@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.
@@ -16,7 +16,7 @@ import { getDependencyGraph } from '../../../common/other/graph-helper.mjs';
16
16
  import { createNewRobbot, validateCommonRobbotIbGib } from '../../../witness/robbot/robbot-helper.mjs';
17
17
  import { createNewApp, } from '../../../witness/app/app-helper.mjs';
18
18
  import { BOOTSTRAP_DATA_KNOWN_SPACE_IDS_KEY, BOOTSTRAP_IBGIB_ADDR } from '../../../witness/space/bootstrap/bootstrap-constants.mjs';
19
- import { DEFAULT_MAX_RETRIES_GET_DEPENDENCY_GRAPH_OUTERSPACE, DEFAULT_MS_BETWEEN_RETRIES_GET_DEPENDENCY_GRAPH_OUTERSPACE, DEFAULT_SECONDS_VALID_LOCAL, SYNC_SPACE_REL8N_NAME } from '../../../witness/space/space-constants.mjs';
19
+ import { DEFAULT_SECONDS_VALID_LOCAL, SYNC_SPACE_REL8N_NAME } from '../../../witness/space/space-constants.mjs';
20
20
  import { DEFAULT_ENCRYPTION_HASH_ALGORITHM, DEFAULT_ENCRYPTION_INITIAL_RECURSIONS, DEFAULT_ENCRYPTION_RECURSIONS_PER_HASH, DEFAULT_ENCRYPTION_SALT_STRATEGY, ENCRYPTION_REL8N_NAME, } from '../../../common/encrypt/encrypt-constants.mjs';
21
21
  import { ROBBOT_REL8N_NAME } from '../../../witness/robbot/robbot-constants.mjs';
22
22
  import { APP_REL8N_NAME } from '../../../witness/app/app-constants.mjs';
@@ -1717,77 +1717,70 @@ export class MetaspaceBase {
1717
1717
  throw error;
1718
1718
  }
1719
1719
  }
1720
- async unwrapEncryptedSyncSpace({ encryptedSpace, fnPromptPassword, dontPrompt, space, fnSpaceFactory, }) {
1721
- const lc = `${this.lc}[${this.unwrapEncryptedSyncSpace.name}]`;
1722
- try {
1723
- // validation
1724
- if (!space) {
1725
- throw new Error(`space required (E: d4d3eaa2d7b9143cf1173b8ae6344c23)`);
1726
- }
1727
- if (!encryptedSpace.rel8ns?.ciphertext) {
1728
- throw new Error(`encryptedSpace is not a ciphertext (E: be5504a5e2b84f3eaa8fbd6e13aab659)`);
1729
- }
1730
- if (encryptedSpace.rel8ns.ciphertext.length !== 1) {
1731
- throw new Error(`only 1 ciphertext rel8n allowed... (E: e8ab2ec38ad844dfb229efc5b8981946)`);
1732
- }
1733
- // get ciphertext ibgib
1734
- const ciphertextAddr = encryptedSpace.rel8ns.ciphertext[0];
1735
- const resCiphertext = await this.get({ addr: ciphertextAddr, space });
1736
- if (!resCiphertext.success) {
1737
- throw new Error(`get ciphertext failed (E: e58b3471c0334cd7bc626998106e6547)`);
1738
- }
1739
- if ((resCiphertext.ibGibs || []).length !== 1) {
1740
- throw new Error(`get ciphertext retrieved non-1 length (eesh) (E: a3a1f00e827b4f88a42b4a7433cf1065)`);
1741
- }
1742
- const ciphertextIbGib = resCiphertext.ibGibs[0];
1743
- // get secrets associated with enciphered space
1744
- if (!encryptedSpace.rel8ns?.secret) {
1745
- throw new Error(`!encryptionIbGib.rel8ns?.secret (E: 8bfed1541976433da9402d7d3a9138dd)`);
1746
- }
1747
- const secretAddrs = encryptedSpace.rel8ns.secret;
1748
- const localUserSpace = await this.getLocalUserSpace({});
1749
- if (!localUserSpace) {
1750
- throw new Error(`(UNEXPECTED) could not get localUserSpace? (E: 3c5687a15b3b58e3dcf1eca4f5fe5723) (E: c123b340177647968e10a6b119d84d2b)`);
1751
- }
1752
- const argGetSecrets = await localUserSpace.argy({
1753
- argData: { ibGibAddrs: secretAddrs, cmd: 'get', }
1754
- });
1755
- const resSecrets = await localUserSpace.witness(argGetSecrets);
1756
- if (!resSecrets.data?.success || (resSecrets.ibGibs || []).length === 0) {
1757
- throw new Error(`couldn't get secret ibgibs (E: cb17687f842f4296a9ecf89d9a568e46)`);
1758
- }
1759
- const secretIbGibs = resSecrets.ibGibs.concat();
1760
- // get plaintext now that we have the ciphertext ibgib and secret ibgib(s)
1761
- const plaintextString = await this.getPlaintextString({
1762
- ciphertextIbGib,
1763
- fnPromptPassword,
1764
- dontPrompt,
1765
- secretIbGibs,
1766
- space,
1767
- });
1768
- const syncSpaceData = JSON.parse(plaintextString);
1769
- if (syncSpaceData.type !== 'sync') {
1770
- throw new Error(`syncSpaceData.type !== 'sync'...this is the only one implemented right now (E: 509b2373d6f8445ebe5bd6f27f62af93)`);
1771
- }
1772
- if (syncSpaceData.subtype !== 'aws-dynamodb') {
1773
- throw new Error(`syncSpaceData.subtype !== 'aws-dynamodb'...only one right now dude (E: b5caaf3b4c60438eb2cee58ce8e1d3f6)`);
1774
- }
1775
- // this is the original aws only implementation. I've just added (untested)
1776
- // a quick factory function where the consumer would do the following code.
1777
- const unwrappedSpace = await fnSpaceFactory(syncSpaceData);
1778
- return unwrappedSpace;
1779
- // so we have a syncspace data (only aws-dynamodb space right now).
1780
- // load this data into a space class with behavior (not just the dto).
1781
- // const awsSpace = new AWSDynamoSpace_V1(syncSpaceData, null);
1782
- // awsSpace.gib = await getGib({ ibGib: awsSpace, hasTjp: false });
1783
- // if (logalot) { console.log(`awsSpace.gib: ${awsSpace.gib}`); }
1784
- // return awsSpace;
1785
- }
1786
- catch (error) {
1787
- console.error(`${lc} ${error.message}`);
1788
- throw error;
1789
- }
1790
- }
1720
+ // async unwrapEncryptedSyncSpace({
1721
+ // encryptedSpace,
1722
+ // fnPromptPassword,
1723
+ // dontPrompt,
1724
+ // space,
1725
+ // fnSpaceFactory,
1726
+ // }: {
1727
+ // encryptedSpace: IbGibSpaceAny,
1728
+ // fnPromptPassword: (title: string, msg: string) => Promise<string | null>,
1729
+ // dontPrompt?: boolean,
1730
+ // space?: IbGibSpaceAny,
1731
+ // fnSpaceFactory: (syncSpaceIbGib: SyncSpaceIbGib) => Promise<IbGibSpaceAny>,
1732
+ // }): Promise<IbGibSpaceAny> {
1733
+ // const lc = `${this.lc}[${this.unwrapEncryptedSyncSpace.name}]`;
1734
+ // try {
1735
+ // // validation
1736
+ // if (!space) { throw new Error(`space required (E: d4d3eaa2d7b9143cf1173b8ae6344c23)`); }
1737
+ // if (!encryptedSpace.rel8ns?.ciphertext) { throw new Error(`encryptedSpace is not a ciphertext (E: be5504a5e2b84f3eaa8fbd6e13aab659)`); }
1738
+ // if (encryptedSpace.rel8ns!.ciphertext!.length !== 1) { throw new Error(`only 1 ciphertext rel8n allowed... (E: e8ab2ec38ad844dfb229efc5b8981946)`); }
1739
+ // // get ciphertext ibgib
1740
+ // const ciphertextAddr = encryptedSpace.rel8ns!.ciphertext![0];
1741
+ // const resCiphertext = await this.get({ addr: ciphertextAddr, space });
1742
+ // if (!resCiphertext.success) { throw new Error(`get ciphertext failed (E: e58b3471c0334cd7bc626998106e6547)`); }
1743
+ // if ((resCiphertext.ibGibs || []).length !== 1) { throw new Error(`get ciphertext retrieved non-1 length (eesh) (E: a3a1f00e827b4f88a42b4a7433cf1065)`); }
1744
+ // const ciphertextIbGib = resCiphertext.ibGibs![0] as CiphertextIbGib_V1;
1745
+ // // get secrets associated with enciphered space
1746
+ // if (!encryptedSpace.rel8ns?.secret) { throw new Error(`!encryptionIbGib.rel8ns?.secret (E: 8bfed1541976433da9402d7d3a9138dd)`); }
1747
+ // const secretAddrs = encryptedSpace.rel8ns!.secret!;
1748
+ // const localUserSpace = await this.getLocalUserSpace({});
1749
+ // if (!localUserSpace) { throw new Error(`(UNEXPECTED) could not get localUserSpace? (E: 3c5687a15b3b58e3dcf1eca4f5fe5723) (E: c123b340177647968e10a6b119d84d2b)`); }
1750
+ // const argGetSecrets = await localUserSpace.argy({
1751
+ // argData: { ibGibAddrs: secretAddrs, cmd: 'get', }
1752
+ // });
1753
+ // const resSecrets = await localUserSpace.witness(argGetSecrets);
1754
+ // if (!resSecrets.data?.success || (resSecrets.ibGibs || []).length === 0) {
1755
+ // throw new Error(`couldn't get secret ibgibs (E: cb17687f842f4296a9ecf89d9a568e46)`);
1756
+ // }
1757
+ // const secretIbGibs = resSecrets.ibGibs.concat() as IbGib_V1<SecretData_V1>[];
1758
+ // // get plaintext now that we have the ciphertext ibgib and secret ibgib(s)
1759
+ // const plaintextString = await this.getPlaintextString({
1760
+ // ciphertextIbGib,
1761
+ // fnPromptPassword,
1762
+ // dontPrompt,
1763
+ // secretIbGibs,
1764
+ // space,
1765
+ // });
1766
+ // const syncSpaceData = JSON.parse(plaintextString) as OuterSpaceData;
1767
+ // if (syncSpaceData.type !== 'sync') { throw new Error(`syncSpaceData.type !== 'sync'...this is the only one implemented right now (E: 509b2373d6f8445ebe5bd6f27f62af93)`); }
1768
+ // if (syncSpaceData.subtype !== 'aws-dynamodb') { throw new Error(`syncSpaceData.subtype !== 'aws-dynamodb'...only one right now dude (E: b5caaf3b4c60438eb2cee58ce8e1d3f6)`); }
1769
+ // // this is the original aws only implementation. I've just added (untested)
1770
+ // // a quick factory function where the consumer would do the following code.
1771
+ // const unwrappedSpace = await fnSpaceFactory(syncSpaceData);
1772
+ // return unwrappedSpace;
1773
+ // // so we have a syncspace data (only aws-dynamodb space right now).
1774
+ // // load this data into a space class with behavior (not just the dto).
1775
+ // // const awsSpace = new AWSDynamoSpace_V1(syncSpaceData, null);
1776
+ // // awsSpace.gib = await getGib({ ibGib: awsSpace, hasTjp: false });
1777
+ // // if (logalot) { console.log(`awsSpace.gib: ${awsSpace.gib}`); }
1778
+ // // return awsSpace;
1779
+ // } catch (error) {
1780
+ // console.error(`${lc} ${error.message}`);
1781
+ // throw error;
1782
+ // }
1783
+ // }
1791
1784
  /**
1792
1785
  * Caching user password secret in memory only.
1793
1786
  *
@@ -2063,80 +2056,102 @@ export class MetaspaceBase {
2063
2056
  throw error;
2064
2057
  }
2065
2058
  }
2066
- async getSyncSpaces({ unwrapEncrypted, createIfNone, dontPrompt, space, outerspaceIds, fnSpaceFactory, fnPromptSecret, fnPromptEncryption, fnPromptOuterSpace, }) {
2067
- const lc = `${this.lc}[${this.getSyncSpaces.name}]`;
2068
- try {
2069
- space = space ?? await this.getLocalUserSpace({});
2070
- if (!space) {
2071
- throw new Error(`space falsy and localUserSpace not initialized (?) (E: bf09346708ba4d6e9a1389bd1b66d500)`);
2072
- }
2073
- // get existing
2074
- let appSyncSpaces = await this.getSpecialRel8dIbGibs({
2075
- type: "outerspaces",
2076
- rel8nName: SYNC_SPACE_REL8N_NAME,
2077
- space,
2078
- });
2079
- // filter if applicable
2080
- const hasOuterspaceIds = (outerspaceIds?.length ?? 0) > 0;
2081
- if (hasOuterspaceIds) {
2082
- appSyncSpaces = appSyncSpaces.filter(x => outerspaceIds.includes(x.data.uuid));
2083
- }
2084
- // create if applicable
2085
- if (appSyncSpaces.length === 0) {
2086
- if (createIfNone) {
2087
- if (hasOuterspaceIds) {
2088
- 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)`);
2089
- }
2090
- const createdReqs = await this._createOuterspaceAndRequiredIbGibs({
2091
- space,
2092
- fnPromptSecret,
2093
- fnPromptEncryption,
2094
- fnPromptOuterSpace,
2095
- });
2096
- if (createdReqs) {
2097
- appSyncSpaces = await this.getSpecialRel8dIbGibs({
2098
- type: "outerspaces",
2099
- rel8nName: SYNC_SPACE_REL8N_NAME,
2100
- space,
2101
- });
2102
- }
2103
- }
2104
- else {
2105
- 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)`);
2106
- }
2107
- }
2108
- // unwrap if requested
2109
- let resSpaces = [];
2110
- if (unwrapEncrypted) {
2111
- for (let i = 0; i < appSyncSpaces.length; i++) {
2112
- let syncSpace = appSyncSpaces[i];
2113
- if (syncSpace.rel8ns) {
2114
- if (syncSpace.rel8ns.ciphertext) {
2115
- syncSpace = await this.unwrapEncryptedSyncSpace({
2116
- encryptedSpace: syncSpace,
2117
- fnPromptPassword: this.getFnPromptPassword(),
2118
- dontPrompt,
2119
- space,
2120
- fnSpaceFactory,
2121
- });
2122
- }
2123
- resSpaces.push(syncSpace);
2124
- }
2125
- else {
2126
- }
2127
- }
2128
- }
2129
- else {
2130
- // still (probably) encrypted
2131
- resSpaces = appSyncSpaces;
2132
- }
2133
- return resSpaces;
2134
- }
2135
- catch (error) {
2136
- console.error(`${lc} ${error.message}`);
2137
- return [];
2138
- }
2139
- }
2059
+ // async getSyncSpaces({
2060
+ // createIfNone,
2061
+ // dontPrompt,
2062
+ // space,
2063
+ // outerspaceIds,
2064
+ // // fnSpaceFactory,
2065
+ // fnPromptSecret,
2066
+ // fnPromptEncryption,
2067
+ // fnPromptOuterSpace,
2068
+ // }: {
2069
+ // // unwrapEncrypted: boolean,
2070
+ // createIfNone: boolean,
2071
+ // /**
2072
+ // * If true, don't prompt the user if we don't have it already cached.
2073
+ // *
2074
+ // * We don't want the user to hit the page and then always have to type in
2075
+ // * the password, just because my password code sucks atow.
2076
+ // */
2077
+ // dontPrompt?: boolean,
2078
+ // space?: IbGibSpaceAny,
2079
+ // /**
2080
+ // * @see {@link syncIbGibs} arg of the same name
2081
+ // */
2082
+ // outerspaceIds?: SpaceId[],
2083
+ // // fnSpaceFactory: (unencryptedSpaceData: any) => Promise<IbGibSpaceAny>,
2084
+ // fnPromptSecret: (space: IbGibSpaceAny) => Promise<SecretIbGib_V1 | undefined>,
2085
+ // fnPromptEncryption: (space: IbGibSpaceAny) => Promise<EncryptionIbGib_V1 | undefined>,
2086
+ // fnPromptOuterSpace: (space: IbGibSpaceAny) => Promise<IbGibSpaceAny | undefined>,
2087
+ // }): Promise<SyncSpaceIbGib[]> {
2088
+ // const lc = `${this.lc}[${this.getSyncSpaces.name}]`;
2089
+ // try {
2090
+ // space = space ?? await this.getLocalUserSpace({});
2091
+ // if (!space) { throw new Error(`space falsy and localUserSpace not initialized (?) (E: bf09346708ba4d6e9a1389bd1b66d500)`); }
2092
+ // // get existing
2093
+ // let resSyncSpaces: SyncSpaceIbGib[] =
2094
+ // await this.getSpecialRel8dIbGibs<SyncSpaceIbGib>({
2095
+ // type: "outerspaces",
2096
+ // rel8nName: SYNC_SPACE_REL8N_NAME,
2097
+ // space,
2098
+ // });
2099
+ // // filter if applicable
2100
+ // const hasOuterspaceIds = (outerspaceIds?.length ?? 0) > 0;
2101
+ // if (hasOuterspaceIds) {
2102
+ // resSyncSpaces = resSyncSpaces.filter(x => outerspaceIds!.includes(x.data!.uuid!));
2103
+ // }
2104
+ // // create if applicable
2105
+ // if (resSyncSpaces.length === 0) {
2106
+ // if (createIfNone) {
2107
+ // 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)`); }
2108
+ // const createdReqs = await this._createOuterspaceAndRequiredIbGibs({
2109
+ // space,
2110
+ // fnPromptSecret,
2111
+ // fnPromptEncryption,
2112
+ // fnPromptOuterSpace,
2113
+ // });
2114
+ // if (createdReqs) {
2115
+ // resSyncSpaces = await this.getSpecialRel8dIbGibs<SyncSpaceIbGib>({
2116
+ // type: "outerspaces",
2117
+ // rel8nName: SYNC_SPACE_REL8N_NAME,
2118
+ // space,
2119
+ // });
2120
+ // }
2121
+ // } else {
2122
+ // 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)`);
2123
+ // }
2124
+ // }
2125
+ // // unwrap if requested
2126
+ // // let resSpaces: SyncSpaceIbGib[] = [];
2127
+ // // if (unwrapEncrypted) {
2128
+ // // for (let i = 0; i < syncSpaceIbGibs.length; i++) {
2129
+ // // let syncSpace = syncSpaceIbGibs[i];
2130
+ // // if (syncSpace.rel8ns) {
2131
+ // // if (syncSpace.rel8ns.ciphertext) {
2132
+ // // syncSpace = await this.unwrapEncryptedSyncSpace({
2133
+ // // encryptedSpace: syncSpace,
2134
+ // // fnPromptPassword: this.getFnPromptPassword!(),
2135
+ // // dontPrompt,
2136
+ // // space,
2137
+ // // fnSpaceFactory,
2138
+ // // });
2139
+ // // }
2140
+ // // resSpaces.push(syncSpace);
2141
+ // // } else {
2142
+ // // }
2143
+ // // }
2144
+ // // } else {
2145
+ // // still (probably) encrypted
2146
+ // // resSpaces = syncSpaceIbGibs;
2147
+ // // }
2148
+ // // return resSpaces;
2149
+ // return resSyncSpaces;
2150
+ // } catch (error) {
2151
+ // console.error(`${lc} ${error.message}`);
2152
+ // return [];
2153
+ // }
2154
+ // }
2140
2155
  // async createRobbotIbGib({
2141
2156
  // robbotData,
2142
2157
  // space,
@@ -2268,10 +2283,9 @@ export class MetaspaceBase {
2268
2283
  return [];
2269
2284
  }
2270
2285
  }
2271
- async syncIbGibs({ dependencyGraphIbGibs,
2272
- // confirm,
2286
+ async syncIbGibs({ dependencyGraphIbGibs, syncSpaceIbGibs,
2273
2287
  // watch,
2274
- outerspaceIds, fnPreSyncProgress, fnSpaceFactory, fnPromptSecret, fnPromptEncryption, fnPromptOuterSpace, }) {
2288
+ }) {
2275
2289
  const lc = `${this.lc}[${this.syncIbGibs.name}]`;
2276
2290
  // map of saga infos across all spaces
2277
2291
  // const sagaInfoMap: { [spaceGib: string]: SyncSagaInfo } = {};
@@ -2325,7 +2339,10 @@ export class MetaspaceBase {
2325
2339
  console.log(`${lc} starting...`);
2326
2340
  }
2327
2341
  if (!dependencyGraphIbGibs || dependencyGraphIbGibs.length === 0) {
2328
- throw new Error(`ibGibs required. (E: 404c36475fb84fc285a23a67c0b8fcb2)`);
2342
+ throw new Error(`dependencyGraphIbGibs required. (E: 404c36475fb84fc285a23a67c0b8fcb2)`);
2343
+ }
2344
+ if (!syncSpaceIbGibs || syncSpaceIbGibs.length === 0) {
2345
+ throw new Error(`syncSpaceIbGibs required (E: c5a022454b9ce34856e141e61e337d24)`);
2329
2346
  }
2330
2347
  // #endregion
2331
2348
  const localUserSpace = await this.getLocalUserSpace({});
@@ -2339,61 +2356,24 @@ export class MetaspaceBase {
2339
2356
  if (logalot) {
2340
2357
  console.log(`${lc} get sync spaces (returns if none)`);
2341
2358
  }
2342
- console.timeLog(syncTimelogName, 'getAppSyncSpaces starting (unwrapEncrypted is true) starting...');
2343
- if (fnPreSyncProgress) {
2344
- fnPreSyncProgress('getting app sync spaces... (I: aa2e8f32ab26457bad703218aa7fb47d)');
2345
- }
2346
- const appSyncSpaces = await this.getSyncSpaces({
2347
- unwrapEncrypted: true,
2348
- createIfNone: true,
2349
- space: localUserSpace,
2350
- outerspaceIds,
2351
- fnSpaceFactory,
2352
- fnPromptSecret,
2353
- fnPromptEncryption,
2354
- fnPromptOuterSpace,
2355
- });
2356
- if (fnPreSyncProgress) {
2357
- fnPreSyncProgress('build complete. (I: 391a9aa7749d45b1aecf9a0010d9937f)');
2358
- }
2359
- console.timeLog(syncTimelogName, 'getAppSyncSpaces starting (unwrapEncrypted is true) complete.');
2360
- if (appSyncSpaces.length === 0) {
2361
- 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)`;
2362
- if (logalot) {
2363
- console.log(`${lc} ${msg}`);
2364
- }
2365
- ;
2366
- const fnAlert = this.getFnAlert();
2367
- await fnAlert({ title: "Sync Cancelled", msg });
2368
- this._syncing = false;
2369
- console.timeLog(syncTimelogName, 'cancelled');
2370
- console.timeEnd(syncTimelogName);
2371
- return undefined; /* <<<< returns early */
2372
- }
2373
- // const localUserSpace = await this.getLocalUserSpace({});
2374
2359
  const participants = [
2375
2360
  // local user space is the src
2376
2361
  { id: localUserSpace.data.uuid, gib: localUserSpace.gib, s_d: 'src', },
2377
2362
  // each sync space is a destination
2378
- ...appSyncSpaces.map(s => {
2363
+ ...syncSpaceIbGibs.map(s => {
2379
2364
  if (!s.data) {
2380
- throw new Error(`space.data required. (E: 3c192771e84445a4b6476d5193b07e9d)`);
2365
+ throw new Error(`syncSpaceIbGib.data required. (E: 3c192771e84445a4b6476d5193b07e9d)`);
2381
2366
  }
2382
2367
  if (!s.data.uuid) {
2383
- throw new Error(`space.data.uuid required. (E: d27e9998227840f99d45a3ed245f3196)`);
2368
+ throw new Error(`syncSpaceIbGib.data.uuid required. (E: d27e9998227840f99d45a3ed245f3196)`);
2384
2369
  }
2385
2370
  if (!s.gib) {
2386
- throw new Error(`space.gib required. (E: db73aceb2f8445d8964ae49b59957072)`);
2371
+ throw new Error(`syncSpaceIbGib.gib required. (E: db73aceb2f8445d8964ae49b59957072)`);
2387
2372
  }
2388
2373
  return { id: s.data.uuid, gib: s.gib, s_d: 'dest', };
2389
2374
  }),
2390
2375
  ];
2391
2376
  // #endregion
2392
- // if (fnPreSyncProgress) { fnPreSyncProgress('building dependency graph... (I: ae178a39c2594557b6d0489b02336ecd)'); }
2393
- // get **ALL** ibgibs that we'll need to put/merge
2394
- // const allIbGibsToSync: { [addr: string]: IbGib_V1 } = {};
2395
- // dependencyGraphIbGibs.forEach(x => { allIbGibsToSync[getIbGibAddr({ ibGib: x })] = x });
2396
- // await this._getAllIbGibsToSyncFromGraph({ dependencyGraphIbGibs, space: localUserSpace });
2397
2377
  // _NOW_ we can finally put/merge into sync spaces.
2398
2378
  // this returns to us the most recent versions which we can update
2399
2379
  // our local timelines if we so choose (which we will).
@@ -2405,7 +2385,7 @@ export class MetaspaceBase {
2405
2385
  }
2406
2386
  const multiSpaceOpId = await getUUID();
2407
2387
  const allSagaInfos = [];
2408
- const startSyncPromises = appSyncSpaces.map(async (syncSpace) => {
2388
+ const startSyncPromises = syncSpaceIbGibs.map(async (syncSpace) => {
2409
2389
  // create the info that will track progress over entire sync saga
2410
2390
  const sagaInfo = await this._createNewSyncSagaInfo({
2411
2391
  multiSpaceOpId,
@@ -2448,7 +2428,7 @@ export class MetaspaceBase {
2448
2428
  }
2449
2429
  catch (error) {
2450
2430
  console.error(`${lc} ${error.message}`);
2451
- await this.finalizeAllSyncSagas_NoThrow({ error });
2431
+ await this._finalizeAllSyncSagas_NoThrow({ error });
2452
2432
  throw error;
2453
2433
  }
2454
2434
  finally {
@@ -2457,8 +2437,8 @@ export class MetaspaceBase {
2457
2437
  }
2458
2438
  }
2459
2439
  }
2460
- async finalizeSyncSaga({ sagaInfo, error, }) {
2461
- const lc = `${this.lc}[${this.finalizeSyncSaga.name}]`;
2440
+ async _finalizeSyncSaga({ sagaInfo, error, }) {
2441
+ const lc = `${this.lc}[${this._finalizeSyncSaga.name}]`;
2462
2442
  try {
2463
2443
  if (logalot) {
2464
2444
  console.log(`${lc} starting...`);
@@ -2525,13 +2505,13 @@ export class MetaspaceBase {
2525
2505
  }
2526
2506
  }
2527
2507
  }
2528
- async finalizeAllSyncSagas_NoThrow({ error, }) {
2529
- const lc = `${this.lc}[${this.finalizeAllSyncSagas_NoThrow.name}]`;
2508
+ async _finalizeAllSyncSagas_NoThrow({ error, }) {
2509
+ const lc = `${this.lc}[${this._finalizeAllSyncSagas_NoThrow.name}]`;
2530
2510
  try {
2531
2511
  const syncSagaInfos_NotComplete = Object.values(this.sagaInfoMap).filter(x => !x.complete);
2532
2512
  for (let i = 0; i < syncSagaInfos_NotComplete.length; i++) {
2533
2513
  const sagaInfo = syncSagaInfos_NotComplete[i];
2534
- await this.finalizeSyncSaga({ sagaInfo, error });
2514
+ await this._finalizeSyncSaga({ sagaInfo, error });
2535
2515
  }
2536
2516
  }
2537
2517
  catch (error) {
@@ -2644,7 +2624,6 @@ export class MetaspaceBase {
2644
2624
  */
2645
2625
  async _startSync({ syncSagaInfo,
2646
2626
  // watch,
2647
- // confirm,
2648
2627
  syncTimelogName, }) {
2649
2628
  const lc = `${this.lc}[${this._startSync.name}]`;
2650
2629
  try {
@@ -2765,7 +2744,7 @@ export class MetaspaceBase {
2765
2744
  const emsg = `${lc}(sagaId: ${sagaInfo.sagaId}) syncStatus$.error: ${error}`;
2766
2745
  console.error(emsg);
2767
2746
  // await this.getFnAlert!()({title: 'couldnt this.syncIbGibs...', msg: emsg});
2768
- await this.finalizeSyncSaga({ sagaInfo, error: emsg });
2747
+ await this._finalizeSyncSaga({ sagaInfo, error: emsg });
2769
2748
  },
2770
2749
  complete: async () => {
2771
2750
  if (logalot) {
@@ -2824,17 +2803,17 @@ export class MetaspaceBase {
2824
2803
  // nothing further to do? hmm...
2825
2804
  break;
2826
2805
  case StatusCode.merged_dna:
2827
- await this.handleSyncStatus_Merged({ status });
2806
+ await this._handleSyncStatus_Merged({ status });
2828
2807
  break;
2829
2808
  case StatusCode.merged_state:
2830
- await this.handleSyncStatus_Merged({ status });
2809
+ await this._handleSyncStatus_Merged({ status });
2831
2810
  break;
2832
2811
  case StatusCode.already_synced:
2833
2812
  // await this.handleSyncComplete_AlreadySynced({sagaInfo, status});
2834
2813
  // nothing further to do? hmm...
2835
2814
  break;
2836
2815
  case StatusCode.completed:
2837
- await this.handleSyncStatus_Complete({ sagaInfo });
2816
+ await this._handleSyncStatus_Complete({ sagaInfo });
2838
2817
  break;
2839
2818
  case StatusCode.undefined:
2840
2819
  // atow undefined is used in primitive status parentage
@@ -2857,8 +2836,8 @@ export class MetaspaceBase {
2857
2836
  }
2858
2837
  }
2859
2838
  ;
2860
- async handleSyncStatus_Merged({ status, }) {
2861
- const lc = `${this.lc}[${this.handleSyncStatus_Merged.name}]`;
2839
+ async _handleSyncStatus_Merged({ status, }) {
2840
+ const lc = `${this.lc}[${this._handleSyncStatus_Merged.name}]`;
2862
2841
  try {
2863
2842
  if (logalot) {
2864
2843
  console.log(`${lc} starting...`);
@@ -2954,20 +2933,20 @@ export class MetaspaceBase {
2954
2933
  throw error;
2955
2934
  }
2956
2935
  }
2957
- async handleSyncStatus_Complete({ sagaInfo, }) {
2958
- const lc = `${this.lc}[${this.handleSyncStatus_Complete.name}]`;
2936
+ async _handleSyncStatus_Complete({ sagaInfo, }) {
2937
+ const lc = `${this.lc}[${this._handleSyncStatus_Complete.name}]`;
2959
2938
  try {
2960
2939
  // cleanup just this saga, which corresponds to a single sync space.
2961
- await this.finalizeSyncSaga({ sagaInfo });
2940
+ await this._finalizeSyncSaga({ sagaInfo });
2962
2941
  // if this is the last saga across all spaces, clean up the rest.
2963
2942
  const allSagaInfos = Object.values(this.sagaInfoMap);
2964
2943
  if (allSagaInfos.every(x => x.complete)) {
2965
- await this.finalizeAllSyncSagas_NoThrow({});
2944
+ await this._finalizeAllSyncSagas_NoThrow({});
2966
2945
  }
2967
2946
  }
2968
2947
  catch (error) {
2969
2948
  console.error(`${lc} ${error.message}`);
2970
- await this.finalizeAllSyncSagas_NoThrow({ error });
2949
+ await this._finalizeAllSyncSagas_NoThrow({ error });
2971
2950
  }
2972
2951
  }
2973
2952
  /**
@@ -3076,96 +3055,89 @@ export class MetaspaceBase {
3076
3055
  throw error;
3077
3056
  }
3078
3057
  }
3079
- async handleWatchTjpUpdates({ updates, outerSpace, localUserSpace, }) {
3080
- const lc = `${this.lc}[${this.handleWatchTjpUpdates.name}]`;
3081
- if (logalot) {
3082
- console.log(`${lc} starting...`);
3083
- }
3084
- try {
3085
- if (!outerSpace.data) {
3086
- throw new Error(`outerSpace.data falsy (E: b5fde89e87bef9b8b6ce38e24be4a823)`);
3087
- }
3088
- /**
3089
- * compile list of addrs we have locally for all updates, so we don't try
3090
- * to download them from outer space unnecessarily.
3091
- */
3092
- const latestAddrsLocallyWithUpdate = [];
3093
- const tjpAddrs = Object.keys(updates);
3094
- const latestAddrs_Store = Object.values(updates);
3095
- for (let i = 0; i < tjpAddrs.length; i++) {
3096
- const tjpAddr = tjpAddrs[i];
3097
- if (logalot) {
3098
- console.log(`${lc} tjpAddr: ${tjpAddr}`);
3099
- }
3100
- const latestAddrLocally = await this.getLatestAddr({ tjpAddr }) ?? tjpAddr;
3101
- if (!latestAddrs_Store.includes(latestAddrLocally) &&
3102
- !latestAddrsLocallyWithUpdate.includes(latestAddrLocally)) {
3103
- latestAddrsLocallyWithUpdate.push(latestAddrLocally);
3104
- }
3105
- }
3106
- if (latestAddrsLocallyWithUpdate.length === 0) {
3107
- if (logalot) {
3108
- console.log(`${lc} latestAddrsLocallyWithUpdate.length === 0. We already had all of the updates locally perhaps. Returning early. (I: 844193c515084d0ebc348349f1ac41f4)`);
3109
- }
3110
- return; /* <<<< returns early */
3111
- }
3112
- /**
3113
- * LOCAL dependencies for latest LOCAL addrs for all tjpAddrs in updates.
3114
- */
3115
- const localDependencyGraphs = await this.getDependencyGraph({
3116
- ibGibAddrs: latestAddrsLocallyWithUpdate,
3117
- live: true,
3118
- maxRetries: DEFAULT_MAX_RETRIES_GET_DEPENDENCY_GRAPH_OUTERSPACE,
3119
- msBetweenRetries: DEFAULT_MS_BETWEEN_RETRIES_GET_DEPENDENCY_GRAPH_OUTERSPACE,
3120
- space: localUserSpace,
3121
- });
3122
- /** all addrs we already have locally */
3123
- const addrsAlreadyStoredLocally = Object.keys(localDependencyGraphs);
3124
- // get dependency graph from outer space, skipping all addrs in local already
3125
- const newerAddrsFromOuterSpace = Object.values(updates);
3126
- const newerIbGibDependencyGraphFromOuterSpace = await getDependencyGraph({
3127
- ibGibAddrs: newerAddrsFromOuterSpace,
3128
- live: false,
3129
- skipAddrs: addrsAlreadyStoredLocally,
3130
- space: outerSpace,
3131
- });
3132
- const newerIbGibsFromOuterSpace = Object.values(newerIbGibDependencyGraphFromOuterSpace);
3133
- if (logalot) {
3134
- console.log(`${lc} got ${newerIbGibsFromOuterSpace.length} ibGibs from outerspace`);
3135
- }
3136
- // save locally
3137
- if (logalot) {
3138
- console.log(`${lc} saving new ibgibs from outerspace in local space...`);
3139
- }
3140
- if (newerIbGibsFromOuterSpace.length > 0) {
3141
- await this.put({ ibGibs: newerIbGibsFromOuterSpace });
3142
- // register the newest tjp ibGibs locally
3143
- if (logalot) {
3144
- console.log(`${lc} registering "new" updated tjp ibgibs locally...`);
3145
- }
3146
- for (let i = 0; i < tjpAddrs.length; i++) {
3147
- const tjpAddr = tjpAddrs[i];
3148
- const updatedAddr = updates[tjpAddr];
3149
- if (!addrsAlreadyStoredLocally.includes(updatedAddr)) {
3150
- const updatedIbGib = newerIbGibDependencyGraphFromOuterSpace[updatedAddr];
3151
- if (!updatedIbGib) {
3152
- throw new Error(`did not get updatedIbGib (${updatedAddr}) from outerspace (${outerSpace.data.uuid}) (E: 818de70f5b444a3ba198ba6480a15b04)`);
3153
- }
3154
- await this.registerNewIbGib({ ibGib: updatedIbGib });
3155
- }
3156
- }
3157
- }
3158
- }
3159
- catch (error) {
3160
- console.error(`${lc} ${error.message}`);
3161
- // does not rethrow
3162
- }
3163
- finally {
3164
- if (logalot) {
3165
- console.log(`${lc} complete.`);
3166
- }
3167
- }
3168
- }
3058
+ // protected async handleWatchTjpUpdates({
3059
+ // updates,
3060
+ // outerSpace,
3061
+ // localUserSpace,
3062
+ // }: {
3063
+ // updates: { [tjpAddr: string]: IbGibAddr; }
3064
+ // outerSpace: IbGibSpaceAny,
3065
+ // localUserSpace: IbGibSpaceAny,
3066
+ // }): Promise<void> {
3067
+ // const lc = `${this.lc}[${this.handleWatchTjpUpdates.name}]`;
3068
+ // if (logalot) { console.log(`${lc} starting...`); }
3069
+ // try {
3070
+ // if (!outerSpace.data) { throw new Error(`outerSpace.data falsy (E: b5fde89e87bef9b8b6ce38e24be4a823)`); }
3071
+ // /**
3072
+ // * compile list of addrs we have locally for all updates, so we don't try
3073
+ // * to download them from outer space unnecessarily.
3074
+ // */
3075
+ // const latestAddrsLocallyWithUpdate: IbGibAddr[] = [];
3076
+ // const tjpAddrs = Object.keys(updates);
3077
+ // const latestAddrs_Store = Object.values(updates);
3078
+ // for (let i = 0; i < tjpAddrs.length; i++) {
3079
+ // const tjpAddr = tjpAddrs[i];
3080
+ // if (logalot) { console.log(`${lc} tjpAddr: ${tjpAddr}`); }
3081
+ // const latestAddrLocally = await this.getLatestAddr({ tjpAddr }) ?? tjpAddr;
3082
+ // if (
3083
+ // !latestAddrs_Store.includes(latestAddrLocally) &&
3084
+ // !latestAddrsLocallyWithUpdate.includes(latestAddrLocally)
3085
+ // ) {
3086
+ // latestAddrsLocallyWithUpdate.push(latestAddrLocally);
3087
+ // }
3088
+ // }
3089
+ // if (latestAddrsLocallyWithUpdate.length === 0) {
3090
+ // if (logalot) { console.log(`${lc} latestAddrsLocallyWithUpdate.length === 0. We already had all of the updates locally perhaps. Returning early. (I: 844193c515084d0ebc348349f1ac41f4)`); }
3091
+ // return; /* <<<< returns early */
3092
+ // }
3093
+ // /**
3094
+ // * LOCAL dependencies for latest LOCAL addrs for all tjpAddrs in updates.
3095
+ // */
3096
+ // const localDependencyGraphs = await this.getDependencyGraph({
3097
+ // ibGibAddrs: latestAddrsLocallyWithUpdate,
3098
+ // live: true,
3099
+ // maxRetries: DEFAULT_MAX_RETRIES_GET_DEPENDENCY_GRAPH_OUTERSPACE,
3100
+ // msBetweenRetries: DEFAULT_MS_BETWEEN_RETRIES_GET_DEPENDENCY_GRAPH_OUTERSPACE,
3101
+ // space: localUserSpace,
3102
+ // });
3103
+ // /** all addrs we already have locally */
3104
+ // const addrsAlreadyStoredLocally = Object.keys(localDependencyGraphs);
3105
+ // // get dependency graph from outer space, skipping all addrs in local already
3106
+ // const newerAddrsFromOuterSpace: IbGibAddr[] = Object.values(updates);
3107
+ // const newerIbGibDependencyGraphFromOuterSpace = await getDependencyGraph({
3108
+ // ibGibAddrs: newerAddrsFromOuterSpace,
3109
+ // live: false,
3110
+ // skipAddrs: addrsAlreadyStoredLocally,
3111
+ // space: outerSpace,
3112
+ // });
3113
+ // const newerIbGibsFromOuterSpace: IbGib_V1[] =
3114
+ // Object.values(newerIbGibDependencyGraphFromOuterSpace);
3115
+ // if (logalot) { console.log(`${lc} got ${newerIbGibsFromOuterSpace.length} ibGibs from outerspace`); }
3116
+ // // save locally
3117
+ // if (logalot) { console.log(`${lc} saving new ibgibs from outerspace in local space...`); }
3118
+ // if (newerIbGibsFromOuterSpace.length > 0) {
3119
+ // await this.put({ ibGibs: newerIbGibsFromOuterSpace });
3120
+ // // register the newest tjp ibGibs locally
3121
+ // if (logalot) { console.log(`${lc} registering "new" updated tjp ibgibs locally...`); }
3122
+ // for (let i = 0; i < tjpAddrs.length; i++) {
3123
+ // const tjpAddr = tjpAddrs[i];
3124
+ // const updatedAddr = updates[tjpAddr];
3125
+ // if (!addrsAlreadyStoredLocally.includes(updatedAddr)) {
3126
+ // const updatedIbGib = newerIbGibDependencyGraphFromOuterSpace[updatedAddr];
3127
+ // if (!updatedIbGib) {
3128
+ // throw new Error(`did not get updatedIbGib (${updatedAddr}) from outerspace (${outerSpace.data.uuid}) (E: 818de70f5b444a3ba198ba6480a15b04)`);
3129
+ // }
3130
+ // await this.registerNewIbGib({ ibGib: updatedIbGib });
3131
+ // }
3132
+ // }
3133
+ // }
3134
+ // } catch (error) {
3135
+ // console.error(`${lc} ${error.message}`);
3136
+ // // does not rethrow
3137
+ // } finally {
3138
+ // if (logalot) { console.log(`${lc} complete.`); }
3139
+ // }
3140
+ // }
3169
3141
  // #endregion syncIbGibs related
3170
3142
  // #region autosync
3171
3143
  async enableAutosync({ tjpIbGibs, }) {