@orpc/zod 0.36.0 → 0.37.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.
- package/dist/index.js +7 -35
- package/package.json +6 -4
package/dist/index.js
CHANGED
@@ -1,33 +1,5 @@
|
|
1
|
-
// ../../node_modules/.pnpm/is-what@5.0.2/node_modules/is-what/dist/getType.js
|
2
|
-
function getType(payload) {
|
3
|
-
return Object.prototype.toString.call(payload).slice(8, -1);
|
4
|
-
}
|
5
|
-
|
6
|
-
// ../../node_modules/.pnpm/is-what@5.0.2/node_modules/is-what/dist/isPlainObject.js
|
7
|
-
function isPlainObject(payload) {
|
8
|
-
if (getType(payload) !== "Object")
|
9
|
-
return false;
|
10
|
-
const prototype = Object.getPrototypeOf(payload);
|
11
|
-
return !!prototype && prototype.constructor === Object && prototype === Object.prototype;
|
12
|
-
}
|
13
|
-
|
14
|
-
// ../../node_modules/.pnpm/radash@12.1.0/node_modules/radash/dist/esm/async.mjs
|
15
|
-
var guard = (func, shouldGuard) => {
|
16
|
-
const _guard = (err) => {
|
17
|
-
if (shouldGuard && !shouldGuard(err))
|
18
|
-
throw err;
|
19
|
-
return void 0;
|
20
|
-
};
|
21
|
-
const isPromise2 = (result) => result instanceof Promise;
|
22
|
-
try {
|
23
|
-
const result = func();
|
24
|
-
return isPromise2(result) ? result.catch(_guard) : result;
|
25
|
-
} catch (err) {
|
26
|
-
return _guard(err);
|
27
|
-
}
|
28
|
-
};
|
29
|
-
|
30
1
|
// src/coercer.ts
|
2
|
+
import { guard, isObject } from "@orpc/shared";
|
31
3
|
import {
|
32
4
|
ZodFirstPartyTypeKind
|
33
5
|
} from "zod";
|
@@ -128,7 +100,7 @@ function zodCoerceInternal(schema, value, options) {
|
|
128
100
|
if (value === void 0) {
|
129
101
|
return [];
|
130
102
|
}
|
131
|
-
if (
|
103
|
+
if (isObject(value) && Object.keys(value).every((k) => /^[1-9]\d*$/.test(k) || k === "0")) {
|
132
104
|
const indexes = Object.keys(value).map((k) => Number(k)).sort((a, b) => a - b);
|
133
105
|
const arr = Array.from({ length: (indexes.at(-1) ?? -1) + 1 });
|
134
106
|
for (const i of indexes) {
|
@@ -139,7 +111,7 @@ function zodCoerceInternal(schema, value, options) {
|
|
139
111
|
}
|
140
112
|
} else if (typeName === ZodFirstPartyTypeKind.ZodObject) {
|
141
113
|
const schema_ = schema;
|
142
|
-
if (
|
114
|
+
if (isObject(value)) {
|
143
115
|
const newObj = {};
|
144
116
|
const keys = /* @__PURE__ */ new Set([
|
145
117
|
...Object.keys(value),
|
@@ -177,7 +149,7 @@ function zodCoerceInternal(schema, value, options) {
|
|
177
149
|
if (value === void 0) {
|
178
150
|
return /* @__PURE__ */ new Set();
|
179
151
|
}
|
180
|
-
if (
|
152
|
+
if (isObject(value) && Object.keys(value).every((k) => /^[1-9]\d*$/.test(k) || k === "0")) {
|
181
153
|
const indexes = Object.keys(value).map((k) => Number(k)).sort((a, b) => a - b);
|
182
154
|
const arr = Array.from({ length: (indexes.at(-1) ?? -1) + 1 });
|
183
155
|
for (const i of indexes) {
|
@@ -200,9 +172,9 @@ function zodCoerceInternal(schema, value, options) {
|
|
200
172
|
if (value === void 0) {
|
201
173
|
return /* @__PURE__ */ new Map();
|
202
174
|
}
|
203
|
-
if (
|
175
|
+
if (isObject(value)) {
|
204
176
|
const arr = Array.from({ length: Object.keys(value).length }).fill(void 0).map(
|
205
|
-
(_, i) =>
|
177
|
+
(_, i) => isObject(value[i]) && Object.keys(value[i]).length === 2 && "0" in value[i] && "1" in value[i] ? [value[i]["0"], value[i]["1"]] : void 0
|
206
178
|
);
|
207
179
|
if (arr.every((v) => !!v)) {
|
208
180
|
return new Map(
|
@@ -216,7 +188,7 @@ function zodCoerceInternal(schema, value, options) {
|
|
216
188
|
}
|
217
189
|
} else if (typeName === ZodFirstPartyTypeKind.ZodRecord) {
|
218
190
|
const schema_ = schema;
|
219
|
-
if (
|
191
|
+
if (isObject(value)) {
|
220
192
|
const newObj = {};
|
221
193
|
for (const [k, v] of Object.entries(value)) {
|
222
194
|
const key = zodCoerceInternal(schema_._def.keyType, k, options_);
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/zod",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.37.0",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -29,13 +29,15 @@
|
|
29
29
|
"dist"
|
30
30
|
],
|
31
31
|
"peerDependencies": {
|
32
|
-
"@orpc/openapi": "0.
|
33
|
-
"@orpc/server": "0.
|
32
|
+
"@orpc/openapi": "0.37.0",
|
33
|
+
"@orpc/server": "0.37.0"
|
34
34
|
},
|
35
35
|
"dependencies": {
|
36
|
+
"@standard-schema/spec": "^1.0.0",
|
36
37
|
"json-schema-typed": "^8.0.1",
|
37
38
|
"wildcard-match": "^5.1.3",
|
38
|
-
"zod": "^3.24.1"
|
39
|
+
"zod": "^3.24.1",
|
40
|
+
"@orpc/shared": "0.37.0"
|
39
41
|
},
|
40
42
|
"scripts": {
|
41
43
|
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|