@symbo.ls/sdk 2.32.1 → 2.32.4

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.
@@ -0,0 +1,442 @@
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 < 3) {
224
+ continue;
225
+ }
226
+ if (p[0] === "schema") {
227
+ continue;
228
+ }
229
+ const [typeName, containerKey, childKey] = p;
230
+ const containerPath = [typeName, containerKey];
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 existing = new Set(v.keys);
316
+ for (const child of pending) {
317
+ if (existing.has(child)) {
318
+ continue;
319
+ }
320
+ v.keys.push(child);
321
+ }
322
+ }
323
+ seen.add(k);
324
+ orders.push(v);
325
+ }
326
+ return orders;
327
+ }
328
+
329
+ // src/utils/changePreprocessor.js
330
+ function isPlainObject2(val) {
331
+ return val && typeof val === "object" && !Array.isArray(val);
332
+ }
333
+ function getByPathSafe(root, path) {
334
+ if (!root || typeof root.getByPath !== "function") {
335
+ return null;
336
+ }
337
+ try {
338
+ return root.getByPath(path);
339
+ } catch {
340
+ return null;
341
+ }
342
+ }
343
+ function preprocessChanges(root, tuples = [], options = {}) {
344
+ const expandTuple = (t) => {
345
+ const [action, path, value] = t || [];
346
+ const isSchemaPath = Array.isArray(path) && path[0] === "schema";
347
+ if (action === "delete") {
348
+ return [t];
349
+ }
350
+ const canConsiderExpansion = action === "update" && Array.isArray(path) && (path.length === 1 || path.length === 2 || isSchemaPath && path.length === 3) && isPlainObject2(value);
351
+ if (!canConsiderExpansion) {
352
+ return [t];
353
+ }
354
+ const prev = getByPathSafe(root, path) || {};
355
+ const next = value || {};
356
+ if (!isPlainObject2(prev) || !isPlainObject2(next)) {
357
+ return [t];
358
+ }
359
+ const ops = diffJson(prev, next, []);
360
+ if (!ops.length) {
361
+ return [t];
362
+ }
363
+ const out = [];
364
+ for (let i = 0; i < ops.length; i++) {
365
+ const op = ops[i];
366
+ const fullPath = [...path, ...op.path];
367
+ const last = fullPath[fullPath.length - 1];
368
+ if (op.action === "set") {
369
+ out.push(["update", fullPath, op.value]);
370
+ } else if (op.action === "del") {
371
+ if (last !== "__order") {
372
+ out.push(["delete", fullPath]);
373
+ }
374
+ }
375
+ }
376
+ return out;
377
+ };
378
+ const minimizeTuples = (input) => {
379
+ const out = [];
380
+ const seen2 = /* @__PURE__ */ new Set();
381
+ for (let i = 0; i < input.length; i++) {
382
+ const expanded = expandTuple(input[i]);
383
+ for (let k = 0; k < expanded.length; k++) {
384
+ const tuple = expanded[k];
385
+ const isDelete = Array.isArray(tuple) && tuple[0] === "delete";
386
+ const isOrderKey = isDelete && Array.isArray(tuple[1]) && tuple[1][tuple[1].length - 1] === "__order";
387
+ if (!isOrderKey) {
388
+ const key = JSON.stringify(tuple);
389
+ if (!seen2.has(key)) {
390
+ seen2.add(key);
391
+ out.push(tuple);
392
+ }
393
+ }
394
+ }
395
+ }
396
+ return out;
397
+ };
398
+ const granularChanges = (() => {
399
+ try {
400
+ const res = minimizeTuples(tuples);
401
+ if (options.append && options.append.length) {
402
+ res.push(...options.append);
403
+ }
404
+ return res;
405
+ } catch {
406
+ return Array.isArray(tuples) ? tuples.slice() : [];
407
+ }
408
+ })();
409
+ const baseOrders = computeOrdersForTuples(root, granularChanges);
410
+ const preferOrdersMap = /* @__PURE__ */ new Map();
411
+ for (let i = 0; i < tuples.length; i++) {
412
+ const t = tuples[i];
413
+ if (!Array.isArray(t) || t.length < 3) {
414
+ continue;
415
+ }
416
+ const [action, path, value] = t;
417
+ if (action !== "update" || !Array.isArray(path) || path.length !== 1 && path.length !== 2 || !isPlainObject2(value)) {
418
+ continue;
419
+ }
420
+ const keys = Object.keys(value).filter((k) => k !== "__order");
421
+ const key = JSON.stringify(path);
422
+ preferOrdersMap.set(key, { path, keys });
423
+ }
424
+ const mergedOrders = [];
425
+ const seen = /* @__PURE__ */ new Set();
426
+ preferOrdersMap.forEach((v, k) => {
427
+ seen.add(k);
428
+ mergedOrders.push(v);
429
+ });
430
+ for (let i = 0; i < baseOrders.length; i++) {
431
+ const v = baseOrders[i];
432
+ const k = JSON.stringify(v.path);
433
+ if (!seen.has(k)) {
434
+ seen.add(k);
435
+ mergedOrders.push(v);
436
+ }
437
+ }
438
+ return { granularChanges, orders: mergedOrders };
439
+ }
440
+ export {
441
+ preprocessChanges
442
+ };
@@ -6025,12 +6025,54 @@ function isPlainObject(o) {
6025
6025
  return o && typeof o === "object" && !Array.isArray(o);
6026
6026
  }
6027
6027
  function deepEqual(a, b) {
6028
- try {
6029
- return JSON.stringify(a) === JSON.stringify(b);
6030
- } catch (err) {
6031
- console.warn("deepEqual error", err);
6028
+ if (Object.is(a, b)) {
6029
+ return true;
6030
+ }
6031
+ if (typeof a === "function" && typeof b === "function") {
6032
+ try {
6033
+ return a.toString() === b.toString();
6034
+ } catch {
6035
+ return false;
6036
+ }
6037
+ }
6038
+ if (typeof a === "function" || typeof b === "function") {
6032
6039
  return false;
6033
6040
  }
6041
+ if (a instanceof Date && b instanceof Date) {
6042
+ return a.getTime() === b.getTime();
6043
+ }
6044
+ if (a instanceof RegExp && b instanceof RegExp) {
6045
+ return String(a) === String(b);
6046
+ }
6047
+ if (Array.isArray(a) && Array.isArray(b)) {
6048
+ if (a.length !== b.length) {
6049
+ return false;
6050
+ }
6051
+ for (let i = 0; i < a.length; i++) {
6052
+ if (!deepEqual(a[i], b[i])) {
6053
+ return false;
6054
+ }
6055
+ }
6056
+ return true;
6057
+ }
6058
+ if (a && b && typeof a === "object" && typeof b === "object") {
6059
+ const aKeys = Object.keys(a);
6060
+ const bKeys = Object.keys(b);
6061
+ if (aKeys.length !== bKeys.length) {
6062
+ return false;
6063
+ }
6064
+ for (let i = 0; i < aKeys.length; i++) {
6065
+ const key = aKeys[i];
6066
+ if (!Object.hasOwn(b, key)) {
6067
+ return false;
6068
+ }
6069
+ if (!deepEqual(a[key], b[key])) {
6070
+ return false;
6071
+ }
6072
+ }
6073
+ return true;
6074
+ }
6075
+ return false;
6034
6076
  }
6035
6077
  function getRootMap(ydoc) {
6036
6078
  return ydoc.getMap("root");
@@ -24,14 +24,12 @@ function getParentPathsFromTuples(tuples = []) {
24
24
  "attr",
25
25
  "state",
26
26
  "scope",
27
- "props",
28
27
  "define",
29
28
  "on",
30
29
  "extend",
31
30
  "extends",
32
31
  "childExtend",
33
32
  "childExtends",
34
- "childProps",
35
33
  "children",
36
34
  "component",
37
35
  "context",
@@ -4,8 +4,7 @@ import { RootStateManager } from "../state/RootStateManager.js";
4
4
  import { rootBus } from "../state/rootEventBus.js";
5
5
  import { validateParams } from "../utils/validation.js";
6
6
  import { deepStringifyFunctions } from "@domql/utils";
7
- import { diffJson } from "../utils/jsonDiff.js";
8
- import { computeOrdersForTuples } from "../utils/ordering.js";
7
+ import { preprocessChanges } from "../utils/changePreprocessor.js";
9
8
  class CollabService extends BaseService {
10
9
  constructor(config) {
11
10
  super(config);
@@ -142,8 +141,8 @@ class CollabService extends BaseService {
142
141
  console.log(
143
142
  `[CollabService] Flushing ${this._pendingOps.length} offline operation batch(es)`
144
143
  );
145
- this._pendingOps.forEach(({ changes, orders }) => {
146
- this.socket.emit("ops", { changes, orders, ts: Date.now() });
144
+ this._pendingOps.forEach(({ changes, granularChanges, orders }) => {
145
+ this.socket.emit("ops", { changes, granularChanges, orders, ts: Date.now() });
147
146
  });
148
147
  this._pendingOps.length = 0;
149
148
  }
@@ -185,94 +184,24 @@ class CollabService extends BaseService {
185
184
  }
186
185
  /* ---------- data helpers ---------- */
187
186
  updateData(tuples, options = {}) {
188
- var _a, _b;
187
+ var _a, _b, _c;
189
188
  this._ensureStateManager();
190
189
  const { isUndo = false, isRedo = false } = options;
191
190
  if (!isUndo && !isRedo && !this._isUndoRedo) {
192
191
  this._trackForUndo(tuples, options);
193
192
  }
194
- const processedTuples = (() => {
195
- var _a2;
196
- try {
197
- const root = (_a2 = this._stateManager) == null ? void 0 : _a2.root;
198
- const isPlainObject = (o) => o && typeof o === "object" && !Array.isArray(o);
199
- const getByPath = (state2, path) => {
200
- if (!state2 || typeof state2.getByPath !== "function") {
201
- return null;
202
- }
203
- try {
204
- return state2.getByPath(path);
205
- } catch {
206
- return null;
207
- }
208
- };
209
- const expandTuple = (t) => {
210
- const [action, path, value] = t || [];
211
- const isSchemaPath = Array.isArray(path) && path[0] === "schema";
212
- if (action === "delete" || isSchemaPath) {
213
- return [t];
214
- }
215
- const canConsiderExpansion = action === "update" && Array.isArray(path) && (path.length === 1 || path.length === 2) && isPlainObject(value);
216
- if (!canConsiderExpansion) {
217
- return [t];
218
- }
219
- const prev = getByPath(root, path) || {};
220
- const next = value || {};
221
- if (!isPlainObject(prev) || !isPlainObject(next)) {
222
- return [t];
223
- }
224
- const ops = diffJson(prev, next, []);
225
- if (!ops.length) {
226
- return [];
227
- }
228
- const arr = [];
229
- for (let j = 0; j < ops.length; j++) {
230
- const op = ops[j];
231
- const fullPath = [...path, ...op.path];
232
- const last = fullPath[fullPath.length - 1];
233
- if (op.action === "set") {
234
- arr.push(["update", fullPath, op.value]);
235
- } else if (op.action === "del") {
236
- if (last !== "__order") {
237
- arr.push(["delete", fullPath]);
238
- }
239
- }
240
- }
241
- return arr;
242
- };
243
- const minimizeTuples = (inputTuples) => {
244
- const out = [];
245
- for (let i = 0; i < inputTuples.length; i++) {
246
- const expanded = expandTuple(inputTuples[i]);
247
- for (let k = 0; k < expanded.length; k++) {
248
- const tuple = expanded[k];
249
- const isDelete = Array.isArray(tuple) && tuple[0] === "delete";
250
- const isOrderKey = isDelete && Array.isArray(tuple[1]) && tuple[1][tuple[1].length - 1] === "__order";
251
- if (!isOrderKey) {
252
- out.push(tuple);
253
- }
254
- }
255
- }
256
- console.log(`Minimized tuples`, out);
257
- return out;
258
- };
259
- console.log(`Processing tuples`, tuples);
260
- return minimizeTuples(tuples);
261
- } catch (err) {
262
- console.warn(
263
- "[CollabService] Minimal diff expansion failed \u2013 using original tuples",
264
- err
265
- );
266
- return tuples;
267
- }
268
- })();
193
+ const root = (_a = this._stateManager) == null ? void 0 : _a.root;
194
+ const { granularChanges: processedTuples, orders } = preprocessChanges(
195
+ root,
196
+ tuples,
197
+ options
198
+ );
269
199
  if (options.append && options.append.length) {
270
200
  processedTuples.push(...options.append);
271
201
  }
272
202
  this._stateManager.applyChanges(tuples, { ...options });
273
- const state = (_a = this._stateManager) == null ? void 0 : _a.root;
203
+ const state = (_b = this._stateManager) == null ? void 0 : _b.root;
274
204
  const el = state == null ? void 0 : state.__element;
275
- const orders = computeOrdersForTuples(state, processedTuples);
276
205
  const stringifiedGranularTuples = (el == null ? void 0 : el.call) ? el.call(
277
206
  "deepStringifyFunctions",
278
207
  processedTuples,
@@ -285,16 +214,18 @@ class CollabService extends BaseService {
285
214
  "deepStringifyFunctions",
286
215
  tuples,
287
216
  Array.isArray(tuples) ? [] : {}
288
- ) : deepStringifyFunctions(
289
- tuples,
290
- Array.isArray(tuples) ? [] : {}
291
- );
217
+ ) : deepStringifyFunctions(tuples, Array.isArray(tuples) ? [] : {});
292
218
  if (!this.isConnected()) {
293
219
  console.warn("[CollabService] Not connected, queuing real-time update");
294
- this._pendingOps.push({ changes: stringifiedTuples, granularChanges: stringifiedGranularTuples, orders, options });
220
+ this._pendingOps.push({
221
+ changes: stringifiedTuples,
222
+ granularChanges: stringifiedGranularTuples,
223
+ orders,
224
+ options
225
+ });
295
226
  return;
296
227
  }
297
- if ((_b = this.socket) == null ? void 0 : _b.connected) {
228
+ if ((_c = this.socket) == null ? void 0 : _c.connected) {
298
229
  console.log("[CollabService] Sending operations to the backend", {
299
230
  changes: stringifiedTuples,
300
231
  granularChanges: stringifiedGranularTuples,
@@ -1,5 +1,7 @@
1
1
  import { BaseService } from "./BaseService.js";
2
2
  import { computeOrdersForTuples } from "../utils/ordering.js";
3
+ import { preprocessChanges } from "../utils/changePreprocessor.js";
4
+ import { deepStringifyFunctions } from "@domql/utils";
3
5
  class ProjectService extends BaseService {
4
6
  // ==================== PROJECT METHODS ====================
5
7
  async createProject(projectData) {
@@ -532,12 +534,15 @@ class ProjectService extends BaseService {
532
534
  }
533
535
  const { message, branch = "main", type = "patch" } = options;
534
536
  const state = this._context && this._context.state;
535
- const derivedOrders = options.orders || (state ? computeOrdersForTuples(state, changes) : []);
537
+ const { granularChanges, orders: preprocessorOrders } = preprocessChanges(state, changes, options);
538
+ const derivedOrders = options.orders || (preprocessorOrders && preprocessorOrders.length ? preprocessorOrders : state ? computeOrdersForTuples(state, granularChanges) : []);
539
+ const stringify = (val) => deepStringifyFunctions(val, Array.isArray(val) ? [] : {});
536
540
  try {
537
541
  const response = await this._request(`/projects/${projectId}/changes`, {
538
542
  method: "POST",
539
543
  body: JSON.stringify({
540
- changes,
544
+ changes: stringify(changes),
545
+ granularChanges: stringify(granularChanges),
541
546
  message,
542
547
  branch,
543
548
  type,