EdgeAIG's picture
download
raw
9.16 kB
import * as Cause from "../../Cause.ts";
import * as Context from "../../Context.ts";
import * as Duration from "../../Duration.ts";
import * as Effect from "../../Effect.ts";
import * as Layer from "../../Layer.ts";
import * as Schema from "../../Schema.ts";
import * as Scope from "../../Scope.ts";
import * as SqlClient from "../sql/SqlClient.ts";
import type { SqlError } from "../sql/SqlError.ts";
import * as Redis from "./Redis.ts";
/**
* Runtime type identifier for `PersistedQueue` values.
*
* @category type IDs
* @since 4.0.0
*/
export declare const TypeId: TypeId;
/**
* Type-level identifier used to brand `PersistedQueue` values.
*
* @category type IDs
* @since 4.0.0
*/
export type TypeId = "~effect/persistence/PersistedQueue";
/**
* Persistent queue of schema-encoded values.
*
* **Details**
*
* `offer` enqueues values by id, and `take` processes one value at a time,
* marking it complete on success or retrying it until the maximum attempts is
* reached.
*
* @category models
* @since 4.0.0
*/
export interface PersistedQueue<in out A, out R = never> {
readonly [TypeId]: TypeId;
/**
* Adds an element to the queue and returns the id of the enqueued element.
*
* **Details**
*
* If an element with the same id already exists in the queue, it will not be
* added again.
*/
readonly offer: (value: A, options?: {
readonly id: string | undefined;
}) => Effect.Effect<string, PersistedQueueError | Schema.SchemaError, R>;
/**
* Takes an element from the queue, waiting until one is available when the
* queue is empty.
*
* **Details**
*
* If the returned effect succeeds, the element is marked as processed;
* otherwise it will be retried according to the provided options. By default,
* max attempts is set to 10.
*/
readonly take: <XA, XE, XR>(f: (value: A, metadata: {
readonly id: string;
readonly attempts: number;
}) => Effect.Effect<XA, XE, XR>, options?: {
readonly maxAttempts?: number | undefined;
}) => Effect.Effect<XA, XE | PersistedQueueError | Schema.SchemaError, R | XR>;
}
declare const PersistedQueueFactory_base: Context.ServiceClass<PersistedQueueFactory, "effect/persistence/PersistedQueue/PersistedQueueFactory", {
readonly make: <S extends Schema.Top>(options: {
readonly name: string;
readonly schema: S;
}) => Effect.Effect<PersistedQueue<S["Type"], S["EncodingServices"] | S["DecodingServices"]>>;
}>;
/**
* Service for constructing named `PersistedQueue` instances from schemas.
*
* @category services
* @since 4.0.0
*/
export declare class PersistedQueueFactory extends PersistedQueueFactory_base {
}
/**
* Accesses `PersistedQueueFactory` to create a named persisted queue for a
* schema.
*
* @category accessors
* @since 4.0.0
*/
export declare const make: <S extends Schema.Top>(options: {
readonly name: string;
readonly schema: S;
}) => Effect.Effect<PersistedQueue<S["Type"], S["EncodingServices"] | S["DecodingServices"]>, never, PersistedQueueFactory>;
/**
* Creates a `PersistedQueueFactory` from the current `PersistedQueueStore`.
*
* **Details**
*
* Values are encoded and decoded with the supplied schema, automatically
* assigned an id when needed, and acknowledged or retried according to the
* `take` handler's exit.
*
* @category constructors
* @since 4.0.0
*/
export declare const makeFactory: Effect.Effect<{
readonly make: <S extends Schema.Top>(options: {
readonly name: string;
readonly schema: S;
}) => Effect.Effect<PersistedQueue<S["Type"], S["EncodingServices"] | S["DecodingServices"]>>;
}, never, PersistedQueueStore>;
/**
* Provides `PersistedQueueFactory` using the current `PersistedQueueStore`.
*
* @category layers
* @since 4.0.0
*/
export declare const layer: Layer.Layer<PersistedQueueFactory, never, PersistedQueueStore>;
/**
* Runtime type identifier for `PersistedQueueError`.
*
* @category type IDs
* @since 4.0.0
*/
export declare const ErrorTypeId: ErrorTypeId;
/**
* Type-level identifier used to brand `PersistedQueueError` values.
*
* @category type IDs
* @since 4.0.0
*/
export type ErrorTypeId = "~@effect/experimental/PersistedQueue/PersistedQueueError";
declare const PersistedQueueError_base: Schema.Class<PersistedQueueError, Schema.Struct<{
readonly _tag: Schema.tag<"PersistedQueueError">;
readonly message: Schema.String;
readonly cause: Schema.optional<Schema.Defect>;
}>, Cause.YieldableError>;
/**
* Error raised by persisted queue store operations.
*
* @category errors
* @since 4.0.0
*/
export declare class PersistedQueueError extends PersistedQueueError_base {
/**
* Marks this value as a persisted queue error for runtime guards.
*
* @since 4.0.0
*/
readonly [ErrorTypeId]: ErrorTypeId;
}
declare const PersistedQueueStore_base: Context.ServiceClass<PersistedQueueStore, "effect/persistence/PersistedQueue/PersistedQueueStore", {
readonly offer: (options: {
readonly name: string;
readonly id: string;
readonly element: unknown;
readonly isCustomId: boolean;
}) => Effect.Effect<void, PersistedQueueError>;
readonly take: (options: {
readonly name: string;
readonly maxAttempts: number;
}) => Effect.Effect<{
readonly id: string;
readonly attempts: number;
readonly element: unknown;
}, PersistedQueueError, Scope.Scope>;
}>;
/**
* Defines the low-level backing store service used by `PersistedQueue`.
*
* **When to use**
*
* Use to provide the persistence backend that stores queued elements, scoped
* takes, retry attempts, and acknowledgements.
*
* **Details**
*
* The store persists offered elements and returns taken elements in a scope so
* the finalizer can complete or retry them based on the processing exit.
*
* @category store
* @since 4.0.0
*/
export declare class PersistedQueueStore extends PersistedQueueStore_base {
}
/**
* Provides an in-memory `PersistedQueueStore`.
*
* **Details**
*
* The store is process-local and volatile; failed takes are requeued until the
* configured maximum attempts is reached.
*
* @category store
* @since 4.0.0
*/
export declare const layerStoreMemory: Layer.Layer<PersistedQueueStore>;
/**
* Creates a Redis-backed `PersistedQueueStore`.
*
* **Details**
*
* The store uses Redis lists and hashes with worker locks, periodically
* refreshes locks while items are being processed, and moves exhausted items
* to a failed queue.
*
* @category store
* @since 4.0.0
*/
export declare const makeStoreRedis: (options?: {
readonly prefix?: string | undefined;
readonly pollInterval?: Duration.Input | undefined;
readonly lockRefreshInterval?: Duration.Input | undefined;
readonly lockExpiration?: Duration.Input | undefined;
} | undefined) => Effect.Effect<{
readonly offer: (options: {
readonly name: string;
readonly id: string;
readonly element: unknown;
readonly isCustomId: boolean;
}) => Effect.Effect<void, PersistedQueueError>;
readonly take: (options: {
readonly name: string;
readonly maxAttempts: number;
}) => Effect.Effect<{
readonly id: string;
readonly attempts: number;
readonly element: unknown;
}, PersistedQueueError, Scope.Scope>;
}, never, Scope.Scope | Redis.Redis>;
/**
* Provides a Redis-backed `PersistedQueueStore` using `makeStoreRedis`.
*
* @category store
* @since 4.0.0
*/
export declare const layerStoreRedis: (options?: {
readonly prefix?: string | undefined;
readonly pollInterval?: Duration.Input | undefined;
readonly lockRefreshInterval?: Duration.Input | undefined;
readonly lockExpiration?: Duration.Input | undefined;
} | undefined) => Layer.Layer<PersistedQueueStore, never, Redis.Redis>;
/**
* Creates a SQL-backed `PersistedQueueStore`.
*
* **Details**
*
* The store creates the queue table and indexes, acquires rows with
* per-worker locks, refreshes active locks while scoped takes are running, and
* retries or completes rows according to the processing exit.
*
* @category store
* @since 4.0.0
*/
export declare const makeStoreSql: (options?: {
readonly tableName?: string | undefined;
readonly pollInterval?: Duration.Input | undefined;
readonly lockRefreshInterval?: Duration.Input | undefined;
readonly lockExpiration?: Duration.Input | undefined;
} | undefined) => Effect.Effect<PersistedQueueStore["Service"], SqlError, SqlClient.SqlClient | Scope.Scope>;
/**
* Provides a SQL-backed `PersistedQueueStore` using `makeStoreSql`.
*
* @category store
* @since 4.0.0
*/
export declare const layerStoreSql: (options?: {
readonly tableName?: string | undefined;
readonly pollInterval?: Duration.Input | undefined;
readonly lockRefreshInterval?: Duration.Input | undefined;
readonly lockExpiration?: Duration.Input | undefined;
} | undefined) => Layer.Layer<PersistedQueueStore, SqlError, SqlClient.SqlClient>;
export {};
//# sourceMappingURL=PersistedQueue.d.ts.map

Xet Storage Details

Size:
9.16 kB
·
Xet hash:
46382ed04d9d54e31dc63eb3b228fa12bb11514db15e5d24b4197d892c5f1e83

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.