@powerhousedao/reactor 6.0.0-dev.52 → 6.0.0-dev.53
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.
|
@@ -3,6 +3,10 @@ type OperationIndex = {
|
|
|
3
3
|
skip: number;
|
|
4
4
|
id: string;
|
|
5
5
|
timestampUtcMs: string;
|
|
6
|
+
action?: {
|
|
7
|
+
id?: string;
|
|
8
|
+
type?: string;
|
|
9
|
+
};
|
|
6
10
|
};
|
|
7
11
|
/**
|
|
8
12
|
* Sorts operations by index and skip number.
|
|
@@ -10,12 +14,15 @@ type OperationIndex = {
|
|
|
10
14
|
*/
|
|
11
15
|
export declare function sortOperations<TOpIndex extends OperationIndex>(operations: TOpIndex[]): TOpIndex[];
|
|
12
16
|
/**
|
|
13
|
-
* Reshuffles operations by timestamp, then
|
|
17
|
+
* Reshuffles operations by timestamp, then applies deterministic tie-breaking.
|
|
14
18
|
* Used for merging concurrent operations from different branches.
|
|
15
19
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
20
|
+
* For strict document-structure actions (e.g., CREATE_DOCUMENT/UPGRADE_DOCUMENT),
|
|
21
|
+
* logical index (index - skip) is prioritized to preserve causal replay order.
|
|
22
|
+
*
|
|
23
|
+
* For other actions, action ID is prioritized to ensure a canonical cross-reactor order
|
|
24
|
+
* for concurrent operations that may have diverged local indices due to prior reshuffles.
|
|
25
|
+
* Logical index and operation ID are then used as deterministic tie-breakers.
|
|
19
26
|
*
|
|
20
27
|
* Example:
|
|
21
28
|
* [0:0, 1:0, 2:0, A3:0, A4:0, A5:0] + [0:0, 1:0, 2:0, B3:0, B4:2, B5:0]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reshuffle.d.ts","sourceRoot":"","sources":["../../../src/utils/reshuffle.ts"],"names":[],"mappings":"AAAA,KAAK,cAAc,GAAG;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"reshuffle.d.ts","sourceRoot":"","sources":["../../../src/utils/reshuffle.ts"],"names":[],"mappings":"AAAA,KAAK,cAAc,GAAG;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE;QACP,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;CACH,CAAC;AAUF;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,SAAS,cAAc,EAC5D,UAAU,EAAE,QAAQ,EAAE,GACrB,QAAQ,EAAE,CAKZ;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,SAAS,cAAc,EAC7D,UAAU,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAC3C,IAAI,EAAE,GAAG,EAAE,EACX,IAAI,EAAE,GAAG,EAAE,GACV,GAAG,EAAE,CAuCP;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,GAAG,SAAS,cAAc,EACrE,UAAU,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAC3C,IAAI,EAAE,GAAG,EAAE,EACX,IAAI,EAAE,GAAG,EAAE,GACV,GAAG,EAAE,CAoBP"}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
const STRICT_ORDER_ACTION_TYPES = new Set([
|
|
2
|
+
"CREATE_DOCUMENT",
|
|
3
|
+
"DELETE_DOCUMENT",
|
|
4
|
+
"UPGRADE_DOCUMENT",
|
|
5
|
+
"ADD_RELATIONSHIP",
|
|
6
|
+
"REMOVE_RELATIONSHIP",
|
|
7
|
+
]);
|
|
1
8
|
/**
|
|
2
9
|
* Sorts operations by index and skip number.
|
|
3
10
|
* [0:0 2:0 1:0 3:3 3:1] => [0:0 1:0 2:0 3:1 3:3]
|
|
@@ -9,12 +16,15 @@ export function sortOperations(operations) {
|
|
|
9
16
|
.sort((a, b) => a.index - b.index);
|
|
10
17
|
}
|
|
11
18
|
/**
|
|
12
|
-
* Reshuffles operations by timestamp, then
|
|
19
|
+
* Reshuffles operations by timestamp, then applies deterministic tie-breaking.
|
|
13
20
|
* Used for merging concurrent operations from different branches.
|
|
14
21
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
22
|
+
* For strict document-structure actions (e.g., CREATE_DOCUMENT/UPGRADE_DOCUMENT),
|
|
23
|
+
* logical index (index - skip) is prioritized to preserve causal replay order.
|
|
24
|
+
*
|
|
25
|
+
* For other actions, action ID is prioritized to ensure a canonical cross-reactor order
|
|
26
|
+
* for concurrent operations that may have diverged local indices due to prior reshuffles.
|
|
27
|
+
* Logical index and operation ID are then used as deterministic tie-breakers.
|
|
18
28
|
*
|
|
19
29
|
* Example:
|
|
20
30
|
* [0:0, 1:0, 2:0, A3:0, A4:0, A5:0] + [0:0, 1:0, 2:0, B3:0, B4:2, B5:0]
|
|
@@ -31,9 +41,20 @@ export function reshuffleByTimestamp(startIndex, opsA, opsB) {
|
|
|
31
41
|
if (timestampDiff !== 0) {
|
|
32
42
|
return timestampDiff;
|
|
33
43
|
}
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
44
|
+
const shouldPrioritizeLogicalIndex = STRICT_ORDER_ACTION_TYPES.has(a.action?.type ?? "") ||
|
|
45
|
+
STRICT_ORDER_ACTION_TYPES.has(b.action?.type ?? "");
|
|
46
|
+
const logicalIndexDiff = a.index - a.skip - (b.index - b.skip);
|
|
47
|
+
if (shouldPrioritizeLogicalIndex) {
|
|
48
|
+
if (logicalIndexDiff !== 0) {
|
|
49
|
+
return logicalIndexDiff;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const actionIdDiff = (a.action?.id ?? "").localeCompare(b.action?.id ?? "");
|
|
53
|
+
if (actionIdDiff !== 0) {
|
|
54
|
+
return actionIdDiff;
|
|
55
|
+
}
|
|
56
|
+
if (!shouldPrioritizeLogicalIndex && logicalIndexDiff !== 0) {
|
|
57
|
+
return logicalIndexDiff;
|
|
37
58
|
}
|
|
38
59
|
return a.id.localeCompare(b.id);
|
|
39
60
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reshuffle.js","sourceRoot":"","sources":["../../../src/utils/reshuffle.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reshuffle.js","sourceRoot":"","sources":["../../../src/utils/reshuffle.ts"],"names":[],"mappings":"AAWA,MAAM,yBAAyB,GAAG,IAAI,GAAG,CAAC;IACxC,iBAAiB;IACjB,iBAAiB;IACjB,kBAAkB;IAClB,kBAAkB;IAClB,qBAAqB;CACtB,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC5B,UAAsB;IAEtB,OAAO,UAAU;SACd,KAAK,EAAE;SACP,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;SAC/B,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,oBAAoB,CAClC,UAA2C,EAC3C,IAAW,EACX,IAAW;IAEX,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;SACtB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACb,MAAM,aAAa,GACjB,IAAI,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE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CAAC,CAAC,CAAC,CAAC;KACpC,CAAC,CAAC,CAAC;AACR,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,4BAA4B,CAC1C,UAA2C,EAC3C,IAAW,EACX,IAAW;IAEX,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;SACtB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACb,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;QACpC,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;YACpB,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,aAAa,GACjB,IAAI,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE;YACpC,IAAI,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE,CAAC;QACvC,IAAI,aAAa,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,aAAa,CAAC;QACvB,CAAC;QACD,OAAO,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAClC,CAAC,CAAC;SACD,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QACf,GAAG,EAAE;QACL,KAAK,EAAE,UAAU,CAAC,KAAK,GAAG,CAAC;QAC3B,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACpC,CAAC,CAAC,CAAC;AACR,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerhousedao/reactor",
|
|
3
|
-
"version": "6.0.0-dev.
|
|
3
|
+
"version": "6.0.0-dev.53",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "https://github.com/powerhouse-inc/powerhouse",
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"kysely": "0.28.11",
|
|
27
27
|
"kysely-pglite-dialect": "1.2.0",
|
|
28
28
|
"uuid": "^11.0.5",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"document-
|
|
29
|
+
"document-model": "6.0.0-dev.53",
|
|
30
|
+
"@powerhousedao/shared": "6.0.0-dev.53",
|
|
31
|
+
"document-drive": "6.0.0-dev.53"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@powerhousedao/analytics-engine-core": "0.5.0",
|