@powerlines/schema 0.9.5 → 0.10.0

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 (45) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/bundle.cjs +48 -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 +46 -0
  8. package/dist/bundle.mjs.map +1 -0
  9. package/dist/extract.cjs +90 -1
  10. package/dist/extract.d.cts +37 -1
  11. package/dist/extract.d.cts.map +1 -1
  12. package/dist/extract.d.mts +37 -1
  13. package/dist/extract.d.mts.map +1 -1
  14. package/dist/extract.mjs +87 -3
  15. package/dist/extract.mjs.map +1 -1
  16. package/dist/index.cjs +15 -1
  17. package/dist/index.d.cts +7 -3
  18. package/dist/index.d.mts +7 -3
  19. package/dist/index.mjs +6 -2
  20. package/dist/is-schema-definition.cjs +18 -0
  21. package/dist/is-schema-definition.d.cts +13 -0
  22. package/dist/is-schema-definition.d.cts.map +1 -0
  23. package/dist/is-schema-definition.d.mts +13 -0
  24. package/dist/is-schema-definition.d.mts.map +1 -0
  25. package/dist/is-schema-definition.mjs +17 -0
  26. package/dist/is-schema-definition.mjs.map +1 -0
  27. package/dist/reflection.cjs +191 -0
  28. package/dist/reflection.d.cts +21 -0
  29. package/dist/reflection.d.cts.map +1 -0
  30. package/dist/reflection.d.mts +21 -0
  31. package/dist/reflection.d.mts.map +1 -0
  32. package/dist/reflection.mjs +189 -0
  33. package/dist/reflection.mjs.map +1 -0
  34. package/dist/resolve.cjs +84 -0
  35. package/dist/resolve.d.cts +36 -0
  36. package/dist/resolve.d.cts.map +1 -0
  37. package/dist/resolve.d.mts +36 -0
  38. package/dist/resolve.d.mts.map +1 -0
  39. package/dist/resolve.mjs +80 -0
  40. package/dist/resolve.mjs.map +1 -0
  41. package/dist/types.d.cts +31 -3
  42. package/dist/types.d.cts.map +1 -1
  43. package/dist/types.d.mts +31 -3
  44. package/dist/types.d.mts.map +1 -1
  45. package/package.json +28 -6
@@ -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,48 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ let _powerlines_core_lib_unplugin = require("@powerlines/core/lib/unplugin");
4
+ let _powerlines_unplugin_esbuild = require("@powerlines/unplugin/esbuild");
5
+ let _stryke_helpers_omit = require("@stryke/helpers/omit");
6
+ let _stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
7
+ let defu = require("defu");
8
+ defu = require_runtime.__toESM(defu, 1);
9
+ let esbuild = require("esbuild");
10
+ let unplugin = require("unplugin");
11
+
12
+ //#region src/bundle.ts
13
+ /**
14
+ * Bundle a type definition to a module.
15
+ *
16
+ * @param context - The context object containing the environment paths.
17
+ * @param file - The file path to bundle.
18
+ * @param options - Optional overrides for the ESBuild configuration.
19
+ * @returns A promise that resolves to the bundled module.
20
+ */
21
+ async function bundle(context, file, options = {}) {
22
+ const path = await context.fs.resolve(file);
23
+ if (!path || !context.fs.existsSync(path)) throw new Error(`Module not found: "${file}". Please check the path and try again.`);
24
+ const result = await (0, esbuild.build)((0, defu.default)({
25
+ entryPoints: [path],
26
+ write: false,
27
+ sourcemap: false,
28
+ splitting: false,
29
+ treeShaking: true,
30
+ bundle: true,
31
+ packages: "bundle",
32
+ platform: "node",
33
+ logLevel: "silent",
34
+ ...(0, _stryke_helpers_omit.omit)(options, ["name", "resolve"])
35
+ }, (0, _powerlines_unplugin_esbuild.resolveOptions)(context), { plugins: [(0, unplugin.createEsbuildPlugin)((0, _powerlines_core_lib_unplugin.createUnpluginResolver)(context, {
36
+ name: options.name ?? `${(0, _stryke_path_file_path_fns.findFileName)(file)} Bundler`,
37
+ prefix: false,
38
+ overrides: (0, defu.default)(options.resolve ?? {}, { skipNodeModulesBundle: false }, context.config.resolve),
39
+ silenceHookLogging: true
40
+ }))()] }));
41
+ if (result.errors.length > 0) throw new Error(`Failed to bundle ${file}: ${result.errors.map((error) => error.text).join(", ")}`);
42
+ if (result.warnings.length > 0) context.warn(`Warnings while bundling ${file}: ${result.warnings.map((warning) => warning.text).join(", ")}`);
43
+ 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.`);
44
+ return result.outputFiles.filter(Boolean)[0];
45
+ }
46
+
47
+ //#endregion
48
+ exports.bundle = bundle;
@@ -0,0 +1,21 @@
1
+ import { PluginContext, ResolveOptions } 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 PluginContext = PluginContext>(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":";;;;;KAiCY,aAAA,GAAgB,WAAA,CAAY,YAAA;EACtC,IAAA;EACA,OAAA,GAAU,WAAA,CAAY,cAAA;AAAA;;;;;;;;;iBAWF,MAAA,kBAAwB,aAAA,GAAgB,aAAA,CAAA,CAC5D,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 { PluginContext, ResolveOptions } 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 PluginContext = PluginContext>(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":";;;;;KAiCY,aAAA,GAAgB,WAAA,CAAY,YAAA;EACtC,IAAA;EACA,OAAA,GAAU,WAAA,CAAY,cAAA;AAAA;;;;;;;;;iBAWF,MAAA,kBAAwB,aAAA,GAAgB,aAAA,CAAA,CAC5D,OAAA,EAAS,QAAA,EACT,IAAA,UACA,OAAA,GAAS,aAAA,GACR,OAAA,CAAQ,UAAA"}
@@ -0,0 +1,46 @@
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
+ entryPoints: [path],
23
+ write: false,
24
+ sourcemap: false,
25
+ splitting: false,
26
+ treeShaking: true,
27
+ bundle: true,
28
+ packages: "bundle",
29
+ platform: "node",
30
+ logLevel: "silent",
31
+ ...omit(options, ["name", "resolve"])
32
+ }, resolveOptions(context), { plugins: [createEsbuildPlugin(createUnpluginResolver(context, {
33
+ name: options.name ?? `${findFileName(file)} Bundler`,
34
+ prefix: false,
35
+ overrides: defu(options.resolve ?? {}, { skipNodeModulesBundle: false }, context.config.resolve),
36
+ silenceHookLogging: true
37
+ }))()] }));
38
+ if (result.errors.length > 0) throw new Error(`Failed to bundle ${file}: ${result.errors.map((error) => error.text).join(", ")}`);
39
+ if (result.warnings.length > 0) context.warn(`Warnings while bundling ${file}: ${result.warnings.map((warning) => warning.text).join(", ")}`);
40
+ 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.`);
41
+ return result.outputFiles.filter(Boolean)[0];
42
+ }
43
+
44
+ //#endregion
45
+ export { bundle };
46
+ //# 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 {\n CreateUnpluginResolverOptions,\n PluginContext,\n ResolveOptions\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 PluginContext = PluginContext>(\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,EAAE,EACN;CACrB,MAAM,OAAO,MAAM,QAAQ,GAAG,QAAQ,KAAK;AAC3C,KAAI,CAAC,QAAQ,CAAC,QAAQ,GAAG,WAAW,KAAK,CACvC,OAAM,IAAI,MACR,sBAAsB,KAAK,yCAC5B;CAGH,MAAM,SAAS,MAAM,MACnB,KACE;EACE,aAAa,CAAC,KAAK;EACnB,OAAO;EACP,WAAW;EACX,WAAW;EACX,aAAa;EACb,QAAQ;EACR,UAAU;EACV,UAAU;EACV,UAAU;EACV,GAAG,KAAK,SAAS,CAAC,QAAQ,UAAU,CAAC;EACtC,EACD,eAAe,QAAQ,EACvB,EACE,SAAS,CACP,oBACE,uBAAuB,SAAS;EAC9B,MAAM,QAAQ,QAAQ,GAAG,aAAa,KAAK,CAAC;EAC5C,QAAQ;EACR,WAAW,KACT,QAAQ,WAAW,EAAE,EACrB,EAAE,uBAAuB,OAAO,EAChC,QAAQ,OAAO,QAChB;EACD,oBAAoB;EACrB,CAAC,CACH,EAAE,CACJ,EACF,CACF,CACF;AACD,KAAI,OAAO,OAAO,SAAS,EACzB,OAAM,IAAI,MACR,oBAAoB,KAAK,IAAI,OAAO,OACjC,KAAI,UAAS,MAAM,KAAK,CACxB,KAAK,KAAK,GACd;AAEH,KAAI,OAAO,SAAS,SAAS,EAC3B,SAAQ,KACN,2BAA2B,KAAK,IAAI,OAAO,SACxC,KAAI,YAAW,QAAQ,KAAK,CAC5B,KAAK,KAAK,GACd;AAEH,KAAI,CAAC,OAAO,eAAe,OAAO,YAAY,OAAO,QAAQ,CAAC,WAAW,EACvE,OAAM,IAAI,MACR,iCACE,KACD,iDACF;AAGH,QAAO,OAAO,YAAY,OAAO,QAAQ,CAAC"}
package/dist/extract.cjs CHANGED
@@ -1,10 +1,33 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ const require_is_schema_definition = require('./is-schema-definition.cjs');
4
+ const require_reflection = require('./reflection.cjs');
5
+ const require_resolve = require('./resolve.cjs');
6
+ let defu = require("defu");
7
+ defu = require_runtime.__toESM(defu, 1);
8
+ let _powerlines_core = require("@powerlines/core");
9
+ let _powerlines_deepkit_esbuild_plugin = require("@powerlines/deepkit/esbuild-plugin");
10
+ let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
2
11
  let _stryke_json = require("@stryke/json");
12
+ let _stryke_type_checks = require("@stryke/type-checks");
3
13
  let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
4
14
  let _stryke_zod = require("@stryke/zod");
5
15
 
6
16
  //#region src/extract.ts
7
17
  /**
18
+ * Converts a reflected Deepkit {@link @powerlines/deepkit/vendor/type#Type} into a JSON Schema (draft-07) representation.
19
+ *
20
+ * @remarks
21
+ * This function delegates to an internal recursive walker that handles the full set of Deepkit reflection kinds.
22
+ *
23
+ * @param reflection - The reflected Deepkit Type to convert.
24
+ * @returns A JSON Schema (draft-07) fragment representing the type, or `undefined` when no schema could be produced.
25
+ */
26
+ function extractReflection(reflection) {
27
+ if (!(0, _powerlines_deepkit_vendor_type.isType)(reflection)) return;
28
+ return require_reflection.reflectionToJsonSchema(reflection);
29
+ }
30
+ /**
8
31
  * Extracts a JSON Schema object from a given schema definition, if possible.
9
32
  *
10
33
  * @remarks
@@ -22,6 +45,72 @@ function extractJsonSchema(schema) {
22
45
  if ((0, _stryke_json.isJsonSchema7ObjectType)(jsonSchema)) return jsonSchema;
23
46
  }
24
47
  }
48
+ /**
49
+ * Extracts a schema definition from a given input object, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object. The function checks the type of the input and attempts to extract the corresponding schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns a `SchemaDefinition` containing the extracted schema and its variant if successful; otherwise, it throws an error.
50
+ *
51
+ * @param input - The input object to extract the schema definition from.
52
+ * @returns A `SchemaDefinition` containing the extracted schema and its variant if successful.
53
+ * @throws An error if the input does not contain a valid schema definition.
54
+ */
55
+ function extractSchema(input) {
56
+ if ((0, _stryke_type_checks_is_set_object.isSetObject)(input)) {
57
+ if ((0, _stryke_zod.isZod3Type)(input)) {
58
+ const schema = extractJsonSchema(input);
59
+ if (schema) return {
60
+ schema,
61
+ variant: "zod3",
62
+ input
63
+ };
64
+ } else if ((0, _stryke_json.isStandardJsonSchema)(input)) {
65
+ const schema = extractJsonSchema(input);
66
+ if (schema) return {
67
+ schema,
68
+ variant: "standard-schema",
69
+ input
70
+ };
71
+ } else if ((0, _stryke_json.isJsonSchema7ObjectType)(input)) {
72
+ const schema = extractJsonSchema(input);
73
+ if (schema) return {
74
+ schema,
75
+ variant: "json-schema",
76
+ input
77
+ };
78
+ } else if ((0, _powerlines_deepkit_vendor_type.isType)(input)) {
79
+ const schema = extractReflection(input);
80
+ if (schema) return {
81
+ schema,
82
+ variant: "reflection",
83
+ input
84
+ };
85
+ }
86
+ }
87
+ throw new Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object.`);
88
+ }
89
+ /**
90
+ * Resolves the provided entry points to their corresponding type definitions. The function accepts an array of entry points, which can be strings (file paths) or type definition objects. It processes each entry point, resolving file paths and glob patterns to find matching files. For each resolved file, it creates a type definition object and resolves it using the `resolveInput` function. The function returns an array of resolved entry type definitions.
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * const schema = await extract(context, "./schemas/*.ts");
95
+ * ```
96
+ *
97
+ * @param context - The plugin context used for resolving the schema definition input.
98
+ * @param input - The schema definition input to extract the JSON Schema from. This can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a TypeScript type definition.
99
+ * @param options - Optional overrides for the ESBuild configuration used during resolution.
100
+ * @returns A promise that resolves to a SchemaDefinition containing the extracted JSON Schema and its variant, or the bytecode if JSON Schema extraction is not possible.
101
+ */
102
+ async function extract(context, input, options = {}) {
103
+ if (require_is_schema_definition.isSchemaDefinition(input)) return input;
104
+ let inputObject = input;
105
+ if ((0, _stryke_type_checks.isSetString)(input) || (0, _powerlines_core.isTypeDefinition)(input)) inputObject = await require_resolve.resolve(context, input, (0, defu.default)(options, { plugins: [(0, _powerlines_deepkit_esbuild_plugin.esbuildPlugin)(context, {
106
+ reflection: "default",
107
+ level: "all"
108
+ })] }));
109
+ return extractSchema(inputObject);
110
+ }
25
111
 
26
112
  //#endregion
27
- exports.extractJsonSchema = extractJsonSchema;
113
+ exports.extract = extract;
114
+ exports.extractJsonSchema = extractJsonSchema;
115
+ exports.extractReflection = extractReflection;
116
+ exports.extractSchema = extractSchema;
@@ -1,6 +1,20 @@
1
+ import { SchemaDefinition, SchemaDefinitionInput, SchemaDefinitionParameter } from "./types.cjs";
2
+ import { PluginContext } from "@powerlines/core";
3
+ import { BuildOptions } from "esbuild";
4
+ import { Type } from "@powerlines/deepkit/vendor/type";
1
5
  import { JsonSchema7Type } from "@stryke/json";
2
6
 
3
7
  //#region src/extract.d.ts
8
+ /**
9
+ * Converts a reflected Deepkit {@link @powerlines/deepkit/vendor/type#Type} into a JSON Schema (draft-07) representation.
10
+ *
11
+ * @remarks
12
+ * This function delegates to an internal recursive walker that handles the full set of Deepkit reflection kinds.
13
+ *
14
+ * @param reflection - The reflected Deepkit Type to convert.
15
+ * @returns A JSON Schema (draft-07) fragment representing the type, or `undefined` when no schema could be produced.
16
+ */
17
+ declare function extractReflection(reflection: Type): JsonSchema7Type | undefined;
4
18
  /**
5
19
  * Extracts a JSON Schema object from a given schema definition, if possible.
6
20
  *
@@ -11,6 +25,28 @@ import { JsonSchema7Type } from "@stryke/json";
11
25
  * @returns The extracted JSON Schema (draft-07) object if successful, otherwise undefined.
12
26
  */
13
27
  declare function extractJsonSchema(schema: unknown): JsonSchema7Type | undefined;
28
+ /**
29
+ * Extracts a schema definition from a given input object, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object. The function checks the type of the input and attempts to extract the corresponding schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns a `SchemaDefinition` containing the extracted schema and its variant if successful; otherwise, it throws an error.
30
+ *
31
+ * @param input - The input object to extract the schema definition from.
32
+ * @returns A `SchemaDefinition` containing the extracted schema and its variant if successful.
33
+ * @throws An error if the input does not contain a valid schema definition.
34
+ */
35
+ declare function extractSchema(input: SchemaDefinitionInput): SchemaDefinition;
36
+ /**
37
+ * Resolves the provided entry points to their corresponding type definitions. The function accepts an array of entry points, which can be strings (file paths) or type definition objects. It processes each entry point, resolving file paths and glob patterns to find matching files. For each resolved file, it creates a type definition object and resolves it using the `resolveInput` function. The function returns an array of resolved entry type definitions.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * const schema = await extract(context, "./schemas/*.ts");
42
+ * ```
43
+ *
44
+ * @param context - The plugin context used for resolving the schema definition input.
45
+ * @param input - The schema definition input to extract the JSON Schema from. This can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a TypeScript type definition.
46
+ * @param options - Optional overrides for the ESBuild configuration used during resolution.
47
+ * @returns A promise that resolves to a SchemaDefinition containing the extracted JSON Schema and its variant, or the bytecode if JSON Schema extraction is not possible.
48
+ */
49
+ declare function extract<TContext extends PluginContext = PluginContext>(context: TContext, input: SchemaDefinitionParameter, options?: Partial<BuildOptions>): Promise<SchemaDefinition>;
14
50
  //#endregion
15
- export { extractJsonSchema };
51
+ export { extract, extractJsonSchema, extractReflection, extractSchema };
16
52
  //# sourceMappingURL=extract.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract.d.cts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;AAgCA;;;;;;;iBAAgB,iBAAA,CACd,MAAA,YACC,eAAA"}
1
+ {"version":3,"file":"extract.d.cts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;;;;;AA+CA;;;;;;;iBAAgB,iBAAA,CACd,UAAA,EAAY,IAAA,GACX,eAAA;;AAiBH;;;;;AAmCA;;;iBAnCgB,iBAAA,CACd,MAAA,YACC,eAAA;;;;;;AA4FH;;iBA3DgB,aAAA,CAAc,KAAA,EAAO,qBAAA,GAAwB,gBAAA;;;;;;;;;;;;;;iBA2DvC,OAAA,kBAAyB,aAAA,GAAgB,aAAA,CAAA,CAC7D,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,yBAAA,EACP,OAAA,GAAS,OAAA,CAAQ,YAAA,IAChB,OAAA,CAAQ,gBAAA"}
@@ -1,6 +1,20 @@
1
+ import { SchemaDefinition, SchemaDefinitionInput, SchemaDefinitionParameter } from "./types.mjs";
2
+ import { BuildOptions } from "esbuild";
3
+ import { PluginContext } from "@powerlines/core";
4
+ import { Type } from "@powerlines/deepkit/vendor/type";
1
5
  import { JsonSchema7Type } from "@stryke/json";
2
6
 
3
7
  //#region src/extract.d.ts
8
+ /**
9
+ * Converts a reflected Deepkit {@link @powerlines/deepkit/vendor/type#Type} into a JSON Schema (draft-07) representation.
10
+ *
11
+ * @remarks
12
+ * This function delegates to an internal recursive walker that handles the full set of Deepkit reflection kinds.
13
+ *
14
+ * @param reflection - The reflected Deepkit Type to convert.
15
+ * @returns A JSON Schema (draft-07) fragment representing the type, or `undefined` when no schema could be produced.
16
+ */
17
+ declare function extractReflection(reflection: Type): JsonSchema7Type | undefined;
4
18
  /**
5
19
  * Extracts a JSON Schema object from a given schema definition, if possible.
6
20
  *
@@ -11,6 +25,28 @@ import { JsonSchema7Type } from "@stryke/json";
11
25
  * @returns The extracted JSON Schema (draft-07) object if successful, otherwise undefined.
12
26
  */
13
27
  declare function extractJsonSchema(schema: unknown): JsonSchema7Type | undefined;
28
+ /**
29
+ * Extracts a schema definition from a given input object, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object. The function checks the type of the input and attempts to extract the corresponding schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns a `SchemaDefinition` containing the extracted schema and its variant if successful; otherwise, it throws an error.
30
+ *
31
+ * @param input - The input object to extract the schema definition from.
32
+ * @returns A `SchemaDefinition` containing the extracted schema and its variant if successful.
33
+ * @throws An error if the input does not contain a valid schema definition.
34
+ */
35
+ declare function extractSchema(input: SchemaDefinitionInput): SchemaDefinition;
36
+ /**
37
+ * Resolves the provided entry points to their corresponding type definitions. The function accepts an array of entry points, which can be strings (file paths) or type definition objects. It processes each entry point, resolving file paths and glob patterns to find matching files. For each resolved file, it creates a type definition object and resolves it using the `resolveInput` function. The function returns an array of resolved entry type definitions.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * const schema = await extract(context, "./schemas/*.ts");
42
+ * ```
43
+ *
44
+ * @param context - The plugin context used for resolving the schema definition input.
45
+ * @param input - The schema definition input to extract the JSON Schema from. This can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a TypeScript type definition.
46
+ * @param options - Optional overrides for the ESBuild configuration used during resolution.
47
+ * @returns A promise that resolves to a SchemaDefinition containing the extracted JSON Schema and its variant, or the bytecode if JSON Schema extraction is not possible.
48
+ */
49
+ declare function extract<TContext extends PluginContext = PluginContext>(context: TContext, input: SchemaDefinitionParameter, options?: Partial<BuildOptions>): Promise<SchemaDefinition>;
14
50
  //#endregion
15
- export { extractJsonSchema };
51
+ export { extract, extractJsonSchema, extractReflection, extractSchema };
16
52
  //# sourceMappingURL=extract.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract.d.mts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;AAgCA;;;;;;;iBAAgB,iBAAA,CACd,MAAA,YACC,eAAA"}
1
+ {"version":3,"file":"extract.d.mts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;;;;;AA+CA;;;;;;;iBAAgB,iBAAA,CACd,UAAA,EAAY,IAAA,GACX,eAAA;;AAiBH;;;;;AAmCA;;;iBAnCgB,iBAAA,CACd,MAAA,YACC,eAAA;;;;;;AA4FH;;iBA3DgB,aAAA,CAAc,KAAA,EAAO,qBAAA,GAAwB,gBAAA;;;;;;;;;;;;;;iBA2DvC,OAAA,kBAAyB,aAAA,GAAgB,aAAA,CAAA,CAC7D,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,yBAAA,EACP,OAAA,GAAS,OAAA,CAAQ,YAAA,IAChB,OAAA,CAAQ,gBAAA"}
package/dist/extract.mjs CHANGED
@@ -1,9 +1,30 @@
1
+ import { isSchemaDefinition } from "./is-schema-definition.mjs";
2
+ import { reflectionToJsonSchema } from "./reflection.mjs";
3
+ import { resolve } from "./resolve.mjs";
4
+ import defu from "defu";
5
+ import { isTypeDefinition } from "@powerlines/core";
6
+ import { esbuildPlugin } from "@powerlines/deepkit/esbuild-plugin";
7
+ import { isType } from "@powerlines/deepkit/vendor/type";
1
8
  import { isJsonSchema7ObjectType, isStandardJsonSchema } from "@stryke/json";
2
- import { isSetObject } from "@stryke/type-checks/is-set-object";
9
+ import { isSetString } from "@stryke/type-checks";
10
+ import { isSetObject as isSetObject$1 } from "@stryke/type-checks/is-set-object";
3
11
  import { extractJsonSchema7, isZod3Type } from "@stryke/zod";
4
12
 
5
13
  //#region src/extract.ts
6
14
  /**
15
+ * Converts a reflected Deepkit {@link @powerlines/deepkit/vendor/type#Type} into a JSON Schema (draft-07) representation.
16
+ *
17
+ * @remarks
18
+ * This function delegates to an internal recursive walker that handles the full set of Deepkit reflection kinds.
19
+ *
20
+ * @param reflection - The reflected Deepkit Type to convert.
21
+ * @returns A JSON Schema (draft-07) fragment representing the type, or `undefined` when no schema could be produced.
22
+ */
23
+ function extractReflection(reflection) {
24
+ if (!isType(reflection)) return;
25
+ return reflectionToJsonSchema(reflection);
26
+ }
27
+ /**
7
28
  * Extracts a JSON Schema object from a given schema definition, if possible.
8
29
  *
9
30
  * @remarks
@@ -13,7 +34,7 @@ import { extractJsonSchema7, isZod3Type } from "@stryke/zod";
13
34
  * @returns The extracted JSON Schema (draft-07) object if successful, otherwise undefined.
14
35
  */
15
36
  function extractJsonSchema(schema) {
16
- if (isSetObject(schema) && (isZod3Type(schema) || isStandardJsonSchema(schema) || isJsonSchema7ObjectType(schema))) {
37
+ if (isSetObject$1(schema) && (isZod3Type(schema) || isStandardJsonSchema(schema) || isJsonSchema7ObjectType(schema))) {
17
38
  let jsonSchema;
18
39
  if (isZod3Type(schema)) jsonSchema = extractJsonSchema7(schema);
19
40
  else if (isStandardJsonSchema(schema)) jsonSchema = schema["~standard"].jsonSchema.input({ target: "draft-07" });
@@ -21,7 +42,70 @@ function extractJsonSchema(schema) {
21
42
  if (isJsonSchema7ObjectType(jsonSchema)) return jsonSchema;
22
43
  }
23
44
  }
45
+ /**
46
+ * Extracts a schema definition from a given input object, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object. The function checks the type of the input and attempts to extract the corresponding schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns a `SchemaDefinition` containing the extracted schema and its variant if successful; otherwise, it throws an error.
47
+ *
48
+ * @param input - The input object to extract the schema definition from.
49
+ * @returns A `SchemaDefinition` containing the extracted schema and its variant if successful.
50
+ * @throws An error if the input does not contain a valid schema definition.
51
+ */
52
+ function extractSchema(input) {
53
+ if (isSetObject$1(input)) {
54
+ if (isZod3Type(input)) {
55
+ const schema = extractJsonSchema(input);
56
+ if (schema) return {
57
+ schema,
58
+ variant: "zod3",
59
+ input
60
+ };
61
+ } else if (isStandardJsonSchema(input)) {
62
+ const schema = extractJsonSchema(input);
63
+ if (schema) return {
64
+ schema,
65
+ variant: "standard-schema",
66
+ input
67
+ };
68
+ } else if (isJsonSchema7ObjectType(input)) {
69
+ const schema = extractJsonSchema(input);
70
+ if (schema) return {
71
+ schema,
72
+ variant: "json-schema",
73
+ input
74
+ };
75
+ } else if (isType(input)) {
76
+ const schema = extractReflection(input);
77
+ if (schema) return {
78
+ schema,
79
+ variant: "reflection",
80
+ input
81
+ };
82
+ }
83
+ }
84
+ throw new Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object.`);
85
+ }
86
+ /**
87
+ * Resolves the provided entry points to their corresponding type definitions. The function accepts an array of entry points, which can be strings (file paths) or type definition objects. It processes each entry point, resolving file paths and glob patterns to find matching files. For each resolved file, it creates a type definition object and resolves it using the `resolveInput` function. The function returns an array of resolved entry type definitions.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * const schema = await extract(context, "./schemas/*.ts");
92
+ * ```
93
+ *
94
+ * @param context - The plugin context used for resolving the schema definition input.
95
+ * @param input - The schema definition input to extract the JSON Schema from. This can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a TypeScript type definition.
96
+ * @param options - Optional overrides for the ESBuild configuration used during resolution.
97
+ * @returns A promise that resolves to a SchemaDefinition containing the extracted JSON Schema and its variant, or the bytecode if JSON Schema extraction is not possible.
98
+ */
99
+ async function extract(context, input, options = {}) {
100
+ if (isSchemaDefinition(input)) return input;
101
+ let inputObject = input;
102
+ if (isSetString(input) || isTypeDefinition(input)) inputObject = await resolve(context, input, defu(options, { plugins: [esbuildPlugin(context, {
103
+ reflection: "default",
104
+ level: "all"
105
+ })] }));
106
+ return extractSchema(inputObject);
107
+ }
24
108
 
25
109
  //#endregion
26
- export { extractJsonSchema };
110
+ export { extract, extractJsonSchema, extractReflection, extractSchema };
27
111
  //# sourceMappingURL=extract.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract.mjs","names":[],"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 { JsonSchema7Type } from \"@stryke/json\";\nimport { isJsonSchema7ObjectType, isStandardJsonSchema } from \"@stryke/json\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { extractJsonSchema7, isZod3Type } from \"@stryke/zod\";\n\n/**\n * Extracts a JSON Schema object from a given schema definition, if possible.\n *\n * @remarks\n * This function checks if the provided schema is a Zod schema, a Standard JSON Schema, or already a JSON Schema object. If it is a Zod schema, it extracts the corresponding JSON Schema. If it is a Standard JSON Schema, it retrieves the input JSON Schema targeting draft-07. Finally, it checks if the resulting JSON Schema is an object type and returns it if so.\n *\n * @param schema - The schema definition to extract the JSON Schema from. This can be a Zod schema, a Standard JSON Schema, or a JSON Schema object.\n * @returns The extracted JSON Schema (draft-07) object if successful, otherwise undefined.\n */\nexport function extractJsonSchema(\n schema: unknown\n): JsonSchema7Type | undefined {\n if (\n isSetObject(schema) &&\n (isZod3Type(schema) ||\n isStandardJsonSchema(schema) ||\n isJsonSchema7ObjectType(schema))\n ) {\n let jsonSchema: JsonSchema7Type;\n if (isZod3Type(schema)) {\n jsonSchema = extractJsonSchema7(schema);\n } else if (isStandardJsonSchema(schema)) {\n jsonSchema = schema[\"~standard\"].jsonSchema.input({\n target: \"draft-07\"\n });\n } else {\n jsonSchema = schema;\n }\n\n if (isJsonSchema7ObjectType(jsonSchema)) {\n return jsonSchema;\n }\n }\n\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;AAgCA,SAAgB,kBACd,QAC6B;AAC7B,KACE,YAAY,OAAO,KAClB,WAAW,OAAO,IACjB,qBAAqB,OAAO,IAC5B,wBAAwB,OAAO,GACjC;EACA,IAAI;AACJ,MAAI,WAAW,OAAO,CACpB,cAAa,mBAAmB,OAAO;WAC9B,qBAAqB,OAAO,CACrC,cAAa,OAAO,aAAa,WAAW,MAAM,EAChD,QAAQ,YACT,CAAC;MAEF,cAAa;AAGf,MAAI,wBAAwB,WAAW,CACrC,QAAO"}
1
+ {"version":3,"file":"extract.mjs","names":["isSetObject"],"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 { PluginContext } from \"@powerlines/core\";\nimport { isTypeDefinition } from \"@powerlines/core\";\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport { isType, Type } from \"@powerlines/deepkit/vendor/type\";\nimport type { JsonSchema7Type } from \"@stryke/json\";\nimport { isJsonSchema7ObjectType, isStandardJsonSchema } from \"@stryke/json\";\nimport { isSetString } from \"@stryke/type-checks\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { extractJsonSchema7, isZod3Type } from \"@stryke/zod\";\nimport defu from \"defu\";\nimport type { BuildOptions } from \"esbuild\";\nimport { isSchemaDefinition } from \"./is-schema-definition\";\nimport { reflectionToJsonSchema } from \"./reflection\";\nimport { resolve } from \"./resolve\";\nimport {\n SchemaDefinition,\n SchemaDefinitionInput,\n SchemaDefinitionParameter\n} from \"./types\";\n\n/**\n * Converts a reflected Deepkit {@link @powerlines/deepkit/vendor/type#Type} into a JSON Schema (draft-07) representation.\n *\n * @remarks\n * This function delegates to an internal recursive walker that handles the full set of Deepkit reflection kinds.\n *\n * @param reflection - The reflected Deepkit Type to convert.\n * @returns A JSON Schema (draft-07) fragment representing the type, or `undefined` when no schema could be produced.\n */\nexport function extractReflection(\n reflection: Type\n): JsonSchema7Type | undefined {\n if (!isType(reflection)) {\n return undefined;\n }\n\n return reflectionToJsonSchema(reflection);\n}\n\n/**\n * Extracts a JSON Schema object from a given schema definition, if possible.\n *\n * @remarks\n * This function checks if the provided schema is a Zod schema, a Standard JSON Schema, or already a JSON Schema object. If it is a Zod schema, it extracts the corresponding JSON Schema. If it is a Standard JSON Schema, it retrieves the input JSON Schema targeting draft-07. Finally, it checks if the resulting JSON Schema is an object type and returns it if so.\n *\n * @param schema - The schema definition to extract the JSON Schema from. This can be a Zod schema, a Standard JSON Schema, or a JSON Schema object.\n * @returns The extracted JSON Schema (draft-07) object if successful, otherwise undefined.\n */\nexport function extractJsonSchema(\n schema: unknown\n): JsonSchema7Type | undefined {\n if (\n isSetObject(schema) &&\n (isZod3Type(schema) ||\n isStandardJsonSchema(schema) ||\n isJsonSchema7ObjectType(schema))\n ) {\n let jsonSchema: JsonSchema7Type;\n if (isZod3Type(schema)) {\n jsonSchema = extractJsonSchema7(schema);\n } else if (isStandardJsonSchema(schema)) {\n jsonSchema = schema[\"~standard\"].jsonSchema.input({\n target: \"draft-07\"\n });\n } else {\n jsonSchema = schema;\n }\n\n if (isJsonSchema7ObjectType(jsonSchema)) {\n return jsonSchema;\n }\n }\n\n return undefined;\n}\n\n/**\n * Extracts a schema definition from a given input object, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object. The function checks the type of the input and attempts to extract the corresponding schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns a `SchemaDefinition` containing the extracted schema and its variant if successful; otherwise, it throws an error.\n *\n * @param input - The input object to extract the schema definition from.\n * @returns A `SchemaDefinition` containing the extracted schema and its variant if successful.\n * @throws An error if the input does not contain a valid schema definition.\n */\nexport function extractSchema(input: SchemaDefinitionInput): SchemaDefinition {\n if (isSetObject(input)) {\n if (isZod3Type(input)) {\n const schema = extractJsonSchema(input);\n if (schema) {\n return {\n schema,\n variant: \"zod3\",\n input\n };\n }\n } else if (isStandardJsonSchema(input)) {\n const schema = extractJsonSchema(input);\n if (schema) {\n return {\n schema,\n variant: \"standard-schema\",\n input\n };\n }\n } else if (isJsonSchema7ObjectType(input)) {\n const schema = extractJsonSchema(input);\n if (schema) {\n return {\n schema,\n variant: \"json-schema\",\n input\n };\n }\n } else if (isType(input)) {\n const schema = extractReflection(input);\n if (schema) {\n return {\n schema,\n variant: \"reflection\",\n input\n };\n }\n }\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, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Resolves the provided entry points to their corresponding type definitions. The function accepts an array of entry points, which can be strings (file paths) or type definition objects. It processes each entry point, resolving file paths and glob patterns to find matching files. For each resolved file, it creates a type definition object and resolves it using the `resolveInput` function. The function returns an array of resolved entry type definitions.\n *\n * @example\n * ```ts\n * const schema = await extract(context, \"./schemas/*.ts\");\n * ```\n *\n * @param context - The plugin context used for resolving the schema definition input.\n * @param input - The schema definition input to extract the JSON Schema from. This can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a TypeScript type definition.\n * @param options - Optional overrides for the ESBuild configuration used during resolution.\n * @returns A promise that resolves to a SchemaDefinition containing the extracted JSON Schema and its variant, or the bytecode if JSON Schema extraction is not possible.\n */\nexport async function extract<TContext extends PluginContext = PluginContext>(\n context: TContext,\n input: SchemaDefinitionParameter,\n options: Partial<BuildOptions> = {}\n): Promise<SchemaDefinition> {\n if (isSchemaDefinition(input)) {\n return input;\n }\n\n let inputObject = input as SchemaDefinitionInput;\n if (isSetString(input) || isTypeDefinition(input)) {\n inputObject = await resolve<SchemaDefinitionInput>(\n context,\n input,\n defu(options, {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n level: \"all\"\n })\n ]\n })\n );\n }\n\n return extractSchema(inputObject);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA+CA,SAAgB,kBACd,YAC6B;AAC7B,KAAI,CAAC,OAAO,WAAW,CACrB;AAGF,QAAO,uBAAuB,WAAW;;;;;;;;;;;AAY3C,SAAgB,kBACd,QAC6B;AAC7B,KACEA,cAAY,OAAO,KAClB,WAAW,OAAO,IACjB,qBAAqB,OAAO,IAC5B,wBAAwB,OAAO,GACjC;EACA,IAAI;AACJ,MAAI,WAAW,OAAO,CACpB,cAAa,mBAAmB,OAAO;WAC9B,qBAAqB,OAAO,CACrC,cAAa,OAAO,aAAa,WAAW,MAAM,EAChD,QAAQ,YACT,CAAC;MAEF,cAAa;AAGf,MAAI,wBAAwB,WAAW,CACrC,QAAO;;;;;;;;;;AAcb,SAAgB,cAAc,OAAgD;AAC5E,KAAIA,cAAY,MAAM,EACpB;MAAI,WAAW,MAAM,EAAE;GACrB,MAAM,SAAS,kBAAkB,MAAM;AACvC,OAAI,OACF,QAAO;IACL;IACA,SAAS;IACT;IACD;aAEM,qBAAqB,MAAM,EAAE;GACtC,MAAM,SAAS,kBAAkB,MAAM;AACvC,OAAI,OACF,QAAO;IACL;IACA,SAAS;IACT;IACD;aAEM,wBAAwB,MAAM,EAAE;GACzC,MAAM,SAAS,kBAAkB,MAAM;AACvC,OAAI,OACF,QAAO;IACL;IACA,SAAS;IACT;IACD;aAEM,OAAO,MAAM,EAAE;GACxB,MAAM,SAAS,kBAAkB,MAAM;AACvC,OAAI,OACF,QAAO;IACL;IACA,SAAS;IACT;IACD;;;AAKP,OAAM,IAAI,MACR,8KACD;;;;;;;;;;;;;;;AAgBH,eAAsB,QACpB,SACA,OACA,UAAiC,EAAE,EACR;AAC3B,KAAI,mBAAmB,MAAM,CAC3B,QAAO;CAGT,IAAI,cAAc;AAClB,KAAI,YAAY,MAAM,IAAI,iBAAiB,MAAM,CAC/C,eAAc,MAAM,QAClB,SACA,OACA,KAAK,SAAS,EACZ,SAAS,CACP,cAAc,SAAS;EACrB,YAAY;EACZ,OAAO;EACR,CAAC,CACH,EACF,CAAC,CACH;AAGH,QAAO,cAAc,YAAY"}
package/dist/index.cjs CHANGED
@@ -1,4 +1,18 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_bundle = require('./bundle.cjs');
3
+ const require_is_schema_definition = require('./is-schema-definition.cjs');
4
+ const require_reflection = require('./reflection.cjs');
5
+ const require_resolve = require('./resolve.cjs');
2
6
  const require_extract = require('./extract.cjs');
3
7
 
4
- exports.extractJsonSchema = require_extract.extractJsonSchema;
8
+ exports.bundle = require_bundle.bundle;
9
+ exports.extract = require_extract.extract;
10
+ exports.extractJsonSchema = require_extract.extractJsonSchema;
11
+ exports.extractReflection = require_extract.extractReflection;
12
+ exports.extractSchema = require_extract.extractSchema;
13
+ exports.isSchemaDefinition = require_is_schema_definition.isSchemaDefinition;
14
+ exports.objectReflectionToJsonSchema = require_reflection.objectReflectionToJsonSchema;
15
+ exports.reflectionToJsonSchema = require_reflection.reflectionToJsonSchema;
16
+ exports.resolve = require_resolve.resolve;
17
+ exports.resolveModule = require_resolve.resolveModule;
18
+ exports.resolveReflection = require_resolve.resolveReflection;
package/dist/index.d.cts CHANGED
@@ -1,3 +1,7 @@
1
- import { extractJsonSchema } from "./extract.cjs";
2
- import { SchemaDefinitionVariant, SchemaReflection } from "./types.cjs";
3
- export { SchemaDefinitionVariant, SchemaReflection, extractJsonSchema };
1
+ import { BundleOptions, bundle } from "./bundle.cjs";
2
+ import { SchemaDefinition, SchemaDefinitionBase, SchemaDefinitionInput, SchemaDefinitionJsonSchema, SchemaDefinitionParameter, SchemaDefinitionReflection, SchemaDefinitionStandardSchema, SchemaDefinitionVariant, SchemaDefinitionZod3 } from "./types.cjs";
3
+ import { extract, extractJsonSchema, extractReflection, extractSchema } from "./extract.cjs";
4
+ import { isSchemaDefinition } from "./is-schema-definition.cjs";
5
+ import { objectReflectionToJsonSchema, reflectionToJsonSchema } from "./reflection.cjs";
6
+ import { resolve, resolveModule, resolveReflection } from "./resolve.cjs";
7
+ export { BundleOptions, SchemaDefinition, SchemaDefinitionBase, SchemaDefinitionInput, SchemaDefinitionJsonSchema, SchemaDefinitionParameter, SchemaDefinitionReflection, SchemaDefinitionStandardSchema, SchemaDefinitionVariant, SchemaDefinitionZod3, bundle, extract, extractJsonSchema, extractReflection, extractSchema, isSchemaDefinition, objectReflectionToJsonSchema, reflectionToJsonSchema, resolve, resolveModule, resolveReflection };
package/dist/index.d.mts CHANGED
@@ -1,3 +1,7 @@
1
- import { extractJsonSchema } from "./extract.mjs";
2
- import { SchemaDefinitionVariant, SchemaReflection } from "./types.mjs";
3
- export { SchemaDefinitionVariant, SchemaReflection, extractJsonSchema };
1
+ import { BundleOptions, bundle } from "./bundle.mjs";
2
+ import { SchemaDefinition, SchemaDefinitionBase, SchemaDefinitionInput, SchemaDefinitionJsonSchema, SchemaDefinitionParameter, SchemaDefinitionReflection, SchemaDefinitionStandardSchema, SchemaDefinitionVariant, SchemaDefinitionZod3 } from "./types.mjs";
3
+ import { extract, extractJsonSchema, extractReflection, extractSchema } from "./extract.mjs";
4
+ import { isSchemaDefinition } from "./is-schema-definition.mjs";
5
+ import { objectReflectionToJsonSchema, reflectionToJsonSchema } from "./reflection.mjs";
6
+ import { resolve, resolveModule, resolveReflection } from "./resolve.mjs";
7
+ export { BundleOptions, SchemaDefinition, SchemaDefinitionBase, SchemaDefinitionInput, SchemaDefinitionJsonSchema, SchemaDefinitionParameter, SchemaDefinitionReflection, SchemaDefinitionStandardSchema, SchemaDefinitionVariant, SchemaDefinitionZod3, bundle, extract, extractJsonSchema, extractReflection, extractSchema, isSchemaDefinition, objectReflectionToJsonSchema, reflectionToJsonSchema, resolve, resolveModule, resolveReflection };
package/dist/index.mjs CHANGED
@@ -1,3 +1,7 @@
1
- import { extractJsonSchema } from "./extract.mjs";
1
+ import { bundle } from "./bundle.mjs";
2
+ import { isSchemaDefinition } from "./is-schema-definition.mjs";
3
+ import { objectReflectionToJsonSchema, reflectionToJsonSchema } from "./reflection.mjs";
4
+ import { resolve, resolveModule, resolveReflection } from "./resolve.mjs";
5
+ import { extract, extractJsonSchema, extractReflection, extractSchema } from "./extract.mjs";
2
6
 
3
- export { extractJsonSchema };
7
+ export { bundle, extract, extractJsonSchema, extractReflection, extractSchema, isSchemaDefinition, objectReflectionToJsonSchema, reflectionToJsonSchema, resolve, resolveModule, resolveReflection };
@@ -0,0 +1,18 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ let _stryke_type_checks = require("@stryke/type-checks");
4
+ let _stryke_json_schema = require("@stryke/json/schema");
5
+
6
+ //#region src/is-schema-definition.ts
7
+ /**
8
+ * Type guard to check if a given input is a `SchemaDefinition` object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants ("json-schema", "standard-schema", "zod3", or "reflection"). If all these conditions are met, the function returns `true`, indicating that the input is a valid `SchemaDefinition`; otherwise, it returns `false`.
9
+ *
10
+ * @param input - The input to check for being a `SchemaDefinition`.
11
+ * @returns `true` if the input is a `SchemaDefinition`, otherwise `false`.
12
+ */
13
+ function isSchemaDefinition(input) {
14
+ return (0, _stryke_type_checks.isSetObject)(input) && "schema" in input && (0, _stryke_json_schema.isJsonSchema7ObjectType)(input.schema) && "input" in input && (0, _stryke_type_checks.isSetObject)(input.input) && "variant" in input && (input.variant === "json-schema" || input.variant === "standard-schema" || input.variant === "zod3" || input.variant === "reflection");
15
+ }
16
+
17
+ //#endregion
18
+ exports.isSchemaDefinition = isSchemaDefinition;