From 2883748f4370251a4078de441c58ff012e55ca8c Mon Sep 17 00:00:00 2001 From: Joelchu Date: Tue, 13 Aug 2019 12:50:43 +0800 Subject: [PATCH 01/19] add extra layer to try to grab the contract from the other middleware from jsonql-koa --- packages/web-console/koa/index.js | 16 +++++ .../tests/fixtures/contract/contract.json | 64 +++++++++++++++---- .../fixtures/contract/public-contract.json | 60 ++++++++++++++--- 3 files changed, 118 insertions(+), 22 deletions(-) diff --git a/packages/web-console/koa/index.js b/packages/web-console/koa/index.js index 3ee2e372..665e605a 100644 --- a/packages/web-console/koa/index.js +++ b/packages/web-console/koa/index.js @@ -95,6 +95,8 @@ const render = (ctx, file, json = false) => { let ext = extname(file) if (ext === '.css') { ctx.type = 'text/css'; + } else if (ext === '.js') { + ctx.type = 'application/javascript'; } else { ctx.type = 'text/html'; } @@ -116,10 +118,24 @@ module.exports = function jsonqlWebConsole(config, isJsonqlConsoleUrl) { } return async function(ctx, next) { if (isJsonqlConsoleUrl(ctx, config)) { + let error = false; if (contractJson === false) { + // we should try to check if ctx contain the contract at this point as well + if (ctx.state && ctx.state.jsonql) { + const { contract } = ctx.state.jsonql; + if (contract) { + contractJson = contract; + } else { + error = true; // just throw it + } + } + } + + if (error) { // render the error page return render(ctx, 'error.html') } + return render(ctx, 'index.html', contractJson) } else { const asset = isWebConsoleAssets(ctx, config) diff --git a/packages/web-console/tests/fixtures/contract/contract.json b/packages/web-console/tests/fixtures/contract/contract.json index cb069393..d4363581 100644 --- a/packages/web-console/tests/fixtures/contract/contract.json +++ b/packages/web-console/tests/fixtures/contract/contract.json @@ -1,14 +1,14 @@ { "query": { - "defaultCall": { - "file": "/home/joel/projects/open-source/jsonql/packages/contract-console/tests/fixtures/resolvers/query/default-call.js", - "description": false, + "getUser": { + "file": "/home/joel/projects/xuefou/packages/postgres-api/resolvers/query/get-user.js", + "description": "Get a user info", "params": [ { "type": [ "number" ], - "description": "a phony id", + "description": "the user id", "name": "id" } ], @@ -17,39 +17,79 @@ "type": [ "object" ], - "description": "an object with whatever" + "description": "userdata" } ] } }, "mutation": { - "defaultSave": { - "file": "/home/joel/projects/open-source/jsonql/packages/contract-console/tests/fixtures/resolvers/mutation/default-save.js", - "description": false, + "saveUser": { + "file": "/home/joel/projects/xuefou/packages/postgres-api/resolvers/mutation/save-user.js", + "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, "sourceType": "module" } diff --git a/packages/web-console/tests/fixtures/contract/public-contract.json b/packages/web-console/tests/fixtures/contract/public-contract.json index c7808b85..a31c6b80 100644 --- a/packages/web-console/tests/fixtures/contract/public-contract.json +++ b/packages/web-console/tests/fixtures/contract/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 c04b6658120c9cdd67d118688d3a093df656c0bb Mon Sep 17 00:00:00 2001 From: Joelchu Date: Tue, 13 Aug 2019 16:52:58 +0800 Subject: [PATCH 02/19] start chopping up the inner templates --- .../koa/public/templates/block.tpl.html | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 packages/web-console/koa/public/templates/block.tpl.html diff --git a/packages/web-console/koa/public/templates/block.tpl.html b/packages/web-console/koa/public/templates/block.tpl.html new file mode 100644 index 00000000..15bdc5bc --- /dev/null +++ b/packages/web-console/koa/public/templates/block.tpl.html @@ -0,0 +1,78 @@ +

Query

+<% _.forEach(resolverBlock, function(value, name) { %> +
+
+

+ <%- name %> +

+ +
+
+
+ <% if (value.description) { %> + <%- value.description %> + <% } else { %> + No description + <% } %> +
+ + + + + + + + + <% if (value.params.length) { %> + <% _.forEach(value.params, function(param) { %> + + + + + + <% + if (param.keys && params.keys.length) { + _.forEach(param.keys, function(keys) { + %> + + <% + }) + } %> + <% }) %> + <% } else { %> + + + + <% } %> + +
NameTypeDescription
<% if (param.variable) { %>...<% } %><%- param.name %><%- param.type %><%- param.description %>
+ No parameter required +
+ + + + + + + + <% _.forEach(value.returns, function(returns) { %> + + + + + <% }) %> + +
TypeDescription
<%- returns.type %><%- returns.description %>
+
+
+ +
+<% }) %> -- Gitee From 0d9761420f13ec9e5d77d5a14183eba801d75e48 Mon Sep 17 00:00:00 2001 From: Joelchu Date: Tue, 13 Aug 2019 19:44:39 +0800 Subject: [PATCH 03/19] finish the new implementation of block template in web-console --- packages/web-console/koa/index.js | 44 ++- packages/web-console/koa/public/index.html | 302 +----------------- .../koa/public/templates/block.tpl.html | 20 +- 3 files changed, 52 insertions(+), 314 deletions(-) diff --git a/packages/web-console/koa/index.js b/packages/web-console/koa/index.js index 665e605a..b8846914 100644 --- a/packages/web-console/koa/index.js +++ b/packages/web-console/koa/index.js @@ -4,12 +4,13 @@ const fsx = require('fs-extra') const _ = require('lodash') const { DEFAULT_CONTRACT_FILE_NAME, - PUBLIC_CONTRACT_FILE_NAME + PUBLIC_CONTRACT_FILE_NAME, + RESOLVER_TYPES, + AUTH_TYPE } = require('jsonql-constants') const publicDir = join(__dirname, 'public') -const assets = [ - '/jsonql-web-console.css' -] +const assets = ['/jsonql-web-console.css'] +const resolverTypes = [AUTH_TYPE].concat(RESOLVER_TYPES) // const debug = require('debug')('jsonql-web-console:koa') let contractJson = null; /** @@ -62,15 +63,32 @@ const isWebConsoleAssets = ctx => { */ const getDocLen = doc => Buffer.byteLength(doc, 'utf8') -// dirty hack -const fix = json => { - if (!json.socket) { - json.socket = false; - } - if (_.isEqual(json.auth, {})) { - json.auth = false; +/** + * Pre-render the block data and add to the json for final output + * @param {object} json the contract data + * @return {object} the transformed version + */ +const transformTplData = json => { + let outJson = json; + if (outJson.timestamp) { + outJson.timestamp = (new Date(outJson.timestamp)).toUTCString() } - return json; + + const tpl = fsx.readFileSync(join(publicDir, 'templates', 'block.tpl.html')) + return resolverTypes.map(resolverType => { + let typeName = resolverType + 'Block'; + let data = json[resolverType] + if (data && !_.isEqual(data, {})) { + return { + [typeName]: _.template(tpl)({ + resolverType, + resolverData: data + }) + } + } + return {[typeName]: false} + }) + .reduce(_.merge, outJson) } /** @@ -78,7 +96,7 @@ const fix = json => { * @param {object} json contract */ const renderTpl = (content, json) => { - return _.template(content)(fix(json)) + return _.template(content)(transformTplData(json)) } /** diff --git a/packages/web-console/koa/public/index.html b/packages/web-console/koa/public/index.html index 16c41092..98abddf4 100644 --- a/packages/web-console/koa/public/index.html +++ b/packages/web-console/koa/public/index.html @@ -14,17 +14,14 @@ jsonql web console alpha - - -
- +
@@ -81,301 +78,20 @@
- <% if (query) { %> -

Query

- <% _.forEach(query, function(value, name) { %> -
-
-

- <%- name %> -

- -
-
-
- <% if (value.description) { %> - <%- value.description %> - <% } else { %> - No description - <% } %> -
- - - - - - - - - <% if (value.params.length) { %> - <% _.forEach(value.params, function(param) { %> - - - - - - <% }) %> - <% } else { %> - - - - <% } %> - -
NameTypeDescription
<%- param.name %><% if (param.variable) { %>...<% } %><%- param.type %><%- param.description %>
- No parameter required -
- - - - - - - - <% _.forEach(value.returns, function(returns) { %> - - - - - <% }) %> - -
TypeDescription
<%- returns.type %><%- returns.description %>
-
-
- -
- <% }) %> + <% if (queryBlock !== false) { %> + <%= queryBlock %> <% } %> - - <% if (mutation) { %> -

Mutation

- <% _.forEach(mutation, function(value, name) { %> -
-
-

- <%- name %> -

- -
-
-
- <% if (value.description) { %> - <%- value.description %> - <% } else { %> - No description - <% } %> -
- - - - - - - - - <% if (value.params.length) { %> - <% _.forEach(value.params, function(param) { %> - - - - - - <% }) %> - <% } else { %> - - - - <% } %> - -
NameTypeDescription
<%- param.name %><% if (param.variable) { %>...<% } %><%- param.type %><%- param.description %>
- No parameter required -
- - - - - - - - <% _.forEach(value.returns, function(returns) { %> - - - - - <% }) %> - -
TypeDescription
<%- returns.type %><%- returns.description %>
-
-
- -
- <% }) %> + <% if (mutationBlock !== false) { %> + <%= mutationBlock %> <% } %> - - <% if (auth) { %> -

auth

- <% _.forEach(auth, function(value, name) { %> -
-
-

- <%- name %> -

- -
-
-
- <% if (value.description) { %> - <%- value.description %> - <% } else { %> - No description - <% } %> -
- - - - - - - - - <% if (value.params.length) { %> - <% _.forEach(value.params, function(param) { %> - - - - - - <% }) %> - <% } else { %> - - - - <% } %> - -
NameTypeDescription
<%- param.name %><% if (param.variable) { %>...<% } %><%- param.type %><%- param.description %>
- No parameter required -
- - - - - - - - <% _.forEach(value.returns, function(returns) { %> - - - - - <% }) %> - -
TypeDescription
<%- returns.type %><%- returns.description %>
-
-
- -
- <% }) %> + <% if (socketBlock !== false) { %> + <%= socketBlock %> <% } %> - - <% if (socket) { %> -

socket

- <% _.forEach(socket, function(value, name) { %> -
-
-

- <%- name %> -

- -
-
-
- <% if (value.description) { %> - <%- value.description %> - <% } else { %> - No description - <% } %> -
- - - - - - - - - <% if (value.params.length) { %> - <% _.forEach(value.params, function(param) { %> - - - - - - <% }) %> - <% } else { %> - - - - <% } %> - -
NameTypeDescription
<%- param.name %><% if (param.variable) { %>...<% } %><%- param.type %><%- param.description %>
- No parameter required -
- - - - - - - - <% _.forEach(value.returns, function(returns) { %> - - - - - <% }) %> - -
TypeDescription
<%- returns.type %><%- returns.description %>
-
-
- -
- <% }) %> + <% if (authBlock) { %> + <%= authBlock %> <% } %>
- - diff --git a/packages/web-console/koa/public/templates/block.tpl.html b/packages/web-console/koa/public/templates/block.tpl.html index 15bdc5bc..51014de7 100644 --- a/packages/web-console/koa/public/templates/block.tpl.html +++ b/packages/web-console/koa/public/templates/block.tpl.html @@ -1,15 +1,15 @@

Query

-<% _.forEach(resolverBlock, function(value, name) { %> +<% _.forEach(resolverData, function(value, name) { %>

<%- name %>

- +
@@ -20,7 +20,7 @@ <% } %>
- +
@@ -28,8 +28,8 @@ <% if (value.params.length) { %> - <% _.forEach(value.params, function(param) { %> - + <% _.forEach(value.params, function(param, i) { %> + 0 && i%2) {%> class="has-background-light"<%} %>> @@ -38,7 +38,11 @@ if (param.keys && params.keys.length) { _.forEach(param.keys, function(keys) { %> - + 0 && i%2) {%> class="has-background-light"<%} %>> + + + + <% }) } %> -- Gitee From 39dc2ba2aeafab08d6ff23df8b4cf85e9b1516f6 Mon Sep 17 00:00:00 2001 From: Joelchu Date: Tue, 13 Aug 2019 19:52:27 +0800 Subject: [PATCH 04/19] take out the methods for testing --- packages/web-console/koa/index.js | 130 +---------------- .../koa/public/templates/block.tpl.html | 2 +- packages/web-console/koa/utils.js | 137 ++++++++++++++++++ packages/web-console/package.json | 2 +- 4 files changed, 144 insertions(+), 127 deletions(-) create mode 100644 packages/web-console/koa/utils.js diff --git a/packages/web-console/koa/index.js b/packages/web-console/koa/index.js index b8846914..1defc9e6 100644 --- a/packages/web-console/koa/index.js +++ b/packages/web-console/koa/index.js @@ -1,130 +1,10 @@ // The main interface to the middleware -const { join, extname } = require('path') -const fsx = require('fs-extra') -const _ = require('lodash') const { - DEFAULT_CONTRACT_FILE_NAME, - PUBLIC_CONTRACT_FILE_NAME, - RESOLVER_TYPES, - AUTH_TYPE -} = require('jsonql-constants') -const publicDir = join(__dirname, 'public') -const assets = ['/jsonql-web-console.css'] -const resolverTypes = [AUTH_TYPE].concat(RESOLVER_TYPES) -// const debug = require('debug')('jsonql-web-console:koa') -let contractJson = null; -/** - * Just to read the contract json - * search for the contract file - * should we check if there is a public-contract first - * if it's not found then we check if there is a contract.json? - * also in the case of just start up, it might happen a fight situation - * @param {object} config configuration - */ -const getContractJson = config => { - const searchDir = [ - join(config.contractDir, PUBLIC_CONTRACT_FILE_NAME), - join(config.contractDir, DEFAULT_CONTRACT_FILE_NAME) - ] - return _(searchDir) - .chain() - .filter(dir => fsx.existsSync(dir)) - .thru(dirs => { - if (dirs.length) { - return fsx.readJsonSync(dirs[0]) - } - return false; - }) - .value() -} - -/** - * check if the path matches our assets - * @param {object} ctx koa context - * @return {boolean|string} false when its not - */ -const isWebConsoleAssets = ctx => { - return _(assets) - .chain() - .filter(path => ctx.path === path) - .thru(path => { - if (path.length) { - return path[0] - } - return false; - }) - .value() -} - -/** - * Get document (string) byte length for use in header - * @param {string} doc to calculate - * @return {number} length - */ -const getDocLen = doc => Buffer.byteLength(doc, 'utf8') - -/** - * Pre-render the block data and add to the json for final output - * @param {object} json the contract data - * @return {object} the transformed version - */ -const transformTplData = json => { - let outJson = json; - if (outJson.timestamp) { - outJson.timestamp = (new Date(outJson.timestamp)).toUTCString() - } - - const tpl = fsx.readFileSync(join(publicDir, 'templates', 'block.tpl.html')) - return resolverTypes.map(resolverType => { - let typeName = resolverType + 'Block'; - let data = json[resolverType] - if (data && !_.isEqual(data, {})) { - return { - [typeName]: _.template(tpl)({ - resolverType, - resolverData: data - }) - } - } - return {[typeName]: false} - }) - .reduce(_.merge, outJson) -} - -/** - * @param {string} content output string from file - * @param {object} json contract - */ -const renderTpl = (content, json) => { - return _.template(content)(transformTplData(json)) -} - -/** - * Render out the content - * @param {object} ctx koa context - * @param {string} file to serve up - * @return {void} nothing should stop here - */ -const render = (ctx, file, json = false) => { - let content = fsx.readFileSync(join(publicDir, file)) - if (json !== false) { - content = renderTpl(content, json) - } - let ext = extname(file) - if (ext === '.css') { - ctx.type = 'text/css'; - } else if (ext === '.js') { - ctx.type = 'application/javascript'; - } else { - ctx.type = 'text/html'; - } - - ctx.size = getDocLen(content) - // should we try to get the contentType? - // ctx.type = opts.contentType; - ctx.status = 200; - ctx.body = content; -} + getContractJson, + isWebConsoleAssets, + getDocLen, + render +} = require('./utils') /** * @param {object} config configuration diff --git a/packages/web-console/koa/public/templates/block.tpl.html b/packages/web-console/koa/public/templates/block.tpl.html index 51014de7..353f0145 100644 --- a/packages/web-console/koa/public/templates/block.tpl.html +++ b/packages/web-console/koa/public/templates/block.tpl.html @@ -27,7 +27,7 @@ - <% if (value.params.length) { %> + <% if (value.params && value.params.length) { %> <% _.forEach(value.params, function(param, i) { %> 0 && i%2) {%> class="has-background-light"<%} %>> diff --git a/packages/web-console/koa/utils.js b/packages/web-console/koa/utils.js new file mode 100644 index 00000000..5def4e09 --- /dev/null +++ b/packages/web-console/koa/utils.js @@ -0,0 +1,137 @@ +// all the require methods +const { join, extname } = require('path') +const fsx = require('fs-extra') +const _ = require('lodash') +const { + DEFAULT_CONTRACT_FILE_NAME, + PUBLIC_CONTRACT_FILE_NAME, + RESOLVER_TYPES, + AUTH_TYPE +} = require('jsonql-constants') +const publicDir = join(__dirname, 'public') +const assets = ['/jsonql-web-console.css'] +const resolverTypes = [AUTH_TYPE].concat(RESOLVER_TYPES) +const debug = require('debug')('jsonql-web-console:koa') +let contractJson = null; +/** + * Just to read the contract json + * search for the contract file + * should we check if there is a public-contract first + * if it's not found then we check if there is a contract.json? + * also in the case of just start up, it might happen a fight situation + * @param {object} config configuration + */ +const getContractJson = config => { + const searchDir = [ + join(config.contractDir, PUBLIC_CONTRACT_FILE_NAME), + join(config.contractDir, DEFAULT_CONTRACT_FILE_NAME) + ] + return _(searchDir) + .chain() + .filter(dir => fsx.existsSync(dir)) + .thru(dirs => { + if (dirs.length) { + return fsx.readJsonSync(dirs[0]) + } + return false; + }) + .value() +} + +/** + * check if the path matches our assets + * @param {object} ctx koa context + * @return {boolean|string} false when its not + */ +const isWebConsoleAssets = ctx => { + return _(assets) + .chain() + .filter(path => ctx.path === path) + .thru(path => { + if (path.length) { + return path[0] + } + return false; + }) + .value() +} + +/** + * Get document (string) byte length for use in header + * @param {string} doc to calculate + * @return {number} length + */ +const getDocLen = doc => Buffer.byteLength(doc, 'utf8') + +/** + * Pre-render the block data and add to the json for final output + * @param {object} json the contract data + * @return {object} the transformed version + */ +const transformTplData = json => { + let outJson = json; + if (outJson.timestamp) { + outJson.timestamp = (new Date(outJson.timestamp)).toUTCString() + } + + const tpl = fsx.readFileSync(join(publicDir, 'templates', 'block.tpl.html')) + return resolverTypes.map(resolverType => { + let typeName = resolverType + 'Block'; + let data = json[resolverType] + debug(data) + if (data && !_.isEqual(data, {})) { + return { + [typeName]: _.template(tpl)({ + resolverType, + resolverData: data + }) + } + } + return {[typeName]: false} + }) + .reduce(_.merge, outJson) +} + +/** + * @param {string} content output string from file + * @param {object} json contract + */ +const renderTpl = (content, json) => { + return _.template(content)(transformTplData(json)) +} + +/** + * Render out the content + * @param {object} ctx koa context + * @param {string} file to serve up + * @return {void} nothing should stop here + */ +const render = (ctx, file, json = false) => { + let content = fsx.readFileSync(join(publicDir, file)) + if (json !== false) { + content = renderTpl(content, json) + } + let ext = extname(file) + if (ext === '.css') { + ctx.type = 'text/css'; + } else if (ext === '.js') { + ctx.type = 'application/javascript'; + } else { + ctx.type = 'text/html'; + } + + ctx.size = getDocLen(content) + // should we try to get the contentType? + // ctx.type = opts.contentType; + ctx.status = 200; + ctx.body = content; +} + +module.exports = { + getContractJson, + isWebConsoleAssets, + getDocLen, + transformTplData, + renderTpl, + render +} diff --git a/packages/web-console/package.json b/packages/web-console/package.json index 5e1e73ec..652b89e4 100644 --- a/packages/web-console/package.json +++ b/packages/web-console/package.json @@ -9,7 +9,7 @@ "jsonql": "node ./tests/fixtures/server.js", "dev": "npm run jsonql & npm run serve", "dev:koa": "node ./koa/dev.js", - "test:browser": "DEBUG=jsonql-web-console*,server-io-core* node ./tests/fixtures/run.js", + "test:browser": "DEBUG=jsonql-web-console* node ./tests/fixtures/run.js", "test:tpl": "DEBUG=jsonql-web-console* node ./tests/fixtures/tpl.js" }, "files": [ -- Gitee From 9dde6c097296a59067e426f019b50e4a5cbc43c5 Mon Sep 17 00:00:00 2001 From: Joelchu Date: Tue, 13 Aug 2019 20:42:02 +0800 Subject: [PATCH 05/19] Fix the template errors in the web-console block.tpl.html --- packages/web-console/koa/index.js | 2 +- .../koa/public/templates/block.tpl.html | 2 +- packages/web-console/koa/utils.js | 10 +++++----- packages/web-console/package.json | 4 ++-- packages/web-console/tests/fixtures/tpl.js | 19 ++----------------- 5 files changed, 11 insertions(+), 26 deletions(-) diff --git a/packages/web-console/koa/index.js b/packages/web-console/koa/index.js index 1defc9e6..f1eeb531 100644 --- a/packages/web-console/koa/index.js +++ b/packages/web-console/koa/index.js @@ -5,7 +5,7 @@ const { getDocLen, render } = require('./utils') - +let contractJson = null; /** * @param {object} config configuration * @param {function} isJsonqlConsoleUrl to check if it's the top calling methods diff --git a/packages/web-console/koa/public/templates/block.tpl.html b/packages/web-console/koa/public/templates/block.tpl.html index 353f0145..8ffdd165 100644 --- a/packages/web-console/koa/public/templates/block.tpl.html +++ b/packages/web-console/koa/public/templates/block.tpl.html @@ -35,7 +35,7 @@ <% - if (param.keys && params.keys.length) { + if (param.keys && param.keys.length) { _.forEach(param.keys, function(keys) { %> 0 && i%2) {%> class="has-background-light"<%} %>> diff --git a/packages/web-console/koa/utils.js b/packages/web-console/koa/utils.js index 5def4e09..0ce870f0 100644 --- a/packages/web-console/koa/utils.js +++ b/packages/web-console/koa/utils.js @@ -8,11 +8,11 @@ const { RESOLVER_TYPES, AUTH_TYPE } = require('jsonql-constants') -const publicDir = join(__dirname, 'public') +const publicDir = process.env.PUBLIC_DIR || join(__dirname, 'public') const assets = ['/jsonql-web-console.css'] const resolverTypes = [AUTH_TYPE].concat(RESOLVER_TYPES) -const debug = require('debug')('jsonql-web-console:koa') -let contractJson = null; +const debug = require('debug')('jsonql-web-console:utils') + /** * Just to read the contract json * search for the contract file @@ -78,7 +78,7 @@ const transformTplData = json => { return resolverTypes.map(resolverType => { let typeName = resolverType + 'Block'; let data = json[resolverType] - debug(data) + debug(resolverType, data) if (data && !_.isEqual(data, {})) { return { [typeName]: _.template(tpl)({ @@ -87,7 +87,7 @@ const transformTplData = json => { }) } } - return {[typeName]: false} + return {[typeName]: false, [resolverType]: false} }) .reduce(_.merge, outJson) } diff --git a/packages/web-console/package.json b/packages/web-console/package.json index 652b89e4..5eb2336d 100644 --- a/packages/web-console/package.json +++ b/packages/web-console/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-web-console", - "version": "0.2.0", + "version": "0.3.0", "main": "koa/index.js", "scripts": { "serve": "vue-cli-service serve", @@ -10,7 +10,7 @@ "dev": "npm run jsonql & npm run serve", "dev:koa": "node ./koa/dev.js", "test:browser": "DEBUG=jsonql-web-console* node ./tests/fixtures/run.js", - "test:tpl": "DEBUG=jsonql-web-console* node ./tests/fixtures/tpl.js" + "test:tpl": "DEBUG=jsonql-web-console* PUBLIC_DIR=/home/joel/projects/open-source/jsonql/packages/web-console/koa/public node ./tests/fixtures/tpl.js" }, "files": [ "koa", diff --git a/packages/web-console/tests/fixtures/tpl.js b/packages/web-console/tests/fixtures/tpl.js index 3fab9608..23dc172f 100644 --- a/packages/web-console/tests/fixtures/tpl.js +++ b/packages/web-console/tests/fixtures/tpl.js @@ -4,25 +4,10 @@ const fsx = require('fs-extra') const { join } = require('path') const debug = require('debug')('jsonql-web-console:test:tpl') const dir = join(__dirname, '..', '..', 'koa') - const content = fsx.readFileSync(join(dir, 'public', 'index.html')) - const json = fsx.readJsonSync(join(__dirname, 'contract', 'public-contract.json')) +const { renderTpl } = require('../../koa/utils') -const fix = json => { - if (!json.socket) { - json.socket = false; - } - if (_.isEqual(json.auth, {})) { - json.auth = false; - } - return json; -} - -const out = _.template(content)( - fix(json) -) - -debug('type', typeof out) +const out = renderTpl(content, json) debug(out) -- Gitee From 213615b95e62d467396f689fdd137b440bd47193 Mon Sep 17 00:00:00 2001 From: Joelchu Date: Tue, 13 Aug 2019 20:45:47 +0800 Subject: [PATCH 06/19] template verify working correctly, --- packages/web-console/koa/public/templates/block.tpl.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web-console/koa/public/templates/block.tpl.html b/packages/web-console/koa/public/templates/block.tpl.html index 8ffdd165..c07300a6 100644 --- a/packages/web-console/koa/public/templates/block.tpl.html +++ b/packages/web-console/koa/public/templates/block.tpl.html @@ -57,7 +57,7 @@
Name Type
<% if (param.variable) { %>...<% } %><%- param.name %> <%- param.type %> <%- param.description %><%- keys.parent %>.<%- keys.name %><%- keys.type %><%- keys.description %>
Description
<% if (param.variable) { %>...<% } %><%- param.name %><%- param.description %>
- +
-- Gitee From 08cb1dcc5ea7586214f86c206c4e32ede7baf287 Mon Sep 17 00:00:00 2001 From: Joelchu Date: Tue, 13 Aug 2019 20:48:50 +0800 Subject: [PATCH 07/19] update jsonql-web-console deps --- packages/web-console/package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/web-console/package.json b/packages/web-console/package.json index 5eb2336d..9e100c6a 100644 --- a/packages/web-console/package.json +++ b/packages/web-console/package.json @@ -10,14 +10,13 @@ "dev": "npm run jsonql & npm run serve", "dev:koa": "node ./koa/dev.js", "test:browser": "DEBUG=jsonql-web-console* node ./tests/fixtures/run.js", - "test:tpl": "DEBUG=jsonql-web-console* PUBLIC_DIR=/home/joel/projects/open-source/jsonql/packages/web-console/koa/public node ./tests/fixtures/tpl.js" + "test:tpl": "DEBUG=jsonql-web-console* PUBLIC_DIR=~/jsonql/packages/web-console/koa/public node ./tests/fixtures/tpl.js" }, "files": [ "koa", "index.js" ], "dependencies": { - "bulma": "^0.7.5", "fs-extra": "^8.1.0", "jsonql-constants": "^1.7.9", "lodash": "^4.17.15" @@ -27,12 +26,13 @@ "@vue/cli-plugin-eslint": "^3.10.0", "@vue/cli-service": "^3.10.0", "babel-eslint": "^10.0.2", - "core-js": "^3.2.0", + "bulma": "^0.7.5", + "core-js": "^3.2.1", "debug": "^4.1.1", "eslint": "^6.1.0", "eslint-plugin-vue": "^5.2.3", "jsonql-client": "^1.3.1", - "jsonql-koa": "^1.3.4", + "jsonql-koa": "^1.3.5", "jsonql-ws-client": "^1.0.0-beta.1", "server-io-core": "^1.2.0", "vue": "^2.6.10", -- Gitee From a5e779f75b393c00ffa0fcecad5e1f7f45b837ee Mon Sep 17 00:00:00 2001 From: Joelchu Date: Tue, 13 Aug 2019 20:51:06 +0800 Subject: [PATCH 08/19] update the deps and verify once again the test run correctly --- packages/koa/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/koa/package.json b/packages/koa/package.json index 89a76124..b4600a06 100755 --- a/packages/koa/package.json +++ b/packages/koa/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-koa", - "version": "1.3.5", + "version": "1.3.6", "description": "jsonql Koa middleware", "main": "index.js", "files": [ @@ -46,7 +46,7 @@ "jsonql-jwt": "^1.2.1", "jsonql-node-client": "^1.1.3", "jsonql-params-validator": "^1.4.3", - "jsonql-web-console": "^0.2.0", + "jsonql-web-console": "^0.3.0", "koa": "^2.7.0", "koa-compose": "^4.1.0", "lodash": "^4.17.15", -- Gitee From e663e0fd6dcb87567875dc551fa039a91106ddeb Mon Sep 17 00:00:00 2001 From: Joelchu Date: Tue, 13 Aug 2019 20:55:35 +0800 Subject: [PATCH 09/19] The console still unable to fetch the json on first run --- packages/web-console/koa/public/index.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/web-console/koa/public/index.html b/packages/web-console/koa/public/index.html index 98abddf4..ef12426d 100644 --- a/packages/web-console/koa/public/index.html +++ b/packages/web-console/koa/public/index.html @@ -6,6 +6,11 @@ jsonql web-console +
Type Description
@@ -57,7 +57,7 @@ <% } %>
Name
- + returns diff --git a/packages/web-console/koa/utils.js b/packages/web-console/koa/utils.js index 7c1b3b91..3af016cb 100644 --- a/packages/web-console/koa/utils.js +++ b/packages/web-console/koa/utils.js @@ -72,6 +72,7 @@ const getDocLen = doc => Buffer.byteLength(doc, 'utf8') const transformTplData = json => { let outJson = json; if (outJson.timestamp) { + debug('timestamp', outJson.timestamp) outJson.timestamp = timeStamp2String(parseInt(outJson.timestamp)) } -- Gitee From a516cb795a4095a6152757086335b28b04aa6e89 Mon Sep 17 00:00:00 2001 From: Joelchu Date: Tue, 13 Aug 2019 22:19:32 +0800 Subject: [PATCH 18/19] jsonql-web-console to v0.4.3 --- packages/web-console/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web-console/package.json b/packages/web-console/package.json index c574e9e2..103c8e3c 100644 --- a/packages/web-console/package.json +++ b/packages/web-console/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-web-console", - "version": "0.4.2", + "version": "0.4.3", "main": "koa/index.js", "scripts": { "serve": "vue-cli-service serve", -- Gitee From 05898ec6c5d01d9c8c497810e6fa7702b8e424a4 Mon Sep 17 00:00:00 2001 From: Joelchu Date: Tue, 13 Aug 2019 22:41:23 +0800 Subject: [PATCH 19/19] remove unused deps and update the timestamp to use mil seconds --- packages/contract-cli/README.md | 7 +++++++ .../contract-cli/lib/public-contract/index.js | 1 + packages/contract-cli/lib/utils.js | 6 +++--- packages/contract-cli/package.json | 19 ++++--------------- packages/contract-cli/tests/generator.test.js | 2 +- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/packages/contract-cli/README.md b/packages/contract-cli/README.md index 1fee04f1..3294e2ef 100755 --- a/packages/contract-cli/README.md +++ b/packages/contract-cli/README.md @@ -219,3 +219,10 @@ We will take the jsdoc output and create an additional temporary contract file ( --- MIT (c) [to1source](https://to1source.cn) & [NEWBRAN LTD](https://newbran.ch) + + +"socket.io-client": "^2.2.0", +"ts-node": "^8.3.0", +"typescript": "^3.5.3", +"ws": "^7.1.2", +"@types/node": "^12.7.1", diff --git a/packages/contract-cli/lib/public-contract/index.js b/packages/contract-cli/lib/public-contract/index.js index 0eb6e281..6322cb74 100644 --- a/packages/contract-cli/lib/public-contract/index.js +++ b/packages/contract-cli/lib/public-contract/index.js @@ -72,6 +72,7 @@ function getEnvContractFile(contractDir) { function getExpired(config, contractJson) { const { expired } = config; const { timestamp } = contractJson; + // the timestamp now comes with milsecond ... if (expired && expired > timestamp) { return { expired } } diff --git a/packages/contract-cli/lib/utils.js b/packages/contract-cli/lib/utils.js index 91083369..413a5761 100644 --- a/packages/contract-cli/lib/utils.js +++ b/packages/contract-cli/lib/utils.js @@ -8,8 +8,8 @@ const checkOptions = require('./options') const { transform } = require('lodash') const debug = require('debug')('jsonql-contract:utils') const { JsonqlError } = require('jsonql-errors') - -const getTimestamp = () => Math.round(Date.now()/1000) +// timestamp with mil seconds +const getTimestamp = () => Date.now() /** * check if there is a config file and use that value instead @@ -92,7 +92,7 @@ const checkFile = config => { if (config.returnAs === 'file') { if (!fsx.existsSync(dist)) { throw new JsonqlError('File is not generated!', dist) - } + } console.info('Your contract file generated in: %s', dist) } else { if (!isObject(dist)) { diff --git a/packages/contract-cli/package.json b/packages/contract-cli/package.json index 1f6a12ca..fa6bc196 100755 --- a/packages/contract-cli/package.json +++ b/packages/contract-cli/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-contract", - "version": "1.7.6", + "version": "1.7.7", "description": "An command line tool to generate the contract.json for jsonql", "main": "index.js", "files": [ @@ -38,25 +38,20 @@ "jsonql-contract": "./cli.js" }, "dependencies": { - "acorn": "^6.2.1", + "acorn": "^7.0.0", "chokidar": "^3.0.2", "colors": "^1.3.3", "fs-extra": "^8.1.0", "glob": "^7.1.4", "jsdoc-api": "^5.0.2", - "jsonql-constants": "^1.7.8", + "jsonql-constants": "^1.7.9", "jsonql-errors": "^1.0.9", "jsonql-params-validator": "^1.4.3", "kefir": "^3.8.6", "lodash": "^4.17.15", - "socket.io-client": "^2.2.0", - "ts-node": "^8.3.0", - "typescript": "^3.5.3", - "ws": "^7.1.1", "yargs": "^13.3.0" }, "devDependencies": { - "@types/node": "^12.6.8", "ava": "^2.2.0", "debug": "^4.1.1", "nyc": "^14.1.1", @@ -77,13 +72,7 @@ "failWithoutAssertions": false, "tap": false, "verbose": true, - "compileEnhancements": false, - "extensions": [ - "ts" - ], - "require": [ - "ts-node/register" - ] + "compileEnhancements": false }, "engine": { "node": ">=8" diff --git a/packages/contract-cli/tests/generator.test.js b/packages/contract-cli/tests/generator.test.js index d3b73926..7e68a788 100755 --- a/packages/contract-cli/tests/generator.test.js +++ b/packages/contract-cli/tests/generator.test.js @@ -23,7 +23,7 @@ const esContractDir = join(__dirname, 'fixtures', 'tmp', 'es') const esResolverDir = join(__dirname, 'fixtures', 'es') -const expired = Math.round(Date.now()/1000) + 60*365; +const expired = Date.now() + 60*365*1000; test.after(async t => { fsx.removeSync(contractDir) -- Gitee
Type