From b30faf4fb85fa875fce564327633d61e42565811 Mon Sep 17 00:00:00 2001 From: joelchu Date: Fri, 8 Nov 2019 22:36:52 +0800 Subject: [PATCH 1/2] jsonql-koa to 1.4.4 --- packages/koa/package.json | 2 +- packages/koa/src/options/index.js | 11 +++++++---- packages/koa/tests/config.test.js | 6 ++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/koa/package.json b/packages/koa/package.json index eccddc6e..395a750b 100644 --- a/packages/koa/package.json +++ b/packages/koa/package.json @@ -73,7 +73,7 @@ "debug": "^4.1.1", "esm": "^3.2.25", "fs-extra": "^8.1.0", - "jsonql-constants": "^1.8.9", + "jsonql-constants": "^1.8.10", "jsonql-contract": "^1.8.4", "jsonql-errors": "^1.1.5", "jsonql-jwt": "^1.3.3", diff --git a/packages/koa/src/options/index.js b/packages/koa/src/options/index.js index ceb13d24..41aeea7c 100644 --- a/packages/koa/src/options/index.js +++ b/packages/koa/src/options/index.js @@ -2,6 +2,8 @@ import { join, resolve } from 'path' import fsx from 'fs-extra' import _ from 'lodash' + +const { CHECKED_KEY } = require('jsonql-constants') import { checkConfig, isString } from 'jsonql-params-validator' import { rsaPemKeys } from 'jsonql-jwt' @@ -9,7 +11,7 @@ import { appProps, constProps, jwtProcessKey } from './options' import { isContract, chainFns, getDebug, inArray, injectToFn } from '../utils' import { getContract } from '../contracts' const debug = getDebug('config-check') -const CHECKED = '__checked__' + /** * break out from the applyAuthOptions because it's not suppose to be there * @NOTE v1.3.8 change it to a fully functional interface @@ -75,12 +77,13 @@ const applyAuthOptions = function(config) { */ export function configCheck(config = {}) { let now = Date.now() - if (config[CHECKED]) { // @TODO we could check the time if we want ... - debug(`config already checked, pass it through`) + let time; + if ((time = config[CHECKED_KEY]) !== undefined) { // @TODO we could check the time if we want ... + debug(`config already checked, pass it through`, time, now - time) return config; } const fn = chainFns(checkConfig, applyGetContract, applyAuthOptions) const opts = fn(config, appProps, constProps) // return opts; - return injectToFn(opts, CHECKED, now) + return injectToFn(opts, CHECKED_KEY, now) } diff --git a/packages/koa/tests/config.test.js b/packages/koa/tests/config.test.js index 446c387d..2b1a0f62 100644 --- a/packages/koa/tests/config.test.js +++ b/packages/koa/tests/config.test.js @@ -3,6 +3,8 @@ const test = require('ava') const fsx = require('fs-extra') const { join, resolve } = require('path') +const { CHECKED_KEY } = require('jsonql-constants') + const { configCheck } = require('../src/options') const processJwtKeysDefault = require('../src/options/process-jwt-keys') const processJwtKeys = processJwtKeysDefault.default @@ -54,6 +56,6 @@ test('It should have privateKey and publicKey when set useJwt = true', async t = test(`It should now have an extra property __checked__`, t => { const opts = configCheck() - debug(opts.__checked__) - t.truthy(opts.__checked__) + debug(opts[CHECKED_KEY]) + t.truthy(opts[CHECKED_KEY]) }) -- Gitee From 1ed944ea0a16e4420515913a7ac62e4d6ea96556 Mon Sep 17 00:00:00 2001 From: joelchu Date: Fri, 8 Nov 2019 22:38:29 +0800 Subject: [PATCH 2/2] add test to make sure the public api is available --- packages/koa/tests/config.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/koa/tests/config.test.js b/packages/koa/tests/config.test.js index 2b1a0f62..35bec24d 100644 --- a/packages/koa/tests/config.test.js +++ b/packages/koa/tests/config.test.js @@ -6,6 +6,7 @@ const { join, resolve } = require('path') const { CHECKED_KEY } = require('jsonql-constants') const { configCheck } = require('../src/options') +const { preConfigCheck } = require('../index') const processJwtKeysDefault = require('../src/options/process-jwt-keys') const processJwtKeys = processJwtKeysDefault.default @@ -55,7 +56,7 @@ test('It should have privateKey and publicKey when set useJwt = true', async t = }) test(`It should now have an extra property __checked__`, t => { - const opts = configCheck() + const opts = preConfigCheck() debug(opts[CHECKED_KEY]) t.truthy(opts[CHECKED_KEY]) }) -- Gitee