@arbol-ai/maximus 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +51 -2
- package/config/oxfmt.d.mts +8 -0
- package/config/oxfmt.mjs +30 -0
- package/config/oxlint-plugin.mjs +41 -0
- package/config/oxlint.d.mts +8 -0
- package/config/oxlint.mjs +118 -0
- package/dist/analytics/analytics.d.ts +34 -0
- package/dist/analytics/analytics.js +62 -0
- package/dist/body.d.ts +2 -0
- package/dist/body.js +4 -0
- package/dist/chunks/body-BcMbreNd.js +106 -0
- package/dist/chunks/correlation-gaiEoMBr.js +45 -0
- package/dist/chunks/execution-qfZuMSIu.js +700 -0
- package/dist/chunks/json-Dwni3u4c.js +63 -0
- package/dist/chunks/record-D2H3cg8S.js +36 -0
- package/dist/chunks/schemas-q-51wBMQ.js +216 -0
- package/dist/chunks/src-Ph5KHCRP.js +1160 -0
- package/dist/chunks/telemetry-DvZgrzZn.js +220 -0
- package/dist/chunks/types-CGwAhnTE.d.ts +1630 -0
- package/dist/chunks/validation-DWxKk1Js.js +382 -0
- package/dist/client/client.d.ts +131 -0
- package/dist/client/client.js +325 -0
- package/dist/diagnostics.d.ts +41 -0
- package/dist/diagnostics.js +4 -0
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +128 -0
- package/dist/http-paths.d.ts +2 -0
- package/dist/http-paths.js +200 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +11 -0
- package/dist/internals.d.ts +2 -0
- package/dist/internals.js +5 -0
- package/dist/mcp/index.d.ts +12 -0
- package/dist/mcp/index.js +406 -0
- package/dist/postgres/index.d.ts +81 -0
- package/dist/postgres/index.js +140 -0
- package/dist/projection.d.ts +36 -0
- package/dist/projection.js +60 -0
- package/dist/schemas.d.ts +2 -0
- package/dist/schemas.js +4 -0
- package/dist/standard-failures.d.ts +91 -0
- package/dist/standard-failures.js +75 -0
- package/dist/tooling/cli.js +110 -0
- package/dist/tooling/testing.d.ts +7 -0
- package/dist/tooling/testing.js +21 -0
- package/dist/webhooks.d.ts +69 -0
- package/dist/webhooks.js +162 -0
- package/dist/workers/runtime.d.ts +112 -0
- package/dist/workers/runtime.js +228 -0
- package/package.json +157 -4
- package/skills/maximus/SKILL.md +89 -0
- package/skills/maximus/references/adding-an-operation.md +179 -0
- package/skills/maximus/references/building-a-service.md +158 -0
- package/skills/maximus/references/errors-and-results.md +77 -0
- package/skills/maximus/references/migration-from-v2.md +62 -0
- package/skills/maximus/references/migration-to-v5.md +37 -0
- package/skills/maximus/references/publishing-and-verification.md +39 -0
- package/skills/maximus/references/testing.md +73 -0
- package/skills/maximus/references/transports.md +119 -0
- package/templates/service/.agents/skills/project/SKILL.md.template +10 -0
- package/templates/service/.github/workflows/ci.yml.template +21 -0
- package/templates/service/.gitignore.template +8 -0
- package/templates/service/CLAUDE.md.template +3 -0
- package/templates/service/README.md.template +45 -0
- package/templates/service/cloudflare.config.ts.template +30 -0
- package/templates/service/oxfmt.config.ts.template +1 -0
- package/templates/service/oxlint.config.ts.template +1 -0
- package/templates/service/package.json.template +31 -0
- package/templates/service/src/app.ts.template +30 -0
- package/templates/service/src/index.ts.template +13 -0
- package/templates/service/tests/contract.test.ts.template +12 -0
- package/templates/service/tsconfig.json.template +16 -0
- package/templates/service/vite.config.ts.template +7 -0
- package/templates/service/vitest.config.ts.template +10 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { r as readBodyText, t as httpBodyFailure } from "./body-BcMbreNd.js";
|
|
2
|
+
|
|
3
|
+
//#region src/internal/json.ts
|
|
4
|
+
/** The media type of a Content-Type value, lowercased and without its parameters. */
|
|
5
|
+
function mediaType(contentType) {
|
|
6
|
+
return contentType?.split(";", 1)[0]?.trim().toLowerCase();
|
|
7
|
+
}
|
|
8
|
+
/** `application/json`, or a structured `+json` type such as `application/problem+json`. */
|
|
9
|
+
function isJsonMediaType(value) {
|
|
10
|
+
const type = mediaType(value);
|
|
11
|
+
return type === "application/json" || /^application\/[a-z0-9!#$&^_.+-]+\+json$/.test(type ?? "");
|
|
12
|
+
}
|
|
13
|
+
/** Decode bounded JSON into unknown for the owner's input/output validator. */
|
|
14
|
+
async function readJsonBody(source, options) {
|
|
15
|
+
const contentType = source.headers.get("content-type");
|
|
16
|
+
if (!(options.allowJsonSuffix ? isJsonMediaType(contentType) : mediaType(contentType) === "application/json")) {
|
|
17
|
+
source.body?.cancel().catch(() => {});
|
|
18
|
+
return {
|
|
19
|
+
ok: false,
|
|
20
|
+
error: httpBodyFailure("unexpected_content_type")
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const text = await readBodyText(source, options);
|
|
24
|
+
if (!text.ok) return text;
|
|
25
|
+
try {
|
|
26
|
+
return {
|
|
27
|
+
ok: true,
|
|
28
|
+
value: JSON.parse(text.value)
|
|
29
|
+
};
|
|
30
|
+
} catch {
|
|
31
|
+
return {
|
|
32
|
+
ok: false,
|
|
33
|
+
error: httpBodyFailure("invalid_json")
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Pass the same deadline to fetch; empty 204/205 responses have no JSON body. */
|
|
38
|
+
async function readJsonResponse(response, options) {
|
|
39
|
+
if (options.signal.aborted) {
|
|
40
|
+
response.body?.cancel().catch(() => {});
|
|
41
|
+
return {
|
|
42
|
+
ok: false,
|
|
43
|
+
error: httpBodyFailure("aborted")
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (response.status === 204 || response.status === 205) return {
|
|
47
|
+
ok: true,
|
|
48
|
+
value: null
|
|
49
|
+
};
|
|
50
|
+
return await readJsonBody(response, {
|
|
51
|
+
...options,
|
|
52
|
+
allowJsonSuffix: true
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/** Bounded Retry-After hint only. A hint never makes repeating a mutation safe. */
|
|
56
|
+
function retryAfterSeconds(value, nowMs, maximum = 3600) {
|
|
57
|
+
if (!value || !Number.isFinite(nowMs) || !Number.isSafeInteger(maximum) || maximum < 0) return;
|
|
58
|
+
const seconds = /^\d+$/.test(value.trim()) ? Number(value.trim()) : (Date.parse(value) - nowMs) / 1e3;
|
|
59
|
+
return Number.isFinite(seconds) ? Math.min(maximum, Math.max(0, Math.ceil(seconds))) : void 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { retryAfterSeconds as a, readJsonResponse as i, mediaType as n, readJsonBody as r, isJsonMediaType as t };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region 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
|
+
//#endregion
|
|
26
|
+
//#region src/internal/record.ts
|
|
27
|
+
/**
|
|
28
|
+
* The plain-record guard the readers of untrusted values share.
|
|
29
|
+
*/
|
|
30
|
+
/** Whether an untrusted value is an object with fields: neither null nor an array. */
|
|
31
|
+
function isRecord(value) {
|
|
32
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { exactLength as n, isRecord as t };
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { a as decodeIssues, n as decodeSchema, o as SchemaValidationError, s as defaultSchema, u as inputSchema } from "./validation-DWxKk1Js.js";
|
|
2
|
+
import { Kind, Type, Type as Type$1, Type as t } from "@sinclair/typebox";
|
|
3
|
+
|
|
4
|
+
//#region src/schema-reader.ts
|
|
5
|
+
/**
|
|
6
|
+
* Reads untrusted data — a stored record, a provider or model answer — through its schema's owner
|
|
7
|
+
* semantics: defaults applied, normalizers run before their checks, unknown keys of a strip object
|
|
8
|
+
* dropped. A refusal carries every issue with its path; nothing is coerced.
|
|
9
|
+
*/
|
|
10
|
+
function checkSchema(schema, input) {
|
|
11
|
+
try {
|
|
12
|
+
return {
|
|
13
|
+
success: true,
|
|
14
|
+
data: decodeSchema(inputSchema(schema, { stripUnknown: true }), input)
|
|
15
|
+
};
|
|
16
|
+
} catch (error) {
|
|
17
|
+
const issues = decodeIssues(error);
|
|
18
|
+
if (!issues) throw error;
|
|
19
|
+
return {
|
|
20
|
+
success: false,
|
|
21
|
+
error: new SchemaValidationError(issues)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** `checkSchema`, throwing its SchemaValidationError on refusal. */
|
|
26
|
+
function readSchema(schema, input) {
|
|
27
|
+
const checked = checkSchema(schema, input);
|
|
28
|
+
if (!checked.success) throw checked.error;
|
|
29
|
+
return checked.data;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/attachment-schema.ts
|
|
34
|
+
/** Runtime-free descriptor for a validated HTTP attachment, never a JSON or RPC value. */
|
|
35
|
+
/** The output of an operation that answers with a file (`http.response: 'attachment'`). */
|
|
36
|
+
const AttachmentOutputSchema = Type.Unsafe({
|
|
37
|
+
[Kind]: "HttpAttachment",
|
|
38
|
+
type: "string",
|
|
39
|
+
format: "binary",
|
|
40
|
+
description: "Authenticated attachment bytes with validated media type, filename and exact length."
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/pagination.ts
|
|
45
|
+
/**
|
|
46
|
+
* The one list contract: bidirectional keyset pagination. A list takes the query fields `cursor`,
|
|
47
|
+
* `direction` and `limit` and answers `{ object: 'list', data, pageInfo }`. The cursor is opaque to
|
|
48
|
+
* callers; there is no page number, page size, offset or implicit total.
|
|
49
|
+
*
|
|
50
|
+
* `PageInfo` and each `Page` are named schemas, so an OpenAPI document carries them once as
|
|
51
|
+
* `#/components/schemas/<name>` and every SDK generated from it shares their types.
|
|
52
|
+
*/
|
|
53
|
+
/** A public schema name: an SDK type in every language generated from the document. */
|
|
54
|
+
const PAGE_ID = /^[A-Z][A-Za-z0-9]{0,127}$/;
|
|
55
|
+
/**
|
|
56
|
+
* How to reach a list's neighboring pages: whether they exist and their opaque cursors, named `PageInfo`.
|
|
57
|
+
*/
|
|
58
|
+
const PageInfoSchema = Type.Object({
|
|
59
|
+
hasNextPage: Type.Boolean({ description: "Whether a later page exists in the current ordering." }),
|
|
60
|
+
hasPreviousPage: Type.Boolean({ description: "Whether an earlier page exists in the current ordering." }),
|
|
61
|
+
nextCursor: Type.Union([Type.String(), Type.Null()], { description: "Opaque cursor for the next page, or null when there is none." }),
|
|
62
|
+
previousCursor: Type.Union([Type.String(), Type.Null()], { description: "Opaque cursor for the previous page, or null when there is none." })
|
|
63
|
+
}, {
|
|
64
|
+
$id: "PageInfo",
|
|
65
|
+
additionalProperties: false
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* A list's `limit`: an integer from 1 to `maximum` (100), `default` (25) when the caller sends none.
|
|
69
|
+
* A list whose items are costly lowers the maximum: `{ ...PageQueryFields, limit: pageLimit({ maximum: 20 }) }`.
|
|
70
|
+
*/
|
|
71
|
+
function pageLimit(options = {}) {
|
|
72
|
+
const { maximum = 100, default: fallback = Math.min(25, maximum) } = options;
|
|
73
|
+
if (!(Number.isInteger(maximum) && Number.isInteger(fallback) && fallback >= 1 && fallback <= maximum)) throw new TypeError("A page limit has an integer default from 1 to its integer maximum.");
|
|
74
|
+
return defaultSchema(Type.Integer({
|
|
75
|
+
minimum: 1,
|
|
76
|
+
maximum,
|
|
77
|
+
description: `Maximum items returned in one page. Defaults to ${fallback}; larger reads require another cursor.`
|
|
78
|
+
}), fallback);
|
|
79
|
+
}
|
|
80
|
+
/** The query fields of a list, spread into its input beside its own filters. */
|
|
81
|
+
const PageQueryFields = {
|
|
82
|
+
cursor: Type.Optional(Type.String({ description: "Opaque cursor returned by pageInfo; omit it to request the first page." })),
|
|
83
|
+
direction: defaultSchema(Type.Union([Type.Literal("forward"), Type.Literal("backward")], { description: "Direction to traverse the stable keyset ordering from the supplied cursor." }), "forward"),
|
|
84
|
+
limit: pageLimit()
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* The output of a list of `item`, named by `$id` (`AppointmentPage`). Give each list its own name and
|
|
88
|
+
* use it for that list only: two different shapes under one `$id` become two components, the second
|
|
89
|
+
* one suffixed `_2`.
|
|
90
|
+
*/
|
|
91
|
+
function Page(item, options) {
|
|
92
|
+
if (!PAGE_ID.test(options.$id)) throw new TypeError(`Page "${options.$id}" needs a PascalCase schema name, such as AppointmentPage.`);
|
|
93
|
+
return Type.Object({
|
|
94
|
+
data: Type.Array(item, { description: "Items admitted by this resource contract within the verified organization." }),
|
|
95
|
+
object: Type.Literal("list", { description: "Discriminator for a resource list response." }),
|
|
96
|
+
pageInfo: {
|
|
97
|
+
...PageInfoSchema,
|
|
98
|
+
description: "Opaque navigation cursors for this page’s stable keyset order."
|
|
99
|
+
}
|
|
100
|
+
}, {
|
|
101
|
+
$id: options.$id,
|
|
102
|
+
additionalProperties: false
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/common-schemas.ts
|
|
108
|
+
/**
|
|
109
|
+
* Values and objects that services publish alike, each named by its `$id`: an OpenAPI document carries
|
|
110
|
+
* it once as `#/components/schemas/<name>`, and every SDK generated from those documents has one type
|
|
111
|
+
* for it. A name is public, so it names exactly one shape. Domain records (people, patients,
|
|
112
|
+
* identity documents) stay with the service that owns them.
|
|
113
|
+
*/
|
|
114
|
+
/** An email address of at most 254 characters, named `EmailAddress`. */
|
|
115
|
+
const EmailAddressSchema = Type.String({
|
|
116
|
+
$id: "EmailAddress",
|
|
117
|
+
format: "email",
|
|
118
|
+
maxLength: 254,
|
|
119
|
+
description: "Email address."
|
|
120
|
+
});
|
|
121
|
+
/** A phone number in E.164 format, named `PhoneNumber`. */
|
|
122
|
+
const PhoneNumberSchema = Type.String({
|
|
123
|
+
$id: "PhoneNumber",
|
|
124
|
+
pattern: "^\\+[1-9][0-9]{1,14}$",
|
|
125
|
+
description: "Phone number in E.164 format."
|
|
126
|
+
});
|
|
127
|
+
/** An HTTPS URL of at most 2048 characters, named `HttpsUrl`. */
|
|
128
|
+
const HttpsUrlSchema = Type.String({
|
|
129
|
+
$id: "HttpsUrl",
|
|
130
|
+
format: "uri",
|
|
131
|
+
pattern: "^https://",
|
|
132
|
+
maxLength: 2048,
|
|
133
|
+
description: "An HTTPS URL."
|
|
134
|
+
});
|
|
135
|
+
/** A `#rrggbb` color, named `HexColor`. */
|
|
136
|
+
const HexColorSchema = Type.String({
|
|
137
|
+
$id: "HexColor",
|
|
138
|
+
pattern: "^#[0-9a-fA-F]{6}$",
|
|
139
|
+
description: "A color, as #rrggbb."
|
|
140
|
+
});
|
|
141
|
+
/** What every `delete` answers. */
|
|
142
|
+
const DeletedObjectSchema = Type.Object({
|
|
143
|
+
id: Type.String({ description: "The id of the deleted resource." }),
|
|
144
|
+
deleted: Type.Literal(true)
|
|
145
|
+
}, {
|
|
146
|
+
$id: "DeletedObject",
|
|
147
|
+
additionalProperties: false
|
|
148
|
+
});
|
|
149
|
+
/** The URL of a `SignedUrl`, described as the credential it is. */
|
|
150
|
+
const SignedUrlFieldSchema = {
|
|
151
|
+
...HttpsUrlSchema,
|
|
152
|
+
description: "The signed URL. Anyone holding it has access until it expires."
|
|
153
|
+
};
|
|
154
|
+
/** A link that grants access by itself until it expires, such as a file download. */
|
|
155
|
+
const SignedUrlSchema = Type.Object({
|
|
156
|
+
url: SignedUrlFieldSchema,
|
|
157
|
+
expiresAt: Type.String({
|
|
158
|
+
format: "date-time",
|
|
159
|
+
description: "When the URL stops working."
|
|
160
|
+
})
|
|
161
|
+
}, {
|
|
162
|
+
$id: "SignedUrl",
|
|
163
|
+
additionalProperties: false
|
|
164
|
+
});
|
|
165
|
+
/** Another resource, by its id and the name people know it by. */
|
|
166
|
+
const NamedReferenceSchema = Type.Object({
|
|
167
|
+
id: Type.String({ description: "The id of the referenced resource." }),
|
|
168
|
+
name: Type.String({ description: "Its name." })
|
|
169
|
+
}, {
|
|
170
|
+
$id: "NamedReference",
|
|
171
|
+
additionalProperties: false
|
|
172
|
+
});
|
|
173
|
+
/** A postal address, shaped as FHIR `Address`. */
|
|
174
|
+
const PostalAddressSchema = Type.Object({
|
|
175
|
+
city: Type.Optional(Type.String({ maxLength: 120 })),
|
|
176
|
+
countryCode: Type.Optional(Type.String({
|
|
177
|
+
description: "ISO 3166-1 alpha-2.",
|
|
178
|
+
pattern: "^[A-Z]{2}$"
|
|
179
|
+
})),
|
|
180
|
+
line: Type.Optional(Type.Array(Type.String({ maxLength: 200 }), { maxItems: 4 })),
|
|
181
|
+
postalCode: Type.Optional(Type.String({ maxLength: 20 })),
|
|
182
|
+
state: Type.Optional(Type.String({ maxLength: 120 })),
|
|
183
|
+
use: Type.Optional(Type.Union([Type.Literal("home"), Type.Literal("work")]))
|
|
184
|
+
}, {
|
|
185
|
+
$id: "PostalAddress",
|
|
186
|
+
additionalProperties: false
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/schemas.ts
|
|
191
|
+
/**
|
|
192
|
+
* `@arbol-ai/maximus/schemas`: the browser-safe schema vocabulary: TypeBox (`t`), its types, the validators
|
|
193
|
+
* and the shared identifier schemas, with nothing that needs a Worker runtime. A contract module that
|
|
194
|
+
* browsers import (a Dashboard reading an API's limits, a widget's settings) imports from here rather than
|
|
195
|
+
* the package root.
|
|
196
|
+
*/
|
|
197
|
+
/** The input of an operation that takes none: an empty strict object. */
|
|
198
|
+
const EmptyInputSchema = Type.Object({}, { additionalProperties: false });
|
|
199
|
+
/**
|
|
200
|
+
* An organization id as identity providers issue them (`org_…`, a UUID, a slug): 1 to 128 letters, digits,
|
|
201
|
+
* `_` and `-`, starting with a letter or digit, named `OrganizationId`. Nothing in it can change the meaning
|
|
202
|
+
* of a storage key, a path or a log line.
|
|
203
|
+
*/
|
|
204
|
+
const OrganizationIdSchema = Type.String({
|
|
205
|
+
$id: "OrganizationId",
|
|
206
|
+
pattern: "^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$",
|
|
207
|
+
description: "Verified organization identifier."
|
|
208
|
+
});
|
|
209
|
+
/** A lowercase RFC 9562 UUID of version 1 to 8, named `Uuid`. */
|
|
210
|
+
const UuidSchema = Type.String({
|
|
211
|
+
$id: "Uuid",
|
|
212
|
+
pattern: "^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
//#endregion
|
|
216
|
+
export { pageLimit as _, t as a, readSchema as b, HexColorSchema as c, PhoneNumberSchema as d, PostalAddressSchema as f, PageQueryFields as g, PageInfoSchema as h, UuidSchema as i, HttpsUrlSchema as l, Page as m, OrganizationIdSchema as n, DeletedObjectSchema as o, SignedUrlSchema as p, Type$1 as r, EmailAddressSchema as s, EmptyInputSchema as t, NamedReferenceSchema as u, AttachmentOutputSchema as v, checkSchema as y };
|