@rhythmjs/openapi 0.0.1 → 0.0.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.
package/dist/body/body.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as schemaMiddleware, t as bodyExtractor } from "../runtime-CCU9lE2d.js";
1
+ import { a as schemaMiddleware, t as bodyExtractor } from "../runtime-BrscD_hj.js";
2
2
  //#region src/body/body.ts
3
3
  function apiBody(schema, options = {}) {
4
4
  const contentType = options.contentType ?? "application/json";
@@ -1,4 +1,4 @@
1
- import { a as schemaMiddleware, n as collectCookies } from "../runtime-CCU9lE2d.js";
1
+ import { a as schemaMiddleware, n as collectCookies } from "../runtime-BrscD_hj.js";
2
2
  //#region src/cookie/cookie.ts
3
3
  function apiCookie(schema, options = {}) {
4
4
  return schemaMiddleware("cookie", schema, { parameters: [{
@@ -1,4 +1,4 @@
1
- import { a as schemaMiddleware, r as collectHeaders } from "../runtime-CCU9lE2d.js";
1
+ import { a as schemaMiddleware, r as collectHeaders } from "../runtime-BrscD_hj.js";
2
2
  //#region src/header/header.ts
3
3
  function apiHeader(schema, options = {}) {
4
4
  return schemaMiddleware("header", schema, { parameters: [{
@@ -1,4 +1,4 @@
1
- import { a as schemaMiddleware } from "../runtime-CCU9lE2d.js";
1
+ import { a as schemaMiddleware } from "../runtime-BrscD_hj.js";
2
2
  //#region src/param/param.ts
3
3
  function apiParam(schema, options = {}) {
4
4
  return schemaMiddleware("param", schema, { parameters: [{
@@ -1,4 +1,4 @@
1
- import { a as schemaMiddleware, i as collectQuery } from "../runtime-CCU9lE2d.js";
1
+ import { a as schemaMiddleware, i as collectQuery } from "../runtime-BrscD_hj.js";
2
2
  //#region src/query/query.ts
3
3
  function apiQuery(schema, options = {}) {
4
4
  return schemaMiddleware("query", schema, { parameters: [{
@@ -46,21 +46,6 @@ function collectCookies(request) {
46
46
  }
47
47
  return out;
48
48
  }
49
- function parseMultipart(body, contentTypeHeader) {
50
- const boundary = /boundary="?([^";]+)"?/i.exec(contentTypeHeader)?.[1];
51
- if (!boundary) return void 0;
52
- const pairs = [];
53
- for (const part of body.split(`--${boundary}`)) {
54
- const headerEnd = part.indexOf("\r\n\r\n");
55
- if (headerEnd === -1) continue;
56
- const headers = part.slice(0, headerEnd);
57
- const name = /content-disposition:[^\r\n]*\sname="([^"]*)"/i.exec(headers)?.[1];
58
- if (name === void 0) continue;
59
- const value = /\sfilename="([^"]*)"/i.exec(headers)?.[1] ?? part.slice(headerEnd + 4).replace(/\r\n$/, "");
60
- pairs.push([name, value]);
61
- }
62
- return collectMultiValue(pairs);
63
- }
64
49
  function bodyExtractor(contentType) {
65
50
  return async (ctx) => {
66
51
  if (contentType.includes("json")) try {
@@ -74,6 +59,17 @@ function bodyExtractor(contentType) {
74
59
  message: "Malformed JSON in request body"
75
60
  };
76
61
  }
62
+ if (contentType.includes("form-data")) try {
63
+ return {
64
+ ok: true,
65
+ value: collectMultiValue(await ctx.request.clone().formData())
66
+ };
67
+ } catch {
68
+ return {
69
+ ok: false,
70
+ message: "Malformed form data in request body"
71
+ };
72
+ }
77
73
  let text;
78
74
  try {
79
75
  text = await ctx.request.clone().text();
@@ -87,16 +83,6 @@ function bodyExtractor(contentType) {
87
83
  ok: true,
88
84
  value: collectMultiValue(new URLSearchParams(text))
89
85
  };
90
- if (contentType.includes("form-data")) {
91
- const value = parseMultipart(text, ctx.request.headers.get("content-type") ?? contentType);
92
- return value ? {
93
- ok: true,
94
- value
95
- } : {
96
- ok: false,
97
- message: "Malformed form data in request body"
98
- };
99
- }
100
86
  return {
101
87
  ok: true,
102
88
  value: text
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhythmjs/openapi",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "OpenAPI 3.1 documentation middleware (request/response schemas, operations, security, docs UI) for Rhythm routers and handlers.",
5
5
  "keywords": [
6
6
  "documentation",
@@ -101,22 +101,12 @@
101
101
  "publishConfig": {
102
102
  "access": "public"
103
103
  },
104
- "scripts": {
105
- "build": "vp pack",
106
- "prepublishOnly": "vp check && vp test && vp pack",
107
- "typecheck": "tsc --noEmit",
108
- "test": "vp test",
109
- "lint": "vp lint",
110
- "fmt": "vp fmt",
111
- "fmt:check": "vp fmt --check",
112
- "check": "vp check"
113
- },
114
104
  "dependencies": {
115
105
  "@standard-schema/spec": "^1.0.0"
116
106
  },
117
107
  "devDependencies": {
118
- "@rhythmjs/rhythm": "^0.0.6",
119
- "@rhythmjs/router": "^0.0.6",
108
+ "@rhythmjs/rhythm": "^0.0.9",
109
+ "@rhythmjs/router": "^0.0.9",
120
110
  "@types/node": "^26.6.3",
121
111
  "@valibot/to-json-schema": "^1.3.0",
122
112
  "typescript": "^7.0.2",
@@ -125,8 +115,8 @@
125
115
  "zod": "^4.1.0"
126
116
  },
127
117
  "peerDependencies": {
128
- "@rhythmjs/rhythm": "^0.0.6",
129
- "@rhythmjs/router": "^0.0.6",
118
+ "@rhythmjs/rhythm": "^0.0.9",
119
+ "@rhythmjs/router": "^0.0.9",
130
120
  "@valibot/to-json-schema": ">=1.0.0",
131
121
  "zod": "^4.0.0"
132
122
  },
@@ -141,5 +131,13 @@
141
131
  "engines": {
142
132
  "node": ">=20.19.0"
143
133
  },
144
- "packageManager": "pnpm@10.33.2"
145
- }
134
+ "scripts": {
135
+ "build": "vp pack",
136
+ "typecheck": "tsc --noEmit",
137
+ "test": "vp test",
138
+ "lint": "vp lint",
139
+ "fmt": "vp fmt",
140
+ "fmt:check": "vp fmt --check",
141
+ "check": "vp check"
142
+ }
143
+ }