/** * Stores encoded results for `Persistable` requests. * * The `Persistence` service creates scoped stores keyed by each request's * `PrimaryKey`. Stores read and write schema-encoded `Exit` values with * optional TTLs, letting request workflows reuse expensive or idempotent results * across fibers, process restarts, or workers that share a backing store. * * @stability unstable * @since 4.0.0 */ import * as Arr from "../Array.ts"; import * as Clock from "../Clock.ts"; import * as Context from "../Context.ts"; import * as Duration from "../Duration.ts"; import * as Effect from "../Effect.ts"; import * as Exit from "../Exit.ts"; import * as Layer from "../Layer.ts"; import * as Schema from "../Schema.ts"; import type * as Scope from "../Scope.ts"; import * as SqlClient from "../sql/SqlClient.ts"; import * as KeyValueStore from "./KeyValueStore.ts"; import * as Persistable from "./Persistable.ts"; import * as Redis from "./Redis.ts"; declare const ErrorTypeId: "~effect/persistence/Persistence/PersistenceError"; declare const PersistenceError_base: Schema.Class; readonly message: Schema.String; readonly cause: Schema.optional; }>, import("../Cause.ts").YieldableError>; /** * Error raised by persistence and backing-store operations. * * @stability unstable * @category errors * @since 4.0.0 */ export declare class PersistenceError extends PersistenceError_base { /** * Marks this value as a persistence error for runtime guards. * * @stability unstable * @since 4.0.0 */ readonly [ErrorTypeId]: typeof ErrorTypeId; } declare const Persistence_base: Context.ServiceClass, key: Persistable.Any) => Duration.Input; }) => Effect.Effect; }>; /** * Service for creating scoped stores of persisted `Persistable` request * results. * * @stability unstable * @category services * @since 4.0.0 */ export declare class Persistence extends Persistence_base { } /** * Typed store for persisted `Exit` values keyed by `Persistable` requests. * * @stability unstable * @category models * @since 4.0.0 */ export interface PersistenceStore { readonly get: (key: Persistable.Persistable) => Effect.Effect | undefined, PersistenceError | Schema.SchemaError, A["DecodingServices"] | E["DecodingServices"]>; readonly getMany: (keys: Iterable>) => Effect.Effect | undefined>, PersistenceError | Schema.SchemaError, A["DecodingServices"] | E["DecodingServices"]>; readonly set: (key: Persistable.Persistable, value: Exit.Exit) => Effect.Effect; readonly setMany: (entries: Iterable, Exit.Exit]>) => Effect.Effect; readonly remove: (key: Persistable.Persistable) => Effect.Effect; readonly clear: Effect.Effect; } declare const BackingPersistence_base: Context.ServiceClass Effect.Effect; }>; /** * Service for creating raw backing stores for persistence store ids. * * @stability unstable * @category services * @since 4.0.0 */ export declare class BackingPersistence extends BackingPersistence_base { } /** * Raw persistence backing store for JSON-compatible objects with optional * TTLs. * * @stability unstable * @category services * @since 4.0.0 */ export interface BackingPersistenceStore { readonly get: (key: string) => Effect.Effect; readonly getMany: (keys: Arr.NonEmptyArray) => Effect.Effect, PersistenceError>; readonly set: (key: string, value: object, ttl: Duration.Duration | undefined) => Effect.Effect; readonly setMany: (entries: Arr.NonEmptyArray) => Effect.Effect; readonly remove: (key: string) => Effect.Effect; readonly clear: Effect.Effect; } /** * Provides `Persistence` from `BackingPersistence`. * * **Details** * * The layer serializes and deserializes `Persistable` exits, applies * per-entry TTLs, and skips writes whose TTL is zero or negative. * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layer: Layer.Layer; /** * Provides an in-memory `BackingPersistence` grouped by store id. * * **Details** * * Entries are process-local and expire according to their stored TTL. * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layerBackingMemory: Layer.Layer; /** * Provides SQL-backed persistence using one table per store id. * * **Details** * * Each table is created if needed and stores JSON-encoded values with optional * expiration timestamps. * * **Gotchas** * * Store ids are used directly in `effect_persistence_${storeId}` table names, * without encoding or collision detection. Choose ids whose full table names * are distinct under the database's identifier rules: * * - Do not use dots: they are interpreted as schema separators. * - Do not rely on case alone to distinguish stores: SQLite treats ASCII-case * variants such as `Users` and `users` as the same table. * - Stay within the database's identifier length limit, including the prefix. * PostgreSQL normally truncates identifiers to 63 bytes, leaving 44 bytes * for the store id. Ids sharing those first 44 bytes can alias the same table. * * Aliased stores share entries: writes can overwrite another store's values, * and clearing one clears the other. For arbitrary store ids, prefer * `layerBackingSql`, which stores ids as row values rather than table names. * * @see layerBackingSql * @stability unstable * @category layers * @since 4.0.0 */ export declare const layerBackingSqlMultiTable: Layer.Layer; /** * Provides SQL-backed persistence using a shared `effect_persistence` table. * * **Details** * * Rows are partitioned by `store_id` and store JSON-encoded values with * optional expiration timestamps. * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layerBackingSql: Layer.Layer; /** * Provides Redis-backed persistence. * * **Details** * * Each store id is used as a key prefix, values are JSON-encoded, and finite * TTLs are stored with Redis expiration. * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layerBackingRedis: Layer.Layer; /** * Provides `BackingPersistence` using a `KeyValueStore`. * * **Details** * * Each store id becomes a key prefix, and values are stored as JSON with * optional expiration timestamps. * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layerBackingKvs: Layer.Layer; /** * Provides `Persistence` backed by the current `KeyValueStore`. * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layerKvs: Layer.Layer; /** * Provides `Persistence` backed by process-local in-memory storage. * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layerMemory: Layer.Layer; /** * Provides `Persistence` backed by the current `Redis` service. * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layerRedis: Layer.Layer; /** * Provides `Persistence` backed by SQL with one table per store id. * * **Gotchas** * * Store ids become `effect_persistence_${storeId}` table names and must obey * the database's identifier rules. Avoid dots, case-only distinctions, and * names exceeding the database's identifier length limit (including the * prefix). Colliding names share data, including writes and clears. * Prefer `layerSql` for arbitrary store ids. * * @see layerBackingSqlMultiTable for database-specific store-id restrictions * @see layerSql * @stability unstable * @category layers * @since 4.0.0 */ export declare const layerSqlMultiTable: Layer.Layer; /** * Provides `Persistence` backed by SQL using a shared persistence table. * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layerSql: Layer.Layer; /** * Converts a TTL to an absolute expiration timestamp in milliseconds. * * **Details** * * Returns `null` for no TTL and uses `clock.currentTimeMillisUnsafe`, so it is * intended for backing-store internals. * * @stability unstable * @category converting * @since 4.0.0 */ export declare const unsafeTtlToExpires: (clock: Clock.Clock, ttl: Duration.Duration | undefined) => number | null; export {}; //# sourceMappingURL=Persistence.d.ts.map