@xyo-network/hash 5.1.22 → 5.1.24
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/browser/worker/subtleHash-bundle.mjs +2 -2
- package/dist/browser/worker/wasmHash-bundle.mjs +38 -36
- package/package.json +15 -12
- package/dist/browser/spec/ObjectHasher.bigobj-parallel.perf.spec.d.ts +0 -2
- package/dist/browser/spec/ObjectHasher.bigobj-parallel.perf.spec.d.ts.map +0 -1
- package/dist/browser/spec/ObjectHasher.bigobj.perf.spec.d.ts +0 -2
- package/dist/browser/spec/ObjectHasher.bigobj.perf.spec.d.ts.map +0 -1
- package/dist/browser/spec/ObjectHasher.spec.d.ts +0 -2
- package/dist/browser/spec/ObjectHasher.spec.d.ts.map +0 -1
- package/dist/browser/spec/ObjectHasher.subtle.perf.spec.d.ts +0 -2
- package/dist/browser/spec/ObjectHasher.subtle.perf.spec.d.ts.map +0 -1
- package/dist/browser/spec/ObjectHasher.wasm-subtle.perf.spec.d.ts +0 -2
- package/dist/browser/spec/ObjectHasher.wasm-subtle.perf.spec.d.ts.map +0 -1
- package/dist/browser/spec/ObjectHasher.wasm.perf.spec.d.ts +0 -2
- package/dist/browser/spec/ObjectHasher.wasm.perf.spec.d.ts.map +0 -1
- package/dist/browser/spec/removeEmptyFields.spec.d.ts +0 -2
- package/dist/browser/spec/removeEmptyFields.spec.d.ts.map +0 -1
- package/dist/neutral/spec/ObjectHasher.bigobj-parallel.perf.spec.d.ts +0 -2
- package/dist/neutral/spec/ObjectHasher.bigobj-parallel.perf.spec.d.ts.map +0 -1
- package/dist/neutral/spec/ObjectHasher.bigobj.perf.spec.d.ts +0 -2
- package/dist/neutral/spec/ObjectHasher.bigobj.perf.spec.d.ts.map +0 -1
- package/dist/neutral/spec/ObjectHasher.spec.d.ts +0 -2
- package/dist/neutral/spec/ObjectHasher.spec.d.ts.map +0 -1
- package/dist/neutral/spec/ObjectHasher.subtle.perf.spec.d.ts +0 -2
- package/dist/neutral/spec/ObjectHasher.subtle.perf.spec.d.ts.map +0 -1
- package/dist/neutral/spec/ObjectHasher.wasm-subtle.perf.spec.d.ts +0 -2
- package/dist/neutral/spec/ObjectHasher.wasm-subtle.perf.spec.d.ts.map +0 -1
- package/dist/neutral/spec/ObjectHasher.wasm.perf.spec.d.ts +0 -2
- package/dist/neutral/spec/ObjectHasher.wasm.perf.spec.d.ts.map +0 -1
- package/dist/neutral/spec/removeEmptyFields.spec.d.ts +0 -2
- package/dist/neutral/spec/removeEmptyFields.spec.d.ts.map +0 -1
- package/dist/node/spec/ObjectHasher.bigobj-parallel.perf.spec.d.ts +0 -2
- package/dist/node/spec/ObjectHasher.bigobj-parallel.perf.spec.d.ts.map +0 -1
- package/dist/node/spec/ObjectHasher.bigobj.perf.spec.d.ts +0 -2
- package/dist/node/spec/ObjectHasher.bigobj.perf.spec.d.ts.map +0 -1
- package/dist/node/spec/ObjectHasher.spec.d.ts +0 -2
- package/dist/node/spec/ObjectHasher.spec.d.ts.map +0 -1
- package/dist/node/spec/ObjectHasher.subtle.perf.spec.d.ts +0 -2
- package/dist/node/spec/ObjectHasher.subtle.perf.spec.d.ts.map +0 -1
- package/dist/node/spec/ObjectHasher.wasm-subtle.perf.spec.d.ts +0 -2
- package/dist/node/spec/ObjectHasher.wasm-subtle.perf.spec.d.ts.map +0 -1
- package/dist/node/spec/ObjectHasher.wasm.perf.spec.d.ts +0 -2
- package/dist/node/spec/ObjectHasher.wasm.perf.spec.d.ts.map +0 -1
- package/dist/node/spec/removeEmptyFields.spec.d.ts +0 -2
- package/dist/node/spec/removeEmptyFields.spec.d.ts.map +0 -1
- package/src/spec/ObjectHasher.bigobj-parallel.perf.spec.ts +0 -98
- package/src/spec/ObjectHasher.bigobj.perf.spec.ts +0 -148
- package/src/spec/ObjectHasher.spec.ts +0 -140
- package/src/spec/ObjectHasher.subtle.perf.spec.ts +0 -59
- package/src/spec/ObjectHasher.wasm-subtle.perf.spec.ts +0 -75
- package/src/spec/ObjectHasher.wasm.perf.spec.ts +0 -60
- package/src/spec/removeEmptyFields.spec.ts +0 -31
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
// ../../../../../../node_modules/.store/@xylabs-platform-npm-5.0.
|
|
48
|
+
// ../../../../../../node_modules/.store/@xylabs-platform-npm-5.0.37-eaa5c7a52a/package/dist/browser/index-browser.mjs
|
|
49
49
|
var subtle = globalThis.crypto.subtle;
|
|
50
50
|
|
|
51
|
-
// ../../../../../../node_modules/.store/@xylabs-threads-npm-5.0.
|
|
51
|
+
// ../../../../../../node_modules/.store/@xylabs-threads-npm-5.0.37-12dec43a8d/package/dist/browser/worker/worker.browser.mjs
|
|
52
52
|
var import_is_observable_2_1_0 = __toESM(require_package(), 1);
|
|
53
53
|
var DefaultErrorSerializer = {
|
|
54
54
|
deserialize(message) {
|
|
@@ -49,6 +49,17 @@
|
|
|
49
49
|
}
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
+
// ../../../../../../node_modules/.store/@xylabs-typeof-npm-5.0.37-8f63e8bd34/package/dist/neutral/index.mjs
|
|
53
|
+
function isUndefined(value) {
|
|
54
|
+
return value === void 0;
|
|
55
|
+
}
|
|
56
|
+
function isString(value) {
|
|
57
|
+
return typeof value === "string";
|
|
58
|
+
}
|
|
59
|
+
function isNumber(value) {
|
|
60
|
+
return typeof value === "number";
|
|
61
|
+
}
|
|
62
|
+
|
|
52
63
|
// ../../../../../../node_modules/.store/zod-npm-4.1.12-8e1ffc4d68/package/v4/classic/external.js
|
|
53
64
|
var external_exports = {};
|
|
54
65
|
__export(external_exports, {
|
|
@@ -12594,29 +12605,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
12594
12605
|
// ../../../../../../node_modules/.store/zod-npm-4.1.12-8e1ffc4d68/package/index.js
|
|
12595
12606
|
var package_default = external_exports;
|
|
12596
12607
|
|
|
12597
|
-
// ../../../../../../node_modules/.store/@xylabs-
|
|
12598
|
-
function isUndefined(value) {
|
|
12599
|
-
return value === void 0;
|
|
12600
|
-
}
|
|
12601
|
-
function isString(value) {
|
|
12602
|
-
return typeof value === "string";
|
|
12603
|
-
}
|
|
12604
|
-
function isNumber(value) {
|
|
12605
|
-
return typeof value === "number";
|
|
12606
|
-
}
|
|
12607
|
-
|
|
12608
|
-
// ../../../../../../node_modules/.store/@xylabs-hex-npm-5.0.24-96a0124165/package/dist/neutral/index.mjs
|
|
12609
|
-
var HexRegExMinMax = (minBytes = 0, maxBytes = Number.MAX_SAFE_INTEGER / 2) => {
|
|
12610
|
-
return new RegExp(`^[a-f0-9]{${minBytes * 2},${maxBytes * 2}}$`);
|
|
12611
|
-
};
|
|
12612
|
-
var HexRegExMinMaxMixedCaseWithPrefix = (minBytes = 0, maxBytes = Number.MAX_SAFE_INTEGER / 2) => {
|
|
12613
|
-
return new RegExp(`^0x[a-fA-F0-9]{${minBytes * 2},${maxBytes * 2}}$`);
|
|
12614
|
-
};
|
|
12615
|
-
var HexRegEx = /^[0-9a-f]+$/;
|
|
12616
|
-
var HexRegExWithPrefix = /^0x[0-9a-f]+$/;
|
|
12617
|
-
var ADDRESS_LENGTH = 40;
|
|
12618
|
-
var AddressRegEx = HexRegExMinMax(ADDRESS_LENGTH / 2, ADDRESS_LENGTH / 2);
|
|
12619
|
-
var AddressZod = string2().regex(AddressRegEx, { message: "Invalid hex format" });
|
|
12608
|
+
// ../../../../../../node_modules/.store/@xylabs-hex-npm-5.0.37-9eedf6dd69/package/dist/neutral/index.mjs
|
|
12620
12609
|
var assertError = (value, assert2, defaultMessage) => {
|
|
12621
12610
|
if (!isUndefined(assert2)) {
|
|
12622
12611
|
const assertString = typeof assert2 === "string" ? assert2 : typeof assert2 === "boolean" ? defaultMessage : assert2(value, defaultMessage);
|
|
@@ -12626,6 +12615,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
12626
12615
|
}
|
|
12627
12616
|
return void 0;
|
|
12628
12617
|
};
|
|
12618
|
+
var HexRegExMinMax = (minBytes = 0, maxBytes = Number.MAX_SAFE_INTEGER / 2) => {
|
|
12619
|
+
return new RegExp(`^[a-f0-9]{${minBytes * 2},${maxBytes * 2}}$`);
|
|
12620
|
+
};
|
|
12621
|
+
var HexRegExMinMaxMixedCaseWithPrefix = (minBytes = 0, maxBytes = Number.MAX_SAFE_INTEGER / 2) => {
|
|
12622
|
+
return new RegExp(`^0x[a-fA-F0-9]{${minBytes * 2},${maxBytes * 2}}$`);
|
|
12623
|
+
};
|
|
12624
|
+
var HexRegEx = /^[0-9a-f]+$/;
|
|
12625
|
+
var HexRegExWithPrefix = /^0x[0-9a-f]+$/;
|
|
12629
12626
|
var bitsToNibbles = (value) => {
|
|
12630
12627
|
const nibbles = value >> 2;
|
|
12631
12628
|
if (value !== nibbles << 2) throw new Error("Bits for nibbles must multiple of 4");
|
|
@@ -12683,13 +12680,18 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
12683
12680
|
}
|
|
12684
12681
|
}
|
|
12685
12682
|
};
|
|
12686
|
-
var
|
|
12683
|
+
var UntypedHexZod = package_default.string().regex(HexRegEx, { message: "Invalid hex format" });
|
|
12684
|
+
var HexZod = UntypedHexZod.transform((val) => val);
|
|
12687
12685
|
var toHex = (value, config2 = {}) => {
|
|
12688
12686
|
const { prefix = false } = config2;
|
|
12689
12687
|
return hexFrom(value, { prefix, ...config2 });
|
|
12690
12688
|
};
|
|
12691
|
-
var
|
|
12692
|
-
var
|
|
12689
|
+
var ADDRESS_LENGTH = 40;
|
|
12690
|
+
var AddressRegEx = HexRegExMinMax(ADDRESS_LENGTH / 2, ADDRESS_LENGTH / 2);
|
|
12691
|
+
var UnTypedAddressZod = UntypedHexZod.regex(AddressRegEx);
|
|
12692
|
+
var AddressZod = UnTypedAddressZod.transform((v) => v);
|
|
12693
|
+
var AddressValidationZod = package_default.string().refine((x) => HexZod.safeParse(x)).refine((x) => x.length === ADDRESS_LENGTH, { error: (e) => new Error(`Address must have 40 characters [${e.input}]`) }).transform((v) => v);
|
|
12694
|
+
var AddressTransformZod = package_default.union([package_default.string(), package_default.bigint(), package_default.number()]).transform((value) => {
|
|
12693
12695
|
switch (typeof value) {
|
|
12694
12696
|
case "bigint": {
|
|
12695
12697
|
return value.toString(16).padStart(ADDRESS_LENGTH, "0");
|
|
@@ -12713,11 +12715,11 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
12713
12715
|
...config2
|
|
12714
12716
|
});
|
|
12715
12717
|
};
|
|
12716
|
-
var AddressToStringZod =
|
|
12717
|
-
var AddressFromStringZod =
|
|
12718
|
+
var AddressToStringZod = package_default.string().regex(AddressRegEx);
|
|
12719
|
+
var AddressFromStringZod = package_default.string().toLowerCase().regex(AddressRegEx).transform((v) => toAddress(v));
|
|
12718
12720
|
var EthAddressRegEx = HexRegExMinMaxMixedCaseWithPrefix(20, 20);
|
|
12719
|
-
var EthAddressToStringZod =
|
|
12720
|
-
var EthAddressFromStringZod =
|
|
12721
|
+
var EthAddressToStringZod = package_default.string().regex(EthAddressRegEx);
|
|
12722
|
+
var EthAddressFromStringZod = package_default.string().regex(EthAddressRegEx).transform((v) => toEthAddress(v));
|
|
12721
12723
|
var toEthAddress = (value, config2 = {}) => {
|
|
12722
12724
|
const { bitLength = 160, prefix = false } = config2;
|
|
12723
12725
|
return `0x${hexFrom(value, {
|
|
@@ -12731,7 +12733,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
12731
12733
|
const loweredValue = typeof value === "string" ? value.toLowerCase() : value;
|
|
12732
12734
|
return isHex(loweredValue, { bitLength, prefix });
|
|
12733
12735
|
};
|
|
12734
|
-
var EthAddressZod =
|
|
12736
|
+
var EthAddressZod = package_default.string().regex(EthAddressRegEx, { message: "Invalid address format" }).refine(
|
|
12735
12737
|
isEthAddress
|
|
12736
12738
|
);
|
|
12737
12739
|
var isHash = (value, bitLength = 256) => {
|
|
@@ -12752,16 +12754,16 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
12752
12754
|
}
|
|
12753
12755
|
var HASH_LENGTH = 32;
|
|
12754
12756
|
var HashRegEx = HexRegExMinMax(HASH_LENGTH, HASH_LENGTH);
|
|
12755
|
-
var HashZod =
|
|
12757
|
+
var HashZod = package_default.string().regex(HashRegEx, { message: "Invalid hex format" }).transform((val) => val);
|
|
12756
12758
|
var HashToJsonZod = HashZod.transform((v) => v);
|
|
12757
|
-
var JsonToHashZod =
|
|
12759
|
+
var JsonToHashZod = package_default.string().transform((v) => asHash(v, true));
|
|
12758
12760
|
function hexToBigInt(hex3) {
|
|
12759
12761
|
return BigInt(hexFromHexString(hex3, { prefix: true }));
|
|
12760
12762
|
}
|
|
12761
|
-
var BigIntToJsonZod =
|
|
12762
|
-
var JsonToBigIntZod =
|
|
12763
|
+
var BigIntToJsonZod = package_default.bigint().nonnegative().transform((x) => toHex(x));
|
|
12764
|
+
var JsonToBigIntZod = package_default.string().transform((x) => toHex(x)).transform((x) => hexToBigInt(x));
|
|
12763
12765
|
|
|
12764
|
-
// ../../../../../../node_modules/.store/@xylabs-threads-npm-5.0.
|
|
12766
|
+
// ../../../../../../node_modules/.store/@xylabs-threads-npm-5.0.37-12dec43a8d/package/dist/browser/worker/worker.browser.mjs
|
|
12765
12767
|
var import_is_observable_2_1_0 = __toESM(require_package(), 1);
|
|
12766
12768
|
var DefaultErrorSerializer = {
|
|
12767
12769
|
deserialize(message) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/hash",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.24",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -44,7 +44,10 @@
|
|
|
44
44
|
"types": "dist/neutral/index.d.ts",
|
|
45
45
|
"files": [
|
|
46
46
|
"dist",
|
|
47
|
-
"src"
|
|
47
|
+
"src",
|
|
48
|
+
"!**/*.bench.*",
|
|
49
|
+
"!**/*.spec.*",
|
|
50
|
+
"!**/*.test.*"
|
|
48
51
|
],
|
|
49
52
|
"scripts": {
|
|
50
53
|
"bundle": "yarn subtleHashBundle && yarn wasmHashBundle",
|
|
@@ -54,24 +57,24 @@
|
|
|
54
57
|
"wasmHashBundle": "esbuild src/worker/wasmHash.ts --bundle --outfile=dist/browser/worker/wasmHash-bundle.mjs --target=chrome120,firefox120,safari14,edge120"
|
|
55
58
|
},
|
|
56
59
|
"dependencies": {
|
|
57
|
-
"@xylabs/assert": "~5.0.
|
|
58
|
-
"@xylabs/hex": "~5.0.
|
|
59
|
-
"@xylabs/object": "~5.0.
|
|
60
|
-
"@xylabs/platform": "~5.0.
|
|
61
|
-
"@xylabs/threads": "~5.0.
|
|
62
|
-
"@xylabs/typeof": "~5.0.
|
|
63
|
-
"@xyo-network/wasm": "~5.1.
|
|
60
|
+
"@xylabs/assert": "~5.0.37",
|
|
61
|
+
"@xylabs/hex": "~5.0.37",
|
|
62
|
+
"@xylabs/object": "~5.0.37",
|
|
63
|
+
"@xylabs/platform": "~5.0.37",
|
|
64
|
+
"@xylabs/threads": "~5.0.37",
|
|
65
|
+
"@xylabs/typeof": "~5.0.37",
|
|
66
|
+
"@xyo-network/wasm": "~5.1.24",
|
|
64
67
|
"hash-wasm": "~4.12.0"
|
|
65
68
|
},
|
|
66
69
|
"devDependencies": {
|
|
67
|
-
"@xylabs/delay": "~5.0.
|
|
70
|
+
"@xylabs/delay": "~5.0.37",
|
|
68
71
|
"@xylabs/ts-scripts-yarn3": "~7.2.8",
|
|
69
72
|
"@xylabs/tsconfig": "~7.2.8",
|
|
70
|
-
"@xylabs/vitest-extended": "~5.0.
|
|
73
|
+
"@xylabs/vitest-extended": "~5.0.37",
|
|
71
74
|
"esbuild": "~0.27.0",
|
|
72
75
|
"publint": "~0.3.15",
|
|
73
76
|
"typescript": "~5.9.3",
|
|
74
|
-
"vitest": "~4.0.
|
|
77
|
+
"vitest": "~4.0.10"
|
|
75
78
|
},
|
|
76
79
|
"publishConfig": {
|
|
77
80
|
"access": "public"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectHasher.bigobj-parallel.perf.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/ObjectHasher.bigobj-parallel.perf.spec.ts"],"names":[],"mappings":"AACA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectHasher.bigobj.perf.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/ObjectHasher.bigobj.perf.spec.ts"],"names":[],"mappings":"AACA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectHasher.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/ObjectHasher.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectHasher.subtle.perf.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/ObjectHasher.subtle.perf.spec.ts"],"names":[],"mappings":"AAIA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectHasher.wasm-subtle.perf.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/ObjectHasher.wasm-subtle.perf.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectHasher.wasm.perf.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/ObjectHasher.wasm.perf.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"removeEmptyFields.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/removeEmptyFields.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectHasher.bigobj-parallel.perf.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/ObjectHasher.bigobj-parallel.perf.spec.ts"],"names":[],"mappings":"AACA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectHasher.bigobj.perf.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/ObjectHasher.bigobj.perf.spec.ts"],"names":[],"mappings":"AACA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectHasher.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/ObjectHasher.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectHasher.subtle.perf.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/ObjectHasher.subtle.perf.spec.ts"],"names":[],"mappings":"AAIA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectHasher.wasm-subtle.perf.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/ObjectHasher.wasm-subtle.perf.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectHasher.wasm.perf.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/ObjectHasher.wasm.perf.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"removeEmptyFields.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/removeEmptyFields.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectHasher.bigobj-parallel.perf.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/ObjectHasher.bigobj-parallel.perf.spec.ts"],"names":[],"mappings":"AACA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectHasher.bigobj.perf.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/ObjectHasher.bigobj.perf.spec.ts"],"names":[],"mappings":"AACA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectHasher.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/ObjectHasher.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectHasher.subtle.perf.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/ObjectHasher.subtle.perf.spec.ts"],"names":[],"mappings":"AAIA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectHasher.wasm-subtle.perf.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/ObjectHasher.wasm-subtle.perf.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectHasher.wasm.perf.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/ObjectHasher.wasm.perf.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"removeEmptyFields.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/removeEmptyFields.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-statements */
|
|
2
|
-
import '@xylabs/vitest-extended'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
beforeAll,
|
|
6
|
-
describe, expect, test,
|
|
7
|
-
} from 'vitest'
|
|
8
|
-
|
|
9
|
-
import { NodeObjectHasher as ObjectHasher } from '../NodeObjectHasher.ts'
|
|
10
|
-
|
|
11
|
-
describe('Hasher - BigObject Parallel ', () => {
|
|
12
|
-
const testObject = {
|
|
13
|
-
testArray: [1, 2, 3],
|
|
14
|
-
testBoolean: true,
|
|
15
|
-
testNull: null,
|
|
16
|
-
testNullObject: { t: null, x: undefined },
|
|
17
|
-
testNumber: 5,
|
|
18
|
-
testObject: { t: 1 },
|
|
19
|
-
testSomeNullObject: {
|
|
20
|
-
s: 1, t: null, x: undefined,
|
|
21
|
-
},
|
|
22
|
-
testString: 'hello there. this is a pretty long string. what do you think?',
|
|
23
|
-
testUndefined: undefined,
|
|
24
|
-
}
|
|
25
|
-
const bigObject = {
|
|
26
|
-
testArray: [1, 2, 3],
|
|
27
|
-
testBoolean: true,
|
|
28
|
-
testNull: null,
|
|
29
|
-
testNullObject: { t: null, x: undefined },
|
|
30
|
-
testNumber: 5,
|
|
31
|
-
testObjArray: [testObject],
|
|
32
|
-
testObject: { t: 1 },
|
|
33
|
-
testSomeNullObject: {
|
|
34
|
-
s: 1, t: null, x: undefined,
|
|
35
|
-
},
|
|
36
|
-
testString: 'hello there. this is a pretty long string. what do you think?',
|
|
37
|
-
testUndefined: undefined,
|
|
38
|
-
}
|
|
39
|
-
for (let i = 0; i < 256; i++) {
|
|
40
|
-
bigObject.testObjArray.push(testObject)
|
|
41
|
-
}
|
|
42
|
-
beforeAll(async () => {
|
|
43
|
-
await ObjectHasher.wasmInitialized
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
test('wasm vs js (performance-big-obj)', async () => {
|
|
47
|
-
const objSize = JSON.stringify(bigObject).length
|
|
48
|
-
const stringifyStart = Date.now()
|
|
49
|
-
for (let x = 0; x < 100; x++) {
|
|
50
|
-
JSON.stringify(bigObject)
|
|
51
|
-
}
|
|
52
|
-
const stringifyDuration = Date.now() - stringifyStart
|
|
53
|
-
console.log(`stringifyDuration: ${stringifyDuration}`)
|
|
54
|
-
console.log(`objSize: ${objSize}`)
|
|
55
|
-
|
|
56
|
-
ObjectHasher.warnIfUsingJsHash = true
|
|
57
|
-
ObjectHasher.wasmSupport.allowWasm = false
|
|
58
|
-
ObjectHasher.allowSubtle = true
|
|
59
|
-
const subtleHashStart = Date.now()
|
|
60
|
-
const subtlePromises: Promise<string>[] = []
|
|
61
|
-
for (let x = 0; x < 180; x++) {
|
|
62
|
-
subtlePromises.push(ObjectHasher.hash(bigObject))
|
|
63
|
-
}
|
|
64
|
-
await Promise.all(subtlePromises)
|
|
65
|
-
const subtleHashDuration = Date.now() - subtleHashStart
|
|
66
|
-
console.log(`subtleHashDuration: ${subtleHashDuration} [${await ObjectHasher.hash(bigObject)}]`)
|
|
67
|
-
|
|
68
|
-
ObjectHasher.warnIfUsingJsHash = false
|
|
69
|
-
ObjectHasher.wasmSupport.allowWasm = false
|
|
70
|
-
ObjectHasher.allowSubtle = false
|
|
71
|
-
const jsHashStart = Date.now()
|
|
72
|
-
const jsPromises: Promise<string>[] = []
|
|
73
|
-
for (let x = 0; x < 180; x++) {
|
|
74
|
-
jsPromises.push(ObjectHasher.hash(bigObject))
|
|
75
|
-
}
|
|
76
|
-
await Promise.all(jsPromises)
|
|
77
|
-
const jsHashDuration = Date.now() - jsHashStart
|
|
78
|
-
console.log(`jsHashDuration: ${jsHashDuration} [${await ObjectHasher.hash(bigObject)}]`)
|
|
79
|
-
|
|
80
|
-
ObjectHasher.wasmSupport.allowWasm = true
|
|
81
|
-
const wasmHashStart = Date.now()
|
|
82
|
-
const wasmPromises: Promise<string>[] = []
|
|
83
|
-
for (let x = 0; x < 180; x++) {
|
|
84
|
-
wasmPromises.push(ObjectHasher.hash(bigObject))
|
|
85
|
-
}
|
|
86
|
-
await Promise.all(wasmPromises)
|
|
87
|
-
const wasmHashDuration = Date.now() - wasmHashStart
|
|
88
|
-
console.log(`wasmHashDuration: ${wasmHashDuration} [${await ObjectHasher.hash(bigObject)}]`)
|
|
89
|
-
expect(stringifyDuration).toBeDefined()
|
|
90
|
-
expect(wasmHashDuration).toBeDefined()
|
|
91
|
-
expect(jsHashDuration).toBeDefined()
|
|
92
|
-
console.log(
|
|
93
|
-
`Wasm is ${jsHashDuration - wasmHashDuration}ms (${((1 - wasmHashDuration / jsHashDuration) * 100).toPrecision(
|
|
94
|
-
2,
|
|
95
|
-
)}%) faster [${wasmHashDuration}ms vs ${jsHashDuration}ms ]`,
|
|
96
|
-
)
|
|
97
|
-
})
|
|
98
|
-
})
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-statements */
|
|
2
|
-
import '@xylabs/vitest-extended'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
beforeAll,
|
|
6
|
-
describe, expect, test,
|
|
7
|
-
} from 'vitest'
|
|
8
|
-
|
|
9
|
-
import { NodeObjectHasher as ObjectHasher } from '../NodeObjectHasher.ts'
|
|
10
|
-
/*
|
|
11
|
-
const cryptoTest = async () => {
|
|
12
|
-
const testObject = {
|
|
13
|
-
testArray: [1, 2, 3],
|
|
14
|
-
testBoolean: true,
|
|
15
|
-
testNull: null,
|
|
16
|
-
testNullObject: { t: null, x: undefined },
|
|
17
|
-
testNumber: 5,
|
|
18
|
-
testObject: { t: 1 },
|
|
19
|
-
testSomeNullObject: { s: 1, t: null, x: undefined },
|
|
20
|
-
testString: 'hello there. this is a pretty long string. what do you think?',
|
|
21
|
-
testUndefined: undefined,
|
|
22
|
-
}
|
|
23
|
-
const bigObject = {
|
|
24
|
-
testArray: [1, 2, 3],
|
|
25
|
-
testBoolean: true,
|
|
26
|
-
testNull: null,
|
|
27
|
-
testNullObject: { t: null, x: undefined },
|
|
28
|
-
testNumber: 5,
|
|
29
|
-
testObjArray: [testObject],
|
|
30
|
-
testObject: { t: 1 },
|
|
31
|
-
testSomeNullObject: { s: 1, t: null, x: undefined },
|
|
32
|
-
testString: 'hello there. this is a pretty long string. what do you think?',
|
|
33
|
-
testUndefined: undefined,
|
|
34
|
-
}
|
|
35
|
-
for (let i = 0; i < 10000; i++) {
|
|
36
|
-
bigObject.testObjArray.push(testObject)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const objSize = JSON.stringify(bigObject).length
|
|
40
|
-
console.log(`objSize: ${objSize}`)
|
|
41
|
-
const stringifiedObj = JSON.stringify(bigObject)
|
|
42
|
-
const enc = new TextEncoder()
|
|
43
|
-
const b = enc.encode(stringifiedObj)
|
|
44
|
-
const cryptoHashStart = Date.now()
|
|
45
|
-
for (let x = 0; x < 100; x++) {
|
|
46
|
-
await crypto.subtle.digest('SHA-256', b)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const toHexString = (bytes) => {
|
|
50
|
-
return Array.from(bytes, (byte) => {
|
|
51
|
-
return ('0' + (byte & 0xff).toString(16)).slice(-2)
|
|
52
|
-
}).join('')
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const cryptoHashDuration = Date.now() - cryptoHashStart
|
|
56
|
-
const result = await crypto.subtle.digest('SHA-256', b)
|
|
57
|
-
const dataview = new DataView(result)
|
|
58
|
-
const array = new Uint8Array(32)
|
|
59
|
-
for (let i = 0; i < dataview.byteLength; i++) {
|
|
60
|
-
array[i] = dataview.getUint8(i)
|
|
61
|
-
}
|
|
62
|
-
console.log(`Result: ${toHexString(array)}`)
|
|
63
|
-
console.log(`cryptoHashDuration: ${cryptoHashDuration}`)
|
|
64
|
-
}
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
|
-
describe.skip('Hasher - BigObject', () => {
|
|
68
|
-
const testObject = {
|
|
69
|
-
testArray: [1, 2, 3],
|
|
70
|
-
testBoolean: true,
|
|
71
|
-
testNull: null,
|
|
72
|
-
testNullObject: { t: null, x: undefined },
|
|
73
|
-
testNumber: 5,
|
|
74
|
-
testObject: { t: 1 },
|
|
75
|
-
testSomeNullObject: {
|
|
76
|
-
s: 1, t: null, x: undefined,
|
|
77
|
-
},
|
|
78
|
-
testString: 'hello there. this is a pretty long string. what do you think?',
|
|
79
|
-
testUndefined: undefined,
|
|
80
|
-
}
|
|
81
|
-
const bigObject = {
|
|
82
|
-
testArray: [1, 2, 3],
|
|
83
|
-
testBoolean: true,
|
|
84
|
-
testNull: null,
|
|
85
|
-
testNullObject: { t: null, x: undefined },
|
|
86
|
-
testNumber: 5,
|
|
87
|
-
testObjArray: [testObject],
|
|
88
|
-
testObject: { t: 1 },
|
|
89
|
-
testSomeNullObject: {
|
|
90
|
-
s: 1, t: null, x: undefined,
|
|
91
|
-
},
|
|
92
|
-
testString: 'hello there. this is a pretty long string. what do you think?',
|
|
93
|
-
testUndefined: undefined,
|
|
94
|
-
}
|
|
95
|
-
for (let i = 0; i < 10_000; i++) {
|
|
96
|
-
bigObject.testObjArray.push(testObject)
|
|
97
|
-
}
|
|
98
|
-
beforeAll(async () => {
|
|
99
|
-
await ObjectHasher.wasmInitialized
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
test('wasm vs js (performance-big-obj)', async () => {
|
|
103
|
-
const objSize = JSON.stringify(bigObject).length
|
|
104
|
-
const stringifyStart = Date.now()
|
|
105
|
-
for (let x = 0; x < 100; x++) {
|
|
106
|
-
JSON.stringify(bigObject)
|
|
107
|
-
}
|
|
108
|
-
const stringifyDuration = Date.now() - stringifyStart
|
|
109
|
-
console.log(`stringifyDuration: ${stringifyDuration}`)
|
|
110
|
-
console.log(`objSize: ${objSize}`)
|
|
111
|
-
|
|
112
|
-
ObjectHasher.warnIfUsingJsHash = true
|
|
113
|
-
ObjectHasher.wasmSupport.allowWasm = false
|
|
114
|
-
ObjectHasher.allowSubtle = true
|
|
115
|
-
const subtleHashStart = Date.now()
|
|
116
|
-
for (let x = 0; x < 100; x++) {
|
|
117
|
-
await ObjectHasher.hash(bigObject)
|
|
118
|
-
}
|
|
119
|
-
const subtleHashDuration = Date.now() - subtleHashStart
|
|
120
|
-
console.log(`subtleHashDuration: ${subtleHashDuration} [${await ObjectHasher.hash(bigObject)}]`)
|
|
121
|
-
|
|
122
|
-
ObjectHasher.warnIfUsingJsHash = false
|
|
123
|
-
ObjectHasher.wasmSupport.allowWasm = false
|
|
124
|
-
ObjectHasher.allowSubtle = false
|
|
125
|
-
const jsHashStart = Date.now()
|
|
126
|
-
for (let x = 0; x < 100; x++) {
|
|
127
|
-
await ObjectHasher.hash(bigObject)
|
|
128
|
-
}
|
|
129
|
-
const jsHashDuration = Date.now() - jsHashStart
|
|
130
|
-
console.log(`jsHashDuration: ${jsHashDuration} [${await ObjectHasher.hash(bigObject)}]`)
|
|
131
|
-
|
|
132
|
-
ObjectHasher.wasmSupport.allowWasm = true
|
|
133
|
-
const wasmHashStart = Date.now()
|
|
134
|
-
for (let x = 0; x < 100; x++) {
|
|
135
|
-
await ObjectHasher.hash(bigObject)
|
|
136
|
-
}
|
|
137
|
-
const wasmHashDuration = Date.now() - wasmHashStart
|
|
138
|
-
console.log(`wasmHashDuration: ${wasmHashDuration} [${await ObjectHasher.hash(bigObject)}]`)
|
|
139
|
-
expect(stringifyDuration).toBeDefined()
|
|
140
|
-
expect(wasmHashDuration).toBeDefined()
|
|
141
|
-
expect(jsHashDuration).toBeDefined()
|
|
142
|
-
console.log(
|
|
143
|
-
`Wasm is ${jsHashDuration - wasmHashDuration}ms (${((1 - wasmHashDuration / jsHashDuration) * 100).toPrecision(
|
|
144
|
-
2,
|
|
145
|
-
)}%) faster [${wasmHashDuration}ms vs ${jsHashDuration}ms ]`,
|
|
146
|
-
)
|
|
147
|
-
})
|
|
148
|
-
})
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import '@xylabs/vitest-extended'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
beforeAll, describe, expect, test,
|
|
5
|
-
} from 'vitest'
|
|
6
|
-
|
|
7
|
-
import { NodeObjectHasher as ObjectHasher } from '../NodeObjectHasher.ts'
|
|
8
|
-
|
|
9
|
-
const perfIterations = 50
|
|
10
|
-
|
|
11
|
-
describe('Hasher', () => {
|
|
12
|
-
const testObject = {
|
|
13
|
-
testArray: [1, 2, 3],
|
|
14
|
-
testBoolean: true,
|
|
15
|
-
testNull: null,
|
|
16
|
-
testNullObject: { t: null, x: undefined },
|
|
17
|
-
testNumber: 5,
|
|
18
|
-
testObject: { t: 1 },
|
|
19
|
-
testSomeNullObject: {
|
|
20
|
-
s: 1, t: null, x: undefined,
|
|
21
|
-
},
|
|
22
|
-
testString: 'hello there. this is a pretty long string. what do you think?',
|
|
23
|
-
testUndefined: undefined,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
beforeAll(async () => {
|
|
27
|
-
await ObjectHasher.wasmInitialized
|
|
28
|
-
})
|
|
29
|
-
test('wasm vs js (compatibility-sync)', async () => {
|
|
30
|
-
ObjectHasher.warnIfUsingJsHash = false
|
|
31
|
-
ObjectHasher.allowSubtle = false
|
|
32
|
-
ObjectHasher.wasmSupport.allowWasm = false
|
|
33
|
-
const jsHash = await ObjectHasher.hash(testObject)
|
|
34
|
-
ObjectHasher.wasmSupport.allowWasm = true
|
|
35
|
-
const wasmHash = await ObjectHasher.hash(testObject)
|
|
36
|
-
expect(jsHash).toEqual(wasmHash)
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
test('wasm vs js (compatibility-async)', async () => {
|
|
40
|
-
ObjectHasher.warnIfUsingJsHash = false
|
|
41
|
-
ObjectHasher.allowSubtle = false
|
|
42
|
-
ObjectHasher.wasmSupport.allowWasm = false
|
|
43
|
-
const jsHash = await ObjectHasher.hash(testObject)
|
|
44
|
-
ObjectHasher.wasmSupport.allowWasm = true
|
|
45
|
-
const wasmHash = await ObjectHasher.hash(testObject)
|
|
46
|
-
expect(jsHash).toEqual(wasmHash)
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
test('subtle vs js (compatibility-async)', async () => {
|
|
50
|
-
ObjectHasher.warnIfUsingJsHash = false
|
|
51
|
-
ObjectHasher.allowSubtle = false
|
|
52
|
-
ObjectHasher.wasmSupport.allowWasm = false
|
|
53
|
-
const jsHash = await ObjectHasher.hash(testObject)
|
|
54
|
-
ObjectHasher.allowSubtle = true
|
|
55
|
-
const subtleHash = await ObjectHasher.hash(testObject)
|
|
56
|
-
expect(jsHash).toEqual(subtleHash)
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
test('wasm vs js (performance-serial)', async () => {
|
|
60
|
-
ObjectHasher.warnIfUsingJsHash = false
|
|
61
|
-
ObjectHasher.allowSubtle = false
|
|
62
|
-
ObjectHasher.wasmSupport.allowWasm = false
|
|
63
|
-
const jsHashStart = Date.now()
|
|
64
|
-
for (let x = 0; x < perfIterations; x++) {
|
|
65
|
-
await ObjectHasher.hash({ ...testObject, nonce: x })
|
|
66
|
-
}
|
|
67
|
-
const jsHashDuration = Date.now() - jsHashStart
|
|
68
|
-
ObjectHasher.wasmSupport.allowWasm = true
|
|
69
|
-
const wasmHashStart = Date.now()
|
|
70
|
-
for (let x = 0; x < perfIterations; x++) {
|
|
71
|
-
await ObjectHasher.hash({ ...testObject, nonce: x })
|
|
72
|
-
}
|
|
73
|
-
const wasmHashDuration = Date.now() - wasmHashStart
|
|
74
|
-
expect(wasmHashDuration).toBeDefined()
|
|
75
|
-
expect(jsHashDuration).toBeDefined()
|
|
76
|
-
console.log(
|
|
77
|
-
`Wasm (serial) is ${jsHashDuration - wasmHashDuration}ms (${((1 - wasmHashDuration / jsHashDuration) * 100).toPrecision(
|
|
78
|
-
2,
|
|
79
|
-
)}%) faster [${wasmHashDuration}ms vs ${jsHashDuration}ms ]`,
|
|
80
|
-
)
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
test.skip('wasm vs js (performance-parallel)', async () => {
|
|
84
|
-
ObjectHasher.warnIfUsingJsHash = false
|
|
85
|
-
ObjectHasher.allowSubtle = false
|
|
86
|
-
ObjectHasher.wasmSupport.allowWasm = false
|
|
87
|
-
const jsTestObjects: ObjectHasher[] = []
|
|
88
|
-
for (let x = 0; x < perfIterations; x++) {
|
|
89
|
-
jsTestObjects.push(new ObjectHasher({ ...testObject, nonce: x }))
|
|
90
|
-
}
|
|
91
|
-
const jsHashStart = Date.now()
|
|
92
|
-
await Promise.all(jsTestObjects.map(obj => obj.hash()))
|
|
93
|
-
const jsHashDuration = Date.now() - jsHashStart
|
|
94
|
-
ObjectHasher.allowSubtle = false
|
|
95
|
-
ObjectHasher.wasmSupport.allowWasm = true
|
|
96
|
-
const wasmTestObjects: ObjectHasher[] = []
|
|
97
|
-
for (let x = 0; x < perfIterations; x++) {
|
|
98
|
-
wasmTestObjects.push(new ObjectHasher({ ...testObject, nonce: x }))
|
|
99
|
-
}
|
|
100
|
-
const wasmHashStart = Date.now()
|
|
101
|
-
await Promise.all(wasmTestObjects.map(obj => obj.hash()))
|
|
102
|
-
const wasmHashDuration = Date.now() - wasmHashStart
|
|
103
|
-
expect(wasmHashDuration).toBeDefined()
|
|
104
|
-
expect(jsHashDuration).toBeDefined()
|
|
105
|
-
console.log(
|
|
106
|
-
`Wasm (parallel) is ${jsHashDuration - wasmHashDuration}ms (${((1 - wasmHashDuration / jsHashDuration) * 100).toPrecision(
|
|
107
|
-
2,
|
|
108
|
-
)}%) faster than js [${wasmHashDuration}ms vs ${jsHashDuration}ms ]`,
|
|
109
|
-
)
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
test('subtle vs js (performance-parallel)', async () => {
|
|
113
|
-
ObjectHasher.warnIfUsingJsHash = false
|
|
114
|
-
ObjectHasher.allowSubtle = false
|
|
115
|
-
ObjectHasher.wasmSupport.allowWasm = false
|
|
116
|
-
const jsTestObjects: ObjectHasher[] = []
|
|
117
|
-
for (let x = 0; x < perfIterations; x++) {
|
|
118
|
-
jsTestObjects.push(new ObjectHasher({ ...testObject, nonce: x }))
|
|
119
|
-
}
|
|
120
|
-
const jsHashStart = Date.now()
|
|
121
|
-
await Promise.all(jsTestObjects.map(obj => obj.hash()))
|
|
122
|
-
const jsHashDuration = Date.now() - jsHashStart
|
|
123
|
-
ObjectHasher.allowSubtle = true
|
|
124
|
-
ObjectHasher.wasmSupport.allowWasm = false
|
|
125
|
-
const subtleTestObjects: ObjectHasher[] = []
|
|
126
|
-
for (let x = 0; x < perfIterations; x++) {
|
|
127
|
-
subtleTestObjects.push(new ObjectHasher({ ...testObject, nonce: x }))
|
|
128
|
-
}
|
|
129
|
-
const subtleHashStart = Date.now()
|
|
130
|
-
await Promise.all(subtleTestObjects.map(obj => obj.hash()))
|
|
131
|
-
const subtleHashDuration = Date.now() - subtleHashStart
|
|
132
|
-
expect(subtleHashDuration).toBeDefined()
|
|
133
|
-
expect(jsHashDuration).toBeDefined()
|
|
134
|
-
console.log(
|
|
135
|
-
`Subtle (parallel) is ${jsHashDuration - subtleHashDuration}ms (${((1 - subtleHashDuration / jsHashDuration) * 100).toPrecision(
|
|
136
|
-
2,
|
|
137
|
-
)}%) faster than js [${subtleHashDuration}ms vs ${jsHashDuration}ms ]`,
|
|
138
|
-
)
|
|
139
|
-
})
|
|
140
|
-
})
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { NodeObjectHasher as ObjectHasher } from '../NodeObjectHasher.ts'
|
|
2
|
-
|
|
3
|
-
const perfIterations = 1000
|
|
4
|
-
|
|
5
|
-
import '@xylabs/vitest-extended'
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
beforeAll, describe, expect, test,
|
|
9
|
-
} from 'vitest'
|
|
10
|
-
|
|
11
|
-
describe('Hasher - Subtle performance', () => {
|
|
12
|
-
const testObject = {
|
|
13
|
-
testArray: [1, 2, 3],
|
|
14
|
-
testBoolean: true,
|
|
15
|
-
testNull: null,
|
|
16
|
-
testNullObject: { t: null, x: undefined },
|
|
17
|
-
testNumber: 5,
|
|
18
|
-
testObject: { t: 1 },
|
|
19
|
-
testSomeNullObject: {
|
|
20
|
-
s: 1, t: null, x: undefined,
|
|
21
|
-
},
|
|
22
|
-
testString: 'hello there. this is a pretty long string. what do you think?',
|
|
23
|
-
testUndefined: undefined,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
beforeAll(async () => {
|
|
27
|
-
await ObjectHasher.wasmInitialized
|
|
28
|
-
})
|
|
29
|
-
test('subtle vs js (performance-parallel)', async () => {
|
|
30
|
-
ObjectHasher.warnIfUsingJsHash = false
|
|
31
|
-
ObjectHasher.allowSubtle = false
|
|
32
|
-
ObjectHasher.wasmSupport.allowWasm = false
|
|
33
|
-
const jsTestObjects: ObjectHasher[] = []
|
|
34
|
-
for (let x = 0; x < perfIterations; x++) {
|
|
35
|
-
jsTestObjects.push(new ObjectHasher({ ...testObject, nonce: x }))
|
|
36
|
-
}
|
|
37
|
-
const jsHashStart = Date.now()
|
|
38
|
-
await Promise.all(jsTestObjects.map(obj => obj.hash()))
|
|
39
|
-
const jsHashDuration = Date.now() - jsHashStart
|
|
40
|
-
|
|
41
|
-
ObjectHasher.warnIfUsingJsHash = true
|
|
42
|
-
ObjectHasher.allowSubtle = true
|
|
43
|
-
ObjectHasher.wasmSupport.allowWasm = false
|
|
44
|
-
const subtleTestObjects: ObjectHasher[] = []
|
|
45
|
-
for (let x = 0; x < perfIterations; x++) {
|
|
46
|
-
subtleTestObjects.push(new ObjectHasher({ ...testObject, nonce: x }))
|
|
47
|
-
}
|
|
48
|
-
const subtleHashStart = Date.now()
|
|
49
|
-
await Promise.all(subtleTestObjects.map(obj => obj.hash()))
|
|
50
|
-
const subtleHashDuration = Date.now() - subtleHashStart
|
|
51
|
-
expect(subtleHashDuration).toBeDefined()
|
|
52
|
-
expect(jsHashDuration).toBeDefined()
|
|
53
|
-
console.log(
|
|
54
|
-
`Subtle (parallel) is ${jsHashDuration - subtleHashDuration}ms (${((1 - subtleHashDuration / jsHashDuration) * 100).toPrecision(
|
|
55
|
-
2,
|
|
56
|
-
)}%) faster than js [${subtleHashDuration}ms vs ${jsHashDuration}ms ]`,
|
|
57
|
-
)
|
|
58
|
-
})
|
|
59
|
-
})
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import '@xylabs/vitest-extended'
|
|
2
|
-
|
|
3
|
-
import { delay } from '@xylabs/delay'
|
|
4
|
-
import type { AnyObject } from '@xylabs/object'
|
|
5
|
-
import {
|
|
6
|
-
beforeAll,
|
|
7
|
-
describe, expect, test,
|
|
8
|
-
} from 'vitest'
|
|
9
|
-
|
|
10
|
-
import { NodeObjectHasher as ObjectHasher } from '../NodeObjectHasher.ts'
|
|
11
|
-
|
|
12
|
-
const perfIterations = 1000
|
|
13
|
-
|
|
14
|
-
describe('Hasher', () => {
|
|
15
|
-
const testObject = () => ({
|
|
16
|
-
salt: `${Date.now()}-${Math.floor(Math.random() * 1000)}`,
|
|
17
|
-
testArray: [1, 2, 3],
|
|
18
|
-
testBoolean: true,
|
|
19
|
-
testNull: null,
|
|
20
|
-
testNullObject: { t: null, x: undefined },
|
|
21
|
-
testNumber: 5,
|
|
22
|
-
testObject: { t: 1 },
|
|
23
|
-
testSomeNullObject: {
|
|
24
|
-
s: 1, t: null, x: undefined,
|
|
25
|
-
},
|
|
26
|
-
testString: 'hello there. this is a pretty long string. what do you think?',
|
|
27
|
-
testUndefined: undefined,
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
beforeAll(async () => {
|
|
31
|
-
await ObjectHasher.wasmInitialized
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
test('subtle vs wasm (performance-parallel)', async () => {
|
|
35
|
-
const testObjects: AnyObject[] = []
|
|
36
|
-
for (let x = 0; x < perfIterations; x++) {
|
|
37
|
-
testObjects.push(testObject())
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const subtleHashDuration = await (async () => {
|
|
41
|
-
ObjectHasher.allowSubtle = true
|
|
42
|
-
ObjectHasher.wasmSupport.allowWasm = false
|
|
43
|
-
// prime it
|
|
44
|
-
await Promise.all([{ length: 8 }].map(async (_, index) => await ObjectHasher.hash(testObjects[index])))
|
|
45
|
-
const subtleHashStart = Date.now()
|
|
46
|
-
const subtleResult = await Promise.all(testObjects.map(obj => ObjectHasher.hash(obj)))
|
|
47
|
-
console.log(`subtleResult count: ${subtleResult.length}`)
|
|
48
|
-
return Date.now() - subtleHashStart
|
|
49
|
-
})()
|
|
50
|
-
|
|
51
|
-
// allow for cleanup
|
|
52
|
-
await delay(2000)
|
|
53
|
-
|
|
54
|
-
const wasmHashDuration = await (async () => {
|
|
55
|
-
ObjectHasher.allowSubtle = false
|
|
56
|
-
ObjectHasher.wasmSupport.allowWasm = true
|
|
57
|
-
// prime it
|
|
58
|
-
await Promise.all([{ length: 8 }].map(async (_, index) => await ObjectHasher.hash(testObjects[index])))
|
|
59
|
-
const wasmHashStart = Date.now()
|
|
60
|
-
const wasmResult = await Promise.all(testObjects.map(obj => ObjectHasher.hash(obj)))
|
|
61
|
-
console.log(`wasmResult count: ${wasmResult.length}`)
|
|
62
|
-
return Date.now() - wasmHashStart
|
|
63
|
-
})()
|
|
64
|
-
|
|
65
|
-
expect(wasmHashDuration).toBeDefined()
|
|
66
|
-
expect(subtleHashDuration).toBeDefined()
|
|
67
|
-
console.log(
|
|
68
|
-
`Subtle (parallel) is ${wasmHashDuration - subtleHashDuration}ms (${((1 - subtleHashDuration / wasmHashDuration) * 100).toPrecision(
|
|
69
|
-
2,
|
|
70
|
-
)}%) faster than Wasm [${subtleHashDuration}ms vs ${wasmHashDuration}ms ]`,
|
|
71
|
-
)
|
|
72
|
-
console.log(`Wasm Average: ${(wasmHashDuration / perfIterations).toPrecision(2)}ms`)
|
|
73
|
-
console.log(`Subtle Average: ${(subtleHashDuration / perfIterations).toPrecision(2)}ms`)
|
|
74
|
-
})
|
|
75
|
-
})
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import '@xylabs/vitest-extended'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
beforeAll,
|
|
5
|
-
describe, expect, test,
|
|
6
|
-
} from 'vitest'
|
|
7
|
-
|
|
8
|
-
import { NodeObjectHasher as ObjectHasher } from '../NodeObjectHasher.ts'
|
|
9
|
-
|
|
10
|
-
const perfIterations = 1000
|
|
11
|
-
|
|
12
|
-
describe('Hasher', () => {
|
|
13
|
-
const testObject = {
|
|
14
|
-
testArray: [1, 2, 3],
|
|
15
|
-
testBoolean: true,
|
|
16
|
-
testNull: null,
|
|
17
|
-
testNullObject: { t: null, x: undefined },
|
|
18
|
-
testNumber: 5,
|
|
19
|
-
testObject: { t: 1 },
|
|
20
|
-
testSomeNullObject: {
|
|
21
|
-
s: 1, t: null, x: undefined,
|
|
22
|
-
},
|
|
23
|
-
testString: 'hello there. this is a pretty long string. what do you think?',
|
|
24
|
-
testUndefined: undefined,
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
beforeAll(async () => {
|
|
28
|
-
await ObjectHasher.wasmInitialized
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
test('wasm vs js (performance-parallel)', async () => {
|
|
32
|
-
ObjectHasher.warnIfUsingJsHash = false
|
|
33
|
-
ObjectHasher.allowSubtle = false
|
|
34
|
-
ObjectHasher.wasmSupport.allowWasm = false
|
|
35
|
-
const jsTestObjects: ObjectHasher[] = []
|
|
36
|
-
for (let x = 0; x < perfIterations; x++) {
|
|
37
|
-
jsTestObjects.push(new ObjectHasher({ ...testObject, nonce: x }))
|
|
38
|
-
}
|
|
39
|
-
const jsHashStart = Date.now()
|
|
40
|
-
await Promise.all(jsTestObjects.map(obj => obj.hash()))
|
|
41
|
-
const jsHashDuration = Date.now() - jsHashStart
|
|
42
|
-
ObjectHasher.warnIfUsingJsHash = true
|
|
43
|
-
ObjectHasher.allowSubtle = false
|
|
44
|
-
ObjectHasher.wasmSupport.allowWasm = true
|
|
45
|
-
const wasmTestObjects: ObjectHasher[] = []
|
|
46
|
-
for (let x = 0; x < perfIterations; x++) {
|
|
47
|
-
wasmTestObjects.push(new ObjectHasher({ ...testObject, nonce: x }))
|
|
48
|
-
}
|
|
49
|
-
const wasmHashStart = Date.now()
|
|
50
|
-
await Promise.all(wasmTestObjects.map(obj => obj.hash()))
|
|
51
|
-
const wasmHashDuration = Date.now() - wasmHashStart
|
|
52
|
-
expect(wasmHashDuration).toBeDefined()
|
|
53
|
-
expect(jsHashDuration).toBeDefined()
|
|
54
|
-
console.log(
|
|
55
|
-
`Wasm (parallel) is ${jsHashDuration - wasmHashDuration}ms (${((1 - wasmHashDuration / jsHashDuration) * 100).toPrecision(
|
|
56
|
-
2,
|
|
57
|
-
)}%) faster than js [${wasmHashDuration}ms vs ${jsHashDuration}ms ]`,
|
|
58
|
-
)
|
|
59
|
-
})
|
|
60
|
-
})
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import '@xylabs/vitest-extended'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
describe, expect, test,
|
|
5
|
-
} from 'vitest'
|
|
6
|
-
|
|
7
|
-
import { removeEmptyFields } from '../removeEmptyFields.ts'
|
|
8
|
-
|
|
9
|
-
describe('removeEmptyFields', () => {
|
|
10
|
-
test('deep', () => {
|
|
11
|
-
const testObject = {
|
|
12
|
-
testArray: [1, 2, 3],
|
|
13
|
-
testBoolean: true,
|
|
14
|
-
testNull: null,
|
|
15
|
-
testNullObject: { t: null, x: undefined },
|
|
16
|
-
testNumber: 5,
|
|
17
|
-
testObject: { t: 1 },
|
|
18
|
-
testSomeNullObject: {
|
|
19
|
-
s: 1, t: null, x: undefined,
|
|
20
|
-
},
|
|
21
|
-
testString: 'hi',
|
|
22
|
-
testUndefined: undefined,
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const result = removeEmptyFields(testObject)
|
|
26
|
-
|
|
27
|
-
expect(Object.keys(result).length).toBe(8)
|
|
28
|
-
expect(Object.keys(result.testSomeNullObject as object).length).toBe(2)
|
|
29
|
-
expect(Object.keys(result.testNullObject as object).length).toBe(1)
|
|
30
|
-
})
|
|
31
|
-
})
|