You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+27-3Lines changed: 27 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -295,7 +295,31 @@ const router = t.router({
295
295
296
296
#### Both
297
297
298
-
To use positional arguments _and_ options, use a tuple with an object at the end:
298
+
To use positional arguments _and_ options, the preferred way is to use input schema metadata (e.g. `z.string().meta({positional: true})`. This is available on zod v4, and arktype via `type('string').configure({positional: true})`):
299
+
300
+
```ts
301
+
t.router({
302
+
copy: t.procedure
303
+
.input(
304
+
z.object({
305
+
source: z.string().meta({positional: true}),
306
+
target: z.string().meta({positional: true}),
307
+
mkdirp: z
308
+
.boolean()
309
+
.optional()
310
+
.describe("Ensure target's parent directory exists before copying"),
2) use a tuple with an object at the end (use this if you're on an old version of zod, or using a library which doesn't support `meta`):
299
323
300
324
```ts
301
325
t.router({
@@ -327,7 +351,7 @@ You might use the above with a command like:
327
351
path/to/cli copy a.txt b.txt --mkdirp
328
352
```
329
353
330
-
>Note: object types for options must appear _last_ in the `.input(...)` tuple, when being used with positional arguments. So `z.tuple([z.string(), z.object({mkdirp: z.boolean()}), z.string()])` would not be allowed.
354
+
>Note: when using a tuple, object types for options must appear _last_ in the `.input(...)` tuple, when being used with positional arguments. So `z.tuple([z.string(), z.object({mkdirp: z.boolean()}), z.string()])` would not be allowed (inputs would have to be passed as JSON).
331
355
332
356
>You can pass an existing tRPC router that's primarily designed to be deployed as a server, in order to invoke your procedures directly in development.
Copy file name to clipboardExpand all lines: src/index.ts
+18Lines changed: 18 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -38,6 +38,24 @@ export * as zod from 'zod'
38
38
39
39
export*astrpcServerfrom'@trpc/server'
40
40
41
+
declare module 'zod/v4'{
42
+
interfaceGlobalMeta{
43
+
/**
44
+
* If true, this property will be mapped to a positional CLI argument by trpc-cli. Only valid for string, number, or boolean types (or arrays of these types).
45
+
* Note: the order of positional arguments is determined by the order of properties in the schema.
0 commit comments