@ibgib/core-gib 0.1.22 → 0.1.25
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/common/other/graph-helper.d.mts +25 -0
- package/dist/common/other/graph-helper.d.mts.map +1 -1
- package/dist/common/other/graph-helper.mjs +75 -1
- package/dist/common/other/graph-helper.mjs.map +1 -1
- package/dist/sync/graft-info/graft-info-helpers.mjs +2 -2
- package/dist/sync/graft-info/graft-info-helpers.mjs.map +1 -1
- package/dist/sync/sync-conflict.respec.mjs +8 -12
- package/dist/sync/sync-conflict.respec.mjs.map +1 -1
- package/dist/sync/sync-constants.d.mts +14 -4
- package/dist/sync/sync-constants.d.mts.map +1 -1
- package/dist/sync/sync-constants.mjs +15 -3
- package/dist/sync/sync-constants.mjs.map +1 -1
- package/dist/sync/sync-helpers.d.mts +22 -15
- package/dist/sync/sync-helpers.d.mts.map +1 -1
- package/dist/sync/sync-helpers.mjs +159 -90
- package/dist/sync/sync-helpers.mjs.map +1 -1
- package/dist/sync/sync-innerspace-constants.respec.mjs +8 -9
- package/dist/sync/sync-innerspace-constants.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace-deep-updates.respec.mjs +8 -9
- package/dist/sync/sync-innerspace-deep-updates.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace-dest-ahead.respec.mjs +8 -9
- package/dist/sync/sync-innerspace-dest-ahead.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs +8 -9
- package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace-partial-update.respec.mjs +8 -9
- package/dist/sync/sync-innerspace-partial-update.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace.respec.mjs +6 -7
- package/dist/sync/sync-innerspace.respec.mjs.map +1 -1
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.d.mts +2 -0
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.d.mts.map +1 -1
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.mjs +4 -0
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.mjs.map +1 -1
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-types.d.mts +0 -15
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-types.d.mts.map +1 -1
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.d.mts +30 -16
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.d.mts.map +1 -1
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs +47 -79
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs.map +1 -1
- package/dist/sync/sync-peer/sync-peer-types.d.mts +40 -1
- package/dist/sync/sync-peer/sync-peer-types.d.mts.map +1 -1
- package/dist/sync/sync-peer/sync-peer-v1.d.mts +47 -14
- package/dist/sync/sync-peer/sync-peer-v1.d.mts.map +1 -1
- package/dist/sync/sync-peer/sync-peer-v1.mjs +188 -144
- package/dist/sync/sync-peer/sync-peer-v1.mjs.map +1 -1
- package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts +39 -3
- package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts.map +1 -1
- package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs +137 -31
- package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs.map +1 -1
- package/dist/sync/sync-saga-context/sync-saga-context-types.d.mts +5 -0
- package/dist/sync/sync-saga-context/sync-saga-context-types.d.mts.map +1 -1
- package/dist/sync/sync-saga-coordinator.d.mts +81 -77
- package/dist/sync/sync-saga-coordinator.d.mts.map +1 -1
- package/dist/sync/sync-saga-coordinator.mjs +608 -597
- package/dist/sync/sync-saga-coordinator.mjs.map +1 -1
- package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts +154 -26
- package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts.map +1 -1
- package/dist/sync/sync-types.d.mts +87 -92
- package/dist/sync/sync-types.d.mts.map +1 -1
- package/dist/sync/sync-types.mjs +6 -2
- package/dist/sync/sync-types.mjs.map +1 -1
- package/dist/timeline/timeline-api.d.mts.map +1 -1
- package/dist/timeline/timeline-api.mjs +15 -8
- package/dist/timeline/timeline-api.mjs.map +1 -1
- package/package.json +1 -1
- package/src/common/other/graph-helper.mts +79 -1
- package/src/sync/graft-info/graft-info-helpers.mts +3 -3
- package/src/sync/sync-conflict.respec.mts +8 -14
- package/src/sync/sync-constants.mts +15 -4
- package/src/sync/sync-helpers.mts +173 -101
- package/src/sync/sync-innerspace-constants.respec.mts +8 -9
- package/src/sync/sync-innerspace-deep-updates.respec.mts +8 -9
- package/src/sync/sync-innerspace-dest-ahead.respec.mts +8 -9
- package/src/sync/sync-innerspace-multiple-timelines.respec.mts +8 -9
- package/src/sync/sync-innerspace-partial-update.respec.mts +9 -12
- package/src/sync/sync-innerspace.respec.mts +6 -7
- package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.mts +7 -0
- package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-types.mts +0 -15
- package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mts +72 -96
- package/src/sync/sync-peer/sync-peer-types.mts +43 -2
- package/src/sync/sync-peer/sync-peer-v1.mts +215 -142
- package/src/sync/sync-saga-context/sync-saga-context-helpers.mts +145 -37
- package/src/sync/sync-saga-context/sync-saga-context-types.mts +5 -0
- package/src/sync/sync-saga-coordinator.mts +680 -714
- package/src/sync/sync-saga-message/sync-saga-message-types.mts +160 -24
- package/src/sync/sync-types.mts +96 -105
- package/src/timeline/timeline-api.mts +17 -10
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
ifWeMight
|
|
11
11
|
} from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
|
|
12
12
|
const maam = `[${import.meta.url}]`, sir = maam;
|
|
13
|
-
import { delay, extractErrorMsg, pretty } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
13
|
+
import { clone, delay, extractErrorMsg, pretty } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
14
14
|
import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
|
|
15
15
|
|
|
16
16
|
import { SyncSagaCoordinator } from './sync-saga-coordinator.mjs';
|
|
@@ -27,6 +27,7 @@ import { IbGibData_V1, IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
|
|
|
27
27
|
import { fnObs } from '../common/pubsub/observer/observer-helper.mjs';
|
|
28
28
|
import { getDependencyGraph } from '../common/other/graph-helper.mjs';
|
|
29
29
|
import { ErrorIbGib_V1 } from '../common/error/error-types.mjs';
|
|
30
|
+
import { SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1 } from './sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.mjs';
|
|
30
31
|
|
|
31
32
|
interface TestData extends IbGibData_V1 {
|
|
32
33
|
text?: string;
|
|
@@ -112,7 +113,7 @@ await respecfully(sir, `Sync Conflict Resolution`, async () => {
|
|
|
112
113
|
|
|
113
114
|
const resGetDest = await getFromSpace({ space: destSpace, addr: getIbGibAddr({ ibGib: v1_Common }) });
|
|
114
115
|
if (!resGetDest.success || !resGetDest.ibGibs || resGetDest.ibGibs.length === 0) {
|
|
115
|
-
throw new Error(`Failed to retrieve v1_Dest from destSpace. (E:
|
|
116
|
+
throw new Error(`Failed to retrieve v1_Dest from destSpace. (E: 40c67811eba14f729880a46dcbb65126)`);
|
|
116
117
|
}
|
|
117
118
|
const v1_Dest = resGetDest.ibGibs[0];
|
|
118
119
|
|
|
@@ -152,21 +153,14 @@ await respecfully(sir, `Sync Conflict Resolution`, async () => {
|
|
|
152
153
|
const senderCoordinator = new SyncSagaCoordinator(mockKeystone);
|
|
153
154
|
const receiverCoordinator = new SyncSagaCoordinator(mockKeystone);
|
|
154
155
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
senderSpace: sourceSpace,
|
|
159
|
-
//
|
|
160
|
-
receiverSpace: destSpace,
|
|
156
|
+
const peer = new SyncPeerInnerspace_V1(clone(SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1));
|
|
157
|
+
await peer.initialized;
|
|
158
|
+
await peer.initializeSender({
|
|
159
|
+
senderSpace: sourceSpace, // "Client"
|
|
160
|
+
receiverSpace: destSpace, // "Server"
|
|
161
161
|
receiverCoordinator,
|
|
162
162
|
receiverMetaspace: metaspace,
|
|
163
|
-
receiverTempSpace: 0 as any, // placeholder this is wrong
|
|
164
|
-
senderTempSpace: 0 as any, // placeholder this is wrong
|
|
165
|
-
}, {
|
|
166
|
-
classname: SyncPeerInnerspace_V1.name,
|
|
167
163
|
});
|
|
168
|
-
await peer.initialized;
|
|
169
|
-
await peer.initialize();
|
|
170
164
|
|
|
171
165
|
// Verify Receiver has correct KV (Pre-Sync Check)
|
|
172
166
|
// This ensures the conflict precondition exists.
|
|
@@ -1,29 +1,40 @@
|
|
|
1
1
|
export const SYNC_ATOM = "sync";
|
|
2
2
|
|
|
3
|
-
export const SYNC_MSG_REL8N_NAME = "
|
|
3
|
+
export const SYNC_MSG_REL8N_NAME = "syncmsg";
|
|
4
4
|
/**
|
|
5
5
|
* payload addrs should be domain-only, i.e., we are not including the sync
|
|
6
6
|
* saga ibgib, or its message stone, or identity keystones.
|
|
7
7
|
*/
|
|
8
8
|
export const SYNC_SAGA_PAYLOAD_ADDRS_DOMAIN = "@payloadAddrsDomain";
|
|
9
9
|
|
|
10
|
+
// #region SyncStage
|
|
10
11
|
export const SYNC_STAGE_INIT = "init";
|
|
11
12
|
export const SYNC_STAGE_ACK = "ack";
|
|
12
|
-
export const SYNC_STAGE_REQUEST = "request";
|
|
13
13
|
export const SYNC_STAGE_DELTA = "delta";
|
|
14
14
|
export const SYNC_STAGE_COMMIT = "commit";
|
|
15
15
|
|
|
16
16
|
export type SyncStage =
|
|
17
17
|
| typeof SYNC_STAGE_INIT
|
|
18
18
|
| typeof SYNC_STAGE_ACK
|
|
19
|
-
| typeof SYNC_STAGE_REQUEST
|
|
20
19
|
| typeof SYNC_STAGE_DELTA
|
|
21
20
|
| typeof SYNC_STAGE_COMMIT;
|
|
22
21
|
|
|
23
22
|
export const SyncStage = {
|
|
23
|
+
/**
|
|
24
|
+
* first frame
|
|
25
|
+
*/
|
|
24
26
|
init: SYNC_STAGE_INIT,
|
|
27
|
+
/**
|
|
28
|
+
* 2nd frame, response to init
|
|
29
|
+
*/
|
|
25
30
|
ack: SYNC_STAGE_ACK,
|
|
26
|
-
|
|
31
|
+
/**
|
|
32
|
+
* exchanging/negotiating ibgibs
|
|
33
|
+
*/
|
|
27
34
|
delta: SYNC_STAGE_DELTA,
|
|
35
|
+
/**
|
|
36
|
+
* final phases of sync
|
|
37
|
+
*/
|
|
28
38
|
commit: SYNC_STAGE_COMMIT,
|
|
29
39
|
} satisfies { [key: string]: SyncStage };
|
|
40
|
+
// #endregion SyncStage
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { extractErrorMsg } from "@ibgib/helper-gib/dist/helpers/utils-helper.mjs";
|
|
1
|
+
import { extractErrorMsg, getUUID } from "@ibgib/helper-gib/dist/helpers/utils-helper.mjs";
|
|
2
2
|
import { IbGib_V1 } from "@ibgib/ts-gib/dist/V1/types.mjs";
|
|
3
3
|
import { Ib } from "@ibgib/ts-gib/dist/types.mjs";
|
|
4
|
+
import { validateIbGibIntrinsically } from "@ibgib/ts-gib/dist/V1/validate-helper.mjs";
|
|
4
5
|
|
|
5
6
|
import { GLOBAL_LOG_A_LOT } from "../core-constants.mjs";
|
|
6
7
|
import { SYNC_ATOM, SYNC_MSG_REL8N_NAME } from "./sync-constants.mjs";
|
|
7
|
-
import { SyncData_V1, SyncIb_V1, SyncIbGib_V1 } from "./sync-types.mjs";
|
|
8
|
+
import { isValidSyncConflictStrategy, SYNC_CONFLICT_STRATEGY_VALID_VALUES, SyncData_V1, SyncIb_V1, SyncIbGib_V1, SyncSagaFrameDependencyGraph } from "./sync-types.mjs";
|
|
8
9
|
import { IbGibSpaceAny } from "../witness/space/space-base-v1.mjs";
|
|
9
10
|
import { getFromSpace } from "../witness/space/space-helper.mjs";
|
|
10
11
|
import { IbGibSpaceResultData, IbGibSpaceResultIbGib, IbGibSpaceResultRel8ns } from "../witness/space/space-types.mjs";
|
|
12
|
+
import { KeystoneIbGib_V1 } from "../keystone/keystone-types.mjs";
|
|
11
13
|
|
|
12
14
|
const logalot = GLOBAL_LOG_A_LOT;
|
|
13
15
|
|
|
@@ -69,142 +71,212 @@ export async function parseSyncIb({
|
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
/**
|
|
72
|
-
*
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
* @returns the name for a tempSpace in the sync
|
|
75
|
+
*/
|
|
76
|
+
export async function getTempSpaceName(): Promise<string> {
|
|
77
|
+
const uuid = await getUUID();
|
|
78
|
+
return `tmp_sync_space_${uuid.substring(0, 8)}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* UNTESTED
|
|
83
|
+
*
|
|
84
|
+
* Checks if an {@link olderAddr} is the address of a past frame in the ibgib
|
|
85
|
+
* with {@link newerAddr}.
|
|
76
86
|
*/
|
|
77
87
|
export async function isPastFrame({
|
|
78
88
|
olderAddr,
|
|
79
89
|
newerAddr,
|
|
80
90
|
space,
|
|
81
|
-
inMemoryGraph,
|
|
82
91
|
}: {
|
|
83
|
-
olderAddr: string,
|
|
84
|
-
newerAddr: string,
|
|
85
|
-
space
|
|
86
|
-
inMemoryGraph?: { [addr: string]: IbGib_V1 },
|
|
92
|
+
olderAddr: string,
|
|
93
|
+
newerAddr: string,
|
|
94
|
+
space: IbGibSpaceAny,
|
|
87
95
|
}): Promise<boolean> {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (inMemoryGraph) {
|
|
92
|
-
// Optimization: Iterate the graph values (or keys) and see if olderAddr is in any 'past'
|
|
93
|
-
// Actually we need to traverse from newerAddr back to olderAddr using the graph.
|
|
94
|
-
|
|
95
|
-
const queue = [newerAddr];
|
|
96
|
-
const visited = new Set<string>();
|
|
97
|
-
|
|
98
|
-
while (queue.length > 0) {
|
|
99
|
-
const currentAddr = queue.shift()!;
|
|
100
|
-
if (visited.has(currentAddr)) continue;
|
|
101
|
-
visited.add(currentAddr);
|
|
102
|
-
|
|
103
|
-
if (currentAddr === olderAddr) return true;
|
|
104
|
-
|
|
105
|
-
const node = inMemoryGraph[currentAddr];
|
|
106
|
-
// If node not in memory graph, we can't traverse further in memory.
|
|
107
|
-
// If we have space, we could fallback, but usually mixed mode is tricky.
|
|
108
|
-
// For now, if provided inMemoryGraph, assume it contains the relevant segment.
|
|
109
|
-
if (!node && space) {
|
|
110
|
-
// optional fallback to space if allowed?
|
|
111
|
-
// User requirement: "at most we are looking... in dependency graph".
|
|
112
|
-
// So let's fallback if space provided.
|
|
113
|
-
const res = await getFromSpace({ space, addr: currentAddr });
|
|
114
|
-
if (res.success && res.ibGibs?.length) {
|
|
115
|
-
const spaceNode = res.ibGibs[0];
|
|
116
|
-
if (spaceNode.rel8ns && spaceNode.rel8ns.past) {
|
|
117
|
-
for (const pastAddr of spaceNode.rel8ns.past) {
|
|
118
|
-
if (!visited.has(pastAddr)) queue.push(pastAddr);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
continue;
|
|
123
|
-
} else if (!node) {
|
|
124
|
-
continue; // Dead end in memory
|
|
125
|
-
}
|
|
96
|
+
const lc = `[${isPastFrame.name}]`;
|
|
97
|
+
try {
|
|
98
|
+
if (logalot) { console.log(`${lc} starting... (I: 4b3548cbc9a2eb749f447ed82fdcf826)`); }
|
|
126
99
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
}
|
|
100
|
+
// quick check...
|
|
101
|
+
if (olderAddr === newerAddr) {
|
|
102
|
+
return true; /* <<<< returns early */
|
|
132
103
|
}
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Fallback to purely space-based traversal if no memory graph
|
|
137
|
-
if (!space) { throw new Error(`Must provide either space or inMemoryGraph for ancestry check.`); }
|
|
138
104
|
|
|
139
|
-
|
|
140
|
-
|
|
105
|
+
// diff, so get the actual ibGib
|
|
106
|
+
let newerIbGib: IbGib_V1;
|
|
107
|
+
const res = await getFromSpace({ space, addr: newerAddr });
|
|
108
|
+
if (res.success && res.ibGibs?.length === 1) {
|
|
109
|
+
newerIbGib = res.ibGibs[0];
|
|
110
|
+
} else {
|
|
111
|
+
throw new Error(`couldn't get newerAddr (${newerAddr}) from space (${space.ib}). (E: 36c758c22b181b2c89a1cd28937a6826)`);
|
|
112
|
+
}
|
|
141
113
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
114
|
+
if (!newerIbGib.rel8ns) {
|
|
115
|
+
console.warn(`${lc} newerIbGib.rel8ns falsy? newerAddr: ${newerAddr}. (W: 6f920811f7080281189f767813814826)`);
|
|
116
|
+
return false; /* <<<< returns early */
|
|
117
|
+
}
|
|
146
118
|
|
|
147
|
-
|
|
119
|
+
const pastAddrs = newerIbGib.rel8ns.past ?? [];
|
|
120
|
+
if (pastAddrs.length === 0) {
|
|
121
|
+
return false; /* <<<< returns early */
|
|
122
|
+
}
|
|
148
123
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const node = res.ibGibs[0];
|
|
152
|
-
if (node.rel8ns && node.rel8ns.past) {
|
|
153
|
-
for (const pastAddr of node.rel8ns.past) {
|
|
154
|
-
if (!visited.has(pastAddr)) queue.push(pastAddr);
|
|
155
|
-
}
|
|
124
|
+
if (pastAddrs.includes(olderAddr)) {
|
|
125
|
+
return true; /* <<<< returns early */
|
|
156
126
|
}
|
|
127
|
+
|
|
128
|
+
// at this point, for most ibgibs we could leave it here. But
|
|
129
|
+
// conceivably, the past could be a linked rel8n. so recurse on the
|
|
130
|
+
// oldest in the past
|
|
131
|
+
|
|
132
|
+
const oldestAddrInThisPast = pastAddrs[0];
|
|
133
|
+
const resRecurse = await isPastFrame({
|
|
134
|
+
olderAddr,
|
|
135
|
+
newerAddr: oldestAddrInThisPast,
|
|
136
|
+
space,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
return resRecurse;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
142
|
+
throw error;
|
|
143
|
+
} finally {
|
|
144
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
157
145
|
}
|
|
158
146
|
|
|
159
|
-
return false;
|
|
160
147
|
}
|
|
161
148
|
|
|
162
149
|
/**
|
|
163
150
|
* Gets a shallow dependency graph for a Sync Saga Frame.
|
|
164
|
-
*
|
|
151
|
+
*
|
|
165
152
|
* DOES NOT GET THE ENTIRE DEPENDENCY FRAME (INCLUDING PAST).
|
|
166
|
-
*
|
|
153
|
+
*
|
|
167
154
|
* Unlike standard `getDependencyGraph`, this does NOT traverse `ancestor` (history) or `past`.
|
|
168
155
|
* It only retrieves the *content* of the current frame:
|
|
169
156
|
* 1. The Frame itself.
|
|
170
157
|
* 2. The Message Stone(s) (`rel8ns.msg`).
|
|
171
|
-
* 3. The Identity (`rel8ns.identity`).
|
|
172
|
-
*
|
|
158
|
+
* 3. The Identity(s) (`rel8ns.identity`).
|
|
159
|
+
*
|
|
173
160
|
* This is used for efficient transmission of the "Current Step" without re-sending the entire history.
|
|
174
161
|
*/
|
|
175
|
-
export async function
|
|
176
|
-
|
|
177
|
-
|
|
162
|
+
export async function getSyncSagaFrameDependencyGraph({
|
|
163
|
+
sagaIbGib,
|
|
164
|
+
localSpace,
|
|
178
165
|
}: {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}): Promise<
|
|
182
|
-
const lc = `[${
|
|
183
|
-
const result: IbGib_V1[] = [ibGib];
|
|
166
|
+
sagaIbGib: SyncIbGib_V1,
|
|
167
|
+
localSpace: IbGibSpaceAny,
|
|
168
|
+
}): Promise<SyncSagaFrameDependencyGraph> {
|
|
169
|
+
const lc = `[${getSyncSagaFrameDependencyGraph.name}]`;
|
|
184
170
|
|
|
185
171
|
// Helper to fetch and push
|
|
186
|
-
const
|
|
187
|
-
const
|
|
188
|
-
if (
|
|
189
|
-
|
|
172
|
+
const fnGet = async (addrs: string[]) => {
|
|
173
|
+
const resGet = await getFromSpace({ space: localSpace, addrs });
|
|
174
|
+
if (resGet.success && resGet.ibGibs?.length === addrs.length) {
|
|
175
|
+
return resGet.ibGibs!;
|
|
190
176
|
} else {
|
|
191
177
|
const resIbGib =
|
|
192
|
-
|
|
193
|
-
if (!resIbGib.data) { throw new Error(`(UNEXPECTED)
|
|
178
|
+
resGet.rawResultIbGib as IbGibSpaceResultIbGib<IbGib_V1, IbGibSpaceResultData, IbGibSpaceResultRel8ns>
|
|
179
|
+
if (!resIbGib.data) { throw new Error(`(UNEXPECTED) resGet.rawResultIbGib.data falsy? (E: c26c681d2f831fc537ba6f48fee36d26)`); }
|
|
194
180
|
throw new Error(`(UNEXPECTED) couldn't find addrs? addrsNotFound: ${resIbGib.data.addrsNotFound}? (E: 43b7b5a6ad982715c8f3eed69bfa0d26)`);
|
|
195
181
|
}
|
|
196
182
|
};
|
|
197
183
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
184
|
+
const validationErrors = await validateSyncSagaFrame({ sagaIbGib });
|
|
185
|
+
if (validationErrors.length > 0) {
|
|
186
|
+
throw new Error(`invalid sync sagaIbGib. validationErrors: ${validationErrors} (E: 19f9e8c9643858ff41312b62293d2126)`);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (!sagaIbGib.rel8ns) { throw new Error(`(UNEXPECTED) validated sagaIbGib.rel8ns falsy? (E: 73af48be8bbf271ec5cf78187ce8c826)`); }
|
|
190
|
+
|
|
191
|
+
// msg stones
|
|
192
|
+
const msgStoneAddrs = sagaIbGib.rel8ns[SYNC_MSG_REL8N_NAME]!;
|
|
193
|
+
const msgStones = await fnGet(msgStoneAddrs);
|
|
194
|
+
|
|
195
|
+
// identities
|
|
196
|
+
const identities = sagaIbGib.rel8ns.identity && sagaIbGib.rel8ns.identity.length > 0 ?
|
|
197
|
+
await fnGet(sagaIbGib.rel8ns.identity) as KeystoneIbGib_V1[] :
|
|
198
|
+
[];
|
|
199
|
+
|
|
200
|
+
return { sagaIbGib, msgStones, identities, };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* only validates this single frame. does not validate any dependencies or past.
|
|
205
|
+
* @returns array of errors, empty if valid
|
|
206
|
+
*/
|
|
207
|
+
export async function validateSyncSagaFrame({
|
|
208
|
+
sagaIbGib
|
|
209
|
+
}: {
|
|
210
|
+
sagaIbGib: SyncIbGib_V1;
|
|
211
|
+
}): Promise<string[]> {
|
|
212
|
+
const lc = `[${validateSyncSagaFrame.name}]`;
|
|
213
|
+
try {
|
|
214
|
+
if (logalot) { console.log(`${lc} starting... (I: dac978e9ec5820f128fbbff817b82826)`); }
|
|
215
|
+
|
|
216
|
+
const errors: string[] = await validateIbGibIntrinsically({ ibGib: sagaIbGib }) ?? [];
|
|
217
|
+
|
|
218
|
+
// intrinsic errors are a non-starter
|
|
219
|
+
if (errors.length > 0) { return errors; /* <<<< returns early */ }
|
|
220
|
+
|
|
221
|
+
if (sagaIbGib.data) {
|
|
222
|
+
const { data } = sagaIbGib;
|
|
223
|
+
|
|
224
|
+
if (data.uuid) {
|
|
225
|
+
// todo: validate uuid
|
|
226
|
+
} else {
|
|
227
|
+
errors.push(`data.uuid required (E: aa24eeda7b88d22e5832a2e8083c0826)`);
|
|
228
|
+
}
|
|
229
|
+
if (data.timestamp) {
|
|
230
|
+
// todo: validate timestamp
|
|
231
|
+
} else {
|
|
232
|
+
errors.push(`data.timestamp required (E: 9c82a88548f4b63c38687428754b3826)`);
|
|
233
|
+
}
|
|
234
|
+
if (data.timestampMs || data.timestampMs === 0) {
|
|
235
|
+
// todo: validate timestampMs
|
|
236
|
+
} else {
|
|
237
|
+
errors.push(`data.timestampMs required (E: 9c82a88548f4b63c38687428754b3826)`);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (data.conflictStrategy) {
|
|
241
|
+
if (!isValidSyncConflictStrategy(data.conflictStrategy)) {
|
|
242
|
+
errors.push(`data.conflictStrategy (${data.conflictStrategy}) is invalid. Must be one of "${SYNC_CONFLICT_STRATEGY_VALID_VALUES}". (E: 6223a8813b688fa2c8644fa8a491bf26)`)
|
|
243
|
+
}
|
|
244
|
+
} else {
|
|
245
|
+
errors.push(`data.conflictStrategy required (E: 9c82a88548f4b63c38687428754b3826)`);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (data.expirationTimestamp) {
|
|
249
|
+
// todo: validate expirationTimestamp
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (data.errors) {
|
|
253
|
+
// todo: validate errors?
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (data.successCount) {
|
|
257
|
+
// todo: validate successCount
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
} else {
|
|
261
|
+
errors.push(`sagaIbGib.data falsy (E: 4de5e8de589d0af7245600fb4fe30926)`);
|
|
202
262
|
}
|
|
203
|
-
|
|
204
|
-
if (
|
|
205
|
-
|
|
263
|
+
|
|
264
|
+
if (sagaIbGib.rel8ns) {
|
|
265
|
+
const msgAddrs = sagaIbGib.rel8ns[SYNC_MSG_REL8N_NAME];
|
|
266
|
+
if (msgAddrs && msgAddrs.length > 0) {
|
|
267
|
+
// todo: validate the syncmsg addr?
|
|
268
|
+
} else {
|
|
269
|
+
errors.push(`sagaIbGib.rel8ns[SYNC_MSG_REL8N_NAME] required. (E: df648dc18148e718682acb4842ecf826)`);
|
|
270
|
+
}
|
|
271
|
+
} else {
|
|
272
|
+
errors.push(`sagaIbGib.rel8ns falsy (E: da37aa492a7275b68a5e1912c7a5e126)`);
|
|
206
273
|
}
|
|
207
|
-
}
|
|
208
274
|
|
|
209
|
-
|
|
275
|
+
return errors;
|
|
276
|
+
} catch (error) {
|
|
277
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
278
|
+
throw error;
|
|
279
|
+
} finally {
|
|
280
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
281
|
+
}
|
|
210
282
|
}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
respecfully, ifWeMight, iReckon, ifWe
|
|
10
10
|
} from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
|
|
11
11
|
const maam = `[${import.meta.url}]`, sir = maam;
|
|
12
|
-
import { delay } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
12
|
+
import { clone, delay } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
13
13
|
import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
|
|
14
14
|
import { Factory_V1 } from '@ibgib/ts-gib/dist/V1/index.mjs';
|
|
15
15
|
|
|
@@ -20,6 +20,7 @@ import { InnerSpace_V1 } from '../witness/space/inner-space/inner-space-v1.mjs';
|
|
|
20
20
|
import { DEFAULT_INNER_SPACE_DATA_V1 } from '../witness/space/inner-space/inner-space-types.mjs';
|
|
21
21
|
import { getTestKeystoneServiceHelper } from '../agent-helpers.mjs';
|
|
22
22
|
import { SyncPeerInnerspace_V1 } from './sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs';
|
|
23
|
+
import { SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1 } from './sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.mjs';
|
|
23
24
|
|
|
24
25
|
const lc = `[sync-innerspace-constants.respec]`;
|
|
25
26
|
|
|
@@ -69,15 +70,13 @@ await respecfully(sir, `Sync Constants (No TJP)`, async () => {
|
|
|
69
70
|
const senderCoordinator = new SyncSagaCoordinator(mockKeystone);
|
|
70
71
|
const receiverCoordinator = new SyncSagaCoordinator(mockKeystone);
|
|
71
72
|
|
|
72
|
-
const peer = new SyncPeerInnerspace_V1(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
const peer = new SyncPeerInnerspace_V1(clone(SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1));
|
|
74
|
+
await peer.initialized;
|
|
75
|
+
await peer.initializeSender({
|
|
76
|
+
senderSpace: sourceSpace, // "Client"
|
|
77
|
+
receiverSpace: destSpace, // "Server"
|
|
78
|
+
receiverCoordinator,
|
|
76
79
|
receiverMetaspace: metaspace,
|
|
77
|
-
receiverTempSpace: 0 as any, // placeholder this is wrong
|
|
78
|
-
senderTempSpace: 0 as any, // placeholder this is wrong
|
|
79
|
-
}, {
|
|
80
|
-
classname: SyncPeerInnerspace_V1.name,
|
|
81
80
|
});
|
|
82
81
|
|
|
83
82
|
// 4. Sync C1 (First Pass)
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
ifWeMight
|
|
10
10
|
} from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
|
|
11
11
|
const maam = `[${import.meta.url}]`, sir = maam;
|
|
12
|
-
import { delay, extractErrorMsg, pretty } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
12
|
+
import { clone, delay, extractErrorMsg, pretty } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
13
13
|
import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
|
|
14
14
|
import { getDependencyGraph } from '../common/other/graph-helper.mjs';
|
|
15
15
|
|
|
@@ -22,6 +22,7 @@ import { mut8Timeline } from '../timeline/timeline-api.mjs';
|
|
|
22
22
|
import { DEFAULT_INNER_SPACE_DATA_V1 } from '../witness/space/inner-space/inner-space-types.mjs';
|
|
23
23
|
import { toDto } from '../common/other/ibgib-helper.mjs';
|
|
24
24
|
import { SyncPeerInnerspace_V1 } from './sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs';
|
|
25
|
+
import { SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1 } from './sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.mjs';
|
|
25
26
|
|
|
26
27
|
const logalot = true;
|
|
27
28
|
const lc = `[sync-innerspace-deep-updates.respec]`;
|
|
@@ -100,15 +101,13 @@ await respecfully(sir, `Sync InnerSpaces (Deep Updates)`, async () => {
|
|
|
100
101
|
const senderCoordinator = new SyncSagaCoordinator(mockKeystone);
|
|
101
102
|
const receiverCoordinator = new SyncSagaCoordinator(mockKeystone);
|
|
102
103
|
|
|
103
|
-
const peer = new SyncPeerInnerspace_V1(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
const peer = new SyncPeerInnerspace_V1(clone(SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1));
|
|
105
|
+
await peer.initialized;
|
|
106
|
+
await peer.initializeSender({
|
|
107
|
+
senderSpace: sourceSpace, // "Client"
|
|
108
|
+
receiverSpace: destSpace, // "Server"
|
|
109
|
+
receiverCoordinator,
|
|
107
110
|
receiverMetaspace: metaspace,
|
|
108
|
-
receiverTempSpace: 0 as any,
|
|
109
|
-
senderTempSpace: 0 as any,
|
|
110
|
-
}, {
|
|
111
|
-
classname: SyncPeerInnerspace_V1.name,
|
|
112
111
|
});
|
|
113
112
|
|
|
114
113
|
// 4. Run Sync
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
ifWeMight
|
|
10
10
|
} from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
|
|
11
11
|
const maam = `[${import.meta.url}]`, sir = maam;
|
|
12
|
-
import { delay, extractErrorMsg, pretty } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
12
|
+
import { clone, delay, extractErrorMsg, pretty } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
13
13
|
import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
|
|
14
14
|
import { getDependencyGraph } from '../common/other/graph-helper.mjs';
|
|
15
15
|
|
|
@@ -22,6 +22,7 @@ import { mut8Timeline } from '../timeline/timeline-api.mjs';
|
|
|
22
22
|
import { DEFAULT_INNER_SPACE_DATA_V1 } from '../witness/space/inner-space/inner-space-types.mjs';
|
|
23
23
|
import { toDto } from '../common/other/ibgib-helper.mjs';
|
|
24
24
|
import { SyncPeerInnerspace_V1 } from './sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs';
|
|
25
|
+
import { SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1 } from './sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.mjs';
|
|
25
26
|
|
|
26
27
|
const logalot = true;
|
|
27
28
|
const lc = `[sync-innerspace-dest-ahead.respec]`;
|
|
@@ -110,15 +111,13 @@ await respecfully(sir, `Sync InnerSpaces (Dest Ahead)`, async () => {
|
|
|
110
111
|
const senderCoordinator = new SyncSagaCoordinator(mockKeystone);
|
|
111
112
|
const receiverCoordinator = new SyncSagaCoordinator(mockKeystone);
|
|
112
113
|
|
|
113
|
-
const peer = new SyncPeerInnerspace_V1(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
const peer = new SyncPeerInnerspace_V1(clone(SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1));
|
|
115
|
+
await peer.initialized;
|
|
116
|
+
await peer.initializeSender({
|
|
117
|
+
senderSpace: sourceSpace, // "Client"
|
|
118
|
+
receiverSpace: destSpace, // "Server"
|
|
119
|
+
receiverCoordinator,
|
|
117
120
|
receiverMetaspace: metaspace,
|
|
118
|
-
receiverTempSpace: 0 as any,// this is wrong just getting to build
|
|
119
|
-
senderTempSpace: 0 as any, // this is wrong just getting to build
|
|
120
|
-
}, {
|
|
121
|
-
classname: SyncPeerInnerspace_V1.name
|
|
122
121
|
});
|
|
123
122
|
|
|
124
123
|
// 4. Run Sync (Source Pushes V1)
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
ifWeMight
|
|
10
10
|
} from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
|
|
11
11
|
const maam = `[${import.meta.url}]`, sir = maam;
|
|
12
|
-
import { delay, extractErrorMsg, pretty } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
12
|
+
import { clone, delay, extractErrorMsg, pretty } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
13
13
|
import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
|
|
14
14
|
import { getDependencyGraph } from '../common/other/graph-helper.mjs';
|
|
15
15
|
|
|
@@ -22,6 +22,7 @@ import { mut8Timeline } from '../timeline/timeline-api.mjs';
|
|
|
22
22
|
import { DEFAULT_INNER_SPACE_DATA_V1 } from '../witness/space/inner-space/inner-space-types.mjs';
|
|
23
23
|
import { toDto } from '../common/other/ibgib-helper.mjs';
|
|
24
24
|
import { SyncPeerInnerspace_V1 } from './sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs';
|
|
25
|
+
import { SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1 } from './sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.mjs';
|
|
25
26
|
|
|
26
27
|
const logalot = true;
|
|
27
28
|
const lc = `[sync-innerspace-multiple-timelines.respec]`;
|
|
@@ -104,15 +105,13 @@ await respecfully(sir, `Sync InnerSpaces (Multiple Timelines)`, async () => {
|
|
|
104
105
|
const senderCoordinator = new SyncSagaCoordinator(mockKeystone);
|
|
105
106
|
const receiverCoordinator = new SyncSagaCoordinator(mockKeystone);
|
|
106
107
|
|
|
107
|
-
const peer = new SyncPeerInnerspace_V1(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
const peer = new SyncPeerInnerspace_V1(clone(SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1));
|
|
109
|
+
await peer.initialized;
|
|
110
|
+
await peer.initializeSender({
|
|
111
|
+
senderSpace: sourceSpace, // "Client"
|
|
112
|
+
receiverSpace: destSpace, // "Server"
|
|
113
|
+
receiverCoordinator,
|
|
111
114
|
receiverMetaspace: metaspace,
|
|
112
|
-
receiverTempSpace: 0 as any,
|
|
113
|
-
senderTempSpace: 0 as any,
|
|
114
|
-
}, {
|
|
115
|
-
classname: SyncPeerInnerspace_V1.name,
|
|
116
115
|
});
|
|
117
116
|
|
|
118
117
|
// 4. Run Sync (Push Both)
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
ifWeMight
|
|
10
10
|
} from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
|
|
11
11
|
const maam = `[${import.meta.url}]`, sir = maam;
|
|
12
|
-
import { delay, extractErrorMsg, pretty } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
12
|
+
import { clone, delay, extractErrorMsg, pretty } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
13
13
|
import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
|
|
14
14
|
import { getDependencyGraph } from '../common/other/graph-helper.mjs';
|
|
15
15
|
|
|
@@ -22,6 +22,7 @@ import { mut8Timeline } from '../timeline/timeline-api.mjs';
|
|
|
22
22
|
import { DEFAULT_INNER_SPACE_DATA_V1 } from '../witness/space/inner-space/inner-space-types.mjs';
|
|
23
23
|
import { toDto } from '../common/other/ibgib-helper.mjs';
|
|
24
24
|
import { SyncPeerInnerspace_V1 } from './sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs';
|
|
25
|
+
import { SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1 } from './sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.mjs';
|
|
25
26
|
|
|
26
27
|
const logalot = true;
|
|
27
28
|
const lc = `[sync-innerspace-partial-update.respec]`;
|
|
@@ -112,18 +113,14 @@ await respecfully(sir, `Sync InnerSpaces (Partial Update)`, async () => {
|
|
|
112
113
|
const senderCoordinator = new SyncSagaCoordinator(mockKeystone);
|
|
113
114
|
const receiverCoordinator = new SyncSagaCoordinator(mockKeystone);
|
|
114
115
|
|
|
115
|
-
const peer = new SyncPeerInnerspace_V1(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
const peer = new SyncPeerInnerspace_V1(clone(SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1));
|
|
117
|
+
await peer.initialized;
|
|
118
|
+
await peer.initializeSender({
|
|
119
|
+
senderSpace: sourceSpace, // "Client"
|
|
120
|
+
receiverSpace: destSpace, // "Server"
|
|
121
|
+
receiverCoordinator,
|
|
119
122
|
receiverMetaspace: metaspace,
|
|
120
|
-
|
|
121
|
-
senderTempSpace: 0 as any,
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
classname: SyncPeerInnerspace_V1.name,
|
|
125
|
-
}
|
|
126
|
-
);
|
|
123
|
+
});
|
|
127
124
|
|
|
128
125
|
// 4. Run Sync (Source Pushes V2)
|
|
129
126
|
console.log(`${lc} Running Sync...`);
|