@powerlines/schema 0.11.81 → 0.11.83

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 (86) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/bundle.cjs +49 -0
  3. package/dist/bundle.d.cts +21 -0
  4. package/dist/bundle.d.cts.map +1 -0
  5. package/dist/bundle.d.mts +21 -0
  6. package/dist/bundle.d.mts.map +1 -0
  7. package/dist/bundle.mjs +48 -0
  8. package/dist/bundle.mjs.map +1 -0
  9. package/dist/codegen.cjs +378 -0
  10. package/dist/codegen.d.cts +67 -0
  11. package/dist/codegen.d.cts.map +1 -0
  12. package/dist/codegen.d.mts +67 -0
  13. package/dist/codegen.d.mts.map +1 -0
  14. package/dist/codegen.mjs +372 -0
  15. package/dist/codegen.mjs.map +1 -0
  16. package/dist/constants.cjs +61 -0
  17. package/dist/constants.d.cts +17 -0
  18. package/dist/constants.d.cts.map +1 -0
  19. package/dist/constants.d.mts +17 -0
  20. package/dist/constants.d.mts.map +1 -0
  21. package/dist/constants.mjs +57 -0
  22. package/dist/constants.mjs.map +1 -0
  23. package/dist/extract.cjs +482 -0
  24. package/dist/extract.d.cts +125 -0
  25. package/dist/extract.d.cts.map +1 -0
  26. package/dist/extract.d.mts +125 -0
  27. package/dist/extract.d.mts.map +1 -0
  28. package/dist/extract.mjs +472 -0
  29. package/dist/extract.mjs.map +1 -0
  30. package/dist/helpers.cjs +241 -0
  31. package/dist/helpers.d.cts +121 -0
  32. package/dist/helpers.d.cts.map +1 -0
  33. package/dist/helpers.d.mts +121 -0
  34. package/dist/helpers.d.mts.map +1 -0
  35. package/dist/helpers.mjs +234 -0
  36. package/dist/helpers.mjs.map +1 -0
  37. package/dist/index.cjs +95 -2434
  38. package/dist/index.d.cts +11 -1892
  39. package/dist/index.d.cts.map +1 -1
  40. package/dist/index.d.mts +11 -1892
  41. package/dist/index.d.mts.map +1 -1
  42. package/dist/index.mjs +12 -2321
  43. package/dist/metadata.cjs +53 -0
  44. package/dist/metadata.d.cts +31 -0
  45. package/dist/metadata.d.cts.map +1 -0
  46. package/dist/metadata.d.mts +31 -0
  47. package/dist/metadata.d.mts.map +1 -0
  48. package/dist/metadata.mjs +52 -0
  49. package/dist/metadata.mjs.map +1 -0
  50. package/dist/persistence.cjs +74 -0
  51. package/dist/persistence.d.cts +47 -0
  52. package/dist/persistence.d.cts.map +1 -0
  53. package/dist/persistence.d.mts +47 -0
  54. package/dist/persistence.d.mts.map +1 -0
  55. package/dist/persistence.mjs +71 -0
  56. package/dist/persistence.mjs.map +1 -0
  57. package/dist/reflection.cjs +426 -0
  58. package/dist/reflection.d.cts +11 -0
  59. package/dist/reflection.d.cts.map +1 -0
  60. package/dist/reflection.d.mts +11 -0
  61. package/dist/reflection.d.mts.map +1 -0
  62. package/dist/reflection.mjs +425 -0
  63. package/dist/reflection.mjs.map +1 -0
  64. package/dist/resolve.cjs +105 -0
  65. package/dist/resolve.d.cts +36 -0
  66. package/dist/resolve.d.cts.map +1 -0
  67. package/dist/resolve.d.mts +36 -0
  68. package/dist/resolve.d.mts.map +1 -0
  69. package/dist/resolve.mjs +102 -0
  70. package/dist/resolve.mjs.map +1 -0
  71. package/dist/type-checks.cjs +633 -0
  72. package/dist/type-checks.d.cts +316 -0
  73. package/dist/type-checks.d.cts.map +1 -0
  74. package/dist/type-checks.d.mts +316 -0
  75. package/dist/type-checks.d.mts.map +1 -0
  76. package/dist/type-checks.mjs +594 -0
  77. package/dist/type-checks.mjs.map +1 -0
  78. package/dist/types.d.cts +1152 -0
  79. package/dist/types.d.cts.map +1 -0
  80. package/dist/types.d.mts +1152 -0
  81. package/dist/types.d.mts.map +1 -0
  82. package/dist/validate.cjs +27 -0
  83. package/dist/validate.mjs +25 -0
  84. package/dist/validate.mjs.map +1 -0
  85. package/package.json +6 -6
  86. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,29 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ exports.__toESM = __toESM;
@@ -0,0 +1,49 @@
1
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
+ let _powerlines_core_lib_unplugin = require("@powerlines/core/lib/unplugin");
3
+ let _powerlines_unplugin_esbuild = require("@powerlines/unplugin/esbuild");
4
+ let _stryke_helpers_omit = require("@stryke/helpers/omit");
5
+ let _stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
6
+ let defu = require("defu");
7
+ defu = require_runtime.__toESM(defu, 1);
8
+ let esbuild = require("esbuild");
9
+ let unplugin = require("unplugin");
10
+
11
+ //#region src/bundle.ts
12
+ /**
13
+ * Bundle a type definition to a module.
14
+ *
15
+ * @param context - The context object containing the environment paths.
16
+ * @param file - The file path to bundle.
17
+ * @param options - Optional overrides for the ESBuild configuration.
18
+ * @returns A promise that resolves to the bundled module.
19
+ */
20
+ async function bundle(context, file, options = {}) {
21
+ const path = await context.fs.resolve(file);
22
+ if (!path || !context.fs.existsSync(path)) throw new Error(`Module not found: "${file}". Please check the path and try again.`);
23
+ const result = await (0, esbuild.build)((0, defu.default)({
24
+ platform: "node",
25
+ ...(0, _stryke_helpers_omit.omit)(options, ["name", "resolve"]),
26
+ logLevel: "silent",
27
+ entryPoints: [path],
28
+ write: false,
29
+ sourcemap: false,
30
+ splitting: false,
31
+ treeShaking: false,
32
+ bundle: true,
33
+ packages: "bundle",
34
+ keepNames: true,
35
+ metafile: false
36
+ }, (0, _powerlines_unplugin_esbuild.resolveOptions)(context), { plugins: [(0, unplugin.createEsbuildPlugin)((0, _powerlines_core_lib_unplugin.createUnpluginResolver)(context, {
37
+ name: options.name ?? `${(0, _stryke_path_file_path_fns.findFileName)(file)} Bundler`,
38
+ prefix: false,
39
+ overrides: (0, defu.default)(options.resolve ?? {}, { skipNodeModulesBundle: false }),
40
+ silenceHookLogging: true
41
+ }))()] }));
42
+ if (result.errors.length > 0) throw new Error(`Failed to bundle ${file}: ${result.errors.map((error) => error.text).join(", ")}`);
43
+ if (result.warnings.length > 0) context.warn(`Warnings while bundling ${file}: ${result.warnings.map((warning) => warning.text).join(", ")}`);
44
+ if (!result.outputFiles || result.outputFiles.filter(Boolean).length === 0) throw new Error(`No output files generated for ${file}. Please check the configuration and try again.`);
45
+ return result.outputFiles.filter(Boolean)[0];
46
+ }
47
+
48
+ //#endregion
49
+ exports.bundle = bundle;
@@ -0,0 +1,21 @@
1
+ import { ResolveOptions, UnresolvedContext } from "@powerlines/core";
2
+ import { DeepPartial } from "@stryke/types/base";
3
+ import { BuildOptions, OutputFile } from "esbuild";
4
+
5
+ //#region src/bundle.d.ts
6
+ type BundleOptions = DeepPartial<BuildOptions> & {
7
+ name?: string;
8
+ resolve?: DeepPartial<ResolveOptions>;
9
+ };
10
+ /**
11
+ * Bundle a type definition to a module.
12
+ *
13
+ * @param context - The context object containing the environment paths.
14
+ * @param file - The file path to bundle.
15
+ * @param options - Optional overrides for the ESBuild configuration.
16
+ * @returns A promise that resolves to the bundled module.
17
+ */
18
+ declare function bundle<TContext extends UnresolvedContext>(context: TContext, file: string, options?: BundleOptions): Promise<OutputFile>;
19
+ //#endregion
20
+ export { BundleOptions, bundle };
21
+ //# sourceMappingURL=bundle.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.d.cts","names":[],"sources":["../src/bundle.ts"],"mappings":";;;;;KA6BY,aAAA,GAAgB,WAAA,CAAY,YAAA;EACtC,IAAA;EACA,OAAA,GAAU,WAAA,CAAY,cAAA;AAAA;;;;;;;;;iBAWF,MAAA,kBAAwB,iBAAA,EAC5C,OAAA,EAAS,QAAA,EACT,IAAA,UACA,OAAA,GAAS,aAAA,GACR,OAAA,CAAQ,UAAA"}
@@ -0,0 +1,21 @@
1
+ import { BuildOptions, OutputFile } from "esbuild";
2
+ import { ResolveOptions, UnresolvedContext } from "@powerlines/core";
3
+ import { DeepPartial } from "@stryke/types/base";
4
+
5
+ //#region src/bundle.d.ts
6
+ type BundleOptions = DeepPartial<BuildOptions> & {
7
+ name?: string;
8
+ resolve?: DeepPartial<ResolveOptions>;
9
+ };
10
+ /**
11
+ * Bundle a type definition to a module.
12
+ *
13
+ * @param context - The context object containing the environment paths.
14
+ * @param file - The file path to bundle.
15
+ * @param options - Optional overrides for the ESBuild configuration.
16
+ * @returns A promise that resolves to the bundled module.
17
+ */
18
+ declare function bundle<TContext extends UnresolvedContext>(context: TContext, file: string, options?: BundleOptions): Promise<OutputFile>;
19
+ //#endregion
20
+ export { BundleOptions, bundle };
21
+ //# sourceMappingURL=bundle.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.d.mts","names":[],"sources":["../src/bundle.ts"],"mappings":";;;;;KA6BY,aAAA,GAAgB,WAAA,CAAY,YAAA;EACtC,IAAA;EACA,OAAA,GAAU,WAAA,CAAY,cAAA;AAAA;;;;;;;;;iBAWF,MAAA,kBAAwB,iBAAA,EAC5C,OAAA,EAAS,QAAA,EACT,IAAA,UACA,OAAA,GAAS,aAAA,GACR,OAAA,CAAQ,UAAA"}
@@ -0,0 +1,48 @@
1
+ import { createUnpluginResolver } from "@powerlines/core/lib/unplugin";
2
+ import { resolveOptions } from "@powerlines/unplugin/esbuild";
3
+ import { omit } from "@stryke/helpers/omit";
4
+ import { findFileName } from "@stryke/path/file-path-fns";
5
+ import defu from "defu";
6
+ import { build } from "esbuild";
7
+ import { createEsbuildPlugin } from "unplugin";
8
+
9
+ //#region src/bundle.ts
10
+ /**
11
+ * Bundle a type definition to a module.
12
+ *
13
+ * @param context - The context object containing the environment paths.
14
+ * @param file - The file path to bundle.
15
+ * @param options - Optional overrides for the ESBuild configuration.
16
+ * @returns A promise that resolves to the bundled module.
17
+ */
18
+ async function bundle(context, file, options = {}) {
19
+ const path = await context.fs.resolve(file);
20
+ if (!path || !context.fs.existsSync(path)) throw new Error(`Module not found: "${file}". Please check the path and try again.`);
21
+ const result = await build(defu({
22
+ platform: "node",
23
+ ...omit(options, ["name", "resolve"]),
24
+ logLevel: "silent",
25
+ entryPoints: [path],
26
+ write: false,
27
+ sourcemap: false,
28
+ splitting: false,
29
+ treeShaking: false,
30
+ bundle: true,
31
+ packages: "bundle",
32
+ keepNames: true,
33
+ metafile: false
34
+ }, resolveOptions(context), { plugins: [createEsbuildPlugin(createUnpluginResolver(context, {
35
+ name: options.name ?? `${findFileName(file)} Bundler`,
36
+ prefix: false,
37
+ overrides: defu(options.resolve ?? {}, { skipNodeModulesBundle: false }),
38
+ silenceHookLogging: true
39
+ }))()] }));
40
+ if (result.errors.length > 0) throw new Error(`Failed to bundle ${file}: ${result.errors.map((error) => error.text).join(", ")}`);
41
+ if (result.warnings.length > 0) context.warn(`Warnings while bundling ${file}: ${result.warnings.map((warning) => warning.text).join(", ")}`);
42
+ if (!result.outputFiles || result.outputFiles.filter(Boolean).length === 0) throw new Error(`No output files generated for ${file}. Please check the configuration and try again.`);
43
+ return result.outputFiles.filter(Boolean)[0];
44
+ }
45
+
46
+ //#endregion
47
+ export { bundle };
48
+ //# sourceMappingURL=bundle.mjs.map
@@ -0,0 +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 { ResolveOptions, UnresolvedContext } 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 platform: \"node\",\n ...omit(options, [\"name\", \"resolve\"]),\n logLevel: \"silent\",\n entryPoints: [path],\n write: false,\n sourcemap: false,\n splitting: false,\n treeShaking: false,\n bundle: true,\n packages: \"bundle\",\n keepNames: true,\n metafile: false\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(options.resolve ?? {}, {\n skipNodeModulesBundle: false\n }),\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":";;;;;;;;;;;;;;;;;AA0CA,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,UAAU;EACV,GAAG,KAAK,SAAS,CAAC,QAAQ,SAAS,CAAC;EACpC,UAAU;EACV,aAAa,CAAC,IAAI;EAClB,OAAO;EACP,WAAW;EACX,WAAW;EACX,aAAa;EACb,QAAQ;EACR,UAAU;EACV,WAAW;EACX,UAAU;CACZ,GACA,eAAe,OAAO,GACtB,EACE,SAAS,CACP,oBACE,uBAAuB,SAAS;EAC9B,MAAM,QAAQ,QAAQ,GAAG,aAAa,IAAI,EAAE;EAC5C,QAAQ;EACR,WAAW,KAAK,QAAQ,WAAW,CAAC,GAAG,EACrC,uBAAuB,MACzB,CAAC;EACD,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"}
@@ -0,0 +1,378 @@
1
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
+ const require_metadata = require('./metadata.cjs');
3
+ const require_type_checks = require('./type-checks.cjs');
4
+ const require_helpers = require('./helpers.cjs');
5
+ const require_validate = require('./validate.cjs');
6
+ let _stryke_convert_to_bool = require("@stryke/convert/to-bool");
7
+ let _stryke_type_checks = require("@stryke/type-checks");
8
+ let _stryke_type_checks_is_boolean = require("@stryke/type-checks/is-boolean");
9
+ let _stryke_type_checks_is_null = require("@stryke/type-checks/is-null");
10
+ let _stryke_type_checks_is_number = require("@stryke/type-checks/is-number");
11
+ let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
12
+ let _stryke_type_checks_is_undefined = require("@stryke/type-checks/is-undefined");
13
+ let ajv_dist_standalone_index_js = require("ajv/dist/standalone/index.js");
14
+ ajv_dist_standalone_index_js = require_runtime.__toESM(ajv_dist_standalone_index_js, 1);
15
+
16
+ //#region src/codegen.ts
17
+ /**
18
+ * Stringifies a value for generated TypeScript code.
19
+ */
20
+ function stringifyValue(value, type) {
21
+ return (0, _stryke_type_checks_is_undefined.isUndefined)(value) ? "undefined" : (0, _stryke_type_checks_is_null.isNull)(value) ? "null" : type === "boolean" || (0, _stryke_type_checks_is_boolean.isBoolean)(value) ? String((0, _stryke_convert_to_bool.toBool)(value)) : type === "number" || (0, _stryke_type_checks_is_number.isNumber)(value) ? Number.parseFloat(String(value)).toLocaleString(void 0, { maximumFractionDigits: 20 }) : type === "integer" ? Number.parseInt(String(value)).toLocaleString() : type === "string" || type === "object" || type === "array" ? JSON.stringify(value) : String(value);
22
+ }
23
+ /**
24
+ * Stringifies a JSON Schema fragment into a TypeScript-like type string.
25
+ */
26
+ function stringifyType(schema) {
27
+ if (!schema) return "unknown";
28
+ if (typeof schema === "boolean") return schema ? "unknown" : "never";
29
+ if (require_type_checks.isJsonSchemaObject(schema) && (0, _stryke_type_checks_is_set_string.isSetString)(schema.name)) return schema.name;
30
+ const objectSchema = schema;
31
+ if ((0, _stryke_type_checks_is_set_string.isSetString)(objectSchema.$ref)) return /^#\/(?:definitions|\$defs)\/(.+)$/.exec(objectSchema.$ref)?.[1] ?? objectSchema.$ref;
32
+ const primaryType = require_metadata.getPrimarySchemaType(schema);
33
+ if (primaryType) {
34
+ if (primaryType === "integer" || primaryType === "number") return "number";
35
+ return primaryType;
36
+ }
37
+ if (objectSchema.type === "array" && Array.isArray(objectSchema.enum)) return objectSchema.enum.map((value) => JSON.stringify(value)).join(" | ");
38
+ if (objectSchema.const !== void 0) return JSON.stringify(objectSchema.const);
39
+ if (objectSchema.type === "array" || objectSchema.items) return `${stringifyType(Array.isArray(objectSchema.items) ? objectSchema.items[0] : objectSchema.items)}[]`;
40
+ if (objectSchema.type === "object" || objectSchema.properties || objectSchema.additionalProperties) {
41
+ if (require_type_checks.isJsonSchema(objectSchema.additionalProperties)) return `{ [key: string]: ${stringifyType(objectSchema.additionalProperties)} }`;
42
+ if (require_type_checks.isJsonSchemaObject(objectSchema)) {
43
+ const required = objectSchema.required ?? [];
44
+ return `{ ${require_helpers.getPropertiesList(objectSchema).map((property) => {
45
+ const suffix = !required.includes(property.name) || require_helpers.isSchemaNullable(property) ? `${!required.includes(property.name) ? "?" : ""}${require_helpers.isSchemaNullable(property) ? " | null" : ""}` : "";
46
+ return `${property.name}${suffix}: ${stringifyType(property)}`;
47
+ }).join(";\n")} }`;
48
+ }
49
+ }
50
+ if (objectSchema.oneOf || objectSchema.anyOf) return (objectSchema.oneOf ?? objectSchema.anyOf ?? []).map((branch) => stringifyType(branch)).join(" | ");
51
+ if (objectSchema.allOf) return "object";
52
+ return "unknown";
53
+ }
54
+ /**
55
+ * Returns a string type representation of a value based on its type and an optional JSON Schema primitive type hint.
56
+ *
57
+ * @param value - The value whose type is to be represented as a string.
58
+ * @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.
59
+ */
60
+ function getJsonSchemaType(value) {
61
+ return (0, _stryke_type_checks_is_null.isNull)(value) ? "null" : (0, _stryke_type_checks_is_boolean.isBoolean)(value) ? "boolean" : (0, _stryke_type_checks.isInteger)(value) ? "integer" : (0, _stryke_type_checks_is_number.isNumber)(value) ? "number" : (0, _stryke_type_checks.isString)(value) ? "string" : (0, _stryke_type_checks.isObject)(value) ? "object" : Array.isArray(value) ? "array" : void 0;
62
+ }
63
+ /**
64
+ * Resolves a local JSON Schema `$ref` (e.g. `#/$defs/Name`) to the referenced definition name.
65
+ */
66
+ function resolveLocalRefName(ref) {
67
+ return /^#\/(?:definitions|\$defs)\/(.+)$/.exec(ref)?.[1];
68
+ }
69
+ /**
70
+ * Converts an arbitrary definition name into a safe JavaScript identifier suffix.
71
+ */
72
+ function toParserIdentifier(name) {
73
+ const cleaned = name.replace(/[^\w$]/gu, "_");
74
+ return `parse_${/^\d/u.test(cleaned) ? `_${cleaned}` : cleaned}`;
75
+ }
76
+ /**
77
+ * Returns the list of JSON Schema `type` keyword values declared on a fragment,
78
+ * preserving `object` and `array` (which {@link readSchemaTypes} intentionally drops).
79
+ */
80
+ function readDeclaredTypes(schema) {
81
+ const type = schema.type;
82
+ if (Array.isArray(type)) return [...type];
83
+ return type ? [type] : [];
84
+ }
85
+ /**
86
+ * Generates a JavaScript expression that builds a path string for a child element.
87
+ */
88
+ function childPath(pathExpr, segment) {
89
+ return `${pathExpr} + ${JSON.stringify(segment)}`;
90
+ }
91
+ /**
92
+ * Generates standalone parser code for a JSON Schema.
93
+ *
94
+ * @remarks
95
+ * The generated `parse` function reads an arbitrary input value and converts it
96
+ * into the shape described by the schema. It walks the schema recursively to:
97
+ *
98
+ * - resolve local `$ref` pointers (`#/$defs/*` and `#/definitions/*`) into
99
+ * dedicated parser functions so recursive schemas are supported,
100
+ * - apply `default` values for object properties (and root/array values) that
101
+ * are missing from the input,
102
+ * - coerce primitive values to the declared type (for example `"42"` to `42`
103
+ * for an `integer` schema, or `1` to `true` for a `boolean` schema),
104
+ * - validate `const`, `enum`, `oneOf`/`anyOf` and `allOf` constraints, and
105
+ * - collect detailed, path-aware errors and throw a `ParserError` when the
106
+ * input cannot be converted into a valid value.
107
+ *
108
+ * @param schema - The JSON Schema to generate parser code for.
109
+ * @returns The generated standalone parser code as a string.
110
+ */
111
+ function generateParserCode(schema) {
112
+ const rootSchema = typeof schema === "boolean" ? schema : schema;
113
+ const definitions = typeof rootSchema === "boolean" ? {} : {
114
+ ...rootSchema.definitions,
115
+ ...rootSchema.$defs
116
+ };
117
+ let tempCounter = 0;
118
+ function nextTemp(prefix) {
119
+ const id = tempCounter;
120
+ tempCounter += 1;
121
+ return `__${prefix}_${id}`;
122
+ }
123
+ function indent(lines, size = 2) {
124
+ const padding = " ".repeat(size);
125
+ return lines.map((line) => `${padding}${line}`);
126
+ }
127
+ /**
128
+ * Generates inline parsing statements for a schema fragment.
129
+ */
130
+ function generateStatements(fragment, valueExpr, pathExpr, targetVar, errorsVar = "errors") {
131
+ if (typeof fragment === "boolean") return fragment ? [`${targetVar} = ${valueExpr};`] : [`${errorsVar}.push({ path: ${pathExpr}, message: "No value is allowed at this location" });`, `${targetVar} = ${valueExpr};`];
132
+ const view = fragment;
133
+ if ((0, _stryke_type_checks_is_set_string.isSetString)(view.$ref)) {
134
+ const refName = resolveLocalRefName(view.$ref);
135
+ if (refName && refName in definitions) return [`${targetVar} = ${toParserIdentifier(refName)}(${valueExpr}, ${pathExpr}, ${errorsVar});`];
136
+ return [`${targetVar} = ${valueExpr};`];
137
+ }
138
+ const valueVar = nextTemp("value");
139
+ const pathVar = nextTemp("path");
140
+ const lines = [`const ${valueVar} = ${valueExpr};`, `const ${pathVar} = ${pathExpr};`];
141
+ if (view.default !== void 0) {
142
+ lines.push(`if (${valueVar} === undefined) {`, ` ${targetVar} = ${JSON.stringify(view.default)};`, `} else {`);
143
+ if (require_helpers.isSchemaNullable(view)) {
144
+ lines.push(` if (${valueVar} === null) {`, ` ${targetVar} = null;`, ` } else {`);
145
+ lines.push(...indent(generateCoreStatements(view, valueVar, pathVar, targetVar, errorsVar), 4));
146
+ lines.push(` }`);
147
+ } else lines.push(...indent(generateCoreStatements(view, valueVar, pathVar, targetVar, errorsVar), 2));
148
+ lines.push(`}`);
149
+ return lines;
150
+ }
151
+ lines.push(`if (${valueVar} === undefined) {`, ` ${errorsVar}.push({ path: ${pathVar}, message: "A value is required" });`, ` ${targetVar} = ${valueVar};`, `} else {`);
152
+ if (require_helpers.isSchemaNullable(view)) {
153
+ lines.push(` if (${valueVar} === null) {`, ` ${targetVar} = null;`, ` } else {`);
154
+ lines.push(...indent(generateCoreStatements(view, valueVar, pathVar, targetVar, errorsVar), 4));
155
+ lines.push(` }`);
156
+ } else lines.push(...indent(generateCoreStatements(view, valueVar, pathVar, targetVar, errorsVar), 2));
157
+ lines.push(`}`);
158
+ return lines;
159
+ }
160
+ /**
161
+ * Generates inline parsing statements assuming `value` is already defined.
162
+ */
163
+ function generateCoreStatements(view, valueVar, pathVar, targetVar, errorsVar) {
164
+ const lines = [];
165
+ if (view.const !== void 0) {
166
+ const constValue = JSON.stringify(view.const);
167
+ lines.push(`if (JSON.stringify(${valueVar}) !== ${constValue}) { ${errorsVar}.push({ path: ${pathVar}, message: "Expected the constant value " + ${constValue} }); }`, `${targetVar} = ${constValue};`);
168
+ return lines;
169
+ }
170
+ if (Array.isArray(view.enum)) {
171
+ const enumValues = JSON.stringify(view.enum);
172
+ lines.push(`if (!${enumValues}.some(allowed => JSON.stringify(allowed) === JSON.stringify(${valueVar}))) { ${errorsVar}.push({ path: ${pathVar}, message: "Expected one of " + ${enumValues} }); }`, `${targetVar} = ${valueVar};`);
173
+ return lines;
174
+ }
175
+ if (Array.isArray(view.oneOf) || Array.isArray(view.anyOf)) {
176
+ const branches = view.oneOf ?? view.anyOf ?? [];
177
+ const matchedVar = nextTemp("matched");
178
+ lines.push(`let ${matchedVar} = false;`);
179
+ for (const branch of branches) {
180
+ const branchErrorsVar = nextTemp("branchErrors");
181
+ const branchResultVar = nextTemp("branchResult");
182
+ lines.push(`if (!${matchedVar}) {`);
183
+ lines.push(` const ${branchErrorsVar}: { path: string; message: string }[] = [];`, ` let ${branchResultVar};`);
184
+ lines.push(...indent(generateStatements(branch, valueVar, pathVar, branchResultVar, branchErrorsVar), 2));
185
+ lines.push(` if (${branchErrorsVar}.length === 0) {`, ` ${targetVar} = ${branchResultVar};`, ` ${matchedVar} = true;`, ` }`, `}`);
186
+ }
187
+ lines.push(`if (!${matchedVar}) {`, ` ${errorsVar}.push({ path: ${pathVar}, message: "Value does not match any of the allowed schemas" });`, ` ${targetVar} = ${valueVar};`, `}`);
188
+ return lines;
189
+ }
190
+ if (Array.isArray(view.allOf)) {
191
+ const { allOf, ...rest } = view;
192
+ const merged = require_helpers.merge(rest, ...allOf);
193
+ lines.push(...generateStatements(merged, valueVar, pathVar, targetVar, errorsVar));
194
+ return lines;
195
+ }
196
+ const declaredTypes = readDeclaredTypes(view);
197
+ switch (require_metadata.getPrimarySchemaType(view) ?? declaredTypes.find((type) => type !== "null") ?? (view.properties ? "object" : view.items ? "array" : void 0)) {
198
+ case "object":
199
+ lines.push(...generateObjectStatements(view, valueVar, pathVar, targetVar, errorsVar));
200
+ break;
201
+ case "array":
202
+ lines.push(...generateArrayStatements(view, valueVar, pathVar, targetVar, errorsVar));
203
+ break;
204
+ case "string":
205
+ lines.push(`if (typeof ${valueVar} === "string") {`, ` ${targetVar} = ${valueVar};`, `} else if (typeof ${valueVar} === "number" || typeof ${valueVar} === "boolean") {`, ` ${targetVar} = String(${valueVar});`, `} else {`, ` ${errorsVar}.push({ path: ${pathVar}, message: "Expected a string value" });`, ` ${targetVar} = ${valueVar};`, `}`);
206
+ break;
207
+ case "integer":
208
+ lines.push(`if (typeof ${valueVar} === "number" && Number.isInteger(${valueVar})) {`, ` ${targetVar} = ${valueVar};`, `} else if (typeof ${valueVar} === "string" && ${valueVar}.trim() !== "" && Number.isInteger(Number(${valueVar}))) {`, ` ${targetVar} = Number(${valueVar});`, `} else if (typeof ${valueVar} === "boolean") {`, ` ${targetVar} = ${valueVar} ? 1 : 0;`, `} else {`, ` ${errorsVar}.push({ path: ${pathVar}, message: "Expected an integer value" });`, ` ${targetVar} = ${valueVar};`, `}`);
209
+ break;
210
+ case "number":
211
+ lines.push(`if (typeof ${valueVar} === "number") {`, ` ${targetVar} = ${valueVar};`, `} else if (typeof ${valueVar} === "string" && ${valueVar}.trim() !== "" && !Number.isNaN(Number(${valueVar}))) {`, ` ${targetVar} = Number(${valueVar});`, `} else if (typeof ${valueVar} === "boolean") {`, ` ${targetVar} = ${valueVar} ? 1 : 0;`, `} else {`, ` ${errorsVar}.push({ path: ${pathVar}, message: "Expected a number value" });`, ` ${targetVar} = ${valueVar};`, `}`);
212
+ break;
213
+ case "boolean":
214
+ lines.push(`if (typeof ${valueVar} === "boolean") {`, ` ${targetVar} = ${valueVar};`, `} else if (${valueVar} === "true" || ${valueVar} === 1) {`, ` ${targetVar} = true;`, `} else if (${valueVar} === "false" || ${valueVar} === 0) {`, ` ${targetVar} = false;`, `} else {`, ` ${errorsVar}.push({ path: ${pathVar}, message: "Expected a boolean value" });`, ` ${targetVar} = ${valueVar};`, `}`);
215
+ break;
216
+ case "null":
217
+ lines.push(`if (${valueVar} === null) {`, ` ${targetVar} = null;`, `} else {`, ` ${errorsVar}.push({ path: ${pathVar}, message: "Expected a null value" });`, ` ${targetVar} = ${valueVar};`, `}`);
218
+ break;
219
+ case void 0:
220
+ default:
221
+ lines.push(`${targetVar} = ${valueVar};`);
222
+ break;
223
+ }
224
+ return lines;
225
+ }
226
+ /**
227
+ * Generates the parsing statements for an `object` schema, applying property
228
+ * defaults and recursing into each declared property.
229
+ */
230
+ function generateObjectStatements(view, valueVar, pathVar, targetVar, errorsVar) {
231
+ const type = stringifyType(view);
232
+ const lines = [
233
+ `if (typeof ${valueVar} !== "object" || ${valueVar} === null || Array.isArray(${valueVar})) {`,
234
+ ` ${errorsVar}.push({ path: ${pathVar}, message: "Expected an object value" });`,
235
+ ` ${targetVar} = ${valueVar};`,
236
+ `} else {`
237
+ ];
238
+ const resultVar = nextTemp("object");
239
+ lines.push(` const ${resultVar} = {}${type ? ` as ${type}` : ""};`);
240
+ const properties = require_type_checks.isJsonSchemaObject(view) ? require_helpers.getPropertiesList(view) : [];
241
+ const propertyNames = /* @__PURE__ */ new Set();
242
+ for (const property of properties) {
243
+ const name = property.name;
244
+ propertyNames.add(name);
245
+ const accessor = `${valueVar}[${JSON.stringify(name)}]`;
246
+ const propertyPath = childPath(pathVar, `.${name}`);
247
+ const propertyVar = nextTemp("property");
248
+ const missingBranch = property.default !== void 0 ? `${resultVar}[${JSON.stringify(name)}] = ${JSON.stringify(property.default)};` : property.required ? `errors.push({ path: ${propertyPath}, message: "Required property is missing" });` : ``;
249
+ lines.push(` if (${accessor} !== undefined) {`, ` let ${propertyVar};`);
250
+ lines.push(...indent(generateStatements(property, accessor, propertyPath, propertyVar, errorsVar), 4));
251
+ lines.push(` ${resultVar}[${JSON.stringify(name)}] = ${propertyVar};`);
252
+ if (missingBranch) lines.push(` } else { ${missingBranch} }`);
253
+ else lines.push(` }`);
254
+ }
255
+ const additional = view.additionalProperties;
256
+ if (require_type_checks.isJsonSchema(additional)) {
257
+ const additionalVar = nextTemp("additional");
258
+ lines.push(` for (const key of Object.keys(${valueVar})) {`, ` if (${JSON.stringify([...propertyNames])}.includes(key)) { continue; }`, ` let ${additionalVar};`);
259
+ lines.push(...indent(generateStatements(additional, `${valueVar}[key]`, `${pathVar} + "." + key`, additionalVar, errorsVar), 4));
260
+ lines.push(` ${resultVar}[key] = ${additionalVar};`, `}`);
261
+ } else if (additional !== false) lines.push(` for (const key of Object.keys(${valueVar})) {`, ` if (${JSON.stringify([...propertyNames])}.includes(key)) { continue; }`, ` ${resultVar}[key] = ${valueVar}[key];`, `}`);
262
+ lines.push(` ${targetVar} = ${resultVar};`, `}`);
263
+ return lines;
264
+ }
265
+ /**
266
+ * Generates the parsing statements for an `array` schema, recursing into each
267
+ * item (supporting both list and tuple `items`/`prefixItems` forms).
268
+ */
269
+ function generateArrayStatements(view, valueVar, pathVar, targetVar, errorsVar) {
270
+ const lines = [
271
+ `if (!Array.isArray(${valueVar})) {`,
272
+ ` ${errorsVar}.push({ path: ${pathVar}, message: "Expected an array value" });`,
273
+ ` ${targetVar} = ${valueVar};`,
274
+ `} else {`
275
+ ];
276
+ const resultVar = nextTemp("array");
277
+ lines.push(` const ${resultVar}: unknown[] = [];`);
278
+ const tupleItems = view.prefixItems ?? (Array.isArray(view.items) ? view.items : void 0);
279
+ if (tupleItems) {
280
+ const listItems = !Array.isArray(view.items) ? view.items : void 0;
281
+ lines.push(` for (let index = 0; index < ${valueVar}.length; index += 1) {`, ` const item = ${valueVar}[index];`, ` let itemResult;`);
282
+ tupleItems.forEach((item, index) => {
283
+ lines.push(`${index === 0 ? " if" : " else if"} (index === ${index}) {`);
284
+ lines.push(...indent(generateStatements(item, "item", childPath(pathVar, `[${index}]`), "itemResult", errorsVar), 6));
285
+ lines.push(` }`);
286
+ });
287
+ if (listItems) {
288
+ lines.push(` else {`);
289
+ lines.push(...indent(generateStatements(listItems, "item", `${pathVar} + "[" + index + "]"`, "itemResult", errorsVar), 6));
290
+ lines.push(` }`);
291
+ } else lines.push(` else { itemResult = item; }`);
292
+ lines.push(` ${resultVar}.push(itemResult);`, ` }`, ` ${targetVar} = ${resultVar};`, `}`);
293
+ return lines;
294
+ }
295
+ const itemSchema = view.items ?? true;
296
+ lines.push(` for (let index = 0; index < ${valueVar}.length; index += 1) {`, ` const item = ${valueVar}[index];`, ` let itemResult;`);
297
+ lines.push(...indent(generateStatements(itemSchema, "item", `${pathVar} + "[" + index + "]"`, "itemResult", errorsVar), 4));
298
+ lines.push(` ${resultVar}.push(itemResult);`, ` }`, ` ${targetVar} = ${resultVar};`, `}`);
299
+ return lines;
300
+ }
301
+ return `/**
302
+ * Error thrown when an input value cannot be parsed into the type described by the JSON Schema.
303
+ */
304
+ export class ParserError extends Error {
305
+ public override name = "ParserError";
306
+
307
+ public errors: { path: string; message: string }[];
308
+
309
+ public constructor(errors: { path: string; message: string }[]) {
310
+ super(
311
+ "Failed to parse the provided value against the JSON Schema:\\n" +
312
+ errors.map(error => " - " + error.path + ": " + error.message).join("\\n")
313
+ );
314
+
315
+ this.errors = errors;
316
+ }
317
+ }
318
+
319
+ ${Object.entries(definitions).map(([name, definition]) => `function ${toParserIdentifier(name)}(value, path, errors) {\n let result;\n${indent(generateStatements(definition, "value", "path", "result", "errors")).join("\n")}\n\n return result;\n}`).join("\n\n")}
320
+
321
+ /**
322
+ * Parses an input value into the type described by the JSON Schema.
323
+ *
324
+ * @remarks
325
+ * The parser applies default values for missing properties, coerces primitive values to the declared type, and throws a {@link ParserError} (containing a detailed list of validation errors) when the value cannot be converted into a valid result.
326
+ *
327
+ * @param value - The input value to parse.
328
+ * @returns The parsed value conforming to the schema.
329
+ */
330
+ export function parse(value: unknown)${schema.name ? `: ${stringifyType(schema)}` : ""} {
331
+ const errors: { path: string; message: string }[] = [];
332
+
333
+ let result;
334
+ ${indent(generateStatements(schema, "value", "\"$\"", "result", "errors")).join("\n")}
335
+
336
+ if (errors.length > 0) {
337
+ throw new ParserError(errors);
338
+ }
339
+
340
+ return result;
341
+ }`;
342
+ }
343
+ /**
344
+ * Generates standalone JSON Schema validation code using Ajv.
345
+ *
346
+ * @remarks
347
+ * The generated code includes a validation function that can be used to validate data against the provided JSON Schema at runtime. The validation function will throw an error if the data does not conform to the schema, providing detailed information about the validation errors.
348
+ *
349
+ * @param schema - The JSON Schema to generate validation code for.
350
+ * @param refsOrFuncts - Optional additional references or functions for Ajv's standalone code generation.
351
+ * @returns The generated standalone validation code as a string.
352
+ */
353
+ function generateValidationCode(schema, refsOrFuncts) {
354
+ return (0, ajv_dist_standalone_index_js.default)(require_validate.getValidator(schema), refsOrFuncts);
355
+ }
356
+ /**
357
+ * Generates standalone JavaScript code for validating and parsing data according to a JSON Schema.
358
+ *
359
+ * @remarks
360
+ * The generated code includes:
361
+ * - Validation code generated by Ajv for the provided JSON Schema, which can be used to validate data against the schema at runtime. The validation function will throw an error if the data does not conform to the schema, providing detailed information about the validation errors.
362
+ * - Parsing code generated for the provided JSON Schema, which can be used to parse and validate data against the schema at runtime. The parsing function will apply default values specified in the schema if they are not present in the input data, throw an error if the input data does not conform to the schema (providing detailed information about the validation errors), and return the parsed data if it is valid according to the schema.
363
+ *
364
+ * @param schema - The JSON Schema to generate code for.
365
+ * @param refsOrFuncts - Optional additional references or functions for Ajv's standalone code generation.
366
+ * @returns The generated standalone validation and parsing code as a string.
367
+ */
368
+ function generateCode(schema, refsOrFuncts) {
369
+ return `${generateValidationCode(schema, refsOrFuncts)}\n\n${generateParserCode(schema)}`;
370
+ }
371
+
372
+ //#endregion
373
+ exports.generateCode = generateCode;
374
+ exports.generateParserCode = generateParserCode;
375
+ exports.generateValidationCode = generateValidationCode;
376
+ exports.getJsonSchemaType = getJsonSchemaType;
377
+ exports.stringifyType = stringifyType;
378
+ exports.stringifyValue = stringifyValue;
@@ -0,0 +1,67 @@
1
+ import { JsonSchema, JsonSchemaType } from "./types.cjs";
2
+ import standaloneCode from "ajv/dist/standalone/index.js";
3
+
4
+ //#region src/codegen.d.ts
5
+ /**
6
+ * Stringifies a value for generated TypeScript code.
7
+ */
8
+ declare function stringifyValue(value?: unknown, type?: JsonSchemaType | string): string;
9
+ /**
10
+ * Stringifies a JSON Schema fragment into a TypeScript-like type string.
11
+ */
12
+ declare function stringifyType(schema?: JsonSchema): string;
13
+ /**
14
+ * Returns a string type representation of a value based on its type and an optional JSON Schema primitive type hint.
15
+ *
16
+ * @param value - The value whose type is to be represented as a string.
17
+ * @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.
18
+ */
19
+ declare function getJsonSchemaType(value?: unknown): JsonSchemaType | undefined;
20
+ /**
21
+ * Generates standalone parser code for a JSON Schema.
22
+ *
23
+ * @remarks
24
+ * The generated `parse` function reads an arbitrary input value and converts it
25
+ * into the shape described by the schema. It walks the schema recursively to:
26
+ *
27
+ * - resolve local `$ref` pointers (`#/$defs/*` and `#/definitions/*`) into
28
+ * dedicated parser functions so recursive schemas are supported,
29
+ * - apply `default` values for object properties (and root/array values) that
30
+ * are missing from the input,
31
+ * - coerce primitive values to the declared type (for example `"42"` to `42`
32
+ * for an `integer` schema, or `1` to `true` for a `boolean` schema),
33
+ * - validate `const`, `enum`, `oneOf`/`anyOf` and `allOf` constraints, and
34
+ * - collect detailed, path-aware errors and throw a `ParserError` when the
35
+ * input cannot be converted into a valid value.
36
+ *
37
+ * @param schema - The JSON Schema to generate parser code for.
38
+ * @returns The generated standalone parser code as a string.
39
+ */
40
+ declare function generateParserCode(schema: JsonSchema): string;
41
+ /**
42
+ * Generates standalone JSON Schema validation code using Ajv.
43
+ *
44
+ * @remarks
45
+ * The generated code includes a validation function that can be used to validate data against the provided JSON Schema at runtime. The validation function will throw an error if the data does not conform to the schema, providing detailed information about the validation errors.
46
+ *
47
+ * @param schema - The JSON Schema to generate validation code for.
48
+ * @param refsOrFuncts - Optional additional references or functions for Ajv's standalone code generation.
49
+ * @returns The generated standalone validation code as a string.
50
+ */
51
+ declare function generateValidationCode(schema: JsonSchema, refsOrFuncts?: Parameters<typeof standaloneCode>[1]): string;
52
+ /**
53
+ * Generates standalone JavaScript code for validating and parsing data according to a JSON Schema.
54
+ *
55
+ * @remarks
56
+ * The generated code includes:
57
+ * - Validation code generated by Ajv for the provided JSON Schema, which can be used to validate data against the schema at runtime. The validation function will throw an error if the data does not conform to the schema, providing detailed information about the validation errors.
58
+ * - Parsing code generated for the provided JSON Schema, which can be used to parse and validate data against the schema at runtime. The parsing function will apply default values specified in the schema if they are not present in the input data, throw an error if the input data does not conform to the schema (providing detailed information about the validation errors), and return the parsed data if it is valid according to the schema.
59
+ *
60
+ * @param schema - The JSON Schema to generate code for.
61
+ * @param refsOrFuncts - Optional additional references or functions for Ajv's standalone code generation.
62
+ * @returns The generated standalone validation and parsing code as a string.
63
+ */
64
+ declare function generateCode(schema: JsonSchema, refsOrFuncts?: Parameters<typeof standaloneCode>[1]): string;
65
+ //#endregion
66
+ export { generateCode, generateParserCode, generateValidationCode, getJsonSchemaType, stringifyType, stringifyValue };
67
+ //# sourceMappingURL=codegen.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codegen.d.cts","names":[],"sources":["../src/codegen.ts"],"mappings":";;;;;;AAqDA;iBAAgB,cAAA,CACd,KAAA,YACA,IAAA,GAAO,cAAc;;;;iBAsBP,aAAA,CAAc,MAAmB,GAAV,UAAU;;;AAtBjB;AAsBhC;;;iBA8FgB,iBAAA,CAAkB,KAAA,aAAkB,cAAc;AA9FjB;AA8FjD;;;;AAAkE;AA0ElE;;;;AAAqD;AAqmBrD;;;;;;;;;AA7wBiD,iBAwKjC,kBAAA,CAAmB,MAAkB,EAAV,UAAU;;;;;AAumBA;AAiBrD;;;;;iBAnBgB,sBAAA,CACd,MAAA,EAAQ,UAAA,EACR,YAAA,GAAe,UAAA,QAAkB,cAAA;;;;;;;;;AAmBkB;;;;iBAFrC,YAAA,CACd,MAAA,EAAQ,UAAA,EACR,YAAA,GAAe,UAAA,QAAkB,cAAA"}