@powerlines/schema 0.11.27 → 0.11.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.cjs +34 -20
- package/dist/bundle.d.cts +3 -3
- package/dist/bundle.d.cts.map +1 -1
- package/dist/bundle.d.mts +3 -3
- package/dist/bundle.d.mts.map +1 -1
- package/dist/bundle.mjs +35 -21
- package/dist/bundle.mjs.map +1 -1
- package/dist/codegen.cjs +40 -36
- package/dist/codegen.d.cts +10 -22
- package/dist/codegen.d.cts.map +1 -1
- package/dist/codegen.d.mts +10 -22
- package/dist/codegen.d.mts.map +1 -1
- package/dist/codegen.mjs +39 -36
- package/dist/codegen.mjs.map +1 -1
- package/dist/constants.cjs +34 -11
- package/dist/constants.d.cts +9 -11
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +9 -11
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +32 -11
- package/dist/constants.mjs.map +1 -1
- package/dist/extract.cjs +122 -92
- package/dist/extract.d.cts +34 -69
- package/dist/extract.d.cts.map +1 -1
- package/dist/extract.d.mts +34 -69
- package/dist/extract.d.mts.map +1 -1
- package/dist/extract.mjs +123 -93
- package/dist/extract.mjs.map +1 -1
- package/dist/helpers.cjs +45 -52
- package/dist/helpers.d.cts +28 -24
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +28 -24
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +46 -52
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +14 -7
- package/dist/index.d.cts +6 -6
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +5 -5
- package/dist/metadata.cjs +80 -0
- package/dist/metadata.d.cts +52 -0
- package/dist/metadata.d.cts.map +1 -0
- package/dist/metadata.d.mts +52 -0
- package/dist/metadata.d.mts.map +1 -0
- package/dist/metadata.mjs +76 -0
- package/dist/metadata.mjs.map +1 -0
- package/dist/persistence.cjs +1 -2
- package/dist/persistence.d.cts +5 -5
- package/dist/persistence.d.cts.map +1 -1
- package/dist/persistence.d.mts +5 -5
- package/dist/persistence.d.mts.map +1 -1
- package/dist/persistence.mjs +1 -1
- package/dist/persistence.mjs.map +1 -1
- package/dist/reflection.cjs +289 -303
- package/dist/reflection.d.cts +3 -16
- package/dist/reflection.d.cts.map +1 -1
- package/dist/reflection.d.mts +3 -16
- package/dist/reflection.d.mts.map +1 -1
- package/dist/reflection.mjs +290 -304
- package/dist/reflection.mjs.map +1 -1
- package/dist/resolve.cjs +7 -7
- package/dist/resolve.mjs +7 -7
- package/dist/resolve.mjs.map +1 -1
- package/dist/type-checks.cjs +122 -40
- package/dist/type-checks.d.cts +41 -33
- package/dist/type-checks.d.cts.map +1 -1
- package/dist/type-checks.d.mts +41 -33
- package/dist/type-checks.d.mts.map +1 -1
- package/dist/type-checks.mjs +120 -37
- package/dist/type-checks.mjs.map +1 -1
- package/dist/types.d.cts +225 -113
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +225 -113
- package/dist/types.d.mts.map +1 -1
- package/package.json +11 -7
- package/dist/jtd.cjs +0 -385
- package/dist/jtd.d.cts +0 -15
- package/dist/jtd.d.cts.map +0 -1
- package/dist/jtd.d.mts +0 -15
- package/dist/jtd.d.mts.map +0 -1
- package/dist/jtd.mjs +0 -384
- package/dist/jtd.mjs.map +0 -1
package/dist/extract.d.cts
CHANGED
|
@@ -1,90 +1,54 @@
|
|
|
1
|
-
import { ExtractedSchema,
|
|
1
|
+
import { ExtractedSchema, JsonSchema, Schema, SchemaInput, SchemaInputVariant, SchemaSource, SchemaSourceInput, SchemaSourceVariant } from "./types.cjs";
|
|
2
2
|
import { Context } from "@powerlines/core";
|
|
3
|
-
import { BuildOptions } from "
|
|
3
|
+
import { BuildOptions } from "rolldown";
|
|
4
4
|
import { Type } from "@powerlines/deepkit/vendor/type";
|
|
5
5
|
|
|
6
6
|
//#region src/extract.d.ts
|
|
7
7
|
/**
|
|
8
|
-
* Creates a hash string for a given schema definition input.
|
|
8
|
+
* Creates a hash string for a given schema definition input.
|
|
9
9
|
*/
|
|
10
|
-
declare function extractHash(variant: SchemaInputVariant, input: SchemaInput): string;
|
|
10
|
+
declare function extractHash<T = unknown>(variant: SchemaInputVariant, input: SchemaInput<T>): string;
|
|
11
11
|
/**
|
|
12
|
-
* Converts a reflected Deepkit {@link
|
|
13
|
-
*
|
|
14
|
-
* @remarks
|
|
15
|
-
* This function delegates to an internal recursive walker that handles the full set of Deepkit reflection kinds.
|
|
16
|
-
*
|
|
17
|
-
* @param reflection - The reflected Deepkit Type to convert.
|
|
18
|
-
* @returns A JSON Schema (draft-07) fragment representing the type, or `undefined` when no schema could be produced.
|
|
12
|
+
* Converts a reflected Deepkit {@link Type} into a JSON Schema (draft-07) representation.
|
|
19
13
|
*/
|
|
20
|
-
declare function extractReflection<
|
|
14
|
+
declare function extractReflection<T = unknown>(reflection: Type): JsonSchema<T> | undefined;
|
|
21
15
|
/**
|
|
22
|
-
* Extracts a JSON
|
|
23
|
-
*
|
|
24
|
-
* @remarks
|
|
25
|
-
* This function checks if the provided input is a Zod schema, a Standard JSON Schema, or already a JSON Schema object, extracts a JSON Schema fragment via the appropriate adapter (Zod and Standard Schema produce draft-07 fragments), and then converts that fragment into a valid JTD form suitable for AJV's JTD validator.
|
|
26
|
-
*
|
|
27
|
-
* @param schema - The schema definition to extract from. This can be a Zod schema, a Standard JSON Schema, or a JSON Schema object.
|
|
28
|
-
* @returns The extracted JTD schema if successful, otherwise undefined.
|
|
29
|
-
*/
|
|
30
|
-
declare function extractJsonSchema<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>>(schema: unknown): JTDSchemaType<TMetadata> | undefined;
|
|
31
|
-
/**
|
|
32
|
-
* Extracts a schema definition from a given input object, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object. The function checks the type of the input and attempts to extract the corresponding schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns a `Schema` containing the extracted schema and its variant if successful; otherwise, it throws an error.
|
|
33
|
-
*
|
|
34
|
-
* @param input - The input object to extract the schema definition from.
|
|
35
|
-
* @returns A `Schema` containing the extracted schema and its variant if successful.
|
|
36
|
-
* @throws An error if the input does not contain a valid schema definition.
|
|
16
|
+
* Extracts a JSON Schema from Zod, Standard Schema, untyped, or JSON Schema inputs.
|
|
37
17
|
*/
|
|
18
|
+
declare function extractJsonSchema<T = unknown>(schema: unknown): JsonSchema<T> | undefined;
|
|
38
19
|
declare function extractResolvedVariant(input: SchemaSourceInput): SchemaSourceVariant;
|
|
20
|
+
declare function extractVariant<T = unknown>(input: SchemaInput<T>): SchemaInputVariant;
|
|
21
|
+
declare function extractSchemaSchema<T = unknown>(input: SchemaSourceInput, variant?: SchemaInputVariant): Promise<JsonSchema<T>>;
|
|
22
|
+
declare function extractSource(variant: SchemaSourceVariant, input: SchemaSourceInput): SchemaSource;
|
|
39
23
|
/**
|
|
40
|
-
* Extracts a
|
|
41
|
-
*
|
|
42
|
-
* @param input - The input object to extract the schema definition from.
|
|
43
|
-
* @returns A `Schema` containing the extracted schema and its variant if successful.
|
|
44
|
-
* @throws An error if the input does not contain a valid schema definition.
|
|
45
|
-
*/
|
|
46
|
-
declare function extractVariant(input: SchemaInput): SchemaInputVariant;
|
|
47
|
-
/**
|
|
48
|
-
* Extracts a JSON Schema object from a given schema definition input. The input can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object. The function checks the type of the input and attempts to extract the corresponding JSON Schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns the extracted JSON Schema if successful; otherwise, it throws an error.
|
|
49
|
-
*
|
|
50
|
-
* @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.
|
|
51
|
-
* @param variant - The variant of the schema definition to extract.
|
|
52
|
-
* @returns The extracted JSON Schema if successful.
|
|
53
|
-
* @throws An error if the input does not contain a valid schema definition.
|
|
54
|
-
*/
|
|
55
|
-
declare function extractSchemaSchema<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>>(input: SchemaSourceInput, variant?: SchemaInputVariant): Promise<JTDSchemaType<TMetadata>>;
|
|
56
|
-
/**
|
|
57
|
-
* Extracts a schema definition from a given input object, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, a JTD schema, an untyped schema, or a reflected Deepkit Type object. The function checks the type of the input and attempts to extract the corresponding schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns a `Schema` containing the extracted schema and its variant if successful; otherwise, it throws an error.
|
|
58
|
-
*
|
|
59
|
-
* @param variant - The variant of the schema definition to extract.
|
|
60
|
-
* @param input - The input object to extract the schema definition from.
|
|
61
|
-
* @returns A `Schema` containing the extracted schema and its variant if successful.
|
|
62
|
-
* @throws An error if the input does not contain a valid schema definition.
|
|
63
|
-
*/
|
|
64
|
-
declare function extractSource<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>>(variant: SchemaSourceVariant, input: SchemaSourceInput): SchemaSource;
|
|
65
|
-
/**
|
|
66
|
-
* 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.
|
|
24
|
+
* Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object. If the input is a type definition reference (e.g. a file path with an export), it will be resolved and bundled using ESBuild to obtain the actual schema definition before extraction.
|
|
67
25
|
*
|
|
68
26
|
* @example
|
|
69
27
|
* ```ts
|
|
70
28
|
* // Resolve a schema definition from a file path
|
|
71
|
-
* const schema1 = await
|
|
29
|
+
* const schema1 = await extract(context, "./schemas.ts#MySchema");
|
|
72
30
|
* // Resolve a schema definition from a JSON Schema object
|
|
73
|
-
* const schema2 = await
|
|
31
|
+
* const schema2 = await extract(context, schemaObject);
|
|
74
32
|
* // Resolve a schema definition from a Zod schema
|
|
75
|
-
* const schema3 = await
|
|
33
|
+
* const schema3 = await extract(context, zodSchema);
|
|
76
34
|
* // Resolve a schema definition from a reflected Deepkit Type object
|
|
77
|
-
* const schema4 = await
|
|
35
|
+
* const schema4 = await extract(context, reflectionType);
|
|
78
36
|
* ```
|
|
79
37
|
*
|
|
80
|
-
* @
|
|
81
|
-
* @
|
|
82
|
-
* @
|
|
83
|
-
* @
|
|
38
|
+
* @see https://github.com/colinhacks/zod
|
|
39
|
+
* @see https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec
|
|
40
|
+
* @see https://json-schema.org/
|
|
41
|
+
* @see https://ajv.js.org/json-type-definition.html
|
|
42
|
+
* @see https://deepkit.io/en/documentation/runtime-types/reflection
|
|
43
|
+
*
|
|
44
|
+
* @param context - The context object providing access to the file system and cache path.
|
|
45
|
+
* @param input - The schema definition input to extract, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object. If the input is a string or a type definition reference, it will be resolved and bundled to obtain the actual schema definition before extraction.
|
|
46
|
+
* @param options - Optional overrides for the ESBuild configuration used during extraction. This can include custom plugins, loaders, or other build options to control how the schema definition is resolved and bundled when the input is a type definition reference.
|
|
47
|
+
* @returns A promise that resolves to the extracted and normalized schema as a JSON Schema object. The function will attempt to extract a valid JSON Schema from the provided input, and if successful, it will return the schema. If the extraction process fails or if the input is not a valid schema definition, it will throw an error indicating the failure.
|
|
84
48
|
*/
|
|
85
|
-
declare function extractSchema<
|
|
49
|
+
declare function extractSchema<T = unknown>(context: Context, input: SchemaInput, options?: Partial<BuildOptions>): Promise<ExtractedSchema<T>>;
|
|
86
50
|
/**
|
|
87
|
-
*
|
|
51
|
+
* Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object. If the input is a type definition reference (e.g. a file path with an export), it will be resolved and bundled using ESBuild to obtain the actual schema definition before extraction.
|
|
88
52
|
*
|
|
89
53
|
* @example
|
|
90
54
|
* ```ts
|
|
@@ -106,12 +70,13 @@ declare function extractSchema<TMetadata extends Partial<SchemaMetadata> = Parti
|
|
|
106
70
|
* @see https://github.com/unjs/untyped
|
|
107
71
|
* @see https://www.typescriptlang.org/docs/handbook/2/types-from-types.html
|
|
108
72
|
*
|
|
109
|
-
* @param context - The
|
|
110
|
-
* @param input - The
|
|
111
|
-
* @param options - Optional overrides for the
|
|
112
|
-
* @returns A promise that resolves to
|
|
73
|
+
* @param context - The context object providing access to the file system and cache path.
|
|
74
|
+
* @param input - The schema definition input to extract, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.
|
|
75
|
+
* @param options - Optional overrides for the ESBuild configuration used during extraction.
|
|
76
|
+
* @returns A promise that resolves to the extracted and normalized schema as a JSON Schema object.
|
|
77
|
+
* @throws Will throw an error if the input is not a valid schema definition or if the extraction process fails to produce a valid schema.
|
|
113
78
|
*/
|
|
114
|
-
declare function extract<
|
|
79
|
+
declare function extract<T = unknown>(context: Context, input: SchemaInput, options?: Partial<BuildOptions>): Promise<Schema<T>>;
|
|
115
80
|
//#endregion
|
|
116
81
|
export { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaSchema, extractSource, extractVariant };
|
|
117
82
|
//# sourceMappingURL=extract.d.cts.map
|
package/dist/extract.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.d.cts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"extract.d.cts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;;;;AAiNA;iBAAgB,WAAA,aAAA,CACd,OAAA,EAAS,kBAAA,EACT,KAAA,EAAO,WAAA,CAAY,CAAA;;;;iBAkCL,iBAAA,aAAA,CACd,UAAA,EAAY,IAAA,GACX,UAAA,CAAW,CAAA;;;;iBAWE,iBAAA,aAAA,CACd,MAAA,YACC,UAAU,CAAC,CAAA;AAAA,iBA6BE,sBAAA,CACd,KAAA,EAAO,iBAAA,GACN,mBAAmB;AAAA,iBAoBN,cAAA,aAAA,CACd,KAAA,EAAO,WAAA,CAAY,CAAA,IAClB,kBAAA;AAAA,iBAQmB,mBAAA,aAAA,CACpB,KAAA,EAAO,iBAAA,EACP,OAAA,GAAU,kBAAA,GACT,OAAA,CAAQ,UAAA,CAAW,CAAA;AAAA,iBA4BN,aAAA,CACd,OAAA,EAAS,mBAAA,EACT,KAAA,EAAO,iBAAA,GACN,YAAA;;AAhJoB;AAkCvB;;;;;;;;;;;;;;AAEe;AAWf;;;;;;;;;iBAiKsB,aAAA,aAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,OAAA,CAAQ,YAAA,IAChB,OAAA,CAAQ,eAAA,CAAgB,CAAA;AAtI3B;;;;;;;;AAEsB;AAoBtB;;;;;;;;;;;;;;AAEqB;AAQrB;;;;;AAhCA,iBAiOsB,OAAA,aAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,OAAA,CAAQ,YAAA,IAChB,OAAA,CAAQ,MAAA,CAAO,CAAA"}
|
package/dist/extract.d.mts
CHANGED
|
@@ -1,90 +1,54 @@
|
|
|
1
|
-
import { ExtractedSchema,
|
|
2
|
-
import { BuildOptions } from "
|
|
1
|
+
import { ExtractedSchema, JsonSchema, Schema, SchemaInput, SchemaInputVariant, SchemaSource, SchemaSourceInput, SchemaSourceVariant } from "./types.mjs";
|
|
2
|
+
import { BuildOptions } from "rolldown";
|
|
3
3
|
import { Context } from "@powerlines/core";
|
|
4
4
|
import { Type } from "@powerlines/deepkit/vendor/type";
|
|
5
5
|
|
|
6
6
|
//#region src/extract.d.ts
|
|
7
7
|
/**
|
|
8
|
-
* Creates a hash string for a given schema definition input.
|
|
8
|
+
* Creates a hash string for a given schema definition input.
|
|
9
9
|
*/
|
|
10
|
-
declare function extractHash(variant: SchemaInputVariant, input: SchemaInput): string;
|
|
10
|
+
declare function extractHash<T = unknown>(variant: SchemaInputVariant, input: SchemaInput<T>): string;
|
|
11
11
|
/**
|
|
12
|
-
* Converts a reflected Deepkit {@link
|
|
13
|
-
*
|
|
14
|
-
* @remarks
|
|
15
|
-
* This function delegates to an internal recursive walker that handles the full set of Deepkit reflection kinds.
|
|
16
|
-
*
|
|
17
|
-
* @param reflection - The reflected Deepkit Type to convert.
|
|
18
|
-
* @returns A JSON Schema (draft-07) fragment representing the type, or `undefined` when no schema could be produced.
|
|
12
|
+
* Converts a reflected Deepkit {@link Type} into a JSON Schema (draft-07) representation.
|
|
19
13
|
*/
|
|
20
|
-
declare function extractReflection<
|
|
14
|
+
declare function extractReflection<T = unknown>(reflection: Type): JsonSchema<T> | undefined;
|
|
21
15
|
/**
|
|
22
|
-
* Extracts a JSON
|
|
23
|
-
*
|
|
24
|
-
* @remarks
|
|
25
|
-
* This function checks if the provided input is a Zod schema, a Standard JSON Schema, or already a JSON Schema object, extracts a JSON Schema fragment via the appropriate adapter (Zod and Standard Schema produce draft-07 fragments), and then converts that fragment into a valid JTD form suitable for AJV's JTD validator.
|
|
26
|
-
*
|
|
27
|
-
* @param schema - The schema definition to extract from. This can be a Zod schema, a Standard JSON Schema, or a JSON Schema object.
|
|
28
|
-
* @returns The extracted JTD schema if successful, otherwise undefined.
|
|
29
|
-
*/
|
|
30
|
-
declare function extractJsonSchema<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>>(schema: unknown): JTDSchemaType<TMetadata> | undefined;
|
|
31
|
-
/**
|
|
32
|
-
* Extracts a schema definition from a given input object, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object. The function checks the type of the input and attempts to extract the corresponding schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns a `Schema` containing the extracted schema and its variant if successful; otherwise, it throws an error.
|
|
33
|
-
*
|
|
34
|
-
* @param input - The input object to extract the schema definition from.
|
|
35
|
-
* @returns A `Schema` containing the extracted schema and its variant if successful.
|
|
36
|
-
* @throws An error if the input does not contain a valid schema definition.
|
|
16
|
+
* Extracts a JSON Schema from Zod, Standard Schema, untyped, or JSON Schema inputs.
|
|
37
17
|
*/
|
|
18
|
+
declare function extractJsonSchema<T = unknown>(schema: unknown): JsonSchema<T> | undefined;
|
|
38
19
|
declare function extractResolvedVariant(input: SchemaSourceInput): SchemaSourceVariant;
|
|
20
|
+
declare function extractVariant<T = unknown>(input: SchemaInput<T>): SchemaInputVariant;
|
|
21
|
+
declare function extractSchemaSchema<T = unknown>(input: SchemaSourceInput, variant?: SchemaInputVariant): Promise<JsonSchema<T>>;
|
|
22
|
+
declare function extractSource(variant: SchemaSourceVariant, input: SchemaSourceInput): SchemaSource;
|
|
39
23
|
/**
|
|
40
|
-
* Extracts a
|
|
41
|
-
*
|
|
42
|
-
* @param input - The input object to extract the schema definition from.
|
|
43
|
-
* @returns A `Schema` containing the extracted schema and its variant if successful.
|
|
44
|
-
* @throws An error if the input does not contain a valid schema definition.
|
|
45
|
-
*/
|
|
46
|
-
declare function extractVariant(input: SchemaInput): SchemaInputVariant;
|
|
47
|
-
/**
|
|
48
|
-
* Extracts a JSON Schema object from a given schema definition input. The input can be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object. The function checks the type of the input and attempts to extract the corresponding JSON Schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns the extracted JSON Schema if successful; otherwise, it throws an error.
|
|
49
|
-
*
|
|
50
|
-
* @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.
|
|
51
|
-
* @param variant - The variant of the schema definition to extract.
|
|
52
|
-
* @returns The extracted JSON Schema if successful.
|
|
53
|
-
* @throws An error if the input does not contain a valid schema definition.
|
|
54
|
-
*/
|
|
55
|
-
declare function extractSchemaSchema<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>>(input: SchemaSourceInput, variant?: SchemaInputVariant): Promise<JTDSchemaType<TMetadata>>;
|
|
56
|
-
/**
|
|
57
|
-
* Extracts a schema definition from a given input object, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, a JTD schema, an untyped schema, or a reflected Deepkit Type object. The function checks the type of the input and attempts to extract the corresponding schema based on its variant. If the input is a Zod schema, it extracts the JSON Schema using the `extractJsonSchema` function. If the input is a Standard JSON Schema, it retrieves the JSON Schema targeting draft-07. If the input is already a JSON Schema object, it uses it directly. If the input is a reflected Deepkit Type object, it extracts the schema using the `extractReflection` function. The function returns a `Schema` containing the extracted schema and its variant if successful; otherwise, it throws an error.
|
|
58
|
-
*
|
|
59
|
-
* @param variant - The variant of the schema definition to extract.
|
|
60
|
-
* @param input - The input object to extract the schema definition from.
|
|
61
|
-
* @returns A `Schema` containing the extracted schema and its variant if successful.
|
|
62
|
-
* @throws An error if the input does not contain a valid schema definition.
|
|
63
|
-
*/
|
|
64
|
-
declare function extractSource<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>>(variant: SchemaSourceVariant, input: SchemaSourceInput): SchemaSource;
|
|
65
|
-
/**
|
|
66
|
-
* 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.
|
|
24
|
+
* Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object. If the input is a type definition reference (e.g. a file path with an export), it will be resolved and bundled using ESBuild to obtain the actual schema definition before extraction.
|
|
67
25
|
*
|
|
68
26
|
* @example
|
|
69
27
|
* ```ts
|
|
70
28
|
* // Resolve a schema definition from a file path
|
|
71
|
-
* const schema1 = await
|
|
29
|
+
* const schema1 = await extract(context, "./schemas.ts#MySchema");
|
|
72
30
|
* // Resolve a schema definition from a JSON Schema object
|
|
73
|
-
* const schema2 = await
|
|
31
|
+
* const schema2 = await extract(context, schemaObject);
|
|
74
32
|
* // Resolve a schema definition from a Zod schema
|
|
75
|
-
* const schema3 = await
|
|
33
|
+
* const schema3 = await extract(context, zodSchema);
|
|
76
34
|
* // Resolve a schema definition from a reflected Deepkit Type object
|
|
77
|
-
* const schema4 = await
|
|
35
|
+
* const schema4 = await extract(context, reflectionType);
|
|
78
36
|
* ```
|
|
79
37
|
*
|
|
80
|
-
* @
|
|
81
|
-
* @
|
|
82
|
-
* @
|
|
83
|
-
* @
|
|
38
|
+
* @see https://github.com/colinhacks/zod
|
|
39
|
+
* @see https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec
|
|
40
|
+
* @see https://json-schema.org/
|
|
41
|
+
* @see https://ajv.js.org/json-type-definition.html
|
|
42
|
+
* @see https://deepkit.io/en/documentation/runtime-types/reflection
|
|
43
|
+
*
|
|
44
|
+
* @param context - The context object providing access to the file system and cache path.
|
|
45
|
+
* @param input - The schema definition input to extract, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object. If the input is a string or a type definition reference, it will be resolved and bundled to obtain the actual schema definition before extraction.
|
|
46
|
+
* @param options - Optional overrides for the ESBuild configuration used during extraction. This can include custom plugins, loaders, or other build options to control how the schema definition is resolved and bundled when the input is a type definition reference.
|
|
47
|
+
* @returns A promise that resolves to the extracted and normalized schema as a JSON Schema object. The function will attempt to extract a valid JSON Schema from the provided input, and if successful, it will return the schema. If the extraction process fails or if the input is not a valid schema definition, it will throw an error indicating the failure.
|
|
84
48
|
*/
|
|
85
|
-
declare function extractSchema<
|
|
49
|
+
declare function extractSchema<T = unknown>(context: Context, input: SchemaInput, options?: Partial<BuildOptions>): Promise<ExtractedSchema<T>>;
|
|
86
50
|
/**
|
|
87
|
-
*
|
|
51
|
+
* Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object. If the input is a type definition reference (e.g. a file path with an export), it will be resolved and bundled using ESBuild to obtain the actual schema definition before extraction.
|
|
88
52
|
*
|
|
89
53
|
* @example
|
|
90
54
|
* ```ts
|
|
@@ -106,12 +70,13 @@ declare function extractSchema<TMetadata extends Partial<SchemaMetadata> = Parti
|
|
|
106
70
|
* @see https://github.com/unjs/untyped
|
|
107
71
|
* @see https://www.typescriptlang.org/docs/handbook/2/types-from-types.html
|
|
108
72
|
*
|
|
109
|
-
* @param context - The
|
|
110
|
-
* @param input - The
|
|
111
|
-
* @param options - Optional overrides for the
|
|
112
|
-
* @returns A promise that resolves to
|
|
73
|
+
* @param context - The context object providing access to the file system and cache path.
|
|
74
|
+
* @param input - The schema definition input to extract, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.
|
|
75
|
+
* @param options - Optional overrides for the ESBuild configuration used during extraction.
|
|
76
|
+
* @returns A promise that resolves to the extracted and normalized schema as a JSON Schema object.
|
|
77
|
+
* @throws Will throw an error if the input is not a valid schema definition or if the extraction process fails to produce a valid schema.
|
|
113
78
|
*/
|
|
114
|
-
declare function extract<
|
|
79
|
+
declare function extract<T = unknown>(context: Context, input: SchemaInput, options?: Partial<BuildOptions>): Promise<Schema<T>>;
|
|
115
80
|
//#endregion
|
|
116
81
|
export { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaSchema, extractSource, extractVariant };
|
|
117
82
|
//# sourceMappingURL=extract.d.mts.map
|
package/dist/extract.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.d.mts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"extract.d.mts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;;;;AAiNA;iBAAgB,WAAA,aAAA,CACd,OAAA,EAAS,kBAAA,EACT,KAAA,EAAO,WAAA,CAAY,CAAA;;;;iBAkCL,iBAAA,aAAA,CACd,UAAA,EAAY,IAAA,GACX,UAAA,CAAW,CAAA;;;;iBAWE,iBAAA,aAAA,CACd,MAAA,YACC,UAAU,CAAC,CAAA;AAAA,iBA6BE,sBAAA,CACd,KAAA,EAAO,iBAAA,GACN,mBAAmB;AAAA,iBAoBN,cAAA,aAAA,CACd,KAAA,EAAO,WAAA,CAAY,CAAA,IAClB,kBAAA;AAAA,iBAQmB,mBAAA,aAAA,CACpB,KAAA,EAAO,iBAAA,EACP,OAAA,GAAU,kBAAA,GACT,OAAA,CAAQ,UAAA,CAAW,CAAA;AAAA,iBA4BN,aAAA,CACd,OAAA,EAAS,mBAAA,EACT,KAAA,EAAO,iBAAA,GACN,YAAA;;AAhJoB;AAkCvB;;;;;;;;;;;;;;AAEe;AAWf;;;;;;;;;iBAiKsB,aAAA,aAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,OAAA,CAAQ,YAAA,IAChB,OAAA,CAAQ,eAAA,CAAgB,CAAA;AAtI3B;;;;;;;;AAEsB;AAoBtB;;;;;;;;;;;;;;AAEqB;AAQrB;;;;;AAhCA,iBAiOsB,OAAA,aAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,OAAA,CAAQ,YAAA,IAChB,OAAA,CAAQ,MAAA,CAAO,CAAA"}
|