From 8c3e0d9e76ba19fa18e623d03a1c320eb89c677c Mon Sep 17 00:00:00 2001 From: Joel Zhu Date: Sun, 25 Aug 2019 21:38:42 +0800 Subject: [PATCH 01/17] change the way how the cache class store things use the hostname as the base key to avoid the cache problem we experience with the contract --- .../src/jsonql/jsonql-cache-class.js | 20 ++++++++++++++++--- packages/node-client/tests/auth.test.js | 11 +++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/packages/node-client/src/jsonql/jsonql-cache-class.js b/packages/node-client/src/jsonql/jsonql-cache-class.js index 7bf1f8cb..06c264ef 100644 --- a/packages/node-client/src/jsonql/jsonql-cache-class.js +++ b/packages/node-client/src/jsonql/jsonql-cache-class.js @@ -1,17 +1,31 @@ // using node-cache for storage +// @2019-08-25 we use the hostname as the base key then store the +// data associate with this particular object +const merge = require('lodash.merge') const NodeCache = require('node-cache') class JsonqlCacheClass { - constructor() { + constructor(config) { this.nc = new NodeCache() + this.ncBaseKey = config.hostname; + } + + get baseCacheObj() { + return this.nc.get(this.ncBaseKey) + } + + set baseCacheObj(values) { + this.nc.set(this.ncBaseKey, values) } getter(key) { - return this.nc.get(key) + let obj = this.baseCacheObj; + return (key in obj) ? obj[key] : false } setter(key, value) { - return this.nc.set(key,value) + let obj = this.baseCacheObj; + this.baseCacheObj = merge(obj, {[key]: value}) } } diff --git a/packages/node-client/tests/auth.test.js b/packages/node-client/tests/auth.test.js index 1adb4e87..8fc7432e 100755 --- a/packages/node-client/tests/auth.test.js +++ b/packages/node-client/tests/auth.test.js @@ -11,7 +11,7 @@ const { contractKey, loginToken, token } = require('./fixtures/options') const { JsonqlAuthorisationError } = require('jsonql-errors') test.before(async (t) => { - const { stop } = await server(); + const { stop } = await server() t.context.stop = stop; const client = await nodeClient({ @@ -19,13 +19,13 @@ test.before(async (t) => { enableAuth: true, contractDir, contractKey - }); + }) t.context.client = client; }) test.after(t => { - t.context.stop(); + t.context.stop() }) test('Testing the login function', async (t) => { @@ -43,6 +43,7 @@ test("Try a wrong password and cause the server to throw error", async t => { client.login('wrong-password') .catch(err => { t.true(err.className === 'JsonqlAuthorisationError') - }); - + }) }) + +test.todo(`Test if the loggin client token is persist`) -- Gitee From 68ad41fb6341556c5622fac8098ac43988ed461a Mon Sep 17 00:00:00 2001 From: joelchu Date: Sun, 25 Aug 2019 21:42:33 +0800 Subject: [PATCH 02/17] setup the basic structure for the new all in one websocket modules --- packages/@jsonql/ws/index.js | 2 ++ packages/@jsonql/ws/package.json | 4 +++- packages/@jsonql/ws/server.js | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 packages/@jsonql/ws/index.js create mode 100644 packages/@jsonql/ws/server.js diff --git a/packages/@jsonql/ws/index.js b/packages/@jsonql/ws/index.js new file mode 100644 index 00000000..35ee6a2a --- /dev/null +++ b/packages/@jsonql/ws/index.js @@ -0,0 +1,2 @@ +// this is the module entry point for ES6 for client +// the main will point to the node.js server side setup diff --git a/packages/@jsonql/ws/package.json b/packages/@jsonql/ws/package.json index 05aff1f4..b431434a 100644 --- a/packages/@jsonql/ws/package.json +++ b/packages/@jsonql/ws/package.json @@ -2,7 +2,9 @@ "name": "@jsonql/ws", "version": "0.0.1", "description": "WS (WebSocket) client / server module for jsonql", - "main": "index.js", + "main": "server.js", + "module": "index.js", + "browser": "dist/jsonql-ws.umd.js", "scripts": { "test": "ava" }, diff --git a/packages/@jsonql/ws/server.js b/packages/@jsonql/ws/server.js new file mode 100644 index 00000000..43156344 --- /dev/null +++ b/packages/@jsonql/ws/server.js @@ -0,0 +1 @@ +// this is the server side setup -- Gitee From 365a53c84b25113960b067292507824276564329 Mon Sep 17 00:00:00 2001 From: joelchu Date: Tue, 27 Aug 2019 16:23:11 +0100 Subject: [PATCH 03/17] add extra param to control if the user want to use the cors plugin --- packages/@jsonql/koa/index.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/@jsonql/koa/index.js b/packages/@jsonql/koa/index.js index 1c40fe92..21db2e94 100644 --- a/packages/@jsonql/koa/index.js +++ b/packages/@jsonql/koa/index.js @@ -4,6 +4,16 @@ const Koa = require('koa') const cors = require('koa-cors') const bodyparser = require('koa-bodyparser') const jsonql = require('jsonql-koa') +const DEFAULT_PORT = 8001; +/** + * simple util method to get the value + * @param {string} name of the key + * @param {object} obj to take value from + * @return {*} the object value id by name or undefined + */ +const getConfigValue = (name, obj) => ( + (name in obj) ? obj[name] : undefined +) /** * @param {object} [config={}] configuration @@ -11,10 +21,15 @@ const jsonql = require('jsonql-koa') */ module.exports = function(config = {}) { - const port = ('port' in config) ? config.port : 8001; + const port = getConfigValue('port', config) || DEFAULT_PORT; + //('port' in config) ? config.port : 8001; const app = new Koa() - app.use(cors()) + let noCors = getConfigValue('cors', config) + if (noCors === undefined || noCors !== false) { + debug(`use cors plugin`) + app.use(cors()) + } app.use(bodyparser()) app.use(jsonql(config)) @@ -24,7 +39,7 @@ module.exports = function(config = {}) { server.close() } debug(`@jsonql/koa server started on @${port}`) - + return { app, server, -- Gitee From c782e2bf02fd99ca07c623c8425294652c53fd28 Mon Sep 17 00:00:00 2001 From: joelchu Date: Sun, 1 Sep 2019 09:04:36 +0100 Subject: [PATCH 04/17] start porting koa to the @jsonql namespace --- packages/@jsonql/koa/config/default.json | 4 -- packages/@jsonql/koa/src/contracts/index.js | 1 + packages/@jsonql/koa/src/index.js | 1 + packages/@jsonql/koa/src/middlewares/index.js | 1 + packages/@jsonql/koa/src/options/index.js | 1 + packages/@jsonql/koa/src/utils/index.js | 1 + packages/@jsonql/koa/ts/README.md | 5 ++ packages/koa/src/lib/config-check/options.js | 13 ++-- .../src/plugin/public-contract.json | 60 +++++++++++++++---- 9 files changed, 68 insertions(+), 19 deletions(-) delete mode 100644 packages/@jsonql/koa/config/default.json create mode 100644 packages/@jsonql/koa/src/contracts/index.js create mode 100644 packages/@jsonql/koa/src/index.js create mode 100644 packages/@jsonql/koa/src/middlewares/index.js create mode 100644 packages/@jsonql/koa/src/options/index.js create mode 100644 packages/@jsonql/koa/src/utils/index.js create mode 100644 packages/@jsonql/koa/ts/README.md diff --git a/packages/@jsonql/koa/config/default.json b/packages/@jsonql/koa/config/default.json deleted file mode 100644 index 8ca2dd8e..00000000 --- a/packages/@jsonql/koa/config/default.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "jsonql-koa-stock-setup", - "port": 8001 -} diff --git a/packages/@jsonql/koa/src/contracts/index.js b/packages/@jsonql/koa/src/contracts/index.js new file mode 100644 index 00000000..d0f6bcd5 --- /dev/null +++ b/packages/@jsonql/koa/src/contracts/index.js @@ -0,0 +1 @@ +// contract related methods export diff --git a/packages/@jsonql/koa/src/index.js b/packages/@jsonql/koa/src/index.js new file mode 100644 index 00000000..4894a877 --- /dev/null +++ b/packages/@jsonql/koa/src/index.js @@ -0,0 +1 @@ +// completely reorganize the folder structure etc diff --git a/packages/@jsonql/koa/src/middlewares/index.js b/packages/@jsonql/koa/src/middlewares/index.js new file mode 100644 index 00000000..17ee5c44 --- /dev/null +++ b/packages/@jsonql/koa/src/middlewares/index.js @@ -0,0 +1 @@ +// all middleware export diff --git a/packages/@jsonql/koa/src/options/index.js b/packages/@jsonql/koa/src/options/index.js new file mode 100644 index 00000000..55c1ad22 --- /dev/null +++ b/packages/@jsonql/koa/src/options/index.js @@ -0,0 +1 @@ +// all the configuration options related methods export diff --git a/packages/@jsonql/koa/src/utils/index.js b/packages/@jsonql/koa/src/utils/index.js new file mode 100644 index 00000000..1edb22a5 --- /dev/null +++ b/packages/@jsonql/koa/src/utils/index.js @@ -0,0 +1 @@ +// the utils methods export diff --git a/packages/@jsonql/koa/ts/README.md b/packages/@jsonql/koa/ts/README.md new file mode 100644 index 00000000..2761d5e3 --- /dev/null +++ b/packages/@jsonql/koa/ts/README.md @@ -0,0 +1,5 @@ +# Typescript port + +There was an idea to port this into Typescript but later on, I found it completely pointless and waste of time. +Since Typescript running from node.js is NOT real language. Instead we move our focus onto deno.js instead, +which Typescript is support natively diff --git a/packages/koa/src/lib/config-check/options.js b/packages/koa/src/lib/config-check/options.js index 987cae06..e423dd74 100755 --- a/packages/koa/src/lib/config-check/options.js +++ b/packages/koa/src/lib/config-check/options.js @@ -27,14 +27,17 @@ const { DEFAULT_PUBLIC_KEY_FILE, DEFAULT_PRIVATE_KEY_FILE, RSA_MIN_MODULE_LEN -} = require('jsonql-constants'); -const { createConfig, constructConfig } = require('jsonql-params-validator'); +} = require('jsonql-constants') +const { + createConfig, + constructConfig +} = require('jsonql-params-validator') // const NodeCache = require('node-cache'); // const mcache = new NodeCache; // @BUG when we deploy it in docker, or using systemd the workingDirectory affect the // execute path, it might be better to allow a config option of workingDirectory and // use that as base -const dirname = process.cwd(); +const dirname = process.cwd() // @TODO we need to create the same fn to clear out the options like I did in server-io-core const constProps = { __checked__: true, @@ -46,7 +49,7 @@ const constProps = { privateKey: false, publicKey: false, initJwtKeys: false -}; +} const appProps = { name: createConfig('jsonql-koa', [STRING_TYPE]), // this is for ID which one is which when use as ms @@ -91,7 +94,7 @@ const appProps = { jsType: {[ARGS_KEY]: CJS_TYPE, [TYPE_KEY]: STRING_TYPE, [ENUM_KEY]: ACCEPTED_JS_TYPES}, // undecided properties - clientConfig: {[ARGS_KEY]: [], [TYPE_KEY]: ARRAY_TYPE}, // need to develop a new tool to validate and inject this + // clientConfig: {[ARGS_KEY]: [], [TYPE_KEY]: ARRAY_TYPE}, // need to develop a new tool to validate and inject this exposeError: {[ARGS_KEY]: false, [TYPE_KEY]: BOOLEAN_TYPE}, // this will allow you to control if you want to throw your error back to your client // Perhaps I should build the same create options style like server-io-core diff --git a/packages/web-console/src/plugin/public-contract.json b/packages/web-console/src/plugin/public-contract.json index c7808b85..a31c6b80 100644 --- a/packages/web-console/src/plugin/public-contract.json +++ b/packages/web-console/src/plugin/public-contract.json @@ -10,14 +10,14 @@ } ] }, - "defaultCall": { - "description": false, + "getUser": { + "description": "Get a user info", "params": [ { "type": [ "number" ], - "description": "a phony id", + "description": "the user id", "name": "id" } ], @@ -26,37 +26,77 @@ "type": [ "object" ], - "description": "an object with whatever" + "description": "userdata" } ] } }, "mutation": { - "defaultSave": { - "description": false, + "saveUser": { + "description": "Save userdata using id to identify which one", "params": [ { "type": [ "object" ], - "name": "payload" + "description": "the userdata object --> create interface", + "name": "payload", + "keys": [ + { + "type": [ + "string" + ], + "description": "name of user", + "name": "username", + "parent": "payload" + }, + { + "type": [ + "string" + ], + "description": "full name", + "name": "fullname", + "parent": "payload" + }, + { + "type": [ + "number", + "any" + ], + "description": "optional time stamp when created", + "name": "created", + "parent": "payload" + } + ] }, { "type": [ "object" ], - "name": "condition" + "description": "where cause", + "name": "condition", + "keys": [ + { + "type": [ + "number" + ], + "description": "the user id", + "name": "id", + "parent": "condition" + } + ] } ], "returns": [ { "type": [ "boolean" - ] + ], + "description": "true when OK" } ] } }, "auth": {}, - "timestamp": 1563798679 + "timestamp": 1565667859 } -- Gitee From ece12f63531658db5440ad2a2610589a14098d90 Mon Sep 17 00:00:00 2001 From: joelchu Date: Sun, 1 Sep 2019 15:27:08 +0100 Subject: [PATCH 05/17] breaking up the code into the utils --- packages/@jsonql/koa/src/utils/index.js | 32 ++++++ packages/util/index.js | 1 + packages/util/main.js | 1 + packages/util/package.json | 7 +- packages/util/src/chain-fns.js | 19 ++++ packages/util/src/contract.js | 1 + packages/util/src/error.js | 35 +++++++ packages/util/src/generic.js | 1 + packages/util/src/koa.js | 97 ++++++++++++++++++ packages/util/src/middleware.js | 128 ++++++++++++++++++++++++ 10 files changed, 319 insertions(+), 3 deletions(-) create mode 100644 packages/util/index.js create mode 100644 packages/util/main.js create mode 100644 packages/util/src/chain-fns.js create mode 100644 packages/util/src/contract.js create mode 100644 packages/util/src/error.js create mode 100644 packages/util/src/generic.js create mode 100644 packages/util/src/koa.js create mode 100644 packages/util/src/middleware.js diff --git a/packages/@jsonql/koa/src/utils/index.js b/packages/@jsonql/koa/src/utils/index.js index 1edb22a5..988bb80d 100644 --- a/packages/@jsonql/koa/src/utils/index.js +++ b/packages/@jsonql/koa/src/utils/index.js @@ -1 +1,33 @@ // the utils methods export +const processJwtKeys = require('./config-check/process-jwt-keys') +const { createTokenValidator } = require('jsonql-jwt') + +const { + chainFns, + + inArray, + getDebug, + + headerParser, + getDocLen, + packResult, + printError, + forbiddenHandler, + ctxErrorHandler, + + isJsonqlPath, + isJsonqlRequest, + isJsonqlConsoleUrl, + + getCallMethod, + isHeaderPresent, + + isObject, + isNotEmpty, + isContractJson, + handleOutput, + extractArgsFromPayload, + getNameFromPayload, + + extractParamsFromContract +} = require('./utils') diff --git a/packages/util/index.js b/packages/util/index.js new file mode 100644 index 00000000..5b3c710f --- /dev/null +++ b/packages/util/index.js @@ -0,0 +1 @@ +// exportfor ES modules diff --git a/packages/util/main.js b/packages/util/main.js new file mode 100644 index 00000000..7f6d3fa9 --- /dev/null +++ b/packages/util/main.js @@ -0,0 +1 @@ +// export for CJS modules diff --git a/packages/util/package.json b/packages/util/package.json index fad2b757..b31000ab 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -1,8 +1,9 @@ { - "name": "jsonql-util", - "version": "1.0.0-beta", + "name": "jsonql-utils", + "version": "1.0.0", "description": "This is not for generate use, it's for jsonql various modules", - "main": "index.js", + "main": "main.js", + "module": "index.js", "scripts": { "test": "ava" }, diff --git a/packages/util/src/chain-fns.js b/packages/util/src/chain-fns.js new file mode 100644 index 00000000..9bb05a4d --- /dev/null +++ b/packages/util/src/chain-fns.js @@ -0,0 +1,19 @@ +const _ = require('lodash') + +/** + * using lodash to chain two functions + * @param {function} mainFn function + * @param {array} ...moreFns functions spread + * @return {function} to accept the parameter for the first function + */ +const chainFns = (mainFn, ...moreFns) => ( + (...args) => { + let chain = _( Reflect.apply(mainFn, null, args) ).chain() + let ctn = moreFns.length; + for (let i = 0; i < ctn; ++i) { + chain = chain.thru(moreFns[i]) + } + + return chain.value() + } +) diff --git a/packages/util/src/contract.js b/packages/util/src/contract.js new file mode 100644 index 00000000..27e91dcf --- /dev/null +++ b/packages/util/src/contract.js @@ -0,0 +1 @@ +// contract related methods diff --git a/packages/util/src/error.js b/packages/util/src/error.js new file mode 100644 index 00000000..64e894e8 --- /dev/null +++ b/packages/util/src/error.js @@ -0,0 +1,35 @@ +// some useful methods for error handling +const { inspect } = require('util') +/** + * Port this from the CIS App + * @param {string} key of object + * @param {mixed} value of object + * @return {string} of things we after + */ +const replaceErrors = function(key, value) { + if (value instanceof Error) { + var error = {}; + Object.getOwnPropertyNames(value).forEach(function (key) { + error[key] = value[key]; + }) + return error; + } + return value; +} + +/** + * create readible string version of the error object + * @param {object} error obj + * @return {string} printable result + */ +const printError = function(error) { + //return 'MASKED'; //error.toString(); + // return JSON.stringify(error, replaceErrors); + return inspect(error, false, null, true) +} + + +module.exports = { + replaceErrors, + printError +} diff --git a/packages/util/src/generic.js b/packages/util/src/generic.js new file mode 100644 index 00000000..75074393 --- /dev/null +++ b/packages/util/src/generic.js @@ -0,0 +1 @@ +// bunch of generic helpers diff --git a/packages/util/src/koa.js b/packages/util/src/koa.js new file mode 100644 index 00000000..6aa51d8d --- /dev/null +++ b/packages/util/src/koa.js @@ -0,0 +1,97 @@ +// koa specific methods +const { CONTENT_TYPE } = require('jsonql-constants') + +/** + * @TODO need to be more flexible + * @param {object} ctx koa + * @param {object} opts configuration + * @return {boolean} if it match + */ +const isJsonqlPath = (ctx, opts) => ctx.path === opts.jsonqlPath; + +/** + * combine two check in one and save time + * @param {object} ctx koa + * @param {object} opts config + * @return {boolean} check result + */ +const isJsonqlRequest = (ctx, opts) => { + const header = isHeaderPresent(ctx.request, opts.contentType) + if (header) { + return isJsonqlPath(ctx, opts) + } + return false; +} + +/** + * check if this is point to the jsonql console + * @param {object} ctx koa context + * @param {object} opts config + * @return {boolean} + */ +const isJsonqlConsoleUrl = (ctx, opts) => ( + ctx.method === 'GET' && isJsonqlPath(ctx, opts) +) + +/** + * Handle the output + * @param {object} opts configuration + * @return {function} with ctx and body as params + */ +const handleOutput = function(opts) { + return function(ctx, body) { + ctx.size = getDocLen(body) + ctx.type = opts.contentType; + ctx.status = 200; + ctx.body = body; + } +} + +/** + * handle HTML output for the web console + * @param {object} ctx koa context + * @param {string} body output content + * @return {void} + */ +const handleHtmlOutput = function(ctx, body) { + ctx.size = getDocLen(body) + ctx.type = 'text/html'; + ctx.status = 200; + ctx.body = body + ''; // just make sure its string output +} + +/** + * use the ctx to generate error output + * V1.1.0 we render this as a normal output with status 200 + * then on the client side will check against the result object for error + * @param {object} ctx context + * @param {number} code 404 / 500 etc + * @param {object} e actual error + * @param {string} message if there is one + * @param {string} name custom error class name + */ +const ctxErrorHandler = function(ctx, code, e, message = '') { + const render = handleOutput({contentType: CONTENT_TYPE}) + let name; + if (typeof code === 'string') { + name = code; + code = jsonqlErrors[name] ? jsonqlErrors[name].statusCode : -1; + } else { + name = jsonqlErrors.getErrorByStatus(code) + } + // preserve the message + if (!message && e && e.message) { + message = e.message; + } + return render(ctx, packError(e, name, code, message)) +} + +/** + * Just a wrapper to be clearer what error is it + * @param {object} ctx koa + * @param {object} e error + * @return {undefined} nothing + */ +const forbiddenHandler = (ctx, e) => ( + ctxErrorHandler(ctx, 403, e, 'JsonqlAuthorisationError') +) diff --git a/packages/util/src/middleware.js b/packages/util/src/middleware.js new file mode 100644 index 00000000..0aed9d5d --- /dev/null +++ b/packages/util/src/middleware.js @@ -0,0 +1,128 @@ +// this is a collection of middleware methods +// should be good to use in Koa or Express +const _ = require('lodash') +const { trim } = _; +const { + QUERY_NAME, + MUTATION_NAME, + API_REQUEST_METHODS, + PAYLOAD_PARAM_NAME, + CONDITION_PARAM_NAME, + RESOLVER_PARAM_NAME , + QUERY_ARG_NAME +} = require('jsonql-constants') + +/** + * From underscore.string library + * @BUG there is a bug here with the non-standard name start with _ + * @param {string} str string + * @return {string} dasherize string + */ +const dasherize = str => ( + trim(str) + .replace(/([A-Z])/g, '-$1') + .replace(/[-_\s]+/g, '-') + .toLowerCase() +) + +/** + * Get document (string) byte length for use in header + * @param {string} doc to calculate + * @return {number} length + */ +const getDocLen = doc => Buffer.byteLength(doc, 'utf8') + +/** + * The koa ctx object is not returning what it said on the documentation + * So I need to write a custom parser to check the request content-type + * @param {object} req the ctx.request + * @param {string} type (optional) to check against + * @return {mixed} Array or Boolean + */ +const headerParser = (req, type) => { + try { + const headers = req.headers.accept.split(',') + if (type) { + return headers.filter(h => h === type) + } + return headers; + } catch (e) { + // When Chrome dev tool activate the headers become empty + return []; + } +} + +/** + * wrapper of above method to make it easier to use + * @param {object} req ctx.request + * @param {string} type of header + * @return {boolean} + */ +const isHeaderPresent = (req, type) => { + const headers = headerParser(req, type) + return !!headers.length; +} + +/** + * getting what is calling after the above check + * @param {string} method of call + * @return {mixed} false on failed + */ +const getCallMethod = method => { + const [ POST, PUT ] = API_REQUEST_METHODS; + switch (true) { + case method === POST: + return QUERY_NAME; + case method === PUT: + return MUTATION_NAME; + default: + return false; + } +} + +/** + * @param {string} name + * @param {string} type + * @param {object} opts + * @return {function} + */ +const getPathToFn = function(name, type, opts) { + const dir = opts.resolverDir; + const fileName = dasherize(name); + let paths = []; + if (opts.contract && opts.contract[type] && opts.contract[type].path) { + paths.push(opts.contract[type].path); + } + paths.push( join(dir, type, fileName, 'index.js') ) + paths.push( join(dir, type, fileName + '.js') ) + // paths.push( join(dir, fileName + '.js') ); + const ctn = paths.length; + for (let i=0; i { + return JSON.stringify({ data: result }) +} + +/** + * wrapper method - the output is trying to match up the structure of the Error sub class + * @param {mixed} detail of fn error + * @param {string} [className=JsonqlError] the errorName + * @param {number} [statusCode=500] the original error code + * @return {string} stringify error + */ +const packError = function(detail, className = 'JsonqlError', statusCode = 500, message = '') { + return JSON.stringify({ + error: { detail, className, statusCode, message } + }) +} -- Gitee From 907bf15ba217acd5a197b8f054491262d5bc4bb0 Mon Sep 17 00:00:00 2001 From: joelchu Date: Sun, 1 Sep 2019 18:15:40 +0100 Subject: [PATCH 06/17] rename util to utils --- packages/{util => utils}/README.md | 0 packages/{util => utils}/index.js | 0 packages/{util => utils}/main.js | 0 packages/{util => utils}/package.json | 0 packages/{util => utils}/src/chain-fns.js | 0 packages/{util => utils}/src/contract.js | 0 packages/{util => utils}/src/error.js | 0 packages/{util => utils}/src/generic.js | 0 packages/{util => utils}/src/koa.js | 0 packages/{util => utils}/src/middleware.js | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename packages/{util => utils}/README.md (100%) rename packages/{util => utils}/index.js (100%) rename packages/{util => utils}/main.js (100%) rename packages/{util => utils}/package.json (100%) rename packages/{util => utils}/src/chain-fns.js (100%) rename packages/{util => utils}/src/contract.js (100%) rename packages/{util => utils}/src/error.js (100%) rename packages/{util => utils}/src/generic.js (100%) rename packages/{util => utils}/src/koa.js (100%) rename packages/{util => utils}/src/middleware.js (100%) diff --git a/packages/util/README.md b/packages/utils/README.md similarity index 100% rename from packages/util/README.md rename to packages/utils/README.md diff --git a/packages/util/index.js b/packages/utils/index.js similarity index 100% rename from packages/util/index.js rename to packages/utils/index.js diff --git a/packages/util/main.js b/packages/utils/main.js similarity index 100% rename from packages/util/main.js rename to packages/utils/main.js diff --git a/packages/util/package.json b/packages/utils/package.json similarity index 100% rename from packages/util/package.json rename to packages/utils/package.json diff --git a/packages/util/src/chain-fns.js b/packages/utils/src/chain-fns.js similarity index 100% rename from packages/util/src/chain-fns.js rename to packages/utils/src/chain-fns.js diff --git a/packages/util/src/contract.js b/packages/utils/src/contract.js similarity index 100% rename from packages/util/src/contract.js rename to packages/utils/src/contract.js diff --git a/packages/util/src/error.js b/packages/utils/src/error.js similarity index 100% rename from packages/util/src/error.js rename to packages/utils/src/error.js diff --git a/packages/util/src/generic.js b/packages/utils/src/generic.js similarity index 100% rename from packages/util/src/generic.js rename to packages/utils/src/generic.js diff --git a/packages/util/src/koa.js b/packages/utils/src/koa.js similarity index 100% rename from packages/util/src/koa.js rename to packages/utils/src/koa.js diff --git a/packages/util/src/middleware.js b/packages/utils/src/middleware.js similarity index 100% rename from packages/util/src/middleware.js rename to packages/utils/src/middleware.js -- Gitee From 2184508ba703c818cbf53622cc1391f477c2e9b2 Mon Sep 17 00:00:00 2001 From: joelchu Date: Sun, 1 Sep 2019 18:17:59 +0100 Subject: [PATCH 07/17] update packages for jsonql-utils --- packages/utils/package.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/utils/package.json b/packages/utils/package.json index b31000ab..7ab4fc12 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -33,5 +33,14 @@ "failWithoutAssertions": false, "tap": false, "compileEnhancements": false + }, + "dependencies": { + "esm": "^3.2.25", + "jsonql-constants": "^1.7.9", + "jsonql-errors": "^1.1.2", + "lodash-es": "^4.17.15" + }, + "devDependencies": { + "ava": "^2.3.0" } } -- Gitee From b2246e551b360e9b987a5b1c1adc2103147ffeff Mon Sep 17 00:00:00 2001 From: joelchu Date: Sun, 1 Sep 2019 18:45:49 +0100 Subject: [PATCH 08/17] port the chain-fns over for the first test, also the param-api from jsonql-params-validator --- packages/utils/main.js | 4 +- packages/utils/package.json | 1 + packages/utils/src/chain-fns.js | 19 ---- packages/utils/src/generic.js | 36 +++++++ packages/utils/src/params-api.js | 142 ++++++++++++++++++++++++++ packages/utils/tests/chain-fn.test.js | 17 +++ 6 files changed, 199 insertions(+), 20 deletions(-) delete mode 100644 packages/utils/src/chain-fns.js create mode 100644 packages/utils/src/params-api.js create mode 100644 packages/utils/tests/chain-fn.test.js diff --git a/packages/utils/main.js b/packages/utils/main.js index 7f6d3fa9..188245a2 100644 --- a/packages/utils/main.js +++ b/packages/utils/main.js @@ -1 +1,3 @@ -// export for CJS modules +// export for CJS modules using esm modules +require = require('esm')(module) +module.exports = require('./index.js') diff --git a/packages/utils/package.json b/packages/utils/package.json index 7ab4fc12..786d5fab 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -35,6 +35,7 @@ "compileEnhancements": false }, "dependencies": { + "debug": "^4.1.1", "esm": "^3.2.25", "jsonql-constants": "^1.7.9", "jsonql-errors": "^1.1.2", diff --git a/packages/utils/src/chain-fns.js b/packages/utils/src/chain-fns.js deleted file mode 100644 index 9bb05a4d..00000000 --- a/packages/utils/src/chain-fns.js +++ /dev/null @@ -1,19 +0,0 @@ -const _ = require('lodash') - -/** - * using lodash to chain two functions - * @param {function} mainFn function - * @param {array} ...moreFns functions spread - * @return {function} to accept the parameter for the first function - */ -const chainFns = (mainFn, ...moreFns) => ( - (...args) => { - let chain = _( Reflect.apply(mainFn, null, args) ).chain() - let ctn = moreFns.length; - for (let i = 0; i < ctn; ++i) { - chain = chain.thru(moreFns[i]) - } - - return chain.value() - } -) diff --git a/packages/utils/src/generic.js b/packages/utils/src/generic.js index 75074393..7a5f321e 100644 --- a/packages/utils/src/generic.js +++ b/packages/utils/src/generic.js @@ -1 +1,37 @@ // bunch of generic helpers +import debug from 'debug' +import * as _ from 'lodash-es' + +/** + * @param {string} name the name part after the : + * @param {string} baseName the base before the : + */ +export const getDebug = (name, baseName = 'jsonql') => { + debug(baseName).extend(name) +} + +/** + * using lodash to chain two functions + * @param {function} mainFn function + * @param {array} ...moreFns functions spread + * @return {function} to accept the parameter for the first function + */ +export const chainFns = (mainFn, ...moreFns) => ( + (...args) => { + let chain = _( Reflect.apply(mainFn, null, args) ).chain() + let ctn = moreFns.length; + for (let i = 0; i < ctn; ++i) { + chain = chain.thru(moreFns[i]) + } + + return chain.value() + } +) + +/** + * DIY in Array + * @param {array} arr to check from + * @param {*} value to check against + * @return {boolean} true on found + */ +export const inArray = (arr, value) => !!arr.filter(a => a === value).length; diff --git a/packages/utils/src/params-api.js b/packages/utils/src/params-api.js new file mode 100644 index 00000000..64758db4 --- /dev/null +++ b/packages/utils/src/params-api.js @@ -0,0 +1,142 @@ +// ported from jsonql-params-validator +// craete several helper function to construct / extract the payload +// and make sure they are all the same +import { + PAYLOAD_PARAM_NAME, + CONDITION_PARAM_NAME, + RESOLVER_PARAM_NAME, + QUERY_ARG_NAME +} from 'jsonql-constants' +import { JsonqlValidationError } from 'jsonql-errors' + +import isString from './string' +import { checkIsArray } from './array' +import { checkIsObject } from './object' + +// make sure it's an object +const formatPayload = payload => isString(payload) ? JSON.parse(payload) : payload; + +/** + * Get name from the payload (ported back from jsonql-koa) + * @param {*} payload to extract from + * @return {string} name + */ +export function getNameFromPayload(payload) { + return Object.keys(payload)[0] +} + +/** + * @param {string} resolverName name of function + * @param {array} [args=[]] from the ...args + * @param {boolean} [jsonp = false] add v1.3.0 to koa + * @return {object} formatted argument + */ +export function createQuery(resolverName, args = [], jsonp = false) { + if (isString(resolverName) && checkIsArray(args)) { + let payload = { [QUERY_ARG_NAME]: args } + if (jsonp === true) { + return payload; + } + return { [resolverName]: payload } + } + throw new JsonqlValidationError(`[createQuery] expect resolverName to be string and args to be array!`, { resolverName, args }) +} + +// string version of the above +export function createQueryStr(resolverName, args = [], jsonp = false) { + return JSON.stringify(createQuery(resolverName, args, jsonp)) +} + +/** + * @param {string} resolverName name of function + * @param {*} payload to send + * @param {object} [condition={}] for what + * @param {boolean} [jsonp = false] add v1.3.0 to koa + * @return {object} formatted argument + */ +export function createMutation(resolverName, payload, condition = {}, jsonp = false) { + const _payload = { + [PAYLOAD_PARAM_NAME]: payload, + [CONDITION_PARAM_NAME]: condition + } + if (jsonp === true) { + return _payload; + } + if (isString(resolverName)) { + return { [resolverName]: _payload } + } + throw new JsonqlValidationError(`[createMutation] expect resolverName to be string!`, { resolverName, payload, condition }) +} + +// string version of above +export function createMutationStr(resolverName, payload, condition = {}, jsonp = false) { + return JSON.stringify(createMutation(resolverName, payload, condition, jsonp)) +} + +/** + * Further break down from method below for use else where + * @param {string} resolverName name of fn + * @param {object} payload payload + * @return {object|boolean} false on failed + */ +export function getQueryFromArgs(resolverName, payload) { + if (resolverName && checkIsObject(payload)) { + const args = payload[resolverName]; + if (args[QUERY_ARG_NAME]) { + return { + [RESOLVER_PARAM_NAME]: resolverName, + [QUERY_ARG_NAME]: args[QUERY_ARG_NAME] + } + } + } + return false; +} + +/** + * extra the payload back + * @param {*} payload from http call + * @return {object} resolverName and args + */ +export function getQueryFromPayload(payload) { + const p = formatPayload(payload); + const resolverName = getNameFromPayload(p) + const result = getQueryFromArgs(resolverName, p) + if (result !== false) { + return result; + } + throw new JsonqlValidationError('[getQueryArgs] Payload is malformed!', payload) +} + +/** + * Further break down from method below for use else where + * @param {string} resolverName name of fn + * @param {object} payload payload + * @return {object|boolean} false on failed + */ +export function getMutationFromArgs(resolverName, payload) { + if (resolverName && checkIsObject(payload)) { + const args = payload[resolverName] + if (args) { + return { + [RESOLVER_PARAM_NAME]: resolverName, + [PAYLOAD_PARAM_NAME]: args[PAYLOAD_PARAM_NAME], + [CONDITION_PARAM_NAME]: args[CONDITION_PARAM_NAME] + } + } + } + return false; +} + +/** + * @param {object} payload + * @return {object} resolverName, payload, conditon + */ +export function getMutationFromPayload(payload) { + const p = formatPayload(payload); + const resolverName = getNameFromPayload(p) + const result = getMutationFromArgs(resolverName, p) + if (result !== false) { + return result; + } + throw new JsonqlValidationError('[getMutationArgs] Payload is malformed!', payload) +} diff --git a/packages/utils/tests/chain-fn.test.js b/packages/utils/tests/chain-fn.test.js new file mode 100644 index 00000000..f01fcfd3 --- /dev/null +++ b/packages/utils/tests/chain-fn.test.js @@ -0,0 +1,17 @@ +// need to test the chain-fns because of the way we change the lodash import +const test = require('ava') +const { chainFns } = require('../src/generic') + +test('It should able to accept more than one functions after the first one', t => { + + const baseFn = (num) => num * 10; + const add1 = (num) => num + 1; + const add2 = (num) => num + 2; + + const fn = chainFns(baseFn, add1, add2) + + const result = fn(10) + + t.is(103, result) + +}) -- Gitee From 1f0247232b92e25573edcd84af1ff17890640747 Mon Sep 17 00:00:00 2001 From: joelchu Date: Sun, 1 Sep 2019 18:55:48 +0100 Subject: [PATCH 09/17] coffee shop is closing, got kick out :S --- packages/utils/src/chain-fns.js | 78 +++++++++++++++++++++++++++++++++ packages/utils/src/generic.js | 21 +-------- 2 files changed, 80 insertions(+), 19 deletions(-) create mode 100644 packages/utils/src/chain-fns.js diff --git a/packages/utils/src/chain-fns.js b/packages/utils/src/chain-fns.js new file mode 100644 index 00000000..23ba0f37 --- /dev/null +++ b/packages/utils/src/chain-fns.js @@ -0,0 +1,78 @@ +// break it out on its own because +// it's building from the lodash-es from scratch +// according to this discussion https://github.com/lodash/lodash/issues/3298 +import map from 'lodash-es/map'; +import filter from 'lodash-es/filter'; + +import toPairs from 'lodash-es/toPairs'; +import orderBy from 'lodash-es/orderBy'; +import groupBy from 'lodash-es/groupBy'; +import sortBy from 'lodash-es/sortBy'; + +import mapValues from 'lodash-es/mapValues' +import thru from 'lodash-es/thru' + +const chainableFunctions = { + map, + filter, + toPairs, + orderBy, + groupBy, + sortBy +} + +/* TS +export const chain = (input: T) => { + let value: any = input; + const wrapper = { + ...mapValues( + chainableFunctions, + (f: any) => (...args: any[]) => { + // lodash always puts input as the first argument + value = f(value, ...args); + return wrapper; + }, + ), + value: () => value, + }; + return wrapper as _.LoDashExplicitWrapper; +}; +*/ + +/** + * @param {*} input anything + * @return {object} chainable object call + */ +export const chainFn = (input) => { + let value = input; + const wrapper = { + ...mapValues( + chainableFunctions, + (f) => (...args) => { + // lodash always puts input as the first argument + value = f(value, ...args); + return wrapper; + }, + ), + value: () => value, + }; + return wrapper; +} + +/** + * using lodash to chain two functions + * @param {function} mainFn function + * @param {array} ...moreFns functions spread + * @return {function} to accept the parameter for the first function + */ +export const chainFns = (mainFn, ...moreFns) => ( + (...args) => { + let chain = chainFn( Reflect.apply(mainFn, null, args) ) + let ctn = moreFns.length; + for (let i = 0; i < ctn; ++i) { + chain = chain.thru(moreFns[i]) + } + + return chain.value() + } +) diff --git a/packages/utils/src/generic.js b/packages/utils/src/generic.js index 7a5f321e..10e6b093 100644 --- a/packages/utils/src/generic.js +++ b/packages/utils/src/generic.js @@ -1,6 +1,7 @@ // bunch of generic helpers import debug from 'debug' -import * as _ from 'lodash-es' +// import * as _ from 'lodash-es' + /** * @param {string} name the name part after the : @@ -10,24 +11,6 @@ export const getDebug = (name, baseName = 'jsonql') => { debug(baseName).extend(name) } -/** - * using lodash to chain two functions - * @param {function} mainFn function - * @param {array} ...moreFns functions spread - * @return {function} to accept the parameter for the first function - */ -export const chainFns = (mainFn, ...moreFns) => ( - (...args) => { - let chain = _( Reflect.apply(mainFn, null, args) ).chain() - let ctn = moreFns.length; - for (let i = 0; i < ctn; ++i) { - chain = chain.thru(moreFns[i]) - } - - return chain.value() - } -) - /** * DIY in Array * @param {array} arr to check from -- Gitee From 8ea542a6391266a5300146382377cc95bebb43e7 Mon Sep 17 00:00:00 2001 From: joelchu Date: Mon, 2 Sep 2019 12:38:59 +0100 Subject: [PATCH 10/17] use reduce to handle the chain func instead of lodash --- packages/utils/src/chain-fns.js | 79 +++------------------------ packages/utils/tests/chain-fn.test.js | 2 +- 2 files changed, 10 insertions(+), 71 deletions(-) diff --git a/packages/utils/src/chain-fns.js b/packages/utils/src/chain-fns.js index 23ba0f37..ed0c7eee 100644 --- a/packages/utils/src/chain-fns.js +++ b/packages/utils/src/chain-fns.js @@ -1,78 +1,17 @@ // break it out on its own because // it's building from the lodash-es from scratch // according to this discussion https://github.com/lodash/lodash/issues/3298 -import map from 'lodash-es/map'; -import filter from 'lodash-es/filter'; - -import toPairs from 'lodash-es/toPairs'; -import orderBy from 'lodash-es/orderBy'; -import groupBy from 'lodash-es/groupBy'; -import sortBy from 'lodash-es/sortBy'; - -import mapValues from 'lodash-es/mapValues' -import thru from 'lodash-es/thru' - -const chainableFunctions = { - map, - filter, - toPairs, - orderBy, - groupBy, - sortBy -} - -/* TS -export const chain = (input: T) => { - let value: any = input; - const wrapper = { - ...mapValues( - chainableFunctions, - (f: any) => (...args: any[]) => { - // lodash always puts input as the first argument - value = f(value, ...args); - return wrapper; - }, - ), - value: () => value, - }; - return wrapper as _.LoDashExplicitWrapper; -}; -*/ /** - * @param {*} input anything - * @return {object} chainable object call - */ -export const chainFn = (input) => { - let value = input; - const wrapper = { - ...mapValues( - chainableFunctions, - (f) => (...args) => { - // lodash always puts input as the first argument - value = f(value, ...args); - return wrapper; - }, - ), - value: () => value, - }; - return wrapper; -} - -/** - * using lodash to chain two functions - * @param {function} mainFn function - * @param {array} ...moreFns functions spread - * @return {function} to accept the parameter for the first function + * using just the map reduce to chain multiple functions together + * @param {function} mainFn the init function + * @param {array} moreFns as many as you want to take the last value and return a new one + * @return {function} accept value for the mainFn */ export const chainFns = (mainFn, ...moreFns) => ( - (...args) => { - let chain = chainFn( Reflect.apply(mainFn, null, args) ) - let ctn = moreFns.length; - for (let i = 0; i < ctn; ++i) { - chain = chain.thru(moreFns[i]) - } - - return chain.value() - } + (...args) => ( + moreFns.reduce((value, nextFn) => ( + Reflect.apply(nextFn, null, [value]) + ), Reflect.apply(mainFn, null, args)) + ) ) diff --git a/packages/utils/tests/chain-fn.test.js b/packages/utils/tests/chain-fn.test.js index f01fcfd3..4121d2e6 100644 --- a/packages/utils/tests/chain-fn.test.js +++ b/packages/utils/tests/chain-fn.test.js @@ -1,6 +1,6 @@ // need to test the chain-fns because of the way we change the lodash import const test = require('ava') -const { chainFns } = require('../src/generic') +const { chainFns } = require('../src/chain-fns') test('It should able to accept more than one functions after the first one', t => { -- Gitee From e2edd7abdc8854ba489751447542eb2357906cd6 Mon Sep 17 00:00:00 2001 From: joelchu Date: Mon, 2 Sep 2019 12:52:35 +0100 Subject: [PATCH 11/17] preparing the next dynamic es6 import test --- packages/utils/tests/fixtures/es6-fn.js | 4 ++++ packages/utils/tests/fixtures/import.js | 9 +++++++++ 2 files changed, 13 insertions(+) create mode 100644 packages/utils/tests/fixtures/es6-fn.js create mode 100644 packages/utils/tests/fixtures/import.js diff --git a/packages/utils/tests/fixtures/es6-fn.js b/packages/utils/tests/fixtures/es6-fn.js new file mode 100644 index 00000000..309491c4 --- /dev/null +++ b/packages/utils/tests/fixtures/es6-fn.js @@ -0,0 +1,4 @@ + +export default function fun() { + return `I am fine!` +} diff --git a/packages/utils/tests/fixtures/import.js b/packages/utils/tests/fixtures/import.js new file mode 100644 index 00000000..413bec88 --- /dev/null +++ b/packages/utils/tests/fixtures/import.js @@ -0,0 +1,9 @@ +// testing the new ES6 dynamic import feature +const { join } = require('path') + +import(join(__dirname, 'es6-fn.js')) + .then(fn => { + console.info(typeof fn) + console.info(fn.toString()) + console.info(fn) + }) -- Gitee From 18c08d38b85f14e684bd4aea181312b856086fc2 Mon Sep 17 00:00:00 2001 From: joelchu Date: Mon, 2 Sep 2019 13:19:05 +0100 Subject: [PATCH 12/17] finalize on porting code from jsonql-params-validators to jsonql-utils --- packages/utils/index.js | 20 +++ packages/utils/package.json | 3 +- packages/utils/tests/fixtures/import.js | 2 +- .../tests/params-api.test.js | 4 +- packages/validator/index.js | 14 -- packages/validator/package.json | 3 +- packages/validator/src/params-api.js | 141 ------------------ 7 files changed, 26 insertions(+), 161 deletions(-) rename packages/{validator => utils}/tests/params-api.test.js (92%) delete mode 100644 packages/validator/src/params-api.js diff --git a/packages/utils/index.js b/packages/utils/index.js index 5b3c710f..9ba1c45e 100644 --- a/packages/utils/index.js +++ b/packages/utils/index.js @@ -1 +1,21 @@ // exportfor ES modules +// ported from jsonql-params-validator +import * as paramsApi from './src/params-api' +import { chainFns } from './src/chain-fns' + + +// exports +export { + // params-api + createQuery: paramsApi.createQuery, + createQueryStr: paramsApi.createQueryStr, + createMutation: paramsApi.createMutation, + createMutationStr: paramsApi.createMutationStr, + getQueryFromArgs: paramsApi.getQueryFromArgs, + getQueryFromPayload: paramsApi.getQueryFromPayload, + getMutationFromArgs: paramsApi.getMutationFromArgs, + getMutationFromPayload: paramsApi.getMutationFromPayload, + getNameFromPayload: paramsApi.getNameFromPayload, + // chain-fns + chainFns +} diff --git a/packages/utils/package.json b/packages/utils/package.json index 786d5fab..81c989e4 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -5,7 +5,8 @@ "main": "main.js", "module": "index.js", "scripts": { - "test": "ava" + "test": "ava", + "test:params": "DEBUG=jsonql* ava ./tests/params-api.test.js" }, "keywords": [ "jsonql", diff --git a/packages/utils/tests/fixtures/import.js b/packages/utils/tests/fixtures/import.js index 413bec88..b25adadc 100644 --- a/packages/utils/tests/fixtures/import.js +++ b/packages/utils/tests/fixtures/import.js @@ -1,6 +1,6 @@ // testing the new ES6 dynamic import feature const { join } = require('path') - +// it doens't work natively yet so screw it @2019-09-02 import(join(__dirname, 'es6-fn.js')) .then(fn => { console.info(typeof fn) diff --git a/packages/validator/tests/params-api.test.js b/packages/utils/tests/params-api.test.js similarity index 92% rename from packages/validator/tests/params-api.test.js rename to packages/utils/tests/params-api.test.js index 00399024..854fb0ac 100644 --- a/packages/validator/tests/params-api.test.js +++ b/packages/utils/tests/params-api.test.js @@ -7,9 +7,9 @@ const { getQueryFromArgs, getMutationFromArgs, getNameFromPayload -} = require('../dist/jsonql-params-validator.cjs') +} = require('../src/params-api') const { PAYLOAD_PARAM_NAME, CONDITION_PARAM_NAME, RESOLVER_PARAM_NAME } = require('jsonql-constants') -const debug = require('debug')('jsonql-params-validator:test:params-api') +const debug = require('debug')('jsonql:params-api') import { JsonqlValidationError } from 'jsonql-errors' diff --git a/packages/validator/index.js b/packages/validator/index.js index ebaac531..ffe7cf2a 100644 --- a/packages/validator/index.js +++ b/packages/validator/index.js @@ -46,17 +46,3 @@ export const isKeyInObject = checkKeyInObject; import checkIsContract from './src/check-is-contract' export const isContract = checkIsContract; - -// add in v1.3.0 - -import * as paramsApi from './src/params-api' - -export const createQuery = paramsApi.createQuery; -export const createQueryStr = paramsApi.createQueryStr; -export const createMutation = paramsApi.createMutation; -export const createMutationStr = paramsApi.createMutationStr; -export const getQueryFromArgs = paramsApi.getQueryFromArgs; -export const getQueryFromPayload = paramsApi.getQueryFromPayload; -export const getMutationFromArgs = paramsApi.getMutationFromArgs; -export const getMutationFromPayload = paramsApi.getMutationFromPayload; -export const getNameFromPayload = paramsApi.getNameFromPayload; diff --git a/packages/validator/package.json b/packages/validator/package.json index 6d58239d..b612a488 100644 --- a/packages/validator/package.json +++ b/packages/validator/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-params-validator", - "version": "1.4.4", + "version": "1.4.5", "description": "JSONQL parameters validator written in ES6+ to use with the client / server", "module": "index.js", "browser": "dist/jsonql-params-validator.umd.js", @@ -24,7 +24,6 @@ "test:check:sync": "DEBUG=jsonql-params-validator:* ava ./tests/check-options-sync.test.js", "test:check:client": "DEBUG=jsonql-params-validator:* ava ./tests/check-node-client-async.test.js", "test:config": "DEBUG=jsonql-params-validator:* ava ./tests/construct-config.test.js", - "test:params": "DEBUG=jsonql-params-validator* ava ./tests/params-api.test.js", "test:bug": "DEBUG=jsonql-params-validator* ava ./tests/ws-check-options.test.js", "debug": "inspect node_modules/ava/profile.js ./tests/combine.test.js", "try": "DEBUG=jsonql-params-validator:* node ./tests/fixtures/try.js", diff --git a/packages/validator/src/params-api.js b/packages/validator/src/params-api.js deleted file mode 100644 index a5f7bfea..00000000 --- a/packages/validator/src/params-api.js +++ /dev/null @@ -1,141 +0,0 @@ -// craete several helper function to construct / extract the payload -// and make sure they are all the same -import { - PAYLOAD_PARAM_NAME, - CONDITION_PARAM_NAME, - RESOLVER_PARAM_NAME, - QUERY_ARG_NAME -} from 'jsonql-constants' -import { JsonqlValidationError } from 'jsonql-errors' - -import isString from './string' -import { checkIsArray } from './array' -import { checkIsObject } from './object' - -// make sure it's an object -const formatPayload = payload => isString(payload) ? JSON.parse(payload) : payload; - -/** - * Get name from the payload (ported back from jsonql-koa) - * @param {*} payload to extract from - * @return {string} name - */ -export function getNameFromPayload(payload) { - return Object.keys(payload)[0] -} - -/** - * @param {string} resolverName name of function - * @param {array} [args=[]] from the ...args - * @param {boolean} [jsonp = false] add v1.3.0 to koa - * @return {object} formatted argument - */ -export function createQuery(resolverName, args = [], jsonp = false) { - if (isString(resolverName) && checkIsArray(args)) { - let payload = { [QUERY_ARG_NAME]: args } - if (jsonp === true) { - return payload; - } - return { [resolverName]: payload } - } - throw new JsonqlValidationError(`[createQuery] expect resolverName to be string and args to be array!`, { resolverName, args }) -} - -// string version of the above -export function createQueryStr(resolverName, args = [], jsonp = false) { - return JSON.stringify(createQuery(resolverName, args, jsonp)) -} - -/** - * @param {string} resolverName name of function - * @param {*} payload to send - * @param {object} [condition={}] for what - * @param {boolean} [jsonp = false] add v1.3.0 to koa - * @return {object} formatted argument - */ -export function createMutation(resolverName, payload, condition = {}, jsonp = false) { - const _payload = { - [PAYLOAD_PARAM_NAME]: payload, - [CONDITION_PARAM_NAME]: condition - } - if (jsonp === true) { - return _payload; - } - if (isString(resolverName)) { - return { [resolverName]: _payload } - } - throw new JsonqlValidationError(`[createMutation] expect resolverName to be string!`, { resolverName, payload, condition }) -} - -// string version of above -export function createMutationStr(resolverName, payload, condition = {}, jsonp = false) { - return JSON.stringify(createMutation(resolverName, payload, condition, jsonp)) -} - -/** - * Further break down from method below for use else where - * @param {string} resolverName name of fn - * @param {object} payload payload - * @return {object|boolean} false on failed - */ -export function getQueryFromArgs(resolverName, payload) { - if (resolverName && checkIsObject(payload)) { - const args = payload[resolverName]; - if (args[QUERY_ARG_NAME]) { - return { - [RESOLVER_PARAM_NAME]: resolverName, - [QUERY_ARG_NAME]: args[QUERY_ARG_NAME] - } - } - } - return false; -} - -/** - * extra the payload back - * @param {*} payload from http call - * @return {object} resolverName and args - */ -export function getQueryFromPayload(payload) { - const p = formatPayload(payload); - const resolverName = getNameFromPayload(p) - const result = getQueryFromArgs(resolverName, p) - if (result !== false) { - return result; - } - throw new JsonqlValidationError('[getQueryArgs] Payload is malformed!', payload) -} - -/** - * Further break down from method below for use else where - * @param {string} resolverName name of fn - * @param {object} payload payload - * @return {object|boolean} false on failed - */ -export function getMutationFromArgs(resolverName, payload) { - if (resolverName && checkIsObject(payload)) { - const args = payload[resolverName] - if (args) { - return { - [RESOLVER_PARAM_NAME]: resolverName, - [PAYLOAD_PARAM_NAME]: args[PAYLOAD_PARAM_NAME], - [CONDITION_PARAM_NAME]: args[CONDITION_PARAM_NAME] - } - } - } - return false; -} - -/** - * @param {object} payload - * @return {object} resolverName, payload, conditon - */ -export function getMutationFromPayload(payload) { - const p = formatPayload(payload); - const resolverName = getNameFromPayload(p) - const result = getMutationFromArgs(resolverName, p) - if (result !== false) { - return result; - } - throw new JsonqlValidationError('[getMutationArgs] Payload is malformed!', payload) -} -- Gitee From 83896f5746db4989edcaf48321fd5e5f55c3a575 Mon Sep 17 00:00:00 2001 From: joelchu Date: Mon, 2 Sep 2019 13:35:26 +0100 Subject: [PATCH 13/17] moving the params-api back to jsonql-params-validator due to its dependencies on the validator and I dont want to introduce a circlar dependencies problem --- packages/utils/index.js | 12 +- packages/validator/index.js | 13 ++ packages/validator/src/params-api.js | 142 ++++++++++++++++++ .../tests/params-api.test.js | 2 +- 4 files changed, 157 insertions(+), 12 deletions(-) create mode 100644 packages/validator/src/params-api.js rename packages/{utils => validator}/tests/params-api.test.js (97%) diff --git a/packages/utils/index.js b/packages/utils/index.js index 9ba1c45e..f4ff440b 100644 --- a/packages/utils/index.js +++ b/packages/utils/index.js @@ -1,21 +1,11 @@ // exportfor ES modules // ported from jsonql-params-validator -import * as paramsApi from './src/params-api' + import { chainFns } from './src/chain-fns' // exports export { - // params-api - createQuery: paramsApi.createQuery, - createQueryStr: paramsApi.createQueryStr, - createMutation: paramsApi.createMutation, - createMutationStr: paramsApi.createMutationStr, - getQueryFromArgs: paramsApi.getQueryFromArgs, - getQueryFromPayload: paramsApi.getQueryFromPayload, - getMutationFromArgs: paramsApi.getMutationFromArgs, - getMutationFromPayload: paramsApi.getMutationFromPayload, - getNameFromPayload: paramsApi.getNameFromPayload, // chain-fns chainFns } diff --git a/packages/validator/index.js b/packages/validator/index.js index ffe7cf2a..afc610a6 100644 --- a/packages/validator/index.js +++ b/packages/validator/index.js @@ -46,3 +46,16 @@ export const isKeyInObject = checkKeyInObject; import checkIsContract from './src/check-is-contract' export const isContract = checkIsContract; + +// from v1.3.0 +import * as paramsApi from './src/params-api' +// params-api +export const createQuery = paramsApi.createQuery; +export const createQueryStr = paramsApi.createQueryStr; +export const createMutation = paramsApi.createMutation; +export const createMutationStr = paramsApi.createMutationStr; +export const getQueryFromArgs = paramsApi.getQueryFromArgs; +export const getQueryFromPayload = paramsApi.getQueryFromPayload; +export const getMutationFromArgs = paramsApi.getMutationFromArgs; +export const getMutationFromPayload = paramsApi.getMutationFromPayload; +export const getNameFromPayload = paramsApi.getNameFromPayload; diff --git a/packages/validator/src/params-api.js b/packages/validator/src/params-api.js new file mode 100644 index 00000000..64758db4 --- /dev/null +++ b/packages/validator/src/params-api.js @@ -0,0 +1,142 @@ +// ported from jsonql-params-validator +// craete several helper function to construct / extract the payload +// and make sure they are all the same +import { + PAYLOAD_PARAM_NAME, + CONDITION_PARAM_NAME, + RESOLVER_PARAM_NAME, + QUERY_ARG_NAME +} from 'jsonql-constants' +import { JsonqlValidationError } from 'jsonql-errors' + +import isString from './string' +import { checkIsArray } from './array' +import { checkIsObject } from './object' + +// make sure it's an object +const formatPayload = payload => isString(payload) ? JSON.parse(payload) : payload; + +/** + * Get name from the payload (ported back from jsonql-koa) + * @param {*} payload to extract from + * @return {string} name + */ +export function getNameFromPayload(payload) { + return Object.keys(payload)[0] +} + +/** + * @param {string} resolverName name of function + * @param {array} [args=[]] from the ...args + * @param {boolean} [jsonp = false] add v1.3.0 to koa + * @return {object} formatted argument + */ +export function createQuery(resolverName, args = [], jsonp = false) { + if (isString(resolverName) && checkIsArray(args)) { + let payload = { [QUERY_ARG_NAME]: args } + if (jsonp === true) { + return payload; + } + return { [resolverName]: payload } + } + throw new JsonqlValidationError(`[createQuery] expect resolverName to be string and args to be array!`, { resolverName, args }) +} + +// string version of the above +export function createQueryStr(resolverName, args = [], jsonp = false) { + return JSON.stringify(createQuery(resolverName, args, jsonp)) +} + +/** + * @param {string} resolverName name of function + * @param {*} payload to send + * @param {object} [condition={}] for what + * @param {boolean} [jsonp = false] add v1.3.0 to koa + * @return {object} formatted argument + */ +export function createMutation(resolverName, payload, condition = {}, jsonp = false) { + const _payload = { + [PAYLOAD_PARAM_NAME]: payload, + [CONDITION_PARAM_NAME]: condition + } + if (jsonp === true) { + return _payload; + } + if (isString(resolverName)) { + return { [resolverName]: _payload } + } + throw new JsonqlValidationError(`[createMutation] expect resolverName to be string!`, { resolverName, payload, condition }) +} + +// string version of above +export function createMutationStr(resolverName, payload, condition = {}, jsonp = false) { + return JSON.stringify(createMutation(resolverName, payload, condition, jsonp)) +} + +/** + * Further break down from method below for use else where + * @param {string} resolverName name of fn + * @param {object} payload payload + * @return {object|boolean} false on failed + */ +export function getQueryFromArgs(resolverName, payload) { + if (resolverName && checkIsObject(payload)) { + const args = payload[resolverName]; + if (args[QUERY_ARG_NAME]) { + return { + [RESOLVER_PARAM_NAME]: resolverName, + [QUERY_ARG_NAME]: args[QUERY_ARG_NAME] + } + } + } + return false; +} + +/** + * extra the payload back + * @param {*} payload from http call + * @return {object} resolverName and args + */ +export function getQueryFromPayload(payload) { + const p = formatPayload(payload); + const resolverName = getNameFromPayload(p) + const result = getQueryFromArgs(resolverName, p) + if (result !== false) { + return result; + } + throw new JsonqlValidationError('[getQueryArgs] Payload is malformed!', payload) +} + +/** + * Further break down from method below for use else where + * @param {string} resolverName name of fn + * @param {object} payload payload + * @return {object|boolean} false on failed + */ +export function getMutationFromArgs(resolverName, payload) { + if (resolverName && checkIsObject(payload)) { + const args = payload[resolverName] + if (args) { + return { + [RESOLVER_PARAM_NAME]: resolverName, + [PAYLOAD_PARAM_NAME]: args[PAYLOAD_PARAM_NAME], + [CONDITION_PARAM_NAME]: args[CONDITION_PARAM_NAME] + } + } + } + return false; +} + +/** + * @param {object} payload + * @return {object} resolverName, payload, conditon + */ +export function getMutationFromPayload(payload) { + const p = formatPayload(payload); + const resolverName = getNameFromPayload(p) + const result = getMutationFromArgs(resolverName, p) + if (result !== false) { + return result; + } + throw new JsonqlValidationError('[getMutationArgs] Payload is malformed!', payload) +} diff --git a/packages/utils/tests/params-api.test.js b/packages/validator/tests/params-api.test.js similarity index 97% rename from packages/utils/tests/params-api.test.js rename to packages/validator/tests/params-api.test.js index 854fb0ac..110dde0f 100644 --- a/packages/utils/tests/params-api.test.js +++ b/packages/validator/tests/params-api.test.js @@ -7,7 +7,7 @@ const { getQueryFromArgs, getMutationFromArgs, getNameFromPayload -} = require('../src/params-api') +} = require('../dist/jsonql-params-validator.cjs') const { PAYLOAD_PARAM_NAME, CONDITION_PARAM_NAME, RESOLVER_PARAM_NAME } = require('jsonql-constants') const debug = require('debug')('jsonql:params-api') import { JsonqlValidationError } from 'jsonql-errors' -- Gitee From b7f711fefa7a691c11d68c32bc24b3f9dfe31ee8 Mon Sep 17 00:00:00 2001 From: joelchu Date: Mon, 2 Sep 2019 13:53:47 +0100 Subject: [PATCH 14/17] start moving code over from the jwt --- packages/{ => @jsonql}/express/package.json | 0 packages/contract-console-ts/.gitignore | 21 - packages/contract-console-ts/README.md | 34 - packages/contract-console-ts/babel.config.js | 5 - packages/contract-console-ts/output.js | 1209 ----------------- packages/contract-console-ts/package.json | 61 - .../contract-console-ts/public/favicon.ico | Bin 4286 -> 0 bytes .../contract-console-ts/public/index.html | 21 - packages/contract-console-ts/src/App.vue | 29 - .../contract-console-ts/src/assets/logo.png | Bin 6849 -> 0 bytes .../src/components/HelloWorld.vue | 59 - packages/contract-console-ts/src/main.ts | 11 - .../contract-console-ts/src/plugin/client.ts | 14 - .../contract-console-ts/src/plugin/jsonql.ts | 10 - .../src/plugin/public-contract.json | 62 - .../contract-console-ts/src/shims-tsx.d.ts | 13 - .../contract-console-ts/src/shims-vue.d.ts | 4 - packages/contract-console-ts/src/store.ts | 18 - .../tests/fixtures/contract/contract.json | 55 - .../fixtures/contract/public-contract.json | 62 - .../tests/fixtures/resolvers/import.js | 2 - .../resolvers/mutation/default-save.js | 10 - .../fixtures/resolvers/query/default-call.js | 10 - .../tests/fixtures/resolvers/resolver.js | 7 - .../tests/fixtures/server.js | 21 - .../tests/jsonql-client.d.ts | 6 - .../tests/unit/example.spec.ts | 13 - packages/contract-console-ts/tsconfig.json | 42 - packages/contract-console-ts/tslint.json | 19 - packages/contract-console-ts/vue.config.js | 20 - packages/utils/index.js | 5 +- packages/utils/src/chain-fns.js | 17 + packages/validator/package.json | 2 +- 33 files changed, 21 insertions(+), 1841 deletions(-) rename packages/{ => @jsonql}/express/package.json (100%) delete mode 100644 packages/contract-console-ts/.gitignore delete mode 100644 packages/contract-console-ts/README.md delete mode 100644 packages/contract-console-ts/babel.config.js delete mode 100644 packages/contract-console-ts/output.js delete mode 100644 packages/contract-console-ts/package.json delete mode 100644 packages/contract-console-ts/public/favicon.ico delete mode 100644 packages/contract-console-ts/public/index.html delete mode 100644 packages/contract-console-ts/src/App.vue delete mode 100644 packages/contract-console-ts/src/assets/logo.png delete mode 100644 packages/contract-console-ts/src/components/HelloWorld.vue delete mode 100644 packages/contract-console-ts/src/main.ts delete mode 100644 packages/contract-console-ts/src/plugin/client.ts delete mode 100644 packages/contract-console-ts/src/plugin/jsonql.ts delete mode 100644 packages/contract-console-ts/src/plugin/public-contract.json delete mode 100644 packages/contract-console-ts/src/shims-tsx.d.ts delete mode 100644 packages/contract-console-ts/src/shims-vue.d.ts delete mode 100644 packages/contract-console-ts/src/store.ts delete mode 100644 packages/contract-console-ts/tests/fixtures/contract/contract.json delete mode 100644 packages/contract-console-ts/tests/fixtures/contract/public-contract.json delete mode 100644 packages/contract-console-ts/tests/fixtures/resolvers/import.js delete mode 100644 packages/contract-console-ts/tests/fixtures/resolvers/mutation/default-save.js delete mode 100644 packages/contract-console-ts/tests/fixtures/resolvers/query/default-call.js delete mode 100644 packages/contract-console-ts/tests/fixtures/resolvers/resolver.js delete mode 100644 packages/contract-console-ts/tests/fixtures/server.js delete mode 100644 packages/contract-console-ts/tests/jsonql-client.d.ts delete mode 100644 packages/contract-console-ts/tests/unit/example.spec.ts delete mode 100644 packages/contract-console-ts/tsconfig.json delete mode 100644 packages/contract-console-ts/tslint.json delete mode 100644 packages/contract-console-ts/vue.config.js diff --git a/packages/express/package.json b/packages/@jsonql/express/package.json similarity index 100% rename from packages/express/package.json rename to packages/@jsonql/express/package.json diff --git a/packages/contract-console-ts/.gitignore b/packages/contract-console-ts/.gitignore deleted file mode 100644 index a0dddc6f..00000000 --- a/packages/contract-console-ts/.gitignore +++ /dev/null @@ -1,21 +0,0 @@ -.DS_Store -node_modules -/dist - -# local env files -.env.local -.env.*.local - -# Log files -npm-debug.log* -yarn-debug.log* -yarn-error.log* - -# Editor directories and files -.idea -.vscode -*.suo -*.ntvs* -*.njsproj -*.sln -*.sw? diff --git a/packages/contract-console-ts/README.md b/packages/contract-console-ts/README.md deleted file mode 100644 index ab6fc40a..00000000 --- a/packages/contract-console-ts/README.md +++ /dev/null @@ -1,34 +0,0 @@ -# contract-console - -## Project setup -``` -npm install -``` - -### Compiles and hot-reloads for development -``` -npm run serve -``` - -### Compiles and minifies for production -``` -npm run build -``` - -### Run your tests -``` -npm run test -``` - -### Lints and fixes files -``` -npm run lint -``` - -### Run your unit tests -``` -npm run test:unit -``` - -### Customize configuration -See [Configuration Reference](https://cli.vuejs.org/config/). diff --git a/packages/contract-console-ts/babel.config.js b/packages/contract-console-ts/babel.config.js deleted file mode 100644 index ba179669..00000000 --- a/packages/contract-console-ts/babel.config.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - presets: [ - '@vue/app' - ] -} diff --git a/packages/contract-console-ts/output.js b/packages/contract-console-ts/output.js deleted file mode 100644 index afc573d8..00000000 --- a/packages/contract-console-ts/output.js +++ /dev/null @@ -1,1209 +0,0 @@ -{ - mode: 'development', - context: '/home/joel/projects/open-source/jsonql/packages/contract-console', - devtool: 'cheap-module-eval-source-map', - node: { - setImmediate: false, - dgram: 'empty', - fs: 'empty', - net: 'empty', - tls: 'empty', - child_process: 'empty' - }, - output: { - path: '/home/joel/projects/open-source/jsonql/packages/contract-console/dist', - filename: '[name].js', - publicPath: '/', - globalObject: '(typeof self !== \'undefined\' ? self : this)' - }, - resolve: { - alias: { - '@': '/home/joel/projects/open-source/jsonql/packages/contract-console/src', - vue$: 'vue/dist/vue.runtime.esm.js' - }, - extensions: [ - '.mjs', - '.js', - '.jsx', - '.vue', - '.json', - '.wasm', - '.ts', - '.tsx' - ], - modules: [ - 'node_modules', - '/home/joel/projects/open-source/jsonql/packages/contract-console/node_modules', - '/home/joel/projects/open-source/jsonql/packages/contract-console/node_modules/@vue/cli-service/node_modules' - ] - }, - resolveLoader: { - modules: [ - '/home/joel/projects/open-source/jsonql/packages/contract-console/node_modules/@vue/cli-plugin-typescript/node_modules', - '/home/joel/projects/open-source/jsonql/packages/contract-console/node_modules/@vue/cli-plugin-babel/node_modules', - 'node_modules', - '/home/joel/projects/open-source/jsonql/packages/contract-console/node_modules', - '/home/joel/projects/open-source/jsonql/packages/contract-console/node_modules/@vue/cli-service/node_modules' - ] - }, - module: { - noParse: /^(vue|vue-router|vuex|vuex-router-sync)$/, - rules: [ - /* config.module.rule('vue') */ - { - test: /\.vue$/, - use: [ - /* config.module.rule('vue').use('cache-loader') */ - { - loader: 'cache-loader', - options: { - cacheDirectory: '/home/joel/projects/open-source/jsonql/packages/contract-console/node_modules/.cache/vue-loader', - cacheIdentifier: '1255578f' - } - }, - /* config.module.rule('vue').use('vue-loader') */ - { - loader: 'vue-loader', - options: { - compilerOptions: { - preserveWhitespace: false - }, - cacheDirectory: '/home/joel/projects/open-source/jsonql/packages/contract-console/node_modules/.cache/vue-loader', - cacheIdentifier: '1255578f' - } - } - ] - }, - /* config.module.rule('images') */ - { - test: /\.(png|jpe?g|gif|webp)(\?.*)?$/, - use: [ - /* config.module.rule('images').use('url-loader') */ - { - loader: 'url-loader', - options: { - limit: 4096, - fallback: { - loader: 'file-loader', - options: { - name: 'img/[name].[hash:8].[ext]' - } - } - } - } - ] - }, - /* config.module.rule('svg') */ - { - test: /\.(svg)(\?.*)?$/, - use: [ - /* config.module.rule('svg').use('file-loader') */ - { - loader: 'file-loader', - options: { - name: 'img/[name].[hash:8].[ext]' - } - } - ] - }, - /* config.module.rule('media') */ - { - test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, - use: [ - /* config.module.rule('media').use('url-loader') */ - { - loader: 'url-loader', - options: { - limit: 4096, - fallback: { - loader: 'file-loader', - options: { - name: 'media/[name].[hash:8].[ext]' - } - } - } - } - ] - }, - /* config.module.rule('fonts') */ - { - test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/i, - use: [ - /* config.module.rule('fonts').use('url-loader') */ - { - loader: 'url-loader', - options: { - limit: 4096, - fallback: { - loader: 'file-loader', - options: { - name: 'fonts/[name].[hash:8].[ext]' - } - } - } - } - ] - }, - /* config.module.rule('pug') */ - { - test: /\.pug$/, - oneOf: [ - /* config.module.rule('pug').oneOf('pug-vue') */ - { - resourceQuery: /vue/, - use: [ - /* config.module.rule('pug').oneOf('pug-vue').use('pug-plain-loader') */ - { - loader: 'pug-plain-loader' - } - ] - }, - /* config.module.rule('pug').oneOf('pug-template') */ - { - use: [ - /* config.module.rule('pug').oneOf('pug-template').use('raw') */ - { - loader: 'raw-loader' - }, - /* config.module.rule('pug').oneOf('pug-template').use('pug-plain') */ - { - loader: 'pug-plain-loader' - } - ] - } - ] - }, - /* config.module.rule('css') */ - { - test: /\.css$/, - oneOf: [ - /* config.module.rule('css').oneOf('vue-modules') */ - { - resourceQuery: /module/, - use: [ - /* config.module.rule('css').oneOf('vue-modules').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('css').oneOf('vue-modules').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2, - modules: true, - localIdentName: '[name]_[local]_[hash:base64:5]' - } - }, - /* config.module.rule('css').oneOf('vue-modules').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - } - ] - }, - /* config.module.rule('css').oneOf('vue') */ - { - resourceQuery: /\?vue/, - use: [ - /* config.module.rule('css').oneOf('vue').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('css').oneOf('vue').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2 - } - }, - /* config.module.rule('css').oneOf('vue').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - } - ] - }, - /* config.module.rule('css').oneOf('normal-modules') */ - { - test: /\.module\.\w+$/, - use: [ - /* config.module.rule('css').oneOf('normal-modules').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('css').oneOf('normal-modules').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2, - modules: true, - localIdentName: '[name]_[local]_[hash:base64:5]' - } - }, - /* config.module.rule('css').oneOf('normal-modules').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - } - ] - }, - /* config.module.rule('css').oneOf('normal') */ - { - use: [ - /* config.module.rule('css').oneOf('normal').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('css').oneOf('normal').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2 - } - }, - /* config.module.rule('css').oneOf('normal').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - } - ] - } - ] - }, - /* config.module.rule('postcss') */ - { - test: /\.p(ost)?css$/, - oneOf: [ - /* config.module.rule('postcss').oneOf('vue-modules') */ - { - resourceQuery: /module/, - use: [ - /* config.module.rule('postcss').oneOf('vue-modules').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('postcss').oneOf('vue-modules').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2, - modules: true, - localIdentName: '[name]_[local]_[hash:base64:5]' - } - }, - /* config.module.rule('postcss').oneOf('vue-modules').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - } - ] - }, - /* config.module.rule('postcss').oneOf('vue') */ - { - resourceQuery: /\?vue/, - use: [ - /* config.module.rule('postcss').oneOf('vue').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('postcss').oneOf('vue').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2 - } - }, - /* config.module.rule('postcss').oneOf('vue').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - } - ] - }, - /* config.module.rule('postcss').oneOf('normal-modules') */ - { - test: /\.module\.\w+$/, - use: [ - /* config.module.rule('postcss').oneOf('normal-modules').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('postcss').oneOf('normal-modules').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2, - modules: true, - localIdentName: '[name]_[local]_[hash:base64:5]' - } - }, - /* config.module.rule('postcss').oneOf('normal-modules').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - } - ] - }, - /* config.module.rule('postcss').oneOf('normal') */ - { - use: [ - /* config.module.rule('postcss').oneOf('normal').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('postcss').oneOf('normal').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2 - } - }, - /* config.module.rule('postcss').oneOf('normal').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - } - ] - } - ] - }, - /* config.module.rule('scss') */ - { - test: /\.scss$/, - oneOf: [ - /* config.module.rule('scss').oneOf('vue-modules') */ - { - resourceQuery: /module/, - use: [ - /* config.module.rule('scss').oneOf('vue-modules').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('scss').oneOf('vue-modules').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2, - modules: true, - localIdentName: '[name]_[local]_[hash:base64:5]' - } - }, - /* config.module.rule('scss').oneOf('vue-modules').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - }, - /* config.module.rule('scss').oneOf('vue-modules').use('sass-loader') */ - { - loader: 'sass-loader', - options: { - sourceMap: false - } - } - ] - }, - /* config.module.rule('scss').oneOf('vue') */ - { - resourceQuery: /\?vue/, - use: [ - /* config.module.rule('scss').oneOf('vue').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('scss').oneOf('vue').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2 - } - }, - /* config.module.rule('scss').oneOf('vue').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - }, - /* config.module.rule('scss').oneOf('vue').use('sass-loader') */ - { - loader: 'sass-loader', - options: { - sourceMap: false - } - } - ] - }, - /* config.module.rule('scss').oneOf('normal-modules') */ - { - test: /\.module\.\w+$/, - use: [ - /* config.module.rule('scss').oneOf('normal-modules').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('scss').oneOf('normal-modules').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2, - modules: true, - localIdentName: '[name]_[local]_[hash:base64:5]' - } - }, - /* config.module.rule('scss').oneOf('normal-modules').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - }, - /* config.module.rule('scss').oneOf('normal-modules').use('sass-loader') */ - { - loader: 'sass-loader', - options: { - sourceMap: false - } - } - ] - }, - /* config.module.rule('scss').oneOf('normal') */ - { - use: [ - /* config.module.rule('scss').oneOf('normal').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('scss').oneOf('normal').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2 - } - }, - /* config.module.rule('scss').oneOf('normal').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - }, - /* config.module.rule('scss').oneOf('normal').use('sass-loader') */ - { - loader: 'sass-loader', - options: { - sourceMap: false - } - } - ] - } - ] - }, - /* config.module.rule('sass') */ - { - test: /\.sass$/, - oneOf: [ - /* config.module.rule('sass').oneOf('vue-modules') */ - { - resourceQuery: /module/, - use: [ - /* config.module.rule('sass').oneOf('vue-modules').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('sass').oneOf('vue-modules').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2, - modules: true, - localIdentName: '[name]_[local]_[hash:base64:5]' - } - }, - /* config.module.rule('sass').oneOf('vue-modules').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - }, - /* config.module.rule('sass').oneOf('vue-modules').use('sass-loader') */ - { - loader: 'sass-loader', - options: { - sourceMap: false, - indentedSyntax: true - } - } - ] - }, - /* config.module.rule('sass').oneOf('vue') */ - { - resourceQuery: /\?vue/, - use: [ - /* config.module.rule('sass').oneOf('vue').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('sass').oneOf('vue').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2 - } - }, - /* config.module.rule('sass').oneOf('vue').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - }, - /* config.module.rule('sass').oneOf('vue').use('sass-loader') */ - { - loader: 'sass-loader', - options: { - sourceMap: false, - indentedSyntax: true - } - } - ] - }, - /* config.module.rule('sass').oneOf('normal-modules') */ - { - test: /\.module\.\w+$/, - use: [ - /* config.module.rule('sass').oneOf('normal-modules').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('sass').oneOf('normal-modules').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2, - modules: true, - localIdentName: '[name]_[local]_[hash:base64:5]' - } - }, - /* config.module.rule('sass').oneOf('normal-modules').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - }, - /* config.module.rule('sass').oneOf('normal-modules').use('sass-loader') */ - { - loader: 'sass-loader', - options: { - sourceMap: false, - indentedSyntax: true - } - } - ] - }, - /* config.module.rule('sass').oneOf('normal') */ - { - use: [ - /* config.module.rule('sass').oneOf('normal').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('sass').oneOf('normal').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2 - } - }, - /* config.module.rule('sass').oneOf('normal').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - }, - /* config.module.rule('sass').oneOf('normal').use('sass-loader') */ - { - loader: 'sass-loader', - options: { - sourceMap: false, - indentedSyntax: true - } - } - ] - } - ] - }, - /* config.module.rule('less') */ - { - test: /\.less$/, - oneOf: [ - /* config.module.rule('less').oneOf('vue-modules') */ - { - resourceQuery: /module/, - use: [ - /* config.module.rule('less').oneOf('vue-modules').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('less').oneOf('vue-modules').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2, - modules: true, - localIdentName: '[name]_[local]_[hash:base64:5]' - } - }, - /* config.module.rule('less').oneOf('vue-modules').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - }, - /* config.module.rule('less').oneOf('vue-modules').use('less-loader') */ - { - loader: 'less-loader', - options: { - sourceMap: false - } - } - ] - }, - /* config.module.rule('less').oneOf('vue') */ - { - resourceQuery: /\?vue/, - use: [ - /* config.module.rule('less').oneOf('vue').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('less').oneOf('vue').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2 - } - }, - /* config.module.rule('less').oneOf('vue').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - }, - /* config.module.rule('less').oneOf('vue').use('less-loader') */ - { - loader: 'less-loader', - options: { - sourceMap: false - } - } - ] - }, - /* config.module.rule('less').oneOf('normal-modules') */ - { - test: /\.module\.\w+$/, - use: [ - /* config.module.rule('less').oneOf('normal-modules').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('less').oneOf('normal-modules').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2, - modules: true, - localIdentName: '[name]_[local]_[hash:base64:5]' - } - }, - /* config.module.rule('less').oneOf('normal-modules').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - }, - /* config.module.rule('less').oneOf('normal-modules').use('less-loader') */ - { - loader: 'less-loader', - options: { - sourceMap: false - } - } - ] - }, - /* config.module.rule('less').oneOf('normal') */ - { - use: [ - /* config.module.rule('less').oneOf('normal').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('less').oneOf('normal').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2 - } - }, - /* config.module.rule('less').oneOf('normal').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - }, - /* config.module.rule('less').oneOf('normal').use('less-loader') */ - { - loader: 'less-loader', - options: { - sourceMap: false - } - } - ] - } - ] - }, - /* config.module.rule('stylus') */ - { - test: /\.styl(us)?$/, - oneOf: [ - /* config.module.rule('stylus').oneOf('vue-modules') */ - { - resourceQuery: /module/, - use: [ - /* config.module.rule('stylus').oneOf('vue-modules').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('stylus').oneOf('vue-modules').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2, - modules: true, - localIdentName: '[name]_[local]_[hash:base64:5]' - } - }, - /* config.module.rule('stylus').oneOf('vue-modules').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - }, - /* config.module.rule('stylus').oneOf('vue-modules').use('stylus-loader') */ - { - loader: 'stylus-loader', - options: { - sourceMap: false, - preferPathResolver: 'webpack' - } - } - ] - }, - /* config.module.rule('stylus').oneOf('vue') */ - { - resourceQuery: /\?vue/, - use: [ - /* config.module.rule('stylus').oneOf('vue').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('stylus').oneOf('vue').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2 - } - }, - /* config.module.rule('stylus').oneOf('vue').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - }, - /* config.module.rule('stylus').oneOf('vue').use('stylus-loader') */ - { - loader: 'stylus-loader', - options: { - sourceMap: false, - preferPathResolver: 'webpack' - } - } - ] - }, - /* config.module.rule('stylus').oneOf('normal-modules') */ - { - test: /\.module\.\w+$/, - use: [ - /* config.module.rule('stylus').oneOf('normal-modules').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('stylus').oneOf('normal-modules').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2, - modules: true, - localIdentName: '[name]_[local]_[hash:base64:5]' - } - }, - /* config.module.rule('stylus').oneOf('normal-modules').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - }, - /* config.module.rule('stylus').oneOf('normal-modules').use('stylus-loader') */ - { - loader: 'stylus-loader', - options: { - sourceMap: false, - preferPathResolver: 'webpack' - } - } - ] - }, - /* config.module.rule('stylus').oneOf('normal') */ - { - use: [ - /* config.module.rule('stylus').oneOf('normal').use('vue-style-loader') */ - { - loader: 'vue-style-loader', - options: { - sourceMap: false, - shadowMode: false - } - }, - /* config.module.rule('stylus').oneOf('normal').use('css-loader') */ - { - loader: 'css-loader', - options: { - sourceMap: false, - importLoaders: 2 - } - }, - /* config.module.rule('stylus').oneOf('normal').use('postcss-loader') */ - { - loader: 'postcss-loader', - options: { - sourceMap: false - } - }, - /* config.module.rule('stylus').oneOf('normal').use('stylus-loader') */ - { - loader: 'stylus-loader', - options: { - sourceMap: false, - preferPathResolver: 'webpack' - } - } - ] - } - ] - }, - /* config.module.rule('js') */ - { - test: /\.m?jsx?$/, - exclude: [ - function () { /* omitted long function */ } - ], - use: [ - /* config.module.rule('js').use('cache-loader') */ - { - loader: 'cache-loader', - options: { - cacheDirectory: '/home/joel/projects/open-source/jsonql/packages/contract-console/node_modules/.cache/babel-loader', - cacheIdentifier: '2835135d' - } - }, - /* config.module.rule('js').use('babel-loader') */ - { - loader: 'babel-loader' - } - ] - }, - /* config.module.rule('ts') */ - { - test: /\.ts$/, - use: [ - /* config.module.rule('ts').use('cache-loader') */ - { - loader: 'cache-loader', - options: { - cacheDirectory: '/home/joel/projects/open-source/jsonql/packages/contract-console/node_modules/.cache/ts-loader', - cacheIdentifier: '79086cb7' - } - }, - /* config.module.rule('ts').use('babel-loader') */ - { - loader: 'babel-loader' - }, - /* config.module.rule('ts').use('ts-loader') */ - { - loader: 'ts-loader', - options: { - transpileOnly: true, - appendTsSuffixTo: [ - '\\.vue$' - ], - happyPackMode: false - } - } - ] - }, - /* config.module.rule('tsx') */ - { - test: /\.tsx$/, - use: [ - /* config.module.rule('tsx').use('cache-loader') */ - { - loader: 'cache-loader', - options: { - cacheDirectory: '/home/joel/projects/open-source/jsonql/packages/contract-console/node_modules/.cache/ts-loader', - cacheIdentifier: '79086cb7' - } - }, - /* config.module.rule('tsx').use('babel-loader') */ - { - loader: 'babel-loader' - }, - /* config.module.rule('tsx').use('ts-loader') */ - { - loader: 'ts-loader', - options: { - transpileOnly: true, - happyPackMode: false, - appendTsxSuffixTo: [ - '\\.vue$' - ] - } - } - ] - } - ] - }, - plugins: [ - /* config.plugin('vue-loader') */ - new VueLoaderPlugin(), - /* config.plugin('define') */ - new DefinePlugin( - { - 'process.env': { - NODE_ENV: '"development"', - BASE_URL: '"/"' - } - } - ), - /* config.plugin('case-sensitive-paths') */ - new CaseSensitivePathsPlugin(), - /* config.plugin('friendly-errors') */ - new FriendlyErrorsWebpackPlugin( - { - additionalTransformers: [ - function () { /* omitted long function */ } - ], - additionalFormatters: [ - function () { /* omitted long function */ } - ] - } - ), - /* config.plugin('hmr') */ - new HotModuleReplacementPlugin(), - /* config.plugin('progress') */ - new ProgressPlugin(), - /* config.plugin('html') */ - new HtmlWebpackPlugin( - { - templateParameters: function () { /* omitted long function */ }, - template: '/home/joel/projects/open-source/jsonql/packages/contract-console/public/index.html' - } - ), - /* config.plugin('preload') */ - new PreloadPlugin( - { - rel: 'preload', - include: 'initial', - fileBlacklist: [ - /\.map$/, - /hot-update\.js$/ - ] - } - ), - /* config.plugin('prefetch') */ - new PreloadPlugin( - { - rel: 'prefetch', - include: 'asyncChunks' - } - ), - /* config.plugin('copy') */ - new CopyWebpackPlugin( - [ - { - from: '/home/joel/projects/open-source/jsonql/packages/contract-console/public', - to: '/home/joel/projects/open-source/jsonql/packages/contract-console/dist', - toType: 'dir', - ignore: [ - '.DS_Store' - ] - } - ] - ), - /* config.plugin('fork-ts-checker') */ - new ForkTsCheckerWebpackPlugin( - { - vue: true, - tslint: false, - formatter: 'codeframe', - checkSyntacticErrors: false - } - ) - ], - entry: { - app: [ - './src/main.ts' - ] - } -} diff --git a/packages/contract-console-ts/package.json b/packages/contract-console-ts/package.json deleted file mode 100644 index 8258587e..00000000 --- a/packages/contract-console-ts/package.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "name": "contract-console", - "version": "0.1.0", - "private": true, - "scripts": { - "serve": "vue-cli-service serve", - "build": "vue-cli-service build", - "lint": "vue-cli-service lint", - "test:unit": "vue-cli-service test:unit", - "be": "node ./tests/fixtures/server.js", - "dev": "npm run be & npm run serve" - }, - "dependencies": { - "@types/debug": "^4.1.4", - "core-js": "^3.1.4", - "debug": "^4.1.1", - "flyio": "^0.6.14", - "vue": "^2.6.10", - "vue-class-component": "^7.1.0", - "vue-property-decorator": "^8.2.1", - "vuex": "^3.1.1" - }, - "devDependencies": { - "@types/chai": "^4.1.7", - "@types/mocha": "^5.2.7", - "@vue/cli-plugin-babel": "^3.9.2", - "@vue/cli-plugin-typescript": "^3.9.0", - "@vue/cli-plugin-unit-mocha": "^3.9.0", - "@vue/cli-service": "^3.9.3", - "@vue/test-utils": "1.0.0-beta.29", - "chai": "^4.2.0", - "jsonql-client": "^1.2.4", - "jsonql-koa": "^1.3.4", - "lint-staged": "^9.2.1", - "server-io-core": "^1.2.0-beta.2", - "typescript": "^3.5.3", - "vue-template-compiler": "^2.6.10" - }, - "postcss": { - "plugins": { - "autoprefixer": {} - } - }, - "browserslist": [ - "> 1%", - "last 2 versions" - ], - "gitHooks": { - "pre-commit": "lint-staged" - }, - "lint-staged": { - "*.ts": [ - "vue-cli-service lint", - "git add" - ], - "*.vue": [ - "vue-cli-service lint", - "git add" - ] - } -} diff --git a/packages/contract-console-ts/public/favicon.ico b/packages/contract-console-ts/public/favicon.ico deleted file mode 100644 index df36fcfb72584e00488330b560ebcf34a41c64c2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4286 zcmds*O-Phc6o&64GDVCEQHxsW(p4>LW*W<827=Unuo8sGpRux(DN@jWP-e29Wl%wj zY84_aq9}^Am9-cWTD5GGEo#+5Fi2wX_P*bo+xO!)p*7B;iKlbFd(U~_d(U?#hLj56 zPhFkj-|A6~Qk#@g^#D^U0XT1cu=c-vu1+SElX9NR;kzAUV(q0|dl0|%h|dI$%VICy zJnu2^L*Te9JrJMGh%-P79CL0}dq92RGU6gI{v2~|)p}sG5x0U*z<8U;Ij*hB9z?ei z@g6Xq-pDoPl=MANPiR7%172VA%r)kevtV-_5H*QJKFmd;8yA$98zCxBZYXTNZ#QFk2(TX0;Y2dt&WitL#$96|gJY=3xX zpCoi|YNzgO3R`f@IiEeSmKrPSf#h#Qd<$%Ej^RIeeYfsxhPMOG`S`Pz8q``=511zm zAm)MX5AV^5xIWPyEu7u>qYs?pn$I4nL9J!=K=SGlKLXpE<5x+2cDTXq?brj?n6sp= zphe9;_JHf40^9~}9i08r{XM$7HB!`{Ys~TK0kx<}ZQng`UPvH*11|q7&l9?@FQz;8 zx!=3<4seY*%=OlbCbcae?5^V_}*K>Uo6ZWV8mTyE^B=DKy7-sdLYkR5Z?paTgK-zyIkKjIcpyO z{+uIt&YSa_$QnN_@t~L014dyK(fOOo+W*MIxbA6Ndgr=Y!f#Tokqv}n<7-9qfHkc3 z=>a|HWqcX8fzQCT=dqVbogRq!-S>H%yA{1w#2Pn;=e>JiEj7Hl;zdt-2f+j2%DeVD zsW0Ab)ZK@0cIW%W7z}H{&~yGhn~D;aiP4=;m-HCo`BEI+Kd6 z={Xwx{TKxD#iCLfl2vQGDitKtN>z|-AdCN|$jTFDg0m3O`WLD4_s#$S diff --git a/packages/contract-console-ts/public/index.html b/packages/contract-console-ts/public/index.html deleted file mode 100644 index 3780d6ee..00000000 --- a/packages/contract-console-ts/public/index.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - contract-console development - - - -
- - - diff --git a/packages/contract-console-ts/src/App.vue b/packages/contract-console-ts/src/App.vue deleted file mode 100644 index 76336168..00000000 --- a/packages/contract-console-ts/src/App.vue +++ /dev/null @@ -1,29 +0,0 @@ - - - - - diff --git a/packages/contract-console-ts/src/assets/logo.png b/packages/contract-console-ts/src/assets/logo.png deleted file mode 100644 index f3d2503fc2a44b5053b0837ebea6e87a2d339a43..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6849 zcmaKRcUV(fvo}bjDT-7nLI_nlK}sT_69H+`qzVWDA|yaU?}j417wLi^B1KB1SLsC& zL0ag7$U(XW5YR7p&Ux?sP$d4lvMt8C^+TcQu4F zQqv!UF!I+kw)c0jhd6+g6oCr9P?7)?!qX1ui*iL{p}sKCAGuJ{{W)0z1pLF|=>h}& zt(2Lr0Z`2ig8<5i%Zk}cO5Fm=LByqGWaS`oqChZdEFmc`0hSb#gg|Aap^{+WKOYcj zHjINK)KDG%&s?Mt4CL(T=?;~U@bU2x_mLKN!#GJuK_CzbNw5SMEJorG!}_5;?R>@1 zSl)jns3WlU7^J%=(hUtfmuUCU&C3%8B5C^f5>W2Cy8jW3#{Od{lF1}|?c61##3dzA zsPlFG;l_FzBK}8>|H_Ru_H#!_7$UH4UKo3lKOA}g1(R&|e@}GINYVzX?q=_WLZCgh z)L|eJMce`D0EIwgRaNETDsr+?vQknSGAi=7H00r`QnI%oQnFxm`G2umXso9l+8*&Q z7WqF|$p49js$mdzo^BXpH#gURy=UO;=IMrYc5?@+sR4y_?d*~0^YP7d+y0{}0)zBM zIKVM(DBvICK#~7N0a+PY6)7;u=dutmNqK3AlsrUU9U`d;msiucB_|8|2kY=(7XA;G zwDA8AR)VCA#JOkxm#6oHNS^YVuOU;8p$N)2{`;oF|rQ?B~K$%rHDxXs+_G zF5|-uqHZvSzq}L;5Kcy_P+x0${33}Ofb6+TX&=y;;PkEOpz%+_bCw_{<&~ zeLV|!bP%l1qxywfVr9Z9JI+++EO^x>ZuCK);=$VIG1`kxK8F2M8AdC$iOe3cj1fo(ce4l-9 z7*zKy3={MixvUk=enQE;ED~7tv%qh&3lR<0m??@w{ILF|e#QOyPkFYK!&Up7xWNtL zOW%1QMC<3o;G9_S1;NkPB6bqbCOjeztEc6TsBM<(q9((JKiH{01+Ud=uw9B@{;(JJ z-DxI2*{pMq`q1RQc;V8@gYAY44Z!%#W~M9pRxI(R?SJ7sy7em=Z5DbuDlr@*q|25V)($-f}9c#?D%dU^RS<(wz?{P zFFHtCab*!rl(~j@0(Nadvwg8q|4!}L^>d?0al6}Rrv9$0M#^&@zjbfJy_n!%mVHK4 z6pLRIQ^Uq~dnyy$`ay51Us6WaP%&O;@49m&{G3z7xV3dLtt1VTOMYl3UW~Rm{Eq4m zF?Zl_v;?7EFx1_+#WFUXxcK78IV)FO>42@cm@}2I%pVbZqQ}3;p;sDIm&knay03a^ zn$5}Q$G!@fTwD$e(x-~aWP0h+4NRz$KlnO_H2c< z(XX#lPuW_%H#Q+c&(nRyX1-IadKR-%$4FYC0fsCmL9ky3 zKpxyjd^JFR+vg2!=HWf}2Z?@Td`0EG`kU?{8zKrvtsm)|7>pPk9nu@2^z96aU2<#` z2QhvH5w&V;wER?mopu+nqu*n8p~(%QkwSs&*0eJwa zMXR05`OSFpfyRb!Y_+H@O%Y z0=K^y6B8Gcbl?SA)qMP3Z+=C(?8zL@=74R=EVnE?vY!1BQy2@q*RUgRx4yJ$k}MnL zs!?74QciNb-LcG*&o<9=DSL>1n}ZNd)w1z3-0Pd^4ED1{qd=9|!!N?xnXjM!EuylY z5=!H>&hSofh8V?Jofyd!h`xDI1fYAuV(sZwwN~{$a}MX^=+0TH*SFp$vyxmUv7C*W zv^3Gl0+eTFgBi3FVD;$nhcp)ka*4gSskYIqQ&+M}xP9yLAkWzBI^I%zR^l1e?bW_6 zIn{mo{dD=)9@V?s^fa55jh78rP*Ze<3`tRCN4*mpO$@7a^*2B*7N_|A(Ve2VB|)_o z$=#_=aBkhe(ifX}MLT()@5?OV+~7cXC3r!%{QJxriXo9I%*3q4KT4Xxzyd{ z9;_%=W%q!Vw$Z7F3lUnY+1HZ*lO;4;VR2+i4+D(m#01OYq|L_fbnT;KN<^dkkCwtd zF7n+O7KvAw8c`JUh6LmeIrk4`F3o|AagKSMK3))_5Cv~y2Bb2!Ibg9BO7Vkz?pAYX zoI=B}+$R22&IL`NCYUYjrdhwjnMx_v=-Qcx-jmtN>!Zqf|n1^SWrHy zK|MwJ?Z#^>)rfT5YSY{qjZ&`Fjd;^vv&gF-Yj6$9-Dy$<6zeP4s+78gS2|t%Z309b z0^fp~ue_}i`U9j!<|qF92_3oB09NqgAoehQ`)<)dSfKoJl_A6Ec#*Mx9Cpd-p#$Ez z={AM*r-bQs6*z$!*VA4|QE7bf@-4vb?Q+pPKLkY2{yKsw{&udv_2v8{Dbd zm~8VAv!G~s)`O3|Q6vFUV%8%+?ZSVUa(;fhPNg#vab@J*9XE4#D%)$UU-T5`fwjz! z6&gA^`OGu6aUk{l*h9eB?opVdrHK>Q@U>&JQ_2pR%}TyOXGq_6s56_`U(WoOaAb+K zXQr#6H}>a-GYs9^bGP2Y&hSP5gEtW+GVC4=wy0wQk=~%CSXj=GH6q z-T#s!BV`xZVxm{~jr_ezYRpqqIcXC=Oq`b{lu`Rt(IYr4B91hhVC?yg{ol4WUr3v9 zOAk2LG>CIECZ-WIs0$N}F#eoIUEtZudc7DPYIjzGqDLWk_A4#(LgacooD z2K4IWs@N`Bddm-{%oy}!k0^i6Yh)uJ1S*90>|bm3TOZxcV|ywHUb(+CeX-o1|LTZM zwU>dY3R&U)T(}5#Neh?-CWT~@{6Ke@sI)uSuzoah8COy)w)B)aslJmp`WUcjdia-0 zl2Y}&L~XfA`uYQboAJ1;J{XLhYjH){cObH3FDva+^8ioOQy%Z=xyjGLmWMrzfFoH; zEi3AG`_v+%)&lDJE;iJWJDI@-X9K5O)LD~j*PBe(wu+|%ar~C+LK1+-+lK=t# z+Xc+J7qp~5q=B~rD!x78)?1+KUIbYr^5rcl&tB-cTtj+e%{gpZZ4G~6r15+d|J(ky zjg@@UzMW0k9@S#W(1H{u;Nq(7llJbq;;4t$awM;l&(2s+$l!Ay9^Ge|34CVhr7|BG z?dAR83smef^frq9V(OH+a+ki#q&-7TkWfFM=5bsGbU(8mC;>QTCWL5ydz9s6k@?+V zcjiH`VI=59P-(-DWXZ~5DH>B^_H~;4$)KUhnmGo*G!Tq8^LjfUDO)lASN*=#AY_yS zqW9UX(VOCO&p@kHdUUgsBO0KhXxn1sprK5h8}+>IhX(nSXZKwlNsjk^M|RAaqmCZB zHBolOHYBas@&{PT=R+?d8pZu zUHfyucQ`(umXSW7o?HQ3H21M`ZJal+%*)SH1B1j6rxTlG3hx1IGJN^M7{$j(9V;MZ zRKybgVuxKo#XVM+?*yTy{W+XHaU5Jbt-UG33x{u(N-2wmw;zzPH&4DE103HV@ER86 z|FZEmQb|&1s5#`$4!Cm}&`^{(4V}OP$bk`}v6q6rm;P!H)W|2i^e{7lTk2W@jo_9q z*aw|U7#+g59Fv(5qI`#O-qPj#@_P>PC#I(GSp3DLv7x-dmYK=C7lPF8a)bxb=@)B1 zUZ`EqpXV2dR}B&r`uM}N(TS99ZT0UB%IN|0H%DcVO#T%L_chrgn#m6%x4KE*IMfjX zJ%4veCEqbXZ`H`F_+fELMC@wuy_ch%t*+Z+1I}wN#C+dRrf2X{1C8=yZ_%Pt6wL_~ zZ2NN-hXOT4P4n$QFO7yYHS-4wF1Xfr-meG9Pn;uK51?hfel`d38k{W)F*|gJLT2#T z<~>spMu4(mul-8Q3*pf=N4DcI)zzjqAgbE2eOT7~&f1W3VsdD44Ffe;3mJp-V@8UC z)|qnPc12o~$X-+U@L_lWqv-RtvB~%hLF($%Ew5w>^NR82qC_0FB z)=hP1-OEx?lLi#jnLzH}a;Nvr@JDO-zQWd}#k^an$Kwml;MrD&)sC5b`s0ZkVyPkb zt}-jOq^%_9>YZe7Y}PhW{a)c39G`kg(P4@kxjcYfgB4XOOcmezdUI7j-!gs7oAo2o zx(Ph{G+YZ`a%~kzK!HTAA5NXE-7vOFRr5oqY$rH>WI6SFvWmahFav!CfRMM3%8J&c z*p+%|-fNS_@QrFr(at!JY9jCg9F-%5{nb5Bo~z@Y9m&SHYV`49GAJjA5h~h4(G!Se zZmK{Bo7ivCfvl}@A-ptkFGcWXAzj3xfl{evi-OG(TaCn1FAHxRc{}B|x+Ua1D=I6M z!C^ZIvK6aS_c&(=OQDZfm>O`Nxsw{ta&yiYPA~@e#c%N>>#rq)k6Aru-qD4(D^v)y z*>Rs;YUbD1S8^D(ps6Jbj0K3wJw>L4m)0e(6Pee3Y?gy9i0^bZO?$*sv+xKV?WBlh zAp*;v6w!a8;A7sLB*g-^<$Z4L7|5jXxxP1}hQZ<55f9<^KJ>^mKlWSGaLcO0=$jem zWyZkRwe~u{{tU63DlCaS9$Y4CP4f?+wwa(&1ou)b>72ydrFvm`Rj-0`kBJgK@nd(*Eh!(NC{F-@=FnF&Y!q`7){YsLLHf0_B6aHc# z>WIuHTyJwIH{BJ4)2RtEauC7Yq7Cytc|S)4^*t8Va3HR zg=~sN^tp9re@w=GTx$;zOWMjcg-7X3Wk^N$n;&Kf1RgVG2}2L-(0o)54C509C&77i zrjSi{X*WV=%C17((N^6R4Ya*4#6s_L99RtQ>m(%#nQ#wrRC8Y%yxkH;d!MdY+Tw@r zjpSnK`;C-U{ATcgaxoEpP0Gf+tx);buOMlK=01D|J+ROu37qc*rD(w`#O=3*O*w9?biwNoq3WN1`&Wp8TvKj3C z3HR9ssH7a&Vr<6waJrU zdLg!ieYz%U^bmpn%;(V%%ugMk92&?_XX1K@mwnVSE6!&%P%Wdi7_h`CpScvspMx?N zQUR>oadnG17#hNc$pkTp+9lW+MBKHRZ~74XWUryd)4yd zj98$%XmIL4(9OnoeO5Fnyn&fpQ9b0h4e6EHHw*l68j;>(ya`g^S&y2{O8U>1*>4zR zq*WSI_2o$CHQ?x0!wl9bpx|Cm2+kFMR)oMud1%n2=qn5nE&t@Fgr#=Zv2?}wtEz^T z9rrj=?IH*qI5{G@Rn&}^Z{+TW}mQeb9=8b<_a`&Cm#n%n~ zU47MvCBsdXFB1+adOO)03+nczfWa#vwk#r{o{dF)QWya9v2nv43Zp3%Ps}($lA02*_g25t;|T{A5snSY?3A zrRQ~(Ygh_ebltHo1VCbJb*eOAr;4cnlXLvI>*$-#AVsGg6B1r7@;g^L zFlJ_th0vxO7;-opU@WAFe;<}?!2q?RBrFK5U{*ai@NLKZ^};Ul}beukveh?TQn;$%9=R+DX07m82gP$=}Uo_%&ngV`}Hyv8g{u z3SWzTGV|cwQuFIs7ZDOqO_fGf8Q`8MwL}eUp>q?4eqCmOTcwQuXtQckPy|4F1on8l zP*h>d+cH#XQf|+6c|S{7SF(Lg>bR~l(0uY?O{OEVlaxa5@e%T&xju=o1`=OD#qc16 zSvyH*my(dcp6~VqR;o(#@m44Lug@~_qw+HA=mS#Z^4reBy8iV?H~I;{LQWk3aKK8$bLRyt$g?- -
-

{{ msg }}

-

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

-

Installed CLI Plugins

- -

Essential Links

- -

Ecosystem

- -
- - - - - - diff --git a/packages/contract-console-ts/src/main.ts b/packages/contract-console-ts/src/main.ts deleted file mode 100644 index a69772e2..00000000 --- a/packages/contract-console-ts/src/main.ts +++ /dev/null @@ -1,11 +0,0 @@ - -import Vue from 'vue'; -import App from './App.vue'; -import store from './store'; - -Vue.config.productionTip = false; - -new Vue({ - store, - render: (h) => h(App), -}).$mount('#app'); diff --git a/packages/contract-console-ts/src/plugin/client.ts b/packages/contract-console-ts/src/plugin/client.ts deleted file mode 100644 index 845961f6..00000000 --- a/packages/contract-console-ts/src/plugin/client.ts +++ /dev/null @@ -1,14 +0,0 @@ - -import Fly from 'flyio/dist/npm/fly' -import jsonqlClient from 'jsonql-client' - -const createClient = async (contract: any, options: any) => await jsonqlClient( - Object.assign({ - hostname: 'http://localhost:8080', - keepContract: false, - showContractDesc: true, - contract - }, options) -) - -export default createClient diff --git a/packages/contract-console-ts/src/plugin/jsonql.ts b/packages/contract-console-ts/src/plugin/jsonql.ts deleted file mode 100644 index 30322b97..00000000 --- a/packages/contract-console-ts/src/plugin/jsonql.ts +++ /dev/null @@ -1,10 +0,0 @@ - -import contract from './public-contract.json' - -import client from './client' - -export default { - install(Vue: any, options: any = {}) { - Vue.JsonqlClient = client(contract, options) - } -} diff --git a/packages/contract-console-ts/src/plugin/public-contract.json b/packages/contract-console-ts/src/plugin/public-contract.json deleted file mode 100644 index c7808b85..00000000 --- a/packages/contract-console-ts/src/plugin/public-contract.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "query": { - "helloWorld": { - "description": "This is the stock resolver for testing purpose", - "params": [], - "returns": [ - { - "type": "string", - "description": "stock message" - } - ] - }, - "defaultCall": { - "description": false, - "params": [ - { - "type": [ - "number" - ], - "description": "a phony id", - "name": "id" - } - ], - "returns": [ - { - "type": [ - "object" - ], - "description": "an object with whatever" - } - ] - } - }, - "mutation": { - "defaultSave": { - "description": false, - "params": [ - { - "type": [ - "object" - ], - "name": "payload" - }, - { - "type": [ - "object" - ], - "name": "condition" - } - ], - "returns": [ - { - "type": [ - "boolean" - ] - } - ] - } - }, - "auth": {}, - "timestamp": 1563798679 -} diff --git a/packages/contract-console-ts/src/shims-tsx.d.ts b/packages/contract-console-ts/src/shims-tsx.d.ts deleted file mode 100644 index 3b88b582..00000000 --- a/packages/contract-console-ts/src/shims-tsx.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import Vue, { VNode } from 'vue'; - -declare global { - namespace JSX { - // tslint:disable no-empty-interface - interface Element extends VNode {} - // tslint:disable no-empty-interface - interface ElementClass extends Vue {} - interface IntrinsicElements { - [elem: string]: any; - } - } -} diff --git a/packages/contract-console-ts/src/shims-vue.d.ts b/packages/contract-console-ts/src/shims-vue.d.ts deleted file mode 100644 index 8f6f4102..00000000 --- a/packages/contract-console-ts/src/shims-vue.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -declare module '*.vue' { - import Vue from 'vue'; - export default Vue; -} diff --git a/packages/contract-console-ts/src/store.ts b/packages/contract-console-ts/src/store.ts deleted file mode 100644 index fead3eaf..00000000 --- a/packages/contract-console-ts/src/store.ts +++ /dev/null @@ -1,18 +0,0 @@ -import Vue from 'vue'; -import Vuex from 'vuex'; -import JsonqlClient from './plugin/jsonql' - -Vue.use(Vuex) -Vue.use(JsonqlClient) - -export default new Vuex.Store({ - state: { - - }, - mutations: { - - }, - actions: { - - }, -}); diff --git a/packages/contract-console-ts/tests/fixtures/contract/contract.json b/packages/contract-console-ts/tests/fixtures/contract/contract.json deleted file mode 100644 index cb069393..00000000 --- a/packages/contract-console-ts/tests/fixtures/contract/contract.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "query": { - "defaultCall": { - "file": "/home/joel/projects/open-source/jsonql/packages/contract-console/tests/fixtures/resolvers/query/default-call.js", - "description": false, - "params": [ - { - "type": [ - "number" - ], - "description": "a phony id", - "name": "id" - } - ], - "returns": [ - { - "type": [ - "object" - ], - "description": "an object with whatever" - } - ] - } - }, - "mutation": { - "defaultSave": { - "file": "/home/joel/projects/open-source/jsonql/packages/contract-console/tests/fixtures/resolvers/mutation/default-save.js", - "description": false, - "params": [ - { - "type": [ - "object" - ], - "name": "payload" - }, - { - "type": [ - "object" - ], - "name": "condition" - } - ], - "returns": [ - { - "type": [ - "boolean" - ] - } - ] - } - }, - "auth": {}, - "timestamp": 1563798679, - "sourceType": "module" -} diff --git a/packages/contract-console-ts/tests/fixtures/contract/public-contract.json b/packages/contract-console-ts/tests/fixtures/contract/public-contract.json deleted file mode 100644 index c7808b85..00000000 --- a/packages/contract-console-ts/tests/fixtures/contract/public-contract.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "query": { - "helloWorld": { - "description": "This is the stock resolver for testing purpose", - "params": [], - "returns": [ - { - "type": "string", - "description": "stock message" - } - ] - }, - "defaultCall": { - "description": false, - "params": [ - { - "type": [ - "number" - ], - "description": "a phony id", - "name": "id" - } - ], - "returns": [ - { - "type": [ - "object" - ], - "description": "an object with whatever" - } - ] - } - }, - "mutation": { - "defaultSave": { - "description": false, - "params": [ - { - "type": [ - "object" - ], - "name": "payload" - }, - { - "type": [ - "object" - ], - "name": "condition" - } - ], - "returns": [ - { - "type": [ - "boolean" - ] - } - ] - } - }, - "auth": {}, - "timestamp": 1563798679 -} diff --git a/packages/contract-console-ts/tests/fixtures/resolvers/import.js b/packages/contract-console-ts/tests/fixtures/resolvers/import.js deleted file mode 100644 index 6601f782..00000000 --- a/packages/contract-console-ts/tests/fixtures/resolvers/import.js +++ /dev/null @@ -1,2 +0,0 @@ -require = require("esm")(module/*, options*/) -module.exports = require("./resolver.js") diff --git a/packages/contract-console-ts/tests/fixtures/resolvers/mutation/default-save.js b/packages/contract-console-ts/tests/fixtures/resolvers/mutation/default-save.js deleted file mode 100644 index e307c3e9..00000000 --- a/packages/contract-console-ts/tests/fixtures/resolvers/mutation/default-save.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * @param {object} payload - * @param {object} condition - * @return {boolean} - */ -export default function defaultSave(payload, condition) { - - - return true; -} diff --git a/packages/contract-console-ts/tests/fixtures/resolvers/query/default-call.js b/packages/contract-console-ts/tests/fixtures/resolvers/query/default-call.js deleted file mode 100644 index 32c8211f..00000000 --- a/packages/contract-console-ts/tests/fixtures/resolvers/query/default-call.js +++ /dev/null @@ -1,10 +0,0 @@ - -/** - * @param {number} id a phony id - * @return {object} an object with whatever - * - */ -export default function defaultCall(id) { - - return {id: id} -} diff --git a/packages/contract-console-ts/tests/fixtures/resolvers/resolver.js b/packages/contract-console-ts/tests/fixtures/resolvers/resolver.js deleted file mode 100644 index 547fa756..00000000 --- a/packages/contract-console-ts/tests/fixtures/resolvers/resolver.js +++ /dev/null @@ -1,7 +0,0 @@ -import querydefaultCall from './query/default-call.js' -import mutationdefaultSave from './mutation/default-save.js' - -export { - querydefaultCall, -mutationdefaultSave -} \ No newline at end of file diff --git a/packages/contract-console-ts/tests/fixtures/server.js b/packages/contract-console-ts/tests/fixtures/server.js deleted file mode 100644 index 42661c55..00000000 --- a/packages/contract-console-ts/tests/fixtures/server.js +++ /dev/null @@ -1,21 +0,0 @@ -const serverIo = require('server-io-core') -const jsonqlKoa = require('jsonql-koa') -const { join } = require('path') -const baseDir = join(__dirname, '..', '..') - -serverIo({ - port: 8001, - open: false, - webroot: [ - join(baseDir, 'node_modules'), - join(baseDir, 'public') - ], - middlewares: [ - jsonqlKoa({ - jsType: 'es', - resolverDir: join(__dirname, 'resolvers'), - contractDir: join(__dirname, 'contract'), - keysDir: join(__dirname, 'keys') - }) - ] -}) diff --git a/packages/contract-console-ts/tests/jsonql-client.d.ts b/packages/contract-console-ts/tests/jsonql-client.d.ts deleted file mode 100644 index 21e38b09..00000000 --- a/packages/contract-console-ts/tests/jsonql-client.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -// create our own type for jsonql-client - -declare module "jsonql-client" { - function jsonqlApi(config: any): any; - export = jsonqlApi; -} diff --git a/packages/contract-console-ts/tests/unit/example.spec.ts b/packages/contract-console-ts/tests/unit/example.spec.ts deleted file mode 100644 index 732a277a..00000000 --- a/packages/contract-console-ts/tests/unit/example.spec.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { expect } from 'chai'; -import { shallowMount } from '@vue/test-utils'; -import HelloWorld from '@/components/HelloWorld.vue'; - -describe('HelloWorld.vue', () => { - it('renders props.msg when passed', () => { - const msg = 'new message'; - const wrapper = shallowMount(HelloWorld, { - propsData: { msg }, - }); - expect(wrapper.text()).to.include(msg); - }); -}); diff --git a/packages/contract-console-ts/tsconfig.json b/packages/contract-console-ts/tsconfig.json deleted file mode 100644 index 97771742..00000000 --- a/packages/contract-console-ts/tsconfig.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "compilerOptions": { - "target": "esnext", - "module": "esnext", - "strict": true, - "jsx": "preserve", - "importHelpers": true, - "moduleResolution": "node", - "experimentalDecorators": true, - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, - "resolveJsonModule": true, - "sourceMap": true, - "baseUrl": ".", - "types": [ - "webpack-env", - "mocha", - "chai" - ], - "paths": { - "@/*": [ - "src/*" - ] - }, - "lib": [ - "esnext", - "dom", - "dom.iterable", - "scripthost" - ] - }, - "include": [ - "src/**/*.ts", - "src/**/*.tsx", - "src/**/*.vue", - "tests/**/*.ts", - "tests/**/*.tsx" - ], - "exclude": [ - "node_modules" - ] -} diff --git a/packages/contract-console-ts/tslint.json b/packages/contract-console-ts/tslint.json deleted file mode 100644 index 2b37e401..00000000 --- a/packages/contract-console-ts/tslint.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "defaultSeverity": "warning", - "extends": [ - "tslint:recommended" - ], - "linterOptions": { - "exclude": [ - "node_modules/**" - ] - }, - "rules": { - "quotemark": [true, "single"], - "indent": [true, "spaces", 2], - "interface-name": false, - "ordered-imports": false, - "object-literal-sort-keys": false, - "no-consecutive-blank-lines": false - } -} diff --git a/packages/contract-console-ts/vue.config.js b/packages/contract-console-ts/vue.config.js deleted file mode 100644 index fdddb55b..00000000 --- a/packages/contract-console-ts/vue.config.js +++ /dev/null @@ -1,20 +0,0 @@ -// add a copy contract here -const fsx = require('fs-extra') -const { join } = require('path') -fsx.copy( - join(__dirname, 'tests', 'fixtures', 'contract', 'public-contract.json'), - join(__dirname, 'src', 'plugin', 'public-contract.json') -) - -module.exports = { - lintOnSave: false, - devServer: { - open: true, - proxy: { - '^/jsonql': { - target: "http://localhost:8001", - ws: true - } - } - } -} diff --git a/packages/utils/index.js b/packages/utils/index.js index f4ff440b..8e2ff953 100644 --- a/packages/utils/index.js +++ b/packages/utils/index.js @@ -1,11 +1,12 @@ // exportfor ES modules // ported from jsonql-params-validator -import { chainFns } from './src/chain-fns' +import { chainFns, chainPromises } from './src/chain-fns' // exports export { // chain-fns - chainFns + chainFns, + chainPromises } diff --git a/packages/utils/src/chain-fns.js b/packages/utils/src/chain-fns.js index ed0c7eee..d9ad6c9b 100644 --- a/packages/utils/src/chain-fns.js +++ b/packages/utils/src/chain-fns.js @@ -15,3 +15,20 @@ export const chainFns = (mainFn, ...moreFns) => ( ), Reflect.apply(mainFn, null, args)) ) ) + + +/** + * previously we already make sure the order of the namespaces + * and attach the auth client to it + * @param {array} promises array of unresolved promises + * @return {object} promise resolved with the array of promises resolved results + */ +export function chainPromises(promises) { + return promises.reduce((promiseChain, currentTask) => ( + promiseChain.then(chainResults => ( + currentTask.then(currentResult => ( + [...chainResults, currentResult] + )) + )) + ), Promise.resolve([])) +} diff --git a/packages/validator/package.json b/packages/validator/package.json index b612a488..334e72df 100644 --- a/packages/validator/package.json +++ b/packages/validator/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-params-validator", - "version": "1.4.5", + "version": "1.4.4", "description": "JSONQL parameters validator written in ES6+ to use with the client / server", "module": "index.js", "browser": "dist/jsonql-params-validator.umd.js", -- Gitee From a0dd385711346e9397dcd40434a8abf6730ea290 Mon Sep 17 00:00:00 2001 From: joelchu Date: Mon, 2 Sep 2019 15:48:24 +0100 Subject: [PATCH 15/17] adding several server status constants to jsonql-constants --- packages/constants/main.js | 8 ++++-- packages/constants/package.json | 2 +- packages/utils/src/contract.js | 50 +++++++++++++++++++++++++++++++++ packages/utils/src/generic.js | 10 +++++++ packages/utils/src/koa.js | 27 ++++++++++-------- packages/vue/package.json | 10 ------- 6 files changed, 83 insertions(+), 24 deletions(-) delete mode 100644 packages/vue/package.json diff --git a/packages/constants/main.js b/packages/constants/main.js index 9bfda742..3ef4c7fd 100644 --- a/packages/constants/main.js +++ b/packages/constants/main.js @@ -166,5 +166,9 @@ 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('.'); +export const DEFAULT_PUBLIC_KEY_FILE = [PUBLIC_KEY_NAME, PEM_EXT].join('.') +export const DEFAULT_PRIVATE_KEY_FILE = [PRIVATE_KEY_NAME, PEM_EXT].join('.') + +export const SUCCESS_STATE = 200; +export const FORBIDDEN_STATE = 403; +export const NOT_FOUND_STATE = 404; diff --git a/packages/constants/package.json b/packages/constants/package.json index 7c7d615f..39f51fe3 100755 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-constants", - "version": "1.7.9", + "version": "1.8.0", "description": "All the share constants for json:ql tools", "main": "index.js", "module": "main.js", diff --git a/packages/utils/src/contract.js b/packages/utils/src/contract.js index 27e91dcf..da99ce35 100644 --- a/packages/utils/src/contract.js +++ b/packages/utils/src/contract.js @@ -1 +1,51 @@ // contract related methods +// This is ported back from ws-server and it will get use in the server / client side +import { isKeyInObject } from './generic' + +/** + * Ported from jsonql-params-validator but different + * if we don't find the socket part then return false + * @param {object} contract the contract object + * @return {object|boolean} false on failed + */ +function extractSocketPart(contract) { + if (isKeyInObject(contract, 'socket')) { + return contract.socket; + } + return false; +} + +/** + * @BUG we should check the socket part instead of expect the downstream to read the menu! + * We only need this when the enableAuth is true otherwise there is only one namespace + * @param {object} contract the socket part of the contract file + * @return {object} 1. remap the contract using the namespace --> resolvers + * 2. the size of the object (1 all private, 2 mixed public with private) + * 3. which namespace is public + */ +export default function groupByNamespace(contract) { + let socket = extractSocketPart(contract) + if (socket === false) { + throw new Error(`socket not found in contract!`) + } + let nspSet = {}; + let size = 0; + let publicNamespace; + for (let resolverName in socket) { + let params = socket[resolverName]; + let { namespace } = params; + if (namespace) { + if (!nspSet[namespace]) { + ++size; + nspSet[namespace] = {}; + } + nspSet[namespace][resolverName] = params; + if (!publicNamespace) { + if (params.public) { + publicNamespace = namespace; + } + } + } + } + return { size, nspSet, publicNamespace } +} diff --git a/packages/utils/src/generic.js b/packages/utils/src/generic.js index 10e6b093..bec690ef 100644 --- a/packages/utils/src/generic.js +++ b/packages/utils/src/generic.js @@ -18,3 +18,13 @@ export const getDebug = (name, baseName = 'jsonql') => { * @return {boolean} true on found */ export const inArray = (arr, value) => !!arr.filter(a => a === value).length; + +/** + * @param {object} obj for search + * @param {string} key target + * @return {boolean} true on success + */ +export const checkKeyInObject = function(obj, key) { + const keys = Object.keys(obj) + return inArray(keys, key) +} diff --git a/packages/utils/src/koa.js b/packages/utils/src/koa.js index 6aa51d8d..d51d7051 100644 --- a/packages/utils/src/koa.js +++ b/packages/utils/src/koa.js @@ -1,13 +1,18 @@ // koa specific methods -const { CONTENT_TYPE } = require('jsonql-constants') +import { CONTENT_TYPE } from 'jsonql-constants' +import jsonqlErrors from 'jsonql-errors' + + +const SUCCESS_STATE = 200; +const FORBIDDEN_STATE = 403; /** * @TODO need to be more flexible * @param {object} ctx koa * @param {object} opts configuration * @return {boolean} if it match */ -const isJsonqlPath = (ctx, opts) => ctx.path === opts.jsonqlPath; +export const isJsonqlPath = (ctx, opts) => ctx.path === opts.jsonqlPath; /** * combine two check in one and save time @@ -15,7 +20,7 @@ const isJsonqlPath = (ctx, opts) => ctx.path === opts.jsonqlPath; * @param {object} opts config * @return {boolean} check result */ -const isJsonqlRequest = (ctx, opts) => { +export const isJsonqlRequest = (ctx, opts) => { const header = isHeaderPresent(ctx.request, opts.contentType) if (header) { return isJsonqlPath(ctx, opts) @@ -29,7 +34,7 @@ const isJsonqlRequest = (ctx, opts) => { * @param {object} opts config * @return {boolean} */ -const isJsonqlConsoleUrl = (ctx, opts) => ( +export const isJsonqlConsoleUrl = (ctx, opts) => ( ctx.method === 'GET' && isJsonqlPath(ctx, opts) ) @@ -38,11 +43,11 @@ const isJsonqlConsoleUrl = (ctx, opts) => ( * @param {object} opts configuration * @return {function} with ctx and body as params */ -const handleOutput = function(opts) { +export const handleOutput = function(opts) { return function(ctx, body) { ctx.size = getDocLen(body) ctx.type = opts.contentType; - ctx.status = 200; + ctx.status = SUCCESS_STATE; ctx.body = body; } } @@ -53,10 +58,10 @@ const handleOutput = function(opts) { * @param {string} body output content * @return {void} */ -const handleHtmlOutput = function(ctx, body) { +export const handleHtmlOutput = function(ctx, body) { ctx.size = getDocLen(body) ctx.type = 'text/html'; - ctx.status = 200; + ctx.status = SUCCESS_STATE; ctx.body = body + ''; // just make sure its string output } @@ -70,7 +75,7 @@ const handleHtmlOutput = function(ctx, body) { * @param {string} message if there is one * @param {string} name custom error class name */ -const ctxErrorHandler = function(ctx, code, e, message = '') { +export const ctxErrorHandler = function(ctx, code, e, message = '') { const render = handleOutput({contentType: CONTENT_TYPE}) let name; if (typeof code === 'string') { @@ -92,6 +97,6 @@ const ctxErrorHandler = function(ctx, code, e, message = '') { * @param {object} e error * @return {undefined} nothing */ -const forbiddenHandler = (ctx, e) => ( - ctxErrorHandler(ctx, 403, e, 'JsonqlAuthorisationError') +export const forbiddenHandler = (ctx, e) => ( + ctxErrorHandler(ctx, FORBIDDEN_STATE, e, 'JsonqlAuthorisationError') ) diff --git a/packages/vue/package.json b/packages/vue/package.json deleted file mode 100644 index 2e906044..00000000 --- a/packages/vue/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "vue", - "version": "0.1.0", - "private": true, - "devDependencies": { - "@vue/cli-plugin-babel": "^3.11.0", - "@vue/cli-plugin-eslint": "^3.11.0", - "@vue/cli-service": "^3.11.0" - } -} \ No newline at end of file -- Gitee From 42cc7c0572efce56bddcbe03557b2a0d37060bd6 Mon Sep 17 00:00:00 2001 From: joelchu Date: Mon, 2 Sep 2019 15:49:26 +0100 Subject: [PATCH 16/17] build new main --- packages/constants/constants.json | 5 ++++- packages/constants/main.js | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/constants/constants.json b/packages/constants/constants.json index 30fcf7df..520eabba 100644 --- a/packages/constants/constants.json +++ b/packages/constants/constants.json @@ -168,5 +168,8 @@ "PUBLIC_KEY_NAME": "publicKey", "PRIVATE_KEY_NAME": "privateKey", "DEFAULT_PUBLIC_KEY_FILE": "publicKey.pem", - "DEFAULT_PRIVATE_KEY_FILE": "privateKey.pem" + "DEFAULT_PRIVATE_KEY_FILE": "privateKey.pem", + "SUCCESS_STATUS": 200, + "FORBIDDEN_STATUS": 403, + "NOT_FOUND_STATUS": 404 } diff --git a/packages/constants/main.js b/packages/constants/main.js index 3ef4c7fd..e68b2023 100644 --- a/packages/constants/main.js +++ b/packages/constants/main.js @@ -169,6 +169,6 @@ 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('.') -export const SUCCESS_STATE = 200; -export const FORBIDDEN_STATE = 403; -export const NOT_FOUND_STATE = 404; +export const SUCCESS_STATUS = 200; +export const FORBIDDEN_STATUS = 403; +export const NOT_FOUND_STATUS = 404; -- Gitee From 11cd643ae751736ccaac4d306d16f2b8e3bfae52 Mon Sep 17 00:00:00 2001 From: joelchu Date: Mon, 2 Sep 2019 16:02:52 +0100 Subject: [PATCH 17/17] adding back the right website to events as well as constants --- packages/@jsonql/event/package.json | 4 ++-- packages/constants/package.json | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/@jsonql/event/package.json b/packages/@jsonql/event/package.json index 24bc4ee7..3dc114ea 100644 --- a/packages/@jsonql/event/package.json +++ b/packages/@jsonql/event/package.json @@ -1,6 +1,6 @@ { "name": "@jsonql/event", - "version": "1.2.2", + "version": "1.2.3", "description": "Event handler library ported from nb-event-service rewritten with Typescript", "main": "dist/jsonql-event.cjs.js", "browser": "dist/jsonql-event.umd.js", @@ -33,7 +33,7 @@ "bugs": { "url": "https://gitee.com/to1source/jsonql/issues" }, - "homepage": "https://gitee.com/to1source/jsonql#readme", + "homepage": "https://jsonql.js.org", "license": "ISC", "devDependencies": { "ava": "^2.2.0", diff --git a/packages/constants/package.json b/packages/constants/package.json index 39f51fe3..c3eaa227 100755 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -25,6 +25,10 @@ "type": "git", "url": "git+ssh://git@gitee.com:to1source/jsonql.git" }, + "homepage": "https://jsonql.js.org", + "bugs": { + "url": "https://gitee.com/to1source/jsonql/issues" + }, "devDependencies": { "fs-extra": "^8.1.0" }, -- Gitee