From 8c2459457ab10c7acf7aa362e70d11838447a6a4 Mon Sep 17 00:00:00 2001 From: joelchu Date: Sun, 15 Mar 2020 09:33:26 +0800 Subject: [PATCH 01/10] stub the intercom handle with all the available methods --- packages/ws-server-core/package.json | 6 +- .../src/handles/get-socket-handler.js | 25 +----- .../src/handles/handle-disconnet.js | 7 ++ .../src/handles/handle-intercom.js | 81 ++++++++++++------- 4 files changed, 66 insertions(+), 53 deletions(-) create mode 100644 packages/ws-server-core/src/handles/handle-disconnet.js diff --git a/packages/ws-server-core/package.json b/packages/ws-server-core/package.json index 980f64cd..a272e9c3 100644 --- a/packages/ws-server-core/package.json +++ b/packages/ws-server-core/package.json @@ -30,10 +30,10 @@ "debug": "^4.1.1", "esm": "^3.2.25", "fs-extra": "^8.1.0", - "jsonql-constants": "^1.9.9", + "jsonql-constants": "^1.9.11", "jsonql-errors": "^1.1.10", "jsonql-jwt": "^1.3.9", - "jsonql-params-validator": "^1.5.3", + "jsonql-params-validator": "^1.6.0", "jsonql-resolver": "^1.1.2", "jsonql-utils": "^1.1.3", "lodash": "^4.17.15", @@ -41,7 +41,7 @@ }, "devDependencies": { "ava": "^3.5.0", - "jsonql-contract": "^1.8.8" + "jsonql-contract": "^1.8.10" }, "ava": { "files": [ diff --git a/packages/ws-server-core/src/handles/get-socket-handler.js b/packages/ws-server-core/src/handles/get-socket-handler.js index 1c47d9cb..3c10df54 100644 --- a/packages/ws-server-core/src/handles/get-socket-handler.js +++ b/packages/ws-server-core/src/handles/get-socket-handler.js @@ -1,15 +1,9 @@ const { - LOGOUT_EVENT_NAME, - SA_LOGIN_EVENT_NAME, - INTER_COM_EVENT_NAME, - SOCKET_PING_EVENT_NAME, + INTERCOM_RESOLVER_NAME, NSP_GROUP } = require('jsonql-constants') const { getResolverFromPayload } = require('jsonql-utils') -const { handleInitPing } = require('./handle-init-ping') const { handleInterCom } = require('./handle-intercom') -const { handleLogout } = require('./handle-logout') -const { handleStandaloneLogin } = require('./handle-standalone-login') const { handleNspResolvers } = require('./handle-nsp-resolvers') const { getRainbowDebug } = require('../share/helpers') @@ -52,23 +46,10 @@ function getSocketHandler(config, ws, deliverFn, req, connectedNamespace, payloa const args = payload[resolverName] // it might be the special internal event? switch (true) { - case resolverName === SOCKET_PING_EVENT_NAME: - - return handleInitPing(deliverFn, req, config) - - case resolverName === LOGOUT_EVENT_NAME: - debug('getSocketHandler:logout') - // we don't need to send anything back @TBC do we need the config - return handleLogout(ws, req, args, config) - - case resolverName === SA_LOGIN_EVENT_NAME: - debug('getSocketHandler:standaloneLogin') - return handleStandaloneLogin(deliverFn, ws, req, args, config) - - case resolverName === INTER_COM_EVENT_NAME: + case resolverName === INTERCOM_RESOLVER_NAME: debug('getSocketHandler:intercom') // We don't need to send anything back // @TBC do we need the config - return handleInterCom(config, ws, req, args, userdata) + return handleInterCom(config, ws, deliverFn, req, connectedNamespace, args, userdata) default: const contractParam = matchResolverByNamespace(resolverName, connectedNamespace, nspGroup) diff --git a/packages/ws-server-core/src/handles/handle-disconnet.js b/packages/ws-server-core/src/handles/handle-disconnet.js new file mode 100644 index 00000000..a8643454 --- /dev/null +++ b/packages/ws-server-core/src/handles/handle-disconnet.js @@ -0,0 +1,7 @@ +// when user disconnect or can we issue a reverse disconnect from the same api? + +function handleDisconnect(config, ws, deliverFn, req, connectedNamespace, args, userdata) { + +} + +module.exports = { handleDisconnect } \ No newline at end of file diff --git a/packages/ws-server-core/src/handles/handle-intercom.js b/packages/ws-server-core/src/handles/handle-intercom.js index 047198bf..8cfd4217 100644 --- a/packages/ws-server-core/src/handles/handle-intercom.js +++ b/packages/ws-server-core/src/handles/handle-intercom.js @@ -1,42 +1,67 @@ +/* +We now group all the ping, login, logout, disconnect, switch event +into one group as the intercom, and all using the same internal resolverName INTERCOME_RESOLVER_NAME +and use the type to tell the different, the main com type REPLY ACKNOWLEDGE will get handle by the ee +but the rest are outside of that scope, therefore it won't affect the currenct operation +*/ const { getDebug } = require('../share/helpers') const debug = getDebug('handle-intercome') +const { + SOCKET_PING_EVENT_NAME, + SA_LOGIN_EVENT_NAME, + LOGOUT_EVENT_NAME, + DISCONNECT_EVENT_NAME + // LOGIN_EVENT_NAME // TBC +} = require('jsonql-constants') +const { handleInitPing } = require('./handle-init-ping') +const { handleLogout } = require('./handle-logout') +const { handleStandaloneLogin } = require('./handle-standalone-login') +const { handleDisconnect } = require('./handle-disconnet') +const { handleUnknownPayload } = require('./handle-unknown-payload') -/** - * handle the one last call when the user issue disconnect - * - */ -function handleDisconnect() { - -} - -/** - * After the user connected (after check) we need to send over a handshake with a CSRF token - * And it will be using it to com onward - */ -function handleConnect() { - -} +/* +case resolverName === SOCKET_PING_EVENT_NAME: + + return handleInitPing(deliverFn, req, config) -/** - * @TBC feature - */ -function handleSwitchUser() { + case resolverName === LOGOUT_EVENT_NAME: + debug('getSocketHandler:logout') + // we don't need to send anything back @TBC do we need the config + return handleLogout(ws, req, args, config) -} + case resolverName === SA_LOGIN_EVENT_NAME: + debug('getSocketHandler:standaloneLogin') + return handleStandaloneLogin(deliverFn, ws, req, args, config) +*/ /** * @TODO handle the intercom event disconnect / switch-user (future feature) + * @param {object} config configuraton + * @param {object} ws the socket instance * @param {function} deliverFn framework specific to send out message - * @param {*} ws - * @param {*} req - * @param {*} json - * @param {*} socketFns - * @param {*} opts - * @param {*} userdata + * @param {object} req the request object + * @param {string} connectedNamespace the namesapce its connected to + * @param {array} args extract from the payload, the first is the event name + * @param {*} userdata it could be empty most of the time + * @return {void} nothing return just send back a reply */ -function handleInterCom(deliverFn, req, json, socketFns, opts, userdata) { - debug(`handleIntercom called`, json) +function handleInterCom(config, ws, deliverFn, req, connectedNamespace, args, userdata) { + const eventName = args[0] + args.splice(0, 1) // take the first one out, it could be empty + + switch (eventName) { + case SOCKET_PING_EVENT_NAME: + return handleInitPing(config, ws, deliverFn, req, connectedNamespace, args) + case SA_LOGIN_EVENT_NAME: + return handleStandaloneLogin(config, ws, deliverFn, req, connectedNamespace, args) + case LOGOUT_EVENT_NAME: + return handleLogout(config, ws, deliverFn, req, connectedNamespace, args, userdata) + case DISCONNECT_EVENT_NAME: + return handleDisconnect(config, ws, deliverFn, req, connectedNamespace, args, userdata) + default: + handleUnknownPayload(config, ws, deliverFn, req, connectedNamespace, args, userdata) + } } module.exports = { handleInterCom } -- Gitee From 5c256f2f951c2621fe1363c79c0255f5d5d4734b Mon Sep 17 00:00:00 2001 From: joelchu Date: Sun, 15 Mar 2020 10:48:07 +0800 Subject: [PATCH 02/10] Making some major change to the jsonql-constants by breaking it up in to related section files, and from now on when module import can directly take what is relevant, althought there will some overlapping for node is the same using just one interface to import everything --- packages/constants/module.js | 143 +----------------- packages/constants/package.json | 2 +- packages/constants/prop.js | 42 +++++ packages/constants/socket.js | 110 ++++++++++++++ packages/constants/validation.js | 27 ++++ .../src/handles/handle-disconnet.js | 13 ++ .../src/handles/handle-init-ping.js | 27 ++-- .../src/handles/handle-intercom.js | 18 +-- packages/ws-server-core/src/options/props.js | 11 +- .../src/share/resolver-methods.js | 15 +- 10 files changed, 240 insertions(+), 168 deletions(-) create mode 100644 packages/constants/prop.js create mode 100644 packages/constants/socket.js create mode 100644 packages/constants/validation.js diff --git a/packages/constants/module.js b/packages/constants/module.js index 291e782a..90cb479b 100644 --- a/packages/constants/module.js +++ b/packages/constants/module.js @@ -65,21 +65,14 @@ export const KEY_WORD = 'continue' export const PUBLIC_KEY = 'public' export const PRIVATE_KEY = 'private' -export const TYPE_KEY = 'type' -export const OPTIONAL_KEY = 'optional' -export const ENUM_KEY = 'enumv' // need to change this because enum is a reserved word -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 AUTH_NAME = AUTH_TYPE // alias -export const LOGIN_NAME = 'login' +export const LOGIN_FN_NAME = 'login' // 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 LOGOUT_FN_NAME = 'logout' +export const VALIDATOR_FN_NAME = 'validator' export const DISCONNECT_FN_NAME = 'disconnect' export const SWITCH_USER_FN_NAME = 'switch-user' @@ -111,30 +104,6 @@ export const ACCEPTED_JS_TYPES = [ ES_TYPE ] // not accept this TS_TYPE at the moment -export const OR_SEPERATOR = '|' - -export const FUNCTION_TYPE = 'function' -export const STRING_TYPE = 'string' -export const BOOLEAN_TYPE = 'boolean' -export const ARRAY_TYPE = 'array' -export const OBJECT_TYPE = 'object' -export const ANY_TYPE = 'any' - -export const NUMBER_TYPE = 'number' -export const NUMBER_TYPES = ['int', 'integer', 'float', 'double', 'decimal'] -// supported types -export const SUPPORTED_TYPES = [ - NUMBER_TYPE, - STRING_TYPE, - BOOLEAN_TYPE, - ARRAY_TYPE, - OBJECT_TYPE, - ANY_TYPE -] - -export const ARRAY_TS_TYPE_LFT = 'Array<' -export const ARRAY_TYPE_LFT = 'array.<' -export const ARRAY_TYPE_RGT = '>' // for contract cli export const RETURN_AS_FILE = 'file' export const RETURN_AS_JSON = 'json' @@ -146,119 +115,17 @@ export const RETURN_AS_ENUM = [ export const NO_ERROR_MSG = 'No message' export const NO_STATUS_CODE = -1 -// use throughout the clients -export const SOCKET_PING_EVENT_NAME = '__ping__' // when init connection do a ping -export const SWITCH_USER_EVENT_NAME = '__switch__' -export const LOGIN_EVENT_NAME = '__login__' -export const LOGOUT_EVENT_NAME = '__logout__' -// when ws switch on standalone mode then we add this event to allow -// perform a standalone login method -export const SA_LOGIN_EVENT_NAME = '__standalone_login__' -// after the user issue the disconnect, then we need a reconnect -export const RECONNECT_EVENT_NAME = '__reconnect__' -// when we receive the token and decode the userdata -// we will inject two more properties into the userdata object -export const SOCKET_CLIENT_ID_KEY = '__socket_client_id_key__' -export const SOCKET_CLIENT_TS_KEY = '__socket_client_ts_key__' -// at the moment we only have __logout__ regardless enableAuth is enable -// this is incorrect, because logout suppose to come after login -// and it should only logout from auth nsp, instead of clear out the -// connection, the following new event @1.9.2 will correct this edge case -// although it should never happens, but in some edge case might want to -// disconnect from the current server, then re-establish connection later -export const CONNECTED_EVENT_NAME = '__connected__' -export const DISCONNECT_EVENT_NAME = '__disconnect__' -// instead of using an event name in place of resolverName in the param -// we use this internal resolverName instead, and in type using the event names -export const INTERCOM_RESOLVER_NAME = '__intercom__' -// group the inter communcation event name in one then for the server -// to create a handler to handle this kind of event -// export const INTER_COM_EVENT_NAME = '__inter_com__' -export const INTER_COM_EVENT_NAMES = [ - CONNECTED_EVENT_NAME, - SWITCH_USER_EVENT_NAME, - DISCONNECT_EVENT_NAME -] -// for ws servers -export const WS_REPLY_TYPE = '__reply__' -export const WS_EVT_NAME = '__event__' -export const WS_DATA_NAME = '__data__' -export const WS_IS_REPLY_KEYS = [ - WS_REPLY_TYPE, - WS_EVT_NAME, - WS_DATA_NAME -] -// this is somewhat vague about what is suppose to do -export const EMIT_REPLY_TYPE = 'emit_reply' -export const ACKNOWLEDGE_REPLY_TYPE = 'acknowledge_reply' -export const ERROR_TYPE = ERROR_KEY // Should replace with ERROR_KEY -export const NSP_GROUP = 'nspGroup' -export const PUBLIC_NAMESPACE = 'publicNamespace' -export const JS_WS_SOCKET_IO_NAME = 'socket.io' -export const JS_WS_NAME = 'ws' -export const JS_PRIMUS_NAME = 'primus' -export const GO_WS_COOLPY7_NAME = 'coolpy7' -// type name and Alias -export const SOCKET_TYPE_KEY = 'serverType' //1.9.1 -export const SOCKET_TYPE_CLIENT_ALIAS = 'socketClientType' // 1.9.0 -export const SOCKET_TYPE_SERVER_ALIAS = 'socketServerType' // 1.9.1 -// for ws client, 1.9.3 breaking change to name them as FN instead of PROP -export const ON_MESSAGE_FN_NAME = 'onMessage' -export const ON_RESULT_FN_NAME = 'onResult' -export const ON_ERROR_FN_NAME = 'onError' -export const ON_READY_FN_NAME = 'onReady' -export const ON_LOGIN_FN_NAME = 'onLogin' // new @1.8.6 -// the actual method name client.resolverName.send -export const SEND_MSG_FN_NAME = 'send' -// this one is for nodeClient inject into the resolver -export const CLIENT_PROP_NAME = 'client' -export const USERDATA_PROP_NAME = 'userdata' + // this are property keys used in the configuration options // and re-use elsewhere export const INIT_CLIENT_PROP_KEY = 'nodeClient' export const INIT_CONTRACT_PROP_KEY = 'initContract' -// this is the default time to wait for reply if exceed this then we -// trigger an error --> 5 seconds -export const DEFAULT_WS_WAIT_TIME = 5000 -export const DEFAULT_RETRY_TIME = 3000 // 1.9.0 -export const TIMEOUT_ERR_MSG = 'timeout' -export const NOT_LOGIN_ERR_MSG = 'NOT LOGIN' -// for crypto operation -export const BASE64_FORMAT = 'base64' -export const HEX_FORMAT = 'hex' -export const UTF8_FORMAT = 'utf8' -export const RSA_FORMATS = [ - BASE64_FORMAT, - HEX_FORMAT -] -export const RSA_ALGO = 'RS256' -export const HSA_ALGO = 'HS256' -export const JWT_SUPPORT_ALGOS = [ - RSA_ALGO, - HSA_ALGO -] -export const RSA_PRIVATE_KEY_HEADER = 'BEGIN RSA PRIVATE KEY' -export const RSA_MIN_MODULE_LEN = 1024 -export const RSA_MAX_MODULE_LEN = 4096 -export const TOKEN_PARAM_NAME = 'token' -export const IO_ROUNDTRIP_LOGIN = 'roundtip' -export const IO_HANDSHAKE_LOGIN = 'handshake' -export const IO_LOGIN_METHODS = [ - IO_ROUNDTRIP_LOGIN, - IO_HANDSHAKE_LOGIN -] - -export const PEM_EXT = 'pem' -export const PUBLIC_KEY_NAME = 'publicKey' -export const PRIVATE_KEY_NAME = 'privateKey' -export const DEFAULT_PUBLIC_KEY_FILE = [PUBLIC_KEY_NAME, PEM_EXT].join('.') -export const DEFAULT_PRIVATE_KEY_FILE = [PRIVATE_KEY_NAME, PEM_EXT].join('.') // status export const SUCCESS_STATUS = 200 export const UNAUTHORIZED_STATUS = 401 diff --git a/packages/constants/package.json b/packages/constants/package.json index a1c0a216..006eb9b7 100755 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-constants", - "version": "1.9.11", + "version": "2.0.0", "description": "All the share constants for jsonql tools", "main": "main.js", "module": "module.js", diff --git a/packages/constants/prop.js b/packages/constants/prop.js new file mode 100644 index 00000000..458ced09 --- /dev/null +++ b/packages/constants/prop.js @@ -0,0 +1,42 @@ +// this is all the key name for the config check map +// all subfix with prop_key + +export const TYPE_KEY = 'type' +export const OPTIONAL_KEY = 'optional' +export const ENUM_KEY = 'enumv' // need to change this because enum is a reserved word +export const ARGS_KEY = 'args' +export const CHECKER_KEY = 'checker' +export const ALIAS_KEY = 'alias' +// @TODO remove this later +export const CHECKED_KEY = '__checked__' + +// first part port from the ws-server-core +export const APP_DIR_PROP_KEY = 'appDir' + +export const AUTH_TO_PROP_KEY = 'authTimeout' +export const ENABLE_AUTH_PROP_KEY = 'enableAuth' +export const USE_JWT_PROP_KEY = 'useJwt' +export const RESOLVER_DIR_PROP_KEY = 'resolverDir' +export const CONTRACT_DIR_PROP_KEY = 'contractDir' + +export const INIT_CONNECTION_FN_NAME_PROP_KEY = 'initConnectionHandlerName' +export const LOGIN_FN_NAME_PROP_KEY = 'loginHandlerName' +export const LOGOUT_FN_NAME_PROP_KEY = 'logoutHandlerName' +export const DISCONNECT_FN_NAME_PROP_KEY = 'disconnectHandlerName' +export const SWITCH_USER_FN_NAME_PROP_KEY = 'switchUserHandlerName' +// this has changed and now make more sense +export const PUBLIC_FN_DIR_PROP_KEY = 'publicResolverDir' +export const PRIVATE_FN_DIR_DROP_KEY = 'privateResolverDir' + +// socket specific +export const ALGORITHM_PROP_KEY = 'algorithm' +export const KEYS_DIR_PROP_KEY = 'keysDir' +export const SOCKET_IO_AUTH_TYPE_PROP_KEY = 'socketIoAuthType' +export const SERVER_INIT_OPT_PROP_KEY = 'serverInitOption' +// type name and Alias +export const SOCKET_TYPE_PROP_KEY = 'serverType' //1.9.1 +export const SOCKET_TYPE_CLIENT_ALIAS = 'socketClientType' // 1.9.0 +export const SOCKET_TYPE_SERVER_ALIAS = 'socketServerType' // 1.9.1 + +export const CSRF_PROP_KEY = 'csrf' +export const ALLOW_ORIGIN_PROP_KEY = 'allowOrigin' diff --git a/packages/constants/socket.js b/packages/constants/socket.js new file mode 100644 index 00000000..776f9c65 --- /dev/null +++ b/packages/constants/socket.js @@ -0,0 +1,110 @@ +// the constants file is gettig too large +// we need to split up and group the related constant in one file +// also it makes the other module easiler to id what they are importing +// use throughout the clients +export const SOCKET_PING_EVENT_NAME = '__ping__' // when init connection do a ping +export const SWITCH_USER_EVENT_NAME = '__switch__' +export const LOGIN_EVENT_NAME = '__login__' +export const LOGOUT_EVENT_NAME = '__logout__' +// when ws switch on standalone mode then we add this event to allow +// perform a standalone login method +export const SA_LOGIN_EVENT_NAME = '__standalone_login__' +// after the user issue the disconnect, then we need a reconnect +export const RECONNECT_EVENT_NAME = '__reconnect__' +// when we receive the token and decode the userdata +// we will inject two more properties into the userdata object +export const SOCKET_CLIENT_ID_KEY = '__socket_client_id_key__' +export const SOCKET_CLIENT_TS_KEY = '__socket_client_ts_key__' +// at the moment we only have __logout__ regardless enableAuth is enable +// this is incorrect, because logout suppose to come after login +// and it should only logout from auth nsp, instead of clear out the +// connection, the following new event @1.9.2 will correct this edge case +// although it should never happens, but in some edge case might want to +// disconnect from the current server, then re-establish connection later +export const CONNECTED_EVENT_NAME = '__connected__' +export const DISCONNECT_EVENT_NAME = '__disconnect__' +// instead of using an event name in place of resolverName in the param +// we use this internal resolverName instead, and in type using the event names +export const INTERCOM_RESOLVER_NAME = '__intercom__' +// group the inter communcation event name in one then for the server +// to create a handler to handle this kind of event +// export const INTER_COM_EVENT_NAME = '__inter_com__' +export const INTER_COM_EVENT_NAMES = [ + CONNECTED_EVENT_NAME, + SWITCH_USER_EVENT_NAME, + DISCONNECT_EVENT_NAME +] +// for ws servers +export const WS_REPLY_TYPE = '__reply__' +export const WS_EVT_NAME = '__event__' +export const WS_DATA_NAME = '__data__' +export const WS_IS_REPLY_KEYS = [ + WS_REPLY_TYPE, + WS_EVT_NAME, + WS_DATA_NAME +] + +// for ws client, 1.9.3 breaking change to name them as FN instead of PROP +export const ON_MESSAGE_FN_NAME = 'onMessage' +export const ON_RESULT_FN_NAME = 'onResult' +export const ON_ERROR_FN_NAME = 'onError' +export const ON_READY_FN_NAME = 'onReady' +export const ON_LOGIN_FN_NAME = 'onLogin' // new @1.8.6 +// the actual method name client.resolverName.send +export const SEND_MSG_FN_NAME = 'send' + +// this one is for nodeClient inject into the resolver +export const CLIENT_PROP_NAME = 'client' +export const USERDATA_PROP_NAME = 'userdata' + +// this is somewhat vague about what is suppose to do +export const EMIT_REPLY_TYPE = 'emit_reply' +export const ACKNOWLEDGE_REPLY_TYPE = 'acknowledge_reply' +export const ERROR_TYPE = ERROR_KEY // Should replace with ERROR_KEY + +export const NSP_GROUP = 'nspGroup' +export const PUBLIC_NAMESPACE = 'publicNamespace' + +export const JS_WS_SOCKET_IO_NAME = 'socket.io' +export const JS_WS_NAME = 'ws' +export const JS_PRIMUS_NAME = 'primus' +export const GO_WS_COOLPY7_NAME = 'coolpy7' + + +// this is the default time to wait for reply if exceed this then we +// trigger an error --> 5 seconds +export const DEFAULT_WS_WAIT_TIME = 5000 +export const DEFAULT_RETRY_TIME = 3000 // 1.9.0 +export const TIMEOUT_ERR_MSG = 'timeout' +export const NOT_LOGIN_ERR_MSG = 'NOT LOGIN' +// for crypto operation +export const BASE64_FORMAT = 'base64' +export const HEX_FORMAT = 'hex' +export const UTF8_FORMAT = 'utf8' +export const RSA_FORMATS = [ + BASE64_FORMAT, + HEX_FORMAT +] +export const RSA_ALGO = 'RS256' +export const HSA_ALGO = 'HS256' +export const JWT_SUPPORT_ALGOS = [ + RSA_ALGO, + HSA_ALGO +] +export const RSA_PRIVATE_KEY_HEADER = 'BEGIN RSA PRIVATE KEY' +export const RSA_MIN_MODULE_LEN = 1024 +export const RSA_MAX_MODULE_LEN = 4096 +export const TOKEN_PARAM_NAME = 'token' +export const IO_ROUNDTRIP_LOGIN = 'roundtip' +export const IO_HANDSHAKE_LOGIN = 'handshake' +export const IO_LOGIN_METHODS = [ + IO_ROUNDTRIP_LOGIN, + IO_HANDSHAKE_LOGIN +] + +export const PEM_EXT = 'pem' +export const PUBLIC_KEY_NAME = 'publicKey' +export const PRIVATE_KEY_NAME = 'privateKey' + +export const DEFAULT_PUBLIC_KEY_FILE = [PUBLIC_KEY_NAME, PEM_EXT].join('.') +export const DEFAULT_PRIVATE_KEY_FILE = [PRIVATE_KEY_NAME, PEM_EXT].join('.') diff --git a/packages/constants/validation.js b/packages/constants/validation.js new file mode 100644 index 00000000..dbf943a0 --- /dev/null +++ b/packages/constants/validation.js @@ -0,0 +1,27 @@ +// validation related constants + + +export const OR_SEPERATOR = '|' + +export const FUNCTION_TYPE = 'function' +export const STRING_TYPE = 'string' +export const BOOLEAN_TYPE = 'boolean' +export const ARRAY_TYPE = 'array' +export const OBJECT_TYPE = 'object' +export const ANY_TYPE = 'any' + +export const NUMBER_TYPE = 'number' +export const NUMBER_TYPES = ['int', 'integer', 'float', 'double', 'decimal'] +// supported types +export const SUPPORTED_TYPES = [ + NUMBER_TYPE, + STRING_TYPE, + BOOLEAN_TYPE, + ARRAY_TYPE, + OBJECT_TYPE, + ANY_TYPE +] + +export const ARRAY_TS_TYPE_LFT = 'Array<' +export const ARRAY_TYPE_LFT = 'array.<' +export const ARRAY_TYPE_RGT = '>' \ No newline at end of file diff --git a/packages/ws-server-core/src/handles/handle-disconnet.js b/packages/ws-server-core/src/handles/handle-disconnet.js index a8643454..4fe89450 100644 --- a/packages/ws-server-core/src/handles/handle-disconnet.js +++ b/packages/ws-server-core/src/handles/handle-disconnet.js @@ -1,5 +1,18 @@ // when user disconnect or can we issue a reverse disconnect from the same api? +/** + * This method suppose to try to take in the user defined disconnect interceptor + * also we could do some internal clean up? but this is framework specific operation + * so this should be the last in the chain, or the first? + * @param {object} config configuraton + * @param {object} ws the socket instance + * @param {function} deliverFn framework specific to send out message + * @param {object} req the request object + * @param {string} connectedNamespace the namesapce its connected to + * @param {array} args extract from the payload, the first is the event name + * @param {*} userdata it could be empty most of the time + * @return {void} nothing return just send back a reply + */ function handleDisconnect(config, ws, deliverFn, req, connectedNamespace, args, userdata) { } diff --git a/packages/ws-server-core/src/handles/handle-init-ping.js b/packages/ws-server-core/src/handles/handle-init-ping.js index 1d779bb4..9ba5298e 100644 --- a/packages/ws-server-core/src/handles/handle-init-ping.js +++ b/packages/ws-server-core/src/handles/handle-init-ping.js @@ -7,22 +7,29 @@ // e.g. allow the user to store the token in a Redis, and subsequenely check it const nanoid = require('nanoid') -const { CSRF_HEADER_KEY, SOCKET_PING_EVENT_NAME } = require('jsonql-constants') -const { deliverMsg } = require('../share/resolver-methods') +const { + CSRF_HEADER_KEY, + SOCKET_PING_EVENT_NAME +} = require('jsonql-constants') +const { deliverIntercomMsg } = require('../share/resolver-methods') + /** * @TODO handle the intercom event disconnect / switch-user (future feature) - * @param {function} deliveryFn framework specific to send out message - * @param {object} req request object - * @param {object} config configuration - * @return {void} + * @param {object} config configuraton + * @param {object} ws the socket instance + * @param {function} deliverFn framework specific to send out message + * @param {object} req the request object + * @param {string} connectedNamespace the namesapce its connected to + * @param {array} args extract from the payload, the first is the event name + * @return {void} nothing return just send back a reply */ -function handleInitPing(deliverFn, req, config) { - debug(`handleIntercom called`, json) +function handleInitPing(config, ws, deliverFn, req, connectedNamespace, args) { + const token = nanoid() // @TODO add hook to process this token + const payload = {[CSRF_HEADER_KEY]: token} - deliverMsg(deliverFn, SOCKET_PING_EVENT_NAME, {[CSRF_HEADER_KEY]: token}) - + deliverIntercomMsg(deliverFn, payload, SOCKET_PING_EVENT_NAME) } module.exports = { handleInitPing } \ No newline at end of file diff --git a/packages/ws-server-core/src/handles/handle-intercom.js b/packages/ws-server-core/src/handles/handle-intercom.js index 8cfd4217..1c422f10 100644 --- a/packages/ws-server-core/src/handles/handle-intercom.js +++ b/packages/ws-server-core/src/handles/handle-intercom.js @@ -20,21 +20,6 @@ const { handleStandaloneLogin } = require('./handle-standalone-login') const { handleDisconnect } = require('./handle-disconnet') const { handleUnknownPayload } = require('./handle-unknown-payload') -/* -case resolverName === SOCKET_PING_EVENT_NAME: - - return handleInitPing(deliverFn, req, config) - - case resolverName === LOGOUT_EVENT_NAME: - debug('getSocketHandler:logout') - // we don't need to send anything back @TBC do we need the config - return handleLogout(ws, req, args, config) - - case resolverName === SA_LOGIN_EVENT_NAME: - debug('getSocketHandler:standaloneLogin') - return handleStandaloneLogin(deliverFn, ws, req, args, config) -*/ - /** * @TODO handle the intercom event disconnect / switch-user (future feature) * @param {object} config configuraton @@ -47,6 +32,9 @@ case resolverName === SOCKET_PING_EVENT_NAME: * @return {void} nothing return just send back a reply */ function handleInterCom(config, ws, deliverFn, req, connectedNamespace, args, userdata) { + // the most important one to take a look at + debug('handleIntercom', args) + const eventName = args[0] args.splice(0, 1) // take the first one out, it could be empty diff --git a/packages/ws-server-core/src/options/props.js b/packages/ws-server-core/src/options/props.js index 2ccd2179..9cf3c533 100644 --- a/packages/ws-server-core/src/options/props.js +++ b/packages/ws-server-core/src/options/props.js @@ -29,10 +29,13 @@ const { SOCKET_TYPE_KEY, SOCKET_TYPE_SERVER_ALIAS, + INIT_CONNECTION_FN_NAME, DISCONNECT_FN_NAME, SWITCH_USER_FN_NAME, LOGIN_NAME, - LOGOUT_NAME + LOGOUT_NAME, + + CSRF_PROP_KEY } = require('jsonql-constants') const { SOCKET_IO } = require('./constants') @@ -57,7 +60,7 @@ const wsBaseOptions = { // we only want the keys directory then we read it back 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 - interComEventHandlerPath: createConfig(null, [STRING_TYPE]), + initConnectionHandlerName: createConfig(INIT_CONNECTION_FN_NAME, [STRING_TYPE]), loginHandlerName: createConfig(LOGIN_NAME, [STRING_TYPE]), logoutHandlerName: createConfig(LOGOUT_NAME, [STRING_TYPE]), disconnectHandlerName: createConfig(DISCONNECT_FN_NAME, [STRING_TYPE]), @@ -72,7 +75,9 @@ const wsBaseOptions = { }), // check the origin if we can allowOrgin: createConfig(['*'], [ARRAY_TYPE]), - serverInitOption: createConfig({}, [OBJECT_TYPE]) + serverInitOption: createConfig({}, [OBJECT_TYPE]), + // placeholder for now + [CSRF_PROP_KEY]: createConfig('', [STRING_TYPE]) } // we have to create a standlone prop to check if the user pass the socket server config first const socketAppProps = { diff --git a/packages/ws-server-core/src/share/resolver-methods.js b/packages/ws-server-core/src/share/resolver-methods.js index 4108da33..ce5e18b0 100644 --- a/packages/ws-server-core/src/share/resolver-methods.js +++ b/packages/ws-server-core/src/share/resolver-methods.js @@ -4,6 +4,7 @@ const { packError } = require('jsonql-utils') const { isNotEmpty, validateAsync } = require('jsonql-params-validator') const { getRainbowDebug, createWsReply } = require('./helpers') const { + INTERCOM_RESOLVER_NAME, ACKNOWLEDGE_REPLY_TYPE, ERROR_TYPE } = require('jsonql-constants') @@ -70,9 +71,21 @@ function deliverMsg(deliverFn, resolverName, result, type = ACKNOWLEDGE_REPLY_TY .then(result => handleResult(deliverFn, resolverName, result, type)) } +/** + * Wrapper method to send back a intercom reply + * @param {function} deliverFn framework specific send method + * @param {*} payload things we want to send back + * @param {string} type type of intercom event + * @return {void} + */ +function deliverIntercomMsg(deliverFn, payload, type) { + deliverFn(createWsReply(type, INTERCOM_RESOLVER_NAME, payload)) +} + module.exports = { validateInput, deliverMsg, - handleError + handleError, + deliverIntercomMsg } -- Gitee From 65deb5f5187270729ec216a02db2b1749e9ed025 Mon Sep 17 00:00:00 2001 From: joelchu Date: Sun, 15 Mar 2020 11:39:29 +0800 Subject: [PATCH 03/10] finish all the base setup and split up the constants into different files --- packages/constants/base.js | 139 ++++++++++++++++++++++++++++++ packages/constants/build.js | 12 ++- packages/constants/import.js | 4 + packages/constants/module.js | 145 ++------------------------------ packages/constants/package.json | 8 +- packages/constants/prop.js | 56 ++++++++++++ 6 files changed, 224 insertions(+), 140 deletions(-) create mode 100644 packages/constants/base.js create mode 100644 packages/constants/import.js diff --git a/packages/constants/base.js b/packages/constants/base.js new file mode 100644 index 00000000..90cb479b --- /dev/null +++ b/packages/constants/base.js @@ -0,0 +1,139 @@ +export const EXT = 'js' // we might do a ts in the future +export const TS_EXT = 'ts' + +export const HELLO = 'Hello world!' +export const HELLO_FN = 'helloWorld' +// the core stuff to id if it's calling with jsonql +export const DATA_KEY = 'data' +export const ERROR_KEY = 'error' + +export const JSONQL_PATH = 'jsonql' +// according to the json query spec +export const CONTENT_TYPE = 'application/vnd.api+json' +export const CHARSET = 'charset=utf-8' +export const DEFAULT_HEADER = { + 'Accept': CONTENT_TYPE, + 'Content-Type': [ CONTENT_TYPE, CHARSET ].join('') +} + +// export const INDEX = 'index' use INDEX_KEY instead +export const DEFAULT_TYPE = 'any' +// contract file names +// export const DEFAULT_FILE_NAME = 'contract.json' // @TODO remove once all changed +// export const PUBLIC_FILE_NAME = 'public-contract.json' // @TODO remove once all changed +export const DEFAULT_CONTRACT_FILE_NAME = 'contract.json' +export const PUBLIC_CONTRACT_FILE_NAME = 'public-contract.json' +// this is for the ES6 module import and export @TODO remove later +export const DEFAULT_RESOLVER_LIST_FILE_NAME = 'resolver.js' +export const DEFAULT_RESOLVER_IMPORT_FILE_NAME = 'import.js' + +export const MODULE_TYPE = 'module' +export const SCRIPT_TYPE = 'script' + +// @TODO remove this is not in use +// export const CLIENT_CONFIG_FILE = '.clients.json' +// export const CONTRACT_CONFIG_FILE = 'jsonql-contract-config.js' +// type of resolvers +export const QUERY_NAME = 'query' +export const MUTATION_NAME = 'mutation' +export const SOCKET_NAME = 'socket' +export const CONTRACT_NAME = 'contract' +export const RESOLVER_TYPES = [ + QUERY_NAME, + MUTATION_NAME, + SOCKET_NAME +] +// for calling the mutation +export const PAYLOAD_PARAM_NAME = 'payload' // @TODO shortern them +export const CONDITION_PARAM_NAME = 'condition' +export const RESOLVER_PARAM_NAME = 'resolverName' +export const QUERY_ARG_NAME = 'args' +export const TIMESTAMP_PARAM_NAME = 'TS' +export const MUTATION_ARGS = [ + RESOLVER_PARAM_NAME, + PAYLOAD_PARAM_NAME, + CONDITION_PARAM_NAME +] +// new jsonp +export const JSONP_CALLBACK_NAME = 'jsonqlJsonpCallback' + +// methods allow +export const API_REQUEST_METHODS = ['POST', 'PUT'] +export const CONTRACT_REQUEST_METHODS = ['GET', 'HEAD'] +// for contract-cli +export const KEY_WORD = 'continue' +export const PUBLIC_KEY = 'public' +export const PRIVATE_KEY = 'private' + + +// author +export const AUTH_TYPE = 'auth' +export const AUTH_NAME = AUTH_TYPE // alias +export const LOGIN_FN_NAME = 'login' +// export const ISSUER_NAME = LOGIN_NAME // legacy issue need to replace them later +export const LOGOUT_FN_NAME = 'logout' +export const VALIDATOR_FN_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 +export const BEARER = 'Bearer' + +// for client use @TODO need to clean this up some of them are not in use +export const CREDENTIAL_STORAGE_KEY = 'jsonqlcredential' +export const CLIENT_STORAGE_KEY = 'jsonqlstore' +export const CLIENT_AUTH_KEY = 'jsonqlauthkey' +// for id the multiple storage engine +export const INDEX_KEY = 'index' +// contract key +export const CONTRACT_KEY_NAME = 'X-JSONQL-CV-KEY' +export const SHOW_CONTRACT_DESC_PARAM = {desc: 'y'} +// directories +export const DEFAULT_RESOLVER_DIR = 'resolvers' +export const DEFAULT_CONTRACT_DIR = 'contracts' +export const DEFAULT_KEYS_DIR = 'keys' +// add in V1.3.4 start supporting socket + +// for validation +export const CJS_TYPE = 'cjs' +export const ES_TYPE = 'es' +export const TS_TYPE = 'ts' +export const ACCEPTED_JS_TYPES = [ + CJS_TYPE, + ES_TYPE +] // not accept this TS_TYPE at the moment + +// for contract cli +export const RETURN_AS_FILE = 'file' +export const RETURN_AS_JSON = 'json' +export const RETURN_AS_ENUM = [ + RETURN_AS_FILE, + RETURN_AS_JSON +] + +export const NO_ERROR_MSG = 'No message' +export const NO_STATUS_CODE = -1 + + + + + + +// this are property keys used in the configuration options +// and re-use elsewhere +export const INIT_CLIENT_PROP_KEY = 'nodeClient' +export const INIT_CONTRACT_PROP_KEY = 'initContract' + + +// status +export const SUCCESS_STATUS = 200 +export const UNAUTHORIZED_STATUS = 401 +export const FORBIDDEN_STATUS = 403 +export const NOT_FOUND_STATUS = 404 +// just whatever +export const DEFAULT_PORT_NUM = 6557 +// headers +export const CSRF_HEADER_KEY = 'X-CSRF-Token' +export const ORIGIN_HEADER_KEYS = ['Origin'] +export const WILD_CARD_CHAR = '*' diff --git a/packages/constants/build.js b/packages/constants/build.js index 6e01805d..beee4b91 100644 --- a/packages/constants/build.js +++ b/packages/constants/build.js @@ -1,6 +1,16 @@ // turn the js into JSON for other language to use +// @2.0.0 we split in files into sections const fsx = require('fs-extra') const { join } = require('path') +const files = [ + 'base.js', + 'prop.js', + 'socket.js', + 'validation.js' +] + + + const props = require('./index.js') const cjs = `module.exports = ${JSON.stringify(props, null, 4)}` @@ -11,7 +21,7 @@ let readme = ''; for (let key in props) { // console.log(`${key} === ${props[key]}`) readme += `- ${key}\r\n` - json[key] = props[key]; + json[key] = props[key] } // create new README diff --git a/packages/constants/import.js b/packages/constants/import.js new file mode 100644 index 00000000..e82f6038 --- /dev/null +++ b/packages/constants/import.js @@ -0,0 +1,4 @@ + + +require = require("esm")(module/*, options*/) +module.exports = require(process.env.IMPORT_FILE_NAME) \ No newline at end of file diff --git a/packages/constants/module.js b/packages/constants/module.js index 90cb479b..4cefbfa9 100644 --- a/packages/constants/module.js +++ b/packages/constants/module.js @@ -1,139 +1,10 @@ -export const EXT = 'js' // we might do a ts in the future -export const TS_EXT = 'ts' +// this was the main files before +// now this is an import interface to combine all the sectioned files +import * as BASE from './base' +import * as PROP from './prop' +import * as SOCKET from './socket' +import * as VALIDATION from './validation' -export const HELLO = 'Hello world!' -export const HELLO_FN = 'helloWorld' -// the core stuff to id if it's calling with jsonql -export const DATA_KEY = 'data' -export const ERROR_KEY = 'error' +const ALL_VARS = Object.assign(BASE, PROP, SOCKET, VALIDATION) -export const JSONQL_PATH = 'jsonql' -// according to the json query spec -export const CONTENT_TYPE = 'application/vnd.api+json' -export const CHARSET = 'charset=utf-8' -export const DEFAULT_HEADER = { - 'Accept': CONTENT_TYPE, - 'Content-Type': [ CONTENT_TYPE, CHARSET ].join('') -} - -// export const INDEX = 'index' use INDEX_KEY instead -export const DEFAULT_TYPE = 'any' -// contract file names -// export const DEFAULT_FILE_NAME = 'contract.json' // @TODO remove once all changed -// export const PUBLIC_FILE_NAME = 'public-contract.json' // @TODO remove once all changed -export const DEFAULT_CONTRACT_FILE_NAME = 'contract.json' -export const PUBLIC_CONTRACT_FILE_NAME = 'public-contract.json' -// this is for the ES6 module import and export @TODO remove later -export const DEFAULT_RESOLVER_LIST_FILE_NAME = 'resolver.js' -export const DEFAULT_RESOLVER_IMPORT_FILE_NAME = 'import.js' - -export const MODULE_TYPE = 'module' -export const SCRIPT_TYPE = 'script' - -// @TODO remove this is not in use -// export const CLIENT_CONFIG_FILE = '.clients.json' -// export const CONTRACT_CONFIG_FILE = 'jsonql-contract-config.js' -// type of resolvers -export const QUERY_NAME = 'query' -export const MUTATION_NAME = 'mutation' -export const SOCKET_NAME = 'socket' -export const CONTRACT_NAME = 'contract' -export const RESOLVER_TYPES = [ - QUERY_NAME, - MUTATION_NAME, - SOCKET_NAME -] -// for calling the mutation -export const PAYLOAD_PARAM_NAME = 'payload' // @TODO shortern them -export const CONDITION_PARAM_NAME = 'condition' -export const RESOLVER_PARAM_NAME = 'resolverName' -export const QUERY_ARG_NAME = 'args' -export const TIMESTAMP_PARAM_NAME = 'TS' -export const MUTATION_ARGS = [ - RESOLVER_PARAM_NAME, - PAYLOAD_PARAM_NAME, - CONDITION_PARAM_NAME -] -// new jsonp -export const JSONP_CALLBACK_NAME = 'jsonqlJsonpCallback' - -// methods allow -export const API_REQUEST_METHODS = ['POST', 'PUT'] -export const CONTRACT_REQUEST_METHODS = ['GET', 'HEAD'] -// for contract-cli -export const KEY_WORD = 'continue' -export const PUBLIC_KEY = 'public' -export const PRIVATE_KEY = 'private' - - -// author -export const AUTH_TYPE = 'auth' -export const AUTH_NAME = AUTH_TYPE // alias -export const LOGIN_FN_NAME = 'login' -// export const ISSUER_NAME = LOGIN_NAME // legacy issue need to replace them later -export const LOGOUT_FN_NAME = 'logout' -export const VALIDATOR_FN_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 -export const BEARER = 'Bearer' - -// for client use @TODO need to clean this up some of them are not in use -export const CREDENTIAL_STORAGE_KEY = 'jsonqlcredential' -export const CLIENT_STORAGE_KEY = 'jsonqlstore' -export const CLIENT_AUTH_KEY = 'jsonqlauthkey' -// for id the multiple storage engine -export const INDEX_KEY = 'index' -// contract key -export const CONTRACT_KEY_NAME = 'X-JSONQL-CV-KEY' -export const SHOW_CONTRACT_DESC_PARAM = {desc: 'y'} -// directories -export const DEFAULT_RESOLVER_DIR = 'resolvers' -export const DEFAULT_CONTRACT_DIR = 'contracts' -export const DEFAULT_KEYS_DIR = 'keys' -// add in V1.3.4 start supporting socket - -// for validation -export const CJS_TYPE = 'cjs' -export const ES_TYPE = 'es' -export const TS_TYPE = 'ts' -export const ACCEPTED_JS_TYPES = [ - CJS_TYPE, - ES_TYPE -] // not accept this TS_TYPE at the moment - -// for contract cli -export const RETURN_AS_FILE = 'file' -export const RETURN_AS_JSON = 'json' -export const RETURN_AS_ENUM = [ - RETURN_AS_FILE, - RETURN_AS_JSON -] - -export const NO_ERROR_MSG = 'No message' -export const NO_STATUS_CODE = -1 - - - - - - -// this are property keys used in the configuration options -// and re-use elsewhere -export const INIT_CLIENT_PROP_KEY = 'nodeClient' -export const INIT_CONTRACT_PROP_KEY = 'initContract' - - -// status -export const SUCCESS_STATUS = 200 -export const UNAUTHORIZED_STATUS = 401 -export const FORBIDDEN_STATUS = 403 -export const NOT_FOUND_STATUS = 404 -// just whatever -export const DEFAULT_PORT_NUM = 6557 -// headers -export const CSRF_HEADER_KEY = 'X-CSRF-Token' -export const ORIGIN_HEADER_KEYS = ['Origin'] -export const WILD_CARD_CHAR = '*' +export default ALL_VARS diff --git a/packages/constants/package.json b/packages/constants/package.json index 006eb9b7..5eccf027 100755 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -1,13 +1,17 @@ { "name": "jsonql-constants", "version": "2.0.0", - "description": "All the share constants for jsonql tools", + "description": "All the share constants for jsonql modules", "main": "main.js", "module": "module.js", "files": [ "main.js", "module.js", - "constants.json" + "constants.json", + "base.js", + "prop.js", + "socket.js", + "validation.js" ], "scripts": { "build": "node ./build.js", diff --git a/packages/constants/prop.js b/packages/constants/prop.js index 458ced09..75f13bee 100644 --- a/packages/constants/prop.js +++ b/packages/constants/prop.js @@ -40,3 +40,59 @@ export const SOCKET_TYPE_SERVER_ALIAS = 'socketServerType' // 1.9.1 export const CSRF_PROP_KEY = 'csrf' export const ALLOW_ORIGIN_PROP_KEY = 'allowOrigin' + +export const STANDALONE_PROP_KEY = 'standalone' +export const DEBUG_ON_PROP_KEY = 'debugOn' + +export const HOSTNAME_PROP_KEY = 'hostname' +export const NAMESAPCE_PROP_KEY = 'namespace' + +export const WS_OPT_PROP_KEY = 'wsOptions' + +export const CONTRACT_PROP_KEY = 'contract' +export const TOKEN_PROP_KEY = 'token' + +export const INIT_CONTRACT_PROP_KEY = 'initContract' +export const CONTENT_TYPE_PROP_KEY = 'contentType' +export const RETURN_AS_PROP_KEY = 'returnAs' +export const NAME_PROP_KEY = 'appName' + +export const EXPIRED_PROP_KEY = 'expired' +export const APP_ROOT_DIR_PROP_KEY = 'appRootDir' + +export const JWT_TOKEN_OPT_PROP_KEY = 'jwtTokenOption' + +export const ENABLE_JSONP_PROP_KEY = 'enableJsonp' + +export const CONTRACT_WITH_DESC_PROP_KEY = 'contractWithDesc' +export const WITH_PUBLIC_CONTRACT_PROP_KEY = 'withPublicContract' +export const PUBLIC_KEY_NAME_PROP_KEY = 'publicKeyFileName' +export const PRIVATE_KEY_NAME_PROP_KEY = 'privateKeyFileName' + +export const RSA_MODULE_LEN_PROP_KEY = 'rsaModulusLength' + +export const JSONQL_PATH_PROP_KEY = 'jsonqlPath' + +export const CONTRACT_KEY_PROP_KEY = 'contractKey' +export const CONTRACT_KEY_NAME_PROP_KEY = 'contractKeyName' + +export const ENABLE_WEB_CONSOLE_PROP_KEY = 'enableWebConsole' +export const JS_TYPE_PROP_KEY = 'jsType' + +export const EXPOSE_ERR_PROP_KEY = 'exposeError' +// this will combine all three options together +// because they are redudant if set this to true +// then whenever start up will build a fresh new contract like now +// if false then the developer has to manually build the contract +// which is what production suppose to be +export const AUTO_CONTRACT_PROP_KEY = 'autoCreateContract' +// still under development +export const VALIDATE_RETURNS_PROP_KEY = 'validateReturns' +export const CLIENT_CONFIG_PROP_KEY = 'clientConfig' +export const ENABLE_UPLOAD_PROP_KEY = 'enableFileUpload' +export const FILE_UPLOAD_NAME_PROP_KEY = 'fileUploadName' +export const FILE_UPLOAD_DIST_PROP_KEY = 'fileUploadDist' +export const FILE_HANDLER_FN_NAME_PROP_KEY = 'fileHandlerName' + +export const ENABLE_SPLIT_TASK_PROP_KEY = 'enableSplitTask' + -- Gitee From 8ddd0767ede18b34609f899d21f466fb4210b8a1 Mon Sep 17 00:00:00 2001 From: joelchu Date: Sun, 15 Mar 2020 12:16:57 +0800 Subject: [PATCH 04/10] port the require es module method from jsonql-resolver to jsonql-constants --- packages/constants/import.js | 29 +++++++++++++++++-- packages/constants/prop.js | 3 +- packages/constants/test.js | 3 ++ .../src/generator/get-socket-auth-resolver.js | 1 + .../src/generator/process-file.js | 1 + packages/resolver/src/resolve-methods.js | 4 +-- packages/resolver/src/search-resolvers.js | 2 +- 7 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 packages/constants/test.js diff --git a/packages/constants/import.js b/packages/constants/import.js index e82f6038..bfa15856 100644 --- a/packages/constants/import.js +++ b/packages/constants/import.js @@ -1,4 +1,29 @@ +/** + * Ported from jsonql-resolver + * Try to use the esm module to require the module directly + * @param {string} pathToResolver path to resolver from contract + * @return {*} resolver function on success + */ +function requireEsModule(pathToResolver) { + let oldRequire + try { + oldRequire = require + require = require("esm")(module/*, options*/) + const obj = require(pathToResolver) + // console.error('requireEsModule', obj) + if (typeof obj === 'function') { + return obj + } else if (obj.default && typeof obj.default === 'function') { + return obj.default + } + throw new Error(`Unable to import ES module!`) + } catch (e) { + throw new Error(e) + } finally { + // reset the require here + require = oldRequire + } +} -require = require("esm")(module/*, options*/) -module.exports = require(process.env.IMPORT_FILE_NAME) \ No newline at end of file +module.exports = requireEsModule \ No newline at end of file diff --git a/packages/constants/prop.js b/packages/constants/prop.js index 75f13bee..e2a5f36a 100644 --- a/packages/constants/prop.js +++ b/packages/constants/prop.js @@ -80,6 +80,8 @@ export const ENABLE_WEB_CONSOLE_PROP_KEY = 'enableWebConsole' export const JS_TYPE_PROP_KEY = 'jsType' export const EXPOSE_ERR_PROP_KEY = 'exposeError' + +export const CLIENT_CONFIG_PROP_KEY = 'clientConfig' // this will combine all three options together // because they are redudant if set this to true // then whenever start up will build a fresh new contract like now @@ -88,7 +90,6 @@ export const EXPOSE_ERR_PROP_KEY = 'exposeError' export const AUTO_CONTRACT_PROP_KEY = 'autoCreateContract' // still under development export const VALIDATE_RETURNS_PROP_KEY = 'validateReturns' -export const CLIENT_CONFIG_PROP_KEY = 'clientConfig' export const ENABLE_UPLOAD_PROP_KEY = 'enableFileUpload' export const FILE_UPLOAD_NAME_PROP_KEY = 'fileUploadName' export const FILE_UPLOAD_DIST_PROP_KEY = 'fileUploadDist' diff --git a/packages/constants/test.js b/packages/constants/test.js new file mode 100644 index 00000000..3bda8075 --- /dev/null +++ b/packages/constants/test.js @@ -0,0 +1,3 @@ +// very simple diy test the variable exports + +const allVars = require('./main.js') \ No newline at end of file diff --git a/packages/contract-cli/src/generator/get-socket-auth-resolver.js b/packages/contract-cli/src/generator/get-socket-auth-resolver.js index 42b39ff9..0fa32a70 100644 --- a/packages/contract-cli/src/generator/get-socket-auth-resolver.js +++ b/packages/contract-cli/src/generator/get-socket-auth-resolver.js @@ -10,6 +10,7 @@ const { inArray } = require('jsonql-params-validator') const { getSourceType } = require('./get-source-type') const { parseFileToAst } = require('./parse-file-to-ast') const { chainPromises } = require('jsonql-utils') + /** * Return the list of files from the folder first * @param {string} resolverDir where the base resolver directory diff --git a/packages/contract-cli/src/generator/process-file.js b/packages/contract-cli/src/generator/process-file.js index e05fb8a6..cd55dac5 100644 --- a/packages/contract-cli/src/generator/process-file.js +++ b/packages/contract-cli/src/generator/process-file.js @@ -14,6 +14,7 @@ const { JsonqlError } = require('jsonql-errors') const { getDebug } = require('../utils') const debug = getDebug('process-file') + /** * @NOTE this should be replace with the split task * Take the map filter out to get the clean resolver objects diff --git a/packages/resolver/src/resolve-methods.js b/packages/resolver/src/resolve-methods.js index 1c15bbf8..833ad487 100644 --- a/packages/resolver/src/resolve-methods.js +++ b/packages/resolver/src/resolve-methods.js @@ -1,6 +1,6 @@ // this was in the core-middleware now make this standalone for use in // two middlewares -const { join } = require('path') +// const { join } = require('path') const { JsonqlResolverNotFoundError, JsonqlResolverAppError, @@ -18,7 +18,7 @@ const { findFromContract } = require('jsonql-utils') const { getDebug, handleOutput, ctxErrorHandler } = require('./utils') -const { searchResolvers, importFromModule, requireEsModule } = require('./search-resolvers') +const { searchResolvers, requireEsModule } = require('./search-resolvers') // importFromModule, const { validateAndCall } = require('./validate-and-call') const { getNodeClientProvider } = require('./client') diff --git a/packages/resolver/src/search-resolvers.js b/packages/resolver/src/search-resolvers.js index 777bfe37..e4f7efea 100644 --- a/packages/resolver/src/search-resolvers.js +++ b/packages/resolver/src/search-resolvers.js @@ -31,7 +31,7 @@ function importFromModule(resolverDir, type, resolverName) { * @return {*} resolver function on success */ function requireEsModule(pathToResolver) { - let oldRequire; + let oldRequire try { oldRequire = require; require = require("esm")(module/*, options*/) -- Gitee From 8082a474d27021000f575203493b5297e74f732c Mon Sep 17 00:00:00 2001 From: joelchu Date: Sun, 15 Mar 2020 12:34:23 +0800 Subject: [PATCH 05/10] update README template for jsonql-constants --- packages/constants/README.md | 48 ++++++++++++++++----------- packages/constants/README_TEMPLATE.md | 18 +++++++--- packages/constants/package.json | 3 +- 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/packages/constants/README.md b/packages/constants/README.md index 0d8e5757..6d397cf5 100755 --- a/packages/constants/README.md +++ b/packages/constants/README.md @@ -1,15 +1,25 @@ -[![NPM](https://nodei.co/npm/jsonql-constants.png?compact=true)](https://npmjs.org/package/jsonql-constants) - -# jsonql-constants - -This is a module that just export all the share constant use across all the -[json:ql](https://jsonql.org) tools. - -Use it only when you want to develop your json:ql compatible tool. If you are using -non-javascript to develop your tool. You can also use the included `constants.json`. - -## constants - +[![NPM](https://nodei.co/npm/jsonql-constants.png?compact=true)](https://npmjs.org/package/jsonql-constants) + +# jsonql-constants + +This is a module export all the share constant use across all the +[jsonql](https://jsonql.org) modules. + +Use it only when you want to develop your jsonql compatible module. +If you are not using javascript to develop your module. +You can also use the included `constants.json`. + +As of Version 2, we split up the constants into sections: + +- base +- prop +- socket +- validation + +Please consult the detail break down below. + +## constants + - EXT - TS_EXT - HELLO @@ -161,10 +171,10 @@ non-javascript to develop your tool. You can also use the included `constants.js - CSRF_HEADER_KEY - ORIGIN_HEADER_KEYS - WILD_CARD_CHAR - - ---- - -MIT - -to1source / newbran ltd (c) 2019 + + +--- + +MIT + +to1source / newbran ltd (c) 2019 diff --git a/packages/constants/README_TEMPLATE.md b/packages/constants/README_TEMPLATE.md index 82b1e764..427e042c 100644 --- a/packages/constants/README_TEMPLATE.md +++ b/packages/constants/README_TEMPLATE.md @@ -2,11 +2,21 @@ # jsonql-constants -This is a module that just export all the share constant use across all the -[json:ql](https://jsonql.org) tools. +This is a module export all the share constant use across all the +[jsonql](https://jsonql.org) modules. -Use it only when you want to develop your json:ql compatible tool. If you are using -non-javascript to develop your tool. You can also use the included `constants.json`. +Use it only when you want to develop your jsonql compatible module. +If you are not using javascript to develop your module. +You can also use the included `constants.json`. + +As of Version 2, we split up the constants into sections: + +- base +- prop +- socket +- validation + +Please consult the detail break down below. ## constants diff --git a/packages/constants/package.json b/packages/constants/package.json index 5eccf027..91ed4bc1 100755 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -15,7 +15,8 @@ ], "scripts": { "build": "node ./build.js", - "prepare": "npm run build" + "prepare": "npm run build", + "test": "node ./test.js" }, "keywords": [ "jsonql", -- Gitee From e52e17e627727526e56185093fb9d31a694303dd Mon Sep 17 00:00:00 2001 From: joelchu Date: Sun, 15 Mar 2020 15:13:57 +0800 Subject: [PATCH 06/10] Fix the import and the test able to see but partial --- packages/constants/build.js | 27 ++++++++++++++++----------- packages/constants/import.js | 7 ++++--- packages/constants/index.js | 12 ++++++++++-- packages/constants/module.js | 10 ---------- packages/constants/package.json | 6 +++--- packages/constants/socket.js | 2 +- packages/constants/test.js | 10 +++++++++- 7 files changed, 43 insertions(+), 31 deletions(-) delete mode 100644 packages/constants/module.js diff --git a/packages/constants/build.js b/packages/constants/build.js index beee4b91..5ab0980d 100644 --- a/packages/constants/build.js +++ b/packages/constants/build.js @@ -8,29 +8,34 @@ const files = [ 'socket.js', 'validation.js' ] +const importFn = require('./import') +const readme = '\r\n' +const allProps = files.map(file => { -const props = require('./index.js') + let props = importFn(join(__dirname, file)) -const cjs = `module.exports = ${JSON.stringify(props, null, 4)}` + // create README output + readme += `### ${file.replace('.js', '').toUpperCase()}\r\n\r\n` + readme += Object.keys(props).map(prop => ( + `- ${prop}\r\n` + )) + readme += '\r\n' -let json = {}; -let readme = ''; + return props +}).reduce((a, b) => Object.assign(a, b), {}) + +const cjs = `module.exports = ${JSON.stringify(allProps, null, 4)}` -for (let key in props) { - // console.log(`${key} === ${props[key]}`) - readme += `- ${key}\r\n` - json[key] = props[key] -} // create new README const tpl = fsx.readFileSync(join(__dirname, 'README_TEMPLATE.md')) const content = tpl.toString().replace('[REPLACE]', readme) -fsx.outputFileSync(join(__dirname, 'README.md'), content) +fsx.outputFileSync(join(__dirname, 'README.md'), readme) fsx.outputFileSync(join(__dirname, 'main.js'), cjs) -fsx.outputJson(join(__dirname, 'constants.json'), json, {spaces: 2}, err => { +fsx.outputJson(join(__dirname, 'constants.json'), allProps, { spaces: 2 }, err => { if (err) { console.log('ERROR:', err) process.exit() diff --git a/packages/constants/import.js b/packages/constants/import.js index bfa15856..aabbd296 100644 --- a/packages/constants/import.js +++ b/packages/constants/import.js @@ -12,11 +12,12 @@ function requireEsModule(pathToResolver) { require = require("esm")(module/*, options*/) const obj = require(pathToResolver) // console.error('requireEsModule', obj) - if (typeof obj === 'function') { + if (typeof obj === 'function' && !obj.default) { return obj - } else if (obj.default && typeof obj.default === 'function') { + } else if (obj.default && (typeof obj.default === 'object' || typeof obj.default === 'function')) { return obj.default - } + } + console.error('ERROR', typeof obj.default, obj) throw new Error(`Unable to import ES module!`) } catch (e) { throw new Error(e) diff --git a/packages/constants/index.js b/packages/constants/index.js index fbb92340..4cefbfa9 100644 --- a/packages/constants/index.js +++ b/packages/constants/index.js @@ -1,2 +1,10 @@ -require = require("esm")(module/*, options*/) -module.exports = require("./module.js") +// this was the main files before +// now this is an import interface to combine all the sectioned files +import * as BASE from './base' +import * as PROP from './prop' +import * as SOCKET from './socket' +import * as VALIDATION from './validation' + +const ALL_VARS = Object.assign(BASE, PROP, SOCKET, VALIDATION) + +export default ALL_VARS diff --git a/packages/constants/module.js b/packages/constants/module.js deleted file mode 100644 index 4cefbfa9..00000000 --- a/packages/constants/module.js +++ /dev/null @@ -1,10 +0,0 @@ -// this was the main files before -// now this is an import interface to combine all the sectioned files -import * as BASE from './base' -import * as PROP from './prop' -import * as SOCKET from './socket' -import * as VALIDATION from './validation' - -const ALL_VARS = Object.assign(BASE, PROP, SOCKET, VALIDATION) - -export default ALL_VARS diff --git a/packages/constants/package.json b/packages/constants/package.json index 91ed4bc1..f4f060e4 100755 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -3,15 +3,15 @@ "version": "2.0.0", "description": "All the share constants for jsonql modules", "main": "main.js", - "module": "module.js", + "module": "index.js", "files": [ "main.js", "module.js", - "constants.json", "base.js", "prop.js", "socket.js", - "validation.js" + "validation.js", + "constants.json" ], "scripts": { "build": "node ./build.js", diff --git a/packages/constants/socket.js b/packages/constants/socket.js index 776f9c65..f151d6bd 100644 --- a/packages/constants/socket.js +++ b/packages/constants/socket.js @@ -60,7 +60,7 @@ export const USERDATA_PROP_NAME = 'userdata' // this is somewhat vague about what is suppose to do export const EMIT_REPLY_TYPE = 'emit_reply' export const ACKNOWLEDGE_REPLY_TYPE = 'acknowledge_reply' -export const ERROR_TYPE = ERROR_KEY // Should replace with ERROR_KEY + export const NSP_GROUP = 'nspGroup' export const PUBLIC_NAMESPACE = 'publicNamespace' diff --git a/packages/constants/test.js b/packages/constants/test.js index 3bda8075..eb76c43b 100644 --- a/packages/constants/test.js +++ b/packages/constants/test.js @@ -1,3 +1,11 @@ // very simple diy test the variable exports +const { join } = require('path') +const importFn = require('./import') + +const props = importFn(join(__dirname, 'index.js')) + + +console.info(props) + + -const allVars = require('./main.js') \ No newline at end of file -- Gitee From d5d7cce4bdd5b436d25384e0f1fe5ec32efd3f7b Mon Sep 17 00:00:00 2001 From: joelchu Date: Sun, 15 Mar 2020 15:23:30 +0800 Subject: [PATCH 07/10] fix the unable to merge module property problem in the import script --- packages/constants/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/constants/index.js b/packages/constants/index.js index 4cefbfa9..54bbeb8d 100644 --- a/packages/constants/index.js +++ b/packages/constants/index.js @@ -5,6 +5,14 @@ import * as PROP from './prop' import * as SOCKET from './socket' import * as VALIDATION from './validation' -const ALL_VARS = Object.assign(BASE, PROP, SOCKET, VALIDATION) +// need to do a dump way to put them together without using a merge method +const ALL_VARS = [ BASE, PROP, SOCKET, VALIDATION ].map(p => { + let obj = {} // turn it into a plain object + for (let n in p) { + obj[n] = p[n] + } + return obj +}) +.reduce((a, b) => Object.assign(a, b), {}) export default ALL_VARS -- Gitee From 88f6f505e56ad1dc0af5d2fee686aa63214c93b9 Mon Sep 17 00:00:00 2001 From: joelchu Date: Sun, 15 Mar 2020 15:27:45 +0800 Subject: [PATCH 08/10] add browser.js files --- packages/constants/browser.js | 0 packages/constants/build.js | 13 +++++++++---- packages/constants/package.json | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 packages/constants/browser.js diff --git a/packages/constants/browser.js b/packages/constants/browser.js new file mode 100644 index 00000000..e69de29b diff --git a/packages/constants/build.js b/packages/constants/build.js index 5ab0980d..c961f2d9 100644 --- a/packages/constants/build.js +++ b/packages/constants/build.js @@ -26,15 +26,20 @@ const allProps = files.map(file => { return props }).reduce((a, b) => Object.assign(a, b), {}) -const cjs = `module.exports = ${JSON.stringify(allProps, null, 4)}` +const strJson = `${JSON.stringify(allProps, null, 4)}` +const cjs = `module.exports = ${strJson}` +const browser = `var jsonqlConstants = ${strJson}` -// create new README +// output to README const tpl = fsx.readFileSync(join(__dirname, 'README_TEMPLATE.md')) const content = tpl.toString().replace('[REPLACE]', readme) - -fsx.outputFileSync(join(__dirname, 'README.md'), readme) +fsx.outputFileSync(join(__dirname, 'README.md'), content) +// out put the cjs main.js fsx.outputFileSync(join(__dirname, 'main.js'), cjs) +// output to browser.js +fsx.outputFileSynx(join(__dirname, 'browser.js'), browser) +// output to constants.json fsx.outputJson(join(__dirname, 'constants.json'), allProps, { spaces: 2 }, err => { if (err) { console.log('ERROR:', err) diff --git a/packages/constants/package.json b/packages/constants/package.json index f4f060e4..73d2031e 100755 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -4,6 +4,7 @@ "description": "All the share constants for jsonql modules", "main": "main.js", "module": "index.js", + "browser": "browser.js", "files": [ "main.js", "module.js", -- Gitee From e551c429a0820de3746a159d0d0dcc6c03b190aa Mon Sep 17 00:00:00 2001 From: joelchu Date: Sun, 15 Mar 2020 15:34:32 +0800 Subject: [PATCH 09/10] output to all scripts works but the README got extra character in each line --- packages/constants/README.md | 405 +++++++++++++++++------------- packages/constants/browser.js | 261 +++++++++++++++++++ packages/constants/build.js | 8 +- packages/constants/constants.json | 169 ++++++++----- packages/constants/import.js | 4 +- packages/constants/main.js | 169 ++++++++----- 6 files changed, 721 insertions(+), 295 deletions(-) diff --git a/packages/constants/README.md b/packages/constants/README.md index 6d397cf5..720b0229 100755 --- a/packages/constants/README.md +++ b/packages/constants/README.md @@ -1,180 +1,245 @@ -[![NPM](https://nodei.co/npm/jsonql-constants.png?compact=true)](https://npmjs.org/package/jsonql-constants) +[![NPM](https://nodei.co/npm/jsonql-constants.png?compact=true)](https://npmjs.org/package/jsonql-constants) + +# jsonql-constants + +This is a module export all the share constant use across all the +[jsonql](https://jsonql.org) modules. + +Use it only when you want to develop your jsonql compatible module. +If you are not using javascript to develop your module. +You can also use the included `constants.json`. + +As of Version 2, we split up the constants into sections: + +- base +- prop +- socket +- validation + +Please consult the detail break down below. + +## constants + -# jsonql-constants +### BASE -This is a module export all the share constant use across all the -[jsonql](https://jsonql.org) modules. - -Use it only when you want to develop your jsonql compatible module. -If you are not using javascript to develop your module. -You can also use the included `constants.json`. - -As of Version 2, we split up the constants into sections: +- EXT +,- TS_EXT +,- HELLO +,- HELLO_FN +,- DATA_KEY +,- ERROR_KEY +,- JSONQL_PATH +,- CONTENT_TYPE +,- CHARSET +,- DEFAULT_HEADER +,- DEFAULT_TYPE +,- DEFAULT_CONTRACT_FILE_NAME +,- PUBLIC_CONTRACT_FILE_NAME +,- DEFAULT_RESOLVER_LIST_FILE_NAME +,- DEFAULT_RESOLVER_IMPORT_FILE_NAME +,- MODULE_TYPE +,- SCRIPT_TYPE +,- QUERY_NAME +,- MUTATION_NAME +,- SOCKET_NAME +,- CONTRACT_NAME +,- RESOLVER_TYPES +,- PAYLOAD_PARAM_NAME +,- CONDITION_PARAM_NAME +,- RESOLVER_PARAM_NAME +,- QUERY_ARG_NAME +,- TIMESTAMP_PARAM_NAME +,- MUTATION_ARGS +,- JSONP_CALLBACK_NAME +,- API_REQUEST_METHODS +,- CONTRACT_REQUEST_METHODS +,- KEY_WORD +,- PUBLIC_KEY +,- PRIVATE_KEY +,- AUTH_TYPE +,- AUTH_NAME +,- LOGIN_FN_NAME +,- LOGOUT_FN_NAME +,- VALIDATOR_FN_NAME +,- DISCONNECT_FN_NAME +,- SWITCH_USER_FN_NAME +,- AUTH_HEADER +,- AUTH_CHECK_HEADER +,- BEARER +,- CREDENTIAL_STORAGE_KEY +,- CLIENT_STORAGE_KEY +,- CLIENT_AUTH_KEY +,- INDEX_KEY +,- CONTRACT_KEY_NAME +,- SHOW_CONTRACT_DESC_PARAM +,- DEFAULT_RESOLVER_DIR +,- DEFAULT_CONTRACT_DIR +,- DEFAULT_KEYS_DIR +,- CJS_TYPE +,- ES_TYPE +,- TS_TYPE +,- ACCEPTED_JS_TYPES +,- RETURN_AS_FILE +,- RETURN_AS_JSON +,- RETURN_AS_ENUM +,- NO_ERROR_MSG +,- NO_STATUS_CODE +,- INIT_CLIENT_PROP_KEY +,- INIT_CONTRACT_PROP_KEY +,- SUCCESS_STATUS +,- UNAUTHORIZED_STATUS +,- FORBIDDEN_STATUS +,- NOT_FOUND_STATUS +,- DEFAULT_PORT_NUM +,- CSRF_HEADER_KEY +,- ORIGIN_HEADER_KEYS +,- WILD_CARD_CHAR -- base -- prop -- socket -- validation +### PROP -Please consult the detail break down below. +- TYPE_KEY +,- OPTIONAL_KEY +,- ENUM_KEY +,- ARGS_KEY +,- CHECKER_KEY +,- ALIAS_KEY +,- CHECKED_KEY +,- APP_DIR_PROP_KEY +,- AUTH_TO_PROP_KEY +,- ENABLE_AUTH_PROP_KEY +,- USE_JWT_PROP_KEY +,- RESOLVER_DIR_PROP_KEY +,- CONTRACT_DIR_PROP_KEY +,- INIT_CONNECTION_FN_NAME_PROP_KEY +,- LOGIN_FN_NAME_PROP_KEY +,- LOGOUT_FN_NAME_PROP_KEY +,- DISCONNECT_FN_NAME_PROP_KEY +,- SWITCH_USER_FN_NAME_PROP_KEY +,- PUBLIC_FN_DIR_PROP_KEY +,- PRIVATE_FN_DIR_DROP_KEY +,- ALGORITHM_PROP_KEY +,- KEYS_DIR_PROP_KEY +,- SOCKET_IO_AUTH_TYPE_PROP_KEY +,- SERVER_INIT_OPT_PROP_KEY +,- SOCKET_TYPE_PROP_KEY +,- SOCKET_TYPE_CLIENT_ALIAS +,- SOCKET_TYPE_SERVER_ALIAS +,- CSRF_PROP_KEY +,- ALLOW_ORIGIN_PROP_KEY +,- STANDALONE_PROP_KEY +,- DEBUG_ON_PROP_KEY +,- HOSTNAME_PROP_KEY +,- NAMESAPCE_PROP_KEY +,- WS_OPT_PROP_KEY +,- CONTRACT_PROP_KEY +,- TOKEN_PROP_KEY +,- INIT_CONTRACT_PROP_KEY +,- CONTENT_TYPE_PROP_KEY +,- RETURN_AS_PROP_KEY +,- NAME_PROP_KEY +,- EXPIRED_PROP_KEY +,- APP_ROOT_DIR_PROP_KEY +,- JWT_TOKEN_OPT_PROP_KEY +,- ENABLE_JSONP_PROP_KEY +,- CONTRACT_WITH_DESC_PROP_KEY +,- WITH_PUBLIC_CONTRACT_PROP_KEY +,- PUBLIC_KEY_NAME_PROP_KEY +,- PRIVATE_KEY_NAME_PROP_KEY +,- RSA_MODULE_LEN_PROP_KEY +,- JSONQL_PATH_PROP_KEY +,- CONTRACT_KEY_PROP_KEY +,- CONTRACT_KEY_NAME_PROP_KEY +,- ENABLE_WEB_CONSOLE_PROP_KEY +,- JS_TYPE_PROP_KEY +,- EXPOSE_ERR_PROP_KEY +,- CLIENT_CONFIG_PROP_KEY +,- AUTO_CONTRACT_PROP_KEY +,- VALIDATE_RETURNS_PROP_KEY +,- ENABLE_UPLOAD_PROP_KEY +,- FILE_UPLOAD_NAME_PROP_KEY +,- FILE_UPLOAD_DIST_PROP_KEY +,- FILE_HANDLER_FN_NAME_PROP_KEY +,- ENABLE_SPLIT_TASK_PROP_KEY -## constants +### SOCKET -- EXT -- TS_EXT -- HELLO -- HELLO_FN -- DATA_KEY -- ERROR_KEY -- JSONQL_PATH -- CONTENT_TYPE -- CHARSET -- DEFAULT_HEADER -- DEFAULT_TYPE -- DEFAULT_CONTRACT_FILE_NAME -- PUBLIC_CONTRACT_FILE_NAME -- DEFAULT_RESOLVER_LIST_FILE_NAME -- DEFAULT_RESOLVER_IMPORT_FILE_NAME -- MODULE_TYPE -- SCRIPT_TYPE -- QUERY_NAME -- MUTATION_NAME -- SOCKET_NAME -- CONTRACT_NAME -- RESOLVER_TYPES -- PAYLOAD_PARAM_NAME -- CONDITION_PARAM_NAME -- RESOLVER_PARAM_NAME -- QUERY_ARG_NAME -- TIMESTAMP_PARAM_NAME -- MUTATION_ARGS -- JSONP_CALLBACK_NAME -- API_REQUEST_METHODS -- CONTRACT_REQUEST_METHODS -- KEY_WORD -- PUBLIC_KEY -- PRIVATE_KEY -- TYPE_KEY -- OPTIONAL_KEY -- ENUM_KEY -- ARGS_KEY -- CHECKER_KEY -- ALIAS_KEY -- CHECKED_KEY -- AUTH_TYPE -- AUTH_NAME -- LOGIN_NAME -- LOGOUT_NAME -- VALIDATOR_NAME -- DISCONNECT_FN_NAME -- SWITCH_USER_FN_NAME -- AUTH_HEADER -- AUTH_CHECK_HEADER -- BEARER -- CREDENTIAL_STORAGE_KEY -- CLIENT_STORAGE_KEY -- CLIENT_AUTH_KEY -- INDEX_KEY -- CONTRACT_KEY_NAME -- SHOW_CONTRACT_DESC_PARAM -- DEFAULT_RESOLVER_DIR -- DEFAULT_CONTRACT_DIR -- DEFAULT_KEYS_DIR -- CJS_TYPE -- ES_TYPE -- TS_TYPE -- ACCEPTED_JS_TYPES -- OR_SEPERATOR -- FUNCTION_TYPE -- STRING_TYPE -- BOOLEAN_TYPE -- ARRAY_TYPE -- OBJECT_TYPE -- ANY_TYPE -- NUMBER_TYPE -- NUMBER_TYPES -- SUPPORTED_TYPES -- ARRAY_TS_TYPE_LFT -- ARRAY_TYPE_LFT -- ARRAY_TYPE_RGT -- RETURN_AS_FILE -- RETURN_AS_JSON -- RETURN_AS_ENUM -- NO_ERROR_MSG -- NO_STATUS_CODE - SOCKET_PING_EVENT_NAME -- SWITCH_USER_EVENT_NAME -- LOGIN_EVENT_NAME -- LOGOUT_EVENT_NAME -- SA_LOGIN_EVENT_NAME -- RECONNECT_EVENT_NAME -- SOCKET_CLIENT_ID_KEY -- SOCKET_CLIENT_TS_KEY -- CONNECTED_EVENT_NAME -- DISCONNECT_EVENT_NAME -- INTERCOM_RESOLVER_NAME -- INTER_COM_EVENT_NAMES -- WS_REPLY_TYPE -- WS_EVT_NAME -- WS_DATA_NAME -- WS_IS_REPLY_KEYS -- EMIT_REPLY_TYPE -- ACKNOWLEDGE_REPLY_TYPE -- ERROR_TYPE -- NSP_GROUP -- PUBLIC_NAMESPACE -- JS_WS_SOCKET_IO_NAME -- JS_WS_NAME -- JS_PRIMUS_NAME -- GO_WS_COOLPY7_NAME -- SOCKET_TYPE_KEY -- SOCKET_TYPE_CLIENT_ALIAS -- SOCKET_TYPE_SERVER_ALIAS -- ON_MESSAGE_FN_NAME -- ON_RESULT_FN_NAME -- ON_ERROR_FN_NAME -- ON_READY_FN_NAME -- ON_LOGIN_FN_NAME -- SEND_MSG_FN_NAME -- CLIENT_PROP_NAME -- USERDATA_PROP_NAME -- INIT_CLIENT_PROP_KEY -- INIT_CONTRACT_PROP_KEY -- DEFAULT_WS_WAIT_TIME -- DEFAULT_RETRY_TIME -- TIMEOUT_ERR_MSG -- NOT_LOGIN_ERR_MSG -- BASE64_FORMAT -- HEX_FORMAT -- UTF8_FORMAT -- RSA_FORMATS -- RSA_ALGO -- HSA_ALGO -- JWT_SUPPORT_ALGOS -- RSA_PRIVATE_KEY_HEADER -- RSA_MIN_MODULE_LEN -- RSA_MAX_MODULE_LEN -- TOKEN_PARAM_NAME -- IO_ROUNDTRIP_LOGIN -- IO_HANDSHAKE_LOGIN -- IO_LOGIN_METHODS -- PEM_EXT -- PUBLIC_KEY_NAME -- PRIVATE_KEY_NAME -- DEFAULT_PUBLIC_KEY_FILE -- DEFAULT_PRIVATE_KEY_FILE -- SUCCESS_STATUS -- UNAUTHORIZED_STATUS -- FORBIDDEN_STATUS -- NOT_FOUND_STATUS -- DEFAULT_PORT_NUM -- CSRF_HEADER_KEY -- ORIGIN_HEADER_KEYS -- WILD_CARD_CHAR +,- SWITCH_USER_EVENT_NAME +,- LOGIN_EVENT_NAME +,- LOGOUT_EVENT_NAME +,- SA_LOGIN_EVENT_NAME +,- RECONNECT_EVENT_NAME +,- SOCKET_CLIENT_ID_KEY +,- SOCKET_CLIENT_TS_KEY +,- CONNECTED_EVENT_NAME +,- DISCONNECT_EVENT_NAME +,- INTERCOM_RESOLVER_NAME +,- INTER_COM_EVENT_NAMES +,- WS_REPLY_TYPE +,- WS_EVT_NAME +,- WS_DATA_NAME +,- WS_IS_REPLY_KEYS +,- ON_MESSAGE_FN_NAME +,- ON_RESULT_FN_NAME +,- ON_ERROR_FN_NAME +,- ON_READY_FN_NAME +,- ON_LOGIN_FN_NAME +,- SEND_MSG_FN_NAME +,- CLIENT_PROP_NAME +,- USERDATA_PROP_NAME +,- EMIT_REPLY_TYPE +,- ACKNOWLEDGE_REPLY_TYPE +,- NSP_GROUP +,- PUBLIC_NAMESPACE +,- JS_WS_SOCKET_IO_NAME +,- JS_WS_NAME +,- JS_PRIMUS_NAME +,- GO_WS_COOLPY7_NAME +,- DEFAULT_WS_WAIT_TIME +,- DEFAULT_RETRY_TIME +,- TIMEOUT_ERR_MSG +,- NOT_LOGIN_ERR_MSG +,- BASE64_FORMAT +,- HEX_FORMAT +,- UTF8_FORMAT +,- RSA_FORMATS +,- RSA_ALGO +,- HSA_ALGO +,- JWT_SUPPORT_ALGOS +,- RSA_PRIVATE_KEY_HEADER +,- RSA_MIN_MODULE_LEN +,- RSA_MAX_MODULE_LEN +,- TOKEN_PARAM_NAME +,- IO_ROUNDTRIP_LOGIN +,- IO_HANDSHAKE_LOGIN +,- IO_LOGIN_METHODS +,- PEM_EXT +,- PUBLIC_KEY_NAME +,- PRIVATE_KEY_NAME +,- DEFAULT_PUBLIC_KEY_FILE +,- DEFAULT_PRIVATE_KEY_FILE +### VALIDATION ---- - -MIT +- OR_SEPERATOR +,- FUNCTION_TYPE +,- STRING_TYPE +,- BOOLEAN_TYPE +,- ARRAY_TYPE +,- OBJECT_TYPE +,- ANY_TYPE +,- NUMBER_TYPE +,- NUMBER_TYPES +,- SUPPORTED_TYPES +,- ARRAY_TS_TYPE_LFT +,- ARRAY_TYPE_LFT +,- ARRAY_TYPE_RGT -to1source / newbran ltd (c) 2019 + + +--- + +MIT + +to1source / newbran ltd (c) 2019 diff --git a/packages/constants/browser.js b/packages/constants/browser.js index e69de29b..06b8fb5c 100644 --- a/packages/constants/browser.js +++ b/packages/constants/browser.js @@ -0,0 +1,261 @@ +var jsonqlConstants = { + "EXT": "js", + "TS_EXT": "ts", + "HELLO": "Hello world!", + "HELLO_FN": "helloWorld", + "DATA_KEY": "data", + "ERROR_KEY": "error", + "JSONQL_PATH": "jsonql", + "CONTENT_TYPE": "application/vnd.api+json", + "CHARSET": "charset=utf-8", + "DEFAULT_HEADER": { + "Accept": "application/vnd.api+json", + "Content-Type": "application/vnd.api+jsoncharset=utf-8" + }, + "DEFAULT_TYPE": "any", + "DEFAULT_CONTRACT_FILE_NAME": "contract.json", + "PUBLIC_CONTRACT_FILE_NAME": "public-contract.json", + "DEFAULT_RESOLVER_LIST_FILE_NAME": "resolver.js", + "DEFAULT_RESOLVER_IMPORT_FILE_NAME": "import.js", + "MODULE_TYPE": "module", + "SCRIPT_TYPE": "script", + "QUERY_NAME": "query", + "MUTATION_NAME": "mutation", + "SOCKET_NAME": "socket", + "CONTRACT_NAME": "contract", + "RESOLVER_TYPES": [ + "query", + "mutation", + "socket" + ], + "PAYLOAD_PARAM_NAME": "payload", + "CONDITION_PARAM_NAME": "condition", + "RESOLVER_PARAM_NAME": "resolverName", + "QUERY_ARG_NAME": "args", + "TIMESTAMP_PARAM_NAME": "TS", + "MUTATION_ARGS": [ + "resolverName", + "payload", + "condition" + ], + "JSONP_CALLBACK_NAME": "jsonqlJsonpCallback", + "API_REQUEST_METHODS": [ + "POST", + "PUT" + ], + "CONTRACT_REQUEST_METHODS": [ + "GET", + "HEAD" + ], + "KEY_WORD": "continue", + "PUBLIC_KEY": "public", + "PRIVATE_KEY": "private", + "AUTH_TYPE": "auth", + "AUTH_NAME": "auth", + "LOGIN_FN_NAME": "login", + "LOGOUT_FN_NAME": "logout", + "VALIDATOR_FN_NAME": "validator", + "DISCONNECT_FN_NAME": "disconnect", + "SWITCH_USER_FN_NAME": "switch-user", + "AUTH_HEADER": "Authorization", + "AUTH_CHECK_HEADER": "authorization", + "BEARER": "Bearer", + "CREDENTIAL_STORAGE_KEY": "jsonqlcredential", + "CLIENT_STORAGE_KEY": "jsonqlstore", + "CLIENT_AUTH_KEY": "jsonqlauthkey", + "INDEX_KEY": "index", + "CONTRACT_KEY_NAME": "X-JSONQL-CV-KEY", + "SHOW_CONTRACT_DESC_PARAM": { + "desc": "y" + }, + "DEFAULT_RESOLVER_DIR": "resolvers", + "DEFAULT_CONTRACT_DIR": "contracts", + "DEFAULT_KEYS_DIR": "keys", + "CJS_TYPE": "cjs", + "ES_TYPE": "es", + "TS_TYPE": "ts", + "ACCEPTED_JS_TYPES": [ + "cjs", + "es" + ], + "RETURN_AS_FILE": "file", + "RETURN_AS_JSON": "json", + "RETURN_AS_ENUM": [ + "file", + "json" + ], + "NO_ERROR_MSG": "No message", + "NO_STATUS_CODE": -1, + "INIT_CLIENT_PROP_KEY": "nodeClient", + "INIT_CONTRACT_PROP_KEY": "initContract", + "SUCCESS_STATUS": 200, + "UNAUTHORIZED_STATUS": 401, + "FORBIDDEN_STATUS": 403, + "NOT_FOUND_STATUS": 404, + "DEFAULT_PORT_NUM": 6557, + "CSRF_HEADER_KEY": "X-CSRF-Token", + "ORIGIN_HEADER_KEYS": [ + "Origin" + ], + "WILD_CARD_CHAR": "*", + "TYPE_KEY": "type", + "OPTIONAL_KEY": "optional", + "ENUM_KEY": "enumv", + "ARGS_KEY": "args", + "CHECKER_KEY": "checker", + "ALIAS_KEY": "alias", + "CHECKED_KEY": "__checked__", + "APP_DIR_PROP_KEY": "appDir", + "AUTH_TO_PROP_KEY": "authTimeout", + "ENABLE_AUTH_PROP_KEY": "enableAuth", + "USE_JWT_PROP_KEY": "useJwt", + "RESOLVER_DIR_PROP_KEY": "resolverDir", + "CONTRACT_DIR_PROP_KEY": "contractDir", + "INIT_CONNECTION_FN_NAME_PROP_KEY": "initConnectionHandlerName", + "LOGIN_FN_NAME_PROP_KEY": "loginHandlerName", + "LOGOUT_FN_NAME_PROP_KEY": "logoutHandlerName", + "DISCONNECT_FN_NAME_PROP_KEY": "disconnectHandlerName", + "SWITCH_USER_FN_NAME_PROP_KEY": "switchUserHandlerName", + "PUBLIC_FN_DIR_PROP_KEY": "publicResolverDir", + "PRIVATE_FN_DIR_DROP_KEY": "privateResolverDir", + "ALGORITHM_PROP_KEY": "algorithm", + "KEYS_DIR_PROP_KEY": "keysDir", + "SOCKET_IO_AUTH_TYPE_PROP_KEY": "socketIoAuthType", + "SERVER_INIT_OPT_PROP_KEY": "serverInitOption", + "SOCKET_TYPE_PROP_KEY": "serverType", + "SOCKET_TYPE_CLIENT_ALIAS": "socketClientType", + "SOCKET_TYPE_SERVER_ALIAS": "socketServerType", + "CSRF_PROP_KEY": "csrf", + "ALLOW_ORIGIN_PROP_KEY": "allowOrigin", + "STANDALONE_PROP_KEY": "standalone", + "DEBUG_ON_PROP_KEY": "debugOn", + "HOSTNAME_PROP_KEY": "hostname", + "NAMESAPCE_PROP_KEY": "namespace", + "WS_OPT_PROP_KEY": "wsOptions", + "CONTRACT_PROP_KEY": "contract", + "TOKEN_PROP_KEY": "token", + "CONTENT_TYPE_PROP_KEY": "contentType", + "RETURN_AS_PROP_KEY": "returnAs", + "NAME_PROP_KEY": "appName", + "EXPIRED_PROP_KEY": "expired", + "APP_ROOT_DIR_PROP_KEY": "appRootDir", + "JWT_TOKEN_OPT_PROP_KEY": "jwtTokenOption", + "ENABLE_JSONP_PROP_KEY": "enableJsonp", + "CONTRACT_WITH_DESC_PROP_KEY": "contractWithDesc", + "WITH_PUBLIC_CONTRACT_PROP_KEY": "withPublicContract", + "PUBLIC_KEY_NAME_PROP_KEY": "publicKeyFileName", + "PRIVATE_KEY_NAME_PROP_KEY": "privateKeyFileName", + "RSA_MODULE_LEN_PROP_KEY": "rsaModulusLength", + "JSONQL_PATH_PROP_KEY": "jsonqlPath", + "CONTRACT_KEY_PROP_KEY": "contractKey", + "CONTRACT_KEY_NAME_PROP_KEY": "contractKeyName", + "ENABLE_WEB_CONSOLE_PROP_KEY": "enableWebConsole", + "JS_TYPE_PROP_KEY": "jsType", + "EXPOSE_ERR_PROP_KEY": "exposeError", + "CLIENT_CONFIG_PROP_KEY": "clientConfig", + "AUTO_CONTRACT_PROP_KEY": "autoCreateContract", + "VALIDATE_RETURNS_PROP_KEY": "validateReturns", + "ENABLE_UPLOAD_PROP_KEY": "enableFileUpload", + "FILE_UPLOAD_NAME_PROP_KEY": "fileUploadName", + "FILE_UPLOAD_DIST_PROP_KEY": "fileUploadDist", + "FILE_HANDLER_FN_NAME_PROP_KEY": "fileHandlerName", + "ENABLE_SPLIT_TASK_PROP_KEY": "enableSplitTask", + "SOCKET_PING_EVENT_NAME": "__ping__", + "SWITCH_USER_EVENT_NAME": "__switch__", + "LOGIN_EVENT_NAME": "__login__", + "LOGOUT_EVENT_NAME": "__logout__", + "SA_LOGIN_EVENT_NAME": "__standalone_login__", + "RECONNECT_EVENT_NAME": "__reconnect__", + "SOCKET_CLIENT_ID_KEY": "__socket_client_id_key__", + "SOCKET_CLIENT_TS_KEY": "__socket_client_ts_key__", + "CONNECTED_EVENT_NAME": "__connected__", + "DISCONNECT_EVENT_NAME": "__disconnect__", + "INTERCOM_RESOLVER_NAME": "__intercom__", + "INTER_COM_EVENT_NAMES": [ + "__connected__", + "__switch__", + "__disconnect__" + ], + "WS_REPLY_TYPE": "__reply__", + "WS_EVT_NAME": "__event__", + "WS_DATA_NAME": "__data__", + "WS_IS_REPLY_KEYS": [ + "__reply__", + "__event__", + "__data__" + ], + "ON_MESSAGE_FN_NAME": "onMessage", + "ON_RESULT_FN_NAME": "onResult", + "ON_ERROR_FN_NAME": "onError", + "ON_READY_FN_NAME": "onReady", + "ON_LOGIN_FN_NAME": "onLogin", + "SEND_MSG_FN_NAME": "send", + "CLIENT_PROP_NAME": "client", + "USERDATA_PROP_NAME": "userdata", + "EMIT_REPLY_TYPE": "emit_reply", + "ACKNOWLEDGE_REPLY_TYPE": "acknowledge_reply", + "NSP_GROUP": "nspGroup", + "PUBLIC_NAMESPACE": "publicNamespace", + "JS_WS_SOCKET_IO_NAME": "socket.io", + "JS_WS_NAME": "ws", + "JS_PRIMUS_NAME": "primus", + "GO_WS_COOLPY7_NAME": "coolpy7", + "DEFAULT_WS_WAIT_TIME": 5000, + "DEFAULT_RETRY_TIME": 3000, + "TIMEOUT_ERR_MSG": "timeout", + "NOT_LOGIN_ERR_MSG": "NOT LOGIN", + "BASE64_FORMAT": "base64", + "HEX_FORMAT": "hex", + "UTF8_FORMAT": "utf8", + "RSA_FORMATS": [ + "base64", + "hex" + ], + "RSA_ALGO": "RS256", + "HSA_ALGO": "HS256", + "JWT_SUPPORT_ALGOS": [ + "RS256", + "HS256" + ], + "RSA_PRIVATE_KEY_HEADER": "BEGIN RSA PRIVATE KEY", + "RSA_MIN_MODULE_LEN": 1024, + "RSA_MAX_MODULE_LEN": 4096, + "TOKEN_PARAM_NAME": "token", + "IO_ROUNDTRIP_LOGIN": "roundtip", + "IO_HANDSHAKE_LOGIN": "handshake", + "IO_LOGIN_METHODS": [ + "roundtip", + "handshake" + ], + "PEM_EXT": "pem", + "PUBLIC_KEY_NAME": "publicKey", + "PRIVATE_KEY_NAME": "privateKey", + "DEFAULT_PUBLIC_KEY_FILE": "publicKey.pem", + "DEFAULT_PRIVATE_KEY_FILE": "privateKey.pem", + "OR_SEPERATOR": "|", + "FUNCTION_TYPE": "function", + "STRING_TYPE": "string", + "BOOLEAN_TYPE": "boolean", + "ARRAY_TYPE": "array", + "OBJECT_TYPE": "object", + "ANY_TYPE": "any", + "NUMBER_TYPE": "number", + "NUMBER_TYPES": [ + "int", + "integer", + "float", + "double", + "decimal" + ], + "SUPPORTED_TYPES": [ + "number", + "string", + "boolean", + "array", + "object", + "any" + ], + "ARRAY_TS_TYPE_LFT": "Array<", + "ARRAY_TYPE_LFT": "array.<", + "ARRAY_TYPE_RGT": ">" +} \ No newline at end of file diff --git a/packages/constants/build.js b/packages/constants/build.js index c961f2d9..cef41b58 100644 --- a/packages/constants/build.js +++ b/packages/constants/build.js @@ -10,7 +10,7 @@ const files = [ ] const importFn = require('./import') -const readme = '\r\n' +let readme = '\r\n' const allProps = files.map(file => { @@ -18,9 +18,7 @@ const allProps = files.map(file => { // create README output readme += `### ${file.replace('.js', '').toUpperCase()}\r\n\r\n` - readme += Object.keys(props).map(prop => ( - `- ${prop}\r\n` - )) + readme += Object.keys(props).map(prop => `- ${prop}\r\n`) readme += '\r\n' return props @@ -38,7 +36,7 @@ fsx.outputFileSync(join(__dirname, 'README.md'), content) // out put the cjs main.js fsx.outputFileSync(join(__dirname, 'main.js'), cjs) // output to browser.js -fsx.outputFileSynx(join(__dirname, 'browser.js'), browser) +fsx.outputFileSync(join(__dirname, 'browser.js'), browser) // output to constants.json fsx.outputJson(join(__dirname, 'constants.json'), allProps, { spaces: 2 }, err => { if (err) { diff --git a/packages/constants/constants.json b/packages/constants/constants.json index 93112558..afe94d13 100644 --- a/packages/constants/constants.json +++ b/packages/constants/constants.json @@ -50,18 +50,11 @@ "KEY_WORD": "continue", "PUBLIC_KEY": "public", "PRIVATE_KEY": "private", - "TYPE_KEY": "type", - "OPTIONAL_KEY": "optional", - "ENUM_KEY": "enumv", - "ARGS_KEY": "args", - "CHECKER_KEY": "checker", - "ALIAS_KEY": "alias", - "CHECKED_KEY": "__checked__", "AUTH_TYPE": "auth", "AUTH_NAME": "auth", - "LOGIN_NAME": "login", - "LOGOUT_NAME": "logout", - "VALIDATOR_NAME": "validator", + "LOGIN_FN_NAME": "login", + "LOGOUT_FN_NAME": "logout", + "VALIDATOR_FN_NAME": "validator", "DISCONNECT_FN_NAME": "disconnect", "SWITCH_USER_FN_NAME": "switch-user", "AUTH_HEADER": "Authorization", @@ -85,32 +78,6 @@ "cjs", "es" ], - "OR_SEPERATOR": "|", - "FUNCTION_TYPE": "function", - "STRING_TYPE": "string", - "BOOLEAN_TYPE": "boolean", - "ARRAY_TYPE": "array", - "OBJECT_TYPE": "object", - "ANY_TYPE": "any", - "NUMBER_TYPE": "number", - "NUMBER_TYPES": [ - "int", - "integer", - "float", - "double", - "decimal" - ], - "SUPPORTED_TYPES": [ - "number", - "string", - "boolean", - "array", - "object", - "any" - ], - "ARRAY_TS_TYPE_LFT": "Array<", - "ARRAY_TYPE_LFT": "array.<", - "ARRAY_TYPE_RGT": ">", "RETURN_AS_FILE": "file", "RETURN_AS_JSON": "json", "RETURN_AS_ENUM": [ @@ -119,6 +86,80 @@ ], "NO_ERROR_MSG": "No message", "NO_STATUS_CODE": -1, + "INIT_CLIENT_PROP_KEY": "nodeClient", + "INIT_CONTRACT_PROP_KEY": "initContract", + "SUCCESS_STATUS": 200, + "UNAUTHORIZED_STATUS": 401, + "FORBIDDEN_STATUS": 403, + "NOT_FOUND_STATUS": 404, + "DEFAULT_PORT_NUM": 6557, + "CSRF_HEADER_KEY": "X-CSRF-Token", + "ORIGIN_HEADER_KEYS": [ + "Origin" + ], + "WILD_CARD_CHAR": "*", + "TYPE_KEY": "type", + "OPTIONAL_KEY": "optional", + "ENUM_KEY": "enumv", + "ARGS_KEY": "args", + "CHECKER_KEY": "checker", + "ALIAS_KEY": "alias", + "CHECKED_KEY": "__checked__", + "APP_DIR_PROP_KEY": "appDir", + "AUTH_TO_PROP_KEY": "authTimeout", + "ENABLE_AUTH_PROP_KEY": "enableAuth", + "USE_JWT_PROP_KEY": "useJwt", + "RESOLVER_DIR_PROP_KEY": "resolverDir", + "CONTRACT_DIR_PROP_KEY": "contractDir", + "INIT_CONNECTION_FN_NAME_PROP_KEY": "initConnectionHandlerName", + "LOGIN_FN_NAME_PROP_KEY": "loginHandlerName", + "LOGOUT_FN_NAME_PROP_KEY": "logoutHandlerName", + "DISCONNECT_FN_NAME_PROP_KEY": "disconnectHandlerName", + "SWITCH_USER_FN_NAME_PROP_KEY": "switchUserHandlerName", + "PUBLIC_FN_DIR_PROP_KEY": "publicResolverDir", + "PRIVATE_FN_DIR_DROP_KEY": "privateResolverDir", + "ALGORITHM_PROP_KEY": "algorithm", + "KEYS_DIR_PROP_KEY": "keysDir", + "SOCKET_IO_AUTH_TYPE_PROP_KEY": "socketIoAuthType", + "SERVER_INIT_OPT_PROP_KEY": "serverInitOption", + "SOCKET_TYPE_PROP_KEY": "serverType", + "SOCKET_TYPE_CLIENT_ALIAS": "socketClientType", + "SOCKET_TYPE_SERVER_ALIAS": "socketServerType", + "CSRF_PROP_KEY": "csrf", + "ALLOW_ORIGIN_PROP_KEY": "allowOrigin", + "STANDALONE_PROP_KEY": "standalone", + "DEBUG_ON_PROP_KEY": "debugOn", + "HOSTNAME_PROP_KEY": "hostname", + "NAMESAPCE_PROP_KEY": "namespace", + "WS_OPT_PROP_KEY": "wsOptions", + "CONTRACT_PROP_KEY": "contract", + "TOKEN_PROP_KEY": "token", + "CONTENT_TYPE_PROP_KEY": "contentType", + "RETURN_AS_PROP_KEY": "returnAs", + "NAME_PROP_KEY": "appName", + "EXPIRED_PROP_KEY": "expired", + "APP_ROOT_DIR_PROP_KEY": "appRootDir", + "JWT_TOKEN_OPT_PROP_KEY": "jwtTokenOption", + "ENABLE_JSONP_PROP_KEY": "enableJsonp", + "CONTRACT_WITH_DESC_PROP_KEY": "contractWithDesc", + "WITH_PUBLIC_CONTRACT_PROP_KEY": "withPublicContract", + "PUBLIC_KEY_NAME_PROP_KEY": "publicKeyFileName", + "PRIVATE_KEY_NAME_PROP_KEY": "privateKeyFileName", + "RSA_MODULE_LEN_PROP_KEY": "rsaModulusLength", + "JSONQL_PATH_PROP_KEY": "jsonqlPath", + "CONTRACT_KEY_PROP_KEY": "contractKey", + "CONTRACT_KEY_NAME_PROP_KEY": "contractKeyName", + "ENABLE_WEB_CONSOLE_PROP_KEY": "enableWebConsole", + "JS_TYPE_PROP_KEY": "jsType", + "EXPOSE_ERR_PROP_KEY": "exposeError", + "CLIENT_CONFIG_PROP_KEY": "clientConfig", + "AUTO_CONTRACT_PROP_KEY": "autoCreateContract", + "VALIDATE_RETURNS_PROP_KEY": "validateReturns", + "ENABLE_UPLOAD_PROP_KEY": "enableFileUpload", + "FILE_UPLOAD_NAME_PROP_KEY": "fileUploadName", + "FILE_UPLOAD_DIST_PROP_KEY": "fileUploadDist", + "FILE_HANDLER_FN_NAME_PROP_KEY": "fileHandlerName", + "ENABLE_SPLIT_TASK_PROP_KEY": "enableSplitTask", "SOCKET_PING_EVENT_NAME": "__ping__", "SWITCH_USER_EVENT_NAME": "__switch__", "LOGIN_EVENT_NAME": "__login__", @@ -143,18 +184,6 @@ "__event__", "__data__" ], - "EMIT_REPLY_TYPE": "emit_reply", - "ACKNOWLEDGE_REPLY_TYPE": "acknowledge_reply", - "ERROR_TYPE": "error", - "NSP_GROUP": "nspGroup", - "PUBLIC_NAMESPACE": "publicNamespace", - "JS_WS_SOCKET_IO_NAME": "socket.io", - "JS_WS_NAME": "ws", - "JS_PRIMUS_NAME": "primus", - "GO_WS_COOLPY7_NAME": "coolpy7", - "SOCKET_TYPE_KEY": "serverType", - "SOCKET_TYPE_CLIENT_ALIAS": "socketClientType", - "SOCKET_TYPE_SERVER_ALIAS": "socketServerType", "ON_MESSAGE_FN_NAME": "onMessage", "ON_RESULT_FN_NAME": "onResult", "ON_ERROR_FN_NAME": "onError", @@ -163,8 +192,14 @@ "SEND_MSG_FN_NAME": "send", "CLIENT_PROP_NAME": "client", "USERDATA_PROP_NAME": "userdata", - "INIT_CLIENT_PROP_KEY": "nodeClient", - "INIT_CONTRACT_PROP_KEY": "initContract", + "EMIT_REPLY_TYPE": "emit_reply", + "ACKNOWLEDGE_REPLY_TYPE": "acknowledge_reply", + "NSP_GROUP": "nspGroup", + "PUBLIC_NAMESPACE": "publicNamespace", + "JS_WS_SOCKET_IO_NAME": "socket.io", + "JS_WS_NAME": "ws", + "JS_PRIMUS_NAME": "primus", + "GO_WS_COOLPY7_NAME": "coolpy7", "DEFAULT_WS_WAIT_TIME": 5000, "DEFAULT_RETRY_TIME": 3000, "TIMEOUT_ERR_MSG": "timeout", @@ -197,14 +232,30 @@ "PRIVATE_KEY_NAME": "privateKey", "DEFAULT_PUBLIC_KEY_FILE": "publicKey.pem", "DEFAULT_PRIVATE_KEY_FILE": "privateKey.pem", - "SUCCESS_STATUS": 200, - "UNAUTHORIZED_STATUS": 401, - "FORBIDDEN_STATUS": 403, - "NOT_FOUND_STATUS": 404, - "DEFAULT_PORT_NUM": 6557, - "CSRF_HEADER_KEY": "X-CSRF-Token", - "ORIGIN_HEADER_KEYS": [ - "Origin" + "OR_SEPERATOR": "|", + "FUNCTION_TYPE": "function", + "STRING_TYPE": "string", + "BOOLEAN_TYPE": "boolean", + "ARRAY_TYPE": "array", + "OBJECT_TYPE": "object", + "ANY_TYPE": "any", + "NUMBER_TYPE": "number", + "NUMBER_TYPES": [ + "int", + "integer", + "float", + "double", + "decimal" ], - "WILD_CARD_CHAR": "*" + "SUPPORTED_TYPES": [ + "number", + "string", + "boolean", + "array", + "object", + "any" + ], + "ARRAY_TS_TYPE_LFT": "Array<", + "ARRAY_TYPE_LFT": "array.<", + "ARRAY_TYPE_RGT": ">" } diff --git a/packages/constants/import.js b/packages/constants/import.js index aabbd296..4ed26293 100644 --- a/packages/constants/import.js +++ b/packages/constants/import.js @@ -12,12 +12,12 @@ function requireEsModule(pathToResolver) { require = require("esm")(module/*, options*/) const obj = require(pathToResolver) // console.error('requireEsModule', obj) - if (typeof obj === 'function' && !obj.default) { + if ((typeof obj === 'function' || typeof obj === 'object') && !obj.default) { return obj } else if (obj.default && (typeof obj.default === 'object' || typeof obj.default === 'function')) { return obj.default } - console.error('ERROR', typeof obj.default, obj) + console.error('ERROR', typeof obj, typeof obj.default, obj) throw new Error(`Unable to import ES module!`) } catch (e) { throw new Error(e) diff --git a/packages/constants/main.js b/packages/constants/main.js index 765ea418..7aa1fbcf 100644 --- a/packages/constants/main.js +++ b/packages/constants/main.js @@ -50,18 +50,11 @@ module.exports = { "KEY_WORD": "continue", "PUBLIC_KEY": "public", "PRIVATE_KEY": "private", - "TYPE_KEY": "type", - "OPTIONAL_KEY": "optional", - "ENUM_KEY": "enumv", - "ARGS_KEY": "args", - "CHECKER_KEY": "checker", - "ALIAS_KEY": "alias", - "CHECKED_KEY": "__checked__", "AUTH_TYPE": "auth", "AUTH_NAME": "auth", - "LOGIN_NAME": "login", - "LOGOUT_NAME": "logout", - "VALIDATOR_NAME": "validator", + "LOGIN_FN_NAME": "login", + "LOGOUT_FN_NAME": "logout", + "VALIDATOR_FN_NAME": "validator", "DISCONNECT_FN_NAME": "disconnect", "SWITCH_USER_FN_NAME": "switch-user", "AUTH_HEADER": "Authorization", @@ -85,32 +78,6 @@ module.exports = { "cjs", "es" ], - "OR_SEPERATOR": "|", - "FUNCTION_TYPE": "function", - "STRING_TYPE": "string", - "BOOLEAN_TYPE": "boolean", - "ARRAY_TYPE": "array", - "OBJECT_TYPE": "object", - "ANY_TYPE": "any", - "NUMBER_TYPE": "number", - "NUMBER_TYPES": [ - "int", - "integer", - "float", - "double", - "decimal" - ], - "SUPPORTED_TYPES": [ - "number", - "string", - "boolean", - "array", - "object", - "any" - ], - "ARRAY_TS_TYPE_LFT": "Array<", - "ARRAY_TYPE_LFT": "array.<", - "ARRAY_TYPE_RGT": ">", "RETURN_AS_FILE": "file", "RETURN_AS_JSON": "json", "RETURN_AS_ENUM": [ @@ -119,6 +86,80 @@ module.exports = { ], "NO_ERROR_MSG": "No message", "NO_STATUS_CODE": -1, + "INIT_CLIENT_PROP_KEY": "nodeClient", + "INIT_CONTRACT_PROP_KEY": "initContract", + "SUCCESS_STATUS": 200, + "UNAUTHORIZED_STATUS": 401, + "FORBIDDEN_STATUS": 403, + "NOT_FOUND_STATUS": 404, + "DEFAULT_PORT_NUM": 6557, + "CSRF_HEADER_KEY": "X-CSRF-Token", + "ORIGIN_HEADER_KEYS": [ + "Origin" + ], + "WILD_CARD_CHAR": "*", + "TYPE_KEY": "type", + "OPTIONAL_KEY": "optional", + "ENUM_KEY": "enumv", + "ARGS_KEY": "args", + "CHECKER_KEY": "checker", + "ALIAS_KEY": "alias", + "CHECKED_KEY": "__checked__", + "APP_DIR_PROP_KEY": "appDir", + "AUTH_TO_PROP_KEY": "authTimeout", + "ENABLE_AUTH_PROP_KEY": "enableAuth", + "USE_JWT_PROP_KEY": "useJwt", + "RESOLVER_DIR_PROP_KEY": "resolverDir", + "CONTRACT_DIR_PROP_KEY": "contractDir", + "INIT_CONNECTION_FN_NAME_PROP_KEY": "initConnectionHandlerName", + "LOGIN_FN_NAME_PROP_KEY": "loginHandlerName", + "LOGOUT_FN_NAME_PROP_KEY": "logoutHandlerName", + "DISCONNECT_FN_NAME_PROP_KEY": "disconnectHandlerName", + "SWITCH_USER_FN_NAME_PROP_KEY": "switchUserHandlerName", + "PUBLIC_FN_DIR_PROP_KEY": "publicResolverDir", + "PRIVATE_FN_DIR_DROP_KEY": "privateResolverDir", + "ALGORITHM_PROP_KEY": "algorithm", + "KEYS_DIR_PROP_KEY": "keysDir", + "SOCKET_IO_AUTH_TYPE_PROP_KEY": "socketIoAuthType", + "SERVER_INIT_OPT_PROP_KEY": "serverInitOption", + "SOCKET_TYPE_PROP_KEY": "serverType", + "SOCKET_TYPE_CLIENT_ALIAS": "socketClientType", + "SOCKET_TYPE_SERVER_ALIAS": "socketServerType", + "CSRF_PROP_KEY": "csrf", + "ALLOW_ORIGIN_PROP_KEY": "allowOrigin", + "STANDALONE_PROP_KEY": "standalone", + "DEBUG_ON_PROP_KEY": "debugOn", + "HOSTNAME_PROP_KEY": "hostname", + "NAMESAPCE_PROP_KEY": "namespace", + "WS_OPT_PROP_KEY": "wsOptions", + "CONTRACT_PROP_KEY": "contract", + "TOKEN_PROP_KEY": "token", + "CONTENT_TYPE_PROP_KEY": "contentType", + "RETURN_AS_PROP_KEY": "returnAs", + "NAME_PROP_KEY": "appName", + "EXPIRED_PROP_KEY": "expired", + "APP_ROOT_DIR_PROP_KEY": "appRootDir", + "JWT_TOKEN_OPT_PROP_KEY": "jwtTokenOption", + "ENABLE_JSONP_PROP_KEY": "enableJsonp", + "CONTRACT_WITH_DESC_PROP_KEY": "contractWithDesc", + "WITH_PUBLIC_CONTRACT_PROP_KEY": "withPublicContract", + "PUBLIC_KEY_NAME_PROP_KEY": "publicKeyFileName", + "PRIVATE_KEY_NAME_PROP_KEY": "privateKeyFileName", + "RSA_MODULE_LEN_PROP_KEY": "rsaModulusLength", + "JSONQL_PATH_PROP_KEY": "jsonqlPath", + "CONTRACT_KEY_PROP_KEY": "contractKey", + "CONTRACT_KEY_NAME_PROP_KEY": "contractKeyName", + "ENABLE_WEB_CONSOLE_PROP_KEY": "enableWebConsole", + "JS_TYPE_PROP_KEY": "jsType", + "EXPOSE_ERR_PROP_KEY": "exposeError", + "CLIENT_CONFIG_PROP_KEY": "clientConfig", + "AUTO_CONTRACT_PROP_KEY": "autoCreateContract", + "VALIDATE_RETURNS_PROP_KEY": "validateReturns", + "ENABLE_UPLOAD_PROP_KEY": "enableFileUpload", + "FILE_UPLOAD_NAME_PROP_KEY": "fileUploadName", + "FILE_UPLOAD_DIST_PROP_KEY": "fileUploadDist", + "FILE_HANDLER_FN_NAME_PROP_KEY": "fileHandlerName", + "ENABLE_SPLIT_TASK_PROP_KEY": "enableSplitTask", "SOCKET_PING_EVENT_NAME": "__ping__", "SWITCH_USER_EVENT_NAME": "__switch__", "LOGIN_EVENT_NAME": "__login__", @@ -143,18 +184,6 @@ module.exports = { "__event__", "__data__" ], - "EMIT_REPLY_TYPE": "emit_reply", - "ACKNOWLEDGE_REPLY_TYPE": "acknowledge_reply", - "ERROR_TYPE": "error", - "NSP_GROUP": "nspGroup", - "PUBLIC_NAMESPACE": "publicNamespace", - "JS_WS_SOCKET_IO_NAME": "socket.io", - "JS_WS_NAME": "ws", - "JS_PRIMUS_NAME": "primus", - "GO_WS_COOLPY7_NAME": "coolpy7", - "SOCKET_TYPE_KEY": "serverType", - "SOCKET_TYPE_CLIENT_ALIAS": "socketClientType", - "SOCKET_TYPE_SERVER_ALIAS": "socketServerType", "ON_MESSAGE_FN_NAME": "onMessage", "ON_RESULT_FN_NAME": "onResult", "ON_ERROR_FN_NAME": "onError", @@ -163,8 +192,14 @@ module.exports = { "SEND_MSG_FN_NAME": "send", "CLIENT_PROP_NAME": "client", "USERDATA_PROP_NAME": "userdata", - "INIT_CLIENT_PROP_KEY": "nodeClient", - "INIT_CONTRACT_PROP_KEY": "initContract", + "EMIT_REPLY_TYPE": "emit_reply", + "ACKNOWLEDGE_REPLY_TYPE": "acknowledge_reply", + "NSP_GROUP": "nspGroup", + "PUBLIC_NAMESPACE": "publicNamespace", + "JS_WS_SOCKET_IO_NAME": "socket.io", + "JS_WS_NAME": "ws", + "JS_PRIMUS_NAME": "primus", + "GO_WS_COOLPY7_NAME": "coolpy7", "DEFAULT_WS_WAIT_TIME": 5000, "DEFAULT_RETRY_TIME": 3000, "TIMEOUT_ERR_MSG": "timeout", @@ -197,14 +232,30 @@ module.exports = { "PRIVATE_KEY_NAME": "privateKey", "DEFAULT_PUBLIC_KEY_FILE": "publicKey.pem", "DEFAULT_PRIVATE_KEY_FILE": "privateKey.pem", - "SUCCESS_STATUS": 200, - "UNAUTHORIZED_STATUS": 401, - "FORBIDDEN_STATUS": 403, - "NOT_FOUND_STATUS": 404, - "DEFAULT_PORT_NUM": 6557, - "CSRF_HEADER_KEY": "X-CSRF-Token", - "ORIGIN_HEADER_KEYS": [ - "Origin" + "OR_SEPERATOR": "|", + "FUNCTION_TYPE": "function", + "STRING_TYPE": "string", + "BOOLEAN_TYPE": "boolean", + "ARRAY_TYPE": "array", + "OBJECT_TYPE": "object", + "ANY_TYPE": "any", + "NUMBER_TYPE": "number", + "NUMBER_TYPES": [ + "int", + "integer", + "float", + "double", + "decimal" ], - "WILD_CARD_CHAR": "*" + "SUPPORTED_TYPES": [ + "number", + "string", + "boolean", + "array", + "object", + "any" + ], + "ARRAY_TS_TYPE_LFT": "Array<", + "ARRAY_TYPE_LFT": "array.<", + "ARRAY_TYPE_RGT": ">" } \ No newline at end of file -- Gitee From 44bf9c6d6d76c7dcf4880286b468c98e8562f188 Mon Sep 17 00:00:00 2001 From: joelchu Date: Sun, 15 Mar 2020 15:40:02 +0800 Subject: [PATCH 10/10] Fix all and ready to publish jsonql-constants to 2.0.0 --- packages/constants/README.md | 432 ++++++++++++++++---------------- packages/constants/build.js | 10 +- packages/constants/package.json | 2 +- 3 files changed, 223 insertions(+), 221 deletions(-) diff --git a/packages/constants/README.md b/packages/constants/README.md index 720b0229..283c8ca9 100755 --- a/packages/constants/README.md +++ b/packages/constants/README.md @@ -20,222 +20,222 @@ Please consult the detail break down below. ## constants - -### BASE - -- EXT -,- TS_EXT -,- HELLO -,- HELLO_FN -,- DATA_KEY -,- ERROR_KEY -,- JSONQL_PATH -,- CONTENT_TYPE -,- CHARSET -,- DEFAULT_HEADER -,- DEFAULT_TYPE -,- DEFAULT_CONTRACT_FILE_NAME -,- PUBLIC_CONTRACT_FILE_NAME -,- DEFAULT_RESOLVER_LIST_FILE_NAME -,- DEFAULT_RESOLVER_IMPORT_FILE_NAME -,- MODULE_TYPE -,- SCRIPT_TYPE -,- QUERY_NAME -,- MUTATION_NAME -,- SOCKET_NAME -,- CONTRACT_NAME -,- RESOLVER_TYPES -,- PAYLOAD_PARAM_NAME -,- CONDITION_PARAM_NAME -,- RESOLVER_PARAM_NAME -,- QUERY_ARG_NAME -,- TIMESTAMP_PARAM_NAME -,- MUTATION_ARGS -,- JSONP_CALLBACK_NAME -,- API_REQUEST_METHODS -,- CONTRACT_REQUEST_METHODS -,- KEY_WORD -,- PUBLIC_KEY -,- PRIVATE_KEY -,- AUTH_TYPE -,- AUTH_NAME -,- LOGIN_FN_NAME -,- LOGOUT_FN_NAME -,- VALIDATOR_FN_NAME -,- DISCONNECT_FN_NAME -,- SWITCH_USER_FN_NAME -,- AUTH_HEADER -,- AUTH_CHECK_HEADER -,- BEARER -,- CREDENTIAL_STORAGE_KEY -,- CLIENT_STORAGE_KEY -,- CLIENT_AUTH_KEY -,- INDEX_KEY -,- CONTRACT_KEY_NAME -,- SHOW_CONTRACT_DESC_PARAM -,- DEFAULT_RESOLVER_DIR -,- DEFAULT_CONTRACT_DIR -,- DEFAULT_KEYS_DIR -,- CJS_TYPE -,- ES_TYPE -,- TS_TYPE -,- ACCEPTED_JS_TYPES -,- RETURN_AS_FILE -,- RETURN_AS_JSON -,- RETURN_AS_ENUM -,- NO_ERROR_MSG -,- NO_STATUS_CODE -,- INIT_CLIENT_PROP_KEY -,- INIT_CONTRACT_PROP_KEY -,- SUCCESS_STATUS -,- UNAUTHORIZED_STATUS -,- FORBIDDEN_STATUS -,- NOT_FOUND_STATUS -,- DEFAULT_PORT_NUM -,- CSRF_HEADER_KEY -,- ORIGIN_HEADER_KEYS -,- WILD_CARD_CHAR - -### PROP - -- TYPE_KEY -,- OPTIONAL_KEY -,- ENUM_KEY -,- ARGS_KEY -,- CHECKER_KEY -,- ALIAS_KEY -,- CHECKED_KEY -,- APP_DIR_PROP_KEY -,- AUTH_TO_PROP_KEY -,- ENABLE_AUTH_PROP_KEY -,- USE_JWT_PROP_KEY -,- RESOLVER_DIR_PROP_KEY -,- CONTRACT_DIR_PROP_KEY -,- INIT_CONNECTION_FN_NAME_PROP_KEY -,- LOGIN_FN_NAME_PROP_KEY -,- LOGOUT_FN_NAME_PROP_KEY -,- DISCONNECT_FN_NAME_PROP_KEY -,- SWITCH_USER_FN_NAME_PROP_KEY -,- PUBLIC_FN_DIR_PROP_KEY -,- PRIVATE_FN_DIR_DROP_KEY -,- ALGORITHM_PROP_KEY -,- KEYS_DIR_PROP_KEY -,- SOCKET_IO_AUTH_TYPE_PROP_KEY -,- SERVER_INIT_OPT_PROP_KEY -,- SOCKET_TYPE_PROP_KEY -,- SOCKET_TYPE_CLIENT_ALIAS -,- SOCKET_TYPE_SERVER_ALIAS -,- CSRF_PROP_KEY -,- ALLOW_ORIGIN_PROP_KEY -,- STANDALONE_PROP_KEY -,- DEBUG_ON_PROP_KEY -,- HOSTNAME_PROP_KEY -,- NAMESAPCE_PROP_KEY -,- WS_OPT_PROP_KEY -,- CONTRACT_PROP_KEY -,- TOKEN_PROP_KEY -,- INIT_CONTRACT_PROP_KEY -,- CONTENT_TYPE_PROP_KEY -,- RETURN_AS_PROP_KEY -,- NAME_PROP_KEY -,- EXPIRED_PROP_KEY -,- APP_ROOT_DIR_PROP_KEY -,- JWT_TOKEN_OPT_PROP_KEY -,- ENABLE_JSONP_PROP_KEY -,- CONTRACT_WITH_DESC_PROP_KEY -,- WITH_PUBLIC_CONTRACT_PROP_KEY -,- PUBLIC_KEY_NAME_PROP_KEY -,- PRIVATE_KEY_NAME_PROP_KEY -,- RSA_MODULE_LEN_PROP_KEY -,- JSONQL_PATH_PROP_KEY -,- CONTRACT_KEY_PROP_KEY -,- CONTRACT_KEY_NAME_PROP_KEY -,- ENABLE_WEB_CONSOLE_PROP_KEY -,- JS_TYPE_PROP_KEY -,- EXPOSE_ERR_PROP_KEY -,- CLIENT_CONFIG_PROP_KEY -,- AUTO_CONTRACT_PROP_KEY -,- VALIDATE_RETURNS_PROP_KEY -,- ENABLE_UPLOAD_PROP_KEY -,- FILE_UPLOAD_NAME_PROP_KEY -,- FILE_UPLOAD_DIST_PROP_KEY -,- FILE_HANDLER_FN_NAME_PROP_KEY -,- ENABLE_SPLIT_TASK_PROP_KEY - -### SOCKET - -- SOCKET_PING_EVENT_NAME -,- SWITCH_USER_EVENT_NAME -,- LOGIN_EVENT_NAME -,- LOGOUT_EVENT_NAME -,- SA_LOGIN_EVENT_NAME -,- RECONNECT_EVENT_NAME -,- SOCKET_CLIENT_ID_KEY -,- SOCKET_CLIENT_TS_KEY -,- CONNECTED_EVENT_NAME -,- DISCONNECT_EVENT_NAME -,- INTERCOM_RESOLVER_NAME -,- INTER_COM_EVENT_NAMES -,- WS_REPLY_TYPE -,- WS_EVT_NAME -,- WS_DATA_NAME -,- WS_IS_REPLY_KEYS -,- ON_MESSAGE_FN_NAME -,- ON_RESULT_FN_NAME -,- ON_ERROR_FN_NAME -,- ON_READY_FN_NAME -,- ON_LOGIN_FN_NAME -,- SEND_MSG_FN_NAME -,- CLIENT_PROP_NAME -,- USERDATA_PROP_NAME -,- EMIT_REPLY_TYPE -,- ACKNOWLEDGE_REPLY_TYPE -,- NSP_GROUP -,- PUBLIC_NAMESPACE -,- JS_WS_SOCKET_IO_NAME -,- JS_WS_NAME -,- JS_PRIMUS_NAME -,- GO_WS_COOLPY7_NAME -,- DEFAULT_WS_WAIT_TIME -,- DEFAULT_RETRY_TIME -,- TIMEOUT_ERR_MSG -,- NOT_LOGIN_ERR_MSG -,- BASE64_FORMAT -,- HEX_FORMAT -,- UTF8_FORMAT -,- RSA_FORMATS -,- RSA_ALGO -,- HSA_ALGO -,- JWT_SUPPORT_ALGOS -,- RSA_PRIVATE_KEY_HEADER -,- RSA_MIN_MODULE_LEN -,- RSA_MAX_MODULE_LEN -,- TOKEN_PARAM_NAME -,- IO_ROUNDTRIP_LOGIN -,- IO_HANDSHAKE_LOGIN -,- IO_LOGIN_METHODS -,- PEM_EXT -,- PUBLIC_KEY_NAME -,- PRIVATE_KEY_NAME -,- DEFAULT_PUBLIC_KEY_FILE -,- DEFAULT_PRIVATE_KEY_FILE - -### VALIDATION - -- OR_SEPERATOR -,- FUNCTION_TYPE -,- STRING_TYPE -,- BOOLEAN_TYPE -,- ARRAY_TYPE -,- OBJECT_TYPE -,- ANY_TYPE -,- NUMBER_TYPE -,- NUMBER_TYPES -,- SUPPORTED_TYPES -,- ARRAY_TS_TYPE_LFT -,- ARRAY_TYPE_LFT -,- ARRAY_TYPE_RGT - + +### BASE + +- EXT +- TS_EXT +- HELLO +- HELLO_FN +- DATA_KEY +- ERROR_KEY +- JSONQL_PATH +- CONTENT_TYPE +- CHARSET +- DEFAULT_HEADER +- DEFAULT_TYPE +- DEFAULT_CONTRACT_FILE_NAME +- PUBLIC_CONTRACT_FILE_NAME +- DEFAULT_RESOLVER_LIST_FILE_NAME +- DEFAULT_RESOLVER_IMPORT_FILE_NAME +- MODULE_TYPE +- SCRIPT_TYPE +- QUERY_NAME +- MUTATION_NAME +- SOCKET_NAME +- CONTRACT_NAME +- RESOLVER_TYPES +- PAYLOAD_PARAM_NAME +- CONDITION_PARAM_NAME +- RESOLVER_PARAM_NAME +- QUERY_ARG_NAME +- TIMESTAMP_PARAM_NAME +- MUTATION_ARGS +- JSONP_CALLBACK_NAME +- API_REQUEST_METHODS +- CONTRACT_REQUEST_METHODS +- KEY_WORD +- PUBLIC_KEY +- PRIVATE_KEY +- AUTH_TYPE +- AUTH_NAME +- LOGIN_FN_NAME +- LOGOUT_FN_NAME +- VALIDATOR_FN_NAME +- DISCONNECT_FN_NAME +- SWITCH_USER_FN_NAME +- AUTH_HEADER +- AUTH_CHECK_HEADER +- BEARER +- CREDENTIAL_STORAGE_KEY +- CLIENT_STORAGE_KEY +- CLIENT_AUTH_KEY +- INDEX_KEY +- CONTRACT_KEY_NAME +- SHOW_CONTRACT_DESC_PARAM +- DEFAULT_RESOLVER_DIR +- DEFAULT_CONTRACT_DIR +- DEFAULT_KEYS_DIR +- CJS_TYPE +- ES_TYPE +- TS_TYPE +- ACCEPTED_JS_TYPES +- RETURN_AS_FILE +- RETURN_AS_JSON +- RETURN_AS_ENUM +- NO_ERROR_MSG +- NO_STATUS_CODE +- INIT_CLIENT_PROP_KEY +- INIT_CONTRACT_PROP_KEY +- SUCCESS_STATUS +- UNAUTHORIZED_STATUS +- FORBIDDEN_STATUS +- NOT_FOUND_STATUS +- DEFAULT_PORT_NUM +- CSRF_HEADER_KEY +- ORIGIN_HEADER_KEYS +- WILD_CARD_CHAR + +### PROP + +- TYPE_KEY +- OPTIONAL_KEY +- ENUM_KEY +- ARGS_KEY +- CHECKER_KEY +- ALIAS_KEY +- CHECKED_KEY +- APP_DIR_PROP_KEY +- AUTH_TO_PROP_KEY +- ENABLE_AUTH_PROP_KEY +- USE_JWT_PROP_KEY +- RESOLVER_DIR_PROP_KEY +- CONTRACT_DIR_PROP_KEY +- INIT_CONNECTION_FN_NAME_PROP_KEY +- LOGIN_FN_NAME_PROP_KEY +- LOGOUT_FN_NAME_PROP_KEY +- DISCONNECT_FN_NAME_PROP_KEY +- SWITCH_USER_FN_NAME_PROP_KEY +- PUBLIC_FN_DIR_PROP_KEY +- PRIVATE_FN_DIR_DROP_KEY +- ALGORITHM_PROP_KEY +- KEYS_DIR_PROP_KEY +- SOCKET_IO_AUTH_TYPE_PROP_KEY +- SERVER_INIT_OPT_PROP_KEY +- SOCKET_TYPE_PROP_KEY +- SOCKET_TYPE_CLIENT_ALIAS +- SOCKET_TYPE_SERVER_ALIAS +- CSRF_PROP_KEY +- ALLOW_ORIGIN_PROP_KEY +- STANDALONE_PROP_KEY +- DEBUG_ON_PROP_KEY +- HOSTNAME_PROP_KEY +- NAMESAPCE_PROP_KEY +- WS_OPT_PROP_KEY +- CONTRACT_PROP_KEY +- TOKEN_PROP_KEY +- INIT_CONTRACT_PROP_KEY +- CONTENT_TYPE_PROP_KEY +- RETURN_AS_PROP_KEY +- NAME_PROP_KEY +- EXPIRED_PROP_KEY +- APP_ROOT_DIR_PROP_KEY +- JWT_TOKEN_OPT_PROP_KEY +- ENABLE_JSONP_PROP_KEY +- CONTRACT_WITH_DESC_PROP_KEY +- WITH_PUBLIC_CONTRACT_PROP_KEY +- PUBLIC_KEY_NAME_PROP_KEY +- PRIVATE_KEY_NAME_PROP_KEY +- RSA_MODULE_LEN_PROP_KEY +- JSONQL_PATH_PROP_KEY +- CONTRACT_KEY_PROP_KEY +- CONTRACT_KEY_NAME_PROP_KEY +- ENABLE_WEB_CONSOLE_PROP_KEY +- JS_TYPE_PROP_KEY +- EXPOSE_ERR_PROP_KEY +- CLIENT_CONFIG_PROP_KEY +- AUTO_CONTRACT_PROP_KEY +- VALIDATE_RETURNS_PROP_KEY +- ENABLE_UPLOAD_PROP_KEY +- FILE_UPLOAD_NAME_PROP_KEY +- FILE_UPLOAD_DIST_PROP_KEY +- FILE_HANDLER_FN_NAME_PROP_KEY +- ENABLE_SPLIT_TASK_PROP_KEY + +### SOCKET + +- SOCKET_PING_EVENT_NAME +- SWITCH_USER_EVENT_NAME +- LOGIN_EVENT_NAME +- LOGOUT_EVENT_NAME +- SA_LOGIN_EVENT_NAME +- RECONNECT_EVENT_NAME +- SOCKET_CLIENT_ID_KEY +- SOCKET_CLIENT_TS_KEY +- CONNECTED_EVENT_NAME +- DISCONNECT_EVENT_NAME +- INTERCOM_RESOLVER_NAME +- INTER_COM_EVENT_NAMES +- WS_REPLY_TYPE +- WS_EVT_NAME +- WS_DATA_NAME +- WS_IS_REPLY_KEYS +- ON_MESSAGE_FN_NAME +- ON_RESULT_FN_NAME +- ON_ERROR_FN_NAME +- ON_READY_FN_NAME +- ON_LOGIN_FN_NAME +- SEND_MSG_FN_NAME +- CLIENT_PROP_NAME +- USERDATA_PROP_NAME +- EMIT_REPLY_TYPE +- ACKNOWLEDGE_REPLY_TYPE +- NSP_GROUP +- PUBLIC_NAMESPACE +- JS_WS_SOCKET_IO_NAME +- JS_WS_NAME +- JS_PRIMUS_NAME +- GO_WS_COOLPY7_NAME +- DEFAULT_WS_WAIT_TIME +- DEFAULT_RETRY_TIME +- TIMEOUT_ERR_MSG +- NOT_LOGIN_ERR_MSG +- BASE64_FORMAT +- HEX_FORMAT +- UTF8_FORMAT +- RSA_FORMATS +- RSA_ALGO +- HSA_ALGO +- JWT_SUPPORT_ALGOS +- RSA_PRIVATE_KEY_HEADER +- RSA_MIN_MODULE_LEN +- RSA_MAX_MODULE_LEN +- TOKEN_PARAM_NAME +- IO_ROUNDTRIP_LOGIN +- IO_HANDSHAKE_LOGIN +- IO_LOGIN_METHODS +- PEM_EXT +- PUBLIC_KEY_NAME +- PRIVATE_KEY_NAME +- DEFAULT_PUBLIC_KEY_FILE +- DEFAULT_PRIVATE_KEY_FILE + +### VALIDATION + +- OR_SEPERATOR +- FUNCTION_TYPE +- STRING_TYPE +- BOOLEAN_TYPE +- ARRAY_TYPE +- OBJECT_TYPE +- ANY_TYPE +- NUMBER_TYPE +- NUMBER_TYPES +- SUPPORTED_TYPES +- ARRAY_TS_TYPE_LFT +- ARRAY_TYPE_LFT +- ARRAY_TYPE_RGT + --- diff --git a/packages/constants/build.js b/packages/constants/build.js index cef41b58..48bce60f 100644 --- a/packages/constants/build.js +++ b/packages/constants/build.js @@ -10,19 +10,21 @@ const files = [ ] const importFn = require('./import') -let readme = '\r\n' +let readme = '\n' const allProps = files.map(file => { let props = importFn(join(__dirname, file)) // create README output - readme += `### ${file.replace('.js', '').toUpperCase()}\r\n\r\n` - readme += Object.keys(props).map(prop => `- ${prop}\r\n`) - readme += '\r\n' + readme += `### ${file.replace('.js', '').toUpperCase()}\n\n` + readme += Object.keys(props).map(prop => `- ${prop}\n`) + readme += '\n' return props }).reduce((a, b) => Object.assign(a, b), {}) +// dirty hack to fix the extra character +readme = readme.replace(/\,\-/g, '-') const strJson = `${JSON.stringify(allProps, null, 4)}` diff --git a/packages/constants/package.json b/packages/constants/package.json index 73d2031e..23c1dd1f 100755 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -7,7 +7,7 @@ "browser": "browser.js", "files": [ "main.js", - "module.js", + "index.js", "base.js", "prop.js", "socket.js", -- Gitee