@danceroutine/tango-schema 1.2.0 → 1.4.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.
- package/dist/domain/Model.d.ts +12 -5
- package/dist/domain/ModelWriteHooks.d.ts +14 -0
- package/dist/domain/index.d.ts +2 -2
- package/dist/domain-Cufz6y1q.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/model/Model.d.ts +4 -1
- package/dist/model/ModelAugmentorRegistry.d.ts +2 -2
- package/dist/model/decorators/Decorators.d.ts +18 -10
- package/dist/model/decorators/domain/DecoratedFieldKind.d.ts +2 -2
- package/dist/model/decorators/domain/ModelRef.d.ts +11 -2
- package/dist/model/decorators/domain/RelationDecoratedSchema.d.ts +16 -1
- package/dist/model/decorators/index.d.ts +5 -1
- package/dist/model/index.d.ts +2 -1
- package/dist/model/index.js +2 -2
- package/dist/model/internal/InternalSchemaModel.d.ts +2 -2
- package/dist/model/registry/ModelRegistry.d.ts +1 -1
- package/dist/model/relations/NormalizedRelationStorageDescriptor.d.ts +2 -2
- package/dist/model/relations/RelationSpec.d.ts +8 -8
- package/dist/{model-CJbsYdkM.js → model-YLW1ydkV.js} +56 -36
- package/dist/model-YLW1ydkV.js.map +1 -0
- package/package.json +2 -2
- package/dist/model/decorators/domain/ManyToManyDecoratedSchema.d.ts +0 -4
- package/dist/model-CJbsYdkM.js.map +0 -1
package/dist/domain/Model.d.ts
CHANGED
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
import type { z } from 'zod';
|
|
2
2
|
import type { ModelMetadata } from './ModelMetadata';
|
|
3
3
|
import type { ModelWriteHooks } from './ModelWriteHooks';
|
|
4
|
-
import
|
|
4
|
+
import { InternalDecoratedFieldKind } from '../model/decorators/domain/DecoratedFieldKind';
|
|
5
|
+
import type { RelationDecoratedSchemaKind } from '../model/decorators/domain/RelationDecoratedSchema';
|
|
5
6
|
declare const MODEL_AUGMENTATION_SCHEMA: unique symbol;
|
|
7
|
+
declare const MODEL_KEY: unique symbol;
|
|
6
8
|
type ModelAugmentationCarrier<TSchema extends z.ZodObject<z.ZodRawShape>> = {
|
|
7
9
|
readonly [MODEL_AUGMENTATION_SCHEMA]?: TSchema;
|
|
8
10
|
};
|
|
11
|
+
type ModelKeyCarrier<TKey extends string> = {
|
|
12
|
+
readonly [MODEL_KEY]?: TKey;
|
|
13
|
+
};
|
|
14
|
+
type IsAny<TValue> = 0 extends 1 & TValue ? true : false;
|
|
9
15
|
declare global {
|
|
10
|
-
interface TangoSchemaModelAugmentations<TSchema extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape
|
|
16
|
+
interface TangoSchemaModelAugmentations<TSchema extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, TKey extends string = string> {
|
|
11
17
|
}
|
|
12
18
|
}
|
|
13
19
|
type ManyToManyFieldKeys<TShape extends z.ZodRawShape> = {
|
|
14
|
-
[K in keyof TShape]: TShape[K] extends
|
|
20
|
+
[K in keyof TShape]: IsAny<TShape[K]> extends true ? never : [RelationDecoratedSchemaKind<TShape[K]>] extends [never] ? never : [RelationDecoratedSchemaKind<TShape[K]>] extends [typeof InternalDecoratedFieldKind.MANY_TO_MANY] ? K : never;
|
|
15
21
|
}[keyof TShape];
|
|
16
22
|
type PersistedShape<TShape extends z.ZodRawShape> = Omit<z.output<z.ZodObject<TShape>>, ManyToManyFieldKeys<TShape>>;
|
|
17
23
|
export type PersistedModelOutput<TSchema extends z.ZodObject<z.ZodRawShape>> = TSchema extends z.ZodObject<infer TShape> ? PersistedShape<TShape> : z.output<TSchema>;
|
|
18
|
-
export interface ModelAugmentations<TSchema extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape
|
|
24
|
+
export interface ModelAugmentations<TSchema extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, TKey extends string = string> extends ModelAugmentationCarrier<TSchema>, ModelKeyCarrier<TKey>, TangoSchemaModelAugmentations<TSchema, TKey> {
|
|
19
25
|
}
|
|
20
|
-
export interface Model<TSchema extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape
|
|
26
|
+
export interface Model<TSchema extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, TKey extends string = string> extends ModelAugmentations<TSchema, TKey> {
|
|
21
27
|
metadata: ModelMetadata;
|
|
22
28
|
schema: TSchema;
|
|
23
29
|
/**
|
|
@@ -25,4 +31,5 @@ export interface Model<TSchema extends z.ZodObject<z.ZodRawShape> = z.ZodObject<
|
|
|
25
31
|
*/
|
|
26
32
|
hooks?: ModelWriteHooks<PersistedModelOutput<TSchema>>;
|
|
27
33
|
}
|
|
34
|
+
export type ModelKeyOf<TModel> = TModel extends Model<z.ZodObject<z.ZodRawShape>, infer TKey> ? TKey : never;
|
|
28
35
|
export {};
|
|
@@ -4,6 +4,12 @@ export interface ModelWriteHookManager<TModel extends Record<string, unknown>> {
|
|
|
4
4
|
delete(id: TModel[keyof TModel]): Promise<void>;
|
|
5
5
|
bulkCreate(inputs: Partial<TModel>[]): Promise<TModel[]>;
|
|
6
6
|
}
|
|
7
|
+
export interface ModelWriteHookOnCommitOptions {
|
|
8
|
+
robust?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface ModelWriteHookTransaction {
|
|
11
|
+
onCommit(callback: () => void, options?: ModelWriteHookOnCommitOptions): void;
|
|
12
|
+
}
|
|
7
13
|
/**
|
|
8
14
|
* Structural model contract passed into write lifecycle hooks.
|
|
9
15
|
*/
|
|
@@ -20,11 +26,13 @@ export interface BeforeCreateHookArgs<TModel extends Record<string, unknown>> {
|
|
|
20
26
|
data: Partial<TModel>;
|
|
21
27
|
model: ModelHookModel<TModel>;
|
|
22
28
|
manager: ModelWriteHookManager<TModel>;
|
|
29
|
+
transaction?: ModelWriteHookTransaction;
|
|
23
30
|
}
|
|
24
31
|
export interface AfterCreateHookArgs<TModel extends Record<string, unknown>> {
|
|
25
32
|
record: TModel;
|
|
26
33
|
model: ModelHookModel<TModel>;
|
|
27
34
|
manager: ModelWriteHookManager<TModel>;
|
|
35
|
+
transaction?: ModelWriteHookTransaction;
|
|
28
36
|
}
|
|
29
37
|
export interface BeforeUpdateHookArgs<TModel extends Record<string, unknown>> {
|
|
30
38
|
id: TModel[keyof TModel];
|
|
@@ -32,6 +40,7 @@ export interface BeforeUpdateHookArgs<TModel extends Record<string, unknown>> {
|
|
|
32
40
|
current: TModel;
|
|
33
41
|
model: ModelHookModel<TModel>;
|
|
34
42
|
manager: ModelWriteHookManager<TModel>;
|
|
43
|
+
transaction?: ModelWriteHookTransaction;
|
|
35
44
|
}
|
|
36
45
|
export interface AfterUpdateHookArgs<TModel extends Record<string, unknown>> {
|
|
37
46
|
id: TModel[keyof TModel];
|
|
@@ -40,28 +49,33 @@ export interface AfterUpdateHookArgs<TModel extends Record<string, unknown>> {
|
|
|
40
49
|
record: TModel;
|
|
41
50
|
model: ModelHookModel<TModel>;
|
|
42
51
|
manager: ModelWriteHookManager<TModel>;
|
|
52
|
+
transaction?: ModelWriteHookTransaction;
|
|
43
53
|
}
|
|
44
54
|
export interface BeforeDeleteHookArgs<TModel extends Record<string, unknown>> {
|
|
45
55
|
id: TModel[keyof TModel];
|
|
46
56
|
current: TModel;
|
|
47
57
|
model: ModelHookModel<TModel>;
|
|
48
58
|
manager: ModelWriteHookManager<TModel>;
|
|
59
|
+
transaction?: ModelWriteHookTransaction;
|
|
49
60
|
}
|
|
50
61
|
export interface AfterDeleteHookArgs<TModel extends Record<string, unknown>> {
|
|
51
62
|
id: TModel[keyof TModel];
|
|
52
63
|
previous: TModel;
|
|
53
64
|
model: ModelHookModel<TModel>;
|
|
54
65
|
manager: ModelWriteHookManager<TModel>;
|
|
66
|
+
transaction?: ModelWriteHookTransaction;
|
|
55
67
|
}
|
|
56
68
|
export interface BeforeBulkCreateHookArgs<TModel extends Record<string, unknown>> {
|
|
57
69
|
rows: Partial<TModel>[];
|
|
58
70
|
model: ModelHookModel<TModel>;
|
|
59
71
|
manager: ModelWriteHookManager<TModel>;
|
|
72
|
+
transaction?: ModelWriteHookTransaction;
|
|
60
73
|
}
|
|
61
74
|
export interface AfterBulkCreateHookArgs<TModel extends Record<string, unknown>> {
|
|
62
75
|
records: TModel[];
|
|
63
76
|
model: ModelHookModel<TModel>;
|
|
64
77
|
manager: ModelWriteHookManager<TModel>;
|
|
78
|
+
transaction?: ModelWriteHookTransaction;
|
|
65
79
|
}
|
|
66
80
|
/**
|
|
67
81
|
* Async-capable model-owned write lifecycle hooks.
|
package/dist/domain/index.d.ts
CHANGED
|
@@ -9,5 +9,5 @@ export type { Field } from './Field';
|
|
|
9
9
|
export type { IndexDef } from './IndexDef';
|
|
10
10
|
export type { RelationDef } from './RelationDef';
|
|
11
11
|
export type { ModelMetadata } from './ModelMetadata';
|
|
12
|
-
export type { Model, ModelAugmentations, PersistedModelOutput } from './Model';
|
|
13
|
-
export type { ModelHookModel, ModelWriteHookManager, ModelWriteHooks, BeforeCreateHookArgs, AfterCreateHookArgs, BeforeUpdateHookArgs, AfterUpdateHookArgs, BeforeDeleteHookArgs, AfterDeleteHookArgs, BeforeBulkCreateHookArgs, AfterBulkCreateHookArgs, } from './ModelWriteHooks';
|
|
12
|
+
export type { Model, ModelAugmentations, ModelKeyOf, PersistedModelOutput } from './Model';
|
|
13
|
+
export type { ModelHookModel, ModelWriteHookOnCommitOptions, ModelWriteHookManager, ModelWriteHookTransaction, ModelWriteHooks, BeforeCreateHookArgs, AfterCreateHookArgs, BeforeUpdateHookArgs, AfterUpdateHookArgs, BeforeDeleteHookArgs, AfterDeleteHookArgs, BeforeBulkCreateHookArgs, AfterBulkCreateHookArgs, } from './ModelWriteHooks';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domain-Cufz6y1q.js","names":[],"sources":["../src/domain/index.ts"],"sourcesContent":["/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\n\nexport type { FieldType } from './FieldType';\nexport type { DeleteReferentialAction } from './DeleteReferentialAction';\nexport type { UpdateReferentialAction } from './UpdateReferentialAction';\nexport type { RelationType } from './RelationType';\nexport type { Field } from './Field';\nexport type { IndexDef } from './IndexDef';\nexport type { RelationDef } from './RelationDef';\nexport type { ModelMetadata } from './ModelMetadata';\nexport type { Model, ModelAugmentations, PersistedModelOutput } from './Model';\nexport type {\n ModelHookModel,\n ModelWriteHookManager,\n ModelWriteHooks,\n BeforeCreateHookArgs,\n AfterCreateHookArgs,\n BeforeUpdateHookArgs,\n AfterUpdateHookArgs,\n BeforeDeleteHookArgs,\n AfterDeleteHookArgs,\n BeforeBulkCreateHookArgs,\n AfterBulkCreateHookArgs,\n} from './ModelWriteHooks';\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"domain-Cufz6y1q.js","names":[],"sources":["../src/domain/index.ts"],"sourcesContent":["/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\n\nexport type { FieldType } from './FieldType';\nexport type { DeleteReferentialAction } from './DeleteReferentialAction';\nexport type { UpdateReferentialAction } from './UpdateReferentialAction';\nexport type { RelationType } from './RelationType';\nexport type { Field } from './Field';\nexport type { IndexDef } from './IndexDef';\nexport type { RelationDef } from './RelationDef';\nexport type { ModelMetadata } from './ModelMetadata';\nexport type { Model, ModelAugmentations, ModelKeyOf, PersistedModelOutput } from './Model';\nexport type {\n ModelHookModel,\n ModelWriteHookOnCommitOptions,\n ModelWriteHookManager,\n ModelWriteHookTransaction,\n ModelWriteHooks,\n BeforeCreateHookArgs,\n AfterCreateHookArgs,\n BeforeUpdateHookArgs,\n AfterUpdateHookArgs,\n BeforeDeleteHookArgs,\n AfterDeleteHookArgs,\n BeforeBulkCreateHookArgs,\n AfterBulkCreateHookArgs,\n} from './ModelWriteHooks';\n"],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export * as domain from './domain/index';
|
|
6
6
|
export * as model from './model/index';
|
|
7
|
-
export type { DeleteReferentialAction, Field, FieldType, IndexDef, ModelHookModel, ModelAugmentations, ModelMetadata, PersistedModelOutput, ModelWriteHookManager, ModelWriteHooks, BeforeCreateHookArgs, AfterCreateHookArgs, BeforeUpdateHookArgs, AfterUpdateHookArgs, BeforeDeleteHookArgs, AfterDeleteHookArgs, BeforeBulkCreateHookArgs, AfterBulkCreateHookArgs, RelationDef, RelationType, UpdateReferentialAction, } from './domain/index';
|
|
8
|
-
export { Model, RelationBuilder, ModelRegistry, registerModelAugmentor, Constraints, Decorators, Indexes, Meta, c, i, m, t, type ModelDefinition, type ForeignKeyDecoratorConfig, type FieldDecoratorBuilder, type ManyToManyDecoratorConfig, type OneToOneDecoratorConfig, } from './model/index';
|
|
7
|
+
export type { DeleteReferentialAction, Field, FieldType, IndexDef, ModelHookModel, ModelKeyOf, ModelAugmentations, ModelMetadata, PersistedModelOutput, ModelWriteHookManager, ModelWriteHooks, BeforeCreateHookArgs, AfterCreateHookArgs, BeforeUpdateHookArgs, AfterUpdateHookArgs, BeforeDeleteHookArgs, AfterDeleteHookArgs, BeforeBulkCreateHookArgs, AfterBulkCreateHookArgs, RelationDef, RelationType, UpdateReferentialAction, } from './domain/index';
|
|
8
|
+
export { Model, RelationBuilder, ModelRegistry, registerModelAugmentor, Constraints, Decorators, Indexes, Meta, c, i, m, t, type ModelDefinition, type ForeignKeyDecoratorConfig, type FieldDecoratorBuilder, type DecoratedFieldKind, type ManyToManyDecoratorConfig, type ModelRef, type ModelRefTarget, type OneToOneDecoratorConfig, type RelationDecoratedSchema, type TypedModelRef, } from './model/index';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Constraints, Decorators, Indexes, Meta, Model, ModelRegistry, RelationBuilder, model_exports, registerModelAugmentor } from "./model-
|
|
1
|
+
import { Constraints, Decorators, Indexes, Meta, Model, ModelRegistry, RelationBuilder, model_exports, registerModelAugmentor } from "./model-YLW1ydkV.js";
|
|
2
2
|
import { domain_exports } from "./domain-Cufz6y1q.js";
|
|
3
3
|
|
|
4
4
|
export { Constraints, Decorators, Indexes, Meta, Model, ModelRegistry, RelationBuilder, Constraints as c, domain_exports as domain, Indexes as i, Meta as m, model_exports as model, registerModelAugmentor, Decorators as t };
|
package/dist/model/Model.d.ts
CHANGED
|
@@ -5,4 +5,7 @@ import type { ModelDefinition } from './ModelDefinition';
|
|
|
5
5
|
* Creates a model definition with metadata and schema validation.
|
|
6
6
|
* Automatically finalizes field types through the owning model registry.
|
|
7
7
|
*/
|
|
8
|
-
export declare function Model<TSchema extends z.ZodObject<z.ZodRawShape>>(definition: ModelDefinition<TSchema>
|
|
8
|
+
export declare function Model<const TNamespace extends string, const TName extends string, TSchema extends z.ZodObject<z.ZodRawShape>>(definition: ModelDefinition<TSchema> & {
|
|
9
|
+
namespace: TNamespace;
|
|
10
|
+
name: TName;
|
|
11
|
+
}): SchemaModel<TSchema, `${TNamespace}/${TName}`>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { z } from 'zod';
|
|
2
2
|
import type { Model } from '../domain/Model';
|
|
3
|
-
export type ModelAugmentor = <TSchema extends z.ZodObject<z.ZodRawShape
|
|
3
|
+
export type ModelAugmentor = <TSchema extends z.ZodObject<z.ZodRawShape>, TKey extends string>(model: Model<TSchema, TKey>) => void;
|
|
4
4
|
/**
|
|
5
5
|
* Register a model augmentor that runs for existing and future models.
|
|
6
6
|
*/
|
|
@@ -8,4 +8,4 @@ export declare function registerModelAugmentor(augmentor: ModelAugmentor): () =>
|
|
|
8
8
|
/**
|
|
9
9
|
* Apply all registered augmentors to a model before it is returned publicly.
|
|
10
10
|
*/
|
|
11
|
-
export declare function applyModelAugmentors<TSchema extends z.ZodObject<z.ZodRawShape
|
|
11
|
+
export declare function applyModelAugmentors<TSchema extends z.ZodObject<z.ZodRawShape>, TKey extends string>(model: Model<TSchema, TKey>): Model<TSchema, TKey>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { ZodTypeAny } from './domain/ZodTypeAny';
|
|
3
|
-
import type
|
|
3
|
+
import { type ModelRef, type ModelRefTarget, type TypedModelRef } from './domain/ModelRef';
|
|
4
4
|
import type { ReferentialOptions } from './domain/TangoFieldMeta';
|
|
5
|
+
import type { Model, ModelKeyOf } from '../../domain';
|
|
5
6
|
import type { ForeignKeyDecoratorConfig, ManyToManyDecoratorConfig, OneToOneDecoratorConfig } from './domain/RelationDecoratorConfig';
|
|
6
7
|
import type { RelationDecoratedSchema } from './domain/RelationDecoratedSchema';
|
|
7
8
|
export interface FieldDecoratorBuilder<TField extends ZodTypeAny> {
|
|
@@ -17,35 +18,41 @@ export interface FieldDecoratorBuilder<TField extends ZodTypeAny> {
|
|
|
17
18
|
errorMessages(map: Record<string, string>): FieldDecoratorBuilder<TField>;
|
|
18
19
|
build(): TField;
|
|
19
20
|
}
|
|
21
|
+
type ConfigName<TConfig> = TConfig extends {
|
|
22
|
+
name: infer TName extends string;
|
|
23
|
+
} ? TName : undefined;
|
|
24
|
+
type ConfigRelatedName<TConfig> = TConfig extends {
|
|
25
|
+
relatedName: infer TRelatedName extends string;
|
|
26
|
+
} ? TRelatedName : undefined;
|
|
20
27
|
type UnaryFieldDecorator = {
|
|
21
28
|
<T extends ZodTypeAny>(schema: T): T;
|
|
22
29
|
<T extends ZodTypeAny>(): (input: T) => T;
|
|
23
30
|
};
|
|
24
31
|
type RelationshipDecorator = {
|
|
25
|
-
<T extends ZodTypeAny
|
|
32
|
+
<TRef extends ModelRef, T extends ZodTypeAny, const TConfig extends ForeignKeyDecoratorConfig<T> & {
|
|
26
33
|
field: T;
|
|
27
|
-
}): RelationDecoratedSchema<T, 'foreignKey'
|
|
28
|
-
(target:
|
|
34
|
+
}>(target: TRef, config: TConfig): RelationDecoratedSchema<T, 'foreignKey', ModelRefTarget<TRef>, ConfigName<TConfig>, ConfigRelatedName<TConfig>>;
|
|
35
|
+
<TRef extends ModelRef, const TConfig extends ForeignKeyDecoratorConfig<z.ZodNumber> | undefined>(target: TRef, config?: TConfig): RelationDecoratedSchema<z.ZodNumber, 'foreignKey', ModelRefTarget<TRef>, ConfigName<TConfig>, ConfigRelatedName<TConfig>>;
|
|
29
36
|
/**
|
|
30
37
|
* @deprecated Use `t.foreignKey(target, { field: schema, ...options })` instead.
|
|
31
38
|
*/
|
|
32
39
|
<T extends ZodTypeAny>(target: ModelRef, schema: T, options?: ReferentialOptions): RelationDecoratedSchema<T, 'foreignKey'>;
|
|
33
40
|
};
|
|
34
41
|
type OneToOneRelationshipDecorator = {
|
|
35
|
-
<T extends ZodTypeAny
|
|
42
|
+
<TRef extends ModelRef, T extends ZodTypeAny, const TConfig extends OneToOneDecoratorConfig<T> & {
|
|
36
43
|
field: T;
|
|
37
|
-
}): RelationDecoratedSchema<T, 'oneToOne'
|
|
38
|
-
(target:
|
|
44
|
+
}>(target: TRef, config: TConfig): RelationDecoratedSchema<T, 'oneToOne', ModelRefTarget<TRef>, ConfigName<TConfig>, ConfigRelatedName<TConfig>>;
|
|
45
|
+
<TRef extends ModelRef, const TConfig extends OneToOneDecoratorConfig<z.ZodNumber> | undefined>(target: TRef, config?: TConfig): RelationDecoratedSchema<z.ZodNumber, 'oneToOne', ModelRefTarget<TRef>, ConfigName<TConfig>, ConfigRelatedName<TConfig>>;
|
|
39
46
|
/**
|
|
40
47
|
* @deprecated Use `t.oneToOne(target, { field: schema, ...options })` instead.
|
|
41
48
|
*/
|
|
42
49
|
<T extends ZodTypeAny>(target: ModelRef, schema: T, options?: ReferentialOptions): RelationDecoratedSchema<T, 'oneToOne'>;
|
|
43
50
|
};
|
|
44
51
|
type ManyToManyDecorator = {
|
|
45
|
-
<T extends ZodTypeAny
|
|
52
|
+
<TRef extends ModelRef, T extends ZodTypeAny, const TConfig extends ManyToManyDecoratorConfig<T> & {
|
|
46
53
|
field: T;
|
|
47
|
-
}): RelationDecoratedSchema<T, 'manyToMany'>;
|
|
48
|
-
(target:
|
|
54
|
+
}>(target: TRef, config: TConfig): RelationDecoratedSchema<T, 'manyToMany', ModelRefTarget<TRef>, ConfigName<TConfig>, undefined>;
|
|
55
|
+
<TRef extends ModelRef, const TConfig extends ManyToManyDecoratorConfig<z.ZodArray<z.ZodNumber>> | undefined>(target: TRef, config?: TConfig): RelationDecoratedSchema<z.ZodArray<z.ZodNumber>, 'manyToMany', ModelRefTarget<TRef>, ConfigName<TConfig>, undefined>;
|
|
49
56
|
/**
|
|
50
57
|
* @deprecated Use `t.manyToMany(target, { field: schema, name })` instead.
|
|
51
58
|
*/
|
|
@@ -53,6 +60,7 @@ type ManyToManyDecorator = {
|
|
|
53
60
|
};
|
|
54
61
|
export interface TangoDecorators {
|
|
55
62
|
field: <T extends ZodTypeAny>(schema: T) => FieldDecoratorBuilder<T>;
|
|
63
|
+
modelRef: <TModel extends Model>(key: ModelKeyOf<TModel>) => TypedModelRef<TModel>;
|
|
56
64
|
primaryKey: UnaryFieldDecorator;
|
|
57
65
|
unique: UnaryFieldDecorator;
|
|
58
66
|
null: UnaryFieldDecorator;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const InternalDecoratedFieldKind: {
|
|
2
2
|
readonly FOREIGN_KEY: "foreignKey";
|
|
3
3
|
readonly ONE_TO_ONE: "oneToOne";
|
|
4
4
|
readonly MANY_TO_MANY: "manyToMany";
|
|
5
5
|
};
|
|
6
|
-
export type DecoratedFieldKind = (typeof
|
|
6
|
+
export type DecoratedFieldKind = (typeof InternalDecoratedFieldKind)[keyof typeof InternalDecoratedFieldKind];
|
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
import type { Model } from '../../../domain';
|
|
2
|
-
|
|
1
|
+
import type { Model, ModelKeyOf } from '../../../domain';
|
|
2
|
+
declare const TANGO_TYPED_MODEL_REF_TARGET: unique symbol;
|
|
3
|
+
export interface TypedModelRef<TModel extends Model = Model> {
|
|
4
|
+
readonly key: ModelKeyOf<TModel>;
|
|
5
|
+
readonly [TANGO_TYPED_MODEL_REF_TARGET]?: TModel;
|
|
6
|
+
}
|
|
7
|
+
export type ModelRef<TModel extends Model = Model> = string | TModel | (() => TModel) | TypedModelRef<TModel>;
|
|
8
|
+
export type ModelRefTarget<TRef> = TRef extends TypedModelRef<infer TModel> ? TModel : TRef extends () => infer TModel ? TModel extends Model ? TModel : never : TRef extends Model ? TRef : never;
|
|
9
|
+
export declare function createTypedModelRef<TModel extends Model>(key: ModelKeyOf<TModel>): TypedModelRef<TModel>;
|
|
10
|
+
export declare function isTypedModelRef(value: unknown): value is TypedModelRef;
|
|
11
|
+
export {};
|
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import type { DecoratedFieldKind } from './DecoratedFieldKind';
|
|
2
|
+
import type { Model } from '../../../domain';
|
|
2
3
|
import type { ZodTypeAny } from './ZodTypeAny';
|
|
3
4
|
declare const TANGO_DECORATED_FIELD_KIND: unique symbol;
|
|
4
|
-
export type RelationDecoratedSchema<TSchema extends ZodTypeAny, TKind extends DecoratedFieldKind> = TSchema & {
|
|
5
|
+
export type RelationDecoratedSchema<TSchema extends ZodTypeAny, TKind extends DecoratedFieldKind, TTargetModel extends Model | never = never, TName extends string | undefined = undefined, TRelatedName extends string | undefined = undefined> = TSchema & {
|
|
5
6
|
readonly [TANGO_DECORATED_FIELD_KIND]: {
|
|
6
7
|
readonly relationKind: TKind;
|
|
8
|
+
readonly targetModel: TTargetModel;
|
|
9
|
+
readonly name: TName;
|
|
10
|
+
readonly relatedName: TRelatedName;
|
|
11
|
+
};
|
|
12
|
+
readonly __tangoRelationDecoratedSchema: {
|
|
13
|
+
readonly relationKind: TKind;
|
|
14
|
+
readonly targetModel: TTargetModel;
|
|
15
|
+
readonly name: TName;
|
|
16
|
+
readonly relatedName: TRelatedName;
|
|
7
17
|
};
|
|
8
18
|
};
|
|
19
|
+
export type RelationDecoratedSchemaKind<TField> = TField extends {
|
|
20
|
+
readonly __tangoRelationDecoratedSchema: {
|
|
21
|
+
readonly relationKind: infer TKind extends DecoratedFieldKind;
|
|
22
|
+
};
|
|
23
|
+
} ? TKind : never;
|
|
9
24
|
export {};
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export { Decorators, Decorators as t } from './Decorators';
|
|
5
5
|
export type { FieldDecoratorBuilder, TangoDecorators } from './Decorators';
|
|
6
|
-
export type { ModelRef } from './domain/ModelRef';
|
|
6
|
+
export type { ModelRef, ModelRefTarget, TypedModelRef } from './domain/ModelRef';
|
|
7
|
+
export { createTypedModelRef, isTypedModelRef } from './domain/ModelRef';
|
|
8
|
+
export type { RelationDecoratedSchema } from './domain/RelationDecoratedSchema';
|
|
9
|
+
export { InternalDecoratedFieldKind } from './domain/DecoratedFieldKind';
|
|
10
|
+
export type { DecoratedFieldKind } from './domain/DecoratedFieldKind';
|
|
7
11
|
export type { ForeignKeyDecoratorConfig, OneToOneDecoratorConfig, ManyToManyDecoratorConfig, } from './domain/RelationDecoratorConfig';
|
|
8
12
|
export type { ReferentialOptions, TangoFieldMeta } from './domain/TangoFieldMeta';
|
|
9
13
|
export type { ZodTypeAny } from './domain/ZodTypeAny';
|
package/dist/model/index.d.ts
CHANGED
|
@@ -15,7 +15,8 @@ export { RelationBuilder } from './relations/index';
|
|
|
15
15
|
export { Model } from './Model';
|
|
16
16
|
export { registerModelAugmentor } from './ModelAugmentorRegistry';
|
|
17
17
|
export { Decorators, t } from './decorators/index';
|
|
18
|
-
export type { TangoDecorators, FieldDecoratorBuilder, ForeignKeyDecoratorConfig, OneToOneDecoratorConfig, ManyToManyDecoratorConfig, } from './decorators/index';
|
|
18
|
+
export type { TangoDecorators, FieldDecoratorBuilder, DecoratedFieldKind, ModelRef, ModelRefTarget, RelationDecoratedSchema, TypedModelRef, ForeignKeyDecoratorConfig, OneToOneDecoratorConfig, ManyToManyDecoratorConfig, } from './decorators/index';
|
|
19
|
+
export { createTypedModelRef, InternalDecoratedFieldKind, isTypedModelRef } from './decorators/index';
|
|
19
20
|
export { Meta, m } from './meta/index';
|
|
20
21
|
export type { ModelConstraint, ModelMetaFragment } from './meta/index';
|
|
21
22
|
export { Constraints, Indexes, c, i } from './constraints/index';
|
package/dist/model/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Constraints, Decorators, Indexes, Meta, Model, ModelRegistry, RelationBuilder, constraints_exports, decorators_exports, meta_exports, registerModelAugmentor, registry_exports, relations_exports } from "../model-
|
|
1
|
+
import { Constraints, Decorators, Indexes, InternalDecoratedFieldKind, Meta, Model, ModelRegistry, RelationBuilder, constraints_exports, createTypedModelRef, decorators_exports, isTypedModelRef, meta_exports, registerModelAugmentor, registry_exports, relations_exports } from "../model-YLW1ydkV.js";
|
|
2
2
|
|
|
3
|
-
export { Constraints, Decorators, Indexes, Meta, Model, ModelRegistry, RelationBuilder, Constraints as c, constraints_exports as constraints, decorators_exports as decorators, Indexes as i, Meta as m, meta_exports as meta, registerModelAugmentor, registry_exports as registry, relations_exports as relations, Decorators as t };
|
|
3
|
+
export { Constraints, Decorators, Indexes, InternalDecoratedFieldKind, Meta, Model, ModelRegistry, RelationBuilder, Constraints as c, constraints_exports as constraints, createTypedModelRef, decorators_exports as decorators, Indexes as i, isTypedModelRef, Meta as m, meta_exports as meta, registerModelAugmentor, registry_exports as registry, relations_exports as relations, Decorators as t };
|
|
@@ -5,13 +5,13 @@ import type { ModelRegistry } from '../registry/ModelRegistry';
|
|
|
5
5
|
import type { NormalizedRelationStorageDescriptor } from '../relations/NormalizedRelationStorageDescriptor';
|
|
6
6
|
type AnySchemaModel = Model<z.ZodObject<z.ZodRawShape>>;
|
|
7
7
|
type AnyInternalSchemaModel = InternalSchemaModel<z.ZodObject<z.ZodRawShape>>;
|
|
8
|
-
export declare class InternalSchemaModel<TSchema extends z.ZodObject<z.ZodRawShape
|
|
8
|
+
export declare class InternalSchemaModel<TSchema extends z.ZodObject<z.ZodRawShape>, TKey extends string = string> implements Model<TSchema, TKey> {
|
|
9
9
|
static readonly BRAND: "tango.schema.internal_schema_model";
|
|
10
10
|
readonly __tangoBrand: typeof InternalSchemaModel.BRAND;
|
|
11
11
|
readonly metadata: ModelMetadata;
|
|
12
12
|
readonly schema: TSchema;
|
|
13
13
|
readonly hooks?: ModelWriteHooks<PersistedModelOutput<TSchema>>;
|
|
14
|
-
readonly objects: ModelAugmentations<TSchema> extends {
|
|
14
|
+
readonly objects: ModelAugmentations<TSchema, TKey> extends {
|
|
15
15
|
readonly objects: infer TObject;
|
|
16
16
|
} ? TObject : never;
|
|
17
17
|
private readonly registry;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Field, Model } from '../../domain/index';
|
|
2
|
-
import type
|
|
2
|
+
import { type ModelRef } from '../decorators/domain/ModelRef';
|
|
3
3
|
import type { FinalizedStorageArtifacts } from '../fields/FinalizedStorageArtifacts';
|
|
4
4
|
import type { ResolvedRelationGraph } from '../relations/ResolvedRelationGraph';
|
|
5
5
|
/**
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { DeleteReferentialAction, UpdateReferentialAction } from '../../domain/index';
|
|
2
2
|
import type { ModelRef } from '../decorators/domain/ModelRef';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const InternalNormalizedRelationOrigin: {
|
|
4
4
|
readonly FOREIGN_KEY: "foreignKey";
|
|
5
5
|
readonly ONE_TO_ONE: "oneToOne";
|
|
6
6
|
readonly MANY_TO_MANY: "manyToMany";
|
|
7
7
|
};
|
|
8
|
-
export type NormalizedRelationOrigin = (typeof
|
|
8
|
+
export type NormalizedRelationOrigin = (typeof InternalNormalizedRelationOrigin)[keyof typeof InternalNormalizedRelationOrigin];
|
|
9
9
|
/**
|
|
10
10
|
* Registry-independent relation descriptor produced immediately after model
|
|
11
11
|
* construction.
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const InternalRelationPublicKind: {
|
|
2
2
|
readonly BELONGS_TO: "belongsTo";
|
|
3
3
|
readonly HAS_ONE: "hasOne";
|
|
4
4
|
readonly HAS_MANY: "hasMany";
|
|
5
5
|
readonly MANY_TO_MANY: "manyToMany";
|
|
6
6
|
};
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const InternalRelationStorageStrategy: {
|
|
8
8
|
readonly REFERENCE: "reference";
|
|
9
9
|
readonly REVERSE_REFERENCE: "reverse_reference";
|
|
10
10
|
readonly MANY_TO_MANY: "many_to_many";
|
|
11
11
|
};
|
|
12
|
-
export declare const
|
|
12
|
+
export declare const InternalRelationCardinality: {
|
|
13
13
|
readonly SINGLE: "single";
|
|
14
14
|
readonly MANY: "many";
|
|
15
15
|
};
|
|
16
|
-
export declare const
|
|
16
|
+
export declare const InternalRelationProvenance: {
|
|
17
17
|
readonly FIELD_DECORATOR: "field-decorator";
|
|
18
18
|
readonly RELATIONS_API: "relations-api";
|
|
19
19
|
readonly SYNTHESIZED_REVERSE: "synthesized-reverse";
|
|
20
20
|
};
|
|
21
|
-
export type RelationPublicKind = (typeof
|
|
22
|
-
export type RelationStorageStrategy = (typeof
|
|
23
|
-
export type RelationCardinality = (typeof
|
|
24
|
-
export type RelationProvenance = (typeof
|
|
21
|
+
export type RelationPublicKind = (typeof InternalRelationPublicKind)[keyof typeof InternalRelationPublicKind];
|
|
22
|
+
export type RelationStorageStrategy = (typeof InternalRelationStorageStrategy)[keyof typeof InternalRelationStorageStrategy];
|
|
23
|
+
export type RelationCardinality = (typeof InternalRelationCardinality)[keyof typeof InternalRelationCardinality];
|
|
24
|
+
export type RelationProvenance = (typeof InternalRelationProvenance)[keyof typeof InternalRelationProvenance];
|
|
25
25
|
/**
|
|
26
26
|
* Author-time relation intent after target resolution but before full graph
|
|
27
27
|
* pairing and naming.
|
|
@@ -25,9 +25,18 @@ function setFieldMetadata(schema, meta) {
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/model/decorators/domain/ModelRef.ts
|
|
30
|
+
function createTypedModelRef(key) {
|
|
31
|
+
return Object.freeze({ key });
|
|
32
|
+
}
|
|
33
|
+
function isTypedModelRef(value) {
|
|
34
|
+
return typeof value === "object" && value !== null && typeof value.key === "string";
|
|
35
|
+
}
|
|
36
|
+
|
|
28
37
|
//#endregion
|
|
29
38
|
//#region src/model/decorators/domain/DecoratedFieldKind.ts
|
|
30
|
-
const
|
|
39
|
+
const InternalDecoratedFieldKind = {
|
|
31
40
|
FOREIGN_KEY: "foreignKey",
|
|
32
41
|
ONE_TO_ONE: "oneToOne",
|
|
33
42
|
MANY_TO_MANY: "manyToMany"
|
|
@@ -150,11 +159,14 @@ function toReferentialOptions(config) {
|
|
|
150
159
|
onUpdate: config.onUpdate
|
|
151
160
|
};
|
|
152
161
|
}
|
|
162
|
+
function modelRef(key) {
|
|
163
|
+
return createTypedModelRef(key);
|
|
164
|
+
}
|
|
153
165
|
function foreignKey(target, schemaOrOptions, maybeOptions) {
|
|
154
166
|
if (isZodType(schemaOrOptions)) {
|
|
155
|
-
warnDeprecatedSchemaOverload(
|
|
167
|
+
warnDeprecatedSchemaOverload(InternalDecoratedFieldKind.FOREIGN_KEY, "t.foreignKey(target, { field: schema, ...options })");
|
|
156
168
|
return applyRelationMetadata(schemaOrOptions, {
|
|
157
|
-
relationKind:
|
|
169
|
+
relationKind: InternalDecoratedFieldKind.FOREIGN_KEY,
|
|
158
170
|
references: {
|
|
159
171
|
target,
|
|
160
172
|
options: maybeOptions
|
|
@@ -164,7 +176,7 @@ function foreignKey(target, schemaOrOptions, maybeOptions) {
|
|
|
164
176
|
const config = schemaOrOptions;
|
|
165
177
|
const schema = config?.field ?? z.number().int();
|
|
166
178
|
return applyRelationMetadata(schema, {
|
|
167
|
-
relationKind:
|
|
179
|
+
relationKind: InternalDecoratedFieldKind.FOREIGN_KEY,
|
|
168
180
|
references: {
|
|
169
181
|
target,
|
|
170
182
|
options: toReferentialOptions(config)
|
|
@@ -174,9 +186,9 @@ function foreignKey(target, schemaOrOptions, maybeOptions) {
|
|
|
174
186
|
}
|
|
175
187
|
function oneToOne(target, schemaOrOptions, maybeOptions) {
|
|
176
188
|
if (isZodType(schemaOrOptions)) {
|
|
177
|
-
warnDeprecatedSchemaOverload(
|
|
189
|
+
warnDeprecatedSchemaOverload(InternalDecoratedFieldKind.ONE_TO_ONE, "t.oneToOne(target, { field: schema, ...options })");
|
|
178
190
|
return applyRelationMetadata(schemaOrOptions, {
|
|
179
|
-
relationKind:
|
|
191
|
+
relationKind: InternalDecoratedFieldKind.ONE_TO_ONE,
|
|
180
192
|
unique: true,
|
|
181
193
|
references: {
|
|
182
194
|
target,
|
|
@@ -187,7 +199,7 @@ function oneToOne(target, schemaOrOptions, maybeOptions) {
|
|
|
187
199
|
const config = schemaOrOptions;
|
|
188
200
|
const schema = config?.field ?? z.number().int();
|
|
189
201
|
return applyRelationMetadata(schema, {
|
|
190
|
-
relationKind:
|
|
202
|
+
relationKind: InternalDecoratedFieldKind.ONE_TO_ONE,
|
|
191
203
|
unique: true,
|
|
192
204
|
references: {
|
|
193
205
|
target,
|
|
@@ -198,9 +210,9 @@ function oneToOne(target, schemaOrOptions, maybeOptions) {
|
|
|
198
210
|
}
|
|
199
211
|
function manyToMany(target, schemaOrConfig) {
|
|
200
212
|
if (isZodType(schemaOrConfig)) {
|
|
201
|
-
warnDeprecatedSchemaOverload(
|
|
213
|
+
warnDeprecatedSchemaOverload(InternalDecoratedFieldKind.MANY_TO_MANY, "t.manyToMany(target, { field: schema, name })");
|
|
202
214
|
return applyRelationMetadata(schemaOrConfig, {
|
|
203
|
-
relationKind:
|
|
215
|
+
relationKind: InternalDecoratedFieldKind.MANY_TO_MANY,
|
|
204
216
|
references: { target }
|
|
205
217
|
});
|
|
206
218
|
}
|
|
@@ -208,12 +220,13 @@ function manyToMany(target, schemaOrConfig) {
|
|
|
208
220
|
const config = schemaOrConfig;
|
|
209
221
|
const schema = config?.field ?? z.array(z.number().int());
|
|
210
222
|
return applyRelationMetadata(schema, {
|
|
211
|
-
relationKind:
|
|
223
|
+
relationKind: InternalDecoratedFieldKind.MANY_TO_MANY,
|
|
212
224
|
references: { target }
|
|
213
225
|
}, config);
|
|
214
226
|
}
|
|
215
227
|
const Decorators = {
|
|
216
228
|
field,
|
|
229
|
+
modelRef,
|
|
217
230
|
primaryKey,
|
|
218
231
|
unique,
|
|
219
232
|
null: nullValue,
|
|
@@ -236,6 +249,9 @@ const Decorators = {
|
|
|
236
249
|
var decorators_exports = {};
|
|
237
250
|
__export(decorators_exports, {
|
|
238
251
|
Decorators: () => Decorators,
|
|
252
|
+
InternalDecoratedFieldKind: () => InternalDecoratedFieldKind,
|
|
253
|
+
createTypedModelRef: () => createTypedModelRef,
|
|
254
|
+
isTypedModelRef: () => isTypedModelRef,
|
|
239
255
|
t: () => Decorators
|
|
240
256
|
});
|
|
241
257
|
|
|
@@ -462,7 +478,7 @@ else return null;
|
|
|
462
478
|
if (meta.default !== undefined) field$1.default = meta.default;
|
|
463
479
|
if (meta.primaryKey) field$1.primaryKey = true;
|
|
464
480
|
if (meta.unique) field$1.unique = true;
|
|
465
|
-
if (meta.relationKind ===
|
|
481
|
+
if (meta.relationKind === InternalDecoratedFieldKind.MANY_TO_MANY) return null;
|
|
466
482
|
if (meta.references) {
|
|
467
483
|
const targetMetadata = resolveReferenceTarget ? resolveReferenceTarget(meta.references.target) : resolveReferenceTargetFromRegistry(meta.references.target, registry, meta.references.options?.column);
|
|
468
484
|
field$1.references = {
|
|
@@ -573,7 +589,7 @@ var RelationDescriptorNormalizer = class RelationDescriptorNormalizer {
|
|
|
573
589
|
referencedTargetColumn: meta.references.options?.column,
|
|
574
590
|
onDelete: meta.references.options?.onDelete,
|
|
575
591
|
onUpdate: meta.references.options?.onUpdate,
|
|
576
|
-
unique: meta.unique || meta.relationKind ===
|
|
592
|
+
unique: meta.unique || meta.relationKind === InternalDecoratedFieldKind.ONE_TO_ONE,
|
|
577
593
|
explicitForwardName: meta.forwardName,
|
|
578
594
|
explicitReverseName: meta.reverseName,
|
|
579
595
|
namingHint: this.deriveNamingHint(candidate.sourceSchemaFieldKey),
|
|
@@ -681,22 +697,22 @@ var InternalSchemaModel = class InternalSchemaModel {
|
|
|
681
697
|
|
|
682
698
|
//#endregion
|
|
683
699
|
//#region src/model/relations/RelationSpec.ts
|
|
684
|
-
const
|
|
700
|
+
const InternalRelationPublicKind = {
|
|
685
701
|
BELONGS_TO: "belongsTo",
|
|
686
702
|
HAS_ONE: "hasOne",
|
|
687
703
|
HAS_MANY: "hasMany",
|
|
688
704
|
MANY_TO_MANY: "manyToMany"
|
|
689
705
|
};
|
|
690
|
-
const
|
|
706
|
+
const InternalRelationStorageStrategy = {
|
|
691
707
|
REFERENCE: "reference",
|
|
692
708
|
REVERSE_REFERENCE: "reverse_reference",
|
|
693
709
|
MANY_TO_MANY: "many_to_many"
|
|
694
710
|
};
|
|
695
|
-
const
|
|
711
|
+
const InternalRelationCardinality = {
|
|
696
712
|
SINGLE: "single",
|
|
697
713
|
MANY: "many"
|
|
698
714
|
};
|
|
699
|
-
const
|
|
715
|
+
const InternalRelationProvenance = {
|
|
700
716
|
FIELD_DECORATOR: "field-decorator",
|
|
701
717
|
RELATIONS_API: "relations-api",
|
|
702
718
|
SYNTHESIZED_REVERSE: "synthesized-reverse"
|
|
@@ -749,11 +765,11 @@ var ResolvedRelationGraphBuilder = class ResolvedRelationGraphBuilder {
|
|
|
749
765
|
sourceModelKey: model.metadata.key,
|
|
750
766
|
targetModelKey: targetModel.metadata.key,
|
|
751
767
|
name: relationName,
|
|
752
|
-
kind:
|
|
753
|
-
storageStrategy:
|
|
754
|
-
cardinality:
|
|
768
|
+
kind: InternalRelationPublicKind.MANY_TO_MANY,
|
|
769
|
+
storageStrategy: InternalRelationStorageStrategy.MANY_TO_MANY,
|
|
770
|
+
cardinality: InternalRelationCardinality.MANY,
|
|
755
771
|
capabilities: MANY_TO_MANY_CAPABILITIES,
|
|
756
|
-
provenance:
|
|
772
|
+
provenance: InternalRelationProvenance.FIELD_DECORATOR,
|
|
757
773
|
alias: `${toSnakeCase(model.metadata.name)}_${relationName}`
|
|
758
774
|
});
|
|
759
775
|
continue;
|
|
@@ -772,19 +788,19 @@ var ResolvedRelationGraphBuilder = class ResolvedRelationGraphBuilder {
|
|
|
772
788
|
targetModelKey: targetModel.metadata.key,
|
|
773
789
|
name: forwardName,
|
|
774
790
|
inverseEdgeId: `${descriptor.edgeId}:inverse`,
|
|
775
|
-
kind:
|
|
776
|
-
storageStrategy:
|
|
777
|
-
cardinality:
|
|
791
|
+
kind: InternalRelationPublicKind.BELONGS_TO,
|
|
792
|
+
storageStrategy: InternalRelationStorageStrategy.REFERENCE,
|
|
793
|
+
cardinality: InternalRelationCardinality.SINGLE,
|
|
778
794
|
localFieldName: descriptor.dbColumnName,
|
|
779
795
|
targetFieldName: descriptor.referencedTargetColumn ?? targetPrimaryKey,
|
|
780
796
|
capabilities: REFERENCE_CAPABILITIES,
|
|
781
|
-
provenance:
|
|
797
|
+
provenance: InternalRelationProvenance.FIELD_DECORATOR,
|
|
782
798
|
alias: `${toSnakeCase(targetModel.metadata.name)}_${forwardName}`
|
|
783
799
|
});
|
|
784
800
|
const reverseOverride = this.findReverseOverride(sourceModel, targetModel, descriptor);
|
|
785
801
|
if (reverseOverride) this.markOverrideMatched(targetModel.metadata.key, reverseOverride[0]);
|
|
786
|
-
const reverseKind = descriptor.unique ?
|
|
787
|
-
const reverseCardinality = descriptor.unique ?
|
|
802
|
+
const reverseKind = descriptor.unique ? InternalRelationPublicKind.HAS_ONE : InternalRelationPublicKind.HAS_MANY;
|
|
803
|
+
const reverseCardinality = descriptor.unique ? InternalRelationCardinality.SINGLE : InternalRelationCardinality.MANY;
|
|
788
804
|
const reverseName = reverseOverride?.[0] ?? descriptor.explicitReverseName ?? this.deriveReverseName(sourceModel, reverseCardinality);
|
|
789
805
|
this.addResolvedRelation({
|
|
790
806
|
edgeId: `${descriptor.edgeId}:inverse`,
|
|
@@ -793,24 +809,24 @@ var ResolvedRelationGraphBuilder = class ResolvedRelationGraphBuilder {
|
|
|
793
809
|
name: reverseName,
|
|
794
810
|
inverseEdgeId: descriptor.edgeId,
|
|
795
811
|
kind: reverseKind,
|
|
796
|
-
storageStrategy:
|
|
812
|
+
storageStrategy: InternalRelationStorageStrategy.REVERSE_REFERENCE,
|
|
797
813
|
cardinality: reverseCardinality,
|
|
798
814
|
localFieldName: descriptor.dbColumnName,
|
|
799
815
|
targetFieldName: descriptor.referencedTargetColumn ?? targetPrimaryKey,
|
|
800
816
|
capabilities: REFERENCE_CAPABILITIES,
|
|
801
|
-
provenance: reverseOverride ?
|
|
817
|
+
provenance: reverseOverride ? InternalRelationProvenance.RELATIONS_API : InternalRelationProvenance.SYNTHESIZED_REVERSE,
|
|
802
818
|
alias: `${toSnakeCase(sourceModel.metadata.name)}_${reverseName}`
|
|
803
819
|
});
|
|
804
820
|
}
|
|
805
821
|
findForwardOverride(sourceModel, targetModel, descriptor, explicitRelations) {
|
|
806
822
|
return Object.entries(explicitRelations).find(([, relation]) => {
|
|
807
823
|
const relationTargetKey = this.resolveRelationTargetKey(sourceModel, relation.target);
|
|
808
|
-
return relation.type ===
|
|
824
|
+
return relation.type === InternalRelationPublicKind.BELONGS_TO && relationTargetKey === targetModel.metadata.key && relation.foreignKey === descriptor.sourceSchemaFieldKey;
|
|
809
825
|
});
|
|
810
826
|
}
|
|
811
827
|
findReverseOverride(sourceModel, targetModel, descriptor) {
|
|
812
828
|
const reverseModelRelations = InternalSchemaModel.getExplicitRelations(targetModel) ?? {};
|
|
813
|
-
const reverseKind = descriptor.unique ?
|
|
829
|
+
const reverseKind = descriptor.unique ? InternalRelationPublicKind.HAS_ONE : InternalRelationPublicKind.HAS_MANY;
|
|
814
830
|
return Object.entries(reverseModelRelations).find(([, relation]) => {
|
|
815
831
|
const relationTargetKey = this.resolveRelationTargetKey(targetModel, relation.target);
|
|
816
832
|
return relationTargetKey === sourceModel.metadata.key && relation.type === reverseKind && relation.foreignKey === descriptor.sourceSchemaFieldKey;
|
|
@@ -848,7 +864,7 @@ var ResolvedRelationGraphBuilder = class ResolvedRelationGraphBuilder {
|
|
|
848
864
|
deriveReverseName(sourceModel, cardinality) {
|
|
849
865
|
if (sourceModel.metadata.defaultRelatedName) return sourceModel.metadata.defaultRelatedName;
|
|
850
866
|
const snake = toSnakeCase(sourceModel.metadata.name);
|
|
851
|
-
return cardinality ===
|
|
867
|
+
return cardinality === InternalRelationCardinality.MANY ? pluralize(snake) : snake;
|
|
852
868
|
}
|
|
853
869
|
};
|
|
854
870
|
|
|
@@ -956,9 +972,10 @@ var ModelRegistry = class ModelRegistry {
|
|
|
956
972
|
* Resolve a string, callback, or direct model reference into a model object.
|
|
957
973
|
*/
|
|
958
974
|
resolveRef(ref) {
|
|
959
|
-
if (typeof ref === "string") {
|
|
960
|
-
const
|
|
961
|
-
|
|
975
|
+
if (typeof ref === "string" || isTypedModelRef(ref)) {
|
|
976
|
+
const key = typeof ref === "string" ? ref : ref.key;
|
|
977
|
+
const model$1 = this.getByKey(key);
|
|
978
|
+
if (!model$1) throw new Error(`Unable to resolve model reference '${key}'. Ensure it is registered in ModelRegistry.`);
|
|
962
979
|
return model$1;
|
|
963
980
|
}
|
|
964
981
|
const model = typeof ref === "function" ? ref() : ref;
|
|
@@ -1103,14 +1120,17 @@ __export(model_exports, {
|
|
|
1103
1120
|
Constraints: () => Constraints,
|
|
1104
1121
|
Decorators: () => Decorators,
|
|
1105
1122
|
Indexes: () => Indexes,
|
|
1123
|
+
InternalDecoratedFieldKind: () => InternalDecoratedFieldKind,
|
|
1106
1124
|
Meta: () => Meta,
|
|
1107
1125
|
Model: () => Model,
|
|
1108
1126
|
ModelRegistry: () => ModelRegistry,
|
|
1109
1127
|
RelationBuilder: () => RelationBuilder,
|
|
1110
1128
|
c: () => Constraints,
|
|
1111
1129
|
constraints: () => constraints_exports,
|
|
1130
|
+
createTypedModelRef: () => createTypedModelRef,
|
|
1112
1131
|
decorators: () => decorators_exports,
|
|
1113
1132
|
i: () => Indexes,
|
|
1133
|
+
isTypedModelRef: () => isTypedModelRef,
|
|
1114
1134
|
m: () => Meta,
|
|
1115
1135
|
meta: () => meta_exports,
|
|
1116
1136
|
registerModelAugmentor: () => registerModelAugmentor,
|
|
@@ -1120,5 +1140,5 @@ __export(model_exports, {
|
|
|
1120
1140
|
});
|
|
1121
1141
|
|
|
1122
1142
|
//#endregion
|
|
1123
|
-
export { Constraints, Decorators, Indexes, Meta, Model, ModelRegistry, RelationBuilder, constraints_exports, decorators_exports, meta_exports, model_exports, registerModelAugmentor, registry_exports, relations_exports };
|
|
1124
|
-
//# sourceMappingURL=model-
|
|
1143
|
+
export { Constraints, Decorators, Indexes, InternalDecoratedFieldKind, Meta, Model, ModelRegistry, RelationBuilder, constraints_exports, createTypedModelRef, decorators_exports, isTypedModelRef, meta_exports, model_exports, registerModelAugmentor, registry_exports, relations_exports };
|
|
1144
|
+
//# sourceMappingURL=model-YLW1ydkV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-YLW1ydkV.js","names":["schema: ZodTypeAny","meta: TangoFieldMeta","key: ModelKeyOf<TModel>","value: unknown","value: unknown","schema: T","meta: TangoFieldMeta","kind: DecoratedFieldKind","replacement: string","schemaOrUndefined: T | undefined","schema?: T","value: string | { now: true } | null","value: string","name: string","values: readonly unknown[]","text: string","map: Record<string, string>","schema: TField","config?: { name?: string; relatedName?: string }","config?: ReferentialOptions","key: ModelKeyOf<TModel>","target: ModelRef","schemaOrOptions?: T | ForeignKeyDecoratorConfig<T>","maybeOptions?: ReferentialOptions","schemaOrOptions?: T | OneToOneDecoratorConfig<T>","schemaOrConfig?: T | ManyToManyDecoratorConfig<T>","Decorators: TangoDecorators","value: boolean","value: string","fields: string[]","options?: { name?: string; where?: string }","condition: string","options?: { name?: string }","definition: { using?: string; elements: string[]; where?: string; name?: string }","on: string[]","options?: Omit<IndexDef, 'on'>","value: unknown","value: unknown","name: string","value: unknown","value: unknown","value: unknown","value: unknown","value: unknown","value: unknown","value: unknown","value: unknown","value: unknown","name: string","zodType: z.ZodType","meta: TangoFieldMeta | undefined","registry: ModelRegistry","resolveReferenceTarget?: (target: ModelRef) => { table: string; pk: string }","type: FieldType","defaultValue: Field['default']","unwrapped: z.ZodType","field: Field","target: ModelRef","explicitColumn?: string","schema: z.ZodObject<z.ZodRawShape>","options?: InferFieldsOptions","fields: Field[]","target: string","foreignKey: string","localKey?: string","sourceModelKey: string","schema: z.ZodObject<z.ZodRawShape>","descriptors: NormalizedRelationStorageDescriptor[]","candidate: RelationCandidate","sourceSchemaFieldKey: string","origin: NormalizedRelationOrigin","fieldKey: string","value: string","name: string","registry: ModelRegistry","metadata: ModelMetadata","schema: TSchema","hooks: ModelWriteHooks<PersistedModelOutput<TSchema>> | undefined","normalizedRelations: readonly NormalizedRelationStorageDescriptor[]","explicitFields: readonly Field[] | undefined","explicitRelations: Readonly<Record<string, RelationDef>> | undefined","definition: ModelDefinition<TSchema>","value: unknown","model: AnySchemaModel","options: GraphBuilderOptions","model: Model","sourceModel: Model","descriptor: NormalizedRelationStorageDescriptor","targetModel: Model","explicitRelations: Readonly<Record<string, RelationDef>>","descriptor: ResolvedRelationDescriptor","modelKey: string","relationName: string","target: string","cardinality: RelationCardinality","registry: ModelRegistry","work: () => Promise<T> | T","model: Model","models: readonly Model[]","namespace: string","name: string","key: string","ref: ModelRef","finalized: FinalizedStorageArtifacts","model: Model | string","fields: readonly Field[]","inferredFields: readonly Field[]","explicitFields?: readonly Field[]","augmentor: ModelAugmentor","model: Model<TSchema, TKey>","definition: ModelDefinition<TSchema> & { namespace: TNamespace; name: TName }"],"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/RelationSpec.ts","../src/model/relations/ResolvedRelationGraphBuilder.ts","../src/model/registry/ModelRegistry.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/relation-target-typing-without-codegen\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 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 },\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 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","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>>;\n\nexport class InternalSchemaModel<TSchema extends z.ZodObject<z.ZodRawShape>, TKey extends string = string>\n implements Model<TSchema, TKey>\n{\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 readonly registry: ModelRegistry;\n private readonly normalizedRelations: readonly NormalizedRelationStorageDescriptor[];\n private readonly explicitFields?: readonly Field[];\n private readonly explicitRelations?: Readonly<Record<string, RelationDef>>;\n\n private constructor(\n registry: ModelRegistry,\n metadata: ModelMetadata,\n schema: TSchema,\n hooks: ModelWriteHooks<PersistedModelOutput<TSchema>> | undefined,\n normalizedRelations: readonly NormalizedRelationStorageDescriptor[],\n explicitFields: readonly Field[] | undefined,\n explicitRelations: Readonly<Record<string, RelationDef>> | undefined\n ) {\n this.registry = registry;\n this.metadata = metadata;\n this.schema = schema;\n this.hooks = hooks;\n this.normalizedRelations = Object.freeze([...normalizedRelations]);\n this.explicitFields = explicitFields ? Object.freeze([...explicitFields]) : undefined;\n this.explicitRelations = explicitRelations;\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 return new InternalSchemaModel(\n registry,\n metadata,\n definition.schema,\n definition.hooks,\n normalizedRelations,\n definition.fields,\n relations\n );\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 return InternalSchemaModel.require(model).registry;\n }\n\n static getNormalizedRelations(model: AnySchemaModel): readonly NormalizedRelationStorageDescriptor[] {\n return InternalSchemaModel.require(model).normalizedRelations;\n }\n\n static getExplicitFields(model: AnySchemaModel): readonly Field[] | undefined {\n return InternalSchemaModel.require(model).explicitFields;\n }\n\n static getExplicitRelations(model: AnySchemaModel): Readonly<Record<string, RelationDef>> | undefined {\n return InternalSchemaModel.require(model).explicitRelations;\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","// 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 type { Model, RelationDef } from '../../domain/index';\nimport type { FinalizedStorageArtifacts } from '../fields/FinalizedStorageArtifacts';\nimport { InternalSchemaModel } from '../internal/InternalSchemaModel';\nimport type { NormalizedRelationStorageDescriptor } from './NormalizedRelationStorageDescriptor';\nimport type { ResolvedRelationDescriptor, ResolvedRelationGraph } from './ResolvedRelationGraph';\nimport {\n type RelationCardinality,\n InternalRelationCardinality,\n InternalRelationPublicKind,\n InternalRelationProvenance,\n InternalRelationStorageStrategy,\n} from './RelationSpec';\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: false,\n hydratable: false,\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 * 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 === 'manyToMany') {\n const relationName = descriptor.explicitForwardName ?? descriptor.namingHint;\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 });\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 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 { AsyncLocalStorage } from 'node:async_hooks';\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';\n\nconst DEFAULT_IDENTIFIER_NAME = 'id';\nconst activeRegistryStorage = new AsyncLocalStorage<ModelRegistry>();\n\n/**\n * Registry that resolves Tango models by stable identity.\n *\n * The global registry is convenient for application bootstrapping, while\n * dedicated instances are useful in tests and tooling.\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\n /**\n * Return the shared process-wide registry used by `Model(...)`.\n */\n static global(): ModelRegistry {\n if (!ModelRegistry.globalRegistry) {\n ModelRegistry.globalRegistry = new ModelRegistry();\n }\n return ModelRegistry.globalRegistry;\n }\n\n /**\n * Return the registry currently bound to model construction work.\n */\n static active(): ModelRegistry {\n return 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 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: Model): ModelRegistry {\n return InternalSchemaModel.getRegistryOwner(model);\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 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 finalized = ResolvedRelationGraphBuilder.build({\n version: this.version,\n models: this.values(),\n storage: this.finalizeStorageArtifacts(),\n resolveRef: (ref) => this.resolveRef(ref),\n });\n this.relationGraphCache = finalized;\n return finalized;\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 }\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","/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\nexport { ModelRegistry } from './ModelRegistry';\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 { 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 { ModelRegistry } from './registry/index';\n"],"mappings":";;;;;;;;;;;;;;;AAGA,MAAM,qBAAqB,IAAI;AAExB,SAAS,iBAAiBA,QAAgD;AAC7E,QAAO,mBAAmB,IAAI,OAAO;AACxC;AAEM,SAAS,iBAAiBA,QAAoBC,MAA4B;CAC7E,MAAM,WAAW,mBAAmB,IAAI,OAAO;AAC/C,oBAAmB,IAAI,QAAQ;EAC3B,GAAG;EACH,GAAG;CACN,EAAC;AACL;;;;ACSM,SAAS,oBAA0CC,KAAgD;AACtG,QAAO,OAAO,OAAO,EAAE,IAAK,EAAC;AAChC;AAEM,SAAS,gBAAgBC,OAAwC;AACpE,eAAc,UAAU,YAAY,UAAU,eAAgB,MAA4B,QAAQ;AACrG;;;;MC9BY,6BAA6B;CACtC,aAAa;CACb,YAAY;CACZ,cAAc;AACjB;;;;ACYD,SAAS,UAAUC,OAAqC;AACpD,UACM,gBACK,UAAU,YACjB,eAAe,gBACP,MAAkC,cAAc;AAE/D;AAED,SAAS,SAA+BC,QAAWC,MAAyB;AACxE,kBAAiB,QAAQ,KAAK;AAC9B,QAAO;AACV;AAED,MAAM,uBAAuB,IAAI;AAEjC,SAAS,6BAA6BC,MAA0BC,aAA2B;AACvF,KAAI,qBAAqB,IAAI,KAAK,CAC9B;AAGJ,sBAAqB,IAAI,KAAK;AAC9B,WAAU,0BAA0B,CAAC,MAChC,mDAAmD,KAAK,gBAAgB,YAAY,WACxF;AACJ;AAED,SAAS,eACLC,mBACAH,MACsB;AACtB,KAAI,kBACA,QAAO,SAAS,mBAAmB,KA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C;AACJ;;;;;;;;;;;;;;ACpSD,MAAM,kBAAkB,IAAI;AAKrB,SAAS,uBAAuBC,WAAuC;AAC1E,iBAAgB,IAAI,UAAU;AAE9B,MAAK,MAAM,SAAS,cAAc,QAAQ,CAAC,QAAQ,CAC/C,WAAU,MAAM;AAGpB,QAAO,MAAM;AACT,kBAAgB,OAAO,UAAU;CACpC;AACJ;AAKM,SAAS,qBACZC,OACoB;AACpB,MAAK,MAAM,aAAa,gBACpB,WAAU,MAAM;AAGpB,QAAO;AACV;;;;ACzBM,SAAS,MAKZC,YAC8C;CAC9C,MAAM,WAAW,WAAW,YAAY,cAAc,QAAQ;CAC9D,MAAM,QAAQ,qBACV,oBAAoB,OAAO,YAAY,SAAS,CACnD;AAED,UAAS,SAAS,MAAM;AACxB,QAAO;AACV"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danceroutine/tango-schema",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Model factory, Zod helpers, and metadata utilities for Tango",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"zod": "^4.0.0",
|
|
41
|
-
"@danceroutine/tango-core": "1.
|
|
41
|
+
"@danceroutine/tango-core": "1.4.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/node": "^22.9.0",
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { INTERNAL_DECORATED_FIELD_KIND } from './DecoratedFieldKind';
|
|
2
|
-
import type { RelationDecoratedSchema } from './RelationDecoratedSchema';
|
|
3
|
-
import type { ZodTypeAny } from './ZodTypeAny';
|
|
4
|
-
export type ManyToManyDecoratedSchema<TSchema extends ZodTypeAny> = RelationDecoratedSchema<TSchema, typeof INTERNAL_DECORATED_FIELD_KIND.MANY_TO_MANY>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"model-CJbsYdkM.js","names":["schema: ZodTypeAny","meta: TangoFieldMeta","value: unknown","schema: T","meta: TangoFieldMeta","kind: DecoratedFieldKind","replacement: string","schemaOrUndefined: T | undefined","schema?: T","value: string | { now: true } | null","value: string","name: string","values: readonly unknown[]","text: string","map: Record<string, string>","schema: TField","config?: { name?: string; relatedName?: string }","config?: ReferentialOptions","target: ModelRef","schemaOrOptions?: T | ForeignKeyDecoratorConfig<T>","maybeOptions?: ReferentialOptions","schemaOrOptions?: T | OneToOneDecoratorConfig<T>","schemaOrConfig?: T | ManyToManyDecoratorConfig<T>","Decorators: TangoDecorators","value: boolean","value: string","fields: string[]","options?: { name?: string; where?: string }","condition: string","options?: { name?: string }","definition: { using?: string; elements: string[]; where?: string; name?: string }","on: string[]","options?: Omit<IndexDef, 'on'>","value: unknown","value: unknown","name: string","value: unknown","value: unknown","value: unknown","value: unknown","value: unknown","value: unknown","value: unknown","value: unknown","value: unknown","name: string","zodType: z.ZodType","meta: TangoFieldMeta | undefined","registry: ModelRegistry","resolveReferenceTarget?: (target: ModelRef) => { table: string; pk: string }","type: FieldType","defaultValue: Field['default']","unwrapped: z.ZodType","field: Field","target: ModelRef","explicitColumn?: string","schema: z.ZodObject<z.ZodRawShape>","options?: InferFieldsOptions","fields: Field[]","target: string","foreignKey: string","localKey?: string","sourceModelKey: string","schema: z.ZodObject<z.ZodRawShape>","descriptors: NormalizedRelationStorageDescriptor[]","candidate: RelationCandidate","sourceSchemaFieldKey: string","origin: NormalizedRelationOrigin","fieldKey: string","value: string","name: string","registry: ModelRegistry","metadata: ModelMetadata","schema: TSchema","hooks: ModelWriteHooks<PersistedModelOutput<TSchema>> | undefined","normalizedRelations: readonly NormalizedRelationStorageDescriptor[]","explicitFields: readonly Field[] | undefined","explicitRelations: Readonly<Record<string, RelationDef>> | undefined","definition: ModelDefinition<TSchema>","value: unknown","model: AnySchemaModel","options: GraphBuilderOptions","model: Model","sourceModel: Model","descriptor: NormalizedRelationStorageDescriptor","targetModel: Model","explicitRelations: Readonly<Record<string, RelationDef>>","descriptor: ResolvedRelationDescriptor","modelKey: string","relationName: string","target: string","cardinality: RelationCardinality","registry: ModelRegistry","work: () => Promise<T> | T","model: Model","models: readonly Model[]","namespace: string","name: string","key: string","ref: ModelRef","finalized: FinalizedStorageArtifacts","model: Model | string","fields: readonly Field[]","inferredFields: readonly Field[]","explicitFields?: readonly Field[]","augmentor: ModelAugmentor","model: Model<TSchema>","definition: ModelDefinition<TSchema>"],"sources":["../src/model/fields/FieldMetadataStore.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/RelationSpec.ts","../src/model/relations/ResolvedRelationGraphBuilder.ts","../src/model/registry/ModelRegistry.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","export const INTERNAL_DECORATED_FIELD_KIND = {\n FOREIGN_KEY: 'foreignKey',\n ONE_TO_ONE: 'oneToOne',\n MANY_TO_MANY: 'manyToMany',\n} as const;\nexport type DecoratedFieldKind = (typeof INTERNAL_DECORATED_FIELD_KIND)[keyof typeof INTERNAL_DECORATED_FIELD_KIND];\n","import { getLogger } from '@danceroutine/tango-core';\nimport { z } from 'zod';\nimport { setFieldMetadata } from '../fields/FieldMetadataStore';\nimport type { ZodTypeAny } from './domain/ZodTypeAny';\nimport type { ModelRef } from './domain/ModelRef';\nimport type { ReferentialOptions, TangoFieldMeta } from './domain/TangoFieldMeta';\nimport type {\n ForeignKeyDecoratorConfig,\n ManyToManyDecoratorConfig,\n OneToOneDecoratorConfig,\n} from './domain/RelationDecoratorConfig';\nimport type { RelationDecoratedSchema } from './domain/RelationDecoratedSchema';\nimport { INTERNAL_DECORATED_FIELD_KIND } 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\nfunction foreignKey<T extends ZodTypeAny>(\n target: ModelRef,\n config: ForeignKeyDecoratorConfig<T> & { field: T }\n): RelationDecoratedSchema<T, 'foreignKey'>;\nfunction foreignKey(target: ModelRef, config?: ForeignKeyDecoratorConfig): z.ZodNumber;\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 INTERNAL_DECORATED_FIELD_KIND.FOREIGN_KEY,\n 't.foreignKey(target, { field: schema, ...options })'\n );\n return applyRelationMetadata(schemaOrOptions, {\n relationKind: INTERNAL_DECORATED_FIELD_KIND.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: INTERNAL_DECORATED_FIELD_KIND.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<T extends ZodTypeAny>(\n target: ModelRef,\n config: OneToOneDecoratorConfig<T> & { field: T }\n): RelationDecoratedSchema<T, 'oneToOne'>;\nfunction oneToOne(target: ModelRef, config?: OneToOneDecoratorConfig): z.ZodNumber;\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 INTERNAL_DECORATED_FIELD_KIND.ONE_TO_ONE,\n 't.oneToOne(target, { field: schema, ...options })'\n );\n return applyRelationMetadata(schemaOrOptions, {\n relationKind: INTERNAL_DECORATED_FIELD_KIND.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: INTERNAL_DECORATED_FIELD_KIND.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<T extends ZodTypeAny>(\n target: ModelRef,\n config: ManyToManyDecoratorConfig<T> & { field: T }\n): RelationDecoratedSchema<T, 'manyToMany'>;\nfunction manyToMany(target: ModelRef, config?: ManyToManyDecoratorConfig): z.ZodArray<z.ZodNumber>;\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 INTERNAL_DECORATED_FIELD_KIND.MANY_TO_MANY,\n 't.manyToMany(target, { field: schema, name })'\n );\n return applyRelationMetadata(schemaOrConfig, {\n relationKind: INTERNAL_DECORATED_FIELD_KIND.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 const schema = config?.field ?? z.array(z.number().int());\n return applyRelationMetadata(\n schema,\n {\n relationKind: INTERNAL_DECORATED_FIELD_KIND.MANY_TO_MANY,\n references: {\n target,\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 <T extends ZodTypeAny>(\n target: ModelRef,\n config: ForeignKeyDecoratorConfig<T> & { field: T }\n ): RelationDecoratedSchema<T, 'foreignKey'>;\n (target: ModelRef, config?: ForeignKeyDecoratorConfig): z.ZodNumber;\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 <T extends ZodTypeAny>(\n target: ModelRef,\n config: OneToOneDecoratorConfig<T> & { field: T }\n ): RelationDecoratedSchema<T, 'oneToOne'>;\n (target: ModelRef, config?: OneToOneDecoratorConfig): z.ZodNumber;\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 <T extends ZodTypeAny>(\n target: ModelRef,\n config: ManyToManyDecoratorConfig<T> & { field: T }\n ): RelationDecoratedSchema<T, 'manyToMany'>;\n (target: ModelRef, config?: ManyToManyDecoratorConfig): z.ZodArray<z.ZodNumber>;\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 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 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 } from './domain/ModelRef';\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 { INTERNAL_DECORATED_FIELD_KIND } 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 === INTERNAL_DECORATED_FIELD_KIND.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 { INTERNAL_DECORATED_FIELD_KIND } 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 === INTERNAL_DECORATED_FIELD_KIND.ONE_TO_ONE,\n explicitForwardName: meta.forwardName,\n explicitReverseName: meta.reverseName,\n namingHint: this.deriveNamingHint(candidate.sourceSchemaFieldKey),\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","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>>;\n\nexport class InternalSchemaModel<TSchema extends z.ZodObject<z.ZodRawShape>> implements Model<TSchema> {\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> extends { readonly objects: infer TObject } ? TObject : never;\n\n private readonly registry: ModelRegistry;\n private readonly normalizedRelations: readonly NormalizedRelationStorageDescriptor[];\n private readonly explicitFields?: readonly Field[];\n private readonly explicitRelations?: Readonly<Record<string, RelationDef>>;\n\n private constructor(\n registry: ModelRegistry,\n metadata: ModelMetadata,\n schema: TSchema,\n hooks: ModelWriteHooks<PersistedModelOutput<TSchema>> | undefined,\n normalizedRelations: readonly NormalizedRelationStorageDescriptor[],\n explicitFields: readonly Field[] | undefined,\n explicitRelations: Readonly<Record<string, RelationDef>> | undefined\n ) {\n this.registry = registry;\n this.metadata = metadata;\n this.schema = schema;\n this.hooks = hooks;\n this.normalizedRelations = Object.freeze([...normalizedRelations]);\n this.explicitFields = explicitFields ? Object.freeze([...explicitFields]) : undefined;\n this.explicitRelations = explicitRelations;\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 return new InternalSchemaModel(\n registry,\n metadata,\n definition.schema,\n definition.hooks,\n normalizedRelations,\n definition.fields,\n relations\n );\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 return InternalSchemaModel.require(model).registry;\n }\n\n static getNormalizedRelations(model: AnySchemaModel): readonly NormalizedRelationStorageDescriptor[] {\n return InternalSchemaModel.require(model).normalizedRelations;\n }\n\n static getExplicitFields(model: AnySchemaModel): readonly Field[] | undefined {\n return InternalSchemaModel.require(model).explicitFields;\n }\n\n static getExplicitRelations(model: AnySchemaModel): Readonly<Record<string, RelationDef>> | undefined {\n return InternalSchemaModel.require(model).explicitRelations;\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","// 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 INTERNAL_RELATION_PUBLIC_KIND = {\n BELONGS_TO: 'belongsTo',\n HAS_ONE: 'hasOne',\n HAS_MANY: 'hasMany',\n MANY_TO_MANY: 'manyToMany',\n} as const;\n\nexport const INTERNAL_RELATION_STORAGE_STRATEGY = {\n REFERENCE: 'reference',\n REVERSE_REFERENCE: 'reverse_reference',\n MANY_TO_MANY: 'many_to_many',\n} as const;\n\nexport const INTERNAL_RELATION_CARDINALITY = {\n SINGLE: 'single',\n MANY: 'many',\n} as const;\n\nexport const INTERNAL_RELATION_PROVENANCE = {\n FIELD_DECORATOR: 'field-decorator',\n RELATIONS_API: 'relations-api',\n SYNTHESIZED_REVERSE: 'synthesized-reverse',\n} as const;\n\nexport type RelationPublicKind = (typeof INTERNAL_RELATION_PUBLIC_KIND)[keyof typeof INTERNAL_RELATION_PUBLIC_KIND];\nexport type RelationStorageStrategy =\n (typeof INTERNAL_RELATION_STORAGE_STRATEGY)[keyof typeof INTERNAL_RELATION_STORAGE_STRATEGY];\nexport type RelationCardinality = (typeof INTERNAL_RELATION_CARDINALITY)[keyof typeof INTERNAL_RELATION_CARDINALITY];\nexport type RelationProvenance = (typeof INTERNAL_RELATION_PROVENANCE)[keyof typeof INTERNAL_RELATION_PROVENANCE];\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 type { Model, RelationDef } from '../../domain/index';\nimport type { FinalizedStorageArtifacts } from '../fields/FinalizedStorageArtifacts';\nimport { InternalSchemaModel } from '../internal/InternalSchemaModel';\nimport type { NormalizedRelationStorageDescriptor } from './NormalizedRelationStorageDescriptor';\nimport type { ResolvedRelationDescriptor, ResolvedRelationGraph } from './ResolvedRelationGraph';\nimport {\n type RelationCardinality,\n INTERNAL_RELATION_CARDINALITY,\n INTERNAL_RELATION_PUBLIC_KIND,\n INTERNAL_RELATION_PROVENANCE,\n INTERNAL_RELATION_STORAGE_STRATEGY,\n} from './RelationSpec';\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: false,\n hydratable: false,\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 * 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 === 'manyToMany') {\n const relationName = descriptor.explicitForwardName ?? descriptor.namingHint;\n this.addResolvedRelation({\n edgeId: descriptor.edgeId,\n sourceModelKey: model.metadata.key,\n targetModelKey: targetModel.metadata.key,\n name: relationName,\n kind: INTERNAL_RELATION_PUBLIC_KIND.MANY_TO_MANY,\n storageStrategy: INTERNAL_RELATION_STORAGE_STRATEGY.MANY_TO_MANY,\n cardinality: INTERNAL_RELATION_CARDINALITY.MANY,\n capabilities: MANY_TO_MANY_CAPABILITIES,\n provenance: INTERNAL_RELATION_PROVENANCE.FIELD_DECORATOR,\n alias: `${toSnakeCase(model.metadata.name)}_${relationName}`,\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: INTERNAL_RELATION_PUBLIC_KIND.BELONGS_TO,\n storageStrategy: INTERNAL_RELATION_STORAGE_STRATEGY.REFERENCE,\n cardinality: INTERNAL_RELATION_CARDINALITY.SINGLE,\n localFieldName: descriptor.dbColumnName,\n targetFieldName: descriptor.referencedTargetColumn ?? targetPrimaryKey,\n capabilities: REFERENCE_CAPABILITIES,\n provenance: INTERNAL_RELATION_PROVENANCE.FIELD_DECORATOR,\n alias: `${toSnakeCase(targetModel.metadata.name)}_${forwardName}`,\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 ? INTERNAL_RELATION_PUBLIC_KIND.HAS_ONE\n : INTERNAL_RELATION_PUBLIC_KIND.HAS_MANY;\n const reverseCardinality = descriptor.unique\n ? INTERNAL_RELATION_CARDINALITY.SINGLE\n : INTERNAL_RELATION_CARDINALITY.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: INTERNAL_RELATION_STORAGE_STRATEGY.REVERSE_REFERENCE,\n cardinality: reverseCardinality,\n localFieldName: descriptor.dbColumnName,\n targetFieldName: descriptor.referencedTargetColumn ?? targetPrimaryKey,\n capabilities: REFERENCE_CAPABILITIES,\n provenance: reverseOverride\n ? INTERNAL_RELATION_PROVENANCE.RELATIONS_API\n : INTERNAL_RELATION_PROVENANCE.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 === INTERNAL_RELATION_PUBLIC_KIND.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 ? INTERNAL_RELATION_PUBLIC_KIND.HAS_ONE\n : INTERNAL_RELATION_PUBLIC_KIND.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 === INTERNAL_RELATION_CARDINALITY.MANY ? pluralize(snake) : snake;\n }\n}\n","import { AsyncLocalStorage } from 'node:async_hooks';\nimport type { Field, Model } from '../../domain/index';\nimport type { ZodTypeAny } from '../decorators/domain/ZodTypeAny';\nimport 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';\n\nconst DEFAULT_IDENTIFIER_NAME = 'id';\nconst activeRegistryStorage = new AsyncLocalStorage<ModelRegistry>();\n\n/**\n * Registry that resolves Tango models by stable identity.\n *\n * The global registry is convenient for application bootstrapping, while\n * dedicated instances are useful in tests and tooling.\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\n /**\n * Return the shared process-wide registry used by `Model(...)`.\n */\n static global(): ModelRegistry {\n if (!ModelRegistry.globalRegistry) {\n ModelRegistry.globalRegistry = new ModelRegistry();\n }\n return ModelRegistry.globalRegistry;\n }\n\n /**\n * Return the registry currently bound to model construction work.\n */\n static active(): ModelRegistry {\n return 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 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: Model): ModelRegistry {\n return InternalSchemaModel.getRegistryOwner(model);\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') {\n const model = this.getByKey(ref);\n if (!model) {\n throw new Error(\n `Unable to resolve model reference '${ref}'. 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 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 finalized = ResolvedRelationGraphBuilder.build({\n version: this.version,\n models: this.values(),\n storage: this.finalizeStorageArtifacts(),\n resolveRef: (ref) => this.resolveRef(ref),\n });\n this.relationGraphCache = finalized;\n return finalized;\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 }\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","/**\n * Domain boundary barrel: centralizes this subdomain's public contract.\n */\nexport { ModelRegistry } from './ModelRegistry';\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>>(model: Model<TSchema>) => 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>>(\n model: Model<TSchema>\n): Model<TSchema> {\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<TSchema extends z.ZodObject<z.ZodRawShape>>(\n definition: ModelDefinition<TSchema>\n): SchemaModel<TSchema> {\n const registry = definition.registry ?? ModelRegistry.active();\n const model = applyModelAugmentors(InternalSchemaModel.create(definition, registry) as SchemaModel<TSchema>);\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 { Model } from './Model';\nexport { registerModelAugmentor } from './ModelAugmentorRegistry';\nexport { Decorators, t } from './decorators/index';\nexport type {\n TangoDecorators,\n FieldDecoratorBuilder,\n ForeignKeyDecoratorConfig,\n OneToOneDecoratorConfig,\n ManyToManyDecoratorConfig,\n} 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 { ModelRegistry } from './registry/index';\n"],"mappings":";;;;;;;;;;;;;;;AAGA,MAAM,qBAAqB,IAAI;AAExB,SAAS,iBAAiBA,QAAgD;AAC7E,QAAO,mBAAmB,IAA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