@fatcherjs/middleware-json 1.7.2 → 2.0.0

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
@@ -2,6 +2,12 @@
2
2
 
3
3
  A middleware for transform response to JSON
4
4
 
5
+ [![codecov](https://codecov.io/gh/fatcherjs/middleware-json/branch/master/graph/badge.svg?token=TFKUGW6YNI)](https://codecov.io/gh/fatcherjs/middleware-json)
6
+ [![install size](https://packagephobia.com/badge?p=@fatcherjs/middleware-json)](https://packagephobia.com/result?p=@fatcherjs/middleware-json)
7
+ <a href="https://unpkg.com/fatcher"><img alt="Size" src="https://img.badgesize.io/https://unpkg.com/fatcher"></a>
8
+ <a href="https://npmjs.com/package/@fatcherjs/middleware-json"><img src="https://img.shields.io/npm/v/@fatcherjs/middleware-json.svg" alt="npm package"></a>
9
+ <a href="https://github.com/fatcherjs/middleware-json/actions/workflows/ci.yml"><img src="https://github.com/fatcherjs/middleware-json/actions/workflows/ci.yml/badge.svg?branch=master" alt="build status"></a>
10
+
5
11
  ## Install
6
12
 
7
13
  ### NPM
@@ -25,7 +31,7 @@ import { fatcher } from 'fatcher';
25
31
  fatcher({
26
32
  url: '/bar/foo',
27
33
  middlewares: [json()],
28
- payload: {
34
+ body: {
29
35
  bar: 'foo',
30
36
  },
31
37
  })
package/dist/json.esm.js CHANGED
@@ -1,21 +1,18 @@
1
- import { canActivate } from 'fatcher';
1
+ import { defineMiddleware, canActivate } from 'fatcher';
2
2
 
3
3
  function json() {
4
- return {
5
- name: "fatcher-middleware-json",
6
- async use(context, next) {
7
- const result = await next();
8
- if (canActivate(result.data)) {
9
- const clonedResponse = result.data.clone();
10
- try {
11
- const data = await clonedResponse.json();
12
- return Object.assign(result, { data });
13
- } catch (e) {
14
- }
4
+ return defineMiddleware(async (context, next) => {
5
+ const result = await next();
6
+ if (canActivate(result.data)) {
7
+ const clonedResponse = result.data.clone();
8
+ try {
9
+ const data = await clonedResponse.json();
10
+ return Object.assign(result, { data });
11
+ } catch (e) {
15
12
  }
16
- return result;
17
13
  }
18
- };
14
+ return result;
15
+ }, "fatcher-middleware-json");
19
16
  }
20
17
 
21
18
  export { json };
package/dist/json.js CHANGED
@@ -5,21 +5,18 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var fatcher = require('fatcher');
6
6
 
7
7
  function json() {
8
- return {
9
- name: "fatcher-middleware-json",
10
- async use(context, next) {
11
- const result = await next();
12
- if (fatcher.canActivate(result.data)) {
13
- const clonedResponse = result.data.clone();
14
- try {
15
- const data = await clonedResponse.json();
16
- return Object.assign(result, { data });
17
- } catch (e) {
18
- }
8
+ return fatcher.defineMiddleware(async (context, next) => {
9
+ const result = await next();
10
+ if (fatcher.canActivate(result.data)) {
11
+ const clonedResponse = result.data.clone();
12
+ try {
13
+ const data = await clonedResponse.json();
14
+ return Object.assign(result, { data });
15
+ } catch (e) {
19
16
  }
20
- return result;
21
17
  }
22
- };
18
+ return result;
19
+ }, "fatcher-middleware-json");
23
20
  }
24
21
 
25
22
  exports.json = json;
package/dist/json.min.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("fatcher")):typeof define=="function"&&define.amd?define(["exports","fatcher"],t):(e=typeof globalThis!="undefined"?globalThis:e||self,t(e.FatcherMiddlewareJson={},e.Fatcher))})(this,function(e,t){"use strict";function o(){return{name:"fatcher-middleware-json",async use(i,a){const n=await a();if(t.canActivate(n.data)){const c=n.data.clone();try{const s=await c.json();return Object.assign(n,{data:s})}catch(s){}}return n}}}e.json=o,Object.defineProperty(e,"__esModule",{value:!0})});
1
+ (function(e,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("fatcher")):typeof define=="function"&&define.amd?define(["exports","fatcher"],t):(e=typeof globalThis!="undefined"?globalThis:e||self,t(e.FatcherMiddlewareJson={},e.Fatcher))})(this,function(e,t){"use strict";function o(){return t.defineMiddleware(async(a,s)=>{const n=await s();if(t.canActivate(n.data)){const d=n.data.clone();try{const i=await d.json();return Object.assign(n,{data:i})}catch(i){}}return n},"fatcher-middleware-json")}e.json=o,Object.defineProperty(e,"__esModule",{value:!0})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fatcherjs/middleware-json",
3
- "version": "1.7.2",
3
+ "version": "2.0.0",
4
4
  "main": "dist/json.js",
5
5
  "module": "dist/json.esm.js",
6
6
  "browser": "dist/json.min.js",
@@ -15,17 +15,41 @@
15
15
  "files": [
16
16
  "dist"
17
17
  ],
18
- "homepage": "https://github.com/fatcherjs/fatcher/tree/master/packages/json",
18
+ "homepage": "https://github.com/fatcherjs/middleware-json",
19
19
  "repository": {
20
20
  "type": "git",
21
- "url": "git+https://github.com/fatcherjs/fatcher.git"
21
+ "url": "git+https://github.com/fatcherjs/middleware-json"
22
22
  },
23
- "dependencies": {
24
- "fatcher": "^1.7.2"
23
+ "devDependencies": {
24
+ "@fansy/eslint-config": "^1.1.0",
25
+ "@fansy/prettier-config": "^1.0.0",
26
+ "@jest/types": "^29.1.2",
27
+ "@rollup/plugin-node-resolve": "^15.0.0",
28
+ "@types/jest": "^29.1.2",
29
+ "@types/node": "^18.11.2",
30
+ "esbuild": "^0.15.10",
31
+ "fatcher": "^2.0.0",
32
+ "jest": "^29.1.2",
33
+ "jest-fetch-mock": "^3.0.3",
34
+ "rimraf": "^3.0.2",
35
+ "rollup": "^2.79.1",
36
+ "rollup-plugin-dts": "^4.2.3",
37
+ "rollup-plugin-esbuild": "^4.10.1",
38
+ "ts-jest": "^29.0.3",
39
+ "ts-node": "^10.9.1",
40
+ "typescript": "^4.8.4"
41
+ },
42
+ "peerDependencies": {
43
+ "fatcher": "^2.0.0"
25
44
  },
26
45
  "scripts": {
27
46
  "dev": "rimraf dist && rollup -c rollup.config.ts -w",
28
47
  "build": "rimraf dist && rollup -c rollup.config.ts",
29
- "deploy": "pnpm run build && pnpm publish --no-git-check"
48
+ "deploy": "pnpm run build && pnpm publish --no-git-check",
49
+ "test": "jest",
50
+ "test:cov": "jest --coverage",
51
+ "eslint": "eslint .",
52
+ "tsc": "tsc --noEmit",
53
+ "ci": "npm run eslint && npm run tsc && npm run build && npm run test"
30
54
  }
31
55
  }