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
17 changes: 13 additions & 4 deletions packages/server/src/adapter/sveltekit/handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Handle, RequestEvent } from '@sveltejs/kit';
import { type Handle, type RequestEvent } from '@sveltejs/kit';
import type { ClientContract } from '@zenstackhq/orm';
import type { SchemaDef } from '@zenstackhq/orm/schema';
import { logInternalError, type CommonAdapterOptions } from '../common';
Expand Down Expand Up @@ -37,9 +37,18 @@ export default function createHandler<Schema extends SchemaDef>(options: SvelteK
const query = Object.fromEntries(event.url.searchParams);
let requestBody: unknown;
if (event.request.body) {
const text = await event.request.text();
if (text) {
requestBody = JSON.parse(text);
try {
const text = await event.request.text();
if (text) {
requestBody = JSON.parse(text);
}
} catch {
return new Response(JSON.stringify({ message: 'invalid JSON payload' }), {
status: 400,
headers: {
'content-type': 'application/json',
},
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/server/test/adapter/fastify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('Fastify adapter tests - rest handler', () => {
app.register(ZenStackFastifyPlugin, {
prefix: '/api',
getClient: () => client,
apiHandler: new RestApiHandler({ schema: client.schema, endpoint: 'http://localhost/api' }),
apiHandler: new RestApiHandler({ schema: client.$schema, endpoint: 'http://localhost/api' }),
});

let r = await app.inject({
Expand Down
6 changes: 3 additions & 3 deletions packages/server/test/adapter/tanstack-start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ model M {
const db = await createTestClient(model);
const options: TanStackStartOptions<SchemaDef> = {
getClient: () => db,
apiHandler: new RPCApiHandler({ schema: db.schema }),
apiHandler: new RPCApiHandler({ schema: db.$schema }),
};

const client = await makeTestClient('/m/create', options)
Expand Down Expand Up @@ -179,7 +179,7 @@ model M {
const db = await createPolicyTestClient(model);
const options: TanStackStartOptions<SchemaDef> = {
getClient: () => db,
apiHandler: new RPCApiHandler({ schema: db.schema }),
apiHandler: new RPCApiHandler({ schema: db.$schema }),
};

const createForbidden = await makeTestClient('/m/create', options)
Expand Down Expand Up @@ -233,7 +233,7 @@ model M {

const options: TanStackStartOptions<SchemaDef> = {
getClient: () => db,
apiHandler: new RestApiHandler({ endpoint: 'http://localhost/api', schema: db.schema }),
apiHandler: new RestApiHandler({ endpoint: 'http://localhost/api', schema: db.$schema }),
};

const create = await makeTestClient('/m', options)
Expand Down