@ibgib/core-gib 0.0.76 → 0.0.77
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/pubsub/observable/observable-base-v1.d.mts +1 -1
- package/dist/common/pubsub/subject/subject-v1.d.mts +1 -1
- package/dist/common/pubsub/subscription/subscription-v1.d.mts +1 -1
- package/dist/witness/app/app-base-v1.d.mts +1 -1
- package/dist/witness/keystone/keystone-base-v1.d.mts +1 -1
- package/dist/witness/robbot/robbot-base-v1.mjs +3 -3
- package/dist/witness/space/metaspace/metaspace-base.d.mts.map +1 -1
- package/dist/witness/space/metaspace/metaspace-base.mjs +1 -1
- package/dist/witness/space/metaspace/metaspace-base.mjs.map +1 -1
- package/dist/witness/witness-with-context/witness-with-context-base-v1.d.mts +8 -8
- package/dist/witness/witness-with-context/witness-with-context-base-v1.mjs +51 -51
- package/package.json +1 -1
- package/src/common/pubsub/observable/observable-base-v1.mts +1 -1
- package/src/common/pubsub/subject/subject-v1.mts +1 -1
- package/src/common/pubsub/subscription/subscription-v1.mts +1 -1
- package/src/witness/app/app-base-v1.mts +1 -1
- package/src/witness/keystone/keystone-base-v1.mts +1 -1
- package/src/witness/robbot/robbot-base-v1.mts +2 -2
- package/src/witness/space/metaspace/metaspace-base.mts +5 -2
- package/src/witness/witness-with-context/witness-with-context-base-v1.mts +47 -47
|
@@ -102,7 +102,7 @@ export abstract class WitnessWithContextBase_V1<
|
|
|
102
102
|
*
|
|
103
103
|
* todo: refactor this to `metaspace` after we have completed majority of refactor/breakout from mvp
|
|
104
104
|
*/
|
|
105
|
-
public
|
|
105
|
+
public metaspace: MetaspaceService | undefined;
|
|
106
106
|
|
|
107
107
|
protected _contextChangesSubscription: SubscriptionWitness | undefined;
|
|
108
108
|
protected _currentWorkingContextIbGib: IbGib_V1 | undefined;
|
|
@@ -142,13 +142,13 @@ export abstract class WitnessWithContextBase_V1<
|
|
|
142
142
|
const lc = `${this.lc}[${this.loadNewerSelfIfAvailable.name}]`;
|
|
143
143
|
try {
|
|
144
144
|
if (logalot) { console.log(`${lc} starting... (I: 94755c3131f4dfa12d20fa38e2926522)`); }
|
|
145
|
-
if (this.
|
|
145
|
+
if (this.metaspace) {
|
|
146
146
|
// check for newer version of self locally before executing
|
|
147
147
|
const thisAddr = getIbGibAddr({ ibGib: this });
|
|
148
|
-
const latestAddr = await this.
|
|
148
|
+
const latestAddr = await this.metaspace.getLatestAddr({ ibGib: this });
|
|
149
149
|
if (latestAddr && latestAddr !== thisAddr) {
|
|
150
150
|
// this has a newer ibgib in its timeline
|
|
151
|
-
let resGet = await this.
|
|
151
|
+
let resGet = await this.metaspace.get({ addr: latestAddr });
|
|
152
152
|
if (!resGet || !resGet?.success || (resGet?.ibGibs ?? []).length === 0) {
|
|
153
153
|
throw new Error(`could not get newer ibgib in timeline (E: 15fa346c8ac17edb96e4b0870104c122)`);
|
|
154
154
|
}
|
|
@@ -157,7 +157,7 @@ export abstract class WitnessWithContextBase_V1<
|
|
|
157
157
|
if (validationErrors?.length > 0) { throw new Error(`validationErrors when loading newer version: ${pretty(validationErrors)} (E: 0d9f0684a1ff6af44e20a57130e3ac22)`); }
|
|
158
158
|
}
|
|
159
159
|
} else {
|
|
160
|
-
console.warn(`${lc} this.
|
|
160
|
+
console.warn(`${lc} this.metaspace undefined (W: 44cc5bf1b14b4695b8de4c589787be06)`);
|
|
161
161
|
}
|
|
162
162
|
} catch (error) {
|
|
163
163
|
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
@@ -176,20 +176,20 @@ export abstract class WitnessWithContextBase_V1<
|
|
|
176
176
|
*
|
|
177
177
|
* @see {@link ibGibs}
|
|
178
178
|
* @see {@link rel8nName}
|
|
179
|
-
* @see {@link
|
|
179
|
+
* @see {@link metaspace}
|
|
180
180
|
* @see {@link space}
|
|
181
181
|
*
|
|
182
182
|
* ## notes
|
|
183
183
|
*
|
|
184
|
-
* * If there is no given `space`, then we will use the `
|
|
184
|
+
* * If there is no given `space`, then we will use the `metaspace` to get
|
|
185
185
|
* the local user space. If none, then we skip persistence.
|
|
186
|
-
* * If there is no `
|
|
186
|
+
* * If there is no `metaspace`, we won't register the new ibgibs locally.
|
|
187
187
|
*/
|
|
188
188
|
protected async rel8To({
|
|
189
189
|
ibGibs,
|
|
190
190
|
rel8nName,
|
|
191
191
|
linked,
|
|
192
|
-
|
|
192
|
+
metaspace,
|
|
193
193
|
// space,
|
|
194
194
|
}: {
|
|
195
195
|
/**
|
|
@@ -211,7 +211,7 @@ export abstract class WitnessWithContextBase_V1<
|
|
|
211
211
|
/**
|
|
212
212
|
* If provided, will register the newly created ibgib.
|
|
213
213
|
*/
|
|
214
|
-
|
|
214
|
+
metaspace?: MetaspaceService,
|
|
215
215
|
// /**
|
|
216
216
|
// * If given (which atow is most likely the case), then the {@link TransformResult} will
|
|
217
217
|
// * be persisted in this `space`.
|
|
@@ -232,24 +232,24 @@ export abstract class WitnessWithContextBase_V1<
|
|
|
232
232
|
const thisValidationErrors = await this.validateThis();
|
|
233
233
|
if (thisValidationErrors?.length > 0) { throw new Error(`this is an invalid ibGib. thisValidationErrors: ${thisValidationErrors.join('|')} (E: 8f08716866cd13bf254222ee9e6a6722)`); }
|
|
234
234
|
|
|
235
|
-
|
|
235
|
+
metaspace = metaspace ?? this.metaspace;
|
|
236
236
|
|
|
237
|
-
if (!
|
|
238
|
-
// if (this.
|
|
239
|
-
// if (logalot) { console.log(`${lc}
|
|
240
|
-
//
|
|
237
|
+
if (!metaspace) {
|
|
238
|
+
// if (this.metaspace) {
|
|
239
|
+
// if (logalot) { console.log(`${lc} metaspace arg falsy, but we have a reference on this object, which we will use. (I: ee0d39a47ee8aee8ffd797721fea4322)`); }
|
|
240
|
+
// metaspace = this.metaspace;
|
|
241
241
|
// }
|
|
242
|
-
throw new Error(`either
|
|
242
|
+
throw new Error(`either metaspace or this.metaspace required (E: b5f9453ddb394a2b76dec74c7304df22)`);
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
// if (!space) {
|
|
246
|
-
// if (
|
|
247
|
-
// if (logalot) { console.log(`${lc} space arg falsy, but
|
|
248
|
-
// space = await
|
|
246
|
+
// if (metaspace) {
|
|
247
|
+
// if (logalot) { console.log(`${lc} space arg falsy, but metaspace truthy, so we'll use metaspace's local user space for persistence. (I: 37a4b4c1406556cb23831671755b0d22)`); }
|
|
248
|
+
// space = await metaspace.getLocalUserSpace({ lock: true });
|
|
249
249
|
// }
|
|
250
250
|
// }
|
|
251
251
|
|
|
252
|
-
// if (!space) { throw new Error(`(UNEXPECTED) space required and
|
|
252
|
+
// if (!space) { throw new Error(`(UNEXPECTED) space required and metaspace couldn't get it? (E: a3b9f9b72f6f6f18883199a19d38c622)`); }
|
|
253
253
|
|
|
254
254
|
// #endregion initialize, validate args and this
|
|
255
255
|
|
|
@@ -285,7 +285,7 @@ export abstract class WitnessWithContextBase_V1<
|
|
|
285
285
|
|
|
286
286
|
// if space is given, perform the persistence
|
|
287
287
|
// if (space) {
|
|
288
|
-
await
|
|
288
|
+
await metaspace.persistTransformResult({ resTransform: resNewThis });
|
|
289
289
|
// } else {
|
|
290
290
|
// if (logalot) { console.log(`${lc} space falsy, skipping persistence (I: 90aa3553e92ad1d02bce61f83648ea22)`); }
|
|
291
291
|
// }
|
|
@@ -295,7 +295,7 @@ export abstract class WitnessWithContextBase_V1<
|
|
|
295
295
|
await this.loadIbGibDto(newThisIbGib);
|
|
296
296
|
|
|
297
297
|
// (in the future, need to revisit the ibgibs service to the idea of locality/ies).
|
|
298
|
-
await
|
|
298
|
+
await metaspace.registerNewIbGib({ ibGib: newThisIbGib });
|
|
299
299
|
} catch (error) {
|
|
300
300
|
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
301
301
|
throw error;
|
|
@@ -321,9 +321,9 @@ export abstract class WitnessWithContextBase_V1<
|
|
|
321
321
|
try {
|
|
322
322
|
if (!ibGibToRel8 && !ibGibAddrToRel8) { throw new Error(`ibGibToRel8 or ibGibAddrToRel8 required (E: 3ee14659fd22355a5ba0e537a477be22)`); }
|
|
323
323
|
if (!contextIbGib) { throw new Error(`contextIbGib required (E: 85f27c7cbf713704c21084c141cd8822)`); }
|
|
324
|
-
if (!this.
|
|
324
|
+
if (!this.metaspace) { throw new Error(`this.metaspace required (E: 6a38c4274bdefc8d44cafd2d6faaa222)`); }
|
|
325
325
|
|
|
326
|
-
// space = space ?? await this.
|
|
326
|
+
// space = space ?? await this.metaspace.getLocalUserSpace({ lock: true });
|
|
327
327
|
// if (!space) { throw new Error(`space required (E: 267ad87c148942cda641349df0bbbd22)`); }
|
|
328
328
|
|
|
329
329
|
if ((rel8nNames ?? []).length === 0) {
|
|
@@ -346,11 +346,11 @@ export abstract class WitnessWithContextBase_V1<
|
|
|
346
346
|
});
|
|
347
347
|
|
|
348
348
|
// ...persist it...
|
|
349
|
-
await this.
|
|
349
|
+
await this.metaspace.persistTransformResult({ resTransform: resRel8ToContext });
|
|
350
350
|
|
|
351
351
|
// ...register the context.
|
|
352
352
|
const { newIbGib: newContext } = resRel8ToContext;
|
|
353
|
-
await this.
|
|
353
|
+
await this.metaspace.registerNewIbGib({ ibGib: newContext });
|
|
354
354
|
} catch (error) {
|
|
355
355
|
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
356
356
|
throw error;
|
|
@@ -365,27 +365,27 @@ export abstract class WitnessWithContextBase_V1<
|
|
|
365
365
|
text: string,
|
|
366
366
|
contextIbGib: IbGib_V1,
|
|
367
367
|
rel8nName: string,
|
|
368
|
-
|
|
368
|
+
metaspace?: MetaspaceService,
|
|
369
369
|
}): Promise<void> {
|
|
370
370
|
const lc = `${this.lc}[${this.createCommentAndRel8ToContextIbGib.name}]`;
|
|
371
371
|
try {
|
|
372
372
|
if (logalot) { console.log(`${lc} starting... (I: c3a005f7d323468a5b4e1b2710901d22)`); }
|
|
373
373
|
|
|
374
|
-
if (!this.
|
|
374
|
+
if (!this.metaspace) { throw new Error(`this.metaspace required (E: 5dbb1a7f0ff5469b8ce3cb1be175e521)`); }
|
|
375
375
|
|
|
376
|
-
// space = space ?? await this.
|
|
377
|
-
// if (!space) { throw new Error(`(UNEXPECTED) space required and wasn't able to get it from
|
|
378
|
-
let space = await this.
|
|
376
|
+
// space = space ?? await this.metaspace.getLocalUserSpace({ lock: true });
|
|
377
|
+
// if (!space) { throw new Error(`(UNEXPECTED) space required and wasn't able to get it from metaspace? (E: 7159f9893a66c28a7e09b61384545622)`); }
|
|
378
|
+
let space = await this.metaspace.getLocalUserSpace({ lock: true });
|
|
379
379
|
|
|
380
380
|
/** tag this comment with metadata to show it came from this witness */
|
|
381
381
|
let resComment = await createCommentIbGib({ text, addlMetadataText: this.getAddlMetadata(), saveInSpace: true, space });
|
|
382
382
|
|
|
383
383
|
// get again to be sure it's the latest space.
|
|
384
|
-
space = await this.
|
|
384
|
+
space = await this.metaspace.getLocalUserSpace({ lock: true });
|
|
385
385
|
|
|
386
386
|
const commentIbGib = resComment.newIbGib as CommentIbGib_V1;
|
|
387
387
|
if (!commentIbGib) { throw new Error(`(UNEXPECTED) failed to create comment? (E: 6d668f4e55198e654324622eabaac922)`); }
|
|
388
|
-
await this.
|
|
388
|
+
await this.metaspace.registerNewIbGib({ ibGib: commentIbGib });
|
|
389
389
|
|
|
390
390
|
await this.rel8ToContextIbGib({ ibGibToRel8: commentIbGib, contextIbGib, rel8nNames: ['comment'] });
|
|
391
391
|
await this.rel8To({
|
|
@@ -477,22 +477,22 @@ export abstract class WitnessWithContextBase_V1<
|
|
|
477
477
|
if (logalot) { console.log(`${lc} starting... (I: c13f7cb92133984048f606075efb8a22)`); }
|
|
478
478
|
let contextIbGib: IbGib_V1;
|
|
479
479
|
if (!arg && !addr) { throw new Error(`either arg or addr required. (E: 3f647b65742242fd9ba878521acf7c22)`); }
|
|
480
|
-
if (!this.
|
|
480
|
+
if (!this.metaspace) { throw new Error(`(UNEXPECTED) this.metaspace required (E: f0046290b0d66d28c4bbbf83d9d9f523)`); }
|
|
481
481
|
if (arg) {
|
|
482
482
|
if ((arg.ibGibs ?? []).length === 0) { throw new Error(`(UNEXPECTED) invalid arg? no context ibgib on arg (E: 89997eb4bdeb3885bee9de5d33ee0f22)`); }
|
|
483
483
|
if ((arg.ibGibs ?? []).length !== 1) { throw new Error(`(UNEXPECTED) invalid arg? only expected one ibgib on arg.ibGibs (E: 1a1498af668740fe9439f4953a74ea8a)`); }
|
|
484
484
|
contextIbGib = arg.ibGibs![0];
|
|
485
485
|
} else {
|
|
486
486
|
// addr provided
|
|
487
|
-
const resGet = await this.
|
|
487
|
+
const resGet = await this.metaspace.get({ addr });
|
|
488
488
|
if (!resGet.success || resGet.ibGibs?.length !== 1) { throw new Error(`could not get context addr (${addr}) (E: 834492313512a45b23a7bebacdc48122)`); }
|
|
489
489
|
contextIbGib = resGet.ibGibs[0];
|
|
490
490
|
}
|
|
491
491
|
|
|
492
492
|
if (latest) {
|
|
493
|
-
const resLatestAddr = await this.
|
|
493
|
+
const resLatestAddr = await this.metaspace.getLatestAddr({ ibGib: contextIbGib });
|
|
494
494
|
if (resLatestAddr !== getIbGibAddr({ ibGib: contextIbGib })) {
|
|
495
|
-
const resGet = await this.
|
|
495
|
+
const resGet = await this.metaspace.get({ addr: resLatestAddr });
|
|
496
496
|
if (resGet.success && resGet.ibGibs?.length === 1) {
|
|
497
497
|
contextIbGib = resGet.ibGibs[0];
|
|
498
498
|
} else {
|
|
@@ -513,7 +513,7 @@ export abstract class WitnessWithContextBase_V1<
|
|
|
513
513
|
* The context is the ibgib where we are interacting with the user(s).
|
|
514
514
|
*
|
|
515
515
|
* When we initialize, we are setting state on this witness as well as
|
|
516
|
-
* subscribing to the context ibgib's updates in `this.
|
|
516
|
+
* subscribing to the context ibgib's updates in `this.metaspace`.
|
|
517
517
|
*
|
|
518
518
|
* if we already have a context, then this will check the new incoming
|
|
519
519
|
* context against it. If it's the same timeline, then this won't do
|
|
@@ -553,7 +553,7 @@ export abstract class WitnessWithContextBase_V1<
|
|
|
553
553
|
const lc = `${this.lc}[${this.initializeContext.name}]`;
|
|
554
554
|
try {
|
|
555
555
|
if (logalot) { console.log(`${lc} starting... (I: d93429c85b0a494388f66fba3eece922)`); }
|
|
556
|
-
if (!this.
|
|
556
|
+
if (!this.metaspace) { throw new Error(`this.metaspace (metaspace) required. set this before using this witness. (E: 67db388a0223bf813b40accd9941ad23)`); }
|
|
557
557
|
if (arg && contextIbGib) {
|
|
558
558
|
console.warn(`${lc} both arg and contextIbGib provided. using raw contextIbGib (W: d6d723ad7fb942079833c40647aecd22)`);
|
|
559
559
|
}
|
|
@@ -593,10 +593,10 @@ export abstract class WitnessWithContextBase_V1<
|
|
|
593
593
|
|
|
594
594
|
// subscribe to context ibgib updates
|
|
595
595
|
const contextTjpAddr = getTjpAddr({ ibGib: this._currentWorkingContextIbGib });
|
|
596
|
-
if (!this.
|
|
597
|
-
if (!this.
|
|
596
|
+
if (!this.metaspace) { throw new Error(`(UNEXPECTED) this.metaspace falsy...not initialized? (E: 6e38bfdc5c2eb5fef884f0183889e823)`); }
|
|
597
|
+
if (!this.metaspace.latestObs) { throw new Error(`(UNEXPECTED) this.metaspace.latestObs falsy? (E: 831936570c14ed526f9c9ab511929923)`); }
|
|
598
598
|
this._contextChangesSubscription =
|
|
599
|
-
await this.
|
|
599
|
+
await this.metaspace.latestObs
|
|
600
600
|
// .pipe(
|
|
601
601
|
// filter(x => x.tjpAddr === contextTjpAddr)
|
|
602
602
|
// ).subscribe(async (update: any) => {
|
|
@@ -631,7 +631,7 @@ export abstract class WitnessWithContextBase_V1<
|
|
|
631
631
|
},
|
|
632
632
|
error: async (err) => {
|
|
633
633
|
const lcErr = `${lc}[latestObs.error]`;
|
|
634
|
-
console.error(`${lcErr} this.
|
|
634
|
+
console.error(`${lcErr} this.metaspace.latestObs error: ${extractObsErrMsg({ err })}. (E: 99df4c42195d46d0a9dbfb06ac45ae00)`)
|
|
635
635
|
},
|
|
636
636
|
}));
|
|
637
637
|
|
|
@@ -649,7 +649,7 @@ export abstract class WitnessWithContextBase_V1<
|
|
|
649
649
|
// if needed)
|
|
650
650
|
// let gibInfo = getGibInfo({ gib: this._currentWorkingContextIbGib.gib });
|
|
651
651
|
// if (gibInfo.tjpGib) {
|
|
652
|
-
// this.
|
|
652
|
+
// this.metaspace.latestObs
|
|
653
653
|
// .subscribe(update => {
|
|
654
654
|
// if (!update.tjpAddr) { return; /* <<<< returns early */ }
|
|
655
655
|
// if (getIbAndGib({ ibGibAddr: update.tjpAddr }).gib !== gibInfo.tjpGib) { return; /* <<<< returns early */ }
|
|
@@ -809,8 +809,8 @@ export abstract class WitnessWithContextBase_V1<
|
|
|
809
809
|
}
|
|
810
810
|
|
|
811
811
|
// get the latest addrs for those children
|
|
812
|
-
if (!this.
|
|
813
|
-
const space = await this.
|
|
812
|
+
if (!this.metaspace) { throw new Error(`this.metaspace falsy. not initialized? (E: 1cc26ca7de7fadcdbaecbd6613350e23)`); }
|
|
813
|
+
const space = await this.metaspace.getLocalUserSpace({});
|
|
814
814
|
if (!space) { throw new Error(`couldn't get local user space? (E: f118f75e5852fc22bba3a6495beec723)`); }
|
|
815
815
|
const resLatestAddrs = await getLatestAddrs({ addrs: newChildrenAddrs, space, });
|
|
816
816
|
const latestAddrs = Object.values(resLatestAddrs?.data?.latestAddrsMap ?? {});
|
|
@@ -821,7 +821,7 @@ export abstract class WitnessWithContextBase_V1<
|
|
|
821
821
|
// some of the addrs were not found in the space
|
|
822
822
|
throw new Error(`some addrs were not found in the space. (E: 2216d8e5ad7fb600ceb025ed7c90f323)`);
|
|
823
823
|
}
|
|
824
|
-
const resGet = await this.
|
|
824
|
+
const resGet = await this.metaspace.get({ addrs: latestAddrs as IbGibAddr[] });
|
|
825
825
|
if (!resGet.success || resGet.ibGibs?.length !== newChildrenAddrs.length) {
|
|
826
826
|
throw new Error(`failed to get newChildren with addrs: ${newChildrenAddrs.join('|')}. Error: ${resGet.errorMsg ?? 'unknown error 5737bd0996d5445b8bd80975bedc0d57'} (E: 05722e11350ec6ffffdb5c7d0caa2922)`);
|
|
827
827
|
}
|