import { debug } from '@revesuite/global/debug'; import type { Transaction } from 'yjs'; import * as Y from 'yjs'; import type { ProxyConfig } from './config.js'; import { createYArrayProxy, createYMapProxy } from './proxy.js'; export type BlockSuiteDocAllowedValue = | Record | unknown[] | Y.Text; export type BlockSuiteDocData = Record; export class BlockSuiteDoc< Data extends BlockSuiteDocData = BlockSuiteDocData > extends Y.Doc { getMapProxy< Key extends keyof Data & string, Value extends Record = Data[Key] extends Record< string, unknown > ? Data[Key] : never >(key: Key, config: ProxyConfig = {}): Value { const map = super.getMap(key); return createYMapProxy(map, config); } getArrayProxy< Key extends keyof Data & string, Value extends unknown[] = Data[Key] extends unknown[] ? Data[Key] : never >(key: Key, config: ProxyConfig = {}): Value { const array = super.getArray(key); return createYArrayProxy(array, config) as Value; } @debug('transact') override transact(f: (arg0: Transaction) => T, origin?: number) { return super.transact(f, origin); } }