@powerlines/schema 0.11.26 → 0.11.27

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.
Files changed (57) hide show
  1. package/dist/bundle.mjs.map +1 -1
  2. package/dist/codegen.cjs +49 -6
  3. package/dist/codegen.d.cts +21 -3
  4. package/dist/codegen.d.cts.map +1 -1
  5. package/dist/codegen.d.mts +21 -3
  6. package/dist/codegen.d.mts.map +1 -1
  7. package/dist/codegen.mjs +44 -3
  8. package/dist/codegen.mjs.map +1 -1
  9. package/dist/constants.cjs +19 -0
  10. package/dist/constants.d.cts +17 -0
  11. package/dist/constants.d.cts.map +1 -0
  12. package/dist/constants.d.mts +17 -0
  13. package/dist/constants.d.mts.map +1 -0
  14. package/dist/constants.mjs +18 -0
  15. package/dist/constants.mjs.map +1 -0
  16. package/dist/extract.cjs +23 -4
  17. package/dist/extract.d.cts.map +1 -1
  18. package/dist/extract.d.mts.map +1 -1
  19. package/dist/extract.mjs +23 -4
  20. package/dist/extract.mjs.map +1 -1
  21. package/dist/helpers.cjs +94 -0
  22. package/dist/helpers.d.cts +44 -0
  23. package/dist/helpers.d.cts.map +1 -0
  24. package/dist/helpers.d.mts +44 -0
  25. package/dist/helpers.d.mts.map +1 -0
  26. package/dist/helpers.mjs +90 -0
  27. package/dist/helpers.mjs.map +1 -0
  28. package/dist/index.cjs +19 -2
  29. package/dist/index.d.cts +7 -4
  30. package/dist/index.d.mts +7 -4
  31. package/dist/index.mjs +6 -3
  32. package/dist/jtd.mjs.map +1 -1
  33. package/dist/persistence.cjs +76 -0
  34. package/dist/persistence.d.cts +47 -0
  35. package/dist/persistence.d.cts.map +1 -0
  36. package/dist/persistence.d.mts +47 -0
  37. package/dist/persistence.d.mts.map +1 -0
  38. package/dist/persistence.mjs +71 -0
  39. package/dist/persistence.mjs.map +1 -0
  40. package/dist/reflection.cjs +13 -6
  41. package/dist/reflection.d.cts.map +1 -1
  42. package/dist/reflection.d.mts.map +1 -1
  43. package/dist/reflection.mjs +12 -6
  44. package/dist/reflection.mjs.map +1 -1
  45. package/dist/resolve.mjs.map +1 -1
  46. package/dist/type-checks.cjs +21 -2
  47. package/dist/type-checks.d.cts +16 -2
  48. package/dist/type-checks.d.cts.map +1 -1
  49. package/dist/type-checks.d.mts +16 -2
  50. package/dist/type-checks.d.mts.map +1 -1
  51. package/dist/type-checks.mjs +21 -4
  52. package/dist/type-checks.mjs.map +1 -1
  53. package/dist/types.d.cts +42 -12
  54. package/dist/types.d.cts.map +1 -1
  55. package/dist/types.d.mts +42 -12
  56. package/dist/types.d.mts.map +1 -1
  57. package/package.json +19 -7
@@ -1 +1 @@
1
- {"version":3,"file":"reflection.mjs","names":[],"sources":["../src/reflection.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 {\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 { isSetArray, isSetObject, isSetString } from \"@stryke/type-checks\";\nimport { JTDSchemaType, SchemaMetadata } from \"./types\";\n\n/**\n * Maps a Deepkit numeric `brand` to the JTD numeric `type` keyword that best preserves the underlying width and signedness.\n *\n * @param brand - The Deepkit `TypeNumberBrand` of a numeric reflection, or `undefined` when no brand is set.\n * @returns The JTD numeric `type` keyword to use.\n */\nfunction numberBrandToJtdType(\n brand: TypeNumberBrand | undefined\n):\n | \"int8\"\n | \"uint8\"\n | \"int16\"\n | \"uint16\"\n | \"int32\"\n | \"uint32\"\n | \"float32\"\n | \"float64\" {\n switch (brand) {\n case TypeNumberBrand.integer:\n return \"int32\";\n case TypeNumberBrand.int8:\n return \"int8\";\n case TypeNumberBrand.uint8:\n return \"uint8\";\n case TypeNumberBrand.int16:\n return \"int16\";\n case TypeNumberBrand.uint16:\n return \"uint16\";\n case TypeNumberBrand.int32:\n return \"int32\";\n case TypeNumberBrand.uint32:\n return \"uint32\";\n case TypeNumberBrand.float:\n case TypeNumberBrand.float32:\n return \"float32\";\n case TypeNumberBrand.float64:\n return \"float64\";\n case undefined:\n default:\n return \"float64\";\n }\n}\n\n/**\n * Converts a Deepkit type reflection into a JSON Type Definition (RFC 8927) form suitable for AJV's JTD validator.\n *\n * @remarks\n * Some TypeScript constructs have no direct JTD equivalent and are handled with the closest available form:\n *\n * - `null` and `undefined` become the empty JTD form with `nullable: true`.\n * - Unions of primitives that cannot be expressed as a JTD enum collapse to the empty form (which validates any value).\n * - String/number/bigint literal unions are emitted as a JTD enum (non-string members are stringified, as JTD requires string enum members).\n * - Tuples are emitted as a JTD elements form whose element schema is the single tuple member type, or the empty schema for mixed tuples.\n * - `Date` is emitted as `{ type: \"timestamp\" }`.\n * - Discriminated unions of object literals (a shared string-literal tag property) are emitted as a JTD discriminator form.\n *\n * @param reflection - The Deepkit type reflection to convert.\n * @returns The corresponding JTD form, or `undefined` if the type cannot be represented.\n */\nexport function reflectionToJsonSchema<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(reflection: Type): JTDSchemaType<TMetadata> | undefined {\n const result = reflectionToJtd<TMetadata>(reflection);\n\n return result;\n}\n\n/**\n * Internal worker that performs the recursive Deepkit reflection → JTD conversion.\n *\n * @param reflection - The Deepkit type reflection to convert.\n * @returns The corresponding JTD form, or `undefined` if the type cannot be represented.\n */\nfunction reflectionToJtd<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(reflection: Type): JTDSchemaType<TMetadata> | undefined {\n const schema = {} as JTDSchemaType<TMetadata>;\n\n if (isSetObject((reflection as { tags?: TagsReflection })?.tags)) {\n const tags = (reflection as { tags: TagsReflection }).tags;\n\n schema.metadata = (schema.metadata ?? {}) as TMetadata;\n if (tags.readonly === true) {\n schema.metadata.isReadonly = true;\n }\n if (tags.ignore === true) {\n schema.metadata.isIgnored = true;\n }\n if (tags.internal === true) {\n schema.metadata.isInternal = true;\n }\n if (tags.runtime === true) {\n schema.metadata.isRuntime = true;\n }\n if (tags.hidden === true) {\n schema.metadata.isHidden = true;\n }\n if (isSetArray(tags.alias)) {\n schema.metadata.alias = tags.alias;\n }\n if (isSetString(tags.title)) {\n schema.metadata.title = tags.title;\n }\n }\n\n switch (reflection.kind) {\n case ReflectionKind.any:\n case ReflectionKind.unknown:\n case ReflectionKind.void:\n case ReflectionKind.object:\n return {};\n case ReflectionKind.never:\n return undefined;\n case ReflectionKind.undefined:\n case ReflectionKind.null:\n return { nullable: true };\n case ReflectionKind.string:\n return { ...schema, type: \"string\" };\n case ReflectionKind.boolean:\n return { ...schema, type: \"boolean\" };\n case ReflectionKind.number:\n return {\n ...schema,\n type: numberBrandToJtdType(reflection.brand)\n };\n case ReflectionKind.bigint:\n // JTD has no native 64-bit integer type — float64 is the widest numeric form.\n return { ...schema, type: \"float64\" };\n case ReflectionKind.regexp:\n return { ...schema, type: \"string\" };\n case ReflectionKind.literal: {\n const { literal } = reflection;\n if (typeof literal === \"string\") {\n return { ...schema, enum: [literal] };\n }\n\n if (typeof literal === \"number\" || typeof literal === \"bigint\") {\n return {\n ...schema,\n enum: [String(literal)]\n };\n }\n\n if (typeof literal === \"boolean\") {\n // JTD has no boolean literal — emit the type form.\n return { ...schema, type: \"boolean\" };\n }\n\n if (literal instanceof RegExp) {\n return { ...schema, type: \"string\" };\n }\n\n return schema;\n }\n case ReflectionKind.templateLiteral:\n return { ...schema, type: \"string\" };\n case ReflectionKind.enum: {\n const values = reflection.values\n .filter(\n (value): value is string | number =>\n typeof value === \"string\" || typeof value === \"number\"\n )\n .map(value => String(value));\n\n const unique = Array.from(new Set(values));\n if (unique.length === 0) {\n return schema;\n }\n\n return { ...schema, enum: unique };\n }\n case ReflectionKind.array: {\n const items = reflectionToJtd<TMetadata>(reflection.type);\n\n return { ...schema, elements: items ?? {} };\n }\n case ReflectionKind.tuple: {\n const items = reflection.types\n .map(member => reflectionToJtd<TMetadata>(member.type))\n .filter((item): item is JTDSchemaType<TMetadata> => item !== undefined);\n if (items.length === 0) {\n return { ...schema, elements: {} };\n }\n\n if (items.length === 1) {\n return { ...schema, elements: items[0]! };\n }\n\n // JTD has no tuple form — accept any element shape.\n return { ...schema, elements: {} };\n }\n case ReflectionKind.union: {\n const branches = reflection.types\n .map(inner => reflectionToJtd<TMetadata>(inner))\n .filter((item): item is JTDSchemaType<TMetadata> => item !== undefined);\n\n const nullable = reflection.types.some(\n inner =>\n inner.kind === ReflectionKind.null ||\n inner.kind === ReflectionKind.undefined\n );\n const nonNull = branches.filter(b => !isPureNullable(b));\n\n if (nonNull.length === 0) {\n return { ...schema, nullable: true };\n }\n\n if (nonNull.length === 1) {\n const only = nonNull[0]!;\n if (nullable) {\n (only as { nullable?: boolean }).nullable = true;\n }\n\n return { ...schema, ...only };\n }\n\n // String-enum union: combine all enum branches into one JTD enum.\n if (nonNull.every(isEnumForm)) {\n const merged = Array.from(\n new Set(nonNull.flatMap(b => (b as { enum: string[] }).enum))\n );\n const form: JTDSchemaType<TMetadata> = { ...schema, enum: merged };\n\n if (nullable) {\n (form as { nullable?: boolean }).nullable = true;\n }\n\n return { ...schema, ...form };\n }\n\n // Discriminated union of object literals: detect a shared string-literal tag.\n const discriminator = tryReflectionDiscriminator<TMetadata>(\n reflection.types\n );\n if (discriminator) {\n if (nullable) {\n (discriminator as { nullable?: boolean }).nullable = true;\n }\n\n return { ...schema, ...discriminator };\n }\n\n // Fallback — JTD has no general union; allow any value.\n const fallback: JTDSchemaType<TMetadata> = {};\n if (nullable) {\n (fallback as { nullable?: boolean }).nullable = true;\n }\n\n return { ...schema, ...fallback };\n }\n case ReflectionKind.intersection: {\n const members = reflection.types\n .map(inner => reflectionToJtd<TMetadata>(inner))\n .filter(\n (item): item is JTDSchemaType<TMetadata> | undefined =>\n item !== undefined\n );\n if (members.length === 0) {\n return undefined as JTDSchemaType<TMetadata> | undefined;\n }\n\n if (members.length === 1) {\n return { ...schema, ...members[0] };\n }\n\n if (\n members.every(member => member && isPropertiesForm<TMetadata>(member))\n ) {\n return mergePropertiesForms<TMetadata>(\n members as JTDSchemaType<TMetadata>[]\n );\n }\n\n return { ...schema, ...members[0] };\n }\n case ReflectionKind.promise:\n return reflectionToJtd<TMetadata>(reflection.type);\n case ReflectionKind.objectLiteral:\n return objectReflectionToJtd<TMetadata>(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 { ...schema, type: \"timestamp\" };\n case \"RegExp\":\n return { ...schema, type: \"string\" };\n case \"URL\":\n return { ...schema, type: \"string\" };\n case \"Set\": {\n const itemType = reflection.arguments?.[0];\n const items = itemType\n ? reflectionToJtd<TMetadata>(itemType)\n : undefined;\n\n return { ...schema, elements: items ?? {} };\n }\n case \"Map\": {\n const valueType = reflection.arguments?.[1];\n const values = valueType\n ? reflectionToJtd<TMetadata>(valueType)\n : undefined;\n\n return { ...schema, values: values ?? {} };\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 // Base64-encoded binary payload — represented as a plain string in JTD.\n return { ...schema, type: \"string\" };\n case undefined:\n default:\n return objectReflectionToJtd<TMetadata>(reflection);\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\n/**\n * Tests whether a JTD form is an enum form.\n *\n * @param form - The JTD form to inspect.\n * @returns `true` if the form is a JTD enum form.\n */\nfunction isEnumForm<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(\n form: JTDSchemaType<TMetadata>\n): form is { enum: string[]; nullable?: boolean; metadata?: TMetadata } {\n return Array.isArray((form as { enum?: unknown[] }).enum);\n}\n\n/**\n * Tests whether a JTD form is a properties form (object).\n *\n * @param form - The JTD form to inspect.\n * @returns `true` if the form is a JTD properties form.\n */\nfunction isPropertiesForm<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(\n form: JTDSchemaType<TMetadata>\n): form is {\n properties: Record<string, JTDSchemaType<TMetadata>>;\n optionalProperties?: Record<string, JTDSchemaType<TMetadata>>;\n nullable?: boolean;\n metadata?: TMetadata;\n} {\n return (\n \"properties\" in (form as object) || \"optionalProperties\" in (form as object)\n );\n}\n\n/**\n * Tests whether a JTD form is the empty `{ nullable: true }` placeholder.\n *\n * @param form - The JTD form to inspect.\n * @returns `true` if the form has no shape constraints beyond `nullable`.\n */\nfunction isPureNullable<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(form: JTDSchemaType<TMetadata>): boolean {\n const keys = Object.keys(form as object).filter(\n k => k !== \"nullable\" && k !== \"metadata\"\n );\n\n return (\n keys.length === 0 && (form as { nullable?: boolean }).nullable === true\n );\n}\n\n/**\n * Shallow-merges two JTD properties forms, unioning their `properties` and `optionalProperties` maps.\n *\n * @param forms - The JTD properties forms to merge.\n * @returns The merged JTD properties form.\n */\nfunction mergePropertiesForms<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(forms: JTDSchemaType<TMetadata>[]): JTDSchemaType<TMetadata> {\n const merged: {\n properties: Record<string, JTDSchemaType<TMetadata>>;\n optionalProperties: Record<string, JTDSchemaType<TMetadata>>;\n additionalProperties?: boolean;\n } = {\n properties: {},\n optionalProperties: {}\n };\n\n for (const form of forms) {\n const p = (\n form as { properties?: Record<string, JTDSchemaType<TMetadata>> }\n ).properties;\n const o = (\n form as { optionalProperties?: Record<string, JTDSchemaType<TMetadata>> }\n ).optionalProperties;\n if (p) {\n Object.assign(merged.properties, p);\n }\n if (o) {\n Object.assign(merged.optionalProperties, o);\n }\n if ((form as { additionalProperties?: boolean }).additionalProperties) {\n merged.additionalProperties = true;\n }\n }\n\n const hasProperties = Object.keys(merged.properties).length > 0;\n const hasOptional = Object.keys(merged.optionalProperties).length > 0;\n const result: JTDSchemaType<TMetadata> = {};\n\n if (hasProperties) {\n (\n result as { properties: Record<string, JTDSchemaType<TMetadata>> }\n ).properties = merged.properties;\n } else if (!hasOptional) {\n (\n result as { properties: Record<string, JTDSchemaType<TMetadata>> }\n ).properties = {};\n }\n\n if (hasOptional) {\n (\n result as { optionalProperties: Record<string, JTDSchemaType<TMetadata>> }\n ).optionalProperties = merged.optionalProperties;\n }\n\n if (merged.additionalProperties) {\n (result as { additionalProperties: boolean }).additionalProperties = true;\n }\n\n return result;\n}\n\n/**\n * Detects whether a Deepkit union represents a tagged union and, when so, emits the corresponding JTD discriminator form.\n *\n * @param types - The Deepkit reflection types that make up the union branches.\n * @returns A JTD discriminator form if every non-null branch is an object literal that shares a string-literal tag property, otherwise `undefined`.\n */\nfunction tryReflectionDiscriminator<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(types: readonly Type[]): JTDSchemaType<TMetadata> | 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 mapping: Record<string, JTDSchemaType<TMetadata>> = {};\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 // Build the branch body excluding the discriminator property.\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 = objectReflectionToJtd<TMetadata>(filteredBranch);\n if (!body || !isPropertiesForm<TMetadata>(body)) {\n return undefined;\n }\n\n mapping[first.literal] = body;\n }\n\n if (!tagKey) {\n return undefined;\n }\n\n return { discriminator: tagKey, mapping };\n}\n\n/**\n * Internal worker that produces a JTD properties form (or `values` form for index signatures alone) from a Deepkit object-like type.\n *\n * @param type - The class or object literal type whose members should be serialized.\n * @returns A JTD properties or values form describing the type's members.\n */\nfunction objectReflectionToJtd<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(type: TypeObjectLiteral | TypeClass): JTDSchemaType<TMetadata> {\n const reflection = ReflectionClass.from(type);\n\n const schema = {} as {\n properties?: Record<string, JTDSchemaType<TMetadata>>;\n optionalProperties?: Record<string, JTDSchemaType<TMetadata>>;\n additionalProperties?: boolean;\n metadata?: TMetadata;\n };\n\n schema.metadata = (schema.metadata ?? {}) as TMetadata;\n schema.metadata.isReadonly = reflection.isReadonly();\n schema.metadata.isIgnored = reflection.isIgnored();\n schema.metadata.isInternal = reflection.isInternal();\n schema.metadata.isRuntime = reflection.isRuntime();\n schema.metadata.isHidden = reflection.isHidden();\n\n if (isSetString(reflection.databaseSchemaName)) {\n schema.metadata.table = reflection.databaseSchemaName;\n }\n if (isSetString(reflection.getDescription())) {\n schema.metadata.description = reflection.getDescription();\n }\n if (isSetArray(reflection.getAlias())) {\n schema.metadata.alias = reflection.getAlias();\n }\n if (isSetString(reflection.getTitle())) {\n schema.metadata.title = reflection.getTitle();\n }\n\n const properties: Record<string, JTDSchemaType<TMetadata>> = {};\n const optionalProperties: Record<string, JTDSchemaType<TMetadata>> = {};\n\n for (const propertyReflection of reflection.getProperties()) {\n if (propertyReflection.getKind() === ReflectionKind.indexSignature) {\n const valueSchema = reflectionToJtd<TMetadata>(propertyReflection.type);\n if (valueSchema) {\n return {\n ...schema,\n values: valueSchema,\n additionalProperties: true\n };\n }\n } else {\n const property = reflectionToJtd<TMetadata>(propertyReflection.type);\n if (!property) {\n continue;\n }\n\n property.metadata = (property.metadata ?? {}) as TMetadata;\n property.metadata.isReadonly = propertyReflection.isReadonly();\n property.metadata.isIgnored = propertyReflection.isIgnored();\n property.metadata.isInternal = propertyReflection.isInternal();\n property.metadata.isRuntime = propertyReflection.isRuntime();\n property.metadata.isPrimaryKey = propertyReflection.isPrimaryKey();\n property.metadata.isHidden = propertyReflection.isHidden();\n\n if (propertyReflection.hasDefault()) {\n property.metadata.default = propertyReflection.getDefaultValue();\n }\n if (isSetString(propertyReflection.getDescription())) {\n property.metadata.description = propertyReflection.getDescription();\n }\n if (isSetArray(propertyReflection.getAlias())) {\n property.metadata.alias = propertyReflection.getAlias();\n }\n if (isSetString(propertyReflection.getTitle())) {\n property.metadata.title = propertyReflection.getTitle();\n }\n\n if (propertyReflection.isOptional()) {\n optionalProperties[propertyReflection.name] = property;\n } else {\n properties[propertyReflection.name] = property;\n }\n }\n }\n\n if (Object.keys(properties).length > 0) {\n schema.properties = properties;\n } else if (Object.keys(optionalProperties).length > 0) {\n schema.optionalProperties = optionalProperties;\n } else {\n schema.properties = {};\n }\n\n return schema;\n}\n"],"mappings":";;;;;;;;;;AAsCA,SAAS,qBACP,OASY;AACZ,SAAQ,OAAR;EACE,KAAK,gBAAgB,QACnB,QAAO;EACT,KAAK,gBAAgB,KACnB,QAAO;EACT,KAAK,gBAAgB,MACnB,QAAO;EACT,KAAK,gBAAgB,MACnB,QAAO;EACT,KAAK,gBAAgB,OACnB,QAAO;EACT,KAAK,gBAAgB,MACnB,QAAO;EACT,KAAK,gBAAgB,OACnB,QAAO;EACT,KAAK,gBAAgB;EACrB,KAAK,gBAAgB,QACnB,QAAO;EACT,KAAK,gBAAgB,QACnB,QAAO;EACT,KAAK;EACL,QACE,QAAO;;;;;;;;;;;;;;;;;;;AAoBb,SAAgB,uBAEd,YAAwD;AAGxD,QAFe,gBAA2B,WAE7B;;;;;;;;AASf,SAAS,gBAEP,YAAwD;CACxD,MAAM,SAAS,EAAE;AAEjB,KAAI,YAAa,YAA0C,KAAK,EAAE;EAChE,MAAM,OAAQ,WAAwC;AAEtD,SAAO,WAAY,OAAO,YAAY,EAAE;AACxC,MAAI,KAAK,aAAa,KACpB,QAAO,SAAS,aAAa;AAE/B,MAAI,KAAK,WAAW,KAClB,QAAO,SAAS,YAAY;AAE9B,MAAI,KAAK,aAAa,KACpB,QAAO,SAAS,aAAa;AAE/B,MAAI,KAAK,YAAY,KACnB,QAAO,SAAS,YAAY;AAE9B,MAAI,KAAK,WAAW,KAClB,QAAO,SAAS,WAAW;AAE7B,MAAI,WAAW,KAAK,MAAM,CACxB,QAAO,SAAS,QAAQ,KAAK;AAE/B,MAAI,YAAY,KAAK,MAAM,CACzB,QAAO,SAAS,QAAQ,KAAK;;AAIjC,SAAQ,WAAW,MAAnB;EACE,KAAK,eA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AAmB,UAAU,CAAC,CAC3C,UAAS,SAAS,QAAQ,mBAAmB,UAAU;AAEzD,MAAI,YAAY,mBAAmB,UAAU,CAAC,CAC5C,UAAS,SAAS,QAAQ,mBAAmB,UAAU;AAGzD,MAAI,mBAAmB,YAAY,CACjC,oBAAmB,mBAAmB,QAAQ;MAE9C,YAAW,mBAAmB,QAAQ;;AAK5C,KAAI,OAAO,KAAK,WAAW,CAAC,SAAS,EACnC,QAAO,aAAa;UACX,OAAO,KAAK,mBAAmB,CAAC,SAAS,EAClD,QAAO,qBAAqB;KAE5B,QAAO,aAAa,EAAE;AAGxB,QAAO"}
1
+ {"version":3,"file":"reflection.mjs","names":[],"sources":["../src/reflection.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 {\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 { isSetArray, isSetObject, isSetString } from \"@stryke/type-checks\";\nimport defu from \"defu\";\nimport { JTDSchemaType, SchemaMetadata } from \"./types\";\n\n/**\n * Maps a Deepkit numeric `brand` to the JTD numeric `type` keyword that best preserves the underlying width and signedness.\n *\n * @param brand - The Deepkit `TypeNumberBrand` of a numeric reflection, or `undefined` when no brand is set.\n * @returns The JTD numeric `type` keyword to use.\n */\nfunction numberBrandToJtdType(\n brand: TypeNumberBrand | undefined\n):\n | \"int8\"\n | \"uint8\"\n | \"int16\"\n | \"uint16\"\n | \"int32\"\n | \"uint32\"\n | \"float32\"\n | \"float64\" {\n switch (brand) {\n case TypeNumberBrand.integer:\n return \"int32\";\n case TypeNumberBrand.int8:\n return \"int8\";\n case TypeNumberBrand.uint8:\n return \"uint8\";\n case TypeNumberBrand.int16:\n return \"int16\";\n case TypeNumberBrand.uint16:\n return \"uint16\";\n case TypeNumberBrand.int32:\n return \"int32\";\n case TypeNumberBrand.uint32:\n return \"uint32\";\n case TypeNumberBrand.float:\n case TypeNumberBrand.float32:\n return \"float32\";\n case TypeNumberBrand.float64:\n return \"float64\";\n case undefined:\n default:\n return \"float64\";\n }\n}\n\n/**\n * Converts a Deepkit type reflection into a JSON Type Definition (RFC 8927) form suitable for AJV's JTD validator.\n *\n * @remarks\n * Some TypeScript constructs have no direct JTD equivalent and are handled with the closest available form:\n *\n * - `null` and `undefined` become the empty JTD form with `nullable: true`.\n * - Unions of primitives that cannot be expressed as a JTD enum collapse to the empty form (which validates any value).\n * - String/number/bigint literal unions are emitted as a JTD enum (non-string members are stringified, as JTD requires string enum members).\n * - Tuples are emitted as a JTD elements form whose element schema is the single tuple member type, or the empty schema for mixed tuples.\n * - `Date` is emitted as `{ type: \"timestamp\" }`.\n * - Discriminated unions of object literals (a shared string-literal tag property) are emitted as a JTD discriminator form.\n *\n * @param reflection - The Deepkit type reflection to convert.\n * @returns The corresponding JTD form, or `undefined` if the type cannot be represented.\n */\nexport function reflectionToJsonSchema<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(reflection: Type): JTDSchemaType<TMetadata> | undefined {\n const result = reflectionToJtd<TMetadata>(reflection);\n\n return result;\n}\n\n/**\n * Internal worker that performs the recursive Deepkit reflection → JTD conversion.\n *\n * @param reflection - The Deepkit type reflection to convert.\n * @returns The corresponding JTD form, or `undefined` if the type cannot be represented.\n */\nfunction reflectionToJtd<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(reflection: Type): JTDSchemaType<TMetadata> | undefined {\n const schema = {} as JTDSchemaType<TMetadata>;\n\n if (isSetObject((reflection as { tags?: TagsReflection })?.tags)) {\n const tags = (reflection as { tags: TagsReflection }).tags;\n\n schema.metadata = (schema.metadata ?? {}) as TMetadata;\n if (tags.readonly === true) {\n schema.metadata.isReadonly = true;\n }\n if (tags.ignore === true) {\n schema.metadata.isIgnored = true;\n }\n if (tags.internal === true) {\n schema.metadata.isInternal = true;\n }\n if (tags.runtime === true) {\n schema.metadata.isRuntime = true;\n }\n if (tags.hidden === true) {\n schema.metadata.isHidden = true;\n }\n if (isSetArray(tags.alias)) {\n schema.metadata.alias = tags.alias;\n }\n if (isSetString(tags.title)) {\n schema.metadata.title = tags.title;\n }\n }\n\n switch (reflection.kind) {\n case ReflectionKind.any:\n case ReflectionKind.unknown:\n case ReflectionKind.void:\n case ReflectionKind.object:\n return {};\n case ReflectionKind.never:\n return undefined;\n case ReflectionKind.undefined:\n case ReflectionKind.null:\n return { nullable: true };\n case ReflectionKind.string:\n return { ...schema, type: \"string\" };\n case ReflectionKind.boolean:\n return { ...schema, type: \"boolean\" };\n case ReflectionKind.number:\n return {\n ...schema,\n type: numberBrandToJtdType(reflection.brand)\n };\n case ReflectionKind.bigint:\n // JTD has no native 64-bit integer type — float64 is the widest numeric form.\n return { ...schema, type: \"float64\" };\n case ReflectionKind.regexp:\n return { ...schema, type: \"string\" };\n case ReflectionKind.literal: {\n const { literal } = reflection;\n if (typeof literal === \"string\") {\n return { ...schema, enum: [literal] };\n }\n\n if (typeof literal === \"number\" || typeof literal === \"bigint\") {\n return {\n ...schema,\n enum: [String(literal)]\n };\n }\n\n if (typeof literal === \"boolean\") {\n // JTD has no boolean literal — emit the type form.\n return { ...schema, type: \"boolean\" };\n }\n\n if (literal instanceof RegExp) {\n return { ...schema, type: \"string\" };\n }\n\n return schema;\n }\n case ReflectionKind.templateLiteral:\n return { ...schema, type: \"string\" };\n case ReflectionKind.enum: {\n const values = reflection.values\n .filter(\n (value): value is string | number =>\n typeof value === \"string\" || typeof value === \"number\"\n )\n .map(value => String(value));\n\n const unique = Array.from(new Set(values));\n if (unique.length === 0) {\n return schema;\n }\n\n return { ...schema, enum: unique };\n }\n case ReflectionKind.array: {\n const items = reflectionToJtd<TMetadata>(reflection.type);\n\n return { ...schema, elements: items ?? {} };\n }\n case ReflectionKind.tuple: {\n const items = reflection.types\n .map(member => reflectionToJtd<TMetadata>(member.type))\n .filter((item): item is JTDSchemaType<TMetadata> => item !== undefined);\n if (items.length === 0) {\n return { ...schema, elements: {} };\n }\n\n if (items.length === 1) {\n return { ...schema, elements: items[0]! };\n }\n\n // JTD has no tuple form — accept any element shape.\n return { ...schema, elements: {} };\n }\n case ReflectionKind.union: {\n const branches = reflection.types\n .map(inner => reflectionToJtd<TMetadata>(inner))\n .filter((item): item is JTDSchemaType<TMetadata> => item !== undefined);\n\n const nullable = reflection.types.some(\n inner =>\n inner.kind === ReflectionKind.null ||\n inner.kind === ReflectionKind.undefined\n );\n const nonNull = branches.filter(b => !isPureNullable(b));\n\n if (nonNull.length === 0) {\n return { ...schema, nullable: true };\n }\n\n if (nonNull.length === 1) {\n const only = nonNull[0]!;\n if (nullable) {\n (only as { nullable?: boolean }).nullable = true;\n }\n\n return { ...schema, ...only };\n }\n\n // String-enum union: combine all enum branches into one JTD enum.\n if (nonNull.every(isEnumForm)) {\n const merged = Array.from(\n new Set(nonNull.flatMap(b => (b as { enum: string[] }).enum))\n );\n const form: JTDSchemaType<TMetadata> = { ...schema, enum: merged };\n\n if (nullable) {\n (form as { nullable?: boolean }).nullable = true;\n }\n\n return { ...schema, ...form };\n }\n\n // Discriminated union of object literals: detect a shared string-literal tag.\n const discriminator = tryReflectionDiscriminator<TMetadata>(\n reflection.types\n );\n if (discriminator) {\n if (nullable) {\n (discriminator as { nullable?: boolean }).nullable = true;\n }\n\n return { ...schema, ...discriminator };\n }\n\n // Fallback — JTD has no general union; allow any value.\n const fallback: JTDSchemaType<TMetadata> = {};\n if (nullable) {\n (fallback as { nullable?: boolean }).nullable = true;\n }\n\n return { ...schema, ...fallback };\n }\n case ReflectionKind.intersection: {\n const members = reflection.types\n .map(inner => reflectionToJtd<TMetadata>(inner))\n .filter(\n (item): item is JTDSchemaType<TMetadata> | undefined =>\n item !== undefined\n );\n if (members.length === 0) {\n return undefined as JTDSchemaType<TMetadata> | undefined;\n }\n\n if (members.length === 1) {\n return { ...schema, ...members[0] };\n }\n\n if (\n members.every(member => member && isPropertiesForm<TMetadata>(member))\n ) {\n return mergePropertiesForms<TMetadata>(\n members as JTDSchemaType<TMetadata>[]\n );\n }\n\n return { ...schema, ...members[0] };\n }\n case ReflectionKind.promise:\n return reflectionToJtd<TMetadata>(reflection.type);\n case ReflectionKind.objectLiteral:\n return objectReflectionToJtd<TMetadata>(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 { ...schema, type: \"timestamp\" };\n case \"RegExp\":\n return { ...schema, type: \"string\" };\n case \"URL\":\n return { ...schema, type: \"string\" };\n case \"Set\": {\n const itemType = reflection.arguments?.[0];\n const items = itemType\n ? reflectionToJtd<TMetadata>(itemType)\n : undefined;\n\n return { ...schema, elements: items ?? {} };\n }\n case \"Map\": {\n const valueType = reflection.arguments?.[1];\n const values = valueType\n ? reflectionToJtd<TMetadata>(valueType)\n : undefined;\n\n return { ...schema, values: values ?? {} };\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 // Base64-encoded binary payload — represented as a plain string in JTD.\n return { ...schema, type: \"string\" };\n case undefined:\n default:\n return objectReflectionToJtd<TMetadata>(reflection);\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\n/**\n * Tests whether a JTD form is an enum form.\n *\n * @param form - The JTD form to inspect.\n * @returns `true` if the form is a JTD enum form.\n */\nfunction isEnumForm<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(\n form: JTDSchemaType<TMetadata>\n): form is { enum: string[]; nullable?: boolean; metadata?: TMetadata } {\n return Array.isArray((form as { enum?: unknown[] }).enum);\n}\n\n/**\n * Tests whether a JTD form is a properties form (object).\n *\n * @param form - The JTD form to inspect.\n * @returns `true` if the form is a JTD properties form.\n */\nfunction isPropertiesForm<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(\n form: JTDSchemaType<TMetadata>\n): form is {\n properties: Record<string, JTDSchemaType<TMetadata>>;\n optionalProperties?: Record<string, JTDSchemaType<TMetadata>>;\n nullable?: boolean;\n metadata?: TMetadata;\n} {\n return (\n \"properties\" in (form as object) || \"optionalProperties\" in (form as object)\n );\n}\n\n/**\n * Tests whether a JTD form is the empty `{ nullable: true }` placeholder.\n *\n * @param form - The JTD form to inspect.\n * @returns `true` if the form has no shape constraints beyond `nullable`.\n */\nfunction isPureNullable<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(form: JTDSchemaType<TMetadata>): boolean {\n const keys = Object.keys(form as object).filter(\n k => k !== \"nullable\" && k !== \"metadata\"\n );\n\n return (\n keys.length === 0 && (form as { nullable?: boolean }).nullable === true\n );\n}\n\n/**\n * Shallow-merges two JTD properties forms, unioning their `properties` and `optionalProperties` maps.\n *\n * @param forms - The JTD properties forms to merge.\n * @returns The merged JTD properties form.\n */\nfunction mergePropertiesForms<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(forms: JTDSchemaType<TMetadata>[]): JTDSchemaType<TMetadata> {\n const merged: {\n properties: Record<string, JTDSchemaType<TMetadata>>;\n optionalProperties: Record<string, JTDSchemaType<TMetadata>>;\n additionalProperties?: boolean;\n } = {\n properties: {},\n optionalProperties: {}\n };\n\n for (const form of forms) {\n const properties = (\n form as { properties?: Record<string, JTDSchemaType<TMetadata>> }\n ).properties;\n const optionalProperties = (\n form as { optionalProperties?: Record<string, JTDSchemaType<TMetadata>> }\n ).optionalProperties;\n if (properties) {\n defu(merged.properties, properties);\n }\n if (optionalProperties) {\n defu(merged.optionalProperties, optionalProperties);\n }\n if ((form as { additionalProperties?: boolean }).additionalProperties) {\n merged.additionalProperties = true;\n }\n }\n\n const hasProperties = Object.keys(merged.properties).length > 0;\n const hasOptional = Object.keys(merged.optionalProperties).length > 0;\n const result: JTDSchemaType<TMetadata> = {};\n\n if (hasProperties) {\n (\n result as { properties: Record<string, JTDSchemaType<TMetadata>> }\n ).properties = merged.properties;\n } else if (!hasOptional) {\n (\n result as { properties: Record<string, JTDSchemaType<TMetadata>> }\n ).properties = {};\n }\n\n if (hasOptional) {\n (\n result as { optionalProperties: Record<string, JTDSchemaType<TMetadata>> }\n ).optionalProperties = merged.optionalProperties;\n }\n\n if (merged.additionalProperties) {\n (result as { additionalProperties: boolean }).additionalProperties = true;\n }\n\n return result;\n}\n\n/**\n * Detects whether a Deepkit union represents a tagged union and, when so, emits the corresponding JTD discriminator form.\n *\n * @param types - The Deepkit reflection types that make up the union branches.\n * @returns A JTD discriminator form if every non-null branch is an object literal that shares a string-literal tag property, otherwise `undefined`.\n */\nfunction tryReflectionDiscriminator<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(types: readonly Type[]): JTDSchemaType<TMetadata> | 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 mapping: Record<string, JTDSchemaType<TMetadata>> = {};\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 // Build the branch body excluding the discriminator property.\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 = objectReflectionToJtd<TMetadata>(filteredBranch);\n if (!body || !isPropertiesForm<TMetadata>(body)) {\n return undefined;\n }\n\n mapping[first.literal] = body;\n }\n\n if (!tagKey) {\n return undefined;\n }\n\n return { discriminator: tagKey, mapping };\n}\n\n/**\n * Internal worker that produces a JTD properties form (or `values` form for index signatures alone) from a Deepkit object-like type.\n *\n * @param type - The class or object literal type whose members should be serialized.\n * @returns A JTD properties or values form describing the type's members.\n */\nfunction objectReflectionToJtd<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(type: TypeObjectLiteral | TypeClass): JTDSchemaType<TMetadata> {\n const reflection = ReflectionClass.from(type);\n\n const schema = {} as {\n properties?: Record<string, JTDSchemaType<TMetadata>>;\n optionalProperties?: Record<string, JTDSchemaType<TMetadata>>;\n additionalProperties?: boolean;\n metadata?: TMetadata;\n };\n\n schema.metadata = (schema.metadata ?? {}) as TMetadata;\n schema.metadata.isReadonly = reflection.isReadonly();\n schema.metadata.isIgnored = reflection.isIgnored();\n schema.metadata.isInternal = reflection.isInternal();\n schema.metadata.isRuntime = reflection.isRuntime();\n schema.metadata.isHidden = reflection.isHidden();\n\n if (isSetString(reflection.databaseSchemaName)) {\n schema.metadata.resourceId = reflection.databaseSchemaName;\n }\n if (isSetString(reflection.getName())) {\n schema.metadata.name = reflection.getName();\n }\n if (isSetString(reflection.getDescription())) {\n schema.metadata.description = reflection.getDescription();\n }\n if (isSetArray(reflection.getAlias())) {\n schema.metadata.alias = reflection.getAlias();\n }\n if (isSetString(reflection.getTitle())) {\n schema.metadata.title = reflection.getTitle();\n }\n\n const properties: Record<string, JTDSchemaType<TMetadata>> = {};\n const optionalProperties: Record<string, JTDSchemaType<TMetadata>> = {};\n\n for (const propertyReflection of reflection.getProperties()) {\n if (propertyReflection.getKind() === ReflectionKind.indexSignature) {\n const valueSchema = reflectionToJtd<TMetadata>(propertyReflection.type);\n if (valueSchema) {\n return {\n ...schema,\n values: valueSchema,\n additionalProperties: true\n };\n }\n } else {\n const property = reflectionToJtd<TMetadata>(propertyReflection.type);\n if (!property) {\n continue;\n }\n\n property.metadata = (property.metadata ?? {}) as TMetadata;\n property.metadata.isReadonly = propertyReflection.isReadonly();\n property.metadata.isIgnored = propertyReflection.isIgnored();\n property.metadata.isInternal = propertyReflection.isInternal();\n property.metadata.isRuntime = propertyReflection.isRuntime();\n property.metadata.isPrimaryKey = propertyReflection.isPrimaryKey();\n property.metadata.isHidden = propertyReflection.isHidden();\n property.nullable = propertyReflection.isNullable();\n property.metadata.visibility = propertyReflection.isPublic()\n ? \"public\"\n : propertyReflection.isProtected()\n ? \"protected\"\n : propertyReflection.isPrivate()\n ? \"private\"\n : undefined;\n\n if (propertyReflection.hasDefault()) {\n property.metadata.default = propertyReflection.getDefaultValue();\n }\n if (isSetString(propertyReflection.getNameAsString())) {\n property.metadata.name = propertyReflection.getNameAsString();\n }\n if (isSetArray(propertyReflection.getGroups())) {\n property.metadata.groups = propertyReflection.getGroups();\n }\n if (isSetString(propertyReflection.getDescription())) {\n property.metadata.description = propertyReflection.getDescription();\n }\n if (isSetArray(propertyReflection.getAlias())) {\n property.metadata.alias = propertyReflection.getAlias();\n }\n if (isSetString(propertyReflection.getTitle())) {\n property.metadata.title = propertyReflection.getTitle();\n }\n\n if (propertyReflection.isOptional()) {\n optionalProperties[propertyReflection.name] = property;\n } else {\n properties[propertyReflection.name] = property;\n }\n }\n }\n\n if (Object.keys(properties).length > 0) {\n schema.properties = properties;\n } else if (Object.keys(optionalProperties).length > 0) {\n schema.optionalProperties = optionalProperties;\n } else {\n schema.properties = {};\n }\n\n return schema;\n}\n"],"mappings":";;;;;;;;;;;AAuCA,SAAS,qBACP,OASY;CACZ,QAAQ,OAAR;EACE,KAAK,gBAAgB,SACnB,OAAO;EACT,KAAK,gBAAgB,MACnB,OAAO;EACT,KAAK,gBAAgB,OACnB,OAAO;EACT,KAAK,gBAAgB,OACnB,OAAO;EACT,KAAK,gBAAgB,QACnB,OAAO;EACT,KAAK,gBAAgB,OACnB,OAAO;EACT,KAAK,gBAAgB,QACnB,OAAO;EACT,KAAK,gBAAgB;EACrB,KAAK,gBAAgB,SACnB,OAAO;EACT,KAAK,gBAAgB,SACnB,OAAO;EACT,KAAK;EACL,SACE,OAAO;CACX;AACF;;;;;;;;;;;;;;;;;AAkBA,SAAgB,uBAEd,YAAwD;CAGxD,OAFe,gBAA2B,UAE9B;AACd;;;;;;;AAQA,SAAS,gBAEP,YAAwD;CACxD,MAAM,SAAS,CAAC;CAEhB,IAAI,YAAa,YAA0C,IAAI,GAAG;EAChE,MAAM,OAAQ,WAAwC;EAEtD,OAAO,WAAY,OAAO,YAAY,CAAC;EACvC,IAAI,KAAK,aAAa,MACpB,OAAO,SAAS,aAAa;EAE/B,IAAI,KAAK,WAAW,MAClB,OAAO,S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"sources":["../src/resolve.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 { PluginContext, UnresolvedContext } from \"@powerlines/core\";\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport { reflect, Type } from \"@powerlines/deepkit/vendor/type\";\nimport { parseTypeDefinition } from \"@stryke/convert/parse-type-definition\";\nimport { findFileDotExtension } from \"@stryke/path/find\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { TypeDefinition } from \"@stryke/types/configuration\";\nimport defu from \"defu\";\nimport { bundle, BundleOptions } from \"./bundle\";\nimport { TypeDefinitionReference } from \"./types\";\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 type - The type definition to compile. This can be either a string or a {@link TypeDefinition} 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 type: TypeDefinitionReference,\n overrides?: BundleOptions\n): Promise<TResult> {\n let typeDefinition!: TypeDefinition;\n if (isSetString(type)) {\n typeDefinition = parseTypeDefinition(type) as TypeDefinition;\n } else {\n typeDefinition = type;\n }\n\n const result = await bundle<TContext>(\n context,\n typeDefinition.file,\n overrides\n );\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 typeDefinition.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 typeDefinition.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 TypeDefinition} 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: TypeDefinitionReference,\n options?: BundleOptions\n): Promise<TResult> {\n let typeDefinition!: TypeDefinition;\n if (isSetString(input)) {\n typeDefinition = parseTypeDefinition(input) as TypeDefinition;\n } else {\n typeDefinition = input;\n }\n\n const resolved = await resolveModule<Record<string, any>, TContext>(\n context,\n typeDefinition,\n options\n );\n\n let exportName = typeDefinition.name;\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 typeDefinition.file\n }\" module. ${\n Object.keys(resolved).length === 0\n ? `After bundling, no exports were found in the module. Please ensure that the \"${\n typeDefinition.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 TypeDefinition} 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: TypeDefinitionReference,\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"],"mappings":";;;;;;;;;;;;;;;;;AAqCA,eAAsB,cAIpB,SACA,MACA,WACkB;CAClB,IAAI;AACJ,KAAI,YAAY,KAAK,CACnB,kBAAiB,oBAAoB,KAAK;KAE1C,kBAAiB;CAGnB,MAAM,SAAS,MAAM,OACnB,SACA,eAAe,MACf,UACD;CAED,IAAI;AACJ,KAAI;AACF,aAAW,MAAM,QAAQ,SAAS,WAAW,OAAO,MAAM;GACxD,UAAU,OAAO;GACjB,KAAK,qBAAqB,OAAO,KAAK;GACvC,CAAC;UACK,OAAO;AACd,MACE,YAAa,MAAgB,QAAQ,IACrC,IAAI,OACF,uBAAuB,QAAQ,OAAO,WAAW,QAAQ,aAAa,MACvE,CAAC,KAAM,MAAgB,QAAQ,EAChC;GACA,MAAM,aAAc,MAAgB,QAAQ,MAC1C,IAAI,OACF,wBAAwB,QAAQ,OAAO,WAAW,QAAQ,aAAa,OACxE,CACF,GAAG;AACJ,SAAM,IAAI,MACR,eAAe,WAAW,4CACxB,eAAe,KAChB,uHACC,QAAQ,OAAO,SAAS,YAAY,WACpC,QAAQ,OAAO,SAAS,YAAY,UAChC;;;EAGZ,OAAO,SACK,KAEP;;AAGH,QAAM,IAAI,MACR,8CACE,eAAe,KAChB,YAAa,MAAgB,UAC5B,QAAQ,OAAO,SAAS,YAAY,WACpC,QAAQ,OAAO,SAAS,YAAY,UAChC;;;EAGV,OAAO,SACG,KAEP;;AAGH,QAAO;;;;;;;;;;AAWT,eAAsB,QAIpB,SACA,OACA,SACkB;CAClB,IAAI;AACJ,KAAI,YAAY,MAAM,CACpB,kBAAiB,oBAAoB,MAAM;KAE3C,kBAAiB;CAGnB,MAAM,WAAW,MAAM,cACrB,SACA,gBACA,QACD;CAED,IAAI,aAAa,eAAe;AAChC,KAAI,CAAC,WACH,cAAa;CAGf,MAAM,iBAAiB,SAAS,eAAe,SAAS,MAAM;AAC9D,KAAI,mBAAmB,OACrB,OAAM,IAAI,MACR,eAAe,WAAW,kCACxB,eAAe,KAChB,YACC,OAAO,KAAK,SAAS,CAAC,WAAW,IAC7B,gFACE,eAAe,KAChB,kBAAkB,WAAW,oCAC9B,+CAA+C,OAAO,KACpD,SACD,CAAC,KACA,KACD,CAAC,kEAET;AAGH,QAAO;;;;;;;;;;AAWT,eAAsB,kBAGpB,SACA,OACA,SACe;AACf,QAAO,QACL,MAAM,QACJ,SACA,OACA,KAAK,SAAS,EACZ,SAAS,CACP,cAAc,SAAS;EACrB,YAAY;EACZ,OAAO;EACR,CAAC,CACH,EACF,CAAC,CACH,CACF"}
1
+ {"version":3,"file":"resolve.mjs","names":[],"sources":["../src/resolve.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 { PluginContext, UnresolvedContext } from \"@powerlines/core\";\nimport { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport { reflect, Type } from \"@powerlines/deepkit/vendor/type\";\nimport { parseTypeDefinition } from \"@stryke/convert/parse-type-definition\";\nimport { findFileDotExtension } from \"@stryke/path/find\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { TypeDefinition } from \"@stryke/types/configuration\";\nimport defu from \"defu\";\nimport { bundle, BundleOptions } from \"./bundle\";\nimport { TypeDefinitionReference } from \"./types\";\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 type - The type definition to compile. This can be either a string or a {@link TypeDefinition} 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 type: TypeDefinitionReference,\n overrides?: BundleOptions\n): Promise<TResult> {\n let typeDefinition!: TypeDefinition;\n if (isSetString(type)) {\n typeDefinition = parseTypeDefinition(type) as TypeDefinition;\n } else {\n typeDefinition = type;\n }\n\n const result = await bundle<TContext>(\n context,\n typeDefinition.file,\n overrides\n );\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 typeDefinition.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 typeDefinition.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 TypeDefinition} 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: TypeDefinitionReference,\n options?: BundleOptions\n): Promise<TResult> {\n let typeDefinition!: TypeDefinition;\n if (isSetString(input)) {\n typeDefinition = parseTypeDefinition(input) as TypeDefinition;\n } else {\n typeDefinition = input;\n }\n\n const resolved = await resolveModule<Record<string, any>, TContext>(\n context,\n typeDefinition,\n options\n );\n\n let exportName = typeDefinition.name;\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 typeDefinition.file\n }\" module. ${\n Object.keys(resolved).length === 0\n ? `After bundling, no exports were found in the module. Please ensure that the \"${\n typeDefinition.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 TypeDefinition} 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: TypeDefinitionReference,\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"],"mappings":";;;;;;;;;;;;;;;;;AAqCA,eAAsB,cAIpB,SACA,MACA,WACkB;CAClB,IAAI;CACJ,IAAI,YAAY,IAAI,GAClB,iBAAiB,oBAAoB,IAAI;MAEzC,iBAAiB;CAGnB,MAAM,SAAS,MAAM,OACnB,SACA,eAAe,MACf,SACF;CAEA,IAAI;CACJ,IAAI;EACF,WAAW,MAAM,QAAQ,SAAS,WAAW,OAAO,MAAM;GACxD,UAAU,OAAO;GACjB,KAAK,qBAAqB,OAAO,IAAI;EACvC,CAAC;CACH,SAAS,OAAO;EACd,IACE,YAAa,MAAgB,OAAO,KACpC,IAAI,OACF,uBAAuB,QAAQ,OAAO,WAAW,QAAQ,aAAa,KACxE,EAAE,KAAM,MAAgB,OAAO,GAC/B;GACA,MAAM,aAAc,MAAgB,QAAQ,MAC1C,IAAI,OACF,wBAAwB,QAAQ,OAAO,WAAW,QAAQ,aAAa,MACzE,CACF,IAAI;GACJ,MAAM,IAAI,MACR,eAAe,WAAW,4CACxB,eAAe,KAChB,uHACC,QAAQ,OAAO,SAAS,YAAY,WACpC,QAAQ,OAAO,SAAS,YAAY,UAChC;;;EAGZ,OAAO,SACK,IAER;EACF;EAEA,MAAM,IAAI,MACR,8CACE,eAAe,KAChB,YAAa,MAAgB,UAC5B,QAAQ,OAAO,SAAS,YAAY,WACpC,QAAQ,OAAO,SAAS,YAAY,UAChC;;;EAGV,OAAO,SACG,IAER;CACF;CAEA,OAAO;AACT;;;;;;;;;AAUA,eAAsB,QAIpB,SACA,OACA,SACkB;CAClB,IAAI;CACJ,IAAI,YAAY,KAAK,GACnB,iBAAiB,oBAAoB,KAAK;MAE1C,iBAAiB;CAGnB,MAAM,WAAW,MAAM,cACrB,SACA,gBACA,OACF;CAEA,IAAI,aAAa,eAAe;CAChC,IAAI,CAAC,YACH,aAAa;CAGf,MAAM,iBAAiB,SAAS,eAAe,SAAS,MAAM;CAC9D,IAAI,mBAAmB,QACrB,MAAM,IAAI,MACR,eAAe,WAAW,kCACxB,eAAe,KAChB,YACC,OAAO,KAAK,QAAQ,EAAE,WAAW,IAC7B,gFACE,eAAe,KAChB,kBAAkB,WAAW,oCAC9B,+CAA+C,OAAO,KACpD,QACF,EAAE,KACA,IACF,EAAE,iEAEV;CAGF,OAAO;AACT;;;;;;;;;AAUA,eAAsB,kBAGpB,SACA,OACA,SACe;CACf,OAAO,QACL,MAAM,QACJ,SACA,OACA,KAAK,SAAS,EACZ,SAAS,CACP,cAAc,SAAS;EACrB,YAAY;EACZ,OAAO;CACT,CAAC,CACH,EACF,CAAC,CACH,CACF;AACF"}
@@ -1,7 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
3
  let _stryke_type_checks = require("@stryke/type-checks");
4
- let _stryke_json_schema = require("@stryke/json/schema");
5
4
 
6
5
  //#region src/type-checks.ts
7
6
  /**
@@ -10,8 +9,17 @@ let _stryke_json_schema = require("@stryke/json/schema");
10
9
  * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
11
10
  * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
12
11
  */
12
+ function isJTDSchemaObject(input) {
13
+ return (0, _stryke_type_checks.isSetObject)(input) && ("properties" in input && (0, _stryke_type_checks.isObject)(input.properties) || "optionalProperties" in input && (0, _stryke_type_checks.isObject)(input.optionalProperties));
14
+ }
15
+ /**
16
+ * Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.
17
+ *
18
+ * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
19
+ * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
20
+ */
13
21
  function isJTDSchema(input) {
14
- return (0, _stryke_json_schema.isJsonSchemaObjectType)(input) && "jtd" in input && input.jtd === true;
22
+ return (0, _stryke_type_checks.isSetObject)(input) && (isJTDSchemaObject(input) || "elements" in input || "values" in input || "ref" in input || "type" in input || "enum" in input || "discriminator" in input && (0, _stryke_type_checks.isSetString)(input.discriminator) && "mapping" in input && (0, _stryke_type_checks.isObject)(input.mapping));
15
23
  }
16
24
  /**
17
25
  * Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedSchema | Schema} object. This function verifies that the input is a non-null object whose optional metadata properties (`id`, `title`, `description`, `$schema`, `tsType`, `markdownType`, `type`, `required`, `tags`, `args`, `properties`, and `resolve`) - when present - match the shapes declared by `untyped`'s [`Schema`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface.
@@ -67,10 +75,21 @@ function isSchema(input) {
67
75
  function isExtractedSchema(input) {
68
76
  return isSchema(input) && "source" in input && (0, _stryke_type_checks.isSetObject)(input.source) && "schema" in input.source && isJTDSchema(input.source.schema) && "variant" in input.source && (0, _stryke_type_checks.isSetString)(input.source.variant);
69
77
  }
78
+ /**
79
+ * Type guard to check if a given input is a {@link ObjectSchema} object. This function verifies that the input is a {@link Schema} object and that its `schema` property has either a `properties` property that is an object or an `optionalProperties` property that is an object (as per the structure of JTD schema objects). If these conditions are met, the function returns `true`, indicating that the input is a valid {@link ObjectSchema}; otherwise, it returns `false`.
80
+ *
81
+ * @param input - The input to check for being a {@link ObjectSchema}.
82
+ * @returns `true` if the input is a {@link ObjectSchema}, otherwise `false`.
83
+ */
84
+ function isObjectSchema(input) {
85
+ return isSchema(input) && isJTDSchemaObject(input.schema);
86
+ }
70
87
 
71
88
  //#endregion
72
89
  exports.isExtractedSchema = isExtractedSchema;
73
90
  exports.isJTDSchema = isJTDSchema;
91
+ exports.isJTDSchemaObject = isJTDSchemaObject;
92
+ exports.isObjectSchema = isObjectSchema;
74
93
  exports.isSchema = isSchema;
75
94
  exports.isUntypedInput = isUntypedInput;
76
95
  exports.isUntypedSchema = isUntypedSchema;
@@ -1,8 +1,15 @@
1
- import { ExtractedSchema, Schema as Schema$1, SchemaMetadata } from "./types.cjs";
1
+ import { ExtractedSchema, JTDSchemaObjectType, ObjectSchema, Schema as Schema$1, SchemaMetadata } from "./types.cjs";
2
2
  import { InputObject, Schema } from "untyped";
3
3
  import { JTDSchemaType } from "ajv/dist/types/jtd-schema.js";
4
4
 
5
5
  //#region src/type-checks.d.ts
6
+ /**
7
+ * Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.
8
+ *
9
+ * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
10
+ * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
11
+ */
12
+ declare function isJTDSchemaObject<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is JTDSchemaObjectType<TMetadata>;
6
13
  /**
7
14
  * Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.
8
15
  *
@@ -38,6 +45,13 @@ declare function isSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(inp
38
45
  * @returns `true` if the input is a {@link ExtractedSchema}, otherwise `false`.
39
46
  */
40
47
  declare function isExtractedSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is ExtractedSchema<TMetadata>;
48
+ /**
49
+ * Type guard to check if a given input is a {@link ObjectSchema} object. This function verifies that the input is a {@link Schema} object and that its `schema` property has either a `properties` property that is an object or an `optionalProperties` property that is an object (as per the structure of JTD schema objects). If these conditions are met, the function returns `true`, indicating that the input is a valid {@link ObjectSchema}; otherwise, it returns `false`.
50
+ *
51
+ * @param input - The input to check for being a {@link ObjectSchema}.
52
+ * @returns `true` if the input is a {@link ObjectSchema}, otherwise `false`.
53
+ */
54
+ declare function isObjectSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is ObjectSchema<TMetadata>;
41
55
  //#endregion
42
- export { isExtractedSchema, isJTDSchema, isSchema, isUntypedInput, isUntypedSchema };
56
+ export { isExtractedSchema, isJTDSchema, isJTDSchemaObject, isObjectSchema, isSchema, isUntypedInput, isUntypedSchema };
43
57
  //# sourceMappingURL=type-checks.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"type-checks.d.cts","names":[],"sources":["../src/type-checks.ts"],"mappings":";;;;;;;AAiCA;;;;iBAAgB,WAAA,mBAA8B,cAAA,GAAiB,cAAA,CAAA,CAC7D,KAAA,YACC,KAAA,IAAS,aAAA,CAAc,SAAA;;;;;;;iBAUV,eAAA,CAAgB,KAAA,YAAiB,KAAA,IAAS,MAAA;;;;;;;iBAwD1C,cAAA,CAAe,KAAA,YAAiB,KAAA,IAAS,WAAA;;;;;;;iBAsBzC,QAAA,mBAA2B,cAAA,GAAiB,cAAA,CAAA,CAC1D,KAAA,YACC,KAAA,IAAS,QAAA,CAAO,SAAA;;AAxBnB;;;;;iBA0CgB,iBAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,eAAA,CAAgB,SAAA"}
1
+ {"version":3,"file":"type-checks.d.cts","names":[],"sources":["../src/type-checks.ts"],"mappings":";;;;;;;AA2CA;;;;iBAAgB,iBAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,mBAAA,CAAoB,SAAA;;;;;;;iBAchC,WAAA,mBAA8B,cAAA,GAAiB,cAAA,CAAA,CAC7D,KAAA,YACC,KAAA,IAAS,aAAA,CAAc,SAAA;;;;;;AAhB+B;iBAsCzC,eAAA,CAAgB,KAAA,YAAiB,KAAA,IAAS,MAAa;;;;;;;iBAwDvD,cAAA,CAAe,KAAA,YAAiB,KAAA,IAAS,WAAkB;;;;;;;iBAsB3D,QAAA,mBAA2B,cAAA,GAAiB,cAAA,CAAA,CAC1D,KAAA,YACC,KAAA,IAAS,QAAA,CAAO,SAAA;;;AAtGgB;AAsBnC;;;iBAkGgB,iBAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,eAAA,CAAgB,SAAA;;;;;AApG2B;AAwDvE;iBA8DgB,cAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,YAAA,CAAa,SAAA"}
@@ -1,8 +1,15 @@
1
- import { ExtractedSchema, Schema as Schema$1, SchemaMetadata } from "./types.mjs";
1
+ import { ExtractedSchema, JTDSchemaObjectType, ObjectSchema, Schema as Schema$1, SchemaMetadata } from "./types.mjs";
2
2
  import { InputObject, Schema } from "untyped";
3
3
  import { JTDSchemaType } from "ajv/dist/types/jtd-schema.js";
4
4
 
5
5
  //#region src/type-checks.d.ts
6
+ /**
7
+ * Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.
8
+ *
9
+ * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
10
+ * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
11
+ */
12
+ declare function isJTDSchemaObject<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is JTDSchemaObjectType<TMetadata>;
6
13
  /**
7
14
  * Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.
8
15
  *
@@ -38,6 +45,13 @@ declare function isSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(inp
38
45
  * @returns `true` if the input is a {@link ExtractedSchema}, otherwise `false`.
39
46
  */
40
47
  declare function isExtractedSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is ExtractedSchema<TMetadata>;
48
+ /**
49
+ * Type guard to check if a given input is a {@link ObjectSchema} object. This function verifies that the input is a {@link Schema} object and that its `schema` property has either a `properties` property that is an object or an `optionalProperties` property that is an object (as per the structure of JTD schema objects). If these conditions are met, the function returns `true`, indicating that the input is a valid {@link ObjectSchema}; otherwise, it returns `false`.
50
+ *
51
+ * @param input - The input to check for being a {@link ObjectSchema}.
52
+ * @returns `true` if the input is a {@link ObjectSchema}, otherwise `false`.
53
+ */
54
+ declare function isObjectSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is ObjectSchema<TMetadata>;
41
55
  //#endregion
42
- export { isExtractedSchema, isJTDSchema, isSchema, isUntypedInput, isUntypedSchema };
56
+ export { isExtractedSchema, isJTDSchema, isJTDSchemaObject, isObjectSchema, isSchema, isUntypedInput, isUntypedSchema };
43
57
  //# sourceMappingURL=type-checks.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"type-checks.d.mts","names":[],"sources":["../src/type-checks.ts"],"mappings":";;;;;;;AAiCA;;;;iBAAgB,WAAA,mBAA8B,cAAA,GAAiB,cAAA,CAAA,CAC7D,KAAA,YACC,KAAA,IAAS,aAAA,CAAc,SAAA;;;;;;;iBAUV,eAAA,CAAgB,KAAA,YAAiB,KAAA,IAAS,MAAA;;;;;;;iBAwD1C,cAAA,CAAe,KAAA,YAAiB,KAAA,IAAS,WAAA;;;;;;;iBAsBzC,QAAA,mBAA2B,cAAA,GAAiB,cAAA,CAAA,CAC1D,KAAA,YACC,KAAA,IAAS,QAAA,CAAO,SAAA;;AAxBnB;;;;;iBA0CgB,iBAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,eAAA,CAAgB,SAAA"}
1
+ {"version":3,"file":"type-checks.d.mts","names":[],"sources":["../src/type-checks.ts"],"mappings":";;;;;;;AA2CA;;;;iBAAgB,iBAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,mBAAA,CAAoB,SAAA;;;;;;;iBAchC,WAAA,mBAA8B,cAAA,GAAiB,cAAA,CAAA,CAC7D,KAAA,YACC,KAAA,IAAS,aAAA,CAAc,SAAA;;;;;;AAhB+B;iBAsCzC,eAAA,CAAgB,KAAA,YAAiB,KAAA,IAAS,MAAa;;;;;;;iBAwDvD,cAAA,CAAe,KAAA,YAAiB,KAAA,IAAS,WAAkB;;;;;;;iBAsB3D,QAAA,mBAA2B,cAAA,GAAiB,cAAA,CAAA,CAC1D,KAAA,YACC,KAAA,IAAS,QAAA,CAAO,SAAA;;;AAtGgB;AAsBnC;;;iBAkGgB,iBAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,eAAA,CAAgB,SAAA;;;;;AApG2B;AAwDvE;iBA8DgB,cAAA,mBACI,cAAA,GAAiB,cAAA,CAAA,CACnC,KAAA,YAAiB,KAAA,IAAS,YAAA,CAAa,SAAA"}
@@ -1,5 +1,4 @@
1
- import { isFunction, isSetObject, isSetString } from "@stryke/type-checks";
2
- import { isJsonSchemaObjectType } from "@stryke/json/schema";
1
+ import { isFunction, isObject, isSetObject, isSetString } from "@stryke/type-checks";
3
2
 
4
3
  //#region src/type-checks.ts
5
4
  /**
@@ -8,8 +7,17 @@ import { isJsonSchemaObjectType } from "@stryke/json/schema";
8
7
  * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
9
8
  * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
10
9
  */
10
+ function isJTDSchemaObject(input) {
11
+ return isSetObject(input) && ("properties" in input && isObject(input.properties) || "optionalProperties" in input && isObject(input.optionalProperties));
12
+ }
13
+ /**
14
+ * Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.
15
+ *
16
+ * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
17
+ * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
18
+ */
11
19
  function isJTDSchema(input) {
12
- return isJsonSchemaObjectType(input) && "jtd" in input && input.jtd === true;
20
+ return isSetObject(input) && (isJTDSchemaObject(input) || "elements" in input || "values" in input || "ref" in input || "type" in input || "enum" in input || "discriminator" in input && isSetString(input.discriminator) && "mapping" in input && isObject(input.mapping));
13
21
  }
14
22
  /**
15
23
  * Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedSchema | Schema} object. This function verifies that the input is a non-null object whose optional metadata properties (`id`, `title`, `description`, `$schema`, `tsType`, `markdownType`, `type`, `required`, `tags`, `args`, `properties`, and `resolve`) - when present - match the shapes declared by `untyped`'s [`Schema`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface.
@@ -65,7 +73,16 @@ function isSchema(input) {
65
73
  function isExtractedSchema(input) {
66
74
  return isSchema(input) && "source" in input && isSetObject(input.source) && "schema" in input.source && isJTDSchema(input.source.schema) && "variant" in input.source && isSetString(input.source.variant);
67
75
  }
76
+ /**
77
+ * Type guard to check if a given input is a {@link ObjectSchema} object. This function verifies that the input is a {@link Schema} object and that its `schema` property has either a `properties` property that is an object or an `optionalProperties` property that is an object (as per the structure of JTD schema objects). If these conditions are met, the function returns `true`, indicating that the input is a valid {@link ObjectSchema}; otherwise, it returns `false`.
78
+ *
79
+ * @param input - The input to check for being a {@link ObjectSchema}.
80
+ * @returns `true` if the input is a {@link ObjectSchema}, otherwise `false`.
81
+ */
82
+ function isObjectSchema(input) {
83
+ return isSchema(input) && isJTDSchemaObject(input.schema);
84
+ }
68
85
 
69
86
  //#endregion
70
- export { isExtractedSchema, isJTDSchema, isSchema, isUntypedInput, isUntypedSchema };
87
+ export { isExtractedSchema, isJTDSchema, isJTDSchemaObject, isObjectSchema, isSchema, isUntypedInput, isUntypedSchema };
71
88
  //# sourceMappingURL=type-checks.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"type-checks.mjs","names":[],"sources":["../src/type-checks.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isJsonSchemaObjectType } from \"@stryke/json/schema\";\nimport { isFunction, isSetObject, isSetString } from \"@stryke/type-checks\";\nimport { JTDSchemaType } from \"ajv/dist/types/jtd-schema\";\nimport {\n InputObject as UntypedInputObject,\n Schema as UntypedSchema\n} from \"untyped\";\nimport { ExtractedSchema, Schema, SchemaMetadata } from \"./types\";\n\n/**\n * Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.\n *\n * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).\n * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.\n */\nexport function isJTDSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(\n input: unknown\n): input is JTDSchemaType<TMetadata> {\n return isJsonSchemaObjectType(input) && \"jtd\" in input && input.jtd === true;\n}\n\n/**\n * Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedSchema | Schema} object. This function verifies that the input is a non-null object whose optional metadata properties (`id`, `title`, `description`, `$schema`, `tsType`, `markdownType`, `type`, `required`, `tags`, `args`, `properties`, and `resolve`) - when present - match the shapes declared by `untyped`'s [`Schema`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface.\n *\n * @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) schema.\n * @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) schema, otherwise `false`.\n */\nexport function isUntypedSchema(input: unknown): input is UntypedSchema {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (\"id\" in schema && !isSetString(schema.id)) {\n return false;\n }\n if (\"title\" in schema && !isSetString(schema.title)) {\n return false;\n }\n if (\"description\" in schema && !isSetString(schema.description)) {\n return false;\n }\n if (\"$schema\" in schema && !isSetString(schema.$schema)) {\n return false;\n }\n if (\"tsType\" in schema && !isSetString(schema.tsType)) {\n return false;\n }\n if (\"markdownType\" in schema && !isSetString(schema.markdownType)) {\n return false;\n }\n if (\n \"type\" in schema &&\n !isSetString(schema.type) &&\n !Array.isArray(schema.type)\n ) {\n return false;\n }\n if (\"required\" in schema && !Array.isArray(schema.required)) {\n return false;\n }\n if (\"tags\" in schema && !Array.isArray(schema.tags)) {\n return false;\n }\n if (\"args\" in schema && !Array.isArray(schema.args)) {\n return false;\n }\n if (\"properties\" in schema && !isSetObject(schema.properties)) {\n return false;\n }\n if (\"resolve\" in schema && !isFunction(schema.resolve)) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedInputObject | InputObject}. This function verifies that the input is a non-null object and that any `untyped`-reserved `$`-prefixed properties have the expected shape: `$schema` (when present) must satisfy {@link isUntypedSchema} and `$resolve` (when present) must be a function. See `untyped`'s [`InputObject`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface for the canonical definition.\n *\n * @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) input object.\n * @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) input object, otherwise `false`.\n */\nexport function isUntypedInput(input: unknown): input is UntypedInputObject {\n if (!isSetObject(input)) {\n return false;\n }\n\n const inputObject = input as Record<string, unknown>;\n if (\"$schema\" in inputObject && !isUntypedSchema(inputObject.$schema)) {\n return false;\n }\n if (\"$resolve\" in inputObject && !isFunction(inputObject.$resolve)) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Type guard to check if a given input is a {@link Schema} object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants (\"json-schema\", \"standard-schema\", \"zod3\", or \"reflection\"). If all these conditions are met, the function returns `true`, indicating that the input is a valid {@link Schema}; otherwise, it returns `false`.\n *\n * @param input - The input to check for being a {@link Schema}.\n * @returns `true` if the input is a {@link Schema}, otherwise `false`.\n */\nexport function isSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(\n input: unknown\n): input is Schema<TMetadata> {\n return (\n isSetObject(input) &&\n \"schema\" in input &&\n isJTDSchema(input.schema) &&\n \"input\" in input &&\n isSetObject(input.input) &&\n \"variant\" in input &&\n isSetString(input.variant)\n );\n}\n\n/**\n * Type guard to check if a given input is a {@link ExtractedSchema} object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants (\"json-schema\", \"standard-schema\", \"zod3\", or \"reflection\"). If all these conditions are met, the function returns `true`, indicating that the input is a valid {@link ExtractedSchema}; otherwise, it returns `false`.\n *\n * @param input - The input to check for being a {@link ExtractedSchema}.\n * @returns `true` if the input is a {@link ExtractedSchema}, otherwise `false`.\n */\nexport function isExtractedSchema<\n TMetadata extends SchemaMetadata = SchemaMetadata\n>(input: unknown): input is ExtractedSchema<TMetadata> {\n return (\n isSchema<TMetadata>(input) &&\n \"source\" in input &&\n isSetObject(input.source) &&\n \"schema\" in input.source &&\n isJTDSchema(input.source.schema) &&\n \"variant\" in input.source &&\n isSetString(input.source.variant)\n );\n}\n"],"mappings":";;;;;;;;;;AAiCA,SAAgB,YACd,OACmC;AACnC,QAAO,uBAAuB,MAAM,IAAI,SAAS,SAAS,MAAM,QAAQ;;;;;;;;AAS1E,SAAgB,gBAAgB,OAAwC;AACtE,KAAI,CAAC,YAAY,MAAM,CACrB,QAAO;CAGT,MAAM,SAAS;AACf,KAAI,QAAQ,UAAU,CAAC,YAAY,OAAO,GAAG,CAC3C,QAAO;AAET,KAAI,WAAW,UAAU,CAAC,YAAY,OAAO,MAAM,CACjD,QAAO;AAET,KAAI,iBAAiB,UAAU,CAAC,YAAY,OAAO,YAAY,CAC7D,QAAO;AAET,KAAI,aAAa,UAAU,CAAC,YAAY,OAAO,QAAQ,CACrD,QAAO;AAET,KAAI,YAAY,UAAU,CAAC,YAAY,OAAO,OAAO,CACnD,QAAO;AAET,KAAI,kBAAkB,UAAU,CAAC,YAAY,OAAO,aAAa,CAC/D,QAAO;AAET,KACE,UAAU,UACV,CAAC,YAAY,OAAO,KAAK,IACzB,CAAC,MAAM,QAAQ,OAAO,KAAK,CAE3B,QAAO;AAET,KAAI,cAAc,UAAU,CAAC,MAAM,QAAQ,OAAO,SAAS,CACzD,QAAO;AAET,KAAI,UAAU,UAAU,CAAC,MAAM,QAAQ,OAAO,KAAK,CACjD,QAAO;AAET,KAAI,UAAU,UAAU,CAAC,MAAM,QAAQ,OAAO,KAAK,CACjD,QAAO;AAET,KAAI,gBAAgB,UAAU,CAAC,YAAY,OAAO,WAAW,CAC3D,QAAO;AAET,KAAI,aAAa,UAAU,CAAC,WAAW,OAAO,QAAQ,CACpD,QAAO;AAGT,QAAO;;;;;;;;AAST,SAAgB,eAAe,OAA6C;AAC1E,KAAI,CAAC,YAAY,MAAM,CACrB,QAAO;CAGT,MAAM,cAAc;AACpB,KAAI,aAAa,eAAe,CAAC,gBAAgB,YAAY,QAAQ,CACnE,QAAO;AAET,KAAI,cAAc,eAAe,CAAC,WAAW,YAAY,SAAS,CAChE,QAAO;AAGT,QAAO;;;;;;;;AAST,SAAgB,SACd,OAC4B;AAC5B,QACE,YAAY,MAAM,IAClB,YAAY,SACZ,YAAY,MAAM,OAAO,IACzB,WAAW,SACX,YAAY,MAAM,MAAM,IACxB,aAAa,SACb,YAAY,MAAM,QAAQ;;;;;;;;AAU9B,SAAgB,kBAEd,OAAqD;AACrD,QACE,SAAoB,MAAM,IAC1B,YAAY,SACZ,YAAY,MAAM,OAAO,IACzB,YAAY,MAAM,UAClB,YAAY,MAAM,OAAO,OAAO,IAChC,aAAa,MAAM,UACnB,YAAY,MAAM,OAAO,QAAQ"}
1
+ {"version":3,"file":"type-checks.mjs","names":[],"sources":["../src/type-checks.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport {\n isFunction,\n isObject,\n isSetObject,\n isSetString\n} from \"@stryke/type-checks\";\nimport { JTDSchemaType } from \"ajv/dist/types/jtd-schema\";\nimport {\n InputObject as UntypedInputObject,\n Schema as UntypedSchema\n} from \"untyped\";\nimport {\n ExtractedSchema,\n JTDSchemaObjectType,\n ObjectSchema,\n Schema,\n SchemaMetadata\n} from \"./types\";\n\n/**\n * Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.\n *\n * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).\n * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.\n */\nexport function isJTDSchemaObject<\n TMetadata extends SchemaMetadata = SchemaMetadata\n>(input: unknown): input is JTDSchemaObjectType<TMetadata> {\n return (\n isSetObject(input) &&\n ((\"properties\" in input && isObject(input.properties)) ||\n (\"optionalProperties\" in input && isObject(input.optionalProperties)))\n );\n}\n\n/**\n * Type guard to check if a given input is a [JSON Type Definition (JTD) schema object](https://tools.ietf.org/html/rfc8927). This function verifies that the input is a non-null object, contains a `jtd` property that is set to `true`, and has a `schema` property that is a JSON Schema (draft-07) object. If all these conditions are met, the function returns `true`, indicating that the input is a valid JTD schema; otherwise, it returns `false`.\n *\n * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).\n * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.\n */\nexport function isJTDSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(\n input: unknown\n): input is JTDSchemaType<TMetadata> {\n return (\n isSetObject(input) &&\n (isJTDSchemaObject<TMetadata>(input) ||\n \"elements\" in input ||\n \"values\" in input ||\n \"ref\" in input ||\n \"type\" in input ||\n \"enum\" in input ||\n (\"discriminator\" in input &&\n isSetString(input.discriminator) &&\n \"mapping\" in input &&\n isObject(input.mapping)))\n );\n}\n\n/**\n * Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedSchema | Schema} object. This function verifies that the input is a non-null object whose optional metadata properties (`id`, `title`, `description`, `$schema`, `tsType`, `markdownType`, `type`, `required`, `tags`, `args`, `properties`, and `resolve`) - when present - match the shapes declared by `untyped`'s [`Schema`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface.\n *\n * @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) schema.\n * @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) schema, otherwise `false`.\n */\nexport function isUntypedSchema(input: unknown): input is UntypedSchema {\n if (!isSetObject(input)) {\n return false;\n }\n\n const schema = input as Record<string, unknown>;\n if (\"id\" in schema && !isSetString(schema.id)) {\n return false;\n }\n if (\"title\" in schema && !isSetString(schema.title)) {\n return false;\n }\n if (\"description\" in schema && !isSetString(schema.description)) {\n return false;\n }\n if (\"$schema\" in schema && !isSetString(schema.$schema)) {\n return false;\n }\n if (\"tsType\" in schema && !isSetString(schema.tsType)) {\n return false;\n }\n if (\"markdownType\" in schema && !isSetString(schema.markdownType)) {\n return false;\n }\n if (\n \"type\" in schema &&\n !isSetString(schema.type) &&\n !Array.isArray(schema.type)\n ) {\n return false;\n }\n if (\"required\" in schema && !Array.isArray(schema.required)) {\n return false;\n }\n if (\"tags\" in schema && !Array.isArray(schema.tags)) {\n return false;\n }\n if (\"args\" in schema && !Array.isArray(schema.args)) {\n return false;\n }\n if (\"properties\" in schema && !isSetObject(schema.properties)) {\n return false;\n }\n if (\"resolve\" in schema && !isFunction(schema.resolve)) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Type guard to check if a given input is an [untyped](https://github.com/unjs/untyped) {@link UntypedInputObject | InputObject}. This function verifies that the input is a non-null object and that any `untyped`-reserved `$`-prefixed properties have the expected shape: `$schema` (when present) must satisfy {@link isUntypedSchema} and `$resolve` (when present) must be a function. See `untyped`'s [`InputObject`](https://github.com/unjs/untyped/blob/main/src/types.ts) interface for the canonical definition.\n *\n * @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) input object.\n * @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) input object, otherwise `false`.\n */\nexport function isUntypedInput(input: unknown): input is UntypedInputObject {\n if (!isSetObject(input)) {\n return false;\n }\n\n const inputObject = input as Record<string, unknown>;\n if (\"$schema\" in inputObject && !isUntypedSchema(inputObject.$schema)) {\n return false;\n }\n if (\"$resolve\" in inputObject && !isFunction(inputObject.$resolve)) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Type guard to check if a given input is a {@link Schema} object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants (\"json-schema\", \"standard-schema\", \"zod3\", or \"reflection\"). If all these conditions are met, the function returns `true`, indicating that the input is a valid {@link Schema}; otherwise, it returns `false`.\n *\n * @param input - The input to check for being a {@link Schema}.\n * @returns `true` if the input is a {@link Schema}, otherwise `false`.\n */\nexport function isSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(\n input: unknown\n): input is Schema<TMetadata> {\n return (\n isSetObject(input) &&\n \"schema\" in input &&\n isJTDSchema(input.schema) &&\n \"input\" in input &&\n isSetObject(input.input) &&\n \"variant\" in input &&\n isSetString(input.variant)\n );\n}\n\n/**\n * Type guard to check if a given input is a {@link ExtractedSchema} object. This function verifies that the input is a non-null object, contains a `schema` property that is a JSON Schema (draft-07) object, contains an `input` property that is a non-null object, and has a `variant` property that is one of the allowed schema variants (\"json-schema\", \"standard-schema\", \"zod3\", or \"reflection\"). If all these conditions are met, the function returns `true`, indicating that the input is a valid {@link ExtractedSchema}; otherwise, it returns `false`.\n *\n * @param input - The input to check for being a {@link ExtractedSchema}.\n * @returns `true` if the input is a {@link ExtractedSchema}, otherwise `false`.\n */\nexport function isExtractedSchema<\n TMetadata extends SchemaMetadata = SchemaMetadata\n>(input: unknown): input is ExtractedSchema<TMetadata> {\n return (\n isSchema<TMetadata>(input) &&\n \"source\" in input &&\n isSetObject(input.source) &&\n \"schema\" in input.source &&\n isJTDSchema(input.source.schema) &&\n \"variant\" in input.source &&\n isSetString(input.source.variant)\n );\n}\n\n/**\n * Type guard to check if a given input is a {@link ObjectSchema} object. This function verifies that the input is a {@link Schema} object and that its `schema` property has either a `properties` property that is an object or an `optionalProperties` property that is an object (as per the structure of JTD schema objects). If these conditions are met, the function returns `true`, indicating that the input is a valid {@link ObjectSchema}; otherwise, it returns `false`.\n *\n * @param input - The input to check for being a {@link ObjectSchema}.\n * @returns `true` if the input is a {@link ObjectSchema}, otherwise `false`.\n */\nexport function isObjectSchema<\n TMetadata extends SchemaMetadata = SchemaMetadata\n>(input: unknown): input is ObjectSchema<TMetadata> {\n return (\n isSchema<TMetadata>(input) && isJTDSchemaObject<TMetadata>(input.schema)\n );\n}\n"],"mappings":";;;;;;;;;AA2CA,SAAgB,kBAEd,OAAyD;CACzD,OACE,YAAY,KAAK,MACf,gBAAgB,SAAS,SAAS,MAAM,UAAU,KACjD,wBAAwB,SAAS,SAAS,MAAM,kBAAkB;AAEzE;;;;;;;AAQA,SAAgB,YACd,OACmC;CACnC,OACE,YAAY,KAAK,MAChB,kBAA6B,KAAK,KACjC,cAAc,SACd,YAAY,SACZ,SAAS,SACT,UAAU,SACV,UAAU,SACT,mBAAmB,SAClB,YAAY,MAAM,aAAa,KAC/B,aAAa,SACb,SAAS,MAAM,OAAO;AAE9B;;;;;;;AAQA,SAAgB,gBAAgB,OAAwC;CACtE,IAAI,CAAC,YAAY,KAAK,GACpB,OAAO;CAGT,MAAM,SAAS;CACf,IAAI,QAAQ,UAAU,CAAC,YAAY,OAAO,EAAE,GAC1C,OAAO;CAET,IAAI,WAAW,UAAU,CAAC,YAAY,OAAO,KAAK,GAChD,OAAO;CAET,IAAI,iBAAiB,UAAU,CAAC,YAAY,OAAO,WAAW,GAC5D,OAAO;CAET,IAAI,aAAa,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kD;CAClD,OACE,SAAoB,KAAK,KAAK,kBAA6B,MAAM,MAAM;AAE3E"}
package/dist/types.d.cts CHANGED
@@ -51,6 +51,10 @@ interface JsonSchemaLike {
51
51
  [key: string]: unknown;
52
52
  }
53
53
  interface SchemaMetadata {
54
+ /**
55
+ * A name for the schema, which can be used by documentation tools or other libraries that support this feature to provide a human-readable name or description for the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
56
+ */
57
+ name?: string;
54
58
  /**
55
59
  * A title for the schema, which can be used by documentation tools or other libraries that support this feature to provide a human-readable name or description for the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
56
60
  */
@@ -68,9 +72,20 @@ interface SchemaMetadata {
68
72
  */
69
73
  examples?: unknown[];
70
74
  /**
71
- * A table name for the schema, which can be used by documentation tools or other libraries that support this feature to provide a human-readable name or description for the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
75
+ * An array of strings indicating groups that the schema belongs to. This property can be used for organizational or categorization purposes in documentation tools or other libraries that support this feature. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
76
+ *
77
+ * @remarks
78
+ * The concept of "groups" is not a standard feature of JSON Schema or JSON Type Definition, but it can be a useful convention for organizing schemas in larger projects or for providing additional metadata that can be leveraged by documentation generators or other tools. The specific meaning and usage of groups would depend on the conventions established within the project or the tools being used.
79
+ */
80
+ groups?: string[];
81
+ /**
82
+ * A visibility level for the schema, which can be used by documentation tools or other libraries that support this feature to determine how the schema should be presented or accessed. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
72
83
  */
73
- table?: string;
84
+ visibility?: "public" | "protected" | "private";
85
+ /**
86
+ * A resource identifier for the schema, which can be used by documentation tools or other libraries that support this feature to provide a human-readable name or description for the schema. The presence of this property does not affect the validation behavior of the schema itself, but it can provide additional context or information about the schema when used in conjunction with compatible tools.
87
+ */
88
+ resourceId?: string;
74
89
  /**
75
90
  * An indicator specifying if the field should be marked as hidden or not.
76
91
  */
@@ -107,6 +122,15 @@ interface SchemaMetadata {
107
122
  union?: JsonSchemaLike[];
108
123
  [key: string]: unknown | undefined;
109
124
  }
125
+ type JTDSchemaObjectForm<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> = {
126
+ properties: Record<string, JTDSchemaType<TMetadata>>;
127
+ optionalProperties?: Record<string, JTDSchemaType<TMetadata>>;
128
+ additionalProperties?: boolean;
129
+ } | {
130
+ properties?: Record<string, JTDSchemaType<TMetadata>>;
131
+ optionalProperties: Record<string, JTDSchemaType<TMetadata>>;
132
+ additionalProperties?: boolean;
133
+ };
110
134
  type JTDSchemaType<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> = ({
111
135
  ref: string;
112
136
  } | {
@@ -117,15 +141,7 @@ type JTDSchemaType<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMet
117
141
  elements: JTDSchemaType<TMetadata>;
118
142
  } | {
119
143
  values: JTDSchemaType<TMetadata>;
120
- } | {
121
- properties: Record<string, JTDSchemaType<TMetadata>>;
122
- optionalProperties?: Record<string, JTDSchemaType<TMetadata>>;
123
- additionalProperties?: boolean;
124
- } | {
125
- properties?: Record<string, JTDSchemaType<TMetadata>>;
126
- optionalProperties: Record<string, JTDSchemaType<TMetadata>>;
127
- additionalProperties?: boolean;
128
- } | {
144
+ } | JTDSchemaObjectForm<TMetadata> | {
129
145
  discriminator: string;
130
146
  mapping: Record<string, JTDSchemaType<TMetadata>>;
131
147
  } | {}) & {
@@ -133,16 +149,30 @@ type JTDSchemaType<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMet
133
149
  metadata?: TMetadata;
134
150
  definitions?: Record<string, JTDSchemaType<TMetadata>>;
135
151
  };
152
+ type JTDSchemaObjectType<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> = JTDSchemaObjectForm<TMetadata> & {
153
+ nullable?: boolean;
154
+ metadata?: TMetadata;
155
+ definitions?: Record<string, JTDSchemaType<TMetadata>>;
156
+ };
136
157
  type SchemaSourceVariant = "standard-schema" | "jtd-schema" | "json-schema" | "zod3" | "untyped" | "reflection";
137
158
  type SchemaInputVariant = SchemaSourceVariant | "type-definition";
138
159
  type SchemaSourceInput<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> = StandardJSONSchemaV1 | JTDSchemaType<TMetadata> | JsonSchemaType | z3.ZodTypeAny | UntypedInputObject | UntypedSchema | Type;
139
160
  type TypeDefinitionReference = TypeDefinition | string;
140
161
  type SchemaInput = SchemaSourceInput | Schema | TypeDefinitionReference;
162
+ /**
163
+ * A type representing a schema that has been extracted from a source input. This type includes a `hash` property, which is a string that uniquely identifies the schema based on its content and source; a `variant` property, which indicates the format or type of the original input from which the schema was extracted (e.g., "jtd-schema", "json-schema", "zod3", "untyped", "reflection", or "type-definition"); and a `schema` property, which is the extracted schema itself represented as a JSON Type Definition (JTD) schema object with optional metadata. This type can be used to represent schemas in a standardized format regardless of their original source or representation.
164
+ */
141
165
  interface Schema<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> {
142
166
  hash: string;
143
167
  variant: SchemaInputVariant;
144
168
  schema: JTDSchemaType<TMetadata>;
145
169
  }
170
+ /**
171
+ * A type representing a JSON Type Definition (JTD) schema that specifically has an object form (i.e., it has either a `properties` property that is an object or an `optionalProperties` property that is an object, as per the structure of JTD schema objects). This type extends the base {@link Schema} type and narrows the `schema` property to be a `JTDSchemaObjectType`, which ensures that any schema of this type will have the structure of a JTD object schema.
172
+ */
173
+ interface ObjectSchema<TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>> extends Schema<TMetadata> {
174
+ schema: JTDSchemaObjectType<TMetadata>;
175
+ }
146
176
  interface BaseSchemaSource {
147
177
  hash: string;
148
178
  variant: SchemaSourceVariant;
@@ -177,5 +207,5 @@ interface ExtractedSchema<TMetadata extends Partial<SchemaMetadata> = Partial<Sc
177
207
  source: SchemaSource;
178
208
  }
179
209
  //#endregion
180
- export { BaseSchemaSource, ExtractedSchema, JTDNumberType, JTDSchemaSchemaSource, JTDSchemaType, JTDStringType, JTDType, JsonSchemaLike, JsonSchemaSchemaSource, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, Zod3SchemaSource };
210
+ export { BaseSchemaSource, ExtractedSchema, JTDNumberType, JTDSchemaObjectForm, JTDSchemaObjectType, JTDSchemaSchemaSource, JTDSchemaType, JTDStringType, JTDType, JsonSchemaLike, JsonSchemaSchemaSource, ObjectSchema, ReflectionSchemaSource, Schema, SchemaInput, SchemaInputVariant, SchemaMetadata, SchemaSource, SchemaSourceInput, SchemaSourceVariant, StandardSchemaSchemaSource, TypeDefinitionReference, UntypedInputObject, UntypedSchema, UntypedSchemaSource, Zod3SchemaSource };
181
211
  //# sourceMappingURL=types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;KAyBY,kBAAA,GAAqB,WAAA;AAAA,KACrB,aAAA,GAAgB,QAAA;AAD5B;;;AAAA,KAMY,aAAA;;AALZ;;KAkBY,aAAA;;;AAbZ;KAkBY,OAAA,GAAU,aAAA,GAAgB,aAAA;AAAA,UAErB,cAAA;EACf,IAAA;EACA,MAAA;EACA,IAAA;EACA,KAAA;EACA,KAAA,GAAQ,cAAA,GAAiB,cAAA;EACzB,UAAA,GAAa,MAAA,SAAe,cAAA;EAC5B,iBAAA,GAAoB,MAAA,SAAe,cAAA;EACnC,oBAAA,aAAiC,cAAA;EACjC,QAAA;EACA,KAAA,GAAQ,cAAA;EACR,KAAA,GAAQ,cAAA;EACR,KAAA,GAAQ,cAAA;EACR,IAAA;EACA,W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