@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.
Files changed (82) hide show
  1. package/dist/bundle.cjs +34 -20
  2. package/dist/bundle.d.cts +3 -3
  3. package/dist/bundle.d.cts.map +1 -1
  4. package/dist/bundle.d.mts +3 -3
  5. package/dist/bundle.d.mts.map +1 -1
  6. package/dist/bundle.mjs +35 -21
  7. package/dist/bundle.mjs.map +1 -1
  8. package/dist/codegen.cjs +40 -36
  9. package/dist/codegen.d.cts +10 -22
  10. package/dist/codegen.d.cts.map +1 -1
  11. package/dist/codegen.d.mts +10 -22
  12. package/dist/codegen.d.mts.map +1 -1
  13. package/dist/codegen.mjs +39 -36
  14. package/dist/codegen.mjs.map +1 -1
  15. package/dist/constants.cjs +34 -11
  16. package/dist/constants.d.cts +9 -11
  17. package/dist/constants.d.cts.map +1 -1
  18. package/dist/constants.d.mts +9 -11
  19. package/dist/constants.d.mts.map +1 -1
  20. package/dist/constants.mjs +32 -11
  21. package/dist/constants.mjs.map +1 -1
  22. package/dist/extract.cjs +122 -92
  23. package/dist/extract.d.cts +34 -69
  24. package/dist/extract.d.cts.map +1 -1
  25. package/dist/extract.d.mts +34 -69
  26. package/dist/extract.d.mts.map +1 -1
  27. package/dist/extract.mjs +123 -93
  28. package/dist/extract.mjs.map +1 -1
  29. package/dist/helpers.cjs +45 -52
  30. package/dist/helpers.d.cts +28 -24
  31. package/dist/helpers.d.cts.map +1 -1
  32. package/dist/helpers.d.mts +28 -24
  33. package/dist/helpers.d.mts.map +1 -1
  34. package/dist/helpers.mjs +46 -52
  35. package/dist/helpers.mjs.map +1 -1
  36. package/dist/index.cjs +14 -7
  37. package/dist/index.d.cts +6 -6
  38. package/dist/index.d.mts +6 -6
  39. package/dist/index.mjs +5 -5
  40. package/dist/metadata.cjs +80 -0
  41. package/dist/metadata.d.cts +52 -0
  42. package/dist/metadata.d.cts.map +1 -0
  43. package/dist/metadata.d.mts +52 -0
  44. package/dist/metadata.d.mts.map +1 -0
  45. package/dist/metadata.mjs +76 -0
  46. package/dist/metadata.mjs.map +1 -0
  47. package/dist/persistence.cjs +1 -2
  48. package/dist/persistence.d.cts +5 -5
  49. package/dist/persistence.d.cts.map +1 -1
  50. package/dist/persistence.d.mts +5 -5
  51. package/dist/persistence.d.mts.map +1 -1
  52. package/dist/persistence.mjs +1 -1
  53. package/dist/persistence.mjs.map +1 -1
  54. package/dist/reflection.cjs +289 -303
  55. package/dist/reflection.d.cts +3 -16
  56. package/dist/reflection.d.cts.map +1 -1
  57. package/dist/reflection.d.mts +3 -16
  58. package/dist/reflection.d.mts.map +1 -1
  59. package/dist/reflection.mjs +290 -304
  60. package/dist/reflection.mjs.map +1 -1
  61. package/dist/resolve.cjs +7 -7
  62. package/dist/resolve.mjs +7 -7
  63. package/dist/resolve.mjs.map +1 -1
  64. package/dist/type-checks.cjs +122 -40
  65. package/dist/type-checks.d.cts +41 -33
  66. package/dist/type-checks.d.cts.map +1 -1
  67. package/dist/type-checks.d.mts +41 -33
  68. package/dist/type-checks.d.mts.map +1 -1
  69. package/dist/type-checks.mjs +120 -37
  70. package/dist/type-checks.mjs.map +1 -1
  71. package/dist/types.d.cts +225 -113
  72. package/dist/types.d.cts.map +1 -1
  73. package/dist/types.d.mts +225 -113
  74. package/dist/types.d.mts.map +1 -1
  75. package/package.json +11 -7
  76. package/dist/jtd.cjs +0 -385
  77. package/dist/jtd.d.cts +0 -15
  78. package/dist/jtd.d.cts.map +0 -1
  79. package/dist/jtd.d.mts +0 -15
  80. package/dist/jtd.d.mts.map +0 -1
  81. package/dist/jtd.mjs +0 -384
  82. package/dist/jtd.mjs.map +0 -1
@@ -1,90 +1,54 @@
1
- import { ExtractedSchema, JTDSchemaType, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant } from "./types.cjs";
1
+ import { ExtractedSchema, JsonSchema, Schema, SchemaInput, SchemaInputVariant, SchemaSource, SchemaSourceInput, SchemaSourceVariant } from "./types.cjs";
2
2
  import { Context } from "@powerlines/core";
3
- import { BuildOptions } from "esbuild";
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. The function checks the type of the input and generates a hash based on its content. If the input is a Zod schema, it hashes the JSON representation of its internal definition. If the input is a Standard JSON Schema, it hashes the JSON representation of its internal standard schema. If the input is already a JSON Schema object, it hashes its JSON representation directly. If the input is a reflected Deepkit Type object, it hashes its JSON representation. The resulting hash string can be used for caching or comparison purposes.
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 @powerlines/deepkit/vendor/type#Type} into a JSON Schema (draft-07) representation.
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<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>>(reflection: Type): JTDSchemaType<TMetadata> | undefined;
14
+ declare function extractReflection<T = unknown>(reflection: Type): JsonSchema<T> | undefined;
21
15
  /**
22
- * Extracts a JSON Type Definition (RFC 8927) schema from a given schema definition, if possible.
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 schema definition from a given input object, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, a reflected Deepkit Type object, or an Untyped schema. 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.
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 extractSchema(context, "./schemas.ts#MySchema");
29
+ * const schema1 = await extract(context, "./schemas.ts#MySchema");
72
30
  * // Resolve a schema definition from a JSON Schema object
73
- * const schema2 = await extractSchema(context, schemaObject);
31
+ * const schema2 = await extract(context, schemaObject);
74
32
  * // Resolve a schema definition from a Zod schema
75
- * const schema3 = await extractSchema(context, zodSchema);
33
+ * const schema3 = await extract(context, zodSchema);
76
34
  * // Resolve a schema definition from a reflected Deepkit Type object
77
- * const schema4 = await extractSchema(context, reflectionType);
35
+ * const schema4 = await extract(context, reflectionType);
78
36
  * ```
79
37
  *
80
- * @param context - The plugin context used for resolving the schema definition input.
81
- * @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.
82
- * @param options - Optional overrides for the ESBuild configuration used during resolution.
83
- * @returns A promise that resolves to a {@link ExtractedSchema} containing the extracted JSON Schema and its variant, or the bytecode if JSON Schema extraction is not possible.
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<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>, TContext extends Context = Context>(context: TContext, input: SchemaInput, options?: Partial<BuildOptions>): Promise<ExtractedSchema<TMetadata>>;
49
+ declare function extractSchema<T = unknown>(context: Context, input: SchemaInput, options?: Partial<BuildOptions>): Promise<ExtractedSchema<T>>;
86
50
  /**
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.
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 {@link Context | context} used for resolving the {@link Schema | schema} definition input.
110
- * @param input - The input object or string to extract the {@link Schema | schema} from. This can be {@link TypeDefinitionReference | a string that references a Typescript module}, a [Zod v3 schema](https://github.com/colinhacks/zod), any type that adheres to [the Standard JSON Schema specification](https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec), a [JSON Schema object](https://json-schema.org/), a [JTD schema object](https://ajv.js.org/json-type-definition.html), an [untyped schema](https://github.com/unjs/untyped), or a [TypeScript type reflection](https://deepkit.io/en/documentation/runtime-types/reflection).
111
- * @param options - Optional overrides for the [ESBuild configuration](https://esbuild.github.io/api/#general-options) used during resolution.
112
- * @returns A promise that resolves to a {@link Schema | schema} object parsed from the input.
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<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>, TContext extends Context = Context>(context: TContext, input: SchemaInput, options?: Partial<BuildOptions>): Promise<Schema<TMetadata>>;
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
@@ -1 +1 @@
1
- {"version":3,"file":"extract.d.cts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;;;;AAqEA;iBAAgB,WAAA,CACd,OAAA,EAAS,kBAAA,EACT,KAAA,EAAO,WAAW;;;;;;;;AAAA;AA8BpB;iBAAgB,iBAAA,mBACI,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,EAAA,CACpD,UAAA,EAAY,IAAA,GAAO,aAAA,CA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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"}
@@ -1,90 +1,54 @@
1
- import { ExtractedSchema, JTDSchemaType, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant } from "./types.mjs";
2
- import { BuildOptions } from "esbuild";
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. The function checks the type of the input and generates a hash based on its content. If the input is a Zod schema, it hashes the JSON representation of its internal definition. If the input is a Standard JSON Schema, it hashes the JSON representation of its internal standard schema. If the input is already a JSON Schema object, it hashes its JSON representation directly. If the input is a reflected Deepkit Type object, it hashes its JSON representation. The resulting hash string can be used for caching or comparison purposes.
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 @powerlines/deepkit/vendor/type#Type} into a JSON Schema (draft-07) representation.
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<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>>(reflection: Type): JTDSchemaType<TMetadata> | undefined;
14
+ declare function extractReflection<T = unknown>(reflection: Type): JsonSchema<T> | undefined;
21
15
  /**
22
- * Extracts a JSON Type Definition (RFC 8927) schema from a given schema definition, if possible.
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 schema definition from a given input object, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, a reflected Deepkit Type object, or an Untyped schema. 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.
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 extractSchema(context, "./schemas.ts#MySchema");
29
+ * const schema1 = await extract(context, "./schemas.ts#MySchema");
72
30
  * // Resolve a schema definition from a JSON Schema object
73
- * const schema2 = await extractSchema(context, schemaObject);
31
+ * const schema2 = await extract(context, schemaObject);
74
32
  * // Resolve a schema definition from a Zod schema
75
- * const schema3 = await extractSchema(context, zodSchema);
33
+ * const schema3 = await extract(context, zodSchema);
76
34
  * // Resolve a schema definition from a reflected Deepkit Type object
77
- * const schema4 = await extractSchema(context, reflectionType);
35
+ * const schema4 = await extract(context, reflectionType);
78
36
  * ```
79
37
  *
80
- * @param context - The plugin context used for resolving the schema definition input.
81
- * @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.
82
- * @param options - Optional overrides for the ESBuild configuration used during resolution.
83
- * @returns A promise that resolves to a {@link ExtractedSchema} containing the extracted JSON Schema and its variant, or the bytecode if JSON Schema extraction is not possible.
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<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>, TContext extends Context = Context>(context: TContext, input: SchemaInput, options?: Partial<BuildOptions>): Promise<ExtractedSchema<TMetadata>>;
49
+ declare function extractSchema<T = unknown>(context: Context, input: SchemaInput, options?: Partial<BuildOptions>): Promise<ExtractedSchema<T>>;
86
50
  /**
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.
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 {@link Context | context} used for resolving the {@link Schema | schema} definition input.
110
- * @param input - The input object or string to extract the {@link Schema | schema} from. This can be {@link TypeDefinitionReference | a string that references a Typescript module}, a [Zod v3 schema](https://github.com/colinhacks/zod), any type that adheres to [the Standard JSON Schema specification](https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec), a [JSON Schema object](https://json-schema.org/), a [JTD schema object](https://ajv.js.org/json-type-definition.html), an [untyped schema](https://github.com/unjs/untyped), or a [TypeScript type reflection](https://deepkit.io/en/documentation/runtime-types/reflection).
111
- * @param options - Optional overrides for the [ESBuild configuration](https://esbuild.github.io/api/#general-options) used during resolution.
112
- * @returns A promise that resolves to a {@link Schema | schema} object parsed from the input.
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<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>, TContext extends Context = Context>(context: TContext, input: SchemaInput, options?: Partial<BuildOptions>): Promise<Schema<TMetadata>>;
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
@@ -1 +1 @@
1
- {"version":3,"file":"extract.d.mts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;;;;AAqEA;iBAAgB,WAAA,CACd,OAAA,EAAS,kBAAA,EACT,KAAA,EAAO,WAAW;;;;;;;;AAAA;AA8BpB;iBAAgB,iBAAA,mBACI,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,EAAA,CACpD,UAAA,EAAY,IAAA,GAAO,aAAA,CAAc,SAAA;;;;;;;;;;iBAiBnB,iBAAA,mBACI,OAAA,CAAQ,cAAA,IAAkB,OAAA,CAAQ,cAAA,EAAA,CACpD,MAAA,YAAkB,aAAA,CAAc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