@liveblocks/client 0.15.0-alpha.2 → 0.15.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.
Files changed (62) hide show
  1. package/lib/esm/index.js +2991 -5
  2. package/lib/esm/index.mjs +2991 -0
  3. package/lib/esm/internal.js +149 -0
  4. package/lib/esm/internal.mjs +149 -0
  5. package/lib/{esm/types.d.ts → index.d.ts} +255 -50
  6. package/lib/index.js +4237 -0
  7. package/lib/{esm/live.d.ts → internal.d.ts} +46 -34
  8. package/lib/internal.js +193 -0
  9. package/package.json +36 -9
  10. package/lib/cjs/AbstractCrdt.d.ts +0 -67
  11. package/lib/cjs/AbstractCrdt.js +0 -95
  12. package/lib/cjs/LiveList.d.ts +0 -144
  13. package/lib/cjs/LiveList.js +0 -527
  14. package/lib/cjs/LiveMap.d.ts +0 -91
  15. package/lib/cjs/LiveMap.js +0 -322
  16. package/lib/cjs/LiveObject.d.ts +0 -80
  17. package/lib/cjs/LiveObject.js +0 -453
  18. package/lib/cjs/LiveRegister.d.ts +0 -29
  19. package/lib/cjs/LiveRegister.js +0 -88
  20. package/lib/cjs/authentication.d.ts +0 -3
  21. package/lib/cjs/authentication.js +0 -71
  22. package/lib/cjs/client.d.ts +0 -27
  23. package/lib/cjs/client.js +0 -80
  24. package/lib/cjs/immutable.d.ts +0 -9
  25. package/lib/cjs/immutable.js +0 -291
  26. package/lib/cjs/index.d.ts +0 -6
  27. package/lib/cjs/index.js +0 -18
  28. package/lib/cjs/live.d.ts +0 -181
  29. package/lib/cjs/live.js +0 -49
  30. package/lib/cjs/position.d.ts +0 -6
  31. package/lib/cjs/position.js +0 -113
  32. package/lib/cjs/room.d.ts +0 -159
  33. package/lib/cjs/room.js +0 -1094
  34. package/lib/cjs/types.d.ts +0 -489
  35. package/lib/cjs/types.js +0 -2
  36. package/lib/cjs/utils.d.ts +0 -11
  37. package/lib/cjs/utils.js +0 -175
  38. package/lib/esm/AbstractCrdt.d.ts +0 -67
  39. package/lib/esm/AbstractCrdt.js +0 -91
  40. package/lib/esm/LiveList.d.ts +0 -144
  41. package/lib/esm/LiveList.js +0 -523
  42. package/lib/esm/LiveMap.d.ts +0 -91
  43. package/lib/esm/LiveMap.js +0 -318
  44. package/lib/esm/LiveObject.d.ts +0 -80
  45. package/lib/esm/LiveObject.js +0 -449
  46. package/lib/esm/LiveRegister.d.ts +0 -29
  47. package/lib/esm/LiveRegister.js +0 -84
  48. package/lib/esm/authentication.d.ts +0 -3
  49. package/lib/esm/authentication.js +0 -66
  50. package/lib/esm/client.d.ts +0 -27
  51. package/lib/esm/client.js +0 -76
  52. package/lib/esm/immutable.d.ts +0 -9
  53. package/lib/esm/immutable.js +0 -282
  54. package/lib/esm/index.d.ts +0 -6
  55. package/lib/esm/live.js +0 -46
  56. package/lib/esm/position.d.ts +0 -6
  57. package/lib/esm/position.js +0 -106
  58. package/lib/esm/room.d.ts +0 -159
  59. package/lib/esm/room.js +0 -1069
  60. package/lib/esm/types.js +0 -1
  61. package/lib/esm/utils.d.ts +0 -11
  62. package/lib/esm/utils.js +0 -164
@@ -1,67 +0,0 @@
1
- import { Op, SerializedCrdt } from "./live";
2
- import { StorageUpdate } from "./types";
3
- export declare type ApplyResult = {
4
- reverse: Op[];
5
- modified: StorageUpdate;
6
- } | {
7
- modified: false;
8
- };
9
- export interface Doc {
10
- generateId: () => string;
11
- generateOpId: () => string;
12
- addItem: (id: string, item: AbstractCrdt) => void;
13
- deleteItem: (id: string) => void;
14
- dispatch: (ops: Op[], reverseOps: Op[], storageUpdates: Map<string, StorageUpdate>) => void;
15
- }
16
- export declare abstract class AbstractCrdt {
17
- #private;
18
- /**
19
- * INTERNAL
20
- */
21
- protected get _doc(): Doc | undefined;
22
- /**
23
- * INTERNAL
24
- */
25
- get _id(): string | undefined;
26
- /**
27
- * INTERNAL
28
- */
29
- get _parent(): AbstractCrdt | undefined;
30
- /**
31
- * INTERNAL
32
- */
33
- get _parentKey(): string | undefined;
34
- /**
35
- * INTERNAL
36
- */
37
- _apply(op: Op, isLocal: boolean): ApplyResult;
38
- /**
39
- * INTERNAL
40
- */
41
- _setParentLink(parent: AbstractCrdt, key: string): void;
42
- /**
43
- * INTERNAL
44
- */
45
- _attach(id: string, doc: Doc): void;
46
- /**
47
- * INTERNAL
48
- */
49
- abstract _attachChild(id: string, key: string, crdt: AbstractCrdt, isLocal: boolean): ApplyResult;
50
- /**
51
- * INTERNAL
52
- */
53
- _detach(): void;
54
- /**
55
- * INTERNAL
56
- */
57
- abstract _detachChild(crdt: AbstractCrdt): ApplyResult;
58
- /**
59
- * INTERNAL
60
- */
61
- abstract _serialize(parentId: string, parentKey: string, doc?: Doc): Op[];
62
- /**
63
- * INTERNAL
64
- */
65
- abstract _toSerializedCrdt(): SerializedCrdt;
66
- abstract _getType(): string;
67
- }
@@ -1,91 +0,0 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
- if (kind === "m") throw new TypeError("Private method is not writable");
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
- };
12
- var _AbstractCrdt_parent, _AbstractCrdt_doc, _AbstractCrdt_id, _AbstractCrdt_parentKey;
13
- import { OpType } from "./live";
14
- export class AbstractCrdt {
15
- constructor() {
16
- _AbstractCrdt_parent.set(this, void 0);
17
- _AbstractCrdt_doc.set(this, void 0);
18
- _AbstractCrdt_id.set(this, void 0);
19
- _AbstractCrdt_parentKey.set(this, void 0);
20
- }
21
- /**
22
- * INTERNAL
23
- */
24
- get _doc() {
25
- return __classPrivateFieldGet(this, _AbstractCrdt_doc, "f");
26
- }
27
- /**
28
- * INTERNAL
29
- */
30
- get _id() {
31
- return __classPrivateFieldGet(this, _AbstractCrdt_id, "f");
32
- }
33
- /**
34
- * INTERNAL
35
- */
36
- get _parent() {
37
- return __classPrivateFieldGet(this, _AbstractCrdt_parent, "f");
38
- }
39
- /**
40
- * INTERNAL
41
- */
42
- get _parentKey() {
43
- return __classPrivateFieldGet(this, _AbstractCrdt_parentKey, "f");
44
- }
45
- /**
46
- * INTERNAL
47
- */
48
- _apply(op, isLocal) {
49
- switch (op.type) {
50
- case OpType.DeleteCrdt: {
51
- if (this._parent != null && this._parentKey != null) {
52
- return this._parent._detachChild(this);
53
- }
54
- return { modified: false };
55
- }
56
- }
57
- return { modified: false };
58
- }
59
- /**
60
- * INTERNAL
61
- */
62
- _setParentLink(parent, key) {
63
- if (__classPrivateFieldGet(this, _AbstractCrdt_parent, "f") != null && __classPrivateFieldGet(this, _AbstractCrdt_parent, "f") !== parent) {
64
- throw new Error("Cannot attach parent if it already exist");
65
- }
66
- __classPrivateFieldSet(this, _AbstractCrdt_parentKey, key, "f");
67
- __classPrivateFieldSet(this, _AbstractCrdt_parent, parent, "f");
68
- }
69
- /**
70
- * INTERNAL
71
- */
72
- _attach(id, doc) {
73
- if (__classPrivateFieldGet(this, _AbstractCrdt_id, "f") || __classPrivateFieldGet(this, _AbstractCrdt_doc, "f")) {
74
- throw new Error("Cannot attach if CRDT is already attached");
75
- }
76
- doc.addItem(id, this);
77
- __classPrivateFieldSet(this, _AbstractCrdt_id, id, "f");
78
- __classPrivateFieldSet(this, _AbstractCrdt_doc, doc, "f");
79
- }
80
- /**
81
- * INTERNAL
82
- */
83
- _detach() {
84
- if (__classPrivateFieldGet(this, _AbstractCrdt_doc, "f") && __classPrivateFieldGet(this, _AbstractCrdt_id, "f")) {
85
- __classPrivateFieldGet(this, _AbstractCrdt_doc, "f").deleteItem(__classPrivateFieldGet(this, _AbstractCrdt_id, "f"));
86
- }
87
- __classPrivateFieldSet(this, _AbstractCrdt_parent, undefined, "f");
88
- __classPrivateFieldSet(this, _AbstractCrdt_doc, undefined, "f");
89
- }
90
- }
91
- _AbstractCrdt_parent = new WeakMap(), _AbstractCrdt_doc = new WeakMap(), _AbstractCrdt_id = new WeakMap(), _AbstractCrdt_parentKey = new WeakMap();
@@ -1,144 +0,0 @@
1
- import { AbstractCrdt, Doc, ApplyResult } from "./AbstractCrdt";
2
- import { SerializedList, SerializedCrdtWithId, Op, SerializedCrdt } from "./live";
3
- /**
4
- * The LiveList class represents an ordered collection of items that is synchorinized across clients.
5
- */
6
- export declare class LiveList<T> extends AbstractCrdt {
7
- #private;
8
- constructor(items?: T[]);
9
- /**
10
- * INTERNAL
11
- */
12
- static _deserialize([id, item]: [id: string, item: SerializedList], parentToChildren: Map<string, SerializedCrdtWithId[]>, doc: Doc): LiveList<never>;
13
- /**
14
- * INTERNAL
15
- */
16
- _serialize(parentId?: string, parentKey?: string, doc?: Doc): Op[];
17
- _indexOfPosition(position: string): number;
18
- /**
19
- * INTERNAL
20
- */
21
- _attach(id: string, doc: Doc): void;
22
- /**
23
- * INTERNAL
24
- */
25
- _detach(): void;
26
- /**
27
- * INTERNAL
28
- */
29
- _attachChild(id: string, key: string, child: AbstractCrdt, isLocal: boolean): ApplyResult;
30
- /**
31
- * INTERNAL
32
- */
33
- _detachChild(child: AbstractCrdt): ApplyResult;
34
- /**
35
- * INTERNAL
36
- */
37
- _setChildKey(key: string, child: AbstractCrdt, previousKey: string): ApplyResult;
38
- /**
39
- * INTERNAL
40
- */
41
- _apply(op: Op, isLocal: boolean): ApplyResult;
42
- /**
43
- * INTERNAL
44
- */
45
- _getType(): string;
46
- /**
47
- * INTERNAL
48
- */
49
- _toSerializedCrdt(): SerializedCrdt;
50
- /**
51
- * Returns the number of elements.
52
- */
53
- get length(): number;
54
- /**
55
- * Adds one element to the end of the LiveList.
56
- * @param element The element to add to the end of the LiveList.
57
- */
58
- push(element: T): void;
59
- /**
60
- * Inserts one element at a specified index.
61
- * @param element The element to insert.
62
- * @param index The index at which you want to insert the element.
63
- */
64
- insert(element: T, index: number): void;
65
- /**
66
- * Move one element from one index to another.
67
- * @param index The index of the element to move
68
- * @param targetIndex The index where the element should be after moving.
69
- */
70
- move(index: number, targetIndex: number): void;
71
- /**
72
- * Deletes an element at the specified index
73
- * @param index The index of the element to delete
74
- */
75
- delete(index: number): void;
76
- clear(): void;
77
- /**
78
- * Returns an Array of all the elements in the LiveList.
79
- */
80
- toArray(): T[];
81
- toCrdtArray(): AbstractCrdt[];
82
- /**
83
- * Tests whether all elements pass the test implemented by the provided function.
84
- * @param predicate Function to test for each element, taking two arguments (the element and its index).
85
- * @returns true if the predicate function returns a truthy value for every element. Otherwise, false.
86
- */
87
- every(predicate: (value: T, index: number) => unknown): boolean;
88
- /**
89
- * Creates an array with all elements that pass the test implemented by the provided function.
90
- * @param predicate Function to test each element of the LiveList. Return a value that coerces to true to keep the element, or to false otherwise.
91
- * @returns An array with the elements that pass the test.
92
- */
93
- filter(predicate: (value: T, index: number) => unknown): T[];
94
- /**
95
- * Returns the first element that satisfies the provided testing function.
96
- * @param predicate Function to execute on each value.
97
- * @returns The value of the first element in the LiveList that satisfies the provided testing function. Otherwise, undefined is returned.
98
- */
99
- find(predicate: (value: T, index: number) => unknown): T | undefined;
100
- /**
101
- * Returns the index of the first element in the LiveList that satisfies the provided testing function.
102
- * @param predicate Function to execute on each value until the function returns true, indicating that the satisfying element was found.
103
- * @returns The index of the first element in the LiveList that passes the test. Otherwise, -1.
104
- */
105
- findIndex(predicate: (value: T, index: number) => unknown): number;
106
- /**
107
- * Executes a provided function once for each element.
108
- * @param callbackfn Function to execute on each element.
109
- */
110
- forEach(callbackfn: (value: T, index: number) => void): void;
111
- /**
112
- * Get the element at the specified index.
113
- * @param index The index on the element to get.
114
- * @returns The element at the specified index or undefined.
115
- */
116
- get(index: number): T | undefined;
117
- /**
118
- * Returns the first index at which a given element can be found in the LiveList, or -1 if it is not present.
119
- * @param searchElement Element to locate.
120
- * @param fromIndex The index to start the search at.
121
- * @returns The first index of the element in the LiveList; -1 if not found.
122
- */
123
- indexOf(searchElement: T, fromIndex?: number): number;
124
- /**
125
- * Returns the last index at which a given element can be found in the LiveList, or -1 if it is not present. The LiveLsit is searched backwards, starting at fromIndex.
126
- * @param searchElement Element to locate.
127
- * @param fromIndex The index at which to start searching backwards.
128
- * @returns
129
- */
130
- lastIndexOf(searchElement: T, fromIndex?: number): number;
131
- /**
132
- * Creates an array populated with the results of calling a provided function on every element.
133
- * @param callback Function that is called for every element.
134
- * @returns An array with each element being the result of the callback function.
135
- */
136
- map<U>(callback: (value: T, index: number) => U): U[];
137
- /**
138
- * Tests whether at least one element in the LiveList passes the test implemented by the provided function.
139
- * @param predicate Function to test for each element.
140
- * @returns true if the callback function returns a truthy value for at least one element. Otherwise, false.
141
- */
142
- some(predicate: (value: T, index: number) => unknown): boolean;
143
- [Symbol.iterator](): IterableIterator<T>;
144
- }