@orpc/zod 0.0.0-next.e9dc36e → 0.0.0-next.ef3ba82

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/dist/index.js CHANGED
@@ -145,4 +145,3 @@ export {
145
145
  regexp,
146
146
  url
147
147
  };
148
- //# sourceMappingURL=index.js.map
@@ -28,4 +28,3 @@ export declare const oz: {
28
28
  url: typeof url;
29
29
  };
30
30
  export {};
31
- //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,21 +1,17 @@
1
1
  {
2
2
  "name": "@orpc/zod",
3
3
  "type": "module",
4
- "version": "0.0.0-next.e9dc36e",
5
- "author": {
6
- "name": "unnoq",
7
- "email": "contact@unnoq.com",
8
- "url": "https://unnoq.com"
9
- },
4
+ "version": "0.0.0-next.ef3ba82",
10
5
  "license": "MIT",
11
- "homepage": "https://github.com/unnoq/orpc",
6
+ "homepage": "https://orpc.unnoq.com",
12
7
  "repository": {
13
8
  "type": "git",
14
- "url": "https://github.com/unnoq/orpc.git",
9
+ "url": "git+https://github.com/unnoq/orpc.git",
15
10
  "directory": "packages/zod"
16
11
  },
17
12
  "keywords": [
18
- "unnoq"
13
+ "unnoq",
14
+ "orpc"
19
15
  ],
20
16
  "exports": {
21
17
  ".": {
@@ -28,8 +24,8 @@
28
24
  }
29
25
  },
30
26
  "files": [
31
- "dist",
32
- "src"
27
+ "!dist/*.tsbuildinfo",
28
+ "dist"
33
29
  ],
34
30
  "dependencies": {
35
31
  "json-schema-typed": "^8.0.1",
@@ -37,7 +33,7 @@
37
33
  "zod": "^3.23.8"
38
34
  },
39
35
  "scripts": {
40
- "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
36
+ "build": "tsup --clean --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
41
37
  "build:watch": "pnpm run build --watch",
42
38
  "type:check": "tsc -b"
43
39
  }
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/// <reference lib=\"dom\" />\n\nimport type { JSONSchema } from 'json-schema-typed/draft-2020-12'\n\nimport wcmatch from 'wildcard-match'\nimport {\n custom,\n type CustomErrorParams,\n type input,\n type output,\n type ZodEffects,\n type ZodType,\n type ZodTypeAny,\n type ZodTypeDef,\n} from 'zod'\n\nexport type CustomZodType = 'File' | 'Blob' | 'Invalid Date' | 'RegExp' | 'URL'\n\nconst customZodTypeSymbol = Symbol('customZodTypeSymbol')\n\nconst customZodFileMimeTypeSymbol = Symbol('customZodFileMimeTypeSymbol')\n\nconst CUSTOM_JSON_SCHEMA_SYMBOL = Symbol('CUSTOM_JSON_SCHEMA')\nconst CUSTOM_JSON_SCHEMA_INPUT_SYMBOL = Symbol('CUSTOM_JSON_SCHEMA_INPUT')\nconst CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL = Symbol('CUSTOM_JSON_SCHEMA_OUTPUT')\n\ntype CustomParams = CustomErrorParams & {\n fatal?: boolean\n}\n\nexport function getCustomZodType(def: ZodTypeDef): CustomZodType | undefined {\n return customZodTypeSymbol in def\n ? (def[customZodTypeSymbol] as CustomZodType)\n : undefined\n}\n\nexport function getCustomZodFileMimeType(def: ZodTypeDef): string | undefined {\n return customZodFileMimeTypeSymbol in def\n ? (def[customZodFileMimeTypeSymbol] as string)\n : undefined\n}\n\nexport function getCustomJSONSchema(\n def: ZodTypeDef,\n options?: { mode?: 'input' | 'output' },\n): Exclude<JSONSchema, boolean> | undefined {\n if (options?.mode === 'input' && CUSTOM_JSON_SCHEMA_INPUT_SYMBOL in def) {\n return def[CUSTOM_JSON_SCHEMA_INPUT_SYMBOL] as Exclude<JSONSchema, boolean>\n }\n\n if (options?.mode === 'output' && CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL in def) {\n return def[CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL] as Exclude<JSONSchema, boolean>\n }\n\n if (CUSTOM_JSON_SCHEMA_SYMBOL in def) {\n return def[CUSTOM_JSON_SCHEMA_SYMBOL] as Exclude<JSONSchema, boolean>\n }\n\n return undefined\n}\n\nfunction composeParams<T = unknown>(options: {\n params?: string | CustomParams | ((input: T) => CustomParams)\n defaultMessage?: string | ((input: T) => string)\n}): (input: T) => CustomParams {\n return (val) => {\n const defaultMessage\n = typeof options.defaultMessage === 'function'\n ? options.defaultMessage(val)\n : options.defaultMessage\n\n if (!options.params) {\n return {\n message: defaultMessage,\n }\n }\n\n if (typeof options.params === 'function') {\n return {\n message: defaultMessage,\n ...options.params(val),\n }\n }\n\n if (typeof options.params === 'object') {\n return {\n message: defaultMessage,\n ...options.params,\n }\n }\n\n return {\n message: options.params,\n }\n }\n}\n\nexport function file(\n params?: string | CustomParams | ((input: unknown) => CustomParams),\n): ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>> & {\n type: (\n mimeType: string,\n params?: string | CustomParams | ((input: unknown) => CustomParams),\n ) => ZodEffects<\n ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>>,\n InstanceType<typeof File>,\n InstanceType<typeof File>\n >\n} {\n const schema = custom<InstanceType<typeof File>>(\n val => val instanceof File,\n composeParams({ params, defaultMessage: 'Input is not a file' }),\n )\n\n Object.assign(schema._def, {\n [customZodTypeSymbol]: 'File' satisfies CustomZodType,\n })\n\n return Object.assign(schema, {\n type: (\n mimeType: string,\n params?: string | CustomParams | ((input: unknown) => CustomParams),\n ) => {\n const isMatch = wcmatch(mimeType)\n\n const refinedSchema = schema.refine(\n val => isMatch(val.type.split(';')[0]!),\n composeParams<InstanceType<typeof File>>({\n params,\n defaultMessage: val =>\n `Expected a file of type ${mimeType} but got a file of type ${val.type || 'unknown'}`,\n }),\n )\n\n Object.assign(refinedSchema._def, {\n [customZodTypeSymbol]: 'File' satisfies CustomZodType,\n [customZodFileMimeTypeSymbol]: mimeType,\n })\n\n return refinedSchema\n },\n })\n}\n\nexport function blob(\n params?: string | CustomParams | ((input: unknown) => CustomParams),\n): ZodType<InstanceType<typeof Blob>, ZodTypeDef, InstanceType<typeof Blob>> {\n const schema = custom<InstanceType<typeof Blob>>(\n val => val instanceof Blob,\n composeParams({ params, defaultMessage: 'Input is not a blob' }),\n )\n\n Object.assign(schema._def, {\n [customZodTypeSymbol]: 'Blob' satisfies CustomZodType,\n })\n\n return schema\n}\n\nexport function invalidDate(\n params?: string | CustomParams | ((input: unknown) => CustomParams),\n): ZodType<Date, ZodTypeDef, Date> {\n const schema = custom<Date>(\n val => val instanceof Date && Number.isNaN(val.getTime()),\n composeParams({ params, defaultMessage: 'Input is not an invalid date' }),\n )\n\n Object.assign(schema._def, {\n [customZodTypeSymbol]: 'Invalid Date' satisfies CustomZodType,\n })\n\n return schema\n}\n\nexport function regexp(\n options?: CustomParams,\n): ZodType<RegExp, ZodTypeDef, RegExp> {\n const schema = custom<RegExp>(\n val => val instanceof RegExp,\n composeParams({ params: options, defaultMessage: 'Input is not a regexp' }),\n )\n\n Object.assign(schema._def, {\n [customZodTypeSymbol]: 'RegExp' satisfies CustomZodType,\n })\n\n return schema\n}\n\nexport function url(options?: CustomParams): ZodType<URL, ZodTypeDef, URL> {\n const schema = custom<URL>(\n val => val instanceof URL,\n composeParams({ params: options, defaultMessage: 'Input is not a URL' }),\n )\n\n Object.assign(schema._def, {\n [customZodTypeSymbol]: 'URL' satisfies CustomZodType,\n })\n\n return schema\n}\n\nexport function openapi<\n T extends ZodTypeAny,\n TMode extends 'input' | 'output' | 'both' = 'both',\n>(\n schema: T,\n custom: Exclude<\n JSONSchema<\n TMode extends 'input'\n ? input<T>\n : TMode extends 'output'\n ? output<T>\n : input<T> & output<T>\n >,\n boolean\n >,\n options?: { mode: TMode },\n): ReturnType<T['refine']> {\n const newSchema = schema.refine(() => true) as ReturnType<T['refine']>\n\n const SYMBOL\n = options?.mode === 'input'\n ? CUSTOM_JSON_SCHEMA_INPUT_SYMBOL\n : options?.mode === 'output'\n ? CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL\n : CUSTOM_JSON_SCHEMA_SYMBOL\n\n Object.assign(newSchema._def, {\n [SYMBOL]: custom,\n })\n\n return newSchema\n}\n\nexport const oz = {\n openapi,\n file,\n blob,\n invalidDate,\n regexp,\n url,\n}\n"],"mappings":"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","names":["params","custom"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"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"}
@@ -1 +0,0 @@
1
- {"fileNames":["../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es5.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2015.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2016.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2017.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2018.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2019.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2020.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2021.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2022.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.dom.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2015.core.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2016.intl.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2017.date.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2017.object.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2017.string.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2019.array.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2019.object.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2019.string.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2019.intl.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2020.date.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2020.string.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2020.number.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2021.promise.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2021.string.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2021.intl.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2022.array.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2022.error.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2022.intl.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2022.object.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2022.string.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.es2022.regexp.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.decorators.d.ts","../../../node_modules/.pnpm/typescript@5.7.2/node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../../node_modules/.pnpm/@types+react@18.3.12/node_modules/@types/react/global.d.ts","../../../node_modules/.pnpm/csstype@3.1.3/node_modules/csstype/index.d.ts","../../../node_modules/.pnpm/@types+prop-types@15.7.13/node_modules/@types/prop-types/index.d.ts","../../../node_modules/.pnpm/@types+react@18.3.12/node_modules/@types/react/index.d.ts","../../../node_modules/.pnpm/@types+react@18.3.12/node_modules/@types/react/jsx-runtime.d.ts","../../../node_modules/.pnpm/json-schema-typed@8.0.1/node_modules/json-schema-typed/draft-2020-12.ts","../../../node_modules/.pnpm/wildcard-match@5.1.3/node_modules/wildcard-match/build/index.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/helpers/typeAliases.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/helpers/util.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/ZodError.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/locales/en.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/errors.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/helpers/parseUtil.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/helpers/enumUtil.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/helpers/errorUtil.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/helpers/partialUtil.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/types.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/external.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/index.d.ts","../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/index.d.ts","../src/index.ts"],"fileIdsList":[[59,60,61],[62],[63],[77],[66,67,77],[68,69],[66,67,68,70,71,75],[67,68],[76],[68],[66,67,68,71,72,73,74],[63,64,65,78]],"fileInfos":[{"version":"e41c290ef7dd7dab3493e6cbe5909e0148edf4a8dad0271be08edec368a0f7b9","affectsGlobalScope":true,"impliedFormat":1},{"version":"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","impliedFormat":1},{"version":"3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75","impliedFormat":1},{"version":"e44bb8bbac7f10ecc786703fe0a6a4b952189f908707980ba8f3c8975a760962","impliedFormat":1},{"version":"5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","impliedFormat":1},{"version":"68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","impliedFormat":1},{"version":"5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","impliedFormat":1},{"version":"feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","impliedFormat":1},{"version":"ee7bad0c15b58988daa84371e0b89d313b762ab83cb5b31b8a2d1162e8eb41c2","impliedFormat":1},{"version":"4fd3f3422b2d2a3dfd5cdd0f387b3a8ec45f006c6ea896a4cb41264c2100bb2c","affectsGlobalScope":true,"impliedFormat":1},{"version":"c57796738e7f83dbc4b8e65132f11a377649c00dd3eee333f672b8f0a6bea671","affectsGlobalScope":true,"impliedFormat":1},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true,"impliedFormat":1},{"version":"515d0b7b9bea2e31ea4ec968e9edd2c39d3eebf4a2d5cbd04e88639819ae3b71","affectsGlobalScope":true,"impliedFormat":1},{"version":"62bb211266ee48b2d0edf0d8d1b191f0c24fc379a82bd4c1692a082c540bc6b1","affectsGlobalScope":true,"impliedFormat":1},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true,"impliedFormat":1},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true,"impliedFormat":1},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true,"impliedFormat":1},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true,"impliedFormat":1},{"version":"936e80ad36a2ee83fc3caf008e7c4c5afe45b3cf3d5c24408f039c1d47bdc1df","affectsGlobalScope":true,"impliedFormat":1},{"version":"d15bea3d62cbbdb9797079416b8ac375ae99162a7fba5de2c6c505446486ac0a","affectsGlobalScope":true,"impliedFormat":1},{"version":"68d18b664c9d32a7336a70235958b8997ebc1c3b8505f4f1ae2b7e7753b87618","affectsGlobalScope":true,"impliedFormat":1},{"version":"eb3d66c8327153d8fa7dd03f9c58d351107fe824c79e9b56b462935176cdf12a","affectsGlobalScope":true,"impliedFormat":1},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true,"impliedFormat":1},{"version":"69ab18c3b76cd9b1be3d188eaf8bba06112ebbe2f47f6c322b5105a6fbc45a2e","affectsGlobalScope":true,"impliedFormat":1},{"version":"fef8cfad2e2dc5f5b3d97a6f4f2e92848eb1b88e897bb7318cef0e2820bceaab","affectsGlobalScope":true,"impliedFormat":1},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true,"impliedFormat":1},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true,"impliedFormat":1},{"version":"954296b30da6d508a104a3a0b5d96b76495c709785c1d11610908e63481ee667","affectsGlobalScope":true,"impliedFormat":1},{"version":"ac9538681b19688c8eae65811b329d3744af679e0bdfa5d842d0e32524c73e1c","affectsGlobalScope":true,"impliedFormat":1},{"version":"0a969edff4bd52585473d24995c5ef223f6652d6ef46193309b3921d65dd4376","affectsGlobalScope":true,"impliedFormat":1},{"version":"9e9fbd7030c440b33d021da145d3232984c8bb7916f277e8ffd3dc2e3eae2bdb","affectsGlobalScope":true,"impliedFormat":1},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true,"impliedFormat":1},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true,"impliedFormat":1},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true,"impliedFormat":1},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true,"impliedFormat":1},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true,"impliedFormat":1},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true,"impliedFormat":1},{"version":"74f7fa2d027d5b33eb0471c8e82a6c87216223181ec31247c357a3e8e2fddc5b","affectsGlobalScope":true,"impliedFormat":1},{"version":"f1e2a172204962276504466a6393426d2ca9c54894b1ad0a6c9dad867a65f876","affectsGlobalScope":true,"impliedFormat":1},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true,"impliedFormat":1},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true,"impliedFormat":1},{"version":"52ada8e0b6e0482b728070b7639ee42e83a9b1c22d205992756fe020fd9f4a47","affectsGlobalScope":true,"impliedFormat":1},{"version":"3bdefe1bfd4d6dee0e26f928f93ccc128f1b64d5d501ff4a8cf3c6371200e5e6","affectsGlobalScope":true,"impliedFormat":1},{"version":"59fb2c069260b4ba00b5643b907ef5d5341b167e7d1dbf58dfd895658bda2867","affectsGlobalScope":true,"impliedFormat":1},{"version":"639e512c0dfc3fad96a84caad71b8834d66329a1f28dc95e3946c9b58176c73a","affectsGlobalScope":true,"impliedFormat":1},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true,"impliedFormat":1},{"version":"af3dd424cf267428f30ccfc376f47a2c0114546b55c44d8c0f1d57d841e28d74","affectsGlobalScope":true,"impliedFormat":1},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true,"impliedFormat":1},{"version":"959d36cddf5e7d572a65045b876f2956c973a586da58e5d26cde519184fd9b8a","affectsGlobalScope":true,"impliedFormat":1},{"version":"965f36eae237dd74e6cca203a43e9ca801ce38824ead814728a2807b1910117d","affectsGlobalScope":true,"impliedFormat":1},{"version":"3925a6c820dcb1a06506c90b1577db1fdbf7705d65b62b99dce4be75c637e26b","affectsGlobalScope":true,"impliedFormat":1},{"version":"0a3d63ef2b853447ec4f749d3f368ce642264246e02911fcb1590d8c161b8005","affectsGlobalScope":true,"impliedFormat":1},{"version":"b5ce7a470bc3628408429040c4e3a53a27755022a32fd05e2cb694e7015386c7","affectsGlobalScope":true,"impliedFormat":1},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true,"impliedFormat":1},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true,"impliedFormat":1},{"version":"b4b67b1a91182421f5df999988c690f14d813b9850b40acd06ed44691f6727ad","affectsGlobalScope":true,"impliedFormat":1},{"version":"8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea","affectsGlobalScope":true,"impliedFormat":1},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true,"impliedFormat":1},{"version":"36a2e4c9a67439aca5f91bb304611d5ae6e20d420503e96c230cf8fcdc948d94","affectsGlobalScope":true,"impliedFormat":1},{"version":"8a8eb4ebffd85e589a1cc7c178e291626c359543403d58c9cd22b81fab5b1fb9","impliedFormat":1},{"version":"ed6b820c54de95b2510bb673490d61c7f2187f532a339d8d04981645a918961f","impliedFormat":1},{"version":"aa17748c522bd586f8712b1a308ea23af59c309b2fd278f6d4f406647c72e659","affectsGlobalScope":true,"impliedFormat":1},{"version":"42c169fb8c2d42f4f668c624a9a11e719d5d07dacbebb63cbcf7ef365b0a75b3","impliedFormat":1},{"version":"126783a400a891fce19c88533874b41073eb898725cb2a86a878e3b18e4e71f8","impliedFormat":99},{"version":"30b2bd1237547fbccd267bd8680d721dce8c71bd2f156d6987d599f9098e15d5","impliedFormat":1},{"version":"5487b97cfa28b26b4a9ef0770f872bdbebd4c46124858de00f242c3eed7519f4","impliedFormat":1},{"version":"c2869c4f2f79fd2d03278a68ce7c061a5a8f4aed59efb655e25fe502e3e471d5","impliedFormat":1},{"version":"b8fe42dbf4b0efba2eb4dbfb2b95a3712676717ff8469767dc439e75d0c1a3b6","impliedFormat":1},{"version":"8485b6da53ec35637d072e516631d25dae53984500de70a6989058f24354666f","impliedFormat":1},{"version":"ebe80346928736532e4a822154eb77f57ef3389dbe2b3ba4e571366a15448ef2","impliedFormat":1},{"version":"83306c97a4643d78420f082547ea0d488a0d134c922c8e65fc0b4f08ef66d92b","impliedFormat":1},{"version":"f672c876c1a04a223cf2023b3d91e8a52bb1544c576b81bf64a8fec82be9969c","impliedFormat":1},{"version":"98a9cc18f661d28e6bd31c436e1984f3980f35e0f0aa9cf795c54f8ccb667ffe","impliedFormat":1},{"version":"c76b0c5727302341d0bdfa2cc2cee4b19ff185b554edb6e8543f0661d8487116","impliedFormat":1},{"version":"dccd26a5c85325a011aff40f401e0892bd0688d44132ba79e803c67e68fffea5","impliedFormat":1},{"version":"f5ef066942e4f0bd98200aa6a6694b831e73200c9b3ade77ad0aa2409e8fe1b1","impliedFormat":1},{"version":"b9e99cd94f4166a245f5158f7286c05406e2a4c694619bceb7a4f3519d1d768e","impliedFormat":1},{"version":"5568d7c32e5cf5f35e092649f4e5e168c3114c800b1d7545b7ae5e0415704802","impliedFormat":1},{"version":"89f7baaef85d67be01d0c72b7ab82f843200f90ec7c22c2e076939e6782b64d1","signature":"fcd80ef2e1c0087c333eb0f1d71f07b24d5905e689703a9af79bf8ae2e0622ae"}],"root":[79],"options":{"composite":true,"declaration":true,"declarationMap":true,"emitDeclarationOnly":true,"esModuleInterop":true,"jsx":4,"module":7,"noImplicitOverride":true,"noUncheckedIndexedAccess":true,"noUncheckedSideEffectImports":true,"outDir":"./","skipLibCheck":true,"strict":true,"target":9,"useDefineForClassFields":true},"referencedMap":[[62,1],[63,2],[64,3],[78,4],[68,5],[70,6],[76,7],[71,8],[74,4],[77,9],[69,10],[75,11],[79,12]],"semanticDiagnosticsPerFile":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79],"latestChangedDtsFile":"./src/index.d.ts","checkPending":true,"version":"5.7.2"}
package/src/index.ts DELETED
@@ -1,243 +0,0 @@
1
- /// <reference lib="dom" />
2
-
3
- import type { JSONSchema } from 'json-schema-typed/draft-2020-12'
4
-
5
- import wcmatch from 'wildcard-match'
6
- import {
7
- custom,
8
- type CustomErrorParams,
9
- type input,
10
- type output,
11
- type ZodEffects,
12
- type ZodType,
13
- type ZodTypeAny,
14
- type ZodTypeDef,
15
- } from 'zod'
16
-
17
- export type CustomZodType = 'File' | 'Blob' | 'Invalid Date' | 'RegExp' | 'URL'
18
-
19
- const customZodTypeSymbol = Symbol('customZodTypeSymbol')
20
-
21
- const customZodFileMimeTypeSymbol = Symbol('customZodFileMimeTypeSymbol')
22
-
23
- const CUSTOM_JSON_SCHEMA_SYMBOL = Symbol('CUSTOM_JSON_SCHEMA')
24
- const CUSTOM_JSON_SCHEMA_INPUT_SYMBOL = Symbol('CUSTOM_JSON_SCHEMA_INPUT')
25
- const CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL = Symbol('CUSTOM_JSON_SCHEMA_OUTPUT')
26
-
27
- type CustomParams = CustomErrorParams & {
28
- fatal?: boolean
29
- }
30
-
31
- export function getCustomZodType(def: ZodTypeDef): CustomZodType | undefined {
32
- return customZodTypeSymbol in def
33
- ? (def[customZodTypeSymbol] as CustomZodType)
34
- : undefined
35
- }
36
-
37
- export function getCustomZodFileMimeType(def: ZodTypeDef): string | undefined {
38
- return customZodFileMimeTypeSymbol in def
39
- ? (def[customZodFileMimeTypeSymbol] as string)
40
- : undefined
41
- }
42
-
43
- export function getCustomJSONSchema(
44
- def: ZodTypeDef,
45
- options?: { mode?: 'input' | 'output' },
46
- ): Exclude<JSONSchema, boolean> | undefined {
47
- if (options?.mode === 'input' && CUSTOM_JSON_SCHEMA_INPUT_SYMBOL in def) {
48
- return def[CUSTOM_JSON_SCHEMA_INPUT_SYMBOL] as Exclude<JSONSchema, boolean>
49
- }
50
-
51
- if (options?.mode === 'output' && CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL in def) {
52
- return def[CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL] as Exclude<JSONSchema, boolean>
53
- }
54
-
55
- if (CUSTOM_JSON_SCHEMA_SYMBOL in def) {
56
- return def[CUSTOM_JSON_SCHEMA_SYMBOL] as Exclude<JSONSchema, boolean>
57
- }
58
-
59
- return undefined
60
- }
61
-
62
- function composeParams<T = unknown>(options: {
63
- params?: string | CustomParams | ((input: T) => CustomParams)
64
- defaultMessage?: string | ((input: T) => string)
65
- }): (input: T) => CustomParams {
66
- return (val) => {
67
- const defaultMessage
68
- = typeof options.defaultMessage === 'function'
69
- ? options.defaultMessage(val)
70
- : options.defaultMessage
71
-
72
- if (!options.params) {
73
- return {
74
- message: defaultMessage,
75
- }
76
- }
77
-
78
- if (typeof options.params === 'function') {
79
- return {
80
- message: defaultMessage,
81
- ...options.params(val),
82
- }
83
- }
84
-
85
- if (typeof options.params === 'object') {
86
- return {
87
- message: defaultMessage,
88
- ...options.params,
89
- }
90
- }
91
-
92
- return {
93
- message: options.params,
94
- }
95
- }
96
- }
97
-
98
- export function file(
99
- params?: string | CustomParams | ((input: unknown) => CustomParams),
100
- ): ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>> & {
101
- type: (
102
- mimeType: string,
103
- params?: string | CustomParams | ((input: unknown) => CustomParams),
104
- ) => ZodEffects<
105
- ZodType<InstanceType<typeof File>, ZodTypeDef, InstanceType<typeof File>>,
106
- InstanceType<typeof File>,
107
- InstanceType<typeof File>
108
- >
109
- } {
110
- const schema = custom<InstanceType<typeof File>>(
111
- val => val instanceof File,
112
- composeParams({ params, defaultMessage: 'Input is not a file' }),
113
- )
114
-
115
- Object.assign(schema._def, {
116
- [customZodTypeSymbol]: 'File' satisfies CustomZodType,
117
- })
118
-
119
- return Object.assign(schema, {
120
- type: (
121
- mimeType: string,
122
- params?: string | CustomParams | ((input: unknown) => CustomParams),
123
- ) => {
124
- const isMatch = wcmatch(mimeType)
125
-
126
- const refinedSchema = schema.refine(
127
- val => isMatch(val.type.split(';')[0]!),
128
- composeParams<InstanceType<typeof File>>({
129
- params,
130
- defaultMessage: val =>
131
- `Expected a file of type ${mimeType} but got a file of type ${val.type || 'unknown'}`,
132
- }),
133
- )
134
-
135
- Object.assign(refinedSchema._def, {
136
- [customZodTypeSymbol]: 'File' satisfies CustomZodType,
137
- [customZodFileMimeTypeSymbol]: mimeType,
138
- })
139
-
140
- return refinedSchema
141
- },
142
- })
143
- }
144
-
145
- export function blob(
146
- params?: string | CustomParams | ((input: unknown) => CustomParams),
147
- ): ZodType<InstanceType<typeof Blob>, ZodTypeDef, InstanceType<typeof Blob>> {
148
- const schema = custom<InstanceType<typeof Blob>>(
149
- val => val instanceof Blob,
150
- composeParams({ params, defaultMessage: 'Input is not a blob' }),
151
- )
152
-
153
- Object.assign(schema._def, {
154
- [customZodTypeSymbol]: 'Blob' satisfies CustomZodType,
155
- })
156
-
157
- return schema
158
- }
159
-
160
- export function invalidDate(
161
- params?: string | CustomParams | ((input: unknown) => CustomParams),
162
- ): ZodType<Date, ZodTypeDef, Date> {
163
- const schema = custom<Date>(
164
- val => val instanceof Date && Number.isNaN(val.getTime()),
165
- composeParams({ params, defaultMessage: 'Input is not an invalid date' }),
166
- )
167
-
168
- Object.assign(schema._def, {
169
- [customZodTypeSymbol]: 'Invalid Date' satisfies CustomZodType,
170
- })
171
-
172
- return schema
173
- }
174
-
175
- export function regexp(
176
- options?: CustomParams,
177
- ): ZodType<RegExp, ZodTypeDef, RegExp> {
178
- const schema = custom<RegExp>(
179
- val => val instanceof RegExp,
180
- composeParams({ params: options, defaultMessage: 'Input is not a regexp' }),
181
- )
182
-
183
- Object.assign(schema._def, {
184
- [customZodTypeSymbol]: 'RegExp' satisfies CustomZodType,
185
- })
186
-
187
- return schema
188
- }
189
-
190
- export function url(options?: CustomParams): ZodType<URL, ZodTypeDef, URL> {
191
- const schema = custom<URL>(
192
- val => val instanceof URL,
193
- composeParams({ params: options, defaultMessage: 'Input is not a URL' }),
194
- )
195
-
196
- Object.assign(schema._def, {
197
- [customZodTypeSymbol]: 'URL' satisfies CustomZodType,
198
- })
199
-
200
- return schema
201
- }
202
-
203
- export function openapi<
204
- T extends ZodTypeAny,
205
- TMode extends 'input' | 'output' | 'both' = 'both',
206
- >(
207
- schema: T,
208
- custom: Exclude<
209
- JSONSchema<
210
- TMode extends 'input'
211
- ? input<T>
212
- : TMode extends 'output'
213
- ? output<T>
214
- : input<T> & output<T>
215
- >,
216
- boolean
217
- >,
218
- options?: { mode: TMode },
219
- ): ReturnType<T['refine']> {
220
- const newSchema = schema.refine(() => true) as ReturnType<T['refine']>
221
-
222
- const SYMBOL
223
- = options?.mode === 'input'
224
- ? CUSTOM_JSON_SCHEMA_INPUT_SYMBOL
225
- : options?.mode === 'output'
226
- ? CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL
227
- : CUSTOM_JSON_SCHEMA_SYMBOL
228
-
229
- Object.assign(newSchema._def, {
230
- [SYMBOL]: custom,
231
- })
232
-
233
- return newSchema
234
- }
235
-
236
- export const oz = {
237
- openapi,
238
- file,
239
- blob,
240
- invalidDate,
241
- regexp,
242
- url,
243
- }