@hotmeshio/hotmesh 0.3.32 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/README.md +128 -823
  2. package/build/index.d.ts +9 -9
  3. package/build/index.js +10 -10
  4. package/build/modules/enums.d.ts +23 -23
  5. package/build/modules/enums.js +26 -26
  6. package/build/modules/errors.d.ts +16 -16
  7. package/build/modules/errors.js +28 -28
  8. package/build/modules/key.js +190 -1
  9. package/build/modules/utils.js +374 -1
  10. package/build/package.json +22 -21
  11. package/build/services/activities/activity.js +549 -1
  12. package/build/services/activities/await.js +114 -1
  13. package/build/services/activities/cycle.js +112 -1
  14. package/build/services/activities/hook.js +168 -1
  15. package/build/services/activities/index.js +20 -1
  16. package/build/services/activities/interrupt.js +158 -1
  17. package/build/services/activities/signal.js +134 -1
  18. package/build/services/activities/trigger.js +246 -1
  19. package/build/services/activities/worker.js +106 -1
  20. package/build/services/collator/index.js +293 -1
  21. package/build/services/compiler/deployer.js +488 -1
  22. package/build/services/compiler/index.js +112 -1
  23. package/build/services/compiler/validator.js +147 -1
  24. package/build/services/engine/index.js +761 -1
  25. package/build/services/exporter/index.js +126 -1
  26. package/build/services/hotmesh/index.d.ts +160 -17
  27. package/build/services/hotmesh/index.js +160 -17
  28. package/build/services/mapper/index.js +81 -1
  29. package/build/services/{meshflow → memflow}/client.d.ts +3 -3
  30. package/build/services/{meshflow → memflow}/client.js +17 -16
  31. package/build/services/{meshflow → memflow}/connection.d.ts +2 -2
  32. package/build/services/{meshflow → memflow}/connection.js +1 -1
  33. package/build/services/memflow/context.d.ts +143 -0
  34. package/build/services/memflow/context.js +299 -0
  35. package/build/services/{meshflow → memflow}/exporter.d.ts +6 -6
  36. package/build/services/memflow/exporter.js +215 -0
  37. package/build/services/{meshflow → memflow}/handle.d.ts +4 -4
  38. package/build/services/{meshflow → memflow}/handle.js +2 -2
  39. package/build/services/{meshflow → memflow}/index.d.ts +18 -13
  40. package/build/services/{meshflow → memflow}/index.js +26 -21
  41. package/build/services/{meshflow → memflow}/schemas/factory.d.ts +4 -4
  42. package/build/services/{meshflow → memflow}/schemas/factory.js +5 -5
  43. package/build/services/{meshflow → memflow}/search.d.ts +1 -1
  44. package/build/services/{meshflow → memflow}/search.js +4 -4
  45. package/build/services/{meshflow → memflow}/worker.d.ts +5 -5
  46. package/build/services/{meshflow → memflow}/worker.js +24 -24
  47. package/build/services/memflow/workflow/common.d.ts +20 -0
  48. package/build/services/memflow/workflow/common.js +47 -0
  49. package/build/services/memflow/workflow/contextMethods.d.ts +14 -0
  50. package/build/services/memflow/workflow/contextMethods.js +33 -0
  51. package/build/services/{meshflow → memflow}/workflow/execChild.js +12 -12
  52. package/build/services/memflow/workflow/execHook.d.ts +65 -0
  53. package/build/services/memflow/workflow/execHook.js +73 -0
  54. package/build/services/{meshflow → memflow}/workflow/hook.js +19 -3
  55. package/build/services/{meshflow → memflow}/workflow/index.d.ts +7 -3
  56. package/build/services/{meshflow → memflow}/workflow/index.js +7 -3
  57. package/build/services/{meshflow → memflow}/workflow/proxyActivities.d.ts +2 -2
  58. package/build/services/{meshflow → memflow}/workflow/proxyActivities.js +8 -8
  59. package/build/services/{meshflow → memflow}/workflow/sleepFor.js +2 -2
  60. package/build/services/{meshflow → memflow}/workflow/waitFor.js +2 -2
  61. package/build/services/meshdata/index.d.ts +24 -24
  62. package/build/services/meshdata/index.js +40 -40
  63. package/build/services/pipe/functions/array.js +74 -1
  64. package/build/services/pipe/functions/bitwise.js +24 -1
  65. package/build/services/pipe/functions/conditional.js +36 -1
  66. package/build/services/pipe/functions/cron.js +40 -1
  67. package/build/services/pipe/functions/date.js +171 -1
  68. package/build/services/pipe/functions/index.js +30 -1
  69. package/build/services/pipe/functions/json.js +12 -1
  70. package/build/services/pipe/functions/logical.js +12 -1
  71. package/build/services/pipe/functions/math.js +184 -1
  72. package/build/services/pipe/functions/number.js +60 -1
  73. package/build/services/pipe/functions/object.js +81 -1
  74. package/build/services/pipe/functions/string.js +69 -1
  75. package/build/services/pipe/functions/symbol.js +33 -1
  76. package/build/services/pipe/functions/unary.js +18 -1
  77. package/build/services/pipe/index.js +242 -1
  78. package/build/services/quorum/index.js +263 -1
  79. package/build/services/reporter/index.js +348 -1
  80. package/build/services/router/config/index.d.ts +11 -0
  81. package/build/services/router/config/index.js +36 -0
  82. package/build/services/router/consumption/index.d.ts +34 -0
  83. package/build/services/router/consumption/index.js +395 -0
  84. package/build/services/router/error-handling/index.d.ts +8 -0
  85. package/build/services/router/error-handling/index.js +98 -0
  86. package/build/services/router/index.d.ts +13 -16
  87. package/build/services/router/index.js +121 -1
  88. package/build/services/router/lifecycle/index.d.ts +27 -0
  89. package/build/services/router/lifecycle/index.js +80 -0
  90. package/build/services/router/telemetry/index.d.ts +11 -0
  91. package/build/services/router/telemetry/index.js +32 -0
  92. package/build/services/router/throttling/index.d.ts +23 -0
  93. package/build/services/router/throttling/index.js +76 -0
  94. package/build/services/search/index.d.ts +2 -1
  95. package/build/services/search/providers/postgres/postgres.d.ts +2 -1
  96. package/build/services/search/providers/postgres/postgres.js +149 -1
  97. package/build/services/search/providers/redis/ioredis.d.ts +1 -0
  98. package/build/services/search/providers/redis/ioredis.js +121 -1
  99. package/build/services/search/providers/redis/redis.d.ts +1 -0
  100. package/build/services/search/providers/redis/redis.js +134 -1
  101. package/build/services/serializer/index.js +282 -1
  102. package/build/services/store/providers/postgres/kvsql.d.ts +1 -1
  103. package/build/services/store/providers/postgres/kvsql.js +198 -1
  104. package/build/services/store/providers/postgres/kvtables.js +441 -1
  105. package/build/services/store/providers/postgres/kvtransaction.js +248 -1
  106. package/build/services/store/providers/postgres/kvtypes/hash.d.ts +1 -1
  107. package/build/services/store/providers/postgres/kvtypes/hash.js +1287 -1
  108. package/build/services/store/providers/postgres/kvtypes/list.js +194 -1
  109. package/build/services/store/providers/postgres/kvtypes/string.js +115 -1
  110. package/build/services/store/providers/postgres/kvtypes/zset.js +214 -1
  111. package/build/services/store/providers/postgres/postgres.js +1036 -1
  112. package/build/services/store/providers/redis/_base.js +980 -1
  113. package/build/services/store/providers/redis/ioredis.js +180 -1
  114. package/build/services/store/providers/redis/redis.js +199 -1
  115. package/build/services/store/providers/store-initializable.js +2 -1
  116. package/build/services/stream/index.d.ts +5 -0
  117. package/build/services/stream/providers/nats/nats.d.ts +1 -0
  118. package/build/services/stream/providers/nats/nats.js +225 -1
  119. package/build/services/stream/providers/postgres/kvtables.d.ts +1 -0
  120. package/build/services/stream/providers/postgres/kvtables.js +146 -1
  121. package/build/services/stream/providers/postgres/postgres.d.ts +19 -0
  122. package/build/services/stream/providers/postgres/postgres.js +519 -1
  123. package/build/services/stream/providers/redis/ioredis.d.ts +1 -0
  124. package/build/services/stream/providers/redis/ioredis.js +272 -1
  125. package/build/services/stream/providers/redis/redis.d.ts +1 -0
  126. package/build/services/stream/providers/redis/redis.js +305 -1
  127. package/build/services/stream/providers/stream-initializable.js +2 -1
  128. package/build/services/sub/providers/nats/nats.js +105 -1
  129. package/build/services/sub/providers/postgres/postgres.js +92 -1
  130. package/build/services/sub/providers/redis/ioredis.js +81 -1
  131. package/build/services/sub/providers/redis/redis.js +72 -1
  132. package/build/services/task/index.js +206 -1
  133. package/build/services/telemetry/index.js +306 -1
  134. package/build/services/worker/index.js +197 -1
  135. package/build/types/error.d.ts +5 -5
  136. package/build/types/exporter.d.ts +1 -1
  137. package/build/types/index.d.ts +3 -3
  138. package/build/types/manifest.d.ts +2 -2
  139. package/build/types/{meshflow.d.ts → memflow.d.ts} +15 -15
  140. package/build/types/meshdata.d.ts +3 -3
  141. package/build/types/postgres.d.ts +7 -0
  142. package/build/types/stream.d.ts +3 -0
  143. package/index.ts +11 -11
  144. package/package.json +22 -21
  145. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  146. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  147. package/build/services/meshflow/exporter.js +0 -1
  148. package/build/services/meshflow/workflow/common.d.ts +0 -18
  149. package/build/services/meshflow/workflow/common.js +0 -45
  150. package/typedoc.json +0 -46
  151. package/types/activity.ts +0 -268
  152. package/types/app.ts +0 -20
  153. package/types/async.ts +0 -6
  154. package/types/cache.ts +0 -1
  155. package/types/collator.ts +0 -9
  156. package/types/error.ts +0 -56
  157. package/types/exporter.ts +0 -102
  158. package/types/hook.ts +0 -44
  159. package/types/hotmesh.ts +0 -314
  160. package/types/index.ts +0 -306
  161. package/types/job.ts +0 -233
  162. package/types/logger.ts +0 -8
  163. package/types/manifest.ts +0 -70
  164. package/types/map.ts +0 -5
  165. package/types/meshcall.ts +0 -235
  166. package/types/meshdata.ts +0 -278
  167. package/types/meshflow.ts +0 -645
  168. package/types/ms.d.ts +0 -7
  169. package/types/nats.ts +0 -270
  170. package/types/pipe.ts +0 -90
  171. package/types/postgres.ts +0 -105
  172. package/types/provider.ts +0 -161
  173. package/types/quorum.ts +0 -167
  174. package/types/redis.ts +0 -404
  175. package/types/serializer.ts +0 -40
  176. package/types/stats.ts +0 -117
  177. package/types/stream.ts +0 -227
  178. package/types/task.ts +0 -7
  179. package/types/telemetry.ts +0 -16
  180. package/types/transition.ts +0 -20
  181. /package/build/services/{meshflow → memflow}/workflow/all.d.ts +0 -0
  182. /package/build/services/{meshflow → memflow}/workflow/all.js +0 -0
  183. /package/build/services/{meshflow → memflow}/workflow/context.d.ts +0 -0
  184. /package/build/services/{meshflow → memflow}/workflow/context.js +0 -0
  185. /package/build/services/{meshflow → memflow}/workflow/didRun.d.ts +0 -0
  186. /package/build/services/{meshflow → memflow}/workflow/didRun.js +0 -0
  187. /package/build/services/{meshflow → memflow}/workflow/emit.d.ts +0 -0
  188. /package/build/services/{meshflow → memflow}/workflow/emit.js +0 -0
  189. /package/build/services/{meshflow → memflow}/workflow/enrich.d.ts +0 -0
  190. /package/build/services/{meshflow → memflow}/workflow/enrich.js +0 -0
  191. /package/build/services/{meshflow → memflow}/workflow/execChild.d.ts +0 -0
  192. /package/build/services/{meshflow → memflow}/workflow/hook.d.ts +0 -0
  193. /package/build/services/{meshflow → memflow}/workflow/interrupt.d.ts +0 -0
  194. /package/build/services/{meshflow → memflow}/workflow/interrupt.js +0 -0
  195. /package/build/services/{meshflow → memflow}/workflow/isSideEffectAllowed.d.ts +0 -0
  196. /package/build/services/{meshflow → memflow}/workflow/isSideEffectAllowed.js +0 -0
  197. /package/build/services/{meshflow → memflow}/workflow/random.d.ts +0 -0
  198. /package/build/services/{meshflow → memflow}/workflow/random.js +0 -0
  199. /package/build/services/{meshflow → memflow}/workflow/searchMethods.d.ts +0 -0
  200. /package/build/services/{meshflow → memflow}/workflow/searchMethods.js +0 -0
  201. /package/build/services/{meshflow → memflow}/workflow/signal.d.ts +0 -0
  202. /package/build/services/{meshflow → memflow}/workflow/signal.js +0 -0
  203. /package/build/services/{meshflow → memflow}/workflow/sleepFor.d.ts +0 -0
  204. /package/build/services/{meshflow → memflow}/workflow/trace.d.ts +0 -0
  205. /package/build/services/{meshflow → memflow}/workflow/trace.js +0 -0
  206. /package/build/services/{meshflow → memflow}/workflow/waitFor.d.ts +0 -0
  207. /package/build/types/{meshflow.js → memflow.js} +0 -0
@@ -1 +1,33 @@
1
- 'use strict';var i=b;(function(c,d){var h=b,e=c();while(!![]){try{var f=parseInt(h(0x1b6))/0x1+parseInt(h(0x1b9))/0x2*(parseInt(h(0x1b2))/0x3)+-parseInt(h(0x1b7))/0x4*(parseInt(h(0x1b1))/0x5)+-parseInt(h(0x1bd))/0x6+-parseInt(h(0x1ba))/0x7*(parseInt(h(0x1b4))/0x8)+-parseInt(h(0x1c3))/0x9+parseInt(h(0x1b8))/0xa*(parseInt(h(0x1bc))/0xb);if(f===d)break;else e['push'](e['shift']());}catch(g){e['push'](e['shift']());}}}(a,0x75483));function b(c,d){var e=a();return b=function(f,g){f=f-0x1b1;var h=e[f];return h;},b(c,d);}function a(){var j=['NaN','5202009VmXNbg','20QcMBkm','29598eLhRvF','date','40RIbQVR','object','714997kgauZy','505860hSHNaZ','9510eyQVEM','140kmZTdb','398839QtuERN','whitespace','15708QLeBva','5487072ZyWWUb','posInfinity','negInfinity','null','SymbolHandler'];a=function(){return j;};return a();}Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports[i(0x1c1)]=void 0x0;class SymbolHandler{[i(0x1c0)](){return null;}['undefined'](){}[i(0x1bb)](){return'\x20';}[i(0x1b5)](){return{};}['array'](){return[];}[i(0x1be)](){return 0x1/0x0;}[i(0x1bf)](){return-0x1/0x0;}[i(0x1c2)](){return NaN;}[i(0x1b3)](){return new Date();}}exports['SymbolHandler']=SymbolHandler;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SymbolHandler = void 0;
4
+ class SymbolHandler {
5
+ null() {
6
+ return null;
7
+ }
8
+ undefined() {
9
+ return undefined;
10
+ }
11
+ whitespace() {
12
+ return ' ';
13
+ }
14
+ object() {
15
+ return {};
16
+ }
17
+ array() {
18
+ return [];
19
+ }
20
+ posInfinity() {
21
+ return Infinity;
22
+ }
23
+ negInfinity() {
24
+ return -Infinity;
25
+ }
26
+ NaN() {
27
+ return NaN;
28
+ }
29
+ date() {
30
+ return new Date();
31
+ }
32
+ }
33
+ exports.SymbolHandler = SymbolHandler;
@@ -1 +1,18 @@
1
- 'use strict';var i=b;function a(){var j=['235720iULPzn','271yETzOB','51ZxcAMy','UnaryHandler','1309266iLtgiA','10598610hUECdg','negative','4870imJOBO','5017465EjIjsd','bitwise_not','7rmDUjR','2857194bIyoDj','4616096MuhOjW'];a=function(){return j;};return a();}(function(c,d){var h=b,e=c();while(!![]){try{var f=parseInt(h(0x15e))/0x1*(parseInt(h(0x164))/0x2)+-parseInt(h(0x15f))/0x3*(parseInt(h(0x16a))/0x4)+parseInt(h(0x165))/0x5+-parseInt(h(0x168))/0x6+-parseInt(h(0x167))/0x7*(parseInt(h(0x169))/0x8)+-parseInt(h(0x161))/0x9+parseInt(h(0x162))/0xa;if(f===d)break;else e['push'](e['shift']());}catch(g){e['push'](e['shift']());}}}(a,0x7f9f8));Object['defineProperty'](exports,'__esModule',{'value':!0x0}),exports[i(0x160)]=void 0x0;function b(c,d){var e=a();return b=function(f,g){f=f-0x15e;var h=e[f];return h;},b(c,d);}class UnaryHandler{['not'](c){return!c;}['positive'](c){return+c;}[i(0x163)](c){return-c;}[i(0x166)](c){return~c;}}exports[i(0x160)]=UnaryHandler;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnaryHandler = void 0;
4
+ class UnaryHandler {
5
+ not(value) {
6
+ return !value;
7
+ }
8
+ positive(value) {
9
+ return +value;
10
+ }
11
+ negative(value) {
12
+ return -value;
13
+ }
14
+ bitwise_not(value) {
15
+ return ~value;
16
+ }
17
+ }
18
+ exports.UnaryHandler = UnaryHandler;
@@ -1 +1,242 @@
1
- 'use strict';const m=b;function a(){const J=['object','defineProperty','__esModule','328088ifKdbt','endsWith','call','context','jobData','isreduceType','Unknown\x20domain\x20name\x20[','{$index','hasOwnProperty','concat','rules','resolveContextTerm','prototype','reduce','Unknown\x20domain\x20function\x20[','getNestedProperty','{$input','processRow',']:\x20','1255566Kgwxfc','resolveContextValue','split','push','7335005qInDwf','isPipeType','308FpIXQY','resolveFunction','Pipe','4642276DkHTqy','resolve','isContextVariable','processCells','isPipeObject','length','process','resolveCellValue','resolveMapTerm','@pipe','resolveMappableValue','cloneUnknown','{$item','isArray','569826nQwYiH','startsWith','default','2611026mvvlaH','isFunction','__importDefault','956350GMjACG','string','isMappable','substring','map'];a=function(){return J;};return a();}(function(c,d){const l=b,e=c();while(!![]){try{const f=parseInt(l(0x6e))/0x1+-parseInt(l(0x89))/0x2+-parseInt(l(0x6b))/0x3+parseInt(l(0x92))/0x4+-parseInt(l(0x8d))/0x5+-parseInt(l(0xa0))/0x6+-parseInt(l(0x8f))/0x7*(-parseInt(l(0x76))/0x8);if(f===d)break;else e['push'](e['shift']());}catch(g){e['push'](e['shift']());}}}(a,0xd247a));function b(c,d){const e=a();return b=function(f,g){f=f-0x6b;let h=e[f];return h;},b(c,d);}var __importDefault=this&&this[m(0x6d)]||function(c){const n=m;return c&&c[n(0x75)]?c:{'default':c};};Object[m(0x74)](exports,m(0x75),{'value':!0x0}),exports[m(0x91)]=void 0x0;const functions_1=__importDefault(require('./functions'));class Pipe{constructor(c,d,f){const o=m;this['rules']=c,this[o(0x7a)]=d,this[o(0x79)]=f;}[m(0x8e)](c){const p=m;return!Array[p(0x9f)](c)&&'@pipe'in c;}['isreduceType'](c){const q=m;return!Array[q(0x9f)](c)&&'@reduce'in c;}static['isPipeObject'](c){const r=m;return r(0x73)==typeof c&&null!==c&&!Array[r(0x9f)](c)&&r(0x9b)in c;}static[m(0x93)](c,d){const s=m;let f;return f=Pipe[s(0x96)](c)?new Pipe(c[s(0x9b)],d):new Pipe([[c]],d),f[s(0x98)]();}[m(0x98)](c=null){const t=m;let d=0x0;c||this[t(0x8e)](this['rules'][0x0])||this[t(0x7b)](this[t(0x80)][0x0])||(c=this[t(0x95)](this['rules'][0x0]),d=0x1);const f=this[t(0x80)][t(0x97)],g=[];for(let h=d;h<f;h++)c=this[t(0x87)](this[t(0x80)][h],c,g);return c[0x0];}['cloneUnknown'](c){const u=m;if(null===c||u(0x73)!=typeof c)return c;if(c instanceof Date)return new Date(c['getTime']());if(c instanceof RegExp)return new RegExp(c);if(Array[u(0x9f)](c))return c[u(0x72)](f=>this[u(0x9d)](f));const d={};for(const f in c)Object[u(0x82)]['hasOwnProperty'][u(0x78)](c,f)&&(d[f]=this[u(0x9d)](c[f]));return d;}['reduce'](c){const v=m;let d=this[v(0x9d)](c[0x1]??null);if(Array[v(0x9f)](c[0x0])){for(let f=0x0;f<c[0x0]['length'];f++)this[v(0x79)]={'$input':c[0x0],'$output':d,'$item':c[0x0][f],'$key':f['toString'](),'$index':f},d=this[v(0x98)]([d]);}else{let g=-0x1;for(const h in c[0x0])g++,this[v(0x79)]={'$input':c[0x0],'$output':d,'$item':c[0x0][h],'$key':h,'$index':g},d=this[v(0x98)]([d]);}return[d];}[m(0x87)](c,d,f){const w=m;if(d&&this['isreduceType'](c))return new Pipe(c['@reduce'],this['jobData'])[w(0x83)](d);if(this[w(0x8e)](c)){const g=new Pipe(c[w(0x9b)],this['jobData'],this['context']);return f[w(0x8c)](g[w(0x98)]()),d;}if(f[w(0x97)]>0x0&&(d=[...f],f[w(0x97)]=0x0),d){const [h,...j]=c;let k;return k=this[w(0x94)](h)?this['resolveContextValue'](h):Pipe[w(0x90)](h)(...d),[k][w(0x7f)](this[w(0x95)]([...j]));}return[][w(0x7f)](this[w(0x95)](Array[w(0x9f)](c)?[...c]:[]));}static['resolveFunction'](c){const x=m;let [d,f]=c[x(0x8b)]('.');d=d[x(0x71)](0x2),f=f[x(0x71)](0x0,f[x(0x97)]-0x1);const g=functions_1[x(0xa2)][d];if(!g)throw new Error(x(0x7c)+c+x(0x88)+d);if(!g[f])throw new Error(x(0x84)+c+x(0x88)+d+'.'+f);return g[f];}[m(0x95)](c){const y=m,d=[];if(Array[y(0x9f)](c)){for(const f of c)d[y(0x8c)](this[y(0x99)](f));}return d;}['isFunction'](c){const z=m;return z(0x6f)==typeof c&&c[z(0xa1)]('{@')&&c[z(0x77)]('}');}[m(0x94)](c){const A=m;if(A(0x6f)==typeof c&&c[A(0x77)]('}'))return c[A(0xa1)](A(0x9e))||c[A(0xa1)]('{$key')||c['startsWith'](A(0x7d))||c['startsWith'](A(0x86))||c['startsWith']('{$output');}['isMappable'](c){const B=m;return B(0x6f)==typeof c&&c[B(0xa1)]('{')&&c[B(0x77)]('}');}[m(0x99)](c){const C=m;if(this[C(0x6c)](c))return Pipe[C(0x90)](c)['call']();return this[C(0x94)](c)?this[C(0x8a)](c):this[C(0x70)](c)?this[C(0x9c)](c):c;}[m(0x85)](c,d){const D=m,f=d[D(0x8b)]('.');let g=c;for(const h of f){if(null===g||D(0x73)!=typeof g||!g[D(0x7e)](h))return;g=g[h];}return g;}['resolveMappableValue'](c){const E=m,d=this[E(0x9a)](c);return this[E(0x85)](this[E(0x7a)],d);}[m(0x8a)](c){const F=m,d=this['resolveContextTerm'](c);return this[F(0x85)](this[F(0x79)],d);}[m(0x81)](c){const G=m;return c[G(0x71)](0x1,c[G(0x97)]-0x1);}['resolveFunctionTerm'](c){const H=m;return c['substring'](0x2,c[H(0x97)]-0x1);}[m(0x9a)](c){const I=m;return c['substring'](0x1,c[I(0x97)]-0x1);}}exports[m(0x91)]=Pipe;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Pipe = void 0;
7
+ const functions_1 = __importDefault(require("./functions"));
8
+ class Pipe {
9
+ constructor(rules, jobData, context) {
10
+ this.rules = rules;
11
+ this.jobData = jobData;
12
+ this.context = context;
13
+ }
14
+ isPipeType(currentRow) {
15
+ return !Array.isArray(currentRow) && '@pipe' in currentRow;
16
+ }
17
+ isreduceType(currentRow) {
18
+ return !Array.isArray(currentRow) && '@reduce' in currentRow;
19
+ }
20
+ static isPipeObject(obj) {
21
+ return (typeof obj === 'object' &&
22
+ obj !== null &&
23
+ !Array.isArray(obj) &&
24
+ '@pipe' in obj);
25
+ }
26
+ static resolve(unresolved, context) {
27
+ let pipe;
28
+ if (Pipe.isPipeObject(unresolved)) {
29
+ pipe = new Pipe(unresolved['@pipe'], context);
30
+ }
31
+ else {
32
+ pipe = new Pipe([[unresolved]], context);
33
+ }
34
+ return pipe.process();
35
+ }
36
+ /**
37
+ * loop through each PipeItem row in this Pipe, resolving and transforming line by line
38
+ * @returns {any} the result of the pipe
39
+ */
40
+ process(resolved = null) {
41
+ let index = 0;
42
+ if (!(resolved ||
43
+ this.isPipeType(this.rules[0]) ||
44
+ this.isreduceType(this.rules[0]))) {
45
+ resolved = this.processCells(this.rules[0]); // Add type assertion
46
+ index = 1;
47
+ }
48
+ const len = this.rules.length;
49
+ const subPipeQueue = [];
50
+ for (let i = index; i < len; i++) {
51
+ resolved = this.processRow(this.rules[i], resolved, subPipeQueue);
52
+ }
53
+ return resolved[0];
54
+ }
55
+ cloneUnknown(value) {
56
+ if (value === null || typeof value !== 'object') {
57
+ return value;
58
+ }
59
+ if (value instanceof Date) {
60
+ return new Date(value.getTime());
61
+ }
62
+ if (value instanceof RegExp) {
63
+ return new RegExp(value);
64
+ }
65
+ if (Array.isArray(value)) {
66
+ return value.map((item) => this.cloneUnknown(item));
67
+ }
68
+ const clonedObj = {};
69
+ for (const key in value) {
70
+ if (Object.prototype.hasOwnProperty.call(value, key)) {
71
+ clonedObj[key] = this.cloneUnknown(value[key]);
72
+ }
73
+ }
74
+ return clonedObj;
75
+ }
76
+ /**
77
+ * Transforms iterable `input` into a single value. Vars $output, $item, $key
78
+ * and $input are available. The final statement in the iterator (the reduction)
79
+ * is assumed to be the return value. A default $output object may be provided
80
+ * to the iterator by placing the the second cell of the preceding row. Otherwise,
81
+ * construct the object during first run and ensure it is the first cell of the
82
+ * last row of the iterator, so it is returned as the $output for the next cycle
83
+ * @param {unknown[]} input
84
+ * @returns {unknown}
85
+ * @private
86
+ */
87
+ reduce(input) {
88
+ let resolved = this.cloneUnknown(input[1] ?? null);
89
+ if (Array.isArray(input[0])) {
90
+ for (let index = 0; index < input[0].length; index++) {
91
+ this.context = {
92
+ $input: input[0],
93
+ $output: resolved,
94
+ $item: input[0][index],
95
+ $key: index.toString(),
96
+ $index: index,
97
+ };
98
+ resolved = this.process([resolved]);
99
+ }
100
+ }
101
+ else {
102
+ let index = -1;
103
+ for (const $key in input[0]) {
104
+ index++;
105
+ this.context = {
106
+ $input: input[0],
107
+ $output: resolved,
108
+ $item: input[0][$key],
109
+ $key,
110
+ $index: index,
111
+ };
112
+ resolved = this.process([resolved]);
113
+ }
114
+ }
115
+ return [resolved];
116
+ }
117
+ processRow(currentRow, resolvedPriorRow, subPipeQueue) {
118
+ if (resolvedPriorRow && this.isreduceType(currentRow)) {
119
+ //reduce the resolvedPriorRow and return the output from the reducer
120
+ const subPipe = new Pipe(currentRow['@reduce'], this.jobData);
121
+ const reduced = subPipe.reduce(resolvedPriorRow);
122
+ return reduced;
123
+ }
124
+ else if (this.isPipeType(currentRow)) {
125
+ //process subPipe and push to subPipeQueue; echo resolvedPriorRow
126
+ const subPipe = new Pipe(currentRow['@pipe'], this.jobData, this.context);
127
+ subPipeQueue.push(subPipe.process());
128
+ return resolvedPriorRow;
129
+ }
130
+ else {
131
+ //pivot the subPipeQueue into the arguments array (resolvedPriorRow)
132
+ if (subPipeQueue.length > 0) {
133
+ resolvedPriorRow = [...subPipeQueue];
134
+ subPipeQueue.length = 0;
135
+ }
136
+ if (!resolvedPriorRow) {
137
+ //if no prior row, use current row as prior row
138
+ return [].concat(this.processCells(Array.isArray(currentRow) ? [...currentRow] : []));
139
+ }
140
+ else {
141
+ const [functionName, ...params] = currentRow; // Add type assertion
142
+ //use resolved values from prior row (n - 1) as input params to cell 1 function
143
+ let resolvedValue;
144
+ if (this.isContextVariable(functionName)) {
145
+ resolvedValue = this.resolveContextValue(functionName);
146
+ }
147
+ else {
148
+ resolvedValue = Pipe.resolveFunction(functionName)(...resolvedPriorRow);
149
+ }
150
+ //resolve remaining cells in row and return concatenated with resolvedValue
151
+ return [resolvedValue].concat(this.processCells([...params]));
152
+ }
153
+ }
154
+ }
155
+ static resolveFunction(functionName) {
156
+ let [prefix, suffix] = functionName.split('.');
157
+ prefix = prefix.substring(2);
158
+ suffix = suffix.substring(0, suffix.length - 1);
159
+ const domain = functions_1.default[prefix];
160
+ if (!domain) {
161
+ throw new Error(`Unknown domain name [${functionName}]: ${prefix}`);
162
+ }
163
+ if (!domain[suffix]) {
164
+ throw new Error(`Unknown domain function [${functionName}]: ${prefix}.${suffix}`);
165
+ }
166
+ return domain[suffix];
167
+ }
168
+ processCells(cells) {
169
+ const resolved = [];
170
+ if (Array.isArray(cells)) {
171
+ for (const currentCell of cells) {
172
+ resolved.push(this.resolveCellValue(currentCell));
173
+ }
174
+ }
175
+ return resolved;
176
+ }
177
+ isFunction(currentCell) {
178
+ return (typeof currentCell === 'string' &&
179
+ currentCell.startsWith('{@') &&
180
+ currentCell.endsWith('}'));
181
+ }
182
+ isContextVariable(currentCell) {
183
+ if (typeof currentCell === 'string' && currentCell.endsWith('}')) {
184
+ return (currentCell.startsWith('{$item') ||
185
+ currentCell.startsWith('{$key') ||
186
+ currentCell.startsWith('{$index') ||
187
+ currentCell.startsWith('{$input') ||
188
+ currentCell.startsWith('{$output'));
189
+ }
190
+ }
191
+ isMappable(currentCell) {
192
+ return (typeof currentCell === 'string' &&
193
+ currentCell.startsWith('{') &&
194
+ currentCell.endsWith('}'));
195
+ }
196
+ resolveCellValue(currentCell) {
197
+ if (this.isFunction(currentCell)) {
198
+ const fn = Pipe.resolveFunction(currentCell);
199
+ return fn.call();
200
+ }
201
+ else if (this.isContextVariable(currentCell)) {
202
+ return this.resolveContextValue(currentCell);
203
+ }
204
+ else if (this.isMappable(currentCell)) {
205
+ return this.resolveMappableValue(currentCell);
206
+ }
207
+ else {
208
+ return currentCell;
209
+ }
210
+ }
211
+ getNestedProperty(obj, path) {
212
+ const pathParts = path.split('.');
213
+ let current = obj;
214
+ for (const part of pathParts) {
215
+ if (current === null ||
216
+ typeof current !== 'object' ||
217
+ !current.hasOwnProperty(part)) {
218
+ return undefined;
219
+ }
220
+ current = current[part];
221
+ }
222
+ return current;
223
+ }
224
+ resolveMappableValue(currentCell) {
225
+ const term = this.resolveMapTerm(currentCell);
226
+ return this.getNestedProperty(this.jobData, term);
227
+ }
228
+ resolveContextValue(currentCell) {
229
+ const term = this.resolveContextTerm(currentCell);
230
+ return this.getNestedProperty(this.context, term);
231
+ }
232
+ resolveContextTerm(currentCell) {
233
+ return currentCell.substring(1, currentCell.length - 1);
234
+ }
235
+ resolveFunctionTerm(currentCell) {
236
+ return currentCell.substring(2, currentCell.length - 1);
237
+ }
238
+ resolveMapTerm(currentCell) {
239
+ return currentCell.substring(1, currentCell.length - 1);
240
+ }
241
+ }
242
+ exports.Pipe = Pipe;
@@ -1 +1,263 @@
1
- 'use strict';const p=b;(function(c,d){const o=b,e=c();while(!![]){try{const f=parseInt(o(0x137))/0x1*(-parseInt(o(0x145))/0x2)+parseInt(o(0x13c))/0x3*(-parseInt(o(0x136))/0x4)+parseInt(o(0x130))/0x5*(-parseInt(o(0xeb))/0x6)+parseInt(o(0xff))/0x7*(-parseInt(o(0xe6))/0x8)+-parseInt(o(0x128))/0x9*(-parseInt(o(0x11c))/0xa)+-parseInt(o(0x13f))/0xb*(parseInt(o(0x147))/0xc)+parseInt(o(0x146))/0xd*(parseInt(o(0x14b))/0xe);if(f===d)break;else e['push'](e['shift']());}catch(g){e['push'](e['shift']());}}}(a,0xdd897));function a(){const G=['XSleepFor','depth','4RMsomM','241nNGLId','../../types/hotmesh','reclaimDelay','HMSH_QUORUM_DELAY_MS','active','2818371sFsztv','initSubChannel','defineProperty','247731QoONZU','verifyQuorumFields','rollCall','quorum\x20config\x20must\x20include\x20`store`\x20and\x20`sub`\x20fields.','store','max','5638gBmhOx','13bAgcbN','588IREVFF','getVID','HMSH_QUORUM_ROLLCALL_CYCLES','engine','60383834isrelD','type','until_version','job','push','HMSH_ACTIVATION_MAX_RETRY','info','sayPong','identifyProvider','filter','rollCallInterval','../store/factory','mintKey','random','7657016AkIamL','requestQuorum','setCacheMode','version','STREAMS','7614mGyhSg','length','quorum-activation-succeeded','../../modules/enums','quorum-rollcall-succeeded','throttle','forEach','callbacks','__esModule','stream','details','unsub','router','quorum-activation-awaiting','namespace','counts','warn','activate','quorum-activation-error','untilVersion','7mHyPTD','originator','inited','reserveScoutRole','releaseScoutRole','QuorumService','initStoreChannel','nocache','pub','QUORUM','../sub/factory','routeToSubscribers','getStreamDepths','processWebHooks','rollcall','cache_mode','logger','stream_depth','guid','formatISODate','profiles','\x20not\x20activated.','publish','pong','quorum','debug','processTimeHooks','reclaimCount','StoreServiceFactory','10Iaanil','subscribe','subscriptionHandler','sleepFor','ping','doRollCall','../../modules/utils','cancelRollCall','quorum-event-received','sub','appId','toString','11714994vcBZDG','CompilerService','SubServiceFactory','KeyType','work','interval','cache','profile','4050huTbIP','init','cacheMode','getApp'];a=function(){return G;};return a();}Object[p(0x13e)](exports,p(0xf3),{'value':!0x0}),exports['QuorumService']=void 0x0;const enums_1=require(p(0xee)),utils_1=require(p(0x122)),compiler_1=require('../compiler'),hotmesh_1=require(p(0x138)),factory_1=require(p(0x109)),factory_2=require(p(0xe3));class QuorumService{constructor(){const q=p;this['profiles']=[],this[q(0x132)]=q(0x12e),this['untilVersion']=null,this[q(0x117)]=null,this['callbacks']=[];}static async[p(0x131)](c,d,f,g,h,j){const r=p;if(g['engine']){const k=new QuorumService();return k[r(0x140)](g),k[r(0xf9)]=c,k[r(0x126)]=d,k[r(0x111)]=f,k[r(0x10f)]=j,k['engine']=h,await k[r(0x105)](g[r(0x14a)][r(0x143)]),await k[r(0x13d)](g[r(0x14a)][r(0x125)],g['engine'][r(0x107)]??g[r(0x14a)][r(0x143)]),await k['subscribe']['subscribe'](hotmesh_1[r(0x12b)][r(0x108)],k[r(0x11e)](),d),await k[r(0x11d)][r(0x11d)](hotmesh_1['KeyType'][r(0x108)],k[r(0x11e)](),d,k[r(0x111)]),k['engine'][r(0x10c)](),k['engine'][r(0x119)](),k;}}[p(0x140)](c){const s=p;if(!(0x0,utils_1[s(0xe0)])(c['engine']['store'])||!(0x0,utils_1[s(0xe0)])(c[s(0x14a)][s(0x125)]))throw new Error(s(0x142));}async['initStoreChannel'](c){const t=p;this[t(0x143)]=await factory_2[t(0x11b)][t(0x131)](c,this[t(0xf9)],this[t(0x126)],this[t(0x10f)]);}async[p(0x13d)](c,d){const u=p;this['subscribe']=await factory_1[u(0x12a)][u(0x131)](c,d,this[u(0xf9)],this['appId'],this[u(0x111)],this[u(0x10f)]);}[p(0x11e)](){const c=this;return async(d,f)=>{const v=b;c[v(0x10f)]['debug'](v(0x124),{'topic':d,'type':f['type']}),v(0xfc)===f['type']?c['engine'][v(0xe8)](f[v(0x10e)],f[v(0xda)]):v(0x120)===f['type']?c[v(0xdf)](c[v(0x126)],c['guid'],f[v(0x100)],f[v(0xf5)]):v(0x116)===f['type']&&c[v(0x111)]===f[v(0x100)]?(c[v(0x117)]=c[v(0x117)]+0x1,f[v(0x12f)]&&c['profiles'][v(0xdc)](f[v(0x12f)])):v(0xf0)===f['type']?c[v(0x14a)][v(0xf0)](f[v(0xf0)]):v(0x12c)===f[v(0xd9)]?c[v(0x14a)][v(0x10c)]():'job'===f['type']?c[v(0x14a)][v(0x10a)](f['topic'],f[v(0xdb)]):'cron'===f['type']?c[v(0x14a)][v(0x119)]():v(0x10d)===f['type']&&c[v(0x121)](f),c[v(0xf2)][v(0xec)]>0x0&&c[v(0xf2)][v(0xf1)](g=>g(d,f));};}async[p(0xdf)](c,d,f,g=!0x1){const w=p;let h;if(g){const j=this[w(0x14a)][w(0x143)][w(0xe4)](hotmesh_1[w(0x12b)][w(0xea)],{'appId':this[w(0x126)]});h={'engine_id':this[w(0x111)],'namespace':this[w(0xf9)],'app_id':this[w(0x126)],'stream':j,'counts':this[w(0x14a)][w(0xf7)][w(0xfa)],'timestamp':(0x0,utils_1[w(0x112)])(new Date()),'inited':this['engine'][w(0x101)],'throttle':this[w(0x14a)][w(0xf7)][w(0xf0)],'reclaimDelay':this[w(0x14a)][w(0xf7)][w(0x139)],'reclaimCount':this['engine'][w(0xf7)][w(0x11a)],'system':await(0x0,utils_1['getSystemHealth'])()};}this[w(0x11d)]['publish'](hotmesh_1[w(0x12b)][w(0x108)],{'type':w(0x116),'guid':d,'originator':f,'profile':h},c);}async[p(0xe7)](c=enums_1[p(0x13a)],d=!0x1){const x=p,f=this[x(0x117)];return this[x(0x117)]=0x0,this[x(0x113)][x(0xec)]=0x0,await this[x(0x11d)][x(0x115)](hotmesh_1['KeyType'][x(0x108)],{'type':x(0x120),'originator':this[x(0x111)],'details':d},this[x(0x126)]),await(0x0,utils_1[x(0x11f)])(c),f;}async[p(0x121)](c){const y=p;let d=0x0;const f=isNaN(c['max'])?enums_1[y(0x149)]:c[y(0x144)];this['rollCallInterval']&&clearTimeout(this['rollCallInterval']);const g=c[y(0x12d)]/0x2,h=g+Math['ceil'](Math[y(0xe5)]()*g);do{if(await(0x0,utils_1[y(0x11f)])(Math['ceil'](0x3e8*Math[y(0xe5)]())),await this[y(0xdf)](this[y(0x126)],this[y(0x111)],null,!0x0),!c['interval'])return;const {promise:j,timerId:k}=(0x0,utils_1[y(0x134)])(0x3e8*h);this[y(0xe2)]=k,await j;}while(this['rollCallInterval']&&d++<f-0x1);}[p(0x123)](){const z=p;this['rollCallInterval']&&(clearTimeout(this[z(0xe2)]),delete this['rollCallInterval']);}['stop'](){this['cancelRollCall']();}async['pub'](c){const A=p;return await this[A(0x11d)][A(0x115)](hotmesh_1['KeyType'][A(0x108)],c,this[A(0x126)],c['topic']||c[A(0x111)]);}async[p(0x125)](c){const B=p;this[B(0xf2)][B(0xdc)](c);}async[p(0xf6)](c){const C=p;this['callbacks']=this[C(0xf2)][C(0xe1)](d=>d!==c);}async[p(0x141)](c=enums_1[p(0x13a)]){const D=p;await this[D(0xe7)](c,!0x0);const d=await this[D(0x14a)][D(0xf4)][D(0x10b)](this[D(0x113)]);return this[D(0x113)]['forEach'](async(f,g)=>{const E=D;f[E(0x110)]=d?.[g]?.[E(0x135)]??0x0;}),this[D(0x113)];}async[p(0xfc)](c,d=enums_1['HMSH_QUORUM_DELAY_MS'],f=0x0){const F=p;c=c[F(0x127)]();if(!await this[F(0x143)][F(0x102)]('activate',Math['ceil'](0x6*d/0x3e8)+0x1)){this[F(0x10f)][F(0x118)](F(0xf8),{'version':c}),await(0x0,utils_1['sleepFor'])(0x6*d);const l=await this[F(0x143)][F(0x133)](this[F(0x126)],!0x0);return 0x1==l?.[F(0x13b)]&&l?.[F(0xe9)]===c;}const g=await this[F(0x14a)][F(0x148)]();await this[F(0xe7)](d);const h=await this[F(0xe7)](d),j=await this[F(0xe7)](d),k=await this[F(0xe7)](d);if(h&&h===j&&j===k){if(this[F(0x10f)][F(0xde)](F(0xef),{'q1':h,'q2':j,'q3':k}),this[F(0x11d)][F(0x115)](hotmesh_1['KeyType']['QUORUM'],{'type':F(0xfc),'cache_mode':F(0x106),'until_version':c},this[F(0x126)]),await new Promise(m=>setTimeout(m,d)),await this[F(0x143)][F(0x103)]('activate'),this[F(0x14a)][F(0xfe)]===c){this[F(0x10f)][F(0xde)](F(0xed),{'version':c});const {id:m}=g,n=new compiler_1[(F(0x129))](this[F(0x143)],this[F(0x14a)][F(0xf4)],this['logger']);return await n[F(0xfc)](m,c);}throw this['logger']['error'](F(0xfd),{'version':c}),new Error('UntilVersion\x20Not\x20Received.\x20Version\x20'+c+'\x20not\x20activated');}if(this[F(0x10f)][F(0xfb)]('quorum-rollcall-error',{'q1':h,'q2':j,'q3':k,'count':f}),this[F(0x143)][F(0x103)](F(0xfc)),f<enums_1[F(0xdd)])return await this[F(0xfc)](c,0x2*d,f+0x1);throw new Error('Quorum\x20not\x20reached.\x20Version\x20'+c+F(0x114));}}function b(c,d){const e=a();return b=function(f,g){f=f-0xd9;let h=e[f];return h;},b(c,d);}exports[p(0x104)]=QuorumService;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QuorumService = void 0;
4
+ const enums_1 = require("../../modules/enums");
5
+ const utils_1 = require("../../modules/utils");
6
+ const compiler_1 = require("../compiler");
7
+ const hotmesh_1 = require("../../types/hotmesh");
8
+ const factory_1 = require("../sub/factory");
9
+ const factory_2 = require("../store/factory");
10
+ class QuorumService {
11
+ /**
12
+ * @private
13
+ */
14
+ constructor() {
15
+ this.profiles = [];
16
+ this.cacheMode = 'cache';
17
+ this.untilVersion = null;
18
+ this.quorum = null;
19
+ this.callbacks = [];
20
+ }
21
+ /**
22
+ * @private
23
+ */
24
+ static async init(namespace, appId, guid, config, engine, logger) {
25
+ if (config.engine) {
26
+ const instance = new QuorumService();
27
+ instance.verifyQuorumFields(config);
28
+ instance.namespace = namespace;
29
+ instance.appId = appId;
30
+ instance.guid = guid;
31
+ instance.logger = logger;
32
+ instance.engine = engine;
33
+ await instance.initStoreChannel(config.engine.store);
34
+ await instance.initSubChannel(config.engine.sub, config.engine.pub ?? config.engine.store);
35
+ //general quorum subscription
36
+ await instance.subscribe.subscribe(hotmesh_1.KeyType.QUORUM, instance.subscriptionHandler(), appId);
37
+ //app-specific quorum subscription (used for pubsub one-time request/response)
38
+ await instance.subscribe.subscribe(hotmesh_1.KeyType.QUORUM, instance.subscriptionHandler(), appId, instance.guid);
39
+ instance.engine.processWebHooks();
40
+ instance.engine.processTimeHooks();
41
+ return instance;
42
+ }
43
+ }
44
+ /**
45
+ * @private
46
+ */
47
+ verifyQuorumFields(config) {
48
+ if (!(0, utils_1.identifyProvider)(config.engine.store) ||
49
+ !(0, utils_1.identifyProvider)(config.engine.sub)) {
50
+ throw new Error('quorum config must include `store` and `sub` fields.');
51
+ }
52
+ }
53
+ /**
54
+ * @private
55
+ */
56
+ async initStoreChannel(store) {
57
+ this.store = await factory_2.StoreServiceFactory.init(store, this.namespace, this.appId, this.logger);
58
+ }
59
+ /**
60
+ * @private
61
+ */
62
+ async initSubChannel(sub, store) {
63
+ this.subscribe = await factory_1.SubServiceFactory.init(sub, store, this.namespace, this.appId, this.guid, this.logger);
64
+ }
65
+ /**
66
+ * @private
67
+ */
68
+ subscriptionHandler() {
69
+ const self = this;
70
+ return async (topic, message) => {
71
+ self.logger.debug('quorum-event-received', { topic, type: message.type });
72
+ if (message.type === 'activate') {
73
+ self.engine.setCacheMode(message.cache_mode, message.until_version);
74
+ }
75
+ else if (message.type === 'ping') {
76
+ self.sayPong(self.appId, self.guid, message.originator, message.details);
77
+ }
78
+ else if (message.type === 'pong' && self.guid === message.originator) {
79
+ self.quorum = self.quorum + 1;
80
+ if (message.profile) {
81
+ self.profiles.push(message.profile);
82
+ }
83
+ }
84
+ else if (message.type === 'throttle') {
85
+ self.engine.throttle(message.throttle);
86
+ }
87
+ else if (message.type === 'work') {
88
+ self.engine.processWebHooks();
89
+ }
90
+ else if (message.type === 'job') {
91
+ self.engine.routeToSubscribers(message.topic, message.job);
92
+ }
93
+ else if (message.type === 'cron') {
94
+ self.engine.processTimeHooks();
95
+ }
96
+ else if (message.type === 'rollcall') {
97
+ self.doRollCall(message);
98
+ }
99
+ //if there are any callbacks, call them
100
+ if (self.callbacks.length > 0) {
101
+ self.callbacks.forEach((cb) => cb(topic, message));
102
+ }
103
+ };
104
+ }
105
+ /**
106
+ * @private
107
+ */
108
+ async sayPong(appId, guid, originator, details = false) {
109
+ let profile;
110
+ if (details) {
111
+ const stream = this.engine.store.mintKey(hotmesh_1.KeyType.STREAMS, {
112
+ appId: this.appId,
113
+ });
114
+ profile = {
115
+ engine_id: this.guid,
116
+ namespace: this.namespace,
117
+ app_id: this.appId,
118
+ stream,
119
+ counts: this.engine.router.counts,
120
+ timestamp: (0, utils_1.formatISODate)(new Date()),
121
+ inited: this.engine.inited,
122
+ throttle: this.engine.router.throttle,
123
+ reclaimDelay: this.engine.router.reclaimDelay,
124
+ reclaimCount: this.engine.router.reclaimCount,
125
+ system: await (0, utils_1.getSystemHealth)(),
126
+ };
127
+ }
128
+ this.subscribe.publish(hotmesh_1.KeyType.QUORUM, {
129
+ type: 'pong',
130
+ guid,
131
+ originator,
132
+ profile,
133
+ }, appId);
134
+ }
135
+ /**
136
+ * A quorum-wide command to request a quorum count.
137
+ * @private
138
+ */
139
+ async requestQuorum(delay = enums_1.HMSH_QUORUM_DELAY_MS, details = false) {
140
+ const quorum = this.quorum;
141
+ this.quorum = 0;
142
+ this.profiles.length = 0;
143
+ await this.subscribe.publish(hotmesh_1.KeyType.QUORUM, {
144
+ type: 'ping',
145
+ originator: this.guid,
146
+ details,
147
+ }, this.appId);
148
+ await (0, utils_1.sleepFor)(delay);
149
+ return quorum;
150
+ }
151
+ /**
152
+ * @private
153
+ */
154
+ async doRollCall(message) {
155
+ let iteration = 0;
156
+ const max = !isNaN(message.max) ? message.max : enums_1.HMSH_QUORUM_ROLLCALL_CYCLES;
157
+ if (this.rollCallInterval)
158
+ clearTimeout(this.rollCallInterval);
159
+ const base = message.interval / 2;
160
+ const amount = base + Math.ceil(Math.random() * base);
161
+ do {
162
+ await (0, utils_1.sleepFor)(Math.ceil(Math.random() * 1000));
163
+ await this.sayPong(this.appId, this.guid, null, true);
164
+ if (!message.interval)
165
+ return;
166
+ const { promise, timerId } = (0, utils_1.XSleepFor)(amount * 1000);
167
+ this.rollCallInterval = timerId;
168
+ await promise;
169
+ } while (this.rollCallInterval && iteration++ < max - 1);
170
+ }
171
+ /**
172
+ * @private
173
+ */
174
+ cancelRollCall() {
175
+ if (this.rollCallInterval) {
176
+ clearTimeout(this.rollCallInterval);
177
+ delete this.rollCallInterval;
178
+ }
179
+ }
180
+ /**
181
+ * @private
182
+ */
183
+ stop() {
184
+ this.cancelRollCall();
185
+ }
186
+ /**
187
+ * @private
188
+ */
189
+ async pub(quorumMessage) {
190
+ return await this.subscribe.publish(hotmesh_1.KeyType.QUORUM, quorumMessage, this.appId, quorumMessage.topic || quorumMessage.guid);
191
+ }
192
+ /**
193
+ * @private
194
+ */
195
+ async sub(callback) {
196
+ this.callbacks.push(callback);
197
+ }
198
+ /**
199
+ * @private
200
+ */
201
+ async unsub(callback) {
202
+ this.callbacks = this.callbacks.filter((cb) => cb !== callback);
203
+ }
204
+ /**
205
+ * @private
206
+ */
207
+ async rollCall(delay = enums_1.HMSH_QUORUM_DELAY_MS) {
208
+ await this.requestQuorum(delay, true);
209
+ const stream_depths = await this.engine.stream.getStreamDepths(this.profiles);
210
+ this.profiles.forEach(async (profile, index) => {
211
+ //if nothing in the table, the depth will be 0
212
+ //todo: separate table for every worker stream?
213
+ profile.stream_depth = stream_depths?.[index]?.depth ?? 0;
214
+ });
215
+ return this.profiles;
216
+ }
217
+ /**
218
+ * @private
219
+ */
220
+ async activate(version, delay = enums_1.HMSH_QUORUM_DELAY_MS, count = 0) {
221
+ version = version.toString();
222
+ const canActivate = await this.store.reserveScoutRole('activate', Math.ceil(delay * 6 / 1000) + 1);
223
+ if (!canActivate) {
224
+ //another engine is already activating the app version
225
+ this.logger.debug('quorum-activation-awaiting', { version });
226
+ await (0, utils_1.sleepFor)(delay * 6);
227
+ const app = await this.store.getApp(this.appId, true);
228
+ return app?.active == true && app?.version === version;
229
+ }
230
+ const config = await this.engine.getVID();
231
+ await this.requestQuorum(delay);
232
+ const q1 = await this.requestQuorum(delay);
233
+ const q2 = await this.requestQuorum(delay);
234
+ const q3 = await this.requestQuorum(delay);
235
+ if (q1 && q1 === q2 && q2 === q3) {
236
+ this.logger.info('quorum-rollcall-succeeded', { q1, q2, q3 });
237
+ this.subscribe.publish(hotmesh_1.KeyType.QUORUM, { type: 'activate', cache_mode: 'nocache', until_version: version }, this.appId);
238
+ await new Promise((resolve) => setTimeout(resolve, delay));
239
+ await this.store.releaseScoutRole('activate');
240
+ //confirm we received the activation message
241
+ if (this.engine.untilVersion === version) {
242
+ this.logger.info('quorum-activation-succeeded', { version });
243
+ const { id } = config;
244
+ const compiler = new compiler_1.CompilerService(this.store, this.engine.stream, this.logger);
245
+ return await compiler.activate(id, version);
246
+ }
247
+ else {
248
+ this.logger.error('quorum-activation-error', { version });
249
+ throw new Error(`UntilVersion Not Received. Version ${version} not activated`);
250
+ }
251
+ }
252
+ else {
253
+ this.logger.warn('quorum-rollcall-error', { q1, q2, q3, count });
254
+ this.store.releaseScoutRole('activate');
255
+ if (count < enums_1.HMSH_ACTIVATION_MAX_RETRY) {
256
+ //increase the delay (give the quorum time to respond) and try again
257
+ return await this.activate(version, delay * 2, count + 1);
258
+ }
259
+ throw new Error(`Quorum not reached. Version ${version} not activated.`);
260
+ }
261
+ }
262
+ }
263
+ exports.QuorumService = QuorumService;