@symbo.ls/sdk 2.32.30 → 2.33.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.
@@ -27,6 +27,31 @@ var import_rootEventBus = require("../state/rootEventBus.js");
27
27
  var import_validation = require("../utils/validation.js");
28
28
  var import_utils = require("@domql/utils");
29
29
  var import_changePreprocessor = require("../utils/changePreprocessor.js");
30
+ const FUNCTION_META_KEYS = ["node", "__ref", "__element", "parent", "parse"];
31
+ function stringifyFunctionsForTransport(value, seen = /* @__PURE__ */ new WeakMap()) {
32
+ if (value === null || typeof value !== "object") {
33
+ return typeof value === "function" ? value.toString() : value;
34
+ }
35
+ if (seen.has(value)) {
36
+ return seen.get(value);
37
+ }
38
+ const clone = Array.isArray(value) ? [] : {};
39
+ seen.set(value, clone);
40
+ if (Array.isArray(value)) {
41
+ for (let i = 0; i < value.length; i++) {
42
+ clone[i] = stringifyFunctionsForTransport(value[i], seen);
43
+ }
44
+ return clone;
45
+ }
46
+ const keys = Object.keys(value);
47
+ for (let i = 0; i < keys.length; i++) {
48
+ const key = keys[i];
49
+ if (!FUNCTION_META_KEYS.includes(key)) {
50
+ clone[key] = stringifyFunctionsForTransport(value[key], seen);
51
+ }
52
+ }
53
+ return clone;
54
+ }
30
55
  class CollabService extends import_BaseService.BaseService {
31
56
  constructor(config) {
32
57
  super(config);
@@ -335,7 +360,7 @@ class CollabService extends import_BaseService.BaseService {
335
360
  }
336
361
  /* ---------- data helpers ---------- */
337
362
  updateData(tuples, options = {}) {
338
- var _a, _b, _c;
363
+ var _a, _b;
339
364
  this._ensureStateManager();
340
365
  const { isUndo = false, isRedo = false } = options;
341
366
  if (!isUndo && !isRedo && !this._isUndoRedo) {
@@ -351,21 +376,10 @@ class CollabService extends import_BaseService.BaseService {
351
376
  processedTuples.push(...options.append);
352
377
  }
353
378
  this._stateManager.applyChanges(tuples, { ...options });
354
- const state = (_b = this._stateManager) == null ? void 0 : _b.root;
355
- const el = state == null ? void 0 : state.__element;
356
- const stringifiedGranularTuples = (el == null ? void 0 : el.call) ? el.call(
357
- "deepStringifyFunctions",
358
- processedTuples,
359
- Array.isArray(processedTuples) ? [] : {}
360
- ) : (0, import_utils.deepStringifyFunctions)(
361
- processedTuples,
362
- Array.isArray(processedTuples) ? [] : {}
379
+ const stringifiedGranularTuples = stringifyFunctionsForTransport(
380
+ processedTuples
363
381
  );
364
- const stringifiedTuples = (el == null ? void 0 : el.call) ? el.call(
365
- "deepStringifyFunctions",
366
- tuples,
367
- Array.isArray(tuples) ? [] : {}
368
- ) : (0, import_utils.deepStringifyFunctions)(tuples, Array.isArray(tuples) ? [] : {});
382
+ const stringifiedTuples = stringifyFunctionsForTransport(tuples);
369
383
  const { message } = options;
370
384
  if (!this.isConnected()) {
371
385
  console.warn("[CollabService] Not connected, queuing real-time update");
@@ -377,7 +391,7 @@ class CollabService extends import_BaseService.BaseService {
377
391
  });
378
392
  return;
379
393
  }
380
- if ((_c = this.socket) == null ? void 0 : _c.connected) {
394
+ if ((_b = this.socket) == null ? void 0 : _b.connected) {
381
395
  const ts = Date.now();
382
396
  console.log("[CollabService] Sending operations to the backend", {
383
397
  changes: stringifiedTuples,
package/dist/esm/index.js CHANGED
@@ -43066,6 +43066,31 @@ function preprocessChanges(root, tuples = [], options = {}) {
43066
43066
  }
43067
43067
 
43068
43068
  // src/services/CollabService.js
43069
+ var FUNCTION_META_KEYS = ["node", "__ref", "__element", "parent", "parse"];
43070
+ function stringifyFunctionsForTransport(value2, seen = /* @__PURE__ */ new WeakMap()) {
43071
+ if (value2 === null || typeof value2 !== "object") {
43072
+ return typeof value2 === "function" ? value2.toString() : value2;
43073
+ }
43074
+ if (seen.has(value2)) {
43075
+ return seen.get(value2);
43076
+ }
43077
+ const clone = Array.isArray(value2) ? [] : {};
43078
+ seen.set(value2, clone);
43079
+ if (Array.isArray(value2)) {
43080
+ for (let i3 = 0; i3 < value2.length; i3++) {
43081
+ clone[i3] = stringifyFunctionsForTransport(value2[i3], seen);
43082
+ }
43083
+ return clone;
43084
+ }
43085
+ const keys2 = Object.keys(value2);
43086
+ for (let i3 = 0; i3 < keys2.length; i3++) {
43087
+ const key = keys2[i3];
43088
+ if (!FUNCTION_META_KEYS.includes(key)) {
43089
+ clone[key] = stringifyFunctionsForTransport(value2[key], seen);
43090
+ }
43091
+ }
43092
+ return clone;
43093
+ }
43069
43094
  var CollabService = class extends BaseService {
43070
43095
  constructor(config) {
43071
43096
  super(config);
@@ -43374,7 +43399,7 @@ var CollabService = class extends BaseService {
43374
43399
  }
43375
43400
  /* ---------- data helpers ---------- */
43376
43401
  updateData(tuples, options = {}) {
43377
- var _a2, _b, _c;
43402
+ var _a2, _b;
43378
43403
  this._ensureStateManager();
43379
43404
  const { isUndo = false, isRedo = false } = options;
43380
43405
  if (!isUndo && !isRedo && !this._isUndoRedo) {
@@ -43390,21 +43415,10 @@ var CollabService = class extends BaseService {
43390
43415
  processedTuples.push(...options.append);
43391
43416
  }
43392
43417
  this._stateManager.applyChanges(tuples, { ...options });
43393
- const state = (_b = this._stateManager) == null ? void 0 : _b.root;
43394
- const el = state == null ? void 0 : state.__element;
43395
- const stringifiedGranularTuples = (el == null ? void 0 : el.call) ? el.call(
43396
- "deepStringifyFunctions",
43397
- processedTuples,
43398
- Array.isArray(processedTuples) ? [] : {}
43399
- ) : deepStringifyFunctions(
43400
- processedTuples,
43401
- Array.isArray(processedTuples) ? [] : {}
43418
+ const stringifiedGranularTuples = stringifyFunctionsForTransport(
43419
+ processedTuples
43402
43420
  );
43403
- const stringifiedTuples = (el == null ? void 0 : el.call) ? el.call(
43404
- "deepStringifyFunctions",
43405
- tuples,
43406
- Array.isArray(tuples) ? [] : {}
43407
- ) : deepStringifyFunctions(tuples, Array.isArray(tuples) ? [] : {});
43421
+ const stringifiedTuples = stringifyFunctionsForTransport(tuples);
43408
43422
  const { message } = options;
43409
43423
  if (!this.isConnected()) {
43410
43424
  console.warn("[CollabService] Not connected, queuing real-time update");
@@ -43416,7 +43430,7 @@ var CollabService = class extends BaseService {
43416
43430
  });
43417
43431
  return;
43418
43432
  }
43419
- if ((_c = this.socket) == null ? void 0 : _c.connected) {
43433
+ if ((_b = this.socket) == null ? void 0 : _b.connected) {
43420
43434
  const ts = Date.now();
43421
43435
  console.log("[CollabService] Sending operations to the backend", {
43422
43436
  changes: stringifiedTuples,
@@ -25141,6 +25141,31 @@ function preprocessChanges(root, tuples = [], options = {}) {
25141
25141
  }
25142
25142
 
25143
25143
  // src/services/CollabService.js
25144
+ var FUNCTION_META_KEYS = ["node", "__ref", "__element", "parent", "parse"];
25145
+ function stringifyFunctionsForTransport(value2, seen = /* @__PURE__ */ new WeakMap()) {
25146
+ if (value2 === null || typeof value2 !== "object") {
25147
+ return typeof value2 === "function" ? value2.toString() : value2;
25148
+ }
25149
+ if (seen.has(value2)) {
25150
+ return seen.get(value2);
25151
+ }
25152
+ const clone = Array.isArray(value2) ? [] : {};
25153
+ seen.set(value2, clone);
25154
+ if (Array.isArray(value2)) {
25155
+ for (let i = 0; i < value2.length; i++) {
25156
+ clone[i] = stringifyFunctionsForTransport(value2[i], seen);
25157
+ }
25158
+ return clone;
25159
+ }
25160
+ const keys2 = Object.keys(value2);
25161
+ for (let i = 0; i < keys2.length; i++) {
25162
+ const key = keys2[i];
25163
+ if (!FUNCTION_META_KEYS.includes(key)) {
25164
+ clone[key] = stringifyFunctionsForTransport(value2[key], seen);
25165
+ }
25166
+ }
25167
+ return clone;
25168
+ }
25144
25169
  var CollabService = class extends BaseService {
25145
25170
  constructor(config) {
25146
25171
  super(config);
@@ -25449,7 +25474,7 @@ var CollabService = class extends BaseService {
25449
25474
  }
25450
25475
  /* ---------- data helpers ---------- */
25451
25476
  updateData(tuples, options = {}) {
25452
- var _a, _b, _c;
25477
+ var _a, _b;
25453
25478
  this._ensureStateManager();
25454
25479
  const { isUndo = false, isRedo = false } = options;
25455
25480
  if (!isUndo && !isRedo && !this._isUndoRedo) {
@@ -25465,21 +25490,10 @@ var CollabService = class extends BaseService {
25465
25490
  processedTuples.push(...options.append);
25466
25491
  }
25467
25492
  this._stateManager.applyChanges(tuples, { ...options });
25468
- const state = (_b = this._stateManager) == null ? void 0 : _b.root;
25469
- const el = state == null ? void 0 : state.__element;
25470
- const stringifiedGranularTuples = (el == null ? void 0 : el.call) ? el.call(
25471
- "deepStringifyFunctions",
25472
- processedTuples,
25473
- Array.isArray(processedTuples) ? [] : {}
25474
- ) : deepStringifyFunctions(
25475
- processedTuples,
25476
- Array.isArray(processedTuples) ? [] : {}
25493
+ const stringifiedGranularTuples = stringifyFunctionsForTransport(
25494
+ processedTuples
25477
25495
  );
25478
- const stringifiedTuples = (el == null ? void 0 : el.call) ? el.call(
25479
- "deepStringifyFunctions",
25480
- tuples,
25481
- Array.isArray(tuples) ? [] : {}
25482
- ) : deepStringifyFunctions(tuples, Array.isArray(tuples) ? [] : {});
25496
+ const stringifiedTuples = stringifyFunctionsForTransport(tuples);
25483
25497
  const { message } = options;
25484
25498
  if (!this.isConnected()) {
25485
25499
  console.warn("[CollabService] Not connected, queuing real-time update");
@@ -25491,7 +25505,7 @@ var CollabService = class extends BaseService {
25491
25505
  });
25492
25506
  return;
25493
25507
  }
25494
- if ((_c = this.socket) == null ? void 0 : _c.connected) {
25508
+ if ((_b = this.socket) == null ? void 0 : _b.connected) {
25495
25509
  const ts = Date.now();
25496
25510
  console.log("[CollabService] Sending operations to the backend", {
25497
25511
  changes: stringifiedTuples,
@@ -43066,6 +43066,31 @@ function preprocessChanges(root, tuples = [], options = {}) {
43066
43066
  }
43067
43067
 
43068
43068
  // src/services/CollabService.js
43069
+ var FUNCTION_META_KEYS = ["node", "__ref", "__element", "parent", "parse"];
43070
+ function stringifyFunctionsForTransport(value2, seen = /* @__PURE__ */ new WeakMap()) {
43071
+ if (value2 === null || typeof value2 !== "object") {
43072
+ return typeof value2 === "function" ? value2.toString() : value2;
43073
+ }
43074
+ if (seen.has(value2)) {
43075
+ return seen.get(value2);
43076
+ }
43077
+ const clone = Array.isArray(value2) ? [] : {};
43078
+ seen.set(value2, clone);
43079
+ if (Array.isArray(value2)) {
43080
+ for (let i3 = 0; i3 < value2.length; i3++) {
43081
+ clone[i3] = stringifyFunctionsForTransport(value2[i3], seen);
43082
+ }
43083
+ return clone;
43084
+ }
43085
+ const keys2 = Object.keys(value2);
43086
+ for (let i3 = 0; i3 < keys2.length; i3++) {
43087
+ const key = keys2[i3];
43088
+ if (!FUNCTION_META_KEYS.includes(key)) {
43089
+ clone[key] = stringifyFunctionsForTransport(value2[key], seen);
43090
+ }
43091
+ }
43092
+ return clone;
43093
+ }
43069
43094
  var CollabService = class extends BaseService {
43070
43095
  constructor(config) {
43071
43096
  super(config);
@@ -43374,7 +43399,7 @@ var CollabService = class extends BaseService {
43374
43399
  }
43375
43400
  /* ---------- data helpers ---------- */
43376
43401
  updateData(tuples, options = {}) {
43377
- var _a2, _b, _c;
43402
+ var _a2, _b;
43378
43403
  this._ensureStateManager();
43379
43404
  const { isUndo = false, isRedo = false } = options;
43380
43405
  if (!isUndo && !isRedo && !this._isUndoRedo) {
@@ -43390,21 +43415,10 @@ var CollabService = class extends BaseService {
43390
43415
  processedTuples.push(...options.append);
43391
43416
  }
43392
43417
  this._stateManager.applyChanges(tuples, { ...options });
43393
- const state = (_b = this._stateManager) == null ? void 0 : _b.root;
43394
- const el = state == null ? void 0 : state.__element;
43395
- const stringifiedGranularTuples = (el == null ? void 0 : el.call) ? el.call(
43396
- "deepStringifyFunctions",
43397
- processedTuples,
43398
- Array.isArray(processedTuples) ? [] : {}
43399
- ) : deepStringifyFunctions(
43400
- processedTuples,
43401
- Array.isArray(processedTuples) ? [] : {}
43418
+ const stringifiedGranularTuples = stringifyFunctionsForTransport(
43419
+ processedTuples
43402
43420
  );
43403
- const stringifiedTuples = (el == null ? void 0 : el.call) ? el.call(
43404
- "deepStringifyFunctions",
43405
- tuples,
43406
- Array.isArray(tuples) ? [] : {}
43407
- ) : deepStringifyFunctions(tuples, Array.isArray(tuples) ? [] : {});
43421
+ const stringifiedTuples = stringifyFunctionsForTransport(tuples);
43408
43422
  const { message } = options;
43409
43423
  if (!this.isConnected()) {
43410
43424
  console.warn("[CollabService] Not connected, queuing real-time update");
@@ -43416,7 +43430,7 @@ var CollabService = class extends BaseService {
43416
43430
  });
43417
43431
  return;
43418
43432
  }
43419
- if ((_c = this.socket) == null ? void 0 : _c.connected) {
43433
+ if ((_b = this.socket) == null ? void 0 : _b.connected) {
43420
43434
  const ts = Date.now();
43421
43435
  console.log("[CollabService] Sending operations to the backend", {
43422
43436
  changes: stringifiedTuples,
@@ -5,6 +5,31 @@ import { rootBus } from "../state/rootEventBus.js";
5
5
  import { validateParams } from "../utils/validation.js";
6
6
  import { deepStringifyFunctions } from "@domql/utils";
7
7
  import { preprocessChanges } from "../utils/changePreprocessor.js";
8
+ const FUNCTION_META_KEYS = ["node", "__ref", "__element", "parent", "parse"];
9
+ function stringifyFunctionsForTransport(value, seen = /* @__PURE__ */ new WeakMap()) {
10
+ if (value === null || typeof value !== "object") {
11
+ return typeof value === "function" ? value.toString() : value;
12
+ }
13
+ if (seen.has(value)) {
14
+ return seen.get(value);
15
+ }
16
+ const clone = Array.isArray(value) ? [] : {};
17
+ seen.set(value, clone);
18
+ if (Array.isArray(value)) {
19
+ for (let i = 0; i < value.length; i++) {
20
+ clone[i] = stringifyFunctionsForTransport(value[i], seen);
21
+ }
22
+ return clone;
23
+ }
24
+ const keys = Object.keys(value);
25
+ for (let i = 0; i < keys.length; i++) {
26
+ const key = keys[i];
27
+ if (!FUNCTION_META_KEYS.includes(key)) {
28
+ clone[key] = stringifyFunctionsForTransport(value[key], seen);
29
+ }
30
+ }
31
+ return clone;
32
+ }
8
33
  class CollabService extends BaseService {
9
34
  constructor(config) {
10
35
  super(config);
@@ -313,7 +338,7 @@ class CollabService extends BaseService {
313
338
  }
314
339
  /* ---------- data helpers ---------- */
315
340
  updateData(tuples, options = {}) {
316
- var _a, _b, _c;
341
+ var _a, _b;
317
342
  this._ensureStateManager();
318
343
  const { isUndo = false, isRedo = false } = options;
319
344
  if (!isUndo && !isRedo && !this._isUndoRedo) {
@@ -329,21 +354,10 @@ class CollabService extends BaseService {
329
354
  processedTuples.push(...options.append);
330
355
  }
331
356
  this._stateManager.applyChanges(tuples, { ...options });
332
- const state = (_b = this._stateManager) == null ? void 0 : _b.root;
333
- const el = state == null ? void 0 : state.__element;
334
- const stringifiedGranularTuples = (el == null ? void 0 : el.call) ? el.call(
335
- "deepStringifyFunctions",
336
- processedTuples,
337
- Array.isArray(processedTuples) ? [] : {}
338
- ) : deepStringifyFunctions(
339
- processedTuples,
340
- Array.isArray(processedTuples) ? [] : {}
357
+ const stringifiedGranularTuples = stringifyFunctionsForTransport(
358
+ processedTuples
341
359
  );
342
- const stringifiedTuples = (el == null ? void 0 : el.call) ? el.call(
343
- "deepStringifyFunctions",
344
- tuples,
345
- Array.isArray(tuples) ? [] : {}
346
- ) : deepStringifyFunctions(tuples, Array.isArray(tuples) ? [] : {});
360
+ const stringifiedTuples = stringifyFunctionsForTransport(tuples);
347
361
  const { message } = options;
348
362
  if (!this.isConnected()) {
349
363
  console.warn("[CollabService] Not connected, queuing real-time update");
@@ -355,7 +369,7 @@ class CollabService extends BaseService {
355
369
  });
356
370
  return;
357
371
  }
358
- if ((_c = this.socket) == null ? void 0 : _c.connected) {
372
+ if ((_b = this.socket) == null ? void 0 : _b.connected) {
359
373
  const ts = Date.now();
360
374
  console.log("[CollabService] Sending operations to the backend", {
361
375
  changes: stringifiedTuples,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symbo.ls/sdk",
3
- "version": "2.32.30",
3
+ "version": "2.33.1",
4
4
  "type": "module",
5
5
  "main": "dist/esm/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -46,12 +46,12 @@
46
46
  "test:user": "cross-env NODE_ENV=$NODE_ENV npx tape integration-tests/index.js integration-tests/user/*.test.js | tap-spec"
47
47
  },
48
48
  "dependencies": {
49
- "@domql/element": "^2.32.30",
50
- "@domql/utils": "^2.32.30",
49
+ "@domql/element": "^2.33.1",
50
+ "@domql/utils": "^2.33.1",
51
51
  "@grafana/faro-web-sdk": "^1.19.0",
52
52
  "@grafana/faro-web-tracing": "^1.19.0",
53
- "@symbo.ls/router": "^2.32.30",
54
- "@symbo.ls/socket": "^2.32.30",
53
+ "@symbo.ls/router": "^2.33.1",
54
+ "@symbo.ls/socket": "^2.33.1",
55
55
  "acorn": "^8.14.0",
56
56
  "acorn-walk": "^8.3.4",
57
57
  "dexie": "^4.0.11",
@@ -73,5 +73,5 @@
73
73
  "tap-spec": "^5.0.0",
74
74
  "tape": "^5.9.0"
75
75
  },
76
- "gitHead": "1f4b829d823a7b42486c0e8f7dca5660bf466c19"
76
+ "gitHead": "29bf734428f60467fe608adeb00c3caad30398fa"
77
77
  }
@@ -6,6 +6,41 @@ import { validateParams } from '../utils/validation.js'
6
6
  import { deepStringifyFunctions } from '@domql/utils'
7
7
  import { preprocessChanges } from '../utils/changePreprocessor.js'
8
8
 
9
+ // Helper: clone a value while converting all functions to strings. This is
10
+ // tailored for collab payloads (tuples / granularChanges) and is more robust
11
+ // for nested array shapes than the generic DOMQL helper.
12
+ const FUNCTION_META_KEYS = ['node', '__ref', '__element', 'parent', 'parse']
13
+
14
+ function stringifyFunctionsForTransport (value, seen = new WeakMap()) {
15
+ if (value === null || typeof value !== 'object') {
16
+ return typeof value === 'function' ? value.toString() : value
17
+ }
18
+
19
+ if (seen.has(value)) {
20
+ return seen.get(value)
21
+ }
22
+
23
+ const clone = Array.isArray(value) ? [] : {}
24
+ seen.set(value, clone)
25
+
26
+ if (Array.isArray(value)) {
27
+ for (let i = 0; i < value.length; i++) {
28
+ clone[i] = stringifyFunctionsForTransport(value[i], seen)
29
+ }
30
+ return clone
31
+ }
32
+
33
+ const keys = Object.keys(value)
34
+ for (let i = 0; i < keys.length; i++) {
35
+ const key = keys[i]
36
+ if (!FUNCTION_META_KEYS.includes(key)) {
37
+ clone[key] = stringifyFunctionsForTransport(value[key], seen)
38
+ }
39
+ }
40
+
41
+ return clone
42
+ }
43
+
9
44
  export class CollabService extends BaseService {
10
45
  constructor(config) {
11
46
  super(config)
@@ -410,29 +445,13 @@ export class CollabService extends BaseService {
410
445
  // Apply changes to local state tree immediately.
411
446
  this._stateManager.applyChanges(tuples, { ...options })
412
447
 
413
- const state = this._stateManager?.root
414
- const el = state?.__element
415
-
416
- // orders already derived by preprocessor
417
-
418
- const stringifiedGranularTuples = el?.call
419
- ? el.call(
420
- 'deepStringifyFunctions',
421
- processedTuples,
422
- Array.isArray(processedTuples) ? [] : {}
423
- )
424
- : deepStringifyFunctions(
425
- processedTuples,
426
- Array.isArray(processedTuples) ? [] : {}
427
- )
448
+ // Use a dedicated helper that correctly handles nested array structures
449
+ // such as granular tuples while also avoiding DOM / state metadata keys.
450
+ const stringifiedGranularTuples = stringifyFunctionsForTransport(
451
+ processedTuples
452
+ )
428
453
 
429
- const stringifiedTuples = el?.call
430
- ? el.call(
431
- 'deepStringifyFunctions',
432
- tuples,
433
- Array.isArray(tuples) ? [] : {}
434
- )
435
- : deepStringifyFunctions(tuples, Array.isArray(tuples) ? [] : {})
454
+ const stringifiedTuples = stringifyFunctionsForTransport(tuples)
436
455
 
437
456
  const { message } = options
438
457