@ibgib/core-gib 0.1.23 → 0.1.26
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 +17 -0
- package/dist/common/other/graph-helper.d.mts.map +1 -1
- package/dist/common/other/graph-helper.mjs +44 -0
- package/dist/common/other/graph-helper.mjs.map +1 -1
- package/dist/common/other/ibgib-helper.d.mts +1 -1
- package/dist/common/other/ibgib-helper.d.mts.map +1 -1
- package/dist/common/other/ibgib-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 +10 -15
- package/dist/sync/sync-conflict.respec.mjs.map +1 -1
- package/dist/sync/sync-constants.d.mts +1 -0
- package/dist/sync/sync-constants.d.mts.map +1 -1
- package/dist/sync/sync-constants.mjs +1 -0
- package/dist/sync/sync-constants.mjs.map +1 -1
- package/dist/sync/sync-helpers.d.mts +5 -0
- package/dist/sync/sync-helpers.d.mts.map +1 -1
- package/dist/sync/sync-helpers.mjs +37 -1
- package/dist/sync/sync-helpers.mjs.map +1 -1
- package/dist/sync/sync-innerspace-constants.respec.mjs +10 -12
- package/dist/sync/sync-innerspace-constants.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace-deep-updates.respec.mjs +10 -12
- package/dist/sync/sync-innerspace-deep-updates.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace-dest-ahead.respec.mjs +10 -12
- package/dist/sync/sync-innerspace-dest-ahead.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs +9 -12
- package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace-partial-update.respec.mjs +9 -14
- package/dist/sync/sync-innerspace-partial-update.respec.mjs.map +1 -1
- package/dist/sync/sync-innerspace.respec.mjs +9 -12
- 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-v1.d.mts +24 -13
- 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 +176 -76
- 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 +29 -6
- package/dist/sync/sync-peer/sync-peer-types.d.mts.map +1 -1
- package/dist/sync/sync-peer/sync-peer-v1.d.mts +38 -55
- package/dist/sync/sync-peer/sync-peer-v1.d.mts.map +1 -1
- package/dist/sync/sync-peer/sync-peer-v1.mjs +111 -244
- package/dist/sync/sync-peer/sync-peer-v1.mjs.map +1 -1
- package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts +32 -1
- 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 +96 -7
- package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs.map +1 -1
- package/dist/sync/sync-saga-coordinator.d.mts +59 -13
- package/dist/sync/sync-saga-coordinator.d.mts.map +1 -1
- package/dist/sync/sync-saga-coordinator.mjs +446 -304
- package/dist/sync/sync-saga-coordinator.mjs.map +1 -1
- package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts +51 -6
- package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts.map +1 -1
- package/dist/sync/sync-types.d.mts +35 -10
- package/dist/sync/sync-types.d.mts.map +1 -1
- package/dist/sync/sync-types.mjs +1 -2
- package/dist/sync/sync-types.mjs.map +1 -1
- package/package.json +1 -1
- package/src/common/other/graph-helper.mts +53 -0
- package/src/common/other/ibgib-helper.mts +1 -1
- package/src/sync/graft-info/graft-info-helpers.mts +3 -3
- package/src/sync/sync-conflict.respec.mts +10 -17
- package/src/sync/sync-constants.mts +1 -0
- package/src/sync/sync-helpers.mts +47 -7
- package/src/sync/sync-innerspace-constants.respec.mts +10 -12
- package/src/sync/sync-innerspace-deep-updates.respec.mts +10 -12
- package/src/sync/sync-innerspace-dest-ahead.respec.mts +10 -12
- package/src/sync/sync-innerspace-multiple-timelines.respec.mts +9 -12
- package/src/sync/sync-innerspace-partial-update.respec.mts +9 -14
- package/src/sync/sync-innerspace.respec.mts +9 -12
- 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-v1.mts +200 -75
- package/src/sync/sync-peer/sync-peer-types.mts +35 -11
- package/src/sync/sync-peer/sync-peer-v1.mts +154 -257
- package/src/sync/sync-saga-context/sync-saga-context-helpers.mts +90 -13
- package/src/sync/sync-saga-coordinator.mts +536 -356
- package/src/sync/sync-saga-message/sync-saga-message-types.mts +56 -4
- package/src/sync/sync-types.mts +46 -13
|
@@ -2,19 +2,27 @@
|
|
|
2
2
|
* @module SyncPeerInnerspace_V1
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { extractErrorMsg, unique } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
5
|
+
import { delay, extractErrorMsg, unique } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
6
6
|
import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
|
|
7
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';
|
|
8
10
|
|
|
9
11
|
import { GLOBAL_LOG_A_LOT } from '../../../core-constants.mjs';
|
|
10
12
|
import { IbGibSpaceAny } from '../../../witness/space/space-base-v1.mjs';
|
|
11
13
|
import { SyncPeer_V1 } from '../sync-peer-v1.mjs';
|
|
12
|
-
import { getFromSpace, putInSpace } from '../../../witness/space/space-helper.mjs';
|
|
14
|
+
import { getFromSpace, putInSpace, registerNewIbGib } from '../../../witness/space/space-helper.mjs';
|
|
13
15
|
import { SyncSagaContextIbGib_V1, } from '../../sync-saga-context/sync-saga-context-types.mjs';
|
|
14
16
|
import { SyncPeerInnerspaceData_V1, SyncPeerInnerspaceIbGib_V1, SyncPeerInnerspaceOptions, SyncPeerInnerspaceRel8ns_V1 } from './sync-peer-innerspace-types.mjs';
|
|
15
17
|
import { MetaspaceService } from '../../../witness/space/metaspace/metaspace-types.mjs';
|
|
16
18
|
import { SyncSagaCoordinator } from '../../sync-saga-coordinator.mjs';
|
|
17
19
|
import { IbGibSpaceResultData } from '../../../witness/space/space-types.mjs';
|
|
20
|
+
import { InitializeSyncPeerOpts } from '../sync-peer-types.mjs';
|
|
21
|
+
import { getSyncSagaMessageFromFrame } from '../../sync-saga-message/sync-saga-message-helpers.mjs';
|
|
22
|
+
import { SYNC_STAGE_VALID_VALUES, SyncStage } from '../../sync-constants.mjs';
|
|
23
|
+
import { SyncSagaMessageAckData_V1, SyncSagaMessageCommitData_V1, SyncSagaMessageData_V1, SyncSagaMessageDeltaData_V1, SyncSagaMessageInitData_V1 } from '../../sync-saga-message/sync-saga-message-types.mjs';
|
|
24
|
+
import { getSyncSagaFrameDependencyGraph, putInSpace_dnasThenNonDnas } from '../../sync-helpers.mjs';
|
|
25
|
+
import { splitPerTjpAndOrDna, toDto } from '../../../common/other/ibgib-helper.mjs';
|
|
18
26
|
|
|
19
27
|
|
|
20
28
|
const logalot = GLOBAL_LOG_A_LOT || true;
|
|
@@ -22,99 +30,76 @@ const logalotControlDomain = true;
|
|
|
22
30
|
const lcControlDomain = '[ControlDomain]';
|
|
23
31
|
|
|
24
32
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* Acts as the "Network" layer, transferring data between two local spaces and
|
|
28
|
-
* executing the receiver's coordinator logic.
|
|
33
|
+
* The innerspace sync peer works with innerspaces for both sender/receiver
|
|
34
|
+
* durable/temp spaces, as well as coordinators for each.
|
|
29
35
|
*/
|
|
30
|
-
export
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
export interface InitializeSyncPeerInnerspaceOpts extends InitializeSyncPeerOpts {
|
|
37
|
+
/**
|
|
38
|
+
* specific to innerspace
|
|
39
|
+
*/
|
|
40
|
+
receiverCoordinator: SyncSagaCoordinator;
|
|
34
41
|
/**
|
|
35
42
|
* specific to innerspace
|
|
36
43
|
*/
|
|
37
|
-
|
|
44
|
+
receiverMetaspace: MetaspaceService;
|
|
38
45
|
/**
|
|
39
46
|
* specific to innerspace
|
|
40
47
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
receiverSpace: IbGibSpaceAny;
|
|
49
|
+
/**
|
|
50
|
+
* If not available at first, this will be automatically created.
|
|
51
|
+
*/
|
|
52
|
+
receiverTempSpace?: IbGibSpaceAny;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Concrete implementation of SyncPeer for local in-memory simulation (Innerspace to Innerspace).
|
|
57
|
+
*
|
|
58
|
+
* Acts as the "Network" layer, transferring data between two local spaces and
|
|
59
|
+
* executing the receiver's coordinator logic.
|
|
60
|
+
*/
|
|
61
|
+
export class SyncPeerInnerspace_V1 extends SyncPeer_V1<InitializeSyncPeerInnerspaceOpts>
|
|
62
|
+
implements SyncPeerInnerspaceIbGib_V1 {
|
|
63
|
+
|
|
64
|
+
protected lc: string = `[${SyncPeerInnerspace_V1.name}]`;
|
|
44
65
|
|
|
45
66
|
override get classname(): string {
|
|
46
67
|
return SyncPeerInnerspace_V1.name;
|
|
47
68
|
}
|
|
48
69
|
|
|
49
70
|
constructor(
|
|
50
|
-
senderSpace: IbGibSpaceAny,
|
|
51
|
-
senderTempSpace: IbGibSpaceAny,
|
|
52
|
-
opts: SyncPeerInnerspaceOptions,
|
|
53
71
|
initialData: SyncPeerInnerspaceData_V1,
|
|
54
72
|
initialRel8ns?: SyncPeerInnerspaceRel8ns_V1,
|
|
55
73
|
) {
|
|
56
|
-
super(
|
|
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;
|
|
74
|
+
super(initialData, initialRel8ns);
|
|
66
75
|
}
|
|
67
76
|
|
|
68
77
|
protected override async ensureReceiverTempSpace(): Promise<IbGibSpaceAny> {
|
|
69
|
-
|
|
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}]`;
|
|
78
|
+
const lc = `${this.lc}[${this.ensureReceiverTempSpace.name}]`;
|
|
92
79
|
try {
|
|
93
|
-
if (logalot) { console.log(`${lc} starting... (I:
|
|
80
|
+
if (logalot) { console.log(`${lc} starting... (I: bab87f15dea77cd4892bd8a8d2e65826)`); }
|
|
94
81
|
|
|
95
|
-
|
|
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)`); }
|
|
82
|
+
if (!this.opts) { throw new Error(`(UNEXPECTED) this.opts falsy? (E: 0f85bd4c3efdbee2a829aca860c48926)`); }
|
|
98
83
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
102
|
-
throw error;
|
|
103
|
-
} finally {
|
|
104
|
-
if (logalot) { console.log(`${lc} complete.`); }
|
|
105
|
-
}
|
|
106
|
-
}
|
|
84
|
+
if (!this.opts.receiverTempSpace) {
|
|
85
|
+
const { receiverMetaspace } = this.opts;
|
|
107
86
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
87
|
+
const uuid = crypto.randomUUID ? crypto.randomUUID() : Math.random().toString(36);
|
|
88
|
+
const tempSpaceName = `tmp_sync_recv_${uuid.substring(0, 8)}`;
|
|
89
|
+
const receiverTempSpace = await receiverMetaspace.createNewLocalSpace({
|
|
90
|
+
opts: {
|
|
91
|
+
allowCancel: false,
|
|
92
|
+
spaceName: tempSpaceName,
|
|
93
|
+
getFnPrompt: receiverMetaspace.getFnPrompt!,
|
|
94
|
+
logalot
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
if (!receiverTempSpace) { throw new Error(`(UNEXPECTED) receiverTempSpace falsy? couldn't create a temp space? (E: a6b8f86b0f58384b884a33b82924b826)`); }
|
|
98
|
+
await receiverTempSpace.initialized;
|
|
99
|
+
this.opts.receiverTempSpace = receiverTempSpace;
|
|
100
|
+
}
|
|
116
101
|
|
|
117
|
-
|
|
102
|
+
return this.opts.receiverTempSpace;
|
|
118
103
|
} catch (error) {
|
|
119
104
|
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
120
105
|
throw error;
|
|
@@ -125,20 +110,160 @@ export class SyncPeerInnerspace_V1 extends SyncPeer_V1 implements SyncPeerInners
|
|
|
125
110
|
|
|
126
111
|
protected async sendContextRequest(context: SyncSagaContextIbGib_V1): Promise<SyncSagaContextIbGib_V1 | undefined> {
|
|
127
112
|
const lc = `${this.lc}[${this.sendContextRequest.name}]`;
|
|
128
|
-
const { receiverSpace, receiverCoordinator, receiverMetaspace } = this;
|
|
129
|
-
|
|
130
113
|
try {
|
|
114
|
+
if (!this.opts) { throw new Error(`(UNEXPECTED) this.opts falsy? (E: d8b1348e3233810128999596b1fa5826)`); }
|
|
115
|
+
|
|
116
|
+
const {
|
|
117
|
+
senderSpace, senderTempSpace,
|
|
118
|
+
receiverSpace, receiverCoordinator, receiverMetaspace,
|
|
119
|
+
receiverTempSpace
|
|
120
|
+
} = this.opts;
|
|
121
|
+
|
|
131
122
|
if (logalot) { console.log(`${lc} starting...Context: ${getIbGibAddr({ ibGib: context })}`); }
|
|
132
123
|
|
|
133
|
-
|
|
124
|
+
const { sagaFrame } = context;
|
|
125
|
+
|
|
126
|
+
// The context has already been validated, authenticated and authorized at this point.
|
|
127
|
+
|
|
128
|
+
// #region sanity validation assertions
|
|
134
129
|
if (!context.data) { throw new Error(`(UNEXPECTED) context.data falsy? (E: 1d2ac8a9b991d451e8900588057fe626)`); }
|
|
135
130
|
if (!context.rel8ns) { throw new Error(`(UNEXPECTED) context.rel8ns falsy? (E: 3508786f0d8880bcadd346282a807826)`); }
|
|
136
131
|
if (!context.rel8ns.sagaFrame) { throw new Error(`(UNEXPECTED) context.rel8ns.sagaFrame falsy? (E: ac06782ad538be406882605f0a83aa26)`); }
|
|
137
132
|
if (!context.sagaFrame) { throw new Error(`(UNEXPECTED) context.sagaFrame falsy? (E: 79cd98a6d9b88a591f4596c8bc58ff26)`); }
|
|
133
|
+
if (!sagaFrame.data) { throw new Error(`(UNEXPECTED) sagaFrame.data falsy? (E: f30e290a8b770e1b387377420ea73a26)`); }
|
|
134
|
+
if (!sagaFrame.rel8ns) { throw new Error(`(UNEXPECTED) sagaFrame.rel8ns falsy? (E: f888caa698b8cf6b4893b7fd6df09726)`); }
|
|
135
|
+
if (!receiverTempSpace) { throw new Error(`(UNEXPECTED) receiverTempSpace falsy? (E: 3b46d838f6fc645c58b29215bfddb826)`); }
|
|
136
|
+
// #endregion sanity validation assertions
|
|
137
|
+
|
|
138
|
+
const { sagaIbGib: _alreadyHave, msgStones, identities } = await getSyncSagaFrameDependencyGraph({
|
|
139
|
+
sagaIbGib: sagaFrame,
|
|
140
|
+
localSpace: senderSpace,
|
|
141
|
+
});
|
|
142
|
+
if (msgStones.length !== 1) { throw new Error(`(UNEXPECTED) msgStones.length !== 1? we're only geared for a single msg stone that is always present (not 0, not greater than 1) (E: 2d3138ed130f1aca116551889483e826)`); }
|
|
143
|
+
const msg = msgStones[0];
|
|
144
|
+
if (!msg.data) { throw new Error(`(UNEXPECTED) sync saga message ibgib.data falsy? (E: 61ec18743988ad3cbab2072d1dd69826)`); }
|
|
145
|
+
|
|
146
|
+
// send the context itself, then send the payload ibgibs separately.
|
|
147
|
+
// in this innerspace, this just means putting the control ibgibs
|
|
148
|
+
// first into the receiver durable space, then we will spin off a
|
|
149
|
+
// promise to put any payload ibgibs in the receiver temp space.
|
|
150
|
+
// We'll test a little latency also, to mimic a fuller, two-part
|
|
151
|
+
// sync peer to ensure that other code is acting as expected.
|
|
152
|
+
|
|
153
|
+
// we store inside out, meaning we do the dependencies first and
|
|
154
|
+
// then the higher-level dependents.
|
|
155
|
+
const payloadIbGibsControl = [
|
|
156
|
+
...identities, msg, sagaFrame, context
|
|
157
|
+
].map(x => toDto({ ibGib: x }));
|
|
158
|
+
await putInSpace({
|
|
159
|
+
ibGibs: payloadIbGibsControl,
|
|
160
|
+
space: receiverSpace,
|
|
161
|
+
});
|
|
162
|
+
// register yet??
|
|
163
|
+
for (const control of payloadIbGibsControl) {
|
|
164
|
+
await registerNewIbGib({
|
|
165
|
+
ibGib: control,
|
|
166
|
+
space: receiverSpace,
|
|
167
|
+
fnBroadcast: undefined
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (context.payloadIbGibsDomain && context.payloadIbGibsDomain.length > 0) {
|
|
172
|
+
await putInSpace_dnasThenNonDnas({
|
|
173
|
+
ibGibs: context.payloadIbGibsDomain,
|
|
174
|
+
space: receiverTempSpace,
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
// no need to register right now, because we're putting into the
|
|
178
|
+
// temp receiver space and we don't register until we commit
|
|
179
|
+
// const { mapWithTjp_NoDna, mapWithTjp_YesDna, mapWithoutTjps } =
|
|
180
|
+
// splitPerTjpAndOrDna({ ibGibs: payload_NonDnas });
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// at this time, the receiver has received the control ibgibs AND
|
|
184
|
+
// the payload ibgibs. so the receiver coordinator should be ready
|
|
185
|
+
// to do its thing.
|
|
186
|
+
|
|
187
|
+
const responseCtx = await receiverCoordinator.receiverContinueSync({
|
|
188
|
+
sagaContext: context,
|
|
189
|
+
metaspace: receiverMetaspace,
|
|
190
|
+
mySpace: receiverSpace,
|
|
191
|
+
myTempSpace: receiverTempSpace,
|
|
192
|
+
});
|
|
138
193
|
|
|
194
|
+
if (!responseCtx) {
|
|
195
|
+
if (logalot) { console.log(`${lc} receiver produced undefined response context. (I: 2e1888ffc9e836689d5b171887c36d26)`); }
|
|
196
|
+
return undefined; /* <<<< returns early */
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// at this point, we have received the full response from the
|
|
200
|
+
// receiver coordinator. Put the response's control ibgibs in the
|
|
201
|
+
// sender's durable space (but don't register them), spin off the
|
|
202
|
+
// process of any response payloads, and return the context.
|
|
139
203
|
|
|
204
|
+
const { msgStones: msgStonesResponse, identities: identitiesResponse } =
|
|
205
|
+
await getSyncSagaFrameDependencyGraph({
|
|
206
|
+
sagaIbGib: responseCtx.sagaFrame,
|
|
207
|
+
localSpace: senderSpace,
|
|
208
|
+
});
|
|
209
|
+
if (msgStonesResponse.length !== 1) { throw new Error(`(UNEXPECTED) msgStonesResponse.length !== 1? we're only geared for a single msg stone that is always present (not 0, not greater than 1) (E: 2d3138ed130f1aca116551889483e826)`); }
|
|
210
|
+
const msgResponse = msgStonesResponse[0];
|
|
211
|
+
if (!msgResponse.data) { throw new Error(`(UNEXPECTED) sync saga message ibgib.data falsy? (E: 61ec18743988ad3cbab2072d1dd69826)`); }
|
|
212
|
+
const responsePayloadIbGibsControl = [
|
|
213
|
+
...identities, msgResponse, responseCtx.sagaFrame, context
|
|
214
|
+
].map(x => toDto({ ibGib: x }));
|
|
215
|
+
await putInSpace({
|
|
216
|
+
ibGibs: responsePayloadIbGibsControl,
|
|
217
|
+
space: senderSpace,
|
|
218
|
+
});
|
|
219
|
+
// register yet??
|
|
220
|
+
for (const control of responsePayloadIbGibsControl) {
|
|
221
|
+
await registerNewIbGib({
|
|
222
|
+
ibGib: control,
|
|
223
|
+
space: senderSpace,
|
|
224
|
+
fnBroadcast: undefined
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// spin off the payloads, as that may take a long time
|
|
229
|
+
const payloadIbGibsDomain_response = responseCtx.payloadIbGibsDomain;
|
|
230
|
+
if (payloadIbGibsDomain_response) {
|
|
231
|
+
new Promise<void>(async (resolve, reject) => {
|
|
232
|
+
const lcPut = `${lc}[putPayloadsPromise]`;
|
|
233
|
+
try {
|
|
234
|
+
if (logalot) { console.log(`${lcPut} starting... (I: 4133e736b4c80d2cf94448b87b206826)`); }
|
|
235
|
+
|
|
236
|
+
// 2 seconds...i want to see huge blocks of logs entries for this to see this happening
|
|
237
|
+
const delayMs = 200;
|
|
238
|
+
for (let i = 0; i < 10; i++) {
|
|
239
|
+
console.warn(`${lc} ARTIFICIALLY DELAYING PAYLOADS TO MIMIC TRANSFER LATENCY. REMOVE THIS DELAY!! (W: 5e7b28f1daa82d955897e9d8cdb16f26)`)
|
|
240
|
+
await delay(delayMs);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (!senderTempSpace) { throw new Error(`(UNEXPECTED) senderTempSpace falsy? (E: b187a8f913c2295ae90d7ae2b47b6a26)`); }
|
|
244
|
+
|
|
245
|
+
await putInSpace_dnasThenNonDnas({
|
|
246
|
+
ibGibs: payloadIbGibsDomain_response,
|
|
247
|
+
space: senderTempSpace,
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
if (logalot) { console.log(`${lcPut} complete.`); }
|
|
251
|
+
resolve();
|
|
252
|
+
} catch (error) {
|
|
253
|
+
const errorMsg = `${lcPut} ${extractErrorMsg(error)}`;
|
|
254
|
+
console.error(errorMsg);
|
|
255
|
+
if (logalot) { console.log(`${lcPut} complete. (errored)`); }
|
|
256
|
+
reject(errorMsg);
|
|
257
|
+
}
|
|
258
|
+
}); // spin off
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* the caller should be getting these from the observable.
|
|
262
|
+
*/
|
|
263
|
+
delete responseCtx.payloadIbGibsDomain;
|
|
264
|
+
}
|
|
140
265
|
|
|
141
|
-
|
|
266
|
+
return responseCtx;
|
|
142
267
|
} catch (error) {
|
|
143
268
|
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
144
269
|
throw error;
|
|
@@ -30,11 +30,32 @@ export interface SyncPeerRel8ns_V1 extends IbGibRel8ns_V1 {
|
|
|
30
30
|
*/
|
|
31
31
|
export interface SyncPeerIbGib_V1 extends IbGib_V1<SyncPeerData_V1, SyncPeerRel8ns_V1> { }
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* base initialization opts
|
|
35
|
+
*/
|
|
36
|
+
export interface InitializeSyncPeerOpts {
|
|
37
|
+
/**
|
|
38
|
+
* sender's durable space.
|
|
39
|
+
*
|
|
40
|
+
* will store control ibgibs (context, sync saga ibgib, control msg stones)
|
|
41
|
+
* here (and in {@link senderTempSpace}) throughout the process for audit trail.
|
|
42
|
+
*/
|
|
43
|
+
senderSpace: IbGibSpaceAny;
|
|
44
|
+
/**
|
|
45
|
+
* sender's temporary space for the entire sync transaction.
|
|
46
|
+
*
|
|
47
|
+
* In addition to control ibgibs which are stored in both temp and durable
|
|
48
|
+
* spaces, this temp space will be where domain ibgibs are stored that are
|
|
49
|
+
* received/created throughout the transaction until commit.
|
|
50
|
+
*/
|
|
51
|
+
senderTempSpace?: IbGibSpaceAny;
|
|
52
|
+
}
|
|
53
|
+
|
|
33
54
|
/**
|
|
34
55
|
* The interface for the SyncPeer witness class.
|
|
35
56
|
* It witnesses a SyncSagaContext and returns a SyncSagaContext (Request -> Response).
|
|
36
57
|
*/
|
|
37
|
-
export interface SyncPeerWitness extends Witness_V1<
|
|
58
|
+
export interface SyncPeerWitness<TInitializeOpts extends InitializeSyncPeerOpts = InitializeSyncPeerOpts> extends Witness_V1<
|
|
38
59
|
SyncSagaContextData_V1,
|
|
39
60
|
SyncSagaContextRel8ns_V1,
|
|
40
61
|
SyncSagaContextIbGib_V1, // Input
|
|
@@ -44,23 +65,26 @@ export interface SyncPeerWitness extends Witness_V1<
|
|
|
44
65
|
SyncPeerData_V1,
|
|
45
66
|
SyncPeerRel8ns_V1
|
|
46
67
|
> {
|
|
47
|
-
|
|
68
|
+
get classname(): string;
|
|
48
69
|
|
|
49
70
|
/**
|
|
50
|
-
* sender
|
|
71
|
+
* sender-specific opts/config
|
|
51
72
|
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
73
|
+
* ## notes
|
|
74
|
+
*
|
|
75
|
+
* I'm doing this hack because I have to be able to create a peer without
|
|
76
|
+
* being able to fully configure it at construction time. So I can't place
|
|
77
|
+
* this init code in the {@link initialize} method.
|
|
54
78
|
*/
|
|
55
|
-
|
|
79
|
+
opts: TInitializeOpts | undefined;
|
|
80
|
+
|
|
56
81
|
/**
|
|
57
|
-
*
|
|
82
|
+
* use this to set the senderTempSpace and any other optional opts that need
|
|
83
|
+
* to be configured just before sending any contexts across the wire.
|
|
58
84
|
*
|
|
59
|
-
*
|
|
60
|
-
* spaces, this temp space will be where domain ibgibs are stored that are
|
|
61
|
-
* received/created throughout the transaction until commit.
|
|
85
|
+
* @see {@link opts}
|
|
62
86
|
*/
|
|
63
|
-
|
|
87
|
+
setOptionalOpts(arg: Partial<TInitializeOpts>): void;
|
|
64
88
|
|
|
65
89
|
/**
|
|
66
90
|
* Observable for streaming large domain payloads asynchronously.
|