@arbol-ai/maximus 7.4.0 → 8.0.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/README.md +36 -38
- package/bin/maximus.js +4 -0
- package/config/oxfmt.mjs +1 -0
- package/config/oxlint.mjs +10 -0
- package/dist/analytics/analytics.d.ts +21 -9
- package/dist/analytics/analytics.js +19 -5
- package/dist/body.d.ts +1 -1
- package/dist/body.js +2 -2
- package/dist/chunks/agent-skills-Ef65jTf_.js +49 -0
- package/dist/chunks/agent-skills-m7y1EUch.js +3 -0
- package/dist/chunks/{body-6LichrQm.js → body-DOIHwIIl.js} +14 -7
- package/dist/chunks/{correlation-BEkcFFGT.js → correlation-4b23a-a4.js} +8 -5
- package/dist/chunks/define-app-CfVZBt7D.js +336 -0
- package/dist/chunks/{errors-D7zG9kx9.js → errors-WfyKhiyk.js} +9 -4
- package/dist/chunks/{execution-kVUJPy1A.js → execution-CfZEx_JP.js} +28 -15
- package/dist/chunks/generate-C-9FKW0o.js +197 -0
- package/dist/chunks/handler-DWTGoduQ.js +140 -0
- package/dist/chunks/http-layout-_h7xwgPC.js +128 -0
- package/dist/chunks/{http-paths-yKD6TSNJ.js → http-paths-DMBxwpp6.js} +50 -31
- package/dist/chunks/{json-Bu4BLT25.js → json-B14evE6-.js} +21 -5
- package/dist/chunks/names-ncD7A3DV.js +280 -0
- package/dist/chunks/openapi-CV0KmJpS.js +1588 -0
- package/dist/chunks/openapi-file-OjSs9mRv.js +83 -0
- package/dist/chunks/pages-DyC0m8Zb.js +14 -0
- package/dist/chunks/prepare-configured-BmRJLg6J.js +3 -0
- package/dist/chunks/prepare-configured-Cithjf80.js +52 -0
- package/dist/chunks/project-files-C0OX7MQQ.js +130 -0
- package/dist/chunks/query-kind-CWKAXEME.js +40 -0
- package/dist/chunks/record-DQUDTpEA.js +10 -0
- package/dist/chunks/result-CKgZHrnj.js +56 -0
- package/dist/chunks/{runtime-DlqA7J38.js → runtime-CVVf5hmp.js} +50 -26
- package/dist/chunks/scaffold-DGrcjR3h.js +3 -0
- package/dist/chunks/scaffold-DZD6dfoZ.js +138 -0
- package/dist/chunks/{schemas-CzTvbXb6.js → schemas-p_aRcMC1.js} +30 -14
- package/dist/chunks/server-CCc7fil4.js +410 -0
- package/dist/chunks/src--HZrH1U9.js +568 -0
- package/dist/chunks/{telemetry-BTwB68m5.js → telemetry-C3LfZcOB.js} +32 -11
- package/dist/chunks/{types-DQdfRF3f.d.ts → types-BQYB4Ads.d.ts} +993 -341
- package/dist/chunks/{validation-r-sgmsqb.js → validation-fTohBT6R.js} +69 -28
- package/dist/chunks/workers-types-iONp32T4.d.ts +143 -0
- package/dist/chunks/yaml-Dk2L24yQ.js +74 -0
- package/dist/diagnostics.d.ts +6 -4
- package/dist/diagnostics.js +2 -2
- package/dist/errors.d.ts +2 -2
- package/dist/errors.js +2 -2
- package/dist/http-paths.d.ts +1 -1
- package/dist/http-paths.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -11
- package/dist/internals.d.ts +1 -1
- package/dist/internals.js +5 -4
- package/dist/mcp/index.d.ts +3 -2
- package/dist/mcp/index.js +5 -387
- package/dist/postgres/index.d.ts +25 -8
- package/dist/postgres/index.js +17 -8
- package/dist/project/config.d.ts +110 -72
- package/dist/project/config.js +161 -45
- package/dist/project/index.d.ts +17 -4
- package/dist/project/index.js +44 -9
- package/dist/projection.d.ts +14 -13
- package/dist/projection.js +8 -32
- package/dist/schemas.d.ts +1 -1
- package/dist/schemas.js +2 -2
- package/dist/standard-failures.d.ts +2 -89
- package/dist/tooling/cli.js +149 -105
- package/dist/tooling/testing.js +2 -2
- package/dist/vite/cloudflare-workers.js +25 -0
- package/dist/vite/index.d.ts +157 -0
- package/dist/vite/index.js +1477 -0
- package/dist/webhooks.d.ts +12 -10
- package/dist/webhooks.js +26 -12
- package/dist/workers/runtime.d.ts +1 -1
- package/dist/workers/runtime.js +1 -1
- package/package.json +26 -22
- package/skills/maximus/SKILL.md +165 -68
- package/skills/maximus/references/deploying.md +73 -0
- package/skills/maximus/references/errors-and-results.md +114 -55
- package/skills/maximus/references/project.md +202 -0
- package/skills/maximus/references/routes-and-tools.md +256 -0
- package/skills/maximus/references/testing.md +137 -50
- package/skills/maximus/references/transports.md +113 -100
- package/skills/maximus/references/writing-code.md +84 -0
- package/templates/mcp/mcp/instructions.md.template +2 -0
- package/templates/mcp/routes/v1/greeting.get.ts.template +12 -0
- package/templates/mcp/tests/mcp.test.ts.template +36 -0
- package/templates/project/.agents/skills/project/SKILL.md.template +21 -12
- package/templates/project/.github/workflows/ci.yml.template +4 -1
- package/templates/project/CLAUDE.md.template +41 -25
- package/templates/project/README.md.template +54 -48
- package/templates/project/middleware/10-response.ts.template +5 -2
- package/templates/project/package.json.template +13 -9
- package/templates/project/pages/index.ts.template +2 -4
- package/templates/project/routes/v1/greeting.get.ts.template +10 -0
- package/templates/project/routes/v1/greeting.post.ts.template +12 -0
- package/templates/project/tests/greeting.test.ts.template +45 -0
- package/templates/project/tsconfig.json.template +8 -6
- package/templates/project/vite.config.ts.template +15 -7
- package/templates/web/app/main.tsx.template +16 -0
- package/templates/web/app/root.tsx.template +17 -0
- package/templates/web/app/routes/index.tsx.template +9 -0
- package/templates/web/index.html.template +12 -0
- package/templates/web/package.json.template +12 -0
- package/templates/web/tsconfig.json.template +7 -0
- package/templates/web/vite.config.ts.template +22 -0
- package/dist/chunks/builder-BiXv7d2v.js +0 -100
- package/dist/chunks/define-app-DvD_1jUE.js +0 -625
- package/dist/chunks/prepare-project-CMyGSEtI.js +0 -236
- package/dist/chunks/prepare-project-MtS0-W_n.js +0 -3
- package/dist/chunks/record-DY-lX9w1.js +0 -34
- package/dist/chunks/src-N3oyx5QF.js +0 -1091
- package/dist/client/client.d.ts +0 -129
- package/dist/client/client.js +0 -321
- package/dist/tooling/vite.d.ts +0 -3
- package/dist/tooling/vite.js +0 -57
- package/skills/maximus/references/adding-an-operation.md +0 -179
- package/skills/maximus/references/building-a-service.md +0 -167
- package/skills/maximus/references/migration-from-v2.md +0 -62
- package/skills/maximus/references/migration-to-v5.md +0 -37
- package/skills/maximus/references/publishing-and-verification.md +0 -42
- package/templates/project/cloudflare.config.ts.template +0 -24
- package/templates/project/maximus.config.ts.template +0 -20
- package/templates/project/routes/v1/greeting.ts.template +0 -38
- package/templates/service/.agents/skills/project/SKILL.md.template +0 -10
- package/templates/service/.github/workflows/ci.yml.template +0 -21
- package/templates/service/.gitignore.template +0 -9
- package/templates/service/CLAUDE.md.template +0 -5
- package/templates/service/README.md.template +0 -45
- package/templates/service/cloudflare.config.ts.template +0 -30
- package/templates/service/package.json.template +0 -36
- package/templates/service/src/app.ts.template +0 -30
- package/templates/service/src/index.ts.template +0 -13
- package/templates/service/tests/contract.test.ts.template +0 -12
- package/templates/service/tsconfig.json.template +0 -16
- package/templates/service/vite.config.ts.template +0 -13
- package/templates/service/vitest.config.ts.template +0 -10
|
@@ -1,48 +1,54 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
A Maximus
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
|
26
|
-
|
|
|
27
|
-
|
|
|
28
|
-
|
|
|
29
|
-
|
|
|
30
|
-
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
1
|
+
# __PROJECT_NAME__
|
|
2
|
+
|
|
3
|
+
A [Maximus](https://github.com/getarbol/maximus) service on Cloudflare Workers: an API whose routes are
|
|
4
|
+
files, served to agents as MCP tools when they say so, and configured in one file, `vite.config.ts`.
|
|
5
|
+
|
|
6
|
+
## Start
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
bun install
|
|
10
|
+
bun run dev
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`bun run dev` serves the Worker at `http://localhost:5173`. `GET /api/v1/greeting` answers
|
|
14
|
+
`{ "message": "Hello World" }` to a signed-in caller. Locally, the development token in `.dev.vars` signs you
|
|
15
|
+
in, from localhost alone:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
curl -H "authorization: Bearer $(cut -d= -f2 .dev.vars)" http://localhost:5173/api/v1/greeting
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`/api/openapi.json` describes the API, and `/health` answers without a token.
|
|
22
|
+
|
|
23
|
+
## Build on it
|
|
24
|
+
|
|
25
|
+
| To add | Do |
|
|
26
|
+
| --------------------------- | -------------------------------------------------------------------------------- |
|
|
27
|
+
| A route | `bunx maximus gen route get '/v1/tasks/{taskId}'` writes its file in `routes/` |
|
|
28
|
+
| A tool only agents call | `bunx maximus gen tool summarize-tasks` writes `mcp/tools/summarize-tasks.ts` |
|
|
29
|
+
| A binding (KV, D1, R2, …) | `env: { TASKS: bindings.kv() }` in `maximus()`, with `bindings` from `cf/config` |
|
|
30
|
+
| Your own failures | `errors.ts` default-exports `defineErrors({ … })` |
|
|
31
|
+
| A provider's webhook | `pages/webhooks/<provider>.post.ts`, which verifies the delivery's signature |
|
|
32
|
+
| Observers or analytics | `telemetry.ts` default-exports `defineTelemetry({ observers })` |
|
|
33
|
+
| What every handler receives | `context.ts` default-exports `defineContext(…)` |
|
|
34
|
+
| Domain logic and stores | A module of `src/` named after its domain, imported as `#src/tasks.ts` |
|
|
35
|
+
|
|
36
|
+
`bun install`, `vp dev`, `vp test` and `vp build` generate `.maximus/` from these files; never edit it.
|
|
37
|
+
[Project structure](https://github.com/getarbol/maximus/blob/main/docs/guides/project-structure.md)
|
|
38
|
+
maps every file and folder a project can hold.
|
|
39
|
+
|
|
40
|
+
## Test, verify and deploy
|
|
41
|
+
|
|
42
|
+
`bun run test` runs the tests in `tests/` in Node, and `bun run verify` runs the types, lint and format,
|
|
43
|
+
the tests and the build. Before the first deployment, set `origin` in `vite.config.ts` to the Worker's
|
|
44
|
+
HTTPS URL (its workers.dev URL or a custom domain you own) and `tokens.issuer` to your authorization server.
|
|
45
|
+
Then:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
bunx cf auth login
|
|
49
|
+
bun run deploy
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The GitHub workflow verifies every pull request and deploys `main`, given the repository secrets
|
|
53
|
+
`CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID`. The
|
|
54
|
+
[Maximus documentation](https://github.com/getarbol/maximus/blob/main/docs/README.md) covers the rest.
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { defineMiddleware } from '@arbol-ai/maximus/config';
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Request middleware, run in filename order around every request before its token is verified: it can add
|
|
5
|
+
* headers, never authenticate a caller. Policy that needs the verified caller is defineOperationMiddleware's.
|
|
6
|
+
*/
|
|
4
7
|
export default defineMiddleware<Env>(async (_request, _env, _context, proceed) => {
|
|
5
8
|
const response = await proceed();
|
|
6
|
-
//
|
|
9
|
+
// Rebuilding a WebSocket upgrade would lose its socket.
|
|
7
10
|
if (response.status === 101) {
|
|
8
11
|
return response;
|
|
9
12
|
}
|
|
@@ -4,30 +4,33 @@
|
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"imports": {
|
|
7
|
-
"#maximus/*": "./.maximus/*.ts"
|
|
7
|
+
"#maximus/*": "./.maximus/*.ts",
|
|
8
|
+
"#src/*": "./src/*"
|
|
8
9
|
},
|
|
9
10
|
"scripts": {
|
|
10
11
|
"prepare": "maximus prepare",
|
|
11
|
-
"prepare:project": "maximus prepare",
|
|
12
12
|
"dev": "vp dev",
|
|
13
|
-
"
|
|
13
|
+
"build": "vp build",
|
|
14
|
+
"preview": "vp preview",
|
|
15
|
+
"test": "vp test run",
|
|
16
|
+
"typecheck": "maximus prepare && tsc",
|
|
14
17
|
"check": "vp check",
|
|
15
18
|
"fix": "vp check --fix",
|
|
16
|
-
"
|
|
17
|
-
"verify": "bun run typecheck && bun run check && bun run build",
|
|
19
|
+
"verify": "bun run typecheck && bun run check && bun run test && bun run build",
|
|
18
20
|
"deploy": "bun run verify && cf deploy --prebuilt --mode production"
|
|
19
21
|
},
|
|
20
22
|
"dependencies": {
|
|
21
23
|
"@arbol-ai/maximus": "__MAXIMUS_VERSION__"
|
|
22
24
|
},
|
|
23
25
|
"devDependencies": {
|
|
24
|
-
"@cloudflare/vite-plugin": "2.0.0-beta.v.
|
|
26
|
+
"@cloudflare/vite-plugin": "2.0.0-beta.v.5",
|
|
27
|
+
"@cloudflare/workers-types": "5.20261027.1",
|
|
25
28
|
"@types/node": "26.6.5",
|
|
26
|
-
"cf": "1.0.0-beta.
|
|
29
|
+
"cf": "1.0.0-beta.23",
|
|
27
30
|
"oxfmt": "0.74.0",
|
|
28
31
|
"oxlint": "1.89.0",
|
|
29
32
|
"typescript": "7.0.2",
|
|
30
|
-
"ultracite": "8.0
|
|
33
|
+
"ultracite": "8.1.0",
|
|
31
34
|
"vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
|
|
32
35
|
"vite-plus": "1.4.0"
|
|
33
36
|
},
|
|
@@ -36,7 +39,8 @@
|
|
|
36
39
|
"vitest": "5.0.5"
|
|
37
40
|
},
|
|
38
41
|
"engines": {
|
|
42
|
+
"bun": ">=1.4.4",
|
|
39
43
|
"node": ">=22.18"
|
|
40
44
|
},
|
|
41
|
-
"packageManager": "bun@1.4.
|
|
45
|
+
"packageManager": "bun@1.4.4"
|
|
42
46
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { HttpRoute } from '@arbol-ai/maximus';
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/** GET /: a public page outside the API. Business data belongs to authenticated routes. */
|
|
4
4
|
const home: HttpRoute<Env> = () =>
|
|
5
5
|
Promise.resolve(
|
|
6
|
-
new Response('Hello World\n', {
|
|
7
|
-
headers: { 'content-type': 'text/plain; charset=utf-8' },
|
|
8
|
-
})
|
|
6
|
+
new Response('Hello World\n', { headers: { 'content-type': 'text/plain; charset=utf-8' } })
|
|
9
7
|
);
|
|
10
8
|
|
|
11
9
|
export default home;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineHandler, t } from '@arbol-ai/maximus';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GET /api/v1/greeting: a greeting for the signed-in caller. The file's name gives the path and the method,
|
|
5
|
+
* and from them the operation, getGreeting, and its scope, __PROJECT_NAME__:greeting:read.
|
|
6
|
+
*/
|
|
7
|
+
export default defineHandler(() => ({ message: 'Hello World' }), {
|
|
8
|
+
description: 'Greet the authenticated caller.',
|
|
9
|
+
output: { message: t.String() },
|
|
10
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineHandler, t } from '@arbol-ai/maximus';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* POST /api/v1/greeting, the operation createGreeting: a greeting for the name the caller sends. A POST that
|
|
5
|
+
* stores nothing declares the read effect, and so needs the read scope, __PROJECT_NAME__:greeting:read.
|
|
6
|
+
*/
|
|
7
|
+
export default defineHandler(({ input }) => ({ message: `Hello, ${input.name}` }), {
|
|
8
|
+
description: 'Create a greeting for the name the caller sends, without storing anything.',
|
|
9
|
+
effect: 'read',
|
|
10
|
+
input: { name: t.String({ minLength: 1, maxLength: 100 }) },
|
|
11
|
+
output: { message: t.String() },
|
|
12
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { expect, it } from 'vite-plus/test';
|
|
2
|
+
|
|
3
|
+
import { handler } from '#maximus/http';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `vp test` prepares the project as `vp dev` does, so the API accepts this development token from localhost,
|
|
7
|
+
* as a developer who holds every scope.
|
|
8
|
+
*/
|
|
9
|
+
const token = 'test-development-token-for-local-tests';
|
|
10
|
+
const env = { DEVELOPMENT_TOKEN: token } as Env;
|
|
11
|
+
|
|
12
|
+
/** Calls the API as the Worker serves it, signed in with the development token. */
|
|
13
|
+
function call(path: string, init: RequestInit = {}) {
|
|
14
|
+
const headers = new Headers(init.headers);
|
|
15
|
+
headers.set('authorization', `Bearer ${token}`);
|
|
16
|
+
return handler(new Request(`http://localhost${path}`, { ...init, headers }), env);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Posts a JSON body to the API, signed in. */
|
|
20
|
+
function post(path: string, body: unknown) {
|
|
21
|
+
return call(path, {
|
|
22
|
+
method: 'POST',
|
|
23
|
+
headers: { 'content-type': 'application/json' },
|
|
24
|
+
body: JSON.stringify(body),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
it('greets an authenticated caller', async () => {
|
|
29
|
+
const response = await call('/api/v1/greeting');
|
|
30
|
+
expect(response.status).toBe(200);
|
|
31
|
+
expect(await response.json()).toMatchObject({ success: true, data: { message: 'Hello World' } });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('greets a caller by name, and refuses a name it cannot use', async () => {
|
|
35
|
+
const greeted = await post('/api/v1/greeting', { name: 'Ana' });
|
|
36
|
+
expect(await greeted.json()).toMatchObject({ data: { message: 'Hello, Ana' } });
|
|
37
|
+
const refused = await post('/api/v1/greeting', { name: '' });
|
|
38
|
+
expect(refused.status).toBe(400);
|
|
39
|
+
expect(await refused.json()).toMatchObject({ success: false, error: { code: 'INVALID_INPUT' } });
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('refuses a caller without a token', async () => {
|
|
43
|
+
const response = await handler(new Request('http://localhost/api/v1/greeting'), env);
|
|
44
|
+
expect(response.status).toBe(401);
|
|
45
|
+
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"lib": ["ES2024"],
|
|
5
5
|
"module": "preserve",
|
|
6
6
|
"moduleResolution": "bundler",
|
|
7
|
-
"types": ["node"],
|
|
7
|
+
"types": ["node", "@cloudflare/workers-types"],
|
|
8
8
|
"strict": true,
|
|
9
9
|
"noEmit": true,
|
|
10
10
|
"allowImportingTsExtensions": true,
|
|
@@ -15,17 +15,19 @@
|
|
|
15
15
|
"include": [
|
|
16
16
|
"src",
|
|
17
17
|
"routes",
|
|
18
|
+
"mcp",
|
|
18
19
|
"pages",
|
|
19
20
|
"middleware",
|
|
20
21
|
"crons",
|
|
21
22
|
"queues",
|
|
22
23
|
"email",
|
|
23
24
|
"durable-objects",
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
25
|
+
"tests",
|
|
26
|
+
"errors.ts",
|
|
27
|
+
"auth.ts",
|
|
28
|
+
"context.ts",
|
|
29
|
+
"telemetry.ts",
|
|
27
30
|
"vite.config.ts",
|
|
28
|
-
".maximus"
|
|
29
|
-
".cloudflare/types"
|
|
31
|
+
".maximus/*.ts"
|
|
30
32
|
]
|
|
31
33
|
}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import lint from '@arbol-ai/maximus/oxlint';
|
|
3
|
-
import { maximusProject } from '@arbol-ai/maximus/vite';
|
|
4
|
-
import { cloudflare } from '@cloudflare/vite-plugin';
|
|
1
|
+
import { maximus } from '@arbol-ai/maximus/vite';
|
|
5
2
|
import { defineConfig } from 'vite-plus';
|
|
6
3
|
|
|
4
|
+
/**
|
|
5
|
+
* The only configuration: the application and the Worker that serves it. Add bindings with
|
|
6
|
+
* `env: { NOTES: bindings.kv() }` from cf/config; the generated Env is inferred from them.
|
|
7
|
+
*/
|
|
7
8
|
export default defineConfig({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
plugins: [
|
|
10
|
+
maximus({
|
|
11
|
+
// The public HTTPS origin: the Worker's workers.dev URL, or the custom domain it is served at.
|
|
12
|
+
origin: 'https://__PROJECT_NAME__.example.com',
|
|
13
|
+
// OAuth access tokens from your authorization server, which MCP clients discover. `vp dev` also
|
|
14
|
+
// accepts the development token in .dev.vars, from localhost alone.
|
|
15
|
+
tokens: { issuer: 'https://auth.example.com/' },
|
|
16
|
+
compatibilityDate: '__COMPATIBILITY_DATE__',
|
|
17
|
+
}),
|
|
18
|
+
],
|
|
11
19
|
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Mounts the web app: React Router with the pages of app/routes/, which maximus prepare lists. */
|
|
2
|
+
import { StrictMode } from 'react';
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
4
|
+
import { createBrowserRouter, RouterProvider } from 'react-router';
|
|
5
|
+
|
|
6
|
+
import { routes } from '#maximus/app-routes';
|
|
7
|
+
|
|
8
|
+
const container = document.querySelector('#root');
|
|
9
|
+
if (!container) {
|
|
10
|
+
throw new Error('index.html needs an element with the id root.');
|
|
11
|
+
}
|
|
12
|
+
createRoot(container).render(
|
|
13
|
+
<StrictMode>
|
|
14
|
+
<RouterProvider router={createBrowserRouter(routes)} />
|
|
15
|
+
</StrictMode>
|
|
16
|
+
);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** The layout around every page, and what a page that fails shows instead. */
|
|
2
|
+
import { Outlet } from 'react-router';
|
|
3
|
+
|
|
4
|
+
/** The layout around every page: the project's name above the page. */
|
|
5
|
+
export default function Root() {
|
|
6
|
+
return (
|
|
7
|
+
<main>
|
|
8
|
+
<h1>__PROJECT_NAME__</h1>
|
|
9
|
+
<Outlet />
|
|
10
|
+
</main>
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** What a page that fails shows instead. */
|
|
15
|
+
export function ErrorBoundary() {
|
|
16
|
+
return <p role="alert">Something went wrong.</p>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The home page, at /: app/routes/ holds the pages, named as their paths. */
|
|
2
|
+
export default function Home() {
|
|
3
|
+
return (
|
|
4
|
+
<p>
|
|
5
|
+
Hello World. The API answers below <code>/api</code>, and <a href="/api/openapi.json">its OpenAPI</a>{' '}
|
|
6
|
+
describes it.
|
|
7
|
+
</p>
|
|
8
|
+
);
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>__PROJECT_NAME__</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="root"></div>
|
|
10
|
+
<script type="module" src="/app/main.tsx"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { maximus } from '@arbol-ai/maximus/vite';
|
|
2
|
+
import react from '@vitejs/plugin-react';
|
|
3
|
+
import { defineConfig } from 'vite-plus';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The only configuration: the application, the Worker that serves it and its web app, which index.html
|
|
7
|
+
* starts. Add bindings with `env: { NOTES: bindings.kv() }` from cf/config; the generated Env is inferred
|
|
8
|
+
* from them.
|
|
9
|
+
*/
|
|
10
|
+
export default defineConfig({
|
|
11
|
+
plugins: [
|
|
12
|
+
react(),
|
|
13
|
+
maximus({
|
|
14
|
+
// The public HTTPS origin: the Worker's workers.dev URL, or the custom domain it is served at.
|
|
15
|
+
origin: 'https://__PROJECT_NAME__.example.com',
|
|
16
|
+
// OAuth access tokens from your authorization server, which MCP clients discover. `vp dev` also
|
|
17
|
+
// accepts the development token in .dev.vars, from localhost alone.
|
|
18
|
+
tokens: { issuer: 'https://auth.example.com/' },
|
|
19
|
+
compatibilityDate: '__COMPATIBILITY_DATE__',
|
|
20
|
+
}),
|
|
21
|
+
],
|
|
22
|
+
});
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { _ as composeOperations, f as ok, t as defineApp } from "./define-app-DvD_1jUE.js";
|
|
2
|
-
|
|
3
|
-
// src/builder.ts
|
|
4
|
-
/** Immutable builders let independent resource modules share inferred context without overwriting routes. */
|
|
5
|
-
var ApplicationBuilder = class ApplicationBuilder {
|
|
6
|
-
/**
|
|
7
|
-
* The application declared so far: its configuration, context preparation, middleware and operations, which
|
|
8
|
-
* `.build()` checks.
|
|
9
|
-
*/
|
|
10
|
-
definition;
|
|
11
|
-
root;
|
|
12
|
-
constructor(definition, root = definition) {
|
|
13
|
-
this.definition = definition;
|
|
14
|
-
this.root = root;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Declares an operation: a camelCase name no other operation uses, its definition (scope, words, effect,
|
|
18
|
-
* schemas and exposure) and its handler, which receives the prepared context and the decoded input and
|
|
19
|
-
* returns a Result.
|
|
20
|
-
*/
|
|
21
|
-
operation(name, definition, execute) {
|
|
22
|
-
const operations = composeOperations(this.definition.operations, { [name]: {
|
|
23
|
-
...definition,
|
|
24
|
-
execute,
|
|
25
|
-
pipeline: {
|
|
26
|
-
context: (invocation) => this.definition.context({
|
|
27
|
-
...invocation,
|
|
28
|
-
operation: name
|
|
29
|
-
}),
|
|
30
|
-
middleware: this.definition.middleware ?? []
|
|
31
|
-
}
|
|
32
|
-
} });
|
|
33
|
-
return new ApplicationBuilder({
|
|
34
|
-
...this.definition,
|
|
35
|
-
operations
|
|
36
|
-
}, this.root);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Adds what `resolve` returns to the context of every operation declared after it. It runs after admission
|
|
40
|
-
* and before the middleware; a failure it returns answers the call. Derive before declaring operations.
|
|
41
|
-
*/
|
|
42
|
-
derive(resolve) {
|
|
43
|
-
if (Object.keys(this.definition.operations).length) throw new TypeError("Derive context before declaring operations.");
|
|
44
|
-
const previous = this.definition.context;
|
|
45
|
-
return new ApplicationBuilder({
|
|
46
|
-
...this.definition,
|
|
47
|
-
context: async (invocation) => {
|
|
48
|
-
const context = await previous(invocation);
|
|
49
|
-
if (!context.ok) return context;
|
|
50
|
-
const derived = await resolve(context.value);
|
|
51
|
-
return derived.ok ? ok({
|
|
52
|
-
...context.value,
|
|
53
|
-
...derived.value
|
|
54
|
-
}) : derived;
|
|
55
|
-
}
|
|
56
|
-
}, this.root);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Wraps every operation declared after it, once the caller is admitted and the context prepared. The
|
|
60
|
-
* middleware calls `next` at most once.
|
|
61
|
-
*/
|
|
62
|
-
use(middleware) {
|
|
63
|
-
return new ApplicationBuilder({
|
|
64
|
-
...this.definition,
|
|
65
|
-
middleware: [...this.definition.middleware ?? [], middleware]
|
|
66
|
-
}, this.root);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Adds the operations of a resource module built from the same application; each keeps the context and
|
|
70
|
-
* middleware it was declared with.
|
|
71
|
-
*/
|
|
72
|
-
mount(module) {
|
|
73
|
-
if (this.root !== module.root) throw new TypeError("Resource groups must derive from the same application.");
|
|
74
|
-
return new ApplicationBuilder({
|
|
75
|
-
...this.definition,
|
|
76
|
-
operations: composeOperations(this.definition.operations, module.definition.operations)
|
|
77
|
-
}, this.root);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Checks every rule the application must keep and returns it. A refusal is a TypeError that names the rule
|
|
81
|
-
* and the operation that breaks it.
|
|
82
|
-
*/
|
|
83
|
-
build() {
|
|
84
|
-
return defineApp()(this.definition);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
|
-
* Starts an application: its name, scope namespace, origin, token policy, error catalog and RPC callers.
|
|
89
|
-
* Chain `.derive()` and `.use()` to prepare each call, `.operation()` to declare operations, `.mount()` to
|
|
90
|
-
* compose resource modules that share this base, then `.build()`.
|
|
91
|
-
*/
|
|
92
|
-
function maximus(configuration) {
|
|
93
|
-
return new ApplicationBuilder({
|
|
94
|
-
...configuration,
|
|
95
|
-
operations: {},
|
|
96
|
-
context: (invocation) => Promise.resolve(ok(invocation))
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export { maximus as t };
|