@remix-run/method-override-middleware 0.1.0 → 0.1.1

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 +1 @@
1
- {"version":3,"file":"method-override.d.ts","sourceRoot":"","sources":["../../src/lib/method-override.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,yBAAyB,CAAA;AAEzE,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAMD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,UAAU,CAoB1E"}
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,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,UAAU,CAe1E"}
@@ -1,4 +1,4 @@
1
- const RequestMethods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'];
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
  *
@@ -11,11 +11,7 @@ const RequestMethods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTION
11
11
  export function methodOverride(options) {
12
12
  let fieldName = options?.fieldName ?? '_method';
13
13
  return async (context) => {
14
- let formData = context.formData;
15
- if (formData == null) {
16
- return;
17
- }
18
- let method = formData.get(fieldName);
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.0",
3
+ "version": "0.1.1",
4
4
  "description": "Middleware for overriding HTTP request methods from form data",
5
5
  "author": "Michael Jackson <mjijackson@gmail.com>",
6
6
  "license": "MIT",
@@ -28,11 +28,11 @@
28
28
  "devDependencies": {
29
29
  "@types/node": "^24.6.0",
30
30
  "typescript": "^5.9.3",
31
- "@remix-run/fetch-router": "0.9.0",
31
+ "@remix-run/fetch-router": "0.12.0",
32
32
  "@remix-run/form-data-middleware": "0.1.0"
33
33
  },
34
34
  "peerDependencies": {
35
- "@remix-run/fetch-router": "^0.9.0"
35
+ "@remix-run/fetch-router": "^0.12.0"
36
36
  },
37
37
  "keywords": [
38
38
  "fetch",
package/src/index.ts CHANGED
@@ -1,2 +1 @@
1
1
  export { type MethodOverrideOptions, methodOverride } from './lib/method-override.ts'
2
-
@@ -1,4 +1,5 @@
1
- import type { Middleware, RequestContext } from '@remix-run/fetch-router'
1
+ import { RequestMethods } from '@remix-run/fetch-router'
2
+ import type { Middleware, RequestContext, RequestMethod } from '@remix-run/fetch-router'
2
3
 
3
4
  export interface MethodOverrideOptions {
4
5
  /**
@@ -8,10 +9,6 @@ export interface MethodOverrideOptions {
8
9
  fieldName?: string
9
10
  }
10
11
 
11
- const RequestMethods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'] as const
12
-
13
- type RequestMethod = (typeof RequestMethods)[number]
14
-
15
12
  /**
16
13
  * Middleware that overrides `context.method` with the value of the method override field.
17
14
  *
@@ -25,12 +22,7 @@ export function methodOverride(options?: MethodOverrideOptions): Middleware {
25
22
  let fieldName = options?.fieldName ?? '_method'
26
23
 
27
24
  return async (context: RequestContext) => {
28
- let formData = context.formData
29
- if (formData == null) {
30
- return
31
- }
32
-
33
- let method = formData.get(fieldName)
25
+ let method = context.formData?.get(fieldName)
34
26
  if (typeof method !== 'string') {
35
27
  return
36
28
  }