@powerlines/schema 0.11.45 → 0.11.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.cjs +1 -1
- package/dist/bundle.d.cts +1 -1
- package/dist/bundle.d.mts +1 -1
- package/dist/bundle.mjs +1 -1
- package/dist/bundle.mjs.map +1 -1
- package/dist/codegen.cjs +28 -22
- package/dist/codegen.d.cts +11 -11
- package/dist/codegen.d.cts.map +1 -1
- package/dist/codegen.d.mts +11 -11
- package/dist/codegen.d.mts.map +1 -1
- package/dist/codegen.mjs +36 -30
- package/dist/codegen.mjs.map +1 -1
- package/dist/constants.cjs +15 -11
- package/dist/constants.d.cts +4 -3
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +4 -3
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +13 -10
- package/dist/constants.mjs.map +1 -1
- package/dist/extract.cjs +158 -20
- package/dist/extract.d.cts +55 -16
- package/dist/extract.d.cts.map +1 -1
- package/dist/extract.d.mts +55 -16
- package/dist/extract.d.mts.map +1 -1
- package/dist/extract.mjs +158 -22
- package/dist/extract.mjs.map +1 -1
- package/dist/helpers.cjs +43 -8
- package/dist/helpers.d.cts +40 -6
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +40 -6
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +43 -10
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +39 -7
- package/dist/index.d.cts +8 -8
- package/dist/index.d.mts +8 -8
- package/dist/index.mjs +7 -7
- package/dist/metadata.cjs +9 -35
- package/dist/metadata.d.cts +5 -26
- package/dist/metadata.d.cts.map +1 -1
- package/dist/metadata.d.mts +5 -26
- package/dist/metadata.d.mts.map +1 -1
- package/dist/metadata.mjs +9 -33
- package/dist/metadata.mjs.map +1 -1
- package/dist/persistence.d.cts +4 -4
- package/dist/persistence.d.cts.map +1 -1
- package/dist/persistence.d.mts +4 -4
- package/dist/persistence.d.mts.map +1 -1
- package/dist/persistence.mjs.map +1 -1
- package/dist/reflection.cjs +72 -50
- package/dist/reflection.d.cts +1 -1
- package/dist/reflection.d.cts.map +1 -1
- package/dist/reflection.d.mts +1 -1
- package/dist/reflection.d.mts.map +1 -1
- package/dist/reflection.mjs +74 -52
- package/dist/reflection.mjs.map +1 -1
- package/dist/type-checks.cjs +363 -83
- package/dist/type-checks.d.cts +138 -16
- package/dist/type-checks.d.cts.map +1 -1
- package/dist/type-checks.d.mts +138 -16
- package/dist/type-checks.d.mts.map +1 -1
- package/dist/type-checks.mjs +336 -85
- package/dist/type-checks.mjs.map +1 -1
- package/dist/types.d.cts +901 -176
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +901 -176
- package/dist/types.d.mts.map +1 -1
- package/dist/validate.mjs.map +1 -1
- package/package.json +5 -5
package/dist/helpers.d.mts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { JsonSchema,
|
|
1
|
+
import { JsonSchema, JsonSchemaObject, Schema } from "./types.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/helpers.d.ts
|
|
4
|
+
type GetPropertiesResult = JsonSchema & {
|
|
5
|
+
name: string;
|
|
6
|
+
required: boolean;
|
|
7
|
+
default?: unknown;
|
|
8
|
+
};
|
|
4
9
|
/**
|
|
5
10
|
* Extracts object properties from a JSON Schema object form.
|
|
6
11
|
*
|
|
@@ -10,7 +15,11 @@ import { JsonSchema, JsonSchemaProperty, Schema } from "./types.mjs";
|
|
|
10
15
|
* @param obj - The JSON Schema object form or a Schema wrapper to extract properties from.
|
|
11
16
|
* @returns An object mapping property names to their corresponding JSON Schema fragments, including metadata.
|
|
12
17
|
*/
|
|
13
|
-
declare function getProperties
|
|
18
|
+
declare function getProperties(obj: Schema | JsonSchemaObject): Record<string, JsonSchema & {
|
|
19
|
+
name: string;
|
|
20
|
+
required: boolean;
|
|
21
|
+
default?: unknown;
|
|
22
|
+
}>;
|
|
14
23
|
/**
|
|
15
24
|
* Returns object properties as an array.
|
|
16
25
|
*
|
|
@@ -20,7 +29,11 @@ declare function getProperties<T extends Record<string, any> = Record<string, an
|
|
|
20
29
|
* @param obj - The JSON Schema object form or a Schema wrapper to extract properties from.
|
|
21
30
|
* @returns An array of JSON Schema fragments representing the properties, each including metadata.
|
|
22
31
|
*/
|
|
23
|
-
declare function getPropertiesList
|
|
32
|
+
declare function getPropertiesList(obj: Schema | JsonSchemaObject): (JsonSchema & {
|
|
33
|
+
name: string;
|
|
34
|
+
required: boolean;
|
|
35
|
+
default?: unknown;
|
|
36
|
+
})[];
|
|
24
37
|
/**
|
|
25
38
|
* Adds a property to a JSON Schema object form.
|
|
26
39
|
*
|
|
@@ -32,7 +45,7 @@ declare function getPropertiesList<T extends Record<string, any> = Record<string
|
|
|
32
45
|
* @param property - The JSON Schema fragment representing the property's schema, including metadata.
|
|
33
46
|
* @throws Will throw an error if the provided schema is not an object form.
|
|
34
47
|
*/
|
|
35
|
-
declare function addProperty
|
|
48
|
+
declare function addProperty(obj: Schema | JsonSchemaObject, name: string, property: JsonSchema): void;
|
|
36
49
|
/**
|
|
37
50
|
* Merges multiple JSON Schema object forms into one.
|
|
38
51
|
*
|
|
@@ -42,7 +55,28 @@ declare function addProperty<T extends Record<string, any> = Record<string, any>
|
|
|
42
55
|
* @param schemas - An array of JSON Schema objects or Schema wrappers to merge.
|
|
43
56
|
* @returns A new JSON Schema object that is the result of merging all input schemas.
|
|
44
57
|
*/
|
|
45
|
-
declare function mergeSchemas
|
|
58
|
+
declare function mergeSchemas(...schemas: (JsonSchema | Schema)[]): JsonSchema;
|
|
59
|
+
/**
|
|
60
|
+
* Returns whether a JSON Schema fragment accepts `null`.
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* This is true if the schema has `nullable: true` or if its `type` includes `"null"`.
|
|
64
|
+
*
|
|
65
|
+
* @param schema - The JSON Schema fragment to check.
|
|
66
|
+
* @returns `true` if the schema accepts `null`, otherwise `false`.
|
|
67
|
+
*/
|
|
68
|
+
declare function isSchemaNullable(schema?: JsonSchema): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Returns whether an object property is optional (not listed in `required`).
|
|
71
|
+
*
|
|
72
|
+
* @remarks
|
|
73
|
+
* 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.
|
|
74
|
+
*
|
|
75
|
+
* @param parent - The parent JSON Schema object containing the property.
|
|
76
|
+
* @param propertyName - The name of the property to check for optionality.
|
|
77
|
+
* @returns `true` if the property is optional, otherwise `false`.
|
|
78
|
+
*/
|
|
79
|
+
declare function isPropertyOptional(parent: JsonSchemaObject, propertyName: string): boolean;
|
|
46
80
|
//#endregion
|
|
47
|
-
export { addProperty, getProperties, getPropertiesList, mergeSchemas };
|
|
81
|
+
export { GetPropertiesResult, addProperty, getProperties, getPropertiesList, isPropertyOptional, isSchemaNullable, mergeSchemas };
|
|
48
82
|
//# 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":";;;KAwBY,mBAAA,GAAsB,UAAU;EAC1C,IAAA;EACA,QAAA;EACA,OAAA;AAAA;;;;;;;AAAO;AAYT;;iBAAgB,aAAA,CACd,GAAA,EAAK,MAAA,GAAS,gBAAA,GACb,MAAA,SAED,UAAA;EAAe,IAAA;EAAc,QAAA;EAAmB,OAAA;AAAA;;;;;;;;;;iBA0ClC,iBAAA,CAAkB,GAAA,EAAK,MAAA,GAAS,gBAAA,IAAgB,UAAA;;;;;;;;;;;;;;;;iBAehD,WAAA,CACd,GAAA,EAAK,MAAA,GAAS,gBAAA,EACd,IAAA,UACA,QAAA,EAAU,UAAA;;;;AAHZ;;;;;;iBAgCgB,YAAA,CAAA,GAAgB,OAAA,GAAU,UAAA,GAAa,MAAA,MAAY,UAAA;;;;;;;;;AA7B7C;iBAoDN,gBAAA,CAAiB,MAAmB,GAAV,UAAU;;;;;;;;;;;iBAsBpC,kBAAA,CACd,MAAA,EAAQ,gBAAgB,EACxB,YAAA"}
|
package/dist/helpers.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readSchemaTypes } from "./metadata.mjs";
|
|
2
2
|
import { isJsonSchemaObject, isSchema } from "./type-checks.mjs";
|
|
3
3
|
import { defu as defu$1 } from "defu";
|
|
4
4
|
import { isSetObject } from "@stryke/type-checks";
|
|
@@ -16,12 +16,18 @@ import { isSetObject } from "@stryke/type-checks";
|
|
|
16
16
|
function getProperties(obj) {
|
|
17
17
|
const properties = {};
|
|
18
18
|
const schema = isSchema(obj) ? obj.schema : obj;
|
|
19
|
-
if (!isJsonSchemaObject(schema)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
if (!isJsonSchemaObject(schema)) return properties;
|
|
20
|
+
if (!isSetObject(schema.properties)) return properties;
|
|
21
|
+
for (const [key, value] of Object.entries(schema.properties)) {
|
|
22
|
+
const propertySchema = {};
|
|
23
|
+
if (typeof value !== "boolean") Object.assign(propertySchema, value);
|
|
24
|
+
properties[key] = {
|
|
25
|
+
...propertySchema,
|
|
26
|
+
name: key,
|
|
27
|
+
required: !isPropertyOptional(schema, key),
|
|
28
|
+
default: schema.default?.[key] ?? propertySchema.default
|
|
29
|
+
};
|
|
30
|
+
}
|
|
25
31
|
return properties;
|
|
26
32
|
}
|
|
27
33
|
/**
|
|
@@ -56,8 +62,7 @@ function addProperty(obj, name, property) {
|
|
|
56
62
|
...property,
|
|
57
63
|
name
|
|
58
64
|
};
|
|
59
|
-
if (
|
|
60
|
-
else if (!schema.required.includes(name)) schema.required.push(name);
|
|
65
|
+
if (!schema.required.includes(name)) schema.required.push(name);
|
|
61
66
|
if (schema.required.length === 0) delete schema.required;
|
|
62
67
|
}
|
|
63
68
|
/**
|
|
@@ -78,7 +83,35 @@ function mergeSchemas(...schemas) {
|
|
|
78
83
|
}
|
|
79
84
|
return result;
|
|
80
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Returns whether a JSON Schema fragment accepts `null`.
|
|
88
|
+
*
|
|
89
|
+
* @remarks
|
|
90
|
+
* This is true if the schema has `nullable: true` or if its `type` includes `"null"`.
|
|
91
|
+
*
|
|
92
|
+
* @param schema - The JSON Schema fragment to check.
|
|
93
|
+
* @returns `true` if the schema accepts `null`, otherwise `false`.
|
|
94
|
+
*/
|
|
95
|
+
function isSchemaNullable(schema) {
|
|
96
|
+
if (!isSetObject(schema)) return false;
|
|
97
|
+
if (schema.nullable === true) return true;
|
|
98
|
+
return readSchemaTypes(schema).includes("null");
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns whether an object property is optional (not listed in `required`).
|
|
102
|
+
*
|
|
103
|
+
* @remarks
|
|
104
|
+
* 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.
|
|
105
|
+
*
|
|
106
|
+
* @param parent - The parent JSON Schema object containing the property.
|
|
107
|
+
* @param propertyName - The name of the property to check for optionality.
|
|
108
|
+
* @returns `true` if the property is optional, otherwise `false`.
|
|
109
|
+
*/
|
|
110
|
+
function isPropertyOptional(parent, propertyName) {
|
|
111
|
+
if (!parent.properties?.[propertyName]) throw new Error(`The property "${propertyName}" does not exist in the parent schema.`);
|
|
112
|
+
return !(parent.required ?? []).includes(propertyName);
|
|
113
|
+
}
|
|
81
114
|
|
|
82
115
|
//#endregion
|
|
83
|
-
export { addProperty, getProperties, getPropertiesList, mergeSchemas };
|
|
116
|
+
export { addProperty, getProperties, getPropertiesList, isPropertyOptional, isSchemaNullable, mergeSchemas };
|
|
84
117
|
//# 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 {
|
|
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"}
|
package/dist/index.cjs
CHANGED
|
@@ -10,34 +10,66 @@ const require_reflection = require('./reflection.cjs');
|
|
|
10
10
|
const require_resolve = require('./resolve.cjs');
|
|
11
11
|
const require_extract = require('./extract.cjs');
|
|
12
12
|
|
|
13
|
-
exports.JSON_SCHEMA_DATA_TYPES = require_constants.JSON_SCHEMA_DATA_TYPES;
|
|
14
13
|
exports.JSON_SCHEMA_METADATA_KEYS = require_constants.JSON_SCHEMA_METADATA_KEYS;
|
|
15
|
-
exports.
|
|
14
|
+
exports.JSON_SCHEMA_PRIMITIVE_TYPES = require_constants.JSON_SCHEMA_PRIMITIVE_TYPES;
|
|
15
|
+
exports.JSON_SCHEMA_TYPES = require_constants.JSON_SCHEMA_TYPES;
|
|
16
|
+
exports.JsonSchemaTypeNames = require_constants.JsonSchemaTypeNames;
|
|
16
17
|
exports.addProperty = require_helpers.addProperty;
|
|
17
|
-
exports.
|
|
18
|
+
exports.applyJsonSchemaMetadata = require_metadata.applyJsonSchemaMetadata;
|
|
18
19
|
exports.bundle = require_bundle.bundle;
|
|
20
|
+
exports.bundleReferences = require_extract.bundleReferences;
|
|
19
21
|
exports.extract = require_extract.extract;
|
|
20
22
|
exports.extractHash = require_extract.extractHash;
|
|
21
23
|
exports.extractJsonSchema = require_extract.extractJsonSchema;
|
|
22
24
|
exports.extractReflection = require_extract.extractReflection;
|
|
23
25
|
exports.extractResolvedVariant = require_extract.extractResolvedVariant;
|
|
24
26
|
exports.extractSchema = require_extract.extractSchema;
|
|
27
|
+
exports.extractSchemaWithSource = require_extract.extractSchemaWithSource;
|
|
25
28
|
exports.extractSource = require_extract.extractSource;
|
|
26
29
|
exports.extractVariant = require_extract.extractVariant;
|
|
27
30
|
exports.generateCode = require_codegen.generateCode;
|
|
28
31
|
exports.getCacheDirectory = require_persistence.getCacheDirectory;
|
|
29
32
|
exports.getCacheFilePath = require_persistence.getCacheFilePath;
|
|
33
|
+
exports.getJsonSchemaType = require_codegen.getJsonSchemaType;
|
|
30
34
|
exports.getPrimarySchemaType = require_metadata.getPrimarySchemaType;
|
|
31
35
|
exports.getProperties = require_helpers.getProperties;
|
|
32
36
|
exports.getPropertiesList = require_helpers.getPropertiesList;
|
|
33
|
-
exports.isExtractedSchema = require_type_checks.isExtractedSchema;
|
|
34
37
|
exports.isJsonSchema = require_type_checks.isJsonSchema;
|
|
38
|
+
exports.isJsonSchemaAllOf = require_type_checks.isJsonSchemaAllOf;
|
|
39
|
+
exports.isJsonSchemaAny = require_type_checks.isJsonSchemaAny;
|
|
40
|
+
exports.isJsonSchemaAnyOf = require_type_checks.isJsonSchemaAnyOf;
|
|
41
|
+
exports.isJsonSchemaArray = require_type_checks.isJsonSchemaArray;
|
|
42
|
+
exports.isJsonSchemaBigint = require_type_checks.isJsonSchemaBigint;
|
|
43
|
+
exports.isJsonSchemaBoolean = require_type_checks.isJsonSchemaBoolean;
|
|
44
|
+
exports.isJsonSchemaDate = require_type_checks.isJsonSchemaDate;
|
|
45
|
+
exports.isJsonSchemaDecimal = require_type_checks.isJsonSchemaDecimal;
|
|
46
|
+
exports.isJsonSchemaEnum = require_type_checks.isJsonSchemaEnum;
|
|
47
|
+
exports.isJsonSchemaInteger = require_type_checks.isJsonSchemaInteger;
|
|
48
|
+
exports.isJsonSchemaKeywords = require_type_checks.isJsonSchemaKeywords;
|
|
49
|
+
exports.isJsonSchemaLiteral = require_type_checks.isJsonSchemaLiteral;
|
|
50
|
+
exports.isJsonSchemaMap = require_type_checks.isJsonSchemaMap;
|
|
51
|
+
exports.isJsonSchemaNativeEnum = require_type_checks.isJsonSchemaNativeEnum;
|
|
52
|
+
exports.isJsonSchemaNever = require_type_checks.isJsonSchemaNever;
|
|
53
|
+
exports.isJsonSchemaNull = require_type_checks.isJsonSchemaNull;
|
|
54
|
+
exports.isJsonSchemaNullable = require_type_checks.isJsonSchemaNullable;
|
|
55
|
+
exports.isJsonSchemaNumber = require_type_checks.isJsonSchemaNumber;
|
|
35
56
|
exports.isJsonSchemaObject = require_type_checks.isJsonSchemaObject;
|
|
57
|
+
exports.isJsonSchemaPrimitiveType = require_type_checks.isJsonSchemaPrimitiveType;
|
|
58
|
+
exports.isJsonSchemaPrimitiveUnion = require_type_checks.isJsonSchemaPrimitiveUnion;
|
|
59
|
+
exports.isJsonSchemaRecord = require_type_checks.isJsonSchemaRecord;
|
|
60
|
+
exports.isJsonSchemaRef = require_type_checks.isJsonSchemaRef;
|
|
61
|
+
exports.isJsonSchemaSet = require_type_checks.isJsonSchemaSet;
|
|
62
|
+
exports.isJsonSchemaString = require_type_checks.isJsonSchemaString;
|
|
63
|
+
exports.isJsonSchemaTuple = require_type_checks.isJsonSchemaTuple;
|
|
64
|
+
exports.isJsonSchemaType = require_type_checks.isJsonSchemaType;
|
|
65
|
+
exports.isJsonSchemaUndefined = require_type_checks.isJsonSchemaUndefined;
|
|
66
|
+
exports.isJsonSchemaUnion = require_type_checks.isJsonSchemaUnion;
|
|
67
|
+
exports.isJsonSchemaUnknown = require_type_checks.isJsonSchemaUnknown;
|
|
36
68
|
exports.isNullOnlyJsonSchema = require_type_checks.isNullOnlyJsonSchema;
|
|
37
|
-
exports.
|
|
38
|
-
exports.isPropertyOptional = require_metadata.isPropertyOptional;
|
|
69
|
+
exports.isPropertyOptional = require_helpers.isPropertyOptional;
|
|
39
70
|
exports.isSchema = require_type_checks.isSchema;
|
|
40
|
-
exports.isSchemaNullable =
|
|
71
|
+
exports.isSchemaNullable = require_helpers.isSchemaNullable;
|
|
72
|
+
exports.isSchemaWithSource = require_type_checks.isSchemaWithSource;
|
|
41
73
|
exports.isStandardSchema = require_type_checks.isStandardSchema;
|
|
42
74
|
exports.isUntypedInput = require_type_checks.isUntypedInput;
|
|
43
75
|
exports.isUntypedSchema = require_type_checks.isUntypedSchema;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { BundleOptions, bundle } from "./bundle.cjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSource, extractVariant } from "./extract.cjs";
|
|
6
|
-
import { addProperty, getProperties, getPropertiesList, mergeSchemas } from "./helpers.cjs";
|
|
7
|
-
import {
|
|
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, JsonSchemaEnum, JsonSchemaInteger, JsonSchemaKeywords, JsonSchemaLiteral, JsonSchemaLogicKeywords, JsonSchemaMap, JsonSchemaMetadataKeywords, JsonSchemaNativeEnum, JsonSchemaNever, JsonSchemaNull, JsonSchemaNullable, JsonSchemaNumber, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaPrimitiveUnion, JsonSchemaRecord, JsonSchemaRecordPropertyNames, JsonSchemaRef, JsonSchemaSchemaSource, JsonSchemaSet, JsonSchemaString, JsonSchemaTuple, JsonSchemaType, JsonSchemaUndefined, JsonSchemaUnion, JsonSchemaUnknown, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, ValibotSchema, ValibotSchemaSource, Zod3SchemaSource } from "./types.cjs";
|
|
4
|
+
import { generateCode, getJsonSchemaType, stringifyType, stringifyValue } from "./codegen.cjs";
|
|
5
|
+
import { bundleReferences, extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaWithSource, extractSource, extractVariant } from "./extract.cjs";
|
|
6
|
+
import { GetPropertiesResult, addProperty, getProperties, getPropertiesList, isPropertyOptional, isSchemaNullable, mergeSchemas } from "./helpers.cjs";
|
|
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 {
|
|
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, isUntypedSchema, 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,
|
|
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, JsonSchemaEnum, JsonSchemaInteger, JsonSchemaKeywords, JsonSchemaLiteral, JsonSchemaLogicKeywords, JsonSchemaMap, JsonSchemaMetadataKeywords, JsonSchemaNativeEnum, JsonSchemaNever, JsonSchemaNull, JsonSchemaNullable, JsonSchemaNumber, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaPrimitiveUnion, JsonSchemaRecord, JsonSchemaRecordPropertyNames, JsonSchemaRef, JsonSchemaSchemaSource, JsonSchemaSet, JsonSchemaString, JsonSchemaTuple, JsonSchemaType, JsonSchemaTypeNames, JsonSchemaUndefined, JsonSchemaUnion, JsonSchemaUnknown, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, ValibotSchema, ValibotSchemaSource, Zod3SchemaSource, 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, isUntypedSchema, isValibotSchema, mergeSchemas, 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 {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSource, extractVariant } from "./extract.mjs";
|
|
6
|
-
import { addProperty, getProperties, getPropertiesList, mergeSchemas } from "./helpers.mjs";
|
|
7
|
-
import {
|
|
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, JsonSchemaEnum, JsonSchemaInteger, JsonSchemaKeywords, JsonSchemaLiteral, JsonSchemaLogicKeywords, JsonSchemaMap, JsonSchemaMetadataKeywords, JsonSchemaNativeEnum, JsonSchemaNever, JsonSchemaNull, JsonSchemaNullable, JsonSchemaNumber, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaPrimitiveUnion, JsonSchemaRecord, JsonSchemaRecordPropertyNames, JsonSchemaRef, JsonSchemaSchemaSource, JsonSchemaSet, JsonSchemaString, JsonSchemaTuple, JsonSchemaType, JsonSchemaUndefined, JsonSchemaUnion, JsonSchemaUnknown, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, ValibotSchema, ValibotSchemaSource, Zod3SchemaSource } from "./types.mjs";
|
|
4
|
+
import { generateCode, getJsonSchemaType, stringifyType, stringifyValue } from "./codegen.mjs";
|
|
5
|
+
import { bundleReferences, extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaWithSource, extractSource, extractVariant } from "./extract.mjs";
|
|
6
|
+
import { GetPropertiesResult, addProperty, getProperties, getPropertiesList, isPropertyOptional, isSchemaNullable, mergeSchemas } from "./helpers.mjs";
|
|
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 {
|
|
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, isUntypedSchema, 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,
|
|
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, JsonSchemaEnum, JsonSchemaInteger, JsonSchemaKeywords, JsonSchemaLiteral, JsonSchemaLogicKeywords, JsonSchemaMap, JsonSchemaMetadataKeywords, JsonSchemaNativeEnum, JsonSchemaNever, JsonSchemaNull, JsonSchemaNullable, JsonSchemaNumber, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaPrimitiveUnion, JsonSchemaRecord, JsonSchemaRecordPropertyNames, JsonSchemaRef, JsonSchemaSchemaSource, JsonSchemaSet, JsonSchemaString, JsonSchemaTuple, JsonSchemaType, JsonSchemaTypeNames, JsonSchemaUndefined, JsonSchemaUnion, JsonSchemaUnknown, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, ValibotSchema, ValibotSchemaSource, Zod3SchemaSource, 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, isUntypedSchema, isValibotSchema, mergeSchemas, 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 {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { addProperty, getProperties, getPropertiesList, mergeSchemas } from "./helpers.mjs";
|
|
6
|
-
import { generateCode,
|
|
2
|
+
import { JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchemaTypeNames } from "./constants.mjs";
|
|
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, isUntypedSchema, isValibotSchema } from "./type-checks.mjs";
|
|
5
|
+
import { addProperty, getProperties, getPropertiesList, isPropertyOptional, isSchemaNullable, mergeSchemas } from "./helpers.mjs";
|
|
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
|
-
import { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSource, extractVariant } from "./extract.mjs";
|
|
10
|
+
import { bundleReferences, extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSchemaWithSource, extractSource, extractVariant } from "./extract.mjs";
|
|
11
11
|
|
|
12
|
-
export {
|
|
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, isUntypedSchema, isValibotSchema, mergeSchemas, readSchema, readSchemaSafe, readSchemaTypes, reflectionToJsonSchema, resolve, resolveModule, resolveReflection, stringifyType, stringifyValue, writeSchema };
|
package/dist/metadata.cjs
CHANGED
|
@@ -10,43 +10,17 @@ let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-obje
|
|
|
10
10
|
* @param metadata - The Powerlines schema metadata to apply.
|
|
11
11
|
* @returns A new JSON Schema fragment with the metadata applied.
|
|
12
12
|
*/
|
|
13
|
-
function
|
|
14
|
-
if (!metadata) return schema;
|
|
13
|
+
function applyJsonSchemaMetadata(schema, metadata) {
|
|
14
|
+
if (!metadata || !(0, _stryke_type_checks_is_set_object.isSetObject)(schema)) return schema;
|
|
15
15
|
const result = { ...schema };
|
|
16
|
+
const mutableResult = result;
|
|
16
17
|
for (const key of require_constants.JSON_SCHEMA_METADATA_KEYS) {
|
|
17
18
|
const value = metadata[key];
|
|
18
|
-
if (value !== void 0 && value !== null)
|
|
19
|
+
if (value !== void 0 && value !== null) mutableResult[key] = value;
|
|
19
20
|
}
|
|
20
21
|
return result;
|
|
21
22
|
}
|
|
22
23
|
/**
|
|
23
|
-
* Returns whether a JSON Schema fragment accepts `null`.
|
|
24
|
-
*
|
|
25
|
-
* @remarks
|
|
26
|
-
* This is true if the schema has `nullable: true` or if its `type` includes `"null"`.
|
|
27
|
-
*
|
|
28
|
-
* @param schema - The JSON Schema fragment to check.
|
|
29
|
-
* @returns `true` if the schema accepts `null`, otherwise `false`.
|
|
30
|
-
*/
|
|
31
|
-
function isSchemaNullable(schema) {
|
|
32
|
-
if (!(0, _stryke_type_checks_is_set_object.isSetObject)(schema)) return false;
|
|
33
|
-
if (schema.nullable === true) return true;
|
|
34
|
-
return readSchemaTypes(schema).includes("null");
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Returns whether an object property is optional (not listed in `required`).
|
|
38
|
-
*
|
|
39
|
-
* @remarks
|
|
40
|
-
* 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.
|
|
41
|
-
*
|
|
42
|
-
* @param parent - The parent JSON Schema object containing the property.
|
|
43
|
-
* @param propertyName - The name of the property to check for optionality.
|
|
44
|
-
* @returns `true` if the property is optional, otherwise `false`.
|
|
45
|
-
*/
|
|
46
|
-
function isPropertyOptional(parent, propertyName) {
|
|
47
|
-
return !(parent.required ?? []).includes(propertyName) && !isSchemaNullable(parent.properties[propertyName]);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
24
|
* Normalizes the JSON Schema `type` keyword to a string array.
|
|
51
25
|
*
|
|
52
26
|
* @remarks
|
|
@@ -56,8 +30,10 @@ function isPropertyOptional(parent, propertyName) {
|
|
|
56
30
|
* @returns An array of JSON Schema primitive type names defined in the `type` keyword, or an empty array if no valid types are found.
|
|
57
31
|
*/
|
|
58
32
|
function readSchemaTypes(schema) {
|
|
59
|
-
if (
|
|
60
|
-
|
|
33
|
+
if (!(0, _stryke_type_checks_is_set_object.isSetObject)(schema)) return [];
|
|
34
|
+
const objectSchema = schema;
|
|
35
|
+
if (Array.isArray(objectSchema.type)) return objectSchema.type.filter((type) => (0, _stryke_type_checks.isSetString)(type));
|
|
36
|
+
if ((0, _stryke_type_checks.isSetString)(objectSchema.type) && objectSchema.type !== "object" && objectSchema.type !== "array") return [objectSchema.type];
|
|
61
37
|
return [];
|
|
62
38
|
}
|
|
63
39
|
/**
|
|
@@ -72,8 +48,6 @@ function getPrimarySchemaType(schema) {
|
|
|
72
48
|
}
|
|
73
49
|
|
|
74
50
|
//#endregion
|
|
75
|
-
exports.
|
|
51
|
+
exports.applyJsonSchemaMetadata = applyJsonSchemaMetadata;
|
|
76
52
|
exports.getPrimarySchemaType = getPrimarySchemaType;
|
|
77
|
-
exports.isPropertyOptional = isPropertyOptional;
|
|
78
|
-
exports.isSchemaNullable = isSchemaNullable;
|
|
79
53
|
exports.readSchemaTypes = readSchemaTypes;
|
package/dist/metadata.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonSchema,
|
|
1
|
+
import { JsonSchema, JsonSchemaMetadataKeywords, JsonSchemaPrimitiveType } from "./types.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/metadata.d.ts
|
|
4
4
|
/**
|
|
@@ -8,28 +8,7 @@ import { JsonSchema, JsonSchemaObject, JsonSchemaPrimitiveType, SchemaMetadata }
|
|
|
8
8
|
* @param metadata - The Powerlines schema metadata to apply.
|
|
9
9
|
* @returns A new JSON Schema fragment with the metadata applied.
|
|
10
10
|
*/
|
|
11
|
-
declare function
|
|
12
|
-
/**
|
|
13
|
-
* Returns whether a JSON Schema fragment accepts `null`.
|
|
14
|
-
*
|
|
15
|
-
* @remarks
|
|
16
|
-
* This is true if the schema has `nullable: true` or if its `type` includes `"null"`.
|
|
17
|
-
*
|
|
18
|
-
* @param schema - The JSON Schema fragment to check.
|
|
19
|
-
* @returns `true` if the schema accepts `null`, otherwise `false`.
|
|
20
|
-
*/
|
|
21
|
-
declare function isSchemaNullable<T = unknown>(schema?: JsonSchema<T>): boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Returns whether an object property is optional (not listed in `required`).
|
|
24
|
-
*
|
|
25
|
-
* @remarks
|
|
26
|
-
* 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.
|
|
27
|
-
*
|
|
28
|
-
* @param parent - The parent JSON Schema object containing the property.
|
|
29
|
-
* @param propertyName - The name of the property to check for optionality.
|
|
30
|
-
* @returns `true` if the property is optional, otherwise `false`.
|
|
31
|
-
*/
|
|
32
|
-
declare function isPropertyOptional<T extends Record<string, any> = Record<string, any>>(parent: JsonSchemaObject<T>, propertyName: string): boolean;
|
|
11
|
+
declare function applyJsonSchemaMetadata(schema: JsonSchema, metadata: JsonSchemaMetadataKeywords | undefined): JsonSchema;
|
|
33
12
|
/**
|
|
34
13
|
* Normalizes the JSON Schema `type` keyword to a string array.
|
|
35
14
|
*
|
|
@@ -39,14 +18,14 @@ declare function isPropertyOptional<T extends Record<string, any> = Record<strin
|
|
|
39
18
|
* @param schema - The JSON Schema fragment to read types from.
|
|
40
19
|
* @returns An array of JSON Schema primitive type names defined in the `type` keyword, or an empty array if no valid types are found.
|
|
41
20
|
*/
|
|
42
|
-
declare function readSchemaTypes
|
|
21
|
+
declare function readSchemaTypes(schema?: JsonSchema): JsonSchemaPrimitiveType[];
|
|
43
22
|
/**
|
|
44
23
|
* Returns the primary non-null JSON Schema type name for a fragment.
|
|
45
24
|
*
|
|
46
25
|
* @param schema - The JSON Schema fragment to check.
|
|
47
26
|
* @returns The primary non-null JSON Schema type name, or `undefined` if none is found.
|
|
48
27
|
*/
|
|
49
|
-
declare function getPrimarySchemaType
|
|
28
|
+
declare function getPrimarySchemaType(schema?: JsonSchema): JsonSchemaPrimitiveType | undefined;
|
|
50
29
|
//#endregion
|
|
51
|
-
export {
|
|
30
|
+
export { applyJsonSchemaMetadata, getPrimarySchemaType, readSchemaTypes };
|
|
52
31
|
//# sourceMappingURL=metadata.d.cts.map
|
package/dist/metadata.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.d.cts","names":[],"sources":["../src/metadata.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"metadata.d.cts","names":[],"sources":["../src/metadata.ts"],"mappings":";;;;;AAuCA;;;;;iBAAgB,uBAAA,CACd,MAAA,EAAQ,UAAA,EACR,QAAA,EAAU,0BAAA,eACT,UAAA;;;;;;;;;AAAU;iBA0BG,eAAA,CACd,MAAA,GAAS,UAAA,GACR,uBAAuB;;;;;;;iBA6BV,oBAAA,CACd,MAAA,GAAS,UAAA,GACR,uBAAuB"}
|
package/dist/metadata.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonSchema,
|
|
1
|
+
import { JsonSchema, JsonSchemaMetadataKeywords, JsonSchemaPrimitiveType } from "./types.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/metadata.d.ts
|
|
4
4
|
/**
|
|
@@ -8,28 +8,7 @@ import { JsonSchema, JsonSchemaObject, JsonSchemaPrimitiveType, SchemaMetadata }
|
|
|
8
8
|
* @param metadata - The Powerlines schema metadata to apply.
|
|
9
9
|
* @returns A new JSON Schema fragment with the metadata applied.
|
|
10
10
|
*/
|
|
11
|
-
declare function
|
|
12
|
-
/**
|
|
13
|
-
* Returns whether a JSON Schema fragment accepts `null`.
|
|
14
|
-
*
|
|
15
|
-
* @remarks
|
|
16
|
-
* This is true if the schema has `nullable: true` or if its `type` includes `"null"`.
|
|
17
|
-
*
|
|
18
|
-
* @param schema - The JSON Schema fragment to check.
|
|
19
|
-
* @returns `true` if the schema accepts `null`, otherwise `false`.
|
|
20
|
-
*/
|
|
21
|
-
declare function isSchemaNullable<T = unknown>(schema?: JsonSchema<T>): boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Returns whether an object property is optional (not listed in `required`).
|
|
24
|
-
*
|
|
25
|
-
* @remarks
|
|
26
|
-
* 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.
|
|
27
|
-
*
|
|
28
|
-
* @param parent - The parent JSON Schema object containing the property.
|
|
29
|
-
* @param propertyName - The name of the property to check for optionality.
|
|
30
|
-
* @returns `true` if the property is optional, otherwise `false`.
|
|
31
|
-
*/
|
|
32
|
-
declare function isPropertyOptional<T extends Record<string, any> = Record<string, any>>(parent: JsonSchemaObject<T>, propertyName: string): boolean;
|
|
11
|
+
declare function applyJsonSchemaMetadata(schema: JsonSchema, metadata: JsonSchemaMetadataKeywords | undefined): JsonSchema;
|
|
33
12
|
/**
|
|
34
13
|
* Normalizes the JSON Schema `type` keyword to a string array.
|
|
35
14
|
*
|
|
@@ -39,14 +18,14 @@ declare function isPropertyOptional<T extends Record<string, any> = Record<strin
|
|
|
39
18
|
* @param schema - The JSON Schema fragment to read types from.
|
|
40
19
|
* @returns An array of JSON Schema primitive type names defined in the `type` keyword, or an empty array if no valid types are found.
|
|
41
20
|
*/
|
|
42
|
-
declare function readSchemaTypes
|
|
21
|
+
declare function readSchemaTypes(schema?: JsonSchema): JsonSchemaPrimitiveType[];
|
|
43
22
|
/**
|
|
44
23
|
* Returns the primary non-null JSON Schema type name for a fragment.
|
|
45
24
|
*
|
|
46
25
|
* @param schema - The JSON Schema fragment to check.
|
|
47
26
|
* @returns The primary non-null JSON Schema type name, or `undefined` if none is found.
|
|
48
27
|
*/
|
|
49
|
-
declare function getPrimarySchemaType
|
|
28
|
+
declare function getPrimarySchemaType(schema?: JsonSchema): JsonSchemaPrimitiveType | undefined;
|
|
50
29
|
//#endregion
|
|
51
|
-
export {
|
|
30
|
+
export { applyJsonSchemaMetadata, getPrimarySchemaType, readSchemaTypes };
|
|
52
31
|
//# sourceMappingURL=metadata.d.mts.map
|
package/dist/metadata.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.d.mts","names":[],"sources":["../src/metadata.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"metadata.d.mts","names":[],"sources":["../src/metadata.ts"],"mappings":";;;;;AAuCA;;;;;iBAAgB,uBAAA,CACd,MAAA,EAAQ,UAAA,EACR,QAAA,EAAU,0BAAA,eACT,UAAA;;;;;;;;;AAAU;iBA0BG,eAAA,CACd,MAAA,GAAS,UAAA,GACR,uBAAuB;;;;;;;iBA6BV,oBAAA,CACd,MAAA,GAAS,UAAA,GACR,uBAAuB"}
|