import type { DefaultValue } from './defaults.js'; export type ColumnStorageType = 'bool' | 'int64' | 'float64' | 'timestamp' | 'date' | 'date64' | 'time64' | 'interval' | 'text' | 'bytes' | 'json' | 'embedding' | 'sparse' | 'decimal128' | 'uuid' | 'json_native' | 'array'; export type PkValue = string | bigint | (string | bigint | null)[]; export type ColumnApplicationType = ColumnStorageType; /** * Where dense embedding values for a column originate. * Mirrors kit-core / mongreldb-core `EmbeddingSource`. * Omitting means application-supplied vectors. Transactional generation * requires a process-local provider registered by the server or Rust Kit. */ export type EmbeddingSource = { kind: 'supplied_by_application'; } | { kind: 'local_model'; modelPath: string; modelId: string; } | { kind: 'configured_model'; providerId: string; modelId: string; modelVersion: string; } | { kind: 'generated_column'; provider: string; } | { kind: 'generated_column_spec'; spec: { providerId: string; modelId: string; modelVersion: string; sourceColumns: number[]; inputTemplate: string; dimension: number; normalization: 'none' | 'l2'; failurePolicy: 'abort_write'; }; }; export interface ColumnSpec { id: number; idExplicit?: boolean; name: TName; storageType: ColumnStorageType; applicationType: TApp; nullable: TNull; primaryKey: boolean; default: TDefault; generated: TGenerated; /** Vector dimension for an `embedding` column (required for ANN). */ embeddingDim?: number; /** * How embedding values are produced. Only for `storageType: 'embedding'`. * Omitted = application-supplied (engine default). */ embeddingSource?: EmbeddingSource; /** Encrypt this column at rest (requires an encrypted database). */ encrypted?: boolean; /** Encrypt but keep queryable via deterministic tokens. */ encryptedIndexable?: boolean; enumValues?: string[]; check?: (value: unknown) => boolean | string; min?: number; max?: number; minLength?: number; maxLength?: number; regex?: RegExp; } export interface IndexSpec { name: string; columns: string[]; unique: boolean; /** Index kind; defaults to `bitmap`. `fm` enables FM substring search so * `contains(col, needle)` pushes down to the engine instead of scanning. * `learned_range` builds a PGM zonemap that accelerates range predicates * (`gt`/`gte`/`lt`/`lte`) on numeric/timestamp columns. */ kind?: 'bitmap' | 'fm' | 'ann' | 'sparse' | 'minhash' | 'learned_range'; /** ANN representation and metric. Defaults to sign-bit Hamming. `product` * selects product quantization; the codebook parameters come from * `annPqNumSubvectors` (required) and `annPqBits` (default 8). */ annQuantization?: 'binary_sign' | 'dense' | 'product'; /** ANN graph/structure algorithm. Defaults to `hnsw`. Orthogonal to * `annQuantization` (the algorithm chooses how search walks the index; * the quantization chooses how vectors are represented). */ annAlgorithm?: 'hnsw' | 'diskann' | 'ivf'; /** Optional SQL predicate for a partial index. */ predicate?: string; annM?: number; annEfConstruction?: number; annEfSearch?: number; /** DiskANN max graph degree R. */ annDiskannR?: number; /** DiskANN build search-list size L. */ annDiskannL?: number; /** DiskANN query beam width. */ annDiskannBeamWidth?: number; /** DiskANN robust-prune alpha × 100 (120 = 1.2). */ annDiskannAlpha?: number; /** IVF inverted-list (centroid) count. */ annIvfNlist?: number; /** IVF probe count at query time. */ annIvfNprobe?: number; /** IVF k-means training sample cap. */ annIvfTrainingSamples?: number; /** Product-quantizer training sample cap. */ annPqTrainingSamples?: number; /** Product-quantizer deterministic training seed. */ annPqSeed?: number; /** Product-quantizer exact-rerank factor (0 disables). */ annPqRerankFactor?: number; /** Product-quantization sub-vector count (required when * `annQuantization: 'product'`). */ annPqNumSubvectors?: number; /** Product-quantization codebook bit width (default 8). */ annPqBits?: number; minhashPermutations?: number; minhashBands?: number; learnedRangeEpsilon?: number; } export interface ForeignKeySpec { name: string; columns: string[]; referencesTable: string; referencesColumns: string[]; onDelete: 'cascade' | 'set null' | 'restrict'; } export interface UniqueSpec { name: string; columns: string[]; } export interface CheckSpec { name: string; expr: (row: Record) => boolean | string; } export interface TableSpec { tableId: number; name: string; columns: TColumns; primaryKey: string[]; indexes: IndexSpec[]; foreignKeys: ForeignKeySpec[]; unique: UniqueSpec[]; checks: CheckSpec[]; /** * Look up a column spec by name. Use this for columns whose name shadows a * table property (e.g. a column literally named `name`), which are not * reachable as a direct `table.` accessor. */ column(name: string): ColumnSpec; } type ApplicationTypeMap = { bool: boolean; int64: bigint; float64: number; timestamp: string; date: string; date64: string; time64: string; interval: { months: number; days: number; nanos: number; }; decimal128: string; uuid: string; json_native: unknown; array: unknown[]; text: string; bytes: unknown; json: unknown; embedding: number[]; sparse: [number, number][]; }; type ApplicationType = ApplicationTypeMap[T]; export type Row = { [K in T['columns'][number] as K['name']]: K['nullable'] extends true ? ApplicationType | null : ApplicationType; }; type ColumnToDefaultName = C extends { name: infer N; nullable: infer Null; default: infer D; generated: infer G; } ? N extends string ? Null extends true ? never : D extends DefaultValue ? N : G extends 'uuid' | 'now' ? N : never : never : never; type ColumnsWithDefault = ColumnToDefaultName; type NullableColumnName = C extends { name: infer N; nullable: infer Null; } ? N extends string ? Null extends true ? N : never : never : never; type NullableColumns = NullableColumnName; type OptionalInsertColumns = Extract | ColumnsWithDefault, keyof Row>; export type Insert = Omit, ColumnsWithDefault | NullableColumns> & Partial, OptionalInsertColumns>>; export type Update = Partial>; export {}; //# sourceMappingURL=types.d.ts.map