@kyneta/yjs-schema 1.6.1 → 1.8.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/README.md +2 -0
- package/dist/index.d.ts +17 -61
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +222 -207
- package/dist/index.js.map +1 -1
- package/package.json +6 -8
- package/src/__tests__/create.test.ts +11 -0
- package/src/__tests__/eager-write-coherence.test.ts +321 -0
- package/src/__tests__/materialize.test.ts +227 -0
- package/src/__tests__/position.test.ts +7 -7
- package/src/__tests__/structural-merge.test.ts +18 -18
- package/src/__tests__/substrate.test.ts +56 -3
- package/src/bind-yjs.ts +3 -5
- package/src/change-mapping.ts +73 -48
- package/src/index.ts +1 -2
- package/src/materialize.ts +109 -0
- package/src/populate.ts +35 -37
- package/src/substrate.ts +277 -111
- package/src/yjs-extract.ts +52 -0
- package/src/yjs-resolve.ts +30 -95
- package/src/__tests__/reader.test.ts +0 -685
- package/src/reader.ts +0 -174
package/README.md
CHANGED
|
@@ -139,6 +139,8 @@ yjsDoc.getMap("root").toJSON() // raw state
|
|
|
139
139
|
yjsDoc.clientID // client ID
|
|
140
140
|
```
|
|
141
141
|
|
|
142
|
+
*Note for raw Y.Doc consumers:* Subscribers attached directly to the underlying `Y.Doc` will newly see `options.origin` faithfully on `transaction.origin` (where previously it was silently dropped).
|
|
143
|
+
|
|
142
144
|
## Yjs Ecosystem Compatibility
|
|
143
145
|
|
|
144
146
|
Because `yjs(doc)` returns a standard `Y.Doc`, the entire Yjs provider ecosystem works out of the box:
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BindingTarget, ChangeBase, DocRef, Instruction, NATIVE, NativeMap, Op, Op as Op$1, Path,
|
|
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
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
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,
|
|
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
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
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
|
|
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
|
-
*
|
|
305
|
-
*
|
|
269
|
+
* Thin wrapper around `foldPath(stepIntoYjs, ...)`. Returns the
|
|
270
|
+
* `PathFoldResult` shape from core — `{ resolved, schema }`.
|
|
306
271
|
*
|
|
307
|
-
* When a `binding` is provided,
|
|
308
|
-
*
|
|
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
|
-
*
|
|
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):
|
|
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,
|
|
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
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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/
|
|
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,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;;;;;;;KC8GC,OAAA;;;;;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