@ibgib/core-gib 0.1.25 → 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 (38) hide show
  1. package/dist/common/other/ibgib-helper.d.mts +1 -1
  2. package/dist/common/other/ibgib-helper.d.mts.map +1 -1
  3. package/dist/common/other/ibgib-helper.mjs.map +1 -1
  4. package/dist/sync/sync-constants.d.mts +1 -0
  5. package/dist/sync/sync-constants.d.mts.map +1 -1
  6. package/dist/sync/sync-constants.mjs +1 -0
  7. package/dist/sync/sync-constants.mjs.map +1 -1
  8. package/dist/sync/sync-helpers.d.mts +5 -0
  9. package/dist/sync/sync-helpers.d.mts.map +1 -1
  10. package/dist/sync/sync-helpers.mjs +37 -1
  11. package/dist/sync/sync-helpers.mjs.map +1 -1
  12. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.d.mts +0 -2
  13. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.d.mts.map +1 -1
  14. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs +148 -62
  15. package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs.map +1 -1
  16. package/dist/sync/sync-peer/sync-peer-v1.d.mts +13 -29
  17. package/dist/sync/sync-peer/sync-peer-v1.d.mts.map +1 -1
  18. package/dist/sync/sync-peer/sync-peer-v1.mjs +17 -57
  19. package/dist/sync/sync-peer/sync-peer-v1.mjs.map +1 -1
  20. package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts +15 -1
  21. package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts.map +1 -1
  22. package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs +60 -4
  23. package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs.map +1 -1
  24. package/dist/sync/sync-saga-coordinator.d.mts +49 -3
  25. package/dist/sync/sync-saga-coordinator.d.mts.map +1 -1
  26. package/dist/sync/sync-saga-coordinator.mjs +180 -101
  27. package/dist/sync/sync-saga-coordinator.mjs.map +1 -1
  28. package/dist/sync/sync-types.d.mts +1 -3
  29. package/dist/sync/sync-types.d.mts.map +1 -1
  30. package/package.json +1 -1
  31. package/src/common/other/ibgib-helper.mts +1 -1
  32. package/src/sync/sync-constants.mts +1 -0
  33. package/src/sync/sync-helpers.mts +41 -1
  34. package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mts +147 -47
  35. package/src/sync/sync-peer/sync-peer-v1.mts +31 -74
  36. package/src/sync/sync-saga-context/sync-saga-context-helpers.mts +55 -7
  37. package/src/sync/sync-saga-coordinator.mts +232 -110
  38. package/src/sync/sync-types.mts +2 -2
@@ -18,7 +18,7 @@ import { InitializeSyncPeerOpts, SyncPeerData_V1, SyncPeerRel8ns_V1, SyncPeerWit
18
18
  import { LightWitnessBase_V1 } from '../../witness/light-witness-base-v1.mjs';
19
19
  import { IbGibSpaceAny } from '../../witness/space/space-base-v1.mjs';
20
20
  import { newupSubject } from '../../common/pubsub/subject/subject-helper.mjs';
21
- import { validateContextAndSagaFrame } from '../sync-saga-context/sync-saga-context-helpers.mjs';
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
24
  const logalot = GLOBAL_LOG_A_LOT || true;
@@ -178,34 +178,36 @@ export abstract class SyncPeer_V1<TInitializeOpts extends InitializeSyncPeerOpts
178
178
  if (validationErrors.length > 0) {
179
179
  throw new Error(`invalid context received. validationErrors: ${validationErrors} (E: 8b34c875c968af29bc433138e57a7826)`);
180
180
  }
181
- const authenticationErrors = await this.authenticateContext({ context });
181
+ const authenticationErrors = await authenticateContext({ context });
182
182
  if (authenticationErrors.length > 0) {
183
183
  throw new Error(`invalid context authentication. authenticationErrors: ${authenticationErrors} (E: da89da5ee1269aeb78952d475d607526)`);
184
184
  }
185
- const authorizationErrors = await this.authorizeContext({ context });
185
+ const authorizationErrors = await authorizeContext({ context });
186
186
  if (authorizationErrors.length > 0) {
187
187
  throw new Error(`invalid context authorization. authorizationErrors: ${authorizationErrors} (E: 8ddc284a758cf10ba829334c1babb826)`);
188
188
  }
189
189
 
190
190
  // at this point, we have a valid, authenticated, authorized context
191
191
 
192
- // 2. EXECUTE: Trigger Remote Processing
192
+ // execute the transfer of control domain ibgibs & outgoing payload
193
+ // ibgibs...
193
194
  const response = await this.sendContextRequest(context);
194
195
 
195
- if (!response) {
196
- if (logalot) { console.log(`${lc} No response from peer.`); }
197
- return undefined;
198
- }
199
-
200
- // at this point, all outgoing payload domain ibgibs have been sent.
201
- // we have received the response context, wherein the sync saga
202
- // frame/msg stone(s) and any keystones should be evolved. Depending
203
- // on the concrete implementation, if there are domain ibgibs to
204
- // receive, they may still be transferring. These will be published
205
- // to this.payloadIbGibsDomainReceived$
196
+ if (response) {
197
+ // at this point, all outgoing payload domain ibgibs have been sent.
198
+ // we have received the response context, wherein the sync saga
199
+ // frame/msg stone(s) and any keystones should be evolved. Depending
200
+ // on the concrete implementation, if there are domain ibgibs to
201
+ // receive, they may still be transferring. These will be published
202
+ // to this.payloadIbGibsDomainReceived$
206
203
 
207
- return response;
204
+ return response;
205
+ } else {
206
+ // response falsy. we could be done, or this could be an error.
207
+ if (logalot) { console.log(`${lc} No response from peer. this may be normal if we just sent the very last commit frame. (I: 1855b7728c8898e1f9c001f8170ba826)`); }
208
208
 
209
+ return undefined;
210
+ }
209
211
  } catch (error) {
210
212
  console.error(`${lc} ${extractErrorMsg(error)}`);
211
213
  throw error;
@@ -215,75 +217,30 @@ export abstract class SyncPeer_V1<TInitializeOpts extends InitializeSyncPeerOpts
215
217
  }
216
218
 
217
219
  /**
220
+ * At this point, this is a validated, authenticated and authorized context
221
+ * to send.
222
+ *
218
223
  * This is responsible for:
219
224
  *
220
- * * sending outgoing {@link context}, the sync saga frame and msg stone(s),
221
- * and identities...
225
+ * * physical sending outgoing {@link context}, the sync saga frame and msg
226
+ * stone(s), and identities...
222
227
  * * AND sending OUTGOING domain ibgibs
223
228
  * {@link SyncSagaContextIbGib_V1.payloadIbGibsDomain}
224
229
  * * getting back the other end's resultant context ibgib, sync saga frame
225
230
  * and msg stone(s), and identities in their entirety...
226
231
  * * AND stream/receiving the RESPONSE payload domain ibgibs, publishing
227
232
  * these to this.payloadIbGibsDomainReceived$.
233
+ * * BUT this should return as soon as the resultant context ibgib comes
234
+ * back.
228
235
  *
229
- * So this returns the RESPONSE context, possibly BEFORE the RESPONSE domain
230
- * ibgibs have been completely received/streamed. The coordinator is responsible
231
- */
232
- protected abstract sendContextRequest(context: SyncSagaContextIbGib_V1): Promise<SyncSagaContextIbGib_V1 | undefined>;
233
-
234
- /**
235
- * Pushes specific IbGib(s) (by address) from Local to Remote.
236
+ * So this returns the RESPONSE context, possibly BEFORE the response DOMAIN
237
+ * ibgibs have been completely received/streamed. The coordinator is
238
+ * responsible for awaiting this stream.
236
239
  *
237
- * Should NOT have to handle identifying if the remote already has it
238
- * (optimization), because the sync coordinator should be doing this in
239
- * its diffing algorithm.
240
+ * @returns next sync saga context if another round, or undefined if we're
241
+ * done. (might throw if there's an error?)
240
242
  */
241
- protected abstract push(addrs: IbGibAddr[]): Promise<void>;
242
-
243
- /**
244
- * Primitive: Pulls specific IbGib(s) (by address) from Remote to Local.
245
- */
246
- protected abstract pull(addrs: IbGibAddr[]): Promise<void>;
247
-
248
-
249
-
250
- /**
251
- * move to sync-peer-helpers.mts as a pure function?
252
- */
253
- protected async authenticateContext({ context }: { context: SyncSagaContextIbGib_V1 }): Promise<string[]> {
254
- const lc = `${this.lc}[${this.authenticateContext.name}]`;
255
- try {
256
- if (logalot) { console.log(`${lc} starting... (I: 2677a482dfa873dcd1aa04a3031ff826)`); }
257
-
258
- console.error(`${lc} NAG ERROR (NOT THROWN): not implemented. // todo: authenticate (v1 must have this after we get merge logic workflow going) (E: bc3a78f2dab18ab64c36d055a4b50526)`);
259
-
260
- return [];
261
- } catch (error) {
262
- console.error(`${lc} ${extractErrorMsg(error)}`);
263
- throw error;
264
- } finally {
265
- if (logalot) { console.log(`${lc} complete.`); }
266
- }
267
- }
268
-
269
- /**
270
- * move to sync-peer-helpers.mts as a pure function?
271
- */
272
- protected async authorizeContext({ context }: { context: SyncSagaContextIbGib_V1 }): Promise<string[]> {
273
- const lc = `${this.lc}[${this.authorizeContext.name}]`;
274
- try {
275
- if (logalot) { console.log(`${lc} starting... (I: 48c918b41ceec0cd489ca3b8819e6826)`); }
276
-
277
- console.error(`${lc} NAG ERROR (NOT THROWN): not implemented. authorize business logic (v1 must have this, but later when we are working on admin vs. student)(E: bc3a78f2dab18ab64c36d055a4b50526)`);
278
-
279
- return [];
280
- } catch (error) {
281
- console.error(`${lc} ${extractErrorMsg(error)}`);
282
- throw error;
283
- } finally {
284
- if (logalot) { console.log(`${lc} complete.`); }
285
- }
286
- }
243
+ protected abstract sendContextRequest(context: SyncSagaContextIbGib_V1): Promise<SyncSagaContextIbGib_V1 | undefined>;
287
244
 
288
245
  /**
289
246
  * Abstract accessor to get an IbGib from the Local space/store.
@@ -19,6 +19,7 @@ import {
19
19
  import { IbGibSpaceAny } from '../../witness/space/space-base-v1.mjs';
20
20
  import { putInSpace, registerNewIbGib } from '../../witness/space/space-helper.mjs';
21
21
  import { SyncIbGib_V1 } from '../sync-types.mjs';
22
+ import { validateSyncSagaFrame } from '../sync-helpers.mjs';
22
23
 
23
24
  const logalot = GLOBAL_LOG_A_LOT;
24
25
 
@@ -215,20 +216,27 @@ export async function validateContextAndSagaFrame({ context }: { context: SyncSa
215
216
  }
216
217
 
217
218
  if (context.sagaFrame) {
218
-
219
+ const sagaFrameErrors =
220
+ await validateSyncSagaFrame({ sagaIbGib: context.sagaFrame });
221
+ sagaFrameErrors.forEach(x => errors.push(x));
219
222
  } else {
220
223
  errors.push(`context.sagaFrame is falsy. (E: b4edd88f4963f493789f83b29ba2df26)`);
221
224
  }
222
225
 
223
- // validate the entire context graph intrinsically, including saga frame, stones, identity(s) (if applicable but not authentication, that will be done in a separate step)
224
-
226
+ // if this is already invalid, we could have intrinsic validation errors, which are a non-starter.
227
+ if (errors.length > 0) { return errors; /* <<<< returns early */ }
225
228
 
229
+ // validate the entire context graph intrinsically, including saga frame, stones, identity(s) (if applicable but not authentication, that will be done in a separate step)
226
230
 
227
- // ensure the non-dto properties on the context object (i.e. props
231
+ // ~~ensure the non-dto properties on the context object (i.e. props
228
232
  // that are not ib, gib, data, or rel8ns) match the data in the
229
- // context object
233
+ // context object~~ NO. THIS WILL BE IN A SEPARATE FUNCTION.
234
+ // See `validateContextDomainPayloadIbGibs`
235
+
236
+ // throw new Error(`not implemented (E: cb639658e1183fa6c8a4ebca023ba926)`);
230
237
 
231
- throw new Error(`not implemented (E: cb639658e1183fa6c8a4ebca023ba926)`);
238
+ console.error(`${lc} NAG ERROR MSG (NOT THROWN): not fully implemented yet (E: d574d85cb578637648ed403857f7a826)`);
239
+ return [];
232
240
  } catch (error) {
233
241
  console.error(`${lc} ${extractErrorMsg(error)}`);
234
242
  throw error;
@@ -239,7 +247,9 @@ export async function validateContextAndSagaFrame({ context }: { context: SyncSa
239
247
 
240
248
 
241
249
  /**
242
- * validates the payload ibgibs ({@link SyncSagaContextIbGib_V1.payloadIbGibsDomain}) intrinsically
250
+ * validates {@link SyncSagaContextIbGib_V1.payloadIbGibsDomain} intrinsically,
251
+ * and ensures that these payloadIbGibs also match the expected addrs in
252
+ * {@link SyncSagaContextData_V1}[{@link SYNC_SAGA_PAYLOAD_ADDRS_DOMAIN}].
243
253
  *
244
254
  * @returns empty array if valid, else validation errors
245
255
  */
@@ -248,6 +258,44 @@ export async function validateContextDomainPayloadIbGibs({ context }: { context:
248
258
  try {
249
259
  if (logalot) { console.log(`${lc} starting... (I: 9f9fe835bcc80c75aa7fd6d887fc0826)`); }
250
260
  console.error(`${lc} NAG MESSAGE (NOT THROWN). not implemented (E: bfe02ab36a227291a8f17ffc08f2ef26)`)
261
+ return [];
262
+ } catch (error) {
263
+ console.error(`${lc} ${extractErrorMsg(error)}`);
264
+ throw error;
265
+ } finally {
266
+ if (logalot) { console.log(`${lc} complete.`); }
267
+ }
268
+ }
269
+
270
+ /**
271
+ * move to sync-peer-helpers.mts as a pure function?
272
+ */
273
+ export async function authenticateContext({ context }: { context: SyncSagaContextIbGib_V1 }): Promise<string[]> {
274
+ const lc = `[${authenticateContext.name}]`;
275
+ try {
276
+ if (logalot) { console.log(`${lc} starting... (I: 2677a482dfa873dcd1aa04a3031ff826)`); }
277
+
278
+ console.error(`${lc} NAG ERROR (NOT THROWN): not implemented. // todo: authenticate (v1 must have this after we get merge logic workflow going) (E: bc3a78f2dab18ab64c36d055a4b50526)`);
279
+
280
+ return [];
281
+ } catch (error) {
282
+ console.error(`${lc} ${extractErrorMsg(error)}`);
283
+ throw error;
284
+ } finally {
285
+ if (logalot) { console.log(`${lc} complete.`); }
286
+ }
287
+ }
288
+
289
+ /**
290
+ * move to sync-peer-helpers.mts as a pure function?
291
+ */
292
+ export async function authorizeContext({ context }: { context: SyncSagaContextIbGib_V1 }): Promise<string[]> {
293
+ const lc = `[${authorizeContext.name}]`;
294
+ try {
295
+ if (logalot) { console.log(`${lc} starting... (I: 48c918b41ceec0cd489ca3b8819e6826)`); }
296
+
297
+ console.error(`${lc} NAG ERROR (NOT THROWN): not implemented. authorize business logic (v1 must have this, but later when we are working on admin vs. student)(E: bc3a78f2dab18ab64c36d055a4b50526)`);
298
+
251
299
  return [];
252
300
  } catch (error) {
253
301
  console.error(`${lc} ${extractErrorMsg(error)}`);