@ibgib/core-gib 0.0.65 → 0.0.67
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.
- package/dist/witness/space/metaspace/metaspace-base.d.mts +9 -59
- package/dist/witness/space/metaspace/metaspace-base.d.mts.map +1 -1
- package/dist/witness/space/metaspace/metaspace-base.mjs +272 -300
- package/dist/witness/space/metaspace/metaspace-base.mjs.map +1 -1
- package/dist/witness/space/metaspace/metaspace-types.d.mts +20 -29
- package/dist/witness/space/metaspace/metaspace-types.d.mts.map +1 -1
- package/dist/witness/space/outer-space/outer-space-helper.d.mts +34 -1
- package/dist/witness/space/outer-space/outer-space-helper.d.mts.map +1 -1
- package/dist/witness/space/outer-space/outer-space-helper.mjs +76 -2
- package/dist/witness/space/outer-space/outer-space-helper.mjs.map +1 -1
- package/dist/witness/space/outer-space/outer-space-types.d.mts +10 -0
- package/dist/witness/space/outer-space/outer-space-types.d.mts.map +1 -1
- package/dist/witness/space/outer-space/outer-space-types.mjs.map +1 -1
- package/dist/witness/space/space-helper.d.mts +0 -3
- package/dist/witness/space/space-helper.d.mts.map +1 -1
- package/dist/witness/space/space-helper.mjs +1 -19
- package/dist/witness/space/space-helper.mjs.map +1 -1
- package/package.json +1 -1
- package/src/witness/space/metaspace/metaspace-base.mts +300 -355
- package/src/witness/space/metaspace/metaspace-types.mts +38 -62
- package/src/witness/space/outer-space/outer-space-helper.mts +89 -5
- package/src/witness/space/outer-space/outer-space-types.mts +10 -0
- package/src/witness/space/space-helper.mts +1 -20
|
@@ -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
|
-
|
|
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
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
}: {
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
}): Promise<IbGibSpaceAny> {
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
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
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
}
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(`
|
|
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
|
-
...
|
|
2708
|
-
if (!s.data) { throw new Error(`
|
|
2709
|
-
if (!s.data.uuid) { throw new Error(`
|
|
2710
|
-
if (!s.gib) { throw new Error(`
|
|
2711
|
-
return { id: s.data.uuid, gib: s.gib, s_d: 'dest', }
|
|
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>[] =
|
|
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.
|
|
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
|
|
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.
|
|
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
|
|
2794
|
+
protected async _finalizeAllSyncSagas_NoThrow({
|
|
2842
2795
|
error,
|
|
2843
2796
|
}: {
|
|
2844
2797
|
error?: any,
|
|
2845
2798
|
}): Promise<void> {
|
|
2846
|
-
const lc = `${this.lc}[${this.
|
|
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.
|
|
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.
|
|
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.
|
|
3118
|
+
await this._handleSyncStatus_Merged({ status });
|
|
3174
3119
|
break;
|
|
3175
3120
|
|
|
3176
3121
|
case StatusCode.merged_state:
|
|
3177
|
-
await this.
|
|
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.
|
|
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
|
|
3153
|
+
protected async _handleSyncStatus_Merged({
|
|
3209
3154
|
status,
|
|
3210
3155
|
}: {
|
|
3211
3156
|
status: SyncStatusIbGib,
|
|
3212
3157
|
}): Promise<void> {
|
|
3213
|
-
const lc = `${this.lc}[${this.
|
|
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
|
|
3242
|
+
protected async _handleSyncStatus_Complete({
|
|
3298
3243
|
sagaInfo,
|
|
3299
3244
|
}: {
|
|
3300
3245
|
sagaInfo: SyncSagaInfo,
|
|
3301
3246
|
}): Promise<void> {
|
|
3302
|
-
const lc = `${this.lc}[${this.
|
|
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.
|
|
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.
|
|
3255
|
+
await this._finalizeAllSyncSagas_NoThrow({});
|
|
3311
3256
|
}
|
|
3312
3257
|
} catch (error) {
|
|
3313
3258
|
console.error(`${lc} ${error.message}`);
|
|
3314
|
-
await this.
|
|
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
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
}: {
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
}): Promise<void> {
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
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
|
|