@ibgib/core-gib 0.1.11 → 0.1.13

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 (36) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/sync/sync-innerspace.respec.mjs +366 -81
  3. package/dist/sync/sync-innerspace.respec.mjs.map +1 -1
  4. package/dist/sync/sync-saga-coordinator.d.mts +57 -2
  5. package/dist/sync/sync-saga-coordinator.d.mts.map +1 -1
  6. package/dist/sync/sync-saga-coordinator.mjs +346 -153
  7. package/dist/sync/sync-saga-coordinator.mjs.map +1 -1
  8. package/dist/timeline/timeline-api.respec.mjs +34 -7
  9. package/dist/timeline/timeline-api.respec.mjs.map +1 -1
  10. package/dist/witness/space/inner-space/inner-space-v1.d.mts +1 -1
  11. package/dist/witness/space/inner-space/inner-space-v1.d.mts.map +1 -1
  12. package/dist/witness/space/inner-space/inner-space-v1.mjs +7 -7
  13. package/dist/witness/space/inner-space/inner-space-v1.mjs.map +1 -1
  14. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace-helper.d.mts +18 -0
  15. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace-helper.d.mts.map +1 -1
  16. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace-helper.mjs +39 -10
  17. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace-helper.mjs.map +1 -1
  18. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.d.mts.map +1 -1
  19. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.mjs +2 -1
  20. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.mjs.map +1 -1
  21. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.respec.mjs +6 -4
  22. package/dist/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.respec.mjs.map +1 -1
  23. package/dist/witness/space/space-helper.d.mts.map +1 -1
  24. package/dist/witness/space/space-helper.mjs +1 -0
  25. package/dist/witness/space/space-helper.mjs.map +1 -1
  26. package/package.json +1 -1
  27. package/src/sync/sync-innerspace.respec.mts +401 -88
  28. package/src/sync/sync-saga-coordinator.mts +411 -161
  29. package/src/timeline/timeline-api.respec.mts +34 -16
  30. package/src/witness/space/inner-space/inner-space-v1.mts +8 -5
  31. package/src/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace-helper.mts +39 -10
  32. package/src/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.mts +2 -1
  33. package/src/witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.respec.mts +5 -3
  34. package/src/witness/space/reconciliation-space/reconciliation-space-base.mts.OLD.md +884 -0
  35. package/src/witness/space/reconciliation-space/reconciliation-space-helper.mts.OLD.md +125 -0
  36. package/src/witness/space/space-helper.mts +1 -1
@@ -9,24 +9,22 @@ import {
9
9
  lastOfEach, lastOfAll,
10
10
  ifWeMight, iReckon, respecfully, respecfullyDear
11
11
  } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
12
+ const maam = `[${import.meta.url}]`, sir = maam;
13
+ import { getUUID } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
14
+ import { IbGibData_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
15
+ import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
12
16
 
13
- import { IbGib_V1, IbGibData_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
17
+ import { GLOBAL_LOG_A_LOT } from '../core-constants.mjs';
14
18
  import { InnerSpace_V1 } from '../witness/space/inner-space/inner-space-v1.mjs';
15
- import { DEFAULT_INNER_SPACE_DATA_V1 } from '../witness/space/inner-space/inner-space-types.mjs';
19
+ import { getLatestAddrs, getFromSpace } from '../witness/space/space-helper.mjs';
16
20
  import {
17
- getLatestAddrs, persistTransformResult, registerNewIbGib, getFromSpace
18
- } from '../witness/space/space-helper.mjs';
19
- import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
20
- import {
21
- createTimeline, mut8Timeline, appendToTimeline, getHistory
21
+ createTimeline, mut8Timeline, getHistory, appendToTimeline
22
22
  } from './timeline-api.mjs';
23
- import { MetaspaceService } from '../witness/space/metaspace/metaspace-types.mjs';
24
- import { IbGibAddr } from '@ibgib/ts-gib/dist/types.mjs';
25
- import { IbGibSpaceAny } from '../witness/space/space-base-v1.mjs';
26
-
27
23
  import { Metaspace_Innerspace } from '../witness/space/metaspace/metaspace-innerspace/metaspace-innerspace.mjs';
24
+ import { resetInnerSpaces } from '../witness/space/metaspace/metaspace-innerspace/metaspace-innerspace-helper.mjs';
25
+
26
+ const logalot = GLOBAL_LOG_A_LOT;
28
27
 
29
- const maam = `[${import.meta.url}]`, sir = maam;
30
28
 
31
29
  interface TestData extends IbGibData_V1 {
32
30
  note?: string;
@@ -40,11 +38,12 @@ respecfully(sir, `[timeline-api]`, async () => {
40
38
  let metaspace: Metaspace_Innerspace;
41
39
 
42
40
  firstOfEach(sir, async () => {
41
+ resetInnerSpaces();
43
42
  metaspace = new Metaspace_Innerspace(undefined);
44
43
  await metaspace.initialize({
45
44
  getFnAlert: () => async ({ title, msg }) => { console.log(`[Alert] ${title}: ${msg}`); },
46
45
  getFnPrompt: () => async ({ title, msg }) => { console.log(`[Prompt] ${title}: ${msg}`); return ''; },
47
- getFnPromptPassword: () => async (title, msg) => { console.log(`[PromptPwd] ${title}: ${msg}`); return null; },
46
+ getFnPromptPassword: () => async (title, msg) => { console.log(`[PromptPwd] ${title}: ${msg}`); return 'password'; },
48
47
  });
49
48
  space = metaspace.zeroSpace as InnerSpace_V1;
50
49
  });
@@ -165,7 +164,8 @@ respecfully(sir, `[timeline-api]`, async () => {
165
164
  const concurrencyLevels = [1, 2, 5, 50];
166
165
 
167
166
  for (const N of concurrencyLevels) {
168
- console.log(`[Stress Test] Testing concurrency level: ${N}`);
167
+ if (logalot) { console.log(`[Stress Test] Testing concurrency level: ${N}`); }
168
+
169
169
 
170
170
  // Arrange: Baseline
171
171
  let tInitial = (await createTimeline<TestData>({
@@ -179,8 +179,26 @@ respecfully(sir, `[timeline-api]`, async () => {
179
179
  const initialN = (tInitial.data!.n || 0); // should be 1
180
180
  const historyInitial = await getHistory({ timeline: tInitial, metaspace, space });
181
181
  const initialHistoryLength = historyInitial.orderedPastIbGibs.length; // should be 1 (genesis)
182
+ console.log(`already had addr for fork expected (I: 585a392f1c5aa0eedc1aedd8bbc31325)`);
182
183
 
183
184
  // Act: Launch N mutations simultaneously
185
+ /**
186
+ * I'm getting output (warnings?) that the transform ibgib addr
187
+ * already exists. This stems from the fact that dna/transform
188
+ * ibgibs do not have timestamps or anything, they simply are
189
+ * memoized args to the transform functions. So we need something
190
+ * unique _in the arg itself_, which in this case means in the
191
+ * `dataToAddOrPatch` field.
192
+ *
193
+ * Note, however, that it is expected for the original `fork`
194
+ * transform that created tInitial to be common and for it to
195
+ * already have this fork dna ibgib. But this shouldn't happen for
196
+ * each mut8 transform.
197
+ */
198
+ const uniqueIdsForUniqueTransforms: string[] = [];
199
+ for (let i = 0; i < N; i++) {
200
+ uniqueIdsForUniqueTransforms.push(await getUUID());
201
+ }
184
202
  const promises: Promise<any>[] = [];
185
203
  for (let i = 0; i < N; i++) {
186
204
  promises.push(mut8Timeline<TestData>({
@@ -191,7 +209,7 @@ respecfully(sir, `[timeline-api]`, async () => {
191
209
  space,
192
210
  mut8Opts: {
193
211
  dataToAddOrPatch: {
194
- uniq: i, // distinct data to ensure unique hashes if needed
212
+ uniqueId: uniqueIdsForUniqueTransforms.pop(),
195
213
  }
196
214
  }
197
215
  // No skipLock! We want them to contend.
@@ -225,7 +243,7 @@ respecfully(sir, `[timeline-api]`, async () => {
225
243
  const expectedHistoryLength = initialHistoryLength + N;
226
244
  iReckon(sir, history.orderedPastIbGibs.length).asTo(`[N=${N}] history length`).isGonnaBe(expectedHistoryLength);
227
245
 
228
- console.log(`[Stress Test] [N=${N}] SUCCESS. Final n=${latestIbGib.data!.n}`);
246
+ if (logalot) { console.log(`[Stress Test] [N=${N}] SUCCESS. Final n=${latestIbGib.data!.n}`); }
229
247
 
230
248
  } catch (err) {
231
249
  console.error(`[Stress Test] [N=${N}] FAILED:`, err);
@@ -1,7 +1,6 @@
1
- import { clone, extractErrorMsg, groupBy, pretty } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
1
+ import { clone, extractErrorMsg, getUUID, groupBy, pretty } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
2
2
  import { IbGibAddr } from '@ibgib/ts-gib/dist/types.mjs';
3
3
  import { getIbGibAddr, } from '@ibgib/ts-gib/dist/helper.mjs';
4
- import { IbGib_V1, getGib, } from '@ibgib/ts-gib/dist/V1/index.mjs';
5
4
  import { validateIbGibIntrinsically } from '@ibgib/ts-gib/dist/V1/validate-helper.mjs';
6
5
 
7
6
  import { GLOBAL_LOG_A_LOT } from '../../../core-constants.mjs';
@@ -14,6 +13,8 @@ import { getSpaceIb, } from '../space-helper.mjs';
14
13
  import { getTjpAddr } from '../../../common/other/ibgib-helper.mjs';
15
14
  import { ReconciliationSpaceBase, ReconciliationSpaceData, ReconciliationSpaceRel8ns } from '../reconciliation-space/reconciliation-space-base.mjs';
16
15
  import { DEFAULT_INNER_SPACE_DATA_V1, InnerSpaceData_V1, InnerSpaceRel8ns_V1 } from './inner-space-types.mjs';
16
+ import { IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
17
+ import { getGib } from '@ibgib/ts-gib/dist/V1/transforms/transform-helper.mjs';
17
18
 
18
19
  const logalot = GLOBAL_LOG_A_LOT;
19
20
 
@@ -84,7 +85,8 @@ export class InnerSpace_V1<
84
85
  }
85
86
  this.data!.classname = InnerSpace_V1.name; // always set?
86
87
  }
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
+ // 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)`); }
89
+ this.data.uuid ??= await getUUID();
88
90
 
89
91
  this.ib = getSpaceIb({ space: this, classname: this.data!.classname });
90
92
  this.gib = await getGib({ ibGib: this });
@@ -197,7 +199,7 @@ export class InnerSpace_V1<
197
199
 
198
200
  if (addrsAlreadyHave.length > 0) {
199
201
  resultData.addrsAlreadyHave = addrsAlreadyHave;
200
- resultData.warnings = (resultData.warnings || []).concat([`${lc} already had addr(s).`]);
202
+ resultData.warnings = (resultData.warnings || []).concat([`${lc} already had addr(s): ${addrsAlreadyHave.join('|')}`]);
201
203
  }
202
204
  resultData.success = true;
203
205
  } catch (error) {
@@ -321,7 +323,8 @@ export class InnerSpace_V1<
321
323
  const timeline = ibGibsInSpaceByTjp[tjpAddr];
322
324
 
323
325
  if (timeline.some(ibGib => ibGib.data?.n === undefined)) {
324
- console.warn(`${lc} timeline includes ibgibs with ibGib.data?.n === undefined (W: 7360a8e81b05accf244fb4b86e796325)`);
326
+ const filtered = timeline.filter(ibGib => ibGib.data?.n === undefined);
327
+ console.warn(`${lc} timeline includes ibgibs with ibGib.data?.n === undefined.\nfiltered:\n${filtered.map(x => pretty(x)).join('\n')}}(W: 7360a8e81b05accf244fb4b86e796325)`);
325
328
  }
326
329
  // sort mutates array in place
327
330
  timeline.sort((a, b) => (a.data?.n ?? -1) > (b.data?.n ?? -1) ? 1 : -1); // sorts ascending, e.g., 0,1,2...[Highest]
@@ -10,7 +10,39 @@ import { InnerSpace_V1, } from "../../inner-space/inner-space-v1.mjs";
10
10
  import { InnerSpaceData_V1 } from "../../inner-space/inner-space-types.mjs";
11
11
 
12
12
 
13
- const innerSpaces: { [tjpGib: string]: IbGibSpaceAny } = {};
13
+ const innerSpaces: { [spaceId: string]: IbGibSpaceAny } = {};
14
+
15
+ /**
16
+ * Extracts the spaceId from the ib string.
17
+ *
18
+ * ib format: `witness space [classname] [name] [id] [type] [subtype]`
19
+ */
20
+ export function getSpaceIdFromIb(ib: string): string {
21
+ if (!ib) { throw new Error(`ib required. (E: 7c28c8e1a8a24345bb344155b4131422)`); }
22
+ const parts = ib.split(' ');
23
+ // witness space classname name id ...
24
+ // 0 1 2 3 4
25
+ if (parts.length < 5) { throw new Error(`invalid space ib format: ${ib} (E: 14a84497e59648949822067786481223)`); }
26
+ return parts[4];
27
+ }
28
+
29
+ /**
30
+ * Manually registers a space in the module-level registry.
31
+ * Use this when creating spaces outside of the standard factory functions
32
+ * (e.g. via direct constructor calls) to ensure they are resolvable by DTO.
33
+ */
34
+ export const registerInnerSpace = (space: IbGibSpaceAny) => {
35
+ const spaceId = getSpaceIdFromIb(space.ib);
36
+ innerSpaces[spaceId] = space;
37
+ }
38
+
39
+ /**
40
+ * Resets the internal registry of spaces.
41
+ * USE FOR TESTING ONLY.
42
+ */
43
+ export const resetInnerSpaces = () => {
44
+ Object.keys(innerSpaces).forEach(key => delete innerSpaces[key]);
45
+ }
14
46
 
15
47
  export const fnCreateNewLocalSpace: LocalSpaceFactoryFunction = async ({
16
48
  allowCancel,
@@ -74,9 +106,7 @@ Enter space name:
74
106
  if (newLocalSpace.gib === GIB) { throw new Error(`localSpace.gib not updated correctly.`); }
75
107
  if (logalot) { console.log(`${lc} localSpace.gib: ${newLocalSpace.gib} (after sha256v1)`); }
76
108
 
77
- const gibInfo = getGibInfo({ gib: newLocalSpace.gib });
78
- const tjpGib = gibInfo.tjpGib ?? newLocalSpace.gib!;
79
- innerSpaces[tjpGib] = newLocalSpace;
109
+ registerInnerSpace(newLocalSpace as IbGibSpaceAny);
80
110
 
81
111
  return newLocalSpace as IbGibSpaceAny;
82
112
  } catch (error) {
@@ -103,9 +133,9 @@ export const fnDtoToSpace: DtoToSpaceFunction = async (spaceDto) => {
103
133
  if (!spaceDto.data) { throw new Error(`invalid spaceDto. InnerSpace_V1 should have truthy data. (E: d402fda7a6a53668b655c2885029a423)`); }
104
134
  // console.dir(spaceDto); // I want to keep this in if we need to turn the logging back on
105
135
 
106
- const gibInfo = getGibInfo({ gib: spaceDto.gib });
107
- const tjpGib = gibInfo.tjpGib ?? spaceDto.gib!;
108
- const existingSpace = innerSpaces[tjpGib];
136
+ const spaceId = getSpaceIdFromIb(spaceDto.ib);
137
+ // console.log(`${lc} spaceDto.gib: ${spaceDto.gib}\ninnerSpaces keys:\n${Object.keys(innerSpaces).join('\n')}`);
138
+ const existingSpace = innerSpaces[spaceId];
109
139
  if (existingSpace) {
110
140
  return existingSpace;
111
141
  } else {
@@ -113,9 +143,8 @@ export const fnDtoToSpace: DtoToSpaceFunction = async (spaceDto) => {
113
143
  console.warn(`${lc} in memory innerspace dto that isnt' the reference to the object itself in memory, and we don't have it in the inner spaces map? i guess we'll create a new one from the dto (W: b8973f3a43f546eeaf59f60331896e75)`)
114
144
  let space = new InnerSpace_V1(spaceDto.data as InnerSpaceData_V1, spaceDto.rel8ns);
115
145
  await space.initialized;
116
- const gibInfo = getGibInfo({ gib: space.gib });
117
- const tjpGib = gibInfo.tjpGib ?? space.gib!;
118
- innerSpaces[tjpGib] = space;
146
+
147
+ registerInnerSpace(space);
119
148
  return space;
120
149
  }
121
150
  }
@@ -12,7 +12,7 @@ import { IbGibSpaceAny } from '../../../../witness/space/space-base-v1.mjs';
12
12
  import { InnerSpace_V1 } from '../../../../witness/space/inner-space/inner-space-v1.mjs';
13
13
  import { IbGibCacheService } from '../../../../common/cache/cache-types.mjs';
14
14
  import { MetaspaceFactory } from '../metaspace-types.mjs';
15
- import { fnCreateNewLocalSpace, fnDtoToSpace } from './metaspace-innerspace-helper.mjs';
15
+ import { fnCreateNewLocalSpace, fnDtoToSpace, registerInnerSpace } from './metaspace-innerspace-helper.mjs';
16
16
  import { MetaspaceBase } from '../metaspace-base.mjs';
17
17
 
18
18
  const logalot = GLOBAL_LOG_A_LOT;
@@ -75,6 +75,7 @@ export class Metaspace_Innerspace extends MetaspaceBase {
75
75
  const zeroSpace = new InnerSpace_V1(/*initialData*/ undefined as any, /*initialRel8ns*/ undefined);
76
76
  zeroSpace.gib = 'gib';
77
77
  this._zeroSpace = zeroSpace;
78
+ registerInnerSpace(this._zeroSpace);
78
79
  return zeroSpace;
79
80
  }
80
81
  };
@@ -16,6 +16,7 @@ import { InnerSpace_V1 } from '../../../../witness/space/inner-space/inner-space
16
16
  import { Metaspace_Innerspace } from './metaspace-innerspace.mjs';
17
17
  import { createTimeline, mut8Timeline } from '../../../../timeline/timeline-api.mjs';
18
18
  import { MetaspaceService } from '../metaspace-types.mjs';
19
+ import { resetInnerSpaces } from './metaspace-innerspace-helper.mjs';
19
20
 
20
21
  const maam = `[${import.meta.url}]`, sir = maam;
21
22
 
@@ -24,6 +25,7 @@ respecfully(sir, `[metaspace-innerspace]`, async () => {
24
25
  let metaspace: Metaspace_Innerspace;
25
26
 
26
27
  firstOfEach(sir, async () => {
28
+ resetInnerSpaces();
27
29
  metaspace = new Metaspace_Innerspace(undefined); // no cache for now
28
30
  await metaspace.initialize({
29
31
  getFnAlert: () => async ({ title, msg }) => { console.log(`[Alert] ${title}: ${msg}`); },
@@ -32,17 +34,17 @@ respecfully(sir, `[metaspace-innerspace]`, async () => {
32
34
  });
33
35
  });
34
36
 
35
- await ifWeMight(sir, `can instantiate`, async () => {
37
+ await ifWe(sir, `can instantiate`, async () => {
36
38
  iReckon(sir, metaspace).asTo('metaspace').isGonnaBeTruthy();
37
39
  iReckon(sir, metaspace.initialized).asTo('initialized').isGonnaBeTrue();
38
40
  });
39
41
 
40
- await ifWeMight(sir, `has zeroSpace`, async () => {
42
+ await ifWe(sir, `has zeroSpace`, async () => {
41
43
  const zs = metaspace.zeroSpace;
42
44
  iReckon(sir, zs).asTo('zeroSpace').isGonnaBeTruthy();
43
45
  });
44
46
 
45
- await ifWeMight(sir, `can createTimeline and track latest`, async () => {
47
+ await ifWe(sir, `can createTimeline and track latest`, async () => {
46
48
  // This implicitly tests getLatestAddr/s via timeline-api usage if we were using it,
47
49
  // but here we call it directly or via minimal timeline op.
48
50