@powerlines/schema 0.11.68 → 0.11.69

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 (63) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +8 -0
  2. package/dist/bundle.cjs +8 -0
  3. package/dist/bundle.d.mts +2 -0
  4. package/dist/bundle.d.mts.map +1 -1
  5. package/dist/bundle.mjs +8 -0
  6. package/dist/bundle.mjs.map +1 -1
  7. package/dist/codegen.cjs +8 -0
  8. package/dist/codegen.d.mts +2 -0
  9. package/dist/codegen.d.mts.map +1 -1
  10. package/dist/codegen.mjs +8 -0
  11. package/dist/codegen.mjs.map +1 -1
  12. package/dist/constants.cjs +8 -0
  13. package/dist/constants.d.mts +2 -0
  14. package/dist/constants.d.mts.map +1 -1
  15. package/dist/constants.mjs +8 -0
  16. package/dist/constants.mjs.map +1 -1
  17. package/dist/extract.cjs +11 -0
  18. package/dist/extract.d.cts +3 -0
  19. package/dist/extract.d.cts.map +1 -1
  20. package/dist/extract.d.mts +5 -0
  21. package/dist/extract.d.mts.map +1 -1
  22. package/dist/extract.mjs +11 -0
  23. package/dist/extract.mjs.map +1 -1
  24. package/dist/helpers.cjs +8 -0
  25. package/dist/helpers.d.mts +2 -0
  26. package/dist/helpers.d.mts.map +1 -1
  27. package/dist/helpers.mjs +8 -0
  28. package/dist/helpers.mjs.map +1 -1
  29. package/dist/index.cjs +8 -0
  30. package/dist/index.d.mts +2 -0
  31. package/dist/index.d.mts.map +1 -1
  32. package/dist/index.mjs +8 -0
  33. package/dist/metadata.cjs +8 -0
  34. package/dist/metadata.d.mts +2 -0
  35. package/dist/metadata.d.mts.map +1 -1
  36. package/dist/metadata.mjs +8 -0
  37. package/dist/metadata.mjs.map +1 -1
  38. package/dist/persistence.cjs +8 -0
  39. package/dist/persistence.d.mts +2 -0
  40. package/dist/persistence.d.mts.map +1 -1
  41. package/dist/persistence.mjs +8 -0
  42. package/dist/persistence.mjs.map +1 -1
  43. package/dist/reflection.cjs +8 -0
  44. package/dist/reflection.d.mts +2 -0
  45. package/dist/reflection.d.mts.map +1 -1
  46. package/dist/reflection.mjs +8 -0
  47. package/dist/reflection.mjs.map +1 -1
  48. package/dist/resolve.cjs +8 -0
  49. package/dist/resolve.d.mts +2 -0
  50. package/dist/resolve.d.mts.map +1 -1
  51. package/dist/resolve.mjs +8 -0
  52. package/dist/resolve.mjs.map +1 -1
  53. package/dist/type-checks.cjs +8 -0
  54. package/dist/type-checks.d.mts +2 -0
  55. package/dist/type-checks.d.mts.map +1 -1
  56. package/dist/type-checks.mjs +8 -0
  57. package/dist/type-checks.mjs.map +1 -1
  58. package/dist/types.d.mts +2 -0
  59. package/dist/types.d.mts.map +1 -1
  60. package/dist/validate.cjs +8 -0
  61. package/dist/validate.mjs +8 -0
  62. package/dist/validate.mjs.map +1 -1
  63. package/package.json +5 -5
@@ -1,3 +1,11 @@
1
+
2
+
3
+ import __tsdown_shims_path from 'node:path'
4
+ import __tsdown_shims_url from 'node:url'
5
+
6
+ const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
7
+ const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
8
+
1
9
  //#region \0rolldown/runtime.js
2
10
  var __create = Object.create;
3
11
  var __defProp = Object.defineProperty;
package/dist/bundle.cjs CHANGED
@@ -1,3 +1,11 @@
1
+
2
+
3
+ import __tsdown_shims_path from 'node:path'
4
+ import __tsdown_shims_url from 'node:url'
5
+
6
+ const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
7
+ const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
8
+
1
9
  const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
10
  let _powerlines_core_lib_unplugin = require("@powerlines/core/lib/unplugin");
3
11
  let _powerlines_unplugin_esbuild = require("@powerlines/unplugin/esbuild");
package/dist/bundle.d.mts CHANGED
@@ -1,3 +1,5 @@
1
+ import __tsdown_shims_path from 'node:path';
2
+ import __tsdown_shims_url from 'node:url';
1
3
  import { BuildOptions, OutputFile } from "esbuild";
2
4
  import { ResolveOptions, UnresolvedContext } from "@powerlines/core";
3
5
  import { DeepPartial } from "@stryke/types/base";
@@ -1 +1 @@
1
- {"version":3,"file":"bundle.d.mts","names":[],"sources":["../src/bundle.ts"],"mappings":";;;;;KAiCY,aAAA,GAAgB,WAAA,CAAY,YAAA;EACtC,IAAA;EACA,OAAA,GAAU,WAAA,CAAY,cAAA;AAAA;;;;;;;;;iBAWF,MAAA,kBAAwB,iBAAA,CAAA,CAC5C,OAAA,EAAS,QAAA,EACT,IAAA,UACA,OAAA,GAAS,aAAA,GACR,OAAA,CAAQ,UAAA"}
1
+ {"version":3,"file":"bundle.d.mts","names":[],"sources":["../src/bundle.ts"],"mappings":";;;;;;;KAiCY,aAAA,GAAgB,WAAA,CAAY,YAAA;EACtC,IAAA;EACA,OAAA,GAAU,WAAA,CAAY,cAAA;AAAA;;;;;;AAFxB;;;iBAasB,MAAA,kBAAwB,iBAAA,CAAA,CAC5C,OAAA,EAAS,QAAA,EACT,IAAA,UACA,OAAA,GAAS,aAAA,GACR,OAAA,CAAQ,UAAA"}
package/dist/bundle.mjs CHANGED
@@ -1,3 +1,11 @@
1
+
2
+
3
+ import __tsdown_shims_path from 'node:path'
4
+ import __tsdown_shims_url from 'node:url'
5
+
6
+ const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
7
+ const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
8
+
1
9
  import { createUnpluginResolver } from "@powerlines/core/lib/unplugin";
2
10
  import { resolveOptions } from "@powerlines/unplugin/esbuild";
3
11
  import { omit } from "@stryke/helpers/omit";
@@ -1 +1 @@
1
- {"version":3,"file":"bundle.mjs","names":[],"sources":["../src/bundle.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 {\n CreateUnpluginResolverOptions,\n ResolveOptions,\n UnresolvedContext\n} from \"@powerlines/core\";\nimport { createUnpluginResolver } from \"@powerlines/core/lib/unplugin\";\nimport { resolveOptions } from \"@powerlines/unplugin/esbuild\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { findFileName } from \"@stryke/path/file-path-fns\";\nimport { DeepPartial } from \"@stryke/types/base\";\nimport defu from \"defu\";\nimport type { BuildOptions } from \"esbuild\";\nimport { build, OutputFile } from \"esbuild\";\nimport { createEsbuildPlugin } from \"unplugin\";\n\nexport type BundleOptions = DeepPartial<BuildOptions> & {\n name?: string;\n resolve?: DeepPartial<ResolveOptions>;\n};\n\n/**\n * Bundle a type definition to a module.\n *\n * @param context - The context object containing the environment paths.\n * @param file - The file path to bundle.\n * @param options - Optional overrides for the ESBuild configuration.\n * @returns A promise that resolves to the bundled module.\n */\nexport async function bundle<TContext extends UnresolvedContext>(\n context: TContext,\n file: string,\n options: BundleOptions = {}\n): Promise<OutputFile> {\n const path = await context.fs.resolve(file);\n if (!path || !context.fs.existsSync(path)) {\n throw new Error(\n `Module not found: \"${file}\". Please check the path and try again.`\n );\n }\n\n const result = await build(\n defu(\n {\n entryPoints: [path],\n write: false,\n sourcemap: false,\n splitting: false,\n treeShaking: true,\n bundle: true,\n packages: \"bundle\",\n platform: \"node\",\n logLevel: \"silent\",\n ...omit(options, [\"name\", \"resolve\"])\n },\n resolveOptions(context),\n {\n plugins: [\n createEsbuildPlugin(\n createUnpluginResolver(context, {\n name: options.name ?? `${findFileName(file)} Bundler`,\n prefix: false,\n overrides: defu(\n options.resolve ?? {},\n { skipNodeModulesBundle: false },\n context.config.resolve\n ) as CreateUnpluginResolverOptions[\"overrides\"],\n silenceHookLogging: true\n })\n )()\n ]\n }\n )\n );\n if (result.errors.length > 0) {\n throw new Error(\n `Failed to bundle ${file}: ${result.errors\n .map(error => error.text)\n .join(\", \")}`\n );\n }\n if (result.warnings.length > 0) {\n context.warn(\n `Warnings while bundling ${file}: ${result.warnings\n .map(warning => warning.text)\n .join(\", \")}`\n );\n }\n if (!result.outputFiles || result.outputFiles.filter(Boolean).length === 0) {\n throw new Error(\n `No output files generated for ${\n file\n }. Please check the configuration and try again.`\n );\n }\n\n return result.outputFiles.filter(Boolean)[0]!;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA8CA,eAAsB,OACpB,SACA,MACA,UAAyB,CAAC,GACL;CACrB,MAAM,OAAO,MAAM,QAAQ,GAAG,QAAQ,IAAI;CAC1C,IAAI,CAAC,QAAQ,CAAC,QAAQ,GAAG,WAAW,IAAI,GACtC,MAAM,IAAI,MACR,sBAAsB,KAAK,wCAC7B;CAGF,MAAM,SAAS,MAAM,MACnB,KACE;EACE,aAAa,CAAC,IAAI;EAClB,OAAO;EACP,WAAW;EACX,WAAW;EACX,aAAa;EACb,QAAQ;EACR,UAAU;EACV,UAAU;EACV,UAAU;EACV,GAAG,KAAK,SAAS,CAAC,QAAQ,SAAS,CAAC;CACtC,GACA,eAAe,OAAO,GACtB,EACE,SAAS,CACP,oBACE,uBAAuB,SAAS;EAC9B,MAAM,QAAQ,QAAQ,GAAG,aAAa,IAAI,EAAE;EAC5C,QAAQ;EACR,WAAW,KACT,QAAQ,WAAW,CAAC,GACpB,EAAE,uBAAuB,MAAM,GAC/B,QAAQ,OAAO,OACjB;EACA,oBAAoB;CACtB,CAAC,CACH,EAAE,CACJ,EACF,CACF,CACF;CACA,IAAI,OAAO,OAAO,SAAS,GACzB,MAAM,IAAI,MACR,oBAAoB,KAAK,IAAI,OAAO,OACjC,KAAI,UAAS,MAAM,IAAI,EACvB,KAAK,IAAI,GACd;CAEF,IAAI,OAAO,SAAS,SAAS,GAC3B,QAAQ,KACN,2BAA2B,KAAK,IAAI,OAAO,SACxC,KAAI,YAAW,QAAQ,IAAI,EAC3B,KAAK,IAAI,GACd;CAEF,IAAI,CAAC,OAAO,eAAe,OAAO,YAAY,OAAO,OAAO,EAAE,WAAW,GACvE,MAAM,IAAI,MACR,iCACE,KACD,gDACH;CAGF,OAAO,OAAO,YAAY,OAAO,OAAO,EAAE;AAC5C"}
1
+ {"version":3,"file":"bundle.mjs","names":[],"sources":["../src/bundle.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 {\n CreateUnpluginResolverOptions,\n ResolveOptions,\n UnresolvedContext\n} from \"@powerlines/core\";\nimport { createUnpluginResolver } from \"@powerlines/core/lib/unplugin\";\nimport { resolveOptions } from \"@powerlines/unplugin/esbuild\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { findFileName } from \"@stryke/path/file-path-fns\";\nimport { DeepPartial } from \"@stryke/types/base\";\nimport defu from \"defu\";\nimport type { BuildOptions } from \"esbuild\";\nimport { build, OutputFile } from \"esbuild\";\nimport { createEsbuildPlugin } from \"unplugin\";\n\nexport type BundleOptions = DeepPartial<BuildOptions> & {\n name?: string;\n resolve?: DeepPartial<ResolveOptions>;\n};\n\n/**\n * Bundle a type definition to a module.\n *\n * @param context - The context object containing the environment paths.\n * @param file - The file path to bundle.\n * @param options - Optional overrides for the ESBuild configuration.\n * @returns A promise that resolves to the bundled module.\n */\nexport async function bundle<TContext extends UnresolvedContext>(\n context: TContext,\n file: string,\n options: BundleOptions = {}\n): Promise<OutputFile> {\n const path = await context.fs.resolve(file);\n if (!path || !context.fs.existsSync(path)) {\n throw new Error(\n `Module not found: \"${file}\". Please check the path and try again.`\n );\n }\n\n const result = await build(\n defu(\n {\n entryPoints: [path],\n write: false,\n sourcemap: false,\n splitting: false,\n treeShaking: true,\n bundle: true,\n packages: \"bundle\",\n platform: \"node\",\n logLevel: \"silent\",\n ...omit(options, [\"name\", \"resolve\"])\n },\n resolveOptions(context),\n {\n plugins: [\n createEsbuildPlugin(\n createUnpluginResolver(context, {\n name: options.name ?? `${findFileName(file)} Bundler`,\n prefix: false,\n overrides: defu(\n options.resolve ?? {},\n { skipNodeModulesBundle: false },\n context.config.resolve\n ) as CreateUnpluginResolverOptions[\"overrides\"],\n silenceHookLogging: true\n })\n )()\n ]\n }\n )\n );\n if (result.errors.length > 0) {\n throw new Error(\n `Failed to bundle ${file}: ${result.errors\n .map(error => error.text)\n .join(\", \")}`\n );\n }\n if (result.warnings.length > 0) {\n context.warn(\n `Warnings while bundling ${file}: ${result.warnings\n .map(warning => warning.text)\n .join(\", \")}`\n );\n }\n if (!result.outputFiles || result.outputFiles.filter(Boolean).length === 0) {\n throw new Error(\n `No output files generated for ${\n file\n }. Please check the configuration and try again.`\n );\n }\n\n return result.outputFiles.filter(Boolean)[0]!;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,eAAsB,OACpB,SACA,MACA,UAAyB,CAAC,GACL;CACrB,MAAM,OAAO,MAAM,QAAQ,GAAG,QAAQ,IAAI;CAC1C,IAAI,CAAC,QAAQ,CAAC,QAAQ,GAAG,WAAW,IAAI,GACtC,MAAM,IAAI,MACR,sBAAsB,KAAK,wCAC7B;CAGF,MAAM,SAAS,MAAM,MACnB,KACE;EACE,aAAa,CAAC,IAAI;EAClB,OAAO;EACP,WAAW;EACX,WAAW;EACX,aAAa;EACb,QAAQ;EACR,UAAU;EACV,UAAU;EACV,UAAU;EACV,GAAG,KAAK,SAAS,CAAC,QAAQ,SAAS,CAAC;CACtC,GACA,eAAe,OAAO,GACtB,EACE,SAAS,CACP,oBACE,uBAAuB,SAAS;EAC9B,MAAM,QAAQ,QAAQ,GAAG,aAAa,IAAI,EAAE;EAC5C,QAAQ;EACR,WAAW,KACT,QAAQ,WAAW,CAAC,GACpB,EAAE,uBAAuB,MAAM,GAC/B,QAAQ,OAAO,OACjB;EACA,oBAAoB;CACtB,CAAC,CACH,EAAE,CACJ,EACF,CACF,CACF;CACA,IAAI,OAAO,OAAO,SAAS,GACzB,MAAM,IAAI,MACR,oBAAoB,KAAK,IAAI,OAAO,OACjC,KAAI,UAAS,MAAM,IAAI,EACvB,KAAK,IAAI,GACd;CAEF,IAAI,OAAO,SAAS,SAAS,GAC3B,QAAQ,KACN,2BAA2B,KAAK,IAAI,OAAO,SACxC,KAAI,YAAW,QAAQ,IAAI,EAC3B,KAAK,IAAI,GACd;CAEF,IAAI,CAAC,OAAO,eAAe,OAAO,YAAY,OAAO,OAAO,EAAE,WAAW,GACvE,MAAM,IAAI,MACR,iCACE,KACD,gDACH;CAGF,OAAO,OAAO,YAAY,OAAO,OAAO,EAAE;AAC5C"}
package/dist/codegen.cjs CHANGED
@@ -1,3 +1,11 @@
1
+
2
+
3
+ import __tsdown_shims_path from 'node:path'
4
+ import __tsdown_shims_url from 'node:url'
5
+
6
+ const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
7
+ const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
8
+
1
9
  const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
10
  const require_metadata = require('./metadata.cjs');
3
11
  const require_type_checks = require('./type-checks.cjs');
@@ -1,3 +1,5 @@
1
+ import __tsdown_shims_path from 'node:path';
2
+ import __tsdown_shims_url from 'node:url';
1
3
  import { JsonSchema, JsonSchemaType } from "./types.mjs";
2
4
  import standaloneCode from "ajv/dist/standalone/index.js";
3
5
 
@@ -1 +1 @@
1
- {"version":3,"file":"codegen.d.mts","names":[],"sources":["../src/codegen.ts"],"mappings":";;;;;;AAiDA;iBAAgB,cAAA,CACd,KAAA,YACA,IAAA,GAAO,cAAc;;;;iBAsBP,aAAA,CAAc,MAAmB,GAAV,UAAU;;;AAtBjB;AAsBhC;;;iBAsFgB,iBAAA,CAAkB,KAAA,aAAkB,cAAc;AAtFjB;AAsFjD;;AAtFiD,iBA2G3B,YAAA,CACpB,OAAA,EAAS,UAAA,EACT,YAAA,GAAe,UAAA,QAAkB,cAAA,OAAkB,OAAA"}
1
+ {"version":3,"file":"codegen.d.mts","names":[],"sources":["../src/codegen.ts"],"mappings":";;;;;;;;;iBAiDgB,cAAA,CACd,KAAA,YACA,IAAA,GAAO,cAAc;;;;iBAsBP,aAAA,CAAc,MAAmB,GAAV,UAAU;;;AAxBjD;;;;iBA8GgB,iBAAA,CAAkB,KAAA,aAAkB,cAAc;;;;iBAqB5C,YAAA,CACpB,OAAA,EAAS,UAAA,EACT,YAAA,GAAe,UAAA,QAAkB,cAAA,OAAkB,OAAA"}
package/dist/codegen.mjs CHANGED
@@ -1,3 +1,11 @@
1
+
2
+
3
+ import __tsdown_shims_path from 'node:path'
4
+ import __tsdown_shims_url from 'node:url'
5
+
6
+ const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
7
+ const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
8
+
1
9
  import { getPrimarySchemaType } from "./metadata.mjs";
2
10
  import { isJsonSchema, isJsonSchemaObject } from "./type-checks.mjs";
3
11
  import { getPropertiesList, isSchemaNullable } from "./helpers.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"codegen.mjs","names":["isUndefined","isNull","isBoolean","isNumber","isSetString"],"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 { isInteger, isObject, isString } from \"@stryke/type-checks\";\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 standaloneCode from \"ajv/dist/standalone\";\nimport { getPropertiesList, isSchemaNullable } from \"./helpers\";\nimport { getPrimarySchemaType } from \"./metadata\";\nimport { isJsonSchema, isJsonSchemaObject } from \"./type-checks\";\nimport { JsonSchema, JsonSchemaType } from \"./types\";\nimport { getValidator } from \"./validate\";\n\ninterface JsonSchemaObjectView {\n $ref?: string;\n type?: JsonSchemaType | readonly JsonSchemaType[];\n enum?: readonly unknown[];\n const?: unknown;\n items?: JsonSchema;\n properties?: Record<string, JsonSchema>;\n additionalProperties?: boolean | JsonSchema;\n required?: string[];\n oneOf?: JsonSchema[];\n anyOf?: JsonSchema[];\n allOf?: JsonSchema[];\n}\n\n/**\n * Stringifies a value for generated TypeScript code.\n */\nexport function stringifyValue(\n value?: unknown,\n type?: JsonSchemaType | 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 : type === \"string\" || type === \"object\" || type === \"array\"\n ? JSON.stringify(value)\n : String(value);\n}\n\n/**\n * Stringifies a JSON Schema fragment into a TypeScript-like type string.\n */\nexport function stringifyType(schema?: JsonSchema): string {\n if (!schema) {\n return \"unknown\";\n }\n\n if (typeof schema === \"boolean\") {\n return schema ? \"unknown\" : \"never\";\n }\n\n const objectSchema = schema as JsonSchemaObjectView;\n\n if (isSetString(objectSchema.$ref)) {\n const match = /^#\\/(?:definitions|\\$defs)\\/(.+)$/.exec(objectSchema.$ref);\n\n return match?.[1] ?? objectSchema.$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 (objectSchema.type === \"array\" && Array.isArray(objectSchema.enum)) {\n const enumValues = objectSchema.enum as readonly unknown[];\n\n return enumValues\n .map((value: unknown) => JSON.stringify(value))\n .join(\" | \");\n }\n\n if (objectSchema.const !== undefined) {\n return JSON.stringify(objectSchema.const);\n }\n\n if (objectSchema.type === \"array\" || objectSchema.items) {\n return `${stringifyType(objectSchema.items)}[]`;\n }\n\n if (\n objectSchema.type === \"object\" ||\n objectSchema.properties ||\n objectSchema.additionalProperties\n ) {\n if (isJsonSchema(objectSchema.additionalProperties)) {\n return `{ [key: string]: ${stringifyType(objectSchema.additionalProperties)} }`;\n }\n\n if (isJsonSchemaObject(objectSchema)) {\n const required = objectSchema.required ?? [];\n\n return `{ ${getPropertiesList(objectSchema)\n .map(property => {\n const suffix =\n !required.includes(property.name) || isSchemaNullable(property)\n ? `${!required.includes(property.name) ? \"?\" : \"\"}${isSchemaNullable(property) ? \" | null\" : \"\"}`\n : \"\";\n\n return `${property.name}${suffix}: ${stringifyType(property)}`;\n })\n .join(\";\\n\")} }`;\n }\n }\n\n if (objectSchema.oneOf || objectSchema.anyOf) {\n return (objectSchema.oneOf ?? objectSchema.anyOf ?? [])\n .map(branch => stringifyType(branch))\n .join(\" | \");\n }\n\n if (objectSchema.allOf) {\n return \"object\";\n }\n\n return \"unknown\";\n}\n\n/**\n * Returns a string type representation of a value based on its type and an optional JSON Schema primitive type hint.\n *\n * @param value - The value whose type is to be represented as a string.\n * @returns A string representation of the value's type, which may be influenced by the provided JSON Schema primitive type hint. The function handles various JavaScript types and formats them accordingly, including special handling for `undefined`, `null`, booleans, numbers (with formatting), strings, objects, and arrays. If a specific type hint is provided, it will take precedence in determining the string representation of the value.\n */\nexport function getJsonSchemaType(value?: unknown): JsonSchemaType | undefined {\n return isNull(value)\n ? \"null\"\n : isBoolean(value)\n ? \"boolean\"\n : isInteger(value)\n ? \"integer\"\n : isNumber(value)\n ? \"number\"\n : isString(value)\n ? \"string\"\n : isObject(value)\n ? \"object\"\n : Array.isArray(value)\n ? \"array\"\n : undefined;\n}\n\n/**\n * Generates standalone JSON Schema validation code using Ajv.\n */\nexport async function generateCode(\n schemas: JsonSchema,\n refsOrFuncts?: Parameters<typeof standaloneCode>[1]\n) {\n const ajv = getValidator(schemas);\n\n return standaloneCode(ajv, refsOrFuncts);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiDA,SAAgB,eACd,OACA,MACQ;CACR,OAAOA,cAAY,KAAK,IACpB,cACAC,SAAO,KAAK,IACV,SACA,SAAS,aAAaC,YAAU,KAAK,IACnC,OAAO,OAAO,KAAK,CAAC,IACpB,SAAS,YAAYC,WAAS,KAAK,IACjC,OAAO,WAAW,OAAO,KAAK,CAAC,EAAE,eAAe,QAAW,EACzD,uBAAuB,GACzB,CAAC,IACD,SAAS,YACP,OAAO,SAAS,OA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AE;EACjB;CACF;CAEA,IAAI,aAAa,SAAS,aAAa,OACrC,QAAQ,aAAa,SAAS,aAAa,SAAS,CAAC,GAClD,KAAI,WAAU,cAAc,MAAM,CAAC,EACnC,KAAK,KAAK;CAGf,IAAI,aAAa,OACf,OAAO;CAGT,OAAO;AACT;;;;;;;AAQA,SAAgB,kBAAkB,OAA6C;CAC7E,OAAOH,SAAO,KAAK,IACf,SACAC,YAAU,KAAK,IACb,YACA,UAAU,KAAK,IACb,YACAC,WAAS,KAAK,IACZ,WACA,SAAS,KAAK,IACZ,WACA,SAAS,KAAK,IACZ,WACA,MAAM,QAAQ,KAAK,IACjB,UACA;AAClB;;;;AAKA,eAAsB,aACpB,SACA,cACA;CAGA,OAAO,eAFK,aAAa,OAED,GAAG,YAAY;AACzC"}
1
+ {"version":3,"file":"codegen.mjs","names":["isUndefined","isNull","isBoolean","isNumber","isSetString"],"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 { isInteger, isObject, isString } from \"@stryke/type-checks\";\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 standaloneCode from \"ajv/dist/standalone\";\nimport { getPropertiesList, isSchemaNullable } from \"./helpers\";\nimport { getPrimarySchemaType } from \"./metadata\";\nimport { isJsonSchema, isJsonSchemaObject } from \"./type-checks\";\nimport { JsonSchema, JsonSchemaType } from \"./types\";\nimport { getValidator } from \"./validate\";\n\ninterface JsonSchemaObjectView {\n $ref?: string;\n type?: JsonSchemaType | readonly JsonSchemaType[];\n enum?: readonly unknown[];\n const?: unknown;\n items?: JsonSchema;\n properties?: Record<string, JsonSchema>;\n additionalProperties?: boolean | JsonSchema;\n required?: string[];\n oneOf?: JsonSchema[];\n anyOf?: JsonSchema[];\n allOf?: JsonSchema[];\n}\n\n/**\n * Stringifies a value for generated TypeScript code.\n */\nexport function stringifyValue(\n value?: unknown,\n type?: JsonSchemaType | 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 : type === \"string\" || type === \"object\" || type === \"array\"\n ? JSON.stringify(value)\n : String(value);\n}\n\n/**\n * Stringifies a JSON Schema fragment into a TypeScript-like type string.\n */\nexport function stringifyType(schema?: JsonSchema): string {\n if (!schema) {\n return \"unknown\";\n }\n\n if (typeof schema === \"boolean\") {\n return schema ? \"unknown\" : \"never\";\n }\n\n const objectSchema = schema as JsonSchemaObjectView;\n\n if (isSetString(objectSchema.$ref)) {\n const match = /^#\\/(?:definitions|\\$defs)\\/(.+)$/.exec(objectSchema.$ref);\n\n return match?.[1] ?? objectSchema.$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 (objectSchema.type === \"array\" && Array.isArray(objectSchema.enum)) {\n const enumValues = objectSchema.enum as readonly unknown[];\n\n return enumValues\n .map((value: unknown) => JSON.stringify(value))\n .join(\" | \");\n }\n\n if (objectSchema.const !== undefined) {\n return JSON.stringify(objectSchema.const);\n }\n\n if (objectSchema.type === \"array\" || objectSchema.items) {\n return `${stringifyType(objectSchema.items)}[]`;\n }\n\n if (\n objectSchema.type === \"object\" ||\n objectSchema.properties ||\n objectSchema.additionalProperties\n ) {\n if (isJsonSchema(objectSchema.additionalProperties)) {\n return `{ [key: string]: ${stringifyType(objectSchema.additionalProperties)} }`;\n }\n\n if (isJsonSchemaObject(objectSchema)) {\n const required = objectSchema.required ?? [];\n\n return `{ ${getPropertiesList(objectSchema)\n .map(property => {\n const suffix =\n !required.includes(property.name) || isSchemaNullable(property)\n ? `${!required.includes(property.name) ? \"?\" : \"\"}${isSchemaNullable(property) ? \" | null\" : \"\"}`\n : \"\";\n\n return `${property.name}${suffix}: ${stringifyType(property)}`;\n })\n .join(\";\\n\")} }`;\n }\n }\n\n if (objectSchema.oneOf || objectSchema.anyOf) {\n return (objectSchema.oneOf ?? objectSchema.anyOf ?? [])\n .map(branch => stringifyType(branch))\n .join(\" | \");\n }\n\n if (objectSchema.allOf) {\n return \"object\";\n }\n\n return \"unknown\";\n}\n\n/**\n * Returns a string type representation of a value based on its type and an optional JSON Schema primitive type hint.\n *\n * @param value - The value whose type is to be represented as a string.\n * @returns A string representation of the value's type, which may be influenced by the provided JSON Schema primitive type hint. The function handles various JavaScript types and formats them accordingly, including special handling for `undefined`, `null`, booleans, numbers (with formatting), strings, objects, and arrays. If a specific type hint is provided, it will take precedence in determining the string representation of the value.\n */\nexport function getJsonSchemaType(value?: unknown): JsonSchemaType | undefined {\n return isNull(value)\n ? \"null\"\n : isBoolean(value)\n ? \"boolean\"\n : isInteger(value)\n ? \"integer\"\n : isNumber(value)\n ? \"number\"\n : isString(value)\n ? \"string\"\n : isObject(value)\n ? \"object\"\n : Array.isArray(value)\n ? \"array\"\n : undefined;\n}\n\n/**\n * Generates standalone JSON Schema validation code using Ajv.\n */\nexport async function generateCode(\n schemas: JsonSchema,\n refsOrFuncts?: Parameters<typeof standaloneCode>[1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AoB,EAAE;EAG9E,IAAI,mBAAmB,YAAY,GAAG;GACpC,MAAM,WAAW,aAAa,YAAY,CAAC;GAE3C,OAAO,KAAK,kBAAkB,YAAY,EACvC,KAAI,aAAY;IACf,MAAM,SACJ,CAAC,SAAS,SAAS,SAAS,IAAI,KAAK,iBAAiB,QAAQ,IAC1D,GAAG,CAAC,SAAS,SAAS,SAAS,IAAI,IAAI,MAAM,KAAK,iBAAiB,QAAQ,IAAI,YAAY,OAC3F;IAEN,OAAO,GAAG,SAAS,OAAO,OAAO,IAAI,cAAc,QAAQ;GAC7D,CAAC,EACA,KAAK,KAAK,EAAE;EACjB;CACF;CAEA,IAAI,aAAa,SAAS,aAAa,OACrC,QAAQ,aAAa,SAAS,aAAa,SAAS,CAAC,GAClD,KAAI,WAAU,cAAc,MAAM,CAAC,EACnC,KAAK,KAAK;CAGf,IAAI,aAAa,OACf,OAAO;CAGT,OAAO;AACT;;;;;;;AAQA,SAAgB,kBAAkB,OAA6C;CAC7E,OAAOH,SAAO,KAAK,IACf,SACAC,YAAU,KAAK,IACb,YACA,UAAU,KAAK,IACb,YACAC,WAAS,KAAK,IACZ,WACA,SAAS,KAAK,IACZ,WACA,SAAS,KAAK,IACZ,WACA,MAAM,QAAQ,KAAK,IACjB,UACA;AAClB;;;;AAKA,eAAsB,aACpB,SACA,cACA;CAGA,OAAO,eAFK,aAAa,OAED,GAAG,YAAY;AACzC"}
@@ -1,4 +1,12 @@
1
1
 
2
+
3
+ import __tsdown_shims_path from 'node:path'
4
+ import __tsdown_shims_url from 'node:url'
5
+
6
+ const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
7
+ const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
8
+
9
+
2
10
  //#region src/constants.ts
3
11
  const VALID_SOURCE_FILE_EXTENSIONS = [
4
12
  "ts",
@@ -1,3 +1,5 @@
1
+ import __tsdown_shims_path from 'node:path';
2
+ import __tsdown_shims_url from 'node:url';
1
3
  //#region src/constants.d.ts
2
4
  declare const VALID_SOURCE_FILE_EXTENSIONS: string[];
3
5
  declare const JsonSchemaTypeNames: {
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.mts","names":[],"sources":["../src/constants.ts"],"mappings":";cAoBa,4BAAA;AAAA,cAiBA,mBAAA;EAAA;;;;;;;;cAUA,2BAAA;AAAA,cAQA,iBAAA;AAAA,cAMA,yBAAA"}
1
+ {"version":3,"file":"constants.d.mts","names":[],"sources":["../src/constants.ts"],"mappings":";;;cAoBa,4BAAA;AAAA,cAiBA,mBAAA;EAAA;;;;;;;;cAUA,2BAAA;AAAA,cAQA,iBAAA;AAAA,cAMA,yBAAA"}
@@ -1,3 +1,11 @@
1
+
2
+
3
+ import __tsdown_shims_path from 'node:path'
4
+ import __tsdown_shims_url from 'node:url'
5
+
6
+ const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
7
+ const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
8
+
1
9
  //#region src/constants.ts
2
10
  const VALID_SOURCE_FILE_EXTENSIONS = [
3
11
  "ts",
@@ -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 type { JsonSchemaMetadataKeywords } from \"./types\";\n\nexport const VALID_SOURCE_FILE_EXTENSIONS = [\n \"ts\",\n \"cts\",\n \"mts\",\n \"tsx\",\n \"js\",\n \"cjs\",\n \"mjs\",\n \"jsx\",\n \"json\",\n \"jsonc\",\n \"json5\",\n \"yaml\",\n \"yml\",\n \"toml\"\n] as const as string[];\n\nexport const JsonSchemaTypeNames = {\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_PRIMITIVE_TYPES = [\n JsonSchemaTypeNames.STRING,\n JsonSchemaTypeNames.NUMBER,\n JsonSchemaTypeNames.INTEGER,\n JsonSchemaTypeNames.BOOLEAN,\n JsonSchemaTypeNames.NULL\n] as const;\n\nexport const JSON_SCHEMA_TYPES = [\n ...JSON_SCHEMA_PRIMITIVE_TYPES,\n JsonSchemaTypeNames.ARRAY,\n JsonSchemaTypeNames.OBJECT\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 JsonSchemaMetadataKeywords>;\n"],"mappings":";AAoBA,MAAa,+BAA+B;CAC1C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,sBAAsB;CACjC,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,SAAS;CACT,MAAM;CACN,QAAQ;CACR,OAAO;AACT;AAEA,MAAa,8BAA8B;CACzC,oBAAoB;CACpB,oBAAoB;CACpB,oBAAoB;CACpB,oBAAoB;CACpB,oBAAoB;AACtB;AAEA,MAAa,oBAAoB;CAC/B,GAAG;CACH,oBAAoB;CACpB,oBAAoB;AACtB;AAEA,MAAa,4BAA4B;CACvC;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 type { JsonSchemaMetadataKeywords } from \"./types\";\n\nexport const VALID_SOURCE_FILE_EXTENSIONS = [\n \"ts\",\n \"cts\",\n \"mts\",\n \"tsx\",\n \"js\",\n \"cjs\",\n \"mjs\",\n \"jsx\",\n \"json\",\n \"jsonc\",\n \"json5\",\n \"yaml\",\n \"yml\",\n \"toml\"\n] as const as string[];\n\nexport const JsonSchemaTypeNames = {\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_PRIMITIVE_TYPES = [\n JsonSchemaTypeNames.STRING,\n JsonSchemaTypeNames.NUMBER,\n JsonSchemaTypeNames.INTEGER,\n JsonSchemaTypeNames.BOOLEAN,\n JsonSchemaTypeNames.NULL\n] as const;\n\nexport const JSON_SCHEMA_TYPES = [\n ...JSON_SCHEMA_PRIMITIVE_TYPES,\n JsonSchemaTypeNames.ARRAY,\n JsonSchemaTypeNames.OBJECT\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 JsonSchemaMetadataKeywords>;\n"],"mappings":";;;;;;;;;AAoBA,MAAa,+BAA+B;CAC1C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,sBAAsB;CACjC,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,SAAS;CACT,MAAM;CACN,QAAQ;CACR,OAAO;AACT;AAEA,MAAa,8BAA8B;CACzC,oBAAoB;CACpB,oBAAoB;CACpB,oBAAoB;CACpB,oBAAoB;CACpB,oBAAoB;AACtB;AAEA,MAAa,oBAAoB;CAC/B,GAAG;CACH,oBAAoB;CACpB,oBAAoB;AACtB;AAEA,MAAa,4BAA4B;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
package/dist/extract.cjs CHANGED
@@ -1,3 +1,11 @@
1
+
2
+
3
+ import __tsdown_shims_path from 'node:path'
4
+ import __tsdown_shims_url from 'node:url'
5
+
6
+ const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
7
+ const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
8
+
1
9
  const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
10
  const require_constants = require('./constants.cjs');
3
11
  const require_type_checks = require('./type-checks.cjs');
@@ -247,6 +255,9 @@ function extractReflection(reflection) {
247
255
  }
248
256
  /**
249
257
  * Extracts a JSON Schema from Zod, Standard Schema, Valibot, untyped, or JSON Schema inputs.
258
+ *
259
+ * @param schema - The schema input to extract a JSON Schema from.
260
+ * @returns The extracted JSON Schema, or `undefined` if the input is not a supported schema type.
250
261
  */
251
262
  function extractJsonSchema(schema) {
252
263
  if ((0, _stryke_type_checks_is_set_object.isSetObject)(schema)) {
@@ -21,6 +21,9 @@ declare function extractHash(variant: SchemaInputVariant, input: SchemaInput): s
21
21
  declare function extractReflection(reflection: Type): JsonSchema | undefined;
22
22
  /**
23
23
  * Extracts a JSON Schema from Zod, Standard Schema, Valibot, untyped, or JSON Schema inputs.
24
+ *
25
+ * @param schema - The schema input to extract a JSON Schema from.
26
+ * @returns The extracted JSON Schema, or `undefined` if the input is not a supported schema type.
24
27
  */
25
28
  declare function extractJsonSchema(schema: unknown): JsonSchema | undefined;
26
29
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"extract.d.cts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;;;;AA8OA;;;;iBAAgB,gBAAA,CAAiB,MAAA,EAAQ,UAAA,GAAa,UAAU;;;;iBAgMhD,WAAA,CACd,OAAA,EAAS,kBAAA,EACT,KAAA,EAAO,WAAW;AAFpB;;;AAAA,iBA2CgB,iBAAA,CAAkB,UAAA,EAAY,IAAA,GAAO,UAAU;;;;iBAW/C,iBAAA,CAAkB,MAAA,YAAkB,UAAU;;AApD1C;AAyCpB;;;;;iBAiDgB,sBAAA,CACd,KAAA,EAAO,iBAAA,GACN,mBAAmB;;;AAnDyC;AAW/D;;;iBAoEgB,cAAA,CAAe,KAAA,EAAO,WAAA,GAAc,kBAAkB;AApER;AAsC9D;;;;;;;AAtC8D,iBAoFxC,aAAA,CACpB,KAAA,EAAO,iBAAA,EACP,OAAA,GAAU,kBAAA,GACT,OAAA,CAAQ,UAAA;AA/CW;AA4BtB;;;;;;;AA5BsB,iBAoFN,aAAA,CACd,OAAA,EAAS,mBAAA,EACT,KAAA,EAAO,iBAAA,GACN,YAAA;AA3DmE;AAgBtE;;;;;;;;;;;;;;;;AAGqB;AAqCrB;;;;;;;;;AAxDsE,iBAkIhD,uBAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,aAAA,GACR,OAAA,CAAQ,eAAA;;;;;AA3EI;AAuEf;;;;;;;;;;;;;;;;;;;AAI0B;AA+H1B;;;;;;;iBAAsB,OAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,aAAA,GACR,OAAA,CAAQ,MAAA"}
1
+ {"version":3,"file":"extract.d.cts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;;;;AAmPA;;;;iBAAgB,gBAAA,CAAiB,MAAA,EAAQ,UAAA,GAAa,UAAU;;;;iBAgMhD,WAAA,CACd,OAAA,EAAS,kBAAA,EACT,KAAA,EAAO,WAAW;AAFpB;;;AAAA,iBA2CgB,iBAAA,CAAkB,UAAA,EAAY,IAAA,GAAO,UAAU;;;;;;AAzC3C;iBAuDJ,iBAAA,CAAkB,MAAA,YAAkB,UAAU;;;;;;;;iBAoC9C,sBAAA,CACd,KAAA,EAAO,iBAAA,GACN,mBAAmB;AAtCtB;;;;AAA8D;AAoC9D;AApCA,iBAkEgB,cAAA,CAAe,KAAA,EAAO,WAAA,GAAc,kBAAkB;;;;;;;AA5BhD;AA4BtB;iBAgBsB,aAAA,CACpB,KAAA,EAAO,iBAAA,EACP,OAAA,GAAU,kBAAA,GACT,OAAA,CAAQ,UAAA;;;;;;;AAnB2D;AAgBtE;iBAwCgB,aAAA,CACd,OAAA,EAAS,mBAAA,EACT,KAAA,EAAO,iBAAA,GACN,YAAA;;;;;;;;;;;;;;;AAxCkB;AAqCrB;;;;;;;;;;;;iBA0EsB,uBAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,aAAA,GACR,OAAA,CAAQ,eAAA;;AA3EI;AAuEf;;;;;;;;;;;;;;;;;;;AAI0B;AA+H1B;;;;;;;;;;iBAAsB,OAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,aAAA,GACR,OAAA,CAAQ,MAAA"}
@@ -1,3 +1,5 @@
1
+ import __tsdown_shims_path from 'node:path';
2
+ import __tsdown_shims_url from 'node:url';
1
3
  import { BundleOptions } from "./bundle.mjs";
2
4
  import { ExtractedSchema, JsonSchema, Schema, SchemaInput, SchemaInputVariant, SchemaSource, SchemaSourceInput, SchemaSourceVariant } from "./types.mjs";
3
5
  import { Context } from "@powerlines/core";
@@ -21,6 +23,9 @@ declare function extractHash(variant: SchemaInputVariant, input: SchemaInput): s
21
23
  declare function extractReflection(reflection: Type): JsonSchema | undefined;
22
24
  /**
23
25
  * Extracts a JSON Schema from Zod, Standard Schema, Valibot, untyped, or JSON Schema inputs.
26
+ *
27
+ * @param schema - The schema input to extract a JSON Schema from.
28
+ * @returns The extracted JSON Schema, or `undefined` if the input is not a supported schema type.
24
29
  */
25
30
  declare function extractJsonSchema(schema: unknown): JsonSchema | undefined;
26
31
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"extract.d.mts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;;;;AA8OA;;;;iBAAgB,gBAAA,CAAiB,MAAA,EAAQ,UAAA,GAAa,UAAU;;;;iBAgMhD,WAAA,CACd,OAAA,EAAS,kBAAA,EACT,KAAA,EAAO,WAAW;AAFpB;;;AAAA,iBA2CgB,iBAAA,CAAkB,UAAA,EAAY,IAAA,GAAO,UAAU;;;;iBAW/C,iBAAA,CAAkB,MAAA,YAAkB,UAAU;;AApD1C;AAyCpB;;;;;iBAiDgB,sBAAA,CACd,KAAA,EAAO,iBAAA,GACN,mBAAmB;;;AAnDyC;AAW/D;;;iBAoEgB,cAAA,CAAe,KAAA,EAAO,WAAA,GAAc,kBAAkB;AApER;AAsC9D;;;;;;;AAtC8D,iBAoFxC,aAAA,CACpB,KAAA,EAAO,iBAAA,EACP,OAAA,GAAU,kBAAA,GACT,OAAA,CAAQ,UAAA;AA/CW;AA4BtB;;;;;;;AA5BsB,iBAoFN,aAAA,CACd,OAAA,EAAS,mBAAA,EACT,KAAA,EAAO,iBAAA,GACN,YAAA;AA3DmE;AAgBtE;;;;;;;;;;;;;;;;AAGqB;AAqCrB;;;;;;;;;AAxDsE,iBAkIhD,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A,EAAO,WAAA,EACP,OAAA,GAAS,aAAA,GACR,OAAA,CAAQ,MAAA"}
package/dist/extract.mjs CHANGED
@@ -1,3 +1,11 @@
1
+
2
+
3
+ import __tsdown_shims_path from 'node:path'
4
+ import __tsdown_shims_url from 'node:url'
5
+
6
+ const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
7
+ const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
8
+
1
9
  import { VALID_SOURCE_FILE_EXTENSIONS } from "./constants.mjs";
2
10
  import { isJsonSchema, isJsonSchemaObject, isSchema, isSchemaWithSource, isUntypedInput, isUntypedInputStrict, isUntypedSchema, isUntypedSchemaStrict, isValibotSchema } from "./type-checks.mjs";
3
11
  import { getCacheDirectory, writeSchema } from "./persistence.mjs";
@@ -245,6 +253,9 @@ function extractReflection(reflection) {
245
253
  }
246
254
  /**
247
255
  * Extracts a JSON Schema from Zod, Standard Schema, Valibot, untyped, or JSON Schema inputs.
256
+ *
257
+ * @param schema - The schema input to extract a JSON Schema from.
258
+ * @returns The extracted JSON Schema, or `undefined` if the input is not a supported schema type.
248
259
  */
249
260
  function extractJsonSchema$1(schema) {
250
261
  if (isSetObject$1(schema)) {
@@ -1 +1 @@
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 { isFileReference } from \"@powerlines/core\";\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport { deserializeType, isType, SerializedType, stringifyType, Type } from \"@powerlines/deepkit/vendor/type\";\nimport { StandardJSONSchemaV1 } from \"@standard-schema/spec\";\nimport { extractFileReference } from \"@stryke/convert/extract-file-reference\";\nimport { murmurhash } from \"@stryke/hash\";\nimport { deepClone } from \"@stryke/helpers/deep-clone\";\nimport { isStandardJsonSchema } from \"@stryke/json\";\nimport { findFileExtensionSafe } from \"@stryke/path/find\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { list } from \"@stryke/string-format/list\";\nimport { isSetString } from \"@stryke/type-checks\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { FileReferenceInput } from \"@stryke/types\";\nimport {\n extractJsonSchema as extractJsonSchemaZod,\n isZod3Type\n} from \"@stryke/zod\";\nimport { toJsonSchema } from \"@valibot/to-json-schema\";\nimport defu from \"defu\";\nimport * as z3 from \"zod/v3\";\nimport { BundleOptions } from \"./bundle\";\nimport { VALID_SOURCE_FILE_EXTENSIONS } from \"./constants\";\nimport { getCacheDirectory, writeSchema } from \"./persistence\";\nimport { reflectionToJsonSchema } from \"./reflection\";\nimport { resolve } from \"./resolve\";\nimport {\n isJsonSchema,\n isJsonSchemaObject,\n isSchema,\n isSchemaWithSource,\n isUntypedInput,\n isUntypedInputStrict,\n isUntypedSchema,\n isUntypedSchemaStrict,\n isValibotSchema\n} from \"./type-checks\";\nimport {\n ExtractedSchema,\n JsonSchema,\n Schema,\n SchemaInput,\n SchemaInputVariant,\n SchemaSource,\n SchemaSourceInput,\n SchemaSourceVariant,\n UntypedInputObject,\n UntypedSchema,\n ValibotSchema\n} from \"./types\";\nimport { SerializedTypes } from \"../../../base/deepkit/schemas/reflection\";\n\nconst SCHEMA_BUNDLE_BASE_URI = \"https://powerlines.invalid/\";\n\nfunction normalizeUri(uri: string): string {\n return uri.endsWith(\"#\") ? uri.slice(0, -1) : uri;\n}\n\nfunction stripUriFragment(uri: string): string {\n const hashIndex = uri.indexOf(\"#\");\n\n return hashIndex >= 0 ? uri.slice(0, hashIndex) : uri;\n}\n\nfunction escapeJsonPointerToken(token: string): string {\n return token.replaceAll(\"~\", \"~0\").replaceAll(\"/\", \"~1\");\n}\n\nfunction toJsonPointer(path: string[]): string {\n if (path.length === 0) {\n return \"\";\n }\n\n return `/${path.map(segment => escapeJsonPointerToken(segment)).join(\"/\")}`;\n}\n\nfunction resolveUri(reference: string, baseUri: string): string {\n try {\n return normalizeUri(new URL(reference, baseUri).toString());\n } catch {\n return normalizeUri(reference);\n }\n}\n\nfunction collectReferenceTargets(\n value: unknown,\n path: string[],\n baseUri: string,\n uriToPointer: Map<string, string>,\n dynamicUriToFragment: Map<string, string>\n): void {\n if (!isSetObject(value)) {\n return;\n }\n\n const schema = value as Record<string, unknown>;\n const pointer = toJsonPointer(path);\n\n const currentBaseUri = isSetString(schema.$id)\n ? resolveUri(schema.$id, baseUri)\n : baseUri;\n\n const currentDocumentUri = stripUriFragment(currentBaseUri);\n\n uriToPointer.set(currentBaseUri, pointer);\n uriToPointer.set(currentDocumentUri, pointer);\n\n if (isSetString(schema.$anchor)) {\n uriToPointer.set(`${currentDocumentUri}#${schema.$anchor}`, pointer);\n }\n\n if (isSetString(schema.$dynamicAnchor)) {\n const dynamicTarget = `${currentDocumentUri}#${schema.$dynamicAnchor}`;\n uriToPointer.set(dynamicTarget, pointer);\n dynamicUriToFragment.set(dynamicTarget, `#${schema.$dynamicAnchor}`);\n }\n\n for (const [key, child] of Object.entries(schema)) {\n if (Array.isArray(child)) {\n child.forEach((entry, index) => {\n collectReferenceTargets(\n entry,\n [...path, key, String(index)],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n });\n continue;\n }\n\n collectReferenceTargets(\n child,\n [...path, key],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n }\n}\n\nfunction rewriteReferenceTargets(\n value: unknown,\n path: string[],\n baseUri: string,\n uriToPointer: Map<string, string>,\n dynamicUriToFragment: Map<string, string>\n): void {\n if (!isSetObject(value)) {\n return;\n }\n\n const schema = value as Record<string, unknown>;\n\n const currentBaseUri = isSetString(schema.$id)\n ? resolveUri(schema.$id, baseUri)\n : baseUri;\n\n if (isSetString(schema.$ref)) {\n const resolvedRefUri = resolveUri(schema.$ref, currentBaseUri);\n const pointer =\n uriToPointer.get(resolvedRefUri) ??\n uriToPointer.get(stripUriFragment(resolvedRefUri));\n\n if (pointer !== undefined) {\n schema.$ref = pointer.length > 0 ? `#${pointer}` : \"#\";\n }\n }\n\n if (isSetString(schema.$dynamicRef)) {\n const resolvedDynamicRefUri = resolveUri(\n schema.$dynamicRef,\n currentBaseUri\n );\n const dynamicFragment = dynamicUriToFragment.get(resolvedDynamicRefUri);\n\n if (dynamicFragment) {\n schema.$dynamicRef = dynamicFragment;\n } else {\n const pointer =\n uriToPointer.get(resolvedDynamicRefUri) ??\n uriToPointer.get(stripUriFragment(resolvedDynamicRefUri));\n\n if (pointer !== undefined) {\n schema.$dynamicRef = pointer.length > 0 ? `#${pointer}` : \"#\";\n }\n }\n }\n\n for (const [key, child] of Object.entries(schema)) {\n if (Array.isArray(child)) {\n child.forEach((entry, index) => {\n rewriteReferenceTargets(\n entry,\n [...path, key, String(index)],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n });\n continue;\n }\n\n rewriteReferenceTargets(\n child,\n [...path, key],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n }\n}\n\n/**\n * Bundles all external references in a JSON Schema into a single schema document by collecting all reference targets and rewriting the references to point to the bundled definitions. This ensures that the resulting schema is self-contained and can be used independently without relying on external documents.\n *\n * @param schema - The JSON Schema to bundle references for.\n * @returns A new JSON Schema with all references bundled and rewritten to point to the bundled definitions.\n */\nexport function bundleReferences(schema: JsonSchema): JsonSchema {\n if (!isSetObject(schema)) {\n return schema;\n }\n\n const bundledSchema = deepClone(schema) as Record<string, unknown>;\n const baseUri = isSetString(bundledSchema.$id)\n ? resolveUri(bundledSchema.$id, SCHEMA_BUNDLE_BASE_URI)\n : SCHEMA_BUNDLE_BASE_URI;\n\n const uriToPointer = new Map<string, string>();\n const dynamicUriToFragment = new Map<string, string>();\n\n collectReferenceTargets(\n bundledSchema,\n [],\n baseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n\n rewriteReferenceTargets(\n bundledSchema,\n [],\n baseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n\n return bundledSchema;\n}\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(schema: unknown): JsonSchema {\n return toJsonSchema(schema as never, {\n target: \"draft-2020-12\"\n }) as JsonSchema;\n}\n\nfunction convertUntypedSchemaToJsonSchema(\n schema: UntypedSchema | Record<string, unknown>\n): JsonSchema {\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;\n}\n\nfunction convertUntypedInputToJsonSchema(\n input: UntypedInputObject\n): JsonSchema {\n const inputObject = input as Record<string, unknown>;\n const base = isUntypedSchema(inputObject.$schema)\n ? convertUntypedSchemaToJsonSchema(inputObject.$schema)\n : {};\n const properties: Record<string, JsonSchema> = {};\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(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(nested.$schema);\n continue;\n }\n\n if (isUntypedSchema(value)) {\n properties[key] = convertUntypedSchemaToJsonSchema(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) ? base.properties : {};\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(\n variant: SchemaInputVariant,\n input: SchemaInput\n): string {\n if (isSetString(input)) {\n return murmurhash({ variant, input });\n } else if (typeof input === \"boolean\") {\n return murmurhash({ variant, input });\n } else if (isSetObject(input)) {\n if (isZod3Type(input)) {\n return murmurhash({ variant, input: input._def });\n } else if (isType(input)) {\n return murmurhash({ variant, input: stringifyType(input) });\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 }\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-2020-12) representation.\n */\nexport function extractReflection(reflection: Type): JsonSchema | undefined {\n if (!isType(reflection)) {\n return undefined;\n }\n\n return reflectionToJsonSchema(reflection);\n}\n\n/**\n * Extracts a JSON Schema from Zod, Standard Schema, Valibot, untyped, or JSON Schema inputs.\n */\nexport function extractJsonSchema(schema: unknown): JsonSchema | undefined {\n if (isSetObject(schema)) {\n if (isZod3Type(schema)) {\n return extractJsonSchemaZod(schema, {\n target: \"draft-2020-12\"\n }) as JsonSchema;\n }\n if (isUntypedInputStrict(schema)) {\n return convertUntypedInputToJsonSchema(schema);\n }\n if (isUntypedSchemaStrict(schema)) {\n return convertUntypedSchemaToJsonSchema(schema);\n }\n if (isStandardJsonSchema(schema)) {\n return schema[\"~standard\"].jsonSchema.input({\n target: \"draft-2020-12\"\n });\n }\n if (isValibotSchema(schema)) {\n return convertValibotSchemaToJsonSchema(schema);\n }\n if (isJsonSchema(schema)) {\n return schema;\n }\n }\n\n return undefined;\n}\n\n\n\n/**\n * Resolves the concrete source variant for a schema source input.\n *\n * @param input - The schema source input to inspect.\n * @returns The resolved schema source variant.\n * @throws Will throw an error when the input cannot be mapped to a supported source variant.\n */\nexport function extractResolvedVariant(\n input: SchemaSourceInput\n): SchemaSourceVariant {\n if (isSetObject(input)) {\n if (isZod3Type(input)) {\n return \"zod3\";\n } else if (isType(input)) {\n return \"reflection\";\n } else if (isUntypedInputStrict(input) || isUntypedSchemaStrict(input)) {\n return \"untyped\";\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 }\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\n/**\n * Determines the top-level input variant for schema extraction.\n *\n * @param input - The schema input to classify.\n * @returns The resolved schema input variant.\n */\nexport function extractVariant(input: SchemaInput): SchemaInputVariant {\n if (isSetString(input) || isFileReference(input)) {\n return \"file-reference\";\n }\n\n return extractResolvedVariant(input as SchemaSourceInput);\n}\n\n/**\n * Extracts and normalizes a JSON Schema from a concrete schema source input.\n *\n * @param input - The schema source input to extract from.\n * @param variant - Optional source variant override. When omitted, the variant is inferred from the input.\n * @returns A promise that resolves to a bundled JSON Schema.\n * @throws Will throw an error if no valid JSON Schema can be extracted from the input.\n */\nexport async function extractSchema(\n input: SchemaSourceInput,\n variant?: SchemaInputVariant\n): Promise<JsonSchema> {\n if (isSchemaWithSource(input)) {\n return input.schema;\n }\n\n const resolvedVariant = variant ?? extractResolvedVariant(input);\n\n let schema: JsonSchema | undefined;\n if (\n resolvedVariant === \"zod3\" ||\n resolvedVariant === \"json-schema\" ||\n resolvedVariant === \"standard-schema\" ||\n resolvedVariant === \"untyped\" ||\n resolvedVariant === \"valibot\"\n ) {\n schema = extractJsonSchema(input);\n } else if (resolvedVariant === \"reflection\") {\n schema = extractReflection(input as Type);\n }\n\n if (schema) {\n return bundleReferences(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\n/**\n * Builds source metadata for a schema input using a known source variant.\n *\n * @param variant - The schema source variant associated with the input.\n * @param input - The schema source input to wrap.\n * @returns The normalized schema source payload, including the source hash and variant.\n * @throws Will throw an error if the provided variant is unsupported.\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 Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a 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 Rolldown 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://zod.dev/\n * @see https://valibot.dev/\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 Valibot schema, any Standard JSON Schema type, a plain 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 Rolldown 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 extractSchemaWithSource(\n context: Context,\n input: SchemaInput,\n options: BundleOptions = {}\n): Promise<ExtractedSchema> {\n if (isSchemaWithSource(input)) {\n return input;\n }\n\n if (isSchema(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 === \"file-reference\") {\n const fileReference = extractFileReference(input as FileReferenceInput);\n if (!fileReference) {\n throw new Error(\n `Failed to extract a valid file reference from the provided input \"${JSON.stringify(\n input\n )}\". Please ensure that the input is correctly formatted as a file reference (e.g. \"./schema.ts#MySchema\") and that the file exists at the specified path.`\n );\n }\n\n const extension = findFileExtensionSafe(fileReference.file);\n if (extension && !VALID_SOURCE_FILE_EXTENSIONS.includes(extension)) {\n throw new Error(\n `The provided schema file input \"${\n fileReference.file\n }\" has an invalid file extension (.${\n extension\n }). Please ensure that the file has one of the following extensions: ${list(\n VALID_SOURCE_FILE_EXTENSIONS,\n { conjunction: \"or\" }\n )}.`\n );\n }\n\n let resolved = await resolve<SchemaSourceInput>(\n context,\n input as FileReferenceInput,\n defu(options, {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n level: \"all\"\n })\n ]\n })\n );\n\n try {\n const type = deserializeType(resolved as SerializedType[]);\n if (isType(type)) {\n resolved = type;\n }\n } catch {\n // If deserialization fails, we assume the resolved output is not a reflected type and proceed with it as-is.\n }\n\n source = extractSource(extractResolvedVariant(resolved), resolved);\n } else if (\n [\n \"json-schema\",\n \"standard-schema\",\n \"zod3\",\n \"untyped\",\n \"valibot\",\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 \"file-reference\", \"json-schema\", \"standard-schema\", \"zod3\", \"valibot\", \"untyped\", or \"reflection\".`\n );\n }\n\n return {\n variant,\n source,\n schema: await extractSchema(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 Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a 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 Rolldown 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 Valibot schema\n * const schema4 = await extract(context, valibotSchema);\n * // Resolve a schema definition from a reflected Deepkit Type object\n * const schema5 = await extract(context, reflectionType);\n * ```\n *\n * @see https://zod.dev/\n * @see https://valibot.dev/\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 Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a reflected Deepkit Type object.\n * @param options - Optional overrides for the Rolldown 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(\n context: Context,\n input: SchemaInput,\n options: BundleOptions = {}\n): Promise<Schema> {\n if (isSchemaWithSource(input) || isSchema(input)) {\n return input;\n }\n\n let result: Schema | 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\n };\n }\n }\n\n result ??= await extractSchemaWithSource(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 Valibot schema, any Standard JSON Schema type, a plain 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":";;;;;;;;;;;;;;;;;;;;;;AAuEA,MAAM,yBAAyB;AAE/B,SAAS,aAAa,KAAqB;CACzC,OAAO,IAAI,SAAS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AO,gBAAgB,QAA4B;GACzD,IAAI,OAAO,IAAI,GACb,WAAW;EAEf,QAAQ,CAER;EAEA,SAAS,cAAc,uBAAuB,QAAQ,GAAG,QAAQ;CACnE,OAAO,IACL;EACE;EACA;EACA;EACA;EACA;EACA;CACF,EAAE,SAAS,OAAO,GAElB,SAAS,cAAc,SAAS,KAA0B;MAE1D,MAAM,IAAI,MACR,oCACE,QACD,iIACH;CAGF,OAAO;EACL;EACA;EACA,QAAQ,MAAM,cAAc,OAAO,QAAQ,OAAO,OAAO;EACzD;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,eAAsB,QACpB,SACA,OACA,UAAyB,CAAC,GACT;CACjB,IAAI,mBAAmB,KAAK,KAAK,SAAS,KAAK,GAC7C,OAAO;CAGT,IAAI;CAEJ,MAAM,UAAU,eAAe,KAAK;CACpC,MAAM,OAAO,YAAY,SAAS,KAAK;CAEvC,MAAM,gBAAgB,UAAU,kBAAkB,OAAO,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,wBAAwB,SAAS,OAAO,OAAO;CAChE,IAAI,CAAC,QAAQ,QACX,MAAM,IAAI,MACR,+NACF;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 { isFileReference } from \"@powerlines/core\";\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport {\n deserializeType,\n isType,\n SerializedType,\n stringifyType,\n Type\n} from \"@powerlines/deepkit/vendor/type\";\nimport { StandardJSONSchemaV1 } from \"@standard-schema/spec\";\nimport { extractFileReference } from \"@stryke/convert/extract-file-reference\";\nimport { murmurhash } from \"@stryke/hash\";\nimport { deepClone } from \"@stryke/helpers/deep-clone\";\nimport { isStandardJsonSchema } from \"@stryke/json\";\nimport { findFileExtensionSafe } from \"@stryke/path/find\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { list } from \"@stryke/string-format/list\";\nimport { isSetString } from \"@stryke/type-checks\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { FileReferenceInput } from \"@stryke/types\";\nimport {\n extractJsonSchema as extractJsonSchemaZod,\n isZod3Type\n} from \"@stryke/zod\";\nimport { toJsonSchema } from \"@valibot/to-json-schema\";\nimport defu from \"defu\";\nimport * as z3 from \"zod/v3\";\nimport { BundleOptions } from \"./bundle\";\nimport { VALID_SOURCE_FILE_EXTENSIONS } from \"./constants\";\nimport { getCacheDirectory, writeSchema } from \"./persistence\";\nimport { reflectionToJsonSchema } from \"./reflection\";\nimport { resolve } from \"./resolve\";\nimport {\n isJsonSchema,\n isJsonSchemaObject,\n isSchema,\n isSchemaWithSource,\n isUntypedInput,\n isUntypedInputStrict,\n isUntypedSchema,\n isUntypedSchemaStrict,\n isValibotSchema\n} from \"./type-checks\";\nimport {\n ExtractedSchema,\n JsonSchema,\n Schema,\n SchemaInput,\n SchemaInputVariant,\n SchemaSource,\n SchemaSourceInput,\n SchemaSourceVariant,\n UntypedInputObject,\n UntypedSchema,\n ValibotSchema\n} from \"./types\";\n\nconst SCHEMA_BUNDLE_BASE_URI = \"https://powerlines.invalid/\";\n\nfunction normalizeUri(uri: string): string {\n return uri.endsWith(\"#\") ? uri.slice(0, -1) : uri;\n}\n\nfunction stripUriFragment(uri: string): string {\n const hashIndex = uri.indexOf(\"#\");\n\n return hashIndex >= 0 ? uri.slice(0, hashIndex) : uri;\n}\n\nfunction escapeJsonPointerToken(token: string): string {\n return token.replaceAll(\"~\", \"~0\").replaceAll(\"/\", \"~1\");\n}\n\nfunction toJsonPointer(path: string[]): string {\n if (path.length === 0) {\n return \"\";\n }\n\n return `/${path.map(segment => escapeJsonPointerToken(segment)).join(\"/\")}`;\n}\n\nfunction resolveUri(reference: string, baseUri: string): string {\n try {\n return normalizeUri(new URL(reference, baseUri).toString());\n } catch {\n return normalizeUri(reference);\n }\n}\n\nfunction collectReferenceTargets(\n value: unknown,\n path: string[],\n baseUri: string,\n uriToPointer: Map<string, string>,\n dynamicUriToFragment: Map<string, string>\n): void {\n if (!isSetObject(value)) {\n return;\n }\n\n const schema = value as Record<string, unknown>;\n const pointer = toJsonPointer(path);\n\n const currentBaseUri = isSetString(schema.$id)\n ? resolveUri(schema.$id, baseUri)\n : baseUri;\n\n const currentDocumentUri = stripUriFragment(currentBaseUri);\n\n uriToPointer.set(currentBaseUri, pointer);\n uriToPointer.set(currentDocumentUri, pointer);\n\n if (isSetString(schema.$anchor)) {\n uriToPointer.set(`${currentDocumentUri}#${schema.$anchor}`, pointer);\n }\n\n if (isSetString(schema.$dynamicAnchor)) {\n const dynamicTarget = `${currentDocumentUri}#${schema.$dynamicAnchor}`;\n uriToPointer.set(dynamicTarget, pointer);\n dynamicUriToFragment.set(dynamicTarget, `#${schema.$dynamicAnchor}`);\n }\n\n for (const [key, child] of Object.entries(schema)) {\n if (Array.isArray(child)) {\n child.forEach((entry, index) => {\n collectReferenceTargets(\n entry,\n [...path, key, String(index)],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n });\n continue;\n }\n\n collectReferenceTargets(\n child,\n [...path, key],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n }\n}\n\nfunction rewriteReferenceTargets(\n value: unknown,\n path: string[],\n baseUri: string,\n uriToPointer: Map<string, string>,\n dynamicUriToFragment: Map<string, string>\n): void {\n if (!isSetObject(value)) {\n return;\n }\n\n const schema = value as Record<string, unknown>;\n\n const currentBaseUri = isSetString(schema.$id)\n ? resolveUri(schema.$id, baseUri)\n : baseUri;\n\n if (isSetString(schema.$ref)) {\n const resolvedRefUri = resolveUri(schema.$ref, currentBaseUri);\n const pointer =\n uriToPointer.get(resolvedRefUri) ??\n uriToPointer.get(stripUriFragment(resolvedRefUri));\n\n if (pointer !== undefined) {\n schema.$ref = pointer.length > 0 ? `#${pointer}` : \"#\";\n }\n }\n\n if (isSetString(schema.$dynamicRef)) {\n const resolvedDynamicRefUri = resolveUri(\n schema.$dynamicRef,\n currentBaseUri\n );\n const dynamicFragment = dynamicUriToFragment.get(resolvedDynamicRefUri);\n\n if (dynamicFragment) {\n schema.$dynamicRef = dynamicFragment;\n } else {\n const pointer =\n uriToPointer.get(resolvedDynamicRefUri) ??\n uriToPointer.get(stripUriFragment(resolvedDynamicRefUri));\n\n if (pointer !== undefined) {\n schema.$dynamicRef = pointer.length > 0 ? `#${pointer}` : \"#\";\n }\n }\n }\n\n for (const [key, child] of Object.entries(schema)) {\n if (Array.isArray(child)) {\n child.forEach((entry, index) => {\n rewriteReferenceTargets(\n entry,\n [...path, key, String(index)],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n });\n continue;\n }\n\n rewriteReferenceTargets(\n child,\n [...path, key],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n }\n}\n\n/**\n * Bundles all external references in a JSON Schema into a single schema document by collecting all reference targets and rewriting the references to point to the bundled definitions. This ensures that the resulting schema is self-contained and can be used independently without relying on external documents.\n *\n * @param schema - The JSON Schema to bundle references for.\n * @returns A new JSON Schema with all references bundled and rewritten to point to the bundled definitions.\n */\nexport function bundleReferences(schema: JsonSchema): JsonSchema {\n if (!isSetObject(schema)) {\n return schema;\n }\n\n const bundledSchema = deepClone(schema) as Record<string, unknown>;\n const baseUri = isSetString(bundledSchema.$id)\n ? resolveUri(bundledSchema.$id, SCHEMA_BUNDLE_BASE_URI)\n : SCHEMA_BUNDLE_BASE_URI;\n\n const uriToPointer = new Map<string, string>();\n const dynamicUriToFragment = new Map<string, string>();\n\n collectReferenceTargets(\n bundledSchema,\n [],\n baseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n\n rewriteReferenceTargets(\n bundledSchema,\n [],\n baseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n\n return bundledSchema;\n}\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(schema: unknown): JsonSchema {\n return toJsonSchema(schema as never, {\n target: \"draft-2020-12\"\n }) as JsonSchema;\n}\n\nfunction convertUntypedSchemaToJsonSchema(\n schema: UntypedSchema | Record<string, unknown>\n): JsonSchema {\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;\n}\n\nfunction convertUntypedInputToJsonSchema(\n input: UntypedInputObject\n): JsonSchema {\n const inputObject = input as Record<string, unknown>;\n const base = isUntypedSchema(inputObject.$schema)\n ? convertUntypedSchemaToJsonSchema(inputObject.$schema)\n : {};\n const properties: Record<string, JsonSchema> = {};\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(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(nested.$schema);\n continue;\n }\n\n if (isUntypedSchema(value)) {\n properties[key] = convertUntypedSchemaToJsonSchema(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) ? base.properties : {};\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(\n variant: SchemaInputVariant,\n input: SchemaInput\n): string {\n if (isSetString(input)) {\n return murmurhash({ variant, input });\n } else if (typeof input === \"boolean\") {\n return murmurhash({ variant, input });\n } else if (isSetObject(input)) {\n if (isZod3Type(input)) {\n return murmurhash({ variant, input: input._def });\n } else if (isType(input)) {\n return murmurhash({ variant, input: stringifyType(input) });\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 }\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-2020-12) representation.\n */\nexport function extractReflection(reflection: Type): JsonSchema | undefined {\n if (!isType(reflection)) {\n return undefined;\n }\n\n return reflectionToJsonSchema(reflection);\n}\n\n/**\n * Extracts a JSON Schema from Zod, Standard Schema, Valibot, untyped, or JSON Schema inputs.\n *\n * @param schema - The schema input to extract a JSON Schema from.\n * @returns The extracted JSON Schema, or `undefined` if the input is not a supported schema type.\n */\nexport function extractJsonSchema(schema: unknown): JsonSchema | undefined {\n if (isSetObject(schema)) {\n if (isZod3Type(schema)) {\n return extractJsonSchemaZod(schema, {\n target: \"draft-2020-12\"\n }) as JsonSchema;\n }\n if (isUntypedInputStrict(schema)) {\n return convertUntypedInputToJsonSchema(schema);\n }\n if (isUntypedSchemaStrict(schema)) {\n return convertUntypedSchemaToJsonSchema(schema);\n }\n if (isStandardJsonSchema(schema)) {\n return schema[\"~standard\"].jsonSchema.input({\n target: \"draft-2020-12\"\n });\n }\n if (isValibotSchema(schema)) {\n return convertValibotSchemaToJsonSchema(schema);\n }\n if (isJsonSchema(schema)) {\n return schema;\n }\n }\n\n return undefined;\n}\n\n/**\n * Resolves the concrete source variant for a schema source input.\n *\n * @param input - The schema source input to inspect.\n * @returns The resolved schema source variant.\n * @throws Will throw an error when the input cannot be mapped to a supported source variant.\n */\nexport function extractResolvedVariant(\n input: SchemaSourceInput\n): SchemaSourceVariant {\n if (isSetObject(input)) {\n if (isZod3Type(input)) {\n return \"zod3\";\n } else if (isType(input)) {\n return \"reflection\";\n } else if (isUntypedInputStrict(input) || isUntypedSchemaStrict(input)) {\n return \"untyped\";\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 }\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\n/**\n * Determines the top-level input variant for schema extraction.\n *\n * @param input - The schema input to classify.\n * @returns The resolved schema input variant.\n */\nexport function extractVariant(input: SchemaInput): SchemaInputVariant {\n if (isSetString(input) || isFileReference(input)) {\n return \"file-reference\";\n }\n\n return extractResolvedVariant(input as SchemaSourceInput);\n}\n\n/**\n * Extracts and normalizes a JSON Schema from a concrete schema source input.\n *\n * @param input - The schema source input to extract from.\n * @param variant - Optional source variant override. When omitted, the variant is inferred from the input.\n * @returns A promise that resolves to a bundled JSON Schema.\n * @throws Will throw an error if no valid JSON Schema can be extracted from the input.\n */\nexport async function extractSchema(\n input: SchemaSourceInput,\n variant?: SchemaInputVariant\n): Promise<JsonSchema> {\n if (isSchemaWithSource(input)) {\n return input.schema;\n }\n\n const resolvedVariant = variant ?? extractResolvedVariant(input);\n\n let schema: JsonSchema | undefined;\n if (\n resolvedVariant === \"zod3\" ||\n resolvedVariant === \"json-schema\" ||\n resolvedVariant === \"standard-schema\" ||\n resolvedVariant === \"untyped\" ||\n resolvedVariant === \"valibot\"\n ) {\n schema = extractJsonSchema(input);\n } else if (resolvedVariant === \"reflection\") {\n schema = extractReflection(input as Type);\n }\n\n if (schema) {\n return bundleReferences(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\n/**\n * Builds source metadata for a schema input using a known source variant.\n *\n * @param variant - The schema source variant associated with the input.\n * @param input - The schema source input to wrap.\n * @returns The normalized schema source payload, including the source hash and variant.\n * @throws Will throw an error if the provided variant is unsupported.\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 Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a 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 Rolldown 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://zod.dev/\n * @see https://valibot.dev/\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 Valibot schema, any Standard JSON Schema type, a plain 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 Rolldown 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 extractSchemaWithSource(\n context: Context,\n input: SchemaInput,\n options: BundleOptions = {}\n): Promise<ExtractedSchema> {\n if (isSchemaWithSource(input)) {\n return input;\n }\n\n if (isSchema(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 === \"file-reference\") {\n const fileReference = extractFileReference(input as FileReferenceInput);\n if (!fileReference) {\n throw new Error(\n `Failed to extract a valid file reference from the provided input \"${JSON.stringify(\n input\n )}\". Please ensure that the input is correctly formatted as a file reference (e.g. \"./schema.ts#MySchema\") and that the file exists at the specified path.`\n );\n }\n\n const extension = findFileExtensionSafe(fileReference.file);\n if (extension && !VALID_SOURCE_FILE_EXTENSIONS.includes(extension)) {\n throw new Error(\n `The provided schema file input \"${\n fileReference.file\n }\" has an invalid file extension (.${\n extension\n }). Please ensure that the file has one of the following extensions: ${list(\n VALID_SOURCE_FILE_EXTENSIONS,\n { conjunction: \"or\" }\n )}.`\n );\n }\n\n let resolved = await resolve<SchemaSourceInput>(\n context,\n input as FileReferenceInput,\n defu(options, {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n level: \"all\"\n })\n ]\n })\n );\n\n try {\n const type = deserializeType(resolved as SerializedType[]);\n if (isType(type)) {\n resolved = type;\n }\n } catch {\n // If deserialization fails, we assume the resolved output is not a reflected type and proceed with it as-is.\n }\n\n source = extractSource(extractResolvedVariant(resolved), resolved);\n } else if (\n [\n \"json-schema\",\n \"standard-schema\",\n \"zod3\",\n \"untyped\",\n \"valibot\",\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 \"file-reference\", \"json-schema\", \"standard-schema\", \"zod3\", \"valibot\", \"untyped\", or \"reflection\".`\n );\n }\n\n return {\n variant,\n source,\n schema: await extractSchema(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 Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a 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 Rolldown 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 Valibot schema\n * const schema4 = await extract(context, valibotSchema);\n * // Resolve a schema definition from a reflected Deepkit Type object\n * const schema5 = await extract(context, reflectionType);\n * ```\n *\n * @see https://zod.dev/\n * @see https://valibot.dev/\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 Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a reflected Deepkit Type object.\n * @param options - Optional overrides for the Rolldown 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(\n context: Context,\n input: SchemaInput,\n options: BundleOptions = {}\n): Promise<Schema> {\n if (isSchemaWithSource(input) || isSchema(input)) {\n return input;\n }\n\n let result: Schema | 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\n };\n }\n }\n\n result ??= await extractSchemaWithSource(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 Valibot schema, any Standard JSON Schema type, a plain 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA,MAAM,yBAAyB;AAE/B,SAAS,aAAa,KAAqB;CACzC,OAAO,IAAI,SAAS,GAAG,IAAI,IAAI,MAAM,GAAG,EAAE,IAAI;AAChD;AAEA,SAAS,iBAAiB,KAAqB;CAC7C,MAAM,YAAY,IAAI,QAAQ,GAAG;CAEjC,OAAO,aAAa,IAAI,IAAI,MAAM,GAAG,SAAS,IAAI;AACpD;AAEA,SAAS,uBAAuB,OAAuB;CACrD,OAAO,MAAM,WAAW,KAAK,IAAI,EAAE,WAAW,KAAK,IAAI;AACzD;AAEA,SAAS,cAAc,MAAwB;CAC7C,IAAI,KAAK,WAAW,GAClB,OAAO;CAGT,OAAO,IAAI,KAAK,KAAI,YAAW,uBAAuB,OAAO,CAAC,EAAE,KAAK,GAAG;AAC1E;AAEA,SAAS,WAAW,WAAmB,SAAyB;CAC9D,IAAI;EACF,OAAO,aAAa,IAAI,IAAI,WAAW,OAAO,EAAE,SAAS,CAAC;CAC5D,QAAQ;EACN,OAAO,aAAa,SAAS;CAC/B;AACF;AAEA,SAAS,wBACP,OACA,MACA,SACA,cACA,sBACM;CACN,IAAI,CAACA,cAAY,KAAK,GACpB;CAGF,MAAM,SAAS;CACf,MAAM,UAAU,cAAc,IAAI;CAElC,MAAM,iBAAiB,YAAY,OAAO,GAAG,IACzC,WAAW,OAAO,KAAK,OAAO,IAC9B;CAEJ,MAAM,qBAAqB,iBAAiB,cAAc;CAE1D,aAAa,IAAI,gBAAgB,OAAO;CACxC,aAAa,IAAI,oBAAoB,OAAO;CAE5C,IAAI,YAAY,OAAO,OAAO,GAC5B,aAAa,IAAI,GAAG,mBAAmB,GAAG,OAAO,WAAW,OAAO;CAGrE,IAAI,YAAY,OAAO,cAAc,GAAG;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C,OAAO;AACT"}
package/dist/helpers.cjs CHANGED
@@ -1,3 +1,11 @@
1
+
2
+
3
+ import __tsdown_shims_path from 'node:path'
4
+ import __tsdown_shims_url from 'node:url'
5
+
6
+ const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
7
+ const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
8
+
1
9
  const require_constants = require('./constants.cjs');
2
10
  const require_metadata = require('./metadata.cjs');
3
11
  const require_type_checks = require('./type-checks.cjs');
@@ -1,3 +1,5 @@
1
+ import __tsdown_shims_path from 'node:path';
2
+ import __tsdown_shims_url from 'node:url';
1
3
  import { JsonSchema, JsonSchemaObject, Schema } from "./types.mjs";
2
4
 
3
5
  //#region src/helpers.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.mts","names":[],"sources":["../src/helpers.ts"],"mappings":";;;KA2BY,mBAAA,GAAsB,UAAU;EAC1C,IAAA;EACA,QAAA;EACA,OAAA;AAAA;;;;;;;AAAO;AAaT;;;iBAAgB,aAAA,CAAc,KAAA,EAAO,MAAA,GAAS,UAAA,GAAa,UAAA;;;;;;;;;;AAAU;iBAyBrD,mBAAA,CACd,KAAA,EAAO,MAAA,GAAS,UAAA,GACf,gBAAA;;;;;;;;;;iBAoBa,aAAA,CACd,GAAA,EAAK,MAAA,GAAS,gBAAA,GACb,MAAA,SAED,UAAA;EAAe,IAAA;EAAc,QAAA;EAAmB,OAAA;AAAA;;;;;;;;;;iBAuClC,iBAAA,CAAkB,GAAA,EAAK,MAAA,GAAS,gBAAA,IAAgB,UAAA;;;;;;;;AAvCP;AAuCzD;;;;;;;iBAegB,WAAA,CACd,GAAA,EAAK,MAAA,GAAS,gBAAA,EACd,IAAA,UACA,QAAA,EAAU,UAAA;;;;;;;;;;iBA0BI,KAAA,CAAA,GAAS,OAAA,GAAU,UAAA,GAAa,MAAA,MAAY,UAAA;;;;;;;;;;iBA0B5C,gBAAA,CAAiB,MAAmB,GAAV,UAAU;;;;;AApD9B;AA0BtB;;;;;iBAgDgB,kBAAA,CACd,MAAA,EAAQ,gBAAgB,EACxB,YAAA;;;;;;;iBAiBc,sBAAA,CAAuB,QAAgB"}
1
+ {"version":3,"file":"helpers.d.mts","names":[],"sources":["../src/helpers.ts"],"mappings":";;;;;KA2BY,mBAAA,GAAsB,UAAU;EAC1C,IAAA;EACA,QAAA;EACA,OAAA;AAAA;;;;;;AAHF;;;;;iBAgBgB,aAAA,CAAc,KAAA,EAAO,MAAA,GAAS,UAAA,GAAa,UAAA;;;;AAblD;AAaT;;;;;;iBAyBgB,mBAAA,CACd,KAAA,EAAO,MAAA,GAAS,UAAA,GACf,gBAAA;;;;;;;AA3BkE;AAyBrE;;iBAsBgB,aAAA,CACd,GAAA,EAAK,MAAA,GAAS,gBAAA,GACb,MAAA,SAED,UAAA;EAAe,IAAA;EAAc,QAAA;EAAmB,OAAA;AAAA;;;;;;;AAxB/B;AAoBnB;;iBA2CgB,iBAAA,CAAkB,GAAA,EAAK,MAAA,GAAS,gBAAA,IAAgB,UAAA;;;;;;;;;;;;;;;;iBAehD,WAAA,CACd,GAAA,EAAK,MAAA,GAAS,gBAAA,EACd,IAAA,UACA,QAAA,EAAU,UAAA;AAlBZ;;;;;;;;;AAAA,iBA4CgB,KAAA,CAAA,GAAS,OAAA,GAAU,UAAA,GAAa,MAAA,MAAY,UAAA;;;;;;;;AA7B5D;;iBAuDgB,gBAAA,CAAiB,MAAmB,GAAV,UAAU;;;;;;;;;;;iBAsBpC,kBAAA,CACd,MAAA,EAAQ,gBAAgB,EACxB,YAAA;;AA5EoB;AA0BtB;;;;iBAmEgB,sBAAA,CAAuB,QAAgB"}
package/dist/helpers.mjs CHANGED
@@ -1,3 +1,11 @@
1
+
2
+
3
+ import __tsdown_shims_path from 'node:path'
4
+ import __tsdown_shims_url from 'node:url'
5
+
6
+ const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
7
+ const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
8
+
1
9
  import { VALID_SOURCE_FILE_EXTENSIONS } from "./constants.mjs";
2
10
  import { readSchemaTypes } from "./metadata.mjs";
3
11
  import { isJsonSchema, isJsonSchemaObject, isSchema } from "./type-checks.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.mjs","names":["defu"],"sources":["../src/helpers.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 { getUnique } from \"@stryke/helpers/get-unique\";\nimport { findFileExtensionSafe } from \"@stryke/path/find\";\nimport { isSetObject } from \"@stryke/type-checks\";\nimport { defu } from \"defu\";\nimport { VALID_SOURCE_FILE_EXTENSIONS } from \"./constants\";\nimport { readSchemaTypes } from \"./metadata\";\nimport { isJsonSchema, isJsonSchemaObject, isSchema } from \"./type-checks\";\nimport { JsonSchema, JsonSchemaLike, JsonSchemaObject, Schema } from \"./types\";\n\nexport type GetPropertiesResult = JsonSchema & {\n name: string;\n required: boolean;\n default?: unknown;\n};\n\n/**\n * Retrieves the JSON Schema from a Schema wrapper or returns the input if it's already a JSON Schema.\n *\n * @remarks\n * This function checks if the input is a Schema wrapper (an object with a `schema` property) and returns the `schema` if it is. If the input is already a JSON Schema, it returns it directly. This allows for flexibility in handling both raw JSON Schema objects and wrapped schemas without needing to check the type at every usage point.\n *\n * @param input - The input which can be either a Schema wrapper or a JSON Schema object.\n * @returns The JSON Schema object.\n * @throws Will throw a TypeError if the input is neither a valid Schema wrapper nor a valid JSON Schema object.\n */\nexport function getJsonSchema(input: Schema | JsonSchema): JsonSchema {\n const schema = isSchema(input) ? input.schema : input;\n if (!isJsonSchema(schema)) {\n throw new TypeError(\n `The provided input is not a valid JSON Schema: ${JSON.stringify(\n schema,\n null,\n 2\n )}`\n );\n }\n\n return schema;\n}\n\n/**\n * Retrieves the JSON Schema in Object form from a Schema wrapper or returns the input if it's already a JSON Schema.\n *\n * @remarks\n * This function checks if the input is a Schema wrapper (an object with a `schema` property) and returns the `schema` if it is. If the input is already a JSON Schema object, it returns it directly. This allows for flexibility in handling both raw JSON Schema objects and wrapped schemas without needing to check the type at every usage point.\n *\n * @param input - The input which can be either a Schema wrapper or a JSON Schema object.\n * @returns The JSON Schema object.\n * @throws Will throw a TypeError if the input is neither a valid Schema wrapper nor a valid JSON Schema object.\n */\nexport function getJsonSchemaObject(\n input: Schema | JsonSchema\n): JsonSchemaObject {\n const schema = getJsonSchema(input);\n if (!isJsonSchemaObject(schema)) {\n throw new TypeError(\n `The provided input is not a valid JSON Schema object: ${JSON.stringify(schema, null, 2)}`\n );\n }\n\n return schema;\n}\n\n/**\n * Extracts object properties from a JSON Schema object form.\n *\n * @remarks\n * This function returns an empty object if the schema is not an object form or if it has no properties.\n *\n * @param obj - The JSON Schema object form or a Schema wrapper to extract properties from.\n * @returns An object mapping property names to their corresponding JSON Schema fragments, including metadata.\n */\nexport function getProperties(\n obj: Schema | JsonSchemaObject\n): Record<\n string,\n JsonSchema & { name: string; required: boolean; default?: unknown }\n> {\n const properties: Record<\n string,\n JsonSchema & { name: string; required: boolean; default?: unknown }\n > = {};\n\n const schema = getJsonSchemaObject(obj);\n if (!isSetObject(schema.properties)) {\n return properties;\n }\n\n for (const [key, value] of Object.entries(schema.properties)) {\n const propertySchema: Record<string, unknown> = {};\n\n if (typeof value !== \"boolean\") {\n Object.assign(propertySchema, value);\n }\n\n properties[key] = {\n ...propertySchema,\n name: key,\n required: !isPropertyOptional(schema, key),\n default: schema.default?.[key] ?? propertySchema.default\n };\n }\n\n return properties;\n}\n\n/**\n * Returns object properties as an array.\n *\n * @remarks\n * This is a convenience function that extracts properties using `getProperties` and returns them as an array.\n *\n * @param obj - The JSON Schema object form or a Schema wrapper to extract properties from.\n * @returns An array of JSON Schema fragments representing the properties, each including metadata.\n */\nexport function getPropertiesList(obj: Schema | JsonSchemaObject) {\n return Object.values(getProperties(obj));\n}\n\n/**\n * Adds a property to a JSON Schema object form.\n *\n * @remarks\n * This function modifies the provided schema in place by adding a new property with the specified name and schema. It also updates the `required` array based on the `optional` flag of the property. If the property is marked as optional, it will be removed from the `required` array; otherwise, it will be added to it.\n *\n * @param obj - The JSON Schema object form or a Schema wrapper to which the property should be added.\n * @param name - The name of the property to add.\n * @param property - The JSON Schema fragment representing the property's schema, including metadata.\n * @throws Will throw an error if the provided schema is not an object form.\n */\nexport function addProperty(\n obj: Schema | JsonSchemaObject,\n name: string,\n property: JsonSchema\n): void {\n const schema = getJsonSchemaObject(obj);\n\n schema.properties ??= {};\n schema.required ??= [];\n\n schema.properties[name] = { ...property, name };\n if (!schema.required.includes(name)) {\n schema.required.push(name);\n }\n\n if (schema.required.length === 0) {\n delete schema.required;\n }\n}\n\n/**\n * Merges multiple JSON Schemas into one.\n *\n * @remarks\n * This function takes multiple JSON Schemas or Schema wrappers and merges them into a single JSON Schema object. The merging process combines properties and metadata from all provided schemas, with later schemas in the arguments list taking precedence over earlier ones in case of conflicts. The resulting schema will include all unique properties and metadata from the input schemas.\n *\n * @param schemas - An array of JSON Schemas or Schema wrappers to merge.\n * @returns A new JSON Schema that is the result of merging all input schemas.\n */\nexport function merge(...schemas: (JsonSchema | Schema)[]): JsonSchema {\n let result: JsonSchema = {};\n for (const schema of schemas.reverse()) {\n if (\n !(result as JsonSchemaLike).type ||\n (result as JsonSchemaLike).type === (schema as JsonSchemaLike).type\n ) {\n result = defu(result, getJsonSchema(schema)) as JsonSchema;\n if (isJsonSchemaObject(result)) {\n result.required = getUnique(result.required ?? []);\n }\n }\n }\n\n return result;\n}\n\n/**\n * Returns whether a JSON Schema fragment accepts `null`.\n *\n * @remarks\n * This is true if the schema has `nullable: true` or if its `type` includes `\"null\"`.\n *\n * @param schema - The JSON Schema fragment to check.\n * @returns `true` if the schema accepts `null`, otherwise `false`.\n */\nexport function isSchemaNullable(schema?: JsonSchema): boolean {\n if (!isSetObject(schema)) {\n return false;\n }\n\n if ((schema as { nullable?: true }).nullable === true) {\n return true;\n }\n\n return readSchemaTypes(schema).includes(\"null\");\n}\n\n/**\n * Returns whether an object property is optional (not listed in `required`).\n *\n * @remarks\n * In JSON Schema, object properties are optional by default unless they are listed in the `required` array of the parent schema. This function checks whether a given property name is not included in the `required` array of its parent schema, indicating that it is optional.\n *\n * @param parent - The parent JSON Schema object containing the property.\n * @param propertyName - The name of the property to check for optionality.\n * @returns `true` if the property is optional, otherwise `false`.\n */\nexport function isPropertyOptional(\n parent: JsonSchemaObject,\n propertyName: string\n): boolean {\n if (!parent.properties?.[propertyName]) {\n throw new Error(\n `The property \"${propertyName}\" does not exist in the parent schema.`\n );\n }\n\n return !(parent.required ?? []).includes(propertyName);\n}\n\n/**\n * Checks if a given file name has a valid schema input file extension.\n *\n * @param fileName - The file name to check for a valid schema input extension.\n * @returns `true` if the file name has a valid schema input extension, otherwise `false`.\n */\nexport function isValidSchemaInputFile(fileName: string): boolean {\n return VALID_SOURCE_FILE_EXTENSIONS.includes(findFileExtensionSafe(fileName));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2CA,SAAgB,cAAc,OAAwC;CACpE,MAAM,SAAS,SAAS,KAAK,IAAI,MAAM,SAAS;CAChD,IAAI,CAAC,aAAa,MAAM,GACtB,MAAM,IAAI,UACR,kDAAkD,KAAK,UACrD,QACA,MACA,CACF,GACF;CAGF,OAAO;AACT;;;;;;;;;;;AAYA,SAAgB,oBACd,OACkB;CACl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UAAU,OAAO,YAAY,CAAC,CAAC;CAErD;CAGF,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,iBAAiB,QAA8B;CAC7D,IAAI,CAAC,YAAY,MAAM,GACrB,OAAO;CAGT,IAAK,OAA+B,aAAa,MAC/C,OAAO;CAGT,OAAO,gBAAgB,MAAM,EAAE,SAAS,MAAM;AAChD;;;;;;;;;;;AAYA,SAAgB,mBACd,QACA,cACS;CACT,IAAI,CAAC,OAAO,aAAa,eACvB,MAAM,IAAI,MACR,iBAAiB,aAAa,uCAChC;CAGF,OAAO,EAAE,OAAO,YAAY,CAAC,GAAG,SAAS,YAAY;AACvD;;;;;;;AAQA,SAAgB,uBAAuB,UAA2B;CAChE,OAAO,6BAA6B,SAAS,sBAAsB,QAAQ,CAAC;AAC9E"}
1
+ {"version":3,"file":"helpers.mjs","names":["defu"],"sources":["../src/helpers.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 { getUnique } from \"@stryke/helpers/get-unique\";\nimport { findFileExtensionSafe } from \"@stryke/path/find\";\nimport { isSetObject } from \"@stryke/type-checks\";\nimport { defu } from \"defu\";\nimport { VALID_SOURCE_FILE_EXTENSIONS } from \"./constants\";\nimport { readSchemaTypes } from \"./metadata\";\nimport { isJsonSchema, isJsonSchemaObject, isSchema } from \"./type-checks\";\nimport { JsonSchema, JsonSchemaLike, JsonSchemaObject, Schema } from \"./types\";\n\nexport type GetPropertiesResult = JsonSchema & {\n name: string;\n required: boolean;\n default?: unknown;\n};\n\n/**\n * Retrieves the JSON Schema from a Schema wrapper or returns the input if it's already a JSON Schema.\n *\n * @remarks\n * This function checks if the input is a Schema wrapper (an object with a `schema` property) and returns the `schema` if it is. If the input is already a JSON Schema, it returns it directly. This allows for flexibility in handling both raw JSON Schema objects and wrapped schemas without needing to check the type at every usage point.\n *\n * @param input - The input which can be either a Schema wrapper or a JSON Schema object.\n * @returns The JSON Schema object.\n * @throws Will throw a TypeError if the input is neither a valid Schema wrapper nor a valid JSON Schema object.\n */\nexport function getJsonSchema(input: Schema | JsonSchema): JsonSchema {\n const schema = isSchema(input) ? input.schema : input;\n if (!isJsonSchema(schema)) {\n throw new TypeError(\n `The provided input is not a valid JSON Schema: ${JSON.stringify(\n schema,\n null,\n 2\n )}`\n );\n }\n\n return schema;\n}\n\n/**\n * Retrieves the JSON Schema in Object form from a Schema wrapper or returns the input if it's already a JSON Schema.\n *\n * @remarks\n * This function checks if the input is a Schema wrapper (an object with a `schema` property) and returns the `schema` if it is. If the input is already a JSON Schema object, it returns it directly. This allows for flexibility in handling both raw JSON Schema objects and wrapped schemas without needing to check the type at every usage point.\n *\n * @param input - The input which can be either a Schema wrapper or a JSON Schema object.\n * @returns The JSON Schema object.\n * @throws Will throw a TypeError if the input is neither a valid Schema wrapper nor a valid JSON Schema object.\n */\nexport function getJsonSchemaObject(\n input: Schema | JsonSchema\n): JsonSchemaObject {\n const schema = getJsonSchema(input);\n if (!isJsonSchemaObject(schema)) {\n throw new TypeError(\n `The provided input is not a valid JSON Schema object: ${JSON.stringify(schema, null, 2)}`\n );\n }\n\n return schema;\n}\n\n/**\n * Extracts object properties from a JSON Schema object form.\n *\n * @remarks\n * This function returns an empty object if the schema is not an object form or if it has no properties.\n *\n * @param obj - The JSON Schema object form or a Schema wrapper to extract properties from.\n * @returns An object mapping property names to their corresponding JSON Schema fragments, including metadata.\n */\nexport function getProperties(\n obj: Schema | JsonSchemaObject\n): Record<\n string,\n JsonSchema & { name: string; required: boolean; default?: unknown }\n> {\n const properties: Record<\n string,\n JsonSchema & { name: string; required: boolean; default?: unknown }\n > = {};\n\n const schema = getJsonSchemaObject(obj);\n if (!isSetObject(schema.properties)) {\n return properties;\n }\n\n for (const [key, value] of Object.entries(schema.properties)) {\n const propertySchema: Record<string, unknown> = {};\n\n if (typeof value !== \"boolean\") {\n Object.assign(propertySchema, value);\n }\n\n properties[key] = {\n ...propertySchema,\n name: key,\n required: !isPropertyOptional(schema, key),\n default: schema.default?.[key] ?? propertySchema.default\n };\n }\n\n return properties;\n}\n\n/**\n * Returns object properties as an array.\n *\n * @remarks\n * This is a convenience function that extracts properties using `getProperties` and returns them as an array.\n *\n * @param obj - The JSON Schema object form or a Schema wrapper to extract properties from.\n * @returns An array of JSON Schema fragments representing the properties, each including metadata.\n */\nexport function getPropertiesList(obj: Schema | JsonSchemaObject) {\n return Object.values(getProperties(obj));\n}\n\n/**\n * Adds a property to a JSON Schema object form.\n *\n * @remarks\n * This function modifies the provided schema in place by adding a new property with the specified name and schema. It also updates the `required` array based on the `optional` flag of the property. If the property is marked as optional, it will be removed from the `required` array; otherwise, it will be added to it.\n *\n * @param obj - The JSON Schema object form or a Schema wrapper to which the property should be added.\n * @param name - The name of the property to add.\n * @param property - The JSON Schema fragment representing the property's schema, including metadata.\n * @throws Will throw an error if the provided schema is not an object form.\n */\nexport function addProperty(\n obj: Schema | JsonSchemaObject,\n name: string,\n property: JsonSchema\n): void {\n const schema = getJsonSchemaObject(obj);\n\n schema.properties ??= {};\n schema.required ??= [];\n\n schema.properties[name] = { ...property, name };\n if (!schema.required.includes(name)) {\n schema.required.push(name);\n }\n\n if (schema.required.length === 0) {\n delete schema.required;\n }\n}\n\n/**\n * Merges multiple JSON Schemas into one.\n *\n * @remarks\n * This function takes multiple JSON Schemas or Schema wrappers and merges them into a single JSON Schema object. The merging process combines properties and metadata from all provided schemas, with later schemas in the arguments list taking precedence over earlier ones in case of conflicts. The resulting schema will include all unique properties and metadata from the input schemas.\n *\n * @param schemas - An array of JSON Schemas or Schema wrappers to merge.\n * @returns A new JSON Schema that is the result of merging all input schemas.\n */\nexport function merge(...schemas: (JsonSchema | Schema)[]): JsonSchema {\n let result: JsonSchema = {};\n for (const schema of schemas.reverse()) {\n if (\n !(result as JsonSchemaLike).type ||\n (result as JsonSchemaLike).type === (schema as JsonSchemaLike).type\n ) {\n result = defu(result, getJsonSchema(schema)) as JsonSchema;\n if (isJsonSchemaObject(result)) {\n result.required = getUnique(result.required ?? []);\n }\n }\n }\n\n return result;\n}\n\n/**\n * Returns whether a JSON Schema fragment accepts `null`.\n *\n * @remarks\n * This is true if the schema has `nullable: true` or if its `type` includes `\"null\"`.\n *\n * @param schema - The JSON Schema fragment to check.\n * @returns `true` if the schema accepts `null`, otherwise `false`.\n */\nexport function isSchemaNullable(schema?: JsonSchema): boolean {\n if (!isSetObject(schema)) {\n return false;\n }\n\n if ((schema as { nullable?: true }).nullable === true) {\n return true;\n }\n\n return readSchemaTypes(schema).includes(\"null\");\n}\n\n/**\n * Returns whether an object property is optional (not listed in `required`).\n *\n * @remarks\n * In JSON Schema, object properties are optional by default unless they are listed in the `required` array of the parent schema. This function checks whether a given property name is not included in the `required` array of its parent schema, indicating that it is optional.\n *\n * @param parent - The parent JSON Schema object containing the property.\n * @param propertyName - The name of the property to check for optionality.\n * @returns `true` if the property is optional, otherwise `false`.\n */\nexport function isPropertyOptional(\n parent: JsonSchemaObject,\n propertyName: string\n): boolean {\n if (!parent.properties?.[propertyName]) {\n throw new Error(\n `The property \"${propertyName}\" does not exist in the parent schema.`\n );\n }\n\n return !(parent.required ?? []).includes(propertyName);\n}\n\n/**\n * Checks if a given file name has a valid schema input file extension.\n *\n * @param fileName - The file name to check for a valid schema input extension.\n * @returns `true` if the file name has a valid schema input extension, otherwise `false`.\n */\nexport function isValidSchemaInputFile(fileName: string): boolean {\n return VALID_SOURCE_FILE_EXTENSIONS.includes(findFileExtensionSafe(fileName));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,SAAgB,cAA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