@pluv/crdt-yjs 0.3.8 → 0.4.1
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/.turbo/turbo-build.log +9 -8
- package/CHANGELOG.md +58 -0
- package/dist/index.d.mts +56 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +7 -2
- package/dist/index.mjs +16 -7
- package/package.json +8 -7
- package/src/array.ts +1 -1
- package/src/doc.ts +25 -10
- package/src/map.ts +1 -1
- package/src/object.ts +1 -1
- package/src/types.ts +4 -2
- package/src/xmlElement.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/crdt-yjs@0.
|
|
2
|
+
> @pluv/crdt-yjs@0.4.1 build /home/runner/work/pluv/pluv/packages/crdt-yjs
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
-
[34mCLI[39m tsup
|
|
7
|
+
[34mCLI[39m tsup v7.1.0
|
|
8
8
|
[34mCLI[39m Target: es6
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m4.87 KB[39m
|
|
12
|
+
[32mCJS[39m ⚡️ Build success in 73ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m3.68 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 73ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 2186ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m3.17 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m3.17 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,63 @@
|
|
|
1
1
|
# @pluv/crdt-yjs
|
|
2
2
|
|
|
3
|
+
## 0.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8fba48b: fix including incorrect dependency
|
|
8
|
+
- 8997c65: bumped dependencies
|
|
9
|
+
- Updated dependencies [8fba48b]
|
|
10
|
+
- Updated dependencies [8997c65]
|
|
11
|
+
- @pluv/types@0.2.2
|
|
12
|
+
|
|
13
|
+
## 0.4.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- 829d31b: Added support for defining persistant frontend storage for rooms via a new `addons` option on rooms.
|
|
18
|
+
|
|
19
|
+
This also introduces the first new addon `@pluv/addon-indexeddb`, which is more-or-less the equivalent to `y-indexeddb` which you can install like so:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
npm install @pluv/addon-indexeddb
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
To use this new addon, simply pass it to options when creating a room:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { addonIndexedDB } from "@pluv/addon-indexeddb";
|
|
29
|
+
import { createClient } from "@pluv/client";
|
|
30
|
+
|
|
31
|
+
const client = createClient({
|
|
32
|
+
// ...
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const room = client.createRoom("my-new-room", {
|
|
36
|
+
addons: [
|
|
37
|
+
// Define your addons in an array like so
|
|
38
|
+
addonIndexedDB(),
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Or when using `@pluv/react`:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
const PluvRoom = createRoomBundle({
|
|
47
|
+
// ...
|
|
48
|
+
addons: [
|
|
49
|
+
// Define your addons in an array like so
|
|
50
|
+
addonIndexedDB(),
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Patch Changes
|
|
56
|
+
|
|
57
|
+
- 8d11672: bumped dependencies to latest
|
|
58
|
+
- Updated dependencies [8d11672]
|
|
59
|
+
- @pluv/types@0.2.1
|
|
60
|
+
|
|
3
61
|
## 0.3.8
|
|
4
62
|
|
|
5
63
|
### Patch Changes
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Array, Map, AbstractType, Text, XmlElement, XmlFragment, XmlText, Doc, Transaction } from 'yjs';
|
|
2
|
+
export { AbstractType, Array, Map, Text } from 'yjs';
|
|
3
|
+
import { JsonPrimitive } from '@pluv/types';
|
|
4
|
+
|
|
5
|
+
declare const array: <T extends unknown>(value?: readonly T[]) => Array<T>;
|
|
6
|
+
|
|
7
|
+
type unstable__YObjectValue = Record<string, NonNullable<JsonPrimitive> | AbstractType<any>>;
|
|
8
|
+
type unstable__YObject<T extends unstable__YObjectValue> = Map<T[keyof T]> & {
|
|
9
|
+
__$type: T;
|
|
10
|
+
};
|
|
11
|
+
declare const object: <T extends unstable__YObjectValue = {}>(value: T) => unstable__YObject<T>;
|
|
12
|
+
|
|
13
|
+
type InferYjsDocJson<TDoc extends YjsDoc<any>> = TDoc extends YjsDoc<infer ITypes> ? {
|
|
14
|
+
[P in keyof ITypes]: InferYjsSharedTypeJson<ITypes[P]>;
|
|
15
|
+
} : never;
|
|
16
|
+
type InferYjsDocSharedType<TDoc extends YjsDoc<any>, TKey extends keyof InferYjsDocSharedTypes<TDoc> = keyof InferYjsDocSharedTypes<TDoc>> = InferYjsDocSharedTypes<TDoc>[TKey];
|
|
17
|
+
type InferYjsDocSharedTypeJson<TDoc extends YjsDoc<any>, TKey extends keyof InferYjsDocSharedTypes<TDoc> = keyof InferYjsDocSharedTypes<TDoc>> = InferYjsSharedTypeJson<InferYjsDocSharedTypes<TDoc>[TKey]>;
|
|
18
|
+
type InferYjsDocSharedTypes<TDoc extends YjsDoc<any>> = TDoc extends YjsDoc<infer ITypes> ? ITypes : never;
|
|
19
|
+
type InferYjsSharedTypeJson<TShared extends unknown> = TShared extends AbstractType<any> ? TShared extends Array<infer IItem> ? readonly InferYjsSharedTypeJson<IItem>[] : TShared extends unstable__YObject<infer IObject> ? {
|
|
20
|
+
[P in keyof IObject]: InferYjsSharedTypeJson<IObject[P]>;
|
|
21
|
+
} : TShared extends Map<infer IItem> ? Record<string, InferYjsSharedTypeJson<IItem>> : TShared extends Text | XmlElement | XmlFragment | XmlText ? string : never : TShared;
|
|
22
|
+
|
|
23
|
+
declare class YjsDoc<T extends Record<string, AbstractType<any>> = {}> {
|
|
24
|
+
value: Doc;
|
|
25
|
+
private get _storage();
|
|
26
|
+
constructor(value?: T);
|
|
27
|
+
applyUpdate(update?: string | Uint8Array | null, origin?: string): this;
|
|
28
|
+
destroy(): void;
|
|
29
|
+
encodeStateAsUpdate(): string;
|
|
30
|
+
get<TKey extends keyof T>(key: TKey): T[TKey];
|
|
31
|
+
getSharedTypes(): T;
|
|
32
|
+
subscribe(fn: (update: string, origin: any, doc: Doc, transaction: Transaction) => void): () => void;
|
|
33
|
+
toJSON(): InferYjsDocJson<this>;
|
|
34
|
+
transact(fn: (transaction: Transaction) => void, origin?: any): void;
|
|
35
|
+
static fromUint8Array(u8a: Uint8Array): string;
|
|
36
|
+
static toUint8Array(str: string): Uint8Array;
|
|
37
|
+
}
|
|
38
|
+
declare const doc: <T extends Record<string, AbstractType<any>> = {}>(value?: T | undefined) => YjsDoc<T>;
|
|
39
|
+
|
|
40
|
+
declare const map: <T extends unknown>(value?: readonly (readonly [key: string, value: T])[]) => Map<T>;
|
|
41
|
+
|
|
42
|
+
declare const text: (value?: string) => Text;
|
|
43
|
+
|
|
44
|
+
interface XmlElementParams {
|
|
45
|
+
children?: readonly (XmlElement | XmlText)[];
|
|
46
|
+
}
|
|
47
|
+
declare const xmlElement: (name: string, params?: XmlElementParams) => XmlElement;
|
|
48
|
+
|
|
49
|
+
interface XmlFragmentParams {
|
|
50
|
+
children?: readonly (XmlElement | XmlText)[];
|
|
51
|
+
}
|
|
52
|
+
declare const xmlFragment: (params?: XmlFragmentParams) => XmlFragment;
|
|
53
|
+
|
|
54
|
+
declare const xmlText: (value?: string) => XmlText;
|
|
55
|
+
|
|
56
|
+
export { InferYjsDocJson, InferYjsDocSharedType, InferYjsDocSharedTypeJson, InferYjsDocSharedTypes, InferYjsSharedTypeJson, XmlElementParams, XmlFragmentParams, YjsDoc, array, doc, map, object, text, unstable__YObject, xmlElement, xmlFragment, xmlText };
|
package/dist/index.d.ts
CHANGED
|
@@ -29,8 +29,9 @@ declare class YjsDoc<T extends Record<string, AbstractType<any>> = {}> {
|
|
|
29
29
|
encodeStateAsUpdate(): string;
|
|
30
30
|
get<TKey extends keyof T>(key: TKey): T[TKey];
|
|
31
31
|
getSharedTypes(): T;
|
|
32
|
-
subscribe(fn: (update: string, origin:
|
|
32
|
+
subscribe(fn: (update: string, origin: any, doc: Doc, transaction: Transaction) => void): () => void;
|
|
33
33
|
toJSON(): InferYjsDocJson<this>;
|
|
34
|
+
transact(fn: (transaction: Transaction) => void, origin?: any): void;
|
|
34
35
|
static fromUint8Array(u8a: Uint8Array): string;
|
|
35
36
|
static toUint8Array(str: string): Uint8Array;
|
|
36
37
|
}
|
package/dist/index.js
CHANGED
|
@@ -60,7 +60,7 @@ var array = (value = []) => {
|
|
|
60
60
|
// src/doc.ts
|
|
61
61
|
var import_js_base64 = require("js-base64");
|
|
62
62
|
var import_yjs2 = require("yjs");
|
|
63
|
-
var YjsDoc = class {
|
|
63
|
+
var YjsDoc = class _YjsDoc {
|
|
64
64
|
constructor(value) {
|
|
65
65
|
this.value = new import_yjs2.Doc();
|
|
66
66
|
if (!value)
|
|
@@ -96,7 +96,7 @@ var YjsDoc = class {
|
|
|
96
96
|
);
|
|
97
97
|
}
|
|
98
98
|
subscribe(fn) {
|
|
99
|
-
const _fn = (update, origin, doc2, transaction) => fn(
|
|
99
|
+
const _fn = (update, origin, doc2, transaction) => fn(_YjsDoc.fromUint8Array(update), origin, doc2, transaction);
|
|
100
100
|
this.value.on("update", _fn);
|
|
101
101
|
return () => {
|
|
102
102
|
this.value.off("update", _fn);
|
|
@@ -105,6 +105,11 @@ var YjsDoc = class {
|
|
|
105
105
|
toJSON() {
|
|
106
106
|
return this._storage.toJSON();
|
|
107
107
|
}
|
|
108
|
+
transact(fn, origin) {
|
|
109
|
+
this.value.transact((tx) => {
|
|
110
|
+
fn(tx);
|
|
111
|
+
}, origin);
|
|
112
|
+
}
|
|
108
113
|
static fromUint8Array(u8a) {
|
|
109
114
|
return (0, import_js_base64.fromUint8Array)(u8a);
|
|
110
115
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -28,8 +28,12 @@ var array = (value = []) => {
|
|
|
28
28
|
|
|
29
29
|
// src/doc.ts
|
|
30
30
|
import { fromUint8Array, toUint8Array } from "js-base64";
|
|
31
|
-
import {
|
|
32
|
-
|
|
31
|
+
import {
|
|
32
|
+
Doc as YDoc,
|
|
33
|
+
applyUpdate,
|
|
34
|
+
encodeStateAsUpdate
|
|
35
|
+
} from "yjs";
|
|
36
|
+
var YjsDoc = class _YjsDoc {
|
|
33
37
|
constructor(value) {
|
|
34
38
|
this.value = new YDoc();
|
|
35
39
|
if (!value)
|
|
@@ -65,7 +69,7 @@ var YjsDoc = class {
|
|
|
65
69
|
);
|
|
66
70
|
}
|
|
67
71
|
subscribe(fn) {
|
|
68
|
-
const _fn = (update, origin, doc2, transaction) => fn(
|
|
72
|
+
const _fn = (update, origin, doc2, transaction) => fn(_YjsDoc.fromUint8Array(update), origin, doc2, transaction);
|
|
69
73
|
this.value.on("update", _fn);
|
|
70
74
|
return () => {
|
|
71
75
|
this.value.off("update", _fn);
|
|
@@ -74,6 +78,11 @@ var YjsDoc = class {
|
|
|
74
78
|
toJSON() {
|
|
75
79
|
return this._storage.toJSON();
|
|
76
80
|
}
|
|
81
|
+
transact(fn, origin) {
|
|
82
|
+
this.value.transact((tx) => {
|
|
83
|
+
fn(tx);
|
|
84
|
+
}, origin);
|
|
85
|
+
}
|
|
77
86
|
static fromUint8Array(u8a) {
|
|
78
87
|
return fromUint8Array(u8a);
|
|
79
88
|
}
|
|
@@ -86,15 +95,15 @@ var doc = (value) => {
|
|
|
86
95
|
};
|
|
87
96
|
|
|
88
97
|
// src/map.ts
|
|
89
|
-
import { Map as
|
|
98
|
+
import { Map as YMap2 } from "yjs";
|
|
90
99
|
var map = (value = []) => {
|
|
91
|
-
return new
|
|
100
|
+
return new YMap2(value);
|
|
92
101
|
};
|
|
93
102
|
|
|
94
103
|
// src/object.ts
|
|
95
|
-
import { Map as
|
|
104
|
+
import { Map as YMap3 } from "yjs";
|
|
96
105
|
var object = (value) => {
|
|
97
|
-
return new
|
|
106
|
+
return new YMap3(Object.entries(value));
|
|
98
107
|
};
|
|
99
108
|
|
|
100
109
|
// src/text.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/crdt-yjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "yjs for @pluv/io",
|
|
5
5
|
"author": "leedavidcs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,18 +17,19 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"@types/react": "^18.2.15",
|
|
20
21
|
"js-base64": "^3.7.5",
|
|
21
|
-
"@pluv/types": "^0.2.
|
|
22
|
+
"@pluv/types": "^0.2.2"
|
|
22
23
|
},
|
|
23
24
|
"peerDependencies": {
|
|
24
25
|
"yjs": "^13.0.0"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
|
-
"tsup": "^
|
|
28
|
-
"typescript": "^5.
|
|
29
|
-
"yjs": "^13.6.
|
|
30
|
-
"@pluv/tsconfig": "^0.1.
|
|
31
|
-
"eslint-config-pluv": "^0.1.
|
|
28
|
+
"tsup": "^7.1.0",
|
|
29
|
+
"typescript": "^5.1.6",
|
|
30
|
+
"yjs": "^13.6.6",
|
|
31
|
+
"@pluv/tsconfig": "^0.1.8",
|
|
32
|
+
"eslint-config-pluv": "^0.1.14"
|
|
32
33
|
},
|
|
33
34
|
"scripts": {
|
|
34
35
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
package/src/array.ts
CHANGED
package/src/doc.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { fromUint8Array, toUint8Array } from "js-base64";
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
AbstractType,
|
|
4
|
+
Transaction,
|
|
5
|
+
Doc as YDoc,
|
|
6
|
+
Map as YMap,
|
|
7
|
+
applyUpdate,
|
|
8
|
+
encodeStateAsUpdate,
|
|
9
|
+
} from "yjs";
|
|
4
10
|
import type { InferYjsDocJson } from "./types";
|
|
5
11
|
|
|
6
12
|
export class YjsDoc<T extends Record<string, AbstractType<any>> = {}> {
|
|
@@ -22,7 +28,7 @@ export class YjsDoc<T extends Record<string, AbstractType<any>> = {}> {
|
|
|
22
28
|
|
|
23
29
|
public applyUpdate(
|
|
24
30
|
update?: string | Uint8Array | null,
|
|
25
|
-
origin?: string
|
|
31
|
+
origin?: string,
|
|
26
32
|
): this {
|
|
27
33
|
if (update === null || typeof update === "undefined") return this;
|
|
28
34
|
|
|
@@ -49,23 +55,23 @@ export class YjsDoc<T extends Record<string, AbstractType<any>> = {}> {
|
|
|
49
55
|
public getSharedTypes(): T {
|
|
50
56
|
return Array.from(this._storage.keys()).reduce(
|
|
51
57
|
(acc, key) => ({ ...acc, [key]: this._storage.get(key) }),
|
|
52
|
-
{} as T
|
|
58
|
+
{} as T,
|
|
53
59
|
);
|
|
54
60
|
}
|
|
55
61
|
|
|
56
62
|
public subscribe(
|
|
57
63
|
fn: (
|
|
58
64
|
update: string,
|
|
59
|
-
origin:
|
|
65
|
+
origin: any,
|
|
60
66
|
doc: YDoc,
|
|
61
|
-
transaction: Transaction
|
|
62
|
-
) => void
|
|
67
|
+
transaction: Transaction,
|
|
68
|
+
) => void,
|
|
63
69
|
): () => void {
|
|
64
70
|
const _fn = (
|
|
65
71
|
update: Uint8Array,
|
|
66
|
-
origin:
|
|
72
|
+
origin: any,
|
|
67
73
|
doc: YDoc,
|
|
68
|
-
transaction: Transaction
|
|
74
|
+
transaction: Transaction,
|
|
69
75
|
) => fn(YjsDoc.fromUint8Array(update), origin, doc, transaction);
|
|
70
76
|
|
|
71
77
|
this.value.on("update", _fn);
|
|
@@ -79,6 +85,15 @@ export class YjsDoc<T extends Record<string, AbstractType<any>> = {}> {
|
|
|
79
85
|
return this._storage.toJSON() as InferYjsDocJson<this>;
|
|
80
86
|
}
|
|
81
87
|
|
|
88
|
+
public transact(
|
|
89
|
+
fn: (transaction: Transaction) => void,
|
|
90
|
+
origin?: any,
|
|
91
|
+
): void {
|
|
92
|
+
this.value.transact((tx) => {
|
|
93
|
+
fn(tx);
|
|
94
|
+
}, origin);
|
|
95
|
+
}
|
|
96
|
+
|
|
82
97
|
public static fromUint8Array(u8a: Uint8Array): string {
|
|
83
98
|
return fromUint8Array(u8a);
|
|
84
99
|
}
|
|
@@ -89,7 +104,7 @@ export class YjsDoc<T extends Record<string, AbstractType<any>> = {}> {
|
|
|
89
104
|
}
|
|
90
105
|
|
|
91
106
|
export const doc = <T extends Record<string, AbstractType<any>> = {}>(
|
|
92
|
-
value?: T
|
|
107
|
+
value?: T,
|
|
93
108
|
): YjsDoc<T> => {
|
|
94
109
|
return new YjsDoc(value);
|
|
95
110
|
};
|
package/src/map.ts
CHANGED
package/src/object.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type unstable__YObject<T extends unstable__YObjectValue> = YMap<
|
|
|
12
12
|
> & { __$type: T };
|
|
13
13
|
|
|
14
14
|
export const object = <T extends unstable__YObjectValue = {}>(
|
|
15
|
-
value: T
|
|
15
|
+
value: T,
|
|
16
16
|
): unstable__YObject<T> => {
|
|
17
17
|
return new YMap(Object.entries(value)) as unstable__YObject<T>;
|
|
18
18
|
};
|
package/src/types.ts
CHANGED
|
@@ -18,12 +18,14 @@ export type InferYjsDocJson<TDoc extends YjsDoc<any>> = TDoc extends YjsDoc<
|
|
|
18
18
|
|
|
19
19
|
export type InferYjsDocSharedType<
|
|
20
20
|
TDoc extends YjsDoc<any>,
|
|
21
|
-
TKey extends
|
|
21
|
+
TKey extends
|
|
22
|
+
keyof InferYjsDocSharedTypes<TDoc> = keyof InferYjsDocSharedTypes<TDoc>,
|
|
22
23
|
> = InferYjsDocSharedTypes<TDoc>[TKey];
|
|
23
24
|
|
|
24
25
|
export type InferYjsDocSharedTypeJson<
|
|
25
26
|
TDoc extends YjsDoc<any>,
|
|
26
|
-
TKey extends
|
|
27
|
+
TKey extends
|
|
28
|
+
keyof InferYjsDocSharedTypes<TDoc> = keyof InferYjsDocSharedTypes<TDoc>,
|
|
27
29
|
> = InferYjsSharedTypeJson<InferYjsDocSharedTypes<TDoc>[TKey]>;
|
|
28
30
|
|
|
29
31
|
export type InferYjsDocSharedTypes<TDoc extends YjsDoc<any>> =
|