@remix-run/method-override-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.
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { Middleware } from '@remix-run/fetch-router';
|
|
2
|
+
/**
|
|
3
|
+
* Options for the `methodOverride` middleware.
|
|
4
|
+
*/
|
|
2
5
|
export interface MethodOverrideOptions {
|
|
3
6
|
/**
|
|
4
7
|
* The name of the form field to check for request method override.
|
|
5
|
-
*
|
|
8
|
+
*
|
|
9
|
+
* @default '_method'
|
|
6
10
|
*/
|
|
7
11
|
fieldName?: string;
|
|
8
12
|
}
|
|
@@ -12,7 +16,7 @@ export interface MethodOverrideOptions {
|
|
|
12
16
|
* Note: This middleware must be placed after the `formData` middleware in the middleware chain, or
|
|
13
17
|
* some other middleware that provides `context.formData`.
|
|
14
18
|
*
|
|
15
|
-
* @param options
|
|
19
|
+
* @param options Options for the method override middleware
|
|
16
20
|
* @returns A middleware that overrides `context.method` with the value of the method override field
|
|
17
21
|
*/
|
|
18
22
|
export declare function methodOverride(options?: MethodOverrideOptions): Middleware;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"method-override.d.ts","sourceRoot":"","sources":["../../src/lib/method-override.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"method-override.d.ts","sourceRoot":"","sources":["../../src/lib/method-override.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAiC,MAAM,yBAAyB,CAAA;AAExF;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,UAAU,CAe1E"}
|
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import { RequestMethods } from '@remix-run/fetch-router';
|
|
2
2
|
/**
|
|
3
3
|
* Middleware that overrides `context.method` with the value of the method override field.
|
|
4
4
|
*
|
|
5
5
|
* Note: This middleware must be placed after the `formData` middleware in the middleware chain, or
|
|
6
6
|
* some other middleware that provides `context.formData`.
|
|
7
7
|
*
|
|
8
|
-
* @param options
|
|
8
|
+
* @param options Options for the method override middleware
|
|
9
9
|
* @returns A middleware that overrides `context.method` with the value of the method override field
|
|
10
10
|
*/
|
|
11
11
|
export function methodOverride(options) {
|
|
12
12
|
let fieldName = options?.fieldName ?? '_method';
|
|
13
|
-
return
|
|
14
|
-
let
|
|
15
|
-
if (formData == null) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
let method = formData.get(fieldName);
|
|
13
|
+
return (context) => {
|
|
14
|
+
let method = context.formData?.get(fieldName);
|
|
19
15
|
if (typeof method !== 'string') {
|
|
20
16
|
return;
|
|
21
17
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remix-run/method-override-middleware",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Middleware for overriding HTTP request methods from form data",
|
|
5
5
|
"author": "Michael Jackson <mjijackson@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^24.6.0",
|
|
30
|
-
"typescript": "
|
|
31
|
-
"@remix-run/fetch-router": "0.
|
|
32
|
-
"@remix-run/form-data-middleware": "0.1.
|
|
30
|
+
"@typescript/native-preview": "7.0.0-dev.20251125.1",
|
|
31
|
+
"@remix-run/fetch-router": "0.15.1",
|
|
32
|
+
"@remix-run/form-data-middleware": "0.1.2"
|
|
33
33
|
},
|
|
34
|
-
"
|
|
35
|
-
"@remix-run/fetch-router": "^0.
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@remix-run/fetch-router": "^0.15.1"
|
|
36
36
|
},
|
|
37
37
|
"keywords": [
|
|
38
38
|
"fetch",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"http-method"
|
|
43
43
|
],
|
|
44
44
|
"scripts": {
|
|
45
|
-
"build": "
|
|
45
|
+
"build": "tsgo -p tsconfig.build.json",
|
|
46
46
|
"clean": "git clean -fdX",
|
|
47
|
-
"test": "node --disable-warning=ExperimentalWarning --test
|
|
48
|
-
"typecheck": "
|
|
47
|
+
"test": "node --disable-warning=ExperimentalWarning --test",
|
|
48
|
+
"typecheck": "tsgo --noEmit"
|
|
49
49
|
}
|
|
50
50
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,36 +1,32 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RequestMethods } from '@remix-run/fetch-router'
|
|
2
|
+
import type { Middleware, RequestContext, RequestMethod } from '@remix-run/fetch-router'
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Options for the `methodOverride` middleware.
|
|
6
|
+
*/
|
|
3
7
|
export interface MethodOverrideOptions {
|
|
4
8
|
/**
|
|
5
9
|
* The name of the form field to check for request method override.
|
|
6
|
-
*
|
|
10
|
+
*
|
|
11
|
+
* @default '_method'
|
|
7
12
|
*/
|
|
8
13
|
fieldName?: string
|
|
9
14
|
}
|
|
10
15
|
|
|
11
|
-
const RequestMethods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'] as const
|
|
12
|
-
|
|
13
|
-
type RequestMethod = (typeof RequestMethods)[number]
|
|
14
|
-
|
|
15
16
|
/**
|
|
16
17
|
* Middleware that overrides `context.method` with the value of the method override field.
|
|
17
18
|
*
|
|
18
19
|
* Note: This middleware must be placed after the `formData` middleware in the middleware chain, or
|
|
19
20
|
* some other middleware that provides `context.formData`.
|
|
20
21
|
*
|
|
21
|
-
* @param options
|
|
22
|
+
* @param options Options for the method override middleware
|
|
22
23
|
* @returns A middleware that overrides `context.method` with the value of the method override field
|
|
23
24
|
*/
|
|
24
25
|
export function methodOverride(options?: MethodOverrideOptions): Middleware {
|
|
25
26
|
let fieldName = options?.fieldName ?? '_method'
|
|
26
27
|
|
|
27
|
-
return
|
|
28
|
-
let
|
|
29
|
-
if (formData == null) {
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let method = formData.get(fieldName)
|
|
28
|
+
return (context: RequestContext) => {
|
|
29
|
+
let method = context.formData?.get(fieldName)
|
|
34
30
|
if (typeof method !== 'string') {
|
|
35
31
|
return
|
|
36
32
|
}
|