Skip to content

Commit 8cbe1b0

Browse files
ErikDakodaclaude
andauthored
fix(clients): keep the ORM runtime out of client bundles (#2871)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5199bb1 commit 8cbe1b0

8 files changed

Lines changed: 184 additions & 127 deletions

File tree

‎packages/clients/client-helpers/src/types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ExtQueryArgsMarker, ExtResultMarker, type QueryOptions } from '@zenstackhq/orm';
1+
import type { ExtQueryArgsMarker, ExtResultMarker, QueryOptions } from '@zenstackhq/orm';
22
import type { SchemaDef } from '@zenstackhq/schema';
33

44
/**

‎packages/clients/tanstack-query/src/common/transaction.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Logger } from '@zenstackhq/client-helpers';
22
import { createInvalidator, TRANSACTION_ROUTE_PREFIX, type InvalidateFunc } from '@zenstackhq/client-helpers';
33
import { fetcher, marshal, type FetchFn } from '@zenstackhq/client-helpers/fetch';
44
import type { TransactionOperation } from '@zenstackhq/client-helpers';
5-
import { CoreReadOperations } from '@zenstackhq/orm';
5+
import { CoreReadOperations } from '@zenstackhq/orm/constants';
66
import type { SchemaDef } from '@zenstackhq/schema';
77

88
/**

‎packages/orm/package.json‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@
106106
"default": "./dist/common-types.cjs"
107107
}
108108
},
109+
"./constants": {
110+
"import": {
111+
"types": "./dist/constants.d.mts",
112+
"default": "./dist/constants.mjs"
113+
},
114+
"require": {
115+
"types": "./dist/constants.d.cts",
116+
"default": "./dist/constants.cjs"
117+
}
118+
},
109119
"./package.json": {
110120
"import": "./package.json",
111121
"require": "./package.json"

‎packages/orm/src/client/constants.ts‎

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,128 @@ export const FILTER_PROPERTY_TO_KIND = {
8585
* Mapping of filter operators to their corresponding filter kind categories.
8686
*/
8787
export type FilterPropertyToKind = typeof FILTER_PROPERTY_TO_KIND;
88+
89+
/**
90+
* List of core CRUD operations. It excludes the 'orThrow' variants.
91+
*/
92+
export const CoreCrudOperations = [
93+
'findMany',
94+
'findUnique',
95+
'findFirst',
96+
'create',
97+
'createMany',
98+
'createManyAndReturn',
99+
'update',
100+
'updateMany',
101+
'updateManyAndReturn',
102+
'upsert',
103+
'delete',
104+
'deleteMany',
105+
'count',
106+
'aggregate',
107+
'groupBy',
108+
'exists',
109+
] as const;
110+
111+
/**
112+
* List of core CRUD operations. It excludes the 'orThrow' variants.
113+
*/
114+
export type CoreCrudOperations = (typeof CoreCrudOperations)[number];
115+
116+
/**
117+
* List of core read operations. It excludes the 'orThrow' variants.
118+
*/
119+
export const CoreReadOperations = [
120+
'findMany',
121+
'findUnique',
122+
'findFirst',
123+
'count',
124+
'aggregate',
125+
'groupBy',
126+
'exists',
127+
] as const;
128+
129+
/**
130+
* List of core read operations. It excludes the 'orThrow' variants.
131+
*/
132+
export type CoreReadOperations = (typeof CoreReadOperations)[number];
133+
134+
/**
135+
* List of core write operations.
136+
*/
137+
export const CoreWriteOperations = [
138+
'create',
139+
'createMany',
140+
'createManyAndReturn',
141+
'update',
142+
'updateMany',
143+
'updateManyAndReturn',
144+
'upsert',
145+
'delete',
146+
'deleteMany',
147+
] as const;
148+
149+
/**
150+
* List of core write operations.
151+
*/
152+
export type CoreWriteOperations = (typeof CoreWriteOperations)[number];
153+
154+
/**
155+
* List of core create operations.
156+
*/
157+
export const CoreCreateOperations = ['create', 'createMany', 'createManyAndReturn', 'upsert'] as const;
158+
159+
/**
160+
* List of core create operations.
161+
*/
162+
export type CoreCreateOperations = (typeof CoreCreateOperations)[number];
163+
164+
/**
165+
* List of core update operations.
166+
*/
167+
export const CoreUpdateOperations = ['update', 'updateMany', 'updateManyAndReturn', 'upsert'] as const;
168+
169+
/**
170+
* List of core update operations.
171+
*/
172+
export type CoreUpdateOperations = (typeof CoreUpdateOperations)[number];
173+
174+
/**
175+
* List of core delete operations.
176+
*/
177+
export const CoreDeleteOperations = ['delete', 'deleteMany'] as const;
178+
179+
/**
180+
* List of core delete operations.
181+
*/
182+
export type CoreDeleteOperations = (typeof CoreDeleteOperations)[number];
183+
184+
/**
185+
* List of all CRUD operations, including 'orThrow' variants.
186+
*/
187+
export const AllCrudOperations = [...CoreCrudOperations, 'findUniqueOrThrow', 'findFirstOrThrow'] as const;
188+
189+
/**
190+
* List of all CRUD operations, including 'orThrow' variants.
191+
*/
192+
export type AllCrudOperations = (typeof AllCrudOperations)[number];
193+
194+
/**
195+
* List of all read operations, including 'orThrow' variants.
196+
*/
197+
export const AllReadOperations = [...CoreReadOperations, 'findUniqueOrThrow', 'findFirstOrThrow'] as const;
198+
199+
/**
200+
* List of all read operations, including 'orThrow' variants.
201+
*/
202+
export type AllReadOperations = (typeof AllReadOperations)[number];
203+
204+
/**
205+
* List of all write operations - simply an alias of CoreWriteOperations.
206+
*/
207+
export const AllWriteOperations = CoreWriteOperations;
208+
209+
/**
210+
* List of all write operations - simply an alias of CoreWriteOperations.
211+
*/
212+
export type AllWriteOperations = CoreWriteOperations;

‎packages/orm/src/client/crud/operations/base.ts‎

Lines changed: 12 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ulid } from 'ulid';
1919
import * as uuid from 'uuid';
2020
import type { AnyKysely } from '../../../utils/kysely-utils';
2121
import { extractFields, fieldsToSelectObject, isEmptyObject } from '../../../utils/object-utils';
22-
import { NUMERIC_FIELD_TYPES } from '../../constants';
22+
import { NUMERIC_FIELD_TYPES, type CoreCrudOperations } from '../../constants';
2323
import { TransactionIsolationLevel, type ClientContract, type CRUD } from '../../contract';
2424
import type { FindArgs, SelectIncludeOmit, WhereInput } from '../../crud-types';
2525
import {
@@ -54,130 +54,17 @@ import { getCrudDialect } from '../dialects';
5454
import type { BaseCrudDialect } from '../dialects/base-dialect';
5555
import { InputValidator } from '../validator';
5656

57-
/**
58-
* List of core CRUD operations. It excludes the 'orThrow' variants.
59-
*/
60-
export const CoreCrudOperations = [
61-
'findMany',
62-
'findUnique',
63-
'findFirst',
64-
'create',
65-
'createMany',
66-
'createManyAndReturn',
67-
'update',
68-
'updateMany',
69-
'updateManyAndReturn',
70-
'upsert',
71-
'delete',
72-
'deleteMany',
73-
'count',
74-
'aggregate',
75-
'groupBy',
76-
'exists',
77-
] as const;
78-
79-
/**
80-
* List of core CRUD operations. It excludes the 'orThrow' variants.
81-
*/
82-
export type CoreCrudOperations = (typeof CoreCrudOperations)[number];
83-
84-
/**
85-
* List of core read operations. It excludes the 'orThrow' variants.
86-
*/
87-
export const CoreReadOperations = [
88-
'findMany',
89-
'findUnique',
90-
'findFirst',
91-
'count',
92-
'aggregate',
93-
'groupBy',
94-
'exists',
95-
] as const;
96-
97-
/**
98-
* List of core read operations. It excludes the 'orThrow' variants.
99-
*/
100-
export type CoreReadOperations = (typeof CoreReadOperations)[number];
101-
102-
/**
103-
* List of core write operations.
104-
*/
105-
export const CoreWriteOperations = [
106-
'create',
107-
'createMany',
108-
'createManyAndReturn',
109-
'update',
110-
'updateMany',
111-
'updateManyAndReturn',
112-
'upsert',
113-
'delete',
114-
'deleteMany',
115-
] as const;
116-
117-
/**
118-
* List of core write operations.
119-
*/
120-
export type CoreWriteOperations = (typeof CoreWriteOperations)[number];
121-
122-
/**
123-
* List of core create operations.
124-
*/
125-
export const CoreCreateOperations = ['create', 'createMany', 'createManyAndReturn', 'upsert'] as const;
126-
127-
/**
128-
* List of core create operations.
129-
*/
130-
export type CoreCreateOperations = (typeof CoreCreateOperations)[number];
131-
132-
/**
133-
* List of core update operations.
134-
*/
135-
export const CoreUpdateOperations = ['update', 'updateMany', 'updateManyAndReturn', 'upsert'] as const;
136-
137-
/**
138-
* List of core update operations.
139-
*/
140-
export type CoreUpdateOperations = (typeof CoreUpdateOperations)[number];
141-
142-
/**
143-
* List of core delete operations.
144-
*/
145-
export const CoreDeleteOperations = ['delete', 'deleteMany'] as const;
146-
147-
/**
148-
* List of core delete operations.
149-
*/
150-
export type CoreDeleteOperations = (typeof CoreDeleteOperations)[number];
151-
152-
/**
153-
* List of all CRUD operations, including 'orThrow' variants.
154-
*/
155-
export const AllCrudOperations = [...CoreCrudOperations, 'findUniqueOrThrow', 'findFirstOrThrow'] as const;
156-
157-
/**
158-
* List of all CRUD operations, including 'orThrow' variants.
159-
*/
160-
export type AllCrudOperations = (typeof AllCrudOperations)[number];
161-
162-
/**
163-
* List of all read operations, including 'orThrow' variants.
164-
*/
165-
export const AllReadOperations = [...CoreReadOperations, 'findUniqueOrThrow', 'findFirstOrThrow'] as const;
166-
167-
/**
168-
* List of all read operations, including 'orThrow' variants.
169-
*/
170-
export type AllReadOperations = (typeof AllReadOperations)[number];
171-
172-
/**
173-
* List of all write operations - simply an alias of CoreWriteOperations.
174-
*/
175-
export const AllWriteOperations = CoreWriteOperations;
176-
177-
/**
178-
* List of all write operations - simply an alias of CoreWriteOperations.
179-
*/
180-
export type AllWriteOperations = CoreWriteOperations;
57+
export {
58+
AllCrudOperations,
59+
AllReadOperations,
60+
AllWriteOperations,
61+
CoreCreateOperations,
62+
CoreCrudOperations,
63+
CoreDeleteOperations,
64+
CoreReadOperations,
65+
CoreUpdateOperations,
66+
CoreWriteOperations,
67+
} from '../../constants';
18168

18269
// context for nested relation operations
18370
export type FromRelationContext = {

‎packages/orm/src/constants.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Dependency-free constants, importable without pulling in the ORM runtime (e.g. from browser clients).
2+
export {
3+
AllCrudOperations,
4+
AllReadOperations,
5+
AllWriteOperations,
6+
CoreCreateOperations,
7+
CoreCrudOperations,
8+
CoreDeleteOperations,
9+
CoreReadOperations,
10+
CoreUpdateOperations,
11+
CoreWriteOperations,
12+
} from './client/constants';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { describe, expect, it } from 'vitest';
2+
import * as constants from '../src/constants';
3+
import * as orm from '../src/index';
4+
5+
describe('constants entry', () => {
6+
it('exports the operation lists of the main entry', () => {
7+
expect(Object.keys(constants).sort()).toEqual([
8+
'AllCrudOperations',
9+
'AllReadOperations',
10+
'AllWriteOperations',
11+
'CoreCreateOperations',
12+
'CoreCrudOperations',
13+
'CoreDeleteOperations',
14+
'CoreReadOperations',
15+
'CoreUpdateOperations',
16+
'CoreWriteOperations',
17+
]);
18+
for (const [name, value] of Object.entries(constants)) {
19+
expect(orm[name as keyof typeof orm]).toBe(value);
20+
}
21+
});
22+
});

‎packages/orm/tsdown.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default createConfig({
66
schema: 'src/schema.ts',
77
helpers: 'src/helpers.ts',
88
'common-types': 'src/common-types.ts',
9+
constants: 'src/constants.ts',
910
'dialects/sqlite': 'src/dialects/sqlite.ts',
1011
'dialects/postgres': 'src/dialects/postgres.ts',
1112
'dialects/mysql': 'src/dialects/mysql.ts',

0 commit comments

Comments
 (0)