Skip to main content
Module

x/kvdex/mod.ts>KvDex

High-level abstraction layer for Deno KV 🦕📁
Go to Latest
class KvDex
import { KvDex } from "https://deno.land/x/kvdex@v0.29.0/mod.ts";

Constructors

new
KvDex(
kv: Deno.Kv,
schema: TSchema,
queueHandlers: Map<string, QueueMessageHandler<KvValue>[]>,
idempotentListener: () => Promise<void>,
)

Properties

private
idempotentListener: () => Promise<void>
private
kv: Deno.Kv
private
queueHandlers: Map<string, QueueMessageHandler<KvValue>[]>
private
schema: TSchema

Methods

atomic<TInput, TOutput extends KvValue>(selector: CollectionSelector<TSchema, TInput, TOutput>)

Initializes an atomic operation.

Takes a selector function as argument which is used to select an initial collection context.

Count all document entries in the KV store.

Does not count index entries or segmented entries as additional documents.

Does not count undelivered queue messages.

Delete all document entries in the KV store.

Delete an undelivered document entry by id from the database queue.

enqueue<T extends KvValue>(data: T, options?: EnqueueOptions)

Add data to the database queue to be delivered to the queue listener via db.listenQueue(). The data will only be received by queue listeners on the database queue and specified topic. The method takes an optional options argument that can be used to set a delivery delay and topic.

findUndelivered<T extends KvValue>(id: KvId, options?: FindOptions)

Find an undelivered document entry by id from the database queue.

listenQueue<T extends KvValue>(handler: QueueMessageHandler<T>, options?: QueueListenerOptions)

Listen for data from the database queue that was enqueued with db.enqueue(). Will only receive data that was enqueued to the database queue. Takes a handler function as argument.

loop<T1 extends KvValue>(fn: (msg: LoopMessage<Awaited<T1>>) => T1 | Promise<T1>, options?: LoopOptions<Awaited<T1>>)

Create a sequential loop built on queues.

Will repeat indefinitely if no exit condition is set.

There is an enforced minimum start delay of 1 second to ensure the queue listener is registered before the first delivery.

setInterval(fn: (msg: IntervalMessage) => unknown, options?: SetIntervalOptions)

Create an interval for a callback function to be invoked, built on queues.

Interval defaults to 1 hour if not set.

Will repeat indefinitely if no exit condition is set.

There is an enforced minimum start delay of 1 second to ensure the queue listener is registered before the first delivery.

Wipe all kvdex entries, including undelivered and history entries.