@ibgib/core-gib 0.1.21 → 0.1.23
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 +8 -0
- package/dist/common/other/graph-helper.d.mts.map +1 -1
- package/dist/common/other/graph-helper.mjs +31 -1
- package/dist/common/other/graph-helper.mjs.map +1 -1
- package/dist/sync/sync-conflict.respec.mjs +31 -28
- package/dist/sync/sync-conflict.respec.mjs.map +1 -1
- package/dist/sync/sync-constants.d.mts +21 -11
- package/dist/sync/sync-constants.d.mts.map +1 -1
- package/dist/sync/sync-constants.mjs +18 -6
- package/dist/sync/sync-constants.mjs.map +1 -1
- package/dist/sync/sync-helpers.d.mts +24 -15
- package/dist/sync/sync-helpers.d.mts.map +1 -1
- package/dist/sync/sync-helpers.mjs +163 -92
- package/dist/sync/sync-helpers.mjs.map +1 -1
- package/dist/sync/sync-innerspace-constants.respec.mjs +12 -7
- package/dist/sync/sync-innerspace-constants.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace-deep-updates.respec.mjs +12 -7
- package/dist/sync/sync-innerspace-deep-updates.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace-dest-ahead.respec.mjs +15 -10
- package/dist/sync/sync-innerspace-dest-ahead.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs +13 -7
- package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace-partial-update.respec.mjs +15 -7
- package/dist/sync/sync-innerspace-partial-update.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace.respec.mjs +13 -7
- package/dist/sync/sync-innerspace.respec.mjs.map +1 -1
- package/dist/sync/sync-peer/sync-peer-constants.d.mts +2 -0
- package/dist/sync/sync-peer/sync-peer-constants.d.mts.map +1 -0
- package/dist/sync/sync-peer/sync-peer-constants.mjs +2 -0
- package/dist/sync/sync-peer/sync-peer-constants.mjs.map +1 -0
- package/dist/sync/sync-peer/sync-peer-helpers.d.mts +2 -0
- package/dist/sync/sync-peer/sync-peer-helpers.d.mts.map +1 -0
- package/dist/sync/sync-peer/sync-peer-helpers.mjs +2 -0
- package/dist/sync/sync-peer/sync-peer-helpers.mjs.map +1 -0
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.d.mts +8 -0
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.d.mts.map +1 -0
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.mjs +8 -0
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.mjs.map +1 -0
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-helpers.d.mts +18 -0
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-helpers.d.mts.map +1 -0
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-helpers.mjs +54 -0
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-helpers.mjs.map +1 -0
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-types.d.mts +65 -0
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-types.d.mts.map +1 -0
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-types.mjs +5 -0
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-types.mjs.map +1 -0
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.d.mts +44 -0
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.d.mts.map +1 -0
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs +183 -0
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs.map +1 -0
- package/dist/sync/sync-peer/sync-peer-types.d.mts +28 -0
- package/dist/sync/sync-peer/sync-peer-types.d.mts.map +1 -1
- package/dist/sync/sync-peer/sync-peer-v1.d.mts +51 -9
- package/dist/sync/sync-peer/sync-peer-v1.d.mts.map +1 -1
- package/dist/sync/sync-peer/sync-peer-v1.mjs +244 -26
- package/dist/sync/sync-peer/sync-peer-v1.mjs.map +1 -1
- package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts +26 -10
- 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 +119 -30
- 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 +31 -22
- package/dist/sync/sync-saga-context/sync-saga-context-types.d.mts.map +1 -1
- package/dist/sync/sync-saga-context/sync-saga-context-types.mjs +1 -9
- package/dist/sync/sync-saga-context/sync-saga-context-types.mjs.map +1 -1
- package/dist/sync/sync-saga-coordinator.d.mts +81 -87
- package/dist/sync/sync-saga-coordinator.d.mts.map +1 -1
- package/dist/sync/sync-saga-coordinator.mjs +627 -571
- package/dist/sync/sync-saga-coordinator.mjs.map +1 -1
- package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts +105 -22
- package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts.map +1 -1
- package/dist/sync/sync-types.d.mts +56 -76
- package/dist/sync/sync-types.d.mts.map +1 -1
- package/dist/sync/sync-types.mjs +5 -0
- 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/dist/witness/light-witness-base-v1.d.mts.map +1 -1
- package/dist/witness/light-witness-base-v1.mjs +2 -0
- package/dist/witness/light-witness-base-v1.mjs.map +1 -1
- package/dist/witness/space/inner-space/inner-space-v1.mjs +1 -1
- package/dist/witness/space/inner-space/inner-space-v1.mjs.map +1 -1
- package/package.json +1 -1
- package/src/common/other/graph-helper.mts +26 -1
- package/src/sync/README.md +31 -22
- package/src/sync/sync-conflict.respec.mts +31 -26
- package/src/sync/sync-constants.mts +19 -9
- package/src/sync/sync-helpers.mts +173 -97
- package/src/sync/sync-innerspace-constants.respec.mts +12 -7
- package/src/sync/sync-innerspace-deep-updates.respec.mts +12 -7
- package/src/sync/sync-innerspace-dest-ahead.respec.mts +14 -9
- package/src/sync/sync-innerspace-multiple-timelines.respec.mts +13 -7
- package/src/sync/sync-innerspace-partial-update.respec.mts +15 -7
- package/src/sync/sync-innerspace.respec.mts +13 -7
- package/src/sync/sync-peer/sync-peer-constants.mts +0 -0
- package/src/sync/sync-peer/sync-peer-helpers.mts +0 -0
- package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.mts +8 -0
- package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-helpers.mts +72 -0
- package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-types.mts +72 -0
- package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mts +193 -0
- package/src/sync/sync-peer/sync-peer-types.mts +30 -1
- package/src/sync/sync-peer/sync-peer-v1.mts +229 -30
- package/src/sync/sync-saga-context/sync-saga-context-helpers.mts +140 -43
- package/src/sync/sync-saga-context/sync-saga-context-types.mts +34 -30
- package/src/sync/sync-saga-coordinator.mts +678 -660
- package/src/sync/sync-saga-message/sync-saga-message-types.mts +106 -22
- package/src/sync/sync-types.mts +59 -87
- package/src/timeline/timeline-api.mts +17 -10
- package/src/witness/light-witness-base-v1.mts +2 -1
- package/src/witness/space/inner-space/inner-space-v1.mts +1 -1
- package/test_output.log +0 -0
- package/tmp.md +62 -44
- package/dist/sync/sync-local-spaces.respec.d.mts +0 -2
- package/dist/sync/sync-local-spaces.respec.d.mts.map +0 -1
- package/dist/sync/sync-local-spaces.respec.mjs +0 -159
- package/dist/sync/sync-local-spaces.respec.mjs.map +0 -1
- package/dist/sync/sync-peer/sync-peer-innerspace-v1.d.mts +0 -42
- package/dist/sync/sync-peer/sync-peer-innerspace-v1.d.mts.map +0 -1
- package/dist/sync/sync-peer/sync-peer-innerspace-v1.mjs +0 -194
- package/dist/sync/sync-peer/sync-peer-innerspace-v1.mjs.map +0 -1
- package/dist/sync/sync-saga-coordinator.respec.d.mts +0 -2
- package/dist/sync/sync-saga-coordinator.respec.d.mts.map +0 -1
- package/dist/sync/sync-saga-coordinator.respec.mjs +0 -40
- package/dist/sync/sync-saga-coordinator.respec.mjs.map +0 -1
- package/src/sync/sync-local-spaces.respec.mts +0 -200
- package/src/sync/sync-peer/sync-peer-innerspace-v1.mts +0 -240
- package/src/sync/sync-saga-coordinator.respec.mts +0 -52
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module sync peer innerspace helpers
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { extractErrorMsg } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
6
|
+
import { Ib } from '@ibgib/ts-gib/dist/types.mjs';
|
|
7
|
+
|
|
8
|
+
import { SYNC_PEER_INNERSPACE_ATOM } from './sync-peer-innerspace-constants.mjs';
|
|
9
|
+
import { SyncPeerInnerspaceIb_V1, SyncPeerInnerspaceData_V1 } from './sync-peer-innerspace-types.mjs';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Constructs the standard 'ib' string for a Sync Peer Innerspace stone.
|
|
13
|
+
*/
|
|
14
|
+
export async function getSyncPeerInnerspaceIb({
|
|
15
|
+
data,
|
|
16
|
+
}: {
|
|
17
|
+
data: SyncPeerInnerspaceData_V1,
|
|
18
|
+
}): Promise<Ib> {
|
|
19
|
+
const lc = `[${getSyncPeerInnerspaceIb.name}]`;
|
|
20
|
+
try {
|
|
21
|
+
if (!data) { throw new Error(`data required (E: 7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d)`); }
|
|
22
|
+
|
|
23
|
+
if (!data.classname) { throw new Error(`invalid data. data.classname required. (E: 3aad38bfe23866c2d8c1ca66b03d9126)`); }
|
|
24
|
+
|
|
25
|
+
// sync_peer_innerspace
|
|
26
|
+
const ib = [
|
|
27
|
+
SYNC_PEER_INNERSPACE_ATOM,
|
|
28
|
+
data.classname,
|
|
29
|
+
].join(' ');
|
|
30
|
+
|
|
31
|
+
return ib;
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Parses a standard Sync Peer Innerspace 'ib' string.
|
|
40
|
+
*/
|
|
41
|
+
export async function parseSyncPeerInnerspaceIb({
|
|
42
|
+
ib,
|
|
43
|
+
}: {
|
|
44
|
+
ib: Ib,
|
|
45
|
+
}): Promise<SyncPeerInnerspaceIb_V1> {
|
|
46
|
+
const lc = `[${parseSyncPeerInnerspaceIb.name}]`;
|
|
47
|
+
try {
|
|
48
|
+
if (ib !== SYNC_PEER_INNERSPACE_ATOM) {
|
|
49
|
+
throw new Error(`Atom mismatch. Expected ${SYNC_PEER_INNERSPACE_ATOM}. Got ${ib}. (E: 8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e)`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const pieces = ib.split(' ');
|
|
53
|
+
|
|
54
|
+
if (pieces.length !== 2) {
|
|
55
|
+
throw new Error(`invalid ib. expected 2 pieces: atom and classname (E: f9c0c8067368444bac69f5777eeaa826)`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const [
|
|
59
|
+
atom,
|
|
60
|
+
classname
|
|
61
|
+
] = pieces;
|
|
62
|
+
|
|
63
|
+
if (atom !== SYNC_PEER_INNERSPACE_ATOM) {
|
|
64
|
+
throw new Error(`invalid ib. atom (${atom}) is expected to be ${SYNC_PEER_INNERSPACE_ATOM} (E: fda078ef3a0853629eb22e48a01a8826)`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return { atom, classname };
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module sync peer innerspace types
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { IbGibData_V1, IbGibRel8ns_V1, IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
|
|
6
|
+
|
|
7
|
+
import { MetaspaceService } from "../../../witness/space/metaspace/metaspace-types.mjs";
|
|
8
|
+
import { IbGibSpaceAny } from "../../../witness/space/space-base-v1.mjs";
|
|
9
|
+
import { SyncSagaCoordinator } from "../../sync-saga-coordinator.mjs";
|
|
10
|
+
import { SYNC_PEER_INNERSPACE_ATOM } from './sync-peer-innerspace-constants.mjs';
|
|
11
|
+
import { SyncPeerData_V1, SyncPeerRel8ns_V1 } from '../sync-peer-types.mjs';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Options for creating a SyncPeerInnerspace instance.
|
|
15
|
+
*/
|
|
16
|
+
export interface SyncPeerInnerspaceOptions {
|
|
17
|
+
/**
|
|
18
|
+
* The "receiver" durable space (not temp).
|
|
19
|
+
*
|
|
20
|
+
* ## notes
|
|
21
|
+
*
|
|
22
|
+
* when syncing/merging locally, we are working with two spaces and this
|
|
23
|
+
* acts as the "remote" space even though it's technically still local.
|
|
24
|
+
*/
|
|
25
|
+
receiverSpace: IbGibSpaceAny;
|
|
26
|
+
/**
|
|
27
|
+
* Coordinator for the "receiver".
|
|
28
|
+
*
|
|
29
|
+
* @see {@link receiverSpace} notes.
|
|
30
|
+
*/
|
|
31
|
+
receiverCoordinator: SyncSagaCoordinator;
|
|
32
|
+
/**
|
|
33
|
+
* Metaspace for the "receiver".
|
|
34
|
+
*
|
|
35
|
+
* @see {@link receiverSpace} notes.
|
|
36
|
+
*/
|
|
37
|
+
receiverMetaspace: MetaspaceService;
|
|
38
|
+
/**
|
|
39
|
+
* Temporary sync transaction space for the "receiver", for storage of
|
|
40
|
+
* domain ibgibs created/received throughout the sync saga until commit.
|
|
41
|
+
*
|
|
42
|
+
* @see {@link receiverSpace} notes.
|
|
43
|
+
*/
|
|
44
|
+
receiverTempSpace: IbGibSpaceAny;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface SyncPeerInnerspaceIb_V1 {
|
|
48
|
+
atom: typeof SYNC_PEER_INNERSPACE_ATOM;
|
|
49
|
+
/**
|
|
50
|
+
* @see {@link SyncPeerInnerspaceData_V1.classname}
|
|
51
|
+
*/
|
|
52
|
+
classname: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Data payload for the Sync Peer Innerspace.
|
|
57
|
+
*/
|
|
58
|
+
export interface SyncPeerInnerspaceData_V1 extends SyncPeerData_V1 {
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Relationships for the Sync Peer Innerspace.
|
|
63
|
+
*/
|
|
64
|
+
export interface SyncPeerInnerspaceRel8ns_V1 extends SyncPeerRel8ns_V1 {
|
|
65
|
+
// Currently no specific rel8ns needed beyond base
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The SyncPeerInnerspace ibGib.
|
|
70
|
+
*/
|
|
71
|
+
export interface SyncPeerInnerspaceIbGib_V1 extends IbGib_V1<SyncPeerInnerspaceData_V1, SyncPeerInnerspaceRel8ns_V1> {
|
|
72
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module SyncPeerInnerspace_V1
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { extractErrorMsg, unique } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
6
|
+
import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
|
|
7
|
+
import { IbGibAddr } from '@ibgib/ts-gib/dist/types.mjs';
|
|
8
|
+
|
|
9
|
+
import { GLOBAL_LOG_A_LOT } from '../../../core-constants.mjs';
|
|
10
|
+
import { IbGibSpaceAny } from '../../../witness/space/space-base-v1.mjs';
|
|
11
|
+
import { SyncPeer_V1 } from '../sync-peer-v1.mjs';
|
|
12
|
+
import { getFromSpace, putInSpace } from '../../../witness/space/space-helper.mjs';
|
|
13
|
+
import { SyncSagaContextIbGib_V1, } from '../../sync-saga-context/sync-saga-context-types.mjs';
|
|
14
|
+
import { SyncPeerInnerspaceData_V1, SyncPeerInnerspaceIbGib_V1, SyncPeerInnerspaceOptions, SyncPeerInnerspaceRel8ns_V1 } from './sync-peer-innerspace-types.mjs';
|
|
15
|
+
import { MetaspaceService } from '../../../witness/space/metaspace/metaspace-types.mjs';
|
|
16
|
+
import { SyncSagaCoordinator } from '../../sync-saga-coordinator.mjs';
|
|
17
|
+
import { IbGibSpaceResultData } from '../../../witness/space/space-types.mjs';
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
const logalot = GLOBAL_LOG_A_LOT || true;
|
|
21
|
+
const logalotControlDomain = true;
|
|
22
|
+
const lcControlDomain = '[ControlDomain]';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Concrete implementation of SyncPeer for local in-memory simulation (Innerspace to Innerspace).
|
|
26
|
+
*
|
|
27
|
+
* Acts as the "Network" layer, transferring data between two local spaces and
|
|
28
|
+
* executing the receiver's coordinator logic.
|
|
29
|
+
*/
|
|
30
|
+
export class SyncPeerInnerspace_V1 extends SyncPeer_V1 implements SyncPeerInnerspaceIbGib_V1 {
|
|
31
|
+
|
|
32
|
+
protected lc: string = `[${SyncPeerInnerspace_V1.name}]`;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* specific to innerspace
|
|
36
|
+
*/
|
|
37
|
+
protected receiverCoordinator: SyncSagaCoordinator;
|
|
38
|
+
/**
|
|
39
|
+
* specific to innerspace
|
|
40
|
+
*/
|
|
41
|
+
protected receiverMetaspace: MetaspaceService;
|
|
42
|
+
public receiverSpace: IbGibSpaceAny;
|
|
43
|
+
public receiverTempSpace: IbGibSpaceAny;
|
|
44
|
+
|
|
45
|
+
override get classname(): string {
|
|
46
|
+
return SyncPeerInnerspace_V1.name;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
constructor(
|
|
50
|
+
senderSpace: IbGibSpaceAny,
|
|
51
|
+
senderTempSpace: IbGibSpaceAny,
|
|
52
|
+
opts: SyncPeerInnerspaceOptions,
|
|
53
|
+
initialData: SyncPeerInnerspaceData_V1,
|
|
54
|
+
initialRel8ns?: SyncPeerInnerspaceRel8ns_V1,
|
|
55
|
+
) {
|
|
56
|
+
super(senderSpace, senderTempSpace, initialData, initialRel8ns);
|
|
57
|
+
const {
|
|
58
|
+
receiverCoordinator,
|
|
59
|
+
receiverMetaspace, receiverSpace, receiverTempSpace
|
|
60
|
+
} = opts;
|
|
61
|
+
|
|
62
|
+
this.receiverCoordinator = receiverCoordinator;
|
|
63
|
+
this.receiverMetaspace = receiverMetaspace;
|
|
64
|
+
this.receiverSpace = receiverSpace;
|
|
65
|
+
this.receiverTempSpace = receiverTempSpace;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
protected override async ensureReceiverTempSpace(): Promise<IbGibSpaceAny> {
|
|
69
|
+
if (!this.receiverTempSpace) {
|
|
70
|
+
const { receiverMetaspace } = this;
|
|
71
|
+
|
|
72
|
+
const uuid = crypto.randomUUID ? crypto.randomUUID() : Math.random().toString(36);
|
|
73
|
+
const tempSpaceName = `tmp_sync_recv_${uuid.substring(0, 8)}`;
|
|
74
|
+
const receiverTempSpace = await this.receiverMetaspace.createNewLocalSpace({
|
|
75
|
+
opts: {
|
|
76
|
+
allowCancel: false,
|
|
77
|
+
spaceName: tempSpaceName,
|
|
78
|
+
getFnPrompt: this.receiverMetaspace.getFnPrompt!,
|
|
79
|
+
logalot
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
if (!receiverTempSpace) { throw new Error(`(UNEXPECTED) receiverTempSpace falsy? couldn't create a temp space? (E: a6b8f86b0f58384b884a33b82924b826)`); }
|
|
83
|
+
await receiverTempSpace.initialized;
|
|
84
|
+
this.receiverTempSpace = receiverTempSpace;
|
|
85
|
+
}
|
|
86
|
+
return this.receiverTempSpace;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
protected async push(addrs: IbGibAddr[]): Promise<void> {
|
|
91
|
+
const lc = `${this.lc}[${this.push.name}]`;
|
|
92
|
+
try {
|
|
93
|
+
if (logalot) { console.log(`${lc} starting... (I: 07bce80be18f3259b8a311ed9c4da926)`); }
|
|
94
|
+
|
|
95
|
+
// silly defensive checks because this has been a ridiculous development cycle
|
|
96
|
+
if (!this.senderSpace) { throw new Error(`(UNEXPECTED) this.senderSpace falsy? (E: 503e288168f5d297f4d4e028bc538826)`); }
|
|
97
|
+
if (!this.receiverSpace) { throw new Error(`(UNEXPECTED) this.receiverSpace falsy? (E: 0bd7c1a0ba4868ac7a260e15b504e826)`); }
|
|
98
|
+
|
|
99
|
+
await this.transfer({ addrs, from: this.senderSpace, to: this.receiverSpace });
|
|
100
|
+
} catch (error) {
|
|
101
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
102
|
+
throw error;
|
|
103
|
+
} finally {
|
|
104
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
protected async pull(addrs: IbGibAddr[]): Promise<void> {
|
|
109
|
+
const lc = `${this.lc}[${this.pull.name}]`;
|
|
110
|
+
try {
|
|
111
|
+
if (logalot) { console.log(`${lc} starting... (I: b16a28ed0dc8f52f1838ee257d9b1126)`); }
|
|
112
|
+
|
|
113
|
+
// silly defensive checks because this has been a ridiculous development cycle
|
|
114
|
+
if (!this.receiverSpace) { throw new Error(`(UNEXPECTED) this.receiverSpace falsy? (E: bd2fdfa89ba4c89a185b68e9bb1f1c26)`); }
|
|
115
|
+
if (!this.senderTempSpace) { throw new Error(`(UNEXPECTED) this.senderTempSpace falsy? (E: b23fa55713f881493dac4a9835ac7326)`); }
|
|
116
|
+
|
|
117
|
+
await this.transfer({ addrs, from: this.receiverSpace, to: this.senderTempSpace });
|
|
118
|
+
} catch (error) {
|
|
119
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
120
|
+
throw error;
|
|
121
|
+
} finally {
|
|
122
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
protected async sendContextRequest(context: SyncSagaContextIbGib_V1): Promise<SyncSagaContextIbGib_V1 | undefined> {
|
|
127
|
+
const lc = `${this.lc}[${this.sendContextRequest.name}]`;
|
|
128
|
+
const { receiverSpace, receiverCoordinator, receiverMetaspace } = this;
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
if (logalot) { console.log(`${lc} starting...Context: ${getIbGibAddr({ ibGib: context })}`); }
|
|
132
|
+
|
|
133
|
+
// 0. Validate context (naive, not business logic validation)
|
|
134
|
+
if (!context.data) { throw new Error(`(UNEXPECTED) context.data falsy? (E: 1d2ac8a9b991d451e8900588057fe626)`); }
|
|
135
|
+
if (!context.rel8ns) { throw new Error(`(UNEXPECTED) context.rel8ns falsy? (E: 3508786f0d8880bcadd346282a807826)`); }
|
|
136
|
+
if (!context.rel8ns.sagaFrame) { throw new Error(`(UNEXPECTED) context.rel8ns.sagaFrame falsy? (E: ac06782ad538be406882605f0a83aa26)`); }
|
|
137
|
+
if (!context.sagaFrame) { throw new Error(`(UNEXPECTED) context.sagaFrame falsy? (E: 79cd98a6d9b88a591f4596c8bc58ff26)`); }
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
throw new Error(`not implemented (E: 72840872e252d9f7380f1998b5a0c826)`);
|
|
142
|
+
} catch (error) {
|
|
143
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Helper to copy single ibgib from A to B.
|
|
150
|
+
*/
|
|
151
|
+
protected async transfer({
|
|
152
|
+
addrs,
|
|
153
|
+
from,
|
|
154
|
+
to
|
|
155
|
+
}: {
|
|
156
|
+
addrs: IbGibAddr[],
|
|
157
|
+
from: IbGibSpaceAny,
|
|
158
|
+
to: IbGibSpaceAny
|
|
159
|
+
}): Promise<void> {
|
|
160
|
+
const lc = `${this.lc}[${this.transfer.name}]`;
|
|
161
|
+
try {
|
|
162
|
+
if (logalot) { console.log(`${lc} starting... (I: f1145dc75a461afc885efe984f08d426)`); }
|
|
163
|
+
|
|
164
|
+
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)`)
|
|
165
|
+
|
|
166
|
+
// 1. Get from Source
|
|
167
|
+
const resGet = await getFromSpace({ space: from, addrs });
|
|
168
|
+
if (!resGet.success || !resGet.ibGibs || resGet.ibGibs.length !== addrs.length) {
|
|
169
|
+
if (!resGet.rawResultIbGib) { throw new Error(`(UNEXPECTED) resGet.rawResultIbGib falsy? (E: b829f827a378890bcf7dc3d41c908826)`); }
|
|
170
|
+
if (!resGet.rawResultIbGib.data) { throw new Error(`(UNEXPECTED) resGet.rawResultIbGib.data falsy? (E: 8d15341d8fa8fc96297425e3c6e39226)`); }
|
|
171
|
+
const data = resGet.rawResultIbGib.data as IbGibSpaceResultData;
|
|
172
|
+
|
|
173
|
+
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)`);
|
|
174
|
+
}
|
|
175
|
+
const ibGibs = resGet.ibGibs.concat();
|
|
176
|
+
|
|
177
|
+
// 2. Put in Dest
|
|
178
|
+
// Note: putInSpace handles existence check usually, or we can check.
|
|
179
|
+
const resPut = await putInSpace({ space: to, ibGibs });
|
|
180
|
+
if (resPut.success) {
|
|
181
|
+
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) `);
|
|
182
|
+
} else {
|
|
183
|
+
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)`);
|
|
184
|
+
}
|
|
185
|
+
} catch (error) {
|
|
186
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
187
|
+
throw error;
|
|
188
|
+
} finally {
|
|
189
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
}
|
|
193
|
+
}
|
|
@@ -3,15 +3,20 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { IbGibData_V1, IbGibRel8ns_V1, IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
|
|
6
|
+
import { SubjectWitness } from '../../common/pubsub/subject/subject-types.mjs';
|
|
6
7
|
|
|
7
8
|
import { SyncSagaContextData_V1, SyncSagaContextIbGib_V1, SyncSagaContextRel8ns_V1 } from '../sync-saga-context/sync-saga-context-types.mjs';
|
|
8
9
|
import { Witness_V1 } from '../../witness/witness-types.mjs';
|
|
10
|
+
import { IbGibSpaceAny } from '../../witness/space/space-base-v1.mjs';
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Data for the SyncPeer witness.
|
|
12
14
|
*/
|
|
13
15
|
export interface SyncPeerData_V1 extends IbGibData_V1 {
|
|
14
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Concrete peer instance
|
|
18
|
+
*/
|
|
19
|
+
classname: string;
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
/**
|
|
@@ -40,4 +45,28 @@ export interface SyncPeerWitness extends Witness_V1<
|
|
|
40
45
|
SyncPeerRel8ns_V1
|
|
41
46
|
> {
|
|
42
47
|
// witness(arg: SyncSagaContextIbGib_V1): Promise<SyncSagaContextIbGib_V1 | undefined>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* sender's durable space.
|
|
51
|
+
*
|
|
52
|
+
* will store control ibgibs (context, sync saga ibgib, control msg stones)
|
|
53
|
+
* here (and in {@link senderTempSpace}) throughout the process for audit trail.
|
|
54
|
+
*/
|
|
55
|
+
senderSpace: IbGibSpaceAny;
|
|
56
|
+
/**
|
|
57
|
+
* sender's temporary space for the entire sync transaction.
|
|
58
|
+
*
|
|
59
|
+
* In addition to control ibgibs which are stored in both temp and durable
|
|
60
|
+
* spaces, this temp space will be where domain ibgibs are stored that are
|
|
61
|
+
* received/created throughout the transaction until commit.
|
|
62
|
+
*/
|
|
63
|
+
senderTempSpace: IbGibSpaceAny;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Observable for streaming large domain payloads asynchronously.
|
|
67
|
+
*
|
|
68
|
+
* Implementations should publish domain ibgibs to this observable as they are received.
|
|
69
|
+
* The handling code (e.g. SyncSagaCoordinator) will subscribe to this.
|
|
70
|
+
*/
|
|
71
|
+
payloadIbGibsDomainReceived$: SubjectWitness<IbGib_V1>;
|
|
43
72
|
}
|