@ibgib/core-gib 0.1.27 → 0.1.29
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/meta-stone/meta-stone-helper.d.mts.map +1 -1
- package/dist/common/meta-stone/meta-stone-helper.mjs +19 -7
- package/dist/common/meta-stone/meta-stone-helper.mjs.map +1 -1
- package/dist/sync/sync-helpers.d.mts +11 -5
- package/dist/sync/sync-helpers.d.mts.map +1 -1
- package/dist/sync/sync-helpers.mjs +33 -9
- package/dist/sync/sync-helpers.mjs.map +1 -1
- package/dist/sync/sync-innerspace-constants.respec.mjs +36 -36
- package/dist/sync/sync-innerspace-constants.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace-deep-updates.respec.mjs +5 -3
- package/dist/sync/sync-innerspace-deep-updates.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs +2 -2
- package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace-partial-update.respec.mjs +3 -3
- package/dist/sync/sync-innerspace-partial-update.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace.respec.mjs +49 -20
- package/dist/sync/sync-innerspace.respec.mjs.map +1 -1
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.d.mts +0 -9
- 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 +13 -42
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs.map +1 -1
- package/dist/sync/sync-peer/sync-peer-v1.mjs +2 -2
- package/dist/sync/sync-peer/sync-peer-v1.mjs.map +1 -1
- package/dist/sync/sync-saga-coordinator.d.mts +23 -159
- package/dist/sync/sync-saga-coordinator.d.mts.map +1 -1
- package/dist/sync/sync-saga-coordinator.mjs +508 -172
- package/dist/sync/sync-saga-coordinator.mjs.map +1 -1
- package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts +12 -17
- package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts.map +1 -1
- package/dist/sync/sync-types.d.mts +18 -23
- package/dist/sync/sync-types.d.mts.map +1 -1
- package/dist/sync/sync-types.mjs +15 -21
- package/dist/sync/sync-types.mjs.map +1 -1
- package/package.json +1 -1
- package/src/common/meta-stone/meta-stone-helper.mts +17 -7
- package/src/sync/sync-helpers.mts +36 -13
- package/src/sync/sync-innerspace-constants.respec.mts +39 -39
- package/src/sync/sync-innerspace-deep-updates.respec.mts +6 -6
- package/src/sync/sync-innerspace-multiple-timelines.respec.mts +1 -1
- package/src/sync/sync-innerspace-partial-update.respec.mts +2 -2
- package/src/sync/sync-innerspace.respec.mts +20 -19
- package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mts +11 -58
- package/src/sync/sync-peer/sync-peer-v1.mts +2 -2
- package/src/sync/sync-saga-coordinator.mts +472 -191
- package/src/sync/sync-saga-message/sync-saga-message-types.mts +13 -18
- package/src/sync/sync-types.mts +26 -33
- package/test_output.log +0 -0
- package/tmp.md +170 -62
|
@@ -7,11 +7,12 @@ import { getIbGibAddr } from "@ibgib/ts-gib/dist/helper.mjs";
|
|
|
7
7
|
|
|
8
8
|
import { GLOBAL_LOG_A_LOT } from "../core-constants.mjs";
|
|
9
9
|
import { SYNC_ATOM, SYNC_MSG_REL8N_NAME } from "./sync-constants.mjs";
|
|
10
|
-
import { isValidSyncConflictStrategy, SYNC_CONFLICT_STRATEGY_VALID_VALUES, SyncData_V1,
|
|
10
|
+
import { isValidSyncConflictStrategy, SYNC_CONFLICT_STRATEGY_VALID_VALUES, SyncData_V1, SyncSagaFrameOrigin, SyncIb_V1, SyncIbGib_V1, SyncSagaFrameDependencyGraph } from "./sync-types.mjs";
|
|
11
11
|
import { IbGibSpaceAny } from "../witness/space/space-base-v1.mjs";
|
|
12
12
|
import { getFromSpace, putInSpace } from "../witness/space/space-helper.mjs";
|
|
13
13
|
import { IbGibSpaceResultData, IbGibSpaceResultIbGib, IbGibSpaceResultRel8ns } from "../witness/space/space-types.mjs";
|
|
14
14
|
import { KeystoneIbGib_V1 } from "../keystone/keystone-types.mjs";
|
|
15
|
+
import { SyncSagaMessageCommitData_V1, SyncSagaMessageIbGib_V1 } from "./sync-saga-message/sync-saga-message-types.mjs";
|
|
15
16
|
|
|
16
17
|
const logalot = GLOBAL_LOG_A_LOT;
|
|
17
18
|
|
|
@@ -192,7 +193,7 @@ export async function getSyncSagaFrameDependencyGraph({
|
|
|
192
193
|
|
|
193
194
|
// msg stones
|
|
194
195
|
const msgStoneAddrs = sagaIbGib.rel8ns[SYNC_MSG_REL8N_NAME]!;
|
|
195
|
-
const msgStones = await fnGet(msgStoneAddrs);
|
|
196
|
+
const msgStones = await fnGet(msgStoneAddrs) as SyncSagaMessageIbGib_V1[];
|
|
196
197
|
|
|
197
198
|
// identities
|
|
198
199
|
const identities = sagaIbGib.rel8ns.identity && sagaIbGib.rel8ns.identity.length > 0 ?
|
|
@@ -242,11 +243,10 @@ export async function getFullSyncSagaHistory({
|
|
|
242
243
|
resGraphs.push(graph);
|
|
243
244
|
}
|
|
244
245
|
|
|
245
|
-
// my attempt at lining up
|
|
246
|
+
// the \n are my my attempt at lining up an indent
|
|
246
247
|
if (logalot) { console.log(`${lc} resGraphs:...\n ${pretty(resGraphs).split('\n').join('\n ')}\n...(I: d8e11827d88a3454d887ff05fb4ff526)`); }
|
|
247
248
|
|
|
248
249
|
return resGraphs;
|
|
249
|
-
|
|
250
250
|
} catch (error) {
|
|
251
251
|
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
252
252
|
throw error;
|
|
@@ -336,6 +336,23 @@ export async function validateSyncSagaFrame({
|
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
338
|
|
|
339
|
+
export async function validateFullSyncSagaHistory({
|
|
340
|
+
history,
|
|
341
|
+
}: {
|
|
342
|
+
history: SyncSagaFrameDependencyGraph[],
|
|
343
|
+
}): Promise<string[]> {
|
|
344
|
+
const lc = `[${validateFullSyncSagaHistory.name}]`;
|
|
345
|
+
try {
|
|
346
|
+
if (logalot) { console.log(`${lc} starting... (I: df02b802f6989096b8d8f728e2c0a526)`); }
|
|
347
|
+
console.error(`${lc} NAG ERROR (NOT THROWN) need to implement more validation on full saga history. (E: 9bfcc9247a1c783fd361a4a8216fef26)`)
|
|
348
|
+
return [];
|
|
349
|
+
} catch (error) {
|
|
350
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
351
|
+
throw error;
|
|
352
|
+
} finally {
|
|
353
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
354
|
+
}
|
|
355
|
+
}
|
|
339
356
|
|
|
340
357
|
export async function putInSpace_dnasThenNonDnas({
|
|
341
358
|
ibGibs,
|
|
@@ -343,7 +360,7 @@ export async function putInSpace_dnasThenNonDnas({
|
|
|
343
360
|
}: {
|
|
344
361
|
ibGibs: IbGib_V1[],
|
|
345
362
|
space: IbGibSpaceAny,
|
|
346
|
-
}): Promise<
|
|
363
|
+
}): Promise<{ payload_Dnas: IbGib_V1[], payload_NonDnas: IbGib_V1[] }> {
|
|
347
364
|
const lc = `[${putInSpace_dnasThenNonDnas.name}]`;
|
|
348
365
|
try {
|
|
349
366
|
if (logalot) { console.log(`${lc} starting... (I: aa3ab828402836b3914800a8ffa1b826)`); }
|
|
@@ -363,10 +380,16 @@ export async function putInSpace_dnasThenNonDnas({
|
|
|
363
380
|
}
|
|
364
381
|
|
|
365
382
|
// dnas are the simplest and we store those first...
|
|
366
|
-
|
|
383
|
+
if (payload_Dnas.length > 0) {
|
|
384
|
+
await putInSpace({ ibGibs: payload_Dnas, isDna: true, space, });
|
|
385
|
+
}
|
|
367
386
|
|
|
368
387
|
// then put all non-dnas ("regular" ibgibs) in the space
|
|
369
|
-
|
|
388
|
+
if (payload_NonDnas.length > 0) {
|
|
389
|
+
await putInSpace({ ibGibs: payload_NonDnas, isDna: false, space, });
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return { payload_Dnas, payload_NonDnas };
|
|
370
393
|
} catch (error) {
|
|
371
394
|
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
372
395
|
throw error;
|
|
@@ -376,14 +399,14 @@ export async function putInSpace_dnasThenNonDnas({
|
|
|
376
399
|
}
|
|
377
400
|
|
|
378
401
|
/**
|
|
379
|
-
* @see {@link
|
|
402
|
+
* @see {@link SyncSagaFrameOrigin}
|
|
380
403
|
*/
|
|
381
|
-
export function
|
|
404
|
+
export function getSyncSagaFrameOrigin({
|
|
382
405
|
sagaFrame,
|
|
383
406
|
}: {
|
|
384
407
|
sagaFrame: SyncIbGib_V1,
|
|
385
|
-
}):
|
|
386
|
-
const lc = `[${
|
|
408
|
+
}): SyncSagaFrameOrigin {
|
|
409
|
+
const lc = `[${getSyncSagaFrameOrigin.name}]`;
|
|
387
410
|
try {
|
|
388
411
|
if (logalot) { console.log(`${lc} starting... (I: 93521332d0dd2f5e88398b7db95e8126)`); }
|
|
389
412
|
if (!sagaFrame) { throw new Error(`(UNEXPECTED) sagaFrame falsy? (E: 01fb28be6668d88ea49bb298c739c926)`); }
|
|
@@ -395,9 +418,9 @@ export function getExecutionContext({
|
|
|
395
418
|
// odd => receiver
|
|
396
419
|
|
|
397
420
|
if (modulo === 0) {
|
|
398
|
-
return
|
|
421
|
+
return SyncSagaFrameOrigin.sender;
|
|
399
422
|
} else if (modulo === 1) {
|
|
400
|
-
return
|
|
423
|
+
return SyncSagaFrameOrigin.receiver;
|
|
401
424
|
} else {
|
|
402
425
|
throw new Error(`(UNEXPECTED) modulo is neither 0 nor 1? my logic sucks! This was way too defensive on my part... (E: 559488a2eef8d17b57079ca8886ee826)`);
|
|
403
426
|
}
|
|
@@ -55,8 +55,8 @@ await respecfully(sir, `Sync Constants (No TJP)`, async () => {
|
|
|
55
55
|
// 2. Create Constant (C1) in Source
|
|
56
56
|
// Factory_V1.constant returns Promise<IbGib_V1>, not { newIbGib: ... }
|
|
57
57
|
const c1 = await Factory_V1.constant({
|
|
58
|
-
ib: 'constant_c1',
|
|
59
58
|
parentPrimitiveIb: 'root',
|
|
59
|
+
ib: 'constant_c1',
|
|
60
60
|
data: { some: 'data' },
|
|
61
61
|
});
|
|
62
62
|
const addrC1 = getIbGibAddr({ ibGib: c1 });
|
|
@@ -81,7 +81,7 @@ await respecfully(sir, `Sync Constants (No TJP)`, async () => {
|
|
|
81
81
|
|
|
82
82
|
// 4. Sync C1 (First Pass)
|
|
83
83
|
let resSync = await senderCoordinator.sync({
|
|
84
|
-
peer
|
|
84
|
+
peer,
|
|
85
85
|
localSpace: sourceSpace,
|
|
86
86
|
metaspace: metaspace,
|
|
87
87
|
domainIbGibs: [c1],
|
|
@@ -94,43 +94,43 @@ await respecfully(sir, `Sync Constants (No TJP)`, async () => {
|
|
|
94
94
|
const getC1Dest = await getFromSpace({ space: destSpace, addr: addrC1 });
|
|
95
95
|
iReckon(sir, getC1Dest.success && !!getC1Dest.ibGibs![0]).asTo('Dest has C1 after sync').isGonnaBeTrue();
|
|
96
96
|
|
|
97
|
-
// 5. Sync C1 (Second Pass - Idempotency / Smart Diff)
|
|
98
|
-
// Should NOT send payload again.
|
|
99
|
-
resSync = await senderCoordinator.sync({
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
});
|
|
106
|
-
await resSync.done;
|
|
107
|
-
iReckon(sir, true).asTo('Sync execution 2 (idempotent) completes').isGonnaBeTrue();
|
|
108
|
-
|
|
109
|
-
// 6. Create "Constant with Dependency" (C2 -> C1)
|
|
110
|
-
const c2 = await Factory_V1.constant({
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
});
|
|
117
|
-
const addrC2 = getIbGibAddr({ ibGib: c2 });
|
|
118
|
-
await putInSpace({ space: sourceSpace, ibGibs: [c2] });
|
|
119
|
-
|
|
120
|
-
// Sync C2
|
|
121
|
-
resSync = await senderCoordinator.sync({
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
});
|
|
128
|
-
await resSync.done;
|
|
129
|
-
iReckon(sir, true).asTo('Sync C2 completes').isGonnaBeTrue();
|
|
130
|
-
|
|
131
|
-
// Verify C2 in Dest
|
|
132
|
-
const getC2Dest = await getFromSpace({ space: destSpace, addr: addrC2 });
|
|
133
|
-
iReckon(sir, getC2Dest.success).asTo('Dest has C2').isGonnaBeTrue();
|
|
97
|
+
// // 5. Sync C1 (Second Pass - Idempotency / Smart Diff)
|
|
98
|
+
// // Should NOT send payload again.
|
|
99
|
+
// resSync = await senderCoordinator.sync({
|
|
100
|
+
// peer: peer,
|
|
101
|
+
// localSpace: sourceSpace,
|
|
102
|
+
// metaspace: metaspace,
|
|
103
|
+
// domainIbGibs: [c1],
|
|
104
|
+
// useSessionIdentity: false,
|
|
105
|
+
// });
|
|
106
|
+
// await resSync.done;
|
|
107
|
+
// iReckon(sir, true).asTo('Sync execution 2 (idempotent) completes').isGonnaBeTrue();
|
|
108
|
+
|
|
109
|
+
// // 6. Create "Constant with Dependency" (C2 -> C1)
|
|
110
|
+
// const c2 = await Factory_V1.constant({
|
|
111
|
+
// ib: 'constant_c2',
|
|
112
|
+
// parentPrimitiveIb: 'root',
|
|
113
|
+
// rel8ns: {
|
|
114
|
+
// link: [addrC1], // C2 links to C1
|
|
115
|
+
// },
|
|
116
|
+
// });
|
|
117
|
+
// const addrC2 = getIbGibAddr({ ibGib: c2 });
|
|
118
|
+
// await putInSpace({ space: sourceSpace, ibGibs: [c2] });
|
|
119
|
+
|
|
120
|
+
// // Sync C2
|
|
121
|
+
// resSync = await senderCoordinator.sync({
|
|
122
|
+
// peer: peer,
|
|
123
|
+
// localSpace: sourceSpace,
|
|
124
|
+
// metaspace: metaspace,
|
|
125
|
+
// domainIbGibs: [c2],
|
|
126
|
+
// useSessionIdentity: false,
|
|
127
|
+
// });
|
|
128
|
+
// await resSync.done;
|
|
129
|
+
// iReckon(sir, true).asTo('Sync C2 completes').isGonnaBeTrue();
|
|
130
|
+
|
|
131
|
+
// // Verify C2 in Dest
|
|
132
|
+
// const getC2Dest = await getFromSpace({ space: destSpace, addr: addrC2 });
|
|
133
|
+
// iReckon(sir, getC2Dest.success).asTo('Dest has C2').isGonnaBeTrue();
|
|
134
134
|
|
|
135
135
|
});
|
|
136
136
|
});
|
|
@@ -11,20 +11,20 @@ import {
|
|
|
11
11
|
const maam = `[${import.meta.url}]`, sir = maam;
|
|
12
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
|
-
import { getDependencyGraph } from '../common/other/graph-helper.mjs';
|
|
15
14
|
|
|
15
|
+
import { GLOBAL_LOG_A_LOT } from '../core-constants.mjs';
|
|
16
|
+
import { getDependencyGraph } from '../common/other/graph-helper.mjs';
|
|
16
17
|
import { SyncSagaCoordinator } from './sync-saga-coordinator.mjs';
|
|
17
|
-
import {
|
|
18
|
+
import { getFromSpace } from '../witness/space/space-helper.mjs';
|
|
18
19
|
import { Metaspace_Innerspace } from '../witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.mjs';
|
|
19
20
|
import { InnerSpace_V1 } from '../witness/space/inner-space/inner-space-v1.mjs';
|
|
20
21
|
import { createTimelineRootHelper, getTestKeystoneServiceHelper } from '../agent-helpers.mjs';
|
|
21
22
|
import { mut8Timeline } from '../timeline/timeline-api.mjs';
|
|
22
23
|
import { DEFAULT_INNER_SPACE_DATA_V1 } from '../witness/space/inner-space/inner-space-types.mjs';
|
|
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
25
|
import { SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1 } from './sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.mjs';
|
|
26
26
|
|
|
27
|
-
const logalot = true;
|
|
27
|
+
const logalot = GLOBAL_LOG_A_LOT || true;
|
|
28
28
|
const lc = `[sync-innerspace-deep-updates.respec]`;
|
|
29
29
|
|
|
30
30
|
await respecfully(sir, `Sync InnerSpaces (Deep Updates)`, async () => {
|
|
@@ -121,14 +121,14 @@ await respecfully(sir, `Sync InnerSpaces (Deep Updates)`, async () => {
|
|
|
121
121
|
localSpace: sourceSpace,
|
|
122
122
|
metaspace: metaspace,
|
|
123
123
|
domainIbGibs: [commentV2], // Sync the TIP
|
|
124
|
+
useSessionIdentity: false,
|
|
124
125
|
});
|
|
125
|
-
|
|
126
126
|
await resSync.done;
|
|
127
127
|
|
|
128
128
|
// 5. Verify Dest
|
|
129
129
|
console.log(`${lc} Verifying Destination...`);
|
|
130
130
|
|
|
131
|
-
await
|
|
131
|
+
await ifWeMight(sir, `verify deep timeline present`, async () => {
|
|
132
132
|
// Verify Tip (V2)
|
|
133
133
|
const getV2 = await getFromSpace({ space: destSpace, addr: addrV2 });
|
|
134
134
|
iReckon(sir, getV2.success).asTo('Tip V2 present').isGonnaBeTrue();
|
|
@@ -130,7 +130,7 @@ await respecfully(sir, `Sync InnerSpaces (Multiple Timelines)`, async () => {
|
|
|
130
130
|
// 5. Verify Dest
|
|
131
131
|
console.log(`${lc} Verifying Destination...`);
|
|
132
132
|
|
|
133
|
-
await
|
|
133
|
+
await ifWeMight(sir, `verify timelines present`, async () => {
|
|
134
134
|
// Verify A
|
|
135
135
|
const getA = await getFromSpace({ space: destSpace, addr: addrA });
|
|
136
136
|
iReckon(sir, getA.success).asTo('Timeline A present').isGonnaBeTrue();
|
|
@@ -98,7 +98,7 @@ await respecfully(sir, `Sync InnerSpaces (Partial Update)`, async () => {
|
|
|
98
98
|
// Transfer Root & V1 to Dest (Simulate previous sync)
|
|
99
99
|
await putInSpace({ space: destSpace, ibGibs: [root, v1] });
|
|
100
100
|
|
|
101
|
-
await
|
|
101
|
+
await ifWeMight(sir, 'verify setup', async () => {
|
|
102
102
|
// Verify Dest has V1
|
|
103
103
|
const checkV1 = await getFromSpace({ space: destSpace, addr: getIbGibAddr({ ibGib: v1 }) });
|
|
104
104
|
iReckon(sir, checkV1.success).asTo('Dest has V1').isGonnaBeTrue();
|
|
@@ -137,7 +137,7 @@ await respecfully(sir, `Sync InnerSpaces (Partial Update)`, async () => {
|
|
|
137
137
|
// 5. Verify Dest (Should now have V2)
|
|
138
138
|
console.log(`${lc} Verifying Destination...`);
|
|
139
139
|
|
|
140
|
-
await
|
|
140
|
+
await ifWeMight(sir, `verify dest updated`, async () => {
|
|
141
141
|
// Verify Tip (V2)
|
|
142
142
|
const getV2 = await getFromSpace({ space: destSpace, addr: addrV2 });
|
|
143
143
|
iReckon(sir, getV2.success).asTo('V2 present in Dest').isGonnaBeTrue();
|
|
@@ -13,6 +13,7 @@ const maam = `[${import.meta.url}]`, sir = maam;
|
|
|
13
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
|
+
import { GLOBAL_LOG_A_LOT } from '../core-constants.mjs';
|
|
16
17
|
import { SyncSagaCoordinator } from './sync-saga-coordinator.mjs';
|
|
17
18
|
import { getFromSpace } from '../witness/space/space-helper.mjs';
|
|
18
19
|
import { Metaspace_Innerspace } from '../witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.mjs';
|
|
@@ -25,7 +26,7 @@ import { fnObs } from '../common/pubsub/observer/observer-helper.mjs';
|
|
|
25
26
|
import { SyncPeerInnerspace_V1 } from './sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs';
|
|
26
27
|
import { SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1 } from './sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.mjs';
|
|
27
28
|
|
|
28
|
-
const logalot =
|
|
29
|
+
const logalot = GLOBAL_LOG_A_LOT;
|
|
29
30
|
const lc = `[sync-innerspace.respec]`;
|
|
30
31
|
|
|
31
32
|
await respecfully(sir, `Sync InnerSpaces`, async () => {
|
|
@@ -47,7 +48,7 @@ await respecfully(sir, `Sync InnerSpaces`, async () => {
|
|
|
47
48
|
const defaultLocalUserSpace = await metaspace.getLocalUserSpace({ lock: false });
|
|
48
49
|
if (!defaultLocalUserSpace) { throw new Error(`(UNEXPECTED) defaultLocalUserSpace falsy? (E: 56f019430b29b45147e0caa4d5931826)`); }
|
|
49
50
|
await defaultLocalUserSpace.initialized;
|
|
50
|
-
console.log(`defaultLocalUserSpace: ${pretty(toDto({ ibGib: defaultLocalUserSpace }))}`);
|
|
51
|
+
if (logalot) { console.log(`defaultLocalUserSpace: ${pretty(toDto({ ibGib: defaultLocalUserSpace }))}`); }
|
|
51
52
|
|
|
52
53
|
sourceSpace = new InnerSpace_V1({
|
|
53
54
|
...DEFAULT_INNER_SPACE_DATA_V1,
|
|
@@ -56,7 +57,7 @@ await respecfully(sir, `Sync InnerSpaces`, async () => {
|
|
|
56
57
|
description: 'source test space',
|
|
57
58
|
});
|
|
58
59
|
await sourceSpace.initialized;
|
|
59
|
-
console.log(`sourceSpace: ${pretty(toDto({ ibGib: sourceSpace }))}`);
|
|
60
|
+
if (logalot) { console.log(`sourceSpace: ${pretty(toDto({ ibGib: sourceSpace }))}`); }
|
|
60
61
|
// await (sourceSpace as any).initialize(); // DO NOT AWAIT THIS. THIS IS AUTOMATICALLY AWAITED IN PLUMBING
|
|
61
62
|
|
|
62
63
|
destSpace = new InnerSpace_V1({
|
|
@@ -66,11 +67,11 @@ await respecfully(sir, `Sync InnerSpaces`, async () => {
|
|
|
66
67
|
description: 'dest test space',
|
|
67
68
|
});
|
|
68
69
|
await destSpace.initialized;
|
|
69
|
-
console.log(`destSpace: ${pretty(toDto({ ibGib: destSpace }))}`);
|
|
70
|
+
if (logalot) { console.log(`destSpace: ${pretty(toDto({ ibGib: destSpace }))}`); }
|
|
70
71
|
// await (destSpace as any).initialized; // DO NOT AWAIT THIS. THIS IS AUTOMATICALLY AWAITED IN PLUMBING
|
|
71
72
|
|
|
72
73
|
// 2. Seed Source Data
|
|
73
|
-
console.log(`${lc} Creating data in Source...`);
|
|
74
|
+
if (logalot) { console.log(`${lc} Creating data in Source...`); }
|
|
74
75
|
const root = await createTimelineRootHelper({
|
|
75
76
|
ib: 'timeline_root',
|
|
76
77
|
// data: { type: 'root', n: 0 }, // DO NOT TRY TO MANUALLY SET n
|
|
@@ -90,11 +91,11 @@ await respecfully(sir, `Sync InnerSpaces`, async () => {
|
|
|
90
91
|
const childAddr = getIbGibAddr({ ibGib: child });
|
|
91
92
|
|
|
92
93
|
// 3. Setup Coordinators & Peer
|
|
93
|
-
console.log(`${lc} Setting up Coordinators...`);
|
|
94
|
+
if (logalot) { console.log(`${lc} Setting up Coordinators...`); }
|
|
94
95
|
const mockKeystone = await getTestKeystoneServiceHelper();
|
|
95
96
|
// const identity = await (mockKeystone as any).getIdentity(); // SKIP IDENTITY FOR INITIAL TESTING SIMPLICITY
|
|
96
97
|
|
|
97
|
-
// Sender Coordinator
|
|
98
|
+
// Sender Coordinator
|
|
98
99
|
const senderCoordinator = new SyncSagaCoordinator(mockKeystone);
|
|
99
100
|
|
|
100
101
|
// Receiver Coordinator
|
|
@@ -114,7 +115,7 @@ await respecfully(sir, `Sync InnerSpaces`, async () => {
|
|
|
114
115
|
});
|
|
115
116
|
|
|
116
117
|
// 4. Run Sync
|
|
117
|
-
console.log(`${lc} Running Sync...`);
|
|
118
|
+
if (logalot) { console.log(`${lc} Running Sync...`); }
|
|
118
119
|
const resSync = await senderCoordinator.sync({
|
|
119
120
|
peer: peer,
|
|
120
121
|
localSpace: sourceSpace,
|
|
@@ -123,7 +124,7 @@ await respecfully(sir, `Sync InnerSpaces`, async () => {
|
|
|
123
124
|
useSessionIdentity: false,
|
|
124
125
|
}); // Type cast if needed until we align optional params
|
|
125
126
|
|
|
126
|
-
console.log(`${lc} resSync: ${pretty(resSync)}`);
|
|
127
|
+
if (logalot) { console.log(`${lc} resSync: ${pretty(resSync)}`); }
|
|
127
128
|
|
|
128
129
|
const sublc = `${lc}[updates$]`;
|
|
129
130
|
/**
|
|
@@ -132,44 +133,44 @@ await respecfully(sir, `Sync InnerSpaces`, async () => {
|
|
|
132
133
|
*/
|
|
133
134
|
const subscription = await resSync.updates$.subscribe(fnObs({
|
|
134
135
|
next: async (ctxIbGib) => {
|
|
135
|
-
console.log(`${sublc} next fired`);
|
|
136
|
+
if (logalot) { console.log(`${sublc} next fired`); }
|
|
136
137
|
},
|
|
137
138
|
error: async (e) => {
|
|
138
|
-
console.log(`${sublc} error fired`);
|
|
139
|
+
if (logalot) { console.log(`${sublc} error fired`); }
|
|
139
140
|
},
|
|
140
141
|
complete: async () => {
|
|
141
|
-
console.log(`${sublc} complete fired`);
|
|
142
|
+
if (logalot) { console.log(`${sublc} complete fired`); }
|
|
142
143
|
},
|
|
143
144
|
}));
|
|
144
145
|
|
|
145
|
-
console.log(`${lc} awaiting resSync.done`)
|
|
146
|
+
if (logalot) { console.log(`${lc} awaiting resSync.done`) }
|
|
146
147
|
await resSync.done;
|
|
147
148
|
|
|
148
149
|
|
|
149
150
|
// todo: add iReckon assertions about resSync
|
|
150
151
|
|
|
151
152
|
// 5. Verify Dest
|
|
152
|
-
console.log(`${lc} Verifying Destination...`);
|
|
153
|
+
if (logalot) { console.log(`${lc} Verifying Destination...`); }
|
|
153
154
|
try {
|
|
154
155
|
const getChildInDest = await getFromSpace({ space: destSpace, addr: childAddr });
|
|
155
156
|
|
|
156
|
-
await
|
|
157
|
+
await ifWeMight(sir, `verify success getChildInDest`, async () => {
|
|
157
158
|
iReckon(sir, getChildInDest.success).asTo('Child present in Dest').isGonnaBeTrue();
|
|
158
159
|
});
|
|
159
160
|
|
|
160
|
-
await
|
|
161
|
+
await ifWeMight(sir, `verify getChildInDest.ibGibs`, async () => {
|
|
161
162
|
const firstChild = getChildInDest.ibGibs?.[0];
|
|
162
|
-
console.log(`${lc} firstChild: ${pretty(firstChild)}`);
|
|
163
|
+
if (logalot) { console.log(`${lc} firstChild: ${pretty(firstChild)}`); }
|
|
163
164
|
iReckon(sir, firstChild?.data?.n).asTo('Child content matches').isGonnaBe(2);
|
|
164
165
|
});
|
|
165
166
|
|
|
166
167
|
} catch (error) {
|
|
167
|
-
await
|
|
168
|
+
await ifWeMight(sir, `doh`, async () => {
|
|
168
169
|
// hack here I'm getting tired...
|
|
169
170
|
iReckon(sir, true).asTo(`error: ${extractErrorMsg(error)}`).isGonnaBeFalse();
|
|
170
171
|
});
|
|
171
172
|
} finally {
|
|
172
|
-
console.log(`${lc} Test complete.`);
|
|
173
|
+
if (logalot) { console.log(`${lc} Test complete.`); }
|
|
173
174
|
}
|
|
174
175
|
});
|
|
175
176
|
|
|
@@ -4,30 +4,22 @@
|
|
|
4
4
|
|
|
5
5
|
import { delay, extractErrorMsg, pretty, unique } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
6
6
|
import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
|
|
7
|
-
import { IbGibAddr } from '@ibgib/ts-gib/dist/types.mjs';
|
|
8
|
-
import { IbGib_V1, IbGibData_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
|
|
9
|
-
import { isDna } from '@ibgib/ts-gib/dist/V1/transforms/transform-helper.mjs';
|
|
10
7
|
|
|
11
8
|
import { GLOBAL_LOG_A_LOT } from '../../../core-constants.mjs';
|
|
12
9
|
import { IbGibSpaceAny } from '../../../witness/space/space-base-v1.mjs';
|
|
13
10
|
import { SyncPeer_V1 } from '../sync-peer-v1.mjs';
|
|
14
|
-
import {
|
|
11
|
+
import { putInSpace, registerNewIbGib } from '../../../witness/space/space-helper.mjs';
|
|
15
12
|
import { SyncSagaContextIbGib_V1, } from '../../sync-saga-context/sync-saga-context-types.mjs';
|
|
16
13
|
import { SyncPeerInnerspaceData_V1, SyncPeerInnerspaceIbGib_V1, SyncPeerInnerspaceOptions, SyncPeerInnerspaceRel8ns_V1 } from './sync-peer-innerspace-types.mjs';
|
|
17
14
|
import { MetaspaceService } from '../../../witness/space/metaspace/metaspace-types.mjs';
|
|
18
15
|
import { SyncSagaCoordinator } from '../../sync-saga-coordinator.mjs';
|
|
19
|
-
import { IbGibSpaceResultData } from '../../../witness/space/space-types.mjs';
|
|
20
16
|
import { InitializeSyncPeerOpts } from '../sync-peer-types.mjs';
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import { SyncSagaMessageAckData_V1, SyncSagaMessageCommitData_V1, SyncSagaMessageData_V1, SyncSagaMessageDeltaData_V1, SyncSagaMessageInitData_V1 } from '../../sync-saga-message/sync-saga-message-types.mjs';
|
|
24
|
-
import { getExecutionContext, getSyncSagaFrameDependencyGraph, putInSpace_dnasThenNonDnas } from '../../sync-helpers.mjs';
|
|
25
|
-
import { splitPerTjpAndOrDna, toDto } from '../../../common/other/ibgib-helper.mjs';
|
|
26
|
-
import { SyncExecutionContext } from '../../sync-types.mjs';
|
|
17
|
+
import { getSyncSagaFrameDependencyGraph, putInSpace_dnasThenNonDnas } from '../../sync-helpers.mjs';
|
|
18
|
+
import { toDto } from '../../../common/other/ibgib-helper.mjs';
|
|
27
19
|
|
|
28
20
|
|
|
29
|
-
const logalot = GLOBAL_LOG_A_LOT
|
|
30
|
-
const logalotControlDomain =
|
|
21
|
+
const logalot = GLOBAL_LOG_A_LOT;
|
|
22
|
+
const logalotControlDomain = false;
|
|
31
23
|
const lcControlDomain = '[ControlDomain]';
|
|
32
24
|
|
|
33
25
|
/**
|
|
@@ -112,6 +104,8 @@ export class SyncPeerInnerspace_V1 extends SyncPeer_V1<InitializeSyncPeerInnersp
|
|
|
112
104
|
protected async sendContextRequest(context: SyncSagaContextIbGib_V1): Promise<SyncSagaContextIbGib_V1 | undefined> {
|
|
113
105
|
const lc = `${this.lc}[${this.sendContextRequest.name}]`;
|
|
114
106
|
try {
|
|
107
|
+
if (logalot) { console.log(`${lc} starting... (I: bab87f15dea77cd4892bd8a8d2e65826)`); }
|
|
108
|
+
|
|
115
109
|
if (!this.opts) { throw new Error(`(UNEXPECTED) this.opts falsy? (E: d8b1348e3233810128999596b1fa5826)`); }
|
|
116
110
|
|
|
117
111
|
const {
|
|
@@ -141,7 +135,7 @@ export class SyncPeerInnerspace_V1 extends SyncPeer_V1<InitializeSyncPeerInnersp
|
|
|
141
135
|
// let localTempSpace: IbGibSpaceAny;
|
|
142
136
|
// let remoteSpace: IbGibSpaceAny;
|
|
143
137
|
// let remoteTempSpace: IbGibSpaceAny;
|
|
144
|
-
// if (
|
|
138
|
+
// if (getSyncSagaFrameOrigin({ sagaFrame: context.sagaFrame }) === SyncSagaFrameOrigin.sender) {
|
|
145
139
|
// localSpace = senderSpace;
|
|
146
140
|
// localTempSpace = senderTempSpace;
|
|
147
141
|
// remoteSpace = receiverSpace;
|
|
@@ -173,6 +167,7 @@ export class SyncPeerInnerspace_V1 extends SyncPeer_V1<InitializeSyncPeerInnersp
|
|
|
173
167
|
const payloadIbGibsControl = [
|
|
174
168
|
...identities, msg, sagaFrame, context
|
|
175
169
|
].map(x => toDto({ ibGib: x }));
|
|
170
|
+
if (logalot) { console.log(`${lc} putting into receiverSpace: ${receiverSpace.ib} (I: 1ba18b14a26bdd0e7800da4812898826)`); }
|
|
176
171
|
await putInSpace({
|
|
177
172
|
ibGibs: payloadIbGibsControl,
|
|
178
173
|
space: receiverSpace,
|
|
@@ -187,6 +182,7 @@ export class SyncPeerInnerspace_V1 extends SyncPeer_V1<InitializeSyncPeerInnersp
|
|
|
187
182
|
}
|
|
188
183
|
|
|
189
184
|
if (context.payloadIbGibsDomain && context.payloadIbGibsDomain.length > 0) {
|
|
185
|
+
if (logalot) { console.log(`${lc} putting into receiverTempSpace: ${receiverTempSpace.ib} (I: d0cea920b818393d68118bc8a1515526)`); }
|
|
190
186
|
await putInSpace_dnasThenNonDnas({
|
|
191
187
|
ibGibs: context.payloadIbGibsDomain,
|
|
192
188
|
space: receiverTempSpace,
|
|
@@ -289,52 +285,9 @@ export class SyncPeerInnerspace_V1 extends SyncPeer_V1<InitializeSyncPeerInnersp
|
|
|
289
285
|
} catch (error) {
|
|
290
286
|
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
291
287
|
throw error;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Helper to copy single ibgib from A to B.
|
|
297
|
-
*/
|
|
298
|
-
protected async transfer({
|
|
299
|
-
addrs,
|
|
300
|
-
from,
|
|
301
|
-
to
|
|
302
|
-
}: {
|
|
303
|
-
addrs: IbGibAddr[],
|
|
304
|
-
from: IbGibSpaceAny,
|
|
305
|
-
to: IbGibSpaceAny
|
|
306
|
-
}): Promise<void> {
|
|
307
|
-
const lc = `${this.lc}[${this.transfer.name}]`;
|
|
308
|
-
try {
|
|
309
|
-
if (logalot) { console.log(`${lc} starting... (I: f1145dc75a461afc885efe984f08d426)`); }
|
|
310
|
-
|
|
311
|
-
console.error(`${lc} NAG ERROR (DOES NOT THROW): This needs to be adapted to be able to pull from multiple spaces. IOW, the 'from' param should be an array of spaces. This is because we need to be checking both durable and temp spaces when querying. (E: 823f3856b8b82ece080868e85ded0826)`)
|
|
312
|
-
|
|
313
|
-
// 1. Get from Source
|
|
314
|
-
const resGet = await getFromSpace({ space: from, addrs });
|
|
315
|
-
if (!resGet.success || !resGet.ibGibs || resGet.ibGibs.length !== addrs.length) {
|
|
316
|
-
if (!resGet.rawResultIbGib) { throw new Error(`(UNEXPECTED) resGet.rawResultIbGib falsy? (E: b829f827a378890bcf7dc3d41c908826)`); }
|
|
317
|
-
if (!resGet.rawResultIbGib.data) { throw new Error(`(UNEXPECTED) resGet.rawResultIbGib.data falsy? (E: 8d15341d8fa8fc96297425e3c6e39226)`); }
|
|
318
|
-
const data = resGet.rawResultIbGib.data as IbGibSpaceResultData;
|
|
319
|
-
|
|
320
|
-
throw new Error(`${lc} Failed to get all ${addrs} from source space ${from.ib}. resGet.errorMsg: ${resGet.errorMsg}. failed info: ${JSON.stringify(data)} (E: 4ed3383573382920c80054d7c1024626)`);
|
|
321
|
-
}
|
|
322
|
-
const ibGibs = resGet.ibGibs.concat();
|
|
323
|
-
|
|
324
|
-
// 2. Put in Dest
|
|
325
|
-
// Note: putInSpace handles existence check usually, or we can check.
|
|
326
|
-
const resPut = await putInSpace({ space: to, ibGibs });
|
|
327
|
-
if (resPut.success) {
|
|
328
|
-
console.error(`${lc} NAG ERROR: (SORT OF AN ERROR, DID NOT THROW): is the sync peer responsible for calling registerNewIbGib?? I'm not sure at this point if that is true, rather, I think that it probably is NOT responsible for this. But I'm putting this error msg as a nag message until this is resolved. (E: 00086833e294ee834800046801c47826) `);
|
|
329
|
-
} else {
|
|
330
|
-
throw new Error(`ERROR: successfully got addrs (${addrs}) from space (${from.ib}), BUT failed to put into space (${to.ib}). resPut.errorMsg: ${resPut.errorMsg}. timedOut: ${resPut.timedOut}. (E: c1044e14cc1db72d28a2240819dab826)`);
|
|
331
|
-
}
|
|
332
|
-
} catch (error) {
|
|
333
|
-
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
334
|
-
throw error;
|
|
335
288
|
} finally {
|
|
336
289
|
if (logalot) { console.log(`${lc} complete.`); }
|
|
337
290
|
}
|
|
338
|
-
|
|
339
291
|
}
|
|
292
|
+
|
|
340
293
|
}
|
|
@@ -21,8 +21,8 @@ import { newupSubject } from '../../common/pubsub/subject/subject-helper.mjs';
|
|
|
21
21
|
import { authenticateContext, authorizeContext, validateContextAndSagaFrame } from '../sync-saga-context/sync-saga-context-helpers.mjs';
|
|
22
22
|
import { getFromSpace } from '../../witness/space/space-helper.mjs';
|
|
23
23
|
|
|
24
|
-
const logalot = GLOBAL_LOG_A_LOT
|
|
25
|
-
const logalotControlDomain =
|
|
24
|
+
const logalot = GLOBAL_LOG_A_LOT;
|
|
25
|
+
const logalotControlDomain = false;
|
|
26
26
|
const lcControlDomain = '[ControlDomain]';
|
|
27
27
|
|
|
28
28
|
/**
|