From 15f929424de2eac5ce0eb5a922040d01a8470c04 Mon Sep 17 00:00:00 2001 From: Steve Date: Thu, 15 Aug 2019 20:15:29 +0900 Subject: [PATCH 1/2] chore: optimize initializer w/o log --- src/core/lemon-engine-model.ts | 2 +- src/index.ts | 69 ++++++++++++++++++---------------- src/plugins/notify-service.ts | 20 +++++----- 3 files changed, 47 insertions(+), 44 deletions(-) diff --git a/src/core/lemon-engine-model.ts b/src/core/lemon-engine-model.ts index ac155c3..6b21678 100644 --- a/src/core/lemon-engine-model.ts +++ b/src/core/lemon-engine-model.ts @@ -338,7 +338,7 @@ const buildModel: EnginePluginBuilder = (_$, name, options) => const CONF_ES_TYPE = CONF_GET_VAL('ES_TYPE', ''); // ElasticSearch Type Name of this Table. (optional) #이게 ES6가면서 type이 의미 없어짐!. const CONF_ES_MASTER = CONF_GET_VAL('ES_MASTER', CONF_ES_TIMESERIES ? 1 : 0);// ES is master role? (default true if CONF_ES_FIELDS is null). (요건 main 노드만 있고, 일부 필드만 ES에 넣을 경우) const CONF_ES_VERSION = CONF_GET_VAL('ES_VERSION', 5); // ES Version Number. (5 means backward compartible) - _log(NS, '! CONF_ES_TIMESERIES=', CONF_ES_TIMESERIES); + // _log(NS, '! CONF_ES_TIMESERIES=', CONF_ES_TIMESERIES); //! Security Configurations. const CONF_XECURE_KEY = CONF_GET_VAL('XECURE_KEY', null); // Encryption/Decryption Key. diff --git a/src/index.ts b/src/index.ts index 9e9ab84..9c5d9d6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -124,7 +124,7 @@ export default function initiate(scope: {_$?: LemonEngine; [key: string]: any } return opt; } - //! root instance to manage global objects. + //! create root instance to manage global objects. const $engineBuilder = (): LemonEngine =>{ //! engine base function. const $engineBase = function(name: string, service: EnginePluggable): EnginePluggable { // global identifier. @@ -133,12 +133,16 @@ export default function initiate(scope: {_$?: LemonEngine; [key: string]: any } let org = typeof thiz.$plugins[name] !== 'undefined' ? thiz.$plugins[name] : undefined; if (!service) return org; if (org === undefined) { - _log('INFO! service[' + name + '] registered'); + _log(`INFO! service[${name}] registered`); thiz.$plugins[name] = service; return service; + } else if (true) { + //! ignore if duplicated >2.2.3 + // _log(`WARN! service[${name}] duplicated!`); + return org; } else { //! extends options. - _inf('WARN! service[' + name + '] extended.'); + _inf(`WARN! service[${name}] extended.`); org = _extend(org, service); thiz.$plugins[name] = org; return org; @@ -181,6 +185,31 @@ export default function initiate(scope: {_$?: LemonEngine; [key: string]: any } return buildModel($engine, name, option); } + //! start initialization only if making $engine. + STAGE && _inf('#STAGE =', STAGE); + + //! use base BACKBONE endpoint. + const BACKBONE = $engine.environ('BACKBONE_API', $engine.environ('BACKBONE-API', '')); + BACKBONE && _inf('#BACKBONE =', BACKBONE); + const ep = (name: string)=> (BACKBONE && `${BACKBONE}/${name}`) || ''; + + //! load common services.... + mysql($engine, 'MS', ep('mysql')); // load service, and register as 'MS' + dynamo($engine, 'DS', ep('dynamo')); // load service, and register as 'DS' + redis($engine, 'RS', ep('redis')); // load service, and register as 'RS' + elastic6($engine, 'ES6', ep('elastic6')); // load service, and register as 'ES6' + s3($engine, 'S3', ep('s3')); // load service, and register as 'S3' + sqs($engine, 'SS', ep('sqs')); // load service, and register as 'SS' + sns($engine, 'SN', ep('sns')); // load service, and register as 'SN' + ses($engine, 'SE', ep('ses')); // load service, and register as 'SE' + webProxy($engine, 'WS', ep('web')); // load service, and register as 'WS' + cognito($engine, 'CS', ep('cognito')); // load service, and register as 'CS' + lambda($engine, 'LS', ep('lambda')); // load service, and register as 'LS' + protocol($engine, 'PR', ep('protocol')); // load service, and register as 'PR' + cron($engine, 'CR', ep('cron')); // load service, and register as 'CR' + agw($engine, 'AG', ep('agw')); // load service, and register as 'AG' + _inf(`! engine[${ROOT_NAME}] service ready !`); + //! returns. return $engine; } @@ -188,38 +217,12 @@ export default function initiate(scope: {_$?: LemonEngine; [key: string]: any } //! reuse via scope or build new. const $engine: LemonEngine = scope._$ || $engineBuilder(); - //! register as global instances as default. - scope._log = _log; - scope._inf = _inf; - scope._err = _err; + //! register as global instances. + scope._log = scope._log || _log; + scope._inf = scope._inf || _inf; + scope._err = scope._err || _err; scope._$ = $engine; - // $root[_$.id] = _$; - STAGE && _inf('#STAGE =', STAGE); - - //! use base BACKBONE endpoint. - const BACKBONE = $engine.environ('BACKBONE_API', $engine.environ('BACKBONE-API', '')); - BACKBONE && _inf('#BACKBONE =', BACKBONE); - const ep = (name: string)=> (BACKBONE && `${BACKBONE}/${name}`) || ''; - - //! load common services.... - mysql($engine, 'MS', ep('mysql')); // load service, and register as 'MS' - dynamo($engine, 'DS', ep('dynamo')); // load service, and register as 'DS' - redis($engine, 'RS', ep('redis')); // load service, and register as 'RS' - elastic6($engine, 'ES6', ep('elastic6')); // load service, and register as 'ES6' - s3($engine, 'S3', ep('s3')); // load service, and register as 'S3' - sqs($engine, 'SS', ep('sqs')); // load service, and register as 'SS' - sns($engine, 'SN', ep('sns')); // load service, and register as 'SN' - ses($engine, 'SE', ep('ses')); // load service, and register as 'SE' - webProxy($engine, 'WS', ep('web')); // load service, and register as 'WS' - cognito($engine, 'CS', ep('cognito')); // load service, and register as 'CS' - lambda($engine, 'LS', ep('lambda')); // load service, and register as 'LS' - protocol($engine, 'PR', ep('protocol')); // load service, and register as 'PR' - cron($engine, 'CR', ep('cron')); // load service, and register as 'CR' - agw($engine, 'AG', ep('agw')); // load service, and register as 'AG' - - _inf(`! engine[${ROOT_NAME}] service ready !`); - //! returns finally. return $engine; } diff --git a/src/plugins/notify-service.ts b/src/plugins/notify-service.ts index 6871f70..4f5a120 100644 --- a/src/plugins/notify-service.ts +++ b/src/plugins/notify-service.ts @@ -198,7 +198,7 @@ const maker: EnginePluginBuilder = (_$, name, options) => { } //! register subscription. - _log(NS, '> INFO! - register subscriber by id ='+id); + // _log(NS, '> INFO! - register subscriber by id ='+id); //! inline function. let handler: any = null; @@ -225,16 +225,16 @@ const maker: EnginePluginBuilder = (_$, name, options) => { if (!id.endsWith(':*')){ if (!thiz.$notify[id]) thiz.$notify[id] = []; thiz.$notify[id].push(handler); - _log(NS, `! notify-subscribe(${id}) count=`, thiz.$notify[id].length); + // _log(NS, `! notify-subscribe(${id}) count=`, thiz.$notify[id].length); } else { const id2 = id.substring(0, id.length-1); RECORD_MODES.forEach(mode => { let id = id2 + mode; if (!thiz.$notify[id]) thiz.$notify[id] = []; thiz.$notify[id].push(handler); - _log(NS, `> notify-subscribe(${id}) count=`, thiz.$notify[id].length); + // _log(NS, `> notify-subscribe(${id}) count=`, thiz.$notify[id].length); }) - _log(NS, `! notify-subscribe(${id}) ... modes=`, RECORD_MODES.join('/')); + // _log(NS, `! notify-subscribe(${id}) ... modes=`, RECORD_MODES.join('/')); } } @@ -267,7 +267,7 @@ const maker: EnginePluginBuilder = (_$, name, options) => { //! main body. let id = ''+that._id; let params = that.params; - _log(NS, `- my_notify_subscribe_sync(${id}).... params=`, typeof params); + // _log(NS, `- my_notify_subscribe_sync(${id}).... params=`, typeof params); //! If starts with ':', then auto-complete with self notify-id. if(id.startsWith(':')) { @@ -293,7 +293,7 @@ const maker: EnginePluginBuilder = (_$, name, options) => { } //! register subscription. - _log(NS, '> INFO! - register subscriber by id ='+id); + // _log(NS, '> INFO! - register subscriber by id ='+id); //! inline function. let handler: any = {handle: null as any, promise: null as any}; @@ -328,21 +328,21 @@ const maker: EnginePluginBuilder = (_$, name, options) => { if (!id.endsWith(':*')){ if (!thiz.$notify[id]) thiz.$notify[id] = []; thiz.$notify[id].push(handler); - _log(NS, `! notify-subscribe(${id}) count=`, thiz.$notify[id].length); + // _log(NS, `! notify-subscribe(${id}) count=`, thiz.$notify[id].length); } else { const id2 = id.substring(0, id.length-1); RECORD_MODES.forEach(mode => { let id = id2 + mode; if (!thiz.$notify[id]) thiz.$notify[id] = []; thiz.$notify[id].push(handler); - _log(NS, `> notify-subscribe(${id}) count=`, thiz.$notify[id].length); + // _log(NS, `> notify-subscribe(${id}) count=`, thiz.$notify[id].length); }) - _log(NS, `! notify-subscribe(${id}) ... modes=`, RECORD_MODES.join('/')); + // _log(NS, `! notify-subscribe(${id}) ... modes=`, RECORD_MODES.join('/')); } } //! 리턴은 Promised 된 것으로... - _log(NS, `! subscribed-notify(${id})... that=`, $U.json(that)); + // _log(NS, `! subscribed-notify(${id})... that=`, $U.json(that)); return Promise.resolve(that); }; From baadcdef2ffde4906f54b5d1489bead8c4d0a78d Mon Sep 17 00:00:00 2001 From: Steve Date: Thu, 15 Aug 2019 20:16:41 +0900 Subject: [PATCH 2/2] ver2.2.4 --- README.md | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6ee9317..5eb0766 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ Plz, request PR. See [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) | Version | Description |-- |-- +| 2.2.4 | optimize log in init engine. | 2.2.3 | hot-fix type error of `$U.dt()`. | 2.2.2 | relay context as `that._ctx` in `on_record_update()`, and use common `BACKBONE_API` env. | 2.2.1 | hot-fix error of `$protocol().do_execute()`. diff --git a/package.json b/package.json index 5c56e3d..d4428c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lemon-engine", - "version": "2.2.3", + "version": "2.2.4", "description": "Lemon Engine Module to Synchronize Node over DynamoDB + ElastiCache + Elasticsearch by [lemoncloud](https://lemoncloud.io)", "main": "dist/index.js", "types": "dist/index.d.ts",