@hotmeshio/hotmesh 0.0.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 (263) hide show
  1. package/LICENSE +214 -0
  2. package/README.md +241 -0
  3. package/build/index.d.ts +4 -0
  4. package/build/index.js +7 -0
  5. package/build/modules/errors.d.ts +28 -0
  6. package/build/modules/errors.js +50 -0
  7. package/build/modules/key.d.ts +75 -0
  8. package/build/modules/key.js +116 -0
  9. package/build/modules/utils.d.ts +34 -0
  10. package/build/modules/utils.js +173 -0
  11. package/build/package.json +73 -0
  12. package/build/services/activities/activity.d.ts +59 -0
  13. package/build/services/activities/activity.js +396 -0
  14. package/build/services/activities/await.d.ts +16 -0
  15. package/build/services/activities/await.js +143 -0
  16. package/build/services/activities/emit.d.ts +9 -0
  17. package/build/services/activities/emit.js +13 -0
  18. package/build/services/activities/index.d.ts +15 -0
  19. package/build/services/activities/index.js +16 -0
  20. package/build/services/activities/iterate.d.ts +9 -0
  21. package/build/services/activities/iterate.js +13 -0
  22. package/build/services/activities/trigger.d.ts +22 -0
  23. package/build/services/activities/trigger.js +161 -0
  24. package/build/services/activities/worker.d.ts +17 -0
  25. package/build/services/activities/worker.js +164 -0
  26. package/build/services/collator/index.d.ts +54 -0
  27. package/build/services/collator/index.js +171 -0
  28. package/build/services/compiler/deployer.d.ts +35 -0
  29. package/build/services/compiler/deployer.js +412 -0
  30. package/build/services/compiler/index.d.ts +30 -0
  31. package/build/services/compiler/index.js +111 -0
  32. package/build/services/compiler/validator.d.ts +32 -0
  33. package/build/services/compiler/validator.js +134 -0
  34. package/build/services/connector/clients/ioredis.d.ts +13 -0
  35. package/build/services/connector/clients/ioredis.js +50 -0
  36. package/build/services/connector/clients/redis.d.ts +13 -0
  37. package/build/services/connector/clients/redis.js +62 -0
  38. package/build/services/connector/index.d.ts +5 -0
  39. package/build/services/connector/index.js +31 -0
  40. package/build/services/dimension/index.d.ts +29 -0
  41. package/build/services/dimension/index.js +35 -0
  42. package/build/services/durable/asyncLocalStorage.d.ts +3 -0
  43. package/build/services/durable/asyncLocalStorage.js +5 -0
  44. package/build/services/durable/client.d.ts +15 -0
  45. package/build/services/durable/client.js +108 -0
  46. package/build/services/durable/connection.d.ts +4 -0
  47. package/build/services/durable/connection.js +51 -0
  48. package/build/services/durable/factory.d.ts +3 -0
  49. package/build/services/durable/factory.js +123 -0
  50. package/build/services/durable/handle.d.ts +8 -0
  51. package/build/services/durable/handle.js +38 -0
  52. package/build/services/durable/index.d.ts +57 -0
  53. package/build/services/durable/index.js +58 -0
  54. package/build/services/durable/native.d.ts +4 -0
  55. package/build/services/durable/native.js +47 -0
  56. package/build/services/durable/worker.d.ts +36 -0
  57. package/build/services/durable/worker.js +266 -0
  58. package/build/services/durable/workflow.d.ts +6 -0
  59. package/build/services/durable/workflow.js +135 -0
  60. package/build/services/engine/index.d.ts +82 -0
  61. package/build/services/engine/index.js +511 -0
  62. package/build/services/hotmesh/index.d.ts +45 -0
  63. package/build/services/hotmesh/index.js +134 -0
  64. package/build/services/logger/index.d.ts +17 -0
  65. package/build/services/logger/index.js +73 -0
  66. package/build/services/mapper/index.d.ts +24 -0
  67. package/build/services/mapper/index.js +72 -0
  68. package/build/services/pipe/functions/array.d.ts +24 -0
  69. package/build/services/pipe/functions/array.js +69 -0
  70. package/build/services/pipe/functions/bitwise.d.ts +9 -0
  71. package/build/services/pipe/functions/bitwise.js +24 -0
  72. package/build/services/pipe/functions/conditional.d.ts +10 -0
  73. package/build/services/pipe/functions/conditional.js +27 -0
  74. package/build/services/pipe/functions/date.d.ts +57 -0
  75. package/build/services/pipe/functions/date.js +167 -0
  76. package/build/services/pipe/functions/index.d.ts +25 -0
  77. package/build/services/pipe/functions/index.js +26 -0
  78. package/build/services/pipe/functions/json.d.ts +5 -0
  79. package/build/services/pipe/functions/json.js +12 -0
  80. package/build/services/pipe/functions/math.d.ts +38 -0
  81. package/build/services/pipe/functions/math.js +111 -0
  82. package/build/services/pipe/functions/number.d.ts +25 -0
  83. package/build/services/pipe/functions/number.js +133 -0
  84. package/build/services/pipe/functions/object.d.ts +22 -0
  85. package/build/services/pipe/functions/object.js +63 -0
  86. package/build/services/pipe/functions/string.d.ts +23 -0
  87. package/build/services/pipe/functions/string.js +69 -0
  88. package/build/services/pipe/functions/symbol.d.ts +12 -0
  89. package/build/services/pipe/functions/symbol.js +33 -0
  90. package/build/services/pipe/functions/unary.d.ts +7 -0
  91. package/build/services/pipe/functions/unary.js +18 -0
  92. package/build/services/pipe/index.d.ts +30 -0
  93. package/build/services/pipe/index.js +128 -0
  94. package/build/services/quorum/index.d.ts +34 -0
  95. package/build/services/quorum/index.js +147 -0
  96. package/build/services/reporter/index.d.ts +47 -0
  97. package/build/services/reporter/index.js +330 -0
  98. package/build/services/serializer/index.d.ts +36 -0
  99. package/build/services/serializer/index.js +222 -0
  100. package/build/services/signaler/store.d.ts +15 -0
  101. package/build/services/signaler/store.js +53 -0
  102. package/build/services/signaler/stream.d.ts +43 -0
  103. package/build/services/signaler/stream.js +317 -0
  104. package/build/services/store/cache.d.ts +66 -0
  105. package/build/services/store/cache.js +127 -0
  106. package/build/services/store/clients/ioredis.d.ts +27 -0
  107. package/build/services/store/clients/ioredis.js +96 -0
  108. package/build/services/store/clients/redis.d.ts +29 -0
  109. package/build/services/store/clients/redis.js +143 -0
  110. package/build/services/store/index.d.ts +88 -0
  111. package/build/services/store/index.js +657 -0
  112. package/build/services/stream/clients/ioredis.d.ts +23 -0
  113. package/build/services/stream/clients/ioredis.js +115 -0
  114. package/build/services/stream/clients/redis.d.ts +23 -0
  115. package/build/services/stream/clients/redis.js +119 -0
  116. package/build/services/stream/index.d.ts +21 -0
  117. package/build/services/stream/index.js +9 -0
  118. package/build/services/sub/clients/ioredis.d.ts +20 -0
  119. package/build/services/sub/clients/ioredis.js +72 -0
  120. package/build/services/sub/clients/redis.d.ts +20 -0
  121. package/build/services/sub/clients/redis.js +63 -0
  122. package/build/services/sub/index.d.ts +18 -0
  123. package/build/services/sub/index.js +9 -0
  124. package/build/services/task/index.d.ts +18 -0
  125. package/build/services/task/index.js +73 -0
  126. package/build/services/telemetry/index.d.ts +49 -0
  127. package/build/services/telemetry/index.js +223 -0
  128. package/build/services/worker/index.d.ts +30 -0
  129. package/build/services/worker/index.js +105 -0
  130. package/build/types/activity.d.ts +86 -0
  131. package/build/types/activity.js +2 -0
  132. package/build/types/app.d.ts +16 -0
  133. package/build/types/app.js +2 -0
  134. package/build/types/async.d.ts +5 -0
  135. package/build/types/async.js +2 -0
  136. package/build/types/cache.d.ts +1 -0
  137. package/build/types/cache.js +2 -0
  138. package/build/types/collator.d.ts +8 -0
  139. package/build/types/collator.js +11 -0
  140. package/build/types/durable.d.ts +59 -0
  141. package/build/types/durable.js +2 -0
  142. package/build/types/hook.d.ts +31 -0
  143. package/build/types/hook.js +9 -0
  144. package/build/types/hotmesh.d.ts +82 -0
  145. package/build/types/hotmesh.js +2 -0
  146. package/build/types/index.d.ts +20 -0
  147. package/build/types/index.js +21 -0
  148. package/build/types/ioredisclient.d.ts +5 -0
  149. package/build/types/ioredisclient.js +5 -0
  150. package/build/types/job.d.ts +50 -0
  151. package/build/types/job.js +2 -0
  152. package/build/types/logger.d.ts +6 -0
  153. package/build/types/logger.js +2 -0
  154. package/build/types/map.d.ts +4 -0
  155. package/build/types/map.js +2 -0
  156. package/build/types/pipe.d.ts +4 -0
  157. package/build/types/pipe.js +2 -0
  158. package/build/types/quorum.d.ts +46 -0
  159. package/build/types/quorum.js +2 -0
  160. package/build/types/redis.d.ts +8 -0
  161. package/build/types/redis.js +2 -0
  162. package/build/types/redisclient.d.ts +25 -0
  163. package/build/types/redisclient.js +2 -0
  164. package/build/types/serializer.d.ts +33 -0
  165. package/build/types/serializer.js +2 -0
  166. package/build/types/stats.d.ts +83 -0
  167. package/build/types/stats.js +2 -0
  168. package/build/types/stream.d.ts +67 -0
  169. package/build/types/stream.js +25 -0
  170. package/build/types/telemetry.d.ts +1 -0
  171. package/build/types/telemetry.js +11 -0
  172. package/build/types/transition.d.ts +17 -0
  173. package/build/types/transition.js +2 -0
  174. package/index.ts +5 -0
  175. package/modules/errors.ts +55 -0
  176. package/modules/key.ts +129 -0
  177. package/modules/utils.ts +170 -0
  178. package/package.json +73 -0
  179. package/services/activities/activity.ts +473 -0
  180. package/services/activities/await.ts +172 -0
  181. package/services/activities/emit.ts +25 -0
  182. package/services/activities/index.ts +15 -0
  183. package/services/activities/iterate.ts +26 -0
  184. package/services/activities/trigger.ts +196 -0
  185. package/services/activities/worker.ts +190 -0
  186. package/services/collator/README.md +102 -0
  187. package/services/collator/index.ts +182 -0
  188. package/services/compiler/deployer.ts +432 -0
  189. package/services/compiler/index.ts +98 -0
  190. package/services/compiler/validator.ts +154 -0
  191. package/services/connector/clients/ioredis.ts +57 -0
  192. package/services/connector/clients/redis.ts +72 -0
  193. package/services/connector/index.ts +44 -0
  194. package/services/dimension/README.md +73 -0
  195. package/services/dimension/index.ts +39 -0
  196. package/services/durable/asyncLocalStorage.ts +3 -0
  197. package/services/durable/client.ts +116 -0
  198. package/services/durable/connection.ts +50 -0
  199. package/services/durable/factory.ts +124 -0
  200. package/services/durable/handle.ts +43 -0
  201. package/services/durable/index.ts +60 -0
  202. package/services/durable/native.ts +46 -0
  203. package/services/durable/worker.ts +254 -0
  204. package/services/durable/workflow.ts +136 -0
  205. package/services/engine/index.ts +615 -0
  206. package/services/hotmesh/index.ts +182 -0
  207. package/services/logger/index.ts +79 -0
  208. package/services/mapper/index.ts +84 -0
  209. package/services/pipe/functions/array.ts +87 -0
  210. package/services/pipe/functions/bitwise.ts +27 -0
  211. package/services/pipe/functions/conditional.ts +31 -0
  212. package/services/pipe/functions/date.ts +214 -0
  213. package/services/pipe/functions/index.ts +25 -0
  214. package/services/pipe/functions/json.ts +11 -0
  215. package/services/pipe/functions/math.ts +143 -0
  216. package/services/pipe/functions/number.ts +150 -0
  217. package/services/pipe/functions/object.ts +79 -0
  218. package/services/pipe/functions/string.ts +86 -0
  219. package/services/pipe/functions/symbol.ts +39 -0
  220. package/services/pipe/functions/unary.ts +19 -0
  221. package/services/pipe/index.ts +138 -0
  222. package/services/quorum/index.ts +200 -0
  223. package/services/reporter/index.ts +379 -0
  224. package/services/serializer/README.md +10 -0
  225. package/services/serializer/index.ts +243 -0
  226. package/services/signaler/store.ts +61 -0
  227. package/services/signaler/stream.ts +354 -0
  228. package/services/store/cache.ts +172 -0
  229. package/services/store/clients/ioredis.ts +123 -0
  230. package/services/store/clients/redis.ts +169 -0
  231. package/services/store/index.ts +757 -0
  232. package/services/stream/clients/ioredis.ts +148 -0
  233. package/services/stream/clients/redis.ts +144 -0
  234. package/services/stream/index.ts +57 -0
  235. package/services/sub/clients/ioredis.ts +83 -0
  236. package/services/sub/clients/redis.ts +74 -0
  237. package/services/sub/index.ts +25 -0
  238. package/services/task/index.ts +86 -0
  239. package/services/telemetry/index.ts +267 -0
  240. package/services/worker/index.ts +165 -0
  241. package/types/activity.ts +115 -0
  242. package/types/app.ts +20 -0
  243. package/types/async.ts +7 -0
  244. package/types/cache.ts +1 -0
  245. package/types/collator.ts +9 -0
  246. package/types/durable.ts +81 -0
  247. package/types/hook.ts +32 -0
  248. package/types/hotmesh.ts +102 -0
  249. package/types/index.ts +138 -0
  250. package/types/ioredisclient.ts +10 -0
  251. package/types/job.ts +59 -0
  252. package/types/logger.ts +6 -0
  253. package/types/map.ts +5 -0
  254. package/types/ms.d.ts +7 -0
  255. package/types/pipe.ts +7 -0
  256. package/types/quorum.ts +59 -0
  257. package/types/redis.ts +27 -0
  258. package/types/redisclient.ts +29 -0
  259. package/types/serializer.ts +38 -0
  260. package/types/stats.ts +100 -0
  261. package/types/stream.ts +75 -0
  262. package/types/telemetry.ts +15 -0
  263. package/types/transition.ts +20 -0
@@ -0,0 +1,102 @@
1
+ import { ILogger } from "../services/logger";
2
+ import { HotMeshService } from "../services/hotmesh";
3
+ import { HookRules } from "./hook";
4
+ import { RedisClass, RedisClient, RedisOptions } from "./redis";
5
+ import { StreamData, StreamDataResponse } from "./stream";
6
+
7
+ type HotMesh = typeof HotMeshService;
8
+
9
+ type RedisConfig = {
10
+ class: RedisClass;
11
+ options: RedisOptions;
12
+ }
13
+
14
+ type HotMeshEngine = {
15
+ store?: RedisClient; //set by hotmesh using instanced `redis` class
16
+ stream?: RedisClient; //set by hotmesh using instanced `redis` class
17
+ sub?: RedisClient; //set by hotmesh using instanced `redis` class
18
+ redis?: RedisConfig;
19
+ reclaimDelay?: number; //milliseconds
20
+ reclaimCount?: number;
21
+ }
22
+
23
+ type HotMeshWorker = {
24
+ topic: string;
25
+ store?: RedisClient; //set by hotmesh using instanced `redis` class
26
+ stream?: RedisClient; //set by hotmesh using instanced `redis` class
27
+ sub?: RedisClient; //set by hotmesh using instanced `redis` class
28
+ redis?: {
29
+ class: RedisClass;
30
+ options: RedisOptions;
31
+ };
32
+ reclaimDelay?: number; //milliseconds
33
+ reclaimCount?: number; //max number of times to reclaim a stream
34
+ callback: (payload: StreamData) => Promise<StreamDataResponse|void>;
35
+ }
36
+
37
+ type HotMeshConfig = {
38
+ appId: string;
39
+ namespace?: string;
40
+ name?: string;
41
+ logger?: ILogger;
42
+ logLevel?: 'silly' | 'debug' | 'info' | 'warn' | 'error' | 'silent';
43
+ engine?: HotMeshEngine;
44
+ workers?: HotMeshWorker[];
45
+ }
46
+
47
+ type HotMeshGraph = {
48
+ subscribes: string;
49
+ publishes?: string;
50
+ expire?: number;
51
+ output?: {
52
+ schema: Record<string, any>;
53
+ };
54
+ input?: {
55
+ schema: Record<string, any>;
56
+ };
57
+ activities: Record<string, any>;
58
+ transitions?: Record<string, any>;
59
+ hooks?: HookRules;
60
+ };
61
+
62
+ type HotMeshSettings = {
63
+ namespace: string;
64
+ version: string;
65
+ };
66
+
67
+ type HotMeshManifest = {
68
+ app: {
69
+ id: string;
70
+ version: string;
71
+ settings: Record<string, any>;
72
+ graphs: HotMeshGraph[];
73
+ };
74
+ };
75
+
76
+ type VersionedFields = {
77
+ [K in `versions/${string}`]: any;
78
+ };
79
+
80
+ type HotMeshApp = VersionedFields & {
81
+ id: string; // customer's chosen app id
82
+ version: string; // customer's chosen version scheme (semver, etc)
83
+ settings?: string; // stringified JSON for app settings
84
+ active?: boolean; // is the app active?
85
+ };
86
+
87
+ type HotMeshApps = {
88
+ [appId: string]: HotMeshApp;
89
+ };
90
+
91
+ export {
92
+ HotMesh,
93
+ HotMeshEngine,
94
+ RedisConfig,
95
+ HotMeshWorker,
96
+ HotMeshSettings,
97
+ HotMeshApp, //a single app in the db
98
+ HotMeshApps, //object array of all apps in the db
99
+ HotMeshConfig, //customer config
100
+ HotMeshManifest,
101
+ HotMeshGraph
102
+ };
package/types/index.ts ADDED
@@ -0,0 +1,138 @@
1
+ export {
2
+ ActivityType,
3
+ ActivityDataType,
4
+ ActivityContext,
5
+ ActivityData,
6
+ ActivityDuplex,
7
+ ActivityLeg,
8
+ ActivityMetadata,
9
+ Consumes,
10
+ AwaitActivity,
11
+ BaseActivity,
12
+ EmitActivity,
13
+ WorkerActivity,
14
+ IterateActivity,
15
+ TriggerActivity,
16
+ TriggerActivityStats } from './activity';
17
+ export {
18
+ App,
19
+ AppVID,
20
+ AppTransitions,
21
+ AppSubscriptions
22
+ } from './app';
23
+ export { AsyncSignal } from './async';
24
+ export { CacheMode } from './cache';
25
+ export {
26
+ CollationFaultType,
27
+ CollationStage } from './collator';
28
+ export {
29
+ HookCondition,
30
+ HookConditions,
31
+ HookGate,
32
+ HookInterface,
33
+ HookRule,
34
+ HookRules,
35
+ HookSignal
36
+ } from './hook';
37
+ export {
38
+ RedisClientType as IORedisClientType,
39
+ RedisMultiType as IORedisMultiType } from './ioredisclient';
40
+ export { ILogger } from './logger';
41
+ export {
42
+ JobData,
43
+ JobsData,
44
+ JobMetadata,
45
+ JobOutput,
46
+ JobState,
47
+ JobStatus,
48
+ PartialJobState } from './job';
49
+ export { MappingStatements } from './map';
50
+ export {
51
+ Pipe,
52
+ PipeItem,
53
+ PipeItems } from './pipe';
54
+ export {
55
+ HotMesh,
56
+ HotMeshApp,
57
+ HotMeshApps,
58
+ HotMeshConfig,
59
+ HotMeshEngine,
60
+ RedisConfig,
61
+ HotMeshGraph,
62
+ HotMeshManifest,
63
+ HotMeshSettings,
64
+ HotMeshWorker } from './hotmesh';
65
+ export {
66
+ ActivateMessage,
67
+ JobMessage,
68
+ JobMessageCallback,
69
+ PingMessage,
70
+ PongMessage,
71
+ QuorumMessage,
72
+ SubscriptionCallback,
73
+ ThrottleMessage,
74
+ WorkMessage } from './quorum';
75
+ export {
76
+ MultiResponseFlags,
77
+ RedisClient,
78
+ RedisMulti } from './redis'; //common redis types
79
+ export {
80
+ RedisClientType,
81
+ RedisMultiType } from './redisclient';
82
+ export {
83
+ JSONSchema,
84
+ StringAnyType,
85
+ StringScalarType,
86
+ StringStringType,
87
+ SymbolMap,
88
+ SymbolMaps,
89
+ SymbolRanges,
90
+ Symbols,
91
+ SymbolSets } from './serializer';
92
+ export {
93
+ AggregatedData,
94
+ CountByFacet,
95
+ GetStatsOptions,
96
+ IdsData,
97
+ Measure,
98
+ MeasureIds,
99
+ MetricTypes,
100
+ StatType,
101
+ StatsType,
102
+ IdsResponse,
103
+ JobStats,
104
+ JobStatsInput,
105
+ JobStatsRange,
106
+ StatsResponse,
107
+ Segment,
108
+ TimeSegment } from './stats';
109
+ export {
110
+ ReclaimedMessageType,
111
+ StreamCode,
112
+ StreamConfig,
113
+ StreamData,
114
+ StreamDataType,
115
+ StreamError,
116
+ StreamDataResponse,
117
+ StreamRetryPolicy,
118
+ StreamRole,
119
+ StreamStatus } from './stream';
120
+ export {
121
+ context,
122
+ Context,
123
+ Counter,
124
+ Meter,
125
+ metrics,
126
+ propagation,
127
+ SpanContext,
128
+ Span,
129
+ SpanStatus,
130
+ SpanStatusCode,
131
+ SpanKind,
132
+ trace,
133
+ Tracer,
134
+ ValueType } from './telemetry';
135
+ export {
136
+ TransitionMatch,
137
+ TransitionRule,
138
+ Transitions } from './transition';
@@ -0,0 +1,10 @@
1
+ import { Redis, ChainableCommander, RedisOptions } from 'ioredis';
2
+
3
+ type RedisClassType = { new (options: RedisOptions): Redis };
4
+
5
+ export {
6
+ RedisClassType,
7
+ Redis as RedisClientType,
8
+ ChainableCommander as RedisMultiType,
9
+ RedisOptions as RedisClientOptions,
10
+ }
package/types/job.ts ADDED
@@ -0,0 +1,59 @@
1
+ type JobData = Record<string, unknown|Record<string, unknown>>;
2
+ type JobsData = Record<string, unknown>;
3
+
4
+ type ActivityData = {
5
+ data: Record<string, unknown>;
6
+ metadata?: Record<string, unknown>;
7
+ };
8
+
9
+ type JobMetadata = {
10
+ key?: string; //job_key
11
+ jid: string; //job_id (jid+dad+aid) is composite key for activity
12
+ dad: string; //dimensional address for the activity (,0,0,1)
13
+ aid: string; //activity_id as in the YAML file
14
+ pj?: string; //parent_job_id (pj+pd+pa) is composite key for parent activity
15
+ pd?: string; //parent_dimensional_address
16
+ pa?: string; //parent_activity_id
17
+ ngn?: string; //engine guid (one time subscriptions)
18
+ app: string; //app_id
19
+ vrs: string; //app version
20
+ tpc: string; //subscription topic
21
+ ts: string //201203120005 (slice of time) //time series
22
+ jc: string; //GMT created //job_created
23
+ ju: string; //GMT updated //job_updated
24
+ js: JobStatus;
25
+ atp: string; //activity_type
26
+ stp: string; //activity_subtype
27
+ spn: string; //open telemetry span context
28
+ trc: string; //open telemetry trace context
29
+ err?: string; //stringified job error json: {message: string, code: number, error?}
30
+ expire?: number; //process data expire policy
31
+ };
32
+
33
+ type JobStatus = number; //job_status semaphore
34
+
35
+ type JobState = {
36
+ metadata: JobMetadata;
37
+ data: JobData;
38
+ [activityId: symbol]: {
39
+ input: ActivityData;
40
+ output: ActivityData;
41
+ hook: ActivityData;
42
+ settings: ActivityData;
43
+ errors: ActivityData;
44
+ };
45
+ };
46
+
47
+ //format when publishing job meta/data on the wire when it completes
48
+ type JobOutput = {
49
+ metadata: JobMetadata;
50
+ data: JobData;
51
+ };
52
+
53
+ //jid+dad+aid is a composite guid; signal in and restore the full job context
54
+ type PartialJobState = {
55
+ metadata: JobMetadata | Pick<JobMetadata, 'jid' | 'dad' | 'aid'>;
56
+ data: JobData;
57
+ };
58
+
59
+ export { JobState, JobStatus, JobData, JobsData, JobMetadata, PartialJobState, JobOutput };
@@ -0,0 +1,6 @@
1
+ export interface ILogger {
2
+ info(message: string, ...meta: any[]): void;
3
+ error(message: string, ...meta: any[]): void;
4
+ warn(message: string, ...meta: any[]): void;
5
+ debug(message: string, ...meta: any[]): void;
6
+ }
package/types/map.ts ADDED
@@ -0,0 +1,5 @@
1
+ type MappingStatements = {
2
+ [activityId: string]: string[];
3
+ };
4
+
5
+ export { MappingStatements };
package/types/ms.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ declare module 'ms' {
2
+ function ms(value: string): number;
3
+ function ms(value: number): string;
4
+ function ms(value: string | number): string | number;
5
+
6
+ export = ms;
7
+ }
package/types/pipe.ts ADDED
@@ -0,0 +1,7 @@
1
+ type PipeItem = string | boolean | number | null;
2
+
3
+ type PipeItems = PipeItem[];
4
+
5
+ type Pipe = (PipeItem[] | Pipe)[];
6
+
7
+ export { Pipe, PipeItem, PipeItems };
@@ -0,0 +1,59 @@
1
+ import { JobOutput } from "./job";
2
+
3
+ /**
4
+ * The types in this file are used to define those messages that are sent
5
+ * to hotmesh client instances when a new version is about to be activated.
6
+ * These messages serve to coordinate the cache invalidation and switch-over
7
+ * to the new version without any downtime and a coordinating parent server.
8
+ */
9
+ export type QuorumMessage = PingMessage | PongMessage | ActivateMessage | WorkMessage | JobMessage | ThrottleMessage;
10
+
11
+ //used for coordination like version activation
12
+ export interface PingMessage {
13
+ type: 'ping';
14
+ originator: string; //guid
15
+ }
16
+
17
+ export interface WorkMessage {
18
+ type: 'work';
19
+ originator: string; //guid
20
+ }
21
+
22
+ //used for coordination like version activation
23
+ export interface PongMessage {
24
+ type: 'pong';
25
+ originator: string; //clone of originator guid passed in ping
26
+ guid: string;
27
+ }
28
+
29
+ export interface ActivateMessage {
30
+ type: 'activate';
31
+ cache_mode: 'nocache' | 'cache';
32
+ until_version: string;
33
+ }
34
+
35
+ export interface JobMessage {
36
+ type: 'job';
37
+ topic: string; //this comes from the 'publishes' field in the YAML
38
+ job: JobOutput
39
+ }
40
+
41
+ //delay in ms between fetches from the buffered stream (speed/slow down entire network)
42
+ export interface ThrottleMessage {
43
+ type: 'throttle';
44
+ guid?: string; //target the engine quorum
45
+ topic?: string; //target a worker quorum
46
+ throttle: number; //0-n
47
+ }
48
+
49
+ export interface JobMessageCallback {
50
+ (topic: string, message: JobOutput): void;
51
+ }
52
+
53
+ export interface SubscriptionCallback {
54
+ (topic: string, message: Record<string, any>): void;
55
+ }
56
+
57
+ export interface QuorumMessageCallback {
58
+ (topic: string, message: QuorumMessage): void;
59
+ }
package/types/redis.ts ADDED
@@ -0,0 +1,27 @@
1
+ import {
2
+ RedisClassType,
3
+ RedisClientType as RCT,
4
+ RedisMultiType as RMT,
5
+ RedisClientOptions as RCO
6
+ } from './redisclient';
7
+ import {
8
+ RedisClassType as IORRedisClassType,
9
+ RedisClientType as IORCT,
10
+ RedisMultiType as IORMT,
11
+ RedisClientOptions as IORCO
12
+ } from './ioredisclient';
13
+
14
+ type RedisClass = RedisClassType | IORRedisClassType;
15
+ type RedisClient = RCT | IORCT;
16
+ type RedisMulti = RMT | IORMT;
17
+ type RedisOptions = RCO | IORCO;
18
+
19
+ type MultiResponseFlags = (string | number)[]; // e.g., [3, 2, '0']
20
+
21
+ export {
22
+ RedisClass,
23
+ RedisClient,
24
+ RedisMulti,
25
+ RedisOptions,
26
+ MultiResponseFlags,
27
+ }
@@ -0,0 +1,29 @@
1
+ import { createClient, RedisClientOptions } from 'redis';
2
+
3
+ type RedisClientType = ReturnType<typeof createClient>;
4
+
5
+ interface RedisMultiType {
6
+ XADD(key: string, id: string, fields: any): this;
7
+ XACK(key: string, group: string, id: string): this;
8
+ XDEL(key: string, id: string): this;
9
+ HDEL(key: string, itemId: string): this;
10
+ HGET(key: string, itemId: string): this;
11
+ HGETALL(key: string): this;
12
+ HINCRBYFLOAT(key: string, itemId: string, value: number): this;
13
+ HMGET(key: string, itemIds: string[]): this;
14
+ HSET(key: string, values: Record<string, string>): this;
15
+ LRANGE(key: string, start: number, end: number): this;
16
+ RPUSH(key: string, value: string): this;
17
+ ZADD(key: string, values: { score: string, value: string }): this;
18
+ sendCommand(command: string[]): Promise<any>;
19
+ exec: () => Promise<unknown[]>;
20
+ }
21
+
22
+ type RedisClassType = { createClient: (options: RedisClientOptions) => any };
23
+
24
+ export {
25
+ RedisClassType,
26
+ RedisClientType,
27
+ RedisMultiType,
28
+ RedisClientOptions,
29
+ }
@@ -0,0 +1,38 @@
1
+ export interface JSONSchema {
2
+ type?: string;
3
+ enum?: string[];
4
+ examples?: any[];
5
+ properties?: { [key: string]: JSONSchema };
6
+ items?: JSONSchema;
7
+ description?: string;
8
+ 'x-train'?: boolean; //extension property to mark item `values` as not being trainable (ssn, dob, guids are examples of fields that should never have their `values` trained)
9
+ }
10
+
11
+ export type SymbolRanges = { //keyname is <ns>:<app>:symbols:
12
+ [key: string]: number; //eg: {"$": 0, "a1": 26, "a2" 39, "$metadata_cursor": 39, "$data_cursor": 2704} (job ($) holds range 0-26; every other activity has a number that increments by 13; up to 200+ unique activities may be modeled; the :cursor fields are used by the sytem to track the next reserved tranche using hincrby
13
+ }
14
+
15
+ export type Symbols = { //keyname is <ns>:<app>:symbols:<aid> (where aid can be $ for job or a1, a2, etc. for activities)
16
+ [key: string]: string; //eg: {"operation/name": "26", "a2" 39, ":cursor": 39} (job holds range 0-26; every other activity has a number that increments by 13; up to 200 activity ranges may be listed; one field called $count is used by the sytem to track the next reserved tranche using hincrby; job always seeds with 26
17
+ }
18
+
19
+ export type SymbolSets = {
20
+ [key: string]: {
21
+ [key: string]: string;
22
+ }
23
+ }
24
+
25
+ export type StringStringType = {
26
+ [key: string]: string;
27
+ };
28
+
29
+ export type StringAnyType = {
30
+ [key: string]: any;
31
+ };
32
+
33
+ export type StringScalarType = {
34
+ [key: string]: boolean | number | string;
35
+ };
36
+
37
+ export type SymbolMap = Map<string, string>;
38
+ export type SymbolMaps = Map<string, SymbolMap>;
package/types/stats.ts ADDED
@@ -0,0 +1,100 @@
1
+ type MetricTypes = 'count' | 'sum' | 'avg' | 'mdn' | 'max' | 'min' | 'index';
2
+
3
+ interface StatType {
4
+ target: string; //e.g, (a target on the input data: `<activity>.input.data`) => {`object/type:widgetA|widgetB:sum`: <sum>}, {`object/type:widgetA|widgetB:count`: <count>}
5
+ metric: MetricTypes; //count, avg, etc
6
+ value: number|string; //a value to increment (sum); value to save to sorted set (mdn) or an id to add to an `index` or just '1' for a count
7
+ }
8
+
9
+ interface Measure {
10
+ target: string;
11
+ type: string;
12
+ value: number;
13
+ }
14
+
15
+ interface Segment {
16
+ time: string;
17
+ count: number;
18
+ measures: Measure[];
19
+ }
20
+
21
+ interface StatsType {
22
+ general: StatType[];
23
+ index: StatType[];
24
+ median: StatType[];
25
+ }
26
+
27
+ interface JobStats {
28
+ count?: number;
29
+ [field: string]: number;
30
+ }
31
+
32
+ interface JobStatsRange {
33
+ [key: string]: JobStats
34
+ }
35
+
36
+ interface JobStatsInput {
37
+ data: Record<string, unknown>;
38
+ range?: string;
39
+ start?: string;
40
+ end?: string;
41
+ sparse?: boolean;
42
+ }
43
+
44
+ interface GetStatsOptions {
45
+ key: string;
46
+ granularity: string;
47
+ range?: string;
48
+ start?: string;
49
+ end?: string;
50
+ sparse?: boolean;
51
+ }
52
+
53
+ interface StatsResponse {
54
+ key: string;
55
+ granularity: string;
56
+ range: string;
57
+ end: string | Date;
58
+ count: number;
59
+ measures: Measure[];
60
+ segments?: Segment[]; //`sparse` output does not subdived by datetime segments
61
+ }
62
+
63
+ interface AggregatedData {
64
+ [key: string]: number;
65
+ }
66
+
67
+ interface IdsData {
68
+ [target: string]: string[];
69
+ }
70
+
71
+ interface MeasureIds {
72
+ time: string;
73
+ target: string;
74
+ count: number;
75
+ type: 'ids';
76
+ ids: string[];
77
+ }
78
+
79
+ interface TimeSegment {
80
+ time: string;
81
+ measures: MeasureIds[];
82
+ }
83
+
84
+
85
+ interface CountByFacet {
86
+ facet: string;
87
+ count: number;
88
+ }
89
+
90
+ interface IdsResponse {
91
+ key: string;
92
+ facets: string[];
93
+ granularity: string;
94
+ range: string;
95
+ start: string;
96
+ counts: CountByFacet[];
97
+ segments: TimeSegment[];
98
+ }
99
+
100
+ export { StatsType, StatType, MetricTypes, JobStats, JobStatsRange, JobStatsInput, GetStatsOptions, StatsResponse, AggregatedData, Measure, Segment, IdsData, MeasureIds, TimeSegment, IdsResponse, CountByFacet };
@@ -0,0 +1,75 @@
1
+ export interface StreamRetryPolicy {
2
+ [key: string]: [number, 'x']; //key is err code, val is the retry profile [(max retry count),(type (x:exponential (default)) (only 10, 100, 1000, 10000 allowed))
3
+ }
4
+
5
+ export type StreamCode = number; //3-digit status code
6
+
7
+ export type StreamError = {
8
+ message: string;
9
+ code: number;
10
+ job_id?: string; //used when communicating errors externally
11
+ stack?: string; //unhandled errors will have a stack
12
+ name?: string; //unhandled errors will have a name
13
+ error?: Record<string, unknown>; //custom user-defined error details go here
14
+ }
15
+
16
+ export enum StreamStatus {
17
+ SUCCESS = 'success',
18
+ ERROR = 'error',
19
+ PENDING = 'pending',
20
+ }
21
+
22
+ export enum StreamDataType {
23
+ TIMEHOOK = 'timehook',
24
+ WEBHOOK = 'webhook',
25
+ AWAIT = 'await',
26
+ RESULT = 'result', //await result
27
+ WORKER = 'worker',
28
+ RESPONSE = 'response', //worker response
29
+ TRANSITION = 'transition',
30
+ }
31
+
32
+ export interface StreamData {
33
+ metadata: {
34
+ topic?: string;
35
+ jid?: string; //is optonal if type is WEBHOOK
36
+ dad?: string; //dimensional address
37
+ aid: string;
38
+ trc?: string; //trace id
39
+ spn?: string; //span id
40
+ try?: number; //current try count
41
+ };
42
+ type?: StreamDataType;
43
+ data: Record<string, unknown>;
44
+ policies?: {
45
+ retry?: StreamRetryPolicy;
46
+ };
47
+ status?: StreamStatus; //assume success
48
+ code?: number; //assume 200
49
+ }
50
+
51
+ export interface StreamDataResponse extends StreamData {}
52
+
53
+ export enum StreamRole {
54
+ WORKER = 'worker',
55
+ ENGINE = 'engine',
56
+ SYSTEM = 'system', //reserved for system use (i.e, if worker or engine fails)
57
+ }
58
+
59
+ export type ReclaimedMessageType = [
60
+ messageId: string, //stream id (e.g.,`<timestamp>-<count>`)
61
+ details: [
62
+ key: string, //`key' is always 'message'
63
+ value: string //`value` is stringified StreamData (StreamDataType)
64
+ ]
65
+ ][]; //wrapped in an outer array
66
+
67
+ export type StreamConfig = {
68
+ namespace: string;
69
+ appId: string;
70
+ guid: string;
71
+ role: StreamRole;
72
+ topic?: string;
73
+ reclaimDelay?: number; //default 60_000
74
+ reclaimCount?: number; //default 3 (any value greater throws an error)
75
+ }
@@ -0,0 +1,15 @@
1
+ export {
2
+ context,
3
+ Context,
4
+ Counter,
5
+ Meter,
6
+ metrics,
7
+ propagation,
8
+ SpanContext,
9
+ Span,
10
+ SpanStatus,
11
+ SpanStatusCode,
12
+ SpanKind,
13
+ trace,
14
+ Tracer,
15
+ ValueType } from '@opentelemetry/api';