import type { z } from 'zod/v4'; import type { Table } from '../db/types.js'; import type { InferSelect, InferFieldOutput } from './brand.js'; import type { AnyPgColumn, PgTable } from '../query/pg-core/index.js'; import type { InsertProjection, SelectProjection, UpdateProjection } from './projections.js'; export type FieldKind = 'uuid' | 'text' | 'integer' | 'serial' | 'bigint' | 'boolean' | 'timestamp' | 'date' | 'enum' | 'jsonb' | 'decimal' | 'money' | 'pgLsn' | 'custom'; export interface FieldMeta { readonly kind: FieldKind; readonly nullable: boolean; readonly hasDefault: boolean; readonly defaultValue?: unknown; readonly primaryKey: boolean; readonly defaultRandom: boolean; readonly unique: boolean; readonly readOnly: boolean; readonly tenant: boolean; /** * Whether this field may be captured into a trace step's input snapshot. * Fail-closed: fields are trace-unsafe unless `.traceSafe()` opts them in, * so a new field is never captured by accident. */ readonly traceSafe: boolean; readonly brand?: string; readonly reference?: { /** * Eager DefinedTable, or a thunk returning one. The thunk form lets a * field reference its own table (self-reference) or a table defined later * in the same import cycle (forward-reference) — the thunk is only * resolved at table build / validation time, after the cycle has settled. */ readonly definition: DomainDefinition | (() => DomainDefinition); readonly field: string; /** * When `false`, the brand and the validator's brand-reuse check inherit * from the referenced field, but no FK constraint is emitted in the * generated DDL. Used for cross-partition references where an enforced * FK would prevent independent partition lifecycle (e.g. `audit_record` * keeping `traceId` after the trace partition is dropped). Default true. */ readonly enforced?: boolean; }; readonly min?: number; readonly max?: number; readonly autoManaged: boolean; readonly email: boolean; readonly url: boolean; readonly regex?: RegExp; readonly precision?: { readonly p: number; readonly s: number; }; readonly enumValues?: readonly string[]; readonly jsonbShape?: z.ZodType; readonly serializedAs?: 'string'; readonly customColumn?: unknown; readonly customValidator?: z.ZodType; } /** * Phantom flags tracked at the type level so insert/select/update projection * types can omit auto-managed columns, mark primary-key+defaulted columns as * optional, etc. The runtime reads from `_meta`; `_flags` exists only for the * type system. */ export interface FieldFlags { readonly nullable?: boolean; readonly hasDefault?: boolean; readonly primaryKey?: boolean; readonly defaultRandom?: boolean; readonly autoManaged?: boolean; readonly readOnly?: boolean; readonly serial?: boolean; } /** A field in a domain definition — carries runtime metadata and phantom output/flag types. */ export interface FieldDescriptor { readonly _meta: FieldMeta; readonly _output?: TOutput; readonly _flags?: TFlags; } type AnyFieldDescriptor = FieldDescriptor; /** Constraint alias for generic bounds — safe under exactOptionalPropertyTypes. */ export type FieldRecord = Record; /** Referential action for a foreign key on UPDATE / DELETE. */ export type ForeignKeyAction = 'cascade' | 'restrict' | 'no action' | 'set null' | 'set default'; /** A multi-column foreign key — the only way to reference a partitioned table's composite key. */ export interface CompositeForeignKey { /** Local field keys forming the key, in order. */ readonly columns: readonly string[]; readonly references: { /** * Eager DefinedTable or a thunk returning one. The thunk form lets a * composite FK target a table from the same import cycle (e.g. * `trace_step` referencing `trace` where both modules import each other * via field-level thunked references). */ readonly definition: DefinedTable | (() => DefinedTable); /** Foreign field keys, positionally matched to `columns`. */ readonly columns: readonly string[]; }; readonly onDelete?: ForeignKeyAction; readonly onUpdate?: ForeignKeyAction; } /** Resolves a possibly-lazy definition reference to its concrete DefinedTable. */ export declare function resolveDefinitionRef>(ref: T | (() => T)): T; /** Declares a table as RANGE-partitioned. The partition column must be part of the primary key. */ export interface PartitionSpec { readonly strategy: 'range'; /** Field key of the partition column. */ readonly column: string; } /** Options for pipe.define() — database affinity, virtual mode, custom indexes, keys, partitioning. */ export interface DefineOptions { readonly database?: string; readonly virtual?: boolean; readonly indexes?: (columns: Record) => Record; /** Composite primary key by field key. Mutually exclusive with field-level .primaryKey(). */ readonly primaryKey?: readonly string[]; /** Multi-column foreign keys. Single-column FKs use field-level .references(). */ readonly foreignKeys?: readonly CompositeForeignKey[]; /** Marks the table RANGE-partitioned. Partitions are managed outside the migration. */ readonly partitionBy?: PartitionSpec; } /** Column type projected from a FieldDescriptor — carries the right data type for Drizzle operators. */ export type FieldColumn = AnyPgColumn<{ data: NonNullable>; notNull: null extends InferFieldOutput ? false : true; }>; /** Maps field definitions to typed Drizzle column references. */ export type ProjectedColumns = { readonly [K in keyof TFields & string]: FieldColumn; }; /** Definition metadata and projection methods — the non-table surface of a DefinedTable. */ export interface DefinitionMethods { readonly $name: string; readonly $fields: TFields; readonly $options: DefineOptions; readonly $traits: readonly string[]; table(): Table; insertShape(): z.ZodType>; selectShape(): z.ZodType>; updateShape(): z.ZodType>; factory(): FactoryBuilder; effectiveDated(): DefinedTable; audited(): DefinedTable; softDeleted(): DefinedTable; readonly Select: InferSelect; readonly Insert: InsertProjection; readonly Update: UpdateProjection; } /** * A domain definition that IS a Drizzle PgTable — columns are direct properties, * usable in from(), eq(), orderBy(), joins, and partial selects. * * Created by pipe.define(). Metadata uses $ prefix ($name, $fields, $options, $traits) * to avoid collisions with column properties. * * The PgTable base is parameterized with ProjectedColumns so that Drizzle's * _['columns'] carries named, branded column types. Without this, select() * and returning() fall back to index-signature records. */ export type DefinedTable = PgTable<{ name: string; schema: string | undefined; columns: ProjectedColumns; dialect: 'pg'; }> & ProjectedColumns & DefinitionMethods; /** * @deprecated Use DefinedTable instead. DomainDefinition is kept for backward compatibility * with code that hasn't migrated to the direct-column-access API. */ export type DomainDefinition = DefinedTable; /** A named set of fields that can be applied to a domain definition via trait methods. */ export interface TraitDefinition { readonly name: string; readonly fields: FieldRecord; } export interface EffectiveDatedFields { readonly effectiveFrom: FieldDescriptor; readonly effectiveTo: FieldDescriptor; readonly version: FieldDescriptor; } export interface AuditedFields { readonly createdAt: FieldDescriptor; readonly updatedAt: FieldDescriptor; readonly createdBy: FieldDescriptor; readonly updatedBy: FieldDescriptor; } export interface SoftDeletedFields { readonly deletedAt: FieldDescriptor; readonly deletedBy: FieldDescriptor; } /** Test data factory — inserts rows and resolves FK dependencies automatically. */ export interface FactoryBuilder { create(overrides?: Partial>, options?: FactoryOptions): Promise>; createMany(count: number, overrides?: Partial> | ((index: number) => Partial>), options?: FactoryOptions): Promise[]>; } export interface FactoryOptions { readonly db?: unknown; readonly tenantId?: string; } export {}; //# sourceMappingURL=types.d.ts.map