@ibgib/ts-gib 0.5.27 → 0.5.28
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/V1/factory.d.mts +26 -1
- package/dist/V1/factory.d.mts.map +1 -1
- package/dist/V1/factory.mjs +97 -52
- package/dist/V1/factory.mjs.map +1 -1
- package/package.json +1 -1
- package/src/V1/factory.mts +117 -49
- package/src/V1/factory.respec.mts +44 -1
package/dist/V1/factory.d.mts
CHANGED
|
@@ -23,7 +23,7 @@ export declare class Factory_V1 {
|
|
|
23
23
|
*
|
|
24
24
|
* @returns The entire transform result object that includes the newly produced ibGib as well as any derivative/intermediate ibgibs.
|
|
25
25
|
*/
|
|
26
|
-
static firstGen<TData = any>({ ib, parentIbGib, data, rel8ns, dna, tjp, linkedRel8ns, noTimestamp, nCounter, }: {
|
|
26
|
+
static firstGen<TData = any>({ ib, parentIbGib, data, rel8ns, dna, tjp, linkedRel8ns, noTimestamp, nCounter, squash, }: {
|
|
27
27
|
ib: Ib;
|
|
28
28
|
parentIbGib: IbGib;
|
|
29
29
|
data?: TData;
|
|
@@ -31,8 +31,33 @@ export declare class Factory_V1 {
|
|
|
31
31
|
dna?: boolean;
|
|
32
32
|
tjp?: TemporalJunctionPointOptions;
|
|
33
33
|
linkedRel8ns?: string[];
|
|
34
|
+
/**
|
|
35
|
+
* If true, no timestamp will be
|
|
36
|
+
*/
|
|
34
37
|
noTimestamp?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* if true, data.n will be set to 0 on the first frame, and 1 on the
|
|
40
|
+
* second.
|
|
41
|
+
*/
|
|
35
42
|
nCounter?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* ONLY USED IF {@link dna} IS FALSY.
|
|
45
|
+
*
|
|
46
|
+
* If {@link dna} is falsy and this is true, then the resulting 1st gen
|
|
47
|
+
* ibgib will be squashed into a single frame, even if both mut8 and
|
|
48
|
+
* rel8 transforms are executed.
|
|
49
|
+
*
|
|
50
|
+
* ## intent / driving use case
|
|
51
|
+
*
|
|
52
|
+
* We are working on the new, production-quality v1 sync saga and we
|
|
53
|
+
* want the saga ibgib to be one frame per participant (Alice, Bob).
|
|
54
|
+
* So Alice creates one frame, then Bob evolves 1 frame, etc. No dna
|
|
55
|
+
* is required, because this is not meant to be merged at a later time.
|
|
56
|
+
*
|
|
57
|
+
* So the use case is when you don't need dna and you want a single
|
|
58
|
+
* frame.
|
|
59
|
+
*/
|
|
60
|
+
squash?: boolean;
|
|
36
61
|
}): Promise<TransformResult<IbGib_V1>>;
|
|
37
62
|
/**
|
|
38
63
|
* Generate an ibgib datum that has no dna and no timeline.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.mts","sourceRoot":"","sources":["../../src/V1/factory.mts"],"names":[],"mappings":"AAKA,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AACrG,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"factory.d.mts","sourceRoot":"","sources":["../../src/V1/factory.mts"],"names":[],"mappings":"AAKA,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AACrG,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAOrE,qBAAa,UAAU;IACnB,MAAM,CAAC,IAAI;IAIX;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,EACb,EAAE,EACL,EAAE;QACC,EAAE,EAAE,EAAE,CAAA;KACT,GAAG,QAAQ;IAIZ;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,EACd,GAAG,EACN,EAAE;QACC,GAAG,EAAE,EAAE,EAAE,CAAA;KACZ,GAAG,QAAQ,EAAE;IAId;;;;;OAKG;WAC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WACU,QAAQ,CACjB,KAAK,SAAS,YAAY,GAAG,GAAG,EAChC,OAAO,SAAS,cAAc,GAAG,cAAc,EACjD,EACE,iBAAiB,EACjB,EAAE,EACF,eAAe,EACf,IAAI,EACJ,MAAM,GACT,EAAE;QACC,iBAAiB,EAAE,EAAE,CAAC;QACtB,EAAE,EAAE,EAAE,CAAC;QACP;;WAEG;QACH,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,IAAI,CAAC,EAAE,KAAK,CAAC;QACb,MAAM,CAAC,EAAE,OAAO,CAAC;KACpB,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;CAkBxC"}
|
package/dist/V1/factory.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { getUUID } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
1
|
+
import { extractErrorMsg, getUUID } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
2
2
|
import { fork } from './transforms/fork.mjs';
|
|
3
3
|
import { mut8 } from './transforms/mut8.mjs';
|
|
4
4
|
import { rel8 } from './transforms/rel8.mjs';
|
|
5
5
|
import { IB, GIB, ROOT, IB_REGEXP_DEFAULT, FORBIDDEN_ADD_RENAME_REMOVE_REL8N_NAMES } from './constants.mjs';
|
|
6
6
|
import { validateIb } from './validate-helper.mjs';
|
|
7
7
|
import { getGib } from './transforms/transform-helper.mjs';
|
|
8
|
+
const logalot = false;
|
|
8
9
|
export class Factory_V1 {
|
|
9
10
|
static root() {
|
|
10
11
|
return Factory_V1.primitive({ ib: IB });
|
|
@@ -30,66 +31,110 @@ export class Factory_V1 {
|
|
|
30
31
|
*
|
|
31
32
|
* @returns The entire transform result object that includes the newly produced ibGib as well as any derivative/intermediate ibgibs.
|
|
32
33
|
*/
|
|
33
|
-
static async firstGen({ ib = IB, parentIbGib = Factory_V1.root(), data, rel8ns, dna, tjp, linkedRel8ns, noTimestamp, nCounter, }) {
|
|
34
|
+
static async firstGen({ ib = IB, parentIbGib = Factory_V1.root(), data, rel8ns, dna, tjp, linkedRel8ns, noTimestamp, nCounter, squash, }) {
|
|
34
35
|
const lc = `[${Factory_V1.name}][${Factory_V1.firstGen.name}]`;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
});
|
|
47
|
-
interimResults.push(resFork);
|
|
48
|
-
src = resFork.newIbGib;
|
|
49
|
-
if (data) {
|
|
50
|
-
let resMut8 = await mut8({
|
|
51
|
-
src,
|
|
52
|
-
dataToAddOrPatch: data,
|
|
53
|
-
dna,
|
|
54
|
-
linkedRel8ns,
|
|
55
|
-
noTimestamp,
|
|
56
|
-
nCounter,
|
|
57
|
-
});
|
|
58
|
-
interimResults.push(resMut8);
|
|
59
|
-
src = resMut8.newIbGib;
|
|
60
|
-
}
|
|
61
|
-
;
|
|
62
|
-
if (rel8ns) {
|
|
63
|
-
let resRel8 = await rel8({
|
|
36
|
+
try {
|
|
37
|
+
if (logalot) {
|
|
38
|
+
console.log(`${lc} starting... (I: b7152fbd94382516d9f7c591bcf4c326)`);
|
|
39
|
+
}
|
|
40
|
+
if (dna && squash) {
|
|
41
|
+
throw new Error(`both dna and squash cannot be true. Squash requires that no dna exist. (E: abfc58b4a4c8654924aa5428d0831826)`);
|
|
42
|
+
}
|
|
43
|
+
/** * Multiple transform steps will create multiple results. */
|
|
44
|
+
const interimResults = [];
|
|
45
|
+
let src = parentIbGib || ROOT;
|
|
46
|
+
let resFork = await fork({
|
|
64
47
|
src,
|
|
65
|
-
|
|
48
|
+
destIb: ib,
|
|
49
|
+
tjp,
|
|
66
50
|
dna,
|
|
67
51
|
linkedRel8ns,
|
|
68
52
|
noTimestamp,
|
|
69
53
|
nCounter,
|
|
70
54
|
});
|
|
71
|
-
interimResults.push(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
interimResults.
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
55
|
+
interimResults.push(resFork);
|
|
56
|
+
src = resFork.newIbGib;
|
|
57
|
+
if (data) {
|
|
58
|
+
let resMut8 = await mut8({
|
|
59
|
+
src,
|
|
60
|
+
dataToAddOrPatch: data,
|
|
61
|
+
dna,
|
|
62
|
+
linkedRel8ns,
|
|
63
|
+
noTimestamp,
|
|
64
|
+
nCounter,
|
|
65
|
+
});
|
|
66
|
+
interimResults.push(resMut8);
|
|
67
|
+
src = resMut8.newIbGib;
|
|
68
|
+
}
|
|
69
|
+
;
|
|
70
|
+
if (rel8ns) {
|
|
71
|
+
let resRel8 = await rel8({
|
|
72
|
+
src,
|
|
73
|
+
rel8nsToAddByAddr: rel8ns,
|
|
74
|
+
dna,
|
|
75
|
+
linkedRel8ns,
|
|
76
|
+
noTimestamp,
|
|
77
|
+
nCounter,
|
|
78
|
+
});
|
|
79
|
+
interimResults.push(resRel8);
|
|
80
|
+
// src = resRel8.newIbGib; // not needed because not used (this is the last step)
|
|
81
|
+
}
|
|
82
|
+
if (interimResults.length > 1) {
|
|
83
|
+
const newIbGib = interimResults.slice(interimResults.length - 1)[0].newIbGib;
|
|
84
|
+
const resultWithIntermediates = {
|
|
85
|
+
newIbGib,
|
|
86
|
+
/**
|
|
87
|
+
* all the interResults except the last one go in the intermediate ibGibs
|
|
88
|
+
*/
|
|
89
|
+
intermediateIbGibs: interimResults.slice(0, interimResults.length - 1).map(x => x.newIbGib),
|
|
90
|
+
};
|
|
91
|
+
if (dna) {
|
|
92
|
+
if (squash) {
|
|
93
|
+
(`${lc} (E: 62c595422e21ad8ce8eae658976fd826)`);
|
|
94
|
+
}
|
|
95
|
+
// combine all of the interim dnas
|
|
96
|
+
let dnas = [];
|
|
97
|
+
interimResults.forEach(res => { dnas = dnas.concat(res.dnas); });
|
|
98
|
+
resultWithIntermediates.dnas = dnas;
|
|
99
|
+
return resultWithIntermediates;
|
|
100
|
+
}
|
|
101
|
+
else if (squash) {
|
|
102
|
+
// manually remove past and change the tjp, if it exists
|
|
103
|
+
if (!newIbGib.rel8ns) {
|
|
104
|
+
throw new Error(`(UNEXPECTED) newIbGib.rel8ns is falsy? (E: 6b09e8057fc5b00c6cfd13be60e97f26)`);
|
|
105
|
+
}
|
|
106
|
+
delete newIbGib.rel8ns.past;
|
|
107
|
+
if (newIbGib.rel8ns.tjp) {
|
|
108
|
+
delete newIbGib.rel8ns.tjp;
|
|
109
|
+
newIbGib.data ??= {};
|
|
110
|
+
newIbGib.data.isTjp = true;
|
|
111
|
+
}
|
|
112
|
+
// recalculate the gib
|
|
113
|
+
newIbGib.gib = await getGib({ ibGib: newIbGib });
|
|
114
|
+
const resultSquashed = { newIbGib };
|
|
115
|
+
return resultSquashed;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// no dna and no squash
|
|
119
|
+
return resultWithIntermediates;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else if (interimResults.length === 1) {
|
|
123
|
+
// for some reason the caller just used this as a fork.
|
|
124
|
+
return interimResults[0];
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
throw new Error(`(UNEXPECTED) interimResults.length is not 1 and not greater than 1? 0? But we had to fork? (E: a256c88c56916a46a888796f76ef4826)`);
|
|
128
|
+
}
|
|
86
129
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
130
|
+
catch (error) {
|
|
131
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
132
|
+
throw error;
|
|
90
133
|
}
|
|
91
|
-
|
|
92
|
-
|
|
134
|
+
finally {
|
|
135
|
+
if (logalot) {
|
|
136
|
+
console.log(`${lc} complete.`);
|
|
137
|
+
}
|
|
93
138
|
}
|
|
94
139
|
}
|
|
95
140
|
/**
|
package/dist/V1/factory.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.mjs","sourceRoot":"","sources":["../../src/V1/factory.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iDAAiD,CAAC;
|
|
1
|
+
{"version":3,"file":"factory.mjs","sourceRoot":"","sources":["../../src/V1/factory.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,iDAAiD,CAAC;AAE3F,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAG7C,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,iBAAiB,EAAE,uCAAuC,EAAE,MAAM,iBAAiB,CAAC;AAC5G,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAE3D,MAAM,OAAO,GAAG,KAAK,CAAC;AAEtB,MAAM,OAAO,UAAU;IACnB,MAAM,CAAC,IAAI;QACP,OAAO,UAAU,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,EACb,EAAE,EAGL;QACG,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,EACd,GAAG,EAGN;QACG,OAAO,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IACvD,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAc,EAC/B,EAA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;;;;;;OA8BG;IACH,MAAM,CAAC,KAAK,CAAC,QAAQ,CAGnB,EACE,iBAAiB,EACjB,EAAE,EACF,eAAe,EACf,IAAI,EACJ,MAAM,GAUT;QACG,MAAM,EAAE,GAAG,IAAI,UAAU,CAAC,IAAI,KAAK,UAAU,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC;QAC/D,IAAI,CAAC;YACD,MAAM,aAAa,GAAG,MAAM,UAAU,CAAC,KAAK,CAAC;gBACzC,iBAAiB;gBACjB,EAAE;gBACF,eAAe;gBACf,IAAI;gBACJ,MAAM;gBACN,WAAW,EAAE,IAAI;gBACjB,IAAI,EAAE,KAAK;aACd,CAAC,CAAC;YACH,OAAO,aAAa,CAAC;QACzB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YACxC,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ibgib/ts-gib",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.28",
|
|
4
4
|
"description": "ibgib library with low-level graphing-related substrate functionality, e.g. creating raw ibgibs and transformations. node19+ needed for heavily-used webcrypto hashing isomorphically consumed in node and browsers (apps).",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "https://gitlab.com/ibgib/ts-gib",
|
package/src/V1/factory.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getUUID } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
1
|
+
import { extractErrorMsg, getUUID } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
2
2
|
|
|
3
3
|
import { fork } from './transforms/fork.mjs';
|
|
4
4
|
import { mut8 } from './transforms/mut8.mjs';
|
|
@@ -9,6 +9,8 @@ import { IB, GIB, ROOT, IB_REGEXP_DEFAULT, FORBIDDEN_ADD_RENAME_REMOVE_REL8N_NAM
|
|
|
9
9
|
import { validateIb } from './validate-helper.mjs';
|
|
10
10
|
import { getGib } from './transforms/transform-helper.mjs';
|
|
11
11
|
|
|
12
|
+
const logalot = false;
|
|
13
|
+
|
|
12
14
|
export class Factory_V1 {
|
|
13
15
|
static root() {
|
|
14
16
|
return Factory_V1.primitive({ ib: IB });
|
|
@@ -55,6 +57,7 @@ export class Factory_V1 {
|
|
|
55
57
|
linkedRel8ns,
|
|
56
58
|
noTimestamp,
|
|
57
59
|
nCounter,
|
|
60
|
+
squash,
|
|
58
61
|
}: {
|
|
59
62
|
ib: Ib,
|
|
60
63
|
parentIbGib: IbGib,
|
|
@@ -63,68 +66,133 @@ export class Factory_V1 {
|
|
|
63
66
|
dna?: boolean,
|
|
64
67
|
tjp?: TemporalJunctionPointOptions;
|
|
65
68
|
linkedRel8ns?: string[],
|
|
69
|
+
/**
|
|
70
|
+
* If true, no timestamp will be
|
|
71
|
+
*/
|
|
66
72
|
noTimestamp?: boolean,
|
|
73
|
+
/**
|
|
74
|
+
* if true, data.n will be set to 0 on the first frame, and 1 on the
|
|
75
|
+
* second.
|
|
76
|
+
*/
|
|
67
77
|
nCounter?: boolean,
|
|
78
|
+
/**
|
|
79
|
+
* ONLY USED IF {@link dna} IS FALSY.
|
|
80
|
+
*
|
|
81
|
+
* If {@link dna} is falsy and this is true, then the resulting 1st gen
|
|
82
|
+
* ibgib will be squashed into a single frame, even if both mut8 and
|
|
83
|
+
* rel8 transforms are executed.
|
|
84
|
+
*
|
|
85
|
+
* ## intent / driving use case
|
|
86
|
+
*
|
|
87
|
+
* We are working on the new, production-quality v1 sync saga and we
|
|
88
|
+
* want the saga ibgib to be one frame per participant (Alice, Bob).
|
|
89
|
+
* So Alice creates one frame, then Bob evolves 1 frame, etc. No dna
|
|
90
|
+
* is required, because this is not meant to be merged at a later time.
|
|
91
|
+
*
|
|
92
|
+
* So the use case is when you don't need dna and you want a single
|
|
93
|
+
* frame.
|
|
94
|
+
*/
|
|
95
|
+
squash?: boolean,
|
|
68
96
|
}): Promise<TransformResult<IbGib_V1>> {
|
|
69
97
|
const lc = `[${Factory_V1.name}][${Factory_V1.firstGen.name}]`;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
let src: IbGib_V1 = parentIbGib || ROOT;
|
|
73
|
-
let resFork = await fork({
|
|
74
|
-
src,
|
|
75
|
-
destIb: ib,
|
|
76
|
-
tjp,
|
|
77
|
-
dna,
|
|
78
|
-
linkedRel8ns,
|
|
79
|
-
noTimestamp,
|
|
80
|
-
nCounter,
|
|
81
|
-
});
|
|
82
|
-
interimResults.push(resFork);
|
|
83
|
-
src = resFork.newIbGib;
|
|
98
|
+
try {
|
|
99
|
+
if (logalot) { console.log(`${lc} starting... (I: b7152fbd94382516d9f7c591bcf4c326)`); }
|
|
84
100
|
|
|
85
|
-
|
|
86
|
-
let resMut8 = await mut8({
|
|
87
|
-
src,
|
|
88
|
-
dataToAddOrPatch: data,
|
|
89
|
-
dna,
|
|
90
|
-
linkedRel8ns,
|
|
91
|
-
noTimestamp,
|
|
92
|
-
nCounter,
|
|
93
|
-
});
|
|
94
|
-
interimResults.push(resMut8);
|
|
95
|
-
src = resMut8.newIbGib;
|
|
96
|
-
};
|
|
101
|
+
if (dna && squash) { throw new Error(`both dna and squash cannot be true. Squash requires that no dna exist. (E: abfc58b4a4c8654924aa5428d0831826)`); }
|
|
97
102
|
|
|
98
|
-
|
|
99
|
-
|
|
103
|
+
/** * Multiple transform steps will create multiple results. */
|
|
104
|
+
const interimResults: TransformResult<IbGib_V1>[] = [];
|
|
105
|
+
let src: IbGib_V1 = parentIbGib || ROOT;
|
|
106
|
+
let resFork = await fork({
|
|
100
107
|
src,
|
|
101
|
-
|
|
108
|
+
destIb: ib,
|
|
109
|
+
tjp,
|
|
102
110
|
dna,
|
|
103
111
|
linkedRel8ns,
|
|
104
112
|
noTimestamp,
|
|
105
113
|
nCounter,
|
|
106
114
|
});
|
|
107
|
-
interimResults.push(
|
|
108
|
-
|
|
109
|
-
|
|
115
|
+
interimResults.push(resFork);
|
|
116
|
+
src = resFork.newIbGib;
|
|
117
|
+
|
|
118
|
+
if (data) {
|
|
119
|
+
let resMut8 = await mut8({
|
|
120
|
+
src,
|
|
121
|
+
dataToAddOrPatch: data,
|
|
122
|
+
dna,
|
|
123
|
+
linkedRel8ns,
|
|
124
|
+
noTimestamp,
|
|
125
|
+
nCounter,
|
|
126
|
+
});
|
|
127
|
+
interimResults.push(resMut8);
|
|
128
|
+
src = resMut8.newIbGib;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
if (rel8ns) {
|
|
132
|
+
let resRel8 = await rel8({
|
|
133
|
+
src,
|
|
134
|
+
rel8nsToAddByAddr: rel8ns,
|
|
135
|
+
dna,
|
|
136
|
+
linkedRel8ns,
|
|
137
|
+
noTimestamp,
|
|
138
|
+
nCounter,
|
|
139
|
+
});
|
|
140
|
+
interimResults.push(resRel8);
|
|
141
|
+
// src = resRel8.newIbGib; // not needed because not used (this is the last step)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (interimResults.length > 1) {
|
|
145
|
+
const newIbGib = interimResults.slice(interimResults.length - 1)[0].newIbGib;
|
|
146
|
+
const resultWithIntermediates = {
|
|
147
|
+
newIbGib,
|
|
148
|
+
/**
|
|
149
|
+
* all the interResults except the last one go in the intermediate ibGibs
|
|
150
|
+
*/
|
|
151
|
+
intermediateIbGibs: interimResults.slice(0, interimResults.length - 1).map(x => x.newIbGib),
|
|
152
|
+
} as TransformResult<IbGib_V1>;
|
|
153
|
+
|
|
154
|
+
if (dna) {
|
|
155
|
+
if (squash) { (`${lc} (E: 62c595422e21ad8ce8eae658976fd826)`) }
|
|
156
|
+
|
|
157
|
+
// combine all of the interim dnas
|
|
158
|
+
let dnas: IbGib_V1[] = [];
|
|
159
|
+
interimResults.forEach(res => { dnas = dnas.concat(res.dnas!); });
|
|
160
|
+
resultWithIntermediates.dnas = dnas;
|
|
110
161
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
162
|
+
return resultWithIntermediates;
|
|
163
|
+
} else if (squash) {
|
|
164
|
+
// manually remove past and change the tjp, if it exists
|
|
165
|
+
if (!newIbGib.rel8ns) { throw new Error(`(UNEXPECTED) newIbGib.rel8ns is falsy? (E: 6b09e8057fc5b00c6cfd13be60e97f26)`); }
|
|
166
|
+
|
|
167
|
+
delete newIbGib.rel8ns.past;
|
|
168
|
+
|
|
169
|
+
if (newIbGib.rel8ns.tjp) {
|
|
170
|
+
delete newIbGib.rel8ns.tjp;
|
|
171
|
+
newIbGib.data ??= {};
|
|
172
|
+
newIbGib.data.isTjp = true;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// recalculate the gib
|
|
176
|
+
newIbGib.gib = await getGib({ ibGib: newIbGib });
|
|
177
|
+
|
|
178
|
+
const resultSquashed: TransformResult<IbGib_V1> = { newIbGib };
|
|
179
|
+
|
|
180
|
+
return resultSquashed;
|
|
181
|
+
} else {
|
|
182
|
+
// no dna and no squash
|
|
183
|
+
return resultWithIntermediates;
|
|
184
|
+
}
|
|
185
|
+
} else if (interimResults.length === 1) {
|
|
186
|
+
// for some reason the caller just used this as a fork.
|
|
187
|
+
return interimResults[0];
|
|
188
|
+
} else {
|
|
189
|
+
throw new Error(`(UNEXPECTED) interimResults.length is not 1 and not greater than 1? 0? But we had to fork? (E: a256c88c56916a46a888796f76ef4826)`);
|
|
121
190
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
throw new Error(`${lc} hmm, I'm not sure...`);
|
|
191
|
+
} catch (error) {
|
|
192
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
193
|
+
throw error;
|
|
194
|
+
} finally {
|
|
195
|
+
if (logalot) { console.log(`${lc} complete.`); }
|
|
128
196
|
}
|
|
129
197
|
}
|
|
130
198
|
|
|
@@ -5,7 +5,7 @@ import { ROOT, } from './constants.mjs';
|
|
|
5
5
|
import { Factory_V1 as factory } from './factory.mjs';
|
|
6
6
|
import { sha256v1 } from './sha256v1.mjs';
|
|
7
7
|
import { getGib, getGibInfo } from './transforms/transform-helper.mjs';
|
|
8
|
-
import { firstOfAll, ifWe, iReckon, respecfully } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
|
|
8
|
+
import { firstOfAll, ifWe, ifWeMight, iReckon, respecfully } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
|
|
9
9
|
const maam = `[${import.meta.url}]`, sir = maam;
|
|
10
10
|
|
|
11
11
|
const PRIMITIVE_IBS: string[] = [
|
|
@@ -91,6 +91,49 @@ await respecfully(sir, `when using factory`, async () => {
|
|
|
91
91
|
iReckon(sir, intermediateIbGibs![1].ib).isGonnaBe(testIb);
|
|
92
92
|
});
|
|
93
93
|
|
|
94
|
+
await respecfully(sir, `squash param`, async () => {
|
|
95
|
+
await ifWe(sir, `should throw if both dna and squash are true`, async () => {
|
|
96
|
+
let errorMsg;
|
|
97
|
+
try {
|
|
98
|
+
await factory.firstGen({
|
|
99
|
+
ib: 'squash_dna_fail',
|
|
100
|
+
parentIbGib: ROOT,
|
|
101
|
+
dna: true,
|
|
102
|
+
squash: true,
|
|
103
|
+
});
|
|
104
|
+
} catch (e: any) { errorMsg = e.message; }
|
|
105
|
+
iReckon(sir, errorMsg).asTo('errorMsg').isGonnaBeTruthy();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
await ifWe(sir, `should squash simple fork+mut8 into single frame`, async () => {
|
|
109
|
+
const { newIbGib, intermediateIbGibs } = await factory.firstGen({
|
|
110
|
+
ib: 'squash_it',
|
|
111
|
+
parentIbGib: ROOT,
|
|
112
|
+
data: DATA_SIMPLE_XY,
|
|
113
|
+
squash: true,
|
|
114
|
+
noTimestamp: true,
|
|
115
|
+
});
|
|
116
|
+
iReckon(sir, newIbGib).isGonnaBeTruthy();
|
|
117
|
+
iReckon(sir, newIbGib.data).isGonnaBe(DATA_SIMPLE_XY);
|
|
118
|
+
// should nuke past
|
|
119
|
+
iReckon(sir, newIbGib.rel8ns!.past).isGonnaBeUndefined();
|
|
120
|
+
// should not return intermediates
|
|
121
|
+
iReckon(sir, intermediateIbGibs).isGonnaBeUndefined();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
await ifWe(sir, `should handle tjp (remove rel8n, add data.isTjp)`, async () => {
|
|
125
|
+
const { newIbGib } = await factory.firstGen({
|
|
126
|
+
ib: 'squash_tjp',
|
|
127
|
+
parentIbGib: ROOT,
|
|
128
|
+
data: DATA_SIMPLE_XY,
|
|
129
|
+
squash: true,
|
|
130
|
+
tjp: { timestamp: true }
|
|
131
|
+
});
|
|
132
|
+
iReckon(sir, newIbGib.rel8ns!.tjp).isGonnaBeUndefined();
|
|
133
|
+
iReckon(sir, newIbGib.data!.isTjp).isGonnaBeTruthy();
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
94
137
|
|
|
95
138
|
|
|
96
139
|
});
|