querysub 0.12.0 → 0.13.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "querysub",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "note1": "note on node-forge fork, see https://github.com/digitalbazaar/forge/issues/744 for details",
@@ -15,7 +15,7 @@
15
15
  "@types/pako": "^2.0.3",
16
16
  "@types/yargs": "^15.0.5",
17
17
  "acme-client": "^5.0.0",
18
- "cbor-x": "^1.5.6",
18
+ "cbor-x": "^1.6.0",
19
19
  "chalk": "^5.2.0",
20
20
  "diskusage": "^1.2.0",
21
21
  "fs-ext": "^2.0.0",
@@ -55,6 +55,7 @@ class PathValueCommitter {
55
55
  // Returns true if all the writes are accepted by some node (this should almost always be the case)
56
56
  public commitValues(values: PathValue[], predictWrites: "predictWrites" | undefined): void {
57
57
  if (values.length === 0) return;
58
+
58
59
  ActionsHistory.OnWrite(values);
59
60
 
60
61
  let now = Date.now();
@@ -31,6 +31,7 @@ import type { FunctionMetadata } from "../3-path-functions/syncSchema";
31
31
  import { DEPTH_TO_DATA, MODULE_INDEX, getCurrentCall, getCurrentCallObj } from "../3-path-functions/PathFunctionRunner";
32
32
  import { inlineNestedCalls } from "../3-path-functions/syncSchema";
33
33
  import { interceptCalls, runCall } from "../3-path-functions/PathFunctionHelpers";
34
+ import { deepCloneCborx } from "../misc/cloneHelpers";
34
35
 
35
36
  // TODO: Break this into two parts:
36
37
  // 1) Run and get accesses
@@ -596,6 +597,15 @@ export class PathValueProxyWatcher {
596
597
  throw new Error(`Tried to write a non-local path in a "noLocks" watcher, ${watcher.debugName}, path ${pathStr}`);
597
598
  }
598
599
 
600
+ if (!pathStr.startsWith(LOCAL_DOMAIN_PATH)) {
601
+ // Copy the value, to ensure any proxy values aren't attempted to be written
602
+ // to the database. A bit slower, but... it should be fine. We COULD do this
603
+ // later on, but this makes it easier to attribute lag and errors to the original source.
604
+ // - If we had a proxy, we WOULD copy it eventually, but we would copy it later,
605
+ // which would cause an error, because the reader wouldn't be trackable.
606
+ value = deepCloneCborx(value);
607
+ }
608
+
599
609
  if (watcher.permissionsChecker) {
600
610
  if (!watcher.permissionsChecker.checkPermissions(pathStr).allowed) {
601
611
  if (value !== specialObjectWriteValue) {
@@ -13,6 +13,7 @@ import { isDefined } from "../misc";
13
13
  import { blue, green, red } from "socket-function/src/formatting/logColors";
14
14
  import { getPathStr2 } from "../path";
15
15
  import { sort } from "socket-function/src/misc";
16
+ import { decodeCborx, encodeCborx } from "../misc/cloneHelpers";
16
17
  const cborxInstance = lazy(() => new cborx.Encoder({ structuredClone: true }));
17
18
 
18
19
 
@@ -174,15 +175,9 @@ export function writeFunctionCall(config: {
174
175
  }
175
176
 
176
177
  export function parseArgs(call: CallSpec) {
177
- return cborxInstance().decode(Buffer.from(call.argsEncoded, "base64"));
178
+ return decodeCborx(Buffer.from(call.argsEncoded, "base64"));
178
179
  }
179
180
 
180
181
  export function encodeArgs(args: unknown[]) {
181
- // NOTE: This will throw if we try to encode a function. This is probably okay.
182
- // - We use this to prevent accidentally encoding VirtualDOM to the database / objects
183
- // with functions.
184
- // - If this becomes an issue, we might catch the error, and strip functions if we
185
- // have found them.
186
- // - Or... is there are a way to tell cborx to strip the functions?
187
- return cborxInstance().encode(args).toString("base64");
182
+ return encodeCborx(args).toString("base64");
188
183
  }
@@ -0,0 +1,16 @@
1
+ import cborx from "cbor-x";
2
+ import { lazy } from "socket-function/src/caching";
3
+ const cborxInstance = lazy(() => new cborx.Encoder({ structuredClone: true }));
4
+ export function deepCloneCborx<T>(value: T): T {
5
+ return decodeCborx(encodeCborx(value));
6
+ }
7
+
8
+
9
+ export function encodeCborx<T>(value: T): Buffer {
10
+ // We need to iterate on it, expanding keys, etc
11
+ return cborxInstance().encode(value);
12
+ }
13
+
14
+ export function decodeCborx<T>(value: Buffer): T {
15
+ return cborxInstance().decode(value);
16
+ }