@powerlines/schema 0.11.41 → 0.11.42

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 (50) hide show
  1. package/dist/bundle.cjs +0 -1
  2. package/dist/codegen.cjs +0 -1
  3. package/dist/constants.cjs +0 -2
  4. package/dist/constants.d.cts +1 -1
  5. package/dist/constants.d.mts +1 -1
  6. package/dist/constants.mjs +0 -1
  7. package/dist/constants.mjs.map +1 -1
  8. package/dist/extract.cjs +23 -9
  9. package/dist/extract.d.cts +2 -3
  10. package/dist/extract.d.cts.map +1 -1
  11. package/dist/extract.d.mts +2 -3
  12. package/dist/extract.d.mts.map +1 -1
  13. package/dist/extract.mjs +28 -12
  14. package/dist/extract.mjs.map +1 -1
  15. package/dist/helpers.cjs +0 -1
  16. package/dist/index.cjs +2 -1
  17. package/dist/index.d.cts +30 -4
  18. package/dist/index.d.cts.map +1 -0
  19. package/dist/index.d.mts +30 -4
  20. package/dist/index.d.mts.map +1 -0
  21. package/dist/index.mjs +3 -3
  22. package/dist/metadata.cjs +1 -2
  23. package/dist/metadata.d.cts.map +1 -1
  24. package/dist/metadata.d.mts.map +1 -1
  25. package/dist/metadata.mjs +1 -1
  26. package/dist/metadata.mjs.map +1 -1
  27. package/dist/persistence.cjs +0 -1
  28. package/dist/reflection.cjs +0 -1
  29. package/dist/resolve.cjs +0 -1
  30. package/dist/type-checks.cjs +27 -2
  31. package/dist/type-checks.d.cts +17 -1
  32. package/dist/type-checks.d.cts.map +1 -1
  33. package/dist/type-checks.d.mts +17 -1
  34. package/dist/type-checks.d.mts.map +1 -1
  35. package/dist/type-checks.mjs +25 -1
  36. package/dist/type-checks.mjs.map +1 -1
  37. package/dist/types.d.cts +34 -19
  38. package/dist/types.d.cts.map +1 -1
  39. package/dist/types.d.mts +34 -19
  40. package/dist/types.d.mts.map +1 -1
  41. package/dist/validate.cjs +1 -12
  42. package/dist/validate.mjs +1 -10
  43. package/dist/validate.mjs.map +1 -1
  44. package/package.json +20 -53
  45. package/dist/types.cjs +0 -0
  46. package/dist/types.mjs +0 -1
  47. package/dist/validate.d.cts +0 -21
  48. package/dist/validate.d.cts.map +0 -1
  49. package/dist/validate.d.mts +0 -21
  50. package/dist/validate.d.mts.map +0 -1
package/dist/bundle.cjs CHANGED
@@ -1,4 +1,3 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
1
  const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
2
  let _powerlines_core_lib_unplugin = require("@powerlines/core/lib/unplugin");
4
3
  let _powerlines_unplugin_rolldown = require("@powerlines/unplugin/rolldown");
package/dist/codegen.cjs CHANGED
@@ -1,4 +1,3 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
1
  const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
2
  const require_metadata = require('./metadata.cjs');
4
3
  const require_type_checks = require('./type-checks.cjs');
@@ -1,4 +1,3 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
1
 
3
2
  //#region src/constants.ts
4
3
  const JsonSchemaTypes = {
@@ -25,7 +24,6 @@ const JSON_SCHEMA_METADATA_KEYS = [
25
24
  "title",
26
25
  "description",
27
26
  "examples",
28
- "visibility",
29
27
  "hidden",
30
28
  "ignore",
31
29
  "internal",
@@ -9,7 +9,7 @@ declare const JsonSchemaTypes: {
9
9
  readonly ARRAY: "array";
10
10
  };
11
11
  declare const JSON_SCHEMA_DATA_TYPES: readonly ["string", "number", "integer", "boolean", "array", "object", "null"];
12
- declare const JSON_SCHEMA_METADATA_KEYS: ("title" | "description" | "docs" | "examples" | "alias" | "tags" | "visibility" | "deprecated" | "hidden" | "ignore" | "internal" | "runtime" | "readOnly" | "writeOnly")[];
12
+ declare const JSON_SCHEMA_METADATA_KEYS: ("title" | "description" | "docs" | "examples" | "alias" | "tags" | "deprecated" | "hidden" | "ignore" | "internal" | "runtime" | "readOnly" | "writeOnly")[];
13
13
  //#endregion
14
14
  export { JSON_SCHEMA_DATA_TYPES, JSON_SCHEMA_METADATA_KEYS, JsonSchemaTypes };
15
15
  //# sourceMappingURL=constants.d.cts.map
@@ -9,7 +9,7 @@ declare const JsonSchemaTypes: {
9
9
  readonly ARRAY: "array";
10
10
  };
11
11
  declare const JSON_SCHEMA_DATA_TYPES: readonly ["string", "number", "integer", "boolean", "array", "object", "null"];
12
- declare const JSON_SCHEMA_METADATA_KEYS: ("title" | "description" | "docs" | "examples" | "alias" | "tags" | "visibility" | "deprecated" | "hidden" | "ignore" | "internal" | "runtime" | "readOnly" | "writeOnly")[];
12
+ declare const JSON_SCHEMA_METADATA_KEYS: ("title" | "description" | "docs" | "examples" | "alias" | "tags" | "deprecated" | "hidden" | "ignore" | "internal" | "runtime" | "readOnly" | "writeOnly")[];
13
13
  //#endregion
14
14
  export { JSON_SCHEMA_DATA_TYPES, JSON_SCHEMA_METADATA_KEYS, JsonSchemaTypes };
15
15
  //# sourceMappingURL=constants.d.mts.map
@@ -23,7 +23,6 @@ const JSON_SCHEMA_METADATA_KEYS = [
23
23
  "title",
24
24
  "description",
25
25
  "examples",
26
- "visibility",
27
26
  "hidden",
28
27
  "ignore",
29
28
  "internal",
@@ -1 +1 @@
1
- {"version":3,"file":"constants.mjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { SchemaMetadata } from \"./types\";\n\nexport const JsonSchemaTypes = {\n STRING: \"string\",\n NUMBER: \"number\",\n INTEGER: \"integer\",\n BOOLEAN: \"boolean\",\n NULL: \"null\",\n OBJECT: \"object\",\n ARRAY: \"array\"\n} as const;\n\nexport const JSON_SCHEMA_DATA_TYPES = [\n JsonSchemaTypes.STRING,\n JsonSchemaTypes.NUMBER,\n JsonSchemaTypes.INTEGER,\n JsonSchemaTypes.BOOLEAN,\n JsonSchemaTypes.ARRAY,\n JsonSchemaTypes.OBJECT,\n JsonSchemaTypes.NULL\n] as const;\n\nexport const JSON_SCHEMA_METADATA_KEYS = [\n \"docs\",\n \"deprecated\",\n \"title\",\n \"description\",\n \"examples\",\n \"visibility\",\n \"hidden\",\n \"ignore\",\n \"internal\",\n \"runtime\",\n \"readOnly\",\n \"writeOnly\",\n \"alias\",\n \"tags\"\n] satisfies ReadonlyArray<keyof SchemaMetadata>;\n"],"mappings":";AAoBA,MAAa,kBAAkB;CAC7B,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,SAAS;CACT,MAAM;CACN,QAAQ;CACR,OAAO;AACT;AAEA,MAAa,yBAAyB;CACpC,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;AAClB;AAEA,MAAa,4BAA4B;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
1
+ {"version":3,"file":"constants.mjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { SchemaMetadata } from \"./types\";\n\nexport const JsonSchemaTypes = {\n STRING: \"string\",\n NUMBER: \"number\",\n INTEGER: \"integer\",\n BOOLEAN: \"boolean\",\n NULL: \"null\",\n OBJECT: \"object\",\n ARRAY: \"array\"\n} as const;\n\nexport const JSON_SCHEMA_DATA_TYPES = [\n JsonSchemaTypes.STRING,\n JsonSchemaTypes.NUMBER,\n JsonSchemaTypes.INTEGER,\n JsonSchemaTypes.BOOLEAN,\n JsonSchemaTypes.ARRAY,\n JsonSchemaTypes.OBJECT,\n JsonSchemaTypes.NULL\n] as const;\n\nexport const JSON_SCHEMA_METADATA_KEYS = [\n \"docs\",\n \"deprecated\",\n \"title\",\n \"description\",\n \"examples\",\n \"hidden\",\n \"ignore\",\n \"internal\",\n \"runtime\",\n \"readOnly\",\n \"writeOnly\",\n \"alias\",\n \"tags\"\n] satisfies ReadonlyArray<keyof SchemaMetadata>;\n"],"mappings":";AAoBA,MAAa,kBAAkB;CAC7B,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,SAAS;CACT,MAAM;CACN,QAAQ;CACR,OAAO;AACT;AAEA,MAAa,yBAAyB;CACpC,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;AAClB;AAEA,MAAa,4BAA4B;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
package/dist/extract.cjs CHANGED
@@ -1,4 +1,3 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
1
  const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
2
  const require_type_checks = require('./type-checks.cjs');
4
3
  const require_persistence = require('./persistence.cjs');
@@ -15,6 +14,7 @@ let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type")
15
14
  let _stryke_hash = require("@stryke/hash");
16
15
  let _stryke_path_join = require("@stryke/path/join");
17
16
  let _stryke_zod = require("@stryke/zod");
17
+ let _valibot_to_json_schema = require("@valibot/to-json-schema");
18
18
 
19
19
  //#region src/extract.ts
20
20
  function convertNestedUntypedSchema(value) {
@@ -30,6 +30,9 @@ function convertNestedUntypedSchemaArray(value) {
30
30
  if (!Array.isArray(value)) return value;
31
31
  return value.map((item) => convertNestedUntypedSchema(item));
32
32
  }
33
+ function convertValibotSchemaToJsonSchema(schema) {
34
+ return (0, _valibot_to_json_schema.toJsonSchema)(schema, { target: "draft-07" });
35
+ }
33
36
  function convertUntypedSchemaToJsonSchema(schema) {
34
37
  const source = schema;
35
38
  const jsonSchema = {};
@@ -109,6 +112,10 @@ function extractHash(variant, input) {
109
112
  variant,
110
113
  input
111
114
  });
115
+ else if (require_type_checks.isValibotSchema(input)) return (0, _stryke_hash.murmurhash)({
116
+ variant,
117
+ input: convertValibotSchemaToJsonSchema(input)
118
+ });
112
119
  else if (require_type_checks.isUntypedInput(input)) return (0, _stryke_hash.murmurhash)({
113
120
  variant,
114
121
  input: convertUntypedInputToJsonSchema(input)
@@ -122,7 +129,7 @@ function extractHash(variant, input) {
122
129
  input: (0, _powerlines_deepkit_vendor_type.stringifyType)(input)
123
130
  });
124
131
  }
125
- throw new Error(`Failed to create an input hash for the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object.`);
132
+ throw new Error(`Failed to create an input hash for the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, or a reflected Deepkit Type object.`);
126
133
  }
127
134
  /**
128
135
  * Converts a reflected Deepkit {@link Type} into a JSON Schema (draft-07) representation.
@@ -132,25 +139,28 @@ function extractReflection(reflection) {
132
139
  return require_reflection.reflectionToJsonSchema(reflection);
133
140
  }
134
141
  /**
135
- * Extracts a JSON Schema from Zod, Standard Schema, untyped, or JSON Schema inputs.
142
+ * Extracts a JSON Schema from Zod, Standard Schema, Valibot, untyped, or JSON Schema inputs.
136
143
  */
137
144
  function extractJsonSchema(schema) {
138
- if ((0, _stryke_type_checks_is_set_object.isSetObject)(schema) && ((0, _stryke_zod.isZod3Type)(schema) || (0, _stryke_json.isStandardJsonSchema)(schema) || require_type_checks.isUntypedInput(schema) || require_type_checks.isUntypedSchema(schema))) {
145
+ if ((0, _stryke_type_checks_is_set_object.isSetObject)(schema)) {
139
146
  if ((0, _stryke_zod.isZod3Type)(schema)) return (0, _stryke_zod.extractJsonSchema)(schema);
140
147
  if ((0, _stryke_json.isStandardJsonSchema)(schema)) return schema["~standard"].jsonSchema.input({ target: "draft-2020-12" });
148
+ if (require_type_checks.isValibotSchema(schema)) return convertValibotSchemaToJsonSchema(schema);
141
149
  if (require_type_checks.isUntypedInput(schema)) return convertUntypedInputToJsonSchema(schema);
142
150
  if (require_type_checks.isUntypedSchema(schema)) return convertUntypedSchemaToJsonSchema(schema);
143
- } else if (require_type_checks.isJsonSchema(schema)) return schema;
151
+ if (require_type_checks.isJsonSchema(schema)) return schema;
152
+ }
144
153
  }
145
154
  function extractResolvedVariant(input) {
146
155
  if ((0, _stryke_type_checks_is_set_object.isSetObject)(input)) {
147
156
  if ((0, _stryke_zod.isZod3Type)(input)) return "zod3";
148
157
  else if ((0, _stryke_json.isStandardJsonSchema)(input)) return "standard-schema";
149
158
  else if (require_type_checks.isJsonSchema(input)) return "json-schema";
159
+ else if (require_type_checks.isValibotSchema(input)) return "valibot";
150
160
  else if ((0, _powerlines_deepkit_vendor_type.isType)(input)) return "reflection";
151
161
  else if (require_type_checks.isUntypedInput(input) || require_type_checks.isUntypedSchema(input)) return "untyped";
152
162
  }
153
- throw new Error(`Failed to determine the variant of the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a reflected Deepkit Type object, or an Untyped schema.`);
163
+ throw new Error(`Failed to determine the variant of the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, a reflected Deepkit Type object, or an Untyped schema.`);
154
164
  }
155
165
  function extractVariant(input) {
156
166
  if ((0, _stryke_type_checks.isSetString)(input) || (0, _powerlines_core.isTypeDefinition)(input)) return "type-definition";
@@ -160,10 +170,10 @@ async function extractSchemaSchema(input, variant) {
160
170
  if (require_type_checks.isExtractedSchema(input)) return input.schema;
161
171
  const resolvedVariant = variant ?? extractResolvedVariant(input);
162
172
  let schema;
163
- if (resolvedVariant === "zod3" || resolvedVariant === "json-schema" || resolvedVariant === "standard-schema" || resolvedVariant === "untyped") schema = extractJsonSchema(input);
173
+ if (resolvedVariant === "zod3" || resolvedVariant === "json-schema" || resolvedVariant === "standard-schema" || resolvedVariant === "untyped" || resolvedVariant === "valibot") schema = extractJsonSchema(input);
164
174
  else if (resolvedVariant === "reflection") schema = extractReflection(input);
165
175
  if (schema) return schema;
166
- throw new Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`);
176
+ throw new Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, an untyped schema, or a reflected Deepkit Type object.`);
167
177
  }
168
178
  function extractSource(variant, input) {
169
179
  if (variant === "zod3") return {
@@ -186,6 +196,11 @@ function extractSource(variant, input) {
186
196
  variant: "json-schema",
187
197
  schema: input
188
198
  };
199
+ else if (variant === "valibot") return {
200
+ hash: extractHash(variant, input),
201
+ variant: "valibot",
202
+ schema: input
203
+ };
189
204
  else if (variant === "reflection") return {
190
205
  hash: extractHash(variant, input),
191
206
  variant: "reflection",
@@ -309,6 +324,5 @@ exports.extractJsonSchema = extractJsonSchema;
309
324
  exports.extractReflection = extractReflection;
310
325
  exports.extractResolvedVariant = extractResolvedVariant;
311
326
  exports.extractSchema = extractSchema;
312
- exports.extractSchemaSchema = extractSchemaSchema;
313
327
  exports.extractSource = extractSource;
314
328
  exports.extractVariant = extractVariant;
@@ -13,12 +13,11 @@ declare function extractHash<T = unknown>(variant: SchemaInputVariant, input: Sc
13
13
  */
14
14
  declare function extractReflection<T = unknown>(reflection: Type): JsonSchema<T> | undefined;
15
15
  /**
16
- * Extracts a JSON Schema from Zod, Standard Schema, untyped, or JSON Schema inputs.
16
+ * Extracts a JSON Schema from Zod, Standard Schema, Valibot, untyped, or JSON Schema inputs.
17
17
  */
18
18
  declare function extractJsonSchema<T = unknown>(schema: unknown): JsonSchema<T> | undefined;
19
19
  declare function extractResolvedVariant(input: SchemaSourceInput): SchemaSourceVariant;
20
20
  declare function extractVariant<T = unknown>(input: SchemaInput<T>): SchemaInputVariant;
21
- declare function extractSchemaSchema<T = unknown>(input: SchemaSourceInput, variant?: SchemaInputVariant): Promise<JsonSchema<T>>;
22
21
  declare function extractSource(variant: SchemaSourceVariant, input: SchemaSourceInput): SchemaSource;
23
22
  /**
24
23
  * Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object. If the input is a type definition reference (e.g. a file path with an export), it will be resolved and bundled using ESBuild to obtain the actual schema definition before extraction.
@@ -78,5 +77,5 @@ declare function extractSchema<T = unknown>(context: Context, input: SchemaInput
78
77
  */
79
78
  declare function extract<T = unknown>(context: Context, input: SchemaInput, options?: Partial<BuildOptions>): Promise<Schema<T>>;
80
79
  //#endregion
81
- export { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaSchema, extractSource, extractVariant };
80
+ export { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSource, extractVariant };
82
81
  //# sourceMappingURL=extract.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract.d.cts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;;;;AA0NA;iBAAgB,WAAA,aAAA,CACd,OAAA,EAAS,kBAAA,EACT,KAAA,EAAO,WAAA,CAAY,CAAA;;;;iBAkCL,iBAAA,aAAA,CACd,UAAA,EAAY,IAAA,GACX,UAAA,CAAW,CAAA;;;;iBAWE,iBAAA,aAAA,CACd,MAAA,YACC,UAAU,CAAC,CAAA;AAAA,i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AAtJoB;AAuCvB;;;;;;;;;;;;;;AAEe;AAWf;;;;;;;;iBAwKsB,aAAA,aAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,OAAA,CAAQ,YAAA,IAChB,OAAA,CAAQ,eAAA,CAAgB,CAAA;AA1KZ;AA2Bf;;;;;;;;AAEsB;AAsBtB;;;;;;;;;;;;;;AAEqB;AAwCrB;;;;AA7Fe,iBAqQO,OAAA,aAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,OAAA,CAAQ,YAAA,IAChB,OAAA,CAAQ,MAAA,CAAO,CAAA"}
@@ -13,12 +13,11 @@ declare function extractHash<T = unknown>(variant: SchemaInputVariant, input: Sc
13
13
  */
14
14
  declare function extractReflection<T = unknown>(reflection: Type): JsonSchema<T> | undefined;
15
15
  /**
16
- * Extracts a JSON Schema from Zod, Standard Schema, untyped, or JSON Schema inputs.
16
+ * Extracts a JSON Schema from Zod, Standard Schema, Valibot, untyped, or JSON Schema inputs.
17
17
  */
18
18
  declare function extractJsonSchema<T = unknown>(schema: unknown): JsonSchema<T> | undefined;
19
19
  declare function extractResolvedVariant(input: SchemaSourceInput): SchemaSourceVariant;
20
20
  declare function extractVariant<T = unknown>(input: SchemaInput<T>): SchemaInputVariant;
21
- declare function extractSchemaSchema<T = unknown>(input: SchemaSourceInput, variant?: SchemaInputVariant): Promise<JsonSchema<T>>;
22
21
  declare function extractSource(variant: SchemaSourceVariant, input: SchemaSourceInput): SchemaSource;
23
22
  /**
24
23
  * Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object. If the input is a type definition reference (e.g. a file path with an export), it will be resolved and bundled using ESBuild to obtain the actual schema definition before extraction.
@@ -78,5 +77,5 @@ declare function extractSchema<T = unknown>(context: Context, input: SchemaInput
78
77
  */
79
78
  declare function extract<T = unknown>(context: Context, input: SchemaInput, options?: Partial<BuildOptions>): Promise<Schema<T>>;
80
79
  //#endregion
81
- export { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaSchema, extractSource, extractVariant };
80
+ export { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSource, extractVariant };
82
81
  //# sourceMappingURL=extract.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract.d.mts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;;;;AA0NA;iBAAgB,WAAA,aAAA,CACd,OAAA,EAAS,kBAAA,EACT,KAAA,EAAO,WAAA,CAAY,CAAA;;;;iBAkCL,iBAAA,aAAA,CACd,UAAA,EAAY,IAAA,GACX,UAAA,CAAW,CAAA;;;;iBAWE,iBAAA,aAAA,CACd,MAAA,YACC,UAAU,CAAC,CAAA;AAAA,iBA6BE,sBAAA,CACd,KAAA,EAAO,iBAAA,GACN,mBAAmB;AAAA,iBAoBN,cAAA,aAAA,CACd,KAAA,EAAO,WAAA,CAAY,CAAA,IAClB,kBAAA;AAAA,iBAQmB,mBAAA,aAAA,CACpB,KAAA,EAAO,iBAAA,EACP,OAAA,GAAU,kBAAA,GACT,OAAA,CAAQ,UAAA,CAAW,CAAA;AAAA,iBA4BN,aAAA,CACd,OAAA,EAAS,mBAAA,EACT,KAAA,EAAO,iBAAA,GACN,YAAA;;AAhJoB;AAkCvB;;;;;;;;;;;;;;AAEe;AAWf;;;;;;;;;iBAiKsB,aAAA,aAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,OAAA,CAAQ,YAAA,IAChB,OAAA,CAAQ,eAAA,CAAgB,CAAA;AAtI3B;;;;;;;;AAEsB;AAoBtB;;;;;;;;;;;;;;AAEqB;AAQrB;;;;;AAhCA,iBAiOsB,OAAA,aAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,OAAA,CAAQ,YAAA,IAChB,OAAA,CAAQ,MAAA,CAAO,CAAA"}
1
+ {"version":3,"file":"extract.d.mts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;;;;AAqOA;iBAAgB,WAAA,aAAA,CACd,OAAA,EAAS,kBAAA,EACT,KAAA,EAAO,WAAA,CAAY,CAAA;;;;iBAuCL,iBAAA,aAAA,CACd,UAAA,EAAY,IAAA,GACX,UAAA,CAAW,CAAA;;;;iBAWE,iBAAA,aAAA,CACd,MAAA,YACC,UAAU,CAAC,CAAA;AAAA,iBA2BE,sBAAA,CACd,KAAA,EAAO,iBAAA,GACN,mBAAmB;AAAA,iBAsBN,cAAA,aAAA,CACd,KAAA,EAAO,WAAA,CAAY,CAAA,IAClB,kBAAA;AAAA,iBAwCa,aAAA,CACd,OAAA,EAAS,mBAAA,EACT,KAAA,EAAO,iBAAA,GACN,YAAA;;;AAtJoB;AAuCvB;;;;;;;;;;;;;;AAEe;AAWf;;;;;;;;iBAwKsB,aAAA,aAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,OAAA,CAAQ,YAAA,IAChB,OAAA,CAAQ,eAAA,CAAgB,CAAA;AA1KZ;AA2Bf;;;;;;;;AAEsB;AAsBtB;;;;;;;;;;;;;;AAEqB;AAwCrB;;;;AA7Fe,iBAqQO,OAAA,aAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,OAAA,CAAQ,YAAA,IAChB,OAAA,CAAQ,MAAA,CAAO,CAAA"}
package/dist/extract.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { isExtractedSchema, isJsonSchema, isJsonSchemaObject, isSchema, isUntypedInput, isUntypedSchema } from "./type-checks.mjs";
1
+ import { isExtractedSchema, isJsonSchema, isJsonSchemaObject, isSchema, isUntypedInput, isUntypedSchema, isValibotSchema } from "./type-checks.mjs";
2
2
  import { getCacheDirectory, writeSchema } from "./persistence.mjs";
3
3
  import { reflectionToJsonSchema } from "./reflection.mjs";
4
4
  import { resolve } from "./resolve.mjs";
@@ -11,7 +11,8 @@ import { rolldownPlugin } from "@powerlines/deepkit/rolldown-plugin";
11
11
  import { isType, stringifyType } from "@powerlines/deepkit/vendor/type";
12
12
  import { murmurhash } from "@stryke/hash";
13
13
  import { joinPaths } from "@stryke/path/join";
14
- import { extractJsonSchema as extractJsonSchema$1, isZod3Type } from "@stryke/zod";
14
+ import { extractJsonSchema, isZod3Type } from "@stryke/zod";
15
+ import { toJsonSchema } from "@valibot/to-json-schema";
15
16
 
16
17
  //#region src/extract.ts
17
18
  function convertNestedUntypedSchema(value) {
@@ -27,6 +28,9 @@ function convertNestedUntypedSchemaArray(value) {
27
28
  if (!Array.isArray(value)) return value;
28
29
  return value.map((item) => convertNestedUntypedSchema(item));
29
30
  }
31
+ function convertValibotSchemaToJsonSchema(schema) {
32
+ return toJsonSchema(schema, { target: "draft-07" });
33
+ }
30
34
  function convertUntypedSchemaToJsonSchema(schema) {
31
35
  const source = schema;
32
36
  const jsonSchema = {};
@@ -106,6 +110,10 @@ function extractHash(variant, input) {
106
110
  variant,
107
111
  input
108
112
  });
113
+ else if (isValibotSchema(input)) return murmurhash({
114
+ variant,
115
+ input: convertValibotSchemaToJsonSchema(input)
116
+ });
109
117
  else if (isUntypedInput(input)) return murmurhash({
110
118
  variant,
111
119
  input: convertUntypedInputToJsonSchema(input)
@@ -119,7 +127,7 @@ function extractHash(variant, input) {
119
127
  input: stringifyType(input)
120
128
  });
121
129
  }
122
- throw new Error(`Failed to create an input hash for the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object.`);
130
+ throw new Error(`Failed to create an input hash for the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, or a reflected Deepkit Type object.`);
123
131
  }
124
132
  /**
125
133
  * Converts a reflected Deepkit {@link Type} into a JSON Schema (draft-07) representation.
@@ -129,25 +137,28 @@ function extractReflection(reflection) {
129
137
  return reflectionToJsonSchema(reflection);
130
138
  }
131
139
  /**
132
- * Extracts a JSON Schema from Zod, Standard Schema, untyped, or JSON Schema inputs.
140
+ * Extracts a JSON Schema from Zod, Standard Schema, Valibot, untyped, or JSON Schema inputs.
133
141
  */
134
- function extractJsonSchema(schema) {
135
- if (isSetObject$1(schema) && (isZod3Type(schema) || isStandardJsonSchema(schema) || isUntypedInput(schema) || isUntypedSchema(schema))) {
136
- if (isZod3Type(schema)) return extractJsonSchema$1(schema);
142
+ function extractJsonSchema$1(schema) {
143
+ if (isSetObject$1(schema)) {
144
+ if (isZod3Type(schema)) return extractJsonSchema(schema);
137
145
  if (isStandardJsonSchema(schema)) return schema["~standard"].jsonSchema.input({ target: "draft-2020-12" });
146
+ if (isValibotSchema(schema)) return convertValibotSchemaToJsonSchema(schema);
138
147
  if (isUntypedInput(schema)) return convertUntypedInputToJsonSchema(schema);
139
148
  if (isUntypedSchema(schema)) return convertUntypedSchemaToJsonSchema(schema);
140
- } else if (isJsonSchema(schema)) return schema;
149
+ if (isJsonSchema(schema)) return schema;
150
+ }
141
151
  }
142
152
  function extractResolvedVariant(input) {
143
153
  if (isSetObject$1(input)) {
144
154
  if (isZod3Type(input)) return "zod3";
145
155
  else if (isStandardJsonSchema(input)) return "standard-schema";
146
156
  else if (isJsonSchema(input)) return "json-schema";
157
+ else if (isValibotSchema(input)) return "valibot";
147
158
  else if (isType(input)) return "reflection";
148
159
  else if (isUntypedInput(input) || isUntypedSchema(input)) return "untyped";
149
160
  }
150
- throw new Error(`Failed to determine the variant of the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a reflected Deepkit Type object, or an Untyped schema.`);
161
+ throw new Error(`Failed to determine the variant of the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, a reflected Deepkit Type object, or an Untyped schema.`);
151
162
  }
152
163
  function extractVariant(input) {
153
164
  if (isSetString(input) || isTypeDefinition(input)) return "type-definition";
@@ -157,10 +168,10 @@ async function extractSchemaSchema(input, variant) {
157
168
  if (isExtractedSchema(input)) return input.schema;
158
169
  const resolvedVariant = variant ?? extractResolvedVariant(input);
159
170
  let schema;
160
- if (resolvedVariant === "zod3" || resolvedVariant === "json-schema" || resolvedVariant === "standard-schema" || resolvedVariant === "untyped") schema = extractJsonSchema(input);
171
+ if (resolvedVariant === "zod3" || resolvedVariant === "json-schema" || resolvedVariant === "standard-schema" || resolvedVariant === "untyped" || resolvedVariant === "valibot") schema = extractJsonSchema$1(input);
161
172
  else if (resolvedVariant === "reflection") schema = extractReflection(input);
162
173
  if (schema) return schema;
163
- throw new Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`);
174
+ throw new Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, an untyped schema, or a reflected Deepkit Type object.`);
164
175
  }
165
176
  function extractSource(variant, input) {
166
177
  if (variant === "zod3") return {
@@ -183,6 +194,11 @@ function extractSource(variant, input) {
183
194
  variant: "json-schema",
184
195
  schema: input
185
196
  };
197
+ else if (variant === "valibot") return {
198
+ hash: extractHash(variant, input),
199
+ variant: "valibot",
200
+ schema: input
201
+ };
186
202
  else if (variant === "reflection") return {
187
203
  hash: extractHash(variant, input),
188
204
  variant: "reflection",
@@ -300,5 +316,5 @@ async function extract(context, input, options = {}) {
300
316
  }
301
317
 
302
318
  //#endregion
303
- export { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaSchema, extractSource, extractVariant };
319
+ export { extract, extractHash, extractJsonSchema$1 as extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSource, extractVariant };
304
320
  //# sourceMappingURL=extract.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract.mjs","names":["isSetObject","extractJsonSchemaZod"],"sources":["../src/extract.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { Context } from \"@powerlines/core\";\nimport { isTypeDefinition } from \"@powerlines/core\";\nimport { rolldownPlugin } from \"@powerlines/deepkit/rolldown-plugin\";\nimport { isType, stringifyType, Type } from \"@powerlines/deepkit/vendor/type\";\nimport { StandardJSONSchemaV1 } from \"@standard-schema/spec\";\nimport { murmurhash } from \"@stryke/hash\";\nimport { isStandardJsonSchema } from \"@stryke/json\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { isSetString } from \"@stryke/type-checks\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport {\n extractJsonSchema as extractJsonSchemaZod,\n isZod3Type\n} from \"@stryke/zod\";\nimport defu from \"defu\";\nimport type { BuildOptions } from \"rolldown\";\nimport * as z3 from \"zod/v3\";\nimport { getCacheDirectory, writeSchema } from \"./persistence\";\nimport { reflectionToJsonSchema } from \"./reflection\";\nimport { resolve } from \"./resolve\";\nimport {\n isExtractedSchema,\n isJsonSchema,\n isJsonSchemaObject,\n isSchema,\n isUntypedInput,\n isUntypedSchema\n} from \"./type-checks\";\nimport {\n ExtractedSchema,\n JsonSchema,\n Schema,\n SchemaInput,\n SchemaInputVariant,\n SchemaSource,\n SchemaSourceInput,\n SchemaSourceVariant,\n TypeDefinitionReference,\n UntypedInputObject,\n UntypedSchema\n} from \"./types\";\n\nfunction convertNestedUntypedSchema(value: unknown): unknown {\n if (isUntypedSchema(value)) {\n return convertUntypedSchemaToJsonSchema(value);\n }\n\n if (isSetObject(value)) {\n if (isUntypedInput(value)) {\n return convertUntypedInputToJsonSchema(value);\n }\n\n const nested = value as Record<string, unknown>;\n if (\"$schema\" in nested && isUntypedSchema(nested.$schema)) {\n return convertUntypedSchemaToJsonSchema(nested.$schema);\n }\n }\n\n return value;\n}\n\nfunction convertNestedUntypedSchemaArray(value: unknown): unknown {\n if (!Array.isArray(value)) {\n return value;\n }\n\n return value.map(item => convertNestedUntypedSchema(item));\n}\n\nfunction convertUntypedSchemaToJsonSchema<T = unknown>(\n schema: UntypedSchema | Record<string, unknown>\n): JsonSchema<T> {\n const source = schema as Record<string, unknown>;\n const jsonSchema: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(source)) {\n if (\n key === \"tsType\" ||\n key === \"markdownType\" ||\n key === \"tags\" ||\n key === \"args\" ||\n key === \"resolve\"\n ) {\n continue;\n }\n\n if (key === \"id\" && isSetString(value)) {\n jsonSchema.$id = value;\n continue;\n }\n\n if (\n key === \"properties\" ||\n key === \"patternProperties\" ||\n key === \"dependentSchemas\" ||\n key === \"$defs\" ||\n key === \"definitions\"\n ) {\n if (!isSetObject(value)) {\n jsonSchema[key] = value;\n continue;\n }\n\n jsonSchema[key] = Object.fromEntries(\n Object.entries(value).map(([propertyKey, propertyValue]) => [\n propertyKey,\n convertNestedUntypedSchema(propertyValue)\n ])\n );\n continue;\n }\n\n if (\n key === \"items\" ||\n key === \"contains\" ||\n key === \"if\" ||\n key === \"then\" ||\n key === \"else\" ||\n key === \"not\" ||\n key === \"propertyNames\" ||\n key === \"additionalProperties\" ||\n key === \"unevaluatedProperties\"\n ) {\n jsonSchema[key] = convertNestedUntypedSchema(value);\n continue;\n }\n\n if (key === \"oneOf\" || key === \"anyOf\" || key === \"allOf\") {\n jsonSchema[key] = convertNestedUntypedSchemaArray(value);\n continue;\n }\n\n jsonSchema[key] = value;\n }\n\n return jsonSchema as JsonSchema<T>;\n}\n\nfunction convertUntypedInputToJsonSchema<T = unknown>(\n input: UntypedInputObject\n): JsonSchema<T> {\n const inputObject = input as Record<string, unknown>;\n const base = (\n isUntypedSchema(inputObject.$schema)\n ? convertUntypedSchemaToJsonSchema<T>(inputObject.$schema)\n : {}\n ) as JsonSchema<T>;\n const properties: Record<string, JsonSchema<T>> = {};\n\n for (const [key, value] of Object.entries(inputObject)) {\n if (key.startsWith(\"$\")) {\n continue;\n }\n\n if (!isSetObject(value)) {\n continue;\n }\n\n if (isUntypedInput(value)) {\n properties[key] = convertUntypedInputToJsonSchema<T>(value);\n continue;\n }\n\n const nested = value as Record<string, unknown>;\n if (\"$schema\" in nested && isUntypedSchema(nested.$schema)) {\n properties[key] = convertUntypedSchemaToJsonSchema<T>(nested.$schema);\n continue;\n }\n\n if (isUntypedSchema(value)) {\n properties[key] = convertUntypedSchemaToJsonSchema<T>(value);\n }\n }\n\n if (!isJsonSchemaObject(base)) {\n throw new Error(\n `Failed to convert untyped input to JSON Schema. The base schema must be a valid JSON Schema object.`\n );\n }\n\n const baseProperties = isSetObject(base.properties)\n ? (base.properties as Record<string, JsonSchema<T>>)\n : {};\n const mergedProperties = {\n ...baseProperties,\n ...properties\n };\n\n return {\n ...base,\n type: base.type ?? \"object\",\n ...(Object.keys(mergedProperties).length > 0\n ? { properties: mergedProperties }\n : {})\n };\n}\n\n/**\n * Creates a hash string for a given schema definition input.\n */\nexport function extractHash<T = unknown>(\n variant: SchemaInputVariant,\n input: SchemaInput<T>\n): string {\n if (isSetString(input)) {\n return murmurhash({ variant, input });\n } else if (isSetObject(input)) {\n if (isZod3Type(input)) {\n return murmurhash({ variant, input: input._def });\n } else if (isStandardJsonSchema(input)) {\n return murmurhash({ variant, input: input[\"~standard\"] });\n } else if (isJsonSchema(input)) {\n return murmurhash({ variant, input });\n } else if (isUntypedInput(input)) {\n return murmurhash({\n variant,\n input: convertUntypedInputToJsonSchema(input)\n });\n } else if (isUntypedSchema(input)) {\n return murmurhash({\n variant,\n input: convertUntypedSchemaToJsonSchema(input)\n });\n } else if (isType(input)) {\n return murmurhash({ variant, input: stringifyType(input) });\n }\n }\n\n throw new Error(\n `Failed to create an input hash for the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Converts a reflected Deepkit {@link Type} into a JSON Schema (draft-07) representation.\n */\nexport function extractReflection<T = unknown>(\n reflection: Type\n): JsonSchema<T> | undefined {\n if (!isType(reflection)) {\n return undefined;\n }\n\n return reflectionToJsonSchema<T>(reflection);\n}\n\n/**\n * Extracts a JSON Schema from Zod, Standard Schema, untyped, or JSON Schema inputs.\n */\nexport function extractJsonSchema<T = unknown>(\n schema: unknown\n): JsonSchema<T> | undefined {\n if (\n isSetObject(schema) &&\n (isZod3Type(schema) ||\n isStandardJsonSchema(schema) ||\n isUntypedInput(schema) ||\n isUntypedSchema(schema))\n ) {\n if (isZod3Type(schema)) {\n return extractJsonSchemaZod(schema) as JsonSchema<T>;\n }\n if (isStandardJsonSchema(schema)) {\n return schema[\"~standard\"].jsonSchema.input({\n target: \"draft-2020-12\"\n }) as JsonSchema<T>;\n }\n if (isUntypedInput(schema)) {\n return convertUntypedInputToJsonSchema<T>(schema);\n }\n if (isUntypedSchema(schema)) {\n return convertUntypedSchemaToJsonSchema<T>(schema);\n }\n } else if (isJsonSchema<T>(schema)) {\n return schema;\n }\n\n return undefined;\n}\n\nexport function extractResolvedVariant(\n input: SchemaSourceInput\n): SchemaSourceVariant {\n if (isSetObject(input)) {\n if (isZod3Type(input)) {\n return \"zod3\";\n } else if (isStandardJsonSchema(input)) {\n return \"standard-schema\";\n } else if (isJsonSchema(input)) {\n return \"json-schema\";\n } else if (isType(input)) {\n return \"reflection\";\n } else if (isUntypedInput(input) || isUntypedSchema(input)) {\n return \"untyped\";\n }\n }\n\n throw new Error(\n `Failed to determine the variant of the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a reflected Deepkit Type object, or an Untyped schema.`\n );\n}\n\nexport function extractVariant<T = unknown>(\n input: SchemaInput<T>\n): SchemaInputVariant {\n if (isSetString(input) || isTypeDefinition(input)) {\n return \"type-definition\";\n }\n\n return extractResolvedVariant(input as SchemaSourceInput);\n}\n\nexport async function extractSchemaSchema<T = unknown>(\n input: SchemaSourceInput,\n variant?: SchemaInputVariant\n): Promise<JsonSchema<T>> {\n if (isExtractedSchema<T>(input)) {\n return input.schema;\n }\n\n const resolvedVariant = variant ?? extractResolvedVariant(input);\n\n let schema: JsonSchema<T> | undefined;\n if (\n resolvedVariant === \"zod3\" ||\n resolvedVariant === \"json-schema\" ||\n resolvedVariant === \"standard-schema\" ||\n resolvedVariant === \"untyped\"\n ) {\n schema = extractJsonSchema<T>(input);\n } else if (resolvedVariant === \"reflection\") {\n schema = extractReflection(input as Type);\n }\n\n if (schema) {\n return schema;\n }\n\n throw new Error(\n `Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`\n );\n}\n\nexport function extractSource(\n variant: SchemaSourceVariant,\n input: SchemaSourceInput\n): SchemaSource {\n if (variant === \"zod3\") {\n return {\n hash: extractHash(variant, input),\n variant: \"zod3\",\n schema: input as z3.ZodTypeAny\n };\n } else if (variant === \"untyped\") {\n return {\n hash: extractHash(variant, input),\n variant: \"untyped\",\n schema: input as UntypedInputObject | UntypedSchema\n };\n } else if (variant === \"standard-schema\") {\n return {\n hash: extractHash(variant, input),\n variant: \"standard-schema\",\n schema: input as StandardJSONSchemaV1\n };\n } else if (variant === \"json-schema\") {\n return {\n hash: extractHash(variant, input),\n variant: \"json-schema\",\n schema: input as JsonSchema\n };\n } else if (variant === \"reflection\") {\n return {\n hash: extractHash(variant, input),\n variant: \"reflection\",\n schema: input as Type\n };\n }\n\n throw new Error(\n `Failed to extract source information from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object. If the input is a type definition reference (e.g. a file path with an export), it will be resolved and bundled using ESBuild to obtain the actual schema definition before extraction.\n *\n * @example\n * ```ts\n * // Resolve a schema definition from a file path\n * const schema1 = await extract(context, \"./schemas.ts#MySchema\");\n * // Resolve a schema definition from a JSON Schema object\n * const schema2 = await extract(context, schemaObject);\n * // Resolve a schema definition from a Zod schema\n * const schema3 = await extract(context, zodSchema);\n * // Resolve a schema definition from a reflected Deepkit Type object\n * const schema4 = await extract(context, reflectionType);\n * ```\n *\n * @see https://github.com/colinhacks/zod\n * @see https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec\n * @see https://json-schema.org/\n * @see https://ajv.js.org/json-type-definition.html\n * @see https://deepkit.io/en/documentation/runtime-types/reflection\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param input - The schema definition input to extract, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object. If the input is a string or a type definition reference, it will be resolved and bundled to obtain the actual schema definition before extraction.\n * @param options - Optional overrides for the ESBuild configuration used during extraction. This can include custom plugins, loaders, or other build options to control how the schema definition is resolved and bundled when the input is a type definition reference.\n * @returns A promise that resolves to the extracted and normalized schema as a JSON Schema object. The function will attempt to extract a valid JSON Schema from the provided input, and if successful, it will return the schema. If the extraction process fails or if the input is not a valid schema definition, it will throw an error indicating the failure.\n */\nexport async function extractSchema<T = unknown>(\n context: Context,\n input: SchemaInput,\n options: Partial<BuildOptions> = {}\n): Promise<ExtractedSchema<T>> {\n if (isExtractedSchema<T>(input)) {\n return input;\n }\n\n if (isSchema<T>(input)) {\n return {\n ...input,\n source: {\n hash: extractHash(\"json-schema\", input.schema),\n variant: \"json-schema\",\n schema: input.schema\n }\n };\n }\n\n let source: SchemaSource;\n\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n\n if (variant === \"type-definition\") {\n const resolved = await resolve<SchemaSourceInput>(\n context,\n input as TypeDefinitionReference,\n defu(options, {\n plugins: [\n rolldownPlugin(context, {\n reflection: \"default\",\n level: \"all\"\n })\n ]\n })\n );\n\n source = extractSource(extractResolvedVariant(resolved), resolved);\n } else if (\n [\n \"json-schema\",\n \"standard-schema\",\n \"zod3\",\n \"untyped\",\n \"reflection\"\n ].includes(variant)\n ) {\n source = extractSource(variant, input as SchemaSourceInput);\n } else {\n throw new Error(\n `Invalid schema definition input \"${\n variant\n }\". The variant must be one of \"type-definition\", \"json-schema\", \"standard-schema\", \"zod3\", \"untyped\", or \"reflection\".`\n );\n }\n\n return {\n variant,\n source,\n schema: await extractSchemaSchema<T>(source.schema, source.variant),\n hash\n };\n}\n\n/**\n * Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object. If the input is a type definition reference (e.g. a file path with an export), it will be resolved and bundled using ESBuild to obtain the actual schema definition before extraction.\n *\n * @example\n * ```ts\n * // Resolve a schema definition from a file path\n * const schema1 = await extract(context, \"./schemas.ts#MySchema\");\n * // Resolve a schema definition from a JSON Schema object\n * const schema2 = await extract(context, schemaObject);\n * // Resolve a schema definition from a Zod schema\n * const schema3 = await extract(context, zodSchema);\n * // Resolve a schema definition from a reflected Deepkit Type object\n * const schema4 = await extract(context, reflectionType);\n * ```\n *\n * @see https://github.com/colinhacks/zod\n * @see https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec\n * @see https://json-schema.org/\n * @see https://ajv.js.org/json-type-definition.html\n * @see https://deepkit.io/en/documentation/runtime-types/reflection\n * @see https://github.com/unjs/untyped\n * @see https://www.typescriptlang.org/docs/handbook/2/types-from-types.html\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param input - The schema definition input to extract, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.\n * @param options - Optional overrides for the ESBuild configuration used during extraction.\n * @returns A promise that resolves to the extracted and normalized schema as a JSON Schema object.\n * @throws Will throw an error if the input is not a valid schema definition or if the extraction process fails to produce a valid schema.\n */\nexport async function extract<T = unknown>(\n context: Context,\n input: SchemaInput,\n options: Partial<BuildOptions> = {}\n): Promise<Schema<T>> {\n if (isExtractedSchema<T>(input) || isSchema<T>(input)) {\n return input;\n }\n\n let result: Schema<T> | undefined;\n\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n\n const cacheFilePath = joinPaths(getCacheDirectory(context), `${hash}.json`);\n if (\n context.config.skipCache !== true &&\n context.fs.existsSync(cacheFilePath)\n ) {\n const schema = await context.fs.read(cacheFilePath);\n if (schema) {\n result = {\n variant,\n hash,\n schema: JSON.parse(schema) as JsonSchema<T>\n };\n }\n }\n\n result ??= await extractSchema<T>(context, input, options);\n if (!result?.schema) {\n throw new Error(\n `Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`\n );\n }\n\n if (context.config.skipCache !== true) {\n await writeSchema(context, result);\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA4DA,SAAS,2BAA2B,OAAyB;CAC3D,IAAI,gBAAgB,KAAK,GACvB,OAAO,iCAAiC,KAAK;CAG/C,IAAIA,cAAY,KAAK,GAAG;EACtB,IAAI,eAAe,KAAK,GACtB,OAAO,gCAAgC,KAAK;EAG9C,MAAM,SAAS;EACf,IAAI,aAAa,UAAU,gBAAgB,OAAO,OAAO,GACvD,OAAO,iCAAiC,OAAO,OAAO;CAE1D;CAEA,OAAO;AACT;AAEA,SAAS,gCAAgC,OAAyB;CAChE,IAAI,CAAC,MAAM,QAAQ,KAAK,GACtB,OAAO;CAGT,OAAO,MAAM,KAAI,SAAQ,2BAA2B,IAAI,CAAC;AAC3D;AAEA,SAAS,iCACP,QACe;CACf,MAAM,SAAS;CACf,MAAM,aAAsC,CAAC;CAE7C,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,GAAG;EACjD,IACE,QAAQ,YACR,QAAQ,kBACR,QAAQ,UACR,QAAQ,UACR,QAAQ,WAER;EAGF,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,GAAG,GAAG,KAAK,MAAM;CAC1E,IACE,QAAQ,OAAO,cAAc,QAC7B,QAAQ,GAAG,WAAW,aAAa,GACnC;EACA,MAAM,SAAS,MAAM,QAAQ,GAAG,KAAK,aAAa;EAClD,IAAI,QACF,SAAS;GACP;GACA;GACA,QAAQ,KAAK,MAAM,MAAM;EAC3B;CAEJ;CAEA,WAAW,MAAM,cAAiB,SAAS,OAAO,OAAO;CACzD,IAAI,CAAC,QAAQ,QACX,MAAM,IAAI,MACR,gMACF;CAGF,IAAI,QAAQ,OAAO,cAAc,MAC/B,MAAM,YAAY,SAAS,MAAM;CAGnC,OAAO;AACT"}
1
+ {"version":3,"file":"extract.mjs","names":["isSetObject","extractJsonSchema","extractJsonSchemaZod"],"sources":["../src/extract.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { Context } from \"@powerlines/core\";\nimport { isTypeDefinition } from \"@powerlines/core\";\nimport { rolldownPlugin } from \"@powerlines/deepkit/rolldown-plugin\";\nimport { isType, stringifyType, Type } from \"@powerlines/deepkit/vendor/type\";\nimport { StandardJSONSchemaV1 } from \"@standard-schema/spec\";\nimport { murmurhash } from \"@stryke/hash\";\nimport { isStandardJsonSchema } from \"@stryke/json\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { isSetString } from \"@stryke/type-checks\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport {\n extractJsonSchema as extractJsonSchemaZod,\n isZod3Type\n} from \"@stryke/zod\";\nimport { toJsonSchema } from \"@valibot/to-json-schema\";\nimport defu from \"defu\";\nimport type { BuildOptions } from \"rolldown\";\nimport * as z3 from \"zod/v3\";\nimport { getCacheDirectory, writeSchema } from \"./persistence\";\nimport { reflectionToJsonSchema } from \"./reflection\";\nimport { resolve } from \"./resolve\";\nimport {\n isExtractedSchema,\n isJsonSchema,\n isJsonSchemaObject,\n isSchema,\n isUntypedInput,\n isUntypedSchema,\n isValibotSchema\n} from \"./type-checks\";\nimport {\n ExtractedSchema,\n JsonSchema,\n Schema,\n SchemaInput,\n SchemaInputVariant,\n SchemaSource,\n SchemaSourceInput,\n SchemaSourceVariant,\n TypeDefinitionReference,\n UntypedInputObject,\n UntypedSchema,\n ValibotSchema\n} from \"./types\";\n\nfunction convertNestedUntypedSchema(value: unknown): unknown {\n if (isUntypedSchema(value)) {\n return convertUntypedSchemaToJsonSchema(value);\n }\n\n if (isSetObject(value)) {\n if (isUntypedInput(value)) {\n return convertUntypedInputToJsonSchema(value);\n }\n\n const nested = value as Record<string, unknown>;\n if (\"$schema\" in nested && isUntypedSchema(nested.$schema)) {\n return convertUntypedSchemaToJsonSchema(nested.$schema);\n }\n }\n\n return value;\n}\n\nfunction convertNestedUntypedSchemaArray(value: unknown): unknown {\n if (!Array.isArray(value)) {\n return value;\n }\n\n return value.map(item => convertNestedUntypedSchema(item));\n}\n\nfunction convertValibotSchemaToJsonSchema<T = unknown>(\n schema: unknown\n): JsonSchema<T> {\n return toJsonSchema(schema as never, {\n target: \"draft-07\"\n }) as JsonSchema<T>;\n}\n\nfunction convertUntypedSchemaToJsonSchema<T = unknown>(\n schema: UntypedSchema | Record<string, unknown>\n): JsonSchema<T> {\n const source = schema as Record<string, unknown>;\n const jsonSchema: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(source)) {\n if (\n key === \"tsType\" ||\n key === \"markdownType\" ||\n key === \"tags\" ||\n key === \"args\" ||\n key === \"resolve\"\n ) {\n continue;\n }\n\n if (key === \"id\" && isSetString(value)) {\n jsonSchema.$id = value;\n continue;\n }\n\n if (\n key === \"properties\" ||\n key === \"patternProperties\" ||\n key === \"dependentSchemas\" ||\n key === \"$defs\" ||\n key === \"definitions\"\n ) {\n if (!isSetObject(value)) {\n jsonSchema[key] = value;\n continue;\n }\n\n jsonSchema[key] = Object.fromEntries(\n Object.entries(value).map(([propertyKey, propertyValue]) => [\n propertyKey,\n convertNestedUntypedSchema(propertyValue)\n ])\n );\n continue;\n }\n\n if (\n key === \"items\" ||\n key === \"contains\" ||\n key === \"if\" ||\n key === \"then\" ||\n key === \"else\" ||\n key === \"not\" ||\n key === \"propertyNames\" ||\n key === \"additionalProperties\" ||\n key === \"unevaluatedProperties\"\n ) {\n jsonSchema[key] = convertNestedUntypedSchema(value);\n continue;\n }\n\n if (key === \"oneOf\" || key === \"anyOf\" || key === \"allOf\") {\n jsonSchema[key] = convertNestedUntypedSchemaArray(value);\n continue;\n }\n\n jsonSchema[key] = value;\n }\n\n return jsonSchema as JsonSchema<T>;\n}\n\nfunction convertUntypedInputToJsonSchema<T = unknown>(\n input: UntypedInputObject\n): JsonSchema<T> {\n const inputObject = input as Record<string, unknown>;\n const base = (\n isUntypedSchema(inputObject.$schema)\n ? convertUntypedSchemaToJsonSchema<T>(inputObject.$schema)\n : {}\n ) as JsonSchema<T>;\n const properties: Record<string, JsonSchema<T>> = {};\n\n for (const [key, value] of Object.entries(inputObject)) {\n if (key.startsWith(\"$\")) {\n continue;\n }\n\n if (!isSetObject(value)) {\n continue;\n }\n\n if (isUntypedInput(value)) {\n properties[key] = convertUntypedInputToJsonSchema<T>(value);\n continue;\n }\n\n const nested = value as Record<string, unknown>;\n if (\"$schema\" in nested && isUntypedSchema(nested.$schema)) {\n properties[key] = convertUntypedSchemaToJsonSchema<T>(nested.$schema);\n continue;\n }\n\n if (isUntypedSchema(value)) {\n properties[key] = convertUntypedSchemaToJsonSchema<T>(value);\n }\n }\n\n if (!isJsonSchemaObject(base)) {\n throw new Error(\n `Failed to convert untyped input to JSON Schema. The base schema must be a valid JSON Schema object.`\n );\n }\n\n const baseProperties = isSetObject(base.properties)\n ? (base.properties as Record<string, JsonSchema<T>>)\n : {};\n const mergedProperties = {\n ...baseProperties,\n ...properties\n };\n\n return {\n ...base,\n type: base.type ?? \"object\",\n ...(Object.keys(mergedProperties).length > 0\n ? { properties: mergedProperties }\n : {})\n };\n}\n\n/**\n * Creates a hash string for a given schema definition input.\n */\nexport function extractHash<T = unknown>(\n variant: SchemaInputVariant,\n input: SchemaInput<T>\n): string {\n if (isSetString(input)) {\n return murmurhash({ variant, input });\n } else if (isSetObject(input)) {\n if (isZod3Type(input)) {\n return murmurhash({ variant, input: input._def });\n } else if (isStandardJsonSchema(input)) {\n return murmurhash({ variant, input: input[\"~standard\"] });\n } else if (isJsonSchema(input)) {\n return murmurhash({ variant, input });\n } else if (isValibotSchema(input)) {\n return murmurhash({\n variant,\n input: convertValibotSchemaToJsonSchema(input)\n });\n } else if (isUntypedInput(input)) {\n return murmurhash({\n variant,\n input: convertUntypedInputToJsonSchema(input)\n });\n } else if (isUntypedSchema(input)) {\n return murmurhash({\n variant,\n input: convertUntypedSchemaToJsonSchema(input)\n });\n } else if (isType(input)) {\n return murmurhash({ variant, input: stringifyType(input) });\n }\n }\n\n throw new Error(\n `Failed to create an input hash for the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Converts a reflected Deepkit {@link Type} into a JSON Schema (draft-07) representation.\n */\nexport function extractReflection<T = unknown>(\n reflection: Type\n): JsonSchema<T> | undefined {\n if (!isType(reflection)) {\n return undefined;\n }\n\n return reflectionToJsonSchema<T>(reflection);\n}\n\n/**\n * Extracts a JSON Schema from Zod, Standard Schema, Valibot, untyped, or JSON Schema inputs.\n */\nexport function extractJsonSchema<T = unknown>(\n schema: unknown\n): JsonSchema<T> | undefined {\n if (isSetObject(schema)) {\n if (isZod3Type(schema)) {\n return extractJsonSchemaZod(schema) as JsonSchema<T>;\n }\n if (isStandardJsonSchema(schema)) {\n return schema[\"~standard\"].jsonSchema.input({\n target: \"draft-2020-12\"\n }) as JsonSchema<T>;\n }\n if (isValibotSchema(schema)) {\n return convertValibotSchemaToJsonSchema<T>(schema);\n }\n if (isUntypedInput(schema)) {\n return convertUntypedInputToJsonSchema<T>(schema);\n }\n if (isUntypedSchema(schema)) {\n return convertUntypedSchemaToJsonSchema<T>(schema);\n }\n if (isJsonSchema<T>(schema)) {\n return schema;\n }\n }\n\n return undefined;\n}\n\nexport function extractResolvedVariant(\n input: SchemaSourceInput\n): SchemaSourceVariant {\n if (isSetObject(input)) {\n if (isZod3Type(input)) {\n return \"zod3\";\n } else if (isStandardJsonSchema(input)) {\n return \"standard-schema\";\n } else if (isJsonSchema(input)) {\n return \"json-schema\";\n } else if (isValibotSchema(input)) {\n return \"valibot\";\n } else if (isType(input)) {\n return \"reflection\";\n } else if (isUntypedInput(input) || isUntypedSchema(input)) {\n return \"untyped\";\n }\n }\n\n throw new Error(\n `Failed to determine the variant of the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, a reflected Deepkit Type object, or an Untyped schema.`\n );\n}\n\nexport function extractVariant<T = unknown>(\n input: SchemaInput<T>\n): SchemaInputVariant {\n if (isSetString(input) || isTypeDefinition(input)) {\n return \"type-definition\";\n }\n\n return extractResolvedVariant(input as SchemaSourceInput);\n}\n\nasync function extractSchemaSchema<T = unknown>(\n input: SchemaSourceInput,\n variant?: SchemaInputVariant\n): Promise<JsonSchema<T>> {\n if (isExtractedSchema<T>(input)) {\n return input.schema;\n }\n\n const resolvedVariant = variant ?? extractResolvedVariant(input);\n\n let schema: JsonSchema<T> | undefined;\n if (\n resolvedVariant === \"zod3\" ||\n resolvedVariant === \"json-schema\" ||\n resolvedVariant === \"standard-schema\" ||\n resolvedVariant === \"untyped\" ||\n resolvedVariant === \"valibot\"\n ) {\n schema = extractJsonSchema<T>(input);\n } else if (resolvedVariant === \"reflection\") {\n schema = extractReflection(input as Type);\n }\n\n if (schema) {\n return schema;\n }\n\n throw new Error(\n `Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, an untyped schema, or a reflected Deepkit Type object.`\n );\n}\n\nexport function extractSource(\n variant: SchemaSourceVariant,\n input: SchemaSourceInput\n): SchemaSource {\n if (variant === \"zod3\") {\n return {\n hash: extractHash(variant, input),\n variant: \"zod3\",\n schema: input as z3.ZodTypeAny\n };\n } else if (variant === \"untyped\") {\n return {\n hash: extractHash(variant, input),\n variant: \"untyped\",\n schema: input as UntypedInputObject | UntypedSchema\n };\n } else if (variant === \"standard-schema\") {\n return {\n hash: extractHash(variant, input),\n variant: \"standard-schema\",\n schema: input as StandardJSONSchemaV1\n };\n } else if (variant === \"json-schema\") {\n return {\n hash: extractHash(variant, input),\n variant: \"json-schema\",\n schema: input as JsonSchema\n };\n } else if (variant === \"valibot\") {\n return {\n hash: extractHash(variant, input),\n variant: \"valibot\",\n schema: input as ValibotSchema\n };\n } else if (variant === \"reflection\") {\n return {\n hash: extractHash(variant, input),\n variant: \"reflection\",\n schema: input as Type\n };\n }\n\n throw new Error(\n `Failed to extract source information from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object. If the input is a type definition reference (e.g. a file path with an export), it will be resolved and bundled using ESBuild to obtain the actual schema definition before extraction.\n *\n * @example\n * ```ts\n * // Resolve a schema definition from a file path\n * const schema1 = await extract(context, \"./schemas.ts#MySchema\");\n * // Resolve a schema definition from a JSON Schema object\n * const schema2 = await extract(context, schemaObject);\n * // Resolve a schema definition from a Zod schema\n * const schema3 = await extract(context, zodSchema);\n * // Resolve a schema definition from a reflected Deepkit Type object\n * const schema4 = await extract(context, reflectionType);\n * ```\n *\n * @see https://github.com/colinhacks/zod\n * @see https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec\n * @see https://json-schema.org/\n * @see https://ajv.js.org/json-type-definition.html\n * @see https://deepkit.io/en/documentation/runtime-types/reflection\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param input - The schema definition input to extract, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object. If the input is a string or a type definition reference, it will be resolved and bundled to obtain the actual schema definition before extraction.\n * @param options - Optional overrides for the ESBuild configuration used during extraction. This can include custom plugins, loaders, or other build options to control how the schema definition is resolved and bundled when the input is a type definition reference.\n * @returns A promise that resolves to the extracted and normalized schema as a JSON Schema object. The function will attempt to extract a valid JSON Schema from the provided input, and if successful, it will return the schema. If the extraction process fails or if the input is not a valid schema definition, it will throw an error indicating the failure.\n */\nexport async function extractSchema<T = unknown>(\n context: Context,\n input: SchemaInput,\n options: Partial<BuildOptions> = {}\n): Promise<ExtractedSchema<T>> {\n if (isExtractedSchema<T>(input)) {\n return input;\n }\n\n if (isSchema<T>(input)) {\n return {\n ...input,\n source: {\n hash: extractHash(\"json-schema\", input.schema),\n variant: \"json-schema\",\n schema: input.schema\n }\n };\n }\n\n let source: SchemaSource;\n\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n\n if (variant === \"type-definition\") {\n const resolved = await resolve<SchemaSourceInput>(\n context,\n input as TypeDefinitionReference,\n defu(options, {\n plugins: [\n rolldownPlugin(context, {\n reflection: \"default\",\n level: \"all\"\n })\n ]\n })\n );\n\n source = extractSource(extractResolvedVariant(resolved), resolved);\n } else if (\n [\n \"json-schema\",\n \"standard-schema\",\n \"zod3\",\n \"untyped\",\n \"reflection\"\n ].includes(variant)\n ) {\n source = extractSource(variant, input as SchemaSourceInput);\n } else {\n throw new Error(\n `Invalid schema definition input \"${\n variant\n }\". The variant must be one of \"type-definition\", \"json-schema\", \"standard-schema\", \"zod3\", \"untyped\", or \"reflection\".`\n );\n }\n\n return {\n variant,\n source,\n schema: await extractSchemaSchema<T>(source.schema, source.variant),\n hash\n };\n}\n\n/**\n * Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object. If the input is a type definition reference (e.g. a file path with an export), it will be resolved and bundled using ESBuild to obtain the actual schema definition before extraction.\n *\n * @example\n * ```ts\n * // Resolve a schema definition from a file path\n * const schema1 = await extract(context, \"./schemas.ts#MySchema\");\n * // Resolve a schema definition from a JSON Schema object\n * const schema2 = await extract(context, schemaObject);\n * // Resolve a schema definition from a Zod schema\n * const schema3 = await extract(context, zodSchema);\n * // Resolve a schema definition from a reflected Deepkit Type object\n * const schema4 = await extract(context, reflectionType);\n * ```\n *\n * @see https://github.com/colinhacks/zod\n * @see https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec\n * @see https://json-schema.org/\n * @see https://ajv.js.org/json-type-definition.html\n * @see https://deepkit.io/en/documentation/runtime-types/reflection\n * @see https://github.com/unjs/untyped\n * @see https://www.typescriptlang.org/docs/handbook/2/types-from-types.html\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param input - The schema definition input to extract, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.\n * @param options - Optional overrides for the ESBuild configuration used during extraction.\n * @returns A promise that resolves to the extracted and normalized schema as a JSON Schema object.\n * @throws Will throw an error if the input is not a valid schema definition or if the extraction process fails to produce a valid schema.\n */\nexport async function extract<T = unknown>(\n context: Context,\n input: SchemaInput,\n options: Partial<BuildOptions> = {}\n): Promise<Schema<T>> {\n if (isExtractedSchema<T>(input) || isSchema<T>(input)) {\n return input;\n }\n\n let result: Schema<T> | undefined;\n\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n\n const cacheFilePath = joinPaths(getCacheDirectory(context), `${hash}.json`);\n if (\n context.config.skipCache !== true &&\n context.fs.existsSync(cacheFilePath)\n ) {\n const schema = await context.fs.read(cacheFilePath);\n if (schema) {\n result = {\n variant,\n hash,\n schema: JSON.parse(schema) as JsonSchema<T>\n };\n }\n }\n\n result ??= await extractSchema<T>(context, input, options);\n if (!result?.schema) {\n throw new Error(\n `Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`\n );\n }\n\n if (context.config.skipCache !== true) {\n await writeSchema(context, result);\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA+DA,SAAS,2BAA2B,OAAyB;CAC3D,IAAI,gBAAgB,KAAK,GACvB,OAAO,iCAAiC,KAAK;CAG/C,IAAIA,cAAY,KAAK,GAAG;EACtB,IAAI,eAAe,KAAK,GACtB,OAAO,gCAAgC,KAAK;EAG9C,MAAM,SAAS;EACf,IAAI,aAAa,UAAU,gBAAgB,OAAO,OAAO,GACvD,OAAO,iCAAiC,OAAO,OAAO;CAE1D;CAEA,OAAO;AACT;AAEA,SAAS,gCAAgC,OAAyB;CAChE,IAAI,CAAC,MAAM,QAAQ,KAAK,GACtB,OAAO;CAGT,OAAO,MAAM,KAAI,SAAQ,2BAA2B,IAAI,CAAC;AAC3D;AAEA,SAAS,iCACP,QACe;CACf,OAAO,aAAa,QAAiB,EACnC,QAAQ,WACV,CAAC;AACH;AAEA,SAAS,iCACP,QACe;CACf,MAAM,SAAS;CACf,MAAM,aAAsC,CAAC;CAE7C,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,GAAG;EACjD,IACE,QAAQ,YACR,QAAQ,kBACR,QAAQ,UACR,QAAQ,UACR,QAAQ,WAER;EAGF,IAAI,QAAQ,QAAQ,YAAY,KAAK,GAAG;GACtC,WAAW,MAAM;GACjB;EACF;EAEA,IACE,QAAQ,gBACR,QAAQ,uBACR,QAAQ,sBACR,QAAQ,WACR,QAAQ,eACR;GACA,IAAI,CAACA,cAAY,KAAK,GAAG;IACvB,WAAW,OAAO;IAClB;GACF;GAEA,WAAW,OAAO,OAAO,YACvB,OAAO,QAAQ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Q,OAAO,cAAc,QAC7B,QAAQ,GAAG,WAAW,aAAa,GACnC;EACA,MAAM,SAAS,MAAM,QAAQ,GAAG,KAAK,aAAa;EAClD,IAAI,QACF,SAAS;GACP;GACA;GACA,QAAQ,KAAK,MAAM,MAAM;EAC3B;CAEJ;CAEA,WAAW,MAAM,cAAiB,SAAS,OAAO,OAAO;CACzD,IAAI,CAAC,QAAQ,QACX,MAAM,IAAI,MACR,gMACF;CAGF,IAAI,QAAQ,OAAO,cAAc,MAC/B,MAAM,YAAY,SAAS,MAAM;CAGnC,OAAO;AACT"}
package/dist/helpers.cjs CHANGED
@@ -1,4 +1,3 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
1
  const require_metadata = require('./metadata.cjs');
3
2
  const require_type_checks = require('./type-checks.cjs');
4
3
  let defu = require("defu");
package/dist/index.cjs CHANGED
@@ -22,7 +22,6 @@ exports.extractJsonSchema = require_extract.extractJsonSchema;
22
22
  exports.extractReflection = require_extract.extractReflection;
23
23
  exports.extractResolvedVariant = require_extract.extractResolvedVariant;
24
24
  exports.extractSchema = require_extract.extractSchema;
25
- exports.extractSchemaSchema = require_extract.extractSchemaSchema;
26
25
  exports.extractSource = require_extract.extractSource;
27
26
  exports.extractVariant = require_extract.extractVariant;
28
27
  exports.generateCode = require_codegen.generateCode;
@@ -39,8 +38,10 @@ exports.isNullableSchema = require_codegen.isNullableSchema;
39
38
  exports.isPropertyOptional = require_metadata.isPropertyOptional;
40
39
  exports.isSchema = require_type_checks.isSchema;
41
40
  exports.isSchemaNullable = require_metadata.isSchemaNullable;
41
+ exports.isStandardSchema = require_type_checks.isStandardSchema;
42
42
  exports.isUntypedInput = require_type_checks.isUntypedInput;
43
43
  exports.isUntypedSchema = require_type_checks.isUntypedSchema;
44
+ exports.isValibotSchema = require_type_checks.isValibotSchema;
44
45
  exports.mergeSchemas = require_helpers.mergeSchemas;
45
46
  exports.readSchema = require_persistence.readSchema;
46
47
  exports.readSchemaSafe = require_persistence.readSchemaSafe;
package/dist/index.d.cts CHANGED
@@ -1,12 +1,38 @@
1
1
  import { BundleOptions, bundle } from "./bundle.cjs";
2
- import { BaseSchemaSource, ExtractedSchema, JsonSchema, JsonSchemaLike, JsonSchemaNullable, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaProperty, JsonSchemaSchemaSource, JsonType, NumberFormat, NumberKeywords, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, StringKeywords, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, Zod3SchemaSource } from "./types.cjs";
2
+ import { BaseSchemaSource, ExtractedSchema, JsonSchema, JsonSchemaLike, JsonSchemaNullable, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaProperty, JsonSchemaSchemaSource, JsonType, NumberFormat, NumberKeywords, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, StringKeywords, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, ValibotSchema, ValibotSchemaSource, Zod3SchemaSource } from "./types.cjs";
3
3
  import { generateCode, isNullableSchema, stringifyType, stringifyValue } from "./codegen.cjs";
4
4
  import { JSON_SCHEMA_DATA_TYPES, JSON_SCHEMA_METADATA_KEYS, JsonSchemaTypes } from "./constants.cjs";
5
- import { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaSchema, extractSource, extractVariant } from "./extract.cjs";
5
+ import { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSource, extractVariant } from "./extract.cjs";
6
6
  import { addProperty, getProperties, getPropertiesList, mergeSchemas } from "./helpers.cjs";
7
7
  import { applySchemaMetadata, getPrimarySchemaType, isPropertyOptional, isSchemaNullable, readSchemaTypes } from "./metadata.cjs";
8
8
  import { getCacheDirectory, getCacheFilePath, readSchema, readSchemaSafe, writeSchema } from "./persistence.cjs";
9
9
  import { reflectionToJsonSchema } from "./reflection.cjs";
10
10
  import { resolve, resolveModule, resolveReflection } from "./resolve.cjs";
11
- import { isExtractedSchema, isJsonSchema, isJsonSchemaObject, isNullOnlyJsonSchema, isSchema, isUntypedInput, isUntypedSchema } from "./type-checks.cjs";
12
- export { BaseSchemaSource, BundleOptions, ExtractedSchema, JSON_SCHEMA_DATA_TYPES, JSON_SCHEMA_METADATA_KEYS, JsonSchema, JsonSchemaLike, JsonSchemaNullable, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaProperty, JsonSchemaSchemaSource, JsonSchemaTypes, JsonType, NumberFormat, NumberKeywords, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, StringKeywords, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, Zod3SchemaSource, addProperty, applySchemaMetadata, bundle, extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaSchema, extractSource, extractVariant, generateCode, getCacheDirectory, getCacheFilePath, getPrimarySchemaType, getProperties, getPropertiesList, isExtractedSchema, isJsonSchema, isJsonSchemaObject, isNullOnlyJsonSchema, isNullableSchema, isPropertyOptional, isSchema, isSchemaNullable, isUntypedInput, isUntypedSchema, mergeSchemas, readSchema, readSchemaSafe, readSchemaTypes, reflectionToJsonSchema, resolve, resolveModule, resolveReflection, stringifyType, stringifyValue, writeSchema };
11
+ import { isExtractedSchema, isJsonSchema, isJsonSchemaObject, isNullOnlyJsonSchema, isSchema, isStandardSchema, isUntypedInput, isUntypedSchema, isValibotSchema } from "./type-checks.cjs";
12
+
13
+ //#region src/index.d.ts
14
+ declare module "zod" {
15
+ interface GlobalMeta {
16
+ id?: string;
17
+ title?: string;
18
+ description?: string;
19
+ docs?: string;
20
+ alias?: string[];
21
+ tags?: string[];
22
+ deprecated?: boolean;
23
+ hidden?: boolean;
24
+ ignore?: boolean;
25
+ internal?: boolean;
26
+ runtime?: boolean;
27
+ examples?: unknown[];
28
+ readOnly?: boolean;
29
+ writeOnly?: boolean;
30
+ contentEncoding?: string;
31
+ contentMediaType?: string;
32
+ contentSchema?: string;
33
+ [keyword: string]: unknown;
34
+ }
35
+ }
36
+ //#endregion
37
+ export { BaseSchemaSource, BundleOptions, ExtractedSchema, JSON_SCHEMA_DATA_TYPES, JSON_SCHEMA_METADATA_KEYS, JsonSchema, JsonSchemaLike, JsonSchemaNullable, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaProperty, JsonSchemaSchemaSource, JsonSchemaTypes, JsonType, NumberFormat, NumberKeywords, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, StringKeywords, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, ValibotSchema, ValibotSchemaSource, Zod3SchemaSource, addProperty, applySchemaMetadata, bundle, extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSource, extractVariant, generateCode, getCacheDirectory, getCacheFilePath, getPrimarySchemaType, getProperties, getPropertiesList, isExtractedSchema, isJsonSchema, isJsonSchemaObject, isNullOnlyJsonSchema, isNullableSchema, isPropertyOptional, isSchema, isSchemaNullable, isStandardSchema, isUntypedInput, isUntypedSchema, isValibotSchema, mergeSchemas, readSchema, readSchemaSafe, readSchemaTypes, reflectionToJsonSchema, resolve, resolveModule, resolveReflection, stringifyType, stringifyValue, writeSchema };
38
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;;YAmBY,UAAA;IACR,EAAA;IACA,KAAA;IACA,WAAA;IACA,IAAA;IACA,KAAA;IACA,IAAA;IACA,UAAA;IACA,MAAA;IACA,MAAA;IACA,QAAA;IACA,OAAA;IACA,QAAA;IACA,QAAA;IACA,SAAA;IACA,eAAA;IACA,gBAAA;IACA,aAAA;IAAA,CACC,OAAA;EAAA;AAAA"}
package/dist/index.d.mts CHANGED
@@ -1,12 +1,38 @@
1
1
  import { BundleOptions, bundle } from "./bundle.mjs";
2
- import { BaseSchemaSource, ExtractedSchema, JsonSchema, JsonSchemaLike, JsonSchemaNullable, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaProperty, JsonSchemaSchemaSource, JsonType, NumberFormat, NumberKeywords, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, StringKeywords, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, Zod3SchemaSource } from "./types.mjs";
2
+ import { BaseSchemaSource, ExtractedSchema, JsonSchema, JsonSchemaLike, JsonSchemaNullable, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaProperty, JsonSchemaSchemaSource, JsonType, NumberFormat, NumberKeywords, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, StringKeywords, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, ValibotSchema, ValibotSchemaSource, Zod3SchemaSource } from "./types.mjs";
3
3
  import { generateCode, isNullableSchema, stringifyType, stringifyValue } from "./codegen.mjs";
4
4
  import { JSON_SCHEMA_DATA_TYPES, JSON_SCHEMA_METADATA_KEYS, JsonSchemaTypes } from "./constants.mjs";
5
- import { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaSchema, extractSource, extractVariant } from "./extract.mjs";
5
+ import { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSource, extractVariant } from "./extract.mjs";
6
6
  import { addProperty, getProperties, getPropertiesList, mergeSchemas } from "./helpers.mjs";
7
7
  import { applySchemaMetadata, getPrimarySchemaType, isPropertyOptional, isSchemaNullable, readSchemaTypes } from "./metadata.mjs";
8
8
  import { getCacheDirectory, getCacheFilePath, readSchema, readSchemaSafe, writeSchema } from "./persistence.mjs";
9
9
  import { reflectionToJsonSchema } from "./reflection.mjs";
10
10
  import { resolve, resolveModule, resolveReflection } from "./resolve.mjs";
11
- import { isExtractedSchema, isJsonSchema, isJsonSchemaObject, isNullOnlyJsonSchema, isSchema, isUntypedInput, isUntypedSchema } from "./type-checks.mjs";
12
- export { BaseSchemaSource, BundleOptions, ExtractedSchema, JSON_SCHEMA_DATA_TYPES, JSON_SCHEMA_METADATA_KEYS, JsonSchema, JsonSchemaLike, JsonSchemaNullable, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaProperty, JsonSchemaSchemaSource, JsonSchemaTypes, JsonType, NumberFormat, NumberKeywords, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, StringKeywords, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, Zod3SchemaSource, addProperty, applySchemaMetadata, bundle, extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaSchema, extractSource, extractVariant, generateCode, getCacheDirectory, getCacheFilePath, getPrimarySchemaType, getProperties, getPropertiesList, isExtractedSchema, isJsonSchema, isJsonSchemaObject, isNullOnlyJsonSchema, isNullableSchema, isPropertyOptional, isSchema, isSchemaNullable, isUntypedInput, isUntypedSchema, mergeSchemas, readSchema, readSchemaSafe, readSchemaTypes, reflectionToJsonSchema, resolve, resolveModule, resolveReflection, stringifyType, stringifyValue, writeSchema };
11
+ import { isExtractedSchema, isJsonSchema, isJsonSchemaObject, isNullOnlyJsonSchema, isSchema, isStandardSchema, isUntypedInput, isUntypedSchema, isValibotSchema } from "./type-checks.mjs";
12
+
13
+ //#region src/index.d.ts
14
+ declare module "zod" {
15
+ interface GlobalMeta {
16
+ id?: string;
17
+ title?: string;
18
+ description?: string;
19
+ docs?: string;
20
+ alias?: string[];
21
+ tags?: string[];
22
+ deprecated?: boolean;
23
+ hidden?: boolean;
24
+ ignore?: boolean;
25
+ internal?: boolean;
26
+ runtime?: boolean;
27
+ examples?: unknown[];
28
+ readOnly?: boolean;
29
+ writeOnly?: boolean;
30
+ contentEncoding?: string;
31
+ contentMediaType?: string;
32
+ contentSchema?: string;
33
+ [keyword: string]: unknown;
34
+ }
35
+ }
36
+ //#endregion
37
+ export { BaseSchemaSource, BundleOptions, ExtractedSchema, JSON_SCHEMA_DATA_TYPES, JSON_SCHEMA_METADATA_KEYS, JsonSchema, JsonSchemaLike, JsonSchemaNullable, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaProperty, JsonSchemaSchemaSource, JsonSchemaTypes, JsonType, NumberFormat, NumberKeywords, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, StringKeywords, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, ValibotSchema, ValibotSchemaSource, Zod3SchemaSource, addProperty, applySchemaMetadata, bundle, extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSource, extractVariant, generateCode, getCacheDirectory, getCacheFilePath, getPrimarySchemaType, getProperties, getPropertiesList, isExtractedSchema, isJsonSchema, isJsonSchemaObject, isNullOnlyJsonSchema, isNullableSchema, isPropertyOptional, isSchema, isSchemaNullable, isStandardSchema, isUntypedInput, isUntypedSchema, isValibotSchema, mergeSchemas, readSchema, readSchemaSafe, readSchemaTypes, reflectionToJsonSchema, resolve, resolveModule, resolveReflection, stringifyType, stringifyValue, writeSchema };
38
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;;YAmBY,UAAA;IACR,EAAA;IACA,KAAA;IACA,WAAA;IACA,IAAA;IACA,KAAA;IACA,IAAA;IACA,UAAA;IACA,MAAA;IACA,MAAA;IACA,QAAA;IACA,OAAA;IACA,QAAA;IACA,QAAA;IACA,SAAA;IACA,eAAA;IACA,gBAAA;IACA,aAAA;IAAA,CACC,OAAA;EAAA;AAAA"}