@pluv/crdt 0.0.0-experimental-20250527040415

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.
@@ -0,0 +1,19 @@
1
+
2
+
3
+ > @pluv/crdt@2.2.4 build /home/leedavidcs/projects/pluv/packages/crdt
4
+ > tsup src/index.ts --format esm,cjs --dts
5
+
6
+ CLI Building entry: src/index.ts
7
+ CLI Using tsconfig: tsconfig.json
8
+ CLI tsup v8.5.0
9
+ CLI Target: es6
10
+ ESM Build start
11
+ CJS Build start
12
+ CJS dist/index.js 2.68 KB
13
+ CJS ⚡️ Build success in 37ms
14
+ ESM dist/index.mjs 1.55 KB
15
+ ESM ⚡️ Build success in 37ms
16
+ DTS Build start
17
+ DTS ⚡️ Build success in 676ms
18
+ DTS dist/index.d.mts 2.64 KB
19
+ DTS dist/index.d.ts 2.64 KB
@@ -0,0 +1,5 @@
1
+
2
+
3
+ > @pluv/crdt@2.2.1 lint /home/leedavidcs/projects/pluv/packages/crdt
4
+ > eslint "src/**/*.ts*" --fix --max-warnings 0
5
+
package/CHANGELOG.md ADDED
@@ -0,0 +1,721 @@
1
+ # @pluv/crdt
2
+
3
+ ## 0.0.0-experimental-20250527040415
4
+
5
+ ### Patch Changes
6
+
7
+ - @pluv/types@0.0.0-experimental-20250527040415
8
+
9
+ ## 2.2.7
10
+
11
+ ### Patch Changes
12
+
13
+ - @pluv/types@2.2.7
14
+
15
+ ## 2.2.6
16
+
17
+ ### Patch Changes
18
+
19
+ - @pluv/types@2.2.6
20
+
21
+ ## 2.2.5
22
+
23
+ ### Patch Changes
24
+
25
+ - @pluv/types@2.2.5
26
+
27
+ ## 2.2.4
28
+
29
+ ### Patch Changes
30
+
31
+ - @pluv/types@2.2.4
32
+
33
+ ## 2.2.3
34
+
35
+ ### Patch Changes
36
+
37
+ - @pluv/types@2.2.3
38
+
39
+ ## 2.2.2
40
+
41
+ ### Patch Changes
42
+
43
+ - @pluv/types@2.2.2
44
+
45
+ ## 2.2.1
46
+
47
+ ### Patch Changes
48
+
49
+ - @pluv/types@2.2.1
50
+
51
+ ## 2.2.0
52
+
53
+ ### Patch Changes
54
+
55
+ - @pluv/types@2.2.0
56
+
57
+ ## 2.1.0
58
+
59
+ ### Patch Changes
60
+
61
+ - @pluv/types@2.1.0
62
+
63
+ ## 2.0.2
64
+
65
+ ### Patch Changes
66
+
67
+ - @pluv/types@2.0.2
68
+
69
+ ## 2.0.1
70
+
71
+ ### Patch Changes
72
+
73
+ - @pluv/types@2.0.1
74
+
75
+ ## 2.0.0
76
+
77
+ ### Patch Changes
78
+
79
+ - 047a1d8: Moved several internal types to `@pluv/types`.
80
+ - Updated dependencies [047a1d8]
81
+ - @pluv/types@2.0.0
82
+
83
+ ## 1.0.2
84
+
85
+ ### Patch Changes
86
+
87
+ - @pluv/types@1.0.2
88
+
89
+ ## 1.0.1
90
+
91
+ ### Patch Changes
92
+
93
+ - @pluv/types@1.0.1
94
+
95
+ ## 1.0.0
96
+
97
+ ### Major Changes
98
+
99
+ - af94706: pluv.io is now stable and production ready!
100
+
101
+ With this v1 release, pluv.io will now follow [semantic versioning](https://semver.org/) with more comprehensive release notes for future changes to the library.
102
+
103
+ Checkout the [full documentation here](https://pluv.io/docs/introduction) to get started today!
104
+
105
+ ### Patch Changes
106
+
107
+ - Updated dependencies [af94706]
108
+ - @pluv/types@1.0.0
109
+
110
+ ## 0.44.2
111
+
112
+ ### Patch Changes
113
+
114
+ - @pluv/types@0.44.2
115
+
116
+ ## 0.44.1
117
+
118
+ ### Patch Changes
119
+
120
+ - @pluv/types@0.44.1
121
+
122
+ ## 0.44.0
123
+
124
+ ### Patch Changes
125
+
126
+ - @pluv/types@0.44.0
127
+
128
+ ## 0.43.0
129
+
130
+ ### Patch Changes
131
+
132
+ - @pluv/types@0.43.0
133
+
134
+ ## 0.42.0
135
+
136
+ ### Patch Changes
137
+
138
+ - @pluv/types@0.42.0
139
+
140
+ ## 0.41.7
141
+
142
+ ### Patch Changes
143
+
144
+ - @pluv/types@0.41.7
145
+
146
+ ## 0.41.6
147
+
148
+ ### Patch Changes
149
+
150
+ - @pluv/types@0.41.6
151
+
152
+ ## 0.41.5
153
+
154
+ ### Patch Changes
155
+
156
+ - @pluv/types@0.41.5
157
+
158
+ ## 0.41.4
159
+
160
+ ### Patch Changes
161
+
162
+ - @pluv/types@0.41.4
163
+
164
+ ## 0.41.3
165
+
166
+ ### Patch Changes
167
+
168
+ - @pluv/types@0.41.3
169
+
170
+ ## 0.41.2
171
+
172
+ ### Patch Changes
173
+
174
+ - @pluv/types@0.41.2
175
+
176
+ ## 0.41.1
177
+
178
+ ### Patch Changes
179
+
180
+ - @pluv/types@0.41.1
181
+
182
+ ## 0.41.0
183
+
184
+ ### Patch Changes
185
+
186
+ - @pluv/types@0.41.0
187
+
188
+ ## 0.40.2
189
+
190
+ ### Patch Changes
191
+
192
+ - @pluv/types@0.40.2
193
+
194
+ ## 0.40.1
195
+
196
+ ### Patch Changes
197
+
198
+ - @pluv/types@0.40.1
199
+
200
+ ## 0.40.0
201
+
202
+ ### Patch Changes
203
+
204
+ - @pluv/types@0.40.0
205
+
206
+ ## 0.39.1
207
+
208
+ ### Patch Changes
209
+
210
+ - @pluv/types@0.39.1
211
+
212
+ ## 0.39.0
213
+
214
+ ### Patch Changes
215
+
216
+ - @pluv/types@0.39.0
217
+
218
+ ## 0.38.14
219
+
220
+ ### Patch Changes
221
+
222
+ - @pluv/types@0.38.14
223
+
224
+ ## 0.38.13
225
+
226
+ ### Patch Changes
227
+
228
+ - @pluv/types@0.38.13
229
+
230
+ ## 0.38.12
231
+
232
+ ### Patch Changes
233
+
234
+ - @pluv/types@0.38.12
235
+
236
+ ## 0.38.11
237
+
238
+ ### Patch Changes
239
+
240
+ - @pluv/types@0.38.11
241
+
242
+ ## 0.38.10
243
+
244
+ ### Patch Changes
245
+
246
+ - @pluv/types@0.38.10
247
+
248
+ ## 0.38.9
249
+
250
+ ### Patch Changes
251
+
252
+ - @pluv/types@0.38.9
253
+
254
+ ## 0.38.8
255
+
256
+ ### Patch Changes
257
+
258
+ - @pluv/types@0.38.8
259
+
260
+ ## 0.38.7
261
+
262
+ ### Patch Changes
263
+
264
+ - @pluv/types@0.38.7
265
+
266
+ ## 0.38.6
267
+
268
+ ### Patch Changes
269
+
270
+ - @pluv/types@0.38.6
271
+
272
+ ## 0.38.5
273
+
274
+ ### Patch Changes
275
+
276
+ - @pluv/types@0.38.5
277
+
278
+ ## 0.38.4
279
+
280
+ ### Patch Changes
281
+
282
+ - @pluv/types@0.38.4
283
+
284
+ ## 0.38.3
285
+
286
+ ### Patch Changes
287
+
288
+ - @pluv/types@0.38.3
289
+
290
+ ## 0.38.2
291
+
292
+ ### Patch Changes
293
+
294
+ - @pluv/types@0.38.2
295
+
296
+ ## 0.38.1
297
+
298
+ ### Patch Changes
299
+
300
+ - @pluv/types@0.38.1
301
+
302
+ ## 0.38.0
303
+
304
+ ### Patch Changes
305
+
306
+ - Updated dependencies [f4ceca3]
307
+ - @pluv/types@0.38.0
308
+
309
+ ## 0.37.7
310
+
311
+ ### Patch Changes
312
+
313
+ - @pluv/types@0.37.7
314
+
315
+ ## 0.37.6
316
+
317
+ ### Patch Changes
318
+
319
+ - @pluv/types@0.37.6
320
+
321
+ ## 0.37.5
322
+
323
+ ### Patch Changes
324
+
325
+ - @pluv/types@0.37.5
326
+
327
+ ## 0.37.4
328
+
329
+ ### Patch Changes
330
+
331
+ - @pluv/types@0.37.4
332
+
333
+ ## 0.37.3
334
+
335
+ ### Patch Changes
336
+
337
+ - @pluv/types@0.37.3
338
+
339
+ ## 0.37.2
340
+
341
+ ### Patch Changes
342
+
343
+ - @pluv/types@0.37.2
344
+
345
+ ## 0.37.1
346
+
347
+ ### Patch Changes
348
+
349
+ - @pluv/types@0.37.1
350
+
351
+ ## 0.37.0
352
+
353
+ ### Patch Changes
354
+
355
+ - @pluv/types@0.37.0
356
+
357
+ ## 0.36.0
358
+
359
+ ### Patch Changes
360
+
361
+ - @pluv/types@0.36.0
362
+
363
+ ## 0.35.4
364
+
365
+ ### Patch Changes
366
+
367
+ - @pluv/types@0.35.4
368
+
369
+ ## 0.35.3
370
+
371
+ ### Patch Changes
372
+
373
+ - @pluv/types@0.35.3
374
+
375
+ ## 0.35.2
376
+
377
+ ### Patch Changes
378
+
379
+ - Updated dependencies [81cb692]
380
+ - @pluv/types@0.35.2
381
+
382
+ ## 0.35.1
383
+
384
+ ### Patch Changes
385
+
386
+ - @pluv/types@0.35.1
387
+
388
+ ## 0.35.0
389
+
390
+ ### Patch Changes
391
+
392
+ - @pluv/types@0.35.0
393
+
394
+ ## 0.34.1
395
+
396
+ ### Patch Changes
397
+
398
+ - @pluv/types@0.34.1
399
+
400
+ ## 0.34.0
401
+
402
+ ### Patch Changes
403
+
404
+ - @pluv/types@0.34.0
405
+
406
+ ## 0.33.0
407
+
408
+ ### Patch Changes
409
+
410
+ - @pluv/types@0.33.0
411
+
412
+ ## 0.32.9
413
+
414
+ ### Patch Changes
415
+
416
+ - @pluv/types@0.32.9
417
+
418
+ ## 0.32.8
419
+
420
+ ### Patch Changes
421
+
422
+ - @pluv/types@0.32.8
423
+
424
+ ## 0.32.7
425
+
426
+ ### Patch Changes
427
+
428
+ - @pluv/types@0.32.7
429
+
430
+ ## 0.32.6
431
+
432
+ ### Patch Changes
433
+
434
+ - @pluv/types@0.32.6
435
+
436
+ ## 0.32.5
437
+
438
+ ### Patch Changes
439
+
440
+ - @pluv/types@0.32.5
441
+
442
+ ## 0.32.4
443
+
444
+ ### Patch Changes
445
+
446
+ - @pluv/types@0.32.4
447
+
448
+ ## 0.32.3
449
+
450
+ ### Patch Changes
451
+
452
+ - @pluv/types@0.32.3
453
+
454
+ ## 0.32.2
455
+
456
+ ### Patch Changes
457
+
458
+ - @pluv/types@0.32.2
459
+
460
+ ## 0.32.1
461
+
462
+ ### Patch Changes
463
+
464
+ - @pluv/types@0.32.1
465
+
466
+ ## 0.32.0
467
+
468
+ ### Patch Changes
469
+
470
+ - @pluv/types@0.32.0
471
+
472
+ ## 0.31.0
473
+
474
+ ### Patch Changes
475
+
476
+ - @pluv/types@0.31.0
477
+
478
+ ## 0.30.2
479
+
480
+ ### Patch Changes
481
+
482
+ - @pluv/types@0.30.2
483
+
484
+ ## 0.30.1
485
+
486
+ ### Patch Changes
487
+
488
+ - @pluv/types@0.30.1
489
+
490
+ ## 0.30.0
491
+
492
+ ### Patch Changes
493
+
494
+ - @pluv/types@0.30.0
495
+
496
+ ## 0.29.0
497
+
498
+ ### Patch Changes
499
+
500
+ - @pluv/types@0.29.0
501
+
502
+ ## 0.28.0
503
+
504
+ ### Patch Changes
505
+
506
+ - @pluv/types@0.28.0
507
+
508
+ ## 0.27.0
509
+
510
+ ### Patch Changes
511
+
512
+ - @pluv/types@0.27.0
513
+
514
+ ## 0.26.0
515
+
516
+ ### Patch Changes
517
+
518
+ - @pluv/types@0.26.0
519
+
520
+ ## 0.25.4
521
+
522
+ ### Patch Changes
523
+
524
+ - @pluv/types@0.25.4
525
+
526
+ ## 0.25.3
527
+
528
+ ### Patch Changes
529
+
530
+ - @pluv/types@0.25.3
531
+
532
+ ## 0.25.2
533
+
534
+ ### Patch Changes
535
+
536
+ - @pluv/types@0.25.2
537
+
538
+ ## 0.25.1
539
+
540
+ ### Patch Changes
541
+
542
+ - @pluv/types@0.25.1
543
+
544
+ ## 0.25.0
545
+
546
+ ### Patch Changes
547
+
548
+ - @pluv/types@0.25.0
549
+
550
+ ## 0.24.1
551
+
552
+ ### Patch Changes
553
+
554
+ - @pluv/types@0.24.1
555
+
556
+ ## 0.24.0
557
+
558
+ ### Patch Changes
559
+
560
+ - @pluv/types@0.24.0
561
+
562
+ ## 0.23.0
563
+
564
+ ### Patch Changes
565
+
566
+ - @pluv/types@0.23.0
567
+
568
+ ## 0.22.0
569
+
570
+ ### Patch Changes
571
+
572
+ - @pluv/types@0.22.0
573
+
574
+ ## 0.21.1
575
+
576
+ ### Patch Changes
577
+
578
+ - @pluv/types@0.21.1
579
+
580
+ ## 0.21.0
581
+
582
+ ### Patch Changes
583
+
584
+ - @pluv/types@0.21.0
585
+
586
+ ## 0.20.0
587
+
588
+ ### Minor Changes
589
+
590
+ - 9492085: **BREAKING**: `@pluv/crdt-yjs` and `@pluv/crdt-loro` have been updated so that the utilities to create shared-types/containers no-longer return a wrapper around the underlying shared-types and containers, but rather return the shared-types/containers directly.
591
+
592
+ This means that for methods such as `getStorage` from `@pluv/client` and `useStorage` from `@pluv/react`, the shared-types/containers are also returned instead of the wrapper types.
593
+
594
+ The motivation for these changes are so that pluv.io is supplementary to `yjs` and `loro-crdt`, instead of having these libraries be an internal implementation of pluv.io.
595
+
596
+ ```ts
597
+ // Before
598
+
599
+ import { yjs } from "@pluv/crdt-yjs";
600
+
601
+ yjs.array([]); // Returns CrdtYjsArray
602
+ yjs.object([]); // Returns CrdtYjsObject
603
+
604
+ const room: PluvRoom = /* ... */;
605
+
606
+ room.getStorage("messages"); // Returns AbstractCrdtType
607
+
608
+ const [, sharedType] = useStorage("messages"); // sharedType is an AbstractCrdtType
609
+ ```
610
+
611
+ ```ts
612
+ // Now
613
+
614
+ import { yjs } from "@pluv/crdt-yjs";
615
+
616
+ yjs.array([]); // Returns yjs.Array
617
+ yjs.object([]); // Returns yjs.Map
618
+
619
+ const room: PluvRoom = /* ... */;
620
+
621
+ room.getStorage("messages"); // Returns yjs.AbstractType
622
+
623
+ const [, sharedType] = useStorage("messages"); // sharedType is a yjs.AbstractType
624
+ ```
625
+
626
+ For `@pluv/crdt-loro` specifically, `@pluv/client` relies on [loro events and subscriptions](https://www.loro.dev/docs/tutorial/get_started#event) to detect changes. The `AbstractLoroCrdt` types previously called `Loro.commit` after each change as an abstraction, but now this no-longer happens. To ensure that changes to loro containers are properly handled in `@pluv/react`, make sure to commit your changes whenever possible:
627
+
628
+ ```ts
629
+ // Before
630
+
631
+ const [data, container] = useStorage("messages");
632
+
633
+ // This automatically called Loro.commit under the hood and rerendered the page with updated data.
634
+ container.push(loro.object({ name: "John Doe", age: 35 }));
635
+ ```
636
+
637
+ ```ts
638
+ // Now
639
+
640
+ const [data, container] = useStorage("messages");
641
+
642
+ const doc = useDoc();
643
+ const transact = useTransact();
644
+
645
+ // Updates need to be committed back to the doc whenever the changes need to be emitted to other users
646
+ // The returned data also will not update until the changes are commited
647
+
648
+ // The two operations below are functionally equivalent
649
+ transact(() => {
650
+ container.push(loro.object({ name: "John Doe", age: 35 }));
651
+ });
652
+
653
+ container.push(loro.object({ name: "John Doe", age: 35 }));
654
+ doc.value.commit();
655
+ ```
656
+
657
+ ### Patch Changes
658
+
659
+ - @pluv/types@0.20.0
660
+
661
+ ## 0.19.0
662
+
663
+ ### Patch Changes
664
+
665
+ - @pluv/types@0.19.0
666
+
667
+ ## 0.18.0
668
+
669
+ ### Patch Changes
670
+
671
+ - Updated dependencies [99b5ca9]
672
+ - @pluv/types@0.18.0
673
+
674
+ ## 0.17.3
675
+
676
+ ### Patch Changes
677
+
678
+ - @pluv/types@0.17.3
679
+
680
+ ## 0.17.2
681
+
682
+ ### Patch Changes
683
+
684
+ - @pluv/types@0.17.2
685
+
686
+ ## 0.17.1
687
+
688
+ ### Patch Changes
689
+
690
+ - @pluv/types@0.17.1
691
+
692
+ ## 0.17.0
693
+
694
+ ### Patch Changes
695
+
696
+ - Updated dependencies [507bc00]
697
+ - @pluv/types@0.17.0
698
+
699
+ ## 0.16.3
700
+
701
+ ### Patch Changes
702
+
703
+ - @pluv/types@0.16.3
704
+
705
+ ## 0.16.2
706
+
707
+ ### Patch Changes
708
+
709
+ - @pluv/types@0.16.2
710
+
711
+ ## 0.16.1
712
+
713
+ ### Patch Changes
714
+
715
+ - @pluv/types@0.16.1
716
+
717
+ ## 0.16.0
718
+
719
+ ### Patch Changes
720
+
721
+ - @pluv/types@0.16.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Shoubhit Dash
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,50 @@
1
+ import { CrdtType, CrdtDocLike, DocApplyEncodedStateParams, DocBatchApplyEncodedStateParams, DocSubscribeCallbackParams } from '@pluv/types';
2
+ export { CrdtDocLike, CrdtType, DocApplyEncodedStateParams, DocBatchApplyEncodedStateParams, DocSubscribeCallbackParams, InferCrdtJson } from '@pluv/types';
3
+
4
+ declare abstract class AbstractCrdtDocFactory<TDoc extends any, TStorage extends Record<string, CrdtType<any, any>>> {
5
+ _initialStorage: (builder: any) => TStorage;
6
+ constructor(initialStorage: (builder: any) => TStorage);
7
+ abstract getEmpty(): CrdtDocLike<TDoc, TStorage>;
8
+ abstract getFactory(initialStorage?: (builder: any) => TStorage): AbstractCrdtDocFactory<TDoc, TStorage>;
9
+ abstract getInitialized(initialStorage?: (builder: any) => TStorage): CrdtDocLike<TDoc, TStorage>;
10
+ resolveEncodedState(updates: string | string[] | readonly string[]): string | null;
11
+ }
12
+
13
+ declare class NoopCrdtDoc implements CrdtDocLike<any, any> {
14
+ value: any;
15
+ applyEncodedState(params: DocApplyEncodedStateParams): this;
16
+ batchApplyEncodedState(params: DocBatchApplyEncodedStateParams): this;
17
+ canRedo(): boolean;
18
+ canUndo(): boolean;
19
+ destroy(): void;
20
+ get(key?: undefined): {};
21
+ get<TKey extends never>(key: TKey): {}[TKey];
22
+ getEncodedState(): string;
23
+ isEmpty(): boolean;
24
+ rebuildStorage(): this;
25
+ redo(): this;
26
+ subscribe(listener: (params: DocSubscribeCallbackParams<any, any>) => void): () => void;
27
+ toJson(): any;
28
+ track(): this;
29
+ transact(fn: () => void, origin?: string | undefined): this;
30
+ undo(): this;
31
+ }
32
+
33
+ declare class NoopCrdtDocFactory extends AbstractCrdtDocFactory<any, any> {
34
+ constructor(initialStorage?: () => {});
35
+ getEmpty(): NoopCrdtDoc;
36
+ getFactory(initialStorage?: ((builder: any) => any) | undefined): NoopCrdtDocFactory;
37
+ getInitialized(initialStorage?: ((builder: any) => any) | undefined): NoopCrdtDoc;
38
+ }
39
+
40
+ declare const noop: {
41
+ doc: (args?: any) => NoopCrdtDocFactory;
42
+ };
43
+
44
+ type InferDoc<TFactory extends AbstractCrdtDocFactory<any, any>> = InferDocLike<TFactory>["value"];
45
+ type InferDocLike<TFactory extends AbstractCrdtDocFactory<any, any>> = ReturnType<TFactory["getInitialized"]>;
46
+ type InferInitialStorageFn<TFactory extends AbstractCrdtDocFactory<any, any>> = TFactory["_initialStorage"];
47
+ type InferStorage<TFactory extends AbstractCrdtDocFactory<any, any>> = ReturnType<InferInitialStorageFn<TFactory>>;
48
+ type InferBuilder<TFactory extends AbstractCrdtDocFactory<any, any>> = Parameters<InferInitialStorageFn<TFactory>>[0];
49
+
50
+ export { AbstractCrdtDocFactory, type InferBuilder, type InferDoc, type InferDocLike, type InferInitialStorageFn, type InferStorage, NoopCrdtDoc, NoopCrdtDocFactory, noop };
@@ -0,0 +1,50 @@
1
+ import { CrdtType, CrdtDocLike, DocApplyEncodedStateParams, DocBatchApplyEncodedStateParams, DocSubscribeCallbackParams } from '@pluv/types';
2
+ export { CrdtDocLike, CrdtType, DocApplyEncodedStateParams, DocBatchApplyEncodedStateParams, DocSubscribeCallbackParams, InferCrdtJson } from '@pluv/types';
3
+
4
+ declare abstract class AbstractCrdtDocFactory<TDoc extends any, TStorage extends Record<string, CrdtType<any, any>>> {
5
+ _initialStorage: (builder: any) => TStorage;
6
+ constructor(initialStorage: (builder: any) => TStorage);
7
+ abstract getEmpty(): CrdtDocLike<TDoc, TStorage>;
8
+ abstract getFactory(initialStorage?: (builder: any) => TStorage): AbstractCrdtDocFactory<TDoc, TStorage>;
9
+ abstract getInitialized(initialStorage?: (builder: any) => TStorage): CrdtDocLike<TDoc, TStorage>;
10
+ resolveEncodedState(updates: string | string[] | readonly string[]): string | null;
11
+ }
12
+
13
+ declare class NoopCrdtDoc implements CrdtDocLike<any, any> {
14
+ value: any;
15
+ applyEncodedState(params: DocApplyEncodedStateParams): this;
16
+ batchApplyEncodedState(params: DocBatchApplyEncodedStateParams): this;
17
+ canRedo(): boolean;
18
+ canUndo(): boolean;
19
+ destroy(): void;
20
+ get(key?: undefined): {};
21
+ get<TKey extends never>(key: TKey): {}[TKey];
22
+ getEncodedState(): string;
23
+ isEmpty(): boolean;
24
+ rebuildStorage(): this;
25
+ redo(): this;
26
+ subscribe(listener: (params: DocSubscribeCallbackParams<any, any>) => void): () => void;
27
+ toJson(): any;
28
+ track(): this;
29
+ transact(fn: () => void, origin?: string | undefined): this;
30
+ undo(): this;
31
+ }
32
+
33
+ declare class NoopCrdtDocFactory extends AbstractCrdtDocFactory<any, any> {
34
+ constructor(initialStorage?: () => {});
35
+ getEmpty(): NoopCrdtDoc;
36
+ getFactory(initialStorage?: ((builder: any) => any) | undefined): NoopCrdtDocFactory;
37
+ getInitialized(initialStorage?: ((builder: any) => any) | undefined): NoopCrdtDoc;
38
+ }
39
+
40
+ declare const noop: {
41
+ doc: (args?: any) => NoopCrdtDocFactory;
42
+ };
43
+
44
+ type InferDoc<TFactory extends AbstractCrdtDocFactory<any, any>> = InferDocLike<TFactory>["value"];
45
+ type InferDocLike<TFactory extends AbstractCrdtDocFactory<any, any>> = ReturnType<TFactory["getInitialized"]>;
46
+ type InferInitialStorageFn<TFactory extends AbstractCrdtDocFactory<any, any>> = TFactory["_initialStorage"];
47
+ type InferStorage<TFactory extends AbstractCrdtDocFactory<any, any>> = ReturnType<InferInitialStorageFn<TFactory>>;
48
+ type InferBuilder<TFactory extends AbstractCrdtDocFactory<any, any>> = Parameters<InferInitialStorageFn<TFactory>>[0];
49
+
50
+ export { AbstractCrdtDocFactory, type InferBuilder, type InferDoc, type InferDocLike, type InferInitialStorageFn, type InferStorage, NoopCrdtDoc, NoopCrdtDocFactory, noop };
package/dist/index.js ADDED
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ AbstractCrdtDocFactory: () => AbstractCrdtDocFactory,
24
+ NoopCrdtDoc: () => NoopCrdtDoc,
25
+ NoopCrdtDocFactory: () => NoopCrdtDocFactory,
26
+ noop: () => noop
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+
30
+ // src/AbstractCrdtDocFactory.ts
31
+ var AbstractCrdtDocFactory = class {
32
+ constructor(initialStorage) {
33
+ this._initialStorage = initialStorage;
34
+ }
35
+ resolveEncodedState(updates) {
36
+ if (typeof updates === "string") return updates;
37
+ if (!updates.length) return null;
38
+ return this.getEmpty().batchApplyEncodedState({ updates }).getEncodedState();
39
+ }
40
+ };
41
+
42
+ // src/NoopCrdtDoc.ts
43
+ var NoopCrdtDoc = class {
44
+ constructor() {
45
+ this.value = null;
46
+ }
47
+ applyEncodedState(params) {
48
+ return this;
49
+ }
50
+ batchApplyEncodedState(params) {
51
+ return this;
52
+ }
53
+ canRedo() {
54
+ return false;
55
+ }
56
+ canUndo() {
57
+ return false;
58
+ }
59
+ destroy() {
60
+ return;
61
+ }
62
+ get(key) {
63
+ return typeof key === "string" ? void 0 : {};
64
+ }
65
+ getEncodedState() {
66
+ return "";
67
+ }
68
+ isEmpty() {
69
+ return true;
70
+ }
71
+ rebuildStorage() {
72
+ return this;
73
+ }
74
+ redo() {
75
+ return this;
76
+ }
77
+ subscribe(listener) {
78
+ return () => void 0;
79
+ }
80
+ toJson() {
81
+ return {};
82
+ }
83
+ track() {
84
+ return this;
85
+ }
86
+ transact(fn, origin) {
87
+ fn();
88
+ return this;
89
+ }
90
+ undo() {
91
+ return this;
92
+ }
93
+ };
94
+
95
+ // src/NoopCrdtDocFactory.ts
96
+ var NoopCrdtDocFactory = class extends AbstractCrdtDocFactory {
97
+ constructor(initialStorage = () => ({})) {
98
+ super(initialStorage);
99
+ }
100
+ getEmpty() {
101
+ return new NoopCrdtDoc();
102
+ }
103
+ getFactory(initialStorage) {
104
+ return this;
105
+ }
106
+ getInitialized(initialStorage) {
107
+ return new NoopCrdtDoc();
108
+ }
109
+ };
110
+
111
+ // src/noop.ts
112
+ var noop = {
113
+ doc: (args) => new NoopCrdtDocFactory()
114
+ };
115
+ // Annotate the CommonJS export names for ESM import in node:
116
+ 0 && (module.exports = {
117
+ AbstractCrdtDocFactory,
118
+ NoopCrdtDoc,
119
+ NoopCrdtDocFactory,
120
+ noop
121
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,91 @@
1
+ // src/AbstractCrdtDocFactory.ts
2
+ var AbstractCrdtDocFactory = class {
3
+ constructor(initialStorage) {
4
+ this._initialStorage = initialStorage;
5
+ }
6
+ resolveEncodedState(updates) {
7
+ if (typeof updates === "string") return updates;
8
+ if (!updates.length) return null;
9
+ return this.getEmpty().batchApplyEncodedState({ updates }).getEncodedState();
10
+ }
11
+ };
12
+
13
+ // src/NoopCrdtDoc.ts
14
+ var NoopCrdtDoc = class {
15
+ constructor() {
16
+ this.value = null;
17
+ }
18
+ applyEncodedState(params) {
19
+ return this;
20
+ }
21
+ batchApplyEncodedState(params) {
22
+ return this;
23
+ }
24
+ canRedo() {
25
+ return false;
26
+ }
27
+ canUndo() {
28
+ return false;
29
+ }
30
+ destroy() {
31
+ return;
32
+ }
33
+ get(key) {
34
+ return typeof key === "string" ? void 0 : {};
35
+ }
36
+ getEncodedState() {
37
+ return "";
38
+ }
39
+ isEmpty() {
40
+ return true;
41
+ }
42
+ rebuildStorage() {
43
+ return this;
44
+ }
45
+ redo() {
46
+ return this;
47
+ }
48
+ subscribe(listener) {
49
+ return () => void 0;
50
+ }
51
+ toJson() {
52
+ return {};
53
+ }
54
+ track() {
55
+ return this;
56
+ }
57
+ transact(fn, origin) {
58
+ fn();
59
+ return this;
60
+ }
61
+ undo() {
62
+ return this;
63
+ }
64
+ };
65
+
66
+ // src/NoopCrdtDocFactory.ts
67
+ var NoopCrdtDocFactory = class extends AbstractCrdtDocFactory {
68
+ constructor(initialStorage = () => ({})) {
69
+ super(initialStorage);
70
+ }
71
+ getEmpty() {
72
+ return new NoopCrdtDoc();
73
+ }
74
+ getFactory(initialStorage) {
75
+ return this;
76
+ }
77
+ getInitialized(initialStorage) {
78
+ return new NoopCrdtDoc();
79
+ }
80
+ };
81
+
82
+ // src/noop.ts
83
+ var noop = {
84
+ doc: (args) => new NoopCrdtDocFactory()
85
+ };
86
+ export {
87
+ AbstractCrdtDocFactory,
88
+ NoopCrdtDoc,
89
+ NoopCrdtDocFactory,
90
+ noop
91
+ };
@@ -0,0 +1,4 @@
1
+ import { config } from "eslint-config-pluv/base";
2
+
3
+ /** @type {import("eslint").Linter.Config} */
4
+ export default config;
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@pluv/crdt",
3
+ "version": "0.0.0-experimental-20250527040415",
4
+ "description": "crdt base for @pluv/io",
5
+ "author": "leedavidcs",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/pluv-io/pluv",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/pluv-io/pluv.git",
11
+ "directory": "packages/crdt"
12
+ },
13
+ "main": "./dist/index.js",
14
+ "module": "./dist/index.mjs",
15
+ "types": "./dist/index.d.ts",
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "dependencies": {
20
+ "@pluv/types": "^0.0.0-experimental-20250527040415"
21
+ },
22
+ "devDependencies": {
23
+ "eslint": "^9.27.0",
24
+ "tsup": "^8.5.0",
25
+ "typescript": "^5.8.3",
26
+ "@pluv/tsconfig": "^0.0.0-experimental-20250527040415",
27
+ "eslint-config-pluv": "^0.0.0-experimental-20250527040415"
28
+ },
29
+ "scripts": {
30
+ "build": "tsup src/index.ts --format esm,cjs --dts",
31
+ "dev": "tsup src/index.ts --format esm,cjs --watch --dts",
32
+ "lint": "eslint \"src/**/*.ts*\" --fix --max-warnings 0",
33
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
34
+ }
35
+ }
@@ -0,0 +1,27 @@
1
+ import type { CrdtDocLike, CrdtType } from "@pluv/types";
2
+
3
+ export abstract class AbstractCrdtDocFactory<
4
+ TDoc extends any,
5
+ TStorage extends Record<string, CrdtType<any, any>>,
6
+ > {
7
+ public _initialStorage: (builder: any) => TStorage;
8
+
9
+ constructor(initialStorage: (builder: any) => TStorage) {
10
+ this._initialStorage = initialStorage;
11
+ }
12
+
13
+ public abstract getEmpty(): CrdtDocLike<TDoc, TStorage>;
14
+ public abstract getFactory(
15
+ initialStorage?: (builder: any) => TStorage,
16
+ ): AbstractCrdtDocFactory<TDoc, TStorage>;
17
+ public abstract getInitialized(
18
+ initialStorage?: (builder: any) => TStorage,
19
+ ): CrdtDocLike<TDoc, TStorage>;
20
+
21
+ public resolveEncodedState(updates: string | string[] | readonly string[]): string | null {
22
+ if (typeof updates === "string") return updates;
23
+ if (!updates.length) return null;
24
+
25
+ return this.getEmpty().batchApplyEncodedState({ updates }).getEncodedState();
26
+ }
27
+ }
@@ -0,0 +1,74 @@
1
+ import {
2
+ CrdtDocLike,
3
+ DocApplyEncodedStateParams,
4
+ DocBatchApplyEncodedStateParams,
5
+ DocSubscribeCallbackParams,
6
+ } from "@pluv/types";
7
+
8
+ export class NoopCrdtDoc implements CrdtDocLike<any, any> {
9
+ public value: any = null;
10
+
11
+ public applyEncodedState(params: DocApplyEncodedStateParams): this {
12
+ return this;
13
+ }
14
+
15
+ public batchApplyEncodedState(params: DocBatchApplyEncodedStateParams): this {
16
+ return this;
17
+ }
18
+
19
+ public canRedo(): boolean {
20
+ return false;
21
+ }
22
+
23
+ public canUndo(): boolean {
24
+ return false;
25
+ }
26
+
27
+ public destroy(): void {
28
+ return;
29
+ }
30
+
31
+ public get(key?: undefined): {};
32
+ public get<TKey extends never>(key: TKey): {}[TKey];
33
+ public get(key?: string): {} | undefined {
34
+ return typeof key === "string" ? undefined : {};
35
+ }
36
+
37
+ public getEncodedState(): string {
38
+ return "";
39
+ }
40
+
41
+ public isEmpty(): boolean {
42
+ return true;
43
+ }
44
+
45
+ public rebuildStorage(): this {
46
+ return this;
47
+ }
48
+
49
+ public redo(): this {
50
+ return this;
51
+ }
52
+
53
+ public subscribe(listener: (params: DocSubscribeCallbackParams<any, any>) => void): () => void {
54
+ return () => undefined;
55
+ }
56
+
57
+ public toJson(): any {
58
+ return {};
59
+ }
60
+
61
+ public track(): this {
62
+ return this;
63
+ }
64
+
65
+ public transact(fn: () => void, origin?: string | undefined): this {
66
+ fn();
67
+
68
+ return this;
69
+ }
70
+
71
+ public undo(): this {
72
+ return this;
73
+ }
74
+ }
@@ -0,0 +1,20 @@
1
+ import { AbstractCrdtDocFactory } from "./AbstractCrdtDocFactory";
2
+ import { NoopCrdtDoc } from "./NoopCrdtDoc";
3
+
4
+ export class NoopCrdtDocFactory extends AbstractCrdtDocFactory<any, any> {
5
+ constructor(initialStorage: () => {} = () => ({})) {
6
+ super(initialStorage);
7
+ }
8
+
9
+ public getEmpty(): NoopCrdtDoc {
10
+ return new NoopCrdtDoc();
11
+ }
12
+
13
+ public getFactory(initialStorage?: ((builder: any) => any) | undefined): NoopCrdtDocFactory {
14
+ return this;
15
+ }
16
+
17
+ public getInitialized(initialStorage?: ((builder: any) => any) | undefined): NoopCrdtDoc {
18
+ return new NoopCrdtDoc();
19
+ }
20
+ }
package/src/index.ts ADDED
@@ -0,0 +1,19 @@
1
+ export type {
2
+ CrdtDocLike,
3
+ CrdtType,
4
+ DocApplyEncodedStateParams,
5
+ DocBatchApplyEncodedStateParams,
6
+ DocSubscribeCallbackParams,
7
+ InferCrdtJson,
8
+ } from "@pluv/types";
9
+ export { AbstractCrdtDocFactory } from "./AbstractCrdtDocFactory";
10
+ export { noop } from "./noop";
11
+ export { NoopCrdtDoc } from "./NoopCrdtDoc";
12
+ export { NoopCrdtDocFactory } from "./NoopCrdtDocFactory";
13
+ export type {
14
+ InferBuilder,
15
+ InferDoc,
16
+ InferDocLike,
17
+ InferInitialStorageFn,
18
+ InferStorage,
19
+ } from "./types";
package/src/noop.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { NoopCrdtDocFactory } from "./NoopCrdtDocFactory";
2
+
3
+ export const noop = {
4
+ doc: (args?: any) => new NoopCrdtDocFactory(),
5
+ };
package/src/types.ts ADDED
@@ -0,0 +1,19 @@
1
+ import type { AbstractCrdtDocFactory } from "./AbstractCrdtDocFactory";
2
+
3
+ export type InferDoc<TFactory extends AbstractCrdtDocFactory<any, any>> =
4
+ InferDocLike<TFactory>["value"];
5
+
6
+ export type InferDocLike<TFactory extends AbstractCrdtDocFactory<any, any>> = ReturnType<
7
+ TFactory["getInitialized"]
8
+ >;
9
+
10
+ export type InferInitialStorageFn<TFactory extends AbstractCrdtDocFactory<any, any>> =
11
+ TFactory["_initialStorage"];
12
+
13
+ export type InferStorage<TFactory extends AbstractCrdtDocFactory<any, any>> = ReturnType<
14
+ InferInitialStorageFn<TFactory>
15
+ >;
16
+
17
+ export type InferBuilder<TFactory extends AbstractCrdtDocFactory<any, any>> = Parameters<
18
+ InferInitialStorageFn<TFactory>
19
+ >[0];
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "@pluv/tsconfig/library.json",
3
+ "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
4
+ "exclude": ["node_modules"],
5
+ "compilerOptions": {
6
+ "lib": ["esnext"]
7
+ }
8
+ }