From 3c130b13bce5a56dd957d1deabef426b9fa291af Mon Sep 17 00:00:00 2001 From: nodkz Date: Wed, 23 May 2018 17:34:10 +0600 Subject: [PATCH] chore(Flowtype): add check on test, fix errors --- .flowconfig | 5 ++++- package.json | 28 +++++++++------------------- src/fetchWithMiddleware.js | 2 +- src/middleware/batch.js | 9 +++++---- 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/.flowconfig b/.flowconfig index a044f78..ec5b56d 100644 --- a/.flowconfig +++ b/.flowconfig @@ -1,4 +1,8 @@ [ignore] +/lib/.* +/es/.* +/node8/.* +/mjs/.* .*/node_modules/ajv.* .*/node_modules/acorn.* .*/node_modules/async.* @@ -37,4 +41,3 @@ [options] esproposal.class_instance_fields=enable suppress_comment= \\(.\\|\n\\)*\\$FlowFixMe -unsafe.enable_getters_and_setters=true diff --git a/package.json b/package.json index 143648a..39ab65d 100644 --- a/package.json +++ b/package.json @@ -1,26 +1,16 @@ { "name": "react-relay-network-layer", "version": "0.0.0-semantically-released", - "description": "Network Layer for React Relay and Express (Batch Queries, AuthToken, Logging, Retry)", - "files": [ - "es", - "lib" - ], + "description": + "Network Layer for React Relay and Express (Batch Queries, AuthToken, Logging, Retry)", + "files": ["es", "lib"], "main": "lib/index.js", "jsnext:main": "es/index.js", "repository": { "type": "git", "url": "https://github.com/nodkz/react-relay-network-layer.git" }, - "keywords": [ - "relay", - "react", - "network layer", - "batch", - "express", - "jwt", - "auth token" - ], + "keywords": ["relay", "react", "network layer", "batch", "express", "jwt", "auth token"], "license": "MIT", "bugs": { "url": "https://github.com/nodkz/react-relay-network-layer/issues" @@ -61,19 +51,19 @@ } }, "jest": { - "roots": [ - "/src" - ] + "roots": ["/src"] }, "scripts": { "build": "npm run build-lib && npm run build-es && npm run build-flow", "build-lib": "rimraf lib && BABEL_ENV=lib babel src --ignore __tests__,__mocks__ -d lib", "build-es": "rimraf es && BABEL_ENV=es babel src --ignore __tests__,__mocks__ -d es", - "build-flow": "find ./src -name '*.js' -not -path '*/__*' | while read filepath; do cp $filepath `echo $filepath | sed 's/\\/src\\//\\/lib\\//g'`.flow; done", + "build-flow": + "find ./src -name '*.js' -not -path '*/__*' | while read filepath; do cp $filepath `echo $filepath | sed 's/\\/src\\//\\/lib\\//g'`.flow; done", "lint": "eslint src test *.js", "coverage": "jest --coverage --maxWorkers 2", "watch": "jest --watch", - "test": "npm run coverage && npm run lint", + "test": "npm run coverage && npm run lint && npm run flow", + "flow": "flow", "semantic-release": "semantic-release pre && npm publish && semantic-release post" } } diff --git a/src/fetchWithMiddleware.js b/src/fetchWithMiddleware.js index 67f1e01..67bf41d 100644 --- a/src/fetchWithMiddleware.js +++ b/src/fetchWithMiddleware.js @@ -20,7 +20,7 @@ function runFetch(req: RRNLRequestObject): Promise { } } - return fetch(url, opts) + return fetch(url, (opts: any)) .then(res => { if (res.status < 200 || res.status >= 300) { return res.text().then(text => { diff --git a/src/middleware/batch.js b/src/middleware/batch.js index 47c5cdd..23b63d8 100644 --- a/src/middleware/batch.js +++ b/src/middleware/batch.js @@ -174,17 +174,18 @@ function sendRequests(requestMap: BatchRequestMap, next, opts) { return next(req) .then(batchResponse => { - if (!batchResponse || !Array.isArray(batchResponse.payload)) { + const payload = batchResponse ? batchResponse.payload : null; + if (!Array.isArray(payload)) { throw new Error('Wrong response from server'); } - const responseHasIds: boolean = batchResponse.payload.every(response => response.id); - if (!responseHasIds && ids.length !== batchResponse.payload.length) { + const responseHasIds: boolean = payload.every(response => response.id); + if (!responseHasIds && ids.length !== payload.length) { throw new Error(`Server returned a different number of responses than requested. It's not possible to correlate requests and responses`); } - batchResponse.payload.forEach((res, i) => { + payload.forEach((res, i) => { if (!res) return; const request = responseHasIds ? requestMap[res.id] : requestMap[ids[i]];