@powerlines/schema 0.11.57 → 0.11.59
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/constants.cjs +18 -1
- package/dist/constants.d.cts +2 -1
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +2 -1
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +17 -1
- package/dist/constants.mjs.map +1 -1
- package/dist/extract.cjs +10 -3
- package/dist/extract.d.cts.map +1 -1
- package/dist/extract.d.mts.map +1 -1
- package/dist/extract.mjs +11 -4
- package/dist/extract.mjs.map +1 -1
- package/dist/helpers.cjs +57 -15
- package/dist/helpers.d.cts +35 -6
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +35 -6
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +55 -16
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +6 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +4 -4
- package/dist/resolve.cjs +35 -12
- package/dist/resolve.d.cts +7 -7
- package/dist/resolve.d.cts.map +1 -1
- package/dist/resolve.d.mts +7 -7
- package/dist/resolve.d.mts.map +1 -1
- package/dist/resolve.mjs +35 -12
- package/dist/resolve.mjs.map +1 -1
- package/dist/type-checks.cjs +94 -0
- package/dist/type-checks.d.cts +92 -1
- package/dist/type-checks.d.cts.map +1 -1
- package/dist/type-checks.d.mts +92 -1
- package/dist/type-checks.d.mts.map +1 -1
- package/dist/type-checks.mjs +94 -1
- package/dist/type-checks.mjs.map +1 -1
- package/dist/types.d.cts +4 -8
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +4 -8
- package/dist/types.d.mts.map +1 -1
- package/package.json +21 -17
package/dist/helpers.d.mts
CHANGED
|
@@ -6,6 +6,28 @@ type GetPropertiesResult = JsonSchema & {
|
|
|
6
6
|
required: boolean;
|
|
7
7
|
default?: unknown;
|
|
8
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves the JSON Schema from a Schema wrapper or returns the input if it's already a JSON Schema.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* This function checks if the input is a Schema wrapper (an object with a `schema` property) and returns the `schema` if it is. If the input is already a JSON Schema, it returns it directly. This allows for flexibility in handling both raw JSON Schema objects and wrapped schemas without needing to check the type at every usage point.
|
|
14
|
+
*
|
|
15
|
+
* @param input - The input which can be either a Schema wrapper or a JSON Schema object.
|
|
16
|
+
* @returns The JSON Schema object.
|
|
17
|
+
* @throws Will throw a TypeError if the input is neither a valid Schema wrapper nor a valid JSON Schema object.
|
|
18
|
+
*/
|
|
19
|
+
declare function getJsonSchema(input: Schema | JsonSchema): JsonSchema;
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves the JSON Schema in Object form from a Schema wrapper or returns the input if it's already a JSON Schema.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* This function checks if the input is a Schema wrapper (an object with a `schema` property) and returns the `schema` if it is. If the input is already a JSON Schema object, it returns it directly. This allows for flexibility in handling both raw JSON Schema objects and wrapped schemas without needing to check the type at every usage point.
|
|
25
|
+
*
|
|
26
|
+
* @param input - The input which can be either a Schema wrapper or a JSON Schema object.
|
|
27
|
+
* @returns The JSON Schema object.
|
|
28
|
+
* @throws Will throw a TypeError if the input is neither a valid Schema wrapper nor a valid JSON Schema object.
|
|
29
|
+
*/
|
|
30
|
+
declare function getJsonSchemaObject(input: Schema | JsonSchema): JsonSchemaObject;
|
|
9
31
|
/**
|
|
10
32
|
* Extracts object properties from a JSON Schema object form.
|
|
11
33
|
*
|
|
@@ -47,15 +69,15 @@ declare function getPropertiesList(obj: Schema | JsonSchemaObject): (JsonSchema
|
|
|
47
69
|
*/
|
|
48
70
|
declare function addProperty(obj: Schema | JsonSchemaObject, name: string, property: JsonSchema): void;
|
|
49
71
|
/**
|
|
50
|
-
* Merges multiple JSON
|
|
72
|
+
* Merges multiple JSON Schemas into one.
|
|
51
73
|
*
|
|
52
74
|
* @remarks
|
|
53
|
-
* This function takes multiple JSON
|
|
75
|
+
* This function takes multiple JSON Schemas or Schema wrappers and merges them into a single JSON Schema object. The merging process combines properties and metadata from all provided schemas, with later schemas in the arguments list taking precedence over earlier ones in case of conflicts. The resulting schema will include all unique properties and metadata from the input schemas.
|
|
54
76
|
*
|
|
55
|
-
* @param schemas - An array of JSON
|
|
56
|
-
* @returns A new JSON Schema
|
|
77
|
+
* @param schemas - An array of JSON Schemas or Schema wrappers to merge.
|
|
78
|
+
* @returns A new JSON Schema that is the result of merging all input schemas.
|
|
57
79
|
*/
|
|
58
|
-
declare function
|
|
80
|
+
declare function merge(...schemas: (JsonSchema | Schema)[]): JsonSchema;
|
|
59
81
|
/**
|
|
60
82
|
* Returns whether a JSON Schema fragment accepts `null`.
|
|
61
83
|
*
|
|
@@ -77,6 +99,13 @@ declare function isSchemaNullable(schema?: JsonSchema): boolean;
|
|
|
77
99
|
* @returns `true` if the property is optional, otherwise `false`.
|
|
78
100
|
*/
|
|
79
101
|
declare function isPropertyOptional(parent: JsonSchemaObject, propertyName: string): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Checks if a given file name has a valid schema input file extension.
|
|
104
|
+
*
|
|
105
|
+
* @param fileName - The file name to check for a valid schema input extension.
|
|
106
|
+
* @returns `true` if the file name has a valid schema input extension, otherwise `false`.
|
|
107
|
+
*/
|
|
108
|
+
declare function isValidSchemaInputFile(fileName: string): boolean;
|
|
80
109
|
//#endregion
|
|
81
|
-
export { GetPropertiesResult, addProperty, getProperties, getPropertiesList, isPropertyOptional, isSchemaNullable,
|
|
110
|
+
export { GetPropertiesResult, addProperty, getJsonSchema, getJsonSchemaObject, getProperties, getPropertiesList, isPropertyOptional, isSchemaNullable, isValidSchemaInputFile, merge };
|
|
82
111
|
//# sourceMappingURL=helpers.d.mts.map
|
package/dist/helpers.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.mts","names":[],"sources":["../src/helpers.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"helpers.d.mts","names":[],"sources":["../src/helpers.ts"],"mappings":";;;KA2BY,mBAAA,GAAsB,UAAU;EAC1C,IAAA;EACA,QAAA;EACA,OAAA;AAAA;;;;;;;AAAO;AAaT;;;iBAAgB,aAAA,CAAc,KAAA,EAAO,MAAA,GAAS,UAAA,GAAa,UAAA;;;;;;;;;;AAAU;iBAmBrD,mBAAA,CACd,KAAA,EAAO,MAAA,GAAS,UAAA,GACf,gBAAA;;;;;;;;;;iBAkBa,aAAA,CACd,GAAA,EAAK,MAAA,GAAS,gBAAA,GACb,MAAA,SAED,UAAA;EAAe,IAAA;EAAc,QAAA;EAAmB,OAAA;AAAA;;;;;;;;;;iBAuClC,iBAAA,CAAkB,GAAA,EAAK,MAAA,GAAS,gBAAA,IAAgB,UAAA;;;;;;;;AAvCP;AAuCzD;;;;;;;iBAegB,WAAA,CACd,GAAA,EAAK,MAAA,GAAS,gBAAA,EACd,IAAA,UACA,QAAA,EAAU,UAAA;;;;;;;;;;iBA0BI,KAAA,CAAA,GAAS,OAAA,GAAU,UAAA,GAAa,MAAA,MAAY,UAAA;;;;;;;;;;iBA0B5C,gBAAA,CAAiB,MAAmB,GAAV,UAAU;;;;;AApD9B;AA0BtB;;;;;iBAgDgB,kBAAA,CACd,MAAA,EAAQ,gBAAgB,EACxB,YAAA;;;;;;;iBAiBc,sBAAA,CAAuB,QAAgB"}
|
package/dist/helpers.mjs
CHANGED
|
@@ -1,10 +1,43 @@
|
|
|
1
|
+
import { VALID_SOURCE_FILE_EXTENSIONS } from "./constants.mjs";
|
|
1
2
|
import { readSchemaTypes } from "./metadata.mjs";
|
|
2
|
-
import { isJsonSchemaObject, isSchema } from "./type-checks.mjs";
|
|
3
|
+
import { isJsonSchema, isJsonSchemaObject, isSchema } from "./type-checks.mjs";
|
|
3
4
|
import { defu as defu$1 } from "defu";
|
|
4
5
|
import { isSetObject } from "@stryke/type-checks";
|
|
6
|
+
import { getUnique } from "@stryke/helpers/get-unique";
|
|
7
|
+
import { findFileExtensionSafe } from "@stryke/path/find";
|
|
5
8
|
|
|
6
9
|
//#region src/helpers.ts
|
|
7
10
|
/**
|
|
11
|
+
* Retrieves the JSON Schema from a Schema wrapper or returns the input if it's already a JSON Schema.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* This function checks if the input is a Schema wrapper (an object with a `schema` property) and returns the `schema` if it is. If the input is already a JSON Schema, it returns it directly. This allows for flexibility in handling both raw JSON Schema objects and wrapped schemas without needing to check the type at every usage point.
|
|
15
|
+
*
|
|
16
|
+
* @param input - The input which can be either a Schema wrapper or a JSON Schema object.
|
|
17
|
+
* @returns The JSON Schema object.
|
|
18
|
+
* @throws Will throw a TypeError if the input is neither a valid Schema wrapper nor a valid JSON Schema object.
|
|
19
|
+
*/
|
|
20
|
+
function getJsonSchema(input) {
|
|
21
|
+
const schema = isSchema(input) ? input.schema : input;
|
|
22
|
+
if (!isJsonSchema(schema)) throw new TypeError("The provided input is not a valid JSON Schema");
|
|
23
|
+
return schema;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves the JSON Schema in Object form from a Schema wrapper or returns the input if it's already a JSON Schema.
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* This function checks if the input is a Schema wrapper (an object with a `schema` property) and returns the `schema` if it is. If the input is already a JSON Schema object, it returns it directly. This allows for flexibility in handling both raw JSON Schema objects and wrapped schemas without needing to check the type at every usage point.
|
|
30
|
+
*
|
|
31
|
+
* @param input - The input which can be either a Schema wrapper or a JSON Schema object.
|
|
32
|
+
* @returns The JSON Schema object.
|
|
33
|
+
* @throws Will throw a TypeError if the input is neither a valid Schema wrapper nor a valid JSON Schema object.
|
|
34
|
+
*/
|
|
35
|
+
function getJsonSchemaObject(input) {
|
|
36
|
+
const schema = getJsonSchema(input);
|
|
37
|
+
if (!isJsonSchemaObject(schema)) throw new TypeError("The provided input is not a valid JSON Schema object");
|
|
38
|
+
return schema;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
8
41
|
* Extracts object properties from a JSON Schema object form.
|
|
9
42
|
*
|
|
10
43
|
* @remarks
|
|
@@ -15,8 +48,7 @@ import { isSetObject } from "@stryke/type-checks";
|
|
|
15
48
|
*/
|
|
16
49
|
function getProperties(obj) {
|
|
17
50
|
const properties = {};
|
|
18
|
-
const schema =
|
|
19
|
-
if (!isJsonSchemaObject(schema)) return properties;
|
|
51
|
+
const schema = getJsonSchemaObject(obj);
|
|
20
52
|
if (!isSetObject(schema.properties)) return properties;
|
|
21
53
|
for (const [key, value] of Object.entries(schema.properties)) {
|
|
22
54
|
const propertySchema = {};
|
|
@@ -54,8 +86,7 @@ function getPropertiesList(obj) {
|
|
|
54
86
|
* @throws Will throw an error if the provided schema is not an object form.
|
|
55
87
|
*/
|
|
56
88
|
function addProperty(obj, name, property) {
|
|
57
|
-
const schema =
|
|
58
|
-
if (!isJsonSchemaObject(schema)) throw new Error("Cannot add property to non-object schema");
|
|
89
|
+
const schema = getJsonSchemaObject(obj);
|
|
59
90
|
schema.properties ??= {};
|
|
60
91
|
schema.required ??= [];
|
|
61
92
|
schema.properties[name] = {
|
|
@@ -66,20 +97,19 @@ function addProperty(obj, name, property) {
|
|
|
66
97
|
if (schema.required.length === 0) delete schema.required;
|
|
67
98
|
}
|
|
68
99
|
/**
|
|
69
|
-
* Merges multiple JSON
|
|
100
|
+
* Merges multiple JSON Schemas into one.
|
|
70
101
|
*
|
|
71
102
|
* @remarks
|
|
72
|
-
* This function takes multiple JSON
|
|
103
|
+
* This function takes multiple JSON Schemas or Schema wrappers and merges them into a single JSON Schema object. The merging process combines properties and metadata from all provided schemas, with later schemas in the arguments list taking precedence over earlier ones in case of conflicts. The resulting schema will include all unique properties and metadata from the input schemas.
|
|
73
104
|
*
|
|
74
|
-
* @param schemas - An array of JSON
|
|
75
|
-
* @returns A new JSON Schema
|
|
105
|
+
* @param schemas - An array of JSON Schemas or Schema wrappers to merge.
|
|
106
|
+
* @returns A new JSON Schema that is the result of merging all input schemas.
|
|
76
107
|
*/
|
|
77
|
-
function
|
|
78
|
-
|
|
79
|
-
for (const schema of schemas) {
|
|
80
|
-
|
|
81
|
-
if (
|
|
82
|
-
defu$1(result, jsonSchema);
|
|
108
|
+
function merge(...schemas) {
|
|
109
|
+
let result = {};
|
|
110
|
+
for (const schema of schemas.reverse()) if (!result.type || result.type === schema.type) {
|
|
111
|
+
result = defu$1(result, getJsonSchema(schema));
|
|
112
|
+
if (isJsonSchemaObject(result)) result.required = getUnique(result.required ?? []);
|
|
83
113
|
}
|
|
84
114
|
return result;
|
|
85
115
|
}
|
|
@@ -111,7 +141,16 @@ function isPropertyOptional(parent, propertyName) {
|
|
|
111
141
|
if (!parent.properties?.[propertyName]) throw new Error(`The property "${propertyName}" does not exist in the parent schema.`);
|
|
112
142
|
return !(parent.required ?? []).includes(propertyName);
|
|
113
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Checks if a given file name has a valid schema input file extension.
|
|
146
|
+
*
|
|
147
|
+
* @param fileName - The file name to check for a valid schema input extension.
|
|
148
|
+
* @returns `true` if the file name has a valid schema input extension, otherwise `false`.
|
|
149
|
+
*/
|
|
150
|
+
function isValidSchemaInputFile(fileName) {
|
|
151
|
+
return VALID_SOURCE_FILE_EXTENSIONS.includes(findFileExtensionSafe(fileName));
|
|
152
|
+
}
|
|
114
153
|
|
|
115
154
|
//#endregion
|
|
116
|
-
export { addProperty, getProperties, getPropertiesList, isPropertyOptional, isSchemaNullable,
|
|
155
|
+
export { addProperty, getJsonSchema, getJsonSchemaObject, getProperties, getPropertiesList, isPropertyOptional, isSchemaNullable, isValidSchemaInputFile, merge };
|
|
117
156
|
//# sourceMappingURL=helpers.mjs.map
|
package/dist/helpers.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.mjs","names":[],"sources":["../src/helpers.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 { isSetObject } from \"@stryke/type-checks\";\nimport { defu } from \"defu\";\nimport { readSchemaTypes } from \"./metadata\";\nimport { isJsonSchemaObject, isSchema } from \"./type-checks\";\nimport { JsonSchema, JsonSchemaObject, Schema } from \"./types\";\n\nexport type GetPropertiesResult = JsonSchema & {\n name: string;\n required: boolean;\n default?: unknown;\n};\n\n/**\n * Extracts object properties from a JSON Schema object form.\n *\n * @remarks\n * This function returns an empty object if the schema is not an object form or if it has no properties.\n *\n * @param obj - The JSON Schema object form or a Schema wrapper to extract properties from.\n * @returns An object mapping property names to their corresponding JSON Schema fragments, including metadata.\n */\nexport function getProperties(\n obj: Schema | JsonSchemaObject\n): Record<\n string,\n JsonSchema & { name: string; required: boolean; default?: unknown }\n> {\n const properties: Record<\n string,\n JsonSchema & { name: string; required: boolean; default?: unknown }\n > = {};\n const schema: JsonSchema = isSchema(obj) ? obj.schema : obj;\n if (!isJsonSchemaObject(schema)) {\n return properties;\n }\n\n if (!isSetObject(schema.properties)) {\n return properties;\n }\n\n for (const [key, value] of Object.entries(schema.properties)) {\n const propertySchema: Record<string, unknown> = {};\n\n if (typeof value !== \"boolean\") {\n Object.assign(propertySchema, value);\n }\n\n properties[key] = {\n ...propertySchema,\n name: key,\n required: !isPropertyOptional(schema, key),\n default: schema.default?.[key] ?? propertySchema.default\n };\n }\n\n return properties;\n}\n\n/**\n * Returns object properties as an array.\n *\n * @remarks\n * This is a convenience function that extracts properties using `getProperties` and returns them as an array.\n *\n * @param obj - The JSON Schema object form or a Schema wrapper to extract properties from.\n * @returns An array of JSON Schema fragments representing the properties, each including metadata.\n */\nexport function getPropertiesList(obj: Schema | JsonSchemaObject) {\n return Object.values(getProperties(obj));\n}\n\n/**\n * Adds a property to a JSON Schema object form.\n *\n * @remarks\n * This function modifies the provided schema in place by adding a new property with the specified name and schema. It also updates the `required` array based on the `optional` flag of the property. If the property is marked as optional, it will be removed from the `required` array; otherwise, it will be added to it.\n *\n * @param obj - The JSON Schema object form or a Schema wrapper to which the property should be added.\n * @param name - The name of the property to add.\n * @param property - The JSON Schema fragment representing the property's schema, including metadata.\n * @throws Will throw an error if the provided schema is not an object form.\n */\nexport function addProperty(\n obj: Schema | JsonSchemaObject,\n name: string,\n property: JsonSchema\n): void {\n const schema = (isSchema(obj) ? obj.schema : obj) as JsonSchemaObject;\n if (!isJsonSchemaObject(schema)) {\n throw new Error(\"Cannot add property to non-object schema\");\n }\n\n schema.properties ??= {};\n schema.required ??= [];\n\n schema.properties[name] = { ...property, name };\n if (!schema.required.includes(name)) {\n schema.required.push(name);\n }\n\n if (schema.required.length === 0) {\n delete schema.required;\n }\n}\n\n/**\n * Merges multiple JSON Schema object forms into one.\n *\n * @remarks\n * This function takes multiple JSON Schema objects or Schema wrappers and merges them into a single JSON Schema object. The merging process combines properties and metadata from all provided schemas, with later schemas in the arguments list taking precedence over earlier ones in case of conflicts. The resulting schema will include all unique properties and metadata from the input schemas.\n *\n * @param schemas - An array of JSON Schema objects or Schema wrappers to merge.\n * @returns A new JSON Schema object that is the result of merging all input schemas.\n */\nexport function mergeSchemas(...schemas: (JsonSchema | Schema)[]): JsonSchema {\n const result: JsonSchema = {};\n for (const schema of schemas) {\n const jsonSchema: JsonSchema = isSchema(schema) ? schema.schema : schema;\n if (!isJsonSchemaObject(jsonSchema)) {\n continue;\n }\n\n defu(result, jsonSchema);\n }\n\n return result;\n}\n\n/**\n * Returns whether a JSON Schema fragment accepts `null`.\n *\n * @remarks\n * This is true if the schema has `nullable: true` or if its `type` includes `\"null\"`.\n *\n * @param schema - The JSON Schema fragment to check.\n * @returns `true` if the schema accepts `null`, otherwise `false`.\n */\nexport function isSchemaNullable(schema?: JsonSchema): boolean {\n if (!isSetObject(schema)) {\n return false;\n }\n\n if ((schema as { nullable?: true }).nullable === true) {\n return true;\n }\n\n return readSchemaTypes(schema).includes(\"null\");\n}\n\n/**\n * Returns whether an object property is optional (not listed in `required`).\n *\n * @remarks\n * In JSON Schema, object properties are optional by default unless they are listed in the `required` array of the parent schema. This function checks whether a given property name is not included in the `required` array of its parent schema, indicating that it is optional.\n *\n * @param parent - The parent JSON Schema object containing the property.\n * @param propertyName - The name of the property to check for optionality.\n * @returns `true` if the property is optional, otherwise `false`.\n */\nexport function isPropertyOptional(\n parent: JsonSchemaObject,\n propertyName: string\n): boolean {\n if (!parent.properties?.[propertyName]) {\n throw new Error(\n `The property \"${propertyName}\" does not exist in the parent schema.`\n );\n }\n\n return !(parent.required ?? []).includes(propertyName);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAuCA,SAAgB,cACd,KAIA;CACA,MAAM,aAGF,CAAC;CACL,MAAM,SAAqB,SAAS,GAAG,IAAI,IAAI,SAAS;CACxD,IAAI,CAAC,mBAAmB,MAAM,GAC5B,OAAO;CAGT,IAAI,CAAC,YAAY,OAAO,UAAU,GAChC,OAAO;CAGT,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,UAAU,GAAG;EAC5D,MAAM,iBAA0C,CAAC;EAEjD,IAAI,OAAO,UAAU,WACnB,OAAO,OAAO,gBAAgB,KAAK;EAGrC,WAAW,OAAO;GAChB,GAAG;GACH,MAAM;GACN,UAAU,CAAC,mBAAmB,QAAQ,GAAG;GACzC,SAAS,OAAO,UAAU,QAAQ,eAAe;EACnD;CACF;CAEA,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,kBAAkB,KAAgC;CAChE,OAAO,OAAO,OAAO,cAAc,GAAG,CAAC;AACzC;;;;;;;;;;;;AAaA,SAAgB,YACd,KACA,MACA,UACM;CACN,MAAM,SAAU,SAAS,GAAG,IAAI,IAAI,SAAS;CAC7C,IAAI,CAAC,mBAAmB,MAAM,GAC5B,MAAM,IAAI,MAAM,0CAA0C;CAG5D,OAAO,eAAe,CAAC;CACvB,OAAO,aAAa,CAAC;CAErB,OAAO,WAAW,QAAQ;EAAE,GAAG;EAAU;CAAK;CAC9C,IAAI,CAAC,OAAO,SAAS,SAAS,IAAI,GAChC,OAAO,SAAS,KAAK,IAAI;CAG3B,IAAI,OAAO,SAAS,WAAW,GAC7B,OAAO,OAAO;AAElB;;;;;;;;;;AAWA,SAAgB,aAAa,GAAG,SAA8C;CAC5E,MAAM,SAAqB,CAAC;CAC5B,KAAK,MAAM,UAAU,SAAS;EAC5B,MAAM,aAAyB,SAAS,MAAM,IAAI,OAAO,SAAS;EAClE,IAAI,CAAC,mBAAmB,UAAU,GAChC;EAGF,OAAK,QAAQ,UAAU;CACzB;CAEA,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,iBAAiB,QAA8B;CAC7D,IAAI,CAAC,YAAY,MAAM,GACrB,OAAO;CAGT,IAAK,OAA+B,aAAa,MAC/C,OAAO;CAGT,OAAO,gBAAgB,MAAM,EAAE,SAAS,MAAM;AAChD;;;;;;;;;;;AAYA,SAAgB,mBACd,QACA,cACS;CACT,IAAI,CAAC,OAAO,aAAa,eACvB,MAAM,IAAI,MACR,iBAAiB,aAAa,uCAChC;CAGF,OAAO,EAAE,OAAO,YAAY,CAAC,GAAG,SAAS,YAAY;AACvD"}
|
|
1
|
+
{"version":3,"file":"helpers.mjs","names":["defu"],"sources":["../src/helpers.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 { getUnique } from \"@stryke/helpers/get-unique\";\nimport { findFileExtensionSafe } from \"@stryke/path/find\";\nimport { isSetObject } from \"@stryke/type-checks\";\nimport { defu } from \"defu\";\nimport { VALID_SOURCE_FILE_EXTENSIONS } from \"./constants\";\nimport { readSchemaTypes } from \"./metadata\";\nimport { isJsonSchema, isJsonSchemaObject, isSchema } from \"./type-checks\";\nimport { JsonSchema, JsonSchemaLike, JsonSchemaObject, Schema } from \"./types\";\n\nexport type GetPropertiesResult = JsonSchema & {\n name: string;\n required: boolean;\n default?: unknown;\n};\n\n/**\n * Retrieves the JSON Schema from a Schema wrapper or returns the input if it's already a JSON Schema.\n *\n * @remarks\n * This function checks if the input is a Schema wrapper (an object with a `schema` property) and returns the `schema` if it is. If the input is already a JSON Schema, it returns it directly. This allows for flexibility in handling both raw JSON Schema objects and wrapped schemas without needing to check the type at every usage point.\n *\n * @param input - The input which can be either a Schema wrapper or a JSON Schema object.\n * @returns The JSON Schema object.\n * @throws Will throw a TypeError if the input is neither a valid Schema wrapper nor a valid JSON Schema object.\n */\nexport function getJsonSchema(input: Schema | JsonSchema): JsonSchema {\n const schema = isSchema(input) ? input.schema : input;\n if (!isJsonSchema(schema)) {\n throw new TypeError(\"The provided input is not a valid JSON Schema\");\n }\n\n return schema;\n}\n\n/**\n * Retrieves the JSON Schema in Object form from a Schema wrapper or returns the input if it's already a JSON Schema.\n *\n * @remarks\n * This function checks if the input is a Schema wrapper (an object with a `schema` property) and returns the `schema` if it is. If the input is already a JSON Schema object, it returns it directly. This allows for flexibility in handling both raw JSON Schema objects and wrapped schemas without needing to check the type at every usage point.\n *\n * @param input - The input which can be either a Schema wrapper or a JSON Schema object.\n * @returns The JSON Schema object.\n * @throws Will throw a TypeError if the input is neither a valid Schema wrapper nor a valid JSON Schema object.\n */\nexport function getJsonSchemaObject(\n input: Schema | JsonSchema\n): JsonSchemaObject {\n const schema = getJsonSchema(input);\n if (!isJsonSchemaObject(schema)) {\n throw new TypeError(\"The provided input is not a valid JSON Schema object\");\n }\n\n return schema;\n}\n\n/**\n * Extracts object properties from a JSON Schema object form.\n *\n * @remarks\n * This function returns an empty object if the schema is not an object form or if it has no properties.\n *\n * @param obj - The JSON Schema object form or a Schema wrapper to extract properties from.\n * @returns An object mapping property names to their corresponding JSON Schema fragments, including metadata.\n */\nexport function getProperties(\n obj: Schema | JsonSchemaObject\n): Record<\n string,\n JsonSchema & { name: string; required: boolean; default?: unknown }\n> {\n const properties: Record<\n string,\n JsonSchema & { name: string; required: boolean; default?: unknown }\n > = {};\n\n const schema = getJsonSchemaObject(obj);\n if (!isSetObject(schema.properties)) {\n return properties;\n }\n\n for (const [key, value] of Object.entries(schema.properties)) {\n const propertySchema: Record<string, unknown> = {};\n\n if (typeof value !== \"boolean\") {\n Object.assign(propertySchema, value);\n }\n\n properties[key] = {\n ...propertySchema,\n name: key,\n required: !isPropertyOptional(schema, key),\n default: schema.default?.[key] ?? propertySchema.default\n };\n }\n\n return properties;\n}\n\n/**\n * Returns object properties as an array.\n *\n * @remarks\n * This is a convenience function that extracts properties using `getProperties` and returns them as an array.\n *\n * @param obj - The JSON Schema object form or a Schema wrapper to extract properties from.\n * @returns An array of JSON Schema fragments representing the properties, each including metadata.\n */\nexport function getPropertiesList(obj: Schema | JsonSchemaObject) {\n return Object.values(getProperties(obj));\n}\n\n/**\n * Adds a property to a JSON Schema object form.\n *\n * @remarks\n * This function modifies the provided schema in place by adding a new property with the specified name and schema. It also updates the `required` array based on the `optional` flag of the property. If the property is marked as optional, it will be removed from the `required` array; otherwise, it will be added to it.\n *\n * @param obj - The JSON Schema object form or a Schema wrapper to which the property should be added.\n * @param name - The name of the property to add.\n * @param property - The JSON Schema fragment representing the property's schema, including metadata.\n * @throws Will throw an error if the provided schema is not an object form.\n */\nexport function addProperty(\n obj: Schema | JsonSchemaObject,\n name: string,\n property: JsonSchema\n): void {\n const schema = getJsonSchemaObject(obj);\n\n schema.properties ??= {};\n schema.required ??= [];\n\n schema.properties[name] = { ...property, name };\n if (!schema.required.includes(name)) {\n schema.required.push(name);\n }\n\n if (schema.required.length === 0) {\n delete schema.required;\n }\n}\n\n/**\n * Merges multiple JSON Schemas into one.\n *\n * @remarks\n * This function takes multiple JSON Schemas or Schema wrappers and merges them into a single JSON Schema object. The merging process combines properties and metadata from all provided schemas, with later schemas in the arguments list taking precedence over earlier ones in case of conflicts. The resulting schema will include all unique properties and metadata from the input schemas.\n *\n * @param schemas - An array of JSON Schemas or Schema wrappers to merge.\n * @returns A new JSON Schema that is the result of merging all input schemas.\n */\nexport function merge(...schemas: (JsonSchema | Schema)[]): JsonSchema {\n let result: JsonSchema = {};\n for (const schema of schemas.reverse()) {\n if (\n !(result as JsonSchemaLike).type ||\n (result as JsonSchemaLike).type === (schema as JsonSchemaLike).type\n ) {\n result = defu(result, getJsonSchema(schema)) as JsonSchema;\n if (isJsonSchemaObject(result)) {\n result.required = getUnique(result.required ?? []);\n }\n }\n }\n\n return result;\n}\n\n/**\n * Returns whether a JSON Schema fragment accepts `null`.\n *\n * @remarks\n * This is true if the schema has `nullable: true` or if its `type` includes `\"null\"`.\n *\n * @param schema - The JSON Schema fragment to check.\n * @returns `true` if the schema accepts `null`, otherwise `false`.\n */\nexport function isSchemaNullable(schema?: JsonSchema): boolean {\n if (!isSetObject(schema)) {\n return false;\n }\n\n if ((schema as { nullable?: true }).nullable === true) {\n return true;\n }\n\n return readSchemaTypes(schema).includes(\"null\");\n}\n\n/**\n * Returns whether an object property is optional (not listed in `required`).\n *\n * @remarks\n * In JSON Schema, object properties are optional by default unless they are listed in the `required` array of the parent schema. This function checks whether a given property name is not included in the `required` array of its parent schema, indicating that it is optional.\n *\n * @param parent - The parent JSON Schema object containing the property.\n * @param propertyName - The name of the property to check for optionality.\n * @returns `true` if the property is optional, otherwise `false`.\n */\nexport function isPropertyOptional(\n parent: JsonSchemaObject,\n propertyName: string\n): boolean {\n if (!parent.properties?.[propertyName]) {\n throw new Error(\n `The property \"${propertyName}\" does not exist in the parent schema.`\n );\n }\n\n return !(parent.required ?? []).includes(propertyName);\n}\n\n/**\n * Checks if a given file name has a valid schema input file extension.\n *\n * @param fileName - The file name to check for a valid schema input extension.\n * @returns `true` if the file name has a valid schema input extension, otherwise `false`.\n */\nexport function isValidSchemaInputFile(fileName: string): boolean {\n return VALID_SOURCE_FILE_EXTENSIONS.includes(findFileExtensionSafe(fileName));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2CA,SAAgB,cAAc,OAAwC;CACpE,MAAM,SAAS,SAAS,KAAK,IAAI,MAAM,SAAS;CAChD,IAAI,CAAC,aAAa,MAAM,GACtB,MAAM,IAAI,UAAU,+CAA+C;CAGrE,OAAO;AACT;;;;;;;;;;;AAYA,SAAgB,oBACd,OACkB;CAClB,MAAM,SAAS,cAAc,KAAK;CAClC,IAAI,CAAC,mBAAmB,MAAM,GAC5B,MAAM,IAAI,UAAU,sDAAsD;CAG5E,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,cACd,KAIA;CACA,MAAM,aAGF,CAAC;CAEL,MAAM,SAAS,oBAAoB,GAAG;CACtC,IAAI,CAAC,YAAY,OAAO,UAAU,GAChC,OAAO;CAGT,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,UAAU,GAAG;EAC5D,MAAM,iBAA0C,CAAC;EAEjD,IAAI,OAAO,UAAU,WACnB,OAAO,OAAO,gBAAgB,KAAK;EAGrC,WAAW,OAAO;GAChB,GAAG;GACH,MAAM;GACN,UAAU,CAAC,mBAAmB,QAAQ,GAAG;GACzC,SAAS,OAAO,UAAU,QAAQ,eAAe;EACnD;CACF;CAEA,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,kBAAkB,KAAgC;CAChE,OAAO,OAAO,OAAO,cAAc,GAAG,CAAC;AACzC;;;;;;;;;;;;AAaA,SAAgB,YACd,KACA,MACA,UACM;CACN,MAAM,SAAS,oBAAoB,GAAG;CAEtC,OAAO,eAAe,CAAC;CACvB,OAAO,aAAa,CAAC;CAErB,OAAO,WAAW,QAAQ;EAAE,GAAG;EAAU;CAAK;CAC9C,IAAI,CAAC,OAAO,SAAS,SAAS,IAAI,GAChC,OAAO,SAAS,KAAK,IAAI;CAG3B,IAAI,OAAO,SAAS,WAAW,GAC7B,OAAO,OAAO;AAElB;;;;;;;;;;AAWA,SAAgB,MAAM,GAAG,SAA8C;CACrE,IAAI,SAAqB,CAAC;CAC1B,KAAK,MAAM,UAAU,QAAQ,QAAQ,GACnC,IACE,CAAE,OAA0B,QAC3B,OAA0B,SAAU,OAA0B,MAC/D;EACA,SAASA,OAAK,QAAQ,cAAc,MAAM,CAAC;EAC3C,IAAI,mBAAmB,MAAM,GAC3B,OAAO,WAAW,UAAU,OAAO,YAAY,CAAC,CAAC;CAErD;CAGF,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,iBAAiB,QAA8B;CAC7D,IAAI,CAAC,YAAY,MAAM,GACrB,OAAO;CAGT,IAAK,OAA+B,aAAa,MAC/C,OAAO;CAGT,OAAO,gBAAgB,MAAM,EAAE,SAAS,MAAM;AAChD;;;;;;;;;;;AAYA,SAAgB,mBACd,QACA,cACS;CACT,IAAI,CAAC,OAAO,aAAa,eACvB,MAAM,IAAI,MACR,iBAAiB,aAAa,uCAChC;CAGF,OAAO,EAAE,OAAO,YAAY,CAAC,GAAG,SAAS,YAAY;AACvD;;;;;;;AAQA,SAAgB,uBAAuB,UAA2B;CAChE,OAAO,6BAA6B,SAAS,sBAAsB,QAAQ,CAAC;AAC9E"}
|
package/dist/index.cjs
CHANGED
|
@@ -14,6 +14,7 @@ exports.JSON_SCHEMA_METADATA_KEYS = require_constants.JSON_SCHEMA_METADATA_KEYS;
|
|
|
14
14
|
exports.JSON_SCHEMA_PRIMITIVE_TYPES = require_constants.JSON_SCHEMA_PRIMITIVE_TYPES;
|
|
15
15
|
exports.JSON_SCHEMA_TYPES = require_constants.JSON_SCHEMA_TYPES;
|
|
16
16
|
exports.JsonSchemaTypeNames = require_constants.JsonSchemaTypeNames;
|
|
17
|
+
exports.VALID_SOURCE_FILE_EXTENSIONS = require_constants.VALID_SOURCE_FILE_EXTENSIONS;
|
|
17
18
|
exports.addProperty = require_helpers.addProperty;
|
|
18
19
|
exports.applyJsonSchemaMetadata = require_metadata.applyJsonSchemaMetadata;
|
|
19
20
|
exports.bundle = require_bundle.bundle;
|
|
@@ -30,6 +31,8 @@ exports.extractVariant = require_extract.extractVariant;
|
|
|
30
31
|
exports.generateCode = require_codegen.generateCode;
|
|
31
32
|
exports.getCacheDirectory = require_persistence.getCacheDirectory;
|
|
32
33
|
exports.getCacheFilePath = require_persistence.getCacheFilePath;
|
|
34
|
+
exports.getJsonSchema = require_helpers.getJsonSchema;
|
|
35
|
+
exports.getJsonSchemaObject = require_helpers.getJsonSchemaObject;
|
|
33
36
|
exports.getJsonSchemaType = require_codegen.getJsonSchemaType;
|
|
34
37
|
exports.getPrimarySchemaType = require_metadata.getPrimarySchemaType;
|
|
35
38
|
exports.getProperties = require_helpers.getProperties;
|
|
@@ -69,6 +72,7 @@ exports.isNullOnlyJsonSchema = require_type_checks.isNullOnlyJsonSchema;
|
|
|
69
72
|
exports.isPropertyOptional = require_helpers.isPropertyOptional;
|
|
70
73
|
exports.isSchema = require_type_checks.isSchema;
|
|
71
74
|
exports.isSchemaNullable = require_helpers.isSchemaNullable;
|
|
75
|
+
exports.isSchemaObject = require_type_checks.isSchemaObject;
|
|
72
76
|
exports.isSchemaWithSource = require_type_checks.isSchemaWithSource;
|
|
73
77
|
exports.isStandardSchema = require_type_checks.isStandardSchema;
|
|
74
78
|
exports.isUntypedInput = require_type_checks.isUntypedInput;
|
|
@@ -76,7 +80,8 @@ exports.isUntypedInputStrict = require_type_checks.isUntypedInputStrict;
|
|
|
76
80
|
exports.isUntypedSchema = require_type_checks.isUntypedSchema;
|
|
77
81
|
exports.isUntypedSchemaStrict = require_type_checks.isUntypedSchemaStrict;
|
|
78
82
|
exports.isValibotSchema = require_type_checks.isValibotSchema;
|
|
79
|
-
exports.
|
|
83
|
+
exports.isValidSchemaInputFile = require_helpers.isValidSchemaInputFile;
|
|
84
|
+
exports.merge = require_helpers.merge;
|
|
80
85
|
exports.readSchema = require_persistence.readSchema;
|
|
81
86
|
exports.readSchemaSafe = require_persistence.readSchemaSafe;
|
|
82
87
|
exports.readSchemaTypes = require_metadata.readSchemaTypes;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { BundleOptions, bundle } from "./bundle.cjs";
|
|
2
|
-
import { JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchemaTypeNames } from "./constants.cjs";
|
|
3
|
-
import { BaseSchemaSource, ExtractedSchema, JsonSchema, JsonSchemaAllOf, JsonSchemaAny, JsonSchemaAnyOf, JsonSchemaArray, JsonSchemaBigint, JsonSchemaBoolean, JsonSchemaConditionalKeywords, JsonSchemaDate, JsonSchemaDecimal, JsonSchemaDecimalFormat, JsonSchemaEnum, JsonSchemaInteger, JsonSchemaIntegerFormat, JsonSchemaKeywords, JsonSchemaLike, JsonSchemaLiteral, JsonSchemaLogicKeywords, JsonSchemaMap, JsonSchemaMetadataKeywords, JsonSchemaNativeEnum, JsonSchemaNever, JsonSchemaNull, JsonSchemaNullable, JsonSchemaNumber, JsonSchemaNumberFormat, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaPrimitiveUnion, JsonSchemaRecord, JsonSchemaRecordPropertyNames, JsonSchemaRef, JsonSchemaSchemaSource, JsonSchemaSet, JsonSchemaString, JsonSchemaStringFormat, JsonSchemaTuple, JsonSchemaType, JsonSchemaUndefined, JsonSchemaUnion, JsonSchemaUnknown, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource,
|
|
2
|
+
import { JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchemaTypeNames, VALID_SOURCE_FILE_EXTENSIONS } from "./constants.cjs";
|
|
3
|
+
import { BaseSchemaSource, ExtractedSchema, JsonSchema, JsonSchemaAllOf, JsonSchemaAny, JsonSchemaAnyOf, JsonSchemaArray, JsonSchemaBigint, JsonSchemaBoolean, JsonSchemaConditionalKeywords, JsonSchemaDate, JsonSchemaDecimal, JsonSchemaDecimalFormat, JsonSchemaEnum, JsonSchemaInteger, JsonSchemaIntegerFormat, JsonSchemaKeywords, JsonSchemaLike, JsonSchemaLiteral, JsonSchemaLogicKeywords, JsonSchemaMap, JsonSchemaMetadataKeywords, JsonSchemaNativeEnum, JsonSchemaNever, JsonSchemaNull, JsonSchemaNullable, JsonSchemaNumber, JsonSchemaNumberFormat, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaPrimitiveUnion, JsonSchemaRecord, JsonSchemaRecordPropertyNames, JsonSchemaRef, JsonSchemaSchemaSource, JsonSchemaSet, JsonSchemaString, JsonSchemaStringFormat, JsonSchemaTuple, JsonSchemaType, JsonSchemaUndefined, JsonSchemaUnion, JsonSchemaUnknown, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, UntypedInputObject, UntypedSchema, UntypedSchemaSource, ValibotSchema, ValibotSchemaSource, Zod3SchemaSource } from "./types.cjs";
|
|
4
4
|
import { generateCode, getJsonSchemaType, stringifyType, stringifyValue } from "./codegen.cjs";
|
|
5
5
|
import { bundleReferences, extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaWithSource, extractSource, extractVariant } from "./extract.cjs";
|
|
6
|
-
import { GetPropertiesResult, addProperty, getProperties, getPropertiesList, isPropertyOptional, isSchemaNullable,
|
|
6
|
+
import { GetPropertiesResult, addProperty, getJsonSchema, getJsonSchemaObject, getProperties, getPropertiesList, isPropertyOptional, isSchemaNullable, isValidSchemaInputFile, merge } from "./helpers.cjs";
|
|
7
7
|
import { applyJsonSchemaMetadata, getPrimarySchemaType, readSchemaTypes } from "./metadata.cjs";
|
|
8
8
|
import { getCacheDirectory, getCacheFilePath, readSchema, readSchemaSafe, writeSchema } from "./persistence.cjs";
|
|
9
9
|
import { reflectionToJsonSchema } from "./reflection.cjs";
|
|
10
10
|
import { resolve, resolveModule, resolveReflection } from "./resolve.cjs";
|
|
11
|
-
import { isJsonSchema, isJsonSchemaAllOf, isJsonSchemaAny, isJsonSchemaAnyOf, isJsonSchemaArray, isJsonSchemaBigint, isJsonSchemaBoolean, isJsonSchemaDate, isJsonSchemaDecimal, isJsonSchemaEnum, isJsonSchemaInteger, isJsonSchemaKeywords, isJsonSchemaLiteral, isJsonSchemaMap, isJsonSchemaNativeEnum, isJsonSchemaNever, isJsonSchemaNull, isJsonSchemaNullable, isJsonSchemaNumber, isJsonSchemaObject, isJsonSchemaPrimitiveType, isJsonSchemaPrimitiveUnion, isJsonSchemaRecord, isJsonSchemaRef, isJsonSchemaSet, isJsonSchemaString, isJsonSchemaTuple, isJsonSchemaType, isJsonSchemaUndefined, isJsonSchemaUnion, isJsonSchemaUnknown, isNullOnlyJsonSchema, isSchema, isSchemaWithSource, isStandardSchema, isUntypedInput, isUntypedInputStrict, isUntypedSchema, isUntypedSchemaStrict, isValibotSchema } from "./type-checks.cjs";
|
|
11
|
+
import { isJsonSchema, isJsonSchemaAllOf, isJsonSchemaAny, isJsonSchemaAnyOf, isJsonSchemaArray, isJsonSchemaBigint, isJsonSchemaBoolean, isJsonSchemaDate, isJsonSchemaDecimal, isJsonSchemaEnum, isJsonSchemaInteger, isJsonSchemaKeywords, isJsonSchemaLiteral, isJsonSchemaMap, isJsonSchemaNativeEnum, isJsonSchemaNever, isJsonSchemaNull, isJsonSchemaNullable, isJsonSchemaNumber, isJsonSchemaObject, isJsonSchemaPrimitiveType, isJsonSchemaPrimitiveUnion, isJsonSchemaRecord, isJsonSchemaRef, isJsonSchemaSet, isJsonSchemaString, isJsonSchemaTuple, isJsonSchemaType, isJsonSchemaUndefined, isJsonSchemaUnion, isJsonSchemaUnknown, isNullOnlyJsonSchema, isSchema, isSchemaObject, isSchemaWithSource, isStandardSchema, isUntypedInput, isUntypedInputStrict, isUntypedSchema, isUntypedSchemaStrict, isValibotSchema } from "./type-checks.cjs";
|
|
12
12
|
|
|
13
13
|
//#region src/index.d.ts
|
|
14
14
|
declare module "zod" {
|
|
@@ -34,5 +34,5 @@ declare module "zod" {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
//#endregion
|
|
37
|
-
export { BaseSchemaSource, BundleOptions, ExtractedSchema, GetPropertiesResult, JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchema, JsonSchemaAllOf, JsonSchemaAny, JsonSchemaAnyOf, JsonSchemaArray, JsonSchemaBigint, JsonSchemaBoolean, JsonSchemaConditionalKeywords, JsonSchemaDate, JsonSchemaDecimal, JsonSchemaDecimalFormat, JsonSchemaEnum, JsonSchemaInteger, JsonSchemaIntegerFormat, JsonSchemaKeywords, JsonSchemaLike, JsonSchemaLiteral, JsonSchemaLogicKeywords, JsonSchemaMap, JsonSchemaMetadataKeywords, JsonSchemaNativeEnum, JsonSchemaNever, JsonSchemaNull, JsonSchemaNullable, JsonSchemaNumber, JsonSchemaNumberFormat, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaPrimitiveUnion, JsonSchemaRecord, JsonSchemaRecordPropertyNames, JsonSchemaRef, JsonSchemaSchemaSource, JsonSchemaSet, JsonSchemaString, JsonSchemaStringFormat, JsonSchemaTuple, JsonSchemaType, JsonSchemaTypeNames, JsonSchemaUndefined, JsonSchemaUnion, JsonSchemaUnknown, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource,
|
|
37
|
+
export { BaseSchemaSource, BundleOptions, ExtractedSchema, GetPropertiesResult, JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchema, JsonSchemaAllOf, JsonSchemaAny, JsonSchemaAnyOf, JsonSchemaArray, JsonSchemaBigint, JsonSchemaBoolean, JsonSchemaConditionalKeywords, JsonSchemaDate, JsonSchemaDecimal, JsonSchemaDecimalFormat, JsonSchemaEnum, JsonSchemaInteger, JsonSchemaIntegerFormat, JsonSchemaKeywords, JsonSchemaLike, JsonSchemaLiteral, JsonSchemaLogicKeywords, JsonSchemaMap, JsonSchemaMetadataKeywords, JsonSchemaNativeEnum, JsonSchemaNever, JsonSchemaNull, JsonSchemaNullable, JsonSchemaNumber, JsonSchemaNumberFormat, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaPrimitiveUnion, JsonSchemaRecord, JsonSchemaRecordPropertyNames, JsonSchemaRef, JsonSchemaSchemaSource, JsonSchemaSet, JsonSchemaString, JsonSchemaStringFormat, JsonSchemaTuple, JsonSchemaType, JsonSchemaTypeNames, JsonSchemaUndefined, JsonSchemaUnion, JsonSchemaUnknown, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, UntypedInputObject, UntypedSchema, UntypedSchemaSource, VALID_SOURCE_FILE_EXTENSIONS, ValibotSchema, ValibotSchemaSource, Zod3SchemaSource, addProperty, applyJsonSchemaMetadata, bundle, bundleReferences, extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaWithSource, extractSource, extractVariant, generateCode, getCacheDirectory, getCacheFilePath, getJsonSchema, getJsonSchemaObject, getJsonSchemaType, getPrimarySchemaType, getProperties, getPropertiesList, isJsonSchema, isJsonSchemaAllOf, isJsonSchemaAny, isJsonSchemaAnyOf, isJsonSchemaArray, isJsonSchemaBigint, isJsonSchemaBoolean, isJsonSchemaDate, isJsonSchemaDecimal, isJsonSchemaEnum, isJsonSchemaInteger, isJsonSchemaKeywords, isJsonSchemaLiteral, isJsonSchemaMap, isJsonSchemaNativeEnum, isJsonSchemaNever, isJsonSchemaNull, isJsonSchemaNullable, isJsonSchemaNumber, isJsonSchemaObject, isJsonSchemaPrimitiveType, isJsonSchemaPrimitiveUnion, isJsonSchemaRecord, isJsonSchemaRef, isJsonSchemaSet, isJsonSchemaString, isJsonSchemaTuple, isJsonSchemaType, isJsonSchemaUndefined, isJsonSchemaUnion, isJsonSchemaUnknown, isNullOnlyJsonSchema, isPropertyOptional, isSchema, isSchemaNullable, isSchemaObject, isSchemaWithSource, isStandardSchema, isUntypedInput, isUntypedInputStrict, isUntypedSchema, isUntypedSchemaStrict, isValibotSchema, isValidSchemaInputFile, merge, readSchema, readSchemaSafe, readSchemaTypes, reflectionToJsonSchema, resolve, resolveModule, resolveReflection, stringifyType, stringifyValue, writeSchema };
|
|
38
38
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { BundleOptions, bundle } from "./bundle.mjs";
|
|
2
|
-
import { JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchemaTypeNames } from "./constants.mjs";
|
|
3
|
-
import { BaseSchemaSource, ExtractedSchema, JsonSchema, JsonSchemaAllOf, JsonSchemaAny, JsonSchemaAnyOf, JsonSchemaArray, JsonSchemaBigint, JsonSchemaBoolean, JsonSchemaConditionalKeywords, JsonSchemaDate, JsonSchemaDecimal, JsonSchemaDecimalFormat, JsonSchemaEnum, JsonSchemaInteger, JsonSchemaIntegerFormat, JsonSchemaKeywords, JsonSchemaLike, JsonSchemaLiteral, JsonSchemaLogicKeywords, JsonSchemaMap, JsonSchemaMetadataKeywords, JsonSchemaNativeEnum, JsonSchemaNever, JsonSchemaNull, JsonSchemaNullable, JsonSchemaNumber, JsonSchemaNumberFormat, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaPrimitiveUnion, JsonSchemaRecord, JsonSchemaRecordPropertyNames, JsonSchemaRef, JsonSchemaSchemaSource, JsonSchemaSet, JsonSchemaString, JsonSchemaStringFormat, JsonSchemaTuple, JsonSchemaType, JsonSchemaUndefined, JsonSchemaUnion, JsonSchemaUnknown, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource,
|
|
2
|
+
import { JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchemaTypeNames, VALID_SOURCE_FILE_EXTENSIONS } from "./constants.mjs";
|
|
3
|
+
import { BaseSchemaSource, ExtractedSchema, JsonSchema, JsonSchemaAllOf, JsonSchemaAny, JsonSchemaAnyOf, JsonSchemaArray, JsonSchemaBigint, JsonSchemaBoolean, JsonSchemaConditionalKeywords, JsonSchemaDate, JsonSchemaDecimal, JsonSchemaDecimalFormat, JsonSchemaEnum, JsonSchemaInteger, JsonSchemaIntegerFormat, JsonSchemaKeywords, JsonSchemaLike, JsonSchemaLiteral, JsonSchemaLogicKeywords, JsonSchemaMap, JsonSchemaMetadataKeywords, JsonSchemaNativeEnum, JsonSchemaNever, JsonSchemaNull, JsonSchemaNullable, JsonSchemaNumber, JsonSchemaNumberFormat, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaPrimitiveUnion, JsonSchemaRecord, JsonSchemaRecordPropertyNames, JsonSchemaRef, JsonSchemaSchemaSource, JsonSchemaSet, JsonSchemaString, JsonSchemaStringFormat, JsonSchemaTuple, JsonSchemaType, JsonSchemaUndefined, JsonSchemaUnion, JsonSchemaUnknown, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, UntypedInputObject, UntypedSchema, UntypedSchemaSource, ValibotSchema, ValibotSchemaSource, Zod3SchemaSource } from "./types.mjs";
|
|
4
4
|
import { generateCode, getJsonSchemaType, stringifyType, stringifyValue } from "./codegen.mjs";
|
|
5
5
|
import { bundleReferences, extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaWithSource, extractSource, extractVariant } from "./extract.mjs";
|
|
6
|
-
import { GetPropertiesResult, addProperty, getProperties, getPropertiesList, isPropertyOptional, isSchemaNullable,
|
|
6
|
+
import { GetPropertiesResult, addProperty, getJsonSchema, getJsonSchemaObject, getProperties, getPropertiesList, isPropertyOptional, isSchemaNullable, isValidSchemaInputFile, merge } from "./helpers.mjs";
|
|
7
7
|
import { applyJsonSchemaMetadata, getPrimarySchemaType, readSchemaTypes } from "./metadata.mjs";
|
|
8
8
|
import { getCacheDirectory, getCacheFilePath, readSchema, readSchemaSafe, writeSchema } from "./persistence.mjs";
|
|
9
9
|
import { reflectionToJsonSchema } from "./reflection.mjs";
|
|
10
10
|
import { resolve, resolveModule, resolveReflection } from "./resolve.mjs";
|
|
11
|
-
import { isJsonSchema, isJsonSchemaAllOf, isJsonSchemaAny, isJsonSchemaAnyOf, isJsonSchemaArray, isJsonSchemaBigint, isJsonSchemaBoolean, isJsonSchemaDate, isJsonSchemaDecimal, isJsonSchemaEnum, isJsonSchemaInteger, isJsonSchemaKeywords, isJsonSchemaLiteral, isJsonSchemaMap, isJsonSchemaNativeEnum, isJsonSchemaNever, isJsonSchemaNull, isJsonSchemaNullable, isJsonSchemaNumber, isJsonSchemaObject, isJsonSchemaPrimitiveType, isJsonSchemaPrimitiveUnion, isJsonSchemaRecord, isJsonSchemaRef, isJsonSchemaSet, isJsonSchemaString, isJsonSchemaTuple, isJsonSchemaType, isJsonSchemaUndefined, isJsonSchemaUnion, isJsonSchemaUnknown, isNullOnlyJsonSchema, isSchema, isSchemaWithSource, isStandardSchema, isUntypedInput, isUntypedInputStrict, isUntypedSchema, isUntypedSchemaStrict, isValibotSchema } from "./type-checks.mjs";
|
|
11
|
+
import { isJsonSchema, isJsonSchemaAllOf, isJsonSchemaAny, isJsonSchemaAnyOf, isJsonSchemaArray, isJsonSchemaBigint, isJsonSchemaBoolean, isJsonSchemaDate, isJsonSchemaDecimal, isJsonSchemaEnum, isJsonSchemaInteger, isJsonSchemaKeywords, isJsonSchemaLiteral, isJsonSchemaMap, isJsonSchemaNativeEnum, isJsonSchemaNever, isJsonSchemaNull, isJsonSchemaNullable, isJsonSchemaNumber, isJsonSchemaObject, isJsonSchemaPrimitiveType, isJsonSchemaPrimitiveUnion, isJsonSchemaRecord, isJsonSchemaRef, isJsonSchemaSet, isJsonSchemaString, isJsonSchemaTuple, isJsonSchemaType, isJsonSchemaUndefined, isJsonSchemaUnion, isJsonSchemaUnknown, isNullOnlyJsonSchema, isSchema, isSchemaObject, isSchemaWithSource, isStandardSchema, isUntypedInput, isUntypedInputStrict, isUntypedSchema, isUntypedSchemaStrict, isValibotSchema } from "./type-checks.mjs";
|
|
12
12
|
|
|
13
13
|
//#region src/index.d.ts
|
|
14
14
|
declare module "zod" {
|
|
@@ -34,5 +34,5 @@ declare module "zod" {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
//#endregion
|
|
37
|
-
export { BaseSchemaSource, BundleOptions, ExtractedSchema, GetPropertiesResult, JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchema, JsonSchemaAllOf, JsonSchemaAny, JsonSchemaAnyOf, JsonSchemaArray, JsonSchemaBigint, JsonSchemaBoolean, JsonSchemaConditionalKeywords, JsonSchemaDate, JsonSchemaDecimal, JsonSchemaDecimalFormat, JsonSchemaEnum, JsonSchemaInteger, JsonSchemaIntegerFormat, JsonSchemaKeywords, JsonSchemaLike, JsonSchemaLiteral, JsonSchemaLogicKeywords, JsonSchemaMap, JsonSchemaMetadataKeywords, JsonSchemaNativeEnum, JsonSchemaNever, JsonSchemaNull, JsonSchemaNullable, JsonSchemaNumber, JsonSchemaNumberFormat, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaPrimitiveUnion, JsonSchemaRecord, JsonSchemaRecordPropertyNames, JsonSchemaRef, JsonSchemaSchemaSource, JsonSchemaSet, JsonSchemaString, JsonSchemaStringFormat, JsonSchemaTuple, JsonSchemaType, JsonSchemaTypeNames, JsonSchemaUndefined, JsonSchemaUnion, JsonSchemaUnknown, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource,
|
|
37
|
+
export { BaseSchemaSource, BundleOptions, ExtractedSchema, GetPropertiesResult, JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchema, JsonSchemaAllOf, JsonSchemaAny, JsonSchemaAnyOf, JsonSchemaArray, JsonSchemaBigint, JsonSchemaBoolean, JsonSchemaConditionalKeywords, JsonSchemaDate, JsonSchemaDecimal, JsonSchemaDecimalFormat, JsonSchemaEnum, JsonSchemaInteger, JsonSchemaIntegerFormat, JsonSchemaKeywords, JsonSchemaLike, JsonSchemaLiteral, JsonSchemaLogicKeywords, JsonSchemaMap, JsonSchemaMetadataKeywords, JsonSchemaNativeEnum, JsonSchemaNever, JsonSchemaNull, JsonSchemaNullable, JsonSchemaNumber, JsonSchemaNumberFormat, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaPrimitiveUnion, JsonSchemaRecord, JsonSchemaRecordPropertyNames, JsonSchemaRef, JsonSchemaSchemaSource, JsonSchemaSet, JsonSchemaString, JsonSchemaStringFormat, JsonSchemaTuple, JsonSchemaType, JsonSchemaTypeNames, JsonSchemaUndefined, JsonSchemaUnion, JsonSchemaUnknown, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, UntypedInputObject, UntypedSchema, UntypedSchemaSource, VALID_SOURCE_FILE_EXTENSIONS, ValibotSchema, ValibotSchemaSource, Zod3SchemaSource, addProperty, applyJsonSchemaMetadata, bundle, bundleReferences, extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaWithSource, extractSource, extractVariant, generateCode, getCacheDirectory, getCacheFilePath, getJsonSchema, getJsonSchemaObject, getJsonSchemaType, getPrimarySchemaType, getProperties, getPropertiesList, isJsonSchema, isJsonSchemaAllOf, isJsonSchemaAny, isJsonSchemaAnyOf, isJsonSchemaArray, isJsonSchemaBigint, isJsonSchemaBoolean, isJsonSchemaDate, isJsonSchemaDecimal, isJsonSchemaEnum, isJsonSchemaInteger, isJsonSchemaKeywords, isJsonSchemaLiteral, isJsonSchemaMap, isJsonSchemaNativeEnum, isJsonSchemaNever, isJsonSchemaNull, isJsonSchemaNullable, isJsonSchemaNumber, isJsonSchemaObject, isJsonSchemaPrimitiveType, isJsonSchemaPrimitiveUnion, isJsonSchemaRecord, isJsonSchemaRef, isJsonSchemaSet, isJsonSchemaString, isJsonSchemaTuple, isJsonSchemaType, isJsonSchemaUndefined, isJsonSchemaUnion, isJsonSchemaUnknown, isNullOnlyJsonSchema, isPropertyOptional, isSchema, isSchemaNullable, isSchemaObject, isSchemaWithSource, isStandardSchema, isUntypedInput, isUntypedInputStrict, isUntypedSchema, isUntypedSchemaStrict, isValibotSchema, isValidSchemaInputFile, merge, readSchema, readSchemaSafe, readSchemaTypes, reflectionToJsonSchema, resolve, resolveModule, resolveReflection, stringifyType, stringifyValue, writeSchema };
|
|
38
38
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { bundle } from "./bundle.mjs";
|
|
2
|
-
import { JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchemaTypeNames } from "./constants.mjs";
|
|
2
|
+
import { JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchemaTypeNames, VALID_SOURCE_FILE_EXTENSIONS } from "./constants.mjs";
|
|
3
3
|
import { applyJsonSchemaMetadata, getPrimarySchemaType, readSchemaTypes } from "./metadata.mjs";
|
|
4
|
-
import { isJsonSchema, isJsonSchemaAllOf, isJsonSchemaAny, isJsonSchemaAnyOf, isJsonSchemaArray, isJsonSchemaBigint, isJsonSchemaBoolean, isJsonSchemaDate, isJsonSchemaDecimal, isJsonSchemaEnum, isJsonSchemaInteger, isJsonSchemaKeywords, isJsonSchemaLiteral, isJsonSchemaMap, isJsonSchemaNativeEnum, isJsonSchemaNever, isJsonSchemaNull, isJsonSchemaNullable, isJsonSchemaNumber, isJsonSchemaObject, isJsonSchemaPrimitiveType, isJsonSchemaPrimitiveUnion, isJsonSchemaRecord, isJsonSchemaRef, isJsonSchemaSet, isJsonSchemaString, isJsonSchemaTuple, isJsonSchemaType, isJsonSchemaUndefined, isJsonSchemaUnion, isJsonSchemaUnknown, isNullOnlyJsonSchema, isSchema, isSchemaWithSource, isStandardSchema, isUntypedInput, isUntypedInputStrict, isUntypedSchema, isUntypedSchemaStrict, isValibotSchema } from "./type-checks.mjs";
|
|
5
|
-
import { addProperty, getProperties, getPropertiesList, isPropertyOptional, isSchemaNullable,
|
|
4
|
+
import { isJsonSchema, isJsonSchemaAllOf, isJsonSchemaAny, isJsonSchemaAnyOf, isJsonSchemaArray, isJsonSchemaBigint, isJsonSchemaBoolean, isJsonSchemaDate, isJsonSchemaDecimal, isJsonSchemaEnum, isJsonSchemaInteger, isJsonSchemaKeywords, isJsonSchemaLiteral, isJsonSchemaMap, isJsonSchemaNativeEnum, isJsonSchemaNever, isJsonSchemaNull, isJsonSchemaNullable, isJsonSchemaNumber, isJsonSchemaObject, isJsonSchemaPrimitiveType, isJsonSchemaPrimitiveUnion, isJsonSchemaRecord, isJsonSchemaRef, isJsonSchemaSet, isJsonSchemaString, isJsonSchemaTuple, isJsonSchemaType, isJsonSchemaUndefined, isJsonSchemaUnion, isJsonSchemaUnknown, isNullOnlyJsonSchema, isSchema, isSchemaObject, isSchemaWithSource, isStandardSchema, isUntypedInput, isUntypedInputStrict, isUntypedSchema, isUntypedSchemaStrict, isValibotSchema } from "./type-checks.mjs";
|
|
5
|
+
import { addProperty, getJsonSchema, getJsonSchemaObject, getProperties, getPropertiesList, isPropertyOptional, isSchemaNullable, isValidSchemaInputFile, merge } from "./helpers.mjs";
|
|
6
6
|
import { generateCode, getJsonSchemaType, stringifyType, stringifyValue } from "./codegen.mjs";
|
|
7
7
|
import { getCacheDirectory, getCacheFilePath, readSchema, readSchemaSafe, writeSchema } from "./persistence.mjs";
|
|
8
8
|
import { reflectionToJsonSchema } from "./reflection.mjs";
|
|
9
9
|
import { resolve, resolveModule, resolveReflection } from "./resolve.mjs";
|
|
10
10
|
import { bundleReferences, extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaWithSource, extractSource, extractVariant } from "./extract.mjs";
|
|
11
11
|
|
|
12
|
-
export { JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchemaTypeNames, addProperty, applyJsonSchemaMetadata, bundle, bundleReferences, extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaWithSource, extractSource, extractVariant, generateCode, getCacheDirectory, getCacheFilePath, getJsonSchemaType, getPrimarySchemaType, getProperties, getPropertiesList, isJsonSchema, isJsonSchemaAllOf, isJsonSchemaAny, isJsonSchemaAnyOf, isJsonSchemaArray, isJsonSchemaBigint, isJsonSchemaBoolean, isJsonSchemaDate, isJsonSchemaDecimal, isJsonSchemaEnum, isJsonSchemaInteger, isJsonSchemaKeywords, isJsonSchemaLiteral, isJsonSchemaMap, isJsonSchemaNativeEnum, isJsonSchemaNever, isJsonSchemaNull, isJsonSchemaNullable, isJsonSchemaNumber, isJsonSchemaObject, isJsonSchemaPrimitiveType, isJsonSchemaPrimitiveUnion, isJsonSchemaRecord, isJsonSchemaRef, isJsonSchemaSet, isJsonSchemaString, isJsonSchemaTuple, isJsonSchemaType, isJsonSchemaUndefined, isJsonSchemaUnion, isJsonSchemaUnknown, isNullOnlyJsonSchema, isPropertyOptional, isSchema, isSchemaNullable, isSchemaWithSource, isStandardSchema, isUntypedInput, isUntypedInputStrict, isUntypedSchema, isUntypedSchemaStrict, isValibotSchema,
|
|
12
|
+
export { JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchemaTypeNames, VALID_SOURCE_FILE_EXTENSIONS, addProperty, applyJsonSchemaMetadata, bundle, bundleReferences, extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaWithSource, extractSource, extractVariant, generateCode, getCacheDirectory, getCacheFilePath, getJsonSchema, getJsonSchemaObject, getJsonSchemaType, getPrimarySchemaType, getProperties, getPropertiesList, isJsonSchema, isJsonSchemaAllOf, isJsonSchemaAny, isJsonSchemaAnyOf, isJsonSchemaArray, isJsonSchemaBigint, isJsonSchemaBoolean, isJsonSchemaDate, isJsonSchemaDecimal, isJsonSchemaEnum, isJsonSchemaInteger, isJsonSchemaKeywords, isJsonSchemaLiteral, isJsonSchemaMap, isJsonSchemaNativeEnum, isJsonSchemaNever, isJsonSchemaNull, isJsonSchemaNullable, isJsonSchemaNumber, isJsonSchemaObject, isJsonSchemaPrimitiveType, isJsonSchemaPrimitiveUnion, isJsonSchemaRecord, isJsonSchemaRef, isJsonSchemaSet, isJsonSchemaString, isJsonSchemaTuple, isJsonSchemaType, isJsonSchemaUndefined, isJsonSchemaUnion, isJsonSchemaUnknown, isNullOnlyJsonSchema, isPropertyOptional, isSchema, isSchemaNullable, isSchemaObject, isSchemaWithSource, isStandardSchema, isUntypedInput, isUntypedInputStrict, isUntypedSchema, isUntypedSchemaStrict, isValibotSchema, isValidSchemaInputFile, merge, readSchema, readSchemaSafe, readSchemaTypes, reflectionToJsonSchema, resolve, resolveModule, resolveReflection, stringifyType, stringifyValue, writeSchema };
|
package/dist/resolve.cjs
CHANGED
|
@@ -3,23 +3,25 @@ const require_bundle = require('./bundle.cjs');
|
|
|
3
3
|
let defu = require("defu");
|
|
4
4
|
defu = require_runtime.__toESM(defu, 1);
|
|
5
5
|
let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
6
|
+
let _stryke_path_find = require("@stryke/path/find");
|
|
6
7
|
let _powerlines_deepkit_esbuild_plugin = require("@powerlines/deepkit/esbuild-plugin");
|
|
7
8
|
let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
8
|
-
let
|
|
9
|
-
let
|
|
9
|
+
let _stryke_convert_extract_file_reference = require("@stryke/convert/extract-file-reference");
|
|
10
|
+
let smol_toml = require("smol-toml");
|
|
11
|
+
let yaml = require("yaml");
|
|
10
12
|
|
|
11
13
|
//#region src/resolve.ts
|
|
12
14
|
/**
|
|
13
15
|
* Compiles a type definition to a module and returns the module.
|
|
14
16
|
*
|
|
15
17
|
* @param context - The context object containing the environment paths.
|
|
16
|
-
* @param type - The type definition to compile. This can be either a string or a {@link
|
|
18
|
+
* @param type - The type definition to compile. This can be either a string or a {@link FileReference} object.
|
|
17
19
|
* @param overrides - Optional overrides for the ESBuild configuration.
|
|
18
20
|
* @returns A promise that resolves to the compiled module.
|
|
19
21
|
*/
|
|
20
22
|
async function resolveModule(context, type, overrides) {
|
|
21
23
|
let typeDefinition;
|
|
22
|
-
if ((0, _stryke_type_checks_is_set_string.isSetString)(type)) typeDefinition = (0,
|
|
24
|
+
if ((0, _stryke_type_checks_is_set_string.isSetString)(type)) typeDefinition = (0, _stryke_convert_extract_file_reference.extractFileReference)(type);
|
|
23
25
|
else typeDefinition = type;
|
|
24
26
|
const result = await require_bundle.bundle(context, typeDefinition.file, overrides);
|
|
25
27
|
let resolved;
|
|
@@ -47,26 +49,47 @@ ${result.text}` : ""}`);
|
|
|
47
49
|
* Compiles a type definition to a module and returns the specified export from the module.
|
|
48
50
|
*
|
|
49
51
|
* @param context - The context object containing the environment paths.
|
|
50
|
-
* @param input - The type definition to compile. This can be either a string or a {@link
|
|
52
|
+
* @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
|
|
51
53
|
* @param options - Optional overrides for the ESBuild configuration.
|
|
52
54
|
* @returns A promise that resolves to the compiled module.
|
|
53
55
|
*/
|
|
54
56
|
async function resolve(context, input, options) {
|
|
55
|
-
|
|
56
|
-
if ((
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
const fileReference = (0, _stryke_convert_extract_file_reference.extractFileReference)(input);
|
|
58
|
+
if (!fileReference) throw new Error(`Failed to extract a file reference from the provided input. The input must be a string or an object with a "file" property that specifies the file path and optional export name.`);
|
|
59
|
+
const extension = (0, _stryke_path_find.findFileExtensionSafe)(fileReference.file);
|
|
60
|
+
if (extension.startsWith("json")) try {
|
|
61
|
+
const json = await context.fs.read(fileReference.file);
|
|
62
|
+
if (!(0, _stryke_type_checks_is_set_string.isSetString)(json)) throw new Error(`The file at "${fileReference.file}" could not be read as a string. Please ensure the file exists and contains valid JSON.`);
|
|
63
|
+
return JSON.parse(json);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
throw new Error(`Failed to read or parse the JSON file at "${fileReference.file}". Please ensure the file exists and contains valid JSON. Error: ${error.message}`);
|
|
66
|
+
}
|
|
67
|
+
else if (extension === "yaml" || extension === "yml") try {
|
|
68
|
+
const yaml$1 = await context.fs.read(fileReference.file);
|
|
69
|
+
if (!(0, _stryke_type_checks_is_set_string.isSetString)(yaml$1)) throw new Error(`The file at "${fileReference.file}" could not be read as a string. Please ensure the file exists and contains valid YAML.`);
|
|
70
|
+
return (0, yaml.parse)(yaml$1);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
throw new Error(`Failed to read or parse the YAML file at "${fileReference.file}". Please ensure the file exists and contains valid YAML. Error: ${error.message}`);
|
|
73
|
+
}
|
|
74
|
+
else if (extension === "toml") try {
|
|
75
|
+
const toml = await context.fs.read(fileReference.file);
|
|
76
|
+
if (!(0, _stryke_type_checks_is_set_string.isSetString)(toml)) throw new Error(`The file at "${fileReference.file}" could not be read as a string. Please ensure the file exists and contains valid TOML.`);
|
|
77
|
+
return (0, smol_toml.parse)(toml);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
throw new Error(`Failed to read or parse the TOML file at "${fileReference.file}". Please ensure the file exists and contains valid TOML. Error: ${error.message}`);
|
|
80
|
+
}
|
|
81
|
+
const resolved = await resolveModule(context, fileReference, options);
|
|
82
|
+
let exportName = fileReference.export;
|
|
60
83
|
if (!exportName) exportName = "default";
|
|
61
84
|
const resolvedExport = resolved[exportName] ?? resolved[`__Ω${exportName}`];
|
|
62
|
-
if (resolvedExport === void 0) throw new Error(`The export "${exportName}" could not be resolved in the "${
|
|
85
|
+
if (resolvedExport === void 0) throw new Error(`The export "${exportName}" could not be resolved in the "${fileReference.file}" module. ${Object.keys(resolved).length === 0 ? `After bundling, no exports were found in the module. Please ensure that the "${fileReference.file}" module has a "${exportName}" export with the desired value.` : `After bundling, the available exports were: ${Object.keys(resolved).join(", ")}. Please ensure that the export exists and is correctly named.`}`);
|
|
63
86
|
return resolvedExport;
|
|
64
87
|
}
|
|
65
88
|
/**
|
|
66
89
|
* Resolves a type definition to a Deepkit Type reflection. This function compiles the provided type definition to a module, evaluates the module to get the specified export, and then reflects the export to get its Deepkit Type reflection.
|
|
67
90
|
*
|
|
68
91
|
* @param context - The context object containing the environment paths.
|
|
69
|
-
* @param input - The type definition to compile. This can be either a string or a {@link
|
|
92
|
+
* @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
|
|
70
93
|
* @param options - Optional overrides for the ESBuild configuration.
|
|
71
94
|
* @returns A promise that resolves to the Deepkit Type reflection.
|
|
72
95
|
*/
|
package/dist/resolve.d.cts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
import { BundleOptions } from "./bundle.cjs";
|
|
2
|
-
import { TypeDefinitionReference } from "./types.cjs";
|
|
3
2
|
import { PluginContext, UnresolvedContext } from "@powerlines/core";
|
|
4
3
|
import { Type } from "@powerlines/deepkit/vendor/type";
|
|
4
|
+
import { FileReference, FileReferenceInput } from "@stryke/types/configuration";
|
|
5
5
|
|
|
6
6
|
//#region src/resolve.d.ts
|
|
7
7
|
/**
|
|
8
8
|
* Compiles a type definition to a module and returns the module.
|
|
9
9
|
*
|
|
10
10
|
* @param context - The context object containing the environment paths.
|
|
11
|
-
* @param type - The type definition to compile. This can be either a string or a {@link
|
|
11
|
+
* @param type - The type definition to compile. This can be either a string or a {@link FileReference} object.
|
|
12
12
|
* @param overrides - Optional overrides for the ESBuild configuration.
|
|
13
13
|
* @returns A promise that resolves to the compiled module.
|
|
14
14
|
*/
|
|
15
|
-
declare function resolveModule<TResult, TContext extends UnresolvedContext = UnresolvedContext>(context: TContext, type:
|
|
15
|
+
declare function resolveModule<TResult, TContext extends UnresolvedContext = UnresolvedContext>(context: TContext, type: FileReference, overrides?: BundleOptions): Promise<TResult>;
|
|
16
16
|
/**
|
|
17
17
|
* Compiles a type definition to a module and returns the specified export from the module.
|
|
18
18
|
*
|
|
19
19
|
* @param context - The context object containing the environment paths.
|
|
20
|
-
* @param input - The type definition to compile. This can be either a string or a {@link
|
|
20
|
+
* @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
|
|
21
21
|
* @param options - Optional overrides for the ESBuild configuration.
|
|
22
22
|
* @returns A promise that resolves to the compiled module.
|
|
23
23
|
*/
|
|
24
|
-
declare function resolve<TResult, TContext extends UnresolvedContext = UnresolvedContext>(context: TContext, input:
|
|
24
|
+
declare function resolve<TResult, TContext extends UnresolvedContext = UnresolvedContext>(context: TContext, input: FileReferenceInput, options?: BundleOptions): Promise<TResult>;
|
|
25
25
|
/**
|
|
26
26
|
* Resolves a type definition to a Deepkit Type reflection. This function compiles the provided type definition to a module, evaluates the module to get the specified export, and then reflects the export to get its Deepkit Type reflection.
|
|
27
27
|
*
|
|
28
28
|
* @param context - The context object containing the environment paths.
|
|
29
|
-
* @param input - The type definition to compile. This can be either a string or a {@link
|
|
29
|
+
* @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
|
|
30
30
|
* @param options - Optional overrides for the ESBuild configuration.
|
|
31
31
|
* @returns A promise that resolves to the Deepkit Type reflection.
|
|
32
32
|
*/
|
|
33
|
-
declare function resolveReflection<TContext extends PluginContext = PluginContext>(context: TContext, input:
|
|
33
|
+
declare function resolveReflection<TContext extends PluginContext = PluginContext>(context: TContext, input: FileReference, options?: BundleOptions): Promise<Type>;
|
|
34
34
|
//#endregion
|
|
35
35
|
export { resolve, resolveModule, resolveReflection };
|
|
36
36
|
//# sourceMappingURL=resolve.d.cts.map
|
package/dist/resolve.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.cts","names":[],"sources":["../src/resolve.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"resolve.d.cts","names":[],"sources":["../src/resolve.ts"],"mappings":";;;;;;;;AAsCA;;;;;;iBAAsB,aAAA,2BAEH,iBAAA,GAAoB,iBAAA,CAAA,CAErC,OAAA,EAAS,QAAA,EACT,IAAA,EAAM,aAAA,EACN,SAAA,GAAY,aAAA,GACX,OAAA,CAAQ,OAAA;;;;;;;;;iBAyEW,OAAA,2BAEH,iBAAA,GAAoB,iBAAA,CAAA,CAErC,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,kBAAA,EACP,OAAA,GAAU,aAAA,GACT,OAAA,CAAQ,OAAA;;;;;;;;;iBAiGW,iBAAA,kBACH,aAAA,GAAgB,aAAA,CAAA,CAEjC,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,aAAA,EACP,OAAA,GAAU,aAAA,GACT,OAAA,CAAQ,IAAA"}
|
package/dist/resolve.d.mts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
import { BundleOptions } from "./bundle.mjs";
|
|
2
|
-
import { TypeDefinitionReference } from "./types.mjs";
|
|
3
2
|
import { PluginContext, UnresolvedContext } from "@powerlines/core";
|
|
4
3
|
import { Type } from "@powerlines/deepkit/vendor/type";
|
|
4
|
+
import { FileReference, FileReferenceInput } from "@stryke/types/configuration";
|
|
5
5
|
|
|
6
6
|
//#region src/resolve.d.ts
|
|
7
7
|
/**
|
|
8
8
|
* Compiles a type definition to a module and returns the module.
|
|
9
9
|
*
|
|
10
10
|
* @param context - The context object containing the environment paths.
|
|
11
|
-
* @param type - The type definition to compile. This can be either a string or a {@link
|
|
11
|
+
* @param type - The type definition to compile. This can be either a string or a {@link FileReference} object.
|
|
12
12
|
* @param overrides - Optional overrides for the ESBuild configuration.
|
|
13
13
|
* @returns A promise that resolves to the compiled module.
|
|
14
14
|
*/
|
|
15
|
-
declare function resolveModule<TResult, TContext extends UnresolvedContext = UnresolvedContext>(context: TContext, type:
|
|
15
|
+
declare function resolveModule<TResult, TContext extends UnresolvedContext = UnresolvedContext>(context: TContext, type: FileReference, overrides?: BundleOptions): Promise<TResult>;
|
|
16
16
|
/**
|
|
17
17
|
* Compiles a type definition to a module and returns the specified export from the module.
|
|
18
18
|
*
|
|
19
19
|
* @param context - The context object containing the environment paths.
|
|
20
|
-
* @param input - The type definition to compile. This can be either a string or a {@link
|
|
20
|
+
* @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
|
|
21
21
|
* @param options - Optional overrides for the ESBuild configuration.
|
|
22
22
|
* @returns A promise that resolves to the compiled module.
|
|
23
23
|
*/
|
|
24
|
-
declare function resolve<TResult, TContext extends UnresolvedContext = UnresolvedContext>(context: TContext, input:
|
|
24
|
+
declare function resolve<TResult, TContext extends UnresolvedContext = UnresolvedContext>(context: TContext, input: FileReferenceInput, options?: BundleOptions): Promise<TResult>;
|
|
25
25
|
/**
|
|
26
26
|
* Resolves a type definition to a Deepkit Type reflection. This function compiles the provided type definition to a module, evaluates the module to get the specified export, and then reflects the export to get its Deepkit Type reflection.
|
|
27
27
|
*
|
|
28
28
|
* @param context - The context object containing the environment paths.
|
|
29
|
-
* @param input - The type definition to compile. This can be either a string or a {@link
|
|
29
|
+
* @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
|
|
30
30
|
* @param options - Optional overrides for the ESBuild configuration.
|
|
31
31
|
* @returns A promise that resolves to the Deepkit Type reflection.
|
|
32
32
|
*/
|
|
33
|
-
declare function resolveReflection<TContext extends PluginContext = PluginContext>(context: TContext, input:
|
|
33
|
+
declare function resolveReflection<TContext extends PluginContext = PluginContext>(context: TContext, input: FileReference, options?: BundleOptions): Promise<Type>;
|
|
34
34
|
//#endregion
|
|
35
35
|
export { resolve, resolveModule, resolveReflection };
|
|
36
36
|
//# sourceMappingURL=resolve.d.mts.map
|
package/dist/resolve.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.mts","names":[],"sources":["../src/resolve.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"resolve.d.mts","names":[],"sources":["../src/resolve.ts"],"mappings":";;;;;;;;AAsCA;;;;;;iBAAsB,aAAA,2BAEH,iBAAA,GAAoB,iBAAA,CAAA,CAErC,OAAA,EAAS,QAAA,EACT,IAAA,EAAM,aAAA,EACN,SAAA,GAAY,aAAA,GACX,OAAA,CAAQ,OAAA;;;;;;;;;iBAyEW,OAAA,2BAEH,iBAAA,GAAoB,iBAAA,CAAA,CAErC,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,kBAAA,EACP,OAAA,GAAU,aAAA,GACT,OAAA,CAAQ,OAAA;;;;;;;;;iBAiGW,iBAAA,kBACH,aAAA,GAAgB,aAAA,CAAA,CAEjC,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,aAAA,EACP,OAAA,GAAU,aAAA,GACT,OAAA,CAAQ,IAAA"}
|