@pluv/crdt-yjs 0.42.0 → 0.44.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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @pluv/crdt-yjs@0.42.0 build /home/runner/work/pluv/pluv/packages/crdt-yjs
2
+ > @pluv/crdt-yjs@0.44.0 build /home/runner/work/pluv/pluv/packages/crdt-yjs
3
3
  > tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -8,11 +8,11 @@
8
8
  CLI Target: es6
9
9
  ESM Build start
10
10
  CJS Build start
11
- CJS dist/index.js 11.76 KB
12
- CJS ⚡️ Build success in 114ms
13
- ESM dist/index.mjs 10.97 KB
14
- ESM ⚡️ Build success in 114ms
11
+ ESM dist/index.mjs 11.15 KB
12
+ ESM ⚡️ Build success in 105ms
13
+ CJS dist/index.js 11.96 KB
14
+ CJS ⚡️ Build success in 106ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 2140ms
16
+ DTS ⚡️ Build success in 2319ms
17
17
  DTS dist/index.d.mts 3.95 KB
18
18
  DTS dist/index.d.ts 3.95 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @pluv/crdt-yjs
2
2
 
3
+ ## 0.44.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 503c23b: Updated `batchApplyEncodedState` to use `Yjs.mergeUpdates` to more efficiently update the document under-the-hood, while also producing a smaller document.
8
+ - @pluv/crdt@0.44.0
9
+ - @pluv/types@0.44.0
10
+
11
+ ## 0.43.0
12
+
13
+ ### Patch Changes
14
+
15
+ - @pluv/crdt@0.43.0
16
+ - @pluv/types@0.43.0
17
+
3
18
  ## 0.42.0
4
19
 
5
20
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Array, Doc, Map, Text, XmlElement, XmlText, XmlFragment } from 'yjs';
2
- import { CrdtType, AbstractCrdtDoc, DocApplyEncodedStateParams, DocSubscribeCallbackParams, InferCrdtJson, AbstractCrdtDocFactory } from '@pluv/crdt';
2
+ import { CrdtType, AbstractCrdtDoc, DocApplyEncodedStateParams, DocBatchApplyEncodedStateParams, DocSubscribeCallbackParams, InferCrdtJson, AbstractCrdtDocFactory } from '@pluv/crdt';
3
3
 
4
4
  type YjsType<TValue extends unknown, TJson extends unknown = any> = CrdtType<TValue, TJson> & {
5
5
  initialValue?: any;
@@ -14,7 +14,7 @@ declare class CrdtYjsDoc<TStorage extends Record<string, YjsType<any, any>>> ext
14
14
  private _undoManager;
15
15
  constructor(value?: TStorage);
16
16
  applyEncodedState(params: DocApplyEncodedStateParams): this;
17
- batchApplyEncodedState(updates: readonly (DocApplyEncodedStateParams | string | null | undefined)[]): this;
17
+ batchApplyEncodedState(params: DocBatchApplyEncodedStateParams): this;
18
18
  canRedo(): boolean;
19
19
  canUndo(): boolean;
20
20
  destroy(): void;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Array, Doc, Map, Text, XmlElement, XmlText, XmlFragment } from 'yjs';
2
- import { CrdtType, AbstractCrdtDoc, DocApplyEncodedStateParams, DocSubscribeCallbackParams, InferCrdtJson, AbstractCrdtDocFactory } from '@pluv/crdt';
2
+ import { CrdtType, AbstractCrdtDoc, DocApplyEncodedStateParams, DocBatchApplyEncodedStateParams, DocSubscribeCallbackParams, InferCrdtJson, AbstractCrdtDocFactory } from '@pluv/crdt';
3
3
 
4
4
  type YjsType<TValue extends unknown, TJson extends unknown = any> = CrdtType<TValue, TJson> & {
5
5
  initialValue?: any;
@@ -14,7 +14,7 @@ declare class CrdtYjsDoc<TStorage extends Record<string, YjsType<any, any>>> ext
14
14
  private _undoManager;
15
15
  constructor(value?: TStorage);
16
16
  applyEncodedState(params: DocApplyEncodedStateParams): this;
17
- batchApplyEncodedState(updates: readonly (DocApplyEncodedStateParams | string | null | undefined)[]): this;
17
+ batchApplyEncodedState(params: DocBatchApplyEncodedStateParams): this;
18
18
  canRedo(): boolean;
19
19
  canUndo(): boolean;
20
20
  destroy(): void;
package/dist/index.js CHANGED
@@ -196,20 +196,25 @@ var CrdtYjsDoc = class extends import_crdt.AbstractCrdtDoc {
196
196
  (0, import_yjs7.applyUpdate)(this.value, uint8Update, origin);
197
197
  return this;
198
198
  }
199
- batchApplyEncodedState(updates) {
200
- const params = updates.reduce((acc, update) => {
199
+ batchApplyEncodedState(params) {
200
+ var _a;
201
+ const { origin } = params;
202
+ const updates = (_a = params.updates) != null ? _a : [];
203
+ const filtered = updates.reduce((acc, update) => {
201
204
  if (!update) return acc;
202
205
  if (typeof update === "string") {
203
- acc.push({ update });
206
+ acc.push((0, import_js_base64.toUint8Array)(update));
204
207
  return acc;
205
208
  }
206
- if (!!update && typeof update === "object") {
209
+ if (typeof update === "object") {
207
210
  acc.push(update);
208
211
  return acc;
209
212
  }
210
213
  return acc;
211
214
  }, []);
212
- return params.reduce((doc2, update) => doc2.applyEncodedState(update), this);
215
+ if (!filtered.length) return this;
216
+ const merged = (0, import_yjs7.mergeUpdates)(filtered);
217
+ return this.applyEncodedState({ origin, update: merged });
213
218
  }
214
219
  canRedo() {
215
220
  var _a;
package/dist/index.mjs CHANGED
@@ -67,7 +67,8 @@ import {
67
67
  XmlFragment as YXmlFragment,
68
68
  XmlText as YXmlText2,
69
69
  applyUpdate,
70
- encodeStateAsUpdate
70
+ encodeStateAsUpdate,
71
+ mergeUpdates
71
72
  } from "yjs";
72
73
 
73
74
  // src/map/YjsMap.ts
@@ -188,20 +189,25 @@ var CrdtYjsDoc = class extends AbstractCrdtDoc {
188
189
  applyUpdate(this.value, uint8Update, origin);
189
190
  return this;
190
191
  }
191
- batchApplyEncodedState(updates) {
192
- const params = updates.reduce((acc, update) => {
192
+ batchApplyEncodedState(params) {
193
+ var _a;
194
+ const { origin } = params;
195
+ const updates = (_a = params.updates) != null ? _a : [];
196
+ const filtered = updates.reduce((acc, update) => {
193
197
  if (!update) return acc;
194
198
  if (typeof update === "string") {
195
- acc.push({ update });
199
+ acc.push(toUint8Array(update));
196
200
  return acc;
197
201
  }
198
- if (!!update && typeof update === "object") {
202
+ if (typeof update === "object") {
199
203
  acc.push(update);
200
204
  return acc;
201
205
  }
202
206
  return acc;
203
207
  }, []);
204
- return params.reduce((doc2, update) => doc2.applyEncodedState(update), this);
208
+ if (!filtered.length) return this;
209
+ const merged = mergeUpdates(filtered);
210
+ return this.applyEncodedState({ origin, update: merged });
205
211
  }
206
212
  canRedo() {
207
213
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/crdt-yjs",
3
- "version": "0.42.0",
3
+ "version": "0.44.0",
4
4
  "description": "yjs for @pluv/io",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -18,8 +18,8 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "js-base64": "^3.7.7",
21
- "@pluv/crdt": "^0.42.0",
22
- "@pluv/types": "^0.42.0"
21
+ "@pluv/crdt": "^0.44.0",
22
+ "@pluv/types": "^0.44.0"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "yjs": "^13.0.0"
@@ -29,8 +29,8 @@
29
29
  "tsup": "^8.4.0",
30
30
  "typescript": "^5.8.3",
31
31
  "yjs": "^13.6.26",
32
- "@pluv/tsconfig": "^0.42.0",
33
- "eslint-config-pluv": "^0.42.0"
32
+ "@pluv/tsconfig": "^0.44.0",
33
+ "eslint-config-pluv": "^0.44.0"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "tsup src/index.ts --format esm,cjs --dts",
@@ -1,4 +1,9 @@
1
- import type { DocApplyEncodedStateParams, DocSubscribeCallbackParams, InferCrdtJson } from "@pluv/crdt";
1
+ import type {
2
+ DocApplyEncodedStateParams,
3
+ DocBatchApplyEncodedStateParams,
4
+ DocSubscribeCallbackParams,
5
+ InferCrdtJson,
6
+ } from "@pluv/crdt";
2
7
  import { AbstractCrdtDoc } from "@pluv/crdt";
3
8
  import { fromUint8Array, toUint8Array } from "js-base64";
4
9
  import {
@@ -13,6 +18,7 @@ import {
13
18
  XmlText as YXmlText,
14
19
  applyUpdate,
15
20
  encodeStateAsUpdate,
21
+ mergeUpdates,
16
22
  } from "yjs";
17
23
  import { YjsArray } from "../array/YjsArray";
18
24
  import { YjsMap } from "../map/YjsMap";
@@ -108,26 +114,31 @@ export class CrdtYjsDoc<TStorage extends Record<string, YjsType<any, any>>> exte
108
114
  return this;
109
115
  }
110
116
 
111
- public batchApplyEncodedState(updates: readonly (DocApplyEncodedStateParams | string | null | undefined)[]): this {
112
- const params = updates.reduce<DocApplyEncodedStateParams[]>((acc, update) => {
117
+ public batchApplyEncodedState(params: DocBatchApplyEncodedStateParams): this {
118
+ const { origin } = params;
119
+ const updates = params.updates ?? [];
120
+
121
+ const filtered = updates.reduce<Uint8Array[]>((acc, update) => {
113
122
  if (!update) return acc;
114
123
 
115
124
  if (typeof update === "string") {
116
- acc.push({ update });
117
-
125
+ acc.push(toUint8Array(update));
118
126
  return acc;
119
127
  }
120
128
 
121
- if (!!update && typeof update === "object") {
129
+ if (typeof update === "object") {
122
130
  acc.push(update);
123
-
124
131
  return acc;
125
132
  }
126
133
 
127
134
  return acc;
128
135
  }, []);
129
136
 
130
- return params.reduce((doc, update) => doc.applyEncodedState(update), this);
137
+ if (!filtered.length) return this;
138
+
139
+ const merged = mergeUpdates(filtered);
140
+
141
+ return this.applyEncodedState({ origin, update: merged });
131
142
  }
132
143
 
133
144
  public canRedo(): boolean {