@temporary-name/zod 1.9.3-alpha.50b729ba628b987e14f5bd1004e5a04590fd4b4e → 1.9.3-alpha.52ad782be6ff2aac22845e524cd6454f857fb89b

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@temporary-name/zod",
3
3
  "type": "module",
4
- "version": "1.9.3-alpha.50b729ba628b987e14f5bd1004e5a04590fd4b4e",
4
+ "version": "1.9.3-alpha.52ad782be6ff2aac22845e524cd6454f857fb89b",
5
5
  "license": "MIT",
6
6
  "homepage": "https://www.stainless.com/",
7
7
  "repository": {
@@ -17,25 +17,18 @@
17
17
  "types": "./dist/index.d.mts",
18
18
  "import": "./dist/index.mjs",
19
19
  "default": "./dist/index.mjs"
20
- },
21
- "./zod4": {
22
- "types": "./dist/zod4/index.d.mts",
23
- "import": "./dist/zod4/index.mjs",
24
- "default": "./dist/zod4/index.mjs"
25
20
  }
26
21
  },
27
22
  "files": [
28
23
  "dist"
29
24
  ],
30
25
  "peerDependencies": {
31
- "@temporary-name/contract": "1.9.3-alpha.50b729ba628b987e14f5bd1004e5a04590fd4b4e",
32
- "@temporary-name/server": "1.9.3-alpha.50b729ba628b987e14f5bd1004e5a04590fd4b4e"
26
+ "@temporary-name/contract": "1.9.3-alpha.52ad782be6ff2aac22845e524cd6454f857fb89b",
27
+ "@temporary-name/server": "1.9.3-alpha.52ad782be6ff2aac22845e524cd6454f857fb89b"
33
28
  },
34
29
  "dependencies": {
35
- "escape-string-regexp": "^5.0.0",
36
- "wildcard-match": "^5.1.3",
37
30
  "zod": "^4.1.11",
38
- "@temporary-name/shared": "1.9.3-alpha.50b729ba628b987e14f5bd1004e5a04590fd4b4e"
31
+ "@temporary-name/shared": "1.9.3-alpha.52ad782be6ff2aac22845e524cd6454f857fb89b"
39
32
  },
40
33
  "devDependencies": {},
41
34
  "scripts": {
@@ -1,12 +0,0 @@
1
- import { Context } from '@temporary-name/server';
2
- import { StandardHandlerPlugin, StandardHandlerOptions } from '@temporary-name/server/standard';
3
-
4
- /**
5
- * @deprecated Use [Smart Coercion Plugin](https://orpc.unnoq.com/docs/openapi/plugins/smart-coercion) instead.
6
- */
7
- declare class experimental_ZodSmartCoercionPlugin<TContext extends Context> implements StandardHandlerPlugin<TContext> {
8
- #private;
9
- init(options: StandardHandlerOptions<TContext>): void;
10
- }
11
-
12
- export { experimental_ZodSmartCoercionPlugin };
@@ -1,12 +0,0 @@
1
- import { Context } from '@temporary-name/server';
2
- import { StandardHandlerPlugin, StandardHandlerOptions } from '@temporary-name/server/standard';
3
-
4
- /**
5
- * @deprecated Use [Smart Coercion Plugin](https://orpc.unnoq.com/docs/openapi/plugins/smart-coercion) instead.
6
- */
7
- declare class experimental_ZodSmartCoercionPlugin<TContext extends Context> implements StandardHandlerPlugin<TContext> {
8
- #private;
9
- init(options: StandardHandlerOptions<TContext>): void;
10
- }
11
-
12
- export { experimental_ZodSmartCoercionPlugin };
@@ -1,259 +0,0 @@
1
- import { isObject, guard } from '@temporary-name/shared';
2
-
3
- class experimental_ZodSmartCoercionPlugin {
4
- init(options) {
5
- options.clientInterceptors ??= [];
6
- options.clientInterceptors.unshift((options2) => {
7
- const inputSchema = options2.procedure["~orpc"].inputSchema;
8
- if (!inputSchema || inputSchema["~standard"].vendor !== "zod" || !("_zod" in inputSchema)) {
9
- return options2.next();
10
- }
11
- const coercedInput = this.#coerce(inputSchema, options2.input);
12
- return options2.next({ ...options2, input: coercedInput });
13
- });
14
- }
15
- #coerce(schema, value) {
16
- switch (schema._zod.def.type) {
17
- case "number": {
18
- if (typeof value === "string") {
19
- return this.#stringToNumber(value);
20
- }
21
- return value;
22
- }
23
- case "bigint": {
24
- if (typeof value === "string") {
25
- return this.#stringToBigInt(value);
26
- }
27
- return value;
28
- }
29
- case "boolean":
30
- case "success": {
31
- if (typeof value === "string") {
32
- return this.#stringToBoolean(value);
33
- }
34
- return value;
35
- }
36
- case "date": {
37
- if (typeof value === "string") {
38
- return this.#stringToDate(value);
39
- }
40
- return value;
41
- }
42
- case "literal":
43
- case "enum": {
44
- const literal = schema;
45
- if (!literal._zod.values.has(value) && typeof value === "string") {
46
- const num = this.#stringToNumber(value);
47
- if (literal._zod.values.has(num)) {
48
- return num;
49
- }
50
- const bool = this.#stringToBoolean(value);
51
- if (literal._zod.values.has(bool)) {
52
- return bool;
53
- }
54
- const bigint = this.#stringToBigInt(value);
55
- if (literal._zod.values.has(bigint)) {
56
- return bigint;
57
- }
58
- }
59
- return value;
60
- }
61
- case "array": {
62
- const array = schema;
63
- if (value === void 0) {
64
- return [];
65
- }
66
- if (Array.isArray(value)) {
67
- return value.map((v) => this.#coerce(array._zod.def.element, v));
68
- }
69
- return value;
70
- }
71
- case "tuple": {
72
- const tuple = schema;
73
- if (value === void 0) {
74
- return [];
75
- }
76
- if (Array.isArray(value)) {
77
- return value.map((v, i) => {
78
- const s = tuple._zod.def.items[i] ?? tuple._zod.def.rest;
79
- return s ? this.#coerce(s, v) : v;
80
- });
81
- }
82
- return value;
83
- }
84
- case "set": {
85
- const set = schema;
86
- if (value === void 0) {
87
- return /* @__PURE__ */ new Set();
88
- }
89
- if (Array.isArray(value)) {
90
- return new Set(value.map((v) => this.#coerce(set._zod.def.valueType, v)));
91
- }
92
- if (value instanceof Set) {
93
- return new Set(Array.from(value).map((v) => this.#coerce(set._zod.def.valueType, v)));
94
- }
95
- return value;
96
- }
97
- case "object": {
98
- const object = schema;
99
- if (value === void 0) {
100
- return {};
101
- }
102
- if (isObject(value)) {
103
- const newObj = {};
104
- const keys = /* @__PURE__ */ new Set([...Object.keys(value), ...Object.keys(object._zod.def.shape)]);
105
- for (const k of keys) {
106
- const s = object._zod.def.shape[k] ?? object._zod.def.catchall;
107
- newObj[k] = s ? this.#coerce(s, value[k]) : value[k];
108
- }
109
- return newObj;
110
- }
111
- return value;
112
- }
113
- case "record": {
114
- const record = schema;
115
- if (value === void 0) {
116
- return {};
117
- }
118
- if (isObject(value)) {
119
- const newObj = {};
120
- for (const [k, v] of Object.entries(value)) {
121
- const key = this.#coerce(record._zod.def.keyType, k);
122
- const val = this.#coerce(record._zod.def.valueType, v);
123
- newObj[key] = val;
124
- }
125
- return newObj;
126
- }
127
- return value;
128
- }
129
- case "map": {
130
- const map = schema;
131
- if (value === void 0) {
132
- return /* @__PURE__ */ new Map();
133
- }
134
- if (Array.isArray(value) && value.every((i) => Array.isArray(i) && i.length <= 2)) {
135
- return new Map(
136
- value.map(([k, v]) => [
137
- this.#coerce(map._zod.def.keyType, k),
138
- this.#coerce(map._zod.def.valueType, v)
139
- ])
140
- );
141
- }
142
- if (value instanceof Map) {
143
- return new Map(
144
- Array.from(value).map(([k, v]) => [
145
- this.#coerce(map._zod.def.keyType, k),
146
- this.#coerce(map._zod.def.valueType, v)
147
- ])
148
- );
149
- }
150
- return value;
151
- }
152
- case "union": {
153
- const union = schema;
154
- if (union._zod.def.options.length === 1) {
155
- return this.#coerce(union._zod.def.options[0], value);
156
- }
157
- if (isObject(value)) {
158
- const discriminator = "discriminator" in union._zod.def && typeof union._zod.def.discriminator === "string" ? union._zod.def.discriminator : void 0;
159
- for (const option of union._zod.def.options) {
160
- if (!option._zod.propValues) {
161
- continue;
162
- }
163
- if (discriminator !== void 0) {
164
- if (option._zod.propValues[discriminator]?.has(value[discriminator])) {
165
- return this.#coerce(option, value);
166
- }
167
- } else {
168
- for (const key in option._zod.propValues) {
169
- if (option._zod.propValues[key]?.has(value[key])) {
170
- return this.#coerce(option, value);
171
- }
172
- }
173
- }
174
- }
175
- }
176
- return value;
177
- }
178
- case "intersection": {
179
- const intersection = schema;
180
- return this.#coerce(intersection._zod.def.right, this.#coerce(intersection._zod.def.left, value));
181
- }
182
- case "optional": {
183
- const optional = schema;
184
- if (value === void 0) {
185
- return void 0;
186
- }
187
- return this.#coerce(optional._zod.def.innerType, value);
188
- }
189
- case "nonoptional": {
190
- const nonoptional = schema;
191
- return this.#coerce(nonoptional._zod.def.innerType, value);
192
- }
193
- case "nullable": {
194
- const nullable = schema;
195
- if (value === null) {
196
- return null;
197
- }
198
- return this.#coerce(nullable._zod.def.innerType, value);
199
- }
200
- case "readonly": {
201
- const readonly_ = schema;
202
- return this.#coerce(readonly_._zod.def.innerType, value);
203
- }
204
- case "pipe": {
205
- const pipe = schema;
206
- return this.#coerce(pipe._zod.def.in, value);
207
- }
208
- case "default":
209
- case "prefault": {
210
- const default_ = schema;
211
- if (value === void 0) {
212
- return value;
213
- }
214
- return this.#coerce(default_._zod.def.innerType, value);
215
- }
216
- case "catch": {
217
- const catch_ = schema;
218
- return this.#coerce(catch_._zod.def.innerType, value);
219
- }
220
- case "lazy": {
221
- const lazy = schema;
222
- if (value !== void 0) {
223
- return this.#coerce(lazy._zod.def.getter(), value);
224
- }
225
- return value;
226
- }
227
- default: {
228
- schema._zod.def.type;
229
- return value;
230
- }
231
- }
232
- }
233
- #stringToNumber(value) {
234
- const num = Number(value);
235
- return Number.isNaN(num) || num.toString() !== value ? value : num;
236
- }
237
- #stringToBigInt(value) {
238
- return guard(() => BigInt(value)) ?? value;
239
- }
240
- #stringToBoolean(value) {
241
- const lower = value.toLowerCase();
242
- if (lower === "false" || lower === "off" || lower === "f") {
243
- return false;
244
- }
245
- if (lower === "true" || lower === "on" || lower === "t") {
246
- return true;
247
- }
248
- return value;
249
- }
250
- #stringToDate(value) {
251
- const date = new Date(value);
252
- if (!Number.isNaN(date.getTime()) && date.toISOString().startsWith(value)) {
253
- return date;
254
- }
255
- return value;
256
- }
257
- }
258
-
259
- export { experimental_ZodSmartCoercionPlugin };