@orpc/zod 0.0.0-next.bc9d3dd → 0.0.0-next.bf323bf

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/index.js +47 -45
  2. package/package.json +5 -4
package/dist/index.js CHANGED
@@ -1,33 +1,44 @@
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);
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
27
15
  }
16
+ return to;
28
17
  };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ // ../../node_modules/.pnpm/escape-string-regexp@4.0.0/node_modules/escape-string-regexp/index.js
28
+ var require_escape_string_regexp = __commonJS({
29
+ "../../node_modules/.pnpm/escape-string-regexp@4.0.0/node_modules/escape-string-regexp/index.js"(exports, module) {
30
+ "use strict";
31
+ module.exports = (string) => {
32
+ if (typeof string !== "string") {
33
+ throw new TypeError("Expected a string");
34
+ }
35
+ return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
36
+ };
37
+ }
38
+ });
29
39
 
30
40
  // src/coercer.ts
41
+ import { guard, isObject } from "@orpc/shared";
31
42
  import {
32
43
  ZodFirstPartyTypeKind
33
44
  } from "zod";
@@ -128,7 +139,7 @@ function zodCoerceInternal(schema, value, options) {
128
139
  if (value === void 0) {
129
140
  return [];
130
141
  }
131
- if (isPlainObject(value) && Object.keys(value).every((k) => /^[1-9]\d*$/.test(k) || k === "0")) {
142
+ if (isObject(value) && Object.keys(value).every((k) => /^[1-9]\d*$/.test(k) || k === "0")) {
132
143
  const indexes = Object.keys(value).map((k) => Number(k)).sort((a, b) => a - b);
133
144
  const arr = Array.from({ length: (indexes.at(-1) ?? -1) + 1 });
134
145
  for (const i of indexes) {
@@ -139,7 +150,7 @@ function zodCoerceInternal(schema, value, options) {
139
150
  }
140
151
  } else if (typeName === ZodFirstPartyTypeKind.ZodObject) {
141
152
  const schema_ = schema;
142
- if (isPlainObject(value)) {
153
+ if (isObject(value)) {
143
154
  const newObj = {};
144
155
  const keys = /* @__PURE__ */ new Set([
145
156
  ...Object.keys(value),
@@ -177,7 +188,7 @@ function zodCoerceInternal(schema, value, options) {
177
188
  if (value === void 0) {
178
189
  return /* @__PURE__ */ new Set();
179
190
  }
180
- if (isPlainObject(value) && Object.keys(value).every((k) => /^[1-9]\d*$/.test(k) || k === "0")) {
191
+ if (isObject(value) && Object.keys(value).every((k) => /^[1-9]\d*$/.test(k) || k === "0")) {
181
192
  const indexes = Object.keys(value).map((k) => Number(k)).sort((a, b) => a - b);
182
193
  const arr = Array.from({ length: (indexes.at(-1) ?? -1) + 1 });
183
194
  for (const i of indexes) {
@@ -200,9 +211,9 @@ function zodCoerceInternal(schema, value, options) {
200
211
  if (value === void 0) {
201
212
  return /* @__PURE__ */ new Map();
202
213
  }
203
- if (isPlainObject(value)) {
214
+ if (isObject(value)) {
204
215
  const arr = Array.from({ length: Object.keys(value).length }).fill(void 0).map(
205
- (_, i) => isPlainObject(value[i]) && Object.keys(value[i]).length === 2 && "0" in value[i] && "1" in value[i] ? [value[i]["0"], value[i]["1"]] : void 0
216
+ (_, 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
217
  );
207
218
  if (arr.every((v) => !!v)) {
208
219
  return new Map(
@@ -216,7 +227,7 @@ function zodCoerceInternal(schema, value, options) {
216
227
  }
217
228
  } else if (typeName === ZodFirstPartyTypeKind.ZodRecord) {
218
229
  const schema_ = schema;
219
- if (isPlainObject(value)) {
230
+ if (isObject(value)) {
220
231
  const newObj = {};
221
232
  for (const [k, v] of Object.entries(value)) {
222
233
  const key = zodCoerceInternal(schema_._def.keyType, k, options_);
@@ -344,17 +355,8 @@ function zodCoerceInternal(schema, value, options) {
344
355
  }
345
356
 
346
357
  // src/converter.ts
358
+ var import_escape_string_regexp = __toESM(require_escape_string_regexp(), 1);
347
359
  import { JSONSchemaFormat } from "@orpc/openapi";
348
-
349
- // ../../node_modules/.pnpm/escape-string-regexp@5.0.0/node_modules/escape-string-regexp/index.js
350
- function escapeStringRegexp(string) {
351
- if (typeof string !== "string") {
352
- throw new TypeError("Expected a string");
353
- }
354
- return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
355
- }
356
-
357
- // src/converter.ts
358
360
  import {
359
361
  ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2
360
362
  } from "zod";
@@ -614,13 +616,13 @@ function zodToJsonSchema(schema, options) {
614
616
  json.maxLength = check.value;
615
617
  break;
616
618
  case "includes":
617
- json.pattern = escapeStringRegexp(check.value);
619
+ json.pattern = (0, import_escape_string_regexp.default)(check.value);
618
620
  break;
619
621
  case "startsWith":
620
- json.pattern = `^${escapeStringRegexp(check.value)}`;
622
+ json.pattern = `^${(0, import_escape_string_regexp.default)(check.value)}`;
621
623
  break;
622
624
  case "endsWith":
623
- json.pattern = `${escapeStringRegexp(check.value)}$`;
625
+ json.pattern = `${(0, import_escape_string_regexp.default)(check.value)}$`;
624
626
  break;
625
627
  case "emoji":
626
628
  json.pattern = "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/zod",
3
3
  "type": "module",
4
- "version": "0.0.0-next.bc9d3dd",
4
+ "version": "0.0.0-next.bf323bf",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -29,14 +29,15 @@
29
29
  "dist"
30
30
  ],
31
31
  "peerDependencies": {
32
- "@orpc/openapi": "0.0.0-next.bc9d3dd",
33
- "@orpc/server": "0.0.0-next.bc9d3dd"
32
+ "@orpc/openapi": "0.0.0-next.bf323bf",
33
+ "@orpc/server": "0.0.0-next.bf323bf"
34
34
  },
35
35
  "dependencies": {
36
36
  "@standard-schema/spec": "^1.0.0",
37
37
  "json-schema-typed": "^8.0.1",
38
38
  "wildcard-match": "^5.1.3",
39
- "zod": "^3.24.1"
39
+ "zod": "^3.24.1",
40
+ "@orpc/shared": "0.0.0-next.bf323bf"
40
41
  },
41
42
  "scripts": {
42
43
  "build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",