zenstack-trpc 0.1.6 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +109 -47
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/router-generator.d.ts +16 -16
- package/dist/router-generator.d.ts.map +1 -1
- package/dist/router-generator.js +2 -1
- package/dist/typed-client.d.ts +89 -115
- package/dist/typed-client.d.ts.map +1 -1
- package/dist/typed-client.js +17 -46
- package/dist/zod-schemas.d.ts.map +1 -1
- package/dist/zod-schemas.js +5 -3
- package/package.json +13 -1
package/README.md
CHANGED
|
@@ -146,89 +146,146 @@ const usersWithPosts = await caller.user.findMany({ include: { posts: true } });
|
|
|
146
146
|
// Type: (User & { posts: Post[] })[]
|
|
147
147
|
```
|
|
148
148
|
|
|
149
|
-
### `
|
|
149
|
+
### `ZenStackRouter<Schema>` and `ZenStackRouterRecord<Schema>`
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
Type helpers for the generated router structure:
|
|
152
152
|
|
|
153
|
-
|
|
153
|
+
- **`ZenStackRouter<Schema>`** - The full router type including `_def` and `createCaller`
|
|
154
|
+
- **`ZenStackRouterRecord<Schema>`** - Just the procedure map (useful for type composition)
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import type { ZenStackRouter, ZenStackRouterRecord } from "zenstack-trpc";
|
|
158
|
+
import type { SchemaType } from "./zenstack/schema.js";
|
|
159
|
+
|
|
160
|
+
// The full router type
|
|
161
|
+
type MyRouter = ZenStackRouter<SchemaType>;
|
|
162
|
+
|
|
163
|
+
// Just the procedures (for advanced type manipulation)
|
|
164
|
+
type Procedures = ZenStackRouterRecord<SchemaType>;
|
|
165
|
+
// { user: { findMany: ..., create: ..., ... }, post: { ... }, ... }
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Composable Type System
|
|
169
|
+
|
|
170
|
+
The library provides a composable type system for adding full `include`/`select` type inference to tRPC clients. This solves tRPC's limitation where generic type information is lost during type inference.
|
|
171
|
+
|
|
172
|
+
The system uses three composable parts:
|
|
173
|
+
1. **`WithZenStack<Schema, Path?>`** - Base type container with your schema and optional nesting path
|
|
174
|
+
2. **`WithReact<...>` / `WithClient<...>`** - Adapter that transforms to React hooks or vanilla client types
|
|
175
|
+
3. **`typedClient<Typed>()`** - Applies the composed types to your client
|
|
154
176
|
|
|
155
177
|
```typescript
|
|
156
|
-
import { createTRPCClient, httpBatchLink } from "@trpc/client";
|
|
157
178
|
import { createTRPCReact } from "@trpc/react-query";
|
|
158
|
-
import {
|
|
179
|
+
import { typedClient, type WithZenStack, type WithReact } from "zenstack-trpc";
|
|
159
180
|
import type { AppRouter } from "./server/trpc.js";
|
|
160
181
|
import type { SchemaType } from "./zenstack/schema.js";
|
|
161
182
|
|
|
162
|
-
//
|
|
163
|
-
|
|
164
|
-
createTRPCClient<AppRouter>({
|
|
165
|
-
links: [httpBatchLink({ url: "http://localhost:3000/trpc" })],
|
|
166
|
-
})
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
// Now includes are fully typed!
|
|
170
|
-
const usersWithPosts = await client.user.findMany.query({
|
|
171
|
-
include: { posts: true }
|
|
172
|
-
});
|
|
173
|
-
// Type: (User & { posts: Post[] })[]
|
|
183
|
+
// Compose your types
|
|
184
|
+
type Typed = WithReact<WithZenStack<SchemaType>>;
|
|
174
185
|
|
|
175
|
-
//
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
);
|
|
186
|
+
// Apply to client
|
|
187
|
+
const _trpc = createTRPCReact<AppRouter>();
|
|
188
|
+
export const trpc = typedClient<Typed>()(_trpc);
|
|
179
189
|
|
|
180
|
-
//
|
|
190
|
+
// Now includes are fully typed!
|
|
181
191
|
const { data } = trpc.user.findMany.useQuery({
|
|
182
192
|
include: { posts: true }
|
|
183
193
|
});
|
|
184
194
|
// data is typed as (User & { posts: Post[] })[] | undefined
|
|
185
195
|
```
|
|
186
196
|
|
|
187
|
-
|
|
197
|
+
For vanilla tRPC clients, use `WithClient`:
|
|
188
198
|
|
|
189
199
|
```typescript
|
|
190
|
-
import
|
|
200
|
+
import { createTRPCClient, httpBatchLink } from "@trpc/client";
|
|
201
|
+
import { typedClient, type WithZenStack, type WithClient } from "zenstack-trpc";
|
|
191
202
|
|
|
192
|
-
|
|
193
|
-
|
|
203
|
+
type Typed = WithClient<WithZenStack<SchemaType>>;
|
|
204
|
+
|
|
205
|
+
const _client = createTRPCClient<AppRouter>({
|
|
206
|
+
links: [httpBatchLink({ url: "http://localhost:3000/trpc" })],
|
|
207
|
+
});
|
|
208
|
+
export const client = typedClient<Typed>()(_client);
|
|
209
|
+
|
|
210
|
+
const usersWithPosts = await client.user.findMany.query({
|
|
211
|
+
include: { posts: true }
|
|
212
|
+
});
|
|
213
|
+
// Type: (User & { posts: Post[] })[]
|
|
194
214
|
```
|
|
195
215
|
|
|
196
216
|
### Nested Namespaces (Merged Routers)
|
|
197
217
|
|
|
198
|
-
When
|
|
218
|
+
When merging the ZenStack router with other routers, you need to cast it to `AnyRouter` for tRPC compatibility:
|
|
199
219
|
|
|
200
220
|
```typescript
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
221
|
+
import { initTRPC } from "@trpc/server";
|
|
222
|
+
import type { AnyRouter } from "@trpc/server";
|
|
223
|
+
import { createZenStackRouter } from "zenstack-trpc";
|
|
224
|
+
import { schema } from "./zenstack/schema.js";
|
|
225
|
+
|
|
226
|
+
const t = initTRPC.context<{ db: any }>().create();
|
|
227
|
+
|
|
228
|
+
// Create the ZenStack router and cast for tRPC compatibility
|
|
229
|
+
const generatedRouter = createZenStackRouter(schema, t) as unknown as AnyRouter;
|
|
206
230
|
|
|
231
|
+
// Merge with other routers
|
|
232
|
+
export const appRouter = t.router({
|
|
233
|
+
admin: adminRouter,
|
|
234
|
+
auth: authRouter,
|
|
235
|
+
generated: generatedRouter,
|
|
236
|
+
});
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
On the client side, include the path in `WithZenStack` to get full type inference:
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
207
242
|
import { createTRPCReact } from "@trpc/react-query";
|
|
243
|
+
import { typedClient, type WithZenStack, type WithReact } from "zenstack-trpc";
|
|
208
244
|
import type { AppRouter } from "./server/trpc.js";
|
|
209
245
|
import type { SchemaType } from "./zenstack/schema.js";
|
|
210
|
-
import type { WithZenStackTypes } from "zenstack-trpc";
|
|
211
246
|
|
|
247
|
+
// Single level nesting:
|
|
248
|
+
type Typed = WithReact<WithZenStack<SchemaType, "generated">>;
|
|
212
249
|
const _trpc = createTRPCReact<AppRouter>();
|
|
250
|
+
export const trpc = typedClient<Typed>()(_trpc);
|
|
213
251
|
|
|
214
|
-
//
|
|
215
|
-
type
|
|
216
|
-
|
|
217
|
-
};
|
|
218
|
-
export const trpc = _trpc as unknown as TypedTRPC;
|
|
252
|
+
// Multi-level nesting (dot notation):
|
|
253
|
+
type Typed = WithReact<WithZenStack<SchemaType, "api.db">>;
|
|
254
|
+
export const trpc = typedClient<Typed>()(_trpc);
|
|
219
255
|
|
|
220
|
-
//
|
|
221
|
-
|
|
256
|
+
// Now you can use:
|
|
257
|
+
// trpc.generated.user.findMany.useQuery({ include: { posts: true } }) // fully typed
|
|
258
|
+
// trpc.auth.login.useMutation() // other routers unaffected
|
|
259
|
+
```
|
|
222
260
|
|
|
223
|
-
|
|
224
|
-
export const trpc = withNestedZenStackReact<SchemaType, typeof _trpc, 'db'>('db')(_trpc);
|
|
261
|
+
### Custom Adapters
|
|
225
262
|
|
|
226
|
-
|
|
227
|
-
// export const client = withNestedZenStackClient<SchemaType, typeof _client, 'db'>('db')(_client);
|
|
263
|
+
The composable architecture allows third parties to create custom adapters. An adapter transforms `WithZenStack` into framework-specific types:
|
|
228
264
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
265
|
+
```typescript
|
|
266
|
+
import type { WithZenStack, TypedTRPCReact } from "zenstack-trpc";
|
|
267
|
+
|
|
268
|
+
// Example: Custom adapter for a hypothetical framework
|
|
269
|
+
type WithMyFramework<T extends WithZenStack<any, any>> =
|
|
270
|
+
T extends WithZenStack<infer S, infer P>
|
|
271
|
+
? { readonly __types: MyFrameworkTypes<S>; readonly __path: P }
|
|
272
|
+
: never;
|
|
273
|
+
|
|
274
|
+
// Usage:
|
|
275
|
+
type Typed = WithMyFramework<WithZenStack<SchemaType, "db">>;
|
|
276
|
+
const client = typedClient<Typed>()(myFrameworkClient);
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Direct Type Access
|
|
280
|
+
|
|
281
|
+
For advanced use cases, you can access the underlying types directly:
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
import type { TypedTRPCClient, TypedTRPCReact } from "zenstack-trpc";
|
|
285
|
+
|
|
286
|
+
// Manual casting
|
|
287
|
+
const client = _client as unknown as TypedTRPCClient<SchemaType>;
|
|
288
|
+
const trpc = _trpc as unknown as TypedTRPCReact<SchemaType>;
|
|
232
289
|
```
|
|
233
290
|
|
|
234
291
|
### Zod Schema Access
|
|
@@ -248,6 +305,11 @@ const userSchemas = createModelSchemas(schema, "User");
|
|
|
248
305
|
- tRPC >= 11.0.0
|
|
249
306
|
- Zod >= 3.0.0
|
|
250
307
|
|
|
308
|
+
### Optional (for React hooks)
|
|
309
|
+
|
|
310
|
+
- `@trpc/react-query` >= 11.0.0
|
|
311
|
+
- `@tanstack/react-query` >= 5.0.0
|
|
312
|
+
|
|
251
313
|
## License
|
|
252
314
|
|
|
253
315
|
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
*
|
|
27
27
|
* @packageDocumentation
|
|
28
28
|
*/
|
|
29
|
-
export { createZenStackRouter, type ZenStackRouter, type ZenStackRouterRecord, type
|
|
30
|
-
export {
|
|
29
|
+
export { createZenStackRouter, type ZenStackRouter, type ZenStackRouterRecord, type TypedRouterCaller, type TRPCInstance, } from "./router-generator.js";
|
|
30
|
+
export { type WithZenStack, type WithReact, type WithClient, typedClient, type TypedTRPCClient, type TypedTRPCReact, } from "./typed-client.js";
|
|
31
31
|
export { createModelSchemas, createWhereSchema, createCreateDataSchema, createUpdateDataSchema, createUniqueWhereSchema, createSelectSchema, createIncludeSchema, createOrderBySchema, } from "./zod-schemas.js";
|
|
32
32
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAGH,OAAO,EACL,oBAAoB,EACpB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAGH,OAAO,EACL,oBAAoB,EACpB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,YAAY,GAClB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,WAAW,EAEX,KAAK,eAAe,EACpB,KAAK,cAAc,GACpB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -29,8 +29,6 @@
|
|
|
29
29
|
// Router generator and types
|
|
30
30
|
export { createZenStackRouter, } from "./router-generator.js";
|
|
31
31
|
// Typed client helpers for full include/select inference
|
|
32
|
-
export {
|
|
33
|
-
// Converter utilities
|
|
34
|
-
withZenStackTypes, withNestedZenStackReact, withNestedZenStackClient, } from "./typed-client.js";
|
|
32
|
+
export { typedClient, } from "./typed-client.js";
|
|
35
33
|
// Zod schema generators (for advanced usage)
|
|
36
34
|
export { createModelSchemas, createWhereSchema, createCreateDataSchema, createUpdateDataSchema, createUniqueWhereSchema, createSelectSchema, createIncludeSchema, createOrderBySchema, } from "./zod-schemas.js";
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import type { SchemaDef, GetModels } from "@zenstackhq/orm/schema";
|
|
2
2
|
import type { FindManyArgs, FindUniqueArgs, FindFirstArgs, CreateArgs, CreateManyArgs, UpdateArgs, UpdateManyArgs, UpsertArgs, DeleteArgs, DeleteManyArgs, CountArgs, AggregateArgs, GroupByArgs, SimplifiedPlainResult } from "@zenstackhq/orm";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
|
|
5
|
-
* Type helper to convert model names to lowercase
|
|
6
|
-
*/
|
|
7
|
-
type Uncapitalize<S extends string> = S extends `${infer First}${infer Rest}` ? `${Lowercase<First>}${Rest}` : S;
|
|
4
|
+
import type { Uncapitalize } from "./typed-client.js";
|
|
8
5
|
/**
|
|
9
6
|
* Type for a single model's procedures - provides FULL dynamic input AND output typing
|
|
10
7
|
*
|
|
@@ -146,9 +143,9 @@ export declare function createZenStackRouter<Schema extends SchemaDef, TContext
|
|
|
146
143
|
}>(schema: Schema, t: TRPCInstance): ZenStackRouter<Schema, TContext>;
|
|
147
144
|
/**
|
|
148
145
|
* Type for a query procedure with proper input/output typing
|
|
149
|
-
* Matches tRPC's internal Procedure interface for type inference
|
|
146
|
+
* Matches tRPC's internal Procedure interface for type inference and AnyProcedure compatibility
|
|
150
147
|
*/
|
|
151
|
-
|
|
148
|
+
interface TypedQueryProcedure<TInput, TOutput> {
|
|
152
149
|
_def: {
|
|
153
150
|
$types: {
|
|
154
151
|
input: TInput;
|
|
@@ -158,16 +155,16 @@ type TypedQueryProcedure<TInput, TOutput> = {
|
|
|
158
155
|
type: 'query';
|
|
159
156
|
meta: unknown;
|
|
160
157
|
experimental_caller: boolean;
|
|
161
|
-
inputs:
|
|
158
|
+
inputs: unknown[];
|
|
162
159
|
};
|
|
163
160
|
meta: unknown;
|
|
164
161
|
(opts: unknown): Promise<TOutput>;
|
|
165
|
-
}
|
|
162
|
+
}
|
|
166
163
|
/**
|
|
167
164
|
* Type for a mutation procedure with proper input/output typing
|
|
168
|
-
* Matches tRPC's internal Procedure interface for type inference
|
|
165
|
+
* Matches tRPC's internal Procedure interface for type inference and AnyProcedure compatibility
|
|
169
166
|
*/
|
|
170
|
-
|
|
167
|
+
interface TypedMutationProcedure<TInput, TOutput> {
|
|
171
168
|
_def: {
|
|
172
169
|
$types: {
|
|
173
170
|
input: TInput;
|
|
@@ -177,16 +174,17 @@ type TypedMutationProcedure<TInput, TOutput> = {
|
|
|
177
174
|
type: 'mutation';
|
|
178
175
|
meta: unknown;
|
|
179
176
|
experimental_caller: boolean;
|
|
180
|
-
inputs:
|
|
177
|
+
inputs: unknown[];
|
|
181
178
|
};
|
|
182
179
|
meta: unknown;
|
|
183
180
|
(opts: unknown): Promise<TOutput>;
|
|
184
|
-
}
|
|
181
|
+
}
|
|
185
182
|
/**
|
|
186
183
|
* Type for a single model's tRPC procedures (for client inference)
|
|
187
184
|
* This maps each operation to its tRPC procedure type with proper input/output
|
|
185
|
+
* @internal
|
|
188
186
|
*/
|
|
189
|
-
|
|
187
|
+
type TRPCModelProcedures<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
|
|
190
188
|
findMany: TypedQueryProcedure<FindManyArgs<Schema, Model> | undefined, SimplifiedPlainResult<Schema, Model, {}>[]>;
|
|
191
189
|
findUnique: TypedQueryProcedure<FindUniqueArgs<Schema, Model>, SimplifiedPlainResult<Schema, Model, {}> | null>;
|
|
192
190
|
findFirst: TypedQueryProcedure<FindFirstArgs<Schema, Model> | undefined, SimplifiedPlainResult<Schema, Model, {}> | null>;
|
|
@@ -208,13 +206,15 @@ export type TRPCModelProcedures<Schema extends SchemaDef, Model extends GetModel
|
|
|
208
206
|
groupBy: TypedQueryProcedure<GroupByArgs<Schema, Model>, any[]>;
|
|
209
207
|
};
|
|
210
208
|
/**
|
|
211
|
-
* Type for the full router record that tRPC uses for inference
|
|
209
|
+
* Type for the full router record that tRPC uses for inference.
|
|
210
|
+
* Use this type when nesting the ZenStack router within another router.
|
|
212
211
|
*/
|
|
213
212
|
export type ZenStackRouterRecord<Schema extends SchemaDef> = {
|
|
214
213
|
[K in GetModels<Schema> as Uncapitalize<K>]: TRPCModelProcedures<Schema, K>;
|
|
215
214
|
};
|
|
216
215
|
/**
|
|
217
|
-
* The typed router type that clients can use for proper inference
|
|
216
|
+
* The typed router type that clients can use for proper inference.
|
|
217
|
+
* Compatible with tRPC's AnyRouter for use in merged routers.
|
|
218
218
|
*/
|
|
219
219
|
export type ZenStackRouter<Schema extends SchemaDef, TContext = any> = {
|
|
220
220
|
_def: {
|
|
@@ -234,7 +234,7 @@ export type ZenStackRouter<Schema extends SchemaDef, TContext = any> = {
|
|
|
234
234
|
record: ZenStackRouterRecord<Schema>;
|
|
235
235
|
router: true;
|
|
236
236
|
procedures: ZenStackRouterRecord<Schema>;
|
|
237
|
-
lazy:
|
|
237
|
+
lazy: Record<string, unknown>;
|
|
238
238
|
};
|
|
239
239
|
createCaller: (ctx: TContext) => TypedRouterCaller<Schema>;
|
|
240
240
|
} & ZenStackRouterRecord<Schema>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-generator.d.ts","sourceRoot":"","sources":["../src/router-generator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,aAAa,EACb,UAAU,EACV,cAAc,EACd,UAAU,EACV,cAAc,EACd,UAAU,EACV,UAAU,EACV,cAAc,EACd,SAAS,EACT,aAAa,EACb,WAAW,EACX,qBAAqB,EACtB,MAAM,iBAAi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,oBAAoB,CAAC,MAAM,CAAC,CAAC"}
|
package/dist/router-generator.js
CHANGED
|
@@ -17,7 +17,8 @@ function createModelProcedures(schema, modelName, t) {
|
|
|
17
17
|
message: `Operation ${op} not found on model ${modelName}`,
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
const result = await model[op](input);
|
|
21
|
+
return result;
|
|
21
22
|
};
|
|
22
23
|
if (isQuery) {
|
|
23
24
|
return t.procedure.input(inputSchema).query(handler);
|
package/dist/typed-client.d.ts
CHANGED
|
@@ -2,32 +2,32 @@
|
|
|
2
2
|
* Typed tRPC client helpers for full include/select type inference.
|
|
3
3
|
*
|
|
4
4
|
* tRPC's standard type inference loses generic type information for procedure
|
|
5
|
-
* input/output types. This module provides type
|
|
6
|
-
* dynamic typing based on include/select options.
|
|
5
|
+
* input/output types. This module provides a composable type system that
|
|
6
|
+
* restores full dynamic typing based on include/select options.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
9
|
* ```typescript
|
|
10
|
-
* import { createTRPCClient } from "@trpc/client";
|
|
11
10
|
* import { createTRPCReact } from "@trpc/react-query";
|
|
12
|
-
* import {
|
|
11
|
+
* import { typedClient, type WithZenStack, type WithReact } from "zenstack-trpc";
|
|
13
12
|
* import type { AppRouter } from "./server/trpc.js";
|
|
14
13
|
* import type { SchemaType } from "./zenstack/schema.js";
|
|
15
14
|
*
|
|
16
|
-
* //
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* );
|
|
15
|
+
* // Compose types and apply to client
|
|
16
|
+
* type Typed = WithReact<WithZenStack<SchemaType>>;
|
|
17
|
+
* const _trpc = createTRPCReact<AppRouter>();
|
|
18
|
+
* export const trpc = typedClient<Typed>()(_trpc);
|
|
20
19
|
*
|
|
21
|
-
* //
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* );
|
|
20
|
+
* // With nested namespace
|
|
21
|
+
* type Typed = WithReact<WithZenStack<SchemaType, "db">>;
|
|
22
|
+
* export const trpc = typedClient<Typed>()(_trpc);
|
|
25
23
|
* ```
|
|
26
24
|
*/
|
|
27
25
|
import type { SchemaDef, GetModels } from "@zenstackhq/orm/schema";
|
|
28
26
|
import type { FindManyArgs, FindUniqueArgs, FindFirstArgs, CreateArgs, CreateManyArgs, UpdateArgs, UpdateManyArgs, UpsertArgs, DeleteArgs, DeleteManyArgs, CountArgs, AggregateArgs, GroupByArgs, SimplifiedPlainResult } from "@zenstackhq/orm";
|
|
29
|
-
|
|
30
|
-
type
|
|
27
|
+
import type { UseQueryResult, UseMutationResult, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
|
|
28
|
+
import type { TRPCClientErrorLike } from "@trpc/client";
|
|
29
|
+
/** Convert model names to lowercase (internal utility, also used by router-generator) */
|
|
30
|
+
export type Uncapitalize<S extends string> = S extends `${infer F}${infer R}` ? `${Lowercase<F>}${R}` : S;
|
|
31
31
|
/** Infer result type with optional array wrapping */
|
|
32
32
|
type Result<S extends SchemaDef, M extends GetModels<S>, T, D, Arr extends boolean = false> = Arr extends true ? (SimplifiedPlainResult<S, M, T> extends never ? D : SimplifiedPlainResult<S, M, T>[]) : (SimplifiedPlainResult<S, M, T> extends never ? D : SimplifiedPlainResult<S, M, T>);
|
|
33
33
|
/** Default result type for a model */
|
|
@@ -81,101 +81,47 @@ interface SimpleMutation<Args, R> {
|
|
|
81
81
|
type ClientProcedure<S extends SchemaDef, M extends GetModels<S>, Op extends keyof OperationArgs<S, M>> = Op extends MutationOps ? Op extends CountResultOps ? SimpleMutation<OperationArgs<S, M>[Op], {
|
|
82
82
|
count: number;
|
|
83
83
|
}> : DynamicMutation<S, M, OperationArgs<S, M>[Op], DefaultResult<S, M>> : Op extends NumberResultOps ? SimpleQuery<OperationArgs<S, M>[Op], number> : Op extends AnyResultOps ? SimpleQuery<OperationArgs<S, M>[Op], any> : Op extends 'groupBy' ? SimpleQuery<OperationArgs<S, M>[Op], any[]> : DynamicQuery<S, M, OperationArgs<S, M>[Op], Op extends NullableOps ? DefaultResult<S, M> | null : Op extends ArrayOps ? DefaultResult<S, M>[] : DefaultResult<S, M>, Op extends ArrayOps ? true : false>;
|
|
84
|
-
/** All client procedures for a model */
|
|
85
|
-
|
|
84
|
+
/** All client procedures for a model (internal) */
|
|
85
|
+
type TypedClientModelProcedures<S extends SchemaDef, M extends GetModels<S>> = {
|
|
86
86
|
[Op in keyof OperationArgs<S, M>]: ClientProcedure<S, M, Op>;
|
|
87
87
|
};
|
|
88
|
-
/**
|
|
89
|
-
type
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
isPending: boolean;
|
|
94
|
-
isError: boolean;
|
|
95
|
-
isSuccess: boolean;
|
|
96
|
-
refetch: () => Promise<unknown>;
|
|
97
|
-
[k: string]: unknown;
|
|
98
|
-
};
|
|
99
|
-
/** Base mutation result shape */
|
|
100
|
-
type MutationResult<T, V> = {
|
|
101
|
-
data: T | undefined;
|
|
102
|
-
error: Error | null;
|
|
103
|
-
isLoading: boolean;
|
|
104
|
-
isPending: boolean;
|
|
105
|
-
isError: boolean;
|
|
106
|
-
isSuccess: boolean;
|
|
107
|
-
mutate: (v: V, o?: {
|
|
108
|
-
onSuccess?: (d: T) => void;
|
|
109
|
-
onError?: (e: Error) => void;
|
|
110
|
-
onSettled?: () => void;
|
|
111
|
-
}) => void;
|
|
112
|
-
mutateAsync: (v: V, o?: {
|
|
113
|
-
onSuccess?: (d: T) => void;
|
|
114
|
-
onError?: (e: Error) => void;
|
|
115
|
-
onSettled?: () => void;
|
|
116
|
-
}) => Promise<T>;
|
|
117
|
-
[k: string]: unknown;
|
|
88
|
+
/** tRPC hook result extension */
|
|
89
|
+
type TRPCHookResult = {
|
|
90
|
+
trpc: {
|
|
91
|
+
path: string;
|
|
92
|
+
};
|
|
118
93
|
};
|
|
94
|
+
/** Query result with tRPC extension */
|
|
95
|
+
type TRPCQueryResult<TData, TError = TRPCClientErrorLike<any>> = UseQueryResult<TData, TError> & TRPCHookResult;
|
|
96
|
+
/** Mutation result with tRPC extension */
|
|
97
|
+
type TRPCMutationResult<TData, TError, TVariables, TContext = unknown> = UseMutationResult<TData, TError, TVariables, TContext> & TRPCHookResult;
|
|
98
|
+
/** Query options type */
|
|
99
|
+
type QueryOpts<TData, TError = TRPCClientErrorLike<any>> = Omit<UseQueryOptions<TData, TError, TData, any>, 'queryKey' | 'queryFn'>;
|
|
100
|
+
/** Mutation options type */
|
|
101
|
+
type MutationOpts<TData, TError, TVariables, TContext = unknown> = Omit<UseMutationOptions<TData, TError, TVariables, TContext>, 'mutationKey' | 'mutationFn'>;
|
|
119
102
|
/** Query hook - infers result from input */
|
|
120
103
|
interface DynamicQueryHook<S extends SchemaDef, M extends GetModels<S>, Args, Default, Arr extends boolean> {
|
|
121
|
-
useQuery<T extends Args>(input: T, opts?:
|
|
122
|
-
|
|
123
|
-
[k: string]: unknown;
|
|
124
|
-
}): QueryResult<Result<S, M, T, Default, Arr>>;
|
|
125
|
-
useQuery(input?: undefined, opts?: {
|
|
126
|
-
enabled?: boolean;
|
|
127
|
-
[k: string]: unknown;
|
|
128
|
-
}): QueryResult<Default>;
|
|
104
|
+
useQuery<T extends Args>(input: T, opts?: QueryOpts<Result<S, M, T, Default, Arr>>): TRPCQueryResult<Result<S, M, T, Default, Arr>>;
|
|
105
|
+
useQuery(input?: undefined, opts?: QueryOpts<Default>): TRPCQueryResult<Default>;
|
|
129
106
|
}
|
|
130
107
|
/** Simple query hook - fixed result type */
|
|
131
108
|
interface SimpleQueryHook<Args, R> {
|
|
132
|
-
useQuery(input?: Args, opts?:
|
|
133
|
-
enabled?: boolean;
|
|
134
|
-
[k: string]: unknown;
|
|
135
|
-
}): QueryResult<R>;
|
|
109
|
+
useQuery(input?: Args, opts?: QueryOpts<R>): TRPCQueryResult<R>;
|
|
136
110
|
}
|
|
137
111
|
/** Mutation hook - infers result from input */
|
|
138
112
|
interface DynamicMutationHook<S extends SchemaDef, M extends GetModels<S>, Args, Default> {
|
|
139
|
-
useMutation(opts?:
|
|
140
|
-
onSuccess?: (d: any) => void;
|
|
141
|
-
onError?: (e: Error) => void;
|
|
142
|
-
onSettled?: () => void;
|
|
143
|
-
[k: string]: unknown;
|
|
144
|
-
}): {
|
|
145
|
-
mutate: <T extends Args>(input: T, o?: {
|
|
146
|
-
onSuccess?: (d: Result<S, M, T, Default>) => void;
|
|
147
|
-
onError?: (e: Error) => void;
|
|
148
|
-
onSettled?: () => void;
|
|
149
|
-
}) => void;
|
|
150
|
-
mutateAsync: <T extends Args>(input: T, o?: {
|
|
151
|
-
onSuccess?: (d: Result<S, M, T, Default>) => void;
|
|
152
|
-
onError?: (e: Error) => void;
|
|
153
|
-
onSettled?: () => void;
|
|
154
|
-
}) => Promise<Result<S, M, T, Default>>;
|
|
155
|
-
data: Default | undefined;
|
|
156
|
-
error: Error | null;
|
|
157
|
-
isLoading: boolean;
|
|
158
|
-
isPending: boolean;
|
|
159
|
-
isError: boolean;
|
|
160
|
-
isSuccess: boolean;
|
|
161
|
-
[k: string]: unknown;
|
|
162
|
-
};
|
|
113
|
+
useMutation<TContext = unknown>(opts?: MutationOpts<Default, TRPCClientErrorLike<any>, Args, TContext>): TRPCMutationResult<Default, TRPCClientErrorLike<any>, Args, TContext>;
|
|
163
114
|
}
|
|
164
115
|
/** Simple mutation hook - fixed result type */
|
|
165
116
|
interface SimpleMutationHook<Args, R> {
|
|
166
|
-
useMutation(opts?:
|
|
167
|
-
onSuccess?: (d: R) => void;
|
|
168
|
-
onError?: (e: Error) => void;
|
|
169
|
-
onSettled?: () => void;
|
|
170
|
-
[k: string]: unknown;
|
|
171
|
-
}): MutationResult<R, Args>;
|
|
117
|
+
useMutation<TContext = unknown>(opts?: MutationOpts<R, TRPCClientErrorLike<any>, Args, TContext>): TRPCMutationResult<R, TRPCClientErrorLike<any>, Args, TContext>;
|
|
172
118
|
}
|
|
173
119
|
/** Build React hook type for an operation */
|
|
174
120
|
type ReactHook<S extends SchemaDef, M extends GetModels<S>, Op extends keyof OperationArgs<S, M>> = Op extends MutationOps ? Op extends CountResultOps ? SimpleMutationHook<OperationArgs<S, M>[Op], {
|
|
175
121
|
count: number;
|
|
176
122
|
}> : DynamicMutationHook<S, M, OperationArgs<S, M>[Op], DefaultResult<S, M>> : Op extends NumberResultOps ? SimpleQueryHook<OperationArgs<S, M>[Op], number> : Op extends AnyResultOps ? SimpleQueryHook<OperationArgs<S, M>[Op], any> : Op extends 'groupBy' ? SimpleQueryHook<OperationArgs<S, M>[Op], any[]> : DynamicQueryHook<S, M, OperationArgs<S, M>[Op], Op extends NullableOps ? DefaultResult<S, M> | null : Op extends ArrayOps ? DefaultResult<S, M>[] : DefaultResult<S, M>, Op extends ArrayOps ? true : false>;
|
|
177
|
-
/** All React hooks for a model */
|
|
178
|
-
|
|
123
|
+
/** All React hooks for a model (internal) */
|
|
124
|
+
type TypedReactModelHooks<S extends SchemaDef, M extends GetModels<S>> = {
|
|
179
125
|
[Op in keyof OperationArgs<S, M>]: ReactHook<S, M, Op>;
|
|
180
126
|
};
|
|
181
127
|
/** Typed vanilla tRPC client with full include/select type inference */
|
|
@@ -187,54 +133,82 @@ export type TypedTRPCReact<S extends SchemaDef> = {
|
|
|
187
133
|
[K in GetModels<S> as Uncapitalize<K>]: TypedReactModelHooks<S, K>;
|
|
188
134
|
};
|
|
189
135
|
/**
|
|
190
|
-
*
|
|
191
|
-
* with include/select inference. This is a type-only transformation.
|
|
136
|
+
* Base ZenStack type container. Use with adapter types like WithReact or WithClient.
|
|
192
137
|
*
|
|
193
138
|
* @example
|
|
194
139
|
* ```typescript
|
|
195
|
-
* //
|
|
196
|
-
*
|
|
140
|
+
* // With React adapter:
|
|
141
|
+
* type Typed = WithReact<WithZenStack<SchemaType, "generated">>;
|
|
142
|
+
*
|
|
143
|
+
* // With vanilla client adapter:
|
|
144
|
+
* type Typed = WithClient<WithZenStack<SchemaType, "db">>;
|
|
197
145
|
*
|
|
198
|
-
* //
|
|
199
|
-
*
|
|
146
|
+
* // At root level (no nesting):
|
|
147
|
+
* type Typed = WithReact<WithZenStack<SchemaType>>;
|
|
200
148
|
* ```
|
|
201
149
|
*/
|
|
202
|
-
export
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
} ? TypedTRPCReact<S> : T extends {
|
|
207
|
-
query: any;
|
|
208
|
-
} | {
|
|
209
|
-
mutate: any;
|
|
210
|
-
} ? TypedTRPCClient<S> : TypedTRPCClient<S> & TypedTRPCReact<S>;
|
|
150
|
+
export type WithZenStack<S extends SchemaDef, TPath extends string | undefined = undefined> = {
|
|
151
|
+
readonly __schema: S;
|
|
152
|
+
readonly __path: TPath;
|
|
153
|
+
};
|
|
211
154
|
/**
|
|
212
|
-
*
|
|
155
|
+
* React Query adapter - transforms WithZenStack into tRPC React hook types.
|
|
213
156
|
*
|
|
214
157
|
* @example
|
|
215
158
|
* ```typescript
|
|
216
|
-
* type
|
|
217
|
-
*
|
|
159
|
+
* type Typed = WithReact<WithZenStack<SchemaType, "generated">>;
|
|
160
|
+
* const trpc = typedClient<Typed>()(_trpc);
|
|
218
161
|
* ```
|
|
219
162
|
*/
|
|
220
|
-
export type
|
|
163
|
+
export type WithReact<T extends WithZenStack<any, any>> = T extends WithZenStack<infer S, infer P> ? {
|
|
164
|
+
readonly __types: TypedTRPCReact<S>;
|
|
165
|
+
readonly __path: P;
|
|
166
|
+
} : never;
|
|
221
167
|
/**
|
|
222
|
-
*
|
|
168
|
+
* Vanilla tRPC client adapter - transforms WithZenStack into vanilla client types.
|
|
223
169
|
*
|
|
224
170
|
* @example
|
|
225
171
|
* ```typescript
|
|
226
|
-
*
|
|
172
|
+
* type Typed = WithClient<WithZenStack<SchemaType, "db">>;
|
|
173
|
+
* const client = typedClient<Typed>()(rawClient);
|
|
227
174
|
* ```
|
|
228
175
|
*/
|
|
229
|
-
export
|
|
176
|
+
export type WithClient<T extends WithZenStack<any, any>> = T extends WithZenStack<infer S, infer P> ? {
|
|
177
|
+
readonly __types: TypedTRPCClient<S>;
|
|
178
|
+
readonly __path: P;
|
|
179
|
+
} : never;
|
|
180
|
+
/** Extract the final types from an adapter */
|
|
181
|
+
type ExtractTypes<T> = T extends {
|
|
182
|
+
readonly __types: infer Types;
|
|
183
|
+
} ? Types : never;
|
|
184
|
+
/** Extract the path from an adapter */
|
|
185
|
+
type ExtractPath<T> = T extends {
|
|
186
|
+
readonly __path: infer P;
|
|
187
|
+
} ? P : undefined;
|
|
188
|
+
/** Apply the typed transformation to a client */
|
|
189
|
+
type ApplyTyped<TClient, T> = ExtractPath<T> extends string ? ApplyAtPath<TClient, ExtractPath<T>, ExtractTypes<T>> : ExtractTypes<T>;
|
|
230
190
|
/**
|
|
231
|
-
*
|
|
191
|
+
* Apply composed types to a tRPC client.
|
|
232
192
|
*
|
|
233
193
|
* @example
|
|
234
194
|
* ```typescript
|
|
235
|
-
*
|
|
195
|
+
* // Define composed types
|
|
196
|
+
* type Typed = WithReact<WithZenStack<SchemaType, "generated">>;
|
|
197
|
+
*
|
|
198
|
+
* // Apply to client
|
|
199
|
+
* const _trpc = createTRPCReact<AppRouter>();
|
|
200
|
+
* export const trpc = typedClient<Typed>()(_trpc);
|
|
236
201
|
* ```
|
|
237
202
|
*/
|
|
238
|
-
export declare function
|
|
203
|
+
export declare function typedClient<T extends {
|
|
204
|
+
readonly __types: any;
|
|
205
|
+
readonly __path: any;
|
|
206
|
+
}>(): <TClient>(client: TClient) => ApplyTyped<TClient, T>;
|
|
207
|
+
/** Recursively apply types at a nested path */
|
|
208
|
+
type ApplyAtPath<TClient, Path extends string, TTypes> = Path extends `${infer Head}.${infer Tail}` ? Omit<TClient, Head> & {
|
|
209
|
+
[K in Head]: Head extends keyof TClient ? ApplyAtPath<TClient[Head], Tail, TTypes> : TTypes;
|
|
210
|
+
} : Omit<TClient, Path> & {
|
|
211
|
+
[K in Path]: TTypes;
|
|
212
|
+
};
|
|
239
213
|
export {};
|
|
240
214
|
//# sourceMappingURL=typed-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typed-client.d.ts","sourceRoot":"","sources":["../src/typed-client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"typed-client.d.ts","sourceRoot":"","sources":["../src/typed-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,aAAa,EACb,UAAU,EACV,cAAc,EACd,UAAU,EACV,cAAc,EACd,UAAU,EACV,UAAU,EACV,cAAc,EACd,SAAS,EACT,aAAa,EACb,WAAW,EACX,qBAAqB,EACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EACV,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EAChB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAExD,yFAAyF;AACzF,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,GAAG,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;AAE1G,qDAAqD;AACrD,KAAK,MAAM,CAAC,CAAC,SAAS,SAAS,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,SAAS,OAAO,GAAG,KAAK,IACxF,GAAG,SAAS,IAAI,GACZ,CAAC,qBAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,SAAS,KAAK,GAAG,CAAC,GAAG,qBAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,GACrF,CAAC,qBAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,SAAS,KAAK,GAAG,C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IAAI,GAAG,IAAI,SAAS,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,MAAM;CAAE,GACrH,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG;KAAG,CAAC,IAAI,IAAI,GAAG,MAAM;CAAE,CAAC"}
|
package/dist/typed-client.js
CHANGED
|
@@ -2,68 +2,39 @@
|
|
|
2
2
|
* Typed tRPC client helpers for full include/select type inference.
|
|
3
3
|
*
|
|
4
4
|
* tRPC's standard type inference loses generic type information for procedure
|
|
5
|
-
* input/output types. This module provides type
|
|
6
|
-
* dynamic typing based on include/select options.
|
|
5
|
+
* input/output types. This module provides a composable type system that
|
|
6
|
+
* restores full dynamic typing based on include/select options.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
9
|
* ```typescript
|
|
10
|
-
* import { createTRPCClient } from "@trpc/client";
|
|
11
10
|
* import { createTRPCReact } from "@trpc/react-query";
|
|
12
|
-
* import {
|
|
11
|
+
* import { typedClient, type WithZenStack, type WithReact } from "zenstack-trpc";
|
|
13
12
|
* import type { AppRouter } from "./server/trpc.js";
|
|
14
13
|
* import type { SchemaType } from "./zenstack/schema.js";
|
|
15
14
|
*
|
|
16
|
-
* //
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* );
|
|
15
|
+
* // Compose types and apply to client
|
|
16
|
+
* type Typed = WithReact<WithZenStack<SchemaType>>;
|
|
17
|
+
* const _trpc = createTRPCReact<AppRouter>();
|
|
18
|
+
* export const trpc = typedClient<Typed>()(_trpc);
|
|
20
19
|
*
|
|
21
|
-
* //
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* );
|
|
20
|
+
* // With nested namespace
|
|
21
|
+
* type Typed = WithReact<WithZenStack<SchemaType, "db">>;
|
|
22
|
+
* export const trpc = typedClient<Typed>()(_trpc);
|
|
25
23
|
* ```
|
|
26
24
|
*/
|
|
27
|
-
// =============================================================================
|
|
28
|
-
// Type Converter Utilities
|
|
29
|
-
// =============================================================================
|
|
30
25
|
/**
|
|
31
|
-
*
|
|
32
|
-
* with include/select inference. This is a type-only transformation.
|
|
26
|
+
* Apply composed types to a tRPC client.
|
|
33
27
|
*
|
|
34
28
|
* @example
|
|
35
29
|
* ```typescript
|
|
36
|
-
* //
|
|
37
|
-
*
|
|
30
|
+
* // Define composed types
|
|
31
|
+
* type Typed = WithReact<WithZenStack<SchemaType, "generated">>;
|
|
38
32
|
*
|
|
39
|
-
* //
|
|
40
|
-
* const
|
|
33
|
+
* // Apply to client
|
|
34
|
+
* const _trpc = createTRPCReact<AppRouter>();
|
|
35
|
+
* export const trpc = typedClient<Typed>()(_trpc);
|
|
41
36
|
* ```
|
|
42
37
|
*/
|
|
43
|
-
export function
|
|
44
|
-
return (client) => {
|
|
45
|
-
return client;
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Helper function to type a nested namespace within your tRPC React hooks.
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```typescript
|
|
53
|
-
* export const trpc = withNestedZenStackReact<SchemaType, typeof _trpc, 'db'>('db')(_trpc);
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
export function withNestedZenStackReact(_namespace) {
|
|
57
|
-
return (client) => client;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Helper function to type a nested namespace within your vanilla tRPC client.
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```typescript
|
|
64
|
-
* export const client = withNestedZenStackClient<SchemaType, typeof _client, 'db'>('db')(_client);
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
export function withNestedZenStackClient(_namespace) {
|
|
38
|
+
export function typedClient() {
|
|
68
39
|
return (client) => client;
|
|
69
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod-schemas.d.ts","sourceRoot":"","sources":["../src/zod-schemas.ts"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,QAAQ,CAAC,GAChC,CAAC,CAAC,UAAU,CAcd;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,SAAS,SAAS,EAC1D,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,MAAM,CAAC,QAAQ,CAAC,GAChC,CAAC,CAAC,UAAU,CAiBd;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,SAAS,SAAS,EAC1D,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,MAAM,CAAC,QAAQ,CAAC,GAChC,CAAC,CAAC,UAAU,CAkBd;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,SAAS,SAAS,EACzD,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,MAAM,CAAC,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmIlC"}
|
package/dist/zod-schemas.js
CHANGED
|
@@ -59,15 +59,17 @@ export function createWhereSchema(schema, modelName) {
|
|
|
59
59
|
shape[fieldName] = z.any().optional();
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
|
-
// For scalar fields, allow direct value or filter object
|
|
62
|
+
// For scalar fields, allow direct value, null, or filter object
|
|
63
63
|
const fieldType = fieldDef.type;
|
|
64
64
|
const baseType = getZodTypeForField(fieldType, false, false);
|
|
65
|
+
const nullableBaseType = baseType.nullable();
|
|
65
66
|
shape[fieldName] = z
|
|
66
67
|
.union([
|
|
67
68
|
baseType,
|
|
69
|
+
z.null(),
|
|
68
70
|
z.object({
|
|
69
|
-
equals:
|
|
70
|
-
not:
|
|
71
|
+
equals: nullableBaseType.optional(),
|
|
72
|
+
not: nullableBaseType.optional(),
|
|
71
73
|
in: z.array(baseType).optional(),
|
|
72
74
|
notIn: z.array(baseType).optional(),
|
|
73
75
|
lt: baseType.optional(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zenstack-trpc",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Auto-generate type-safe tRPC routers from ZenStack V3 schemas",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -46,11 +46,23 @@
|
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@trpc/server": ">=11.0.0",
|
|
49
|
+
"@trpc/react-query": ">=11.0.0",
|
|
50
|
+
"@tanstack/react-query": ">=5.0.0",
|
|
49
51
|
"@zenstackhq/orm": ">=3.0.0",
|
|
50
52
|
"zod": ">=3.0.0 || >=4.0.0"
|
|
51
53
|
},
|
|
54
|
+
"peerDependenciesMeta": {
|
|
55
|
+
"@trpc/react-query": {
|
|
56
|
+
"optional": true
|
|
57
|
+
},
|
|
58
|
+
"@tanstack/react-query": {
|
|
59
|
+
"optional": true
|
|
60
|
+
}
|
|
61
|
+
},
|
|
52
62
|
"devDependencies": {
|
|
63
|
+
"@tanstack/react-query": "^5.90.16",
|
|
53
64
|
"@trpc/client": "^11.8.1",
|
|
65
|
+
"@trpc/react-query": "^11.8.1",
|
|
54
66
|
"@trpc/server": "^11.8.1",
|
|
55
67
|
"@types/better-sqlite3": "^7.6.13",
|
|
56
68
|
"@types/node": "^25.0.3",
|