/** * @license * Copyright 2025 Steven Roussey * SPDX-License-Identifier: Apache-2.0 */ import { DataPortSchemaObject, FromSchema, TypedArraySchemaOptions } from "@workglow/util/schema"; import type { ITabularMigrationApplier } from "../migrations"; import { BaseTabularStorage, ClientProvidedKeysOption } from "./BaseTabularStorage"; import { AnyTabularStorage, AutoGeneratedKeys, CoveringIndexQueryOptions, DeleteSearchCriteria, InsertEntity, ITabularStorage, QueryOptions, SearchCriteria, SimplifyPrimaryKey, TabularSubscribeOptions } from "./ITabularStorage"; export declare const CACHED_TABULAR_REPOSITORY: import("@workglow/util").ServiceToken; /** * A tabular repository wrapper that fronts a durable repository with an * in-memory cache (defaults to {@link InMemoryTabularStorage}). Durable is the * source of truth; the cache is repopulated lazily and on subscribe-driven * invalidation. */ export declare class CachedTabularStorage, Entity = FromSchema, PrimaryKey = SimplifyPrimaryKey, Value = Omit, InsertType extends InsertEntity> = InsertEntity>> extends BaseTabularStorage { readonly cache: ITabularStorage; private durable; private cacheInitialized; private cacheInitPromise; constructor(durable: ITabularStorage, cache?: ITabularStorage, schema?: Schema, primaryKeyNames?: PrimaryKeyNames, indexes?: readonly (keyof NoInfer | readonly (keyof NoInfer)[])[], clientProvidedKeys?: ClientProvidedKeysOption); private setupEventForwarding; /** Promise-based lock so concurrent callers share one initialization pass. */ private initializeCache; put(value: InsertType): Promise; putBulk(values: InsertType[]): Promise; get(key: PrimaryKey): Promise; delete(value: PrimaryKey | Entity): Promise; deleteAll(): Promise; getAll(options?: QueryOptions): Promise; size(): Promise; getOffsetPage(offset: number, limit: number): Promise; query(criteria: SearchCriteria, options?: QueryOptions): Promise; queryIndex(criteria: SearchCriteria, options: CoveringIndexQueryOptions): Promise[]>; deleteSearch(criteria: DeleteSearchCriteria): Promise; /** * Runs `fn` inside the durable store's transaction. The cache layer is * intentionally bypassed for the transaction's duration — coordinating * two-phase commit between the durable store and an in-memory cache is * out of scope, and callers asking for `withTransaction` are asking for * atomicity, which only the durable can provide. Inside `fn`, reads and * writes go straight through the durable's transaction handle. * * **`tx` identity:** the handle passed to `fn` is the durable store's * transaction proxy, not a `CachedTabularStorage`, despite the `(tx: this)` * type. Wrapper-specific members like `tx.cache` or `tx.invalidateCache()` * therefore type-check but throw at runtime — call them on the original * wrapper after `withTransaction` resolves instead. * * **Cache freshness on commit/rollback:** any rows the transaction touched * (committed inserts/updates/deletes, or rolled-back attempts that were * already mirrored into the cache via earlier non-tx writes) leave the * cache potentially out of step with durable. Invalidate unconditionally * after `fn` resolves so the next read repopulates the cache from durable * — over-invalidating on rollback is cheap and avoids leaking the * rollback boundary into the cache layer. Inheriting `BaseTabularStorage`'s * no-op default here would silently lose the rollback / atomicity guarantee, * since the default just runs `fn(this)` against the cached wrapper itself. */ withTransaction(fn: (tx: this) => Promise): Promise; invalidateCache(): Promise; refreshCache(): Promise; /** * Subscribes to durable changes (including external ones) and keeps the * cache in step before forwarding each change to `callback`. */ subscribeToChanges(callback: (change: any) => void, options?: TabularSubscribeOptions): () => void; /** * Forwards `setupDatabase` to the durable storage (which owns any * declared tabular migrations) and to the cache. Migrations themselves * are passed when constructing the inner durable storage; the wrapper * does not declare its own. */ setupDatabase(): Promise; /** * Delegates to the durable storage's applier so callers that use the * wrapper observe migrations declared on the inner durable layer. */ getMigrationApplier(): ITabularMigrationApplier | null; destroy(): void; } //# sourceMappingURL=CachedTabularStorage.d.ts.map