@danceroutine/tango-schema 1.1.3 → 1.2.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.
Files changed (38) hide show
  1. package/dist/domain/Model.d.ts +7 -1
  2. package/dist/domain/index.d.ts +1 -1
  3. package/dist/domain-Cufz6y1q.js.map +1 -1
  4. package/dist/index.d.ts +2 -2
  5. package/dist/index.js +1 -1
  6. package/dist/model/Model.d.ts +1 -1
  7. package/dist/model/ModelDefinition.d.ts +5 -3
  8. package/dist/model/decorators/Decorators.d.ts +46 -6
  9. package/dist/model/decorators/domain/DecoratedFieldKind.d.ts +6 -0
  10. package/dist/model/decorators/domain/ManyToManyDecoratedSchema.d.ts +4 -0
  11. package/dist/model/decorators/domain/ModelRef.d.ts +2 -0
  12. package/dist/model/decorators/domain/RelationDecoratedSchema.d.ts +9 -0
  13. package/dist/model/decorators/domain/RelationDecoratorConfig.d.ts +35 -0
  14. package/dist/model/decorators/{types.d.ts → domain/TangoFieldMeta.d.ts} +6 -5
  15. package/dist/model/decorators/domain/ZodTypeAny.d.ts +2 -0
  16. package/dist/model/decorators/index.d.ts +5 -2
  17. package/dist/model/{internal → fields}/FieldMetadataStore.d.ts +2 -1
  18. package/dist/model/fields/FinalizedStorageArtifacts.d.ts +11 -0
  19. package/dist/model/{inferFields.d.ts → fields/inferFieldsFromSchema.d.ts} +7 -2
  20. package/dist/model/index.d.ts +12 -3
  21. package/dist/model/index.js +2 -2
  22. package/dist/model/internal/InternalSchemaModel.d.ts +31 -0
  23. package/dist/model/registry/ModelRegistry.d.ts +35 -2
  24. package/dist/model/registry/index.d.ts +4 -0
  25. package/dist/model/relations/NormalizedRelationStorageDescriptor.d.ts +36 -0
  26. package/dist/model/relations/RelationBuilder.d.ts +19 -0
  27. package/dist/model/relations/RelationDescriptorNormalizer.d.ts +30 -0
  28. package/dist/model/relations/RelationSpec.d.ts +48 -0
  29. package/dist/model/relations/ResolvedRelationGraph.d.ts +43 -0
  30. package/dist/model/relations/ResolvedRelationGraphBuilder.d.ts +48 -0
  31. package/dist/model/relations/SchemaNaming.d.ts +11 -0
  32. package/dist/model/relations/index.d.ts +13 -0
  33. package/dist/model-CJbsYdkM.js +1124 -0
  34. package/dist/model-CJbsYdkM.js.map +1 -0
  35. package/package.json +3 -2
  36. package/dist/model/RelationBuilder.d.ts +0 -12
  37. package/dist/model-DI8lQH1W.js +0 -585
  38. package/dist/model-DI8lQH1W.js.map +0 -1
@@ -1,6 +1,7 @@
1
1
  import type { z } from 'zod';
2
2
  import type { ModelMetadata } from './ModelMetadata';
3
3
  import type { ModelWriteHooks } from './ModelWriteHooks';
4
+ import type { ManyToManyDecoratedSchema } from '../model/decorators/domain/ManyToManyDecoratedSchema';
4
5
  declare const MODEL_AUGMENTATION_SCHEMA: unique symbol;
5
6
  type ModelAugmentationCarrier<TSchema extends z.ZodObject<z.ZodRawShape>> = {
6
7
  readonly [MODEL_AUGMENTATION_SCHEMA]?: TSchema;
@@ -9,6 +10,11 @@ declare global {
9
10
  interface TangoSchemaModelAugmentations<TSchema extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>> {
10
11
  }
11
12
  }
13
+ type ManyToManyFieldKeys<TShape extends z.ZodRawShape> = {
14
+ [K in keyof TShape]: TShape[K] extends ManyToManyDecoratedSchema<z.ZodTypeAny> ? K : never;
15
+ }[keyof TShape];
16
+ type PersistedShape<TShape extends z.ZodRawShape> = Omit<z.output<z.ZodObject<TShape>>, ManyToManyFieldKeys<TShape>>;
17
+ export type PersistedModelOutput<TSchema extends z.ZodObject<z.ZodRawShape>> = TSchema extends z.ZodObject<infer TShape> ? PersistedShape<TShape> : z.output<TSchema>;
12
18
  export interface ModelAugmentations<TSchema extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>> extends ModelAugmentationCarrier<TSchema>, TangoSchemaModelAugmentations<TSchema> {
13
19
  }
14
20
  export interface Model<TSchema extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>> extends ModelAugmentations<TSchema> {
@@ -17,6 +23,6 @@ export interface Model<TSchema extends z.ZodObject<z.ZodRawShape> = z.ZodObject<
17
23
  /**
18
24
  * Model-owned write lifecycle hooks preserved from the definition.
19
25
  */
20
- hooks?: ModelWriteHooks<z.output<TSchema>>;
26
+ hooks?: ModelWriteHooks<PersistedModelOutput<TSchema>>;
21
27
  }
22
28
  export {};
@@ -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 } from './Model';
12
+ export type { Model, ModelAugmentations, PersistedModelOutput } from './Model';
13
13
  export type { ModelHookModel, ModelWriteHookManager, 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 } 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, 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":""}
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, 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, } 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';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Constraints, Decorators, Indexes, Meta, Model, ModelRegistry, RelationBuilder, model_exports, registerModelAugmentor } from "./model-DI8lQH1W.js";
1
+ import { Constraints, Decorators, Indexes, Meta, Model, ModelRegistry, RelationBuilder, model_exports, registerModelAugmentor } from "./model-CJbsYdkM.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 };
@@ -3,6 +3,6 @@ import type { Model as SchemaModel } from '../domain/Model';
3
3
  import type { ModelDefinition } from './ModelDefinition';
4
4
  /**
5
5
  * Creates a model definition with metadata and schema validation.
6
- * Automatically infers field types from Zod schema if fields are not explicitly provided.
6
+ * Automatically finalizes field types through the owning model registry.
7
7
  */
8
8
  export declare function Model<TSchema extends z.ZodObject<z.ZodRawShape>>(definition: ModelDefinition<TSchema>): SchemaModel<TSchema>;
@@ -1,12 +1,14 @@
1
1
  import { z } from 'zod';
2
- import type { Field, IndexDef, RelationDef } from '../domain/index';
2
+ import type { Field, IndexDef, PersistedModelOutput, RelationDef } from '../domain/index';
3
3
  import type { ModelWriteHooks } from '../domain/index';
4
- import type { RelationBuilder } from './RelationBuilder';
4
+ import type { RelationBuilder } from './relations/RelationBuilder';
5
+ import type { ModelRegistry } from './registry/ModelRegistry';
5
6
  export interface ModelDefinition<TSchema extends z.ZodObject<z.ZodRawShape>> {
6
7
  namespace: string;
7
8
  name: string;
8
9
  table?: string;
9
10
  schema: TSchema;
11
+ registry?: ModelRegistry;
10
12
  fields?: Field[];
11
13
  indexes?: IndexDef[];
12
14
  relations?: (builder: RelationBuilder) => Record<string, RelationDef>;
@@ -17,5 +19,5 @@ export interface ModelDefinition<TSchema extends z.ZodObject<z.ZodRawShape>> {
17
19
  /**
18
20
  * Model-owned write lifecycle hooks that run inside `Model.objects`.
19
21
  */
20
- hooks?: ModelWriteHooks<z.output<TSchema>>;
22
+ hooks?: ModelWriteHooks<PersistedModelOutput<TSchema>>;
21
23
  }
@@ -1,18 +1,58 @@
1
1
  import { z } from 'zod';
2
- import type { ModelRef, ReferentialOptions, ZodTypeAny } from './types';
2
+ import type { ZodTypeAny } from './domain/ZodTypeAny';
3
+ import type { ModelRef } from './domain/ModelRef';
4
+ import type { ReferentialOptions } from './domain/TangoFieldMeta';
5
+ import type { ForeignKeyDecoratorConfig, ManyToManyDecoratorConfig, OneToOneDecoratorConfig } from './domain/RelationDecoratorConfig';
6
+ import type { RelationDecoratedSchema } from './domain/RelationDecoratedSchema';
7
+ export interface FieldDecoratorBuilder<TField extends ZodTypeAny> {
8
+ defaultValue(value: string | {
9
+ now: true;
10
+ } | null): FieldDecoratorBuilder<TField>;
11
+ dbDefault(value: string): FieldDecoratorBuilder<TField>;
12
+ dbColumn(name: string): FieldDecoratorBuilder<TField>;
13
+ dbIndex(): FieldDecoratorBuilder<TField>;
14
+ choices(values: readonly unknown[]): FieldDecoratorBuilder<TField>;
15
+ validators(...values: readonly ((value: unknown) => unknown)[]): FieldDecoratorBuilder<TField>;
16
+ helpText(text: string): FieldDecoratorBuilder<TField>;
17
+ errorMessages(map: Record<string, string>): FieldDecoratorBuilder<TField>;
18
+ build(): TField;
19
+ }
3
20
  type UnaryFieldDecorator = {
4
21
  <T extends ZodTypeAny>(schema: T): T;
5
22
  <T extends ZodTypeAny>(): (input: T) => T;
6
23
  };
7
24
  type RelationshipDecorator = {
8
- <T extends ZodTypeAny>(target: ModelRef, schema: T, options?: ReferentialOptions): T;
9
- (target: ModelRef, options?: ReferentialOptions): z.ZodNumber;
25
+ <T extends ZodTypeAny>(target: ModelRef, config: ForeignKeyDecoratorConfig<T> & {
26
+ field: T;
27
+ }): RelationDecoratedSchema<T, 'foreignKey'>;
28
+ (target: ModelRef, config?: ForeignKeyDecoratorConfig): z.ZodNumber;
29
+ /**
30
+ * @deprecated Use `t.foreignKey(target, { field: schema, ...options })` instead.
31
+ */
32
+ <T extends ZodTypeAny>(target: ModelRef, schema: T, options?: ReferentialOptions): RelationDecoratedSchema<T, 'foreignKey'>;
33
+ };
34
+ type OneToOneRelationshipDecorator = {
35
+ <T extends ZodTypeAny>(target: ModelRef, config: OneToOneDecoratorConfig<T> & {
36
+ field: T;
37
+ }): RelationDecoratedSchema<T, 'oneToOne'>;
38
+ (target: ModelRef, config?: OneToOneDecoratorConfig): z.ZodNumber;
39
+ /**
40
+ * @deprecated Use `t.oneToOne(target, { field: schema, ...options })` instead.
41
+ */
42
+ <T extends ZodTypeAny>(target: ModelRef, schema: T, options?: ReferentialOptions): RelationDecoratedSchema<T, 'oneToOne'>;
10
43
  };
11
44
  type ManyToManyDecorator = {
12
- <T extends ZodTypeAny>(target: ModelRef, schema: T): T;
13
- (target: ModelRef): z.ZodArray<z.ZodNumber>;
45
+ <T extends ZodTypeAny>(target: ModelRef, config: ManyToManyDecoratorConfig<T> & {
46
+ field: T;
47
+ }): RelationDecoratedSchema<T, 'manyToMany'>;
48
+ (target: ModelRef, config?: ManyToManyDecoratorConfig): z.ZodArray<z.ZodNumber>;
49
+ /**
50
+ * @deprecated Use `t.manyToMany(target, { field: schema, name })` instead.
51
+ */
52
+ <T extends ZodTypeAny>(target: ModelRef, schema: T): RelationDecoratedSchema<T, 'manyToMany'>;
14
53
  };
15
54
  export interface TangoDecorators {
55
+ field: <T extends ZodTypeAny>(schema: T) => FieldDecoratorBuilder<T>;
16
56
  primaryKey: UnaryFieldDecorator;
17
57
  unique: UnaryFieldDecorator;
18
58
  null: UnaryFieldDecorator;
@@ -28,7 +68,7 @@ export interface TangoDecorators {
28
68
  helpText: <T extends ZodTypeAny>(schema: T, text: string) => T;
29
69
  errorMessages: <T extends ZodTypeAny>(schema: T, map: Record<string, string>) => T;
30
70
  foreignKey: RelationshipDecorator;
31
- oneToOne: RelationshipDecorator;
71
+ oneToOne: OneToOneRelationshipDecorator;
32
72
  manyToMany: ManyToManyDecorator;
33
73
  }
34
74
  export declare const Decorators: TangoDecorators;
@@ -0,0 +1,6 @@
1
+ export declare const INTERNAL_DECORATED_FIELD_KIND: {
2
+ readonly FOREIGN_KEY: "foreignKey";
3
+ readonly ONE_TO_ONE: "oneToOne";
4
+ readonly MANY_TO_MANY: "manyToMany";
5
+ };
6
+ export type DecoratedFieldKind = (typeof INTERNAL_DECORATED_FIELD_KIND)[keyof typeof INTERNAL_DECORATED_FIELD_KIND];
@@ -0,0 +1,4 @@
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>;
@@ -0,0 +1,2 @@
1
+ import type { Model } from '../../../domain';
2
+ export type ModelRef = string | Model | (() => Model);
@@ -0,0 +1,9 @@
1
+ import type { DecoratedFieldKind } from './DecoratedFieldKind';
2
+ import type { ZodTypeAny } from './ZodTypeAny';
3
+ declare const TANGO_DECORATED_FIELD_KIND: unique symbol;
4
+ export type RelationDecoratedSchema<TSchema extends ZodTypeAny, TKind extends DecoratedFieldKind> = TSchema & {
5
+ readonly [TANGO_DECORATED_FIELD_KIND]: {
6
+ readonly relationKind: TKind;
7
+ };
8
+ };
9
+ export {};
@@ -0,0 +1,35 @@
1
+ import type { ZodTypeAny } from './ZodTypeAny';
2
+ import type { ReferentialOptions } from './TangoFieldMeta';
3
+ /**
4
+ * Config object for `t.foreignKey(...)`.
5
+ *
6
+ * The config object is the preferred second-argument form for relation
7
+ * decorators. Omit `field` to keep Tango's default schema inference.
8
+ */
9
+ export interface ForeignKeyDecoratorConfig<TField extends ZodTypeAny = ZodTypeAny> extends ReferentialOptions {
10
+ field?: TField;
11
+ name?: string;
12
+ relatedName?: string;
13
+ }
14
+ /**
15
+ * Config object for `t.oneToOne(...)`.
16
+ *
17
+ * The config object is the preferred second-argument form for relation
18
+ * decorators. Omit `field` to keep Tango's default schema inference.
19
+ */
20
+ export interface OneToOneDecoratorConfig<TField extends ZodTypeAny = ZodTypeAny> extends ReferentialOptions {
21
+ field?: TField;
22
+ name?: string;
23
+ relatedName?: string;
24
+ }
25
+ /**
26
+ * Config object for `t.manyToMany(...)`.
27
+ *
28
+ * The config object is the preferred second-argument form for relation
29
+ * decorators. Omit `field` to keep Tango's default schema inference.
30
+ */
31
+ export interface ManyToManyDecoratorConfig<TField extends ZodTypeAny = ZodTypeAny> {
32
+ field?: TField;
33
+ name?: string;
34
+ relatedName?: never;
35
+ }
@@ -1,6 +1,6 @@
1
- import type { z } from 'zod';
2
- import type { DeleteReferentialAction, Model, UpdateReferentialAction } from '../../domain/index';
3
- export type ModelRef = string | Model | (() => Model);
1
+ import type { DeleteReferentialAction, UpdateReferentialAction } from '../../../domain';
2
+ import type { DecoratedFieldKind } from './DecoratedFieldKind';
3
+ import type { ModelRef } from './ModelRef';
4
4
  export interface ReferentialOptions {
5
5
  column?: string;
6
6
  onDelete?: DeleteReferentialAction;
@@ -24,6 +24,7 @@ export interface TangoFieldMeta {
24
24
  target: ModelRef;
25
25
  options?: ReferentialOptions;
26
26
  };
27
- relationKind?: 'foreignKey' | 'oneToOne' | 'manyToMany';
27
+ relationKind?: DecoratedFieldKind;
28
+ forwardName?: string;
29
+ reverseName?: string;
28
30
  }
29
- export type ZodTypeAny = z.ZodTypeAny;
@@ -0,0 +1,2 @@
1
+ import type { z } from 'zod';
2
+ export type ZodTypeAny = z.ZodTypeAny;
@@ -2,5 +2,8 @@
2
2
  * Domain boundary barrel: centralizes this subdomain's public contract.
3
3
  */
4
4
  export { Decorators, Decorators as t } from './Decorators';
5
- export type { TangoDecorators } from './Decorators';
6
- export type { ModelRef, ReferentialOptions, TangoFieldMeta, ZodTypeAny } from './types';
5
+ export type { FieldDecoratorBuilder, TangoDecorators } from './Decorators';
6
+ export type { ModelRef } from './domain/ModelRef';
7
+ export type { ForeignKeyDecoratorConfig, OneToOneDecoratorConfig, ManyToManyDecoratorConfig, } from './domain/RelationDecoratorConfig';
8
+ export type { ReferentialOptions, TangoFieldMeta } from './domain/TangoFieldMeta';
9
+ export type { ZodTypeAny } from './domain/ZodTypeAny';
@@ -1,3 +1,4 @@
1
- import type { TangoFieldMeta, ZodTypeAny } from '../decorators/types';
1
+ import type { ZodTypeAny } from '../decorators/domain/ZodTypeAny';
2
+ import type { TangoFieldMeta } from '../decorators/domain/TangoFieldMeta';
2
3
  export declare function getFieldMetadata(schema: ZodTypeAny): TangoFieldMeta | undefined;
3
4
  export declare function setFieldMetadata(schema: ZodTypeAny, meta: TangoFieldMeta): void;
@@ -0,0 +1,11 @@
1
+ import type { Field } from '../../domain/index';
2
+ export interface FinalizedStorageModel {
3
+ key: string;
4
+ table: string;
5
+ fields: readonly Field[];
6
+ pk: string;
7
+ }
8
+ export interface FinalizedStorageArtifacts {
9
+ version: number;
10
+ byModel: ReadonlyMap<string, FinalizedStorageModel>;
11
+ }
@@ -1,8 +1,13 @@
1
1
  import { z } from 'zod';
2
- import type { Field } from '../domain/index';
3
- import { ModelRegistry } from './registry/ModelRegistry';
2
+ import type { Field } from '../../domain/index';
3
+ import type { ModelRef } from '../decorators/domain/ModelRef';
4
+ import { ModelRegistry } from '../registry/ModelRegistry';
4
5
  export type InferFieldsOptions = {
5
6
  registry?: ModelRegistry;
7
+ resolveReferenceTarget?: (target: ModelRef) => {
8
+ table: string;
9
+ pk: string;
10
+ };
6
11
  };
7
12
  /**
8
13
  * Infer Tango field metadata from a Zod object schema and any attached field decorators.
@@ -1,14 +1,23 @@
1
1
  /**
2
2
  * Domain boundary barrel: centralizes this subdomain's public contract.
3
+ *
4
+ * Tango keeps both flat exports and namespaced subdomain barrels here so
5
+ * callers can choose TS-native direct imports or Django-style drill-down
6
+ * access through the bundled `model` namespace at the package root.
3
7
  */
8
+ export * as decorators from './decorators/index';
9
+ export * as meta from './meta/index';
10
+ export * as constraints from './constraints/index';
11
+ export * as registry from './registry/index';
12
+ export * as relations from './relations/index';
4
13
  export type { ModelDefinition } from './ModelDefinition';
5
- export { RelationBuilder } from './RelationBuilder';
14
+ export { RelationBuilder } from './relations/index';
6
15
  export { Model } from './Model';
7
16
  export { registerModelAugmentor } from './ModelAugmentorRegistry';
8
17
  export { Decorators, t } from './decorators/index';
9
- export type { TangoDecorators } from './decorators/index';
18
+ export type { TangoDecorators, FieldDecoratorBuilder, ForeignKeyDecoratorConfig, OneToOneDecoratorConfig, ManyToManyDecoratorConfig, } from './decorators/index';
10
19
  export { Meta, m } from './meta/index';
11
20
  export type { ModelConstraint, ModelMetaFragment } from './meta/index';
12
21
  export { Constraints, Indexes, c, i } from './constraints/index';
13
22
  export type { ConstraintDefinition } from './constraints/index';
14
- export { ModelRegistry } from './registry/ModelRegistry';
23
+ export { ModelRegistry } from './registry/index';
@@ -1,3 +1,3 @@
1
- import { Constraints, Decorators, Indexes, Meta, Model, ModelRegistry, RelationBuilder, registerModelAugmentor } from "../model-DI8lQH1W.js";
1
+ import { Constraints, Decorators, Indexes, Meta, Model, ModelRegistry, RelationBuilder, constraints_exports, decorators_exports, meta_exports, registerModelAugmentor, registry_exports, relations_exports } from "../model-CJbsYdkM.js";
2
2
 
3
- export { Constraints, Decorators, Indexes, Meta, Model, ModelRegistry, RelationBuilder, Constraints as c, Indexes as i, Meta as m, registerModelAugmentor, Decorators as t };
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 };
@@ -0,0 +1,31 @@
1
+ import { z } from 'zod';
2
+ import type { Field, Model, ModelAugmentations, ModelMetadata, ModelWriteHooks, PersistedModelOutput, RelationDef } from '../../domain/index';
3
+ import type { ModelDefinition } from '../ModelDefinition';
4
+ import type { ModelRegistry } from '../registry/ModelRegistry';
5
+ import type { NormalizedRelationStorageDescriptor } from '../relations/NormalizedRelationStorageDescriptor';
6
+ type AnySchemaModel = Model<z.ZodObject<z.ZodRawShape>>;
7
+ type AnyInternalSchemaModel = InternalSchemaModel<z.ZodObject<z.ZodRawShape>>;
8
+ export declare class InternalSchemaModel<TSchema extends z.ZodObject<z.ZodRawShape>> implements Model<TSchema> {
9
+ static readonly BRAND: "tango.schema.internal_schema_model";
10
+ readonly __tangoBrand: typeof InternalSchemaModel.BRAND;
11
+ readonly metadata: ModelMetadata;
12
+ readonly schema: TSchema;
13
+ readonly hooks?: ModelWriteHooks<PersistedModelOutput<TSchema>>;
14
+ readonly objects: ModelAugmentations<TSchema> extends {
15
+ readonly objects: infer TObject;
16
+ } ? TObject : never;
17
+ private readonly registry;
18
+ private readonly normalizedRelations;
19
+ private readonly explicitFields?;
20
+ private readonly explicitRelations?;
21
+ private constructor();
22
+ static create<TSchema extends z.ZodObject<z.ZodRawShape>>(definition: ModelDefinition<TSchema>, registry: ModelRegistry): InternalSchemaModel<TSchema>;
23
+ static isInternalSchemaModel(value: unknown): value is AnyInternalSchemaModel;
24
+ static getRegistryOwner(model: AnySchemaModel): ModelRegistry;
25
+ static getNormalizedRelations(model: AnySchemaModel): readonly NormalizedRelationStorageDescriptor[];
26
+ static getExplicitFields(model: AnySchemaModel): readonly Field[] | undefined;
27
+ static getExplicitRelations(model: AnySchemaModel): Readonly<Record<string, RelationDef>> | undefined;
28
+ private static validateDefinition;
29
+ private static require;
30
+ }
31
+ export {};
@@ -1,5 +1,7 @@
1
- import type { Model } from '../../domain/index';
2
- import type { ModelRef } from '../decorators/types';
1
+ import type { Field, Model } from '../../domain/index';
2
+ import type { ModelRef } from '../decorators/domain/ModelRef';
3
+ import type { FinalizedStorageArtifacts } from '../fields/FinalizedStorageArtifacts';
4
+ import type { ResolvedRelationGraph } from '../relations/ResolvedRelationGraph';
3
5
  /**
4
6
  * Registry that resolves Tango models by stable identity.
5
7
  *
@@ -9,10 +11,21 @@ import type { ModelRef } from '../decorators/types';
9
11
  export declare class ModelRegistry {
10
12
  private static globalRegistry?;
11
13
  private readonly models;
14
+ private version;
15
+ private storageCache?;
16
+ private relationGraphCache?;
12
17
  /**
13
18
  * Return the shared process-wide registry used by `Model(...)`.
14
19
  */
15
20
  static global(): ModelRegistry;
21
+ /**
22
+ * Return the registry currently bound to model construction work.
23
+ */
24
+ static active(): ModelRegistry;
25
+ /**
26
+ * Run work with a specific registry bound as the active construction target.
27
+ */
28
+ static runWithRegistry<T>(registry: ModelRegistry, work: () => Promise<T> | T): Promise<T>;
16
29
  /**
17
30
  * Register a model on the shared global registry.
18
31
  */
@@ -37,6 +50,10 @@ export declare class ModelRegistry {
37
50
  * Clear the shared registry, which is mainly useful in tests.
38
51
  */
39
52
  static clear(): void;
53
+ /**
54
+ * Return the owning registry for a model.
55
+ */
56
+ static getOwner(model: Model): ModelRegistry;
40
57
  /**
41
58
  * Register a model on this registry instance.
42
59
  */
@@ -57,6 +74,18 @@ export declare class ModelRegistry {
57
74
  * Resolve a string, callback, or direct model reference into a model object.
58
75
  */
59
76
  resolveRef(ref: ModelRef): Model;
77
+ /**
78
+ * Finalize storage-only artifacts for all models in this registry.
79
+ */
80
+ finalizeStorageArtifacts(): FinalizedStorageArtifacts;
81
+ /**
82
+ * Return finalized storage fields for a specific model.
83
+ */
84
+ getFinalizedFields(model: Model | string): readonly Field[];
85
+ /**
86
+ * Resolve the registry's relation graph from finalized storage artifacts.
87
+ */
88
+ getResolvedRelationGraph(): ResolvedRelationGraph;
60
89
  /**
61
90
  * Remove all registered models from this registry instance.
62
91
  */
@@ -65,4 +94,8 @@ export declare class ModelRegistry {
65
94
  * Return all registered models in insertion order.
66
95
  */
67
96
  values(): readonly Model[];
97
+ private bumpVersion;
98
+ private freezeFields;
99
+ private inferPrimaryKeyName;
100
+ private mergeStorageFields;
68
101
  }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Domain boundary barrel: centralizes this subdomain's public contract.
3
+ */
4
+ export { ModelRegistry } from './ModelRegistry';
@@ -0,0 +1,36 @@
1
+ import type { DeleteReferentialAction, UpdateReferentialAction } from '../../domain/index';
2
+ import type { ModelRef } from '../decorators/domain/ModelRef';
3
+ export declare const INTERNAL_NORMALIZED_RELATION_ORIGIN: {
4
+ readonly FOREIGN_KEY: "foreignKey";
5
+ readonly ONE_TO_ONE: "oneToOne";
6
+ readonly MANY_TO_MANY: "manyToMany";
7
+ };
8
+ export type NormalizedRelationOrigin = (typeof INTERNAL_NORMALIZED_RELATION_ORIGIN)[keyof typeof INTERNAL_NORMALIZED_RELATION_ORIGIN];
9
+ /**
10
+ * Registry-independent relation descriptor produced immediately after model
11
+ * construction.
12
+ *
13
+ * This is the handoff object between relation authoring and relation
14
+ * resolution. It preserves field-authored relation intent in a normalized form
15
+ * without yet assigning public reverse names or resolved graph edges.
16
+ */
17
+ export interface NormalizedRelationStorageDescriptor {
18
+ edgeId: string;
19
+ sourceModelKey: string;
20
+ sourceSchemaFieldKey: string;
21
+ targetRef: ModelRef;
22
+ origin: NormalizedRelationOrigin;
23
+ localFieldName: string;
24
+ dbColumnName: string;
25
+ referencedTargetColumn?: string;
26
+ onDelete?: DeleteReferentialAction;
27
+ onUpdate?: UpdateReferentialAction;
28
+ unique?: boolean;
29
+ explicitForwardName?: string;
30
+ explicitReverseName?: string;
31
+ namingHint: string;
32
+ throughModelRef?: ModelRef;
33
+ throughSourceFieldName?: string;
34
+ throughTargetFieldName?: string;
35
+ provenance: 'field-decorator';
36
+ }
@@ -0,0 +1,19 @@
1
+ import type { RelationDef } from '../../domain/index';
2
+ /**
3
+ * Public authoring DSL for model-level named relations.
4
+ *
5
+ * This is the first stage of the relations subdomain. Application code uses it
6
+ * inside `relations: (r) => ({ ... })` to declare stable relation names and
7
+ * resolve ambiguity that field decorators alone cannot express.
8
+ *
9
+ * Later internal stages normalize these authored definitions and combine them
10
+ * with field-authored relation metadata to build the resolved relation graph.
11
+ */
12
+ export declare class RelationBuilder {
13
+ /** Declare a one-to-many relation from this model to `target`. */
14
+ hasMany(target: string, foreignKey: string): RelationDef;
15
+ /** Declare an owning relation to a parent model. */
16
+ belongsTo(target: string, foreignKey: string, localKey?: string): RelationDef;
17
+ /** Declare a one-to-one relation from this model to `target`. */
18
+ hasOne(target: string, foreignKey: string): RelationDef;
19
+ }
@@ -0,0 +1,30 @@
1
+ import { z } from 'zod';
2
+ import type { NormalizedRelationStorageDescriptor } from './NormalizedRelationStorageDescriptor';
3
+ /**
4
+ * Normalizes field-authored relation declarations from a model schema into the
5
+ * shared descriptor shape consumed by storage and relation finalization.
6
+ *
7
+ * This is the normalization stage of the relations subdomain. It sits between
8
+ * authoring and resolution:
9
+ *
10
+ * - authoring: decorators attach relation intent to schema fields
11
+ * - normalization: this class converts that intent into a registry-independent
12
+ * descriptor shape
13
+ * - resolution: the graph builder combines those descriptors with finalized
14
+ * storage artifacts and explicit relation names
15
+ */
16
+ export declare class RelationDescriptorNormalizer {
17
+ private readonly sourceModelKey;
18
+ private readonly schema;
19
+ constructor(sourceModelKey: string, schema: z.ZodObject<z.ZodRawShape>);
20
+ static normalize(sourceModelKey: string, schema: z.ZodObject<z.ZodRawShape>): readonly NormalizedRelationStorageDescriptor[];
21
+ /**
22
+ * Run the field-authored relation normalization pipeline for one model
23
+ * schema and emit descriptors that later relation stages can resolve.
24
+ */
25
+ normalize(): readonly NormalizedRelationStorageDescriptor[];
26
+ private collectRelationCandidates;
27
+ private normalizeCandidate;
28
+ private buildEdgeId;
29
+ private deriveNamingHint;
30
+ }
@@ -0,0 +1,48 @@
1
+ export declare const INTERNAL_RELATION_PUBLIC_KIND: {
2
+ readonly BELONGS_TO: "belongsTo";
3
+ readonly HAS_ONE: "hasOne";
4
+ readonly HAS_MANY: "hasMany";
5
+ readonly MANY_TO_MANY: "manyToMany";
6
+ };
7
+ export declare const INTERNAL_RELATION_STORAGE_STRATEGY: {
8
+ readonly REFERENCE: "reference";
9
+ readonly REVERSE_REFERENCE: "reverse_reference";
10
+ readonly MANY_TO_MANY: "many_to_many";
11
+ };
12
+ export declare const INTERNAL_RELATION_CARDINALITY: {
13
+ readonly SINGLE: "single";
14
+ readonly MANY: "many";
15
+ };
16
+ export declare const INTERNAL_RELATION_PROVENANCE: {
17
+ readonly FIELD_DECORATOR: "field-decorator";
18
+ readonly RELATIONS_API: "relations-api";
19
+ readonly SYNTHESIZED_REVERSE: "synthesized-reverse";
20
+ };
21
+ export type RelationPublicKind = (typeof INTERNAL_RELATION_PUBLIC_KIND)[keyof typeof INTERNAL_RELATION_PUBLIC_KIND];
22
+ export type RelationStorageStrategy = (typeof INTERNAL_RELATION_STORAGE_STRATEGY)[keyof typeof INTERNAL_RELATION_STORAGE_STRATEGY];
23
+ export type RelationCardinality = (typeof INTERNAL_RELATION_CARDINALITY)[keyof typeof INTERNAL_RELATION_CARDINALITY];
24
+ export type RelationProvenance = (typeof INTERNAL_RELATION_PROVENANCE)[keyof typeof INTERNAL_RELATION_PROVENANCE];
25
+ /**
26
+ * Author-time relation intent after target resolution but before full graph
27
+ * pairing and naming.
28
+ *
29
+ * This type is the conceptual bridge between normalized descriptors and the
30
+ * fully resolved graph. It exists so the relations subdomain has a stable
31
+ * vocabulary for relation kinds, storage strategies, and provenance as the
32
+ * pipeline becomes more sophisticated.
33
+ */
34
+ export interface RelationSpec {
35
+ edgeId: string;
36
+ sourceModelKey: string;
37
+ sourceSchemaFieldKey?: string;
38
+ targetModelKey: string;
39
+ kind: RelationPublicKind;
40
+ storageStrategy: RelationStorageStrategy;
41
+ localFieldName?: string;
42
+ targetFieldName?: string;
43
+ nameHint?: string;
44
+ throughModelKey?: string;
45
+ throughSourceFieldName?: string;
46
+ throughTargetFieldName?: string;
47
+ provenance: RelationProvenance;
48
+ }
@@ -0,0 +1,43 @@
1
+ import type { RelationCardinality, RelationProvenance, RelationStorageStrategy, RelationPublicKind } from './RelationSpec';
2
+ /**
3
+ * Fully resolved relation edge published by the registry after storage
4
+ * artifacts are finalized.
5
+ *
6
+ * This is the resolution-stage shape consumed by ORM-facing relation metadata.
7
+ * Each descriptor has final naming, cardinality, key mapping, and capability
8
+ * flags that describe whether the edge is currently migratable, queryable, and
9
+ * hydratable.
10
+ */
11
+ export interface ResolvedRelationDescriptor {
12
+ edgeId: string;
13
+ sourceModelKey: string;
14
+ targetModelKey: string;
15
+ name: string;
16
+ inverseEdgeId?: string;
17
+ kind: RelationPublicKind;
18
+ storageStrategy: RelationStorageStrategy;
19
+ cardinality: RelationCardinality;
20
+ localFieldName?: string;
21
+ targetFieldName?: string;
22
+ capabilities: {
23
+ migratable: boolean;
24
+ queryable: boolean;
25
+ hydratable: boolean;
26
+ };
27
+ provenance: RelationProvenance;
28
+ alias: string;
29
+ ambiguity?: string;
30
+ }
31
+ /**
32
+ * Registry-scoped relation graph built from normalized relation descriptors,
33
+ * explicit relation names, and finalized storage artifacts.
34
+ *
35
+ * This is the canonical resolved relation view for query planning and future
36
+ * hydration work. It is versioned because relation resolution is scoped to a
37
+ * specific registry snapshot.
38
+ */
39
+ export interface ResolvedRelationGraph {
40
+ version: number;
41
+ byModel: ReadonlyMap<string, ReadonlyMap<string, ResolvedRelationDescriptor>>;
42
+ byEdgeId: ReadonlyMap<string, ResolvedRelationDescriptor>;
43
+ }