@symbo.ls/sdk 3.2.3 → 3.2.7
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 +141 -0
- package/dist/cjs/config/environment.js +94 -10
- package/dist/cjs/index.js +152 -12
- package/dist/cjs/services/AdminService.js +351 -0
- package/dist/cjs/services/AuthService.js +738 -305
- package/dist/cjs/services/BaseService.js +158 -6
- package/dist/cjs/services/BranchService.js +484 -0
- package/dist/cjs/services/CollabService.js +439 -116
- package/dist/cjs/services/DnsService.js +340 -0
- package/dist/cjs/services/FeatureFlagService.js +175 -0
- package/dist/cjs/services/FileService.js +201 -0
- package/dist/cjs/services/IntegrationService.js +538 -0
- package/dist/cjs/services/MetricsService.js +62 -0
- package/dist/cjs/services/PaymentService.js +271 -0
- package/dist/cjs/services/PlanService.js +426 -0
- package/dist/cjs/services/ProjectService.js +1207 -0
- package/dist/cjs/services/PullRequestService.js +503 -0
- package/dist/cjs/services/ScreenshotService.js +304 -0
- package/dist/cjs/services/SubscriptionService.js +396 -0
- package/dist/cjs/services/TrackingService.js +661 -0
- package/dist/cjs/services/WaitlistService.js +148 -0
- package/dist/cjs/services/index.js +60 -4
- package/dist/cjs/state/RootStateManager.js +2 -23
- package/dist/cjs/state/rootEventBus.js +9 -0
- package/dist/cjs/utils/CollabClient.js +78 -12
- package/dist/cjs/utils/TokenManager.js +16 -3
- package/dist/cjs/utils/changePreprocessor.js +199 -0
- package/dist/cjs/utils/jsonDiff.js +46 -4
- package/dist/cjs/utils/ordering.js +309 -0
- package/dist/cjs/utils/services.js +285 -128
- package/dist/cjs/utils/validation.js +0 -3
- package/dist/esm/config/environment.js +94 -10
- package/dist/esm/index.js +47862 -18248
- package/dist/esm/services/AdminService.js +1132 -0
- package/dist/esm/services/AuthService.js +1493 -386
- package/dist/esm/services/BaseService.js +757 -6
- package/dist/esm/services/BranchService.js +1265 -0
- package/dist/esm/services/CollabService.js +24956 -16089
- package/dist/esm/services/DnsService.js +1121 -0
- package/dist/esm/services/FeatureFlagService.js +956 -0
- package/dist/esm/services/FileService.js +982 -0
- package/dist/esm/services/IntegrationService.js +1319 -0
- package/dist/esm/services/MetricsService.js +843 -0
- package/dist/esm/services/PaymentService.js +1052 -0
- package/dist/esm/services/PlanService.js +1207 -0
- package/dist/esm/services/ProjectService.js +2526 -0
- package/dist/esm/services/PullRequestService.js +1284 -0
- package/dist/esm/services/ScreenshotService.js +1085 -0
- package/dist/esm/services/SubscriptionService.js +1177 -0
- package/dist/esm/services/TrackingService.js +18454 -0
- package/dist/esm/services/WaitlistService.js +929 -0
- package/dist/esm/services/index.js +47373 -18027
- package/dist/esm/state/RootStateManager.js +11 -23
- package/dist/esm/state/rootEventBus.js +9 -0
- package/dist/esm/utils/CollabClient.js +17526 -16120
- package/dist/esm/utils/TokenManager.js +16 -3
- package/dist/esm/utils/changePreprocessor.js +542 -0
- package/dist/esm/utils/jsonDiff.js +958 -43
- package/dist/esm/utils/ordering.js +291 -0
- package/dist/esm/utils/services.js +285 -128
- package/dist/esm/utils/validation.js +116 -50
- package/dist/node/config/environment.js +94 -10
- package/dist/node/index.js +183 -16
- package/dist/node/services/AdminService.js +332 -0
- package/dist/node/services/AuthService.js +742 -310
- package/dist/node/services/BaseService.js +148 -6
- package/dist/node/services/BranchService.js +465 -0
- package/dist/node/services/CollabService.js +439 -116
- package/dist/node/services/DnsService.js +321 -0
- package/dist/node/services/FeatureFlagService.js +156 -0
- package/dist/node/services/FileService.js +182 -0
- package/dist/node/services/IntegrationService.js +519 -0
- package/dist/node/services/MetricsService.js +43 -0
- package/dist/node/services/PaymentService.js +252 -0
- package/dist/node/services/PlanService.js +407 -0
- package/dist/node/services/ProjectService.js +1188 -0
- package/dist/node/services/PullRequestService.js +484 -0
- package/dist/node/services/ScreenshotService.js +285 -0
- package/dist/node/services/SubscriptionService.js +377 -0
- package/dist/node/services/TrackingService.js +632 -0
- package/dist/node/services/WaitlistService.js +129 -0
- package/dist/node/services/index.js +60 -4
- package/dist/node/state/RootStateManager.js +2 -23
- package/dist/node/state/rootEventBus.js +9 -0
- package/dist/node/utils/CollabClient.js +77 -11
- package/dist/node/utils/TokenManager.js +16 -3
- package/dist/node/utils/changePreprocessor.js +180 -0
- package/dist/node/utils/jsonDiff.js +46 -4
- package/dist/node/utils/ordering.js +290 -0
- package/dist/node/utils/services.js +285 -128
- package/dist/node/utils/validation.js +0 -3
- package/package.json +30 -18
- package/src/config/environment.js +95 -10
- package/src/index.js +190 -23
- package/src/services/AdminService.js +374 -0
- package/src/services/AuthService.js +874 -328
- package/src/services/BaseService.js +166 -6
- package/src/services/BranchService.js +536 -0
- package/src/services/CollabService.js +557 -148
- package/src/services/DnsService.js +366 -0
- package/src/services/FeatureFlagService.js +174 -0
- package/src/services/FileService.js +213 -0
- package/src/services/IntegrationService.js +548 -0
- package/src/services/MetricsService.js +40 -0
- package/src/services/PaymentService.js +287 -0
- package/src/services/PlanService.js +468 -0
- package/src/services/ProjectService.js +1366 -0
- package/src/services/PullRequestService.js +537 -0
- package/src/services/ScreenshotService.js +258 -0
- package/src/services/SubscriptionService.js +425 -0
- package/src/services/TrackingService.js +853 -0
- package/src/services/WaitlistService.js +130 -0
- package/src/services/index.js +79 -5
- package/src/services/tests/BranchService/createBranch.test.js +153 -0
- package/src/services/tests/BranchService/deleteBranch.test.js +173 -0
- package/src/services/tests/BranchService/getBranchChanges.test.js +146 -0
- package/src/services/tests/BranchService/listBranches.test.js +87 -0
- package/src/services/tests/BranchService/mergeBranch.test.js +210 -0
- package/src/services/tests/BranchService/publishVersion.test.js +183 -0
- package/src/services/tests/BranchService/renameBranch.test.js +240 -0
- package/src/services/tests/BranchService/resetBranch.test.js +152 -0
- package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +67 -0
- package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +75 -0
- package/src/services/tests/FileService/createFileFormData.test.js +74 -0
- package/src/services/tests/FileService/getFileUrl.test.js +69 -0
- package/src/services/tests/FileService/updateProjectIcon.test.js +109 -0
- package/src/services/tests/FileService/uploadDocument.test.js +36 -0
- package/src/services/tests/FileService/uploadFile.test.js +78 -0
- package/src/services/tests/FileService/uploadFileWithValidation.test.js +114 -0
- package/src/services/tests/FileService/uploadImage.test.js +36 -0
- package/src/services/tests/FileService/uploadMultipleFiles.test.js +111 -0
- package/src/services/tests/FileService/validateFile.test.js +63 -0
- package/src/services/tests/PlanService/createPlan.test.js +104 -0
- package/src/services/tests/PlanService/createPlanWithValidation.test.js +523 -0
- package/src/services/tests/PlanService/deletePlan.test.js +92 -0
- package/src/services/tests/PlanService/getActivePlans.test.js +123 -0
- package/src/services/tests/PlanService/getAdminPlans.test.js +84 -0
- package/src/services/tests/PlanService/getPlan.test.js +50 -0
- package/src/services/tests/PlanService/getPlanByKey.test.js +109 -0
- package/src/services/tests/PlanService/getPlanWithValidation.test.js +85 -0
- package/src/services/tests/PlanService/getPlans.test.js +53 -0
- package/src/services/tests/PlanService/getPlansByPriceRange.test.js +109 -0
- package/src/services/tests/PlanService/getPlansWithValidation.test.js +48 -0
- package/src/services/tests/PlanService/initializePlans.test.js +75 -0
- package/src/services/tests/PlanService/updatePlan.test.js +111 -0
- package/src/services/tests/PlanService/updatePlanWithValidation.test.js +556 -0
- package/src/state/RootStateManager.js +37 -32
- package/src/state/rootEventBus.js +19 -0
- package/src/utils/CollabClient.js +99 -12
- package/src/utils/TokenManager.js +20 -3
- package/src/utils/changePreprocessor.js +239 -0
- package/src/utils/jsonDiff.js +40 -5
- package/src/utils/ordering.js +271 -0
- package/src/utils/services.js +306 -139
- package/src/utils/validation.js +0 -3
- package/dist/cjs/services/AIService.js +0 -155
- package/dist/cjs/services/BasedService.js +0 -1185
- package/dist/cjs/services/CoreService.js +0 -2295
- package/dist/cjs/services/SocketService.js +0 -309
- package/dist/cjs/services/SymstoryService.js +0 -571
- package/dist/cjs/utils/basedQuerys.js +0 -181
- package/dist/cjs/utils/symstoryClient.js +0 -259
- package/dist/esm/services/AIService.js +0 -185
- package/dist/esm/services/BasedService.js +0 -5262
- package/dist/esm/services/CoreService.js +0 -2827
- package/dist/esm/services/SocketService.js +0 -456
- package/dist/esm/services/SymstoryService.js +0 -7025
- package/dist/esm/utils/basedQuerys.js +0 -163
- package/dist/esm/utils/symstoryClient.js +0 -354
- package/dist/node/services/AIService.js +0 -136
- package/dist/node/services/BasedService.js +0 -1156
- package/dist/node/services/CoreService.js +0 -2266
- package/dist/node/services/SocketService.js +0 -280
- package/dist/node/services/SymstoryService.js +0 -542
- package/dist/node/utils/basedQuerys.js +0 -162
- package/dist/node/utils/symstoryClient.js +0 -230
- package/src/services/AIService.js +0 -150
- package/src/services/BasedService.js +0 -1302
- package/src/services/CoreService.js +0 -2548
- package/src/services/SocketService.js +0 -336
- package/src/services/SymstoryService.js +0 -649
- package/src/utils/basedQuerys.js +0 -164
- package/src/utils/symstoryClient.js +0 -252
|
@@ -23,7 +23,7 @@ var TokenManager = class {
|
|
|
23
23
|
});
|
|
24
24
|
this.config = {
|
|
25
25
|
storagePrefix: "symbols_",
|
|
26
|
-
storageType: "localStorage",
|
|
26
|
+
storageType: typeof window === "undefined" || process.env.NODE_ENV === "test" || process.env.NODE_ENV === "testing" ? "memory" : "localStorage",
|
|
27
27
|
// 'localStorage' | 'sessionStorage' | 'memory'
|
|
28
28
|
refreshBuffer: 60 * 1e3,
|
|
29
29
|
// Refresh 1 minute before expiry
|
|
@@ -63,13 +63,26 @@ var TokenManager = class {
|
|
|
63
63
|
if (typeof window === "undefined") {
|
|
64
64
|
return this._memoryStorage;
|
|
65
65
|
}
|
|
66
|
+
const safeGetStorage = (provider) => {
|
|
67
|
+
try {
|
|
68
|
+
const storage = provider();
|
|
69
|
+
const testKey = `${this.config.storagePrefix}__tm_test__`;
|
|
70
|
+
storage.setItem(testKey, "1");
|
|
71
|
+
storage.removeItem(testKey);
|
|
72
|
+
return storage;
|
|
73
|
+
} catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const localStorageInstance = safeGetStorage(() => window.localStorage);
|
|
78
|
+
const sessionStorageInstance = safeGetStorage(() => window.sessionStorage);
|
|
66
79
|
switch (this.config.storageType) {
|
|
67
80
|
case "sessionStorage":
|
|
68
|
-
return
|
|
81
|
+
return sessionStorageInstance || this._memoryStorage;
|
|
69
82
|
case "memory":
|
|
70
83
|
return this._memoryStorage;
|
|
71
84
|
default:
|
|
72
|
-
return
|
|
85
|
+
return localStorageInstance || this._memoryStorage;
|
|
73
86
|
}
|
|
74
87
|
}
|
|
75
88
|
/**
|
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
// src/utils/jsonDiff.js
|
|
2
|
+
function isPlainObject(o) {
|
|
3
|
+
return o && typeof o === "object" && !Array.isArray(o);
|
|
4
|
+
}
|
|
5
|
+
function deepEqual(a, b) {
|
|
6
|
+
if (Object.is(a, b)) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
if (typeof a === "function" && typeof b === "function") {
|
|
10
|
+
try {
|
|
11
|
+
return a.toString() === b.toString();
|
|
12
|
+
} catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (typeof a === "function" || typeof b === "function") {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
if (a instanceof Date && b instanceof Date) {
|
|
20
|
+
return a.getTime() === b.getTime();
|
|
21
|
+
}
|
|
22
|
+
if (a instanceof RegExp && b instanceof RegExp) {
|
|
23
|
+
return String(a) === String(b);
|
|
24
|
+
}
|
|
25
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
26
|
+
if (a.length !== b.length) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
for (let i = 0; i < a.length; i++) {
|
|
30
|
+
if (!deepEqual(a[i], b[i])) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
if (a && b && typeof a === "object" && typeof b === "object") {
|
|
37
|
+
const aKeys = Object.keys(a);
|
|
38
|
+
const bKeys = Object.keys(b);
|
|
39
|
+
if (aKeys.length !== bKeys.length) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
for (let i = 0; i < aKeys.length; i++) {
|
|
43
|
+
const key = aKeys[i];
|
|
44
|
+
if (!Object.hasOwn(b, key)) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (!deepEqual(a[key], b[key])) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
function diffJson(prev, next, prefix = []) {
|
|
56
|
+
const ops = [];
|
|
57
|
+
const _prefix = Array.isArray(prefix) ? prefix : [];
|
|
58
|
+
for (const key in prev) {
|
|
59
|
+
if (Object.hasOwn(prev, key) && !(key in next)) {
|
|
60
|
+
ops.push({ action: "del", path: [..._prefix, key] });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
for (const key in next) {
|
|
64
|
+
if (Object.hasOwn(next, key)) {
|
|
65
|
+
const pVal = prev == null ? void 0 : prev[key];
|
|
66
|
+
const nVal = next[key];
|
|
67
|
+
if (isPlainObject(pVal) && isPlainObject(nVal)) {
|
|
68
|
+
ops.push(...diffJson(pVal, nVal, [..._prefix, key]));
|
|
69
|
+
} else if (!deepEqual(pVal, nVal)) {
|
|
70
|
+
ops.push({ action: "set", path: [..._prefix, key], value: nVal });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return ops;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/utils/ordering.js
|
|
78
|
+
function isObjectLike(val) {
|
|
79
|
+
return val && typeof val === "object" && !Array.isArray(val);
|
|
80
|
+
}
|
|
81
|
+
function normalizePath(path) {
|
|
82
|
+
if (Array.isArray(path)) {
|
|
83
|
+
return path;
|
|
84
|
+
}
|
|
85
|
+
if (typeof path === "string") {
|
|
86
|
+
return [path];
|
|
87
|
+
}
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
function getParentPathsFromTuples(tuples = []) {
|
|
91
|
+
const seen = /* @__PURE__ */ new Set();
|
|
92
|
+
const parents = [];
|
|
93
|
+
const META_KEYS = /* @__PURE__ */ new Set([
|
|
94
|
+
"style",
|
|
95
|
+
"class",
|
|
96
|
+
"text",
|
|
97
|
+
"html",
|
|
98
|
+
"content",
|
|
99
|
+
"data",
|
|
100
|
+
"attr",
|
|
101
|
+
"state",
|
|
102
|
+
"scope",
|
|
103
|
+
"define",
|
|
104
|
+
"on",
|
|
105
|
+
"extend",
|
|
106
|
+
"extends",
|
|
107
|
+
"childExtend",
|
|
108
|
+
"childExtends",
|
|
109
|
+
"children",
|
|
110
|
+
"component",
|
|
111
|
+
"context",
|
|
112
|
+
"tag",
|
|
113
|
+
"key",
|
|
114
|
+
"__order",
|
|
115
|
+
"if"
|
|
116
|
+
]);
|
|
117
|
+
for (let i = 0; i < tuples.length; i++) {
|
|
118
|
+
const tuple = tuples[i];
|
|
119
|
+
if (!Array.isArray(tuple) || tuple.length < 2) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const path = normalizePath(tuple[1]);
|
|
123
|
+
if (!path.length) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (path[0] === "schema") {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const immediateParent = path.slice(0, -1);
|
|
130
|
+
if (immediateParent.length) {
|
|
131
|
+
const key = JSON.stringify(immediateParent);
|
|
132
|
+
if (!seen.has(key)) {
|
|
133
|
+
seen.add(key);
|
|
134
|
+
parents.push(immediateParent);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const last = path[path.length - 1];
|
|
138
|
+
if (META_KEYS.has(last) && path.length >= 2) {
|
|
139
|
+
const containerParent = path.slice(0, -2);
|
|
140
|
+
if (containerParent.length) {
|
|
141
|
+
const key2 = JSON.stringify(containerParent);
|
|
142
|
+
if (!seen.has(key2)) {
|
|
143
|
+
seen.add(key2);
|
|
144
|
+
parents.push(containerParent);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
for (let j = 0; j < path.length; j++) {
|
|
149
|
+
const seg = path[j];
|
|
150
|
+
if (!META_KEYS.has(seg)) {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const containerParent2 = path.slice(0, j);
|
|
154
|
+
if (!containerParent2.length) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const key3 = JSON.stringify(containerParent2);
|
|
158
|
+
if (!seen.has(key3)) {
|
|
159
|
+
seen.add(key3);
|
|
160
|
+
parents.push(containerParent2);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return parents;
|
|
165
|
+
}
|
|
166
|
+
function computeOrdersFromState(root, parentPaths = []) {
|
|
167
|
+
if (!root || typeof root.getByPath !== "function") {
|
|
168
|
+
return [];
|
|
169
|
+
}
|
|
170
|
+
const orders = [];
|
|
171
|
+
const EXCLUDE_KEYS = /* @__PURE__ */ new Set(["__order"]);
|
|
172
|
+
for (let i = 0; i < parentPaths.length; i++) {
|
|
173
|
+
const parentPath = parentPaths[i];
|
|
174
|
+
const obj = (() => {
|
|
175
|
+
try {
|
|
176
|
+
return root.getByPath(parentPath);
|
|
177
|
+
} catch {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
})();
|
|
181
|
+
if (!isObjectLike(obj)) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
const keys = Object.keys(obj).filter((k) => !EXCLUDE_KEYS.has(k));
|
|
185
|
+
orders.push({ path: parentPath, keys });
|
|
186
|
+
}
|
|
187
|
+
return orders;
|
|
188
|
+
}
|
|
189
|
+
function normaliseSchemaCode(code) {
|
|
190
|
+
if (typeof code !== "string" || !code.length) {
|
|
191
|
+
return "";
|
|
192
|
+
}
|
|
193
|
+
return code.replaceAll("/////n", "\n").replaceAll("/////tilde", "`");
|
|
194
|
+
}
|
|
195
|
+
function parseExportedObject(code) {
|
|
196
|
+
const src = normaliseSchemaCode(code);
|
|
197
|
+
if (!src) {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
const body = src.replace(/^\s*export\s+default\s*/u, "return ");
|
|
201
|
+
try {
|
|
202
|
+
return new Function(body)();
|
|
203
|
+
} catch {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function extractTopLevelKeysFromCode(code) {
|
|
208
|
+
const obj = parseExportedObject(code);
|
|
209
|
+
if (!obj || typeof obj !== "object") {
|
|
210
|
+
return [];
|
|
211
|
+
}
|
|
212
|
+
return Object.keys(obj);
|
|
213
|
+
}
|
|
214
|
+
function computeOrdersForTuples(root, tuples = []) {
|
|
215
|
+
const pendingChildrenByContainer = /* @__PURE__ */ new Map();
|
|
216
|
+
for (let i = 0; i < tuples.length; i++) {
|
|
217
|
+
const t = tuples[i];
|
|
218
|
+
if (!Array.isArray(t)) {
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
const [action, path] = t;
|
|
222
|
+
const p = normalizePath(path);
|
|
223
|
+
if (!Array.isArray(p) || p.length < 2) {
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (p[0] === "schema") {
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
const containerPath = p.slice(0, -1);
|
|
230
|
+
const childKey = p[p.length - 1];
|
|
231
|
+
const key = JSON.stringify(containerPath);
|
|
232
|
+
if (!pendingChildrenByContainer.has(key)) {
|
|
233
|
+
pendingChildrenByContainer.set(key, /* @__PURE__ */ new Set());
|
|
234
|
+
}
|
|
235
|
+
if (action === "update" || action === "set") {
|
|
236
|
+
pendingChildrenByContainer.get(key).add(childKey);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const preferredOrderMap = /* @__PURE__ */ new Map();
|
|
240
|
+
for (let i = 0; i < tuples.length; i++) {
|
|
241
|
+
const t = tuples[i];
|
|
242
|
+
if (!Array.isArray(t)) {
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
const [action, path, value] = t;
|
|
246
|
+
const p = normalizePath(path);
|
|
247
|
+
if (action !== "update" || !Array.isArray(p) || p.length < 3) {
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if (p[0] !== "schema") {
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
const [, type, key] = p;
|
|
254
|
+
const containerPath = [type, key];
|
|
255
|
+
const uses = value && Array.isArray(value.uses) ? value.uses : null;
|
|
256
|
+
const code = value && value.code;
|
|
257
|
+
const obj = (() => {
|
|
258
|
+
try {
|
|
259
|
+
return root && typeof root.getByPath === "function" ? root.getByPath(containerPath) : null;
|
|
260
|
+
} catch {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
})();
|
|
264
|
+
if (!obj) {
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
const present = new Set(Object.keys(obj));
|
|
268
|
+
const EXCLUDE_KEYS = /* @__PURE__ */ new Set(["__order"]);
|
|
269
|
+
const codeKeys = extractTopLevelKeysFromCode(code);
|
|
270
|
+
let resolved = [];
|
|
271
|
+
const pendingKey = JSON.stringify(containerPath);
|
|
272
|
+
const pendingChildren = pendingChildrenByContainer.get(pendingKey) || /* @__PURE__ */ new Set();
|
|
273
|
+
const eligible = /* @__PURE__ */ new Set([...present, ...pendingChildren]);
|
|
274
|
+
if (Array.isArray(codeKeys) && codeKeys.length) {
|
|
275
|
+
resolved = codeKeys.filter((k) => eligible.has(k) && !EXCLUDE_KEYS.has(k));
|
|
276
|
+
}
|
|
277
|
+
if (Array.isArray(uses) && uses.length) {
|
|
278
|
+
for (let u = 0; u < uses.length; u++) {
|
|
279
|
+
const keyName = uses[u];
|
|
280
|
+
if (eligible.has(keyName) && !EXCLUDE_KEYS.has(keyName) && !resolved.includes(keyName)) {
|
|
281
|
+
resolved.push(keyName);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (pendingChildren.size) {
|
|
286
|
+
for (const child of pendingChildren) {
|
|
287
|
+
if (!EXCLUDE_KEYS.has(child) && !resolved.includes(child)) {
|
|
288
|
+
resolved.push(child);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (resolved.length) {
|
|
293
|
+
preferredOrderMap.set(JSON.stringify(containerPath), { path: containerPath, keys: resolved });
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
const parents = getParentPathsFromTuples(tuples);
|
|
297
|
+
const orders = [];
|
|
298
|
+
const seen = /* @__PURE__ */ new Set();
|
|
299
|
+
preferredOrderMap.forEach((v) => {
|
|
300
|
+
const k = JSON.stringify(v.path);
|
|
301
|
+
if (!seen.has(k)) {
|
|
302
|
+
seen.add(k);
|
|
303
|
+
orders.push(v);
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
const fallbackOrders = computeOrdersFromState(root, parents);
|
|
307
|
+
for (let i = 0; i < fallbackOrders.length; i++) {
|
|
308
|
+
const v = fallbackOrders[i];
|
|
309
|
+
const k = JSON.stringify(v.path);
|
|
310
|
+
if (seen.has(k)) {
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
const pending = pendingChildrenByContainer.get(k);
|
|
314
|
+
if (pending && pending.size) {
|
|
315
|
+
const existingKeys = v.keys;
|
|
316
|
+
const existingSet = new Set(existingKeys);
|
|
317
|
+
const META_KEYS = /* @__PURE__ */ new Set([
|
|
318
|
+
"style",
|
|
319
|
+
"class",
|
|
320
|
+
"text",
|
|
321
|
+
"html",
|
|
322
|
+
"content",
|
|
323
|
+
"data",
|
|
324
|
+
"attr",
|
|
325
|
+
"state",
|
|
326
|
+
"scope",
|
|
327
|
+
"define",
|
|
328
|
+
"on",
|
|
329
|
+
"extend",
|
|
330
|
+
"extends",
|
|
331
|
+
"childExtend",
|
|
332
|
+
"childExtends",
|
|
333
|
+
"children",
|
|
334
|
+
"component",
|
|
335
|
+
"context",
|
|
336
|
+
"tag",
|
|
337
|
+
"key",
|
|
338
|
+
"__order",
|
|
339
|
+
"if"
|
|
340
|
+
]);
|
|
341
|
+
let firstMetaIndex = existingKeys.length;
|
|
342
|
+
for (let j = 0; j < existingKeys.length; j++) {
|
|
343
|
+
if (META_KEYS.has(existingKeys[j])) {
|
|
344
|
+
firstMetaIndex = j;
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
for (const child of pending) {
|
|
349
|
+
if (existingSet.has(child)) {
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
const insertIndex = firstMetaIndex;
|
|
353
|
+
existingKeys.splice(insertIndex, 0, child);
|
|
354
|
+
existingSet.add(child);
|
|
355
|
+
firstMetaIndex++;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
seen.add(k);
|
|
359
|
+
orders.push(v);
|
|
360
|
+
}
|
|
361
|
+
return orders;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// src/utils/changePreprocessor.js
|
|
365
|
+
function isPlainObject2(val) {
|
|
366
|
+
return val && typeof val === "object" && !Array.isArray(val);
|
|
367
|
+
}
|
|
368
|
+
function getByPathSafe(root, path) {
|
|
369
|
+
if (!root || typeof root.getByPath !== "function") {
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
try {
|
|
373
|
+
return root.getByPath(path);
|
|
374
|
+
} catch {
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
function resolveNextValueFromTuples(tuples, path) {
|
|
379
|
+
if (!Array.isArray(tuples) || !Array.isArray(path)) {
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
for (let i = tuples.length - 1; i >= 0; i--) {
|
|
383
|
+
const t = tuples[i];
|
|
384
|
+
if (!Array.isArray(t) || t.length < 3) {
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
const [action, tuplePath, tupleValue] = t;
|
|
388
|
+
if (action !== "update" && action !== "set" || !Array.isArray(tuplePath)) {
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
if (tuplePath.length > path.length) {
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
let isPrefix = true;
|
|
395
|
+
for (let j = 0; j < tuplePath.length; j++) {
|
|
396
|
+
if (tuplePath[j] !== path[j]) {
|
|
397
|
+
isPrefix = false;
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
if (!isPrefix) {
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
if (tuplePath.length === path.length) {
|
|
405
|
+
return tupleValue;
|
|
406
|
+
}
|
|
407
|
+
let current = tupleValue;
|
|
408
|
+
for (let j = tuplePath.length; j < path.length; j++) {
|
|
409
|
+
if (current == null) {
|
|
410
|
+
return null;
|
|
411
|
+
}
|
|
412
|
+
current = current[path[j]];
|
|
413
|
+
}
|
|
414
|
+
if (current !== null) {
|
|
415
|
+
return current;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
function preprocessChanges(root, tuples = [], options = {}) {
|
|
421
|
+
const expandTuple = (t) => {
|
|
422
|
+
const [action, path, value] = t || [];
|
|
423
|
+
const isSchemaPath = Array.isArray(path) && path[0] === "schema";
|
|
424
|
+
const isFilesPath = Array.isArray(path) && path[0] === "files";
|
|
425
|
+
if (action === "delete") {
|
|
426
|
+
return [t];
|
|
427
|
+
}
|
|
428
|
+
const canConsiderExpansion = action === "update" && Array.isArray(path) && (path.length === 1 || path.length === 2 || isSchemaPath && path.length === 3) && isPlainObject2(value);
|
|
429
|
+
if (!canConsiderExpansion || isFilesPath || value && value.type === "files") {
|
|
430
|
+
return [t];
|
|
431
|
+
}
|
|
432
|
+
const prevRaw = getByPathSafe(root, path);
|
|
433
|
+
const isCreatePath = Array.isArray(path) && action === "update" && // e.g. ['update', ['components', 'NewKey'], {...}]
|
|
434
|
+
(!isSchemaPath && path.length === 2 || // e.g. ['update', ['schema', 'components', 'NewKey'], {...}]
|
|
435
|
+
isSchemaPath && path.length === 3) && (prevRaw === null || typeof prevRaw === "undefined");
|
|
436
|
+
if (isCreatePath) {
|
|
437
|
+
return [t];
|
|
438
|
+
}
|
|
439
|
+
const prev = prevRaw || {};
|
|
440
|
+
const next = value || {};
|
|
441
|
+
if (!isPlainObject2(prev) || !isPlainObject2(next)) {
|
|
442
|
+
return [t];
|
|
443
|
+
}
|
|
444
|
+
const ops = diffJson(prev, next, []);
|
|
445
|
+
if (!ops.length) {
|
|
446
|
+
return [t];
|
|
447
|
+
}
|
|
448
|
+
const out = [];
|
|
449
|
+
for (let i = 0; i < ops.length; i++) {
|
|
450
|
+
const op = ops[i];
|
|
451
|
+
const fullPath = [...path, ...op.path];
|
|
452
|
+
const last = fullPath[fullPath.length - 1];
|
|
453
|
+
if (op.action === "set") {
|
|
454
|
+
out.push(["update", fullPath, op.value]);
|
|
455
|
+
} else if (op.action === "del") {
|
|
456
|
+
if (last !== "__order") {
|
|
457
|
+
out.push(["delete", fullPath]);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
return out;
|
|
462
|
+
};
|
|
463
|
+
const minimizeTuples = (input) => {
|
|
464
|
+
const out = [];
|
|
465
|
+
const seen2 = /* @__PURE__ */ new Set();
|
|
466
|
+
for (let i = 0; i < input.length; i++) {
|
|
467
|
+
const expanded = expandTuple(input[i]);
|
|
468
|
+
for (let k = 0; k < expanded.length; k++) {
|
|
469
|
+
const tuple = expanded[k];
|
|
470
|
+
const isDelete = Array.isArray(tuple) && tuple[0] === "delete";
|
|
471
|
+
const isOrderKey = isDelete && Array.isArray(tuple[1]) && tuple[1][tuple[1].length - 1] === "__order";
|
|
472
|
+
if (!isOrderKey) {
|
|
473
|
+
const key = JSON.stringify(tuple);
|
|
474
|
+
if (!seen2.has(key)) {
|
|
475
|
+
seen2.add(key);
|
|
476
|
+
out.push(tuple);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
return out;
|
|
482
|
+
};
|
|
483
|
+
const granularChanges = (() => {
|
|
484
|
+
try {
|
|
485
|
+
const res = minimizeTuples(tuples);
|
|
486
|
+
if (options.append && options.append.length) {
|
|
487
|
+
res.push(...options.append);
|
|
488
|
+
}
|
|
489
|
+
return res;
|
|
490
|
+
} catch {
|
|
491
|
+
return Array.isArray(tuples) ? tuples.slice() : [];
|
|
492
|
+
}
|
|
493
|
+
})();
|
|
494
|
+
const hydratedGranularChanges = granularChanges.map((t) => {
|
|
495
|
+
if (!Array.isArray(t) || t.length < 3) {
|
|
496
|
+
return t;
|
|
497
|
+
}
|
|
498
|
+
const [action, path] = t;
|
|
499
|
+
if (action !== "update" && action !== "set" || !Array.isArray(path)) {
|
|
500
|
+
return t;
|
|
501
|
+
}
|
|
502
|
+
const nextValue = resolveNextValueFromTuples(tuples, path);
|
|
503
|
+
if (nextValue === null) {
|
|
504
|
+
return t;
|
|
505
|
+
}
|
|
506
|
+
return [action, path, nextValue];
|
|
507
|
+
});
|
|
508
|
+
const baseOrders = computeOrdersForTuples(root, hydratedGranularChanges);
|
|
509
|
+
const preferOrdersMap = /* @__PURE__ */ new Map();
|
|
510
|
+
for (let i = 0; i < tuples.length; i++) {
|
|
511
|
+
const t = tuples[i];
|
|
512
|
+
if (!Array.isArray(t) || t.length < 3) {
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
const [action, path, value] = t;
|
|
516
|
+
const isFilesPath = Array.isArray(path) && path[0] === "files";
|
|
517
|
+
if (action !== "update" || !Array.isArray(path) || path.length !== 1 && path.length !== 2 || !isPlainObject2(value) || isFilesPath || value && value.type === "files") {
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
const keys = Object.keys(value).filter((k) => k !== "__order");
|
|
521
|
+
const key = JSON.stringify(path);
|
|
522
|
+
preferOrdersMap.set(key, { path, keys });
|
|
523
|
+
}
|
|
524
|
+
const mergedOrders = [];
|
|
525
|
+
const seen = /* @__PURE__ */ new Set();
|
|
526
|
+
preferOrdersMap.forEach((v, k) => {
|
|
527
|
+
seen.add(k);
|
|
528
|
+
mergedOrders.push(v);
|
|
529
|
+
});
|
|
530
|
+
for (let i = 0; i < baseOrders.length; i++) {
|
|
531
|
+
const v = baseOrders[i];
|
|
532
|
+
const k = JSON.stringify(v.path);
|
|
533
|
+
if (!seen.has(k)) {
|
|
534
|
+
seen.add(k);
|
|
535
|
+
mergedOrders.push(v);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return { granularChanges: hydratedGranularChanges, orders: mergedOrders };
|
|
539
|
+
}
|
|
540
|
+
export {
|
|
541
|
+
preprocessChanges
|
|
542
|
+
};
|