diff --git a/.gitignore b/.gitignore index a871408f53429626fa5baf3623d29edbb7c4c0b7..20d0703d777636c00fc87769c1d55df41cee8a00 100755 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/node_modules +/**/node_modules .DS_Store yarn.lock package-lock.json diff --git a/packages/@jsonql/http-client/README.md b/archived/http-client/README.md similarity index 100% rename from packages/@jsonql/http-client/README.md rename to archived/http-client/README.md diff --git a/packages/@jsonql/http-client/core.js b/archived/http-client/core.js similarity index 100% rename from packages/@jsonql/http-client/core.js rename to archived/http-client/core.js diff --git a/packages/@jsonql/http-client/core.js.map b/archived/http-client/core.js.map similarity index 100% rename from packages/@jsonql/http-client/core.js.map rename to archived/http-client/core.js.map diff --git a/packages/@jsonql/http-client/dist/jsonql-client.static.js b/archived/http-client/dist/jsonql-client.static.js similarity index 100% rename from packages/@jsonql/http-client/dist/jsonql-client.static.js rename to archived/http-client/dist/jsonql-client.static.js diff --git a/packages/@jsonql/http-client/dist/jsonql-client.static.js.map b/archived/http-client/dist/jsonql-client.static.js.map similarity index 100% rename from packages/@jsonql/http-client/dist/jsonql-client.static.js.map rename to archived/http-client/dist/jsonql-client.static.js.map diff --git a/packages/@jsonql/http-client/dist/jsonql-client.umd.js b/archived/http-client/dist/jsonql-client.umd.js similarity index 100% rename from packages/@jsonql/http-client/dist/jsonql-client.umd.js rename to archived/http-client/dist/jsonql-client.umd.js diff --git a/packages/@jsonql/http-client/dist/jsonql-client.umd.js.map b/archived/http-client/dist/jsonql-client.umd.js.map similarity index 100% rename from packages/@jsonql/http-client/dist/jsonql-client.umd.js.map rename to archived/http-client/dist/jsonql-client.umd.js.map diff --git a/packages/@jsonql/http-client/full.js b/archived/http-client/full.js similarity index 100% rename from packages/@jsonql/http-client/full.js rename to archived/http-client/full.js diff --git a/packages/@jsonql/http-client/index.js b/archived/http-client/index.js similarity index 100% rename from packages/@jsonql/http-client/index.js rename to archived/http-client/index.js diff --git a/packages/@jsonql/http-client/package.json b/archived/http-client/package.json similarity index 100% rename from packages/@jsonql/http-client/package.json rename to archived/http-client/package.json diff --git a/packages/@jsonql/http-client/rollup.config.js b/archived/http-client/rollup.config.js similarity index 100% rename from packages/@jsonql/http-client/rollup.config.js rename to archived/http-client/rollup.config.js diff --git a/packages/@jsonql/http-client/src/base/auth-cls.js b/archived/http-client/src/base/auth-cls.js similarity index 100% rename from packages/@jsonql/http-client/src/base/auth-cls.js rename to archived/http-client/src/base/auth-cls.js diff --git a/packages/@jsonql/http-client/src/base/base-cls.js b/archived/http-client/src/base/base-cls.js similarity index 100% rename from packages/@jsonql/http-client/src/base/base-cls.js rename to archived/http-client/src/base/base-cls.js diff --git a/packages/@jsonql/http-client/src/base/contract-cls.js b/archived/http-client/src/base/contract-cls.js similarity index 100% rename from packages/@jsonql/http-client/src/base/contract-cls.js rename to archived/http-client/src/base/contract-cls.js diff --git a/packages/@jsonql/http-client/src/base/http-cls.js b/archived/http-client/src/base/http-cls.js similarity index 100% rename from packages/@jsonql/http-client/src/base/http-cls.js rename to archived/http-client/src/base/http-cls.js diff --git a/packages/@jsonql/http-client/src/base/index.js b/archived/http-client/src/base/index.js similarity index 100% rename from packages/@jsonql/http-client/src/base/index.js rename to archived/http-client/src/base/index.js diff --git a/packages/@jsonql/http-client/src/core/jsonql-api-generator.js b/archived/http-client/src/core/jsonql-api-generator.js similarity index 100% rename from packages/@jsonql/http-client/src/core/jsonql-api-generator.js rename to archived/http-client/src/core/jsonql-api-generator.js diff --git a/packages/@jsonql/http-client/src/core/jsonql-static-generator.js b/archived/http-client/src/core/jsonql-static-generator.js similarity index 100% rename from packages/@jsonql/http-client/src/core/jsonql-static-generator.js rename to archived/http-client/src/core/jsonql-static-generator.js diff --git a/packages/@jsonql/http-client/src/core/methods-generator.js b/archived/http-client/src/core/methods-generator.js similarity index 100% rename from packages/@jsonql/http-client/src/core/methods-generator.js rename to archived/http-client/src/core/methods-generator.js diff --git a/packages/@jsonql/http-client/src/ee.js b/archived/http-client/src/ee.js similarity index 100% rename from packages/@jsonql/http-client/src/ee.js rename to archived/http-client/src/ee.js diff --git a/packages/@jsonql/http-client/src/index.js b/archived/http-client/src/index.js similarity index 100% rename from packages/@jsonql/http-client/src/index.js rename to archived/http-client/src/index.js diff --git a/packages/@jsonql/http-client/src/jsonql-async.js b/archived/http-client/src/jsonql-async.js similarity index 100% rename from packages/@jsonql/http-client/src/jsonql-async.js rename to archived/http-client/src/jsonql-async.js diff --git a/packages/@jsonql/http-client/src/jsonql-sync.js b/archived/http-client/src/jsonql-sync.js similarity index 100% rename from packages/@jsonql/http-client/src/jsonql-sync.js rename to archived/http-client/src/jsonql-sync.js diff --git a/packages/@jsonql/http-client/src/jsonql-utils.js b/archived/http-client/src/jsonql-utils.js similarity index 100% rename from packages/@jsonql/http-client/src/jsonql-utils.js rename to archived/http-client/src/jsonql-utils.js diff --git a/packages/@jsonql/http-client/src/options/base-options.js b/archived/http-client/src/options/base-options.js similarity index 100% rename from packages/@jsonql/http-client/src/options/base-options.js rename to archived/http-client/src/options/base-options.js diff --git a/packages/@jsonql/http-client/src/options/check-options-async.js b/archived/http-client/src/options/check-options-async.js similarity index 100% rename from packages/@jsonql/http-client/src/options/check-options-async.js rename to archived/http-client/src/options/check-options-async.js diff --git a/packages/@jsonql/http-client/src/options/check-options.js b/archived/http-client/src/options/check-options.js similarity index 100% rename from packages/@jsonql/http-client/src/options/check-options.js rename to archived/http-client/src/options/check-options.js diff --git a/packages/@jsonql/http-client/src/options/index.js b/archived/http-client/src/options/index.js similarity index 100% rename from packages/@jsonql/http-client/src/options/index.js rename to archived/http-client/src/options/index.js diff --git a/packages/@jsonql/http-client/src/static-full.js b/archived/http-client/src/static-full.js similarity index 100% rename from packages/@jsonql/http-client/src/static-full.js rename to archived/http-client/src/static-full.js diff --git a/packages/@jsonql/http-client/src/static.js b/archived/http-client/src/static.js similarity index 100% rename from packages/@jsonql/http-client/src/static.js rename to archived/http-client/src/static.js diff --git a/packages/@jsonql/http-client/src/stores/index.js b/archived/http-client/src/stores/index.js similarity index 100% rename from packages/@jsonql/http-client/src/stores/index.js rename to archived/http-client/src/stores/index.js diff --git a/packages/@jsonql/http-client/src/stores/local-store.js b/archived/http-client/src/stores/local-store.js similarity index 100% rename from packages/@jsonql/http-client/src/stores/local-store.js rename to archived/http-client/src/stores/local-store.js diff --git a/packages/@jsonql/http-client/src/stores/session-store.js b/archived/http-client/src/stores/session-store.js similarity index 100% rename from packages/@jsonql/http-client/src/stores/session-store.js rename to archived/http-client/src/stores/session-store.js diff --git a/packages/@jsonql/http-client/src/utils.js b/archived/http-client/src/utils.js similarity index 100% rename from packages/@jsonql/http-client/src/utils.js rename to archived/http-client/src/utils.js diff --git a/packages/@jsonql/http-client/static.js b/archived/http-client/static.js similarity index 100% rename from packages/@jsonql/http-client/static.js rename to archived/http-client/static.js diff --git a/packages/@jsonql/http-client/static.js.map b/archived/http-client/static.js.map similarity index 100% rename from packages/@jsonql/http-client/static.js.map rename to archived/http-client/static.js.map diff --git a/packages/@jsonql/http-client/tests/assign.test.js b/archived/http-client/tests/assign.test.js similarity index 100% rename from packages/@jsonql/http-client/tests/assign.test.js rename to archived/http-client/tests/assign.test.js diff --git a/packages/@jsonql/http-client/tests/fixtures/contract.js b/archived/http-client/tests/fixtures/contract.js similarity index 100% rename from packages/@jsonql/http-client/tests/fixtures/contract.js rename to archived/http-client/tests/fixtures/contract.js diff --git a/archived/http-client/tests/fixtures/contracts/tmp/contract.json b/archived/http-client/tests/fixtures/contracts/tmp/contract.json new file mode 100644 index 0000000000000000000000000000000000000000..dd303f3553b9ccae3dbed4c544c64a763ec5842a --- /dev/null +++ b/archived/http-client/tests/fixtures/contracts/tmp/contract.json @@ -0,0 +1,122 @@ +{ + "query": { + "getSomething": { + "file": "/home/joel/projects/open-source/jsonql/packages/@jsonql/client/tests/fixtures/resolvers/query/get-something.js", + "description": "This is a new query that require parameters for testing", + "params": [ + { + "type": [ + "string" + ], + "name": "key", + "description": "key" + }, + { + "type": [ + "string" + ], + "name": "value", + "optional": true, + "defaultvalue": "'world'", + "description": "optional value" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "put key / value together into an object" + } + ] + }, + "testList": { + "file": "/home/joel/projects/open-source/jsonql/packages/@jsonql/client/tests/fixtures/resolvers/query/test-list.js", + "description": "Just return a Hello world object", + "params": [], + "returns": [ + { + "type": [ + "object" + ], + "description": "key hello prop world" + } + ] + } + }, + "mutation": { + "plus": { + "file": "/home/joel/projects/open-source/jsonql/packages/@jsonql/client/tests/fixtures/resolvers/mutation/plus.js", + "description": false, + "params": [ + { + "type": [ + "object" + ], + "name": "payload", + "description": "the payload object", + "keys": [ + { + "type": [ + "string" + ], + "description": "required key a", + "name": "a", + "parent": "payload" + }, + { + "type": [ + "string" + ], + "description": "required key b", + "name": "b", + "parent": "payload" + } + ] + }, + { + "type": [ + "object" + ], + "name": "conditions", + "optional": true, + "defaultvalue": "{}", + "description": "optional" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "concat string of a + b;" + } + ] + } + }, + "auth": { + "validator": { + "file": "/home/joel/projects/open-source/jsonql/packages/@jsonql/client/tests/fixtures/resolvers/auth/validator.js", + "description": false, + "params": [ + { + "type": [ + "string" + ], + "name": "key", + "description": "for validation" + } + ], + "returns": [ + { + "type": [ + "boolean" + ], + "description": "true on success" + } + ] + } + }, + "timestamp": 1568257515, + "sourceType": "script" +} diff --git a/archived/http-client/tests/fixtures/contracts/tmp/public-contract.json b/archived/http-client/tests/fixtures/contracts/tmp/public-contract.json new file mode 100644 index 0000000000000000000000000000000000000000..d4d8e3b8819e3291783574bf5434b10836a47221 --- /dev/null +++ b/archived/http-client/tests/fixtures/contracts/tmp/public-contract.json @@ -0,0 +1,106 @@ +{ + "query": { + "helloWorld": { + "description": "This is the stock resolver for testing purpose", + "params": [], + "returns": [ + { + "type": "string", + "description": "stock message" + } + ] + }, + "getSomething": { + "description": "This is a new query that require parameters for testing", + "params": [ + { + "type": [ + "string" + ], + "name": "key", + "description": "key" + }, + { + "type": [ + "string" + ], + "name": "value", + "optional": true, + "defaultvalue": "'world'", + "description": "optional value" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "put key / value together into an object" + } + ] + }, + "testList": { + "description": "Just return a Hello world object", + "params": [], + "returns": [ + { + "type": [ + "object" + ], + "description": "key hello prop world" + } + ] + } + }, + "mutation": { + "plus": { + "description": false, + "params": [ + { + "type": [ + "object" + ], + "name": "payload", + "description": "the payload object", + "keys": [ + { + "type": [ + "string" + ], + "description": "required key a", + "name": "a", + "parent": "payload" + }, + { + "type": [ + "string" + ], + "description": "required key b", + "name": "b", + "parent": "payload" + } + ] + }, + { + "type": [ + "object" + ], + "name": "conditions", + "optional": true, + "defaultvalue": "{}", + "description": "optional" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "concat string of a + b;" + } + ] + } + }, + "auth": {}, + "timestamp": 1568257515 +} diff --git a/packages/@jsonql/http-client/tests/fixtures/dev.js b/archived/http-client/tests/fixtures/dev.js similarity index 100% rename from packages/@jsonql/http-client/tests/fixtures/dev.js rename to archived/http-client/tests/fixtures/dev.js diff --git a/packages/@jsonql/http-client/tests/fixtures/favicon.ico b/archived/http-client/tests/fixtures/favicon.ico similarity index 100% rename from packages/@jsonql/http-client/tests/fixtures/favicon.ico rename to archived/http-client/tests/fixtures/favicon.ico diff --git a/packages/@jsonql/http-client/tests/fixtures/helpers/setup-browser.js b/archived/http-client/tests/fixtures/helpers/setup-browser.js similarity index 100% rename from packages/@jsonql/http-client/tests/fixtures/helpers/setup-browser.js rename to archived/http-client/tests/fixtures/helpers/setup-browser.js diff --git a/packages/@jsonql/http-client/tests/fixtures/index.html b/archived/http-client/tests/fixtures/index.html similarity index 100% rename from packages/@jsonql/http-client/tests/fixtures/index.html rename to archived/http-client/tests/fixtures/index.html diff --git a/packages/@jsonql/http-client/tests/fixtures/keys/privateKey.pem b/archived/http-client/tests/fixtures/keys/privateKey.pem similarity index 100% rename from packages/@jsonql/http-client/tests/fixtures/keys/privateKey.pem rename to archived/http-client/tests/fixtures/keys/privateKey.pem diff --git a/packages/@jsonql/http-client/tests/fixtures/keys/publicKey.pem b/archived/http-client/tests/fixtures/keys/publicKey.pem similarity index 100% rename from packages/@jsonql/http-client/tests/fixtures/keys/publicKey.pem rename to archived/http-client/tests/fixtures/keys/publicKey.pem diff --git a/packages/@jsonql/http-client/tests/fixtures/obj.js b/archived/http-client/tests/fixtures/obj.js similarity index 100% rename from packages/@jsonql/http-client/tests/fixtures/obj.js rename to archived/http-client/tests/fixtures/obj.js diff --git a/packages/@jsonql/http-client/tests/fixtures/old-builds/rollup.example.js b/archived/http-client/tests/fixtures/old-builds/rollup.example.js similarity index 100% rename from packages/@jsonql/http-client/tests/fixtures/old-builds/rollup.example.js rename to archived/http-client/tests/fixtures/old-builds/rollup.example.js diff --git a/packages/@jsonql/http-client/tests/fixtures/old-builds/rollup.full.config.js b/archived/http-client/tests/fixtures/old-builds/rollup.full.config.js similarity index 100% rename from packages/@jsonql/http-client/tests/fixtures/old-builds/rollup.full.config.js rename to archived/http-client/tests/fixtures/old-builds/rollup.full.config.js diff --git a/packages/@jsonql/http-client/tests/fixtures/old-builds/rollup.test.config.js b/archived/http-client/tests/fixtures/old-builds/rollup.test.config.js similarity index 100% rename from packages/@jsonql/http-client/tests/fixtures/old-builds/rollup.test.config.js rename to archived/http-client/tests/fixtures/old-builds/rollup.test.config.js diff --git a/packages/@jsonql/http-client/tests/fixtures/options.json b/archived/http-client/tests/fixtures/options.json similarity index 100% rename from packages/@jsonql/http-client/tests/fixtures/options.json rename to archived/http-client/tests/fixtures/options.json diff --git a/packages/@jsonql/http-client/tests/fixtures/resolvers/auth/issuer.js b/archived/http-client/tests/fixtures/resolvers/auth/issuer.js similarity index 100% rename from packages/@jsonql/http-client/tests/fixtures/resolvers/auth/issuer.js rename to archived/http-client/tests/fixtures/resolvers/auth/issuer.js diff --git a/packages/@jsonql/http-client/tests/fixtures/resolvers/auth/validator.js b/archived/http-client/tests/fixtures/resolvers/auth/validator.js similarity index 100% rename from packages/@jsonql/http-client/tests/fixtures/resolvers/auth/validator.js rename to archived/http-client/tests/fixtures/resolvers/auth/validator.js diff --git a/packages/@jsonql/http-client/tests/fixtures/resolvers/mutation/plus.js b/archived/http-client/tests/fixtures/resolvers/mutation/plus.js similarity index 100% rename from packages/@jsonql/http-client/tests/fixtures/resolvers/mutation/plus.js rename to archived/http-client/tests/fixtures/resolvers/mutation/plus.js diff --git a/packages/@jsonql/http-client/tests/fixtures/resolvers/query/get-something.js b/archived/http-client/tests/fixtures/resolvers/query/get-something.js similarity index 100% rename from packages/@jsonql/http-client/tests/fixtures/resolvers/query/get-something.js rename to archived/http-client/tests/fixtures/resolvers/query/get-something.js diff --git a/packages/@jsonql/http-client/tests/fixtures/resolvers/query/test-list.js b/archived/http-client/tests/fixtures/resolvers/query/test-list.js similarity index 100% rename from packages/@jsonql/http-client/tests/fixtures/resolvers/query/test-list.js rename to archived/http-client/tests/fixtures/resolvers/query/test-list.js diff --git a/packages/@jsonql/http-client/tests/fixtures/run.js b/archived/http-client/tests/fixtures/run.js similarity index 100% rename from packages/@jsonql/http-client/tests/fixtures/run.js rename to archived/http-client/tests/fixtures/run.js diff --git a/packages/@jsonql/http-client/tests/fixtures/server.js b/archived/http-client/tests/fixtures/server.js similarity index 100% rename from packages/@jsonql/http-client/tests/fixtures/server.js rename to archived/http-client/tests/fixtures/server.js diff --git a/packages/@jsonql/http-client/tests/fn.test.js b/archived/http-client/tests/fn.test.js similarity index 100% rename from packages/@jsonql/http-client/tests/fn.test.js rename to archived/http-client/tests/fn.test.js diff --git a/packages/@jsonql/http-client/tests/qunit/run-qunit-setup.js b/archived/http-client/tests/qunit/run-qunit-setup.js similarity index 100% rename from packages/@jsonql/http-client/tests/qunit/run-qunit-setup.js rename to archived/http-client/tests/qunit/run-qunit-setup.js diff --git a/packages/@jsonql/http-client/tests/qunit/run-qunit.js b/archived/http-client/tests/qunit/run-qunit.js similarity index 100% rename from packages/@jsonql/http-client/tests/qunit/run-qunit.js rename to archived/http-client/tests/qunit/run-qunit.js diff --git a/packages/@jsonql/http-client/tests/qunit/tests/base-test.js b/archived/http-client/tests/qunit/tests/base-test.js similarity index 100% rename from packages/@jsonql/http-client/tests/qunit/tests/base-test.js rename to archived/http-client/tests/qunit/tests/base-test.js diff --git a/packages/@jsonql/http-client/tests/qunit/tests/static-test.js b/archived/http-client/tests/qunit/tests/static-test.js similarity index 100% rename from packages/@jsonql/http-client/tests/qunit/tests/static-test.js rename to archived/http-client/tests/qunit/tests/static-test.js diff --git a/packages/@jsonql/http-client/tests/qunit/webroot/index.html b/archived/http-client/tests/qunit/webroot/index.html similarity index 100% rename from packages/@jsonql/http-client/tests/qunit/webroot/index.html rename to archived/http-client/tests/qunit/webroot/index.html diff --git a/packages/@jsonql/http-client/tests/qunit/webroot/nb-qunit-helper.js b/archived/http-client/tests/qunit/webroot/nb-qunit-helper.js similarity index 100% rename from packages/@jsonql/http-client/tests/qunit/webroot/nb-qunit-helper.js rename to archived/http-client/tests/qunit/webroot/nb-qunit-helper.js diff --git a/packages/@jsonql/koa/Dockerfile b/archived/koa-old/Dockerfile similarity index 100% rename from packages/@jsonql/koa/Dockerfile rename to archived/koa-old/Dockerfile diff --git a/archived/koa-old/README.md b/archived/koa-old/README.md new file mode 100644 index 0000000000000000000000000000000000000000..5382033de5c28ae81ae6205675c38e9db8583085 --- /dev/null +++ b/archived/koa-old/README.md @@ -0,0 +1,13 @@ +# @jsonql/koa + +> This is the complete node server using Koa with jsonql-koa middleware and opitonal jsonql socket server plugin + +## Example + +Coming soon. + +--- + +Please check [jsonql.org](https://jsonql.js.org) for more information. + +NB & T1S diff --git a/packages/@jsonql/koa/docker-compose.yml b/archived/koa-old/docker-compose.yml similarity index 100% rename from packages/@jsonql/koa/docker-compose.yml rename to archived/koa-old/docker-compose.yml diff --git a/archived/koa-old/index.js b/archived/koa-old/index.js new file mode 100644 index 0000000000000000000000000000000000000000..bc32779c34929de9c15b7f0296c8e6910b8234c2 --- /dev/null +++ b/archived/koa-old/index.js @@ -0,0 +1,51 @@ +/** + * This is the main interface to export the middleware(s) + * we will take the config here and export array of middleware using koa-compose + */ +import fs from 'fs' +import { merge } from 'lodash' +import compose from 'koa-compose' +import { + coreMiddleware, + authMiddleware, + contractMiddleware, + helloMiddleware, + consoleMiddleware, + publicMethodMiddleware, + initMiddleware +} from './src/middlewares' +import { configCheck } from './src/options' +import { getDebug } from './src/utils' +const debug = getDebug('main') +// main +function jsonqlKoa(config = {}) { + // first check the config + const opts = configCheck(config) + debug('[jsonql-koa] init opts', opts) + // export + let middlewares = [ + initMiddleware(opts), + helloMiddleware(opts), + contractMiddleware(opts) + ] + // only available when enable it + if (config.enableWebConsole) { + middlewares.push(consoleMiddleware(opts)) + } + + if (opts.enableAuth) { + middlewares.push( + publicMethodMiddleware(opts), + authMiddleware(opts) + ) + } + middlewares.push( + coreMiddleware(opts) + ) + // finally + return compose(middlewares) +} + +export { + jsonqlKoa +} diff --git a/packages/@jsonql/koa/main.js b/archived/koa-old/main.js similarity index 100% rename from packages/@jsonql/koa/main.js rename to archived/koa-old/main.js diff --git a/archived/koa-old/package.json b/archived/koa-old/package.json new file mode 100644 index 0000000000000000000000000000000000000000..d26c989bdadf859045f40f4ee64f3f4d6269f8a3 --- /dev/null +++ b/archived/koa-old/package.json @@ -0,0 +1,97 @@ +{ + "name": "@jsonql/koa", + "version": "0.3.0", + "description": "jsonql Koa middleware", + "main": "main.js", + "module": "index.js", + "files": [ + "src", + "index.js", + "main.js" + ], + "scripts": { + "test": "ava --verbose", + "prepare": "npm run test", + "start": "node ./test/fixtures/start.js", + "test:debug": "DEBUG=jsonql* ava --verbose", + "coverage": "nyc ava --verbose", + "test:basic": "DEBUG=jsonql* ava ./tests/koa.test.js", + "test:notfound": "DEBUG=jsonql-koa* ava --verbose ./tests/resolverNotFound.test.js", + "test:es6": "DEBUG=jsonql-koa* ava --verbose ./tests/es6-module.test.js", + "test:jwt": "DEBUG=jsonql-koa*,jsonql-jwt* ava ./tests/jwt.test.js", + "test:jwt-auth": "DEBUG=jsonql-koa* ava ./tests/jwt-auth.test.js", + "test:fail": "ava ./tests/fail.test.js", + "test:contract": "DEBUG=jsonql-koa* ava ./tests/contractWithAuth.test.js", + "test:auth": "DEBUG=jsonql* ava ./tests/auth.test.js", + "test:error": "DEBUG=jsonql-koa* ava ./tests/resolverNotFound.test.js", + "test:config": "DEBUG=jsonql-* ava ./tests/config.test.js", + "test:throw": "DEBUG=jsonql-* ava ./tests/throw.test.js", + "test:gen": "DEBUG=jsonql* ava ./tests/contract.test.js", + "test:jsonp": "DEBUG=jsonql* ava --verbose ./tests/jsonp.test.js", + "test:chain": "DEBUG=jsonql* ava --verbose ./tests/chain-fn.test.js", + "test:clients": "DEBUG=jsonql* ava --verbose ./tests/node-client.test.js", + "web-console": "DEBUG=jsonql-koa*,jsonql-web-console* node ./tests/helpers/browser.js", + "contract": "node ./node_modules/jsonql-contract/cmd.js ./tests/fixtures/resolvers ./tests/fixtures/contracts" + }, + "keywords": [ + "jsonql", + "koa", + "server", + "socket", + "WebSocket", + "API" + ], + "author": "Joel Chu ", + "license": "ISC", + "repository": { + "type": "git", + "url": "git+ssh://git@gitee.com:to1source/jsonql.git" + }, + "bugs": { + "url": "https://gitee.com/to1source/jsonql/issues" + }, + "homepage": "jsonql.org", + "ava": { + "files": [ + "tests/*.test.js", + "!tests/helpers/*.*", + "!tests/fixtures/*.*" + ], + "require": [ + "esm" + ], + "cache": true, + "concurrency": 5, + "failFast": true, + "failWithoutAssertions": false, + "tap": false, + "compileEnhancements": false + }, + "dependencies": { + "debug": "^4.1.1", + "esm": "^3.2.25", + "fs-extra": "^8.1.0", + "jsonql-constants": "^1.8.3", + "jsonql-contract": "^1.7.12", + "jsonql-errors": "^1.1.3", + "jsonql-jwt": "^1.3.2", + "jsonql-node-client": "^1.1.9", + "jsonql-params-validator": "^1.4.11", + "jsonql-resolver": "^0.8.7", + "jsonql-utils": "^0.6.10", + "jsonql-web-console": "^0.4.3", + "koa": "^2.8.1", + "koa-bodyparser": "^4.2.1", + "koa-compose": "^4.1.0", + "koa-cors": "0.0.16", + "lodash": "^4.17.15" + }, + "devDependencies": { + "ava": "^2.4.0", + "jwt-decode": "^2.2.0", + "nyc": "^14.1.1", + "request": "^2.88.0", + "server-io-core": "^1.2.0", + "superkoa": "^1.0.3" + } +} diff --git a/packages/@jsonql/koa/src/contracts/contract-generator.js b/archived/koa-old/src/contracts/contract-generator.js similarity index 100% rename from packages/@jsonql/koa/src/contracts/contract-generator.js rename to archived/koa-old/src/contracts/contract-generator.js diff --git a/packages/@jsonql/koa/src/contracts/get-contract.js b/archived/koa-old/src/contracts/get-contract.js similarity index 100% rename from packages/@jsonql/koa/src/contracts/get-contract.js rename to archived/koa-old/src/contracts/get-contract.js diff --git a/packages/@jsonql/koa/src/contracts/helpers.js b/archived/koa-old/src/contracts/helpers.js similarity index 100% rename from packages/@jsonql/koa/src/contracts/helpers.js rename to archived/koa-old/src/contracts/helpers.js diff --git a/packages/@jsonql/koa/src/contracts/import.js b/archived/koa-old/src/contracts/import.js similarity index 100% rename from packages/@jsonql/koa/src/contracts/import.js rename to archived/koa-old/src/contracts/import.js diff --git a/packages/@jsonql/koa/src/contracts/index.js b/archived/koa-old/src/contracts/index.js similarity index 100% rename from packages/@jsonql/koa/src/contracts/index.js rename to archived/koa-old/src/contracts/index.js diff --git a/packages/@jsonql/koa/src/contracts/process-contract.js b/archived/koa-old/src/contracts/process-contract.js similarity index 100% rename from packages/@jsonql/koa/src/contracts/process-contract.js rename to archived/koa-old/src/contracts/process-contract.js diff --git a/packages/@jsonql/koa/src/contracts/run.js b/archived/koa-old/src/contracts/run.js similarity index 100% rename from packages/@jsonql/koa/src/contracts/run.js rename to archived/koa-old/src/contracts/run.js diff --git a/packages/@jsonql/koa/src/middlewares/auth-middleware.js b/archived/koa-old/src/middlewares/auth-middleware.js similarity index 100% rename from packages/@jsonql/koa/src/middlewares/auth-middleware.js rename to archived/koa-old/src/middlewares/auth-middleware.js diff --git a/packages/@jsonql/koa/src/middlewares/console-middleware.js b/archived/koa-old/src/middlewares/console-middleware.js similarity index 100% rename from packages/@jsonql/koa/src/middlewares/console-middleware.js rename to archived/koa-old/src/middlewares/console-middleware.js diff --git a/packages/@jsonql/koa/src/middlewares/contract-middleware.js b/archived/koa-old/src/middlewares/contract-middleware.js similarity index 100% rename from packages/@jsonql/koa/src/middlewares/contract-middleware.js rename to archived/koa-old/src/middlewares/contract-middleware.js diff --git a/packages/@jsonql/koa/src/middlewares/core-middleware.js b/archived/koa-old/src/middlewares/core-middleware.js similarity index 100% rename from packages/@jsonql/koa/src/middlewares/core-middleware.js rename to archived/koa-old/src/middlewares/core-middleware.js diff --git a/packages/@jsonql/koa/src/middlewares/hello-middleware.js b/archived/koa-old/src/middlewares/hello-middleware.js similarity index 100% rename from packages/@jsonql/koa/src/middlewares/hello-middleware.js rename to archived/koa-old/src/middlewares/hello-middleware.js diff --git a/packages/@jsonql/koa/src/middlewares/index.js b/archived/koa-old/src/middlewares/index.js similarity index 100% rename from packages/@jsonql/koa/src/middlewares/index.js rename to archived/koa-old/src/middlewares/index.js diff --git a/packages/@jsonql/koa/src/middlewares/init-middleware.js b/archived/koa-old/src/middlewares/init-middleware.js similarity index 100% rename from packages/@jsonql/koa/src/middlewares/init-middleware.js rename to archived/koa-old/src/middlewares/init-middleware.js diff --git a/packages/@jsonql/koa/src/middlewares/public-method-middleware.js b/archived/koa-old/src/middlewares/public-method-middleware.js similarity index 100% rename from packages/@jsonql/koa/src/middlewares/public-method-middleware.js rename to archived/koa-old/src/middlewares/public-method-middleware.js diff --git a/archived/koa-old/src/options/index.js b/archived/koa-old/src/options/index.js new file mode 100644 index 0000000000000000000000000000000000000000..d0d55fcc0820563496f16df10d04c9974daba34d --- /dev/null +++ b/archived/koa-old/src/options/index.js @@ -0,0 +1,79 @@ +// wrap all the options and method in one instead of all over the places +import { join, resolve } from 'path' +import fsx from 'fs-extra' +import _ from 'lodash' +import { checkConfig, isString } from 'jsonql-params-validator' +import { rsaPemKeys } from 'jsonql-jwt' + +import { appProps, constProps, jwtProcessKey } from './options' +import { isContract, chainFns, getDebug, inArray } from '../utils' +import { getContract } from '../contracts' +const debug = getDebug('config-check') + +/** + * break out from the applyAuthOptions because it's not suppose to be there + * @NOTE v1.3.8 change it to a fully functional interface + * @param {object} config configuration + * @return {object} with additional properties + */ +const applyGetContract = function(config) { + return _(config) + .chain() + .thru(config => { + const { contract } = config; + if (isContract(contract)) { + config.contract = contract; + return [true, config] + } + return [false, config] + }) + .thru(result => { + let [processed, config] = result + if (!processed) { + debug(`call initContract`) + // get resolve later inside the middleware + config.initContract = getContract(config) + } + return config; + }) + .thru(config => { + if (config.withPublicContract) { + debug(`call generate public contract`) + getContract(config, true) + } + return config; + }) + .value() +} + +/** + * we need an extra step to cache some of the auth related configuration data + * ASYNC AWAIT IS A FUCKING JOKE + * @param {object} config configuration + * @return {object} config with extra property + */ +const applyAuthOptions = function(config) { + if (config.enableAuth && config.useJwt && !isString(config.useJwt)) { + const { keysDir, publicKeyFileName, privateKeyFileName } = config; + const publicKeyPath = join(keysDir, publicKeyFileName) + const privateKeyPath = join(keysDir, privateKeyFileName) + if (fsx.existsSync(publicKeyPath) && fsx.existsSync(privateKeyPath)) { + config.publicKey = fsx.readFileSync(publicKeyPath) + config.privateKey = fsx.readFileSync(privateKeyPath) + } else { + // we only call here then resolve inside the init-middleware + config[jwtProcessKey] = rsaPemKeys(config.rsaModulusLength, config.keysDir) + } + } + return config; +} + +/** + * @param {object} config configuration supply by developer + * @return {object} configuration been checked + * @api public + */ +export function configCheck(config) { + const fn = chainFns(checkConfig, applyGetContract, applyAuthOptions) + return fn(config, appProps, constProps) +} diff --git a/archived/koa-old/src/options/options.js b/archived/koa-old/src/options/options.js new file mode 100644 index 0000000000000000000000000000000000000000..36c6afbccea6d6cd18feb79f532f77715a6bda45 --- /dev/null +++ b/archived/koa-old/src/options/options.js @@ -0,0 +1,113 @@ +import { join } from 'path' +import fs from 'fs' +import { + PUBLIC_KEY, + PRIVATE_KEY, + JSONQL_PATH, + CONTENT_TYPE, + DEFAULT_RESOLVER_DIR, + DEFAULT_CONTRACT_DIR, + CONTRACT_KEY_NAME, + ARRAY_TYPE, + BOOLEAN_TYPE, + STRING_TYPE, + NUMBER_TYPE, + OBJECT_TYPE, + ARGS_KEY, + TYPE_KEY, + ENUM_KEY, + CHECKER_KEY, + ACCEPTED_JS_TYPES, + CJS_TYPE, + ISSUER_NAME, + LOGOUT_NAME, + VALIDATOR_NAME, + RETURN_AS_JSON, + DEFAULT_KEYS_DIR, + DEFAULT_PUBLIC_KEY_FILE, + DEFAULT_PRIVATE_KEY_FILE, + RSA_MIN_MODULE_LEN +} from 'jsonql-constants' +import { + createConfig, + constructConfig +} from 'jsonql-params-validator' +// const NodeCache from '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() +// @TODO we need to create the same fn to clear out the options like I did in server-io-core +const constProps = { + __checked__: true, + contentType: CONTENT_TYPE, + contract: false, + initContract: false, + useDoc: true, + returnAs: RETURN_AS_JSON, + 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 + expired: createConfig(0, [NUMBER_TYPE]), + // allow user to change their auth type methods name + loginHandlerName: createConfig(ISSUER_NAME, [STRING_TYPE]), + logoutHandlerName: createConfig(LOGOUT_NAME, [STRING_TYPE]), + validatorHandlerName: createConfig(VALIDATOR_NAME, [STRING_TYPE, BOOLEAN_TYPE]), + // this flag will change many things + enableAuth: {[ARGS_KEY]: false, [TYPE_KEY]: BOOLEAN_TYPE}, + // from now on always turn this to on + useJwt: createConfig(true, [BOOLEAN_TYPE, STRING_TYPE]), + jwtTokenOption: createConfig(false, [BOOLEAN_TYPE, OBJECT_TYPE]), + // add in v1.3.0 + enableJsonp: createConfig(false, [BOOLEAN_TYPE]), + // show or hide the description field in the public contract + contractWithDesc: createConfig(false, [BOOLEAN_TYPE]), + // @1.3.4 whenever generate a contract will generate the public contract as well + withPublicContract: createConfig(true, [BOOLEAN_TYPE]), + keysDir: createConfig(join(dirname, DEFAULT_KEYS_DIR), [STRING_TYPE]), + publicKeyFileName: createConfig(DEFAULT_PUBLIC_KEY_FILE, [STRING_TYPE]), + privateKeyFileName: createConfig(DEFAULT_PRIVATE_KEY_FILE, [STRING_TYPE]), + rsaModulusLength: createConfig(RSA_MIN_MODULE_LEN, [NUMBER_TYPE]), + + jsonqlPath: {[ARGS_KEY]: ['/', JSONQL_PATH].join(''), [TYPE_KEY]: STRING_TYPE}, + resolverDir: {[ARGS_KEY]: join(dirname, DEFAULT_RESOLVER_DIR), [TYPE_KEY]: STRING_TYPE, [CHECKER_KEY]: fs.existsSync}, + // we don't really need to check if the contract directory exist or not, it will get created + contractDir: {[ARGS_KEY]: join(dirname, DEFAULT_CONTRACT_DIR), [TYPE_KEY]: STRING_TYPE}, + + contractKey: {[ARGS_KEY]: false, [TYPE_KEY]: [BOOLEAN_TYPE, STRING_TYPE]}, + contractKeyName: {[ARGS_KEY]: CONTRACT_KEY_NAME, [TYPE_KEY]: STRING_TYPE}, + + publicMethodDir: createConfig(PUBLIC_KEY, [STRING_TYPE]), + // just try this with string type first + privateMethodDir: constructConfig(PRIVATE_KEY, [STRING_TYPE], true), + + // new feature for v.1.1 release + // if the developer pass the nodeClient config then we will pre-generate the calling method + // for them. We expect them to named the client so it will be key:value pair + + enableWebConsole: {[ARGS_KEY]: false, [TYPE_KEY]: [BOOLEAN_TYPE, OBJECT_TYPE]}, // you need to actively enable this option to have the web console enable + 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 + 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 + autoCreateContract: {[ARGS_KEY]: true, [TYPE_KEY]: BOOLEAN_TYPE}, + buildContractOnStart: {[ARGS_KEY]: false, [TYPE_KEY]: BOOLEAN_TYPE}, // process.env.NODE_ENV === 'development', + keepLastContract: {[ARGS_KEY]: false, [TYPE_KEY]: BOOLEAN_TYPE}, // true keep last one, integer > 0 keep that number of files + validateReturns: {[ARGS_KEY]: false, [TYPE_KEY]: BOOLEAN_TYPE}, // reserved for use in the future + // For v1.5.0 to integrate the node-client + clientConfig: createConfig([], [ARRAY_TYPE]) +}; +const jwtProcessKey = 'INIT_JWT_KEYS' // just for id the promise call +export { + constProps, + appProps, + jwtProcessKey +} diff --git a/packages/@jsonql/koa/src/options/process-jwt-keys.js b/archived/koa-old/src/options/process-jwt-keys.js similarity index 100% rename from packages/@jsonql/koa/src/options/process-jwt-keys.js rename to archived/koa-old/src/options/process-jwt-keys.js diff --git a/packages/@jsonql/koa/src/utils/cache.js b/archived/koa-old/src/utils/cache.js similarity index 100% rename from packages/@jsonql/koa/src/utils/cache.js rename to archived/koa-old/src/utils/cache.js diff --git a/packages/@jsonql/koa/src/utils/index.js b/archived/koa-old/src/utils/index.js similarity index 100% rename from packages/@jsonql/koa/src/utils/index.js rename to archived/koa-old/src/utils/index.js diff --git a/packages/@jsonql/koa/src/utils/utils.js b/archived/koa-old/src/utils/utils.js similarity index 100% rename from packages/@jsonql/koa/src/utils/utils.js rename to archived/koa-old/src/utils/utils.js diff --git a/packages/@jsonql/koa/tests/auth.test.js b/archived/koa-old/tests/auth.test.js similarity index 100% rename from packages/@jsonql/koa/tests/auth.test.js rename to archived/koa-old/tests/auth.test.js diff --git a/packages/@jsonql/koa/tests/config.test.js b/archived/koa-old/tests/config.test.js similarity index 100% rename from packages/@jsonql/koa/tests/config.test.js rename to archived/koa-old/tests/config.test.js diff --git a/packages/@jsonql/koa/tests/contract.test.js b/archived/koa-old/tests/contract.test.js similarity index 100% rename from packages/@jsonql/koa/tests/contract.test.js rename to archived/koa-old/tests/contract.test.js diff --git a/packages/@jsonql/koa/tests/contractWithAuth.test.js b/archived/koa-old/tests/contractWithAuth.test.js similarity index 100% rename from packages/@jsonql/koa/tests/contractWithAuth.test.js rename to archived/koa-old/tests/contractWithAuth.test.js diff --git a/packages/@jsonql/koa/tests/es6-module.test.js b/archived/koa-old/tests/es6-module.test.js similarity index 100% rename from packages/@jsonql/koa/tests/es6-module.test.js rename to archived/koa-old/tests/es6-module.test.js diff --git a/packages/@jsonql/koa/tests/fail.test.js b/archived/koa-old/tests/fail.test.js similarity index 100% rename from packages/@jsonql/koa/tests/fail.test.js rename to archived/koa-old/tests/fail.test.js diff --git a/packages/@jsonql/koa/tests/fixtures/es/mutation/save-something.js b/archived/koa-old/tests/fixtures/es/mutation/save-something.js similarity index 100% rename from packages/@jsonql/koa/tests/fixtures/es/mutation/save-something.js rename to archived/koa-old/tests/fixtures/es/mutation/save-something.js diff --git a/packages/@jsonql/koa/tests/fixtures/es/query/get-something.js b/archived/koa-old/tests/fixtures/es/query/get-something.js similarity index 100% rename from packages/@jsonql/koa/tests/fixtures/es/query/get-something.js rename to archived/koa-old/tests/fixtures/es/query/get-something.js diff --git a/packages/@jsonql/koa/tests/fixtures/html/index.html b/archived/koa-old/tests/fixtures/html/index.html similarity index 100% rename from packages/@jsonql/koa/tests/fixtures/html/index.html rename to archived/koa-old/tests/fixtures/html/index.html diff --git a/packages/@jsonql/koa/tests/fixtures/keys/privateKey.pem b/archived/koa-old/tests/fixtures/keys/privateKey.pem similarity index 100% rename from packages/@jsonql/koa/tests/fixtures/keys/privateKey.pem rename to archived/koa-old/tests/fixtures/keys/privateKey.pem diff --git a/packages/@jsonql/koa/tests/fixtures/keys/publicKey.pem b/archived/koa-old/tests/fixtures/keys/publicKey.pem similarity index 100% rename from packages/@jsonql/koa/tests/fixtures/keys/publicKey.pem rename to archived/koa-old/tests/fixtures/keys/publicKey.pem diff --git a/packages/@jsonql/koa/tests/fixtures/options.js b/archived/koa-old/tests/fixtures/options.js similarity index 100% rename from packages/@jsonql/koa/tests/fixtures/options.js rename to archived/koa-old/tests/fixtures/options.js diff --git a/packages/@jsonql/koa/tests/fixtures/resolvers/auth/custom-login.js b/archived/koa-old/tests/fixtures/resolvers/auth/custom-login.js similarity index 100% rename from packages/@jsonql/koa/tests/fixtures/resolvers/auth/custom-login.js rename to archived/koa-old/tests/fixtures/resolvers/auth/custom-login.js diff --git a/packages/@jsonql/koa/tests/fixtures/resolvers/auth/custom-validator.js b/archived/koa-old/tests/fixtures/resolvers/auth/custom-validator.js similarity index 100% rename from packages/@jsonql/koa/tests/fixtures/resolvers/auth/custom-validator.js rename to archived/koa-old/tests/fixtures/resolvers/auth/custom-validator.js diff --git a/packages/@jsonql/koa/tests/fixtures/resolvers/auth/login.js b/archived/koa-old/tests/fixtures/resolvers/auth/login.js similarity index 100% rename from packages/@jsonql/koa/tests/fixtures/resolvers/auth/login.js rename to archived/koa-old/tests/fixtures/resolvers/auth/login.js diff --git a/packages/@jsonql/koa/tests/fixtures/resolvers/auth/logout.js b/archived/koa-old/tests/fixtures/resolvers/auth/logout.js similarity index 100% rename from packages/@jsonql/koa/tests/fixtures/resolvers/auth/logout.js rename to archived/koa-old/tests/fixtures/resolvers/auth/logout.js diff --git a/packages/@jsonql/koa/tests/fixtures/resolvers/auth/validator.js b/archived/koa-old/tests/fixtures/resolvers/auth/validator.js similarity index 100% rename from packages/@jsonql/koa/tests/fixtures/resolvers/auth/validator.js rename to archived/koa-old/tests/fixtures/resolvers/auth/validator.js diff --git a/packages/@jsonql/koa/tests/fixtures/resolvers/mutation/update-list.js b/archived/koa-old/tests/fixtures/resolvers/mutation/update-list.js similarity index 100% rename from packages/@jsonql/koa/tests/fixtures/resolvers/mutation/update-list.js rename to archived/koa-old/tests/fixtures/resolvers/mutation/update-list.js diff --git a/packages/@jsonql/koa/tests/fixtures/resolvers/mutation/update-ms-service.js b/archived/koa-old/tests/fixtures/resolvers/mutation/update-ms-service.js similarity index 100% rename from packages/@jsonql/koa/tests/fixtures/resolvers/mutation/update-ms-service.js rename to archived/koa-old/tests/fixtures/resolvers/mutation/update-ms-service.js diff --git a/packages/@jsonql/koa/tests/fixtures/resolvers/query/cause-error.js b/archived/koa-old/tests/fixtures/resolvers/query/cause-error.js similarity index 100% rename from packages/@jsonql/koa/tests/fixtures/resolvers/query/cause-error.js rename to archived/koa-old/tests/fixtures/resolvers/query/cause-error.js diff --git a/packages/@jsonql/koa/tests/fixtures/resolvers/query/get-user.js b/archived/koa-old/tests/fixtures/resolvers/query/get-user.js similarity index 100% rename from packages/@jsonql/koa/tests/fixtures/resolvers/query/get-user.js rename to archived/koa-old/tests/fixtures/resolvers/query/get-user.js diff --git a/packages/@jsonql/koa/tests/fixtures/resolvers/query/private/get-secret-msg.js b/archived/koa-old/tests/fixtures/resolvers/query/private/get-secret-msg.js similarity index 100% rename from packages/@jsonql/koa/tests/fixtures/resolvers/query/private/get-secret-msg.js rename to archived/koa-old/tests/fixtures/resolvers/query/private/get-secret-msg.js diff --git a/packages/@jsonql/koa/tests/fixtures/resolvers/query/public/always-available.js b/archived/koa-old/tests/fixtures/resolvers/query/public/always-available.js similarity index 100% rename from packages/@jsonql/koa/tests/fixtures/resolvers/query/public/always-available.js rename to archived/koa-old/tests/fixtures/resolvers/query/public/always-available.js diff --git a/packages/@jsonql/koa/tests/fixtures/resolvers/query/test-list.js b/archived/koa-old/tests/fixtures/resolvers/query/test-list.js similarity index 100% rename from packages/@jsonql/koa/tests/fixtures/resolvers/query/test-list.js rename to archived/koa-old/tests/fixtures/resolvers/query/test-list.js diff --git a/packages/@jsonql/koa/tests/fixtures/sub/resolver/mutation/sub-update-ms-service.js b/archived/koa-old/tests/fixtures/sub/resolver/mutation/sub-update-ms-service.js similarity index 100% rename from packages/@jsonql/koa/tests/fixtures/sub/resolver/mutation/sub-update-ms-service.js rename to archived/koa-old/tests/fixtures/sub/resolver/mutation/sub-update-ms-service.js diff --git a/packages/@jsonql/koa/tests/fixtures/sub/resolver/query/sub-ms-service.js b/archived/koa-old/tests/fixtures/sub/resolver/query/sub-ms-service.js similarity index 100% rename from packages/@jsonql/koa/tests/fixtures/sub/resolver/query/sub-ms-service.js rename to archived/koa-old/tests/fixtures/sub/resolver/query/sub-ms-service.js diff --git a/archived/koa-old/tests/fixtures/tmp/keys/privateKey.pem b/archived/koa-old/tests/fixtures/tmp/keys/privateKey.pem new file mode 100644 index 0000000000000000000000000000000000000000..355c77cab893f4cca3fae0e0df1557af80d380b1 --- /dev/null +++ b/archived/koa-old/tests/fixtures/tmp/keys/privateKey.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXAIBAAKBgQCxPfW1TU3GtnNCXIjEovIyI/Qg6A0aoDccG7SCujbee0ck/QEl +6sIR+KJU1KOcWKmT0TTC8bStJVn2WGwGP5gg5FNHWw92Iz5Uw3mpRGGn1aZ3rs6Q +tqi+LfxjgOagO5SGBYN+K9voFNIL72j0pXaY/70bFxzyxL5WhDJ446mXAQIDAQAB +AoGARjEFd5FvtbxXlPZUa5skU1sNuWJsnhjI+ma2a/cW97DWkf1oUP3RcZCHqRS0 +3pv2PEXjoThblx5trDOERE03D1ZECZ8/RQIkR25qmT72m5Yrf2yDPbM/jcmFlPBe +tSklPgPJoYxVFwT3sUVuplRbTh4evz5oyWfTPiCUjtMI6ykCQQDoPimyoxoGf+gk +VnQwlBi/U3zUpvDZvnSh7fe5Rt0/8JfPKveWO6W2ywr/T3sLgmB3mdZPnWxZqcG8 +oiN+3MabAkEAw194A/z6O07uKdHL5Wz9IzwZr4mWcsAt4QIHHMAecJRLjSEZS8zt +lEUpaDMVUWuvIy9jL+8GbA9z20jE5V1kkwJAK0EYpwq1mCxOYiYv8bRDf67e+wQ0 +q3lLY7VchAdswbHftFf+UN6/GHJsk+yLsDMSIHRoc9+QBIsXaDiSf9hCrQJAJ0Xr +pDGYQ4/MRE/OAuJzyD9ukmDAA3UqQ87aiyb7d3n37fi3UwtwvptghXevU1yoKhR+ +hcYwrkw05+Gq4shxTQJBAOUWJq3rhTl7aWSk2YfN7Tuv3g/WyC/B3dAOrmAA4gsN +KYzeS4CC1ITEkw6buGVSCP6YFJBeO3aU1Q1PfSW2ULI= +-----END RSA PRIVATE KEY----- diff --git a/archived/koa-old/tests/fixtures/tmp/keys/publicKey.pem b/archived/koa-old/tests/fixtures/tmp/keys/publicKey.pem new file mode 100644 index 0000000000000000000000000000000000000000..9b5fd3849167d2663f71e85052a8a1813e7e29d5 --- /dev/null +++ b/archived/koa-old/tests/fixtures/tmp/keys/publicKey.pem @@ -0,0 +1,6 @@ +-----BEGIN PUBLIC KEY----- +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCxPfW1TU3GtnNCXIjEovIyI/Qg +6A0aoDccG7SCujbee0ck/QEl6sIR+KJU1KOcWKmT0TTC8bStJVn2WGwGP5gg5FNH +Ww92Iz5Uw3mpRGGn1aZ3rs6Qtqi+LfxjgOagO5SGBYN+K9voFNIL72j0pXaY/70b +FxzyxL5WhDJ446mXAQIDAQAB +-----END PUBLIC KEY----- diff --git a/packages/@jsonql/koa/tests/fixtures/unused/errors-handler-middleware.js b/archived/koa-old/tests/fixtures/unused/errors-handler-middleware.js similarity index 100% rename from packages/@jsonql/koa/tests/fixtures/unused/errors-handler-middleware.js rename to archived/koa-old/tests/fixtures/unused/errors-handler-middleware.js diff --git a/packages/@jsonql/koa/tests/helpers/browser.js b/archived/koa-old/tests/helpers/browser.js similarity index 100% rename from packages/@jsonql/koa/tests/helpers/browser.js rename to archived/koa-old/tests/helpers/browser.js diff --git a/packages/@jsonql/koa/tests/helpers/hello.js b/archived/koa-old/tests/helpers/hello.js similarity index 100% rename from packages/@jsonql/koa/tests/helpers/hello.js rename to archived/koa-old/tests/helpers/hello.js diff --git a/packages/@jsonql/koa/tests/helpers/server.js b/archived/koa-old/tests/helpers/server.js similarity index 100% rename from packages/@jsonql/koa/tests/helpers/server.js rename to archived/koa-old/tests/helpers/server.js diff --git a/packages/@jsonql/koa/tests/helpers/sub-server.js b/archived/koa-old/tests/helpers/sub-server.js similarity index 100% rename from packages/@jsonql/koa/tests/helpers/sub-server.js rename to archived/koa-old/tests/helpers/sub-server.js diff --git a/packages/@jsonql/koa/tests/jsonp.test.js b/archived/koa-old/tests/jsonp.test.js similarity index 100% rename from packages/@jsonql/koa/tests/jsonp.test.js rename to archived/koa-old/tests/jsonp.test.js diff --git a/packages/@jsonql/koa/tests/jwt-auth.test.js b/archived/koa-old/tests/jwt-auth.test.js similarity index 100% rename from packages/@jsonql/koa/tests/jwt-auth.test.js rename to archived/koa-old/tests/jwt-auth.test.js diff --git a/packages/@jsonql/koa/tests/jwt.test.js b/archived/koa-old/tests/jwt.test.js similarity index 100% rename from packages/@jsonql/koa/tests/jwt.test.js rename to archived/koa-old/tests/jwt.test.js diff --git a/packages/@jsonql/koa/tests/koa.test.js b/archived/koa-old/tests/koa.test.js similarity index 100% rename from packages/@jsonql/koa/tests/koa.test.js rename to archived/koa-old/tests/koa.test.js diff --git a/packages/@jsonql/koa/tests/node-client.donttest.js b/archived/koa-old/tests/node-client.donttest.js similarity index 100% rename from packages/@jsonql/koa/tests/node-client.donttest.js rename to archived/koa-old/tests/node-client.donttest.js diff --git a/packages/@jsonql/koa/tests/resolverNotFound.test.js b/archived/koa-old/tests/resolverNotFound.test.js similarity index 100% rename from packages/@jsonql/koa/tests/resolverNotFound.test.js rename to archived/koa-old/tests/resolverNotFound.test.js diff --git a/packages/@jsonql/koa/tests/throw.test.js b/archived/koa-old/tests/throw.test.js similarity index 100% rename from packages/@jsonql/koa/tests/throw.test.js rename to archived/koa-old/tests/throw.test.js diff --git a/packages/@jsonql/koa/ts/README.md b/archived/koa-old/ts/README.md similarity index 100% rename from packages/@jsonql/koa/ts/README.md rename to archived/koa-old/ts/README.md diff --git a/packages/@jsonql/client/tests/fixtures/start-server.js b/packages/@jsonql/client/tests/fixtures/start-server.js new file mode 100644 index 0000000000000000000000000000000000000000..c5deab5ff22908d318ccafedb6f120b33e63f5c8 --- /dev/null +++ b/packages/@jsonql/client/tests/fixtures/start-server.js @@ -0,0 +1,3 @@ +const serverIo = require('server-io-core') +const jsonqlKoa = require('jsonql-koa') +const jsonqlWsServer = require('jsonql-ws-server') diff --git a/packages/@jsonql/koa/README.md b/packages/@jsonql/koa/README.md index 43d59f6460cc94e24bd77ccab2102b8d76b08adc..10b65a9f3a57449190077c204cfeaa1186f0a4bd 100644 --- a/packages/@jsonql/koa/README.md +++ b/packages/@jsonql/koa/README.md @@ -1,9 +1,18 @@ -# @jsonql/koa +# jsonql-node-server -> This is the jsonql middleware previously published as jsonql-koa, and completely rewritten with ES6 +This is an all in one setup to have your jsonql API server setup in no time. -Please check [jsonql.org](https://jsonql.js.org) for more information. +It includes: + +1. Koa +2. bodyparser, cors middleware +3. jsonql-koa middleware +4. jsonql-ws-server + +## Configuration + +TBC --- -NB & T1S +MIT (c) 2019 NEWBRAN LTD / TO1SOURCE CN diff --git a/packages/@jsonql/koa/cli.js b/packages/@jsonql/koa/cli.js new file mode 100644 index 0000000000000000000000000000000000000000..fe5dd97b21ceae8b8e95f64182288b8c448abdd6 --- /dev/null +++ b/packages/@jsonql/koa/cli.js @@ -0,0 +1,43 @@ +#!/usr/bin/env node +// new cli interface for jsonql Koa server +// this interface only accept on param --config +// and it search for a js or json file to import config +// if it's not found then use all the default options +const { version } = require('./package.json') +const jsonqlKoaServer = require('./index') +const { join, extname } = require('path') +const fsx = require('fs-extra') +const debug = require('debug')('jsonql-koa:cli') +const argv = require('yargs').argv +let config = {} + +if (argv._.length) { + const configFile = argv._[0] + if (fsx.existsSync(configFile)) { + // if it's json + const ext = extname(configFile).toLowerCase() + switch(ext) { + case '.json': + config = fsx.readJsonSync(configFile) + break; + case '.js': + config = require(configFile) + break; + default: + console.error(`Can not use the supplied config file, only support js or json, but got: ${ext}`) + } + } else { + console.error(`config file can not be found in: ${configFile}`) + } +} + +jsonqlKoaServer(config) + +/* +require('yargs') + .option('config', { + alias: 'c', + describe: 'Path to configuration file' + }) + .argv +*/ diff --git a/packages/@jsonql/koa/index.js b/packages/@jsonql/koa/index.js index bc32779c34929de9c15b7f0296c8e6910b8234c2..a6160945fcc0279e029c0896d934ee681cf19f5c 100644 --- a/packages/@jsonql/koa/index.js +++ b/packages/@jsonql/koa/index.js @@ -1,51 +1,20 @@ +// main +const debug = require('debug')('jsonql-koa:main') + /** - * This is the main interface to export the middleware(s) - * we will take the config here and export array of middleware using koa-compose + * @param {object} config options + * @return {object} with several method to control the server */ -import fs from 'fs' -import { merge } from 'lodash' -import compose from 'koa-compose' -import { - coreMiddleware, - authMiddleware, - contractMiddleware, - helloMiddleware, - consoleMiddleware, - publicMethodMiddleware, - initMiddleware -} from './src/middlewares' -import { configCheck } from './src/options' -import { getDebug } from './src/utils' -const debug = getDebug('main') -// main -function jsonqlKoa(config = {}) { - // first check the config - const opts = configCheck(config) - debug('[jsonql-koa] init opts', opts) - // export - let middlewares = [ - initMiddleware(opts), - helloMiddleware(opts), - contractMiddleware(opts) - ] - // only available when enable it - if (config.enableWebConsole) { - middlewares.push(consoleMiddleware(opts)) - } +module.exports = function(config, middlewares = []) { - if (opts.enableAuth) { - middlewares.push( - publicMethodMiddleware(opts), - authMiddleware(opts) - ) - } - middlewares.push( - coreMiddleware(opts) - ) - // finally - return compose(middlewares) -} + debug('config', config) + + return { + start: () => { -export { - jsonqlKoa + }, + stop: () => { + + } + } } diff --git a/packages/@jsonql/koa/package.json b/packages/@jsonql/koa/package.json index d26c989bdadf859045f40f4ee64f3f4d6269f8a3..daba2a026b7eae71976cec68dbf40ded4d0b4985 100644 --- a/packages/@jsonql/koa/package.json +++ b/packages/@jsonql/koa/package.json @@ -1,65 +1,41 @@ { "name": "@jsonql/koa", - "version": "0.3.0", - "description": "jsonql Koa middleware", - "main": "main.js", - "module": "index.js", - "files": [ - "src", - "index.js", - "main.js" - ], + "version": "0.4.0", + "description": "This is the all in one package to start your jsonql project with Koa, jsonql-koa, jsonql-ws-server and more", + "main": "index.js", "scripts": { "test": "ava --verbose", - "prepare": "npm run test", - "start": "node ./test/fixtures/start.js", - "test:debug": "DEBUG=jsonql* ava --verbose", - "coverage": "nyc ava --verbose", - "test:basic": "DEBUG=jsonql* ava ./tests/koa.test.js", - "test:notfound": "DEBUG=jsonql-koa* ava --verbose ./tests/resolverNotFound.test.js", - "test:es6": "DEBUG=jsonql-koa* ava --verbose ./tests/es6-module.test.js", - "test:jwt": "DEBUG=jsonql-koa*,jsonql-jwt* ava ./tests/jwt.test.js", - "test:jwt-auth": "DEBUG=jsonql-koa* ava ./tests/jwt-auth.test.js", - "test:fail": "ava ./tests/fail.test.js", - "test:contract": "DEBUG=jsonql-koa* ava ./tests/contractWithAuth.test.js", - "test:auth": "DEBUG=jsonql* ava ./tests/auth.test.js", - "test:error": "DEBUG=jsonql-koa* ava ./tests/resolverNotFound.test.js", - "test:config": "DEBUG=jsonql-* ava ./tests/config.test.js", - "test:throw": "DEBUG=jsonql-* ava ./tests/throw.test.js", - "test:gen": "DEBUG=jsonql* ava ./tests/contract.test.js", - "test:jsonp": "DEBUG=jsonql* ava --verbose ./tests/jsonp.test.js", - "test:chain": "DEBUG=jsonql* ava --verbose ./tests/chain-fn.test.js", - "test:clients": "DEBUG=jsonql* ava --verbose ./tests/node-client.test.js", - "web-console": "DEBUG=jsonql-koa*,jsonql-web-console* node ./tests/helpers/browser.js", - "contract": "node ./node_modules/jsonql-contract/cmd.js ./tests/fixtures/resolvers ./tests/fixtures/contracts" + "test:cli": "DEBUG=jsonql-koa* node ./cli.js" }, "keywords": [ "jsonql", + "jsonql-koa", "koa", - "server", - "socket", - "WebSocket", - "API" + "node", + "jsonql-ws-server", + "socket.io", + "Web", + "Socket", + "WebSocket" ], "author": "Joel Chu ", - "license": "ISC", + "license": "MIT", + "devDependencies": { + "ava": "^2.4.0", + "debug": "^4.1.1", + "nyc": "^14.1.1", + "superkoa": "^1.0.3" + }, "repository": { "type": "git", "url": "git+ssh://git@gitee.com:to1source/jsonql.git" }, - "bugs": { - "url": "https://gitee.com/to1source/jsonql/issues" - }, - "homepage": "jsonql.org", "ava": { "files": [ "tests/*.test.js", "!tests/helpers/*.*", "!tests/fixtures/*.*" ], - "require": [ - "esm" - ], "cache": true, "concurrency": 5, "failFast": true, @@ -67,31 +43,21 @@ "tap": false, "compileEnhancements": false }, + "engine": { + "node": ">=8" + }, "dependencies": { - "debug": "^4.1.1", - "esm": "^3.2.25", "fs-extra": "^8.1.0", - "jsonql-constants": "^1.8.3", - "jsonql-contract": "^1.7.12", - "jsonql-errors": "^1.1.3", - "jsonql-jwt": "^1.3.2", - "jsonql-node-client": "^1.1.9", - "jsonql-params-validator": "^1.4.11", - "jsonql-resolver": "^0.8.7", - "jsonql-utils": "^0.6.10", - "jsonql-web-console": "^0.4.3", - "koa": "^2.8.1", + "jsonql-koa": "^1.3.10", + "koa": "^2.11.0", "koa-bodyparser": "^4.2.1", - "koa-compose": "^4.1.0", "koa-cors": "0.0.16", - "lodash": "^4.17.15" + "yargs": "^14.2.0" }, - "devDependencies": { - "ava": "^2.4.0", - "jwt-decode": "^2.2.0", - "nyc": "^14.1.1", - "request": "^2.88.0", - "server-io-core": "^1.2.0", - "superkoa": "^1.0.3" + "optionalDependencies": { + "jsonql-ws-server": "^1.3.4" + }, + "bin": { + "jsonql-koa-cli": "./cli.js" } } diff --git a/packages/@jsonql/koa/src/get-socket-server.js b/packages/@jsonql/koa/src/get-socket-server.js new file mode 100644 index 0000000000000000000000000000000000000000..0dc7ad6934be0a520a91960d53635e327a4d44d1 --- /dev/null +++ b/packages/@jsonql/koa/src/get-socket-server.js @@ -0,0 +1,25 @@ +// just wrap this in one method +const { JS_WS_NAME, JS_WS_SOCKET_IO_NAME, JS_PRIMUS_NAME } = require('jsonql-constants') + +/** + * @param {object} config configuration + * @return {*} false when not found or throw Error when module not found + */ +function getSocketServer(config) { + let wsServer; + if (config.serverType) { + switch (config.serverType) { + case JS_WS_NAME: + wsServer = require('jsonql-ws-server') + break; + case JS_WS_SOCKET_IO_NAME: + case JS_PRIMUS_NAME: + default: + throw new Error(`Not support ${config.serverType} at the moment!`) + } + return wsServer(config) + } + return false; +} + +module.exports = { getSocketServer } diff --git a/packages/@jsonql/koa/src/index.js b/packages/@jsonql/koa/src/index.js new file mode 100644 index 0000000000000000000000000000000000000000..6a886a3422e79ec81a6e5c6acc87c9980d308e23 --- /dev/null +++ b/packages/@jsonql/koa/src/index.js @@ -0,0 +1,37 @@ +// main export for set up the server +const http = require('http') +const Koa = require('koa') +const bodyparser = require('koa-bodyparser') +const cors = require('koa-cors') +const contractApi = require('jsonql-koa/contract') +const jsonqlKoa = require('jsonql-koa') +const getSocketServer = require('./get-socket-server') + +/** + * @param {object} config configuration + * @param {array} middlewares what it said + * @return {object} see below for detail + */ +function initServer(config, middlewares) { + const app = new Koa() + // apply default middlewares + app.use(bodyparser()) + app.use(cors()) + // init jsonqlKoa + app.use(jsonqlKoa(config)) + // if any + middlewares.forEach(middleware => { + app.use(middleware) + }) + + const server = http.createServer(app.callback()) + + const ws = jsonqlWsServer(config, server) + // return it + return { + ws, + server + } +} + +module.exports = { initServer } diff --git a/packages/@jsonql/koa/src/options/index.js b/packages/@jsonql/koa/src/options/index.js index d0d55fcc0820563496f16df10d04c9974daba34d..a69bf15f8fa407cd433806f4620f422b05e9c03b 100644 --- a/packages/@jsonql/koa/src/options/index.js +++ b/packages/@jsonql/koa/src/options/index.js @@ -1,79 +1,6 @@ -// wrap all the options and method in one instead of all over the places -import { join, resolve } from 'path' -import fsx from 'fs-extra' -import _ from 'lodash' -import { checkConfig, isString } from 'jsonql-params-validator' -import { rsaPemKeys } from 'jsonql-jwt' +const { checkOptions } = require('jsonql-params-valiator') +const { options } = require('./options') -import { appProps, constProps, jwtProcessKey } from './options' -import { isContract, chainFns, getDebug, inArray } from '../utils' -import { getContract } from '../contracts' -const debug = getDebug('config-check') - -/** - * break out from the applyAuthOptions because it's not suppose to be there - * @NOTE v1.3.8 change it to a fully functional interface - * @param {object} config configuration - * @return {object} with additional properties - */ -const applyGetContract = function(config) { - return _(config) - .chain() - .thru(config => { - const { contract } = config; - if (isContract(contract)) { - config.contract = contract; - return [true, config] - } - return [false, config] - }) - .thru(result => { - let [processed, config] = result - if (!processed) { - debug(`call initContract`) - // get resolve later inside the middleware - config.initContract = getContract(config) - } - return config; - }) - .thru(config => { - if (config.withPublicContract) { - debug(`call generate public contract`) - getContract(config, true) - } - return config; - }) - .value() -} - -/** - * we need an extra step to cache some of the auth related configuration data - * ASYNC AWAIT IS A FUCKING JOKE - * @param {object} config configuration - * @return {object} config with extra property - */ -const applyAuthOptions = function(config) { - if (config.enableAuth && config.useJwt && !isString(config.useJwt)) { - const { keysDir, publicKeyFileName, privateKeyFileName } = config; - const publicKeyPath = join(keysDir, publicKeyFileName) - const privateKeyPath = join(keysDir, privateKeyFileName) - if (fsx.existsSync(publicKeyPath) && fsx.existsSync(privateKeyPath)) { - config.publicKey = fsx.readFileSync(publicKeyPath) - config.privateKey = fsx.readFileSync(privateKeyPath) - } else { - // we only call here then resolve inside the init-middleware - config[jwtProcessKey] = rsaPemKeys(config.rsaModulusLength, config.keysDir) - } - } - return config; -} - -/** - * @param {object} config configuration supply by developer - * @return {object} configuration been checked - * @api public - */ -export function configCheck(config) { - const fn = chainFns(checkConfig, applyGetContract, applyAuthOptions) - return fn(config, appProps, constProps) +module.exports = function(config) { + return checkOptions(config, options) } diff --git a/packages/@jsonql/koa/src/options/options.js b/packages/@jsonql/koa/src/options/options.js index 36c6afbccea6d6cd18feb79f532f77715a6bda45..2b69ff0dd8c05ca4dfe48c6fa712bc08a4b8c07a 100644 --- a/packages/@jsonql/koa/src/options/options.js +++ b/packages/@jsonql/koa/src/options/options.js @@ -1,113 +1,15 @@ -import { join } from 'path' -import fs from 'fs' -import { - PUBLIC_KEY, - PRIVATE_KEY, - JSONQL_PATH, - CONTENT_TYPE, - DEFAULT_RESOLVER_DIR, - DEFAULT_CONTRACT_DIR, - CONTRACT_KEY_NAME, - ARRAY_TYPE, - BOOLEAN_TYPE, - STRING_TYPE, - NUMBER_TYPE, - OBJECT_TYPE, - ARGS_KEY, - TYPE_KEY, - ENUM_KEY, - CHECKER_KEY, - ACCEPTED_JS_TYPES, - CJS_TYPE, - ISSUER_NAME, - LOGOUT_NAME, - VALIDATOR_NAME, - RETURN_AS_JSON, - DEFAULT_KEYS_DIR, - DEFAULT_PUBLIC_KEY_FILE, - DEFAULT_PRIVATE_KEY_FILE, - RSA_MIN_MODULE_LEN -} from 'jsonql-constants' -import { - createConfig, - constructConfig -} from 'jsonql-params-validator' -// const NodeCache from '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() -// @TODO we need to create the same fn to clear out the options like I did in server-io-core -const constProps = { - __checked__: true, - contentType: CONTENT_TYPE, - contract: false, - initContract: false, - useDoc: true, - returnAs: RETURN_AS_JSON, - 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 - expired: createConfig(0, [NUMBER_TYPE]), - // allow user to change their auth type methods name - loginHandlerName: createConfig(ISSUER_NAME, [STRING_TYPE]), - logoutHandlerName: createConfig(LOGOUT_NAME, [STRING_TYPE]), - validatorHandlerName: createConfig(VALIDATOR_NAME, [STRING_TYPE, BOOLEAN_TYPE]), - // this flag will change many things - enableAuth: {[ARGS_KEY]: false, [TYPE_KEY]: BOOLEAN_TYPE}, - // from now on always turn this to on - useJwt: createConfig(true, [BOOLEAN_TYPE, STRING_TYPE]), - jwtTokenOption: createConfig(false, [BOOLEAN_TYPE, OBJECT_TYPE]), - // add in v1.3.0 - enableJsonp: createConfig(false, [BOOLEAN_TYPE]), - // show or hide the description field in the public contract - contractWithDesc: createConfig(false, [BOOLEAN_TYPE]), - // @1.3.4 whenever generate a contract will generate the public contract as well - withPublicContract: createConfig(true, [BOOLEAN_TYPE]), - keysDir: createConfig(join(dirname, DEFAULT_KEYS_DIR), [STRING_TYPE]), - publicKeyFileName: createConfig(DEFAULT_PUBLIC_KEY_FILE, [STRING_TYPE]), - privateKeyFileName: createConfig(DEFAULT_PRIVATE_KEY_FILE, [STRING_TYPE]), - rsaModulusLength: createConfig(RSA_MIN_MODULE_LEN, [NUMBER_TYPE]), - - jsonqlPath: {[ARGS_KEY]: ['/', JSONQL_PATH].join(''), [TYPE_KEY]: STRING_TYPE}, - resolverDir: {[ARGS_KEY]: join(dirname, DEFAULT_RESOLVER_DIR), [TYPE_KEY]: STRING_TYPE, [CHECKER_KEY]: fs.existsSync}, - // we don't really need to check if the contract directory exist or not, it will get created - contractDir: {[ARGS_KEY]: join(dirname, DEFAULT_CONTRACT_DIR), [TYPE_KEY]: STRING_TYPE}, +const { createConfig } = require('jsonql-params-validator') +const { + BOOLEAN_TYPE +} = require('jsonql-constants') - contractKey: {[ARGS_KEY]: false, [TYPE_KEY]: [BOOLEAN_TYPE, STRING_TYPE]}, - contractKeyName: {[ARGS_KEY]: CONTRACT_KEY_NAME, [TYPE_KEY]: STRING_TYPE}, - publicMethodDir: createConfig(PUBLIC_KEY, [STRING_TYPE]), - // just try this with string type first - privateMethodDir: constructConfig(PRIVATE_KEY, [STRING_TYPE], true), - - // new feature for v.1.1 release - // if the developer pass the nodeClient config then we will pre-generate the calling method - // for them. We expect them to named the client so it will be key:value pair - - enableWebConsole: {[ARGS_KEY]: false, [TYPE_KEY]: [BOOLEAN_TYPE, OBJECT_TYPE]}, // you need to actively enable this option to have the web console enable - jsType: {[ARGS_KEY]: CJS_TYPE, [TYPE_KEY]: STRING_TYPE, [ENUM_KEY]: ACCEPTED_JS_TYPES}, +const options = { + autoStart: createConfig(true, [BOOLEAN_TYPE]), + port: createConfig() +} - // undecided properties - // 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 - autoCreateContract: {[ARGS_KEY]: true, [TYPE_KEY]: BOOLEAN_TYPE}, - buildContractOnStart: {[ARGS_KEY]: false, [TYPE_KEY]: BOOLEAN_TYPE}, // process.env.NODE_ENV === 'development', - keepLastContract: {[ARGS_KEY]: false, [TYPE_KEY]: BOOLEAN_TYPE}, // true keep last one, integer > 0 keep that number of files - validateReturns: {[ARGS_KEY]: false, [TYPE_KEY]: BOOLEAN_TYPE}, // reserved for use in the future - // For v1.5.0 to integrate the node-client - clientConfig: createConfig([], [ARRAY_TYPE]) -}; -const jwtProcessKey = 'INIT_JWT_KEYS' // just for id the promise call -export { - constProps, - appProps, - jwtProcessKey +module.exports = { + options } diff --git a/packages/@jsonql/koa/tests/fixtures/test-config.js b/packages/@jsonql/koa/tests/fixtures/test-config.js new file mode 100644 index 0000000000000000000000000000000000000000..a548948076874d07ce0b25ee3315a77f14a832b5 --- /dev/null +++ b/packages/@jsonql/koa/tests/fixtures/test-config.js @@ -0,0 +1,3 @@ +module.export = { + +} diff --git a/packages/@jsonql/koa/tests/fixtures/test-config.json b/packages/@jsonql/koa/tests/fixtures/test-config.json new file mode 100644 index 0000000000000000000000000000000000000000..179713338060e6468a8136a7a2977f84748e22c6 --- /dev/null +++ b/packages/@jsonql/koa/tests/fixtures/test-config.json @@ -0,0 +1,3 @@ +{ + +} diff --git a/packages/constants/README.md b/packages/constants/README.md index 01d8ecdee14d489a3fb929b8cc05e96abbdb990e..4949f51da2e8564adb0ab1fbd7b8d2d1a28a50ad 100755 --- a/packages/constants/README.md +++ b/packages/constants/README.md @@ -141,6 +141,7 @@ non-javascript to develop your tool. You can also use the included `constants.js - SUCCESS_STATUS - FORBIDDEN_STATUS - NOT_FOUND_STATUS +- DEFAULT_PORT_NUM --- diff --git a/packages/constants/constants.json b/packages/constants/constants.json index 8f4f5a1b1d9904a002393fe095e21e80bab8da72..bb6d6e9a949d150c0ab3752b19172d32afa29b39 100644 --- a/packages/constants/constants.json +++ b/packages/constants/constants.json @@ -79,8 +79,7 @@ "TS_TYPE": "ts", "ACCEPTED_JS_TYPES": [ "cjs", - "es", - "ts" + "es" ], "OR_SEPERATOR": "|", "STRING_TYPE": "string", @@ -181,5 +180,6 @@ "DEFAULT_PRIVATE_KEY_FILE": "privateKey.pem", "SUCCESS_STATUS": 200, "FORBIDDEN_STATUS": 403, - "NOT_FOUND_STATUS": 404 + "NOT_FOUND_STATUS": 404, + "DEFAULT_PORT_NUM": 6557 } diff --git a/packages/constants/main.js b/packages/constants/main.js index 90f543f03b8797dec7135ebb714978464786b733..9d9576e22e93d1a72f0e297f8c3e178cc1fc3dda 100644 --- a/packages/constants/main.js +++ b/packages/constants/main.js @@ -79,8 +79,7 @@ module.exports = { "TS_TYPE": "ts", "ACCEPTED_JS_TYPES": [ "cjs", - "es", - "ts" + "es" ], "OR_SEPERATOR": "|", "STRING_TYPE": "string", @@ -181,5 +180,6 @@ module.exports = { "DEFAULT_PRIVATE_KEY_FILE": "privateKey.pem", "SUCCESS_STATUS": 200, "FORBIDDEN_STATUS": 403, - "NOT_FOUND_STATUS": 404 + "NOT_FOUND_STATUS": 404, + "DEFAULT_PORT_NUM": 6557 } \ No newline at end of file diff --git a/packages/constants/module.js b/packages/constants/module.js index 7798223d6cb9daecb28310a5f5dcbbb34fecaf3d..a7737f8cb36147c1fc04d73f3926e399fa725270 100644 --- a/packages/constants/module.js +++ b/packages/constants/module.js @@ -91,7 +91,7 @@ export const DEFAULT_KEYS_DIR = 'keys'; export const CJS_TYPE = 'cjs'; export const ES_TYPE = 'es'; export const TS_TYPE = 'ts'; -export const ACCEPTED_JS_TYPES = [CJS_TYPE, ES_TYPE, TS_TYPE]; +export const ACCEPTED_JS_TYPES = [CJS_TYPE, ES_TYPE]; // not accept this TS_TYPE at the moment export const OR_SEPERATOR = '|'; @@ -190,3 +190,5 @@ export const DEFAULT_PRIVATE_KEY_FILE = [PRIVATE_KEY_NAME, PEM_EXT].join('.') export const SUCCESS_STATUS = 200; export const FORBIDDEN_STATUS = 403; export const NOT_FOUND_STATUS = 404; +// just whatever +export const DEFAULT_PORT_NUM = 6557; diff --git a/packages/constants/package.json b/packages/constants/package.json index 2a63a462b3f8492209cb8a24952378bdc963907f..c5e3c1900d020f979298929a476da7e816fa84b1 100755 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-constants", - "version": "1.8.8", + "version": "1.8.9", "description": "All the share constants for json:ql tools", "main": "main.js", "module": "module.js", diff --git a/packages/express/README.md b/packages/express/README.md new file mode 100644 index 0000000000000000000000000000000000000000..dfe43ad6146d92d22ef00714325c437d18b9a761 --- /dev/null +++ b/packages/express/README.md @@ -0,0 +1,13 @@ +# jsonql-express + +> This is an express middleware for jsonql + +## Example + +Coming soon + +--- + +Main website [jsonql](https://jsonql.org) + +Brought to you by: [NB](https://newbran.ch) & [T1S](https://to1source.cn) diff --git a/packages/express/package.json b/packages/express/package.json new file mode 100644 index 0000000000000000000000000000000000000000..9f1c3840314f193ee00c1dc81e7d74e149351cdf --- /dev/null +++ b/packages/express/package.json @@ -0,0 +1,16 @@ +{ + "name": "jsonql-express", + "version": "0.0.1", + "description": "This is an express middleware for jsonql", + "main": "index.js", + "scripts": { + "test": "ava --verbose" + }, + "keywords": [ + "jsonql", + "express", + "node" + ], + "author": "Joel Chu ", + "license": "ISC" +} diff --git a/packages/node-server/README.md b/packages/node-server/README.md deleted file mode 100644 index 10b65a9f3a57449190077c204cfeaa1186f0a4bd..0000000000000000000000000000000000000000 --- a/packages/node-server/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# jsonql-node-server - -This is an all in one setup to have your jsonql API server setup in no time. - -It includes: - -1. Koa -2. bodyparser, cors middleware -3. jsonql-koa middleware -4. jsonql-ws-server - -## Configuration - -TBC - ---- - -MIT (c) 2019 NEWBRAN LTD / TO1SOURCE CN diff --git a/packages/node-server/index.js b/packages/node-server/index.js deleted file mode 100644 index e15881979c519c39b475b671dbf9ac321686ce9b..0000000000000000000000000000000000000000 --- a/packages/node-server/index.js +++ /dev/null @@ -1,21 +0,0 @@ -// main - - -/** - * @param {object} config options - * @return {object} with several method to control the server - */ -module.exports = function(config) { - - - - - return { - start: () => { - - }, - stop: () => { - - } - } -} diff --git a/packages/node-server/lib/index.js b/packages/node-server/lib/index.js deleted file mode 100644 index 13169b46f4a6d47dee82b830b2426f3c3c399fb3..0000000000000000000000000000000000000000 --- a/packages/node-server/lib/index.js +++ /dev/null @@ -1,33 +0,0 @@ -// main export for lib -const http = require('http'); - -const Koa = require('koa'); -const bodyparser = require('koa-bodyparser'); -const cors = require('koa-cors'); - -const contractApi = require('jsonql-koa/contract'); -const jsonqlKoa = require('jsonql-koa'); - -const jsonqlWsServer = require('../../ws-server'); -// require('jsonql-ws-server') - -module.export = function initServer(config, middlewares = []) { - const app = new Koa(); - // apply default middlewares - app.use(bodyparser()); - app.use(cors()); - // init jsonqlKoa - app.use(jsonqlKoa(config)); - // if any - middlewares.forEach(middleware => { - app.use(middleware); - }); - - const server = http.createServer(app.callback()); - const ws = jsonqlWsServer(config, server); - // return it - return { - ws, - server - }; -} diff --git a/packages/node-server/lib/options/index.js b/packages/node-server/lib/options/index.js deleted file mode 100644 index 5b929953624491ec68b4352d6e9ad10778a624ec..0000000000000000000000000000000000000000 --- a/packages/node-server/lib/options/index.js +++ /dev/null @@ -1,6 +0,0 @@ -const { checkOptions } = require('jsonql-params-valiator'); -const options = require('./options'); - -module.exports = function(config) { - return checkOptions(config, options); -} diff --git a/packages/node-server/lib/options/options.js b/packages/node-server/lib/options/options.js deleted file mode 100644 index b877b5a7ec2713107ab077c9158768dd4c6535c2..0000000000000000000000000000000000000000 --- a/packages/node-server/lib/options/options.js +++ /dev/null @@ -1,14 +0,0 @@ -const { createConfig } = require('jsonql-params-validator'); -const { - BOOLEAN_TYPE -} = require('jsonql-constants'); - - -const options = { - autoStart: createConfig(true, [BOOLEAN_TYPE]) -}; - - -module.exports = { - options -}; diff --git a/packages/node-server/package.json b/packages/node-server/package.json deleted file mode 100644 index 57b20e35eb51f421d82b6ce3a493024e981444f9..0000000000000000000000000000000000000000 --- a/packages/node-server/package.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "name": "jsonql-node-server", - "version": "1.0.0-alpha.1", - "description": "This is the all in one package to start your project jsonql with Koa, jsonql-koa, jsonql-ws-server and more", - "main": "index.js", - "scripts": { - "test": "ava" - }, - "keywords": [ - "jsonql", - "jsonql-koa", - "koa", - "node", - "jsonql-ws-server", - "socket.io", - "Web", - "Socket" - ], - "author": "Joel Chu ", - "license": "MIT", - "devDependencies": { - "ava": "^1.4.1", - "debug": "^3.1.0", - "nyc": "^12.0.2", - "superkoa": "^1.0.3" - }, - "repository": { - "type": "git", - "url": "git+ssh://git@gitee.com:to1source/jsonql.git" - }, - "ava": { - "files": [ - "tests/*.test.js", - "!tests/helpers/*.*", - "!tests/fixtures/*.*" - ], - "cache": true, - "concurrency": 5, - "failFast": true, - "failWithoutAssertions": false, - "tap": false, - "compileEnhancements": false - }, - "engine": { - "node": ">=8" - }, - "dependencies": { - "jsonql-koa": "^1.1.4" - } -} diff --git a/packages/postinstall/README.md b/tools/postinstall/README.md similarity index 100% rename from packages/postinstall/README.md rename to tools/postinstall/README.md diff --git a/packages/postinstall/package.json b/tools/postinstall/package.json similarity index 100% rename from packages/postinstall/package.json rename to tools/postinstall/package.json