@arbol-ai/maximus 7.3.1 → 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.
Files changed (138) hide show
  1. package/README.md +36 -38
  2. package/bin/maximus.js +4 -0
  3. package/config/oxfmt.mjs +1 -0
  4. package/config/oxlint.mjs +10 -0
  5. package/dist/analytics/analytics.d.ts +21 -9
  6. package/dist/analytics/analytics.js +19 -5
  7. package/dist/body.d.ts +1 -1
  8. package/dist/body.js +2 -2
  9. package/dist/chunks/agent-skills-Ef65jTf_.js +49 -0
  10. package/dist/chunks/agent-skills-m7y1EUch.js +3 -0
  11. package/dist/chunks/{body-6LichrQm.js → body-DOIHwIIl.js} +14 -7
  12. package/dist/chunks/{correlation-BEkcFFGT.js → correlation-4b23a-a4.js} +8 -5
  13. package/dist/chunks/define-app-CfVZBt7D.js +336 -0
  14. package/dist/chunks/errors-WfyKhiyk.js +131 -0
  15. package/dist/chunks/execution-CfZEx_JP.js +84 -0
  16. package/dist/chunks/generate-C-9FKW0o.js +197 -0
  17. package/dist/chunks/handler-DWTGoduQ.js +140 -0
  18. package/dist/chunks/http-layout-_h7xwgPC.js +128 -0
  19. package/dist/chunks/http-paths-DMBxwpp6.js +218 -0
  20. package/dist/chunks/{json-Bu4BLT25.js → json-B14evE6-.js} +21 -5
  21. package/dist/chunks/names-ncD7A3DV.js +280 -0
  22. package/dist/chunks/openapi-CV0KmJpS.js +1588 -0
  23. package/dist/chunks/openapi-file-OjSs9mRv.js +83 -0
  24. package/dist/chunks/pages-DyC0m8Zb.js +14 -0
  25. package/dist/chunks/prepare-configured-BmRJLg6J.js +3 -0
  26. package/dist/chunks/prepare-configured-Cithjf80.js +52 -0
  27. package/dist/chunks/project-files-C0OX7MQQ.js +130 -0
  28. package/dist/chunks/query-kind-CWKAXEME.js +40 -0
  29. package/dist/chunks/record-DQUDTpEA.js +10 -0
  30. package/dist/chunks/result-CKgZHrnj.js +56 -0
  31. package/dist/chunks/{runtime-BPnaa-NK.js → runtime-CVVf5hmp.js} +50 -25
  32. package/dist/chunks/scaffold-DGrcjR3h.js +3 -0
  33. package/dist/chunks/scaffold-DZD6dfoZ.js +138 -0
  34. package/dist/chunks/{schemas-CzTvbXb6.js → schemas-p_aRcMC1.js} +30 -14
  35. package/dist/chunks/server-CCc7fil4.js +410 -0
  36. package/dist/chunks/src--HZrH1U9.js +568 -0
  37. package/dist/chunks/standard-failures-CLjxS2ea.js +74 -0
  38. package/dist/chunks/{telemetry-BTwB68m5.js → telemetry-C3LfZcOB.js} +32 -11
  39. package/dist/chunks/{types-BWxDd3tY.d.ts → types-BQYB4Ads.d.ts} +998 -337
  40. package/dist/chunks/{validation-r-sgmsqb.js → validation-fTohBT6R.js} +69 -28
  41. package/dist/chunks/workers-types-iONp32T4.d.ts +143 -0
  42. package/dist/chunks/yaml-Dk2L24yQ.js +74 -0
  43. package/dist/diagnostics.d.ts +6 -4
  44. package/dist/diagnostics.js +2 -2
  45. package/dist/errors.d.ts +2 -2
  46. package/dist/errors.js +2 -125
  47. package/dist/http-paths.d.ts +1 -1
  48. package/dist/http-paths.js +1 -197
  49. package/dist/index.d.ts +2 -2
  50. package/dist/index.js +12 -10
  51. package/dist/internals.d.ts +1 -1
  52. package/dist/internals.js +5 -3
  53. package/dist/mcp/index.d.ts +3 -2
  54. package/dist/mcp/index.js +5 -387
  55. package/dist/postgres/index.d.ts +25 -8
  56. package/dist/postgres/index.js +17 -8
  57. package/dist/project/config.d.ts +139 -0
  58. package/dist/project/config.js +196 -0
  59. package/dist/project/index.d.ts +17 -4
  60. package/dist/project/index.js +44 -9
  61. package/dist/projection.d.ts +14 -13
  62. package/dist/projection.js +8 -32
  63. package/dist/schemas.d.ts +1 -1
  64. package/dist/schemas.js +2 -2
  65. package/dist/standard-failures.d.ts +2 -89
  66. package/dist/standard-failures.js +1 -72
  67. package/dist/tooling/cli.js +151 -107
  68. package/dist/tooling/testing.js +2 -2
  69. package/dist/vite/cloudflare-workers.js +25 -0
  70. package/dist/vite/index.d.ts +157 -0
  71. package/dist/vite/index.js +1477 -0
  72. package/dist/webhooks.d.ts +12 -10
  73. package/dist/webhooks.js +26 -12
  74. package/dist/workers/runtime.d.ts +1 -1
  75. package/dist/workers/runtime.js +1 -1
  76. package/package.json +30 -22
  77. package/skills/maximus/SKILL.md +165 -69
  78. package/skills/maximus/references/deploying.md +73 -0
  79. package/skills/maximus/references/errors-and-results.md +114 -55
  80. package/skills/maximus/references/project.md +202 -0
  81. package/skills/maximus/references/routes-and-tools.md +256 -0
  82. package/skills/maximus/references/testing.md +137 -50
  83. package/skills/maximus/references/transports.md +113 -100
  84. package/skills/maximus/references/writing-code.md +84 -0
  85. package/templates/mcp/mcp/instructions.md.template +2 -0
  86. package/templates/mcp/routes/v1/greeting.get.ts.template +12 -0
  87. package/templates/mcp/tests/mcp.test.ts.template +36 -0
  88. package/templates/project/.agents/skills/project/SKILL.md.template +21 -12
  89. package/templates/project/.github/workflows/ci.yml.template +4 -1
  90. package/templates/project/CLAUDE.md.template +41 -22
  91. package/templates/project/README.md.template +54 -47
  92. package/templates/project/middleware/10-response.ts.template +16 -0
  93. package/templates/project/package.json.template +16 -8
  94. package/templates/project/pages/index.ts.template +2 -4
  95. package/templates/project/routes/v1/greeting.get.ts.template +10 -0
  96. package/templates/project/routes/v1/greeting.post.ts.template +12 -0
  97. package/templates/project/tests/greeting.test.ts.template +45 -0
  98. package/templates/project/tsconfig.json.template +8 -5
  99. package/templates/project/vite.config.ts.template +15 -7
  100. package/templates/web/app/main.tsx.template +16 -0
  101. package/templates/web/app/root.tsx.template +17 -0
  102. package/templates/web/app/routes/index.tsx.template +9 -0
  103. package/templates/web/index.html.template +12 -0
  104. package/templates/web/package.json.template +12 -0
  105. package/templates/web/tsconfig.json.template +7 -0
  106. package/templates/web/vite.config.ts.template +22 -0
  107. package/dist/chunks/execution-B-yy4C7N.js +0 -691
  108. package/dist/chunks/prepare-project-zi106pWF.js +0 -146
  109. package/dist/chunks/record-DY-lX9w1.js +0 -34
  110. package/dist/chunks/src-DPSpGNnT.js +0 -1164
  111. package/dist/client/client.d.ts +0 -129
  112. package/dist/client/client.js +0 -321
  113. package/dist/tooling/vite.d.ts +0 -3
  114. package/dist/tooling/vite.js +0 -44
  115. package/skills/maximus/references/adding-an-operation.md +0 -179
  116. package/skills/maximus/references/building-a-service.md +0 -167
  117. package/skills/maximus/references/migration-from-v2.md +0 -62
  118. package/skills/maximus/references/migration-to-v5.md +0 -37
  119. package/skills/maximus/references/publishing-and-verification.md +0 -39
  120. package/templates/project/cloudflare.config.ts.template +0 -24
  121. package/templates/project/routes/v1/greeting.ts.template +0 -22
  122. package/templates/project/src/app.ts.template +0 -2
  123. package/templates/project/src/application.ts.template +0 -26
  124. package/templates/project/src/index.ts.template +0 -3
  125. package/templates/project/src/worker.ts.template +0 -6
  126. package/templates/service/.agents/skills/project/SKILL.md.template +0 -10
  127. package/templates/service/.github/workflows/ci.yml.template +0 -21
  128. package/templates/service/.gitignore.template +0 -9
  129. package/templates/service/CLAUDE.md.template +0 -5
  130. package/templates/service/README.md.template +0 -45
  131. package/templates/service/cloudflare.config.ts.template +0 -30
  132. package/templates/service/package.json.template +0 -36
  133. package/templates/service/src/app.ts.template +0 -30
  134. package/templates/service/src/index.ts.template +0 -13
  135. package/templates/service/tests/contract.test.ts.template +0 -12
  136. package/templates/service/tsconfig.json.template +0 -16
  137. package/templates/service/vite.config.ts.template +0 -13
  138. package/templates/service/vitest.config.ts.template +0 -10
@@ -1,146 +0,0 @@
1
- import { join, relative, resolve, sep } from "node:path";
2
- import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, writeFileSync } from "node:fs";
3
-
4
- // src/tooling/internal/project-files.ts
5
- /** Deterministic source discovery. Only ordinary source files inside opted-in directories are loaded. */
6
- /** Project-owned convention directories; infrastructure remains in cloudflare.config.ts. */
7
- const PROJECT_DIRECTORIES = [
8
- "routes",
9
- "pages",
10
- "middleware",
11
- "crons",
12
- "queues",
13
- "email",
14
- "durable-objects"
15
- ];
16
- /** Sort by code units so generated imports are identical on every locale and platform. */
17
- function compareNames(a, b) {
18
- return a < b ? -1 : Number(a > b);
19
- }
20
- /** Discover without following symlinks or importing user code into the build host. */
21
- function projectFiles(root, directory, mode) {
22
- const folder = resolve(root, directory);
23
- if (!existsSync(folder)) return [];
24
- if (lstatSync(folder).isSymbolicLink()) throw new TypeError(`Project directory cannot be a symlink: ${directory}`);
25
- const files = [];
26
- function visit(current) {
27
- for (const entry of readdirSync(current, { withFileTypes: true })) {
28
- if (entry.name.startsWith(".") || entry.name.startsWith("_") && !(directory === "email" && entry.name.startsWith("_default."))) continue;
29
- const file = join(current, entry.name);
30
- if (entry.isSymbolicLink()) throw new TypeError(`Project modules cannot be symlinks: ${relative(root, file)}`);
31
- if (entry.isDirectory()) visit(file);
32
- else if (entry.isFile() && /\.(?:[cm]?ts|tsx|[cm]?js|jsx)$/.test(entry.name) && !/\.(?:d|test|spec)(?:\.(?:dev|prod))?\.[^.]+$/.test(entry.name)) {
33
- const name = relative(folder, file).split(sep).join("/").replace(/\.[^.]+$/, "");
34
- const environment = /\.(dev|prod)$/.exec(name)?.[1];
35
- if (environment && (environment === "dev" ? mode !== "development" : mode !== "production")) continue;
36
- files.push({
37
- file,
38
- name: name.replace(/\.(?:dev|prod)$/, "")
39
- });
40
- }
41
- }
42
- }
43
- visit(folder);
44
- files.sort((a, b) => compareNames(a.file, b.file));
45
- return files;
46
- }
47
- /** Convert groups, index files and dynamic operation segments into a native Maximus path. */
48
- function projectPath(name, kind) {
49
- const segments = name.split("/").filter((segment) => !/^\([a-zA-Z0-9_-]+\)$/.test(segment));
50
- if (segments.at(-1) === "index") segments.pop();
51
- const path = `/${segments.map((segment) => {
52
- const parameter = /^\[([a-zA-Z][a-zA-Z0-9_]*)\]$/.exec(segment)?.[1];
53
- if (parameter && kind === "routes") return `{${parameter}}`;
54
- if (!/^[a-zA-Z0-9_-]+$/.test(segment)) throw new TypeError(`Unsupported ${kind} segment: ${segment}. Pages use fixed paths; operations support [parameter].`);
55
- return segment;
56
- }).join("/")}`;
57
- if (kind === "routes" && !/^\/v[1-9][0-9]*\/.+/.test(path)) throw new TypeError(`Operation file must live below routes/v1/ (or another version): ${name}`);
58
- return path;
59
- }
60
-
61
- // src/tooling/internal/prepare-project.ts
62
- /** Build-time source generation preserves each operation's literal type and keeps filesystem code out of Workers. */
63
- /** Generate only owned modules; a failed discovery never replaces the previous output. */
64
- function prepareProject(directory, mode = "production") {
65
- const root = resolve(directory);
66
- for (const required of ["src/application.ts", "src/worker.ts"]) if (!existsSync(join(root, required))) throw new TypeError(`A project layout requires ${required}. Create one with maximus init --layout project.`);
67
- const output = join(root, ".maximus");
68
- if (existsSync(output) && lstatSync(output).isSymbolicLink()) throw new TypeError("The generated .maximus directory cannot be a symlink.");
69
- const files = Object.fromEntries(PROJECT_DIRECTORIES.map((name) => [name, projectFiles(root, name, mode)]));
70
- const header = "// Generated by maximus prepare. Edit the source modules, not this file.\n";
71
- const imports = [];
72
- const source = (file) => JSON.stringify(relative(output, file).split(sep).join("/"));
73
- const register = (kind) => (files[kind] ?? []).map((file, index) => {
74
- const identifier = `${kind.replaceAll("-", "_")}_${index}`;
75
- imports.push(`import ${identifier} from ${source(file.file)};`);
76
- return {
77
- ...file,
78
- identifier
79
- };
80
- });
81
- const routes = register("routes");
82
- const occupied = /* @__PURE__ */ new Set();
83
- const mounts = routes.map(({ name, identifier }) => {
84
- const path = projectPath(name, "routes");
85
- if (occupied.has(path)) throw new TypeError(`Multiple route files claim ${path}; put its methods in one module.`);
86
- occupied.add(path);
87
- return `.mount(${identifier}(${JSON.stringify(path)}))`;
88
- });
89
- const application = `${header}import { base } from '../src/application.ts';\n${imports.join("\n")}\nexport const app = base${mounts.join("")}.build();\n`;
90
- imports.length = 0;
91
- const middleware = register("middleware");
92
- const middlewareSource = `${header}${imports.join("\n")}\nexport const middleware = [${middleware.map(({ identifier }) => identifier).join(", ")}] as const;\n`;
93
- imports.length = 0;
94
- const pages = register("pages");
95
- const pagePaths = /* @__PURE__ */ new Set();
96
- const pageEntries = pages.map(({ name, identifier }) => {
97
- const path = projectPath(name, "pages");
98
- if (pagePaths.has(path)) throw new TypeError(`Multiple page files claim ${path}.`);
99
- pagePaths.add(path);
100
- return `${JSON.stringify(path)}: ${identifier}`;
101
- });
102
- const crons = (files.crons ?? []).map(({ file }, index) => {
103
- imports.push(`import cron_${index}, { cron as schedule_${index} } from ${source(file)};`);
104
- return `{ cron: schedule_${index}, handler: cron_${index} }`;
105
- });
106
- const eventEntries = (kind) => {
107
- const keys = /* @__PURE__ */ new Set();
108
- return register(kind).map(({ name, identifier }) => {
109
- if (name.includes("/") || keys.has(name)) throw new TypeError(`${kind} modules require distinct top-level names: ${name}`);
110
- keys.add(name);
111
- return `${JSON.stringify(name)}: ${identifier}`;
112
- });
113
- };
114
- const queues = eventEntries("queues");
115
- const email = eventEntries("email");
116
- const classes = /* @__PURE__ */ new Set(["Service"]);
117
- const durableObjects = register("durable-objects").map(({ name, identifier }) => {
118
- if (!/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(name)) throw new TypeError(`Durable Object filenames must be top-level kebab-case names: ${name}`);
119
- const className = name.split("-").map((part) => part[0]?.toUpperCase() + part.slice(1)).join("");
120
- if (classes.has(className)) throw new TypeError(`Duplicate Worker export: ${className}`);
121
- classes.add(className);
122
- return `export const ${className} = worker.durableObject(${identifier});`;
123
- });
124
- const worker = `${header}import { createProjectWorker } from '@arbol-ai/maximus/project';\nimport { app } from './app.ts';\nimport { options } from '../src/worker.ts';\n${imports.join("\n")}\nconst worker = createProjectWorker(app, { pages: { ${pageEntries.join(", ")} }, crons: [${crons.join(", ")}], queues: { ${queues.join(", ")} }, email: { ${email.join(", ")} } }, options);\nexport default worker.handler;\nexport const Service = worker.entrypoint;\n${durableObjects.join("\n")}\n`;
125
- mkdirSync(output, { recursive: true });
126
- for (const [name, content] of Object.entries({
127
- "app.ts": application,
128
- "middleware.ts": middlewareSource,
129
- "worker.ts": worker
130
- })) {
131
- const target = join(output, name);
132
- if (existsSync(target) && lstatSync(target).isSymbolicLink()) throw new TypeError(`Generated files cannot be symlinks: ${name}`);
133
- if (!existsSync(target) || readFileSync(target, "utf-8") !== content) {
134
- const temporary = `${target}.${process.pid}.tmp`;
135
- writeFileSync(temporary, content, { flag: "wx" });
136
- renameSync(temporary, target);
137
- }
138
- }
139
- return {
140
- directory: root,
141
- mode,
142
- modules: Object.fromEntries(Object.entries(files).map(([kind, entries]) => [kind, entries.length]))
143
- };
144
- }
145
-
146
- export { PROJECT_DIRECTORIES as n, prepareProject as t };
@@ -1,34 +0,0 @@
1
- // src/internal/exact-length.ts
2
- /**
3
- * Byte streams held to the length their headers declare.
4
- */
5
- /**
6
- * Passes a byte stream through only while it keeps its declared length: a chunk that is not bytes,
7
- * a byte beyond `length` or an end before it errors the stream, so a body never carries more or
8
- * fewer bytes than its headers say.
9
- */
10
- function exactLength(stream, length) {
11
- let received = 0;
12
- return stream.pipeThrough(new TransformStream({
13
- transform(chunk, controller) {
14
- if (!(chunk instanceof Uint8Array)) throw new TypeError("A byte stream carried a chunk that is not bytes.");
15
- received += chunk.byteLength;
16
- if (received > length) throw new TypeError("A byte stream exceeds its declared length.");
17
- controller.enqueue(chunk);
18
- },
19
- flush() {
20
- if (received !== length) throw new TypeError("A byte stream ended before its declared length.");
21
- }
22
- }));
23
- }
24
-
25
- // src/internal/record.ts
26
- /**
27
- * The plain-record guard the readers of untrusted values share.
28
- */
29
- /** Whether an untrusted value is an object with fields: neither null nor an array. */
30
- function isRecord(value) {
31
- return typeof value === "object" && value !== null && !Array.isArray(value);
32
- }
33
-
34
- export { exactLength as n, isRecord as t };