diff --git a/packages/@jsonql/cli/README.md b/packages/@jsonql/cli/README.md new file mode 100644 index 0000000000000000000000000000000000000000..001c4de0af2a69374dc86c36e2c6adf58b922027 --- /dev/null +++ b/packages/@jsonql/cli/README.md @@ -0,0 +1,28 @@ +# @jsonql/cli + +This is an interactive command line client to setup project, +also comes with a command line interface to access a jsonql server. + +## Installation + +You **really should** install this globally: + +```sh +$ npm install --global @jsonql/cli +``` + +## jsonql + +This is the setup tool + +```sh +$ jsonql +``` + +## jsonql-cli + +This is the command line client + +```sh +$ jsonql-cli http://host-to-your-jsonql +``` diff --git a/packages/@jsonql/cli/client.js b/packages/@jsonql/cli/client.js new file mode 100644 index 0000000000000000000000000000000000000000..c86918e57b322438af57588231befe6ef0f1d5fc --- /dev/null +++ b/packages/@jsonql/cli/client.js @@ -0,0 +1 @@ +#!/bin/node diff --git a/packages/@jsonql/cli/index.js b/packages/@jsonql/cli/index.js new file mode 100644 index 0000000000000000000000000000000000000000..c86918e57b322438af57588231befe6ef0f1d5fc --- /dev/null +++ b/packages/@jsonql/cli/index.js @@ -0,0 +1 @@ +#!/bin/node diff --git a/packages/@jsonql/cli/package.json b/packages/@jsonql/cli/package.json index f0f1f26170745900ac52ab3cc71bb0cd892dbdac..eabe8c152d040420b7a44e86bb7795f993a4b143 100644 --- a/packages/@jsonql/cli/package.json +++ b/packages/@jsonql/cli/package.json @@ -1,7 +1,7 @@ { "name": "@jsonql/cli", "version": "0.1.0", - "description": "Interactive cli program to setup your jsonql dev environment", + "description": "Interactive cli program to setup your jsonql dev environment, and a command line client", "main": "index.js", "scripts": { "test": "ava" @@ -12,7 +12,11 @@ "interactive", "shell" ], - "homepage": "jsonql.org", - "author": "Joel Chu ", - "license": "ISC" + "homepage": "https://jsonql.org", + "author": "Joel Chu ", + "license": "UNLICENSED", + "bin": { + "jsonql": "./index.js", + "jsonql-cli": "./client.js" + } } diff --git a/packages/@jsonql/cli/init-dir.js b/packages/@jsonql/cli/src/init-dir.js similarity index 100% rename from packages/@jsonql/cli/init-dir.js rename to packages/@jsonql/cli/src/init-dir.js diff --git a/packages/@jsonql/client/package.json b/packages/@jsonql/client/package.json index e6a8a92b4fb3291e642c915124858ae782c691c7..889ea90e4a502fc51e92240a8ee39ebf3a9949d0 100644 --- a/packages/@jsonql/client/package.json +++ b/packages/@jsonql/client/package.json @@ -18,6 +18,7 @@ "test": "npm run build && npm run test:browser", "test:basic": "DEBUG=jsonql-client* ava ./tests/basic.test.js", "test:login": "DEBUG=jsonql-client* ava ./tests/login.test.js", + "test:vuex": "DEBUG=jsonql-client* ava ./tests/vuex.test.js", "_prepare": "NODE_ENV=production npm run build", "_publish": "npm publish --access public", "test:browser:ws": "npm run build:ws && npm run qunit", @@ -48,7 +49,7 @@ "license": "MIT", "dependencies": { "flyio": "^0.6.14", - "jsonql-client": "^1.5.21" + "jsonql-client": "^1.6.0" }, "optionalDependencies": { "@jsonql/ws": "^1.0.11" @@ -60,11 +61,11 @@ "debug": "^4.1.1", "esm": "^3.2.25", "glob": "^7.1.6", - "koa-favicon": "^2.0.1", + "koa-favicon": "^2.1.0", "nyc": "^15.0.0", "promise-polyfill": "8.1.3", "qunit": "^2.9.3", - "rollup": "^1.31.1", + "rollup": "^1.32.0", "rollup-plugin-alias": "^2.2.0", "rollup-plugin-analyzer": "^3.2.2", "rollup-plugin-async": "^1.2.0", @@ -78,7 +79,7 @@ "rollup-plugin-replace": "^2.2.0", "rollup-plugin-serve": "^1.0.1", "rollup-plugin-terser": "^5.2.0", - "server-io-core": "^1.2.0" + "server-io-core": "^1.3.1" }, "ava": { "files": [ diff --git a/packages/@jsonql/client/tests/vuex.test.js b/packages/@jsonql/client/tests/vuex.test.js new file mode 100644 index 0000000000000000000000000000000000000000..2c9692f2ddeda3fda28e9d247318c4d1b69fc72a --- /dev/null +++ b/packages/@jsonql/client/tests/vuex.test.js @@ -0,0 +1,21 @@ +// run a simple test to verify the options are correct or not +const test = require('ava') +const Fly = require("flyio/src/node") +const { join } = require('path') +const fsx = require('fs-extra') +const debug = require('debug')('jsonql-client:test:vuex') +const contract = fsx.readJsonSync(join(__dirname, 'fixtures', 'contract', 'public-contract.json')) +const config = { + contract, + hostname: 'http://localhost:3456' // just a dummy one +} +const { getJsonqlVuexModule, getActions } = require('../vue/vuex') + +test(`It should able to generate a Vuex store with the flat clients`, t => { + + const store = getActions({'query': {}, 'mutation': {}, 'auth': {}}, config) + + debug(store) + + t.truthy(store) +}) diff --git a/packages/@jsonql/client/vue/index.js b/packages/@jsonql/client/vue/index.js index 34e40d81b4b91b7fc79bf0dcc5b170e5419eddc2..63a6b7343f3d212cfea5f39a3f708b7a1ae403f1 100644 --- a/packages/@jsonql/client/vue/index.js +++ b/packages/@jsonql/client/vue/index.js @@ -1,8 +1,6 @@ // jsonql client for Vue and Vuex (TBC) how to do it import { getJsonqlVuexModule } from './vuex' - - export { getJsonqlVuexModule } diff --git a/packages/@jsonql/client/vue/vuex.js b/packages/@jsonql/client/vue/vuex.js index 0bac69c7366b2192271ea99e2b6029f2e16bab27..6efb315c9ae567724cafd0a7beab56c285c5f050 100644 --- a/packages/@jsonql/client/vue/vuex.js +++ b/packages/@jsonql/client/vue/vuex.js @@ -11,24 +11,25 @@ const ucword = str => ( /** * create actions on the fly - * @param {object} contract the contract object * @param {object} jsonqlClient static version - * @param {boolean} [prefix=true] add prefix or not + * @param {object} config the configuration object * @return {array} actions, names */ -function getActions(contract, jsonqlClient, prefix = false) { +function getActions(jsonqlClient, config) { + const { prefix, contract, namespaced } = config // could be undefined but we want false boolean const availableTypes = ['query', 'mutation', 'auth'] let actions = {} let names = {} for (let name in contract) { if (availableTypes.indexOf(name) > -1) { for (let resolverName in contract[name]) { - let actionName = prefix === false ? resolverName : name + ucword(resolverName) + let actionName = prefix === true ? name + ucword(resolverName) : resolverName // keep the name for export names[actionName] = null + let clientInstance = namespaced === true ? jsonqlClient[name] : jsonqlClient // define actions actions[actionName] = (ctx, ...args) => { - return Reflect.apply(jsonqlClient[name], jsonqlClient, [resolverName].concat(args)) + return Reflect.apply(clientInstance[resolverName], jsonqlClient, args) .then(result => { ctx.commit('addToResult', {name: actionName, result}) return result @@ -51,9 +52,8 @@ function getActions(contract, jsonqlClient, prefix = false) { * @return {object} the Vuex store object */ function getJsonqlVuexModule(Fly, config) { - const { prefix, contract } = config // could be undefined but we want false boolean const jsonqlClient = jsonqlStaticClient(Fly, config) - const [ actions, names ] = getActions(contract, jsonqlClient, prefix) + const [ actions, names ] = getActions(jsonqlClient, config) // just create the structure on the fly return { namespaced: true, @@ -69,7 +69,8 @@ function getJsonqlVuexModule(Fly, config) { state.error[name] = error } }, - // because jsonql are all async call, everything will be create as action + // because jsonql are all async call, + // every resolver will be warp in as action actions: actions, getters: { getJsonqlResult: (state) => (name) => { @@ -79,4 +80,4 @@ function getJsonqlVuexModule(Fly, config) { } } -export { getJsonqlVuexModule } +export { getJsonqlVuexModule, getActions } diff --git a/packages/@jsonql/koa/src/jsonql-koa-server.js b/packages/@jsonql/koa/src/jsonql-koa-server.js index 0a9b06795116e3175c921aef060249efef9844d8..ed4dec40af0063f2c1c3fbf53ee5548073b03b3e 100644 --- a/packages/@jsonql/koa/src/jsonql-koa-server.js +++ b/packages/@jsonql/koa/src/jsonql-koa-server.js @@ -28,7 +28,7 @@ class JsonqlKoaServer { // start the server start(port) { if (!this.started) { - console.info(`Server version: ${version} start on ${port || this.opts.port}`) + console.info(`[jsonql Koa server] version: ${version} start on ${port || this.opts.port}`) this.server.listen(port || this.opts.port) this.started = true } diff --git a/packages/koa/package.json b/packages/koa/package.json index 6c1f4359bbb62701db07ef46a2040b0a4f87a690..cd73b6c2886a87d48e266f1bca26b7599ca44a82 100644 --- a/packages/koa/package.json +++ b/packages/koa/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-koa", - "version": "1.5.7", + "version": "1.6.0", "description": "jsonql Koa middleware", "main": "main.js", "module": "index.js", diff --git a/packages/koa/src/options/options.js b/packages/koa/src/options/options.js index 995466455fa67c2914eb72f2de09182d81484ea8..828be09877d28e08d5e6e5629ee0a7fe7c46bcce 100644 --- a/packages/koa/src/options/options.js +++ b/packages/koa/src/options/options.js @@ -32,6 +32,7 @@ import { createConfig, constructConfig } from 'jsonql-params-validator' +const DEFAULT_APP_DIR = 'app' // const NodeCache from 'node-cache'); // const mcache = new NodeCache; // @BUG when we deploy it in docker, or using systemd the workingDirectory affect the @@ -54,6 +55,7 @@ const constProps = { const appProps = { name: createConfig('jsonql-koa', [STRING_TYPE]), // this is for ID which one is which when use as ms expired: createConfig(0, [NUMBER_TYPE]), + appDir: createConfig(join(dirname, DEFAULT_APP_DIR), [STRING_TYPE]), // allow user to change their auth type methods name loginHandlerName: createConfig(ISSUER_NAME, [STRING_TYPE]), logoutHandlerName: createConfig(LOGOUT_NAME, [STRING_TYPE]), diff --git a/packages/node-client/README.md b/packages/node-client/README.md index 863767d5bf5cbbcd05b60769e36582a6c28f4e46..40710bbdfc4057fd57c7715c54e58231de364fe9 100755 --- a/packages/node-client/README.md +++ b/packages/node-client/README.md @@ -1,11 +1,32 @@ [![NPM](https://nodei.co/npm/jsonql-node-client.png?compact=true)](https://npmjs.org/package/jsonql-node-client) -# json:ql node.js client +# jsonql node client This is the server to server client using node.js, all options identical to the browser client @jsonql/client +**BREAKING CHANGE IN 1.3.0** + +*We have add a `namespaced` option to the configuration, the default is `false` +It means, all your resolver no longer need to be `client.query` or `client.mutation`. +For using with socket client, it will still be under `client.socket` that is due to the way how its +constructed, and add to the client. + +If you pass `namespaced: true` then it will act exactly the same like before. Bear in mind, this option +will require you to have every single resolver to have a unique name, otherwise the name will get overwritten +by one another. Use it with caution.* + +## Installation + +```sh +$ npm i jsonql-node-client +``` + +You don't usually use this directly, this is part of the sub module for other jsonql modules. + --- -ISC [jsonql](http://jsonql.org) +Main website: [jsonql](http://jsonql.org) + +UNLICENSED -[NB](http://newbran.ch) & [T1S](http://to1source.cn) +[NEWBRAN LTD](http://newbran.ch) & [TO1SOURCE](http://to1source.cn) diff --git a/packages/node-client/package.json b/packages/node-client/package.json index 3edf2cadf481a50a799f23a51c956e201730bee2..fbea0dcd49faa6aa33038beabf0f7be06ce3bfc8 100755 --- a/packages/node-client/package.json +++ b/packages/node-client/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-node-client", - "version": "1.2.12", + "version": "1.3.0", "description": "jsonql node.js client with ws clients", "main": "index.js", "scripts": { @@ -14,7 +14,8 @@ "test:config": "DEBUG=jsonql-node-client* ava tests/config.test.js", "test:jwt": "DEBUG=jsonql-node-client*,jsonql-contract* ava tests/jwt.test.js", "test:socket": "DEBUG=jsonql-* ava --verbose tests/socket.test.js", - "test:ms": "DEBUG=jsonql-node-client:main,jsonql-koa:process-contract ava --verbose tests/ms.test.js" + "test:ms": "DEBUG=jsonql-node-client:main,jsonql-koa:process-contract ava --verbose tests/ms.test.js", + "start:debug": "DEBUG=jsonql-* node ./tests/fixtures/server-for-debug" }, "homepage": "jsonql.org", "repository": { @@ -41,6 +42,7 @@ ], "license": "MIT", "dependencies": { + "@to1source/request": "^0.9.4", "debug": "^4.1.1", "flyio": "^0.6.14", "fs-extra": "^8.1.0", @@ -50,19 +52,18 @@ "jsonql-params-validator": "^1.5.2", "jsonql-utils": "^0.9.7", "lodash.merge": "^4.6.2", - "node-cache": "^5.1.0", - "request": "^2.88.2" + "node-cache": "^5.1.0" }, "optionalDependencies": { "@jsonql/ws": "^1.0.11" }, "devDependencies": { - "ava": "^3.3.0", + "ava": "^3.5.0", "jsonql-contract": "^1.8.7", - "jsonql-koa": "^1.5.6", + "jsonql-koa": "^1.5.7", "jsonql-ws-server": "^1.5.3", "nyc": "^15.0.0", - "server-io-core": "^1.2.0", + "server-io-core": "^1.3.1", "superkoa": "^1.0.3" }, "ava": { diff --git a/packages/node-client/src/base/jsonql-base-cls.js b/packages/node-client/src/base/jsonql-base-cls.js index c01f57647c9eaaa147a9edd1d0a10bc3ead632b2..83fdbc1828f4829b2a12e7924eb75cf8faf9dc37 100755 --- a/packages/node-client/src/base/jsonql-base-cls.js +++ b/packages/node-client/src/base/jsonql-base-cls.js @@ -36,9 +36,9 @@ class JsonqlClient extends JsonqlCacheClass { get userdata() { if (this.opts.useJwt) { let token = this.__getAuthToken() - return token ? decodeToken(token) : false; + return token ? decodeToken(token) : false } - return false; + return false } /** @@ -59,26 +59,10 @@ class JsonqlClient extends JsonqlCacheClass { * @param {mixed} body from server with the data key */ __interceptor(payload, body) { - const result = typeof body === 'string' ? JSON.parse(body) : body; - const resolverName = Object.keys(payload)[0]; - // this could create a potential bug when some idiot name their - // resolver similar to their auth methods! - /* - const { loginHandlerName, logoutHandlerName } = this.opts; - switch (true) { - case loginHandlerName === resolverName: - debug(`intercept the ${loginHandlerName}`) - if (result.data) { - this.token = result.data; - } - break; - case logoutHandlerName === resolverName: - debug(`intercept the ${logoutHandlerName}`) - this.logout() - break; - } - */ - return result; + const result = typeof body === 'string' ? JSON.parse(body) : body + const resolverName = Object.keys(payload)[0] + + return result } /** @@ -90,16 +74,17 @@ class JsonqlClient extends JsonqlCacheClass { } /** + * @TODO need to change to use with our own new request method * @param {object} header to set * @return {object} combined header * @private */ __createHeaders(header = {}) { const authHeader = this.__getAuthHeader() - let _header = merge({}, this.baseHeader, header, authHeader) + let _header = merge({}, header, authHeader) debug('sending header', _header) - return _header; + return _header } /** @@ -178,4 +163,4 @@ class JsonqlClient extends JsonqlCacheClass { } // export -module.exports = JsonqlClient; +module.exports = JsonqlClient diff --git a/packages/node-client/src/base/request-client.js b/packages/node-client/src/base/request-client.js index 9c373a351d6c3895dbdd5f561e6691a1a0db718e..6e37fb18fa249c8eb35b1186bc0cbbdab24c2c06 100755 --- a/packages/node-client/src/base/request-client.js +++ b/packages/node-client/src/base/request-client.js @@ -1,13 +1,15 @@ /** * @1.3.0 replace request with flyio because request is deprecated */ -// const Fly = require("flyio/src/node") -const request = require('request') // too much work for now +const request = require('@to1source/request/jsonql') +const querystring = require('querystring') const fsx = require('fs-extra') const { createQuery, createMutation } = require('jsonql-utils') const { clientErrorsHandler } = require('jsonql-errors') + const { API_REQUEST_METHODS } = require('jsonql-constants') -const [ POST, PUT ] = API_REQUEST_METHODS; +const [ POST, PUT ] = API_REQUEST_METHODS + const { display, getDebug, resultHandler } = require('../utils') const JsonqlClient = require('./jsonql-base-cls') @@ -18,16 +20,17 @@ class JsonqlRequestClient extends JsonqlClient { constructor(config = {}) { super(config) - // this.request = new Fly() } - // just a wrapper + /** + * just a wrapper + */ getContract() { return this.__readContract().then(result => { if (typeof result === 'string') { return fsx.readJsonSync(result) } - return result; + return result }) } @@ -39,30 +42,19 @@ class JsonqlRequestClient extends JsonqlClient { */ __requestWrapper(method, payload, headers) { debug('sending payload', display(payload,1)) - return new Promise((resolver, rejecter) => { - try { - request({ - json: true, - url: this.__url__, - headers: this.__createHeaders(headers), - qs: this.__cacheBurst(), - method: method, - body: payload - }, (error, response, body) => { - if (error) { - debug('an error occured', display(error)) - return rejecter(error); - } - debug('result body %O', body) - const result = this.__interceptor(payload, body) - resolver(result) - }) - } catch(e) { - debug('error happens here!', e) - rejecter(e) - } - }) + const url = [this.__url__, querystring.stringify(this.__cacheBurst())].join('?') + const config = { method, headers: this.__createHeaders(headers) } + + return request.jsonql(url, payload, config) + .then(({result}) => { + debug('got result from request', result) + return this.__interceptor(payload, result) + }) + .catch(err => { + debug('Error happens here in request', err) + throw new Error(err) + }) } /** @@ -97,4 +89,4 @@ class JsonqlRequestClient extends JsonqlClient { } } -module.exports = JsonqlRequestClient; +module.exports = JsonqlRequestClient diff --git a/packages/node-client/src/create-socket-client.js b/packages/node-client/src/create-socket-client.js index eecc9bc52c15833d1883bc718daf9ce413ee06a7..0d6228971776f72df70aaac24939c05327f6ba6f 100644 --- a/packages/node-client/src/create-socket-client.js +++ b/packages/node-client/src/create-socket-client.js @@ -14,7 +14,7 @@ function getSocketClient(serverType) { switch (serverType) { case JS_WS_NAME: const jsonqlWsClient = require('@jsonql/ws/node') - return jsonqlWsClient; + return jsonqlWsClient case JS_WS_SOCKET_IO_NAME: case JS_PRIMUS_NAME: @@ -36,10 +36,10 @@ function getSocketClient(serverType) { */ function createSocketClient(client, config, contract) { try { - const { serverType } = config; - debug('config', config[CHECKED_KEY], config) - debug('serverType', serverType) + const { serverType } = config if (serverType) { + debug('config', config[CHECKED_KEY], config) + debug('serverType', serverType) let constProp = { // also need to pass the contract contract, diff --git a/packages/node-client/src/generator.js b/packages/node-client/src/generator.js index 8e1f0c40a0d6cf94471f93e1f9be1392f13673c5..0121db21fcf604becc56d1b4a31a80513d5eba78 100755 --- a/packages/node-client/src/generator.js +++ b/packages/node-client/src/generator.js @@ -46,14 +46,17 @@ function authMethodGenerator(jsonqlInstance, name, opts, contract) { * @return {object} constructed functions call */ function generator(jsonqlInstance, config, contract) { - let obj = {query: {}, mutation: {}, auth: {}}; + const { namespaced } = config + let queryObj = {} + let mutationObj = {} + let obj = {} // process the query first for (let queryFn in contract.query) { // to keep it clean we use a param to id the auth method // const fn = (_contract.query[queryFn].auth === true) ? 'auth' : queryFn; // generate the query method - obj.query[queryFn] = (...args) => { - const params = contract.query[queryFn].params; + queryObj[queryFn] = (...args) => { + const params = contract.query[queryFn].params const _args = params.map((param, i) => args[i]) debug('query', queryFn, _args) // the +1 parameter is the extra headers we want to pass @@ -71,7 +74,7 @@ function generator(jsonqlInstance, config, contract) { // there is only the payload, and conditions parameters // plus a header at the end for (let mutationFn in contract.mutation) { - obj.mutation[mutationFn] = (payload, conditions) => { + mutationObj[mutationFn] = (payload, conditions) => { const params = contract.mutation[mutationFn].params; const header = {}; return validateAsync([payload, conditions], params) @@ -111,16 +114,25 @@ function generator(jsonqlInstance, config, contract) { // 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; + obj.userdata = () => jsonqlInstance.userdata + } + if (namespaced === true) { + obj.query = queryObj + obj.mutation = mutationObj + } else { + obj = Object.assign(obj, queryObj, mutationObj) + } + + if (namespaced === true) { + // create an alias to the helloWorld make it easier for testing + obj.helloWorld = obj.query.helloWorld } - // create an alias to the helloWorld make it easier for testing - obj.helloWorld = obj.query.helloWorld; // the eventEmitter getter - it should not be inside the auth! obj.eventEmitter = () => jsonqlInstance.eventEmitter // store this once again and export it - obj.getJsonqlInstance = () => jsonqlInstance; + obj.getJsonqlInstance = () => jsonqlInstance // output - return obj; + return obj } // export module.exports = { diff --git a/packages/node-client/src/options/index.js b/packages/node-client/src/options/index.js index 71889f1fdc781526d6177a9f46115e1fe7c0bb5f..41f61fad624133b468926c494d24cb417464dd27 100755 --- a/packages/node-client/src/options/index.js +++ b/packages/node-client/src/options/index.js @@ -50,7 +50,8 @@ const appProps = { hostname: constructConfig('', STRING_TYPE), // required the hostname jsonqlPath: constructConfig(JSONQL_PATH, STRING_TYPE), // The path on the server - + // matching the browser client version + namespaced: createConfig(false, [BOOLEAN_TYPE]), useJwt: createConfig(true, [BOOLEAN_TYPE]), loginHandlerName: createConfig(ISSUER_NAME, [STRING_TYPE]), diff --git a/packages/node-client/tests/auth.test.js b/packages/node-client/tests/auth.test.js index 74fec7b88b72b5f4e64e56918746419e792810c6..afe235c7b60e95ee4aab4f02cf20af56b21ac32b 100755 --- a/packages/node-client/tests/auth.test.js +++ b/packages/node-client/tests/auth.test.js @@ -16,6 +16,7 @@ test.before(async (t) => { t.context.stop = stop; const client = await nodeClient({ + namespaced: true, hostname:'http://localhost:8889', enableAuth: true, contractDir, diff --git a/packages/node-client/tests/fixtures/server-for-debug.js b/packages/node-client/tests/fixtures/server-for-debug.js new file mode 100644 index 0000000000000000000000000000000000000000..5dcaf4adea01e4ecd04022298a9ba561ace3b97a --- /dev/null +++ b/packages/node-client/tests/fixtures/server-for-debug.js @@ -0,0 +1,3 @@ +const server = require('./server') + +server() diff --git a/packages/node-client/tests/jwt.test.js b/packages/node-client/tests/jwt.test.js index a85710e1c8007bc6ab525f0e8c56ffff5699aabb..7f1d9a85e7f901845aca1907d12cf333437b99ba 100644 --- a/packages/node-client/tests/jwt.test.js +++ b/packages/node-client/tests/jwt.test.js @@ -10,7 +10,7 @@ const { contractKey, users } = require('./fixtures/options') const contractDir = join(__dirname, 'fixtures', 'jwt') const keysDir = join(__dirname, 'fixtures', 'keys') const port = 8890; -const username = 'joel'; +const username = 'joel' test.before(async t => { // make sure the folder is clean @@ -28,6 +28,7 @@ test.before(async t => { t.context.stop = stop; const client = await nodeClient({ + namespaced: true, hostname:`http://localhost:${port}`, enableAuth: true, loginHandlerName: 'customLogin', diff --git a/packages/node-client/tests/main.test.js b/packages/node-client/tests/main.test.js index 749b778ed0e6c8455e80db8fcb4e91bd4fcacbda..d61d83d81b61e942f11250cd18507444c9616999 100755 --- a/packages/node-client/tests/main.test.js +++ b/packages/node-client/tests/main.test.js @@ -9,7 +9,7 @@ const debug = require('debug')('jsonql-node-client:test:main') test.before(async t => { // create server const { stop } = await server() - t.context.stop = stop; + t.context.stop = stop // create client t.context.client = await nodeClient({ @@ -35,9 +35,9 @@ test('Should able to say Hello world using the shorthand version!' , async t => t.is('Hello world!', result) }) -test(`It should able to access the mutation call`, async t => { +test(`It should able to access the mutation call using the new non-namspaced option`, async t => { - const result = await t.context.client.mutation.sendUser({name: 'Joel'}, {id: 1}) + const result = await t.context.client.sendUser({name: 'Joel'}, {id: 1}) t.truthy(result.timestamp) }) diff --git a/packages/node-client/tests/ms.test.js b/packages/node-client/tests/ms.test.js index a4e4253af7ca20ec8b559de7098c3ef3d542f7ae..5c4137e035899f2816f8b9ae4d6c17ce96636932 100644 --- a/packages/node-client/tests/ms.test.js +++ b/packages/node-client/tests/ms.test.js @@ -26,6 +26,7 @@ test.before(async t => { return app; }).then(app => { return client({ + namespaced: true, hostname: `${host}${portA}`, contractDir: join(baseDir, 'tmp', 'a', 'client') }) @@ -41,6 +42,7 @@ test.before(async t => { return app }).then(app => { return client({ + namespaced: true, hostname: `${host}${portB}`, contractDir: join(baseDir, 'tmp', 'b', 'client') }) diff --git a/packages/node-client/tests/socket.test.js b/packages/node-client/tests/socket.test.js index 7bb9f4ac97674c485b92c42b27289991624a44b6..44c2f563c25ae9bfafc2bcbc828bbdbd571eabf6 100644 --- a/packages/node-client/tests/socket.test.js +++ b/packages/node-client/tests/socket.test.js @@ -22,7 +22,7 @@ test.after(t => { }) test(`It should able to connect the server via http`, async t => { - const result = await t.context.client.query.helloWorld() + const result = await t.context.client.helloWorld() t.is('Hello world!', result) }) diff --git a/packages/node-client/tests/validation.test.js b/packages/node-client/tests/validation.test.js index 384980aef4d3f0a42fccd3669169118a4b294f55..ece07e1f1107d5a439b648f4cb53804d37cf2b53 100644 --- a/packages/node-client/tests/validation.test.js +++ b/packages/node-client/tests/validation.test.js @@ -30,7 +30,7 @@ test.after(t => { // we don't test the valid one because it require a backend to set up test.only('Should able to pass with correct params', async t => { const c = t.context.client; - const user = await c.query.getUser(1) + const user = await c.getUser(1) t.is('Davide', user) debug(typeof JsonqlValidationError) @@ -38,10 +38,10 @@ test.only('Should able to pass with correct params', async t => { }) test('Should failed and throw JsonqlValidationError', async t => { - const c = t.context.client; + const c = t.context.client const e = await t.throwsAsync( async () => { - return await c.query.getUser('1') - } , JsonqlValidationError, 'Expect to throw a JsonqlValidationError' ) + return await c.getUser('1') + } , /* JsonqlValidationError */ null, 'Expect to throw a JsonqlValidationError' ) // @BUG the one that throw from inside is not the same as the one I am passing here? // why? they are all from the same source t.is(e.className , 'JsonqlValidationError') @@ -52,10 +52,10 @@ test('Should failed and throw JsonqlValidationError', async t => { test("Pass an index larger than the database size to cause it throw application error", async t => { const c = t.context.client; const e = await t.throwsAsync( async () => { - return await c.query.getUser(100) + return await c.getUser(100) // @BUG it was expect to throw a JsonqlResolverAppError The detail show its correct but the one throw is JsonqlError - }, JsonqlResolverAppError, + }, /*JsonqlResolverAppError*/ null, 'We should able to get a JsonqlResolverAppError back') t.is(e.className, 'JsonqlResolverAppError') -}); +}) diff --git a/packages/utils/src/obj-define-props.js b/packages/utils/src/obj-define-props.js index 993f7ee95572ad8132b6cef3da8b702358ccc005..98d76e6375aaf22284ed0379466cb6f6515c3eb6 100644 --- a/packages/utils/src/obj-define-props.js +++ b/packages/utils/src/obj-define-props.js @@ -45,7 +45,7 @@ export function injectToFn(resolver, name, data, overwrite = false) { // console.info(`NOT INJECTED`) return resolver } - /* this will throw error! + /* this will throw error! @TODO how to remove props? if (overwrite === true && check !== undefined) { delete resolver[name] // delete this property }