@danceroutine/tango-schema 1.11.15 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"model-aRAusQPz.js","names":["carrier","t"],"sources":["../src/model/fields/FieldMetadataStore.ts","../src/model/decorators/domain/ModelRef.ts","../src/model/decorators/domain/DecoratedFieldKind.ts","../src/model/decorators/Decorators.ts","../src/model/decorators/index.ts","../src/model/meta/Meta.ts","../src/model/meta/index.ts","../src/model/constraints/Constraints.ts","../src/model/constraints/Indexes.ts","../src/model/constraints/index.ts","../src/domain/internal/InternalFieldType.ts","../src/domain/internal/zod/isDate.ts","../src/domain/internal/zod/hasConstructorName.ts","../src/domain/internal/zod/isZodArray.ts","../src/domain/internal/zod/isZodBoolean.ts","../src/domain/internal/zod/isZodDate.ts","../src/domain/internal/zod/isZodDefault.ts","../src/domain/internal/zod/isZodNullable.ts","../src/domain/internal/zod/isZodNumber.ts","../src/domain/internal/zod/isZodObject.ts","../src/domain/internal/zod/isZodOptional.ts","../src/domain/internal/zod/isZodString.ts","../src/model/fields/inferFieldsFromSchema.ts","../src/domain/internal/InternalRelationType.ts","../src/model/relations/RelationBuilder.ts","../src/model/relations/RelationDescriptorNormalizer.ts","../src/model/relations/SchemaNaming.ts","../src/model/internal/InternalSchemaModel.ts","../src/model/relations/NormalizedRelationStorageDescriptor.ts","../src/model/relations/RelationSpec.ts","../src/model/relations/ImplicitManyToManyIdentifier.ts","../src/domain/internal/InternalReferentialAction.ts","../src/model/relations/ImplicitManyToManyThroughFactory.ts","../src/model/relations/ResolvedRelationGraphBuilder.ts","../src/model/registry/GeneratedRelationRegistryArtifact.ts","../src/model/registry/ResolvedRelationGraphArtifactFactory.ts","../src/model/registry/ModelRegistry.ts","../src/resolveSchemaModuleEntrypoint.ts","../src/model/registry/index.ts","../src/model/relations/index.ts","../src/model/ModelAugmentorRegistry.ts","../src/model/Model.ts","../src/model/index.ts"],"sourcesContent":["import type { ZodTypeAny } from '../decorators/domain/ZodTypeAny';\nimport type { TangoFieldMeta } from '../decorators/domain/TangoFieldMeta';\n\nconst fieldMetadataStore = new WeakMap<ZodTypeAny, TangoFieldMeta>();\n\nexport function getFieldMetadata(schema: ZodTypeAny): TangoFieldMeta | undefined {\n return fieldMetadataStore.get(schema);\n}\n\nexport function setFieldMetadata(schema: ZodTypeAny, meta: TangoFieldMeta): void {\n const existing = fieldMetadataStore.get(schema);\n fieldMetadataStore.set(schema, {\n ...existing,\n ...meta,\n });\n}\n","import type { Model, ModelKeyOf } from '../../../domain';\n\n// TODO: consider async model callbacks such as `() => Promise<Model>` when Tango tackles lazy import boundaries for cyclical model graphs.\n// See the ADR: https://tangowebframework.dev/contributors/adr/deep-relation-hydration-with-generated-path-typing\ndeclare const TANGO_TYPED_MODEL_REF_TARGET: unique symbol;\n\nexport interface TypedModelRef<TModel extends Model = Model> {\n readonly key: ModelKeyOf<TModel>;\n readonly [TANGO_TYPED_MODEL_REF_TARGET]?: TModel;\n}\n\nexport type ModelRef<TModel extends Model = Model> = string | TModel | (() => TModel) | TypedModelRef<TModel>;\n\nexport type ModelRefTarget<TRef> =\n TRef extends TypedModelRef<infer TModel>\n ? TModel\n : TRef extends () => infer TModel\n ? TModel extends Model\n ? TModel\n : never\n : TRef extends Model\n ? TRef\n : never;\n\nexport function createTypedModelRef<TModel extends Model>(key: ModelKeyOf<TModel>): TypedModelRef<TModel> {\n return Object.freeze({ key }) as TypedModelRef<TModel>;\n}\n\nexport function isTypedModelRef(value: unknown): value is TypedModelRef {\n return typeof value === 'object' && value !== null && typeof (value as { key?: unknown }).key === 'string';\n}\n","export const InternalDecoratedFieldKind = {\n FOREIGN_KEY: 'foreignKey',\n ONE_TO_ONE: 'oneToOne',\n MANY_TO_MANY: 'manyToMany',\n} as const;\nexport type DecoratedFieldKind = (typeof InternalDecoratedFieldKind)[keyof typeof InternalDecoratedFieldKind];\n","import { getLogger } from '@danceroutine/tango-core';\nimport { z } from 'zod';\nimport { setFieldMetadata } from '../fields/FieldMetadataStore';\nimport type { ZodTypeAny } from './domain/ZodTypeAny';\nimport { createTypedModelRef, type ModelRef, type ModelRefTarget, type TypedModelRef } from './domain/ModelRef';\nimport type { ReferentialOptions, TangoFieldMeta } from './domain/TangoFieldMeta';\nimport type { Model, ModelKeyOf } from '../../domain';\nimport type {\n ForeignKeyDecoratorConfig,\n ManyToManyDecoratorConfig,\n OneToOneDecoratorConfig,\n} from './domain/RelationDecoratorConfig';\nimport type { RelationDecoratedSchema } from './domain/RelationDecoratedSchema';\nimport { InternalDecoratedFieldKind } from './domain/DecoratedFieldKind';\nimport type { DecoratedFieldKind } from './domain/DecoratedFieldKind';\n\nfunction isZodType(value: unknown): value is ZodTypeAny {\n return (\n !!value &&\n typeof value === 'object' &&\n 'safeParse' in value &&\n typeof (value as { safeParse?: unknown }).safeParse === 'function'\n );\n}\n\nfunction decorate<T extends ZodTypeAny>(schema: T, meta: TangoFieldMeta): T {\n setFieldMetadata(schema, meta);\n return schema;\n}\n\nconst warnedDecoratorKinds = new Set<DecoratedFieldKind>();\n\nfunction warnDeprecatedSchemaOverload(kind: DecoratedFieldKind, replacement: string): void {\n if (warnedDecoratorKinds.has(kind)) {\n return;\n }\n\n warnedDecoratorKinds.add(kind);\n getLogger('tango.schema.decorators').warn(\n `Deprecated positional schema overload used for t.${kind}(...). Prefer ${replacement} instead.`\n );\n}\n\nfunction maybeDecorator<T extends ZodTypeAny>(\n schemaOrUndefined: T | undefined,\n meta: TangoFieldMeta\n): T | ((schema: T) => T) {\n if (schemaOrUndefined) {\n return decorate(schemaOrUndefined, meta);\n }\n\n return (schema: T) => decorate(schema, meta);\n}\n\nfunction primaryKey<T extends ZodTypeAny>(schema: T): T;\nfunction primaryKey<T extends ZodTypeAny>(): (input: T) => T;\nfunction primaryKey<T extends ZodTypeAny>(schema?: T): T | ((input: T) => T) {\n return maybeDecorator(schema, { primaryKey: true, notNull: true });\n}\n\nfunction unique<T extends ZodTypeAny>(schema: T): T;\nfunction unique<T extends ZodTypeAny>(): (input: T) => T;\nfunction unique<T extends ZodTypeAny>(schema?: T): T | ((input: T) => T) {\n return maybeDecorator(schema, { unique: true });\n}\n\nfunction nullValue<T extends ZodTypeAny>(schema: T): T;\nfunction nullValue<T extends ZodTypeAny>(): (input: T) => T;\nfunction nullValue<T extends ZodTypeAny>(schema?: T): T | ((input: T) => T) {\n return maybeDecorator(schema, { notNull: false });\n}\n\nfunction notNull<T extends ZodTypeAny>(schema: T): T;\nfunction notNull<T extends ZodTypeAny>(): (input: T) => T;\nfunction notNull<T extends ZodTypeAny>(schema?: T): T | ((input: T) => T) {\n return maybeDecorator(schema, { notNull: true });\n}\n\nfunction defaultValue<T extends ZodTypeAny>(schema: T, value: string | { now: true } | null): T;\nfunction defaultValue<T extends ZodTypeAny>(schema: T, value: string | { now: true } | null): T {\n return decorate(schema, { default: value });\n}\n\nfunction dbDefault<T extends ZodTypeAny>(schema: T, value: string): T;\nfunction dbDefault<T extends ZodTypeAny>(schema: T, value: string): T {\n return decorate(schema, { dbDefault: value });\n}\n\nfunction dbColumn<T extends ZodTypeAny>(schema: T, name: string): T;\nfunction dbColumn<T extends ZodTypeAny>(schema: T, name: string): T {\n return decorate(schema, { dbColumn: name });\n}\n\nfunction dbIndex<T extends ZodTypeAny>(schema: T): T {\n return decorate(schema, { dbIndex: true });\n}\n\nfunction choices<T extends ZodTypeAny>(schema: T, values: readonly unknown[]): T;\nfunction choices<T extends ZodTypeAny>(schema: T, values: readonly unknown[]): T {\n return decorate(schema, { choices: values });\n}\n\nfunction validators<T extends ZodTypeAny>(schema: T, ...values: readonly ((value: unknown) => unknown)[]): T;\nfunction validators<T extends ZodTypeAny>(schema: T, ...values: readonly ((value: unknown) => unknown)[]): T {\n return decorate(schema, { validators: values });\n}\n\nfunction helpText<T extends ZodTypeAny>(schema: T, text: string): T;\nfunction helpText<T extends ZodTypeAny>(schema: T, text: string): T {\n return decorate(schema, { helpText: text });\n}\n\nfunction errorMessages<T extends ZodTypeAny>(schema: T, map: Record<string, string>): T;\nfunction errorMessages<T extends ZodTypeAny>(schema: T, map: Record<string, string>): T {\n return decorate(schema, { errorMessages: map });\n}\n\nexport interface FieldDecoratorBuilder<TField extends ZodTypeAny> {\n defaultValue(value: string | { now: true } | null): FieldDecoratorBuilder<TField>;\n dbDefault(value: string): FieldDecoratorBuilder<TField>;\n dbColumn(name: string): FieldDecoratorBuilder<TField>;\n dbIndex(): FieldDecoratorBuilder<TField>;\n choices(values: readonly unknown[]): FieldDecoratorBuilder<TField>;\n validators(...values: readonly ((value: unknown) => unknown)[]): FieldDecoratorBuilder<TField>;\n helpText(text: string): FieldDecoratorBuilder<TField>;\n errorMessages(map: Record<string, string>): FieldDecoratorBuilder<TField>;\n build(): TField;\n}\n\nclass FieldDecoratorBuilderImpl<TField extends ZodTypeAny> implements FieldDecoratorBuilder<TField> {\n constructor(private readonly schema: TField) {}\n\n defaultValue(value: string | { now: true } | null): FieldDecoratorBuilder<TField> {\n decorate(this.schema, { default: value });\n return this;\n }\n\n dbDefault(value: string): FieldDecoratorBuilder<TField> {\n decorate(this.schema, { dbDefault: value });\n return this;\n }\n\n dbColumn(name: string): FieldDecoratorBuilder<TField> {\n decorate(this.schema, { dbColumn: name });\n return this;\n }\n\n dbIndex(): FieldDecoratorBuilder<TField> {\n decorate(this.schema, { dbIndex: true });\n return this;\n }\n\n choices(values: readonly unknown[]): FieldDecoratorBuilder<TField> {\n decorate(this.schema, { choices: values });\n return this;\n }\n\n validators(...values: readonly ((value: unknown) => unknown)[]): FieldDecoratorBuilder<TField> {\n decorate(this.schema, { validators: values });\n return this;\n }\n\n helpText(text: string): FieldDecoratorBuilder<TField> {\n decorate(this.schema, { helpText: text });\n return this;\n }\n\n errorMessages(map: Record<string, string>): FieldDecoratorBuilder<TField> {\n decorate(this.schema, { errorMessages: map });\n return this;\n }\n\n build(): TField {\n return this.schema;\n }\n}\n\nfunction field<T extends ZodTypeAny>(schema: T): FieldDecoratorBuilder<T> {\n return new FieldDecoratorBuilderImpl(schema);\n}\n\nfunction applyRelationMetadata<T extends ZodTypeAny>(\n schema: T,\n meta: TangoFieldMeta,\n config?: { name?: string; relatedName?: string }\n): T {\n return decorate(schema, {\n ...meta,\n forwardName: config?.name,\n reverseName: config?.relatedName,\n });\n}\n\nfunction toReferentialOptions(config?: ReferentialOptions): ReferentialOptions | undefined {\n if (!config) {\n return undefined;\n }\n\n if (config.column === undefined && config.onDelete === undefined && config.onUpdate === undefined) {\n return undefined;\n }\n\n return {\n column: config.column,\n onDelete: config.onDelete,\n onUpdate: config.onUpdate,\n };\n}\n\ntype ConfigName<TConfig> = TConfig extends { name: infer TName extends string } ? TName : undefined;\ntype ConfigRelatedName<TConfig> = TConfig extends { relatedName: infer TRelatedName extends string }\n ? TRelatedName\n : undefined;\n\nfunction modelRef<TModel extends Model>(key: ModelKeyOf<TModel>): TypedModelRef<TModel> {\n return createTypedModelRef<TModel>(key);\n}\n\nfunction foreignKey<\n TRef extends ModelRef,\n T extends ZodTypeAny,\n const TConfig extends ForeignKeyDecoratorConfig<T> & { field: T },\n>(\n target: TRef,\n config: TConfig\n): RelationDecoratedSchema<T, 'foreignKey', ModelRefTarget<TRef>, ConfigName<TConfig>, ConfigRelatedName<TConfig>>;\nfunction foreignKey<TRef extends ModelRef, const TConfig extends ForeignKeyDecoratorConfig<z.ZodNumber> | undefined>(\n target: TRef,\n config?: TConfig\n): RelationDecoratedSchema<\n z.ZodNumber,\n 'foreignKey',\n ModelRefTarget<TRef>,\n ConfigName<TConfig>,\n ConfigRelatedName<TConfig>\n>;\n/**\n * @deprecated Use `t.foreignKey(target, { field: schema, ...options })` instead.\n */\nfunction foreignKey<T extends ZodTypeAny>(\n target: ModelRef,\n schema: T,\n options?: ReferentialOptions\n): RelationDecoratedSchema<T, 'foreignKey'>;\nfunction foreignKey<T extends ZodTypeAny>(\n target: ModelRef,\n schemaOrOptions?: T | ForeignKeyDecoratorConfig<T>,\n maybeOptions?: ReferentialOptions\n): RelationDecoratedSchema<T, 'foreignKey'> | z.ZodNumber {\n if (isZodType(schemaOrOptions)) {\n warnDeprecatedSchemaOverload(\n InternalDecoratedFieldKind.FOREIGN_KEY,\n 't.foreignKey(target, { field: schema, ...options })'\n );\n return applyRelationMetadata(schemaOrOptions, {\n relationKind: InternalDecoratedFieldKind.FOREIGN_KEY,\n references: {\n target,\n options: maybeOptions,\n },\n }) as RelationDecoratedSchema<T, 'foreignKey'>;\n }\n\n const config = schemaOrOptions;\n const schema = config?.field ?? z.number().int();\n return applyRelationMetadata(\n schema,\n {\n relationKind: InternalDecoratedFieldKind.FOREIGN_KEY,\n references: {\n target,\n options: toReferentialOptions(config),\n },\n notNull: config?.field ? undefined : true,\n },\n config\n ) as RelationDecoratedSchema<T, 'foreignKey'> | z.ZodNumber;\n}\n\nfunction oneToOne<\n TRef extends ModelRef,\n T extends ZodTypeAny,\n const TConfig extends OneToOneDecoratorConfig<T> & { field: T },\n>(\n target: TRef,\n config: TConfig\n): RelationDecoratedSchema<T, 'oneToOne', ModelRefTarget<TRef>, ConfigName<TConfig>, ConfigRelatedName<TConfig>>;\nfunction oneToOne<TRef extends ModelRef, const TConfig extends OneToOneDecoratorConfig<z.ZodNumber> | undefined>(\n target: TRef,\n config?: TConfig\n): RelationDecoratedSchema<\n z.ZodNumber,\n 'oneToOne',\n ModelRefTarget<TRef>,\n ConfigName<TConfig>,\n ConfigRelatedName<TConfig>\n>;\n/**\n * @deprecated Use `t.oneToOne(target, { field: schema, ...options })` instead.\n */\nfunction oneToOne<T extends ZodTypeAny>(\n target: ModelRef,\n schema: T,\n options?: ReferentialOptions\n): RelationDecoratedSchema<T, 'oneToOne'>;\nfunction oneToOne<T extends ZodTypeAny>(\n target: ModelRef,\n schemaOrOptions?: T | OneToOneDecoratorConfig<T>,\n maybeOptions?: ReferentialOptions\n): RelationDecoratedSchema<T, 'oneToOne'> | z.ZodNumber {\n if (isZodType(schemaOrOptions)) {\n warnDeprecatedSchemaOverload(\n InternalDecoratedFieldKind.ONE_TO_ONE,\n 't.oneToOne(target, { field: schema, ...options })'\n );\n return applyRelationMetadata(schemaOrOptions, {\n relationKind: InternalDecoratedFieldKind.ONE_TO_ONE,\n unique: true,\n references: {\n target,\n options: maybeOptions,\n },\n }) as RelationDecoratedSchema<T, 'oneToOne'>;\n }\n\n const config = schemaOrOptions;\n const schema = config?.field ?? z.number().int();\n return applyRelationMetadata(\n schema,\n {\n relationKind: InternalDecoratedFieldKind.ONE_TO_ONE,\n unique: true,\n references: {\n target,\n options: toReferentialOptions(config),\n },\n notNull: config?.field ? undefined : true,\n },\n config\n ) as RelationDecoratedSchema<T, 'oneToOne'> | z.ZodNumber;\n}\n\nfunction manyToMany<\n TRef extends ModelRef,\n T extends ZodTypeAny,\n const TConfig extends ManyToManyDecoratorConfig<T> & { field: T },\n>(\n target: TRef,\n config: TConfig\n): RelationDecoratedSchema<T, 'manyToMany', ModelRefTarget<TRef>, ConfigName<TConfig>, undefined>;\nfunction manyToMany<\n TRef extends ModelRef,\n const TConfig extends ManyToManyDecoratorConfig<z.ZodArray<z.ZodNumber>> | undefined,\n>(\n target: TRef,\n config?: TConfig\n): RelationDecoratedSchema<z.ZodArray<z.ZodNumber>, 'manyToMany', ModelRefTarget<TRef>, ConfigName<TConfig>, undefined>;\n/**\n * @deprecated Use `t.manyToMany(target, { field: schema, name })` instead.\n */\nfunction manyToMany<T extends ZodTypeAny>(target: ModelRef, schema: T): RelationDecoratedSchema<T, 'manyToMany'>;\nfunction manyToMany<T extends ZodTypeAny>(\n target: ModelRef,\n schemaOrConfig?: T | ManyToManyDecoratorConfig<T>\n): RelationDecoratedSchema<T, 'manyToMany'> | z.ZodArray<z.ZodNumber> {\n if (isZodType(schemaOrConfig)) {\n warnDeprecatedSchemaOverload(\n InternalDecoratedFieldKind.MANY_TO_MANY,\n 't.manyToMany(target, { field: schema, name })'\n );\n return applyRelationMetadata(schemaOrConfig, {\n relationKind: InternalDecoratedFieldKind.MANY_TO_MANY,\n references: {\n target,\n },\n }) as RelationDecoratedSchema<T, 'manyToMany'>;\n }\n\n if (schemaOrConfig?.relatedName !== undefined) {\n throw new Error('t.manyToMany(...) does not support relatedName yet.');\n }\n\n const config = schemaOrConfig;\n\n const hasPartialThroughConfig =\n (config?.through !== undefined ||\n config?.throughSourceFieldName !== undefined ||\n config?.throughTargetFieldName !== undefined) &&\n !(config?.through && config.throughSourceFieldName && config.throughTargetFieldName);\n if (hasPartialThroughConfig) {\n throw new Error(\n 't.manyToMany(...) through config requires through, throughSourceFieldName, and throughTargetFieldName.'\n );\n }\n const schema = config?.field ?? z.array(z.number().int());\n return applyRelationMetadata(\n schema,\n {\n relationKind: InternalDecoratedFieldKind.MANY_TO_MANY,\n references: {\n target,\n through: config?.through,\n throughSourceFieldName: config?.throughSourceFieldName,\n throughTargetFieldName: config?.throughTargetFieldName,\n },\n },\n config\n ) as RelationDecoratedSchema<T, 'manyToMany'> | z.ZodArray<z.ZodNumber>;\n}\n\ntype UnaryFieldDecorator = {\n <T extends ZodTypeAny>(schema: T): T;\n <T extends ZodTypeAny>(): (input: T) => T;\n};\n\ntype RelationshipDecorator = {\n <TRef extends ModelRef, T extends ZodTypeAny, const TConfig extends ForeignKeyDecoratorConfig<T> & { field: T }>(\n target: TRef,\n config: TConfig\n ): RelationDecoratedSchema<T, 'foreignKey', ModelRefTarget<TRef>, ConfigName<TConfig>, ConfigRelatedName<TConfig>>;\n <TRef extends ModelRef, const TConfig extends ForeignKeyDecoratorConfig<z.ZodNumber> | undefined>(\n target: TRef,\n config?: TConfig\n ): RelationDecoratedSchema<\n z.ZodNumber,\n 'foreignKey',\n ModelRefTarget<TRef>,\n ConfigName<TConfig>,\n ConfigRelatedName<TConfig>\n >;\n /**\n * @deprecated Use `t.foreignKey(target, { field: schema, ...options })` instead.\n */\n <T extends ZodTypeAny>(\n target: ModelRef,\n schema: T,\n options?: ReferentialOptions\n ): RelationDecoratedSchema<T, 'foreignKey'>;\n};\n\ntype OneToOneRelationshipDecorator = {\n <TRef extends ModelRef, T extends ZodTypeAny, const TConfig extends OneToOneDecoratorConfig<T> & { field: T }>(\n target: TRef,\n config: TConfig\n ): RelationDecoratedSchema<T, 'oneToOne', ModelRefTarget<TRef>, ConfigName<TConfig>, ConfigRelatedName<TConfig>>;\n <TRef extends ModelRef, const TConfig extends OneToOneDecoratorConfig<z.ZodNumber> | undefined>(\n target: TRef,\n config?: TConfig\n ): RelationDecoratedSchema<\n z.ZodNumber,\n 'oneToOne',\n ModelRefTarget<TRef>,\n ConfigName<TConfig>,\n ConfigRelatedName<TConfig>\n >;\n /**\n * @deprecated Use `t.oneToOne(target, { field: schema, ...options })` instead.\n */\n <T extends ZodTypeAny>(\n target: ModelRef,\n schema: T,\n options?: ReferentialOptions\n ): RelationDecoratedSchema<T, 'oneToOne'>;\n};\n\ntype ManyToManyDecorator = {\n <TRef extends ModelRef, T extends ZodTypeAny, const TConfig extends ManyToManyDecoratorConfig<T> & { field: T }>(\n target: TRef,\n config: TConfig\n ): RelationDecoratedSchema<T, 'manyToMany', ModelRefTarget<TRef>, ConfigName<TConfig>, undefined>;\n <TRef extends ModelRef, const TConfig extends ManyToManyDecoratorConfig<z.ZodArray<z.ZodNumber>> | undefined>(\n target: TRef,\n config?: TConfig\n ): RelationDecoratedSchema<\n z.ZodArray<z.ZodNumber>,\n 'manyToMany',\n ModelRefTarget<TRef>,\n ConfigName<TConfig>,\n undefined\n >;\n /**\n * @deprecated Use `t.manyToMany(target, { field: schema, name })` instead.\n */\n <T extends ZodTypeAny>(target: ModelRef, schema: T): RelationDecoratedSchema<T, 'manyToMany'>;\n};\n\nexport interface TangoDecorators {\n field: <T extends ZodTypeAny>(schema: T) => FieldDecoratorBuilder<T>;\n modelRef: <TModel extends Model>(key: ModelKeyOf<TModel>) => TypedModelRef<TModel>;\n primaryKey: UnaryFieldDecorator;\n unique: UnaryFieldDecorator;\n null: UnaryFieldDecorator;\n notNull: UnaryFieldDecorator;\n default: <T extends ZodTypeAny>(schema: T, value: string | { now: true } | null) => T;\n dbDefault: <T extends ZodTypeAny>(schema: T, value: string) => T;\n dbColumn: <T extends ZodTypeAny>(schema: T, name: string) => T;\n dbIndex: <T extends ZodTypeAny>(schema: T) => T;\n choices: <T extends ZodTypeAny>(schema: T, values: readonly unknown[]) => T;\n validators: <T extends ZodTypeAny>(schema: T, ...values: readonly ((value: unknown) => unknown)[]) => T;\n helpText: <T extends ZodTypeAny>(schema: T, text: string) => T;\n errorMessages: <T extends ZodTypeAny>(schema: T, map: Record<string, string>) => T;\n foreignKey: RelationshipDecorator;\n oneToOne: OneToOneRelationshipDecorator;\n manyToMany: ManyToManyDecorator;\n}\n\nexport const Decorators: TangoDecorators = {\n field,\n modelRef,\n primaryKey: primaryKey as UnaryFieldDecorator,\n unique: unique as UnaryFieldDecorator,\n null: nullValue as UnaryFieldDecorator,\n notNull: notNull as UnaryFieldDecorator,\n default: defaultValue,\n dbDefault: dbDefault,\n dbColumn: dbColumn,\n dbIndex: dbIndex,\n choices: choices,\n validators: validators,\n helpText: helpText,\n errorMessages: errorMessages,\n foreignKey: foreignKey as RelationshipDecorator,\n oneToOne: oneToOne as OneToOneRelationshipDecorator,\n manyToMany: manyToMany as ManyToManyDecorator,\n};\n","/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\nexport { Decorators, Decorators as t } from './Decorators';\nexport type { FieldDecoratorBuilder, TangoDecorators } from './Decorators';\nexport type { ModelRef, ModelRefTarget, TypedModelRef } from './domain/ModelRef';\nexport { createTypedModelRef, isTypedModelRef } from './domain/ModelRef';\nexport type { RelationDecoratedSchema } from './domain/RelationDecoratedSchema';\nexport { InternalDecoratedFieldKind } from './domain/DecoratedFieldKind';\nexport type { DecoratedFieldKind } from './domain/DecoratedFieldKind';\nexport type {\n ForeignKeyDecoratorConfig,\n OneToOneDecoratorConfig,\n ManyToManyDecoratorConfig,\n} from './domain/RelationDecoratorConfig';\nexport type { ReferentialOptions, TangoFieldMeta } from './domain/TangoFieldMeta';\nexport type { ZodTypeAny } from './domain/ZodTypeAny';\n","import type { IndexDef } from '../../domain/index';\n\nexport type ModelConstraint = {\n kind: string;\n [key: string]: unknown;\n};\n\nexport type ModelMetaFragment = {\n ordering?: string[];\n managed?: boolean;\n defaultRelatedName?: string;\n indexes?: IndexDef[];\n constraints?: ModelConstraint[];\n};\n\nexport const Meta = {\n ordering(...fields: string[]): ModelMetaFragment {\n return { ordering: fields };\n },\n\n managed(value: boolean): ModelMetaFragment {\n return { managed: value };\n },\n\n defaultRelatedName(value: string): ModelMetaFragment {\n return { defaultRelatedName: value };\n },\n\n indexes(...indexes: IndexDef[]): ModelMetaFragment {\n return { indexes };\n },\n\n constraints(...constraints: ModelConstraint[]): ModelMetaFragment {\n return { constraints };\n },\n\n uniqueTogether(...sets: string[][]): ModelMetaFragment {\n return {\n constraints: sets.map((fields) => ({ kind: 'uniqueTogether', fields })),\n };\n },\n\n indexTogether(...sets: string[][]): ModelMetaFragment {\n return {\n indexes: sets.map((on, index) => ({\n name: `idx_${on.join('_')}_${index}`,\n on,\n })),\n };\n },\n\n merge(...fragments: readonly ModelMetaFragment[]): ModelMetaFragment {\n return fragments.reduce<ModelMetaFragment>(\n (acc, fragment) => ({\n ordering: fragment.ordering ?? acc.ordering,\n managed: fragment.managed ?? acc.managed,\n defaultRelatedName: fragment.defaultRelatedName ?? acc.defaultRelatedName,\n indexes: [...(acc.indexes ?? []), ...(fragment.indexes ?? [])],\n constraints: [...(acc.constraints ?? []), ...(fragment.constraints ?? [])],\n }),\n {}\n );\n },\n};\n","/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\nexport { Meta, Meta as m } from './Meta';\nexport type { ModelConstraint, ModelMetaFragment } from './Meta';\n","export type ConstraintDefinition = {\n kind: string;\n [key: string]: unknown;\n};\n\nexport const Constraints = {\n unique(fields: string[], options?: { name?: string; where?: string }): ConstraintDefinition {\n return {\n kind: 'unique',\n fields,\n ...options,\n };\n },\n\n check(condition: string, options?: { name?: string }): ConstraintDefinition {\n return {\n kind: 'check',\n condition,\n ...options,\n };\n },\n\n exclusion(definition: { using?: string; elements: string[]; where?: string; name?: string }): ConstraintDefinition {\n return {\n kind: 'exclusion',\n ...definition,\n };\n },\n};\n","import type { IndexDef } from '../../domain/index';\n\nexport const Indexes = {\n index(on: string[], options?: Omit<IndexDef, 'on'>): IndexDef {\n const suffix = on.join('_');\n return {\n name: options?.name ?? `idx_${suffix}`,\n on,\n unique: options?.unique,\n where: options?.where,\n };\n },\n};\n","/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\nexport { Constraints, Constraints as c } from './Constraints';\nexport type { ConstraintDefinition } from './Constraints';\nexport { Indexes, Indexes as i } from './Indexes';\n","export const InternalFieldType = {\n SERIAL: 'serial',\n INT: 'int',\n BIGINT: 'bigint',\n TEXT: 'text',\n BOOL: 'bool',\n TIMESTAMPTZ: 'timestamptz',\n JSONB: 'jsonb',\n UUID: 'uuid',\n} as const;\n","export function isDate(value: unknown): value is Date {\n return value !== null && value !== undefined && Object.prototype.toString.call(value) === '[object Date]';\n}\n","export function hasConstructorName(value: unknown, name: string): boolean {\n return (\n !!value &&\n typeof value === 'object' &&\n (value as { constructor?: { name?: unknown } }).constructor?.name === name\n );\n}\n","import { z } from 'zod';\nimport { hasConstructorName } from './hasConstructorName';\n\nexport function isZodArray(value: unknown): value is z.ZodArray<z.ZodTypeAny> {\n return hasConstructorName(value, 'ZodArray');\n}\n","import { z } from 'zod';\nimport { hasConstructorName } from './hasConstructorName';\n\nexport function isZodBoolean(value: unknown): value is z.ZodBoolean {\n return hasConstructorName(value, 'ZodBoolean');\n}\n","import { z } from 'zod';\nimport { hasConstructorName } from './hasConstructorName';\n\nexport function isZodDate(value: unknown): value is z.ZodDate {\n return hasConstructorName(value, 'ZodDate');\n}\n","import { z } from 'zod';\nimport { hasConstructorName } from './hasConstructorName';\n\nexport function isZodDefault(value: unknown): value is z.ZodDefault<z.ZodTypeAny> {\n return hasConstructorName(value, 'ZodDefault');\n}\n","import { z } from 'zod';\nimport { hasConstructorName } from './hasConstructorName';\n\nexport function isZodNullable(value: unknown): value is z.ZodNullable<z.ZodTypeAny> {\n return hasConstructorName(value, 'ZodNullable');\n}\n","import { z } from 'zod';\nimport { hasConstructorName } from './hasConstructorName';\n\nexport function isZodNumber(value: unknown): value is z.ZodNumber {\n return hasConstructorName(value, 'ZodNumber');\n}\n","import { z } from 'zod';\nimport { hasConstructorName } from './hasConstructorName';\n\nexport function isZodObject(value: unknown): value is z.ZodObject<z.ZodRawShape> {\n return hasConstructorName(value, 'ZodObject');\n}\n","import { z } from 'zod';\nimport { hasConstructorName } from './hasConstructorName';\n\nexport function isZodOptional(value: unknown): value is z.ZodOptional<z.ZodTypeAny> {\n return hasConstructorName(value, 'ZodOptional');\n}\n","import { z } from 'zod';\nimport { hasConstructorName } from './hasConstructorName';\n\nexport function isZodString(value: unknown): value is z.ZodString {\n return hasConstructorName(value, 'ZodString');\n}\n","import { z } from 'zod';\nimport type { Field, FieldType } from '../../domain/index';\nimport { InternalFieldType } from '../../domain/internal/InternalFieldType';\nimport { getFieldMetadata } from './FieldMetadataStore';\nimport type { ZodTypeAny } from '../decorators/domain/ZodTypeAny';\nimport type { ModelRef } from '../decorators/domain/ModelRef';\nimport type { TangoFieldMeta } from '../decorators/domain/TangoFieldMeta';\nimport { InternalDecoratedFieldKind } from '../decorators/domain/DecoratedFieldKind';\nimport { ModelRegistry } from '../registry/ModelRegistry';\nimport {\n isDate,\n isZodArray,\n isZodBoolean,\n isZodDate,\n isZodDefault,\n isZodNullable,\n isZodNumber,\n isZodObject,\n isZodOptional,\n isZodString,\n} from '../../domain/internal/zod/index';\n\nexport type InferFieldsOptions = {\n registry?: ModelRegistry;\n resolveReferenceTarget?: (target: ModelRef) => { table: string; pk: string };\n};\n\n/**\n * Infer one storage field from a Zod schema member plus any Tango decorator metadata.\n *\n * The registry and optional target resolver are used only when the field carries\n * reference metadata that must be translated into concrete table/primary-key names.\n */\nfunction inferField(\n name: string,\n zodType: z.ZodType,\n meta: TangoFieldMeta | undefined,\n registry: ModelRegistry,\n resolveReferenceTarget?: (target: ModelRef) => { table: string; pk: string }\n): Field | null {\n let type: FieldType;\n let notNull = true;\n let defaultValue: Field['default'] = undefined;\n\n let unwrapped: z.ZodType = zodType;\n\n if (isZodOptional(unwrapped)) {\n notNull = false;\n unwrapped = unwrapped.unwrap() as z.ZodType;\n }\n\n if (isZodNullable(unwrapped)) {\n notNull = false;\n unwrapped = unwrapped.unwrap() as z.ZodType;\n }\n\n if (isZodDefault(unwrapped)) {\n const def = unwrapped._zod.def.defaultValue;\n if (isDate(def)) {\n defaultValue = { now: true };\n } else if (typeof def === 'string' || typeof def === 'number') {\n defaultValue = String(def);\n }\n unwrapped = unwrapped.removeDefault() as z.ZodType;\n }\n\n if (isZodString(unwrapped)) {\n type = InternalFieldType.TEXT;\n } else if (isZodNumber(unwrapped)) {\n const checks = unwrapped._zod.def.checks ?? [];\n const isInt = checks.some((c) => 'format' in c._zod.def && c._zod.def.format === 'safeint');\n type = isInt ? InternalFieldType.INT : InternalFieldType.BIGINT;\n } else if (isZodBoolean(unwrapped)) {\n type = InternalFieldType.BOOL;\n } else if (isZodDate(unwrapped)) {\n type = InternalFieldType.TIMESTAMPTZ;\n } else if (isZodObject(unwrapped) || isZodArray(unwrapped)) {\n type = InternalFieldType.JSONB;\n } else {\n return null;\n }\n\n const field: Field = {\n name,\n type,\n notNull,\n default: defaultValue,\n };\n\n if (!meta) {\n return field;\n }\n\n if (meta.dbColumn) {\n field.name = meta.dbColumn;\n }\n\n if (typeof meta.notNull === 'boolean') {\n field.notNull = meta.notNull;\n }\n\n if (meta.default !== undefined) {\n field.default = meta.default;\n }\n\n if (meta.primaryKey) {\n field.primaryKey = true;\n }\n\n if (meta.unique) {\n field.unique = true;\n }\n\n // Many-to-many declarations stay on the relation side of the seam. They do\n // not correspond to a stored column on the current table.\n if (meta.relationKind === InternalDecoratedFieldKind.MANY_TO_MANY) {\n return null;\n }\n\n if (meta.references) {\n const targetMetadata = resolveReferenceTarget\n ? resolveReferenceTarget(meta.references.target)\n : resolveReferenceTargetFromRegistry(meta.references.target, registry, meta.references.options?.column);\n\n field.references = {\n table: targetMetadata.table,\n column: meta.references.options?.column ?? targetMetadata.pk,\n onDelete: meta.references.options?.onDelete,\n onUpdate: meta.references.options?.onUpdate,\n };\n }\n\n return field;\n}\n\nfunction resolveReferenceTargetFromRegistry(\n target: ModelRef,\n registry: ModelRegistry,\n explicitColumn?: string\n): { table: string; pk: string } {\n const targetModel = registry.resolveRef(target);\n const primaryKey =\n explicitColumn ?? targetModel.metadata.fields.find((candidate) => candidate.primaryKey)?.name ?? 'id';\n\n return {\n table: targetModel.metadata.table,\n pk: primaryKey,\n };\n}\n\n/**\n * Infer Tango field metadata from a Zod object schema and any attached field decorators.\n */\nexport function inferFieldsFromSchema(schema: z.ZodObject<z.ZodRawShape>, options?: InferFieldsOptions): Field[] {\n const registry = options?.registry ?? ModelRegistry.global();\n const shape = schema.shape;\n const fields: Field[] = [];\n\n for (const [name, zodType] of Object.entries(shape)) {\n const field = inferField(\n name,\n zodType as z.ZodType,\n getFieldMetadata(zodType as ZodTypeAny),\n registry,\n options?.resolveReferenceTarget\n );\n if (field) {\n fields.push(field);\n }\n }\n\n return fields;\n}\n","export const InternalRelationType = {\n HAS_MANY: 'hasMany',\n BELONGS_TO: 'belongsTo',\n HAS_ONE: 'hasOne',\n} as const;\n","import type { RelationDef } from '../../domain/index';\nimport { InternalRelationType } from '../../domain/internal/InternalRelationType';\n\n/**\n * Public authoring DSL for model-level named relations.\n *\n * This is the first stage of the relations subdomain. Application code uses it\n * inside `relations: (r) => ({ ... })` to declare stable relation names and\n * resolve ambiguity that field decorators alone cannot express.\n *\n * Later internal stages normalize these authored definitions and combine them\n * with field-authored relation metadata to build the resolved relation graph.\n */\nexport class RelationBuilder {\n /** Declare a one-to-many relation from this model to `target`. */\n hasMany(target: string, foreignKey: string): RelationDef {\n return {\n type: InternalRelationType.HAS_MANY,\n target,\n foreignKey,\n };\n }\n\n /** Declare an owning relation to a parent model. */\n belongsTo(target: string, foreignKey: string, localKey?: string): RelationDef {\n return {\n type: InternalRelationType.BELONGS_TO,\n target,\n foreignKey,\n localKey,\n };\n }\n\n /** Declare a one-to-one relation from this model to `target`. */\n hasOne(target: string, foreignKey: string): RelationDef {\n return {\n type: InternalRelationType.HAS_ONE,\n target,\n foreignKey,\n };\n }\n}\n","import { z } from 'zod';\nimport type { ZodTypeAny } from '../decorators/domain/ZodTypeAny';\nimport { InternalDecoratedFieldKind } from '../decorators/domain/DecoratedFieldKind';\nimport { getFieldMetadata } from '../fields/FieldMetadataStore';\nimport type {\n NormalizedRelationOrigin,\n NormalizedRelationStorageDescriptor,\n} from './NormalizedRelationStorageDescriptor';\n\ntype RelationCandidate = {\n sourceSchemaFieldKey: string;\n zodType: ZodTypeAny;\n};\n\n/**\n * Normalizes field-authored relation declarations from a model schema into the\n * shared descriptor shape consumed by storage and relation finalization.\n *\n * This is the normalization stage of the relations subdomain. It sits between\n * authoring and resolution:\n *\n * - authoring: decorators attach relation intent to schema fields\n * - normalization: this class converts that intent into a registry-independent\n * descriptor shape\n * - resolution: the graph builder combines those descriptors with finalized\n * storage artifacts and explicit relation names\n */\nexport class RelationDescriptorNormalizer {\n constructor(\n private readonly sourceModelKey: string,\n private readonly schema: z.ZodObject<z.ZodRawShape>\n ) {}\n\n static normalize(\n sourceModelKey: string,\n schema: z.ZodObject<z.ZodRawShape>\n ): readonly NormalizedRelationStorageDescriptor[] {\n return new RelationDescriptorNormalizer(sourceModelKey, schema).normalize();\n }\n\n /**\n * Run the field-authored relation normalization pipeline for one model\n * schema and emit descriptors that later relation stages can resolve.\n */\n normalize(): readonly NormalizedRelationStorageDescriptor[] {\n const descriptors: NormalizedRelationStorageDescriptor[] = [];\n\n for (const candidate of this.collectRelationCandidates()) {\n const descriptor = this.normalizeCandidate(candidate);\n if (descriptor) {\n descriptors.push(descriptor);\n }\n }\n\n return descriptors;\n }\n\n private collectRelationCandidates(): readonly RelationCandidate[] {\n return Object.entries(this.schema.shape).map(([sourceSchemaFieldKey, zodType]) => ({\n sourceSchemaFieldKey,\n zodType: zodType as ZodTypeAny,\n }));\n }\n\n private normalizeCandidate(candidate: RelationCandidate): NormalizedRelationStorageDescriptor | undefined {\n const meta = getFieldMetadata(candidate.zodType);\n if (!meta?.references || !meta.relationKind) {\n return undefined;\n }\n\n return {\n edgeId: this.buildEdgeId(candidate.sourceSchemaFieldKey, meta.relationKind),\n sourceModelKey: this.sourceModelKey,\n sourceSchemaFieldKey: candidate.sourceSchemaFieldKey,\n targetRef: meta.references.target,\n origin: meta.relationKind,\n localFieldName: candidate.sourceSchemaFieldKey,\n dbColumnName: meta.dbColumn ?? candidate.sourceSchemaFieldKey,\n referencedTargetColumn: meta.references.options?.column,\n onDelete: meta.references.options?.onDelete,\n onUpdate: meta.references.options?.onUpdate,\n unique: meta.unique || meta.relationKind === InternalDecoratedFieldKind.ONE_TO_ONE,\n explicitForwardName: meta.forwardName,\n explicitReverseName: meta.reverseName,\n namingHint: this.deriveNamingHint(candidate.sourceSchemaFieldKey),\n throughModelRef: meta.references.through,\n throughSourceFieldName: meta.references.throughSourceFieldName,\n throughTargetFieldName: meta.references.throughTargetFieldName,\n provenance: 'field-decorator',\n };\n }\n\n private buildEdgeId(sourceSchemaFieldKey: string, origin: NormalizedRelationOrigin): string {\n return `${this.sourceModelKey}:${sourceSchemaFieldKey}:${origin}`;\n }\n\n private deriveNamingHint(fieldKey: string): string {\n if (fieldKey.endsWith('Id') && fieldKey.length > 2) {\n return fieldKey.slice(0, -2);\n }\n\n if (fieldKey.endsWith('_id') && fieldKey.length > 3) {\n return fieldKey.slice(0, -3);\n }\n\n return fieldKey;\n }\n}\n","/**\n * Shared naming policy for the model and relations subdomains.\n *\n * These helpers are not an authoring or graph stage on their own. They are the\n * cross-cutting policy layer used by both model construction and relation\n * resolution when Tango derives table names, aliases, and synthesized relation\n * names in a Django-style shape.\n */\nexport function toSnakeCase(value: string): string {\n return value\n .replace(/([a-z0-9])([A-Z])/g, '$1_$2')\n .replace(/[\\s-]+/g, '_')\n .toLowerCase();\n}\n\nexport function pluralize(value: string): string {\n if (/(s|x|z|ch|sh)$/.test(value)) {\n return `${value}es`;\n }\n\n if (/[^aeiou]y$/.test(value)) {\n return `${value.slice(0, -1)}ies`;\n }\n\n return `${value}s`;\n}\n\nexport function deriveTableName(name: string): string {\n return pluralize(toSnakeCase(name));\n}\n\nexport function decapitalizeModelName(name: string): string {\n if (name.length === 0) {\n return name;\n }\n return `${name[0]!.toLowerCase()}${name.slice(1)}`;\n}\n","import { z } from 'zod';\nimport type {\n Field,\n Model,\n ModelAugmentations,\n ModelMetadata,\n ModelWriteHooks,\n PersistedModelOutput,\n RelationDef,\n} from '../../domain/index';\nimport type { ModelDefinition } from '../ModelDefinition';\nimport { RelationBuilder } from '../relations/RelationBuilder';\nimport type { ModelRegistry } from '../registry/ModelRegistry';\nimport type { NormalizedRelationStorageDescriptor } from '../relations/NormalizedRelationStorageDescriptor';\nimport { RelationDescriptorNormalizer } from '../relations/RelationDescriptorNormalizer';\nimport { deriveTableName } from '../relations/SchemaNaming';\n\ntype AnySchemaModel = Model<z.ZodObject<z.ZodRawShape>>;\ntype AnyInternalSchemaModel = InternalSchemaModel<z.ZodObject<z.ZodRawShape>>;\nconst REGISTRY_OWNER_KEY = Symbol.for('tango.schema.registryOwner');\nconst NORMALIZED_RELATIONS_KEY = Symbol.for('tango.schema.normalizedRelations');\nconst EXPLICIT_FIELDS_KEY = Symbol.for('tango.schema.explicitFields');\nconst EXPLICIT_RELATIONS_KEY = Symbol.for('tango.schema.explicitRelations');\n\ntype InternalSchemaModelCarrier = object & {\n [REGISTRY_OWNER_KEY]?: ModelRegistry;\n [NORMALIZED_RELATIONS_KEY]?: readonly NormalizedRelationStorageDescriptor[];\n [EXPLICIT_FIELDS_KEY]?: readonly Field[];\n [EXPLICIT_RELATIONS_KEY]?: Readonly<Record<string, RelationDef>>;\n};\n\nexport class InternalSchemaModel<\n TSchema extends z.ZodObject<z.ZodRawShape>,\n TKey extends string = string,\n> implements Model<TSchema, TKey> {\n static readonly BRAND = 'tango.schema.internal_schema_model' as const;\n\n readonly __tangoBrand: typeof InternalSchemaModel.BRAND = InternalSchemaModel.BRAND;\n readonly metadata: ModelMetadata;\n readonly schema: TSchema;\n readonly hooks?: ModelWriteHooks<PersistedModelOutput<TSchema>>;\n declare readonly objects: ModelAugmentations<TSchema, TKey> extends { readonly objects: infer TObject }\n ? TObject\n : never;\n\n private constructor(\n metadata: ModelMetadata,\n schema: TSchema,\n hooks: ModelWriteHooks<PersistedModelOutput<TSchema>> | undefined\n ) {\n this.metadata = metadata;\n this.schema = schema;\n this.hooks = hooks;\n }\n\n static create<TSchema extends z.ZodObject<z.ZodRawShape>>(\n definition: ModelDefinition<TSchema>,\n registry: ModelRegistry\n ): InternalSchemaModel<TSchema> {\n InternalSchemaModel.validateDefinition(definition);\n\n const builder = new RelationBuilder();\n const relations = definition.relations ? Object.freeze(definition.relations(builder)) : undefined;\n const key = `${definition.namespace}/${definition.name}`;\n const table = definition.table?.trim() || deriveTableName(definition.name);\n const normalizedRelations = RelationDescriptorNormalizer.normalize(key, definition.schema);\n\n const metadata: ModelMetadata = {\n namespace: definition.namespace,\n name: definition.name,\n key,\n table,\n fields: [] as never,\n indexes: definition.indexes,\n relations,\n ordering: definition.ordering,\n managed: definition.managed,\n defaultRelatedName: definition.defaultRelatedName,\n constraints: definition.constraints,\n };\n\n // The field view stays lazy because finalized storage metadata is registry-scoped.\n // The owning registry publishes the current finalized fields for this model\n // instead of freezing a stale one-time snapshot during construction.\n Object.defineProperty(metadata, 'fields', {\n enumerable: true,\n configurable: false,\n get: () => registry.getFinalizedFields(key) as typeof metadata.fields,\n });\n Object.freeze(metadata);\n\n const model = new InternalSchemaModel(metadata, definition.schema, definition.hooks);\n InternalSchemaModel.attachInternals(model, {\n registry,\n normalizedRelations,\n explicitFields: definition.fields,\n explicitRelations: relations,\n });\n return model;\n }\n\n static isInternalSchemaModel(value: unknown): value is AnyInternalSchemaModel {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === InternalSchemaModel.BRAND\n );\n }\n\n static getRegistryOwner(model: AnySchemaModel): ModelRegistry {\n const owner = InternalSchemaModel.carrier(model)[REGISTRY_OWNER_KEY];\n if (!owner) {\n throw new Error(`Model '${model.metadata.key}' is missing internal registry ownership metadata.`);\n }\n return owner;\n }\n\n static getNormalizedRelations(model: AnySchemaModel): readonly NormalizedRelationStorageDescriptor[] {\n return InternalSchemaModel.carrier(model)[NORMALIZED_RELATIONS_KEY] ?? [];\n }\n\n static getExplicitFields(model: AnySchemaModel): readonly Field[] | undefined {\n return InternalSchemaModel.carrier(model)[EXPLICIT_FIELDS_KEY];\n }\n\n static getExplicitRelations(model: AnySchemaModel): Readonly<Record<string, RelationDef>> | undefined {\n return InternalSchemaModel.carrier(model)[EXPLICIT_RELATIONS_KEY];\n }\n\n private static validateDefinition<TSchema extends z.ZodObject<z.ZodRawShape>>(\n definition: ModelDefinition<TSchema>\n ): void {\n if (!definition.namespace.trim()) {\n throw new Error('Model.namespace is required and cannot be empty.');\n }\n if (!definition.name.trim()) {\n throw new Error('Model.name is required and cannot be empty.');\n }\n if (definition.table !== undefined && !definition.table.trim()) {\n throw new Error('Model.table cannot be empty when provided.');\n }\n }\n\n private static require(model: AnySchemaModel): AnyInternalSchemaModel {\n if (!InternalSchemaModel.isInternalSchemaModel(model)) {\n throw new Error(`Model '${model.metadata.key}' is missing internal registry ownership metadata.`);\n }\n\n return model;\n }\n\n private static carrier(model: AnySchemaModel): InternalSchemaModelCarrier {\n return InternalSchemaModel.require(model) as unknown as InternalSchemaModelCarrier;\n }\n\n private static attachInternals(\n model: object,\n internals: {\n registry: ModelRegistry;\n normalizedRelations: readonly NormalizedRelationStorageDescriptor[];\n explicitFields?: readonly Field[];\n explicitRelations?: Readonly<Record<string, RelationDef>>;\n }\n ): void {\n const carrier = model as InternalSchemaModelCarrier;\n\n Object.defineProperties(carrier, {\n [REGISTRY_OWNER_KEY]: {\n value: internals.registry,\n enumerable: false,\n configurable: false,\n writable: false,\n },\n [NORMALIZED_RELATIONS_KEY]: {\n value: Object.freeze([...internals.normalizedRelations]),\n enumerable: false,\n configurable: false,\n writable: false,\n },\n [EXPLICIT_FIELDS_KEY]: {\n value: internals.explicitFields ? Object.freeze([...internals.explicitFields]) : undefined,\n enumerable: false,\n configurable: false,\n writable: false,\n },\n [EXPLICIT_RELATIONS_KEY]: {\n value: internals.explicitRelations,\n enumerable: false,\n configurable: false,\n writable: false,\n },\n });\n }\n}\n","import type { DeleteReferentialAction, UpdateReferentialAction } from '../../domain/index';\nimport type { ModelRef } from '../decorators/domain/ModelRef';\n\nexport const InternalNormalizedRelationOrigin = {\n FOREIGN_KEY: 'foreignKey',\n ONE_TO_ONE: 'oneToOne',\n MANY_TO_MANY: 'manyToMany',\n} as const;\nexport type NormalizedRelationOrigin =\n (typeof InternalNormalizedRelationOrigin)[keyof typeof InternalNormalizedRelationOrigin];\n\n/**\n * Registry-independent relation descriptor produced immediately after model\n * construction.\n *\n * This is the handoff object between relation authoring and relation\n * resolution. It preserves field-authored relation intent in a normalized form\n * without yet assigning public reverse names or resolved graph edges.\n */\nexport interface NormalizedRelationStorageDescriptor {\n edgeId: string;\n sourceModelKey: string;\n sourceSchemaFieldKey: string;\n targetRef: ModelRef;\n origin: NormalizedRelationOrigin;\n localFieldName: string;\n dbColumnName: string;\n referencedTargetColumn?: string;\n onDelete?: DeleteReferentialAction;\n onUpdate?: UpdateReferentialAction;\n unique?: boolean;\n explicitForwardName?: string;\n explicitReverseName?: string;\n namingHint: string;\n throughModelRef?: ModelRef;\n throughSourceFieldName?: string;\n throughTargetFieldName?: string;\n provenance: 'field-decorator';\n}\n","// Keep these as plain string literals rather than TS enums so the runtime\n// values stay identical across package boundaries without enum emit semantics.\nexport const InternalRelationPublicKind = {\n BELONGS_TO: 'belongsTo',\n HAS_ONE: 'hasOne',\n HAS_MANY: 'hasMany',\n MANY_TO_MANY: 'manyToMany',\n} as const;\n\nexport const InternalRelationStorageStrategy = {\n REFERENCE: 'reference',\n REVERSE_REFERENCE: 'reverse_reference',\n MANY_TO_MANY: 'many_to_many',\n} as const;\n\nexport const InternalRelationCardinality = {\n SINGLE: 'single',\n MANY: 'many',\n} as const;\n\nexport const InternalRelationProvenance = {\n FIELD_DECORATOR: 'field-decorator',\n RELATIONS_API: 'relations-api',\n SYNTHESIZED_REVERSE: 'synthesized-reverse',\n} as const;\n\nexport type RelationPublicKind = (typeof InternalRelationPublicKind)[keyof typeof InternalRelationPublicKind];\nexport type RelationStorageStrategy =\n (typeof InternalRelationStorageStrategy)[keyof typeof InternalRelationStorageStrategy];\nexport type RelationCardinality = (typeof InternalRelationCardinality)[keyof typeof InternalRelationCardinality];\nexport type RelationProvenance = (typeof InternalRelationProvenance)[keyof typeof InternalRelationProvenance];\n\n/**\n * Author-time relation intent after target resolution but before full graph\n * pairing and naming.\n *\n * This type is the conceptual bridge between normalized descriptors and the\n * fully resolved graph. It exists so the relations subdomain has a stable\n * vocabulary for relation kinds, storage strategies, and provenance as the\n * pipeline becomes more sophisticated.\n */\nexport interface RelationSpec {\n edgeId: string;\n sourceModelKey: string;\n sourceSchemaFieldKey?: string;\n targetModelKey: string;\n kind: RelationPublicKind;\n storageStrategy: RelationStorageStrategy;\n localFieldName?: string;\n targetFieldName?: string;\n nameHint?: string;\n throughModelKey?: string;\n throughSourceFieldName?: string;\n throughTargetFieldName?: string;\n provenance: RelationProvenance;\n}\n","import { createHash } from 'node:crypto';\n\n/**\n * Single source of truth for identity of Tango-synthesized many-to-many\n * through models. Other parts of the schema package interact with synthesized\n * models exclusively through this class so they do not have to know the\n * namespace or digest scheme those keys encode.\n */\nexport class ImplicitManyToManyIdentifier {\n private static readonly NAMESPACE = 'tango.implicit';\n\n /**\n * Stable model key for the synthesized through model connecting\n * `sourceModelKey` to `targetModelKey` via the schema field\n * `sourceSchemaFieldKey`.\n *\n * The returned key is deterministic across runs so storage and hydration\n * artifacts stay stable as long as the inputs match.\n */\n static getModelKey(sourceModelKey: string, sourceSchemaFieldKey: string, targetModelKey: string): string {\n const digest = ImplicitManyToManyIdentifier.digest(sourceModelKey, sourceSchemaFieldKey, targetModelKey, 32);\n return `${ImplicitManyToManyIdentifier.NAMESPACE}/m2m_${digest}`;\n }\n\n /**\n * Deterministic short digest used to derive the physical join-table name\n * for a synthesized through model. Shorter than the model-key digest so\n * table names stay within common SQL identifier limits.\n */\n static getTableBaseDigest(sourceModelKey: string, sourceSchemaFieldKey: string, targetModelKey: string): string {\n return ImplicitManyToManyIdentifier.digest(sourceModelKey, sourceSchemaFieldKey, targetModelKey, 16);\n }\n\n /**\n * True when `modelKey` was produced by {@link getModelKey} and therefore\n * identifies a synthesized through model. Callers use this instead of\n * comparing namespace prefixes so the namespace remains an implementation\n * detail of this class.\n */\n static isImplicitManyToManyModel(modelKey: string): boolean {\n return modelKey.startsWith(`${ImplicitManyToManyIdentifier.NAMESPACE}/`);\n }\n\n /**\n * Namespace under which synthesized through models are registered.\n * Exposed so {@link ImplicitManyToManyThroughFactory} can construct the\n * model with the correct namespace. External callers that want to ask\n * \"is this an implicit model\" should prefer {@link isImplicitManyToManyModel}.\n */\n static getNamespace(): string {\n return ImplicitManyToManyIdentifier.NAMESPACE;\n }\n\n /**\n * Extract the `m2m_<digest>` component of a synthesized model key so the\n * factory can register the through model with a deterministic name while\n * keeping the namespace owned by this class.\n */\n static getModelName(modelKey: string): string {\n const prefix = `${ImplicitManyToManyIdentifier.NAMESPACE}/`;\n if (!modelKey.startsWith(prefix)) {\n throw new Error(\n `ImplicitManyToManyIdentifier.getModelName expected a key produced by getModelKey, received '${modelKey}'.`\n );\n }\n return modelKey.slice(prefix.length);\n }\n\n private static digest(\n sourceModelKey: string,\n sourceSchemaFieldKey: string,\n targetModelKey: string,\n byteLength: number\n ): string {\n return createHash('sha256')\n .update(`${sourceModelKey}\\0${sourceSchemaFieldKey}\\0${targetModelKey}`, 'utf8')\n .digest('hex')\n .slice(0, byteLength);\n }\n}\n","export const InternalReferentialAction = {\n CASCADE: 'CASCADE',\n SET_NULL: 'SET NULL',\n RESTRICT: 'RESTRICT',\n NO_ACTION: 'NO ACTION',\n} as const;\n","import { z } from 'zod';\nimport type { IndexDef, Model } from '../../domain/index';\nimport { Decorators as t } from '../decorators/Decorators';\nimport type { ModelRef } from '../decorators/domain/ModelRef';\nimport { getFieldMetadata } from '../fields/FieldMetadataStore';\nimport type { ZodTypeAny } from '../decorators/domain/ZodTypeAny';\nimport {\n isZodArray,\n isZodBoolean,\n isZodDate,\n isZodDefault,\n isZodNullable,\n isZodNumber,\n isZodObject,\n isZodOptional,\n isZodString,\n} from '../../domain/internal/zod/index';\nimport { InternalSchemaModel } from '../internal/InternalSchemaModel';\nimport type { ModelRegistry } from '../registry/ModelRegistry';\nimport type { NormalizedRelationStorageDescriptor } from './NormalizedRelationStorageDescriptor';\nimport { InternalNormalizedRelationOrigin } from './NormalizedRelationStorageDescriptor';\nimport { decapitalizeModelName } from './SchemaNaming';\nimport { ImplicitManyToManyIdentifier } from './ImplicitManyToManyIdentifier';\nimport { InternalReferentialAction } from '../../domain/internal/InternalReferentialAction';\n\ntype PrimaryKeyShape = {\n fieldKey: string;\n zod: ZodTypeAny;\n dbColumn: string;\n};\n\nexport class ImplicitManyToManyThroughFactory {\n static throughFieldNames(\n sourceModel: Model,\n targetModel: Model\n ): {\n throughSourceFieldName: string;\n throughTargetFieldName: string;\n } {\n if (sourceModel.metadata.key === targetModel.metadata.key) {\n return {\n throughSourceFieldName: `from${sourceModel.metadata.name}`,\n throughTargetFieldName: `to${targetModel.metadata.name}`,\n };\n }\n\n return {\n throughSourceFieldName: `${decapitalizeModelName(sourceModel.metadata.name)}Id`,\n throughTargetFieldName: `${decapitalizeModelName(targetModel.metadata.name)}Id`,\n };\n }\n\n static buildModels(registry: ModelRegistry): Model[] {\n const descriptors = ImplicitManyToManyThroughFactory.collectImplicitDescriptors(registry);\n const models: Model[] = [];\n const occupiedTables = new Set<string>(\n [...registry.values()].map((m) => m.metadata.table.trim().toLowerCase())\n );\n\n for (const descriptor of descriptors) {\n const sourceModel = registry.getByKey(descriptor.sourceModelKey)!;\n\n const targetModel = registry.resolveRef(descriptor.targetRef);\n const identityKey = ImplicitManyToManyIdentifier.getModelKey(\n descriptor.sourceModelKey,\n descriptor.sourceSchemaFieldKey,\n targetModel.metadata.key\n );\n\n const pkSource = ImplicitManyToManyThroughFactory.readSinglePrimaryKey(sourceModel);\n const pkTarget = ImplicitManyToManyThroughFactory.readSinglePrimaryKey(targetModel);\n\n const digest = ImplicitManyToManyIdentifier.getTableBaseDigest(\n descriptor.sourceModelKey,\n descriptor.sourceSchemaFieldKey,\n targetModel.metadata.key\n );\n const tableName = ImplicitManyToManyThroughFactory.allocateTableName(occupiedTables, digest);\n\n const selfReferential = sourceModel.metadata.key === targetModel.metadata.key;\n let throughSchema: z.ZodObject<z.ZodRawShape>;\n let indexes: IndexDef[];\n\n if (selfReferential) {\n const leftKey = `from${sourceModel.metadata.name}`;\n const rightKey = `to${sourceModel.metadata.name}`;\n\n throughSchema = z.object({\n id: t.primaryKey(z.number().int()),\n [leftKey]: t.foreignKey(sourceModel as ModelRef, {\n field: pkSource.zod,\n onDelete: InternalReferentialAction.CASCADE,\n onUpdate: InternalReferentialAction.CASCADE,\n }),\n [rightKey]: t.foreignKey(sourceModel as ModelRef, {\n field: pkTarget.zod,\n onDelete: InternalReferentialAction.CASCADE,\n onUpdate: InternalReferentialAction.CASCADE,\n }),\n });\n indexes = [\n {\n name: `${tableName}_uniq_pair`,\n on: [leftKey, rightKey],\n unique: true,\n },\n ];\n } else {\n const sourceIdKey = `${decapitalizeModelName(sourceModel.metadata.name)}Id`;\n const targetIdKey = `${decapitalizeModelName(targetModel.metadata.name)}Id`;\n\n throughSchema = z.object({\n id: t.primaryKey(z.number().int()),\n [sourceIdKey]: t.foreignKey(sourceModel as ModelRef, {\n field: pkSource.zod,\n onDelete: InternalReferentialAction.CASCADE,\n onUpdate: InternalReferentialAction.CASCADE,\n }),\n [targetIdKey]: t.foreignKey(targetModel as ModelRef, {\n field: pkTarget.zod,\n onDelete: InternalReferentialAction.CASCADE,\n onUpdate: InternalReferentialAction.CASCADE,\n }),\n });\n\n indexes = [\n {\n name: `${tableName}_uniq_pair`,\n on: [sourceIdKey, targetIdKey],\n unique: true,\n },\n ];\n }\n\n const modelNamePart = ImplicitManyToManyIdentifier.getModelName(identityKey);\n\n const throughModel = InternalSchemaModel.create(\n {\n namespace: ImplicitManyToManyIdentifier.getNamespace(),\n name: modelNamePart,\n table: tableName,\n schema: throughSchema,\n registry,\n indexes,\n managed: true,\n },\n registry\n );\n\n models.push(throughModel);\n }\n\n return models;\n }\n\n private static unwrapForForeignKeyField(zodType: ZodTypeAny): ZodTypeAny {\n let inner: ZodTypeAny = zodType;\n while (isZodOptional(inner)) {\n inner = inner.unwrap() as ZodTypeAny;\n }\n while (isZodNullable(inner)) {\n inner = inner.unwrap() as ZodTypeAny;\n }\n while (isZodDefault(inner)) {\n inner = inner.removeDefault() as ZodTypeAny;\n }\n return inner;\n }\n\n private static clonePrimaryKeySchemaForForeignKey(zodType: ZodTypeAny): ZodTypeAny {\n const unwrapped = ImplicitManyToManyThroughFactory.unwrapForForeignKeyField(zodType);\n\n if (isZodNumber(unwrapped)) {\n const checks = unwrapped._zod.def.checks ?? [];\n const isInt = checks.some((check) => 'format' in check._zod.def && check._zod.def.format === 'safeint');\n return isInt ? z.number().int() : z.number();\n }\n\n if (isZodString(unwrapped)) {\n return z.string();\n }\n\n if (isZodBoolean(unwrapped)) {\n return z.boolean();\n }\n\n if (isZodDate(unwrapped)) {\n return z.date();\n }\n\n if (isZodObject(unwrapped)) {\n return z.object({});\n }\n\n if (isZodArray(unwrapped)) {\n return z.array(z.unknown());\n }\n\n throw new Error('Implicit many-to-many primary keys must resolve to a clonable scalar Zod schema.');\n }\n\n private static readSinglePrimaryKey(model: Model): PrimaryKeyShape {\n const keys: string[] = [];\n for (const [fieldKey, zodType] of Object.entries(model.schema.shape)) {\n const meta = getFieldMetadata(zodType as ZodTypeAny);\n if (meta?.primaryKey) {\n keys.push(fieldKey);\n }\n }\n\n if (keys.length !== 1) {\n throw new Error(\n `Implicit many-to-many requires model '${model.metadata.key}' to declare exactly one primary key field.`\n );\n }\n\n const fieldKey = keys[0]!;\n const zodType = model.schema.shape[fieldKey] as ZodTypeAny;\n const meta = getFieldMetadata(zodType);\n return {\n fieldKey,\n zod: ImplicitManyToManyThroughFactory.clonePrimaryKeySchemaForForeignKey(zodType),\n dbColumn: meta?.dbColumn ?? fieldKey,\n };\n }\n\n private static collectImplicitDescriptors(registry: ModelRegistry): NormalizedRelationStorageDescriptor[] {\n const out: NormalizedRelationStorageDescriptor[] = [];\n for (const model of registry.values()) {\n for (const descriptor of InternalSchemaModel.getNormalizedRelations(model)) {\n if (descriptor.origin !== InternalNormalizedRelationOrigin.MANY_TO_MANY) {\n continue;\n }\n if (\n descriptor.throughModelRef &&\n descriptor.throughSourceFieldName &&\n descriptor.throughTargetFieldName\n ) {\n continue;\n }\n out.push(descriptor);\n }\n }\n return out;\n }\n\n private static allocateTableName(occupied: Set<string>, digest: string): string {\n const base = `m2m_${digest}`;\n let candidate = base;\n let suffix = 0;\n while (occupied.has(candidate.toLowerCase())) {\n suffix += 1;\n candidate = `${base}_${suffix}`;\n }\n occupied.add(candidate.toLowerCase());\n return candidate;\n }\n}\n","import type { Model, RelationDef } from '../../domain/index';\nimport type { FinalizedStorageArtifacts } from '../fields/FinalizedStorageArtifacts';\nimport { InternalSchemaModel } from '../internal/InternalSchemaModel';\nimport type { ResolvedRelationGraphSnapshot } from '../registry/ResolvedRelationGraphSnapshot';\nimport {\n InternalNormalizedRelationOrigin,\n type NormalizedRelationStorageDescriptor,\n} from './NormalizedRelationStorageDescriptor';\nimport type { ResolvedRelationDescriptor, ResolvedRelationGraph } from './ResolvedRelationGraph';\nimport {\n type RelationCardinality,\n InternalRelationCardinality,\n InternalRelationPublicKind,\n InternalRelationProvenance,\n InternalRelationStorageStrategy,\n} from './RelationSpec';\nimport { ImplicitManyToManyThroughFactory } from './ImplicitManyToManyThroughFactory';\nimport { ImplicitManyToManyIdentifier } from './ImplicitManyToManyIdentifier';\nimport { pluralize, toSnakeCase } from './SchemaNaming';\n\nconst REFERENCE_CAPABILITIES = Object.freeze({\n migratable: true,\n queryable: true,\n hydratable: true,\n});\nconst MANY_TO_MANY_CAPABILITIES = Object.freeze({\n migratable: false,\n queryable: true,\n hydratable: true,\n});\nconst RELATION_NAME_SEPARATOR = ':';\n\ntype GraphBuilderOptions = {\n version: number;\n models: readonly Model[];\n storage: FinalizedStorageArtifacts;\n resolveRef: (ref: NormalizedRelationStorageDescriptor['targetRef']) => Model;\n};\n\n/**\n * Resolution-stage builder that turns normalized relation descriptors into the\n * registry-scoped resolved relation graph.\n *\n * This is the final pipeline stage in the relations subdomain. It combines:\n *\n * - normalized field-authored relation descriptors\n * - explicit model-level relation names from `RelationBuilder`\n * - finalized storage artifacts from the registry\n *\n * The result is the canonical named relation graph used by ORM-facing\n * consumers.\n */\nexport class ResolvedRelationGraphBuilder {\n private readonly byModel = new Map<string, Map<string, ResolvedRelationDescriptor>>();\n private readonly byEdgeId = new Map<string, ResolvedRelationDescriptor>();\n private readonly matchedOverrides = new Set<string>();\n\n constructor(private readonly options: GraphBuilderOptions) {}\n\n static build(options: GraphBuilderOptions): ResolvedRelationGraph {\n return new ResolvedRelationGraphBuilder(options).build();\n }\n\n /**\n * Serialize a resolved graph into the canonical snapshot shape used by\n * relation-registry code generation and fingerprinting.\n */\n static createSnapshot(graph: ResolvedRelationGraph): ResolvedRelationGraphSnapshot {\n return {\n models: Array.from(graph.byModel.entries())\n .sort(([left], [right]) => left.localeCompare(right))\n .map(([key, relations]) => ({\n key,\n relations: Array.from(relations.values())\n .sort((left, right) => left.name.localeCompare(right.name))\n .map((relation) => ({\n edgeId: relation.edgeId,\n sourceModelKey: relation.sourceModelKey,\n targetModelKey: relation.targetModelKey,\n name: relation.name,\n inverseEdgeId: relation.inverseEdgeId,\n kind: relation.kind,\n storageStrategy: relation.storageStrategy,\n cardinality: relation.cardinality,\n localFieldName: relation.localFieldName,\n targetFieldName: relation.targetFieldName,\n throughModelKey: relation.throughModelKey,\n throughTable: relation.throughTable,\n throughSourceFieldName: relation.throughSourceFieldName,\n throughTargetFieldName: relation.throughTargetFieldName,\n throughSourceKey: relation.throughSourceKey,\n throughTargetKey: relation.throughTargetKey,\n alias: relation.alias,\n capabilities: {\n migratable: relation.capabilities.migratable,\n queryable: relation.capabilities.queryable,\n hydratable: relation.capabilities.hydratable,\n },\n })),\n })),\n };\n }\n\n /**\n * Resolve every model's normalized relation descriptors into a single\n * registry-scoped graph and fail when authoring ambiguity remains.\n */\n build(): ResolvedRelationGraph {\n for (const model of this.options.models) {\n this.addModelRelations(model);\n }\n\n for (const model of this.options.models) {\n this.assertAllOverridesMatched(model);\n }\n\n return {\n version: this.options.version,\n byModel: this.byModel,\n byEdgeId: this.byEdgeId,\n };\n }\n\n private addModelRelations(model: Model): void {\n const explicitRelations = InternalSchemaModel.getExplicitRelations(model) ?? {};\n\n for (const descriptor of InternalSchemaModel.getNormalizedRelations(model)) {\n const targetModel = this.options.resolveRef(descriptor.targetRef);\n\n if (descriptor.origin === InternalNormalizedRelationOrigin.MANY_TO_MANY) {\n const relationName = descriptor.explicitForwardName ?? descriptor.namingHint;\n let throughModel: Model;\n let throughSourceFieldName: string;\n let throughTargetFieldName: string;\n\n if (\n descriptor.throughModelRef &&\n descriptor.throughSourceFieldName &&\n descriptor.throughTargetFieldName\n ) {\n throughModel = this.options.resolveRef(descriptor.throughModelRef);\n throughSourceFieldName = descriptor.throughSourceFieldName;\n throughTargetFieldName = descriptor.throughTargetFieldName;\n } else {\n throughModel = this.options.resolveRef(\n ImplicitManyToManyIdentifier.getModelKey(\n model.metadata.key,\n descriptor.sourceSchemaFieldKey,\n targetModel.metadata.key\n )\n );\n const implicitNames = ImplicitManyToManyThroughFactory.throughFieldNames(model, targetModel);\n throughSourceFieldName = implicitNames.throughSourceFieldName;\n throughTargetFieldName = implicitNames.throughTargetFieldName;\n }\n\n const throughNormalized = InternalSchemaModel.getNormalizedRelations(throughModel);\n const throughSource = throughNormalized.find(\n (rel) => rel.sourceSchemaFieldKey === throughSourceFieldName\n );\n const throughTarget = throughNormalized.find(\n (rel) => rel.sourceSchemaFieldKey === throughTargetFieldName\n );\n if (!throughSource || !throughTarget) {\n throw new Error(\n `Many-to-many relation '${relationName}' on model '${model.metadata.key}' cannot find through fields on '${throughModel.metadata.key}'.`\n );\n }\n\n const throughStorage = this.options.storage.byModel.get(throughModel.metadata.key);\n if (!throughStorage) {\n throw new Error(\n `Many-to-many relation '${relationName}' on model '${model.metadata.key}' cannot resolve storage artifacts for through model '${throughModel.metadata.key}'.`\n );\n }\n\n this.addResolvedRelation({\n edgeId: descriptor.edgeId,\n sourceModelKey: model.metadata.key,\n targetModelKey: targetModel.metadata.key,\n name: relationName,\n kind: InternalRelationPublicKind.MANY_TO_MANY,\n storageStrategy: InternalRelationStorageStrategy.MANY_TO_MANY,\n cardinality: InternalRelationCardinality.MANY,\n capabilities: MANY_TO_MANY_CAPABILITIES,\n provenance: InternalRelationProvenance.FIELD_DECORATOR,\n alias: `${toSnakeCase(model.metadata.name)}_${relationName}`,\n throughModelKey: throughModel.metadata.key,\n throughTable: throughStorage.table,\n throughSourceFieldName,\n throughTargetFieldName,\n throughSourceKey: throughSource.dbColumnName,\n throughTargetKey: throughTarget.dbColumnName,\n });\n continue;\n }\n\n this.addReferenceRelations(model, descriptor, targetModel, explicitRelations);\n }\n }\n\n private addReferenceRelations(\n sourceModel: Model,\n descriptor: NormalizedRelationStorageDescriptor,\n targetModel: Model,\n explicitRelations: Readonly<Record<string, RelationDef>>\n ): void {\n const forwardOverride = this.findForwardOverride(sourceModel, targetModel, descriptor, explicitRelations);\n if (forwardOverride) {\n this.markOverrideMatched(sourceModel.metadata.key, forwardOverride[0]);\n }\n\n const forwardName = forwardOverride?.[0] ?? descriptor.explicitForwardName ?? descriptor.namingHint;\n const targetPrimaryKey = this.getPrimaryKey(targetModel.metadata.key);\n this.addResolvedRelation({\n edgeId: descriptor.edgeId,\n sourceModelKey: sourceModel.metadata.key,\n targetModelKey: targetModel.metadata.key,\n name: forwardName,\n inverseEdgeId: `${descriptor.edgeId}:inverse`,\n kind: InternalRelationPublicKind.BELONGS_TO,\n storageStrategy: InternalRelationStorageStrategy.REFERENCE,\n cardinality: InternalRelationCardinality.SINGLE,\n localFieldName: descriptor.dbColumnName,\n targetFieldName: descriptor.referencedTargetColumn ?? targetPrimaryKey,\n capabilities: REFERENCE_CAPABILITIES,\n provenance: InternalRelationProvenance.FIELD_DECORATOR,\n alias: `${toSnakeCase(targetModel.metadata.name)}_${forwardName}`,\n });\n\n if (ImplicitManyToManyIdentifier.isImplicitManyToManyModel(sourceModel.metadata.key)) {\n return;\n }\n\n const reverseOverride = this.findReverseOverride(sourceModel, targetModel, descriptor);\n if (reverseOverride) {\n this.markOverrideMatched(targetModel.metadata.key, reverseOverride[0]);\n }\n\n const reverseKind = descriptor.unique\n ? InternalRelationPublicKind.HAS_ONE\n : InternalRelationPublicKind.HAS_MANY;\n const reverseCardinality = descriptor.unique\n ? InternalRelationCardinality.SINGLE\n : InternalRelationCardinality.MANY;\n const reverseName =\n reverseOverride?.[0] ??\n descriptor.explicitReverseName ??\n this.deriveReverseName(sourceModel, reverseCardinality);\n this.addResolvedRelation({\n edgeId: `${descriptor.edgeId}:inverse`,\n sourceModelKey: targetModel.metadata.key,\n targetModelKey: sourceModel.metadata.key,\n name: reverseName,\n inverseEdgeId: descriptor.edgeId,\n kind: reverseKind,\n storageStrategy: InternalRelationStorageStrategy.REVERSE_REFERENCE,\n cardinality: reverseCardinality,\n localFieldName: descriptor.dbColumnName,\n targetFieldName: descriptor.referencedTargetColumn ?? targetPrimaryKey,\n capabilities: REFERENCE_CAPABILITIES,\n provenance: reverseOverride\n ? InternalRelationProvenance.RELATIONS_API\n : InternalRelationProvenance.SYNTHESIZED_REVERSE,\n alias: `${toSnakeCase(sourceModel.metadata.name)}_${reverseName}`,\n });\n }\n\n private findForwardOverride(\n sourceModel: Model,\n targetModel: Model,\n descriptor: NormalizedRelationStorageDescriptor,\n explicitRelations: Readonly<Record<string, RelationDef>>\n ): [string, RelationDef] | undefined {\n return Object.entries(explicitRelations).find(([, relation]) => {\n const relationTargetKey = this.resolveRelationTargetKey(sourceModel, relation.target);\n return (\n relation.type === InternalRelationPublicKind.BELONGS_TO &&\n relationTargetKey === targetModel.metadata.key &&\n relation.foreignKey === descriptor.sourceSchemaFieldKey\n );\n });\n }\n\n private findReverseOverride(\n sourceModel: Model,\n targetModel: Model,\n descriptor: NormalizedRelationStorageDescriptor\n ): [string, RelationDef] | undefined {\n const reverseModelRelations = InternalSchemaModel.getExplicitRelations(targetModel) ?? {};\n const reverseKind = descriptor.unique\n ? InternalRelationPublicKind.HAS_ONE\n : InternalRelationPublicKind.HAS_MANY;\n return Object.entries(reverseModelRelations).find(([, relation]) => {\n const relationTargetKey = this.resolveRelationTargetKey(targetModel, relation.target);\n return (\n relationTargetKey === sourceModel.metadata.key &&\n relation.type === reverseKind &&\n relation.foreignKey === descriptor.sourceSchemaFieldKey\n );\n });\n }\n\n private assertAllOverridesMatched(model: Model): void {\n const explicitRelations = InternalSchemaModel.getExplicitRelations(model);\n if (!explicitRelations) {\n return;\n }\n\n for (const relationName of Object.keys(explicitRelations)) {\n const marker = this.buildOverrideMarker(model.metadata.key, relationName);\n if (!this.matchedOverrides.has(marker)) {\n throw new Error(\n `Relation override '${relationName}' on model '${model.metadata.key}' does not match a field-authored relation.`\n );\n }\n }\n }\n\n private addResolvedRelation(descriptor: ResolvedRelationDescriptor): void {\n const modelRelations =\n this.byModel.get(descriptor.sourceModelKey) ?? new Map<string, ResolvedRelationDescriptor>();\n const existing = modelRelations.get(descriptor.name);\n if (existing) {\n throw new Error(\n `Ambiguous relation name '${descriptor.name}' on model '${descriptor.sourceModelKey}'. Add an explicit relations override.`\n );\n }\n\n modelRelations.set(descriptor.name, descriptor);\n this.byModel.set(descriptor.sourceModelKey, modelRelations);\n this.byEdgeId.set(descriptor.edgeId, descriptor);\n }\n\n private getPrimaryKey(modelKey: string): string {\n return this.options.storage.byModel.get(modelKey)!.pk;\n }\n\n private markOverrideMatched(modelKey: string, relationName: string): void {\n this.matchedOverrides.add(this.buildOverrideMarker(modelKey, relationName));\n }\n\n private buildOverrideMarker(modelKey: string, relationName: string): string {\n return `${modelKey}${RELATION_NAME_SEPARATOR}${relationName}`;\n }\n\n private resolveRelationTargetKey(sourceModel: Model, target: string): string {\n if (target.includes('/')) {\n return target;\n }\n\n return `${sourceModel.metadata.namespace}/${target}`;\n }\n\n private deriveReverseName(sourceModel: Model, cardinality: RelationCardinality): string {\n if (sourceModel.metadata.defaultRelatedName) {\n return sourceModel.metadata.defaultRelatedName;\n }\n\n const snake = toSnakeCase(sourceModel.metadata.name);\n return cardinality === InternalRelationCardinality.MANY ? pluralize(snake) : snake;\n }\n}\n","import type { ResolvedRelationGraphSnapshot } from './ResolvedRelationGraphSnapshot';\n\n// These constants define the current generated-relation artifact contract.\n// They are centralized here so codegen, runtime drift checks, and CLI commands\n// share one default location and filename scheme.\nexport const GENERATED_RELATION_REGISTRY_DIRNAME = '.tango';\nexport const GENERATED_RELATION_REGISTRY_TYPES_FILENAME = 'relations.generated.d.ts';\nexport const GENERATED_RELATION_REGISTRY_METADATA_FILENAME = 'relations.generated.json';\nexport const GENERATED_RELATION_REGISTRY_METADATA_VERSION = 1;\n\nexport type GeneratedRelationRegistryArtifact = {\n version: typeof GENERATED_RELATION_REGISTRY_METADATA_VERSION;\n fingerprint: string;\n snapshot: ResolvedRelationGraphSnapshot;\n};\n","// oxlint-disable unicorn/no-static-only-class\nimport { createHash } from 'node:crypto';\nimport type { ResolvedRelationGraph } from '../relations/ResolvedRelationGraph';\nimport { ResolvedRelationGraphBuilder } from '../relations/ResolvedRelationGraphBuilder';\nimport type { ResolvedRelationGraphSnapshot } from './ResolvedRelationGraphSnapshot';\n\n/**\n * Build canonical serialized artifacts from a resolved relation graph.\n *\n * Generation, drift detection, and related tooling all need the same stable\n * snapshot shape and fingerprinting rules, so that work lives behind one class\n * instead of a pair of free functions.\n */\nexport class ResolvedRelationGraphArtifactFactory {\n static createSnapshot(graph: ResolvedRelationGraph): ResolvedRelationGraphSnapshot {\n return ResolvedRelationGraphBuilder.createSnapshot(graph);\n }\n\n static createFingerprint(value: ResolvedRelationGraph | ResolvedRelationGraphSnapshot): string {\n const snapshot = 'byModel' in value ? ResolvedRelationGraphArtifactFactory.createSnapshot(value) : value;\n return createHash('sha256').update(JSON.stringify(snapshot)).digest('hex');\n }\n}\n","import { AsyncLocalStorage } from 'node:async_hooks';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { getLogger } from '@danceroutine/tango-core';\nimport type { Field, Model } from '../../domain/index';\nimport type { ZodTypeAny } from '../decorators/domain/ZodTypeAny';\nimport { isTypedModelRef, type ModelRef } from '../decorators/domain/ModelRef';\nimport { inferFieldsFromSchema } from '../fields/inferFieldsFromSchema';\nimport { getFieldMetadata } from '../fields/FieldMetadataStore';\nimport type { FinalizedStorageArtifacts, FinalizedStorageModel } from '../fields/FinalizedStorageArtifacts';\nimport { InternalSchemaModel } from '../internal/InternalSchemaModel';\nimport type { ResolvedRelationGraph } from '../relations/ResolvedRelationGraph';\nimport { ResolvedRelationGraphBuilder } from '../relations/ResolvedRelationGraphBuilder';\nimport {\n GENERATED_RELATION_REGISTRY_DIRNAME,\n GENERATED_RELATION_REGISTRY_METADATA_FILENAME,\n GENERATED_RELATION_REGISTRY_METADATA_VERSION,\n type GeneratedRelationRegistryArtifact,\n} from './GeneratedRelationRegistryArtifact';\nimport { ResolvedRelationGraphArtifactFactory } from './ResolvedRelationGraphArtifactFactory';\nimport type { ResolvedRelationGraphSnapshot } from './ResolvedRelationGraphSnapshot';\nimport { ImplicitManyToManyIdentifier } from '../relations/ImplicitManyToManyIdentifier';\nimport { ImplicitManyToManyThroughFactory } from '../relations/ImplicitManyToManyThroughFactory';\n\nconst DEFAULT_IDENTIFIER_NAME = 'id';\nconst ACTIVE_REGISTRY_STORAGE_KEY = Symbol.for('tango.schema.activeRegistryStorage');\n\ntype ModelRegistryRuntimeGlobal = typeof globalThis & {\n [ACTIVE_REGISTRY_STORAGE_KEY]?: AsyncLocalStorage<ModelRegistry>;\n};\n\n/**\n * Registry that resolves Tango models by stable identity.\n *\n * The default shared registry is convenient for application bootstrapping\n * within one schema package instance, while dedicated instances are useful in\n * tests and tooling. Explicit active-registry binding stays process-shared so\n * tooling can construct models across separate schema package copies without\n * relying on the ambient default registry.\n */\nexport class ModelRegistry {\n private static globalRegistry?: ModelRegistry;\n private readonly models = new Map<string, Model>();\n private version = 0;\n private storageCache?: FinalizedStorageArtifacts;\n private relationGraphCache?: ResolvedRelationGraph;\n private lastRelationRegistryDriftCheckVersion?: number;\n\n /**\n * Return the shared default registry used by `Model(...)` for this schema\n * package instance.\n */\n static global(): ModelRegistry {\n ModelRegistry.globalRegistry ??= new ModelRegistry();\n return ModelRegistry.globalRegistry;\n }\n\n /**\n * Return the registry currently bound to model construction work.\n *\n * This explicit binding is process-shared so code that imports separate\n * schema package copies can still participate in one construction flow.\n */\n static active(): ModelRegistry {\n return ModelRegistry.activeRegistryStorage().getStore() ?? ModelRegistry.global();\n }\n\n /**\n * Run work with a specific registry bound as the active construction target.\n */\n static async runWithRegistry<T>(registry: ModelRegistry, work: () => Promise<T> | T): Promise<T> {\n return await ModelRegistry.activeRegistryStorage().run(registry, work);\n }\n\n /**\n * Register a model on the shared global registry.\n */\n static register(model: Model): void {\n ModelRegistry.global().register(model);\n }\n\n /**\n * Register several models on the shared global registry.\n */\n static registerMany(models: readonly Model[]): void {\n ModelRegistry.global().registerMany(models);\n }\n\n /**\n * Resolve a model from the shared registry by namespace and name.\n */\n static get(namespace: string, name: string): Model | undefined {\n return ModelRegistry.global().get(namespace, name);\n }\n\n /**\n * Resolve a model from the shared registry by its `namespace/name` key.\n */\n static getByKey(key: string): Model | undefined {\n return ModelRegistry.global().getByKey(key);\n }\n\n /**\n * Resolve any supported model reference form against the shared registry.\n */\n static resolveRef(ref: ModelRef): Model {\n return ModelRegistry.global().resolveRef(ref);\n }\n\n /**\n * Clear the shared registry, which is mainly useful in tests.\n */\n static clear(): void {\n ModelRegistry.global().clear();\n }\n\n /**\n * Return the owning registry for a model.\n */\n static getOwner(model: { metadata: { key?: string } } & object): ModelRegistry {\n return InternalSchemaModel.getRegistryOwner(model as Model);\n }\n\n private static runtimeGlobal(): ModelRegistryRuntimeGlobal {\n return globalThis as ModelRegistryRuntimeGlobal;\n }\n\n private static activeRegistryStorage(): AsyncLocalStorage<ModelRegistry> {\n const runtimeGlobal = ModelRegistry.runtimeGlobal();\n\n if (!runtimeGlobal[ACTIVE_REGISTRY_STORAGE_KEY]) {\n runtimeGlobal[ACTIVE_REGISTRY_STORAGE_KEY] = new AsyncLocalStorage<ModelRegistry>();\n }\n\n return runtimeGlobal[ACTIVE_REGISTRY_STORAGE_KEY];\n }\n\n /**\n * Register a model on this registry instance.\n */\n register(model: Model): void {\n // A model's finalized storage and relation artifacts are registry-scoped.\n // Rejecting cross-registry reuse here prevents one model object from\n // publishing conflicting finalized views in multiple registries.\n const owner = InternalSchemaModel.getRegistryOwner(model);\n if (owner !== this) {\n throw new Error(\n `Model '${model.metadata.key}' belongs to a different registry and cannot be registered here.`\n );\n }\n\n const existing = this.models.get(model.metadata.key);\n if (existing && existing !== model) {\n throw new Error(`Model '${model.metadata.key}' is already registered in this registry.`);\n }\n\n this.models.set(model.metadata.key, model);\n this.bumpVersion();\n }\n\n /**\n * Register several models on this registry instance.\n */\n registerMany(models: readonly Model[]): void {\n for (const model of models) {\n this.register(model);\n }\n }\n\n /**\n * Resolve a model from this registry instance by namespace and name.\n */\n get(namespace: string, name: string): Model | undefined {\n return this.getByKey(`${namespace}/${name}`);\n }\n\n /**\n * Resolve a model from this registry instance by its `namespace/name` key.\n */\n getByKey(key: string): Model | undefined {\n return this.models.get(key);\n }\n\n /**\n * Resolve a string, callback, or direct model reference into a model object.\n */\n resolveRef(ref: ModelRef): Model {\n if (typeof ref === 'string' || isTypedModelRef(ref)) {\n const key = typeof ref === 'string' ? ref : ref.key;\n const model = this.getByKey(key);\n if (!model) {\n throw new Error(\n `Unable to resolve model reference '${key}'. Ensure it is registered in ModelRegistry.`\n );\n }\n return model;\n }\n\n const model = typeof ref === 'function' ? ref() : ref;\n if (InternalSchemaModel.getRegistryOwner(model) !== this) {\n throw new Error(\n `Model reference '${model.metadata.key}' belongs to a different registry and cannot be resolved here.`\n );\n }\n return model;\n }\n\n /**\n * Finalize storage-only artifacts for all models in this registry.\n */\n finalizeStorageArtifacts(): FinalizedStorageArtifacts {\n if (this.storageCache?.version === this.version) {\n return this.storageCache;\n }\n\n const strippedImplicit = this.stripImplicitManyToManyModels();\n const implicitThroughModels = ImplicitManyToManyThroughFactory.buildModels(this);\n for (const model of implicitThroughModels) {\n this.models.set(model.metadata.key, model);\n }\n if (strippedImplicit || implicitThroughModels.length > 0) {\n this.bumpVersion();\n }\n\n const primaryKeyByModel = new Map<string, string>();\n for (const model of this.models.values()) {\n primaryKeyByModel.set(model.metadata.key, this.inferPrimaryKeyName(model));\n }\n\n const byModel = new Map<string, FinalizedStorageModel>();\n for (const model of this.models.values()) {\n const explicitFields = InternalSchemaModel.getExplicitFields(model);\n const inferredFields = inferFieldsFromSchema(model.schema, {\n registry: this,\n resolveReferenceTarget: (target) => {\n const targetModel = this.resolveRef(target);\n return {\n table: targetModel.metadata.table,\n pk: primaryKeyByModel.get(targetModel.metadata.key)!,\n };\n },\n });\n const fields = this.freezeFields(this.mergeStorageFields(inferredFields, explicitFields));\n const primaryKey = fields.find((field) => field.primaryKey)?.name ?? DEFAULT_IDENTIFIER_NAME;\n\n byModel.set(model.metadata.key, {\n key: model.metadata.key,\n table: model.metadata.table,\n fields,\n pk: primaryKey,\n });\n }\n\n const finalized: FinalizedStorageArtifacts = {\n version: this.version,\n byModel,\n };\n this.storageCache = finalized;\n return finalized;\n }\n\n /**\n * Return finalized storage fields for a specific model.\n */\n getFinalizedFields(model: Model | string): readonly Field[] {\n const key = typeof model === 'string' ? model : model.metadata.key;\n const fields = this.finalizeStorageArtifacts().byModel.get(key)?.fields;\n if (!fields) {\n throw new Error(`No finalized storage fields are available for model '${key}'.`);\n }\n return fields;\n }\n\n /**\n * Resolve the registry's relation graph from finalized storage artifacts.\n */\n getResolvedRelationGraph(): ResolvedRelationGraph {\n if (this.relationGraphCache?.version === this.version) {\n return this.relationGraphCache;\n }\n\n // The registry owns cache/version orchestration. The dedicated builder owns\n // forward edge resolution, reverse synthesis, and override validation.\n const storage = this.finalizeStorageArtifacts();\n const finalized = ResolvedRelationGraphBuilder.build({\n version: this.version,\n models: this.values(),\n storage,\n resolveRef: (ref) => this.resolveRef(ref),\n });\n this.relationGraphCache = finalized;\n this.warnOnGeneratedRelationRegistryDrift(finalized);\n return finalized;\n }\n\n /**\n * Return a canonical snapshot of the resolved relation graph.\n */\n getResolvedRelationGraphSnapshot(): ResolvedRelationGraphSnapshot {\n return ResolvedRelationGraphArtifactFactory.createSnapshot(this.getResolvedRelationGraph());\n }\n\n /**\n * Return a deterministic fingerprint for the resolved relation graph.\n */\n getResolvedRelationGraphFingerprint(): string {\n return ResolvedRelationGraphArtifactFactory.createFingerprint(this.getResolvedRelationGraph());\n }\n\n /**\n * Remove all registered models from this registry instance.\n */\n clear(): void {\n this.models.clear();\n this.bumpVersion();\n }\n\n /**\n * Return all registered models in insertion order.\n */\n values(): readonly Model[] {\n return Array.from(this.models.values());\n }\n\n private bumpVersion(): void {\n this.version += 1;\n this.storageCache = undefined;\n this.relationGraphCache = undefined;\n this.lastRelationRegistryDriftCheckVersion = undefined;\n }\n\n private stripImplicitManyToManyModels(): boolean {\n let removed = false;\n for (const key of this.models.keys()) {\n if (ImplicitManyToManyIdentifier.isImplicitManyToManyModel(key)) {\n this.models.delete(key);\n removed = true;\n }\n }\n return removed;\n }\n\n private freezeFields(fields: readonly Field[]): readonly Field[] {\n return Object.freeze(fields.map((field) => Object.freeze({ ...field })));\n }\n\n private inferPrimaryKeyName(model: Model): string {\n for (const [fieldKey, zodType] of Object.entries(model.schema.shape)) {\n const meta = getFieldMetadata(zodType as ZodTypeAny);\n if (meta?.primaryKey) {\n return meta.dbColumn ?? fieldKey;\n }\n }\n\n const explicitFields = InternalSchemaModel.getExplicitFields(model);\n if (explicitFields) {\n return explicitFields.find((field) => field.primaryKey)?.name ?? DEFAULT_IDENTIFIER_NAME;\n }\n\n return DEFAULT_IDENTIFIER_NAME;\n }\n\n private mergeStorageFields(inferredFields: readonly Field[], explicitFields?: readonly Field[]): readonly Field[] {\n if (!explicitFields?.length) {\n return inferredFields;\n }\n\n const mergedFields = new Map(inferredFields.map((field) => [field.name, field]));\n for (const explicitField of explicitFields) {\n mergedFields.set(explicitField.name, explicitField);\n }\n\n return Array.from(mergedFields.values());\n }\n\n private warnOnGeneratedRelationRegistryDrift(graph: ResolvedRelationGraph): void {\n if (\n this.lastRelationRegistryDriftCheckVersion === this.version ||\n !this.shouldCheckGeneratedRelationRegistry()\n ) {\n return;\n }\n this.lastRelationRegistryDriftCheckVersion = this.version;\n\n const expected = this.readGeneratedRelationRegistryArtifact();\n if (!expected) {\n return;\n }\n\n // Compare against the same canonical snapshot shape that code\n // generation writes so drift checks operate on one shared contract.\n const liveSnapshot = ResolvedRelationGraphArtifactFactory.createSnapshot(graph);\n if (this.isPartialRegistrySnapshot(liveSnapshot, expected.snapshot)) {\n return;\n }\n\n const liveFingerprint = ResolvedRelationGraphArtifactFactory.createFingerprint(liveSnapshot);\n if (liveFingerprint === expected.fingerprint) {\n return;\n }\n\n getLogger('tango.schema.registry').warn(\n `Generated relation registry drift detected. Run 'tango codegen relations' to refresh ${GENERATED_RELATION_REGISTRY_DIRNAME}/${GENERATED_RELATION_REGISTRY_METADATA_FILENAME}.`\n );\n }\n\n private shouldCheckGeneratedRelationRegistry(): boolean {\n return process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';\n }\n\n private readGeneratedRelationRegistryArtifact(): GeneratedRelationRegistryArtifact | undefined {\n const metadataPath = resolve(\n process.cwd(),\n GENERATED_RELATION_REGISTRY_DIRNAME,\n GENERATED_RELATION_REGISTRY_METADATA_FILENAME\n );\n if (!existsSync(metadataPath)) {\n return undefined;\n }\n\n try {\n const parsed = JSON.parse(readFileSync(metadataPath, 'utf8')) as Partial<GeneratedRelationRegistryArtifact>;\n if (\n parsed.version !== GENERATED_RELATION_REGISTRY_METADATA_VERSION ||\n typeof parsed.fingerprint !== 'string' ||\n !parsed.snapshot ||\n !Array.isArray(parsed.snapshot.models)\n ) {\n getLogger('tango.schema.registry').warn(\n `Ignoring malformed generated relation registry metadata at '${metadataPath}'.`\n );\n return undefined;\n }\n\n return parsed as GeneratedRelationRegistryArtifact;\n } catch (error) {\n getLogger('tango.schema.registry').warn(\n `Unable to read generated relation registry metadata at '${metadataPath}'.`,\n error\n );\n return undefined;\n }\n }\n\n private isPartialRegistrySnapshot(\n liveSnapshot: ResolvedRelationGraphSnapshot,\n expectedSnapshot: ResolvedRelationGraphSnapshot\n ): boolean {\n const expectedModels = new Map(expectedSnapshot.models.map((model) => [model.key, model]));\n if (liveSnapshot.models.some((model) => !expectedModels.has(model.key))) {\n return false;\n }\n\n if (liveSnapshot.models.length >= expectedSnapshot.models.length) {\n return false;\n }\n\n for (const model of liveSnapshot.models) {\n const expectedModel = expectedModels.get(model.key)!;\n if (JSON.stringify(model.relations) !== JSON.stringify(expectedModel.relations)) {\n return false;\n }\n }\n\n return true;\n }\n}\n","import { existsSync } from 'node:fs';\nimport { dirname, extname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nconst LOCAL_ENTRYPOINT_CANDIDATES = ['./index.ts', './index.js'] as const;\n\n/**\n * Resolve the current package root entrypoint for `@danceroutine/tango-schema`.\n *\n * Tooling loaders alias app-side `@danceroutine/tango-schema` imports back to\n * this path so project modules reuse the same schema package instance across\n * workspace-source and published-dist environments.\n */\nexport function resolveSchemaModuleEntrypoint(): string {\n for (const relativePath of LOCAL_ENTRYPOINT_CANDIDATES) {\n const absolutePath = fileURLToPath(new URL(relativePath, import.meta.url));\n if (existsSync(absolutePath)) {\n return absolutePath;\n }\n }\n\n throw new Error(\n `Unable to resolve the @danceroutine/tango-schema entrypoint relative to '${fileURLToPath(import.meta.url)}'.`\n );\n}\n\n/**\n * Return explicit Jiti alias entries for the schema package root and its\n * public subpaths so app modules always reuse the same schema package instance.\n *\n * @internal\n * Exported for Tango tooling/framework consumption only. This helper exists so\n * Tango loaders can force app modules to reuse the active schema package\n * instance during module execution. It is not intended as a stable application\n * API, and the alias map may be more permissive than the package exports\n * surface by design.\n */\nexport function createSchemaModuleAliases(): Record<string, string> {\n const entrypoint = resolveSchemaModuleEntrypoint();\n const packageRoot = dirname(entrypoint);\n const extension = extname(entrypoint);\n const modelEntrypoint = resolve(packageRoot, 'model', `index${extension}`);\n const domainEntrypoint = resolve(packageRoot, 'domain', `index${extension}`);\n\n if (!existsSync(modelEntrypoint) || !existsSync(domainEntrypoint)) {\n throw new Error(\n `Unable to resolve the @danceroutine/tango-schema subpath entrypoints relative to '${entrypoint}'.`\n );\n }\n\n return {\n '@danceroutine/tango-schema': entrypoint,\n '@danceroutine/tango-schema/model': modelEntrypoint,\n '@danceroutine/tango-schema/domain': domainEntrypoint,\n // Deliberately permissive for tooling-time identity unification. This\n // is not intended to widen the package's supported end-user API.\n '@danceroutine/tango-schema/': `${packageRoot}/`,\n };\n}\n","/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\nexport { ModelRegistry } from './ModelRegistry';\nexport { createSchemaModuleAliases, resolveSchemaModuleEntrypoint } from '../../resolveSchemaModuleEntrypoint';\nexport {\n GENERATED_RELATION_REGISTRY_DIRNAME,\n GENERATED_RELATION_REGISTRY_METADATA_FILENAME,\n GENERATED_RELATION_REGISTRY_METADATA_VERSION,\n GENERATED_RELATION_REGISTRY_TYPES_FILENAME,\n type GeneratedRelationRegistryArtifact,\n} from './GeneratedRelationRegistryArtifact';\nexport { ResolvedRelationGraphArtifactFactory } from './ResolvedRelationGraphArtifactFactory';\nexport {\n type ResolvedRelationGraphSnapshot,\n type ResolvedRelationGraphSnapshotModel,\n type ResolvedRelationGraphSnapshotRelation,\n} from './ResolvedRelationGraphSnapshot';\n","/**\n * Domain boundary barrel for relation authoring.\n *\n * The relations subdomain has three internal layers:\n *\n * - authoring: `RelationBuilder`\n * - normalization: field-authored relations become normalized descriptors\n * - resolution: normalized descriptors become the registry-scoped relation graph\n *\n * Only the authoring surface is exported here. The later pipeline stages stay\n * internal until Tango intentionally publishes them as supported contracts.\n */\nexport { RelationBuilder } from './RelationBuilder';\n","import type { z } from 'zod';\nimport type { Model } from '../domain/Model';\nimport { ModelRegistry } from './registry/ModelRegistry';\n\nexport type ModelAugmentor = <TSchema extends z.ZodObject<z.ZodRawShape>, TKey extends string>(\n model: Model<TSchema, TKey>\n) => void;\n\nconst modelAugmentors = new Set<ModelAugmentor>();\n\n/**\n * Register a model augmentor that runs for existing and future models.\n */\nexport function registerModelAugmentor(augmentor: ModelAugmentor): () => void {\n modelAugmentors.add(augmentor);\n\n for (const model of ModelRegistry.global().values()) {\n augmentor(model);\n }\n\n return () => {\n modelAugmentors.delete(augmentor);\n };\n}\n\n/**\n * Apply all registered augmentors to a model before it is returned publicly.\n */\nexport function applyModelAugmentors<TSchema extends z.ZodObject<z.ZodRawShape>, TKey extends string>(\n model: Model<TSchema, TKey>\n): Model<TSchema, TKey> {\n for (const augmentor of modelAugmentors) {\n augmentor(model);\n }\n\n return model;\n}\n","import { z } from 'zod';\nimport type { Model as SchemaModel } from '../domain/Model';\nimport type { ModelDefinition } from './ModelDefinition';\nimport { applyModelAugmentors } from './ModelAugmentorRegistry';\nimport { InternalSchemaModel } from './internal/InternalSchemaModel';\nimport { ModelRegistry } from './registry/ModelRegistry';\n\n/**\n * Creates a model definition with metadata and schema validation.\n * Automatically finalizes field types through the owning model registry.\n */\nexport function Model<\n const TNamespace extends string,\n const TName extends string,\n TSchema extends z.ZodObject<z.ZodRawShape>,\n>(\n definition: ModelDefinition<TSchema> & { namespace: TNamespace; name: TName }\n): SchemaModel<TSchema, `${TNamespace}/${TName}`> {\n const registry = definition.registry ?? ModelRegistry.active();\n const model = applyModelAugmentors(\n InternalSchemaModel.create(definition, registry) as SchemaModel<TSchema, `${TNamespace}/${TName}`>\n );\n\n registry.register(model);\n return model;\n}\n","/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n *\n * Tango keeps both flat exports and namespaced subdomain barrels here so\n * callers can choose TS-native direct imports or Django-style drill-down\n * access through the bundled `model` namespace at the package root.\n */\n\nexport * as decorators from './decorators/index';\nexport * as meta from './meta/index';\nexport * as constraints from './constraints/index';\nexport * as registry from './registry/index';\nexport * as relations from './relations/index';\n\nexport type { ModelDefinition } from './ModelDefinition';\nexport { RelationBuilder } from './relations/index';\nexport { ImplicitManyToManyIdentifier } from './relations/ImplicitManyToManyIdentifier';\nexport { Model } from './Model';\nexport { registerModelAugmentor } from './ModelAugmentorRegistry';\nexport { Decorators, t } from './decorators/index';\nexport type {\n TangoDecorators,\n FieldDecoratorBuilder,\n DecoratedFieldKind,\n ModelRef,\n ModelRefTarget,\n RelationDecoratedSchema,\n TypedModelRef,\n ForeignKeyDecoratorConfig,\n OneToOneDecoratorConfig,\n ManyToManyDecoratorConfig,\n} from './decorators/index';\nexport { createTypedModelRef, InternalDecoratedFieldKind, isTypedModelRef } from './decorators/index';\nexport { Meta, m } from './meta/index';\nexport type { ModelConstraint, ModelMetaFragment } from './meta/index';\nexport { Constraints, Indexes, c, i } from './constraints/index';\nexport type { ConstraintDefinition } from './constraints/index';\nexport {\n ModelRegistry,\n createSchemaModuleAliases,\n resolveSchemaModuleEntrypoint,\n GENERATED_RELATION_REGISTRY_DIRNAME,\n GENERATED_RELATION_REGISTRY_METADATA_FILENAME,\n GENERATED_RELATION_REGISTRY_METADATA_VERSION,\n GENERATED_RELATION_REGISTRY_TYPES_FILENAME,\n ResolvedRelationGraphArtifactFactory,\n type GeneratedRelationRegistryArtifact,\n type ResolvedRelationGraphSnapshot,\n type ResolvedRelationGraphSnapshotModel,\n type ResolvedRelationGraphSnapshotRelation,\n} from './registry/index';\n"],"mappings":";;;;;;;;;AAGA,MAAM,qCAAqB,IAAI,QAAoC;AAEnE,SAAgB,iBAAiB,QAAgD;CAC7E,OAAO,mBAAmB,IAAI,MAAM;AACxC;AAEA,SAAgB,iBAAiB,QAAoB,MAA4B;CAC7E,MAAM,WAAW,mBAAmB,IAAI,MAAM;CAC9C,mBAAmB,IAAI,QAAQ;EAC3B,GAAG;EACH,GAAG;CACP,CAAC;AACL;;;ACSA,SAAgB,oBAA0C,KAAgD;CACtG,OAAO,OAAO,OAAO,EAAE,IAAI,CAAC;AAChC;AAEA,SAAgB,gBAAgB,OAAwC;CACpE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,OAAQ,MAA4B,QAAQ;AACtG;;;AC9BA,MAAa,6BAA6B;CACtC,aAAa;CACb,YAAY;CACZ,cAAc;AAClB;;;ACYA,SAAS,UAAU,OAAqC;CACpD,OACI,CAAC,CAAC,SACF,OAAO,UAAU,YACjB,eAAe,SACf,OAAQ,MAAkC,cAAc;AAEhE;AAEA,SAAS,SAA+B,QAAW,MAAyB;CACxE,iBAAiB,QAAQ,IAAI;CAC7B,OAAO;AACX;AAEA,MAAM,uCAAuB,IAAI,IAAwB;AAEzD,SAAS,6BAA6B,MAA0B,aAA2B;CACvF,IAAI,qBAAqB,IAAI,IAAI,GAC7B;CAGJ,qBAAqB,IAAI,IAAI;CAC7B,UAAU,yBAAyB,EAAE,KACjC,oDAAoD,KAAK,gBAAgB,YAAY,UACzF;AACJ;AAEA,SAAS,eACL,mBACA,MACsB;CACtB,IAAI,mBACA,OA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Aa,SAAS,QAAQ,WAAW;CACzE,MAAM,mBAAmB,QAAQ,aAAa,UAAU,QAAQ,WAAW;CAE3E,IAAI,CAAC,WAAW,eAAe,KAAK,CAAC,WAAW,gBAAgB,GAC5D,MAAM,IAAI,MACN,qFAAqF,WAAW,GACpG;CAGJ,OAAO;EACH,8BAA8B;EAC9B,oCAAoC;EACpC,qCAAqC;EAGrC,+BAA+B,GAAG,YAAY;CAClD;AACJ;;;;;;;;;;;;;;;;;;AGlDA,MAAM,kCAAkB,IAAI,IAAoB;;;;AAKhD,SAAgB,uBAAuB,WAAuC;CAC1E,gBAAgB,IAAI,SAAS;CAE7B,KAAK,MAAM,SAAS,cAAc,OAAO,EAAE,OAAO,GAC9C,UAAU,KAAK;CAGnB,aAAa;EACT,gBAAgB,OAAO,SAAS;CACpC;AACJ;;;;AAKA,SAAgB,qBACZ,OACoB;CACpB,KAAK,MAAM,aAAa,iBACpB,UAAU,KAAK;CAGnB,OAAO;AACX;;;;;;;ACzBA,SAAgB,MAKZ,YAC8C;CAC9C,MAAM,WAAW,WAAW,YAAY,cAAc,OAAO;CAC7D,MAAM,QAAQ,qBACV,oBAAoB,OAAO,YAAY,QAAQ,CACnD;CAEA,SAAS,SAAS,KAAK;CACvB,OAAO;AACX"}
1
+ {"version":3,"file":"model-aRAusQPz.js","names":["carrier","t"],"sources":["../src/model/fields/FieldMetadataStore.ts","../src/model/decorators/domain/ModelRef.ts","../src/model/decorators/domain/DecoratedFieldKind.ts","../src/model/decorators/Decorators.ts","../src/model/decorators/index.ts","../src/model/meta/Meta.ts","../src/model/meta/index.ts","../src/model/constraints/Constraints.ts","../src/model/constraints/Indexes.ts","../src/model/constraints/index.ts","../src/domain/internal/InternalFieldType.ts","../src/domain/internal/zod/isDate.ts","../src/domain/internal/zod/hasConstructorName.ts","../src/domain/internal/zod/isZodArray.ts","../src/domain/internal/zod/isZodBoolean.ts","../src/domain/internal/zod/isZodDate.ts","../src/domain/internal/zod/isZodDefault.ts","../src/domain/internal/zod/isZodNullable.ts","../src/domain/internal/zod/isZodNumber.ts","../src/domain/internal/zod/isZodObject.ts","../src/domain/internal/zod/isZodOptional.ts","../src/domain/internal/zod/isZodString.ts","../src/model/fields/inferFieldsFromSchema.ts","../src/domain/internal/InternalRelationType.ts","../src/model/relations/RelationBuilder.ts","../src/model/relations/RelationDescriptorNormalizer.ts","../src/model/relations/SchemaNaming.ts","../src/model/internal/InternalSchemaModel.ts","../src/model/relations/NormalizedRelationStorageDescriptor.ts","../src/model/relations/RelationSpec.ts","../src/model/relations/ImplicitManyToManyIdentifier.ts","../src/domain/internal/InternalReferentialAction.ts","../src/model/relations/ImplicitManyToManyThroughFactory.ts","../src/model/relations/ResolvedRelationGraphBuilder.ts","../src/model/registry/GeneratedRelationRegistryArtifact.ts","../src/model/registry/ResolvedRelationGraphArtifactFactory.ts","../src/model/registry/ModelRegistry.ts","../src/resolveSchemaModuleEntrypoint.ts","../src/model/registry/index.ts","../src/model/relations/index.ts","../src/model/ModelAugmentorRegistry.ts","../src/model/Model.ts","../src/model/index.ts"],"sourcesContent":["import type { ZodTypeAny } from '../decorators/domain/ZodTypeAny';\nimport type { TangoFieldMeta } from '../decorators/domain/TangoFieldMeta';\n\nconst fieldMetadataStore = new WeakMap<ZodTypeAny, TangoFieldMeta>();\n\nexport function getFieldMetadata(schema: ZodTypeAny): TangoFieldMeta | undefined {\n return fieldMetadataStore.get(schema);\n}\n\nexport function setFieldMetadata(schema: ZodTypeAny, meta: TangoFieldMeta): void {\n const existing = fieldMetadataStore.get(schema);\n fieldMetadataStore.set(schema, {\n ...existing,\n ...meta,\n });\n}\n","import type { Model, ModelKeyOf } from '../../../domain';\n\n// TODO: consider async model callbacks such as `() => Promise<Model>` when Tango tackles lazy import boundaries for cyclical model graphs.\n// See the ADR: https://tangowebframework.dev/contributors/adr/deep-relation-hydration-with-generated-path-typing\ndeclare const TANGO_TYPED_MODEL_REF_TARGET: unique symbol;\n\nexport interface TypedModelRef<TModel extends Model = Model> {\n readonly key: ModelKeyOf<TModel>;\n readonly [TANGO_TYPED_MODEL_REF_TARGET]?: TModel;\n}\n\nexport type ModelRef<TModel extends Model = Model> = string | TModel | (() => TModel) | TypedModelRef<TModel>;\n\nexport type ModelRefTarget<TRef> =\n TRef extends TypedModelRef<infer TModel>\n ? TModel\n : TRef extends () => infer TModel\n ? TModel extends Model\n ? TModel\n : never\n : TRef extends Model\n ? TRef\n : never;\n\nexport function createTypedModelRef<TModel extends Model>(key: ModelKeyOf<TModel>): TypedModelRef<TModel> {\n return Object.freeze({ key }) as TypedModelRef<TModel>;\n}\n\nexport function isTypedModelRef(value: unknown): value is TypedModelRef {\n return typeof value === 'object' && value !== null && typeof (value as { key?: unknown }).key === 'string';\n}\n","export const InternalDecoratedFieldKind = {\n FOREIGN_KEY: 'foreignKey',\n ONE_TO_ONE: 'oneToOne',\n MANY_TO_MANY: 'manyToMany',\n} as const;\nexport type DecoratedFieldKind = (typeof InternalDecoratedFieldKind)[keyof typeof InternalDecoratedFieldKind];\n","import { getLogger } from '@danceroutine/tango-core';\nimport { z } from 'zod';\nimport { setFieldMetadata } from '../fields/FieldMetadataStore';\nimport type { ZodTypeAny } from './domain/ZodTypeAny';\nimport { createTypedModelRef, type ModelRef, type ModelRefTarget, type TypedModelRef } from './domain/ModelRef';\nimport type { ReferentialOptions, TangoFieldMeta } from './domain/TangoFieldMeta';\nimport type { Model, ModelKeyOf } from '../../domain';\nimport type {\n ForeignKeyDecoratorConfig,\n ManyToManyDecoratorConfig,\n OneToOneDecoratorConfig,\n} from './domain/RelationDecoratorConfig';\nimport type { RelationDecoratedSchema } from './domain/RelationDecoratedSchema';\nimport { InternalDecoratedFieldKind } from './domain/DecoratedFieldKind';\nimport type { DecoratedFieldKind } from './domain/DecoratedFieldKind';\n\nfunction isZodType(value: unknown): value is ZodTypeAny {\n return (\n !!value &&\n typeof value === 'object' &&\n 'safeParse' in value &&\n typeof (value as { safeParse?: unknown }).safeParse === 'function'\n );\n}\n\nfunction decorate<T extends ZodTypeAny>(schema: T, meta: TangoFieldMeta): T {\n setFieldMetadata(schema, meta);\n return schema;\n}\n\nconst warnedDecoratorKinds = new Set<DecoratedFieldKind>();\n\nfunction warnDeprecatedSchemaOverload(kind: DecoratedFieldKind, replacement: string): void {\n if (warnedDecoratorKinds.has(kind)) {\n return;\n }\n\n warnedDecoratorKinds.add(kind);\n getLogger('tango.schema.decorators').warn(\n `Deprecated positional schema overload used for t.${kind}(...). Prefer ${replacement} instead.`\n );\n}\n\nfunction maybeDecorator<T extends ZodTypeAny>(\n schemaOrUndefined: T | undefined,\n meta: TangoFieldMeta\n): T | ((schema: T) => T) {\n if (schemaOrUndefined) {\n return decorate(schemaOrUndefined, meta);\n }\n\n return (schema: T) => decorate(schema, meta);\n}\n\nfunction primaryKey<T extends ZodTypeAny>(schema: T): T;\nfunction primaryKey<T extends ZodTypeAny>(): (input: T) => T;\nfunction primaryKey<T extends ZodTypeAny>(schema?: T): T | ((input: T) => T) {\n return maybeDecorator(schema, { primaryKey: true, notNull: true });\n}\n\nfunction unique<T extends ZodTypeAny>(schema: T): T;\nfunction unique<T extends ZodTypeAny>(): (input: T) => T;\nfunction unique<T extends ZodTypeAny>(schema?: T): T | ((input: T) => T) {\n return maybeDecorator(schema, { unique: true });\n}\n\nfunction nullValue<T extends ZodTypeAny>(schema: T): T;\nfunction nullValue<T extends ZodTypeAny>(): (input: T) => T;\nfunction nullValue<T extends ZodTypeAny>(schema?: T): T | ((input: T) => T) {\n return maybeDecorator(schema, { notNull: false });\n}\n\nfunction notNull<T extends ZodTypeAny>(schema: T): T;\nfunction notNull<T extends ZodTypeAny>(): (input: T) => T;\nfunction notNull<T extends ZodTypeAny>(schema?: T): T | ((input: T) => T) {\n return maybeDecorator(schema, { notNull: true });\n}\n\nfunction defaultValue<T extends ZodTypeAny>(schema: T, value: string | { now: true } | null): T;\nfunction defaultValue<T extends ZodTypeAny>(schema: T, value: string | { now: true } | null): T {\n return decorate(schema, { default: value });\n}\n\nfunction dbDefault<T extends ZodTypeAny>(schema: T, value: string): T;\nfunction dbDefault<T extends ZodTypeAny>(schema: T, value: string): T {\n return decorate(schema, { dbDefault: value });\n}\n\nfunction dbColumn<T extends ZodTypeAny>(schema: T, name: string): T;\nfunction dbColumn<T extends ZodTypeAny>(schema: T, name: string): T {\n return decorate(schema, { dbColumn: name });\n}\n\nfunction dbIndex<T extends ZodTypeAny>(schema: T): T {\n return decorate(schema, { dbIndex: true });\n}\n\nfunction choices<T extends ZodTypeAny>(schema: T, values: readonly unknown[]): T;\nfunction choices<T extends ZodTypeAny>(schema: T, values: readonly unknown[]): T {\n return decorate(schema, { choices: values });\n}\n\nfunction validators<T extends ZodTypeAny>(schema: T, ...values: readonly ((value: unknown) => unknown)[]): T;\nfunction validators<T extends ZodTypeAny>(schema: T, ...values: readonly ((value: unknown) => unknown)[]): T {\n return decorate(schema, { validators: values });\n}\n\nfunction helpText<T extends ZodTypeAny>(schema: T, text: string): T;\nfunction helpText<T extends ZodTypeAny>(schema: T, text: string): T {\n return decorate(schema, { helpText: text });\n}\n\nfunction errorMessages<T extends ZodTypeAny>(schema: T, map: Record<string, string>): T;\nfunction errorMessages<T extends ZodTypeAny>(schema: T, map: Record<string, string>): T {\n return decorate(schema, { errorMessages: map });\n}\n\nexport interface FieldDecoratorBuilder<TField extends ZodTypeAny> {\n defaultValue(value: string | { now: true } | null): FieldDecoratorBuilder<TField>;\n dbDefault(value: string): FieldDecoratorBuilder<TField>;\n dbColumn(name: string): FieldDecoratorBuilder<TField>;\n dbIndex(): FieldDecoratorBuilder<TField>;\n choices(values: readonly unknown[]): FieldDecoratorBuilder<TField>;\n validators(...values: readonly ((value: unknown) => unknown)[]): FieldDecoratorBuilder<TField>;\n helpText(text: string): FieldDecoratorBuilder<TField>;\n errorMessages(map: Record<string, string>): FieldDecoratorBuilder<TField>;\n build(): TField;\n}\n\nclass FieldDecoratorBuilderImpl<TField extends ZodTypeAny> implements FieldDecoratorBuilder<TField> {\n constructor(private readonly schema: TField) {}\n\n defaultValue(value: string | { now: true } | null): FieldDecoratorBuilder<TField> {\n decorate(this.schema, { default: value });\n return this;\n }\n\n dbDefault(value: string): FieldDecoratorBuilder<TField> {\n decorate(this.schema, { dbDefault: value });\n return this;\n }\n\n dbColumn(name: string): FieldDecoratorBuilder<TField> {\n decorate(this.schema, { dbColumn: name });\n return this;\n }\n\n dbIndex(): FieldDecoratorBuilder<TField> {\n decorate(this.schema, { dbIndex: true });\n return this;\n }\n\n choices(values: readonly unknown[]): FieldDecoratorBuilder<TField> {\n decorate(this.schema, { choices: values });\n return this;\n }\n\n validators(...values: readonly ((value: unknown) => unknown)[]): FieldDecoratorBuilder<TField> {\n decorate(this.schema, { validators: values });\n return this;\n }\n\n helpText(text: string): FieldDecoratorBuilder<TField> {\n decorate(this.schema, { helpText: text });\n return this;\n }\n\n errorMessages(map: Record<string, string>): FieldDecoratorBuilder<TField> {\n decorate(this.schema, { errorMessages: map });\n return this;\n }\n\n build(): TField {\n return this.schema;\n }\n}\n\nfunction field<T extends ZodTypeAny>(schema: T): FieldDecoratorBuilder<T> {\n return new FieldDecoratorBuilderImpl(schema);\n}\n\nfunction applyRelationMetadata<T extends ZodTypeAny>(\n schema: T,\n meta: TangoFieldMeta,\n config?: { name?: string; relatedName?: string }\n): T {\n return decorate(schema, {\n ...meta,\n forwardName: config?.name,\n reverseName: config?.relatedName,\n });\n}\n\nfunction toReferentialOptions(config?: ReferentialOptions): ReferentialOptions | undefined {\n if (!config) {\n return undefined;\n }\n\n if (config.column === undefined && config.onDelete === undefined && config.onUpdate === undefined) {\n return undefined;\n }\n\n return {\n column: config.column,\n onDelete: config.onDelete,\n onUpdate: config.onUpdate,\n };\n}\n\ntype ConfigName<TConfig> = TConfig extends { name: infer TName extends string } ? TName : undefined;\ntype ConfigRelatedName<TConfig> = TConfig extends { relatedName: infer TRelatedName extends string }\n ? TRelatedName\n : undefined;\n\nfunction modelRef<TModel extends Model>(key: ModelKeyOf<TModel>): TypedModelRef<TModel> {\n return createTypedModelRef<TModel>(key);\n}\n\nfunction foreignKey<\n TRef extends ModelRef,\n T extends ZodTypeAny,\n const TConfig extends ForeignKeyDecoratorConfig<T> & { field: T },\n>(\n target: TRef,\n config: TConfig\n): RelationDecoratedSchema<T, 'foreignKey', ModelRefTarget<TRef>, ConfigName<TConfig>, ConfigRelatedName<TConfig>>;\nfunction foreignKey<TRef extends ModelRef, const TConfig extends ForeignKeyDecoratorConfig<z.ZodNumber> | undefined>(\n target: TRef,\n config?: TConfig\n): RelationDecoratedSchema<\n z.ZodNumber,\n 'foreignKey',\n ModelRefTarget<TRef>,\n ConfigName<TConfig>,\n ConfigRelatedName<TConfig>\n>;\n/**\n * @deprecated Use `t.foreignKey(target, { field: schema, ...options })` instead.\n */\nfunction foreignKey<T extends ZodTypeAny>(\n target: ModelRef,\n schema: T,\n options?: ReferentialOptions\n): RelationDecoratedSchema<T, 'foreignKey'>;\nfunction foreignKey<T extends ZodTypeAny>(\n target: ModelRef,\n schemaOrOptions?: T | ForeignKeyDecoratorConfig<T>,\n maybeOptions?: ReferentialOptions\n): RelationDecoratedSchema<T, 'foreignKey'> | z.ZodNumber {\n if (isZodType(schemaOrOptions)) {\n warnDeprecatedSchemaOverload(\n InternalDecoratedFieldKind.FOREIGN_KEY,\n 't.foreignKey(target, { field: schema, ...options })'\n );\n return applyRelationMetadata(schemaOrOptions, {\n relationKind: InternalDecoratedFieldKind.FOREIGN_KEY,\n references: {\n target,\n options: maybeOptions,\n },\n }) as RelationDecoratedSchema<T, 'foreignKey'>;\n }\n\n const config = schemaOrOptions;\n const schema = config?.field ?? z.number().int();\n return applyRelationMetadata(\n schema,\n {\n relationKind: InternalDecoratedFieldKind.FOREIGN_KEY,\n references: {\n target,\n options: toReferentialOptions(config),\n },\n notNull: config?.field ? undefined : true,\n },\n config\n ) as RelationDecoratedSchema<T, 'foreignKey'> | z.ZodNumber;\n}\n\nfunction oneToOne<\n TRef extends ModelRef,\n T extends ZodTypeAny,\n const TConfig extends OneToOneDecoratorConfig<T> & { field: T },\n>(\n target: TRef,\n config: TConfig\n): RelationDecoratedSchema<T, 'oneToOne', ModelRefTarget<TRef>, ConfigName<TConfig>, ConfigRelatedName<TConfig>>;\nfunction oneToOne<TRef extends ModelRef, const TConfig extends OneToOneDecoratorConfig<z.ZodNumber> | undefined>(\n target: TRef,\n config?: TConfig\n): RelationDecoratedSchema<\n z.ZodNumber,\n 'oneToOne',\n ModelRefTarget<TRef>,\n ConfigName<TConfig>,\n ConfigRelatedName<TConfig>\n>;\n/**\n * @deprecated Use `t.oneToOne(target, { field: schema, ...options })` instead.\n */\nfunction oneToOne<T extends ZodTypeAny>(\n target: ModelRef,\n schema: T,\n options?: ReferentialOptions\n): RelationDecoratedSchema<T, 'oneToOne'>;\nfunction oneToOne<T extends ZodTypeAny>(\n target: ModelRef,\n schemaOrOptions?: T | OneToOneDecoratorConfig<T>,\n maybeOptions?: ReferentialOptions\n): RelationDecoratedSchema<T, 'oneToOne'> | z.ZodNumber {\n if (isZodType(schemaOrOptions)) {\n warnDeprecatedSchemaOverload(\n InternalDecoratedFieldKind.ONE_TO_ONE,\n 't.oneToOne(target, { field: schema, ...options })'\n );\n return applyRelationMetadata(schemaOrOptions, {\n relationKind: InternalDecoratedFieldKind.ONE_TO_ONE,\n unique: true,\n references: {\n target,\n options: maybeOptions,\n },\n }) as RelationDecoratedSchema<T, 'oneToOne'>;\n }\n\n const config = schemaOrOptions;\n const schema = config?.field ?? z.number().int();\n return applyRelationMetadata(\n schema,\n {\n relationKind: InternalDecoratedFieldKind.ONE_TO_ONE,\n unique: true,\n references: {\n target,\n options: toReferentialOptions(config),\n },\n notNull: config?.field ? undefined : true,\n },\n config\n ) as RelationDecoratedSchema<T, 'oneToOne'> | z.ZodNumber;\n}\n\nfunction manyToMany<\n TRef extends ModelRef,\n T extends ZodTypeAny,\n const TConfig extends ManyToManyDecoratorConfig<T> & { field: T },\n>(\n target: TRef,\n config: TConfig\n): RelationDecoratedSchema<T, 'manyToMany', ModelRefTarget<TRef>, ConfigName<TConfig>, undefined>;\nfunction manyToMany<\n TRef extends ModelRef,\n const TConfig extends ManyToManyDecoratorConfig<z.ZodArray<z.ZodNumber>> | undefined,\n>(\n target: TRef,\n config?: TConfig\n): RelationDecoratedSchema<z.ZodArray<z.ZodNumber>, 'manyToMany', ModelRefTarget<TRef>, ConfigName<TConfig>, undefined>;\n/**\n * @deprecated Use `t.manyToMany(target, { field: schema, name })` instead.\n */\nfunction manyToMany<T extends ZodTypeAny>(target: ModelRef, schema: T): RelationDecoratedSchema<T, 'manyToMany'>;\nfunction manyToMany<T extends ZodTypeAny>(\n target: ModelRef,\n schemaOrConfig?: T | ManyToManyDecoratorConfig<T>\n): RelationDecoratedSchema<T, 'manyToMany'> | z.ZodArray<z.ZodNumber> {\n if (isZodType(schemaOrConfig)) {\n warnDeprecatedSchemaOverload(\n InternalDecoratedFieldKind.MANY_TO_MANY,\n 't.manyToMany(target, { field: schema, name })'\n );\n return applyRelationMetadata(schemaOrConfig, {\n relationKind: InternalDecoratedFieldKind.MANY_TO_MANY,\n references: {\n target,\n },\n }) as RelationDecoratedSchema<T, 'manyToMany'>;\n }\n\n if (schemaOrConfig?.relatedName !== undefined) {\n throw new Error('t.manyToMany(...) does not support relatedName yet.');\n }\n\n const config = schemaOrConfig;\n\n const hasPartialThroughConfig =\n (config?.through !== undefined ||\n config?.throughSourceFieldName !== undefined ||\n config?.throughTargetFieldName !== undefined) &&\n !(config?.through && config.throughSourceFieldName && config.throughTargetFieldName);\n if (hasPartialThroughConfig) {\n throw new Error(\n 't.manyToMany(...) through config requires through, throughSourceFieldName, and throughTargetFieldName.'\n );\n }\n const schema = config?.field ?? z.array(z.number().int());\n return applyRelationMetadata(\n schema,\n {\n relationKind: InternalDecoratedFieldKind.MANY_TO_MANY,\n references: {\n target,\n through: config?.through,\n throughSourceFieldName: config?.throughSourceFieldName,\n throughTargetFieldName: config?.throughTargetFieldName,\n },\n },\n config\n ) as RelationDecoratedSchema<T, 'manyToMany'> | z.ZodArray<z.ZodNumber>;\n}\n\ntype UnaryFieldDecorator = {\n <T extends ZodTypeAny>(schema: T): T;\n <T extends ZodTypeAny>(): (input: T) => T;\n};\n\ntype RelationshipDecorator = {\n <TRef extends ModelRef, T extends ZodTypeAny, const TConfig extends ForeignKeyDecoratorConfig<T> & { field: T }>(\n target: TRef,\n config: TConfig\n ): RelationDecoratedSchema<T, 'foreignKey', ModelRefTarget<TRef>, ConfigName<TConfig>, ConfigRelatedName<TConfig>>;\n <TRef extends ModelRef, const TConfig extends ForeignKeyDecoratorConfig<z.ZodNumber> | undefined>(\n target: TRef,\n config?: TConfig\n ): RelationDecoratedSchema<\n z.ZodNumber,\n 'foreignKey',\n ModelRefTarget<TRef>,\n ConfigName<TConfig>,\n ConfigRelatedName<TConfig>\n >;\n /**\n * @deprecated Use `t.foreignKey(target, { field: schema, ...options })` instead.\n */\n <T extends ZodTypeAny>(\n target: ModelRef,\n schema: T,\n options?: ReferentialOptions\n ): RelationDecoratedSchema<T, 'foreignKey'>;\n};\n\ntype OneToOneRelationshipDecorator = {\n <TRef extends ModelRef, T extends ZodTypeAny, const TConfig extends OneToOneDecoratorConfig<T> & { field: T }>(\n target: TRef,\n config: TConfig\n ): RelationDecoratedSchema<T, 'oneToOne', ModelRefTarget<TRef>, ConfigName<TConfig>, ConfigRelatedName<TConfig>>;\n <TRef extends ModelRef, const TConfig extends OneToOneDecoratorConfig<z.ZodNumber> | undefined>(\n target: TRef,\n config?: TConfig\n ): RelationDecoratedSchema<\n z.ZodNumber,\n 'oneToOne',\n ModelRefTarget<TRef>,\n ConfigName<TConfig>,\n ConfigRelatedName<TConfig>\n >;\n /**\n * @deprecated Use `t.oneToOne(target, { field: schema, ...options })` instead.\n */\n <T extends ZodTypeAny>(\n target: ModelRef,\n schema: T,\n options?: ReferentialOptions\n ): RelationDecoratedSchema<T, 'oneToOne'>;\n};\n\ntype ManyToManyDecorator = {\n <TRef extends ModelRef, T extends ZodTypeAny, const TConfig extends ManyToManyDecoratorConfig<T> & { field: T }>(\n target: TRef,\n config: TConfig\n ): RelationDecoratedSchema<T, 'manyToMany', ModelRefTarget<TRef>, ConfigName<TConfig>, undefined>;\n <TRef extends ModelRef, const TConfig extends ManyToManyDecoratorConfig<z.ZodArray<z.ZodNumber>> | undefined>(\n target: TRef,\n config?: TConfig\n ): RelationDecoratedSchema<\n z.ZodArray<z.ZodNumber>,\n 'manyToMany',\n ModelRefTarget<TRef>,\n ConfigName<TConfig>,\n undefined\n >;\n /**\n * @deprecated Use `t.manyToMany(target, { field: schema, name })` instead.\n */\n <T extends ZodTypeAny>(target: ModelRef, schema: T): RelationDecoratedSchema<T, 'manyToMany'>;\n};\n\nexport interface TangoDecorators {\n field: <T extends ZodTypeAny>(schema: T) => FieldDecoratorBuilder<T>;\n modelRef: <TModel extends Model>(key: ModelKeyOf<TModel>) => TypedModelRef<TModel>;\n primaryKey: UnaryFieldDecorator;\n unique: UnaryFieldDecorator;\n null: UnaryFieldDecorator;\n notNull: UnaryFieldDecorator;\n default: <T extends ZodTypeAny>(schema: T, value: string | { now: true } | null) => T;\n dbDefault: <T extends ZodTypeAny>(schema: T, value: string) => T;\n dbColumn: <T extends ZodTypeAny>(schema: T, name: string) => T;\n dbIndex: <T extends ZodTypeAny>(schema: T) => T;\n choices: <T extends ZodTypeAny>(schema: T, values: readonly unknown[]) => T;\n validators: <T extends ZodTypeAny>(schema: T, ...values: readonly ((value: unknown) => unknown)[]) => T;\n helpText: <T extends ZodTypeAny>(schema: T, text: string) => T;\n errorMessages: <T extends ZodTypeAny>(schema: T, map: Record<string, string>) => T;\n foreignKey: RelationshipDecorator;\n oneToOne: OneToOneRelationshipDecorator;\n manyToMany: ManyToManyDecorator;\n}\n\nexport const Decorators: TangoDecorators = {\n field,\n modelRef,\n primaryKey: primaryKey as UnaryFieldDecorator,\n unique: unique as UnaryFieldDecorator,\n null: nullValue as UnaryFieldDecorator,\n notNull: notNull as UnaryFieldDecorator,\n default: defaultValue,\n dbDefault: dbDefault,\n dbColumn: dbColumn,\n dbIndex: dbIndex,\n choices: choices,\n validators: validators,\n helpText: helpText,\n errorMessages: errorMessages,\n foreignKey: foreignKey as RelationshipDecorator,\n oneToOne: oneToOne as OneToOneRelationshipDecorator,\n manyToMany: manyToMany as ManyToManyDecorator,\n};\n","/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\nexport { Decorators, Decorators as t } from './Decorators';\nexport type { FieldDecoratorBuilder, TangoDecorators } from './Decorators';\nexport type { ModelRef, ModelRefTarget, TypedModelRef } from './domain/ModelRef';\nexport { createTypedModelRef, isTypedModelRef } from './domain/ModelRef';\nexport type { RelationDecoratedSchema } from './domain/RelationDecoratedSchema';\nexport { InternalDecoratedFieldKind } from './domain/DecoratedFieldKind';\nexport type { DecoratedFieldKind } from './domain/DecoratedFieldKind';\nexport type {\n ForeignKeyDecoratorConfig,\n OneToOneDecoratorConfig,\n ManyToManyDecoratorConfig,\n} from './domain/RelationDecoratorConfig';\nexport type { ReferentialOptions, TangoFieldMeta } from './domain/TangoFieldMeta';\nexport type { ZodTypeAny } from './domain/ZodTypeAny';\n","import type { IndexDef } from '../../domain/index';\n\nexport type ModelConstraint = {\n kind: string;\n [key: string]: unknown;\n};\n\nexport type ModelMetaFragment = {\n ordering?: string[];\n managed?: boolean;\n defaultRelatedName?: string;\n indexes?: IndexDef[];\n constraints?: ModelConstraint[];\n};\n\nexport const Meta = {\n ordering(...fields: string[]): ModelMetaFragment {\n return { ordering: fields };\n },\n\n managed(value: boolean): ModelMetaFragment {\n return { managed: value };\n },\n\n defaultRelatedName(value: string): ModelMetaFragment {\n return { defaultRelatedName: value };\n },\n\n indexes(...indexes: IndexDef[]): ModelMetaFragment {\n return { indexes };\n },\n\n constraints(...constraints: ModelConstraint[]): ModelMetaFragment {\n return { constraints };\n },\n\n uniqueTogether(...sets: string[][]): ModelMetaFragment {\n return {\n constraints: sets.map((fields) => ({ kind: 'uniqueTogether', fields })),\n };\n },\n\n indexTogether(...sets: string[][]): ModelMetaFragment {\n return {\n indexes: sets.map((on, index) => ({\n name: `idx_${on.join('_')}_${index}`,\n on,\n })),\n };\n },\n\n merge(...fragments: readonly ModelMetaFragment[]): ModelMetaFragment {\n return fragments.reduce<ModelMetaFragment>(\n (acc, fragment) => ({\n ordering: fragment.ordering ?? acc.ordering,\n managed: fragment.managed ?? acc.managed,\n defaultRelatedName: fragment.defaultRelatedName ?? acc.defaultRelatedName,\n indexes: [...(acc.indexes ?? []), ...(fragment.indexes ?? [])],\n constraints: [...(acc.constraints ?? []), ...(fragment.constraints ?? [])],\n }),\n {}\n );\n },\n};\n","/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\nexport { Meta, Meta as m } from './Meta';\nexport type { ModelConstraint, ModelMetaFragment } from './Meta';\n","export type ConstraintDefinition = {\n kind: string;\n [key: string]: unknown;\n};\n\nexport const Constraints = {\n unique(fields: string[], options?: { name?: string; where?: string }): ConstraintDefinition {\n return {\n kind: 'unique',\n fields,\n ...options,\n };\n },\n\n check(condition: string, options?: { name?: string }): ConstraintDefinition {\n return {\n kind: 'check',\n condition,\n ...options,\n };\n },\n\n exclusion(definition: { using?: string; elements: string[]; where?: string; name?: string }): ConstraintDefinition {\n return {\n kind: 'exclusion',\n ...definition,\n };\n },\n};\n","import type { IndexDef } from '../../domain/index';\n\nexport const Indexes = {\n index(on: string[], options?: Omit<IndexDef, 'on'>): IndexDef {\n const suffix = on.join('_');\n return {\n name: options?.name ?? `idx_${suffix}`,\n on,\n unique: options?.unique,\n where: options?.where,\n };\n },\n};\n","/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\nexport { Constraints, Constraints as c } from './Constraints';\nexport type { ConstraintDefinition } from './Constraints';\nexport { Indexes, Indexes as i } from './Indexes';\n","export const InternalFieldType = {\n SERIAL: 'serial',\n INT: 'int',\n BIGINT: 'bigint',\n TEXT: 'text',\n BOOL: 'bool',\n TIMESTAMPTZ: 'timestamptz',\n JSONB: 'jsonb',\n UUID: 'uuid',\n} as const;\n","export function isDate(value: unknown): value is Date {\n return value !== null && value !== undefined && Object.prototype.toString.call(value) === '[object Date]';\n}\n","export function hasConstructorName(value: unknown, name: string): boolean {\n return (\n !!value &&\n typeof value === 'object' &&\n (value as { constructor?: { name?: unknown } }).constructor?.name === name\n );\n}\n","import { z } from 'zod';\nimport { hasConstructorName } from './hasConstructorName';\n\nexport function isZodArray(value: unknown): value is z.ZodArray<z.ZodTypeAny> {\n return hasConstructorName(value, 'ZodArray');\n}\n","import { z } from 'zod';\nimport { hasConstructorName } from './hasConstructorName';\n\nexport function isZodBoolean(value: unknown): value is z.ZodBoolean {\n return hasConstructorName(value, 'ZodBoolean');\n}\n","import { z } from 'zod';\nimport { hasConstructorName } from './hasConstructorName';\n\nexport function isZodDate(value: unknown): value is z.ZodDate {\n return hasConstructorName(value, 'ZodDate');\n}\n","import { z } from 'zod';\nimport { hasConstructorName } from './hasConstructorName';\n\nexport function isZodDefault(value: unknown): value is z.ZodDefault<z.ZodTypeAny> {\n return hasConstructorName(value, 'ZodDefault');\n}\n","import { z } from 'zod';\nimport { hasConstructorName } from './hasConstructorName';\n\nexport function isZodNullable(value: unknown): value is z.ZodNullable<z.ZodTypeAny> {\n return hasConstructorName(value, 'ZodNullable');\n}\n","import { z } from 'zod';\nimport { hasConstructorName } from './hasConstructorName';\n\nexport function isZodNumber(value: unknown): value is z.ZodNumber {\n return hasConstructorName(value, 'ZodNumber');\n}\n","import { z } from 'zod';\nimport { hasConstructorName } from './hasConstructorName';\n\nexport function isZodObject(value: unknown): value is z.ZodObject<z.ZodRawShape> {\n return hasConstructorName(value, 'ZodObject');\n}\n","import { z } from 'zod';\nimport { hasConstructorName } from './hasConstructorName';\n\nexport function isZodOptional(value: unknown): value is z.ZodOptional<z.ZodTypeAny> {\n return hasConstructorName(value, 'ZodOptional');\n}\n","import { z } from 'zod';\nimport { hasConstructorName } from './hasConstructorName';\n\nexport function isZodString(value: unknown): value is z.ZodString {\n return hasConstructorName(value, 'ZodString');\n}\n","import { z } from 'zod';\nimport type { Field, FieldType } from '../../domain/index';\nimport { InternalFieldType } from '../../domain/internal/InternalFieldType';\nimport { getFieldMetadata } from './FieldMetadataStore';\nimport type { ZodTypeAny } from '../decorators/domain/ZodTypeAny';\nimport type { ModelRef } from '../decorators/domain/ModelRef';\nimport type { TangoFieldMeta } from '../decorators/domain/TangoFieldMeta';\nimport { InternalDecoratedFieldKind } from '../decorators/domain/DecoratedFieldKind';\nimport { ModelRegistry } from '../registry/ModelRegistry';\nimport {\n isDate,\n isZodArray,\n isZodBoolean,\n isZodDate,\n isZodDefault,\n isZodNullable,\n isZodNumber,\n isZodObject,\n isZodOptional,\n isZodString,\n} from '../../domain/internal/zod/index';\n\nexport type InferFieldsOptions = {\n registry?: ModelRegistry;\n resolveReferenceTarget?: (target: ModelRef) => { table: string; pk: string };\n};\n\n/**\n * Infer one storage field from a Zod schema member plus any Tango decorator metadata.\n *\n * The registry and optional target resolver are used only when the field carries\n * reference metadata that must be translated into concrete table/primary-key names.\n */\nfunction inferField(\n name: string,\n zodType: z.ZodType,\n meta: TangoFieldMeta | undefined,\n registry: ModelRegistry,\n resolveReferenceTarget?: (target: ModelRef) => { table: string; pk: string }\n): Field | null {\n let type: FieldType;\n let notNull = true;\n let defaultValue: Field['default'] = undefined;\n\n let unwrapped: z.ZodType = zodType;\n\n if (isZodOptional(unwrapped)) {\n notNull = false;\n unwrapped = unwrapped.unwrap() as z.ZodType;\n }\n\n if (isZodNullable(unwrapped)) {\n notNull = false;\n unwrapped = unwrapped.unwrap() as z.ZodType;\n }\n\n if (isZodDefault(unwrapped)) {\n const def = unwrapped._zod.def.defaultValue;\n if (isDate(def)) {\n defaultValue = { now: true };\n } else if (typeof def === 'string' || typeof def === 'number') {\n defaultValue = String(def);\n }\n unwrapped = unwrapped.removeDefault() as z.ZodType;\n }\n\n if (isZodString(unwrapped)) {\n type = InternalFieldType.TEXT;\n } else if (isZodNumber(unwrapped)) {\n const checks = unwrapped._zod.def.checks ?? [];\n const isInt = checks.some((c) => 'format' in c._zod.def && c._zod.def.format === 'safeint');\n type = isInt ? InternalFieldType.INT : InternalFieldType.BIGINT;\n } else if (isZodBoolean(unwrapped)) {\n type = InternalFieldType.BOOL;\n } else if (isZodDate(unwrapped)) {\n type = InternalFieldType.TIMESTAMPTZ;\n } else if (isZodObject(unwrapped) || isZodArray(unwrapped)) {\n type = InternalFieldType.JSONB;\n } else {\n return null;\n }\n\n const field: Field = {\n name,\n type,\n notNull,\n default: defaultValue,\n };\n\n if (!meta) {\n return field;\n }\n\n if (meta.dbColumn) {\n field.name = meta.dbColumn;\n }\n\n if (typeof meta.notNull === 'boolean') {\n field.notNull = meta.notNull;\n }\n\n if (meta.default !== undefined) {\n field.default = meta.default;\n }\n\n if (meta.primaryKey) {\n field.primaryKey = true;\n }\n\n if (meta.unique) {\n field.unique = true;\n }\n\n // Many-to-many declarations stay on the relation side of the seam. They do\n // not correspond to a stored column on the current table.\n if (meta.relationKind === InternalDecoratedFieldKind.MANY_TO_MANY) {\n return null;\n }\n\n if (meta.references) {\n const targetMetadata = resolveReferenceTarget\n ? resolveReferenceTarget(meta.references.target)\n : resolveReferenceTargetFromRegistry(meta.references.target, registry, meta.references.options?.column);\n\n field.references = {\n table: targetMetadata.table,\n column: meta.references.options?.column ?? targetMetadata.pk,\n onDelete: meta.references.options?.onDelete,\n onUpdate: meta.references.options?.onUpdate,\n };\n }\n\n return field;\n}\n\nfunction resolveReferenceTargetFromRegistry(\n target: ModelRef,\n registry: ModelRegistry,\n explicitColumn?: string\n): { table: string; pk: string } {\n const targetModel = registry.resolveRef(target);\n const primaryKey =\n explicitColumn ?? targetModel.metadata.fields.find((candidate) => candidate.primaryKey)?.name ?? 'id';\n\n return {\n table: targetModel.metadata.table,\n pk: primaryKey,\n };\n}\n\n/**\n * Infer Tango field metadata from a Zod object schema and any attached field decorators.\n */\nexport function inferFieldsFromSchema(schema: z.ZodObject<z.ZodRawShape>, options?: InferFieldsOptions): Field[] {\n const registry = options?.registry ?? ModelRegistry.global();\n const shape = schema.shape;\n const fields: Field[] = [];\n\n for (const [name, zodType] of Object.entries(shape)) {\n const field = inferField(\n name,\n zodType as z.ZodType,\n getFieldMetadata(zodType as ZodTypeAny),\n registry,\n options?.resolveReferenceTarget\n );\n if (field) {\n fields.push(field);\n }\n }\n\n return fields;\n}\n","export const InternalRelationType = {\n HAS_MANY: 'hasMany',\n BELONGS_TO: 'belongsTo',\n HAS_ONE: 'hasOne',\n} as const;\n","import type { RelationDef } from '../../domain/index';\nimport { InternalRelationType } from '../../domain/internal/InternalRelationType';\n\n/**\n * Public authoring DSL for model-level named relations.\n *\n * This is the first stage of the relations subdomain. Application code uses it\n * inside `relations: (r) => ({ ... })` to declare stable relation names and\n * resolve ambiguity that field decorators alone cannot express.\n *\n * Later internal stages normalize these authored definitions and combine them\n * with field-authored relation metadata to build the resolved relation graph.\n */\nexport class RelationBuilder {\n /** Declare a one-to-many relation from this model to `target`. */\n hasMany(target: string, foreignKey: string): RelationDef {\n return {\n type: InternalRelationType.HAS_MANY,\n target,\n foreignKey,\n };\n }\n\n /** Declare an owning relation to a parent model. */\n belongsTo(target: string, foreignKey: string, localKey?: string): RelationDef {\n return {\n type: InternalRelationType.BELONGS_TO,\n target,\n foreignKey,\n localKey,\n };\n }\n\n /** Declare a one-to-one relation from this model to `target`. */\n hasOne(target: string, foreignKey: string): RelationDef {\n return {\n type: InternalRelationType.HAS_ONE,\n target,\n foreignKey,\n };\n }\n}\n","import { z } from 'zod';\nimport type { ZodTypeAny } from '../decorators/domain/ZodTypeAny';\nimport { InternalDecoratedFieldKind } from '../decorators/domain/DecoratedFieldKind';\nimport { getFieldMetadata } from '../fields/FieldMetadataStore';\nimport type {\n NormalizedRelationOrigin,\n NormalizedRelationStorageDescriptor,\n} from './NormalizedRelationStorageDescriptor';\n\ntype RelationCandidate = {\n sourceSchemaFieldKey: string;\n zodType: ZodTypeAny;\n};\n\n/**\n * Normalizes field-authored relation declarations from a model schema into the\n * shared descriptor shape consumed by storage and relation finalization.\n *\n * This is the normalization stage of the relations subdomain. It sits between\n * authoring and resolution:\n *\n * - authoring: decorators attach relation intent to schema fields\n * - normalization: this class converts that intent into a registry-independent\n * descriptor shape\n * - resolution: the graph builder combines those descriptors with finalized\n * storage artifacts and explicit relation names\n */\nexport class RelationDescriptorNormalizer {\n constructor(\n private readonly sourceModelKey: string,\n private readonly schema: z.ZodObject<z.ZodRawShape>\n ) {}\n\n static normalize(\n sourceModelKey: string,\n schema: z.ZodObject<z.ZodRawShape>\n ): readonly NormalizedRelationStorageDescriptor[] {\n return new RelationDescriptorNormalizer(sourceModelKey, schema).normalize();\n }\n\n /**\n * Run the field-authored relation normalization pipeline for one model\n * schema and emit descriptors that later relation stages can resolve.\n */\n normalize(): readonly NormalizedRelationStorageDescriptor[] {\n const descriptors: NormalizedRelationStorageDescriptor[] = [];\n\n for (const candidate of this.collectRelationCandidates()) {\n const descriptor = this.normalizeCandidate(candidate);\n if (descriptor) {\n descriptors.push(descriptor);\n }\n }\n\n return descriptors;\n }\n\n private collectRelationCandidates(): readonly RelationCandidate[] {\n return Object.entries(this.schema.shape).map(([sourceSchemaFieldKey, zodType]) => ({\n sourceSchemaFieldKey,\n zodType: zodType as ZodTypeAny,\n }));\n }\n\n private normalizeCandidate(candidate: RelationCandidate): NormalizedRelationStorageDescriptor | undefined {\n const meta = getFieldMetadata(candidate.zodType);\n if (!meta?.references || !meta.relationKind) {\n return undefined;\n }\n\n return {\n edgeId: this.buildEdgeId(candidate.sourceSchemaFieldKey, meta.relationKind),\n sourceModelKey: this.sourceModelKey,\n sourceSchemaFieldKey: candidate.sourceSchemaFieldKey,\n targetRef: meta.references.target,\n origin: meta.relationKind,\n localFieldName: candidate.sourceSchemaFieldKey,\n dbColumnName: meta.dbColumn ?? candidate.sourceSchemaFieldKey,\n referencedTargetColumn: meta.references.options?.column,\n onDelete: meta.references.options?.onDelete,\n onUpdate: meta.references.options?.onUpdate,\n unique: meta.unique || meta.relationKind === InternalDecoratedFieldKind.ONE_TO_ONE,\n explicitForwardName: meta.forwardName,\n explicitReverseName: meta.reverseName,\n namingHint: this.deriveNamingHint(candidate.sourceSchemaFieldKey),\n throughModelRef: meta.references.through,\n throughSourceFieldName: meta.references.throughSourceFieldName,\n throughTargetFieldName: meta.references.throughTargetFieldName,\n provenance: 'field-decorator',\n };\n }\n\n private buildEdgeId(sourceSchemaFieldKey: string, origin: NormalizedRelationOrigin): string {\n return `${this.sourceModelKey}:${sourceSchemaFieldKey}:${origin}`;\n }\n\n private deriveNamingHint(fieldKey: string): string {\n if (fieldKey.endsWith('Id') && fieldKey.length > 2) {\n return fieldKey.slice(0, -2);\n }\n\n if (fieldKey.endsWith('_id') && fieldKey.length > 3) {\n return fieldKey.slice(0, -3);\n }\n\n return fieldKey;\n }\n}\n","/**\n * Shared naming policy for the model and relations subdomains.\n *\n * These helpers are not an authoring or graph stage on their own. They are the\n * cross-cutting policy layer used by both model construction and relation\n * resolution when Tango derives table names, aliases, and synthesized relation\n * names in a Django-style shape.\n */\nexport function toSnakeCase(value: string): string {\n return value\n .replace(/([a-z0-9])([A-Z])/g, '$1_$2')\n .replace(/[\\s-]+/g, '_')\n .toLowerCase();\n}\n\nexport function pluralize(value: string): string {\n if (/(s|x|z|ch|sh)$/.test(value)) {\n return `${value}es`;\n }\n\n if (/[^aeiou]y$/.test(value)) {\n return `${value.slice(0, -1)}ies`;\n }\n\n return `${value}s`;\n}\n\nexport function deriveTableName(name: string): string {\n return pluralize(toSnakeCase(name));\n}\n\nexport function decapitalizeModelName(name: string): string {\n if (name.length === 0) {\n return name;\n }\n return `${name[0]!.toLowerCase()}${name.slice(1)}`;\n}\n","import { z } from 'zod';\nimport type {\n Field,\n Model,\n ModelAugmentations,\n ModelMetadata,\n ModelWriteHooks,\n PersistedModelOutput,\n RelationDef,\n} from '../../domain/index';\nimport type { ModelDefinition } from '../ModelDefinition';\nimport { RelationBuilder } from '../relations/RelationBuilder';\nimport type { ModelRegistry } from '../registry/ModelRegistry';\nimport type { NormalizedRelationStorageDescriptor } from '../relations/NormalizedRelationStorageDescriptor';\nimport { RelationDescriptorNormalizer } from '../relations/RelationDescriptorNormalizer';\nimport { deriveTableName } from '../relations/SchemaNaming';\n\ntype AnySchemaModel = Model<z.ZodObject<z.ZodRawShape>>;\ntype AnyInternalSchemaModel = InternalSchemaModel<z.ZodObject<z.ZodRawShape>>;\nconst REGISTRY_OWNER_KEY = Symbol.for('tango.schema.registryOwner');\nconst NORMALIZED_RELATIONS_KEY = Symbol.for('tango.schema.normalizedRelations');\nconst EXPLICIT_FIELDS_KEY = Symbol.for('tango.schema.explicitFields');\nconst EXPLICIT_RELATIONS_KEY = Symbol.for('tango.schema.explicitRelations');\n\ntype InternalSchemaModelCarrier = object & {\n [REGISTRY_OWNER_KEY]?: ModelRegistry;\n [NORMALIZED_RELATIONS_KEY]?: readonly NormalizedRelationStorageDescriptor[];\n [EXPLICIT_FIELDS_KEY]?: readonly Field[];\n [EXPLICIT_RELATIONS_KEY]?: Readonly<Record<string, RelationDef>>;\n};\n\nexport class InternalSchemaModel<\n TSchema extends z.ZodObject<z.ZodRawShape>,\n TKey extends string = string,\n> implements Model<TSchema, TKey> {\n static readonly BRAND = 'tango.schema.internal_schema_model' as const;\n\n readonly __tangoBrand: typeof InternalSchemaModel.BRAND = InternalSchemaModel.BRAND;\n readonly metadata: ModelMetadata;\n readonly schema: TSchema;\n readonly hooks?: ModelWriteHooks<PersistedModelOutput<TSchema>>;\n declare readonly objects: ModelAugmentations<TSchema, TKey> extends { readonly objects: infer TObject }\n ? TObject\n : never;\n\n private constructor(\n metadata: ModelMetadata,\n schema: TSchema,\n hooks: ModelWriteHooks<PersistedModelOutput<TSchema>> | undefined\n ) {\n this.metadata = metadata;\n this.schema = schema;\n this.hooks = hooks;\n }\n\n static create<TSchema extends z.ZodObject<z.ZodRawShape>>(\n definition: ModelDefinition<TSchema>,\n registry: ModelRegistry\n ): InternalSchemaModel<TSchema> {\n InternalSchemaModel.validateDefinition(definition);\n\n const builder = new RelationBuilder();\n const relations = definition.relations ? Object.freeze(definition.relations(builder)) : undefined;\n const key = `${definition.namespace}/${definition.name}`;\n const table = definition.table?.trim() || deriveTableName(definition.name);\n const normalizedRelations = RelationDescriptorNormalizer.normalize(key, definition.schema);\n\n const metadata: ModelMetadata = {\n namespace: definition.namespace,\n name: definition.name,\n key,\n table,\n fields: [] as never,\n indexes: definition.indexes,\n relations,\n ordering: definition.ordering,\n managed: definition.managed,\n defaultRelatedName: definition.defaultRelatedName,\n constraints: definition.constraints,\n };\n\n // The field view stays lazy because finalized storage metadata is registry-scoped.\n // The owning registry publishes the current finalized fields for this model\n // instead of freezing a stale one-time snapshot during construction.\n Object.defineProperty(metadata, 'fields', {\n enumerable: true,\n configurable: false,\n get: () => registry.getFinalizedFields(key) as typeof metadata.fields,\n });\n Object.freeze(metadata);\n\n const model = new InternalSchemaModel(metadata, definition.schema, definition.hooks);\n InternalSchemaModel.attachInternals(model, {\n registry,\n normalizedRelations,\n explicitFields: definition.fields,\n explicitRelations: relations,\n });\n return model;\n }\n\n static isInternalSchemaModel(value: unknown): value is AnyInternalSchemaModel {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __tangoBrand?: unknown }).__tangoBrand === InternalSchemaModel.BRAND\n );\n }\n\n static getRegistryOwner(model: AnySchemaModel): ModelRegistry {\n const owner = InternalSchemaModel.carrier(model)[REGISTRY_OWNER_KEY];\n if (!owner) {\n throw new Error(`Model '${model.metadata.key}' is missing internal registry ownership metadata.`);\n }\n return owner;\n }\n\n static getNormalizedRelations(model: AnySchemaModel): readonly NormalizedRelationStorageDescriptor[] {\n return InternalSchemaModel.carrier(model)[NORMALIZED_RELATIONS_KEY] ?? [];\n }\n\n static getExplicitFields(model: AnySchemaModel): readonly Field[] | undefined {\n return InternalSchemaModel.carrier(model)[EXPLICIT_FIELDS_KEY];\n }\n\n static getExplicitRelations(model: AnySchemaModel): Readonly<Record<string, RelationDef>> | undefined {\n return InternalSchemaModel.carrier(model)[EXPLICIT_RELATIONS_KEY];\n }\n\n private static validateDefinition<TSchema extends z.ZodObject<z.ZodRawShape>>(\n definition: ModelDefinition<TSchema>\n ): void {\n if (!definition.namespace.trim()) {\n throw new Error('Model.namespace is required and cannot be empty.');\n }\n if (!definition.name.trim()) {\n throw new Error('Model.name is required and cannot be empty.');\n }\n if (definition.table !== undefined && !definition.table.trim()) {\n throw new Error('Model.table cannot be empty when provided.');\n }\n }\n\n private static require(model: AnySchemaModel): AnyInternalSchemaModel {\n if (!InternalSchemaModel.isInternalSchemaModel(model)) {\n throw new Error(`Model '${model.metadata.key}' is missing internal registry ownership metadata.`);\n }\n\n return model;\n }\n\n private static carrier(model: AnySchemaModel): InternalSchemaModelCarrier {\n return InternalSchemaModel.require(model) as unknown as InternalSchemaModelCarrier;\n }\n\n private static attachInternals(\n model: object,\n internals: {\n registry: ModelRegistry;\n normalizedRelations: readonly NormalizedRelationStorageDescriptor[];\n explicitFields?: readonly Field[];\n explicitRelations?: Readonly<Record<string, RelationDef>>;\n }\n ): void {\n const carrier = model as InternalSchemaModelCarrier;\n\n Object.defineProperties(carrier, {\n [REGISTRY_OWNER_KEY]: {\n value: internals.registry,\n enumerable: false,\n configurable: false,\n writable: false,\n },\n [NORMALIZED_RELATIONS_KEY]: {\n value: Object.freeze([...internals.normalizedRelations]),\n enumerable: false,\n configurable: false,\n writable: false,\n },\n [EXPLICIT_FIELDS_KEY]: {\n value: internals.explicitFields ? Object.freeze([...internals.explicitFields]) : undefined,\n enumerable: false,\n configurable: false,\n writable: false,\n },\n [EXPLICIT_RELATIONS_KEY]: {\n value: internals.explicitRelations,\n enumerable: false,\n configurable: false,\n writable: false,\n },\n });\n }\n}\n","import type { DeleteReferentialAction, UpdateReferentialAction } from '../../domain/index';\nimport type { ModelRef } from '../decorators/domain/ModelRef';\n\nexport const InternalNormalizedRelationOrigin = {\n FOREIGN_KEY: 'foreignKey',\n ONE_TO_ONE: 'oneToOne',\n MANY_TO_MANY: 'manyToMany',\n} as const;\nexport type NormalizedRelationOrigin =\n (typeof InternalNormalizedRelationOrigin)[keyof typeof InternalNormalizedRelationOrigin];\n\n/**\n * Registry-independent relation descriptor produced immediately after model\n * construction.\n *\n * This is the handoff object between relation authoring and relation\n * resolution. It preserves field-authored relation intent in a normalized form\n * without yet assigning public reverse names or resolved graph edges.\n */\nexport interface NormalizedRelationStorageDescriptor {\n edgeId: string;\n sourceModelKey: string;\n sourceSchemaFieldKey: string;\n targetRef: ModelRef;\n origin: NormalizedRelationOrigin;\n localFieldName: string;\n dbColumnName: string;\n referencedTargetColumn?: string;\n onDelete?: DeleteReferentialAction;\n onUpdate?: UpdateReferentialAction;\n unique?: boolean;\n explicitForwardName?: string;\n explicitReverseName?: string;\n namingHint: string;\n throughModelRef?: ModelRef;\n throughSourceFieldName?: string;\n throughTargetFieldName?: string;\n provenance: 'field-decorator';\n}\n","// Keep these as plain string literals rather than TS enums so the runtime\n// values stay identical across package boundaries without enum emit semantics.\nexport const InternalRelationPublicKind = {\n BELONGS_TO: 'belongsTo',\n HAS_ONE: 'hasOne',\n HAS_MANY: 'hasMany',\n MANY_TO_MANY: 'manyToMany',\n} as const;\n\nexport const InternalRelationStorageStrategy = {\n REFERENCE: 'reference',\n REVERSE_REFERENCE: 'reverse_reference',\n MANY_TO_MANY: 'many_to_many',\n} as const;\n\nexport const InternalRelationCardinality = {\n SINGLE: 'single',\n MANY: 'many',\n} as const;\n\nexport const InternalRelationProvenance = {\n FIELD_DECORATOR: 'field-decorator',\n RELATIONS_API: 'relations-api',\n SYNTHESIZED_REVERSE: 'synthesized-reverse',\n} as const;\n\nexport type RelationPublicKind = (typeof InternalRelationPublicKind)[keyof typeof InternalRelationPublicKind];\nexport type RelationStorageStrategy =\n (typeof InternalRelationStorageStrategy)[keyof typeof InternalRelationStorageStrategy];\nexport type RelationCardinality = (typeof InternalRelationCardinality)[keyof typeof InternalRelationCardinality];\nexport type RelationProvenance = (typeof InternalRelationProvenance)[keyof typeof InternalRelationProvenance];\n\n/**\n * Author-time relation intent after target resolution but before full graph\n * pairing and naming.\n *\n * This type is the conceptual bridge between normalized descriptors and the\n * fully resolved graph. It exists so the relations subdomain has a stable\n * vocabulary for relation kinds, storage strategies, and provenance as the\n * pipeline becomes more sophisticated.\n */\nexport interface RelationSpec {\n edgeId: string;\n sourceModelKey: string;\n sourceSchemaFieldKey?: string;\n targetModelKey: string;\n kind: RelationPublicKind;\n storageStrategy: RelationStorageStrategy;\n localFieldName?: string;\n targetFieldName?: string;\n nameHint?: string;\n throughModelKey?: string;\n throughSourceFieldName?: string;\n throughTargetFieldName?: string;\n provenance: RelationProvenance;\n}\n","import { createHash } from 'node:crypto';\n\n/**\n * Single source of truth for identity of Tango-synthesized many-to-many\n * through models. Other parts of the schema package interact with synthesized\n * models exclusively through this class so they do not have to know the\n * namespace or digest scheme those keys encode.\n */\nexport class ImplicitManyToManyIdentifier {\n private static readonly NAMESPACE = 'tango.implicit';\n\n /**\n * Stable model key for the synthesized through model connecting\n * `sourceModelKey` to `targetModelKey` via the schema field\n * `sourceSchemaFieldKey`.\n *\n * The returned key is deterministic across runs so storage and hydration\n * artifacts stay stable as long as the inputs match.\n */\n static getModelKey(sourceModelKey: string, sourceSchemaFieldKey: string, targetModelKey: string): string {\n const digest = ImplicitManyToManyIdentifier.digest(sourceModelKey, sourceSchemaFieldKey, targetModelKey, 32);\n return `${ImplicitManyToManyIdentifier.NAMESPACE}/m2m_${digest}`;\n }\n\n /**\n * Deterministic short digest used to derive the physical join-table name\n * for a synthesized through model. Shorter than the model-key digest so\n * table names stay within common SQL identifier limits.\n */\n static getTableBaseDigest(sourceModelKey: string, sourceSchemaFieldKey: string, targetModelKey: string): string {\n return ImplicitManyToManyIdentifier.digest(sourceModelKey, sourceSchemaFieldKey, targetModelKey, 16);\n }\n\n /**\n * True when `modelKey` was produced by {@link getModelKey} and therefore\n * identifies a synthesized through model. Callers use this instead of\n * comparing namespace prefixes so the namespace remains an implementation\n * detail of this class.\n */\n static isImplicitManyToManyModel(modelKey: string): boolean {\n return modelKey.startsWith(`${ImplicitManyToManyIdentifier.NAMESPACE}/`);\n }\n\n /**\n * Namespace under which synthesized through models are registered.\n * Exposed so {@link ImplicitManyToManyThroughFactory} can construct the\n * model with the correct namespace. External callers that want to ask\n * \"is this an implicit model\" should prefer {@link isImplicitManyToManyModel}.\n */\n static getNamespace(): string {\n return ImplicitManyToManyIdentifier.NAMESPACE;\n }\n\n /**\n * Extract the `m2m_<digest>` component of a synthesized model key so the\n * factory can register the through model with a deterministic name while\n * keeping the namespace owned by this class.\n */\n static getModelName(modelKey: string): string {\n const prefix = `${ImplicitManyToManyIdentifier.NAMESPACE}/`;\n if (!modelKey.startsWith(prefix)) {\n throw new Error(\n `ImplicitManyToManyIdentifier.getModelName expected a key produced by getModelKey, received '${modelKey}'.`\n );\n }\n return modelKey.slice(prefix.length);\n }\n\n private static digest(\n sourceModelKey: string,\n sourceSchemaFieldKey: string,\n targetModelKey: string,\n byteLength: number\n ): string {\n return createHash('sha256')\n .update(`${sourceModelKey}\\0${sourceSchemaFieldKey}\\0${targetModelKey}`, 'utf8')\n .digest('hex')\n .slice(0, byteLength);\n }\n}\n","export const InternalReferentialAction = {\n CASCADE: 'CASCADE',\n SET_NULL: 'SET NULL',\n RESTRICT: 'RESTRICT',\n NO_ACTION: 'NO ACTION',\n} as const;\n","import { z } from 'zod';\nimport type { IndexDef, Model } from '../../domain/index';\nimport { Decorators as t } from '../decorators/Decorators';\nimport type { ModelRef } from '../decorators/domain/ModelRef';\nimport { getFieldMetadata } from '../fields/FieldMetadataStore';\nimport type { ZodTypeAny } from '../decorators/domain/ZodTypeAny';\nimport {\n isZodArray,\n isZodBoolean,\n isZodDate,\n isZodDefault,\n isZodNullable,\n isZodNumber,\n isZodObject,\n isZodOptional,\n isZodString,\n} from '../../domain/internal/zod/index';\nimport { InternalSchemaModel } from '../internal/InternalSchemaModel';\nimport type { ModelRegistry } from '../registry/ModelRegistry';\nimport type { NormalizedRelationStorageDescriptor } from './NormalizedRelationStorageDescriptor';\nimport { InternalNormalizedRelationOrigin } from './NormalizedRelationStorageDescriptor';\nimport { decapitalizeModelName } from './SchemaNaming';\nimport { ImplicitManyToManyIdentifier } from './ImplicitManyToManyIdentifier';\nimport { InternalReferentialAction } from '../../domain/internal/InternalReferentialAction';\n\ntype PrimaryKeyShape = {\n fieldKey: string;\n zod: ZodTypeAny;\n dbColumn: string;\n};\n\nexport class ImplicitManyToManyThroughFactory {\n static throughFieldNames(\n sourceModel: Model,\n targetModel: Model\n ): {\n throughSourceFieldName: string;\n throughTargetFieldName: string;\n } {\n if (sourceModel.metadata.key === targetModel.metadata.key) {\n return {\n throughSourceFieldName: `from${sourceModel.metadata.name}`,\n throughTargetFieldName: `to${targetModel.metadata.name}`,\n };\n }\n\n return {\n throughSourceFieldName: `${decapitalizeModelName(sourceModel.metadata.name)}Id`,\n throughTargetFieldName: `${decapitalizeModelName(targetModel.metadata.name)}Id`,\n };\n }\n\n static buildModels(registry: ModelRegistry): Model[] {\n const descriptors = ImplicitManyToManyThroughFactory.collectImplicitDescriptors(registry);\n const models: Model[] = [];\n const occupiedTables = new Set<string>(\n [...registry.values()].map((m) => m.metadata.table.trim().toLowerCase())\n );\n\n for (const descriptor of descriptors) {\n const sourceModel = registry.getByKey(descriptor.sourceModelKey)!;\n\n const targetModel = registry.resolveRef(descriptor.targetRef);\n const identityKey = ImplicitManyToManyIdentifier.getModelKey(\n descriptor.sourceModelKey,\n descriptor.sourceSchemaFieldKey,\n targetModel.metadata.key\n );\n\n const pkSource = ImplicitManyToManyThroughFactory.readSinglePrimaryKey(sourceModel);\n const pkTarget = ImplicitManyToManyThroughFactory.readSinglePrimaryKey(targetModel);\n\n const digest = ImplicitManyToManyIdentifier.getTableBaseDigest(\n descriptor.sourceModelKey,\n descriptor.sourceSchemaFieldKey,\n targetModel.metadata.key\n );\n const tableName = ImplicitManyToManyThroughFactory.allocateTableName(occupiedTables, digest);\n\n const selfReferential = sourceModel.metadata.key === targetModel.metadata.key;\n let throughSchema: z.ZodObject<z.ZodRawShape>;\n let indexes: IndexDef[];\n\n if (selfReferential) {\n const leftKey = `from${sourceModel.metadata.name}`;\n const rightKey = `to${sourceModel.metadata.name}`;\n\n throughSchema = z.object({\n id: t.primaryKey(z.number().int()),\n [leftKey]: t.foreignKey(sourceModel as ModelRef, {\n field: pkSource.zod,\n onDelete: InternalReferentialAction.CASCADE,\n onUpdate: InternalReferentialAction.CASCADE,\n }),\n [rightKey]: t.foreignKey(sourceModel as ModelRef, {\n field: pkTarget.zod,\n onDelete: InternalReferentialAction.CASCADE,\n onUpdate: InternalReferentialAction.CASCADE,\n }),\n });\n indexes = [\n {\n name: `${tableName}_uniq_pair`,\n on: [leftKey, rightKey],\n unique: true,\n },\n ];\n } else {\n const sourceIdKey = `${decapitalizeModelName(sourceModel.metadata.name)}Id`;\n const targetIdKey = `${decapitalizeModelName(targetModel.metadata.name)}Id`;\n\n throughSchema = z.object({\n id: t.primaryKey(z.number().int()),\n [sourceIdKey]: t.foreignKey(sourceModel as ModelRef, {\n field: pkSource.zod,\n onDelete: InternalReferentialAction.CASCADE,\n onUpdate: InternalReferentialAction.CASCADE,\n }),\n [targetIdKey]: t.foreignKey(targetModel as ModelRef, {\n field: pkTarget.zod,\n onDelete: InternalReferentialAction.CASCADE,\n onUpdate: InternalReferentialAction.CASCADE,\n }),\n });\n\n indexes = [\n {\n name: `${tableName}_uniq_pair`,\n on: [sourceIdKey, targetIdKey],\n unique: true,\n },\n ];\n }\n\n const modelNamePart = ImplicitManyToManyIdentifier.getModelName(identityKey);\n\n const throughModel = InternalSchemaModel.create(\n {\n namespace: ImplicitManyToManyIdentifier.getNamespace(),\n name: modelNamePart,\n table: tableName,\n schema: throughSchema,\n registry,\n indexes,\n managed: true,\n },\n registry\n );\n\n models.push(throughModel);\n }\n\n return models;\n }\n\n private static unwrapForForeignKeyField(zodType: ZodTypeAny): ZodTypeAny {\n let inner: ZodTypeAny = zodType;\n while (isZodOptional(inner)) {\n inner = inner.unwrap() as ZodTypeAny;\n }\n while (isZodNullable(inner)) {\n inner = inner.unwrap() as ZodTypeAny;\n }\n while (isZodDefault(inner)) {\n inner = inner.removeDefault() as ZodTypeAny;\n }\n return inner;\n }\n\n private static clonePrimaryKeySchemaForForeignKey(zodType: ZodTypeAny): ZodTypeAny {\n const unwrapped = ImplicitManyToManyThroughFactory.unwrapForForeignKeyField(zodType);\n\n if (isZodNumber(unwrapped)) {\n const checks = unwrapped._zod.def.checks ?? [];\n const isInt = checks.some((check) => 'format' in check._zod.def && check._zod.def.format === 'safeint');\n return isInt ? z.number().int() : z.number();\n }\n\n if (isZodString(unwrapped)) {\n return z.string();\n }\n\n if (isZodBoolean(unwrapped)) {\n return z.boolean();\n }\n\n if (isZodDate(unwrapped)) {\n return z.date();\n }\n\n if (isZodObject(unwrapped)) {\n return z.object({});\n }\n\n if (isZodArray(unwrapped)) {\n return z.array(z.unknown());\n }\n\n throw new Error('Implicit many-to-many primary keys must resolve to a clonable scalar Zod schema.');\n }\n\n private static readSinglePrimaryKey(model: Model): PrimaryKeyShape {\n const keys: string[] = [];\n for (const [fieldKey, zodType] of Object.entries(model.schema.shape)) {\n const meta = getFieldMetadata(zodType as ZodTypeAny);\n if (meta?.primaryKey) {\n keys.push(fieldKey);\n }\n }\n\n if (keys.length !== 1) {\n throw new Error(\n `Implicit many-to-many requires model '${model.metadata.key}' to declare exactly one primary key field.`\n );\n }\n\n const fieldKey = keys[0]!;\n const zodType = model.schema.shape[fieldKey] as ZodTypeAny;\n const meta = getFieldMetadata(zodType);\n return {\n fieldKey,\n zod: ImplicitManyToManyThroughFactory.clonePrimaryKeySchemaForForeignKey(zodType),\n dbColumn: meta?.dbColumn ?? fieldKey,\n };\n }\n\n private static collectImplicitDescriptors(registry: ModelRegistry): NormalizedRelationStorageDescriptor[] {\n const out: NormalizedRelationStorageDescriptor[] = [];\n for (const model of registry.values()) {\n for (const descriptor of InternalSchemaModel.getNormalizedRelations(model)) {\n if (descriptor.origin !== InternalNormalizedRelationOrigin.MANY_TO_MANY) {\n continue;\n }\n if (\n descriptor.throughModelRef &&\n descriptor.throughSourceFieldName &&\n descriptor.throughTargetFieldName\n ) {\n continue;\n }\n out.push(descriptor);\n }\n }\n return out;\n }\n\n private static allocateTableName(occupied: Set<string>, digest: string): string {\n const base = `m2m_${digest}`;\n let candidate = base;\n let suffix = 0;\n while (occupied.has(candidate.toLowerCase())) {\n suffix += 1;\n candidate = `${base}_${suffix}`;\n }\n occupied.add(candidate.toLowerCase());\n return candidate;\n }\n}\n","import type { Model, RelationDef } from '../../domain/index';\nimport type { FinalizedStorageArtifacts } from '../fields/FinalizedStorageArtifacts';\nimport { InternalSchemaModel } from '../internal/InternalSchemaModel';\nimport type { ResolvedRelationGraphSnapshot } from '../registry/ResolvedRelationGraphSnapshot';\nimport {\n InternalNormalizedRelationOrigin,\n type NormalizedRelationStorageDescriptor,\n} from './NormalizedRelationStorageDescriptor';\nimport type { ResolvedRelationDescriptor, ResolvedRelationGraph } from './ResolvedRelationGraph';\nimport {\n type RelationCardinality,\n InternalRelationCardinality,\n InternalRelationPublicKind,\n InternalRelationProvenance,\n InternalRelationStorageStrategy,\n} from './RelationSpec';\nimport { ImplicitManyToManyThroughFactory } from './ImplicitManyToManyThroughFactory';\nimport { ImplicitManyToManyIdentifier } from './ImplicitManyToManyIdentifier';\nimport { pluralize, toSnakeCase } from './SchemaNaming';\n\nconst REFERENCE_CAPABILITIES = Object.freeze({\n migratable: true,\n queryable: true,\n hydratable: true,\n});\nconst MANY_TO_MANY_CAPABILITIES = Object.freeze({\n migratable: false,\n queryable: true,\n hydratable: true,\n});\nconst RELATION_NAME_SEPARATOR = ':';\n\ntype GraphBuilderOptions = {\n version: number;\n models: readonly Model[];\n storage: FinalizedStorageArtifacts;\n resolveRef: (ref: NormalizedRelationStorageDescriptor['targetRef']) => Model;\n};\n\n/**\n * Resolution-stage builder that turns normalized relation descriptors into the\n * registry-scoped resolved relation graph.\n *\n * This is the final pipeline stage in the relations subdomain. It combines:\n *\n * - normalized field-authored relation descriptors\n * - explicit model-level relation names from `RelationBuilder`\n * - finalized storage artifacts from the registry\n *\n * The result is the canonical named relation graph used by ORM-facing\n * consumers.\n */\nexport class ResolvedRelationGraphBuilder {\n private readonly byModel = new Map<string, Map<string, ResolvedRelationDescriptor>>();\n private readonly byEdgeId = new Map<string, ResolvedRelationDescriptor>();\n private readonly matchedOverrides = new Set<string>();\n\n constructor(private readonly options: GraphBuilderOptions) {}\n\n static build(options: GraphBuilderOptions): ResolvedRelationGraph {\n return new ResolvedRelationGraphBuilder(options).build();\n }\n\n /**\n * Serialize a resolved graph into the canonical snapshot shape used by\n * relation-registry code generation and fingerprinting.\n */\n static createSnapshot(graph: ResolvedRelationGraph): ResolvedRelationGraphSnapshot {\n return {\n models: Array.from(graph.byModel.entries())\n .sort(([left], [right]) => left.localeCompare(right))\n .map(([key, relations]) => ({\n key,\n relations: Array.from(relations.values())\n .sort((left, right) => left.name.localeCompare(right.name))\n .map((relation) => ({\n edgeId: relation.edgeId,\n sourceModelKey: relation.sourceModelKey,\n targetModelKey: relation.targetModelKey,\n name: relation.name,\n inverseEdgeId: relation.inverseEdgeId,\n kind: relation.kind,\n storageStrategy: relation.storageStrategy,\n cardinality: relation.cardinality,\n localFieldName: relation.localFieldName,\n targetFieldName: relation.targetFieldName,\n throughModelKey: relation.throughModelKey,\n throughTable: relation.throughTable,\n throughSourceFieldName: relation.throughSourceFieldName,\n throughTargetFieldName: relation.throughTargetFieldName,\n throughSourceKey: relation.throughSourceKey,\n throughTargetKey: relation.throughTargetKey,\n alias: relation.alias,\n capabilities: {\n migratable: relation.capabilities.migratable,\n queryable: relation.capabilities.queryable,\n hydratable: relation.capabilities.hydratable,\n },\n })),\n })),\n };\n }\n\n /**\n * Resolve every model's normalized relation descriptors into a single\n * registry-scoped graph and fail when authoring ambiguity remains.\n */\n build(): ResolvedRelationGraph {\n for (const model of this.options.models) {\n this.addModelRelations(model);\n }\n\n for (const model of this.options.models) {\n this.assertAllOverridesMatched(model);\n }\n\n return {\n version: this.options.version,\n byModel: this.byModel,\n byEdgeId: this.byEdgeId,\n };\n }\n\n private addModelRelations(model: Model): void {\n const explicitRelations = InternalSchemaModel.getExplicitRelations(model) ?? {};\n\n for (const descriptor of InternalSchemaModel.getNormalizedRelations(model)) {\n const targetModel = this.options.resolveRef(descriptor.targetRef);\n\n if (descriptor.origin === InternalNormalizedRelationOrigin.MANY_TO_MANY) {\n const relationName = descriptor.explicitForwardName ?? descriptor.namingHint;\n let throughModel: Model;\n let throughSourceFieldName: string;\n let throughTargetFieldName: string;\n\n if (\n descriptor.throughModelRef &&\n descriptor.throughSourceFieldName &&\n descriptor.throughTargetFieldName\n ) {\n throughModel = this.options.resolveRef(descriptor.throughModelRef);\n throughSourceFieldName = descriptor.throughSourceFieldName;\n throughTargetFieldName = descriptor.throughTargetFieldName;\n } else {\n throughModel = this.options.resolveRef(\n ImplicitManyToManyIdentifier.getModelKey(\n model.metadata.key,\n descriptor.sourceSchemaFieldKey,\n targetModel.metadata.key\n )\n );\n const implicitNames = ImplicitManyToManyThroughFactory.throughFieldNames(model, targetModel);\n throughSourceFieldName = implicitNames.throughSourceFieldName;\n throughTargetFieldName = implicitNames.throughTargetFieldName;\n }\n\n const throughNormalized = InternalSchemaModel.getNormalizedRelations(throughModel);\n const throughSource = throughNormalized.find(\n (rel) => rel.sourceSchemaFieldKey === throughSourceFieldName\n );\n const throughTarget = throughNormalized.find(\n (rel) => rel.sourceSchemaFieldKey === throughTargetFieldName\n );\n if (!throughSource || !throughTarget) {\n throw new Error(\n `Many-to-many relation '${relationName}' on model '${model.metadata.key}' cannot find through fields on '${throughModel.metadata.key}'.`\n );\n }\n\n const throughStorage = this.options.storage.byModel.get(throughModel.metadata.key);\n if (!throughStorage) {\n throw new Error(\n `Many-to-many relation '${relationName}' on model '${model.metadata.key}' cannot resolve storage artifacts for through model '${throughModel.metadata.key}'.`\n );\n }\n\n this.addResolvedRelation({\n edgeId: descriptor.edgeId,\n sourceModelKey: model.metadata.key,\n targetModelKey: targetModel.metadata.key,\n name: relationName,\n kind: InternalRelationPublicKind.MANY_TO_MANY,\n storageStrategy: InternalRelationStorageStrategy.MANY_TO_MANY,\n cardinality: InternalRelationCardinality.MANY,\n capabilities: MANY_TO_MANY_CAPABILITIES,\n provenance: InternalRelationProvenance.FIELD_DECORATOR,\n alias: `${toSnakeCase(model.metadata.name)}_${relationName}`,\n throughModelKey: throughModel.metadata.key,\n throughTable: throughStorage.table,\n throughSourceFieldName,\n throughTargetFieldName,\n throughSourceKey: throughSource.dbColumnName,\n throughTargetKey: throughTarget.dbColumnName,\n });\n continue;\n }\n\n this.addReferenceRelations(model, descriptor, targetModel, explicitRelations);\n }\n }\n\n private addReferenceRelations(\n sourceModel: Model,\n descriptor: NormalizedRelationStorageDescriptor,\n targetModel: Model,\n explicitRelations: Readonly<Record<string, RelationDef>>\n ): void {\n const forwardOverride = this.findForwardOverride(sourceModel, targetModel, descriptor, explicitRelations);\n if (forwardOverride) {\n this.markOverrideMatched(sourceModel.metadata.key, forwardOverride[0]);\n }\n\n const forwardName = forwardOverride?.[0] ?? descriptor.explicitForwardName ?? descriptor.namingHint;\n const targetPrimaryKey = this.getPrimaryKey(targetModel.metadata.key);\n this.addResolvedRelation({\n edgeId: descriptor.edgeId,\n sourceModelKey: sourceModel.metadata.key,\n targetModelKey: targetModel.metadata.key,\n name: forwardName,\n inverseEdgeId: `${descriptor.edgeId}:inverse`,\n kind: InternalRelationPublicKind.BELONGS_TO,\n storageStrategy: InternalRelationStorageStrategy.REFERENCE,\n cardinality: InternalRelationCardinality.SINGLE,\n localFieldName: descriptor.dbColumnName,\n targetFieldName: descriptor.referencedTargetColumn ?? targetPrimaryKey,\n capabilities: REFERENCE_CAPABILITIES,\n provenance: InternalRelationProvenance.FIELD_DECORATOR,\n alias: `${toSnakeCase(targetModel.metadata.name)}_${forwardName}`,\n });\n\n if (ImplicitManyToManyIdentifier.isImplicitManyToManyModel(sourceModel.metadata.key)) {\n return;\n }\n\n const reverseOverride = this.findReverseOverride(sourceModel, targetModel, descriptor);\n if (reverseOverride) {\n this.markOverrideMatched(targetModel.metadata.key, reverseOverride[0]);\n }\n\n const reverseKind = descriptor.unique\n ? InternalRelationPublicKind.HAS_ONE\n : InternalRelationPublicKind.HAS_MANY;\n const reverseCardinality = descriptor.unique\n ? InternalRelationCardinality.SINGLE\n : InternalRelationCardinality.MANY;\n const reverseName =\n reverseOverride?.[0] ??\n descriptor.explicitReverseName ??\n this.deriveReverseName(sourceModel, reverseCardinality);\n this.addResolvedRelation({\n edgeId: `${descriptor.edgeId}:inverse`,\n sourceModelKey: targetModel.metadata.key,\n targetModelKey: sourceModel.metadata.key,\n name: reverseName,\n inverseEdgeId: descriptor.edgeId,\n kind: reverseKind,\n storageStrategy: InternalRelationStorageStrategy.REVERSE_REFERENCE,\n cardinality: reverseCardinality,\n localFieldName: descriptor.dbColumnName,\n targetFieldName: descriptor.referencedTargetColumn ?? targetPrimaryKey,\n capabilities: REFERENCE_CAPABILITIES,\n provenance: reverseOverride\n ? InternalRelationProvenance.RELATIONS_API\n : InternalRelationProvenance.SYNTHESIZED_REVERSE,\n alias: `${toSnakeCase(sourceModel.metadata.name)}_${reverseName}`,\n });\n }\n\n private findForwardOverride(\n sourceModel: Model,\n targetModel: Model,\n descriptor: NormalizedRelationStorageDescriptor,\n explicitRelations: Readonly<Record<string, RelationDef>>\n ): [string, RelationDef] | undefined {\n return Object.entries(explicitRelations).find(([, relation]) => {\n const relationTargetKey = this.resolveRelationTargetKey(sourceModel, relation.target);\n return (\n relation.type === InternalRelationPublicKind.BELONGS_TO &&\n relationTargetKey === targetModel.metadata.key &&\n relation.foreignKey === descriptor.sourceSchemaFieldKey\n );\n });\n }\n\n private findReverseOverride(\n sourceModel: Model,\n targetModel: Model,\n descriptor: NormalizedRelationStorageDescriptor\n ): [string, RelationDef] | undefined {\n const reverseModelRelations = InternalSchemaModel.getExplicitRelations(targetModel) ?? {};\n const reverseKind = descriptor.unique\n ? InternalRelationPublicKind.HAS_ONE\n : InternalRelationPublicKind.HAS_MANY;\n return Object.entries(reverseModelRelations).find(([, relation]) => {\n const relationTargetKey = this.resolveRelationTargetKey(targetModel, relation.target);\n return (\n relationTargetKey === sourceModel.metadata.key &&\n relation.type === reverseKind &&\n relation.foreignKey === descriptor.sourceSchemaFieldKey\n );\n });\n }\n\n private assertAllOverridesMatched(model: Model): void {\n const explicitRelations = InternalSchemaModel.getExplicitRelations(model);\n if (!explicitRelations) {\n return;\n }\n\n for (const relationName of Object.keys(explicitRelations)) {\n const marker = this.buildOverrideMarker(model.metadata.key, relationName);\n if (!this.matchedOverrides.has(marker)) {\n throw new Error(\n `Relation override '${relationName}' on model '${model.metadata.key}' does not match a field-authored relation.`\n );\n }\n }\n }\n\n private addResolvedRelation(descriptor: ResolvedRelationDescriptor): void {\n const modelRelations =\n this.byModel.get(descriptor.sourceModelKey) ?? new Map<string, ResolvedRelationDescriptor>();\n const existing = modelRelations.get(descriptor.name);\n if (existing) {\n throw new Error(\n `Ambiguous relation name '${descriptor.name}' on model '${descriptor.sourceModelKey}'. Add an explicit relations override.`\n );\n }\n\n modelRelations.set(descriptor.name, descriptor);\n this.byModel.set(descriptor.sourceModelKey, modelRelations);\n this.byEdgeId.set(descriptor.edgeId, descriptor);\n }\n\n private getPrimaryKey(modelKey: string): string {\n return this.options.storage.byModel.get(modelKey)!.pk;\n }\n\n private markOverrideMatched(modelKey: string, relationName: string): void {\n this.matchedOverrides.add(this.buildOverrideMarker(modelKey, relationName));\n }\n\n private buildOverrideMarker(modelKey: string, relationName: string): string {\n return `${modelKey}${RELATION_NAME_SEPARATOR}${relationName}`;\n }\n\n private resolveRelationTargetKey(sourceModel: Model, target: string): string {\n if (target.includes('/')) {\n return target;\n }\n\n return `${sourceModel.metadata.namespace}/${target}`;\n }\n\n private deriveReverseName(sourceModel: Model, cardinality: RelationCardinality): string {\n if (sourceModel.metadata.defaultRelatedName) {\n return sourceModel.metadata.defaultRelatedName;\n }\n\n const snake = toSnakeCase(sourceModel.metadata.name);\n return cardinality === InternalRelationCardinality.MANY ? pluralize(snake) : snake;\n }\n}\n","import type { ResolvedRelationGraphSnapshot } from './ResolvedRelationGraphSnapshot';\n\n// These constants define the current generated-relation artifact contract.\n// They are centralized here so codegen, runtime drift checks, and CLI commands\n// share one default location and filename scheme.\nexport const GENERATED_RELATION_REGISTRY_DIRNAME = '.tango';\nexport const GENERATED_RELATION_REGISTRY_TYPES_FILENAME = 'relations.generated.d.ts';\nexport const GENERATED_RELATION_REGISTRY_METADATA_FILENAME = 'relations.generated.json';\nexport const GENERATED_RELATION_REGISTRY_METADATA_VERSION = 1;\n\nexport type GeneratedRelationRegistryArtifact = {\n version: typeof GENERATED_RELATION_REGISTRY_METADATA_VERSION;\n fingerprint: string;\n snapshot: ResolvedRelationGraphSnapshot;\n};\n","// oxlint-disable unicorn/no-static-only-class\nimport { createHash } from 'node:crypto';\nimport type { ResolvedRelationGraph } from '../relations/ResolvedRelationGraph';\nimport { ResolvedRelationGraphBuilder } from '../relations/ResolvedRelationGraphBuilder';\nimport type { ResolvedRelationGraphSnapshot } from './ResolvedRelationGraphSnapshot';\n\n/**\n * Build canonical serialized artifacts from a resolved relation graph.\n *\n * Generation, drift detection, and related tooling all need the same stable\n * snapshot shape and fingerprinting rules, so that work lives behind one class\n * instead of a pair of free functions.\n */\nexport class ResolvedRelationGraphArtifactFactory {\n static createSnapshot(graph: ResolvedRelationGraph): ResolvedRelationGraphSnapshot {\n return ResolvedRelationGraphBuilder.createSnapshot(graph);\n }\n\n static createFingerprint(value: ResolvedRelationGraph | ResolvedRelationGraphSnapshot): string {\n const snapshot = 'byModel' in value ? ResolvedRelationGraphArtifactFactory.createSnapshot(value) : value;\n return createHash('sha256').update(JSON.stringify(snapshot)).digest('hex');\n }\n}\n","import { AsyncLocalStorage } from 'node:async_hooks';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { getLogger } from '@danceroutine/tango-core';\nimport type { Field, Model } from '../../domain/index';\nimport type { ZodTypeAny } from '../decorators/domain/ZodTypeAny';\nimport { isTypedModelRef, type ModelRef } from '../decorators/domain/ModelRef';\nimport { inferFieldsFromSchema } from '../fields/inferFieldsFromSchema';\nimport { getFieldMetadata } from '../fields/FieldMetadataStore';\nimport type { FinalizedStorageArtifacts, FinalizedStorageModel } from '../fields/FinalizedStorageArtifacts';\nimport { InternalSchemaModel } from '../internal/InternalSchemaModel';\nimport type { ResolvedRelationGraph } from '../relations/ResolvedRelationGraph';\nimport { ResolvedRelationGraphBuilder } from '../relations/ResolvedRelationGraphBuilder';\nimport {\n GENERATED_RELATION_REGISTRY_DIRNAME,\n GENERATED_RELATION_REGISTRY_METADATA_FILENAME,\n GENERATED_RELATION_REGISTRY_METADATA_VERSION,\n type GeneratedRelationRegistryArtifact,\n} from './GeneratedRelationRegistryArtifact';\nimport { ResolvedRelationGraphArtifactFactory } from './ResolvedRelationGraphArtifactFactory';\nimport type { ResolvedRelationGraphSnapshot } from './ResolvedRelationGraphSnapshot';\nimport { ImplicitManyToManyIdentifier } from '../relations/ImplicitManyToManyIdentifier';\nimport { ImplicitManyToManyThroughFactory } from '../relations/ImplicitManyToManyThroughFactory';\n\nconst DEFAULT_IDENTIFIER_NAME = 'id';\nconst ACTIVE_REGISTRY_STORAGE_KEY = Symbol.for('tango.schema.activeRegistryStorage');\n\ntype ModelRegistryRuntimeGlobal = typeof globalThis & {\n [ACTIVE_REGISTRY_STORAGE_KEY]?: AsyncLocalStorage<ModelRegistry>;\n};\n\n/**\n * Registry that resolves Tango models by stable identity.\n *\n * The default shared registry is convenient for application bootstrapping\n * within one schema package instance, while dedicated instances are useful in\n * tests and tooling. Explicit active-registry binding stays process-shared so\n * tooling can construct models across separate schema package copies without\n * relying on the ambient default registry.\n */\nexport class ModelRegistry {\n private static globalRegistry?: ModelRegistry;\n private readonly models = new Map<string, Model>();\n private version = 0;\n private storageCache?: FinalizedStorageArtifacts;\n private relationGraphCache?: ResolvedRelationGraph;\n private lastRelationRegistryDriftCheckVersion?: number;\n\n /**\n * Return the shared default registry used by `Model(...)` for this schema\n * package instance.\n */\n static global(): ModelRegistry {\n ModelRegistry.globalRegistry ??= new ModelRegistry();\n return ModelRegistry.globalRegistry;\n }\n\n /**\n * Return the registry currently bound to model construction work.\n *\n * This explicit binding is process-shared so code that imports separate\n * schema package copies can still participate in one construction flow.\n */\n static active(): ModelRegistry {\n return ModelRegistry.activeRegistryStorage().getStore() ?? ModelRegistry.global();\n }\n\n /**\n * Run work with a specific registry bound as the active construction target.\n */\n static async runWithRegistry<T>(registry: ModelRegistry, work: () => Promise<T> | T): Promise<T> {\n return await ModelRegistry.activeRegistryStorage().run(registry, work);\n }\n\n /**\n * Register a model on the shared global registry.\n */\n static register(model: Model): void {\n ModelRegistry.global().register(model);\n }\n\n /**\n * Register several models on the shared global registry.\n */\n static registerMany(models: readonly Model[]): void {\n ModelRegistry.global().registerMany(models);\n }\n\n /**\n * Resolve a model from the shared registry by namespace and name.\n */\n static get(namespace: string, name: string): Model | undefined {\n return ModelRegistry.global().get(namespace, name);\n }\n\n /**\n * Resolve a model from the shared registry by its `namespace/name` key.\n */\n static getByKey(key: string): Model | undefined {\n return ModelRegistry.global().getByKey(key);\n }\n\n /**\n * Resolve any supported model reference form against the shared registry.\n */\n static resolveRef(ref: ModelRef): Model {\n return ModelRegistry.global().resolveRef(ref);\n }\n\n /**\n * Clear the shared registry, which is mainly useful in tests.\n */\n static clear(): void {\n ModelRegistry.global().clear();\n }\n\n /**\n * Return the owning registry for a model.\n */\n static getOwner(model: { metadata: { key?: string } } & object): ModelRegistry {\n return InternalSchemaModel.getRegistryOwner(model as Model);\n }\n\n private static runtimeGlobal(): ModelRegistryRuntimeGlobal {\n return globalThis as ModelRegistryRuntimeGlobal;\n }\n\n private static activeRegistryStorage(): AsyncLocalStorage<ModelRegistry> {\n const runtimeGlobal = ModelRegistry.runtimeGlobal();\n\n if (!runtimeGlobal[ACTIVE_REGISTRY_STORAGE_KEY]) {\n runtimeGlobal[ACTIVE_REGISTRY_STORAGE_KEY] = new AsyncLocalStorage<ModelRegistry>();\n }\n\n return runtimeGlobal[ACTIVE_REGISTRY_STORAGE_KEY];\n }\n\n /**\n * Register a model on this registry instance.\n */\n register(model: Model): void {\n // A model's finalized storage and relation artifacts are registry-scoped.\n // Rejecting cross-registry reuse here prevents one model object from\n // publishing conflicting finalized views in multiple registries.\n const owner = InternalSchemaModel.getRegistryOwner(model);\n if (owner !== this) {\n throw new Error(\n `Model '${model.metadata.key}' belongs to a different registry and cannot be registered here.`\n );\n }\n\n const existing = this.models.get(model.metadata.key);\n if (existing && existing !== model) {\n throw new Error(`Model '${model.metadata.key}' is already registered in this registry.`);\n }\n\n this.models.set(model.metadata.key, model);\n this.bumpVersion();\n }\n\n /**\n * Register several models on this registry instance.\n */\n registerMany(models: readonly Model[]): void {\n for (const model of models) {\n this.register(model);\n }\n }\n\n /**\n * Resolve a model from this registry instance by namespace and name.\n */\n get(namespace: string, name: string): Model | undefined {\n return this.getByKey(`${namespace}/${name}`);\n }\n\n /**\n * Resolve a model from this registry instance by its `namespace/name` key.\n */\n getByKey(key: string): Model | undefined {\n return this.models.get(key);\n }\n\n /**\n * Resolve a string, callback, or direct model reference into a model object.\n */\n resolveRef(ref: ModelRef): Model {\n if (typeof ref === 'string' || isTypedModelRef(ref)) {\n const key = typeof ref === 'string' ? ref : ref.key;\n const model = this.getByKey(key);\n if (!model) {\n throw new Error(\n `Unable to resolve model reference '${key}'. Ensure it is registered in ModelRegistry.`\n );\n }\n return model;\n }\n\n const model = typeof ref === 'function' ? ref() : ref;\n if (InternalSchemaModel.getRegistryOwner(model) !== this) {\n throw new Error(\n `Model reference '${model.metadata.key}' belongs to a different registry and cannot be resolved here.`\n );\n }\n return model;\n }\n\n /**\n * Finalize storage-only artifacts for all models in this registry.\n */\n finalizeStorageArtifacts(): FinalizedStorageArtifacts {\n if (this.storageCache?.version === this.version) {\n return this.storageCache;\n }\n\n const strippedImplicit = this.stripImplicitManyToManyModels();\n const implicitThroughModels = ImplicitManyToManyThroughFactory.buildModels(this);\n for (const model of implicitThroughModels) {\n this.models.set(model.metadata.key, model);\n }\n if (strippedImplicit || implicitThroughModels.length > 0) {\n this.bumpVersion();\n }\n\n const primaryKeyByModel = new Map<string, string>();\n for (const model of this.models.values()) {\n primaryKeyByModel.set(model.metadata.key, this.inferPrimaryKeyName(model));\n }\n\n const byModel = new Map<string, FinalizedStorageModel>();\n for (const model of this.models.values()) {\n const explicitFields = InternalSchemaModel.getExplicitFields(model);\n const inferredFields = inferFieldsFromSchema(model.schema, {\n registry: this,\n resolveReferenceTarget: (target) => {\n const targetModel = this.resolveRef(target);\n return {\n table: targetModel.metadata.table,\n pk: primaryKeyByModel.get(targetModel.metadata.key)!,\n };\n },\n });\n const fields = this.freezeFields(this.mergeStorageFields(inferredFields, explicitFields));\n const primaryKey = fields.find((field) => field.primaryKey)?.name ?? DEFAULT_IDENTIFIER_NAME;\n\n byModel.set(model.metadata.key, {\n key: model.metadata.key,\n table: model.metadata.table,\n fields,\n pk: primaryKey,\n });\n }\n\n const finalized: FinalizedStorageArtifacts = {\n version: this.version,\n byModel,\n };\n this.storageCache = finalized;\n return finalized;\n }\n\n /**\n * Return finalized storage fields for a specific model.\n */\n getFinalizedFields(model: Model | string): readonly Field[] {\n const key = typeof model === 'string' ? model : model.metadata.key;\n const fields = this.finalizeStorageArtifacts().byModel.get(key)?.fields;\n if (!fields) {\n throw new Error(`No finalized storage fields are available for model '${key}'.`);\n }\n return fields;\n }\n\n /**\n * Resolve the registry's relation graph from finalized storage artifacts.\n */\n getResolvedRelationGraph(): ResolvedRelationGraph {\n if (this.relationGraphCache?.version === this.version) {\n return this.relationGraphCache;\n }\n\n // The registry owns cache/version orchestration. The dedicated builder owns\n // forward edge resolution, reverse synthesis, and override validation.\n const storage = this.finalizeStorageArtifacts();\n const finalized = ResolvedRelationGraphBuilder.build({\n version: this.version,\n models: this.values(),\n storage,\n resolveRef: (ref) => this.resolveRef(ref),\n });\n this.relationGraphCache = finalized;\n this.warnOnGeneratedRelationRegistryDrift(finalized);\n return finalized;\n }\n\n /**\n * Return a canonical snapshot of the resolved relation graph.\n */\n getResolvedRelationGraphSnapshot(): ResolvedRelationGraphSnapshot {\n return ResolvedRelationGraphArtifactFactory.createSnapshot(this.getResolvedRelationGraph());\n }\n\n /**\n * Return a deterministic fingerprint for the resolved relation graph.\n */\n getResolvedRelationGraphFingerprint(): string {\n return ResolvedRelationGraphArtifactFactory.createFingerprint(this.getResolvedRelationGraph());\n }\n\n /**\n * Remove all registered models from this registry instance.\n */\n clear(): void {\n this.models.clear();\n this.bumpVersion();\n }\n\n /**\n * Return all registered models in insertion order.\n */\n values(): readonly Model[] {\n return Array.from(this.models.values());\n }\n\n private bumpVersion(): void {\n this.version += 1;\n this.storageCache = undefined;\n this.relationGraphCache = undefined;\n this.lastRelationRegistryDriftCheckVersion = undefined;\n }\n\n private stripImplicitManyToManyModels(): boolean {\n let removed = false;\n for (const key of this.models.keys()) {\n if (ImplicitManyToManyIdentifier.isImplicitManyToManyModel(key)) {\n this.models.delete(key);\n removed = true;\n }\n }\n return removed;\n }\n\n private freezeFields(fields: readonly Field[]): readonly Field[] {\n return Object.freeze(fields.map((field) => Object.freeze({ ...field })));\n }\n\n private inferPrimaryKeyName(model: Model): string {\n for (const [fieldKey, zodType] of Object.entries(model.schema.shape)) {\n const meta = getFieldMetadata(zodType as ZodTypeAny);\n if (meta?.primaryKey) {\n return meta.dbColumn ?? fieldKey;\n }\n }\n\n const explicitFields = InternalSchemaModel.getExplicitFields(model);\n if (explicitFields) {\n return explicitFields.find((field) => field.primaryKey)?.name ?? DEFAULT_IDENTIFIER_NAME;\n }\n\n return DEFAULT_IDENTIFIER_NAME;\n }\n\n private mergeStorageFields(inferredFields: readonly Field[], explicitFields?: readonly Field[]): readonly Field[] {\n if (!explicitFields?.length) {\n return inferredFields;\n }\n\n const mergedFields = new Map(inferredFields.map((field) => [field.name, field]));\n for (const explicitField of explicitFields) {\n mergedFields.set(explicitField.name, explicitField);\n }\n\n return Array.from(mergedFields.values());\n }\n\n private warnOnGeneratedRelationRegistryDrift(graph: ResolvedRelationGraph): void {\n if (\n this.lastRelationRegistryDriftCheckVersion === this.version ||\n !this.shouldCheckGeneratedRelationRegistry()\n ) {\n return;\n }\n this.lastRelationRegistryDriftCheckVersion = this.version;\n\n const expected = this.readGeneratedRelationRegistryArtifact();\n if (!expected) {\n return;\n }\n\n // Compare against the same canonical snapshot shape that code\n // generation writes so drift checks operate on one shared contract.\n const liveSnapshot = ResolvedRelationGraphArtifactFactory.createSnapshot(graph);\n if (this.isPartialRegistrySnapshot(liveSnapshot, expected.snapshot)) {\n return;\n }\n\n const liveFingerprint = ResolvedRelationGraphArtifactFactory.createFingerprint(liveSnapshot);\n if (liveFingerprint === expected.fingerprint) {\n return;\n }\n\n getLogger('tango.schema.registry').warn(\n `Generated relation registry drift detected. Run 'tango codegen relations' to refresh ${GENERATED_RELATION_REGISTRY_DIRNAME}/${GENERATED_RELATION_REGISTRY_METADATA_FILENAME}.`\n );\n }\n\n private shouldCheckGeneratedRelationRegistry(): boolean {\n return process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';\n }\n\n private readGeneratedRelationRegistryArtifact(): GeneratedRelationRegistryArtifact | undefined {\n const metadataPath = resolve(\n process.cwd(),\n GENERATED_RELATION_REGISTRY_DIRNAME,\n GENERATED_RELATION_REGISTRY_METADATA_FILENAME\n );\n if (!existsSync(metadataPath)) {\n return undefined;\n }\n\n try {\n const parsed = JSON.parse(readFileSync(metadataPath, 'utf8')) as Partial<GeneratedRelationRegistryArtifact>;\n if (\n parsed.version !== GENERATED_RELATION_REGISTRY_METADATA_VERSION ||\n typeof parsed.fingerprint !== 'string' ||\n !parsed.snapshot ||\n !Array.isArray(parsed.snapshot.models)\n ) {\n getLogger('tango.schema.registry').warn(\n `Ignoring malformed generated relation registry metadata at '${metadataPath}'.`\n );\n return undefined;\n }\n\n return parsed as GeneratedRelationRegistryArtifact;\n } catch (error) {\n getLogger('tango.schema.registry').warn(\n `Unable to read generated relation registry metadata at '${metadataPath}'.`,\n error\n );\n return undefined;\n }\n }\n\n private isPartialRegistrySnapshot(\n liveSnapshot: ResolvedRelationGraphSnapshot,\n expectedSnapshot: ResolvedRelationGraphSnapshot\n ): boolean {\n const expectedModels = new Map(expectedSnapshot.models.map((model) => [model.key, model]));\n if (liveSnapshot.models.some((model) => !expectedModels.has(model.key))) {\n return false;\n }\n\n if (liveSnapshot.models.length >= expectedSnapshot.models.length) {\n return false;\n }\n\n for (const model of liveSnapshot.models) {\n const expectedModel = expectedModels.get(model.key)!;\n if (JSON.stringify(model.relations) !== JSON.stringify(expectedModel.relations)) {\n return false;\n }\n }\n\n return true;\n }\n}\n","import { existsSync } from 'node:fs';\nimport { dirname, extname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nconst LOCAL_ENTRYPOINT_CANDIDATES = ['./index.ts', './index.js'] as const;\n\n/**\n * Resolve the current package root entrypoint for `@danceroutine/tango-schema`.\n *\n * Tooling loaders alias app-side `@danceroutine/tango-schema` imports back to\n * this path so project modules reuse the same schema package instance across\n * workspace-source and published-dist environments.\n */\nexport function resolveSchemaModuleEntrypoint(): string {\n for (const relativePath of LOCAL_ENTRYPOINT_CANDIDATES) {\n const absolutePath = fileURLToPath(new URL(relativePath, import.meta.url));\n if (existsSync(absolutePath)) {\n return absolutePath;\n }\n }\n\n throw new Error(\n `Unable to resolve the @danceroutine/tango-schema entrypoint relative to '${fileURLToPath(import.meta.url)}'.`\n );\n}\n\n/**\n * Return explicit Jiti alias entries for the schema package root and its\n * public subpaths so app modules always reuse the same schema package instance.\n *\n * @internal\n * Exported for Tango tooling/framework consumption only. This helper exists so\n * Tango loaders can force app modules to reuse the active schema package\n * instance during module execution. It is not intended as a stable application\n * API, and the alias map may be more permissive than the package exports\n * surface by design.\n */\nexport function createSchemaModuleAliases(): Record<string, string> {\n const entrypoint = resolveSchemaModuleEntrypoint();\n const packageRoot = dirname(entrypoint);\n const extension = extname(entrypoint);\n const modelEntrypoint = resolve(packageRoot, 'model', `index${extension}`);\n const domainEntrypoint = resolve(packageRoot, 'domain', `index${extension}`);\n\n if (!existsSync(modelEntrypoint) || !existsSync(domainEntrypoint)) {\n throw new Error(\n `Unable to resolve the @danceroutine/tango-schema subpath entrypoints relative to '${entrypoint}'.`\n );\n }\n\n return {\n '@danceroutine/tango-schema': entrypoint,\n '@danceroutine/tango-schema/model': modelEntrypoint,\n '@danceroutine/tango-schema/domain': domainEntrypoint,\n // Deliberately permissive for tooling-time identity unification. This\n // is not intended to widen the package's supported end-user API.\n '@danceroutine/tango-schema/': `${packageRoot}/`,\n };\n}\n","/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\nexport { ModelRegistry } from './ModelRegistry';\nexport { createSchemaModuleAliases, resolveSchemaModuleEntrypoint } from '../../resolveSchemaModuleEntrypoint';\nexport {\n GENERATED_RELATION_REGISTRY_DIRNAME,\n GENERATED_RELATION_REGISTRY_METADATA_FILENAME,\n GENERATED_RELATION_REGISTRY_METADATA_VERSION,\n GENERATED_RELATION_REGISTRY_TYPES_FILENAME,\n type GeneratedRelationRegistryArtifact,\n} from './GeneratedRelationRegistryArtifact';\nexport { ResolvedRelationGraphArtifactFactory } from './ResolvedRelationGraphArtifactFactory';\nexport {\n type ResolvedRelationGraphSnapshot,\n type ResolvedRelationGraphSnapshotModel,\n type ResolvedRelationGraphSnapshotRelation,\n} from './ResolvedRelationGraphSnapshot';\n","/**\n * Domain boundary barrel for relation authoring.\n *\n * The relations subdomain has three internal layers:\n *\n * - authoring: `RelationBuilder`\n * - normalization: field-authored relations become normalized descriptors\n * - resolution: normalized descriptors become the registry-scoped relation graph\n *\n * Only the authoring surface is exported here. The later pipeline stages stay\n * internal until Tango intentionally publishes them as supported contracts.\n */\nexport { RelationBuilder } from './RelationBuilder';\n","import type { z } from 'zod';\nimport type { Model } from '../domain/Model';\nimport { ModelRegistry } from './registry/ModelRegistry';\n\nexport type ModelAugmentor = <TSchema extends z.ZodObject<z.ZodRawShape>, TKey extends string>(\n model: Model<TSchema, TKey>\n) => void;\n\nconst modelAugmentors = new Set<ModelAugmentor>();\n\n/**\n * Register a model augmentor that runs for existing and future models.\n */\nexport function registerModelAugmentor(augmentor: ModelAugmentor): () => void {\n modelAugmentors.add(augmentor);\n\n for (const model of ModelRegistry.global().values()) {\n augmentor(model);\n }\n\n return () => {\n modelAugmentors.delete(augmentor);\n };\n}\n\n/**\n * Apply all registered augmentors to a model before it is returned publicly.\n */\nexport function applyModelAugmentors<TSchema extends z.ZodObject<z.ZodRawShape>, TKey extends string>(\n model: Model<TSchema, TKey>\n): Model<TSchema, TKey> {\n for (const augmentor of modelAugmentors) {\n augmentor(model);\n }\n\n return model;\n}\n","import { z } from 'zod';\nimport type { Model as SchemaModel } from '../domain/Model';\nimport type { ModelDefinition } from './ModelDefinition';\nimport { applyModelAugmentors } from './ModelAugmentorRegistry';\nimport { InternalSchemaModel } from './internal/InternalSchemaModel';\nimport { ModelRegistry } from './registry/ModelRegistry';\n\n/**\n * Creates a model definition with metadata and schema validation.\n * Automatically finalizes field types through the owning model registry.\n */\nexport function Model<\n const TNamespace extends string,\n const TName extends string,\n TSchema extends z.ZodObject<z.ZodRawShape>,\n>(\n definition: ModelDefinition<TSchema> & { namespace: TNamespace; name: TName }\n): SchemaModel<TSchema, `${TNamespace}/${TName}`> {\n const registry = definition.registry ?? ModelRegistry.active();\n const model = applyModelAugmentors(\n InternalSchemaModel.create(definition, registry) as SchemaModel<TSchema, `${TNamespace}/${TName}`>\n );\n\n registry.register(model);\n return model;\n}\n","/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n *\n * Tango keeps both flat exports and namespaced subdomain barrels here so\n * callers can choose TS-native direct imports or Django-style drill-down\n * access through the bundled `model` namespace at the package root.\n */\n\nexport * as decorators from './decorators/index';\nexport * as meta from './meta/index';\nexport * as constraints from './constraints/index';\nexport * as registry from './registry/index';\nexport * as relations from './relations/index';\n\nexport type { ModelDefinition } from './ModelDefinition';\nexport { RelationBuilder } from './relations/index';\nexport { ImplicitManyToManyIdentifier } from './relations/ImplicitManyToManyIdentifier';\nexport { Model } from './Model';\nexport { registerModelAugmentor } from './ModelAugmentorRegistry';\nexport { Decorators, t } from './decorators/index';\nexport type {\n TangoDecorators,\n FieldDecoratorBuilder,\n DecoratedFieldKind,\n ModelRef,\n ModelRefTarget,\n RelationDecoratedSchema,\n TypedModelRef,\n ForeignKeyDecoratorConfig,\n OneToOneDecoratorConfig,\n ManyToManyDecoratorConfig,\n} from './decorators/index';\nexport { createTypedModelRef, InternalDecoratedFieldKind, isTypedModelRef } from './decorators/index';\nexport { Meta, m } from './meta/index';\nexport type { ModelConstraint, ModelMetaFragment } from './meta/index';\nexport { Constraints, Indexes, c, i } from './constraints/index';\nexport type { ConstraintDefinition } from './constraints/index';\nexport {\n ModelRegistry,\n createSchemaModuleAliases,\n resolveSchemaModuleEntrypoint,\n GENERATED_RELATION_REGISTRY_DIRNAME,\n GENERATED_RELATION_REGISTRY_METADATA_FILENAME,\n GENERATED_RELATION_REGISTRY_METADATA_VERSION,\n GENERATED_RELATION_REGISTRY_TYPES_FILENAME,\n ResolvedRelationGraphArtifactFactory,\n type GeneratedRelationRegistryArtifact,\n type ResolvedRelationGraphSnapshot,\n type ResolvedRelationGraphSnapshotModel,\n type ResolvedRelationGraphSnapshotRelation,\n} from './registry/index';\n"],"mappings":";;;;;;;;;AAGA,MAAM,qCAAqB,IAAI,QAAoC;AAEnE,SAAgB,iBAAiB,QAAgD;CAC7E,OAAO,mBAAmB,IAAI,MAAM;AACxC;AAEA,SAAgB,iBAAiB,QAAoB,MAA4B;CAC7E,MAAM,WAAW,mBAAmB,IAAI,MAAM;CAC9C,mBAAmB,IAAI,QAAQ;EAC3B,GAAG;EACH,GAAG;CACP,CAAC;AACL;;;ACSA,SAAgB,oBAA0C,KAAgD;CACtG,OA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;;;;;;;;;;;;;;;;AGlDA,MAAM,kCAAkB,IAAI,IAAoB;;;;AAKhD,SAAgB,uBAAuB,WAAuC;CAC1E,gBAAgB,IAAI,SAAS;CAE7B,KAAK,MAAM,SAAS,cAAc,OAAO,CAAC,CAAC,OAAO,GAC9C,UAAU,KAAK;CAGnB,aAAa;EACT,gBAAgB,OAAO,SAAS;CACpC;AACJ;;;;AAKA,SAAgB,qBACZ,OACoB;CACpB,KAAK,MAAM,aAAa,iBACpB,UAAU,KAAK;CAGnB,OAAO;AACX;;;;;;;ACzBA,SAAgB,MAKZ,YAC8C;CAC9C,MAAM,WAAW,WAAW,YAAY,cAAc,OAAO;CAC7D,MAAM,QAAQ,qBACV,oBAAoB,OAAO,YAAY,QAAQ,CACnD;CAEA,SAAS,SAAS,KAAK;CACvB,OAAO;AACX"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danceroutine/tango-schema",
3
- "version": "1.11.15",
3
+ "version": "1.12.0",
4
4
  "description": "Model factory, Zod helpers, and metadata utilities for Tango",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -38,11 +38,11 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "zod": "^4.0.0",
41
- "@danceroutine/tango-core": "1.11.15"
41
+ "@danceroutine/tango-core": "1.12.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/node": "^25.9.1",
45
- "tsdown": "^0.22.1",
45
+ "tsdown": "^0.22.2",
46
46
  "typescript": "^6.0.3",
47
47
  "vitest": "^4.1.8"
48
48
  },