@powerlines/schema 0.8.67

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 (49) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +303 -0
  3. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  4. package/dist/bundle.cjs +48 -0
  5. package/dist/bundle.d.cts +21 -0
  6. package/dist/bundle.d.cts.map +1 -0
  7. package/dist/bundle.d.mts +21 -0
  8. package/dist/bundle.d.mts.map +1 -0
  9. package/dist/bundle.mjs +46 -0
  10. package/dist/bundle.mjs.map +1 -0
  11. package/dist/extract.cjs +116 -0
  12. package/dist/extract.d.cts +52 -0
  13. package/dist/extract.d.cts.map +1 -0
  14. package/dist/extract.d.mts +52 -0
  15. package/dist/extract.d.mts.map +1 -0
  16. package/dist/extract.mjs +111 -0
  17. package/dist/extract.mjs.map +1 -0
  18. package/dist/index.cjs +18 -0
  19. package/dist/index.d.cts +7 -0
  20. package/dist/index.d.mts +7 -0
  21. package/dist/index.mjs +7 -0
  22. package/dist/is-schema-definition.cjs +18 -0
  23. package/dist/is-schema-definition.d.cts +13 -0
  24. package/dist/is-schema-definition.d.cts.map +1 -0
  25. package/dist/is-schema-definition.d.mts +13 -0
  26. package/dist/is-schema-definition.d.mts.map +1 -0
  27. package/dist/is-schema-definition.mjs +17 -0
  28. package/dist/is-schema-definition.mjs.map +1 -0
  29. package/dist/reflection.cjs +191 -0
  30. package/dist/reflection.d.cts +21 -0
  31. package/dist/reflection.d.cts.map +1 -0
  32. package/dist/reflection.d.mts +21 -0
  33. package/dist/reflection.d.mts.map +1 -0
  34. package/dist/reflection.mjs +189 -0
  35. package/dist/reflection.mjs.map +1 -0
  36. package/dist/resolve.cjs +84 -0
  37. package/dist/resolve.d.cts +36 -0
  38. package/dist/resolve.d.cts.map +1 -0
  39. package/dist/resolve.d.mts +36 -0
  40. package/dist/resolve.d.mts.map +1 -0
  41. package/dist/resolve.mjs +80 -0
  42. package/dist/resolve.mjs.map +1 -0
  43. package/dist/types.cjs +0 -0
  44. package/dist/types.d.cts +39 -0
  45. package/dist/types.d.cts.map +1 -0
  46. package/dist/types.d.mts +39 -0
  47. package/dist/types.d.mts.map +1 -0
  48. package/dist/types.mjs +1 -0
  49. package/package.json +103 -0
@@ -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"}
@@ -0,0 +1,116 @@
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");
11
+ let _stryke_json = require("@stryke/json");
12
+ let _stryke_type_checks = require("@stryke/type-checks");
13
+ let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
14
+ let _stryke_zod = require("@stryke/zod");
15
+
16
+ //#region src/extract.ts
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
+ /**
31
+ * Extracts a JSON Schema object from a given schema definition, if possible.
32
+ *
33
+ * @remarks
34
+ * 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.
35
+ *
36
+ * @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.
37
+ * @returns The extracted JSON Schema (draft-07) object if successful, otherwise undefined.
38
+ */
39
+ function extractJsonSchema(schema) {
40
+ if ((0, _stryke_type_checks_is_set_object.isSetObject)(schema) && ((0, _stryke_zod.isZod3Type)(schema) || (0, _stryke_json.isStandardJsonSchema)(schema) || (0, _stryke_json.isJsonSchema7ObjectType)(schema))) {
41
+ let jsonSchema;
42
+ if ((0, _stryke_zod.isZod3Type)(schema)) jsonSchema = (0, _stryke_zod.extractJsonSchema7)(schema);
43
+ else if ((0, _stryke_json.isStandardJsonSchema)(schema)) jsonSchema = schema["~standard"].jsonSchema.input({ target: "draft-07" });
44
+ else jsonSchema = schema;
45
+ if ((0, _stryke_json.isJsonSchema7ObjectType)(jsonSchema)) return jsonSchema;
46
+ }
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
+ }
111
+
112
+ //#endregion
113
+ exports.extract = extract;
114
+ exports.extractJsonSchema = extractJsonSchema;
115
+ exports.extractReflection = extractReflection;
116
+ exports.extractSchema = extractSchema;
@@ -0,0 +1,52 @@
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";
5
+ import { JsonSchema7Type } from "@stryke/json";
6
+
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;
18
+ /**
19
+ * Extracts a JSON Schema object from a given schema definition, if possible.
20
+ *
21
+ * @remarks
22
+ * 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.
23
+ *
24
+ * @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.
25
+ * @returns The extracted JSON Schema (draft-07) object if successful, otherwise undefined.
26
+ */
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>;
50
+ //#endregion
51
+ export { extract, extractJsonSchema, extractReflection, extractSchema };
52
+ //# sourceMappingURL=extract.d.cts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,52 @@
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";
5
+ import { JsonSchema7Type } from "@stryke/json";
6
+
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;
18
+ /**
19
+ * Extracts a JSON Schema object from a given schema definition, if possible.
20
+ *
21
+ * @remarks
22
+ * 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.
23
+ *
24
+ * @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.
25
+ * @returns The extracted JSON Schema (draft-07) object if successful, otherwise undefined.
26
+ */
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>;
50
+ //#endregion
51
+ export { extract, extractJsonSchema, extractReflection, extractSchema };
52
+ //# sourceMappingURL=extract.d.mts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,111 @@
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";
8
+ import { isJsonSchema7ObjectType, isStandardJsonSchema } from "@stryke/json";
9
+ import { isSetString } from "@stryke/type-checks";
10
+ import { isSetObject as isSetObject$1 } from "@stryke/type-checks/is-set-object";
11
+ import { extractJsonSchema7, isZod3Type } from "@stryke/zod";
12
+
13
+ //#region src/extract.ts
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
+ /**
28
+ * Extracts a JSON Schema object from a given schema definition, if possible.
29
+ *
30
+ * @remarks
31
+ * 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.
32
+ *
33
+ * @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.
34
+ * @returns The extracted JSON Schema (draft-07) object if successful, otherwise undefined.
35
+ */
36
+ function extractJsonSchema(schema) {
37
+ if (isSetObject$1(schema) && (isZod3Type(schema) || isStandardJsonSchema(schema) || isJsonSchema7ObjectType(schema))) {
38
+ let jsonSchema;
39
+ if (isZod3Type(schema)) jsonSchema = extractJsonSchema7(schema);
40
+ else if (isStandardJsonSchema(schema)) jsonSchema = schema["~standard"].jsonSchema.input({ target: "draft-07" });
41
+ else jsonSchema = schema;
42
+ if (isJsonSchema7ObjectType(jsonSchema)) return jsonSchema;
43
+ }
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
+ }
108
+
109
+ //#endregion
110
+ export { extract, extractJsonSchema, extractReflection, extractSchema };
111
+ //# sourceMappingURL=extract.mjs.map
@@ -0,0 +1 @@
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 ADDED
@@ -0,0 +1,18 @@
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');
6
+ const require_extract = require('./extract.cjs');
7
+
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;
@@ -0,0 +1,7 @@
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 };
@@ -0,0 +1,7 @@
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 ADDED
@@ -0,0 +1,7 @@
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";
6
+
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;
@@ -0,0 +1,13 @@
1
+ import { SchemaDefinition } from "./types.cjs";
2
+
3
+ //#region src/is-schema-definition.d.ts
4
+ /**
5
+ * 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`.
6
+ *
7
+ * @param input - The input to check for being a `SchemaDefinition`.
8
+ * @returns `true` if the input is a `SchemaDefinition`, otherwise `false`.
9
+ */
10
+ declare function isSchemaDefinition(input: unknown): input is SchemaDefinition;
11
+ //#endregion
12
+ export { isSchemaDefinition };
13
+ //# sourceMappingURL=is-schema-definition.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-schema-definition.d.cts","names":[],"sources":["../src/is-schema-definition.ts"],"mappings":";;;;;AA4BA;;;;iBAAgB,kBAAA,CAAmB,KAAA,YAAiB,KAAA,IAAS,gBAAA"}
@@ -0,0 +1,13 @@
1
+ import { SchemaDefinition } from "./types.mjs";
2
+
3
+ //#region src/is-schema-definition.d.ts
4
+ /**
5
+ * 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`.
6
+ *
7
+ * @param input - The input to check for being a `SchemaDefinition`.
8
+ * @returns `true` if the input is a `SchemaDefinition`, otherwise `false`.
9
+ */
10
+ declare function isSchemaDefinition(input: unknown): input is SchemaDefinition;
11
+ //#endregion
12
+ export { isSchemaDefinition };
13
+ //# sourceMappingURL=is-schema-definition.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-schema-definition.d.mts","names":[],"sources":["../src/is-schema-definition.ts"],"mappings":";;;;;AA4BA;;;;iBAAgB,kBAAA,CAAmB,KAAA,YAAiB,KAAA,IAAS,gBAAA"}
@@ -0,0 +1,17 @@
1
+ import { isSetObject } from "@stryke/type-checks";
2
+ import { isJsonSchema7ObjectType } from "@stryke/json/schema";
3
+
4
+ //#region src/is-schema-definition.ts
5
+ /**
6
+ * 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`.
7
+ *
8
+ * @param input - The input to check for being a `SchemaDefinition`.
9
+ * @returns `true` if the input is a `SchemaDefinition`, otherwise `false`.
10
+ */
11
+ function isSchemaDefinition(input) {
12
+ return isSetObject(input) && "schema" in input && isJsonSchema7ObjectType(input.schema) && "input" in input && isSetObject(input.input) && "variant" in input && (input.variant === "json-schema" || input.variant === "standard-schema" || input.variant === "zod3" || input.variant === "reflection");
13
+ }
14
+
15
+ //#endregion
16
+ export { isSchemaDefinition };
17
+ //# sourceMappingURL=is-schema-definition.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-schema-definition.mjs","names":[],"sources":["../src/is-schema-definition.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 { isJsonSchema7ObjectType } from \"@stryke/json/schema\";\nimport { isSetObject } from \"@stryke/type-checks\";\nimport { SchemaDefinition } from \"./types\";\n\n/**\n * 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`.\n *\n * @param input - The input to check for being a `SchemaDefinition`.\n * @returns `true` if the input is a `SchemaDefinition`, otherwise `false`.\n */\nexport function isSchemaDefinition(input: unknown): input is SchemaDefinition {\n return (\n isSetObject(input) &&\n \"schema\" in input &&\n isJsonSchema7ObjectType(input.schema) &&\n \"input\" in input &&\n isSetObject(input.input) &&\n \"variant\" in input &&\n (input.variant === \"json-schema\" ||\n input.variant === \"standard-schema\" ||\n input.variant === \"zod3\" ||\n input.variant === \"reflection\")\n );\n}\n"],"mappings":";;;;;;;;;;AA4BA,SAAgB,mBAAmB,OAA2C;AAC5E,QACE,YAAY,MAAM,IAClB,YAAY,SACZ,wBAAwB,MAAM,OAAO,IACrC,WAAW,SACX,YAAY,MAAM,MAAM,IACxB,aAAa,UACZ,MAAM,YAAY,iBACjB,MAAM,YAAY,qBAClB,MAAM,YAAY,UAClB,MAAM,YAAY"}