@arbol-ai/maximus 7.3.1 → 7.4.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/body.d.ts +1 -1
- package/dist/chunks/builder-BiXv7d2v.js +100 -0
- package/dist/chunks/{execution-B-yy4C7N.js → define-app-DvD_1jUE.js} +5 -71
- package/dist/chunks/errors-D7zG9kx9.js +126 -0
- package/dist/chunks/execution-kVUJPy1A.js +71 -0
- package/dist/chunks/http-paths-yKD6TSNJ.js +199 -0
- package/dist/chunks/prepare-project-CMyGSEtI.js +236 -0
- package/dist/chunks/prepare-project-MtS0-W_n.js +3 -0
- package/dist/chunks/{runtime-BPnaa-NK.js → runtime-DlqA7J38.js} +4 -3
- package/dist/chunks/{src-DPSpGNnT.js → src-N3oyx5QF.js} +31 -104
- package/dist/chunks/standard-failures-CLjxS2ea.js +74 -0
- package/dist/chunks/{types-BWxDd3tY.d.ts → types-DQdfRF3f.d.ts} +13 -4
- package/dist/client/client.d.ts +1 -1
- package/dist/client/client.js +2 -2
- package/dist/diagnostics.d.ts +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -124
- package/dist/http-paths.d.ts +1 -1
- package/dist/http-paths.js +1 -197
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -4
- package/dist/internals.d.ts +1 -1
- package/dist/internals.js +3 -2
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +3 -3
- package/dist/project/config.d.ts +101 -0
- package/dist/project/config.js +80 -0
- package/dist/project/index.d.ts +1 -1
- package/dist/project/index.js +3 -3
- package/dist/schemas.d.ts +1 -1
- package/dist/standard-failures.js +1 -72
- package/dist/tooling/cli.js +10 -10
- package/dist/tooling/vite.d.ts +1 -1
- package/dist/tooling/vite.js +38 -25
- 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 +4 -5
- package/skills/maximus/references/building-a-service.md +8 -8
- package/skills/maximus/references/publishing-and-verification.md +14 -11
- package/templates/project/.agents/skills/project/SKILL.md.template +7 -7
- package/templates/project/CLAUDE.md.template +10 -7
- package/templates/project/README.md.template +8 -7
- package/templates/project/cloudflare.config.ts.template +1 -1
- package/templates/project/{src/application.ts.template → maximus.config.ts.template} +4 -10
- package/templates/project/middleware/10-response.ts.template +13 -0
- package/templates/project/package.json.template +4 -0
- package/templates/project/routes/v1/greeting.ts.template +33 -17
- package/templates/project/tsconfig.json.template +1 -0
- package/dist/chunks/prepare-project-zi106pWF.js +0 -146
- package/templates/project/src/app.ts.template +0 -2
- package/templates/project/src/index.ts.template +0 -3
- package/templates/project/src/worker.ts.template +0 -6
|
@@ -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,6 +0,0 @@
|
|
|
1
|
-
import type { WorkerOptions } from '@arbol-ai/maximus/workers';
|
|
2
|
-
|
|
3
|
-
/** Keep API ownership separate from public pages. Bindings and triggers belong in cloudflare.config.ts. */
|
|
4
|
-
export const options: WorkerOptions<Env> = {
|
|
5
|
-
http: { basePath: '/api', healthPath: '/health' },
|
|
6
|
-
};
|