From 18a81f37b2154236fba41995550667a48136e1ef Mon Sep 17 00:00:00 2001 From: joelchu Date: Fri, 6 Mar 2020 13:02:43 +0800 Subject: [PATCH 01/12] breaking up the ws-server-core options file into two --- packages/ws-server-core/package.json | 4 +- packages/ws-server-core/src/options/index.js | 85 +++---------------- packages/ws-server-core/src/options/props.js | 81 ++++++++++++++++++ .../ws-server-core/src/share/add-property.js | 18 +--- 4 files changed, 97 insertions(+), 91 deletions(-) create mode 100644 packages/ws-server-core/src/options/props.js diff --git a/packages/ws-server-core/package.json b/packages/ws-server-core/package.json index 9fe65801..dbf16e01 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.5.0", + "version": "0.6.0", "description": "This is the core module that drive the Jsonql WS Socket server, not for direct use.", "main": "index.js", "files": [ @@ -26,7 +26,7 @@ "debug": "^4.1.1", "esm": "^3.2.25", "fs-extra": "^8.1.0", - "jsonql-constants": "^1.9.1", + "jsonql-constants": "^1.9.4", "jsonql-errors": "^1.1.10", "jsonql-jwt": "^1.3.9", "jsonql-params-validator": "^1.5.2", diff --git a/packages/ws-server-core/src/options/index.js b/packages/ws-server-core/src/options/index.js index 985115d5..d3f5b2e9 100644 --- a/packages/ws-server-core/src/options/index.js +++ b/packages/ws-server-core/src/options/index.js @@ -1,91 +1,26 @@ // WS options +// methods const { join } = require('path') const fsx = require('fs-extra') const { JsonqlValidationError } = require('jsonql-errors') const { - createConfig, checkConfig, checkConfigAsync, isString } = require('jsonql-params-validator') +const { getContract } = require('../share/get-contract') +// properties const { - HSA_ALGO, - ENUM_KEY, - ALIAS_KEY, - PUBLIC_KEY, - PRIVATE_KEY, - STRING_TYPE, - BOOLEAN_TYPE, - NUMBER_TYPE, PEM_EXT, PUBLIC_KEY_NAME, - PRIVATE_KEY_NAME, - IO_HANDSHAKE_LOGIN, - IO_ROUNDTRIP_LOGIN, - DEFAULT_RESOLVER_DIR, - DEFAULT_CONTRACT_DIR, - DEFAULT_KEYS_DIR, - SOCKET_TYPE_KEY, - SOCKET_TYPE_SERVER_ALIAS + PRIVATE_KEY_NAME } = require('jsonql-constants') - -const { - SOCKET_IO, - SECRET_MISSING_ERR -} = require('./constants') -const { getContract } = require('../share/get-contract') - -// const { getDebug } = require('../share/helpers') -// const debug = getDebug('options') - -const dirname = process.cwd() - -// base options -const wsBaseOptions = { - appDir: createConfig('', [STRING_TYPE]), // just matching the Koa but not in use at the moment - // @TODO this will be moving out shortly after the test done - // RS256 this will need to figure out how to distribute the key - algorithm: createConfig(HSA_ALGO, [STRING_TYPE]), - authTimeout: createConfig(15000, [NUMBER_TYPE]), - // we require the contract already generated and pass here - // contract: createConfig({}, [OBJECT_TYPE]), this been causing no end of problem, we don't need it! - enableAuth: createConfig(false, [BOOLEAN_TYPE]), - // this option now is only for passing the key - // this cause a bug because this option is always BOOLEAN and STRING TYPE! - useJwt: createConfig(true, [STRING_TYPE, BOOLEAN_TYPE]), // need to double check this - // update this options to match the jsonql-koa 1.4.10 - resolverDir: createConfig(join(dirname, DEFAULT_RESOLVER_DIR), [STRING_TYPE]), - contractDir: createConfig(join(dirname, DEFAULT_CONTRACT_DIR), [STRING_TYPE]), - keysDir: createConfig(join(dirname, DEFAULT_KEYS_DIR), [STRING_TYPE]), - - // this is for construct the namespace - publicMethodDir: createConfig(PUBLIC_KEY, [STRING_TYPE]), - // just try this with string type first - privateMethodDir: createConfig(PRIVATE_KEY, [STRING_TYPE, BOOLEAN_TYPE]), - // we only want the keys directory then we read it back - // keysDir: createConfig(false, [STRING_TYPE]), - socketIoAuthType: createConfig(false, [STRING_TYPE], { - [ENUM_KEY]: [IO_HANDSHAKE_LOGIN, IO_ROUNDTRIP_LOGIN] - }) -} -// we have to create a standlone prop to check if the user pass the socket server config first -const socketAppProps = { - [SOCKET_TYPE_KEY]: createConfig(SOCKET_IO, [STRING_TYPE], { - [ALIAS_KEY]: SOCKET_TYPE_SERVER_ALIAS - }) -} - -// merge this together for use -const wsDefaultOptions = Object.assign(wsBaseOptions, socketAppProps) - -const wsConstProps = { - contract: false, - publicKey: false, - privateKey: false, - secret: false, - publicNamespace: PUBLIC_KEY, - privateNamespace: PRIVATE_KEY -} +const { SECRET_MISSING_ERR } = require('./constants') +const { + wsDefaultOptions, + wsConstProps, + socketAppProps +} = require('./props') /** * We need this to find the socket server type diff --git a/packages/ws-server-core/src/options/props.js b/packages/ws-server-core/src/options/props.js new file mode 100644 index 00000000..f35bde02 --- /dev/null +++ b/packages/ws-server-core/src/options/props.js @@ -0,0 +1,81 @@ +// break out from the index.js to keep property in one place +// and methods in another +const { join } = require('path') +const { createConfig } = require('jsonql-params-validator') +const { + HSA_ALGO, + ENUM_KEY, + ALIAS_KEY, + PUBLIC_KEY, + PRIVATE_KEY, + STRING_TYPE, + BOOLEAN_TYPE, + NUMBER_TYPE, + IO_HANDSHAKE_LOGIN, + IO_ROUNDTRIP_LOGIN, + DEFAULT_RESOLVER_DIR, + DEFAULT_CONTRACT_DIR, + DEFAULT_KEYS_DIR, + SOCKET_TYPE_KEY, + SOCKET_TYPE_SERVER_ALIAS +} = require('jsonql-constants') +const { SOCKET_IO } = require('./constants') + +// const { getDebug } = require('../share/helpers') +// const debug = getDebug('options') + +const dirname = process.cwd() + +// base options +const wsBaseOptions = { + appDir: createConfig('', [STRING_TYPE]), // just matching the Koa but not in use at the moment + // @TODO this will be moving out shortly after the test done + // RS256 this will need to figure out how to distribute the key + algorithm: createConfig(HSA_ALGO, [STRING_TYPE]), + authTimeout: createConfig(15000, [NUMBER_TYPE]), + // we require the contract already generated and pass here + // contract: createConfig({}, [OBJECT_TYPE]), this been causing no end of problem, we don't need it! + enableAuth: createConfig(false, [BOOLEAN_TYPE]), + // this option now is only for passing the key + // this cause a bug because this option is always BOOLEAN and STRING TYPE! + useJwt: createConfig(true, [STRING_TYPE, BOOLEAN_TYPE]), // need to double check this + // update this options to match the jsonql-koa 1.4.10 + resolverDir: createConfig(join(dirname, DEFAULT_RESOLVER_DIR), [STRING_TYPE]), + contractDir: createConfig(join(dirname, DEFAULT_CONTRACT_DIR), [STRING_TYPE]), + keysDir: createConfig(join(dirname, DEFAULT_KEYS_DIR), [STRING_TYPE]), + // @0.6.0 expect this to be the path to the interComEventHandler to handle the INTER_COM_EVENT_NAMES + interComEventHandler: createConfig(null, [STRING_TYPE]), + // this is for construct the namespace + publicMethodDir: createConfig(PUBLIC_KEY, [STRING_TYPE]), + // just try this with string type first + privateMethodDir: createConfig(PRIVATE_KEY, [STRING_TYPE, BOOLEAN_TYPE]), + // we only want the keys directory then we read it back + // keysDir: createConfig(false, [STRING_TYPE]), + socketIoAuthType: createConfig(false, [STRING_TYPE], { + [ENUM_KEY]: [IO_HANDSHAKE_LOGIN, IO_ROUNDTRIP_LOGIN] + }) +} +// we have to create a standlone prop to check if the user pass the socket server config first +const socketAppProps = { + [SOCKET_TYPE_KEY]: createConfig(SOCKET_IO, [STRING_TYPE], { + [ALIAS_KEY]: SOCKET_TYPE_SERVER_ALIAS + }) +} + +// merge this together for use +const wsDefaultOptions = Object.assign(wsBaseOptions, socketAppProps) + +const wsConstProps = { + contract: false, + publicKey: false, + privateKey: false, + secret: false, + publicNamespace: PUBLIC_KEY, + privateNamespace: PRIVATE_KEY +} + +module.exports = { + wsDefaultOptions, + wsConstProps, + socketAppProps +} \ No newline at end of file diff --git a/packages/ws-server-core/src/share/add-property.js b/packages/ws-server-core/src/share/add-property.js index 10394399..a4771bd0 100644 --- a/packages/ws-server-core/src/share/add-property.js +++ b/packages/ws-server-core/src/share/add-property.js @@ -1,8 +1,7 @@ // add required properties to the resolver const { EMIT_REPLY_TYPE, - SEND_MSG_PROP_NAME, - // ON_MESSAGE_PROP_NAME, + SEND_MSG_FN_NAME, JS_WS_NAME, INIT_CLIENT_PROP_KEY } = require('jsonql-constants') @@ -13,16 +12,6 @@ const { injectNodeClient } = require('jsonql-resolver') const { nil, createWsReply, getDebug } = require('../share/helpers') const debug = getDebug(`addProperty`) -/* -@TODO is this necessary? -resolver = addHandlerProperty(resolver, ON_MESSAGE_PROP_NAME, function(handler) { - if (handler && typeof handler === 'function') { - - } - throw new JsonqlError(resolverName, {message: `Require ${ON_MESSAGE_PROP_NAME} to be a function!`}) -}, nil) -*/ - /** * using the serverType to provide different addProperty method to this * change to return a promise on 1.4.4 @@ -38,8 +27,9 @@ const addProperty = (fn, resolverName, ws, userdata, opts) => { .resolve(injectToFn(fn, JS_WS_NAME, ws)) // define the send method .then(resolver => { - debug(`add ${SEND_MSG_PROP_NAME} to ${resolverName}`) - return objDefineProps(fn, SEND_MSG_PROP_NAME, function(prop) { + // @NOTE this will add a `send` function to this resolver + debug(`add ${SEND_MSG_FN_NAME} to ${resolverName}`) + return objDefineProps(resolver, SEND_MSG_FN_NAME, function(prop) { // @TODO should this get validate as well? ws.send(createWsReply(EMIT_REPLY_TYPE, resolverName, prop)) }, nil) -- Gitee From 1b3f345c30bb6732540218a91bfab957ece33137 Mon Sep 17 00:00:00 2001 From: joelchu Date: Fri, 6 Mar 2020 13:27:36 +0800 Subject: [PATCH 02/12] Adding the intercom handler method for the internal event handlers --- packages/ws-server-core/index.js | 51 ++--------------- packages/ws-server-core/src/core.js | 55 +++++++++++++++++++ packages/ws-server-core/src/index.js | 11 +++- packages/ws-server-core/src/options/props.js | 2 +- .../src/share/inter-com-handler.js | 46 ++++++++++++++++ 5 files changed, 117 insertions(+), 48 deletions(-) create mode 100644 packages/ws-server-core/src/core.js create mode 100644 packages/ws-server-core/src/share/inter-com-handler.js diff --git a/packages/ws-server-core/index.js b/packages/ws-server-core/index.js index 3e2d1943..97c977ff 100644 --- a/packages/ws-server-core/index.js +++ b/packages/ws-server-core/index.js @@ -1,15 +1,13 @@ // Not going to use the koa-socket-2 due to it's lack of support namespace // which is completely useless for us if there is no namespace -const { JsonqlError } = require('jsonql-errors') const { // rename them wsServerDefaultOptions, wsServerConstProps, // rest of the exports - initWsServerOption, checkSocketServerType, - wsServerCheckConfiguration - + jsonqlWsServerCoreAction, + jsonqlWsServerCore } = require('./src') // we also need to export all the share methods here because they will get use // in the respective external methods @@ -24,50 +22,11 @@ const { getUserdata } = require('./src/share/helpers') const { resolveMethod } = require('./src/share/resolve-method') - +const { createInterComEventHandler } = require('./src/share/inter-com-handler') const debug = getDebug('main') // also report the constants const jsonqlWsCoreConstants = require('./src/options/constants') -/** - * @0.4.0 we breaking up the config and init server in two fn - * Then when we need to combine with other modules, we only use the init - * Also there might be a chance that we need to merge the contract? - * @param {object} obj combine several properties in one - * @param {object} obj.opts checked configuration options - * @param {object} obj.server the http server instance - * @param {object} obj.wsCreateServer reverse passing the wsCreateServer fn from outter module - * @param {object} obj.wsSetup a pre start up function pass from outter module - * @return {promise} checked config - */ -function jsonqlWsServerCoreAction({opts, server, wsCreateServer, wsSetup}) { - - return initWsServerOption(opts) - .then(_opts => { - const nspObj = wsCreateServer(_opts, server) - return Reflect.apply(wsSetup, null, [_opts, nspObj]) - }) - .catch(err => { - console.error('Init jsonql Web Socket server error', err) - throw new JsonqlError('jsonqlWsServer', err) - }) -} - -/** - * This will take the two methods and return a method to generate the web socket server - * This is for standalone server type which unlikely to get use often - * @param {function} wsCreateServer generate the base server - * @param {function} wsSetup the method that bind the events - * @return {function} the method that accept the config and server instance to run - */ -function jsonqlWsServerCore(wsCreateServer, wsSetup) { - - return (config, server) => ( - wsServerCheckConfiguration(config) - .then(opts => ({ opts, server, wsCreateServer, wsSetup })) - .then(jsonqlWsServerCoreAction) - ) -} // export every bits out then the downstream build as they want module.exports = { @@ -91,5 +50,7 @@ module.exports = { jsonqlWsCoreConstants, // the actual methods that create the server jsonqlWsServerCore, - jsonqlWsServerCoreAction + jsonqlWsServerCoreAction, + // @0.6.0 + createInterComEventHandler } diff --git a/packages/ws-server-core/src/core.js b/packages/ws-server-core/src/core.js new file mode 100644 index 00000000..dbd0a8f7 --- /dev/null +++ b/packages/ws-server-core/src/core.js @@ -0,0 +1,55 @@ +// These methods were inside the index.js +// which make it hard to understand why it's there +// these are the core functionality for the other module +// to create the actual Web Socket Server +const { JsonqlError } = require('jsonql-errors') +const { + initWsServerOption, + wsServerCheckConfiguration +} = require('./options') + +/** + * @0.4.0 we breaking up the config and init server in two fn + * Then when we need to combine with other modules, we only use the init + * Also there might be a chance that we need to merge the contract? + * @param {object} obj combine several properties in one + * @param {object} obj.opts checked configuration options + * @param {object} obj.server the http server instance + * @param {object} obj.wsCreateServer reverse passing the wsCreateServer fn from outter module + * @param {object} obj.wsSetup a pre start up function pass from outter module + * @return {promise} checked config + */ +function jsonqlWsServerCoreAction({opts, server, wsCreateServer, wsSetup}) { + + return initWsServerOption(opts) + .then(_opts => { + const nspObj = wsCreateServer(_opts, server) + return Reflect.apply(wsSetup, null, [_opts, nspObj]) + }) + .catch(err => { + console.error('Init jsonql Web Socket server error', err) + throw new JsonqlError('jsonqlWsServer', err) + }) +} + + +/** + * This will take the two methods and return a method to generate the web socket server + * This is for standalone server type which unlikely to get use often + * @param {function} wsCreateServer generate the base server + * @param {function} wsSetup the method that bind the events + * @return {function} the method that accept the config and server instance to run + */ +function jsonqlWsServerCore(wsCreateServer, wsSetup) { + + return (config, server) => ( + wsServerCheckConfiguration(config) + .then(opts => ({ opts, server, wsCreateServer, wsSetup })) + .then(jsonqlWsServerCoreAction) + ) +} + +module.exports = { + jsonqlWsServerCoreAction, + jsonqlWsServerCore +} \ No newline at end of file diff --git a/packages/ws-server-core/src/index.js b/packages/ws-server-core/src/index.js index d9d56174..b5cdb138 100644 --- a/packages/ws-server-core/src/index.js +++ b/packages/ws-server-core/src/index.js @@ -6,6 +6,10 @@ const { wsDefaultOptions, wsConstProps } = require('./options') +const { + jsonqlWsServerCoreAction, + jsonqlWsServerCore +} = require('./core') // rename it before export const wsServerDefaultOptions = wsDefaultOptions const wsServerConstProps = wsConstProps @@ -15,7 +19,10 @@ module.exports = { wsServerDefaultOptions, wsServerConstProps, // rest of the exports - initWsServerOption, checkSocketServerType, - wsServerCheckConfiguration + initWsServerOption, + wsServerCheckConfiguration, + // the two top level core methods to create the websocket server + jsonqlWsServerCoreAction, + jsonqlWsServerCore } diff --git a/packages/ws-server-core/src/options/props.js b/packages/ws-server-core/src/options/props.js index f35bde02..8dd7d77e 100644 --- a/packages/ws-server-core/src/options/props.js +++ b/packages/ws-server-core/src/options/props.js @@ -44,7 +44,7 @@ const wsBaseOptions = { contractDir: createConfig(join(dirname, DEFAULT_CONTRACT_DIR), [STRING_TYPE]), keysDir: createConfig(join(dirname, DEFAULT_KEYS_DIR), [STRING_TYPE]), // @0.6.0 expect this to be the path to the interComEventHandler to handle the INTER_COM_EVENT_NAMES - interComEventHandler: createConfig(null, [STRING_TYPE]), + interComEventHandlerPath: createConfig(null, [STRING_TYPE]), // this is for construct the namespace publicMethodDir: createConfig(PUBLIC_KEY, [STRING_TYPE]), // just try this with string type first diff --git a/packages/ws-server-core/src/share/inter-com-handler.js b/packages/ws-server-core/src/share/inter-com-handler.js new file mode 100644 index 00000000..c13f966c --- /dev/null +++ b/packages/ws-server-core/src/share/inter-com-handler.js @@ -0,0 +1,46 @@ +const { + INTER_COM_EVENT_NAMES, + INTER_COM_EVENT_NAME +} = require('jsonql-constants') +const getDebug = require('./helpers') +const debug = getDebug('inter-com-handler') +const fsx = require('fs-extra') + +/** + * Find the intercom handler and return it + * @param {object} opts configuration + * @return {boolean|function} false on not found, or the actual function call + */ +function getHandler(opts) { + const { interComEventHandlerPath } = opts + // this is up to how the developer supply this option + if (interComEventHandlerPath !== null && fsx.existsSync(interComEventHandlerPath)) { + return require(interComEventHandlerPath) + } + // just return a dummy + return () => {} +} + +/** + * This will be the new intercom event handler + * we expect the user to pass an absolute path to the file that is + * going to handle this type of events + * then whenever it gets call, it will get take over by this function + * @param {object} opts the configuration + * @param {object} ee the event emitter + * + */ +function createInterComEventHandler(opts, ee) { + const handler = getHandler(opts) + // we first add our own handlers + INTER_COM_EVENT_NAMES.forEach(evtName => { + ee.$on(evtName, function interComHandler(...args) { + // just debug for the time being + debug(`Hear this ${evtName}`, args) + // also call the developer supply methods, add the eventName before the args + Reflect.apply(handler, null, [evtName].concat(args)) + }) + }) +} + +module.exports = { createInterComEventHandler } \ No newline at end of file -- Gitee From d5ad34b860078163fa3b93bb38a74e909d0f9ab9 Mon Sep 17 00:00:00 2001 From: joelchu Date: Fri, 6 Mar 2020 14:42:07 +0800 Subject: [PATCH 03/12] mark the todos --- packages/ws-server-core/src/share/inter-com-handler.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/ws-server-core/src/share/inter-com-handler.js b/packages/ws-server-core/src/share/inter-com-handler.js index c13f966c..2429c525 100644 --- a/packages/ws-server-core/src/share/inter-com-handler.js +++ b/packages/ws-server-core/src/share/inter-com-handler.js @@ -8,6 +8,9 @@ const fsx = require('fs-extra') /** * Find the intercom handler and return it + * OK since the two event disconnect and switch user are in fact user related + * Therefore we could put them under socket/auth folder also the socket related + * login / logout can also put in there. @TODO * @param {object} opts configuration * @return {boolean|function} false on not found, or the actual function call */ -- Gitee From 7c6065b40152bbedf1bad160c16b12955ca3508f Mon Sep 17 00:00:00 2001 From: joelchu Date: Fri, 6 Mar 2020 15:04:26 +0800 Subject: [PATCH 04/12] moving things around --- packages/ws-server/index.js | 38 ++++--------------- packages/ws-server/package.json | 2 +- packages/ws-server/src/core/modules.js | 28 ++++++++++++++ packages/ws-server/src/core/verify-client.js | 16 ++++---- .../ws-server/src/core/ws-create-server.js | 2 +- packages/ws-server/src/core/ws-setup.js | 4 +- packages/ws-server/src/index.js | 37 ++++++++++++++++-- 7 files changed, 83 insertions(+), 44 deletions(-) create mode 100644 packages/ws-server/src/core/modules.js diff --git a/packages/ws-server/index.js b/packages/ws-server/index.js index 20d45af8..5a0f1059 100644 --- a/packages/ws-server/index.js +++ b/packages/ws-server/index.js @@ -1,41 +1,17 @@ // Not going to use the koa-socket-2 due to it's lack of support namespace // which is completely useless for us if there is no namespace -const { wsSetup, wsCreateServer } = require('./src') const { checkSocketServerType, - jsonqlWsServerCore, - jsonqlWsServerCoreAction, + // props export wsServerDefaultOptions, wsServerConstProps -} = require('jsonql-ws-server-core') -// require('../ws-server-core') - -/** - * This is the method that is the actual create server without the config check - * @param {object} opts the already checked configuration - * @param {object} server the http server instance - * @return {object} the jsonql ws server instance - */ -function jsonqlWsServerAction(opts, server) { - const params = { opts, server, wsCreateServer, wsSetup } - return jsonqlWsServerCoreAction(params) -} - -/** - * The main method - * @param {object} config this is now diverse from the middleware setup - * @param {string} config.serverType socket.io or ws in the background - * @param {object} config.options the actual options to pass to the underlying setups - * @param {object} config.server this is the http/s server that required to bind to the socket to run on the same connection - * @return {mixed} return the undelying socket server instance for further use - */ -function jsonqlWsServer(config, server) { - // @TODO check the options - const setupFn = jsonqlWsServerCore(wsCreateServer, wsSetup) - return setupFn(config, server) -} +} = require('./src/core/modules') +const { + jsonqlWsServer, + jsonqlWsServerAction +} = require('./src') -// breaking change we export it as a name module +// breaking change @1.6.0 we export it as a name module module.exports = { jsonqlWsServer, jsonqlWsServerAction, diff --git a/packages/ws-server/package.json b/packages/ws-server/package.json index 6fca8078..5696df88 100755 --- a/packages/ws-server/package.json +++ b/packages/ws-server/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-ws-server", - "version": "1.6.2", + "version": "1.6.3", "description": "Setup WebSocket server for the jsonql to run on the same host, automatic generate public / private channel using contract", "main": "index.js", "files": [ diff --git a/packages/ws-server/src/core/modules.js b/packages/ws-server/src/core/modules.js new file mode 100644 index 00000000..68847fdb --- /dev/null +++ b/packages/ws-server/src/core/modules.js @@ -0,0 +1,28 @@ +// keep all the import from ws-server-core in one place +// for easy switching to debug +const { + checkSocketServerType, + jsonqlWsServerCore, + jsonqlWsServerCoreAction, + wsServerDefaultOptions, + wsServerConstProps, + getNamespace, + getDebug, + createWsReply, + getUserdata, + resolveMethod +} = require('jsonql-ws-server-core') +// require('../../../ws-server-core') + +module.exports = { + checkSocketServerType, + jsonqlWsServerCore, + jsonqlWsServerCoreAction, + wsServerDefaultOptions, + wsServerConstProps, + getNamespace, + getDebug, + createWsReply, + getUserdata, + resolveMethod +} \ No newline at end of file diff --git a/packages/ws-server/src/core/verify-client.js b/packages/ws-server/src/core/verify-client.js index df6051b8..5c994964 100644 --- a/packages/ws-server/src/core/verify-client.js +++ b/packages/ws-server/src/core/verify-client.js @@ -8,6 +8,15 @@ const { jwtDecode } = require('jsonql-jwt') const debug = require('debug')('jsonql-jwt:ws:verify-client') +/* +old method keep for reference +const params = query.split('&') +return params.filter(param => ( + param.indexOf(TOKEN_PARAM_NAME) > -1 + )) + .reduce((f, n) => n ? n.split('=')[1] : f, false) +*/ + /** * What the name said * @param {string} uri to decode @@ -20,13 +29,6 @@ function getTokenFromQuery(uri) { return params[TOKEN_PARAM_NAME] || false } return false - /* - const params = query.split('&') - return params.filter(param => ( - param.indexOf(TOKEN_PARAM_NAME) > -1 - )) - .reduce((f, n) => n ? n.split('=')[1] : f, false) - */ } /** diff --git a/packages/ws-server/src/core/ws-create-server.js b/packages/ws-server/src/core/ws-create-server.js index 74db01d4..aefa2dac 100644 --- a/packages/ws-server/src/core/ws-create-server.js +++ b/packages/ws-server/src/core/ws-create-server.js @@ -3,7 +3,7 @@ const url = require('url') const WebSocket = require('ws') // need to move the method back here const { createVerifyClient } = require('./verify-client') -const { getNamespace, getDebug } = require('jsonql-ws-server-core') +const { getNamespace, getDebug } = require('./modules') const debug = getDebug('ws-setup') /** diff --git a/packages/ws-server/src/core/ws-setup.js b/packages/ws-server/src/core/ws-setup.js index c4bd3d34..fde05297 100644 --- a/packages/ws-server/src/core/ws-setup.js +++ b/packages/ws-server/src/core/ws-setup.js @@ -14,7 +14,7 @@ const { createWsReply, getUserdata, resolveMethod -} = require('jsonql-ws-server-core') +} = require('./modules') const WS_EXIT_ID = 1 const debug = getDebug('ws-setup') @@ -121,6 +121,8 @@ const wsSetup = (opts, nspObj) => { if (resolverName === LOGOUT_EVT_NAME) { return handleLogout(ws) } + // @TODO add a bunch of other new inter comm methods here as well + // only allow the method under that particular namespace if (methodsInNsp[resolverName]) { debug('methodsInNsp[resolverName]', methodsInNsp[resolverName]) diff --git a/packages/ws-server/src/index.js b/packages/ws-server/src/index.js index b1fcdd75..5defcddf 100644 --- a/packages/ws-server/src/index.js +++ b/packages/ws-server/src/index.js @@ -1,8 +1,39 @@ // re-export here const { wsCreateServer } = require('./core/ws-create-server') const { wsSetup } = require('./core/ws-setup') -// re-export +// move back from the root index.js +const { + jsonqlWsServerCore, + jsonqlWsServerCoreAction +} = require('./core/modules') + +/** + * This is the method that is the actual create server without the config check + * @param {object} opts the already checked configuration + * @param {object} server the http server instance + * @return {object} the jsonql ws server instance + */ +function jsonqlWsServerAction(opts, server) { + const params = { opts, server, wsCreateServer, wsSetup } + return jsonqlWsServerCoreAction(params) +} + +/** + * The main method + * @param {object} config this is now diverse from the middleware setup + * @param {string} config.serverType socket.io or ws in the background + * @param {object} config.options the actual options to pass to the underlying setups + * @param {object} config.server this is the http/s server that required to bind to the socket to run on the same connection + * @return {mixed} return the undelying socket server instance for further use + */ +function jsonqlWsServer(config, server) { + // @TODO check the options + const setupFn = jsonqlWsServerCore(wsCreateServer, wsSetup) + return setupFn(config, server) +} + + module.exports = { - wsSetup, - wsCreateServer + jsonqlWsServerAction, + jsonqlWsServer } -- Gitee From 91581f15c2508406e40bf3a2c2283ee4ae70e009 Mon Sep 17 00:00:00 2001 From: joelchu Date: Fri, 6 Mar 2020 15:08:54 +0800 Subject: [PATCH 05/12] All working --- packages/ws-server-core/src/share/inter-com-handler.js | 2 +- packages/ws-server/src/core/modules.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/ws-server-core/src/share/inter-com-handler.js b/packages/ws-server-core/src/share/inter-com-handler.js index 2429c525..47d20e80 100644 --- a/packages/ws-server-core/src/share/inter-com-handler.js +++ b/packages/ws-server-core/src/share/inter-com-handler.js @@ -2,7 +2,7 @@ const { INTER_COM_EVENT_NAMES, INTER_COM_EVENT_NAME } = require('jsonql-constants') -const getDebug = require('./helpers') +const { getDebug } = require('./helpers') const debug = getDebug('inter-com-handler') const fsx = require('fs-extra') diff --git a/packages/ws-server/src/core/modules.js b/packages/ws-server/src/core/modules.js index 68847fdb..b13b5b44 100644 --- a/packages/ws-server/src/core/modules.js +++ b/packages/ws-server/src/core/modules.js @@ -11,8 +11,8 @@ const { createWsReply, getUserdata, resolveMethod -} = require('jsonql-ws-server-core') -// require('../../../ws-server-core') +} = require('../../../ws-server-core') +// require('jsonql-ws-server-core') module.exports = { checkSocketServerType, -- Gitee From 1de5ceb699c0960013c7cebebf9cca5cdd8a32a0 Mon Sep 17 00:00:00 2001 From: joelchu Date: Fri, 6 Mar 2020 15:30:02 +0800 Subject: [PATCH 06/12] seems to be fine --- packages/ws-server-core/index.js | 4 +-- packages/ws-server-core/src/share/helpers.js | 4 +++ .../src/share/inter-com-handler.js | 29 ++++++++----------- packages/ws-server/src/core/modules.js | 6 ++-- packages/ws-server/src/core/ws-setup.js | 11 +++++-- 5 files changed, 30 insertions(+), 24 deletions(-) diff --git a/packages/ws-server-core/index.js b/packages/ws-server-core/index.js index 97c977ff..935782f6 100644 --- a/packages/ws-server-core/index.js +++ b/packages/ws-server-core/index.js @@ -22,7 +22,7 @@ const { getUserdata } = require('./src/share/helpers') const { resolveMethod } = require('./src/share/resolve-method') -const { createInterComEventHandler } = require('./src/share/inter-com-handler') +const { interComEventHandler } = require('./src/share/inter-com-handler') const debug = getDebug('main') // also report the constants const jsonqlWsCoreConstants = require('./src/options/constants') @@ -52,5 +52,5 @@ module.exports = { jsonqlWsServerCore, jsonqlWsServerCoreAction, // @0.6.0 - createInterComEventHandler + interComEventHandler } diff --git a/packages/ws-server-core/src/share/helpers.js b/packages/ws-server-core/src/share/helpers.js index a1ccc80b..cdeface7 100644 --- a/packages/ws-server-core/src/share/helpers.js +++ b/packages/ws-server-core/src/share/helpers.js @@ -105,6 +105,10 @@ const nil = function() { } /** + * get the userdata via the decoded jwt from the request object + * @TODO we need to create a hook that let developer to plug in their own + * implementation in the future, + * therefore they could store this in a database or whatever * @param {object} req the request object * @return {object} userdata */ diff --git a/packages/ws-server-core/src/share/inter-com-handler.js b/packages/ws-server-core/src/share/inter-com-handler.js index 47d20e80..d1948dab 100644 --- a/packages/ws-server-core/src/share/inter-com-handler.js +++ b/packages/ws-server-core/src/share/inter-com-handler.js @@ -1,7 +1,4 @@ -const { - INTER_COM_EVENT_NAMES, - INTER_COM_EVENT_NAME -} = require('jsonql-constants') + const { getDebug } = require('./helpers') const debug = getDebug('inter-com-handler') const fsx = require('fs-extra') @@ -18,6 +15,7 @@ function getHandler(opts) { const { interComEventHandlerPath } = opts // this is up to how the developer supply this option if (interComEventHandlerPath !== null && fsx.existsSync(interComEventHandlerPath)) { + // @TODO we should use the getResolver method to search for the handler instead return require(interComEventHandlerPath) } // just return a dummy @@ -29,21 +27,18 @@ function getHandler(opts) { * we expect the user to pass an absolute path to the file that is * going to handle this type of events * then whenever it gets call, it will get take over by this function + * @param {string} evtType the type of the intercom event * @param {object} opts the configuration - * @param {object} ee the event emitter - * + * @param {array} args whatever argument we received + * @return {void} */ -function createInterComEventHandler(opts, ee) { +function interComEventHandler(evtType, opts, args) { const handler = getHandler(opts) - // we first add our own handlers - INTER_COM_EVENT_NAMES.forEach(evtName => { - ee.$on(evtName, function interComHandler(...args) { - // just debug for the time being - debug(`Hear this ${evtName}`, args) - // also call the developer supply methods, add the eventName before the args - Reflect.apply(handler, null, [evtName].concat(args)) - }) - }) + + // just debug for the time being + debug(`Hear this ${evtName}`, args) + // also call the developer supply methods, add the eventName before the args + Reflect.apply(handler, null, [evtType].concat(args)) } -module.exports = { createInterComEventHandler } \ No newline at end of file +module.exports = { interComEventHandler } \ No newline at end of file diff --git a/packages/ws-server/src/core/modules.js b/packages/ws-server/src/core/modules.js index b13b5b44..862a895a 100644 --- a/packages/ws-server/src/core/modules.js +++ b/packages/ws-server/src/core/modules.js @@ -10,7 +10,8 @@ const { getDebug, createWsReply, getUserdata, - resolveMethod + resolveMethod, + interComEventHandler } = require('../../../ws-server-core') // require('jsonql-ws-server-core') @@ -24,5 +25,6 @@ module.exports = { getDebug, createWsReply, getUserdata, - resolveMethod + resolveMethod, + interComEventHandler } \ No newline at end of file diff --git a/packages/ws-server/src/core/ws-setup.js b/packages/ws-server/src/core/ws-setup.js index fde05297..81598696 100644 --- a/packages/ws-server/src/core/ws-setup.js +++ b/packages/ws-server/src/core/ws-setup.js @@ -7,13 +7,15 @@ const { ACKNOWLEDGE_REPLY_TYPE, ERROR_TYPE, LOGOUT_NAME, - TIMESTAMP_PARAM_NAME + TIMESTAMP_PARAM_NAME, + INTER_COM_EVENT_NAME } = require('jsonql-constants') const { getDebug, createWsReply, getUserdata, - resolveMethod + resolveMethod, + interComEventHandler } = require('./modules') const WS_EXIT_ID = 1 @@ -122,7 +124,10 @@ const wsSetup = (opts, nspObj) => { return handleLogout(ws) } // @TODO add a bunch of other new inter comm methods here as well - + if (resolverName === INTER_COM_EVENT_NAME) { + // just throw everyt into it + return interComEventHandler(ws, req, json, socketFns, opts, getUserdata(req)) + } // only allow the method under that particular namespace if (methodsInNsp[resolverName]) { debug('methodsInNsp[resolverName]', methodsInNsp[resolverName]) -- Gitee From af507a406e1af5ea42f6eeb4372813f6ff662cde Mon Sep 17 00:00:00 2001 From: joelchu Date: Fri, 6 Mar 2020 15:32:53 +0800 Subject: [PATCH 07/12] jsonql-ws-server to 1.6.3 --- packages/ws-server/package.json | 4 ++-- packages/ws-server/src/core/modules.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/ws-server/package.json b/packages/ws-server/package.json index 5696df88..66d8aa89 100755 --- a/packages/ws-server/package.json +++ b/packages/ws-server/package.json @@ -8,7 +8,7 @@ "src" ], "scripts": { - "test": "ava ", + "test": "ava", "prepare": "npm run test", "test:ws": "DEBUG=jsonql-ws-server* ava ./tests/ws-connect.test.js", "test:error": "DEBUG=jsonql-ws-server* ava ./tests/ws-connect-error.test.js", @@ -27,7 +27,7 @@ "author": "Joel Chu ", "license": "MIT", "dependencies": { - "jsonql-ws-server-core": "^0.5.0", + "jsonql-ws-server-core": "^0.6.0", "ws": "^7.2.1" }, "devDependencies": { diff --git a/packages/ws-server/src/core/modules.js b/packages/ws-server/src/core/modules.js index 862a895a..4b8635e2 100644 --- a/packages/ws-server/src/core/modules.js +++ b/packages/ws-server/src/core/modules.js @@ -12,8 +12,8 @@ const { getUserdata, resolveMethod, interComEventHandler -} = require('../../../ws-server-core') -// require('jsonql-ws-server-core') +} = require('jsonql-ws-server-core') +// require('../../../ws-server-core') module.exports = { checkSocketServerType, -- Gitee From 535f0fda4eed81ecc2dc5f95c055b7675a75bcbd Mon Sep 17 00:00:00 2001 From: joelchu Date: Fri, 6 Mar 2020 15:43:47 +0800 Subject: [PATCH 08/12] update client event handler and mark the new feature todos --- packages/ws-client-core/package.json | 4 +- .../src/share/client-event-handler.js | 67 ++++++++++++------- 2 files changed, 45 insertions(+), 26 deletions(-) diff --git a/packages/ws-client-core/package.json b/packages/ws-client-core/package.json index 47323097..14e846d2 100644 --- a/packages/ws-client-core/package.json +++ b/packages/ws-client-core/package.json @@ -53,7 +53,7 @@ "node": ">=8" }, "dependencies": { - "jsonql-constants": "^1.9.3", + "jsonql-constants": "^1.9.4", "jsonql-errors": "^1.1.10", "jsonql-params-validator": "^1.5.2", "jsonql-utils": "^1.0.0", @@ -64,7 +64,7 @@ "esm": "^3.2.25", "fs-extra": "^8.1.0", "jsonql-contract": "^1.8.7", - "jsonql-ws-server": "^1.6.2", + "jsonql-ws-server": "^1.6.3", "kefir": "^3.8.6", "ws": "^7.2.1" }, diff --git a/packages/ws-client-core/src/share/client-event-handler.js b/packages/ws-client-core/src/share/client-event-handler.js index 2920629f..c9aed47f 100644 --- a/packages/ws-client-core/src/share/client-event-handler.js +++ b/packages/ws-client-core/src/share/client-event-handler.js @@ -5,8 +5,8 @@ import { LOGOUT_EVENT_NAME, NOT_LOGIN_ERR_MSG, - ON_ERROR_PROP_NAME, - ON_RESULT_PROP_NAME + ON_ERROR_FN_NAME, + ON_RESULT_FN_NAME } from 'jsonql-constants' import { EMIT_EVT, SOCKET_IO } from '../options/constants' import { createEvt, clearMainEmitEvt } from '../utils' @@ -33,9 +33,9 @@ const notLoginWsHandler = (namespace, ee, opts) => { } // It should just throw error here and should not call the result // because that's channel for handling normal event not the fake one - ee.$call(createEvt(namespace, resolverName, ON_ERROR_PROP_NAME), [ error ]) + ee.$call(createEvt(namespace, resolverName, ON_ERROR_FN_NAME), [ error ]) // also trigger the result handler, but wrap inside the error key - ee.$call(createEvt(namespace, resolverName, ON_RESULT_PROP_NAME), [{ error }]) + ee.$call(createEvt(namespace, resolverName, ON_RESULT_FN_NAME), [{ error }]) } ) } @@ -49,6 +49,37 @@ const getPrivateNamespace = (namespaces) => ( namespaces.length > 1 ? namespaces[0] : false ) +/** + * Only when there is a private namespace then we bind to this event + * @param {object} nsps the available nsp(s) + * @param {array} namespaces available namespace + * @param {object} ee eventEmitter + * @param {object} opts configuration + * @return {void} + */ +const logoutEvtHandler = (nsps, namespaces, ee, opts) => { + // this will be available regardless enableAuth + // because the server can log the client out + ee.$on(LOGOUT_EVENT_NAME, function logoutEvtHandlerAction() { + opts.log('LOGOUT_EVENT_NAME') + // disconnect(nsps, opts.serverType) + // we need to issue error to all the namespace onError handler + triggerNamespacesOnError(ee, namespaces, LOGOUT_EVENT_NAME) + // rebind all of the handler to the fake one + namespaces.forEach( namespace => { + clearMainEmitEvt(ee, namespace) + // clear out the nsp + nsps[namespace] = null + // @TODO here is the problem, we clear out ALL the nsps + // but we should keep the public nsp, because logout doesn't mean + // disconnect everything right? + + // add a NOT LOGIN error if call + notLoginWsHandler(namespace, ee, opts) + }) + }) +} + /** * centralize all the comm in one place * @param {object} opts configuration @@ -64,6 +95,7 @@ export function clientEventHandler(opts, nspMap, ee, bindWsHandler, namespaces, // then we can use this prop to determine if we need to fire the ON_LOGIN_PROP_NAME event const privateNamespace = getPrivateNamespace(namespaces) let isPrivate = false + let hasPrivate = false const { log } = opts // loop // @BUG for io this has to be in order the one with auth need to get call first @@ -83,27 +115,14 @@ export function clientEventHandler(opts, nspMap, ee, bindWsHandler, namespaces, Reflect.apply(bindWsHandler, null, args) } else { // a dummy placeholder + // @TODO but it should be a not connect handler + // when it's not login (or fail) this should be handle differently notLoginWsHandler(namespace, ee, opts) } }) - // this will be available regardless enableAuth - // because the server can log the client out - ee.$on(LOGOUT_EVENT_NAME, function logoutEvtHandler() { - log('LOGOUT_EVENT_NAME') - // disconnect(nsps, opts.serverType) - // we need to issue error to all the namespace onError handler - triggerNamespacesOnError(ee, namespaces, LOGOUT_EVENT_NAME) - // rebind all of the handler to the fake one - namespaces.forEach( namespace => { - clearMainEmitEvt(ee, namespace) - // clear out the nsp - nsps[namespace] = null - // @TODO here is the problem, we clear out ALL the nsps - // but we should keep the public nsp, because logout doesn't mean - // disconnect everything right? - - // add a NOT LOGIN error if call - notLoginWsHandler(namespace, ee, opts) - }) - }) + // logout event handler + if (hasPrivate) { + logoutEvtHandler(nsps, namespaces, ee, opts) + } + // @TODO the INTERCOM event handlers } -- Gitee From 978f8f56257d8dfd97db24e3d9f2024ead0970ac Mon Sep 17 00:00:00 2001 From: joelchu Date: Fri, 6 Mar 2020 15:51:42 +0800 Subject: [PATCH 09/12] update all the constants --- .../ws-client-core/src/core/action-call.js | 4 +-- .../src/core/resolver-methods.js | 8 ++++-- .../src/core/setup-auth-methods.js | 6 ++-- .../ws-client-core/src/core/setup-resolver.js | 28 +++++++++---------- .../ws-client-core/src/core/setup-send.js | 13 +++++---- .../ws-client-core/src/options/constants.js | 8 +++--- packages/ws-client-core/src/options/index.js | 11 ++++++-- .../src/share/trigger-namespaces-on-error.js | 4 +-- 8 files changed, 46 insertions(+), 36 deletions(-) diff --git a/packages/ws-client-core/src/core/action-call.js b/packages/ws-client-core/src/core/action-call.js index b2d3491f..1c7c1225 100644 --- a/packages/ws-client-core/src/core/action-call.js +++ b/packages/ws-client-core/src/core/action-call.js @@ -1,5 +1,5 @@ // the actual trigger call method -import { ON_RESULT_PROP_NAME, EMIT_REPLY_TYPE } from 'jsonql-constants' +import { ON_RESULT_FN_NAME, EMIT_REPLY_TYPE } from 'jsonql-constants' import { createEvt, toArray } from '../utils' import { respondHandler } from './respond-handler' @@ -27,7 +27,7 @@ export function actionCall(ee, namespace, resolverName, args = [], log) { // this cause the onResult got the result back first // and it should be the promise resolve first ee.$on( - createEvt(namespace, resolverName, ON_RESULT_PROP_NAME), + createEvt(namespace, resolverName, ON_RESULT_FN_NAME), function actionCallResultHandler(result) { log(`got the first result`, result) diff --git a/packages/ws-client-core/src/core/resolver-methods.js b/packages/ws-client-core/src/core/resolver-methods.js index 4e9792fa..0929989c 100644 --- a/packages/ws-client-core/src/core/resolver-methods.js +++ b/packages/ws-client-core/src/core/resolver-methods.js @@ -11,12 +11,16 @@ import { finalCatch } from 'jsonql-errors' import { validateAsync } from 'jsonql-params-validator' import { setupResolver } from './setup-resolver' import { actionCall } from './action-call' -import { createEvt, objDefineProps, isFunc, injectToFn } from '../utils' +import { + createEvt, + objDefineProps, + isFunc, + injectToFn +} from '../utils' import { ON_ERROR_PROP_NAME, ON_READY_PROP_NAME } from 'jsonql-constants' -// import { CB_FN_NAME } from '../options/constants' /** * create the actual function to send message to server diff --git a/packages/ws-client-core/src/core/setup-auth-methods.js b/packages/ws-client-core/src/core/setup-auth-methods.js index 9084479b..d23fb914 100644 --- a/packages/ws-client-core/src/core/setup-auth-methods.js +++ b/packages/ws-client-core/src/core/setup-auth-methods.js @@ -2,7 +2,7 @@ import { LOGIN_EVENT_NAME, LOGOUT_EVENT_NAME, - ON_LOGIN_PROP_NAME + ON_LOGIN_FN_NAME } from 'jsonql-constants' import { JsonqlValidationError } from 'jsonql-errors' import { injectToFn, chainFns, isString, objDefineProps, isFunc } from '../utils' @@ -56,10 +56,10 @@ const setupLogoutHandler = (obj, opts, ee) => [ * @return {array} [ obj, opts, ee] what comes in what goes out */ const createOnLoginhandler = (obj, opts, ee) => [ - objDefineProps(obj, ON_LOGIN_PROP_NAME, function onLoginCallbackHandler(onLoginCallback) { + objDefineProps(obj, ON_LOGIN_FN_NAME, function onLoginCallbackHandler(onLoginCallback) { if (isFunc(onLoginCallback)) { // only one callback can registered with it, TBC - ee.$only(ON_LOGIN_PROP_NAME, onLoginCallback) + ee.$only(ON_LOGIN_FN_NAME, onLoginCallback) } }), opts, diff --git a/packages/ws-client-core/src/core/setup-resolver.js b/packages/ws-client-core/src/core/setup-resolver.js index c80da042..e8e78cf3 100644 --- a/packages/ws-client-core/src/core/setup-resolver.js +++ b/packages/ws-client-core/src/core/setup-resolver.js @@ -1,9 +1,9 @@ // break up the original setup resolver method here // import { JsonqlValidationError, finalCatch } from 'jsonql-errors' import { - ON_ERROR_PROP_NAME, - ON_MESSAGE_PROP_NAME, - ON_RESULT_PROP_NAME + ON_ERROR_FN_NAME, + ON_MESSAGE_FN_NAME, + ON_RESULT_FN_NAME } from 'jsonql-constants' // local import { MY_NAMESPACE } from '../options/constants' @@ -11,8 +11,6 @@ import { chainFns, objDefineProps, injectToFn, createEvt, isFunc } from '../util import { respondHandler } from './respond-handler' import { setupSend } from './setup-send' - - /** * The first one in the chain, just setup a namespace prop * the rest are passing through @@ -36,15 +34,15 @@ const setupNamespace = (fn, ee, namespace, resolverName, params, log) => [ * onResult handler */ const setupOnResult = (fn, ee, namespace, resolverName, params, log) => [ - objDefineProps(fn, ON_RESULT_PROP_NAME, function(resultCallback) { + objDefineProps(fn, ON_RESULT_FN_NAME, function(resultCallback) { if (isFunc(resultCallback)) { ee.$on( - createEvt(namespace, resolverName, ON_RESULT_PROP_NAME), + createEvt(namespace, resolverName, ON_RESULT_FN_NAME), function resultHandler(result) { respondHandler(result, resultCallback, (error) => { log(`Catch error: "${resolverName}"`, error) ee.$trigger( - createEvt(namespace, resolverName, ON_ERROR_PROP_NAME), + createEvt(namespace, resolverName, ON_ERROR_FN_NAME), error ) }) @@ -64,7 +62,7 @@ const setupOnResult = (fn, ee, namespace, resolverName, params, log) => [ * bi-directional data stream */ const setupOnMessage = (fn, ee, namespace, resolverName, params, log) => [ - objDefineProps(fn, ON_MESSAGE_PROP_NAME, function(messageCallback) { + objDefineProps(fn, ON_MESSAGE_FN_NAME, function(messageCallback) { // we expect this to be a function if (isFunc(messageCallback)) { // did that add to the callback @@ -72,14 +70,14 @@ const setupOnMessage = (fn, ee, namespace, resolverName, params, log) => [ respondHandler(args, messageCallback, (error) => { log(`Catch error: "${resolverName}"`, error) ee.$trigger( - createEvt(namespace, resolverName, ON_ERROR_PROP_NAME), + createEvt(namespace, resolverName, ON_ERROR_FN_NAME), error ) }) } // register the handler for this message event ee.$only( - createEvt(namespace, resolverName, ON_MESSAGE_PROP_NAME), + createEvt(namespace, resolverName, ON_MESSAGE_FN_NAME), onMessageCallback ) } @@ -92,14 +90,14 @@ const setupOnMessage = (fn, ee, namespace, resolverName, params, log) => [ ] /** - * ON_ERROR_PROP_NAME handler + * ON_ERROR_FN_NAME handler */ const setupOnError = (fn, ee, namespace, resolverName, params, log) => [ - objDefineProps(fn, ON_ERROR_PROP_NAME, function(resolverErrorHandler) { + objDefineProps(fn, ON_ERROR_FN_NAME, function(resolverErrorHandler) { if (isFunc(resolverErrorHandler)) { - // please note ON_ERROR_PROP_NAME can add multiple listners + // please note ON_ERROR_FN_NAME can add multiple listners ee.$only( - createEvt(namespace, resolverName, ON_ERROR_PROP_NAME), + createEvt(namespace, resolverName, ON_ERROR_FN_NAME), resolverErrorHandler ) } diff --git a/packages/ws-client-core/src/core/setup-send.js b/packages/ws-client-core/src/core/setup-send.js index e90ed62d..9a3fff7d 100644 --- a/packages/ws-client-core/src/core/setup-send.js +++ b/packages/ws-client-core/src/core/setup-send.js @@ -1,15 +1,16 @@ +// setting up the send method import { JsonqlValidationError, finalCatch } from 'jsonql-errors' import { ERROR_KEY, - ON_ERROR_PROP_NAME, - SEND_MSG_PROP_NAME + ON_ERROR_FN_NAME, + SEND_MSG_FN_NAME } from 'jsonql-constants' import { validateAsync } from 'jsonql-params-validator' import { objDefineProps, createEvt, toArray } from '../utils' import { actionCall } from './action-call' /** - * pairing with the server vesrion SEND_MSG_PROP_NAME + * pairing with the server vesrion SEND_MSG_FN_NAME * last of the chain so only return the resolver (fn) * @param {function} fn the resolver function * @param {object} ee event emitter instance @@ -20,7 +21,7 @@ import { actionCall } from './action-call' * @return {function} return the resolver itself */ export const setupSend = (fn, ee, namespace, resolverName, params, log) => ( - objDefineProps(fn, SEND_MSG_PROP_NAME, function sendSetter(messagePayload) { + objDefineProps(fn, SEND_MSG_FN_NAME, function sendSetter(messagePayload) { // debugFn('got payload for', messagePayload) // @NOTE change from sync interface to async @ 1.0.0 // this way we will able to catch all the error(s) @@ -30,7 +31,7 @@ export const setupSend = (fn, ee, namespace, resolverName, params, log) => ( if (result[ERROR_KEY] && result[ERROR_KEY].length) { // debugFn(`got ERROR_KEY`, result[ERROR_KEY]) ee.$call( - createEvt(namespace, resolverName, ON_ERROR_PROP_NAME), + createEvt(namespace, resolverName, ON_ERROR_FN_NAME), [new JsonqlValidationError(resolverName, result[ERROR_KEY])] ) } else { @@ -41,7 +42,7 @@ export const setupSend = (fn, ee, namespace, resolverName, params, log) => ( .catch(err => { // debugFn(`error after validateAsync`, err) ee.$call( - createEvt(namespace, resolverName, ON_ERROR_PROP_NAME), + createEvt(namespace, resolverName, ON_ERROR_FN_NAME), [new JsonqlValidationError(resolverName, err)] ) }) diff --git a/packages/ws-client-core/src/options/constants.js b/packages/ws-client-core/src/options/constants.js index 733bd153..419e890b 100644 --- a/packages/ws-client-core/src/options/constants.js +++ b/packages/ws-client-core/src/options/constants.js @@ -4,8 +4,8 @@ import { EMIT_REPLY_TYPE, JS_WS_SOCKET_IO_NAME, JS_WS_NAME, - ON_MESSAGE_PROP_NAME, - ON_RESULT_PROP_NAME + ON_MESSAGE_FN_NAME, + ON_RESULT_FN_NAME } from 'jsonql-constants' const SOCKET_IO = JS_WS_SOCKET_IO_NAME @@ -42,8 +42,8 @@ export { MISSING_PROP_ERR, UNKNOWN_CLIENT_ERR, EMIT_EVT, - ON_MESSAGE_PROP_NAME, - ON_RESULT_PROP_NAME, + ON_MESSAGE_FN_NAME, + ON_RESULT_FN_NAME, NAMESPACE_KEY, UNKNOWN_RESULT, NOT_ALLOW_OP, diff --git a/packages/ws-client-core/src/options/index.js b/packages/ws-client-core/src/options/index.js index 606eed31..d0aa7f61 100644 --- a/packages/ws-client-core/src/options/index.js +++ b/packages/ws-client-core/src/options/index.js @@ -1,6 +1,13 @@ // create options -import { checkConfigAsync, checkConfig } from 'jsonql-params-validator' -import { wsCoreDefaultOptions, wsCoreConstProps, socketAppProps } from './defaults' +import { + checkConfigAsync, + checkConfig +} from 'jsonql-params-validator' +import { + wsCoreDefaultOptions, + wsCoreConstProps, + socketAppProps +} from './defaults' import { fixWss, getHostName, diff --git a/packages/ws-client-core/src/share/trigger-namespaces-on-error.js b/packages/ws-client-core/src/share/trigger-namespaces-on-error.js index 0145f592..3a6430be 100644 --- a/packages/ws-client-core/src/share/trigger-namespaces-on-error.js +++ b/packages/ws-client-core/src/share/trigger-namespaces-on-error.js @@ -1,5 +1,5 @@ // this use by client-event-handler -import { ON_ERROR_PROP_NAME } from 'jsonql-constants' +import { ON_ERROR_FN_NAME } from 'jsonql-constants' import { createEvt } from '../utils' /** @@ -12,7 +12,7 @@ import { createEvt } from '../utils' export function triggerNamespacesOnError(ee, namespaces, message) { namespaces.forEach( namespace => { ee.$trigger( - createEvt(namespace, ON_ERROR_PROP_NAME), + createEvt(namespace, ON_ERROR_FN_NAME), [{ message, namespace }] ) }) -- Gitee From da6972cc630314cbc8e9d861a9a3203e92d5ad6a Mon Sep 17 00:00:00 2001 From: joelchu Date: Fri, 6 Mar 2020 16:29:27 +0800 Subject: [PATCH 10/12] fix up all the constants related problems --- .../ws-client-core/src/core/resolver-methods.js | 14 +++++++------- packages/ws-client-core/tests/auth.test.js | 10 +++++----- packages/ws-client-core/tests/fixtures/io-setup.js | 2 +- .../tests/fixtures/lib/fake-ws-client.js | 8 ++++---- .../tests/fixtures/resolvers/socket/continuous.js | 10 +++++----- .../fixtures/resolvers/socket/public/pinging.js | 6 +++--- .../fixtures/resolvers/socket/send-extra-msg.js | 4 ++-- .../tests/fixtures/resolvers/socket/simple.js | 2 +- .../tests/fixtures/resolvers/socket/throw-error.js | 2 +- .../ws-client-core/tests/fixtures/server-setup.js | 6 +++--- packages/ws-client-core/tests/tbd.test.js | 8 ++++---- 11 files changed, 36 insertions(+), 36 deletions(-) diff --git a/packages/ws-client-core/src/core/resolver-methods.js b/packages/ws-client-core/src/core/resolver-methods.js index 0929989c..e308e33d 100644 --- a/packages/ws-client-core/src/core/resolver-methods.js +++ b/packages/ws-client-core/src/core/resolver-methods.js @@ -18,8 +18,8 @@ import { injectToFn } from '../utils' import { - ON_ERROR_PROP_NAME, - ON_READY_PROP_NAME + ON_ERROR_FN_NAME, + ON_READY_FN_NAME } from 'jsonql-constants' /** @@ -81,13 +81,13 @@ export function createNamespaceErrorHandler(obj, opts, ee, nspSet) { // using the onError as name // @TODO we should follow the convention earlier // make this a setter for the obj itself - objDefineProps(obj, ON_ERROR_PROP_NAME, function namespaceErrorCallbackHandler(namespaceErrorHandler) { + objDefineProps(obj, ON_ERROR_FN_NAME, function namespaceErrorCallbackHandler(namespaceErrorHandler) { if (isFunc(namespaceErrorHandler)) { - // please note ON_ERROR_PROP_NAME can add multiple listners + // please note ON_ERROR_FN_NAME can add multiple listners for (let namespace in nspSet) { // this one is very tricky, we need to make sure the trigger is calling // with the namespace as well as the error - ee.$on(createEvt(namespace, ON_ERROR_PROP_NAME), namespaceErrorHandler) + ee.$on(createEvt(namespace, ON_ERROR_FN_NAME), namespaceErrorHandler) } } }), @@ -105,10 +105,10 @@ export function createNamespaceErrorHandler(obj, opts, ee, nspSet) { */ export function createOnReadyHandler(obj, opts, ee) { return [ - objDefineProps(obj, ON_READY_PROP_NAME, function onReadyCallbackHandler(onReadyCallback) { + objDefineProps(obj, ON_READY_FN_NAME, function onReadyCallbackHandler(onReadyCallback) { if (isFunc(onReadyCallback)) { // reduce it down to just one flat level - ee.$on(ON_READY_PROP_NAME, onReadyCallback) + ee.$on(ON_READY_FN_NAME, onReadyCallback) } }), opts, diff --git a/packages/ws-client-core/tests/auth.test.js b/packages/ws-client-core/tests/auth.test.js index 00c169e8..b9055603 100644 --- a/packages/ws-client-core/tests/auth.test.js +++ b/packages/ws-client-core/tests/auth.test.js @@ -8,8 +8,8 @@ const { mockClient, log } = require('./fixtures/lib/mock-client') const { - ON_ERROR_PROP_NAME, - ON_LOGIN_PROP_NAME + ON_ERROR_FN_NAME, + ON_LOGIN_FN_NAME } = require('jsonql-constants') test.before(async t => { @@ -27,14 +27,14 @@ test.cb(`We should able to get a list of event register via the eventEmitter`, t t.truthy(client) // note it's one name onError that will listen to all the nsp errors - client[ON_ERROR_PROP_NAME] = function() { + client[ON_ERROR_FN_NAME] = function() { log(`OnError callback added`) } // there is only one onReady call now - client[ON_LOGIN_PROP_NAME] = function(msg) { - log(`${ON_LOGIN_PROP_NAME} callback added`, msg) + client[ON_LOGIN_FN_NAME] = function(msg) { + log(`${ON_LOGIN_FN_NAME} callback added`, msg) t.pass() t.end() } diff --git a/packages/ws-client-core/tests/fixtures/io-setup.js b/packages/ws-client-core/tests/fixtures/io-setup.js index 2b6c9555..b02e1445 100644 --- a/packages/ws-client-core/tests/fixtures/io-setup.js +++ b/packages/ws-client-core/tests/fixtures/io-setup.js @@ -1,5 +1,5 @@ // const Koa = require('koa'); -const bodyparser = require('koa-bodyparser') +// const bodyparser = require('koa-bodyparser') const jsonqlWsServer = require('jsonql-ws-server') const config = require('./contract-config') const { join } = require('path') diff --git a/packages/ws-client-core/tests/fixtures/lib/fake-ws-client.js b/packages/ws-client-core/tests/fixtures/lib/fake-ws-client.js index bae790c4..93a42cbe 100644 --- a/packages/ws-client-core/tests/fixtures/lib/fake-ws-client.js +++ b/packages/ws-client-core/tests/fixtures/lib/fake-ws-client.js @@ -3,8 +3,8 @@ import debug from 'debug' const log = debug('jsonql-ws-client:test:fake-client') import { - ON_READY_PROP_NAME, - ON_LOGIN_PROP_NAME + ON_READY_FN_NAME, + ON_LOGIN_FN_NAME } from 'jsonql-constants' function fakeWsClient(...args) { @@ -22,9 +22,9 @@ function fakeWsClient(...args) { // we fire the the onReady after 1/2 second setTimeout(() => { if (enableAuth) { - obj.ee.$trigger(ON_LOGIN_PROP_NAME, 'You are login') + obj.ee.$trigger(ON_LOGIN_FN_NAME, 'You are login') } else { - obj.ee.$trigger(ON_READY_PROP_NAME, 'fake!') + obj.ee.$trigger(ON_READY_FN_NAME, 'fake!') } }, 500) diff --git a/packages/ws-client-core/tests/fixtures/resolvers/socket/continuous.js b/packages/ws-client-core/tests/fixtures/resolvers/socket/continuous.js index 3d468bb9..e83e373d 100644 --- a/packages/ws-client-core/tests/fixtures/resolvers/socket/continuous.js +++ b/packages/ws-client-core/tests/fixtures/resolvers/socket/continuous.js @@ -1,6 +1,6 @@ // this will keep sending out message until received a terminate call -let timer; -let ctn = 0; +let timer +let ctn = 0 const debug = require('debug')('jsonql-ws-client:socket:continous') /** * @param {string} msg a message @@ -12,10 +12,10 @@ module.exports = function continuous(msg) { } // use the send setter instead timer = setInterval(() => { - continuous.send = msg + ` [${++ctn}] ${Date.now()}`; - }, 1000); + continuous.send = msg + ` [${++ctn}] ${Date.now()}` + }, 1000) // return result return new Promise((resolver) => { resolver(`start at ${Date.now()}`) - }); + }) } diff --git a/packages/ws-client-core/tests/fixtures/resolvers/socket/public/pinging.js b/packages/ws-client-core/tests/fixtures/resolvers/socket/public/pinging.js index 9aa000f3..fc1e36ba 100644 --- a/packages/ws-client-core/tests/fixtures/resolvers/socket/public/pinging.js +++ b/packages/ws-client-core/tests/fixtures/resolvers/socket/public/pinging.js @@ -1,7 +1,7 @@ // this is a public method always avaialble const debug = require('debug')('jsonql-ws-client:resolver:pinging') -let ctn = 0; +let ctn = 0 /** * @param {string} msg message * @return {string} reply message based on your message @@ -17,12 +17,12 @@ module.exports = function pinging(msg) { debug(`got a pong`) pinging.send = 'ping'; default: - return `Got your message ${msg}`; + return `Got your message ${msg}` //pinging.send = 'You lose!'; } return true; } ++ctn; debug(`Did return here`) - return 'connection established'; + return 'connection established' } diff --git a/packages/ws-client-core/tests/fixtures/resolvers/socket/send-extra-msg.js b/packages/ws-client-core/tests/fixtures/resolvers/socket/send-extra-msg.js index 9144b99a..6b2d3547 100644 --- a/packages/ws-client-core/tests/fixtures/resolvers/socket/send-extra-msg.js +++ b/packages/ws-client-core/tests/fixtures/resolvers/socket/send-extra-msg.js @@ -6,7 +6,7 @@ * @return {number} x + ? */ module.exports = function sendExtraMsg(x) { - sendExtraMsg.send = x + 2; + sendExtraMsg.send = x + 2 - return x + 1; + return x + 1 } diff --git a/packages/ws-client-core/tests/fixtures/resolvers/socket/simple.js b/packages/ws-client-core/tests/fixtures/resolvers/socket/simple.js index 61810eae..a50a4140 100644 --- a/packages/ws-client-core/tests/fixtures/resolvers/socket/simple.js +++ b/packages/ws-client-core/tests/fixtures/resolvers/socket/simple.js @@ -5,5 +5,5 @@ * @return {number} a number + 1; */ module.exports = function(i) { - return ++i; + return ++i } diff --git a/packages/ws-client-core/tests/fixtures/resolvers/socket/throw-error.js b/packages/ws-client-core/tests/fixtures/resolvers/socket/throw-error.js index a7fcd6f4..030e27a3 100644 --- a/packages/ws-client-core/tests/fixtures/resolvers/socket/throw-error.js +++ b/packages/ws-client-core/tests/fixtures/resolvers/socket/throw-error.js @@ -5,5 +5,5 @@ * @return {error} just throw */ module.exports = function() { - throw new Error('Shitty Shitty Bang Bang'); + throw new Error('Shitty Shitty Bang Bang') } diff --git a/packages/ws-client-core/tests/fixtures/server-setup.js b/packages/ws-client-core/tests/fixtures/server-setup.js index 34862304..92dc86d7 100644 --- a/packages/ws-client-core/tests/fixtures/server-setup.js +++ b/packages/ws-client-core/tests/fixtures/server-setup.js @@ -1,8 +1,8 @@ const http = require('http') -const fsx = require('fs-extra') +// const fsx = require('fs-extra') const { join } = require('path') -const debug = require('debug')('jsonql-ws-client:fixtures:server') -const { JSONQL_PATH } = require('jsonql-constants') +// const debug = require('debug')('jsonql-ws-client:fixtures:server') +// const { JSONQL_PATH } = require('jsonql-constants') const resolverDir = join(__dirname, 'resolvers') const contractDir = join(__dirname, 'contract') diff --git a/packages/ws-client-core/tests/tbd.test.js b/packages/ws-client-core/tests/tbd.test.js index ba0f6042..51a6088f 100644 --- a/packages/ws-client-core/tests/tbd.test.js +++ b/packages/ws-client-core/tests/tbd.test.js @@ -6,8 +6,8 @@ const { mockClient, log } = require('./fixtures/lib/mock-client') const { - ON_ERROR_PROP_NAME, - ON_READY_PROP_NAME + ON_ERROR_FN_NAME, + ON_READY_FN_NAME } = require('jsonql-constants') test.before(async t => { @@ -25,12 +25,12 @@ test.cb(`We should able to get a list of event register via the eventEmitter`, t t.truthy(client) // note it's one name onError that will listen to all the nsp errors - client[ON_ERROR_PROP_NAME] = function() { + client[ON_ERROR_FN_NAME] = function() { log(`OnError callback added`) } // there is only one onReady call now - client[ON_READY_PROP_NAME] = function(msg) { + client[ON_READY_FN_NAME] = function(msg) { log(`onError callback added`, msg) t.pass() t.end() -- Gitee From 0cbbf47d8023d7507a1f54e9b031f09e39525b69 Mon Sep 17 00:00:00 2001 From: joelchu Date: Fri, 6 Mar 2020 16:42:20 +0800 Subject: [PATCH 11/12] remove the vue folder from @jsonql --- packages/@jsonql/vue/.gitignore | 21 ------- packages/@jsonql/vue/README.md | 29 --------- packages/@jsonql/vue/babel.config.js | 5 -- packages/@jsonql/vue/package.json | 47 -------------- packages/@jsonql/vue/public/favicon.ico | Bin 4286 -> 0 bytes packages/@jsonql/vue/public/index.html | 17 ----- packages/@jsonql/vue/src/App.vue | 28 --------- packages/@jsonql/vue/src/assets/logo.png | Bin 6849 -> 0 bytes .../@jsonql/vue/src/components/HelloWorld.vue | 58 ------------------ packages/@jsonql/vue/src/main.js | 8 --- 10 files changed, 213 deletions(-) delete mode 100644 packages/@jsonql/vue/.gitignore delete mode 100644 packages/@jsonql/vue/README.md delete mode 100644 packages/@jsonql/vue/babel.config.js delete mode 100644 packages/@jsonql/vue/package.json delete mode 100644 packages/@jsonql/vue/public/favicon.ico delete mode 100644 packages/@jsonql/vue/public/index.html delete mode 100644 packages/@jsonql/vue/src/App.vue delete mode 100644 packages/@jsonql/vue/src/assets/logo.png delete mode 100644 packages/@jsonql/vue/src/components/HelloWorld.vue delete mode 100644 packages/@jsonql/vue/src/main.js diff --git a/packages/@jsonql/vue/.gitignore b/packages/@jsonql/vue/.gitignore deleted file mode 100644 index a0dddc6f..00000000 --- a/packages/@jsonql/vue/.gitignore +++ /dev/null @@ -1,21 +0,0 @@ -.DS_Store -node_modules -/dist - -# local env files -.env.local -.env.*.local - -# Log files -npm-debug.log* -yarn-debug.log* -yarn-error.log* - -# Editor directories and files -.idea -.vscode -*.suo -*.ntvs* -*.njsproj -*.sln -*.sw? diff --git a/packages/@jsonql/vue/README.md b/packages/@jsonql/vue/README.md deleted file mode 100644 index 60834447..00000000 --- a/packages/@jsonql/vue/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# vue - -## Project setup -``` -npm install -``` - -### Compiles and hot-reloads for development -``` -npm run serve -``` - -### Compiles and minifies for production -``` -npm run build -``` - -### Run your tests -``` -npm run test -``` - -### Lints and fixes files -``` -npm run lint -``` - -### Customize configuration -See [Configuration Reference](https://cli.vuejs.org/config/). diff --git a/packages/@jsonql/vue/babel.config.js b/packages/@jsonql/vue/babel.config.js deleted file mode 100644 index ba179669..00000000 --- a/packages/@jsonql/vue/babel.config.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - presets: [ - '@vue/app' - ] -} diff --git a/packages/@jsonql/vue/package.json b/packages/@jsonql/vue/package.json deleted file mode 100644 index c04e5a8e..00000000 --- a/packages/@jsonql/vue/package.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "name": "vue", - "version": "0.1.0", - "private": true, - "scripts": { - "serve": "vue-cli-service serve", - "build": "vue-cli-service build", - "lint": "vue-cli-service lint" - }, - "dependencies": { - "core-js": "^2.6.5", - "vue": "^2.6.10" - }, - "devDependencies": { - "@vue/cli-plugin-babel": "^3.11.0", - "@vue/cli-plugin-eslint": "^3.11.0", - "@vue/cli-service": "^3.11.0", - "babel-eslint": "^10.0.1", - "eslint": "^5.16.0", - "eslint-plugin-vue": "^5.0.0", - "vue-template-compiler": "^2.6.10" - }, - "eslintConfig": { - "root": true, - "env": { - "node": true - }, - "extends": [ - "plugin:vue/essential", - "eslint:recommended" - ], - "rules": {}, - "parserOptions": { - "parser": "babel-eslint" - } - }, - "postcss": { - "plugins": { - "autoprefixer": {} - } - }, - "browserslist": [ - "> 1%", - "last 2 versions" - ], - "homepage": "jsonql.org" -} diff --git a/packages/@jsonql/vue/public/favicon.ico b/packages/@jsonql/vue/public/favicon.ico deleted file mode 100644 index df36fcfb72584e00488330b560ebcf34a41c64c2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4286 zcmds*O-Phc6o&64GDVCEQHxsW(p4>LW*W<827=Unuo8sGpRux(DN@jWP-e29Wl%wj zY84_aq9}^Am9-cWTD5GGEo#+5Fi2wX_P*bo+xO!)p*7B;iKlbFd(U~_d(U?#hLj56 zPhFkj-|A6~Qk#@g^#D^U0XT1cu=c-vu1+SElX9NR;kzAUV(q0|dl0|%h|dI$%VICy zJnu2^L*Te9JrJMGh%-P79CL0}dq92RGU6gI{v2~|)p}sG5x0U*z<8U;Ij*hB9z?ei z@g6Xq-pDoPl=MANPiR7%172VA%r)kevtV-_5H*QJKFmd;8yA$98zCxBZYXTNZ#QFk2(TX0;Y2dt&WitL#$96|gJY=3xX zpCoi|YNzgO3R`f@IiEeSmKrPSf#h#Qd<$%Ej^RIeeYfsxhPMOG`S`Pz8q``=511zm zAm)MX5AV^5xIWPyEu7u>qYs?pn$I4nL9J!=K=SGlKLXpE<5x+2cDTXq?brj?n6sp= zphe9;_JHf40^9~}9i08r{XM$7HB!`{Ys~TK0kx<}ZQng`UPvH*11|q7&l9?@FQz;8 zx!=3<4seY*%=OlbCbcae?5^V_}*K>Uo6ZWV8mTyE^B=DKy7-sdLYkR5Z?paTgK-zyIkKjIcpyO z{+uIt&YSa_$QnN_@t~L014dyK(fOOo+W*MIxbA6Ndgr=Y!f#Tokqv}n<7-9qfHkc3 z=>a|HWqcX8fzQCT=dqVbogRq!-S>H%yA{1w#2Pn;=e>JiEj7Hl;zdt-2f+j2%DeVD zsW0Ab)ZK@0cIW%W7z}H{&~yGhn~D;aiP4=;m-HCo`BEI+Kd6 z={Xwx{TKxD#iCLfl2vQGDitKtN>z|-AdCN|$jTFDg0m3O`WLD4_s#$S diff --git a/packages/@jsonql/vue/public/index.html b/packages/@jsonql/vue/public/index.html deleted file mode 100644 index eac2e22b..00000000 --- a/packages/@jsonql/vue/public/index.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - vue - - - -
- - - diff --git a/packages/@jsonql/vue/src/App.vue b/packages/@jsonql/vue/src/App.vue deleted file mode 100644 index fcc56627..00000000 --- a/packages/@jsonql/vue/src/App.vue +++ /dev/null @@ -1,28 +0,0 @@ - - - - - diff --git a/packages/@jsonql/vue/src/assets/logo.png b/packages/@jsonql/vue/src/assets/logo.png deleted file mode 100644 index f3d2503fc2a44b5053b0837ebea6e87a2d339a43..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6849 zcmaKRcUV(fvo}bjDT-7nLI_nlK}sT_69H+`qzVWDA|yaU?}j417wLi^B1KB1SLsC& zL0ag7$U(XW5YR7p&Ux?sP$d4lvMt8C^+TcQu4F zQqv!UF!I+kw)c0jhd6+g6oCr9P?7)?!qX1ui*iL{p}sKCAGuJ{{W)0z1pLF|=>h}& zt(2Lr0Z`2ig8<5i%Zk}cO5Fm=LByqGWaS`oqChZdEFmc`0hSb#gg|Aap^{+WKOYcj zHjINK)KDG%&s?Mt4CL(T=?;~U@bU2x_mLKN!#GJuK_CzbNw5SMEJorG!}_5;?R>@1 zSl)jns3WlU7^J%=(hUtfmuUCU&C3%8B5C^f5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Wk^N$n;&Kf1RgVG2}2L-(0o)54C509C&77i zrjSi{X*WV=%C17((N^6R4Ya*4#6s_L99RtQ>m(%#nQ#wrRC8Y%yxkH;d!MdY+Tw@r zjpSnK`;C-U{ATcgaxoEpP0Gf+tx);buOMlK=01D|J+ROu37qc*rD(w`#O=3*O*w9?biwNoq3WN1`&Wp8TvKj3C z3HR9ssH7a&Vr<6waJrU zdLg!ieYz%U^bmpn%;(V%%ugMk92&?_XX1K@mwnVSE6!&%P%Wdi7_h`CpScvspMx?N zQUR>oadnG17#hNc$pkTp+9lW+MBKHRZ~74XWUryd)4yd zj98$%XmIL4(9OnoeO5Fnyn&fpQ9b0h4e6EHHw*l68j;>(ya`g^S&y2{O8U>1*>4zR zq*WSI_2o$CHQ?x0!wl9bpx|Cm2+kFMR)oMud1%n2=qn5nE&t@Fgr#=Zv2?}wtEz^T z9rrj=?IH*qI5{G@Rn&}^Z{+TW}mQeb9=8b<_a`&Cm#n%n~ zU47MvCBsdXFB1+adOO)03+nczfWa#vwk#r{o{dF)QWya9v2nv43Zp3%Ps}($lA02*_g25t;|T{A5snSY?3A zrRQ~(Ygh_ebltHo1VCbJb*eOAr;4cnlXLvI>*$-#AVsGg6B1r7@;g^L zFlJ_th0vxO7;-opU@WAFe;<}?!2q?RBrFK5U{*ai@NLKZ^};Ul}beukveh?TQn;$%9=R+DX07m82gP$=}Uo_%&ngV`}Hyv8g{u z3SWzTGV|cwQuFIs7ZDOqO_fGf8Q`8MwL}eUp>q?4eqCmOTcwQuXtQckPy|4F1on8l zP*h>d+cH#XQf|+6c|S{7SF(Lg>bR~l(0uY?O{OEVlaxa5@e%T&xju=o1`=OD#qc16 zSvyH*my(dcp6~VqR;o(#@m44Lug@~_qw+HA=mS#Z^4reBy8iV?H~I;{LQWk3aKK8$bLRyt$g?- -
-

{{ msg }}

-

- For a guide and recipes on how to configure / customize this project,
- check out the - vue-cli documentation. -

-

Installed CLI Plugins

- -

Essential Links

- -

Ecosystem

- -
- - - - - - diff --git a/packages/@jsonql/vue/src/main.js b/packages/@jsonql/vue/src/main.js deleted file mode 100644 index 63eb05f7..00000000 --- a/packages/@jsonql/vue/src/main.js +++ /dev/null @@ -1,8 +0,0 @@ -import Vue from 'vue' -import App from './App.vue' - -Vue.config.productionTip = false - -new Vue({ - render: h => h(App), -}).$mount('#app') -- Gitee From 5daa904b4aaca887fd8a6e9a60b9f5231f70e652 Mon Sep 17 00:00:00 2001 From: joelchu Date: Fri, 6 Mar 2020 16:47:28 +0800 Subject: [PATCH 12/12] add two new methods name and remove the issuer_name --- packages/constants/README.md | 3 ++- packages/constants/constants.json | 3 ++- packages/constants/main.js | 3 ++- packages/constants/module.js | 5 ++++- packages/constants/package.json | 2 +- packages/ws-client-core/src/options/defaults.js | 4 ++-- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/constants/README.md b/packages/constants/README.md index 1e6ac25d..7d37789d 100755 --- a/packages/constants/README.md +++ b/packages/constants/README.md @@ -53,9 +53,10 @@ non-javascript to develop your tool. You can also use the included `constants.js - CHECKED_KEY - AUTH_TYPE - LOGIN_NAME -- ISSUER_NAME - LOGOUT_NAME - VALIDATOR_NAME +- DISCONNECT_FN_NAME +- SWITCH_USER_FN_NAME - AUTH_HEADER - AUTH_CHECK_HEADER - BEARER diff --git a/packages/constants/constants.json b/packages/constants/constants.json index 8dbe86cf..397f4574 100644 --- a/packages/constants/constants.json +++ b/packages/constants/constants.json @@ -59,9 +59,10 @@ "CHECKED_KEY": "__checked__", "AUTH_TYPE": "auth", "LOGIN_NAME": "login", - "ISSUER_NAME": "login", "LOGOUT_NAME": "logout", "VALIDATOR_NAME": "validator", + "DISCONNECT_FN_NAME": "disconnect", + "SWITCH_USER_FN_NAME": "switch-user", "AUTH_HEADER": "Authorization", "AUTH_CHECK_HEADER": "authorization", "BEARER": "Bearer", diff --git a/packages/constants/main.js b/packages/constants/main.js index f9dfa41c..7106a1b6 100644 --- a/packages/constants/main.js +++ b/packages/constants/main.js @@ -59,9 +59,10 @@ module.exports = { "CHECKED_KEY": "__checked__", "AUTH_TYPE": "auth", "LOGIN_NAME": "login", - "ISSUER_NAME": "login", "LOGOUT_NAME": "logout", "VALIDATOR_NAME": "validator", + "DISCONNECT_FN_NAME": "disconnect", + "SWITCH_USER_FN_NAME": "switch-user", "AUTH_HEADER": "Authorization", "AUTH_CHECK_HEADER": "authorization", "BEARER": "Bearer", diff --git a/packages/constants/module.js b/packages/constants/module.js index fec52a9d..1a9b9a0c 100644 --- a/packages/constants/module.js +++ b/packages/constants/module.js @@ -62,13 +62,16 @@ export const ENUM_KEY = 'enumv' // need to change this because enum is a reserv export const ARGS_KEY = 'args' export const CHECKER_KEY = 'checker' export const ALIAS_KEY = 'alias' +// @TODO remove this later export const CHECKED_KEY = '__checked__' // author export const AUTH_TYPE = 'auth' export const LOGIN_NAME = 'login' -export const ISSUER_NAME = LOGIN_NAME // legacy issue need to replace them later +// export const ISSUER_NAME = LOGIN_NAME // legacy issue need to replace them later export const LOGOUT_NAME = 'logout' export const VALIDATOR_NAME = 'validator' +export const DISCONNECT_FN_NAME = 'disconnect' +export const SWITCH_USER_FN_NAME = 'switch-user' export const AUTH_HEADER = 'Authorization' export const AUTH_CHECK_HEADER = 'authorization' // this is for checking so it must be lowercase diff --git a/packages/constants/package.json b/packages/constants/package.json index 455b05e2..67769c73 100755 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-constants", - "version": "1.9.4", + "version": "1.9.5", "description": "All the share constants for json:ql tools", "main": "main.js", "module": "module.js", diff --git a/packages/ws-client-core/src/options/defaults.js b/packages/ws-client-core/src/options/defaults.js index 3a20e91d..43b1f333 100644 --- a/packages/ws-client-core/src/options/defaults.js +++ b/packages/ws-client-core/src/options/defaults.js @@ -9,7 +9,7 @@ import { ENUM_KEY, CHECKER_KEY, JSONQL_PATH, - ISSUER_NAME, + LOGIN_NAME, LOGOUT_NAME, IO_ROUNDTRIP_LOGIN, IO_HANDSHAKE_LOGIN, @@ -23,7 +23,7 @@ const AVAILABLE_METHODS = [IO_ROUNDTRIP_LOGIN, IO_HANDSHAKE_LOGIN] const wsBaseOptions = { debugOn: createConfig(false, [BOOLEAN_TYPE]), // useCallbackStyle: createConfig(false, [BOOLEAN_TYPE]), abandoned in 0.6.0 - loginHandlerName: createConfig(ISSUER_NAME, [STRING_TYPE]), + loginHandlerName: createConfig(LOGIN_NAME, [STRING_TYPE]), logoutHandlerName: createConfig(LOGOUT_NAME, [STRING_TYPE]), // this is for socket.io loginMethod: createConfig(IO_HANDSHAKE_LOGIN, [STRING_TYPE], {[ENUM_KEY]: AVAILABLE_METHODS}), -- Gitee