Socket
Socket
Sign inDemoInstall

lemoncloud-engine-js

Package Overview
Dependencies
4
Maintainers
3
Versions
66
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.10 to 0.3.11

2

core/lemon-engine-model.js

@@ -1,1 +0,1 @@

"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};function _defineProperty(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}module.exports=function(e,r,t){var n=r||"LEM",f=e.U,m=e._,i=e.MS,d=e.DS,o=e.RS,u=e.ES,_=e.ES6;if(!f)throw new Error("$U is required!");if(!m)throw new Error("$U is required!");if(!i)throw new Error("$MS is required!");if(!d)throw new Error("$DS is required!");if(!o)throw new Error("$RS is required!");var h=e.log,s=e.inf,l=e.err,p=f.NS(n,"green"),a=t||{},c=function(e){throw new Error("NOT_IMPLEMENTED - "+p+":"+JSON.stringify(e))};a.do_prepare=c,a.do_create=c,a.do_clone=c,a.do_update=c,a.do_increment=c,a.do_read=c,a.do_delete=c,a.do_destroy=c,a.do_search=c,a.do_initialize=c,a.do_terminate=c,a.do_test_self=c,a.on_records=c,a.do_notify=c,a.do_subscribe=c,a.do_next_id=c,r.startsWith("_")||e(r,a);var v=function(e,r){return void 0===a[e]?r:a[e]},E=v("VERSION",1),y=v("REVISION",1),P=v("VERSION_NAME","V"),j=v("REVISION_NAME","R"),w=v("ID_INPUT","id"),g=v("ID_NAME","id"),S=v("ID_TYPE","test"),q=v("ID_NEXT",0),N=v("DYNA_TABLE","TestTable"),R=v("REDIS_PKEY","TPKEY"),b=v("FIELDS",null),O=v("DEFAULTS",null),T=v("CLONEABLE",!1),A=v("CLONED_ID","cloned"),x=v("PARENT_ID","parent"),I=v("PARENT_IMUT",!0),D=v("ES_INDEX","test-v1"),W=v("ES_TYPE","test"),M=v("ES_FIELDS",["updated_at","name"]),L=v("ES_MASTER",0),$=v("ES_VERSION",5),V=5<$?_:u;if(!V)throw new Error("$ES is required! Ver:"+$);var k=v("NS_NAME",""),U=require("dynamodb-value"),F=require("./notify-service")(e,"!"+k,{NS_NAME:k});a.do_notify=F.do_notify,a.do_subscribe=F.do_subscribe,T&&b&&(x&&b.indexOf(x)<0&&b.push(x),A&&b.indexOf(A)<0&&b.push(A));var Y=[w,g,"created_at","updated_at","deleted_at",A];I&&x&&Y.push(x);var z=function(e,r,t,n){t=t||"","object"===(void 0===(e=e||0)?"undefined":_typeof(e))?r=r?f.extend(e,r):e:(r=null==r?{}:"object"!==(void 0===r?"undefined":_typeof(r))||r instanceof Promise?{params:r}:f.copy(r),r=f.extend(r,{_id:e}));var i=r;if(void 0!==i.records)return f.promise(i);if(t.startsWith("notify"))return f.promise(i);if(i&&void 0!==i._is_prepared&&i._is_prepared)return i._current_mode=t,i._method_stack.push(t),1e3<i._method_stack.length?Promise.reject(p+"method-stack full. size:"+i._method_stack):f.promise(i);e=S.startsWith("#")?i._id||i[w]||"":f.N(i._id||i[w]||0);var o=i._current_time||f.current_time_ms();return i._id=e,i._current_time=o,i._current_mode=t,i._method_stack=[],i._method_stack.push(t),i._updated_node=null,i._ctx=n,i._node={},i._is_prepared=!0,void 0===i._params_count&&(i._params_count=0,i=m.reduce(i,function(e,r,t){return t.startsWith("_")||t.startsWith("$")||0<=Y.indexOf(t)||e._params_count++,e},i)),f.promise(i)},B=function(e){if(!e)return e;var r=e._current_mode||"";if(void 0!==e.records)return f.promise(e);if(r.startsWith("notify"))return f.promise(e);if(e._method_stack&&e._method_stack.pop(),"read"!==r&&"increment"!==r&&"create"!==r)return e;if(void 0!==e._auto_populate&&!e._auto_populate)return e;var t=e._node;return 0===e._params_count||-1===e._fields_count?e=m.reduce(t,function(e,r,t){return"updated_at"===t&&void 0!==e[t]?e[t]=e[t]>r?e[t]:r:e[t]=r,e},e):0<=e._fields_count&&(e=b?b.reduce(function(e,r){return void 0!==e[r]&&void 0!==t[r]&&(e[r]=t[r]),e},e):e),e},Q=function(r){var e=r._id;if(h(p,"- my_prepare_id("+S+", "+e+")...."),S.startsWith("#")){if(S&&S.startsWith("#")&&1<S.length&&0<q){var t=S.substring(1);return i.do_get_next_id(t).then(function(e){return h(p,"> created next-id["+t+"]=",e),r._id=e,r})}}else if(S&&!e)return i.do_get_next_id(S).then(function(e){return h(p,"> created next-id=",e),r._id=e,r});return h(p,"> prepared-id =",e),Promise.resolve(r)},H=function(t){if(!t._current_mode)throw new Error(p+"_current_mode is required!");var n=t._current_mode,i=O||{},o=0,e=t._node||{};return b?"prepare"===n||"create"===n||"clone"===n?e=b.reduce(function(e,r){return r===g||r===P||r===j||("prepare"===n?(void 0!==i[r]?e[r]=O[r]:void 0!==t[r]&&(e[r]=t[r]),P&&(e[P]=E),j&&(e[j]=0)):("create"===n&&j&&(e[j]=y-1),void 0!==t[r]&&(e[r]=t[r])),o++),e},e):"update"!==n&&"increment"!==n&&"read"!==n||(e=b.reduce(function(e,r){return r===g||void 0!==t[r]&&o++,e},e)):o=-1,t._fields_count=o,t._node=e,t},C=function(e,r){return e.created_at=0,e.updated_at=r,e.deleted_at=r,e},J=function(e,r){return e.created_at=r,e.updated_at=r,e.deleted_at=0,e},K=function(r){if(!r._node)return Promise.reject(new Error(p+"_node is required!"));if(!r._current_time)return Promise.reject(new Error(p+"_current_time is required!"));var t=r._id,n=(r._node,r._current_time);return t?ae(r).catch(function(e){return l(p,"not found. err=",e),r}).then(function(e){var r=(e=H(e))._node||{};if(e._force_create)l(p,"WARN! _force_create is set!");else if(!r.deleted_at)return l(p,"INVALID STATE FOR PREPARED. ID=",t,", TIMES[CUD]=",[r.created_at,r.updated_at,r.deleted_at]),Promise.reject(new Error(p+"INVALID STATE."));return e[w]=e._id,r[g]=e._id,e._node=C(e._node,n),e}):(r=H(r),Q(r).then(function(e){var r=e._node||{};return e[w]=e._id,r[g]=e._id,e._node=C(r,n),e}))},X=function(e){if(!e._id)return Promise.reject(new Error(p+"_id is required!"));if(!e._node)return Promise.reject(new Error(p+"_node is required!"));if(!e._current_time)return Promise.reject(new Error(p+"_current_time is required!"));var t=e._id,r=e._node,n=e._current_time;return h(p,"> prepared-id =",t,", current-time =",n,", node =",f.json(r)),ae(e).then(function(e){var r=(e=H(e))._node||{};if(e._force_create)l(p,"WARN! _force_create is set!");else if(!r.deleted_at)return l(p,"INVALID STATE FOR CREATED. ID=",t,", TIMES[CUD]=",[r.created_at,r.updated_at,r.deleted_at]),Promise.reject(new Error(p+"INVALID STATE."));return e._node=J(e._node,n),e})},G=function(e){if(!e._id)return Promise.reject(new Error(p+"_id is required!"));if(!e._node)return Promise.reject(new Error(p+"_node is required!"));if(!e._current_time)return Promise.reject(new Error(p+"_current_time is required!"));var r=e._id,t=e._node,n=e._current_time;return h(p,"> cloned-id =",r,", current-time =",n,", node =",f.json(t)),ae(e).then(function(e){return h(p,">> get-item-node old=",f.json(e._node)),(e=H(e))._node=J(e._node,n),e})},Z=function(e){if(!e._id)return Promise.reject(new Error(p+"_id is required!"));if(!e._node)return Promise.reject(new Error(p+"_node is required!"));if(!e._current_time)return Promise.reject(new Error(p+"_current_time is required!"));e._id,e._node;var n=e._current_time;return 0===(e=H(e))._fields_count?e:ae(e).then(function(e){var r,t;return e._node=(r=e._node,t=n,r.updated_at=t,r),e})},ee=function(e){if(!e._id)return Promise.reject(new Error(p+"_id is required!"));if(!e._node)return Promise.reject(new Error(p+"_node is required!"));if(!e._current_time)return Promise.reject(new Error(p+"_current_time is required!"));var r=e._id,t=e._node,n=e._current_time;return h(p,"> deleted-id =",r,", current-time =",n,", node =",f.json(t)),ae(e).then(function(e){var r,t;return h(p,">> get-item-node old=",f.json(e._node)),(e=H(e))._node=(r=e._node,t=n,r.updated_at=t,r.deleted_at=t,r),e})},re=function(r){var e;if(!r._id)return Promise.reject(new Error(p+"_id is required!"));var t=r._id;h(p,"- dynamo:my_read_node ("+t+")....");var n=S.startsWith("#")?"String":"";return d.do_get_item(N,(e={},_defineProperty(e,g,t),_defineProperty(e,"idType",n),e)).then(function(e){return h(p,"> dynamo:get-item-node("+t+") res=",f.json(e)),r._node=e,r})},te=function(r){if(!r._id)return Promise.reject(new Error(p+"_id is required!"));if(!r._node)return Promise.reject(new Error(p+"_node is required!"));var t=r._id,e=r._node,n={},i=0;for(var o in r)r.hasOwnProperty(o)&&(o=""+o)&&(o.startsWith("_")||o.startsWith("$")||0<=Y.indexOf(o)||b&&b.indexOf(o)<0||o&&(n[o]=r[o],e[o]=r[o],i++));return n.updated_at=e.updated_at,r._updated_node=null,(r._updated_count=i)?(void 0!==e[j]&&(e[j]=f.N(e[j],0)+1),d.do_update_item(N,_defineProperty({},g,t),n,j?_defineProperty({},j,1):null).then(function(e){return r._updated_node=n,h(p,"> dynamo:updated-item("+t+") res=",f.json(e)),r})):b?r:Promise.reject(new Error(p+"nothing to update"))},ne=function(r){if(!r._id)return Promise.reject(new Error(p+"_id is required!"));if(!r._node)return Promise.reject(new Error(p+"_node is required!"));var t=r._id,e=r._node,n=r._current_mode||"",i=r._current_time;if(h(p,"- dynamo:my_save_node("+t+")...."),h(p,"> dynamo:node-id =",t,", current-time =",i,", node =",f.json(e)),"prepare"!==n)for(var o in r)r.hasOwnProperty(o)&&(o=""+o)&&(o.startsWith("_")||o.startsWith("$")||0<=Y.indexOf(o)||b&&b.indexOf(o)<0||(e[o]=r[o]));return void 0!==e[j]&&(e[j]=f.N(e[j],0)+1),d.do_create_item(N,_defineProperty({},g,t),e).then(function(e){return h(p,"> dynamo:saved-item("+t+") res=",e),r})},ie=function(r){if(!r._id)return Promise.reject(new Error(p+"_id is required!"));if(!r._node)return Promise.reject(new Error(p+"_node is required!"));var t=r._id,e=r._node,n={},i=0;for(var o in r)r.hasOwnProperty(o)&&((o=""+o).startsWith("_")||o.startsWith("$")||0<=Y.indexOf(o)||b&&b.indexOf(o)<0||o&&(n[o]=r[o],e[o]=f.N(e[o],0)+f.N(r[o]),i++));return n.updated_at=e.updated_at,h(p,"> dynamo:increment-node =",n),r._updated_node=null,(r._updated_count=i)?(void 0!==e[j]&&(e[j]=f.N(e[j],0)+1),d.do_increment_item(N,_defineProperty({},g,t),n,j?_defineProperty({},j,1):null).then(function(e){return h(p,"> dynamo:updated-item("+t+") res=",f.json(e)),r._updated_node=n,r})):b?r:Promise.reject(new Error(p+"nothing to update"))},oe=function(r){if(!r._id)return Promise.reject(new Error(p+"_id is required!"));var t=r._id;return d.do_delete_item(N,_defineProperty({},g,t)).then(function(e){return h(p,"> dynamo:deleted-item-node("+t+") res=",f.json(e)),r._node=e||{},r})},de={my_read_node:function(r){if(!r._id)return Promise.reject(new Error(p+"_id is required!"));if(!R)return Promise.reject(r);var t=r._id;return o.do_get_item(R,t).then(function(e){return e?(r._node=e,r):Promise.reject(r)}).catch(function(e){throw e instanceof Error&&(l(p,"! redis:get-item("+R+", "+t+") err =",e.message||e),r._error=e),r})},my_save_node:function(r){if(!r._id)return Promise.reject(new Error(p+"_id is required!"));if(!r._node)return Promise.reject(new Error(p+"_node is required!"));if(!R)return Promise.resolve(r);var t=r._id,e=r._node;h(p,"- redis:my_save_node("+R+":"+t+"). node=",f.json(e));var n=de.my_set_node_footprint(t,e);return n=n.then(function(){return o.do_create_item(R,t,e)}).then(function(e){return h(p,"> redis:save-item-node("+t+") res=",f.json(e)),r})},my_update_node:function(r){if(!r._id)return Promise.reject(new Error(p+"_id is required!"));if(!r._node)return Promise.reject(new Error(p+"_node is required!"));if(!R)return Promise.resolve(r);var t=r._id,e=r._node,n=de.my_set_node_footprint(t,e);return n=n.then(function(){return o.do_update_item(R,t,e)}).then(function(e){return h(p,"> redis:update-item-node("+t+") res=",f.json(e)),r})},my_delete_node:function(r){if(!r._id)return Promise.reject(new Error(p+"_id is required!"));if(!R)return Promise.resolve(r);var t=r._id;return o.do_delete_item(R,t).then(function(e){return h(p,"> redis:delete-item-node("+t+") res=",f.json(e)),r})},my_set_node_footprint:function(r,e){if(!r)return Promise.reject(new Error(p+"id is required!"));if(!R)return Promise.resolve(0);e=e||{};var t=f.N(e.updated_at,0),n=f.hash(e);return o.do_create_item([R+"/UPDATED",R+"/HASH"],r,[t,n]).then(function(e){return h(p,"> redis:set node-footprint("+r+") res=",f.json(e)),e})},my_get_updated_at:function(e){return e?R?o.do_get_item(R+"/UPDATED",e).then(function(e){return e}):Promise.resolve(-1):Promise.reject(new Error(p+"id is required!"))},my_get_hash_value:function(e){return e?R?o.do_get_item(R+"/HASH",e).then(function(e){return e}):Promise.resolve(-1):Promise.reject(new Error(p+"id is required!"))}},ue=function(r){if(!r._id)return Promise.reject(new Error(p+"elasticsearch:_id is required!"));if(!r._node)return Promise.reject(new Error(p+"elasticsearch:_node is required!"));if(!D||!W)return r;var t=r._id,n=r._node;if(M){var e=m.reduce(M,function(e,r){return void 0!==n[r]&&(e[r]=n[r]),e},{});return Object.keys(e).length?(void 0!==n.created_at&&(e.created_at=n.created_at),void 0!==n.updated_at&&(e.updated_at=n.updated_at),void 0!==n.deleted_at&&(e.deleted_at=n.deleted_at),L?V.do_create_item(D,W,t,e).then(function(e){return h(p,"! elasticsearch:saved-item("+t+") res=",f.json(e)),r}):V.do_update_item(D,W,t,e).then(function(e){return h(p,"! elasticsearch:updated-item("+t+") res=",f.json(e)),r})):(h(p,"! elasticsearch:WARN! nothing to update ("+t+")...."),r)}return V.do_create_item(D,W,t,n).then(function(e){return h(p,"! elasticsearch:saved-item2("+t+") res=",f.json(e)),r})},_e=function(r){if(!r._id)return Promise.reject(new Error(p+"elasticsearch:_id is required!"));if(!D||!W)return r;var t=r._id;return M&&!L?(h(p,"! elasticsearch:WARN! ignore delete ("+t+")...."),r):V.do_delete_item(D,W,t).then(function(e){return h(p,"! elasticsearch:deleted-item("+t+") res=",f.json(e)),r})},se=function(i){if(!D||!W)return i;if(h(p,"- elasticsearch:do_search_item()...."),M&&!L)return h(p,"! elasticsearch:WARN! ignore search ()...."),i;var o={$page:0,$limit:0};return o.$page=f.N(i.page||0),o.$limit=f.N(i.ipp||10),o.deleted_at="0",i.$source&&(o.$source=i.$source),i.Q&&(o.$Q=i.Q),i.A&&(o.$A=i.A),i.O&&(o.$O=i.O),o.$O=o.$O||(S.startsWith("#")?"id.keyword":"id"),M&&M.forEach(function(e){void 0!==i[e]&&(o[e]=i[e]),void 0!==i["!"+e]&&(o["!"+e]=i["!"+e]),void 0!==i["#"+e]&&(o["#"+e]=i["#"+e])}),V.do_search_item(D,W,o).then(function(e){var r=e&&e.hits||{},t=r.hits||[],n=r;return i.list=t.map(function(e){return f.extend({_score:e._score},e._source)}),i.total=f.N(n.total||0),i.page=o.$page,i.ipp=o.$limit,i.took=e.took||0,void 0!==e.aggregations&&(i.aggregations=e.aggregations),i}).catch(function(e){throw l(p,"!ERR =",e),e})},ae=function(e){if(!e._id)return Promise.reject(new Error(p+"_id is required!"));e._id;return Promise.resolve(e).then(de.my_read_node).catch(function(e){return re(e).then(function(e){return void 0===(e._node||{})[g]?Promise.reject(new Error(p+"404 NOT FOUND. "+N+".id:"+(e._id||""))):e}).then(de.my_save_node)})},ce=function(e){if(!e._id)return Promise.reject(new Error(p+"_id is required!"));if(!e._node)return Promise.reject(new Error(p+"_node is required!"));e._id;return Promise.resolve(e).then(ne).then(de.my_save_node).then(ue).then(function(e){return e})},fe=function(e){if(!e._id)return Promise.reject(new Error(p+"_id is required!"));if(!e._node)return Promise.reject(new Error(p+"_node is required!"));if(!e._current_time)return Promise.reject(new Error(p+"_current_time is required!"));var r=e._id;return h(p,"- my_clone_node ("+r+")...."),Promise.resolve(e).then(function(n){if(!T)return n;var e=n._id,i=void 0!==n[x]?f.N(n[x],0):e,o=e;return Q({_id:0}).then(function(e){var r=e._id,t=n._node||{};return t[g]=r,x&&(t[x]=i),A&&(t[A]=o),x&&(n[x]=i),A&&(n[A]=o),n._clone_id=r,n._node=t,n})}).then(function(e){if(!e._id)return Promise.reject(new Error(p+"_id is required!"));if(!e._node)return Promise.reject(new Error(p+"_node is required!"));if(!e._clone_id)return Promise.reject(new Error(p+"_clone_id is required!"));var r=e._id;return e._id=e._clone_id,m.reduce(e,function(e,r,t){return t&&(t.startsWith("_")||t.startsWith("$")||0<=Y.indexOf(t)||void 0!==e[t]&&(e[t]=r)),e},e._node),h(p,">> before save-node().. that._node =",f.json(e._node)),ce(e).then(function(){return e._id=r,e})}).then(function(e){return h(p,">> cloned-node["+e._id+" -> "+e._clone_id+"] res=",f.json(e._node)),e})},me=function(e){if(!e._id)return Promise.reject(new Error(p+"_id is required!"));var r=e._id;return h(p,"- my_delete_node ("+r+")...."),Promise.resolve(e).then(oe).then(de.my_delete_node).then(_e).then(function(e){return h(p,">> deleted-node res=",f.json(e._node)),e})},he=function(e){return h(p,"- my_search_node ()...."),Promise.resolve(e).then(se).then(function(e){return e})},le=function(e){if(!e)return e;if(!e._id)return Promise.reject(new Error(p+"_id is required!"));e._id;var n=e._current_mode;return Promise.resolve(e).then(function(r){var e=!1;if("create"===n||"prepare"===n||"delete"===n||"destroy"===n?e=!0:"update"!==n&&"increment"!==n||(e=0<r._fields_count),e){var t=k+":event:"+n;return h(p,">>> notify event-id:",t,", notifiable=",e),Ee(t,r).then(function(e){return r})}return r})},pe=function(r){if(!r.records)return Promise.reject(new Error(p+"records is required!"));var e=r.records.slice(0);if(h(p,"- my_event_records().... records.len=",e.length),!e.length)return r;var t,n,i;return(t=e,n=ve,i=f.promise(t.shift()),i=t.reduce(function(e,r){return e.then(function(){return n(r)})},i.then(function(e){return n(e)}))).catch(function(e){return l(p,"error ignored! =",e),r}).then(function(){return r})},ve=function(e){if(!e)return Promise.reject(new Error("record is required"));if(!e.dynamodb&&!e.Sns)return Promise.reject(new Error("record.dynamodb|Sns is required"));var i=e.eventName||"EVENT",r=null;if(e.dynamodb){var o=e.table||e.eventSourceARN&&e.eventSourceARN.split("/")[1]||"";if(h(p,"--- process-record("+o+") ... "),N!==o)return h(p,"! ignore record-table: "+N+" != "+o+" "),e;var t=e.dynamodb.Keys?U.toJavascript(e.dynamodb.Keys):{},d=e.dynamodb.NewImage?U.toJavascript(e.dynamodb.NewImage):null,n=e.dynamodb.OldImage?U.toJavascript(e.dynamodb.OldImage):null,u=t[g],_="MODIFY"===i?f.diff(n,d):null,s=f.N(d&&d.updated_at||0),a=_?m.reduce(_,function(e,r){return e[r]=n[r],e},{}):null,c={_id:u,_node:d,_updated_at:s,_diff:_,_prev:a};switch(r=Promise.resolve(c),_&&h(p,">> "+o+".different["+u+"]=",f.json(_)),i){case"INSERT":case"MODIFY":r=r.then(function(t){var n=t._id;return de.my_get_updated_at(n).then(function(e){if(l(p,">> "+o+".updated_at["+n+"] res=",e," <- ",t._updated_at,t._updated_at!==e?"*":""),!e||t._updated_at>=e){var r=f.hash(d);return de.my_get_hash_value(n).then(function(e){return e&&e===r?(h(p,"! WARN! ignored due to hash-value matching =",e),t):(h(p,"! INFO! node was updated. hash :=",r,"<-",e),de.my_save_node(t).then(ue))})}return h(p,"! ignored due to old-record"),t})});break;case"REMOVE":h(p,">> removed!"),r=(r=r.then(de.my_delete_node)).then(_e)}}else e.Sns&&(h(p,">> event-SNS =",e.Sns),r=Promise.resolve(e.Sns));return r?r.then(function(r){var e={INSERT:"create",MODIFY:"update",REMOVE:"delete",EVENT:"event"}[i],t=!!e;if(r._current_mode=e,t){var n=k+":record:"+e;return h(p,">>> notify event-id:",n,", notifiable=",t),Ee(n,r).then(function(e){return r})}return r}).then(function(){return e}):Promise.reject(new Error("invalid chain!"))},Ee=function(e,r){return F.do_notify(e,r)},ye=function(r){var e=[];if(N){var t=S.startsWith("#")?"S":"N";e.push(Promise.resolve("DynamoDb").then(function(e){return h(p,"# initialize ",e),d.do_create_table(N,g,t).then(function(e){return e.TableDescription.TableName===N})}).catch(function(e){if("ResourceInUseException"===e.code)return!1;throw e}))}else h(p,"DS: WARN! ignored configuration. DYNA_TABLE=",N);if(S&&!S.startsWith("#")?e.push(Promise.resolve("MySQL").then(function(e){return h(p,"# initialize MySQL (Sequence) "),i.do_create_id_seq(S,q).then(function(e){return h(p,"> create-id-seq res=",e),!0})}).catch(function(e){if("ER_TABLE_EXISTS_ERROR"===e.code)return!1;throw e})):S&&S.startsWith("#")&&1<S.length&&0<q?e.push(Promise.resolve("MySQL").then(function(e){h(p,"# initialize MySQL (Sequence) ");var r=S.substring(1);return i.do_create_id_seq(r,q).then(function(e){return h(p,"> create-id-seq["+r+"] res=",e),!0})}).catch(function(e){if("ER_TABLE_EXISTS_ERROR"===e.code)return!1;throw e})):h(p,"MS: WARN! ignored configuration. ID_TYPE=",S),D&&W&&M){var n={mappings:{_default_:{dynamic_templates:[{string_fields:{match:"*_multi",match_mapping_type:"string",mapping:{type:"multi_field",fields:{"{name}":{type:6<=$?"text":"string",index:"analyzed",omit_norms:!0,index_options:"docs"},"{name}.raw":{type:6<=$?"text":"string",index:"not_analyzed",ignore_above:256}}}}}],properties:{"@version":{type:6<=$?"text":"string",index:!(6<=$)&&"not_analyzed"},title:{type:6<=$?"text":"string"},name:{type:6<=$?"text":"string"},created_at:{type:"date",format:"strict_date_optional_time||epoch_millis"},updated_at:{type:"date",format:"strict_date_optional_time||epoch_millis"},deleted_at:{type:"date",format:"strict_date_optional_time||epoch_millis"}}}}};6<=$||(n.mappings._default_.all={enabled:!0}),e.push(Promise.resolve("ElasticSearch").then(function(e){return h(p,"# initialize ElasticSearch (Type) ",W),V.do_create_index_type(D,W,n).then(function(e){return h(p,"> create-es-index res=",e),!0})}).catch(function(e){if(l(p,"> create-es-index error=",e),"index_already_exists_exception"===e.type)return!0;throw e}).then(function(e){return e}))}else h(p,"MS: WARN! ignored configuration. ES_TYPE=",W);return Promise.all(e).then(function(e){return h(p,">> results=",e),r._result=e,r})},Pe=function(r){var e=[];if(N&&(h(p,"# terminate DynamoDB"),e.push(d.do_delete_table(N).then(function(e){return e.TableDescription.TableName===N}).catch(function(e){if("ResourceNotFoundException"===e.code)return!0;throw e}))),S&&!S.startsWith("#"))h(p,"# terminate MySQL (Sequence) "),e.push(i.do_delete_id_seq(S).then(function(e){return h(p,"> delete-id-seq res=",e),!0}).catch(function(e){if("ER_BAD_TABLE_ERROR"===e.code)return!0;throw e}));else if(S&&S.startsWith("#")&&1<S.length&&0<q){h(p,"# terminate MySQL (Sequence) ");var t=S.substring(1);e.push(i.do_delete_id_seq(t).then(function(e){return h(p,"> delete-id-seq["+t+"] res=",e),!0}).catch(function(e){if("ER_BAD_TABLE_ERROR"===e.code)return!0;throw e}))}else h(p,"# ignored MySQL (Sequence) ");return D&&W?(h(p,"# terminate ES (Index) "),e.push(V.do_delete_index_type(D,null).then(function(e){return h(p,"> delete-es-index res=",e),!0}).catch(function(e){throw l(p,"> create-es-index error=",e),e}))):h(p,"# ignored ES (Index) "),Promise.all(e).then(function(e){return h(p,">> results=",e),r._result=e,r})},je=function(e){var r={a:1,b:2,x:3},t={x:3,a:1,b:2},n={b:2,x:3,a:1};r.name="hi",t.name="hi",n.name="hi",h(p,"# node1 =",f.json(r)),h(p,"> node2 =",f.json(t)),h(p,"> node3 =",f.json(n)),h(p,"# node1.sorted =",f.json(r,!0)),h(p,"> node2.sorted =",f.json(t,!0)),h(p,"> node3.sorted =",f.json(n,!0)),h(p,"# hash1 =",f.hash(1)),h(p,"> node1 =",f.hash(r)),h(p,"> node2 =",f.hash(t)),h(p,"> node3 =",f.hash(n));var i={updated_at:234,name:"test hash"};return Promise.resolve(i).then(function(e){return o.do_create_item("H#",1,e)}).then(function(){return o.do_get_item("H#",1).then(function(e){return h(p,"> read-back data=",e),e})}).then(function(){return de.my_set_node_footprint(1,i)}).then(function(){return de.my_get_updated_at(1).then(function(e){return h(p,"> updated-at value=",void 0===e?"undefined":_typeof(e),":",e),e})}).then(function(){return de.my_get_hash_value(1).then(function(e){return h(p,"> hash-value value=",void 0===e?"undefined":_typeof(e),":",e),e})})},we=function(r){return h(p,"- my_test_self()...."),Promise.resolve(r).then(je).then(function(e){return e||r})};return a.do_prepare_chain=function(e,r,t,n){return z(e,r,t,n)},a.do_finish_chain=function(e,r,t,n){return B(e)},a.do_prepare=function(e,r){return z(e,r,"prepare").then(K).then(ce).then(le).then(B)},a.do_create=function(t,n){return z(t,n,"create").then(X).catch(function(e){l(p,"ERR! prepare_node_created =",e instanceof Error,e.message||e);var r=e&&e.message||"";if(e instanceof Error&&0<=r.indexOf("404 NOT FOUND"))return s(p,"WARN! AUTO TRY TO PREPARE NODE. ID="+t),z(t,n,"create").then(function(e){var r=e._current_time;return e=H(e),h(p,">> prepared old-node=",f.json(e._node)),e._node=J(e._node,r),e});throw e}).then(ce).then(le).then(B)},a.do_clone=function(e,r){return z(e,r,"clone").then(G).then(fe).then(le).then(B)},a.do_read=function(e,r){return z(e,r,"read").then(H).then(function(e){return 0!==e._params_count&&0===e._fields_count?e:ae(e)}).then(le).then(B)},a.do_update=function(e,r){return z(e,r,"update").then(Z).then(function(e){return 0===e._fields_count?e:function(t){if(!t._id)return Promise.reject(new Error(p+"_id is required!"));var e=t._id;return h(p,"- my_update_node ("+e+")...."),0===t._fields_count?(h(p,"! my_update_node() no need to update... fields_count="+t._fields_count),t):Promise.resolve(t).then(te).then(function(e){return e._updated_node?de.my_save_node(e):e}).then(function(e){return e._updated_node?ue(e):e}).then(function(e){return h(p,">> updated-node res=",f.json(e._updated_node)),e}).catch(function(e){var r=e&&e.message||"";if(l(p,">> updated-node err=",r),0<r.indexOf("an attribute that does not exist in the item"))return ce(t);throw e})}(e)}).then(le).then(B)},a.do_increment=function(e,r){return z(e,r,"increment").then(Z).then(function(e){return 0===e._fields_count?e:function(e){if(!e._id)return Promise.reject(new Error(p+"_id is required!"));var r=e._id;return h(p,"- my_increment_node ("+r+")...."),0===e._fields_count?(h(p,"! my_increment_node() no need to increment... fields_count="+e._fields_count),e):Promise.resolve(e).then(ie).then(function(e){return e._updated_node?de.my_save_node(e):e}).then(function(e){return e._updated_node?ue(e):e}).then(function(e){return h(p,">> increment-node res=",f.json(e._updated_node)),e})}(e)}).then(le).then(B)},a.do_delete=function(e,r){return z(e,r,"delete").then(ee).then(ce).then(le).then(B)},a.do_destroy=function(e,r){return z(e,r,"destroy").then(me).then(le).then(B)},a.do_search=function(e,r){return z(e,r,"search").then(he).then(B)},a.on_records=function(e,r){return z(e,r,"on_records").then(pe).then(B)},a.do_initialize=function(e,r){return z(e,r,"initialize").then(ye).then(B)},a.do_terminate=function(e,r){return z(e,r,"terminate").then(Pe).then(B)},a.do_test_self=function(e,r){return z(e,r,"self-test").then(we).then(B)},a.do_next_id=function(){return Q({_id:0}).then(function(e){return e._id})},a};
"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};function _defineProperty(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}module.exports=function(e,r,t){var n=r||"LEM",f=e.U,m=e._,i=e.MS,d=e.DS,o=e.RS,u=e.ES,_=e.ES6;if(!f)throw new Error("$U is required!");if(!m)throw new Error("$U is required!");if(!i)throw new Error("$MS is required!");if(!d)throw new Error("$DS is required!");if(!o)throw new Error("$RS is required!");var h=e.log,s=e.inf,l=e.err,p=f.NS(n,"green"),a=t||{},c=function(e){throw new Error("NOT_IMPLEMENTED - "+p+":"+JSON.stringify(e))};a.do_prepare=c,a.do_create=c,a.do_clone=c,a.do_update=c,a.do_increment=c,a.do_read=c,a.do_delete=c,a.do_destroy=c,a.do_search=c,a.do_initialize=c,a.do_terminate=c,a.do_test_self=c,a.on_records=c,a.do_notify=c,a.do_subscribe=c,a.do_next_id=c,r.startsWith("_")||e(r,a);var v=function(e,r){return void 0===a[e]?r:a[e]},E=v("VERSION",1),y=v("REVISION",1),P=v("VERSION_NAME","V"),j=v("REVISION_NAME","R"),w=v("ID_INPUT","id"),g=v("ID_NAME","id"),S=v("ID_TYPE","test"),q=v("ID_NEXT",0),N=v("DYNA_TABLE","TestTable"),R=v("REDIS_PKEY","TPKEY"),b=v("FIELDS",null),O=v("DEFAULTS",null),T=v("CLONEABLE",!1),A=v("CLONED_ID","cloned"),x=v("PARENT_ID","parent"),I=v("PARENT_IMUT",!0),D=v("ES_INDEX","test-v1"),W=v("ES_TYPE","test"),M=v("ES_FIELDS",["updated_at","name"]),L=v("ES_MASTER",0),$=v("ES_VERSION",5),V=5<$?_:u;if(!V)throw new Error("$ES is required! Ver:"+$);var k=v("NS_NAME",""),U=require("dynamodb-value"),F=require("./notify-service")(e,"!"+k,{NS_NAME:k});a.do_notify=F.do_notify,a.do_subscribe=F.do_subscribe,T&&b&&(x&&b.indexOf(x)<0&&b.push(x),A&&b.indexOf(A)<0&&b.push(A));var Y=[w,g,"created_at","updated_at","deleted_at",A];I&&x&&Y.push(x);var z=function(e,r,t,n){t=t||"","object"===(void 0===(e=e||0)?"undefined":_typeof(e))?r=r?f.extend(e,r):e:(r=null==r?{}:"object"!==(void 0===r?"undefined":_typeof(r))||r instanceof Promise?{params:r}:f.copy(r),r=f.extend(r,{_id:e}));var i=r;if(void 0!==i.records)return f.promise(i);if(t.startsWith("notify"))return f.promise(i);if(i&&void 0!==i._is_prepared&&i._is_prepared)return i._current_mode=t,i._method_stack.push(t),1e3<i._method_stack.length?Promise.reject(p+"method-stack full. size:"+i._method_stack):f.promise(i);e=S.startsWith("#")?i._id||i[w]||"":f.N(i._id||i[w]||0);var o=i._current_time||f.current_time_ms();return i._id=e,i._current_time=o,i._current_mode=t,i._method_stack=[],i._method_stack.push(t),i._updated_node=null,i._ctx=n,i._node={},i._is_prepared=!0,void 0===i._params_count&&(i._params_count=0,i=m.reduce(i,function(e,r,t){return t.startsWith("_")||t.startsWith("$")||0<=Y.indexOf(t)||e._params_count++,e},i)),f.promise(i)},B=function(e){if(!e)return e;var r=e._current_mode||"";if(void 0!==e.records)return f.promise(e);if(r.startsWith("notify"))return f.promise(e);if(e._method_stack&&e._method_stack.pop(),"read"!==r&&"increment"!==r&&"create"!==r)return e;if(void 0!==e._auto_populate&&!e._auto_populate)return e;var t=e._node;return 0===e._params_count||-1===e._fields_count?e=m.reduce(t,function(e,r,t){return"updated_at"===t&&void 0!==e[t]?e[t]=e[t]>r?e[t]:r:e[t]=r,e},e):0<=e._fields_count&&(e=b?b.reduce(function(e,r){return void 0!==e[r]&&void 0!==t[r]&&(e[r]=t[r]),e},e):e),e},Q=function(r){var e=r._id;if(h(p,"- my_prepare_id("+S+", "+e+")...."),S.startsWith("#")){if(S&&S.startsWith("#")&&1<S.length&&0<q){var t=S.substring(1);return i.do_get_next_id(t).then(function(e){return h(p,"> created next-id["+t+"]=",e),r._id=e,r})}}else if(S&&!e)return i.do_get_next_id(S).then(function(e){return h(p,"> created next-id=",e),r._id=e,r});return h(p,"> prepared-id =",e),Promise.resolve(r)},H=function(t){if(!t._current_mode)throw new Error(p+"_current_mode is required!");var n=t._current_mode,i=O||{},o=0,e=t._node||{};return b?"prepare"===n||"create"===n||"clone"===n?e=b.reduce(function(e,r){return r===g||r===P||r===j||("prepare"===n?(void 0!==i[r]?e[r]=O[r]:void 0!==t[r]&&(e[r]=t[r]),P&&(e[P]=E),j&&(e[j]=0)):("create"===n&&j&&(e[j]=y-1),void 0!==t[r]&&(e[r]=t[r])),o++),e},e):"update"!==n&&"increment"!==n&&"read"!==n||(e=b.reduce(function(e,r){return r===g||void 0!==t[r]&&o++,e},e)):o=-1,t._fields_count=o,t._node=e,t},C=function(e,r){return e.created_at=0,e.updated_at=r,e.deleted_at=r,e},J=function(e,r){return e.created_at=r,e.updated_at=r,e.deleted_at=0,e},K=function(r){if(!r._node)return Promise.reject(new Error(p+"_node is required!"));if(!r._current_time)return Promise.reject(new Error(p+"_current_time is required!"));var t=r._id,n=(r._node,r._current_time);return t?ae(r).catch(function(e){return l(p,"not found. err=",e),r}).then(function(e){var r=(e=H(e))._node||{};if(e._force_create)l(p,"WARN! _force_create is set!");else if(!r.deleted_at)return l(p,"INVALID STATE FOR PREPARED. ID=",t,", TIMES[CUD]=",[r.created_at,r.updated_at,r.deleted_at]),Promise.reject(new Error(p+"INVALID STATE."));return e[w]=e._id,r[g]=e._id,e._node=C(e._node,n),e}):(r=H(r),Q(r).then(function(e){var r=e._node||{};return e[w]=e._id,r[g]=e._id,e._node=C(r,n),e}))},X=function(e){if(!e._id)return Promise.reject(new Error(p+"_id is required!"));if(!e._node)return Promise.reject(new Error(p+"_node is required!"));if(!e._current_time)return Promise.reject(new Error(p+"_current_time is required!"));var t=e._id,r=e._node,n=e._current_time;return h(p,"> prepared-id =",t,", current-time =",n,", node =",f.json(r)),ae(e).then(function(e){var r=(e=H(e))._node||{};if(e._force_create)l(p,"WARN! _force_create is set!");else if(!r.deleted_at)return l(p,"INVALID STATE FOR CREATED. ID=",t,", TIMES[CUD]=",[r.created_at,r.updated_at,r.deleted_at]),Promise.reject(new Error(p+"INVALID STATE."));return e._node=J(e._node,n),e})},G=function(e){if(!e._id)return Promise.reject(new Error(p+"_id is required!"));if(!e._node)return Promise.reject(new Error(p+"_node is required!"));if(!e._current_time)return Promise.reject(new Error(p+"_current_time is required!"));var r=e._id,t=e._node,n=e._current_time;return h(p,"> cloned-id =",r,", current-time =",n,", node =",f.json(t)),ae(e).then(function(e){return h(p,">> get-item-node old=",f.json(e._node)),(e=H(e))._node=J(e._node,n),e})},Z=function(e){if(!e._id)return Promise.reject(new Error(p+"_id is required!"));if(!e._node)return Promise.reject(new Error(p+"_node is required!"));if(!e._current_time)return Promise.reject(new Error(p+"_current_time is required!"));e._id,e._node;var n=e._current_time;return 0===(e=H(e))._fields_count?e:ae(e).then(function(e){var r,t;return e._node=(r=e._node,t=n,r.updated_at=t,r),e})},ee=function(e){if(!e._id)return Promise.reject(new Error(p+"_id is required!"));if(!e._node)return Promise.reject(new Error(p+"_node is required!"));if(!e._current_time)return Promise.reject(new Error(p+"_current_time is required!"));var r=e._id,t=e._node,n=e._current_time;return h(p,"> deleted-id =",r,", current-time =",n,", node =",f.json(t)),ae(e).then(function(e){var r,t;return h(p,">> get-item-node old=",f.json(e._node)),(e=H(e))._node=(r=e._node,t=n,r.updated_at=t,r.deleted_at=t,r),e})},re=function(r){var e;if(!r._id)return Promise.reject(new Error(p+"_id is required!"));var t=r._id;h(p,"- dynamo:my_read_node ("+t+")....");var n=S.startsWith("#")?"String":"";return d.do_get_item(N,(e={},_defineProperty(e,g,t),_defineProperty(e,"idType",n),e)).then(function(e){return h(p,"> dynamo:get-item-node("+t+") res=",f.json(e)),r._node=e,r})},te=function(r){if(!r._id)return Promise.reject(new Error(p+"_id is required!"));if(!r._node)return Promise.reject(new Error(p+"_node is required!"));var t=r._id,e=r._node,n={},i=0;for(var o in r)r.hasOwnProperty(o)&&(o=""+o)&&(o.startsWith("_")||o.startsWith("$")||0<=Y.indexOf(o)||b&&b.indexOf(o)<0||o&&(n[o]=r[o],e[o]=r[o],i++));return n.updated_at=e.updated_at,r._updated_node=null,(r._updated_count=i)?(void 0!==e[j]&&(e[j]=f.N(e[j],0)+1),d.do_update_item(N,_defineProperty({},g,t),n,j?_defineProperty({},j,1):null).then(function(e){return r._updated_node=n,h(p,"> dynamo:updated-item("+t+") res=",f.json(e)),r})):b?r:Promise.reject(new Error(p+"nothing to update"))},ne=function(r){if(!r._id)return Promise.reject(new Error(p+"_id is required!"));if(!r._node)return Promise.reject(new Error(p+"_node is required!"));var t=r._id,e=r._node,n=r._current_mode||"",i=r._current_time;if(h(p,"- dynamo:my_save_node("+t+")...."),h(p,"> dynamo:node-id =",t,", current-time =",i,", node =",f.json(e)),"prepare"!==n)for(var o in r)r.hasOwnProperty(o)&&(o=""+o)&&(o.startsWith("_")||o.startsWith("$")||0<=Y.indexOf(o)||b&&b.indexOf(o)<0||(e[o]=r[o]));return void 0!==e[j]&&(e[j]=f.N(e[j],0)+1),d.do_create_item(N,_defineProperty({},g,t),e).then(function(e){return h(p,"> dynamo:saved-item("+t+") res=",e),r})},ie=function(r){if(!r._id)return Promise.reject(new Error(p+"_id is required!"));if(!r._node)return Promise.reject(new Error(p+"_node is required!"));var t=r._id,e=r._node,n={},i=0;for(var o in r)r.hasOwnProperty(o)&&((o=""+o).startsWith("_")||o.startsWith("$")||0<=Y.indexOf(o)||b&&b.indexOf(o)<0||o&&(n[o]=r[o],e[o]=f.N(e[o],0)+f.N(r[o]),i++));return n.updated_at=e.updated_at,h(p,"> dynamo:increment-node =",n),r._updated_node=null,(r._updated_count=i)?(void 0!==e[j]&&(e[j]=f.N(e[j],0)+1),d.do_increment_item(N,_defineProperty({},g,t),n,j?_defineProperty({},j,1):null).then(function(e){return h(p,"> dynamo:updated-item("+t+") res=",f.json(e)),r._updated_node=n,r})):b?r:Promise.reject(new Error(p+"nothing to update"))},oe=function(r){if(!r._id)return Promise.reject(new Error(p+"_id is required!"));var t=r._id;return d.do_delete_item(N,_defineProperty({},g,t)).then(function(e){return h(p,"> dynamo:deleted-item-node("+t+") res=",f.json(e)),r._node=e||{},r})},de={my_read_node:function(r){if(!r._id)return Promise.reject(new Error(p+"_id is required!"));if(!R)return Promise.reject(r);var t=r._id;return o.do_get_item(R,t).then(function(e){return e?(r._node=e,r):Promise.reject(r)}).catch(function(e){throw e instanceof Error&&(l(p,"! redis:get-item("+R+", "+t+") err =",e.message||e),r._error=e),r})},my_save_node:function(r){if(!r._id)return Promise.reject(new Error(p+"_id is required!"));if(!r._node)return Promise.reject(new Error(p+"_node is required!"));if(!R)return Promise.resolve(r);var t=r._id,e=r._node;h(p,"- redis:my_save_node("+R+":"+t+"). node=",f.json(e));var n=de.my_set_node_footprint(t,e);return n=n.then(function(){return o.do_create_item(R,t,e)}).then(function(e){return h(p,"> redis:save-item-node("+t+") res=",f.json(e)),r})},my_update_node:function(r){if(!r._id)return Promise.reject(new Error(p+"_id is required!"));if(!r._node)return Promise.reject(new Error(p+"_node is required!"));if(!R)return Promise.resolve(r);var t=r._id,e=r._node,n=de.my_set_node_footprint(t,e);return n=n.then(function(){return o.do_update_item(R,t,e)}).then(function(e){return h(p,"> redis:update-item-node("+t+") res=",f.json(e)),r})},my_delete_node:function(r){if(!r._id)return Promise.reject(new Error(p+"_id is required!"));if(!R)return Promise.resolve(r);var t=r._id;return o.do_delete_item(R,t).then(function(e){return h(p,"> redis:delete-item-node("+t+") res=",f.json(e)),r})},my_set_node_footprint:function(r,e){if(!r)return Promise.reject(new Error(p+"id is required!"));if(!R)return Promise.resolve(0);e=e||{};var t=f.N(e.updated_at,0),n=f.hash(e);return o.do_create_item([R+"/UPDATED",R+"/HASH"],r,[t,n]).then(function(e){return h(p,"> redis:set node-footprint("+r+") res=",f.json(e)),e})},my_get_updated_at:function(e){return e?R?o.do_get_item(R+"/UPDATED",e).then(function(e){return e}):Promise.resolve(-1):Promise.reject(new Error(p+"id is required!"))},my_get_hash_value:function(e){return e?R?o.do_get_item(R+"/HASH",e).then(function(e){return e}):Promise.resolve(-1):Promise.reject(new Error(p+"id is required!"))}},ue=function(r){if(!r._id)return Promise.reject(new Error(p+"elasticsearch:_id is required!"));if(!r._node)return Promise.reject(new Error(p+"elasticsearch:_node is required!"));if(!D||!W)return r;var t=r._id,n=r._node;if(M){var e=m.reduce(M,function(e,r){return void 0!==n[r]&&(e[r]=n[r]),e},{});return Object.keys(e).length?(void 0!==n.created_at&&(e.created_at=n.created_at),void 0!==n.updated_at&&(e.updated_at=n.updated_at),void 0!==n.deleted_at&&(e.deleted_at=n.deleted_at),L?V.do_create_item(D,W,t,e).then(function(e){return h(p,"! elasticsearch:saved-item("+t+") res=",f.json(e)),r}):V.do_update_item(D,W,t,e).then(function(e){return h(p,"! elasticsearch:updated-item("+t+") res=",f.json(e)),r})):(h(p,"! elasticsearch:WARN! nothing to update ("+t+")...."),r)}return V.do_create_item(D,W,t,n).then(function(e){return h(p,"! elasticsearch:saved-item2("+t+") res=",f.json(e)),r})},_e=function(r){if(!r._id)return Promise.reject(new Error(p+"elasticsearch:_id is required!"));if(!D||!W)return r;var t=r._id;return M&&!L?(h(p,"! elasticsearch:WARN! ignore delete ("+t+")...."),r):V.do_delete_item(D,W,t).then(function(e){return h(p,"! elasticsearch:deleted-item("+t+") res=",f.json(e)),r})},se=function(i){if(!D||!W)return i;if(h(p,"- elasticsearch:do_search_item()...."),M&&!L)return h(p,"! elasticsearch:WARN! ignore search ()...."),i;var o={$page:0,$limit:0};return o.$page=f.N(i.page||0),o.$limit=f.N(0===i.ipp?0:i.ipp||10),o.deleted_at="0",i.$source&&(o.$source=i.$source),i.Q&&(o.$Q=i.Q),i.A&&(o.$A=i.A),i.O&&(o.$O=i.O),o.$O=o.$O||(S.startsWith("#")?"id.keyword":"id"),M&&M.forEach(function(e){void 0!==i[e]&&(o[e]=i[e]),void 0!==i["!"+e]&&(o["!"+e]=i["!"+e]),void 0!==i["#"+e]&&(o["#"+e]=i["#"+e])}),V.do_search_item(D,W,o).then(function(e){var r=e&&e.hits||{},t=r.hits||[],n=r;return i.list=t.map(function(e){return f.extend({_score:e._score},e._source)}),i.total=f.N(n.total||0),i.page=o.$page,i.ipp=o.$limit,i.took=e.took||0,void 0!==e.aggregations&&(i.aggregations=e.aggregations),i}).catch(function(e){throw l(p,"!ERR =",e),e})},ae=function(e){if(!e._id)return Promise.reject(new Error(p+"_id is required!"));e._id;return Promise.resolve(e).then(de.my_read_node).catch(function(e){return re(e).then(function(e){return void 0===(e._node||{})[g]?Promise.reject(new Error(p+"404 NOT FOUND. "+N+".id:"+(e._id||""))):e}).then(de.my_save_node)})},ce=function(e){if(!e._id)return Promise.reject(new Error(p+"_id is required!"));if(!e._node)return Promise.reject(new Error(p+"_node is required!"));e._id;return Promise.resolve(e).then(ne).then(de.my_save_node).then(ue).then(function(e){return e})},fe=function(e){if(!e._id)return Promise.reject(new Error(p+"_id is required!"));if(!e._node)return Promise.reject(new Error(p+"_node is required!"));if(!e._current_time)return Promise.reject(new Error(p+"_current_time is required!"));var r=e._id;return h(p,"- my_clone_node ("+r+")...."),Promise.resolve(e).then(function(n){if(!T)return n;var e=n._id,i=void 0!==n[x]?f.N(n[x],0):e,o=e;return Q({_id:0}).then(function(e){var r=e._id,t=n._node||{};return t[g]=r,x&&(t[x]=i),A&&(t[A]=o),x&&(n[x]=i),A&&(n[A]=o),n._clone_id=r,n._node=t,n})}).then(function(e){if(!e._id)return Promise.reject(new Error(p+"_id is required!"));if(!e._node)return Promise.reject(new Error(p+"_node is required!"));if(!e._clone_id)return Promise.reject(new Error(p+"_clone_id is required!"));var r=e._id;return e._id=e._clone_id,m.reduce(e,function(e,r,t){return t&&(t.startsWith("_")||t.startsWith("$")||0<=Y.indexOf(t)||void 0!==e[t]&&(e[t]=r)),e},e._node),h(p,">> before save-node().. that._node =",f.json(e._node)),ce(e).then(function(){return e._id=r,e})}).then(function(e){return h(p,">> cloned-node["+e._id+" -> "+e._clone_id+"] res=",f.json(e._node)),e})},me=function(e){if(!e._id)return Promise.reject(new Error(p+"_id is required!"));var r=e._id;return h(p,"- my_delete_node ("+r+")...."),Promise.resolve(e).then(oe).then(de.my_delete_node).then(_e).then(function(e){return h(p,">> deleted-node res=",f.json(e._node)),e})},he=function(e){return h(p,"- my_search_node ()...."),Promise.resolve(e).then(se).then(function(e){return e})},le=function(e){if(!e)return e;if(!e._id)return Promise.reject(new Error(p+"_id is required!"));e._id;var n=e._current_mode;return Promise.resolve(e).then(function(r){var e=!1;if("create"===n||"prepare"===n||"delete"===n||"destroy"===n?e=!0:"update"!==n&&"increment"!==n||(e=0<r._fields_count),e){var t=k+":event:"+n;return h(p,">>> notify event-id:",t,", notifiable=",e),Ee(t,r).then(function(e){return r})}return r})},pe=function(r){if(!r.records)return Promise.reject(new Error(p+"records is required!"));var e=r.records.slice(0);if(h(p,"- my_event_records().... records.len=",e.length),!e.length)return r;var t,n,i;return(t=e,n=ve,i=f.promise(t.shift()),i=t.reduce(function(e,r){return e.then(function(){return n(r)})},i.then(function(e){return n(e)}))).catch(function(e){return l(p,"error ignored! =",e),r}).then(function(){return r})},ve=function(e){if(!e)return Promise.reject(new Error("record is required"));if(!e.dynamodb&&!e.Sns)return Promise.reject(new Error("record.dynamodb|Sns is required"));var i=e.eventName||"EVENT",r=null;if(e.dynamodb){var o=e.table||e.eventSourceARN&&e.eventSourceARN.split("/")[1]||"";if(h(p,"--- process-record("+o+") ... "),N!==o)return h(p,"! ignore record-table: "+N+" != "+o+" "),e;var t=e.dynamodb.Keys?U.toJavascript(e.dynamodb.Keys):{},d=e.dynamodb.NewImage?U.toJavascript(e.dynamodb.NewImage):null,n=e.dynamodb.OldImage?U.toJavascript(e.dynamodb.OldImage):null,u=t[g],_="MODIFY"===i?f.diff(n,d):null,s=f.N(d&&d.updated_at||0),a=_?m.reduce(_,function(e,r){return e[r]=n[r],e},{}):null,c={_id:u,_node:d,_updated_at:s,_diff:_,_prev:a};switch(r=Promise.resolve(c),_&&h(p,">> "+o+".different["+u+"]=",f.json(_)),i){case"INSERT":case"MODIFY":r=r.then(function(t){var n=t._id;return de.my_get_updated_at(n).then(function(e){if(l(p,">> "+o+".updated_at["+n+"] res=",e," <- ",t._updated_at,t._updated_at!==e?"*":""),!e||t._updated_at>=e){var r=f.hash(d);return de.my_get_hash_value(n).then(function(e){return e&&e===r?(h(p,"! WARN! ignored due to hash-value matching =",e),t):(h(p,"! INFO! node was updated. hash :=",r,"<-",e),de.my_save_node(t).then(ue))})}return h(p,"! ignored due to old-record"),t})});break;case"REMOVE":h(p,">> removed!"),r=(r=r.then(de.my_delete_node)).then(_e)}}else e.Sns&&(h(p,">> event-SNS =",e.Sns),r=Promise.resolve(e.Sns));return r?r.then(function(r){var e={INSERT:"create",MODIFY:"update",REMOVE:"delete",EVENT:"event"}[i],t=!!e;if(r._current_mode=e,t){var n=k+":record:"+e;return h(p,">>> notify event-id:",n,", notifiable=",t),Ee(n,r).then(function(e){return r})}return r}).then(function(){return e}):Promise.reject(new Error("invalid chain!"))},Ee=function(e,r){return F.do_notify(e,r)},ye=function(r){var e=[];if(N){var t=S.startsWith("#")?"S":"N";e.push(Promise.resolve("DynamoDb").then(function(e){return h(p,"# initialize ",e),d.do_create_table(N,g,t).then(function(e){return e.TableDescription.TableName===N})}).catch(function(e){if("ResourceInUseException"===e.code)return!1;throw e}))}else h(p,"DS: WARN! ignored configuration. DYNA_TABLE=",N);if(S&&!S.startsWith("#")?e.push(Promise.resolve("MySQL").then(function(e){return h(p,"# initialize MySQL (Sequence) "),i.do_create_id_seq(S,q).then(function(e){return h(p,"> create-id-seq res=",e),!0})}).catch(function(e){if("ER_TABLE_EXISTS_ERROR"===e.code)return!1;throw e})):S&&S.startsWith("#")&&1<S.length&&0<q?e.push(Promise.resolve("MySQL").then(function(e){h(p,"# initialize MySQL (Sequence) ");var r=S.substring(1);return i.do_create_id_seq(r,q).then(function(e){return h(p,"> create-id-seq["+r+"] res=",e),!0})}).catch(function(e){if("ER_TABLE_EXISTS_ERROR"===e.code)return!1;throw e})):h(p,"MS: WARN! ignored configuration. ID_TYPE=",S),D&&W&&M){var n={mappings:{_default_:{dynamic_templates:[{string_fields:{match:"*_multi",match_mapping_type:"string",mapping:{type:"multi_field",fields:{"{name}":{type:6<=$?"text":"string",index:"analyzed",omit_norms:!0,index_options:"docs"},"{name}.raw":{type:6<=$?"text":"string",index:"not_analyzed",ignore_above:256}}}}}],properties:{"@version":{type:6<=$?"text":"string",index:!(6<=$)&&"not_analyzed"},title:{type:6<=$?"text":"string"},name:{type:6<=$?"text":"string"},created_at:{type:"date",format:"strict_date_optional_time||epoch_millis"},updated_at:{type:"date",format:"strict_date_optional_time||epoch_millis"},deleted_at:{type:"date",format:"strict_date_optional_time||epoch_millis"}}}}};6<=$||(n.mappings._default_.all={enabled:!0}),e.push(Promise.resolve("ElasticSearch").then(function(e){return h(p,"# initialize ElasticSearch (Type) ",W),V.do_create_index_type(D,W,n).then(function(e){return h(p,"> create-es-index res=",e),!0})}).catch(function(e){if(l(p,"> create-es-index error=",e),"index_already_exists_exception"===e.type)return!0;throw e}).then(function(e){return e}))}else h(p,"MS: WARN! ignored configuration. ES_TYPE=",W);return Promise.all(e).then(function(e){return h(p,">> results=",e),r._result=e,r})},Pe=function(r){var e=[];if(N&&(h(p,"# terminate DynamoDB"),e.push(d.do_delete_table(N).then(function(e){return e.TableDescription.TableName===N}).catch(function(e){if("ResourceNotFoundException"===e.code)return!0;throw e}))),S&&!S.startsWith("#"))h(p,"# terminate MySQL (Sequence) "),e.push(i.do_delete_id_seq(S).then(function(e){return h(p,"> delete-id-seq res=",e),!0}).catch(function(e){if("ER_BAD_TABLE_ERROR"===e.code)return!0;throw e}));else if(S&&S.startsWith("#")&&1<S.length&&0<q){h(p,"# terminate MySQL (Sequence) ");var t=S.substring(1);e.push(i.do_delete_id_seq(t).then(function(e){return h(p,"> delete-id-seq["+t+"] res=",e),!0}).catch(function(e){if("ER_BAD_TABLE_ERROR"===e.code)return!0;throw e}))}else h(p,"# ignored MySQL (Sequence) ");return D&&W?(h(p,"# terminate ES (Index) "),e.push(V.do_delete_index_type(D,null).then(function(e){return h(p,"> delete-es-index res=",e),!0}).catch(function(e){throw l(p,"> create-es-index error=",e),e}))):h(p,"# ignored ES (Index) "),Promise.all(e).then(function(e){return h(p,">> results=",e),r._result=e,r})},je=function(e){var r={a:1,b:2,x:3},t={x:3,a:1,b:2},n={b:2,x:3,a:1};r.name="hi",t.name="hi",n.name="hi",h(p,"# node1 =",f.json(r)),h(p,"> node2 =",f.json(t)),h(p,"> node3 =",f.json(n)),h(p,"# node1.sorted =",f.json(r,!0)),h(p,"> node2.sorted =",f.json(t,!0)),h(p,"> node3.sorted =",f.json(n,!0)),h(p,"# hash1 =",f.hash(1)),h(p,"> node1 =",f.hash(r)),h(p,"> node2 =",f.hash(t)),h(p,"> node3 =",f.hash(n));var i={updated_at:234,name:"test hash"};return Promise.resolve(i).then(function(e){return o.do_create_item("H#",1,e)}).then(function(){return o.do_get_item("H#",1).then(function(e){return h(p,"> read-back data=",e),e})}).then(function(){return de.my_set_node_footprint(1,i)}).then(function(){return de.my_get_updated_at(1).then(function(e){return h(p,"> updated-at value=",void 0===e?"undefined":_typeof(e),":",e),e})}).then(function(){return de.my_get_hash_value(1).then(function(e){return h(p,"> hash-value value=",void 0===e?"undefined":_typeof(e),":",e),e})})},we=function(r){return h(p,"- my_test_self()...."),Promise.resolve(r).then(je).then(function(e){return e||r})};return a.do_prepare_chain=function(e,r,t,n){return z(e,r,t,n)},a.do_finish_chain=function(e,r,t,n){return B(e)},a.do_prepare=function(e,r){return z(e,r,"prepare").then(K).then(ce).then(le).then(B)},a.do_create=function(t,n){return z(t,n,"create").then(X).catch(function(e){l(p,"ERR! prepare_node_created =",e instanceof Error,e.message||e);var r=e&&e.message||"";if(e instanceof Error&&0<=r.indexOf("404 NOT FOUND"))return s(p,"WARN! AUTO TRY TO PREPARE NODE. ID="+t),z(t,n,"create").then(function(e){var r=e._current_time;return e=H(e),h(p,">> prepared old-node=",f.json(e._node)),e._node=J(e._node,r),e});throw e}).then(ce).then(le).then(B)},a.do_clone=function(e,r){return z(e,r,"clone").then(G).then(fe).then(le).then(B)},a.do_read=function(e,r){return z(e,r,"read").then(H).then(function(e){return 0!==e._params_count&&0===e._fields_count?e:ae(e)}).then(le).then(B)},a.do_update=function(e,r){return z(e,r,"update").then(Z).then(function(e){return 0===e._fields_count?e:function(t){if(!t._id)return Promise.reject(new Error(p+"_id is required!"));var e=t._id;return h(p,"- my_update_node ("+e+")...."),0===t._fields_count?(h(p,"! my_update_node() no need to update... fields_count="+t._fields_count),t):Promise.resolve(t).then(te).then(function(e){return e._updated_node?de.my_save_node(e):e}).then(function(e){return e._updated_node?ue(e):e}).then(function(e){return h(p,">> updated-node res=",f.json(e._updated_node)),e}).catch(function(e){var r=e&&e.message||"";if(l(p,">> updated-node err=",r),0<r.indexOf("an attribute that does not exist in the item"))return ce(t);throw e})}(e)}).then(le).then(B)},a.do_increment=function(e,r){return z(e,r,"increment").then(Z).then(function(e){return 0===e._fields_count?e:function(e){if(!e._id)return Promise.reject(new Error(p+"_id is required!"));var r=e._id;return h(p,"- my_increment_node ("+r+")...."),0===e._fields_count?(h(p,"! my_increment_node() no need to increment... fields_count="+e._fields_count),e):Promise.resolve(e).then(ie).then(function(e){return e._updated_node?de.my_save_node(e):e}).then(function(e){return e._updated_node?ue(e):e}).then(function(e){return h(p,">> increment-node res=",f.json(e._updated_node)),e})}(e)}).then(le).then(B)},a.do_delete=function(e,r){return z(e,r,"delete").then(ee).then(ce).then(le).then(B)},a.do_destroy=function(e,r){return z(e,r,"destroy").then(me).then(le).then(B)},a.do_search=function(e,r){return z(e,r,"search").then(he).then(B)},a.on_records=function(e,r){return z(e,r,"on_records").then(pe).then(B)},a.do_initialize=function(e,r){return z(e,r,"initialize").then(ye).then(B)},a.do_terminate=function(e,r){return z(e,r,"terminate").then(Pe).then(B)},a.do_test_self=function(e,r){return z(e,r,"self-test").then(we).then(B)},a.do_next_id=function(){return Q({_id:0}).then(function(e){return e._id})},a};
{
"name": "lemoncloud-engine-js",
"version": "0.3.10",
"version": "0.3.11",
"description": "lemoncloud.io - core engine module with user/group/chat service.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -87,2 +87,3 @@ # lemoncloud-engine-js

|-- |--
| 0.3.11 | allow ipp to be set 0.
| 0.3.10 | sns-proxy as 'SN'

@@ -89,0 +90,0 @@ | 0.3.9 | support ES6 with `ES_VERSION = 6`.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc