Skip to content

Commit

Permalink
chore(Flowtype): add check on test, fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nodkz committed May 23, 2018
1 parent 6684a93 commit 3c130b1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
5 changes: 4 additions & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[ignore]
<PROJECT_ROOT>/lib/.*
<PROJECT_ROOT>/es/.*
<PROJECT_ROOT>/node8/.*
<PROJECT_ROOT>/mjs/.*
.*/node_modules/ajv.*
.*/node_modules/acorn.*
.*/node_modules/async.*
Expand Down Expand Up @@ -37,4 +41,3 @@
[options]
esproposal.class_instance_fields=enable
suppress_comment= \\(.\\|\n\\)*\\$FlowFixMe
unsafe.enable_getters_and_setters=true
28 changes: 9 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -61,19 +51,19 @@
}
},
"jest": {
"roots": [
"<rootDir>/src"
]
"roots": ["<rootDir>/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"
}
}
2 changes: 1 addition & 1 deletion src/fetchWithMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function runFetch(req: RRNLRequestObject): Promise<RRNLResponseObject> {
}
}

return fetch(url, opts)
return fetch(url, (opts: any))
.then(res => {
if (res.status < 200 || res.status >= 300) {
return res.text().then(text => {
Expand Down
9 changes: 5 additions & 4 deletions src/middleware/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]];

Expand Down

0 comments on commit 3c130b1

Please sign in to comment.