@ibgib/core-gib 0.0.112 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/common/import-export/import-export-types.d.mts +8 -0
  2. package/dist/common/import-export/import-export-types.d.mts.map +1 -1
  3. package/dist/timeline/timeline-api.d.mts +297 -0
  4. package/dist/timeline/timeline-api.d.mts.map +1 -0
  5. package/dist/timeline/timeline-api.mjs +725 -0
  6. package/dist/timeline/timeline-api.mjs.map +1 -0
  7. package/dist/timeline/timeline-types.d.mts +42 -0
  8. package/dist/timeline/timeline-types.d.mts.map +1 -0
  9. package/dist/timeline/timeline-types.mjs +2 -0
  10. package/dist/timeline/timeline-types.mjs.map +1 -0
  11. package/dist/witness/space/filesystem-space/filesystem-space-v1.d.mts +0 -1
  12. package/dist/witness/space/filesystem-space/filesystem-space-v1.d.mts.map +1 -1
  13. package/dist/witness/space/filesystem-space/filesystem-space-v1.mjs +0 -3
  14. package/dist/witness/space/filesystem-space/filesystem-space-v1.mjs.map +1 -1
  15. package/dist/witness/space/inner-space/inner-space-constants.d.mts +2 -0
  16. package/dist/witness/space/inner-space/inner-space-constants.d.mts.map +1 -0
  17. package/dist/witness/space/inner-space/inner-space-constants.mjs +2 -0
  18. package/dist/witness/space/inner-space/inner-space-constants.mjs.map +1 -0
  19. package/dist/witness/space/inner-space/inner-space-types.d.mts +23 -0
  20. package/dist/witness/space/inner-space/inner-space-types.d.mts.map +1 -0
  21. package/dist/witness/space/inner-space/inner-space-types.mjs +32 -0
  22. package/dist/witness/space/inner-space/inner-space-types.mjs.map +1 -0
  23. package/dist/witness/space/inner-space/inner-space-v1.d.mts +13 -7
  24. package/dist/witness/space/inner-space/inner-space-v1.d.mts.map +1 -1
  25. package/dist/witness/space/inner-space/inner-space-v1.mjs +159 -8
  26. package/dist/witness/space/inner-space/inner-space-v1.mjs.map +1 -1
  27. package/dist/witness/space/inner-space/inner-space-v1.respec.mjs +206 -52
  28. package/dist/witness/space/inner-space/inner-space-v1.respec.mjs.map +1 -1
  29. package/dist/witness/space/metaspace/metaspace-base.d.mts.map +1 -1
  30. package/dist/witness/space/metaspace/metaspace-base.mjs +4 -2
  31. package/dist/witness/space/metaspace/metaspace-base.mjs.map +1 -1
  32. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace-helper.d.mts.map +1 -1
  33. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace-helper.mjs +28 -9
  34. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace-helper.mjs.map +1 -1
  35. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.d.mts.map +1 -1
  36. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.mjs +27 -3
  37. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.mjs.map +1 -1
  38. package/dist/witness/space/reconciliation-space/reconciliation-space-base.d.mts +100 -0
  39. package/dist/witness/space/reconciliation-space/reconciliation-space-base.d.mts.map +1 -0
  40. package/dist/witness/space/reconciliation-space/reconciliation-space-base.mjs +758 -0
  41. package/dist/witness/space/reconciliation-space/reconciliation-space-base.mjs.map +1 -0
  42. package/dist/witness/space/reconciliation-space/reconciliation-space-helper.d.mts +40 -0
  43. package/dist/witness/space/reconciliation-space/reconciliation-space-helper.d.mts.map +1 -0
  44. package/dist/witness/space/reconciliation-space/reconciliation-space-helper.mjs +90 -0
  45. package/dist/witness/space/reconciliation-space/reconciliation-space-helper.mjs.map +1 -0
  46. package/dist/witness/space/space-helper.d.mts.map +1 -1
  47. package/dist/witness/space/space-helper.mjs +11 -2
  48. package/dist/witness/space/space-helper.mjs.map +1 -1
  49. package/dist/witness/space/space-respec-helper.d.mts.map +1 -1
  50. package/dist/witness/space/space-respec-helper.mjs +3 -0
  51. package/dist/witness/space/space-respec-helper.mjs.map +1 -1
  52. package/package.json +1 -1
  53. package/src/common/import-export/import-export-types.mts +8 -0
  54. package/src/timeline/timeline-api.mts +943 -0
  55. package/src/timeline/timeline-types.mts +38 -0
  56. package/src/witness/space/filesystem-space/filesystem-space-v1.mts +0 -3
  57. package/src/witness/space/inner-space/inner-space-constants.mts +1 -0
  58. package/src/witness/space/inner-space/inner-space-types.mts +44 -0
  59. package/src/witness/space/inner-space/inner-space-v1.mts +157 -28
  60. package/src/witness/space/inner-space/inner-space-v1.respec.mts +242 -58
  61. package/src/witness/space/metaspace/metaspace-base.mts +7 -1
  62. package/src/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace-helper.mts +32 -10
  63. package/src/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.mts +76 -53
  64. package/src/witness/space/reconciliation-space/reconciliation-space-base.mts +884 -0
  65. package/src/witness/space/reconciliation-space/reconciliation-space-helper.mts +125 -0
  66. package/src/witness/space/space-helper.mts +6 -2
  67. package/src/witness/space/space-respec-helper.mts +4 -4
@@ -0,0 +1,38 @@
1
+ import { IbGibAddr } from "@ibgib/ts-gib/dist/types.mjs";
2
+ import { IbGib_V1 } from "@ibgib/ts-gib/dist/V1/types.mjs";
3
+
4
+ /**
5
+ * A history information record that gives access to a given timeline.
6
+ *
7
+ * ## NOTE on timeline, "latest", out-of-date, etc.
8
+ *
9
+ * Unless the timeline is locked, this timeline info could be out-of-date at any
10
+ * moment.
11
+ *
12
+ * If this timeline info was built using the latest ibgib in a given space, then
13
+ * this will be current (not out-of-date). The {@link headIbGib} will be the latest ibgib
14
+ * in the timeline, and it the past will be complete.
15
+ *
16
+ * If the timeline was not built using the latest ibgib in the space, then this
17
+ * timeline info will be built according to the ibgib it was given at the time
18
+ * and will be correct relative to that ibgib as the {@link headIbGib}.
19
+ */
20
+ export interface TimelineHistoryInfo {
21
+ /**
22
+ * The "latest" ibgib in the given timeline, BUT ONLY PER CONTEXT.
23
+ */
24
+ headIbGib: IbGib_V1;
25
+ /**
26
+ * Fully loaded ibGibs for a timeline.
27
+ */
28
+ orderedPastIbGibs: IbGib_V1[];
29
+ /**
30
+ * Same as {@link orderedPastIbGibs}, but mapped out by their ibGibAddr -> ibGib.
31
+ */
32
+ pastIbGibMap: { [addr: IbGibAddr]: IbGib_V1 };
33
+ /**
34
+ * If provided, this is a map of a dnaIbGibAddr -> dnaIbGib. This is to be
35
+ * used in combination with a given ibGib.rel8ns.dna addrs.
36
+ */
37
+ dnaMap?: { [addr: IbGibAddr]: IbGib_V1 };
38
+ }
@@ -1603,7 +1603,4 @@ export abstract class FilesystemSpace_V1<
1603
1603
  }
1604
1604
 
1605
1605
  // #endregion other helpers
1606
-
1607
- private foo(): void {
1608
- }
1609
1606
  }
@@ -0,0 +1 @@
1
+ export const DEFAULT_INNER_SPACE_DESCRIPTION = `This is an in-memory innerspace.`;
@@ -0,0 +1,44 @@
1
+ import { ReconciliationSpaceData, ReconciliationSpaceRel8ns } from "../reconciliation-space/reconciliation-space-base.mjs";
2
+ import { DEFAULT_LOCAL_SPACE_POLLING_INTERVAL_MS, IBGIB_SPACE_NAME_DEFAULT, ZERO_SPACE_ID } from "../space-constants.mjs";
3
+ import { DEFAULT_INNER_SPACE_DESCRIPTION } from "./inner-space-constants.mjs";
4
+
5
+ export interface InnerSpaceData_V1 extends ReconciliationSpaceData {
6
+ // /**
7
+ // * If true, then this will include this space's ibGib's addrs (i.e. index)
8
+ // * in its {@link data} property.
9
+ // */
10
+ // trackAddrs: boolean;
11
+ }
12
+
13
+ /**
14
+ * Used in bootstrapping.
15
+ *
16
+ * If you change this, please bump the version
17
+ *
18
+ * (but of course won't be the end of the world when this doesn't happen).
19
+ *
20
+ * ## notes
21
+ *
22
+ * This is a terrible kluge port from NodeFilesystemSpaceData_V1. I am just
23
+ * moving "as fast as I can" (I can't move fast these days). Little of the
24
+ * filesystem internal details reallly matter I think, as this is just meant to
25
+ * be a local space living on indexeddb. The main thing is segregation of local
26
+ * spaces from each other, but I think this is covered to begin with via the
27
+ * space name used in the path somewhere.
28
+ */
29
+ export const DEFAULT_INNER_SPACE_DATA_V1: InnerSpaceData_V1 = {
30
+ version: '1',
31
+ uuid: ZERO_SPACE_ID,
32
+ name: IBGIB_SPACE_NAME_DEFAULT,
33
+ classname: 'InnerSpace_V1',
34
+ persistOptsAndResultIbGibs: false,
35
+ validateIbGibAddrsMatchIbGibs: false,
36
+ longPollingIntervalMs: DEFAULT_LOCAL_SPACE_POLLING_INTERVAL_MS,
37
+ allowPrimitiveArgs: false,
38
+ catchAllErrors: true,
39
+ description: DEFAULT_INNER_SPACE_DESCRIPTION,
40
+ trace: false,
41
+ }
42
+
43
+ export interface InnerSpaceRel8ns_V1 extends ReconciliationSpaceRel8ns {
44
+ }
@@ -1,31 +1,22 @@
1
+ import { clone, extractErrorMsg, groupBy, pretty } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
1
2
  import { IbGibAddr } from '@ibgib/ts-gib/dist/types.mjs';
2
3
  import { getIbGibAddr, } from '@ibgib/ts-gib/dist/helper.mjs';
3
- import {
4
- IbGib_V1, IbGibRel8ns_V1, IbGibData_V1, sha256v1, Factory_V1, ROOT, getGib,
5
- } from '@ibgib/ts-gib/dist/V1/index.mjs';
4
+ import { IbGib_V1, getGib, } from '@ibgib/ts-gib/dist/V1/index.mjs';
6
5
  import { validateIbGibIntrinsically } from '@ibgib/ts-gib/dist/V1/validate-helper.mjs';
7
6
 
8
- import { SpaceBase_V1 } from '../space-base-v1.mjs';
7
+ import { GLOBAL_LOG_A_LOT } from '../../../core-constants.mjs';
9
8
  import {
10
9
  IbGibSpaceData, IbGibSpaceOptionsData, IbGibSpaceOptionsRel8ns,
11
10
  IbGibSpaceOptionsIbGib, IbGibSpaceResultData, IbGibSpaceResultRel8ns,
12
- IbGibSpaceResultIbGib,
13
- IbGibSpaceRel8ns
11
+ IbGibSpaceResultIbGib, IbGibSpaceRel8ns,
14
12
  } from '../space-types.mjs';
15
- import { getSpaceIb } from '../space-helper.mjs';
16
- import { GLOBAL_LOG_A_LOT } from '../../../core-constants.mjs';
13
+ import { getSpaceIb, } from '../space-helper.mjs';
14
+ import { getTjpAddr } from '../../../common/other/ibgib-helper.mjs';
15
+ import { ReconciliationSpaceBase, ReconciliationSpaceData, ReconciliationSpaceRel8ns } from '../reconciliation-space/reconciliation-space-base.mjs';
16
+ import { DEFAULT_INNER_SPACE_DATA_V1, InnerSpaceData_V1, InnerSpaceRel8ns_V1 } from './inner-space-types.mjs';
17
17
 
18
18
  const logalot = GLOBAL_LOG_A_LOT;
19
19
 
20
- export interface InnerSpace_V1_Data extends IbGibSpaceData {
21
- // /**
22
- // * If true, then this will include this space's ibGib's addrs (i.e. index)
23
- // * in its {@link data} property.
24
- // */
25
- // trackAddrs: boolean;
26
- }
27
- export interface InnerSpace_V1_Rel8ns extends IbGibSpaceRel8ns {
28
- }
29
20
 
30
21
  /**
31
22
  * Base class convenience for a "local" space
@@ -36,19 +27,18 @@ export interface InnerSpace_V1_Rel8ns extends IbGibSpaceRel8ns {
36
27
  */
37
28
  export class InnerSpace_V1<
38
29
  TIbGib extends IbGib_V1 = IbGib_V1,
39
- TData extends InnerSpace_V1_Data = InnerSpace_V1_Data,
40
- TRel8ns extends InnerSpace_V1_Rel8ns = InnerSpace_V1_Rel8ns
41
- > extends SpaceBase_V1<
30
+ TData extends InnerSpaceData_V1 = InnerSpaceData_V1,
31
+ TRel8ns extends InnerSpaceRel8ns_V1 = InnerSpaceRel8ns_V1
32
+ > extends ReconciliationSpaceBase<
42
33
  TIbGib,
34
+ TData,
35
+ TRel8ns,
43
36
  IbGibSpaceOptionsData,
44
37
  IbGibSpaceOptionsRel8ns,
45
38
  IbGibSpaceOptionsIbGib<TIbGib, IbGibSpaceOptionsData, IbGibSpaceOptionsRel8ns>,
46
39
  IbGibSpaceResultData,
47
40
  IbGibSpaceResultRel8ns,
48
- IbGibSpaceResultIbGib<TIbGib, IbGibSpaceResultData, IbGibSpaceResultRel8ns>,
49
- TData,
50
- TRel8ns
51
- > {
41
+ IbGibSpaceResultIbGib<TIbGib, IbGibSpaceResultData, IbGibSpaceResultRel8ns>> {
52
42
 
53
43
  /**
54
44
  * Log context for convenience with logging. (Ignore if you don't want to use this.)
@@ -75,11 +65,28 @@ export class InnerSpace_V1<
75
65
  protected async initialize(): Promise<void> {
76
66
  const lc = `${this.lc}[${this.initialize.name}]`;
77
67
  try {
68
+ // if (logalot) { console.log(`${lc} starting...`); }
69
+ // await super.initialize();
70
+ // if (!this.data) { throw new Error(`(UNEXPECTED) this.data is falsy? (E: 6461b2e4c9877053689dbc8bb375a623)`); }
71
+ // if (!this.data?.classname) { this.data!.classname = InnerSpace_V1.name }
72
+ // this.ib = getSpaceIb({ space: this });
73
+ // this.gib = await getGib({ ibGib: this });
74
+
78
75
  if (logalot) { console.log(`${lc} starting...`); }
79
- await super.initialize();
80
- if (!this.data) { throw new Error(`(UNEXPECTED) this.data is falsy? (E: 6461b2e4c9877053689dbc8bb375a623)`); }
81
- if (!this.data?.classname) { this.data!.classname = InnerSpace_V1.name }
82
- this.ib = getSpaceIb({ space: this });
76
+ if (!this.data) {
77
+ this.data = clone(DEFAULT_INNER_SPACE_DATA_V1);
78
+ this.data = this.data!; // why does ts compiler need this?
79
+ }
80
+ if (this.data!.classname !== InnerSpace_V1.name) {
81
+ if (this.data.classname) {
82
+ // only warn if the consumer has explicitly set a different classname
83
+ console.warn(`${lc} this.data.classname (${this.data.classname}) !== ${InnerSpace_V1.name}. overriding this. (W: 4cac18140e58f0bd2890010a3639d225)`);
84
+ }
85
+ this.data!.classname = InnerSpace_V1.name; // always set?
86
+ }
87
+ if (!this.data.uuid) { throw new Error(`this.data.uuid is falsy. right now i'm assuming data.uuid is truthy. this is what i'm using atow (12/2024) (E: e531e3c812c22324e856cf219e337825)`); }
88
+
89
+ this.ib = getSpaceIb({ space: this, classname: this.data!.classname });
83
90
  this.gib = await getGib({ ibGib: this });
84
91
  } catch (error) {
85
92
  console.error(`${lc} ${error.message}`);
@@ -89,6 +96,61 @@ export class InnerSpace_V1<
89
96
  }
90
97
  }
91
98
 
99
+ protected async _getLatestAddrsInStore(ibGibs: TIbGib[]): Promise<{ [addr: string]: IbGibAddr | null; }> {
100
+ const lc = `${this.lc}[_getLatestAddrsInStore]`;
101
+ try {
102
+ if (logalot) { console.log(`${lc} starting...`); }
103
+ const ibGibAddrs = ibGibs.map(x => getIbGibAddr({ ibGib: x }));
104
+ const arg = { data: { ibGibAddrs } } as IbGibSpaceOptionsIbGib;
105
+ const resGet = await this.getLatestAddrsImpl(arg as any);
106
+ return resGet.data!.latestAddrsMap!;
107
+ } catch (error) {
108
+ console.error(`${lc} ${extractErrorMsg(error)}`);
109
+ throw error;
110
+ }
111
+ }
112
+
113
+ protected async _getIbGibsFromStore(addrs: IbGibAddr[]): Promise<{ [addr: string]: TIbGib; }> {
114
+ const lc = `${this.lc}[_getIbGibsFromStore]`;
115
+ try {
116
+ if (logalot) { console.log(`${lc} starting...`); }
117
+ const res: { [addr: string]: TIbGib } = {};
118
+ for (const addr of addrs) {
119
+ if (this.ibGibs[addr]) {
120
+ res[addr] = this.ibGibs[addr];
121
+ }
122
+ }
123
+ return res;
124
+ } catch (error) {
125
+ console.error(`${lc} ${extractErrorMsg(error)}`);
126
+ throw error;
127
+ }
128
+ }
129
+
130
+ protected async _putIbGibsToStore(ibGibs: TIbGib[]): Promise<void> {
131
+ const lc = `${this.lc}[_putIbGibsToStore]`;
132
+ try {
133
+ if (logalot) { console.log(`${lc} starting...`); }
134
+ await this.putIbGibsImpl({ ibGibs, addrsAlreadyHave: [] });
135
+ } catch (error) {
136
+ console.error(`${lc} ${extractErrorMsg(error)}`);
137
+ throw error;
138
+ }
139
+ }
140
+
141
+ protected async _deleteIbGibsFromStore(addrs: IbGibAddr[]): Promise<void> {
142
+ const lc = `${this.lc}[_deleteIbGibsFromStore]`;
143
+ try {
144
+ if (logalot) { console.log(`${lc} starting...`); }
145
+ for (const addr of addrs) {
146
+ delete this.ibGibs[addr];
147
+ }
148
+ } catch (error) {
149
+ console.error(`${lc} ${extractErrorMsg(error)}`);
150
+ throw error;
151
+ }
152
+ }
153
+
92
154
  protected async getImpl(arg: IbGibSpaceOptionsIbGib<TIbGib, IbGibSpaceOptionsData, IbGibSpaceOptionsRel8ns>):
93
155
  Promise<IbGibSpaceResultIbGib<TIbGib, IbGibSpaceResultData, IbGibSpaceResultRel8ns>> {
94
156
  const lc = `${this.lc}[${this.getImpl.name}]`;
@@ -229,6 +291,73 @@ export class InnerSpace_V1<
229
291
  const result = await this.resulty({ resultData });
230
292
  return result;
231
293
  }
294
+ protected async getLatestAddrsImpl(arg: IbGibSpaceOptionsIbGib<TIbGib, IbGibSpaceOptionsData, IbGibSpaceOptionsRel8ns>): Promise<IbGibSpaceResultIbGib<TIbGib, IbGibSpaceResultData, IbGibSpaceResultRel8ns>> {
295
+ const lc = `${this.lc}[${this.getLatestAddrsImpl.name}]`;
296
+ if (logalot) { console.log(`${lc} starting... (I: 913548fe045270432ea96f2a59ca6625)`); }
297
+ const resultData: IbGibSpaceResultData = { optsAddr: getIbGibAddr({ ibGib: arg }), }
298
+ try {
299
+ if (!arg.data) { throw new Error(`(UNEXPECTED) !arg.data? (E: 60869288f3deeff5d1dd93be5f4b8624)`); }
300
+ if (!arg.data.ibGibAddrs) { throw new Error(`(UNEXPECTED) !arg.data.ibGibAddrs? (E: d62cfac462daacc5b2f50c7c3ae45d24)`); }
301
+
302
+ // get all ibgibs in the space and group them by their tjp address
303
+ const ibGibsInSpace = Object.values(this.ibGibs);
304
+ const ibGibsInSpaceByTjp = groupBy({ items: ibGibsInSpace, keyFn: x => getTjpAddr({ ibGib: x })! });
305
+
306
+ if (logalot) { console.log(`${lc} ibGibsInSpaceByTjp: ${pretty(ibGibsInSpaceByTjp)} (I: af9f88985b96822b68ad4928eb6f6a25)`); }
307
+
308
+ const latestAddrsMap: { [addr: string]: IbGibAddr | null } = {};
309
+
310
+ // iterate over each address we're looking for
311
+ for (const localAddr of arg.data.ibGibAddrs) {
312
+ const localIbGib = this.ibGibs[localAddr];
313
+ if (!localIbGib) {
314
+ latestAddrsMap[localAddr] = null; // or handle as error/not found
315
+ continue;
316
+ }
317
+
318
+ const tjpAddr = getTjpAddr({ ibGib: localIbGib });
319
+ if (tjpAddr && ibGibsInSpaceByTjp[tjpAddr]) {
320
+ // if we have a timeline for this tjp, find the latest
321
+ const timeline = ibGibsInSpaceByTjp[tjpAddr];
322
+
323
+ if (timeline.some(ibGib => ibGib.data?.n === undefined)) {
324
+ console.warn(`${lc} timeline includes ibgibs with ibGib.data?.n === undefined (W: 7360a8e81b05accf244fb4b86e796325)`);
325
+ }
326
+ // sort mutates array in place
327
+ timeline.sort((a, b) => (a.data?.n ?? -1) > (b.data?.n ?? -1) ? 1 : -1); // sorts ascending, e.g., 0,1,2...[Highest]
328
+
329
+ // last one is the latest
330
+ let latestInTimeline = timeline.at(-1);
331
+ if (latestInTimeline) {
332
+ latestAddrsMap[localAddr] = getIbGibAddr({ ibGib: latestInTimeline });
333
+ } else {
334
+ latestAddrsMap[localAddr] = null;
335
+ }
336
+ } else {
337
+ // if it has no tjp, it is its own latest if it exists
338
+ latestAddrsMap[localAddr] = this.ibGibs[localAddr] ? localAddr : null;
339
+ }
340
+ }
341
+
342
+ resultData.latestAddrsMap = latestAddrsMap;
343
+ resultData.success = true;
344
+
345
+ } catch (error) {
346
+ const emsg = `${lc} ${extractErrorMsg(error)}`;
347
+ console.error(emsg);
348
+ resultData.errors = [emsg];
349
+ }
350
+
351
+ try {
352
+ let result = await this.resulty({ resultData });
353
+ return result;
354
+ } catch (error) {
355
+ console.error(`${lc}[resulty] ${extractErrorMsg(error)}`);
356
+ throw error;
357
+ } finally {
358
+ if (logalot) { console.log(`${lc} complete. (I: 913548fe045270432ea96f2a59ca6625)`); }
359
+ }
360
+ }
232
361
  /**
233
362
  * Performs a naive `exists: boolean` or `includes: boolean` analog.
234
363
  *
@@ -1,69 +1,253 @@
1
- import { getUUID, } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
1
+ import { extractErrorMsg, getUUID, pretty, } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
2
2
  import {
3
- firstOfEach, firstOfAll, ifWe,
4
- lastOfEach, lastOfAll,
5
- ifWeMight, iReckon, respecfully
3
+ ifWe, ifWeMight, iReckon,
4
+ respecfully, respecfullyDear,
6
5
  } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
7
6
  const maam = `[${import.meta.url}]`, sir = maam;
7
+ import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
8
+ // import { IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
9
+
10
+ import { getTjpAddr } from '../../../common/other/ibgib-helper.mjs';
11
+ // import { SyncSpaceOptionsIbGib } from '../outer-space/outer-space-types.mjs';
8
12
 
9
13
  import {
10
14
  testSpace_createAndInit,
11
15
  testSpace_persistTransformResult,
12
- testSpace_putGetDelete
16
+ testSpace_putGetDelete,
17
+ testSpace_registerNewIbGib_GetLatest,
13
18
  } from '../space-respec-helper.mjs';
14
- import { InnerSpace_V1, } from './inner-space-v1.mjs';
15
-
16
- await respecfully(sir, `[${InnerSpace_V1.name} specs]`, async () => {
17
-
18
- await testSpace_createAndInit({
19
- respecfulTitle: sir,
20
- // shortcircuitRespec: true,
21
- fnGetInitialSpaceData: async () => {
22
- return {
23
- name: (await getUUID()).substring(0, 8),
24
- uuid: await getUUID(),
25
- };
26
- },
27
- fnGetInitialSpaceRel8ns: () => {
28
- return Promise.resolve(undefined);
29
- },
30
- fnGetSpace: (initialData: any, initialRel8ns) => {
31
- return Promise.resolve(new InnerSpace_V1(initialData, initialRel8ns));
32
- },
33
- })
34
-
35
- await testSpace_putGetDelete({
36
- respecfulTitle: sir,
37
- // shortcircuitRespec: true,
38
- fnGetInitialSpaceData: async () => {
39
- return {
40
- name: (await getUUID()).substring(0, 8),
41
- uuid: await getUUID(),
42
- };
43
- },
44
- fnGetInitialSpaceRel8ns: () => {
45
- return Promise.resolve(undefined);
46
- },
47
- fnGetSpace: (initialData: any, initialRel8ns) => {
48
- return Promise.resolve(new InnerSpace_V1(initialData, initialRel8ns));
49
- },
50
- });
19
+ import { InnerSpace_V1, } from './inner-space-v1.mjs';
20
+ import { createTimeline, getHistory, mut8Timeline } from '../../../timeline/timeline-api.mjs';
21
+ import { MetaspaceService } from '../metaspace/metaspace-types.mjs';
22
+ import { Metaspace_Innerspace } from '../metaspace/metaspace-innerspace/metaspace-innerspace.mjs';
23
+ // import { getLatestAddrs, putInSpace } from '../space-helper.mjs';
51
24
 
52
- await testSpace_persistTransformResult({
53
- respecfulTitle: sir,
54
- // shortcircuitRespec: true,
55
- fnGetInitialSpaceData: async () => {
56
- return {
57
- name: (await getUUID()).substring(0, 8),
58
- uuid: await getUUID(),
59
- };
60
- },
61
- fnGetInitialSpaceRel8ns: () => {
62
- return Promise.resolve(undefined);
63
- },
64
- fnGetSpace: (initialData: any, initialRel8ns) => {
65
- return Promise.resolve(new InnerSpace_V1(initialData, initialRel8ns));
66
- },
67
- });
25
+ // ifWeMight() // don't remove this line while we're actively testing on this file. it is a limitation of my shortcut discovery script that it looks for a regex that matches ifWeMight/respecfullyDear followed by an open paren
26
+
27
+ const logalot = true;
28
+ /**
29
+ * not sure where to put this, but we probably will want to reuse this in the
30
+ * future (assuming it works)
31
+ * @returns metaspace service reference
32
+ */
33
+ async function getNewInitializedInMemoryMetaspaceForTesting({
34
+ defaultSpaceName,
35
+ }: {
36
+ defaultSpaceName: string,
37
+ }): Promise<MetaspaceService> {
38
+ const lc = `[${getNewInitializedInMemoryMetaspaceForTesting.name}]`;
39
+ try {
40
+ if (logalot) { console.log(`${lc} starting... (I: 766d7596addcb73f4820586469233b25)`); }
41
+
42
+ let metaspace = new Metaspace_Innerspace(/*cacheSvc*/undefined);
43
+ if (logalot) { console.log(`${lc} creating metaspace complete. initializing... (I: 61b74d62e8832c9fa853e4b8c4c2d825)`); }
44
+
45
+ await metaspace.initialize({
46
+ spaceName: defaultSpaceName,
47
+ metaspaceFactory: undefined,
48
+ getFnAlert: () => { return async ({ title, msg }) => console.log(title, msg) },
49
+ getFnPrompt: () => {
50
+ return async ({ title, msg }) => {
51
+ // if this is needed, we might set up some way for testing
52
+ // to prepare either a queue of prompts or some kind of map
53
+ // and put it on the metaspace itself
54
+ throw new Error(`not implemented (E: c7ef688a02f8cb74487260f9274ac825)`);
55
+ // promptForText({ title, msg, confirm: false });
56
+ }
57
+ },
58
+ getFnPromptPassword: () => {
59
+ return async () => {
60
+ return 'password';
61
+ // promptForSecret({ confirm: true })
62
+ }
63
+ },
64
+ });
65
+ return metaspace;
66
+ } catch (error) {
67
+ console.error(`${lc} ${extractErrorMsg(error)}`);
68
+ throw error;
69
+ } finally {
70
+ if (logalot) { console.log(`${lc} complete.`); }
71
+ }
72
+ }
73
+
74
+ await respecfullyDear(sir, 'metaspace setup itself', async () => {
75
+ await ifWeMight(sir, 'should init a metaspace', async () => {
76
+ const testSpaceName = 'TestSpaceName';
77
+
78
+ const metaspace = await getNewInitializedInMemoryMetaspaceForTesting({
79
+ defaultSpaceName: testSpaceName
80
+ });
68
81
 
82
+ iReckon(sir, metaspace.zeroSpace).asTo('metaspace should have a zero space').isGonnaBeTruthy();
83
+ });
69
84
  });
85
+
86
+ // await respecfullyDear(sir, `[${InnerSpace_V1.name} specs]`, async () => {
87
+
88
+ // await testSpace_createAndInit({
89
+ // respecfulTitle: sir,
90
+ // // shortcircuitRespec: true,
91
+ // fnGetInitialSpaceData: async () => {
92
+ // return {
93
+ // name: (await getUUID()).substring(0, 8),
94
+ // uuid: await getUUID(),
95
+ // };
96
+ // },
97
+ // fnGetInitialSpaceRel8ns: () => {
98
+ // return Promise.resolve(undefined);
99
+ // },
100
+ // fnGetSpace: (initialData: any, initialRel8ns) => {
101
+ // return Promise.resolve(new InnerSpace_V1(initialData, initialRel8ns));
102
+ // },
103
+ // })
104
+
105
+ // await testSpace_putGetDelete({
106
+ // respecfulTitle: sir,
107
+ // // shortcircuitRespec: true,
108
+ // fnGetInitialSpaceData: async () => {
109
+ // return {
110
+ // name: (await getUUID()).substring(0, 8),
111
+ // uuid: await getUUID(),
112
+ // };
113
+ // },
114
+ // fnGetInitialSpaceRel8ns: () => {
115
+ // return Promise.resolve(undefined);
116
+ // },
117
+ // fnGetSpace: (initialData: any, initialRel8ns) => {
118
+ // return Promise.resolve(new InnerSpace_V1(initialData, initialRel8ns));
119
+ // },
120
+ // });
121
+
122
+ // await testSpace_persistTransformResult({
123
+ // respecfulTitle: sir,
124
+ // // shortcircuitRespec: true,
125
+ // fnGetInitialSpaceData: async () => {
126
+ // return {
127
+ // name: (await getUUID()).substring(0, 8),
128
+ // uuid: await getUUID(),
129
+ // };
130
+ // },
131
+ // fnGetInitialSpaceRel8ns: () => {
132
+ // return Promise.resolve(undefined);
133
+ // },
134
+ // fnGetSpace: (initialData: any, initialRel8ns) => {
135
+ // return Promise.resolve(new InnerSpace_V1(initialData, initialRel8ns));
136
+ // },
137
+ // });
138
+
139
+ // await testSpace_registerNewIbGib_GetLatest({
140
+ // respecfulTitle: sir,
141
+ // // shortcircuitRespec: true,
142
+ // fnGetInitialSpaceData: async () => {
143
+ // return {
144
+ // name: (await getUUID()).substring(0, 8),
145
+ // uuid: await getUUID(),
146
+ // };
147
+ // },
148
+ // fnGetInitialSpaceRel8ns: () => {
149
+ // return Promise.resolve(undefined);
150
+ // },
151
+ // fnGetSpace: (initialData: any, initialRel8ns) => {
152
+ // return Promise.resolve(new InnerSpace_V1(initialData, initialRel8ns));
153
+ // },
154
+ // testLatestIterations: 5,
155
+ // });
156
+
157
+ // });
158
+
159
+
160
+
161
+ // await respecfully(sir, 'reconciliation', async () => {
162
+ // const createSpace = async (name: string): Promise<InnerSpace_V1> => {
163
+ // const spaceData: InnerSpaceData_V1 = {
164
+ // name,
165
+ // classname: InnerSpace_V1.name,
166
+ // uuid: await getUUID(),
167
+ // };
168
+ // const space = new InnerSpace_V1(spaceData);
169
+ // await space.initialized;
170
+ // return space;
171
+ // };
172
+
173
+ // const testSpaceName = 'TestSpaceName';
174
+
175
+ // // common setup for reconciliation tests
176
+ // const metaspace: MetaspaceService = await getNewInitializedInMemoryMetaspaceForTesting({
177
+ // defaultSpaceName: testSpaceName
178
+ // });
179
+ // // const metaspace = new Metaspace_V1();
180
+ // // await metaspace.initialize();
181
+
182
+ // await ifWe(sir, 'should sync a new timeline to an empty destination space', async () => {
183
+ // // ARRANGE
184
+ // const local_space = await createSpace('local');
185
+ // const outer_space = await createSpace('outer');
186
+
187
+ // // Create a timeline in local_space using the new timeline-api
188
+ // const { newIbGib: timelineV1 } = await createTimeline({
189
+ // parentIb: 'test',
190
+ // ib: 'my test timeline',
191
+ // data: { foo: 'bar' },
192
+ // metaspace,
193
+ // space: local_space,
194
+ // });
195
+
196
+ // const timelineV2 = await mut8Timeline({
197
+ // timeline: timelineV1,
198
+ // mut8Opts: { dataToAddOrPatch: { foo: 'rab' } },
199
+ // metaspace,
200
+ // space: local_space,
201
+ // });
202
+
203
+ // // Get history for sync
204
+ // const historyInfo = await getHistory({
205
+ // timeline: timelineV2,
206
+ // includeDna: true,
207
+ // metaspace,
208
+ // space: local_space,
209
+ // });
210
+
211
+ // const timelineIbGibs = [
212
+ // ...(Object.values(historyInfo.dnaMap ?? {})),
213
+ // ...historyInfo.orderedPastIbGibs,
214
+ // historyInfo.headIbGib,
215
+ // ];
216
+ // const timelineAddrs = timelineIbGibs.map(x => getIbGibAddr({ ibGib: x }));
217
+ // const tjpAddr = getTjpAddr({ ibGib: timelineV1 });
218
+
219
+ // // ensure outer_space is empty // there is no such functionality
220
+ // // const resGetAddrsOuterBefore = await outer_space.getAddrs({});
221
+ // // iReckon(sir, 'outer space should be empty initially', resGetAddrsOuterBefore.data.addrs.length, 0);
222
+
223
+ // // ACT
224
+ // // const syncOpts: SyncSpaceOptionsIbGib = {
225
+ // // ib: 'sync opts',
226
+ // // gib: 'sync_opts_gib',
227
+ // // data: {
228
+ // // cmdModifiers: ['sync'],
229
+ // // ibGibAddrs: timelineAddrs,
230
+ // // },
231
+ // // ibGibs: timelineIbGibs,
232
+ // // } as any;
233
+
234
+ // // // metaspace.syncIbGibs
235
+ // // putInSpace({})
236
+ // // const resSync = await outer_space.put(syncOpts);
237
+
238
+ // // ASSERT
239
+ // // iReckon(sir, `sync result success should be true. res: ${pretty(resSync)}`, resSync.data.success, true);
240
+ // // iReckon(sir, resSync?.data?.success).asTo(`sync result success`).isGonnaBeTrue();
241
+
242
+ // // const resGetAddrsOuterAfter = await outer_space.getAddrs({});
243
+ // // iReckon(sir, 'outer space should have all timeline ibgibs after sync', resGetAddrsOuterAfter.data.addrs.length, timelineAddrs.length);
244
+
245
+ // // const resGetLatest = await outer_space.getLatestAddrs({ data: { ibGibAddrs: [tjpAddr] } } as any);
246
+ // // const resGetLatest = getLatestAddrs({
247
+ // // tjpAddrs: tjpAddrs,
248
+ // // space: outer_space,
249
+ // // });
250
+ // // iReckon(sir, 'latest addr in outer space should match latest from local', resGetLatest.data.latestAddrsMap[tjpAddr], getIbGibAddr({ ibGib: timelineV2 }));
251
+ // });
252
+
253
+ // });
@@ -3496,7 +3496,13 @@ export abstract class MetaspaceBase implements MetaspaceService {
3496
3496
  try {
3497
3497
  if (logalot) { console.log(`${lc} starting...`); }
3498
3498
  const autosyncsIbGib = await this.getSpecialIbGib({ type: "autosyncs" });
3499
- if (!autosyncsIbGib?.rel8ns) { throw new Error(`autosyncsIbGib?.rel8ns falsy (E: 3fdcdf40f33c41ed9b7a01a079a8fd71)`); }
3499
+ if (!autosyncsIbGib) {
3500
+ console.warn(`${lc} autosyncsIbGib ("autosyncs") special ibgib not found not found. maybe fine, no idea. (W: 30ad2df15b38999106883358722fd425)`);
3501
+ return; /* <<<< returns early */
3502
+ }
3503
+
3504
+ // if (!autosyncsIbGib?.rel8ns) { throw new Error(`autosyncsIbGib?.rel8ns falsy (E: 3fdcdf40f33c41ed9b7a01a079a8fd71)`); }
3505
+
3500
3506
  if (autosyncsIbGib.rel8ns) {
3501
3507
  this._alwaysAutosyncTjpAddrsCache =
3502
3508
  new Set(autosyncsIbGib.rel8ns[AUTOSYNC_ALWAYS_REL8N_NAME]);