@powerlines/schema 0.11.28 → 0.11.38

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 (82) hide show
  1. package/dist/bundle.cjs +34 -20
  2. package/dist/bundle.d.cts +3 -3
  3. package/dist/bundle.d.cts.map +1 -1
  4. package/dist/bundle.d.mts +3 -3
  5. package/dist/bundle.d.mts.map +1 -1
  6. package/dist/bundle.mjs +35 -21
  7. package/dist/bundle.mjs.map +1 -1
  8. package/dist/codegen.cjs +55 -8
  9. package/dist/codegen.d.cts +12 -6
  10. package/dist/codegen.d.cts.map +1 -1
  11. package/dist/codegen.d.mts +12 -6
  12. package/dist/codegen.d.mts.map +1 -1
  13. package/dist/codegen.mjs +52 -8
  14. package/dist/codegen.mjs.map +1 -1
  15. package/dist/constants.cjs +42 -0
  16. package/dist/constants.d.cts +15 -0
  17. package/dist/constants.d.cts.map +1 -0
  18. package/dist/constants.d.mts +15 -0
  19. package/dist/constants.d.mts.map +1 -0
  20. package/dist/constants.mjs +39 -0
  21. package/dist/constants.mjs.map +1 -0
  22. package/dist/extract.cjs +144 -95
  23. package/dist/extract.d.cts +34 -69
  24. package/dist/extract.d.cts.map +1 -1
  25. package/dist/extract.d.mts +34 -69
  26. package/dist/extract.d.mts.map +1 -1
  27. package/dist/extract.mjs +144 -95
  28. package/dist/extract.mjs.map +1 -1
  29. package/dist/helpers.cjs +87 -0
  30. package/dist/helpers.d.cts +48 -0
  31. package/dist/helpers.d.cts.map +1 -0
  32. package/dist/helpers.d.mts +48 -0
  33. package/dist/helpers.d.mts.map +1 -0
  34. package/dist/helpers.mjs +84 -0
  35. package/dist/helpers.mjs.map +1 -0
  36. package/dist/index.cjs +29 -5
  37. package/dist/index.d.cts +8 -5
  38. package/dist/index.d.mts +8 -5
  39. package/dist/index.mjs +7 -4
  40. package/dist/metadata.cjs +80 -0
  41. package/dist/metadata.d.cts +52 -0
  42. package/dist/metadata.d.cts.map +1 -0
  43. package/dist/metadata.d.mts +52 -0
  44. package/dist/metadata.d.mts.map +1 -0
  45. package/dist/metadata.mjs +76 -0
  46. package/dist/metadata.mjs.map +1 -0
  47. package/dist/persistence.cjs +75 -0
  48. package/dist/persistence.d.cts +47 -0
  49. package/dist/persistence.d.cts.map +1 -0
  50. package/dist/persistence.d.mts +47 -0
  51. package/dist/persistence.d.mts.map +1 -0
  52. package/dist/persistence.mjs +71 -0
  53. package/dist/persistence.mjs.map +1 -0
  54. package/dist/reflection.cjs +292 -299
  55. package/dist/reflection.d.cts +3 -16
  56. package/dist/reflection.d.cts.map +1 -1
  57. package/dist/reflection.d.mts +3 -16
  58. package/dist/reflection.d.mts.map +1 -1
  59. package/dist/reflection.mjs +291 -299
  60. package/dist/reflection.mjs.map +1 -1
  61. package/dist/resolve.cjs +7 -7
  62. package/dist/resolve.mjs +7 -7
  63. package/dist/resolve.mjs.map +1 -1
  64. package/dist/type-checks.cjs +126 -25
  65. package/dist/type-checks.d.cts +45 -23
  66. package/dist/type-checks.d.cts.map +1 -1
  67. package/dist/type-checks.d.mts +45 -23
  68. package/dist/type-checks.d.mts.map +1 -1
  69. package/dist/type-checks.mjs +125 -25
  70. package/dist/type-checks.mjs.map +1 -1
  71. package/dist/types.d.cts +237 -95
  72. package/dist/types.d.cts.map +1 -1
  73. package/dist/types.d.mts +237 -95
  74. package/dist/types.d.mts.map +1 -1
  75. package/package.json +24 -8
  76. package/dist/jtd.cjs +0 -385
  77. package/dist/jtd.d.cts +0 -15
  78. package/dist/jtd.d.cts.map +0 -1
  79. package/dist/jtd.d.mts +0 -15
  80. package/dist/jtd.d.mts.map +0 -1
  81. package/dist/jtd.mjs +0 -384
  82. package/dist/jtd.mjs.map +0 -1
@@ -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;EAC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CACzD,KAAI,mBAAmB,SAAS,KAAK,eAAe,gBAAgB;EAClE,MAAM,cAAc,gBAA2B,mBAAmB,KAAK;AACvE,MAAI,YACF,QAAO;GACL,GAAG;GACH,QAAQ;GACR,sBAAsB;GACvB;QAEE;EACL,MAAM,WAAW,gBAA2B,mBAAmB,KAAK;AACpE,MAAI,CAAC,SACH;AAGF,WAAS,WAAY,SAAS,YAAY,EAAE;AAC5C,WAAS,SAAS,aAAa,mBAAmB,YAAY;AAC9D,WAAS,SAAS,YAAY,mBAAmB,WAAW;AAC5D,WAAS,SAAS,aAAa,mBAAmB,YAAY;AAC9D,WAAS,SAAS,YAAY,mBAAmB,WAAW;AAC5D,WAAS,SAAS,eAAe,mBAAmB,cAAc;AAClE,WAAS,SAAS,WAAW,mBAAmB,UAAU;AAE1D,MAAI,mBAAmB,YAAY,CACjC,UAAS,SAAS,UAAU,mBAAmB,iBAAiB;AAElE,MAAI,YAAY,mBAAmB,gBAAgB,CAAC,CAClD,UAAS,SAAS,cAAc,mBAAmB,gBAAgB;AAErE,MAAI,WAAW,mBAAmB,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 {\n isSetArray,\n isSetObject,\n isSetString,\n isUndefined\n} from \"@stryke/type-checks\";\nimport defu from \"defu\";\nimport {\n isJsonSchema,\n isJsonSchemaObject,\n isNullOnlyJsonSchema\n} from \"./type-checks\";\nimport {\n JsonSchema,\n JsonSchemaLike,\n JsonSchemaObject,\n JsonSchemaProperty\n} from \"./types\";\n\n/**\n * Maps a Deepkit numeric `brand` to JSON Schema `type` and `format`.\n *\n * @remarks\n * This function takes a `TypeNumberBrand` (which represents specific numeric types in Deepkit, such as `integer`, `float`, `int8`, etc.) and returns a corresponding JSON Schema fragment that includes the appropriate `type`, `format`, and any relevant keywords (like `multipleOf` for integers). If the brand is not recognized, it defaults to a generic JSON Schema for numbers.\n *\n * @param brand - The Deepkit numeric brand to convert.\n * @return A JSON Schema fragment representing the numeric type corresponding to the provided brand.\n */\nfunction numberBrandToJsonSchema(\n brand: TypeNumberBrand | undefined\n): JsonSchema<number> {\n switch (brand) {\n case TypeNumberBrand.integer:\n return {\n type: \"integer\",\n format: \"int32\",\n multipleOf: 1\n };\n case TypeNumberBrand.int8:\n return { type: \"integer\", format: \"int8\", multipleOf: 1 };\n case TypeNumberBrand.uint8:\n return { type: \"integer\", format: \"uint8\", multipleOf: 1 };\n case TypeNumberBrand.int16:\n return { type: \"integer\", format: \"int16\", multipleOf: 1 };\n case TypeNumberBrand.uint16:\n return { type: \"integer\", format: \"uint16\", multipleOf: 1 };\n case TypeNumberBrand.int32:\n return { type: \"integer\", format: \"int32\", multipleOf: 1 };\n case TypeNumberBrand.uint32:\n return { type: \"integer\", format: \"uint32\", multipleOf: 1 };\n case TypeNumberBrand.float:\n case TypeNumberBrand.float32:\n return { type: \"number\", format: \"float\" };\n case TypeNumberBrand.float64:\n return { type: \"number\", format: \"double\" };\n case undefined:\n default:\n return { type: \"number\" };\n }\n}\n\nfunction withReflectionTags<T = unknown>(\n reflection: Type,\n schema: Partial<JsonSchema<T>>\n): JsonSchema<T> {\n if (!isSetObject((reflection as { tags?: TagsReflection })?.tags)) {\n return schema as JsonSchema<T>;\n }\n\n const tags = (reflection as { tags: TagsReflection }).tags;\n if (isSetString(tags.title)) {\n schema.title = tags.title;\n }\n if (isSetArray(tags.alias)) {\n schema.alias = tags.alias;\n }\n if (!isUndefined(tags.hidden)) {\n schema.hidden = tags.hidden;\n }\n if (!isUndefined(tags.ignore)) {\n schema.ignore = tags.ignore;\n }\n if (!isUndefined(tags.internal)) {\n schema.internal = tags.internal;\n }\n if (!isUndefined(tags.runtime)) {\n schema.runtime = tags.runtime;\n }\n if (!isUndefined(tags.readonly)) {\n schema.readOnly = tags.readonly;\n }\n\n return schema as JsonSchema<T>;\n}\n\nfunction withNullable<T = unknown>(\n schema: JsonSchema<T>,\n nullable: boolean\n): JsonSchema<T> {\n if (!nullable) {\n return schema;\n }\n\n const types = Array.isArray(schema.type)\n ? [...schema.type]\n : schema.type\n ? [schema.type]\n : [];\n if (!types.includes(\"null\")) {\n types.push(\"null\");\n }\n\n return {\n ...schema,\n type: types.length === 1 ? types[0] : types\n } as JsonSchema<T>;\n}\n\n/**\n * Converts a Deepkit type reflection into a JSON Schema (draft-07) fragment.\n */\nexport function reflectionToJsonSchema<T = unknown>(\n reflection: Type\n): JsonSchema<T> | undefined {\n return reflectionToJsonSchemaInner<T>(reflection);\n}\n\nfunction reflectionToJsonSchemaInner<T = unknown>(\n reflection: Type\n): JsonSchema<T> | undefined {\n switch (reflection.kind) {\n case ReflectionKind.any:\n case ReflectionKind.unknown:\n case ReflectionKind.void:\n case ReflectionKind.object:\n return withReflectionTags<T>(reflection, { name: reflection.typeName });\n case ReflectionKind.never:\n return undefined;\n case ReflectionKind.undefined:\n case ReflectionKind.null:\n return withReflectionTags<T>(reflection, {\n type: \"null\",\n name: reflection.typeName,\n nullable: true\n });\n case ReflectionKind.string:\n return withReflectionTags<T>(reflection, {\n type: \"string\",\n name: reflection.typeName\n });\n case ReflectionKind.boolean:\n return withReflectionTags<T>(reflection, {\n type: \"boolean\",\n name: reflection.typeName\n });\n case ReflectionKind.number: {\n const numeric = numberBrandToJsonSchema(reflection.brand);\n\n return withReflectionTags<T>(reflection, numeric as JsonSchema<T>);\n }\n case ReflectionKind.bigint:\n return withReflectionTags<T>(reflection, {\n type: \"integer\",\n name: reflection.typeName,\n format: \"int64\",\n multipleOf: 1\n });\n case ReflectionKind.regexp:\n return withReflectionTags<T>(reflection, {\n type: \"string\",\n name: reflection.typeName,\n format: \"regex\",\n contentMediaType: \"text/regex\"\n });\n case ReflectionKind.literal: {\n const { literal } = reflection;\n if (\n typeof literal === \"string\" ||\n typeof literal === \"number\" ||\n typeof literal === \"boolean\"\n ) {\n return withReflectionTags<T>(reflection, {\n type: typeof literal,\n name: reflection.typeName,\n const: literal\n });\n }\n if (typeof literal === \"bigint\") {\n return withReflectionTags<T>(reflection, {\n type: \"integer\",\n name: reflection.typeName,\n format: \"int64\",\n multipleOf: 1,\n const: String(literal)\n });\n }\n if (literal instanceof RegExp) {\n return withReflectionTags<T>(reflection, {\n type: \"string\",\n name: reflection.typeName,\n format: \"regex\",\n const: literal.source\n });\n }\n return withReflectionTags<T>(reflection, {\n name: reflection.typeName\n });\n }\n case ReflectionKind.templateLiteral:\n return withReflectionTags<T>(reflection, { type: \"string\" });\n case ReflectionKind.enum: {\n const values = reflection.values.filter(\n value =>\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\"\n );\n if (values.length === 0) {\n return withReflectionTags<T>(reflection, {\n name: reflection.typeName,\n description: reflection.description\n });\n }\n return withReflectionTags<T>(reflection, {\n name: reflection.typeName,\n description: reflection.description,\n enum: values\n });\n }\n case ReflectionKind.array: {\n const items = reflectionToJsonSchemaInner<T>(reflection.type);\n\n return withReflectionTags<T>(reflection, {\n type: \"array\",\n name: reflection.typeName,\n items: items ?? {}\n });\n }\n case ReflectionKind.tuple: {\n const items = reflection.types\n .map(member => reflectionToJsonSchemaInner<T>(member.type))\n .filter((item): item is JsonSchema => item !== undefined);\n if (items.length <= 1) {\n return withReflectionTags<T>(reflection, {\n type: \"array\",\n name: reflection.typeName,\n items: items[0] ?? {}\n });\n }\n return withReflectionTags<T>(reflection, {\n type: \"array\",\n name: reflection.typeName,\n items,\n minItems: items.length,\n maxItems: items.length\n });\n }\n case ReflectionKind.union: {\n const branches = reflection.types\n .map(inner => reflectionToJsonSchemaInner<T>(inner))\n .filter(isJsonSchema) as JsonSchema<T>[];\n const nullable = reflection.types.some(\n inner =>\n inner.kind === ReflectionKind.null ||\n inner.kind === ReflectionKind.undefined\n );\n const nonNull = branches.filter(\n branch => branch.type !== \"null\" && !isNullOnlyJsonSchema(branch)\n );\n\n if (nonNull.length === 0) {\n return withReflectionTags<T>(reflection, {\n type: \"null\",\n nullable: true\n });\n }\n\n if (nonNull.length === 1) {\n return withNullable(\n withReflectionTags<T>(reflection, {\n name: reflection.typeName,\n ...nonNull[0]\n }),\n nullable\n );\n }\n\n const enumValues = nonNull\n .map(branch => branch.const)\n .filter(value => value !== undefined);\n if (enumValues.length === nonNull.length) {\n return withNullable(\n withReflectionTags<T>(reflection, {\n name: reflection.typeName,\n enum: enumValues\n }),\n nullable\n );\n }\n\n const discriminator = tryReflectionDiscriminator<T>(reflection.types);\n if (discriminator) {\n return withNullable(\n withReflectionTags<T>(reflection, {\n name: reflection.typeName,\n ...discriminator\n }),\n nullable\n );\n }\n\n return withNullable(\n withReflectionTags<T>(reflection, {\n name: reflection.typeName,\n anyOf: nonNull\n }),\n nullable\n );\n }\n case ReflectionKind.intersection: {\n const members = reflection.types\n .map(inner => reflectionToJsonSchemaInner<T>(inner))\n .filter((item): item is JsonSchema => item !== undefined);\n if (members.length === 0) {\n return undefined;\n }\n if (members.length === 1) {\n return withReflectionTags<T>(reflection, {\n name: reflection.typeName,\n ...members[0]\n });\n }\n if (members.every(isJsonSchemaObject)) {\n return withReflectionTags<T>(reflection, {\n name: reflection.typeName,\n ...mergeObjectSchemas(members)\n });\n }\n return withReflectionTags<T>(reflection, {\n name: reflection.typeName,\n allOf: members\n });\n }\n case ReflectionKind.promise:\n return reflectionToJsonSchemaInner<T>(reflection.type);\n case ReflectionKind.objectLiteral:\n return objectReflectionToJsonSchema(reflection);\n case ReflectionKind.class: {\n const classType = reflection.classType as { name?: string } | undefined;\n const className = classType?.name;\n switch (className) {\n case \"Date\":\n return withReflectionTags<T>(reflection, {\n type: \"string\",\n format: \"date-time\"\n });\n case \"RegExp\":\n return withReflectionTags<T>(reflection, {\n type: \"string\",\n format: \"regex\"\n });\n case \"URL\":\n return withReflectionTags<T>(reflection, {\n type: \"string\",\n format: \"uri\"\n });\n case \"Set\": {\n const itemType = reflection.arguments?.[0];\n const items = itemType\n ? reflectionToJsonSchemaInner<T>(itemType)\n : undefined;\n\n return withReflectionTags<T>(reflection, {\n type: \"array\",\n items: items ?? {},\n uniqueItems: true\n });\n }\n case \"Map\": {\n const valueType = reflection.arguments?.[1];\n const values = valueType\n ? reflectionToJsonSchemaInner<T>(valueType)\n : undefined;\n\n return withReflectionTags<T>(reflection, {\n type: \"object\",\n additionalProperties: values ?? true\n });\n }\n case \"Uint8Array\":\n case \"Uint8ClampedArray\":\n case \"Uint16Array\":\n case \"Uint32Array\":\n case \"Int8Array\":\n case \"Int16Array\":\n case \"Int32Array\":\n case \"Float32Array\":\n case \"Float64Array\":\n case \"BigInt64Array\":\n case \"BigUint64Array\":\n return withReflectionTags<T>(reflection, {\n type: \"string\",\n format: \"byte\",\n contentEncoding: \"base64\"\n });\n case undefined:\n default:\n return withReflectionTags<T>(reflection, {\n name: reflection.typeName,\n description: reflection.description,\n ...objectReflectionToJsonSchema(reflection)\n });\n }\n }\n case ReflectionKind.symbol:\n case ReflectionKind.property:\n case ReflectionKind.method:\n case ReflectionKind.function:\n case ReflectionKind.parameter:\n case ReflectionKind.typeParameter:\n case ReflectionKind.tupleMember:\n case ReflectionKind.enumMember:\n case ReflectionKind.rest:\n case ReflectionKind.indexSignature:\n case ReflectionKind.propertySignature:\n case ReflectionKind.methodSignature:\n case ReflectionKind.infer:\n case ReflectionKind.callSignature:\n default:\n return undefined;\n }\n}\n\nfunction mergeObjectSchemas<T = unknown>(\n schemas: JsonSchema<T>[]\n): JsonSchema<T> {\n const merged: JsonSchema<T> = {\n type: \"object\",\n properties: {},\n required: []\n };\n\n for (const schema of schemas) {\n if (schema.properties) {\n merged.properties = defu(merged.properties, schema.properties);\n }\n if (schema.required) {\n merged.required = Array.from(\n new Set([...(merged.required ?? []), ...schema.required])\n );\n }\n if (schema.additionalProperties !== undefined) {\n merged.additionalProperties = schema.additionalProperties;\n }\n }\n\n if ((merged.required?.length ?? 0) === 0) {\n delete merged.required;\n }\n\n return merged;\n}\n\nfunction tryReflectionDiscriminator<T = unknown>(\n types: readonly Type[]\n): JsonSchema<T> | undefined {\n const nonNullTypes = types.filter(\n t => t.kind !== ReflectionKind.null && t.kind !== ReflectionKind.undefined\n );\n const objectBranches: Array<TypeObjectLiteral | TypeClass> =\n nonNullTypes.filter(\n t =>\n t.kind === ReflectionKind.objectLiteral ||\n t.kind === ReflectionKind.class\n );\n\n if (\n objectBranches.length < 2 ||\n objectBranches.length !== nonNullTypes.length\n ) {\n return undefined;\n }\n\n let tagKey: string | undefined;\n const branches: JsonSchemaLike[] = [];\n\n for (const branch of objectBranches) {\n const literalProps: Array<{ name: string; literal: string }> = [];\n for (const member of branch.types) {\n if (\n (member.kind === ReflectionKind.property ||\n member.kind === ReflectionKind.propertySignature) &&\n typeof member.name === \"string\" &&\n member.type.kind === ReflectionKind.literal &&\n typeof (member.type as { literal?: unknown }).literal === \"string\"\n ) {\n literalProps.push({\n name: member.name,\n literal: (member.type as { literal: string }).literal\n });\n }\n }\n\n if (literalProps.length === 0) {\n return undefined;\n }\n\n const first = literalProps[0]!;\n if (!tagKey) {\n tagKey = first.name;\n } else if (tagKey !== first.name) {\n return undefined;\n }\n\n const filteredBranch = {\n ...branch,\n types: branch.types.filter(\n member =>\n !(\n (member.kind === ReflectionKind.property ||\n member.kind === ReflectionKind.propertySignature) &&\n member.name === tagKey\n )\n )\n } as TypeObjectLiteral | TypeClass;\n\n const body = objectReflectionToJsonSchema(filteredBranch);\n if (!body || !isJsonSchemaObject(body)) {\n return undefined;\n }\n\n branches.push({\n type: \"object\",\n properties: {\n [tagKey]: { const: first.literal },\n ...(body.properties ?? {})\n },\n required: [tagKey, ...(body.required ?? [])],\n additionalProperties: body.additionalProperties ?? false\n } as JsonSchemaLike);\n }\n\n if (!tagKey) {\n return undefined;\n }\n\n return {\n oneOf: branches,\n discriminator: { propertyName: tagKey }\n } as JsonSchema<T>;\n}\n\nfunction objectReflectionToJsonSchema<\n T extends Record<string, any> = Record<string, any>\n>(type: TypeObjectLiteral | TypeClass): JsonSchema<T> {\n const reflection = ReflectionClass.from(type);\n\n const schema: JsonSchemaObject<T> = {\n type: \"object\",\n name: reflection.getName(),\n description: reflection.getDescription(),\n properties: {},\n required: [],\n readOnly: reflection.isReadonly(),\n ignore: reflection.isIgnored(),\n internal: reflection.isInternal(),\n runtime: reflection.isRuntime(),\n hidden: reflection.isHidden(),\n primaryKey: reflection\n .getPrimaries()\n .map(primary => primary.getNameAsString()),\n ...(isSetString(reflection.databaseSchemaName)\n ? { databaseSchemaName: reflection.databaseSchemaName }\n : {}),\n ...(isSetString(reflection.getName())\n ? { name: reflection.getName() }\n : {}),\n ...(isSetString(reflection.getDescription())\n ? { description: reflection.getDescription() }\n : {}),\n ...(isSetArray(reflection.getAlias())\n ? { alias: reflection.getAlias() }\n : {}),\n ...(isSetString(reflection.getTitle())\n ? { title: reflection.getTitle() }\n : {})\n };\n\n for (const propertyReflection of reflection.getProperties()) {\n if (propertyReflection.getKind() === ReflectionKind.indexSignature) {\n schema.additionalProperties =\n reflectionToJsonSchemaInner(propertyReflection.type) ?? true;\n continue;\n }\n\n let property = reflectionToJsonSchemaInner<any>(propertyReflection.type);\n if (!property) {\n continue;\n }\n\n property = {\n ...property,\n name: propertyReflection.getNameAsString(),\n description: propertyReflection.getDescription(),\n readOnly: propertyReflection.isReadonly(),\n ignore: propertyReflection.isIgnored(),\n internal: propertyReflection.isInternal(),\n runtime: propertyReflection.isRuntime(),\n hidden: propertyReflection.isHidden(),\n visibility: propertyReflection.isPublic()\n ? \"public\"\n : propertyReflection.isProtected()\n ? \"protected\"\n : propertyReflection.isPrivate()\n ? \"private\"\n : undefined,\n ...(propertyReflection.hasDefault()\n ? { default: propertyReflection.getDefaultValue() }\n : {}),\n ...(isSetArray(propertyReflection.getGroups())\n ? { tags: propertyReflection.getGroups() }\n : {}),\n ...(isSetArray(propertyReflection.getAlias())\n ? { alias: propertyReflection.getAlias() }\n : {}),\n ...(isSetString(propertyReflection.getTitle())\n ? { title: propertyReflection.getTitle() }\n : {})\n };\n\n if (propertyReflection.isNullable()) {\n property = withNullable(property, true);\n }\n\n schema.properties ??= {};\n schema.properties[propertyReflection.name] =\n property as JsonSchemaProperty<T>;\n if (!propertyReflection.isOptional()) {\n schema.required ??= [];\n schema.required.push(propertyReflection.name);\n }\n }\n\n return schema;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyDA,SAAS,wBACP,OACoB;CACpB,QAAQ,OAAR;EACE,KAAK,gBAAgB,SACnB,OAAO;GACL,MAAM;GACN,QAAQ;GACR,YAAY;EACd;EACF,KAAK,gBAAgB,MACnB,OAAO;GAAE,MAAM;GAAW,QAAQ;GAAQ,YAAY;EAAE;EAC1D,KAAK,gBAAgB,OACnB,OAAO;GAAE,MAAM;GAAW,QAAQ;GAAS,YAAY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ime = require('./_virtual/_rolldown/runtime.cjs');
3
3
  const require_bundle = require('./bundle.cjs');
4
4
  let defu = require("defu");
5
5
  defu = require_runtime.__toESM(defu, 1);
6
- let _powerlines_deepkit_esbuild_plugin = require("@powerlines/deepkit/esbuild-plugin");
6
+ let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
7
7
  let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
8
+ let _powerlines_deepkit_esbuild_plugin = require("@powerlines/deepkit/esbuild-plugin");
8
9
  let _stryke_convert_parse_type_definition = require("@stryke/convert/parse-type-definition");
9
10
  let _stryke_path_find = require("@stryke/path/find");
10
- let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
11
11
 
12
12
  //#region src/resolve.ts
13
13
  /**
@@ -25,9 +25,9 @@ async function resolveModule(context, type, overrides) {
25
25
  const result = await require_bundle.bundle(context, typeDefinition.file, overrides);
26
26
  let resolved;
27
27
  try {
28
- resolved = await context.resolver.evalModule(result.text, {
29
- filename: result.path,
30
- ext: (0, _stryke_path_find.findFileDotExtension)(result.path)
28
+ resolved = await context.resolver.evalModule(result.code, {
29
+ filename: result.fileName,
30
+ ext: (0, _stryke_path_find.findFileDotExtension)(result.fileName)
31
31
  });
32
32
  } catch (error) {
33
33
  if ((0, _stryke_type_checks_is_set_string.isSetString)(error.message) && new RegExp(`Cannot find module '${context.config.framework?.name || "powerlines"}:.*'`).test(error.message)) {
@@ -35,12 +35,12 @@ async function resolveModule(context, type, overrides) {
35
35
  throw new Error(`The module "${moduleName}" could not be resolved while evaluating "${typeDefinition.file}". It is possible the required built-in modules have not yet been generated. Please check the order of your plugins. ${context.config.logLevel.general === "debug" || context.config.logLevel.general === "trace" ? `
36
36
 
37
37
  Bundle output for module:
38
- ${result.text}` : ""}`);
38
+ ${result.code}` : ""}`);
39
39
  }
40
40
  throw new Error(`Failed to evaluate the bundled module for "${typeDefinition.file}". Error: ${error.message}${context.config.logLevel.general === "debug" || context.config.logLevel.general === "trace" ? `
41
41
 
42
42
  Bundle output for module:
43
- ${result.text}` : ""}`);
43
+ ${result.code}` : ""}`);
44
44
  }
45
45
  return resolved;
46
46
  }
package/dist/resolve.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import { bundle } from "./bundle.mjs";
2
2
  import defu from "defu";
3
- import { esbuildPlugin } from "@powerlines/deepkit/esbuild-plugin";
3
+ import { isSetString } from "@stryke/type-checks/is-set-string";
4
4
  import { reflect } from "@powerlines/deepkit/vendor/type";
5
+ import { esbuildPlugin } from "@powerlines/deepkit/esbuild-plugin";
5
6
  import { parseTypeDefinition } from "@stryke/convert/parse-type-definition";
6
7
  import { findFileDotExtension } from "@stryke/path/find";
7
- import { isSetString } from "@stryke/type-checks/is-set-string";
8
8
 
9
9
  //#region src/resolve.ts
10
10
  /**
@@ -22,9 +22,9 @@ async function resolveModule(context, type, overrides) {
22
22
  const result = await bundle(context, typeDefinition.file, overrides);
23
23
  let resolved;
24
24
  try {
25
- resolved = await context.resolver.evalModule(result.text, {
26
- filename: result.path,
27
- ext: findFileDotExtension(result.path)
25
+ resolved = await context.resolver.evalModule(result.code, {
26
+ filename: result.fileName,
27
+ ext: findFileDotExtension(result.fileName)
28
28
  });
29
29
  } catch (error) {
30
30
  if (isSetString(error.message) && new RegExp(`Cannot find module '${context.config.framework?.name || "powerlines"}:.*'`).test(error.message)) {
@@ -32,12 +32,12 @@ async function resolveModule(context, type, overrides) {
32
32
  throw new Error(`The module "${moduleName}" could not be resolved while evaluating "${typeDefinition.file}". It is possible the required built-in modules have not yet been generated. Please check the order of your plugins. ${context.config.logLevel.general === "debug" || context.config.logLevel.general === "trace" ? `
33
33
 
34
34
  Bundle output for module:
35
- ${result.text}` : ""}`);
35
+ ${result.code}` : ""}`);
36
36
  }
37
37
  throw new Error(`Failed to evaluate the bundled module for "${typeDefinition.file}". Error: ${error.message}${context.config.logLevel.general === "debug" || context.config.logLevel.general === "trace" ? `
38
38
 
39
39
  Bundle output for module:
40
- ${result.text}` : ""}`);
40
+ ${result.code}` : ""}`);
41
41
  }
42
42
  return resolved;
43
43
  }
@@ -1 +1 @@
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 { 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.code, {\n filename: result.fileName,\n ext: findFileDotExtension(result.fileName)\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.code}`\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.code}`\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,QAAQ;EAC3C,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,23 +1,125 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
+ const require_constants = require('./constants.cjs');
3
3
  let _stryke_type_checks = require("@stryke/type-checks");
4
- let _stryke_json_schema = require("@stryke/json/schema");
4
+ let _stryke_json = require("@stryke/json");
5
5
 
6
6
  //#region src/type-checks.ts
7
+ const JSON_SCHEMA_DATA_TYPE_SET = new Set(require_constants.JSON_SCHEMA_DATA_TYPES);
8
+ const isSetNumber = (value) => typeof value === "number" && Number.isFinite(value);
9
+ const isSetBoolean = (value) => typeof value === "boolean";
10
+ const isNonNegativeInteger = (value) => Number.isInteger(value) && value >= 0;
11
+ const isSchemaLikeValue = (value) => (0, _stryke_type_checks.isSetObject)(value) || isSetBoolean(value);
12
+ const isStringArray = (value) => Array.isArray(value) && value.every((item) => (0, _stryke_type_checks.isSetString)(item));
13
+ const isRecordOfStringArrays = (value) => (0, _stryke_type_checks.isSetObject)(value) && Object.values(value).every((item) => isStringArray(item));
14
+ const TYPE_KEYWORD_VALIDATORS = {
15
+ string: {
16
+ minLength: isNonNegativeInteger,
17
+ maxLength: isNonNegativeInteger,
18
+ pattern: _stryke_type_checks.isSetString,
19
+ format: _stryke_type_checks.isSetString,
20
+ contentEncoding: _stryke_type_checks.isSetString,
21
+ contentMediaType: _stryke_type_checks.isSetString
22
+ },
23
+ number: {
24
+ minimum: isSetNumber,
25
+ maximum: isSetNumber,
26
+ exclusiveMinimum: isSetNumber,
27
+ exclusiveMaximum: isSetNumber,
28
+ multipleOf: isSetNumber
29
+ },
30
+ integer: {
31
+ minimum: isSetNumber,
32
+ maximum: isSetNumber,
33
+ exclusiveMinimum: isSetNumber,
34
+ exclusiveMaximum: isSetNumber,
35
+ multipleOf: isSetNumber
36
+ },
37
+ boolean: {},
38
+ array: {
39
+ items: isSchemaLikeValue,
40
+ prefixItems: Array.isArray,
41
+ contains: isSchemaLikeValue,
42
+ minItems: isNonNegativeInteger,
43
+ maxItems: isNonNegativeInteger,
44
+ uniqueItems: isSetBoolean,
45
+ minContains: isNonNegativeInteger,
46
+ maxContains: isNonNegativeInteger
47
+ },
48
+ object: {
49
+ properties: _stryke_type_checks.isSetObject,
50
+ patternProperties: _stryke_type_checks.isSetObject,
51
+ additionalProperties: isSchemaLikeValue,
52
+ required: isStringArray,
53
+ minProperties: isNonNegativeInteger,
54
+ maxProperties: isNonNegativeInteger,
55
+ dependentRequired: isRecordOfStringArrays,
56
+ dependentSchemas: _stryke_type_checks.isSetObject,
57
+ propertyNames: isSchemaLikeValue,
58
+ unevaluatedProperties: isSchemaLikeValue
59
+ },
60
+ null: {}
61
+ };
7
62
  /**
8
- * 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`.
63
+ * Type guard for JSON Schema types.
9
64
  *
10
- * @param input - The input to check for being a [JTD schema](https://tools.ietf.org/html/rfc8927).
11
- * @returns `true` if the input is a [JTD schema](https://tools.ietf.org/html/rfc8927), otherwise `false`.
65
+ * @remarks
66
+ * This function checks if the input is a JSON Schema type, which is defined as having a `type` property or a `$ref` property. This is used to determine if a given input conforms to the structure of a JSON Schema definition that includes type information.
67
+ *
68
+ * @param input - The value to check.
69
+ * @returns True if the input is a JSON Schema type, false otherwise.
70
+ */
71
+ function isJsonSchema(input) {
72
+ if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
73
+ const schema = input;
74
+ if ("$ref" in schema && (0, _stryke_type_checks.isSetString)(schema.$ref)) return true;
75
+ if (!("type" in schema)) return false;
76
+ const schemaTypes = [];
77
+ if ((0, _stryke_type_checks.isSetString)(schema.type)) {
78
+ if (!JSON_SCHEMA_DATA_TYPE_SET.has(schema.type)) return false;
79
+ schemaTypes.push(schema.type);
80
+ } else if (Array.isArray(schema.type) && schema.type.length > 0) {
81
+ if (!schema.type.every((schemaType) => (0, _stryke_type_checks.isSetString)(schemaType) && JSON_SCHEMA_DATA_TYPE_SET.has(schemaType)) || new Set(schema.type).size !== schema.type.length) return false;
82
+ schemaTypes.push(...schema.type);
83
+ } else return false;
84
+ const typeKeywordValidators = schemaTypes.flatMap((schemaType) => Object.entries(TYPE_KEYWORD_VALIDATORS[schemaType]));
85
+ for (const [keyword, validator] of typeKeywordValidators) if (keyword in schema && !validator(schema[keyword])) return false;
86
+ if ("minItems" in schema && "maxItems" in schema && isNonNegativeInteger(schema.minItems) && isNonNegativeInteger(schema.maxItems) && schema.minItems > schema.maxItems) return false;
87
+ if ("minLength" in schema && "maxLength" in schema && isNonNegativeInteger(schema.minLength) && isNonNegativeInteger(schema.maxLength) && schema.minLength > schema.maxLength) return false;
88
+ if ("minProperties" in schema && "maxProperties" in schema && isNonNegativeInteger(schema.minProperties) && isNonNegativeInteger(schema.maxProperties) && schema.minProperties > schema.maxProperties) return false;
89
+ return true;
90
+ }
91
+ /**
92
+ * Type guard for JSON Schema object forms.
93
+ *
94
+ * @remarks
95
+ * This function checks if the input is a JSON Schema object type, which is defined as having a `type` property equal to "object" or having a `properties` object. This is used to determine if a given input conforms to the structure of a JSON Schema object definition.
96
+ *
97
+ * @param input - The value to check.
98
+ * @returns True if the input is a JSON Schema object type, false otherwise.
12
99
  */
13
- function isJTDSchema(input) {
14
- return (0, _stryke_json_schema.isJsonSchemaObjectType)(input) && "jtd" in input && input.jtd === true;
100
+ function isJsonSchemaObject(input) {
101
+ return (0, _stryke_json.isJsonSchemaObjectType)(input) && (input.type === "object" || (0, _stryke_type_checks.isObject)(input.properties));
15
102
  }
16
103
  /**
17
- * 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.
104
+ * Type guard for JSON Schemas that only accept `null`.
105
+ *
106
+ * @remarks
107
+ * This function checks if the input is a JSON Schema that exclusively accepts the `null` type. It verifies that the input is a valid JSON Schema and that its `type` property is set to "null". This is useful for identifying schemas that are specifically designed to allow only `null` values.
18
108
  *
19
- * @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) schema.
20
- * @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) schema, otherwise `false`.
109
+ * @param input - The value to check.
110
+ * @returns True if the input is a JSON Schema that only accepts `null`, false otherwise.
111
+ */
112
+ function isNullOnlyJsonSchema(input) {
113
+ return isJsonSchema(input) && input.type === "null";
114
+ }
115
+ /**
116
+ * Type guard for untyped schema objects.
117
+ *
118
+ * @remarks
119
+ * This function checks if the input is an untyped schema object, which is defined as having certain properties that are commonly found in untyped schema definitions. This includes properties such as `id`, `title`, `description`, `$schema`, `tsType`, `markdownType`, `type`, `required`, `tags`, `args`, `properties`, and `resolve`. The function verifies that these properties, if present, conform to the expected types (e.g., strings for certain properties, arrays for others). This type guard is used to determine if a given input can be treated as an untyped schema object within the context of the Powerlines schema system.
120
+ *
121
+ * @param input - The value to check.
122
+ * @returns True if the input is an untyped schema object, false otherwise.
21
123
  */
22
124
  function isUntypedSchema(input) {
23
125
  if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
@@ -37,10 +139,13 @@ function isUntypedSchema(input) {
37
139
  return true;
38
140
  }
39
141
  /**
40
- * 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.
142
+ * Type guard for untyped input objects.
41
143
  *
42
- * @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) input object.
43
- * @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) input object, otherwise `false`.
144
+ * @remarks
145
+ * This function checks if the input is an untyped input object, which is defined as having certain properties that are commonly found in untyped input definitions. This includes properties such as `$schema` and `$resolve`. The function verifies that these properties, if present, conform to the expected types (e.g., objects for `$schema`, functions for `$resolve`). This type guard is used to determine if a given input can be treated as an untyped input object within the context of the Powerlines schema system.
146
+ *
147
+ * @param input - The value to check.
148
+ * @returns True if the input is an untyped input object, false otherwise.
44
149
  */
45
150
  function isUntypedInput(input) {
46
151
  if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
@@ -50,27 +155,23 @@ function isUntypedInput(input) {
50
155
  return true;
51
156
  }
52
157
  /**
53
- * 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`.
158
+ * Type guard for Powerlines Schema objects.
54
159
  *
55
- * @param input - The input to check for being a {@link Schema}.
56
- * @returns `true` if the input is a {@link Schema}, otherwise `false`.
160
+ * @param input - The value to check.
161
+ * @returns True if the input is a Powerlines Schema object, false otherwise.
57
162
  */
58
163
  function isSchema(input) {
59
- return (0, _stryke_type_checks.isSetObject)(input) && "schema" in input && isJTDSchema(input.schema) && "input" in input && (0, _stryke_type_checks.isSetObject)(input.input) && "variant" in input && (0, _stryke_type_checks.isSetString)(input.variant);
164
+ return (0, _stryke_type_checks.isSetObject)(input) && "schema" in input && isJsonSchema(input.schema) && "variant" in input && (0, _stryke_type_checks.isSetString)(input.variant) && "hash" in input && (0, _stryke_type_checks.isSetString)(input.hash);
60
165
  }
61
- /**
62
- * 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`.
63
- *
64
- * @param input - The input to check for being a {@link ExtractedSchema}.
65
- * @returns `true` if the input is a {@link ExtractedSchema}, otherwise `false`.
66
- */
67
166
  function isExtractedSchema(input) {
68
- 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);
167
+ return isSchema(input) && "source" in input && (0, _stryke_type_checks.isSetObject)(input.source) && "schema" in input.source && "variant" in input.source && (0, _stryke_type_checks.isSetString)(input.source.variant);
69
168
  }
70
169
 
71
170
  //#endregion
72
171
  exports.isExtractedSchema = isExtractedSchema;
73
- exports.isJTDSchema = isJTDSchema;
172
+ exports.isJsonSchema = isJsonSchema;
173
+ exports.isJsonSchemaObject = isJsonSchemaObject;
174
+ exports.isNullOnlyJsonSchema = isNullOnlyJsonSchema;
74
175
  exports.isSchema = isSchema;
75
176
  exports.isUntypedInput = isUntypedInput;
76
177
  exports.isUntypedSchema = isUntypedSchema;
@@ -1,43 +1,65 @@
1
- import { ExtractedSchema, Schema as Schema$1, SchemaMetadata } from "./types.cjs";
1
+ import { ExtractedSchema, JsonSchema, JsonSchemaObject, Schema as Schema$1 } from "./types.cjs";
2
2
  import { InputObject, Schema } from "untyped";
3
- import { JTDSchemaType } from "ajv/dist/types/jtd-schema.js";
4
3
 
5
4
  //#region src/type-checks.d.ts
6
5
  /**
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`.
6
+ * Type guard for JSON Schema types.
8
7
  *
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`.
8
+ * @remarks
9
+ * This function checks if the input is a JSON Schema type, which is defined as having a `type` property or a `$ref` property. This is used to determine if a given input conforms to the structure of a JSON Schema definition that includes type information.
10
+ *
11
+ * @param input - The value to check.
12
+ * @returns True if the input is a JSON Schema type, false otherwise.
11
13
  */
12
- declare function isJTDSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is JTDSchemaType<TMetadata>;
14
+ declare function isJsonSchema<T = unknown>(input: unknown): input is JsonSchema<T>;
13
15
  /**
14
- * 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.
16
+ * Type guard for JSON Schema object forms.
17
+ *
18
+ * @remarks
19
+ * This function checks if the input is a JSON Schema object type, which is defined as having a `type` property equal to "object" or having a `properties` object. This is used to determine if a given input conforms to the structure of a JSON Schema object definition.
15
20
  *
16
- * @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) schema.
17
- * @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) schema, otherwise `false`.
21
+ * @param input - The value to check.
22
+ * @returns True if the input is a JSON Schema object type, false otherwise.
18
23
  */
19
- declare function isUntypedSchema(input: unknown): input is Schema;
24
+ declare function isJsonSchemaObject<T extends Record<string, any> = Record<string, any>>(input: unknown): input is JsonSchemaObject<T>;
20
25
  /**
21
- * 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.
26
+ * Type guard for JSON Schemas that only accept `null`.
22
27
  *
23
- * @param input - The input to check for being an [untyped](https://github.com/unjs/untyped) input object.
24
- * @returns `true` if the input is an [untyped](https://github.com/unjs/untyped) input object, otherwise `false`.
28
+ * @remarks
29
+ * This function checks if the input is a JSON Schema that exclusively accepts the `null` type. It verifies that the input is a valid JSON Schema and that its `type` property is set to "null". This is useful for identifying schemas that are specifically designed to allow only `null` values.
30
+ *
31
+ * @param input - The value to check.
32
+ * @returns True if the input is a JSON Schema that only accepts `null`, false otherwise.
25
33
  */
26
- declare function isUntypedInput(input: unknown): input is InputObject;
34
+ declare function isNullOnlyJsonSchema(input: unknown): input is JsonSchema<null>;
35
+ /**
36
+ * Type guard for untyped schema objects.
37
+ *
38
+ * @remarks
39
+ * This function checks if the input is an untyped schema object, which is defined as having certain properties that are commonly found in untyped schema definitions. This includes properties such as `id`, `title`, `description`, `$schema`, `tsType`, `markdownType`, `type`, `required`, `tags`, `args`, `properties`, and `resolve`. The function verifies that these properties, if present, conform to the expected types (e.g., strings for certain properties, arrays for others). This type guard is used to determine if a given input can be treated as an untyped schema object within the context of the Powerlines schema system.
40
+ *
41
+ * @param input - The value to check.
42
+ * @returns True if the input is an untyped schema object, false otherwise.
43
+ */
44
+ declare function isUntypedSchema(input: unknown): input is Schema;
27
45
  /**
28
- * 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`.
46
+ * Type guard for untyped input objects.
47
+ *
48
+ * @remarks
49
+ * This function checks if the input is an untyped input object, which is defined as having certain properties that are commonly found in untyped input definitions. This includes properties such as `$schema` and `$resolve`. The function verifies that these properties, if present, conform to the expected types (e.g., objects for `$schema`, functions for `$resolve`). This type guard is used to determine if a given input can be treated as an untyped input object within the context of the Powerlines schema system.
29
50
  *
30
- * @param input - The input to check for being a {@link Schema}.
31
- * @returns `true` if the input is a {@link Schema}, otherwise `false`.
51
+ * @param input - The value to check.
52
+ * @returns True if the input is an untyped input object, false otherwise.
32
53
  */
33
- declare function isSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is Schema$1<TMetadata>;
54
+ declare function isUntypedInput(input: unknown): input is InputObject;
34
55
  /**
35
- * 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`.
56
+ * Type guard for Powerlines Schema objects.
36
57
  *
37
- * @param input - The input to check for being a {@link ExtractedSchema}.
38
- * @returns `true` if the input is a {@link ExtractedSchema}, otherwise `false`.
58
+ * @param input - The value to check.
59
+ * @returns True if the input is a Powerlines Schema object, false otherwise.
39
60
  */
40
- declare function isExtractedSchema<TMetadata extends SchemaMetadata = SchemaMetadata>(input: unknown): input is ExtractedSchema<TMetadata>;
61
+ declare function isSchema<T = unknown>(input: unknown): input is Schema$1<T>;
62
+ declare function isExtractedSchema<T = unknown>(input: unknown): input is ExtractedSchema<T>;
41
63
  //#endregion
42
- export { isExtractedSchema, isJTDSchema, isSchema, isUntypedInput, isUntypedSchema };
64
+ export { isExtractedSchema, isJsonSchema, isJsonSchemaObject, isNullOnlyJsonSchema, isSchema, isUntypedInput, isUntypedSchema };
43
65
  //# 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":";;;;;;AAyHA;;;;;;;iBAAgB,YAAA,aAAA,CACd,KAAA,YACC,KAAA,IAAS,UAAU,CAAC,CAAA;;;AAAC;AA4FxB;;;;;;iBAAgB,kBAAA,WACJ,MAAA,gBAAsB,MAAA,cAAA,CAChC,KAAA,YAAiB,KAAA,IAAS,gBAAA,CAAiB,CAAA;;;;;;;;;;iBAgB7B,oBAAA,CACd,KAAA,YACC,KAAA,IAAS,UAAU;AAlBwB;AAgB9C;;;;;;;;AAhB8C,iBA+B9B,eAAA,CAAgB,KAAA,YAAiB,KAAA,IAAS,MAAa;AAAvE;;;;;;;;AAAuE;AAAvE,iBA2DgB,cAAA,CAAe,KAAA,YAAiB,KAAA,IAAS,WAAkB;;;;;;;iBAsB3D,QAAA,aAAA,CAAsB,KAAA,YAAiB,KAAA,IAAS,QAAM,CAAC,CAAA;AAAA,iBAYvD,iBAAA,aAAA,CACd,KAAA,YACC,KAAA,IAAS,eAAe,CAAC,CAAA"}