@layerzerolabs/zod-utils 0.2.58 → 0.2.60

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.
@@ -11,17 +11,17 @@
11
11
  CLI Cleaning output folder
12
12
  CJS Build start
13
13
  ESM Build start
14
- ESM dist/schema.js 184.00 B
15
- ESM dist/R6AQXXPU.js 1.14 KB
16
- ESM dist/index.js 4.06 KB
17
- ESM dist/schema.js.map 70.00 B
18
- ESM dist/R6AQXXPU.js.map 3.22 KB
19
- ESM dist/index.js.map 11.03 KB
20
- ESM ⚡️ Build success in 273ms
21
- CJS dist/schema.cjs 709.00 B
22
- CJS dist/index.cjs 4.79 KB
23
- CJS dist/GR4ZG7N6.cjs 1.29 KB
24
- CJS dist/schema.cjs.map 71.00 B
14
+ CJS dist/index.cjs 5.04 KB
15
+ CJS dist/schema.cjs 969.00 B
16
+ CJS dist/GOAM7GGG.cjs 1.96 KB
25
17
  CJS dist/index.cjs.map 11.04 KB
26
- CJS dist/GR4ZG7N6.cjs.map 3.23 KB
27
- CJS ⚡️ Build success in 275ms
18
+ CJS dist/schema.cjs.map 71.00 B
19
+ CJS dist/GOAM7GGG.cjs.map 4.76 KB
20
+ CJS ⚡️ Build success in 131ms
21
+ ESM dist/schema.js 212.00 B
22
+ ESM dist/index.js 4.09 KB
23
+ ESM dist/THJGESDP.js 1.77 KB
24
+ ESM dist/index.js.map 11.03 KB
25
+ ESM dist/THJGESDP.js.map 4.76 KB
26
+ ESM dist/schema.js.map 70.00 B
27
+ ESM ⚡️ Build success in 132ms
@@ -2,7 +2,7 @@
2
2
  > @layerzerolabs/zod-utils@0.0.0 lint /home/runner/work/monorepo-internal/monorepo-internal/packages/zod-utils
3
3
  > eslint . --max-warnings 0 || (eslint . --fix --max-warnings 0 && false)
4
4
 
5
- (node:54593) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/runner/work/monorepo-internal/monorepo-internal/eslint.config.js?mtime=1774057370219 is not specified and it doesn't parse as CommonJS.
5
+ (node:58432) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/runner/work/monorepo-internal/monorepo-internal/eslint.config.js?mtime=1774493247955 is not specified and it doesn't parse as CommonJS.
6
6
  Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
7
7
  To eliminate this warning, add "type": "module" to /home/runner/work/monorepo-internal/monorepo-internal/package.json.
8
8
  (Use `node --trace-warnings ...` to show where the warning was created)
@@ -30,11 +30,29 @@ var createFunctionPointerSchema = /* @__PURE__ */ __name(() => (
30
30
  // FIXME this can be a real schema
31
31
  customSchema()
32
32
  ), "createFunctionPointerSchema");
33
+ var brandedSchemaPropertyKey = "__BRANDED_SCHEMA_NAME";
34
+ var brandSchema = /* @__PURE__ */ __name((schema, name) => Object.defineProperty(schema, brandedSchemaPropertyKey, {
35
+ enumerable: false,
36
+ configurable: false,
37
+ writable: false,
38
+ value: name
39
+ }), "brandSchema");
40
+ var isBrandedWith = /* @__PURE__ */ __name((expected, schema) => {
41
+ if (!(brandedSchemaPropertyKey in expected)) {
42
+ throw new Error("Branded model is not itself branded");
43
+ }
44
+ if (!(brandedSchemaPropertyKey in schema)) {
45
+ return false;
46
+ }
47
+ return schema[brandedSchemaPropertyKey] === expected[brandedSchemaPropertyKey];
48
+ }, "isBrandedWith");
33
49
 
34
50
  exports.__name = __name;
51
+ exports.brandSchema = brandSchema;
35
52
  exports.createFunctionPointerSchema = createFunctionPointerSchema;
36
53
  exports.customSchema = customSchema;
37
54
  exports.functionSchema = functionSchema;
55
+ exports.isBrandedWith = isBrandedWith;
38
56
  exports.schemaIsFunctionSchema = schemaIsFunctionSchema;
39
- //# sourceMappingURL=GR4ZG7N6.cjs.map
40
- //# sourceMappingURL=GR4ZG7N6.cjs.map
57
+ //# sourceMappingURL=GOAM7GGG.cjs.map
58
+ //# sourceMappingURL=GOAM7GGG.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/schema.ts"],"names":["functionSchemaTag","Symbol","functionSchema","input","output","obj","z","object","Object","defineProperty","value","writable","parse","i","Error","schemaIsFunctionSchema","schema","hasOwn","customSchema","validate","custom","createFunctionPointerSchema","brandedSchemaPropertyKey","brandSchema","name","enumerable","configurable","isBrandedWith","expected"],"mappings":";;;;;;AAUA,IAAMA,iBAAAA,GAAoBC,OAAO,uBAAA,CAAA;AAG1B,IAAMC,cAAAA,mBAAiB,MAAA,CAAA,CAAqD,EAC/EC,KAAAA,EACAC,QAAM,KAIT;AACG,EAAA,MAAMC,GAAAA,GAAMC,MAAEC,MAAAA,CAAO;AACjBJ,IAAAA,KAAAA;AACAC,IAAAA;GACJ,CAAA;AACAI,EAAAA,MAAAA,CAAOC,cAAAA,CAAeJ,KAAKL,iBAAAA,EAAmB;IAAEU,KAAAA,EAAO,IAAA;IAAMC,QAAAA,EAAU;GAAM,CAAA;AAI7EN,EAAAA,GAAAA,CAAIO,KAAAA,GAAQ,CAACC,CAAAA,KAAAA;AACT,IAAA,IAAI,OAAOA,MAAM,UAAA,EAAY;AACzB,MAAA,MAAM,IAAIC,KAAAA,CAAM,CAAA,EAAGD,CAAAA,CAAAA,kBAAAA,CAAqB,CAAA;AAC5C,IAAA;AAGA,IAAA,OAAOA,CAAAA;AACX,EAAA,CAAA;AACA,EAAA,OAAOR,GAAAA;AACX,CAAA,EAxB8B,gBAAA;AA0BvB,IAAMU,sBAAAA,2BACTC,MAAAA,KAAAA;AAEA,EAAA,OAAOR,MAAAA,CAAOS,MAAAA,CAAOD,MAAAA,EAAQhB,iBAAAA,CAAAA;AACjC,CAAA,EAJsC,wBAAA;AAM/B,IAAMkB,+BAAe,MAAA,CAAA,CAAIC,QAAAA,KAC5Bb,KAAAA,CAAEc,MAAAA,CAAUD,QAAAA,CAAAA,EADY,cAAA;AAGrB,IAAME,2BAAAA,mBAA8B,MAAA,CAAA;;EAEvCH,YAAAA;AAFuC,CAAA,EAAA,6BAAA;AAY3C,IAAMI,wBAAAA,GAA2B,uBAAA;AAG1B,IAAMC,8BAAc,MAAA,CAAA,CAA2BP,MAAAA,EAAgBQ,SAClEhB,MAAAA,CAAOC,cAAAA,CAAeO,QAAQM,wBAAAA,EAA0B;EACpDG,UAAAA,EAAY,KAAA;EACZC,YAAAA,EAAc,KAAA;EACdf,QAAAA,EAAU,KAAA;EACVD,KAAAA,EAAOc;AACX,CAAA,CAAA,EANuB,aAAA;AAQpB,IAAMG,aAAAA,mBAAgB,MAAA,CAAA,CACzBC,QAAAA,EACAZ,MAAAA,KAAAA;AAEA,EAAA,IAAI,EAAEM,4BAA4BM,QAAAA,CAAAA,EAAW;AACzC,IAAA,MAAM,IAAId,MAAM,qCAAA,CAAA;AACpB,EAAA;AAEA,EAAA,IAAI,EAAEQ,4BAA4BN,MAAAA,CAAAA,EAAS;AACvC,IAAA,OAAO,KAAA;AACX,EAAA;AAEA,EAAA,OAAOA,MAAAA,CAAOM,wBAAAA,CAAAA,KAA8BM,QAAAA,CAASN,wBAAAA,CAAAA;AACzD,CAAA,EAb6B,eAAA","file":"GOAM7GGG.cjs","sourcesContent":["import { z } from 'zod';\n\nimport type { FunctionPointer } from '@layerzerolabs/function-pointer';\n\nexport type InferredArray<T extends z.ZodType[], Output extends any[] = []> = T extends []\n ? Output\n : T extends [infer Head, ...infer Tail extends z.ZodType[]]\n ? InferredArray<Tail, [...Output, z.infer<Head>]>\n : never;\n\nconst functionSchemaTag = Symbol('__FUNCTION_SCHEMA_TAG');\n\n// This essentially replicates the functionality of z.function in zod v3\nexport const functionSchema = <Input extends z.ZodTuple, Output extends z.ZodType>({\n input,\n output,\n}: {\n input: Input;\n output: Output;\n}) => {\n const obj = z.object({\n input,\n output,\n });\n Object.defineProperty(obj, functionSchemaTag, { value: true, writable: false });\n // We don't expect the function to actually be an object with an input field and an output field\n // so we override the parse function. We can't actually parse functions since input and output\n // types are lost at runtime, but we can check the runtime type of the object\n obj.parse = (i) => {\n if (typeof i !== 'function') {\n throw new Error(`${i} is not a function`);\n }\n // The return type here just has to match the inference of z.object,\n // the actual inference of the schema will be the z.ZodType custom\n return i as any;\n };\n return obj as unknown as z.ZodType<(...args: z.infer<Input>) => z.infer<Output>>;\n};\n\nexport const schemaIsFunctionSchema = (\n schema: z.ZodType,\n): schema is ReturnType<typeof functionSchema> => {\n return Object.hasOwn(schema, functionSchemaTag);\n};\n\nexport const customSchema = <T>(validate?: (data: any) => T) =>\n z.custom<T>(validate) as z.ZodType<T>;\n\nexport const createFunctionPointerSchema = <T extends FunctionPointer>() =>\n // FIXME this can be a real schema\n customSchema<T>();\n\nexport type BuildZodObject<T extends object> = z.ZodObject<\n {\n [K in keyof T]: z.ZodType<T[K]>;\n },\n z.core.$strip\n>;\n\n// utils for branding schemata with names\nconst brandedSchemaPropertyKey = '__BRANDED_SCHEMA_NAME' as const;\n\n/** Unavoidably, this mutates the underlying schema. Use with caution. */\nexport const brandSchema = <Schema extends z.ZodType>(schema: Schema, name: string): Schema =>\n Object.defineProperty(schema, brandedSchemaPropertyKey, {\n enumerable: false,\n configurable: false,\n writable: false,\n value: name,\n });\n\nexport const isBrandedWith = <Branded extends z.ZodType>(\n expected: Branded,\n schema: z.ZodType,\n): schema is Branded => {\n if (!(brandedSchemaPropertyKey in expected)) {\n throw new Error('Branded model is not itself branded');\n }\n\n if (!(brandedSchemaPropertyKey in schema)) {\n return false;\n }\n\n return schema[brandedSchemaPropertyKey] === expected[brandedSchemaPropertyKey];\n};\n"]}
@@ -28,7 +28,23 @@ var createFunctionPointerSchema = /* @__PURE__ */ __name(() => (
28
28
  // FIXME this can be a real schema
29
29
  customSchema()
30
30
  ), "createFunctionPointerSchema");
31
+ var brandedSchemaPropertyKey = "__BRANDED_SCHEMA_NAME";
32
+ var brandSchema = /* @__PURE__ */ __name((schema, name) => Object.defineProperty(schema, brandedSchemaPropertyKey, {
33
+ enumerable: false,
34
+ configurable: false,
35
+ writable: false,
36
+ value: name
37
+ }), "brandSchema");
38
+ var isBrandedWith = /* @__PURE__ */ __name((expected, schema) => {
39
+ if (!(brandedSchemaPropertyKey in expected)) {
40
+ throw new Error("Branded model is not itself branded");
41
+ }
42
+ if (!(brandedSchemaPropertyKey in schema)) {
43
+ return false;
44
+ }
45
+ return schema[brandedSchemaPropertyKey] === expected[brandedSchemaPropertyKey];
46
+ }, "isBrandedWith");
31
47
 
32
- export { __name, createFunctionPointerSchema, customSchema, functionSchema, schemaIsFunctionSchema };
33
- //# sourceMappingURL=R6AQXXPU.js.map
34
- //# sourceMappingURL=R6AQXXPU.js.map
48
+ export { __name, brandSchema, createFunctionPointerSchema, customSchema, functionSchema, isBrandedWith, schemaIsFunctionSchema };
49
+ //# sourceMappingURL=THJGESDP.js.map
50
+ //# sourceMappingURL=THJGESDP.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/schema.ts"],"names":["functionSchemaTag","Symbol","functionSchema","input","output","obj","z","object","Object","defineProperty","value","writable","parse","i","Error","schemaIsFunctionSchema","schema","hasOwn","customSchema","validate","custom","createFunctionPointerSchema","brandedSchemaPropertyKey","brandSchema","name","enumerable","configurable","isBrandedWith","expected"],"mappings":";;;;AAUA,IAAMA,iBAAAA,GAAoBC,OAAO,uBAAA,CAAA;AAG1B,IAAMC,cAAAA,mBAAiB,MAAA,CAAA,CAAqD,EAC/EC,KAAAA,EACAC,QAAM,KAIT;AACG,EAAA,MAAMC,GAAAA,GAAMC,EAAEC,MAAAA,CAAO;AACjBJ,IAAAA,KAAAA;AACAC,IAAAA;GACJ,CAAA;AACAI,EAAAA,MAAAA,CAAOC,cAAAA,CAAeJ,KAAKL,iBAAAA,EAAmB;IAAEU,KAAAA,EAAO,IAAA;IAAMC,QAAAA,EAAU;GAAM,CAAA;AAI7EN,EAAAA,GAAAA,CAAIO,KAAAA,GAAQ,CAACC,CAAAA,KAAAA;AACT,IAAA,IAAI,OAAOA,MAAM,UAAA,EAAY;AACzB,MAAA,MAAM,IAAIC,KAAAA,CAAM,CAAA,EAAGD,CAAAA,CAAAA,kBAAAA,CAAqB,CAAA;AAC5C,IAAA;AAGA,IAAA,OAAOA,CAAAA;AACX,EAAA,CAAA;AACA,EAAA,OAAOR,GAAAA;AACX,CAAA,EAxB8B,gBAAA;AA0BvB,IAAMU,sBAAAA,2BACTC,MAAAA,KAAAA;AAEA,EAAA,OAAOR,MAAAA,CAAOS,MAAAA,CAAOD,MAAAA,EAAQhB,iBAAAA,CAAAA;AACjC,CAAA,EAJsC,wBAAA;AAM/B,IAAMkB,+BAAe,MAAA,CAAA,CAAIC,QAAAA,KAC5Bb,CAAAA,CAAEc,MAAAA,CAAUD,QAAAA,CAAAA,EADY,cAAA;AAGrB,IAAME,2BAAAA,mBAA8B,MAAA,CAAA;;EAEvCH,YAAAA;AAFuC,CAAA,EAAA,6BAAA;AAY3C,IAAMI,wBAAAA,GAA2B,uBAAA;AAG1B,IAAMC,8BAAc,MAAA,CAAA,CAA2BP,MAAAA,EAAgBQ,SAClEhB,MAAAA,CAAOC,cAAAA,CAAeO,QAAQM,wBAAAA,EAA0B;EACpDG,UAAAA,EAAY,KAAA;EACZC,YAAAA,EAAc,KAAA;EACdf,QAAAA,EAAU,KAAA;EACVD,KAAAA,EAAOc;AACX,CAAA,CAAA,EANuB,aAAA;AAQpB,IAAMG,aAAAA,mBAAgB,MAAA,CAAA,CACzBC,QAAAA,EACAZ,MAAAA,KAAAA;AAEA,EAAA,IAAI,EAAEM,4BAA4BM,QAAAA,CAAAA,EAAW;AACzC,IAAA,MAAM,IAAId,MAAM,qCAAA,CAAA;AACpB,EAAA;AAEA,EAAA,IAAI,EAAEQ,4BAA4BN,MAAAA,CAAAA,EAAS;AACvC,IAAA,OAAO,KAAA;AACX,EAAA;AAEA,EAAA,OAAOA,MAAAA,CAAOM,wBAAAA,CAAAA,KAA8BM,QAAAA,CAASN,wBAAAA,CAAAA;AACzD,CAAA,EAb6B,eAAA","file":"THJGESDP.js","sourcesContent":["import { z } from 'zod';\n\nimport type { FunctionPointer } from '@layerzerolabs/function-pointer';\n\nexport type InferredArray<T extends z.ZodType[], Output extends any[] = []> = T extends []\n ? Output\n : T extends [infer Head, ...infer Tail extends z.ZodType[]]\n ? InferredArray<Tail, [...Output, z.infer<Head>]>\n : never;\n\nconst functionSchemaTag = Symbol('__FUNCTION_SCHEMA_TAG');\n\n// This essentially replicates the functionality of z.function in zod v3\nexport const functionSchema = <Input extends z.ZodTuple, Output extends z.ZodType>({\n input,\n output,\n}: {\n input: Input;\n output: Output;\n}) => {\n const obj = z.object({\n input,\n output,\n });\n Object.defineProperty(obj, functionSchemaTag, { value: true, writable: false });\n // We don't expect the function to actually be an object with an input field and an output field\n // so we override the parse function. We can't actually parse functions since input and output\n // types are lost at runtime, but we can check the runtime type of the object\n obj.parse = (i) => {\n if (typeof i !== 'function') {\n throw new Error(`${i} is not a function`);\n }\n // The return type here just has to match the inference of z.object,\n // the actual inference of the schema will be the z.ZodType custom\n return i as any;\n };\n return obj as unknown as z.ZodType<(...args: z.infer<Input>) => z.infer<Output>>;\n};\n\nexport const schemaIsFunctionSchema = (\n schema: z.ZodType,\n): schema is ReturnType<typeof functionSchema> => {\n return Object.hasOwn(schema, functionSchemaTag);\n};\n\nexport const customSchema = <T>(validate?: (data: any) => T) =>\n z.custom<T>(validate) as z.ZodType<T>;\n\nexport const createFunctionPointerSchema = <T extends FunctionPointer>() =>\n // FIXME this can be a real schema\n customSchema<T>();\n\nexport type BuildZodObject<T extends object> = z.ZodObject<\n {\n [K in keyof T]: z.ZodType<T[K]>;\n },\n z.core.$strip\n>;\n\n// utils for branding schemata with names\nconst brandedSchemaPropertyKey = '__BRANDED_SCHEMA_NAME' as const;\n\n/** Unavoidably, this mutates the underlying schema. Use with caution. */\nexport const brandSchema = <Schema extends z.ZodType>(schema: Schema, name: string): Schema =>\n Object.defineProperty(schema, brandedSchemaPropertyKey, {\n enumerable: false,\n configurable: false,\n writable: false,\n value: name,\n });\n\nexport const isBrandedWith = <Branded extends z.ZodType>(\n expected: Branded,\n schema: z.ZodType,\n): schema is Branded => {\n if (!(brandedSchemaPropertyKey in expected)) {\n throw new Error('Branded model is not itself branded');\n }\n\n if (!(brandedSchemaPropertyKey in schema)) {\n return false;\n }\n\n return schema[brandedSchemaPropertyKey] === expected[brandedSchemaPropertyKey];\n};\n"]}
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var GR4ZG7N6_cjs = require('./GR4ZG7N6.cjs');
3
+ var GOAM7GGG_cjs = require('./GOAM7GGG.cjs');
4
4
  var zod = require('zod');
5
5
 
6
6
  var RESOLVING = Symbol("mapOnSchema/resolving");
@@ -18,7 +18,7 @@ function mapOnSchema(schema, fn) {
18
18
  results.set(s, result);
19
19
  return result;
20
20
  }
21
- GR4ZG7N6_cjs.__name(mapElement, "mapElement");
21
+ GOAM7GGG_cjs.__name(mapElement, "mapElement");
22
22
  function mapInner() {
23
23
  if (schema instanceof zod.z.ZodObject) {
24
24
  const newShape = {};
@@ -69,7 +69,7 @@ function mapOnSchema(schema, fn) {
69
69
  return new zod.z.ZodLazy({
70
70
  ...schema.def,
71
71
  // NB: This leaks `fn` into the schema, but there is no other way to support recursive schemas
72
- getter: /* @__PURE__ */ GR4ZG7N6_cjs.__name(() => mapElement(schema.def.getter()), "getter")
72
+ getter: /* @__PURE__ */ GOAM7GGG_cjs.__name(() => mapElement(schema.def.getter()), "getter")
73
73
  });
74
74
  } else if (schema instanceof zod.z.ZodPromise) {
75
75
  return new zod.z.ZodPromise({
@@ -108,34 +108,42 @@ function mapOnSchema(schema, fn) {
108
108
  return schema;
109
109
  }
110
110
  }
111
- GR4ZG7N6_cjs.__name(mapInner, "mapInner");
111
+ GOAM7GGG_cjs.__name(mapInner, "mapInner");
112
112
  return fn(mapInner());
113
113
  }
114
- GR4ZG7N6_cjs.__name(mapOnSchema, "mapOnSchema");
114
+ GOAM7GGG_cjs.__name(mapOnSchema, "mapOnSchema");
115
115
  function zodDeepPartial(schema) {
116
116
  return mapOnSchema(schema, (s) => s?.optional?.());
117
117
  }
118
- GR4ZG7N6_cjs.__name(zodDeepPartial, "zodDeepPartial");
118
+ GOAM7GGG_cjs.__name(zodDeepPartial, "zodDeepPartial");
119
119
  function zodDeepRequired(schema) {
120
120
  return mapOnSchema(schema, (s) => s?.nonoptional?.());
121
121
  }
122
- GR4ZG7N6_cjs.__name(zodDeepRequired, "zodDeepRequired");
122
+ GOAM7GGG_cjs.__name(zodDeepRequired, "zodDeepRequired");
123
123
 
124
+ Object.defineProperty(exports, "brandSchema", {
125
+ enumerable: true,
126
+ get: function () { return GOAM7GGG_cjs.brandSchema; }
127
+ });
124
128
  Object.defineProperty(exports, "createFunctionPointerSchema", {
125
129
  enumerable: true,
126
- get: function () { return GR4ZG7N6_cjs.createFunctionPointerSchema; }
130
+ get: function () { return GOAM7GGG_cjs.createFunctionPointerSchema; }
127
131
  });
128
132
  Object.defineProperty(exports, "customSchema", {
129
133
  enumerable: true,
130
- get: function () { return GR4ZG7N6_cjs.customSchema; }
134
+ get: function () { return GOAM7GGG_cjs.customSchema; }
131
135
  });
132
136
  Object.defineProperty(exports, "functionSchema", {
133
137
  enumerable: true,
134
- get: function () { return GR4ZG7N6_cjs.functionSchema; }
138
+ get: function () { return GOAM7GGG_cjs.functionSchema; }
139
+ });
140
+ Object.defineProperty(exports, "isBrandedWith", {
141
+ enumerable: true,
142
+ get: function () { return GOAM7GGG_cjs.isBrandedWith; }
135
143
  });
136
144
  Object.defineProperty(exports, "schemaIsFunctionSchema", {
137
145
  enumerable: true,
138
- get: function () { return GR4ZG7N6_cjs.schemaIsFunctionSchema; }
146
+ get: function () { return GOAM7GGG_cjs.schemaIsFunctionSchema; }
139
147
  });
140
148
  exports.mapOnSchema = mapOnSchema;
141
149
  exports.zodDeepPartial = zodDeepPartial;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { __name } from './R6AQXXPU.js';
2
- export { createFunctionPointerSchema, customSchema, functionSchema, schemaIsFunctionSchema } from './R6AQXXPU.js';
1
+ import { __name } from './THJGESDP.js';
2
+ export { brandSchema, createFunctionPointerSchema, customSchema, functionSchema, isBrandedWith, schemaIsFunctionSchema } from './THJGESDP.js';
3
3
  import { z } from 'zod';
4
4
 
5
5
  var RESOLVING = Symbol("mapOnSchema/resolving");
package/dist/schema.cjs CHANGED
@@ -1,24 +1,32 @@
1
1
  'use strict';
2
2
 
3
- var GR4ZG7N6_cjs = require('./GR4ZG7N6.cjs');
3
+ var GOAM7GGG_cjs = require('./GOAM7GGG.cjs');
4
4
 
5
5
 
6
6
 
7
+ Object.defineProperty(exports, "brandSchema", {
8
+ enumerable: true,
9
+ get: function () { return GOAM7GGG_cjs.brandSchema; }
10
+ });
7
11
  Object.defineProperty(exports, "createFunctionPointerSchema", {
8
12
  enumerable: true,
9
- get: function () { return GR4ZG7N6_cjs.createFunctionPointerSchema; }
13
+ get: function () { return GOAM7GGG_cjs.createFunctionPointerSchema; }
10
14
  });
11
15
  Object.defineProperty(exports, "customSchema", {
12
16
  enumerable: true,
13
- get: function () { return GR4ZG7N6_cjs.customSchema; }
17
+ get: function () { return GOAM7GGG_cjs.customSchema; }
14
18
  });
15
19
  Object.defineProperty(exports, "functionSchema", {
16
20
  enumerable: true,
17
- get: function () { return GR4ZG7N6_cjs.functionSchema; }
21
+ get: function () { return GOAM7GGG_cjs.functionSchema; }
22
+ });
23
+ Object.defineProperty(exports, "isBrandedWith", {
24
+ enumerable: true,
25
+ get: function () { return GOAM7GGG_cjs.isBrandedWith; }
18
26
  });
19
27
  Object.defineProperty(exports, "schemaIsFunctionSchema", {
20
28
  enumerable: true,
21
- get: function () { return GR4ZG7N6_cjs.schemaIsFunctionSchema; }
29
+ get: function () { return GOAM7GGG_cjs.schemaIsFunctionSchema; }
22
30
  });
23
31
  //# sourceMappingURL=schema.cjs.map
24
32
  //# sourceMappingURL=schema.cjs.map
package/dist/schema.d.ts CHANGED
@@ -11,4 +11,7 @@ export declare const createFunctionPointerSchema: <T extends FunctionPointer>()
11
11
  export type BuildZodObject<T extends object> = z.ZodObject<{
12
12
  [K in keyof T]: z.ZodType<T[K]>;
13
13
  }, z.core.$strip>;
14
+ /** Unavoidably, this mutates the underlying schema. Use with caution. */
15
+ export declare const brandSchema: <Schema extends z.ZodType>(schema: Schema, name: string) => Schema;
16
+ export declare const isBrandedWith: <Branded extends z.ZodType>(expected: Branded, schema: z.ZodType) => schema is Branded;
14
17
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAEvE,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE,MAAM,SAAS,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,SAAS,EAAE,GACpF,MAAM,GACN,CAAC,SAAS,CAAC,MAAM,IAAI,EAAE,GAAG,MAAM,IAAI,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC,GACvD,aAAa,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,GAC/C,KAAK,CAAC;AAKd,eAAO,MAAM,cAAc,GAAI,KAAK,SAAS,CAAC,CAAC,QAAQ,EAAE,MAAM,SAAS,CAAC,CAAC,OAAO,EAAE,oBAGhF;IACC,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAClB,KAiB4B,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAClF,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAC/B,QAAQ,CAAC,CAAC,OAAO,KAClB,MAAM,IAAI,UAAU,CAAC,OAAO,cAAc,CAE5C,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,CAAC,EAAE,WAAW,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,KAC9B,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAE1C,eAAO,MAAM,2BAA2B,GAAI,CAAC,SAAS,eAAe,kEAEhD,CAAC;AAEtB,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,CAAC,SAAS,CACtD;KACK,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAClC,EACD,CAAC,CAAC,IAAI,CAAC,MAAM,CAChB,CAAC"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAEvE,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE,MAAM,SAAS,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,SAAS,EAAE,GACpF,MAAM,GACN,CAAC,SAAS,CAAC,MAAM,IAAI,EAAE,GAAG,MAAM,IAAI,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC,GACvD,aAAa,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,GAC/C,KAAK,CAAC;AAKd,eAAO,MAAM,cAAc,GAAI,KAAK,SAAS,CAAC,CAAC,QAAQ,EAAE,MAAM,SAAS,CAAC,CAAC,OAAO,EAAE,oBAGhF;IACC,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAClB,KAiB4B,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAClF,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAC/B,QAAQ,CAAC,CAAC,OAAO,KAClB,MAAM,IAAI,UAAU,CAAC,OAAO,cAAc,CAE5C,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,CAAC,EAAE,WAAW,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,KAC9B,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAE1C,eAAO,MAAM,2BAA2B,GAAI,CAAC,SAAS,eAAe,kEAEhD,CAAC;AAEtB,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,CAAC,SAAS,CACtD;KACK,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAClC,EACD,CAAC,CAAC,IAAI,CAAC,MAAM,CAChB,CAAC;AAKF,yEAAyE;AACzE,eAAO,MAAM,WAAW,GAAI,MAAM,SAAS,CAAC,CAAC,OAAO,EAAE,QAAQ,MAAM,EAAE,MAAM,MAAM,KAAG,MAM/E,CAAC;AAEP,eAAO,MAAM,aAAa,GAAI,OAAO,SAAS,CAAC,CAAC,OAAO,EACnD,UAAU,OAAO,EACjB,QAAQ,CAAC,CAAC,OAAO,KAClB,MAAM,IAAI,OAUZ,CAAC"}
package/dist/schema.js CHANGED
@@ -1,3 +1,3 @@
1
- export { createFunctionPointerSchema, customSchema, functionSchema, schemaIsFunctionSchema } from './R6AQXXPU.js';
1
+ export { brandSchema, createFunctionPointerSchema, customSchema, functionSchema, isBrandedWith, schemaIsFunctionSchema } from './THJGESDP.js';
2
2
  //# sourceMappingURL=schema.js.map
3
3
  //# sourceMappingURL=schema.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layerzerolabs/zod-utils",
3
- "version": "0.2.58",
3
+ "version": "0.2.60",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -15,12 +15,12 @@
15
15
  "types": "./dist/index.d.ts",
16
16
  "dependencies": {
17
17
  "zod": "4.3.5",
18
- "@layerzerolabs/function-pointer": "0.2.58"
18
+ "@layerzerolabs/function-pointer": "0.2.60"
19
19
  },
20
20
  "devDependencies": {
21
21
  "tsup": "^8.4.0",
22
- "@layerzerolabs/tsup-configuration": "0.2.58",
23
- "@layerzerolabs/typescript-configuration": "0.2.58"
22
+ "@layerzerolabs/tsup-configuration": "0.2.60",
23
+ "@layerzerolabs/typescript-configuration": "0.2.60"
24
24
  },
25
25
  "publishConfig": {
26
26
  "access": "restricted",
package/src/schema.ts CHANGED
@@ -56,3 +56,30 @@ export type BuildZodObject<T extends object> = z.ZodObject<
56
56
  },
57
57
  z.core.$strip
58
58
  >;
59
+
60
+ // utils for branding schemata with names
61
+ const brandedSchemaPropertyKey = '__BRANDED_SCHEMA_NAME' as const;
62
+
63
+ /** Unavoidably, this mutates the underlying schema. Use with caution. */
64
+ export const brandSchema = <Schema extends z.ZodType>(schema: Schema, name: string): Schema =>
65
+ Object.defineProperty(schema, brandedSchemaPropertyKey, {
66
+ enumerable: false,
67
+ configurable: false,
68
+ writable: false,
69
+ value: name,
70
+ });
71
+
72
+ export const isBrandedWith = <Branded extends z.ZodType>(
73
+ expected: Branded,
74
+ schema: z.ZodType,
75
+ ): schema is Branded => {
76
+ if (!(brandedSchemaPropertyKey in expected)) {
77
+ throw new Error('Branded model is not itself branded');
78
+ }
79
+
80
+ if (!(brandedSchemaPropertyKey in schema)) {
81
+ return false;
82
+ }
83
+
84
+ return schema[brandedSchemaPropertyKey] === expected[brandedSchemaPropertyKey];
85
+ };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/schema.ts"],"names":["functionSchemaTag","Symbol","functionSchema","input","output","obj","z","object","Object","defineProperty","value","writable","parse","i","Error","schemaIsFunctionSchema","schema","hasOwn","customSchema","validate","custom","createFunctionPointerSchema"],"mappings":";;;;;;AAUA,IAAMA,iBAAAA,GAAoBC,OAAO,uBAAA,CAAA;AAG1B,IAAMC,cAAAA,mBAAiB,MAAA,CAAA,CAAqD,EAC/EC,KAAAA,EACAC,QAAM,KAIT;AACG,EAAA,MAAMC,GAAAA,GAAMC,MAAEC,MAAAA,CAAO;AACjBJ,IAAAA,KAAAA;AACAC,IAAAA;GACJ,CAAA;AACAI,EAAAA,MAAAA,CAAOC,cAAAA,CAAeJ,KAAKL,iBAAAA,EAAmB;IAAEU,KAAAA,EAAO,IAAA;IAAMC,QAAAA,EAAU;GAAM,CAAA;AAI7EN,EAAAA,GAAAA,CAAIO,KAAAA,GAAQ,CAACC,CAAAA,KAAAA;AACT,IAAA,IAAI,OAAOA,MAAM,UAAA,EAAY;AACzB,MAAA,MAAM,IAAIC,KAAAA,CAAM,CAAA,EAAGD,CAAAA,CAAAA,kBAAAA,CAAqB,CAAA;AAC5C,IAAA;AAGA,IAAA,OAAOA,CAAAA;AACX,EAAA,CAAA;AACA,EAAA,OAAOR,GAAAA;AACX,CAAA,EAxB8B,gBAAA;AA0BvB,IAAMU,sBAAAA,2BACTC,MAAAA,KAAAA;AAEA,EAAA,OAAOR,MAAAA,CAAOS,MAAAA,CAAOD,MAAAA,EAAQhB,iBAAAA,CAAAA;AACjC,CAAA,EAJsC,wBAAA;AAM/B,IAAMkB,+BAAe,MAAA,CAAA,CAAIC,QAAAA,KAC5Bb,KAAAA,CAAEc,MAAAA,CAAUD,QAAAA,CAAAA,EADY,cAAA;AAGrB,IAAME,2BAAAA,mBAA8B,MAAA,CAAA;;EAEvCH,YAAAA;AAFuC,CAAA,EAAA,6BAAA","file":"GR4ZG7N6.cjs","sourcesContent":["import { z } from 'zod';\n\nimport type { FunctionPointer } from '@layerzerolabs/function-pointer';\n\nexport type InferredArray<T extends z.ZodType[], Output extends any[] = []> = T extends []\n ? Output\n : T extends [infer Head, ...infer Tail extends z.ZodType[]]\n ? InferredArray<Tail, [...Output, z.infer<Head>]>\n : never;\n\nconst functionSchemaTag = Symbol('__FUNCTION_SCHEMA_TAG');\n\n// This essentially replicates the functionality of z.function in zod v3\nexport const functionSchema = <Input extends z.ZodTuple, Output extends z.ZodType>({\n input,\n output,\n}: {\n input: Input;\n output: Output;\n}) => {\n const obj = z.object({\n input,\n output,\n });\n Object.defineProperty(obj, functionSchemaTag, { value: true, writable: false });\n // We don't expect the function to actually be an object with an input field and an output field\n // so we override the parse function. We can't actually parse functions since input and output\n // types are lost at runtime, but we can check the runtime type of the object\n obj.parse = (i) => {\n if (typeof i !== 'function') {\n throw new Error(`${i} is not a function`);\n }\n // The return type here just has to match the inference of z.object,\n // the actual inference of the schema will be the z.ZodType custom\n return i as any;\n };\n return obj as unknown as z.ZodType<(...args: z.infer<Input>) => z.infer<Output>>;\n};\n\nexport const schemaIsFunctionSchema = (\n schema: z.ZodType,\n): schema is ReturnType<typeof functionSchema> => {\n return Object.hasOwn(schema, functionSchemaTag);\n};\n\nexport const customSchema = <T>(validate?: (data: any) => T) =>\n z.custom<T>(validate) as z.ZodType<T>;\n\nexport const createFunctionPointerSchema = <T extends FunctionPointer>() =>\n // FIXME this can be a real schema\n customSchema<T>();\n\nexport type BuildZodObject<T extends object> = z.ZodObject<\n {\n [K in keyof T]: z.ZodType<T[K]>;\n },\n z.core.$strip\n>;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/schema.ts"],"names":["functionSchemaTag","Symbol","functionSchema","input","output","obj","z","object","Object","defineProperty","value","writable","parse","i","Error","schemaIsFunctionSchema","schema","hasOwn","customSchema","validate","custom","createFunctionPointerSchema"],"mappings":";;;;AAUA,IAAMA,iBAAAA,GAAoBC,OAAO,uBAAA,CAAA;AAG1B,IAAMC,cAAAA,mBAAiB,MAAA,CAAA,CAAqD,EAC/EC,KAAAA,EACAC,QAAM,KAIT;AACG,EAAA,MAAMC,GAAAA,GAAMC,EAAEC,MAAAA,CAAO;AACjBJ,IAAAA,KAAAA;AACAC,IAAAA;GACJ,CAAA;AACAI,EAAAA,MAAAA,CAAOC,cAAAA,CAAeJ,KAAKL,iBAAAA,EAAmB;IAAEU,KAAAA,EAAO,IAAA;IAAMC,QAAAA,EAAU;GAAM,CAAA;AAI7EN,EAAAA,GAAAA,CAAIO,KAAAA,GAAQ,CAACC,CAAAA,KAAAA;AACT,IAAA,IAAI,OAAOA,MAAM,UAAA,EAAY;AACzB,MAAA,MAAM,IAAIC,KAAAA,CAAM,CAAA,EAAGD,CAAAA,CAAAA,kBAAAA,CAAqB,CAAA;AAC5C,IAAA;AAGA,IAAA,OAAOA,CAAAA;AACX,EAAA,CAAA;AACA,EAAA,OAAOR,GAAAA;AACX,CAAA,EAxB8B,gBAAA;AA0BvB,IAAMU,sBAAAA,2BACTC,MAAAA,KAAAA;AAEA,EAAA,OAAOR,MAAAA,CAAOS,MAAAA,CAAOD,MAAAA,EAAQhB,iBAAAA,CAAAA;AACjC,CAAA,EAJsC,wBAAA;AAM/B,IAAMkB,+BAAe,MAAA,CAAA,CAAIC,QAAAA,KAC5Bb,CAAAA,CAAEc,MAAAA,CAAUD,QAAAA,CAAAA,EADY,cAAA;AAGrB,IAAME,2BAAAA,mBAA8B,MAAA,CAAA;;EAEvCH,YAAAA;AAFuC,CAAA,EAAA,6BAAA","file":"R6AQXXPU.js","sourcesContent":["import { z } from 'zod';\n\nimport type { FunctionPointer } from '@layerzerolabs/function-pointer';\n\nexport type InferredArray<T extends z.ZodType[], Output extends any[] = []> = T extends []\n ? Output\n : T extends [infer Head, ...infer Tail extends z.ZodType[]]\n ? InferredArray<Tail, [...Output, z.infer<Head>]>\n : never;\n\nconst functionSchemaTag = Symbol('__FUNCTION_SCHEMA_TAG');\n\n// This essentially replicates the functionality of z.function in zod v3\nexport const functionSchema = <Input extends z.ZodTuple, Output extends z.ZodType>({\n input,\n output,\n}: {\n input: Input;\n output: Output;\n}) => {\n const obj = z.object({\n input,\n output,\n });\n Object.defineProperty(obj, functionSchemaTag, { value: true, writable: false });\n // We don't expect the function to actually be an object with an input field and an output field\n // so we override the parse function. We can't actually parse functions since input and output\n // types are lost at runtime, but we can check the runtime type of the object\n obj.parse = (i) => {\n if (typeof i !== 'function') {\n throw new Error(`${i} is not a function`);\n }\n // The return type here just has to match the inference of z.object,\n // the actual inference of the schema will be the z.ZodType custom\n return i as any;\n };\n return obj as unknown as z.ZodType<(...args: z.infer<Input>) => z.infer<Output>>;\n};\n\nexport const schemaIsFunctionSchema = (\n schema: z.ZodType,\n): schema is ReturnType<typeof functionSchema> => {\n return Object.hasOwn(schema, functionSchemaTag);\n};\n\nexport const customSchema = <T>(validate?: (data: any) => T) =>\n z.custom<T>(validate) as z.ZodType<T>;\n\nexport const createFunctionPointerSchema = <T extends FunctionPointer>() =>\n // FIXME this can be a real schema\n customSchema<T>();\n\nexport type BuildZodObject<T extends object> = z.ZodObject<\n {\n [K in keyof T]: z.ZodType<T[K]>;\n },\n z.core.$strip\n>;\n"]}