@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.
Files changed (80) hide show
  1. package/dist/common/other/graph-helper.d.mts +17 -0
  2. package/dist/common/other/graph-helper.d.mts.map +1 -1
  3. package/dist/common/other/graph-helper.mjs +44 -0
  4. package/dist/common/other/graph-helper.mjs.map +1 -1
  5. package/dist/common/other/ibgib-helper.d.mts +1 -1
  6. package/dist/common/other/ibgib-helper.d.mts.map +1 -1
  7. package/dist/common/other/ibgib-helper.mjs.map +1 -1
  8. package/dist/sync/graft-info/graft-info-helpers.mjs +2 -2
  9. package/dist/sync/graft-info/graft-info-helpers.mjs.map +1 -1
  10. package/dist/sync/sync-conflict.respec.mjs +10 -15
  11. package/dist/sync/sync-conflict.respec.mjs.map +1 -1
  12. package/dist/sync/sync-constants.d.mts +1 -0
  13. package/dist/sync/sync-constants.d.mts.map +1 -1
  14. package/dist/sync/sync-constants.mjs +1 -0
  15. package/dist/sync/sync-constants.mjs.map +1 -1
  16. package/dist/sync/sync-helpers.d.mts +5 -0
  17. package/dist/sync/sync-helpers.d.mts.map +1 -1
  18. package/dist/sync/sync-helpers.mjs +37 -1
  19. package/dist/sync/sync-helpers.mjs.map +1 -1
  20. package/dist/sync/sync-innerspace-constants.respec.mjs +10 -12
  21. package/dist/sync/sync-innerspace-constants.respec.mjs.map +1 -1
  22. package/dist/sync/sync-innerspace-deep-updates.respec.mjs +10 -12
  23. package/dist/sync/sync-innerspace-deep-updates.respec.mjs.map +1 -1
  24. package/dist/sync/sync-innerspace-dest-ahead.respec.mjs +10 -12
  25. package/dist/sync/sync-innerspace-dest-ahead.respec.mjs.map +1 -1
  26. package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs +9 -12
  27. package/dist/sync/sync-innerspace-multiple-timelines.respec.mjs.map +1 -1
  28. package/dist/sync/sync-innerspace-partial-update.respec.mjs +9 -14
  29. package/dist/sync/sync-innerspace-partial-update.respec.mjs.map +1 -1
  30. package/dist/sync/sync-innerspace.respec.mjs +9 -12
  31. package/dist/sync/sync-innerspace.respec.mjs.map +1 -1
  32. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.d.mts +2 -0
  33. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.d.mts.map +1 -1
  34. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.mjs +4 -0
  35. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.mjs.map +1 -1
  36. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.d.mts +24 -13
  37. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.d.mts.map +1 -1
  38. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs +176 -76
  39. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs.map +1 -1
  40. package/dist/sync/sync-peer/sync-peer-types.d.mts +29 -6
  41. package/dist/sync/sync-peer/sync-peer-types.d.mts.map +1 -1
  42. package/dist/sync/sync-peer/sync-peer-v1.d.mts +38 -55
  43. package/dist/sync/sync-peer/sync-peer-v1.d.mts.map +1 -1
  44. package/dist/sync/sync-peer/sync-peer-v1.mjs +111 -244
  45. package/dist/sync/sync-peer/sync-peer-v1.mjs.map +1 -1
  46. package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts +32 -1
  47. package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts.map +1 -1
  48. package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs +96 -7
  49. package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs.map +1 -1
  50. package/dist/sync/sync-saga-coordinator.d.mts +59 -13
  51. package/dist/sync/sync-saga-coordinator.d.mts.map +1 -1
  52. package/dist/sync/sync-saga-coordinator.mjs +446 -304
  53. package/dist/sync/sync-saga-coordinator.mjs.map +1 -1
  54. package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts +51 -6
  55. package/dist/sync/sync-saga-message/sync-saga-message-types.d.mts.map +1 -1
  56. package/dist/sync/sync-types.d.mts +35 -10
  57. package/dist/sync/sync-types.d.mts.map +1 -1
  58. package/dist/sync/sync-types.mjs +1 -2
  59. package/dist/sync/sync-types.mjs.map +1 -1
  60. package/package.json +1 -1
  61. package/src/common/other/graph-helper.mts +53 -0
  62. package/src/common/other/ibgib-helper.mts +1 -1
  63. package/src/sync/graft-info/graft-info-helpers.mts +3 -3
  64. package/src/sync/sync-conflict.respec.mts +10 -17
  65. package/src/sync/sync-constants.mts +1 -0
  66. package/src/sync/sync-helpers.mts +47 -7
  67. package/src/sync/sync-innerspace-constants.respec.mts +10 -12
  68. package/src/sync/sync-innerspace-deep-updates.respec.mts +10 -12
  69. package/src/sync/sync-innerspace-dest-ahead.respec.mts +10 -12
  70. package/src/sync/sync-innerspace-multiple-timelines.respec.mts +9 -12
  71. package/src/sync/sync-innerspace-partial-update.respec.mts +9 -14
  72. package/src/sync/sync-innerspace.respec.mts +9 -12
  73. package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.mts +7 -0
  74. package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mts +200 -75
  75. package/src/sync/sync-peer/sync-peer-types.mts +35 -11
  76. package/src/sync/sync-peer/sync-peer-v1.mts +154 -257
  77. package/src/sync/sync-saga-context/sync-saga-context-helpers.mts +90 -13
  78. package/src/sync/sync-saga-coordinator.mts +536 -356
  79. package/src/sync/sync-saga-message/sync-saga-message-types.mts +56 -4
  80. package/src/sync/sync-types.mts +46 -13
@@ -1,9 +1,11 @@
1
1
  import { IbGib_V1, IbGibData_V1, IbGibRel8ns_V1 } from "@ibgib/ts-gib/dist/V1/types.mjs";
2
+ import { IbGibAddr } from "@ibgib/ts-gib/dist/types.mjs";
3
+
2
4
  import { KeystoneIbGib_V1 } from "../../keystone/keystone-types.mjs";
3
5
  import { SyncStage } from "../sync-constants.mjs";
4
6
  import { SyncMode, SyncConflictStrategy, } from "../sync-types.mjs";
5
7
  import { SYNC_SAGA_MSG_ATOM } from "./sync-saga-message-constants.mjs";
6
- import { IbGibAddr } from "@ibgib/ts-gib/dist/types.mjs";
8
+ import type { getDeltaDependencyGraph } from '../../common/other/graph-helper.mjs';
7
9
 
8
10
  export interface SyncSagaMessageIb_V1 {
9
11
  atom: typeof SYNC_SAGA_MSG_ATOM;
@@ -71,6 +73,50 @@ export interface SyncSagaMessageInitData_V1 extends SyncSagaMessageData_V1 {
71
73
  conflictStrategy?: SyncConflictStrategy;
72
74
  }
73
75
 
76
+ /**
77
+ * When an endpoing doesn't have a timeline or some part of it, then this info
78
+ * contains sufficient information for the other endpoint to know what addrs to
79
+ * send.
80
+ */
81
+ export interface SyncSagaRequestAddrInfo {
82
+ /**
83
+ * We know this addr exists, but we don't have it. If we don't know anything
84
+ * about this timeline, then this will equal {@link tjpAddr}
85
+ */
86
+ addr: IbGibAddr;
87
+ /**
88
+ * if we're talking about an ibgib with a timeline (with ibgib.rel8ns.tjp),
89
+ * then this will be that timeline's addr (tjpAddr).
90
+ */
91
+ tjpAddr?: IbGibAddr;
92
+ /**
93
+ * If this is truthy, then we already have something from this timeline and
94
+ * this will be the latest addr in that timeline.
95
+ *
96
+ * If falsy, then we are requesting the entire timeline be sent.
97
+ *
98
+ * This is to be used to calculate the delta graph.
99
+ * @see {@link getDeltaDependencyGraph}
100
+ */
101
+ latestAddrAlreadyHave?: IbGibAddr;
102
+ }
103
+
104
+ /**
105
+ * when one endpoint says "hey, i have these that you need", they create this.
106
+ */
107
+ export interface SyncSagaPushOfferInfo {
108
+ /**
109
+ * all addrs to be pushed, should be the entire delta dependency graph.
110
+ * @see {@link getDeltaDependencyGraph}
111
+ */
112
+ addrs: IbGibAddr[];
113
+ /**
114
+ * if we're talking about an ibgib with a timeline (with ibgib.rel8ns.tjp),
115
+ * then this will be that timeline's addr (tjpAddr).
116
+ */
117
+ tjpAddr?: IbGibAddr;
118
+ }
119
+
74
120
  export interface SyncSagaConflictInfo {
75
121
  tjpAddr: string;
76
122
  /**
@@ -98,8 +144,8 @@ export interface SyncSagaConflictInfo {
98
144
 
99
145
  export interface SyncSagaMessageAckData_V1 extends SyncSagaMessageData_V1 {
100
146
  stage: typeof SyncStage.ack;
101
- deltaReqAddrs: string[];
102
- pushOfferAddrs: string[];
147
+ deltaRequestAddrInfos: SyncSagaRequestAddrInfo[];
148
+ pushOfferInfos: SyncSagaPushOfferInfo[];
103
149
  /**
104
150
  * Map of group keys (TJP addr/constant addr) to list of known addresses
105
151
  * in that timeline.
@@ -113,8 +159,14 @@ export interface SyncSagaMessageAckData_V1 extends SyncSagaMessageData_V1 {
113
159
  * it needs all of the dependencies of A^5 (including A^4), but it does
114
160
  * NOT need to send A^0-A^3 (and dependencies) because receiver already has
115
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
116
168
  */
117
- knowledgeVector?: { [tjpAddr: string]: string[] };
169
+ // knowledgeVector?: { [tjpAddr: string]: string[] };
118
170
  /**
119
171
  * List of identified conflicts.
120
172
  *
@@ -34,18 +34,19 @@ export function isValidSyncMode(mode: string): mode is SyncMode {
34
34
  // #region SyncConflictStrategy
35
35
  export const SYNC_CONFLICT_STRATEGY_ABORT = 'abort';
36
36
  export const SYNC_CONFLICT_STRATEGY_OPTIMISTIC = 'optimistic';
37
- export const SYNC_CONFLICT_STRATEGY_MANUAL = 'manual';
37
+ // export const SYNC_CONFLICT_STRATEGY_MANUAL = 'manual'; // not implemented yet
38
38
  export type SyncConflictStrategy =
39
39
  | typeof SYNC_CONFLICT_STRATEGY_ABORT
40
40
  | typeof SYNC_CONFLICT_STRATEGY_OPTIMISTIC
41
- | typeof SYNC_CONFLICT_STRATEGY_MANUAL;
41
+ // | typeof SYNC_CONFLICT_STRATEGY_MANUAL // not implemented yet
42
+ ;
42
43
  /**
43
44
  * @see {@link SyncOptions.conflictStrategy}
44
45
  */
45
46
  export const SyncConflictStrategy = {
46
47
  abort: SYNC_CONFLICT_STRATEGY_ABORT,
47
48
  optimistic: SYNC_CONFLICT_STRATEGY_OPTIMISTIC,
48
- manual: SYNC_CONFLICT_STRATEGY_MANUAL,
49
+ // manual: SYNC_CONFLICT_STRATEGY_MANUAL, // not implemented yet
49
50
  } satisfies { [key in SyncConflictStrategy]: SyncConflictStrategy };
50
51
  export const SYNC_CONFLICT_STRATEGY_VALID_VALUES = Object.values(SyncConflictStrategy);
51
52
  export function isValidSyncConflictStrategy(strategy: string): strategy is SyncConflictStrategy {
@@ -53,15 +54,47 @@ export function isValidSyncConflictStrategy(strategy: string): strategy is SyncC
53
54
  }
54
55
  // #endregion SyncConflictStrategy
55
56
 
57
+ export interface NextSagaFrameInfo_Frame {
58
+ frame: SyncIbGib_V1;
59
+ payloadIbGibsDomain?: IbGib_V1[];
60
+ // conflictInfos?: SyncSagaConflictInfo;
61
+ responseWasNull?: undefined;
62
+ }
63
+ export interface NextSagaFrameInfo_Null {
64
+ frame: never;
65
+ payloadIbGibsDomain?: never;
66
+ conflictInfos?: never;
67
+ responseWasNull: true;
68
+ }
56
69
  /**
57
70
  * Result of handling a saga frame.
58
- * Separates control and domain payloads.
71
+ *
72
+ * ## notes
73
+ *
74
+ * After commit, this may have been a null response, so `frame` will not be
75
+ * defined, thus the discriminated union type.
59
76
  */
60
- export interface HandleSagaFrameResult {
61
- frame: SyncIbGib_V1;
62
- payloadIbGibsDomain?: IbGib_V1[];
63
- conflictInfos?: SyncSagaConflictInfo;
77
+ export type NextSagaFrameInfo =
78
+ NextSagaFrameInfo_Frame | NextSagaFrameInfo_Null;
79
+
80
+
81
+ export interface HandleSagaResponseContextResult_Base {
82
+ /**
83
+ * if truthy, handling saga context failed, else it succeeded.
84
+ */
85
+ errorMsg?: string;
86
+ /**
87
+ * inner handling of the frame itself
88
+ */
89
+ nextFrameInfo?: NextSagaFrameInfo;
90
+ }
91
+ export interface HandleSagaResponseContextResult_Frame extends HandleSagaResponseContextResult_Base {
92
+ nextFrameInfo: NextSagaFrameInfo;
93
+ }
94
+ export interface HandleSagaResponseContextResult_Error extends HandleSagaResponseContextResult_Base {
95
+ errorMsg: string;
64
96
  }
97
+ export type HandleSagaResponseContextResult = HandleSagaResponseContextResult_Frame | HandleSagaResponseContextResult_Error;
65
98
 
66
99
  export interface SyncOptions {
67
100
  /**
@@ -70,7 +103,7 @@ export interface SyncOptions {
70
103
  peer: SyncPeerWitness;
71
104
  /**
72
105
  * The ibgibs we wish to sync.
73
- *
106
+ *
74
107
  * These should all exist in {@link source}
75
108
  */
76
109
  domainIbGibs: IbGib_V1[],
@@ -101,14 +134,14 @@ export interface SyncOptions {
101
134
  /**
102
135
  * How to handle conflicts when both Source and Dest have diverged on the
103
136
  * same timeline.
104
- *
137
+ *
105
138
  * @default 'abort'
106
139
  */
107
140
  conflictStrategy?: SyncConflictStrategy;
108
141
  /**
109
- * If true, creates an ephemeral session identity for the sync process to
142
+ * If true, creates an ephemeral session identity for the sync process to
110
143
  * secure the sync transaction itself.
111
- *
144
+ *
112
145
  * @default true
113
146
  */
114
147
  useSessionIdentity?: boolean;
@@ -122,7 +155,7 @@ export interface SyncSagaInfo {
122
155
 
123
156
  /**
124
157
  * Observable stream of context updates happening during the saga.
125
- *
158
+ *
126
159
  * Subscribe to this to receive real-time progress throughout the sync
127
160
  * process, whenever the sync ibgib is evolved (including when receiving a
128
161
  * response from the peer).