@liveblocks/core 1.1.1-internal1 → 1.1.1-internal2
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/dist/index.d.ts +12 -0
- package/dist/index.js +54 -24
- package/package.json +5 -4
package/dist/index.d.ts
CHANGED
|
@@ -1052,6 +1052,17 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
|
|
|
1052
1052
|
*/
|
|
1053
1053
|
addToHistory: boolean;
|
|
1054
1054
|
}): void;
|
|
1055
|
+
/**
|
|
1056
|
+
*
|
|
1057
|
+
* Sends Yjs document updates to liveblocks server
|
|
1058
|
+
*
|
|
1059
|
+
* @param {string} data the doc update to send to the server, base64 encoded uint8array
|
|
1060
|
+
*/
|
|
1061
|
+
updateYDoc(data: string): void;
|
|
1062
|
+
/**
|
|
1063
|
+
* Sends a request for the current document from liveblocks server
|
|
1064
|
+
*/
|
|
1065
|
+
fetchYDoc(stateVector: string): void;
|
|
1055
1066
|
/**
|
|
1056
1067
|
* Broadcasts an event to other users in the room. Event broadcasted to the room can be listened with {@link Room.subscribe}("event").
|
|
1057
1068
|
* @param {any} event the event to broadcast. Should be serializable to JSON
|
|
@@ -1109,6 +1120,7 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
|
|
|
1109
1120
|
*/
|
|
1110
1121
|
readonly storageDidLoad: Observable<void>;
|
|
1111
1122
|
readonly storageStatus: Observable<StorageStatus>;
|
|
1123
|
+
readonly ydoc: Observable<string>;
|
|
1112
1124
|
};
|
|
1113
1125
|
/**
|
|
1114
1126
|
* Batches modifications made during the given function.
|
package/dist/index.js
CHANGED
|
@@ -145,7 +145,7 @@ var onMessageFromPanel = eventSource.observable;
|
|
|
145
145
|
// src/devtools/index.ts
|
|
146
146
|
var VERSION = true ? (
|
|
147
147
|
/* istanbul ignore next */
|
|
148
|
-
"1.1.1-
|
|
148
|
+
"1.1.1-internal2"
|
|
149
149
|
) : "dev";
|
|
150
150
|
var _devtoolsSetupHasRun = false;
|
|
151
151
|
function setupDevTools(getAllRooms) {
|
|
@@ -460,7 +460,11 @@ var FSM = class {
|
|
|
460
460
|
}
|
|
461
461
|
get currentState() {
|
|
462
462
|
if (this.currentStateOrNull === null) {
|
|
463
|
-
|
|
463
|
+
if (this.runningState === 0 /* NOT_STARTED_YET */) {
|
|
464
|
+
throw new Error("Not started yet");
|
|
465
|
+
} else {
|
|
466
|
+
throw new Error("Already stopped");
|
|
467
|
+
}
|
|
464
468
|
}
|
|
465
469
|
return this.currentStateOrNull;
|
|
466
470
|
}
|
|
@@ -482,10 +486,10 @@ var FSM = class {
|
|
|
482
486
|
*/
|
|
483
487
|
stop() {
|
|
484
488
|
if (this.runningState !== 1 /* STARTED */) {
|
|
485
|
-
throw new Error("Cannot stop a state machine that
|
|
489
|
+
throw new Error("Cannot stop a state machine that hasn't started yet");
|
|
486
490
|
}
|
|
487
|
-
this.runningState = 2 /* STOPPED */;
|
|
488
491
|
this.exit(null);
|
|
492
|
+
this.runningState = 2 /* STOPPED */;
|
|
489
493
|
this.currentStateOrNull = null;
|
|
490
494
|
}
|
|
491
495
|
constructor(initialContext) {
|
|
@@ -653,10 +657,11 @@ var FSM = class {
|
|
|
653
657
|
* Exits the current state, and executes any necessary cleanup functions.
|
|
654
658
|
* Call this before changing the current state to the next state.
|
|
655
659
|
*
|
|
656
|
-
* @param levels Defines how many "levels" of nesting will be
|
|
657
|
-
* example, if you transition from `foo.bar.qux` to
|
|
658
|
-
* the level is 1. But if you transition from
|
|
659
|
-
* then the level is 3.
|
|
660
|
+
* @param levels Defines how many "levels" of nesting will be
|
|
661
|
+
* exited. For example, if you transition from `foo.bar.qux` to
|
|
662
|
+
* `foo.bar.baz`, then the level is 1. But if you transition from
|
|
663
|
+
* `foo.bar.qux` to `bla.bla`, then the level is 3.
|
|
664
|
+
* If `null`, it will exit all levels.
|
|
660
665
|
*/
|
|
661
666
|
exit(levels) {
|
|
662
667
|
this.eventHub.willExitState.notify(this.currentState);
|
|
@@ -695,12 +700,15 @@ var FSM = class {
|
|
|
695
700
|
* transition to happen. When that happens, will trigger side effects.
|
|
696
701
|
*/
|
|
697
702
|
send(event) {
|
|
703
|
+
if (!this.knownEventTypes.has(event.type)) {
|
|
704
|
+
throw new Error(`Invalid event ${JSON.stringify(event.type)}`);
|
|
705
|
+
}
|
|
706
|
+
if (this.runningState === 2 /* STOPPED */) {
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
698
709
|
const targetFn = this.getTargetFn(event.type);
|
|
699
710
|
if (targetFn !== void 0) {
|
|
700
711
|
return this.transition(event, targetFn);
|
|
701
|
-
}
|
|
702
|
-
if (!this.knownEventTypes.has(event.type)) {
|
|
703
|
-
throw new Error(`Invalid event ${JSON.stringify(event.type)}`);
|
|
704
712
|
} else {
|
|
705
713
|
this.eventHub.didIgnoreEvent.notify(event);
|
|
706
714
|
}
|
|
@@ -1699,7 +1707,7 @@ function nanoid(length = 7) {
|
|
|
1699
1707
|
}
|
|
1700
1708
|
|
|
1701
1709
|
// src/crdts/LiveRegister.ts
|
|
1702
|
-
var LiveRegister = class extends AbstractCrdt {
|
|
1710
|
+
var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
1703
1711
|
constructor(data) {
|
|
1704
1712
|
super();
|
|
1705
1713
|
this._data = data;
|
|
@@ -1709,7 +1717,7 @@ var LiveRegister = class extends AbstractCrdt {
|
|
|
1709
1717
|
}
|
|
1710
1718
|
/** @internal */
|
|
1711
1719
|
static _deserialize([id, item], _parentToChildren, pool) {
|
|
1712
|
-
const register = new
|
|
1720
|
+
const register = new _LiveRegister(item.data);
|
|
1713
1721
|
register._attach(id, pool);
|
|
1714
1722
|
return register;
|
|
1715
1723
|
}
|
|
@@ -1777,7 +1785,7 @@ function compareNodePosition(itemA, itemB) {
|
|
|
1777
1785
|
const posB = itemB._parentPos;
|
|
1778
1786
|
return posA === posB ? 0 : posA < posB ? -1 : 1;
|
|
1779
1787
|
}
|
|
1780
|
-
var LiveList = class extends AbstractCrdt {
|
|
1788
|
+
var LiveList = class _LiveList extends AbstractCrdt {
|
|
1781
1789
|
constructor(items = []) {
|
|
1782
1790
|
super();
|
|
1783
1791
|
this._items = [];
|
|
@@ -1794,7 +1802,7 @@ var LiveList = class extends AbstractCrdt {
|
|
|
1794
1802
|
}
|
|
1795
1803
|
/** @internal */
|
|
1796
1804
|
static _deserialize([id], parentToChildren, pool) {
|
|
1797
|
-
const list = new
|
|
1805
|
+
const list = new _LiveList();
|
|
1798
1806
|
list._attach(id, pool);
|
|
1799
1807
|
const children = parentToChildren.get(id);
|
|
1800
1808
|
if (children === void 0) {
|
|
@@ -2784,7 +2792,7 @@ var freeze = process.env.NODE_ENV === "production" ? (
|
|
|
2784
2792
|
) : Object.freeze;
|
|
2785
2793
|
|
|
2786
2794
|
// src/crdts/LiveMap.ts
|
|
2787
|
-
var LiveMap = class extends AbstractCrdt {
|
|
2795
|
+
var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
2788
2796
|
constructor(entries2) {
|
|
2789
2797
|
super();
|
|
2790
2798
|
this.unacknowledgedSet = /* @__PURE__ */ new Map();
|
|
@@ -2825,7 +2833,7 @@ var LiveMap = class extends AbstractCrdt {
|
|
|
2825
2833
|
* @internal
|
|
2826
2834
|
*/
|
|
2827
2835
|
static _deserialize([id, _item], parentToChildren, pool) {
|
|
2828
|
-
const map = new
|
|
2836
|
+
const map = new _LiveMap();
|
|
2829
2837
|
map._attach(id, pool);
|
|
2830
2838
|
const children = parentToChildren.get(id);
|
|
2831
2839
|
if (children === void 0) {
|
|
@@ -3130,7 +3138,7 @@ var LiveMap = class extends AbstractCrdt {
|
|
|
3130
3138
|
};
|
|
3131
3139
|
|
|
3132
3140
|
// src/crdts/LiveObject.ts
|
|
3133
|
-
var LiveObject = class extends AbstractCrdt {
|
|
3141
|
+
var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
3134
3142
|
constructor(obj = {}) {
|
|
3135
3143
|
super();
|
|
3136
3144
|
this._propToLastUpdate = /* @__PURE__ */ new Map();
|
|
@@ -3168,8 +3176,8 @@ var LiveObject = class extends AbstractCrdt {
|
|
|
3168
3176
|
}
|
|
3169
3177
|
/** @internal */
|
|
3170
3178
|
static _fromItems(items, pool) {
|
|
3171
|
-
const [root, parentToChildren] =
|
|
3172
|
-
return
|
|
3179
|
+
const [root, parentToChildren] = _LiveObject._buildRootAndParentToChildren(items);
|
|
3180
|
+
return _LiveObject._deserialize(
|
|
3173
3181
|
root,
|
|
3174
3182
|
parentToChildren,
|
|
3175
3183
|
pool
|
|
@@ -3205,7 +3213,7 @@ var LiveObject = class extends AbstractCrdt {
|
|
|
3205
3213
|
}
|
|
3206
3214
|
/** @internal */
|
|
3207
3215
|
static _deserialize([id, item], parentToChildren, pool) {
|
|
3208
|
-
const liveObj = new
|
|
3216
|
+
const liveObj = new _LiveObject(item.data);
|
|
3209
3217
|
liveObj._attach(id, pool);
|
|
3210
3218
|
return this._deserializeChildren(liveObj, parentToChildren, pool);
|
|
3211
3219
|
}
|
|
@@ -4394,7 +4402,8 @@ function createRoom(options, config) {
|
|
|
4394
4402
|
storage: makeEventSource(),
|
|
4395
4403
|
history: makeEventSource(),
|
|
4396
4404
|
storageDidLoad: makeEventSource(),
|
|
4397
|
-
storageStatus: makeEventSource()
|
|
4405
|
+
storageStatus: makeEventSource(),
|
|
4406
|
+
ydoc: makeEventSource()
|
|
4398
4407
|
};
|
|
4399
4408
|
function sendMessages(messageOrMessages) {
|
|
4400
4409
|
var _a2, _b2;
|
|
@@ -4815,6 +4824,10 @@ function createRoom(options, config) {
|
|
|
4815
4824
|
}
|
|
4816
4825
|
break;
|
|
4817
4826
|
}
|
|
4827
|
+
case 300 /* UPDATE_YDOC */: {
|
|
4828
|
+
eventHub.ydoc.notify(message.update);
|
|
4829
|
+
break;
|
|
4830
|
+
}
|
|
4818
4831
|
case 104 /* ROOM_STATE */: {
|
|
4819
4832
|
updates.others.push(onRoomStateMessage(message));
|
|
4820
4833
|
break;
|
|
@@ -4933,6 +4946,13 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
4933
4946
|
}
|
|
4934
4947
|
return messages;
|
|
4935
4948
|
}
|
|
4949
|
+
function updateYDoc(update) {
|
|
4950
|
+
context.buffer.messages.push({
|
|
4951
|
+
type: 301 /* UPDATE_YDOC */,
|
|
4952
|
+
update
|
|
4953
|
+
});
|
|
4954
|
+
flushNowOrSoon();
|
|
4955
|
+
}
|
|
4936
4956
|
function broadcastEvent(event, options2 = {
|
|
4937
4957
|
shouldQueueEventIfNotReady: false
|
|
4938
4958
|
}) {
|
|
@@ -4992,6 +5012,13 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
4992
5012
|
};
|
|
4993
5013
|
});
|
|
4994
5014
|
}
|
|
5015
|
+
function fetchYDoc(vector) {
|
|
5016
|
+
context.buffer.messages.push({
|
|
5017
|
+
type: 300 /* FETCH_YDOC */,
|
|
5018
|
+
vector
|
|
5019
|
+
});
|
|
5020
|
+
flushNowOrSoon();
|
|
5021
|
+
}
|
|
4995
5022
|
function undo() {
|
|
4996
5023
|
if (context.activeBatch) {
|
|
4997
5024
|
throw new Error("undo is not allowed during a batch");
|
|
@@ -5113,7 +5140,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5113
5140
|
storage: eventHub.storage.observable,
|
|
5114
5141
|
history: eventHub.history.observable,
|
|
5115
5142
|
storageDidLoad: eventHub.storageDidLoad.observable,
|
|
5116
|
-
storageStatus: eventHub.storageStatus.observable
|
|
5143
|
+
storageStatus: eventHub.storageStatus.observable,
|
|
5144
|
+
ydoc: eventHub.ydoc.observable
|
|
5117
5145
|
};
|
|
5118
5146
|
return {
|
|
5119
5147
|
/* NOTE: Exposing __internal here only to allow testing implementation details in unit tests */
|
|
@@ -5148,6 +5176,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5148
5176
|
destroy: () => managedSocket.destroy(),
|
|
5149
5177
|
// Presence
|
|
5150
5178
|
updatePresence,
|
|
5179
|
+
updateYDoc,
|
|
5151
5180
|
broadcastEvent,
|
|
5152
5181
|
// Storage
|
|
5153
5182
|
batch,
|
|
@@ -5159,6 +5188,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5159
5188
|
pause: pauseHistory,
|
|
5160
5189
|
resume: resumeHistory
|
|
5161
5190
|
},
|
|
5191
|
+
fetchYDoc,
|
|
5162
5192
|
getStorage,
|
|
5163
5193
|
getStorageSnapshot,
|
|
5164
5194
|
getStorageStatus,
|
|
@@ -5274,7 +5304,7 @@ function makeCreateSocketDelegateForRoom(liveblocksServer, WebSocketPolyfill) {
|
|
|
5274
5304
|
// @ts-ignore (__PACKAGE_VERSION__ will be injected by the build script)
|
|
5275
5305
|
true ? (
|
|
5276
5306
|
/* istanbul ignore next */
|
|
5277
|
-
"1.1.1-
|
|
5307
|
+
"1.1.1-internal2"
|
|
5278
5308
|
) : "dev"}`
|
|
5279
5309
|
);
|
|
5280
5310
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liveblocks/core",
|
|
3
|
-
"version": "1.1.1-
|
|
3
|
+
"version": "1.1.1-internal2",
|
|
4
4
|
"description": "Shared code and foundational internals for Liveblocks",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -22,13 +22,14 @@
|
|
|
22
22
|
"build": "tsup",
|
|
23
23
|
"format": "(eslint --fix src/ || true) && prettier --write src/",
|
|
24
24
|
"lint": "eslint src/",
|
|
25
|
+
"lint:package": "publint --strict && attw --pack",
|
|
25
26
|
"test": "jest --silent --verbose --color=always",
|
|
26
27
|
"test:types": "tsd",
|
|
27
28
|
"test:watch": "jest --silent --verbose --color=always --watch",
|
|
28
29
|
"test:e2e": "jest --silent --verbose --color=always --config=./jest.config.e2e.js",
|
|
29
|
-
"test:deps": "depcruise src --exclude __tests__
|
|
30
|
-
"showdeps": "depcruise src --include-only '^src' --exclude='__tests__' --
|
|
31
|
-
"showdeps:high-level": "depcruise src --include-only '^src' --exclude='(^src/index.ts|shallow.ts|__tests__)' --collapse='^src/(refs|lib|compat|types|crdts|protocol)' --
|
|
30
|
+
"test:deps": "depcruise src --exclude __tests__",
|
|
31
|
+
"showdeps": "depcruise src --include-only '^src' --exclude='__tests__' --output-type dot | dot -T svg > /tmp/dependency-graph.svg && open /tmp/dependency-graph.svg",
|
|
32
|
+
"showdeps:high-level": "depcruise src --include-only '^src' --exclude='(^src/index.ts|shallow.ts|__tests__)' --collapse='^src/(refs|lib|compat|types|crdts|protocol)' --output-type dot | dot -T svg > /tmp/dependency-graph.svg && open /tmp/dependency-graph.svg"
|
|
32
33
|
},
|
|
33
34
|
"license": "Apache-2.0",
|
|
34
35
|
"devDependencies": {
|