@ibgib/core-gib 0.1.26 → 0.1.28

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.
Files changed (34) hide show
  1. package/dist/sync/sync-helpers.d.mts +23 -2
  2. package/dist/sync/sync-helpers.d.mts.map +1 -1
  3. package/dist/sync/sync-helpers.mjs +121 -4
  4. package/dist/sync/sync-helpers.mjs.map +1 -1
  5. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.d.mts.map +1 -1
  6. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs +30 -9
  7. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs.map +1 -1
  8. package/dist/sync/sync-peer/sync-peer-v1.d.mts.map +1 -1
  9. package/dist/sync/sync-peer/sync-peer-v1.mjs +1 -0
  10. package/dist/sync/sync-peer/sync-peer-v1.mjs.map +1 -1
  11. package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts.map +1 -1
  12. package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs +17 -3
  13. package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs.map +1 -1
  14. package/dist/sync/sync-saga-context/sync-saga-context-types.d.mts +8 -0
  15. package/dist/sync/sync-saga-context/sync-saga-context-types.d.mts.map +1 -1
  16. package/dist/sync/sync-saga-coordinator.d.mts +30 -153
  17. package/dist/sync/sync-saga-coordinator.d.mts.map +1 -1
  18. package/dist/sync/sync-saga-coordinator.mjs +585 -406
  19. package/dist/sync/sync-saga-coordinator.mjs.map +1 -1
  20. package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts +13 -18
  21. package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts.map +1 -1
  22. package/dist/sync/sync-types.d.mts +36 -6
  23. package/dist/sync/sync-types.d.mts.map +1 -1
  24. package/dist/sync/sync-types.mjs +32 -0
  25. package/dist/sync/sync-types.mjs.map +1 -1
  26. package/package.json +2 -2
  27. package/src/sync/sync-helpers.mts +113 -6
  28. package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mts +30 -8
  29. package/src/sync/sync-peer/sync-peer-v1.mts +2 -0
  30. package/src/sync/sync-saga-context/sync-saga-context-helpers.mts +14 -2
  31. package/src/sync/sync-saga-context/sync-saga-context-types.mts +13 -5
  32. package/src/sync/sync-saga-coordinator.mts +656 -463
  33. package/src/sync/sync-saga-message/sync-saga-message-types.mts +27 -32
  34. package/src/sync/sync-types.mts +45 -8
@@ -6,6 +6,7 @@ import { SyncStage } from "../sync-constants.mjs";
6
6
  import { SyncMode, SyncConflictStrategy, } from "../sync-types.mjs";
7
7
  import { SYNC_SAGA_MSG_ATOM } from "./sync-saga-message-constants.mjs";
8
8
  import type { getDeltaDependencyGraph } from '../../common/other/graph-helper.mjs';
9
+ import type { SyncSagaContextIbGib_V1, SyncSagaContextData_V1 } from '../sync-saga-context/sync-saga-context-types.mjs';
9
10
 
10
11
  export interface SyncSagaMessageIb_V1 {
11
12
  atom: typeof SYNC_SAGA_MSG_ATOM;
@@ -38,7 +39,7 @@ export interface SyncSagaMessageIbGib_V1 extends IbGib_V1<SyncSagaMessageData_V1
38
39
 
39
40
  /**
40
41
  * The "Hello" of the sync protocol.
41
- *
42
+ *
42
43
  * Exchanges knowledge vectors (what I have) and identity (who I am).
43
44
  */
44
45
  export interface SyncSagaMessageInitData_V1 extends SyncSagaMessageData_V1 {
@@ -47,7 +48,7 @@ export interface SyncSagaMessageInitData_V1 extends SyncSagaMessageData_V1 {
47
48
  /**
48
49
  * Map of TJP (Temporal Joint Point) to latest known ibGibAddr.
49
50
  * Use this to calculate what is missing (Delta).
50
- *
51
+ *
51
52
  * IOW, this is a map of the starting and end points of an ibGib's timeline.
52
53
  */
53
54
  knowledgeVector: { [tjp: string]: IbGibAddr };
@@ -67,14 +68,14 @@ export interface SyncSagaMessageInitData_V1 extends SyncSagaMessageData_V1 {
67
68
 
68
69
  /**
69
70
  * This is also in the sync saga ibgib itself now...
70
- *
71
+ *
71
72
  * @see {@link SyncOptions.conflictStrategy}
72
73
  */
73
74
  conflictStrategy?: SyncConflictStrategy;
74
75
  }
75
76
 
76
77
  /**
77
- * When an endpoing doesn't have a timeline or some part of it, then this info
78
+ * When an endpoing doesn't have a timeline or some part of it, then this info
78
79
  * contains sufficient information for the other endpoint to know what addrs to
79
80
  * send.
80
81
  */
@@ -92,9 +93,9 @@ export interface SyncSagaRequestAddrInfo {
92
93
  /**
93
94
  * If this is truthy, then we already have something from this timeline and
94
95
  * this will be the latest addr in that timeline.
95
- *
96
+ *
96
97
  * If falsy, then we are requesting the entire timeline be sent.
97
- *
98
+ *
98
99
  * This is to be used to calculate the delta graph.
99
100
  * @see {@link getDeltaDependencyGraph}
100
101
  */
@@ -145,31 +146,19 @@ export interface SyncSagaConflictInfo {
145
146
  export interface SyncSagaMessageAckData_V1 extends SyncSagaMessageData_V1 {
146
147
  stage: typeof SyncStage.ack;
147
148
  deltaRequestAddrInfos: SyncSagaRequestAddrInfo[];
148
- pushOfferInfos: SyncSagaPushOfferInfo[];
149
149
  /**
150
- * Map of group keys (TJP addr/constant addr) to list of known addresses
151
- * in that timeline.
152
- *
153
- * This will be used by Sender to calculate differential payloads. So
154
- * when the sender goes to get the dependency graph of its tip ibgib,
155
- * it can skip all of the addrs in this.
156
- *
157
- * For example, say sender has A^5 and receiver only has A^3. Sender
158
- * will see in this map { [A^0]: [A^0, A^1, A^2, A^3] } and know that
159
- * it needs all of the dependencies of A^5 (including A^4), but it does
160
- * NOT need to send A^0-A^3 (and dependencies) because receiver already has
161
- * these.
162
- *
163
- * ## notes
164
- *
165
- * I dislike this name in my rewrite/cleanup of this algorithm. However, I'm
166
- * keeping it and am using it right now in handleInitFrame for including
167
- * the receiver's latest addr/tip for the deltaReqAddrs. But really, I should
168
- */
169
- // knowledgeVector?: { [tjpAddr: string]: string[] };
150
+ * Infos regarding ibgibs that the receiver (generator of this ack)
151
+ * knows/believes that the sender does NOT have (after looking at knowledge
152
+ * vector of sender).
153
+ *
154
+ * This includes addrs that will correspond to the context.payloadAddrsDomain
155
+ *
156
+ * ## note
157
+ */
158
+ pushOfferInfos: SyncSagaPushOfferInfo[];
170
159
  /**
171
160
  * List of identified conflicts.
172
- *
161
+ *
173
162
  * If present, the Sender should use the `timelineAddrs` (Receiver's
174
163
  * history) to compute the LCA and delta requirements for merging.
175
164
  */
@@ -178,22 +167,28 @@ export interface SyncSagaMessageAckData_V1 extends SyncSagaMessageData_V1 {
178
167
 
179
168
  /**
180
169
  * The "Body" of the sync protocol. Carries the manifests of data to be
181
- * transferred.
182
- *
170
+ * transferred.
171
+ *
183
172
  * If any {@link payloadAddrsDomain} exist, then these will be populated in the
184
173
  * {@link SyncSagaContextIbGib_V1}.
185
174
  */
186
175
  export interface SyncSagaMessageDeltaData_V1 extends SyncSagaMessageData_V1 {
187
176
  stage: typeof SyncStage.delta;
188
- requests?: string[];
177
+ deltaRequestAddrInfos?: SyncSagaRequestAddrInfo[];
189
178
  /**
190
- * Flag indicating the sender has no further requests or payloads
179
+ * Flag indicating the sender has no further requests or payloads
191
180
  * and is ready to commit the transaction.
192
181
  */
193
182
  proposeCommit?: boolean;
194
183
  /**
195
184
  * Domain ibgib addresses (actual user data being synced).
196
185
  * These go to tempSpace ONLY until final commit.
186
+ *
187
+ * NOTE: There is also a payloadAddrsDomain on the actual context itself on
188
+ * {@link SyncSagaContextData_V1}.
189
+ * NOTE: There is also payload info in {@link SyncSagaMessageAckData_V1}
190
+ * in {@link SyncSagaMessageAckData_V1.pushOfferInfos}. Not quite as elegant
191
+ * as I want it to be but there ya go.
197
192
  */
198
193
  payloadAddrsDomain?: string[];
199
194
  }
@@ -9,7 +9,7 @@ import { IbGibSpaceAny } from "../witness/space/space-base-v1.mjs";
9
9
  import { MetaspaceService } from "../witness/space/metaspace/metaspace-types.mjs";
10
10
  import { SyncPeerWitness } from "./sync-peer/sync-peer-types.mjs";
11
11
  import { FlatIbGibGraph } from "../common/other/graph-types.mjs";
12
- import { SyncSagaConflictInfo } from "./sync-saga-message/sync-saga-message-types.mjs";
12
+ import { SyncSagaConflictInfo, SyncSagaMessageIbGib_V1 } from "./sync-saga-message/sync-saga-message-types.mjs";
13
13
 
14
14
 
15
15
  // #region SyncMode
@@ -54,17 +54,53 @@ export function isValidSyncConflictStrategy(strategy: string): strategy is SyncC
54
54
  }
55
55
  // #endregion SyncConflictStrategy
56
56
 
57
+ // #region SyncExecutionContext
58
+ export const SYNC_EXECUTION_CONTEXT_SENDER = 'sender';
59
+ export const SYNC_EXECUTION_CONTEXT_RECEIVER = 'receiver';
60
+ export type SyncExecutionContext =
61
+ | typeof SYNC_EXECUTION_CONTEXT_SENDER
62
+ | typeof SYNC_EXECUTION_CONTEXT_RECEIVER
63
+ ;
64
+ /**
65
+ * if the current code execution is executing on the original sender (the
66
+ * initiator of the sync saga operation) or the other party, the "receiver" (the
67
+ * one responding).
68
+ *
69
+ * This is driven by looking at the latest value of `sagaFrame.data.n` value.
70
+ *
71
+ * NOTE: This is not to be confused with the sync saga context ibgib, which is
72
+ * something else entirely. That is the transport wrapper ibgib around the saga.
73
+ * this is strictly the enum for where the code is executing.
74
+ */
75
+ export const SyncExecutionContext = {
76
+ /**
77
+ * The current code is executing on the initial location that started the
78
+ * sync.
79
+ */
80
+ sender: SYNC_EXECUTION_CONTEXT_SENDER,
81
+ /**
82
+ * The current code is executing on the receiving end, which is either a
83
+ * physically different location or is the logical "receiver" of an
84
+ * in-memory sync execution.
85
+ */
86
+ receiver: SYNC_EXECUTION_CONTEXT_RECEIVER,
87
+ } satisfies { [key in SyncExecutionContext]: SyncExecutionContext };
88
+ export const SYNC_EXECUTION_CONTEXT_VALID_VALUES = Object.values(SyncExecutionContext);
89
+ export function isValidSyncExecutionContext(executionContext: string): executionContext is SyncExecutionContext {
90
+ return SYNC_EXECUTION_CONTEXT_VALID_VALUES.includes(executionContext as SyncExecutionContext);
91
+ }
92
+ // #endregion SyncConflictStrategy
93
+
57
94
  export interface NextSagaFrameInfo_Frame {
58
95
  frame: SyncIbGib_V1;
59
96
  payloadIbGibsDomain?: IbGib_V1[];
60
- // conflictInfos?: SyncSagaConflictInfo;
61
- responseWasNull?: undefined;
97
+ sagaComplete?: undefined;
62
98
  }
63
- export interface NextSagaFrameInfo_Null {
64
- frame: never;
99
+ export interface NextSagaFrameInfo_SagaComplete {
100
+ frame?: never;
65
101
  payloadIbGibsDomain?: never;
66
102
  conflictInfos?: never;
67
- responseWasNull: true;
103
+ sagaComplete: true;
68
104
  }
69
105
  /**
70
106
  * Result of handling a saga frame.
@@ -75,7 +111,7 @@ export interface NextSagaFrameInfo_Null {
75
111
  * defined, thus the discriminated union type.
76
112
  */
77
113
  export type NextSagaFrameInfo =
78
- NextSagaFrameInfo_Frame | NextSagaFrameInfo_Null;
114
+ NextSagaFrameInfo_Frame | NextSagaFrameInfo_SagaComplete;
79
115
 
80
116
 
81
117
  export interface HandleSagaResponseContextResult_Base {
@@ -170,7 +206,8 @@ export interface SyncSagaInfo {
170
206
 
171
207
  export interface SyncSagaFrameDependencyGraph {
172
208
  sagaIbGib: SyncIbGib_V1;
173
- msgStones: IbGib_V1[];
209
+ // msgStones: IbGib_V1[];
210
+ msgStones: SyncSagaMessageIbGib_V1[];
174
211
  identities: KeystoneIbGib_V1[];
175
212
  }
176
213