Persistable.ts
Persistable.ts overview
Section titled “Persistable.ts overview”Describes request values whose results can be persisted.
A Persistable request has a primary key and schemas for its success and
error results. Persistence and PersistedCache use that information to
store the request’s Exit value and restore it later from a backing store.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”accessors
Section titled “accessors”exitSchema
Section titled “exitSchema”Returns the cached Exit schema for a persistable request’s success and
error schemas.
Signature
declare const exitSchema: <A extends Schema.Constraint, E extends Schema.Constraint>( self: Persistable<A, E>) => Schema.Exit<A, E, Schema.Defect>Since v4.0.0
constructors
Section titled “constructors”Creates request classes that implement Persistable and Request.Request.
Details
The generated class stores the supplied tag, derives its primary key from the payload, and carries schemas for persisted success and error exits.
Signature
declare const Class: < Config extends { payload: Record<string, unknown>; requires?: any; requestError?: any } = { payload: {} }>() => < const Tag extends string, A extends Schema.Constraint = Schema.Void, E extends Schema.Constraint = Schema.Never>( tag: Tag, options: { readonly primaryKey: (payload: Config["payload"]) => string readonly success?: A | undefined readonly error?: E | undefined }) => new ( args: Types.EqualsWith< Config["payload"], {}, void, { readonly [P in keyof Config["payload"] as P extends "_tag" ? never : P]: Config["payload"][P] } >) => { readonly _tag: Tag } & { readonly [K in keyof Config["payload"]]: Config["payload"][K] } & Persistable<A, E> & Request.Request< A["Type"], E["Type"] | ("requestError" extends keyof Config ? Config["requestError"] : PersistenceError | Schema.SchemaError), | A["DecodingServices"] | A["EncodingServices"] | E["DecodingServices"] | E["EncodingServices"] | ("requires" extends keyof Config ? Config["requires"] : never) >Since v4.0.0
models
Section titled “models”Any (type alias)
Section titled “Any (type alias)”Any persistable request regardless of its success and error schemas.
Signature
type Any = Persistable<Schema.Constraint, Schema.Constraint>Since v4.0.0
DecodingServices (type alias)
Section titled “DecodingServices (type alias)”Services required to decode a persisted success or error value for the request.
Signature
type DecodingServices<A> = | A["~effect/persistence/Persistable"]["success"]["DecodingServices"] | A["~effect/persistence/Persistable"]["error"]["DecodingServices"]Since v4.0.0
EncodingServices (type alias)
Section titled “EncodingServices (type alias)”Services required to encode a success or error value for persistence.
Signature
type EncodingServices<A> = | A["~effect/persistence/Persistable"]["success"]["EncodingServices"] | A["~effect/persistence/Persistable"]["error"]["EncodingServices"]Since v4.0.0
Error (type alias)
Section titled “Error (type alias)”Extracts the error value type from a persistable request.
Signature
type Error<A> = A["~effect/persistence/Persistable"]["error"]["Type"]Since v4.0.0
ErrorSchema (type alias)
Section titled “ErrorSchema (type alias)”Extracts the error schema from a persistable request.
Signature
type ErrorSchema<A> = A["~effect/persistence/Persistable"]["error"]Since v4.0.0
Persistable (interface)
Section titled “Persistable (interface)”A primary-keyed request value whose success and error results can be serialized for persistence.
Signature
export interface Persistable<A extends Schema.Constraint, E extends Schema.Constraint> extends PrimaryKey.PrimaryKey { readonly [symbol]: { readonly success: A readonly error: E }}Since v4.0.0
Services (type alias)
Section titled “Services (type alias)”All schema services required to encode and decode a persistable request result.
Signature
type Services<A> = | A["~effect/persistence/Persistable"]["success"]["DecodingServices"] | A["~effect/persistence/Persistable"]["success"]["EncodingServices"] | A["~effect/persistence/Persistable"]["error"]["DecodingServices"] | A["~effect/persistence/Persistable"]["error"]["EncodingServices"]Since v4.0.0
Success (type alias)
Section titled “Success (type alias)”Extracts the success value type from a persistable request.
Signature
type Success<A> = A["~effect/persistence/Persistable"]["success"]["Type"]Since v4.0.0
SuccessSchema (type alias)
Section titled “SuccessSchema (type alias)”Extracts the success schema from a persistable request.
Signature
type SuccessSchema<A> = A["~effect/persistence/Persistable"]["success"]Since v4.0.0
TimeToLiveFn (type alias)
Section titled “TimeToLiveFn (type alias)”Computes the time to live for a persisted result from the result Exit and
request value.
Signature
type TimeToLiveFn<K> = (exit: Exit.Exit<Success<K>, Error<K>>, request: K) => Duration.InputSince v4.0.0
serialization
Section titled “serialization”deserializeExit
Section titled “deserializeExit”Decodes a persisted value into an Exit for a persistable request using its
success and error schemas.
Signature
declare const deserializeExit: <A extends Schema.Constraint, E extends Schema.Constraint>( self: Persistable<A, E>, encoded: unknown) => Effect.Effect<Exit.Exit<A["Type"], E["Type"]>, Schema.SchemaError, A["DecodingServices"] | E["DecodingServices"]>Since v4.0.0
serializeExit
Section titled “serializeExit”Encodes an Exit for a persistable request using its success and error
schemas.
Signature
declare const serializeExit: <A extends Schema.Constraint, E extends Schema.Constraint>( self: Persistable<A, E>, exit: Exit.Exit<A["Type"], E["Type"]>) => Effect.Effect<unknown, Schema.SchemaError, A["EncodingServices"] | E["EncodingServices"]>Since v4.0.0
symbols
Section titled “symbols”symbol
Section titled “symbol”Defines the property key used to attach success and error schemas to persistable requests.
When to use
Use to implement persistable request values by attaching success and error schemas at this property key.
Signature
declare const symbol: "~effect/persistence/Persistable"Since v4.0.0