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
1 change: 0 additions & 1 deletion packages/clients/tanstack-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description": "TanStack Query Client for consuming ZenStack v3's CRUD service",
"main": "index.js",
"type": "module",
"private": true,
"scripts": {
"build": "tsc --noEmit && tsup-node && pnpm test:generate && pnpm test:typecheck",
"watch": "tsup-node --watch",
Expand Down
22 changes: 12 additions & 10 deletions packages/server/src/api/rest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import type { FieldDef, ModelDef, SchemaDef } from '@zenstackhq/orm/schema';
import { Decimal } from 'decimal.js';
import SuperJSON from 'superjson';
import { Linker, Paginator, Relator, Serializer, type SerializerOptions } from 'ts-japi';
import tsjapi, { type Linker, type Paginator, type Relator, type Serializer, type SerializerOptions } from 'ts-japi';
import UrlPattern from 'url-pattern';
import z from 'zod';
import type { ApiHandler, LogConfig, RequestContext, Response } from '../../types';
Expand Down Expand Up @@ -610,7 +610,9 @@ export class RestApiHandler<Schema extends SchemaDef> implements ApiHandler<Sche
status: 200,
body: await this.serializeItems(relationInfo.type, entity[relationship], {
linkers: {
document: new Linker(() => this.makeLinkUrl(`/${mappedType}/${resourceId}/${relationship}`)),
document: new tsjapi.Linker(() =>
this.makeLinkUrl(`/${mappedType}/${resourceId}/${relationship}`),
),
paginator,
},
include,
Expand Down Expand Up @@ -670,7 +672,7 @@ export class RestApiHandler<Schema extends SchemaDef> implements ApiHandler<Sche
if (entity?.[relationship]) {
const serialized: any = await this.serializeItems(relationInfo.type, entity[relationship], {
linkers: {
document: new Linker(() =>
document: new tsjapi.Linker(() =>
this.makeLinkUrl(`/${mappedType}/${resourceId}/relationships/${relationship}`),
),
paginator,
Expand Down Expand Up @@ -827,7 +829,7 @@ export class RestApiHandler<Schema extends SchemaDef> implements ApiHandler<Sche

const totalPages = Math.ceil(total / limit);

return new Paginator(() => ({
return new tsjapi.Paginator(() => ({
first: this.replaceURLSearchParams(baseUrl, { 'page[limit]': limit }),
last: this.replaceURLSearchParams(baseUrl, {
'page[offset]': (totalPages - 1) * limit,
Expand Down Expand Up @@ -1110,7 +1112,7 @@ export class RestApiHandler<Schema extends SchemaDef> implements ApiHandler<Sche

const serialized: any = await this.serializeItems(relationInfo.type, entity[relationship], {
linkers: {
document: new Linker(() =>
document: new tsjapi.Linker(() =>
this.makeLinkUrl(`/${mappedType}/${resourceId}/relationships/${relationship}`),
),
},
Expand Down Expand Up @@ -1308,7 +1310,7 @@ export class RestApiHandler<Schema extends SchemaDef> implements ApiHandler<Sche
continue;
}

const linker = new Linker((items) =>
const linker = new tsjapi.Linker((items) =>
Array.isArray(items)
? this.makeLinkUrl(`/${mappedModel}`)
: this.makeLinkUrl(`/${mappedModel}/${this.getId(model, items)}`),
Expand All @@ -1326,7 +1328,7 @@ export class RestApiHandler<Schema extends SchemaDef> implements ApiHandler<Sche
projection = null;
}

const serializer = new Serializer(model, {
const serializer = new tsjapi.Serializer(model, {
version: '1.1',
idKey: this.makeIdKey(ids),
linkers: {
Expand Down Expand Up @@ -1360,18 +1362,18 @@ export class RestApiHandler<Schema extends SchemaDef> implements ApiHandler<Sche
if (fieldIds.length > 0) {
const mappedModel = this.mapModelName(modelLower);

const relator = new Relator(
const relator = new tsjapi.Relator(
async (data) => {
return (data as any)[field];
},
fieldSerializer,
{
relatedName: field,
linkers: {
related: new Linker((primary) =>
related: new tsjapi.Linker((primary) =>
this.makeLinkUrl(`/${mappedModel}/${this.getId(model, primary)}/${field}`),
),
relationship: new Linker((primary) =>
relationship: new tsjapi.Linker((primary) =>
this.makeLinkUrl(
`/${mappedModel}/${this.getId(model, primary)}/relationships/${field}`,
),
Expand Down