bazis 0.98.2 → 0.98.3

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.
@@ -11,6 +11,20 @@ export interface BindingDefaults {
11
11
  consumes?: string;
12
12
  }
13
13
 
14
+ const BODILESS_METHODS = new Set(["GET", "HEAD", "OPTIONS"]);
15
+
16
+ /**
17
+ * `consumes` of a route applies to every request with a body, however the
18
+ * action reads it: a body model, `ctx.formData()`, `ctx.text()` or nothing.
19
+ */
20
+ export function assertConsumes(ctx: HttpContext, consumes: string | undefined): void {
21
+ if (consumes === undefined || BODILESS_METHODS.has(ctx.method)) return;
22
+ const contentType = ctx.header("content-type") ?? "";
23
+ if (!contentType.toLowerCase().startsWith(consumes.toLowerCase())) {
24
+ throw new UnsupportedMediaTypeError(consumes);
25
+ }
26
+ }
27
+
14
28
  function bindValue(binding: ParameterBinding, raw: string | undefined, kind: string): unknown {
15
29
  if (raw === undefined) {
16
30
  if (binding.defaultValue !== undefined) {
@@ -1,5 +1,5 @@
1
1
  import type { Class, Token } from "../../di";
2
- import { bindArguments } from "../Binding/ParameterBinder";
2
+ import { assertConsumes, bindArguments } from "../Binding/ParameterBinder";
3
3
  import { resolveGeneratedBindings } from "../Binding/autoBindings";
4
4
  import { generatedSourcesAreStale } from "../../generatedFingerprint";
5
5
  import { controllerMetaOf, type ActionMeta, type ControllerMeta } from "../Decorators/metadata";
@@ -139,6 +139,7 @@ export class RouterBuilder {
139
139
 
140
140
  const boundary: HttpMiddleware = async (ctx, next) => {
141
141
  try {
142
+ assertConsumes(ctx, bindingDefaults.consumes);
142
143
  const args = bindings ? await bindArguments(bindings, ctx, bindingDefaults) : [ctx];
143
144
  for (const filter of filters) {
144
145
  await filter.before?.(ctx);
@@ -232,7 +232,7 @@ export class CodexAppServerClient implements CodexClient {
232
232
  if (method === "account/updated") this.modelCache = undefined;
233
233
  }, () => { this.clearLogin(); this.modelCache = undefined; });
234
234
  const initialized = await client.request("initialize", {
235
- clientInfo: { name: "bazis", title: "Bazis", version: "0.98.2" }, capabilities: { experimentalApi: true },
235
+ clientInfo: { name: "bazis", title: "Bazis", version: "0.98.3" }, capabilities: { experimentalApi: true },
236
236
  }, 15_000, signal);
237
237
  if (resolve(text(initialized.codexHome, 4096)) !== this.paths.home) throw new CodexError("PROTOCOL_ERROR");
238
238
  client.notify("initialized");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bazis",
3
- "version": "0.98.2",
3
+ "version": "0.98.3",
4
4
  "description": "Modular backend framework for Bun in TypeScript: DI wired by codegen, HTTP, a PostgreSQL ORM, JWT, WebSocket, agents and a CLI.",
5
5
  "license": "MIT",
6
6
  "author": "Alexander Alenin",