@kyneta/yjs-schema 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BindingTarget, ChangeBase, DocRef, Instruction, NATIVE, NativeMap, Op, Op as Op$1, Path, Position, Reader, Ref, ReplicaFactory, Schema, Schema as Schema$1, SchemaBinding, Segment, Side, Substrate, SubstrateFactory, SubstratePayload, Version, applyChanges, change, createDoc, createRef, exportEntirety, exportSince, merge, subscribe, subscribeNode, unwrap, version } from "@kyneta/schema";
1
+ import { BindingTarget, ChangeBase, DocRef, Instruction, NATIVE, NativeMap, Op, Op as Op$1, Path, PathFoldResult, PathStepper, Position, Ref, ReplicaFactory, Schema, Schema as Schema$1, SchemaBinding, Side, Substrate, SubstrateFactory, SubstratePayload, Version, applyChanges, change, createDoc, createRef, exportEntirety, exportSince, merge, subscribe, subscribeNode, unwrap, version } from "@kyneta/schema";
2
2
  import * as Y from "yjs";
3
3
  import { Doc } from "yjs";
4
4
  import { Changeset } from "@kyneta/changefeed";
@@ -93,14 +93,10 @@ declare function eventsToOps(events: Y.YEvent<any>[], schema: Schema$1, binding?
93
93
  * schema's fields, and creates empty containers for each field within a
94
94
  * single `doc.transact()` call for atomicity.
95
95
  *
96
- * When `conditional` is true, fields that already exist in the root map
97
- * are skipped. This is the correct mode after hydration — containers
98
- * present from stored state must not be overwritten (each `rootMap.set()`
99
- * is a CRDT write that advances the version vector and may conflict
100
- * with stored operations).
101
- *
102
- * When `conditional` is false (default), all fields are created
103
- * unconditionally. This is the correct mode for fresh documents.
96
+ * Container fields (text, product, sequence, map) are created if absent;
97
+ * existing containers are preserved (calling `rootMap.set()` on a field
98
+ * that already exists would be a destructive CRDT write). Scalar and sum
99
+ * fields are no-ops the materializer handles zeros.
104
100
  *
105
101
  * **Structural identity:** This function temporarily sets `doc.clientID`
106
102
  * to `STRUCTURAL_YJS_CLIENT_ID` (0) for the duration of container creation,
@@ -114,11 +110,9 @@ declare function eventsToOps(events: Y.YEvent<any>[], schema: Schema$1, binding?
114
110
  *
115
111
  * @param doc - The Y.Doc to prepare
116
112
  * @param schema - The root document schema (a ProductSchema)
117
- * @param conditional - If true, skip fields that already exist in the root map.
118
- * Context: jj:smmulzkm (two-phase substrate construction)
119
113
  * @param binding - Optional SchemaBinding for identity-keyed containers.
120
114
  */
121
- declare function ensureContainers(doc: Y.Doc, schema: Schema$1, conditional?: boolean, binding?: SchemaBinding): void;
115
+ declare function ensureContainers(doc: Y.Doc, schema: Schema$1, binding?: SchemaBinding): void;
122
116
  //#endregion
123
117
  //#region src/position.d.ts
124
118
  /** Map kyneta Side to Yjs assoc. Left → -1 (left-sticky), Right → 0 (right-sticky). */
@@ -135,24 +129,6 @@ declare class YjsPosition implements Position {
135
129
  transform(_instructions: readonly Instruction[]): void;
136
130
  }
137
131
  //#endregion
138
- //#region src/reader.d.ts
139
- /**
140
- * Creates a Reader that navigates the Yjs shared type tree live,
141
- * using the schema as a type witness to determine navigation at each
142
- * path segment.
143
- *
144
- * The reader is a live view — mutations to the underlying Y.Doc
145
- * (via `doc.transact()`, or `Y.applyUpdate()`) are immediately
146
- * visible through the reader.
147
- *
148
- * Internally obtains the root map via `doc.getMap("root")`.
149
- *
150
- * @param doc - The Y.Doc to read from.
151
- * @param schema - The root schema for the document.
152
- * @param binding - Optional SchemaBinding for identity-keyed navigation.
153
- */
154
- declare function yjsReader(doc: Y.Doc, schema: Schema$1, binding?: SchemaBinding): Reader;
155
- //#endregion
156
132
  //#region src/version.d.ts
157
133
  /**
158
134
  * A Version wrapping a Yjs snapshot (state vector + delete set).
@@ -282,43 +258,23 @@ declare const yjsSubstrateFactory: SubstrateFactory<YjsVersion>;
282
258
  * - `Y.Text` → terminal (cannot step further)
283
259
  * - Plain value → terminal (return `undefined`)
284
260
  *
285
- * @param current - The current position (a Yjs shared type or plain value)
286
- * @param segment - The path segment to follow
287
- * @param identity - Optional identity hash to use instead of the segment's resolved value
261
+ * `_nextSchema` is part of the `PathStepper` contract for Loro's root
262
+ * dispatch but is unused here Yjs's `instanceof` dispatch doesn't
263
+ * need to look ahead at the next schema kind.
288
264
  */
289
- declare function stepIntoYjs(current: unknown, segment: Segment, identity?: string): unknown;
290
- /**
291
- * Result of resolving a Yjs shared type at a path.
292
- *
293
- * Includes both the resolved Yjs value and the schema at that position,
294
- * enabling callers to distinguish between schema kinds that map to the
295
- * same Yjs type (e.g. "text" vs "richtext" both use Y.Text).
296
- */
297
- interface ResolvedYjs {
298
- readonly resolved: unknown;
299
- readonly schema: Schema$1;
300
- }
265
+ declare const stepIntoYjs: PathStepper;
301
266
  /**
302
267
  * Resolve a Yjs shared type (or plain value) at the given path.
303
268
  *
304
- * Left-folds over path segments using `advanceSchema` for pure schema
305
- * descent and `stepIntoYjs` for Yjs-specific navigation.
269
+ * Thin wrapper around `foldPath(stepIntoYjs, ...)`. Returns the
270
+ * `PathFoldResult` shape from core — `{ resolved, schema }`.
306
271
  *
307
- * When a `binding` is provided, each step computes the absolute schema
308
- * path and looks up the identity hash from `binding.forward`. This
309
- * identity hash is used instead of the field name at every product-field
310
- * boundary (root and nested).
272
+ * When a `binding` is provided, every product-field boundary uses the
273
+ * identity hash from `binding.forward` instead of the field name.
311
274
  *
312
- * Returns both the Yjs shared type (or plain value) and the schema at
313
- * the terminal position. For an empty path, returns the root map and
314
- * root schema.
315
- *
316
- * @param rootMap - The root `Y.Map` obtained via `doc.getMap("root")`
317
- * @param rootSchema - The root document schema
318
- * @param path - The path to resolve
319
- * @param binding - Optional SchemaBinding for identity-keyed navigation.
275
+ * For an empty path, returns the root map and root schema.
320
276
  */
321
- declare function resolveYjsType(rootMap: Y.Map<any>, rootSchema: Schema$1, path: Path, binding?: SchemaBinding): ResolvedYjs;
277
+ declare function resolveYjsType(rootMap: Y.Map<any>, rootSchema: Schema$1, path: Path, binding?: SchemaBinding): PathFoldResult;
322
278
  //#endregion
323
- export { type Changeset, type DocRef, NATIVE, type Op, type Ref, Schema, type SubstratePayload, type YjsLaws, type YjsNativeMap, YjsPosition, YjsVersion, applyChangeToYjs, applyChanges, change, createDoc, createRef, createYjsSubstrate, ensureContainers, eventsToOps, exportEntirety, exportSince, fromYjsAssoc, merge, resolveYjsType, stepIntoYjs, subscribe, subscribeNode, toYjsAssoc, unwrap, version, yjs, yjsReader, yjsReplicaFactory, yjsSubstrateFactory };
279
+ export { type Changeset, type DocRef, NATIVE, type Op, type Ref, Schema, type SubstratePayload, type YjsLaws, type YjsNativeMap, YjsPosition, YjsVersion, applyChangeToYjs, applyChanges, change, createDoc, createRef, createYjsSubstrate, ensureContainers, eventsToOps, exportEntirety, exportSince, fromYjsAssoc, merge, resolveYjsType, stepIntoYjs, subscribe, subscribeNode, toYjsAssoc, unwrap, version, yjs, yjsReplicaFactory, yjsSubstrateFactory };
324
280
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/native-map.ts","../src/bind-yjs.ts","../src/change-mapping.ts","../src/populate.ts","../src/position.ts","../src/reader.ts","../src/version.ts","../src/substrate.ts","../src/yjs-resolve.ts"],"mappings":";;;;;;;;;;AAwBA;;;;;;;;;;;;UAAiB,YAAA,SAAqB,SAAA;EAAA,SAC3B,IAAA,EAAM,CAAA,CAAE,GAAA;EAAA,SACR,IAAA,EAAM,CAAA,CAAE,IAAA;EAAA,SACR,OAAA;EAAA,SACA,IAAA,EAAM,CAAA,CAAE,KAAA;EAAA,SACR,WAAA;EAAA,SACA,MAAA,EAAQ,CAAA,CAAE,GAAA;EAAA,SACV,GAAA,EAAK,CAAA,CAAE,GAAA;EAAA,SACP,IAAA;EAAA,SACA,GAAA;EAAA,SACA,MAAA;EAAA,SACA,GAAA;AAAA;;;;;;;KCgHC,OAAA;;;;;;;;;;;;;;cAmBC,GAAA,EAAK,aAAA,CAAc,OAAA,EAAS,YAAA;;;;;;;AD9IzC;;;;;;;;iBEoCgB,gB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AAA,EACL,EAAA,EAAI,UAAA,QADI,CAAA,CAC4B,eAAA,IACnC,UAAA;ELIc;AAmBnB;;;;;EKVE,SAAA,CAAA;ELU6B;;;;;;AAAsB;;;;AC1GrD;;;;EIoHE,OAAA,CAAQ,KAAA,EAAO,OAAA;EJjHT;;;;;;;;;;;;;EI6IN,IAAA,CAAK,KAAA,EAAO,OAAA,GAAU,UAAA;EJ3IZ;;;AAAa;AAsbzB;;;;;EAtbY,OIgKH,KAAA,CAAM,UAAA,WAAqB,UAAA;AAAA;;;;;;ANzMpC;;;;;;;;;;;;;;;;iBOqDgB,kBAAA,CACd,GAAA,EAAK,CAAA,CAAE,GAAA,EACP,MAAA,EAAQ,QAAA,EACR,OAAA,GAAU,aAAA,GACT,SAAA,CAAU,UAAA;AAAA,cAiWA,iBAAA,EAAmB,cAAc,CAAC,UAAA;AAAA,cA8BlC,mBAAA,EAAqB,gBAAgB,CAAC,UAAA;;;;;;;APxbnD;;;;;;;;;iBQuBgB,WAAA,CACd,OAAA,WACA,OAAA,EAAS,OAAO,EAChB,QAAA;;;;;;;;UA+Be,WAAA;EAAA,SACN,QAAA;EAAA,SACA,MAAA,EAAQ,QAAU;AAAA;;;;;;;;;;;;;;ARhDf;;;;ACgHd;;;iBOzCgB,cAAA,CACd,OAAA,EAAS,CAAA,CAAE,GAAA,OACX,UAAA,EAAY,QAAA,EACZ,IAAA,EAAM,IAAA,EACN,OAAA,GAAU,aAAA,GACT,WAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/native-map.ts","../src/bind-yjs.ts","../src/change-mapping.ts","../src/populate.ts","../src/position.ts","../src/version.ts","../src/substrate.ts","../src/yjs-resolve.ts"],"mappings":";;;;;;;;;;AAwBA;;;;;;;;;;;;UAAiB,YAAA,SAAqB,SAAA;EAAA,SAC3B,IAAA,EAAM,CAAA,CAAE,GAAA;EAAA,SACR,IAAA,EAAM,CAAA,CAAE,IAAA;EAAA,SACR,OAAA;EAAA,SACA,IAAA,EA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