@ibgib/core-gib 0.0.65 → 0.0.66

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.
@@ -15,7 +15,8 @@ import {
15
15
  } from '../../../common/other/other-types.mjs';
16
16
  import { TagIbGib_V1 } from '../../../common/tag/tag-types.mjs';
17
17
  import {
18
- ParticipantInfo, StatusCode, SyncSagaInfo, SyncSpaceOptionsData,
18
+ OuterSpaceData,
19
+ ParticipantInfo, StatusCode, SyncSagaInfo, SyncSpaceIbGib, SyncSpaceOptionsData,
19
20
  SyncSpaceOptionsIbGib, SyncSpaceResultIbGib, SyncStatusIbGib,
20
21
  } from '../../../witness/space/outer-space/outer-space-types.mjs';
21
22
  import { IbGibSpaceData, IbGibSpaceRel8ns, SpaceId } from '../../../witness/space/space-types.mjs';
@@ -1956,76 +1957,76 @@ export abstract class MetaspaceBase implements MetaspaceService {
1956
1957
  }
1957
1958
  }
1958
1959
 
1959
- async unwrapEncryptedSyncSpace({
1960
- encryptedSpace,
1961
- fnPromptPassword,
1962
- dontPrompt,
1963
- space,
1964
- fnSpaceFactory,
1965
- }: {
1966
- encryptedSpace: IbGibSpaceAny,
1967
- fnPromptPassword: (title: string, msg: string) => Promise<string | null>,
1968
- dontPrompt?: boolean,
1969
- space?: IbGibSpaceAny,
1970
- fnSpaceFactory: (unencryptedSpaceData: any) => Promise<IbGibSpaceAny>,
1971
- }): Promise<IbGibSpaceAny> {
1972
- const lc = `${this.lc}[${this.unwrapEncryptedSyncSpace.name}]`;
1973
- try {
1974
- // validation
1975
- if (!space) { throw new Error(`space required (E: d4d3eaa2d7b9143cf1173b8ae6344c23)`); }
1976
- if (!encryptedSpace.rel8ns?.ciphertext) { throw new Error(`encryptedSpace is not a ciphertext (E: be5504a5e2b84f3eaa8fbd6e13aab659)`); }
1977
- if (encryptedSpace.rel8ns!.ciphertext!.length !== 1) { throw new Error(`only 1 ciphertext rel8n allowed... (E: e8ab2ec38ad844dfb229efc5b8981946)`); }
1978
-
1979
- // get ciphertext ibgib
1980
- const ciphertextAddr = encryptedSpace.rel8ns!.ciphertext![0];
1981
- const resCiphertext = await this.get({ addr: ciphertextAddr, space });
1982
- if (!resCiphertext.success) { throw new Error(`get ciphertext failed (E: e58b3471c0334cd7bc626998106e6547)`); }
1983
- if ((resCiphertext.ibGibs || []).length !== 1) { throw new Error(`get ciphertext retrieved non-1 length (eesh) (E: a3a1f00e827b4f88a42b4a7433cf1065)`); }
1984
- const ciphertextIbGib = resCiphertext.ibGibs![0] as CiphertextIbGib_V1;
1985
-
1986
- // get secrets associated with enciphered space
1987
- if (!encryptedSpace.rel8ns?.secret) { throw new Error(`!encryptionIbGib.rel8ns?.secret (E: 8bfed1541976433da9402d7d3a9138dd)`); }
1988
- const secretAddrs = encryptedSpace.rel8ns!.secret!;
1989
- const localUserSpace = await this.getLocalUserSpace({});
1990
- if (!localUserSpace) { throw new Error(`(UNEXPECTED) could not get localUserSpace? (E: 3c5687a15b3b58e3dcf1eca4f5fe5723) (E: c123b340177647968e10a6b119d84d2b)`); }
1991
- const argGetSecrets = await localUserSpace.argy({
1992
- argData: { ibGibAddrs: secretAddrs, cmd: 'get', }
1993
- });
1994
- const resSecrets = await localUserSpace.witness(argGetSecrets);
1995
- if (!resSecrets.data?.success || (resSecrets.ibGibs || []).length === 0) {
1996
- throw new Error(`couldn't get secret ibgibs (E: cb17687f842f4296a9ecf89d9a568e46)`);
1997
- }
1998
- const secretIbGibs = resSecrets.ibGibs.concat() as IbGib_V1<SecretData_V1>[];
1999
-
2000
- // get plaintext now that we have the ciphertext ibgib and secret ibgib(s)
2001
- const plaintextString = await this.getPlaintextString({
2002
- ciphertextIbGib,
2003
- fnPromptPassword,
2004
- dontPrompt,
2005
- secretIbGibs,
2006
- space,
2007
- });
2008
-
2009
- const syncSpaceData = JSON.parse(plaintextString);
2010
- if (syncSpaceData.type !== 'sync') { throw new Error(`syncSpaceData.type !== 'sync'...this is the only one implemented right now (E: 509b2373d6f8445ebe5bd6f27f62af93)`); }
2011
- if (syncSpaceData.subtype !== 'aws-dynamodb') { throw new Error(`syncSpaceData.subtype !== 'aws-dynamodb'...only one right now dude (E: b5caaf3b4c60438eb2cee58ce8e1d3f6)`); }
2012
-
2013
- // this is the original aws only implementation. I've just added (untested)
2014
- // a quick factory function where the consumer would do the following code.
2015
- const unwrappedSpace = await fnSpaceFactory(syncSpaceData);
2016
- return unwrappedSpace;
2017
- // so we have a syncspace data (only aws-dynamodb space right now).
2018
- // load this data into a space class with behavior (not just the dto).
2019
- // const awsSpace = new AWSDynamoSpace_V1(syncSpaceData, null);
2020
- // awsSpace.gib = await getGib({ ibGib: awsSpace, hasTjp: false });
2021
- // if (logalot) { console.log(`awsSpace.gib: ${awsSpace.gib}`); }
2022
- // return awsSpace;
2023
-
2024
- } catch (error) {
2025
- console.error(`${lc} ${error.message}`);
2026
- throw error;
2027
- }
2028
- }
1960
+ // async unwrapEncryptedSyncSpace({
1961
+ // encryptedSpace,
1962
+ // fnPromptPassword,
1963
+ // dontPrompt,
1964
+ // space,
1965
+ // fnSpaceFactory,
1966
+ // }: {
1967
+ // encryptedSpace: IbGibSpaceAny,
1968
+ // fnPromptPassword: (title: string, msg: string) => Promise<string | null>,
1969
+ // dontPrompt?: boolean,
1970
+ // space?: IbGibSpaceAny,
1971
+ // fnSpaceFactory: (syncSpaceIbGib: SyncSpaceIbGib) => Promise<IbGibSpaceAny>,
1972
+ // }): Promise<IbGibSpaceAny> {
1973
+ // const lc = `${this.lc}[${this.unwrapEncryptedSyncSpace.name}]`;
1974
+ // try {
1975
+ // // validation
1976
+ // if (!space) { throw new Error(`space required (E: d4d3eaa2d7b9143cf1173b8ae6344c23)`); }
1977
+ // if (!encryptedSpace.rel8ns?.ciphertext) { throw new Error(`encryptedSpace is not a ciphertext (E: be5504a5e2b84f3eaa8fbd6e13aab659)`); }
1978
+ // if (encryptedSpace.rel8ns!.ciphertext!.length !== 1) { throw new Error(`only 1 ciphertext rel8n allowed... (E: e8ab2ec38ad844dfb229efc5b8981946)`); }
1979
+
1980
+ // // get ciphertext ibgib
1981
+ // const ciphertextAddr = encryptedSpace.rel8ns!.ciphertext![0];
1982
+ // const resCiphertext = await this.get({ addr: ciphertextAddr, space });
1983
+ // if (!resCiphertext.success) { throw new Error(`get ciphertext failed (E: e58b3471c0334cd7bc626998106e6547)`); }
1984
+ // if ((resCiphertext.ibGibs || []).length !== 1) { throw new Error(`get ciphertext retrieved non-1 length (eesh) (E: a3a1f00e827b4f88a42b4a7433cf1065)`); }
1985
+ // const ciphertextIbGib = resCiphertext.ibGibs![0] as CiphertextIbGib_V1;
1986
+
1987
+ // // get secrets associated with enciphered space
1988
+ // if (!encryptedSpace.rel8ns?.secret) { throw new Error(`!encryptionIbGib.rel8ns?.secret (E: 8bfed1541976433da9402d7d3a9138dd)`); }
1989
+ // const secretAddrs = encryptedSpace.rel8ns!.secret!;
1990
+ // const localUserSpace = await this.getLocalUserSpace({});
1991
+ // if (!localUserSpace) { throw new Error(`(UNEXPECTED) could not get localUserSpace? (E: 3c5687a15b3b58e3dcf1eca4f5fe5723) (E: c123b340177647968e10a6b119d84d2b)`); }
1992
+ // const argGetSecrets = await localUserSpace.argy({
1993
+ // argData: { ibGibAddrs: secretAddrs, cmd: 'get', }
1994
+ // });
1995
+ // const resSecrets = await localUserSpace.witness(argGetSecrets);
1996
+ // if (!resSecrets.data?.success || (resSecrets.ibGibs || []).length === 0) {
1997
+ // throw new Error(`couldn't get secret ibgibs (E: cb17687f842f4296a9ecf89d9a568e46)`);
1998
+ // }
1999
+ // const secretIbGibs = resSecrets.ibGibs.concat() as IbGib_V1<SecretData_V1>[];
2000
+
2001
+ // // get plaintext now that we have the ciphertext ibgib and secret ibgib(s)
2002
+ // const plaintextString = await this.getPlaintextString({
2003
+ // ciphertextIbGib,
2004
+ // fnPromptPassword,
2005
+ // dontPrompt,
2006
+ // secretIbGibs,
2007
+ // space,
2008
+ // });
2009
+
2010
+ // const syncSpaceData = JSON.parse(plaintextString) as OuterSpaceData;
2011
+ // if (syncSpaceData.type !== 'sync') { throw new Error(`syncSpaceData.type !== 'sync'...this is the only one implemented right now (E: 509b2373d6f8445ebe5bd6f27f62af93)`); }
2012
+ // if (syncSpaceData.subtype !== 'aws-dynamodb') { throw new Error(`syncSpaceData.subtype !== 'aws-dynamodb'...only one right now dude (E: b5caaf3b4c60438eb2cee58ce8e1d3f6)`); }
2013
+
2014
+ // // this is the original aws only implementation. I've just added (untested)
2015
+ // // a quick factory function where the consumer would do the following code.
2016
+ // const unwrappedSpace = await fnSpaceFactory(syncSpaceData);
2017
+ // return unwrappedSpace;
2018
+ // // so we have a syncspace data (only aws-dynamodb space right now).
2019
+ // // load this data into a space class with behavior (not just the dto).
2020
+ // // const awsSpace = new AWSDynamoSpace_V1(syncSpaceData, null);
2021
+ // // awsSpace.gib = await getGib({ ibGib: awsSpace, hasTjp: false });
2022
+ // // if (logalot) { console.log(`awsSpace.gib: ${awsSpace.gib}`); }
2023
+ // // return awsSpace;
2024
+
2025
+ // } catch (error) {
2026
+ // console.error(`${lc} ${error.message}`);
2027
+ // throw error;
2028
+ // }
2029
+ // }
2029
2030
 
2030
2031
  /**
2031
2032
  * Caching user password secret in memory only.
@@ -2313,110 +2314,110 @@ export abstract class MetaspaceBase implements MetaspaceService {
2313
2314
  }
2314
2315
  }
2315
2316
 
2316
- async getSyncSpaces({
2317
- unwrapEncrypted,
2318
- createIfNone,
2319
- dontPrompt,
2320
- space,
2321
- outerspaceIds,
2322
- fnSpaceFactory,
2323
- fnPromptSecret,
2324
- fnPromptEncryption,
2325
- fnPromptOuterSpace,
2326
- }: {
2327
- unwrapEncrypted: boolean,
2328
- createIfNone: boolean,
2329
- /**
2330
- * If true, don't prompt the user if we don't have it already cached.
2331
- *
2332
- * We don't want the user to hit the page and then always have to type in
2333
- * the password, just because my password code sucks atow.
2334
- */
2335
- dontPrompt?: boolean,
2336
- space?: IbGibSpaceAny,
2337
- /**
2338
- * @see {@link syncIbGibs} arg of the same name
2339
- */
2340
- outerspaceIds?: SpaceId[],
2341
- fnSpaceFactory: (unencryptedSpaceData: any) => Promise<IbGibSpaceAny>,
2342
- fnPromptSecret: (space: IbGibSpaceAny) => Promise<SecretIbGib_V1 | undefined>,
2343
- fnPromptEncryption: (space: IbGibSpaceAny) => Promise<EncryptionIbGib_V1 | undefined>,
2344
- fnPromptOuterSpace: (space: IbGibSpaceAny) => Promise<IbGibSpaceAny | undefined>,
2345
- }): Promise<IbGibSpaceAny[]> {
2346
- const lc = `${this.lc}[${this.getSyncSpaces.name}]`;
2347
- try {
2348
- space = space ?? await this.getLocalUserSpace({});
2349
- if (!space) { throw new Error(`space falsy and localUserSpace not initialized (?) (E: bf09346708ba4d6e9a1389bd1b66d500)`); }
2350
-
2351
- // get existing
2352
- let appSyncSpaces: IbGibSpaceAny[] =
2353
- await this.getSpecialRel8dIbGibs<IbGibSpaceAny>({
2354
- type: "outerspaces",
2355
- rel8nName: SYNC_SPACE_REL8N_NAME,
2356
- space,
2357
- });
2358
-
2359
- // filter if applicable
2360
- const hasOuterspaceIds = (outerspaceIds?.length ?? 0) > 0;
2361
- if (hasOuterspaceIds) {
2362
- appSyncSpaces = appSyncSpaces.filter(x => outerspaceIds!.includes(x.data!.uuid!));
2363
- }
2364
-
2365
- // create if applicable
2366
- if (appSyncSpaces.length === 0) {
2367
- if (createIfNone) {
2368
- if (hasOuterspaceIds) { throw new Error(`(UNEXPECTED) both createIfNone true and outerspaceIds (filter) also true? you cannot have both of these set, it's one of the other. (E: 9caaa121dee3e41e6e29916614cd4e24)`); }
2369
- const createdReqs = await this._createOuterspaceAndRequiredIbGibs({
2370
- space,
2371
- fnPromptSecret,
2372
- fnPromptEncryption,
2373
- fnPromptOuterSpace,
2374
- });
2375
- if (createdReqs) {
2376
- appSyncSpaces = await this.getSpecialRel8dIbGibs<IbGibSpaceAny>({
2377
- type: "outerspaces",
2378
- rel8nName: SYNC_SPACE_REL8N_NAME,
2379
- space,
2380
- });
2381
- }
2382
- } else {
2383
- throw new Error(`No sync spaces found. First create a sync outerspace (like a cloud sync space) in order to synchronize with it (E: 8f395f226ac7b558b9317befefbcb724)`);
2384
- }
2385
- }
2386
-
2387
- // unwrap if requested
2388
- let resSpaces: IbGibSpaceAny[] = [];
2389
- if (unwrapEncrypted) {
2390
- for (let i = 0; i < appSyncSpaces.length; i++) {
2391
- let syncSpace = appSyncSpaces[i];
2392
-
2393
- if (syncSpace.rel8ns) {
2394
- if (syncSpace.rel8ns.ciphertext) {
2395
- syncSpace = await this.unwrapEncryptedSyncSpace({
2396
- encryptedSpace: syncSpace,
2397
- fnPromptPassword: this.getFnPromptPassword!(),
2398
- dontPrompt,
2399
- space,
2400
- fnSpaceFactory,
2401
- });
2402
- }
2403
-
2404
- resSpaces.push(syncSpace);
2405
- } else {
2406
- }
2407
-
2408
- }
2409
- } else {
2410
- // still (probably) encrypted
2411
- resSpaces = appSyncSpaces;
2412
- }
2413
-
2414
- return resSpaces;
2415
- } catch (error) {
2416
- console.error(`${lc} ${error.message}`);
2417
- return [];
2418
- }
2419
- }
2317
+ // async getSyncSpaces({
2318
+ // createIfNone,
2319
+ // dontPrompt,
2320
+ // space,
2321
+ // outerspaceIds,
2322
+ // // fnSpaceFactory,
2323
+ // fnPromptSecret,
2324
+ // fnPromptEncryption,
2325
+ // fnPromptOuterSpace,
2326
+ // }: {
2327
+ // // unwrapEncrypted: boolean,
2328
+ // createIfNone: boolean,
2329
+ // /**
2330
+ // * If true, don't prompt the user if we don't have it already cached.
2331
+ // *
2332
+ // * We don't want the user to hit the page and then always have to type in
2333
+ // * the password, just because my password code sucks atow.
2334
+ // */
2335
+ // dontPrompt?: boolean,
2336
+ // space?: IbGibSpaceAny,
2337
+ // /**
2338
+ // * @see {@link syncIbGibs} arg of the same name
2339
+ // */
2340
+ // outerspaceIds?: SpaceId[],
2341
+ // // fnSpaceFactory: (unencryptedSpaceData: any) => Promise<IbGibSpaceAny>,
2342
+ // fnPromptSecret: (space: IbGibSpaceAny) => Promise<SecretIbGib_V1 | undefined>,
2343
+ // fnPromptEncryption: (space: IbGibSpaceAny) => Promise<EncryptionIbGib_V1 | undefined>,
2344
+ // fnPromptOuterSpace: (space: IbGibSpaceAny) => Promise<IbGibSpaceAny | undefined>,
2345
+ // }): Promise<SyncSpaceIbGib[]> {
2346
+ // const lc = `${this.lc}[${this.getSyncSpaces.name}]`;
2347
+ // try {
2348
+ // space = space ?? await this.getLocalUserSpace({});
2349
+ // if (!space) { throw new Error(`space falsy and localUserSpace not initialized (?) (E: bf09346708ba4d6e9a1389bd1b66d500)`); }
2350
+
2351
+ // // get existing
2352
+ // let resSyncSpaces: SyncSpaceIbGib[] =
2353
+ // await this.getSpecialRel8dIbGibs<SyncSpaceIbGib>({
2354
+ // type: "outerspaces",
2355
+ // rel8nName: SYNC_SPACE_REL8N_NAME,
2356
+ // space,
2357
+ // });
2358
+
2359
+ // // filter if applicable
2360
+ // const hasOuterspaceIds = (outerspaceIds?.length ?? 0) > 0;
2361
+ // if (hasOuterspaceIds) {
2362
+ // resSyncSpaces = resSyncSpaces.filter(x => outerspaceIds!.includes(x.data!.uuid!));
2363
+ // }
2364
+
2365
+ // // create if applicable
2366
+ // if (resSyncSpaces.length === 0) {
2367
+ // if (createIfNone) {
2368
+ // if (hasOuterspaceIds) { throw new Error(`(UNEXPECTED) both createIfNone true and outerspaceIds (filter) also true? you cannot have both of these set, it's one of the other. (E: 9caaa121dee3e41e6e29916614cd4e24)`); }
2369
+ // const createdReqs = await this._createOuterspaceAndRequiredIbGibs({
2370
+ // space,
2371
+ // fnPromptSecret,
2372
+ // fnPromptEncryption,
2373
+ // fnPromptOuterSpace,
2374
+ // });
2375
+ // if (createdReqs) {
2376
+ // resSyncSpaces = await this.getSpecialRel8dIbGibs<SyncSpaceIbGib>({
2377
+ // type: "outerspaces",
2378
+ // rel8nName: SYNC_SPACE_REL8N_NAME,
2379
+ // space,
2380
+ // });
2381
+ // }
2382
+ // } else {
2383
+ // throw new Error(`No sync spaces found. First create a sync outerspace (like a cloud sync space) in order to synchronize with it (E: 8f395f226ac7b558b9317befefbcb724)`);
2384
+ // }
2385
+ // }
2386
+
2387
+ // // unwrap if requested
2388
+ // // let resSpaces: SyncSpaceIbGib[] = [];
2389
+ // // if (unwrapEncrypted) {
2390
+ // // for (let i = 0; i < syncSpaceIbGibs.length; i++) {
2391
+ // // let syncSpace = syncSpaceIbGibs[i];
2392
+
2393
+ // // if (syncSpace.rel8ns) {
2394
+ // // if (syncSpace.rel8ns.ciphertext) {
2395
+ // // syncSpace = await this.unwrapEncryptedSyncSpace({
2396
+ // // encryptedSpace: syncSpace,
2397
+ // // fnPromptPassword: this.getFnPromptPassword!(),
2398
+ // // dontPrompt,
2399
+ // // space,
2400
+ // // fnSpaceFactory,
2401
+ // // });
2402
+ // // }
2403
+
2404
+ // // resSpaces.push(syncSpace);
2405
+ // // } else {
2406
+ // // }
2407
+
2408
+ // // }
2409
+ // // } else {
2410
+ // // still (probably) encrypted
2411
+ // // resSpaces = syncSpaceIbGibs;
2412
+ // // }
2413
+
2414
+ // // return resSpaces;
2415
+ // return resSyncSpaces;
2416
+ // } catch (error) {
2417
+ // console.error(`${lc} ${error.message}`);
2418
+ // return [];
2419
+ // }
2420
+ // }
2420
2421
 
2421
2422
  // async createRobbotIbGib({
2422
2423
  // robbotData,
@@ -2586,39 +2587,22 @@ export abstract class MetaspaceBase implements MetaspaceService {
2586
2587
 
2587
2588
  async syncIbGibs({
2588
2589
  dependencyGraphIbGibs,
2589
- // confirm,
2590
+ syncSpaceIbGibs,
2590
2591
  // watch,
2591
- outerspaceIds,
2592
- fnPreSyncProgress,
2593
- fnSpaceFactory,
2594
- fnPromptSecret,
2595
- fnPromptEncryption,
2596
- fnPromptOuterSpace,
2597
2592
  }: {
2593
+ /**
2594
+ * @see {@link MetaspaceService.syncIbGibs}
2595
+ */
2598
2596
  dependencyGraphIbGibs?: IbGib_V1[],
2599
- // confirm?: boolean,
2597
+ /**
2598
+ * @see {@link MetaspaceService.syncIbGibs}
2599
+ */
2600
+ syncSpaceIbGibs: IbGibSpaceAny[],
2600
2601
  // /**
2601
2602
  // * If true, will watch ibgibs in dependency graph that have timelines
2602
2603
  // * (tjps).
2603
2604
  // */
2604
2605
  // watch?: boolean,
2605
- /**
2606
- * if provided, these will determine which outerspace(s) we will sync
2607
- * the {@link dependencyGraphIbGibs} with.
2608
- */
2609
- outerspaceIds?: SpaceId[],
2610
- /**
2611
- * The meat of the sync process is tracked via a status within the sync
2612
- * spaces themselves. I'm addign this fn to track the pre and post progress
2613
- * stuff, since decrypting takes some time, and building the dependency
2614
- * graphs takes time. Both of these happen before the actual syncing occurs
2615
- * in the spaces.
2616
- */
2617
- fnPreSyncProgress?: (msg: string) => Promise<void>,
2618
- fnSpaceFactory: (unencryptedSpaceData: any) => Promise<IbGibSpaceAny>,
2619
- fnPromptSecret: (space: IbGibSpaceAny) => Promise<SecretIbGib_V1 | undefined>,
2620
- fnPromptEncryption: (space: IbGibSpaceAny) => Promise<EncryptionIbGib_V1 | undefined>,
2621
- fnPromptOuterSpace: (space: IbGibSpaceAny) => Promise<IbGibSpaceAny | undefined>,
2622
2606
  }): Promise<SyncSagaInfo[] | undefined> {
2623
2607
  const lc = `${this.lc}[${this.syncIbGibs.name}]`;
2624
2608
  // map of saga infos across all spaces
@@ -2665,7 +2649,8 @@ export abstract class MetaspaceBase implements MetaspaceService {
2665
2649
 
2666
2650
  // #region validate
2667
2651
  if (logalot) { console.log(`${lc} starting...`); }
2668
- if (!dependencyGraphIbGibs || dependencyGraphIbGibs.length === 0) { throw new Error(`ibGibs required. (E: 404c36475fb84fc285a23a67c0b8fcb2)`); }
2652
+ if (!dependencyGraphIbGibs || dependencyGraphIbGibs.length === 0) { throw new Error(`dependencyGraphIbGibs required. (E: 404c36475fb84fc285a23a67c0b8fcb2)`); }
2653
+ if (!syncSpaceIbGibs || syncSpaceIbGibs.length === 0) { throw new Error(`syncSpaceIbGibs required (E: c5a022454b9ce34856e141e61e337d24)`); }
2669
2654
  // #endregion
2670
2655
 
2671
2656
  const localUserSpace = await this.getLocalUserSpace({});
@@ -2674,52 +2659,20 @@ export abstract class MetaspaceBase implements MetaspaceService {
2674
2659
 
2675
2660
  // #region get sync spaces and build participant infos
2676
2661
  if (logalot) { console.log(`${lc} get sync spaces (returns if none)`); }
2677
- console.timeLog(syncTimelogName, 'getAppSyncSpaces starting (unwrapEncrypted is true) starting...');
2678
- if (fnPreSyncProgress) { fnPreSyncProgress('getting app sync spaces... (I: aa2e8f32ab26457bad703218aa7fb47d)'); }
2679
- const appSyncSpaces: IbGibSpaceAny[] = await this.getSyncSpaces({
2680
- unwrapEncrypted: true,
2681
- createIfNone: true,
2682
- space: localUserSpace,
2683
- outerspaceIds,
2684
- fnSpaceFactory,
2685
- fnPromptSecret,
2686
- fnPromptEncryption,
2687
- fnPromptOuterSpace,
2688
- });
2689
- if (fnPreSyncProgress) { fnPreSyncProgress('build complete. (I: 391a9aa7749d45b1aecf9a0010d9937f)'); }
2690
- console.timeLog(syncTimelogName, 'getAppSyncSpaces starting (unwrapEncrypted is true) complete.');
2691
- if (appSyncSpaces.length === 0) {
2692
- const msg = `Hmm, we seem to not have any sync spaces, and we can't exactly sync without them. Sometimes this is because of a wrong password? (I: 902bd3e00c3246abb646a750f2f2b782)`;
2693
- if (logalot) { console.log(`${lc} ${msg}`) };
2694
- const fnAlert = this.getFnAlert!();
2695
- await fnAlert({ title: "Sync Cancelled", msg });
2696
- this._syncing = false;
2697
- console.timeLog(syncTimelogName, 'cancelled');
2698
- console.timeEnd(syncTimelogName);
2699
- return undefined; /* <<<< returns early */
2700
- }
2701
- // const localUserSpace = await this.getLocalUserSpace({});
2702
2662
  const participants: ParticipantInfo[] = [
2703
2663
  // local user space is the src
2704
2664
  { id: localUserSpace.data.uuid, gib: localUserSpace.gib, s_d: 'src', },
2705
2665
 
2706
2666
  // each sync space is a destination
2707
- ...appSyncSpaces.map(s => {
2708
- if (!s.data) { throw new Error(`space.data required. (E: 3c192771e84445a4b6476d5193b07e9d)`); }
2709
- if (!s.data.uuid) { throw new Error(`space.data.uuid required. (E: d27e9998227840f99d45a3ed245f3196)`); }
2710
- if (!s.gib) { throw new Error(`space.gib required. (E: db73aceb2f8445d8964ae49b59957072)`); }
2711
- return { id: s.data.uuid, gib: s.gib, s_d: 'dest', } as ParticipantInfo;
2667
+ ...syncSpaceIbGibs.map(s => {
2668
+ if (!s.data) { throw new Error(`syncSpaceIbGib.data required. (E: 3c192771e84445a4b6476d5193b07e9d)`); }
2669
+ if (!s.data.uuid) { throw new Error(`syncSpaceIbGib.data.uuid required. (E: d27e9998227840f99d45a3ed245f3196)`); }
2670
+ if (!s.gib) { throw new Error(`syncSpaceIbGib.gib required. (E: db73aceb2f8445d8964ae49b59957072)`); }
2671
+ return { id: s.data.uuid, gib: s.gib, s_d: 'dest', } satisfies ParticipantInfo;
2712
2672
  }),
2713
2673
  ];
2714
2674
  // #endregion
2715
2675
 
2716
- // if (fnPreSyncProgress) { fnPreSyncProgress('building dependency graph... (I: ae178a39c2594557b6d0489b02336ecd)'); }
2717
- // get **ALL** ibgibs that we'll need to put/merge
2718
- // const allIbGibsToSync: { [addr: string]: IbGib_V1 } = {};
2719
- // dependencyGraphIbGibs.forEach(x => { allIbGibsToSync[getIbGibAddr({ ibGib: x })] = x });
2720
-
2721
- // await this._getAllIbGibsToSyncFromGraph({ dependencyGraphIbGibs, space: localUserSpace });
2722
-
2723
2676
  // _NOW_ we can finally put/merge into sync spaces.
2724
2677
  // this returns to us the most recent versions which we can update
2725
2678
  // our local timelines if we so choose (which we will).
@@ -2730,7 +2683,7 @@ export abstract class MetaspaceBase implements MetaspaceService {
2730
2683
  if (logalot) { console.log(`${lc} syncing to spaces in parallel...`); }
2731
2684
  const multiSpaceOpId = await getUUID();
2732
2685
  const allSagaInfos: SyncSagaInfo[] = [];
2733
- const startSyncPromises: Promise<void>[] = appSyncSpaces.map(async syncSpace => {
2686
+ const startSyncPromises: Promise<void>[] = syncSpaceIbGibs.map(async syncSpace => {
2734
2687
  // create the info that will track progress over entire sync saga
2735
2688
  const sagaInfo =
2736
2689
  await this._createNewSyncSagaInfo({
@@ -2775,21 +2728,21 @@ export abstract class MetaspaceBase implements MetaspaceService {
2775
2728
  return allSagaInfos;
2776
2729
  } catch (error) {
2777
2730
  console.error(`${lc} ${error.message}`);
2778
- await this.finalizeAllSyncSagas_NoThrow({ error });
2731
+ await this._finalizeAllSyncSagas_NoThrow({ error });
2779
2732
  throw error;
2780
2733
  } finally {
2781
2734
  if (logalot) { console.log(`${lc} complete.`); }
2782
2735
  }
2783
2736
  }
2784
2737
 
2785
- protected async finalizeSyncSaga({
2738
+ protected async _finalizeSyncSaga({
2786
2739
  sagaInfo,
2787
2740
  error,
2788
2741
  }: {
2789
2742
  sagaInfo: SyncSagaInfo,
2790
2743
  error?: any,
2791
2744
  }): Promise<void> {
2792
- const lc = `${this.lc}[${this.finalizeSyncSaga.name}]`;
2745
+ const lc = `${this.lc}[${this._finalizeSyncSaga.name}]`;
2793
2746
  try {
2794
2747
  if (logalot) { console.log(`${lc} starting...`); }
2795
2748
  if (sagaInfo.complete) { return; }
@@ -2838,18 +2791,18 @@ export abstract class MetaspaceBase implements MetaspaceService {
2838
2791
  }
2839
2792
  }
2840
2793
 
2841
- protected async finalizeAllSyncSagas_NoThrow({
2794
+ protected async _finalizeAllSyncSagas_NoThrow({
2842
2795
  error,
2843
2796
  }: {
2844
2797
  error?: any,
2845
2798
  }): Promise<void> {
2846
- const lc = `${this.lc}[${this.finalizeAllSyncSagas_NoThrow.name}]`;
2799
+ const lc = `${this.lc}[${this._finalizeAllSyncSagas_NoThrow.name}]`;
2847
2800
  try {
2848
2801
  const syncSagaInfos_NotComplete =
2849
2802
  Object.values(this.sagaInfoMap).filter(x => !x.complete);
2850
2803
  for (let i = 0; i < syncSagaInfos_NotComplete.length; i++) {
2851
2804
  const sagaInfo = syncSagaInfos_NotComplete[i];
2852
- await this.finalizeSyncSaga({ sagaInfo, error });
2805
+ await this._finalizeSyncSaga({ sagaInfo, error });
2853
2806
  }
2854
2807
  } catch (error) {
2855
2808
  console.error(`${lc}(UNEXPECTED) ${error.message}`);
@@ -2976,18 +2929,10 @@ export abstract class MetaspaceBase implements MetaspaceService {
2976
2929
  protected async _startSync({
2977
2930
  syncSagaInfo,
2978
2931
  // watch,
2979
- // confirm,
2980
2932
  syncTimelogName,
2981
2933
  }: {
2982
2934
  syncSagaInfo: SyncSagaInfo,
2983
2935
  // watch?: boolean,
2984
- /**
2985
- * Will confirm via checking existence of ibgibs in sync space after
2986
- * writing them.
2987
- *
2988
- * NOTE: IGNORED ATM
2989
- */
2990
- // confirm?: boolean,
2991
2936
  syncTimelogName: string,
2992
2937
  }): Promise<SyncSpaceResultIbGib> {
2993
2938
  const lc = `${this.lc}[${this._startSync.name}]`;
@@ -3112,7 +3057,7 @@ export abstract class MetaspaceBase implements MetaspaceService {
3112
3057
  const emsg = `${lc}(sagaId: ${sagaInfo.sagaId}) syncStatus$.error: ${error}`;
3113
3058
  console.error(emsg);
3114
3059
  // await this.getFnAlert!()({title: 'couldnt this.syncIbGibs...', msg: emsg});
3115
- await this.finalizeSyncSaga({ sagaInfo, error: emsg });
3060
+ await this._finalizeSyncSaga({ sagaInfo, error: emsg });
3116
3061
  },
3117
3062
  complete: async () => {
3118
3063
  if (logalot) { console.log(`${lc}(sagaId: ${sagaInfo.sagaId}) syncStatus$.complete.`); }
@@ -3170,11 +3115,11 @@ export abstract class MetaspaceBase implements MetaspaceService {
3170
3115
  break;
3171
3116
 
3172
3117
  case StatusCode.merged_dna:
3173
- await this.handleSyncStatus_Merged({ status });
3118
+ await this._handleSyncStatus_Merged({ status });
3174
3119
  break;
3175
3120
 
3176
3121
  case StatusCode.merged_state:
3177
- await this.handleSyncStatus_Merged({ status });
3122
+ await this._handleSyncStatus_Merged({ status });
3178
3123
  break;
3179
3124
 
3180
3125
  case StatusCode.already_synced:
@@ -3183,7 +3128,7 @@ export abstract class MetaspaceBase implements MetaspaceService {
3183
3128
  break;
3184
3129
 
3185
3130
  case StatusCode.completed:
3186
- await this.handleSyncStatus_Complete({ sagaInfo });
3131
+ await this._handleSyncStatus_Complete({ sagaInfo });
3187
3132
  break;
3188
3133
 
3189
3134
  case StatusCode.undefined:
@@ -3205,12 +3150,12 @@ export abstract class MetaspaceBase implements MetaspaceService {
3205
3150
  }
3206
3151
  };
3207
3152
 
3208
- protected async handleSyncStatus_Merged({
3153
+ protected async _handleSyncStatus_Merged({
3209
3154
  status,
3210
3155
  }: {
3211
3156
  status: SyncStatusIbGib,
3212
3157
  }): Promise<void> {
3213
- const lc = `${this.lc}[${this.handleSyncStatus_Merged.name}]`;
3158
+ const lc = `${this.lc}[${this._handleSyncStatus_Merged.name}]`;
3214
3159
  try {
3215
3160
  if (logalot) { console.log(`${lc} starting...`); }
3216
3161
  // #region validate
@@ -3294,24 +3239,24 @@ export abstract class MetaspaceBase implements MetaspaceService {
3294
3239
  }
3295
3240
  }
3296
3241
 
3297
- protected async handleSyncStatus_Complete({
3242
+ protected async _handleSyncStatus_Complete({
3298
3243
  sagaInfo,
3299
3244
  }: {
3300
3245
  sagaInfo: SyncSagaInfo,
3301
3246
  }): Promise<void> {
3302
- const lc = `${this.lc}[${this.handleSyncStatus_Complete.name}]`;
3247
+ const lc = `${this.lc}[${this._handleSyncStatus_Complete.name}]`;
3303
3248
  try {
3304
3249
  // cleanup just this saga, which corresponds to a single sync space.
3305
- await this.finalizeSyncSaga({ sagaInfo });
3250
+ await this._finalizeSyncSaga({ sagaInfo });
3306
3251
 
3307
3252
  // if this is the last saga across all spaces, clean up the rest.
3308
3253
  const allSagaInfos = Object.values(this.sagaInfoMap);
3309
3254
  if (allSagaInfos.every(x => x.complete)) {
3310
- await this.finalizeAllSyncSagas_NoThrow({});
3255
+ await this._finalizeAllSyncSagas_NoThrow({});
3311
3256
  }
3312
3257
  } catch (error) {
3313
3258
  console.error(`${lc} ${error.message}`);
3314
- await this.finalizeAllSyncSagas_NoThrow({ error });
3259
+ await this._finalizeAllSyncSagas_NoThrow({ error });
3315
3260
  }
3316
3261
  }
3317
3262
 
@@ -3443,97 +3388,97 @@ export abstract class MetaspaceBase implements MetaspaceService {
3443
3388
  }
3444
3389
  }
3445
3390
 
3446
- protected async handleWatchTjpUpdates({
3447
- updates,
3448
- outerSpace,
3449
- localUserSpace,
3450
- }: {
3451
- updates: { [tjpAddr: string]: IbGibAddr; }
3452
- outerSpace: IbGibSpaceAny,
3453
- localUserSpace: IbGibSpaceAny,
3454
- }): Promise<void> {
3455
- const lc = `${this.lc}[${this.handleWatchTjpUpdates.name}]`;
3456
- if (logalot) { console.log(`${lc} starting...`); }
3457
- try {
3458
- if (!outerSpace.data) { throw new Error(`outerSpace.data falsy (E: b5fde89e87bef9b8b6ce38e24be4a823)`); }
3459
-
3460
- /**
3461
- * compile list of addrs we have locally for all updates, so we don't try
3462
- * to download them from outer space unnecessarily.
3463
- */
3464
- const latestAddrsLocallyWithUpdate: IbGibAddr[] = [];
3465
- const tjpAddrs = Object.keys(updates);
3466
- const latestAddrs_Store = Object.values(updates);
3467
- for (let i = 0; i < tjpAddrs.length; i++) {
3468
- const tjpAddr = tjpAddrs[i];
3469
- if (logalot) { console.log(`${lc} tjpAddr: ${tjpAddr}`); }
3470
- const latestAddrLocally = await this.getLatestAddr({ tjpAddr }) ?? tjpAddr;
3471
- if (
3472
- !latestAddrs_Store.includes(latestAddrLocally) &&
3473
- !latestAddrsLocallyWithUpdate.includes(latestAddrLocally)
3474
- ) {
3475
- latestAddrsLocallyWithUpdate.push(latestAddrLocally);
3476
- }
3477
- }
3478
- if (latestAddrsLocallyWithUpdate.length === 0) {
3479
- if (logalot) { console.log(`${lc} latestAddrsLocallyWithUpdate.length === 0. We already had all of the updates locally perhaps. Returning early. (I: 844193c515084d0ebc348349f1ac41f4)`); }
3480
- return; /* <<<< returns early */
3481
- }
3482
-
3483
- /**
3484
- * LOCAL dependencies for latest LOCAL addrs for all tjpAddrs in updates.
3485
- */
3486
- const localDependencyGraphs = await this.getDependencyGraph({
3487
- ibGibAddrs: latestAddrsLocallyWithUpdate,
3488
- live: true,
3489
- maxRetries: DEFAULT_MAX_RETRIES_GET_DEPENDENCY_GRAPH_OUTERSPACE,
3490
- msBetweenRetries: DEFAULT_MS_BETWEEN_RETRIES_GET_DEPENDENCY_GRAPH_OUTERSPACE,
3491
- space: localUserSpace,
3492
- });
3493
-
3494
- /** all addrs we already have locally */
3495
- const addrsAlreadyStoredLocally = Object.keys(localDependencyGraphs);
3496
-
3497
- // get dependency graph from outer space, skipping all addrs in local already
3498
- const newerAddrsFromOuterSpace: IbGibAddr[] = Object.values(updates);
3499
- const newerIbGibDependencyGraphFromOuterSpace = await getDependencyGraph({
3500
- ibGibAddrs: newerAddrsFromOuterSpace,
3501
- live: false,
3502
- skipAddrs: addrsAlreadyStoredLocally,
3503
- space: outerSpace,
3504
- });
3505
- const newerIbGibsFromOuterSpace: IbGib_V1[] =
3506
- Object.values(newerIbGibDependencyGraphFromOuterSpace);
3507
-
3508
- if (logalot) { console.log(`${lc} got ${newerIbGibsFromOuterSpace.length} ibGibs from outerspace`); }
3509
-
3510
- // save locally
3511
- if (logalot) { console.log(`${lc} saving new ibgibs from outerspace in local space...`); }
3512
- if (newerIbGibsFromOuterSpace.length > 0) {
3513
- await this.put({ ibGibs: newerIbGibsFromOuterSpace });
3514
-
3515
- // register the newest tjp ibGibs locally
3516
- if (logalot) { console.log(`${lc} registering "new" updated tjp ibgibs locally...`); }
3517
- for (let i = 0; i < tjpAddrs.length; i++) {
3518
- const tjpAddr = tjpAddrs[i];
3519
- const updatedAddr = updates[tjpAddr];
3520
- if (!addrsAlreadyStoredLocally.includes(updatedAddr)) {
3521
- const updatedIbGib = newerIbGibDependencyGraphFromOuterSpace[updatedAddr];
3522
- if (!updatedIbGib) {
3523
- throw new Error(`did not get updatedIbGib (${updatedAddr}) from outerspace (${outerSpace.data.uuid}) (E: 818de70f5b444a3ba198ba6480a15b04)`);
3524
- }
3525
- await this.registerNewIbGib({ ibGib: updatedIbGib });
3526
- }
3527
- }
3528
- }
3529
-
3530
- } catch (error) {
3531
- console.error(`${lc} ${error.message}`);
3532
- // does not rethrow
3533
- } finally {
3534
- if (logalot) { console.log(`${lc} complete.`); }
3535
- }
3536
- }
3391
+ // protected async handleWatchTjpUpdates({
3392
+ // updates,
3393
+ // outerSpace,
3394
+ // localUserSpace,
3395
+ // }: {
3396
+ // updates: { [tjpAddr: string]: IbGibAddr; }
3397
+ // outerSpace: IbGibSpaceAny,
3398
+ // localUserSpace: IbGibSpaceAny,
3399
+ // }): Promise<void> {
3400
+ // const lc = `${this.lc}[${this.handleWatchTjpUpdates.name}]`;
3401
+ // if (logalot) { console.log(`${lc} starting...`); }
3402
+ // try {
3403
+ // if (!outerSpace.data) { throw new Error(`outerSpace.data falsy (E: b5fde89e87bef9b8b6ce38e24be4a823)`); }
3404
+
3405
+ // /**
3406
+ // * compile list of addrs we have locally for all updates, so we don't try
3407
+ // * to download them from outer space unnecessarily.
3408
+ // */
3409
+ // const latestAddrsLocallyWithUpdate: IbGibAddr[] = [];
3410
+ // const tjpAddrs = Object.keys(updates);
3411
+ // const latestAddrs_Store = Object.values(updates);
3412
+ // for (let i = 0; i < tjpAddrs.length; i++) {
3413
+ // const tjpAddr = tjpAddrs[i];
3414
+ // if (logalot) { console.log(`${lc} tjpAddr: ${tjpAddr}`); }
3415
+ // const latestAddrLocally = await this.getLatestAddr({ tjpAddr }) ?? tjpAddr;
3416
+ // if (
3417
+ // !latestAddrs_Store.includes(latestAddrLocally) &&
3418
+ // !latestAddrsLocallyWithUpdate.includes(latestAddrLocally)
3419
+ // ) {
3420
+ // latestAddrsLocallyWithUpdate.push(latestAddrLocally);
3421
+ // }
3422
+ // }
3423
+ // if (latestAddrsLocallyWithUpdate.length === 0) {
3424
+ // if (logalot) { console.log(`${lc} latestAddrsLocallyWithUpdate.length === 0. We already had all of the updates locally perhaps. Returning early. (I: 844193c515084d0ebc348349f1ac41f4)`); }
3425
+ // return; /* <<<< returns early */
3426
+ // }
3427
+
3428
+ // /**
3429
+ // * LOCAL dependencies for latest LOCAL addrs for all tjpAddrs in updates.
3430
+ // */
3431
+ // const localDependencyGraphs = await this.getDependencyGraph({
3432
+ // ibGibAddrs: latestAddrsLocallyWithUpdate,
3433
+ // live: true,
3434
+ // maxRetries: DEFAULT_MAX_RETRIES_GET_DEPENDENCY_GRAPH_OUTERSPACE,
3435
+ // msBetweenRetries: DEFAULT_MS_BETWEEN_RETRIES_GET_DEPENDENCY_GRAPH_OUTERSPACE,
3436
+ // space: localUserSpace,
3437
+ // });
3438
+
3439
+ // /** all addrs we already have locally */
3440
+ // const addrsAlreadyStoredLocally = Object.keys(localDependencyGraphs);
3441
+
3442
+ // // get dependency graph from outer space, skipping all addrs in local already
3443
+ // const newerAddrsFromOuterSpace: IbGibAddr[] = Object.values(updates);
3444
+ // const newerIbGibDependencyGraphFromOuterSpace = await getDependencyGraph({
3445
+ // ibGibAddrs: newerAddrsFromOuterSpace,
3446
+ // live: false,
3447
+ // skipAddrs: addrsAlreadyStoredLocally,
3448
+ // space: outerSpace,
3449
+ // });
3450
+ // const newerIbGibsFromOuterSpace: IbGib_V1[] =
3451
+ // Object.values(newerIbGibDependencyGraphFromOuterSpace);
3452
+
3453
+ // if (logalot) { console.log(`${lc} got ${newerIbGibsFromOuterSpace.length} ibGibs from outerspace`); }
3454
+
3455
+ // // save locally
3456
+ // if (logalot) { console.log(`${lc} saving new ibgibs from outerspace in local space...`); }
3457
+ // if (newerIbGibsFromOuterSpace.length > 0) {
3458
+ // await this.put({ ibGibs: newerIbGibsFromOuterSpace });
3459
+
3460
+ // // register the newest tjp ibGibs locally
3461
+ // if (logalot) { console.log(`${lc} registering "new" updated tjp ibgibs locally...`); }
3462
+ // for (let i = 0; i < tjpAddrs.length; i++) {
3463
+ // const tjpAddr = tjpAddrs[i];
3464
+ // const updatedAddr = updates[tjpAddr];
3465
+ // if (!addrsAlreadyStoredLocally.includes(updatedAddr)) {
3466
+ // const updatedIbGib = newerIbGibDependencyGraphFromOuterSpace[updatedAddr];
3467
+ // if (!updatedIbGib) {
3468
+ // throw new Error(`did not get updatedIbGib (${updatedAddr}) from outerspace (${outerSpace.data.uuid}) (E: 818de70f5b444a3ba198ba6480a15b04)`);
3469
+ // }
3470
+ // await this.registerNewIbGib({ ibGib: updatedIbGib });
3471
+ // }
3472
+ // }
3473
+ // }
3474
+
3475
+ // } catch (error) {
3476
+ // console.error(`${lc} ${error.message}`);
3477
+ // // does not rethrow
3478
+ // } finally {
3479
+ // if (logalot) { console.log(`${lc} complete.`); }
3480
+ // }
3481
+ // }
3537
3482
 
3538
3483
  // #endregion syncIbGibs related
3539
3484