@symbo.ls/sdk 2.34.35 → 3.1.2
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/README.md +2 -143
- package/dist/cjs/config/environment.js +30 -98
- package/dist/cjs/index.js +24 -144
- package/dist/cjs/services/AIService.js +155 -0
- package/dist/cjs/services/AuthService.js +305 -738
- package/dist/cjs/services/BaseService.js +6 -158
- package/dist/cjs/services/BasedService.js +1185 -0
- package/dist/cjs/services/CoreService.js +1751 -0
- package/dist/cjs/services/SocketIOService.js +307 -0
- package/dist/cjs/services/SocketService.js +161 -0
- package/dist/cjs/services/SymstoryService.js +571 -0
- package/dist/cjs/services/index.js +16 -64
- package/dist/cjs/utils/TokenManager.js +30 -78
- package/dist/cjs/utils/basedQuerys.js +181 -0
- package/dist/cjs/utils/services.js +103 -301
- package/dist/cjs/utils/symstoryClient.js +259 -0
- package/dist/cjs/utils/validation.js +3 -0
- package/dist/esm/config/environment.js +30 -98
- package/dist/esm/index.js +8797 -49416
- package/dist/esm/services/AIService.js +185 -0
- package/dist/esm/services/AuthService.js +386 -1493
- package/dist/esm/services/BaseService.js +6 -757
- package/dist/esm/services/BasedService.js +5278 -0
- package/dist/esm/services/CoreService.js +2264 -0
- package/dist/esm/services/SocketIOService.js +470 -0
- package/dist/esm/services/SocketService.js +191 -0
- package/dist/esm/services/SymstoryService.js +7041 -0
- package/dist/esm/services/index.js +8690 -49015
- package/dist/esm/utils/TokenManager.js +30 -78
- package/dist/esm/utils/basedQuerys.js +163 -0
- package/dist/esm/utils/services.js +103 -301
- package/dist/esm/utils/symstoryClient.js +370 -0
- package/dist/esm/utils/validation.js +7 -4
- package/dist/node/config/environment.js +30 -98
- package/dist/node/index.js +32 -175
- package/dist/node/services/AIService.js +136 -0
- package/dist/node/services/AuthService.js +310 -742
- package/dist/node/services/BaseService.js +6 -148
- package/dist/node/services/BasedService.js +1156 -0
- package/dist/node/services/CoreService.js +1722 -0
- package/dist/node/services/SocketIOService.js +278 -0
- package/dist/node/services/SocketService.js +142 -0
- package/dist/node/services/SymstoryService.js +542 -0
- package/dist/node/services/index.js +16 -64
- package/dist/node/utils/TokenManager.js +30 -78
- package/dist/node/utils/basedQuerys.js +162 -0
- package/dist/node/utils/services.js +103 -301
- package/dist/node/utils/symstoryClient.js +230 -0
- package/dist/node/utils/validation.js +3 -0
- package/package.json +16 -35
- package/src/config/environment.js +28 -99
- package/src/index.js +36 -181
- package/src/services/AIService.js +150 -0
- package/src/services/AuthService.js +328 -874
- package/src/services/BaseService.js +6 -166
- package/src/services/BasedService.js +1301 -0
- package/src/services/CoreService.js +1943 -0
- package/src/services/SocketIOService.js +334 -0
- package/src/services/SocketService.js +168 -0
- package/src/services/SymstoryService.js +649 -0
- package/src/services/index.js +13 -80
- package/src/utils/TokenManager.js +33 -88
- package/src/utils/basedQuerys.js +164 -0
- package/src/utils/services.js +107 -326
- package/src/utils/symstoryClient.js +252 -0
- package/src/utils/validation.js +3 -0
- package/dist/cjs/services/AdminService.js +0 -351
- package/dist/cjs/services/BranchService.js +0 -484
- package/dist/cjs/services/CollabService.js +0 -743
- package/dist/cjs/services/DnsService.js +0 -340
- package/dist/cjs/services/FeatureFlagService.js +0 -175
- package/dist/cjs/services/FileService.js +0 -201
- package/dist/cjs/services/IntegrationService.js +0 -538
- package/dist/cjs/services/MetricsService.js +0 -62
- package/dist/cjs/services/PaymentService.js +0 -271
- package/dist/cjs/services/PlanService.js +0 -426
- package/dist/cjs/services/ProjectService.js +0 -1207
- package/dist/cjs/services/PullRequestService.js +0 -503
- package/dist/cjs/services/ScreenshotService.js +0 -304
- package/dist/cjs/services/SubscriptionService.js +0 -396
- package/dist/cjs/services/TrackingService.js +0 -661
- package/dist/cjs/services/WaitlistService.js +0 -148
- package/dist/cjs/state/RootStateManager.js +0 -65
- package/dist/cjs/state/rootEventBus.js +0 -74
- package/dist/cjs/utils/CollabClient.js +0 -223
- package/dist/cjs/utils/changePreprocessor.js +0 -199
- package/dist/cjs/utils/jsonDiff.js +0 -145
- package/dist/cjs/utils/ordering.js +0 -309
- package/dist/esm/services/AdminService.js +0 -1132
- package/dist/esm/services/BranchService.js +0 -1265
- package/dist/esm/services/CollabService.js +0 -26838
- package/dist/esm/services/DnsService.js +0 -1121
- package/dist/esm/services/FeatureFlagService.js +0 -956
- package/dist/esm/services/FileService.js +0 -982
- package/dist/esm/services/IntegrationService.js +0 -1319
- package/dist/esm/services/MetricsService.js +0 -843
- package/dist/esm/services/PaymentService.js +0 -1052
- package/dist/esm/services/PlanService.js +0 -1207
- package/dist/esm/services/ProjectService.js +0 -2526
- package/dist/esm/services/PullRequestService.js +0 -1284
- package/dist/esm/services/ScreenshotService.js +0 -1085
- package/dist/esm/services/SubscriptionService.js +0 -1177
- package/dist/esm/services/TrackingService.js +0 -18343
- package/dist/esm/services/WaitlistService.js +0 -929
- package/dist/esm/state/RootStateManager.js +0 -90
- package/dist/esm/state/rootEventBus.js +0 -56
- package/dist/esm/utils/CollabClient.js +0 -18901
- package/dist/esm/utils/changePreprocessor.js +0 -542
- package/dist/esm/utils/jsonDiff.js +0 -7011
- package/dist/esm/utils/ordering.js +0 -291
- package/dist/node/services/AdminService.js +0 -332
- package/dist/node/services/BranchService.js +0 -465
- package/dist/node/services/CollabService.js +0 -724
- package/dist/node/services/DnsService.js +0 -321
- package/dist/node/services/FeatureFlagService.js +0 -156
- package/dist/node/services/FileService.js +0 -182
- package/dist/node/services/IntegrationService.js +0 -519
- package/dist/node/services/MetricsService.js +0 -43
- package/dist/node/services/PaymentService.js +0 -252
- package/dist/node/services/PlanService.js +0 -407
- package/dist/node/services/ProjectService.js +0 -1188
- package/dist/node/services/PullRequestService.js +0 -484
- package/dist/node/services/ScreenshotService.js +0 -285
- package/dist/node/services/SubscriptionService.js +0 -377
- package/dist/node/services/TrackingService.js +0 -632
- package/dist/node/services/WaitlistService.js +0 -129
- package/dist/node/state/RootStateManager.js +0 -36
- package/dist/node/state/rootEventBus.js +0 -55
- package/dist/node/utils/CollabClient.js +0 -194
- package/dist/node/utils/changePreprocessor.js +0 -180
- package/dist/node/utils/jsonDiff.js +0 -116
- package/dist/node/utils/ordering.js +0 -290
- package/src/services/AdminService.js +0 -374
- package/src/services/BranchService.js +0 -536
- package/src/services/CollabService.js +0 -900
- package/src/services/DnsService.js +0 -366
- package/src/services/FeatureFlagService.js +0 -174
- package/src/services/FileService.js +0 -213
- package/src/services/IntegrationService.js +0 -548
- package/src/services/MetricsService.js +0 -40
- package/src/services/PaymentService.js +0 -287
- package/src/services/PlanService.js +0 -468
- package/src/services/ProjectService.js +0 -1366
- package/src/services/PullRequestService.js +0 -537
- package/src/services/ScreenshotService.js +0 -258
- package/src/services/SubscriptionService.js +0 -425
- package/src/services/TrackingService.js +0 -853
- package/src/services/WaitlistService.js +0 -130
- package/src/services/tests/BranchService/createBranch.test.js +0 -153
- package/src/services/tests/BranchService/deleteBranch.test.js +0 -173
- package/src/services/tests/BranchService/getBranchChanges.test.js +0 -146
- package/src/services/tests/BranchService/listBranches.test.js +0 -87
- package/src/services/tests/BranchService/mergeBranch.test.js +0 -210
- package/src/services/tests/BranchService/publishVersion.test.js +0 -183
- package/src/services/tests/BranchService/renameBranch.test.js +0 -240
- package/src/services/tests/BranchService/resetBranch.test.js +0 -152
- package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +0 -67
- package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +0 -75
- package/src/services/tests/FileService/createFileFormData.test.js +0 -74
- package/src/services/tests/FileService/getFileUrl.test.js +0 -69
- package/src/services/tests/FileService/updateProjectIcon.test.js +0 -109
- package/src/services/tests/FileService/uploadDocument.test.js +0 -36
- package/src/services/tests/FileService/uploadFile.test.js +0 -78
- package/src/services/tests/FileService/uploadFileWithValidation.test.js +0 -114
- package/src/services/tests/FileService/uploadImage.test.js +0 -36
- package/src/services/tests/FileService/uploadMultipleFiles.test.js +0 -111
- package/src/services/tests/FileService/validateFile.test.js +0 -63
- package/src/services/tests/PlanService/createPlan.test.js +0 -104
- package/src/services/tests/PlanService/createPlanWithValidation.test.js +0 -523
- package/src/services/tests/PlanService/deletePlan.test.js +0 -92
- package/src/services/tests/PlanService/getActivePlans.test.js +0 -123
- package/src/services/tests/PlanService/getAdminPlans.test.js +0 -84
- package/src/services/tests/PlanService/getPlan.test.js +0 -50
- package/src/services/tests/PlanService/getPlanByKey.test.js +0 -109
- package/src/services/tests/PlanService/getPlanWithValidation.test.js +0 -85
- package/src/services/tests/PlanService/getPlans.test.js +0 -53
- package/src/services/tests/PlanService/getPlansByPriceRange.test.js +0 -109
- package/src/services/tests/PlanService/getPlansWithValidation.test.js +0 -48
- package/src/services/tests/PlanService/initializePlans.test.js +0 -75
- package/src/services/tests/PlanService/updatePlan.test.js +0 -111
- package/src/services/tests/PlanService/updatePlanWithValidation.test.js +0 -556
- package/src/state/RootStateManager.js +0 -76
- package/src/state/rootEventBus.js +0 -67
- package/src/utils/CollabClient.js +0 -248
- package/src/utils/changePreprocessor.js +0 -239
- package/src/utils/jsonDiff.js +0 -144
- package/src/utils/ordering.js +0 -271
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { BaseService } from "./BaseService.js";
|
|
2
|
-
class WaitlistService extends BaseService {
|
|
3
|
-
// ==================== WAITLIST METHODS ====================
|
|
4
|
-
/**
|
|
5
|
-
* Join a waitlist campaign (public).
|
|
6
|
-
*
|
|
7
|
-
* Mirrors: POST /waitlist (WaitlistController.join)
|
|
8
|
-
*/
|
|
9
|
-
async joinWaitlist(data = {}) {
|
|
10
|
-
this._requireReady("joinWaitlist");
|
|
11
|
-
if (!data || typeof data !== "object") {
|
|
12
|
-
throw new Error("Waitlist join payload is required");
|
|
13
|
-
}
|
|
14
|
-
if (!data.email) {
|
|
15
|
-
throw new Error("Email is required");
|
|
16
|
-
}
|
|
17
|
-
try {
|
|
18
|
-
const response = await this._request("/waitlist", {
|
|
19
|
-
method: "POST",
|
|
20
|
-
body: JSON.stringify(data),
|
|
21
|
-
methodName: "joinWaitlist"
|
|
22
|
-
});
|
|
23
|
-
if (response.success) {
|
|
24
|
-
return response.data;
|
|
25
|
-
}
|
|
26
|
-
throw new Error(response.message);
|
|
27
|
-
} catch (error) {
|
|
28
|
-
throw new Error(`Failed to join waitlist: ${error.message}`, { cause: error });
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* List waitlist entries (admin).
|
|
33
|
-
*
|
|
34
|
-
* Mirrors: GET /waitlist (WaitlistController.list)
|
|
35
|
-
*/
|
|
36
|
-
async listWaitlistEntries(options = {}) {
|
|
37
|
-
this._requireReady("listWaitlistEntries");
|
|
38
|
-
const {
|
|
39
|
-
campaignKey,
|
|
40
|
-
status,
|
|
41
|
-
search,
|
|
42
|
-
page,
|
|
43
|
-
limit
|
|
44
|
-
} = options || {};
|
|
45
|
-
const queryParams = new URLSearchParams();
|
|
46
|
-
if (campaignKey != null) {
|
|
47
|
-
queryParams.append("campaignKey", String(campaignKey));
|
|
48
|
-
}
|
|
49
|
-
if (status != null) {
|
|
50
|
-
queryParams.append("status", String(status));
|
|
51
|
-
}
|
|
52
|
-
if (search != null) {
|
|
53
|
-
queryParams.append("search", String(search));
|
|
54
|
-
}
|
|
55
|
-
if (page != null) {
|
|
56
|
-
queryParams.append("page", String(page));
|
|
57
|
-
}
|
|
58
|
-
if (limit != null) {
|
|
59
|
-
queryParams.append("limit", String(limit));
|
|
60
|
-
}
|
|
61
|
-
const queryString = queryParams.toString();
|
|
62
|
-
const url = `/waitlist${queryString ? `?${queryString}` : ""}`;
|
|
63
|
-
try {
|
|
64
|
-
const response = await this._request(url, {
|
|
65
|
-
method: "GET",
|
|
66
|
-
methodName: "listWaitlistEntries"
|
|
67
|
-
});
|
|
68
|
-
if (response.success) {
|
|
69
|
-
return response.data;
|
|
70
|
-
}
|
|
71
|
-
throw new Error(response.message);
|
|
72
|
-
} catch (error) {
|
|
73
|
-
throw new Error(`Failed to list waitlist entries: ${error.message}`, { cause: error });
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Update a waitlist entry (admin).
|
|
78
|
-
*
|
|
79
|
-
* Mirrors: PATCH /waitlist/:id (WaitlistController.update)
|
|
80
|
-
*/
|
|
81
|
-
async updateWaitlistEntry(id, update = {}) {
|
|
82
|
-
this._requireReady("updateWaitlistEntry");
|
|
83
|
-
if (!id) {
|
|
84
|
-
throw new Error("Waitlist entry ID is required");
|
|
85
|
-
}
|
|
86
|
-
if (!update || typeof update !== "object") {
|
|
87
|
-
throw new Error("Update payload is required");
|
|
88
|
-
}
|
|
89
|
-
try {
|
|
90
|
-
const response = await this._request(`/waitlist/${id}`, {
|
|
91
|
-
method: "PATCH",
|
|
92
|
-
body: JSON.stringify(update),
|
|
93
|
-
methodName: "updateWaitlistEntry"
|
|
94
|
-
});
|
|
95
|
-
if (response.success) {
|
|
96
|
-
return response.data;
|
|
97
|
-
}
|
|
98
|
-
throw new Error(response.message);
|
|
99
|
-
} catch (error) {
|
|
100
|
-
throw new Error(`Failed to update waitlist entry: ${error.message}`, { cause: error });
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Send an invitation email for a waitlist entry (admin).
|
|
105
|
-
*
|
|
106
|
-
* Mirrors: POST /waitlist/:id/invite (WaitlistController.invite)
|
|
107
|
-
*/
|
|
108
|
-
async inviteWaitlistEntry(id) {
|
|
109
|
-
this._requireReady("inviteWaitlistEntry");
|
|
110
|
-
if (!id) {
|
|
111
|
-
throw new Error("Waitlist entry ID is required");
|
|
112
|
-
}
|
|
113
|
-
try {
|
|
114
|
-
const response = await this._request(`/waitlist/${id}/invite`, {
|
|
115
|
-
method: "POST",
|
|
116
|
-
methodName: "inviteWaitlistEntry"
|
|
117
|
-
});
|
|
118
|
-
if (response.success) {
|
|
119
|
-
return response.data;
|
|
120
|
-
}
|
|
121
|
-
throw new Error(response.message);
|
|
122
|
-
} catch (error) {
|
|
123
|
-
throw new Error(`Failed to invite waitlist entry: ${error.message}`, { cause: error });
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
export {
|
|
128
|
-
WaitlistService
|
|
129
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import * as utils from "@domql/utils";
|
|
2
|
-
import { rootBus } from "./rootEventBus.js";
|
|
3
|
-
const { isFunction } = utils.default || utils;
|
|
4
|
-
class RootStateManager {
|
|
5
|
-
constructor(rootState) {
|
|
6
|
-
this._rootState = rootState;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Apply change tuples to the root state using the built-in setPathCollection
|
|
10
|
-
* of Symbo.ls APP state tree.
|
|
11
|
-
*
|
|
12
|
-
* @param {Array} changes – eg. ['update', ['foo'], 'bar']
|
|
13
|
-
* @param {Object} opts – forwarded to setPathCollection
|
|
14
|
-
*/
|
|
15
|
-
async applyChanges(changes = [], opts = {}) {
|
|
16
|
-
if (!this._rootState || !isFunction(this._rootState.setPathCollection)) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const result = await this._rootState.setPathCollection(changes, {
|
|
20
|
-
preventUpdate: true,
|
|
21
|
-
...opts
|
|
22
|
-
});
|
|
23
|
-
return result;
|
|
24
|
-
}
|
|
25
|
-
setVersion(v) {
|
|
26
|
-
if (this._rootState) {
|
|
27
|
-
this._rootState.version = v;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
get root() {
|
|
31
|
-
return this._rootState;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
export {
|
|
35
|
-
RootStateManager
|
|
36
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
const getGlobalBus = () => {
|
|
2
|
-
if (globalThis.__SMBLS_ROOT_BUS__) {
|
|
3
|
-
return globalThis.__SMBLS_ROOT_BUS__;
|
|
4
|
-
}
|
|
5
|
-
const events = {};
|
|
6
|
-
const lastPayloads = {};
|
|
7
|
-
const bus = {
|
|
8
|
-
on(event, handler) {
|
|
9
|
-
(events[event] ||= []).push(handler);
|
|
10
|
-
if (Object.hasOwn(lastPayloads, event)) {
|
|
11
|
-
try {
|
|
12
|
-
handler(lastPayloads[event]);
|
|
13
|
-
} catch (err) {
|
|
14
|
-
console.error("[rootBus] handler error for (replay)", event, err);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
off(event, handler) {
|
|
19
|
-
const list = events[event];
|
|
20
|
-
if (!list) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const idx = list.indexOf(handler);
|
|
24
|
-
if (idx !== -1) {
|
|
25
|
-
list.splice(idx, 1);
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
emit(event, payload) {
|
|
29
|
-
lastPayloads[event] = payload;
|
|
30
|
-
const list = events[event];
|
|
31
|
-
if (!list || !list.length) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
list.slice().forEach((fn) => {
|
|
35
|
-
try {
|
|
36
|
-
fn(payload);
|
|
37
|
-
} catch (err) {
|
|
38
|
-
console.error("[rootBus] handler error for", event, err);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
Object.defineProperty(bus, "_listeners", {
|
|
44
|
-
value: events,
|
|
45
|
-
enumerable: false
|
|
46
|
-
});
|
|
47
|
-
globalThis.__SMBLS_ROOT_BUS__ = bus;
|
|
48
|
-
return bus;
|
|
49
|
-
};
|
|
50
|
-
const rootBus = getGlobalBus();
|
|
51
|
-
var rootEventBus_default = rootBus;
|
|
52
|
-
export {
|
|
53
|
-
rootEventBus_default as default,
|
|
54
|
-
rootBus
|
|
55
|
-
};
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import { io } from "socket.io-client";
|
|
2
|
-
import * as Y from "yjs";
|
|
3
|
-
import { nanoid } from "nanoid";
|
|
4
|
-
import environment from "../config/environment.js";
|
|
5
|
-
import { diffJson, applyOpsToJson } from "./jsonDiff.js";
|
|
6
|
-
class CollabClient {
|
|
7
|
-
/* public fields */
|
|
8
|
-
socket = null;
|
|
9
|
-
ydoc = null;
|
|
10
|
-
branch = "main";
|
|
11
|
-
live = false;
|
|
12
|
-
projectId = null;
|
|
13
|
-
jwt = null;
|
|
14
|
-
/* private state */
|
|
15
|
-
_buffer = [];
|
|
16
|
-
_flushTimer = null;
|
|
17
|
-
_clientId = nanoid();
|
|
18
|
-
_outboxStore = createMemoryOutbox();
|
|
19
|
-
// Dexie table fallback
|
|
20
|
-
_readyResolve;
|
|
21
|
-
ready = new Promise((res) => this._readyResolve = res);
|
|
22
|
-
constructor({ jwt, projectId, branch = "main", live = false }) {
|
|
23
|
-
Object.assign(this, { jwt, projectId, branch, live });
|
|
24
|
-
this.ydoc = new Y.Doc();
|
|
25
|
-
const hasIndexedDB = typeof globalThis.indexedDB !== "undefined";
|
|
26
|
-
if (typeof window === "undefined" || !hasIndexedDB) {
|
|
27
|
-
console.log("[CollabClient] IndexedDB not available \u2013 skipping offline persistence");
|
|
28
|
-
} else {
|
|
29
|
-
import("y-indexeddb").then(({ IndexeddbPersistence }) => {
|
|
30
|
-
new IndexeddbPersistence(`${projectId}:${branch}`, this.ydoc);
|
|
31
|
-
}).catch((err) => {
|
|
32
|
-
console.warn("[CollabClient] Failed to load IndexeddbPersistence:", err);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
if (typeof window !== "undefined" && hasIndexedDB) {
|
|
36
|
-
createDexieOutbox(`${projectId}:${branch}`).then((outboxStore) => {
|
|
37
|
-
this._outboxStore = outboxStore;
|
|
38
|
-
}).catch((err) => {
|
|
39
|
-
console.warn("[CollabClient] Failed to load Dexie:", err);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
this.socket = io(environment.socketUrl, {
|
|
43
|
-
path: "/collab-socket",
|
|
44
|
-
transports: ["websocket"],
|
|
45
|
-
auth: { token: jwt, projectId, branch, live },
|
|
46
|
-
reconnectionAttempts: Infinity,
|
|
47
|
-
reconnectionDelayMax: 4e3
|
|
48
|
-
});
|
|
49
|
-
this.socket.on("snapshot", this._onSnapshot).on("ops", this._onOps).on("commit", this._onCommit).on("liveMode", this._onLiveMode).on("connect", this._onConnect).on("error", this._onError);
|
|
50
|
-
this._prevJson = this.ydoc.getMap("root").toJSON();
|
|
51
|
-
this.ydoc.on("afterTransaction", (tr) => {
|
|
52
|
-
if (tr.origin === "remote") {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const currentJson = this.ydoc.getMap("root").toJSON();
|
|
56
|
-
const ops = diffJson(this._prevJson, currentJson);
|
|
57
|
-
this._prevJson = currentJson;
|
|
58
|
-
if (!ops.length) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
this._queueOps(ops);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
/* ---------- public helpers ---------- */
|
|
65
|
-
toggleLive(flag) {
|
|
66
|
-
this.socket.emit("toggleLive", Boolean(flag));
|
|
67
|
-
}
|
|
68
|
-
sendCursor(data) {
|
|
69
|
-
this.socket.emit("cursor", data);
|
|
70
|
-
}
|
|
71
|
-
sendPresence(d) {
|
|
72
|
-
this.socket.emit("presence", d);
|
|
73
|
-
}
|
|
74
|
-
/* ---------- private handlers ---------- */
|
|
75
|
-
_onSnapshot = ({
|
|
76
|
-
data
|
|
77
|
-
/* Uint8Array */
|
|
78
|
-
}) => {
|
|
79
|
-
if (Array.isArray(data) ? data.length : data && data.byteLength) {
|
|
80
|
-
Y.applyUpdate(this.ydoc, Uint8Array.from(data));
|
|
81
|
-
} else {
|
|
82
|
-
console.warn("[collab] Received empty snapshot \u2013 skipping applyUpdate");
|
|
83
|
-
}
|
|
84
|
-
this._prevJson = this.ydoc.getMap("root").toJSON();
|
|
85
|
-
if (typeof this._readyResolve === "function") {
|
|
86
|
-
this._readyResolve();
|
|
87
|
-
this._readyResolve = null;
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
_onOps = ({ changes }) => {
|
|
91
|
-
applyOpsToJson(changes, this.ydoc);
|
|
92
|
-
this._prevJson = this.ydoc.getMap("root").toJSON();
|
|
93
|
-
};
|
|
94
|
-
_onCommit = async ({ version }) => {
|
|
95
|
-
await this._outboxStore.clear();
|
|
96
|
-
console.info("[collab] committed", version);
|
|
97
|
-
};
|
|
98
|
-
_onConnect = async () => {
|
|
99
|
-
if (typeof this._readyResolve === "function") {
|
|
100
|
-
this._readyResolve();
|
|
101
|
-
this._readyResolve = null;
|
|
102
|
-
}
|
|
103
|
-
const queued = await this._outboxStore.toArray();
|
|
104
|
-
if (queued.length) {
|
|
105
|
-
this.socket.emit("ops", {
|
|
106
|
-
changes: queued.flatMap((e) => e.ops),
|
|
107
|
-
ts: Date.now(),
|
|
108
|
-
clientId: this._clientId
|
|
109
|
-
});
|
|
110
|
-
await this._outboxStore.clear();
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
/* ---------- buffering & debounce ---------- */
|
|
114
|
-
_queueOps(ops) {
|
|
115
|
-
this._buffer.push(...ops);
|
|
116
|
-
this._outboxStore.put({ id: nanoid(), ops });
|
|
117
|
-
if (this.live && this.socket.connected) {
|
|
118
|
-
this._flushNow();
|
|
119
|
-
} else {
|
|
120
|
-
clearTimeout(this._flushTimer);
|
|
121
|
-
this._flushTimer = setTimeout(() => this._flushNow(), 40);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
_flushNow() {
|
|
125
|
-
if (!this._buffer.length || !this.socket.connected) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
this.socket.emit("ops", {
|
|
129
|
-
changes: this._buffer,
|
|
130
|
-
ts: Date.now(),
|
|
131
|
-
clientId: this._clientId
|
|
132
|
-
});
|
|
133
|
-
this._buffer.length = 0;
|
|
134
|
-
}
|
|
135
|
-
dispose() {
|
|
136
|
-
var _a;
|
|
137
|
-
clearTimeout(this._flushTimer);
|
|
138
|
-
this._flushTimer = null;
|
|
139
|
-
this._buffer.length = 0;
|
|
140
|
-
if ((_a = this._outboxStore) == null ? void 0 : _a.clear) {
|
|
141
|
-
try {
|
|
142
|
-
const result = this._outboxStore.clear();
|
|
143
|
-
if (result && typeof result.catch === "function") {
|
|
144
|
-
result.catch(() => {
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
} catch (error) {
|
|
148
|
-
console.warn("[CollabClient] Failed to clear outbox store during dispose:", error);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
if (this.socket) {
|
|
152
|
-
this.socket.off("snapshot", this._onSnapshot);
|
|
153
|
-
this.socket.off("ops", this._onOps);
|
|
154
|
-
this.socket.off("commit", this._onCommit);
|
|
155
|
-
this.socket.off("liveMode", this._onLiveMode);
|
|
156
|
-
this.socket.off("connect", this._onConnect);
|
|
157
|
-
this.socket.off("error", this._onError);
|
|
158
|
-
this.socket.removeAllListeners();
|
|
159
|
-
this.socket.disconnect();
|
|
160
|
-
this.socket = null;
|
|
161
|
-
}
|
|
162
|
-
if (this.ydoc) {
|
|
163
|
-
this.ydoc.destroy();
|
|
164
|
-
this.ydoc = null;
|
|
165
|
-
}
|
|
166
|
-
if (typeof this._readyResolve === "function") {
|
|
167
|
-
this._readyResolve();
|
|
168
|
-
this._readyResolve = null;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
_onLiveMode = (flag) => {
|
|
172
|
-
this.live = flag;
|
|
173
|
-
};
|
|
174
|
-
_onError = (e) => {
|
|
175
|
-
console.warn("[collab] socket error", e);
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
function createMemoryOutbox() {
|
|
179
|
-
const store = /* @__PURE__ */ new Map();
|
|
180
|
-
return {
|
|
181
|
-
put: (item) => store.set(item.id, item),
|
|
182
|
-
toArray: () => Array.from(store.values()),
|
|
183
|
-
clear: () => store.clear()
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
async function createDexieOutbox(name) {
|
|
187
|
-
const { default: Dexie } = await import("dexie");
|
|
188
|
-
const db = new Dexie(`collab-${name}`);
|
|
189
|
-
db.version(1).stores({ outbox: "id, ops" });
|
|
190
|
-
return db.table("outbox");
|
|
191
|
-
}
|
|
192
|
-
export {
|
|
193
|
-
CollabClient
|
|
194
|
-
};
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { diffJson } from "./jsonDiff.js";
|
|
2
|
-
import { computeOrdersForTuples } from "./ordering.js";
|
|
3
|
-
function isPlainObject(val) {
|
|
4
|
-
return val && typeof val === "object" && !Array.isArray(val);
|
|
5
|
-
}
|
|
6
|
-
function getByPathSafe(root, path) {
|
|
7
|
-
if (!root || typeof root.getByPath !== "function") {
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
try {
|
|
11
|
-
return root.getByPath(path);
|
|
12
|
-
} catch {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function resolveNextValueFromTuples(tuples, path) {
|
|
17
|
-
if (!Array.isArray(tuples) || !Array.isArray(path)) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
for (let i = tuples.length - 1; i >= 0; i--) {
|
|
21
|
-
const t = tuples[i];
|
|
22
|
-
if (!Array.isArray(t) || t.length < 3) {
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
const [action, tuplePath, tupleValue] = t;
|
|
26
|
-
if (action !== "update" && action !== "set" || !Array.isArray(tuplePath)) {
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
if (tuplePath.length > path.length) {
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
let isPrefix = true;
|
|
33
|
-
for (let j = 0; j < tuplePath.length; j++) {
|
|
34
|
-
if (tuplePath[j] !== path[j]) {
|
|
35
|
-
isPrefix = false;
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (!isPrefix) {
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
if (tuplePath.length === path.length) {
|
|
43
|
-
return tupleValue;
|
|
44
|
-
}
|
|
45
|
-
let current = tupleValue;
|
|
46
|
-
for (let j = tuplePath.length; j < path.length; j++) {
|
|
47
|
-
if (current == null) {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
current = current[path[j]];
|
|
51
|
-
}
|
|
52
|
-
if (current !== null) {
|
|
53
|
-
return current;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
function preprocessChanges(root, tuples = [], options = {}) {
|
|
59
|
-
const expandTuple = (t) => {
|
|
60
|
-
const [action, path, value] = t || [];
|
|
61
|
-
const isSchemaPath = Array.isArray(path) && path[0] === "schema";
|
|
62
|
-
const isFilesPath = Array.isArray(path) && path[0] === "files";
|
|
63
|
-
if (action === "delete") {
|
|
64
|
-
return [t];
|
|
65
|
-
}
|
|
66
|
-
const canConsiderExpansion = action === "update" && Array.isArray(path) && (path.length === 1 || path.length === 2 || isSchemaPath && path.length === 3) && isPlainObject(value);
|
|
67
|
-
if (!canConsiderExpansion || isFilesPath || value && value.type === "files") {
|
|
68
|
-
return [t];
|
|
69
|
-
}
|
|
70
|
-
const prevRaw = getByPathSafe(root, path);
|
|
71
|
-
const isCreatePath = Array.isArray(path) && action === "update" && // e.g. ['update', ['components', 'NewKey'], {...}]
|
|
72
|
-
(!isSchemaPath && path.length === 2 || // e.g. ['update', ['schema', 'components', 'NewKey'], {...}]
|
|
73
|
-
isSchemaPath && path.length === 3) && (prevRaw === null || typeof prevRaw === "undefined");
|
|
74
|
-
if (isCreatePath) {
|
|
75
|
-
return [t];
|
|
76
|
-
}
|
|
77
|
-
const prev = prevRaw || {};
|
|
78
|
-
const next = value || {};
|
|
79
|
-
if (!isPlainObject(prev) || !isPlainObject(next)) {
|
|
80
|
-
return [t];
|
|
81
|
-
}
|
|
82
|
-
const ops = diffJson(prev, next, []);
|
|
83
|
-
if (!ops.length) {
|
|
84
|
-
return [t];
|
|
85
|
-
}
|
|
86
|
-
const out = [];
|
|
87
|
-
for (let i = 0; i < ops.length; i++) {
|
|
88
|
-
const op = ops[i];
|
|
89
|
-
const fullPath = [...path, ...op.path];
|
|
90
|
-
const last = fullPath[fullPath.length - 1];
|
|
91
|
-
if (op.action === "set") {
|
|
92
|
-
out.push(["update", fullPath, op.value]);
|
|
93
|
-
} else if (op.action === "del") {
|
|
94
|
-
if (last !== "__order") {
|
|
95
|
-
out.push(["delete", fullPath]);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return out;
|
|
100
|
-
};
|
|
101
|
-
const minimizeTuples = (input) => {
|
|
102
|
-
const out = [];
|
|
103
|
-
const seen2 = /* @__PURE__ */ new Set();
|
|
104
|
-
for (let i = 0; i < input.length; i++) {
|
|
105
|
-
const expanded = expandTuple(input[i]);
|
|
106
|
-
for (let k = 0; k < expanded.length; k++) {
|
|
107
|
-
const tuple = expanded[k];
|
|
108
|
-
const isDelete = Array.isArray(tuple) && tuple[0] === "delete";
|
|
109
|
-
const isOrderKey = isDelete && Array.isArray(tuple[1]) && tuple[1][tuple[1].length - 1] === "__order";
|
|
110
|
-
if (!isOrderKey) {
|
|
111
|
-
const key = JSON.stringify(tuple);
|
|
112
|
-
if (!seen2.has(key)) {
|
|
113
|
-
seen2.add(key);
|
|
114
|
-
out.push(tuple);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return out;
|
|
120
|
-
};
|
|
121
|
-
const granularChanges = (() => {
|
|
122
|
-
try {
|
|
123
|
-
const res = minimizeTuples(tuples);
|
|
124
|
-
if (options.append && options.append.length) {
|
|
125
|
-
res.push(...options.append);
|
|
126
|
-
}
|
|
127
|
-
return res;
|
|
128
|
-
} catch {
|
|
129
|
-
return Array.isArray(tuples) ? tuples.slice() : [];
|
|
130
|
-
}
|
|
131
|
-
})();
|
|
132
|
-
const hydratedGranularChanges = granularChanges.map((t) => {
|
|
133
|
-
if (!Array.isArray(t) || t.length < 3) {
|
|
134
|
-
return t;
|
|
135
|
-
}
|
|
136
|
-
const [action, path] = t;
|
|
137
|
-
if (action !== "update" && action !== "set" || !Array.isArray(path)) {
|
|
138
|
-
return t;
|
|
139
|
-
}
|
|
140
|
-
const nextValue = resolveNextValueFromTuples(tuples, path);
|
|
141
|
-
if (nextValue === null) {
|
|
142
|
-
return t;
|
|
143
|
-
}
|
|
144
|
-
return [action, path, nextValue];
|
|
145
|
-
});
|
|
146
|
-
const baseOrders = computeOrdersForTuples(root, hydratedGranularChanges);
|
|
147
|
-
const preferOrdersMap = /* @__PURE__ */ new Map();
|
|
148
|
-
for (let i = 0; i < tuples.length; i++) {
|
|
149
|
-
const t = tuples[i];
|
|
150
|
-
if (!Array.isArray(t) || t.length < 3) {
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
const [action, path, value] = t;
|
|
154
|
-
const isFilesPath = Array.isArray(path) && path[0] === "files";
|
|
155
|
-
if (action !== "update" || !Array.isArray(path) || path.length !== 1 && path.length !== 2 || !isPlainObject(value) || isFilesPath || value && value.type === "files") {
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
const keys = Object.keys(value).filter((k) => k !== "__order");
|
|
159
|
-
const key = JSON.stringify(path);
|
|
160
|
-
preferOrdersMap.set(key, { path, keys });
|
|
161
|
-
}
|
|
162
|
-
const mergedOrders = [];
|
|
163
|
-
const seen = /* @__PURE__ */ new Set();
|
|
164
|
-
preferOrdersMap.forEach((v, k) => {
|
|
165
|
-
seen.add(k);
|
|
166
|
-
mergedOrders.push(v);
|
|
167
|
-
});
|
|
168
|
-
for (let i = 0; i < baseOrders.length; i++) {
|
|
169
|
-
const v = baseOrders[i];
|
|
170
|
-
const k = JSON.stringify(v.path);
|
|
171
|
-
if (!seen.has(k)) {
|
|
172
|
-
seen.add(k);
|
|
173
|
-
mergedOrders.push(v);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return { granularChanges: hydratedGranularChanges, orders: mergedOrders };
|
|
177
|
-
}
|
|
178
|
-
export {
|
|
179
|
-
preprocessChanges
|
|
180
|
-
};
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
function isPlainObject(o) {
|
|
2
|
-
return o && typeof o === "object" && !Array.isArray(o);
|
|
3
|
-
}
|
|
4
|
-
function deepEqual(a, b) {
|
|
5
|
-
if (Object.is(a, b)) {
|
|
6
|
-
return true;
|
|
7
|
-
}
|
|
8
|
-
if (typeof a === "function" && typeof b === "function") {
|
|
9
|
-
try {
|
|
10
|
-
return a.toString() === b.toString();
|
|
11
|
-
} catch {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
if (typeof a === "function" || typeof b === "function") {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
if (a instanceof Date && b instanceof Date) {
|
|
19
|
-
return a.getTime() === b.getTime();
|
|
20
|
-
}
|
|
21
|
-
if (a instanceof RegExp && b instanceof RegExp) {
|
|
22
|
-
return String(a) === String(b);
|
|
23
|
-
}
|
|
24
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
25
|
-
if (a.length !== b.length) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
for (let i = 0; i < a.length; i++) {
|
|
29
|
-
if (!deepEqual(a[i], b[i])) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
if (a && b && typeof a === "object" && typeof b === "object") {
|
|
36
|
-
const aKeys = Object.keys(a);
|
|
37
|
-
const bKeys = Object.keys(b);
|
|
38
|
-
if (aKeys.length !== bKeys.length) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
for (let i = 0; i < aKeys.length; i++) {
|
|
42
|
-
const key = aKeys[i];
|
|
43
|
-
if (!Object.hasOwn(b, key)) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
if (!deepEqual(a[key], b[key])) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
import * as Y from "yjs";
|
|
55
|
-
function getRootMap(ydoc) {
|
|
56
|
-
return ydoc.getMap("root");
|
|
57
|
-
}
|
|
58
|
-
function diffJson(prev, next, prefix = []) {
|
|
59
|
-
const ops = [];
|
|
60
|
-
const _prefix = Array.isArray(prefix) ? prefix : [];
|
|
61
|
-
for (const key in prev) {
|
|
62
|
-
if (Object.hasOwn(prev, key) && !(key in next)) {
|
|
63
|
-
ops.push({ action: "del", path: [..._prefix, key] });
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
for (const key in next) {
|
|
67
|
-
if (Object.hasOwn(next, key)) {
|
|
68
|
-
const pVal = prev == null ? void 0 : prev[key];
|
|
69
|
-
const nVal = next[key];
|
|
70
|
-
if (isPlainObject(pVal) && isPlainObject(nVal)) {
|
|
71
|
-
ops.push(...diffJson(pVal, nVal, [..._prefix, key]));
|
|
72
|
-
} else if (!deepEqual(pVal, nVal)) {
|
|
73
|
-
ops.push({ action: "set", path: [..._prefix, key], value: nVal });
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return ops;
|
|
78
|
-
}
|
|
79
|
-
function applyOpsToJson(ops, ydoc) {
|
|
80
|
-
if (!ydoc || !Array.isArray(ops) || !ops.length) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
ydoc.transact(() => {
|
|
84
|
-
const root = getRootMap(ydoc);
|
|
85
|
-
ops.forEach((op) => {
|
|
86
|
-
const { action, path = [], value } = op || {};
|
|
87
|
-
if (!path.length) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
let target = root;
|
|
91
|
-
for (let i = 0; i < path.length - 1; i++) {
|
|
92
|
-
const key = path[i];
|
|
93
|
-
let next = target.get(key);
|
|
94
|
-
if (!(next instanceof Y.Map)) {
|
|
95
|
-
const fresh = new Y.Map();
|
|
96
|
-
if (isPlainObject(next)) {
|
|
97
|
-
Object.entries(next).forEach(([k, v]) => fresh.set(k, v));
|
|
98
|
-
}
|
|
99
|
-
target.set(key, fresh);
|
|
100
|
-
next = fresh;
|
|
101
|
-
}
|
|
102
|
-
target = next;
|
|
103
|
-
}
|
|
104
|
-
const last = path[path.length - 1];
|
|
105
|
-
if (action === "set") {
|
|
106
|
-
target.set(last, value);
|
|
107
|
-
} else if (action === "del") {
|
|
108
|
-
target.delete(last);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}, "remote");
|
|
112
|
-
}
|
|
113
|
-
export {
|
|
114
|
-
applyOpsToJson,
|
|
115
|
-
diffJson
|
|
116
|
-
};
|