querysub 0.437.0 → 0.439.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.
Files changed (81) hide show
  1. package/.eslintrc.js +50 -50
  2. package/bin/deploy.js +0 -0
  3. package/bin/function.js +0 -0
  4. package/bin/server.js +0 -0
  5. package/costsBenefits.txt +115 -115
  6. package/deploy.ts +2 -2
  7. package/package.json +2 -2
  8. package/spec.txt +1192 -1192
  9. package/src/-a-archives/archives.ts +202 -202
  10. package/src/-a-archives/archivesDisk.ts +454 -454
  11. package/src/-a-auth/certs.ts +540 -540
  12. package/src/-a-auth/node-forge-ed25519.d.ts +16 -16
  13. package/src/-b-authorities/dnsAuthority.ts +138 -138
  14. package/src/-c-identity/IdentityController.ts +258 -258
  15. package/src/-d-trust/NetworkTrust2.ts +180 -180
  16. package/src/-e-certs/EdgeCertController.ts +252 -252
  17. package/src/-e-certs/certAuthority.ts +201 -201
  18. package/src/-f-node-discovery/NodeDiscovery.ts +640 -640
  19. package/src/-g-core-values/NodeCapabilities.ts +200 -200
  20. package/src/-h-path-value-serialize/stringSerializer.ts +175 -175
  21. package/src/0-path-value-core/PathValueCommitter.ts +468 -468
  22. package/src/0-path-value-core/PathValueController.ts +0 -2
  23. package/src/0-path-value-core/archiveLocks/archiveSnapshots.ts +37 -1
  24. package/src/0-path-value-core/pathValueCore.ts +12 -0
  25. package/src/2-proxy/PathValueProxyWatcher.ts +2542 -2542
  26. package/src/2-proxy/TransactionDelayer.ts +94 -94
  27. package/src/2-proxy/pathDatabaseProxyBase.ts +36 -36
  28. package/src/2-proxy/pathValueProxy.ts +159 -159
  29. package/src/3-path-functions/PathFunctionRunner.ts +24 -13
  30. package/src/3-path-functions/PathFunctionRunnerMain.ts +87 -87
  31. package/src/3-path-functions/pathFunctionLoader.ts +516 -516
  32. package/src/3-path-functions/tests/rejectTest.ts +76 -76
  33. package/src/4-deploy/deployCheck.ts +6 -6
  34. package/src/4-dom/css.tsx +29 -29
  35. package/src/4-dom/cssTypes.d.ts +211 -211
  36. package/src/4-dom/qreact.tsx +2799 -2799
  37. package/src/4-dom/qreactTest.tsx +410 -410
  38. package/src/4-querysub/permissions.ts +335 -335
  39. package/src/4-querysub/querysubPrediction.ts +483 -483
  40. package/src/5-diagnostics/qreactDebug.tsx +400 -346
  41. package/src/TestController.ts +34 -34
  42. package/src/bits.ts +104 -104
  43. package/src/buffers.ts +69 -69
  44. package/src/diagnostics/ActionsHistory.ts +57 -57
  45. package/src/diagnostics/PathDistributionInfo.tsx +9 -1
  46. package/src/diagnostics/listenOnDebugger.ts +71 -71
  47. package/src/diagnostics/logs/IndexedLogs/BufferUnitIndex.ts +1 -1
  48. package/src/diagnostics/logs/diskLogger.ts +6 -0
  49. package/src/diagnostics/misc-pages/SnapshotViewer.tsx +78 -1
  50. package/src/diagnostics/periodic.ts +111 -111
  51. package/src/diagnostics/trackResources.ts +91 -91
  52. package/src/diagnostics/watchdog.ts +120 -120
  53. package/src/errors.ts +133 -133
  54. package/src/forceProduction.ts +2 -2
  55. package/src/fs.ts +80 -80
  56. package/src/functional/diff.ts +857 -857
  57. package/src/functional/promiseCache.ts +78 -78
  58. package/src/functional/random.ts +8 -8
  59. package/src/functional/stats.ts +60 -60
  60. package/src/heapDumps.ts +665 -665
  61. package/src/https.ts +1 -1
  62. package/src/library-components/AspectSizedComponent.tsx +87 -87
  63. package/src/library-components/ButtonSelector.tsx +64 -64
  64. package/src/library-components/DropdownCustom.tsx +150 -150
  65. package/src/library-components/DropdownSelector.tsx +31 -31
  66. package/src/library-components/InlinePopup.tsx +66 -66
  67. package/src/library-components/uncaughtToast.tsx +2 -0
  68. package/src/misc/color.ts +29 -29
  69. package/src/misc/hash.ts +83 -83
  70. package/src/misc/ipPong.js +13 -13
  71. package/src/misc/networking.ts +1 -1
  72. package/src/misc/random.ts +44 -44
  73. package/src/misc.ts +196 -196
  74. package/src/path.ts +255 -255
  75. package/src/persistentLocalStore.ts +41 -41
  76. package/src/promise.ts +14 -14
  77. package/src/storage/fileSystemPointer.ts +71 -71
  78. package/src/test/heapProcess.ts +35 -35
  79. package/src/zip.ts +15 -15
  80. package/tsconfig.json +26 -26
  81. package/yarnSpec.txt +56 -56
@@ -1,176 +1,176 @@
1
- import debugbreak from "debugbreak";
2
- import { measureFnc, measureWrap } from "socket-function/src/profiling/measure";
3
- import { asFloat64 } from "../buffers";
4
-
5
- export class StringSerialize {
6
-
7
- // TIMING: About 1.6X SLOWER than JSON.stringify (HOWEVER, if you JSON.stringify+parse, stringify
8
- // only takes about 15% of the time, so... stringify time is mostly irrelevant).
9
- // - ALSO, uses less bytes than JSON.stringify, especially for small strings (JSON.stringify
10
- // has at least 3 bytes overhead per string, more if the strings contain `"`)
11
- @measureFnc
12
- public static serializeStrings(texts: string[]): Buffer {
13
- let nullValues: {
14
- index: number;
15
- count: number;
16
- }[] = [];
17
- for (let i = 0; i < texts.length; i++) {
18
- let text = texts[i];
19
- if (text.includes("\0")) {
20
- let nullCount = 0;
21
- for (let i = 0; i < text.length; i++) {
22
- if (text[i] === "\0") {
23
- nullCount++;
24
- }
25
- }
26
- nullValues.push({
27
- index: i,
28
- count: nullCount,
29
- });
30
- }
31
- }
32
- function float64Buffer(values: number[]) {
33
- return Buffer.from(new Float64Array(values).buffer);
34
- }
35
-
36
- return Buffer.concat([
37
- float64Buffer([texts.length]),
38
- float64Buffer([nullValues.length]),
39
- float64Buffer(nullValues.map(v => v.index)),
40
- float64Buffer(nullValues.map(v => v.count)),
41
- Buffer.from(texts.join("\0")),
42
- ]);
43
- }
44
-
45
- // TIMING: About 2X faster than JSON.parse
46
- // - UNLESS you HEAVILY use "\0", then 5x slower than JSON.parse
47
- @measureFnc
48
- public static deserializeStrings(buffer: Buffer): string[] {
49
- let getObj = this.deserializeStringsLazy(buffer);
50
- let strings: string[][] = [];
51
- while (true) {
52
- let nextStrings = getObj.getNextStrings();
53
- if (!nextStrings) {
54
- break;
55
- }
56
- strings.push(nextStrings);
57
- }
58
- // Unfortunate to have to .flat it, but... it's probably faster than parsing the strings?
59
- let result = strings.flat();
60
- return result;
61
- }
62
- public static deserializeStringsLazy(buffer: Buffer, readChunkSize = 1_000_000): {
63
- getNextStrings(): string[] | undefined;
64
- } {
65
- let curReadPos = 0;
66
- function readFloat64(count: number): number[] {
67
- let results: number[] = [];
68
- for (let i = 0; i < count; i++) {
69
- results.push(buffer.readDoubleLE(curReadPos));
70
- curReadPos += 8;
71
- }
72
- return results;
73
- }
74
- let auditCountRead = 0;
75
- let count = readFloat64(1)[0];
76
- let nullValueCount = readFloat64(1)[0];
77
- let nullIndexes = readFloat64(nullValueCount);
78
- let nullCounts = readFloat64(nullValueCount);
79
- let indexToNullCount = new Map<number, number>();
80
- for (let i = 0; i < nullValueCount; i++) {
81
- indexToNullCount.set(nullIndexes[i], nullCounts[i]);
82
- }
83
- // "" splits into [""], so we need to check count to see if it is really [""], or actually [].
84
- // (otherwise "" is fine, as we "\0" join, it is just the zero count case that is tricky)
85
- if (count === 0) {
86
- return { getNextStrings() { return undefined; } };
87
- }
88
-
89
- let prevParts: string[] | undefined;
90
-
91
- return { getNextStrings: measureWrap(getNextStrings) };
92
- function getNextStrings() {
93
- let currentEnd = curReadPos + readChunkSize;
94
- if (currentEnd > buffer.length) currentEnd = buffer.length;
95
- while (currentEnd < buffer.length && buffer[currentEnd] !== 0) {
96
- currentEnd++;
97
- }
98
- if (curReadPos >= currentEnd && !prevParts) {
99
- if (auditCountRead !== count) {
100
- throw new Error(`Expected to read ${count} strings, but only read ${auditCountRead}. Either the data is corrupted, or our code is bugged.`);
101
- }
102
- return undefined;
103
- }
104
- let text = buffer.toString("utf8", curReadPos, currentEnd);
105
- curReadPos = currentEnd + 1;
106
-
107
- let textParts = text.split("\0");
108
- if (prevParts) {
109
- textParts = prevParts.concat(textParts);
110
- prevParts = undefined;
111
- }
112
-
113
- let outputParts: string[] = [];
114
- let index = 0;
115
- while (index < textParts.length) {
116
- let partCount = (indexToNullCount.get(outputParts.length) ?? 0) + 1;
117
- if (partCount === 1) {
118
- outputParts.push(textParts[index]);
119
- } else {
120
- if (index + partCount > textParts.length) {
121
- prevParts = textParts.slice(index);
122
- break;
123
- } else {
124
- outputParts.push(textParts.slice(index, index + partCount).join("\0"));
125
- }
126
- }
127
- index += partCount;
128
- }
129
-
130
- auditCountRead += outputParts.length;
131
- return outputParts;
132
- }
133
- }
134
- public static deserializeStringsOld(buffer: Buffer): string[] {
135
- let offset = 0;
136
- function readFloat64(count: number): number[] {
137
- let results: number[] = [];
138
- for (let i = 0; i < count; i++) {
139
- results.push(buffer.readDoubleLE(offset));
140
- offset += 8;
141
- }
142
- return results;
143
- }
144
- let count = readFloat64(1)[0];
145
- let nullValueCount = readFloat64(1)[0];
146
- let nullIndexes = readFloat64(nullValueCount);
147
- let nullCounts = readFloat64(nullValueCount);
148
- let indexToNullCount = new Map<number, number>();
149
- for (let i = 0; i < nullValueCount; i++) {
150
- indexToNullCount.set(nullIndexes[i], nullCounts[i]);
151
- }
152
- // "" splits into [""], so we need to check count to see if it is really [""], or actually [].
153
- // (otherwise "" is fine, as we "\0" join, it is just the zero count case that is tricky)
154
- if (count === 0) {
155
- return [];
156
- }
157
-
158
- let text = buffer.toString("utf8", offset);
159
-
160
- let textParts = text.split("\0");
161
-
162
- let outputParts: string[] = [];
163
- let index = 0;
164
- while (index < textParts.length) {
165
- let partCount = (indexToNullCount.get(outputParts.length) ?? 0) + 1;
166
- if (partCount === 1) {
167
- outputParts.push(textParts[index]);
168
- } else {
169
- outputParts.push(textParts.slice(index, index + partCount).join("\0"));
170
- }
171
- index += partCount;
172
- }
173
-
174
- return outputParts;
175
- }
1
+ import debugbreak from "debugbreak";
2
+ import { measureFnc, measureWrap } from "socket-function/src/profiling/measure";
3
+ import { asFloat64 } from "../buffers";
4
+
5
+ export class StringSerialize {
6
+
7
+ // TIMING: About 1.6X SLOWER than JSON.stringify (HOWEVER, if you JSON.stringify+parse, stringify
8
+ // only takes about 15% of the time, so... stringify time is mostly irrelevant).
9
+ // - ALSO, uses less bytes than JSON.stringify, especially for small strings (JSON.stringify
10
+ // has at least 3 bytes overhead per string, more if the strings contain `"`)
11
+ @measureFnc
12
+ public static serializeStrings(texts: string[]): Buffer {
13
+ let nullValues: {
14
+ index: number;
15
+ count: number;
16
+ }[] = [];
17
+ for (let i = 0; i < texts.length; i++) {
18
+ let text = texts[i];
19
+ if (text.includes("\0")) {
20
+ let nullCount = 0;
21
+ for (let i = 0; i < text.length; i++) {
22
+ if (text[i] === "\0") {
23
+ nullCount++;
24
+ }
25
+ }
26
+ nullValues.push({
27
+ index: i,
28
+ count: nullCount,
29
+ });
30
+ }
31
+ }
32
+ function float64Buffer(values: number[]) {
33
+ return Buffer.from(new Float64Array(values).buffer);
34
+ }
35
+
36
+ return Buffer.concat([
37
+ float64Buffer([texts.length]),
38
+ float64Buffer([nullValues.length]),
39
+ float64Buffer(nullValues.map(v => v.index)),
40
+ float64Buffer(nullValues.map(v => v.count)),
41
+ Buffer.from(texts.join("\0")),
42
+ ]);
43
+ }
44
+
45
+ // TIMING: About 2X faster than JSON.parse
46
+ // - UNLESS you HEAVILY use "\0", then 5x slower than JSON.parse
47
+ @measureFnc
48
+ public static deserializeStrings(buffer: Buffer): string[] {
49
+ let getObj = this.deserializeStringsLazy(buffer);
50
+ let strings: string[][] = [];
51
+ while (true) {
52
+ let nextStrings = getObj.getNextStrings();
53
+ if (!nextStrings) {
54
+ break;
55
+ }
56
+ strings.push(nextStrings);
57
+ }
58
+ // Unfortunate to have to .flat it, but... it's probably faster than parsing the strings?
59
+ let result = strings.flat();
60
+ return result;
61
+ }
62
+ public static deserializeStringsLazy(buffer: Buffer, readChunkSize = 1_000_000): {
63
+ getNextStrings(): string[] | undefined;
64
+ } {
65
+ let curReadPos = 0;
66
+ function readFloat64(count: number): number[] {
67
+ let results: number[] = [];
68
+ for (let i = 0; i < count; i++) {
69
+ results.push(buffer.readDoubleLE(curReadPos));
70
+ curReadPos += 8;
71
+ }
72
+ return results;
73
+ }
74
+ let auditCountRead = 0;
75
+ let count = readFloat64(1)[0];
76
+ let nullValueCount = readFloat64(1)[0];
77
+ let nullIndexes = readFloat64(nullValueCount);
78
+ let nullCounts = readFloat64(nullValueCount);
79
+ let indexToNullCount = new Map<number, number>();
80
+ for (let i = 0; i < nullValueCount; i++) {
81
+ indexToNullCount.set(nullIndexes[i], nullCounts[i]);
82
+ }
83
+ // "" splits into [""], so we need to check count to see if it is really [""], or actually [].
84
+ // (otherwise "" is fine, as we "\0" join, it is just the zero count case that is tricky)
85
+ if (count === 0) {
86
+ return { getNextStrings() { return undefined; } };
87
+ }
88
+
89
+ let prevParts: string[] | undefined;
90
+
91
+ return { getNextStrings: measureWrap(getNextStrings) };
92
+ function getNextStrings() {
93
+ let currentEnd = curReadPos + readChunkSize;
94
+ if (currentEnd > buffer.length) currentEnd = buffer.length;
95
+ while (currentEnd < buffer.length && buffer[currentEnd] !== 0) {
96
+ currentEnd++;
97
+ }
98
+ if (curReadPos >= currentEnd && !prevParts) {
99
+ if (auditCountRead !== count) {
100
+ throw new Error(`Expected to read ${count} strings, but only read ${auditCountRead}. Either the data is corrupted, or our code is bugged.`);
101
+ }
102
+ return undefined;
103
+ }
104
+ let text = buffer.toString("utf8", curReadPos, currentEnd);
105
+ curReadPos = currentEnd + 1;
106
+
107
+ let textParts = text.split("\0");
108
+ if (prevParts) {
109
+ textParts = prevParts.concat(textParts);
110
+ prevParts = undefined;
111
+ }
112
+
113
+ let outputParts: string[] = [];
114
+ let index = 0;
115
+ while (index < textParts.length) {
116
+ let partCount = (indexToNullCount.get(outputParts.length) ?? 0) + 1;
117
+ if (partCount === 1) {
118
+ outputParts.push(textParts[index]);
119
+ } else {
120
+ if (index + partCount > textParts.length) {
121
+ prevParts = textParts.slice(index);
122
+ break;
123
+ } else {
124
+ outputParts.push(textParts.slice(index, index + partCount).join("\0"));
125
+ }
126
+ }
127
+ index += partCount;
128
+ }
129
+
130
+ auditCountRead += outputParts.length;
131
+ return outputParts;
132
+ }
133
+ }
134
+ public static deserializeStringsOld(buffer: Buffer): string[] {
135
+ let offset = 0;
136
+ function readFloat64(count: number): number[] {
137
+ let results: number[] = [];
138
+ for (let i = 0; i < count; i++) {
139
+ results.push(buffer.readDoubleLE(offset));
140
+ offset += 8;
141
+ }
142
+ return results;
143
+ }
144
+ let count = readFloat64(1)[0];
145
+ let nullValueCount = readFloat64(1)[0];
146
+ let nullIndexes = readFloat64(nullValueCount);
147
+ let nullCounts = readFloat64(nullValueCount);
148
+ let indexToNullCount = new Map<number, number>();
149
+ for (let i = 0; i < nullValueCount; i++) {
150
+ indexToNullCount.set(nullIndexes[i], nullCounts[i]);
151
+ }
152
+ // "" splits into [""], so we need to check count to see if it is really [""], or actually [].
153
+ // (otherwise "" is fine, as we "\0" join, it is just the zero count case that is tricky)
154
+ if (count === 0) {
155
+ return [];
156
+ }
157
+
158
+ let text = buffer.toString("utf8", offset);
159
+
160
+ let textParts = text.split("\0");
161
+
162
+ let outputParts: string[] = [];
163
+ let index = 0;
164
+ while (index < textParts.length) {
165
+ let partCount = (indexToNullCount.get(outputParts.length) ?? 0) + 1;
166
+ if (partCount === 1) {
167
+ outputParts.push(textParts[index]);
168
+ } else {
169
+ outputParts.push(textParts.slice(index, index + partCount).join("\0"));
170
+ }
171
+ index += partCount;
172
+ }
173
+
174
+ return outputParts;
175
+ }
176
176
  }