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
support arktype (generalise json-schemable validation libraries) (#59)
Be less zod-biased, so that arktype (or in theory another validation
library implementing `.toJsonSchema()`) can be used instead of zod.
Mostly out of my own curiosity, and zod will remain the recommended way
to use this, but feels sensible to not be too coupled to zod.
Notes:
- arktype's `.toJsonSchema()` doesn't always produce a usable json
schema, see arktypeio/arktype#1379 and
arktype.test.ts
- removes some overly-clever logic that attempts to smart-parse
positional arguments based on zod tuple elements etc. Still support
distinction between number and integer and string (so that `mycli foo
2.2` will parse as `"2.2"` for an input of type `z.union([z.string(),
z.number().int()])`. But even this is arguably too smart. Maybe an
argument of type `z.union([z.string(), z.number()])` should just always
parse as a number
Future:
- valibot
- typebox
- effect
- more??
- maybe a proposal to add `.toJsonSchema()` to the standard-schema spec?
I doubt it would be accpeted, but maybe, if there were some official
caveats like it being optional, and it being able to rely on external
libs or something
- maybe even more logic around how to pick a winner in a union
- probably an env var to allow doing something like
`TRPC_CLI_JSON_INPUTS=true mycli foo --input '{"xx": 1, "yy" 2}'` - idea
being that if you don't like the way this library has transformed the
input type into CLI arguments, you can opt out as an escape hatch
---------
Co-authored-by: Misha Kaletsky <[email protected]>
Note: you will need to install `arktype` as a dependency separately
531
+
Note: some arktype features result in types that can't be converted cleanly to CLI args/options, so for some procedures you may need to use the `--input` flag to pass in a JSON string. Check your CLI help text to see if this is the case.
532
+
507
533
## tRPC v10 vs v11
508
534
509
535
Both versions 10 and 11 of `@trpc/server` are both supported, but if using tRPC v11 you must pass in your `@trpc/server` module to `createCli`:
@@ -958,11 +984,15 @@ You can then use tab-completion to autocomplete commands and flags.
958
984
959
985
### Implementation and dependencies
960
986
987
+
All dependencies have zero dependencies of their own, so the dependency tree is very shallow.
988
+
989
+
-[@trpc/server](https://npmjs.com/package/@trpc/server) for the trpc router
961
990
-[commander](https://npmjs.com/package/commander) for parsing arguments before passing to trpc
991
+
-[zod](https://npmjs.com/package/zod) for input validation, included for convenience
962
992
-[zod-to-json-schema](https://npmjs.com/package/zod-to-json-schema) to convert zod schemas to make them easier to recurse and format help text from
963
993
-[zod-validation-error](https://npmjs.com/package/zod-validation-error) to make bad inputs have readable error messages
964
994
965
-
`zod` and `@tprc/server` are peer dependencies - right now only zod 3+ and @trpc/server 10+ have been tested, but it may work with most versions of zod.
995
+
`zod` and `@tprc/server` are included as dependencies for convenience, but you can use your own separate installations if you prefer. Zod 3+ and @trpc/server 10 and 11, have been tested. It should work with most versions of zod.
0 commit comments