@ibgib/core-gib 0.0.64 → 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.
Files changed (28) hide show
  1. package/dist/common/other/other-constants.d.mts +0 -2
  2. package/dist/common/other/other-constants.d.mts.map +1 -1
  3. package/dist/common/other/other-constants.mjs +0 -2
  4. package/dist/common/other/other-constants.mjs.map +1 -1
  5. package/dist/witness/app/app-helper.d.mts +0 -1
  6. package/dist/witness/app/app-helper.d.mts.map +1 -1
  7. package/dist/witness/app/app-helper.mjs +3 -3
  8. package/dist/witness/app/app-helper.mjs.map +1 -1
  9. package/dist/witness/space/metaspace/metaspace-base.d.mts +9 -59
  10. package/dist/witness/space/metaspace/metaspace-base.d.mts.map +1 -1
  11. package/dist/witness/space/metaspace/metaspace-base.mjs +299 -315
  12. package/dist/witness/space/metaspace/metaspace-base.mjs.map +1 -1
  13. package/dist/witness/space/metaspace/metaspace-types.d.mts +6 -29
  14. package/dist/witness/space/metaspace/metaspace-types.d.mts.map +1 -1
  15. package/dist/witness/space/outer-space/outer-space-helper.d.mts.map +1 -1
  16. package/dist/witness/space/outer-space/outer-space-helper.mjs +5 -0
  17. package/dist/witness/space/outer-space/outer-space-helper.mjs.map +1 -1
  18. package/dist/witness/space/outer-space/outer-space-types.d.mts +9 -4
  19. package/dist/witness/space/outer-space/outer-space-types.d.mts.map +1 -1
  20. package/dist/witness/space/outer-space/outer-space-types.mjs +0 -1
  21. package/dist/witness/space/outer-space/outer-space-types.mjs.map +1 -1
  22. package/package.json +1 -1
  23. package/src/common/other/other-constants.mts +0 -4
  24. package/src/witness/app/app-helper.mts +3 -3
  25. package/src/witness/space/metaspace/metaspace-base.mts +326 -371
  26. package/src/witness/space/metaspace/metaspace-types.mts +27 -62
  27. package/src/witness/space/outer-space/outer-space-helper.mts +9 -0
  28. package/src/witness/space/outer-space/outer-space-types.mts +9 -6
@@ -1,5 +1,6 @@
1
1
  import { delay, getUUID, groupBy, pretty } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
2
2
  import { encrypt, decrypt, } from '@ibgib/encrypt-gib/dist/encrypt-decrypt.mjs';
3
+ import { DEFAULT_ALPHABET_INDEXING_MODE_BLOCKMODE, DEFAULT_ALPHABET_INDEXING_MODE_LEGACY } from '@ibgib/encrypt-gib/dist/constants.mjs';
3
4
  import { IbGib_V1, } from '@ibgib/ts-gib/dist/V1/types.mjs';
4
5
  import { GIB, GIB_DELIMITER, IB, ROOT, } from '@ibgib/ts-gib/dist/V1/constants.mjs';
5
6
  import { IbGibAddr, TjpIbGibAddr, TransformResult, } from '@ibgib/ts-gib/dist/types.mjs';
@@ -14,7 +15,8 @@ import {
14
15
  } from '../../../common/other/other-types.mjs';
15
16
  import { TagIbGib_V1 } from '../../../common/tag/tag-types.mjs';
16
17
  import {
17
- ParticipantInfo, StatusCode, SyncSagaInfo, SyncSpaceOptionsData,
18
+ OuterSpaceData,
19
+ ParticipantInfo, StatusCode, SyncSagaInfo, SyncSpaceIbGib, SyncSpaceOptionsData,
18
20
  SyncSpaceOptionsIbGib, SyncSpaceResultIbGib, SyncStatusIbGib,
19
21
  } from '../../../witness/space/outer-space/outer-space-types.mjs';
20
22
  import { IbGibSpaceData, IbGibSpaceRel8ns, SpaceId } from '../../../witness/space/space-types.mjs';
@@ -49,7 +51,7 @@ import { spaceNameIsValid, } from '../../../witness/space/space-helper.mjs';
49
51
  import { RobbotPromptResult } from '../../../witness/robbot/robbot-types.mjs';
50
52
  import { createNewRobbot, validateCommonRobbotData, validateCommonRobbotIbGib } from '../../../witness/robbot/robbot-helper.mjs';
51
53
  import { AppPromptResult } from '../../../witness/app/app-types.mjs';
52
- import { createNewApp, documentLocationIsAtWelcomePage } from '../../../witness/app/app-helper.mjs';
54
+ import { createNewApp, } from '../../../witness/app/app-helper.mjs';
53
55
  import { CommentIbGib_V1, UpdateCommentPromptResult } from '../../../common/comment/comment-types.mjs';
54
56
  import { IbGibCacheService } from '../../../common/cache/cache-types.mjs';
55
57
  import { BOOTSTRAP_DATA_KNOWN_SPACE_IDS_KEY, BOOTSTRAP_IBGIB_ADDR } from '../../../witness/space/bootstrap/bootstrap-constants.mjs';
@@ -1879,19 +1881,19 @@ export abstract class MetaspaceBase implements MetaspaceService {
1879
1881
  const lc = `${this.lc}[${this.getPlaintextString.name}]`;
1880
1882
  try {
1881
1883
  // validate
1882
- if ((secretIbGibs || []).length === 0) { throw new Error(`secretIbGibs required.`); }
1884
+ if ((secretIbGibs || []).length === 0) { throw new Error(`secretIbGibs required. (E: 99a605b540c54b6db4d2ffe2caeb226a)`); }
1883
1885
  if (!ciphertextIbGib.data) { throw new Error(`ciphertextIbGib.data falsy (E: 598fc6473149e240a7d6916ecf642323)`); }
1884
1886
  if (!ciphertextIbGib.data.ciphertext) { throw new Error(`ciphertextIbGib.data.ciphertext falsy (E: 0e764a71ec214132a5a528f17f495a7c)`); }
1885
- if (!ciphertextIbGib.rel8ns?.encryption) { throw new Error(`ciphertextIbGib.rel8ns.encryption falsy`) }
1886
- if (ciphertextIbGib.rel8ns!.encryption!.length !== 1) { throw new Error(`ciphertextIbGib.rel8ns!.encryption!.length !== 1`); }
1887
+ if (!ciphertextIbGib.rel8ns?.encryption) { throw new Error(`ciphertextIbGib.rel8ns.encryption falsy (E: a0b4d5d8674b4d0191fa619164153022)`) }
1888
+ if (ciphertextIbGib.rel8ns!.encryption!.length !== 1) { throw new Error(`ciphertextIbGib.rel8ns!.encryption!.length !== 1 (E: a4a463e1ef0e45b4917eb04cb40d8173)`); }
1887
1889
 
1888
1890
  // get corresponding encryption ibgib for encryption settings
1889
1891
  const encryptionAddr = ciphertextIbGib.rel8ns!.encryption![0];
1890
1892
  const resEncryption = await this.get({ addr: encryptionAddr, space });
1891
- if (!resEncryption.success) { throw new Error(`get encryption failed`); }
1892
- if ((resEncryption.ibGibs || []).length !== 1) { throw new Error(`get encryption retrieved non-1 length (eesh)`); }
1893
+ if (!resEncryption.success) { throw new Error(`get encryption failed (E: feef34c05fae439c81ade7fc23037af1)`); }
1894
+ if ((resEncryption.ibGibs || []).length !== 1) { throw new Error(`get encryption retrieved non-1 length (eesh) (E: 5d7e2023cc2b4e349574c17d5cfc8867)`); }
1893
1895
  const encryptionIbGib = resEncryption.ibGibs![0] as IbGib_V1<EncryptionData_V1>;
1894
- if (!encryptionIbGib.data) { throw new Error('encryptionIbGib.data falsy'); }
1896
+ if (!encryptionIbGib.data) { throw new Error(`encryptionIbGib.data falsy (E: 409a243afbf24c20987524f6588816fa)`); }
1895
1897
 
1896
1898
  // prompt user for the password
1897
1899
  const password = await this.getPasswordForSecrets({
@@ -1904,13 +1906,23 @@ export abstract class MetaspaceBase implements MetaspaceService {
1904
1906
 
1905
1907
  // we're about the decrypt, but maybe the data doesn't have everything.
1906
1908
  // So WARN for any defaults we're using.
1907
- if (!encryptionIbGib.data.initialRecursions) { console.warn(`${lc} using default initialRecursions`); }
1908
- if (!encryptionIbGib.data.recursionsPerHash) { console.warn(`${lc} using default recursionsPerHash`); }
1909
- if (!encryptionIbGib.data.saltStrategy) { console.warn(`${lc} using default saltStrategy`); }
1910
- if (!encryptionIbGib.data.hashAlgorithm) { console.warn(`${lc} using default hashAlgorithm`); }
1909
+ if (!encryptionIbGib.data.initialRecursions) { console.warn(`${lc} using default initialRecursions because encryptionIbGib does not state this explicitly (W: 66774cbfccd44423949d34167da6d50b)`); }
1910
+ if (!encryptionIbGib.data.recursionsPerHash) { console.warn(`${lc} using default recursionsPerHash because encryptionIbGib does not state this explicitly (W: 29e264094f384d259319ba8587cd4f63)`); }
1911
+ if (!encryptionIbGib.data.saltStrategy) { console.warn(`${lc} using default saltStrategy because encryptionIbGib does not state this explicitly (W: 7a5acadb8d634c7e87f62c86b57ac7a2)`); }
1912
+ if (!encryptionIbGib.data.hashAlgorithm) { console.warn(`${lc} using default hashAlgorithm because encryptionIbGib does not state this explicitly(W: 2254db3569534b239a8c471b700c8500)`); }
1913
+
1914
+ const defaultIndexingMode = encryptionIbGib.data.blockMode ?
1915
+ DEFAULT_ALPHABET_INDEXING_MODE_BLOCKMODE :
1916
+ DEFAULT_ALPHABET_INDEXING_MODE_LEGACY;
1917
+ if (encryptionIbGib.data.blockMode) {
1918
+ if (!encryptionIbGib.data.blockModeOptions) { throw new Error(`invalid encryptionIbGib.data. blockMode is truthy but blockModeOptions is falsy. (E: 84bbc27a5248b7c4734a1674e41dd224)`); }
1919
+ if (!encryptionIbGib.data.indexingMode) {
1920
+ console.warn(`${lc} not complete. using default indexingMode ${defaultIndexingMode} because encryptionIbGib does not state this explicitly. (W: c15797cd8d0740ea886a348c10be2e5c)`)
1921
+ }
1922
+ }
1911
1923
 
1912
1924
  // do actual decryption
1913
- if (logalot) { console.log(`${lc} starting decrypt...`); }
1925
+ if (logalot) { console.log(`${lc} starting decrypt... (I: e14176ebc9a7470fb977d2184f1e2430)`); }
1914
1926
  const timerName = 'sync_log decrypt';
1915
1927
  console.time(timerName);
1916
1928
  console.timeLog(timerName, 'decrypting...');
@@ -1927,10 +1939,12 @@ export abstract class MetaspaceBase implements MetaspaceService {
1927
1939
  hashAlgorithm:
1928
1940
  encryptionIbGib.data.hashAlgorithm || DEFAULT_ENCRYPTION_HASH_ALGORITHM,
1929
1941
  encryptedDataDelimiter: encryptionIbGib.data.encryptedDataDelimiter,
1942
+ blockMode: encryptionIbGib.data.blockMode ? encryptionIbGib.data.blockModeOptions! : undefined,
1943
+ indexingMode: encryptionIbGib.data.indexingMode || defaultIndexingMode,
1930
1944
  });
1931
1945
  console.timeLog(timerName, 'decrypting complete.');
1932
1946
  console.timeEnd(timerName);
1933
- if (logalot) { console.log(`${lc} decrypt complete.`); }
1947
+ if (logalot) { console.log(`${lc} decrypt complete. (I: 15a8182230294a8a96504ba3667f039a)`); }
1934
1948
  if (resDecrypt.errors?.length ?? 0 > 0) { throw new Error(resDecrypt.errors!.join('|')); }
1935
1949
 
1936
1950
  if (!resDecrypt.decryptedData) { throw new Error(`(UNEXPECTED) resDecrypt has no errors but resDecrypt.decryptedData falsy? (E: 06e73992fb02e45e3c18db33f9a61b23)`); }
@@ -1943,76 +1957,76 @@ export abstract class MetaspaceBase implements MetaspaceService {
1943
1957
  }
1944
1958
  }
1945
1959
 
1946
- async unwrapEncryptedSyncSpace({
1947
- encryptedSpace,
1948
- fnPromptPassword,
1949
- dontPrompt,
1950
- space,
1951
- fnSpaceFactory,
1952
- }: {
1953
- encryptedSpace: IbGibSpaceAny,
1954
- fnPromptPassword: (title: string, msg: string) => Promise<string | null>,
1955
- dontPrompt?: boolean,
1956
- space?: IbGibSpaceAny,
1957
- fnSpaceFactory: (unencryptedSpaceData: any) => Promise<IbGibSpaceAny>,
1958
- }): Promise<IbGibSpaceAny> {
1959
- const lc = `${this.lc}[${this.unwrapEncryptedSyncSpace.name}]`;
1960
- try {
1961
- // validation
1962
- if (!space) { throw new Error(`space required (E: d4d3eaa2d7b9143cf1173b8ae6344c23)`); }
1963
- if (!encryptedSpace.rel8ns?.ciphertext) { throw new Error(`encryptedSpace is not a ciphertext`); }
1964
- if (encryptedSpace.rel8ns!.ciphertext!.length !== 1) { throw new Error(`only 1 ciphertext rel8n allowed...`); }
1965
-
1966
- // get ciphertext ibgib
1967
- const ciphertextAddr = encryptedSpace.rel8ns!.ciphertext![0];
1968
- const resCiphertext = await this.get({ addr: ciphertextAddr, space });
1969
- if (!resCiphertext.success) { throw new Error(`get ciphertext failed`); }
1970
- if ((resCiphertext.ibGibs || []).length !== 1) { throw new Error(`get ciphertext retrieved non-1 length (eesh)`); }
1971
- const ciphertextIbGib = resCiphertext.ibGibs![0] as CiphertextIbGib_V1;
1972
-
1973
- // get secrets associated with enciphered space
1974
- if (!encryptedSpace.rel8ns?.secret) { throw new Error('!encryptionIbGib.rel8ns?.secret'); }
1975
- const secretAddrs = encryptedSpace.rel8ns!.secret!;
1976
- const localUserSpace = await this.getLocalUserSpace({});
1977
- if (!localUserSpace) { throw new Error(`(UNEXPECTED) could not get localUserSpace? (E: 3c5687a15b3b58e3dcf1eca4f5fe5723)`); }
1978
- const argGetSecrets = await localUserSpace.argy({
1979
- argData: { ibGibAddrs: secretAddrs, cmd: 'get', }
1980
- });
1981
- const resSecrets = await localUserSpace.witness(argGetSecrets);
1982
- if (!resSecrets.data?.success || (resSecrets.ibGibs || []).length === 0) {
1983
- throw new Error(`couldn't get secret ibgibs`);
1984
- }
1985
- const secretIbGibs = resSecrets.ibGibs.concat() as IbGib_V1<SecretData_V1>[];
1986
-
1987
- // get plaintext now that we have the ciphertext ibgib and secret ibgib(s)
1988
- const plaintextString = await this.getPlaintextString({
1989
- ciphertextIbGib: ciphertextIbGib,
1990
- fnPromptPassword,
1991
- dontPrompt,
1992
- secretIbGibs,
1993
- space,
1994
- });
1995
-
1996
- const syncSpaceData = JSON.parse(plaintextString);
1997
- if (syncSpaceData.type !== 'sync') { throw new Error(`syncSpaceData.type !== 'sync'...this is the only one implemented right now`); }
1998
- if (syncSpaceData.subtype !== 'aws-dynamodb') { throw new Error(`syncSpaceData.subtype !== 'aws-dynamodb'...only one right now dude`); }
1999
-
2000
- // this is the original aws only implementation. I've just added (untested)
2001
- // a quick factory function where the consumer would do the following code.
2002
- const unwrappedSpace = await fnSpaceFactory(syncSpaceData);
2003
- return unwrappedSpace;
2004
- // so we have a syncspace data (only aws-dynamodb space right now).
2005
- // load this data into a space class with behavior (not just the dto).
2006
- // const awsSpace = new AWSDynamoSpace_V1(syncSpaceData, null);
2007
- // awsSpace.gib = await getGib({ ibGib: awsSpace, hasTjp: false });
2008
- // if (logalot) { console.log(`awsSpace.gib: ${awsSpace.gib}`); }
2009
- // return awsSpace;
2010
-
2011
- } catch (error) {
2012
- console.error(`${lc} ${error.message}`);
2013
- throw error;
2014
- }
2015
- }
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
+ // }
2016
2030
 
2017
2031
  /**
2018
2032
  * Caching user password secret in memory only.
@@ -2300,113 +2314,110 @@ export abstract class MetaspaceBase implements MetaspaceService {
2300
2314
  }
2301
2315
  }
2302
2316
 
2303
- async getAppSyncSpaces({
2304
- unwrapEncrypted,
2305
- createIfNone,
2306
- dontPrompt,
2307
- space,
2308
- outerspaceIds,
2309
- fnSpaceFactory,
2310
- fnPromptSecret,
2311
- fnPromptEncryption,
2312
- fnPromptOuterSpace,
2313
- }: {
2314
- unwrapEncrypted: boolean,
2315
- createIfNone: boolean,
2316
- /**
2317
- * If true, don't prompt the user if we don't have it already cached.
2318
- *
2319
- * We don't want the user to hit the page and then always have to type in
2320
- * the password, just because my password code sucks atow.
2321
- */
2322
- dontPrompt?: boolean,
2323
- space?: IbGibSpaceAny,
2324
- /**
2325
- * @see {@link syncIbGibs} arg of the same name
2326
- */
2327
- outerspaceIds?: SpaceId[],
2328
- fnSpaceFactory: (unencryptedSpaceData: any) => Promise<IbGibSpaceAny>,
2329
- fnPromptSecret: (space: IbGibSpaceAny) => Promise<SecretIbGib_V1 | undefined>,
2330
- fnPromptEncryption: (space: IbGibSpaceAny) => Promise<EncryptionIbGib_V1 | undefined>,
2331
- fnPromptOuterSpace: (space: IbGibSpaceAny) => Promise<IbGibSpaceAny | undefined>,
2332
- }): Promise<IbGibSpaceAny[]> {
2333
- const lc = `${this.lc}[${this.getAppSyncSpaces.name}]`;
2334
- try {
2335
- // I don't want this pinging the user if we're on the welcome page.
2336
- dontPrompt = dontPrompt ?? documentLocationIsAtWelcomePage();
2337
-
2338
- space = space ?? await this.getLocalUserSpace({});
2339
- if (!space) { throw new Error(`space falsy and localUserSpace not initialized (?) (E: bf09346708ba4d6e9a1389bd1b66d500)`); }
2340
-
2341
- // get existing
2342
- let appSyncSpaces: IbGibSpaceAny[] =
2343
- await this.getSpecialRel8dIbGibs<IbGibSpaceAny>({
2344
- type: "outerspaces",
2345
- rel8nName: SYNC_SPACE_REL8N_NAME,
2346
- space,
2347
- });
2348
-
2349
- // filter if applicable
2350
- const hasOuterspaceIds = (outerspaceIds?.length ?? 0) > 0;
2351
- if (hasOuterspaceIds) {
2352
- appSyncSpaces = appSyncSpaces.filter(x => outerspaceIds!.includes(x.data!.uuid!));
2353
- }
2354
-
2355
- // create if applicable
2356
- if (appSyncSpaces.length === 0) {
2357
- if (createIfNone) {
2358
- 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)`); }
2359
- const createdReqs = await this._createOuterspaceAndRequiredIbGibs({
2360
- space,
2361
- fnPromptSecret,
2362
- fnPromptEncryption,
2363
- fnPromptOuterSpace,
2364
- });
2365
- if (createdReqs) {
2366
- appSyncSpaces = await this.getSpecialRel8dIbGibs<IbGibSpaceAny>({
2367
- type: "outerspaces",
2368
- rel8nName: SYNC_SPACE_REL8N_NAME,
2369
- space,
2370
- });
2371
- }
2372
- } else {
2373
- 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)`);
2374
- }
2375
- }
2376
-
2377
- // unwrap if requested
2378
- let resSpaces: IbGibSpaceAny[] = [];
2379
- if (unwrapEncrypted) {
2380
- for (let i = 0; i < appSyncSpaces.length; i++) {
2381
- let syncSpace = appSyncSpaces[i];
2382
-
2383
- if (syncSpace.rel8ns) {
2384
- if (syncSpace.rel8ns.ciphertext) {
2385
- syncSpace = await this.unwrapEncryptedSyncSpace({
2386
- encryptedSpace: syncSpace,
2387
- fnPromptPassword: this.getFnPromptPassword!(),
2388
- dontPrompt,
2389
- space,
2390
- fnSpaceFactory,
2391
- });
2392
- }
2393
-
2394
- resSpaces.push(syncSpace);
2395
- } else {
2396
- }
2397
-
2398
- }
2399
- } else {
2400
- // still (probably) encrypted
2401
- resSpaces = appSyncSpaces;
2402
- }
2403
-
2404
- return resSpaces;
2405
- } catch (error) {
2406
- console.error(`${lc} ${error.message}`);
2407
- return [];
2408
- }
2409
- }
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
+ // }
2410
2421
 
2411
2422
  // async createRobbotIbGib({
2412
2423
  // robbotData,
@@ -2576,39 +2587,22 @@ export abstract class MetaspaceBase implements MetaspaceService {
2576
2587
 
2577
2588
  async syncIbGibs({
2578
2589
  dependencyGraphIbGibs,
2579
- // confirm,
2590
+ syncSpaceIbGibs,
2580
2591
  // watch,
2581
- outerspaceIds,
2582
- fnPreSyncProgress,
2583
- fnSpaceFactory,
2584
- fnPromptSecret,
2585
- fnPromptEncryption,
2586
- fnPromptOuterSpace,
2587
2592
  }: {
2593
+ /**
2594
+ * @see {@link MetaspaceService.syncIbGibs}
2595
+ */
2588
2596
  dependencyGraphIbGibs?: IbGib_V1[],
2589
- // confirm?: boolean,
2597
+ /**
2598
+ * @see {@link MetaspaceService.syncIbGibs}
2599
+ */
2600
+ syncSpaceIbGibs: IbGibSpaceAny[],
2590
2601
  // /**
2591
2602
  // * If true, will watch ibgibs in dependency graph that have timelines
2592
2603
  // * (tjps).
2593
2604
  // */
2594
2605
  // watch?: boolean,
2595
- /**
2596
- * if provided, these will determine which outerspace(s) we will sync
2597
- * the {@link dependencyGraphIbGibs} with.
2598
- */
2599
- outerspaceIds?: SpaceId[],
2600
- /**
2601
- * The meat of the sync process is tracked via a status within the sync
2602
- * spaces themselves. I'm addign this fn to track the pre and post progress
2603
- * stuff, since decrypting takes some time, and building the dependency
2604
- * graphs takes time. Both of these happen before the actual syncing occurs
2605
- * in the spaces.
2606
- */
2607
- fnPreSyncProgress?: (msg: string) => Promise<void>,
2608
- fnSpaceFactory: (unencryptedSpaceData: any) => Promise<IbGibSpaceAny>,
2609
- fnPromptSecret: (space: IbGibSpaceAny) => Promise<SecretIbGib_V1 | undefined>,
2610
- fnPromptEncryption: (space: IbGibSpaceAny) => Promise<EncryptionIbGib_V1 | undefined>,
2611
- fnPromptOuterSpace: (space: IbGibSpaceAny) => Promise<IbGibSpaceAny | undefined>,
2612
2606
  }): Promise<SyncSagaInfo[] | undefined> {
2613
2607
  const lc = `${this.lc}[${this.syncIbGibs.name}]`;
2614
2608
  // map of saga infos across all spaces
@@ -2655,7 +2649,8 @@ export abstract class MetaspaceBase implements MetaspaceService {
2655
2649
 
2656
2650
  // #region validate
2657
2651
  if (logalot) { console.log(`${lc} starting...`); }
2658
- 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)`); }
2659
2654
  // #endregion
2660
2655
 
2661
2656
  const localUserSpace = await this.getLocalUserSpace({});
@@ -2664,52 +2659,20 @@ export abstract class MetaspaceBase implements MetaspaceService {
2664
2659
 
2665
2660
  // #region get sync spaces and build participant infos
2666
2661
  if (logalot) { console.log(`${lc} get sync spaces (returns if none)`); }
2667
- console.timeLog(syncTimelogName, 'getAppSyncSpaces starting (unwrapEncrypted is true) starting...');
2668
- if (fnPreSyncProgress) { fnPreSyncProgress('getting app sync spaces... (I: aa2e8f32ab26457bad703218aa7fb47d)'); }
2669
- const appSyncSpaces: IbGibSpaceAny[] = await this.getAppSyncSpaces({
2670
- unwrapEncrypted: true,
2671
- createIfNone: true,
2672
- space: localUserSpace,
2673
- outerspaceIds,
2674
- fnSpaceFactory,
2675
- fnPromptSecret,
2676
- fnPromptEncryption,
2677
- fnPromptOuterSpace,
2678
- });
2679
- if (fnPreSyncProgress) { fnPreSyncProgress('build complete. (I: 391a9aa7749d45b1aecf9a0010d9937f)'); }
2680
- console.timeLog(syncTimelogName, 'getAppSyncSpaces starting (unwrapEncrypted is true) complete.');
2681
- if (appSyncSpaces.length === 0) {
2682
- 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)`;
2683
- if (logalot) { console.log(`${lc} ${msg}`) };
2684
- const fnAlert = this.getFnAlert!();
2685
- await fnAlert({ title: "Sync Cancelled", msg });
2686
- this._syncing = false;
2687
- console.timeLog(syncTimelogName, 'cancelled');
2688
- console.timeEnd(syncTimelogName);
2689
- return undefined; /* <<<< returns early */
2690
- }
2691
- // const localUserSpace = await this.getLocalUserSpace({});
2692
2662
  const participants: ParticipantInfo[] = [
2693
2663
  // local user space is the src
2694
2664
  { id: localUserSpace.data.uuid, gib: localUserSpace.gib, s_d: 'src', },
2695
2665
 
2696
2666
  // each sync space is a destination
2697
- ...appSyncSpaces.map(s => {
2698
- if (!s.data) { throw new Error(`space.data required. (E: 3c192771e84445a4b6476d5193b07e9d)`); }
2699
- if (!s.data.uuid) { throw new Error(`space.data.uuid required. (E: d27e9998227840f99d45a3ed245f3196)`); }
2700
- if (!s.gib) { throw new Error(`space.gib required. (E: db73aceb2f8445d8964ae49b59957072)`); }
2701
- 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;
2702
2672
  }),
2703
2673
  ];
2704
2674
  // #endregion
2705
2675
 
2706
- // if (fnPreSyncProgress) { fnPreSyncProgress('building dependency graph... (I: ae178a39c2594557b6d0489b02336ecd)'); }
2707
- // get **ALL** ibgibs that we'll need to put/merge
2708
- // const allIbGibsToSync: { [addr: string]: IbGib_V1 } = {};
2709
- // dependencyGraphIbGibs.forEach(x => { allIbGibsToSync[getIbGibAddr({ ibGib: x })] = x });
2710
-
2711
- // await this._getAllIbGibsToSyncFromGraph({ dependencyGraphIbGibs, space: localUserSpace });
2712
-
2713
2676
  // _NOW_ we can finally put/merge into sync spaces.
2714
2677
  // this returns to us the most recent versions which we can update
2715
2678
  // our local timelines if we so choose (which we will).
@@ -2720,7 +2683,7 @@ export abstract class MetaspaceBase implements MetaspaceService {
2720
2683
  if (logalot) { console.log(`${lc} syncing to spaces in parallel...`); }
2721
2684
  const multiSpaceOpId = await getUUID();
2722
2685
  const allSagaInfos: SyncSagaInfo[] = [];
2723
- const startSyncPromises: Promise<void>[] = appSyncSpaces.map(async syncSpace => {
2686
+ const startSyncPromises: Promise<void>[] = syncSpaceIbGibs.map(async syncSpace => {
2724
2687
  // create the info that will track progress over entire sync saga
2725
2688
  const sagaInfo =
2726
2689
  await this._createNewSyncSagaInfo({
@@ -2765,21 +2728,21 @@ export abstract class MetaspaceBase implements MetaspaceService {
2765
2728
  return allSagaInfos;
2766
2729
  } catch (error) {
2767
2730
  console.error(`${lc} ${error.message}`);
2768
- await this.finalizeAllSyncSagas_NoThrow({ error });
2731
+ await this._finalizeAllSyncSagas_NoThrow({ error });
2769
2732
  throw error;
2770
2733
  } finally {
2771
2734
  if (logalot) { console.log(`${lc} complete.`); }
2772
2735
  }
2773
2736
  }
2774
2737
 
2775
- protected async finalizeSyncSaga({
2738
+ protected async _finalizeSyncSaga({
2776
2739
  sagaInfo,
2777
2740
  error,
2778
2741
  }: {
2779
2742
  sagaInfo: SyncSagaInfo,
2780
2743
  error?: any,
2781
2744
  }): Promise<void> {
2782
- const lc = `${this.lc}[${this.finalizeSyncSaga.name}]`;
2745
+ const lc = `${this.lc}[${this._finalizeSyncSaga.name}]`;
2783
2746
  try {
2784
2747
  if (logalot) { console.log(`${lc} starting...`); }
2785
2748
  if (sagaInfo.complete) { return; }
@@ -2828,18 +2791,18 @@ export abstract class MetaspaceBase implements MetaspaceService {
2828
2791
  }
2829
2792
  }
2830
2793
 
2831
- protected async finalizeAllSyncSagas_NoThrow({
2794
+ protected async _finalizeAllSyncSagas_NoThrow({
2832
2795
  error,
2833
2796
  }: {
2834
2797
  error?: any,
2835
2798
  }): Promise<void> {
2836
- const lc = `${this.lc}[${this.finalizeAllSyncSagas_NoThrow.name}]`;
2799
+ const lc = `${this.lc}[${this._finalizeAllSyncSagas_NoThrow.name}]`;
2837
2800
  try {
2838
2801
  const syncSagaInfos_NotComplete =
2839
2802
  Object.values(this.sagaInfoMap).filter(x => !x.complete);
2840
2803
  for (let i = 0; i < syncSagaInfos_NotComplete.length; i++) {
2841
2804
  const sagaInfo = syncSagaInfos_NotComplete[i];
2842
- await this.finalizeSyncSaga({ sagaInfo, error });
2805
+ await this._finalizeSyncSaga({ sagaInfo, error });
2843
2806
  }
2844
2807
  } catch (error) {
2845
2808
  console.error(`${lc}(UNEXPECTED) ${error.message}`);
@@ -2966,18 +2929,10 @@ export abstract class MetaspaceBase implements MetaspaceService {
2966
2929
  protected async _startSync({
2967
2930
  syncSagaInfo,
2968
2931
  // watch,
2969
- // confirm,
2970
2932
  syncTimelogName,
2971
2933
  }: {
2972
2934
  syncSagaInfo: SyncSagaInfo,
2973
2935
  // watch?: boolean,
2974
- /**
2975
- * Will confirm via checking existence of ibgibs in sync space after
2976
- * writing them.
2977
- *
2978
- * NOTE: IGNORED ATM
2979
- */
2980
- // confirm?: boolean,
2981
2936
  syncTimelogName: string,
2982
2937
  }): Promise<SyncSpaceResultIbGib> {
2983
2938
  const lc = `${this.lc}[${this._startSync.name}]`;
@@ -3102,7 +3057,7 @@ export abstract class MetaspaceBase implements MetaspaceService {
3102
3057
  const emsg = `${lc}(sagaId: ${sagaInfo.sagaId}) syncStatus$.error: ${error}`;
3103
3058
  console.error(emsg);
3104
3059
  // await this.getFnAlert!()({title: 'couldnt this.syncIbGibs...', msg: emsg});
3105
- await this.finalizeSyncSaga({ sagaInfo, error: emsg });
3060
+ await this._finalizeSyncSaga({ sagaInfo, error: emsg });
3106
3061
  },
3107
3062
  complete: async () => {
3108
3063
  if (logalot) { console.log(`${lc}(sagaId: ${sagaInfo.sagaId}) syncStatus$.complete.`); }
@@ -3160,11 +3115,11 @@ export abstract class MetaspaceBase implements MetaspaceService {
3160
3115
  break;
3161
3116
 
3162
3117
  case StatusCode.merged_dna:
3163
- await this.handleSyncStatus_Merged({ status });
3118
+ await this._handleSyncStatus_Merged({ status });
3164
3119
  break;
3165
3120
 
3166
3121
  case StatusCode.merged_state:
3167
- await this.handleSyncStatus_Merged({ status });
3122
+ await this._handleSyncStatus_Merged({ status });
3168
3123
  break;
3169
3124
 
3170
3125
  case StatusCode.already_synced:
@@ -3173,7 +3128,7 @@ export abstract class MetaspaceBase implements MetaspaceService {
3173
3128
  break;
3174
3129
 
3175
3130
  case StatusCode.completed:
3176
- await this.handleSyncStatus_Complete({ sagaInfo });
3131
+ await this._handleSyncStatus_Complete({ sagaInfo });
3177
3132
  break;
3178
3133
 
3179
3134
  case StatusCode.undefined:
@@ -3195,12 +3150,12 @@ export abstract class MetaspaceBase implements MetaspaceService {
3195
3150
  }
3196
3151
  };
3197
3152
 
3198
- protected async handleSyncStatus_Merged({
3153
+ protected async _handleSyncStatus_Merged({
3199
3154
  status,
3200
3155
  }: {
3201
3156
  status: SyncStatusIbGib,
3202
3157
  }): Promise<void> {
3203
- const lc = `${this.lc}[${this.handleSyncStatus_Merged.name}]`;
3158
+ const lc = `${this.lc}[${this._handleSyncStatus_Merged.name}]`;
3204
3159
  try {
3205
3160
  if (logalot) { console.log(`${lc} starting...`); }
3206
3161
  // #region validate
@@ -3284,24 +3239,24 @@ export abstract class MetaspaceBase implements MetaspaceService {
3284
3239
  }
3285
3240
  }
3286
3241
 
3287
- protected async handleSyncStatus_Complete({
3242
+ protected async _handleSyncStatus_Complete({
3288
3243
  sagaInfo,
3289
3244
  }: {
3290
3245
  sagaInfo: SyncSagaInfo,
3291
3246
  }): Promise<void> {
3292
- const lc = `${this.lc}[${this.handleSyncStatus_Complete.name}]`;
3247
+ const lc = `${this.lc}[${this._handleSyncStatus_Complete.name}]`;
3293
3248
  try {
3294
3249
  // cleanup just this saga, which corresponds to a single sync space.
3295
- await this.finalizeSyncSaga({ sagaInfo });
3250
+ await this._finalizeSyncSaga({ sagaInfo });
3296
3251
 
3297
3252
  // if this is the last saga across all spaces, clean up the rest.
3298
3253
  const allSagaInfos = Object.values(this.sagaInfoMap);
3299
3254
  if (allSagaInfos.every(x => x.complete)) {
3300
- await this.finalizeAllSyncSagas_NoThrow({});
3255
+ await this._finalizeAllSyncSagas_NoThrow({});
3301
3256
  }
3302
3257
  } catch (error) {
3303
3258
  console.error(`${lc} ${error.message}`);
3304
- await this.finalizeAllSyncSagas_NoThrow({ error });
3259
+ await this._finalizeAllSyncSagas_NoThrow({ error });
3305
3260
  }
3306
3261
  }
3307
3262
 
@@ -3433,97 +3388,97 @@ export abstract class MetaspaceBase implements MetaspaceService {
3433
3388
  }
3434
3389
  }
3435
3390
 
3436
- protected async handleWatchTjpUpdates({
3437
- updates,
3438
- outerSpace,
3439
- localUserSpace,
3440
- }: {
3441
- updates: { [tjpAddr: string]: IbGibAddr; }
3442
- outerSpace: IbGibSpaceAny,
3443
- localUserSpace: IbGibSpaceAny,
3444
- }): Promise<void> {
3445
- const lc = `${this.lc}[${this.handleWatchTjpUpdates.name}]`;
3446
- if (logalot) { console.log(`${lc} starting...`); }
3447
- try {
3448
- if (!outerSpace.data) { throw new Error(`outerSpace.data falsy (E: b5fde89e87bef9b8b6ce38e24be4a823)`); }
3449
-
3450
- /**
3451
- * compile list of addrs we have locally for all updates, so we don't try
3452
- * to download them from outer space unnecessarily.
3453
- */
3454
- const latestAddrsLocallyWithUpdate: IbGibAddr[] = [];
3455
- const tjpAddrs = Object.keys(updates);
3456
- const latestAddrs_Store = Object.values(updates);
3457
- for (let i = 0; i < tjpAddrs.length; i++) {
3458
- const tjpAddr = tjpAddrs[i];
3459
- if (logalot) { console.log(`${lc} tjpAddr: ${tjpAddr}`); }
3460
- const latestAddrLocally = await this.getLatestAddr({ tjpAddr }) ?? tjpAddr;
3461
- if (
3462
- !latestAddrs_Store.includes(latestAddrLocally) &&
3463
- !latestAddrsLocallyWithUpdate.includes(latestAddrLocally)
3464
- ) {
3465
- latestAddrsLocallyWithUpdate.push(latestAddrLocally);
3466
- }
3467
- }
3468
- if (latestAddrsLocallyWithUpdate.length === 0) {
3469
- if (logalot) { console.log(`${lc} latestAddrsLocallyWithUpdate.length === 0. We already had all of the updates locally perhaps. Returning early. (I: 844193c515084d0ebc348349f1ac41f4)`); }
3470
- return; /* <<<< returns early */
3471
- }
3472
-
3473
- /**
3474
- * LOCAL dependencies for latest LOCAL addrs for all tjpAddrs in updates.
3475
- */
3476
- const localDependencyGraphs = await this.getDependencyGraph({
3477
- ibGibAddrs: latestAddrsLocallyWithUpdate,
3478
- live: true,
3479
- maxRetries: DEFAULT_MAX_RETRIES_GET_DEPENDENCY_GRAPH_OUTERSPACE,
3480
- msBetweenRetries: DEFAULT_MS_BETWEEN_RETRIES_GET_DEPENDENCY_GRAPH_OUTERSPACE,
3481
- space: localUserSpace,
3482
- });
3483
-
3484
- /** all addrs we already have locally */
3485
- const addrsAlreadyStoredLocally = Object.keys(localDependencyGraphs);
3486
-
3487
- // get dependency graph from outer space, skipping all addrs in local already
3488
- const newerAddrsFromOuterSpace: IbGibAddr[] = Object.values(updates);
3489
- const newerIbGibDependencyGraphFromOuterSpace = await getDependencyGraph({
3490
- ibGibAddrs: newerAddrsFromOuterSpace,
3491
- live: false,
3492
- skipAddrs: addrsAlreadyStoredLocally,
3493
- space: outerSpace,
3494
- });
3495
- const newerIbGibsFromOuterSpace: IbGib_V1[] =
3496
- Object.values(newerIbGibDependencyGraphFromOuterSpace);
3497
-
3498
- if (logalot) { console.log(`${lc} got ${newerIbGibsFromOuterSpace.length} ibGibs from outerspace`); }
3499
-
3500
- // save locally
3501
- if (logalot) { console.log(`${lc} saving new ibgibs from outerspace in local space...`); }
3502
- if (newerIbGibsFromOuterSpace.length > 0) {
3503
- await this.put({ ibGibs: newerIbGibsFromOuterSpace });
3504
-
3505
- // register the newest tjp ibGibs locally
3506
- if (logalot) { console.log(`${lc} registering "new" updated tjp ibgibs locally...`); }
3507
- for (let i = 0; i < tjpAddrs.length; i++) {
3508
- const tjpAddr = tjpAddrs[i];
3509
- const updatedAddr = updates[tjpAddr];
3510
- if (!addrsAlreadyStoredLocally.includes(updatedAddr)) {
3511
- const updatedIbGib = newerIbGibDependencyGraphFromOuterSpace[updatedAddr];
3512
- if (!updatedIbGib) {
3513
- throw new Error(`did not get updatedIbGib (${updatedAddr}) from outerspace (${outerSpace.data.uuid}) (E: 818de70f5b444a3ba198ba6480a15b04)`);
3514
- }
3515
- await this.registerNewIbGib({ ibGib: updatedIbGib });
3516
- }
3517
- }
3518
- }
3519
-
3520
- } catch (error) {
3521
- console.error(`${lc} ${error.message}`);
3522
- // does not rethrow
3523
- } finally {
3524
- if (logalot) { console.log(`${lc} complete.`); }
3525
- }
3526
- }
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
+ // }
3527
3482
 
3528
3483
  // #endregion syncIbGibs related
3529
3484