import type { EntityDefinition, EntityRegistry, L2CacheAdapter, MaybePromise, ModeEnricherHook, Store, StoreContext, StoreLogger, StoreLoggerAdapter, StoreReadOptions, StoreRecord, StoreResult, SubEntityRegistry, StoreWhere } from "../../types.js"; import type { StoreRuntimeSqlite, StoreRuntimeSqliteOptions } from "./sqlite/types.js"; export type RuntimeEntityRegistry = Record; export interface RuntimeEntityDefinition extends Omit { required?: readonly string[]; private?: Record; storage?: string; modes?: Record; [key: string]: unknown; } export interface RuntimeEntityModeDefinition { name?: string; enrich?: string; hooks?: Record | readonly string[]; privateFields?: string[]; metadata?: Record; select?(record: StoreRecord): StoreRecord; with?: RuntimeHydrationMap; [key: string]: unknown; } export type RuntimeHydrationMap = Record; export type RuntimeHydrationDeclaration = RuntimeRelationHydration | RuntimeCountHydration | RuntimeComputedHydration; export interface RuntimeRelationHydration { type: "relation"; entity: string; id: string; mode?: string; assign: string; when?: RuntimeBootCondition; } export interface RuntimeCountHydration { type: "count"; entity: string; foreignKey: string; localKey: string; assign: Record; set?: readonly RuntimeHydrationSet[]; } export interface RuntimeHydrationSet { field: string; value: unknown; when?: RuntimeBootCondition; } export interface RuntimeComputedHydration { type: "computed"; compute(record: StoreRecord, api: RuntimeHydrationApi): MaybePromise>; } export interface RuntimeHydrationApi { context: StoreContext; readAll(entity: string, context: StoreContext, options?: StoreReadOptions): Promise>; readById(entity: string, id: string, context: StoreContext, options?: StoreReadOptions): Promise>; url(record: StoreRecord): string; } export interface StoreRuntimeCreateOptions { entities: TRegistry; postgres?: StoreRuntimePostgresOptions; sqlite?: StoreRuntimeSqliteOptions; modes?: StoreRuntimeModeOptions; boot?: StoreRuntimeBootOptions; memo?: StoreRuntimeMemoOptions; events?: StoreRuntimeEvents; subEntities?: SubEntityRegistry | RuntimeProviderSubEntityRegistry; logger?: StoreLogger; loggerAdapter?: StoreLoggerAdapter; } export interface StoreRuntimePostgresOptions { databaseUrl?: string; schema?: string; pool?: StoreRuntimePostgresPoolOptions; client?: RuntimePostgresClient; indexes?: readonly RuntimePostgresIndex[]; migrations?: readonly RuntimePostgresMigration[]; slowQueryMs?: number; logOperations?: boolean; logSql?: boolean; resultMode?: "throw" | "envelope"; logger?: StoreLogger; metrics?(event: RuntimePostgresMetricsEvent): MaybePromise; } export interface StoreRuntimePostgresPoolOptions { max?: number; idleTimeoutMs?: number; connectionTimeoutMs?: number; statementTimeoutMs?: number; } export interface RuntimePostgresClient { query>(sql: string, params?: readonly unknown[]): Promise<{ rows: T[]; }>; connect?(): Promise; on?(event: "error", handler: (error: unknown) => void): void; idleCount?: number; totalCount?: number; waitingCount?: number; } export interface RuntimePostgresMetricsEvent { elapsedMs: number; operation?: string; name?: string; success: boolean; rowCount: number; } export interface RuntimePostgresIndex { table: string; name?: string; expression: string; method?: "btree" | "gin"; } export type RuntimePostgresMigration = (api: RuntimePostgresMigrationApi) => MaybePromise; export interface RuntimePostgresMigrationApi { query(sql: string, params?: readonly unknown[]): Promise>; schema: string; } export interface StoreRuntimeModeOptions { hookRoot?: URL; hookFileConvention?: "entity/with/name" | "entity/name" | string; legacyHookAdapter?: RuntimeLegacyHookAdapter; } export type RuntimeLegacyHookAdapter = (input: { entity: string; hook: string; mode: string; }) => MaybePromise; export interface StoreRuntimeBootOptions { fixes?: readonly RuntimeBootFix[]; rewrites?: RuntimeRewriteRegistry; followUps?: RuntimeFollowUpRegistry; context?: StoreContext; environment?: { developerMode?: boolean; splitDev?: boolean; [key: string]: unknown; }; onResult?(result: RuntimeBootResult): MaybePromise; developerMode?: boolean; splitDev?: boolean; } export interface RuntimeBootFix { entity: string; actions: readonly RuntimeBootAction[]; context?: StoreContext; } export interface RuntimeBootAction { if?: RuntimeBootCondition; if_all?: readonly RuntimeBootCondition[]; set?: StoreWhere; set_if_missing?: StoreWhere; unset?: readonly string[]; rewrite?: string; after?: readonly RuntimeFollowUpConfig[]; run_after_on_match?: boolean; skip_in_developer_mode?: boolean; skip_in_split_dev?: boolean; } export interface RuntimeBootCondition { field: string; equals?: unknown; equals_any?: readonly unknown[]; gt?: number; } export type RuntimeRewriteRegistry = Record | Record>; export type RuntimeRewrite = (record: StoreRecord, context: RuntimeBootActionContext) => MaybePromise; export interface RuntimeBootActionContext { entity: string; context: StoreContext; config: RuntimeBootAction; } export interface RuntimeFollowUpConfig { call: string; config?: StoreWhere; } export type RuntimeFollowUpRegistry = Record; export type RuntimeFollowUp = (input: { call: string; entity: string; record: StoreRecord; config?: StoreWhere; }) => MaybePromise; export interface RuntimeBootResult { changedCount: number; entities: Record; queuedFollowUps: RuntimeQueuedFollowUp[]; followUpCount: number; followUpsRunCount: number; followUps: RuntimeBootFollowUpOutcome[]; failures: RuntimeBootFailure[]; skipped: RuntimeBootSkipped[]; } export interface RuntimeBootFollowUpOutcome { call: string; entity: string; recordId?: string; skipped: boolean; ok: boolean; result?: unknown; message?: string; error_code?: string; error?: boolean; noop?: boolean; status?: number; data?: unknown; details?: unknown; meta?: Record; } export interface RuntimeBootEntityResult { scanned: number; changed: number; } export interface RuntimeQueuedFollowUp { entity: string; recordId: string; record?: StoreRecord; call: string; config?: StoreWhere; } export interface RuntimeBootFailure { entity: string; id?: string; message: string; } export interface RuntimeBootSkipped { entity: string; reason: string; } export interface StoreRuntimeEvents { onWrite?(event: StoreRuntimeWriteEvent): MaybePromise; } export interface StoreRuntimeWriteEvent { entity: string; context: StoreContext; record?: StoreRecord; operation: "put" | "by" | "remove" | "removeMany"; } export interface StoreRuntimeMemoOptions { redis?: RuntimeRemoteInvalidationAdapter; l1?: false | RuntimeL1MemoOptions; l2?: L2CacheAdapter | RuntimeJsonMemoAdapter; ignoredKeys?: readonly string[]; invalidationTtlMs?: number; } export interface RuntimeL1MemoOptions { maxEntries?: number; ttlMs?: number; } export interface RuntimeRemoteInvalidationAdapter { publish(channel: string, message: string): MaybePromise; subscribe?(channel: string, handler: (message: string) => void): MaybePromise; } export interface RuntimeRedisMemoAdapterInput { getJson(key: string): MaybePromise; setJson(key: string, value: T, ttlMs?: number): MaybePromise; del?(key: string): MaybePromise; incr?(key: string): MaybePromise; publishJson?(channel: string, payload: unknown): MaybePromise; subscribeJson?(channel: string, handler: (payload: unknown) => void): MaybePromise; } export interface RuntimeJsonMemoAdapter extends L2CacheAdapter, RuntimeRemoteInvalidationAdapter { } export interface StoreRuntimeMemo { get(key: string): Promise; set(key: string, value: T, options?: { ttlMs?: number; entity?: string; }): Promise; run(key: string, load: () => MaybePromise, options?: { ttlMs?: number; entity?: string; }): Promise; invalidateEntity(entity: string): Promise; inspectRead(key: string, entity?: string): RuntimeMemoInspection; keyForRead(input: RuntimeMemoReadKeyInput): string; entityVersion(entity: string): number; } export interface RuntimeMemoInspection { enabled: boolean; cached: boolean; inflight: boolean; invalidated: boolean; invalidatedAt: string; invalidatedVersion: number; hit: "l1" | "l2" | "miss"; key: string; version: number; } export interface RuntimeMemoReadKeyInput { entity: string; operation: string; mode?: string; context?: StoreContext; where?: StoreWhere; input?: unknown; options?: StoreWhere; } export interface StoreRuntimePostgres { query>(sql: string, params?: readonly unknown[], options?: RuntimePostgresQueryOptions): Promise>; init(): Promise; } export type RuntimePostgresQueryResult> = { ok?: true; rows: T[]; rowCount?: number; } | { ok: false; error: true; error_code: string; message: string; rows: []; rowCount: 0; }; export interface RuntimePostgresQueryOptions { operation?: "read" | "write" | "ddl" | "migration"; name?: string; allowLiterals?: boolean; } export interface StoreRuntimeFacade extends Pick { onBoot(): Promise; postgres: StoreRuntimePostgres; sqlite: StoreRuntimeSqlite; memo: StoreRuntimeMemo; } export type RuntimeProviderSubEntityRegistry = Record; export interface RuntimeProviderSubEntityDefinition { kind: "provider"; validateContext?(context: StoreContext): StoreResult | { ok: true; ctx?: StoreContext; } | null | undefined; list?(context: StoreContext, options: StoreReadOptions, api: RuntimeProviderSubEntityApi): MaybePromise; by?(where: StoreWhere, context: StoreContext, options: StoreReadOptions, api: RuntimeProviderSubEntityApi): MaybePromise; count?(context: StoreContext, options: StoreReadOptions, api: RuntimeProviderSubEntityApi): MaybePromise; } export interface RuntimeProviderSubEntityApi { readAll(entity: string, context: StoreContext, options?: StoreReadOptions): Promise>; readById(entity: string, id: string, context: StoreContext, options?: StoreReadOptions): Promise>; recorded_at: string; } export interface NormalizedRuntimeConfig { entities: EntityRegistry; } //# sourceMappingURL=types.d.ts.map