@remix-run/form-data-middleware 0.1.0 → 0.1.2
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/lib/form-data.d.ts +7 -1
- package/dist/lib/form-data.d.ts.map +1 -1
- package/dist/lib/form-data.js +4 -3
- package/package.json +9 -9
- package/src/index.ts +0 -1
- package/src/lib/form-data.ts +13 -9
package/dist/lib/form-data.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { type FileUploadHandler, type ParseFormDataOptions } from '@remix-run/form-data-parser';
|
|
2
2
|
import type { Middleware } from '@remix-run/fetch-router';
|
|
3
|
+
/**
|
|
4
|
+
* Options for the `formData` middleware.
|
|
5
|
+
*/
|
|
3
6
|
export interface FormDataOptions extends ParseFormDataOptions {
|
|
4
7
|
/**
|
|
5
|
-
* Set `true` to suppress parse errors.
|
|
8
|
+
* Set `true` to suppress parse errors.
|
|
9
|
+
*
|
|
10
|
+
* @default false
|
|
6
11
|
*/
|
|
7
12
|
suppressErrors?: boolean;
|
|
8
13
|
/**
|
|
@@ -14,6 +19,7 @@ export interface FormDataOptions extends ParseFormDataOptions {
|
|
|
14
19
|
}
|
|
15
20
|
/**
|
|
16
21
|
* Middleware that parses `FormData` from the request body and populates `context.formData`.
|
|
22
|
+
*
|
|
17
23
|
* @param options Options for parsing form data
|
|
18
24
|
* @returns A middleware function that parses form data
|
|
19
25
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-data.d.ts","sourceRoot":"","sources":["../../src/lib/form-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EAC1B,MAAM,6BAA6B,CAAA;
|
|
1
|
+
{"version":3,"file":"form-data.d.ts","sourceRoot":"","sources":["../../src/lib/form-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EAC1B,MAAM,6BAA6B,CAAA;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEzD;;GAEG;AACH,MAAM,WAAW,eAAgB,SAAQ,oBAAoB;IAC3D;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;;OAIG;IACH,aAAa,CAAC,EAAE,iBAAiB,CAAA;CAClC;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,UAAU,CA6B9D"}
|
package/dist/lib/form-data.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FormDataParseError, parseFormData, } from '@remix-run/form-data-parser';
|
|
2
2
|
/**
|
|
3
3
|
* Middleware that parses `FormData` from the request body and populates `context.formData`.
|
|
4
|
+
*
|
|
4
5
|
* @param options Options for parsing form data
|
|
5
6
|
* @returns A middleware function that parses form data
|
|
6
7
|
*/
|
|
@@ -8,15 +9,14 @@ export function formData(options) {
|
|
|
8
9
|
let suppressErrors = options?.suppressErrors ?? false;
|
|
9
10
|
let uploadHandler = options?.uploadHandler;
|
|
10
11
|
return async (context) => {
|
|
11
|
-
|
|
12
|
-
let method = context.method;
|
|
13
|
-
if (method === 'GET' || method === 'HEAD') {
|
|
12
|
+
if (context.method === 'GET' || context.method === 'HEAD') {
|
|
14
13
|
return;
|
|
15
14
|
}
|
|
16
15
|
let contentType = context.headers.get('Content-Type');
|
|
17
16
|
if (contentType == null ||
|
|
18
17
|
(!contentType.startsWith('multipart/') &&
|
|
19
18
|
!contentType.startsWith('application/x-www-form-urlencoded'))) {
|
|
19
|
+
context.formData = new FormData();
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
22
|
try {
|
|
@@ -26,6 +26,7 @@ export function formData(options) {
|
|
|
26
26
|
if (!suppressErrors || !(error instanceof FormDataParseError)) {
|
|
27
27
|
throw error;
|
|
28
28
|
}
|
|
29
|
+
context.formData = new FormData();
|
|
29
30
|
}
|
|
30
31
|
};
|
|
31
32
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remix-run/form-data-middleware",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Middleware for parsing FormData from request bodies",
|
|
5
5
|
"author": "Michael Jackson <mjijackson@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,13 +27,13 @@
|
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^24.6.0",
|
|
30
|
-
"typescript": "
|
|
31
|
-
"@remix-run/fetch-router": "0.
|
|
30
|
+
"@typescript/native-preview": "7.0.0-dev.20251125.1",
|
|
31
|
+
"@remix-run/fetch-router": "0.15.1",
|
|
32
32
|
"@remix-run/form-data-parser": "0.14.0"
|
|
33
33
|
},
|
|
34
|
-
"
|
|
35
|
-
"@remix-run/
|
|
36
|
-
"@remix-run/
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@remix-run/fetch-router": "^0.15.1",
|
|
36
|
+
"@remix-run/form-data-parser": "^0.14.0"
|
|
37
37
|
},
|
|
38
38
|
"keywords": [
|
|
39
39
|
"fetch",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"file-upload"
|
|
45
45
|
],
|
|
46
46
|
"scripts": {
|
|
47
|
-
"build": "
|
|
47
|
+
"build": "tsgo -p tsconfig.build.json",
|
|
48
48
|
"clean": "git clean -fdX",
|
|
49
|
-
"test": "node --disable-warning=ExperimentalWarning --test
|
|
50
|
-
"typecheck": "
|
|
49
|
+
"test": "node --disable-warning=ExperimentalWarning --test",
|
|
50
|
+
"typecheck": "tsgo --noEmit"
|
|
51
51
|
}
|
|
52
52
|
}
|
package/src/index.ts
CHANGED
package/src/lib/form-data.ts
CHANGED
|
@@ -4,12 +4,16 @@ import {
|
|
|
4
4
|
type FileUploadHandler,
|
|
5
5
|
type ParseFormDataOptions,
|
|
6
6
|
} from '@remix-run/form-data-parser'
|
|
7
|
+
import type { Middleware } from '@remix-run/fetch-router'
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Options for the `formData` middleware.
|
|
11
|
+
*/
|
|
10
12
|
export interface FormDataOptions extends ParseFormDataOptions {
|
|
11
13
|
/**
|
|
12
|
-
* Set `true` to suppress parse errors.
|
|
14
|
+
* Set `true` to suppress parse errors.
|
|
15
|
+
*
|
|
16
|
+
* @default false
|
|
13
17
|
*/
|
|
14
18
|
suppressErrors?: boolean
|
|
15
19
|
/**
|
|
@@ -22,6 +26,7 @@ export interface FormDataOptions extends ParseFormDataOptions {
|
|
|
22
26
|
|
|
23
27
|
/**
|
|
24
28
|
* Middleware that parses `FormData` from the request body and populates `context.formData`.
|
|
29
|
+
*
|
|
25
30
|
* @param options Options for parsing form data
|
|
26
31
|
* @returns A middleware function that parses form data
|
|
27
32
|
*/
|
|
@@ -29,21 +34,18 @@ export function formData(options?: FormDataOptions): Middleware {
|
|
|
29
34
|
let suppressErrors = options?.suppressErrors ?? false
|
|
30
35
|
let uploadHandler = options?.uploadHandler
|
|
31
36
|
|
|
32
|
-
return async (context
|
|
33
|
-
|
|
34
|
-
let method = context.method
|
|
35
|
-
|
|
36
|
-
if (method === 'GET' || method === 'HEAD') {
|
|
37
|
+
return async (context) => {
|
|
38
|
+
if (context.method === 'GET' || context.method === 'HEAD') {
|
|
37
39
|
return
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
let contentType = context.headers.get('Content-Type')
|
|
41
|
-
|
|
42
43
|
if (
|
|
43
44
|
contentType == null ||
|
|
44
45
|
(!contentType.startsWith('multipart/') &&
|
|
45
46
|
!contentType.startsWith('application/x-www-form-urlencoded'))
|
|
46
47
|
) {
|
|
48
|
+
context.formData = new FormData()
|
|
47
49
|
return
|
|
48
50
|
}
|
|
49
51
|
|
|
@@ -53,6 +55,8 @@ export function formData(options?: FormDataOptions): Middleware {
|
|
|
53
55
|
if (!suppressErrors || !(error instanceof FormDataParseError)) {
|
|
54
56
|
throw error
|
|
55
57
|
}
|
|
58
|
+
|
|
59
|
+
context.formData = new FormData()
|
|
56
60
|
}
|
|
57
61
|
}
|
|
58
62
|
}
|