@arbol-ai/maximus 7.0.0 → 7.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/README.md CHANGED
@@ -40,7 +40,7 @@ export const app = maximus<Env>({
40
40
 
41
41
  Entries: the root (the core), `/workers` (the Worker), `/mcp` (MCP tools), `/client` (a typed
42
42
  client), `/schemas` (browser-safe schemas), `/errors` and `/failures` (runtime-free), `/body`,
43
- `/webhooks`, `/http-paths`, `/diagnostics`, `/internals` (the transport SPI), `/analytics`,
43
+ `/webhooks`, `/http-paths`, `/projection`, `/diagnostics`, `/internals` (the transport SPI), `/analytics`,
44
44
  `/postgres` (with the optional peer `pg`), `/testing`, `/oxlint` and `/oxfmt`. It installs the
45
45
  `maximus` CLI and ships the Maximus Agent Skill in `skills/maximus/`.
46
46
  See [package exports](https://github.com/getarbol/maximus/blob/main/docs/reference/exports.md).
@@ -0,0 +1,36 @@
1
+ //#region src/projection.d.ts
2
+ /**
3
+ * How a service's names and input schemas project onto the surfaces a gateway builds from its OpenAPI
4
+ * document, so the service, the gateway and the gateway's generated clients agree without coordinating:
5
+ * the MCP tool, the CLI's kebab-case words, a permission's description and the typed query codec.
6
+ * Browser-safe: no runtime, no schema library.
7
+ */
8
+ /** How one input field travels in a query string. */
9
+ export type QueryKind = 'string' | 'integer' | 'number' | 'boolean' | 'list';
10
+ /** Resolves a local `$ref` (`#/components/schemas/<name>`) of a bundled document. */
11
+ export type SchemaResolver = (reference: string) => unknown;
12
+ /** A resource and the verb that acts on it, such as `appointments` and `findNearest`. */
13
+ export interface ProjectedName {
14
+ /** The resource, in camelCase. */
15
+ readonly resource: string;
16
+ /** The verb, in camelCase. */
17
+ readonly verb: string;
18
+ }
19
+ /** A camelCase name in kebab-case: `findNearest` is `find-nearest`. */
20
+ export declare function kebab(value: string): string;
21
+ /** A camelCase or kebab-case name in snake_case: `findNearest` and `find-nearest` are `find_nearest`. */
22
+ export declare function snake(value: string): string;
23
+ /**
24
+ * What a permission lets a person do, read from its scope: `integrations:service-accounts:write` is
25
+ * "Write service accounts". A description the service declares wins over it; one operation's title
26
+ * never stands in, since a permission covers several operations.
27
+ */
28
+ export declare function permissionDescription(scope: string): string;
29
+ /** Portable across MCP clients and model providers (`^[a-z][a-z0-9_]{0,63}$`). */
30
+ export declare function mcpToolName(namespace: string, name: ProjectedName): string;
31
+ /**
32
+ * How one input field travels in a query string, or null when it cannot: objects and nested lists
33
+ * do not. Lists are comma separated; a `null` alternative is not expressible and is ignored.
34
+ */
35
+ export declare function queryKind(schema: unknown, resolve?: SchemaResolver): QueryKind | null;
36
+ //#endregion
@@ -0,0 +1,60 @@
1
+ //#region src/projection.ts
2
+ function record(value) {
3
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
4
+ }
5
+ /** A camelCase name in kebab-case: `findNearest` is `find-nearest`. */
6
+ function kebab(value) {
7
+ return value.replaceAll(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
8
+ }
9
+ /** A camelCase or kebab-case name in snake_case: `findNearest` and `find-nearest` are `find_nearest`. */
10
+ function snake(value) {
11
+ return value.replaceAll("-", "_").replaceAll(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
12
+ }
13
+ /**
14
+ * What a permission lets a person do, read from its scope: `integrations:service-accounts:write` is
15
+ * "Write service accounts". A description the service declares wins over it; one operation's title
16
+ * never stands in, since a permission covers several operations.
17
+ */
18
+ function permissionDescription(scope) {
19
+ const [, ...segments] = scope.split(":");
20
+ const action = segments.at(-1) ?? scope;
21
+ const subject = segments.slice(0, -1).join(" ").replaceAll("-", " ");
22
+ return `${action.charAt(0).toUpperCase()}${action.slice(1)} ${subject}`;
23
+ }
24
+ /** Portable across MCP clients and model providers (`^[a-z][a-z0-9_]{0,63}$`). */
25
+ function mcpToolName(namespace, name) {
26
+ const tool = `${snake(namespace)}_${snake(name.resource)}_${snake(name.verb)}`;
27
+ if (!/^[a-z][a-z0-9_]{0,63}$/.test(tool)) throw new TypeError(`MCP tool name ${tool} is not portable.`);
28
+ return tool;
29
+ }
30
+ function resolved(schema, resolve) {
31
+ let value = schema;
32
+ for (let depth = 0; record(value) && typeof value.$ref === "string"; depth += 1) {
33
+ if (!resolve || depth > 16) return;
34
+ value = resolve(value.$ref);
35
+ }
36
+ return value;
37
+ }
38
+ /**
39
+ * How one input field travels in a query string, or null when it cannot: objects and nested lists
40
+ * do not. Lists are comma separated; a `null` alternative is not expressible and is ignored.
41
+ */
42
+ function queryKind(schema, resolve) {
43
+ const value = resolved(schema, resolve);
44
+ if (!record(value)) return null;
45
+ let branches = null;
46
+ if (Array.isArray(value.anyOf)) branches = value.anyOf;
47
+ else if (Array.isArray(value.oneOf)) branches = value.oneOf;
48
+ if (branches) {
49
+ const kinds = branches.filter((branch) => !(record(branch) && branch.type === "null")).map((branch) => queryKind(branch, resolve));
50
+ if (!kinds.length || kinds.includes(null)) return null;
51
+ if (kinds.includes("list")) return kinds.every((kind) => kind === "list" || kind === "string") ? "list" : null;
52
+ return kinds.every((kind) => kind === kinds[0]) ? kinds[0] ?? null : null;
53
+ }
54
+ if (value.type === "array") return queryKind(value.items, resolve) === "string" ? "list" : null;
55
+ if (value.type === "string" || typeof value.const === "string" || Array.isArray(value.enum) && value.enum.every((entry) => typeof entry === "string")) return "string";
56
+ return value.type === "integer" || value.type === "number" || value.type === "boolean" ? value.type : null;
57
+ }
58
+
59
+ //#endregion
60
+ export { kebab, mcpToolName, permissionDescription, queryKind, snake };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arbol-ai/maximus",
3
- "version": "7.0.0",
3
+ "version": "7.1.0",
4
4
  "description": "Maximus: define a service once and serve it over HTTP, MCP and Worker RPC on Cloudflare Workers, with its OpenAPI, typed client and CLI.",
5
5
  "keywords": [
6
6
  "api",
@@ -67,6 +67,10 @@
67
67
  "types": "./dist/http-paths.d.ts",
68
68
  "import": "./dist/http-paths.js"
69
69
  },
70
+ "./projection": {
71
+ "types": "./dist/projection.d.ts",
72
+ "import": "./dist/projection.js"
73
+ },
70
74
  "./diagnostics": {
71
75
  "types": "./dist/diagnostics.d.ts",
72
76
  "import": "./dist/diagnostics.js"