import { BindingTarget, ChangeBase, DocRef, Instruction, NATIVE, NativeMap, Op, Op as Op$1, Path, PathFoldResult, PathStepper, Position, RawPath, Ref, Releasable, ReplicaFactory, Schema, Schema as Schema$1, SchemaBinding, Side, Substrate, SubstrateFactory, SubstratePayload, Version, applyChanges, batch, createDoc, createRef, exportEntirety, exportSince, merge, subscribe, subscribeNode, unwrap, version } from "@kyneta/schema"; import * as Y from "yjs"; import { Doc } from "yjs"; import { Changeset } from "@kyneta/changefeed"; //#region src/native-map.d.ts /** * NativeMap for the Yjs CRDT substrate. * * Maps each schema kind to the corresponding Yjs shared type: * - `root → Y.Doc` (the document itself) * - `text → Y.Text` * - `counter → undefined` (Yjs has no counter type) * - `list → Y.Array` * - `movableList → undefined` (Yjs has no movable list) * - `struct → Y.Map` (Yjs uses maps for struct fields) * - `map → Y.Map` * - `tree → undefined` (Yjs has no tree type) * - `set → undefined` (not yet supported) * - `scalar → undefined` (no container; stored in parent map) * - `sum → undefined` (no container; stored in parent map) */ interface YjsNativeMap extends NativeMap { readonly root: Y.Doc; readonly text: Y.Text; readonly counter: undefined; readonly list: Y.Array; readonly movableList: undefined; readonly struct: Y.Map; readonly map: Y.Map; readonly tree: undefined; readonly set: undefined; readonly scalar: undefined; readonly sum: undefined; } //#endregion //#region src/bind-yjs.d.ts /** * The Yjs `clientID` a peer id writes under: its 53-bit `peerNumber`. * * 53 bits is the widest id a JS `number` holds exactly; Yjs's own random ids * use only 32, but its encoders carry any safe integer. Never 0, which is * `STRUCTURAL_YJS_CLIENT_ID`, and always the low 53 bits of the peer id's * Loro PeerID (`loroPeerId` in `@kyneta/loro-schema`). */ declare function yjsClientId(peerId: string): number; /** * Yjs composition-law tags — the set of concurrent composition laws * that the Yjs substrate faithfully implements. */ type YjsLaws = "lww" | "positional-ot" | "lww-per-key" | "lww-tag-replaced"; /** * The Yjs CRDT binding target. * * - `yjs.bind(schema)` — bind a schema to Yjs with collaborative sync * - `yjs.replica()` — create a collaborative replica * * Laws are constrained to `YjsLaws` — schemas requiring composition laws * outside this set (e.g. `"additive"` from `Schema.counter()`, * `"positional-ot-move"` from `Schema.movableList()`) are rejected at * compile time. * * To access the underlying Y.Doc, use `unwrap(ref)` from `@kyneta/schema`. */ declare const yjs: BindingTarget; //#endregion //#region src/change-mapping.d.ts /** * Apply a kyneta Change to the Yjs shared type tree imperatively. * * Resolves the target shared type at `path`, then applies the change * via the appropriate Yjs API. Must be called within a `doc.transact()` * for atomicity and correct event batching. * * @param rootMap - The root `Y.Map` obtained via `doc.getMap("root")` * @param rootSchema - The root document schema * @param path - The path to the target * @param change - The kyneta Change to apply */ declare function applyChangeToYjs(rootMap: Y.Map, rootSchema: Schema$1, path: Path, change: ChangeBase, binding?: SchemaBinding): void; /** * Convert `observeDeep` events into kyneta `Op[]` for changefeed delivery. * * Each `Y.YEvent` in the array maps to one Op with: * - `path`: derived from `event.path` (relative to the observed root Y.Map) * - `change`: derived from the event's delta/keys based on target type * * `event.path` in `observeDeep` is relative to the observed shared type. * Since we observe `rootMap` (the single root Y.Map), paths map directly * to kyneta `PathSegment[]`. * * @param events - The events from the `observeDeep` callback */ declare function eventsToOps(events: Y.YEvent[], schema: Schema$1, binding?: SchemaBinding): Op$1[]; //#endregion //#region src/populate.d.ts /** * Ensure that a Y.Doc's root map contains the correct Yjs shared types * matching the schema structure. * * Obtains the root map via `doc.getMap("root")`, reads the root product * schema's fields, and creates empty containers for each field within a * single `doc.transact()` call for atomicity. * * Container fields (text, product, sequence, map) are created if absent; * existing containers are preserved (calling `rootMap.set()` on a field * that already exists would be a destructive CRDT write). Scalar and sum * fields are no-ops — the materializer handles zeros. * * **Structural identity:** This function temporarily sets `doc.clientID` * to `STRUCTURAL_YJS_CLIENT_ID` (0) for the duration of container creation, * then restores the caller's clientID. This produces byte-identical * structural ops across all peers, enabling Yjs deduplication on merge. * * **Identity-keying:** When a `binding` is provided, each root field's * key in the root Y.Map is the identity hash from `binding.forward` * instead of the field name. Nested product fields are similarly keyed * via `ensureMapContainers`. * * @param doc - The Y.Doc to prepare * @param schema - The root document schema (a ProductSchema) * @param binding - Optional SchemaBinding for identity-keyed containers. */ declare function ensureContainers(doc: Y.Doc, schema: Schema$1, binding?: SchemaBinding): void; //#endregion //#region src/position.d.ts /** Map kyneta Side to Yjs assoc. Left → -1 (left-sticky), Right → 0 (right-sticky). */ declare function toYjsAssoc(side: Side): number; /** Map Yjs assoc to kyneta Side. Negative → left, non-negative → right. */ declare function fromYjsAssoc(assoc: number): Side; declare class YjsPosition implements Position { private readonly rpos; private readonly doc; readonly side: Side; /** `doc` is the substrate's slot: a position made before the substrate is * disposed throws `DocumentClosedError`. */ constructor(rpos: Y.RelativePosition, doc: Releasable); resolve(): number | null; encode(): Uint8Array; transform(_instructions: readonly Instruction[]): void; } //#endregion //#region src/version.d.ts /** A Version wrapping a Yjs state vector. */ declare class YjsVersion implements Version { #private; /** Encoded state vector: the cursor `exportSince()` exports from. */ readonly sv: Uint8Array; constructor(sv: Uint8Array); /** * Yjs is a collaborative (CRDT) substrate — lineages are never minted * automatically. `lineage` is always `DEFAULT_LINEAGE` for the document's * lifetime; new lineages require an explicit developer-invoked migration * primitive (T3 migrations, not implemented here). */ get lineage(): string; /** The version of a document holding nothing: the empty state vector. */ static readonly empty: YjsVersion; /** The version of a live `Y.Doc`: its state vector. O(clients). */ static fromDoc(doc: Doc): YjsVersion; /** `base64(sv)`. */ serialize(): string; compare(other: Version): "behind" | "equal" | "ahead" | "concurrent"; meet(other: Version): YjsVersion; join(other: Version): YjsVersion; /** Parse `serialize()`'s output. */ static parse(serialized: string): YjsVersion; } //#endregion //#region src/substrate.d.ts /** A top-level type Kyneta writes to only to advance the clock. */ declare const DELETE_CLOCK = "kyneta.clock"; /** * Creates a `Substrate` wrapping a user-provided Y.Doc. * * This is the "bring your own doc" entry point. The user creates and * manages the Y.Doc (possibly via a Yjs provider); this function wraps * it with a schema-aware overlay providing typed reads, writes, * versioning, and export/merge through the standard Substrate interface. * * **Event bridge contract:** An `observeDeep` handler is registered on the * root Y.Map from construction until `dispose`. Every mutation under * it that this substrate's `runBatch` did not make (a merge, or a write on * the Y.Doc from an editor binding or another substrate) is announced to * the kyneta changefeed, with `replay: false` iff its transaction is local. * A write to another top-level type is not announced, since the schema has * no place for it, but `subscribeLocalUpdates` still reports it. * * @param doc - The Y.Doc to wrap. The caller owns it: the substrate's * `dispose` unregisters every listener it put on it and lets go of it, and * never destroys it. * @param schema - The root schema for the document. * @param binding - Optional SchemaBinding for identity-keyed containers. */ declare function createYjsSubstrate(doc: Y.Doc, schema: Schema$1, binding?: SchemaBinding): Substrate; /** * Schema-free replica factory for Yjs: headless replicas over bare `Y.Doc`s, * with no schema walking, no container initialization, no reader, no event * bridge and no changefeed. What conduit participants (stores, routing * servers) use to accumulate state, compute per-peer deltas, and compact * storage without interpreting document fields. */ declare const yjsReplicaFactory: ReplicaFactory; /** * The standalone Yjs factory: no peer identity of its own (each document * keeps Yjs's random clientID), and containers keyed by the schema's own * identity binding (`identityBindingOf`), as `yjs.bind` keys them. Build with * `createSubstrate` and `substrateFromEntirety` (`@kyneta/schema`). */ declare const yjsSubstrateFactory: SubstrateFactory; //#endregion //#region src/yjs-resolve.d.ts /** * Navigate one step deeper into the Yjs shared type tree. * * Uses `instanceof` for runtime type discrimination: * - `Y.Map` → `.get(key)` — uses the identity hash when provided * - `Y.Array` → `.get(index)` * - `Y.Text` → terminal (cannot step further) * - Plain value → terminal (return `undefined`) * * `_nextSchema` is part of the `PathStepper` contract for Loro's root * dispatch but is unused here — Yjs's `instanceof` dispatch doesn't * need to look ahead at the next schema kind. */ declare const stepIntoYjs: PathStepper; /** * Resolve a Yjs shared type (or plain value) at the given path. * * Thin wrapper around `foldPath(stepIntoYjs, ...)`. Returns the * `PathFoldResult` shape from core — `{ resolved, schema }`. * * When a `binding` is provided, every product-field boundary uses the * identity hash from `binding.forward` instead of the field name. * * For an empty path, returns the root map and root schema. */ declare function resolveYjsType(rootMap: Y.Map, rootSchema: Schema$1, path: Path, binding?: SchemaBinding): PathFoldResult; //#endregion export { type Changeset, DELETE_CLOCK, type DocRef, NATIVE, type Op, type Ref, Schema, type SubstratePayload, type YjsLaws, type YjsNativeMap, YjsPosition, YjsVersion, applyChangeToYjs, applyChanges, batch, createDoc, createRef, createYjsSubstrate, ensureContainers, eventsToOps, exportEntirety, exportSince, fromYjsAssoc, merge, resolveYjsType, stepIntoYjs, subscribe, subscribeNode, toYjsAssoc, unwrap, version, yjs, yjsClientId, yjsReplicaFactory, yjsSubstrateFactory }; //# sourceMappingURL=index.d.ts.map