@powerlines/schema 0.11.40 → 0.11.42
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 +0 -1
- package/dist/codegen.cjs +12 -19
- package/dist/codegen.d.cts +7 -2
- package/dist/codegen.d.cts.map +1 -1
- package/dist/codegen.d.mts +7 -2
- package/dist/codegen.d.mts.map +1 -1
- package/dist/codegen.mjs +13 -18
- package/dist/codegen.mjs.map +1 -1
- package/dist/constants.cjs +0 -2
- package/dist/constants.d.cts +1 -1
- package/dist/constants.d.mts +1 -1
- package/dist/constants.mjs +0 -1
- package/dist/constants.mjs.map +1 -1
- package/dist/extract.cjs +23 -9
- package/dist/extract.d.cts +2 -3
- package/dist/extract.d.cts.map +1 -1
- package/dist/extract.d.mts +2 -3
- package/dist/extract.d.mts.map +1 -1
- package/dist/extract.mjs +28 -12
- package/dist/extract.mjs.map +1 -1
- package/dist/helpers.cjs +0 -1
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.d.cts +30 -4
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +30 -4
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3 -3
- package/dist/metadata.cjs +1 -2
- package/dist/metadata.d.cts.map +1 -1
- package/dist/metadata.d.mts.map +1 -1
- package/dist/metadata.mjs +1 -1
- package/dist/metadata.mjs.map +1 -1
- package/dist/persistence.cjs +0 -1
- package/dist/reflection.cjs +0 -1
- package/dist/resolve.cjs +0 -1
- package/dist/type-checks.cjs +27 -2
- package/dist/type-checks.d.cts +17 -1
- package/dist/type-checks.d.cts.map +1 -1
- package/dist/type-checks.d.mts +17 -1
- package/dist/type-checks.d.mts.map +1 -1
- package/dist/type-checks.mjs +25 -1
- package/dist/type-checks.mjs.map +1 -1
- package/dist/types.d.cts +43 -28
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +44 -29
- package/dist/types.d.mts.map +1 -1
- package/dist/validate.cjs +27 -0
- package/dist/validate.mjs +25 -0
- package/dist/validate.mjs.map +1 -0
- package/package.json +20 -49
- package/dist/types.cjs +0 -0
- package/dist/types.mjs +0 -1
package/dist/type-checks.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-checks.mjs","names":[],"sources":["../src/type-checks.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 { isJsonSchemaObjectType } from \"@stryke/json\";\nimport {\n isFunction,\n isObject,\n isSetObject,\n isSetString\n} from \"@stryke/type-checks\";\nimport {\n InputObject as UntypedInputObject,\n Schema as UntypedSchema\n} from \"untyped\";\nimport { JSON_SCHEMA_DATA_TYPES } from \"./constants\";\nimport { ExtractedSchema, JsonSchema, JsonSchemaObject, Schema } from \"./types\";\n\ntype JsonSchemaDataType = (typeof JSON_SCHEMA_DATA_TYPES)[number];\n\nconst JSON_SCHEMA_DATA_TYPE_SET = new Set<JsonSchemaDataType>(\n JSON_SCHEMA_DATA_TYPES\n);\n\ntype SchemaKeywordValidator = (value: unknown) => boolean;\n\nconst isSetNumber = (value: unknown): value is number =>\n typeof value === \"number\" && Number.isFinite(value);\n\nconst isSetBoolean = (value: unknown): value is boolean =>\n typeof value === \"boolean\";\n\nconst isNonNegativeInteger = (value: unknown): value is number =>\n Number.isInteger(value) && (value as number) >= 0;\n\nconst isSchemaLikeValue = (value: unknown): boolean =>\n isSetObject(value) || isSetBoolean(value);\n\nconst isStringArray = (value: unknown): value is string[] =>\n Array.isArray(value) && value.every(item => isSetString(item));\n\nconst isRecordOfStringArrays = (\n value: unknown\n): value is Record<string, string[]> =>\n isSetObject(value) && Object.values(value).every(item => isStringArray(item));\n\nconst TYPE_KEYWORD_VALIDATORS: Record<\n JsonSchemaDataType,\n Record<string, SchemaKeywordValidator>\n> = {\n string: {\n minLength: isNonNegativeInteger,\n maxLength: isNonNegativeInteger,\n pattern: isSetString,\n format: isSetString,\n contentEncoding: isSetString,\n contentMediaType: isSetString\n },\n number: {\n minimum: isSetNumber,\n maximum: isSetNumber,\n exclusiveMinimum: isSetNumber,\n exclusiveMaximum: isSetNumber,\n multipleOf: isSetNumber\n },\n integer: {\n minimum: isSetNumber,\n maximum: isSetNumber,\n exclusiveMinimum: isSetNumber,\n exclusiveMaximum: isSetNumber,\n multipleOf: isSetNumber\n },\n boolean: {},\n array: {\n items: isSchemaLikeValue,\n prefixItems: Array.isArray,\n contains: isSchemaLikeValue,\n minItems: isNonNegativeInteger,\n maxItems: isNonNegativeInteger,\n uniqueItems: isSetBoolean,\n minContains: isNonNegativeInteger,\n maxContains: isNonNegativeInteger\n },\n object: {\n properties: isSetObject,\n patternProperties: isSetObject,\n additionalProperties: isSchemaLikeValue,\n required: isStringArray,\n minProperties: isNonNegativeInteger,\n maxProperties: isNonNegativeInteger,\n dependentRequired: isRecordOfStringArrays,\n dependentSchemas: isSetObject,\n propertyNames: isSchemaLikeValue,\n unevaluatedProperties: isSchemaLikeValue\n },\n null: {}\n};\n\n/**\n * Type guard for JSON Schema types.\n *\n * @remarks\n * This function checks if the input is a JSON Schema type, which is defined as having a `type` property or a `$ref` property. This is used to determine if a given input conforms to the structure of a JSON Schema definition that includes type information.\n *\n * @param input - The value to check.\n * @returns True if the input is a JSON Schema type, false otherwise.\n */\nexport function isJsonSchema<T = unknown>(\n input: unknown\n): input is JsonSchema<T> {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n if (\"$ref\" in schema && isSetString(schema.$ref)) {\n return true;\n }\n\n if (!(\"type\" in schema)) {\n return false;\n }\n\n const schemaTypes: JsonSchemaDataType[] = [];\n\n if (isSetString(schema.type)) {\n if (!JSON_SCHEMA_DATA_TYPE_SET.has(schema.type as JsonSchemaDataType)) {\n return false;\n }\n\n schemaTypes.push(schema.type as JsonSchemaDataType);\n } else if (Array.isArray(schema.type) && schema.type.length > 0) {\n if (\n !schema.type.every(\n schemaType =>\n isSetString(schemaType) &&\n JSON_SCHEMA_DATA_TYPE_SET.has(schemaType as JsonSchemaDataType)\n ) ||\n new Set(schema.type).size !== schema.type.length\n ) {\n return false;\n }\n\n schemaTypes.push(...(schema.type as JsonSchemaDataType[]));\n } else {\n return false;\n }\n\n const typeKeywordValidators = schemaTypes.flatMap(schemaType =>\n Object.entries(TYPE_KEYWORD_VALIDATORS[schemaType])\n );\n\n for (const [keyword, validator] of typeKeywordValidators) {\n if (keyword in schema && !validator(schema[keyword])) {\n return false;\n }\n }\n\n if (\n \"minItems\" in schema &&\n \"maxItems\" in schema &&\n isNonNegativeInteger(schema.minItems) &&\n isNonNegativeInteger(schema.maxItems) &&\n schema.minItems > schema.maxItems\n ) {\n return false;\n }\n\n if (\n \"minLength\" in schema &&\n \"maxLength\" in schema &&\n isNonNegativeInteger(schema.minLength) &&\n isNonNegativeInteger(schema.maxLength) &&\n schema.minLength > schema.maxLength\n ) {\n return false;\n }\n\n if (\n \"minProperties\" in schema &&\n \"maxProperties\" in schema &&\n isNonNegativeInteger(schema.minProperties) &&\n isNonNegativeInteger(schema.maxProperties) &&\n schema.minProperties > schema.maxProperties\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Type guard for JSON Schema object forms.\n *\n * @remarks\n * This function checks if the input is a JSON Schema object type, which is defined as having a `type` property equal to \"object\" or having a `properties` object. This is used to determine if a given input conforms to the structure of a JSON Schema object definition.\n *\n * @param input - The value to check.\n * @returns True if the input is a JSON Schema object type, false otherwise.\n */\nexport function isJsonSchemaObject<\n T extends Record<string, any> = Record<string, any>\n>(input: unknown): input is JsonSchemaObject<T> {\n return (\n isJsonSchemaObjectType(input) &&\n (input.type === \"object\" || isObject(input.properties))\n );\n}\n\n/**\n * Type guard for JSON Schemas that only accept `null`.\n *\n * @remarks\n * This function checks if the input is a JSON Schema that exclusively accepts the `null` type. It verifies that the input is a valid JSON Schema and that its `type` property is set to \"null\". This is useful for identifying schemas that are specifically designed to allow only `null` values.\n *\n * @param input - The value to check.\n * @returns True if the input is a JSON Schema that only accepts `null`, false otherwise.\n */\nexport function isNullOnlyJsonSchema(\n input: unknown\n): input is JsonSchema<null> {\n return isJsonSchema(input) && input.type === \"null\";\n}\n\n/**\n * Type guard for untyped schema objects.\n *\n * @remarks\n * This function checks if the input is an untyped schema object, which is defined as having certain properties that are commonly found in untyped schema definitions. This includes properties such as `id`, `title`, `description`, `$schema`, `tsType`, `markdownType`, `type`, `required`, `tags`, `args`, `properties`, and `resolve`. The function verifies that these properties, if present, conform to the expected types (e.g., strings for certain properties, arrays for others). This type guard is used to determine if a given input can be treated as an untyped schema object within the context of the Powerlines schema system.\n *\n * @param input - The value to check.\n * @returns True if the input is an untyped schema object, false otherwise.\n */\nexport function isUntypedSchema(input: unknown): input is UntypedSchema {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (\"id\" in schema && !isSetString(schema.id)) {\n return false;\n }\n if (\"title\" in schema && !isSetString(schema.title)) {\n return false;\n }\n if (\"description\" in schema && !isSetString(schema.description)) {\n return false;\n }\n if (\"$schema\" in schema && !isSetString(schema.$schema)) {\n return false;\n }\n if (\"tsType\" in schema && !isSetString(schema.tsType)) {\n return false;\n }\n if (\"markdownType\" in schema && !isSetString(schema.markdownType)) {\n return false;\n }\n if (\n \"type\" in schema &&\n !isSetString(schema.type) &&\n !Array.isArray(schema.type)\n ) {\n return false;\n }\n if (\"required\" in schema && !Array.isArray(schema.required)) {\n return false;\n }\n if (\"tags\" in schema && !Array.isArray(schema.tags)) {\n return false;\n }\n if (\"args\" in schema && !Array.isArray(schema.args)) {\n return false;\n }\n if (\"properties\" in schema && !isSetObject(schema.properties)) {\n return false;\n }\n if (\"resolve\" in schema && !isFunction(schema.resolve)) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Type guard for untyped input objects.\n *\n * @remarks\n * This function checks if the input is an untyped input object, which is defined as having certain properties that are commonly found in untyped input definitions. This includes properties such as `$schema` and `$resolve`. The function verifies that these properties, if present, conform to the expected types (e.g., objects for `$schema`, functions for `$resolve`). This type guard is used to determine if a given input can be treated as an untyped input object within the context of the Powerlines schema system.\n *\n * @param input - The value to check.\n * @returns True if the input is an untyped input object, false otherwise.\n */\nexport function isUntypedInput(input: unknown): input is UntypedInputObject {\n if (!isSetObject(input)) {\n return false;\n }\n\n const inputObject = input as Record<string, unknown>;\n if (\"$schema\" in inputObject && !isUntypedSchema(inputObject.$schema)) {\n return false;\n }\n if (\"$resolve\" in inputObject && !isFunction(inputObject.$resolve)) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Type guard for Powerlines Schema objects.\n *\n * @param input - The value to check.\n * @returns True if the input is a Powerlines Schema object, false otherwise.\n */\nexport function isSchema<T = unknown>(input: unknown): input is Schema<T> {\n return (\n isSetObject(input) &&\n \"schema\" in input &&\n isJsonSchema(input.schema) &&\n \"variant\" in input &&\n isSetString(input.variant) &&\n \"hash\" in input &&\n isSetString(input.hash)\n );\n}\n\nexport function isExtractedSchema<T = unknown>(\n input: unknown\n): input is ExtractedSchema<T> {\n return (\n isSchema<T>(input) &&\n \"source\" in input &&\n isSetObject(input.source) &&\n \"schema\" in input.source &&\n \"variant\" in input.source &&\n isSetString(input.source.variant)\n );\n}\n"],"mappings":";;;;;AAkCA,MAAM,4BAA4B,IAAI,IACpC,sBACF;AAIA,MAAM,eAAe,UACnB,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK;AAEpD,MAAM,gBAAgB,UACpB,OAAO,UAAU;AAEnB,MAAM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
|
1
|
+
{"version":3,"file":"type-checks.mjs","names":[],"sources":["../src/type-checks.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 type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { isJsonSchemaObjectType } from \"@stryke/json\";\nimport {\n isFunction,\n isObject,\n isSetObject,\n isSetString\n} from \"@stryke/type-checks\";\nimport {\n InputObject as UntypedInputObject,\n Schema as UntypedSchema\n} from \"untyped\";\nimport type { BaseSchema } from \"valibot\";\nimport { JSON_SCHEMA_DATA_TYPES } from \"./constants\";\nimport { ExtractedSchema, JsonSchema, JsonSchemaObject, Schema } from \"./types\";\n\ntype JsonSchemaDataType = (typeof JSON_SCHEMA_DATA_TYPES)[number];\n\nconst JSON_SCHEMA_DATA_TYPE_SET = new Set<JsonSchemaDataType>(\n JSON_SCHEMA_DATA_TYPES\n);\n\ntype SchemaKeywordValidator = (value: unknown) => boolean;\n\nconst isSetNumber = (value: unknown): value is number =>\n typeof value === \"number\" && Number.isFinite(value);\n\nconst isSetBoolean = (value: unknown): value is boolean =>\n typeof value === \"boolean\";\n\nconst isNonNegativeInteger = (value: unknown): value is number =>\n Number.isInteger(value) && (value as number) >= 0;\n\nconst isSchemaLikeValue = (value: unknown): boolean =>\n isSetObject(value) || isSetBoolean(value);\n\nconst isStringArray = (value: unknown): value is string[] =>\n Array.isArray(value) && value.every(item => isSetString(item));\n\nconst isRecordOfStringArrays = (\n value: unknown\n): value is Record<string, string[]> =>\n isSetObject(value) && Object.values(value).every(item => isStringArray(item));\n\nconst TYPE_KEYWORD_VALIDATORS: Record<\n JsonSchemaDataType,\n Record<string, SchemaKeywordValidator>\n> = {\n string: {\n minLength: isNonNegativeInteger,\n maxLength: isNonNegativeInteger,\n pattern: isSetString,\n format: isSetString,\n contentEncoding: isSetString,\n contentMediaType: isSetString\n },\n number: {\n minimum: isSetNumber,\n maximum: isSetNumber,\n exclusiveMinimum: isSetNumber,\n exclusiveMaximum: isSetNumber,\n multipleOf: isSetNumber\n },\n integer: {\n minimum: isSetNumber,\n maximum: isSetNumber,\n exclusiveMinimum: isSetNumber,\n exclusiveMaximum: isSetNumber,\n multipleOf: isSetNumber\n },\n boolean: {},\n array: {\n items: isSchemaLikeValue,\n prefixItems: Array.isArray,\n contains: isSchemaLikeValue,\n minItems: isNonNegativeInteger,\n maxItems: isNonNegativeInteger,\n uniqueItems: isSetBoolean,\n minContains: isNonNegativeInteger,\n maxContains: isNonNegativeInteger\n },\n object: {\n properties: isSetObject,\n patternProperties: isSetObject,\n additionalProperties: isSchemaLikeValue,\n required: isStringArray,\n minProperties: isNonNegativeInteger,\n maxProperties: isNonNegativeInteger,\n dependentRequired: isRecordOfStringArrays,\n dependentSchemas: isSetObject,\n propertyNames: isSchemaLikeValue,\n unevaluatedProperties: isSchemaLikeValue\n },\n null: {}\n};\n\n/**\n * Type guard for Standard Schema V1 objects.\n *\n * @param input - The value to check.\n * @returns True if the input is a Standard Schema V1 object, false otherwise.\n */\nexport function isStandardSchema(input: unknown): input is StandardSchemaV1 {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (!isSetObject(schema[\"~standard\"])) {\n return false;\n }\n\n const standard = schema[\"~standard\"] as Record<string, unknown>;\n\n return standard.version === 1 && isFunction(standard.validate);\n}\n\n/**\n * Type guard for Valibot BaseSchema objects.\n *\n * @param input - The value to check.\n * @returns True if the input is a Valibot BaseSchema, false otherwise.\n */\nexport function isValibotSchema(\n input: unknown\n): input is BaseSchema<any, any, any> {\n if (!isSetObject(input) || !isStandardSchema(input)) {\n return false;\n }\n\n const schema = input as unknown as Record<string, unknown>;\n\n return (\n schema.kind === \"schema\" &&\n isSetString(schema.type) &&\n isSetBoolean(schema.async) &&\n isFunction(schema.reference) &&\n isSetString(schema.expects) &&\n isFunction(schema[\"~run\"])\n );\n}\n\n/**\n * Type guard for JSON Schema types.\n *\n * @remarks\n * This function checks if the input is a JSON Schema type, which is defined as having a `type` property or a `$ref` property. This is used to determine if a given input conforms to the structure of a JSON Schema definition that includes type information.\n *\n * @param input - The value to check.\n * @returns True if the input is a JSON Schema type, false otherwise.\n */\nexport function isJsonSchema<T = unknown>(\n input: unknown\n): input is JsonSchema<T> {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n if (\"$ref\" in schema && isSetString(schema.$ref)) {\n return true;\n }\n\n if (!(\"type\" in schema)) {\n return false;\n }\n\n const schemaTypes: JsonSchemaDataType[] = [];\n\n if (isSetString(schema.type)) {\n if (!JSON_SCHEMA_DATA_TYPE_SET.has(schema.type as JsonSchemaDataType)) {\n return false;\n }\n\n schemaTypes.push(schema.type as JsonSchemaDataType);\n } else if (Array.isArray(schema.type) && schema.type.length > 0) {\n if (\n !schema.type.every(\n schemaType =>\n isSetString(schemaType) &&\n JSON_SCHEMA_DATA_TYPE_SET.has(schemaType as JsonSchemaDataType)\n ) ||\n new Set(schema.type).size !== schema.type.length\n ) {\n return false;\n }\n\n schemaTypes.push(...(schema.type as JsonSchemaDataType[]));\n } else {\n return false;\n }\n\n const typeKeywordValidators = schemaTypes.flatMap(schemaType =>\n Object.entries(TYPE_KEYWORD_VALIDATORS[schemaType])\n );\n\n for (const [keyword, validator] of typeKeywordValidators) {\n if (keyword in schema && !validator(schema[keyword])) {\n return false;\n }\n }\n\n if (\n \"minItems\" in schema &&\n \"maxItems\" in schema &&\n isNonNegativeInteger(schema.minItems) &&\n isNonNegativeInteger(schema.maxItems) &&\n schema.minItems > schema.maxItems\n ) {\n return false;\n }\n\n if (\n \"minLength\" in schema &&\n \"maxLength\" in schema &&\n isNonNegativeInteger(schema.minLength) &&\n isNonNegativeInteger(schema.maxLength) &&\n schema.minLength > schema.maxLength\n ) {\n return false;\n }\n\n if (\n \"minProperties\" in schema &&\n \"maxProperties\" in schema &&\n isNonNegativeInteger(schema.minProperties) &&\n isNonNegativeInteger(schema.maxProperties) &&\n schema.minProperties > schema.maxProperties\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Type guard for JSON Schema object forms.\n *\n * @remarks\n * This function checks if the input is a JSON Schema object type, which is defined as having a `type` property equal to \"object\" or having a `properties` object. This is used to determine if a given input conforms to the structure of a JSON Schema object definition.\n *\n * @param input - The value to check.\n * @returns True if the input is a JSON Schema object type, false otherwise.\n */\nexport function isJsonSchemaObject<\n T extends Record<string, any> = Record<string, any>\n>(input: unknown): input is JsonSchemaObject<T> {\n return (\n isJsonSchemaObjectType(input) &&\n (input.type === \"object\" || isObject(input.properties))\n );\n}\n\n/**\n * Type guard for JSON Schemas that only accept `null`.\n *\n * @remarks\n * This function checks if the input is a JSON Schema that exclusively accepts the `null` type. It verifies that the input is a valid JSON Schema and that its `type` property is set to \"null\". This is useful for identifying schemas that are specifically designed to allow only `null` values.\n *\n * @param input - The value to check.\n * @returns True if the input is a JSON Schema that only accepts `null`, false otherwise.\n */\nexport function isNullOnlyJsonSchema(\n input: unknown\n): input is JsonSchema<null> {\n return isJsonSchema<null>(input) && input.type === \"null\";\n}\n\n/**\n * Type guard for untyped schema objects.\n *\n * @remarks\n * This function checks if the input is an untyped schema object, which is defined as having certain properties that are commonly found in untyped schema definitions. This includes properties such as `id`, `title`, `description`, `$schema`, `tsType`, `markdownType`, `type`, `required`, `tags`, `args`, `properties`, and `resolve`. The function verifies that these properties, if present, conform to the expected types (e.g., strings for certain properties, arrays for others). This type guard is used to determine if a given input can be treated as an untyped schema object within the context of the Powerlines schema system.\n *\n * @param input - The value to check.\n * @returns True if the input is an untyped schema object, false otherwise.\n */\nexport function isUntypedSchema(input: unknown): input is UntypedSchema {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (\"id\" in schema && !isSetString(schema.id)) {\n return false;\n }\n if (\"title\" in schema && !isSetString(schema.title)) {\n return false;\n }\n if (\"description\" in schema && !isSetString(schema.description)) {\n return false;\n }\n if (\"$schema\" in schema && !isSetString(schema.$schema)) {\n return false;\n }\n if (\"tsType\" in schema && !isSetString(schema.tsType)) {\n return false;\n }\n if (\"markdownType\" in schema && !isSetString(schema.markdownType)) {\n return false;\n }\n if (\n \"type\" in schema &&\n !isSetString(schema.type) &&\n !Array.isArray(schema.type)\n ) {\n return false;\n }\n if (\"required\" in schema && !Array.isArray(schema.required)) {\n return false;\n }\n if (\"tags\" in schema && !Array.isArray(schema.tags)) {\n return false;\n }\n if (\"args\" in schema && !Array.isArray(schema.args)) {\n return false;\n }\n if (\"properties\" in schema && !isSetObject(schema.properties)) {\n return false;\n }\n if (\"resolve\" in schema && !isFunction(schema.resolve)) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Type guard for untyped input objects.\n *\n * @remarks\n * This function checks if the input is an untyped input object, which is defined as having certain properties that are commonly found in untyped input definitions. This includes properties such as `$schema` and `$resolve`. The function verifies that these properties, if present, conform to the expected types (e.g., objects for `$schema`, functions for `$resolve`). This type guard is used to determine if a given input can be treated as an untyped input object within the context of the Powerlines schema system.\n *\n * @param input - The value to check.\n * @returns True if the input is an untyped input object, false otherwise.\n */\nexport function isUntypedInput(input: unknown): input is UntypedInputObject {\n if (!isSetObject(input)) {\n return false;\n }\n\n const inputObject = input as Record<string, unknown>;\n if (\"$schema\" in inputObject && !isUntypedSchema(inputObject.$schema)) {\n return false;\n }\n if (\"$resolve\" in inputObject && !isFunction(inputObject.$resolve)) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Type guard for Powerlines Schema objects.\n *\n * @param input - The value to check.\n * @returns True if the input is a Powerlines Schema object, false otherwise.\n */\nexport function isSchema<T = unknown>(input: unknown): input is Schema<T> {\n return (\n isSetObject(input) &&\n \"schema\" in input &&\n isJsonSchema(input.schema) &&\n \"variant\" in input &&\n isSetString(input.variant) &&\n \"hash\" in input &&\n isSetString(input.hash)\n );\n}\n\nexport function isExtractedSchema<T = unknown>(\n input: unknown\n): input is ExtractedSchema<T> {\n return (\n isSchema<T>(input) &&\n \"source\" in input &&\n isSetObject(input.source) &&\n \"schema\" in input.source &&\n \"variant\" in input.source &&\n isSetString(input.source.variant)\n );\n}\n"],"mappings":";;;;;AAoCA,MAAM,4BAA4B,IAAI,IACpC,sBACF;AAIA,MAAM,eAAe,UACnB,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK;AAEpD,MAAM,gBAAgB,UACpB,OAAO,UAAU;AAEnB,MAAM,wBAAwB,UAC5B,OAAO,UAAU,KAAK,KAAM,SAAoB;AAElD,MAAM,qBAAqB,UACzB,YAAY,KAAK,KAAK,aAAa,KAAK;AAE1C,MAAM,iBAAiB,UACrB,MAAM,QAAQ,KAAK,KAAK,MAAM,OAAM,SAAQ,YAAY,IAAI,CAAC;AAE/D,MAAM,0BACJ,UAEA,YAAY,KAAK,KAAK,OAAO,OAAO,KAAK,EAAE,OAAM,SAAQ,cAAc,IAAI,CAAC;AAE9E,MAAM,0BAGF;CACF,QAAQ;EACN,WAAW;EACX,WAAW;EACX,SAAS;EACT,QAAQ;EACR,iBAAiB;EACjB,kBAAkB;CACpB;CACA,QAAQ;EACN,SAAS;EACT,SAAS;EACT,kBAAkB;EAClB,kBAAkB;EAClB,YAAY;CACd;CACA,SAAS;EACP,SAAS;EACT,SAAS;EACT,kBAAkB;EAClB,kBAAkB;EAClB,YAAY;CACd;CACA,SAAS,CAAC;CACV,OAAO;EACL,OAAO;EACP,aAAa,MAAM;EACnB,UAAU;EACV,UAAU;EACV,UAAU;EACV,aAAa;EACb,aAAa;EACb,aAAa;CACf;CACA,QAAQ;EACN,YAAY;EACZ,mBAAmB;EACnB,sBAAsB;EACtB,UAAU;EACV,eAAe;E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AI,KACxB,CAAC,MAAM,QAAQ,OAAO,IAAI,GAE1B,OAAO;CAET,IAAI,cAAc,UAAU,CAAC,MAAM,QAAQ,OAAO,QAAQ,GACxD,OAAO;CAET,IAAI,UAAU,UAAU,CAAC,MAAM,QAAQ,OAAO,IAAI,GAChD,OAAO;CAET,IAAI,UAAU,UAAU,CAAC,MAAM,QAAQ,OAAO,IAAI,GAChD,OAAO;CAET,IAAI,gBAAgB,UAAU,CAAC,YAAY,OAAO,UAAU,GAC1D,OAAO;CAET,IAAI,aAAa,UAAU,CAAC,WAAW,OAAO,OAAO,GACnD,OAAO;CAGT,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,eAAe,OAA6C;CAC1E,IAAI,CAAC,YAAY,KAAK,GACpB,OAAO;CAGT,MAAM,cAAc;CACpB,IAAI,aAAa,eAAe,CAAC,gBAAgB,YAAY,OAAO,GAClE,OAAO;CAET,IAAI,cAAc,eAAe,CAAC,WAAW,YAAY,QAAQ,GAC/D,OAAO;CAGT,OAAO;AACT;;;;;;;AAQA,SAAgB,SAAsB,OAAoC;CACxE,OACE,YAAY,KAAK,KACjB,YAAY,SACZ,aAAa,MAAM,MAAM,KACzB,aAAa,SACb,YAAY,MAAM,OAAO,KACzB,UAAU,SACV,YAAY,MAAM,IAAI;AAE1B;AAEA,SAAgB,kBACd,OAC6B;CAC7B,OACE,SAAY,KAAK,KACjB,YAAY,SACZ,YAAY,MAAM,MAAM,KACxB,YAAY,MAAM,UAClB,aAAa,MAAM,UACnB,YAAY,MAAM,OAAO,OAAO;AAEpC"}
|
package/dist/types.d.cts
CHANGED
|
@@ -2,12 +2,14 @@ import { Type } from "@powerlines/deepkit/vendor/type";
|
|
|
2
2
|
import { StandardJSONSchemaV1 } from "@standard-schema/spec";
|
|
3
3
|
import { TypeDefinition } from "@stryke/types/configuration";
|
|
4
4
|
import { FormatName } from "ajv-formats/dist/formats.js";
|
|
5
|
-
import { InputObject, Schema
|
|
5
|
+
import { InputObject, Schema } from "untyped";
|
|
6
|
+
import { BaseIssue, BaseSchema } from "valibot";
|
|
6
7
|
import * as z3 from "zod/v3";
|
|
7
8
|
|
|
8
9
|
//#region src/types.d.ts
|
|
9
10
|
type UntypedInputObject = InputObject;
|
|
10
|
-
type UntypedSchema = Schema
|
|
11
|
+
type UntypedSchema = Schema;
|
|
12
|
+
type ValibotSchema<TInput = unknown, TOutput = unknown, TIssue extends BaseIssue<unknown> = BaseIssue<unknown>> = BaseSchema<TInput, TOutput, TIssue>;
|
|
11
13
|
/**
|
|
12
14
|
* JSON Schema primitive type names used by {@link stringifyType}.
|
|
13
15
|
*/
|
|
@@ -55,11 +57,11 @@ interface StringKeywords {
|
|
|
55
57
|
type Known = {
|
|
56
58
|
[key: string]: Known;
|
|
57
59
|
} | [Known, ...Known[]] | Known[] | number | string | boolean | null;
|
|
58
|
-
type UncheckedPropertiesSchema<T> = { [K in keyof T]-?: (UncheckedJsonSchemaType<T[K], false> &
|
|
60
|
+
type UncheckedPropertiesSchema<T> = { [K in keyof T]-?: (UncheckedJsonSchemaType<T[K], false> & JsonSchemaNullable<T[K]>) | {
|
|
59
61
|
$ref: string;
|
|
60
62
|
} };
|
|
61
63
|
type UncheckedRequiredMembers<T> = { [K in keyof T]-?: undefined extends T[K] ? never : K }[keyof T];
|
|
62
|
-
type
|
|
64
|
+
type JsonSchemaNullable<T> = undefined extends T ? {
|
|
63
65
|
/** Indicates that the value may be null in addition to the declared type. */nullable: true; /** A constant value constrained to null when the schema is nullable. */
|
|
64
66
|
const?: null; /** Allowed values, including null when the schema is nullable. */
|
|
65
67
|
enum?: readonly (T | null)[]; /** The default value to use when none is provided. */
|
|
@@ -84,7 +86,7 @@ type UncheckedJsonSchemaType<T, IsPartial extends boolean> = ({
|
|
|
84
86
|
type: JsonType<"boolean", IsPartial>;
|
|
85
87
|
} : T extends readonly [any, ...any[]] ? {
|
|
86
88
|
type: JsonType<"array", IsPartial>; /** The tuple items in order. */
|
|
87
|
-
items: { readonly [K in keyof T]-?: UncheckedJsonSchemaType<T[K], false> &
|
|
89
|
+
items: { readonly [K in keyof T]-?: UncheckedJsonSchemaType<T[K], false> & JsonSchemaNullable<T[K]> } & {
|
|
88
90
|
length: T["length"];
|
|
89
91
|
}; /** The minimum number of items allowed in the tuple. */
|
|
90
92
|
minItems: T["length"];
|
|
@@ -155,17 +157,28 @@ type UncheckedJsonSchemaType<T, IsPartial extends boolean> = ({
|
|
|
155
157
|
*/
|
|
156
158
|
$comment?: string;
|
|
157
159
|
/**
|
|
158
|
-
* A record of schema definitions that can be referenced throughout the schema using
|
|
160
|
+
* A record of schema definitions that can be referenced throughout the schema using {@link UncheckedJsonSchemaType.$ref}. This property can be used to define reusable schema components and reduce redundancy in schema definitions. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
159
161
|
*/
|
|
160
162
|
$defs?: Record<string, UncheckedJsonSchemaType<Known, true>>;
|
|
161
|
-
/**
|
|
162
|
-
* A record of schema definitions that can be referenced throughout the schema using `$ref`. This property is a legacy version of `$defs` and is maintained for backward compatibility with earlier versions of the JSON Schema specification. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
163
|
-
*/
|
|
164
|
-
definitions?: Record<string, UncheckedJsonSchemaType<Known, true>>;
|
|
165
163
|
/**
|
|
166
164
|
* A name for the schema, which can be used by documentation tools or other libraries that support this feature to provide a human-readable name or description for the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
167
165
|
*/
|
|
168
166
|
name?: string;
|
|
167
|
+
/**
|
|
168
|
+
* A unique identifier for the schema, which can be used to reference or identify the schema in various contexts. This property is part of the JSON Schema specification and does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
169
|
+
*
|
|
170
|
+
* @remarks
|
|
171
|
+
* This property is a legacy version of {@link UncheckedJsonSchemaType.$id} and is maintained for backward compatibility with earlier versions of the JSON Schema specification. The presence of this property does not affect the validation behavior of the schema itself, but it can be used to reference or identify the schema in various contexts when used in conjunction with compatible tools.
|
|
172
|
+
*
|
|
173
|
+
* @deprecated Use {@link UncheckedJsonSchemaType.$id} instead.
|
|
174
|
+
*/
|
|
175
|
+
id?: string;
|
|
176
|
+
/**
|
|
177
|
+
* A record of schema definitions that can be referenced throughout the schema using {@link UncheckedJsonSchemaType.$ref}. This property is a legacy version of {@link UncheckedJsonSchemaType.$defs} and is maintained for backward compatibility with earlier versions of the JSON Schema specification. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
178
|
+
*
|
|
179
|
+
* @deprecated Use {@link UncheckedJsonSchemaType.$defs} instead.
|
|
180
|
+
*/
|
|
181
|
+
definitions?: Record<string, UncheckedJsonSchemaType<Known, true>>;
|
|
169
182
|
[keyword: string]: any;
|
|
170
183
|
};
|
|
171
184
|
interface SchemaMetadata {
|
|
@@ -178,13 +191,13 @@ interface SchemaMetadata {
|
|
|
178
191
|
*/
|
|
179
192
|
description?: string;
|
|
180
193
|
/**
|
|
181
|
-
* A URL
|
|
194
|
+
* A URL to external documentation for the schema, which can be used by documentation tools or other libraries that support this feature to provide additional information or resources related to the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
182
195
|
*/
|
|
183
196
|
docs?: string;
|
|
184
197
|
/**
|
|
185
198
|
* An array of example values that conform to the schema. This property can be used to provide sample data for documentation purposes or to assist developers in understanding the expected structure and content of the data that the schema represents. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the expected data when used in conjunction with compatible tools.
|
|
186
199
|
*/
|
|
187
|
-
examples?:
|
|
200
|
+
examples?: unknown[];
|
|
188
201
|
/**
|
|
189
202
|
* An array of strings or an alias reference to indicate that the field is an alias for one or more other fields.
|
|
190
203
|
*/
|
|
@@ -193,10 +206,6 @@ interface SchemaMetadata {
|
|
|
193
206
|
* An array of strings indicating groups that the schema belongs to. This property can be used for organizational or categorization purposes in documentation tools or other libraries that support this feature. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
194
207
|
*/
|
|
195
208
|
tags?: string[];
|
|
196
|
-
/**
|
|
197
|
-
* A visibility level for the schema, which can be used by documentation tools or other libraries that support this feature to determine how the schema should be presented or accessed. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
198
|
-
*/
|
|
199
|
-
visibility?: "public" | "protected" | "private";
|
|
200
209
|
/**
|
|
201
210
|
* An indicator specifying if the field is deprecated or not. This property can be used by documentation tools or other libraries that support this feature to provide additional information or warnings about the usage of the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
202
211
|
*/
|
|
@@ -240,7 +249,7 @@ interface SchemaMetadata {
|
|
|
240
249
|
*/
|
|
241
250
|
contentSchema?: string;
|
|
242
251
|
}
|
|
243
|
-
type JsonSchemaProperty<T extends Record<string, any> = Record<string, any>, TName extends string = string> =
|
|
252
|
+
type JsonSchemaProperty<T extends Record<string, any> = Record<string, any>, TName extends keyof T & string = keyof T & string> = JsonSchema<T[TName]> & {
|
|
244
253
|
/** The property name within the parent object schema. */name: TName;
|
|
245
254
|
/**
|
|
246
255
|
* An indicator specifying if the field is nullable or not. If `true`, the field can accept `null` as a valid value. This property can be used by validation libraries or other tools that support this feature to provide additional validation rules for the data that the schema represents. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the expected data when used in conjunction with compatible tools.
|
|
@@ -259,15 +268,15 @@ type JsonSchemaObject<T extends Record<string, any> = Record<string, any>> = Omi
|
|
|
259
268
|
properties: Record<string, JsonSchemaProperty<T>>; /** The property names that are required on the object. */
|
|
260
269
|
required?: string[];
|
|
261
270
|
} & SchemaMetadata;
|
|
262
|
-
type SchemaSourceVariant = "standard-schema" | "json-schema" | "zod3" | "untyped" | "reflection";
|
|
271
|
+
type SchemaSourceVariant = "standard-schema" | "json-schema" | "zod3" | "untyped" | "valibot" | "reflection";
|
|
263
272
|
type SchemaInputVariant = SchemaSourceVariant | "type-definition";
|
|
264
|
-
type SchemaSourceInput<T = unknown> = StandardJSONSchemaV1 | JsonSchema<T> | z3.ZodTypeAny | UntypedInputObject | UntypedSchema | Type;
|
|
273
|
+
type SchemaSourceInput<T = unknown> = StandardJSONSchemaV1 | JsonSchema<T> | z3.ZodTypeAny | UntypedInputObject | UntypedSchema | ValibotSchema | Type;
|
|
265
274
|
type TypeDefinitionReference = TypeDefinition | string;
|
|
266
|
-
type SchemaInput<T = unknown> = SchemaSourceInput<T> | Schema<T> | TypeDefinitionReference;
|
|
275
|
+
type SchemaInput<T = unknown> = SchemaSourceInput<T> | Schema$1<T> | TypeDefinitionReference;
|
|
267
276
|
/**
|
|
268
277
|
* A schema extracted from a source input, normalized to JSON Schema.
|
|
269
278
|
*/
|
|
270
|
-
interface Schema<T = unknown> {
|
|
279
|
+
interface Schema$1<T = unknown> {
|
|
271
280
|
/** A stable content hash for the normalized schema. */
|
|
272
281
|
hash: string;
|
|
273
282
|
/** The source variant used to derive the normalized {@link JsonSchema}. */
|
|
@@ -275,19 +284,19 @@ interface Schema<T = unknown> {
|
|
|
275
284
|
/** The normalized schema definition. */
|
|
276
285
|
schema: JsonSchema<T>;
|
|
277
286
|
}
|
|
278
|
-
interface BaseSchemaSource {
|
|
287
|
+
interface BaseSchemaSource<T = unknown> {
|
|
279
288
|
/** A stable content hash for the original source schema. */
|
|
280
289
|
hash: string;
|
|
281
290
|
/** The specific source format used for the schema input. */
|
|
282
291
|
variant: SchemaSourceVariant;
|
|
283
292
|
/** The original schema input captured before normalization. */
|
|
284
|
-
schema: SchemaSourceInput
|
|
293
|
+
schema: SchemaSourceInput<T>;
|
|
285
294
|
}
|
|
286
|
-
interface JsonSchemaSchemaSource<
|
|
295
|
+
interface JsonSchemaSchemaSource<T = unknown> extends BaseSchemaSource<T> {
|
|
287
296
|
/** Indicates the source input already uses JSON Schema syntax. */
|
|
288
297
|
variant: "json-schema";
|
|
289
298
|
/** The original JSON Schema document. */
|
|
290
|
-
schema: JsonSchema<
|
|
299
|
+
schema: JsonSchema<T>;
|
|
291
300
|
}
|
|
292
301
|
interface StandardSchemaSchemaSource extends BaseSchemaSource {
|
|
293
302
|
/** Indicates the source input follows the Standard Schema format. */
|
|
@@ -313,11 +322,17 @@ interface UntypedSchemaSource extends BaseSchemaSource {
|
|
|
313
322
|
/** The original Untyped schema input. */
|
|
314
323
|
schema: UntypedInputObject | UntypedSchema;
|
|
315
324
|
}
|
|
316
|
-
|
|
317
|
-
|
|
325
|
+
interface ValibotSchemaSource extends BaseSchemaSource {
|
|
326
|
+
/** Indicates the source input comes from the Valibot schema model. */
|
|
327
|
+
variant: "valibot";
|
|
328
|
+
/** The original Valibot schema input. */
|
|
329
|
+
schema: ValibotSchema;
|
|
330
|
+
}
|
|
331
|
+
type SchemaSource = JsonSchemaSchemaSource | StandardSchemaSchemaSource | Zod3SchemaSource | UntypedSchemaSource | ValibotSchemaSource | ReflectionSchemaSource;
|
|
332
|
+
interface ExtractedSchema<T = unknown> extends Schema$1<T> {
|
|
318
333
|
/** The schema source that produced this normalized schema. */
|
|
319
334
|
source: SchemaSource;
|
|
320
335
|
}
|
|
321
336
|
//#endregion
|
|
322
|
-
export { BaseSchemaSource, ExtractedSchema, JsonSchema, JsonSchemaLike, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaProperty, JsonSchemaSchemaSource, JsonType, NumberFormat, NumberKeywords, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, StringKeywords, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, Zod3SchemaSource };
|
|
337
|
+
export { BaseSchemaSource, ExtractedSchema, JsonSchema, JsonSchemaLike, JsonSchemaNullable, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaProperty, JsonSchemaSchemaSource, JsonType, NumberFormat, NumberKeywords, ReflectionSchemaSource, Schema$1 as Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, StringKeywords, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, ValibotSchema, ValibotSchemaSource, Zod3SchemaSource };
|
|
323
338
|
//# sourceMappingURL=types.d.cts.map
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;;KA0BY,kBAAA,GAAqB,WAAW;AAAA,KAChC,aAAA,GAAgB,MAAO;AAAA,KAEvB,aAAA,qDAGK,SAAA,YAAqB,SAAA,aAClC,UAAA,CAAW,MAAA,EAAQ,OAAA,EAAS,MAAA;;;;KAKpB,uBAAA;AAAA,KASP,uBAAA,2GACmD,IAAA,KACpD,IAAI;AAAA,KAEH,mBAAA,OAA0B,CAAA,gBAAiB,CAAA,EAAG,CAAC,6BAClD,CAAA,sBAEE,CAAA;;;AA3B+B;KAiCvB,cAAA,GAAiB,uBAAA,CAAwB,KAAA,UACnD,cAAA;AAAA,KAEG,sBAAA,MAA4B,OAAA,CAAQ,uBAAA,CAAwB,CAAA;AAAA,KAErD,QAAA,gDAGR,SAAA,gBAAyB,CAAA,eAAgB,CAAA;AAAA,KAEjC,YAAA;AAAA,UAWK,cAAA;EAhDF;EAkDb,OAAA;EAlD8B;EAqD9B,OAAA;EArDY;EAwDZ,gBAAA;EA3DA;EA8DA,gBAAA;EA5DA;EA+DA,UAAA;EA/DoC;EAkEpC,MAAA,GAAS,YAAY;AAAA;AAAA,UAGN,cAAA;EApEe;EAsE9B,SAAA;EAtEoC;EAyEpC,SAAA;EApEiC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AA,SAAmC,gBAAgB;EAra3B;EAuavC,OAAA;EAraU;EAwaV,MAAA,EAAQ,oBAAA;AAAA;AAAA,UAGO,gBAAA,SAAyB,gBAAgB;EAzaxB;EA2ahC,OAAA;EAxaI;EA2aJ,MAAA,EAAQ,EAAA,CAAG,UAAA;AAAA;AAAA,UAGI,sBAAA,SAA+B,gBAAgB;EA1apD;EA4aV,OAAA;EAraQ;EAwaR,MAAA,EAAQ,IAAA;AAAA;AAAA,UAGO,mBAAA,SAA4B,gBAAA;EAzarC;EA2aN,OAAA;EAzagB;EA4ahB,MAAA,EAAQ,kBAAA,GAAqB,aAAA;AAAA;AAAA,UAGd,mBAAA,SAA4B,gBAAgB;EA3a/C;EA6aZ,OAAA;EA7asC;EAgbtC,MAAA,EAAQ,aAAA;AAAA;AAAA,KAGE,YAAA,GACR,sBAAA,GACA,0BAAA,GACA,gBAAA,GACA,mBAAA,GACA,mBAAA,GACA,sBAAA;AAAA,UAEa,eAAA,sBAAqC,QAAA,CAAO,CAAA;EApb7C;EAsbd,MAAA,EAAQ,YAAA;AAAA"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { FormatName } from "ajv-formats/dist/formats.js";
|
|
2
1
|
import { Type } from "@powerlines/deepkit/vendor/type";
|
|
3
2
|
import { StandardJSONSchemaV1 } from "@standard-schema/spec";
|
|
4
3
|
import { TypeDefinition } from "@stryke/types/configuration";
|
|
5
|
-
import {
|
|
4
|
+
import { FormatName } from "ajv-formats/dist/formats.js";
|
|
5
|
+
import { InputObject, Schema } from "untyped";
|
|
6
|
+
import { BaseIssue, BaseSchema } from "valibot";
|
|
6
7
|
import * as z3 from "zod/v3";
|
|
7
8
|
|
|
8
9
|
//#region src/types.d.ts
|
|
9
10
|
type UntypedInputObject = InputObject;
|
|
10
|
-
type UntypedSchema = Schema
|
|
11
|
+
type UntypedSchema = Schema;
|
|
12
|
+
type ValibotSchema<TInput = unknown, TOutput = unknown, TIssue extends BaseIssue<unknown> = BaseIssue<unknown>> = BaseSchema<TInput, TOutput, TIssue>;
|
|
11
13
|
/**
|
|
12
14
|
* JSON Schema primitive type names used by {@link stringifyType}.
|
|
13
15
|
*/
|
|
@@ -55,11 +57,11 @@ interface StringKeywords {
|
|
|
55
57
|
type Known = {
|
|
56
58
|
[key: string]: Known;
|
|
57
59
|
} | [Known, ...Known[]] | Known[] | number | string | boolean | null;
|
|
58
|
-
type UncheckedPropertiesSchema<T> = { [K in keyof T]-?: (UncheckedJsonSchemaType<T[K], false> &
|
|
60
|
+
type UncheckedPropertiesSchema<T> = { [K in keyof T]-?: (UncheckedJsonSchemaType<T[K], false> & JsonSchemaNullable<T[K]>) | {
|
|
59
61
|
$ref: string;
|
|
60
62
|
} };
|
|
61
63
|
type UncheckedRequiredMembers<T> = { [K in keyof T]-?: undefined extends T[K] ? never : K }[keyof T];
|
|
62
|
-
type
|
|
64
|
+
type JsonSchemaNullable<T> = undefined extends T ? {
|
|
63
65
|
/** Indicates that the value may be null in addition to the declared type. */nullable: true; /** A constant value constrained to null when the schema is nullable. */
|
|
64
66
|
const?: null; /** Allowed values, including null when the schema is nullable. */
|
|
65
67
|
enum?: readonly (T | null)[]; /** The default value to use when none is provided. */
|
|
@@ -84,7 +86,7 @@ type UncheckedJsonSchemaType<T, IsPartial extends boolean> = ({
|
|
|
84
86
|
type: JsonType<"boolean", IsPartial>;
|
|
85
87
|
} : T extends readonly [any, ...any[]] ? {
|
|
86
88
|
type: JsonType<"array", IsPartial>; /** The tuple items in order. */
|
|
87
|
-
items: { readonly [K in keyof T]-?: UncheckedJsonSchemaType<T[K], false> &
|
|
89
|
+
items: { readonly [K in keyof T]-?: UncheckedJsonSchemaType<T[K], false> & JsonSchemaNullable<T[K]> } & {
|
|
88
90
|
length: T["length"];
|
|
89
91
|
}; /** The minimum number of items allowed in the tuple. */
|
|
90
92
|
minItems: T["length"];
|
|
@@ -155,17 +157,28 @@ type UncheckedJsonSchemaType<T, IsPartial extends boolean> = ({
|
|
|
155
157
|
*/
|
|
156
158
|
$comment?: string;
|
|
157
159
|
/**
|
|
158
|
-
* A record of schema definitions that can be referenced throughout the schema using
|
|
160
|
+
* A record of schema definitions that can be referenced throughout the schema using {@link UncheckedJsonSchemaType.$ref}. This property can be used to define reusable schema components and reduce redundancy in schema definitions. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
159
161
|
*/
|
|
160
162
|
$defs?: Record<string, UncheckedJsonSchemaType<Known, true>>;
|
|
161
|
-
/**
|
|
162
|
-
* A record of schema definitions that can be referenced throughout the schema using `$ref`. This property is a legacy version of `$defs` and is maintained for backward compatibility with earlier versions of the JSON Schema specification. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
163
|
-
*/
|
|
164
|
-
definitions?: Record<string, UncheckedJsonSchemaType<Known, true>>;
|
|
165
163
|
/**
|
|
166
164
|
* A name for the schema, which can be used by documentation tools or other libraries that support this feature to provide a human-readable name or description for the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
167
165
|
*/
|
|
168
166
|
name?: string;
|
|
167
|
+
/**
|
|
168
|
+
* A unique identifier for the schema, which can be used to reference or identify the schema in various contexts. This property is part of the JSON Schema specification and does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
169
|
+
*
|
|
170
|
+
* @remarks
|
|
171
|
+
* This property is a legacy version of {@link UncheckedJsonSchemaType.$id} and is maintained for backward compatibility with earlier versions of the JSON Schema specification. The presence of this property does not affect the validation behavior of the schema itself, but it can be used to reference or identify the schema in various contexts when used in conjunction with compatible tools.
|
|
172
|
+
*
|
|
173
|
+
* @deprecated Use {@link UncheckedJsonSchemaType.$id} instead.
|
|
174
|
+
*/
|
|
175
|
+
id?: string;
|
|
176
|
+
/**
|
|
177
|
+
* A record of schema definitions that can be referenced throughout the schema using {@link UncheckedJsonSchemaType.$ref}. This property is a legacy version of {@link UncheckedJsonSchemaType.$defs} and is maintained for backward compatibility with earlier versions of the JSON Schema specification. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
178
|
+
*
|
|
179
|
+
* @deprecated Use {@link UncheckedJsonSchemaType.$defs} instead.
|
|
180
|
+
*/
|
|
181
|
+
definitions?: Record<string, UncheckedJsonSchemaType<Known, true>>;
|
|
169
182
|
[keyword: string]: any;
|
|
170
183
|
};
|
|
171
184
|
interface SchemaMetadata {
|
|
@@ -178,13 +191,13 @@ interface SchemaMetadata {
|
|
|
178
191
|
*/
|
|
179
192
|
description?: string;
|
|
180
193
|
/**
|
|
181
|
-
* A URL
|
|
194
|
+
* A URL to external documentation for the schema, which can be used by documentation tools or other libraries that support this feature to provide additional information or resources related to the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
182
195
|
*/
|
|
183
196
|
docs?: string;
|
|
184
197
|
/**
|
|
185
198
|
* An array of example values that conform to the schema. This property can be used to provide sample data for documentation purposes or to assist developers in understanding the expected structure and content of the data that the schema represents. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the expected data when used in conjunction with compatible tools.
|
|
186
199
|
*/
|
|
187
|
-
examples?:
|
|
200
|
+
examples?: unknown[];
|
|
188
201
|
/**
|
|
189
202
|
* An array of strings or an alias reference to indicate that the field is an alias for one or more other fields.
|
|
190
203
|
*/
|
|
@@ -193,10 +206,6 @@ interface SchemaMetadata {
|
|
|
193
206
|
* An array of strings indicating groups that the schema belongs to. This property can be used for organizational or categorization purposes in documentation tools or other libraries that support this feature. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
194
207
|
*/
|
|
195
208
|
tags?: string[];
|
|
196
|
-
/**
|
|
197
|
-
* A visibility level for the schema, which can be used by documentation tools or other libraries that support this feature to determine how the schema should be presented or accessed. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
198
|
-
*/
|
|
199
|
-
visibility?: "public" | "protected" | "private";
|
|
200
209
|
/**
|
|
201
210
|
* An indicator specifying if the field is deprecated or not. This property can be used by documentation tools or other libraries that support this feature to provide additional information or warnings about the usage of the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
|
|
202
211
|
*/
|
|
@@ -240,7 +249,7 @@ interface SchemaMetadata {
|
|
|
240
249
|
*/
|
|
241
250
|
contentSchema?: string;
|
|
242
251
|
}
|
|
243
|
-
type JsonSchemaProperty<T extends Record<string, any> = Record<string, any>, TName extends string = string> =
|
|
252
|
+
type JsonSchemaProperty<T extends Record<string, any> = Record<string, any>, TName extends keyof T & string = keyof T & string> = JsonSchema<T[TName]> & {
|
|
244
253
|
/** The property name within the parent object schema. */name: TName;
|
|
245
254
|
/**
|
|
246
255
|
* An indicator specifying if the field is nullable or not. If `true`, the field can accept `null` as a valid value. This property can be used by validation libraries or other tools that support this feature to provide additional validation rules for the data that the schema represents. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the expected data when used in conjunction with compatible tools.
|
|
@@ -259,15 +268,15 @@ type JsonSchemaObject<T extends Record<string, any> = Record<string, any>> = Omi
|
|
|
259
268
|
properties: Record<string, JsonSchemaProperty<T>>; /** The property names that are required on the object. */
|
|
260
269
|
required?: string[];
|
|
261
270
|
} & SchemaMetadata;
|
|
262
|
-
type SchemaSourceVariant = "standard-schema" | "json-schema" | "zod3" | "untyped" | "reflection";
|
|
271
|
+
type SchemaSourceVariant = "standard-schema" | "json-schema" | "zod3" | "untyped" | "valibot" | "reflection";
|
|
263
272
|
type SchemaInputVariant = SchemaSourceVariant | "type-definition";
|
|
264
|
-
type SchemaSourceInput<T = unknown> = StandardJSONSchemaV1 | JsonSchema<T> | z3.ZodTypeAny | UntypedInputObject | UntypedSchema | Type;
|
|
273
|
+
type SchemaSourceInput<T = unknown> = StandardJSONSchemaV1 | JsonSchema<T> | z3.ZodTypeAny | UntypedInputObject | UntypedSchema | ValibotSchema | Type;
|
|
265
274
|
type TypeDefinitionReference = TypeDefinition | string;
|
|
266
|
-
type SchemaInput<T = unknown> = SchemaSourceInput<T> | Schema<T> | TypeDefinitionReference;
|
|
275
|
+
type SchemaInput<T = unknown> = SchemaSourceInput<T> | Schema$1<T> | TypeDefinitionReference;
|
|
267
276
|
/**
|
|
268
277
|
* A schema extracted from a source input, normalized to JSON Schema.
|
|
269
278
|
*/
|
|
270
|
-
interface Schema<T = unknown> {
|
|
279
|
+
interface Schema$1<T = unknown> {
|
|
271
280
|
/** A stable content hash for the normalized schema. */
|
|
272
281
|
hash: string;
|
|
273
282
|
/** The source variant used to derive the normalized {@link JsonSchema}. */
|
|
@@ -275,19 +284,19 @@ interface Schema<T = unknown> {
|
|
|
275
284
|
/** The normalized schema definition. */
|
|
276
285
|
schema: JsonSchema<T>;
|
|
277
286
|
}
|
|
278
|
-
interface BaseSchemaSource {
|
|
287
|
+
interface BaseSchemaSource<T = unknown> {
|
|
279
288
|
/** A stable content hash for the original source schema. */
|
|
280
289
|
hash: string;
|
|
281
290
|
/** The specific source format used for the schema input. */
|
|
282
291
|
variant: SchemaSourceVariant;
|
|
283
292
|
/** The original schema input captured before normalization. */
|
|
284
|
-
schema: SchemaSourceInput
|
|
293
|
+
schema: SchemaSourceInput<T>;
|
|
285
294
|
}
|
|
286
|
-
interface JsonSchemaSchemaSource<
|
|
295
|
+
interface JsonSchemaSchemaSource<T = unknown> extends BaseSchemaSource<T> {
|
|
287
296
|
/** Indicates the source input already uses JSON Schema syntax. */
|
|
288
297
|
variant: "json-schema";
|
|
289
298
|
/** The original JSON Schema document. */
|
|
290
|
-
schema: JsonSchema<
|
|
299
|
+
schema: JsonSchema<T>;
|
|
291
300
|
}
|
|
292
301
|
interface StandardSchemaSchemaSource extends BaseSchemaSource {
|
|
293
302
|
/** Indicates the source input follows the Standard Schema format. */
|
|
@@ -313,11 +322,17 @@ interface UntypedSchemaSource extends BaseSchemaSource {
|
|
|
313
322
|
/** The original Untyped schema input. */
|
|
314
323
|
schema: UntypedInputObject | UntypedSchema;
|
|
315
324
|
}
|
|
316
|
-
|
|
317
|
-
|
|
325
|
+
interface ValibotSchemaSource extends BaseSchemaSource {
|
|
326
|
+
/** Indicates the source input comes from the Valibot schema model. */
|
|
327
|
+
variant: "valibot";
|
|
328
|
+
/** The original Valibot schema input. */
|
|
329
|
+
schema: ValibotSchema;
|
|
330
|
+
}
|
|
331
|
+
type SchemaSource = JsonSchemaSchemaSource | StandardSchemaSchemaSource | Zod3SchemaSource | UntypedSchemaSource | ValibotSchemaSource | ReflectionSchemaSource;
|
|
332
|
+
interface ExtractedSchema<T = unknown> extends Schema$1<T> {
|
|
318
333
|
/** The schema source that produced this normalized schema. */
|
|
319
334
|
source: SchemaSource;
|
|
320
335
|
}
|
|
321
336
|
//#endregion
|
|
322
|
-
export { BaseSchemaSource, ExtractedSchema, JsonSchema, JsonSchemaLike, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaProperty, JsonSchemaSchemaSource, JsonType, NumberFormat, NumberKeywords, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, StringKeywords, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, Zod3SchemaSource };
|
|
337
|
+
export { BaseSchemaSource, ExtractedSchema, JsonSchema, JsonSchemaLike, JsonSchemaNullable, JsonSchemaObject, JsonSchemaPrimitiveType, JsonSchemaProperty, JsonSchemaSchemaSource, JsonType, NumberFormat, NumberKeywords, ReflectionSchemaSource, Schema$1 as Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, StringKeywords, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, ValibotSchema, ValibotSchemaSource, Zod3SchemaSource };
|
|
323
338
|
//# sourceMappingURL=types.d.mts.map
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;;KA0BY,kBAAA,GAAqB,WAAW;AAAA,KAChC,aAAA,GAAgB,MAAO;AAAA,KAEvB,aAAA,qDAGK,SAAA,YAAqB,SAAA,aAClC,UAAA,CAAW,MAAA,EAAQ,OAAA,EAAS,MAAA;;;;KAKpB,uBAAA;AAAA,KASP,uBAAA,2GACmD,IAAA,KACpD,IAAI;AAAA,KAEH,mBAAA,OAA0B,CAAA,gBAAiB,CAAA,EAAG,CAAC,6BAClD,CAAA,sBAEE,CAAA;;;AA3B+B;KAiCvB,cAAA,GAAiB,uBAAA,CAAwB,KAAA,UACnD,cAAA;AAAA,KAEG,sBAAA,MAA4B,OAAA,CAAQ,uBAAA,CAAwB,CAAA;AAAA,KAErD,QAAA,gDAGR,SAAA,gBAAyB,CAAA,eAAgB,CAAA;AAAA,KAEjC,YAAA;AAAA,UAWK,cAAA;EAhDF;EAkDb,OAAA;EAlD8B;EAqD9B,OAAA;EArDY;EAwDZ,gBAAA;EA3DA;EA8DA,gBAAA;EA5DA;EA+DA,UAAA;EA/DoC;EAkEpC,MAAA,GAAS,YAAY;AAAA;AAAA,UAGN,cAAA;EApEe;EAsE9B,SAAA;EAtEoC;EAyEpC,SAAA;EApEiC;EAuEjC,OAAA;EAvEiC;AAAA;AAOvB;;;;;;EA0EV,MAAA,GAAS,UAAU;AAAA;AAAA,KAGhB,KAAA;EAAA,CAEE,GAAA,WAAc,KAAA;AAAA,KAEhB,KAAA,KAAU,KAAA,MACX,KAAA;AAAA,KAMC,yBAAA,oBACS,CAAA,MACP,uBAAA,CAAwB,CAAA,CAAE,CAAA,YAAa,kBAAA,CA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;EAwaR,MAAA,EAAQ,IAAA;AAAA;AAAA,UAGO,mBAAA,SAA4B,gBAAA;EAzarC;EA2aN,OAAA;EAzagB;EA4ahB,MAAA,EAAQ,kBAAA,GAAqB,aAAA;AAAA;AAAA,UAGd,mBAAA,SAA4B,gBAAgB;EA3a/C;EA6aZ,OAAA;EA7asC;EAgbtC,MAAA,EAAQ,aAAA;AAAA;AAAA,KAGE,YAAA,GACR,sBAAA,GACA,0BAAA,GACA,gBAAA,GACA,mBAAA,GACA,mBAAA,GACA,sBAAA;AAAA,UAEa,eAAA,sBAAqC,QAAA,CAAO,CAAA;EApb7C;EAsbd,MAAA,EAAQ,YAAA;AAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
let ajv = require("ajv");
|
|
3
|
+
ajv = require_runtime.__toESM(ajv, 1);
|
|
4
|
+
let ajv_formats = require("ajv-formats");
|
|
5
|
+
ajv_formats = require_runtime.__toESM(ajv_formats, 1);
|
|
6
|
+
|
|
7
|
+
//#region src/validate.ts
|
|
8
|
+
/**
|
|
9
|
+
* Gets an Ajv validator instance for a given JSON Schema.
|
|
10
|
+
*
|
|
11
|
+
* @param schema - The JSON Schema to create a validator for.
|
|
12
|
+
* @returns An Ajv instance with the schema added.
|
|
13
|
+
*/
|
|
14
|
+
function getValidator(schema) {
|
|
15
|
+
const ajv$1 = new ajv.default({
|
|
16
|
+
schemas: [schema],
|
|
17
|
+
code: {
|
|
18
|
+
source: true,
|
|
19
|
+
esm: true
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
(0, ajv_formats.default)(ajv$1);
|
|
23
|
+
return ajv$1;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.getValidator = getValidator;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Ajv from "ajv";
|
|
2
|
+
import addFormats from "ajv-formats";
|
|
3
|
+
|
|
4
|
+
//#region src/validate.ts
|
|
5
|
+
/**
|
|
6
|
+
* Gets an Ajv validator instance for a given JSON Schema.
|
|
7
|
+
*
|
|
8
|
+
* @param schema - The JSON Schema to create a validator for.
|
|
9
|
+
* @returns An Ajv instance with the schema added.
|
|
10
|
+
*/
|
|
11
|
+
function getValidator(schema) {
|
|
12
|
+
const ajv = new Ajv({
|
|
13
|
+
schemas: [schema],
|
|
14
|
+
code: {
|
|
15
|
+
source: true,
|
|
16
|
+
esm: true
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
addFormats(ajv);
|
|
20
|
+
return ajv;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { getValidator };
|
|
25
|
+
//# sourceMappingURL=validate.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.mjs","names":[],"sources":["../src/validate.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 Ajv, { ValidateFunction } from \"ajv\";\nimport addFormats from \"ajv-formats\";\nimport { JsonSchema } from \"./types\";\n\n/**\n * Gets an Ajv validator instance for a given JSON Schema.\n *\n * @param schema - The JSON Schema to create a validator for.\n * @returns An Ajv instance with the schema added.\n */\nexport function getValidator<T = unknown>(schema: JsonSchema<T>): Ajv {\n const ajv = new Ajv({\n schemas: [schema],\n code: { source: true, esm: true }\n });\n\n addFormats(ajv);\n\n return ajv;\n}\n\n/**\n * Gets a validation function for a given JSON Schema.\n *\n * @param schema - The JSON Schema to create a validation function for.\n * @returns A function that validates data against the schema and returns a boolean indicating validity.\n */\nexport function getValidatorFunction<T = unknown>(\n schema: JsonSchema<T>\n): ValidateFunction<T> {\n const ajv = getValidator(schema);\n\n return ajv.compile<T>(schema);\n}\n"],"mappings":";;;;;;;;;;AA4BA,SAAgB,aAA0B,QAA4B;CACpE,MAAM,MAAM,IAAI,IAAI;EAClB,SAAS,CAAC,MAAM;EAChB,MAAM;GAAE,QAAQ;GAAM,KAAK;EAAK;CAClC,CAAC;CAED,WAAW,GAAG;CAEd,OAAO;AACT"}
|