@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,293 @@
1
- 'use strict';const r=b;(function(c,d){const q=b,e=c();while(!![]){try{const f=parseInt(q(0x1ab))/0x1*(-parseInt(q(0x190))/0x2)+-parseInt(q(0x18a))/0x3*(parseInt(q(0x165))/0x4)+-parseInt(q(0x172))/0x5*(parseInt(q(0x196))/0x6)+-parseInt(q(0x1a6))/0x7*(parseInt(q(0x1a5))/0x8)+parseInt(q(0x1a1))/0x9+parseInt(q(0x184))/0xa*(parseInt(q(0x1a4))/0xb)+parseInt(q(0x1ad))/0xc;if(f===d)break;else e['push'](e['shift']());}catch(g){e['push'](e['shift']());}}}(a,0x46bc1));function a(){const R=['config','../../types/collator','isInactive','129130kRZAyd','resolveReentryDimension','notarizeEarlyExit','verifyInteger','888000001000001','MISSING','51LdOVmm','targetLength','lastIndexOf','forEach','getDimensionalAddress','INACTIVE','43182rODIBr','jid','transitions','collateSynthetic','store','notarizeReentry','6qoQBJC','aid','authorizeReentry','CollationFaultType','isArray','CollationError','exec','trigger','FORBIDDEN','enter','bindAncestorArray','3164769LUtYwB','indexOf','type','418CPAahH','8kvfMLK','3589691zsZWPY','notarizeEntry','substring','cycle','__esModule','15QIWKyJ','ancestors','5185020NWPOdz','length','getDimensionsById','context','isPrimed','DUPLICATE','27512eWnbRV','join','find','push','999000000000000','isDuplicate','getDigitAtIndex','notarizeContinuation','collator-trigger-activity-not-found','dad','getSeed','getDimensionalIndex','reverse','155435gdwctj','notarizeInception','getTriggerSeed','CollatorService','metadata','split','getDimensionalSeed','toString','leg','verifySyntheticInteger','activities','notarizeEarlyCompletion','defineProperty','collate','ancestor'];a=function(){return R;};return a();}Object[r(0x17e)](exports,r(0x1aa),{'value':!0x0}),exports[r(0x175)]=void 0x0;const errors_1=require('../../modules/errors'),collator_1=require(r(0x182));function b(c,d){const e=a();return b=function(f,g){f=f-0x163;let h=e[f];return h;},b(c,d);}class CollatorService{static['assertJobActive'](c,d,f,g=0x0){if(c<=g)throw new errors_1['InactiveJobError'](d,c,f);}static[r(0x18e)](c,d=!0x1){const s=r;let f=c[s(0x1b0)][s(0x176)][s(0x16e)]||c['metadata'][s(0x16e)];return d&&f&&0x2===c[s(0x17a)]&&(f=f[s(0x1a8)](0x0,f[s(0x18c)](','))+',0'),CollatorService[s(0x1af)]([...c[s(0x181)]['ancestors'],c[s(0x176)]['aid']],f);}static[r(0x185)](c){const t=r,d=c['config'][t(0x180)],f=c[t(0x181)][t(0x1ac)][t(0x1a2)](d),g=c[t(0x176)][t(0x16e)][t(0x177)](',');return g[t(0x1ae)]=f+0x1,g[t(0x168)]('0'),g[t(0x166)](',');}static async[r(0x1a7)](c,d){const u=r,f=await c['store'][u(0x17f)](c[u(0x1b0)][u(0x176)]['jid'],c['metadata'][u(0x197)],-0x5af3107a4000,this['getDimensionalAddress'](c),d);return this[u(0x187)](f,0x1,'enter'),f;}static async[r(0x198)](c,d){const v=r;return await c['store'][v(0x17f)](c[v(0x1b0)][v(0x176)][v(0x191)],c['metadata'][v(0x197)],-0x9184e72a000,this[v(0x18e)](c),d);}static async[r(0x186)](c,d){const w=r;return await c[w(0x194)]['collate'](c[w(0x1b0)][w(0x176)][w(0x191)],c['metadata'][w(0x197)],-0xa012317b000,this[w(0x18e)](c),d);}static async[r(0x17d)](c,d){const x=r,f=c[x(0x181)][x(0x1a9)]?0x9184e72a000:0xa012317b000;return await c[x(0x194)][x(0x17f)](c[x(0x1b0)][x(0x176)][x(0x191)],c[x(0x176)][x(0x197)],0xf4241-f,this[x(0x18e)](c),d);}static async[r(0x173)](c,d,f){const y=r;d&&await c['store'][y(0x193)](c[y(0x1b0)][y(0x176)][y(0x191)],d,0xf4240,f);}static async['isInceptionOverage'](c,d){const z=r;if(d)return await c[z(0x194)][z(0x193)](c[z(0x1b0)][z(0x176)][z(0x191)],d,0xf4240)>0xf4240;return!0x1;}static async[r(0x195)](c,d,f){const A=r,g=c[A(0x1b0)]['metadata'][A(0x191)],h=f||c[A(0x194)]['transact']();await c[A(0x194)][A(0x17f)](g,c['metadata'][A(0x197)],0xf4240,this['getDimensionalAddress'](c,!0x0),h),await c[A(0x194)][A(0x193)](g,d,0xf4240,h);const [j,k]=await h[A(0x19c)](),m=Array[A(0x19a)](j)?j[0x1]:j,p=Array[A(0x19a)](k)?k[0x1]:k;return this[A(0x187)](m,0x2,A(0x19f)),this[A(0x17b)](p),m;}static async[r(0x16c)](c,d){const B=r;return await c['store'][B(0x17f)](c[B(0x1b0)][B(0x176)]['jid'],c[B(0x176)]['aid'],0x1,this[B(0x18e)](c),d);}static async['notarizeCompletion'](c,d){const C=r,f=c[C(0x181)][C(0x1a9)]?0x0:0xe8d4a51000;return await c['store'][C(0x17f)](c['context'][C(0x176)][C(0x191)],c['metadata'][C(0x197)],0x1-f,this[C(0x18e)](c),d);}static['getDigitAtIndex'](c,d){const D=r,f=c[D(0x179)]();if(d<0x0||d>=f[D(0x1ae)])return null;return parseInt(f[d],0xa);}static[r(0x170)](c){const E=r,d=c[E(0x179)]();if(d['length']<0x9)return null;const f=d['substring'](0x3,0x9);return parseInt(f,0xa)-0x1;}static['isDuplicate'](c,d){const F=r;return this[F(0x16b)](c,d)<0x8;}static[r(0x183)](c){const G=r;return this[G(0x16b)](c,0x2)<0x9;}static['isPrimed'](c,d){return 0x1==d?-0x5af3107a4000!=c:this['getDigitAtIndex'](c,0x0)<0x9&&this['getDigitAtIndex'](c,0x1)<0x9;}static[r(0x17b)](c){const H=r,d=c[H(0x179)]();if(parseInt(d[d['length']-0x1],0xa)>0x0)throw new errors_1['CollationError'](c,0x2,'enter',collator_1[H(0x199)]['INACTIVE']);if(c>=0x1e8480)throw new errors_1[(H(0x19b))](c,0x2,H(0x19f),collator_1[H(0x199)][H(0x164)]);}static[r(0x187)](c,d,f){const I=r;let g;if(0x1===d&&I(0x19f)===f?this[I(0x163)](c,0x1)?this[I(0x16a)](c,0x0)?g=collator_1[I(0x199)][I(0x164)]:0x331a2bfa73000!=c&&(g=collator_1['CollationFaultType']['INVALID']):g=collator_1[I(0x199)][I(0x189)]:0x1===d&&'exit'===f?-0x9184e72a000===c?g=collator_1[I(0x199)]['MISSING']:this[I(0x16a)](c,0x1)&&(g=collator_1[I(0x199)][I(0x164)]):0x2===d&&'enter'===f&&(this[I(0x163)](c,0x2)?this[I(0x183)](c)&&(g=collator_1[I(0x199)][I(0x18f)]):g=collator_1[I(0x199)][I(0x19e)]),g)throw new errors_1['CollationError'](c,d,f,g);}static[r(0x1af)](c,d){const J=r,f={'$ADJACENT':d+',0'};let g=d;return c[J(0x171)]()[J(0x18d)](h=>{const K=J;f[h]=g,g=g[K(0x1a8)](0x0,g[K(0x18c)](','));}),f;}static[r(0x16f)](){const L=r;return L(0x169);}static[r(0x174)](){const M=r;return M(0x188);}static['compile'](c){const N=r;CollatorService[N(0x1a0)](c);}static[r(0x1a0)](c){const O=r;c[O(0x18d)](d=>{const P=O,f={},g=Object['keys'](d[P(0x17c)])[P(0x167)](j=>P(0x19d)===d['activities'][j][P(0x1a3)]);if(!g)throw new Error(P(0x16d));const h=(j,k)=>{const Q=P;f[j]=k,d[Q(0x17c)][j][Q(0x1ac)]=k,(d[Q(0x192)]?.[j]||[])['forEach'](l=>{h(l['to'],[...k,j]);});};h(g,[]);});}static[r(0x178)](c=0x0){return','+c;}}exports[r(0x175)]=CollatorService,CollatorService[r(0x18b)]=0xf;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CollatorService = void 0;
4
+ const errors_1 = require("../../modules/errors");
5
+ const collator_1 = require("../../types/collator");
6
+ class CollatorService {
7
+ /**
8
+ * Upon re/entry, verify that the job status is active
9
+ */
10
+ static assertJobActive(status, jobId, activityId, threshold = 0) {
11
+ if (status <= threshold) {
12
+ throw new errors_1.InactiveJobError(jobId, status, activityId);
13
+ }
14
+ }
15
+ /**
16
+ * returns the dimensional address (dad) for the target; due
17
+ * to the nature of the notary system, the dad for leg 2 entry
18
+ * must target the `0` index while leg 2 exit must target the
19
+ * current index (0)
20
+ */
21
+ static getDimensionalAddress(activity, isEntry = false) {
22
+ let dad = activity.context.metadata.dad || activity.metadata.dad;
23
+ if (isEntry && dad && activity.leg === 2) {
24
+ dad = `${dad.substring(0, dad.lastIndexOf(','))},0`;
25
+ }
26
+ return CollatorService.getDimensionsById([...activity.config.ancestors, activity.metadata.aid], dad);
27
+ }
28
+ /**
29
+ * resolves the dimensional address for the
30
+ * ancestor in the graph to go back to. this address
31
+ * is determined by trimming the last digits from
32
+ * the `dad` (including the target).
33
+ * the target activity index is then set to `0`, so that
34
+ * the origin node can be queried for approval/entry.
35
+ */
36
+ static resolveReentryDimension(activity) {
37
+ const targetActivityId = activity.config.ancestor;
38
+ const ancestors = activity.config.ancestors;
39
+ const ancestorIndex = ancestors.indexOf(targetActivityId);
40
+ const dimensions = activity.metadata.dad.split(','); //e.g., `,0,0,1,0`
41
+ dimensions.length = ancestorIndex + 1;
42
+ dimensions.push('0');
43
+ return dimensions.join(',');
44
+ }
45
+ static async notarizeEntry(activity, transaction) {
46
+ //decrement by -100_000_000_000_000
47
+ const amount = await activity.store.collate(activity.context.metadata.jid, activity.metadata.aid, -100000000000000, this.getDimensionalAddress(activity), transaction);
48
+ this.verifyInteger(amount, 1, 'enter');
49
+ return amount;
50
+ }
51
+ static async authorizeReentry(activity, transaction) {
52
+ //set second digit to 8, allowing for re-entry
53
+ //decrement by -10_000_000_000_000
54
+ const amount = await activity.store.collate(activity.context.metadata.jid, activity.metadata.aid, -10000000000000, this.getDimensionalAddress(activity), transaction);
55
+ return amount;
56
+ }
57
+ static async notarizeEarlyExit(activity, transaction) {
58
+ //decrement the 2nd and 3rd digits to fully deactivate (`cycle` activities use this command to fully exit after leg 1) (should result in `888000000000000`)
59
+ return await activity.store.collate(activity.context.metadata.jid, activity.metadata.aid, -11000000000000, this.getDimensionalAddress(activity), transaction);
60
+ }
61
+ static async notarizeEarlyCompletion(activity, transaction) {
62
+ //initialize both `possible` (1m) and `actualized` (1) zero dimension, while decrementing the 2nd
63
+ //3rd digit is optionally kept open if the activity might be used in a cycle
64
+ const decrement = activity.config.cycle
65
+ ? 10000000000000
66
+ : 11000000000000;
67
+ return await activity.store.collate(activity.context.metadata.jid, activity.metadata.aid, 1000001 - decrement, this.getDimensionalAddress(activity), transaction);
68
+ }
69
+ /**
70
+ * sets the synthetic inception key (in case of an overage occurs).
71
+ */
72
+ static async notarizeInception(activity, guid, transaction) {
73
+ if (guid) {
74
+ await activity.store.collateSynthetic(activity.context.metadata.jid, guid, 1000000, transaction);
75
+ }
76
+ }
77
+ /**
78
+ * ignore those ID collisions that are due to re-entry overages
79
+ */
80
+ static async isInceptionOverage(activity, guid) {
81
+ if (guid) {
82
+ const amount = await activity.store.collateSynthetic(activity.context.metadata.jid, guid, 1000000);
83
+ return amount > 1000000;
84
+ }
85
+ return false;
86
+ }
87
+ /**
88
+ * verifies both the concrete and synthetic keys for the activity; concrete keys
89
+ * exist in the original model and are effectively the 'real' keys. In reality,
90
+ * hook activities are atomized during compilation to create a synthetic DAG that
91
+ * is used to track the status of the graph in a distributed environment. The
92
+ * synthetic key represents different dimensional realities and is used to
93
+ * track re-entry overages (it distinguishes between the original and re-entry).
94
+ * The essential challenge is: is this a re-entry that is purposeful in
95
+ * order to induce cycles, or is the re-entry due to a failure in the system?
96
+ */
97
+ static async notarizeReentry(activity, guid, transaction) {
98
+ const jid = activity.context.metadata.jid;
99
+ const localMulti = transaction || activity.store.transact();
100
+ //increment by 1_000_000 (indicates re-entry and is used to drive the 'dimensional address' for adjacent activities (minus 1))
101
+ await activity.store.collate(jid, activity.metadata.aid, 1000000, this.getDimensionalAddress(activity, true), localMulti);
102
+ await activity.store.collateSynthetic(jid, guid, 1000000, localMulti);
103
+ const [_amountConcrete, _amountSynthetic] = await localMulti.exec();
104
+ const amountConcrete = Array.isArray(_amountConcrete)
105
+ ? _amountConcrete[1]
106
+ : _amountConcrete;
107
+ const amountSynthetic = Array.isArray(_amountSynthetic)
108
+ ? _amountSynthetic[1]
109
+ : _amountSynthetic;
110
+ this.verifyInteger(amountConcrete, 2, 'enter');
111
+ this.verifySyntheticInteger(amountSynthetic);
112
+ return amountConcrete;
113
+ }
114
+ static async notarizeContinuation(activity, transaction) {
115
+ //keep open; actualize the leg2 dimension (+1)
116
+ return await activity.store.collate(activity.context.metadata.jid, activity.metadata.aid, 1, this.getDimensionalAddress(activity), transaction);
117
+ }
118
+ static async notarizeCompletion(activity, transaction) {
119
+ //1) ALWAYS actualize leg2 dimension (+1)
120
+ //2) IF the activity is used in a cycle, don't close leg 2!
121
+ const decrement = activity.config.cycle ? 0 : 1000000000000;
122
+ return await activity.store.collate(activity.context.metadata.jid, activity.metadata.aid, 1 - decrement, this.getDimensionalAddress(activity), transaction);
123
+ }
124
+ static getDigitAtIndex(num, targetDigitIndex) {
125
+ const numStr = num.toString();
126
+ if (targetDigitIndex < 0 || targetDigitIndex >= numStr.length) {
127
+ return null;
128
+ }
129
+ const digit = parseInt(numStr[targetDigitIndex], 10);
130
+ return digit;
131
+ }
132
+ static getDimensionalIndex(num) {
133
+ const numStr = num.toString();
134
+ if (numStr.length < 9) {
135
+ return null;
136
+ }
137
+ const extractedStr = numStr.substring(3, 9);
138
+ const extractedInt = parseInt(extractedStr, 10);
139
+ return extractedInt - 1;
140
+ }
141
+ static isDuplicate(num, targetDigitIndex) {
142
+ return this.getDigitAtIndex(num, targetDigitIndex) < 8;
143
+ }
144
+ static isInactive(num) {
145
+ return this.getDigitAtIndex(num, 2) < 9;
146
+ }
147
+ static isPrimed(amount, leg) {
148
+ //activity entry is not allowed if paths not properly pre-set
149
+ if (leg == 1) {
150
+ return amount != -100000000000000;
151
+ }
152
+ else {
153
+ return (this.getDigitAtIndex(amount, 0) < 9 &&
154
+ this.getDigitAtIndex(amount, 1) < 9);
155
+ }
156
+ }
157
+ /**
158
+ * During compilation, the graphs are compiled into structures necessary
159
+ * for distributed processing; these are referred to as 'synthetic DAGs',
160
+ * because they are not part of the original graph, but are used to track
161
+ * the status of the graph in a distributed environment. This check ensures
162
+ * that the 'synthetic key' is not a duplicate. (which is different than
163
+ * saying the 'key' is not a duplicate)
164
+ */
165
+ static verifySyntheticInteger(amount) {
166
+ const samount = amount.toString();
167
+ const isCompletedValue = parseInt(samount[samount.length - 1], 10);
168
+ if (isCompletedValue > 0) {
169
+ //already done error (ack/delete clearly failed; this is a duplicate)
170
+ throw new errors_1.CollationError(amount, 2, 'enter', collator_1.CollationFaultType.INACTIVE);
171
+ }
172
+ else if (amount >= 2000000) {
173
+ //duplicate synthetic key (this is a duplicate job ID)
174
+ throw new errors_1.CollationError(amount, 2, 'enter', collator_1.CollationFaultType.DUPLICATE);
175
+ }
176
+ }
177
+ static verifyInteger(amount, leg, stage) {
178
+ let faultType;
179
+ if (leg === 1 && stage === 'enter') {
180
+ if (!this.isPrimed(amount, 1)) {
181
+ faultType = collator_1.CollationFaultType.MISSING;
182
+ }
183
+ else if (this.isDuplicate(amount, 0)) {
184
+ faultType = collator_1.CollationFaultType.DUPLICATE;
185
+ }
186
+ else if (amount != 899000000000000) {
187
+ faultType = collator_1.CollationFaultType.INVALID;
188
+ }
189
+ }
190
+ else if (leg === 1 && stage === 'exit') {
191
+ if (amount === -10000000000000) {
192
+ faultType = collator_1.CollationFaultType.MISSING;
193
+ }
194
+ else if (this.isDuplicate(amount, 1)) {
195
+ faultType = collator_1.CollationFaultType.DUPLICATE;
196
+ }
197
+ }
198
+ else if (leg === 2 && stage === 'enter') {
199
+ if (!this.isPrimed(amount, 2)) {
200
+ faultType = collator_1.CollationFaultType.FORBIDDEN;
201
+ }
202
+ else if (this.isInactive(amount)) {
203
+ faultType = collator_1.CollationFaultType.INACTIVE;
204
+ }
205
+ }
206
+ if (faultType) {
207
+ throw new errors_1.CollationError(amount, leg, stage, faultType);
208
+ }
209
+ }
210
+ static getDimensionsById(ancestors, dad) {
211
+ //ancestors is an ordered list of all ancestors, starting with the trigger (['t1', 'a1', 'a2'])
212
+ //dad is the dimensional address of the ancestors list (',0,5,3')
213
+ //loop through the ancestors list and create a map of the ancestor to the dimensional address.
214
+ //return { 't1': ',0', 'a1': ',0,5', 'a1': ',0,5,3', $ADJACENT: ',0,5,3,0' };
215
+ // `adjacent` is a special key that is used to track the dimensional address of adjacent activities
216
+ const map = { $ADJACENT: `${dad},0` };
217
+ let dadStr = dad;
218
+ ancestors.reverse().forEach((ancestor) => {
219
+ map[ancestor] = dadStr;
220
+ dadStr = dadStr.substring(0, dadStr.lastIndexOf(','));
221
+ });
222
+ return map;
223
+ }
224
+ /**
225
+ * All non-trigger activities are assigned a status seed by their parent
226
+ */
227
+ static getSeed() {
228
+ return '999000000000000';
229
+ }
230
+ /**
231
+ * All trigger activities are assigned a status seed in a completed state
232
+ */
233
+ static getTriggerSeed() {
234
+ return '888000001000001';
235
+ }
236
+ /**
237
+ * entry point for compiler-type activities. This is called by the compiler
238
+ * to bind the sorted activity IDs to the trigger activity. These are then used
239
+ * at runtime by the activities to track job/activity status.
240
+ * @param graphs
241
+ */
242
+ static compile(graphs) {
243
+ CollatorService.bindAncestorArray(graphs);
244
+ }
245
+ /**
246
+ * binds the ancestor array to each activity.
247
+ * Used in conjunction with the dimensional
248
+ * address (dad). If dad is `,0,1,0,0` and the
249
+ * ancestor array is `['t1', 'a1', 'a2']` for
250
+ * activity 'a3', then the SAVED DAD
251
+ * will always have the trailing
252
+ * 0's removed. This ensures that the addressing
253
+ * remains consistent even if the graph changes.
254
+ * id DAD SAVED DAD
255
+ * * t1 => ,0 => [empty]
256
+ * * a1 => ,0,1 => ,0,1
257
+ * * a2 => ,0,1,0 => ,0,1
258
+ * * a3 => ,0,1,0,0 => ,0,1
259
+ *
260
+ */
261
+ static bindAncestorArray(graphs) {
262
+ graphs.forEach((graph) => {
263
+ const ancestors = {};
264
+ const startingNode = Object.keys(graph.activities).find((activity) => graph.activities[activity].type === 'trigger');
265
+ if (!startingNode) {
266
+ throw new Error('collator-trigger-activity-not-found');
267
+ }
268
+ const dfs = (node, parentList) => {
269
+ ancestors[node] = parentList;
270
+ graph.activities[node]['ancestors'] = parentList;
271
+ const transitions = graph.transitions?.[node] || [];
272
+ transitions.forEach((transition) => {
273
+ dfs(transition.to, [...parentList, node]);
274
+ });
275
+ };
276
+ // Start the DFS traversal
277
+ dfs(startingNode, []);
278
+ });
279
+ }
280
+ /**
281
+ * All activities exist on a dimensional plane. Zero
282
+ * is the default. A value of
283
+ * `AxY,0,0,0,0,1,0,0` would reflect that
284
+ * an ancestor activity was dimensionalized beyond
285
+ * the default.
286
+ */
287
+ static getDimensionalSeed(index = 0) {
288
+ return `,${index}`;
289
+ }
290
+ }
291
+ exports.CollatorService = CollatorService;
292
+ //max int digit count that supports `hincrby`
293
+ CollatorService.targetLength = 15;