export function createComputePool(opts?: { poolSize?: number; }): ComputePool; export type ComputeTask = s.Unwrap | undefined; type: "mergeUpdates"; gc: boolean; updates: Uint8Array[]; } | { from?: number | undefined; to?: number | undefined; by?: string | undefined; contentIds?: Uint8Array | undefined; withCustomAttributions?: { k: string; v: string; }[] | null | undefined; type: "computePruneSet"; contentmapBin: Uint8Array; } | { type: "computeStateVector"; update: Uint8Array; } | { type: "changeset"; nongcDoc: Uint8Array; contentmapBin: Uint8Array; from: number | null; to: number | null; by: string; withCustomAttributions: { k: string; v: string; }[] | null; includeYdoc: boolean; includeDelta: boolean; includeAttributions: boolean; } | { contentIds?: Uint8Array | undefined; type: "activity"; nongcDoc: Uint8Array; contentmapBin: Uint8Array; from: number; to: number; by: string; withCustomAttributions: { k: string; v: string; }[] | null; includeCustomAttributions: boolean; includeDelta: boolean; includeYdoc: boolean; includeAttributions: boolean; limit: number; reverse: boolean; group: boolean; groupMaxGap: number; groupMaxDuration: number; } | { type: "patchYdoc"; update: Uint8Array; currentDoc: Uint8Array; userid: string; customAttributions: { k: string; v: string; }[]; } | { from?: number | undefined; to?: number | undefined; by?: string | undefined; contentIds?: Uint8Array | undefined; withCustomAttributions?: { k: string; v: string; }[] | null | undefined; type: "rollback"; nongcDoc: Uint8Array; contentmapBin: Uint8Array; userid: string; customAttributions: { k: string; v: string; }[]; }>>; declare class ComputePool { /** * @param {number} maxPoolSize */ constructor(maxPoolSize: number); maxPoolSize: number; /** * @type {Array} */ workers: Array; /** * @type {Array<{ task: ComputeTask, transferList: ArrayBuffer[], logContext: Object, resolve: (value: any) => void, reject: (reason: any) => void }>} */ queue: Array<{ task: ComputeTask; transferList: ArrayBuffer[]; logContext: { [x: string]: any; }; resolve: (value: any) => void; reject: (reason: any) => void; }>; /** * @param {ComputeTask} task * @param {Array} transferList * @param {Object} logContext * @returns {Promise} */ run(task: ComputeTask, transferList: Array, logContext: { [x: string]: any; }): Promise; /** * Merges updates synchronously if there are 0-1 updates or the total size * is <= 5kb. Otherwise offloads to a worker thread. When `gc` is `true`, * deleted content is garbage-collected. * * When `prune` (a serialized `IdSet`) is given, that content is * garbage-collected after merging (used to prune churned history). * * @param {boolean} gc * @param {Array>} updates * @param {Object} logContext * @param {Uint8Array} [prune] * @returns {Promise>} */ mergeUpdates(gc: boolean, updates: Array>, logContext?: { [x: string]: any; }, prune?: Uint8Array): Promise>; /** * Computes the prune set for a time/author/content range: the IDs that were * both inserted and deleted within the filtered range (`intersectSets` of the * in-range insertions and deletions). Returns the serialized `IdSet`, or * `null` if nothing matches. * * @param {object} opts * @param {Uint8Array} opts.contentmapBin * @param {number} [opts.from] * @param {number} [opts.to] * @param {string} [opts.by] * @param {Uint8Array} [opts.contentIds] * @param {Array<{k: string, v: string}>|null} [opts.withCustomAttributions] * @param {Object} [logContext] * @returns {Promise|null>} */ computePruneSet(opts: { contentmapBin: Uint8Array; from?: number | undefined; to?: number | undefined; by?: string | undefined; contentIds?: Uint8Array | undefined; withCustomAttributions?: { k: string; v: string; }[] | null | undefined; }, logContext?: { [x: string]: any; }): Promise | null>; /** * Computes the state vector from an encoded update. * * `encodeStateVectorFromUpdate` is a full linear scan of the update binary * (measured at ~30-40 MB/s), so it runs synchronously for updates < 512kb * (under ~15ms). Larger updates are offloaded to a worker. The buffer can't * be transferred (the caller reuses it for syncStep2), so the main thread * still pays a structured-clone copy on postMessage — but that copy is * ~32x cheaper than the scan (e.g. ~0.8ms vs ~25ms for a 1mb update). * * @param {Uint8Array} update * @param {Object} logContext * @returns {Promise>} */ computeStateVector(update: Uint8Array, logContext?: { [x: string]: any; }): Promise>; /** * @param {object} opts * @param {Uint8Array} opts.nongcDoc * @param {Uint8Array} opts.contentmapBin * @param {number|null} opts.from * @param {number|null} opts.to * @param {string} opts.by * @param {Array<{k: string, v: string}>|null} opts.withCustomAttributions * @param {boolean} opts.includeYdoc * @param {boolean} opts.includeDelta * @param {boolean} opts.includeAttributions * @param {Object} [logContext] * @returns {Promise>} */ changeset(opts: { nongcDoc: Uint8Array; contentmapBin: Uint8Array; from: number | null; to: number | null; by: string; withCustomAttributions: Array<{ k: string; v: string; }> | null; includeYdoc: boolean; includeDelta: boolean; includeAttributions: boolean; }, logContext?: { [x: string]: any; }): Promise>; /** * @param {object} opts * @param {Uint8Array} opts.nongcDoc * @param {Uint8Array} opts.contentmapBin * @param {number} opts.from * @param {number} opts.to * @param {string} opts.by * @param {Uint8Array} [opts.contentIds] * @param {Array<{k: string, v: string}>|null} opts.withCustomAttributions * @param {boolean} opts.includeCustomAttributions * @param {boolean} opts.includeDelta * @param {boolean} opts.includeYdoc * @param {boolean} opts.includeAttributions * @param {number} opts.limit * @param {boolean} opts.reverse * @param {boolean} opts.group * @param {number} opts.groupMaxGap * @param {number} opts.groupMaxDuration * @param {Object} [logContext] * @returns {Promise>} */ activity(opts: { nongcDoc: Uint8Array; contentmapBin: Uint8Array; from: number; to: number; by: string; contentIds?: Uint8Array | undefined; withCustomAttributions: Array<{ k: string; v: string; }> | null; includeCustomAttributions: boolean; includeDelta: boolean; includeYdoc: boolean; includeAttributions: boolean; limit: number; reverse: boolean; group: boolean; groupMaxGap: number; groupMaxDuration: number; }, logContext?: { [x: string]: any; }): Promise>; /** * @param {object} opts * @param {Uint8Array} opts.update * @param {Uint8Array} opts.currentDoc * @param {string} opts.userid * @param {Array<{k: string, v: string}>} opts.customAttributions * @param {Object} [logContext] * @returns {Promise<{ update: Uint8Array, contentmap: Uint8Array } | null>} */ patchYdoc(opts: { update: Uint8Array; currentDoc: Uint8Array; userid: string; customAttributions: Array<{ k: string; v: string; }>; }, logContext?: { [x: string]: any; }): Promise<{ update: Uint8Array; contentmap: Uint8Array; } | null>; /** * @param {object} opts * @param {Uint8Array} opts.nongcDoc * @param {Uint8Array} opts.contentmapBin * @param {number} [opts.from] * @param {number} [opts.to] * @param {string} [opts.by] * @param {Uint8Array} [opts.contentIds] * @param {Array<{k: string, v: string}>|null} [opts.withCustomAttributions] * @param {string} opts.userid * @param {Array<{k: string, v: string}>} opts.customAttributions * @param {Object} [logContext] * @returns {Promise<{ update: Uint8Array, contentmap: Uint8Array }>} */ rollback(opts: { nongcDoc: Uint8Array; contentmapBin: Uint8Array; from?: number | undefined; to?: number | undefined; by?: string | undefined; contentIds?: Uint8Array | undefined; withCustomAttributions?: { k: string; v: string; }[] | null | undefined; userid: string; customAttributions: Array<{ k: string; v: string; }>; }, logContext?: { [x: string]: any; }): Promise<{ update: Uint8Array; contentmap: Uint8Array; }>; destroy(): Promise; } import * as s from 'lib0/schema'; declare class ComputeWorker { /** * @param {ComputePool} pool */ constructor(pool: ComputePool); pool: ComputePool; worker: Worker; isComputing: boolean; isDead: boolean; /** * Unix time in ms when the current task started. */ taskStart: number; /** * Unix time in ms when the current task ended. */ taskEnd: number; /** * Unix time in ms when the worker was last used. */ lastUsed: number; /** * @type {((value: any) => void) | null} */ _cbResolve: ((value: any) => void) | null; /** * @type {((reason: any) => void) | null} */ _cbReject: ((reason: any) => void) | null; /** * @type {Object?} */ _logContext: { [x: string]: any; } | null; /** * @param {ComputeTask} task * @param {Array} transferList * @param {Object} logContext * @param {(value: any) => void} resolve * @param {(reason: any) => void} reject */ run(task: ComputeTask, transferList: Array, logContext: { [x: string]: any; }, resolve: (value: any) => void, reject: (reason: any) => void): void; terminate(): Promise; } import { Worker } from 'node:worker_threads'; export {}; //# sourceMappingURL=compute.d.ts.map