@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.
@@ -1,17 +1,18 @@
1
1
 
2
- > @pluv/crdt-yjs@0.3.8 build /home/runner/work/pluv/pluv/packages/crdt-yjs
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
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
- CLI tsup v6.7.0
7
+ CLI tsup v7.1.0
8
8
  CLI Target: es6
9
9
  ESM Build start
10
10
  CJS Build start
11
- ESM dist/index.mjs 3.57 KB
12
- ESM ⚡️ Build success in 77ms
13
- CJS dist/index.js 4.77 KB
14
- CJS ⚡️ Build success in 79ms
11
+ CJS dist/index.js 4.87 KB
12
+ CJS ⚡️ Build success in 73ms
13
+ ESM dist/index.mjs 3.68 KB
14
+ ESM ⚡️ Build success in 73ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 1561ms
17
- DTS dist/index.d.ts 3.10 KB
16
+ DTS ⚡️ Build success in 2186ms
17
+ DTS dist/index.d.mts 3.17 KB
18
+ DTS dist/index.d.ts 3.17 KB
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
@@ -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: string, doc: Doc, transaction: Transaction) => void): () => void;
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(YjsDoc.fromUint8Array(update), origin, doc2, transaction);
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 { applyUpdate, Doc as YDoc, encodeStateAsUpdate } from "yjs";
32
- var YjsDoc = class {
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(YjsDoc.fromUint8Array(update), origin, doc2, transaction);
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 YMap } from "yjs";
98
+ import { Map as YMap2 } from "yjs";
90
99
  var map = (value = []) => {
91
- return new YMap(value);
100
+ return new YMap2(value);
92
101
  };
93
102
 
94
103
  // src/object.ts
95
- import { Map as YMap2 } from "yjs";
104
+ import { Map as YMap3 } from "yjs";
96
105
  var object = (value) => {
97
- return new YMap2(Object.entries(value));
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.8",
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.0"
22
+ "@pluv/types": "^0.2.2"
22
23
  },
23
24
  "peerDependencies": {
24
25
  "yjs": "^13.0.0"
25
26
  },
26
27
  "devDependencies": {
27
- "tsup": "^6.7.0",
28
- "typescript": "^5.0.4",
29
- "yjs": "^13.6.1",
30
- "@pluv/tsconfig": "^0.1.6",
31
- "eslint-config-pluv": "^0.1.12"
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
@@ -1,7 +1,7 @@
1
1
  import { Array as YArray } from "yjs";
2
2
 
3
3
  export const array = <T extends unknown>(
4
- value: readonly T[] = []
4
+ value: readonly T[] = [],
5
5
  ): YArray<T> => {
6
6
  const yarray = new YArray<T>();
7
7
 
package/src/doc.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import { fromUint8Array, toUint8Array } from "js-base64";
2
- import type { AbstractType, Map as YMap, Transaction } from "yjs";
3
- import { applyUpdate, Doc as YDoc, encodeStateAsUpdate } from "yjs";
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: string,
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: string,
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
@@ -1,7 +1,7 @@
1
1
  import { Map as YMap } from "yjs";
2
2
 
3
3
  export const map = <T extends unknown>(
4
- value: readonly (readonly [key: string, value: T])[] = []
4
+ value: readonly (readonly [key: string, value: T])[] = [],
5
5
  ): YMap<T> => {
6
6
  return new YMap(value);
7
7
  };
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 keyof InferYjsDocSharedTypes<TDoc> = keyof InferYjsDocSharedTypes<TDoc>
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 keyof InferYjsDocSharedTypes<TDoc> = keyof InferYjsDocSharedTypes<TDoc>
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>> =
package/src/xmlElement.ts CHANGED
@@ -7,7 +7,7 @@ export interface XmlElementParams {
7
7
 
8
8
  export const xmlElement = (
9
9
  name: string,
10
- params: XmlElementParams = {}
10
+ params: XmlElementParams = {},
11
11
  ): YXmlElement => {
12
12
  const { children = [] } = params;
13
13