Skip to content

Commit

Permalink
chore: upgrade ts-japi (#1214)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 authored Apr 6, 2024
1 parent 92bc731 commit 4e8427d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
6 changes: 3 additions & 3 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
"lower-case-first": "^2.0.2",
"superjson": "^1.11.0",
"tiny-invariant": "^1.3.1",
"ts-japi": "^1.8.0",
"ts-japi": "^1.10.1",
"upper-case-first": "^2.0.2",
"url-pattern": "^1.0.3",
"zod": "^3.22.4",
"zod-validation-error": "^1.5.0"
},
"devDependencies": {
"@nestjs/common": "^10.0.0",
"@nestjs/platform-express": "^10.3.5",
"@nestjs/testing": "^10.3.5",
"@sveltejs/kit": "1.21.0",
Expand All @@ -54,8 +55,7 @@
"isomorphic-fetch": "^3.0.0",
"next": "^13.4.5",
"nuxt": "^3.7.4",
"supertest": "^6.3.3",
"@nestjs/common": "^10.0.0"
"supertest": "^6.3.3"
},
"exports": {
"./package.json": "./package.json",
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/api/rest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ class RequestHandler extends APIHandlerBase {
throw new Error(`serializer not found for model ${model}`);
}

// serialize to JSON:API strcuture
// serialize to JSON:API structure
const serialized = await serializer.serialize(items, options);

// convert the serialization result to plain object otherwise SuperJSON won't work
Expand Down
19 changes: 11 additions & 8 deletions packages/server/src/api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ export function registerCustomSerializers() {
'Decimal'
);

SuperJSON.registerCustom<Buffer, string>(
{
isApplicable: (v): v is Buffer => Buffer.isBuffer(v),
serialize: (v) => v.toString('base64'),
deserialize: (v) => Buffer.from(v, 'base64'),
},
'Bytes'
);
// `Buffer` is not available in edge runtime
if (globalThis.Buffer) {
SuperJSON.registerCustom<Buffer, string>(
{
isApplicable: (v): v is Buffer => Buffer.isBuffer(v),
serialize: (v) => v.toString('base64'),
deserialize: (v) => Buffer.from(v, 'base64'),
},
'Bytes'
);
}
}
4 changes: 2 additions & 2 deletions packages/server/tests/api/rest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ describe('REST server tests', () => {
query: { include: 'posts.comments' },
prisma,
});
expect(r.body.included).toHaveLength(3);
expect(r.body.included).toHaveLength(4);
expect(r.body.included[2]).toMatchObject({
type: 'comment',
attributes: { content: 'Comment1' },
Expand All @@ -1027,7 +1027,7 @@ describe('REST server tests', () => {
query: { include: 'posts.comments,profile' },
prisma,
});
expect(r.body.included).toHaveLength(4);
expect(r.body.included).toHaveLength(5);
const profile = r.body.included.find((item: any) => item.type === 'profile');
expect(profile).toMatchObject({
type: 'profile',
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4e8427d

Please sign in to comment.