Skip to content

Commit

Permalink
defaults results to an empty object if null or undefined (#270)
Browse files Browse the repository at this point in the history
allow returning void
infer storage set return value
  • Loading branch information
Wozacosta authored Dec 6, 2023
1 parent 20fad45 commit 0bd66f5
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .changeset/rude-boxes-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@ledgerhq/wallet-api-simulator": patch
"@ledgerhq/wallet-api-client": patch
"@ledgerhq/wallet-api-core": patch
---

allow empty (void) values to be returned by the RPCNode requests
4 changes: 2 additions & 2 deletions packages/core/src/JSONRPC/RpcNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export abstract class RpcNode<TSHandlers, TCHandlers> {

private _request<K extends keyof TCHandlers>(
request: RpcRequest<K, MethodParamsIfExists<TCHandlers, K>>,
): Promise<ReturnTypeOfMethodIfExists<TCHandlers, K>> {
): Promise<ReturnTypeOfMethodIfExists<TCHandlers, K> | undefined> {
return new Promise((resolve, reject) => {
if (!request.id) {
reject(new Error("requests need to have an id"));
Expand Down Expand Up @@ -90,7 +90,7 @@ export abstract class RpcNode<TSHandlers, TCHandlers> {
public request<K extends keyof TCHandlers>(
method: K,
params: MethodParamsIfExists<TCHandlers, K>,
): Promise<ReturnTypeOfMethodIfExists<TCHandlers, K>> {
): Promise<ReturnTypeOfMethodIfExists<TCHandlers, K> | undefined> {
const requestId = uuidv4();
return this._request({
id: requestId,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/JSONRPC/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function createRpcRequest<T>(
type CreateRpcResponseParams<T, E> =
| {
id: string | number | null;
result: T;
result?: T;
}
| {
id: string | number | null;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/JSONRPC/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export type RpcResponseSuccess<TResult = unknown> = RpcResponseCommon & {
* This member **MUST NOT** exist if there was an error invoking the method.
* The value of this member is determined by the method invoked on the Server.
*/
result: TResult;
result?: TResult;
};

export type RpcResponseFailed<TErrorData = unknown> = RpcResponseCommon & {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/JSONRPC/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const schemaRPCResponseSuccess = z
.object({
jsonrpc: z.literal("2.0"),
id: schemaRPCId,
result: z.object({}).passthrough(),
result: z.object({}).passthrough().optional(),
})
.strict();

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/spec/types/StorageSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const schemaStorageSetParams = z.object({
storeId: z.string().optional(),
});

const schemaStorageSetResults = z.void();
const schemaStorageSetResults = z.void().optional();

export const schemaStorageSet = {
params: schemaStorageSetParams,
Expand Down
2 changes: 1 addition & 1 deletion packages/simulator/tests/simulator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ describe("Simulator", () => {
// WHEN
const key = "testKey";
const value = "testValue";
void client.storage.set(key, value); // TODO fix me when we can await
await client.storage.set(key, value);
const retrievedValue = await client.storage.get(key);

// THEN
Expand Down

2 comments on commit 0bd66f5

@vercel
Copy link

@vercel vercel bot commented on 0bd66f5 Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

wallet-api – ./apps/docs

wallet-api-git-main-ledgerhq.vercel.app
wallet-api-ledgerhq.vercel.app
wallet.api.live.ledger.com

@vercel
Copy link

@vercel vercel bot commented on 0bd66f5 Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

wallet-api-wallet-api-tools – ./apps/wallet-api-tools

wallet-api-wallet-api-tools-ledgerhq.vercel.app
wallet-api-wallet-api-tools-git-main-ledgerhq.vercel.app
wallet-api-wallet-api-tools.vercel.app

Please sign in to comment.