@powerlines/schema 0.11.63 → 0.11.66
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/helpers.cjs +2 -2
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +2 -2
- package/dist/helpers.mjs.map +1 -1
- package/package.json +5 -5
package/dist/helpers.cjs
CHANGED
|
@@ -19,7 +19,7 @@ let _stryke_path_find = require("@stryke/path/find");
|
|
|
19
19
|
*/
|
|
20
20
|
function getJsonSchema(input) {
|
|
21
21
|
const schema = require_type_checks.isSchema(input) ? input.schema : input;
|
|
22
|
-
if (!require_type_checks.isJsonSchema(schema)) throw new TypeError(
|
|
22
|
+
if (!require_type_checks.isJsonSchema(schema)) throw new TypeError(`The provided input is not a valid JSON Schema: ${JSON.stringify(schema, null, 2)}`);
|
|
23
23
|
return schema;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
@@ -34,7 +34,7 @@ function getJsonSchema(input) {
|
|
|
34
34
|
*/
|
|
35
35
|
function getJsonSchemaObject(input) {
|
|
36
36
|
const schema = getJsonSchema(input);
|
|
37
|
-
if (!require_type_checks.isJsonSchemaObject(schema)) throw new TypeError(
|
|
37
|
+
if (!require_type_checks.isJsonSchemaObject(schema)) throw new TypeError(`The provided input is not a valid JSON Schema object: ${JSON.stringify(schema, null, 2)}`);
|
|
38
38
|
return schema;
|
|
39
39
|
}
|
|
40
40
|
/**
|
package/dist/helpers.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.cts","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;
|
|
1
|
+
{"version":3,"file":"helpers.d.cts","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;iBAyBrD,mBAAA,CACd,KAAA,EAAO,MAAA,GAAS,UAAA,GACf,gBAAA;;;;;;;;;;iBAoBa,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.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;iBAyBrD,mBAAA,CACd,KAAA,EAAO,MAAA,GAAS,UAAA,GACf,gBAAA;;;;;;;;;;iBAoBa,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
|
@@ -19,7 +19,7 @@ import { findFileExtensionSafe } from "@stryke/path/find";
|
|
|
19
19
|
*/
|
|
20
20
|
function getJsonSchema(input) {
|
|
21
21
|
const schema = isSchema(input) ? input.schema : input;
|
|
22
|
-
if (!isJsonSchema(schema)) throw new TypeError(
|
|
22
|
+
if (!isJsonSchema(schema)) throw new TypeError(`The provided input is not a valid JSON Schema: ${JSON.stringify(schema, null, 2)}`);
|
|
23
23
|
return schema;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
@@ -34,7 +34,7 @@ function getJsonSchema(input) {
|
|
|
34
34
|
*/
|
|
35
35
|
function getJsonSchemaObject(input) {
|
|
36
36
|
const schema = getJsonSchema(input);
|
|
37
|
-
if (!isJsonSchemaObject(schema)) throw new TypeError(
|
|
37
|
+
if (!isJsonSchemaObject(schema)) throw new TypeError(`The provided input is not a valid JSON Schema object: ${JSON.stringify(schema, null, 2)}`);
|
|
38
38
|
return schema;
|
|
39
39
|
}
|
|
40
40
|
/**
|
package/dist/helpers.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,KAI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T,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"}
|
|
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(\n `The provided input is not a valid JSON Schema: ${JSON.stringify(\n schema,\n null,\n 2\n )}`\n );\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(\n `The provided input is not a valid JSON Schema object: ${JSON.stringify(schema, null, 2)}`\n );\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,UACR,kDAAkD,KAAK,UACrD,QACA,MACA,CACF,GACF;CAGF,OAAO;AACT;;;;;;;;;;;A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B,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerlines/schema",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.66",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A package containing a Powerlines plugin to assist in developing other Powerlines plugins.",
|
|
6
6
|
"keywords": [
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
"typings": "dist/index.d.mts",
|
|
60
60
|
"files": ["dist"],
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@powerlines/core": "^0.48.
|
|
63
|
-
"@powerlines/deepkit": "^0.9.
|
|
64
|
-
"@powerlines/unplugin": "^0.0.
|
|
62
|
+
"@powerlines/core": "^0.48.24",
|
|
63
|
+
"@powerlines/deepkit": "^0.9.56",
|
|
64
|
+
"@powerlines/unplugin": "^0.0.72",
|
|
65
65
|
"@standard-schema/spec": "^1.1.0",
|
|
66
66
|
"@stryke/convert": "^0.7.10",
|
|
67
67
|
"@stryke/hash": "^0.13.32",
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
"zod": { "optional": true }
|
|
97
97
|
},
|
|
98
98
|
"publishConfig": { "access": "public" },
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "ba29330277e0d8be78bdad08d260ddae06a95e81"
|
|
100
100
|
}
|