@symbo.ls/sdk 2.34.34 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/README.md +13 -315
  2. package/dist/cjs/config/environment.js +50 -124
  3. package/dist/cjs/index.js +22 -169
  4. package/dist/cjs/services/AIService.js +155 -0
  5. package/dist/cjs/services/AuthService.js +277 -751
  6. package/dist/cjs/services/BaseService.js +6 -158
  7. package/dist/cjs/services/BasedService.js +679 -0
  8. package/dist/cjs/services/SocketIOService.js +309 -0
  9. package/dist/cjs/services/SocketService.js +161 -0
  10. package/dist/cjs/services/SymstoryService.js +485 -0
  11. package/dist/cjs/services/index.js +16 -64
  12. package/dist/cjs/utils/basedQuerys.js +61 -0
  13. package/dist/cjs/utils/permission.js +4 -4
  14. package/dist/cjs/utils/services.js +80 -301
  15. package/dist/cjs/utils/symstoryClient.js +228 -0
  16. package/dist/cjs/utils/validation.js +3 -0
  17. package/dist/esm/config/environment.js +50 -124
  18. package/dist/esm/index.js +11282 -49789
  19. package/dist/esm/services/AIService.js +185 -0
  20. package/dist/esm/services/AuthService.js +358 -1506
  21. package/dist/esm/services/BaseService.js +6 -757
  22. package/dist/esm/services/BasedService.js +4651 -0
  23. package/dist/esm/services/SocketIOService.js +467 -0
  24. package/dist/esm/services/SocketService.js +191 -0
  25. package/dist/esm/services/SymstoryService.js +6849 -0
  26. package/dist/esm/services/index.js +11188 -49352
  27. package/dist/esm/utils/basedQuerys.js +43 -0
  28. package/dist/esm/utils/permission.js +4 -4
  29. package/dist/esm/utils/services.js +80 -301
  30. package/dist/esm/utils/symstoryClient.js +334 -0
  31. package/dist/esm/utils/validation.js +26 -93
  32. package/dist/node/config/environment.js +50 -124
  33. package/dist/node/index.js +26 -202
  34. package/dist/node/services/AIService.js +136 -0
  35. package/dist/node/services/AuthService.js +278 -751
  36. package/dist/node/services/BaseService.js +6 -148
  37. package/dist/node/services/BasedService.js +650 -0
  38. package/dist/node/services/SocketIOService.js +280 -0
  39. package/dist/node/services/SocketService.js +142 -0
  40. package/dist/node/services/SymstoryService.js +456 -0
  41. package/dist/node/services/index.js +16 -64
  42. package/dist/node/utils/basedQuerys.js +42 -0
  43. package/dist/node/utils/permission.js +4 -4
  44. package/dist/node/utils/services.js +80 -301
  45. package/dist/node/utils/symstoryClient.js +199 -0
  46. package/dist/node/utils/validation.js +3 -0
  47. package/package.json +21 -43
  48. package/src/config/environment.js +50 -126
  49. package/src/index.js +24 -208
  50. package/src/services/AIService.js +150 -0
  51. package/src/services/AuthService.js +298 -893
  52. package/src/services/BaseService.js +6 -166
  53. package/src/services/BasedService.js +722 -0
  54. package/src/services/SocketIOService.js +356 -0
  55. package/src/services/SocketService.js +168 -0
  56. package/src/services/SymstoryService.js +563 -0
  57. package/src/services/index.js +13 -80
  58. package/src/utils/basedQuerys.js +41 -0
  59. package/src/utils/permission.js +4 -4
  60. package/src/utils/services.js +83 -325
  61. package/src/utils/symstoryClient.js +218 -0
  62. package/src/utils/validation.js +3 -0
  63. package/dist/cjs/services/AdminService.js +0 -351
  64. package/dist/cjs/services/BranchService.js +0 -484
  65. package/dist/cjs/services/CollabService.js +0 -743
  66. package/dist/cjs/services/DnsService.js +0 -340
  67. package/dist/cjs/services/FeatureFlagService.js +0 -175
  68. package/dist/cjs/services/FileService.js +0 -201
  69. package/dist/cjs/services/IntegrationService.js +0 -538
  70. package/dist/cjs/services/MetricsService.js +0 -62
  71. package/dist/cjs/services/PaymentService.js +0 -271
  72. package/dist/cjs/services/PlanService.js +0 -426
  73. package/dist/cjs/services/ProjectService.js +0 -1207
  74. package/dist/cjs/services/PullRequestService.js +0 -503
  75. package/dist/cjs/services/ScreenshotService.js +0 -304
  76. package/dist/cjs/services/SubscriptionService.js +0 -396
  77. package/dist/cjs/services/TrackingService.js +0 -661
  78. package/dist/cjs/services/WaitlistService.js +0 -148
  79. package/dist/cjs/state/RootStateManager.js +0 -65
  80. package/dist/cjs/state/rootEventBus.js +0 -74
  81. package/dist/cjs/utils/CollabClient.js +0 -223
  82. package/dist/cjs/utils/TokenManager.js +0 -422
  83. package/dist/cjs/utils/changePreprocessor.js +0 -199
  84. package/dist/cjs/utils/jsonDiff.js +0 -145
  85. package/dist/cjs/utils/ordering.js +0 -309
  86. package/dist/esm/services/AdminService.js +0 -1132
  87. package/dist/esm/services/BranchService.js +0 -1265
  88. package/dist/esm/services/CollabService.js +0 -26838
  89. package/dist/esm/services/DnsService.js +0 -1121
  90. package/dist/esm/services/FeatureFlagService.js +0 -956
  91. package/dist/esm/services/FileService.js +0 -982
  92. package/dist/esm/services/IntegrationService.js +0 -1319
  93. package/dist/esm/services/MetricsService.js +0 -843
  94. package/dist/esm/services/PaymentService.js +0 -1052
  95. package/dist/esm/services/PlanService.js +0 -1207
  96. package/dist/esm/services/ProjectService.js +0 -2526
  97. package/dist/esm/services/PullRequestService.js +0 -1284
  98. package/dist/esm/services/ScreenshotService.js +0 -1085
  99. package/dist/esm/services/SubscriptionService.js +0 -1177
  100. package/dist/esm/services/TrackingService.js +0 -18343
  101. package/dist/esm/services/WaitlistService.js +0 -929
  102. package/dist/esm/state/RootStateManager.js +0 -90
  103. package/dist/esm/state/rootEventBus.js +0 -56
  104. package/dist/esm/utils/CollabClient.js +0 -18901
  105. package/dist/esm/utils/TokenManager.js +0 -408
  106. package/dist/esm/utils/changePreprocessor.js +0 -542
  107. package/dist/esm/utils/jsonDiff.js +0 -7011
  108. package/dist/esm/utils/ordering.js +0 -291
  109. package/dist/node/services/AdminService.js +0 -332
  110. package/dist/node/services/BranchService.js +0 -465
  111. package/dist/node/services/CollabService.js +0 -724
  112. package/dist/node/services/DnsService.js +0 -321
  113. package/dist/node/services/FeatureFlagService.js +0 -156
  114. package/dist/node/services/FileService.js +0 -182
  115. package/dist/node/services/IntegrationService.js +0 -519
  116. package/dist/node/services/MetricsService.js +0 -43
  117. package/dist/node/services/PaymentService.js +0 -252
  118. package/dist/node/services/PlanService.js +0 -407
  119. package/dist/node/services/ProjectService.js +0 -1188
  120. package/dist/node/services/PullRequestService.js +0 -484
  121. package/dist/node/services/ScreenshotService.js +0 -285
  122. package/dist/node/services/SubscriptionService.js +0 -377
  123. package/dist/node/services/TrackingService.js +0 -632
  124. package/dist/node/services/WaitlistService.js +0 -129
  125. package/dist/node/state/RootStateManager.js +0 -36
  126. package/dist/node/state/rootEventBus.js +0 -55
  127. package/dist/node/utils/CollabClient.js +0 -194
  128. package/dist/node/utils/TokenManager.js +0 -403
  129. package/dist/node/utils/changePreprocessor.js +0 -180
  130. package/dist/node/utils/jsonDiff.js +0 -116
  131. package/dist/node/utils/ordering.js +0 -290
  132. package/src/services/AdminService.js +0 -374
  133. package/src/services/BranchService.js +0 -536
  134. package/src/services/CollabService.js +0 -900
  135. package/src/services/DnsService.js +0 -366
  136. package/src/services/FeatureFlagService.js +0 -174
  137. package/src/services/FileService.js +0 -213
  138. package/src/services/IntegrationService.js +0 -548
  139. package/src/services/MetricsService.js +0 -40
  140. package/src/services/PaymentService.js +0 -287
  141. package/src/services/PlanService.js +0 -468
  142. package/src/services/ProjectService.js +0 -1366
  143. package/src/services/PullRequestService.js +0 -537
  144. package/src/services/ScreenshotService.js +0 -258
  145. package/src/services/SubscriptionService.js +0 -425
  146. package/src/services/TrackingService.js +0 -853
  147. package/src/services/WaitlistService.js +0 -130
  148. package/src/services/tests/BranchService/createBranch.test.js +0 -153
  149. package/src/services/tests/BranchService/deleteBranch.test.js +0 -173
  150. package/src/services/tests/BranchService/getBranchChanges.test.js +0 -146
  151. package/src/services/tests/BranchService/listBranches.test.js +0 -87
  152. package/src/services/tests/BranchService/mergeBranch.test.js +0 -210
  153. package/src/services/tests/BranchService/publishVersion.test.js +0 -183
  154. package/src/services/tests/BranchService/renameBranch.test.js +0 -240
  155. package/src/services/tests/BranchService/resetBranch.test.js +0 -152
  156. package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +0 -67
  157. package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +0 -75
  158. package/src/services/tests/FileService/createFileFormData.test.js +0 -74
  159. package/src/services/tests/FileService/getFileUrl.test.js +0 -69
  160. package/src/services/tests/FileService/updateProjectIcon.test.js +0 -109
  161. package/src/services/tests/FileService/uploadDocument.test.js +0 -36
  162. package/src/services/tests/FileService/uploadFile.test.js +0 -78
  163. package/src/services/tests/FileService/uploadFileWithValidation.test.js +0 -114
  164. package/src/services/tests/FileService/uploadImage.test.js +0 -36
  165. package/src/services/tests/FileService/uploadMultipleFiles.test.js +0 -111
  166. package/src/services/tests/FileService/validateFile.test.js +0 -63
  167. package/src/services/tests/PlanService/createPlan.test.js +0 -104
  168. package/src/services/tests/PlanService/createPlanWithValidation.test.js +0 -523
  169. package/src/services/tests/PlanService/deletePlan.test.js +0 -92
  170. package/src/services/tests/PlanService/getActivePlans.test.js +0 -123
  171. package/src/services/tests/PlanService/getAdminPlans.test.js +0 -84
  172. package/src/services/tests/PlanService/getPlan.test.js +0 -50
  173. package/src/services/tests/PlanService/getPlanByKey.test.js +0 -109
  174. package/src/services/tests/PlanService/getPlanWithValidation.test.js +0 -85
  175. package/src/services/tests/PlanService/getPlans.test.js +0 -53
  176. package/src/services/tests/PlanService/getPlansByPriceRange.test.js +0 -109
  177. package/src/services/tests/PlanService/getPlansWithValidation.test.js +0 -48
  178. package/src/services/tests/PlanService/initializePlans.test.js +0 -75
  179. package/src/services/tests/PlanService/updatePlan.test.js +0 -111
  180. package/src/services/tests/PlanService/updatePlanWithValidation.test.js +0 -556
  181. package/src/state/RootStateManager.js +0 -76
  182. package/src/state/rootEventBus.js +0 -67
  183. package/src/utils/CollabClient.js +0 -248
  184. package/src/utils/TokenManager.js +0 -479
  185. package/src/utils/changePreprocessor.js +0 -239
  186. package/src/utils/jsonDiff.js +0 -144
  187. package/src/utils/ordering.js +0 -271
@@ -1,542 +0,0 @@
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
- };