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
package/src/errors.ts CHANGED
@@ -1,134 +1,134 @@
1
- import debugbreak from "debugbreak";
2
- import { delay } from "socket-function/src/batching";
3
- import { blue, red } from "socket-function/src/formatting/logColors";
4
- import { canHaveChildren } from "socket-function/src/types";
5
-
6
- let callstackTracking = false;
7
- /** WARNING: This can be VERY slow. The only way to record the callstack of some errors is to record it
8
- * on promise initialization, which results in gathering callstacks even for successful promises.
9
- */
10
- export function enableCallbackTracking() {
11
- callstackTracking = true;
12
- }
13
-
14
- function logError(e: Error, callstack: unknown) {
15
- console.error(`${blue("Error from promise")}: ${red(e.stack || e.message)}`);
16
- if (callstackTracking) {
17
- console.log(callstack);
18
- }
19
- }
20
- export function logErrors(promiseorError: Promise<unknown> | unknown | undefined) {
21
- let callstack = callstackTracking && new Error().stack;
22
- if (!promiseorError) return;
23
- if (!canHaveChildren(promiseorError)) return;
24
- if (promiseorError instanceof Promise) {
25
- promiseorError.catch(e => {
26
- logError(e, callstack);
27
- });
28
- } else {
29
- if (promiseorError instanceof Error) {
30
- logError(promiseorError, callstack);
31
- }
32
- }
33
- }
34
- export function ignoreErrors(promise: Promise<unknown>) {
35
- if (!promise) return;
36
- if (!promise?.catch) return;
37
- promise.catch(e => { });
38
- }
39
-
40
- /** Logs the error as well. */
41
- export function errorToUndefined<T>(p: Promise<T>): Promise<T | undefined> {
42
- if (!p?.catch) return p;
43
- return p.catch((e) => {
44
- console.error(`${blue("Error to undefined error")}: ${red(e.stack)}`);
45
- return undefined;
46
- });
47
- }
48
- export function errorToUndefinedSilent<T>(p: Promise<T>): Promise<T | undefined> {
49
- if (!p?.catch) return Promise.resolve(undefined);
50
- return p.catch((e) => {
51
- return undefined;
52
- });
53
- }
54
-
55
- export function timeoutToError<T>(time: number, p: Promise<T>, err: () => Error) {
56
- return new Promise<T>((resolve, reject) => {
57
- let timeout = setTimeout(() => reject(err()), time);
58
- p.then(resolve, reject).finally(() => clearTimeout(timeout));
59
- });
60
- }
61
-
62
- // NOTE: Both errors and timeouts are converted to undefined
63
- export function timeoutToUndefined<T>(time: number, p: Promise<T>) {
64
- return new Promise<T | undefined>((resolve, reject) => {
65
- let timeout = setTimeout(() => {
66
- console.error(blue(`timeoutToUndefined timed out after ${time}`));
67
- resolve(undefined);
68
- }, time);
69
- p.then(resolve,
70
- (err) => {
71
- console.error(`${blue("timeoutToUndefined error")}: ${red(err.stack)}`);
72
- resolve(undefined);
73
- }
74
- ).finally(() => clearTimeout(timeout));
75
- });
76
- }
77
- export function timeoutToUndefinedSilent<T>(time: number, p: Promise<T>) {
78
- return new Promise<T | undefined>((resolve, reject) => {
79
- let timeout = setTimeout(() => {
80
- resolve(undefined);
81
- }, time);
82
- p.then(
83
- resolve,
84
- (err) => {
85
- resolve(undefined);
86
- }
87
- ).finally(() => clearTimeout(timeout));
88
- });
89
- }
90
-
91
- /** Used when accessing paid resources, so we don't rack up charges due to an error,
92
- * but also so that it doesn't take forever for the initial call to run.
93
- */
94
- export async function backoffRetryLoop<T>(code: () => Promise<T>, waitTime = 5 * 1000) {
95
- while (true) {
96
- try {
97
- return await code();
98
- } catch (e: any) {
99
- console.error(`Error retrying in ${waitTime}ms\n${e.stack}`);
100
- await delay(waitTime);
101
- waitTime *= 1.01;
102
- }
103
- }
104
- }
105
-
106
- export function errorify(error: any, messageOverride?: string) {
107
- if (error instanceof Error) {
108
- return error;
109
- }
110
- let errorObj = new Error();
111
- if (typeof error === "string" && error.includes("\n")) {
112
- errorObj.stack = error;
113
- errorObj.message = error.split("\n")[0];
114
- } else {
115
- errorObj.message = error;
116
- errorObj.stack = error + "\n" + errorObj.stack;
117
- }
118
- if (messageOverride) {
119
- errorObj.message = messageOverride;
120
- }
121
- return errorObj;
122
- }
123
-
124
- export function assertValue<T>(value: T | undefined | null, message?: string): T {
125
- if (value === undefined || value === null) {
126
- throw new Error(`Value is ${value === undefined ? "undefined" : "null"}, ${message}`);
127
- }
128
- return value;
129
- }
130
- export function assert<T>(value: T | undefined | null, message?: string): asserts value is T {
131
- if (value === undefined || value === null) {
132
- throw new Error(`Value is ${value === undefined ? "undefined" : "null"}, ${message}`);
133
- }
1
+ import debugbreak from "debugbreak";
2
+ import { delay } from "socket-function/src/batching";
3
+ import { blue, red } from "socket-function/src/formatting/logColors";
4
+ import { canHaveChildren } from "socket-function/src/types";
5
+
6
+ let callstackTracking = false;
7
+ /** WARNING: This can be VERY slow. The only way to record the callstack of some errors is to record it
8
+ * on promise initialization, which results in gathering callstacks even for successful promises.
9
+ */
10
+ export function enableCallbackTracking() {
11
+ callstackTracking = true;
12
+ }
13
+
14
+ function logError(e: Error, callstack: unknown) {
15
+ console.error(`${blue("Error from promise")}: ${red(e.stack || e.message)}`);
16
+ if (callstackTracking) {
17
+ console.log(callstack);
18
+ }
19
+ }
20
+ export function logErrors(promiseorError: Promise<unknown> | unknown | undefined) {
21
+ let callstack = callstackTracking && new Error().stack;
22
+ if (!promiseorError) return;
23
+ if (!canHaveChildren(promiseorError)) return;
24
+ if (promiseorError instanceof Promise) {
25
+ promiseorError.catch(e => {
26
+ logError(e, callstack);
27
+ });
28
+ } else {
29
+ if (promiseorError instanceof Error) {
30
+ logError(promiseorError, callstack);
31
+ }
32
+ }
33
+ }
34
+ export function ignoreErrors(promise: Promise<unknown>) {
35
+ if (!promise) return;
36
+ if (!promise?.catch) return;
37
+ promise.catch(e => { });
38
+ }
39
+
40
+ /** Logs the error as well. */
41
+ export function errorToUndefined<T>(p: Promise<T>): Promise<T | undefined> {
42
+ if (!p?.catch) return p;
43
+ return p.catch((e) => {
44
+ console.error(`${blue("Error to undefined error")}: ${red(e.stack)}`);
45
+ return undefined;
46
+ });
47
+ }
48
+ export function errorToUndefinedSilent<T>(p: Promise<T>): Promise<T | undefined> {
49
+ if (!p?.catch) return Promise.resolve(undefined);
50
+ return p.catch((e) => {
51
+ return undefined;
52
+ });
53
+ }
54
+
55
+ export function timeoutToError<T>(time: number, p: Promise<T>, err: () => Error) {
56
+ return new Promise<T>((resolve, reject) => {
57
+ let timeout = setTimeout(() => reject(err()), time);
58
+ p.then(resolve, reject).finally(() => clearTimeout(timeout));
59
+ });
60
+ }
61
+
62
+ // NOTE: Both errors and timeouts are converted to undefined
63
+ export function timeoutToUndefined<T>(time: number, p: Promise<T>) {
64
+ return new Promise<T | undefined>((resolve, reject) => {
65
+ let timeout = setTimeout(() => {
66
+ console.error(blue(`timeoutToUndefined timed out after ${time}`));
67
+ resolve(undefined);
68
+ }, time);
69
+ p.then(resolve,
70
+ (err) => {
71
+ console.error(`${blue("timeoutToUndefined error")}: ${red(err.stack)}`);
72
+ resolve(undefined);
73
+ }
74
+ ).finally(() => clearTimeout(timeout));
75
+ });
76
+ }
77
+ export function timeoutToUndefinedSilent<T>(time: number, p: Promise<T>) {
78
+ return new Promise<T | undefined>((resolve, reject) => {
79
+ let timeout = setTimeout(() => {
80
+ resolve(undefined);
81
+ }, time);
82
+ p.then(
83
+ resolve,
84
+ (err) => {
85
+ resolve(undefined);
86
+ }
87
+ ).finally(() => clearTimeout(timeout));
88
+ });
89
+ }
90
+
91
+ /** Used when accessing paid resources, so we don't rack up charges due to an error,
92
+ * but also so that it doesn't take forever for the initial call to run.
93
+ */
94
+ export async function backoffRetryLoop<T>(code: () => Promise<T>, waitTime = 5 * 1000) {
95
+ while (true) {
96
+ try {
97
+ return await code();
98
+ } catch (e: any) {
99
+ console.error(`Error retrying in ${waitTime}ms\n${e.stack}`);
100
+ await delay(waitTime);
101
+ waitTime *= 1.01;
102
+ }
103
+ }
104
+ }
105
+
106
+ export function errorify(error: any, messageOverride?: string) {
107
+ if (error instanceof Error) {
108
+ return error;
109
+ }
110
+ let errorObj = new Error();
111
+ if (typeof error === "string" && error.includes("\n")) {
112
+ errorObj.stack = error;
113
+ errorObj.message = error.split("\n")[0];
114
+ } else {
115
+ errorObj.message = error;
116
+ errorObj.stack = error + "\n" + errorObj.stack;
117
+ }
118
+ if (messageOverride) {
119
+ errorObj.message = messageOverride;
120
+ }
121
+ return errorObj;
122
+ }
123
+
124
+ export function assertValue<T>(value: T | undefined | null, message?: string): T {
125
+ if (value === undefined || value === null) {
126
+ throw new Error(`Value is ${value === undefined ? "undefined" : "null"}, ${message}`);
127
+ }
128
+ return value;
129
+ }
130
+ export function assert<T>(value: T | undefined | null, message?: string): asserts value is T {
131
+ if (value === undefined || value === null) {
132
+ throw new Error(`Value is ${value === undefined ? "undefined" : "null"}, ${message}`);
133
+ }
134
134
  }
@@ -1,3 +1,3 @@
1
- if (typeof process === "object") {
2
- process.env["NODE_ENV"] = "production";
1
+ if (typeof process === "object") {
2
+ process.env["NODE_ENV"] = "production";
3
3
  }
package/src/fs.ts CHANGED
@@ -1,81 +1,81 @@
1
- import { cache, lazy } from "socket-function/src/caching";
2
- import os from "os";
3
- import fs from "fs";
4
- import debugbreak from "debugbreak";
5
- import { isNode } from "socket-function/src/misc";
6
- import path from "path";
7
- import { magenta } from "socket-function/src/formatting/logColors";
8
-
9
- let rootDir = "";
10
- if (isNode()) {
11
- let base = path.resolve(".");
12
- // Search upwards until we find a package.json
13
- while (base.length > 3 && !fs.existsSync(base + "/package.json")) {
14
- base = path.resolve(base + "/..");
15
- }
16
- rootDir = pathToLongPath(base.replaceAll("\\", "/") + "/database-storage/");
17
- }
18
-
19
- export function setRootDirKey(key: string) {
20
- rootDir = pathToLongPath(os.homedir() + "/" + key + "/");
21
- }
22
- export function setRootDir(newRootDir: string) {
23
- rootDir = newRootDir;
24
- rootDir = pathToLongPath(rootDir);
25
- }
26
- function pathToLongPath(fullPath: string): string {
27
- // I guess we don't need the special prefix?
28
- // if (isNode() && process.platform === "win32") {
29
- // fullPath = path.resolve(fullPath);
30
- // if (!fullPath.startsWith("\\\\?\\")) {
31
- // fullPath = "\\\\?\\" + fullPath;
32
- // }
33
- // }
34
- if (isNode()) {
35
- fullPath = path.resolve(fullPath).replaceAll("\\", "/") + "/";
36
- }
37
- return fullPath;
38
- }
39
-
40
- export const getStorageDir = lazy(() => {
41
- let dir = rootDir;
42
- if (isNode() && !fs.existsSync(dir)) {
43
- fs.mkdirSync(dir);
44
- }
45
- return dir;
46
- });
47
-
48
- export const getSubFolder = cache((path: string) => {
49
- let dir = getStorageDir() + path;
50
- if (!dir.endsWith("/")) {
51
- dir += "/";
52
- }
53
- if (isNode() && !fs.existsSync(dir)) {
54
- fs.mkdirSync(dir);
55
- }
56
- return dir;
57
- });
58
- export const getStorageFolder = getSubFolder;
59
-
60
- export async function* readDirRecursive(dir: string): AsyncGenerator<string> {
61
- try {
62
- for (let file of await fs.promises.readdir(dir)) {
63
- let fullPath = dir + file;
64
- try {
65
- let stat = await fs.promises.stat(fullPath);
66
- if (stat.isDirectory()) {
67
- yield* readDirRecursive(fullPath + "/");
68
- }
69
- } catch { }
70
- }
71
- } catch { }
72
- }
73
-
74
- export async function fsExistsAsync(path: string) {
75
- try {
76
- await fs.promises.stat(path);
77
- return true;
78
- } catch {
79
- return false;
80
- }
1
+ import { cache, lazy } from "socket-function/src/caching";
2
+ import os from "os";
3
+ import fs from "fs";
4
+ import debugbreak from "debugbreak";
5
+ import { isNode } from "socket-function/src/misc";
6
+ import path from "path";
7
+ import { magenta } from "socket-function/src/formatting/logColors";
8
+
9
+ let rootDir = "";
10
+ if (isNode()) {
11
+ let base = path.resolve(".");
12
+ // Search upwards until we find a package.json
13
+ while (base.length > 3 && !fs.existsSync(base + "/package.json")) {
14
+ base = path.resolve(base + "/..");
15
+ }
16
+ rootDir = pathToLongPath(base.replaceAll("\\", "/") + "/database-storage/");
17
+ }
18
+
19
+ export function setRootDirKey(key: string) {
20
+ rootDir = pathToLongPath(os.homedir() + "/" + key + "/");
21
+ }
22
+ export function setRootDir(newRootDir: string) {
23
+ rootDir = newRootDir;
24
+ rootDir = pathToLongPath(rootDir);
25
+ }
26
+ function pathToLongPath(fullPath: string): string {
27
+ // I guess we don't need the special prefix?
28
+ // if (isNode() && process.platform === "win32") {
29
+ // fullPath = path.resolve(fullPath);
30
+ // if (!fullPath.startsWith("\\\\?\\")) {
31
+ // fullPath = "\\\\?\\" + fullPath;
32
+ // }
33
+ // }
34
+ if (isNode()) {
35
+ fullPath = path.resolve(fullPath).replaceAll("\\", "/") + "/";
36
+ }
37
+ return fullPath;
38
+ }
39
+
40
+ export const getStorageDir = lazy(() => {
41
+ let dir = rootDir;
42
+ if (isNode() && !fs.existsSync(dir)) {
43
+ fs.mkdirSync(dir);
44
+ }
45
+ return dir;
46
+ });
47
+
48
+ export const getSubFolder = cache((path: string) => {
49
+ let dir = getStorageDir() + path;
50
+ if (!dir.endsWith("/")) {
51
+ dir += "/";
52
+ }
53
+ if (isNode() && !fs.existsSync(dir)) {
54
+ fs.mkdirSync(dir);
55
+ }
56
+ return dir;
57
+ });
58
+ export const getStorageFolder = getSubFolder;
59
+
60
+ export async function* readDirRecursive(dir: string): AsyncGenerator<string> {
61
+ try {
62
+ for (let file of await fs.promises.readdir(dir)) {
63
+ let fullPath = dir + file;
64
+ try {
65
+ let stat = await fs.promises.stat(fullPath);
66
+ if (stat.isDirectory()) {
67
+ yield* readDirRecursive(fullPath + "/");
68
+ }
69
+ } catch { }
70
+ }
71
+ } catch { }
72
+ }
73
+
74
+ export async function fsExistsAsync(path: string) {
75
+ try {
76
+ await fs.promises.stat(path);
77
+ return true;
78
+ } catch {
79
+ return false;
80
+ }
81
81
  }