querysub 0.2.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/.dependency-cruiser.js +304 -0
- package/.eslintrc.js +51 -0
- package/.github/copilot-instructions.md +1 -0
- package/.vscode/settings.json +25 -0
- package/bin/deploy.js +4 -0
- package/bin/function.js +4 -0
- package/bin/server.js +4 -0
- package/costsBenefits.txt +112 -0
- package/deploy.ts +3 -0
- package/inject.ts +1 -0
- package/package.json +60 -0
- package/prompts.txt +54 -0
- package/spec.txt +820 -0
- package/src/-a-archives/archiveCache.ts +913 -0
- package/src/-a-archives/archives.ts +148 -0
- package/src/-a-archives/archivesBackBlaze.ts +792 -0
- package/src/-a-archives/archivesDisk.ts +418 -0
- package/src/-a-archives/copyLocalToBackblaze.ts +24 -0
- package/src/-a-auth/certs.ts +517 -0
- package/src/-a-auth/der.ts +122 -0
- package/src/-a-auth/ed25519.ts +1015 -0
- package/src/-a-auth/node-forge-ed25519.d.ts +17 -0
- package/src/-b-authorities/dnsAuthority.ts +203 -0
- package/src/-b-authorities/emailAuthority.ts +57 -0
- package/src/-c-identity/IdentityController.ts +200 -0
- package/src/-d-trust/NetworkTrust2.ts +150 -0
- package/src/-e-certs/EdgeCertController.ts +288 -0
- package/src/-e-certs/certAuthority.ts +192 -0
- package/src/-f-node-discovery/NodeDiscovery.ts +543 -0
- package/src/-g-core-values/NodeCapabilities.ts +134 -0
- package/src/-g-core-values/oneTimeForward.ts +91 -0
- package/src/-h-path-value-serialize/PathValueSerializer.ts +769 -0
- package/src/-h-path-value-serialize/stringSerializer.ts +176 -0
- package/src/0-path-value-core/LoggingClient.tsx +24 -0
- package/src/0-path-value-core/NodePathAuthorities.ts +978 -0
- package/src/0-path-value-core/PathController.ts +1 -0
- package/src/0-path-value-core/PathValueCommitter.ts +565 -0
- package/src/0-path-value-core/PathValueController.ts +231 -0
- package/src/0-path-value-core/archiveLocks/ArchiveLocks.ts +154 -0
- package/src/0-path-value-core/archiveLocks/ArchiveLocks2.ts +820 -0
- package/src/0-path-value-core/archiveLocks/archiveSnapshots.ts +180 -0
- package/src/0-path-value-core/debugLogs.ts +90 -0
- package/src/0-path-value-core/pathValueArchives.ts +483 -0
- package/src/0-path-value-core/pathValueCore.ts +2217 -0
- package/src/1-path-client/RemoteWatcher.ts +558 -0
- package/src/1-path-client/pathValueClientWatcher.ts +702 -0
- package/src/2-proxy/PathValueProxyWatcher.ts +1857 -0
- package/src/2-proxy/archiveMoveHarness.ts +376 -0
- package/src/2-proxy/garbageCollection.ts +753 -0
- package/src/2-proxy/pathDatabaseProxyBase.ts +37 -0
- package/src/2-proxy/pathValueProxy.ts +139 -0
- package/src/2-proxy/schema2.ts +518 -0
- package/src/3-path-functions/PathFunctionHelpers.ts +129 -0
- package/src/3-path-functions/PathFunctionRunner.ts +619 -0
- package/src/3-path-functions/PathFunctionRunnerMain.ts +67 -0
- package/src/3-path-functions/deployBlock.ts +10 -0
- package/src/3-path-functions/deployCheck.ts +7 -0
- package/src/3-path-functions/deployMain.ts +160 -0
- package/src/3-path-functions/pathFunctionLoader.ts +282 -0
- package/src/3-path-functions/syncSchema.ts +475 -0
- package/src/3-path-functions/tests/functionsTest.ts +135 -0
- package/src/3-path-functions/tests/rejectTest.ts +77 -0
- package/src/4-dom/css.tsx +29 -0
- package/src/4-dom/cssTypes.d.ts +212 -0
- package/src/4-dom/qreact.tsx +2322 -0
- package/src/4-dom/qreactTest.tsx +417 -0
- package/src/4-querysub/Querysub.ts +877 -0
- package/src/4-querysub/QuerysubController.ts +620 -0
- package/src/4-querysub/copyEvent.ts +0 -0
- package/src/4-querysub/permissions.ts +289 -0
- package/src/4-querysub/permissionsShared.ts +1 -0
- package/src/4-querysub/querysubPrediction.ts +525 -0
- package/src/5-diagnostics/FullscreenModal.tsx +67 -0
- package/src/5-diagnostics/GenericFormat.tsx +165 -0
- package/src/5-diagnostics/Modal.tsx +79 -0
- package/src/5-diagnostics/Table.tsx +183 -0
- package/src/5-diagnostics/TimeGrouper.tsx +114 -0
- package/src/5-diagnostics/diskValueAudit.ts +216 -0
- package/src/5-diagnostics/memoryValueAudit.ts +442 -0
- package/src/5-diagnostics/nodeMetadata.ts +135 -0
- package/src/5-diagnostics/qreactDebug.tsx +309 -0
- package/src/5-diagnostics/shared.ts +26 -0
- package/src/5-diagnostics/synchronousLagTracking.ts +47 -0
- package/src/TestController.ts +35 -0
- package/src/allowclient.flag +0 -0
- package/src/bits.ts +86 -0
- package/src/buffers.ts +69 -0
- package/src/config.ts +53 -0
- package/src/config2.ts +48 -0
- package/src/diagnostics/ActionsHistory.ts +56 -0
- package/src/diagnostics/NodeViewer.tsx +503 -0
- package/src/diagnostics/SizeLimiter.ts +62 -0
- package/src/diagnostics/TimeDebug.tsx +18 -0
- package/src/diagnostics/benchmark.ts +139 -0
- package/src/diagnostics/errorLogs/ErrorLogController.ts +515 -0
- package/src/diagnostics/errorLogs/ErrorLogCore.ts +274 -0
- package/src/diagnostics/errorLogs/LogClassifiers.tsx +302 -0
- package/src/diagnostics/errorLogs/LogFilterUI.tsx +84 -0
- package/src/diagnostics/errorLogs/LogNotify.tsx +101 -0
- package/src/diagnostics/errorLogs/LogTimeSelector.tsx +724 -0
- package/src/diagnostics/errorLogs/LogViewer.tsx +757 -0
- package/src/diagnostics/errorLogs/hookErrors.ts +60 -0
- package/src/diagnostics/errorLogs/logFiltering.tsx +149 -0
- package/src/diagnostics/heapTag.ts +13 -0
- package/src/diagnostics/listenOnDebugger.ts +77 -0
- package/src/diagnostics/logs/DiskLoggerPage.tsx +572 -0
- package/src/diagnostics/logs/ObjectDisplay.tsx +165 -0
- package/src/diagnostics/logs/ansiFormat.ts +108 -0
- package/src/diagnostics/logs/diskLogGlobalContext.ts +38 -0
- package/src/diagnostics/logs/diskLogger.ts +305 -0
- package/src/diagnostics/logs/diskShimConsoleLogs.ts +32 -0
- package/src/diagnostics/logs/injectFileLocationToConsole.ts +50 -0
- package/src/diagnostics/logs/logGitHashes.ts +30 -0
- package/src/diagnostics/managementPages.tsx +289 -0
- package/src/diagnostics/periodic.ts +89 -0
- package/src/diagnostics/runSaturationTest.ts +416 -0
- package/src/diagnostics/satSchema.ts +64 -0
- package/src/diagnostics/trackResources.ts +82 -0
- package/src/diagnostics/watchdog.ts +55 -0
- package/src/errors.ts +132 -0
- package/src/forceProduction.ts +3 -0
- package/src/fs.ts +72 -0
- package/src/heapDumps.ts +666 -0
- package/src/https.ts +2 -0
- package/src/inject.ts +1 -0
- package/src/library-components/ATag.tsx +84 -0
- package/src/library-components/Button.tsx +344 -0
- package/src/library-components/ButtonSelector.tsx +64 -0
- package/src/library-components/DropdownCustom.tsx +151 -0
- package/src/library-components/DropdownSelector.tsx +32 -0
- package/src/library-components/Input.tsx +334 -0
- package/src/library-components/InputLabel.tsx +198 -0
- package/src/library-components/InputPicker.tsx +125 -0
- package/src/library-components/LazyComponent.tsx +62 -0
- package/src/library-components/MeasureHeightCSS.tsx +48 -0
- package/src/library-components/MeasuredDiv.tsx +47 -0
- package/src/library-components/ShowMore.tsx +51 -0
- package/src/library-components/SyncedController.ts +171 -0
- package/src/library-components/TimeRangeSelector.tsx +407 -0
- package/src/library-components/URLParam.ts +263 -0
- package/src/library-components/colors.tsx +14 -0
- package/src/library-components/drag.ts +114 -0
- package/src/library-components/icons.tsx +692 -0
- package/src/library-components/niceStringify.ts +50 -0
- package/src/library-components/renderToString.ts +52 -0
- package/src/misc/PromiseRace.ts +101 -0
- package/src/misc/color.ts +30 -0
- package/src/misc/getParentProcessId.cs +53 -0
- package/src/misc/getParentProcessId.ts +53 -0
- package/src/misc/hash.ts +83 -0
- package/src/misc/ipPong.js +13 -0
- package/src/misc/networking.ts +2 -0
- package/src/misc/random.ts +45 -0
- package/src/misc.ts +19 -0
- package/src/noserverhotreload.flag +0 -0
- package/src/path.ts +226 -0
- package/src/persistentLocalStore.ts +37 -0
- package/src/promise.ts +15 -0
- package/src/server.ts +73 -0
- package/src/src.d.ts +1 -0
- package/src/test/heapProcess.ts +36 -0
- package/src/test/mongoSatTest.tsx +55 -0
- package/src/test/satTest.ts +193 -0
- package/src/test/test.tsx +552 -0
- package/src/zip.ts +92 -0
- package/src/zipThreaded.ts +106 -0
- package/src/zipThreadedWorker.js +19 -0
- package/tsconfig.json +27 -0
- package/yarnSpec.txt +56 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import debugbreak from "debugbreak";
|
|
2
|
+
|
|
3
|
+
let currentDatabase!: { value: unknown };
|
|
4
|
+
const CURRENT_DATABASE_GLOBAL_KEY = "pathDatabaseProxy_currentDatabase-7010c456-d83a-40f4-a58a-0ff0251cef16";
|
|
5
|
+
// NOTE: We use the global state, so that required libraries can use a different version
|
|
6
|
+
// of our library, but still share the same database!
|
|
7
|
+
if ((global as any)[CURRENT_DATABASE_GLOBAL_KEY]) {
|
|
8
|
+
currentDatabase = (global as any)[CURRENT_DATABASE_GLOBAL_KEY];
|
|
9
|
+
} else {
|
|
10
|
+
currentDatabase = { value: undefined };
|
|
11
|
+
(global as any)[CURRENT_DATABASE_GLOBAL_KEY] = currentDatabase;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function rawSchema<Schema>(): () => Schema {
|
|
15
|
+
return () => {
|
|
16
|
+
if (!currentDatabase.value) {
|
|
17
|
+
debugbreak(2);
|
|
18
|
+
debugger;
|
|
19
|
+
throw new Error(`Cannot access synced data outside of tracked code (render functions, event callbacks, QuerySub.serviceWrite, QuerySub.createWatcher callback, etc)`);
|
|
20
|
+
}
|
|
21
|
+
return currentDatabase.value as unknown as Schema;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function isInProxyDatabase() {
|
|
26
|
+
return !!currentDatabase.value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function runCodeWithDatabase<T>(database: unknown, code: () => T): T {
|
|
30
|
+
let prevDatabase = currentDatabase.value;
|
|
31
|
+
currentDatabase.value = database;
|
|
32
|
+
try {
|
|
33
|
+
return code();
|
|
34
|
+
} finally {
|
|
35
|
+
currentDatabase.value = prevDatabase;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { runInfinitePoll } from "socket-function/src/batching";
|
|
2
|
+
import { cache, lazy } from "socket-function/src/caching";
|
|
3
|
+
import { appendToPathStr, rootPathStr } from "../path";
|
|
4
|
+
import { MAX_CHANGE_AGE } from "../0-path-value-core/pathValueCore";
|
|
5
|
+
import { runCodeWithDatabase } from "./pathDatabaseProxyBase";
|
|
6
|
+
import { canHaveChildren } from "socket-function/src/types";
|
|
7
|
+
import { isNode } from "socket-function/src/misc";
|
|
8
|
+
|
|
9
|
+
let noopProxy = createPathValueProxy({ getCallback: () => undefined, setCallback: () => { }, getSymbol: () => undefined, getKeys: () => [] });
|
|
10
|
+
let gettingPath: { value: string } | undefined;
|
|
11
|
+
export function getProxyPath(get: () => unknown): string {
|
|
12
|
+
// We need to set the database incase it isn't set.
|
|
13
|
+
return runCodeWithDatabase(noopProxy, () => {
|
|
14
|
+
if (gettingPath) throw new Error(`Can't call getProxyPath while already getting a path.`);
|
|
15
|
+
gettingPath = { value: "" };
|
|
16
|
+
try {
|
|
17
|
+
get();
|
|
18
|
+
return gettingPath.value;
|
|
19
|
+
} finally {
|
|
20
|
+
gettingPath = undefined;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const isProxySymbol = Symbol.for("isProxySymbol");
|
|
26
|
+
export function isValueProxy(value: unknown) {
|
|
27
|
+
return canHaveChildren(value) && value[isProxySymbol];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const isProxySymbol2 = Symbol.for("isProxySymbol2");
|
|
31
|
+
/** If it is a proxy, returns the proxy path */
|
|
32
|
+
export function isValueProxy2(value: unknown): string | undefined {
|
|
33
|
+
return canHaveChildren(value) && value[isProxySymbol2] as any || undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const getPathFromProxy = isValueProxy2;
|
|
37
|
+
(globalThis as any).getPathFromProxy = getPathFromProxy;
|
|
38
|
+
|
|
39
|
+
export function createPathValueProxy(
|
|
40
|
+
config: {
|
|
41
|
+
getCallback: (pathStr: string) => { value: unknown } | undefined;
|
|
42
|
+
setCallback: (pathStr: string, value: unknown) => void;
|
|
43
|
+
hasCallback?: (pathStr: string) => boolean;
|
|
44
|
+
getSymbol: (pathStr: string, symbol: symbol) => { value: unknown } | undefined;
|
|
45
|
+
getKeys: (pathStr: string) => string[];
|
|
46
|
+
}
|
|
47
|
+
): unknown {
|
|
48
|
+
let createdCount = 0;
|
|
49
|
+
let createProxyCached = cache(createProxy);
|
|
50
|
+
let proxyClearLoop = lazy(() => {
|
|
51
|
+
runInfinitePoll(MAX_CHANGE_AGE, function clearProxyCache() {
|
|
52
|
+
// TODO: Maybe allow proxies to stick around?
|
|
53
|
+
//if (createdCount > 1000 * 100)
|
|
54
|
+
{
|
|
55
|
+
createdCount = 0;
|
|
56
|
+
createProxyCached = cache(createProxy);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
let ensureProxyClearLoop = () => {
|
|
61
|
+
if (createdCount < 1000 * 10) return;
|
|
62
|
+
proxyClearLoop();
|
|
63
|
+
};
|
|
64
|
+
return createProxyCached(rootPathStr);
|
|
65
|
+
function createProxy(parentPathStr: string) {
|
|
66
|
+
createdCount++;
|
|
67
|
+
let proxy: object = new Proxy(
|
|
68
|
+
// NOTE: This is an object now, because the data won't contain any functions, as that makes things way too
|
|
69
|
+
// complicated, and dangerous.
|
|
70
|
+
Object.create(null),
|
|
71
|
+
{
|
|
72
|
+
get(target, property) {
|
|
73
|
+
if (property === isProxySymbol) return true;
|
|
74
|
+
if (property === isProxySymbol2) return parentPathStr;
|
|
75
|
+
ensureProxyClearLoop();
|
|
76
|
+
if (typeof property === "symbol") {
|
|
77
|
+
let value = config.getSymbol(parentPathStr, property);
|
|
78
|
+
if (value) {
|
|
79
|
+
return value.value;
|
|
80
|
+
}
|
|
81
|
+
return createProxyCached(parentPathStr);
|
|
82
|
+
}
|
|
83
|
+
// if (property === "[object Object]") {
|
|
84
|
+
// console.warn(`Reading from key that looks like an object. Is it possible that you passed a proxy as a parameter which had no value? You might want to check if the key has a value first with if(atomic(value)). In ${parentPathStr}`);
|
|
85
|
+
// }
|
|
86
|
+
|
|
87
|
+
let pathStr = appendToPathStr(parentPathStr, property);
|
|
88
|
+
if (gettingPath) {
|
|
89
|
+
gettingPath.value = pathStr;
|
|
90
|
+
} else {
|
|
91
|
+
let value = config.getCallback(pathStr);
|
|
92
|
+
if (value) {
|
|
93
|
+
return value.value;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return createProxyCached(pathStr);
|
|
97
|
+
},
|
|
98
|
+
set(obj, prop, value) {
|
|
99
|
+
if (typeof prop === "symbol") {
|
|
100
|
+
throw new Error("Can't set symbol properties in the database");
|
|
101
|
+
}
|
|
102
|
+
let pathStr = appendToPathStr(parentPathStr, prop);
|
|
103
|
+
config.setCallback(pathStr, value);
|
|
104
|
+
return true;
|
|
105
|
+
},
|
|
106
|
+
// Just convert delete to be a set to undefined, so everything works
|
|
107
|
+
deleteProperty(target, prop) {
|
|
108
|
+
if (typeof prop === "symbol") {
|
|
109
|
+
throw new Error("Can't set symbol properties in the database");
|
|
110
|
+
}
|
|
111
|
+
let pathStr = appendToPathStr(parentPathStr, prop);
|
|
112
|
+
config.setCallback(pathStr, undefined);
|
|
113
|
+
return true;
|
|
114
|
+
},
|
|
115
|
+
getOwnPropertyDescriptor(target, property) {
|
|
116
|
+
// NOTE: The "value" field shouldn't even be part of the property descriptor, and usually isn't
|
|
117
|
+
// used. Returning it would just be inefficient, So while we should have
|
|
118
|
+
// `value: this[prop]` here, I'm not adding it.
|
|
119
|
+
return { configurable: true, enumerable: true, writable: true };
|
|
120
|
+
},
|
|
121
|
+
ownKeys(target) {
|
|
122
|
+
return config.getKeys(parentPathStr);
|
|
123
|
+
},
|
|
124
|
+
has(target, property) {
|
|
125
|
+
if (typeof property === "symbol") {
|
|
126
|
+
return (proxy as any)[property] !== undefined;
|
|
127
|
+
}
|
|
128
|
+
if (config.hasCallback) {
|
|
129
|
+
let pathStr = appendToPathStr(parentPathStr, property);
|
|
130
|
+
return config.hasCallback(pathStr);
|
|
131
|
+
}
|
|
132
|
+
let keys = config.getKeys(parentPathStr);
|
|
133
|
+
return keys.includes(property as string);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
return proxy;
|
|
138
|
+
}
|
|
139
|
+
}
|