@ibgib/core-gib 0.0.68 → 0.0.70
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/common/encrypt/encrypt-constants.d.mts +4 -0
- package/dist/common/encrypt/encrypt-constants.d.mts.map +1 -1
- package/dist/common/encrypt/encrypt-constants.mjs +4 -0
- package/dist/common/encrypt/encrypt-constants.mjs.map +1 -1
- package/dist/common/encrypt/encrypt-types.d.mts +1 -4
- package/dist/common/encrypt/encrypt-types.d.mts.map +1 -1
- package/dist/common/encrypt/encrypt-types.mjs +0 -1
- package/dist/common/encrypt/encrypt-types.mjs.map +1 -1
- package/dist/common/pubsub/subject/subject-v1.d.mts.map +1 -1
- package/dist/common/pubsub/subject/subject-v1.mjs +1 -0
- package/dist/common/pubsub/subject/subject-v1.mjs.map +1 -1
- package/dist/witness/space/metaspace/metaspace-base.d.mts +11 -3
- package/dist/witness/space/metaspace/metaspace-base.d.mts.map +1 -1
- package/dist/witness/space/metaspace/metaspace-base.mjs +56 -56
- package/dist/witness/space/metaspace/metaspace-base.mjs.map +1 -1
- package/dist/witness/space/metaspace/metaspace-types.d.mts +4 -0
- package/dist/witness/space/metaspace/metaspace-types.d.mts.map +1 -1
- package/dist/witness/space/outer-space/outer-space-types.d.mts +15 -6
- package/dist/witness/space/outer-space/outer-space-types.d.mts.map +1 -1
- package/dist/witness/space/outer-space/outer-space-types.mjs +15 -6
- package/dist/witness/space/outer-space/outer-space-types.mjs.map +1 -1
- package/package.json +1 -1
- package/src/common/encrypt/encrypt-constants.mts +5 -0
- package/src/common/encrypt/encrypt-types.mts +2 -2
- package/src/common/pubsub/subject/subject-v1.mts +1 -0
- package/src/witness/space/metaspace/metaspace-base.mts +76 -73
- package/src/witness/space/metaspace/metaspace-types.mts +4 -0
- package/src/witness/space/outer-space/outer-space-types.mts +15 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ibgib/core-gib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.70",
|
|
4
4
|
"description": "ibgib core functionality, including base architecture for witnesses, spaces, apps, robbots, etc., as well as shared utility functions. Node v19+ needed for heavily-used isomorphic webcrypto hashing consumed in both node and browsers.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "https://gitlab.com/ibgib/core-gib",
|
|
@@ -27,6 +27,11 @@ export const ENCRYPTION_NAME_REGEXP = /^[a-zA-Z0-9_\-.]{1,255}$/;
|
|
|
27
27
|
* An encryptions ibgib uses this rel8n name for its children encryptions.
|
|
28
28
|
*/
|
|
29
29
|
export const ENCRYPTION_REL8N_NAME = 'encryption';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* atom for ciphertext...hmm
|
|
33
|
+
*/
|
|
34
|
+
export const CIPHERTEXT_ATOM = 'ciphertext';
|
|
30
35
|
/**
|
|
31
36
|
* Related encrypted ciphertext ibgibs will use this rel8n name.
|
|
32
37
|
* Those ciphertext ibgibs will then relate to the encryption used.
|
|
@@ -116,7 +116,7 @@ export interface EncryptionIbGib_V1 extends IbGib_V1<EncryptionData_V1, Encrypti
|
|
|
116
116
|
/**
|
|
117
117
|
* Data for the actual encrypted ciphertext.
|
|
118
118
|
*/
|
|
119
|
-
export interface CiphertextData<TMetadata = any> {
|
|
119
|
+
export interface CiphertextData<TMetadata = any> extends IbGibData_V1 {
|
|
120
120
|
ciphertext?: string;
|
|
121
121
|
metadata?: TMetadata;
|
|
122
122
|
}
|
|
@@ -125,7 +125,7 @@ export interface CiphertextData<TMetadata = any> {
|
|
|
125
125
|
* Rel8ns for the actual encrypted ciphertext
|
|
126
126
|
*/
|
|
127
127
|
export interface CiphertextRel8ns extends IbGibRel8ns_V1 {
|
|
128
|
-
[ENCRYPTION_REL8N_NAME]?: IbGibAddr[];
|
|
128
|
+
// [ENCRYPTION_REL8N_NAME]?: IbGibAddr[];
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
/**
|
|
@@ -266,6 +266,7 @@ export class Subject_V1<
|
|
|
266
266
|
// dispatch to observer's via its `next` fn
|
|
267
267
|
await (observer as ObserverWitness<TIbGibIn_ie_Payload>).next(payloadIbGib);
|
|
268
268
|
} else {
|
|
269
|
+
debugger; // unexpected error state
|
|
269
270
|
console.warn(`${lc} (UNEXPECTED) subscriber reference still held but is unsubscribed? skipping for now (i.e. won't remove subscriber) in case that code is in yielded execution and just hasn't gotten around to it with event loop (but that would be weird). (W: c116e799f6b9483c97fd030eb0dd09ea)`)
|
|
270
271
|
}
|
|
271
272
|
}
|
|
@@ -5,9 +5,9 @@ import { IbGib_V1, } from '@ibgib/ts-gib/dist/V1/types.mjs';
|
|
|
5
5
|
import { GIB, GIB_DELIMITER, IB, ROOT, } from '@ibgib/ts-gib/dist/V1/constants.mjs';
|
|
6
6
|
import { IbGibAddr, TjpIbGibAddr, TransformResult, } from '@ibgib/ts-gib/dist/types.mjs';
|
|
7
7
|
import { getIbGibAddr, } from '@ibgib/ts-gib/dist/helper.mjs';
|
|
8
|
-
import { Factory_V1 as factory } from '@ibgib/ts-gib/dist/V1/index.mjs';
|
|
9
8
|
import { getGib, getGibInfo, isPrimitive } from '@ibgib/ts-gib/dist/V1/transforms/transform-helper.mjs';
|
|
10
9
|
|
|
10
|
+
import { GLOBAL_LOG_A_LOT, GLOBAL_TIMER_NAME } from '../../../core-constants.mjs';
|
|
11
11
|
import {
|
|
12
12
|
DeleteIbGibOpts, DeleteIbGibResult,
|
|
13
13
|
GetIbGibOpts, GetIbGibResult,
|
|
@@ -31,44 +31,37 @@ import {
|
|
|
31
31
|
} from '../../../common/encrypt/encrypt-types.mjs';
|
|
32
32
|
import { RobbotIbGib_V1 } from '../../../witness/robbot/robbot-types.mjs';
|
|
33
33
|
import { AppIbGib_V1 } from '../../../witness/app/app-types.mjs';
|
|
34
|
-
import {
|
|
35
|
-
getTimelinesGroupedByTjp, getTjpAddr, hasTjp
|
|
36
|
-
} from '../../../common/other/ibgib-helper.mjs';
|
|
37
|
-
// import {
|
|
38
|
-
// getFnPrompt, getFnAlert, getFnPromptPassword
|
|
39
|
-
// } from '../../../common/prompt-functions.mjs';
|
|
34
|
+
import { constantIbGib, getTimelinesGroupedByTjp, hasTjp } from '../../../common/other/ibgib-helper.mjs';
|
|
40
35
|
import {
|
|
41
36
|
getValidatedBootstrapIbGib, getLocalSpace, execInSpaceWithLocking,
|
|
42
37
|
updateBootstrapIbGib, getSpaceArgMetadata, createTagIbGibAndSundry,
|
|
43
38
|
getConfigAddr, setConfigAddr, setCurrentRoot, rel8ToCurrentRoot,
|
|
44
39
|
rel8ToSpecialIbGib, registerNewIbGib, persistTransformResult, getFromSpace,
|
|
45
|
-
putInSpace, deleteFromSpace, getLatestAddrs, getTjpIbGib,
|
|
46
|
-
|
|
47
|
-
trash, archive, parseSpaceIb,
|
|
40
|
+
putInSpace, deleteFromSpace, getLatestAddrs, getTjpIbGib, getSpecialIbGib,
|
|
41
|
+
getSpecialRel8dIbGibs, /*createRobbotIbGib, */ trash, archive, parseSpaceIb,
|
|
48
42
|
} from '../../../witness/space/space-helper.mjs';
|
|
49
43
|
import { getDependencyGraph, GetDependencyGraphOptions } from '../../../common/other/graph-helper.mjs';
|
|
50
|
-
import { spaceNameIsValid, } from '../../../witness/space/space-helper.mjs';
|
|
51
44
|
import { RobbotPromptResult } from '../../../witness/robbot/robbot-types.mjs';
|
|
52
45
|
import { createNewRobbot, validateCommonRobbotData, validateCommonRobbotIbGib } from '../../../witness/robbot/robbot-helper.mjs';
|
|
53
46
|
import { AppPromptResult } from '../../../witness/app/app-types.mjs';
|
|
54
47
|
import { createNewApp, } from '../../../witness/app/app-helper.mjs';
|
|
55
|
-
import { CommentIbGib_V1, UpdateCommentPromptResult } from '../../../common/comment/comment-types.mjs';
|
|
56
48
|
import { IbGibCacheService } from '../../../common/cache/cache-types.mjs';
|
|
57
49
|
import { BOOTSTRAP_DATA_KNOWN_SPACE_IDS_KEY, BOOTSTRAP_IBGIB_ADDR } from '../../../witness/space/bootstrap/bootstrap-constants.mjs';
|
|
58
|
-
import {
|
|
59
|
-
import {
|
|
60
|
-
|
|
50
|
+
import { DEFAULT_SECONDS_VALID_LOCAL, SYNC_SPACE_REL8N_NAME } from '../../../witness/space/space-constants.mjs';
|
|
51
|
+
import {
|
|
52
|
+
CIPHERTEXT_ATOM, DEFAULT_ENCRYPTION_HASH_ALGORITHM,
|
|
53
|
+
DEFAULT_ENCRYPTION_INITIAL_RECURSIONS,
|
|
54
|
+
DEFAULT_ENCRYPTION_RECURSIONS_PER_HASH, DEFAULT_ENCRYPTION_SALT_STRATEGY,
|
|
55
|
+
ENCRYPTION_REL8N_NAME,
|
|
56
|
+
} from '../../../common/encrypt/encrypt-constants.mjs';
|
|
61
57
|
import { ROBBOT_REL8N_NAME } from '../../../witness/robbot/robbot-constants.mjs';
|
|
62
58
|
import { APP_REL8N_NAME } from '../../../witness/app/app-constants.mjs';
|
|
63
59
|
import { AUTOSYNC_ALWAYS_REL8N_NAME } from '../../../common/other/other-constants.mjs';
|
|
64
60
|
import {
|
|
65
|
-
MetaspaceInitializeOptions, CreateLocalSpaceOptions,
|
|
66
|
-
LocalSpaceFactoryFunction,
|
|
61
|
+
MetaspaceInitializeOptions, CreateLocalSpaceOptions,
|
|
62
|
+
LocalSpaceFactoryFunction, MetaspaceFactory
|
|
67
63
|
} from './metaspace-types.mjs';
|
|
68
64
|
import { MetaspaceService, TempCacheEntry } from './metaspace-types.mjs';
|
|
69
|
-
import { InnerSpace_V1 } from '../../../witness/space/inner-space/inner-space-v1.mjs';
|
|
70
|
-
|
|
71
|
-
import { GLOBAL_LOG_A_LOT, GLOBAL_TIMER_NAME } from '../../../core-constants.mjs';
|
|
72
65
|
import { newupSubject } from '../../../common/pubsub/subject/subject-helper.mjs';
|
|
73
66
|
import { ObservableWitness, } from '../../../common/pubsub/observable/observable-types.mjs';
|
|
74
67
|
import { SubjectWitness } from '../../../common/pubsub/subject/subject-types.mjs';
|
|
@@ -1750,6 +1743,9 @@ export abstract class MetaspaceBase implements MetaspaceService {
|
|
|
1750
1743
|
}
|
|
1751
1744
|
}
|
|
1752
1745
|
|
|
1746
|
+
/**
|
|
1747
|
+
* creates a ciphertext ibgib (stone) based on the given plaintext.
|
|
1748
|
+
*/
|
|
1753
1749
|
async getCiphertextIbGib<TEncryptionIbGib extends IbGib_V1<EncryptionData_V1>, TMetadata = any>({
|
|
1754
1750
|
plaintext,
|
|
1755
1751
|
password,
|
|
@@ -1773,7 +1769,7 @@ export abstract class MetaspaceBase implements MetaspaceService {
|
|
|
1773
1769
|
*/
|
|
1774
1770
|
encryptionIbGib: TEncryptionIbGib,
|
|
1775
1771
|
/**
|
|
1776
|
-
*
|
|
1772
|
+
* Confirms encryption succeeds by doing an immediate decrypt and checking against original data.
|
|
1777
1773
|
*/
|
|
1778
1774
|
confirm?: boolean,
|
|
1779
1775
|
/**
|
|
@@ -1805,7 +1801,7 @@ export abstract class MetaspaceBase implements MetaspaceService {
|
|
|
1805
1801
|
try {
|
|
1806
1802
|
const encryptionInfo = encryptionIbGib.data;
|
|
1807
1803
|
if (encryptionInfo?.method !== EncryptionMethod.encrypt_gib) {
|
|
1808
|
-
throw new Error('only encrypt-gib is implemented.');
|
|
1804
|
+
throw new Error('only encrypt-gib is implemented. (E: 1d8eb1be6d3f44f0a79b498f237147e6');
|
|
1809
1805
|
}
|
|
1810
1806
|
const info: EncryptionInfo_EncryptGib = encryptionInfo;
|
|
1811
1807
|
const resEncrypt = await encrypt({
|
|
@@ -1817,6 +1813,8 @@ export abstract class MetaspaceBase implements MetaspaceService {
|
|
|
1817
1813
|
saltStrategy: info.saltStrategy,
|
|
1818
1814
|
hashAlgorithm: info.hashAlgorithm,
|
|
1819
1815
|
encryptedDataDelimiter: info.encryptedDataDelimiter,
|
|
1816
|
+
blockMode: encryptionInfo.blockMode ? encryptionInfo.blockModeOptions : undefined,
|
|
1817
|
+
indexingMode: encryptionInfo.indexingMode,
|
|
1820
1818
|
confirm,
|
|
1821
1819
|
});
|
|
1822
1820
|
|
|
@@ -1824,40 +1822,34 @@ export abstract class MetaspaceBase implements MetaspaceService {
|
|
|
1824
1822
|
if (resEncrypt.errors?.length ?? 0 > 0) { throw new Error(resEncrypt.errors!.join('\n')); }
|
|
1825
1823
|
if (!resEncrypt.encryptedData) { throw new Error(`encryptedData is falsy`) }
|
|
1826
1824
|
|
|
1827
|
-
const data: CiphertextData = {
|
|
1825
|
+
const data: CiphertextData = {
|
|
1826
|
+
ciphertext: resEncrypt.encryptedData,
|
|
1827
|
+
uuid: await getUUID(),
|
|
1828
|
+
};
|
|
1828
1829
|
if (publicMetadata) { data.metadata = publicMetadata; }
|
|
1829
1830
|
|
|
1830
|
-
const
|
|
1831
|
-
|
|
1831
|
+
const ciphertextIbGib = await constantIbGib<CiphertextData, CiphertextRel8ns>({
|
|
1832
|
+
parentPrimitiveIb: ibRoot || CIPHERTEXT_ATOM,
|
|
1833
|
+
ib:
|
|
1834
|
+
publicIbMetadata ?
|
|
1835
|
+
`${ibRoot || CIPHERTEXT_ATOM} ${publicIbMetadata}` :
|
|
1836
|
+
`${ibRoot || CIPHERTEXT_ATOM}`,
|
|
1837
|
+
data,
|
|
1838
|
+
rel8ns: undefined,
|
|
1839
|
+
}) as CiphertextIbGib_V1;
|
|
1840
|
+
const resTransform: TransformResult<CiphertextIbGib_V1> = {
|
|
1841
|
+
newIbGib: ciphertextIbGib
|
|
1832
1842
|
}
|
|
1833
1843
|
|
|
1834
|
-
const resCiphertext = (
|
|
1835
|
-
await factory.firstGen({
|
|
1836
|
-
parentIbGib: factory.primitive({ ib: ibRoot || 'ciphertext' }),
|
|
1837
|
-
ib:
|
|
1838
|
-
publicIbMetadata ?
|
|
1839
|
-
`${ibRoot || 'ciphertext'} ${publicIbMetadata}` :
|
|
1840
|
-
`${ibRoot || 'ciphertext'}`,
|
|
1841
|
-
data,
|
|
1842
|
-
rel8ns,
|
|
1843
|
-
dna: false,
|
|
1844
|
-
tjp: { uuid: true, timestamp: true },
|
|
1845
|
-
nCounter: true,
|
|
1846
|
-
})
|
|
1847
|
-
) as TransformResult<CiphertextIbGib_V1>;
|
|
1848
|
-
|
|
1849
|
-
if (!resCiphertext.newIbGib) { throw new Error('Error creating ciphertext ibgib.'); }
|
|
1850
|
-
|
|
1851
1844
|
if (persist) {
|
|
1852
|
-
await this.persistTransformResult({ resTransform
|
|
1845
|
+
await this.persistTransformResult({ resTransform });
|
|
1853
1846
|
}
|
|
1854
1847
|
|
|
1855
|
-
return
|
|
1848
|
+
return resTransform;
|
|
1856
1849
|
} catch (error) {
|
|
1857
1850
|
console.error(`${lc} ${error.message}`);
|
|
1858
1851
|
throw error;
|
|
1859
1852
|
}
|
|
1860
|
-
|
|
1861
1853
|
}
|
|
1862
1854
|
|
|
1863
1855
|
/**
|
|
@@ -2586,10 +2578,15 @@ export abstract class MetaspaceBase implements MetaspaceService {
|
|
|
2586
2578
|
protected subSagaSyncTimeLog: SubscriptionWitness | undefined;
|
|
2587
2579
|
|
|
2588
2580
|
async syncIbGibs({
|
|
2581
|
+
localSpace,
|
|
2589
2582
|
dependencyGraphIbGibs,
|
|
2590
2583
|
syncSpaceIbGibs,
|
|
2591
2584
|
// watch,
|
|
2592
2585
|
}: {
|
|
2586
|
+
/**
|
|
2587
|
+
* @see {@link MetaspaceService.syncIbGibs}
|
|
2588
|
+
*/
|
|
2589
|
+
localSpace: IbGibSpaceAny,
|
|
2593
2590
|
/**
|
|
2594
2591
|
* @see {@link MetaspaceService.syncIbGibs}
|
|
2595
2592
|
*/
|
|
@@ -2618,18 +2615,20 @@ export abstract class MetaspaceBase implements MetaspaceService {
|
|
|
2618
2615
|
|
|
2619
2616
|
// have to make sagaId and syncStatus$ early to enable timeLog calls
|
|
2620
2617
|
const sagaId = (await getUUID()).slice(0, 24);
|
|
2621
|
-
const syncStatus$ = await newupSubject<SyncStatusIbGib>();
|
|
2618
|
+
const syncStatus$ = await newupSubject<SyncStatusIbGib>({ replay: true });
|
|
2622
2619
|
const syncTimelogName = `sync_log ${sagaId}`;
|
|
2623
2620
|
console.time(syncTimelogName);
|
|
2624
2621
|
console.timeLog(syncTimelogName, 'start');
|
|
2625
2622
|
this.subSagaSyncTimeLog = await syncStatus$.subscribe(fnObs<SyncStatusIbGib>({
|
|
2626
2623
|
next: async (status) => {
|
|
2624
|
+
// debugger; // metaspacebase syncIbGibs next
|
|
2627
2625
|
if (logalot) { console.log(`${lc}[obs.next] next called (I: 9af8d3267b0ff473fe5f8024f0dbed23)`); }
|
|
2628
2626
|
if (status.data?.statusCode === StatusCode.completed) {
|
|
2629
2627
|
console.timeLog(syncTimelogName, 'StatusCode.complete');
|
|
2630
2628
|
}
|
|
2631
2629
|
},
|
|
2632
2630
|
error: async (_: any) => {
|
|
2631
|
+
// debugger; // metaspacebase syncIbGibs error
|
|
2633
2632
|
if (logalot) { console.log(`${lc}[obs.error] error called (I: 976b08ab82d64299b17927eac16b1693)`); }
|
|
2634
2633
|
console.timeEnd(syncTimelogName)
|
|
2635
2634
|
if (!this.subSagaSyncTimeLog) {
|
|
@@ -2638,6 +2637,7 @@ export abstract class MetaspaceBase implements MetaspaceService {
|
|
|
2638
2637
|
await this.subSagaSyncTimeLog!.unsubscribe();
|
|
2639
2638
|
},
|
|
2640
2639
|
complete: async () => {
|
|
2640
|
+
// debugger; // metaspacebase syncIbGibs complete
|
|
2641
2641
|
if (logalot) { console.log(`${lc}[obs.complete] complete called (I: 72307340e2b34b22b0787e3a3c906c06)`); }
|
|
2642
2642
|
console.timeEnd(syncTimelogName)
|
|
2643
2643
|
if (!this.subSagaSyncTimeLog) {
|
|
@@ -2653,7 +2653,7 @@ export abstract class MetaspaceBase implements MetaspaceService {
|
|
|
2653
2653
|
if (!syncSpaceIbGibs || syncSpaceIbGibs.length === 0) { throw new Error(`syncSpaceIbGibs required (E: c5a022454b9ce34856e141e61e337d24)`); }
|
|
2654
2654
|
// #endregion
|
|
2655
2655
|
|
|
2656
|
-
const localUserSpace = await this.getLocalUserSpace({});
|
|
2656
|
+
const localUserSpace = localSpace ?? await this.getLocalUserSpace({});
|
|
2657
2657
|
if (!localUserSpace?.data) { throw new Error(`localUserSpace?.data falsy (E: e7ff57e4d529cde903619078ee9b6e23)`); }
|
|
2658
2658
|
if (!localUserSpace.gib) { throw new Error(`localUserSpace.gib falsy (E: 884d86d20e7a4468b3c8b2c3ab7dba7e)`); }
|
|
2659
2659
|
|
|
@@ -2755,10 +2755,13 @@ export abstract class MetaspaceBase implements MetaspaceService {
|
|
|
2755
2755
|
`${lc} something went wrong (E: d7db873d9e8b4f14b5b490cadd9730f4)`;
|
|
2756
2756
|
console.error(emsg);
|
|
2757
2757
|
if (!sagaInfo.syncStatus$.error) { throw new Error(`(UNEXPECTED) sagaInfo.syncStatus$.error is falsy? (E: 8522f275dbbf0885db75aead27d72923)`); }
|
|
2758
|
-
sagaInfo.syncStatus$.error!(emsg);
|
|
2758
|
+
await sagaInfo.syncStatus$.error!(emsg);
|
|
2759
2759
|
}
|
|
2760
|
-
|
|
2761
|
-
sagaInfo.syncStatus$.complete();
|
|
2760
|
+
// we don't call complete() from within a next() (i don't think)
|
|
2761
|
+
// if (!sagaInfo.syncStatus$.complete) { throw new Error(`(UNEXPECTED) sagaInfo.syncStatus$.complete is falsy? (E: 836f42d8f7084ff9afd73696134d41e6)`); }
|
|
2762
|
+
// if (!sagaInfo.syncStatus$.isCompleteOrErrored) {
|
|
2763
|
+
// await sagaInfo.syncStatus$.complete();
|
|
2764
|
+
// }
|
|
2762
2765
|
}
|
|
2763
2766
|
// I think $.complete() closes subscriptions, but to be double sure...
|
|
2764
2767
|
let toUnsubscribe: SubscriptionWitness[] = [];
|
|
@@ -2766,15 +2769,10 @@ export abstract class MetaspaceBase implements MetaspaceService {
|
|
|
2766
2769
|
for (let i = 0; i < subscriptions.length; i++) {
|
|
2767
2770
|
const sub = subscriptions[i];
|
|
2768
2771
|
let unsubscribed = await sub.unsubscribed();
|
|
2769
|
-
if (!unsubscribed) {
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
// .forEach(sub => { sub.unsubscribe(); });
|
|
2774
|
-
// for (let i = 0; i < toUnsubscribe.length; i++) {
|
|
2775
|
-
// let sub = toUnsubscribe[i];
|
|
2776
|
-
// await sub.unsubscribe();
|
|
2777
|
-
// }
|
|
2772
|
+
if (!unsubscribed) {
|
|
2773
|
+
await sub.unsubscribe();
|
|
2774
|
+
}
|
|
2775
|
+
}
|
|
2778
2776
|
|
|
2779
2777
|
if (logalot) { console.log(`${lc} setting sagaInfo.complete to true (I: 85c34469cdac404782c2024ad6b6fbd1)`); }
|
|
2780
2778
|
sagaInfo.complete = true;
|
|
@@ -3041,25 +3039,21 @@ export abstract class MetaspaceBase implements MetaspaceService {
|
|
|
3041
3039
|
const sagaInfo = infos[i];
|
|
3042
3040
|
|
|
3043
3041
|
let sub = await sagaInfo.syncStatus$
|
|
3044
|
-
// .pipe(
|
|
3045
|
-
// concatMap(async (status: SyncStatusIbGib) => {
|
|
3046
|
-
// if (logalot) { console.log(`${lc}(sagaId: ${sagaInfo.sagaId}) status received. ${status?.data?.statusCode ?? 'no status'}`) }
|
|
3047
|
-
// await this._handleSyncStatusIbGib({ status, sagaInfo });
|
|
3048
|
-
// return status;
|
|
3049
|
-
// })
|
|
3050
|
-
// )
|
|
3051
3042
|
.subscribe(fnObs({
|
|
3052
3043
|
next: async (status: SyncStatusIbGib) => {
|
|
3044
|
+
// debugger; // metaspacebase handlesagaupdates next
|
|
3053
3045
|
if (logalot) { console.log(`${lc}(sagaId: ${sagaInfo.sagaId}) subscribe next triggered. status: ${status?.data?.statusCode} (I: 41e1f61e5e1b422ead1d72a1c92c7d51)`); }
|
|
3054
3046
|
await this._handleSyncStatusIbGib({ status, sagaInfo });
|
|
3055
3047
|
},
|
|
3056
3048
|
error: async (error: string) => {
|
|
3049
|
+
// debugger; // metaspacebase handlesagaupdates error
|
|
3057
3050
|
const emsg = `${lc}(sagaId: ${sagaInfo.sagaId}) syncStatus$.error: ${error}`;
|
|
3058
3051
|
console.error(emsg);
|
|
3059
3052
|
// await this.getFnAlert!()({title: 'couldnt this.syncIbGibs...', msg: emsg});
|
|
3060
3053
|
await this._finalizeSyncSaga({ sagaInfo, error: emsg });
|
|
3061
3054
|
},
|
|
3062
3055
|
complete: async () => {
|
|
3056
|
+
// debugger; // metaspacebase handlesagaupdates complete
|
|
3063
3057
|
if (logalot) { console.log(`${lc}(sagaId: ${sagaInfo.sagaId}) syncStatus$.complete.`); }
|
|
3064
3058
|
}
|
|
3065
3059
|
}));
|
|
@@ -3115,11 +3109,11 @@ export abstract class MetaspaceBase implements MetaspaceService {
|
|
|
3115
3109
|
break;
|
|
3116
3110
|
|
|
3117
3111
|
case StatusCode.merged_dna:
|
|
3118
|
-
await this._handleSyncStatus_Merged({ status });
|
|
3112
|
+
await this._handleSyncStatus_Merged({ status, sagaInfo });
|
|
3119
3113
|
break;
|
|
3120
3114
|
|
|
3121
3115
|
case StatusCode.merged_state:
|
|
3122
|
-
await this._handleSyncStatus_Merged({ status });
|
|
3116
|
+
await this._handleSyncStatus_Merged({ status, sagaInfo });
|
|
3123
3117
|
break;
|
|
3124
3118
|
|
|
3125
3119
|
case StatusCode.already_synced:
|
|
@@ -3146,14 +3140,16 @@ export abstract class MetaspaceBase implements MetaspaceService {
|
|
|
3146
3140
|
if (!sagaInfo.syncStatus$?.error) {
|
|
3147
3141
|
throw new Error(`(UNEXPECTED) sagaInfo.syncStatus$.error falsy? (E: 36cc488835aeb12e1ae6b7a49d0d8523)`);
|
|
3148
3142
|
}
|
|
3149
|
-
sagaInfo.syncStatus$.error(emsg);
|
|
3143
|
+
await sagaInfo.syncStatus$.error(emsg);
|
|
3150
3144
|
}
|
|
3151
3145
|
};
|
|
3152
3146
|
|
|
3153
3147
|
protected async _handleSyncStatus_Merged({
|
|
3154
3148
|
status,
|
|
3149
|
+
sagaInfo,
|
|
3155
3150
|
}: {
|
|
3156
3151
|
status: SyncStatusIbGib,
|
|
3152
|
+
sagaInfo: SyncSagaInfo,
|
|
3157
3153
|
}): Promise<void> {
|
|
3158
3154
|
const lc = `${this.lc}[${this._handleSyncStatus_Merged.name}]`;
|
|
3159
3155
|
try {
|
|
@@ -3171,6 +3167,13 @@ export abstract class MetaspaceBase implements MetaspaceService {
|
|
|
3171
3167
|
|
|
3172
3168
|
if (logalot) { console.log(`${lc} validated.`); }
|
|
3173
3169
|
|
|
3170
|
+
|
|
3171
|
+
const participants_src = sagaInfo.participants.filter(x => x.s_d === 'src');
|
|
3172
|
+
if (participants_src.length !== 1) { throw new Error(`(UNEXPECTED) participants_src.length !== 1? atow (03/2024) only one src participant is expected. (E: ed4b3ae15f5da34c77655553aaf82224)`); }
|
|
3173
|
+
const localSpaceId = participants_src.at(0)!.id;
|
|
3174
|
+
const localSpace = await this.getLocalUserSpace({ localSpaceId });
|
|
3175
|
+
if (!localSpace) { throw new Error(`(UNEXPECTED) couldn't get src participant with space id (${localSpaceId}) in the middle of a saga? (E: c75732b748f6a168254e38dc5548e824)`); }
|
|
3176
|
+
|
|
3174
3177
|
// first, we will store the newly created ibgibs in the local space. Then
|
|
3175
3178
|
// we want to rebase our local timeline to point to the new one. I believe
|
|
3176
3179
|
// we can do this simply by registering the latest created ibgib which
|
|
@@ -3192,7 +3195,7 @@ export abstract class MetaspaceBase implements MetaspaceService {
|
|
|
3192
3195
|
const timeline = timelines[tjpAddr];
|
|
3193
3196
|
const latestIbGibInTimeline = timeline[timeline.length - 1];
|
|
3194
3197
|
// registerNewIbGib is idempotent if already registered as latest
|
|
3195
|
-
await this.registerNewIbGib({ ibGib: latestIbGibInTimeline });
|
|
3198
|
+
await this.registerNewIbGib({ ibGib: latestIbGibInTimeline, space: localSpace });
|
|
3196
3199
|
}
|
|
3197
3200
|
};
|
|
3198
3201
|
|
|
@@ -3201,7 +3204,7 @@ export abstract class MetaspaceBase implements MetaspaceService {
|
|
|
3201
3204
|
// meanwhile, we must collect all ibgib timelines (with tjps) to register
|
|
3202
3205
|
if (status.createdIbGibs?.length ?? 0 > 0) {
|
|
3203
3206
|
if (logalot) { console.log(`${lc} putting createdIbGibs (${status.createdIbGibs!.length}): ${status.createdIbGibs!.map(x => getIbGibAddr({ ibGib: x })).join('\n')}.`); }
|
|
3204
|
-
const resPutCreated = await this.put({ ibGibs: status.createdIbGibs });
|
|
3207
|
+
const resPutCreated = await this.put({ ibGibs: status.createdIbGibs, space: localSpace });
|
|
3205
3208
|
if (!resPutCreated.success) { throw new Error(`Couldn't save created ibGibs locally? (E: f8bc91259c5043d589cd2e7ad2220c1f)`); }
|
|
3206
3209
|
if (status.storeOnlyIbGibs) {
|
|
3207
3210
|
await registerLatestInTimelines(status.storeOnlyIbGibs)
|
|
@@ -3214,7 +3217,7 @@ export abstract class MetaspaceBase implements MetaspaceService {
|
|
|
3214
3217
|
if (status.storeOnlyIbGibs?.length ?? 0 > 0) {
|
|
3215
3218
|
if (logalot) { console.log(`${lc} putting storeOnlyIbGibs (${status.storeOnlyIbGibs!.length}): ${status.storeOnlyIbGibs!.map(x => getIbGibAddr({ ibGib: x })).join('\n')}.`); }
|
|
3216
3219
|
console.warn(`${lc} putting storeOnlyIbGibs (${status.storeOnlyIbGibs!.length}): ${status.storeOnlyIbGibs!.map(x => getIbGibAddr({ ibGib: x })).join('\n')}.`);
|
|
3217
|
-
const resPutStoreOnly = await this.put({ ibGibs: status.storeOnlyIbGibs });
|
|
3220
|
+
const resPutStoreOnly = await this.put({ ibGibs: status.storeOnlyIbGibs, space: localSpace });
|
|
3218
3221
|
if (!resPutStoreOnly.success) { throw new Error(`Couldn't save storeonly ibGibs locally? (E: c5ab044718ab42bba27f5852149b7ddc)`); }
|
|
3219
3222
|
await registerLatestInTimelines(status.storeOnlyIbGibs!)
|
|
3220
3223
|
} else {
|
|
@@ -3229,7 +3232,7 @@ export abstract class MetaspaceBase implements MetaspaceService {
|
|
|
3229
3232
|
for (let i = 0; i < newLatestIbGibs.length; i++) {
|
|
3230
3233
|
const latestIbGib = newLatestIbGibs[i];
|
|
3231
3234
|
if (logalot) { console.log(`${lc} registering latestIbGib in localUserSpace: ${getIbGibAddr({ ibGib: latestIbGib })}`); }
|
|
3232
|
-
await this.registerNewIbGib({ ibGib: latestIbGib });
|
|
3235
|
+
await this.registerNewIbGib({ ibGib: latestIbGib, space: localSpace });
|
|
3233
3236
|
}
|
|
3234
3237
|
|
|
3235
3238
|
if (logalot) { console.log(`${lc} complete.`); }
|
|
@@ -83,21 +83,30 @@ export const StatusCode = {
|
|
|
83
83
|
*/
|
|
84
84
|
updated: 'updated' as StatusCode,
|
|
85
85
|
/**
|
|
86
|
-
* When syncing, this means that we've
|
|
87
|
-
*
|
|
88
|
-
*
|
|
86
|
+
* When syncing, this means that we've reconciled one or more timeline(s)
|
|
87
|
+
* between the local and sync spaces. The process of this was by
|
|
88
|
+
* automatically applying dna ibgibs that did not exist in one or the other
|
|
89
|
+
* timelines, so that the end result is that the dna at the end is
|
|
90
|
+
* "effectively equal". this does not guarantee order, it only guarantees
|
|
91
|
+
* application. anything sensitive to order must be done with locality.
|
|
89
92
|
*
|
|
90
93
|
* Note that in this case, we've created new ibgib to fulfill the operation
|
|
91
94
|
* (besides the derivative metadata ibgibs created in the communication).
|
|
95
|
+
* These ibgibs should be found on the status ibgib.
|
|
96
|
+
*
|
|
97
|
+
* @see {@link merged_state}
|
|
92
98
|
*/
|
|
93
99
|
merged_dna: 'merged_dna' as StatusCode,
|
|
94
100
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
101
|
+
* Similar to {@link merged_dna}, but we didn't have dna to work with. So we
|
|
102
|
+
* fudged and did our best guess at merging the state using some opinionated
|
|
103
|
+
* algorithms.
|
|
98
104
|
*
|
|
99
105
|
* Note that in this case, we've created new ibgib to fulfill the operation
|
|
100
106
|
* (besides the derivative metadata ibgibs created in the communication).
|
|
107
|
+
* These ibgibs should be found on the status ibgib.
|
|
108
|
+
*
|
|
109
|
+
* @see {@link merged_dna}
|
|
101
110
|
*/
|
|
102
111
|
merged_state: 'merged_state' as StatusCode,
|
|
103
112
|
/**
|