@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.
- package/dist/cjs/config/environment.js +43 -8
- package/dist/cjs/index.js +12 -4
- package/dist/cjs/services/AdminService.js +4 -4
- package/dist/cjs/services/AuthService.js +36 -149
- package/dist/cjs/services/BaseService.js +5 -18
- package/dist/cjs/services/BranchService.js +10 -10
- package/dist/cjs/services/CollabService.js +94 -61
- package/dist/cjs/services/CoreService.js +19 -19
- package/dist/cjs/services/DnsService.js +4 -4
- package/dist/cjs/services/FileService.js +2 -2
- package/dist/cjs/services/PaymentService.js +2 -2
- package/dist/cjs/services/PlanService.js +12 -12
- package/dist/cjs/services/ProjectService.js +45 -35
- package/dist/cjs/services/PullRequestService.js +7 -7
- package/dist/cjs/services/ScreenshotService.js +304 -0
- package/dist/cjs/services/SubscriptionService.js +14 -14
- package/dist/cjs/services/index.js +4 -0
- package/dist/cjs/utils/TokenManager.js +16 -5
- package/dist/cjs/utils/changePreprocessor.js +134 -0
- package/dist/cjs/utils/jsonDiff.js +46 -4
- package/dist/cjs/utils/ordering.js +274 -0
- package/dist/cjs/utils/services.js +14 -1
- package/dist/esm/config/environment.js +43 -8
- package/dist/esm/index.js +1099 -417
- package/dist/esm/services/AdminService.js +68 -35
- package/dist/esm/services/AuthService.js +100 -168
- package/dist/esm/services/BaseService.js +64 -31
- package/dist/esm/services/BranchService.js +74 -41
- package/dist/esm/services/CollabService.js +570 -97
- package/dist/esm/services/CoreService.js +83 -50
- package/dist/esm/services/DnsService.js +68 -35
- package/dist/esm/services/FileService.js +66 -33
- package/dist/esm/services/PaymentService.js +66 -33
- package/dist/esm/services/PlanService.js +76 -43
- package/dist/esm/services/ProjectService.js +547 -66
- package/dist/esm/services/PullRequestService.js +71 -38
- package/dist/esm/services/ScreenshotService.js +992 -0
- package/dist/esm/services/SubscriptionService.js +78 -45
- package/dist/esm/services/index.js +1076 -412
- package/dist/esm/utils/CollabClient.js +89 -12
- package/dist/esm/utils/TokenManager.js +16 -5
- package/dist/esm/utils/changePreprocessor.js +442 -0
- package/dist/esm/utils/jsonDiff.js +46 -4
- package/dist/esm/utils/ordering.js +256 -0
- package/dist/esm/utils/services.js +14 -1
- package/dist/node/config/environment.js +43 -8
- package/dist/node/index.js +14 -5
- package/dist/node/services/AdminService.js +4 -4
- package/dist/node/services/AuthService.js +36 -139
- package/dist/node/services/BaseService.js +5 -18
- package/dist/node/services/BranchService.js +10 -10
- package/dist/node/services/CollabService.js +95 -62
- package/dist/node/services/CoreService.js +19 -19
- package/dist/node/services/DnsService.js +4 -4
- package/dist/node/services/FileService.js +2 -2
- package/dist/node/services/PaymentService.js +2 -2
- package/dist/node/services/PlanService.js +12 -12
- package/dist/node/services/ProjectService.js +45 -35
- package/dist/node/services/PullRequestService.js +7 -7
- package/dist/node/services/ScreenshotService.js +285 -0
- package/dist/node/services/SubscriptionService.js +14 -14
- package/dist/node/services/index.js +4 -0
- package/dist/node/utils/TokenManager.js +16 -5
- package/dist/node/utils/changePreprocessor.js +115 -0
- package/dist/node/utils/jsonDiff.js +46 -4
- package/dist/node/utils/ordering.js +255 -0
- package/dist/node/utils/services.js +14 -1
- package/package.json +7 -6
- package/src/config/environment.js +48 -9
- package/src/index.js +38 -22
- package/src/services/AdminService.js +4 -4
- package/src/services/AuthService.js +42 -175
- package/src/services/BaseService.js +7 -24
- package/src/services/BranchService.js +10 -10
- package/src/services/CollabService.js +115 -74
- package/src/services/CoreService.js +19 -19
- package/src/services/DnsService.js +4 -4
- package/src/services/FileService.js +2 -2
- package/src/services/PaymentService.js +2 -2
- package/src/services/PlanService.js +12 -12
- package/src/services/ProjectService.js +50 -35
- package/src/services/PullRequestService.js +7 -7
- package/src/services/ScreenshotService.js +258 -0
- package/src/services/SubscriptionService.js +14 -14
- package/src/services/index.js +6 -1
- package/src/utils/TokenManager.js +19 -5
- package/src/utils/changePreprocessor.js +139 -0
- package/src/utils/jsonDiff.js +40 -5
- package/src/utils/ordering.js +244 -0
- package/src/utils/services.js +15 -1
|
@@ -17488,18 +17488,28 @@ var CONFIG = {
|
|
|
17488
17488
|
// For based api
|
|
17489
17489
|
basedOrg: "symbols",
|
|
17490
17490
|
// For based api
|
|
17491
|
-
githubClientId: "
|
|
17491
|
+
githubClientId: "Ov23liAFrsR0StbAO6PO",
|
|
17492
17492
|
// For github api
|
|
17493
17493
|
// Environment-specific feature toggles (override common)
|
|
17494
17494
|
features: {
|
|
17495
17495
|
betaFeatures: true
|
|
17496
17496
|
// Enable beta features in local dev
|
|
17497
|
-
}
|
|
17497
|
+
},
|
|
17498
|
+
typesenseCollectionName: "docs",
|
|
17499
|
+
typesenseApiKey: "vZya3L2zpq8L6iI5WWMUZJZABvT63VDb",
|
|
17500
|
+
typesenseHost: "localhost",
|
|
17501
|
+
typesensePort: "8108",
|
|
17502
|
+
typesenseProtocol: "http"
|
|
17498
17503
|
},
|
|
17499
17504
|
development: {
|
|
17500
17505
|
socketUrl: "https://dev.api.symbols.app",
|
|
17501
17506
|
apiUrl: "https://dev.api.symbols.app",
|
|
17502
|
-
githubClientId: "Ov23liHxyWFBxS8f1gnF"
|
|
17507
|
+
githubClientId: "Ov23liHxyWFBxS8f1gnF",
|
|
17508
|
+
typesenseCollectionName: "docs",
|
|
17509
|
+
typesenseApiKey: "awmcVpbWqZi9IUgmvslp1C5LKDU8tMjA",
|
|
17510
|
+
typesenseHost: "tl2qpnwxev4cjm36p-1.a1.typesense.net",
|
|
17511
|
+
typesensePort: "443",
|
|
17512
|
+
typesenseProtocol: "https"
|
|
17503
17513
|
},
|
|
17504
17514
|
testing: {
|
|
17505
17515
|
socketUrl: "https://test.api.symbols.app",
|
|
@@ -17507,12 +17517,22 @@ var CONFIG = {
|
|
|
17507
17517
|
basedEnv: "testing",
|
|
17508
17518
|
basedProject: "platform-v2-sm",
|
|
17509
17519
|
basedOrg: "symbols",
|
|
17510
|
-
githubClientId: "Ov23liHxyWFBxS8f1gnF"
|
|
17520
|
+
githubClientId: "Ov23liHxyWFBxS8f1gnF",
|
|
17521
|
+
typesenseCollectionName: "docs",
|
|
17522
|
+
typesenseApiKey: "awmcVpbWqZi9IUgmvslp1C5LKDU8tMjA",
|
|
17523
|
+
typesenseHost: "tl2qpnwxev4cjm36p-1.a1.typesense.net",
|
|
17524
|
+
typesensePort: "443",
|
|
17525
|
+
typesenseProtocol: "https"
|
|
17511
17526
|
},
|
|
17512
17527
|
upcoming: {
|
|
17513
17528
|
socketUrl: "https://upcoming.api.symbols.app",
|
|
17514
17529
|
apiUrl: "https://upcoming.api.symbols.app",
|
|
17515
|
-
githubClientId: "Ov23liWF7NvdZ056RV5J"
|
|
17530
|
+
githubClientId: "Ov23liWF7NvdZ056RV5J",
|
|
17531
|
+
typesenseCollectionName: "docs",
|
|
17532
|
+
typesenseApiKey: "awmcVpbWqZi9IUgmvslp1C5LKDU8tMjA",
|
|
17533
|
+
typesenseHost: "tl2qpnwxev4cjm36p-1.a1.typesense.net",
|
|
17534
|
+
typesensePort: "443",
|
|
17535
|
+
typesenseProtocol: "https"
|
|
17516
17536
|
},
|
|
17517
17537
|
staging: {
|
|
17518
17538
|
socketUrl: "https://staging.api.symbols.app",
|
|
@@ -17520,7 +17540,12 @@ var CONFIG = {
|
|
|
17520
17540
|
basedEnv: "staging",
|
|
17521
17541
|
basedProject: "platform-v2-sm",
|
|
17522
17542
|
basedOrg: "symbols",
|
|
17523
|
-
githubClientId: "Ov23ligwZDQVD0VfuWNa"
|
|
17543
|
+
githubClientId: "Ov23ligwZDQVD0VfuWNa",
|
|
17544
|
+
typesenseCollectionName: "docs",
|
|
17545
|
+
typesenseApiKey: "awmcVpbWqZi9IUgmvslp1C5LKDU8tMjA",
|
|
17546
|
+
typesenseHost: "tl2qpnwxev4cjm36p-1.a1.typesense.net",
|
|
17547
|
+
typesensePort: "443",
|
|
17548
|
+
typesenseProtocol: "https"
|
|
17524
17549
|
},
|
|
17525
17550
|
production: {
|
|
17526
17551
|
socketUrl: "https://api.symbols.app",
|
|
@@ -17528,7 +17553,12 @@ var CONFIG = {
|
|
|
17528
17553
|
basedEnv: "production",
|
|
17529
17554
|
basedProject: "platform-v2-sm",
|
|
17530
17555
|
basedOrg: "symbols",
|
|
17531
|
-
githubClientId: "Ov23liFAlOEIXtX3dBtR"
|
|
17556
|
+
githubClientId: "Ov23liFAlOEIXtX3dBtR",
|
|
17557
|
+
typesenseCollectionName: "docs",
|
|
17558
|
+
typesenseApiKey: "awmcVpbWqZi9IUgmvslp1C5LKDU8tMjA",
|
|
17559
|
+
typesenseHost: "tl2qpnwxev4cjm36p-1.a1.typesense.net",
|
|
17560
|
+
typesensePort: "443",
|
|
17561
|
+
typesenseProtocol: "https"
|
|
17532
17562
|
}
|
|
17533
17563
|
};
|
|
17534
17564
|
var getEnvironment = () => {
|
|
@@ -17550,6 +17580,11 @@ var getConfig = () => {
|
|
|
17550
17580
|
basedProject: process.env.SYMBOLS_APP_BASED_PROJECT || envConfig.basedProject,
|
|
17551
17581
|
basedOrg: process.env.SYMBOLS_APP_BASED_ORG || envConfig.basedOrg,
|
|
17552
17582
|
githubClientId: process.env.SYMBOLS_APP_GITHUB_CLIENT_ID || envConfig.githubClientId,
|
|
17583
|
+
typesenseCollectionName: process.env.TYPESENSE_COLLECTION_NAME || envConfig.typesenseCollectionName,
|
|
17584
|
+
typesenseApiKey: process.env.TYPESENSE_API_KEY || envConfig.typesenseApiKey,
|
|
17585
|
+
typesenseHost: process.env.TYPESENSE_HOST || envConfig.typesenseHost,
|
|
17586
|
+
typesensePort: process.env.TYPESENSE_PORT || envConfig.typesensePort,
|
|
17587
|
+
typesenseProtocol: process.env.TYPESENSE_PROTOCOL || envConfig.typesenseProtocol,
|
|
17553
17588
|
isDevelopment: isDevelopment(env),
|
|
17554
17589
|
isTesting: env === "testing",
|
|
17555
17590
|
isStaging: env === "staging",
|
|
@@ -17569,7 +17604,7 @@ var getConfig = () => {
|
|
|
17569
17604
|
);
|
|
17570
17605
|
}
|
|
17571
17606
|
if (finalConfig.isDevelopment) {
|
|
17572
|
-
console.
|
|
17607
|
+
console.warn(
|
|
17573
17608
|
"environment in SDK:",
|
|
17574
17609
|
env || process.env.NODE_ENV || process.env.NODE_ENV
|
|
17575
17610
|
);
|
|
@@ -17593,12 +17628,54 @@ function isPlainObject(o) {
|
|
|
17593
17628
|
return o && typeof o === "object" && !Array.isArray(o);
|
|
17594
17629
|
}
|
|
17595
17630
|
function deepEqual(a, b) {
|
|
17596
|
-
|
|
17597
|
-
return
|
|
17598
|
-
}
|
|
17599
|
-
|
|
17631
|
+
if (Object.is(a, b)) {
|
|
17632
|
+
return true;
|
|
17633
|
+
}
|
|
17634
|
+
if (typeof a === "function" && typeof b === "function") {
|
|
17635
|
+
try {
|
|
17636
|
+
return a.toString() === b.toString();
|
|
17637
|
+
} catch {
|
|
17638
|
+
return false;
|
|
17639
|
+
}
|
|
17640
|
+
}
|
|
17641
|
+
if (typeof a === "function" || typeof b === "function") {
|
|
17600
17642
|
return false;
|
|
17601
17643
|
}
|
|
17644
|
+
if (a instanceof Date && b instanceof Date) {
|
|
17645
|
+
return a.getTime() === b.getTime();
|
|
17646
|
+
}
|
|
17647
|
+
if (a instanceof RegExp && b instanceof RegExp) {
|
|
17648
|
+
return String(a) === String(b);
|
|
17649
|
+
}
|
|
17650
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
17651
|
+
if (a.length !== b.length) {
|
|
17652
|
+
return false;
|
|
17653
|
+
}
|
|
17654
|
+
for (let i = 0; i < a.length; i++) {
|
|
17655
|
+
if (!deepEqual(a[i], b[i])) {
|
|
17656
|
+
return false;
|
|
17657
|
+
}
|
|
17658
|
+
}
|
|
17659
|
+
return true;
|
|
17660
|
+
}
|
|
17661
|
+
if (a && b && typeof a === "object" && typeof b === "object") {
|
|
17662
|
+
const aKeys = Object.keys(a);
|
|
17663
|
+
const bKeys = Object.keys(b);
|
|
17664
|
+
if (aKeys.length !== bKeys.length) {
|
|
17665
|
+
return false;
|
|
17666
|
+
}
|
|
17667
|
+
for (let i = 0; i < aKeys.length; i++) {
|
|
17668
|
+
const key = aKeys[i];
|
|
17669
|
+
if (!Object.hasOwn(b, key)) {
|
|
17670
|
+
return false;
|
|
17671
|
+
}
|
|
17672
|
+
if (!deepEqual(a[key], b[key])) {
|
|
17673
|
+
return false;
|
|
17674
|
+
}
|
|
17675
|
+
}
|
|
17676
|
+
return true;
|
|
17677
|
+
}
|
|
17678
|
+
return false;
|
|
17602
17679
|
}
|
|
17603
17680
|
function getRootMap(ydoc) {
|
|
17604
17681
|
return ydoc.getMap("root");
|
|
@@ -23,7 +23,7 @@ var TokenManager = class {
|
|
|
23
23
|
});
|
|
24
24
|
this.config = {
|
|
25
25
|
storagePrefix: "symbols_",
|
|
26
|
-
storageType: typeof window === "undefined" || process.env.NODE_ENV === "test" ? "memory" : "localStorage",
|
|
26
|
+
storageType: typeof window === "undefined" || process.env.NODE_ENV === "test" || process.env.NODE_ENV === "testing" ? "memory" : "localStorage",
|
|
27
27
|
// 'localStorage' | 'sessionStorage' | 'memory'
|
|
28
28
|
refreshBuffer: 60 * 1e3,
|
|
29
29
|
// Refresh 1 minute before expiry
|
|
@@ -63,15 +63,26 @@ var TokenManager = class {
|
|
|
63
63
|
if (typeof window === "undefined") {
|
|
64
64
|
return this._memoryStorage;
|
|
65
65
|
}
|
|
66
|
-
const
|
|
67
|
-
|
|
66
|
+
const safeGetStorage = (provider) => {
|
|
67
|
+
try {
|
|
68
|
+
const storage = provider();
|
|
69
|
+
const testKey = `${this.config.storagePrefix}__tm_test__`;
|
|
70
|
+
storage.setItem(testKey, "1");
|
|
71
|
+
storage.removeItem(testKey);
|
|
72
|
+
return storage;
|
|
73
|
+
} catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const localStorageInstance = safeGetStorage(() => window.localStorage);
|
|
78
|
+
const sessionStorageInstance = safeGetStorage(() => window.sessionStorage);
|
|
68
79
|
switch (this.config.storageType) {
|
|
69
80
|
case "sessionStorage":
|
|
70
|
-
return
|
|
81
|
+
return sessionStorageInstance || this._memoryStorage;
|
|
71
82
|
case "memory":
|
|
72
83
|
return this._memoryStorage;
|
|
73
84
|
default:
|
|
74
|
-
return
|
|
85
|
+
return localStorageInstance || this._memoryStorage;
|
|
75
86
|
}
|
|
76
87
|
}
|
|
77
88
|
/**
|
|
@@ -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
|
-
|
|
6029
|
-
return
|
|
6030
|
-
}
|
|
6031
|
-
|
|
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");
|