@powerlines/schema 0.11.76 → 0.11.77

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["isSetObject","baseObj","isUndefined","isNull","isBoolean","isNumber","isSetString","isSetString","parseYaml","parseToml","isSetObject","stringifyType","extractJsonSchemaZod"],"sources":["../src/bundle.ts","../src/constants.ts","../src/metadata.ts","../src/type-checks.ts","../src/helpers.ts","../src/validate.ts","../src/codegen.ts","../src/persistence.ts","../src/reflection.ts","../src/resolve.ts","../src/extract.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 { ResolveOptions, UnresolvedContext } from \"@powerlines/core\";\nimport { createUnpluginResolver } from \"@powerlines/core/lib/unplugin\";\nimport { resolveOptions } from \"@powerlines/unplugin/esbuild\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { findFileName } from \"@stryke/path/file-path-fns\";\nimport { DeepPartial } from \"@stryke/types/base\";\nimport defu from \"defu\";\nimport type { BuildOptions } from \"esbuild\";\nimport { build, OutputFile } from \"esbuild\";\nimport { createEsbuildPlugin } from \"unplugin\";\n\nexport type BundleOptions = DeepPartial<BuildOptions> & {\n name?: string;\n resolve?: DeepPartial<ResolveOptions>;\n};\n\n/**\n * Bundle a type definition to a module.\n *\n * @param context - The context object containing the environment paths.\n * @param file - The file path to bundle.\n * @param options - Optional overrides for the ESBuild configuration.\n * @returns A promise that resolves to the bundled module.\n */\nexport async function bundle<TContext extends UnresolvedContext>(\n context: TContext,\n file: string,\n options: BundleOptions = {}\n): Promise<OutputFile> {\n const path = await context.fs.resolve(file);\n if (!path || !context.fs.existsSync(path)) {\n throw new Error(\n `Module not found: \"${file}\". Please check the path and try again.`\n );\n }\n\n const result = await build(\n defu(\n {\n platform: \"node\",\n ...omit(options, [\"name\", \"resolve\"]),\n logLevel: \"silent\",\n entryPoints: [path],\n write: false,\n sourcemap: false,\n splitting: false,\n treeShaking: false,\n bundle: true,\n packages: \"bundle\",\n keepNames: true,\n metafile: false\n },\n resolveOptions(context),\n {\n plugins: [\n createEsbuildPlugin(\n createUnpluginResolver(context, {\n name: options.name ?? `${findFileName(file)} Bundler`,\n prefix: false,\n overrides: defu(options.resolve ?? {}, {\n skipNodeModulesBundle: false\n }),\n silenceHookLogging: true\n })\n )()\n ]\n }\n )\n );\n if (result.errors.length > 0) {\n throw new Error(\n `Failed to bundle ${file}: ${result.errors\n .map(error => error.text)\n .join(\", \")}`\n );\n }\n if (result.warnings.length > 0) {\n context.warn(\n `Warnings while bundling ${file}: ${result.warnings\n .map(warning => warning.text)\n .join(\", \")}`\n );\n }\n if (!result.outputFiles || result.outputFiles.filter(Boolean).length === 0) {\n throw new Error(\n `No output files generated for ${\n file\n }. Please check the configuration and try again.`\n );\n }\n\n return result.outputFiles.filter(Boolean)[0]!;\n}\n","/* -------------------------------------------------------------------\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 { JsonSchemaMetadataKeywords } from \"./types\";\n\nexport const VALID_SOURCE_FILE_EXTENSIONS = [\n \"ts\",\n \"cts\",\n \"mts\",\n \"tsx\",\n \"js\",\n \"cjs\",\n \"mjs\",\n \"jsx\",\n \"json\",\n \"jsonc\",\n \"json5\",\n \"yaml\",\n \"yml\",\n \"toml\"\n] as const as string[];\n\nexport const JsonSchemaTypeNames = {\n STRING: \"string\",\n NUMBER: \"number\",\n INTEGER: \"integer\",\n BOOLEAN: \"boolean\",\n NULL: \"null\",\n OBJECT: \"object\",\n ARRAY: \"array\"\n} as const;\n\nexport const JSON_SCHEMA_PRIMITIVE_TYPES = [\n JsonSchemaTypeNames.STRING,\n JsonSchemaTypeNames.NUMBER,\n JsonSchemaTypeNames.INTEGER,\n JsonSchemaTypeNames.BOOLEAN,\n JsonSchemaTypeNames.NULL\n] as const;\n\nexport const JSON_SCHEMA_TYPES = [\n ...JSON_SCHEMA_PRIMITIVE_TYPES,\n JsonSchemaTypeNames.ARRAY,\n JsonSchemaTypeNames.OBJECT\n] as const;\n\nexport const JSON_SCHEMA_METADATA_KEYS = [\n \"docs\",\n \"deprecated\",\n \"title\",\n \"description\",\n \"examples\",\n \"hidden\",\n \"ignore\",\n \"internal\",\n \"runtime\",\n \"readOnly\",\n \"writeOnly\",\n \"alias\",\n \"tags\"\n] satisfies ReadonlyArray<keyof JsonSchemaMetadataKeywords>;\n","/* -------------------------------------------------------------------\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 { isSetString } from \"@stryke/type-checks\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { JSON_SCHEMA_METADATA_KEYS } from \"./constants\";\nimport {\n JsonSchema,\n JsonSchemaMetadataKeywords,\n JsonSchemaPrimitiveType,\n JsonSchemaType\n} from \"./types\";\n\ninterface JsonSchemaTypeView {\n type?: JsonSchemaType | readonly JsonSchemaType[];\n}\n\n/**\n * Applies Powerlines schema metadata onto a JSON Schema fragment.\n *\n * @param schema - The JSON Schema fragment to apply metadata to.\n * @param metadata - The Powerlines schema metadata to apply.\n * @returns A new JSON Schema fragment with the metadata applied.\n */\nexport function applyJsonSchemaMetadata(\n schema: JsonSchema,\n metadata: JsonSchemaMetadataKeywords | undefined\n): JsonSchema {\n if (!metadata || !isSetObject(schema)) {\n return schema;\n }\n\n const result: JsonSchema = { ...schema };\n const mutableResult = result as Record<string, unknown>;\n for (const key of JSON_SCHEMA_METADATA_KEYS) {\n const value = metadata[key];\n if (value !== undefined && value !== null) {\n mutableResult[key] = value;\n }\n }\n\n return result;\n}\n\n/**\n * Normalizes the JSON Schema `type` keyword to a string array.\n *\n * @remarks\n * This function ensures that the `type` keyword of a JSON Schema fragment is always represented as an array of strings, even if it was originally defined as a single string. This normalization simplifies type checking and processing of JSON Schemas by providing a consistent format for the `type` information.\n *\n * @param schema - The JSON Schema fragment to read types from.\n * @returns An array of JSON Schema primitive type names defined in the `type` keyword, or an empty array if no valid types are found.\n */\nexport function readSchemaTypes(\n schema?: JsonSchema\n): JsonSchemaPrimitiveType[] {\n if (!isSetObject(schema)) {\n return [];\n }\n\n const objectSchema = schema as JsonSchemaTypeView;\n\n if (Array.isArray(objectSchema.type)) {\n return objectSchema.type.filter(\n (type: JsonSchemaPrimitiveType): type is JsonSchemaPrimitiveType =>\n isSetString(type)\n );\n }\n if (\n isSetString(objectSchema.type) &&\n objectSchema.type !== \"object\" &&\n objectSchema.type !== \"array\"\n ) {\n return [objectSchema.type];\n }\n return [];\n}\n\n/**\n * Returns the primary non-null JSON Schema type name for a fragment.\n *\n * @param schema - The JSON Schema fragment to check.\n * @returns The primary non-null JSON Schema type name, or `undefined` if none is found.\n */\nexport function getPrimarySchemaType(\n schema?: JsonSchema\n): JsonSchemaPrimitiveType | undefined {\n if (!isSetObject(schema)) {\n return undefined;\n }\n\n return readSchemaTypes(schema).find(type => type !== \"null\");\n}\n","/* -------------------------------------------------------------------\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 { isFunction, isSetObject, isSetString } from \"@stryke/type-checks\";\nimport type {\n FunctionArg as UntypedFunctionArg,\n InputObject as UntypedInputObject,\n Schema as UntypedSchema,\n TypeDescriptor as UntypedTypeDescriptor\n} from \"untyped\";\nimport type { BaseSchema } from \"valibot\";\nimport { JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES } from \"./constants\";\nimport {\n JsonSchema,\n JsonSchemaAllOf,\n JsonSchemaAny,\n JsonSchemaAnyOf,\n JsonSchemaArray,\n JsonSchemaBigint,\n JsonSchemaBoolean,\n JsonSchemaDate,\n JsonSchemaDecimal,\n JsonSchemaEnum,\n JsonSchemaInteger,\n JsonSchemaKeywords,\n JsonSchemaLiteral,\n JsonSchemaMap,\n JsonSchemaNativeEnum,\n JsonSchemaNever,\n JsonSchemaNull,\n JsonSchemaNullable,\n JsonSchemaNumber,\n JsonSchemaObject,\n JsonSchemaPrimitiveType,\n JsonSchemaPrimitiveUnion,\n JsonSchemaRecord,\n JsonSchemaRef,\n JsonSchemaSet,\n JsonSchemaString,\n JsonSchemaTuple,\n JsonSchemaType,\n JsonSchemaUndefined,\n JsonSchemaUnion,\n JsonSchemaUnknown,\n Schema,\n ExtractedSchema as SchemaWithSource\n} from \"./types\";\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\";\nconst isSchemaLikeValue = (value: unknown): boolean =>\n isSetObject(value) || isSetBoolean(value);\n\nconst isRecordOfSchemaLike = (\n value: unknown\n): value is Record<string, unknown> =>\n isSetObject(value) &&\n Object.values(value).every(item => isSchemaLikeValue(item));\n\nconst isVocabularyMap = (value: unknown): value is Record<string, boolean> =>\n isSetObject(value) && Object.values(value).every(item => isSetBoolean(item));\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 JSON_SCHEMA_PRIMITIVE_TYPE_SET = new Set<JsonSchemaPrimitiveType>(\n JSON_SCHEMA_PRIMITIVE_TYPES\n);\nconst JSON_SCHEMA_TYPE_SET = new Set<JsonSchemaType>(JSON_SCHEMA_TYPES);\n\n/**\n * A helper type guard to check if a value is a JSON Schema primitive type.\n *\n * @param value - The value to check.\n * @returns True if the value is a JSON Schema primitive type, false otherwise.\n */\nexport function isJsonSchemaPrimitiveType(\n value: unknown\n): value is JsonSchemaPrimitiveType {\n return (\n isSetString(value) &&\n JSON_SCHEMA_PRIMITIVE_TYPE_SET.has(value as JsonSchemaPrimitiveType)\n );\n}\n\n/**\n * A helper type guard to check if a value is a JSON Schema type.\n *\n * @param value - The value to check.\n * @returns True if the value is a JSON Schema type, false otherwise.\n */\nexport function isJsonSchemaType(value: unknown): value is JsonSchemaType {\n return (\n isSetString(value) && JSON_SCHEMA_TYPE_SET.has(value as JsonSchemaType)\n );\n}\n\nconst DATE_FORMAT_SET = new Set([\n \"date\",\n \"time\",\n \"date-time\",\n \"iso-time\",\n \"iso-date-time\",\n \"unix-time\"\n]);\n\nconst isSetBigint = (value: unknown): value is bigint =>\n typeof value === \"bigint\";\n\ntype UntypedJSType =\n | \"string\"\n | \"number\"\n | \"bigint\"\n | \"boolean\"\n | \"symbol\"\n | \"function\"\n | \"object\"\n | \"any\"\n | \"array\";\n\nconst UNTYPED_TYPE_NAME_SET = new Set<UntypedJSType>([\n \"string\",\n \"number\",\n \"bigint\",\n \"boolean\",\n \"symbol\",\n \"function\",\n \"object\",\n \"any\",\n \"array\"\n]);\n\nconst isUntypedJSType = (value: unknown): value is UntypedJSType =>\n isSetString(value) && UNTYPED_TYPE_NAME_SET.has(value as UntypedJSType);\n\nconst isUntypedTypeDescriptor = (\n value: unknown\n): value is UntypedTypeDescriptor => {\n if (!isSetObject(value)) {\n return false;\n }\n\n const descriptor = value as Record<string, unknown>;\n if (\n descriptor.type !== undefined &&\n !(\n (isSetString(descriptor.type) && isUntypedJSType(descriptor.type)) ||\n (Array.isArray(descriptor.type) &&\n descriptor.type.every(item => isUntypedJSType(item)))\n )\n ) {\n return false;\n }\n\n if (descriptor.tsType !== undefined && !isSetString(descriptor.tsType)) {\n return false;\n }\n\n if (\n descriptor.markdownType !== undefined &&\n !isSetString(descriptor.markdownType)\n ) {\n return false;\n }\n\n if (\n descriptor.items !== undefined &&\n !(\n isUntypedTypeDescriptor(descriptor.items) ||\n (Array.isArray(descriptor.items) &&\n descriptor.items.every(item => isUntypedTypeDescriptor(item)))\n )\n ) {\n return false;\n }\n\n return true;\n};\n\nconst isUntypedFunctionArg = (value: unknown): value is UntypedFunctionArg => {\n if (!isUntypedTypeDescriptor(value)) {\n return false;\n }\n\n const arg = value as Record<string, unknown>;\n if (arg.name !== undefined && !isSetString(arg.name)) {\n return false;\n }\n\n return arg.optional === undefined || typeof arg.optional === \"boolean\";\n};\n\nconst isRecordOfUntypedSchema = (\n value: unknown\n): value is Record<string, UntypedSchema> =>\n isSetObject(value) &&\n Object.values(value).every(item => isUntypedSchema(item));\n\nconst isArrayOf = <T>(\n value: unknown,\n predicate: (item: unknown) => item is T\n): value is T[] => Array.isArray(value) && value.every(item => predicate(item));\n\nconst isTupleOfTwo = <A, B>(\n value: unknown,\n aPredicate: (item: unknown) => item is A,\n bPredicate: (item: unknown) => item is B\n): value is [A, B] =>\n Array.isArray(value) &&\n value.length === 2 &&\n aPredicate(value[0]) &&\n bPredicate(value[1]);\n\nconst isOptionalString = (value: unknown): value is string | undefined =>\n value === undefined || isSetString(value);\n\nconst isOptionalBoolean = (value: unknown): value is boolean | undefined =>\n value === undefined || isSetBoolean(value);\n\nconst isOptionalNumber = (value: unknown): value is number | undefined =>\n value === undefined || isSetNumber(value);\n\nconst isOptionalBigint = (value: unknown): value is bigint | undefined =>\n value === undefined || isSetBigint(value);\n\nconst isOptionalJsonSchema = (\n value: unknown\n): value is JsonSchema | undefined =>\n value === undefined || isJsonSchema(value);\n\nconst isOptionalJsonSchemaArray = (\n value: unknown\n): value is JsonSchema[] | undefined =>\n value === undefined || isArrayOf(value, isJsonSchema);\n\nconst isOptionalPrimitiveTypeArray = (\n value: unknown\n): value is JsonSchemaPrimitiveType[] | undefined =>\n value === undefined ||\n (Array.isArray(value) &&\n value.every(\n item =>\n isSetString(item) &&\n JSON_SCHEMA_PRIMITIVE_TYPE_SET.has(item as JsonSchemaPrimitiveType)\n ));\n\nconst isOptionalJsonSchemaTypeArray = (\n value: unknown\n): value is JsonSchemaType[] | undefined =>\n value === undefined ||\n (Array.isArray(value) &&\n value.every(\n item =>\n isSetString(item) && JSON_SCHEMA_TYPE_SET.has(item as JsonSchemaType)\n ));\n\nconst hasValidJsonSchemaKeywords = (\n schema: Record<string, unknown>\n): boolean => {\n if (!isOptionalString(schema.$id)) {\n return false;\n }\n if (!isOptionalString(schema.$schema)) {\n return false;\n }\n if (\n schema.$vocabulary !== undefined &&\n !isVocabularyMap(schema.$vocabulary)\n ) {\n return false;\n }\n if (!isOptionalString(schema.$comment)) {\n return false;\n }\n if (!isOptionalString(schema.$anchor)) {\n return false;\n }\n if (schema.$defs !== undefined && !isRecordOfSchemaLike(schema.$defs)) {\n return false;\n }\n if (!isOptionalString(schema.$dynamicRef)) {\n return false;\n }\n if (!isOptionalString(schema.$dynamicAnchor)) {\n return false;\n }\n if (!isOptionalString(schema.name)) {\n return false;\n }\n if (!isOptionalString(schema.title)) {\n return false;\n }\n if (!isOptionalString(schema.description)) {\n return false;\n }\n if (!isOptionalString(schema.docs)) {\n return false;\n }\n if (schema.examples !== undefined && !Array.isArray(schema.examples)) {\n return false;\n }\n if (schema.alias !== undefined && !isStringArray(schema.alias)) {\n return false;\n }\n if (schema.tags !== undefined && !isStringArray(schema.tags)) {\n return false;\n }\n if (!isOptionalBoolean(schema.deprecated)) {\n return false;\n }\n if (!isOptionalBoolean(schema.hidden)) {\n return false;\n }\n if (!isOptionalBoolean(schema.ignore)) {\n return false;\n }\n if (!isOptionalBoolean(schema.internal)) {\n return false;\n }\n if (!isOptionalBoolean(schema.runtime)) {\n return false;\n }\n if (!isOptionalBoolean(schema.readOnly)) {\n return false;\n }\n if (!isOptionalBoolean(schema.writeOnly)) {\n return false;\n }\n\n if (!isOptionalJsonSchemaArray(schema.allOf)) {\n return false;\n }\n if (!isOptionalJsonSchemaArray(schema.anyOf)) {\n return false;\n }\n if (!isOptionalJsonSchemaArray(schema.oneOf)) {\n return false;\n }\n if (!isOptionalJsonSchema(schema.not)) {\n return false;\n }\n\n if (!isOptionalJsonSchema(schema.if)) {\n return false;\n }\n if (!isOptionalJsonSchema(schema.then)) {\n return false;\n }\n if (!isOptionalJsonSchema(schema.else)) {\n return false;\n }\n\n return true;\n};\n\n/**\n * Type guard for shared JSON Schema keyword groups.\n *\n * @param input - The value to check.\n * @returns True if the input is a JSON Schema keyword group, false otherwise.\n */\nexport function isJsonSchemaKeywords(\n input: unknown\n): input is JsonSchemaKeywords {\n if (!isSetObject(input)) {\n return false;\n }\n\n return hasValidJsonSchemaKeywords(input as Record<string, unknown>);\n}\n\n/**\n * Type guard for generic JSON Schema objects with optional `$ref`.\n *\n * @param input - The value to check.\n * @returns True if the input is a generic JSON Schema object, false otherwise.\n */\nexport function isJsonSchemaAny(input: unknown): input is JsonSchemaAny {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return hasValidJsonSchemaKeywords(schema) && isOptionalString(schema.$ref);\n}\n\n/**\n * Type guard for JSON Schema array types.\n *\n * @param input - The value to check.\n * @returns True if the input is a JSON Schema array schema, false otherwise.\n */\nexport function isJsonSchemaArray(input: unknown): input is JsonSchemaArray {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (!hasValidJsonSchemaKeywords(schema) || schema.type !== \"array\") {\n return false;\n }\n\n return (\n isOptionalJsonSchemaArray(schema.prefixItems) &&\n isOptionalJsonSchema(schema.items) &&\n isOptionalJsonSchema(schema.contains) &&\n isOptionalNumber(schema.minItems) &&\n isOptionalNumber(schema.maxItems) &&\n isOptionalBoolean(schema.uniqueItems) &&\n isOptionalNumber(schema.minContains) &&\n isOptionalNumber(schema.maxContains) &&\n (schema.unevaluatedItems === undefined ||\n isSetBoolean(schema.unevaluatedItems) ||\n isJsonSchema(schema.unevaluatedItems))\n );\n}\n\n/**\n * Type guard for bigint-backed integer schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a bigint-backed integer schema, false otherwise.\n */\nexport function isJsonSchemaBigint(input: unknown): input is JsonSchemaBigint {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (\n !hasValidJsonSchemaKeywords(schema) ||\n schema.type !== \"integer\" ||\n schema.format !== \"int64\"\n ) {\n return false;\n }\n\n return (\n isOptionalBigint(schema.minimum) &&\n isOptionalBigint(schema.exclusiveMinimum) &&\n isOptionalBigint(schema.maximum) &&\n isOptionalBigint(schema.exclusiveMaximum) &&\n isOptionalBigint(schema.multipleOf) &&\n isOptionalBigint(schema.default) &&\n (schema.enum === undefined || isArrayOf(schema.enum, isSetBigint))\n );\n}\n\n/**\n * Type guard for boolean schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a boolean schema, false otherwise.\n */\nexport function isJsonSchemaBoolean(\n input: unknown\n): input is JsonSchemaBoolean {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return (\n hasValidJsonSchemaKeywords(schema) &&\n schema.type === \"boolean\" &&\n isOptionalBoolean(schema.default)\n );\n}\n\n/**\n * Type guard for date/time schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a date or time schema, false otherwise.\n */\nexport function isJsonSchemaDate(input: unknown): input is JsonSchemaDate {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (!hasValidJsonSchemaKeywords(schema)) {\n return false;\n }\n\n if (schema.anyOf !== undefined) {\n return isArrayOf(schema.anyOf, isJsonSchemaDate);\n }\n\n if (schema.type !== \"integer\" && schema.type !== \"string\") {\n return false;\n }\n\n if (!isSetString(schema.format) || !DATE_FORMAT_SET.has(schema.format)) {\n return false;\n }\n\n return (\n isOptionalNumber(schema.minimum) &&\n isOptionalNumber(schema.maximum) &&\n (schema.default === undefined ||\n isSetString(schema.default) ||\n isSetNumber(schema.default))\n );\n}\n\n/**\n * Type guard for enum-constrained schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is an enum-constrained schema, false otherwise.\n */\nexport function isJsonSchemaEnum(input: unknown): input is JsonSchemaEnum {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (\n !hasValidJsonSchemaKeywords(schema) ||\n !isSetString(schema.type) ||\n !JSON_SCHEMA_PRIMITIVE_TYPE_SET.has(\n schema.type as JsonSchemaPrimitiveType\n ) ||\n !Array.isArray(schema.enum)\n ) {\n return false;\n }\n\n const typeName = schema.type as JsonSchemaPrimitiveType;\n const enumValues = schema.enum;\n const defaultValue = schema.default;\n\n if (typeName === \"string\") {\n return (\n enumValues.every(value => isSetString(value)) &&\n (defaultValue === undefined || isSetString(defaultValue))\n );\n }\n\n if (typeName === \"number\" || typeName === \"integer\") {\n return (\n enumValues.every(value => isSetNumber(value)) &&\n (defaultValue === undefined || isSetNumber(defaultValue))\n );\n }\n\n if (typeName === \"boolean\") {\n return (\n enumValues.every(value => isSetBoolean(value)) &&\n (defaultValue === undefined || isSetBoolean(defaultValue))\n );\n }\n\n return (\n typeName === \"null\" &&\n enumValues.every(value => value === null) &&\n (defaultValue === undefined || defaultValue === null)\n );\n}\n\n/**\n * Type guard for `allOf` composition schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is an `allOf` schema, false otherwise.\n */\nexport function isJsonSchemaAllOf(input: unknown): input is JsonSchemaAllOf {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (\n !hasValidJsonSchemaKeywords(schema) ||\n !isArrayOf(schema.allOf, isJsonSchema)\n ) {\n return false;\n }\n\n return (\n schema.unevaluatedProperties === undefined ||\n isSetBoolean(schema.unevaluatedProperties) ||\n isJsonSchema(schema.unevaluatedProperties)\n );\n}\n\n/**\n * Type guard for literal-value schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a literal-value schema, false otherwise.\n */\nexport function isJsonSchemaLiteral(\n input: unknown\n): input is JsonSchemaLiteral {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (!hasValidJsonSchemaKeywords(schema) || !(\"const\" in schema)) {\n return false;\n }\n\n return (\n schema.type === undefined ||\n (isSetString(schema.type) && isJsonSchemaType(schema.type)) ||\n isOptionalJsonSchemaTypeArray(schema.type)\n );\n}\n\n/**\n * Type guard for map tuple-array schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a map tuple-array schema, false otherwise.\n */\nexport function isJsonSchemaMap(input: unknown): input is JsonSchemaMap {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (\n !hasValidJsonSchemaKeywords(schema) ||\n schema.type !== \"array\" ||\n schema.maxItems !== 125 ||\n !isSetObject(schema.items)\n ) {\n return false;\n }\n\n const items = schema.items as Record<string, unknown>;\n\n return (\n items.type === \"array\" &&\n isTupleOfTwo(items.prefixItems, isJsonSchema, isJsonSchema) &&\n (items.items === undefined || items.items === false) &&\n items.minItems === 2 &&\n items.maxItems === 2\n );\n}\n\n/**\n * Type guard for native enum schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a native enum schema, false otherwise.\n */\nexport function isJsonSchemaNativeEnum(\n input: unknown\n): input is JsonSchemaNativeEnum {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n const isValidType =\n schema.type === \"string\" ||\n schema.type === \"number\" ||\n (Array.isArray(schema.type) &&\n schema.type.length === 2 &&\n schema.type[0] === \"string\" &&\n schema.type[1] === \"number\");\n\n return (\n hasValidJsonSchemaKeywords(schema) &&\n isValidType &&\n Array.isArray(schema.enum) &&\n schema.enum.every(value => isSetString(value) || isSetNumber(value))\n );\n}\n\n/**\n * Type guard for impossible/never schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a never schema, false otherwise.\n */\nexport function isJsonSchemaNever(input: unknown): input is JsonSchemaNever {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return hasValidJsonSchemaKeywords(schema) && isJsonSchemaAny(schema.not);\n}\n\n/**\n * Type guard for `null` schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a null schema, false otherwise.\n */\nexport function isJsonSchemaNull(input: unknown): input is JsonSchemaNull {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return (\n hasValidJsonSchemaKeywords(schema) &&\n schema.type === \"null\" &&\n (schema.const === undefined || schema.const === null) &&\n (schema.enum === undefined ||\n (Array.isArray(schema.enum) && schema.enum.every(v => v === null))) &&\n (schema.default === undefined || schema.default === null)\n );\n}\n\n/**\n * Type guard for nullable schema unions.\n *\n * @param input - The value to check.\n * @returns True if the input is a nullable schema union, false otherwise.\n */\nexport function isJsonSchemaNullable(\n input: unknown\n): input is JsonSchemaNullable {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (!hasValidJsonSchemaKeywords(schema)) {\n return false;\n }\n\n const anyOfBranch =\n schema.anyOf !== undefined &&\n Array.isArray(schema.anyOf) &&\n schema.anyOf.length === 2 &&\n isJsonSchema(schema.anyOf[0]) &&\n isJsonSchemaNull(schema.anyOf[1]);\n\n const typeBranch =\n Array.isArray(schema.type) &&\n schema.type.length === 2 &&\n ((schema.type[0] === \"null\" &&\n isSetString(schema.type[1]) &&\n schema.type[1] !== \"null\" &&\n JSON_SCHEMA_TYPE_SET.has(schema.type[1] as JsonSchemaType)) ||\n (schema.type[1] === \"null\" &&\n isSetString(schema.type[0]) &&\n schema.type[0] !== \"null\" &&\n JSON_SCHEMA_TYPE_SET.has(schema.type[0] as JsonSchemaType)));\n\n return anyOfBranch || typeBranch;\n}\n\n/**\n * Type guard for numeric schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a numeric schema, false otherwise.\n */\nexport function isJsonSchemaNumber(input: unknown): input is JsonSchemaNumber {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (\n !hasValidJsonSchemaKeywords(schema) ||\n (schema.type !== \"number\" && schema.type !== \"integer\")\n ) {\n return false;\n }\n\n return (\n isOptionalString(schema.format) &&\n isOptionalNumber(schema.minimum) &&\n isOptionalNumber(schema.exclusiveMinimum) &&\n isOptionalNumber(schema.maximum) &&\n isOptionalNumber(schema.exclusiveMaximum) &&\n isOptionalNumber(schema.multipleOf) &&\n isOptionalNumber(schema.default) &&\n (schema.enum === undefined || isArrayOf(schema.enum, isSetNumber))\n );\n}\n\n/**\n * Type guard for integer schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is an integer schema, false otherwise.\n */\nexport function isJsonSchemaInteger(\n input: unknown\n): input is JsonSchemaInteger {\n return isJsonSchemaNumber(input) && input.type === \"integer\";\n}\n\n/**\n * Type guard for decimal schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a decimal schema, false otherwise.\n */\nexport function isJsonSchemaDecimal(\n input: unknown\n): input is JsonSchemaDecimal {\n return isJsonSchemaNumber(input) && input.type === \"number\";\n}\n\n/**\n * Type guard for object schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is an object schema, false otherwise.\n */\nexport function isJsonSchemaObject(input: unknown): input is JsonSchemaObject {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return (\n hasValidJsonSchemaKeywords(schema) &&\n schema.type === \"object\" &&\n (schema.properties === undefined ||\n isRecordOfSchemaLike(schema.properties)) &&\n (schema.patternProperties === undefined ||\n isRecordOfSchemaLike(schema.patternProperties)) &&\n (schema.additionalProperties === undefined ||\n isSetBoolean(schema.additionalProperties) ||\n isJsonSchema(schema.additionalProperties)) &&\n (schema.required === undefined || isStringArray(schema.required)) &&\n (schema.unevaluatedProperties === undefined ||\n isSetBoolean(schema.unevaluatedProperties) ||\n isJsonSchema(schema.unevaluatedProperties)) &&\n (schema.dependencies === undefined ||\n (isSetObject(schema.dependencies) &&\n Object.values(schema.dependencies).every(\n item => isStringArray(item) || isJsonSchema(item)\n ))) &&\n (schema.dependentRequired === undefined ||\n isRecordOfStringArrays(schema.dependentRequired)) &&\n (schema.dependentSchemas === undefined ||\n isRecordOfSchemaLike(schema.dependentSchemas)) &&\n isOptionalNumber(schema.minProperties) &&\n isOptionalNumber(schema.maxProperties) &&\n (schema.primaryKey === undefined || isStringArray(schema.primaryKey)) &&\n isOptionalString(schema.databaseSchema)\n );\n}\n\n/**\n * Type guard for string schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a string schema, false otherwise.\n */\nexport function isJsonSchemaString(input: unknown): input is JsonSchemaString {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return (\n hasValidJsonSchemaKeywords(schema) &&\n schema.type === \"string\" &&\n isOptionalNumber(schema.minLength) &&\n isOptionalNumber(schema.maxLength) &&\n isOptionalString(schema.pattern) &&\n isOptionalString(schema.format) &&\n isOptionalString(schema.default) &&\n (schema.enum === undefined || isArrayOf(schema.enum, isSetString)) &&\n isOptionalString(schema.contentMediaType) &&\n isOptionalString(schema.contentEncoding) &&\n isOptionalString(schema.contentSchema)\n );\n}\n\n/**\n * Type guard for set-like array schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a set-like array schema, false otherwise.\n */\nexport function isJsonSchemaSet(input: unknown): input is JsonSchemaSet {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return (\n hasValidJsonSchemaKeywords(schema) &&\n schema.type === \"array\" &&\n schema.uniqueItems === true &&\n isOptionalJsonSchemaArray(schema.prefixItems) &&\n isOptionalJsonSchema(schema.items) &&\n isOptionalJsonSchema(schema.contains) &&\n isOptionalNumber(schema.minItems) &&\n isOptionalNumber(schema.maxItems) &&\n isOptionalNumber(schema.minContains) &&\n isOptionalNumber(schema.maxContains) &&\n (schema.unevaluatedItems === undefined ||\n isSetBoolean(schema.unevaluatedItems) ||\n isJsonSchema(schema.unevaluatedItems))\n );\n}\n\n/**\n * Type guard for record schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a record schema, false otherwise.\n */\nexport function isJsonSchemaRecord(input: unknown): input is JsonSchemaRecord {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return (\n hasValidJsonSchemaKeywords(schema) &&\n schema.type === \"object\" &&\n (schema.patternProperties === undefined ||\n isRecordOfSchemaLike(schema.patternProperties)) &&\n (schema.additionalProperties === undefined ||\n isSetBoolean(schema.additionalProperties) ||\n isJsonSchema(schema.additionalProperties)) &&\n isOptionalJsonSchema(schema.propertyNames)\n );\n}\n\n/**\n * Type guard for tuple schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a tuple schema, false otherwise.\n */\nexport function isJsonSchemaTuple(input: unknown): input is JsonSchemaTuple {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return (\n hasValidJsonSchemaKeywords(schema) &&\n schema.type === \"array\" &&\n isArrayOf(schema.prefixItems, isJsonSchema) &&\n isOptionalNumber(schema.minItems) &&\n isOptionalNumber(schema.maxItems) &&\n isOptionalJsonSchema(schema.items) &&\n isOptionalJsonSchema(schema.contains) &&\n isOptionalBoolean(schema.uniqueItems) &&\n isOptionalNumber(schema.minContains) &&\n isOptionalNumber(schema.maxContains) &&\n (schema.unevaluatedItems === undefined ||\n isSetBoolean(schema.unevaluatedItems) ||\n isJsonSchema(schema.unevaluatedItems))\n );\n}\n\n/**\n * Type guard for undefined-representing schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is an undefined-representing schema, false otherwise.\n */\nexport function isJsonSchemaUndefined(\n input: unknown\n): input is JsonSchemaUndefined {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return (\n hasValidJsonSchemaKeywords(schema) &&\n isJsonSchemaAny(schema.not) &&\n (schema.default === undefined || schema.default === undefined)\n );\n}\n\n/**\n * Type guard for primitive-union schema variants.\n *\n * @param input - The value to check.\n * @returns True if the input is a primitive-union schema variant, false otherwise.\n */\nexport function isJsonSchemaPrimitiveUnion(\n input: unknown\n): input is JsonSchemaPrimitiveUnion {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (!hasValidJsonSchemaKeywords(schema)) {\n return false;\n }\n\n if (\n isSetString(schema.type) &&\n JSON_SCHEMA_PRIMITIVE_TYPE_SET.has(schema.type as JsonSchemaPrimitiveType)\n ) {\n if (schema.enum === undefined) {\n return true;\n }\n\n if (!Array.isArray(schema.enum)) {\n return false;\n }\n\n if (schema.type === \"string\") {\n return (\n schema.enum.every(value => isSetString(value)) &&\n (schema.default === undefined || isSetString(schema.default))\n );\n }\n\n if (schema.type === \"number\") {\n return (\n schema.enum.every(value => isSetNumber(value)) &&\n (schema.default === undefined || isSetNumber(schema.default))\n );\n }\n\n if (schema.type === \"boolean\") {\n return (\n schema.enum.every(value => isSetBoolean(value)) &&\n (schema.default === undefined || isSetBoolean(schema.default))\n );\n }\n\n if (schema.type === \"integer\") {\n if (schema.format !== \"int64\") {\n return false;\n }\n\n return (\n schema.enum.every(value => isSetBigint(value)) &&\n (schema.default === undefined || isSetBigint(schema.default))\n );\n }\n\n return (\n schema.type === \"null\" &&\n schema.enum.every(value => value === null) &&\n (schema.default === undefined || schema.default === null)\n );\n }\n\n return isOptionalPrimitiveTypeArray(schema.type) && schema.type !== undefined;\n}\n\n/**\n * Type guard for union schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a union schema, false otherwise.\n */\nexport function isJsonSchemaUnion(input: unknown): input is JsonSchemaUnion {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return (\n hasValidJsonSchemaKeywords(schema) &&\n (isJsonSchemaPrimitiveUnion(schema) || isJsonSchemaAnyOf(schema))\n );\n}\n\n/**\n * Type guard for permissive unknown schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a permissive unknown schema, false otherwise.\n */\nexport function isJsonSchemaUnknown(\n input: unknown\n): input is JsonSchemaUnknown {\n return isJsonSchemaAny(input);\n}\n\n/**\n * Type guard for `anyOf` composition schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is an `anyOf` schema, false otherwise.\n */\nexport function isJsonSchemaAnyOf(input: unknown): input is JsonSchemaAnyOf {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return (\n hasValidJsonSchemaKeywords(schema) && isArrayOf(schema.anyOf, isJsonSchema)\n );\n}\n\n/**\n * Type guard for reference schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a reference schema, false otherwise.\n */\nexport function isJsonSchemaRef(input: unknown): input is JsonSchemaRef {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return hasValidJsonSchemaKeywords(schema) && isSetString(schema.$ref);\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(input: unknown): input is JsonSchema {\n return (\n isJsonSchemaString(input) ||\n isJsonSchemaInteger(input) ||\n isJsonSchemaDecimal(input) ||\n isJsonSchemaBigint(input) ||\n isJsonSchemaBoolean(input) ||\n isJsonSchemaDate(input) ||\n isJsonSchemaEnum(input) ||\n isJsonSchemaLiteral(input) ||\n isJsonSchemaNativeEnum(input) ||\n isJsonSchemaNull(input) ||\n isJsonSchemaArray(input) ||\n isJsonSchemaObject(input) ||\n isJsonSchemaRecord(input) ||\n isJsonSchemaTuple(input) ||\n isJsonSchemaUnion(input) ||\n isJsonSchemaUndefined(input) ||\n isJsonSchemaRef(input) ||\n isJsonSchemaNever(input) ||\n isJsonSchemaMap(input) ||\n isJsonSchemaAny(input) ||\n isJsonSchemaNullable(input) ||\n isJsonSchemaAllOf(input) ||\n isJsonSchemaUnknown(input) ||\n isJsonSchemaSet(input)\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(input: unknown): input is JsonSchemaNull {\n return isJsonSchemaNull(input);\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 (!isUntypedTypeDescriptor(schema)) {\n return false;\n }\n if (\"id\" in schema && !isSetString(schema.id)) {\n return false;\n }\n if (\"resolve\" in schema && !isFunction(schema.resolve)) {\n return false;\n }\n if (\"properties\" in schema && !isRecordOfUntypedSchema(schema.properties)) {\n return false;\n }\n if (\"required\" in schema && !isStringArray(schema.required)) {\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 (\"tags\" in schema && !isStringArray(schema.tags)) {\n return false;\n }\n if (\n \"args\" in schema &&\n (!Array.isArray(schema.args) ||\n !schema.args.every(item => isUntypedFunctionArg(item)))\n ) {\n return false;\n }\n if (\"returns\" in schema && !isUntypedTypeDescriptor(schema.returns)) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Strict type guard for untyped schema objects.\n *\n * @remarks\n * This guard narrows values to the Untyped schema model while explicitly\n * rejecting values that are also valid JSON Schema instances.\n *\n * @param input - The value to check.\n * @returns True if the input is an untyped schema and not a JSON Schema.\n */\nexport function isUntypedSchemaStrict(input: unknown): input is UntypedSchema {\n return isUntypedSchema(input) && !isJsonSchema(input);\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 * Strict type guard for untyped input objects.\n *\n * @remarks\n * This guard narrows values to the Untyped input-object model while\n * explicitly rejecting values that are valid JSON Schema objects.\n *\n * @param input - The value to check.\n * @returns True if the input is an untyped input object and not JSON Schema.\n */\nexport function isUntypedInputStrict(\n input: unknown\n): input is UntypedInputObject {\n if (!isUntypedInput(input) || isJsonSchema(input)) {\n return false;\n }\n\n const inputObject = input as Record<string, unknown>;\n if (\n \"$schema\" in inputObject &&\n inputObject.$schema !== undefined &&\n !isUntypedSchemaStrict(inputObject.$schema)\n ) {\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(input: unknown): input is Schema {\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\n/**\n * Type guard for extracted schema objects that include source information.\n *\n * @param input - The value to check.\n * @returns True if the input is a SchemaWithSource object, false otherwise.\n */\nexport function isSchemaWithSource(input: unknown): input is SchemaWithSource {\n return (\n isSchema(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\n/**\n * Type guard for Powerlines Schemas that are in Object form.\n *\n * @param input - The value to check.\n * @returns True if the input is a Powerlines Schema object in Object form, false otherwise.\n */\nexport function isSchemaObject(\n input: unknown\n): input is Schema<JsonSchemaObject> {\n return isSchema(input) && isJsonSchemaObject(input.schema);\n}\n","/* -------------------------------------------------------------------\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 { 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 * Keywords whose values are a flat record of named JSON Schema fragments.\n * Each child schema is merged recursively with its counterpart.\n */\nconst SCHEMA_RECORD_KEYWORDS = new Set([\n \"properties\",\n \"patternProperties\",\n \"$defs\",\n \"definitions\",\n \"dependentSchemas\"\n]);\n\n/**\n * Keywords whose value is a single JSON Schema fragment that should be\n * recursively merged when both sides define it.\n */\nconst SCHEMA_SINGLE_KEYWORDS = new Set([\n \"if\",\n \"then\",\n \"else\",\n \"not\",\n \"contains\",\n \"items\",\n \"additionalProperties\",\n \"unevaluatedProperties\",\n \"propertyNames\",\n \"unevaluatedItems\"\n]);\n\n/**\n * Keywords whose values are arrays of JSON Schema fragments that should be\n * concatenated (rather than overridden) during a merge.\n */\nconst SCHEMA_ARRAY_CONCAT_KEYWORDS = new Set([\"allOf\", \"anyOf\", \"oneOf\"]);\n\n/**\n * Recursively merges two JSON Schema fragments. `override` wins for any scalar\n * key that both schemas define, while structured keywords are handled\n * specially:\n *\n * - `properties`, `patternProperties`, `$defs`, `definitions`,\n * `dependentSchemas` — each matching child schema is merged recursively.\n * - `allOf`, `anyOf`, `oneOf` — arrays are concatenated.\n * - `if`, `then`, `else`, `not`, `contains`, `items`,\n * `additionalProperties`, `unevaluatedProperties`, `propertyNames`,\n * `unevaluatedItems` — merged recursively when both sides are schemas.\n * - `required` — arrays are unioned and deduplicated.\n */\nfunction mergeTwo(base: JsonSchema, override: JsonSchema): JsonSchema {\n const baseObj = base as Record<string, unknown>;\n const result: Record<string, unknown> = { ...baseObj };\n\n for (const [key, overrideValue] of Object.entries(\n override as Record<string, unknown>\n )) {\n const baseValue = result[key];\n\n if (key === \"required\") {\n result[key] = getUnique([\n ...(Array.isArray(baseValue) ? (baseValue as string[]) : []),\n ...(Array.isArray(overrideValue) ? (overrideValue as string[]) : [])\n ]);\n } else if (\n SCHEMA_RECORD_KEYWORDS.has(key) &&\n isSetObject(baseValue) &&\n isSetObject(overrideValue)\n ) {\n const merged: Record<string, unknown> = {\n ...(baseValue as Record<string, unknown>)\n };\n for (const [childKey, childOverride] of Object.entries(\n overrideValue as Record<string, unknown>\n )) {\n const childBase = merged[childKey];\n merged[childKey] =\n isJsonSchema(childBase) && isJsonSchema(childOverride)\n ? mergeTwo(childBase, childOverride)\n : childOverride;\n }\n result[key] = merged;\n } else if (\n SCHEMA_ARRAY_CONCAT_KEYWORDS.has(key) &&\n Array.isArray(baseValue) &&\n Array.isArray(overrideValue)\n ) {\n result[key] = [\n ...(baseValue as JsonSchema[]),\n ...(overrideValue as JsonSchema[])\n ];\n } else if (\n SCHEMA_SINGLE_KEYWORDS.has(key) &&\n isJsonSchema(baseValue) &&\n isJsonSchema(overrideValue)\n ) {\n result[key] = mergeTwo(baseValue, overrideValue);\n } else {\n result[key] = overrideValue;\n }\n }\n\n return result;\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\n * into a single JSON Schema object. Later schemas in the argument list take\n * precedence over earlier ones for scalar conflicts.\n *\n * Structured keywords are merged recursively:\n * - Named child schemas (`properties`, `$defs`, etc.) are merged\n * per-property via recursive calls to `merge`.\n * - Composition arrays (`allOf`, `anyOf`, `oneOf`) are concatenated.\n * - Single-schema keywords (`if`, `then`, `else`, `not`, `items`, etc.)\n * are merged recursively when both sides define them.\n * - `required` arrays are unioned and deduplicated.\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 const jsonSchemas = schemas.map(s => getJsonSchema(s));\n if (jsonSchemas.length === 0) {\n return {};\n }\n\n return jsonSchemas.reduce((acc, schema) => {\n const accType = (acc as JsonSchemaLike).type;\n const schemaType = (schema as JsonSchemaLike).type;\n\n if (accType && schemaType && accType !== schemaType) {\n // Incompatible types — the later schema wins entirely.\n return schema;\n }\n\n return mergeTwo(acc, schema);\n });\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","/* -------------------------------------------------------------------\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(schema: JsonSchema): 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(schema: JsonSchema): ValidateFunction {\n const ajv = getValidator(schema);\n\n return ajv.compile(schema);\n}\n","/* -------------------------------------------------------------------\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 { toBool } from \"@stryke/convert/to-bool\";\nimport { isInteger, isObject, isString } from \"@stryke/type-checks\";\nimport { isBoolean } from \"@stryke/type-checks/is-boolean\";\nimport { isNull } from \"@stryke/type-checks/is-null\";\nimport { isNumber } from \"@stryke/type-checks/is-number\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isUndefined } from \"@stryke/type-checks/is-undefined\";\nimport standaloneCode from \"ajv/dist/standalone\";\nimport { getPropertiesList, isSchemaNullable } from \"./helpers\";\nimport { getPrimarySchemaType } from \"./metadata\";\nimport { isJsonSchema, isJsonSchemaObject } from \"./type-checks\";\nimport { JsonSchema, JsonSchemaType } from \"./types\";\nimport { getValidator } from \"./validate\";\n\ninterface JsonSchemaObjectView {\n $ref?: string;\n type?: JsonSchemaType | readonly JsonSchemaType[];\n enum?: readonly unknown[];\n const?: unknown;\n items?: JsonSchema;\n properties?: Record<string, JsonSchema>;\n additionalProperties?: boolean | JsonSchema;\n required?: string[];\n oneOf?: JsonSchema[];\n anyOf?: JsonSchema[];\n allOf?: JsonSchema[];\n}\n\n/**\n * Stringifies a value for generated TypeScript code.\n */\nexport function stringifyValue(\n value?: unknown,\n type?: JsonSchemaType | string\n): string {\n return isUndefined(value)\n ? \"undefined\"\n : isNull(value)\n ? \"null\"\n : type === \"boolean\" || isBoolean(value)\n ? String(toBool(value))\n : type === \"number\" || isNumber(value)\n ? Number.parseFloat(String(value)).toLocaleString(undefined, {\n maximumFractionDigits: 20\n })\n : type === \"integer\"\n ? Number.parseInt(String(value)).toLocaleString()\n : type === \"string\" || type === \"object\" || type === \"array\"\n ? JSON.stringify(value)\n : String(value);\n}\n\n/**\n * Stringifies a JSON Schema fragment into a TypeScript-like type string.\n */\nexport function stringifyType(schema?: JsonSchema): string {\n if (!schema) {\n return \"unknown\";\n }\n\n if (typeof schema === \"boolean\") {\n return schema ? \"unknown\" : \"never\";\n }\n\n const objectSchema = schema as JsonSchemaObjectView;\n\n if (isSetString(objectSchema.$ref)) {\n const match = /^#\\/(?:definitions|\\$defs)\\/(.+)$/.exec(objectSchema.$ref);\n\n return match?.[1] ?? objectSchema.$ref;\n }\n\n const primaryType = getPrimarySchemaType(schema);\n if (primaryType) {\n if (primaryType === \"integer\" || primaryType === \"number\") {\n return \"number\";\n }\n\n return primaryType;\n }\n\n if (objectSchema.type === \"array\" && Array.isArray(objectSchema.enum)) {\n const enumValues = objectSchema.enum as readonly unknown[];\n\n return enumValues\n .map((value: unknown) => JSON.stringify(value))\n .join(\" | \");\n }\n\n if (objectSchema.const !== undefined) {\n return JSON.stringify(objectSchema.const);\n }\n\n if (objectSchema.type === \"array\" || objectSchema.items) {\n return `${stringifyType(objectSchema.items)}[]`;\n }\n\n if (\n objectSchema.type === \"object\" ||\n objectSchema.properties ||\n objectSchema.additionalProperties\n ) {\n if (isJsonSchema(objectSchema.additionalProperties)) {\n return `{ [key: string]: ${stringifyType(objectSchema.additionalProperties)} }`;\n }\n\n if (isJsonSchemaObject(objectSchema)) {\n const required = objectSchema.required ?? [];\n\n return `{ ${getPropertiesList(objectSchema)\n .map(property => {\n const suffix =\n !required.includes(property.name) || isSchemaNullable(property)\n ? `${!required.includes(property.name) ? \"?\" : \"\"}${isSchemaNullable(property) ? \" | null\" : \"\"}`\n : \"\";\n\n return `${property.name}${suffix}: ${stringifyType(property)}`;\n })\n .join(\";\\n\")} }`;\n }\n }\n\n if (objectSchema.oneOf || objectSchema.anyOf) {\n return (objectSchema.oneOf ?? objectSchema.anyOf ?? [])\n .map(branch => stringifyType(branch))\n .join(\" | \");\n }\n\n if (objectSchema.allOf) {\n return \"object\";\n }\n\n return \"unknown\";\n}\n\n/**\n * Returns a string type representation of a value based on its type and an optional JSON Schema primitive type hint.\n *\n * @param value - The value whose type is to be represented as a string.\n * @returns A string representation of the value's type, which may be influenced by the provided JSON Schema primitive type hint. The function handles various JavaScript types and formats them accordingly, including special handling for `undefined`, `null`, booleans, numbers (with formatting), strings, objects, and arrays. If a specific type hint is provided, it will take precedence in determining the string representation of the value.\n */\nexport function getJsonSchemaType(value?: unknown): JsonSchemaType | undefined {\n return isNull(value)\n ? \"null\"\n : isBoolean(value)\n ? \"boolean\"\n : isInteger(value)\n ? \"integer\"\n : isNumber(value)\n ? \"number\"\n : isString(value)\n ? \"string\"\n : isObject(value)\n ? \"object\"\n : Array.isArray(value)\n ? \"array\"\n : undefined;\n}\n\n/**\n * Generates standalone JSON Schema validation code using Ajv.\n */\nexport async function generateCode(\n schemas: JsonSchema,\n refsOrFuncts?: Parameters<typeof standaloneCode>[1]\n) {\n const ajv = getValidator(schemas);\n\n return standaloneCode(ajv, refsOrFuncts);\n}\n","/* -------------------------------------------------------------------\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 { Context } from \"@powerlines/core\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { extractHash, extractVariant } from \"./extract\";\nimport { isSchema } from \"./type-checks\";\nimport { Schema, SchemaInput } from \"./types\";\n\n/**\n * A helper function to get the cache directory path for storing schemas. This function takes a context object as input and returns the path to the cache directory where schemas are stored. The cache directory is constructed by joining the `cachePath` property from the context with a subdirectory named \"schemas\". This function is useful for centralizing the logic for determining where schema files should be cached, ensuring that all schema-related file operations use a consistent location for storing and retrieving cached schemas.\n *\n * @param context - The context object providing access to the cache path.\n * @returns The path to the cache directory for storing schemas, constructed by joining the context's `cachePath` with the \"schemas\" subdirectory.\n */\nexport function getCacheDirectory(context: Context): string {\n return joinPaths(context.cachePath, \"schemas\");\n}\n\n/**\n * A helper function to get the file path for a cached schema based on the provided context and schema input. This function first extracts the variant and hash from the input schema using the `extractVariant` and `extractHash` functions, respectively. It then constructs the file path to the cached schema JSON file by joining the cache directory path (obtained from the `getCacheDirectory` function) with a filename derived from the extracted hash. The resulting file path points to where the cached schema should be stored or retrieved from in the file system. This function is essential for ensuring that all operations related to caching schemas use a consistent method for determining the correct file path based on the schema's unique identifier (hash).\n *\n * @param context - The context object providing access to the cache path.\n * @param input - The input schema from which to extract the variant and hash for constructing the cache file path.\n * @returns The file path to the cached schema JSON file, constructed by joining the cache directory path with a filename derived from the extracted hash of the schema input.\n */\nexport function getCacheFilePath(context: Context, input: SchemaInput): string {\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n\n return joinPaths(getCacheDirectory(context), `${hash}.json`);\n}\n\n/**\n * Writes a given schema to the file system using the provided context. This function first checks if the input is a valid schema using the `isSchema` type guard. If the input is not a valid schema, it throws an error indicating that the provided input is invalid. If the input is valid, it proceeds to write the schema to a JSON file in the cache directory specified by the context. The file is named using the hash of the schema to ensure uniqueness and easy retrieval in future operations. The schema is serialized to JSON format before being written to the file system. This function is asynchronous and returns a promise that resolves once the writing operation is complete.\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param schema - The schema to be written to the file system, which must be a valid schema object containing a `variant`, `schema`, and `hash` property.\n * @throws Will throw an error if the provided input is not a valid schema.\n */\nexport async function writeSchema(context: Context, schema: Schema) {\n if (!isSchema(schema)) {\n throw new Error(\n `The provided input is not a valid schema. A valid schema must have a \"variant\" property indicating the type of the input and a \"schema\" property containing the parsed JSON Schema object.`\n );\n }\n\n await context.fs.write(\n getCacheFilePath(context, schema),\n JSON.stringify(schema.schema)\n );\n}\n\n/**\n * A helper function to read a schema from the file system using the provided context. This function first extracts the variant and hash from the input schema using the `extractVariant` and `extractHash` functions, respectively. It then constructs the file path to the cached schema JSON file based on the cache path provided in the context and the extracted hash. The function checks if the file exists in the cache; if it does not exist, it returns `undefined`. If the file exists, it reads the contents of the file, parses it as JSON, and returns the resulting object. This function is asynchronous and returns a promise that resolves to either the parsed schema object or `undefined` if the schema is not found in the cache.\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param input - The input schema from which to extract the variant and hash for locating the cached schema file.\n * @returns A promise that resolves to the parsed schema object if found in the cache, or `undefined` if the schema does not exist in the cache.\n */\nexport async function readSchemaSafe(\n context: Context,\n input: SchemaInput\n): Promise<Schema | undefined> {\n const cacheFilePath = getCacheFilePath(context, input);\n if (!(await context.fs.exists(cacheFilePath))) {\n return undefined;\n }\n\n const data = await context.fs.read(cacheFilePath);\n if (!data) {\n return undefined;\n }\n\n return JSON.parse(data);\n}\n\n/**\n * Reads a schema from the file system using the provided context and input. This function first attempts to read the schema using the `readSchemaSafe` helper function, which returns `undefined` if the schema is not found in the cache. If the schema is not found, this function throws an error indicating that the schema with the specified variant and hash does not exist in the cache. The error message suggests that this may be due to a missing or corrupted cache file, or because the schema has not been written to the cache yet. It advises ensuring that the schema is properly written to the cache before attempting to read it. If the schema is successfully read from the cache, it is returned as a parsed object. This function is asynchronous and returns a promise that resolves to the parsed schema object if found, or throws an error if the schema is not found in the cache.\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param input - The input schema from which to extract the variant and hash for locating the cached schema file.\n * @returns A promise that resolves to the parsed schema object if found in the cache, or throws an error if the schema does not exist in the cache.\n * @throws Will throw an error if the schema with the specified variant and hash does not exist in the cache.\n */\nexport async function readSchema(\n context: Context,\n input: SchemaInput\n): Promise<Schema> {\n const schema = await readSchemaSafe(context, input);\n if (!schema) {\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n\n throw new Error(\n `The ${variant} schema with hash \"${\n hash\n }\" does not exist in the cache. This may be due to a missing or corrupted cache file, or because the schema has not been written to the cache yet. Please ensure that the schema is properly written to the cache before attempting to read it.`\n );\n }\n\n return schema;\n}\n","/* -------------------------------------------------------------------\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 {\n TagsReflection,\n Type,\n TypeClass\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n ReflectionClass,\n ReflectionKind,\n TypeNumberBrand,\n TypeObjectLiteral\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n isBigInt,\n isBoolean,\n isInteger,\n isNull,\n isNumber,\n isRegExp,\n isSetArray,\n isSetObject,\n isSetString,\n isString,\n isUndefined\n} from \"@stryke/type-checks\";\nimport defu from \"defu\";\nimport { getJsonSchemaType } from \"./codegen\";\nimport {\n isJsonSchemaObject,\n isJsonSchemaPrimitiveType,\n isNullOnlyJsonSchema\n} from \"./type-checks\";\nimport {\n JsonSchema,\n JsonSchemaNullable,\n JsonSchemaObject,\n JsonSchemaPrimitiveType\n} from \"./types\";\n\n/**\n * Maps a Deepkit numeric `brand` to JSON Schema `type` and `format`.\n *\n * @remarks\n * This function takes a `TypeNumberBrand` (which represents specific numeric types in Deepkit, such as `integer`, `float`, `int8`, etc.) and returns a corresponding JSON Schema fragment that includes the appropriate `type`, `format`, and any relevant keywords (like `multipleOf` for integers). If the brand is not recognized, it defaults to a generic JSON Schema for numbers.\n *\n * @param brand - The Deepkit numeric brand to convert.\n * @return A JSON Schema fragment representing the numeric type corresponding to the provided brand.\n */\nfunction numberBrandToJsonSchema(\n brand: TypeNumberBrand | undefined\n): JsonSchema {\n switch (brand) {\n case TypeNumberBrand.integer:\n return {\n type: \"integer\",\n format: \"int32\",\n multipleOf: 1\n };\n case TypeNumberBrand.int8:\n return { type: \"integer\", format: \"int8\", multipleOf: 1 };\n case TypeNumberBrand.uint8:\n return { type: \"integer\", format: \"uint8\", multipleOf: 1 };\n case TypeNumberBrand.int16:\n return { type: \"integer\", format: \"int16\", multipleOf: 1 };\n case TypeNumberBrand.uint16:\n return { type: \"integer\", format: \"uint16\", multipleOf: 1 };\n case TypeNumberBrand.int32:\n return { type: \"integer\", format: \"int32\", multipleOf: 1 };\n case TypeNumberBrand.uint32:\n return { type: \"integer\", format: \"uint32\", multipleOf: 1 };\n case TypeNumberBrand.float:\n case TypeNumberBrand.float32:\n return { type: \"number\", format: \"float\" };\n case TypeNumberBrand.float64:\n return { type: \"number\", format: \"double\" };\n case undefined:\n default:\n return { type: \"number\" };\n }\n}\n\nfunction withReflectionTags(reflection: Type, schema: JsonSchema): JsonSchema {\n if (\n !isSetObject(schema) ||\n !isSetObject((reflection as { tags?: TagsReflection })?.tags)\n ) {\n return schema;\n }\n\n const updatedSchema = { ...schema };\n const tags = (reflection as { tags: TagsReflection }).tags;\n if (isSetString(tags.title)) {\n updatedSchema.title = tags.title;\n }\n if (isSetArray(tags.alias)) {\n updatedSchema.alias = tags.alias;\n }\n if (!isUndefined(tags.hidden)) {\n updatedSchema.hidden = tags.hidden;\n }\n if (!isUndefined(tags.ignore)) {\n updatedSchema.ignore = tags.ignore;\n }\n if (!isUndefined(tags.internal)) {\n updatedSchema.internal = tags.internal;\n }\n if (!isUndefined(tags.runtime)) {\n updatedSchema.runtime = tags.runtime;\n }\n if (!isUndefined(tags.readonly)) {\n updatedSchema.readOnly = tags.readonly;\n }\n\n return updatedSchema;\n}\n\nfunction withNullable(schema: JsonSchema): JsonSchemaNullable {\n if (!isSetObject(schema)) {\n return {\n anyOf: [schema, { type: \"null\", default: null }]\n };\n }\n\n const rawType = (schema as { type?: string | readonly string[] }).type;\n\n const types = Array.isArray(rawType)\n ? [...rawType]\n : rawType\n ? [rawType]\n : [];\n if (!types.includes(\"null\")) {\n types.push(\"null\");\n }\n\n return {\n ...schema,\n type: types.length === 1 ? types[0] : types\n };\n}\n\n/**\n * Converts a Deepkit type reflection into a JSON Schema (draft-07) fragment.\n */\nexport function reflectionToJsonSchema(\n reflection: Type\n): JsonSchema | undefined {\n return reflectionToJsonSchemaInner(reflection);\n}\n\nfunction reflectionToJsonSchemaInner(reflection: Type): JsonSchema | undefined {\n switch (reflection.kind) {\n case ReflectionKind.any:\n case ReflectionKind.unknown:\n case ReflectionKind.void:\n case ReflectionKind.object:\n return withReflectionTags(reflection, { name: reflection.typeName });\n case ReflectionKind.never:\n return undefined;\n case ReflectionKind.undefined:\n case ReflectionKind.null:\n return withReflectionTags(reflection, {\n type: \"null\",\n name: reflection.typeName,\n default: null\n });\n case ReflectionKind.string:\n return withReflectionTags(reflection, {\n type: \"string\",\n name: reflection.typeName\n });\n case ReflectionKind.boolean:\n return withReflectionTags(reflection, {\n type: \"boolean\",\n name: reflection.typeName\n });\n case ReflectionKind.number: {\n const numeric = numberBrandToJsonSchema(reflection.brand);\n\n return withReflectionTags(reflection, numeric);\n }\n case ReflectionKind.bigint:\n return withReflectionTags(reflection, {\n type: \"integer\",\n name: reflection.typeName,\n format: \"int64\"\n });\n case ReflectionKind.regexp:\n return withReflectionTags(reflection, {\n type: \"string\",\n name: reflection.typeName,\n format: \"regex\",\n contentMediaType: \"text/regex\"\n });\n case ReflectionKind.literal: {\n const { literal } = reflection;\n if (isBigInt(literal)) {\n return withReflectionTags(reflection, {\n type: \"integer\",\n name: reflection.typeName,\n format: \"int64\",\n const: literal\n });\n }\n\n if (isRegExp(literal)) {\n return withReflectionTags(reflection, {\n type: \"string\",\n name: reflection.typeName,\n format: \"regex\",\n const: literal.source\n });\n }\n\n return withReflectionTags(reflection, {\n type: getJsonSchemaType(literal),\n name: reflection.typeName,\n const: literal\n });\n }\n case ReflectionKind.templateLiteral:\n return withReflectionTags(reflection, { type: \"string\" });\n case ReflectionKind.enum: {\n const values = reflection.values.filter(\n value =>\n isString(value) ||\n isInteger(value) ||\n isBigInt(value) ||\n isNumber(value) ||\n isBoolean(value) ||\n isNull(value)\n ) as (string | number | bigint | boolean | null)[];\n if (values.length === 0) {\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n description: reflection.description,\n enum: []\n });\n }\n\n return withReflectionTags(reflection, {\n type: values.every(value => isString(value))\n ? \"string\"\n : values.every(value => isInteger(value) || isBigInt(value))\n ? \"integer\"\n : values.every(value => isNumber(value))\n ? \"number\"\n : values.every(value => isBoolean(value))\n ? \"boolean\"\n : values.every(value => isNull(value))\n ? \"null\"\n : values.reduce((ret, value) => {\n const type = getJsonSchemaType(value);\n if (\n isJsonSchemaPrimitiveType(type) &&\n !ret.includes(type)\n ) {\n ret.push(type);\n }\n\n return ret;\n }, [] as JsonSchemaPrimitiveType[]),\n name: reflection.typeName,\n description: reflection.description,\n enum: values,\n default: values.length === 1 ? values[0] : undefined\n });\n }\n case ReflectionKind.array: {\n const items = reflectionToJsonSchemaInner(reflection.type);\n\n return withReflectionTags(reflection, {\n type: \"array\",\n name: reflection.typeName,\n items: items ?? {}\n });\n }\n case ReflectionKind.tuple: {\n const items = reflection.types\n .map(member => reflectionToJsonSchemaInner(member.type))\n .filter((item): item is JsonSchema => item !== undefined);\n if (items.length <= 1) {\n return withReflectionTags(reflection, {\n type: \"array\",\n name: reflection.typeName,\n items: items.length === 1 ? items[0] : {}\n });\n }\n\n return withReflectionTags(reflection, {\n type: \"array\",\n name: reflection.typeName,\n prefixItems: items,\n minItems: items.length,\n maxItems: items.length\n });\n }\n case ReflectionKind.union: {\n const branches = reflection.types\n .map(inner => reflectionToJsonSchemaInner(inner))\n .filter((branch): branch is JsonSchema => branch !== undefined);\n if (\n !reflection.types.some(\n inner =>\n inner.kind === ReflectionKind.null ||\n inner.kind === ReflectionKind.undefined\n )\n ) {\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n anyOf: branches\n });\n }\n\n const nonNull = branches.filter(branch => !isNullOnlyJsonSchema(branch));\n if (nonNull.length === 0) {\n return withReflectionTags(reflection, {\n type: \"null\",\n default: null\n });\n }\n\n if (nonNull.length === 1) {\n const first = nonNull[0]!;\n\n if (!isSetObject(first)) {\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n anyOf: [first]\n })\n );\n }\n\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n ...(first as Record<string, unknown>)\n })\n );\n }\n\n const enumValues = nonNull\n .map(branch =>\n isSetObject(branch)\n ? (branch as { const?: unknown }).const\n : undefined\n )\n .filter(\n (value): value is string | number | bigint | boolean | null =>\n value === null ||\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"bigint\" ||\n typeof value === \"boolean\"\n );\n if (enumValues.length === nonNull.length) {\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n enum: enumValues\n })\n );\n }\n\n const discriminator = tryReflectionDiscriminator(reflection.types);\n if (discriminator && isSetObject(discriminator)) {\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n ...(discriminator as Record<string, unknown>)\n })\n );\n }\n\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n anyOf: nonNull\n })\n );\n }\n case ReflectionKind.intersection: {\n const members = reflection.types\n .map(inner => reflectionToJsonSchemaInner(inner))\n .filter((item): item is JsonSchema => item !== undefined);\n if (members.length === 0) {\n return undefined;\n }\n if (members.length === 1) {\n if (!isSetObject(members[0])) {\n return members[0];\n }\n\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n ...members[0]\n });\n }\n if (members.every(isJsonSchemaObject)) {\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n ...mergeObjectSchemas(members)\n });\n }\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n allOf: members\n });\n }\n case ReflectionKind.promise:\n return reflectionToJsonSchemaInner(reflection.type);\n case ReflectionKind.objectLiteral:\n return objectReflectionToJsonSchema(reflection);\n case ReflectionKind.class: {\n const classType = reflection.classType as { name?: string } | undefined;\n const className = classType?.name;\n switch (className) {\n case \"Date\":\n return withReflectionTags(reflection, {\n type: \"string\",\n format: \"date-time\"\n });\n case \"RegExp\":\n return withReflectionTags(reflection, {\n type: \"string\",\n format: \"regex\"\n });\n case \"URL\":\n return withReflectionTags(reflection, {\n type: \"string\",\n format: \"uri\"\n });\n case \"Set\": {\n const itemType = reflection.arguments?.[0];\n const items = itemType\n ? reflectionToJsonSchemaInner(itemType)\n : undefined;\n\n return withReflectionTags(reflection, {\n type: \"array\",\n items: items ?? {},\n uniqueItems: true\n });\n }\n case \"Map\": {\n const valueType = reflection.arguments?.[1];\n const values = valueType\n ? reflectionToJsonSchemaInner(valueType)\n : undefined;\n\n return withReflectionTags(reflection, {\n type: \"object\",\n additionalProperties: values ?? true\n });\n }\n case \"Uint8Array\":\n case \"Uint8ClampedArray\":\n case \"Uint16Array\":\n case \"Uint32Array\":\n case \"Int8Array\":\n case \"Int16Array\":\n case \"Int32Array\":\n case \"Float32Array\":\n case \"Float64Array\":\n case \"BigInt64Array\":\n case \"BigUint64Array\":\n return withReflectionTags(reflection, {\n type: \"string\",\n format: \"byte\",\n contentEncoding: \"base64\"\n });\n case undefined:\n default:\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n description: reflection.description,\n ...objectReflectionToJsonSchema(reflection)\n });\n }\n }\n case ReflectionKind.symbol:\n case ReflectionKind.property:\n case ReflectionKind.method:\n case ReflectionKind.function:\n case ReflectionKind.parameter:\n case ReflectionKind.typeParameter:\n case ReflectionKind.tupleMember:\n case ReflectionKind.enumMember:\n case ReflectionKind.rest:\n case ReflectionKind.indexSignature:\n case ReflectionKind.propertySignature:\n case ReflectionKind.methodSignature:\n case ReflectionKind.infer:\n case ReflectionKind.callSignature:\n default:\n return undefined;\n }\n}\n\nfunction mergeObjectSchemas(schemas: JsonSchemaObject[]): JsonSchemaObject {\n const merged: JsonSchemaObject = {\n type: \"object\",\n properties: {},\n required: []\n };\n\n for (const schema of schemas) {\n if (schema.properties) {\n merged.properties = defu(merged.properties, schema.properties);\n }\n if (schema.required) {\n merged.required = Array.from(\n new Set([...(merged.required ?? []), ...schema.required])\n );\n }\n if (schema.additionalProperties !== undefined) {\n merged.additionalProperties = schema.additionalProperties;\n }\n }\n\n if ((merged.required?.length ?? 0) === 0) {\n delete merged.required;\n }\n\n return merged;\n}\n\nfunction tryReflectionDiscriminator(\n types: readonly Type[]\n): JsonSchema | undefined {\n const nonNullTypes = types.filter(\n t => t.kind !== ReflectionKind.null && t.kind !== ReflectionKind.undefined\n );\n const objectBranches: Array<TypeObjectLiteral | TypeClass> =\n nonNullTypes.filter(\n t =>\n t.kind === ReflectionKind.objectLiteral ||\n t.kind === ReflectionKind.class\n );\n\n if (\n objectBranches.length < 2 ||\n objectBranches.length !== nonNullTypes.length\n ) {\n return undefined;\n }\n\n let tagKey: string | undefined;\n const branches: JsonSchemaObject[] = [];\n\n for (const branch of objectBranches) {\n const literalProps: Array<{ name: string; literal: string }> = [];\n for (const member of branch.types) {\n if (\n (member.kind === ReflectionKind.property ||\n member.kind === ReflectionKind.propertySignature) &&\n typeof member.name === \"string\" &&\n member.type.kind === ReflectionKind.literal &&\n typeof (member.type as { literal?: unknown }).literal === \"string\"\n ) {\n literalProps.push({\n name: member.name,\n literal: (member.type as { literal: string }).literal\n });\n }\n }\n\n if (literalProps.length === 0) {\n return undefined;\n }\n\n const first = literalProps[0]!;\n if (!tagKey) {\n tagKey = first.name;\n } else if (tagKey !== first.name) {\n return undefined;\n }\n\n const filteredBranch = {\n ...branch,\n types: branch.types.filter(\n member =>\n !(\n (member.kind === ReflectionKind.property ||\n member.kind === ReflectionKind.propertySignature) &&\n member.name === tagKey\n )\n )\n } as TypeObjectLiteral | TypeClass;\n\n const body = objectReflectionToJsonSchema(filteredBranch);\n if (!body || !isJsonSchemaObject(body)) {\n return undefined;\n }\n\n branches.push({\n type: \"object\",\n properties: {\n [tagKey]: { const: first.literal },\n ...(body.properties ?? {})\n },\n required: [tagKey, ...(body.required ?? [])],\n additionalProperties: body.additionalProperties ?? false\n });\n }\n\n if (!tagKey) {\n return undefined;\n }\n\n return {\n oneOf: branches,\n discriminator: { propertyName: tagKey }\n } as JsonSchema;\n}\n\nfunction objectReflectionToJsonSchema(\n type: TypeObjectLiteral | TypeClass\n): JsonSchemaObject {\n const reflection = ReflectionClass.from(type);\n\n const schema: JsonSchemaObject = {\n type: \"object\",\n name: reflection.getName(),\n description: reflection.getDescription(),\n properties: {},\n required: [],\n readOnly: reflection.isReadonly(),\n ignore: reflection.isIgnored(),\n internal: reflection.isInternal(),\n runtime: reflection.isRuntime(),\n hidden: reflection.isHidden(),\n primaryKey: reflection\n .getPrimaries()\n .map(primary => primary.getNameAsString()),\n ...(isSetString(reflection.databaseSchemaName)\n ? { databaseSchemaName: reflection.databaseSchemaName }\n : {}),\n ...(isSetString(reflection.getName())\n ? { name: reflection.getName() }\n : {}),\n ...(isSetString(reflection.getDescription())\n ? { description: reflection.getDescription() }\n : {}),\n ...(isSetArray(reflection.getAlias())\n ? { alias: reflection.getAlias() }\n : {}),\n ...(isSetString(reflection.getTitle())\n ? { title: reflection.getTitle() }\n : {})\n };\n\n for (const propertyReflection of reflection.getProperties()) {\n if (propertyReflection.getKind() === ReflectionKind.indexSignature) {\n schema.additionalProperties =\n reflectionToJsonSchemaInner(propertyReflection.type) ?? true;\n continue;\n }\n\n let property = reflectionToJsonSchemaInner(\n propertyReflection.type\n ) as JsonSchema;\n if (!property) {\n continue;\n }\n\n const propertySchema = isSetObject(property) ? property : {};\n\n property = {\n ...propertySchema,\n name: propertyReflection.getNameAsString(),\n description: propertyReflection.getDescription(),\n readOnly: propertyReflection.isReadonly(),\n ignore: propertyReflection.isIgnored(),\n internal: propertyReflection.isInternal(),\n runtime: propertyReflection.isRuntime(),\n hidden: propertyReflection.isHidden(),\n ...(propertyReflection.hasDefault()\n ? { default: propertyReflection.getDefaultValue() }\n : {}),\n ...(isSetArray(propertyReflection.getGroups())\n ? { tags: propertyReflection.getGroups() }\n : {}),\n ...(isSetArray(propertyReflection.getAlias())\n ? { alias: propertyReflection.getAlias() }\n : {}),\n ...(isSetString(propertyReflection.getTitle())\n ? { title: propertyReflection.getTitle() }\n : {})\n };\n\n if (propertyReflection.isNullable()) {\n property = withNullable(property);\n }\n\n schema.properties ??= {};\n schema.properties[propertyReflection.name] = property;\n if (!propertyReflection.isOptional()) {\n schema.required ??= [];\n schema.required.push(propertyReflection.name);\n }\n }\n\n return schema;\n}\n","/* -------------------------------------------------------------------\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 { PluginContext, UnresolvedContext } from \"@powerlines/core\";\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport { reflect, Type } from \"@powerlines/deepkit/vendor/type\";\nimport { extractFileReference } from \"@stryke/convert/extract-file-reference\";\nimport { findFileDotExtension, findFileExtensionSafe } from \"@stryke/path/find\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { FileReference, FileReferenceInput } from \"@stryke/types/configuration\";\nimport defu from \"defu\";\nimport { parse as parseToml } from \"smol-toml\";\nimport { parse as parseYaml } from \"yaml\";\nimport { bundle, BundleOptions } from \"./bundle\";\n\n/**\n * Compiles a type definition to a module and returns the module.\n *\n * @param context - The context object containing the environment paths.\n * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.\n * @param overrides - Optional overrides for the ESBuild configuration.\n * @returns A promise that resolves to the compiled module.\n */\nexport async function resolveModule<\n TResult,\n TContext extends UnresolvedContext = UnresolvedContext\n>(\n context: TContext,\n input: FileReferenceInput,\n overrides?: BundleOptions\n): Promise<TResult> {\n const fileReference = extractFileReference(input);\n if (!fileReference) {\n throw new Error(\n `Failed to extract a file reference from the provided input ${JSON.stringify(\n input\n )}. The input must be a string or an object with a \"file\" property that specifies the file path and optional export name.`\n );\n }\n\n const result = await bundle<TContext>(context, fileReference.file, overrides);\n\n let resolved: any;\n try {\n resolved = await context.resolver.evalModule(result.text, {\n filename: result.path,\n ext: findFileDotExtension(result.path)\n });\n } catch (error) {\n if (\n isSetString((error as Error).message) &&\n new RegExp(\n `Cannot find module '${context.config.framework?.name || \"powerlines\"}:.*'`\n ).test((error as Error).message)\n ) {\n const moduleName = (error as Error).message.match(\n new RegExp(\n `Cannot find module '(${context.config.framework?.name || \"powerlines\"}:.*)'`\n )\n )?.[1];\n throw new Error(\n `The module \"${moduleName}\" could not be resolved while evaluating \"${\n fileReference.file\n }\". It is possible the required built-in modules have not yet been generated. Please check the order of your plugins. ${\n context.config.logLevel.general === \"debug\" ||\n context.config.logLevel.general === \"trace\"\n ? `\n\nBundle output for module:\n${result.text}`\n : \"\"\n }`\n );\n }\n\n throw new Error(\n `Failed to evaluate the bundled module for \"${\n fileReference.file\n }\". Error: ${(error as Error).message}${\n context.config.logLevel.general === \"debug\" ||\n context.config.logLevel.general === \"trace\"\n ? `\n\nBundle output for module:\n${result.text}`\n : \"\"\n }`\n );\n }\n\n return resolved;\n}\n\n/**\n * Compiles a type definition to a module and returns the specified export from the module.\n *\n * @param context - The context object containing the environment paths.\n * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.\n * @param options - Optional overrides for the ESBuild configuration.\n * @returns A promise that resolves to the compiled module.\n */\nexport async function resolve<\n TResult,\n TContext extends UnresolvedContext = UnresolvedContext\n>(\n context: TContext,\n input: FileReferenceInput,\n options?: BundleOptions\n): Promise<TResult> {\n const fileReference = extractFileReference(input);\n if (!fileReference) {\n throw new Error(\n `Failed to extract a file reference from the provided input. The input must be a string or an object with a \"file\" property that specifies the file path and optional export name.`\n );\n }\n\n const extension = findFileExtensionSafe(fileReference.file);\n if (extension.startsWith(\"json\")) {\n try {\n const json = await context.fs.read(fileReference.file);\n if (!isSetString(json)) {\n throw new Error(\n `The file at \"${fileReference.file}\" could not be read as a string. Please ensure the file exists and contains valid JSON.`\n );\n }\n\n return JSON.parse(json) as TResult;\n } catch (error) {\n throw new Error(\n `Failed to read or parse the JSON file at \"${fileReference.file}\". Please ensure the file exists and contains valid JSON. Error: ${(error as Error).message}`\n );\n }\n } else if (extension === \"yaml\" || extension === \"yml\") {\n try {\n const yaml = await context.fs.read(fileReference.file);\n if (!isSetString(yaml)) {\n throw new Error(\n `The file at \"${fileReference.file}\" could not be read as a string. Please ensure the file exists and contains valid YAML.`\n );\n }\n\n return parseYaml(yaml) as TResult;\n } catch (error) {\n throw new Error(\n `Failed to read or parse the YAML file at \"${fileReference.file}\". Please ensure the file exists and contains valid YAML. Error: ${(error as Error).message}`\n );\n }\n } else if (extension === \"toml\") {\n try {\n const toml = await context.fs.read(fileReference.file);\n if (!isSetString(toml)) {\n throw new Error(\n `The file at \"${fileReference.file}\" could not be read as a string. Please ensure the file exists and contains valid TOML.`\n );\n }\n\n return parseToml(toml) as TResult;\n } catch (error) {\n throw new Error(\n `Failed to read or parse the TOML file at \"${fileReference.file}\". Please ensure the file exists and contains valid TOML. Error: ${(error as Error).message}`\n );\n }\n }\n\n const resolved = await resolveModule<Record<string, any>, TContext>(\n context,\n fileReference,\n options\n );\n\n let exportName = fileReference.export;\n if (!exportName) {\n exportName = \"default\";\n }\n\n const resolvedExport = resolved[exportName] ?? resolved[`__Ω${exportName}`];\n if (resolvedExport === undefined) {\n throw new Error(\n `The export \"${exportName}\" could not be resolved in the \"${\n fileReference.file\n }\" module. ${\n Object.keys(resolved).length === 0\n ? `After bundling, no exports were found in the module. Please ensure that the \"${\n fileReference.file\n }\" module has a \"${exportName}\" export with the desired value.`\n : `After bundling, the available exports were: ${Object.keys(\n resolved\n ).join(\n \", \"\n )}. Please ensure that the export exists and is correctly named.`\n }`\n );\n }\n\n return resolvedExport;\n}\n\n/**\n * Resolves a type definition to a Deepkit Type reflection. This function compiles the provided type definition to a module, evaluates the module to get the specified export, and then reflects the export to get its Deepkit Type reflection.\n *\n * @param context - The context object containing the environment paths.\n * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.\n * @param options - Optional overrides for the ESBuild configuration.\n * @returns A promise that resolves to the Deepkit Type reflection.\n */\nexport async function resolveReflection<\n TContext extends PluginContext = PluginContext\n>(\n context: TContext,\n input: FileReference,\n options?: BundleOptions\n): Promise<Type> {\n return reflect(\n await resolve<Type>(\n context,\n input,\n defu(options, {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n level: \"all\"\n })\n ]\n })\n )\n );\n}\n","/* -------------------------------------------------------------------\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 { Context } from \"@powerlines/core\";\nimport { isFileReference } from \"@powerlines/core\";\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport {\n isType,\n reflect,\n stringifyType,\n Type\n} from \"@powerlines/deepkit/vendor/type\";\nimport { StandardJSONSchemaV1 } from \"@standard-schema/spec\";\nimport { extractFileReference } from \"@stryke/convert/extract-file-reference\";\nimport { murmurhash } from \"@stryke/hash\";\nimport { deepClone } from \"@stryke/helpers/deep-clone\";\nimport { isStandardJsonSchema } from \"@stryke/json\";\nimport { findFileExtensionSafe } from \"@stryke/path/find\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { list } from \"@stryke/string-format/list\";\nimport { isSetString } from \"@stryke/type-checks\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { FileReferenceInput } from \"@stryke/types\";\nimport {\n extractJsonSchema as extractJsonSchemaZod,\n isZod3Type\n} from \"@stryke/zod\";\nimport { toJsonSchema } from \"@valibot/to-json-schema\";\nimport defu from \"defu\";\nimport * as z3 from \"zod/v3\";\nimport { BundleOptions } from \"./bundle\";\nimport { VALID_SOURCE_FILE_EXTENSIONS } from \"./constants\";\nimport { getCacheDirectory, writeSchema } from \"./persistence\";\nimport { reflectionToJsonSchema } from \"./reflection\";\nimport { resolve } from \"./resolve\";\nimport {\n isJsonSchema,\n isJsonSchemaObject,\n isSchema,\n isSchemaWithSource,\n isUntypedInput,\n isUntypedInputStrict,\n isUntypedSchema,\n isUntypedSchemaStrict,\n isValibotSchema\n} from \"./type-checks\";\nimport {\n ExtractedSchema,\n JsonSchema,\n Schema,\n SchemaInput,\n SchemaInputVariant,\n SchemaSource,\n SchemaSourceInput,\n SchemaSourceVariant,\n UntypedInputObject,\n UntypedSchema,\n ValibotSchema\n} from \"./types\";\n\nconst SCHEMA_BUNDLE_BASE_URI = \"https://powerlines.invalid/\";\n\nfunction normalizeUri(uri: string): string {\n return uri.endsWith(\"#\") ? uri.slice(0, -1) : uri;\n}\n\nfunction stripUriFragment(uri: string): string {\n const hashIndex = uri.indexOf(\"#\");\n\n return hashIndex >= 0 ? uri.slice(0, hashIndex) : uri;\n}\n\nfunction escapeJsonPointerToken(token: string): string {\n return token.replaceAll(\"~\", \"~0\").replaceAll(\"/\", \"~1\");\n}\n\nfunction toJsonPointer(path: string[]): string {\n if (path.length === 0) {\n return \"\";\n }\n\n return `/${path.map(segment => escapeJsonPointerToken(segment)).join(\"/\")}`;\n}\n\nfunction resolveUri(reference: string, baseUri: string): string {\n try {\n return normalizeUri(new URL(reference, baseUri).toString());\n } catch {\n return normalizeUri(reference);\n }\n}\n\nfunction collectReferenceTargets(\n value: unknown,\n path: string[],\n baseUri: string,\n uriToPointer: Map<string, string>,\n dynamicUriToFragment: Map<string, string>\n): void {\n if (!isSetObject(value)) {\n return;\n }\n\n const schema = value as Record<string, unknown>;\n const pointer = toJsonPointer(path);\n\n const currentBaseUri = isSetString(schema.$id)\n ? resolveUri(schema.$id, baseUri)\n : baseUri;\n\n const currentDocumentUri = stripUriFragment(currentBaseUri);\n\n uriToPointer.set(currentBaseUri, pointer);\n uriToPointer.set(currentDocumentUri, pointer);\n\n if (isSetString(schema.$anchor)) {\n uriToPointer.set(`${currentDocumentUri}#${schema.$anchor}`, pointer);\n }\n\n if (isSetString(schema.$dynamicAnchor)) {\n const dynamicTarget = `${currentDocumentUri}#${schema.$dynamicAnchor}`;\n uriToPointer.set(dynamicTarget, pointer);\n dynamicUriToFragment.set(dynamicTarget, `#${schema.$dynamicAnchor}`);\n }\n\n for (const [key, child] of Object.entries(schema)) {\n if (Array.isArray(child)) {\n child.forEach((entry, index) => {\n collectReferenceTargets(\n entry,\n [...path, key, String(index)],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n });\n continue;\n }\n\n collectReferenceTargets(\n child,\n [...path, key],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n }\n}\n\nfunction rewriteReferenceTargets(\n value: unknown,\n path: string[],\n baseUri: string,\n uriToPointer: Map<string, string>,\n dynamicUriToFragment: Map<string, string>\n): void {\n if (!isSetObject(value)) {\n return;\n }\n\n const schema = value as Record<string, unknown>;\n\n const currentBaseUri = isSetString(schema.$id)\n ? resolveUri(schema.$id, baseUri)\n : baseUri;\n\n if (isSetString(schema.$ref)) {\n const resolvedRefUri = resolveUri(schema.$ref, currentBaseUri);\n const pointer =\n uriToPointer.get(resolvedRefUri) ??\n uriToPointer.get(stripUriFragment(resolvedRefUri));\n\n if (pointer !== undefined) {\n schema.$ref = pointer.length > 0 ? `#${pointer}` : \"#\";\n }\n }\n\n if (isSetString(schema.$dynamicRef)) {\n const resolvedDynamicRefUri = resolveUri(\n schema.$dynamicRef,\n currentBaseUri\n );\n const dynamicFragment = dynamicUriToFragment.get(resolvedDynamicRefUri);\n\n if (dynamicFragment) {\n schema.$dynamicRef = dynamicFragment;\n } else {\n const pointer =\n uriToPointer.get(resolvedDynamicRefUri) ??\n uriToPointer.get(stripUriFragment(resolvedDynamicRefUri));\n\n if (pointer !== undefined) {\n schema.$dynamicRef = pointer.length > 0 ? `#${pointer}` : \"#\";\n }\n }\n }\n\n for (const [key, child] of Object.entries(schema)) {\n if (Array.isArray(child)) {\n child.forEach((entry, index) => {\n rewriteReferenceTargets(\n entry,\n [...path, key, String(index)],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n });\n continue;\n }\n\n rewriteReferenceTargets(\n child,\n [...path, key],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n }\n}\n\n/**\n * Bundles all external references in a JSON Schema into a single schema document by collecting all reference targets and rewriting the references to point to the bundled definitions. This ensures that the resulting schema is self-contained and can be used independently without relying on external documents.\n *\n * @param schema - The JSON Schema to bundle references for.\n * @returns A new JSON Schema with all references bundled and rewritten to point to the bundled definitions.\n */\nexport function bundleReferences(schema: JsonSchema): JsonSchema {\n if (!isSetObject(schema)) {\n return schema;\n }\n\n const bundledSchema = deepClone(schema) as Record<string, unknown>;\n const baseUri = isSetString(bundledSchema.$id)\n ? resolveUri(bundledSchema.$id, SCHEMA_BUNDLE_BASE_URI)\n : SCHEMA_BUNDLE_BASE_URI;\n\n const uriToPointer = new Map<string, string>();\n const dynamicUriToFragment = new Map<string, string>();\n\n collectReferenceTargets(\n bundledSchema,\n [],\n baseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n\n rewriteReferenceTargets(\n bundledSchema,\n [],\n baseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n\n return bundledSchema;\n}\n\nfunction convertNestedUntypedSchema(value: unknown): unknown {\n if (isUntypedSchema(value)) {\n return convertUntypedSchemaToJsonSchema(value);\n }\n\n if (isSetObject(value)) {\n if (isUntypedInput(value)) {\n return convertUntypedInputToJsonSchema(value);\n }\n\n const nested = value as Record<string, unknown>;\n if (\"$schema\" in nested && isUntypedSchema(nested.$schema)) {\n return convertUntypedSchemaToJsonSchema(nested.$schema);\n }\n }\n\n return value;\n}\n\nfunction convertNestedUntypedSchemaArray(value: unknown): unknown {\n if (!Array.isArray(value)) {\n return value;\n }\n\n return value.map(item => convertNestedUntypedSchema(item));\n}\n\nfunction convertValibotSchemaToJsonSchema(schema: unknown): JsonSchema {\n return toJsonSchema(schema as never, {\n target: \"draft-2020-12\"\n }) as JsonSchema;\n}\n\nfunction convertUntypedSchemaToJsonSchema(\n schema: UntypedSchema | Record<string, unknown>\n): JsonSchema {\n const source = schema as Record<string, unknown>;\n const jsonSchema: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(source)) {\n if (\n key === \"tsType\" ||\n key === \"markdownType\" ||\n key === \"tags\" ||\n key === \"args\" ||\n key === \"resolve\"\n ) {\n continue;\n }\n\n if (key === \"id\" && isSetString(value)) {\n jsonSchema.$id = value;\n continue;\n }\n\n if (\n key === \"properties\" ||\n key === \"patternProperties\" ||\n key === \"dependentSchemas\" ||\n key === \"$defs\" ||\n key === \"definitions\"\n ) {\n if (!isSetObject(value)) {\n jsonSchema[key] = value;\n continue;\n }\n\n jsonSchema[key] = Object.fromEntries(\n Object.entries(value).map(([propertyKey, propertyValue]) => [\n propertyKey,\n convertNestedUntypedSchema(propertyValue)\n ])\n );\n continue;\n }\n\n if (\n key === \"items\" ||\n key === \"contains\" ||\n key === \"if\" ||\n key === \"then\" ||\n key === \"else\" ||\n key === \"not\" ||\n key === \"propertyNames\" ||\n key === \"additionalProperties\" ||\n key === \"unevaluatedProperties\"\n ) {\n jsonSchema[key] = convertNestedUntypedSchema(value);\n continue;\n }\n\n if (key === \"oneOf\" || key === \"anyOf\" || key === \"allOf\") {\n jsonSchema[key] = convertNestedUntypedSchemaArray(value);\n continue;\n }\n\n jsonSchema[key] = value;\n }\n\n return jsonSchema;\n}\n\nfunction convertUntypedInputToJsonSchema(\n input: UntypedInputObject\n): JsonSchema {\n const inputObject = input as Record<string, unknown>;\n const base = isUntypedSchema(inputObject.$schema)\n ? convertUntypedSchemaToJsonSchema(inputObject.$schema)\n : {};\n const properties: Record<string, JsonSchema> = {};\n\n for (const [key, value] of Object.entries(inputObject)) {\n if (key.startsWith(\"$\")) {\n continue;\n }\n\n if (!isSetObject(value)) {\n continue;\n }\n\n if (isUntypedInput(value)) {\n properties[key] = convertUntypedInputToJsonSchema(value);\n continue;\n }\n\n const nested = value as Record<string, unknown>;\n if (\"$schema\" in nested && isUntypedSchema(nested.$schema)) {\n properties[key] = convertUntypedSchemaToJsonSchema(nested.$schema);\n continue;\n }\n\n if (isUntypedSchema(value)) {\n properties[key] = convertUntypedSchemaToJsonSchema(value);\n }\n }\n\n if (!isJsonSchemaObject(base)) {\n throw new Error(\n `Failed to convert untyped input to JSON Schema. The base schema must be a valid JSON Schema object.`\n );\n }\n\n const baseProperties = isSetObject(base.properties) ? base.properties : {};\n const mergedProperties = {\n ...baseProperties,\n ...properties\n };\n\n return {\n ...base,\n type: base.type ?? \"object\",\n ...(Object.keys(mergedProperties).length > 0\n ? { properties: mergedProperties }\n : {})\n };\n}\n\n/**\n * Creates a hash string for a given schema definition input.\n */\nexport function extractHash(\n variant: SchemaInputVariant,\n input: SchemaInput\n): string {\n if (isSetString(input)) {\n return murmurhash({ variant, input });\n } else if (typeof input === \"boolean\") {\n return murmurhash({ variant, input });\n } else if (isSetObject(input)) {\n if (isZod3Type(input)) {\n return murmurhash({ variant, input: input._def });\n } else if (isType(input)) {\n return murmurhash({ variant, input: stringifyType(input) });\n } else if (isStandardJsonSchema(input)) {\n return murmurhash({ variant, input: input[\"~standard\"] });\n } else if (isJsonSchema(input)) {\n return murmurhash({ variant, input });\n } else if (isValibotSchema(input)) {\n return murmurhash({\n variant,\n input: convertValibotSchemaToJsonSchema(input)\n });\n } else if (isUntypedInput(input)) {\n return murmurhash({\n variant,\n input: convertUntypedInputToJsonSchema(input)\n });\n } else if (isUntypedSchema(input)) {\n return murmurhash({\n variant,\n input: convertUntypedSchemaToJsonSchema(input)\n });\n }\n }\n\n throw new Error(\n `Failed to create an input hash for the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Converts a reflected Deepkit {@link Type} into a JSON Schema (draft-2020-12) representation.\n */\nexport function extractReflection(reflection: Type): JsonSchema | undefined {\n if (!isType(reflection)) {\n return undefined;\n }\n\n return reflectionToJsonSchema(reflection);\n}\n\n/**\n * Extracts a JSON Schema from Zod, Standard Schema, Valibot, untyped, or JSON Schema inputs.\n *\n * @param schema - The schema input to extract a JSON Schema from.\n * @returns The extracted JSON Schema, or `undefined` if the input is not a supported schema type.\n */\nexport function extractJsonSchema(schema: unknown): JsonSchema | undefined {\n if (isSetObject(schema)) {\n if (isZod3Type(schema)) {\n return extractJsonSchemaZod(schema, {\n target: \"draft-2020-12\"\n }) as JsonSchema;\n }\n if (isUntypedInputStrict(schema)) {\n return convertUntypedInputToJsonSchema(schema);\n }\n if (isUntypedSchemaStrict(schema)) {\n return convertUntypedSchemaToJsonSchema(schema);\n }\n if (isStandardJsonSchema(schema)) {\n return schema[\"~standard\"].jsonSchema.input({\n target: \"draft-2020-12\"\n });\n }\n if (isValibotSchema(schema)) {\n return convertValibotSchemaToJsonSchema(schema);\n }\n if (isJsonSchema(schema)) {\n return schema;\n }\n }\n\n return undefined;\n}\n\n/**\n * Resolves the concrete source variant for a schema source input.\n *\n * @param input - The schema source input to inspect.\n * @returns The resolved schema source variant.\n * @throws Will throw an error when the input cannot be mapped to a supported source variant.\n */\nexport function extractResolvedVariant(\n input: SchemaSourceInput\n): SchemaSourceVariant {\n if (isSetObject(input)) {\n if (isZod3Type(input)) {\n return \"zod3\";\n } else if (isType(input)) {\n return \"reflection\";\n } else if (isUntypedInputStrict(input) || isUntypedSchemaStrict(input)) {\n return \"untyped\";\n } else if (isStandardJsonSchema(input)) {\n return \"standard-schema\";\n } else if (isJsonSchema(input)) {\n return \"json-schema\";\n } else if (isValibotSchema(input)) {\n return \"valibot\";\n }\n }\n\n throw new Error(\n `Failed to determine the variant of the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, a reflected Deepkit Type object, or an Untyped schema.`\n );\n}\n\n/**\n * Determines the top-level input variant for schema extraction.\n *\n * @param input - The schema input to classify.\n * @returns The resolved schema input variant.\n */\nexport function extractVariant(input: SchemaInput): SchemaInputVariant {\n if (isSetString(input) || isFileReference(input)) {\n return \"file-reference\";\n }\n\n return extractResolvedVariant(input as SchemaSourceInput);\n}\n\n/**\n * Extracts and normalizes a JSON Schema from a concrete schema source input.\n *\n * @param input - The schema source input to extract from.\n * @param variant - Optional source variant override. When omitted, the variant is inferred from the input.\n * @returns A promise that resolves to a bundled JSON Schema.\n * @throws Will throw an error if no valid JSON Schema can be extracted from the input.\n */\nexport async function extractSchema(\n input: SchemaSourceInput,\n variant?: SchemaInputVariant\n): Promise<JsonSchema> {\n if (isSchemaWithSource(input)) {\n return input.schema;\n }\n\n const resolvedVariant = variant ?? extractResolvedVariant(input);\n\n let schema: JsonSchema | undefined;\n if (\n resolvedVariant === \"zod3\" ||\n resolvedVariant === \"json-schema\" ||\n resolvedVariant === \"standard-schema\" ||\n resolvedVariant === \"untyped\" ||\n resolvedVariant === \"valibot\"\n ) {\n schema = extractJsonSchema(input);\n } else if (resolvedVariant === \"reflection\") {\n schema = extractReflection(input as Type);\n }\n\n if (schema) {\n return bundleReferences(schema);\n }\n\n throw new Error(\n `Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, an untyped schema, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Builds source metadata for a schema input using a known source variant.\n *\n * @param variant - The schema source variant associated with the input.\n * @param input - The schema source input to wrap.\n * @returns The normalized schema source payload, including the source hash and variant.\n * @throws Will throw an error if the provided variant is unsupported.\n */\nexport function extractSource(\n variant: SchemaSourceVariant,\n input: SchemaSourceInput\n): SchemaSource {\n if (variant === \"zod3\") {\n return {\n hash: extractHash(variant, input),\n variant: \"zod3\",\n schema: input as z3.ZodTypeAny\n };\n } else if (variant === \"untyped\") {\n return {\n hash: extractHash(variant, input),\n variant: \"untyped\",\n schema: input as UntypedInputObject | UntypedSchema\n };\n } else if (variant === \"standard-schema\") {\n return {\n hash: extractHash(variant, input),\n variant: \"standard-schema\",\n schema: input as StandardJSONSchemaV1\n };\n } else if (variant === \"json-schema\") {\n return {\n hash: extractHash(variant, input),\n variant: \"json-schema\",\n schema: input as JsonSchema\n };\n } else if (variant === \"valibot\") {\n return {\n hash: extractHash(variant, input),\n variant: \"valibot\",\n schema: input as ValibotSchema\n };\n } else if (variant === \"reflection\") {\n return {\n hash: extractHash(variant, input),\n variant: \"reflection\",\n schema: input as Type\n };\n }\n\n throw new Error(\n `Failed to extract source information from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a Deepkit Type object. If the input is a type definition reference (e.g. a file path with an export), it will be resolved and bundled using Rolldown to obtain the actual schema definition before extraction.\n *\n * @example\n * ```ts\n * // Resolve a schema definition from a file path\n * const schema1 = await extract(context, \"./schemas.ts#MySchema\");\n * // Resolve a schema definition from a JSON Schema object\n * const schema2 = await extract(context, schemaObject);\n * // Resolve a schema definition from a Zod schema\n * const schema3 = await extract(context, zodSchema);\n * // Resolve a schema definition from a reflected Deepkit Type object\n * const schema4 = await extract(context, reflectionType);\n * ```\n *\n * @see https://zod.dev/\n * @see https://valibot.dev/\n * @see https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec\n * @see https://json-schema.org/\n * @see https://ajv.js.org/json-type-definition.html\n * @see https://deepkit.io/en/documentation/runtime-types/reflection\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param input - The schema definition input to extract, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a reflected Deepkit Type object. If the input is a string or a type definition reference, it will be resolved and bundled to obtain the actual schema definition before extraction.\n * @param options - Optional overrides for the Rolldown configuration used during extraction. This can include custom plugins, loaders, or other build options to control how the schema definition is resolved and bundled when the input is a type definition reference.\n * @returns A promise that resolves to the extracted and normalized schema as a JSON Schema object. The function will attempt to extract a valid JSON Schema from the provided input, and if successful, it will return the schema. If the extraction process fails or if the input is not a valid schema definition, it will throw an error indicating the failure.\n */\nexport async function extractSchemaWithSource(\n context: Context,\n input: SchemaInput,\n options: BundleOptions = {}\n): Promise<ExtractedSchema> {\n if (isSchemaWithSource(input)) {\n return input;\n }\n\n if (isSchema(input)) {\n return {\n ...input,\n source: {\n hash: extractHash(\"json-schema\", input.schema),\n variant: \"json-schema\",\n schema: input.schema\n }\n };\n }\n\n let source: SchemaSource;\n\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n\n if (variant === \"file-reference\") {\n const fileReference = extractFileReference(input as FileReferenceInput);\n if (!fileReference) {\n throw new Error(\n `Failed to extract a valid file reference from the provided input \"${JSON.stringify(\n input\n )}\". Please ensure that the input is correctly formatted as a file reference (e.g. \"./schema.ts#MySchema\") and that the file exists at the specified path.`\n );\n }\n\n const extension = findFileExtensionSafe(fileReference.file);\n if (extension && !VALID_SOURCE_FILE_EXTENSIONS.includes(extension)) {\n throw new Error(\n `The provided schema file input \"${\n fileReference.file\n }\" has an invalid file extension (.${\n extension\n }). Please ensure that the file has one of the following extensions: ${list(\n VALID_SOURCE_FILE_EXTENSIONS,\n { conjunction: \"or\" }\n )}.`\n );\n }\n\n let resolved = await resolve<SchemaSourceInput>(\n context,\n input as FileReferenceInput,\n defu(options, {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n level: \"all\"\n })\n ]\n })\n );\n\n try {\n const type = reflect(resolved);\n if (isType(type)) {\n resolved = type;\n }\n } catch {\n // If reflection fails, we assume the resolved output is not a reflected type and proceed with it as-is.\n }\n\n source = extractSource(extractResolvedVariant(resolved), resolved);\n } else if (\n [\n \"json-schema\",\n \"standard-schema\",\n \"zod3\",\n \"untyped\",\n \"valibot\",\n \"reflection\"\n ].includes(variant)\n ) {\n source = extractSource(variant, input as SchemaSourceInput);\n } else {\n throw new Error(\n `Invalid schema definition input \"${\n variant\n }\". The variant must be one of \"file-reference\", \"json-schema\", \"standard-schema\", \"zod3\", \"valibot\", \"untyped\", or \"reflection\".`\n );\n }\n\n return {\n variant,\n source,\n schema: await extractSchema(source.schema, source.variant),\n hash\n };\n}\n\n/**\n * Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a Deepkit Type object. If the input is a type definition reference (e.g. a file path with an export), it will be resolved and bundled using Rolldown to obtain the actual schema definition before extraction.\n *\n * @example\n * ```ts\n * // Resolve a schema definition from a file path\n * const schema1 = await extract(context, \"./schemas.ts#MySchema\");\n * // Resolve a schema definition from a JSON Schema object\n * const schema2 = await extract(context, schemaObject);\n * // Resolve a schema definition from a Zod schema\n * const schema3 = await extract(context, zodSchema);\n * // Resolve a schema definition from a Valibot schema\n * const schema4 = await extract(context, valibotSchema);\n * // Resolve a schema definition from a reflected Deepkit Type object\n * const schema5 = await extract(context, reflectionType);\n * ```\n *\n * @see https://zod.dev/\n * @see https://valibot.dev/\n * @see https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec\n * @see https://json-schema.org/\n * @see https://ajv.js.org/json-type-definition.html\n * @see https://deepkit.io/en/documentation/runtime-types/reflection\n * @see https://github.com/unjs/untyped\n * @see https://www.typescriptlang.org/docs/handbook/2/types-from-types.html\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param input - The schema definition input to extract, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a reflected Deepkit Type object.\n * @param options - Optional overrides for the Rolldown configuration used during extraction.\n * @returns A promise that resolves to the extracted and normalized schema as a JSON Schema object.\n * @throws Will throw an error if the input is not a valid schema definition or if the extraction process fails to produce a valid schema.\n */\nexport async function extract(\n context: Context,\n input: SchemaInput,\n options: BundleOptions = {}\n): Promise<Schema> {\n if (isSchemaWithSource(input) || isSchema(input)) {\n return input;\n }\n\n let result: Schema | undefined;\n\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n\n const cacheFilePath = joinPaths(getCacheDirectory(context), `${hash}.json`);\n if (\n context.config.skipCache !== true &&\n context.fs.existsSync(cacheFilePath)\n ) {\n const schema = await context.fs.read(cacheFilePath);\n if (schema) {\n result = {\n variant,\n hash,\n schema: JSON.parse(schema) as JsonSchema\n };\n }\n }\n\n result ??= await extractSchemaWithSource(context, input, options);\n if (!result?.schema) {\n throw new Error(\n `Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`\n );\n }\n\n if (context.config.skipCache !== true) {\n await writeSchema(context, result);\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,eAAsB,OACpB,SACA,MACA,UAAyB,CAAC,GACL;CACrB,MAAM,OAAO,MAAM,QAAQ,GAAG,QAAQ,IAAI;CAC1C,IAAI,CAAC,QAAQ,CAAC,QAAQ,GAAG,WAAW,IAAI,GACtC,MAAM,IAAI,MACR,sBAAsB,KAAK,wCAC7B;CAGF,MAAM,S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,aAAa,GACnC;EACA,MAAM,SAAS,MAAM,QAAQ,GAAG,KAAK,aAAa;EAClD,IAAI,QACF,SAAS;GACP;GACA;GACA,QAAQ,KAAK,MAAM,MAAM;EAC3B;CAEJ;CAEA,WAAW,MAAM,wBAAwB,SAAS,OAAO,OAAO;CAChE,IAAI,CAAC,QAAQ,QACX,MAAM,IAAI,MACR,+NACF;CAGF,IAAI,QAAQ,OAAO,cAAc,MAC/B,MAAM,YAAY,SAAS,MAAM;CAGnC,OAAO;AACT"}
1
+ {"version":3,"file":"index.mjs","names":["isSetObject","baseObj","isUndefined","isNull","isBoolean","isNumber","isSetString","isSetString","parseYaml","parseToml","isSetObject","stringifyType","extractJsonSchemaZod"],"sources":["../src/bundle.ts","../src/constants.ts","../src/metadata.ts","../src/type-checks.ts","../src/helpers.ts","../src/validate.ts","../src/codegen.ts","../src/persistence.ts","../src/reflection.ts","../src/resolve.ts","../src/extract.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 { ResolveOptions, UnresolvedContext } from \"@powerlines/core\";\nimport { createUnpluginResolver } from \"@powerlines/core/lib/unplugin\";\nimport { resolveOptions } from \"@powerlines/unplugin/esbuild\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { findFileName } from \"@stryke/path/file-path-fns\";\nimport { DeepPartial } from \"@stryke/types/base\";\nimport defu from \"defu\";\nimport type { BuildOptions } from \"esbuild\";\nimport { build, OutputFile } from \"esbuild\";\nimport { createEsbuildPlugin } from \"unplugin\";\n\nexport type BundleOptions = DeepPartial<BuildOptions> & {\n name?: string;\n resolve?: DeepPartial<ResolveOptions>;\n};\n\n/**\n * Bundle a type definition to a module.\n *\n * @param context - The context object containing the environment paths.\n * @param file - The file path to bundle.\n * @param options - Optional overrides for the ESBuild configuration.\n * @returns A promise that resolves to the bundled module.\n */\nexport async function bundle<TContext extends UnresolvedContext>(\n context: TContext,\n file: string,\n options: BundleOptions = {}\n): Promise<OutputFile> {\n const path = await context.fs.resolve(file);\n if (!path || !context.fs.existsSync(path)) {\n throw new Error(\n `Module not found: \"${file}\". Please check the path and try again.`\n );\n }\n\n const result = await build(\n defu(\n {\n platform: \"node\",\n ...omit(options, [\"name\", \"resolve\"]),\n logLevel: \"silent\",\n entryPoints: [path],\n write: false,\n sourcemap: false,\n splitting: false,\n treeShaking: false,\n bundle: true,\n packages: \"bundle\",\n keepNames: true,\n metafile: false\n },\n resolveOptions(context),\n {\n plugins: [\n createEsbuildPlugin(\n createUnpluginResolver(context, {\n name: options.name ?? `${findFileName(file)} Bundler`,\n prefix: false,\n overrides: defu(options.resolve ?? {}, {\n skipNodeModulesBundle: false\n }),\n silenceHookLogging: true\n })\n )()\n ]\n }\n )\n );\n if (result.errors.length > 0) {\n throw new Error(\n `Failed to bundle ${file}: ${result.errors\n .map(error => error.text)\n .join(\", \")}`\n );\n }\n if (result.warnings.length > 0) {\n context.warn(\n `Warnings while bundling ${file}: ${result.warnings\n .map(warning => warning.text)\n .join(\", \")}`\n );\n }\n if (!result.outputFiles || result.outputFiles.filter(Boolean).length === 0) {\n throw new Error(\n `No output files generated for ${\n file\n }. Please check the configuration and try again.`\n );\n }\n\n return result.outputFiles.filter(Boolean)[0]!;\n}\n","/* -------------------------------------------------------------------\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 { JsonSchemaMetadataKeywords } from \"./types\";\n\nexport const VALID_SOURCE_FILE_EXTENSIONS = [\n \"ts\",\n \"cts\",\n \"mts\",\n \"tsx\",\n \"js\",\n \"cjs\",\n \"mjs\",\n \"jsx\",\n \"json\",\n \"jsonc\",\n \"json5\",\n \"yaml\",\n \"yml\",\n \"toml\"\n] as const as string[];\n\nexport const JsonSchemaTypeNames = {\n STRING: \"string\",\n NUMBER: \"number\",\n INTEGER: \"integer\",\n BOOLEAN: \"boolean\",\n NULL: \"null\",\n OBJECT: \"object\",\n ARRAY: \"array\"\n} as const;\n\nexport const JSON_SCHEMA_PRIMITIVE_TYPES = [\n JsonSchemaTypeNames.STRING,\n JsonSchemaTypeNames.NUMBER,\n JsonSchemaTypeNames.INTEGER,\n JsonSchemaTypeNames.BOOLEAN,\n JsonSchemaTypeNames.NULL\n] as const;\n\nexport const JSON_SCHEMA_TYPES = [\n ...JSON_SCHEMA_PRIMITIVE_TYPES,\n JsonSchemaTypeNames.ARRAY,\n JsonSchemaTypeNames.OBJECT\n] as const;\n\nexport const JSON_SCHEMA_METADATA_KEYS = [\n \"docs\",\n \"deprecated\",\n \"title\",\n \"description\",\n \"examples\",\n \"hidden\",\n \"ignore\",\n \"internal\",\n \"runtime\",\n \"readOnly\",\n \"writeOnly\",\n \"alias\",\n \"tags\"\n] satisfies ReadonlyArray<keyof JsonSchemaMetadataKeywords>;\n","/* -------------------------------------------------------------------\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 { isSetString } from \"@stryke/type-checks\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { JSON_SCHEMA_METADATA_KEYS } from \"./constants\";\nimport {\n JsonSchema,\n JsonSchemaMetadataKeywords,\n JsonSchemaPrimitiveType,\n JsonSchemaType\n} from \"./types\";\n\ninterface JsonSchemaTypeView {\n type?: JsonSchemaType | readonly JsonSchemaType[];\n}\n\n/**\n * Applies Powerlines schema metadata onto a JSON Schema fragment.\n *\n * @param schema - The JSON Schema fragment to apply metadata to.\n * @param metadata - The Powerlines schema metadata to apply.\n * @returns A new JSON Schema fragment with the metadata applied.\n */\nexport function applyJsonSchemaMetadata(\n schema: JsonSchema,\n metadata: JsonSchemaMetadataKeywords | undefined\n): JsonSchema {\n if (!metadata || !isSetObject(schema)) {\n return schema;\n }\n\n const result: JsonSchema = { ...schema };\n const mutableResult = result as Record<string, unknown>;\n for (const key of JSON_SCHEMA_METADATA_KEYS) {\n const value = metadata[key];\n if (value !== undefined && value !== null) {\n mutableResult[key] = value;\n }\n }\n\n return result;\n}\n\n/**\n * Normalizes the JSON Schema `type` keyword to a string array.\n *\n * @remarks\n * This function ensures that the `type` keyword of a JSON Schema fragment is always represented as an array of strings, even if it was originally defined as a single string. This normalization simplifies type checking and processing of JSON Schemas by providing a consistent format for the `type` information.\n *\n * @param schema - The JSON Schema fragment to read types from.\n * @returns An array of JSON Schema primitive type names defined in the `type` keyword, or an empty array if no valid types are found.\n */\nexport function readSchemaTypes(\n schema?: JsonSchema\n): JsonSchemaPrimitiveType[] {\n if (!isSetObject(schema)) {\n return [];\n }\n\n const objectSchema = schema as JsonSchemaTypeView;\n\n if (Array.isArray(objectSchema.type)) {\n return objectSchema.type.filter(\n (type: JsonSchemaPrimitiveType): type is JsonSchemaPrimitiveType =>\n isSetString(type)\n );\n }\n if (\n isSetString(objectSchema.type) &&\n objectSchema.type !== \"object\" &&\n objectSchema.type !== \"array\"\n ) {\n return [objectSchema.type];\n }\n return [];\n}\n\n/**\n * Returns the primary non-null JSON Schema type name for a fragment.\n *\n * @param schema - The JSON Schema fragment to check.\n * @returns The primary non-null JSON Schema type name, or `undefined` if none is found.\n */\nexport function getPrimarySchemaType(\n schema?: JsonSchema\n): JsonSchemaPrimitiveType | undefined {\n if (!isSetObject(schema)) {\n return undefined;\n }\n\n return readSchemaTypes(schema).find(type => type !== \"null\");\n}\n","/* -------------------------------------------------------------------\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 {\n isBoolean,\n isFunction,\n isSetObject,\n isSetString,\n isString\n} from \"@stryke/type-checks\";\nimport type {\n FunctionArg as UntypedFunctionArg,\n InputObject as UntypedInputObject,\n Schema as UntypedSchema,\n TypeDescriptor as UntypedTypeDescriptor\n} from \"untyped\";\nimport type { BaseSchema } from \"valibot\";\nimport { JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES } from \"./constants\";\nimport {\n JsonSchema,\n JsonSchemaAllOf,\n JsonSchemaAny,\n JsonSchemaAnyOf,\n JsonSchemaArray,\n JsonSchemaBigint,\n JsonSchemaBoolean,\n JsonSchemaDate,\n JsonSchemaDecimal,\n JsonSchemaEnum,\n JsonSchemaInteger,\n JsonSchemaKeywords,\n JsonSchemaLiteral,\n JsonSchemaMap,\n JsonSchemaNativeEnum,\n JsonSchemaNever,\n JsonSchemaNull,\n JsonSchemaNullable,\n JsonSchemaNumber,\n JsonSchemaObject,\n JsonSchemaPrimitiveType,\n JsonSchemaPrimitiveUnion,\n JsonSchemaRecord,\n JsonSchemaRef,\n JsonSchemaSet,\n JsonSchemaString,\n JsonSchemaTuple,\n JsonSchemaType,\n JsonSchemaUndefined,\n JsonSchemaUnion,\n JsonSchemaUnknown,\n Schema,\n ExtractedSchema as SchemaWithSource\n} from \"./types\";\n\nconst isSetNumber = (value: unknown): value is number =>\n typeof value === \"number\" && Number.isFinite(value);\n\nconst isSchemaLikeValue = (value: unknown): boolean =>\n isSetObject(value) || isBoolean(value);\n\nconst isRecordOfSchemaLike = (\n value: unknown\n): value is Record<string, unknown> =>\n isSetObject(value) &&\n Object.values(value).every(item => isSchemaLikeValue(item));\n\nconst isVocabularyMap = (value: unknown): value is Record<string, boolean> =>\n isSetObject(value) && Object.values(value).every(item => isBoolean(item));\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 JSON_SCHEMA_PRIMITIVE_TYPE_SET = new Set<JsonSchemaPrimitiveType>(\n JSON_SCHEMA_PRIMITIVE_TYPES\n);\nconst JSON_SCHEMA_TYPE_SET = new Set<JsonSchemaType>(JSON_SCHEMA_TYPES);\n\n/**\n * A helper type guard to check if a value is a JSON Schema primitive type.\n *\n * @param value - The value to check.\n * @returns True if the value is a JSON Schema primitive type, false otherwise.\n */\nexport function isJsonSchemaPrimitiveType(\n value: unknown\n): value is JsonSchemaPrimitiveType {\n return (\n isSetString(value) &&\n JSON_SCHEMA_PRIMITIVE_TYPE_SET.has(value as JsonSchemaPrimitiveType)\n );\n}\n\n/**\n * A helper type guard to check if a value is a JSON Schema type.\n *\n * @param value - The value to check.\n * @returns True if the value is a JSON Schema type, false otherwise.\n */\nexport function isJsonSchemaType(value: unknown): value is JsonSchemaType {\n return (\n isSetString(value) && JSON_SCHEMA_TYPE_SET.has(value as JsonSchemaType)\n );\n}\n\nconst DATE_FORMAT_SET = new Set([\n \"date\",\n \"time\",\n \"date-time\",\n \"iso-time\",\n \"iso-date-time\",\n \"unix-time\"\n]);\n\nconst isSetBigint = (value: unknown): value is bigint =>\n typeof value === \"bigint\";\n\ntype UntypedJSType =\n | \"string\"\n | \"number\"\n | \"bigint\"\n | \"boolean\"\n | \"symbol\"\n | \"function\"\n | \"object\"\n | \"any\"\n | \"array\";\n\nconst UNTYPED_TYPE_NAME_SET = new Set<UntypedJSType>([\n \"string\",\n \"number\",\n \"bigint\",\n \"boolean\",\n \"symbol\",\n \"function\",\n \"object\",\n \"any\",\n \"array\"\n]);\n\nconst isUntypedJSType = (value: unknown): value is UntypedJSType =>\n isSetString(value) && UNTYPED_TYPE_NAME_SET.has(value as UntypedJSType);\n\nconst isUntypedTypeDescriptor = (\n value: unknown\n): value is UntypedTypeDescriptor => {\n if (!isSetObject(value)) {\n return false;\n }\n\n const descriptor = value as Record<string, unknown>;\n if (\n descriptor.type !== undefined &&\n !(\n (isSetString(descriptor.type) && isUntypedJSType(descriptor.type)) ||\n (Array.isArray(descriptor.type) &&\n descriptor.type.every(item => isUntypedJSType(item)))\n )\n ) {\n return false;\n }\n\n if (descriptor.tsType !== undefined && !isSetString(descriptor.tsType)) {\n return false;\n }\n\n if (\n descriptor.markdownType !== undefined &&\n !isSetString(descriptor.markdownType)\n ) {\n return false;\n }\n\n if (\n descriptor.items !== undefined &&\n !(\n isUntypedTypeDescriptor(descriptor.items) ||\n (Array.isArray(descriptor.items) &&\n descriptor.items.every(item => isUntypedTypeDescriptor(item)))\n )\n ) {\n return false;\n }\n\n return true;\n};\n\nconst isUntypedFunctionArg = (value: unknown): value is UntypedFunctionArg => {\n if (!isUntypedTypeDescriptor(value)) {\n return false;\n }\n\n const arg = value as Record<string, unknown>;\n if (arg.name !== undefined && !isSetString(arg.name)) {\n return false;\n }\n\n return arg.optional === undefined || typeof arg.optional === \"boolean\";\n};\n\nconst isRecordOfUntypedSchema = (\n value: unknown\n): value is Record<string, UntypedSchema> =>\n isSetObject(value) &&\n Object.values(value).every(item => isUntypedSchema(item));\n\nconst isArrayOf = <T>(\n value: unknown,\n predicate: (item: unknown) => item is T\n): value is T[] => Array.isArray(value) && value.every(item => predicate(item));\n\nconst isTupleOfTwo = <A, B>(\n value: unknown,\n aPredicate: (item: unknown) => item is A,\n bPredicate: (item: unknown) => item is B\n): value is [A, B] =>\n Array.isArray(value) &&\n value.length === 2 &&\n aPredicate(value[0]) &&\n bPredicate(value[1]);\n\nconst isOptionalString = (\n value: unknown,\n allowEmpty = false\n): value is string | undefined =>\n value === undefined || (isString(value) && (allowEmpty || value.length > 0));\n\nconst isOptionalBoolean = (value: unknown): value is boolean | undefined =>\n value === undefined || isBoolean(value);\n\nconst isOptionalNumber = (value: unknown): value is number | undefined =>\n value === undefined || isSetNumber(value);\n\nconst isOptionalBigint = (value: unknown): value is bigint | undefined =>\n value === undefined || isSetBigint(value);\n\nconst isOptionalJsonSchema = (\n value: unknown\n): value is JsonSchema | undefined =>\n value === undefined || isJsonSchema(value);\n\nconst isOptionalJsonSchemaArray = (\n value: unknown\n): value is JsonSchema[] | undefined =>\n value === undefined || isArrayOf(value, isJsonSchema);\n\nconst isOptionalPrimitiveTypeArray = (\n value: unknown\n): value is JsonSchemaPrimitiveType[] | undefined =>\n value === undefined ||\n (Array.isArray(value) &&\n value.every(\n item =>\n isSetString(item) &&\n JSON_SCHEMA_PRIMITIVE_TYPE_SET.has(item as JsonSchemaPrimitiveType)\n ));\n\nconst isOptionalJsonSchemaTypeArray = (\n value: unknown\n): value is JsonSchemaType[] | undefined =>\n value === undefined ||\n (Array.isArray(value) &&\n value.every(\n item =>\n isSetString(item) && JSON_SCHEMA_TYPE_SET.has(item as JsonSchemaType)\n ));\n\nconst hasValidJsonSchemaKeywords = (\n schema: Record<string, unknown>\n): boolean => {\n if (!isOptionalString(schema.$id)) {\n return false;\n }\n if (!isOptionalString(schema.$schema)) {\n return false;\n }\n if (\n schema.$vocabulary !== undefined &&\n !isVocabularyMap(schema.$vocabulary)\n ) {\n return false;\n }\n if (!isOptionalString(schema.$comment, true)) {\n return false;\n }\n if (!isOptionalString(schema.$anchor)) {\n return false;\n }\n if (schema.$defs !== undefined && !isRecordOfSchemaLike(schema.$defs)) {\n return false;\n }\n if (!isOptionalString(schema.$dynamicRef)) {\n return false;\n }\n if (!isOptionalString(schema.$dynamicAnchor)) {\n return false;\n }\n if (!isOptionalString(schema.name)) {\n return false;\n }\n if (!isOptionalString(schema.title, true)) {\n return false;\n }\n if (!isOptionalString(schema.description, true)) {\n return false;\n }\n if (!isOptionalString(schema.docs, true)) {\n return false;\n }\n if (schema.examples !== undefined && !Array.isArray(schema.examples)) {\n return false;\n }\n if (schema.alias !== undefined && !isStringArray(schema.alias)) {\n return false;\n }\n if (schema.tags !== undefined && !isStringArray(schema.tags)) {\n return false;\n }\n if (!isOptionalBoolean(schema.deprecated)) {\n return false;\n }\n if (!isOptionalBoolean(schema.hidden)) {\n return false;\n }\n if (!isOptionalBoolean(schema.ignore)) {\n return false;\n }\n if (!isOptionalBoolean(schema.internal)) {\n return false;\n }\n if (!isOptionalBoolean(schema.runtime)) {\n return false;\n }\n if (!isOptionalBoolean(schema.readOnly)) {\n return false;\n }\n if (!isOptionalBoolean(schema.writeOnly)) {\n return false;\n }\n\n if (!isOptionalJsonSchemaArray(schema.allOf)) {\n return false;\n }\n if (!isOptionalJsonSchemaArray(schema.anyOf)) {\n return false;\n }\n if (!isOptionalJsonSchemaArray(schema.oneOf)) {\n return false;\n }\n if (!isOptionalJsonSchema(schema.not)) {\n return false;\n }\n\n if (!isOptionalJsonSchema(schema.if)) {\n return false;\n }\n if (!isOptionalJsonSchema(schema.then)) {\n return false;\n }\n if (!isOptionalJsonSchema(schema.else)) {\n return false;\n }\n\n return true;\n};\n\n/**\n * Type guard for shared JSON Schema keyword groups.\n *\n * @param input - The value to check.\n * @returns True if the input is a JSON Schema keyword group, false otherwise.\n */\nexport function isJsonSchemaKeywords(\n input: unknown\n): input is JsonSchemaKeywords {\n if (!isSetObject(input)) {\n return false;\n }\n\n return hasValidJsonSchemaKeywords(input as Record<string, unknown>);\n}\n\n/**\n * Type guard for generic JSON Schema objects with optional `$ref`.\n *\n * @param input - The value to check.\n * @returns True if the input is a generic JSON Schema object, false otherwise.\n */\nexport function isJsonSchemaAny(input: unknown): input is JsonSchemaAny {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return hasValidJsonSchemaKeywords(schema) && isOptionalString(schema.$ref);\n}\n\n/**\n * Type guard for JSON Schema array types.\n *\n * @param input - The value to check.\n * @returns True if the input is a JSON Schema array schema, false otherwise.\n */\nexport function isJsonSchemaArray(input: unknown): input is JsonSchemaArray {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (!hasValidJsonSchemaKeywords(schema) || schema.type !== \"array\") {\n return false;\n }\n\n return (\n isOptionalJsonSchemaArray(schema.prefixItems) &&\n isOptionalJsonSchema(schema.items) &&\n isOptionalJsonSchema(schema.contains) &&\n isOptionalNumber(schema.minItems) &&\n isOptionalNumber(schema.maxItems) &&\n isOptionalBoolean(schema.uniqueItems) &&\n isOptionalNumber(schema.minContains) &&\n isOptionalNumber(schema.maxContains) &&\n (schema.unevaluatedItems === undefined ||\n isBoolean(schema.unevaluatedItems) ||\n isJsonSchema(schema.unevaluatedItems))\n );\n}\n\n/**\n * Type guard for bigint-backed integer schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a bigint-backed integer schema, false otherwise.\n */\nexport function isJsonSchemaBigint(input: unknown): input is JsonSchemaBigint {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (\n !hasValidJsonSchemaKeywords(schema) ||\n schema.type !== \"integer\" ||\n schema.format !== \"int64\"\n ) {\n return false;\n }\n\n return (\n isOptionalBigint(schema.minimum) &&\n isOptionalBigint(schema.exclusiveMinimum) &&\n isOptionalBigint(schema.maximum) &&\n isOptionalBigint(schema.exclusiveMaximum) &&\n isOptionalBigint(schema.multipleOf) &&\n isOptionalBigint(schema.default) &&\n (schema.enum === undefined || isArrayOf(schema.enum, isSetBigint))\n );\n}\n\n/**\n * Type guard for boolean schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a boolean schema, false otherwise.\n */\nexport function isJsonSchemaBoolean(\n input: unknown\n): input is JsonSchemaBoolean {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return (\n hasValidJsonSchemaKeywords(schema) &&\n schema.type === \"boolean\" &&\n isOptionalBoolean(schema.default)\n );\n}\n\n/**\n * Type guard for date/time schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a date or time schema, false otherwise.\n */\nexport function isJsonSchemaDate(input: unknown): input is JsonSchemaDate {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (!hasValidJsonSchemaKeywords(schema)) {\n return false;\n }\n\n if (schema.anyOf !== undefined) {\n return isArrayOf(schema.anyOf, isJsonSchemaDate);\n }\n\n if (schema.type !== \"integer\" && schema.type !== \"string\") {\n return false;\n }\n\n if (!isSetString(schema.format) || !DATE_FORMAT_SET.has(schema.format)) {\n return false;\n }\n\n return (\n isOptionalNumber(schema.minimum) &&\n isOptionalNumber(schema.maximum) &&\n (schema.default === undefined ||\n isSetString(schema.default) ||\n isSetNumber(schema.default))\n );\n}\n\n/**\n * Type guard for enum-constrained schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is an enum-constrained schema, false otherwise.\n */\nexport function isJsonSchemaEnum(input: unknown): input is JsonSchemaEnum {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (\n !hasValidJsonSchemaKeywords(schema) ||\n !isSetString(schema.type) ||\n !JSON_SCHEMA_PRIMITIVE_TYPE_SET.has(\n schema.type as JsonSchemaPrimitiveType\n ) ||\n !Array.isArray(schema.enum)\n ) {\n return false;\n }\n\n const typeName = schema.type as JsonSchemaPrimitiveType;\n const enumValues = schema.enum;\n const defaultValue = schema.default;\n\n if (typeName === \"string\") {\n return (\n enumValues.every(value => isSetString(value)) &&\n (defaultValue === undefined || isSetString(defaultValue))\n );\n }\n\n if (typeName === \"number\" || typeName === \"integer\") {\n return (\n enumValues.every(value => isSetNumber(value)) &&\n (defaultValue === undefined || isSetNumber(defaultValue))\n );\n }\n\n if (typeName === \"boolean\") {\n return (\n enumValues.every(value => isBoolean(value)) &&\n (defaultValue === undefined || isBoolean(defaultValue))\n );\n }\n\n return (\n typeName === \"null\" &&\n enumValues.every(value => value === null) &&\n (defaultValue === undefined || defaultValue === null)\n );\n}\n\n/**\n * Type guard for `allOf` composition schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is an `allOf` schema, false otherwise.\n */\nexport function isJsonSchemaAllOf(input: unknown): input is JsonSchemaAllOf {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (\n !hasValidJsonSchemaKeywords(schema) ||\n !isArrayOf(schema.allOf, isJsonSchema)\n ) {\n return false;\n }\n\n return (\n schema.unevaluatedProperties === undefined ||\n isBoolean(schema.unevaluatedProperties) ||\n isJsonSchema(schema.unevaluatedProperties)\n );\n}\n\n/**\n * Type guard for literal-value schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a literal-value schema, false otherwise.\n */\nexport function isJsonSchemaLiteral(\n input: unknown\n): input is JsonSchemaLiteral {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (!hasValidJsonSchemaKeywords(schema) || !(\"const\" in schema)) {\n return false;\n }\n\n return (\n schema.type === undefined ||\n (isSetString(schema.type) && isJsonSchemaType(schema.type)) ||\n isOptionalJsonSchemaTypeArray(schema.type)\n );\n}\n\n/**\n * Type guard for map tuple-array schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a map tuple-array schema, false otherwise.\n */\nexport function isJsonSchemaMap(input: unknown): input is JsonSchemaMap {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (\n !hasValidJsonSchemaKeywords(schema) ||\n schema.type !== \"array\" ||\n schema.maxItems !== 125 ||\n !isSetObject(schema.items)\n ) {\n return false;\n }\n\n const items = schema.items as Record<string, unknown>;\n\n return (\n items.type === \"array\" &&\n isTupleOfTwo(items.prefixItems, isJsonSchema, isJsonSchema) &&\n (items.items === undefined || items.items === false) &&\n items.minItems === 2 &&\n items.maxItems === 2\n );\n}\n\n/**\n * Type guard for native enum schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a native enum schema, false otherwise.\n */\nexport function isJsonSchemaNativeEnum(\n input: unknown\n): input is JsonSchemaNativeEnum {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n const isValidType =\n schema.type === \"string\" ||\n schema.type === \"number\" ||\n (Array.isArray(schema.type) &&\n schema.type.length === 2 &&\n schema.type[0] === \"string\" &&\n schema.type[1] === \"number\");\n\n return (\n hasValidJsonSchemaKeywords(schema) &&\n isValidType &&\n Array.isArray(schema.enum) &&\n schema.enum.every(value => isSetString(value) || isSetNumber(value))\n );\n}\n\n/**\n * Type guard for impossible/never schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a never schema, false otherwise.\n */\nexport function isJsonSchemaNever(input: unknown): input is JsonSchemaNever {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return hasValidJsonSchemaKeywords(schema) && isJsonSchemaAny(schema.not);\n}\n\n/**\n * Type guard for `null` schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a null schema, false otherwise.\n */\nexport function isJsonSchemaNull(input: unknown): input is JsonSchemaNull {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return (\n hasValidJsonSchemaKeywords(schema) &&\n schema.type === \"null\" &&\n (schema.const === undefined || schema.const === null) &&\n (schema.enum === undefined ||\n (Array.isArray(schema.enum) && schema.enum.every(v => v === null))) &&\n (schema.default === undefined || schema.default === null)\n );\n}\n\n/**\n * Type guard for nullable schema unions.\n *\n * @param input - The value to check.\n * @returns True if the input is a nullable schema union, false otherwise.\n */\nexport function isJsonSchemaNullable(\n input: unknown\n): input is JsonSchemaNullable {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (!hasValidJsonSchemaKeywords(schema)) {\n return false;\n }\n\n const anyOfBranch =\n schema.anyOf !== undefined &&\n Array.isArray(schema.anyOf) &&\n schema.anyOf.length === 2 &&\n isJsonSchema(schema.anyOf[0]) &&\n isJsonSchemaNull(schema.anyOf[1]);\n\n const typeBranch =\n Array.isArray(schema.type) &&\n schema.type.length === 2 &&\n ((schema.type[0] === \"null\" &&\n isSetString(schema.type[1]) &&\n schema.type[1] !== \"null\" &&\n JSON_SCHEMA_TYPE_SET.has(schema.type[1] as JsonSchemaType)) ||\n (schema.type[1] === \"null\" &&\n isSetString(schema.type[0]) &&\n schema.type[0] !== \"null\" &&\n JSON_SCHEMA_TYPE_SET.has(schema.type[0] as JsonSchemaType)));\n\n return anyOfBranch || typeBranch;\n}\n\n/**\n * Type guard for numeric schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a numeric schema, false otherwise.\n */\nexport function isJsonSchemaNumber(input: unknown): input is JsonSchemaNumber {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (\n !hasValidJsonSchemaKeywords(schema) ||\n (schema.type !== \"number\" && schema.type !== \"integer\")\n ) {\n return false;\n }\n\n return (\n isOptionalString(schema.format) &&\n isOptionalNumber(schema.minimum) &&\n isOptionalNumber(schema.exclusiveMinimum) &&\n isOptionalNumber(schema.maximum) &&\n isOptionalNumber(schema.exclusiveMaximum) &&\n isOptionalNumber(schema.multipleOf) &&\n isOptionalNumber(schema.default) &&\n (schema.enum === undefined || isArrayOf(schema.enum, isSetNumber))\n );\n}\n\n/**\n * Type guard for integer schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is an integer schema, false otherwise.\n */\nexport function isJsonSchemaInteger(\n input: unknown\n): input is JsonSchemaInteger {\n return isJsonSchemaNumber(input) && input.type === \"integer\";\n}\n\n/**\n * Type guard for decimal schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a decimal schema, false otherwise.\n */\nexport function isJsonSchemaDecimal(\n input: unknown\n): input is JsonSchemaDecimal {\n return isJsonSchemaNumber(input) && input.type === \"number\";\n}\n\n/**\n * Type guard for object schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is an object schema, false otherwise.\n */\nexport function isJsonSchemaObject(input: unknown): input is JsonSchemaObject {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return (\n hasValidJsonSchemaKeywords(schema) &&\n schema.type === \"object\" &&\n (schema.properties === undefined ||\n isRecordOfSchemaLike(schema.properties)) &&\n (schema.patternProperties === undefined ||\n isRecordOfSchemaLike(schema.patternProperties)) &&\n (schema.additionalProperties === undefined ||\n isBoolean(schema.additionalProperties) ||\n isJsonSchema(schema.additionalProperties)) &&\n (schema.required === undefined || isStringArray(schema.required)) &&\n (schema.unevaluatedProperties === undefined ||\n isBoolean(schema.unevaluatedProperties) ||\n isJsonSchema(schema.unevaluatedProperties)) &&\n (schema.dependencies === undefined ||\n (isSetObject(schema.dependencies) &&\n Object.values(schema.dependencies).every(\n item => isStringArray(item) || isJsonSchema(item)\n ))) &&\n (schema.dependentRequired === undefined ||\n isRecordOfStringArrays(schema.dependentRequired)) &&\n (schema.dependentSchemas === undefined ||\n isRecordOfSchemaLike(schema.dependentSchemas)) &&\n isOptionalNumber(schema.minProperties) &&\n isOptionalNumber(schema.maxProperties) &&\n (schema.primaryKey === undefined || isStringArray(schema.primaryKey)) &&\n isOptionalString(schema.databaseSchema)\n );\n}\n\n/**\n * Type guard for string schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a string schema, false otherwise.\n */\nexport function isJsonSchemaString(input: unknown): input is JsonSchemaString {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return (\n hasValidJsonSchemaKeywords(schema) &&\n schema.type === \"string\" &&\n isOptionalNumber(schema.minLength) &&\n isOptionalNumber(schema.maxLength) &&\n isOptionalString(schema.pattern) &&\n isOptionalString(schema.format) &&\n isOptionalString(schema.default) &&\n (schema.enum === undefined || isArrayOf(schema.enum, isSetString)) &&\n isOptionalString(schema.contentMediaType) &&\n isOptionalString(schema.contentEncoding) &&\n isOptionalString(schema.contentSchema)\n );\n}\n\n/**\n * Type guard for set-like array schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a set-like array schema, false otherwise.\n */\nexport function isJsonSchemaSet(input: unknown): input is JsonSchemaSet {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return (\n hasValidJsonSchemaKeywords(schema) &&\n schema.type === \"array\" &&\n schema.uniqueItems === true &&\n isOptionalJsonSchemaArray(schema.prefixItems) &&\n isOptionalJsonSchema(schema.items) &&\n isOptionalJsonSchema(schema.contains) &&\n isOptionalNumber(schema.minItems) &&\n isOptionalNumber(schema.maxItems) &&\n isOptionalNumber(schema.minContains) &&\n isOptionalNumber(schema.maxContains) &&\n (schema.unevaluatedItems === undefined ||\n isBoolean(schema.unevaluatedItems) ||\n isJsonSchema(schema.unevaluatedItems))\n );\n}\n\n/**\n * Type guard for record schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a record schema, false otherwise.\n */\nexport function isJsonSchemaRecord(input: unknown): input is JsonSchemaRecord {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return (\n hasValidJsonSchemaKeywords(schema) &&\n schema.type === \"object\" &&\n (schema.patternProperties === undefined ||\n isRecordOfSchemaLike(schema.patternProperties)) &&\n (schema.additionalProperties === undefined ||\n isBoolean(schema.additionalProperties) ||\n isJsonSchema(schema.additionalProperties)) &&\n isOptionalJsonSchema(schema.propertyNames)\n );\n}\n\n/**\n * Type guard for tuple schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a tuple schema, false otherwise.\n */\nexport function isJsonSchemaTuple(input: unknown): input is JsonSchemaTuple {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return (\n hasValidJsonSchemaKeywords(schema) &&\n schema.type === \"array\" &&\n isArrayOf(schema.prefixItems, isJsonSchema) &&\n isOptionalNumber(schema.minItems) &&\n isOptionalNumber(schema.maxItems) &&\n isOptionalJsonSchema(schema.items) &&\n isOptionalJsonSchema(schema.contains) &&\n isOptionalBoolean(schema.uniqueItems) &&\n isOptionalNumber(schema.minContains) &&\n isOptionalNumber(schema.maxContains) &&\n (schema.unevaluatedItems === undefined ||\n isBoolean(schema.unevaluatedItems) ||\n isJsonSchema(schema.unevaluatedItems))\n );\n}\n\n/**\n * Type guard for undefined-representing schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is an undefined-representing schema, false otherwise.\n */\nexport function isJsonSchemaUndefined(\n input: unknown\n): input is JsonSchemaUndefined {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return (\n hasValidJsonSchemaKeywords(schema) &&\n isJsonSchemaAny(schema.not) &&\n (schema.default === undefined || schema.default === undefined)\n );\n}\n\n/**\n * Type guard for primitive-union schema variants.\n *\n * @param input - The value to check.\n * @returns True if the input is a primitive-union schema variant, false otherwise.\n */\nexport function isJsonSchemaPrimitiveUnion(\n input: unknown\n): input is JsonSchemaPrimitiveUnion {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (!hasValidJsonSchemaKeywords(schema)) {\n return false;\n }\n\n if (\n isSetString(schema.type) &&\n JSON_SCHEMA_PRIMITIVE_TYPE_SET.has(schema.type as JsonSchemaPrimitiveType)\n ) {\n if (schema.enum === undefined) {\n return true;\n }\n\n if (!Array.isArray(schema.enum)) {\n return false;\n }\n\n if (schema.type === \"string\") {\n return (\n schema.enum.every(value => isSetString(value)) &&\n (schema.default === undefined || isSetString(schema.default))\n );\n }\n\n if (schema.type === \"number\") {\n return (\n schema.enum.every(value => isSetNumber(value)) &&\n (schema.default === undefined || isSetNumber(schema.default))\n );\n }\n\n if (schema.type === \"boolean\") {\n return (\n schema.enum.every(value => isBoolean(value)) &&\n (schema.default === undefined || isBoolean(schema.default))\n );\n }\n\n if (schema.type === \"integer\") {\n if (schema.format !== \"int64\") {\n return false;\n }\n\n return (\n schema.enum.every(value => isSetBigint(value)) &&\n (schema.default === undefined || isSetBigint(schema.default))\n );\n }\n\n return (\n schema.type === \"null\" &&\n schema.enum.every(value => value === null) &&\n (schema.default === undefined || schema.default === null)\n );\n }\n\n return isOptionalPrimitiveTypeArray(schema.type) && schema.type !== undefined;\n}\n\n/**\n * Type guard for union schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a union schema, false otherwise.\n */\nexport function isJsonSchemaUnion(input: unknown): input is JsonSchemaUnion {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return (\n hasValidJsonSchemaKeywords(schema) &&\n (isJsonSchemaPrimitiveUnion(schema) || isJsonSchemaAnyOf(schema))\n );\n}\n\n/**\n * Type guard for permissive unknown schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a permissive unknown schema, false otherwise.\n */\nexport function isJsonSchemaUnknown(\n input: unknown\n): input is JsonSchemaUnknown {\n return isJsonSchemaAny(input);\n}\n\n/**\n * Type guard for `anyOf` composition schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is an `anyOf` schema, false otherwise.\n */\nexport function isJsonSchemaAnyOf(input: unknown): input is JsonSchemaAnyOf {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return (\n hasValidJsonSchemaKeywords(schema) && isArrayOf(schema.anyOf, isJsonSchema)\n );\n}\n\n/**\n * Type guard for reference schemas.\n *\n * @param input - The value to check.\n * @returns True if the input is a reference schema, false otherwise.\n */\nexport function isJsonSchemaRef(input: unknown): input is JsonSchemaRef {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n\n return hasValidJsonSchemaKeywords(schema) && isSetString(schema.$ref);\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 isBoolean(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(input: unknown): input is JsonSchema {\n return (\n isJsonSchemaString(input) ||\n isJsonSchemaInteger(input) ||\n isJsonSchemaDecimal(input) ||\n isJsonSchemaBigint(input) ||\n isJsonSchemaBoolean(input) ||\n isJsonSchemaDate(input) ||\n isJsonSchemaEnum(input) ||\n isJsonSchemaLiteral(input) ||\n isJsonSchemaNativeEnum(input) ||\n isJsonSchemaNull(input) ||\n isJsonSchemaArray(input) ||\n isJsonSchemaObject(input) ||\n isJsonSchemaRecord(input) ||\n isJsonSchemaTuple(input) ||\n isJsonSchemaUnion(input) ||\n isJsonSchemaUndefined(input) ||\n isJsonSchemaRef(input) ||\n isJsonSchemaNever(input) ||\n isJsonSchemaMap(input) ||\n isJsonSchemaAny(input) ||\n isJsonSchemaNullable(input) ||\n isJsonSchemaAllOf(input) ||\n isJsonSchemaUnknown(input) ||\n isJsonSchemaSet(input)\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(input: unknown): input is JsonSchemaNull {\n return isJsonSchemaNull(input);\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 (!isUntypedTypeDescriptor(schema)) {\n return false;\n }\n if (\"id\" in schema && !isSetString(schema.id)) {\n return false;\n }\n if (\"resolve\" in schema && !isFunction(schema.resolve)) {\n return false;\n }\n if (\"properties\" in schema && !isRecordOfUntypedSchema(schema.properties)) {\n return false;\n }\n if (\"required\" in schema && !isStringArray(schema.required)) {\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 (\"tags\" in schema && !isStringArray(schema.tags)) {\n return false;\n }\n if (\n \"args\" in schema &&\n (!Array.isArray(schema.args) ||\n !schema.args.every(item => isUntypedFunctionArg(item)))\n ) {\n return false;\n }\n if (\"returns\" in schema && !isUntypedTypeDescriptor(schema.returns)) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Strict type guard for untyped schema objects.\n *\n * @remarks\n * This guard narrows values to the Untyped schema model while explicitly\n * rejecting values that are also valid JSON Schema instances.\n *\n * @param input - The value to check.\n * @returns True if the input is an untyped schema and not a JSON Schema.\n */\nexport function isUntypedSchemaStrict(input: unknown): input is UntypedSchema {\n return isUntypedSchema(input) && !isJsonSchema(input);\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 * Strict type guard for untyped input objects.\n *\n * @remarks\n * This guard narrows values to the Untyped input-object model while\n * explicitly rejecting values that are valid JSON Schema objects.\n *\n * @param input - The value to check.\n * @returns True if the input is an untyped input object and not JSON Schema.\n */\nexport function isUntypedInputStrict(\n input: unknown\n): input is UntypedInputObject {\n if (!isUntypedInput(input) || isJsonSchema(input)) {\n return false;\n }\n\n const inputObject = input as Record<string, unknown>;\n if (\n \"$schema\" in inputObject &&\n inputObject.$schema !== undefined &&\n !isUntypedSchemaStrict(inputObject.$schema)\n ) {\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(input: unknown): input is Schema {\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\n/**\n * Type guard for extracted schema objects that include source information.\n *\n * @param input - The value to check.\n * @returns True if the input is a SchemaWithSource object, false otherwise.\n */\nexport function isSchemaWithSource(input: unknown): input is SchemaWithSource {\n return (\n isSchema(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\n/**\n * Type guard for Powerlines Schemas that are in Object form.\n *\n * @param input - The value to check.\n * @returns True if the input is a Powerlines Schema object in Object form, false otherwise.\n */\nexport function isSchemaObject(\n input: unknown\n): input is Schema<JsonSchemaObject> {\n return isSchema(input) && isJsonSchemaObject(input.schema);\n}\n","/* -------------------------------------------------------------------\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 { 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 * Keywords whose values are a flat record of named JSON Schema fragments.\n * Each child schema is merged recursively with its counterpart.\n */\nconst SCHEMA_RECORD_KEYWORDS = new Set([\n \"properties\",\n \"patternProperties\",\n \"$defs\",\n \"definitions\",\n \"dependentSchemas\"\n]);\n\n/**\n * Keywords whose value is a single JSON Schema fragment that should be\n * recursively merged when both sides define it.\n */\nconst SCHEMA_SINGLE_KEYWORDS = new Set([\n \"if\",\n \"then\",\n \"else\",\n \"not\",\n \"contains\",\n \"items\",\n \"additionalProperties\",\n \"unevaluatedProperties\",\n \"propertyNames\",\n \"unevaluatedItems\"\n]);\n\n/**\n * Keywords whose values are arrays of JSON Schema fragments that should be\n * concatenated (rather than overridden) during a merge.\n */\nconst SCHEMA_ARRAY_CONCAT_KEYWORDS = new Set([\"allOf\", \"anyOf\", \"oneOf\"]);\n\n/**\n * Recursively merges two JSON Schema fragments. `override` wins for any scalar\n * key that both schemas define, while structured keywords are handled\n * specially:\n *\n * - `properties`, `patternProperties`, `$defs`, `definitions`,\n * `dependentSchemas` — each matching child schema is merged recursively.\n * - `allOf`, `anyOf`, `oneOf` — arrays are concatenated.\n * - `if`, `then`, `else`, `not`, `contains`, `items`,\n * `additionalProperties`, `unevaluatedProperties`, `propertyNames`,\n * `unevaluatedItems` — merged recursively when both sides are schemas.\n * - `required` — arrays are unioned and deduplicated.\n */\nfunction mergeTwo(base: JsonSchema, override: JsonSchema): JsonSchema {\n const baseObj = base as Record<string, unknown>;\n const result: Record<string, unknown> = { ...baseObj };\n\n for (const [key, overrideValue] of Object.entries(\n override as Record<string, unknown>\n )) {\n const baseValue = result[key];\n\n if (key === \"required\") {\n result[key] = getUnique([\n ...(Array.isArray(baseValue) ? (baseValue as string[]) : []),\n ...(Array.isArray(overrideValue) ? (overrideValue as string[]) : [])\n ]);\n } else if (\n SCHEMA_RECORD_KEYWORDS.has(key) &&\n isSetObject(baseValue) &&\n isSetObject(overrideValue)\n ) {\n const merged: Record<string, unknown> = {\n ...(baseValue as Record<string, unknown>)\n };\n for (const [childKey, childOverride] of Object.entries(\n overrideValue as Record<string, unknown>\n )) {\n const childBase = merged[childKey];\n merged[childKey] =\n isJsonSchema(childBase) && isJsonSchema(childOverride)\n ? mergeTwo(childBase, childOverride)\n : childOverride;\n }\n result[key] = merged;\n } else if (\n SCHEMA_ARRAY_CONCAT_KEYWORDS.has(key) &&\n Array.isArray(baseValue) &&\n Array.isArray(overrideValue)\n ) {\n result[key] = [\n ...(baseValue as JsonSchema[]),\n ...(overrideValue as JsonSchema[])\n ];\n } else if (\n SCHEMA_SINGLE_KEYWORDS.has(key) &&\n isJsonSchema(baseValue) &&\n isJsonSchema(overrideValue)\n ) {\n result[key] = mergeTwo(baseValue, overrideValue);\n } else {\n result[key] = overrideValue;\n }\n }\n\n return result;\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\n * into a single JSON Schema object. Later schemas in the argument list take\n * precedence over earlier ones for scalar conflicts.\n *\n * Structured keywords are merged recursively:\n * - Named child schemas (`properties`, `$defs`, etc.) are merged\n * per-property via recursive calls to `merge`.\n * - Composition arrays (`allOf`, `anyOf`, `oneOf`) are concatenated.\n * - Single-schema keywords (`if`, `then`, `else`, `not`, `items`, etc.)\n * are merged recursively when both sides define them.\n * - `required` arrays are unioned and deduplicated.\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 const jsonSchemas = schemas.map(s => getJsonSchema(s));\n if (jsonSchemas.length === 0) {\n return {};\n }\n\n return jsonSchemas.reduce((acc, schema) => {\n const accType = (acc as JsonSchemaLike).type;\n const schemaType = (schema as JsonSchemaLike).type;\n\n if (accType && schemaType && accType !== schemaType) {\n // Incompatible types — the later schema wins entirely.\n return schema;\n }\n\n return mergeTwo(acc, schema);\n });\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","/* -------------------------------------------------------------------\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(schema: JsonSchema): 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(schema: JsonSchema): ValidateFunction {\n const ajv = getValidator(schema);\n\n return ajv.compile(schema);\n}\n","/* -------------------------------------------------------------------\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 { toBool } from \"@stryke/convert/to-bool\";\nimport { isInteger, isObject, isString } from \"@stryke/type-checks\";\nimport { isBoolean } from \"@stryke/type-checks/is-boolean\";\nimport { isNull } from \"@stryke/type-checks/is-null\";\nimport { isNumber } from \"@stryke/type-checks/is-number\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isUndefined } from \"@stryke/type-checks/is-undefined\";\nimport standaloneCode from \"ajv/dist/standalone\";\nimport { getPropertiesList, isSchemaNullable } from \"./helpers\";\nimport { getPrimarySchemaType } from \"./metadata\";\nimport { isJsonSchema, isJsonSchemaObject } from \"./type-checks\";\nimport { JsonSchema, JsonSchemaType } from \"./types\";\nimport { getValidator } from \"./validate\";\n\ninterface JsonSchemaObjectView {\n $ref?: string;\n type?: JsonSchemaType | readonly JsonSchemaType[];\n enum?: readonly unknown[];\n const?: unknown;\n items?: JsonSchema;\n properties?: Record<string, JsonSchema>;\n additionalProperties?: boolean | JsonSchema;\n required?: string[];\n oneOf?: JsonSchema[];\n anyOf?: JsonSchema[];\n allOf?: JsonSchema[];\n}\n\n/**\n * Stringifies a value for generated TypeScript code.\n */\nexport function stringifyValue(\n value?: unknown,\n type?: JsonSchemaType | string\n): string {\n return isUndefined(value)\n ? \"undefined\"\n : isNull(value)\n ? \"null\"\n : type === \"boolean\" || isBoolean(value)\n ? String(toBool(value))\n : type === \"number\" || isNumber(value)\n ? Number.parseFloat(String(value)).toLocaleString(undefined, {\n maximumFractionDigits: 20\n })\n : type === \"integer\"\n ? Number.parseInt(String(value)).toLocaleString()\n : type === \"string\" || type === \"object\" || type === \"array\"\n ? JSON.stringify(value)\n : String(value);\n}\n\n/**\n * Stringifies a JSON Schema fragment into a TypeScript-like type string.\n */\nexport function stringifyType(schema?: JsonSchema): string {\n if (!schema) {\n return \"unknown\";\n }\n\n if (typeof schema === \"boolean\") {\n return schema ? \"unknown\" : \"never\";\n }\n\n const objectSchema = schema as JsonSchemaObjectView;\n\n if (isSetString(objectSchema.$ref)) {\n const match = /^#\\/(?:definitions|\\$defs)\\/(.+)$/.exec(objectSchema.$ref);\n\n return match?.[1] ?? objectSchema.$ref;\n }\n\n const primaryType = getPrimarySchemaType(schema);\n if (primaryType) {\n if (primaryType === \"integer\" || primaryType === \"number\") {\n return \"number\";\n }\n\n return primaryType;\n }\n\n if (objectSchema.type === \"array\" && Array.isArray(objectSchema.enum)) {\n const enumValues = objectSchema.enum as readonly unknown[];\n\n return enumValues\n .map((value: unknown) => JSON.stringify(value))\n .join(\" | \");\n }\n\n if (objectSchema.const !== undefined) {\n return JSON.stringify(objectSchema.const);\n }\n\n if (objectSchema.type === \"array\" || objectSchema.items) {\n return `${stringifyType(objectSchema.items)}[]`;\n }\n\n if (\n objectSchema.type === \"object\" ||\n objectSchema.properties ||\n objectSchema.additionalProperties\n ) {\n if (isJsonSchema(objectSchema.additionalProperties)) {\n return `{ [key: string]: ${stringifyType(objectSchema.additionalProperties)} }`;\n }\n\n if (isJsonSchemaObject(objectSchema)) {\n const required = objectSchema.required ?? [];\n\n return `{ ${getPropertiesList(objectSchema)\n .map(property => {\n const suffix =\n !required.includes(property.name) || isSchemaNullable(property)\n ? `${!required.includes(property.name) ? \"?\" : \"\"}${isSchemaNullable(property) ? \" | null\" : \"\"}`\n : \"\";\n\n return `${property.name}${suffix}: ${stringifyType(property)}`;\n })\n .join(\";\\n\")} }`;\n }\n }\n\n if (objectSchema.oneOf || objectSchema.anyOf) {\n return (objectSchema.oneOf ?? objectSchema.anyOf ?? [])\n .map(branch => stringifyType(branch))\n .join(\" | \");\n }\n\n if (objectSchema.allOf) {\n return \"object\";\n }\n\n return \"unknown\";\n}\n\n/**\n * Returns a string type representation of a value based on its type and an optional JSON Schema primitive type hint.\n *\n * @param value - The value whose type is to be represented as a string.\n * @returns A string representation of the value's type, which may be influenced by the provided JSON Schema primitive type hint. The function handles various JavaScript types and formats them accordingly, including special handling for `undefined`, `null`, booleans, numbers (with formatting), strings, objects, and arrays. If a specific type hint is provided, it will take precedence in determining the string representation of the value.\n */\nexport function getJsonSchemaType(value?: unknown): JsonSchemaType | undefined {\n return isNull(value)\n ? \"null\"\n : isBoolean(value)\n ? \"boolean\"\n : isInteger(value)\n ? \"integer\"\n : isNumber(value)\n ? \"number\"\n : isString(value)\n ? \"string\"\n : isObject(value)\n ? \"object\"\n : Array.isArray(value)\n ? \"array\"\n : undefined;\n}\n\n/**\n * Generates standalone JSON Schema validation code using Ajv.\n */\nexport async function generateCode(\n schemas: JsonSchema,\n refsOrFuncts?: Parameters<typeof standaloneCode>[1]\n) {\n const ajv = getValidator(schemas);\n\n return standaloneCode(ajv, refsOrFuncts);\n}\n","/* -------------------------------------------------------------------\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 { Context } from \"@powerlines/core\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { extractHash, extractVariant } from \"./extract\";\nimport { isSchema } from \"./type-checks\";\nimport { Schema, SchemaInput } from \"./types\";\n\n/**\n * A helper function to get the cache directory path for storing schemas. This function takes a context object as input and returns the path to the cache directory where schemas are stored. The cache directory is constructed by joining the `cachePath` property from the context with a subdirectory named \"schemas\". This function is useful for centralizing the logic for determining where schema files should be cached, ensuring that all schema-related file operations use a consistent location for storing and retrieving cached schemas.\n *\n * @param context - The context object providing access to the cache path.\n * @returns The path to the cache directory for storing schemas, constructed by joining the context's `cachePath` with the \"schemas\" subdirectory.\n */\nexport function getCacheDirectory(context: Context): string {\n return joinPaths(context.cachePath, \"schemas\");\n}\n\n/**\n * A helper function to get the file path for a cached schema based on the provided context and schema input. This function first extracts the variant and hash from the input schema using the `extractVariant` and `extractHash` functions, respectively. It then constructs the file path to the cached schema JSON file by joining the cache directory path (obtained from the `getCacheDirectory` function) with a filename derived from the extracted hash. The resulting file path points to where the cached schema should be stored or retrieved from in the file system. This function is essential for ensuring that all operations related to caching schemas use a consistent method for determining the correct file path based on the schema's unique identifier (hash).\n *\n * @param context - The context object providing access to the cache path.\n * @param input - The input schema from which to extract the variant and hash for constructing the cache file path.\n * @returns The file path to the cached schema JSON file, constructed by joining the cache directory path with a filename derived from the extracted hash of the schema input.\n */\nexport function getCacheFilePath(context: Context, input: SchemaInput): string {\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n\n return joinPaths(getCacheDirectory(context), `${hash}.json`);\n}\n\n/**\n * Writes a given schema to the file system using the provided context. This function first checks if the input is a valid schema using the `isSchema` type guard. If the input is not a valid schema, it throws an error indicating that the provided input is invalid. If the input is valid, it proceeds to write the schema to a JSON file in the cache directory specified by the context. The file is named using the hash of the schema to ensure uniqueness and easy retrieval in future operations. The schema is serialized to JSON format before being written to the file system. This function is asynchronous and returns a promise that resolves once the writing operation is complete.\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param schema - The schema to be written to the file system, which must be a valid schema object containing a `variant`, `schema`, and `hash` property.\n * @throws Will throw an error if the provided input is not a valid schema.\n */\nexport async function writeSchema(context: Context, schema: Schema) {\n if (!isSchema(schema)) {\n throw new Error(\n `The provided input is not a valid schema. A valid schema must have a \"variant\" property indicating the type of the input and a \"schema\" property containing the parsed JSON Schema object.`\n );\n }\n\n await context.fs.write(\n getCacheFilePath(context, schema),\n JSON.stringify(schema.schema)\n );\n}\n\n/**\n * A helper function to read a schema from the file system using the provided context. This function first extracts the variant and hash from the input schema using the `extractVariant` and `extractHash` functions, respectively. It then constructs the file path to the cached schema JSON file based on the cache path provided in the context and the extracted hash. The function checks if the file exists in the cache; if it does not exist, it returns `undefined`. If the file exists, it reads the contents of the file, parses it as JSON, and returns the resulting object. This function is asynchronous and returns a promise that resolves to either the parsed schema object or `undefined` if the schema is not found in the cache.\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param input - The input schema from which to extract the variant and hash for locating the cached schema file.\n * @returns A promise that resolves to the parsed schema object if found in the cache, or `undefined` if the schema does not exist in the cache.\n */\nexport async function readSchemaSafe(\n context: Context,\n input: SchemaInput\n): Promise<Schema | undefined> {\n const cacheFilePath = getCacheFilePath(context, input);\n if (!(await context.fs.exists(cacheFilePath))) {\n return undefined;\n }\n\n const data = await context.fs.read(cacheFilePath);\n if (!data) {\n return undefined;\n }\n\n return JSON.parse(data);\n}\n\n/**\n * Reads a schema from the file system using the provided context and input. This function first attempts to read the schema using the `readSchemaSafe` helper function, which returns `undefined` if the schema is not found in the cache. If the schema is not found, this function throws an error indicating that the schema with the specified variant and hash does not exist in the cache. The error message suggests that this may be due to a missing or corrupted cache file, or because the schema has not been written to the cache yet. It advises ensuring that the schema is properly written to the cache before attempting to read it. If the schema is successfully read from the cache, it is returned as a parsed object. This function is asynchronous and returns a promise that resolves to the parsed schema object if found, or throws an error if the schema is not found in the cache.\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param input - The input schema from which to extract the variant and hash for locating the cached schema file.\n * @returns A promise that resolves to the parsed schema object if found in the cache, or throws an error if the schema does not exist in the cache.\n * @throws Will throw an error if the schema with the specified variant and hash does not exist in the cache.\n */\nexport async function readSchema(\n context: Context,\n input: SchemaInput\n): Promise<Schema> {\n const schema = await readSchemaSafe(context, input);\n if (!schema) {\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n\n throw new Error(\n `The ${variant} schema with hash \"${\n hash\n }\" does not exist in the cache. This may be due to a missing or corrupted cache file, or because the schema has not been written to the cache yet. Please ensure that the schema is properly written to the cache before attempting to read it.`\n );\n }\n\n return schema;\n}\n","/* -------------------------------------------------------------------\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 {\n TagsReflection,\n Type,\n TypeClass\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n ReflectionClass,\n ReflectionKind,\n TypeNumberBrand,\n TypeObjectLiteral\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n isBigInt,\n isBoolean,\n isInteger,\n isNull,\n isNumber,\n isRegExp,\n isSetArray,\n isSetObject,\n isSetString,\n isString,\n isUndefined\n} from \"@stryke/type-checks\";\nimport defu from \"defu\";\nimport { getJsonSchemaType } from \"./codegen\";\nimport {\n isJsonSchemaObject,\n isJsonSchemaPrimitiveType,\n isNullOnlyJsonSchema\n} from \"./type-checks\";\nimport {\n JsonSchema,\n JsonSchemaNullable,\n JsonSchemaObject,\n JsonSchemaPrimitiveType\n} from \"./types\";\n\n/**\n * Maps a Deepkit numeric `brand` to JSON Schema `type` and `format`.\n *\n * @remarks\n * This function takes a `TypeNumberBrand` (which represents specific numeric types in Deepkit, such as `integer`, `float`, `int8`, etc.) and returns a corresponding JSON Schema fragment that includes the appropriate `type`, `format`, and any relevant keywords (like `multipleOf` for integers). If the brand is not recognized, it defaults to a generic JSON Schema for numbers.\n *\n * @param brand - The Deepkit numeric brand to convert.\n * @return A JSON Schema fragment representing the numeric type corresponding to the provided brand.\n */\nfunction numberBrandToJsonSchema(\n brand: TypeNumberBrand | undefined\n): JsonSchema {\n switch (brand) {\n case TypeNumberBrand.integer:\n return {\n type: \"integer\",\n format: \"int32\",\n multipleOf: 1\n };\n case TypeNumberBrand.int8:\n return { type: \"integer\", format: \"int8\", multipleOf: 1 };\n case TypeNumberBrand.uint8:\n return { type: \"integer\", format: \"uint8\", multipleOf: 1 };\n case TypeNumberBrand.int16:\n return { type: \"integer\", format: \"int16\", multipleOf: 1 };\n case TypeNumberBrand.uint16:\n return { type: \"integer\", format: \"uint16\", multipleOf: 1 };\n case TypeNumberBrand.int32:\n return { type: \"integer\", format: \"int32\", multipleOf: 1 };\n case TypeNumberBrand.uint32:\n return { type: \"integer\", format: \"uint32\", multipleOf: 1 };\n case TypeNumberBrand.float:\n case TypeNumberBrand.float32:\n return { type: \"number\", format: \"float\" };\n case TypeNumberBrand.float64:\n return { type: \"number\", format: \"double\" };\n case undefined:\n default:\n return { type: \"number\" };\n }\n}\n\nfunction withReflectionTags(reflection: Type, schema: JsonSchema): JsonSchema {\n if (\n !isSetObject(schema) ||\n !isSetObject((reflection as { tags?: TagsReflection })?.tags)\n ) {\n return schema;\n }\n\n const updatedSchema = { ...schema };\n const tags = (reflection as { tags: TagsReflection }).tags;\n if (isSetString(tags.title)) {\n updatedSchema.title = tags.title;\n }\n if (isSetArray(tags.alias)) {\n updatedSchema.alias = tags.alias;\n }\n if (!isUndefined(tags.hidden)) {\n updatedSchema.hidden = tags.hidden;\n }\n if (!isUndefined(tags.ignore)) {\n updatedSchema.ignore = tags.ignore;\n }\n if (!isUndefined(tags.internal)) {\n updatedSchema.internal = tags.internal;\n }\n if (!isUndefined(tags.runtime)) {\n updatedSchema.runtime = tags.runtime;\n }\n if (!isUndefined(tags.readonly)) {\n updatedSchema.readOnly = tags.readonly;\n }\n\n return updatedSchema;\n}\n\nfunction withNullable(schema: JsonSchema): JsonSchemaNullable {\n if (!isSetObject(schema)) {\n return {\n anyOf: [schema, { type: \"null\", default: null }]\n };\n }\n\n const rawType = (schema as { type?: string | readonly string[] }).type;\n\n const types = Array.isArray(rawType)\n ? [...rawType]\n : rawType\n ? [rawType]\n : [];\n if (!types.includes(\"null\")) {\n types.push(\"null\");\n }\n\n return {\n ...schema,\n type: types.length === 1 ? types[0] : types\n };\n}\n\n/**\n * Converts a Deepkit type reflection into a JSON Schema (draft-07) fragment.\n */\nexport function reflectionToJsonSchema(\n reflection: Type\n): JsonSchema | undefined {\n return reflectionToJsonSchemaInner(reflection);\n}\n\nfunction reflectionToJsonSchemaInner(reflection: Type): JsonSchema | undefined {\n switch (reflection.kind) {\n case ReflectionKind.any:\n case ReflectionKind.unknown:\n case ReflectionKind.void:\n case ReflectionKind.object:\n return withReflectionTags(reflection, { name: reflection.typeName });\n case ReflectionKind.never:\n return undefined;\n case ReflectionKind.undefined:\n case ReflectionKind.null:\n return withReflectionTags(reflection, {\n type: \"null\",\n name: reflection.typeName,\n default: null\n });\n case ReflectionKind.string:\n return withReflectionTags(reflection, {\n type: \"string\",\n name: reflection.typeName\n });\n case ReflectionKind.boolean:\n return withReflectionTags(reflection, {\n type: \"boolean\",\n name: reflection.typeName\n });\n case ReflectionKind.number: {\n const numeric = numberBrandToJsonSchema(reflection.brand);\n\n return withReflectionTags(reflection, numeric);\n }\n case ReflectionKind.bigint:\n return withReflectionTags(reflection, {\n type: \"integer\",\n name: reflection.typeName,\n format: \"int64\"\n });\n case ReflectionKind.regexp:\n return withReflectionTags(reflection, {\n type: \"string\",\n name: reflection.typeName,\n format: \"regex\",\n contentMediaType: \"text/regex\"\n });\n case ReflectionKind.literal: {\n const { literal } = reflection;\n if (isBigInt(literal)) {\n return withReflectionTags(reflection, {\n type: \"integer\",\n name: reflection.typeName,\n format: \"int64\",\n const: literal\n });\n }\n\n if (isRegExp(literal)) {\n return withReflectionTags(reflection, {\n type: \"string\",\n name: reflection.typeName,\n format: \"regex\",\n const: literal.source\n });\n }\n\n return withReflectionTags(reflection, {\n type: getJsonSchemaType(literal),\n name: reflection.typeName,\n const: literal\n });\n }\n case ReflectionKind.templateLiteral:\n return withReflectionTags(reflection, { type: \"string\" });\n case ReflectionKind.enum: {\n const values = reflection.values.filter(\n value =>\n isString(value) ||\n isInteger(value) ||\n isBigInt(value) ||\n isNumber(value) ||\n isBoolean(value) ||\n isNull(value)\n ) as (string | number | bigint | boolean | null)[];\n if (values.length === 0) {\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n description: reflection.description,\n enum: []\n });\n }\n\n return withReflectionTags(reflection, {\n type: values.every(value => isString(value))\n ? \"string\"\n : values.every(value => isInteger(value) || isBigInt(value))\n ? \"integer\"\n : values.every(value => isNumber(value))\n ? \"number\"\n : values.every(value => isBoolean(value))\n ? \"boolean\"\n : values.every(value => isNull(value))\n ? \"null\"\n : values.reduce((ret, value) => {\n const type = getJsonSchemaType(value);\n if (\n isJsonSchemaPrimitiveType(type) &&\n !ret.includes(type)\n ) {\n ret.push(type);\n }\n\n return ret;\n }, [] as JsonSchemaPrimitiveType[]),\n name: reflection.typeName,\n description: reflection.description,\n enum: values,\n default: values.length === 1 ? values[0] : undefined\n });\n }\n case ReflectionKind.array: {\n const items = reflectionToJsonSchemaInner(reflection.type);\n\n return withReflectionTags(reflection, {\n type: \"array\",\n name: reflection.typeName,\n items: items ?? {}\n });\n }\n case ReflectionKind.tuple: {\n const items = reflection.types\n .map(member => reflectionToJsonSchemaInner(member.type))\n .filter((item): item is JsonSchema => item !== undefined);\n if (items.length <= 1) {\n return withReflectionTags(reflection, {\n type: \"array\",\n name: reflection.typeName,\n items: items.length === 1 ? items[0] : {}\n });\n }\n\n return withReflectionTags(reflection, {\n type: \"array\",\n name: reflection.typeName,\n prefixItems: items,\n minItems: items.length,\n maxItems: items.length\n });\n }\n case ReflectionKind.union: {\n const branches = reflection.types\n .map(inner => reflectionToJsonSchemaInner(inner))\n .filter((branch): branch is JsonSchema => branch !== undefined);\n if (\n !reflection.types.some(\n inner =>\n inner.kind === ReflectionKind.null ||\n inner.kind === ReflectionKind.undefined\n )\n ) {\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n anyOf: branches\n });\n }\n\n const nonNull = branches.filter(branch => !isNullOnlyJsonSchema(branch));\n if (nonNull.length === 0) {\n return withReflectionTags(reflection, {\n type: \"null\",\n default: null\n });\n }\n\n if (nonNull.length === 1) {\n const first = nonNull[0]!;\n\n if (!isSetObject(first)) {\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n anyOf: [first]\n })\n );\n }\n\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n ...(first as Record<string, unknown>)\n })\n );\n }\n\n const enumValues = nonNull\n .map(branch =>\n isSetObject(branch)\n ? (branch as { const?: unknown }).const\n : undefined\n )\n .filter(\n (value): value is string | number | bigint | boolean | null =>\n value === null ||\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"bigint\" ||\n typeof value === \"boolean\"\n );\n if (enumValues.length === nonNull.length) {\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n enum: enumValues\n })\n );\n }\n\n const discriminator = tryReflectionDiscriminator(reflection.types);\n if (discriminator && isSetObject(discriminator)) {\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n ...(discriminator as Record<string, unknown>)\n })\n );\n }\n\n return withNullable(\n withReflectionTags(reflection, {\n name: reflection.typeName,\n anyOf: nonNull\n })\n );\n }\n case ReflectionKind.intersection: {\n const members = reflection.types\n .map(inner => reflectionToJsonSchemaInner(inner))\n .filter((item): item is JsonSchema => item !== undefined);\n if (members.length === 0) {\n return undefined;\n }\n if (members.length === 1) {\n if (!isSetObject(members[0])) {\n return members[0];\n }\n\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n ...members[0]\n });\n }\n if (members.every(isJsonSchemaObject)) {\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n ...mergeObjectSchemas(members)\n });\n }\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n allOf: members\n });\n }\n case ReflectionKind.promise:\n return reflectionToJsonSchemaInner(reflection.type);\n case ReflectionKind.objectLiteral:\n return objectReflectionToJsonSchema(reflection);\n case ReflectionKind.class: {\n const classType = reflection.classType as { name?: string } | undefined;\n const className = classType?.name;\n switch (className) {\n case \"Date\":\n return withReflectionTags(reflection, {\n type: \"string\",\n format: \"date-time\"\n });\n case \"RegExp\":\n return withReflectionTags(reflection, {\n type: \"string\",\n format: \"regex\"\n });\n case \"URL\":\n return withReflectionTags(reflection, {\n type: \"string\",\n format: \"uri\"\n });\n case \"Set\": {\n const itemType = reflection.arguments?.[0];\n const items = itemType\n ? reflectionToJsonSchemaInner(itemType)\n : undefined;\n\n return withReflectionTags(reflection, {\n type: \"array\",\n items: items ?? {},\n uniqueItems: true\n });\n }\n case \"Map\": {\n const valueType = reflection.arguments?.[1];\n const values = valueType\n ? reflectionToJsonSchemaInner(valueType)\n : undefined;\n\n return withReflectionTags(reflection, {\n type: \"object\",\n additionalProperties: values ?? true\n });\n }\n case \"Uint8Array\":\n case \"Uint8ClampedArray\":\n case \"Uint16Array\":\n case \"Uint32Array\":\n case \"Int8Array\":\n case \"Int16Array\":\n case \"Int32Array\":\n case \"Float32Array\":\n case \"Float64Array\":\n case \"BigInt64Array\":\n case \"BigUint64Array\":\n return withReflectionTags(reflection, {\n type: \"string\",\n format: \"byte\",\n contentEncoding: \"base64\"\n });\n case undefined:\n default:\n return withReflectionTags(reflection, {\n name: reflection.typeName,\n description: reflection.description,\n ...objectReflectionToJsonSchema(reflection)\n });\n }\n }\n case ReflectionKind.symbol:\n case ReflectionKind.property:\n case ReflectionKind.method:\n case ReflectionKind.function:\n case ReflectionKind.parameter:\n case ReflectionKind.typeParameter:\n case ReflectionKind.tupleMember:\n case ReflectionKind.enumMember:\n case ReflectionKind.rest:\n case ReflectionKind.indexSignature:\n case ReflectionKind.propertySignature:\n case ReflectionKind.methodSignature:\n case ReflectionKind.infer:\n case ReflectionKind.callSignature:\n default:\n return undefined;\n }\n}\n\nfunction mergeObjectSchemas(schemas: JsonSchemaObject[]): JsonSchemaObject {\n const merged: JsonSchemaObject = {\n type: \"object\",\n properties: {},\n required: []\n };\n\n for (const schema of schemas) {\n if (schema.properties) {\n merged.properties = defu(merged.properties, schema.properties);\n }\n if (schema.required) {\n merged.required = Array.from(\n new Set([...(merged.required ?? []), ...schema.required])\n );\n }\n if (schema.additionalProperties !== undefined) {\n merged.additionalProperties = schema.additionalProperties;\n }\n }\n\n if ((merged.required?.length ?? 0) === 0) {\n delete merged.required;\n }\n\n return merged;\n}\n\nfunction tryReflectionDiscriminator(\n types: readonly Type[]\n): JsonSchema | undefined {\n const nonNullTypes = types.filter(\n t => t.kind !== ReflectionKind.null && t.kind !== ReflectionKind.undefined\n );\n const objectBranches: Array<TypeObjectLiteral | TypeClass> =\n nonNullTypes.filter(\n t =>\n t.kind === ReflectionKind.objectLiteral ||\n t.kind === ReflectionKind.class\n );\n\n if (\n objectBranches.length < 2 ||\n objectBranches.length !== nonNullTypes.length\n ) {\n return undefined;\n }\n\n let tagKey: string | undefined;\n const branches: JsonSchemaObject[] = [];\n\n for (const branch of objectBranches) {\n const literalProps: Array<{ name: string; literal: string }> = [];\n for (const member of branch.types) {\n if (\n (member.kind === ReflectionKind.property ||\n member.kind === ReflectionKind.propertySignature) &&\n typeof member.name === \"string\" &&\n member.type.kind === ReflectionKind.literal &&\n typeof (member.type as { literal?: unknown }).literal === \"string\"\n ) {\n literalProps.push({\n name: member.name,\n literal: (member.type as { literal: string }).literal\n });\n }\n }\n\n if (literalProps.length === 0) {\n return undefined;\n }\n\n const first = literalProps[0]!;\n if (!tagKey) {\n tagKey = first.name;\n } else if (tagKey !== first.name) {\n return undefined;\n }\n\n const filteredBranch = {\n ...branch,\n types: branch.types.filter(\n member =>\n !(\n (member.kind === ReflectionKind.property ||\n member.kind === ReflectionKind.propertySignature) &&\n member.name === tagKey\n )\n )\n } as TypeObjectLiteral | TypeClass;\n\n const body = objectReflectionToJsonSchema(filteredBranch);\n if (!body || !isJsonSchemaObject(body)) {\n return undefined;\n }\n\n branches.push({\n type: \"object\",\n properties: {\n [tagKey]: { const: first.literal },\n ...(body.properties ?? {})\n },\n required: [tagKey, ...(body.required ?? [])],\n additionalProperties: body.additionalProperties ?? false\n });\n }\n\n if (!tagKey) {\n return undefined;\n }\n\n return {\n oneOf: branches,\n discriminator: { propertyName: tagKey }\n } as JsonSchema;\n}\n\nfunction objectReflectionToJsonSchema(\n type: TypeObjectLiteral | TypeClass\n): JsonSchemaObject {\n const reflection = ReflectionClass.from(type);\n\n const schema: JsonSchemaObject = {\n type: \"object\",\n name: reflection.getName(),\n description: reflection.getDescription(),\n properties: {},\n required: [],\n readOnly: reflection.isReadonly(),\n ignore: reflection.isIgnored(),\n internal: reflection.isInternal(),\n runtime: reflection.isRuntime(),\n hidden: reflection.isHidden(),\n primaryKey: reflection\n .getPrimaries()\n .map(primary => primary.getNameAsString()),\n ...(isSetString(reflection.databaseSchemaName)\n ? { databaseSchemaName: reflection.databaseSchemaName }\n : {}),\n ...(isSetString(reflection.getName())\n ? { name: reflection.getName() }\n : {}),\n ...(isSetString(reflection.getDescription())\n ? { description: reflection.getDescription() }\n : {}),\n ...(isSetArray(reflection.getAlias())\n ? { alias: reflection.getAlias() }\n : {}),\n ...(isSetString(reflection.getTitle())\n ? { title: reflection.getTitle() }\n : {})\n };\n\n for (const propertyReflection of reflection.getProperties()) {\n if (propertyReflection.getKind() === ReflectionKind.indexSignature) {\n schema.additionalProperties =\n reflectionToJsonSchemaInner(propertyReflection.type) ?? true;\n continue;\n }\n\n let property = reflectionToJsonSchemaInner(\n propertyReflection.type\n ) as JsonSchema;\n if (!property) {\n continue;\n }\n\n const propertySchema = isSetObject(property) ? property : {};\n\n property = {\n ...propertySchema,\n name: propertyReflection.getNameAsString(),\n description: propertyReflection.getDescription(),\n readOnly: propertyReflection.isReadonly(),\n ignore: propertyReflection.isIgnored(),\n internal: propertyReflection.isInternal(),\n runtime: propertyReflection.isRuntime(),\n hidden: propertyReflection.isHidden(),\n ...(propertyReflection.hasDefault()\n ? { default: propertyReflection.getDefaultValue() }\n : {}),\n ...(isSetArray(propertyReflection.getGroups())\n ? { tags: propertyReflection.getGroups() }\n : {}),\n ...(isSetArray(propertyReflection.getAlias())\n ? { alias: propertyReflection.getAlias() }\n : {}),\n ...(isSetString(propertyReflection.getTitle())\n ? { title: propertyReflection.getTitle() }\n : {})\n };\n\n if (propertyReflection.isNullable()) {\n property = withNullable(property);\n }\n\n schema.properties ??= {};\n schema.properties[propertyReflection.name] = property;\n if (!propertyReflection.isOptional()) {\n schema.required ??= [];\n schema.required.push(propertyReflection.name);\n }\n }\n\n return schema;\n}\n","/* -------------------------------------------------------------------\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 { PluginContext, UnresolvedContext } from \"@powerlines/core\";\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport { reflect, Type } from \"@powerlines/deepkit/vendor/type\";\nimport { extractFileReference } from \"@stryke/convert/extract-file-reference\";\nimport { findFileDotExtension, findFileExtensionSafe } from \"@stryke/path/find\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { FileReference, FileReferenceInput } from \"@stryke/types/configuration\";\nimport defu from \"defu\";\nimport { parse as parseToml } from \"smol-toml\";\nimport { parse as parseYaml } from \"yaml\";\nimport { bundle, BundleOptions } from \"./bundle\";\n\n/**\n * Compiles a type definition to a module and returns the module.\n *\n * @param context - The context object containing the environment paths.\n * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.\n * @param overrides - Optional overrides for the ESBuild configuration.\n * @returns A promise that resolves to the compiled module.\n */\nexport async function resolveModule<\n TResult,\n TContext extends UnresolvedContext = UnresolvedContext\n>(\n context: TContext,\n input: FileReferenceInput,\n overrides?: BundleOptions\n): Promise<TResult> {\n const fileReference = extractFileReference(input);\n if (!fileReference) {\n throw new Error(\n `Failed to extract a file reference from the provided input ${JSON.stringify(\n input\n )}. The input must be a string or an object with a \"file\" property that specifies the file path and optional export name.`\n );\n }\n\n const result = await bundle<TContext>(context, fileReference.file, overrides);\n\n let resolved: any;\n try {\n resolved = await context.resolver.evalModule(result.text, {\n filename: result.path,\n ext: findFileDotExtension(result.path)\n });\n } catch (error) {\n if (\n isSetString((error as Error).message) &&\n new RegExp(\n `Cannot find module '${context.config.framework?.name || \"powerlines\"}:.*'`\n ).test((error as Error).message)\n ) {\n const moduleName = (error as Error).message.match(\n new RegExp(\n `Cannot find module '(${context.config.framework?.name || \"powerlines\"}:.*)'`\n )\n )?.[1];\n throw new Error(\n `The module \"${moduleName}\" could not be resolved while evaluating \"${\n fileReference.file\n }\". It is possible the required built-in modules have not yet been generated. Please check the order of your plugins. ${\n context.config.logLevel.general === \"debug\" ||\n context.config.logLevel.general === \"trace\"\n ? `\n\nBundle output for module:\n${result.text}`\n : \"\"\n }`\n );\n }\n\n throw new Error(\n `Failed to evaluate the bundled module for \"${\n fileReference.file\n }\". Error: ${(error as Error).message}${\n context.config.logLevel.general === \"debug\" ||\n context.config.logLevel.general === \"trace\"\n ? `\n\nBundle output for module:\n${result.text}`\n : \"\"\n }`\n );\n }\n\n return resolved;\n}\n\n/**\n * Compiles a type definition to a module and returns the specified export from the module.\n *\n * @param context - The context object containing the environment paths.\n * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.\n * @param options - Optional overrides for the ESBuild configuration.\n * @returns A promise that resolves to the compiled module.\n */\nexport async function resolve<\n TResult,\n TContext extends UnresolvedContext = UnresolvedContext\n>(\n context: TContext,\n input: FileReferenceInput,\n options?: BundleOptions\n): Promise<TResult> {\n const fileReference = extractFileReference(input);\n if (!fileReference) {\n throw new Error(\n `Failed to extract a file reference from the provided input. The input must be a string or an object with a \"file\" property that specifies the file path and optional export name.`\n );\n }\n\n const extension = findFileExtensionSafe(fileReference.file);\n if (extension.startsWith(\"json\")) {\n try {\n const json = await context.fs.read(fileReference.file);\n if (!isSetString(json)) {\n throw new Error(\n `The file at \"${fileReference.file}\" could not be read as a string. Please ensure the file exists and contains valid JSON.`\n );\n }\n\n return JSON.parse(json) as TResult;\n } catch (error) {\n throw new Error(\n `Failed to read or parse the JSON file at \"${fileReference.file}\". Please ensure the file exists and contains valid JSON. Error: ${(error as Error).message}`\n );\n }\n } else if (extension === \"yaml\" || extension === \"yml\") {\n try {\n const yaml = await context.fs.read(fileReference.file);\n if (!isSetString(yaml)) {\n throw new Error(\n `The file at \"${fileReference.file}\" could not be read as a string. Please ensure the file exists and contains valid YAML.`\n );\n }\n\n return parseYaml(yaml) as TResult;\n } catch (error) {\n throw new Error(\n `Failed to read or parse the YAML file at \"${fileReference.file}\". Please ensure the file exists and contains valid YAML. Error: ${(error as Error).message}`\n );\n }\n } else if (extension === \"toml\") {\n try {\n const toml = await context.fs.read(fileReference.file);\n if (!isSetString(toml)) {\n throw new Error(\n `The file at \"${fileReference.file}\" could not be read as a string. Please ensure the file exists and contains valid TOML.`\n );\n }\n\n return parseToml(toml) as TResult;\n } catch (error) {\n throw new Error(\n `Failed to read or parse the TOML file at \"${fileReference.file}\". Please ensure the file exists and contains valid TOML. Error: ${(error as Error).message}`\n );\n }\n }\n\n const resolved = await resolveModule<Record<string, any>, TContext>(\n context,\n fileReference,\n options\n );\n\n let exportName = fileReference.export;\n if (!exportName) {\n exportName = \"default\";\n }\n\n const resolvedExport = resolved[exportName] ?? resolved[`__Ω${exportName}`];\n if (resolvedExport === undefined) {\n throw new Error(\n `The export \"${exportName}\" could not be resolved in the \"${\n fileReference.file\n }\" module. ${\n Object.keys(resolved).length === 0\n ? `After bundling, no exports were found in the module. Please ensure that the \"${\n fileReference.file\n }\" module has a \"${exportName}\" export with the desired value.`\n : `After bundling, the available exports were: ${Object.keys(\n resolved\n ).join(\n \", \"\n )}. Please ensure that the export exists and is correctly named.`\n }`\n );\n }\n\n return resolvedExport;\n}\n\n/**\n * Resolves a type definition to a Deepkit Type reflection. This function compiles the provided type definition to a module, evaluates the module to get the specified export, and then reflects the export to get its Deepkit Type reflection.\n *\n * @param context - The context object containing the environment paths.\n * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.\n * @param options - Optional overrides for the ESBuild configuration.\n * @returns A promise that resolves to the Deepkit Type reflection.\n */\nexport async function resolveReflection<\n TContext extends PluginContext = PluginContext\n>(\n context: TContext,\n input: FileReference,\n options?: BundleOptions\n): Promise<Type> {\n return reflect(\n await resolve<Type>(\n context,\n input,\n defu(options, {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n level: \"all\"\n })\n ]\n })\n )\n );\n}\n","/* -------------------------------------------------------------------\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 { Context } from \"@powerlines/core\";\nimport { isFileReference } from \"@powerlines/core\";\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport {\n isType,\n reflect,\n stringifyType,\n Type\n} from \"@powerlines/deepkit/vendor/type\";\nimport { StandardJSONSchemaV1 } from \"@standard-schema/spec\";\nimport { extractFileReference } from \"@stryke/convert/extract-file-reference\";\nimport { murmurhash } from \"@stryke/hash\";\nimport { deepClone } from \"@stryke/helpers/deep-clone\";\nimport { isStandardJsonSchema } from \"@stryke/json\";\nimport { findFileExtensionSafe } from \"@stryke/path/find\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { list } from \"@stryke/string-format/list\";\nimport { isSetString } from \"@stryke/type-checks\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { FileReferenceInput } from \"@stryke/types\";\nimport {\n extractJsonSchema as extractJsonSchemaZod,\n isZod3Type\n} from \"@stryke/zod\";\nimport { toJsonSchema } from \"@valibot/to-json-schema\";\nimport defu from \"defu\";\nimport * as z3 from \"zod/v3\";\nimport { BundleOptions } from \"./bundle\";\nimport { VALID_SOURCE_FILE_EXTENSIONS } from \"./constants\";\nimport { getCacheDirectory, writeSchema } from \"./persistence\";\nimport { reflectionToJsonSchema } from \"./reflection\";\nimport { resolve } from \"./resolve\";\nimport {\n isJsonSchema,\n isJsonSchemaObject,\n isSchema,\n isSchemaWithSource,\n isUntypedInput,\n isUntypedInputStrict,\n isUntypedSchema,\n isUntypedSchemaStrict,\n isValibotSchema\n} from \"./type-checks\";\nimport {\n ExtractedSchema,\n JsonSchema,\n Schema,\n SchemaInput,\n SchemaInputVariant,\n SchemaSource,\n SchemaSourceInput,\n SchemaSourceVariant,\n UntypedInputObject,\n UntypedSchema,\n ValibotSchema\n} from \"./types\";\n\nconst SCHEMA_BUNDLE_BASE_URI = \"https://powerlines.invalid/\";\n\nfunction normalizeUri(uri: string): string {\n return uri.endsWith(\"#\") ? uri.slice(0, -1) : uri;\n}\n\nfunction stripUriFragment(uri: string): string {\n const hashIndex = uri.indexOf(\"#\");\n\n return hashIndex >= 0 ? uri.slice(0, hashIndex) : uri;\n}\n\nfunction escapeJsonPointerToken(token: string): string {\n return token.replaceAll(\"~\", \"~0\").replaceAll(\"/\", \"~1\");\n}\n\nfunction toJsonPointer(path: string[]): string {\n if (path.length === 0) {\n return \"\";\n }\n\n return `/${path.map(segment => escapeJsonPointerToken(segment)).join(\"/\")}`;\n}\n\nfunction resolveUri(reference: string, baseUri: string): string {\n try {\n return normalizeUri(new URL(reference, baseUri).toString());\n } catch {\n return normalizeUri(reference);\n }\n}\n\nfunction collectReferenceTargets(\n value: unknown,\n path: string[],\n baseUri: string,\n uriToPointer: Map<string, string>,\n dynamicUriToFragment: Map<string, string>\n): void {\n if (!isSetObject(value)) {\n return;\n }\n\n const schema = value as Record<string, unknown>;\n const pointer = toJsonPointer(path);\n\n const currentBaseUri = isSetString(schema.$id)\n ? resolveUri(schema.$id, baseUri)\n : baseUri;\n\n const currentDocumentUri = stripUriFragment(currentBaseUri);\n\n uriToPointer.set(currentBaseUri, pointer);\n uriToPointer.set(currentDocumentUri, pointer);\n\n if (isSetString(schema.$anchor)) {\n uriToPointer.set(`${currentDocumentUri}#${schema.$anchor}`, pointer);\n }\n\n if (isSetString(schema.$dynamicAnchor)) {\n const dynamicTarget = `${currentDocumentUri}#${schema.$dynamicAnchor}`;\n uriToPointer.set(dynamicTarget, pointer);\n dynamicUriToFragment.set(dynamicTarget, `#${schema.$dynamicAnchor}`);\n }\n\n for (const [key, child] of Object.entries(schema)) {\n if (Array.isArray(child)) {\n child.forEach((entry, index) => {\n collectReferenceTargets(\n entry,\n [...path, key, String(index)],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n });\n continue;\n }\n\n collectReferenceTargets(\n child,\n [...path, key],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n }\n}\n\nfunction rewriteReferenceTargets(\n value: unknown,\n path: string[],\n baseUri: string,\n uriToPointer: Map<string, string>,\n dynamicUriToFragment: Map<string, string>\n): void {\n if (!isSetObject(value)) {\n return;\n }\n\n const schema = value as Record<string, unknown>;\n\n const currentBaseUri = isSetString(schema.$id)\n ? resolveUri(schema.$id, baseUri)\n : baseUri;\n\n if (isSetString(schema.$ref)) {\n const resolvedRefUri = resolveUri(schema.$ref, currentBaseUri);\n const pointer =\n uriToPointer.get(resolvedRefUri) ??\n uriToPointer.get(stripUriFragment(resolvedRefUri));\n\n if (pointer !== undefined) {\n schema.$ref = pointer.length > 0 ? `#${pointer}` : \"#\";\n }\n }\n\n if (isSetString(schema.$dynamicRef)) {\n const resolvedDynamicRefUri = resolveUri(\n schema.$dynamicRef,\n currentBaseUri\n );\n const dynamicFragment = dynamicUriToFragment.get(resolvedDynamicRefUri);\n\n if (dynamicFragment) {\n schema.$dynamicRef = dynamicFragment;\n } else {\n const pointer =\n uriToPointer.get(resolvedDynamicRefUri) ??\n uriToPointer.get(stripUriFragment(resolvedDynamicRefUri));\n\n if (pointer !== undefined) {\n schema.$dynamicRef = pointer.length > 0 ? `#${pointer}` : \"#\";\n }\n }\n }\n\n for (const [key, child] of Object.entries(schema)) {\n if (Array.isArray(child)) {\n child.forEach((entry, index) => {\n rewriteReferenceTargets(\n entry,\n [...path, key, String(index)],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n });\n continue;\n }\n\n rewriteReferenceTargets(\n child,\n [...path, key],\n currentBaseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n }\n}\n\n/**\n * Bundles all external references in a JSON Schema into a single schema document by collecting all reference targets and rewriting the references to point to the bundled definitions. This ensures that the resulting schema is self-contained and can be used independently without relying on external documents.\n *\n * @param schema - The JSON Schema to bundle references for.\n * @returns A new JSON Schema with all references bundled and rewritten to point to the bundled definitions.\n */\nexport function bundleReferences(schema: JsonSchema): JsonSchema {\n if (!isSetObject(schema)) {\n return schema;\n }\n\n const bundledSchema = deepClone(schema) as Record<string, unknown>;\n const baseUri = isSetString(bundledSchema.$id)\n ? resolveUri(bundledSchema.$id, SCHEMA_BUNDLE_BASE_URI)\n : SCHEMA_BUNDLE_BASE_URI;\n\n const uriToPointer = new Map<string, string>();\n const dynamicUriToFragment = new Map<string, string>();\n\n collectReferenceTargets(\n bundledSchema,\n [],\n baseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n\n rewriteReferenceTargets(\n bundledSchema,\n [],\n baseUri,\n uriToPointer,\n dynamicUriToFragment\n );\n\n return bundledSchema;\n}\n\nfunction convertNestedUntypedSchema(value: unknown): unknown {\n if (isUntypedSchema(value)) {\n return convertUntypedSchemaToJsonSchema(value);\n }\n\n if (isSetObject(value)) {\n if (isUntypedInput(value)) {\n return convertUntypedInputToJsonSchema(value);\n }\n\n const nested = value as Record<string, unknown>;\n if (\"$schema\" in nested && isUntypedSchema(nested.$schema)) {\n return convertUntypedSchemaToJsonSchema(nested.$schema);\n }\n }\n\n return value;\n}\n\nfunction convertNestedUntypedSchemaArray(value: unknown): unknown {\n if (!Array.isArray(value)) {\n return value;\n }\n\n return value.map(item => convertNestedUntypedSchema(item));\n}\n\nfunction convertValibotSchemaToJsonSchema(schema: unknown): JsonSchema {\n return toJsonSchema(schema as never, {\n target: \"draft-2020-12\"\n }) as JsonSchema;\n}\n\nfunction convertUntypedSchemaToJsonSchema(\n schema: UntypedSchema | Record<string, unknown>\n): JsonSchema {\n const source = schema as Record<string, unknown>;\n const jsonSchema: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(source)) {\n if (\n key === \"tsType\" ||\n key === \"markdownType\" ||\n key === \"tags\" ||\n key === \"args\" ||\n key === \"resolve\"\n ) {\n continue;\n }\n\n if (key === \"id\" && isSetString(value)) {\n jsonSchema.$id = value;\n continue;\n }\n\n if (\n key === \"properties\" ||\n key === \"patternProperties\" ||\n key === \"dependentSchemas\" ||\n key === \"$defs\" ||\n key === \"definitions\"\n ) {\n if (!isSetObject(value)) {\n jsonSchema[key] = value;\n continue;\n }\n\n jsonSchema[key] = Object.fromEntries(\n Object.entries(value).map(([propertyKey, propertyValue]) => [\n propertyKey,\n convertNestedUntypedSchema(propertyValue)\n ])\n );\n continue;\n }\n\n if (\n key === \"items\" ||\n key === \"contains\" ||\n key === \"if\" ||\n key === \"then\" ||\n key === \"else\" ||\n key === \"not\" ||\n key === \"propertyNames\" ||\n key === \"additionalProperties\" ||\n key === \"unevaluatedProperties\"\n ) {\n jsonSchema[key] = convertNestedUntypedSchema(value);\n continue;\n }\n\n if (key === \"oneOf\" || key === \"anyOf\" || key === \"allOf\") {\n jsonSchema[key] = convertNestedUntypedSchemaArray(value);\n continue;\n }\n\n jsonSchema[key] = value;\n }\n\n return jsonSchema;\n}\n\nfunction convertUntypedInputToJsonSchema(\n input: UntypedInputObject\n): JsonSchema {\n const inputObject = input as Record<string, unknown>;\n const base = isUntypedSchema(inputObject.$schema)\n ? convertUntypedSchemaToJsonSchema(inputObject.$schema)\n : {};\n const properties: Record<string, JsonSchema> = {};\n\n for (const [key, value] of Object.entries(inputObject)) {\n if (key.startsWith(\"$\")) {\n continue;\n }\n\n if (!isSetObject(value)) {\n continue;\n }\n\n if (isUntypedInput(value)) {\n properties[key] = convertUntypedInputToJsonSchema(value);\n continue;\n }\n\n const nested = value as Record<string, unknown>;\n if (\"$schema\" in nested && isUntypedSchema(nested.$schema)) {\n properties[key] = convertUntypedSchemaToJsonSchema(nested.$schema);\n continue;\n }\n\n if (isUntypedSchema(value)) {\n properties[key] = convertUntypedSchemaToJsonSchema(value);\n }\n }\n\n if (!isJsonSchemaObject(base)) {\n throw new Error(\n `Failed to convert untyped input to JSON Schema. The base schema must be a valid JSON Schema object.`\n );\n }\n\n const baseProperties = isSetObject(base.properties) ? base.properties : {};\n const mergedProperties = {\n ...baseProperties,\n ...properties\n };\n\n return {\n ...base,\n type: base.type ?? \"object\",\n ...(Object.keys(mergedProperties).length > 0\n ? { properties: mergedProperties }\n : {})\n };\n}\n\n/**\n * Creates a hash string for a given schema definition input.\n */\nexport function extractHash(\n variant: SchemaInputVariant,\n input: SchemaInput\n): string {\n if (isSetString(input)) {\n return murmurhash({ variant, input });\n } else if (typeof input === \"boolean\") {\n return murmurhash({ variant, input });\n } else if (isSetObject(input)) {\n if (isZod3Type(input)) {\n return murmurhash({ variant, input: input._def });\n } else if (isType(input)) {\n return murmurhash({ variant, input: stringifyType(input) });\n } else if (isStandardJsonSchema(input)) {\n return murmurhash({ variant, input: input[\"~standard\"] });\n } else if (isJsonSchema(input)) {\n return murmurhash({ variant, input });\n } else if (isValibotSchema(input)) {\n return murmurhash({\n variant,\n input: convertValibotSchemaToJsonSchema(input)\n });\n } else if (isUntypedInput(input)) {\n return murmurhash({\n variant,\n input: convertUntypedInputToJsonSchema(input)\n });\n } else if (isUntypedSchema(input)) {\n return murmurhash({\n variant,\n input: convertUntypedSchemaToJsonSchema(input)\n });\n }\n }\n\n throw new Error(\n `Failed to create an input hash for the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Converts a reflected Deepkit {@link Type} into a JSON Schema (draft-2020-12) representation.\n */\nexport function extractReflection(reflection: Type): JsonSchema | undefined {\n if (!isType(reflection)) {\n return undefined;\n }\n\n return reflectionToJsonSchema(reflection);\n}\n\n/**\n * Extracts a JSON Schema from Zod, Standard Schema, Valibot, untyped, or JSON Schema inputs.\n *\n * @param schema - The schema input to extract a JSON Schema from.\n * @returns The extracted JSON Schema, or `undefined` if the input is not a supported schema type.\n */\nexport function extractJsonSchema(schema: unknown): JsonSchema | undefined {\n if (isSetObject(schema)) {\n if (isZod3Type(schema)) {\n return extractJsonSchemaZod(schema, {\n target: \"draft-2020-12\"\n }) as JsonSchema;\n }\n if (isUntypedInputStrict(schema)) {\n return convertUntypedInputToJsonSchema(schema);\n }\n if (isUntypedSchemaStrict(schema)) {\n return convertUntypedSchemaToJsonSchema(schema);\n }\n if (isStandardJsonSchema(schema)) {\n return schema[\"~standard\"].jsonSchema.input({\n target: \"draft-2020-12\"\n });\n }\n if (isValibotSchema(schema)) {\n return convertValibotSchemaToJsonSchema(schema);\n }\n if (isJsonSchema(schema)) {\n return schema;\n }\n }\n\n return undefined;\n}\n\n/**\n * Resolves the concrete source variant for a schema source input.\n *\n * @param input - The schema source input to inspect.\n * @returns The resolved schema source variant.\n * @throws Will throw an error when the input cannot be mapped to a supported source variant.\n */\nexport function extractResolvedVariant(\n input: SchemaSourceInput\n): SchemaSourceVariant {\n if (isSetObject(input)) {\n if (isZod3Type(input)) {\n return \"zod3\";\n } else if (isType(input)) {\n return \"reflection\";\n } else if (isUntypedInputStrict(input) || isUntypedSchemaStrict(input)) {\n return \"untyped\";\n } else if (isStandardJsonSchema(input)) {\n return \"standard-schema\";\n } else if (isJsonSchema(input)) {\n return \"json-schema\";\n } else if (isValibotSchema(input)) {\n return \"valibot\";\n }\n }\n\n throw new Error(\n `Failed to determine the variant of the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, a reflected Deepkit Type object, or an Untyped schema.`\n );\n}\n\n/**\n * Determines the top-level input variant for schema extraction.\n *\n * @param input - The schema input to classify.\n * @returns The resolved schema input variant.\n */\nexport function extractVariant(input: SchemaInput): SchemaInputVariant {\n if (isSetString(input) || isFileReference(input)) {\n return \"file-reference\";\n }\n\n return extractResolvedVariant(input as SchemaSourceInput);\n}\n\n/**\n * Extracts and normalizes a JSON Schema from a concrete schema source input.\n *\n * @param input - The schema source input to extract from.\n * @param variant - Optional source variant override. When omitted, the variant is inferred from the input.\n * @returns A promise that resolves to a bundled JSON Schema.\n * @throws Will throw an error if no valid JSON Schema can be extracted from the input.\n */\nexport async function extractSchema(\n input: SchemaSourceInput,\n variant?: SchemaInputVariant\n): Promise<JsonSchema> {\n if (isSchemaWithSource(input)) {\n return input.schema;\n }\n\n const resolvedVariant = variant ?? extractResolvedVariant(input);\n\n let schema: JsonSchema | undefined;\n if (\n resolvedVariant === \"zod3\" ||\n resolvedVariant === \"json-schema\" ||\n resolvedVariant === \"standard-schema\" ||\n resolvedVariant === \"untyped\" ||\n resolvedVariant === \"valibot\"\n ) {\n schema = extractJsonSchema(input);\n } else if (resolvedVariant === \"reflection\") {\n schema = extractReflection(input as Type);\n }\n\n if (schema) {\n return bundleReferences(schema);\n }\n\n throw new Error(\n `Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, an untyped schema, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Builds source metadata for a schema input using a known source variant.\n *\n * @param variant - The schema source variant associated with the input.\n * @param input - The schema source input to wrap.\n * @returns The normalized schema source payload, including the source hash and variant.\n * @throws Will throw an error if the provided variant is unsupported.\n */\nexport function extractSource(\n variant: SchemaSourceVariant,\n input: SchemaSourceInput\n): SchemaSource {\n if (variant === \"zod3\") {\n return {\n hash: extractHash(variant, input),\n variant: \"zod3\",\n schema: input as z3.ZodTypeAny\n };\n } else if (variant === \"untyped\") {\n return {\n hash: extractHash(variant, input),\n variant: \"untyped\",\n schema: input as UntypedInputObject | UntypedSchema\n };\n } else if (variant === \"standard-schema\") {\n return {\n hash: extractHash(variant, input),\n variant: \"standard-schema\",\n schema: input as StandardJSONSchemaV1\n };\n } else if (variant === \"json-schema\") {\n return {\n hash: extractHash(variant, input),\n variant: \"json-schema\",\n schema: input as JsonSchema\n };\n } else if (variant === \"valibot\") {\n return {\n hash: extractHash(variant, input),\n variant: \"valibot\",\n schema: input as ValibotSchema\n };\n } else if (variant === \"reflection\") {\n return {\n hash: extractHash(variant, input),\n variant: \"reflection\",\n schema: input as Type\n };\n }\n\n throw new Error(\n `Failed to extract source information from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`\n );\n}\n\n/**\n * Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a Deepkit Type object. If the input is a type definition reference (e.g. a file path with an export), it will be resolved and bundled using Rolldown to obtain the actual schema definition before extraction.\n *\n * @example\n * ```ts\n * // Resolve a schema definition from a file path\n * const schema1 = await extract(context, \"./schemas.ts#MySchema\");\n * // Resolve a schema definition from a JSON Schema object\n * const schema2 = await extract(context, schemaObject);\n * // Resolve a schema definition from a Zod schema\n * const schema3 = await extract(context, zodSchema);\n * // Resolve a schema definition from a reflected Deepkit Type object\n * const schema4 = await extract(context, reflectionType);\n * ```\n *\n * @see https://zod.dev/\n * @see https://valibot.dev/\n * @see https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec\n * @see https://json-schema.org/\n * @see https://ajv.js.org/json-type-definition.html\n * @see https://deepkit.io/en/documentation/runtime-types/reflection\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param input - The schema definition input to extract, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a reflected Deepkit Type object. If the input is a string or a type definition reference, it will be resolved and bundled to obtain the actual schema definition before extraction.\n * @param options - Optional overrides for the Rolldown configuration used during extraction. This can include custom plugins, loaders, or other build options to control how the schema definition is resolved and bundled when the input is a type definition reference.\n * @returns A promise that resolves to the extracted and normalized schema as a JSON Schema object. The function will attempt to extract a valid JSON Schema from the provided input, and if successful, it will return the schema. If the extraction process fails or if the input is not a valid schema definition, it will throw an error indicating the failure.\n */\nexport async function extractSchemaWithSource(\n context: Context,\n input: SchemaInput,\n options: BundleOptions = {}\n): Promise<ExtractedSchema> {\n if (isSchemaWithSource(input)) {\n return input;\n }\n\n if (isSchema(input)) {\n return {\n ...input,\n source: {\n hash: extractHash(\"json-schema\", input.schema),\n variant: \"json-schema\",\n schema: input.schema\n }\n };\n }\n\n let source: SchemaSource;\n\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n\n if (variant === \"file-reference\") {\n const fileReference = extractFileReference(input as FileReferenceInput);\n if (!fileReference) {\n throw new Error(\n `Failed to extract a valid file reference from the provided input \"${JSON.stringify(\n input\n )}\". Please ensure that the input is correctly formatted as a file reference (e.g. \"./schema.ts#MySchema\") and that the file exists at the specified path.`\n );\n }\n\n const extension = findFileExtensionSafe(fileReference.file);\n if (extension && !VALID_SOURCE_FILE_EXTENSIONS.includes(extension)) {\n throw new Error(\n `The provided schema file input \"${\n fileReference.file\n }\" has an invalid file extension (.${\n extension\n }). Please ensure that the file has one of the following extensions: ${list(\n VALID_SOURCE_FILE_EXTENSIONS,\n { conjunction: \"or\" }\n )}.`\n );\n }\n\n let resolved = await resolve<SchemaSourceInput>(\n context,\n input as FileReferenceInput,\n defu(options, {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n level: \"all\"\n })\n ]\n })\n );\n\n try {\n const type = reflect(resolved);\n if (isType(type)) {\n resolved = type;\n }\n } catch {\n // If reflection fails, we assume the resolved output is not a reflected type and proceed with it as-is.\n }\n\n source = extractSource(extractResolvedVariant(resolved), resolved);\n } else if (\n [\n \"json-schema\",\n \"standard-schema\",\n \"zod3\",\n \"untyped\",\n \"valibot\",\n \"reflection\"\n ].includes(variant)\n ) {\n source = extractSource(variant, input as SchemaSourceInput);\n } else {\n throw new Error(\n `Invalid schema definition input \"${\n variant\n }\". The variant must be one of \"file-reference\", \"json-schema\", \"standard-schema\", \"zod3\", \"valibot\", \"untyped\", or \"reflection\".`\n );\n }\n\n return {\n variant,\n source,\n schema: await extractSchema(source.schema, source.variant),\n hash\n };\n}\n\n/**\n * Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a Deepkit Type object. If the input is a type definition reference (e.g. a file path with an export), it will be resolved and bundled using Rolldown to obtain the actual schema definition before extraction.\n *\n * @example\n * ```ts\n * // Resolve a schema definition from a file path\n * const schema1 = await extract(context, \"./schemas.ts#MySchema\");\n * // Resolve a schema definition from a JSON Schema object\n * const schema2 = await extract(context, schemaObject);\n * // Resolve a schema definition from a Zod schema\n * const schema3 = await extract(context, zodSchema);\n * // Resolve a schema definition from a Valibot schema\n * const schema4 = await extract(context, valibotSchema);\n * // Resolve a schema definition from a reflected Deepkit Type object\n * const schema5 = await extract(context, reflectionType);\n * ```\n *\n * @see https://zod.dev/\n * @see https://valibot.dev/\n * @see https://standardschema.dev/json-schema#what-schema-libraries-support-this-spec\n * @see https://json-schema.org/\n * @see https://ajv.js.org/json-type-definition.html\n * @see https://deepkit.io/en/documentation/runtime-types/reflection\n * @see https://github.com/unjs/untyped\n * @see https://www.typescriptlang.org/docs/handbook/2/types-from-types.html\n *\n * @param context - The context object providing access to the file system and cache path.\n * @param input - The schema definition input to extract, which can be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a reflected Deepkit Type object.\n * @param options - Optional overrides for the Rolldown configuration used during extraction.\n * @returns A promise that resolves to the extracted and normalized schema as a JSON Schema object.\n * @throws Will throw an error if the input is not a valid schema definition or if the extraction process fails to produce a valid schema.\n */\nexport async function extract(\n context: Context,\n input: SchemaInput,\n options: BundleOptions = {}\n): Promise<Schema> {\n if (isSchemaWithSource(input) || isSchema(input)) {\n return input;\n }\n\n let result: Schema | undefined;\n\n const variant = extractVariant(input);\n const hash = extractHash(variant, input);\n\n const cacheFilePath = joinPaths(getCacheDirectory(context), `${hash}.json`);\n if (\n context.config.skipCache !== true &&\n context.fs.existsSync(cacheFilePath)\n ) {\n const schema = await context.fs.read(cacheFilePath);\n if (schema) {\n result = {\n variant,\n hash,\n schema: JSON.parse(schema) as JsonSchema\n };\n }\n }\n\n result ??= await extractSchemaWithSource(context, input, options);\n if (!result?.schema) {\n throw new Error(\n `Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Valibot schema, any Standard JSON Schema type, a plain JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`\n );\n }\n\n if (context.config.skipCache !== true) {\n await writeSchema(context, result);\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,eAAsB,OACpB,SACA,MACA,UAAyB,CAAC,GACL;CACrB,MAAM,OAAO,MAAM,QAAQ,GAAG,QAAQ,IAAI;CA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