@remix-run/method-override-middleware 0.1.7 → 0.1.9

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/README.md CHANGED
@@ -19,9 +19,9 @@ npm i remix
19
19
  This middleware runs after [the `formData` middleware](https://github.com/remix-run/remix/tree/main/packages/form-data-middleware) and updates the request context's `context.method` with the value of the method override field. This is useful for simulating RESTful API request methods like PUT and DELETE using HTML forms.
20
20
 
21
21
  ```ts
22
- import { createRouter } from 'remix/fetch-router'
23
- import { formData } from 'remix/form-data-middleware'
24
- import { methodOverride } from 'remix/method-override-middleware'
22
+ import { createRouter } from 'remix/router'
23
+ import { formData } from 'remix/middleware/form-data'
24
+ import { methodOverride } from 'remix/middleware/method-override'
25
25
 
26
26
  let router = createRouter({
27
27
  // methodOverride must come AFTER formData middleware
@@ -1 +1 @@
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;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,UAAU,CAe1E"}
1
+ {"version":3,"file":"method-override.d.ts","sourceRoot":"","sources":["../../src/lib/method-override.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,yBAAyB,CAAA;AAEzE;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,UAAU,CAe1E"}
@@ -1,4 +1,4 @@
1
- import { RequestMethods } from '@remix-run/fetch-router';
1
+ import { isRequestMethod } from '@remix-run/fetch-router';
2
2
  /**
3
3
  * Middleware that overrides `context.method` with the value of the method override field.
4
4
  *
@@ -12,12 +12,12 @@ import { RequestMethods } from '@remix-run/fetch-router';
12
12
  export function methodOverride(options) {
13
13
  let fieldName = options?.fieldName ?? '_method';
14
14
  return (context) => {
15
- let method = context.has(FormData) ? context.get(FormData).get(fieldName) : null;
15
+ let method = context.get(FormData)?.get(fieldName);
16
16
  if (typeof method !== 'string') {
17
17
  return;
18
18
  }
19
19
  let requestMethod = method.toUpperCase();
20
- if (RequestMethods.includes(requestMethod)) {
20
+ if (isRequestMethod(requestMethod)) {
21
21
  context.method = requestMethod;
22
22
  }
23
23
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix-run/method-override-middleware",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
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,13 +28,13 @@
28
28
  "devDependencies": {
29
29
  "@types/node": "^24.6.0",
30
30
  "@typescript/native-preview": "7.0.0-dev.20251125.1",
31
- "@remix-run/assert": "0.2.0",
32
- "@remix-run/form-data-middleware": "0.2.3",
33
- "@remix-run/test": "0.3.0",
34
- "@remix-run/fetch-router": "0.18.2"
31
+ "@remix-run/assert": "0.2.1",
32
+ "@remix-run/test": "0.4.1",
33
+ "@remix-run/fetch-router": "0.19.1",
34
+ "@remix-run/form-data-middleware": "0.3.1"
35
35
  },
36
36
  "dependencies": {
37
- "@remix-run/fetch-router": "^0.18.2"
37
+ "@remix-run/fetch-router": "^0.19.1"
38
38
  },
39
39
  "keywords": [
40
40
  "fetch",
@@ -1,5 +1,5 @@
1
- import { RequestMethods } from '@remix-run/fetch-router'
2
- import type { Middleware, RequestContext, RequestMethod } from '@remix-run/fetch-router'
1
+ import { isRequestMethod } from '@remix-run/fetch-router'
2
+ import type { Middleware, RequestContext } from '@remix-run/fetch-router'
3
3
 
4
4
  /**
5
5
  * Options for the {@link methodOverride} middleware.
@@ -27,14 +27,14 @@ export function methodOverride(options?: MethodOverrideOptions): Middleware {
27
27
  let fieldName = options?.fieldName ?? '_method'
28
28
 
29
29
  return (context: RequestContext) => {
30
- let method = context.has(FormData) ? context.get(FormData).get(fieldName) : null
30
+ let method = context.get(FormData)?.get(fieldName)
31
31
  if (typeof method !== 'string') {
32
32
  return
33
33
  }
34
34
 
35
- let requestMethod = method.toUpperCase() as RequestMethod
35
+ let requestMethod = method.toUpperCase()
36
36
 
37
- if (RequestMethods.includes(requestMethod)) {
37
+ if (isRequestMethod(requestMethod)) {
38
38
  context.method = requestMethod
39
39
  }
40
40
  }