@arbol-ai/maximus 8.0.1 → 8.1.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/dist/analytics/analytics.d.ts +1 -1
- package/dist/analytics/analytics.js +2 -2
- package/dist/body.d.ts +1 -1
- package/dist/capture/index.d.ts +37 -0
- package/dist/capture/index.js +182 -0
- package/dist/chunks/{define-app-x7uY70_1.js → define-app-BxGZdNmS.js} +14 -3
- package/dist/chunks/delay-BsKQP_lF.js +12 -0
- package/dist/chunks/digest-C7UGt760.js +13 -0
- package/dist/chunks/{errors-C5w9WY1l.js → errors-CWgE9uvM.js} +1 -1
- package/dist/chunks/execution-BTiAWA4n.js +264 -0
- package/dist/chunks/{http-layout-DS8DnPyu.js → http-layout-BvlbD__1.js} +1 -1
- package/dist/chunks/{openapi-CeolxIqa.js → openapi-BF3eCpux.js} +11 -20
- package/dist/chunks/{openapi-file-Bz9FRaE6.js → openapi-file-RcXoq0AF.js} +1 -1
- package/dist/chunks/{pages-iZTvFs5a.js → pages-BCksUeRf.js} +1 -1
- package/dist/chunks/{runtime-D94vx21X.js → runtime-D5eR9-Es.js} +38 -9
- package/dist/chunks/{schemas-p_aRcMC1.js → schemas-BOFxZP1c.js} +1 -1
- package/dist/chunks/{server-Bzf1Q1_4.js → server-B9C8KPwa.js} +5 -4
- package/dist/chunks/{src-CPrJpbOM.js → src-C-4z443M.js} +61 -15
- package/dist/chunks/{telemetry-C3LfZcOB.js → telemetry-BtxJh69Q.js} +4 -4
- package/dist/chunks/{types-DTIuIEJ-.d.ts → types-Dqo3oGig.d.ts} +236 -31
- package/dist/chunks/{validation-fTohBT6R.js → validation-DMu0rkMQ.js} +266 -16
- package/dist/chunks/{workers-types-BRk_Xa_5.d.ts → workers-types-BgjyDtGd.d.ts} +1 -1
- package/dist/diagnostics.d.ts +1 -1
- package/dist/diagnostics.js +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -1
- package/dist/http-paths.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -6
- package/dist/internals.d.ts +2 -2
- package/dist/internals.js +5 -5
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/project/config.d.ts +1 -1
- package/dist/project/index.d.ts +2 -2
- package/dist/project/index.js +3 -3
- package/dist/schemas.d.ts +2 -2
- package/dist/schemas.js +3 -3
- package/dist/standard-failures.d.ts +1 -1
- package/dist/tooling/cli.js +1 -1
- package/dist/vite/index.d.ts +2 -2
- package/dist/vite/index.js +12 -7
- package/dist/webhooks.d.ts +1 -1
- package/dist/workers/runtime.d.ts +1 -1
- package/dist/workers/runtime.js +1 -1
- package/package.json +5 -1
- package/skills/maximus/SKILL.md +7 -0
- package/skills/maximus/references/project.md +4 -0
- package/skills/maximus/references/routes-and-tools.md +2 -0
- package/templates/project/CLAUDE.md.template +3 -3
- package/templates/project/README.md.template +1 -0
- package/templates/project/tsconfig.json.template +1 -0
- package/dist/chunks/execution-rOiLo8VG.js +0 -84
package/dist/vite/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as checkMcpResourceNames } from "../chunks/define-app-
|
|
1
|
+
import { t as checkMcpResourceNames } from "../chunks/define-app-BxGZdNmS.js";
|
|
2
2
|
import { a as operationPathParameters } from "../chunks/http-paths-DMBxwpp6.js";
|
|
3
|
-
import { a as ownsPrefix, t as VERSIONED_PATH } from "../chunks/http-layout-
|
|
4
|
-
import { t as checkPagePaths } from "../chunks/pages-
|
|
3
|
+
import { a as ownsPrefix, t as VERSIONED_PATH } from "../chunks/http-layout-BvlbD__1.js";
|
|
4
|
+
import { t as checkPagePaths } from "../chunks/pages-BCksUeRf.js";
|
|
5
5
|
import { t as routeName } from "../chunks/names-ncD7A3DV.js";
|
|
6
6
|
import { a as projectPath, i as projectFiles, o as publicFiles, r as compareNames, s as routeShape, t as PROJECT_DIRECTORIES } from "../chunks/project-files-C0OX7MQQ.js";
|
|
7
7
|
import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
@@ -1078,11 +1078,13 @@ function prepareProject(directory, mode, project) {
|
|
|
1078
1078
|
const auth = rootModule(root, "auth");
|
|
1079
1079
|
const context = rootModule(root, "context");
|
|
1080
1080
|
const telemetry = rootModule(root, "telemetry");
|
|
1081
|
+
const capture = rootModule(root, "capture");
|
|
1081
1082
|
for (const module of [
|
|
1082
1083
|
catalog,
|
|
1083
1084
|
auth,
|
|
1084
1085
|
context,
|
|
1085
|
-
telemetry
|
|
1086
|
+
telemetry,
|
|
1087
|
+
capture
|
|
1086
1088
|
]) if (module) readProjectModule(root, join(root, module), "config");
|
|
1087
1089
|
const files = Object.fromEntries(PROJECT_DIRECTORIES.map((name) => [name, projectFiles(root, name, mode)]));
|
|
1088
1090
|
for (const { file } of files.middleware) readProjectModule(root, file, "middleware");
|
|
@@ -1160,6 +1162,7 @@ function prepareProject(directory, mode, project) {
|
|
|
1160
1162
|
"maximus",
|
|
1161
1163
|
...catalog ? [] : ["standardErrors"]
|
|
1162
1164
|
].join(", ")} } from '@arbol-ai/maximus';`,
|
|
1165
|
+
...capture ? ["import { defineCapture } from '@arbol-ai/maximus/capture';"] : [],
|
|
1163
1166
|
`import { ${context ? "bindContext, " : ""}useProjectMiddleware } from '@arbol-ai/maximus/config';`,
|
|
1164
1167
|
"import { application } from './config.ts';",
|
|
1165
1168
|
"import { middleware } from './middleware.ts';",
|
|
@@ -1167,13 +1170,15 @@ function prepareProject(directory, mode, project) {
|
|
|
1167
1170
|
...catalog ? [`import errors from ${relativeModule(catalog)};`] : [],
|
|
1168
1171
|
...auth ? [`import auth from ${relativeModule(auth)};`] : [],
|
|
1169
1172
|
...context ? [`import context from ${relativeModule(context)};`] : [],
|
|
1170
|
-
...telemetry ? [`import telemetry from ${relativeModule(telemetry)};`] : []
|
|
1173
|
+
...telemetry ? [`import telemetry from ${relativeModule(telemetry)};`] : [],
|
|
1174
|
+
...capture ? [`import capture from ${relativeModule(capture)};`] : []
|
|
1171
1175
|
], [`const configured = maximus<Env>({ ${[
|
|
1172
1176
|
"...application",
|
|
1173
1177
|
...auth ? ["tokens: { ...application.tokens, ...defineAuth(auth) }"] : [],
|
|
1174
1178
|
catalog ? "errors" : "errors: standardErrors",
|
|
1175
1179
|
...described ? ["mcp"] : [],
|
|
1176
|
-
...telemetry ? ["telemetry: defineTelemetry(telemetry)"] : []
|
|
1180
|
+
...telemetry ? ["telemetry: defineTelemetry(telemetry)"] : [],
|
|
1181
|
+
...capture ? ["capture: defineCapture(capture)"] : []
|
|
1177
1182
|
].join(", ")} });`, `export const base = useProjectMiddleware(${context ? "bindContext(configured, context)" : "configured"}, middleware);`]),
|
|
1178
1183
|
"register.d.ts": generatedModule(mode, ["import type { base } from './base.ts';", ...catalog ? [`import type errors from ${relativeModule(catalog)};`] : []], [
|
|
1179
1184
|
"declare global {",
|
|
@@ -1265,7 +1270,7 @@ function prepareProject(directory, mode, project) {
|
|
|
1265
1270
|
/** A web app's pages and layout, and the files its build serves by name. */
|
|
1266
1271
|
const WEB_APP_DIRECTORIES = ["app", "public"];
|
|
1267
1272
|
/** The root modules that complete the application, and the web app's HTML entry. */
|
|
1268
|
-
const ROOT_MODULE = /^(?:(?:errors|auth|context|telemetry)\.(?:ts|mts|js|mjs)|index\.html)$/;
|
|
1273
|
+
const ROOT_MODULE = /^(?:(?:errors|auth|context|telemetry|capture)\.(?:ts|mts|js|mjs)|index\.html)$/;
|
|
1269
1274
|
/**
|
|
1270
1275
|
* What the Worker's configuration and exports follow from a prepared project: Cloudflare's plugin reads them as
|
|
1271
1276
|
* the server starts, so only a restart applies a change to them.
|
package/dist/webhooks.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Cr as Failure, dr as Result } from "./chunks/types-Dqo3oGig.js";
|
|
2
2
|
/** Why a webhook signature was refused: absent, malformed, outside the time tolerance, or not matching. */
|
|
3
3
|
export declare const WEBHOOK_SIGNATURE_FAILURES: readonly ['missing', 'malformed', 'expired', 'mismatch'];
|
|
4
4
|
/** Why a webhook signature was refused. */
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as credentials, i as createWorker, n as WorkerOptions, o as WorkerAssetsOptions, r as WorkerRuntime, t as RpcMethods } from "../chunks/workers-types-
|
|
1
|
+
import { a as credentials, i as createWorker, n as WorkerOptions, o as WorkerAssetsOptions, r as WorkerRuntime, t as RpcMethods } from "../chunks/workers-types-BgjyDtGd.js";
|
|
2
2
|
export { RpcMethods, type WorkerAssetsOptions, WorkerOptions, WorkerRuntime, createWorker, credentials };
|
package/dist/workers/runtime.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arbol-ai/maximus",
|
|
3
|
-
"version": "8.0
|
|
3
|
+
"version": "8.1.0",
|
|
4
4
|
"description": "Maximus: define a service once and serve it over HTTP, MCP and Worker RPC on Cloudflare Workers, configured in vite.config.ts, with its OpenAPI and CLI.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -95,6 +95,10 @@
|
|
|
95
95
|
"types": "./dist/analytics/analytics.d.ts",
|
|
96
96
|
"import": "./dist/analytics/analytics.js"
|
|
97
97
|
},
|
|
98
|
+
"./capture": {
|
|
99
|
+
"types": "./dist/capture/index.d.ts",
|
|
100
|
+
"import": "./dist/capture/index.js"
|
|
101
|
+
},
|
|
98
102
|
"./postgres": {
|
|
99
103
|
"types": "./dist/postgres/index.d.ts",
|
|
100
104
|
"import": "./dist/postgres/index.js"
|
package/skills/maximus/SKILL.md
CHANGED
|
@@ -23,6 +23,7 @@ context.ts export default defineContext(({ env, principa
|
|
|
23
23
|
errors.ts export default defineErrors({ … }): the service's own failure codes
|
|
24
24
|
auth.ts export default defineAuth({ resolve }): tokens the service verifies itself
|
|
25
25
|
telemetry.ts export default defineTelemetry({ observers }): observers such as analytics()
|
|
26
|
+
capture.ts export default defineCapture({ sink, payloads, dimensions }): a record of every call
|
|
26
27
|
middleware/ defineMiddleware (before admission) or defineOperationMiddleware (after it)
|
|
27
28
|
pages/ crons/ queues/ email/ Public pages and webhooks (pages/webhooks/x.post.ts), event handlers
|
|
28
29
|
durable-objects/ Durable Object classes, one per file
|
|
@@ -95,6 +96,7 @@ Every `maximus` command says what it did in a sentence; `--json` prints it as JS
|
|
|
95
96
|
| Many items in one answer | `output: Page(Item, { $id: 'ItemPage' })` with `input: PageQueryFields`. |
|
|
96
97
|
| A file upload or download | `http: { body: 'bytes' }` with `body.read()`; `output: AttachmentOutputSchema` with `http: { response: 'attachment' }`. |
|
|
97
98
|
| Data in Postgres | `withTenantTransaction` from `@arbol-ai/maximus/postgres`. |
|
|
99
|
+
| A record of every call, for audit or a lake | `capture.ts` with `defineCapture` from `@arbol-ai/maximus/capture`; mark credential fields `secret: true`. See [Capture](https://github.com/getarbol/maximus/blob/main/docs/guides/capture.md). |
|
|
98
100
|
| Guidance agents read over MCP | `mcp/instructions.md`, `mcp/guides/<name>.md`, `mcp/skills/<name>.md`: static text for every caller, never tenant data. |
|
|
99
101
|
| A 7.x service | [Upgrading to 8.0](https://github.com/getarbol/maximus/blob/main/docs/upgrading-to-8.md). |
|
|
100
102
|
|
|
@@ -118,6 +120,10 @@ Every `maximus` command says what it did in a sentence; `--json` prints it as JS
|
|
|
118
120
|
clinical data never go in a log line, a failure's `data` or message, a refinement message, an MCP guide or
|
|
119
121
|
skill, or an example. Report a caught error with `reportUnexpected(error, surface)`, which keeps its name
|
|
120
122
|
and drops its message.
|
|
123
|
+
- **Content leaves only through capture.** Observers still receive metadata alone, never input, output or
|
|
124
|
+
credentials. Capture (`capture.ts`) is a separate, declared destination, which the owner authorized on 3
|
|
125
|
+
November 2026: content reaches a store through it, never through a log line, an observer or a failure. Mark
|
|
126
|
+
every credential field `secret: true`, where the wire carries it, before turning capture on.
|
|
121
127
|
- **Worker code reads `env`, never `process.env`.** A secret is `bindings.secret()`. The development token is
|
|
122
128
|
never declared in `env` and never set on a deployed Worker.
|
|
123
129
|
- **Outbound calls:** a Worker's `fetch(…, { redirect: 'error' })` throws before it sends anything. Send with
|
|
@@ -171,6 +177,7 @@ The documentation is in the Maximus repository, indexed by
|
|
|
171
177
|
[Postgres transactions](https://github.com/getarbol/maximus/blob/main/docs/guides/postgres.md).
|
|
172
178
|
- Ship it: [Testing](https://github.com/getarbol/maximus/blob/main/docs/guides/testing.md),
|
|
173
179
|
[Observability](https://github.com/getarbol/maximus/blob/main/docs/guides/observability.md),
|
|
180
|
+
[Capture](https://github.com/getarbol/maximus/blob/main/docs/guides/capture.md),
|
|
174
181
|
[Deploying](https://github.com/getarbol/maximus/blob/main/docs/guides/deploying.md),
|
|
175
182
|
[Lint and format](https://github.com/getarbol/maximus/blob/main/docs/guides/lint-and-format.md).
|
|
176
183
|
- Reference: [Configuration](https://github.com/getarbol/maximus/blob/main/docs/reference/configuration.md),
|
|
@@ -109,6 +109,10 @@ Each is optional and default-exports one declaration:
|
|
|
109
109
|
the observers of every call, such as `analytics({ record })` from `@arbol-ai/maximus/analytics`. Observers
|
|
110
110
|
receive safe metadata alone, never input, output or credentials. See
|
|
111
111
|
[Observability](https://github.com/getarbol/maximus/blob/main/docs/guides/observability.md).
|
|
112
|
+
- `capture.ts`: `defineCapture({ enabled, sink, payloads, dimensions })`, from `@arbol-ai/maximus/capture`: one
|
|
113
|
+
complete record of every call and refusal for a store the service declares, such as `pipeline({ binding })`.
|
|
114
|
+
It is apart from telemetry, and it never carries what a schema marks `secret: true`, a token or raw bytes. See
|
|
115
|
+
[Capture](https://github.com/getarbol/maximus/blob/main/docs/guides/capture.md).
|
|
112
116
|
|
|
113
117
|
Root modules never import a route or a generated module.
|
|
114
118
|
|
|
@@ -128,6 +128,8 @@ browsers can import):
|
|
|
128
128
|
`HttpsUrlSchema`, `HexColorSchema`, `PostalAddressSchema`, `NamedReferenceSchema`, `SignedUrlSchema`,
|
|
129
129
|
`DeletedObjectSchema`, `EmptyInputSchema`.
|
|
130
130
|
- Absent values in an output are `t.Union([X, t.Null()])`: answer every field.
|
|
131
|
+
- `secret: true` on a schema marks a value capture never records, such as `t.String({ secret: true })`. It
|
|
132
|
+
changes nothing a caller or a handler sees.
|
|
131
133
|
- Codecs from `@arbol-ai/maximus/schemas` (`normalizeSchema`, `transformSchema`, `refineSchema`,
|
|
132
134
|
`inspectSchema`, `pipeSchema`, `stripObject`) run only inside `inputSchema(…)`; `.build()` refuses an input
|
|
133
135
|
that uses them outside it. `defaultSchema` gives a field its default. A refinement's message reaches the
|
|
@@ -7,8 +7,8 @@ node_modules/@arbol-ai/maximus that `bun install` fills.
|
|
|
7
7
|
## Structure
|
|
8
8
|
|
|
9
9
|
This is a Maximus project on Cloudflare Workers. vite.config.ts is its only configuration: maximus() states
|
|
10
|
-
the application, its bindings and its Worker, and errors.ts, context.ts, auth.ts and
|
|
11
|
-
it in code when present.
|
|
10
|
+
the application, its bindings and its Worker, and errors.ts, context.ts, auth.ts, telemetry.ts and capture.ts
|
|
11
|
+
complete it in code when present.
|
|
12
12
|
|
|
13
13
|
- routes/: one defineHandler(handler, contract) per file, named by its path and method:
|
|
14
14
|
routes/v1/tasks/[taskId].delete.ts answers DELETE /api/v1/tasks/{taskId}. Its operation name, effect and
|
|
@@ -29,7 +29,7 @@ it in code when present.
|
|
|
29
29
|
- src/: the domain, in modules named after it, which any folder imports as #src/<module>.ts. tests/:
|
|
30
30
|
tests that call `handler` from #maximus/http in Node.
|
|
31
31
|
- .maximus/: generated by `maximus prepare`, vp dev, vp build and vp test. Never edit it, and never import
|
|
32
|
-
it at runtime from errors.ts, context.ts, auth.ts or
|
|
32
|
+
it at runtime from errors.ts, context.ts, auth.ts, telemetry.ts or capture.ts.
|
|
33
33
|
|
|
34
34
|
The project-structure guide maps every file:
|
|
35
35
|
https://github.com/getarbol/maximus/blob/main/docs/guides/project-structure.md. Bindings and triggers
|
|
@@ -30,6 +30,7 @@ curl -H "authorization: Bearer $(cut -d= -f2 .dev.vars)" http://localhost:5173/a
|
|
|
30
30
|
| Your own failures | `errors.ts` default-exports `defineErrors({ … })` |
|
|
31
31
|
| A provider's webhook | `pages/webhooks/<provider>.post.ts`, which verifies the delivery's signature |
|
|
32
32
|
| Observers or analytics | `telemetry.ts` default-exports `defineTelemetry({ observers })` |
|
|
33
|
+
| A record of every call | `capture.ts` default-exports `defineCapture({ sink, payloads })` |
|
|
33
34
|
| What every handler receives | `context.ts` default-exports `defineContext(…)` |
|
|
34
35
|
| Domain logic and stores | A module of `src/` named after its domain, imported as `#src/tasks.ts` |
|
|
35
36
|
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { t as decodeInput } from "./validation-fTohBT6R.js";
|
|
2
|
-
import { i as standardErrors } from "./errors-C5w9WY1l.js";
|
|
3
|
-
import { a as isAttachmentSchema, o as validAttachment } from "./define-app-x7uY70_1.js";
|
|
4
|
-
import { t as err } from "./result-CKgZHrnj.js";
|
|
5
|
-
import { A as operationOutputLimit, b as ADMISSION_CODES, k as operationMatchesScopes, w as STANDARD_CODES, x as BODY_CODES } from "./openapi-CeolxIqa.js";
|
|
6
|
-
import { a as telemetryEnabled, i as reportUnexpected } from "./telemetry-C3LfZcOB.js";
|
|
7
|
-
import { Value } from "@sinclair/typebox/value";
|
|
8
|
-
|
|
9
|
-
// src/execution.ts
|
|
10
|
-
/**
|
|
11
|
-
* The one execution path every transport calls: the caller's eligibility, input decoding, context
|
|
12
|
-
* preparation, middleware, the handler, and the checks on what it returns.
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* The execution path every transport shares: checks that the caller may run the operation (its scopes when
|
|
16
|
-
* `authority` is given, its actor kind, and `authority` itself when the operation has conditional scopes),
|
|
17
|
-
* decodes the input, prepares the context, runs the middleware and the handler, then checks the result
|
|
18
|
-
* against the catalog, the declared failures, the output schema and the output limit. A refused caller
|
|
19
|
-
* answers `FORBIDDEN` and a refused input `INVALID_INPUT`. An unexpected error becomes `INTERNAL_ERROR`,
|
|
20
|
-
* reported while telemetry is on, and is never thrown.
|
|
21
|
-
*/
|
|
22
|
-
async function executeOperation(manifest, operation, env, principal, input, authority, background, body) {
|
|
23
|
-
if (operation.conditionalScopes?.length && !authority || authority && !operationMatchesScopes(operation, authority.scopes) || operation.actorKinds && !operation.actorKinds.includes(principal.actorKind)) return err(standardErrors.forbidden.create());
|
|
24
|
-
try {
|
|
25
|
-
const admitted = decodeInput(operation.input, input);
|
|
26
|
-
if (!admitted.ok) return err(standardErrors.invalidInput.create(admitted.error.data));
|
|
27
|
-
const trustedAuthority = authority ? Object.freeze({
|
|
28
|
-
surface: authority.surface,
|
|
29
|
-
scopes: Object.freeze([...authority.scopes]),
|
|
30
|
-
client: Object.freeze({ ...authority.client }),
|
|
31
|
-
...authority.token ? { token: authority.token } : {}
|
|
32
|
-
}) : void 0;
|
|
33
|
-
const invocation = {
|
|
34
|
-
env,
|
|
35
|
-
principal,
|
|
36
|
-
input: admitted.value,
|
|
37
|
-
...body ? { body } : {},
|
|
38
|
-
...background ? { background } : {},
|
|
39
|
-
...trustedAuthority ? { authority: trustedAuthority } : {}
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* A failure the call answers, from its context, middleware or handler: one of the catalog and, when the
|
|
43
|
-
* operation declares its failures, a declared or standard one. A failure only admission answers, or a
|
|
44
|
-
* body's for an operation that reads no byte body, is never the operation's. Any other is the server's
|
|
45
|
-
* error.
|
|
46
|
-
*/
|
|
47
|
-
const declared = (answered) => {
|
|
48
|
-
const failure = manifest.errors.validate(answered);
|
|
49
|
-
if (ADMISSION_CODES.has(failure.code) || BODY_CODES.has(failure.code) && operation.http?.body !== "bytes") throw new TypeError(`Failure ${failure.code} is answered before an operation runs, never by it`);
|
|
50
|
-
if (operation.failures && !STANDARD_CODES.has(failure.code) && !operation.failures.includes(failure.code)) throw new TypeError(`Undeclared failure ${failure.code}`);
|
|
51
|
-
return failure;
|
|
52
|
-
};
|
|
53
|
-
const context = operation.pipeline ? await operation.pipeline.context(invocation) : await manifest.context(invocation);
|
|
54
|
-
if (!context.ok) return err(declared(context.error));
|
|
55
|
-
const chain = operation.pipeline?.middleware ?? manifest.middleware ?? [];
|
|
56
|
-
let latest = -1;
|
|
57
|
-
/**
|
|
58
|
-
* Runs the middleware at `index`, whose `next` runs the following one, until the handler; each `next`
|
|
59
|
-
* runs once.
|
|
60
|
-
*/
|
|
61
|
-
const dispatch = async (index) => {
|
|
62
|
-
if (index <= latest) throw new Error("Middleware next() may be called only once.");
|
|
63
|
-
latest = index;
|
|
64
|
-
const middleware = chain[index];
|
|
65
|
-
return await (middleware ? middleware(context.value, () => dispatch(index + 1)) : operation.execute(context.value, admitted.value));
|
|
66
|
-
};
|
|
67
|
-
const result = await dispatch(0);
|
|
68
|
-
if (!result || typeof result.ok !== "boolean" || !Object.hasOwn(result, "ok") || Object.keys(result).length !== 2 || !Object.hasOwn(result, result.ok ? "value" : "error")) throw new TypeError("Invalid operation result");
|
|
69
|
-
if (!result.ok) return err(declared(result.error));
|
|
70
|
-
const maxOutputBytes = operationOutputLimit(manifest, operation);
|
|
71
|
-
if (isAttachmentSchema(operation.output)) {
|
|
72
|
-
if (!validAttachment(result.value, maxOutputBytes)) throw new TypeError("Invalid attachment output");
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
if (!Value.Check(operation.output, result.value)) throw new TypeError("Invalid operation output");
|
|
76
|
-
if (new TextEncoder().encode(JSON.stringify(result.value)).byteLength > maxOutputBytes) throw new TypeError("Operation output exceeds its limit");
|
|
77
|
-
return result;
|
|
78
|
-
} catch (error) {
|
|
79
|
-
if (telemetryEnabled(manifest.telemetry, env)) reportUnexpected(error, "operation", principal.requestId);
|
|
80
|
-
return err(standardErrors.internal.create());
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export { executeOperation as t };
|