Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/server/src/api/rpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,17 @@ export class RPCApiHandler<Schema extends SchemaDef = SchemaDef> implements ApiH
}

private async processRequestPayload(args: any) {
const { meta, ...rest } = args;
const { meta, ...rest } = args ?? {};
if (meta?.serialization) {
try {
// superjson deserialization
args = SuperJSON.deserialize({ json: rest, meta: meta.serialization });
} catch (err) {
return { result: undefined, error: `failed to deserialize request payload: ${(err as Error).message}` };
}
} else {
// drop meta when no serialization info is present
args = rest;
}
return { result: args, error: undefined };
}
Expand Down
26 changes: 26 additions & 0 deletions packages/server/test/api/rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ describe('RPC API Handler Tests', () => {
float Float
decimal Decimal
boolean Boolean
stringList String[]
bytes Bytes
bars Bar[]
}
Expand All @@ -386,6 +387,7 @@ describe('RPC API Handler Tests', () => {
const dateValue = new Date();
const bytesValue = new Uint8Array([1, 2, 3, 4]);
const barBytesValue = new Uint8Array([7, 8, 9]);
const stringListValue = ['a', 'b', 'c'];

const createData = {
string: 'string',
Expand All @@ -396,6 +398,7 @@ describe('RPC API Handler Tests', () => {
decimal: decimalValue,
boolean: true,
bytes: bytesValue,
stringList: stringListValue,
bars: {
create: { bytes: barBytesValue },
},
Expand Down Expand Up @@ -424,6 +427,8 @@ describe('RPC API Handler Tests', () => {
expect(data.date instanceof Date).toBeTruthy();
expect(Decimal.isDecimal(data.decimal)).toBeTruthy();
expect(data.bars[0].bytes).toBeInstanceOf(Uint8Array);
expect(Array.isArray(data.stringList)).toBeTruthy();
expect(data.stringList).toEqual(stringListValue);

// find with filter not found
const serializedQ = SuperJSON.serialize({
Expand Down Expand Up @@ -506,6 +511,27 @@ describe('RPC API Handler Tests', () => {
});
expect(r.status).toBe(200);
expect(r.data).toBeNull();

// validate update on stringList
const serializedUpdate = SuperJSON.serialize({
where: { id: 1 },
data: {
stringList: ['d', 'e', 'f'],
},
});
r = await handleRequest({
method: 'patch',
path: '/foo/update',
query: {},
client,
requestBody: {
...(serializedUpdate.json as any),
meta: { serialization: serializedUpdate.meta },
},
});
expect(r.status).toBe(200);
expect(r.data).toBeTruthy();
expect(r.data.stringList).toEqual(['d', 'e', 'f']);
});

function makeHandler() {
Expand Down
Loading