querysub 0.433.0 → 0.437.0
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/.eslintrc.js +50 -50
- package/bin/deploy.js +0 -0
- package/bin/function.js +0 -0
- package/bin/server.js +0 -0
- package/costsBenefits.txt +115 -115
- package/deploy.ts +2 -2
- package/package.json +1 -1
- package/spec.txt +1192 -1192
- package/src/-a-archives/archives.ts +202 -202
- package/src/-a-archives/archivesDisk.ts +454 -454
- package/src/-a-auth/certs.ts +540 -540
- package/src/-a-auth/node-forge-ed25519.d.ts +16 -16
- package/src/-b-authorities/dnsAuthority.ts +138 -138
- package/src/-c-identity/IdentityController.ts +258 -258
- package/src/-d-trust/NetworkTrust2.ts +180 -180
- package/src/-e-certs/EdgeCertController.ts +252 -252
- package/src/-e-certs/certAuthority.ts +201 -201
- package/src/-f-node-discovery/NodeDiscovery.ts +640 -640
- package/src/-g-core-values/NodeCapabilities.ts +200 -200
- package/src/-h-path-value-serialize/stringSerializer.ts +175 -175
- package/src/0-path-value-core/PathValueCommitter.ts +468 -468
- package/src/0-path-value-core/pathValueCore.ts +2 -2
- package/src/2-proxy/PathValueProxyWatcher.ts +2542 -2542
- package/src/2-proxy/TransactionDelayer.ts +94 -94
- package/src/2-proxy/pathDatabaseProxyBase.ts +36 -36
- package/src/2-proxy/pathValueProxy.ts +159 -159
- package/src/3-path-functions/PathFunctionRunnerMain.ts +87 -87
- package/src/3-path-functions/pathFunctionLoader.ts +516 -516
- package/src/3-path-functions/tests/rejectTest.ts +76 -76
- package/src/4-deploy/deployCheck.ts +6 -6
- package/src/4-dom/css.tsx +29 -29
- package/src/4-dom/cssTypes.d.ts +211 -211
- package/src/4-dom/qreact.tsx +2799 -2799
- package/src/4-dom/qreactTest.tsx +410 -410
- package/src/4-querysub/permissions.ts +335 -335
- package/src/4-querysub/querysubPrediction.ts +483 -483
- package/src/5-diagnostics/qreactDebug.tsx +346 -346
- package/src/TestController.ts +34 -34
- package/src/bits.ts +104 -104
- package/src/buffers.ts +69 -69
- package/src/diagnostics/ActionsHistory.ts +57 -57
- package/src/diagnostics/listenOnDebugger.ts +71 -71
- package/src/diagnostics/periodic.ts +111 -111
- package/src/diagnostics/trackResources.ts +91 -91
- package/src/diagnostics/watchdog.ts +120 -120
- package/src/errors.ts +133 -133
- package/src/forceProduction.ts +2 -2
- package/src/fs.ts +80 -80
- package/src/functional/diff.ts +857 -857
- package/src/functional/promiseCache.ts +78 -78
- package/src/functional/random.ts +8 -8
- package/src/functional/stats.ts +60 -60
- package/src/heapDumps.ts +665 -665
- package/src/https.ts +1 -1
- package/src/library-components/AspectSizedComponent.tsx +87 -87
- package/src/library-components/ButtonSelector.tsx +64 -64
- package/src/library-components/DropdownCustom.tsx +150 -150
- package/src/library-components/DropdownSelector.tsx +31 -31
- package/src/library-components/InlinePopup.tsx +66 -66
- package/src/misc/color.ts +29 -29
- package/src/misc/hash.ts +83 -83
- package/src/misc/ipPong.js +13 -13
- package/src/misc/networking.ts +1 -1
- package/src/misc/random.ts +44 -44
- package/src/misc.ts +196 -196
- package/src/path.ts +255 -255
- package/src/persistentLocalStore.ts +41 -41
- package/src/promise.ts +14 -14
- package/src/storage/fileSystemPointer.ts +71 -71
- package/src/test/heapProcess.ts +35 -35
- package/src/zip.ts +15 -15
- package/tsconfig.json +26 -26
- package/yarnSpec.txt +56 -56
package/src/TestController.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
module.allowclient = true;
|
|
2
|
-
|
|
3
|
-
import debugbreak from "debugbreak";
|
|
4
|
-
import { SocketFunction } from "socket-function/SocketFunction";
|
|
5
|
-
import { IdentityController_getReconnectNodeId } from "./-c-identity/IdentityController";
|
|
6
|
-
|
|
7
|
-
import { requiresNetworkTrustHook } from "./-d-trust/NetworkTrust2";
|
|
8
|
-
import os from "os";
|
|
9
|
-
|
|
10
|
-
class TestControllerBase {
|
|
11
|
-
async test() {
|
|
12
|
-
const caller = SocketFunction.getCaller();
|
|
13
|
-
console.log(`test called from ${caller.nodeId}`);
|
|
14
|
-
return {
|
|
15
|
-
nodeId: caller?.nodeId,
|
|
16
|
-
reconnectNodeId: IdentityController_getReconnectNodeId(caller),
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
async getProcessId() {
|
|
20
|
-
return process.pid;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
export const TestController = SocketFunction.register(
|
|
26
|
-
"TestController-fbdd0aa9-a8ed-4d8c-80a8-8ab2f57c99db",
|
|
27
|
-
new TestControllerBase(),
|
|
28
|
-
() => ({
|
|
29
|
-
getProcessId: {},
|
|
30
|
-
test: {},
|
|
31
|
-
}),
|
|
32
|
-
() => ({
|
|
33
|
-
hooks: [requiresNetworkTrustHook],
|
|
34
|
-
})
|
|
1
|
+
module.allowclient = true;
|
|
2
|
+
|
|
3
|
+
import debugbreak from "debugbreak";
|
|
4
|
+
import { SocketFunction } from "socket-function/SocketFunction";
|
|
5
|
+
import { IdentityController_getReconnectNodeId } from "./-c-identity/IdentityController";
|
|
6
|
+
|
|
7
|
+
import { requiresNetworkTrustHook } from "./-d-trust/NetworkTrust2";
|
|
8
|
+
import os from "os";
|
|
9
|
+
|
|
10
|
+
class TestControllerBase {
|
|
11
|
+
async test() {
|
|
12
|
+
const caller = SocketFunction.getCaller();
|
|
13
|
+
console.log(`test called from ${caller.nodeId}`);
|
|
14
|
+
return {
|
|
15
|
+
nodeId: caller?.nodeId,
|
|
16
|
+
reconnectNodeId: IdentityController_getReconnectNodeId(caller),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
async getProcessId() {
|
|
20
|
+
return process.pid;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
export const TestController = SocketFunction.register(
|
|
26
|
+
"TestController-fbdd0aa9-a8ed-4d8c-80a8-8ab2f57c99db",
|
|
27
|
+
new TestControllerBase(),
|
|
28
|
+
() => ({
|
|
29
|
+
getProcessId: {},
|
|
30
|
+
test: {},
|
|
31
|
+
}),
|
|
32
|
+
() => ({
|
|
33
|
+
hooks: [requiresNetworkTrustHook],
|
|
34
|
+
})
|
|
35
35
|
);
|
package/src/bits.ts
CHANGED
|
@@ -1,105 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
/** Subtracts the smallest possible value from a number (a double). This makes it possible to convert an exclusive range end
|
|
3
|
-
* to an inclusive range end, which is sometimes required (as in, < x is the same as <= minusEpsilon(x)).
|
|
4
|
-
*/
|
|
5
|
-
export function minusEpsilon(value: number) {
|
|
6
|
-
let high = getHighUint32(value);
|
|
7
|
-
let low = getLowUint32(value);
|
|
8
|
-
|
|
9
|
-
if (low === 0) {
|
|
10
|
-
low = 2 ** 32 - 1;
|
|
11
|
-
high--;
|
|
12
|
-
} else {
|
|
13
|
-
low--;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return setLowHighUint32(low, high);
|
|
17
|
-
}
|
|
18
|
-
const maxUint32 = 2 ** 32 - 1;
|
|
19
|
-
export function addEpsilons(value: number, count: number) {
|
|
20
|
-
let high = getHighUint32(value);
|
|
21
|
-
let low = getLowUint32(value);
|
|
22
|
-
|
|
23
|
-
low += count;
|
|
24
|
-
if (low < 0) {
|
|
25
|
-
low += maxUint32;
|
|
26
|
-
high++;
|
|
27
|
-
} else if (low > maxUint32) {
|
|
28
|
-
low -= maxUint32;
|
|
29
|
-
high--;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return setLowHighUint32(low, high);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
let conversionBuffer = new Float64Array(1);
|
|
36
|
-
let conversionUint8Buffer = new Uint8Array(conversionBuffer.buffer);
|
|
37
|
-
let conversionUint32Buffer = new Uint32Array(conversionBuffer.buffer);
|
|
38
|
-
export function getHighUint32(num: number): number {
|
|
39
|
-
conversionBuffer[0] = num;
|
|
40
|
-
return conversionUint32Buffer[1];
|
|
41
|
-
}
|
|
42
|
-
export function getLowUint32(num: number): number {
|
|
43
|
-
conversionBuffer[0] = num;
|
|
44
|
-
return conversionUint32Buffer[0];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** IMPORTANT! Beware of comparisons with 64 bit numbers. getFloat64_fromBytes(4294136438, 168) !== getFloat64_fromBytes(4294136438, 168).
|
|
48
|
-
* USE is64BitEqual instead, OR, ensure the 2 highest bits are always 0.
|
|
49
|
-
*/
|
|
50
|
-
export function setLowHighUint32(low: number, high: number): number {
|
|
51
|
-
conversionUint32Buffer[0] = low;
|
|
52
|
-
conversionUint32Buffer[1] = high;
|
|
53
|
-
return conversionBuffer[0];
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** Adds protection against NaN values, changing the result if it would be NaN. This is because NaN values will compare to be not equal even if they are equal in certain cases, and in other cases, they'll always be equal, even if their bits are not equal.
|
|
57
|
-
- This means this is not a reversible operation. However, in a lot of cases, that doesn't matter.
|
|
58
|
-
*/
|
|
59
|
-
export function setLowHighUint32Safe(low: number, high: number): number {
|
|
60
|
-
conversionUint32Buffer[0] = low;
|
|
61
|
-
// Prevent NaN by not setting all the exponent bits to 1
|
|
62
|
-
conversionUint32Buffer[1] = high & 0xBFFFFFFF;
|
|
63
|
-
return conversionBuffer[0];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// NOTE: Not reversible, see setLowHighUint32Safe
|
|
67
|
-
export function xor64BitsSafe(a: number, b: number): number {
|
|
68
|
-
let high = getHighUint32(a);
|
|
69
|
-
let low = getLowUint32(a);
|
|
70
|
-
let high2 = getHighUint32(b);
|
|
71
|
-
let low2 = getLowUint32(b);
|
|
72
|
-
return setLowHighUint32Safe(low ^ low2, high ^ high2);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Gets bits that can be stored in a number. Specifically, the first 62 bits,
|
|
76
|
-
// as 64 bits will not compare correctly when treated as a double.
|
|
77
|
-
export function getShortNumber(buffer: Buffer): number {
|
|
78
|
-
let high = buffer.readUInt32BE(0) & 0x3FFFFFFF;
|
|
79
|
-
let low = buffer.readUInt32BE(4);
|
|
80
|
-
return setLowHighUint32(low, high);
|
|
81
|
-
}
|
|
82
|
-
/* Returns a number between 0 and 2**48 */
|
|
83
|
-
export function getBufferInt(buffer: Buffer): number {
|
|
84
|
-
let num = 0;
|
|
85
|
-
for (let i = 0; i < Math.min(buffer.length, 6); i++) {
|
|
86
|
-
num = num * 256 + buffer[i];
|
|
87
|
-
}
|
|
88
|
-
return num;
|
|
89
|
-
}
|
|
90
|
-
const intMax = 2 ** 48;
|
|
91
|
-
/** Returns a number between 0 (inclusive) and 1 (exclusive) */
|
|
92
|
-
export function getBufferFraction(buffer: Buffer): number {
|
|
93
|
-
let int = getBufferInt(buffer);
|
|
94
|
-
return int / intMax;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/*
|
|
98
|
-
export function numberToBase64(num: number): string {
|
|
99
|
-
conversionBuffer[0] = num;
|
|
100
|
-
return Buffer.from(conversionBuffer.buffer).toString("base64");
|
|
101
|
-
}
|
|
102
|
-
export function numberFromBase64(base64: string) {
|
|
103
|
-
return new Float64Array(Buffer.from(base64, "base64"))[0];
|
|
104
|
-
}
|
|
1
|
+
|
|
2
|
+
/** Subtracts the smallest possible value from a number (a double). This makes it possible to convert an exclusive range end
|
|
3
|
+
* to an inclusive range end, which is sometimes required (as in, < x is the same as <= minusEpsilon(x)).
|
|
4
|
+
*/
|
|
5
|
+
export function minusEpsilon(value: number) {
|
|
6
|
+
let high = getHighUint32(value);
|
|
7
|
+
let low = getLowUint32(value);
|
|
8
|
+
|
|
9
|
+
if (low === 0) {
|
|
10
|
+
low = 2 ** 32 - 1;
|
|
11
|
+
high--;
|
|
12
|
+
} else {
|
|
13
|
+
low--;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return setLowHighUint32(low, high);
|
|
17
|
+
}
|
|
18
|
+
const maxUint32 = 2 ** 32 - 1;
|
|
19
|
+
export function addEpsilons(value: number, count: number) {
|
|
20
|
+
let high = getHighUint32(value);
|
|
21
|
+
let low = getLowUint32(value);
|
|
22
|
+
|
|
23
|
+
low += count;
|
|
24
|
+
if (low < 0) {
|
|
25
|
+
low += maxUint32;
|
|
26
|
+
high++;
|
|
27
|
+
} else if (low > maxUint32) {
|
|
28
|
+
low -= maxUint32;
|
|
29
|
+
high--;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return setLowHighUint32(low, high);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let conversionBuffer = new Float64Array(1);
|
|
36
|
+
let conversionUint8Buffer = new Uint8Array(conversionBuffer.buffer);
|
|
37
|
+
let conversionUint32Buffer = new Uint32Array(conversionBuffer.buffer);
|
|
38
|
+
export function getHighUint32(num: number): number {
|
|
39
|
+
conversionBuffer[0] = num;
|
|
40
|
+
return conversionUint32Buffer[1];
|
|
41
|
+
}
|
|
42
|
+
export function getLowUint32(num: number): number {
|
|
43
|
+
conversionBuffer[0] = num;
|
|
44
|
+
return conversionUint32Buffer[0];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** IMPORTANT! Beware of comparisons with 64 bit numbers. getFloat64_fromBytes(4294136438, 168) !== getFloat64_fromBytes(4294136438, 168).
|
|
48
|
+
* USE is64BitEqual instead, OR, ensure the 2 highest bits are always 0.
|
|
49
|
+
*/
|
|
50
|
+
export function setLowHighUint32(low: number, high: number): number {
|
|
51
|
+
conversionUint32Buffer[0] = low;
|
|
52
|
+
conversionUint32Buffer[1] = high;
|
|
53
|
+
return conversionBuffer[0];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Adds protection against NaN values, changing the result if it would be NaN. This is because NaN values will compare to be not equal even if they are equal in certain cases, and in other cases, they'll always be equal, even if their bits are not equal.
|
|
57
|
+
- This means this is not a reversible operation. However, in a lot of cases, that doesn't matter.
|
|
58
|
+
*/
|
|
59
|
+
export function setLowHighUint32Safe(low: number, high: number): number {
|
|
60
|
+
conversionUint32Buffer[0] = low;
|
|
61
|
+
// Prevent NaN by not setting all the exponent bits to 1
|
|
62
|
+
conversionUint32Buffer[1] = high & 0xBFFFFFFF;
|
|
63
|
+
return conversionBuffer[0];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// NOTE: Not reversible, see setLowHighUint32Safe
|
|
67
|
+
export function xor64BitsSafe(a: number, b: number): number {
|
|
68
|
+
let high = getHighUint32(a);
|
|
69
|
+
let low = getLowUint32(a);
|
|
70
|
+
let high2 = getHighUint32(b);
|
|
71
|
+
let low2 = getLowUint32(b);
|
|
72
|
+
return setLowHighUint32Safe(low ^ low2, high ^ high2);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Gets bits that can be stored in a number. Specifically, the first 62 bits,
|
|
76
|
+
// as 64 bits will not compare correctly when treated as a double.
|
|
77
|
+
export function getShortNumber(buffer: Buffer): number {
|
|
78
|
+
let high = buffer.readUInt32BE(0) & 0x3FFFFFFF;
|
|
79
|
+
let low = buffer.readUInt32BE(4);
|
|
80
|
+
return setLowHighUint32(low, high);
|
|
81
|
+
}
|
|
82
|
+
/* Returns a number between 0 and 2**48 */
|
|
83
|
+
export function getBufferInt(buffer: Buffer): number {
|
|
84
|
+
let num = 0;
|
|
85
|
+
for (let i = 0; i < Math.min(buffer.length, 6); i++) {
|
|
86
|
+
num = num * 256 + buffer[i];
|
|
87
|
+
}
|
|
88
|
+
return num;
|
|
89
|
+
}
|
|
90
|
+
const intMax = 2 ** 48;
|
|
91
|
+
/** Returns a number between 0 (inclusive) and 1 (exclusive) */
|
|
92
|
+
export function getBufferFraction(buffer: Buffer): number {
|
|
93
|
+
let int = getBufferInt(buffer);
|
|
94
|
+
return int / intMax;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/*
|
|
98
|
+
export function numberToBase64(num: number): string {
|
|
99
|
+
conversionBuffer[0] = num;
|
|
100
|
+
return Buffer.from(conversionBuffer.buffer).toString("base64");
|
|
101
|
+
}
|
|
102
|
+
export function numberFromBase64(base64: string) {
|
|
103
|
+
return new Float64Array(Buffer.from(base64, "base64"))[0];
|
|
104
|
+
}
|
|
105
105
|
*/
|
package/src/buffers.ts
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
import { canHaveChildren } from "socket-function/src/types";
|
|
2
|
-
|
|
3
|
-
export type ArrayBufferViewTypes = Uint8Array | Int8Array | Uint16Array | Int16Array | Uint32Array | Int32Array | BigUint64Array | BigInt64Array | Float64Array | Float32Array | Uint8ClampedArray;
|
|
4
|
-
export type BufferType = ArrayBuffer | SharedArrayBuffer | ArrayBufferViewTypes;
|
|
5
|
-
|
|
6
|
-
export function cloneBuffer(data: Buffer): Buffer {
|
|
7
|
-
let newBuffer = Buffer.alloc(data.length);
|
|
8
|
-
data.copy(newBuffer);
|
|
9
|
-
return newBuffer;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export function asBuffer(data: BufferType): Buffer {
|
|
14
|
-
if (!data) return data;
|
|
15
|
-
if (data instanceof Buffer) return data;
|
|
16
|
-
if (!canHaveChildren(data)) return data as any;
|
|
17
|
-
if (!("buffer" in data) || !("byteOffset" in data) || !("byteLength" in data)) {
|
|
18
|
-
return Buffer.from(data);
|
|
19
|
-
}
|
|
20
|
-
let result = Buffer.from((data as any).buffer, (data as any).byteOffset, (data as any).byteLength);
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
export function asFloat64(data: Buffer): Float64Array {
|
|
24
|
-
if (data.length % 8 !== 0) {
|
|
25
|
-
throw new Error(`Data is not 8 count aligned, received length of ${data.length}`);
|
|
26
|
-
}
|
|
27
|
-
if (data.byteOffset % 8 !== 0) {
|
|
28
|
-
throw new Error(`Data is not 8 byte aligned, received offset of ${data.byteOffset}`);
|
|
29
|
-
}
|
|
30
|
-
return new Float64Array(data.buffer, data.byteOffset, Math.floor(data.length / 8));
|
|
31
|
-
}
|
|
32
|
-
export function asFloat32(data: Buffer): Float32Array {
|
|
33
|
-
if (data.length % 4 !== 0) {
|
|
34
|
-
throw new Error(`Data is not 4 byte aligned, received length of ${data.length}`);
|
|
35
|
-
}
|
|
36
|
-
if (data.byteOffset % 4 !== 0) {
|
|
37
|
-
throw new Error(`Data is not 4 byte aligned, received offset of ${data.byteOffset}`);
|
|
38
|
-
}
|
|
39
|
-
return new Float32Array(data.buffer, data.byteOffset, Math.floor(data.length / 4));
|
|
40
|
-
}
|
|
41
|
-
export function asUint32(data: Buffer): Uint32Array {
|
|
42
|
-
if (data.length % 4 !== 0) {
|
|
43
|
-
throw new Error(`Data is not 4 byte aligned, received length of ${data.length}`);
|
|
44
|
-
}
|
|
45
|
-
if (data.byteOffset % 4 !== 0) {
|
|
46
|
-
throw new Error(`Data is not 4 byte aligned, received offset of ${data.byteOffset}`);
|
|
47
|
-
}
|
|
48
|
-
return new Uint32Array(data.buffer, data.byteOffset, Math.floor(data.length / 4));
|
|
49
|
-
}
|
|
50
|
-
export function asInt32(data: Buffer): Int32Array {
|
|
51
|
-
if (data.length % 4 !== 0) {
|
|
52
|
-
throw new Error(`Data is not 4 byte aligned, received length of ${data.length}`);
|
|
53
|
-
}
|
|
54
|
-
if (data.byteOffset % 4 !== 0) {
|
|
55
|
-
throw new Error(`Data is not 4 byte aligned, received offset of ${data.byteOffset}`);
|
|
56
|
-
}
|
|
57
|
-
return new Int32Array(data.buffer, data.byteOffset, Math.floor(data.length / 4));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
export function asFloat64MaybeCopy(data: Buffer) {
|
|
62
|
-
if (data.length % 8 !== 0) {
|
|
63
|
-
throw new Error(`Data is not 8 count aligned, received length of ${data.length}`);
|
|
64
|
-
}
|
|
65
|
-
if (data.byteOffset % 8 !== 0) {
|
|
66
|
-
return asFloat64(cloneBuffer(data));
|
|
67
|
-
}
|
|
68
|
-
return new Float64Array(data.buffer, data.byteOffset, Math.floor(data.length / 8));
|
|
69
|
-
}
|
|
1
|
+
import { canHaveChildren } from "socket-function/src/types";
|
|
2
|
+
|
|
3
|
+
export type ArrayBufferViewTypes = Uint8Array | Int8Array | Uint16Array | Int16Array | Uint32Array | Int32Array | BigUint64Array | BigInt64Array | Float64Array | Float32Array | Uint8ClampedArray;
|
|
4
|
+
export type BufferType = ArrayBuffer | SharedArrayBuffer | ArrayBufferViewTypes;
|
|
5
|
+
|
|
6
|
+
export function cloneBuffer(data: Buffer): Buffer {
|
|
7
|
+
let newBuffer = Buffer.alloc(data.length);
|
|
8
|
+
data.copy(newBuffer);
|
|
9
|
+
return newBuffer;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
export function asBuffer(data: BufferType): Buffer {
|
|
14
|
+
if (!data) return data;
|
|
15
|
+
if (data instanceof Buffer) return data;
|
|
16
|
+
if (!canHaveChildren(data)) return data as any;
|
|
17
|
+
if (!("buffer" in data) || !("byteOffset" in data) || !("byteLength" in data)) {
|
|
18
|
+
return Buffer.from(data);
|
|
19
|
+
}
|
|
20
|
+
let result = Buffer.from((data as any).buffer, (data as any).byteOffset, (data as any).byteLength);
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
export function asFloat64(data: Buffer): Float64Array {
|
|
24
|
+
if (data.length % 8 !== 0) {
|
|
25
|
+
throw new Error(`Data is not 8 count aligned, received length of ${data.length}`);
|
|
26
|
+
}
|
|
27
|
+
if (data.byteOffset % 8 !== 0) {
|
|
28
|
+
throw new Error(`Data is not 8 byte aligned, received offset of ${data.byteOffset}`);
|
|
29
|
+
}
|
|
30
|
+
return new Float64Array(data.buffer, data.byteOffset, Math.floor(data.length / 8));
|
|
31
|
+
}
|
|
32
|
+
export function asFloat32(data: Buffer): Float32Array {
|
|
33
|
+
if (data.length % 4 !== 0) {
|
|
34
|
+
throw new Error(`Data is not 4 byte aligned, received length of ${data.length}`);
|
|
35
|
+
}
|
|
36
|
+
if (data.byteOffset % 4 !== 0) {
|
|
37
|
+
throw new Error(`Data is not 4 byte aligned, received offset of ${data.byteOffset}`);
|
|
38
|
+
}
|
|
39
|
+
return new Float32Array(data.buffer, data.byteOffset, Math.floor(data.length / 4));
|
|
40
|
+
}
|
|
41
|
+
export function asUint32(data: Buffer): Uint32Array {
|
|
42
|
+
if (data.length % 4 !== 0) {
|
|
43
|
+
throw new Error(`Data is not 4 byte aligned, received length of ${data.length}`);
|
|
44
|
+
}
|
|
45
|
+
if (data.byteOffset % 4 !== 0) {
|
|
46
|
+
throw new Error(`Data is not 4 byte aligned, received offset of ${data.byteOffset}`);
|
|
47
|
+
}
|
|
48
|
+
return new Uint32Array(data.buffer, data.byteOffset, Math.floor(data.length / 4));
|
|
49
|
+
}
|
|
50
|
+
export function asInt32(data: Buffer): Int32Array {
|
|
51
|
+
if (data.length % 4 !== 0) {
|
|
52
|
+
throw new Error(`Data is not 4 byte aligned, received length of ${data.length}`);
|
|
53
|
+
}
|
|
54
|
+
if (data.byteOffset % 4 !== 0) {
|
|
55
|
+
throw new Error(`Data is not 4 byte aligned, received offset of ${data.byteOffset}`);
|
|
56
|
+
}
|
|
57
|
+
return new Int32Array(data.buffer, data.byteOffset, Math.floor(data.length / 4));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
export function asFloat64MaybeCopy(data: Buffer) {
|
|
62
|
+
if (data.length % 8 !== 0) {
|
|
63
|
+
throw new Error(`Data is not 8 count aligned, received length of ${data.length}`);
|
|
64
|
+
}
|
|
65
|
+
if (data.byteOffset % 8 !== 0) {
|
|
66
|
+
return asFloat64(cloneBuffer(data));
|
|
67
|
+
}
|
|
68
|
+
return new Float64Array(data.buffer, data.byteOffset, Math.floor(data.length / 8));
|
|
69
|
+
}
|
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
import { blue, green } from "socket-function/src/formatting/logColors";
|
|
2
|
-
import { ClientWatcher } from "../1-path-client/pathValueClientWatcher";
|
|
3
|
-
import { debugPathValuePath, PathValue } from "../0-path-value-core/pathValueCore";
|
|
4
|
-
import { pathValueSerializer } from "../-h-path-value-serialize/PathValueSerializer";
|
|
5
|
-
import { LOCAL_DOMAIN_PATH } from "../0-path-value-core/PathRouter";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function group(expanded: boolean) {
|
|
10
|
-
return expanded ? console.group : console.groupCollapsed;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
let epoch = Date.now();
|
|
14
|
-
export class ActionsHistory {
|
|
15
|
-
public static LOG_ACTION_HISTORY = "";
|
|
16
|
-
public static OnNewWatches(config: { newPathsWatched: Set<string>; newParentsWatched: Set<string>; debugName?: string; authorityId: string; }) {
|
|
17
|
-
if (ClientWatcher.DEBUG_READS) {
|
|
18
|
-
let now = Date.now();
|
|
19
|
-
group(ClientWatcher.DEBUG_READS_EXPANDED)(`(${now - epoch}ms) New watch count ${config.newPathsWatched.size} (${config.newParentsWatched.size} parent watches) for ${JSON.stringify(config.debugName || "anonymous")}. Authority ${config.authorityId}, time ${now}`);
|
|
20
|
-
for (let path of config.newParentsWatched) {
|
|
21
|
-
console.log(blue(path));
|
|
22
|
-
}
|
|
23
|
-
for (let path of config.newPathsWatched) {
|
|
24
|
-
console.log(path);
|
|
25
|
-
}
|
|
26
|
-
console.groupEnd();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
public static OnRead(values: PathValue[]) {
|
|
30
|
-
if (ClientWatcher.DEBUG_READS && values.length > 0) {
|
|
31
|
-
values = values.filter(x => !x.path.startsWith(LOCAL_DOMAIN_PATH));
|
|
32
|
-
if (values.length > 0) {
|
|
33
|
-
let now = Date.now();
|
|
34
|
-
let oldest = Math.min(...values.map(x => x.time.time).filter(x => x), now);
|
|
35
|
-
group(ClientWatcher.DEBUG_READS_EXPANDED)(`(${now - epoch}ms, ${now}) Read count ${values.length}, ${(Date.now() - oldest).toFixed()}ms old`);
|
|
36
|
-
for (let value of values) {
|
|
37
|
-
console.log(blue(debugPathValuePath(value)), "===", pathValueSerializer.getPathValue(value), `(${value.valid ? "valid" : "invalid"})`);
|
|
38
|
-
}
|
|
39
|
-
console.groupEnd();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (!ActionsHistory.LOG_ACTION_HISTORY) return;
|
|
43
|
-
}
|
|
44
|
-
public static OnWrite(values: PathValue[]) {
|
|
45
|
-
if (ClientWatcher.DEBUG_WRITES) {
|
|
46
|
-
values = values.filter(x => !x.path.startsWith(LOCAL_DOMAIN_PATH));
|
|
47
|
-
if (values.length > 0) {
|
|
48
|
-
let now = Date.now();
|
|
49
|
-
group(ClientWatcher.DEBUG_WRITES_EXPANDED)(green(`(${now - epoch}ms, ${now}) Committing writes ${values.length}`));
|
|
50
|
-
for (let value of values) {
|
|
51
|
-
console.log(green(debugPathValuePath(value)), "=", pathValueSerializer.getPathValue(value), `(${value.valid ? "valid" : "invalid"})`);
|
|
52
|
-
}
|
|
53
|
-
console.groupEnd();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (!ActionsHistory.LOG_ACTION_HISTORY) return;
|
|
57
|
-
}
|
|
1
|
+
import { blue, green } from "socket-function/src/formatting/logColors";
|
|
2
|
+
import { ClientWatcher } from "../1-path-client/pathValueClientWatcher";
|
|
3
|
+
import { debugPathValuePath, PathValue } from "../0-path-value-core/pathValueCore";
|
|
4
|
+
import { pathValueSerializer } from "../-h-path-value-serialize/PathValueSerializer";
|
|
5
|
+
import { LOCAL_DOMAIN_PATH } from "../0-path-value-core/PathRouter";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function group(expanded: boolean) {
|
|
10
|
+
return expanded ? console.group : console.groupCollapsed;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let epoch = Date.now();
|
|
14
|
+
export class ActionsHistory {
|
|
15
|
+
public static LOG_ACTION_HISTORY = "";
|
|
16
|
+
public static OnNewWatches(config: { newPathsWatched: Set<string>; newParentsWatched: Set<string>; debugName?: string; authorityId: string; }) {
|
|
17
|
+
if (ClientWatcher.DEBUG_READS) {
|
|
18
|
+
let now = Date.now();
|
|
19
|
+
group(ClientWatcher.DEBUG_READS_EXPANDED)(`(${now - epoch}ms) New watch count ${config.newPathsWatched.size} (${config.newParentsWatched.size} parent watches) for ${JSON.stringify(config.debugName || "anonymous")}. Authority ${config.authorityId}, time ${now}`);
|
|
20
|
+
for (let path of config.newParentsWatched) {
|
|
21
|
+
console.log(blue(path));
|
|
22
|
+
}
|
|
23
|
+
for (let path of config.newPathsWatched) {
|
|
24
|
+
console.log(path);
|
|
25
|
+
}
|
|
26
|
+
console.groupEnd();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
public static OnRead(values: PathValue[]) {
|
|
30
|
+
if (ClientWatcher.DEBUG_READS && values.length > 0) {
|
|
31
|
+
values = values.filter(x => !x.path.startsWith(LOCAL_DOMAIN_PATH));
|
|
32
|
+
if (values.length > 0) {
|
|
33
|
+
let now = Date.now();
|
|
34
|
+
let oldest = Math.min(...values.map(x => x.time.time).filter(x => x), now);
|
|
35
|
+
group(ClientWatcher.DEBUG_READS_EXPANDED)(`(${now - epoch}ms, ${now}) Read count ${values.length}, ${(Date.now() - oldest).toFixed()}ms old`);
|
|
36
|
+
for (let value of values) {
|
|
37
|
+
console.log(blue(debugPathValuePath(value)), "===", pathValueSerializer.getPathValue(value), `(${value.valid ? "valid" : "invalid"})`);
|
|
38
|
+
}
|
|
39
|
+
console.groupEnd();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (!ActionsHistory.LOG_ACTION_HISTORY) return;
|
|
43
|
+
}
|
|
44
|
+
public static OnWrite(values: PathValue[]) {
|
|
45
|
+
if (ClientWatcher.DEBUG_WRITES) {
|
|
46
|
+
values = values.filter(x => !x.path.startsWith(LOCAL_DOMAIN_PATH));
|
|
47
|
+
if (values.length > 0) {
|
|
48
|
+
let now = Date.now();
|
|
49
|
+
group(ClientWatcher.DEBUG_WRITES_EXPANDED)(green(`(${now - epoch}ms, ${now}) Committing writes ${values.length}`));
|
|
50
|
+
for (let value of values) {
|
|
51
|
+
console.log(green(debugPathValuePath(value)), "=", pathValueSerializer.getPathValue(value), `(${value.valid ? "valid" : "invalid"})`);
|
|
52
|
+
}
|
|
53
|
+
console.groupEnd();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (!ActionsHistory.LOG_ACTION_HISTORY) return;
|
|
57
|
+
}
|
|
58
58
|
}
|