zenstack-trpc 0.1.0 → 0.1.3

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 CHANGED
@@ -9,16 +9,12 @@ Auto-generate fully type-safe tRPC routers from [ZenStack V3](https://zenstack.d
9
9
  - **Dynamic result typing** - `include`/`select` options reflected in return types
10
10
  - **Zod validation** - Runtime input validation built-in
11
11
  - **All CRUD operations** - findMany, findUnique, create, update, delete, and more
12
- - **Standard tRPC** - Works with all tRPC adapters (HTTP, WebSocket, Next.js, etc.)
12
+ - **Standard tRPC** - Works with all tRPC adapters and clients
13
13
 
14
14
  ## Installation
15
15
 
16
16
  ```bash
17
17
  npm install zenstack-trpc @trpc/server @zenstackhq/orm zod
18
- # or
19
- pnpm add zenstack-trpc @trpc/server @zenstackhq/orm zod
20
- # or
21
- yarn add zenstack-trpc @trpc/server @zenstackhq/orm zod
22
18
  ```
23
19
 
24
20
  ## Quick Start
@@ -57,92 +53,87 @@ npx zenstack generate
57
53
  ### 3. Create the tRPC router
58
54
 
59
55
  ```typescript
56
+ // server/trpc.ts
57
+ import { initTRPC } from "@trpc/server";
60
58
  import { ZenStackClient } from "@zenstackhq/orm";
61
- import { schema, SchemaType } from "./zenstack/schema.js";
62
- import {
63
- createTRPC,
64
- createZenStackRouter,
65
- type Context,
66
- type TypedRouterCaller,
67
- } from "zenstack-trpc";
59
+ import { schema } from "./zenstack/schema.js";
60
+ import { createZenStackRouter } from "zenstack-trpc";
68
61
 
69
62
  // Create your database client
70
63
  const db = new ZenStackClient(schema, {
71
64
  dialect: yourDialect, // Kysely dialect (SQLite, PostgreSQL, MySQL, etc.)
72
65
  });
73
66
 
74
- // Create tRPC instance
75
- const t = createTRPC<Context>();
76
-
77
- // Generate the router from your schema
78
- const appRouter = createZenStackRouter(schema, t);
67
+ // Create your tRPC instance
68
+ const t = initTRPC.context<{ db: typeof db }>().create();
79
69
 
80
- // Export for client usage
70
+ // Generate the router
71
+ export const appRouter = createZenStackRouter(schema, t);
81
72
  export type AppRouter = typeof appRouter;
82
73
  ```
83
74
 
84
- ### 4. Use the router
75
+ ### 4. Use with tRPC client
85
76
 
86
77
  ```typescript
87
- // Create a typed caller
88
- const caller = appRouter.createCaller({ db }) as TypedRouterCaller<SchemaType>;
78
+ // client.ts
79
+ import { createTRPCClient, httpBatchLink } from "@trpc/client";
80
+ import type { AppRouter } from "./server/trpc.js";
81
+
82
+ const client = createTRPCClient<AppRouter>({
83
+ links: [httpBatchLink({ url: "http://localhost:3000/trpc" })],
84
+ });
89
85
 
90
86
  // All operations are fully typed!
91
- const users = await caller.user.findMany();
92
- // ^? { id: string, email: string, name: string | null, ... }[]
87
+ const users = await client.user.findMany.query();
93
88
 
94
- // Include relations - return type automatically includes them
95
- const usersWithPosts = await caller.user.findMany({
96
- include: { posts: true }
89
+ // Include relations
90
+ const usersWithPosts = await client.user.findMany.query({
91
+ include: { posts: true },
97
92
  });
98
- // ^? { id: string, ..., posts: Post[] }[]
99
93
 
100
- // Select specific fields
101
- const emails = await caller.user.findMany({
102
- select: { id: true, email: true }
103
- });
104
- // ^? { id: string, email: string }[]
105
-
106
- // Create with full validation
107
- const user = await caller.user.create({
108
- data: {
109
- email: "alice@example.com",
110
- name: "Alice",
111
- },
94
+ // Create with validation
95
+ const user = await client.user.create.mutate({
96
+ data: { email: "alice@example.com", name: "Alice" },
112
97
  });
113
98
 
114
- // Update with type-safe where clause
115
- await caller.user.update({
99
+ // Update
100
+ await client.user.update.mutate({
116
101
  where: { id: user.id },
117
102
  data: { name: "Alice Smith" },
118
103
  });
119
104
  ```
120
105
 
121
- ## API Reference
106
+ ## Generated Router Structure
122
107
 
123
- ### `createTRPC<Context>()`
108
+ For each model in your schema, the following procedures are generated:
124
109
 
125
- Creates a tRPC instance with the given context type.
110
+ | Queries | Mutations |
111
+ |---------|-----------|
112
+ | findMany | create |
113
+ | findUnique | createMany |
114
+ | findFirst | update |
115
+ | count | updateMany |
116
+ | aggregate | upsert |
117
+ | groupBy | delete |
118
+ | | deleteMany |
126
119
 
127
- ```typescript
128
- import { createTRPC, type Context } from "zenstack-trpc";
129
-
130
- const t = createTRPC<Context>();
131
- ```
120
+ ## API Reference
132
121
 
133
122
  ### `createZenStackRouter(schema, t)`
134
123
 
135
124
  Generates a tRPC router from a ZenStack schema.
136
125
 
137
126
  ```typescript
127
+ import { initTRPC } from "@trpc/server";
138
128
  import { createZenStackRouter } from "zenstack-trpc";
139
129
 
130
+ const t = initTRPC.context<{ db: any }>().create();
140
131
  const appRouter = createZenStackRouter(schema, t);
141
132
  ```
142
133
 
143
134
  ### `TypedRouterCaller<SchemaType>`
144
135
 
145
- Type helper for fully typed caller with dynamic input/output inference.
136
+ Type helper for server-side caller with full type inference.
146
137
 
147
138
  ```typescript
148
139
  import type { TypedRouterCaller } from "zenstack-trpc";
@@ -151,130 +142,19 @@ import type { SchemaType } from "./zenstack/schema.js";
151
142
  const caller = appRouter.createCaller({ db }) as TypedRouterCaller<SchemaType>;
152
143
  ```
153
144
 
154
- ### `TypedModelProcedures<Schema, Model>`
155
-
156
- Type helper for a single model's procedures.
157
-
158
- ```typescript
159
- import type { TypedModelProcedures } from "zenstack-trpc";
160
-
161
- type UserProcedures = TypedModelProcedures<SchemaType, "User">;
162
- ```
163
-
164
- ## Generated Router Structure
165
-
166
- For each model in your schema, the following procedures are generated:
167
-
168
- ```
169
- router
170
- ├── user
171
- │ ├── findMany (query)
172
- │ ├── findUnique (query)
173
- │ ├── findFirst (query)
174
- │ ├── create (mutation)
175
- │ ├── createMany (mutation)
176
- │ ├── update (mutation)
177
- │ ├── updateMany (mutation)
178
- │ ├── upsert (mutation)
179
- │ ├── delete (mutation)
180
- │ ├── deleteMany (mutation)
181
- │ ├── count (query)
182
- │ ├── aggregate (query)
183
- │ └── groupBy (query)
184
- ├── post
185
- │ └── ... (same operations)
186
- ```
187
-
188
- ## Using with tRPC Adapters
189
-
190
- ### Standalone HTTP Server
191
-
192
- ```typescript
193
- import { createHTTPServer } from "@trpc/server/adapters/standalone";
194
-
195
- const server = createHTTPServer({
196
- router: appRouter,
197
- createContext: () => ({ db }),
198
- });
199
-
200
- server.listen(3000);
201
- ```
202
-
203
- ### Next.js App Router
204
-
205
- ```typescript
206
- // app/api/trpc/[trpc]/route.ts
207
- import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
208
-
209
- const handler = (req: Request) =>
210
- fetchRequestHandler({
211
- endpoint: "/api/trpc",
212
- req,
213
- router: appRouter,
214
- createContext: () => ({ db }),
215
- });
216
-
217
- export { handler as GET, handler as POST };
218
- ```
219
-
220
- ### Express
221
-
222
- ```typescript
223
- import express from "express";
224
- import { createExpressMiddleware } from "@trpc/server/adapters/express";
225
-
226
- const app = express();
227
-
228
- app.use(
229
- "/trpc",
230
- createExpressMiddleware({
231
- router: appRouter,
232
- createContext: () => ({ db }),
233
- })
234
- );
235
- ```
236
-
237
- ## Advanced Usage
238
-
239
- ### Custom Context
240
-
241
- Extend the context with authentication or other data:
242
-
243
- ```typescript
244
- interface MyContext extends Context {
245
- db: any;
246
- userId?: string;
247
- }
248
-
249
- const t = createTRPC<MyContext>();
250
- const appRouter = createZenStackRouter(schema, t);
251
-
252
- // In your adapter
253
- createContext: (opts) => ({
254
- db: getEnhancedDb(opts.req), // ZenStack enhanced client with access control
255
- userId: getUserFromRequest(opts.req),
256
- });
257
- ```
258
-
259
145
  ### Zod Schema Access
260
146
 
261
147
  Access the generated Zod schemas for custom validation:
262
148
 
263
149
  ```typescript
264
- import {
265
- createModelSchemas,
266
- createWhereSchema,
267
- createCreateDataSchema,
268
- } from "zenstack-trpc";
150
+ import { createModelSchemas, createWhereSchema } from "zenstack-trpc";
269
151
 
270
152
  const userSchemas = createModelSchemas(schema, "User");
271
- const whereSchema = createWhereSchema(schema, "User");
272
153
  ```
273
154
 
274
155
  ## Requirements
275
156
 
276
157
  - Node.js >= 18
277
- - TypeScript >= 5.0
278
158
  - ZenStack V3 (`@zenstackhq/orm` >= 3.0.0)
279
159
  - tRPC >= 11.0.0
280
160
  - Zod >= 3.0.0
package/dist/index.d.ts CHANGED
@@ -5,20 +5,19 @@
5
5
  *
6
6
  * @example
7
7
  * ```typescript
8
+ * import { initTRPC } from "@trpc/server";
8
9
  * import { ZenStackClient } from "@zenstackhq/orm";
9
10
  * import { schema, SchemaType } from "./zenstack/schema.js";
10
- * import {
11
- * createTRPC,
12
- * createZenStackRouter,
13
- * type Context,
14
- * type TypedRouterCaller,
15
- * } from "zenstack-trpc";
11
+ * import { createZenStackRouter, type TypedRouterCaller } from "zenstack-trpc";
16
12
  *
17
- * const db = new ZenStackClient(schema, { dialect: yourDialect });
18
- * const t = createTRPC<Context>();
13
+ * // Create your tRPC instance with your context
14
+ * const t = initTRPC.context<{ db: any }>().create();
15
+ *
16
+ * // Generate the router
19
17
  * const appRouter = createZenStackRouter(schema, t);
20
18
  *
21
19
  * // Create a typed caller with full type inference
20
+ * const db = new ZenStackClient(schema, { dialect: yourDialect });
22
21
  * const caller = appRouter.createCaller({ db }) as TypedRouterCaller<SchemaType>;
23
22
  *
24
23
  * // All operations are fully typed!
@@ -27,6 +26,6 @@
27
26
  *
28
27
  * @packageDocumentation
29
28
  */
30
- export { createTRPC, createZenStackRouter, type Context, type ZenStackRouter, type TypedRouterCaller, type TypedModelProcedures, type TRPCInstance, } from "./router-generator.js";
29
+ export { createZenStackRouter, type ZenStackRouter, type ZenStackRouterRecord, type TRPCModelProcedures, type TypedRouterCaller, type TypedModelProcedures, type TRPCInstance, } from "./router-generator.js";
31
30
  export { createModelSchemas, createWhereSchema, createCreateDataSchema, createUpdateDataSchema, createUniqueWhereSchema, createSelectSchema, createIncludeSchema, createOrderBySchema, } from "./zod-schemas.js";
32
31
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,YAAY,GAClB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC"}
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,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,YAAY,GAClB,MAAM,uBAAuB,CAAC;AAG/B,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
@@ -5,20 +5,19 @@
5
5
  *
6
6
  * @example
7
7
  * ```typescript
8
+ * import { initTRPC } from "@trpc/server";
8
9
  * import { ZenStackClient } from "@zenstackhq/orm";
9
10
  * import { schema, SchemaType } from "./zenstack/schema.js";
10
- * import {
11
- * createTRPC,
12
- * createZenStackRouter,
13
- * type Context,
14
- * type TypedRouterCaller,
15
- * } from "zenstack-trpc";
11
+ * import { createZenStackRouter, type TypedRouterCaller } from "zenstack-trpc";
16
12
  *
17
- * const db = new ZenStackClient(schema, { dialect: yourDialect });
18
- * const t = createTRPC<Context>();
13
+ * // Create your tRPC instance with your context
14
+ * const t = initTRPC.context<{ db: any }>().create();
15
+ *
16
+ * // Generate the router
19
17
  * const appRouter = createZenStackRouter(schema, t);
20
18
  *
21
19
  * // Create a typed caller with full type inference
20
+ * const db = new ZenStackClient(schema, { dialect: yourDialect });
22
21
  * const caller = appRouter.createCaller({ db }) as TypedRouterCaller<SchemaType>;
23
22
  *
24
23
  * // All operations are fully typed!
@@ -28,6 +27,6 @@
28
27
  * @packageDocumentation
29
28
  */
30
29
  // Router generator and types
31
- export { createTRPC, createZenStackRouter, } from "./router-generator.js";
30
+ export { createZenStackRouter, } from "./router-generator.js";
32
31
  // Zod schema generators (for advanced usage)
33
32
  export { createModelSchemas, createWhereSchema, createCreateDataSchema, createUpdateDataSchema, createUniqueWhereSchema, createSelectSchema, createIncludeSchema, createOrderBySchema, } from "./zod-schemas.js";
@@ -1,27 +1,6 @@
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
- /**
4
- * Context type for the tRPC router
5
- * The db property accepts any ZenStack client instance
6
- */
7
- export interface Context {
8
- db: any;
9
- }
10
- declare const _initTRPCResult: import("@trpc/server").TRPCRootObject<Context, object, import("@trpc/server").TRPCRuntimeConfigOptions<Context, object>, {
11
- ctx: Context;
12
- meta: object;
13
- errorShape: import("@trpc/server").TRPCDefaultErrorShape;
14
- transformer: false;
15
- }>;
16
- /**
17
- * Type representing the result of initTRPC.context().create()
18
- */
19
- export type TRPCInstance = typeof _initTRPCResult;
20
- /**
21
- * Creates a tRPC instance with the given context
22
- * @returns A tRPC instance configured with your context type
23
- */
24
- export declare function createTRPC<TContext extends Context>(): TRPCInstance;
3
+ import { z } from "zod";
25
4
  /**
26
5
  * Type helper to convert model names to lowercase
27
6
  */
@@ -118,167 +97,132 @@ export interface TypedModelProcedures<Schema extends SchemaDef, Model extends Ge
118
97
  export type TypedRouterCaller<Schema extends SchemaDef> = {
119
98
  [K in GetModels<Schema> as Uncapitalize<K>]: TypedModelProcedures<Schema, K>;
120
99
  };
100
+ /**
101
+ * Minimal tRPC instance interface required by createZenStackRouter
102
+ */
103
+ export interface TRPCInstance {
104
+ procedure: {
105
+ input: (schema: z.ZodType) => {
106
+ query: (handler: (opts: {
107
+ ctx: any;
108
+ input: any;
109
+ }) => Promise<any>) => any;
110
+ mutation: (handler: (opts: {
111
+ ctx: any;
112
+ input: any;
113
+ }) => Promise<any>) => any;
114
+ };
115
+ };
116
+ router: (procedures: Record<string, any>) => any;
117
+ }
121
118
  /**
122
119
  * Creates a tRPC router from a ZenStack schema.
123
120
  *
124
121
  * The router follows the pattern: router.modelName.operation
125
122
  * Example: router.user.findMany(), router.post.create()
126
123
  *
127
- * For proper typing on the caller, use the TypedRouterCaller type:
128
- *
129
124
  * @example
130
125
  * ```ts
131
- * import { createZenStackRouter, createTRPC, Context, TypedRouterCaller } from './trpc';
132
- * import { schema, SchemaType } from '../zenstack/schema';
126
+ * import { createZenStackRouter, ZenStackRouter } from 'zenstack-trpc';
127
+ * import { initTRPC } from '@trpc/server';
128
+ * import { schema, SchemaType } from './zenstack/schema';
133
129
  *
134
- * const t = createTRPC<Context>();
135
- * const appRouter = createZenStackRouter(schema, t);
136
- *
137
- * // Create a typed caller with FULL type inference
138
- * const caller = appRouter.createCaller({ db }) as TypedRouterCaller<SchemaType>;
130
+ * // Create your own tRPC instance with your context
131
+ * const t = initTRPC.context<{ db: typeof dbClient }>().create();
139
132
  *
140
- * // Types are fully inferred based on your query!
141
- * const users = await caller.user.findMany();
142
- * // ^? { id: string, email: string, name: string | null, ... }[]
143
- *
144
- * const usersWithPosts = await caller.user.findMany({ include: { posts: true } });
145
- * // ^? { id: string, email: string, ..., posts: Post[] }[]
133
+ * // Generate the router with full type inference
134
+ * const appRouter = createZenStackRouter(schema, t);
146
135
  *
136
+ * // Export the typed router for clients
147
137
  * export type AppRouter = typeof appRouter;
138
+ *
139
+ * // Client usage (with full type inference):
140
+ * // const client = createTRPCClient<AppRouter>({ ... });
141
+ * // const users = await client.user.findMany.query(); // Fully typed!
148
142
  * ```
149
143
  */
150
- export declare function createZenStackRouter<Schema extends SchemaDef>(schema: Schema, t: TRPCInstance): import("@trpc/server").TRPCBuiltRouter<{
151
- ctx: Context;
152
- meta: object;
153
- errorShape: import("@trpc/server").TRPCDefaultErrorShape;
154
- transformer: false;
155
- }, import("@trpc/server").TRPCDecorateCreateRouterOptions<Record<string, import("@trpc/server").TRPCBuiltRouter<{
156
- ctx: Context;
157
- meta: object;
158
- errorShape: import("@trpc/server").TRPCDefaultErrorShape;
159
- transformer: false;
160
- }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
161
- findMany: import("@trpc/server").TRPCQueryProcedure<{
162
- input: unknown;
163
- output: any;
164
- meta: object;
165
- }> | import("@trpc/server").TRPCMutationProcedure<{
166
- input: unknown;
167
- output: any;
168
- meta: object;
169
- }>;
170
- findUnique: import("@trpc/server").TRPCQueryProcedure<{
171
- input: unknown;
172
- output: any;
173
- meta: object;
174
- }> | import("@trpc/server").TRPCMutationProcedure<{
175
- input: unknown;
176
- output: any;
177
- meta: object;
178
- }>;
179
- findFirst: import("@trpc/server").TRPCQueryProcedure<{
180
- input: unknown;
181
- output: any;
182
- meta: object;
183
- }> | import("@trpc/server").TRPCMutationProcedure<{
184
- input: unknown;
185
- output: any;
186
- meta: object;
187
- }>;
188
- count: import("@trpc/server").TRPCQueryProcedure<{
189
- input: unknown;
190
- output: any;
191
- meta: object;
192
- }> | import("@trpc/server").TRPCMutationProcedure<{
193
- input: unknown;
194
- output: any;
195
- meta: object;
196
- }>;
197
- aggregate: import("@trpc/server").TRPCQueryProcedure<{
198
- input: unknown;
199
- output: any;
200
- meta: object;
201
- }> | import("@trpc/server").TRPCMutationProcedure<{
202
- input: unknown;
203
- output: any;
204
- meta: object;
205
- }>;
206
- groupBy: import("@trpc/server").TRPCQueryProcedure<{
207
- input: unknown;
208
- output: any;
209
- meta: object;
210
- }> | import("@trpc/server").TRPCMutationProcedure<{
211
- input: unknown;
212
- output: any;
213
- meta: object;
214
- }>;
215
- create: import("@trpc/server").TRPCQueryProcedure<{
216
- input: unknown;
217
- output: any;
218
- meta: object;
219
- }> | import("@trpc/server").TRPCMutationProcedure<{
220
- input: unknown;
221
- output: any;
222
- meta: object;
223
- }>;
224
- createMany: import("@trpc/server").TRPCQueryProcedure<{
225
- input: unknown;
226
- output: any;
227
- meta: object;
228
- }> | import("@trpc/server").TRPCMutationProcedure<{
229
- input: unknown;
230
- output: any;
231
- meta: object;
232
- }>;
233
- update: import("@trpc/server").TRPCQueryProcedure<{
234
- input: unknown;
235
- output: any;
236
- meta: object;
237
- }> | import("@trpc/server").TRPCMutationProcedure<{
238
- input: unknown;
239
- output: any;
240
- meta: object;
241
- }>;
242
- updateMany: import("@trpc/server").TRPCQueryProcedure<{
243
- input: unknown;
244
- output: any;
245
- meta: object;
246
- }> | import("@trpc/server").TRPCMutationProcedure<{
247
- input: unknown;
248
- output: any;
249
- meta: object;
250
- }>;
251
- upsert: import("@trpc/server").TRPCQueryProcedure<{
252
- input: unknown;
253
- output: any;
254
- meta: object;
255
- }> | import("@trpc/server").TRPCMutationProcedure<{
256
- input: unknown;
257
- output: any;
258
- meta: object;
144
+ export declare function createZenStackRouter<Schema extends SchemaDef, TContext extends {
145
+ db: any;
146
+ }>(schema: Schema, t: TRPCInstance): ZenStackRouter<Schema, TContext>;
147
+ /**
148
+ * Type for a query procedure with proper input/output typing
149
+ * Matches tRPC's internal structure for type inference
150
+ */
151
+ type TypedQueryProcedure<TInput, TOutput> = {
152
+ _def: {
153
+ $types: {
154
+ input: TInput;
155
+ output: TOutput;
156
+ };
157
+ procedure: true;
158
+ type: 'query';
159
+ meta: unknown;
160
+ experimental_caller: boolean;
161
+ };
162
+ };
163
+ /**
164
+ * Type for a mutation procedure with proper input/output typing
165
+ * Matches tRPC's internal structure for type inference
166
+ */
167
+ type TypedMutationProcedure<TInput, TOutput> = {
168
+ _def: {
169
+ $types: {
170
+ input: TInput;
171
+ output: TOutput;
172
+ };
173
+ procedure: true;
174
+ type: 'mutation';
175
+ meta: unknown;
176
+ experimental_caller: boolean;
177
+ };
178
+ };
179
+ /**
180
+ * Type for a single model's tRPC procedures (for client inference)
181
+ * This maps each operation to its tRPC procedure type with proper input/output
182
+ */
183
+ export type TRPCModelProcedures<Schema extends SchemaDef, Model extends GetModels<Schema>, TContext> = {
184
+ findMany: TypedQueryProcedure<FindManyArgs<Schema, Model> | undefined, SimplifiedPlainResult<Schema, Model, {}>[]>;
185
+ findUnique: TypedQueryProcedure<FindUniqueArgs<Schema, Model>, SimplifiedPlainResult<Schema, Model, {}> | null>;
186
+ findFirst: TypedQueryProcedure<FindFirstArgs<Schema, Model> | undefined, SimplifiedPlainResult<Schema, Model, {}> | null>;
187
+ create: TypedMutationProcedure<CreateArgs<Schema, Model>, SimplifiedPlainResult<Schema, Model, {}>>;
188
+ createMany: TypedMutationProcedure<CreateManyArgs<Schema, Model>, {
189
+ count: number;
259
190
  }>;
260
- delete: import("@trpc/server").TRPCQueryProcedure<{
261
- input: unknown;
262
- output: any;
263
- meta: object;
264
- }> | import("@trpc/server").TRPCMutationProcedure<{
265
- input: unknown;
266
- output: any;
267
- meta: object;
191
+ update: TypedMutationProcedure<UpdateArgs<Schema, Model>, SimplifiedPlainResult<Schema, Model, {}>>;
192
+ updateMany: TypedMutationProcedure<UpdateManyArgs<Schema, Model>, {
193
+ count: number;
268
194
  }>;
269
- deleteMany: import("@trpc/server").TRPCQueryProcedure<{
270
- input: unknown;
271
- output: any;
272
- meta: object;
273
- }> | import("@trpc/server").TRPCMutationProcedure<{
274
- input: unknown;
275
- output: any;
276
- meta: object;
195
+ upsert: TypedMutationProcedure<UpsertArgs<Schema, Model>, SimplifiedPlainResult<Schema, Model, {}>>;
196
+ delete: TypedMutationProcedure<DeleteArgs<Schema, Model>, SimplifiedPlainResult<Schema, Model, {}>>;
197
+ deleteMany: TypedMutationProcedure<DeleteManyArgs<Schema, Model>, {
198
+ count: number;
277
199
  }>;
278
- }>>>>>;
200
+ count: TypedQueryProcedure<CountArgs<Schema, Model> | undefined, number>;
201
+ aggregate: TypedQueryProcedure<AggregateArgs<Schema, Model>, any>;
202
+ groupBy: TypedQueryProcedure<GroupByArgs<Schema, Model>, any[]>;
203
+ };
279
204
  /**
280
- * Type helper to extract the router type for a given schema
205
+ * Type for the full router record that tRPC uses for inference
281
206
  */
282
- export type ZenStackRouter<Schema extends SchemaDef> = ReturnType<typeof createZenStackRouter<Schema>>;
207
+ export type ZenStackRouterRecord<Schema extends SchemaDef, TContext> = {
208
+ [K in GetModels<Schema> as Uncapitalize<K>]: TRPCModelProcedures<Schema, K, TContext>;
209
+ };
210
+ /**
211
+ * The typed router type that clients can use for proper inference
212
+ */
213
+ export type ZenStackRouter<Schema extends SchemaDef, TContext = any> = {
214
+ _def: {
215
+ _config: {
216
+ $types: {
217
+ ctx: TContext;
218
+ meta: object;
219
+ errorShape: any;
220
+ transformer: false;
221
+ };
222
+ };
223
+ record: ZenStackRouterRecord<Schema, TContext>;
224
+ };
225
+ createCaller: (ctx: TContext) => TypedRouterCaller<Schema>;
226
+ };
283
227
  export {};
284
228
  //# sourceMappingURL=router-generator.d.ts.map
@@ -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,iBAAiB,CAAC;AAIzB;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,GAAG,CAAC;CACT;AAGD,QAAA,MAAM,eAAe;;;;;EAAuC,CAAC;AAE7D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AAM,EAAE;gBACN,GAAG,EAAE,QAAQ,CAAC;gBACd,IAAI,EAAE,MAAM,CAAC;gBACb,UAAU,EAAE,GAAG,CAAC;gBAChB,WAAW,EAAE,KAAK,CAAC;aACpB,CAAC;SACH,CAAC;QACF,MAAM,EAAE,oBAAoB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;KAChD,CAAC;IACF,YAAY,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,iBAAiB,CAAC,MAAM,CAAC,CAAC;CAC5D,CAAC"}
@@ -1,14 +1,5 @@
1
- import { initTRPC, TRPCError } from "@trpc/server";
1
+ import { TRPCError } from "@trpc/server";
2
2
  import { createModelSchemas } from "./zod-schemas.js";
3
- // Internal type for initTRPC result
4
- const _initTRPCResult = initTRPC.context().create();
5
- /**
6
- * Creates a tRPC instance with the given context
7
- * @returns A tRPC instance configured with your context type
8
- */
9
- export function createTRPC() {
10
- return initTRPC.context().create();
11
- }
12
3
  /**
13
4
  * Creates procedures for a single model
14
5
  */
@@ -58,27 +49,24 @@ function createModelProcedures(schema, modelName, t) {
58
49
  * The router follows the pattern: router.modelName.operation
59
50
  * Example: router.user.findMany(), router.post.create()
60
51
  *
61
- * For proper typing on the caller, use the TypedRouterCaller type:
62
- *
63
52
  * @example
64
53
  * ```ts
65
- * import { createZenStackRouter, createTRPC, Context, TypedRouterCaller } from './trpc';
66
- * import { schema, SchemaType } from '../zenstack/schema';
54
+ * import { createZenStackRouter, ZenStackRouter } from 'zenstack-trpc';
55
+ * import { initTRPC } from '@trpc/server';
56
+ * import { schema, SchemaType } from './zenstack/schema';
67
57
  *
68
- * const t = createTRPC<Context>();
69
- * const appRouter = createZenStackRouter(schema, t);
58
+ * // Create your own tRPC instance with your context
59
+ * const t = initTRPC.context<{ db: typeof dbClient }>().create();
70
60
  *
71
- * // Create a typed caller with FULL type inference
72
- * const caller = appRouter.createCaller({ db }) as TypedRouterCaller<SchemaType>;
73
- *
74
- * // Types are fully inferred based on your query!
75
- * const users = await caller.user.findMany();
76
- * // ^? { id: string, email: string, name: string | null, ... }[]
77
- *
78
- * const usersWithPosts = await caller.user.findMany({ include: { posts: true } });
79
- * // ^? { id: string, email: string, ..., posts: Post[] }[]
61
+ * // Generate the router with full type inference
62
+ * const appRouter = createZenStackRouter(schema, t);
80
63
  *
64
+ * // Export the typed router for clients
81
65
  * export type AppRouter = typeof appRouter;
66
+ *
67
+ * // Client usage (with full type inference):
68
+ * // const client = createTRPCClient<AppRouter>({ ... });
69
+ * // const users = await client.user.findMany.query(); // Fully typed!
82
70
  * ```
83
71
  */
84
72
  export function createZenStackRouter(schema, t) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zenstack-trpc",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "Auto-generate type-safe tRPC routers from ZenStack V3 schemas",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -17,13 +17,6 @@
17
17
  "README.md",
18
18
  "LICENSE"
19
19
  ],
20
- "scripts": {
21
- "build": "tsc -p tsconfig.build.json",
22
- "prepublishOnly": "pnpm run build",
23
- "test": "vitest run",
24
- "test:watch": "vitest",
25
- "typecheck": "tsc --noEmit"
26
- },
27
20
  "keywords": [
28
21
  "zenstack",
29
22
  "trpc",
@@ -55,6 +48,7 @@
55
48
  "zod": ">=3.0.0 || >=4.0.0"
56
49
  },
57
50
  "devDependencies": {
51
+ "@trpc/client": "^11.8.1",
58
52
  "@trpc/server": "^11.8.1",
59
53
  "@types/better-sqlite3": "^7.6.13",
60
54
  "@types/node": "^25.0.3",
@@ -67,5 +61,11 @@
67
61
  "typescript": "^5.9.3",
68
62
  "vitest": "^4.0.16",
69
63
  "zod": "^4.3.5"
64
+ },
65
+ "scripts": {
66
+ "build": "tsc -p tsconfig.build.json",
67
+ "test": "vitest run",
68
+ "test:watch": "vitest",
69
+ "typecheck": "tsc --noEmit"
70
70
  }
71
- }
71
+ }