@symbo.ls/sdk 2.32.2 → 2.32.5

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 (90) hide show
  1. package/dist/cjs/config/environment.js +43 -8
  2. package/dist/cjs/index.js +12 -4
  3. package/dist/cjs/services/AdminService.js +4 -4
  4. package/dist/cjs/services/AuthService.js +36 -149
  5. package/dist/cjs/services/BaseService.js +5 -18
  6. package/dist/cjs/services/BranchService.js +10 -10
  7. package/dist/cjs/services/CollabService.js +94 -61
  8. package/dist/cjs/services/CoreService.js +19 -19
  9. package/dist/cjs/services/DnsService.js +4 -4
  10. package/dist/cjs/services/FileService.js +2 -2
  11. package/dist/cjs/services/PaymentService.js +2 -2
  12. package/dist/cjs/services/PlanService.js +12 -12
  13. package/dist/cjs/services/ProjectService.js +45 -35
  14. package/dist/cjs/services/PullRequestService.js +7 -7
  15. package/dist/cjs/services/ScreenshotService.js +304 -0
  16. package/dist/cjs/services/SubscriptionService.js +14 -14
  17. package/dist/cjs/services/index.js +4 -0
  18. package/dist/cjs/utils/TokenManager.js +16 -5
  19. package/dist/cjs/utils/changePreprocessor.js +134 -0
  20. package/dist/cjs/utils/jsonDiff.js +46 -4
  21. package/dist/cjs/utils/ordering.js +274 -0
  22. package/dist/cjs/utils/services.js +14 -1
  23. package/dist/esm/config/environment.js +43 -8
  24. package/dist/esm/index.js +1099 -417
  25. package/dist/esm/services/AdminService.js +68 -35
  26. package/dist/esm/services/AuthService.js +100 -168
  27. package/dist/esm/services/BaseService.js +64 -31
  28. package/dist/esm/services/BranchService.js +74 -41
  29. package/dist/esm/services/CollabService.js +570 -97
  30. package/dist/esm/services/CoreService.js +83 -50
  31. package/dist/esm/services/DnsService.js +68 -35
  32. package/dist/esm/services/FileService.js +66 -33
  33. package/dist/esm/services/PaymentService.js +66 -33
  34. package/dist/esm/services/PlanService.js +76 -43
  35. package/dist/esm/services/ProjectService.js +547 -66
  36. package/dist/esm/services/PullRequestService.js +71 -38
  37. package/dist/esm/services/ScreenshotService.js +992 -0
  38. package/dist/esm/services/SubscriptionService.js +78 -45
  39. package/dist/esm/services/index.js +1076 -412
  40. package/dist/esm/utils/CollabClient.js +89 -12
  41. package/dist/esm/utils/TokenManager.js +16 -5
  42. package/dist/esm/utils/changePreprocessor.js +442 -0
  43. package/dist/esm/utils/jsonDiff.js +46 -4
  44. package/dist/esm/utils/ordering.js +256 -0
  45. package/dist/esm/utils/services.js +14 -1
  46. package/dist/node/config/environment.js +43 -8
  47. package/dist/node/index.js +14 -5
  48. package/dist/node/services/AdminService.js +4 -4
  49. package/dist/node/services/AuthService.js +36 -139
  50. package/dist/node/services/BaseService.js +5 -18
  51. package/dist/node/services/BranchService.js +10 -10
  52. package/dist/node/services/CollabService.js +95 -62
  53. package/dist/node/services/CoreService.js +19 -19
  54. package/dist/node/services/DnsService.js +4 -4
  55. package/dist/node/services/FileService.js +2 -2
  56. package/dist/node/services/PaymentService.js +2 -2
  57. package/dist/node/services/PlanService.js +12 -12
  58. package/dist/node/services/ProjectService.js +45 -35
  59. package/dist/node/services/PullRequestService.js +7 -7
  60. package/dist/node/services/ScreenshotService.js +285 -0
  61. package/dist/node/services/SubscriptionService.js +14 -14
  62. package/dist/node/services/index.js +4 -0
  63. package/dist/node/utils/TokenManager.js +16 -5
  64. package/dist/node/utils/changePreprocessor.js +115 -0
  65. package/dist/node/utils/jsonDiff.js +46 -4
  66. package/dist/node/utils/ordering.js +255 -0
  67. package/dist/node/utils/services.js +14 -1
  68. package/package.json +7 -6
  69. package/src/config/environment.js +48 -9
  70. package/src/index.js +38 -22
  71. package/src/services/AdminService.js +4 -4
  72. package/src/services/AuthService.js +42 -175
  73. package/src/services/BaseService.js +7 -24
  74. package/src/services/BranchService.js +10 -10
  75. package/src/services/CollabService.js +115 -74
  76. package/src/services/CoreService.js +19 -19
  77. package/src/services/DnsService.js +4 -4
  78. package/src/services/FileService.js +2 -2
  79. package/src/services/PaymentService.js +2 -2
  80. package/src/services/PlanService.js +12 -12
  81. package/src/services/ProjectService.js +50 -35
  82. package/src/services/PullRequestService.js +7 -7
  83. package/src/services/ScreenshotService.js +258 -0
  84. package/src/services/SubscriptionService.js +14 -14
  85. package/src/services/index.js +6 -1
  86. package/src/utils/TokenManager.js +19 -5
  87. package/src/utils/changePreprocessor.js +139 -0
  88. package/src/utils/jsonDiff.js +40 -5
  89. package/src/utils/ordering.js +244 -0
  90. package/src/utils/services.js +15 -1
@@ -14111,18 +14111,28 @@ var CONFIG = {
14111
14111
  // For based api
14112
14112
  basedOrg: "symbols",
14113
14113
  // For based api
14114
- githubClientId: "Ov23liHxyWFBxS8f1gnF",
14114
+ githubClientId: "Ov23liAFrsR0StbAO6PO",
14115
14115
  // For github api
14116
14116
  // Environment-specific feature toggles (override common)
14117
14117
  features: {
14118
14118
  betaFeatures: true
14119
14119
  // Enable beta features in local dev
14120
- }
14120
+ },
14121
+ typesenseCollectionName: "docs",
14122
+ typesenseApiKey: "vZya3L2zpq8L6iI5WWMUZJZABvT63VDb",
14123
+ typesenseHost: "localhost",
14124
+ typesensePort: "8108",
14125
+ typesenseProtocol: "http"
14121
14126
  },
14122
14127
  development: {
14123
14128
  socketUrl: "https://dev.api.symbols.app",
14124
14129
  apiUrl: "https://dev.api.symbols.app",
14125
- githubClientId: "Ov23liHxyWFBxS8f1gnF"
14130
+ githubClientId: "Ov23liHxyWFBxS8f1gnF",
14131
+ typesenseCollectionName: "docs",
14132
+ typesenseApiKey: "awmcVpbWqZi9IUgmvslp1C5LKDU8tMjA",
14133
+ typesenseHost: "tl2qpnwxev4cjm36p-1.a1.typesense.net",
14134
+ typesensePort: "443",
14135
+ typesenseProtocol: "https"
14126
14136
  },
14127
14137
  testing: {
14128
14138
  socketUrl: "https://test.api.symbols.app",
@@ -14130,12 +14140,22 @@ var CONFIG = {
14130
14140
  basedEnv: "testing",
14131
14141
  basedProject: "platform-v2-sm",
14132
14142
  basedOrg: "symbols",
14133
- githubClientId: "Ov23liHxyWFBxS8f1gnF"
14143
+ githubClientId: "Ov23liHxyWFBxS8f1gnF",
14144
+ typesenseCollectionName: "docs",
14145
+ typesenseApiKey: "awmcVpbWqZi9IUgmvslp1C5LKDU8tMjA",
14146
+ typesenseHost: "tl2qpnwxev4cjm36p-1.a1.typesense.net",
14147
+ typesensePort: "443",
14148
+ typesenseProtocol: "https"
14134
14149
  },
14135
14150
  upcoming: {
14136
14151
  socketUrl: "https://upcoming.api.symbols.app",
14137
14152
  apiUrl: "https://upcoming.api.symbols.app",
14138
- githubClientId: "Ov23liWF7NvdZ056RV5J"
14153
+ githubClientId: "Ov23liWF7NvdZ056RV5J",
14154
+ typesenseCollectionName: "docs",
14155
+ typesenseApiKey: "awmcVpbWqZi9IUgmvslp1C5LKDU8tMjA",
14156
+ typesenseHost: "tl2qpnwxev4cjm36p-1.a1.typesense.net",
14157
+ typesensePort: "443",
14158
+ typesenseProtocol: "https"
14139
14159
  },
14140
14160
  staging: {
14141
14161
  socketUrl: "https://staging.api.symbols.app",
@@ -14143,7 +14163,12 @@ var CONFIG = {
14143
14163
  basedEnv: "staging",
14144
14164
  basedProject: "platform-v2-sm",
14145
14165
  basedOrg: "symbols",
14146
- githubClientId: "Ov23ligwZDQVD0VfuWNa"
14166
+ githubClientId: "Ov23ligwZDQVD0VfuWNa",
14167
+ typesenseCollectionName: "docs",
14168
+ typesenseApiKey: "awmcVpbWqZi9IUgmvslp1C5LKDU8tMjA",
14169
+ typesenseHost: "tl2qpnwxev4cjm36p-1.a1.typesense.net",
14170
+ typesensePort: "443",
14171
+ typesenseProtocol: "https"
14147
14172
  },
14148
14173
  production: {
14149
14174
  socketUrl: "https://api.symbols.app",
@@ -14151,7 +14176,12 @@ var CONFIG = {
14151
14176
  basedEnv: "production",
14152
14177
  basedProject: "platform-v2-sm",
14153
14178
  basedOrg: "symbols",
14154
- githubClientId: "Ov23liFAlOEIXtX3dBtR"
14179
+ githubClientId: "Ov23liFAlOEIXtX3dBtR",
14180
+ typesenseCollectionName: "docs",
14181
+ typesenseApiKey: "awmcVpbWqZi9IUgmvslp1C5LKDU8tMjA",
14182
+ typesenseHost: "tl2qpnwxev4cjm36p-1.a1.typesense.net",
14183
+ typesensePort: "443",
14184
+ typesenseProtocol: "https"
14155
14185
  }
14156
14186
  };
14157
14187
  var getEnvironment = () => {
@@ -14173,6 +14203,11 @@ var getConfig = () => {
14173
14203
  basedProject: process.env.SYMBOLS_APP_BASED_PROJECT || envConfig.basedProject,
14174
14204
  basedOrg: process.env.SYMBOLS_APP_BASED_ORG || envConfig.basedOrg,
14175
14205
  githubClientId: process.env.SYMBOLS_APP_GITHUB_CLIENT_ID || envConfig.githubClientId,
14206
+ typesenseCollectionName: process.env.TYPESENSE_COLLECTION_NAME || envConfig.typesenseCollectionName,
14207
+ typesenseApiKey: process.env.TYPESENSE_API_KEY || envConfig.typesenseApiKey,
14208
+ typesenseHost: process.env.TYPESENSE_HOST || envConfig.typesenseHost,
14209
+ typesensePort: process.env.TYPESENSE_PORT || envConfig.typesensePort,
14210
+ typesenseProtocol: process.env.TYPESENSE_PROTOCOL || envConfig.typesenseProtocol,
14176
14211
  isDevelopment: isDevelopment(env),
14177
14212
  isTesting: env === "testing",
14178
14213
  isStaging: env === "staging",
@@ -14192,7 +14227,7 @@ var getConfig = () => {
14192
14227
  );
14193
14228
  }
14194
14229
  if (finalConfig.isDevelopment) {
14195
- console.log(
14230
+ console.warn(
14196
14231
  "environment in SDK:",
14197
14232
  env || process.env.NODE_ENV || process.env.NODE_ENV
14198
14233
  );
@@ -14231,7 +14266,7 @@ var TokenManager = class {
14231
14266
  });
14232
14267
  this.config = {
14233
14268
  storagePrefix: "symbols_",
14234
- storageType: typeof window === "undefined" || process.env.NODE_ENV === "test" ? "memory" : "localStorage",
14269
+ storageType: typeof window === "undefined" || process.env.NODE_ENV === "test" || process.env.NODE_ENV === "testing" ? "memory" : "localStorage",
14235
14270
  // 'localStorage' | 'sessionStorage' | 'memory'
14236
14271
  refreshBuffer: 60 * 1e3,
14237
14272
  // Refresh 1 minute before expiry
@@ -14271,15 +14306,26 @@ var TokenManager = class {
14271
14306
  if (typeof window === "undefined") {
14272
14307
  return this._memoryStorage;
14273
14308
  }
14274
- const hasLocalStorage = typeof window.localStorage !== "undefined";
14275
- const hasSessionStorage = typeof window.sessionStorage !== "undefined";
14309
+ const safeGetStorage = (provider) => {
14310
+ try {
14311
+ const storage = provider();
14312
+ const testKey = `${this.config.storagePrefix}__tm_test__`;
14313
+ storage.setItem(testKey, "1");
14314
+ storage.removeItem(testKey);
14315
+ return storage;
14316
+ } catch {
14317
+ return null;
14318
+ }
14319
+ };
14320
+ const localStorageInstance = safeGetStorage(() => window.localStorage);
14321
+ const sessionStorageInstance = safeGetStorage(() => window.sessionStorage);
14276
14322
  switch (this.config.storageType) {
14277
14323
  case "sessionStorage":
14278
- return hasSessionStorage ? window.sessionStorage : this._memoryStorage;
14324
+ return sessionStorageInstance || this._memoryStorage;
14279
14325
  case "memory":
14280
14326
  return this._memoryStorage;
14281
14327
  default:
14282
- return hasLocalStorage ? window.localStorage : this._memoryStorage;
14328
+ return localStorageInstance || this._memoryStorage;
14283
14329
  }
14284
14330
  }
14285
14331
  /**
@@ -14618,20 +14664,10 @@ var BaseService = class {
14618
14664
  }
14619
14665
  this._tokenManager = getTokenManager({
14620
14666
  apiUrl: this._apiUrl,
14621
- onTokenRefresh: (tokens) => {
14622
- this.updateContext({ authToken: tokens.accessToken });
14623
- },
14624
- onTokenExpired: () => {
14625
- this.updateContext({ authToken: null });
14626
- },
14627
14667
  onTokenError: (error) => {
14628
14668
  console.error("Token management error:", error);
14629
14669
  }
14630
14670
  });
14631
- const { authToken } = this._context;
14632
- if (authToken && !this._tokenManager.hasTokens()) {
14633
- this._tokenManager.setTokens({ access_token: authToken });
14634
- }
14635
14671
  this._setReady();
14636
14672
  } catch (error) {
14637
14673
  this._setError(error);
@@ -14640,7 +14676,9 @@ var BaseService = class {
14640
14676
  }
14641
14677
  // Update context
14642
14678
  updateContext(context) {
14643
- this._context = { ...this._context, ...context };
14679
+ if (context && typeof context === "object") {
14680
+ Object.assign(this._context, context);
14681
+ }
14644
14682
  }
14645
14683
  // Get service status
14646
14684
  getStatus() {
@@ -14695,11 +14733,6 @@ var BaseService = class {
14695
14733
  error
14696
14734
  );
14697
14735
  }
14698
- } else if (this._requiresInit(options.methodName)) {
14699
- const { authToken } = this._context;
14700
- if (authToken) {
14701
- defaultHeaders.Authorization = `Bearer ${authToken}`;
14702
- }
14703
14736
  }
14704
14737
  try {
14705
14738
  const response = await fetch(url2, {
@@ -14717,11 +14750,11 @@ var BaseService = class {
14717
14750
  error = await response.json();
14718
14751
  } catch {
14719
14752
  }
14720
- throw new Error(error.message || error.error || "Request failed");
14753
+ throw new Error(error.message || error.error || "Request failed", { cause: error });
14721
14754
  }
14722
14755
  return response.status === 204 ? null : response.json();
14723
14756
  } catch (error) {
14724
- throw new Error(`Request failed: ${error.message}`);
14757
+ throw new Error(`Request failed: ${error.message}`, { cause: error });
14725
14758
  }
14726
14759
  }
14727
14760
  // Helper method to determine if a method requires initialization
@@ -18137,12 +18170,54 @@ function isPlainObject(o) {
18137
18170
  return o && typeof o === "object" && !Array.isArray(o);
18138
18171
  }
18139
18172
  function deepEqual(a, b) {
18140
- try {
18141
- return JSON.stringify(a) === JSON.stringify(b);
18142
- } catch (err) {
18143
- console.warn("deepEqual error", err);
18173
+ if (Object.is(a, b)) {
18174
+ return true;
18175
+ }
18176
+ if (typeof a === "function" && typeof b === "function") {
18177
+ try {
18178
+ return a.toString() === b.toString();
18179
+ } catch {
18180
+ return false;
18181
+ }
18182
+ }
18183
+ if (typeof a === "function" || typeof b === "function") {
18144
18184
  return false;
18145
18185
  }
18186
+ if (a instanceof Date && b instanceof Date) {
18187
+ return a.getTime() === b.getTime();
18188
+ }
18189
+ if (a instanceof RegExp && b instanceof RegExp) {
18190
+ return String(a) === String(b);
18191
+ }
18192
+ if (Array.isArray(a) && Array.isArray(b)) {
18193
+ if (a.length !== b.length) {
18194
+ return false;
18195
+ }
18196
+ for (let i = 0; i < a.length; i++) {
18197
+ if (!deepEqual(a[i], b[i])) {
18198
+ return false;
18199
+ }
18200
+ }
18201
+ return true;
18202
+ }
18203
+ if (a && b && typeof a === "object" && typeof b === "object") {
18204
+ const aKeys = Object.keys(a);
18205
+ const bKeys = Object.keys(b);
18206
+ if (aKeys.length !== bKeys.length) {
18207
+ return false;
18208
+ }
18209
+ for (let i = 0; i < aKeys.length; i++) {
18210
+ const key = aKeys[i];
18211
+ if (!Object.hasOwn(b, key)) {
18212
+ return false;
18213
+ }
18214
+ if (!deepEqual(a[key], b[key])) {
18215
+ return false;
18216
+ }
18217
+ }
18218
+ return true;
18219
+ }
18220
+ return false;
18146
18221
  }
18147
18222
  function getRootMap(ydoc) {
18148
18223
  return ydoc.getMap("root");
@@ -24521,7 +24596,373 @@ var validateParams = {
24521
24596
  };
24522
24597
 
24523
24598
  // src/services/CollabService.js
24524
- import { deepStringify } from "@domql/utils";
24599
+ import { deepStringifyFunctions } from "@domql/utils";
24600
+
24601
+ // src/utils/ordering.js
24602
+ function isObjectLike(val) {
24603
+ return val && typeof val === "object" && !Array.isArray(val);
24604
+ }
24605
+ function normalizePath(path) {
24606
+ if (Array.isArray(path)) {
24607
+ return path;
24608
+ }
24609
+ if (typeof path === "string") {
24610
+ return [path];
24611
+ }
24612
+ return [];
24613
+ }
24614
+ function getParentPathsFromTuples(tuples = []) {
24615
+ const seen = /* @__PURE__ */ new Set();
24616
+ const parents = [];
24617
+ const META_KEYS = /* @__PURE__ */ new Set([
24618
+ "style",
24619
+ "class",
24620
+ "text",
24621
+ "html",
24622
+ "content",
24623
+ "data",
24624
+ "attr",
24625
+ "state",
24626
+ "scope",
24627
+ "define",
24628
+ "on",
24629
+ "extend",
24630
+ "extends",
24631
+ "childExtend",
24632
+ "childExtends",
24633
+ "children",
24634
+ "component",
24635
+ "context",
24636
+ "tag",
24637
+ "key",
24638
+ "__order",
24639
+ "if"
24640
+ ]);
24641
+ for (let i = 0; i < tuples.length; i++) {
24642
+ const tuple = tuples[i];
24643
+ if (!Array.isArray(tuple) || tuple.length < 2) {
24644
+ continue;
24645
+ }
24646
+ const path = normalizePath(tuple[1]);
24647
+ if (!path.length) {
24648
+ continue;
24649
+ }
24650
+ if (path[0] === "schema") {
24651
+ continue;
24652
+ }
24653
+ const immediateParent = path.slice(0, -1);
24654
+ if (immediateParent.length) {
24655
+ const key = JSON.stringify(immediateParent);
24656
+ if (!seen.has(key)) {
24657
+ seen.add(key);
24658
+ parents.push(immediateParent);
24659
+ }
24660
+ }
24661
+ const last2 = path[path.length - 1];
24662
+ if (META_KEYS.has(last2) && path.length >= 2) {
24663
+ const containerParent = path.slice(0, -2);
24664
+ if (containerParent.length) {
24665
+ const key2 = JSON.stringify(containerParent);
24666
+ if (!seen.has(key2)) {
24667
+ seen.add(key2);
24668
+ parents.push(containerParent);
24669
+ }
24670
+ }
24671
+ }
24672
+ for (let j = 0; j < path.length; j++) {
24673
+ const seg = path[j];
24674
+ if (!META_KEYS.has(seg)) {
24675
+ continue;
24676
+ }
24677
+ const containerParent2 = path.slice(0, j);
24678
+ if (!containerParent2.length) {
24679
+ continue;
24680
+ }
24681
+ const key3 = JSON.stringify(containerParent2);
24682
+ if (!seen.has(key3)) {
24683
+ seen.add(key3);
24684
+ parents.push(containerParent2);
24685
+ }
24686
+ }
24687
+ }
24688
+ return parents;
24689
+ }
24690
+ function computeOrdersFromState(root, parentPaths = []) {
24691
+ if (!root || typeof root.getByPath !== "function") {
24692
+ return [];
24693
+ }
24694
+ const orders = [];
24695
+ const EXCLUDE_KEYS = /* @__PURE__ */ new Set(["__order"]);
24696
+ for (let i = 0; i < parentPaths.length; i++) {
24697
+ const parentPath = parentPaths[i];
24698
+ const obj = (() => {
24699
+ try {
24700
+ return root.getByPath(parentPath);
24701
+ } catch {
24702
+ return null;
24703
+ }
24704
+ })();
24705
+ if (!isObjectLike(obj)) {
24706
+ continue;
24707
+ }
24708
+ const keys2 = Object.keys(obj).filter((k) => !EXCLUDE_KEYS.has(k));
24709
+ orders.push({ path: parentPath, keys: keys2 });
24710
+ }
24711
+ return orders;
24712
+ }
24713
+ function normaliseSchemaCode(code) {
24714
+ if (typeof code !== "string" || !code.length) {
24715
+ return "";
24716
+ }
24717
+ return code.replaceAll("/////n", "\n").replaceAll("/////tilde", "`");
24718
+ }
24719
+ function parseExportedObject(code) {
24720
+ const src = normaliseSchemaCode(code);
24721
+ if (!src) {
24722
+ return null;
24723
+ }
24724
+ const body = src.replace(/^\s*export\s+default\s*/u, "return ");
24725
+ try {
24726
+ return new Function(body)();
24727
+ } catch {
24728
+ return null;
24729
+ }
24730
+ }
24731
+ function extractTopLevelKeysFromCode(code) {
24732
+ const obj = parseExportedObject(code);
24733
+ if (!obj || typeof obj !== "object") {
24734
+ return [];
24735
+ }
24736
+ return Object.keys(obj);
24737
+ }
24738
+ function computeOrdersForTuples(root, tuples = []) {
24739
+ const pendingChildrenByContainer = /* @__PURE__ */ new Map();
24740
+ for (let i = 0; i < tuples.length; i++) {
24741
+ const t = tuples[i];
24742
+ if (!Array.isArray(t)) {
24743
+ continue;
24744
+ }
24745
+ const [action, path] = t;
24746
+ const p = normalizePath(path);
24747
+ if (!Array.isArray(p) || p.length < 3) {
24748
+ continue;
24749
+ }
24750
+ if (p[0] === "schema") {
24751
+ continue;
24752
+ }
24753
+ const [typeName, containerKey, childKey] = p;
24754
+ const containerPath = [typeName, containerKey];
24755
+ const key = JSON.stringify(containerPath);
24756
+ if (!pendingChildrenByContainer.has(key)) {
24757
+ pendingChildrenByContainer.set(key, /* @__PURE__ */ new Set());
24758
+ }
24759
+ if (action === "update" || action === "set") {
24760
+ pendingChildrenByContainer.get(key).add(childKey);
24761
+ }
24762
+ }
24763
+ const preferredOrderMap = /* @__PURE__ */ new Map();
24764
+ for (let i = 0; i < tuples.length; i++) {
24765
+ const t = tuples[i];
24766
+ if (!Array.isArray(t)) {
24767
+ continue;
24768
+ }
24769
+ const [action, path, value2] = t;
24770
+ const p = normalizePath(path);
24771
+ if (action !== "update" || !Array.isArray(p) || p.length < 3) {
24772
+ continue;
24773
+ }
24774
+ if (p[0] !== "schema") {
24775
+ continue;
24776
+ }
24777
+ const [, type, key] = p;
24778
+ const containerPath = [type, key];
24779
+ const uses = value2 && Array.isArray(value2.uses) ? value2.uses : null;
24780
+ const code = value2 && value2.code;
24781
+ const obj = (() => {
24782
+ try {
24783
+ return root && typeof root.getByPath === "function" ? root.getByPath(containerPath) : null;
24784
+ } catch {
24785
+ return null;
24786
+ }
24787
+ })();
24788
+ if (!obj) {
24789
+ continue;
24790
+ }
24791
+ const present = new Set(Object.keys(obj));
24792
+ const EXCLUDE_KEYS = /* @__PURE__ */ new Set(["__order"]);
24793
+ const codeKeys = extractTopLevelKeysFromCode(code);
24794
+ let resolved = [];
24795
+ const pendingKey = JSON.stringify(containerPath);
24796
+ const pendingChildren = pendingChildrenByContainer.get(pendingKey) || /* @__PURE__ */ new Set();
24797
+ const eligible = /* @__PURE__ */ new Set([...present, ...pendingChildren]);
24798
+ if (Array.isArray(codeKeys) && codeKeys.length) {
24799
+ resolved = codeKeys.filter((k) => eligible.has(k) && !EXCLUDE_KEYS.has(k));
24800
+ }
24801
+ if (Array.isArray(uses) && uses.length) {
24802
+ for (let u = 0; u < uses.length; u++) {
24803
+ const keyName = uses[u];
24804
+ if (eligible.has(keyName) && !EXCLUDE_KEYS.has(keyName) && !resolved.includes(keyName)) {
24805
+ resolved.push(keyName);
24806
+ }
24807
+ }
24808
+ }
24809
+ if (pendingChildren.size) {
24810
+ for (const child of pendingChildren) {
24811
+ if (!EXCLUDE_KEYS.has(child) && !resolved.includes(child)) {
24812
+ resolved.push(child);
24813
+ }
24814
+ }
24815
+ }
24816
+ if (resolved.length) {
24817
+ preferredOrderMap.set(JSON.stringify(containerPath), { path: containerPath, keys: resolved });
24818
+ }
24819
+ }
24820
+ const parents = getParentPathsFromTuples(tuples);
24821
+ const orders = [];
24822
+ const seen = /* @__PURE__ */ new Set();
24823
+ preferredOrderMap.forEach((v) => {
24824
+ const k = JSON.stringify(v.path);
24825
+ if (!seen.has(k)) {
24826
+ seen.add(k);
24827
+ orders.push(v);
24828
+ }
24829
+ });
24830
+ const fallbackOrders = computeOrdersFromState(root, parents);
24831
+ for (let i = 0; i < fallbackOrders.length; i++) {
24832
+ const v = fallbackOrders[i];
24833
+ const k = JSON.stringify(v.path);
24834
+ if (seen.has(k)) {
24835
+ continue;
24836
+ }
24837
+ const pending = pendingChildrenByContainer.get(k);
24838
+ if (pending && pending.size) {
24839
+ const existing = new Set(v.keys);
24840
+ for (const child of pending) {
24841
+ if (existing.has(child)) {
24842
+ continue;
24843
+ }
24844
+ v.keys.push(child);
24845
+ }
24846
+ }
24847
+ seen.add(k);
24848
+ orders.push(v);
24849
+ }
24850
+ return orders;
24851
+ }
24852
+
24853
+ // src/utils/changePreprocessor.js
24854
+ function isPlainObject2(val) {
24855
+ return val && typeof val === "object" && !Array.isArray(val);
24856
+ }
24857
+ function getByPathSafe(root, path) {
24858
+ if (!root || typeof root.getByPath !== "function") {
24859
+ return null;
24860
+ }
24861
+ try {
24862
+ return root.getByPath(path);
24863
+ } catch {
24864
+ return null;
24865
+ }
24866
+ }
24867
+ function preprocessChanges(root, tuples = [], options = {}) {
24868
+ const expandTuple = (t) => {
24869
+ const [action, path, value2] = t || [];
24870
+ const isSchemaPath = Array.isArray(path) && path[0] === "schema";
24871
+ if (action === "delete") {
24872
+ return [t];
24873
+ }
24874
+ const canConsiderExpansion = action === "update" && Array.isArray(path) && (path.length === 1 || path.length === 2 || isSchemaPath && path.length === 3) && isPlainObject2(value2);
24875
+ if (!canConsiderExpansion) {
24876
+ return [t];
24877
+ }
24878
+ const prev = getByPathSafe(root, path) || {};
24879
+ const next = value2 || {};
24880
+ if (!isPlainObject2(prev) || !isPlainObject2(next)) {
24881
+ return [t];
24882
+ }
24883
+ const ops = diffJson(prev, next, []);
24884
+ if (!ops.length) {
24885
+ return [t];
24886
+ }
24887
+ const out = [];
24888
+ for (let i = 0; i < ops.length; i++) {
24889
+ const op = ops[i];
24890
+ const fullPath = [...path, ...op.path];
24891
+ const last2 = fullPath[fullPath.length - 1];
24892
+ if (op.action === "set") {
24893
+ out.push(["update", fullPath, op.value]);
24894
+ } else if (op.action === "del") {
24895
+ if (last2 !== "__order") {
24896
+ out.push(["delete", fullPath]);
24897
+ }
24898
+ }
24899
+ }
24900
+ return out;
24901
+ };
24902
+ const minimizeTuples = (input) => {
24903
+ const out = [];
24904
+ const seen2 = /* @__PURE__ */ new Set();
24905
+ for (let i = 0; i < input.length; i++) {
24906
+ const expanded = expandTuple(input[i]);
24907
+ for (let k = 0; k < expanded.length; k++) {
24908
+ const tuple = expanded[k];
24909
+ const isDelete = Array.isArray(tuple) && tuple[0] === "delete";
24910
+ const isOrderKey = isDelete && Array.isArray(tuple[1]) && tuple[1][tuple[1].length - 1] === "__order";
24911
+ if (!isOrderKey) {
24912
+ const key = JSON.stringify(tuple);
24913
+ if (!seen2.has(key)) {
24914
+ seen2.add(key);
24915
+ out.push(tuple);
24916
+ }
24917
+ }
24918
+ }
24919
+ }
24920
+ return out;
24921
+ };
24922
+ const granularChanges = (() => {
24923
+ try {
24924
+ const res = minimizeTuples(tuples);
24925
+ if (options.append && options.append.length) {
24926
+ res.push(...options.append);
24927
+ }
24928
+ return res;
24929
+ } catch {
24930
+ return Array.isArray(tuples) ? tuples.slice() : [];
24931
+ }
24932
+ })();
24933
+ const baseOrders = computeOrdersForTuples(root, granularChanges);
24934
+ const preferOrdersMap = /* @__PURE__ */ new Map();
24935
+ for (let i = 0; i < tuples.length; i++) {
24936
+ const t = tuples[i];
24937
+ if (!Array.isArray(t) || t.length < 3) {
24938
+ continue;
24939
+ }
24940
+ const [action, path, value2] = t;
24941
+ if (action !== "update" || !Array.isArray(path) || path.length !== 1 && path.length !== 2 || !isPlainObject2(value2)) {
24942
+ continue;
24943
+ }
24944
+ const keys2 = Object.keys(value2).filter((k) => k !== "__order");
24945
+ const key = JSON.stringify(path);
24946
+ preferOrdersMap.set(key, { path, keys: keys2 });
24947
+ }
24948
+ const mergedOrders = [];
24949
+ const seen = /* @__PURE__ */ new Set();
24950
+ preferOrdersMap.forEach((v, k) => {
24951
+ seen.add(k);
24952
+ mergedOrders.push(v);
24953
+ });
24954
+ for (let i = 0; i < baseOrders.length; i++) {
24955
+ const v = baseOrders[i];
24956
+ const k = JSON.stringify(v.path);
24957
+ if (!seen.has(k)) {
24958
+ seen.add(k);
24959
+ mergedOrders.push(v);
24960
+ }
24961
+ }
24962
+ return { granularChanges, orders: mergedOrders };
24963
+ }
24964
+
24965
+ // src/services/CollabService.js
24525
24966
  var CollabService = class extends BaseService {
24526
24967
  constructor(config) {
24527
24968
  super(config);
@@ -24585,8 +25026,8 @@ var CollabService = class extends BaseService {
24585
25026
  logger(`[Notification] ${title}${message ? ` \u2013 ${message}` : ""}`);
24586
25027
  return;
24587
25028
  }
24588
- case "deepStringify": {
24589
- return deepStringify(...args2);
25029
+ case "deepStringifyFunctions": {
25030
+ return deepStringifyFunctions(...args2);
24590
25031
  }
24591
25032
  default:
24592
25033
  return {};
@@ -24621,57 +25062,49 @@ var CollabService = class extends BaseService {
24621
25062
  if (this._client) {
24622
25063
  await this.disconnect();
24623
25064
  }
24624
- try {
24625
- this._client = new CollabClient({
24626
- jwt,
24627
- projectId,
24628
- branch,
24629
- live: Boolean(pro)
24630
- });
24631
- await new Promise((resolve) => {
24632
- var _a2, _b2;
24633
- if ((_a2 = this._client.socket) == null ? void 0 : _a2.connected) {
24634
- resolve();
24635
- } else {
24636
- (_b2 = this._client.socket) == null ? void 0 : _b2.once("connect", resolve);
24637
- }
24638
- });
24639
- console.log("[CollabService] socket connected");
24640
- (_b = this._client.socket) == null ? void 0 : _b.on("ops", ({ changes }) => {
24641
- console.log(`ops event`);
24642
- console.log(changes);
24643
- this._stateManager.applyChanges(changes, { fromSocket: true });
24644
- });
24645
- (_c = this._client.socket) == null ? void 0 : _c.on("commit", ({ version: version2 }) => {
24646
- if (version2) {
24647
- this._stateManager.setVersion(version2);
24648
- }
24649
- rootBus.emit("checkpoint:done", { version: version2, origin: "auto" });
24650
- });
24651
- (_d = this._client.socket) == null ? void 0 : _d.on("clients", this._handleClientsEvent.bind(this));
24652
- (_e = this._client.socket) == null ? void 0 : _e.on(
24653
- "bundle:done",
24654
- this._handleBundleDoneEvent.bind(this)
24655
- );
24656
- (_f = this._client.socket) == null ? void 0 : _f.on(
24657
- "bundle:error",
24658
- this._handleBundleErrorEvent.bind(this)
24659
- );
24660
- if (this._pendingOps.length) {
24661
- console.log(
24662
- `[CollabService] Flushing ${this._pendingOps.length} offline operation batch(es)`
24663
- );
24664
- this._pendingOps.forEach(({ tuples }) => {
24665
- this.socket.emit("ops", { changes: tuples, ts: Date.now() });
24666
- });
24667
- this._pendingOps.length = 0;
25065
+ this._client = new CollabClient({
25066
+ jwt,
25067
+ projectId,
25068
+ branch,
25069
+ live: Boolean(pro)
25070
+ });
25071
+ await new Promise((resolve) => {
25072
+ var _a2, _b2;
25073
+ if ((_a2 = this._client.socket) == null ? void 0 : _a2.connected) {
25074
+ resolve();
25075
+ } else {
25076
+ (_b2 = this._client.socket) == null ? void 0 : _b2.once("connect", resolve);
24668
25077
  }
24669
- this._connected = true;
24670
- console.log("[CollabService] Connected to project:", projectId);
24671
- } catch (err) {
24672
- console.error("[CollabService] Connection failed:", err);
24673
- throw err;
25078
+ });
25079
+ (_b = this._client.socket) == null ? void 0 : _b.on("ops", ({ changes }) => {
25080
+ console.log(`ops event`);
25081
+ this._stateManager.applyChanges(changes, { fromSocket: true });
25082
+ });
25083
+ (_c = this._client.socket) == null ? void 0 : _c.on("commit", ({ version: version2 }) => {
25084
+ if (version2) {
25085
+ this._stateManager.setVersion(version2);
25086
+ }
25087
+ rootBus.emit("checkpoint:done", { version: version2, origin: "auto" });
25088
+ });
25089
+ (_d = this._client.socket) == null ? void 0 : _d.on("clients", this._handleClientsEvent.bind(this));
25090
+ (_e = this._client.socket) == null ? void 0 : _e.on(
25091
+ "bundle:done",
25092
+ this._handleBundleDoneEvent.bind(this)
25093
+ );
25094
+ (_f = this._client.socket) == null ? void 0 : _f.on(
25095
+ "bundle:error",
25096
+ this._handleBundleErrorEvent.bind(this)
25097
+ );
25098
+ if (this._pendingOps.length) {
25099
+ console.log(
25100
+ `[CollabService] Flushing ${this._pendingOps.length} offline operation batch(es)`
25101
+ );
25102
+ this._pendingOps.forEach(({ changes, granularChanges, orders }) => {
25103
+ this.socket.emit("ops", { changes, granularChanges, orders, ts: Date.now() });
25104
+ });
25105
+ this._pendingOps.length = 0;
24674
25106
  }
25107
+ this._connected = true;
24675
25108
  }
24676
25109
  disconnect() {
24677
25110
  var _a;
@@ -24709,24 +25142,60 @@ var CollabService = class extends BaseService {
24709
25142
  }
24710
25143
  /* ---------- data helpers ---------- */
24711
25144
  updateData(tuples, options = {}) {
24712
- var _a;
25145
+ var _a, _b, _c;
24713
25146
  this._ensureStateManager();
24714
25147
  const { isUndo = false, isRedo = false } = options;
24715
25148
  if (!isUndo && !isRedo && !this._isUndoRedo) {
24716
25149
  this._trackForUndo(tuples, options);
24717
25150
  }
25151
+ const root = (_a = this._stateManager) == null ? void 0 : _a.root;
25152
+ const { granularChanges: processedTuples, orders } = preprocessChanges(
25153
+ root,
25154
+ tuples,
25155
+ options
25156
+ );
24718
25157
  if (options.append && options.append.length) {
24719
- tuples.push(...options.append);
25158
+ processedTuples.push(...options.append);
24720
25159
  }
24721
25160
  this._stateManager.applyChanges(tuples, { ...options });
24722
- tuples = deepStringify(tuples, []);
25161
+ const state = (_b = this._stateManager) == null ? void 0 : _b.root;
25162
+ const el = state == null ? void 0 : state.__element;
25163
+ const stringifiedGranularTuples = (el == null ? void 0 : el.call) ? el.call(
25164
+ "deepStringifyFunctions",
25165
+ processedTuples,
25166
+ Array.isArray(processedTuples) ? [] : {}
25167
+ ) : deepStringifyFunctions(
25168
+ processedTuples,
25169
+ Array.isArray(processedTuples) ? [] : {}
25170
+ );
25171
+ const stringifiedTuples = (el == null ? void 0 : el.call) ? el.call(
25172
+ "deepStringifyFunctions",
25173
+ tuples,
25174
+ Array.isArray(tuples) ? [] : {}
25175
+ ) : deepStringifyFunctions(tuples, Array.isArray(tuples) ? [] : {});
24723
25176
  if (!this.isConnected()) {
24724
25177
  console.warn("[CollabService] Not connected, queuing real-time update");
24725
- this._pendingOps.push({ tuples, options });
25178
+ this._pendingOps.push({
25179
+ changes: stringifiedTuples,
25180
+ granularChanges: stringifiedGranularTuples,
25181
+ orders,
25182
+ options
25183
+ });
24726
25184
  return;
24727
25185
  }
24728
- if ((_a = this.socket) == null ? void 0 : _a.connected) {
24729
- this.socket.emit("ops", { changes: tuples, ts: Date.now() });
25186
+ if ((_c = this.socket) == null ? void 0 : _c.connected) {
25187
+ console.log("[CollabService] Sending operations to the backend", {
25188
+ changes: stringifiedTuples,
25189
+ granularChanges: stringifiedGranularTuples,
25190
+ orders,
25191
+ ts: Date.now()
25192
+ });
25193
+ this.socket.emit("ops", {
25194
+ changes: stringifiedTuples,
25195
+ granularChanges: stringifiedGranularTuples,
25196
+ orders,
25197
+ ts: Date.now()
25198
+ });
24730
25199
  }
24731
25200
  return { success: true };
24732
25201
  }
@@ -24867,7 +25336,7 @@ var CollabService = class extends BaseService {
24867
25336
  const updatedOpts = { ...opts, skipComponentsChangedEvent: true };
24868
25337
  return this.updateData(tuples, updatedOpts);
24869
25338
  } catch (error) {
24870
- throw new Error(`Failed to add item: ${error.message}`);
25339
+ throw new Error(`Failed to add item: ${error.message}`, { cause: error });
24871
25340
  }
24872
25341
  }
24873
25342
  addMultipleItems(items, opts = {}) {
@@ -24896,7 +25365,7 @@ var CollabService = class extends BaseService {
24896
25365
  title: "Failed to add item",
24897
25366
  message: error.message
24898
25367
  });
24899
- throw new Error(`Failed to add item: ${error.message}`);
25368
+ throw new Error(`Failed to add item: ${error.message}`, { cause: error });
24900
25369
  }
24901
25370
  }
24902
25371
  updateItem(type, data2, opts = {}) {
@@ -24918,7 +25387,9 @@ var CollabService = class extends BaseService {
24918
25387
  title: "Failed to update item",
24919
25388
  message: error.message
24920
25389
  });
24921
- throw new Error(`Failed to update item: ${error.message}`);
25390
+ throw new Error(`Failed to update item: ${error.message}`, {
25391
+ cause: error
25392
+ });
24922
25393
  }
24923
25394
  }
24924
25395
  deleteItem(type, key, opts = {}) {
@@ -24943,7 +25414,9 @@ var CollabService = class extends BaseService {
24943
25414
  title: "Failed to delete item",
24944
25415
  message: error.message
24945
25416
  });
24946
- throw new Error(`Failed to delete item: ${error.message}`);
25417
+ throw new Error(`Failed to delete item: ${error.message}`, {
25418
+ cause: error
25419
+ });
24947
25420
  }
24948
25421
  }
24949
25422
  /* ---------- socket event helpers ---------- */