From bfe0de231803d8c927d72508dc5a80dab3cecb68 Mon Sep 17 00:00:00 2001 From: joelchu Date: Wed, 25 Dec 2019 10:06:43 +0800 Subject: [PATCH 1/4] update the deps --- packages/@jsonql/ws/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@jsonql/ws/package.json b/packages/@jsonql/ws/package.json index 7869863c..2b1367d4 100644 --- a/packages/@jsonql/ws/package.json +++ b/packages/@jsonql/ws/package.json @@ -54,7 +54,7 @@ "fs-extra": "^8.1.0", "glob": "^7.1.6", "jsonql-contract": "^1.8.5", - "jsonql-koa": "^1.5.5", + "jsonql-koa": "^1.5.6", "jsonql-ws-server": "^1.5.2", "kefir": "^3.8.6", "koa": "^2.11.0", -- Gitee From 20e429dbd22e11a85fb157a85a72423f394a62ea Mon Sep 17 00:00:00 2001 From: joelchu Date: Wed, 25 Dec 2019 10:40:34 +0800 Subject: [PATCH 2/4] keep the generate contract for testing --- packages/@jsonql/koa/package.json | 8 +- .../contract/client1/public-contract.json | 255 +++++++++++++++ .../contract/client2/public-contract.json | 58 ++++ .../ms-a/client0/public-contract.json | 58 ++++ .../fixtures/contract/ms-a/contract.json | 291 ++++++++++++++++++ .../contract/ms-a/public-contract.json | 267 ++++++++++++++++ .../fixtures/contract/ms-b/contract.json | 56 ++++ .../contract/ms-b/public-contract.json | 62 ++++ 8 files changed, 1051 insertions(+), 4 deletions(-) create mode 100644 packages/@jsonql/koa/tests/fixtures/contract/client1/public-contract.json create mode 100644 packages/@jsonql/koa/tests/fixtures/contract/client2/public-contract.json create mode 100644 packages/@jsonql/koa/tests/fixtures/contract/ms-a/client0/public-contract.json create mode 100644 packages/@jsonql/koa/tests/fixtures/contract/ms-a/contract.json create mode 100644 packages/@jsonql/koa/tests/fixtures/contract/ms-a/public-contract.json create mode 100644 packages/@jsonql/koa/tests/fixtures/contract/ms-b/contract.json create mode 100644 packages/@jsonql/koa/tests/fixtures/contract/ms-b/public-contract.json diff --git a/packages/@jsonql/koa/package.json b/packages/@jsonql/koa/package.json index fd44dab4..cc3a9dee 100644 --- a/packages/@jsonql/koa/package.json +++ b/packages/@jsonql/koa/package.json @@ -33,7 +33,7 @@ "license": "MIT", "devDependencies": { "ava": "^2.4.0", - "nyc": "^14.1.1", + "nyc": "^15.0.0", "superkoa": "^1.0.3" }, "repository": { @@ -60,16 +60,16 @@ "debug": "^4.1.1", "fs-extra": "^8.1.0", "jsonql-constants": "^1.8.14", - "jsonql-koa": "^1.5.3", + "jsonql-koa": "^1.5.6", "jsonql-params-validator": "^1.5.2", - "jsonql-utils": "^0.9.3", + "jsonql-utils": "^0.9.7", "koa": "^2.11.0", "koa-bodyparser": "^4.2.1", "koa-cors": "0.0.16", "yargs": "^15.0.2" }, "optionalDependencies": { - "jsonql-ws-server": "^1.5.1" + "jsonql-ws-server": "^1.5.2" }, "bin": { "jsonql-koa-cli": "./cli.js" diff --git a/packages/@jsonql/koa/tests/fixtures/contract/client1/public-contract.json b/packages/@jsonql/koa/tests/fixtures/contract/client1/public-contract.json new file mode 100644 index 00000000..ffd30dc3 --- /dev/null +++ b/packages/@jsonql/koa/tests/fixtures/contract/client1/public-contract.json @@ -0,0 +1,255 @@ +{ + "query": { + "helloWorld": { + "params": [], + "returns": [ + { + "type": "string", + "description": "stock message" + } + ] + }, + "causeError": { + "params": [ + { + "type": [ + "any" + ], + "name": "x", + "description": "param" + } + ], + "returns": [ + { + "type": [ + "any" + ], + "description": "unknown" + } + ] + }, + "getSomething": { + "params": [], + "returns": [ + { + "type": [ + "object" + ], + "description": "an object contains two different time stamps" + } + ] + }, + "getUser": { + "params": [ + { + "type": [ + "string" + ], + "name": "args", + "variable": true, + "description": "passing unknown number of param" + } + ], + "returns": [ + { + "type": [ + "any" + ], + "description": "extract from last of the args" + } + ] + }, + "testList": { + "params": [ + { + "type": [ + "number" + ], + "name": "num", + "description": "a number" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "@TODO need to figure out how to give keys to the returns" + } + ] + } + }, + "mutation": { + "saveRemote": { + "params": [ + { + "type": [ + "object" + ], + "name": "payload", + "description": "something to save" + }, + { + "type": [ + "number" + ], + "name": "condition" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "with array of timestamp" + } + ] + }, + "updateList": { + "params": [ + { + "type": [ + "object" + ], + "name": "payload", + "keys": [ + { + "type": [ + "number" + ], + "name": "user", + "parent": "payload" + } + ] + }, + { + "type": [ + "object" + ], + "name": "condition" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "with user as key" + } + ] + } + }, + "auth": {}, + "timestamp": 1577240037, + "socket": { + "causeError": { + "params": [ + { + "type": [ + "string" + ], + "name": "msg", + "description": "a message" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "a message but here we throw an error" + } + ] + }, + "chatroom": { + "params": [ + { + "type": [ + "string" + ], + "name": "msg", + "description": "message" + }, + { + "type": [ + "number" + ], + "name": "timestamp", + "description": "for checking the time" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "reply" + } + ] + }, + "delayFn": { + "params": [ + { + "type": [ + "string" + ], + "name": "msg", + "description": "a message" + }, + { + "type": [ + "number" + ], + "name": "timestamp", + "description": "a timestamp" + } + ], + "returns": false + }, + "msPass": { + "params": [ + { + "type": [ + "string" + ], + "name": "msg", + "description": "an incoming message" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "contain everything and send it back" + } + ] + }, + "wsHandler": { + "params": [ + { + "type": [ + "string" + ], + "name": "msg", + "description": "message" + }, + { + "type": [ + "number" + ], + "name": "timestamp", + "description": "timestamp" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "msg + time lapsed" + } + ] + } + } +} diff --git a/packages/@jsonql/koa/tests/fixtures/contract/client2/public-contract.json b/packages/@jsonql/koa/tests/fixtures/contract/client2/public-contract.json new file mode 100644 index 00000000..8c764542 --- /dev/null +++ b/packages/@jsonql/koa/tests/fixtures/contract/client2/public-contract.json @@ -0,0 +1,58 @@ +{ + "query": { + "helloWorld": { + "params": [], + "returns": [ + { + "type": "string", + "description": "stock message" + } + ] + }, + "sendingOutSomething": { + "params": [], + "returns": [ + { + "type": [ + "string" + ], + "description": "a random message" + } + ] + } + }, + "mutation": { + "saveSomething": { + "params": [ + { + "type": [ + "object" + ], + "name": "payload" + }, + { + "type": [ + "number" + ], + "name": "condition" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "result" + } + ] + } + }, + "auth": {}, + "timestamp": 1577240037, + "socket": { + "giveNumber": { + "params": [], + "returns": false + } + } +} diff --git a/packages/@jsonql/koa/tests/fixtures/contract/ms-a/client0/public-contract.json b/packages/@jsonql/koa/tests/fixtures/contract/ms-a/client0/public-contract.json new file mode 100644 index 00000000..8c764542 --- /dev/null +++ b/packages/@jsonql/koa/tests/fixtures/contract/ms-a/client0/public-contract.json @@ -0,0 +1,58 @@ +{ + "query": { + "helloWorld": { + "params": [], + "returns": [ + { + "type": "string", + "description": "stock message" + } + ] + }, + "sendingOutSomething": { + "params": [], + "returns": [ + { + "type": [ + "string" + ], + "description": "a random message" + } + ] + } + }, + "mutation": { + "saveSomething": { + "params": [ + { + "type": [ + "object" + ], + "name": "payload" + }, + { + "type": [ + "number" + ], + "name": "condition" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "result" + } + ] + } + }, + "auth": {}, + "timestamp": 1577240037, + "socket": { + "giveNumber": { + "params": [], + "returns": false + } + } +} diff --git a/packages/@jsonql/koa/tests/fixtures/contract/ms-a/contract.json b/packages/@jsonql/koa/tests/fixtures/contract/ms-a/contract.json new file mode 100644 index 00000000..3ffcb66f --- /dev/null +++ b/packages/@jsonql/koa/tests/fixtures/contract/ms-a/contract.json @@ -0,0 +1,291 @@ +{ + "query": { + "causeError": { + "file": "/home/joel/projects/open-source/jsonql/packages/@jsonql/koa/tests/fixtures/resolvers/query/cause-error.js", + "description": false, + "params": [ + { + "type": [ + "any" + ], + "name": "x", + "description": "param" + } + ], + "returns": [ + { + "type": [ + "any" + ], + "description": "unknown" + } + ] + }, + "getSomething": { + "file": "/home/joel/projects/open-source/jsonql/packages/@jsonql/koa/tests/fixtures/resolvers/query/get-something.js", + "description": "just a pass over method to get something from server b", + "params": [], + "returns": [ + { + "type": [ + "object" + ], + "description": "an object contains two different time stamps" + } + ] + }, + "getUser": { + "file": "/home/joel/projects/open-source/jsonql/packages/@jsonql/koa/tests/fixtures/resolvers/query/get-user.js", + "description": "This use a spread as parameter", + "params": [ + { + "type": [ + "string" + ], + "name": "args", + "variable": true, + "description": "passing unknown number of param" + } + ], + "returns": [ + { + "type": [ + "any" + ], + "description": "extract from last of the args" + } + ] + }, + "testList": { + "file": "/home/joel/projects/open-source/jsonql/packages/@jsonql/koa/tests/fixtures/resolvers/query/test-list.js", + "description": false, + "params": [ + { + "type": [ + "number" + ], + "name": "num", + "description": "a number" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "@TODO need to figure out how to give keys to the returns" + } + ] + } + }, + "mutation": { + "saveRemote": { + "file": "/home/joel/projects/open-source/jsonql/packages/@jsonql/koa/tests/fixtures/resolvers/mutation/save-remote.js", + "description": "This will call the remote ms to save the result then modified it", + "params": [ + { + "type": [ + "object" + ], + "name": "payload", + "description": "something to save" + }, + { + "type": [ + "number" + ], + "name": "condition" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "with array of timestamp" + } + ] + }, + "updateList": { + "file": "/home/joel/projects/open-source/jsonql/packages/@jsonql/koa/tests/fixtures/resolvers/mutation/update-list.js", + "description": false, + "params": [ + { + "type": [ + "object" + ], + "name": "payload", + "keys": [ + { + "type": [ + "number" + ], + "name": "user", + "parent": "payload" + } + ] + }, + { + "type": [ + "object" + ], + "name": "condition" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "with user as key" + } + ] + } + }, + "auth": { + "login": { + "file": "/home/joel/projects/open-source/jsonql/packages/@jsonql/koa/tests/fixtures/resolvers/auth/login.js", + "description": "login method", + "params": [ + { + "type": [ + "string" + ], + "name": "name", + "description": "give it a name" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "a userdata object with timestamp" + } + ] + } + }, + "timestamp": 1577240037, + "sourceType": "script", + "socket": { + "causeError": { + "file": "/home/joel/projects/open-source/jsonql/packages/@jsonql/koa/tests/fixtures/resolvers/socket/cause-error.js", + "description": false, + "params": [ + { + "type": [ + "string" + ], + "name": "msg", + "description": "a message" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "a message but here we throw an error" + } + ] + }, + "chatroom": { + "file": "/home/joel/projects/open-source/jsonql/packages/@jsonql/koa/tests/fixtures/resolvers/socket/chatroom.js", + "description": false, + "params": [ + { + "type": [ + "string" + ], + "name": "msg", + "description": "message" + }, + { + "type": [ + "number" + ], + "name": "timestamp", + "description": "for checking the time" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "reply" + } + ] + }, + "delayFn": { + "file": "/home/joel/projects/open-source/jsonql/packages/@jsonql/koa/tests/fixtures/resolvers/socket/delay-fn.js", + "description": false, + "params": [ + { + "type": [ + "string" + ], + "name": "msg", + "description": "a message" + }, + { + "type": [ + "number" + ], + "name": "timestamp", + "description": "a timestamp" + } + ], + "returns": false + }, + "msPass": { + "file": "/home/joel/projects/open-source/jsonql/packages/@jsonql/koa/tests/fixtures/resolvers/socket/ms-pass.js", + "description": "just a pass over method to call server B", + "params": [ + { + "type": [ + "string" + ], + "name": "msg", + "description": "an incoming message" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "contain everything and send it back" + } + ] + }, + "wsHandler": { + "file": "/home/joel/projects/open-source/jsonql/packages/@jsonql/koa/tests/fixtures/resolvers/socket/ws-handler.js", + "description": "method just for testing the ws", + "params": [ + { + "type": [ + "string" + ], + "name": "msg", + "description": "message" + }, + { + "type": [ + "number" + ], + "name": "timestamp", + "description": "timestamp" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "msg + time lapsed" + } + ] + } + } +} diff --git a/packages/@jsonql/koa/tests/fixtures/contract/ms-a/public-contract.json b/packages/@jsonql/koa/tests/fixtures/contract/ms-a/public-contract.json new file mode 100644 index 00000000..a8d8b5e0 --- /dev/null +++ b/packages/@jsonql/koa/tests/fixtures/contract/ms-a/public-contract.json @@ -0,0 +1,267 @@ +{ + "query": { + "helloWorld": { + "description": "This is the stock resolver for testing purpose", + "params": [], + "returns": [ + { + "type": "string", + "description": "stock message" + } + ] + }, + "causeError": { + "description": false, + "params": [ + { + "type": [ + "any" + ], + "name": "x", + "description": "param" + } + ], + "returns": [ + { + "type": [ + "any" + ], + "description": "unknown" + } + ] + }, + "getSomething": { + "description": "just a pass over method to get something from server b", + "params": [], + "returns": [ + { + "type": [ + "object" + ], + "description": "an object contains two different time stamps" + } + ] + }, + "getUser": { + "description": "This use a spread as parameter", + "params": [ + { + "type": [ + "string" + ], + "name": "args", + "variable": true, + "description": "passing unknown number of param" + } + ], + "returns": [ + { + "type": [ + "any" + ], + "description": "extract from last of the args" + } + ] + }, + "testList": { + "description": false, + "params": [ + { + "type": [ + "number" + ], + "name": "num", + "description": "a number" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "@TODO need to figure out how to give keys to the returns" + } + ] + } + }, + "mutation": { + "saveRemote": { + "description": "This will call the remote ms to save the result then modified it", + "params": [ + { + "type": [ + "object" + ], + "name": "payload", + "description": "something to save" + }, + { + "type": [ + "number" + ], + "name": "condition" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "with array of timestamp" + } + ] + }, + "updateList": { + "description": false, + "params": [ + { + "type": [ + "object" + ], + "name": "payload", + "keys": [ + { + "type": [ + "number" + ], + "name": "user", + "parent": "payload" + } + ] + }, + { + "type": [ + "object" + ], + "name": "condition" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "with user as key" + } + ] + } + }, + "auth": {}, + "timestamp": 1577240037, + "socket": { + "causeError": { + "description": false, + "params": [ + { + "type": [ + "string" + ], + "name": "msg", + "description": "a message" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "a message but here we throw an error" + } + ] + }, + "chatroom": { + "description": false, + "params": [ + { + "type": [ + "string" + ], + "name": "msg", + "description": "message" + }, + { + "type": [ + "number" + ], + "name": "timestamp", + "description": "for checking the time" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "reply" + } + ] + }, + "delayFn": { + "description": false, + "params": [ + { + "type": [ + "string" + ], + "name": "msg", + "description": "a message" + }, + { + "type": [ + "number" + ], + "name": "timestamp", + "description": "a timestamp" + } + ], + "returns": false + }, + "msPass": { + "description": "just a pass over method to call server B", + "params": [ + { + "type": [ + "string" + ], + "name": "msg", + "description": "an incoming message" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "contain everything and send it back" + } + ] + }, + "wsHandler": { + "description": "method just for testing the ws", + "params": [ + { + "type": [ + "string" + ], + "name": "msg", + "description": "message" + }, + { + "type": [ + "number" + ], + "name": "timestamp", + "description": "timestamp" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "msg + time lapsed" + } + ] + } + } +} diff --git a/packages/@jsonql/koa/tests/fixtures/contract/ms-b/contract.json b/packages/@jsonql/koa/tests/fixtures/contract/ms-b/contract.json new file mode 100644 index 00000000..7b0c44ae --- /dev/null +++ b/packages/@jsonql/koa/tests/fixtures/contract/ms-b/contract.json @@ -0,0 +1,56 @@ +{ + "query": { + "sendingOutSomething": { + "file": "/home/joel/projects/open-source/jsonql/packages/@jsonql/koa/tests/fixtures/resolvers-ext/query/sending-out-something.js", + "description": "This is publicly available server whenever connect just send out a random message", + "params": [], + "returns": [ + { + "type": [ + "string" + ], + "description": "a random message" + } + ] + } + }, + "mutation": { + "saveSomething": { + "file": "/home/joel/projects/open-source/jsonql/packages/@jsonql/koa/tests/fixtures/resolvers-ext/mutation/save-something.js", + "description": "this is for a remote C server to call", + "params": [ + { + "type": [ + "object" + ], + "name": "payload" + }, + { + "type": [ + "number" + ], + "name": "condition" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "result" + } + ] + } + }, + "auth": {}, + "timestamp": 1577240037, + "sourceType": "script", + "socket": { + "giveNumber": { + "file": "/home/joel/projects/open-source/jsonql/packages/@jsonql/koa/tests/fixtures/resolvers-ext/socket/give-number.js", + "description": "This is the socket interface that is publicly available and whenever connect\nwill give you a timestamp", + "params": [], + "returns": false + } + } +} diff --git a/packages/@jsonql/koa/tests/fixtures/contract/ms-b/public-contract.json b/packages/@jsonql/koa/tests/fixtures/contract/ms-b/public-contract.json new file mode 100644 index 00000000..34f46f39 --- /dev/null +++ b/packages/@jsonql/koa/tests/fixtures/contract/ms-b/public-contract.json @@ -0,0 +1,62 @@ +{ + "query": { + "helloWorld": { + "description": "This is the stock resolver for testing purpose", + "params": [], + "returns": [ + { + "type": "string", + "description": "stock message" + } + ] + }, + "sendingOutSomething": { + "description": "This is publicly available server whenever connect just send out a random message", + "params": [], + "returns": [ + { + "type": [ + "string" + ], + "description": "a random message" + } + ] + } + }, + "mutation": { + "saveSomething": { + "description": "this is for a remote C server to call", + "params": [ + { + "type": [ + "object" + ], + "name": "payload" + }, + { + "type": [ + "number" + ], + "name": "condition" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "result" + } + ] + } + }, + "auth": {}, + "timestamp": 1577240037, + "socket": { + "giveNumber": { + "description": "This is the socket interface that is publicly available and whenever connect\nwill give you a timestamp", + "params": [], + "returns": false + } + } +} -- Gitee From 8a55f3bed2871c1e32e3b6916137357bf1fbf38c Mon Sep 17 00:00:00 2001 From: joelchu Date: Wed, 25 Dec 2019 10:50:46 +0800 Subject: [PATCH 3/4] clean up the coding style in the contract generator --- packages/contract-cli/src/ast/acorn.js | 8 +++--- packages/contract-cli/src/ast/jsdoc.js | 26 +++++++++---------- .../src/generator/generate-output.js | 5 ---- .../src/generator/get-resolver.js | 16 ++++++------ .../contract-cli/src/generator/helpers.js | 16 ++++++------ packages/contract-cli/src/generator/index.js | 6 ++--- packages/contract-cli/src/get-paths.js | 2 +- .../contract-cli/src/public-contract/index.js | 12 ++++----- packages/contract-cli/src/utils.js | 8 +++--- .../fixtures}/es-post-process.js | 2 +- packages/node-client/index.js | 8 +++--- packages/node-client/package.json | 2 +- 12 files changed, 53 insertions(+), 58 deletions(-) rename packages/contract-cli/{src/generator => tests/fixtures}/es-post-process.js (98%) diff --git a/packages/contract-cli/src/ast/acorn.js b/packages/contract-cli/src/ast/acorn.js index 9db5b4e8..0020ea1c 100644 --- a/packages/contract-cli/src/ast/acorn.js +++ b/packages/contract-cli/src/ast/acorn.js @@ -9,7 +9,7 @@ const { DEFAULT_TYPE } = require('jsonql-constants') * @return {boolean} true found */ function isExpression(tree) { - return tree.type === 'ExpressionStatement'; + return tree.type === 'ExpressionStatement' } /** @@ -38,7 +38,7 @@ function extractParams(tree) { }); } } - return false; + return false } /** @@ -47,7 +47,7 @@ function extractParams(tree) { * @return {object} cleaned object */ function processArgOutput(args) { - return args.type || DEFAULT_TYPE; + return args.type || DEFAULT_TYPE } /** @@ -65,7 +65,7 @@ function extractReturns(tree) { .filter(arg => arg.type === 'ReturnStatement') .map(arg => processArgOutput(arg.argument))) } catch (e) { - return false; + return false } } diff --git a/packages/contract-cli/src/ast/jsdoc.js b/packages/contract-cli/src/ast/jsdoc.js index 50eac479..45240bd5 100644 --- a/packages/contract-cli/src/ast/jsdoc.js +++ b/packages/contract-cli/src/ast/jsdoc.js @@ -36,24 +36,24 @@ const normalizeType = function(type) { } // normal check if (indexOf(SUPPORTED_TYPES, t) > -1) { - return t; + return t } // @TODO if they pass something like number[] string[] then we need special care // if its number? if (indexOf(NUMBER_TYPES, t) > -1) { - return NUMBER_TYPE; + return NUMBER_TYPE } // this is the Array type and we keep it if (t.indexOf('array.') > -1) { // debug('Array type here', t); // process the type within the array - const _type = t.replace(LFT,'').replace(RHT,''); + const _type = t.replace(LFT,'').replace(RHT,'') // call myself again - return LFT + normalizeType(_type) + RHT; + return LFT + normalizeType(_type) + RHT } // and finally if we couldn't figure it out then it will all be any type! - debug(`Raised a warning here, the ${type} / ${t} is unknown to use!`); - return DEFAULT_TYPE; + debug(`Raised a warning here, the ${type} / ${t} is unknown to use!`) + return DEFAULT_TYPE } /** @@ -70,7 +70,7 @@ const transformName = function(params) { p.name = names[1]; p.parent = names[0]; } - return p; + return p }) } @@ -97,21 +97,21 @@ const foldParams = function(params) { const children = getChildren(_params) // capture to validate if there is any children left const len = size(children) - let ctn = 0; + let ctn = 0 // @TODO here if we just reduce the array and it's done // but the problem is if there is an wrong comment with orphan // then this will cause a bug gone unnotice, so we need to check once again return params.filter(p => { - return !p.parent; + return !p.parent }).map(p => { if (children[p.name]) { ++ctn; p.keys = children[p.name] } - return p; + return p }) } - return params; + return params } /** @@ -140,7 +140,7 @@ const processParams = function(params) { } param.type = param.type.names.map(normalizeType) // pass through - return param; + return param }) } return false @@ -204,7 +204,7 @@ const searchForParams = function(output) { debug(`output`, detailOut(output)) return search(output, result.name) } - return result; + return result } /** diff --git a/packages/contract-cli/src/generator/generate-output.js b/packages/contract-cli/src/generator/generate-output.js index dc9a9268..c2d4e692 100644 --- a/packages/contract-cli/src/generator/generate-output.js +++ b/packages/contract-cli/src/generator/generate-output.js @@ -1,8 +1,6 @@ // the final step to generate output const { RETURN_AS_JSON } = require('jsonql-constants') const { keepOrCleanContract, isContractExisted, writeFileOut } = require('./files-op') -// @NOTE this is removed in v1.7.21 -// const { esPostProcess } = require('./es-post-process') const { mutateContract } = require('./helpers') const { join } = require('path') /** @@ -24,9 +22,6 @@ const generateOutput = function(sourceType, config, contract, rawData = false) { writeFileOut(dist, finalContract) .then(() => ( config.returnAs === RETURN_AS_JSON ? finalContract : dist - /* - esPostProcess(sourceType, resolverDir, rawData || contract) - .then(() => config.returnAs === RETURN_AS_JSON ? finalContract : dist) */ )) )) } diff --git a/packages/contract-cli/src/generator/get-resolver.js b/packages/contract-cli/src/generator/get-resolver.js index 185ec717..86bf0297 100644 --- a/packages/contract-cli/src/generator/get-resolver.js +++ b/packages/contract-cli/src/generator/get-resolver.js @@ -39,7 +39,7 @@ const sourceFileType = src => { } else if (source.indexOf('export default') > -1) { return MODULE_TYPE } - return false; + return false } /** @@ -70,10 +70,10 @@ function getSourceType(objs) { * @return {object} with {ok:true} to id that is a resolver */ const checkResolver = (indexFile, inDir, fileType, config) => (baseFile) => { - const failed = {ok: false}; + const failed = {ok: false} const fileParts = compact(baseFile.replace(inDir, '').toLowerCase().split('/')) - const ctn = fileParts.length; - const type = fileParts[0]; + const ctn = fileParts.length + const type = fileParts[0] // we ignore all the fileParts on the root level if (fileParts.length === 1) { return failed; @@ -101,8 +101,8 @@ const checkResolver = (indexFile, inDir, fileType, config) => (baseFile) => { if (inTypesArray(type) || isAuthType(type, fileName, config)) { let isPublic = checkIfIsPublic(fileParts, config) let isPrivate = checkIfIsPrivate(fileParts, config) - let lastFile = fileParts[ctn - 1]; - let ok = lastFile === indexFile; + let lastFile = fileParts[ctn - 1] + let ok = lastFile === indexFile let fileName3 = fileName; if (isPublic || isPrivate) { ok = true; @@ -116,7 +116,7 @@ const checkResolver = (indexFile, inDir, fileType, config) => (baseFile) => { return packOutput(type, fileName, true, baseFile, false, config) } default: - return failed; + return failed } } @@ -131,7 +131,7 @@ function getResolver(config, fileType) { // return a function here const fn = checkResolver(indexFile, config.resolverDir, fileType, config) // debug(fn.toString()) - return fn; + return fn } /** diff --git a/packages/contract-cli/src/generator/helpers.js b/packages/contract-cli/src/generator/helpers.js index 02f9b6ea..ad70dfc8 100644 --- a/packages/contract-cli/src/generator/helpers.js +++ b/packages/contract-cli/src/generator/helpers.js @@ -60,18 +60,18 @@ const isAuthType = function(type, file, config) { */ const addSocketProps = function(type, config, obj) { if (type === SOCKET_NAME && config.enableAuth) { - let nsp = `${JSONQL_PATH}/`; - let { publicMethodDir, privateMethodDir } = config; + let nsp = `${JSONQL_PATH}/` + let { publicMethodDir, privateMethodDir } = config let namespace; if (obj.public) { - namespace = nsp + publicMethodDir; + namespace = nsp + publicMethodDir } else { namespace = nsp + (privateMethodDir ? privateMethodDir : PRIVATE_KEY) } return extend(obj, { namespace }) } - return obj; + return obj } /** @@ -140,7 +140,7 @@ const takeDownArray = function(arr) { if (arr.length && arr.length === 1) { return takeDownArray(arr[0]) } - return arr; + return arr } /** @@ -151,10 +151,10 @@ const takeDownArray = function(arr) { * @return {object} mutation contract */ function mutateContract(config, contract) { - let extraContractProps = {}; + let extraContractProps = {} if (config.extraContractProps && isObject(config.extraContractProps)) { debug('merge with config.extraContractProps') - extraContractProps = config.extraContractProps; + extraContractProps = config.extraContractProps } return merge({}, contract, extraContractProps) } @@ -183,7 +183,7 @@ module.exports = { packOutput, takeDownArray, - + mutateContract, logToFile, diff --git a/packages/contract-cli/src/generator/index.js b/packages/contract-cli/src/generator/index.js index b56a2464..d5a168c5 100644 --- a/packages/contract-cli/src/generator/index.js +++ b/packages/contract-cli/src/generator/index.js @@ -17,7 +17,7 @@ const { readFilesOutContract } = require('./read-files-out-contract') const { generateOutput } = require('./generate-output') const { isContractExisted } = require('./files-op') -let ctn = 0; +let ctn = 0 /** * Show a message when run this program * @param {object} config input could be not clean @@ -33,9 +33,9 @@ const banner = config => { 'out: ', colors.green(`${config.contractDir}`), `[${config.returnAs} output] ${config.public ? '[public]': ''}` - ); + ) } - return ctn; + return ctn } /** diff --git a/packages/contract-cli/src/get-paths.js b/packages/contract-cli/src/get-paths.js index 9115dd0a..62d60424 100755 --- a/packages/contract-cli/src/get-paths.js +++ b/packages/contract-cli/src/get-paths.js @@ -33,7 +33,7 @@ function getPaths(argv) { } } rejecter('You need to provide the input path!') - }); + }) } /** diff --git a/packages/contract-cli/src/public-contract/index.js b/packages/contract-cli/src/public-contract/index.js index 66c483ea..d2b76126 100644 --- a/packages/contract-cli/src/public-contract/index.js +++ b/packages/contract-cli/src/public-contract/index.js @@ -21,7 +21,7 @@ const cleanForPublic = (json, config) => { } = config; for (let type in json) { for (let fn in json[type]) { - delete json[type][fn].file; + delete json[type][fn].file // @1.7.4 remove the description to reduce the size of the contract // @ 1.7.6 this function move to the Koa instead // because we want to keep the data in the file only remove it when serving up @@ -45,9 +45,9 @@ const cleanForPublic = (json, config) => { } // don't need this in the public json // debug(json.sourceType) - delete json.sourceType; + delete json.sourceType // export - return json; + return json } /** @@ -62,7 +62,7 @@ function getEnvContractFile(contractDir) { debug('found env contract') return fsx.readJsonSync(overwriteContractFile) } - return {}; + return {} } /** @@ -94,7 +94,7 @@ function publicContractGenerator(config, contractJson) { const baseContract = fsx.readJsonSync(join(__dirname, 'hello-world.json')) // env contract file - this should not get written to file // @TODO disable this feature for now and decide if we need it later - const extraContracts = {}; + const extraContracts = {} // const extraContracts = config.raw ? getEnvContractFile(contractDir) : {}; const expiredEntry = getExpired(config, contractJson) // export @@ -107,7 +107,7 @@ function publicContractGenerator(config, contractJson) { expiredEntry ), config - ); + ) } module.exports = { publicContractGenerator } diff --git a/packages/contract-cli/src/utils.js b/packages/contract-cli/src/utils.js index 2ce632b7..4155acb2 100644 --- a/packages/contract-cli/src/utils.js +++ b/packages/contract-cli/src/utils.js @@ -33,8 +33,8 @@ const checkForConfigFile = opts => { console.info(`Config file: ${cfile} could not be found!`) } } - return opts; -}; + return opts +} /** * break down the process from applyDefaultOptions @@ -62,7 +62,7 @@ const getConfigFromArgs = (config, cmd) => ( break; } } else { - result[key] = value; + result[key] = value } }, {}) ) @@ -104,7 +104,7 @@ const checkFile = config => { throw new JsonqlError('Contract json not in the correct format!') } } - return config; // now keep returning the config for next op + return config // now keep returning the config for next op } } diff --git a/packages/contract-cli/src/generator/es-post-process.js b/packages/contract-cli/tests/fixtures/es-post-process.js similarity index 98% rename from packages/contract-cli/src/generator/es-post-process.js rename to packages/contract-cli/tests/fixtures/es-post-process.js index 4cf10b42..9be10899 100644 --- a/packages/contract-cli/src/generator/es-post-process.js +++ b/packages/contract-cli/tests/fixtures/es-post-process.js @@ -17,7 +17,7 @@ const { const { getDebug } = require('../utils') const debug = getDebug('es-extra') -const IMPORT_JS_TEMPLATE = 'import.template.js'; +const IMPORT_JS_TEMPLATE = 'import.template.js' /** * Get the path to the file from the `files` key diff --git a/packages/node-client/index.js b/packages/node-client/index.js index d237e20b..19c13fe5 100755 --- a/packages/node-client/index.js +++ b/packages/node-client/index.js @@ -23,7 +23,7 @@ module.exports = function jsonqlNodeClient(config) { // @TODO remove once the socket client checked .then(opts => { debug('[jsonql-node-client] init opts', opts) - return opts; + return opts }) // start the init sequence .then(opts => ( @@ -47,7 +47,7 @@ module.exports = function jsonqlNodeClient(config) { ) ) // create the node client if any - .then(({opts, contract, client}) => { - return createSocketClient(client, opts, contract) - }) + .then(({opts, contract, client}) => ( + createSocketClient(client, opts, contract) + )) } diff --git a/packages/node-client/package.json b/packages/node-client/package.json index 828f6a43..5a4b149c 100755 --- a/packages/node-client/package.json +++ b/packages/node-client/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-node-client", - "version": "1.2.10", + "version": "1.2.11", "description": "jsonql node.js client with ws clients", "main": "index.js", "scripts": { -- Gitee From 32ba6ebd621947cc438f1fd6ace0185d44d25523 Mon Sep 17 00:00:00 2001 From: joelchu Date: Wed, 25 Dec 2019 10:52:48 +0800 Subject: [PATCH 4/4] jsonql-contract to 1.8.6 --- packages/contract-cli/package.json | 12 ++++++------ .../node-client/tests/fixtures/jwt/contract.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/contract-cli/package.json b/packages/contract-cli/package.json index d72ee11d..2b865fa4 100755 --- a/packages/contract-cli/package.json +++ b/packages/contract-cli/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-contract", - "version": "1.8.5", + "version": "1.8.6", "description": "JS API / command line tool to generate the contract.json for jsonql", "main": "index.js", "files": [ @@ -45,16 +45,16 @@ }, "dependencies": { "acorn": "^7.1.0", - "chokidar": "^3.3.0", + "chokidar": "^3.3.1", "colors": "^1.4.0", "debug": "^4.1.1", "fs-extra": "^8.1.0", "glob": "^7.1.6", "jsdoc-api": "^5.0.4", - "jsonql-constants": "^1.8.13", + "jsonql-constants": "^1.8.14", "jsonql-errors": "^1.1.10", - "jsonql-params-validator": "^1.5.1", - "jsonql-utils": "^0.9.2", + "jsonql-params-validator": "^1.5.2", + "jsonql-utils": "^0.9.7", "kefir": "^3.8.6", "lodash": "^4.17.15", "nb-split-tasks": "^0.6.0", @@ -62,7 +62,7 @@ }, "devDependencies": { "ava": "^2.4.0", - "nyc": "^14.1.1", + "nyc": "^15.0.0", "request": "^2.88.0" }, "ava": { diff --git a/packages/node-client/tests/fixtures/jwt/contract.json b/packages/node-client/tests/fixtures/jwt/contract.json index b38181fa..cd53c3d7 100644 --- a/packages/node-client/tests/fixtures/jwt/contract.json +++ b/packages/node-client/tests/fixtures/jwt/contract.json @@ -102,7 +102,7 @@ ] } }, - "timestamp": 1575882699, + "timestamp": 1577242325, "sourceType": "script", "socket": { "gateway": { -- Gitee