@ibgib/ts-gib 0.4.9
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/.vscode/launch.json +24 -0
- package/.vscode/settings.json +34 -0
- package/.vscode/tasks.json +37 -0
- package/CHANGELOG.md +159 -0
- package/README.md +502 -0
- package/dist/V1/constants.d.mts +22 -0
- package/dist/V1/constants.d.mts.map +1 -0
- package/dist/V1/constants.mjs +21 -0
- package/dist/V1/constants.mjs.map +1 -0
- package/dist/V1/factory.d.mts +23 -0
- package/dist/V1/factory.d.mts.map +1 -0
- package/dist/V1/factory.mjs +78 -0
- package/dist/V1/factory.mjs.map +1 -0
- package/dist/V1/index.d.mts +6 -0
- package/dist/V1/index.d.mts.map +1 -0
- package/dist/V1/index.mjs +6 -0
- package/dist/V1/index.mjs.map +1 -0
- package/dist/V1/sha256v1.d.mts +19 -0
- package/dist/V1/sha256v1.d.mts.map +1 -0
- package/dist/V1/sha256v1.mjs +86 -0
- package/dist/V1/sha256v1.mjs.map +1 -0
- package/dist/V1/transforms/fork.d.mts +16 -0
- package/dist/V1/transforms/fork.d.mts.map +1 -0
- package/dist/V1/transforms/fork.mjs +111 -0
- package/dist/V1/transforms/fork.mjs.map +1 -0
- package/dist/V1/transforms/index.d.mts +5 -0
- package/dist/V1/transforms/index.d.mts.map +1 -0
- package/dist/V1/transforms/index.mjs +5 -0
- package/dist/V1/transforms/index.mjs.map +1 -0
- package/dist/V1/transforms/mut8.d.mts +50 -0
- package/dist/V1/transforms/mut8.d.mts.map +1 -0
- package/dist/V1/transforms/mut8.mjs +246 -0
- package/dist/V1/transforms/mut8.mjs.map +1 -0
- package/dist/V1/transforms/rel8.d.mts +14 -0
- package/dist/V1/transforms/rel8.d.mts.map +1 -0
- package/dist/V1/transforms/rel8.mjs +176 -0
- package/dist/V1/transforms/rel8.mjs.map +1 -0
- package/dist/V1/transforms/transform-helper.d.mts +92 -0
- package/dist/V1/transforms/transform-helper.d.mts.map +1 -0
- package/dist/V1/transforms/transform-helper.mjs +189 -0
- package/dist/V1/transforms/transform-helper.mjs.map +1 -0
- package/dist/V1/types.d.mts +79 -0
- package/dist/V1/types.d.mts.map +1 -0
- package/dist/V1/types.mjs +12 -0
- package/dist/V1/types.mjs.map +1 -0
- package/dist/helper.d.mts +77 -0
- package/dist/helper.d.mts.map +1 -0
- package/dist/helper.mjs +179 -0
- package/dist/helper.mjs.map +1 -0
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types.d.mts +242 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +2 -0
- package/dist/types.mjs.map +1 -0
- package/jasmine-browser.json +18 -0
- package/jasmine.json +6 -0
- package/package.json +61 -0
- package/src/V1/constants.mts +23 -0
- package/src/V1/factory.mts +110 -0
- package/src/V1/factory.spec.mts +162 -0
- package/src/V1/index.mts +5 -0
- package/src/V1/sha256v1.mts +85 -0
- package/src/V1/sha256v1.spec.mts +221 -0
- package/src/V1/transforms/fork.mts +100 -0
- package/src/V1/transforms/fork.spec.mts +410 -0
- package/src/V1/transforms/index.mts +4 -0
- package/src/V1/transforms/mut8.mts +239 -0
- package/src/V1/transforms/mut8.spec.mts +656 -0
- package/src/V1/transforms/rel8.mts +173 -0
- package/src/V1/transforms/rel8.spec.mts +556 -0
- package/src/V1/transforms/transform-helper.mts +263 -0
- package/src/V1/transforms/transform-helper.spec.mts +45 -0
- package/src/V1/types.mts +84 -0
- package/src/helper.mts +192 -0
- package/src/helper.spec.mts +127 -0
- package/src/index.cts +3 -0
- package/src/index.mts +3 -0
- package/src/types.mts +242 -0
- package/tsconfig.json +15 -0
- package/tsconfig.test.json +10 -0
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test basic mut8 transforms.
|
|
3
|
+
*
|
|
4
|
+
* NOTE:
|
|
5
|
+
* This only tests the node implementation, and manual testing
|
|
6
|
+
* is required for browser until I get some kind of browser testing
|
|
7
|
+
* going.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { IbGib_V1, IbGibRel8ns_V1, Rel8n } from '../types.mjs';
|
|
11
|
+
import { TransformOpts_Rel8, IbGibAddr, IbGibRel8ns } from '../../types.mjs';
|
|
12
|
+
import { pretty, clone, delay, getIbGibAddr, getIbAndGib } from '../../helper.mjs';
|
|
13
|
+
import { ROOT, ROOT_ADDR } from '../constants.mjs';
|
|
14
|
+
import { fork } from './fork.mjs';
|
|
15
|
+
// import { mut8 } from './mut8.mjs';
|
|
16
|
+
import { rel8 } from './rel8.mjs';
|
|
17
|
+
import { Factory_V1 as factory } from '../factory.mjs';
|
|
18
|
+
import { getGib, getGibInfo } from './transform-helper.mjs';
|
|
19
|
+
import { sha256v1 } from '../sha256v1.mjs';
|
|
20
|
+
|
|
21
|
+
const PRIMITIVE_IBGIBS = [
|
|
22
|
+
factory.root(),
|
|
23
|
+
...factory.primitives({
|
|
24
|
+
ibs: [
|
|
25
|
+
'a', '7', 'tag',
|
|
26
|
+
'any string/value that isnt hashed with a gib is a primitive',
|
|
27
|
+
// e.g. 6 -> 6^ -> 6^gib are all equivalent ib^gib addresses,
|
|
28
|
+
]
|
|
29
|
+
}),
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const STR = 'string here';
|
|
33
|
+
const RENAME_ME_KEY = 'rename me please';
|
|
34
|
+
const RENAMED_KEY = 'renamed successfully';
|
|
35
|
+
const RENAME_VALUE = 'hey heres a value';
|
|
36
|
+
const DATA_SIMPLE_XY = { x: 1, y: 2 };
|
|
37
|
+
const DATA_SIMPLE_XY_STR = { x: 1, y: 2, str: STR };
|
|
38
|
+
const DATA_COMPLEX_XY_NESTED = {
|
|
39
|
+
xyObj: DATA_SIMPLE_XY,
|
|
40
|
+
nested1: { [RENAME_ME_KEY]: RENAME_VALUE },
|
|
41
|
+
};
|
|
42
|
+
const NEW_IB = 'new ib here yo';
|
|
43
|
+
|
|
44
|
+
const DATAS_SIMPLE = [
|
|
45
|
+
DATA_SIMPLE_XY,
|
|
46
|
+
DATA_SIMPLE_XY_STR,
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
const SIMPLE_REL8N_NAMES: string[] = [
|
|
50
|
+
// just some possible example rel8n names
|
|
51
|
+
'child', 'container', 'folder', 'identity', 'tag', 'liked'
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Generates a simple rel8ns to Add/Remove mapping from the given rel8nNames.
|
|
56
|
+
*
|
|
57
|
+
* @param rel8nNames list of rel8nnames that will be mapped to all of the sample test primitives
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* For example, if you pass in ['child', 'tag'], then this will build an object
|
|
61
|
+
* from PRIMITIVE_IBGIBS.
|
|
62
|
+
* {
|
|
63
|
+
* child: ['ib^gib', 'a^gib', '7^gib', 'tag^gib'...],
|
|
64
|
+
* tag: ['ib^gib', 'a^gib', '7^gib', 'tag^gib'...],
|
|
65
|
+
* }
|
|
66
|
+
*/
|
|
67
|
+
function buildRel8nsToAddOrRemoveFromPrimitives(rel8nNames: string[]): IbGibRel8ns {
|
|
68
|
+
const result: IbGibRel8ns = {};
|
|
69
|
+
rel8nNames.forEach(rel8nName => {
|
|
70
|
+
result[rel8nName] = PRIMITIVE_IBGIBS.map(x => getIbGibAddr({ ibGib: x }));
|
|
71
|
+
});
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
describe(`can't rel8 primitives to others`, () => {
|
|
76
|
+
for (const src of PRIMITIVE_IBGIBS) {
|
|
77
|
+
|
|
78
|
+
it(`should fail to add rel8ns`, async () => {
|
|
79
|
+
let errored = false;
|
|
80
|
+
try {
|
|
81
|
+
const rel8nsToAddByAddr = buildRel8nsToAddOrRemoveFromPrimitives(SIMPLE_REL8N_NAMES);
|
|
82
|
+
const _ignored = await rel8({ src, rel8nsToAddByAddr });
|
|
83
|
+
} catch (error) {
|
|
84
|
+
errored = true;
|
|
85
|
+
}
|
|
86
|
+
expect(errored).toBeTrue()
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it(`should fail to remove rel8ns`, async () => {
|
|
90
|
+
let errored = false;
|
|
91
|
+
try {
|
|
92
|
+
const rel8nsToRemoveByAddr = buildRel8nsToAddOrRemoveFromPrimitives(SIMPLE_REL8N_NAMES);
|
|
93
|
+
const _ignored = await rel8({ src, rel8nsToRemoveByAddr });
|
|
94
|
+
} catch (error) {
|
|
95
|
+
errored = true;
|
|
96
|
+
}
|
|
97
|
+
expect(errored).toBeTrue()
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it(`should fail to add and remove rel8ns`, async () => {
|
|
101
|
+
let errored = false;
|
|
102
|
+
try {
|
|
103
|
+
const rel8nsToAddByAddr =
|
|
104
|
+
buildRel8nsToAddOrRemoveFromPrimitives(SIMPLE_REL8N_NAMES);
|
|
105
|
+
const rel8nsToRemoveByAddr =
|
|
106
|
+
buildRel8nsToAddOrRemoveFromPrimitives([SIMPLE_REL8N_NAMES[0]]); // just the first, no real reason
|
|
107
|
+
const _ignored = await rel8({ src, rel8nsToAddByAddr, rel8nsToRemoveByAddr });
|
|
108
|
+
} catch (error) {
|
|
109
|
+
errored = true;
|
|
110
|
+
}
|
|
111
|
+
expect(errored).toBeTrue()
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe(`when rel8ing a regular ibgib`, () => {
|
|
118
|
+
|
|
119
|
+
describe(`simple rel8ns to 1st gens (from primitives)`, () => {
|
|
120
|
+
for (const primitive of PRIMITIVE_IBGIBS) {
|
|
121
|
+
|
|
122
|
+
it(`should add/remove simple rel8ns`, async () => {
|
|
123
|
+
|
|
124
|
+
let { newIbGib: src } = await fork({ src: primitive, noTimestamp: true });
|
|
125
|
+
|
|
126
|
+
// #region add rel8ns
|
|
127
|
+
|
|
128
|
+
const rel8nsToAddByAddr = buildRel8nsToAddOrRemoveFromPrimitives(SIMPLE_REL8N_NAMES);
|
|
129
|
+
|
|
130
|
+
// we now have a non-primitive 1st gen source and wish to
|
|
131
|
+
// add rel8ns in it pointing to other ibGibs.
|
|
132
|
+
|
|
133
|
+
const { newIbGib: rel8nsAddedIbGib } =
|
|
134
|
+
await rel8({ src, rel8nsToAddByAddr, noTimestamp: true });
|
|
135
|
+
expect(rel8nsAddedIbGib).toBeTruthy();
|
|
136
|
+
expect(rel8nsAddedIbGib.rel8ns).toBeTruthy();
|
|
137
|
+
expect(rel8nsAddedIbGib.rel8ns).toBeTruthy();
|
|
138
|
+
const rel8nNames_AddedIbGib = Object.keys(rel8nsAddedIbGib.rel8ns!);
|
|
139
|
+
SIMPLE_REL8N_NAMES.forEach(simpleRel8nName => {
|
|
140
|
+
expect(rel8nNames_AddedIbGib).toContain(simpleRel8nName);
|
|
141
|
+
const simpleRel8nAddrs = rel8nsAddedIbGib.rel8ns![simpleRel8nName]!;
|
|
142
|
+
// expect(simpleRel8nAddrs).not.toHaveSize(0);
|
|
143
|
+
expect(simpleRel8nAddrs).not.toHaveSize(0);
|
|
144
|
+
const expectedRel8nAddrs = rel8nsToAddByAddr[simpleRel8nName];
|
|
145
|
+
expect(expectedRel8nAddrs).not.toHaveSize(0);
|
|
146
|
+
expect(simpleRel8nAddrs).toEqual(expectedRel8nAddrs!);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// #endregion
|
|
150
|
+
|
|
151
|
+
// #region Remove rel8ns
|
|
152
|
+
|
|
153
|
+
const rel8nsToRemoveByAddr: IbGibRel8ns = {};
|
|
154
|
+
SIMPLE_REL8N_NAMES.forEach(x => rel8nsToRemoveByAddr[x] = [
|
|
155
|
+
ROOT_ADDR, 'tag^gib'
|
|
156
|
+
]);
|
|
157
|
+
|
|
158
|
+
const { newIbGib: rel8nsRemovedIbGib } =
|
|
159
|
+
await rel8({ src: rel8nsAddedIbGib, rel8nsToRemoveByAddr, noTimestamp: true });
|
|
160
|
+
expect(rel8nsRemovedIbGib).toBeTruthy();
|
|
161
|
+
expect(rel8nsRemovedIbGib.rel8ns).toBeTruthy();
|
|
162
|
+
expect(rel8nsRemovedIbGib.rel8ns).toBeTruthy();
|
|
163
|
+
|
|
164
|
+
SIMPLE_REL8N_NAMES.forEach(simpleRel8nName => {
|
|
165
|
+
const rel8dAddrs = rel8nsRemovedIbGib.rel8ns![simpleRel8nName]!;
|
|
166
|
+
// expect(rel8dAddrs).not.toContain(to.not.include.any.members([ROOT_ADDR, 'tag^gib']);
|
|
167
|
+
[ROOT_ADDR, 'tag^gib'].forEach(x => { expect(rel8dAddrs).not.toContain(x); })
|
|
168
|
+
|
|
169
|
+
// expect(rel8dAddrs).to.include.all.members(
|
|
170
|
+
// PRIMITIVE_IBGIBS
|
|
171
|
+
// .map(x => getIbGibAddr({ ibGib: x }))
|
|
172
|
+
// .filter(addr => addr !== ROOT_ADDR && addr !== 'tag^gib')
|
|
173
|
+
// );
|
|
174
|
+
PRIMITIVE_IBGIBS
|
|
175
|
+
.map(x => getIbGibAddr({ ibGib: x }))
|
|
176
|
+
.filter(addr => addr !== ROOT_ADDR && addr !== 'tag^gib')
|
|
177
|
+
.forEach(x => expect(rel8dAddrs).toContain(x));
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
//#endregion
|
|
181
|
+
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* we're going to perform the same transforms to two different, unique sources.
|
|
186
|
+
* (in this case, differentiated by the ib).
|
|
187
|
+
* for the src1, we're going to execute transforms via the normal calls.
|
|
188
|
+
* then for src2, we'll make the call from the dna generated from the src1 transforms.
|
|
189
|
+
* both should make the same transformations with regards to the rel8ns added/removed.
|
|
190
|
+
*/
|
|
191
|
+
it(`should create pure, reproducible dna`, async () => {
|
|
192
|
+
|
|
193
|
+
const ib1 = 'ib 1 yo';
|
|
194
|
+
let { newIbGib: src1 } = await fork({ src: primitive, noTimestamp: true, destIb: ib1 });
|
|
195
|
+
const ib2 = 'ib 2 here';
|
|
196
|
+
let { newIbGib: src2 } = await fork({ src: primitive, noTimestamp: true, destIb: ib2 });
|
|
197
|
+
const src2Addr = getIbGibAddr({ ibGib: src2 });
|
|
198
|
+
|
|
199
|
+
// #region add rel8ns
|
|
200
|
+
|
|
201
|
+
const rel8nsToAddByAddr = buildRel8nsToAddOrRemoveFromPrimitives(SIMPLE_REL8N_NAMES);
|
|
202
|
+
|
|
203
|
+
// we now have a non-primitive 1st gen source and wish to
|
|
204
|
+
// add rel8ns in it pointing to other ibGibs.
|
|
205
|
+
|
|
206
|
+
const { newIbGib: rel8nsAddedIbGib, intermediateIbGibs, dnas: dnasRel8Add } =
|
|
207
|
+
await rel8({ src: src1, rel8nsToAddByAddr, noTimestamp: true, dna: true });
|
|
208
|
+
expect(dnasRel8Add).toBeTruthy();
|
|
209
|
+
expect(dnasRel8Add).toBeTruthy();
|
|
210
|
+
// ATOW dna only produces 1
|
|
211
|
+
const rel8DnaAdd = dnasRel8Add![0];
|
|
212
|
+
const rel8DnaDataAdd: TransformOpts_Rel8<IbGib_V1> = clone(rel8DnaAdd.data!);
|
|
213
|
+
const rel8nNames_AddedIbGib = Object.keys(rel8nsAddedIbGib.rel8ns!);
|
|
214
|
+
SIMPLE_REL8N_NAMES.forEach(simpleRel8nName => {
|
|
215
|
+
expect(rel8nNames_AddedIbGib).toContain(simpleRel8nName);
|
|
216
|
+
const simpleRel8nAddrs = rel8nsAddedIbGib.rel8ns![simpleRel8nName]!;
|
|
217
|
+
expect(simpleRel8nAddrs).not.toHaveSize(0);
|
|
218
|
+
const expectedRel8nAddrs = rel8nsToAddByAddr[simpleRel8nName];
|
|
219
|
+
expect(expectedRel8nAddrs).not.toHaveSize(0);
|
|
220
|
+
expect(simpleRel8nAddrs).toEqual(expectedRel8nAddrs!);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
// rerun the same rel8 call, but get the args from the dna of the
|
|
224
|
+
// previous call. Then check to ensure the same rel8ns were added.
|
|
225
|
+
|
|
226
|
+
rel8DnaDataAdd.src = src2;
|
|
227
|
+
rel8DnaDataAdd.srcAddr = src2Addr;
|
|
228
|
+
const { newIbGib: rel8nsAddedIbGib2, dnas: _dnasRel8Add2 } =
|
|
229
|
+
await rel8(rel8DnaDataAdd);
|
|
230
|
+
const rel8nNames_AddedIbGib2 = Object.keys(rel8nsAddedIbGib2.rel8ns!);
|
|
231
|
+
SIMPLE_REL8N_NAMES.forEach(simpleRel8nName => {
|
|
232
|
+
expect(rel8nNames_AddedIbGib2).toContain(simpleRel8nName);
|
|
233
|
+
const simpleRel8nAddrs = rel8nsAddedIbGib2.rel8ns![simpleRel8nName]!;
|
|
234
|
+
expect(simpleRel8nAddrs).not.toHaveSize(0);
|
|
235
|
+
const expectedRel8nAddrs = rel8nsToAddByAddr[simpleRel8nName];
|
|
236
|
+
expect(expectedRel8nAddrs).not.toHaveSize(0);
|
|
237
|
+
expect(simpleRel8nAddrs).toEqual(expectedRel8nAddrs!);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// #endregion
|
|
241
|
+
|
|
242
|
+
// #region Remove rel8ns
|
|
243
|
+
|
|
244
|
+
const rel8nsToRemoveByAddr: IbGibRel8ns = {};
|
|
245
|
+
SIMPLE_REL8N_NAMES.forEach(x => rel8nsToRemoveByAddr[x] = [
|
|
246
|
+
ROOT_ADDR, 'tag^gib'
|
|
247
|
+
]);
|
|
248
|
+
|
|
249
|
+
const { newIbGib: rel8nsRemovedIbGib, dnas: dnasRel8Remove } =
|
|
250
|
+
await rel8({ src: rel8nsAddedIbGib, rel8nsToRemoveByAddr, noTimestamp: true, dna: true });
|
|
251
|
+
// ATOW dna only produces 1
|
|
252
|
+
const rel8DnaRemove = dnasRel8Remove![0];
|
|
253
|
+
const rel8DnaDataRemove: TransformOpts_Rel8<IbGib_V1> = clone(rel8DnaRemove.data!);
|
|
254
|
+
const rel8nNames_RemoveIbGib = Object.keys(rel8nsRemovedIbGib.rel8ns!);
|
|
255
|
+
|
|
256
|
+
SIMPLE_REL8N_NAMES.forEach(simpleRel8nName => {
|
|
257
|
+
const rel8dAddrs = rel8nsRemovedIbGib.rel8ns![simpleRel8nName]!;
|
|
258
|
+
// expect(rel8dAddrs).to.not.include.any.members([ROOT_ADDR, 'tag^gib']);
|
|
259
|
+
[ROOT_ADDR, 'tag^gib'].every(x => { expect(rel8dAddrs).not.toContain(x); });
|
|
260
|
+
|
|
261
|
+
// expect(rel8dAddrs).to.include.all.members(
|
|
262
|
+
// PRIMITIVE_IBGIBS
|
|
263
|
+
// .map(x => getIbGibAddr({ ibGib: x }))
|
|
264
|
+
// .filter(addr => addr !== ROOT_ADDR && addr !== 'tag^gib')
|
|
265
|
+
// );
|
|
266
|
+
PRIMITIVE_IBGIBS
|
|
267
|
+
.map(x => getIbGibAddr({ ibGib: x }))
|
|
268
|
+
.filter(addr => addr !== ROOT_ADDR && addr !== 'tag^gib')
|
|
269
|
+
.forEach(x => expect(rel8dAddrs).toContain(x));
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
// rerun the same (un)rel8 call, but get the args from the dna of the
|
|
273
|
+
// previous call. Then check to see if the same rel8ns were removed.
|
|
274
|
+
// it should remove the same rel8ns.
|
|
275
|
+
|
|
276
|
+
rel8DnaDataRemove.src = rel8nsAddedIbGib2;
|
|
277
|
+
rel8DnaDataRemove.srcAddr = undefined;
|
|
278
|
+
const { newIbGib: rel8nsRemovedIbGib2, dnas: _dnasRel8Remove } =
|
|
279
|
+
await rel8(rel8DnaDataRemove);
|
|
280
|
+
|
|
281
|
+
SIMPLE_REL8N_NAMES.forEach(simpleRel8nName => {
|
|
282
|
+
const rel8dAddrs = rel8nsRemovedIbGib2.rel8ns![simpleRel8nName]!;
|
|
283
|
+
// expect(rel8dAddrs).to.not.include.any.members([ROOT_ADDR, 'tag^gib']);
|
|
284
|
+
[ROOT_ADDR, 'tag^gib'].forEach(x => expect(rel8dAddrs).not.toContain(x))
|
|
285
|
+
|
|
286
|
+
// expect(rel8dAddrs).to.include.all.members(
|
|
287
|
+
// PRIMITIVE_IBGIBS
|
|
288
|
+
// .map(x => getIbGibAddr({ ibGib: x }))
|
|
289
|
+
// .filter(addr => addr !== ROOT_ADDR && addr !== 'tag^gib')
|
|
290
|
+
// );
|
|
291
|
+
PRIMITIVE_IBGIBS
|
|
292
|
+
.map(x => getIbGibAddr({ ibGib: x }))
|
|
293
|
+
.filter(addr => addr !== ROOT_ADDR && addr !== 'tag^gib')
|
|
294
|
+
.forEach(x => expect(rel8dAddrs).toContain(x));
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
//#endregion
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it(`should rel8 linked rel8ns to make only one rel8n`, async () => {
|
|
301
|
+
// linkedRel8ns should produce a rel8n that only has one target
|
|
302
|
+
let testRel8nName = 'test';
|
|
303
|
+
let { newIbGib: src1 } =
|
|
304
|
+
await fork({ src: primitive, linkedRel8ns: ['past', 'ancestor'] });
|
|
305
|
+
let src1Addr = getIbGibAddr({ ibGib: src1 });
|
|
306
|
+
expect((src1?.rel8ns?.past || []).length).withContext('src1.rel8ns.past.length').toEqual(0);
|
|
307
|
+
if (primitive.ib !== 'ib') {
|
|
308
|
+
expect((src1?.rel8ns?.ancestor || []).length).withContext('src1.rel8ns.ancestor.length').toEqual(1);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
let { newIbGib: src2 } =
|
|
312
|
+
await rel8({
|
|
313
|
+
src: src1,
|
|
314
|
+
rel8nsToAddByAddr: { [testRel8nName]: ['a^gib'] },
|
|
315
|
+
linkedRel8ns: ['past', 'ancestor', testRel8nName],
|
|
316
|
+
});
|
|
317
|
+
expect((src2?.rel8ns?.past || []).length).withContext('src2.rel8ns.past.length').toEqual(1);
|
|
318
|
+
if (primitive.ib !== 'ib') {
|
|
319
|
+
expect((src2?.rel8ns?.ancestor || []).length).withContext('src2.rel8ns.ancestor.length').toEqual(1);
|
|
320
|
+
}
|
|
321
|
+
expect((src2?.rel8ns![testRel8nName] || []).length).withContext(`src2.rel8ns.${testRel8nName}.length`).toEqual(1);
|
|
322
|
+
expect(src2?.rel8ns![testRel8nName]![0]).withContext(`src2.rel8ns.${testRel8nName}[0]`).toEqual('a^gib');
|
|
323
|
+
|
|
324
|
+
let { newIbGib: src3 } =
|
|
325
|
+
await rel8({
|
|
326
|
+
src: src2,
|
|
327
|
+
rel8nsToAddByAddr: { [testRel8nName]: ['b^gib'] },
|
|
328
|
+
linkedRel8ns: ['past', 'ancestor', testRel8nName],
|
|
329
|
+
});
|
|
330
|
+
expect((src3?.rel8ns?.past || []).length).withContext('src3.rel8ns.past.length').toEqual(1);
|
|
331
|
+
if (primitive.ib !== 'ib') {
|
|
332
|
+
expect((src3?.rel8ns?.ancestor || []).length).withContext('src3.rel8ns.ancestor.length').toEqual(1);
|
|
333
|
+
}
|
|
334
|
+
expect((src3?.rel8ns![testRel8nName] || []).length).withContext(`src3.rel8ns.${testRel8nName}.length`).toEqual(1);
|
|
335
|
+
expect(src3?.rel8ns![testRel8nName]![0]).withContext(`src3.rel8ns.${testRel8nName}[0]`).toEqual('b^gib');
|
|
336
|
+
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it(`should rel8 tjp ASAP, i.e. first rel8 after fork, also shoehorned tjpGib testing`, async () => {
|
|
340
|
+
// the tjp rel8n should be set ASAP because it's very important.
|
|
341
|
+
// so if the first transform after fork is a rel8, then do it there.
|
|
342
|
+
const testRel8ns = { irrelevant: ['ib^gib'] };
|
|
343
|
+
const { newIbGib: tjpIbGib } =
|
|
344
|
+
await fork({ src: primitive, tjp: { uuid: true, timestamp: true } });
|
|
345
|
+
const tjpAddr = getIbGibAddr({ ibGib: tjpIbGib });
|
|
346
|
+
const tjpAddrGib = getIbAndGib({ ibGibAddr: tjpAddr }).gib;
|
|
347
|
+
expect(tjpIbGib?.data?.isTjp).withContext('src1.data.isTjp').toBeTruthy();
|
|
348
|
+
expect(tjpIbGib?.rel8ns?.tjp).withContext('src1.rel8ns.tjp').toBeUndefined();
|
|
349
|
+
const { newIbGib: hasRel8dTjp } =
|
|
350
|
+
await rel8({ src: tjpIbGib, rel8nsToAddByAddr: testRel8ns });
|
|
351
|
+
const hasRel8dTjpAddr = getIbGibAddr({ ibGib: hasRel8dTjp });
|
|
352
|
+
const hasRel8dTjpAddrGib = getIbAndGib({ ibGibAddr: hasRel8dTjpAddr }).gib;
|
|
353
|
+
expect(hasRel8dTjp?.data?.isTjp).withContext('src2.data.isTjp').toBeUndefined();
|
|
354
|
+
expect(hasRel8dTjp?.rel8ns?.tjp).withContext('src2.rel8ns.tjp').toBeTruthy();
|
|
355
|
+
expect(hasRel8dTjp!.rel8ns!.tjp!.length).withContext('src2.rel8ns.tjp.length').toEqual(1);
|
|
356
|
+
expect(hasRel8dTjp!.rel8ns!.tjp!).toContain(tjpAddr);
|
|
357
|
+
|
|
358
|
+
// the gib should not just be the hash, since it has a tjp timeline
|
|
359
|
+
expect(hasRel8dTjpAddrGib).toContain(tjpAddrGib);
|
|
360
|
+
|
|
361
|
+
// shoe-horning in here some getGibInfo testing...eesh
|
|
362
|
+
const hasRel8dTjpGibInfo = getGibInfo({ ibGibAddr: hasRel8dTjpAddr }); // via addr
|
|
363
|
+
expect(hasRel8dTjpGibInfo.isPrimitive).toBeUndefined();
|
|
364
|
+
expect(hasRel8dTjpGibInfo.piecesCount).toEqual(2, 'pieces count');
|
|
365
|
+
const hasRel8dTjpHash = await sha256v1(hasRel8dTjp, '');
|
|
366
|
+
expect(hasRel8dTjpGibInfo.punctiliarHash).toEqual(hasRel8dTjpHash, 'punctiliarHash');
|
|
367
|
+
expect(hasRel8dTjpGibInfo.tjpGib).toEqual(tjpAddrGib);
|
|
368
|
+
// the info should be the same if we get it straight from the gib
|
|
369
|
+
const hasRel8dTjpGibInfo_viaGib = getGibInfo({ gib: hasRel8dTjpAddrGib }); // via gib
|
|
370
|
+
expect(hasRel8dTjpGibInfo_viaGib).toEqual(hasRel8dTjpGibInfo, 'infos via addr and gib should be equal');
|
|
371
|
+
|
|
372
|
+
// ok, yes my testing is out of control, but I'm going to shoehorn in here
|
|
373
|
+
// another rel8 and make sure that the punctiliar hash is correct and the gib only has two pieces.
|
|
374
|
+
const testRel8ns2 = { more_irrelevant: ['ib^gib'] };
|
|
375
|
+
const { newIbGib: thirdGenIbGib } =
|
|
376
|
+
await rel8({ src: hasRel8dTjp, rel8nsToAddByAddr: testRel8ns });
|
|
377
|
+
const thirdGenAddr = getIbGibAddr({ ibGib: thirdGenIbGib });
|
|
378
|
+
const thirdGenGibInfo = getGibInfo({ ibGibAddr: thirdGenAddr });
|
|
379
|
+
const thirdGenHash = await sha256v1(thirdGenIbGib, '');
|
|
380
|
+
expect(thirdGenGibInfo.punctiliarHash).toEqual(thirdGenHash);
|
|
381
|
+
expect(thirdGenGibInfo.tjpGib).toEqual(tjpAddrGib, 'third gen match tjpAddrGib');
|
|
382
|
+
expect(thirdGenGibInfo.piecesCount).toEqual(2, 'third gen pieces');
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
describe(`nCounter`, () => {
|
|
388
|
+
it(`should increment existing n counter`, async () => {
|
|
389
|
+
for (const primitive of PRIMITIVE_IBGIBS) {
|
|
390
|
+
let { newIbGib: src_0 } =
|
|
391
|
+
await fork({ src: primitive, nCounter: true });
|
|
392
|
+
|
|
393
|
+
expect(src_0.data).toBeTruthy();
|
|
394
|
+
expect(src_0.data!.n).toEqual(0);
|
|
395
|
+
expect(src_0!.data?.isTjp).withContext("isTjp").toBeUndefined();
|
|
396
|
+
|
|
397
|
+
const rel8nsToAddByAddr = buildRel8nsToAddOrRemoveFromPrimitives(SIMPLE_REL8N_NAMES);
|
|
398
|
+
|
|
399
|
+
// we now have a non-primitive 1st gen source and wish to
|
|
400
|
+
// add rel8ns in it pointing to other ibGibs.
|
|
401
|
+
|
|
402
|
+
const { newIbGib: src_1 } =
|
|
403
|
+
await rel8({
|
|
404
|
+
src: src_0,
|
|
405
|
+
rel8nsToAddByAddr,
|
|
406
|
+
noTimestamp: true,
|
|
407
|
+
nCounter: true
|
|
408
|
+
});
|
|
409
|
+
expect(src_1).toBeTruthy();
|
|
410
|
+
expect(src_1.rel8ns).toBeTruthy();
|
|
411
|
+
expect(src_1.rel8ns).toBeTruthy();
|
|
412
|
+
const rel8nNames_AddedIbGib = Object.keys(src_1.rel8ns!);
|
|
413
|
+
SIMPLE_REL8N_NAMES.forEach(simpleRel8nName => {
|
|
414
|
+
expect(rel8nNames_AddedIbGib).toContain(simpleRel8nName);
|
|
415
|
+
const simpleRel8nAddrs = src_1.rel8ns![simpleRel8nName]!;
|
|
416
|
+
expect(simpleRel8nAddrs).not.toHaveSize(0);
|
|
417
|
+
const expectedRel8nAddrs = rel8nsToAddByAddr[simpleRel8nName];
|
|
418
|
+
expect(expectedRel8nAddrs).not.toHaveSize(0);
|
|
419
|
+
expect(simpleRel8nAddrs).toEqual(expectedRel8nAddrs!);
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
expect(src_1.data).toBeTruthy();
|
|
423
|
+
expect(src_1.data).toBeTruthy();
|
|
424
|
+
expect(src_1.data!.n).toBeTruthy();
|
|
425
|
+
expect(src_1.data!.n).toBeTruthy();
|
|
426
|
+
expect(src_1.data!.n).toEqual(1);
|
|
427
|
+
expect(src_1!.data?.isTjp).withContext("isTjp").toBeUndefined();
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
it(`should start new n counter, implicit nCounter falsy`, async () => {
|
|
431
|
+
for (const primitive of PRIMITIVE_IBGIBS) {
|
|
432
|
+
let { newIbGib: src_0 } =
|
|
433
|
+
await fork({ src: primitive });
|
|
434
|
+
|
|
435
|
+
expect(src_0.data).toBeTruthy();
|
|
436
|
+
expect(src_0.data).toBeTruthy();
|
|
437
|
+
expect(src_0.data!.n).toBeUndefined();
|
|
438
|
+
|
|
439
|
+
const rel8nsToAddByAddr = buildRel8nsToAddOrRemoveFromPrimitives(SIMPLE_REL8N_NAMES);
|
|
440
|
+
|
|
441
|
+
// we now have a non-primitive 1st gen source and wish to
|
|
442
|
+
// add rel8ns in it pointing to other ibGibs.
|
|
443
|
+
|
|
444
|
+
const { newIbGib: src_1 } =
|
|
445
|
+
await rel8({
|
|
446
|
+
src: src_0,
|
|
447
|
+
rel8nsToAddByAddr,
|
|
448
|
+
noTimestamp: true,
|
|
449
|
+
nCounter: true
|
|
450
|
+
});
|
|
451
|
+
expect(src_1).toBeTruthy();
|
|
452
|
+
expect(src_1.rel8ns).toBeTruthy();
|
|
453
|
+
expect(src_1.rel8ns).toBeTruthy();
|
|
454
|
+
const rel8nNames_AddedIbGib = Object.keys(src_1.rel8ns!);
|
|
455
|
+
SIMPLE_REL8N_NAMES.forEach(simpleRel8nName => {
|
|
456
|
+
expect(rel8nNames_AddedIbGib).toContain(simpleRel8nName);
|
|
457
|
+
const simpleRel8nAddrs = src_1.rel8ns![simpleRel8nName]!;
|
|
458
|
+
expect(simpleRel8nAddrs).not.toHaveSize(0);
|
|
459
|
+
const expectedRel8nAddrs = rel8nsToAddByAddr[simpleRel8nName];
|
|
460
|
+
expect(expectedRel8nAddrs).not.toHaveSize(0);
|
|
461
|
+
expect(simpleRel8nAddrs).toEqual(expectedRel8nAddrs!);
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
expect(src_1.data).toBeTruthy();
|
|
465
|
+
expect(src_1.data!.n).toEqual(0);
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
it(`should start new n counter, explicit nCounter falsy`, async () => {
|
|
469
|
+
for (const primitive of PRIMITIVE_IBGIBS) {
|
|
470
|
+
let { newIbGib: src_0 } =
|
|
471
|
+
await fork({ src: primitive, nCounter: false });
|
|
472
|
+
|
|
473
|
+
expect(src_0.data).toBeTruthy();
|
|
474
|
+
expect(src_0.data).toBeTruthy();
|
|
475
|
+
expect(src_0.data!.n).toBeUndefined();
|
|
476
|
+
expect(src_0!.data!.isTjp).withContext("isTjp").toBeUndefined();
|
|
477
|
+
|
|
478
|
+
const rel8nsToAddByAddr = buildRel8nsToAddOrRemoveFromPrimitives(SIMPLE_REL8N_NAMES);
|
|
479
|
+
|
|
480
|
+
// we now have a non-primitive 1st gen source and wish to
|
|
481
|
+
// add rel8ns in it pointing to other ibGibs.
|
|
482
|
+
|
|
483
|
+
const { newIbGib: src_1 } =
|
|
484
|
+
await rel8({
|
|
485
|
+
src: src_0,
|
|
486
|
+
rel8nsToAddByAddr,
|
|
487
|
+
noTimestamp: true,
|
|
488
|
+
nCounter: true
|
|
489
|
+
});
|
|
490
|
+
expect(src_1).toBeTruthy();
|
|
491
|
+
expect(src_1.rel8ns).toBeTruthy();
|
|
492
|
+
expect(src_1.rel8ns).toBeTruthy();
|
|
493
|
+
const rel8nNames_AddedIbGib = Object.keys(src_1.rel8ns!);
|
|
494
|
+
SIMPLE_REL8N_NAMES.forEach(simpleRel8nName => {
|
|
495
|
+
expect(rel8nNames_AddedIbGib).toContain(simpleRel8nName);
|
|
496
|
+
const simpleRel8nAddrs = src_1.rel8ns![simpleRel8nName]!;
|
|
497
|
+
expect(simpleRel8nAddrs).not.toHaveSize(0);
|
|
498
|
+
const expectedRel8nAddrs = rel8nsToAddByAddr[simpleRel8nName];
|
|
499
|
+
expect(expectedRel8nAddrs).not.toHaveSize(0);
|
|
500
|
+
expect(simpleRel8nAddrs).toEqual(expectedRel8nAddrs!);
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
expect(src_1.data).toBeTruthy();
|
|
504
|
+
expect(src_1.data!.n).toEqual(0);
|
|
505
|
+
expect(src_1!.data!.isTjp).withContext("isTjp").toBeUndefined();
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
// for (const primitive of PRIMITIVE_IBGIBS) {
|
|
509
|
+
// let { newIbGib: src_0 } =
|
|
510
|
+
// await fork({src: primitive, noTimestamp: true, nCounter: false});
|
|
511
|
+
|
|
512
|
+
// expect(src_0.data).toBeUndefined();
|
|
513
|
+
|
|
514
|
+
// let { newIbGib: src_1 } =
|
|
515
|
+
// await mut8({
|
|
516
|
+
// src: src_0,
|
|
517
|
+
// dataToAddOrPatch: DATA_SIMPLE_XY,
|
|
518
|
+
// nCounter: true
|
|
519
|
+
// });
|
|
520
|
+
// expect(src_1.data).toBeTruthy();
|
|
521
|
+
// expect(src_1.data!.n).toEqual(0);
|
|
522
|
+
// }
|
|
523
|
+
// });
|
|
524
|
+
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
describe(`when rel8 with dna`, () => {
|
|
528
|
+
it(`should have gibs that is corroborated with getGib`, async () => {
|
|
529
|
+
for (const primitive of PRIMITIVE_IBGIBS) {
|
|
530
|
+
let { newIbGib: src_0 } =
|
|
531
|
+
await fork({ src: primitive, nCounter: false, dna: true });
|
|
532
|
+
|
|
533
|
+
const rel8nsToAddByAddr = buildRel8nsToAddOrRemoveFromPrimitives(SIMPLE_REL8N_NAMES);
|
|
534
|
+
|
|
535
|
+
// we now have a non-primitive 1st gen source and wish to
|
|
536
|
+
// add rel8ns in it pointing to other ibGibs.
|
|
537
|
+
|
|
538
|
+
const { newIbGib, intermediateIbGibs, dnas } =
|
|
539
|
+
await rel8({
|
|
540
|
+
src: src_0,
|
|
541
|
+
rel8nsToAddByAddr,
|
|
542
|
+
noTimestamp: true,
|
|
543
|
+
nCounter: true,
|
|
544
|
+
dna: true,
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
const ibGibs = [newIbGib, ...(intermediateIbGibs ?? []), ...(dnas ?? [])];
|
|
548
|
+
for (let i = 0; i < ibGibs.length; i++) {
|
|
549
|
+
const ibGib = ibGibs[i];
|
|
550
|
+
const gottenGib = await getGib({ ibGib });
|
|
551
|
+
expect(ibGib.gib).toEqual(gottenGib);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
});
|
|
556
|
+
});
|