@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.
Files changed (135) 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-D7zG9kx9.js → errors-WfyKhiyk.js} +9 -4
  15. package/dist/chunks/{execution-kVUJPy1A.js → execution-CfZEx_JP.js} +28 -15
  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-yKD6TSNJ.js → http-paths-DMBxwpp6.js} +50 -31
  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-DlqA7J38.js → runtime-CVVf5hmp.js} +50 -26
  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/{telemetry-BTwB68m5.js → telemetry-C3LfZcOB.js} +32 -11
  38. package/dist/chunks/{types-DQdfRF3f.d.ts → types-BQYB4Ads.d.ts} +993 -341
  39. package/dist/chunks/{validation-r-sgmsqb.js → validation-fTohBT6R.js} +69 -28
  40. package/dist/chunks/workers-types-iONp32T4.d.ts +143 -0
  41. package/dist/chunks/yaml-Dk2L24yQ.js +74 -0
  42. package/dist/diagnostics.d.ts +6 -4
  43. package/dist/diagnostics.js +2 -2
  44. package/dist/errors.d.ts +2 -2
  45. package/dist/errors.js +2 -2
  46. package/dist/http-paths.d.ts +1 -1
  47. package/dist/http-paths.js +1 -1
  48. package/dist/index.d.ts +2 -2
  49. package/dist/index.js +12 -11
  50. package/dist/internals.d.ts +1 -1
  51. package/dist/internals.js +5 -4
  52. package/dist/mcp/index.d.ts +3 -2
  53. package/dist/mcp/index.js +5 -387
  54. package/dist/postgres/index.d.ts +25 -8
  55. package/dist/postgres/index.js +17 -8
  56. package/dist/project/config.d.ts +110 -72
  57. package/dist/project/config.js +161 -45
  58. package/dist/project/index.d.ts +17 -4
  59. package/dist/project/index.js +44 -9
  60. package/dist/projection.d.ts +14 -13
  61. package/dist/projection.js +8 -32
  62. package/dist/schemas.d.ts +1 -1
  63. package/dist/schemas.js +2 -2
  64. package/dist/standard-failures.d.ts +2 -89
  65. package/dist/tooling/cli.js +149 -105
  66. package/dist/tooling/testing.js +2 -2
  67. package/dist/vite/cloudflare-workers.js +25 -0
  68. package/dist/vite/index.d.ts +157 -0
  69. package/dist/vite/index.js +1477 -0
  70. package/dist/webhooks.d.ts +12 -10
  71. package/dist/webhooks.js +26 -12
  72. package/dist/workers/runtime.d.ts +1 -1
  73. package/dist/workers/runtime.js +1 -1
  74. package/package.json +26 -22
  75. package/skills/maximus/SKILL.md +165 -68
  76. package/skills/maximus/references/deploying.md +73 -0
  77. package/skills/maximus/references/errors-and-results.md +114 -55
  78. package/skills/maximus/references/project.md +202 -0
  79. package/skills/maximus/references/routes-and-tools.md +256 -0
  80. package/skills/maximus/references/testing.md +137 -50
  81. package/skills/maximus/references/transports.md +113 -100
  82. package/skills/maximus/references/writing-code.md +84 -0
  83. package/templates/mcp/mcp/instructions.md.template +2 -0
  84. package/templates/mcp/routes/v1/greeting.get.ts.template +12 -0
  85. package/templates/mcp/tests/mcp.test.ts.template +36 -0
  86. package/templates/project/.agents/skills/project/SKILL.md.template +21 -12
  87. package/templates/project/.github/workflows/ci.yml.template +4 -1
  88. package/templates/project/CLAUDE.md.template +41 -25
  89. package/templates/project/README.md.template +54 -48
  90. package/templates/project/middleware/10-response.ts.template +5 -2
  91. package/templates/project/package.json.template +13 -9
  92. package/templates/project/pages/index.ts.template +2 -4
  93. package/templates/project/routes/v1/greeting.get.ts.template +10 -0
  94. package/templates/project/routes/v1/greeting.post.ts.template +12 -0
  95. package/templates/project/tests/greeting.test.ts.template +45 -0
  96. package/templates/project/tsconfig.json.template +8 -6
  97. package/templates/project/vite.config.ts.template +15 -7
  98. package/templates/web/app/main.tsx.template +16 -0
  99. package/templates/web/app/root.tsx.template +17 -0
  100. package/templates/web/app/routes/index.tsx.template +9 -0
  101. package/templates/web/index.html.template +12 -0
  102. package/templates/web/package.json.template +12 -0
  103. package/templates/web/tsconfig.json.template +7 -0
  104. package/templates/web/vite.config.ts.template +22 -0
  105. package/dist/chunks/builder-BiXv7d2v.js +0 -100
  106. package/dist/chunks/define-app-DvD_1jUE.js +0 -625
  107. package/dist/chunks/prepare-project-CMyGSEtI.js +0 -236
  108. package/dist/chunks/prepare-project-MtS0-W_n.js +0 -3
  109. package/dist/chunks/record-DY-lX9w1.js +0 -34
  110. package/dist/chunks/src-N3oyx5QF.js +0 -1091
  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 -57
  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 -42
  120. package/templates/project/cloudflare.config.ts.template +0 -24
  121. package/templates/project/maximus.config.ts.template +0 -20
  122. package/templates/project/routes/v1/greeting.ts.template +0 -38
  123. package/templates/service/.agents/skills/project/SKILL.md.template +0 -10
  124. package/templates/service/.github/workflows/ci.yml.template +0 -21
  125. package/templates/service/.gitignore.template +0 -9
  126. package/templates/service/CLAUDE.md.template +0 -5
  127. package/templates/service/README.md.template +0 -45
  128. package/templates/service/cloudflare.config.ts.template +0 -30
  129. package/templates/service/package.json.template +0 -36
  130. package/templates/service/src/app.ts.template +0 -30
  131. package/templates/service/src/index.ts.template +0 -13
  132. package/templates/service/tests/contract.test.ts.template +0 -12
  133. package/templates/service/tsconfig.json.template +0 -16
  134. package/templates/service/vite.config.ts.template +0 -13
  135. package/templates/service/vitest.config.ts.template +0 -10
@@ -1,236 +0,0 @@
1
- import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, writeFileSync } from "node:fs";
2
- import { join, relative, resolve, sep } from "node:path";
3
- import { parseSync } from "vite";
4
-
5
- // src/tooling/internal/project-exports.ts
6
- /** Read public export names with Oxc, without importing or executing application modules. */
7
- const ROUTE_METHODS = [
8
- "GET",
9
- "POST",
10
- "PUT",
11
- "PATCH",
12
- "DELETE"
13
- ];
14
- /** Refuse direct runtime import cycles and workerd-only imports in application configuration. */
15
- function readProjectModule(file, role) {
16
- const parsed = parseSync(file, readFileSync(file, "utf-8"));
17
- if (parsed.errors.length) throw new TypeError(`Cannot discover ${file}: ${parsed.errors[0]?.message}`);
18
- for (const node of parsed.program.body) {
19
- let source;
20
- if (node.type === "ImportDeclaration" && node.importKind !== "type") {
21
- if (node.specifiers.length === 0 || node.specifiers.some((specifier) => specifier.type !== "ImportSpecifier" || specifier.importKind !== "type")) source = node.source.value;
22
- } else if ((node.type === "ExportNamedDeclaration" || node.type === "ExportAllDeclaration") && node.exportKind !== "type") source = node.source?.value;
23
- if (!source) continue;
24
- const generated = /(?:\.maximus\/|#maximus\/)([^/.?#]+)/.exec(source)?.[1];
25
- if (generated && (role === "config" || [
26
- "app",
27
- "worker",
28
- "entry"
29
- ].includes(generated) || role === "middleware" && ["base", "routes"].includes(generated))) throw new TypeError(`Runtime import ${source} creates a generated-module cycle in ${file}. Use a type-only import or shared domain module.`);
30
- if (role === "config" && (source.startsWith("cloudflare:") || /^@arbol-ai\/maximus\/(?:workers|project)$/.test(source))) throw new TypeError(`Configuration must remain importable outside workerd: ${source} in ${file}. Import its types only.`);
31
- }
32
- return parsed;
33
- }
34
- /** Explicit exports make discovery reproducible; wildcard re-exports have no locally owned method set. */
35
- function routeExports(file) {
36
- const parsed = readProjectModule(file, "route");
37
- const names = /* @__PURE__ */ new Set();
38
- for (const statement of parsed.module.staticExports) for (const entry of statement.entries) {
39
- if (entry.isType) continue;
40
- const name = entry.exportName.kind === "Default" ? "default" : entry.exportName.name;
41
- if (!name) throw new TypeError(`Route modules require explicit exports, not export *: ${file}`);
42
- names.add(name);
43
- }
44
- const methods = ROUTE_METHODS.filter((method) => names.has(method));
45
- if (names.has("default")) {
46
- if (methods.length) throw new TypeError(`Choose a default route factory or named method exports, not both: ${file}`);
47
- return {
48
- legacy: true,
49
- methods: []
50
- };
51
- }
52
- const unsupported = [...names].filter((name) => !ROUTE_METHODS.some((method) => method === name));
53
- if (!methods.length || unsupported.length) throw new TypeError(`Route ${file} must export GET, POST, PUT, PATCH or DELETE. Keep helpers private or in _files.`);
54
- return {
55
- legacy: false,
56
- methods
57
- };
58
- }
59
-
60
- // src/tooling/internal/project-files.ts
61
- /** Deterministic source discovery. Only ordinary source files inside opted-in directories are loaded. */
62
- /** Project-owned convention directories; infrastructure remains in cloudflare.config.ts. */
63
- const PROJECT_DIRECTORIES = [
64
- "routes",
65
- "pages",
66
- "middleware",
67
- "crons",
68
- "queues",
69
- "email",
70
- "durable-objects"
71
- ];
72
- /** Sort by code units so generated imports are identical on every locale and platform. */
73
- function compareNames(a, b) {
74
- return a < b ? -1 : Number(a > b);
75
- }
76
- /** Discover without following symlinks or importing user code into the build host. */
77
- function projectFiles(root, directory, mode) {
78
- const folder = resolve(root, directory);
79
- if (!existsSync(folder)) return [];
80
- if (lstatSync(folder).isSymbolicLink()) throw new TypeError(`Project directory cannot be a symlink: ${directory}`);
81
- const files = [];
82
- function visit(current) {
83
- for (const entry of readdirSync(current, { withFileTypes: true })) {
84
- if (entry.name.startsWith(".") || entry.name.startsWith("_") && !(directory === "email" && entry.name.startsWith("_default."))) continue;
85
- const file = join(current, entry.name);
86
- if (entry.isSymbolicLink()) throw new TypeError(`Project modules cannot be symlinks: ${relative(root, file)}`);
87
- if (entry.isDirectory()) visit(file);
88
- else if (entry.isFile() && /\.(?:[cm]?ts|tsx|[cm]?js|jsx)$/.test(entry.name) && !/\.(?:d|test|spec)(?:\.(?:dev|prod))?\.[^.]+$/.test(entry.name)) {
89
- const name = relative(folder, file).split(sep).join("/").replace(/\.[^.]+$/, "");
90
- const environment = /\.(dev|prod)$/.exec(name)?.[1];
91
- if (environment && (environment === "dev" ? mode !== "development" : mode !== "production")) continue;
92
- files.push({
93
- file,
94
- name: name.replace(/\.(?:dev|prod)$/, "")
95
- });
96
- }
97
- }
98
- }
99
- visit(folder);
100
- files.sort((a, b) => compareNames(a.file, b.file));
101
- return files;
102
- }
103
- /** Convert groups, index files and dynamic operation segments into a native Maximus path. */
104
- function projectPath(name, kind) {
105
- const segments = name.split("/").filter((segment) => !/^\([a-zA-Z0-9_-]+\)$/.test(segment));
106
- if (segments.at(-1) === "index") segments.pop();
107
- const path = `/${segments.map((segment) => {
108
- const parameter = /^\[([a-zA-Z][a-zA-Z0-9_]*)\]$/.exec(segment)?.[1];
109
- if (parameter && kind === "routes") return `{${parameter}}`;
110
- if (!/^[a-zA-Z0-9_-]+$/.test(segment)) throw new TypeError(`Unsupported ${kind} segment: ${segment}. Pages use fixed paths; operations support [parameter].`);
111
- return segment;
112
- }).join("/")}`;
113
- if (kind === "routes" && !/^\/v[1-9][0-9]*\/.+/.test(path)) throw new TypeError(`Operation file must live below routes/v1/ (or another version): ${name}`);
114
- return path;
115
- }
116
-
117
- // src/tooling/internal/prepare-project.ts
118
- /** Build-time source generation preserves each operation's literal type and keeps filesystem code out of Workers. */
119
- /** Generate only owned modules; a failed discovery never replaces the previous output. */
120
- function prepareProject(directory, mode = "production") {
121
- const root = resolve(directory);
122
- const configs = [
123
- "maximus.config.ts",
124
- "maximus.config.mts",
125
- "maximus.config.js",
126
- "maximus.config.mjs"
127
- ].filter((name) => existsSync(join(root, name)));
128
- if (configs.length > 1) throw new TypeError("Keep exactly one maximus.config module at the project root.");
129
- const [config] = configs;
130
- if (config && lstatSync(join(root, config)).isSymbolicLink()) throw new TypeError("The Maximus configuration cannot be a symlink.");
131
- for (const required of config ? [] : ["src/application.ts", "src/worker.ts"]) if (!existsSync(join(root, required))) throw new TypeError(`Add maximus.config.ts, or keep the legacy ${required}. Create a project with maximus init --layout project.`);
132
- const output = join(root, ".maximus");
133
- if (existsSync(output) && lstatSync(output).isSymbolicLink()) throw new TypeError("The generated .maximus directory cannot be a symlink.");
134
- const files = Object.fromEntries(PROJECT_DIRECTORIES.map((name) => [name, projectFiles(root, name, mode)]));
135
- if (config) readProjectModule(join(root, config), "config");
136
- for (const { file } of files.middleware ?? []) readProjectModule(file, "middleware");
137
- const header = `// Generated by maximus prepare (${mode}). Edit the source modules, not this file.\n`;
138
- const imports = [];
139
- const source = (file) => JSON.stringify(relative(output, file).split(sep).join("/"));
140
- const register = (kind) => (files[kind] ?? []).map((file, index) => {
141
- const identifier = `${kind.replaceAll("-", "_")}_${index}`;
142
- imports.push(`import ${identifier} from ${source(file.file)};`);
143
- return {
144
- ...file,
145
- identifier
146
- };
147
- });
148
- const occupied = /* @__PURE__ */ new Set();
149
- const mounts = (files.routes ?? []).flatMap(({ name, file }, index) => {
150
- const path = projectPath(name, "routes");
151
- if (occupied.has(path)) throw new TypeError(`Multiple route files claim ${path}; put its methods in one module.`);
152
- occupied.add(path);
153
- const identifier = `routes_${index}`;
154
- const exports = routeExports(file);
155
- if (exports.legacy) {
156
- imports.push(`import ${identifier} from ${source(file)};`);
157
- return [`.mount(${identifier}(${JSON.stringify(path)}))`];
158
- }
159
- imports.push(`import * as ${identifier} from ${source(file)};`);
160
- return exports.methods.map((method) => `.mount(${identifier}.${method}(${JSON.stringify(path)}, ${JSON.stringify(method)}))`);
161
- });
162
- const application = `${header}import { checkProjectPipeline } from '@arbol-ai/maximus/config';\nimport { base } from './base.ts';\n${imports.join("\n")}\nexport const app = checkProjectPipeline(base, base${mounts.join("")}.build());\n`;
163
- imports.length = 0;
164
- const middleware = register("middleware");
165
- const middlewareSource = `${header}import { collectMiddleware } from '@arbol-ai/maximus/config';\n${imports.join("\n")}\nexport const { middleware, requestMiddleware } = collectMiddleware([${middleware.map(({ identifier }) => identifier).join(", ")}] as const);\n`;
166
- const baseSource = config ? `${header}import config from '../${config}';\nimport { useProjectMiddleware } from '@arbol-ai/maximus/config';\nimport { middleware } from './middleware.ts';\nexport const base: typeof config.application = useProjectMiddleware(config.application, middleware);\n` : `${header}export { base } from '../src/application.ts';\n`;
167
- const routeSource = `${header}import { createRoute } from '@arbol-ai/maximus/config';\nimport { base } from './base.ts';\nexport const defineRoute = createRoute(base);\n`;
168
- imports.length = 0;
169
- const pages = register("pages");
170
- const pagePaths = /* @__PURE__ */ new Set();
171
- const pageEntries = pages.map(({ name, identifier }) => {
172
- const path = projectPath(name, "pages");
173
- if (pagePaths.has(path)) throw new TypeError(`Multiple page files claim ${path}.`);
174
- pagePaths.add(path);
175
- return `${JSON.stringify(path)}: ${identifier}`;
176
- });
177
- const crons = (files.crons ?? []).map(({ file }, index) => {
178
- imports.push(`import cron_${index}, { cron as schedule_${index} } from ${source(file)};`);
179
- return `{ cron: schedule_${index}, handler: cron_${index} }`;
180
- });
181
- const eventEntries = (kind) => {
182
- const keys = /* @__PURE__ */ new Set();
183
- return register(kind).map(({ name, identifier }) => {
184
- if (name.includes("/") || keys.has(name)) throw new TypeError(`${kind} modules require distinct top-level names: ${name}`);
185
- keys.add(name);
186
- return `${JSON.stringify(name)}: ${identifier}`;
187
- });
188
- };
189
- const queues = eventEntries("queues");
190
- const email = eventEntries("email");
191
- const classes = /* @__PURE__ */ new Set(["Service"]);
192
- const durableObjects = register("durable-objects").map(({ name, identifier }) => {
193
- 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}`);
194
- const className = name.split("-").map((part) => part[0]?.toUpperCase() + part.slice(1)).join("");
195
- if (classes.has(className)) throw new TypeError(`Duplicate Worker export: ${className}`);
196
- classes.add(className);
197
- return `export const ${className} = worker.durableObject(${identifier});`;
198
- });
199
- const worker = `${header}import { createProjectWorker } from '@arbol-ai/maximus/project';\nimport type { WorkerRuntime } from '@arbol-ai/maximus/workers';\nimport type { ProjectEnv } from '@arbol-ai/maximus/config';\nimport type { base } from './base.ts';\nimport { app } from './app.ts';\n${config ? `import config from '../${config}';\nconst options = config.worker;` : "import { options } from '../src/worker.ts';"}\nimport { requestMiddleware } from './middleware.ts';\n${imports.join("\n")}\nconst worker: WorkerRuntime<${config ? "ProjectEnv<typeof config>" : "Parameters<typeof base.definition.context>[0]['env']"}, typeof app.operations> = createProjectWorker(app, { pages: { ${pageEntries.join(", ")} }, crons: [${crons.join(", ")}], queues: { ${queues.join(", ")} }, email: { ${email.join(", ")} } }, { ...options, http: { ...options.http, middleware: [...(options.http?.middleware ?? []), ...requestMiddleware] } });\nexport default worker.handler;\nexport const Service = worker.entrypoint;\n${durableObjects.join("\n")}\n`;
200
- mkdirSync(output, { recursive: true });
201
- const generated = {
202
- "middleware.ts": middlewareSource,
203
- "base.ts": baseSource,
204
- "routes.ts": routeSource,
205
- "app.ts": application,
206
- "worker.ts": worker,
207
- "entry.ts": "// Generated by maximus prepare. Stable Cloudflare entrypoint.\nexport { default } from './worker.ts';\nexport * from './worker.ts';\n"
208
- };
209
- for (const name of Object.keys(generated)) {
210
- const target = join(output, name);
211
- if (existsSync(target) && (lstatSync(target).isSymbolicLink() || !lstatSync(target).isFile())) throw new TypeError(`Generated files must be ordinary files: ${name}`);
212
- }
213
- let changed = false;
214
- for (const [name, content] of Object.entries(generated)) {
215
- const target = join(output, name);
216
- if (existsSync(target) && lstatSync(target).isSymbolicLink()) throw new TypeError(`Generated files cannot be symlinks: ${name}`);
217
- if (!existsSync(target) || readFileSync(target, "utf-8") !== content) {
218
- changed = true;
219
- const temporary = `${target}.${process.pid}.tmp`;
220
- writeFileSync(temporary, content, { flag: "wx" });
221
- renameSync(temporary, target);
222
- }
223
- }
224
- return {
225
- directory: root,
226
- mode,
227
- layout: config ? "config" : "legacy",
228
- changed,
229
- config,
230
- durableObjects: files["durable-objects"]?.map(({ file }) => file) ?? [],
231
- files: Object.values(files).flat().map(({ file }) => file),
232
- modules: Object.fromEntries(Object.entries(files).map(([kind, entries]) => [kind, entries.length]))
233
- };
234
- }
235
-
236
- export { PROJECT_DIRECTORIES as n, prepareProject as t };
@@ -1,3 +0,0 @@
1
- import { t as prepareProject } from "./prepare-project-CMyGSEtI.js";
2
-
3
- export { prepareProject };
@@ -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 };