copilotz 1.0.0-rc.20 → 1.0.0-rc.21
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/CHANGELOG.md +417 -0
- package/README.md +295 -19
- package/hosts/orgs/mod.d.ts +4 -1
- package/hosts/orgs/mod.js +2 -2
- package/hosts/web/files.d.ts +6 -2
- package/hosts/web/files.js +36 -3
- package/hosts/web/node/mod.d.ts +1 -1
- package/hosts/web/node/mod.js +1 -1
- package/hosts/web/node/serve.d.ts +26 -0
- package/hosts/web/node/serve.js +23 -1
- package/hosts/web/routes.d.ts +28 -1
- package/hosts/web/routes.js +65 -10
- package/hosts/web/server.d.ts +5 -4
- package/hosts/web/server.js +1 -1
- package/package.json +2 -2
- package/plugins/access/accounts/collections/account.d.ts +2 -2
- package/plugins/access/contacts/actions/chat.d.ts +1 -0
- package/plugins/access/contacts/actions/chat.js +45 -0
- package/plugins/access/contacts/actions/forget.d.ts +1 -0
- package/plugins/access/contacts/actions/forget.js +56 -0
- package/plugins/access/contacts/actions/start.d.ts +1 -0
- package/plugins/access/contacts/actions/start.js +50 -0
- package/plugins/access/contacts/collections/contact.d.ts +81 -0
- package/plugins/access/contacts/collections/contact.js +58 -0
- package/plugins/access/contacts/contract.d.ts +10 -0
- package/plugins/access/contacts/contract.js +10 -0
- package/plugins/access/contacts/mod.d.ts +27 -0
- package/plugins/access/contacts/mod.js +49 -0
- package/plugins/access/contacts/views/contact.d.ts +8 -0
- package/plugins/access/contacts/views/contact.js +25 -0
- package/plugins/access/contacts/web.d.ts +7 -0
- package/plugins/access/contacts/web.js +11 -0
- package/plugins/access/directory/collections/credit-code.d.ts +1 -1
- package/plugins/access/directory/collections/invite.d.ts +1 -1
- package/plugins/access/identity/mod.js +8 -6
- package/plugins/access/mod.d.ts +7 -1
- package/plugins/access/mod.js +7 -2
- package/plugins/access/spaces/actions/agents.js +12 -6
- package/plugins/access/spaces/actions/create.js +10 -1
- package/plugins/access/spaces/actions/invitation.js +5 -2
- package/plugins/access/spaces/actions/keep.d.ts +1 -0
- package/plugins/access/spaces/actions/keep.js +55 -0
- package/plugins/access/spaces/actions/member.js +17 -4
- package/plugins/access/spaces/actions/rename.js +4 -0
- package/plugins/access/spaces/collections/member.d.ts +1 -1
- package/plugins/access/spaces/collections/request.d.ts +1 -1
- package/plugins/access/spaces/collections/space.d.ts +9 -0
- package/plugins/access/spaces/collections/space.js +2 -0
- package/plugins/access/spaces/contract.d.ts +4 -3
- package/plugins/access/spaces/contract.js +1 -1
- package/plugins/access/spaces/mod.d.ts +7 -1
- package/plugins/access/spaces/mod.js +8 -1
- package/plugins/access/spaces/resources/tools.d.ts +0 -5
- package/plugins/access/spaces/resources/tools.js +11 -1
- package/plugins/access/spaces/shared/agents.js +2 -2
- package/plugins/access/spaces/shared/can.d.ts +18 -3
- package/plugins/access/spaces/shared/can.js +32 -5
- package/plugins/access/spaces/shared/declared.d.ts +21 -0
- package/plugins/access/spaces/shared/declared.js +8 -0
- package/plugins/access/spaces/shared/labels.d.ts +7 -1
- package/plugins/access/spaces/shared/labels.js +56 -8
- package/plugins/access/spaces/shared/managers.js +2 -2
- package/plugins/access/spaces/shared/names.d.ts +9 -5
- package/plugins/access/spaces/shared/names.js +36 -19
- package/plugins/access/spaces/shared/reach.d.ts +20 -6
- package/plugins/access/spaces/shared/reach.js +62 -20
- package/plugins/access/spaces/shared/rules.d.ts +10 -5
- package/plugins/access/spaces/shared/rules.js +35 -10
- package/plugins/access/spaces/shared/seat.d.ts +3 -2
- package/plugins/access/spaces/shared/seat.js +9 -2
- package/plugins/access/spaces/views/where.d.ts +4 -2
- package/plugins/access/spaces/views/where.js +9 -0
- package/plugins/access/spaces/web.js +1 -1
- package/plugins/access/web.d.ts +1 -0
- package/plugins/access/web.js +1 -0
- package/plugins/agents/chat/actions/erase.d.ts +1 -0
- package/plugins/agents/chat/actions/erase.js +51 -0
- package/plugins/agents/chat/actions/open.d.ts +1 -0
- package/plugins/agents/chat/actions/open.js +49 -0
- package/plugins/agents/chat/actions/quiet.d.ts +1 -0
- package/plugins/agents/chat/actions/quiet.js +33 -0
- package/plugins/agents/chat/actions/say.d.ts +1 -0
- package/plugins/agents/chat/actions/say.js +82 -0
- package/plugins/agents/chat/actions/send.js +57 -19
- package/plugins/agents/chat/actions/shown.d.ts +1 -0
- package/plugins/agents/chat/actions/shown.js +35 -0
- package/plugins/agents/chat/collections/intent.d.ts +124 -0
- package/plugins/agents/chat/collections/intent.js +52 -0
- package/plugins/agents/chat/collections/message.d.ts +74 -1
- package/plugins/agents/chat/collections/message.js +23 -1
- package/plugins/agents/chat/collections/shown.d.ts +105 -0
- package/plugins/agents/chat/collections/shown.js +34 -0
- package/plugins/agents/chat/contract.d.ts +15 -7
- package/plugins/agents/chat/contract.js +7 -1
- package/plugins/agents/chat/mod.d.ts +20 -2
- package/plugins/agents/chat/mod.js +43 -4
- package/plugins/agents/chat/processors/failed.js +15 -5
- package/plugins/agents/chat/processors/turn.d.ts +1 -1
- package/plugins/agents/chat/processors/turn.js +95 -35
- package/plugins/agents/chat/shared/delivery.d.ts +16 -2
- package/plugins/agents/chat/shared/delivery.js +62 -7
- package/plugins/agents/chat/shared/send.d.ts +1 -3
- package/plugins/agents/chat/shared/send.js +2 -9
- package/plugins/agents/chat/shared/tools.d.ts +33 -0
- package/plugins/agents/chat/shared/tools.js +28 -0
- package/plugins/agents/chat/shared/types.d.ts +59 -1
- package/plugins/agents/chat/views/message.d.ts +4 -2
- package/plugins/agents/chat/views/message.js +22 -4
- package/plugins/agents/chat/views/prompt.js +38 -4
- package/plugins/agents/history/collections/outline.d.ts +1 -1
- package/plugins/agents/history/collections/summary.d.ts +1 -1
- package/plugins/agents/history/mod.js +2 -1
- package/plugins/agents/history/processors/erase.d.ts +3 -0
- package/plugins/agents/history/processors/erase.js +11 -0
- package/plugins/agents/memory/mod.js +2 -1
- package/plugins/agents/memory/processors/extract.d.ts +1 -1
- package/plugins/agents/memory/processors/extract.js +5 -0
- package/plugins/agents/memory/resources/tools.js +1 -1
- package/plugins/agents/memory/shared/settings.d.ts +7 -2
- package/plugins/agents/memory/shared/settings.js +9 -1
- package/plugins/agents/routines/collections/routine.d.ts +1 -1
- package/plugins/agents/routines/collections/run.d.ts +1 -1
- package/plugins/compute/apps/collections/app.d.ts +2 -2
- package/plugins/compute/cloud/resources/tools.js +3 -3
- package/plugins/compute/computers/collections/approval.d.ts +2 -2
- package/plugins/compute/computers/collections/grant.d.ts +1 -1
- package/plugins/compute/computers/collections/preview.d.ts +2 -2
- package/plugins/compute/computers/program/version.d.ts +1 -1
- package/plugins/compute/computers/program/version.js +1 -1
- package/plugins/compute/computers/resources/downloads.js +1 -1
- package/plugins/compute/computers/shared/wake.d.ts +1 -1
- package/plugins/compute/computers/shared/wake.js +17 -0
- package/plugins/interfaces/api/collections/key.d.ts +1 -1
- package/plugins/interfaces/api/shared/events.js +5 -4
- package/plugins/interfaces/maintenance/actions/read.d.ts +4 -0
- package/plugins/interfaces/maintenance/actions/read.js +76 -0
- package/plugins/interfaces/maintenance/actions/write.d.ts +4 -0
- package/plugins/interfaces/maintenance/actions/write.js +64 -0
- package/plugins/interfaces/maintenance/contract.d.ts +60 -0
- package/plugins/interfaces/maintenance/contract.js +2 -0
- package/plugins/interfaces/maintenance/mod.d.ts +52 -0
- package/plugins/interfaces/maintenance/mod.js +66 -0
- package/plugins/interfaces/maintenance/resources/routes.d.ts +71 -0
- package/plugins/interfaces/maintenance/resources/routes.js +457 -0
- package/plugins/interfaces/maintenance/shared/ops.d.ts +4 -0
- package/plugins/interfaces/maintenance/shared/ops.js +19 -0
- package/plugins/interfaces/mcp/actions/call.d.ts +11 -0
- package/plugins/interfaces/mcp/actions/call.js +304 -0
- package/plugins/interfaces/mcp/actions/prune.d.ts +1 -0
- package/plugins/interfaces/mcp/actions/prune.js +18 -0
- package/plugins/interfaces/mcp/collections/closed.d.ts +23 -0
- package/plugins/interfaces/mcp/collections/closed.js +17 -0
- package/plugins/interfaces/mcp/collections/rate.d.ts +27 -0
- package/plugins/interfaces/mcp/collections/rate.js +18 -0
- package/plugins/interfaces/mcp/collections/receipt.d.ts +46 -0
- package/plugins/interfaces/mcp/collections/receipt.js +46 -0
- package/plugins/interfaces/mcp/contract.d.ts +9 -0
- package/plugins/interfaces/mcp/contract.js +9 -0
- package/plugins/interfaces/mcp/mod.d.ts +84 -0
- package/plugins/interfaces/mcp/mod.js +122 -0
- package/plugins/interfaces/mcp/processors/closed.d.ts +13 -0
- package/plugins/interfaces/mcp/processors/closed.js +16 -0
- package/plugins/interfaces/mcp/resources/running.d.ts +21 -0
- package/plugins/interfaces/mcp/resources/running.js +36 -0
- package/plugins/interfaces/mcp/resources/server.d.ts +54 -0
- package/plugins/interfaces/mcp/resources/server.js +423 -0
- package/plugins/interfaces/mcp/resources/tools.d.ts +114 -0
- package/plugins/interfaces/mcp/resources/tools.js +324 -0
- package/plugins/interfaces/mcp/shared/caller.d.ts +45 -0
- package/plugins/interfaces/mcp/shared/caller.js +99 -0
- package/plugins/interfaces/mcp/shared/keys.d.ts +50 -0
- package/plugins/interfaces/mcp/shared/keys.js +53 -0
- package/plugins/interfaces/mcp/shared/settings.d.ts +187 -0
- package/plugins/interfaces/mcp/shared/settings.js +176 -0
- package/plugins/interfaces/mcp/views/offered.d.ts +20 -0
- package/plugins/interfaces/mcp/views/offered.js +20 -0
- package/plugins/interfaces/mod.d.ts +5 -1
- package/plugins/interfaces/mod.js +5 -1
- package/plugins/interfaces/terminal/actions/print.js +1 -1
- package/plugins/interfaces/terminal/actions/set.js +1 -1
- package/plugins/interfaces/terminal/collections/output.d.ts +1 -1
- package/plugins/interfaces/terminal/collections/shell.js +1 -1
- package/plugins/interfaces/voice/actions/block.d.ts +2 -0
- package/plugins/interfaces/voice/actions/block.js +74 -0
- package/plugins/interfaces/voice/actions/call.d.ts +19 -0
- package/plugins/interfaces/voice/actions/call.js +253 -0
- package/plugins/interfaces/voice/actions/hook.d.ts +5 -0
- package/plugins/interfaces/voice/actions/hook.js +225 -0
- package/plugins/interfaces/voice/actions/prune.d.ts +1 -0
- package/plugins/interfaces/voice/actions/prune.js +35 -0
- package/plugins/interfaces/voice/collections/blocked.d.ts +87 -0
- package/plugins/interfaces/voice/collections/blocked.js +34 -0
- package/plugins/interfaces/voice/collections/call.d.ts +279 -0
- package/plugins/interfaces/voice/collections/call.js +77 -0
- package/plugins/interfaces/voice/collections/phone.d.ts +74 -0
- package/plugins/interfaces/voice/collections/phone.js +26 -0
- package/plugins/interfaces/voice/contract.d.ts +14 -0
- package/plugins/interfaces/voice/contract.js +2 -0
- package/plugins/interfaces/voice/mod.d.ts +57 -0
- package/plugins/interfaces/voice/mod.js +118 -0
- package/plugins/interfaces/voice/processors/forget.d.ts +13 -0
- package/plugins/interfaces/voice/processors/forget.js +27 -0
- package/plugins/interfaces/voice/resources/relay.d.ts +77 -0
- package/plugins/interfaces/voice/resources/relay.js +428 -0
- package/plugins/interfaces/voice/resources/tools.d.ts +1 -0
- package/plugins/interfaces/voice/resources/tools.js +25 -0
- package/plugins/interfaces/voice/shared/caller.d.ts +27 -0
- package/plugins/interfaces/voice/shared/caller.js +38 -0
- package/plugins/interfaces/voice/shared/settings.d.ts +136 -0
- package/plugins/interfaces/voice/shared/settings.js +121 -0
- package/plugins/interfaces/voice/shared/signature.d.ts +11 -0
- package/plugins/interfaces/voice/shared/signature.js +34 -0
- package/plugins/interfaces/voice/views/call.d.ts +41 -0
- package/plugins/interfaces/voice/views/call.js +30 -0
- package/plugins/interfaces/voice/views/context.d.ts +9 -0
- package/plugins/interfaces/voice/views/context.js +14 -0
- package/plugins/interfaces/voice/views/message.d.ts +17 -0
- package/plugins/interfaces/voice/views/message.js +41 -0
- package/plugins/interfaces/whatsapp/actions/connect.js +3 -0
- package/plugins/interfaces/whatsapp/actions/disconnect.js +4 -1
- package/plugins/interfaces/whatsapp/actions/hook.js +27 -11
- package/plugins/interfaces/whatsapp/actions/set.d.ts +8 -0
- package/plugins/interfaces/whatsapp/actions/set.js +121 -0
- package/plugins/interfaces/whatsapp/collections/blocked.d.ts +29 -0
- package/plugins/interfaces/whatsapp/collections/blocked.js +22 -0
- package/plugins/interfaces/whatsapp/collections/code.d.ts +1 -1
- package/plugins/interfaces/whatsapp/collections/number.d.ts +90 -4
- package/plugins/interfaces/whatsapp/collections/number.js +36 -4
- package/plugins/interfaces/whatsapp/collections/phone.d.ts +13 -3
- package/plugins/interfaces/whatsapp/collections/phone.js +9 -3
- package/plugins/interfaces/whatsapp/collections/rate.d.ts +27 -0
- package/plugins/interfaces/whatsapp/collections/rate.js +13 -0
- package/plugins/interfaces/whatsapp/collections/sent.d.ts +24 -12
- package/plugins/interfaces/whatsapp/collections/sent.js +11 -7
- package/plugins/interfaces/whatsapp/collections/thread.d.ts +14 -6
- package/plugins/interfaces/whatsapp/collections/thread.js +7 -5
- package/plugins/interfaces/whatsapp/collections/typing.d.ts +70 -0
- package/plugins/interfaces/whatsapp/collections/typing.js +21 -0
- package/plugins/interfaces/whatsapp/contract.d.ts +27 -4
- package/plugins/interfaces/whatsapp/contract.js +34 -1
- package/plugins/interfaces/whatsapp/events/undelivered.d.ts +8 -0
- package/plugins/interfaces/whatsapp/events/undelivered.js +17 -0
- package/plugins/interfaces/whatsapp/mod.d.ts +28 -2
- package/plugins/interfaces/whatsapp/mod.js +65 -6
- package/plugins/interfaces/whatsapp/processors/forget.d.ts +6 -0
- package/plugins/interfaces/whatsapp/processors/forget.js +11 -0
- package/plugins/interfaces/whatsapp/processors/receive.d.ts +17 -3
- package/plugins/interfaces/whatsapp/processors/receive.js +264 -81
- package/plugins/interfaces/whatsapp/processors/reply.d.ts +25 -5
- package/plugins/interfaces/whatsapp/processors/reply.js +216 -20
- package/plugins/interfaces/whatsapp/processors/typing.d.ts +8 -0
- package/plugins/interfaces/whatsapp/processors/typing.js +25 -0
- package/plugins/interfaces/whatsapp/shared/customers.d.ts +13 -0
- package/plugins/interfaces/whatsapp/shared/customers.js +16 -0
- package/plugins/interfaces/whatsapp/shared/graph.d.ts +31 -6
- package/plugins/interfaces/whatsapp/shared/graph.js +117 -10
- package/plugins/interfaces/whatsapp/shared/media.d.ts +23 -0
- package/plugins/interfaces/whatsapp/shared/media.js +46 -0
- package/plugins/interfaces/whatsapp/shared/number.d.ts +19 -8
- package/plugins/interfaces/whatsapp/shared/number.js +64 -7
- package/plugins/interfaces/whatsapp/shared/parts.d.ts +94 -0
- package/plugins/interfaces/whatsapp/shared/parts.js +184 -0
- package/plugins/interfaces/whatsapp/shared/payload.d.ts +27 -1
- package/plugins/interfaces/whatsapp/shared/payload.js +36 -1
- package/plugins/interfaces/whatsapp/shared/settings.d.ts +49 -1
- package/plugins/interfaces/whatsapp/shared/settings.js +11 -0
- package/plugins/interfaces/whatsapp/views/message.d.ts +13 -0
- package/plugins/interfaces/whatsapp/views/message.js +13 -0
- package/plugins/interfaces/whatsapp/views/web/line.d.ts +24 -0
- package/plugins/interfaces/whatsapp/views/web/line.js +44 -0
- package/plugins/interfaces/whatsapp/views/web/space.d.ts +7 -5
- package/plugins/interfaces/whatsapp/views/web/space.js +17 -10
- package/plugins/interfaces/whatsapp/views/web/style.d.ts +1 -1
- package/plugins/interfaces/whatsapp/views/web/style.js +8 -0
- package/plugins/models/adapters/llm/anthropic.d.ts +1 -1
- package/plugins/models/adapters/llm/anthropic.js +28 -15
- package/plugins/models/adapters/llm/gemini.d.ts +1 -1
- package/plugins/models/adapters/llm/gemini.js +2 -1
- package/plugins/models/adapters/llm/openai-compatible.d.ts +1 -1
- package/plugins/models/adapters/llm/openai-compatible.js +2 -1
- package/plugins/models/adapters/llm/openai.d.ts +1 -1
- package/plugins/models/adapters/llm/openai.js +16 -4
- package/plugins/models/shared/types.d.ts +8 -0
- package/plugins/models/shared/types.js +10 -0
- package/runtime/actor.d.ts +6 -0
- package/runtime/actor.js +9 -4
- package/runtime/aggregate.js +8 -2
- package/runtime/blobs.d.ts +15 -12
- package/runtime/blobs.js +58 -11
- package/runtime/cache.d.ts +6 -0
- package/runtime/cache.js +19 -1
- package/runtime/define.d.ts +10 -0
- package/runtime/errors.d.ts +20 -2
- package/runtime/errors.js +7 -1
- package/runtime/executor.js +27 -11
- package/runtime/links.d.ts +31 -0
- package/runtime/links.js +60 -0
- package/runtime/maintain.d.ts +88 -0
- package/runtime/maintain.js +120 -0
- package/runtime/memory.js +7 -4
- package/runtime/mod.d.ts +6 -4
- package/runtime/mod.js +5 -2
- package/runtime/mongo.d.ts +13 -0
- package/runtime/mongo.js +39 -8
- package/runtime/observe.d.ts +2 -0
- package/runtime/observe.js +14 -10
- package/runtime/ops.d.ts +5 -0
- package/runtime/ops.js +10 -1
- package/runtime/owner.d.ts +18 -1
- package/runtime/owner.js +127 -61
- package/runtime/presence.d.ts +18 -0
- package/runtime/presence.js +25 -0
- package/runtime/registry.d.ts +5 -0
- package/runtime/registry.js +18 -0
- package/runtime/runtime.js +9 -3
- package/runtime/store.d.ts +48 -1
- package/runtime/wire.d.ts +1 -0
- package/runtime/wire.js +3 -1
- package/stores/blobs/files/mod.js +4 -2
- package/stores/blobs/gcs/mod.d.ts +3 -0
- package/stores/blobs/gcs/mod.js +6 -5
- package/stores/blobs/http/mod.d.ts +1 -1
- package/stores/blobs/http/mod.js +2 -1
- package/stores/latency/mod.js +5 -1
- package/stores/sql/postgres/maintenance.d.ts +24 -0
- package/stores/sql/postgres/maintenance.js +258 -0
- package/stores/sql/postgres/mod.d.ts +20 -4
- package/stores/sql/postgres/mod.js +363 -96
- package/stores/sql/postgres/update.js +3 -1
- package/stores/sql/shared/capped.d.ts +2 -0
- package/stores/sql/shared/capped.js +22 -0
- package/stores/sql/shared/rows.d.ts +14 -0
- package/stores/sql/shared/rows.js +29 -0
- package/stores/sql/shared/statement.d.ts +12 -0
- package/stores/sql/shared/statement.js +244 -0
- package/stores/sql/sqlite/apart.d.ts +11 -0
- package/stores/sql/sqlite/apart.js +219 -0
- package/stores/sql/sqlite/mod.d.ts +16 -2
- package/stores/sql/sqlite/mod.js +246 -51
- package/testing/mod.js +1 -1
package/runtime/mongo.js
CHANGED
|
@@ -1,28 +1,57 @@
|
|
|
1
|
+
import { invalid } from "./errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* A field name a write may give: not an operator's or a blob reference's
|
|
4
|
+
* (`$…`, as MongoDB refuses them), nor `__proto__`, which reaches the
|
|
5
|
+
* prototype; else `invalid`. `constructor` and `prototype` are names like any
|
|
6
|
+
* other: paths follow and make an object's own fields only. `path` is what
|
|
7
|
+
* the name is part of, for the message.
|
|
8
|
+
*/
|
|
9
|
+
export function checkName(name, path = name) {
|
|
10
|
+
if (!isFieldName(name)) {
|
|
11
|
+
throw invalid(`A write can't name the field "${path.slice(0, 80)}": no part of it may start with "$", ` +
|
|
12
|
+
`or be __proto__`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** Whether a write may give a field this name (see `checkName`). */
|
|
16
|
+
export const isFieldName = (name) => !name.startsWith("$") && name !== "__proto__";
|
|
17
|
+
/** A dotted path a write may name: every part of it a field name it may give. */
|
|
18
|
+
export function checkPath(path) {
|
|
19
|
+
for (const name of path.split("."))
|
|
20
|
+
checkName(name, path);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Whether a path goes on into `value`: an object or array, but not a blob
|
|
24
|
+
* reference, which stands for a (large) string, nor any other object with a
|
|
25
|
+
* `$blob` key (planted). A path ends at those as it does at a string.
|
|
26
|
+
*/
|
|
27
|
+
const branch = (value) => value !== null && typeof value === "object" && !Object.hasOwn(value, "$blob");
|
|
28
|
+
/** The value at a dotted path, through the document's own fields only (never its prototype's). */
|
|
1
29
|
export function get(doc, path) {
|
|
2
30
|
let value = doc;
|
|
3
31
|
for (const key of path.split(".")) {
|
|
4
|
-
if (value
|
|
32
|
+
if (!branch(value) || !Object.hasOwn(value, key))
|
|
5
33
|
return undefined;
|
|
6
34
|
value = value[key];
|
|
7
35
|
}
|
|
8
36
|
return value;
|
|
9
37
|
}
|
|
38
|
+
/** Sets a dotted path's value, making objects on the way (in place of anything else there). */
|
|
10
39
|
function set(doc, path, value) {
|
|
40
|
+
checkPath(path);
|
|
11
41
|
const keys = path.split(".");
|
|
12
42
|
let target = doc;
|
|
13
43
|
for (const key of keys.slice(0, -1)) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
target = target[key];
|
|
44
|
+
const next = Object.hasOwn(target, key) ? target[key] : undefined;
|
|
45
|
+
target = (branch(next) ? next : (target[key] = {}));
|
|
17
46
|
}
|
|
18
47
|
target[keys.at(-1)] = value;
|
|
19
48
|
}
|
|
20
49
|
function unset(doc, path) {
|
|
50
|
+
checkPath(path);
|
|
21
51
|
const keys = path.split(".");
|
|
22
52
|
const parent = keys.length > 1 ? get(doc, keys.slice(0, -1).join(".")) : doc;
|
|
23
|
-
if (parent
|
|
53
|
+
if (branch(parent))
|
|
24
54
|
delete parent[keys.at(-1)];
|
|
25
|
-
}
|
|
26
55
|
}
|
|
27
56
|
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
28
57
|
const OPERATORS = new Set([
|
|
@@ -189,6 +218,8 @@ export function sortAndPage(docs, options = {}) {
|
|
|
189
218
|
*/
|
|
190
219
|
export function seedOf(filter) {
|
|
191
220
|
const seed = {};
|
|
221
|
+
// What it takes, it writes.
|
|
222
|
+
const checked = (path) => (checkPath(path), path);
|
|
192
223
|
const take = (clause) => {
|
|
193
224
|
for (const [path, value] of Object.entries(clause)) {
|
|
194
225
|
if (path === "$and") {
|
|
@@ -198,9 +229,9 @@ export function seedOf(filter) {
|
|
|
198
229
|
else if (path.startsWith("$"))
|
|
199
230
|
continue;
|
|
200
231
|
else if (value === null || typeof value !== "object")
|
|
201
|
-
seed[path] = value;
|
|
232
|
+
seed[checked(path)] = value;
|
|
202
233
|
else if ("$eq" in value && Object.keys(value).length === 1)
|
|
203
|
-
seed[path] = value.$eq;
|
|
234
|
+
seed[checked(path)] = value.$eq;
|
|
204
235
|
}
|
|
205
236
|
};
|
|
206
237
|
take(filter);
|
package/runtime/observe.d.ts
CHANGED
|
@@ -34,6 +34,8 @@ export type Observers = {
|
|
|
34
34
|
observe<R = unknown>(medium: string, kind: string, item: unknown, options?: ObserveOptions): Observation<R>;
|
|
35
35
|
/** What a commit changed, by collection: the parts that read it run again. */
|
|
36
36
|
changed(seen: [string, Change[]][]): void;
|
|
37
|
+
/** Anything may have changed (maintenance SQL): every part that read something runs again. */
|
|
38
|
+
stale(): void;
|
|
37
39
|
/** Resolves when no part is running: every observed View shows the latest data. */
|
|
38
40
|
idle(): Promise<void>;
|
|
39
41
|
};
|
package/runtime/observe.js
CHANGED
|
@@ -73,6 +73,18 @@ export function createObservers(env) {
|
|
|
73
73
|
settled.resolve();
|
|
74
74
|
});
|
|
75
75
|
};
|
|
76
|
+
/** Runs these parts again; several tell their new output together, once the last has it. */
|
|
77
|
+
const again = (due) => {
|
|
78
|
+
if (due.size > 1) {
|
|
79
|
+
const wave = { waiting: new Map(), done: new Set() };
|
|
80
|
+
for (const p of due) {
|
|
81
|
+
wave.waiting.set(p, p.generation);
|
|
82
|
+
(p.waves ??= new Set()).add(wave);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
for (const p of due)
|
|
86
|
+
start(p);
|
|
87
|
+
};
|
|
76
88
|
const part = (medium, kind, item, hints, viewer, place, actor) => {
|
|
77
89
|
const p = {
|
|
78
90
|
medium,
|
|
@@ -353,17 +365,9 @@ export function createObservers(env) {
|
|
|
353
365
|
}
|
|
354
366
|
}
|
|
355
367
|
}
|
|
356
|
-
|
|
357
|
-
if (due.size > 1) {
|
|
358
|
-
const wave = { waiting: new Map(), done: new Set() };
|
|
359
|
-
for (const p of due) {
|
|
360
|
-
wave.waiting.set(p, p.generation);
|
|
361
|
-
(p.waves ??= new Set()).add(wave);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
for (const p of due)
|
|
365
|
-
start(p);
|
|
368
|
+
again(due);
|
|
366
369
|
},
|
|
370
|
+
stale: () => again(new Set([...readers.values()].flatMap((parts) => [...parts]))),
|
|
367
371
|
idle: () => settled.promise,
|
|
368
372
|
};
|
|
369
373
|
}
|
package/runtime/ops.d.ts
CHANGED
|
@@ -139,6 +139,11 @@ export type Outcome = {
|
|
|
139
139
|
action?: string;
|
|
140
140
|
inputHash?: string;
|
|
141
141
|
};
|
|
142
|
+
/**
|
|
143
|
+
* Results whose private fields the log leaves out (see `ActionDef.private`),
|
|
144
|
+
* whole, by call id: what a retry of the call answers with.
|
|
145
|
+
*/
|
|
146
|
+
export declare const RESULTS = "sys.results";
|
|
142
147
|
export declare function outcome(reader: Reader, call: string): Promise<Outcome>;
|
|
143
148
|
/** What the owner does around each write. */
|
|
144
149
|
export type Hooks = {
|
package/runtime/ops.js
CHANGED
|
@@ -33,6 +33,11 @@ export function read(reader, op) {
|
|
|
33
33
|
return outcome(reader, op.call);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Results whose private fields the log leaves out (see `ActionDef.private`),
|
|
38
|
+
* whole, by call id: what a retry of the call answers with.
|
|
39
|
+
*/
|
|
40
|
+
export const RESULTS = "sys.results";
|
|
36
41
|
export async function outcome(reader, call) {
|
|
37
42
|
const events = await reader.related(call, [
|
|
38
43
|
"action.started",
|
|
@@ -44,9 +49,13 @@ export async function outcome(reader, call) {
|
|
|
44
49
|
const done = events.find((e) => e.type === "action.completed");
|
|
45
50
|
const started = events.find((e) => e.id === call);
|
|
46
51
|
const attempts = started ? 1 + count("action.retried") : 0;
|
|
52
|
+
// One with private fields is kept whole apart; erased there, the log's is what's left.
|
|
53
|
+
const result = done?.data.private
|
|
54
|
+
? (await reader.findOne(RESULTS, { _id: call }))?.result ?? done.data.result
|
|
55
|
+
: done?.data.result;
|
|
47
56
|
return {
|
|
48
57
|
completed: Boolean(done),
|
|
49
|
-
...(done ? { result
|
|
58
|
+
...(done ? { result } : {}),
|
|
50
59
|
attempts,
|
|
51
60
|
lost: attempts > count("action.failed") + (done ? 1 : 0),
|
|
52
61
|
...(started
|
package/runtime/owner.d.ts
CHANGED
|
@@ -3,12 +3,16 @@ import { type Clock } from "./schedules.js";
|
|
|
3
3
|
import { type Hypervisor, type HypervisorOptions } from "oxianjs";
|
|
4
4
|
import type { Plugins, RenderOptions, Resources, WorkerJob } from "./define.js";
|
|
5
5
|
import { type Blobs } from "./blobs.js";
|
|
6
|
+
import { type Maintenance } from "./maintain.js";
|
|
6
7
|
import { type Observation, type ObserveOptions } from "./observe.js";
|
|
7
8
|
import type { Actor, Event, Store } from "./store.js";
|
|
8
9
|
export type Transport = HypervisorOptions["transports"][number];
|
|
9
10
|
export type Feed = {
|
|
10
11
|
kind: "event";
|
|
12
|
+
/** As the log holds it: a large value is a blob reference. */
|
|
11
13
|
event: Event;
|
|
14
|
+
/** The event with its large values in place of their references, read when asked. */
|
|
15
|
+
full(): Promise<Event>;
|
|
12
16
|
} | {
|
|
13
17
|
kind: "frame";
|
|
14
18
|
channel: string;
|
|
@@ -102,6 +106,11 @@ export type Owner = {
|
|
|
102
106
|
*/
|
|
103
107
|
wake(): Promise<void>;
|
|
104
108
|
stats(): Stats;
|
|
109
|
+
/**
|
|
110
|
+
* SQL beside the collections, for trusted host code only (the maintenance
|
|
111
|
+
* plugin's routes): plugin code never gets it. See runtime/maintain.ts.
|
|
112
|
+
*/
|
|
113
|
+
maintenance: Maintenance;
|
|
105
114
|
/** The Oxian Hypervisor executors connect to; serve it to accept remote executors. */
|
|
106
115
|
hypervisor: Hypervisor;
|
|
107
116
|
/**
|
|
@@ -116,7 +125,15 @@ export type Owner = {
|
|
|
116
125
|
signal?: AbortSignal;
|
|
117
126
|
}): Promise<WorkerJob>;
|
|
118
127
|
};
|
|
119
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Stops. No Processor delivery or timer occurrence starts; those running
|
|
130
|
+
* get `drain` ms (5 s by default) to finish, then stop where they are. A
|
|
131
|
+
* delivery that didn't finish keeps its Processor's cursor before its
|
|
132
|
+
* event, so the next owner delivers it again (`retry`).
|
|
133
|
+
*/
|
|
134
|
+
close(options?: {
|
|
135
|
+
drain?: number;
|
|
136
|
+
}): Promise<void>;
|
|
120
137
|
};
|
|
121
138
|
export declare function createOwner(options: {
|
|
122
139
|
store: Store;
|
package/runtime/owner.js
CHANGED
|
@@ -4,20 +4,22 @@
|
|
|
4
4
|
* Processors. Plugin code runs in executors, which reach the store only by
|
|
5
5
|
* sending ops to the owner over Oxian.
|
|
6
6
|
*/
|
|
7
|
+
import { workerPresence } from "./presence.js";
|
|
7
8
|
import { plan } from "./aggregate.js";
|
|
8
9
|
import { noMetrics } from "./metrics.js";
|
|
9
10
|
import { systemClock, TIMERS } from "./schedules.js";
|
|
10
11
|
import { createTimers } from "./timers.js";
|
|
11
12
|
import { createHypervisor } from "oxianjs";
|
|
12
|
-
import { hydrate, offload } from "./blobs.js";
|
|
13
|
+
import { hydrate, offload, refuseBlobKeys } from "./blobs.js";
|
|
13
14
|
import { createCache } from "./cache.js";
|
|
15
|
+
import { createMaintenance } from "./maintain.js";
|
|
14
16
|
import { createObservers } from "./observe.js";
|
|
15
17
|
import { reading, startup } from "./reads.js";
|
|
16
18
|
import { BROWSER, createBrowsers, READ_VIEW, readView, SESSION, WIRE } from "./browsers.js";
|
|
17
19
|
import { memoryStore } from "./memory.js";
|
|
18
20
|
import { isRead, perform, read, } from "./ops.js";
|
|
19
|
-
import { check, matches } from "./mongo.js";
|
|
20
|
-
import { canonical, checked, compile, events, fingerprint, invalid, json, merge, } from "./registry.js";
|
|
21
|
+
import { check, checkPath, matches } from "./mongo.js";
|
|
22
|
+
import { canonical, checked, compile, events, fingerprint, invalid, json, merge, unprivate, } from "./registry.js";
|
|
21
23
|
import { decode, DISPATCH, encode, failure, lines, OP, raise, RUN, } from "./wire.js";
|
|
22
24
|
const SYSTEM = "sys.";
|
|
23
25
|
/** A held transaction with no op for this long is rolled back. */
|
|
@@ -31,6 +33,8 @@ const DAY = 86_400_000;
|
|
|
31
33
|
* it should be).
|
|
32
34
|
*/
|
|
33
35
|
const DELIVERY_ATTEMPTS = 3;
|
|
36
|
+
/** How long a closing owner waits for running deliveries to finish, by default (ms). */
|
|
37
|
+
const DRAIN_MS = 5_000;
|
|
34
38
|
const aborted = Object.freeze({ aborted: true });
|
|
35
39
|
const forbidden = (message) => Object.assign(new Error(message), { code: "forbidden" });
|
|
36
40
|
/** Strings compared in time that doesn't depend on where they differ (keys). */
|
|
@@ -92,6 +96,21 @@ export async function createOwner(options) {
|
|
|
92
96
|
const memory = fleeting.size ? memoryStore() : undefined;
|
|
93
97
|
const inMemory = (op) => "collection" in op && fleeting.has(op.collection);
|
|
94
98
|
const known = (op) => {
|
|
99
|
+
// What plugin code writes holds no `$blob` key (see blobs.ts). Offloading looks as it walks
|
|
100
|
+
// what's stored; an upsert's filter (it seeds the new document) and in-memory writes (never
|
|
101
|
+
// offloaded) are looked at here. So are an update's field paths: `{ $set: { "a.$blob": … } }`
|
|
102
|
+
// would make one, as would a path through `__proto__` reach every object's prototype.
|
|
103
|
+
if ((op.op === "update" || op.op === "replace") && op.options?.upsert) {
|
|
104
|
+
refuseBlobKeys(op.filter);
|
|
105
|
+
}
|
|
106
|
+
if (op.op === "update" && Object.keys(op.update).some((key) => key.startsWith("$"))) {
|
|
107
|
+
for (const fields of Object.values(op.update)) {
|
|
108
|
+
for (const path of Object.keys(fields ?? {}))
|
|
109
|
+
checkPath(path);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (inMemory(op) && !isRead(op))
|
|
113
|
+
refuseBlobKeys(op);
|
|
95
114
|
if (!("collection" in op) || op.collection.startsWith(SYSTEM))
|
|
96
115
|
return;
|
|
97
116
|
if (!validators[op.collection])
|
|
@@ -126,6 +145,8 @@ export async function createOwner(options) {
|
|
|
126
145
|
validators[collection](doc);
|
|
127
146
|
};
|
|
128
147
|
const closing = new AbortController();
|
|
148
|
+
// Closing begins: nothing new starts (deliveries, timer occurrences), and what runs may finish.
|
|
149
|
+
const draining = new AbortController();
|
|
129
150
|
// Time calls Actions: one clock, for the earliest timer (see timers.ts).
|
|
130
151
|
const timers = createTimers({
|
|
131
152
|
store,
|
|
@@ -133,9 +154,10 @@ export async function createOwner(options) {
|
|
|
133
154
|
schedules: registry.schedules,
|
|
134
155
|
actions: registry.actions,
|
|
135
156
|
write: (ops) => writeEach(ops),
|
|
136
|
-
|
|
157
|
+
// A timer keeps its input as stored, large values as blob references: the Action gets it whole.
|
|
158
|
+
call: async (action, input, id, scheduled, actor) => await begin(action, await hydrate(input, blobsOf(store)), id, true, scheduled, actor),
|
|
137
159
|
track: (work) => track(work),
|
|
138
|
-
signal:
|
|
160
|
+
signal: draining.signal,
|
|
139
161
|
metrics,
|
|
140
162
|
});
|
|
141
163
|
// Indexed fields must be scalars their schema types, so stores may compare them as such.
|
|
@@ -217,7 +239,7 @@ export async function createOwner(options) {
|
|
|
217
239
|
unsaved.delete(name);
|
|
218
240
|
for (const event of events) {
|
|
219
241
|
measure.events.add(1, { type: event.type });
|
|
220
|
-
publish({ kind: "event", event });
|
|
242
|
+
publish({ kind: "event", event, full: () => whole(event) });
|
|
221
243
|
route(event, true);
|
|
222
244
|
}
|
|
223
245
|
if (seen.length)
|
|
@@ -270,7 +292,7 @@ export async function createOwner(options) {
|
|
|
270
292
|
}
|
|
271
293
|
const blobs = [];
|
|
272
294
|
const put = (blob) => (blobs.push(blob), Promise.resolve());
|
|
273
|
-
const large = (value) => offload(value, put, options.blobThreshold);
|
|
295
|
+
const large = (value) => offload(value, put, options.blobThreshold, by.foreign);
|
|
274
296
|
// The same values perform() offloads: documents, updates, edge data, event data.
|
|
275
297
|
const steps = await Promise.all(ops.map(async (op) => {
|
|
276
298
|
switch (op.op) {
|
|
@@ -279,19 +301,16 @@ export async function createOwner(options) {
|
|
|
279
301
|
emit: { ...op.event, ...(actor ? { actor } : {}), data: await large(op.event.data) },
|
|
280
302
|
};
|
|
281
303
|
case "insert":
|
|
282
|
-
return {
|
|
283
|
-
write: { ...op, docs: await large(op.docs) },
|
|
284
|
-
record: recorded(op.collection),
|
|
285
|
-
};
|
|
304
|
+
return { write: { ...op, docs: await large(op.docs) }, ...recording(op.collection) };
|
|
286
305
|
case "update":
|
|
287
306
|
return {
|
|
288
307
|
write: { ...op, update: await large(op.update) },
|
|
289
|
-
|
|
308
|
+
...recording(op.collection),
|
|
290
309
|
};
|
|
291
310
|
case "replace":
|
|
292
|
-
return { write: { ...op, doc: await large(op.doc) },
|
|
311
|
+
return { write: { ...op, doc: await large(op.doc) }, ...recording(op.collection) };
|
|
293
312
|
case "delete":
|
|
294
|
-
return { write: op,
|
|
313
|
+
return { write: op, ...recording(op.collection) };
|
|
295
314
|
case "link":
|
|
296
315
|
return { write: { ...op, edge: await large(op.edge) }, record: false };
|
|
297
316
|
default:
|
|
@@ -325,6 +344,11 @@ export async function createOwner(options) {
|
|
|
325
344
|
};
|
|
326
345
|
// Large values: in the configured blob store, or in the store's own blobs.
|
|
327
346
|
const blobsOf = (reader) => (id) => options.blobs ? options.blobs.get(id) : reader.blob(id);
|
|
347
|
+
/** A committed event with its large values in place. */
|
|
348
|
+
const whole = async (event) => ({
|
|
349
|
+
...event,
|
|
350
|
+
data: await hydrate(event.data, blobsOf(store)),
|
|
351
|
+
});
|
|
328
352
|
// Reads of committed state go through the cache; reads in a transaction see its own writes.
|
|
329
353
|
const cache = options.cache === false ? undefined : createCache({
|
|
330
354
|
...options.cache,
|
|
@@ -361,7 +385,7 @@ export async function createOwner(options) {
|
|
|
361
385
|
await write([{
|
|
362
386
|
op: "emit",
|
|
363
387
|
event: { type, data: json(data), ...(options.id ? { id: options.id } : {}) },
|
|
364
|
-
}], options.actor ? { actor: options.actor } : {});
|
|
388
|
+
}], { ...(options.actor ? { actor: options.actor } : {}), foreign: true });
|
|
365
389
|
};
|
|
366
390
|
const observers = createObservers({
|
|
367
391
|
views: registry.views,
|
|
@@ -385,7 +409,7 @@ export async function createOwner(options) {
|
|
|
385
409
|
const _id = typeof doc._id === "string" ? doc._id : crypto.randomUUID();
|
|
386
410
|
const op = { op: "insert", collection, docs: [{ ...doc, _id }] };
|
|
387
411
|
known(op);
|
|
388
|
-
void writeEach([op]).catch(() => { });
|
|
412
|
+
void writeEach([op], { foreign: true }).catch(() => { });
|
|
389
413
|
return _id;
|
|
390
414
|
}, metrics, actor);
|
|
391
415
|
},
|
|
@@ -395,14 +419,20 @@ export async function createOwner(options) {
|
|
|
395
419
|
// Every change to a declared collection is an event, committed with it; records are their own.
|
|
396
420
|
const recorded = (collection) => !collection.startsWith(SYSTEM) && registry.collections[collection]?.events !== false &&
|
|
397
421
|
!registry.collections[collection]?.records && !fleeting.has(collection);
|
|
422
|
+
// The log keeps no private field: a token or key never lands in an event.
|
|
423
|
+
const unlogged = (collection) => registry.collections[collection]?.private ?? [];
|
|
424
|
+
/** How a store's command records a write: whether it does, and without which fields. */
|
|
425
|
+
const recording = (collection) => {
|
|
426
|
+
const hidden = unlogged(collection);
|
|
427
|
+
return { record: recorded(collection), ...(hidden.length ? { private: hidden } : {}) };
|
|
428
|
+
};
|
|
398
429
|
const lifecycle = (tx, collection, changes, by) => {
|
|
399
430
|
if (!recorded(collection))
|
|
400
431
|
return;
|
|
401
432
|
const { cause } = by;
|
|
402
433
|
const actor = by.actor ? { actor: by.actor } : {};
|
|
403
|
-
|
|
404
|
-
const
|
|
405
|
-
const open = (doc) => kept.length ? unprivate(doc, kept) : doc;
|
|
434
|
+
const hidden = unlogged(collection);
|
|
435
|
+
const open = (doc) => unprivate(doc, hidden);
|
|
406
436
|
for (const { _id, before, after } of changes) {
|
|
407
437
|
if (!before) {
|
|
408
438
|
tx.emit({
|
|
@@ -437,7 +467,7 @@ export async function createOwner(options) {
|
|
|
437
467
|
const performEach = async (tx, ops, by, seen, later) => {
|
|
438
468
|
const hooks = {
|
|
439
469
|
validate,
|
|
440
|
-
offload: (value) => offload(value, (blob) => options.blobs ? options.blobs.put(blob) : tx.putBlob(blob), options.blobThreshold),
|
|
470
|
+
offload: (value) => offload(value, (blob) => options.blobs ? options.blobs.put(blob) : tx.putBlob(blob), options.blobThreshold, by.foreign),
|
|
441
471
|
changed: (collection, changes) => {
|
|
442
472
|
// What an actor's write leaves must stay within what they reach.
|
|
443
473
|
const keep = by.keep?.get(collection);
|
|
@@ -638,6 +668,7 @@ export async function createOwner(options) {
|
|
|
638
668
|
...(request.actor ? { actor: request.actor } : {}),
|
|
639
669
|
...(request.keep?.size ? { keep: request.keep } : {}),
|
|
640
670
|
...(request.saw ? { saw: request.saw } : {}),
|
|
671
|
+
foreign: true,
|
|
641
672
|
}, seen, later);
|
|
642
673
|
}
|
|
643
674
|
catch (error) {
|
|
@@ -711,6 +742,7 @@ export async function createOwner(options) {
|
|
|
711
742
|
...(request.actor ? { actor: request.actor } : {}),
|
|
712
743
|
...(keep.size ? { keep } : {}),
|
|
713
744
|
saw,
|
|
745
|
+
foreign: true,
|
|
714
746
|
});
|
|
715
747
|
}
|
|
716
748
|
let transaction = held.get(request.tx);
|
|
@@ -724,9 +756,8 @@ export async function createOwner(options) {
|
|
|
724
756
|
return transaction.send({ ...request, ops, keep, saw });
|
|
725
757
|
};
|
|
726
758
|
// Workers of plugins' kinds (computers…): admitted by their kind's Action, then found by id.
|
|
727
|
-
const connected =
|
|
759
|
+
const connected = workerPresence();
|
|
728
760
|
const resumed = new Map();
|
|
729
|
-
const workerKey = (kind, id) => `${kind}\u0000${id}`;
|
|
730
761
|
/** Who a worker of a plugin's kind is, from `<kind>:<secret>`; undefined: not one. */
|
|
731
762
|
const workerOf = async (credential) => {
|
|
732
763
|
const capability = String(credential.capability);
|
|
@@ -903,7 +934,9 @@ export async function createOwner(options) {
|
|
|
903
934
|
}
|
|
904
935
|
if (definition.providerId.startsWith("worker:")) {
|
|
905
936
|
const { kind, id } = definition.providerConfig;
|
|
906
|
-
|
|
937
|
+
// Moved to a fresh connection (Oxian's handoff), it never left: nothing to tell.
|
|
938
|
+
if (!connected.arrived(kind, id, fence.identity.workerId, fence.connectionId))
|
|
939
|
+
return;
|
|
907
940
|
return tell(registry.workers[kind]?.ready, id);
|
|
908
941
|
}
|
|
909
942
|
ready.add(fence.connectionId);
|
|
@@ -913,10 +946,9 @@ export async function createOwner(options) {
|
|
|
913
946
|
browsers.gone(fence.identity.workerId, fence.connectionId);
|
|
914
947
|
if (definition.providerId.startsWith("worker:")) {
|
|
915
948
|
const { kind, id } = definition.providerConfig;
|
|
916
|
-
//
|
|
917
|
-
if (connected.
|
|
949
|
+
// Gone only if this was the connection it's on: back, or moved, on another, it's there.
|
|
950
|
+
if (!connected.left(kind, id, fence.identity.workerId, fence.connectionId))
|
|
918
951
|
return;
|
|
919
|
-
connected.delete(workerKey(kind, id));
|
|
920
952
|
return tell(registry.workers[kind]?.gone, id);
|
|
921
953
|
}
|
|
922
954
|
ready.delete(fence.connectionId);
|
|
@@ -953,7 +985,7 @@ export async function createOwner(options) {
|
|
|
953
985
|
if (!def || !def.workloads.includes(workload)) {
|
|
954
986
|
return refused(`No ${kind} work "${workload}"`, "invalid");
|
|
955
987
|
}
|
|
956
|
-
const workerId = connected.
|
|
988
|
+
const workerId = connected.workerOf(kind, String(id));
|
|
957
989
|
if (!workerId)
|
|
958
990
|
return refused(`${kind} ${id} isn't connected`, "offline");
|
|
959
991
|
const handle = await hypervisor.dispatch({
|
|
@@ -1111,10 +1143,13 @@ export async function createOwner(options) {
|
|
|
1111
1143
|
emit({
|
|
1112
1144
|
id,
|
|
1113
1145
|
type: "action.started",
|
|
1114
|
-
// An unrecorded Action's input stays out of the log, whatever became of it
|
|
1146
|
+
// An unrecorded Action's input stays out of the log, whatever became of it,
|
|
1147
|
+
// and so do an Action's private fields.
|
|
1115
1148
|
data: {
|
|
1116
1149
|
action,
|
|
1117
|
-
input: registry.actions[action]?.record === false
|
|
1150
|
+
input: registry.actions[action]?.record === false
|
|
1151
|
+
? null
|
|
1152
|
+
: unprivate(input ?? null, registry.actions[action]?.private ?? []),
|
|
1118
1153
|
inputHash,
|
|
1119
1154
|
startedAt,
|
|
1120
1155
|
attempt,
|
|
@@ -1181,11 +1216,12 @@ export async function createOwner(options) {
|
|
|
1181
1216
|
stop?.abort();
|
|
1182
1217
|
return !!stop;
|
|
1183
1218
|
};
|
|
1219
|
+
/** Delivers an event to a Processor: false when closing cut it short (it isn't done). */
|
|
1184
1220
|
const deliver = async (name, event, recovered, lane) => {
|
|
1185
1221
|
const stop = new AbortController();
|
|
1186
1222
|
active.set(lane, stop);
|
|
1187
1223
|
try {
|
|
1188
|
-
await attempts(name, event, recovered, stop.signal);
|
|
1224
|
+
return await attempts(name, event, recovered, stop.signal);
|
|
1189
1225
|
}
|
|
1190
1226
|
finally {
|
|
1191
1227
|
if (active.get(lane) === stop)
|
|
@@ -1195,18 +1231,19 @@ export async function createOwner(options) {
|
|
|
1195
1231
|
const attempts = async (name, event, recovered, stop) => {
|
|
1196
1232
|
for (let attempt = 1;; attempt++) {
|
|
1197
1233
|
try {
|
|
1198
|
-
const full =
|
|
1234
|
+
const full = await whole(event);
|
|
1199
1235
|
await run({
|
|
1200
1236
|
kind: "process",
|
|
1201
1237
|
processor: name,
|
|
1202
1238
|
event: full,
|
|
1203
1239
|
retry: recovered || attempt > 1,
|
|
1204
1240
|
}, stop);
|
|
1205
|
-
return;
|
|
1241
|
+
return true;
|
|
1206
1242
|
}
|
|
1207
1243
|
catch (error) {
|
|
1244
|
+
// Cut short by closing: not done, and not failed either.
|
|
1208
1245
|
if (closing.signal.aborted)
|
|
1209
|
-
return;
|
|
1246
|
+
return false;
|
|
1210
1247
|
// Every failed attempt is on record: the retry that follows, or the final failure.
|
|
1211
1248
|
const after = error.code === "executor_lost" ? "lost" : "failed";
|
|
1212
1249
|
// A stopped delivery is over, and so is one whose failure says trying again won't help.
|
|
@@ -1235,13 +1272,13 @@ export async function createOwner(options) {
|
|
|
1235
1272
|
cause: event.id,
|
|
1236
1273
|
})), false).catch(() => { });
|
|
1237
1274
|
if (last)
|
|
1238
|
-
return;
|
|
1275
|
+
return true;
|
|
1239
1276
|
await new Promise((resolve) => {
|
|
1240
1277
|
const timer = setTimeout(resolve, 200 * attempt);
|
|
1241
|
-
stop.addEventListener("abort", () => (clearTimeout(timer), resolve(undefined)), {
|
|
1242
|
-
once: true,
|
|
1243
|
-
});
|
|
1278
|
+
AbortSignal.any([stop, closing.signal]).addEventListener("abort", () => (clearTimeout(timer), resolve(undefined)), { once: true });
|
|
1244
1279
|
});
|
|
1280
|
+
if (closing.signal.aborted)
|
|
1281
|
+
return false;
|
|
1245
1282
|
}
|
|
1246
1283
|
}
|
|
1247
1284
|
};
|
|
@@ -1275,7 +1312,9 @@ export async function createOwner(options) {
|
|
|
1275
1312
|
inflight.get(name).add(event.seq);
|
|
1276
1313
|
seen.set(name, Math.max(seen.get(name) ?? 0, event.seq));
|
|
1277
1314
|
const tail = track(lane.tail.then(async () => {
|
|
1278
|
-
|
|
1315
|
+
// One not delivered stays in flight: its Processor's cursor never moves past it.
|
|
1316
|
+
if (draining.signal.aborted || !await deliver(name, event, retry, key))
|
|
1317
|
+
return;
|
|
1279
1318
|
inflight.get(name).delete(event.seq);
|
|
1280
1319
|
advance(name);
|
|
1281
1320
|
})).finally(() => {
|
|
@@ -1303,13 +1342,26 @@ export async function createOwner(options) {
|
|
|
1303
1342
|
}
|
|
1304
1343
|
await timers.recover();
|
|
1305
1344
|
const api = {
|
|
1345
|
+
maintenance: createMaintenance({
|
|
1346
|
+
store,
|
|
1347
|
+
epoch,
|
|
1348
|
+
blobs: options.blobs,
|
|
1349
|
+
blobThreshold: options.blobThreshold,
|
|
1350
|
+
// SQL changed what nothing follows: forget what came from documents, then tell.
|
|
1351
|
+
wrote: (events) => {
|
|
1352
|
+
cache?.clear();
|
|
1353
|
+
committed([], events);
|
|
1354
|
+
observers.stale();
|
|
1355
|
+
void timers.wake();
|
|
1356
|
+
},
|
|
1357
|
+
}),
|
|
1306
1358
|
workers: {
|
|
1307
1359
|
async dispatch(kind, id, workload, body, options = {}) {
|
|
1308
1360
|
const def = registry.workers[kind];
|
|
1309
1361
|
if (!def || !def.workloads.includes(workload)) {
|
|
1310
1362
|
throw invalid(`No ${kind} work "${workload}"`);
|
|
1311
1363
|
}
|
|
1312
|
-
const workerId = connected.
|
|
1364
|
+
const workerId = connected.workerOf(kind, String(id));
|
|
1313
1365
|
if (!workerId) {
|
|
1314
1366
|
throw Object.assign(new Error(`${kind} ${id} isn't connected`), { code: "offline" });
|
|
1315
1367
|
}
|
|
@@ -1339,8 +1391,16 @@ export async function createOwner(options) {
|
|
|
1339
1391
|
if (actor && actor.kind !== "system" && !def.allow?.(actor, input)) {
|
|
1340
1392
|
return Promise.reject(forbidden(`${actor.kind} ${actor.id} may not call "${action}".`));
|
|
1341
1393
|
}
|
|
1394
|
+
const given = json(input);
|
|
1395
|
+
// What an Action is given goes on record as it is: it may hold no `$blob` key.
|
|
1396
|
+
try {
|
|
1397
|
+
refuseBlobKeys(given);
|
|
1398
|
+
}
|
|
1399
|
+
catch (error) {
|
|
1400
|
+
return Promise.reject(error);
|
|
1401
|
+
}
|
|
1342
1402
|
const id = options.id ?? crypto.randomUUID();
|
|
1343
|
-
return begin(action,
|
|
1403
|
+
return begin(action, given, id, options.id !== undefined, undefined, actor);
|
|
1344
1404
|
},
|
|
1345
1405
|
async render(medium, kind, item, options = {}) {
|
|
1346
1406
|
return await run({
|
|
@@ -1406,42 +1466,48 @@ export async function createOwner(options) {
|
|
|
1406
1466
|
misses: cache?.stats().misses ?? 0,
|
|
1407
1467
|
}),
|
|
1408
1468
|
hypervisor,
|
|
1409
|
-
async close() {
|
|
1469
|
+
async close(options = {}) {
|
|
1470
|
+
// What's running (deliveries, timer occurrences) gets a while to finish,
|
|
1471
|
+
// workers still there to serve it; nothing new starts.
|
|
1472
|
+
draining.abort();
|
|
1473
|
+
timers.close();
|
|
1474
|
+
const drain = options.drain ?? DRAIN_MS;
|
|
1475
|
+
if (drain > 0 && pending) {
|
|
1476
|
+
let timer;
|
|
1477
|
+
await Promise.race([
|
|
1478
|
+
(async () => {
|
|
1479
|
+
while (pending)
|
|
1480
|
+
await drained.promise;
|
|
1481
|
+
})(),
|
|
1482
|
+
new Promise((resolve) => timer = setTimeout(resolve, drain)),
|
|
1483
|
+
]);
|
|
1484
|
+
clearTimeout(timer);
|
|
1485
|
+
}
|
|
1410
1486
|
// Workers still connected go with it: their kinds hear so while it still runs.
|
|
1411
|
-
for (const
|
|
1412
|
-
const [kind, id] = key.split("\u0000");
|
|
1487
|
+
for (const [kind, id] of connected.all())
|
|
1413
1488
|
tell(registry.workers[kind]?.gone, id);
|
|
1414
|
-
}
|
|
1415
1489
|
connected.clear();
|
|
1416
1490
|
await Promise.all(telling);
|
|
1417
1491
|
closing.abort();
|
|
1418
|
-
timers.close();
|
|
1419
1492
|
clearTimeout(flushing);
|
|
1420
1493
|
// A browser's session is a stream that never ends on its own: end them, so the
|
|
1421
1494
|
// shutdown's drain doesn't wait them out.
|
|
1422
1495
|
browsers.closeAll();
|
|
1423
1496
|
await hypervisor.shutdown();
|
|
1424
|
-
if (
|
|
1425
|
-
|
|
1426
|
-
|
|
1497
|
+
// Processors' last positions are saved if they can be (a fenced owner can't): the store
|
|
1498
|
+
// closes either way, and a failure still reaches the caller.
|
|
1499
|
+
try {
|
|
1500
|
+
if (unsaved.size)
|
|
1501
|
+
await commit(async () => { });
|
|
1502
|
+
}
|
|
1503
|
+
finally {
|
|
1504
|
+
await store.close();
|
|
1505
|
+
}
|
|
1427
1506
|
},
|
|
1428
1507
|
};
|
|
1429
1508
|
return api;
|
|
1430
1509
|
}
|
|
1431
1510
|
/** The scalar type a schema gives a dot path (through properties and additionalProperties), if one. */
|
|
1432
|
-
/** A copy of `doc` without the private fields at these (dotted) paths. */
|
|
1433
|
-
function unprivate(doc, fields) {
|
|
1434
|
-
const copy = structuredClone(doc);
|
|
1435
|
-
for (const path of fields) {
|
|
1436
|
-
const keys = path.split(".");
|
|
1437
|
-
let at = copy;
|
|
1438
|
-
for (const key of keys.slice(0, -1))
|
|
1439
|
-
at = at?.[key];
|
|
1440
|
-
if (at && typeof at === "object")
|
|
1441
|
-
delete at[keys.at(-1)];
|
|
1442
|
-
}
|
|
1443
|
-
return copy;
|
|
1444
|
-
}
|
|
1445
1511
|
function scalarOf(schema, path) {
|
|
1446
1512
|
let node = schema;
|
|
1447
1513
|
for (const key of path.split(".")) {
|