diff --git a/packages/resolver/package.json b/packages/resolver/package.json index f32d102d1640e2e9675c000689803165e42566b2..a72a33e92c0694dcce0fdbecf40097ec589c8b61 100644 --- a/packages/resolver/package.json +++ b/packages/resolver/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-resolver", - "version": "1.0.9", + "version": "1.1.0", "description": "This is NOT for general use, please do not install it directly. This module is part of the jsonql tools supporting modules.", "main": "index.js", "files": [ @@ -8,12 +8,12 @@ "index.js" ], "scripts": { - "test": "ava --verbose", + "test": "ava", "prepare": "npm run test", - "test:base": "DEBUG=jsonql* ava --verbose ./tests/base.test.js", - "test:clients": "DEBUG=jsonql* ava --verbose ./tests/clients.test.js", - "test:throw": "DEBUG=jsonql-resolver* ava --verbose ./tests/throw.test.js", - "test:es": "DEBUG=jsonql-resolver* ava --verbose ./tests/es.test.js", + "test:base": "DEBUG=jsonql* ava ./tests/base.test.js", + "test:clients": "DEBUG=jsonql* ava ./tests/clients.test.js", + "test:throw": "DEBUG=jsonql-resolver* ava ./tests/throw.test.js", + "test:es": "DEBUG=jsonql-resolver* ava ./tests/es.test.js", "contract": "DEBUG=jsonql-contract* jsonql-contract create ./tests/fixtures/resolvers ./tests/fixtures/contract" }, "keywords": [ @@ -31,33 +31,30 @@ "jsonql-constants": "^1.8.14", "jsonql-errors": "^1.1.10", "jsonql-jwt": "^1.3.8", - "jsonql-node-client": "^1.2.10", + "jsonql-node-client": "^1.3.0", "jsonql-params-validator": "^1.5.2", "jsonql-utils": "^0.9.7", "lodash.merge": "^4.6.2" }, "devDependencies": { - "ava": "^2.4.0", - "jsonql-contract": "^1.8.6", - "jsonql-koa": "^1.5.6", - "server-io-core": "^1.2.0" + "ava": "^3.5.0", + "jsonql-contract": "^1.8.7", + "jsonql-koa": "^1.6.2", + "server-io-core": "^1.3.1" }, "ava": { "files": [ - "tests/**/*.test.js", - "!tests/fixtures/**/*.*" + "tests/**/*.test.js" ], - "sources": [ - "**/*.{js,jsx}", - "!dist/**/*" + "ignoredByWatcher": [ + "tests/fixtures/**/*.*" ], "cache": true, "concurrency": 5, "failFast": true, "failWithoutAssertions": false, "tap": false, - "verbose": true, - "compileEnhancements": false + "verbose": true }, "engine": { "node": ">=8" diff --git a/packages/resolver/src/client/validate-client-config.js b/packages/resolver/src/client/validate-client-config.js index 1558d2179bd65064449556d8f2520742a02fbc85..7328431e34de26d04cdf44024b3c40b68f391c2b 100644 --- a/packages/resolver/src/client/validate-client-config.js +++ b/packages/resolver/src/client/validate-client-config.js @@ -9,9 +9,9 @@ const debug = getDebug('validate-client-config') * @return {object|boolean} false when there is none, with additional properties */ const validateClientConfig = function(config) { - const ctn = config.clientConfig ? config.clientConfig.length : 0; + const ctn = config.clientConfig ? config.clientConfig.length : 0 // take the contractDir from the main - const contractDir = config.contractDir; + const contractDir = config.contractDir if (ctn) { let names = [] let clients = [] @@ -33,9 +33,9 @@ const validateClientConfig = function(config) { // push it back to the config clients.push(client) } - return clients; + return clients } - return false; + return false } module.exports = { validateClientConfig } diff --git a/packages/resolver/src/handle-auth-methods.js b/packages/resolver/src/handle-auth-methods.js index a451ac439e8531ee8631fb28217494f4de8b7d52..b897a9e5b6307cf082df6a3d30686314761e867b 100644 --- a/packages/resolver/src/handle-auth-methods.js +++ b/packages/resolver/src/handle-auth-methods.js @@ -1,16 +1,11 @@ // Auth methods handler const { - QUERY_NAME, - MUTATION_NAME, AUTH_TYPE, - LOGOUT_NAME, - ISSUER_NAME, QUERY_ARG_NAME, UNAUTHORIZED_STATUS } = require('jsonql-constants') const { JsonqlResolverNotFoundError, - JsonqlResolverAppError, JsonqlValidationError, JsonqlAuthorisationError, getErrorNameByInstance, @@ -31,10 +26,10 @@ const debug = getDebug('public-method-middleware') * @return {function} the correct handler */ const getLocalValidator = (config, contract) => { - const { validatorHandlerName } = config; + const { validatorHandlerName } = config // if you explicitly set it to false then it will be ignore if (!validatorHandlerName) { - return false; + return false } // @BUG when this searchResolvers throw error the next call can not use instanceof to check the Error? // @TODO there is no need to pass the type here, it will always be the AUTH_TYPE @@ -46,14 +41,16 @@ const getLocalValidator = (config, contract) => { * This is move from the auth middleware to handle the ISSUER_NAME and LOGOUT_NAME * They both are always publicly available * @param {object} ctx koa context - * @param {string} resolverName to call + * @param {string} resolverName to call --> TODO remove this? * @param {object} payload it send * @param {object} opts configuration * @param {object} contract to match against */ const handleAuthMethods = async function(ctx, resolverName, payload, opts, contract) { try { - const { loginHandlerName } = opts; + const { loginHandlerName } = opts + // @1.1.0 @TODO the resolverName can overwrite the stock name ? + // @TODO look at how to deal with the OAuth validation // @TODO here we intercept the result and add extra output if the useJwt is enabled const issuerFnPath = searchResolvers(loginHandlerName, AUTH_TYPE, opts, contract) const issuerFn = require(issuerFnPath) diff --git a/packages/resolver/src/search-resolvers.js b/packages/resolver/src/search-resolvers.js index 8f1221ddaa428aea798b0624b0451100f83e2cb5..777bfe3798cbb12a97cd114709b969d96dd25bf3 100644 --- a/packages/resolver/src/search-resolvers.js +++ b/packages/resolver/src/search-resolvers.js @@ -8,7 +8,7 @@ const { DEFAULT_RESOLVER_IMPORT_FILE_NAME } = require('jsonql-constants') const { getDebug } = require('./utils') const debug = getDebug('search-resolvers') -const prod = process.env.NODE_ENV === 'production'; +const prod = process.env.NODE_ENV === 'production' /** * @TODO we might have to change to the contract folder instead @@ -42,14 +42,14 @@ function requireEsModule(pathToResolver) { if (typeof obj === 'function') { return obj; } else if (obj.default && typeof obj.default === 'function') { - return obj.default; + return obj.default } throw new JsonqlError(`Unable to import ES module!`) } catch (e) { throw new JsonqlError(e) } finally { - // reset the require here? - require = oldRequire; // reset + // reset the require here + require = oldRequire } } @@ -66,18 +66,18 @@ function requireEsModule(pathToResolver) { */ function searchResolvers(name, type, opts, contract) { try { - const json = typeof contract === 'string' ? JSON.parse(contract) : contract; + const json = typeof contract === 'string' ? JSON.parse(contract) : contract let pathToResolver; pathToResolver = findFromContract(type, name, json) if (pathToResolver !== false) { - return pathToResolver; + return pathToResolver } debug(`pathToResolver not found in contract`, type, name, json) // search by running pathToResolver = getPathToFn(name, type, opts) if (pathToResolver) { - return pathToResolver; + return pathToResolver } const debugMsg = `${name} not found! [${opts.name}]` diff --git a/packages/resolver/src/validate-and-call.js b/packages/resolver/src/validate-and-call.js index 32b7f155fcce4dbedd0370f8439d60a6562eb5b3..69172a9842b5de96faebb7f90320a57e387765fa 100644 --- a/packages/resolver/src/validate-and-call.js +++ b/packages/resolver/src/validate-and-call.js @@ -22,8 +22,8 @@ const getEncodeJwtMethod = opts => { if (resultMethod && typeof resultMethod === 'function') { return resultMethod; } - let key = isString(opts.useJwt) ? opts.useJwt : opts.privateKey; - let alg = isString(opts.useJwt) ? HSA_ALGO : RSA_ALGO; + let key = isString(opts.useJwt) ? opts.useJwt : opts.privateKey + let alg = isString(opts.useJwt) ? HSA_ALGO : RSA_ALGO // add jwtTokenOption for the extra configuration for generate token return loginResultToJwt(key, opts.jwtTokenOption, alg) } diff --git a/packages/resolver/tests/base.test.js b/packages/resolver/tests/base.test.js index f48d18429429cd294f8929ddaebbd0d2f2382953..6b0757b7da2ace9daa36cbe3cbceb909753165c7 100644 --- a/packages/resolver/tests/base.test.js +++ b/packages/resolver/tests/base.test.js @@ -16,7 +16,7 @@ test.before(async t => { }) test(`It should able to call a resolver`, async t => { - const resolverName = 'getSomething'; + const resolverName = 'getSomething' const payload = createQuery(resolverName, ['Joel']) const result = await executeResolver( diff --git a/packages/resolver/tests/clients.test.js b/packages/resolver/tests/clients.test.js index d5c8d675bfe16a6b42cdbad4ef862e7fd8ab397e..0be5b949a099f6d0a9864011c767799d5cfe53fa 100644 --- a/packages/resolver/tests/clients.test.js +++ b/packages/resolver/tests/clients.test.js @@ -1,8 +1,8 @@ // this is for testing the inject client const test = require('ava') const { join } = require('path') -const nodeClient = require('jsonql-node-client') -const debug = require('debug')('jsonql-resolver:test:clients') +// const nodeClient = require('jsonql-node-client') +// const debug = require('debug')('jsonql-resolver:test:clients') const anotherServer = require('./fixtures/another-server') const { executeResolver } = require('../') const readJson = require('./fixtures/read-json') diff --git a/packages/resolver/tests/es.test.js b/packages/resolver/tests/es.test.js index 2602e859b271ade30d3ad77b4ef0c52d66a4d739..de8da991b54aabc247c3f6020470eb21da71118c 100644 --- a/packages/resolver/tests/es.test.js +++ b/packages/resolver/tests/es.test.js @@ -26,7 +26,7 @@ test.after(t => { // start testing test(`It should able to generate a contract for the es module`, t => { - const contract = t.context.contract; + const contract = t.context.contract debug(contract) diff --git a/packages/resolver/tests/fixtures/another-server.js b/packages/resolver/tests/fixtures/another-server.js index 13b109c845585c2238a94f19dc5070a2b3704652..82b3e9069db191dcfad14176104cc07b6ca02174 100644 --- a/packages/resolver/tests/fixtures/another-server.js +++ b/packages/resolver/tests/fixtures/another-server.js @@ -1,7 +1,6 @@ // this is the ms run on 8001 - const serverIoCore = require('server-io-core') -const { jsonqlKoa } = require('../../../koa') +const { jsonqlKoa } = require('jsonql-koa') const { join } = require('path') // export the return for use later module.exports = () => serverIoCore({ diff --git a/packages/resolver/tests/fixtures/contract/another/contract.json b/packages/resolver/tests/fixtures/contract/another/contract.json index f5c77d02f740d909b8ceb1ff71104cbbcaff0c0a..15710be98d80bd6ba1157e8d710cc5483f0e953a 100644 --- a/packages/resolver/tests/fixtures/contract/another/contract.json +++ b/packages/resolver/tests/fixtures/contract/another/contract.json @@ -99,6 +99,6 @@ }, "mutation": {}, "auth": {}, - "timestamp": 1576129069, + "timestamp": 1583285808, "sourceType": "script" } diff --git a/packages/resolver/tests/fixtures/contract/another/public-contract.json b/packages/resolver/tests/fixtures/contract/another/public-contract.json index baace634953d67b4ee7505bb7aeab74e8ca39671..41057d673502e6b4806ff0486d0f9fabd4e3507f 100644 --- a/packages/resolver/tests/fixtures/contract/another/public-contract.json +++ b/packages/resolver/tests/fixtures/contract/another/public-contract.json @@ -104,5 +104,5 @@ }, "mutation": {}, "auth": {}, - "timestamp": 1576129069 + "timestamp": 1583285808 } diff --git a/packages/resolver/tests/fixtures/contract/contract.json b/packages/resolver/tests/fixtures/contract/contract.json index 83a1e58a1b218a990bf84b5e1f7fb424d27ceb14..bcc5f3dbb48f559d43616b99a6575d7f26167cc0 100644 --- a/packages/resolver/tests/fixtures/contract/contract.json +++ b/packages/resolver/tests/fixtures/contract/contract.json @@ -99,6 +99,6 @@ }, "mutation": {}, "auth": {}, - "timestamp": 1576128195, + "timestamp": 1583286535, "sourceType": "script" } diff --git a/packages/resolver/tests/fixtures/contract/es/contract.json b/packages/resolver/tests/fixtures/contract/es/contract.json index b175add3af12178d5463a9d65b40adf36895d2ad..c56d8ecfdb3543c1fad04b9d2ab380010206cf43 100644 --- a/packages/resolver/tests/fixtures/contract/es/contract.json +++ b/packages/resolver/tests/fixtures/contract/es/contract.json @@ -43,6 +43,6 @@ } }, "auth": {}, - "timestamp": 1577247858, + "timestamp": 1583287348, "sourceType": "module" } diff --git a/packages/resolver/tests/fixtures/es/import.js b/packages/resolver/tests/fixtures/es/import.js deleted file mode 100644 index 6601f782c3497ae953db86928e4e6e922da04a10..0000000000000000000000000000000000000000 --- a/packages/resolver/tests/fixtures/es/import.js +++ /dev/null @@ -1,2 +0,0 @@ -require = require("esm")(module/*, options*/) -module.exports = require("./resolver.js") diff --git a/packages/resolver/tests/fixtures/es/resolver.js b/packages/resolver/tests/fixtures/es/resolver.js deleted file mode 100644 index 9057792d52c58f8bf7b6f1ff88ab9fbc7c4f3967..0000000000000000000000000000000000000000 --- a/packages/resolver/tests/fixtures/es/resolver.js +++ /dev/null @@ -1,7 +0,0 @@ -import querygetSomething from './query/get-something.js' -import mutationsaveSomething from './mutation/save-something.js' - -export { - querygetSomething, -mutationsaveSomething -} \ No newline at end of file diff --git a/packages/resolver/tests/fixtures/resolvers/query/call-ms-service.js b/packages/resolver/tests/fixtures/resolvers/query/call-ms-service.js index c415c064b7809133e65d2444060a34593fb292c1..f8c9ba627f1c22489763737657a9d81fc4ff0601 100644 --- a/packages/resolver/tests/fixtures/resolvers/query/call-ms-service.js +++ b/packages/resolver/tests/fixtures/resolvers/query/call-ms-service.js @@ -11,5 +11,5 @@ module.exports = async function callMsService(txt) { debug(client0) let txt0 = ['callMsService', txt].join(' ') - return await client0.query.anotherService(txt0) + return await client0.anotherService(txt0) } diff --git a/packages/resolver/tests/fixtures/resolvers/query/to-fail.js b/packages/resolver/tests/fixtures/resolvers/query/to-fail.js index 2a681edb106d57177c5cfd53c57c46a00d5fed16..764800ddf2672e4e6c0801506e583686d1002526 100644 --- a/packages/resolver/tests/fixtures/resolvers/query/to-fail.js +++ b/packages/resolver/tests/fixtures/resolvers/query/to-fail.js @@ -3,5 +3,5 @@ * @return {*} a variable that didn't exist */ module.exports = function toFail() { - return varNotExisted; + return varNotExisted } diff --git a/packages/resolver/tests/fixtures/rm.js b/packages/resolver/tests/fixtures/rm.js index f54298164691f5e87cd5ae52f2a69953ffecdebf..f94f2b418938a93ca46bc0ecf07b888873d344de 100644 --- a/packages/resolver/tests/fixtures/rm.js +++ b/packages/resolver/tests/fixtures/rm.js @@ -20,13 +20,13 @@ exports.rmdirs = async function rmdirs(dir) { exports.rmdirs = async function rmdirs(dir) { let entries = await readdir(dir, { withFileTypes: true }); let results = await Promise.all(entries.map(entry => { - let fullPath = path.join(dir, entry.name); + let fullPath = path.join(dir, entry.name) let task = entry.isDirectory() ? rmdirs(fullPath) : unlink(fullPath) return task.catch(error => ({ error })) })); results.forEach(result => { // Ignore missing files/directories; bail on other errors - if (result && result.error.code !== 'ENOENT') throw result.error; - }); + if (result && result.error.code !== 'ENOENT') throw result.error + }) await rmdir(dir) } diff --git a/packages/resolver/tests/throw.test.js b/packages/resolver/tests/throw.test.js index fa7c26a7d1844f893cd5684ca29635edbefbc30d..81efd8c0957ecf50aa935a72098e15ab73e7ed5a 100644 --- a/packages/resolver/tests/throw.test.js +++ b/packages/resolver/tests/throw.test.js @@ -6,8 +6,8 @@ const { JsonqlAuthorisationError, JsonqlValidationError, JsonqlResolverAppError, - getErrorNameByInstance, - UNKNOWN_ERROR + getErrorNameByInstance + // UNKNOWN_ERROR } = require('jsonql-errors') const { join } = require('path') @@ -53,7 +53,7 @@ test.cb(`When the resolver throw certain type of error, it should forward the sa test.cb(`When resolver throw error, it should able to throw back a JsonqlResolverAppError`, t => { t.plan(1) - const resolverName = 'toFail'; + const resolverName = 'toFail' const payload = createQuery(resolverName, []) executeResolver( @@ -85,8 +85,8 @@ test(`The getLocalValidator should throw a JsonqlResolverNotFoundError`, t => { return getLocalValidator({ validatorHandlerName: 'validator' }, t.context.contract) - }, JsonqlResolverNotFoundError, 'There is no validator and should throw error') - - // debug(error) - + }, /* JsonqlResolverNotFoundError*/ null, 'There is no validator and should throw error') + + // debug('', error) + t.is(error.className , 'JsonqlResolverNotFoundError') }) diff --git a/packages/ws-server-core/package.json b/packages/ws-server-core/package.json index cd04cd7639637f540dee314835bbdee634afdef6..9ca73e86f625c50248d31bb6a0d2579615f2d107 100644 --- a/packages/ws-server-core/package.json +++ b/packages/ws-server-core/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-ws-server-core", - "version": "0.4.1", + "version": "0.4.2", "description": "This is the core module that drive the Jsonql WS Socket server, not for direct use.", "main": "index.js", "files": [ @@ -59,10 +59,6 @@ "engine": { "node": ">=8" }, - "optionalDependencies": { - "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" - }, "repository": { "type": "git", "url": "git+ssh://git@gitee.com:to1source/jsonql.git"