@powerlines/schema 0.11.27 → 0.11.37

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 (82) hide show
  1. package/dist/bundle.cjs +34 -20
  2. package/dist/bundle.d.cts +3 -3
  3. package/dist/bundle.d.cts.map +1 -1
  4. package/dist/bundle.d.mts +3 -3
  5. package/dist/bundle.d.mts.map +1 -1
  6. package/dist/bundle.mjs +35 -21
  7. package/dist/bundle.mjs.map +1 -1
  8. package/dist/codegen.cjs +40 -36
  9. package/dist/codegen.d.cts +10 -22
  10. package/dist/codegen.d.cts.map +1 -1
  11. package/dist/codegen.d.mts +10 -22
  12. package/dist/codegen.d.mts.map +1 -1
  13. package/dist/codegen.mjs +39 -36
  14. package/dist/codegen.mjs.map +1 -1
  15. package/dist/constants.cjs +34 -11
  16. package/dist/constants.d.cts +9 -11
  17. package/dist/constants.d.cts.map +1 -1
  18. package/dist/constants.d.mts +9 -11
  19. package/dist/constants.d.mts.map +1 -1
  20. package/dist/constants.mjs +32 -11
  21. package/dist/constants.mjs.map +1 -1
  22. package/dist/extract.cjs +122 -92
  23. package/dist/extract.d.cts +34 -69
  24. package/dist/extract.d.cts.map +1 -1
  25. package/dist/extract.d.mts +34 -69
  26. package/dist/extract.d.mts.map +1 -1
  27. package/dist/extract.mjs +123 -93
  28. package/dist/extract.mjs.map +1 -1
  29. package/dist/helpers.cjs +45 -52
  30. package/dist/helpers.d.cts +28 -24
  31. package/dist/helpers.d.cts.map +1 -1
  32. package/dist/helpers.d.mts +28 -24
  33. package/dist/helpers.d.mts.map +1 -1
  34. package/dist/helpers.mjs +46 -52
  35. package/dist/helpers.mjs.map +1 -1
  36. package/dist/index.cjs +14 -7
  37. package/dist/index.d.cts +6 -6
  38. package/dist/index.d.mts +6 -6
  39. package/dist/index.mjs +5 -5
  40. package/dist/metadata.cjs +80 -0
  41. package/dist/metadata.d.cts +52 -0
  42. package/dist/metadata.d.cts.map +1 -0
  43. package/dist/metadata.d.mts +52 -0
  44. package/dist/metadata.d.mts.map +1 -0
  45. package/dist/metadata.mjs +76 -0
  46. package/dist/metadata.mjs.map +1 -0
  47. package/dist/persistence.cjs +1 -2
  48. package/dist/persistence.d.cts +5 -5
  49. package/dist/persistence.d.cts.map +1 -1
  50. package/dist/persistence.d.mts +5 -5
  51. package/dist/persistence.d.mts.map +1 -1
  52. package/dist/persistence.mjs +1 -1
  53. package/dist/persistence.mjs.map +1 -1
  54. package/dist/reflection.cjs +289 -303
  55. package/dist/reflection.d.cts +3 -16
  56. package/dist/reflection.d.cts.map +1 -1
  57. package/dist/reflection.d.mts +3 -16
  58. package/dist/reflection.d.mts.map +1 -1
  59. package/dist/reflection.mjs +290 -304
  60. package/dist/reflection.mjs.map +1 -1
  61. package/dist/resolve.cjs +7 -7
  62. package/dist/resolve.mjs +7 -7
  63. package/dist/resolve.mjs.map +1 -1
  64. package/dist/type-checks.cjs +122 -40
  65. package/dist/type-checks.d.cts +41 -33
  66. package/dist/type-checks.d.cts.map +1 -1
  67. package/dist/type-checks.d.mts +41 -33
  68. package/dist/type-checks.d.mts.map +1 -1
  69. package/dist/type-checks.mjs +120 -37
  70. package/dist/type-checks.mjs.map +1 -1
  71. package/dist/types.d.cts +225 -113
  72. package/dist/types.d.cts.map +1 -1
  73. package/dist/types.d.mts +225 -113
  74. package/dist/types.d.mts.map +1 -1
  75. package/package.json +11 -7
  76. package/dist/jtd.cjs +0 -385
  77. package/dist/jtd.d.cts +0 -15
  78. package/dist/jtd.d.cts.map +0 -1
  79. package/dist/jtd.d.mts +0 -15
  80. package/dist/jtd.d.mts.map +0 -1
  81. package/dist/jtd.mjs +0 -384
  82. package/dist/jtd.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"codegen.mjs","names":[],"sources":["../src/codegen.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 { toBool } from \"@stryke/convert/to-bool\";\nimport { isBoolean } from \"@stryke/type-checks/is-boolean\";\nimport { isNull } from \"@stryke/type-checks/is-null\";\nimport { isNumber } from \"@stryke/type-checks/is-number\";\nimport { isUndefined } from \"@stryke/type-checks/is-undefined\";\nimport type { Options } from \"ajv/lib/jtd\";\nimport Ajv from \"ajv/lib/jtd\";\nimport standaloneCode from \"ajv/lib/standalone\";\nimport { getProperties } from \"./helpers\";\nimport { JTDSchemaType, JTDType } from \"./types\";\n\n/**\n * Stringifies a value as a string.\n *\n * @remarks\n * This function is used to convert a value into a string representation that can be used in generated code, such as default values in TypeScript declarations. It handles different types of values, including booleans, numbers, and strings, and formats them appropriately. For example, boolean values are converted to \"true\" or \"false\", numbers are formatted with locale-specific separators, and strings are JSON-stringified with escaped quotes. The function also takes into account the type of the value when stringifying, allowing for specific formatting based on the type (e.g., different handling for integers vs. floats). This ensures that the generated code is both accurate and readable.\n *\n * @param value - The value to stringify.\n * @returns A string representation of the value.\n */\nexport function stringifyValue(value?: unknown, type?: JTDType): string {\n return isUndefined(value)\n ? \"undefined\"\n : isNull(value)\n ? \"null\"\n : type === \"boolean\" || isBoolean(value)\n ? String(toBool(value))\n : type && type.startsWith(\"float\")\n ? Number.parseFloat(String(value)).toLocaleString(undefined, {\n maximumFractionDigits: 20\n })\n : (type && [\"int\", \"uint\"].some(prefix => type.startsWith(prefix))) ||\n isNumber(value)\n ? Number.parseInt(String(value)).toLocaleString()\n : type === \"timestamp\"\n ? `\"${new Date(String(value)).toISOString()}\"`\n : JSON.stringify(\n String(value).replaceAll('\"', '\\\\\"'),\n undefined,\n 2\n );\n}\n\n/**\n * Stringifies a JTD schema type into a string representation. This function takes a JTD schema type as input and returns a string that represents the type in a human-readable format. It handles various JTD schema constructs, such as references, primitive types, enums, arrays, objects, and discriminated unions. The resulting string can be used for documentation, error messages, or any context where a textual representation of the schema type is needed. The function recursively processes nested schemas to ensure that complex types are accurately represented in the output string.\n *\n * @param schema - The JTD schema type to stringify.\n * @returns A string representation of the JTD schema type.\n */\nexport function stringifyType(schema?: JTDSchemaType): string {\n if (!schema) {\n return \"unknown\";\n }\n\n if (\"ref\" in schema) {\n return schema.ref;\n }\n\n if (\"type\" in schema) {\n return [\"float\", \"uint\", \"int\"].some(prefix =>\n schema.type.startsWith(prefix)\n )\n ? \"number\"\n : schema.type === \"timestamp\"\n ? \"string\"\n : schema.type;\n }\n\n if (\"enum\" in schema) {\n return schema.enum.map(value => JSON.stringify(value)).join(\" | \");\n }\n\n if (\"elements\" in schema) {\n return `${stringifyType(schema.elements)}[]`;\n }\n\n if (\"values\" in schema) {\n return `{ [key: string]: ${stringifyType(schema.values)} }`;\n }\n\n if (\"properties\" in schema || \"optionalProperties\" in schema) {\n return `{ ${Object.entries(getProperties(schema))\n .map(([key, value]) => {\n return `${key}${value.optional ? \"?\" : \"\"}: ${stringifyType(value)}`;\n })\n .join(\";\\n\")} }`;\n }\n\n if (\"discriminator\" in schema) {\n return \"object\";\n }\n\n return \"unknown\";\n}\n\n/**\n * Generates standalone validation code for the provided JSON schemas using the Ajv library. This function takes an array of JSON schemas and an optional set of references or functions, and returns a string containing the generated validation code. The generated code can be used to validate data against the provided schemas without requiring the Ajv library at runtime, making it suitable for use in environments where minimizing dependencies is important.\n *\n * @param schemas - An array of JSON schemas to generate validation code for. Each schema should be a valid JSON schema object that defines the structure and constraints of the data to be validated.\n * @param refsOrFuncts - An optional parameter that can be either an object containing schema references or a function that returns such an object. This parameter allows you to provide additional schemas that may be referenced by the main schemas, or to define custom functions that can be used in the generated validation code. If not provided, the function will generate code based solely on the provided schemas.\n * @returns A promise that resolves to a string containing the generated standalone validation code.\n */\nexport async function generateCode(\n schemas: Options[\"schemas\"],\n refsOrFuncts?: Parameters<typeof standaloneCode>[1]\n) {\n return standaloneCode(\n new Ajv({\n schemas,\n code: { source: true, esm: true }\n }),\n refsOrFuncts\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,eAAe,OAAiB,MAAwB;CACtE,OAAO,YAAY,KAAK,IACpB,cACA,OAAO,KAAK,IACV,SACA,SAAS,aAAa,UAAU,KAAK,IACnC,OAAO,OAAO,KAAK,CAAC,IACpB,QAAQ,KAAK,WAAW,OAAO,IAC7B,OAAO,WAAW,OAAO,KAAK,CAAC,EAAE,eAAe,QAAW,EACzD,uBAAuB,GACzB,CAAC,IACA,QAAQ,CAAC,OAAO,MAAM,EAAE,MAAK,WAAU,KAAK,WAAW,MAAM,CAAC,KAC7D,SAAS,KAAK,IACd,OAAO,SAAS,OAAO,KAAK,CAAC,EAAE,eAAe,IAC9C,SAAS,cACP,IAAI,IAAI,KAAK,OAAO,KAAK,CAAC,EAAE,YAAY,EAAE,KAC1C,KAAK,UACH,OAAO,KAAK,EAAE,WAAW,MAAK,MAAK,GACnC,QACA,CACF;AAChB;;;;;;;AAQA,SAAgB,cAAc,QAAgC;CAC5D,IAAI,CAAC,QACH,OAAO;CAGT,IAAI,SAAS,QACX,OAAO,OAAO;CAGhB,IAAI,UAAU,QACZ,OAAO;EAAC;EAAS;EAAQ;CAAK,EAAE,MAAK,WACnC,OAAO,KAAK,WAAW,MAAM,CAC/B,IACI,WACA,OAAO,SAAS,cACd,WACA,OAAO;CAGf,IAAI,UAAU,QACZ,OAAO,OAAO,KAAK,KAAI,UAAS,KAAK,UAAU,KAAK,CAAC,EAAE,KAAK,KAAK;CAGnE,IAAI,cAAc,QAChB,OAAO,GAAG,cAAc,OAAO,QAAQ,EAAE;CAG3C,IAAI,YAAY,QACd,OAAO,oBAAoB,cAAc,OAAO,MAAM,EAAE;CAG1D,IAAI,gBAAgB,UAAU,wBAAwB,QACpD,OAAO,KAAK,OAAO,QAAQ,cAAc,MAAM,CAAC,EAC7C,KAAK,CAAC,KAAK,WAAW;EACrB,OAAO,GAAG,MAAM,MAAM,WAAW,MAAM,GAAG,IAAI,cAAc,KAAK;CACnE,CAAC,EACA,KAAK,KAAK,EAAE;CAGjB,IAAI,mBAAmB,QACrB,OAAO;CAGT,OAAO;AACT;;;;;;;;AASA,eAAsB,aACpB,SACA,cACA;CACA,OAAO,eACL,IAAI,IAAI;EACN;EACA,MAAM;GAAE,QAAQ;GAAM,KAAK;EAAK;CAClC,CAAC,GACD,YACF;AACF"}
1
+ {"version":3,"file":"codegen.mjs","names":[],"sources":["../src/codegen.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 { toBool } from \"@stryke/convert/to-bool\";\nimport { isBoolean } from \"@stryke/type-checks/is-boolean\";\nimport { isNull } from \"@stryke/type-checks/is-null\";\nimport { isNumber } from \"@stryke/type-checks/is-number\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isUndefined } from \"@stryke/type-checks/is-undefined\";\nimport type { Options } from \"ajv\";\nimport Ajv from \"ajv\";\nimport { formatNames, fullFormats } from \"ajv-formats/dist/formats\";\nimport { _, Name } from \"ajv/dist/compile/codegen\";\nimport standaloneCode from \"ajv/dist/standalone\";\nimport { getPropertiesList } from \"./helpers\";\nimport { getPrimarySchemaType, isSchemaNullable } from \"./metadata\";\nimport { isJsonSchemaObject } from \"./type-checks\";\nimport { JsonSchema, JsonSchemaPrimitiveType } from \"./types\";\n\n/**\n * Stringifies a value for generated TypeScript code.\n */\nexport function stringifyValue(\n value?: unknown,\n type?: JsonSchemaPrimitiveType | string\n): string {\n return isUndefined(value)\n ? \"undefined\"\n : isNull(value)\n ? \"null\"\n : type === \"boolean\" || isBoolean(value)\n ? String(toBool(value))\n : type === \"number\" || isNumber(value)\n ? Number.parseFloat(String(value)).toLocaleString(undefined, {\n maximumFractionDigits: 20\n })\n : type === \"integer\"\n ? Number.parseInt(String(value)).toLocaleString()\n : JSON.stringify(value);\n}\n\n/**\n * Stringifies a JSON Schema fragment into a TypeScript-like type string.\n */\nexport function stringifyType<T = unknown>(schema?: JsonSchema<T>): string {\n if (!schema) {\n return \"unknown\";\n }\n\n if (isSetString(schema.$ref)) {\n const match = /^#\\/(?:definitions|\\$defs)\\/(.+)$/.exec(schema.$ref);\n\n return match?.[1] ?? schema.$ref;\n }\n\n const primaryType = getPrimarySchemaType(schema);\n if (primaryType) {\n if (primaryType === \"integer\" || primaryType === \"number\") {\n return \"number\";\n }\n\n return primaryType;\n }\n\n if (Array.isArray(schema.enum)) {\n return schema.enum.map(value => JSON.stringify(value)).join(\" | \");\n }\n\n if (schema.const !== undefined) {\n return JSON.stringify(schema.const);\n }\n\n if (schema.type === \"array\" || schema.items) {\n const items = Array.isArray(schema.items) ? schema.items[0] : schema.items;\n\n return `${stringifyType(items)}[]`;\n }\n\n if (\n schema.type === \"object\" ||\n schema.properties ||\n schema.additionalProperties\n ) {\n if (\n schema.additionalProperties &&\n typeof schema.additionalProperties === \"object\"\n ) {\n return `{ [key: string]: ${stringifyType(schema.additionalProperties)} }`;\n }\n\n if (isJsonSchemaObject(schema)) {\n return `{ ${getPropertiesList(schema as JsonSchema<Record<string, any>>)\n .map(property => {\n const suffix =\n property.optional || property.nullable\n ? `${property.optional ? \"?\" : \"\"}${property.nullable ? \" | null\" : \"\"}`\n : \"\";\n\n return `${property.key}${suffix}: ${stringifyType(property.value)}`;\n })\n .join(\";\\n\")} }`;\n }\n }\n\n if (schema.oneOf || schema.anyOf) {\n return ((schema.oneOf ?? schema.anyOf ?? []) as JsonSchema<T>[])\n .map(branch => stringifyType(branch))\n .join(\" | \");\n }\n\n if (schema.allOf) {\n return \"object\";\n }\n\n return \"unknown\";\n}\n\n/**\n * Generates standalone JSON Schema validation code using Ajv.\n */\nexport async function generateCode(\n schemas: Options[\"schemas\"],\n refsOrFuncts?: Parameters<typeof standaloneCode>[1]\n) {\n const ajv = new Ajv({\n schemas,\n code: { source: true, esm: true }\n });\n\n ajv.opts.code.formats ??= _`await import(\"ajv-formats/dist/formats\").${new Name(\n \"fullFormats\"\n )}`;\n for (const formatName of formatNames) {\n ajv.addFormat(formatName, fullFormats[formatName]);\n }\n\n return standaloneCode(ajv, refsOrFuncts);\n}\n\nexport function isNullableSchema(schema?: JsonSchema): boolean {\n return isSchemaNullable(schema);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqCA,SAAgB,eACd,OACA,MACQ;CACR,OAAO,YAAY,KAAK,IACpB,cACA,OAAO,KAAK,IACV,SACA,SAAS,aAAa,UAAU,KAAK,IACnC,OAAO,OAAO,KAAK,CAAC,IACpB,SAAS,YAAY,SAAS,KAAK,IACjC,OAAO,WAAW,OAAO,KAAK,CAAC,EAAE,eAAe,QAAW,EACzD,uBAAuB,GACzB,CAAC,IACD,SAAS,YACP,OAAO,SAAS,OAAO,KAAK,CAAC,EAAE,eAAe,IAC9C,KAAK,UAAU,KAAK;AAClC;;;;AAKA,SAAgB,cAA2B,QAAgC;CACzE,IAAI,CAAC,QACH,OAAO;CAGT,IAAI,YAAY,OAAO,IAAI,GAGzB,OAFc,oCAAoC,KAAK,OAAO,IAEnD,IAAI,MAAM,OAAO;CAG9B,MAAM,cAAc,qBAAqB,MAAM;CAC/C,IAAI,aAAa;EACf,IAAI,gBAAgB,aAAa,gBAAgB,UAC/C,OAAO;EAGT,OAAO;CACT;CAEA,IAAI,MAAM,QAAQ,OAAO,IAAI,GAC3B,OAAO,OAAO,KAAK,KAAI,UAAS,KAAK,UAAU,KAAK,CAAC,EAAE,KAAK,KAAK;CAGnE,IAAI,OAAO,UAAU,QACnB,OAAO,KAAK,UAAU,OAAO,KAAK;CAGpC,IAAI,OAAO,SAAS,WAAW,OAAO,OAGpC,OAAO,GAAG,cAFI,MAAM,QAAQ,OAAO,KAAK,IAAI,OAAO,MAAM,KAAK,OAAO,KAExC,EAAE;CAGjC,IACE,OAAO,SAAS,YAChB,OAAO,cACP,OAAO,sBACP;EACA,IACE,OAAO,wBACP,OAAO,OAAO,yBAAyB,UAEvC,OAAO,oBAAoB,cAAc,OAAO,oBAAoB,EAAE;EAGxE,IAAI,mBAAmB,MAAM,GAC3B,OAAO,KAAK,kBAAkB,MAAyC,EACpE,KAAI,aAAY;GACf,MAAM,SACJ,SAAS,YAAY,SAAS,WAC1B,GAAG,SAAS,WAAW,MAAM,KAAK,SAAS,WAAW,YAAY,OAClE;GAEN,OAAO,GAAG,SAAS,MAAM,OAAO,IAAI,cAAc,SAAS,KAAK;EAClE,CAAC,EACA,KAAK,KAAK,EAAE;CAEnB;CAEA,IAAI,OAAO,SAAS,OAAO,OACzB,QAAS,OAAO,SAAS,OAAO,SAAS,CAAC,GACvC,KAAI,WAAU,cAAc,MAAM,CAAC,EACnC,KAAK,KAAK;CAGf,IAAI,OAAO,OACT,OAAO;CAGT,OAAO;AACT;;;;AAKA,eAAsB,aACpB,SACA,cACA;CACA,MAAM,MAAM,IAAI,IAAI;EAClB;EACA,MAAM;GAAE,QAAQ;GAAM,KAAK;EAAK;CAClC,CAAC;CAED,IAAI,KAAK,KAAK,YAAY,CAAC,4CAA4C,IAAI,KACzE,aACF;CACA,KAAK,MAAM,cAAc,aACvB,IAAI,UAAU,YAAY,YAAY,WAAW;CAGnD,OAAO,eAAe,KAAK,YAAY;AACzC;AAEA,SAAgB,iBAAiB,QAA8B;CAC7D,OAAO,iBAAiB,MAAM;AAChC"}
@@ -1,19 +1,42 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
3
  //#region src/constants.ts
4
- const JTDTypes = {
4
+ const JsonSchemaTypes = {
5
5
  STRING: "string",
6
- TIMESTAMP: "timestamp",
6
+ NUMBER: "number",
7
+ INTEGER: "integer",
7
8
  BOOLEAN: "boolean",
8
- FLOAT32: "float32",
9
- FLOAT64: "float64",
10
- INT8: "int8",
11
- UINT8: "uint8",
12
- INT16: "int16",
13
- UINT16: "uint16",
14
- INT32: "int32",
15
- UINT32: "uint32"
9
+ NULL: "null",
10
+ OBJECT: "object",
11
+ ARRAY: "array"
16
12
  };
13
+ const JSON_SCHEMA_DATA_TYPES = [
14
+ JsonSchemaTypes.STRING,
15
+ JsonSchemaTypes.NUMBER,
16
+ JsonSchemaTypes.INTEGER,
17
+ JsonSchemaTypes.BOOLEAN,
18
+ JsonSchemaTypes.ARRAY,
19
+ JsonSchemaTypes.OBJECT,
20
+ JsonSchemaTypes.NULL
21
+ ];
22
+ const JSON_SCHEMA_METADATA_KEYS = [
23
+ "docs",
24
+ "deprecated",
25
+ "title",
26
+ "description",
27
+ "examples",
28
+ "visibility",
29
+ "hidden",
30
+ "ignore",
31
+ "internal",
32
+ "runtime",
33
+ "readOnly",
34
+ "writeOnly",
35
+ "alias",
36
+ "tags"
37
+ ];
17
38
 
18
39
  //#endregion
19
- exports.JTDTypes = JTDTypes;
40
+ exports.JSON_SCHEMA_DATA_TYPES = JSON_SCHEMA_DATA_TYPES;
41
+ exports.JSON_SCHEMA_METADATA_KEYS = JSON_SCHEMA_METADATA_KEYS;
42
+ exports.JsonSchemaTypes = JsonSchemaTypes;
@@ -1,17 +1,15 @@
1
1
  //#region src/constants.d.ts
2
- declare const JTDTypes: {
2
+ declare const JsonSchemaTypes: {
3
3
  readonly STRING: "string";
4
- readonly TIMESTAMP: "timestamp";
4
+ readonly NUMBER: "number";
5
+ readonly INTEGER: "integer";
5
6
  readonly BOOLEAN: "boolean";
6
- readonly FLOAT32: "float32";
7
- readonly FLOAT64: "float64";
8
- readonly INT8: "int8";
9
- readonly UINT8: "uint8";
10
- readonly INT16: "int16";
11
- readonly UINT16: "uint16";
12
- readonly INT32: "int32";
13
- readonly UINT32: "uint32";
7
+ readonly NULL: "null";
8
+ readonly OBJECT: "object";
9
+ readonly ARRAY: "array";
14
10
  };
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")[];
15
13
  //#endregion
16
- export { JTDTypes };
14
+ export { JSON_SCHEMA_DATA_TYPES, JSON_SCHEMA_METADATA_KEYS, JsonSchemaTypes };
17
15
  //# sourceMappingURL=constants.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.cts","names":[],"sources":["../src/constants.ts"],"mappings":";cAkBa,QAAA;EAAA"}
1
+ {"version":3,"file":"constants.d.cts","names":[],"sources":["../src/constants.ts"],"mappings":";cAoBa,eAAA;EAAA;;;;;;;;cAUA,sBAAA;AAAA,cAUA,yBAAA"}
@@ -1,17 +1,15 @@
1
1
  //#region src/constants.d.ts
2
- declare const JTDTypes: {
2
+ declare const JsonSchemaTypes: {
3
3
  readonly STRING: "string";
4
- readonly TIMESTAMP: "timestamp";
4
+ readonly NUMBER: "number";
5
+ readonly INTEGER: "integer";
5
6
  readonly BOOLEAN: "boolean";
6
- readonly FLOAT32: "float32";
7
- readonly FLOAT64: "float64";
8
- readonly INT8: "int8";
9
- readonly UINT8: "uint8";
10
- readonly INT16: "int16";
11
- readonly UINT16: "uint16";
12
- readonly INT32: "int32";
13
- readonly UINT32: "uint32";
7
+ readonly NULL: "null";
8
+ readonly OBJECT: "object";
9
+ readonly ARRAY: "array";
14
10
  };
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")[];
15
13
  //#endregion
16
- export { JTDTypes };
14
+ export { JSON_SCHEMA_DATA_TYPES, JSON_SCHEMA_METADATA_KEYS, JsonSchemaTypes };
17
15
  //# sourceMappingURL=constants.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.mts","names":[],"sources":["../src/constants.ts"],"mappings":";cAkBa,QAAA;EAAA"}
1
+ {"version":3,"file":"constants.d.mts","names":[],"sources":["../src/constants.ts"],"mappings":";cAoBa,eAAA;EAAA;;;;;;;;cAUA,sBAAA;AAAA,cAUA,yBAAA"}
@@ -1,18 +1,39 @@
1
1
  //#region src/constants.ts
2
- const JTDTypes = {
2
+ const JsonSchemaTypes = {
3
3
  STRING: "string",
4
- TIMESTAMP: "timestamp",
4
+ NUMBER: "number",
5
+ INTEGER: "integer",
5
6
  BOOLEAN: "boolean",
6
- FLOAT32: "float32",
7
- FLOAT64: "float64",
8
- INT8: "int8",
9
- UINT8: "uint8",
10
- INT16: "int16",
11
- UINT16: "uint16",
12
- INT32: "int32",
13
- UINT32: "uint32"
7
+ NULL: "null",
8
+ OBJECT: "object",
9
+ ARRAY: "array"
14
10
  };
11
+ const JSON_SCHEMA_DATA_TYPES = [
12
+ JsonSchemaTypes.STRING,
13
+ JsonSchemaTypes.NUMBER,
14
+ JsonSchemaTypes.INTEGER,
15
+ JsonSchemaTypes.BOOLEAN,
16
+ JsonSchemaTypes.ARRAY,
17
+ JsonSchemaTypes.OBJECT,
18
+ JsonSchemaTypes.NULL
19
+ ];
20
+ const JSON_SCHEMA_METADATA_KEYS = [
21
+ "docs",
22
+ "deprecated",
23
+ "title",
24
+ "description",
25
+ "examples",
26
+ "visibility",
27
+ "hidden",
28
+ "ignore",
29
+ "internal",
30
+ "runtime",
31
+ "readOnly",
32
+ "writeOnly",
33
+ "alias",
34
+ "tags"
35
+ ];
15
36
 
16
37
  //#endregion
17
- export { JTDTypes };
38
+ export { JSON_SCHEMA_DATA_TYPES, JSON_SCHEMA_METADATA_KEYS, JsonSchemaTypes };
18
39
  //# sourceMappingURL=constants.mjs.map
@@ -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\nexport const JTDTypes = {\n STRING: \"string\",\n TIMESTAMP: \"timestamp\",\n BOOLEAN: \"boolean\",\n FLOAT32: \"float32\",\n FLOAT64: \"float64\",\n INT8: \"int8\",\n UINT8: \"uint8\",\n INT16: \"int16\",\n UINT16: \"uint16\",\n INT32: \"int32\",\n UINT32: \"uint32\"\n} as const;\n"],"mappings":";AAkBA,MAAa,WAAW;CACtB,QAAQ;CACR,WAAW;CACX,SAAS;CACT,SAAS;CACT,SAAS;CACT,MAAM;CACN,OAAO;CACP,OAAO;CACP,QAAQ;CACR,OAAO;CACP,QAAQ;AACV"}
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"}
package/dist/extract.cjs CHANGED
@@ -1,25 +1,94 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
3
  const require_type_checks = require('./type-checks.cjs');
4
- const require_jtd = require('./jtd.cjs');
5
4
  const require_persistence = require('./persistence.cjs');
6
5
  const require_reflection = require('./reflection.cjs');
7
6
  const require_resolve = require('./resolve.cjs');
8
7
  let defu = require("defu");
9
8
  defu = require_runtime.__toESM(defu, 1);
10
9
  let _stryke_type_checks = require("@stryke/type-checks");
10
+ let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
11
+ let _stryke_json = require("@stryke/json");
11
12
  let _powerlines_core = require("@powerlines/core");
12
- let _powerlines_deepkit_esbuild_plugin = require("@powerlines/deepkit/esbuild-plugin");
13
+ let _powerlines_deepkit_rolldown_plugin = require("@powerlines/deepkit/rolldown-plugin");
13
14
  let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
14
15
  let _stryke_hash = require("@stryke/hash");
15
- let _stryke_json = require("@stryke/json");
16
16
  let _stryke_path_join = require("@stryke/path/join");
17
- let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
18
17
  let _stryke_zod = require("@stryke/zod");
19
18
 
20
19
  //#region src/extract.ts
20
+ function convertNestedUntypedSchema(value) {
21
+ if (require_type_checks.isUntypedSchema(value)) return convertUntypedSchemaToJsonSchema(value);
22
+ if ((0, _stryke_type_checks_is_set_object.isSetObject)(value)) {
23
+ if (require_type_checks.isUntypedInput(value)) return convertUntypedInputToJsonSchema(value);
24
+ const nested = value;
25
+ if ("$schema" in nested && require_type_checks.isUntypedSchema(nested.$schema)) return convertUntypedSchemaToJsonSchema(nested.$schema);
26
+ }
27
+ return value;
28
+ }
29
+ function convertNestedUntypedSchemaArray(value) {
30
+ if (!Array.isArray(value)) return value;
31
+ return value.map((item) => convertNestedUntypedSchema(item));
32
+ }
33
+ function convertUntypedSchemaToJsonSchema(schema) {
34
+ const source = schema;
35
+ const jsonSchema = {};
36
+ for (const [key, value] of Object.entries(source)) {
37
+ if (key === "tsType" || key === "markdownType" || key === "tags" || key === "args" || key === "resolve") continue;
38
+ if (key === "id" && (0, _stryke_type_checks.isSetString)(value)) {
39
+ jsonSchema.$id = value;
40
+ continue;
41
+ }
42
+ if (key === "properties" || key === "patternProperties" || key === "dependentSchemas" || key === "$defs" || key === "definitions") {
43
+ if (!(0, _stryke_type_checks_is_set_object.isSetObject)(value)) {
44
+ jsonSchema[key] = value;
45
+ continue;
46
+ }
47
+ jsonSchema[key] = Object.fromEntries(Object.entries(value).map(([propertyKey, propertyValue]) => [propertyKey, convertNestedUntypedSchema(propertyValue)]));
48
+ continue;
49
+ }
50
+ if (key === "items" || key === "contains" || key === "if" || key === "then" || key === "else" || key === "not" || key === "propertyNames" || key === "additionalProperties" || key === "unevaluatedProperties") {
51
+ jsonSchema[key] = convertNestedUntypedSchema(value);
52
+ continue;
53
+ }
54
+ if (key === "oneOf" || key === "anyOf" || key === "allOf") {
55
+ jsonSchema[key] = convertNestedUntypedSchemaArray(value);
56
+ continue;
57
+ }
58
+ jsonSchema[key] = value;
59
+ }
60
+ return jsonSchema;
61
+ }
62
+ function convertUntypedInputToJsonSchema(input) {
63
+ const inputObject = input;
64
+ const base = require_type_checks.isUntypedSchema(inputObject.$schema) ? convertUntypedSchemaToJsonSchema(inputObject.$schema) : {};
65
+ const properties = {};
66
+ for (const [key, value] of Object.entries(inputObject)) {
67
+ if (key.startsWith("$")) continue;
68
+ if (!(0, _stryke_type_checks_is_set_object.isSetObject)(value)) continue;
69
+ if (require_type_checks.isUntypedInput(value)) {
70
+ properties[key] = convertUntypedInputToJsonSchema(value);
71
+ continue;
72
+ }
73
+ const nested = value;
74
+ if ("$schema" in nested && require_type_checks.isUntypedSchema(nested.$schema)) {
75
+ properties[key] = convertUntypedSchemaToJsonSchema(nested.$schema);
76
+ continue;
77
+ }
78
+ if (require_type_checks.isUntypedSchema(value)) properties[key] = convertUntypedSchemaToJsonSchema(value);
79
+ }
80
+ const mergedProperties = {
81
+ ...(0, _stryke_type_checks_is_set_object.isSetObject)(base.properties) ? base.properties : {},
82
+ ...properties
83
+ };
84
+ return {
85
+ ...base,
86
+ type: base.type ?? "object",
87
+ ...Object.keys(mergedProperties).length > 0 ? { properties: mergedProperties } : {}
88
+ };
89
+ }
21
90
  /**
22
- * Creates a hash string for a given schema definition input. The function checks the type of the input and generates a hash based on its content. If the input is a Zod schema, it hashes the JSON representation of its internal definition. If the input is a Standard JSON Schema, it hashes the JSON representation of its internal standard schema. If the input is already a JSON Schema object, it hashes its JSON representation directly. If the input is a reflected Deepkit Type object, it hashes its JSON representation. The resulting hash string can be used for caching or comparison purposes.
91
+ * Creates a hash string for a given schema definition input.
23
92
  */
24
93
  function extractHash(variant, input) {
25
94
  if ((0, _stryke_type_checks.isSetString)(input)) return (0, _stryke_hash.murmurhash)({
@@ -35,10 +104,18 @@ function extractHash(variant, input) {
35
104
  variant,
36
105
  input: input["~standard"]
37
106
  });
38
- else if ((0, _stryke_json.isJsonSchemaObjectType)(input)) return (0, _stryke_hash.murmurhash)({
107
+ else if (require_type_checks.isJsonSchema(input)) return (0, _stryke_hash.murmurhash)({
39
108
  variant,
40
109
  input
41
110
  });
111
+ else if (require_type_checks.isUntypedInput(input)) return (0, _stryke_hash.murmurhash)({
112
+ variant,
113
+ input: convertUntypedInputToJsonSchema(input)
114
+ });
115
+ else if (require_type_checks.isUntypedSchema(input)) return (0, _stryke_hash.murmurhash)({
116
+ variant,
117
+ input: convertUntypedSchemaToJsonSchema(input)
118
+ });
42
119
  else if ((0, _powerlines_deepkit_vendor_type.isType)(input)) return (0, _stryke_hash.murmurhash)({
43
120
  variant,
44
121
  input: (0, _powerlines_deepkit_vendor_type.stringifyType)(input)
@@ -47,95 +124,47 @@ function extractHash(variant, input) {
47
124
  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.`);
48
125
  }
49
126
  /**
50
- * Converts a reflected Deepkit {@link @powerlines/deepkit/vendor/type#Type} into a JSON Schema (draft-07) representation.
51
- *
52
- * @remarks
53
- * This function delegates to an internal recursive walker that handles the full set of Deepkit reflection kinds.
54
- *
55
- * @param reflection - The reflected Deepkit Type to convert.
56
- * @returns A JSON Schema (draft-07) fragment representing the type, or `undefined` when no schema could be produced.
127
+ * Converts a reflected Deepkit {@link Type} into a JSON Schema (draft-07) representation.
57
128
  */
58
129
  function extractReflection(reflection) {
59
130
  if (!(0, _powerlines_deepkit_vendor_type.isType)(reflection)) return;
60
131
  return require_reflection.reflectionToJsonSchema(reflection);
61
132
  }
62
133
  /**
63
- * Extracts a JSON Type Definition (RFC 8927) schema from a given schema definition, if possible.
64
- *
65
- * @remarks
66
- * This function checks if the provided input is a Zod schema, a Standard JSON Schema, or already a JSON Schema object, extracts a JSON Schema fragment via the appropriate adapter (Zod and Standard Schema produce draft-07 fragments), and then converts that fragment into a valid JTD form suitable for AJV's JTD validator.
67
- *
68
- * @param schema - The schema definition to extract from. This can be a Zod schema, a Standard JSON Schema, or a JSON Schema object.
69
- * @returns The extracted JTD schema if successful, otherwise undefined.
134
+ * Extracts a JSON Schema from Zod, Standard Schema, untyped, or JSON Schema inputs.
70
135
  */
71
136
  function extractJsonSchema(schema) {
72
- if ((0, _stryke_type_checks_is_set_object.isSetObject)(schema) && ((0, _stryke_zod.isZod3Type)(schema) || (0, _stryke_json.isStandardJsonSchema)(schema) || (0, _stryke_json.isJsonSchemaObjectType)(schema) || require_type_checks.isUntypedInput(schema) || require_type_checks.isUntypedSchema(schema))) {
73
- let jsonSchema;
74
- if ((0, _stryke_zod.isZod3Type)(schema)) jsonSchema = (0, _stryke_zod.extractJsonSchema)(schema);
75
- else if ((0, _stryke_json.isStandardJsonSchema)(schema)) jsonSchema = schema["~standard"].jsonSchema.input({ target: "draft-2020-12" });
76
- else if (require_type_checks.isUntypedInput(schema)) jsonSchema = schema.$schema;
77
- else jsonSchema = schema;
78
- const jtd = require_jtd.jsonSchemaToJtd(jsonSchema);
79
- if (jtd) return jtd;
137
+ if ((0, _stryke_type_checks_is_set_object.isSetObject)(schema) && ((0, _stryke_zod.isZod3Type)(schema) || (0, _stryke_json.isStandardJsonSchema)(schema) || require_type_checks.isJsonSchema(schema) || require_type_checks.isUntypedInput(schema) || require_type_checks.isUntypedSchema(schema))) {
138
+ if ((0, _stryke_zod.isZod3Type)(schema)) return (0, _stryke_zod.extractJsonSchema)(schema);
139
+ if ((0, _stryke_json.isStandardJsonSchema)(schema)) return schema["~standard"].jsonSchema.input({ target: "draft-2020-12" });
140
+ if (require_type_checks.isUntypedInput(schema)) return convertUntypedInputToJsonSchema(schema);
141
+ if (require_type_checks.isUntypedSchema(schema)) return convertUntypedSchemaToJsonSchema(schema);
142
+ return schema;
80
143
  }
81
144
  }
82
- /**
83
- * Extracts a schema definition from a given input object, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object. The function checks the type of the input and attempts to extract the corresponding schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns a `Schema` containing the extracted schema and its variant if successful; otherwise, it throws an error.
84
- *
85
- * @param input - The input object to extract the schema definition from.
86
- * @returns A `Schema` containing the extracted schema and its variant if successful.
87
- * @throws An error if the input does not contain a valid schema definition.
88
- */
89
145
  function extractResolvedVariant(input) {
90
146
  if ((0, _stryke_type_checks_is_set_object.isSetObject)(input)) {
91
147
  if ((0, _stryke_zod.isZod3Type)(input)) return "zod3";
92
148
  else if ((0, _stryke_json.isStandardJsonSchema)(input)) return "standard-schema";
93
- else if (require_type_checks.isJTDSchema(input)) return "jtd-schema";
94
- else if ((0, _stryke_json.isJsonSchemaObjectType)(input)) return "json-schema";
149
+ else if (require_type_checks.isJsonSchema(input)) return "json-schema";
95
150
  else if ((0, _powerlines_deepkit_vendor_type.isType)(input)) return "reflection";
96
151
  else if (require_type_checks.isUntypedInput(input) || require_type_checks.isUntypedSchema(input)) return "untyped";
97
152
  }
98
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.`);
99
154
  }
100
- /**
101
- * Extracts a schema definition from a given input object, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, a reflected Deepkit Type object, or an Untyped schema. The function checks the type of the input and attempts to extract the corresponding schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns a `Schema` containing the extracted schema and its variant if successful; otherwise, it throws an error.
102
- *
103
- * @param input - The input object to extract the schema definition from.
104
- * @returns A `Schema` containing the extracted schema and its variant if successful.
105
- * @throws An error if the input does not contain a valid schema definition.
106
- */
107
155
  function extractVariant(input) {
108
156
  if ((0, _stryke_type_checks.isSetString)(input) || (0, _powerlines_core.isTypeDefinition)(input)) return "type-definition";
109
157
  return extractResolvedVariant(input);
110
158
  }
111
- /**
112
- * Extracts a JSON Schema object from a given schema definition input. The input can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object. The function checks the type of the input and attempts to extract the corresponding JSON Schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns the extracted JSON Schema if successful; otherwise, it throws an error.
113
- *
114
- * @param input - The schema definition input to extract the JSON Schema from. This can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a TypeScript type definition.
115
- * @param variant - The variant of the schema definition to extract.
116
- * @returns The extracted JSON Schema if successful.
117
- * @throws An error if the input does not contain a valid schema definition.
118
- */
119
159
  async function extractSchemaSchema(input, variant) {
120
160
  if (require_type_checks.isExtractedSchema(input)) return input.schema;
121
161
  const resolvedVariant = variant ?? extractResolvedVariant(input);
122
162
  let schema;
123
- if (resolvedVariant === "zod3" || resolvedVariant === "json-schema" || resolvedVariant === "standard-schema" || resolvedVariant === "untyped") {
124
- const jsonSchema = extractJsonSchema(input);
125
- if (jsonSchema) schema = require_jtd.jsonSchemaToJtd(jsonSchema);
126
- } else if (resolvedVariant === "reflection") schema = extractReflection(input);
127
- else if (resolvedVariant === "jtd-schema") schema = input;
163
+ if (resolvedVariant === "zod3" || resolvedVariant === "json-schema" || resolvedVariant === "standard-schema" || resolvedVariant === "untyped") schema = extractJsonSchema(input);
164
+ else if (resolvedVariant === "reflection") schema = extractReflection(input);
128
165
  if (schema) return schema;
129
- 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 JTD schema, an untyped schema, or a reflected Deepkit Type object.`);
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.`);
130
167
  }
131
- /**
132
- * Extracts a schema definition from a given input object, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, a JTD schema, an untyped schema, or a reflected Deepkit Type object. The function checks the type of the input and attempts to extract the corresponding schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns a `Schema` containing the extracted schema and its variant if successful; otherwise, it throws an error.
133
- *
134
- * @param variant - The variant of the schema definition to extract.
135
- * @param input - The input object to extract the schema definition from.
136
- * @returns A `Schema` containing the extracted schema and its variant if successful.
137
- * @throws An error if the input does not contain a valid schema definition.
138
- */
139
168
  function extractSource(variant, input) {
140
169
  if (variant === "zod3") return {
141
170
  hash: extractHash(variant, input),
@@ -162,40 +191,41 @@ function extractSource(variant, input) {
162
191
  variant: "reflection",
163
192
  schema: input
164
193
  };
165
- else if (variant === "jtd-schema") return {
166
- hash: extractHash(variant, input),
167
- variant: "jtd-schema",
168
- schema: input
169
- };
170
- throw new Error(`Failed to extract source information from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a JTD schema, an untyped schema, or a reflected Deepkit Type object.`);
194
+ throw new Error(`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.`);
171
195
  }
172
196
  /**
173
- * Resolves the provided entry points to their corresponding type definitions. The function accepts an array of entry points, which can be strings (file paths) or type definition objects. It processes each entry point, resolving file paths and glob patterns to find matching files. For each resolved file, it creates a type definition object and resolves it using the `resolveInput` function. The function returns an array of resolved entry type definitions.
197
+ * 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.
174
198
  *
175
199
  * @example
176
200
  * ```ts
177
201
  * // Resolve a schema definition from a file path
178
- * const schema1 = await extractSchema(context, "./schemas.ts#MySchema");
202
+ * const schema1 = await extract(context, "./schemas.ts#MySchema");
179
203
  * // Resolve a schema definition from a JSON Schema object
180
- * const schema2 = await extractSchema(context, schemaObject);
204
+ * const schema2 = await extract(context, schemaObject);
181
205
  * // Resolve a schema definition from a Zod schema
182
- * const schema3 = await extractSchema(context, zodSchema);
206
+ * const schema3 = await extract(context, zodSchema);
183
207
  * // Resolve a schema definition from a reflected Deepkit Type object
184
- * const schema4 = await extractSchema(context, reflectionType);
208
+ * const schema4 = await extract(context, reflectionType);
185
209
  * ```
186
210
  *
187
- * @param context - The plugin context used for resolving the schema definition input.
188
- * @param input - The schema definition input to extract the JSON Schema from. This can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a TypeScript type definition.
189
- * @param options - Optional overrides for the ESBuild configuration used during resolution.
190
- * @returns A promise that resolves to a {@link ExtractedSchema} containing the extracted JSON Schema and its variant, or the bytecode if JSON Schema extraction is not possible.
211
+ * @see https://github.com/colinhacks/zod
212
+ * @see https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec
213
+ * @see https://json-schema.org/
214
+ * @see https://ajv.js.org/json-type-definition.html
215
+ * @see https://deepkit.io/en/documentation/runtime-types/reflection
216
+ *
217
+ * @param context - The context object providing access to the file system and cache path.
218
+ * @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.
219
+ * @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.
220
+ * @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.
191
221
  */
192
222
  async function extractSchema(context, input, options = {}) {
193
223
  if (require_type_checks.isExtractedSchema(input)) return input;
194
224
  if (require_type_checks.isSchema(input)) return {
195
225
  ...input,
196
226
  source: {
197
- hash: extractHash("jtd-schema", input.schema),
198
- variant: "jtd-schema",
227
+ hash: extractHash("json-schema", input.schema),
228
+ variant: "json-schema",
199
229
  schema: input.schema
200
230
  }
201
231
  };
@@ -203,20 +233,19 @@ async function extractSchema(context, input, options = {}) {
203
233
  const variant = extractVariant(input);
204
234
  const hash = extractHash(variant, input);
205
235
  if (variant === "type-definition") {
206
- const resolved = await require_resolve.resolve(context, input, (0, defu.default)(options, { plugins: [(0, _powerlines_deepkit_esbuild_plugin.esbuildPlugin)(context, {
236
+ const resolved = await require_resolve.resolve(context, input, (0, defu.default)(options, { plugins: [(0, _powerlines_deepkit_rolldown_plugin.rolldownPlugin)(context, {
207
237
  reflection: "default",
208
238
  level: "all"
209
239
  })] }));
210
240
  source = extractSource(extractResolvedVariant(resolved), resolved);
211
241
  } else if ([
212
242
  "json-schema",
213
- "jtd-schema",
214
243
  "standard-schema",
215
244
  "zod3",
216
245
  "untyped",
217
246
  "reflection"
218
247
  ].includes(variant)) source = extractSource(variant, input);
219
- else throw new Error(`Invalid schema definition input "${variant}". The variant must be one of "type-definition", "json-schema", "jtd-schema", "standard-schema", "zod3", "untyped", or "reflection".`);
248
+ else throw new Error(`Invalid schema definition input "${variant}". The variant must be one of "type-definition", "json-schema", "standard-schema", "zod3", "untyped", or "reflection".`);
220
249
  return {
221
250
  variant,
222
251
  source,
@@ -225,7 +254,7 @@ async function extractSchema(context, input, options = {}) {
225
254
  };
226
255
  }
227
256
  /**
228
- * Resolves the provided entry points to their corresponding type definitions. The function accepts an array of entry points, which can be strings (file paths) or type definition objects. It processes each entry point, resolving file paths and glob patterns to find matching files. For each resolved file, it creates a type definition object and resolves it using the `resolveInput` function. The function returns an array of resolved entry type definitions.
257
+ * 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.
229
258
  *
230
259
  * @example
231
260
  * ```ts
@@ -247,10 +276,11 @@ async function extractSchema(context, input, options = {}) {
247
276
  * @see https://github.com/unjs/untyped
248
277
  * @see https://www.typescriptlang.org/docs/handbook/2/types-from-types.html
249
278
  *
250
- * @param context - The {@link Context | context} used for resolving the {@link Schema | schema} definition input.
251
- * @param input - The input object or string to extract the {@link Schema | schema} from. This can be {@link TypeDefinitionReference | a string that references a Typescript module}, a [Zod v3 schema](https://github.com/colinhacks/zod), any type that adheres to [the Standard JSON Schema specification](https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec), a [JSON Schema object](https://json-schema.org/), a [JTD schema object](https://ajv.js.org/json-type-definition.html), an [untyped schema](https://github.com/unjs/untyped), or a [TypeScript type reflection](https://deepkit.io/en/documentation/runtime-types/reflection).
252
- * @param options - Optional overrides for the [ESBuild configuration](https://esbuild.github.io/api/#general-options) used during resolution.
253
- * @returns A promise that resolves to a {@link Schema | schema} object parsed from the input.
279
+ * @param context - The context object providing access to the file system and cache path.
280
+ * @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.
281
+ * @param options - Optional overrides for the ESBuild configuration used during extraction.
282
+ * @returns A promise that resolves to the extracted and normalized schema as a JSON Schema object.
283
+ * @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.
254
284
  */
255
285
  async function extract(context, input, options = {}) {
256
286
  if (require_type_checks.isExtractedSchema(input) || require_type_checks.isSchema(input)) return input;
@@ -267,7 +297,7 @@ async function extract(context, input, options = {}) {
267
297
  };
268
298
  }
269
299
  result ??= await extractSchema(context, input, options);
270
- if (!result?.schema) 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 JTD schema, an untyped schema, or a reflected Deepkit Type object.`);
300
+ if (!result?.schema) 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.`);
271
301
  if (context.config.skipCache !== true) await require_persistence.writeSchema(context, result);
272
302
  return result;
273
303
  }