From 38e06e54d90916ab0cb53aa9b78482755516f6bd Mon Sep 17 00:00:00 2001 From: joelchu Date: Fri, 8 Nov 2019 15:38:31 +0800 Subject: [PATCH 1/2] all existing test passed --- packages/koa/package.json | 2 +- packages/koa/tests/jwt-auth.test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/koa/package.json b/packages/koa/package.json index f396fd2f..4afe61fc 100644 --- a/packages/koa/package.json +++ b/packages/koa/package.json @@ -77,7 +77,7 @@ "jsonql-contract": "^1.8.4", "jsonql-errors": "^1.1.5", "jsonql-jwt": "^1.3.3", - "jsonql-node-client": "^1.2.0", + "jsonql-node-client": "^1.2.1", "jsonql-params-validator": "^1.4.11", "jsonql-resolver": "^0.9.4", "jsonql-utils": "^0.8.3", diff --git a/packages/koa/tests/jwt-auth.test.js b/packages/koa/tests/jwt-auth.test.js index 82919bd1..1525cc8b 100644 --- a/packages/koa/tests/jwt-auth.test.js +++ b/packages/koa/tests/jwt-auth.test.js @@ -13,7 +13,7 @@ const debug = require('debug')('jsonql-koa:test:jwt'); const { type, headers, dirs, dummy } = require('./fixtures/options'); const createServer = require('./helpers/server') -const dir = 'jwt'; +const dir = 'jwt-auth'; const keysDir = join(__dirname, 'fixtures', 'keys') const { createTokenValidator, loginResultToJwt } = require('jsonql-jwt') @@ -38,7 +38,7 @@ test.before( t => { test.after(t => { - fsx.removeSync(join(__dirname, 'fixtures', 'tmp', 'jwt')) + fsx.removeSync(join(__dirname, 'fixtures', 'tmp', dir)) // fsx.removeSync(join(__dirname, 'fixtures', 'tmp', '')) }) -- Gitee From 72838dd3a76ce062360a596780787cbb23058c24 Mon Sep 17 00:00:00 2001 From: joelchu Date: Fri, 8 Nov 2019 16:10:42 +0800 Subject: [PATCH 2/2] found the problem with the generator the eventEmitter fn should be outside of the auth --- packages/koa/contracts/public-contract.json | 192 ++++++++++++++++++++ packages/koa/package.json | 2 +- packages/node-client/package.json | 2 +- packages/node-client/src/generator.js | 6 +- 4 files changed, 197 insertions(+), 5 deletions(-) create mode 100644 packages/koa/contracts/public-contract.json diff --git a/packages/koa/contracts/public-contract.json b/packages/koa/contracts/public-contract.json new file mode 100644 index 00000000..08cb6fad --- /dev/null +++ b/packages/koa/contracts/public-contract.json @@ -0,0 +1,192 @@ +{ + "query": { + "helloWorld": { + "params": [], + "returns": [ + { + "type": "string", + "description": "stock message" + } + ] + }, + "causeError": { + "params": [ + { + "type": [ + "any" + ], + "name": "x", + "description": "param" + } + ], + "returns": [ + { + "type": [ + "any" + ], + "description": "unknown" + } + ] + }, + "getUser": { + "params": [ + { + "type": [ + "string" + ], + "name": "args", + "variable": true, + "description": "passing unknown number of param" + } + ], + "returns": [ + { + "type": [ + "any" + ], + "description": "extract from last of the args" + } + ] + }, + "getSecretMsg": { + "params": [], + "returns": [ + { + "type": [ + "string" + ], + "description": "a secret message" + } + ] + }, + "alwaysAvailable": { + "public": true, + "params": [], + "returns": [ + { + "type": [ + "string" + ], + "description": "a message" + } + ] + }, + "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": { + "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": { + "login": { + "params": [ + { + "type": [ + "string" + ], + "name": "username", + "description": "user name" + }, + { + "type": [ + "string" + ], + "name": "password", + "description": "password" + } + ], + "returns": [ + { + "type": [ + "string", + "boolean" + ], + "description": "token on success, false on fail" + } + ] + }, + "logout": { + "params": [], + "returns": [ + { + "type": [ + "boolean" + ], + "description": "just return something" + } + ] + } + }, + "timestamp": 1573116438, + "socket": { + "callSub": { + "namespace": "jsonql/private", + "params": [ + { + "type": [ + "string" + ], + "name": "msg", + "description": "a message" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "a reply from the sub" + } + ] + } + } +} diff --git a/packages/koa/package.json b/packages/koa/package.json index 4afe61fc..2acf5c68 100644 --- a/packages/koa/package.json +++ b/packages/koa/package.json @@ -57,7 +57,7 @@ "tests/*.test.js", "!tests/helpers/*.*", "!tests/fixtures/*.*", - "!tests/node-client.test.js" + "!tests/node-client.test.xyz.js" ], "require": [ "esm" diff --git a/packages/node-client/package.json b/packages/node-client/package.json index 2cc0f046..1a049a72 100755 --- a/packages/node-client/package.json +++ b/packages/node-client/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-node-client", - "version": "1.2.1", + "version": "1.2.2", "description": "jsonql node.js client", "main": "index.js", "scripts": { diff --git a/packages/node-client/src/generator.js b/packages/node-client/src/generator.js index 596c362a..516b7aba 100755 --- a/packages/node-client/src/generator.js +++ b/packages/node-client/src/generator.js @@ -108,15 +108,15 @@ function generator(jsonqlInstance, config, contract) { jsonqlInstance.logoutCallback() } } - // the eventEmitter getter - obj.eventEmitter = () => jsonqlInstance.eventEmitter // we have to make this into a function if I want to // need to create a getter method for it otherwise // it's straight through pass to the instance property obj.userdata = () => jsonqlInstance.userdata; } + // the eventEmitter getter - it should not be inside the auth! + obj.eventEmitter = () => jsonqlInstance.eventEmitter // store this once again and export it - obj.jsonqlClientInstance = jsonqlInstance; + obj.getJsonqlInstance = () => jsonqlInstance; // output return obj; } -- Gitee