@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,7 +1,7 @@
1
1
  {
2
2
  "name": "@hotmeshio/hotmesh",
3
- "version": "0.3.32",
4
- "description": "Serverless Workflow",
3
+ "version": "0.4.1",
4
+ "description": "Permanent-Memory Workflows & AI Agents",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
7
7
  "homepage": "https://hotmesh.io/",
@@ -14,6 +14,8 @@
14
14
  "obfuscate": "ts-node scripts/obfuscate.ts",
15
15
  "clean-build": "npm run clean && npm run build",
16
16
  "clean-build-obfuscate": "npm run clean-build && npm run obfuscate",
17
+ "docs": "typedoc",
18
+ "docs:clean": "rimraf ./docs/hotmesh && typedoc",
17
19
  "lint": "eslint . --ext .ts",
18
20
  "lint:fix": "eslint . --fix --ext .ts",
19
21
  "start": "ts-node src/index.ts",
@@ -26,20 +28,21 @@
26
28
  "test:connect:redis": "NODE_ENV=test jest ./tests/unit/services/connector/providers/redis.test.ts --detectOpenHandles --forceExit --verbose",
27
29
  "test:connect:nats": "NODE_ENV=test jest ./tests/unit/services/connector/providers/nats.test.ts --detectOpenHandles --forceExit --verbose",
28
30
  "test:cycle": "NODE_ENV=test jest ./tests/functional/cycle/*.test.ts --detectOpenHandles --forceExit --verbose",
29
- "test:meshflow": "NODE_ENV=test jest ./tests/meshflow/*/*.test.ts --detectOpenHandles --forceExit --verbose",
30
- "test:meshflow:basic": "HMSH_LOGLEVEL=info NODE_ENV=test jest ./tests/meshflow/basic/*.test.ts --detectOpenHandles --forceExit --verbose",
31
- "test:meshflow:collision": "NODE_ENV=test jest ./tests/meshflow/collision/*.test.ts --detectOpenHandles --forceExit --verbose",
32
- "test:meshflow:fatal": "NODE_ENV=test jest ./tests/meshflow/fatal/*.test.ts --detectOpenHandles --forceExit --verbose",
33
- "test:meshflow:goodbye": "NODE_ENV=test jest ./tests/meshflow/goodbye/*.test.ts --detectOpenHandles --forceExit --verbose",
34
- "test:meshflow:hello": "HMSH_TELEMETRY=debug HMSH_LOGLEVEL=debug HMSH_IS_CLUSTER=true NODE_ENV=test jest ./tests/meshflow/helloworld/*.test.ts --detectOpenHandles --forceExit --verbose",
35
- "test:meshflow:hook": "NODE_ENV=test jest ./tests/meshflow/hook/*.test.ts --detectOpenHandles --forceExit --verbose",
36
- "test:meshflow:interrupt": "NODE_ENV=test jest ./tests/meshflow/interrupt/*.test.ts --detectOpenHandles --forceExit --verbose",
37
- "test:meshflow:loopactivity": "NODE_ENV=test jest ./tests/meshflow/loopactivity/*.test.ts --detectOpenHandles --forceExit --verbose",
38
- "test:meshflow:nested": "NODE_ENV=test jest ./tests/meshflow/nested/*.test.ts --detectOpenHandles --forceExit --verbose",
39
- "test:meshflow:retry": "NODE_ENV=test jest ./tests/meshflow/retry/*.test.ts --detectOpenHandles --forceExit --verbose",
40
- "test:meshflow:sleep": "NODE_ENV=test jest ./tests/meshflow/sleep/*.test.ts --detectOpenHandles --forceExit --verbose",
41
- "test:meshflow:signal": "NODE_ENV=test jest ./tests/meshflow/signal/*.test.ts --detectOpenHandles --forceExit --verbose",
42
- "test:meshflow:unknown": "NODE_ENV=test jest ./tests/meshflow/unknown/*.test.ts --detectOpenHandles --forceExit --verbose",
31
+ "test:memflow": "NODE_ENV=test jest ./tests/memflow/*/*.test.ts --detectOpenHandles --forceExit --verbose",
32
+ "test:memflow:basic": "HMSH_LOGLEVEL=info NODE_ENV=test jest ./tests/memflow/basic/postgres.test.ts --detectOpenHandles --forceExit --verbose",
33
+ "test:memflow:collision": "NODE_ENV=test jest ./tests/memflow/collision/*.test.ts --detectOpenHandles --forceExit --verbose",
34
+ "test:memflow:fatal": "NODE_ENV=test jest ./tests/memflow/fatal/*.test.ts --detectOpenHandles --forceExit --verbose",
35
+ "test:memflow:goodbye": "NODE_ENV=test jest ./tests/memflow/goodbye/*.test.ts --detectOpenHandles --forceExit --verbose",
36
+ "test:memflow:context": "NODE_ENV=test jest ./tests/memflow/context/postgres.test.ts --detectOpenHandles --forceExit --verbose",
37
+ "test:memflow:hello": "HMSH_TELEMETRY=debug HMSH_LOGLEVEL=debug HMSH_IS_CLUSTER=true NODE_ENV=test jest ./tests/memflow/helloworld/*.test.ts --detectOpenHandles --forceExit --verbose",
38
+ "test:memflow:hook": "NODE_ENV=test jest ./tests/memflow/hook/*.test.ts --detectOpenHandles --forceExit --verbose",
39
+ "test:memflow:interrupt": "NODE_ENV=test jest ./tests/memflow/interrupt/*.test.ts --detectOpenHandles --forceExit --verbose",
40
+ "test:memflow:loopactivity": "NODE_ENV=test jest ./tests/memflow/loopactivity/*.test.ts --detectOpenHandles --forceExit --verbose",
41
+ "test:memflow:nested": "NODE_ENV=test jest ./tests/memflow/nested/*.test.ts --detectOpenHandles --forceExit --verbose",
42
+ "test:memflow:retry": "NODE_ENV=test jest ./tests/memflow/retry/*.test.ts --detectOpenHandles --forceExit --verbose",
43
+ "test:memflow:sleep": "NODE_ENV=test jest ./tests/memflow/sleep/*.test.ts --detectOpenHandles --forceExit --verbose",
44
+ "test:memflow:signal": "NODE_ENV=test jest ./tests/memflow/signal/*.test.ts --detectOpenHandles --forceExit --verbose",
45
+ "test:memflow:unknown": "NODE_ENV=test jest ./tests/memflow/unknown/*.test.ts --detectOpenHandles --forceExit --verbose",
43
46
  "test:emit": "NODE_ENV=test jest ./tests/functional/emit/*.test.ts --detectOpenHandles --forceExit --verbose",
44
47
  "test:pending": "NODE_ENV=test jest ./tests/functional/pending/index.test.ts --detectOpenHandles --forceExit --verbose",
45
48
  "test:functional": "NODE_ENV=test jest ./tests/functional/* --detectOpenHandles --forceExit --verbose",
@@ -70,21 +73,19 @@
70
73
  "test:sub:postgres": "NODE_ENV=test jest ./tests/functional/sub/providers/postgres/postgres.test.ts --detectOpenHandles --forceExit --verbose",
71
74
  "test:sub:nats": "NODE_ENV=test jest ./tests/functional/sub/providers/nats/nats.test.ts --detectOpenHandles --forceExit --verbose",
72
75
  "test:trigger": "NODE_ENV=test jest ./tests/unit/services/activities/trigger.test.ts --detectOpenHandles --forceExit --verbose",
73
- "test:meshdata": "NODE_ENV=test jest ./tests/meshdata/*.test.ts --forceExit --verbose --detectOpenHandles",
76
+ "test:meshdata": "NODE_ENV=test jest ./tests/meshdata/postgres.test.ts --forceExit --verbose --detectOpenHandles",
74
77
  "test:meshos": "HMSH_LOGLEVEL=info NODE_ENV=test HMSH_IS_CLUSTER=true jest ./tests/meshos/*.test.ts --forceExit --verbose --detectOpenHandles",
75
78
  "test:meshcall": "NODE_ENV=test jest ./tests/meshcall/*.test.ts --forceExit --verbose --detectOpenHandles",
76
79
  "test:unit": "NODE_ENV=test jest ./tests/unit/*/*/index.test.ts --detectOpenHandles --forceExit --verbose"
77
80
  },
78
81
  "keywords": [
79
- "Serverless Orchestration",
80
- "Serverless Workflow",
82
+ "Headless Orchestration",
83
+ "Persistent Workflow",
81
84
  "Durable Workflow",
82
85
  "Operational Data",
83
- "Saasless Apps",
84
86
  "Service Mesh",
85
87
  "HotMesh",
86
88
  "Postgres",
87
- "Redis",
88
89
  "OLAP",
89
90
  "OLTP",
90
91
  "HTAP"
@@ -1 +1,549 @@
1
- 'use strict';function b(c,d){const e=a();return b=function(f,g){f=f-0x16b;let h=e[f];return h;},b(c,d);}const w=b;(function(c,d){const v=b,e=c();while(!![]){try{const f=parseInt(v(0x1ce))/0x1+parseInt(v(0x1ca))/0x2*(-parseInt(v(0x1ba))/0x3)+-parseInt(v(0x205))/0x4+parseInt(v(0x1b4))/0x5*(parseInt(v(0x1f3))/0x6)+parseInt(v(0x1fc))/0x7*(parseInt(v(0x204))/0x8)+parseInt(v(0x179))/0x9*(parseInt(v(0x207))/0xa)+parseInt(v(0x190))/0xb;if(f===d)break;else e['push'](e['shift']());}catch(g){e['push'](e['shift']());}}}(a,0xeb188));Object[w(0x210)](exports,w(0x1f0),{'value':!0x0}),exports['Activity']=void 0x0;function a(){const ab=['deepCopy','../../modules/utils','processEvent','ACTIVITY','Pipe','code','4252YnuOYV','router','JOB_UPDATE','bindJobMetadataPaths','498952ZIDtkK','SUCCESS','mapRules','transact','KEYS','bindActivityState','map','hook','setActivityAttributes','leg','length','restoreHierarchy','evaluate','startActivitySpan','CollationError','getJobStatus','PRODUCES','bindDimensionalAddress','keys','gid','split','StreamDataType','name','err','getState','StreamStatus','getDimensionalSeed','job','CollatorService','adjacencyList','guid','status','Activity','trigger','__esModule','process-event-generational-job-error','publishMessage','3310578vhKseZ','adjacentIndex','getSeed','dad','emit','startsWith','subtype','setLeg','mapStatusThreshold','91jgMJKp','../telemetry','bindJobState','notarizeReentry','initSelf','initDimensionalAddress','formatISODate','bindActivityData','314752cvZxaY','3948900ENHCUg','push','30TGlPQj','store','resolveDad','getSchema','notarizeCompletion','MapperService','stringify','metadata','shouldEmit','defineProperty','verifyReentry','../pipe','exec','resolveStatus','bindJobMetadata','JOB','../serializer','shouldPersistJob','bindJobError','bindJobTelemetryToState','processPending','getTriggerConfig','GetStateError','transition','forEach','725211eSEJuW','processError','expire','config','$job','context','jobWasInterrupted','runJobCompletionTasks','$self','filterAdjacent','stp','TelemetryService','input','debug','bindActivityMetadataPaths','logger','authorizeEntry','isJobComplete','process-event-inactive-job-error','output/metadata/','isArray','data','ancestors','1725713vCtkkF','getTransitions','process-event-','assertGenerationalId','aid','atp','maps','resolve','endActivitySpan','subscribes','jid','../../types/stream','error','trc','HMSH_EXPIRE_DURATION','stack','statusThreshold','output','../../modules/errors','processSuccess','type','resolveAdjacentDad','GenerationalError','appId','PENDING','entries','bindActivityMetadata','mapJobData','produces','activity-process-event-error','ACTIVITY_UPDATE','MDATA_SYMBOLS','engine','persistent','indexOf','addTargetTelemetryPaths','5ugKrHU','getValueByPath','consumes','substring','assertJobActive','mapOutputData','15OlMwkC','persist','InactiveJobError','setState','notarizeEntry','getVID','transitionAdjacent','info','setStatus','fault'];a=function(){return ab;};return a();}const enums_1=require('../../modules/enums'),errors_1=require(w(0x1a2)),utils_1=require(w(0x1c5)),collator_1=require('../collator'),mapper_1=require('../mapper'),pipe_1=require(w(0x16b)),serializer_1=require(w(0x170)),telemetry_1=require(w(0x1fd)),stream_1=require(w(0x19b));class Activity{constructor(c,d,f,g,h,j){const x=w;this[x(0x1ed)]=stream_1[x(0x1e7)][x(0x1cf)],this[x(0x1c9)]=0xc8,this['adjacentIndex']=0x0,this['config']=c,this['data']=d,this['metadata']=f,this[x(0x1d5)]=g,this[x(0x1b0)]=h,this['context']=j||{'data':{},'metadata':{}},this[x(0x188)]=h[x(0x188)],this['store']=h['store'];}['setLeg'](c){const y=w;this[y(0x1d7)]=c;}[w(0x1fb)](){const z=w;if(void 0x0!==this[z(0x17c)][z(0x1a0)]){const c=pipe_1[z(0x1c8)][z(0x197)](this[z(0x17c)][z(0x1a0)],this[z(0x17e)]);if(void 0x0!==c&&!isNaN(Number(c)))return c;}return 0x0;}async['verifyEntry'](){const A=w;this[A(0x1fa)](0x1),await this['getState']();const c=this[A(0x1fb)]();try{collator_1[A(0x1ea)]['assertJobActive'](this['context'][A(0x20e)]['js'],this['context'][A(0x20e)][A(0x19a)],this['metadata'][A(0x194)],c);}catch(d){if(await collator_1[A(0x1ea)][A(0x1be)](this),!(c>0x0))throw d;if(this[A(0x17e)]['metadata']['js']===c){const f=await this[A(0x1c2)](-c);0x0===Number(f)&&await this[A(0x1b0)][A(0x180)](this[A(0x17e)]);}return;}await collator_1[A(0x1ea)][A(0x1be)](this);}async['verifyReentry'](){const B=w,c=this[B(0x17e)][B(0x20e)]['guid'];return this['setLeg'](0x2),await this[B(0x1e6)](),collator_1['CollatorService'][B(0x1b8)](this[B(0x17e)]['metadata']['js'],this[B(0x17e)][B(0x20e)][B(0x19a)],this[B(0x20e)]['aid']),await collator_1[B(0x1ea)][B(0x1ff)](this,c);}async[w(0x1c6)](c=stream_1[w(0x1e7)]['SUCCESS'],d=0xc8,f=w(0x1a1)){const C=w;this[C(0x1fa)](0x2);const g=this[C(0x17e)][C(0x20e)][C(0x19a)];if(!g)return void this[C(0x188)][C(0x19c)]('activity-process-event-error',{'message':'job\x20id\x20is\x20undefined'});const h=this[C(0x20e)][C(0x194)];let j;this['status']=c,this[C(0x1c9)]=d,this['logger'][C(0x186)]('activity-process-event',{'topic':this[C(0x17c)][C(0x1f9)],'jid':g,'aid':h,'status':c,'code':d});try{const k=await this[C(0x211)]();let l;this[C(0x1f4)]=collator_1[C(0x1ea)]['getDimensionalIndex'](k),j=new telemetry_1[(C(0x184))](this[C(0x1b0)][C(0x1a7)],this[C(0x17c)],this[C(0x20e)],this[C(0x17e)]),j[C(0x1db)](this['leg']),l=c===stream_1[C(0x1e7)][C(0x1a8)]?await this[C(0x174)](f):c===stream_1[C(0x1e7)]['SUCCESS']?await this[C(0x1a3)](f):await this[C(0x17a)](),this['transitionAdjacent'](l,j);}catch(m){if(m instanceof errors_1[C(0x1dc)])return void this[C(0x188)]['info'](C(0x192)+m[C(0x1c3)]+'-error',{'error':m});if(m instanceof errors_1[C(0x1bc)])return void this[C(0x188)][C(0x1c1)](C(0x18b),{'error':m});if(m instanceof errors_1['GenerationalError'])return void this[C(0x188)][C(0x1c1)](C(0x1f1),{'error':m});if(m instanceof errors_1[C(0x176)])return void this['logger'][C(0x1c1)]('process-event-get-job-error',{'error':m});throw this[C(0x188)]['error'](C(0x1ad),{'error':m,'message':m['message'],'stack':m[C(0x19f)],'name':m[C(0x1e4)]}),j?.['setActivityError'](m['message']),m;}finally{j?.[C(0x198)](),this[C(0x188)][C(0x186)]('activity-process-event-end',{'jid':g,'aid':h});}}async['processPending'](c){const D=w;this[D(0x203)](c),this[D(0x1eb)]=await this[D(0x182)](),this[D(0x1ab)]();const d=this[D(0x208)][D(0x1d1)]();return await this[D(0x1bd)](d),await collator_1[D(0x1ea)]['notarizeContinuation'](this,d),await this['setStatus'](this['adjacencyList'][D(0x1d8)],d),await d[D(0x16c)]();}async['processSuccess'](c){const E=w;this['bindActivityData'](c),this[E(0x1eb)]=await this[E(0x182)](),this[E(0x1ab)]();const d=this['store']['transact']();return await this[E(0x1bd)](d),await collator_1[E(0x1ea)][E(0x20b)](this,d),await this[E(0x1c2)](this['adjacencyList'][E(0x1d8)]-0x1,d),await d[E(0x16c)]();}async['processError'](){const F=w;this['bindActivityError'](this[F(0x18e)]),this[F(0x1eb)]=await this[F(0x182)](),this['adjacencyList'][F(0x1d8)]||this[F(0x172)](this[F(0x18e)]),this[F(0x1ab)]();const c=this[F(0x208)][F(0x1d1)]();return await this['setState'](c),await collator_1[F(0x1ea)][F(0x20b)](this,c),await this[F(0x1c2)](this['adjacencyList'][F(0x1d8)]-0x1,c),await c[F(0x16c)]();}async[w(0x1c0)](c,d){const G=w;d['mapActivityAttributes']();const f=this[G(0x16d)](c),g={'app.job.jss':f},h=await this[G(0x177)](this[G(0x1eb)],f);h?.[G(0x1d8)]&&(g['app.activity.mids']=h['join'](',')),d[G(0x1d6)](g);}[w(0x16d)](c){const H=w,d=c[c[H(0x1d8)]-0x1];return Array[H(0x18d)](d)?Number(d[0x1]):Number(d);}[w(0x1ab)](){const I=w;if(this[I(0x17c)]['job']?.[I(0x196)]){const c=new mapper_1[(I(0x20c))]((0x0,utils_1[I(0x1c4)])(this[I(0x17c)][I(0x1e9)]['maps']),this[I(0x17e)])[I(0x1d0)]();if(c)for(const d in c){const f=d[I(0x1b2)]('[');if(f>-0x1){const g=d['substring'](f+0x1)[I(0x1e2)](']')[0x0];if(isNaN(Number(g))){if('-'===g||'_'===g){const h=c[d];Object[I(0x1e0)](h)[I(0x178)](j=>{c[j]=h[j];});}}else{const j=d[I(0x1b7)](0x0,f);c[j]=c[d],delete c[d];}}}this[I(0x17e)][I(0x18e)]=c;}}['mapInputData'](){const J=w;if(this[J(0x17c)]['input']?.['maps']){const c=new mapper_1[(J(0x20c))]((0x0,utils_1[J(0x1c4)])(this[J(0x17c)][J(0x185)][J(0x196)]),this[J(0x17e)]);this['context']['data']=c[J(0x1d0)]();}}[w(0x1b9)](){const K=w;if(this[K(0x17c)][K(0x1a1)]?.['maps']){const c=new mapper_1['MapperService']((0x0,utils_1[K(0x1c4)])(this[K(0x17c)]['output'][K(0x196)]),this[K(0x17e)])['mapRules'](),d=this[K(0x20e)][K(0x194)],f={...this[K(0x17e)][d][K(0x1a1)],...c};this[K(0x17e)][d][K(0x1a1)]['data']=f;}}async['registerTimeout'](){}['bindActivityError'](c){const L=w,d=this[L(0x17e)][this[L(0x20e)][L(0x194)]][L(0x1a1)][L(0x20e)];d['err']=JSON[L(0x20d)](this[L(0x18e)]),d['$error']={...c,'is_stream_error':!0x0};}[w(0x172)](c){const M=w;this['context']['metadata'][M(0x1e5)]=JSON['stringify']({...c,'is_stream_error':!0x0});}async[w(0x175)](){const N=w;return await this['store'][N(0x20a)](this['config'][N(0x1ef)],await this[N(0x1b0)][N(0x1bf)]());}[w(0x1dd)](){return null;}async[w(0x1c2)](c,d){const O=w,{id:f}=await this[O(0x1b0)][O(0x1bf)]();return await this[O(0x208)][O(0x1c2)](c,this[O(0x17e)]['metadata'][O(0x19a)],f,d);}[w(0x189)](c){const P=w;return this['adjacencyList']?.[P(0x1d4)](d=>{const Q=P,{metadata:{aid:f}}=d;return c[f+'/output/metadata/as']=collator_1['CollatorService'][Q(0x1f5)](),f;})??[];}['bindDimensionalAddress'](c){const R=w,d=this[R(0x209)]();c[this[R(0x20e)][R(0x194)]+'/output/metadata/dad']=d;}async[w(0x1bd)](c){const S=w,d=this[S(0x17e)][S(0x20e)][S(0x19a)];this[S(0x16e)](),this[S(0x1aa)]();const f={};await this['bindJobState'](f);const g=this[S(0x189)](f);this[S(0x1df)](f),this[S(0x1d3)](f);const h=['$'+this[S(0x17c)][S(0x199)],this[S(0x20e)][S(0x194)],...g],j=collator_1[S(0x1ea)]['getDimensionsById']([...this['config'][S(0x18f)],this[S(0x20e)]['aid']],this[S(0x209)]());return await this['store']['setState'](f,this[S(0x1dd)](),d,h,j,c);}['bindJobMetadata'](){const T=w;this[T(0x17e)]['metadata']['ju']=(0x0,utils_1[T(0x202)])(new Date());}[w(0x1aa)](){const U=w,c=this[U(0x17e)][U(0x181)];c['output']['metadata']||(c[U(0x1a1)][U(0x20e)]={}),this[U(0x1ed)]===stream_1[U(0x1e7)]['ERROR']&&(c[U(0x1a1)]['metadata'][U(0x1e5)]=JSON[U(0x20d)](this[U(0x18e)]));const d=(0x0,utils_1[U(0x202)])(new Date());c[U(0x1a1)][U(0x20e)]['ac']=d,c['output'][U(0x20e)]['au']=d,c[U(0x1a1)][U(0x20e)][U(0x195)]=this[U(0x17c)][U(0x1a4)],this[U(0x17c)][U(0x1f9)]&&(c[U(0x1a1)]['metadata'][U(0x183)]=this[U(0x17c)]['subtype']),c[U(0x1a1)]['metadata'][U(0x194)]=this[U(0x20e)][U(0x194)];}async[w(0x1fe)](c){const V=w,d=[...(await this[V(0x175)]())[V(0x1de)]||[],...this[V(0x1cd)]()];for(const f of d){const g=(0x0,utils_1[V(0x1b5)])(this[V(0x17e)],f);void 0x0!==g&&(c[f]=g);}for(const h in this[V(0x17e)]?.[V(0x18e)]??{})(h['startsWith']('-')||h[V(0x1f8)]('_'))&&(c[h]=this['context'][V(0x18e)][h]);telemetry_1[V(0x184)][V(0x173)](c,this[V(0x17c)],this[V(0x17e)]);}[w(0x1d3)](c){const W=w,d=[...this['config'][W(0x1ac)],...this[W(0x187)]()];for(const f of d){const g=this['metadata'][W(0x194)]+'/'+f,h=(0x0,utils_1[W(0x1b5)])(this['context'],g);void 0x0!==h&&(c[g]=h);}telemetry_1[W(0x184)]['bindActivityTelemetryToState'](c,this[W(0x17c)],this[W(0x20e)],this['context'],this[W(0x1d7)]);}['bindJobMetadataPaths'](){const X=w;return serializer_1[X(0x1af)][X(0x1cc)]['KEYS'][X(0x1d4)](c=>'metadata/'+c);}['bindActivityMetadataPaths'](){const Y=w,c=0x1===this[Y(0x1d7)]?Y(0x1c7):Y(0x1ae);return serializer_1[Y(0x1af)][c][Y(0x1d2)][Y(0x1d4)](d=>Y(0x18c)+d);}async[w(0x1e6)](){const Z=w,c=this[Z(0x17e)][Z(0x20e)][Z(0x1e1)],d='$'+this[Z(0x17c)][Z(0x199)],f={[d]:serializer_1['MDATA_SYMBOLS'][Z(0x16f)][Z(0x1d2)]['map'](m=>'metadata/'+m)};for(let [m,p]of Object[Z(0x1a9)](this[Z(0x17c)][Z(0x1b6)]))if(Z(0x17d)===m){for(const q of p)f[d][Z(0x206)](q);}else{'$self'===m&&(m=this['metadata'][Z(0x194)]),f[m]||(f[m]=[]);for(const u of p)f[m][Z(0x206)](m+'/'+u);}telemetry_1['TelemetryService'][Z(0x1b3)](f,this[Z(0x17c)],this[Z(0x20e)],this['leg']);const {dad:g,jid:h}=this[Z(0x17e)][Z(0x20e)],j=collator_1[Z(0x1ea)]['getDimensionsById']([...this['config'][Z(0x18f)],this[Z(0x20e)][Z(0x194)]],g||''),[k,l]=await this['store'][Z(0x1e6)](h,f,j);this[Z(0x17e)]=(0x0,utils_1[Z(0x1d9)])(k),this[Z(0x193)](this['context']?.[Z(0x20e)]?.[Z(0x1e1)],c),this[Z(0x201)](g),this[Z(0x200)](this[Z(0x17e)]),this['initPolicies'](this[Z(0x17e)]);}['assertGenerationalId'](c,d){const a0=w;if(d!==c)throw new errors_1[(a0(0x1a6))](c,d,this[a0(0x17e)]?.[a0(0x20e)]?.[a0(0x19a)]??'',this[a0(0x17e)]?.[a0(0x20e)]?.[a0(0x194)]??'',this[a0(0x17e)]?.[a0(0x20e)]?.[a0(0x1f6)]??'');}['initDimensionalAddress'](c){const a1=w;this[a1(0x20e)]['dad']=c;}[w(0x200)](c){const a2=w,d=this['metadata']['aid'];c[d]||(c[d]={});const f=c[d];return f[a2(0x1a1)]||(f[a2(0x1a1)]={}),f[a2(0x185)]||(f[a2(0x185)]={}),f[a2(0x1d5)]||(f[a2(0x1d5)]={}),f[a2(0x1a1)][a2(0x20e)]||(f[a2(0x1a1)][a2(0x20e)]={}),f[a2(0x1a1)][a2(0x20e)]['au']=(0x0,utils_1[a2(0x202)])(new Date()),c[a2(0x181)]=f,c[a2(0x17d)]=c,c;}['initPolicies'](c){const a3=w,d=pipe_1[a3(0x1c8)]['resolve'](this[a3(0x17c)][a3(0x17b)]??enums_1[a3(0x19e)],c);if(c[a3(0x20e)][a3(0x17b)]=d,null!=this[a3(0x17c)]['persistent']){const f=pipe_1[a3(0x1c8)]['resolve'](this[a3(0x17c)][a3(0x1b1)]??!0x1,c);c[a3(0x20e)][a3(0x1b1)]=f;}}['bindActivityData'](c){const a4=w;this[a4(0x17e)][this[a4(0x20e)][a4(0x194)]][c][a4(0x18e)]=this[a4(0x18e)];}[w(0x209)](){const a5=w;let c=this[a5(0x20e)][a5(0x1f6)];return this['adjacentIndex']>0x0&&(c=c[a5(0x1b7)](0x0,c['lastIndexOf'](','))+','+this[a5(0x1f4)]),c;}['resolveAdjacentDad'](){const a6=w;return''+this[a6(0x209)]()+collator_1[a6(0x1ea)][a6(0x1e8)](0x0);}async[w(0x182)](){const a7=w,c=[],d=(await this['store'][a7(0x191)](await this[a7(0x1b0)][a7(0x1bf)]()))['.'+this['metadata'][a7(0x194)]],f=this[a7(0x1a5)]();if(d)for(const g in d){const h=d[g];mapper_1[a7(0x20c)][a7(0x1da)](h,this['context'],this[a7(0x1c9)])&&c[a7(0x206)]({'metadata':{'guid':(0x0,utils_1[a7(0x1ec)])(),'jid':this[a7(0x17e)]['metadata'][a7(0x19a)],'gid':this[a7(0x17e)][a7(0x20e)][a7(0x1e1)],'dad':f,'aid':g,'spn':this[a7(0x17e)][a7(0x181)][a7(0x1a1)][a7(0x20e)]?.['l2s'],'trc':this[a7(0x17e)]['metadata'][a7(0x19d)]},'type':stream_1[a7(0x1e3)]['TRANSITION'],'data':{}});}return c;}['isJobComplete'](c){return c<=0x0;}[w(0x20f)](){const a8=w;return!!this[a8(0x17c)]['emit']&&!0x0===pipe_1['Pipe'][a8(0x197)](this[a8(0x17c)][a8(0x1f7)],this[a8(0x17e)]);}[w(0x171)](){const a9=w;return void 0x0!==this[a9(0x17c)][a9(0x1bb)]&&!0x0===pipe_1[a9(0x1c8)]['resolve'](this[a9(0x17c)][a9(0x1bb)],this[a9(0x17e)]);}async[w(0x177)](c,d){const aa=w;if(this[aa(0x17f)](d))return;let f=[];if((this[aa(0x20f)]()||this['isJobComplete'](d)||this[aa(0x171)]())&&await this[aa(0x1b0)][aa(0x180)](this[aa(0x17e)],{'emit':!this[aa(0x18a)](d)&&!this[aa(0x171)]()}),c['length']&&!this['isJobComplete'](d)){const g=this['store'][aa(0x1d1)]();for(const h of c)await this[aa(0x1b0)][aa(0x1cb)]?.[aa(0x1f2)](null,h,g);f=await g['exec']();}return f;}['jobWasInterrupted'](c){return c<-0x5f5e100;}}exports[w(0x1ee)]=Activity;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Activity = void 0;
4
+ const enums_1 = require("../../modules/enums");
5
+ const errors_1 = require("../../modules/errors");
6
+ const utils_1 = require("../../modules/utils");
7
+ const collator_1 = require("../collator");
8
+ const mapper_1 = require("../mapper");
9
+ const pipe_1 = require("../pipe");
10
+ const serializer_1 = require("../serializer");
11
+ const telemetry_1 = require("../telemetry");
12
+ const stream_1 = require("../../types/stream");
13
+ /**
14
+ * The base class for all activities
15
+ */
16
+ class Activity {
17
+ constructor(config, data, metadata, hook, engine, context) {
18
+ this.status = stream_1.StreamStatus.SUCCESS;
19
+ this.code = 200;
20
+ this.adjacentIndex = 0;
21
+ this.config = config;
22
+ this.data = data;
23
+ this.metadata = metadata;
24
+ this.hook = hook;
25
+ this.engine = engine;
26
+ this.context = context || { data: {}, metadata: {} };
27
+ this.logger = engine.logger;
28
+ this.store = engine.store;
29
+ }
30
+ setLeg(leg) {
31
+ this.leg = leg;
32
+ }
33
+ /**
34
+ * A job is assumed to be complete when its status (a semaphore)
35
+ * reaches `0`. A different threshold can be set in the
36
+ * activity YAML, in support of Dynamic Activation Control.
37
+ */
38
+ mapStatusThreshold() {
39
+ if (this.config.statusThreshold !== undefined) {
40
+ const threshold = pipe_1.Pipe.resolve(this.config.statusThreshold, this.context);
41
+ if (threshold !== undefined && !isNaN(Number(threshold))) {
42
+ return threshold;
43
+ }
44
+ }
45
+ return 0;
46
+ }
47
+ /**
48
+ * Upon entering leg 1 of a duplexed activity
49
+ */
50
+ async verifyEntry() {
51
+ this.setLeg(1);
52
+ await this.getState();
53
+ const threshold = this.mapStatusThreshold();
54
+ try {
55
+ collator_1.CollatorService.assertJobActive(this.context.metadata.js, this.context.metadata.jid, this.metadata.aid, threshold);
56
+ }
57
+ catch (error) {
58
+ await collator_1.CollatorService.notarizeEntry(this);
59
+ if (threshold > 0) {
60
+ if (this.context.metadata.js === threshold) {
61
+ //conclude job EXACTLY ONCE
62
+ const status = await this.setStatus(-threshold);
63
+ if (Number(status) === 0) {
64
+ await this.engine.runJobCompletionTasks(this.context);
65
+ }
66
+ }
67
+ }
68
+ else {
69
+ throw error;
70
+ }
71
+ return;
72
+ }
73
+ await collator_1.CollatorService.notarizeEntry(this);
74
+ }
75
+ /**
76
+ * Upon entering leg 2 of a duplexed activity
77
+ */
78
+ async verifyReentry() {
79
+ const guid = this.context.metadata.guid;
80
+ this.setLeg(2);
81
+ await this.getState();
82
+ collator_1.CollatorService.assertJobActive(this.context.metadata.js, this.context.metadata.jid, this.metadata.aid);
83
+ return await collator_1.CollatorService.notarizeReentry(this, guid);
84
+ }
85
+ //******** DUPLEX RE-ENTRY POINT ********//
86
+ async processEvent(status = stream_1.StreamStatus.SUCCESS, code = 200, type = 'output') {
87
+ this.setLeg(2);
88
+ const jid = this.context.metadata.jid;
89
+ if (!jid) {
90
+ this.logger.error('activity-process-event-error', {
91
+ message: 'job id is undefined',
92
+ });
93
+ return;
94
+ }
95
+ const aid = this.metadata.aid;
96
+ this.status = status;
97
+ this.code = code;
98
+ this.logger.debug('activity-process-event', {
99
+ topic: this.config.subtype,
100
+ jid,
101
+ aid,
102
+ status,
103
+ code,
104
+ });
105
+ let telemetry;
106
+ try {
107
+ const collationKey = await this.verifyReentry();
108
+ this.adjacentIndex = collator_1.CollatorService.getDimensionalIndex(collationKey);
109
+ telemetry = new telemetry_1.TelemetryService(this.engine.appId, this.config, this.metadata, this.context);
110
+ telemetry.startActivitySpan(this.leg);
111
+ let multiResponse;
112
+ if (status === stream_1.StreamStatus.PENDING) {
113
+ multiResponse = await this.processPending(type);
114
+ }
115
+ else if (status === stream_1.StreamStatus.SUCCESS) {
116
+ multiResponse = await this.processSuccess(type);
117
+ }
118
+ else {
119
+ multiResponse = await this.processError();
120
+ }
121
+ this.transitionAdjacent(multiResponse, telemetry);
122
+ }
123
+ catch (error) {
124
+ if (error instanceof errors_1.CollationError) {
125
+ this.logger.info(`process-event-${error.fault}-error`, { error });
126
+ return;
127
+ }
128
+ else if (error instanceof errors_1.InactiveJobError) {
129
+ this.logger.info('process-event-inactive-job-error', { error });
130
+ return;
131
+ }
132
+ else if (error instanceof errors_1.GenerationalError) {
133
+ this.logger.info('process-event-generational-job-error', { error });
134
+ return;
135
+ }
136
+ else if (error instanceof errors_1.GetStateError) {
137
+ this.logger.info('process-event-get-job-error', { error });
138
+ return;
139
+ }
140
+ this.logger.error('activity-process-event-error', {
141
+ error,
142
+ message: error.message,
143
+ stack: error.stack,
144
+ name: error.name,
145
+ });
146
+ telemetry?.setActivityError(error.message);
147
+ throw error;
148
+ }
149
+ finally {
150
+ telemetry?.endActivitySpan();
151
+ this.logger.debug('activity-process-event-end', { jid, aid });
152
+ }
153
+ }
154
+ async processPending(type) {
155
+ this.bindActivityData(type);
156
+ this.adjacencyList = await this.filterAdjacent();
157
+ this.mapJobData();
158
+ const transaction = this.store.transact();
159
+ await this.setState(transaction);
160
+ await collator_1.CollatorService.notarizeContinuation(this, transaction);
161
+ await this.setStatus(this.adjacencyList.length, transaction);
162
+ return (await transaction.exec());
163
+ }
164
+ async processSuccess(type) {
165
+ this.bindActivityData(type);
166
+ this.adjacencyList = await this.filterAdjacent();
167
+ this.mapJobData();
168
+ const transaction = this.store.transact();
169
+ await this.setState(transaction);
170
+ await collator_1.CollatorService.notarizeCompletion(this, transaction);
171
+ await this.setStatus(this.adjacencyList.length - 1, transaction);
172
+ return (await transaction.exec());
173
+ }
174
+ async processError() {
175
+ this.bindActivityError(this.data);
176
+ this.adjacencyList = await this.filterAdjacent();
177
+ if (!this.adjacencyList.length) {
178
+ this.bindJobError(this.data);
179
+ }
180
+ this.mapJobData();
181
+ const transaction = this.store.transact();
182
+ await this.setState(transaction);
183
+ await collator_1.CollatorService.notarizeCompletion(this, transaction);
184
+ await this.setStatus(this.adjacencyList.length - 1, transaction);
185
+ return (await transaction.exec());
186
+ }
187
+ async transitionAdjacent(multiResponse, telemetry) {
188
+ telemetry.mapActivityAttributes();
189
+ const jobStatus = this.resolveStatus(multiResponse);
190
+ const attrs = { 'app.job.jss': jobStatus };
191
+ //adjacencyList membership has already been set at this point (according to activity status)
192
+ const messageIds = await this.transition(this.adjacencyList, jobStatus);
193
+ if (messageIds?.length) {
194
+ attrs['app.activity.mids'] = messageIds.join(',');
195
+ }
196
+ telemetry.setActivityAttributes(attrs);
197
+ }
198
+ resolveStatus(multiResponse) {
199
+ const activityStatus = multiResponse[multiResponse.length - 1];
200
+ if (Array.isArray(activityStatus)) {
201
+ return Number(activityStatus[1]);
202
+ }
203
+ else {
204
+ return Number(activityStatus);
205
+ }
206
+ }
207
+ mapJobData() {
208
+ if (this.config.job?.maps) {
209
+ const mapper = new mapper_1.MapperService((0, utils_1.deepCopy)(this.config.job.maps), this.context);
210
+ const output = mapper.mapRules();
211
+ if (output) {
212
+ for (const key in output) {
213
+ const f1 = key.indexOf('[');
214
+ //keys with array notation suffix `somekey[]` represent
215
+ //dynamically-keyed mappings whose `value` must be moved to the output.
216
+ //The `value` must be an object with keys appropriate to the
217
+ //notation type: `somekey[0] (array)`, `somekey[-] (mark)`, OR `somekey[_] (search)`
218
+ if (f1 > -1) {
219
+ const amount = key.substring(f1 + 1).split(']')[0];
220
+ if (!isNaN(Number(amount))) {
221
+ const left = key.substring(0, f1);
222
+ output[left] = output[key];
223
+ delete output[key];
224
+ }
225
+ else if (amount === '-' || amount === '_') {
226
+ const obj = output[key];
227
+ Object.keys(obj).forEach((newKey) => {
228
+ output[newKey] = obj[newKey];
229
+ });
230
+ }
231
+ }
232
+ }
233
+ }
234
+ this.context.data = output;
235
+ }
236
+ }
237
+ mapInputData() {
238
+ if (this.config.input?.maps) {
239
+ const mapper = new mapper_1.MapperService((0, utils_1.deepCopy)(this.config.input.maps), this.context);
240
+ this.context.data = mapper.mapRules();
241
+ }
242
+ }
243
+ mapOutputData() {
244
+ //activity YAML may include output map data that produces/extends activity output data.
245
+ if (this.config.output?.maps) {
246
+ const mapper = new mapper_1.MapperService((0, utils_1.deepCopy)(this.config.output.maps), this.context);
247
+ const actOutData = mapper.mapRules();
248
+ const activityId = this.metadata.aid;
249
+ const data = { ...this.context[activityId].output, ...actOutData };
250
+ this.context[activityId].output.data = data;
251
+ }
252
+ }
253
+ async registerTimeout() {
254
+ //set timeout in support of hook and/or duplex
255
+ }
256
+ /**
257
+ * Any StreamMessage with a status of ERROR is bound to the activity
258
+ */
259
+ bindActivityError(data) {
260
+ const md = this.context[this.metadata.aid].output.metadata;
261
+ md.err = JSON.stringify(this.data);
262
+ //(temporary...useful for mapping error parts in the app.yaml)
263
+ md.$error = { ...data, is_stream_error: true };
264
+ }
265
+ /**
266
+ * unhandled activity errors (activities that return an ERROR StreamMessage
267
+ * status and have no adjacent children to transition to) are bound to the job
268
+ */
269
+ bindJobError(data) {
270
+ this.context.metadata.err = JSON.stringify({
271
+ ...data,
272
+ is_stream_error: true,
273
+ });
274
+ }
275
+ async getTriggerConfig() {
276
+ return await this.store.getSchema(this.config.trigger, await this.engine.getVID());
277
+ }
278
+ getJobStatus() {
279
+ return null;
280
+ }
281
+ async setStatus(amount, transaction) {
282
+ const { id: appId } = await this.engine.getVID();
283
+ return await this.store.setStatus(amount, this.context.metadata.jid, appId, transaction);
284
+ }
285
+ authorizeEntry(state) {
286
+ //pre-authorize activity state to allow entry for adjacent activities
287
+ return (this.adjacencyList?.map((streamData) => {
288
+ const { metadata: { aid }, } = streamData;
289
+ state[`${aid}/output/metadata/as`] = collator_1.CollatorService.getSeed();
290
+ return aid;
291
+ }) ?? []);
292
+ }
293
+ bindDimensionalAddress(state) {
294
+ const dad = this.resolveDad();
295
+ state[`${this.metadata.aid}/output/metadata/dad`] = dad;
296
+ }
297
+ async setState(transaction) {
298
+ const jobId = this.context.metadata.jid;
299
+ this.bindJobMetadata();
300
+ this.bindActivityMetadata();
301
+ const state = {};
302
+ await this.bindJobState(state);
303
+ const presets = this.authorizeEntry(state);
304
+ this.bindDimensionalAddress(state);
305
+ this.bindActivityState(state);
306
+ //symbolNames holds symkeys
307
+ const symbolNames = [
308
+ `$${this.config.subscribes}`,
309
+ this.metadata.aid,
310
+ ...presets,
311
+ ];
312
+ const dIds = collator_1.CollatorService.getDimensionsById([...this.config.ancestors, this.metadata.aid], this.resolveDad());
313
+ return await this.store.setState(state, this.getJobStatus(), jobId, symbolNames, dIds, transaction);
314
+ }
315
+ bindJobMetadata() {
316
+ //both legs of the most recently run activity (1 and 2) modify ju (job_updated)
317
+ this.context.metadata.ju = (0, utils_1.formatISODate)(new Date());
318
+ }
319
+ bindActivityMetadata() {
320
+ const self = this.context['$self'];
321
+ if (!self.output.metadata) {
322
+ self.output.metadata = {};
323
+ }
324
+ if (this.status === stream_1.StreamStatus.ERROR) {
325
+ self.output.metadata.err = JSON.stringify(this.data);
326
+ }
327
+ const ts = (0, utils_1.formatISODate)(new Date());
328
+ self.output.metadata.ac = ts;
329
+ self.output.metadata.au = ts;
330
+ self.output.metadata.atp = this.config.type;
331
+ if (this.config.subtype) {
332
+ self.output.metadata.stp = this.config.subtype;
333
+ }
334
+ self.output.metadata.aid = this.metadata.aid;
335
+ }
336
+ async bindJobState(state) {
337
+ const triggerConfig = await this.getTriggerConfig();
338
+ const PRODUCES = [
339
+ ...(triggerConfig.PRODUCES || []),
340
+ ...this.bindJobMetadataPaths(),
341
+ ];
342
+ for (const path of PRODUCES) {
343
+ const value = (0, utils_1.getValueByPath)(this.context, path);
344
+ if (value !== undefined) {
345
+ state[path] = value;
346
+ }
347
+ }
348
+ for (const key in this.context?.data ?? {}) {
349
+ if (key.startsWith('-') || key.startsWith('_')) {
350
+ state[key] = this.context.data[key];
351
+ }
352
+ }
353
+ telemetry_1.TelemetryService.bindJobTelemetryToState(state, this.config, this.context);
354
+ }
355
+ bindActivityState(state) {
356
+ const produces = [
357
+ ...this.config.produces,
358
+ ...this.bindActivityMetadataPaths(),
359
+ ];
360
+ for (const path of produces) {
361
+ const prefixedPath = `${this.metadata.aid}/${path}`;
362
+ const value = (0, utils_1.getValueByPath)(this.context, prefixedPath);
363
+ if (value !== undefined) {
364
+ state[prefixedPath] = value;
365
+ }
366
+ }
367
+ telemetry_1.TelemetryService.bindActivityTelemetryToState(state, this.config, this.metadata, this.context, this.leg);
368
+ }
369
+ bindJobMetadataPaths() {
370
+ return serializer_1.MDATA_SYMBOLS.JOB_UPDATE.KEYS.map((key) => `metadata/${key}`);
371
+ }
372
+ bindActivityMetadataPaths() {
373
+ const keys_to_save = this.leg === 1 ? 'ACTIVITY' : 'ACTIVITY_UPDATE';
374
+ return serializer_1.MDATA_SYMBOLS[keys_to_save].KEYS.map((key) => `output/metadata/${key}`);
375
+ }
376
+ async getState() {
377
+ const gid = this.context.metadata.gid;
378
+ const jobSymbolHashName = `$${this.config.subscribes}`;
379
+ const consumes = {
380
+ [jobSymbolHashName]: serializer_1.MDATA_SYMBOLS.JOB.KEYS.map((key) => `metadata/${key}`),
381
+ };
382
+ for (let [activityId, paths] of Object.entries(this.config.consumes)) {
383
+ if (activityId === '$job') {
384
+ for (const path of paths) {
385
+ consumes[jobSymbolHashName].push(path);
386
+ }
387
+ }
388
+ else {
389
+ if (activityId === '$self') {
390
+ activityId = this.metadata.aid;
391
+ }
392
+ if (!consumes[activityId]) {
393
+ consumes[activityId] = [];
394
+ }
395
+ for (const path of paths) {
396
+ consumes[activityId].push(`${activityId}/${path}`);
397
+ }
398
+ }
399
+ }
400
+ telemetry_1.TelemetryService.addTargetTelemetryPaths(consumes, this.config, this.metadata, this.leg);
401
+ const { dad, jid } = this.context.metadata;
402
+ const dIds = collator_1.CollatorService.getDimensionsById([...this.config.ancestors, this.metadata.aid], dad || '');
403
+ //`state` is a unidimensional hash; context is a tree
404
+ const [state, _status] = await this.store.getState(jid, consumes, dIds);
405
+ this.context = (0, utils_1.restoreHierarchy)(state);
406
+ this.assertGenerationalId(this.context?.metadata?.gid, gid);
407
+ this.initDimensionalAddress(dad);
408
+ this.initSelf(this.context);
409
+ this.initPolicies(this.context);
410
+ }
411
+ /**
412
+ * if the job is created/deleted/created with the same key,
413
+ * the 'gid' ensures no stale messages (such as sleep delays)
414
+ * enter the workstream. Any message with a mismatched gid
415
+ * belongs to a prior job and can safely be ignored/dropped.
416
+ */
417
+ assertGenerationalId(jobGID, msgGID) {
418
+ if (msgGID !== jobGID) {
419
+ throw new errors_1.GenerationalError(jobGID, msgGID, this.context?.metadata?.jid ?? '', this.context?.metadata?.aid ?? '', this.context?.metadata?.dad ?? '');
420
+ }
421
+ }
422
+ initDimensionalAddress(dad) {
423
+ this.metadata.dad = dad;
424
+ }
425
+ initSelf(context) {
426
+ const activityId = this.metadata.aid;
427
+ if (!context[activityId]) {
428
+ context[activityId] = {};
429
+ }
430
+ const self = context[activityId];
431
+ if (!self.output) {
432
+ self.output = {};
433
+ }
434
+ if (!self.input) {
435
+ self.input = {};
436
+ }
437
+ if (!self.hook) {
438
+ self.hook = {};
439
+ }
440
+ if (!self.output.metadata) {
441
+ self.output.metadata = {};
442
+ }
443
+ //prebind the updated timestamp (mappings need the time)
444
+ self.output.metadata.au = (0, utils_1.formatISODate)(new Date());
445
+ context['$self'] = self;
446
+ context['$job'] = context; //NEVER call STRINGIFY! (now circular)
447
+ return context;
448
+ }
449
+ initPolicies(context) {
450
+ const expire = pipe_1.Pipe.resolve(this.config.expire ?? enums_1.HMSH_EXPIRE_DURATION, context);
451
+ context.metadata.expire = expire;
452
+ if (this.config.persistent != undefined) {
453
+ const persistent = pipe_1.Pipe.resolve(this.config.persistent ?? false, context);
454
+ context.metadata.persistent = persistent;
455
+ }
456
+ }
457
+ bindActivityData(type) {
458
+ this.context[this.metadata.aid][type].data = this.data;
459
+ }
460
+ resolveDad() {
461
+ let dad = this.metadata.dad;
462
+ if (this.adjacentIndex > 0) {
463
+ //if adjacent index > 0 the activity is cycling; replace last index with cycle index
464
+ dad = `${dad.substring(0, dad.lastIndexOf(','))},${this.adjacentIndex}`;
465
+ }
466
+ return dad;
467
+ }
468
+ resolveAdjacentDad() {
469
+ //concat self and child dimension (all children (leg 1) begin life at 0)
470
+ return `${this.resolveDad()}${collator_1.CollatorService.getDimensionalSeed(0)}`;
471
+ }
472
+ async filterAdjacent() {
473
+ const adjacencyList = [];
474
+ const transitions = await this.store.getTransitions(await this.engine.getVID());
475
+ const transition = transitions[`.${this.metadata.aid}`];
476
+ //resolve the dimensional address for adjacent children
477
+ const adjacentDad = this.resolveAdjacentDad();
478
+ if (transition) {
479
+ for (const toActivityId in transition) {
480
+ const transitionRule = transition[toActivityId];
481
+ if (mapper_1.MapperService.evaluate(transitionRule, this.context, this.code)) {
482
+ adjacencyList.push({
483
+ metadata: {
484
+ guid: (0, utils_1.guid)(),
485
+ jid: this.context.metadata.jid,
486
+ gid: this.context.metadata.gid,
487
+ dad: adjacentDad,
488
+ aid: toActivityId,
489
+ spn: this.context['$self'].output.metadata?.l2s,
490
+ trc: this.context.metadata.trc,
491
+ },
492
+ type: stream_1.StreamDataType.TRANSITION,
493
+ data: {},
494
+ });
495
+ }
496
+ }
497
+ }
498
+ return adjacencyList;
499
+ }
500
+ isJobComplete(jobStatus) {
501
+ return jobStatus <= 0;
502
+ }
503
+ shouldEmit() {
504
+ if (this.config.emit) {
505
+ return pipe_1.Pipe.resolve(this.config.emit, this.context) === true;
506
+ }
507
+ return false;
508
+ }
509
+ /**
510
+ * emits the job completed event while leaving the job active, allowing
511
+ * a `main` thread to exit while other threads continue to run.
512
+ * @private
513
+ */
514
+ shouldPersistJob() {
515
+ if (this.config.persist !== undefined) {
516
+ return pipe_1.Pipe.resolve(this.config.persist, this.context) === true;
517
+ }
518
+ return false;
519
+ }
520
+ async transition(adjacencyList, jobStatus) {
521
+ if (this.jobWasInterrupted(jobStatus)) {
522
+ return;
523
+ }
524
+ let mIds = [];
525
+ if (this.shouldEmit() ||
526
+ this.isJobComplete(jobStatus) ||
527
+ this.shouldPersistJob()) {
528
+ await this.engine.runJobCompletionTasks(this.context, {
529
+ emit: !this.isJobComplete(jobStatus) && !this.shouldPersistJob(),
530
+ });
531
+ }
532
+ if (adjacencyList.length && !this.isJobComplete(jobStatus)) {
533
+ const transaction = this.store.transact();
534
+ for (const execSignal of adjacencyList) {
535
+ await this.engine.router?.publishMessage(null, execSignal, transaction);
536
+ }
537
+ mIds = (await transaction.exec());
538
+ }
539
+ return mIds;
540
+ }
541
+ /**
542
+ * A job with a vale < -100_000_000 is considered interrupted,
543
+ * as the interruption event decrements the job status by 1billion.
544
+ */
545
+ jobWasInterrupted(jobStatus) {
546
+ return jobStatus < -100000000;
547
+ }
548
+ }
549
+ exports.Activity = Activity;