@ibgib/ts-gib 0.5.1 → 0.5.2
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/CHANGELOG.md +3 -0
- package/README.md +22 -3
- package/dist/respec-gib.node.d.mts +2 -0
- package/dist/respec-gib.node.d.mts.map +1 -0
- package/dist/respec-gib.node.mjs +211 -0
- package/dist/respec-gib.node.mjs.map +1 -0
- package/package.json +10 -13
- package/src/V1/{factory.spec.mts → factory.respec.mts} +30 -28
- package/src/V1/{sha256v1.spec.mts → sha256v1.respec.mts} +23 -13
- package/src/V1/transforms/fork.spec.mts +126 -126
- package/src/V1/transforms/mut8.spec.mts +174 -174
- package/src/V1/transforms/rel8.spec.mts +109 -109
- package/src/V1/transforms/transform-helper.spec.mts +5 -5
- package/src/helper.respec.mts +62 -0
- package/src/respec-gib.node.mts +199 -0
- package/tsconfig.json +3 -1
- package/tsconfig.test.json +4 -2
- package/jasmine-browser.json +0 -18
- package/jasmine.json +0 -6
- package/src/helper.spec.mts +0 -59
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -513,14 +513,33 @@ frameworks for them), I have kluged a workaround by editing
|
|
|
513
513
|
section. So atow paste the following code before any other `script` tags in the
|
|
514
514
|
`head` section. (the versions may need to change):
|
|
515
515
|
|
|
516
|
-
|
|
516
|
+
|
|
517
|
+
_note: atow I am copy/pasting this text whenever I reinstall `node_modules` folder._
|
|
518
|
+
|
|
519
|
+
_note: if you are having CORS issues, it may be due to the cdn being down._
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
using **unpkg**:
|
|
523
|
+
|
|
524
|
+
```html
|
|
525
|
+
<script type="importmap">
|
|
526
|
+
{
|
|
527
|
+
"imports": {
|
|
528
|
+
"@ibgib/helper-gib": "https://unpkg.com/@ibgib/helper-gib@0.0.4/dist/index.mjs",
|
|
529
|
+
"@ibgib/helper-gib/": "https://unpkg.com/@ibgib/helper-gib@0.0.4/"
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
</script>
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
**using jsdelivr.net**:
|
|
517
536
|
|
|
518
537
|
```html
|
|
519
538
|
<script type="importmap">
|
|
520
539
|
{
|
|
521
540
|
"imports": {
|
|
522
|
-
"@ibgib/helper-gib": "https://
|
|
523
|
-
"@ibgib/helper-gib/": "https://
|
|
541
|
+
"@ibgib/helper-gib": "https://cdn.jsdelivr.net/npm/@ibgib/helper-gib@0.0.4/dist/index.mjs",
|
|
542
|
+
"@ibgib/helper-gib/": "https://cdn.jsdelivr.net/npm/@ibgib/helper-gib@0.0.4/"
|
|
524
543
|
}
|
|
525
544
|
}
|
|
526
545
|
</script>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"respec-gib.node.d.mts","sourceRoot":"","sources":["../src/respec-gib.node.mts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { readdir, open } from 'node:fs/promises';
|
|
2
|
+
import { statSync } from 'node:fs';
|
|
3
|
+
import * as pathUtils from 'path';
|
|
4
|
+
import { pretty } from '@ibgib/helper-gib';
|
|
5
|
+
import { getGlobalRespecGib } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
|
|
6
|
+
// #region settings
|
|
7
|
+
/**
|
|
8
|
+
* This is how I enable/disable verbose logging. Do with it what you will.
|
|
9
|
+
*/
|
|
10
|
+
const logalot = false;
|
|
11
|
+
/** set this to the root of the respecs to look at */
|
|
12
|
+
const RESPEC_ROOT_DIR_RELATIVE_TO_BASE = './dist';
|
|
13
|
+
/** change this to suit your naming convention */
|
|
14
|
+
const RESPEC_FILE_REG_EXP = /^.+respec\.mjs$/;
|
|
15
|
+
// const RESPEC_FILE_REG_EXP = /^.*respec-gib.respec\.mjs$/;
|
|
16
|
+
// if (respecPath.includes('respec-gib.respec.mjs')) {
|
|
17
|
+
/**
|
|
18
|
+
* If on, will first load a file and see if there is an extra respecful
|
|
19
|
+
* `respecfully`/`ifWe` block. Use these if you want to focus on a single or
|
|
20
|
+
* subset of respecs.
|
|
21
|
+
*
|
|
22
|
+
* If there are no extra respecful blocks found in an entire file, that file
|
|
23
|
+
* will be skipped.
|
|
24
|
+
*
|
|
25
|
+
* Note: this only is a flag to search through respec files.
|
|
26
|
+
*/
|
|
27
|
+
const LOOK_FOR_EXTRA_RESPEC = true;
|
|
28
|
+
/**
|
|
29
|
+
* The names of the functions that indicate that we want to focus on just those
|
|
30
|
+
* blocks.
|
|
31
|
+
*
|
|
32
|
+
* ATOW, for first run implementation here, I am implementing it such that it
|
|
33
|
+
* will filter out files that don't have these indicators. The respec files that
|
|
34
|
+
* do have these will execute fully, but the output will only include these
|
|
35
|
+
* particular blocks.
|
|
36
|
+
*/
|
|
37
|
+
const EXTRA_RESPEC_FUNCTION_NAMES = ['respecfullyDear', 'ifWeMight'];
|
|
38
|
+
// #endregion settings
|
|
39
|
+
// #region 1. get respec paths
|
|
40
|
+
const basePath = process.cwd();
|
|
41
|
+
const srcPath = pathUtils.join(basePath, RESPEC_ROOT_DIR_RELATIVE_TO_BASE);
|
|
42
|
+
if (logalot) {
|
|
43
|
+
console.log(`cwd: ${process.cwd()}`);
|
|
44
|
+
}
|
|
45
|
+
if (logalot) {
|
|
46
|
+
console.log(`basePath: ${basePath}`);
|
|
47
|
+
}
|
|
48
|
+
if (logalot) {
|
|
49
|
+
console.log(`srcPath: ${srcPath}`);
|
|
50
|
+
}
|
|
51
|
+
const respecGib = getGlobalRespecGib();
|
|
52
|
+
const allRespecPaths = await getRespecFileFullPaths(srcPath, []);
|
|
53
|
+
if (logalot) {
|
|
54
|
+
console.log(`allRespecPaths: ${allRespecPaths} (I: f5182a455375a8cf2aa6e1127a082423)`);
|
|
55
|
+
}
|
|
56
|
+
let filteredRespecPaths = undefined;
|
|
57
|
+
if (LOOK_FOR_EXTRA_RESPEC) {
|
|
58
|
+
const hasExtraRespecPromises = allRespecPaths.map(async (respecPath) => {
|
|
59
|
+
const hasExtra = await respecFileHasExtraRespec(respecPath);
|
|
60
|
+
return [respecPath, hasExtra];
|
|
61
|
+
});
|
|
62
|
+
const resPathHasExtraTuples = await Promise.all(hasExtraRespecPromises);
|
|
63
|
+
filteredRespecPaths = resPathHasExtraTuples
|
|
64
|
+
.filter(([_respecPath, hasExtra]) => hasExtra)
|
|
65
|
+
.map(([respecPath, _hasExtra]) => respecPath);
|
|
66
|
+
// if there are no files that have extra respec then we do all files
|
|
67
|
+
if (filteredRespecPaths.length === 0) {
|
|
68
|
+
if (logalot) {
|
|
69
|
+
console.log(`filteredRespecPaths is empty. doing allRespecPaths found (I: b98f54656899646025eecb4c028ab523)`);
|
|
70
|
+
}
|
|
71
|
+
filteredRespecPaths = allRespecPaths.concat();
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
console.log(`filteredRespecPaths for extra respec: ${filteredRespecPaths} (I: b98f54656899646025eecb4c028ab523)`);
|
|
75
|
+
respecGib.extraRespecOnly = true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// #endregion 1. get respec paths
|
|
79
|
+
respecGib.allRespecPaths = allRespecPaths;
|
|
80
|
+
respecGib.filteredRespecPaths = filteredRespecPaths;
|
|
81
|
+
const respecPaths = filteredRespecPaths ?? allRespecPaths;
|
|
82
|
+
respecGib.respecPaths = respecPaths;
|
|
83
|
+
if (logalot) {
|
|
84
|
+
console.log(`respecPaths found:\n${respecPaths}`);
|
|
85
|
+
}
|
|
86
|
+
// #region 2. execute paths' respective respecs
|
|
87
|
+
// for now, we'll do sequentially, but in the future we could conceivable farm
|
|
88
|
+
// these out to other node processes, or at least Promise.all
|
|
89
|
+
for (let i = 0; i < respecPaths.length; i++) {
|
|
90
|
+
const respecPath = respecPaths[i];
|
|
91
|
+
if (logalot) {
|
|
92
|
+
console.log(respecPath);
|
|
93
|
+
}
|
|
94
|
+
const esm = await import(respecPath);
|
|
95
|
+
if (logalot) {
|
|
96
|
+
console.log(pretty(Object.keys(esm)));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const skippedRespecPathCount = respecGib.allRespecPaths.length - respecGib.respecPaths.length;
|
|
100
|
+
if (skippedRespecPathCount > 0) {
|
|
101
|
+
console.log('');
|
|
102
|
+
console.error('\x1b[33m%s\x1b[0m', `${skippedRespecPathCount} respec files completely skipped.`); // yellow
|
|
103
|
+
}
|
|
104
|
+
if (respecGib.ifWeBlocksSkipped > 0) {
|
|
105
|
+
console.log('');
|
|
106
|
+
console.error('\x1b[33m%s\x1b[0m', `${respecGib.ifWeBlocksSkipped} ifWe blocks ran but skipped reporting`); // yellow
|
|
107
|
+
}
|
|
108
|
+
if (respecGib.errorMsgs.length === 0) {
|
|
109
|
+
console.log('');
|
|
110
|
+
console.error('\x1b[32m%s\x1b[0m', `💚💚 nothing but respec 💚💚`); // green
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
console.log('');
|
|
114
|
+
console.error('\x1b[31m%s\x1b[0m', `💔💔 DISrespec found 💔💔`); // red
|
|
115
|
+
for (const errorMsg of respecGib.errorMsgs) {
|
|
116
|
+
console.error('\x1b[31m%s\x1b[0m', errorMsg); // red
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// #endregion 2. execute paths' respective respecs
|
|
120
|
+
// #region helper functions
|
|
121
|
+
/**
|
|
122
|
+
* builds a list of respec file paths, recursively traversing subdirectories
|
|
123
|
+
* starting from `dirPath`.
|
|
124
|
+
*
|
|
125
|
+
* @param dirPath a full path corresponding to a directory
|
|
126
|
+
* @param found respec paths already found (used in recursive calls)
|
|
127
|
+
* @returns list of all respec paths according to the respec regexp constant {@link RESPEC_FILE_REG_EXP}
|
|
128
|
+
*/
|
|
129
|
+
async function getRespecFileFullPaths(dirPath, found) {
|
|
130
|
+
const lc = `[${getRespecFileFullPaths.name}][${dirPath}]`;
|
|
131
|
+
try {
|
|
132
|
+
if (logalot) {
|
|
133
|
+
console.log(`${lc} starting... (I: 16026290523925f79ba1933847e2a623)`);
|
|
134
|
+
}
|
|
135
|
+
found ?? (found = []);
|
|
136
|
+
const children = await readdir(dirPath);
|
|
137
|
+
if (logalot) {
|
|
138
|
+
for (let i = 0; i < children.length; i++) {
|
|
139
|
+
console.log(children[i]);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const files = [];
|
|
143
|
+
const dirs = [];
|
|
144
|
+
children.forEach(name => {
|
|
145
|
+
const fullPath = pathUtils.join(dirPath, name);
|
|
146
|
+
const stat = statSync(fullPath);
|
|
147
|
+
if (stat.isDirectory()) {
|
|
148
|
+
// symbolic link could create a loop
|
|
149
|
+
if (!stat.isSymbolicLink()) {
|
|
150
|
+
dirs.push(fullPath);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else if (!!name.match(RESPEC_FILE_REG_EXP)) {
|
|
154
|
+
files.push(fullPath);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
found = found.concat(files);
|
|
158
|
+
for (let i = 0; i < dirs.length; i++) {
|
|
159
|
+
const subfound = await getRespecFileFullPaths(dirs[i], found);
|
|
160
|
+
found = found.concat(subfound);
|
|
161
|
+
}
|
|
162
|
+
return Array.from(new Set(found)); // unique
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
console.error(`${lc} ${error.message}`);
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
finally {
|
|
169
|
+
if (logalot) {
|
|
170
|
+
console.log(`${lc} complete.`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Searches through the file (without importing it) for extra respecful
|
|
176
|
+
* functions.
|
|
177
|
+
*
|
|
178
|
+
* @param respecPath
|
|
179
|
+
* @returns true if extra respecful functions found in file
|
|
180
|
+
*/
|
|
181
|
+
async function respecFileHasExtraRespec(respecPath) {
|
|
182
|
+
const lc = `[${respecFileHasExtraRespec.name}]`;
|
|
183
|
+
try {
|
|
184
|
+
if (logalot) {
|
|
185
|
+
console.log(`${lc} starting... (I: 61f3221917ba77175efa305b14defc23)`);
|
|
186
|
+
}
|
|
187
|
+
const file = await open(respecPath);
|
|
188
|
+
for await (const line of file.readLines()) {
|
|
189
|
+
const hasExtraRespecInLine = EXTRA_RESPEC_FUNCTION_NAMES.some(fnName => {
|
|
190
|
+
if (line.includes(`${fnName}(`)) {
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
if (hasExtraRespecInLine) {
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
console.error(`${lc} ${error.message}`);
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
finally {
|
|
205
|
+
if (logalot) {
|
|
206
|
+
console.log(`${lc} complete.`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// #endregion helper functions
|
|
211
|
+
//# sourceMappingURL=respec-gib.node.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"respec-gib.node.mjs","sourceRoot":"","sources":["../src/respec-gib.node.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,SAAS,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,kDAAkD,CAAC;AAEtF,mBAAmB;AACnB;;GAEG;AACH,MAAM,OAAO,GAAG,KAAK,CAAC;AAEtB,qDAAqD;AACrD,MAAM,gCAAgC,GAAG,QAAQ,CAAC;AAElD,iDAAiD;AACjD,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AAC9C,4DAA4D;AAC5D,sDAAsD;AAEtD;;;;;;;;;GASG;AACH,MA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ED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ibgib/ts-gib",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
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",
|
|
@@ -19,17 +19,18 @@
|
|
|
19
19
|
"test": "npm run test:both",
|
|
20
20
|
"test:both": "npm run build:test && npm run test:node:nobuild && npm run test:browser:nobuild",
|
|
21
21
|
"man:test:both": "use this if you want to test in both node and browser contexts",
|
|
22
|
-
"
|
|
22
|
+
"pretest:node": "npm run build:test",
|
|
23
|
+
"test:node": "node dist/respec-gib.node.mjs --inspect",
|
|
23
24
|
"man:test:node": "use this if you want to build+test in node",
|
|
24
|
-
"test:node:nobuild": "
|
|
25
|
+
"test:node:nobuild": "node dist/respec-gib.node.mjs --inspect",
|
|
25
26
|
"man:test:node:nobuild": "use this if you want to test in node but its already built",
|
|
26
|
-
"test:browser": "npm run build:test &&
|
|
27
|
+
"test:browser": "npm run build:test && echo \"not implemented yet\"",
|
|
27
28
|
"man:test:browser": "use this if you want to build+test only the browser context",
|
|
28
|
-
"test:browser:nobuild": "
|
|
29
|
+
"test:browser:nobuild": "echo \"not implemented yet\"",
|
|
29
30
|
"man:test:browser:nobuild": "use this if you want to test only the browser context but its already built",
|
|
30
|
-
"test:browser:serve": "npm run build:test &&
|
|
31
|
+
"test:browser:serve": "npm run build:test && echo \"not implemented yet\"",
|
|
31
32
|
"man:test:browser:serve": "use this if you want to build+test in the browser and don't want the browser to close when your done. (i.e. you're debugging)",
|
|
32
|
-
"test:browser:serve:nobuild": "
|
|
33
|
+
"test:browser:serve:nobuild": "\"not implemented yet\"",
|
|
33
34
|
"man:test:browser:serve:nobuild": "use this if you are troubleshooting existing dist output and don't want to overwrite those files. (and you're debugging in the browser)",
|
|
34
35
|
"pack": "npm pack --pack-destination=\"./published\"",
|
|
35
36
|
"prepare:publish:minor": "npm run clean && npm version minor && npm run build && npm run pack",
|
|
@@ -46,11 +47,7 @@
|
|
|
46
47
|
"author": "William Raiford",
|
|
47
48
|
"license": "ISC",
|
|
48
49
|
"devDependencies": {
|
|
49
|
-
"@types/
|
|
50
|
-
"@types/node": "^16.11.6",
|
|
51
|
-
"jasmine": "^4.5.0",
|
|
52
|
-
"jasmine-browser-runner": "^1.3.0",
|
|
53
|
-
"jasmine-core": "^4.5.0",
|
|
50
|
+
"@types/node": "^20.2.1",
|
|
54
51
|
"typescript": "^4.9.5"
|
|
55
52
|
},
|
|
56
53
|
"engines": {
|
|
@@ -60,6 +57,6 @@
|
|
|
60
57
|
"access": "public"
|
|
61
58
|
},
|
|
62
59
|
"dependencies": {
|
|
63
|
-
"@ibgib/helper-gib": "^0.0.
|
|
60
|
+
"@ibgib/helper-gib": "^0.0.7"
|
|
64
61
|
}
|
|
65
62
|
}
|
|
@@ -9,6 +9,8 @@ import { Factory_V1 as factory } from './factory.mjs';
|
|
|
9
9
|
import { mut8 } from './transforms/mut8.mjs';
|
|
10
10
|
import { sha256v1 } from './sha256v1.mjs';
|
|
11
11
|
import { getGib, getGibInfo } from './transforms/transform-helper.mjs';
|
|
12
|
+
import { firstOfAll, ifWe, iReckon, respecfully } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
|
|
13
|
+
const maam = `[${import.meta.url}]`, sir = maam;
|
|
12
14
|
|
|
13
15
|
const PRIMITIVE_IBS: string[] = [
|
|
14
16
|
'a', '7', 'tag',
|
|
@@ -25,24 +27,24 @@ const SIMPLE_REL8N_NAMES: string[] = [
|
|
|
25
27
|
];
|
|
26
28
|
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
await respecfully(sir, `when using factory`, async () => {
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
await ifWe(sir, `primitives() should make multiple ibgibs`, async () => {
|
|
31
33
|
const primitiveIbGibs = factory.primitives({ ibs: PRIMITIVE_IBS });
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
iReckon(sir, primitiveIbGibs).isGonnaBeTruthy();
|
|
35
|
+
iReckon(sir, primitiveIbGibs.length).isGonnaBe(PRIMITIVE_IBS.length);
|
|
34
36
|
});
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
await respecfully(sir, `firstGen`, async () => {
|
|
39
|
+
await ifWe(sir, `should make an ibgib`, async () => {
|
|
38
40
|
const testIb = 'some ib here';
|
|
39
41
|
const { newIbGib } = await factory.firstGen({
|
|
40
42
|
ib: testIb,
|
|
41
43
|
parentIbGib: ROOT,
|
|
42
44
|
});
|
|
43
|
-
|
|
45
|
+
iReckon(sir, newIbGib).isGonnaBeTruthy;
|
|
44
46
|
});
|
|
45
|
-
|
|
47
|
+
await ifWe(sir, `should make ibgibs with initial data`, async () => {
|
|
46
48
|
const testIb = 'some ib here';
|
|
47
49
|
const { newIbGib, intermediateIbGibs } = await factory.firstGen({
|
|
48
50
|
ib: testIb,
|
|
@@ -50,17 +52,17 @@ describe(`when using factory`, () => {
|
|
|
50
52
|
data: DATA_SIMPLE_XY,
|
|
51
53
|
noTimestamp: true,
|
|
52
54
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
iReckon(sir, newIbGib.data).asTo(`newIbGib.data`).isGonnaBeTruthy();
|
|
56
|
+
iReckon(sir, newIbGib.data).isGonnaBe(DATA_SIMPLE_XY);
|
|
55
57
|
|
|
56
58
|
// an intermediate ibGib should be created with
|
|
57
59
|
// the same ib, but not yet mutated with the data.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
iReckon(sir, intermediateIbGibs).asTo(`intermediateIbGibs`).isGonnaBeTruthy();
|
|
61
|
+
iReckon(sir, intermediateIbGibs!.length).isGonnaBe(1);
|
|
62
|
+
iReckon(sir, intermediateIbGibs![0].ib).isGonnaBe(testIb);
|
|
63
|
+
iReckon(sir, intermediateIbGibs![0].data).asTo(`intermediateIbGibs[0].data`).not.isGonnaBeTruthy();
|
|
62
64
|
});
|
|
63
|
-
|
|
65
|
+
await ifWe(sir, `should make ibgibs with initial data & rel8ns`, async () => {
|
|
64
66
|
const primitiveIbgibAddrs =
|
|
65
67
|
factory
|
|
66
68
|
.primitives({ ibs: PRIMITIVE_IBS })
|
|
@@ -78,28 +80,28 @@ describe(`when using factory`, () => {
|
|
|
78
80
|
noTimestamp: true,
|
|
79
81
|
rel8ns: testRel8ns,
|
|
80
82
|
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
iReckon(sir, newIbGib.data).asTo(`newIbGib.data`).isGonnaBeTruthy();
|
|
84
|
+
iReckon(sir, newIbGib.data).isGonnaBe(DATA_SIMPLE_XY);
|
|
85
|
+
iReckon(sir, newIbGib.rel8ns).asTo(`newIbGib.rel8ns`).isGonnaBeTruthy();
|
|
84
86
|
SIMPLE_REL8N_NAMES.forEach(rel8nName => {
|
|
85
|
-
|
|
87
|
+
iReckon(sir, newIbGib.rel8ns![rel8nName]).isGonnaBe(primitiveIbgibAddrs);
|
|
86
88
|
})
|
|
87
89
|
|
|
88
90
|
// an intermediate ibGib should be created with
|
|
89
91
|
// the same ib, but not yet mutated with the data.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
iReckon(sir, intermediateIbGibs).asTo(`intermediateIbGibs`).isGonnaBeTruthy();
|
|
93
|
+
iReckon(sir, intermediateIbGibs!.length).isGonnaBe(2);
|
|
94
|
+
iReckon(sir, intermediateIbGibs![0].ib).isGonnaBe(testIb);
|
|
95
|
+
iReckon(sir, intermediateIbGibs![1].ib).isGonnaBe(testIb);
|
|
94
96
|
});
|
|
95
97
|
|
|
96
98
|
|
|
97
99
|
|
|
98
100
|
});
|
|
99
101
|
|
|
100
|
-
|
|
102
|
+
await respecfully(sir, 'hmm how to do this?', async () => {
|
|
101
103
|
var allIbGibs: IbGib_V1[];
|
|
102
|
-
|
|
104
|
+
firstOfAll(sir, async () => {
|
|
103
105
|
// I'm having some weird discrepancies between calling `sha256v1` and
|
|
104
106
|
// `getGib` (which itself calls sha256v1 supposedly).
|
|
105
107
|
//
|
|
@@ -148,14 +150,14 @@ describe(`when using factory`, () => {
|
|
|
148
150
|
];
|
|
149
151
|
});
|
|
150
152
|
|
|
151
|
-
|
|
153
|
+
await ifWe(sir, 'should match up ibGib.gib and getGib & should match up sha256v1 hash and punctiliar hash', async () => {
|
|
152
154
|
for (let i = 0; i < allIbGibs.length; i++) {
|
|
153
155
|
const x = allIbGibs[i];
|
|
154
156
|
let hash_sha256v1Direct = await sha256v1(x, '');
|
|
155
157
|
let hash_getGib = await getGib({ ibGib: x });
|
|
156
158
|
let punctiliarHash = getGibInfo({ gib: hash_getGib }).punctiliarHash;
|
|
157
|
-
|
|
158
|
-
|
|
159
|
+
iReckon(sir, hash_getGib).asTo('hash_getGib does not equal x.gib').isGonnaBe(x.gib!);
|
|
160
|
+
iReckon(sir, hash_sha256v1Direct).isGonnaBe(punctiliarHash!);
|
|
159
161
|
}
|
|
160
162
|
});
|
|
161
163
|
});
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* @module sha256v1
|
|
3
|
+
*
|
|
2
4
|
* Test basic hashing that is used when calculating V1 gib hashes
|
|
3
5
|
* using sha256.
|
|
4
6
|
*
|
|
@@ -7,11 +9,16 @@
|
|
|
7
9
|
* is required for browser until I get some kind of browser testing
|
|
8
10
|
* going.
|
|
9
11
|
*/
|
|
12
|
+
|
|
13
|
+
import { firstOfAll, ifWe, iReckon, respecfully } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
|
|
14
|
+
const maam = `[${import.meta.url}]`, sir = maam;
|
|
15
|
+
|
|
10
16
|
import { IbGib_V1, IbGibRel8ns_V1 } from './types.mjs';
|
|
11
17
|
import { sha256v1, hashToHexCopy } from './sha256v1.mjs';
|
|
12
18
|
import { IbGibWithDataAndRel8ns, IbGibRel8ns } from '../types.mjs';
|
|
13
19
|
import { getGib, getGibInfo } from './transforms/transform-helper.mjs';
|
|
14
20
|
|
|
21
|
+
|
|
15
22
|
import { Factory_V1 as factory } from './factory.mjs';
|
|
16
23
|
|
|
17
24
|
// #region Test Data
|
|
@@ -110,9 +117,9 @@ const TEST_IBGIBS: TestData[] = [
|
|
|
110
117
|
|
|
111
118
|
// #endregion
|
|
112
119
|
|
|
113
|
-
|
|
120
|
+
await respecfully(sir, `when hashing sha256v1`, async () => {
|
|
114
121
|
|
|
115
|
-
|
|
122
|
+
await ifWe(sir, `should hash ibgibs with empty/null/undefined data/rel8ns consistently "forever"`, async () => {
|
|
116
123
|
const ib: string = "ib";
|
|
117
124
|
const gib: string = "gib ignored when hashing";
|
|
118
125
|
const ibHash: string = await hashToHexCopy(ib) || "";
|
|
@@ -120,7 +127,7 @@ describe(`when hashing sha256v1`, () => {
|
|
|
120
127
|
const rel8nsHash: string = "";
|
|
121
128
|
const all = (ibHash + rel8nsHash + dataHash).toUpperCase();
|
|
122
129
|
const manualAllHash = (await hashToHexCopy(all))?.toUpperCase();
|
|
123
|
-
|
|
130
|
+
iReckon(sir, manualAllHash).isGonnaBe("E975776B1A3E4468086E1D8C409116F6E098D13BEEDFE17AF668071B5D11CD55");
|
|
124
131
|
|
|
125
132
|
const equivalents: IbGib_V1[] = [
|
|
126
133
|
// #region empty rel8ns
|
|
@@ -183,23 +190,23 @@ describe(`when hashing sha256v1`, () => {
|
|
|
183
190
|
for (let j = 0; j < equivalents.length; j++) {
|
|
184
191
|
const ibgib = equivalents[j];
|
|
185
192
|
const result = (await sha256v1(ibgib, "")).toUpperCase();
|
|
186
|
-
|
|
193
|
+
iReckon(sir, result).isGonnaBe(manualAllHash!);
|
|
187
194
|
}
|
|
188
195
|
});
|
|
189
196
|
|
|
190
|
-
|
|
197
|
+
await ifWe(sir, `should hash ibgibs with non-null data/rel8ns consistently "forever"`, async () => {
|
|
191
198
|
for (const x of TEST_IBGIBS.filter(x => x.type === "simple_data_rel8ns")) {
|
|
192
199
|
const ibHash: string = await hashToHexCopy(x.ibgib.ib) || "";
|
|
193
200
|
const dataHash: string = await hashToHexCopy(JSON.stringify(x.ibgib.data)) || "";
|
|
194
|
-
|
|
201
|
+
iReckon(sir, dataHash.toUpperCase()).isGonnaBe(x.dataHash);
|
|
195
202
|
const rel8nsHash: string = await hashToHexCopy(JSON.stringify(x.ibgib.rel8ns)) || "";
|
|
196
|
-
|
|
203
|
+
iReckon(sir, rel8nsHash.toUpperCase()).isGonnaBe(x.rel8nsHash);
|
|
197
204
|
const all = (ibHash + rel8nsHash + dataHash).toUpperCase();
|
|
198
205
|
const manualAllHash = (await hashToHexCopy(all))?.toUpperCase();
|
|
199
|
-
|
|
206
|
+
iReckon(sir, manualAllHash).isGonnaBe(x.ibgib.gib);
|
|
200
207
|
|
|
201
208
|
const calculatedGibHash = (await sha256v1(x.ibgib, "")).toUpperCase();
|
|
202
|
-
|
|
209
|
+
iReckon(sir, calculatedGibHash).isGonnaBe(x.ibgib.gib!);
|
|
203
210
|
}
|
|
204
211
|
});
|
|
205
212
|
|
|
@@ -211,11 +218,14 @@ describe(`when hashing sha256v1`, () => {
|
|
|
211
218
|
// this is testing a function that is internal to the sha256v1 func.
|
|
212
219
|
// terrible as can be duplicated (i.e. not DRY), but simple albeit fragile testing
|
|
213
220
|
// for now.
|
|
214
|
-
Object.keys(testHashes_sha256_strings)
|
|
215
|
-
|
|
221
|
+
const keyStrings = Object.keys(testHashes_sha256_strings);
|
|
222
|
+
for (let i = 0; i < keyStrings.length; i++) {
|
|
223
|
+
const x = keyStrings[i];
|
|
224
|
+
await ifWe(sir, `test internal hash function ib: ${x}`, async () => {
|
|
216
225
|
const result = await hashToHexCopy(x);
|
|
217
|
-
|
|
226
|
+
iReckon(sir, result?.toUpperCase()).isGonnaBe(testHashes_sha256_strings[x]);
|
|
218
227
|
});
|
|
219
|
-
|
|
228
|
+
|
|
229
|
+
}
|
|
220
230
|
|
|
221
231
|
});
|