Skip to content

Commit b9294bb

Browse files
authored
fix: tsjapi esm compatibility issue (#362)
1 parent 7cdda90 commit b9294bb

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

packages/clients/tanstack-query/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"description": "TanStack Query Client for consuming ZenStack v3's CRUD service",
55
"main": "index.js",
66
"type": "module",
7-
"private": true,
87
"scripts": {
98
"build": "tsc --noEmit && tsup-node && pnpm test:generate && pnpm test:typecheck",
109
"watch": "tsup-node --watch",

packages/server/src/api/rest/index.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import type { FieldDef, ModelDef, SchemaDef } from '@zenstackhq/orm/schema';
1111
import { Decimal } from 'decimal.js';
1212
import SuperJSON from 'superjson';
13-
import { Linker, Paginator, Relator, Serializer, type SerializerOptions } from 'ts-japi';
13+
import tsjapi, { type Linker, type Paginator, type Relator, type Serializer, type SerializerOptions } from 'ts-japi';
1414
import UrlPattern from 'url-pattern';
1515
import z from 'zod';
1616
import type { ApiHandler, LogConfig, RequestContext, Response } from '../../types';
@@ -610,7 +610,9 @@ export class RestApiHandler<Schema extends SchemaDef> implements ApiHandler<Sche
610610
status: 200,
611611
body: await this.serializeItems(relationInfo.type, entity[relationship], {
612612
linkers: {
613-
document: new Linker(() => this.makeLinkUrl(`/${mappedType}/${resourceId}/${relationship}`)),
613+
document: new tsjapi.Linker(() =>
614+
this.makeLinkUrl(`/${mappedType}/${resourceId}/${relationship}`),
615+
),
614616
paginator,
615617
},
616618
include,
@@ -670,7 +672,7 @@ export class RestApiHandler<Schema extends SchemaDef> implements ApiHandler<Sche
670672
if (entity?.[relationship]) {
671673
const serialized: any = await this.serializeItems(relationInfo.type, entity[relationship], {
672674
linkers: {
673-
document: new Linker(() =>
675+
document: new tsjapi.Linker(() =>
674676
this.makeLinkUrl(`/${mappedType}/${resourceId}/relationships/${relationship}`),
675677
),
676678
paginator,
@@ -827,7 +829,7 @@ export class RestApiHandler<Schema extends SchemaDef> implements ApiHandler<Sche
827829

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

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

11111113
const serialized: any = await this.serializeItems(relationInfo.type, entity[relationship], {
11121114
linkers: {
1113-
document: new Linker(() =>
1115+
document: new tsjapi.Linker(() =>
11141116
this.makeLinkUrl(`/${mappedType}/${resourceId}/relationships/${relationship}`),
11151117
),
11161118
},
@@ -1308,7 +1310,7 @@ export class RestApiHandler<Schema extends SchemaDef> implements ApiHandler<Sche
13081310
continue;
13091311
}
13101312

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

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

1363-
const relator = new Relator(
1365+
const relator = new tsjapi.Relator(
13641366
async (data) => {
13651367
return (data as any)[field];
13661368
},
13671369
fieldSerializer,
13681370
{
13691371
relatedName: field,
13701372
linkers: {
1371-
related: new Linker((primary) =>
1373+
related: new tsjapi.Linker((primary) =>
13721374
this.makeLinkUrl(`/${mappedModel}/${this.getId(model, primary)}/${field}`),
13731375
),
1374-
relationship: new Linker((primary) =>
1376+
relationship: new tsjapi.Linker((primary) =>
13751377
this.makeLinkUrl(
13761378
`/${mappedModel}/${this.getId(model, primary)}/relationships/${field}`,
13771379
),

0 commit comments

Comments
 (0)