@kyneta/yjs-schema 1.1.0 → 1.2.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 +34 -74
- package/dist/index.js +181 -132
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
- package/src/__tests__/bind-constraints.test.ts +333 -0
- package/src/__tests__/bind-yjs.test.ts +38 -40
- package/src/__tests__/create.test.ts +10 -11
- package/src/__tests__/reader.test.ts +38 -61
- package/src/__tests__/record-text-spike.test.ts +9 -10
- package/src/__tests__/structural-merge.test.ts +18 -18
- package/src/__tests__/substrate.test.ts +18 -21
- package/src/__tests__/version.test.ts +75 -0
- package/src/bind-yjs.ts +72 -42
- package/src/change-mapping.ts +46 -55
- package/src/create.ts +2 -2
- package/src/index.ts +12 -25
- package/src/populate.ts +50 -83
- package/src/substrate.ts +52 -7
- package/src/version.ts +55 -0
- package/src/yjs-resolve.ts +1 -11
- package/src/yjs-escape.ts +0 -84
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Version, Schema, Ref, SubstratePayload,
|
|
2
|
-
export {
|
|
1
|
+
import { Version, Schema, Ref, SubstratePayload, SubstrateNamespace, CrdtStrategy, Path, ChangeBase, Op, Reader, Substrate, ReplicaFactory, SubstrateFactory, Segment } from '@kyneta/schema';
|
|
2
|
+
export { Op, Ref, Schema, SubstratePayload, applyChanges, change, subscribe, subscribeNode } from '@kyneta/schema';
|
|
3
3
|
import * as Y from 'yjs';
|
|
4
|
-
|
|
4
|
+
export { Changeset } from '@kyneta/changefeed';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* A Version wrapping a Yjs state vector.
|
|
@@ -41,6 +41,16 @@ declare class YjsVersion implements Version {
|
|
|
41
41
|
* Throws if `other` is not a `YjsVersion`.
|
|
42
42
|
*/
|
|
43
43
|
compare(other: Version): "behind" | "equal" | "ahead" | "concurrent";
|
|
44
|
+
/**
|
|
45
|
+
* Greatest lower bound (lattice meet) of two Yjs versions.
|
|
46
|
+
*
|
|
47
|
+
* Decodes both state vectors, computes the component-wise minimum
|
|
48
|
+
* via the shared `versionVectorMeet` utility, and encodes the result
|
|
49
|
+
* back to a Yjs state vector.
|
|
50
|
+
*
|
|
51
|
+
* @throws If `other` is not a `YjsVersion`.
|
|
52
|
+
*/
|
|
53
|
+
meet(other: Version): YjsVersion;
|
|
44
54
|
/**
|
|
45
55
|
* Parse a serialized YjsVersion string back into a YjsVersion.
|
|
46
56
|
*
|
|
@@ -159,35 +169,23 @@ declare function exportSince(doc: object, since: YjsVersion): SubstratePayload |
|
|
|
159
169
|
declare function merge(doc: object, payload: SubstratePayload, origin?: string): void;
|
|
160
170
|
|
|
161
171
|
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* This is the recommended way to declare a Yjs-backed document type.
|
|
165
|
-
* The factory builder injects a deterministic numeric Yjs clientID derived
|
|
166
|
-
* from the exchange's string peerId, ensuring consistent change attribution
|
|
167
|
-
* across all documents and sessions.
|
|
172
|
+
* The Yjs CRDT substrate namespace.
|
|
168
173
|
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* `
|
|
172
|
-
* `
|
|
174
|
+
* - `yjs.bind(schema)` — collaborative sync (default)
|
|
175
|
+
* - `yjs.bind(schema, "ephemeral")` — ephemeral/presence broadcast
|
|
176
|
+
* - `yjs.replica()` — collaborative replication (default)
|
|
177
|
+
* - `yjs.replica("ephemeral")` — ephemeral replication
|
|
178
|
+
* - `yjs.unwrap(ref)` — access the underlying Y.Doc
|
|
173
179
|
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
* import { bindYjs } from "@kyneta/yjs-schema"
|
|
177
|
-
* import { Schema } from "@kyneta/schema"
|
|
178
|
-
*
|
|
179
|
-
* const TodoDoc = bindYjs(Schema.doc({
|
|
180
|
-
* title: Schema.annotated("text"),
|
|
181
|
-
* items: Schema.list(Schema.struct({
|
|
182
|
-
* name: Schema.string(),
|
|
183
|
-
* done: Schema.boolean(),
|
|
184
|
-
* })),
|
|
185
|
-
* }))
|
|
186
|
-
*
|
|
187
|
-
* const doc = exchange.get("my-todos", TodoDoc)
|
|
188
|
-
* ```
|
|
180
|
+
* Strategy is constrained to `CrdtStrategy` (`"collaborative" | "ephemeral"`).
|
|
181
|
+
* Passing `"authoritative"` is a compile error.
|
|
189
182
|
*/
|
|
190
|
-
|
|
183
|
+
/** The closed set of capability tags that the Yjs substrate supports. */
|
|
184
|
+
type YjsCaps = "text" | "json";
|
|
185
|
+
declare const yjs: SubstrateNamespace<CrdtStrategy, YjsCaps> & {
|
|
186
|
+
/** Access the underlying `Y.Doc` backing a ref. */
|
|
187
|
+
unwrap(ref: object): Y.Doc;
|
|
188
|
+
};
|
|
191
189
|
|
|
192
190
|
/**
|
|
193
191
|
* Apply a kyneta Change to the Yjs shared type tree imperatively.
|
|
@@ -215,15 +213,15 @@ declare function applyChangeToYjs(rootMap: Y.Map<any>, rootSchema: Schema, path:
|
|
|
215
213
|
*
|
|
216
214
|
* @param events - The events from the `observeDeep` callback
|
|
217
215
|
*/
|
|
218
|
-
declare function eventsToOps(events: Y.YEvent<any>[]): Op[];
|
|
216
|
+
declare function eventsToOps(events: Y.YEvent<any>[], schema: Schema): Op[];
|
|
219
217
|
|
|
220
218
|
/**
|
|
221
219
|
* Ensure that a Y.Doc's root map contains the correct Yjs shared types
|
|
222
220
|
* matching the schema structure.
|
|
223
221
|
*
|
|
224
|
-
* Obtains the root map via `doc.getMap("root")`,
|
|
225
|
-
* schema, and creates empty containers for each field within a
|
|
226
|
-
* `doc.transact()` call for atomicity.
|
|
222
|
+
* Obtains the root map via `doc.getMap("root")`, reads the root product
|
|
223
|
+
* schema's fields, and creates empty containers for each field within a
|
|
224
|
+
* single `doc.transact()` call for atomicity.
|
|
227
225
|
*
|
|
228
226
|
* When `conditional` is true, fields that already exist in the root map
|
|
229
227
|
* are skipped. This is the correct mode after hydration — containers
|
|
@@ -240,7 +238,7 @@ declare function eventsToOps(events: Y.YEvent<any>[]): Op[];
|
|
|
240
238
|
* structural ops across all peers, enabling Yjs deduplication on merge.
|
|
241
239
|
*
|
|
242
240
|
* @param doc - The Y.Doc to prepare
|
|
243
|
-
* @param schema - The root document schema (
|
|
241
|
+
* @param schema - The root document schema (a ProductSchema)
|
|
244
242
|
* @param conditional - If true, skip fields that already exist in the root map.
|
|
245
243
|
* Context: jj:smmulzkm (two-phase substrate construction)
|
|
246
244
|
*/
|
|
@@ -281,35 +279,9 @@ declare function yjsReader(doc: Y.Doc, schema: Schema): Reader;
|
|
|
281
279
|
* @param schema - The root schema for the document.
|
|
282
280
|
*/
|
|
283
281
|
declare function createYjsSubstrate(doc: Y.Doc, schema: Schema): Substrate<YjsVersion>;
|
|
282
|
+
declare const yjsReplicaFactory: ReplicaFactory<YjsVersion>;
|
|
284
283
|
declare const yjsSubstrateFactory: SubstrateFactory<YjsVersion>;
|
|
285
284
|
|
|
286
|
-
/**
|
|
287
|
-
* Returns the `Y.Doc` backing the given ref.
|
|
288
|
-
*
|
|
289
|
-
* This is the Yjs-specific escape hatch for accessing substrate-level
|
|
290
|
-
* capabilities: raw Yjs API, y-prosemirror/y-codemirror bindings,
|
|
291
|
-
* undo manager, awareness protocol, Yjs providers (y-websocket,
|
|
292
|
-
* y-indexeddb, y-webrtc, Hocuspocus, Liveblocks), etc.
|
|
293
|
-
*
|
|
294
|
-
* Currently supports root document refs only. Child-level resolution
|
|
295
|
-
* (e.g. `yjs(doc.title)` → `Y.Text`) is future work.
|
|
296
|
-
*
|
|
297
|
-
* @param ref - A root document ref backed by a Yjs substrate
|
|
298
|
-
* @returns The `Y.Doc` backing the ref
|
|
299
|
-
* @throws If the ref is not backed by a Yjs substrate
|
|
300
|
-
*
|
|
301
|
-
* @example
|
|
302
|
-
* ```ts
|
|
303
|
-
* import { yjs } from "@kyneta/yjs-schema"
|
|
304
|
-
*
|
|
305
|
-
* const doc = exchange.get("my-doc", TodoDoc)
|
|
306
|
-
* const yjsDoc = yjs(doc)
|
|
307
|
-
* console.log(yjsDoc.getMap("root").toJSON()) // raw state
|
|
308
|
-
* console.log(yjsDoc.clientID) // client ID
|
|
309
|
-
* ```
|
|
310
|
-
*/
|
|
311
|
-
declare function yjs(ref: object): Doc;
|
|
312
|
-
|
|
313
285
|
/**
|
|
314
286
|
* Navigate one step deeper into the Yjs shared type tree.
|
|
315
287
|
*
|
|
@@ -338,16 +310,4 @@ declare function stepIntoYjs(current: unknown, segment: Segment): unknown;
|
|
|
338
310
|
*/
|
|
339
311
|
declare function resolveYjsType(rootMap: Y.Map<any>, rootSchema: Schema, path: Path): unknown;
|
|
340
312
|
|
|
341
|
-
|
|
342
|
-
* Collaborative text (CRDT). Produces `annotated("text")`.
|
|
343
|
-
*
|
|
344
|
-
* The annotation implies scalar string semantics for reads,
|
|
345
|
-
* but the Yjs substrate provides collaborative editing (insert, delete)
|
|
346
|
-
* via Y.Text.
|
|
347
|
-
*
|
|
348
|
-
* This is a convenience re-export so that `@kyneta/yjs-schema` users
|
|
349
|
-
* don't need to import `LoroSchema` just for `text()`.
|
|
350
|
-
*/
|
|
351
|
-
declare function text(): AnnotatedSchema<"text", undefined>;
|
|
352
|
-
|
|
353
|
-
export { YjsVersion, applyChangeToYjs, bindYjs, createYjsDoc, createYjsDocFromEntirety, createYjsSubstrate, ensureContainers, eventsToOps, exportEntirety, exportSince, merge, resolveYjsType, stepIntoYjs, text, version, yjs, yjsReader, yjsSubstrateFactory };
|
|
313
|
+
export { type YjsCaps, YjsVersion, applyChangeToYjs, createYjsDoc, createYjsDocFromEntirety, createYjsSubstrate, ensureContainers, eventsToOps, exportEntirety, exportSince, merge, resolveYjsType, stepIntoYjs, version, yjs, yjsReader, yjsReplicaFactory, yjsSubstrateFactory };
|