@mininjin/y-durable-objects
Version:
Cloudflare Workers Durable Objects for Yjs
49 lines (48 loc) • 2.17 kB
TypeScript
import { Doc } from "yjs";
export type YDurableObjectPersistenceOptions = {
flushBytes?: number;
flushUpdateClock?: number;
maxChunkBytes?: number;
};
export declare const DEFAULT_FLUSH_BYTES: number;
export declare const DEFAULT_CHUNK_MAX_BYTES: number;
export declare const DEFAULT_FLUSH_UPDATE_CLOCK = 300;
export declare const UPDATE_KEY_MAX_DIGITS = 6;
export declare const VERSION = "v1";
export declare const KEY_PREFIX: string;
export declare const BYTES_KEY: string;
declare const UPDATES_KEY = "updates";
declare const MERGED_KEY = "merged";
export declare const UPDATES_KEY_PREFIX: string;
export declare const MERGED_KEY_PREFIX: string;
export declare const createStorageKey: (type: typeof UPDATES_KEY | typeof MERGED_KEY, clock: number) => string;
/**
* @description YDurableObjectPersistence is a class that provides an interface to persist and retrieve Yjs documents in a Durable Object Transactional Storage.
*/
export declare class YDurableObjectPersistence {
private readonly ctx;
private readonly flushBytes;
private readonly flushUpdateClock;
private readonly maxChunkBytes;
constructor(ctx: DurableObjectState, options?: YDurableObjectPersistenceOptions);
private get storage();
/**
* @description Internally YDurableObjectPersistence stores incremental updates. This method merges all updates into several chunks. (The reason why updates are not merged into a single update is due to the size limit of the values in Transactional Storage.)
*/
flushDocument(): Promise<void>;
/**
* @description Create a Y.Doc instance with the data persisted in Durable Object Transactional Storage. Use this to temporarily create a Yjs document to sync changes or extract data.
* @returns the Yjs document
*/
getYDoc(): Promise<Doc>;
/**
* @description Store a single document update to the database. This method is used to store updates that are received from clients.
* @returns the clock of the update
*/
storeUpdate(update: Uint8Array): Promise<number>;
/**
* @description clear all updates from storage
*/
clear(): Promise<void>;
}
export {};