@orpc/zod 1.3.0 → 1.4.0

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.
Files changed (2) hide show
  1. package/dist/zod4/index.mjs +26 -32
  2. package/package.json +6 -6
@@ -100,8 +100,7 @@ class experimental_ZodSmartCoercionPlugin {
100
100
  }
101
101
  return value;
102
102
  }
103
- case "object":
104
- case "interface": {
103
+ case "object": {
105
104
  const object = schema;
106
105
  if (value === void 0) {
107
106
  return {};
@@ -165,9 +164,21 @@ class experimental_ZodSmartCoercionPlugin {
165
164
  return this.#coerce(union._zod.def.options[0], value);
166
165
  }
167
166
  if (isObject(value)) {
167
+ const discriminator = "discriminator" in union._zod.def && typeof union._zod.def.discriminator === "string" ? union._zod.def.discriminator : void 0;
168
168
  for (const option of union._zod.def.options) {
169
- if (option._zod.disc && this.#matchDiscriminators(value, option._zod.disc)) {
170
- return this.#coerce(option, value);
169
+ if (!option._zod.propValues) {
170
+ continue;
171
+ }
172
+ if (discriminator !== void 0) {
173
+ if (option._zod.propValues[discriminator]?.has(value[discriminator])) {
174
+ return this.#coerce(option, value);
175
+ }
176
+ } else {
177
+ for (const key in option._zod.propValues) {
178
+ if (option._zod.propValues[key]?.has(value[key])) {
179
+ return this.#coerce(option, value);
180
+ }
181
+ }
171
182
  }
172
183
  }
173
184
  }
@@ -255,30 +266,6 @@ class experimental_ZodSmartCoercionPlugin {
255
266
  }
256
267
  return value;
257
268
  }
258
- /**
259
- * This function is inspired from Zod, because it's not exported
260
- * https://github.com/colinhacks/zod/blob/v4/packages/core/src/schemas.ts#L1903C1-L1921C2
261
- */
262
- #matchDiscriminators(input, discs) {
263
- for (const [key, value] of discs) {
264
- const data = input[key];
265
- if (value.values.size && !value.values.has(data)) {
266
- return false;
267
- }
268
- if (value.maps.length === 0) {
269
- continue;
270
- }
271
- if (!isObject(data)) {
272
- return false;
273
- }
274
- for (const m of value.maps) {
275
- if (!this.#matchDiscriminators(data, m)) {
276
- return false;
277
- }
278
- }
279
- }
280
- return true;
281
- }
282
269
  }
283
270
 
284
271
  const experimental_JSON_SCHEMA_REGISTRY = registry();
@@ -320,7 +307,7 @@ class experimental_ZodToJsonSchemaConverter {
320
307
  case "string": {
321
308
  const string = schema2;
322
309
  const json = { type: "string" };
323
- const { minimum, maximum, format, pattern, contentEncoding } = string._zod.bag;
310
+ const { minimum, maximum, format, patterns, contentEncoding } = string._zod.bag;
324
311
  if (typeof minimum === "number") {
325
312
  json.minLength = minimum;
326
313
  }
@@ -333,8 +320,15 @@ class experimental_ZodToJsonSchemaConverter {
333
320
  if (typeof format === "string" && format !== "regex" && json.contentEncoding === void 0) {
334
321
  json.format = this.#handleStringFormat(format);
335
322
  }
336
- if (pattern instanceof RegExp && json.contentEncoding === void 0 && json.format === void 0) {
337
- json.pattern = pattern.source;
323
+ if (patterns instanceof Set && json.contentEncoding === void 0 && json.format === void 0) {
324
+ for (const pattern of patterns) {
325
+ if (json.pattern === void 0) {
326
+ json.pattern = pattern.source;
327
+ } else {
328
+ json.allOf ??= [];
329
+ json.allOf.push({ pattern: pattern.source });
330
+ }
331
+ }
338
332
  }
339
333
  if (format === "jwt" && json.contentEncoding === void 0 && json.format === void 0 && json.pattern === void 0) {
340
334
  json.pattern = /^[\w-]+\.[\w-]+\.[\w-]+$/.source;
@@ -621,7 +615,7 @@ class experimental_ZodToJsonSchemaConverter {
621
615
  if (global) {
622
616
  return {
623
617
  description: global.description,
624
- examples: global.examples
618
+ examples: Array.isArray(global.examples) ? global.examples : void 0
625
619
  };
626
620
  }
627
621
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/zod",
3
3
  "type": "module",
4
- "version": "1.3.0",
4
+ "version": "1.4.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -30,17 +30,17 @@
30
30
  ],
31
31
  "peerDependencies": {
32
32
  "zod": ">=3.24.2",
33
- "@orpc/contract": "1.3.0",
34
- "@orpc/server": "1.3.0"
33
+ "@orpc/contract": "1.4.0",
34
+ "@orpc/server": "1.4.0"
35
35
  },
36
36
  "dependencies": {
37
37
  "escape-string-regexp": "^5.0.0",
38
38
  "wildcard-match": "^5.1.3",
39
- "@orpc/openapi": "1.3.0",
40
- "@orpc/shared": "1.3.0"
39
+ "@orpc/openapi": "1.4.0",
40
+ "@orpc/shared": "1.4.0"
41
41
  },
42
42
  "devDependencies": {
43
- "zod": "^3.25.11",
43
+ "zod": "^3.25.49",
44
44
  "zod-to-json-schema": "^3.24.5"
45
45
  },
46
46
  "scripts": {