@ibgib/ts-gib 0.5.20 → 0.5.23

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 (48) hide show
  1. package/.VSCodeCounter/2024-07-02_16-01-47/details.md +45 -0
  2. package/.VSCodeCounter/2024-07-02_16-01-47/diff-details.md +15 -0
  3. package/.VSCodeCounter/2024-07-02_16-01-47/diff.csv +2 -0
  4. package/.VSCodeCounter/2024-07-02_16-01-47/diff.md +19 -0
  5. package/.VSCodeCounter/2024-07-02_16-01-47/diff.txt +22 -0
  6. package/.VSCodeCounter/2024-07-02_16-01-47/results.csv +32 -0
  7. package/.VSCodeCounter/2024-07-02_16-01-47/results.json +1 -0
  8. package/.VSCodeCounter/2024-07-02_16-01-47/results.md +30 -0
  9. package/.VSCodeCounter/2024-07-02_16-01-47/results.txt +63 -0
  10. package/.vscode/tasks.json +0 -0
  11. package/CHANGELOG.md +11 -0
  12. package/dist/V1/factory.mjs.map +1 -1
  13. package/dist/V1/sha256v1.d.mts +1 -0
  14. package/dist/V1/sha256v1.d.mts.map +1 -1
  15. package/dist/V1/sha256v1.mjs +182 -1
  16. package/dist/V1/sha256v1.mjs.map +1 -1
  17. package/dist/V1/transforms/fork.mjs.map +1 -1
  18. package/dist/V1/transforms/mut8.mjs +1 -1
  19. package/dist/V1/transforms/mut8.mjs.map +1 -1
  20. package/dist/V1/transforms/rel8.d.mts.map +1 -1
  21. package/dist/V1/transforms/rel8.mjs +2 -2
  22. package/dist/V1/transforms/rel8.mjs.map +1 -1
  23. package/dist/V1/transforms/transform-helper.mjs +1 -1
  24. package/dist/V1/transforms/transform-helper.mjs.map +1 -1
  25. package/dist/V1/v1-helper.d.mts.map +1 -1
  26. package/dist/V1/v1-helper.mjs +5 -5
  27. package/dist/V1/v1-helper.mjs.map +1 -1
  28. package/dist/V1/validate-helper.mjs.map +1 -1
  29. package/dist/helper.d.mts +21 -0
  30. package/dist/helper.d.mts.map +1 -1
  31. package/dist/helper.mjs +43 -0
  32. package/dist/helper.mjs.map +1 -1
  33. package/dist/respec-gib.node.mjs +2 -2
  34. package/dist/respec-gib.node.mjs.map +1 -1
  35. package/package.json +2 -2
  36. package/src/V1/factory.respec.mts +4 -8
  37. package/src/V1/sha256v1.mts +183 -1
  38. package/src/V1/sha256v1.respec.mts +1030 -8
  39. package/src/V1/transforms/{fork.spec.mts → fork.respec.mts} +37 -25
  40. package/src/V1/transforms/mut8.mts +1 -1
  41. package/src/V1/transforms/{mut8.spec.mts → mut8.respec.mts} +39 -32
  42. package/src/V1/transforms/rel8.mts +2 -3
  43. package/src/V1/transforms/{rel8.spec.mts → rel8.respec.mts} +76 -61
  44. package/src/V1/transforms/{transform-helper.spec.mts → transform-helper.respec.mts} +9 -9
  45. package/src/V1/v1-helper.mts +6 -5
  46. package/src/helper.mts +48 -0
  47. package/src/helper.respec.mts +81 -1
  48. package/src/respec-gib.node.mts +1 -1
@@ -6,12 +6,16 @@
6
6
  * is required for browser until I get some kind of browser testing
7
7
  * going.
8
8
  */
9
+ import { clone, } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
10
+ import {
11
+ firstOfAll, ifWe, ifWeMight, iReckon, respecfully
12
+ } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
13
+ const maam = `[${import.meta.url}]`, sir = maam;
9
14
 
10
15
  import { IbGib_V1, IbGibRel8ns_V1, Rel8n } from '../types.mjs';
11
16
  import { TransformOpts_Rel8, IbGibAddr, IbGibRel8ns } from '../../types.mjs';
12
17
  import { getIbGibAddr, getIbAndGib } from '../../helper.mjs';
13
- import { pretty, clone, delay, } from '@ibgib/helper-gib';
14
- import { ROOT, ROOT_ADDR } from '../constants.mjs';
18
+ import { ROOT_ADDR } from '../constants.mjs';
15
19
  import { fork } from './fork.mjs';
16
20
  // import { mut8 } from './mut8.mjs';
17
21
  import { rel8 } from './rel8.mjs';
@@ -84,7 +88,7 @@ await respecfully(sir, `can't rel8 primitives to others`, async () => {
84
88
  } catch (error) {
85
89
  errored = true;
86
90
  }
87
- iReckon(sir, errored).toBeTrue()
91
+ iReckon(sir, errored).isGonnaBeTrue()
88
92
  });
89
93
 
90
94
  await ifWe(sir, `should fail to remove rel8ns`, async () => {
@@ -95,7 +99,7 @@ await respecfully(sir, `can't rel8 primitives to others`, async () => {
95
99
  } catch (error) {
96
100
  errored = true;
97
101
  }
98
- iReckon(sir, errored).toBeTrue()
102
+ iReckon(sir, errored).isGonnaBeTrue()
99
103
  });
100
104
 
101
105
  await ifWe(sir, `should fail to add and remove rel8ns`, async () => {
@@ -109,7 +113,7 @@ await respecfully(sir, `can't rel8 primitives to others`, async () => {
109
113
  } catch (error) {
110
114
  errored = true;
111
115
  }
112
- iReckon(sir, errored).toBeTrue()
116
+ iReckon(sir, errored).isGonnaBeTrue()
113
117
  });
114
118
 
115
119
  }
@@ -138,12 +142,13 @@ await respecfully(sir, `when rel8ing a regular ibgib`, async () => {
138
142
  iReckon(sir, rel8nsAddedIbGib.rel8ns).isGonnaBeTruthy();
139
143
  const rel8nNames_AddedIbGib = Object.keys(rel8nsAddedIbGib.rel8ns!);
140
144
  SIMPLE_REL8N_NAMES.forEach(simpleRel8nName => {
141
- iReckon(sir, rel8nNames_AddedIbGib).toContain(simpleRel8nName);
145
+ iReckon(sir, rel8nNames_AddedIbGib).includes(simpleRel8nName);
142
146
  const simpleRel8nAddrs = rel8nsAddedIbGib.rel8ns![simpleRel8nName]!;
143
- // expect(simpleRel8nAddrs).not.toHaveSize(0);
144
- iReckon(sir, simpleRel8nAddrs).not.toHaveSize(0);
145
- const expectedRel8nAddrs = rel8nsToAddByAddr[simpleRel8nName];
146
- iReckon(sir, expectedRel8nAddrs).not.toHaveSize(0);
147
+ // iReckon(sir, simpleRel8nAddrs).not.toHaveSize(0);
148
+ iReckon(sir, simpleRel8nAddrs.length === 0).isGonnaBeFalse();
149
+ const expectedRel8nAddrs = rel8nsToAddByAddr[simpleRel8nName] ?? [];
150
+ // iReckon(sir, expectedRel8nAddrs.length === 0).not.toHaveSize(0);
151
+ iReckon(sir, expectedRel8nAddrs.length === 0).isGonnaBeFalse();
147
152
  iReckon(sir, simpleRel8nAddrs).isGonnaBe(expectedRel8nAddrs!);
148
153
  });
149
154
 
@@ -164,10 +169,10 @@ await respecfully(sir, `when rel8ing a regular ibgib`, async () => {
164
169
 
165
170
  SIMPLE_REL8N_NAMES.forEach(simpleRel8nName => {
166
171
  const rel8dAddrs = rel8nsRemovedIbGib.rel8ns![simpleRel8nName]!;
167
- // expect(rel8dAddrs).not.toContain(to.not.include.any.members([ROOT_ADDR, 'tag^gib']);
168
- [ROOT_ADDR, 'tag^gib'].forEach(x => { expect(rel8dAddrs).not.toContain(x); })
172
+ // iReckon(sir, rel8dAddrs).not.includes(to.not.include.any.members([ROOT_ADDR, 'tag^gib']);
173
+ [ROOT_ADDR, 'tag^gib'].forEach(x => { iReckon(sir, rel8dAddrs).not.includes(x); })
169
174
 
170
- // expect(rel8dAddrs).to.include.all.members(
175
+ // iReckon(sir, rel8dAddrs).to.include.all.members(
171
176
  // PRIMITIVE_IBGIBS
172
177
  // .map(x => getIbGibAddr({ ibGib: x }))
173
178
  // .filter(addr => addr !== ROOT_ADDR && addr !== 'tag^gib')
@@ -175,7 +180,7 @@ await respecfully(sir, `when rel8ing a regular ibgib`, async () => {
175
180
  PRIMITIVE_IBGIBS
176
181
  .map(x => getIbGibAddr({ ibGib: x }))
177
182
  .filter(addr => addr !== ROOT_ADDR && addr !== 'tag^gib')
178
- .forEach(x => expect(rel8dAddrs).toContain(x));
183
+ .forEach(x => iReckon(sir, rel8dAddrs).includes(x));
179
184
  });
180
185
 
181
186
  //#endregion
@@ -213,11 +218,13 @@ await respecfully(sir, `when rel8ing a regular ibgib`, async () => {
213
218
  const rel8DnaDataAdd: TransformOpts_Rel8<IbGib_V1> = clone(rel8DnaAdd.data!);
214
219
  const rel8nNames_AddedIbGib = Object.keys(rel8nsAddedIbGib.rel8ns!);
215
220
  SIMPLE_REL8N_NAMES.forEach(simpleRel8nName => {
216
- iReckon(sir, rel8nNames_AddedIbGib).toContain(simpleRel8nName);
221
+ iReckon(sir, rel8nNames_AddedIbGib).includes(simpleRel8nName);
217
222
  const simpleRel8nAddrs = rel8nsAddedIbGib.rel8ns![simpleRel8nName]!;
218
- iReckon(sir, simpleRel8nAddrs).not.toHaveSize(0);
219
- const expectedRel8nAddrs = rel8nsToAddByAddr[simpleRel8nName];
220
- iReckon(sir, expectedRel8nAddrs).not.toHaveSize(0);
223
+ // iReckon(sir, simpleRel8nAddrs).not.toHaveSize(0);
224
+ iReckon(sir, simpleRel8nAddrs.length === 0).isGonnaBeFalse();
225
+ const expectedRel8nAddrs = rel8nsToAddByAddr[simpleRel8nName] ?? [];
226
+ // iReckon(sir, expectedRel8nAddrs).not.toHaveSize(0);
227
+ iReckon(sir, expectedRel8nAddrs.length === 0).isGonnaBeFalse();
221
228
  iReckon(sir, simpleRel8nAddrs).isGonnaBe(expectedRel8nAddrs!);
222
229
  });
223
230
 
@@ -230,11 +237,13 @@ await respecfully(sir, `when rel8ing a regular ibgib`, async () => {
230
237
  await rel8(rel8DnaDataAdd);
231
238
  const rel8nNames_AddedIbGib2 = Object.keys(rel8nsAddedIbGib2.rel8ns!);
232
239
  SIMPLE_REL8N_NAMES.forEach(simpleRel8nName => {
233
- iReckon(sir, rel8nNames_AddedIbGib2).toContain(simpleRel8nName);
240
+ iReckon(sir, rel8nNames_AddedIbGib2).includes(simpleRel8nName);
234
241
  const simpleRel8nAddrs = rel8nsAddedIbGib2.rel8ns![simpleRel8nName]!;
235
- iReckon(sir, simpleRel8nAddrs).not.toHaveSize(0);
236
- const expectedRel8nAddrs = rel8nsToAddByAddr[simpleRel8nName];
237
- iReckon(sir, expectedRel8nAddrs).not.toHaveSize(0);
242
+ // iReckon(sir, simpleRel8nAddrs).not.toHaveSize(0);
243
+ iReckon(sir, simpleRel8nAddrs.length === 0).isGonnaBeFalse();
244
+ const expectedRel8nAddrs = rel8nsToAddByAddr[simpleRel8nName] ?? [];
245
+ // iReckon(sir, expectedRel8nAddrs).not.toHaveSize(0);
246
+ iReckon(sir, expectedRel8nAddrs.length === 0).isGonnaBeFalse();
238
247
  iReckon(sir, simpleRel8nAddrs).isGonnaBe(expectedRel8nAddrs!);
239
248
  });
240
249
 
@@ -256,10 +265,10 @@ await respecfully(sir, `when rel8ing a regular ibgib`, async () => {
256
265
 
257
266
  SIMPLE_REL8N_NAMES.forEach(simpleRel8nName => {
258
267
  const rel8dAddrs = rel8nsRemovedIbGib.rel8ns![simpleRel8nName]!;
259
- // expect(rel8dAddrs).to.not.include.any.members([ROOT_ADDR, 'tag^gib']);
260
- [ROOT_ADDR, 'tag^gib'].every(x => { expect(rel8dAddrs).not.toContain(x); });
268
+ // iReckon(sir, rel8dAddrs).to.not.include.any.members([ROOT_ADDR, 'tag^gib']);
269
+ [ROOT_ADDR, 'tag^gib'].every(x => { iReckon(sir, rel8dAddrs).not.includes(x); });
261
270
 
262
- // expect(rel8dAddrs).to.include.all.members(
271
+ // iReckon(sir, rel8dAddrs).to.include.all.members(
263
272
  // PRIMITIVE_IBGIBS
264
273
  // .map(x => getIbGibAddr({ ibGib: x }))
265
274
  // .filter(addr => addr !== ROOT_ADDR && addr !== 'tag^gib')
@@ -267,7 +276,7 @@ await respecfully(sir, `when rel8ing a regular ibgib`, async () => {
267
276
  PRIMITIVE_IBGIBS
268
277
  .map(x => getIbGibAddr({ ibGib: x }))
269
278
  .filter(addr => addr !== ROOT_ADDR && addr !== 'tag^gib')
270
- .forEach(x => expect(rel8dAddrs).toContain(x));
279
+ .forEach(x => iReckon(sir, rel8dAddrs).includes(x));
271
280
  });
272
281
 
273
282
  // rerun the same (un)rel8 call, but get the args from the dna of the
@@ -281,10 +290,10 @@ await respecfully(sir, `when rel8ing a regular ibgib`, async () => {
281
290
 
282
291
  SIMPLE_REL8N_NAMES.forEach(simpleRel8nName => {
283
292
  const rel8dAddrs = rel8nsRemovedIbGib2.rel8ns![simpleRel8nName]!;
284
- // expect(rel8dAddrs).to.not.include.any.members([ROOT_ADDR, 'tag^gib']);
285
- [ROOT_ADDR, 'tag^gib'].forEach(x => expect(rel8dAddrs).not.toContain(x))
293
+ // iReckon(sir, rel8dAddrs).to.not.include.any.members([ROOT_ADDR, 'tag^gib']);
294
+ [ROOT_ADDR, 'tag^gib'].forEach(x => iReckon(sir, rel8dAddrs).not.includes(x))
286
295
 
287
- // expect(rel8dAddrs).to.include.all.members(
296
+ // iReckon(sir, rel8dAddrs).to.include.all.members(
288
297
  // PRIMITIVE_IBGIBS
289
298
  // .map(x => getIbGibAddr({ ibGib: x }))
290
299
  // .filter(addr => addr !== ROOT_ADDR && addr !== 'tag^gib')
@@ -292,7 +301,7 @@ await respecfully(sir, `when rel8ing a regular ibgib`, async () => {
292
301
  PRIMITIVE_IBGIBS
293
302
  .map(x => getIbGibAddr({ ibGib: x }))
294
303
  .filter(addr => addr !== ROOT_ADDR && addr !== 'tag^gib')
295
- .forEach(x => expect(rel8dAddrs).toContain(x));
304
+ .forEach(x => iReckon(sir, rel8dAddrs).includes(x));
296
305
  });
297
306
 
298
307
  //#endregion
@@ -346,29 +355,29 @@ await respecfully(sir, `when rel8ing a regular ibgib`, async () => {
346
355
  const tjpAddr = getIbGibAddr({ ibGib: tjpIbGib });
347
356
  const tjpAddrGib = getIbAndGib({ ibGibAddr: tjpAddr }).gib;
348
357
  iReckon(sir, tjpIbGib?.data?.isTjp).asTo('src1.data.isTjp').isGonnaBeTruthy();
349
- iReckon(sir, tjpIbGib?.rel8ns?.tjp).asTo('src1.rel8ns.tjp').toBeUndefined();
358
+ iReckon(sir, tjpIbGib?.rel8ns?.tjp).asTo('src1.rel8ns.tjp').isGonnaBeUndefined();
350
359
  const { newIbGib: hasRel8dTjp } =
351
360
  await rel8({ src: tjpIbGib, rel8nsToAddByAddr: testRel8ns });
352
361
  const hasRel8dTjpAddr = getIbGibAddr({ ibGib: hasRel8dTjp });
353
362
  const hasRel8dTjpAddrGib = getIbAndGib({ ibGibAddr: hasRel8dTjpAddr }).gib;
354
- iReckon(sir, hasRel8dTjp?.data?.isTjp).asTo('src2.data.isTjp').toBeUndefined();
363
+ iReckon(sir, hasRel8dTjp?.data?.isTjp).asTo('src2.data.isTjp').isGonnaBeUndefined();
355
364
  iReckon(sir, hasRel8dTjp?.rel8ns?.tjp).asTo('src2.rel8ns.tjp').isGonnaBeTruthy();
356
365
  iReckon(sir, hasRel8dTjp!.rel8ns!.tjp!.length).asTo('src2.rel8ns.tjp.length').isGonnaBe(1);
357
- iReckon(sir, hasRel8dTjp!.rel8ns!.tjp!).toContain(tjpAddr);
366
+ iReckon(sir, hasRel8dTjp!.rel8ns!.tjp!).includes(tjpAddr);
358
367
 
359
368
  // the gib should not just be the hash, since it has a tjp timeline
360
- iReckon(sir, hasRel8dTjpAddrGib).toContain(tjpAddrGib);
369
+ iReckon(sir, hasRel8dTjpAddrGib).includes(tjpAddrGib);
361
370
 
362
371
  // shoe-horning in here some getGibInfo testing...eesh
363
372
  const hasRel8dTjpGibInfo = getGibInfo({ ibGibAddr: hasRel8dTjpAddr }); // via addr
364
- iReckon(sir, hasRel8dTjpGibInfo.isPrimitive).toBeUndefined();
365
- iReckon(sir, hasRel8dTjpGibInfo.piecesCount).isGonnaBe(2, 'pieces count');
373
+ iReckon(sir, hasRel8dTjpGibInfo.isPrimitive).isGonnaBeUndefined();
374
+ iReckon(sir, hasRel8dTjpGibInfo.piecesCount).asTo('pieces count').isGonnaBe(2);
366
375
  const hasRel8dTjpHash = await sha256v1(hasRel8dTjp, '');
367
- iReckon(sir, hasRel8dTjpGibInfo.punctiliarHash).isGonnaBe(hasRel8dTjpHash, 'punctiliarHash');
376
+ iReckon(sir, hasRel8dTjpGibInfo.punctiliarHash).asTo('punctiliarHash').isGonnaBe(hasRel8dTjpHash);
368
377
  iReckon(sir, hasRel8dTjpGibInfo.tjpGib).isGonnaBe(tjpAddrGib);
369
378
  // the info should be the same if we get it straight from the gib
370
379
  const hasRel8dTjpGibInfo_viaGib = getGibInfo({ gib: hasRel8dTjpAddrGib }); // via gib
371
- iReckon(sir, hasRel8dTjpGibInfo_viaGib).isGonnaBe(hasRel8dTjpGibInfo, 'infos via addr and gib should be equal');
380
+ iReckon(sir, hasRel8dTjpGibInfo_viaGib).asTo('infos via addr and gib should be equal').isGonnaBe(hasRel8dTjpGibInfo);
372
381
 
373
382
  // ok, yes my testing is out of control, but I'm going to shoehorn in here
374
383
  // another rel8 and make sure that the punctiliar hash is correct and the gib only has two pieces.
@@ -379,8 +388,8 @@ await respecfully(sir, `when rel8ing a regular ibgib`, async () => {
379
388
  const thirdGenGibInfo = getGibInfo({ ibGibAddr: thirdGenAddr });
380
389
  const thirdGenHash = await sha256v1(thirdGenIbGib, '');
381
390
  iReckon(sir, thirdGenGibInfo.punctiliarHash).isGonnaBe(thirdGenHash);
382
- iReckon(sir, thirdGenGibInfo.tjpGib).isGonnaBe(tjpAddrGib, 'third gen match tjpAddrGib');
383
- iReckon(sir, thirdGenGibInfo.piecesCount).isGonnaBe(2, 'third gen pieces');
391
+ iReckon(sir, thirdGenGibInfo.tjpGib).asTo('third gen match tjpAddrGib').isGonnaBe(tjpAddrGib);
392
+ iReckon(sir, thirdGenGibInfo.piecesCount).asTo('third gen pieces').isGonnaBe(2);
384
393
  });
385
394
  }
386
395
  });
@@ -393,7 +402,7 @@ await respecfully(sir, `when rel8ing a regular ibgib`, async () => {
393
402
 
394
403
  iReckon(sir, src_0.data).isGonnaBeTruthy();
395
404
  iReckon(sir, src_0.data!.n).isGonnaBe(0);
396
- iReckon(sir, src_0!.data?.isTjp).asTo("isTjp").toBeUndefined();
405
+ iReckon(sir, src_0!.data?.isTjp).asTo("isTjp").isGonnaBeUndefined();
397
406
 
398
407
  const rel8nsToAddByAddr = buildRel8nsToAddOrRemoveFromPrimitives(SIMPLE_REL8N_NAMES);
399
408
 
@@ -412,11 +421,13 @@ await respecfully(sir, `when rel8ing a regular ibgib`, async () => {
412
421
  iReckon(sir, src_1.rel8ns).isGonnaBeTruthy();
413
422
  const rel8nNames_AddedIbGib = Object.keys(src_1.rel8ns!);
414
423
  SIMPLE_REL8N_NAMES.forEach(simpleRel8nName => {
415
- iReckon(sir, rel8nNames_AddedIbGib).toContain(simpleRel8nName);
424
+ iReckon(sir, rel8nNames_AddedIbGib).includes(simpleRel8nName);
416
425
  const simpleRel8nAddrs = src_1.rel8ns![simpleRel8nName]!;
417
- iReckon(sir, simpleRel8nAddrs).not.toHaveSize(0);
418
- const expectedRel8nAddrs = rel8nsToAddByAddr[simpleRel8nName];
419
- iReckon(sir, expectedRel8nAddrs).not.toHaveSize(0);
426
+ // iReckon(sir, simpleRel8nAddrs).not.toHaveSize(0);
427
+ iReckon(sir, simpleRel8nAddrs.length === 0).isGonnaBeFalse();
428
+ const expectedRel8nAddrs = rel8nsToAddByAddr[simpleRel8nName] ?? [];
429
+ // iReckon(sir, expectedRel8nAddrs).not.toHaveSize(0);
430
+ iReckon(sir, expectedRel8nAddrs.length === 0).isGonnaBeFalse();
420
431
  iReckon(sir, simpleRel8nAddrs).isGonnaBe(expectedRel8nAddrs!);
421
432
  });
422
433
 
@@ -425,7 +436,7 @@ await respecfully(sir, `when rel8ing a regular ibgib`, async () => {
425
436
  iReckon(sir, src_1.data!.n).isGonnaBeTruthy();
426
437
  iReckon(sir, src_1.data!.n).isGonnaBeTruthy();
427
438
  iReckon(sir, src_1.data!.n).isGonnaBe(1);
428
- iReckon(sir, src_1!.data?.isTjp).asTo("isTjp").toBeUndefined();
439
+ iReckon(sir, src_1!.data?.isTjp).asTo("isTjp").isGonnaBeUndefined();
429
440
  }
430
441
  });
431
442
  await ifWe(sir, `should start new n counter, implicit nCounter falsy`, async () => {
@@ -435,7 +446,7 @@ await respecfully(sir, `when rel8ing a regular ibgib`, async () => {
435
446
 
436
447
  iReckon(sir, src_0.data).isGonnaBeTruthy();
437
448
  iReckon(sir, src_0.data).isGonnaBeTruthy();
438
- iReckon(sir, src_0.data!.n).toBeUndefined();
449
+ iReckon(sir, src_0.data!.n).isGonnaBeUndefined();
439
450
 
440
451
  const rel8nsToAddByAddr = buildRel8nsToAddOrRemoveFromPrimitives(SIMPLE_REL8N_NAMES);
441
452
 
@@ -454,11 +465,13 @@ await respecfully(sir, `when rel8ing a regular ibgib`, async () => {
454
465
  iReckon(sir, src_1.rel8ns).isGonnaBeTruthy();
455
466
  const rel8nNames_AddedIbGib = Object.keys(src_1.rel8ns!);
456
467
  SIMPLE_REL8N_NAMES.forEach(simpleRel8nName => {
457
- iReckon(sir, rel8nNames_AddedIbGib).toContain(simpleRel8nName);
468
+ iReckon(sir, rel8nNames_AddedIbGib).includes(simpleRel8nName);
458
469
  const simpleRel8nAddrs = src_1.rel8ns![simpleRel8nName]!;
459
- iReckon(sir, simpleRel8nAddrs).not.toHaveSize(0);
460
- const expectedRel8nAddrs = rel8nsToAddByAddr[simpleRel8nName];
461
- iReckon(sir, expectedRel8nAddrs).not.toHaveSize(0);
470
+ // iReckon(sir, simpleRel8nAddrs).not.toHaveSize(0);
471
+ iReckon(sir, simpleRel8nAddrs.length === 0).isGonnaBeFalse();
472
+ const expectedRel8nAddrs = rel8nsToAddByAddr[simpleRel8nName] ?? [];
473
+ // iReckon(sir, expectedRel8nAddrs).not.toHaveSize(0);
474
+ iReckon(sir, expectedRel8nAddrs.length === 0).isGonnaBeFalse();
462
475
  iReckon(sir, simpleRel8nAddrs).isGonnaBe(expectedRel8nAddrs!);
463
476
  });
464
477
 
@@ -473,8 +486,8 @@ await respecfully(sir, `when rel8ing a regular ibgib`, async () => {
473
486
 
474
487
  iReckon(sir, src_0.data).isGonnaBeTruthy();
475
488
  iReckon(sir, src_0.data).isGonnaBeTruthy();
476
- iReckon(sir, src_0.data!.n).toBeUndefined();
477
- iReckon(sir, src_0!.data!.isTjp).asTo("isTjp").toBeUndefined();
489
+ iReckon(sir, src_0.data!.n).isGonnaBeUndefined();
490
+ iReckon(sir, src_0!.data!.isTjp).asTo("isTjp").isGonnaBeUndefined();
478
491
 
479
492
  const rel8nsToAddByAddr = buildRel8nsToAddOrRemoveFromPrimitives(SIMPLE_REL8N_NAMES);
480
493
 
@@ -493,24 +506,26 @@ await respecfully(sir, `when rel8ing a regular ibgib`, async () => {
493
506
  iReckon(sir, src_1.rel8ns).isGonnaBeTruthy();
494
507
  const rel8nNames_AddedIbGib = Object.keys(src_1.rel8ns!);
495
508
  SIMPLE_REL8N_NAMES.forEach(simpleRel8nName => {
496
- iReckon(sir, rel8nNames_AddedIbGib).toContain(simpleRel8nName);
509
+ iReckon(sir, rel8nNames_AddedIbGib).includes(simpleRel8nName);
497
510
  const simpleRel8nAddrs = src_1.rel8ns![simpleRel8nName]!;
498
- iReckon(sir, simpleRel8nAddrs).not.toHaveSize(0);
499
- const expectedRel8nAddrs = rel8nsToAddByAddr[simpleRel8nName];
500
- iReckon(sir, expectedRel8nAddrs).not.toHaveSize(0);
511
+ // iReckon(sir, simpleRel8nAddrs).not.toHaveSize(0);
512
+ iReckon(sir, simpleRel8nAddrs.length === 0).isGonnaBeFalse();
513
+ const expectedRel8nAddrs = rel8nsToAddByAddr[simpleRel8nName] ?? [];
514
+ // iReckon(sir, expectedRel8nAddrs).not.toHaveSize(0);
515
+ iReckon(sir, expectedRel8nAddrs.length === 0).isGonnaBeFalse();
501
516
  iReckon(sir, simpleRel8nAddrs).isGonnaBe(expectedRel8nAddrs!);
502
517
  });
503
518
 
504
519
  iReckon(sir, src_1.data).isGonnaBeTruthy();
505
520
  iReckon(sir, src_1.data!.n).isGonnaBe(0);
506
- iReckon(sir, src_1!.data!.isTjp).asTo("isTjp").toBeUndefined();
521
+ iReckon(sir, src_1!.data!.isTjp).asTo("isTjp").isGonnaBeUndefined();
507
522
  }
508
523
  });
509
524
  // for (const primitive of PRIMITIVE_IBGIBS) {
510
525
  // let { newIbGib: src_0 } =
511
526
  // await fork({src: primitive, noTimestamp: true, nCounter: false});
512
527
 
513
- // expect(src_0.data).toBeUndefined();
528
+ // iReckon(sir, src_0.data).isGonnaBeUndefined();
514
529
 
515
530
  // let { newIbGib: src_1 } =
516
531
  // await mut8({
@@ -518,8 +533,8 @@ await respecfully(sir, `when rel8ing a regular ibgib`, async () => {
518
533
  // dataToAddOrPatch: DATA_SIMPLE_XY,
519
534
  // nCounter: true
520
535
  // });
521
- // expect(src_1.data).isGonnaBeTruthy();
522
- // expect(src_1.data!.n).isGonnaBe(0);
536
+ // iReckon(sir, src_1.data).isGonnaBeTruthy();
537
+ // iReckon(sir, src_1.data!.n).isGonnaBe(0);
523
538
  // }
524
539
  // });
525
540
 
@@ -2,15 +2,15 @@
2
2
  * Test transform-helper.
3
3
  */
4
4
 
5
+ import {
6
+ firstOfEach, firstOfAll, ifWe,
7
+ lastOfEach, lastOfAll,
8
+ ifWeMight, iReckon, respecfully,
9
+ respecfullyDear
10
+ } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
11
+ const maam = `[${import.meta.url}]`, sir = maam;
5
12
 
6
- // import { IbGib_V1, IbGibRel8ns_V1, Rel8n } from '../types.mjs';
7
- // import { TransformOpts_Rel8, IbGibAddr, IbGibRel8ns } from '../../types.mjs';
8
- // import { getIbGibAddr, getIbAndGib } from '../../helper.mjs';
9
- // import { pretty, clone, delay, } from '@ibgib/helper-gib';
10
- // import { ROOT, ROOT_ADDR } from '../constants.mjs';
11
13
  import { fork } from './fork.mjs';
12
- // import { mut8 } from './mut8.mjs';
13
- // import { rel8 } from './rel8.mjs';
14
14
  import { Factory_V1 as factory } from '../factory.mjs';
15
15
  import { isDna } from './transform-helper.mjs';
16
16
 
@@ -32,14 +32,14 @@ await respecfully(sir, `isDna`, async () => {
32
32
  const resFork = await fork({ src, dna: true });
33
33
  resFork.dnas?.every(x => {
34
34
  const resIsDna = isDna({ ibGib: x });
35
- iReckon(sir, resIsDna).toBeTrue()
35
+ iReckon(sir, resIsDna).isGonnaBeTrue()
36
36
  });
37
37
  });
38
38
 
39
39
  await ifWe(sir, `should return false for non-dna ibgibs`, async () => {
40
40
  const resFork = await fork({ src, dna: true });
41
41
  const resIsDna = isDna({ ibGib: resFork.newIbGib });
42
- iReckon(sir, resIsDna).toBeFalse();
42
+ iReckon(sir, resIsDna).isGonnaBeFalse();
43
43
  });
44
44
 
45
45
  }
@@ -1,8 +1,9 @@
1
- import { getIbGibAddr, getIbAndGib } from '../helper.mjs';
2
- import { pretty, clone, delay, } from '@ibgib/helper-gib';
3
- import * as cTsGib from './constants.mjs';
1
+ import { clone, } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
2
+
3
+ import { getIbGibAddr, } from '../helper.mjs';
4
4
  import { getGibInfo } from './transforms/transform-helper.mjs';
5
5
  import { IbGibRel8ns_V1, IbGib_V1 } from "./types.mjs";
6
+ import { GIB, GIB_DELIMITER } from './constants.mjs';
6
7
 
7
8
  /**
8
9
  * Helper function that checks the given `ibGib` to see if it
@@ -49,11 +50,11 @@ export function hasTjp({ ibGib }: { ibGib: IbGib_V1 }): boolean {
49
50
  console.warn(`${lc} ibGib.gib falsy. (W: 6400d780822b44d992846f1196509be3)`);
50
51
  return false;
51
52
  }
52
- if (ibGib.gib.includes(cTsGib.GIB_DELIMITER)) {
53
+ if (ibGib.gib.includes(GIB_DELIMITER)) {
53
54
  return true;
54
55
  }
55
56
 
56
- if (ibGib.gib === cTsGib.GIB) {
57
+ if (ibGib.gib === GIB) {
57
58
  // primitive
58
59
  return false;
59
60
  }
package/src/helper.mts CHANGED
@@ -74,3 +74,51 @@ export function getIbAndGib({
74
74
  }
75
75
  }
76
76
  }
77
+
78
+
79
+ /**
80
+ * Normalizes an object/value for consistent hashing.
81
+ * - Recursively processes objects and arrays.
82
+ * - For objects:
83
+ * - Sorts keys alphabetically.
84
+ * - Removes properties whose values are `undefined`.
85
+ * - Keeps properties whose values are `null`.
86
+ * - For arrays:
87
+ * - Preserves element order.
88
+ * - Recursively normalizes each element.
89
+ * - Primitives (strings, numbers, booleans) and `null` are returned as is.
90
+ *
91
+ * @param value The value to normalize.
92
+ * @returns The normalized value.
93
+ *
94
+ * This has been adjusted due to conversation with Gemini and working on python
95
+ * port. The main thing here is that we normalize array members, but not the
96
+ * array itself. This way the array's order is preserved, but any object members
97
+ * are themselves normalized.
98
+ */
99
+ export function toNormalizedForHashing(value: any): any {
100
+ // Handle null, primitives (string, number, boolean) directly.
101
+ // `undefined` at the top level will be handled by the caller or become part of an object/array.
102
+ if (value === null || typeof value !== 'object') {
103
+ return value;
104
+ }
105
+
106
+ // Handle Arrays: recursively normalize elements, preserve order
107
+ if (Array.isArray(value)) {
108
+ return value.map(element => toNormalizedForHashing(element));
109
+ }
110
+
111
+ // Handle Objects (plain objects)
112
+ const normalizedObject: { [key: string]: any } = {};
113
+ const sortedKeys = Object.keys(value).sort();
114
+
115
+ for (const key of sortedKeys) {
116
+ const propertyValue = value[key];
117
+ if (propertyValue !== undefined) { // CRITICAL: Only omit if value is undefined
118
+ normalizedObject[key] = toNormalizedForHashing(propertyValue);
119
+ }
120
+ // If propertyValue is undefined, it's omitted from normalizedObject.
121
+ // If propertyValue is null, it's included.
122
+ }
123
+ return normalizedObject;
124
+ }
@@ -1,7 +1,7 @@
1
1
  import { ifWe, ifWeMight, iReckon, respecfully } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
2
2
  const maam = `[${import.meta.url}]`, sir = maam;
3
3
 
4
- import { getIbAndGib, getIbGibAddr } from './helper.mjs';
4
+ import { getIbAndGib, getIbGibAddr, toNormalizedForHashing } from './helper.mjs';
5
5
  import { Ib, IbGib } from './types.mjs';
6
6
  import { ROOT, ROOT_ADDR } from './V1/constants.mjs';
7
7
 
@@ -60,3 +60,83 @@ await respecfully(sir, `getIbAndGib`, async () => {
60
60
  });
61
61
 
62
62
  });
63
+
64
+ await respecfully(sir, `normalize object testing for deterministic hashing`, async () => {
65
+ await ifWe(sir, `null, '', {}, undefined, [], etc...`, async () => {
66
+ [
67
+ null,
68
+ '',
69
+ {},
70
+ undefined,
71
+ [],
72
+ 'some string',
73
+ ].forEach(obj1 => {
74
+ const normalized1 = toNormalizedForHashing(obj1);
75
+ iReckon(sir, JSON.stringify(obj1))
76
+ .asTo("Original object should not be modified.")
77
+ .isGonnaBe(JSON.stringify(normalized1));
78
+ });
79
+ });
80
+
81
+ await ifWe(sir, `flat (sort and undefined)`, async () => {
82
+ // test cases with varying key orders and undefined values
83
+ const obj1 = { a: 1, b: 2, c: undefined };
84
+ const obj2 = { c: undefined, b: 2, a: 1 };
85
+ const obj3 = { a: 1, b: 2 };
86
+
87
+ // check original object state before normalization
88
+ const originalObj1String = JSON.stringify(obj1);
89
+
90
+ // normalize the objects
91
+ const normalized1 = toNormalizedForHashing(obj1);
92
+ const normalized2 = toNormalizedForHashing(obj2);
93
+ const normalized3 = toNormalizedForHashing(obj3);
94
+
95
+ // check original object state after normalization to ensure it's unchanged
96
+ iReckon(sir, JSON.stringify(obj1)).asTo("Original object should not be modified.").isGonnaBe(originalObj1String);
97
+
98
+ // convert to JSON strings for easy comparison of normalized objects
99
+ const json1 = JSON.stringify(normalized1);
100
+ const json2 = JSON.stringify(normalized2);
101
+ const json3 = JSON.stringify(normalized3);
102
+
103
+ // assertions for normalization
104
+ iReckon(sir, json1).asTo("Objects with different key orders should normalize to the same string.").isGonnaBe(json2);
105
+ iReckon(sir, json1).asTo("Object with undefined should normalize to the same string as without that key.").isGonnaBe(json3);
106
+
107
+ // parse normalized strings back into objects and re-normalize
108
+ const parsedNormalized1 = toNormalizedForHashing(JSON.parse(json1));
109
+ const parsedNormalized2 = toNormalizedForHashing(JSON.parse(json2));
110
+ const parsedNormalized3 = toNormalizedForHashing(JSON.parse(json3));
111
+
112
+ // sanity check
113
+ iReckon(sir, parsedNormalized1).asTo("parsedNormalized1 truthy").isGonnaBeTruthy();
114
+ iReckon(sir, parsedNormalized2).asTo("parsedNormalized2 truthy").isGonnaBeTruthy();
115
+ iReckon(sir, parsedNormalized3).asTo("parsedNormalized3 truthy").isGonnaBeTruthy();
116
+
117
+ // check if re-normalized objects produce the same string as the original normalized objects
118
+ iReckon(sir, obj1.a).asTo("parsed object `a` property is the same as original object").isGonnaBe(parsedNormalized1["a"]);
119
+ iReckon(sir, JSON.stringify(parsedNormalized1) === json1).asTo("Re-normalized object should produce the same string as the original normalized object.").isGonnaBeTrue();
120
+ iReckon(sir, JSON.stringify(parsedNormalized2) === json2).asTo("Re-normalized object should produce the same string as the original normalized object.").isGonnaBeTrue();
121
+ iReckon(sir, JSON.stringify(parsedNormalized3) === json3).asTo("Re-normalized object should produce the same string as the original normalized object.").isGonnaBeTrue();
122
+ });
123
+
124
+ await ifWe(sir, `nested (sort and undefined)`, async () => {
125
+ // test with nested objects
126
+ const nested1 = { a: { z: 1, y: 2 }, b: 3, c: undefined };
127
+ const nested2 = { b: 3, a: { y: 2, z: 1 } };
128
+
129
+ // normalize nested objects
130
+ const normalizedNested1 = toNormalizedForHashing(nested1);
131
+ const normalizedNested2 = toNormalizedForHashing(nested2);
132
+
133
+ // compare the original and normalized objects' properties
134
+ iReckon(sir, normalizedNested1.a?.z).asTo("nested object `a.z` property is the same as original object").isGonnaBe(nested1.a.z);
135
+ iReckon(sir, normalizedNested1.a?.y).asTo("nested object `a.y` property is the same as original object").isGonnaBe(nested1.a.y);
136
+ iReckon(sir, normalizedNested1.b).asTo("nested object `b` property is the same as original object").isGonnaBe(nested1.b);
137
+ iReckon(sir, normalizedNested1.c).asTo("nested object `c` property is the same as original object").isGonnaBe(nested1.c);
138
+
139
+ // check if nested objects are normalized correctly
140
+ iReckon(sir, JSON.stringify(normalizedNested1)).asTo("Nested objects should normalize to the same string.").isGonnaBe(JSON.stringify(normalizedNested2));
141
+ });
142
+ });
@@ -2,7 +2,7 @@ import { readdir, open } from 'node:fs/promises';
2
2
  import { statSync } from 'node:fs';
3
3
  import * as pathUtils from 'path';
4
4
 
5
- import { pretty } from '@ibgib/helper-gib';
5
+ import { pretty } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
6
6
  import { getGlobalRespecGib } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
7
7
 
8
8
  // #region settings