@peers-app/peers-sdk 0.28.3 → 0.28.4
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.
|
@@ -3,7 +3,7 @@ import type { Table } from "../data/orm/table";
|
|
|
3
3
|
import type { ITool, IToolInstance } from "../data/tools";
|
|
4
4
|
import type { Event, ISubscriptionResult } from "../events";
|
|
5
5
|
import { type Observable } from "../observable";
|
|
6
|
-
import type
|
|
6
|
+
import { type IIsolatedCallPrincipal } from "../package-loader/isolated-runtime";
|
|
7
7
|
import type { IWorkflowRunContext } from "../types/workflow-run-context";
|
|
8
8
|
import { type IContractTransport } from "./contract-transport";
|
|
9
9
|
import type { IContractDefinition, IRemoteContractConsumer } from "./types";
|
|
@@ -12,6 +12,7 @@ const access_level_1 = require("../data/access-level");
|
|
|
12
12
|
const group_permissions_1 = require("../data/group-permissions");
|
|
13
13
|
const decorators_1 = require("../data/orm/decorators");
|
|
14
14
|
const observable_1 = require("../observable");
|
|
15
|
+
const isolated_runtime_1 = require("../package-loader/isolated-runtime");
|
|
15
16
|
const utils_1 = require("../utils");
|
|
16
17
|
const action_dispatch_1 = require("./action-dispatch");
|
|
17
18
|
const contract_transport_1 = require("./contract-transport");
|
|
@@ -585,7 +586,7 @@ function createContractProvider(resolution, opts = {}) {
|
|
|
585
586
|
throw new Error(`Table method '${call.name}.${call.operation}' is not remotely callable`);
|
|
586
587
|
}
|
|
587
588
|
(0, decorators_1.checkRemoteTableSaveOptions)(call.operation, call.args);
|
|
588
|
-
return impl.apply(table, call.args);
|
|
589
|
+
return impl.apply(table, (0, isolated_runtime_1.isolatedTableArgs)(call.operation, call.args));
|
|
589
590
|
}
|
|
590
591
|
case "tool": {
|
|
591
592
|
if (call.operation !== "run") {
|
|
@@ -12,19 +12,33 @@ export declare const ISOLATED_CONTRACT_TABLE_OPERATIONS: readonly ["get", "list"
|
|
|
12
12
|
export type IsolatedContractTableOperation = (typeof ISOLATED_CONTRACT_TABLE_OPERATIONS)[number];
|
|
13
13
|
/** Options a package may pass with a table `save`. */
|
|
14
14
|
export interface IPackageSaveOptions {
|
|
15
|
+
/** Seed a new row so any real write wins, even one not yet synced. Has no effect on updates. */
|
|
16
|
+
weakInsert?: boolean;
|
|
17
|
+
/** Create if missing; otherwise leave the row untouched and return it. Use with weakInsert for defaults. */
|
|
18
|
+
insertOnly?: boolean;
|
|
19
|
+
/** Reset the whole row, replacing even unseen earlier edits from other devices. Later writes still win. */
|
|
20
|
+
saveAsSnapshot?: boolean;
|
|
15
21
|
/** Save a row whose id was deleted before. Without it, that save is refused. */
|
|
16
22
|
restoreIfDeleted?: boolean;
|
|
17
23
|
}
|
|
18
24
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* and accepting it from a package would let that package backdate writes.
|
|
25
|
+
* Copy every host save option except `writtenAt`, accepting only values exactly equal to `true`.
|
|
26
|
+
* `writtenAt` stays host-only: it orders signed rows by their signing time, and accepting it
|
|
27
|
+
* from a package would let that package backdate writes. Unknown keys are dropped.
|
|
23
28
|
*
|
|
24
29
|
* @param options - A table `save`'s second argument, as received.
|
|
25
30
|
* @returns The allowed options, or `undefined` when none are set.
|
|
26
31
|
*/
|
|
27
32
|
export declare function isolatedSaveOptions(options: unknown): IPackageSaveOptions | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Limit a package or contract table write to its public arguments. Only `save` accepts
|
|
35
|
+
* options; `insert` and `update` accept only a row. Other operations keep their arguments.
|
|
36
|
+
*
|
|
37
|
+
* @param operation - The table method being called.
|
|
38
|
+
* @param args - Its arguments, as received across the bridge.
|
|
39
|
+
* @returns Arguments with save options filtered by {@link isolatedSaveOptions}.
|
|
40
|
+
*/
|
|
41
|
+
export declare function isolatedTableArgs(operation: string, args: unknown[]): unknown[];
|
|
28
42
|
/** One line a package worker wrote to its stdout or stderr. */
|
|
29
43
|
export interface IIsolatedWorkerOutput {
|
|
30
44
|
/** The worker's package. */
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ISOLATED_CONTRACT_TABLE_EVENTS = exports.ISOLATED_CONTRACT_TABLE_OPERATIONS = void 0;
|
|
4
4
|
exports.isolatedSaveOptions = isolatedSaveOptions;
|
|
5
|
+
exports.isolatedTableArgs = isolatedTableArgs;
|
|
5
6
|
exports.setIsolatedPackageRuntimeFactory = setIsolatedPackageRuntimeFactory;
|
|
6
7
|
exports.getIsolatedPackageRuntimeFactory = getIsolatedPackageRuntimeFactory;
|
|
7
8
|
/** Standard table methods exposed through isolated contract-table references. */
|
|
@@ -16,18 +17,36 @@ exports.ISOLATED_CONTRACT_TABLE_OPERATIONS = [
|
|
|
16
17
|
"delete",
|
|
17
18
|
];
|
|
18
19
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* and accepting it from a package would let that package backdate writes.
|
|
20
|
+
* Copy every host save option except `writtenAt`, accepting only values exactly equal to `true`.
|
|
21
|
+
* `writtenAt` stays host-only: it orders signed rows by their signing time, and accepting it
|
|
22
|
+
* from a package would let that package backdate writes. Unknown keys are dropped.
|
|
23
23
|
*
|
|
24
24
|
* @param options - A table `save`'s second argument, as received.
|
|
25
25
|
* @returns The allowed options, or `undefined` when none are set.
|
|
26
26
|
*/
|
|
27
27
|
function isolatedSaveOptions(options) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
const supplied = options;
|
|
29
|
+
const allowed = {};
|
|
30
|
+
for (const key of ["weakInsert", "insertOnly", "saveAsSnapshot", "restoreIfDeleted"]) {
|
|
31
|
+
if (supplied?.[key] === true)
|
|
32
|
+
allowed[key] = true;
|
|
33
|
+
}
|
|
34
|
+
return Object.keys(allowed).length ? allowed : undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Limit a package or contract table write to its public arguments. Only `save` accepts
|
|
38
|
+
* options; `insert` and `update` accept only a row. Other operations keep their arguments.
|
|
39
|
+
*
|
|
40
|
+
* @param operation - The table method being called.
|
|
41
|
+
* @param args - Its arguments, as received across the bridge.
|
|
42
|
+
* @returns Arguments with save options filtered by {@link isolatedSaveOptions}.
|
|
43
|
+
*/
|
|
44
|
+
function isolatedTableArgs(operation, args) {
|
|
45
|
+
if (operation === "save") {
|
|
46
|
+
const options = isolatedSaveOptions(args[1]);
|
|
47
|
+
return options ? [args[0], options] : args.slice(0, 1);
|
|
48
|
+
}
|
|
49
|
+
return operation === "insert" || operation === "update" ? args.slice(0, 1) : args;
|
|
31
50
|
}
|
|
32
51
|
/** Table events consumers may subscribe to on an isolated contract table. */
|
|
33
52
|
exports.ISOLATED_CONTRACT_TABLE_EVENTS = ["dataChanged"];
|