Skip to content

Commit

Permalink
Merge pull request #13 from lemoncloud-io/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
steve-lemon authored Aug 15, 2019
2 parents 0a19026 + baadcde commit 6846c27
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 45 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()`.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/core/lemon-engine-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ const buildModel: EnginePluginBuilder<LemonEngineModel> = (_$, 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.
Expand Down
69 changes: 36 additions & 33 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -181,45 +185,44 @@ 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;
}

//! 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;
}
20 changes: 10 additions & 10 deletions src/plugins/notify-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ const maker: EnginePluginBuilder<NotifyService> = (_$, 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;
Expand All @@ -225,16 +225,16 @@ const maker: EnginePluginBuilder<NotifyService> = (_$, 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('/'));
}
}

Expand Down Expand Up @@ -267,7 +267,7 @@ const maker: EnginePluginBuilder<NotifyService> = (_$, 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(':')) {
Expand All @@ -293,7 +293,7 @@ const maker: EnginePluginBuilder<NotifyService> = (_$, 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};
Expand Down Expand Up @@ -328,21 +328,21 @@ const maker: EnginePluginBuilder<NotifyService> = (_$, 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);
};

Expand Down

0 comments on commit 6846c27

Please sign in to comment.