import { Constructor } from '@spinajs/di'; import { IIdentityMap } from './interfaces.js'; import type { ModelBase } from './model.js'; /** * Renders a primary-key value as a Map key. * * Type-tagged so `1` and `'1'` never collide — a string key column and an integer key column * on two different models could otherwise alias each other through a shared cache. Returns * `null` for an absent key: a model with no primary key cannot be identified and is never * registered. * * A composite key arrives as a tuple ( that is what `ModelBase.PrimaryKeyValue` returns for a * multi-column key ). Its parts are rendered individually and length-prefixed, because * `String([1, 2])` and `String(['1,2'])` are both `"1,2"`. A tuple with any part missing has * no identity at all, so it renders as `null` — the same answer as a missing scalar key. * * A one-element tuple renders exactly like the bare scalar: the ORM reads a single-column key * as a scalar everywhere, and both spellings must reach the same entry. * * @param pk - primary key value: a scalar, or a tuple in key order */ export declare function identityKey(pk: unknown): string | null; /** * Maps `(table, primary key) -> instance` for the duration of one `save()` graph walk, or of * one transaction when several saves run inside it ( overview decision D7 ). * * Its only job is to guarantee that a row reached through two relation paths produces one * subject rather than two conflicting ones. It is **not** a cache: nothing outside a * `save()` consults it, it is discarded when the transaction ends, and queries behave * exactly as they did before. * * **Keyed by table name, not by constructor.** A row's identity is the table it lives in plus * its key — that is the definition `SubjectBuilder.buildOrphans` has always used, for the * reason it records there: a `@DiscriminationMap` produces several constructors for one * table, and a subclass instance is still the same row. Keying here by constructor made the * two disagree, so the same row reached once as its base class and once as its discriminated * subclass produced two entries and two conflicting subjects for one row. * * Table names are unique within the map's scope because `UnitOfWork.save()` refuses to span * connections, so the A9 concerns that ruled out CLASS NAME keys — minification, and two * connections declaring the same class name — do not apply to table names here. A table name * is data from the schema, not a symbol the bundler may rewrite. */ export declare class IdentityMap implements IIdentityMap { private _entries; private _size; get Size(): number; get(model: Constructor, pk: unknown): ModelBase | undefined; has(model: Constructor, pk: unknown): boolean; /** * Registers `model` and returns the canonical instance for its identity — the one already * registered if there is one, otherwise `model` itself. A model with no primary key is * returned unchanged and not registered: it has no identity yet. * * @param model - model to canonicalize */ add(model: ModelBase): ModelBase; clear(): void; } //# sourceMappingURL=identity-map.d.ts.map