diff --git a/packages/@jsonql/koa/package.json b/packages/@jsonql/koa/package.json index fd44dab46a3d4a67b26614413c5d8918286d3d1b..cc3a9dee2d5eaf242aef461d99296c6c051ffff7 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 0000000000000000000000000000000000000000..ffd30dc300c7126304283ea652d3b0ac8c3a28b5 --- /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 0000000000000000000000000000000000000000..8c764542450062bd24bcae5e23018cda6beb832d --- /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 0000000000000000000000000000000000000000..8c764542450062bd24bcae5e23018cda6beb832d --- /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 0000000000000000000000000000000000000000..3ffcb66f63df2d285f3fcc139f10b25bd4c82abf --- /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 0000000000000000000000000000000000000000..a8d8b5e038f50cdf4307c1cab09cecd5b6c2e0aa --- /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 0000000000000000000000000000000000000000..7b0c44aeafccab01195ac0454989d9eadd8fe7ed --- /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 0000000000000000000000000000000000000000..34f46f39163cc3add6e16386b398f0a027573e02 --- /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 + } + } +} diff --git a/packages/@jsonql/ws/package.json b/packages/@jsonql/ws/package.json index 7869863cd812d2d457f31050c9938684b600fdf2..2b1367d480d17be138f1a10b294c92cfca35d5e3 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", diff --git a/packages/contract-cli/package.json b/packages/contract-cli/package.json index d72ee11df222ace245b537c8e7e42da14c8f375e..2b865fa4c968c7d9323b9f9829531a50de601148 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/contract-cli/src/ast/acorn.js b/packages/contract-cli/src/ast/acorn.js index 9db5b4e80a71aae15e07c6d51f3ffb246930b2f9..0020ea1cc39cad9de0f67c221819fcf6cdd5905e 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 50eac4793213d67381390c40a877b1c4c808b753..45240bd55fdfe6277d04061e0efebc06c9ca5bd6 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 dc9a92686e5ed40b7a100cdebef7638f923c8f1a..c2d4e692a6675361e8a5aafa0f118208a12c7459 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 185ec717a973a03c10ffbdb1526d3ef5345eb7a8..86bf0297cb1ef68e6c18067e6302e105b5226201 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 02f9b6ea59cac69b8e2a923d263c34809adfe895..ad70dfc82ae480ca014378116817bb4b09468934 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 b56a246402be41c8e40fe027c3b7c01646f46999..d5a168c54781a7f698a1ec88cdc313f1acfcbaa2 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 9115dd0a1531ccacfe5b47332c7f22e9dc3786b8..62d60424f0a6bd4ac834b9b59bfae2dbc308bd14 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 66c483ea85122c29e26d4bce1f781a51b999ca37..d2b761264a48a5479cedec34a0dbb22abc4082a7 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 2ce632b774c0a300965f53dbe8ca54c7ba438141..4155acb2c04bf730b685546e81e7f655018f4dd7 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 4cf10b42ca5a2046ba269df41b38c5a6f8a22e6f..9be10899a987317b0de4e9c9e0fc28d05c583812 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 d237e20ba0a97360c43575aa7288b6bd3161a2aa..19c13fe5bff68a18d31dc382154c192ae7a6bdb8 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 828f6a43487f0df5a4c8e8905d787a14b20c0952..5a4b149c61dfa079e4e57a4c61593502762afc5b 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": { diff --git a/packages/node-client/tests/fixtures/jwt/contract.json b/packages/node-client/tests/fixtures/jwt/contract.json index b38181faf692b76eed5924eb3d710255c25ddb4f..cd53c3d74c14695a94b3d34ce24ce7b5deb42dec 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": {