@hotmeshio/hotmesh 0.0.55 → 0.0.56

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 (181) hide show
  1. package/build/modules/enums.js +1 -10
  2. package/build/modules/key.d.ts +0 -38
  3. package/build/modules/key.js +4 -46
  4. package/build/modules/utils.d.ts +0 -8
  5. package/build/modules/utils.js +0 -14
  6. package/build/package.json +11 -4
  7. package/build/services/activities/activity.d.ts +0 -28
  8. package/build/services/activities/activity.js +1 -46
  9. package/build/services/activities/await.js +0 -4
  10. package/build/services/activities/cycle.d.ts +0 -7
  11. package/build/services/activities/cycle.js +1 -16
  12. package/build/services/activities/hook.d.ts +0 -6
  13. package/build/services/activities/hook.js +2 -12
  14. package/build/services/activities/interrupt.js +0 -8
  15. package/build/services/activities/signal.d.ts +0 -6
  16. package/build/services/activities/signal.js +0 -15
  17. package/build/services/activities/trigger.d.ts +0 -4
  18. package/build/services/activities/trigger.js +1 -7
  19. package/build/services/activities/worker.js +0 -4
  20. package/build/services/collator/index.d.ts +0 -70
  21. package/build/services/collator/index.js +1 -91
  22. package/build/services/compiler/deployer.js +6 -38
  23. package/build/services/compiler/index.d.ts +0 -15
  24. package/build/services/compiler/index.js +0 -20
  25. package/build/services/compiler/validator.d.ts +0 -3
  26. package/build/services/compiler/validator.js +0 -25
  27. package/build/services/connector/clients/ioredis.d.ts +2 -2
  28. package/build/services/connector/clients/ioredis.js +0 -2
  29. package/build/services/connector/clients/redis.d.ts +4 -4
  30. package/build/services/connector/clients/redis.js +1 -3
  31. package/build/services/connector/index.d.ts +1 -1
  32. package/build/services/connector/index.js +0 -2
  33. package/build/services/durable/client.d.ts +1 -26
  34. package/build/services/durable/client.js +0 -56
  35. package/build/services/durable/exporter.d.ts +0 -22
  36. package/build/services/durable/exporter.js +1 -30
  37. package/build/services/durable/handle.d.ts +0 -36
  38. package/build/services/durable/handle.js +0 -46
  39. package/build/services/durable/index.d.ts +0 -4
  40. package/build/services/durable/index.js +0 -4
  41. package/build/services/durable/schemas/factory.d.ts +0 -29
  42. package/build/services/durable/schemas/factory.js +0 -29
  43. package/build/services/durable/search.d.ts +1 -36
  44. package/build/services/durable/search.js +57 -56
  45. package/build/services/durable/worker.js +2 -22
  46. package/build/services/durable/workflow.d.ts +0 -114
  47. package/build/services/durable/workflow.js +1 -141
  48. package/build/services/engine/index.d.ts +1 -6
  49. package/build/services/engine/index.js +1 -43
  50. package/build/services/exporter/index.d.ts +0 -27
  51. package/build/services/exporter/index.js +0 -33
  52. package/build/services/hotmesh/index.d.ts +2 -2
  53. package/build/services/hotmesh/index.js +1 -9
  54. package/build/services/logger/index.js +0 -2
  55. package/build/services/mapper/index.d.ts +0 -14
  56. package/build/services/mapper/index.js +0 -14
  57. package/build/services/pipe/functions/date.d.ts +0 -7
  58. package/build/services/pipe/functions/date.js +0 -7
  59. package/build/services/pipe/functions/math.js +0 -2
  60. package/build/services/pipe/index.d.ts +0 -15
  61. package/build/services/pipe/index.js +2 -23
  62. package/build/services/quorum/index.d.ts +0 -7
  63. package/build/services/quorum/index.js +0 -21
  64. package/build/services/reporter/index.d.ts +0 -5
  65. package/build/services/reporter/index.js +0 -9
  66. package/build/services/router/index.d.ts +0 -9
  67. package/build/services/router/index.js +2 -38
  68. package/build/services/serializer/index.js +7 -26
  69. package/build/services/store/cache.d.ts +0 -18
  70. package/build/services/store/cache.js +0 -18
  71. package/build/services/store/clients/ioredis.d.ts +1 -1
  72. package/build/services/store/clients/ioredis.js +0 -1
  73. package/build/services/store/clients/redis.d.ts +1 -1
  74. package/build/services/store/index.d.ts +0 -55
  75. package/build/services/store/index.js +5 -81
  76. package/build/services/stream/clients/ioredis.d.ts +1 -1
  77. package/build/services/stream/clients/ioredis.js +1 -4
  78. package/build/services/stream/clients/redis.d.ts +1 -1
  79. package/build/services/sub/clients/ioredis.d.ts +1 -1
  80. package/build/services/sub/clients/redis.d.ts +1 -1
  81. package/build/services/task/index.d.ts +0 -9
  82. package/build/services/task/index.js +0 -31
  83. package/build/services/telemetry/index.d.ts +0 -7
  84. package/build/services/telemetry/index.js +1 -13
  85. package/build/services/worker/index.d.ts +0 -4
  86. package/build/services/worker/index.js +2 -6
  87. package/build/types/activity.d.ts +0 -81
  88. package/build/types/durable.d.ts +25 -177
  89. package/build/types/exporter.d.ts +0 -13
  90. package/build/types/hotmesh.d.ts +4 -16
  91. package/build/types/hotmesh.js +0 -3
  92. package/build/types/index.d.ts +4 -6
  93. package/build/types/index.js +4 -3
  94. package/build/types/job.d.ts +1 -86
  95. package/build/types/pipe.d.ts +0 -65
  96. package/build/types/quorum.d.ts +15 -10
  97. package/build/types/redis.d.ts +225 -7
  98. package/build/types/redis.js +9 -0
  99. package/build/types/stream.d.ts +0 -58
  100. package/build/types/stream.js +0 -4
  101. package/package.json +11 -4
  102. package/types/durable.ts +121 -3
  103. package/types/hotmesh.ts +3 -6
  104. package/types/index.ts +23 -10
  105. package/types/job.ts +1 -1
  106. package/types/quorum.ts +22 -0
  107. package/types/redis.ts +267 -18
  108. package/build/types/ioredisclient.d.ts +0 -5
  109. package/build/types/ioredisclient.js +0 -5
  110. package/build/types/redisclient.d.ts +0 -26
  111. package/build/types/redisclient.js +0 -2
  112. package/modules/enums.ts +0 -62
  113. package/modules/errors.ts +0 -280
  114. package/modules/key.ts +0 -101
  115. package/modules/storage.ts +0 -3
  116. package/modules/utils.ts +0 -242
  117. package/services/activities/activity.ts +0 -589
  118. package/services/activities/await.ts +0 -113
  119. package/services/activities/cycle.ts +0 -115
  120. package/services/activities/hook.ts +0 -197
  121. package/services/activities/index.ts +0 -19
  122. package/services/activities/interrupt.ts +0 -172
  123. package/services/activities/signal.ts +0 -148
  124. package/services/activities/trigger.ts +0 -295
  125. package/services/activities/worker.ts +0 -107
  126. package/services/collator/README.md +0 -102
  127. package/services/collator/index.ts +0 -291
  128. package/services/compiler/deployer.ts +0 -504
  129. package/services/compiler/index.ts +0 -98
  130. package/services/compiler/validator.ts +0 -158
  131. package/services/connector/clients/ioredis.ts +0 -57
  132. package/services/connector/clients/redis.ts +0 -72
  133. package/services/connector/index.ts +0 -42
  134. package/services/durable/client.ts +0 -266
  135. package/services/durable/connection.ts +0 -10
  136. package/services/durable/exporter.ts +0 -232
  137. package/services/durable/handle.ts +0 -160
  138. package/services/durable/index.ts +0 -27
  139. package/services/durable/schemas/factory.ts +0 -2358
  140. package/services/durable/search.ts +0 -196
  141. package/services/durable/worker.ts +0 -401
  142. package/services/durable/workflow.ts +0 -557
  143. package/services/engine/index.ts +0 -761
  144. package/services/exporter/index.ts +0 -146
  145. package/services/hotmesh/index.ts +0 -237
  146. package/services/logger/index.ts +0 -79
  147. package/services/mapper/index.ts +0 -89
  148. package/services/pipe/functions/array.ts +0 -78
  149. package/services/pipe/functions/bitwise.ts +0 -27
  150. package/services/pipe/functions/conditional.ts +0 -35
  151. package/services/pipe/functions/date.ts +0 -220
  152. package/services/pipe/functions/index.ts +0 -27
  153. package/services/pipe/functions/json.ts +0 -11
  154. package/services/pipe/functions/logical.ts +0 -11
  155. package/services/pipe/functions/math.ts +0 -217
  156. package/services/pipe/functions/number.ts +0 -75
  157. package/services/pipe/functions/object.ts +0 -98
  158. package/services/pipe/functions/string.ts +0 -86
  159. package/services/pipe/functions/symbol.ts +0 -39
  160. package/services/pipe/functions/unary.ts +0 -19
  161. package/services/pipe/index.ts +0 -216
  162. package/services/quorum/index.ts +0 -319
  163. package/services/reporter/index.ts +0 -387
  164. package/services/router/index.ts +0 -426
  165. package/services/serializer/README.md +0 -10
  166. package/services/serializer/index.ts +0 -285
  167. package/services/store/cache.ts +0 -172
  168. package/services/store/clients/ioredis.ts +0 -145
  169. package/services/store/clients/redis.ts +0 -191
  170. package/services/store/index.ts +0 -1091
  171. package/services/stream/clients/ioredis.ts +0 -157
  172. package/services/stream/clients/redis.ts +0 -158
  173. package/services/stream/index.ts +0 -58
  174. package/services/sub/clients/ioredis.ts +0 -83
  175. package/services/sub/clients/redis.ts +0 -74
  176. package/services/sub/index.ts +0 -25
  177. package/services/task/index.ts +0 -250
  178. package/services/telemetry/index.ts +0 -273
  179. package/services/worker/index.ts +0 -248
  180. package/types/ioredisclient.ts +0 -10
  181. package/types/redisclient.ts +0 -30
@@ -1,146 +0,0 @@
1
- import { VALSEP } from '../../modules/key';
2
- import { ILogger } from '../logger';
3
- import { restoreHierarchy } from '../../modules/utils';
4
- import { SerializerService } from '../serializer';
5
- import { StoreService } from '../store';
6
- import {
7
- DependencyExport,
8
- ExportOptions,
9
- JobActionExport,
10
- JobExport } from '../../types/exporter';
11
- import { RedisClient, RedisMulti } from '../../types/redis';
12
- import {
13
- StringAnyType,
14
- StringStringType,
15
- Symbols } from "../../types/serializer";
16
-
17
- /**
18
- * Downloads job data from Redis (hscan, hmget, hgetall)
19
- * Expands process data and includes dependency list
20
- */
21
- class ExporterService {
22
- appId: string;
23
- logger: ILogger;
24
- store: StoreService<RedisClient, RedisMulti>;
25
- symbols: Promise<Symbols> | Symbols;
26
-
27
- constructor(appId: string, store: StoreService<RedisClient, RedisMulti>, logger: ILogger) {
28
- this.appId = appId;
29
- this.logger = logger;
30
- this.store = store;
31
- }
32
-
33
- /**
34
- * Convert the job hash and dependency list into a JobExport object.
35
- * This object contains various facets that describe the interaction
36
- * in terms relevant to narrative storytelling.
37
- */
38
- async export(jobId: string, options: ExportOptions = {}): Promise<JobExport> {
39
- if (!this.symbols) {
40
- this.symbols = this.store.getAllSymbols();
41
- this.symbols = await this.symbols;
42
- }
43
- const depData = await this.store.getDependencies(jobId);
44
- const jobData = await this.store.getRaw(jobId);
45
- const jobExport = this.inflate(jobData, depData);
46
- return jobExport;
47
- }
48
-
49
- /**
50
- * Inflates the key from Redis, 3-character symbol
51
- * into a human-readable JSON path, reflecting the
52
- * tree-like structure of the unidimensional Hash
53
- */
54
- inflateKey(key: string): string {
55
- return (key in this.symbols) ? this.symbols[key] : key;
56
- }
57
-
58
- /**
59
- * Inflates the job data from Redis into a JobExport object
60
- * @param jobHash - the job data from Redis
61
- * @param dependencyList - the list of dependencies for the job
62
- * @returns - the inflated job data
63
- */
64
- inflate(jobHash: StringStringType, dependencyList: string[]): JobExport {
65
- //the list of actions taken in the workflow and hook functions
66
- const actions: JobActionExport = {
67
- hooks: {},
68
- main: {
69
- cursor: -1,
70
- items: []
71
- }
72
- };
73
- const process: StringAnyType = {};
74
- const dependencies = this.inflateDependencyData(dependencyList, actions);
75
- const regex = /^([a-zA-Z]{3}),(\d+(?:,\d+)*)/;
76
-
77
- Object.entries(jobHash).forEach(([key, value]) => {
78
- const match = key.match(regex);
79
- if (match) {
80
- //activity process state
81
- const [_, letters, numbers] = match;
82
- const path = this.inflateKey(letters);
83
- const dimensions = `${numbers.replace(/,/g, '/')}`;
84
- const resolved = SerializerService.fromString(value);
85
- process[`${dimensions}/${path}`] = resolved;
86
- } else if (key.length === 3) {
87
- //job state
88
- process[this.inflateKey(key)] = SerializerService.fromString(value);
89
- }
90
- });
91
-
92
- return {
93
- dependencies,
94
- process: restoreHierarchy(process),
95
- status: jobHash[':'],
96
- };
97
- }
98
-
99
- /**
100
- * Inflates the dependency data from Redis into a JobExport object by
101
- * organizing the dimensional isolate in sch a way asto interleave
102
- * into a story
103
- * @param data - the dependency data from Redis
104
- * @returns - the organized dependency data
105
- */
106
- inflateDependencyData(data: string[], actions: JobActionExport): DependencyExport[] {
107
- const hookReg = /([0-9,]+)-(\d+)$/;
108
- const flowReg = /-(\d+)$/;
109
- return data.map((dependency, index: number): DependencyExport => {
110
- const [action, topic, gid, _pd, ...jid] = dependency.split(VALSEP);
111
- const jobId = jid.join(VALSEP);
112
- const match = jobId.match(hookReg);
113
- let prefix: string;
114
- let type: 'hook' | 'flow' | 'other';
115
- let dimensionKey: string = '';
116
-
117
- if (match) {
118
- //hook-originating dependency
119
- const [_, dimension, counter] = match;
120
- dimensionKey = dimension.split(',').join('/');
121
- prefix = `${dimensionKey}[${counter}]`;
122
- type = 'hook';
123
- } else {
124
- const match = jobId.match(flowReg);
125
- if (match) {
126
- //main workflow-originating dependency
127
- const [_, counter] = match;
128
- prefix = `[${counter}]`;
129
- type = 'flow';
130
- } else {
131
- //'other' types like signal cleanup
132
- prefix = '/';
133
- type = 'other';
134
- }
135
- }
136
- return {
137
- type: action,
138
- topic,
139
- gid,
140
- jid: jobId,
141
- } as unknown as DependencyExport;
142
- });
143
- }
144
- }
145
-
146
- export { ExporterService };
@@ -1,237 +0,0 @@
1
- import { HMNS } from '../../modules/key';
2
- import { guid } from '../../modules/utils';
3
- import { RedisConnection } from '../connector/clients/redis';
4
- import { RedisConnection as IORedisConnection } from '../connector/clients/ioredis';
5
- import { EngineService } from '../engine';
6
- import { LoggerService, ILogger } from '../logger';
7
- import { QuorumService } from '../quorum';
8
- import { Router } from '../router';
9
- import { WorkerService } from '../worker';
10
- import {
11
- JobState,
12
- JobData,
13
- JobOutput,
14
- JobStatus,
15
- JobInterruptOptions,
16
- ExtensionType} from '../../types/job';
17
- import {
18
- HotMeshConfig,
19
- HotMeshManifest } from '../../types/hotmesh';
20
- import { JobMessageCallback, QuorumProfile, ThrottleMessage, ThrottleOptions } from '../../types/quorum';
21
- import {
22
- JobStatsInput,
23
- GetStatsOptions,
24
- IdsResponse,
25
- StatsResponse } from '../../types/stats';
26
- import { ConnectorService } from '../connector';
27
- import { StreamCode, StreamData, StreamDataResponse, StreamStatus } from '../../types/stream';
28
- import { StringAnyType, StringStringType } from '../../types/serializer';
29
- import { JobExport } from '../../types/exporter';
30
-
31
- class HotMeshService {
32
- namespace: string;
33
- appId: string;
34
- guid: string;
35
- engine: EngineService | null = null;
36
- quorum: QuorumService | null = null;
37
- workers: WorkerService[] = [];
38
- logger: ILogger;
39
-
40
- static disconnecting = false;
41
-
42
- verifyAndSetNamespace(namespace?: string) {
43
- if (!namespace) {
44
- this.namespace = HMNS;
45
- } else if (!namespace.match(/^[A-Za-z0-9-]+$/)) {
46
- throw new Error(`config.namespace [${namespace}] is invalid`);
47
- } else {
48
- this.namespace = namespace;
49
- }
50
- }
51
-
52
- verifyAndSetAppId(appId: string) {
53
- if (!appId?.match(/^[A-Za-z0-9-]+$/)) {
54
- throw new Error(`config.appId [${appId}] is invalid`);
55
- } else if (appId === 'a') {
56
- throw new Error(`config.appId [${appId}] is reserved`);
57
- } else {
58
- this.appId = appId;
59
- }
60
- }
61
-
62
- static async init(config: HotMeshConfig) {
63
- const instance = new HotMeshService();
64
- instance.guid = guid();
65
- instance.verifyAndSetNamespace(config.namespace);
66
- instance.verifyAndSetAppId(config.appId);
67
- instance.logger = new LoggerService(config.appId, instance.guid, config.name || '', config.logLevel);
68
- await instance.initEngine(config, instance.logger);
69
- await instance.initQuorum(config, instance.engine, instance.logger);
70
- await instance.doWork(config, instance.logger);
71
- return instance;
72
- }
73
-
74
- static guid(): string {
75
- return guid();
76
- }
77
-
78
- async initEngine(config: HotMeshConfig, logger: ILogger): Promise<void> {
79
- if (config.engine) {
80
- await ConnectorService.initRedisClients(
81
- config.engine.redis?.class,
82
- config.engine.redis?.options,
83
- config.engine,
84
- );
85
- this.engine = await EngineService.init(
86
- this.namespace,
87
- this.appId,
88
- this.guid,
89
- config,
90
- logger,
91
- );
92
- }
93
- }
94
-
95
- async initQuorum(config: HotMeshConfig, engine: EngineService, logger: ILogger): Promise<void> {
96
- if (engine) {
97
- this.quorum = await QuorumService.init(
98
- this.namespace,
99
- this.appId,
100
- this.guid,
101
- config,
102
- engine,
103
- logger
104
- );
105
- }
106
- }
107
-
108
- async doWork(config: HotMeshConfig, logger: ILogger) {
109
- this.workers = await WorkerService.init(
110
- this.namespace,
111
- this.appId,
112
- this.guid,
113
- config,
114
- logger
115
- );
116
- }
117
-
118
- // ************* PUB/SUB METHODS *************
119
- async pub(topic: string, data: JobData = {}, context?: JobState, extended?: ExtensionType): Promise<string> {
120
- return await this.engine?.pub(topic, data, context, extended);
121
- }
122
- async sub(topic: string, callback: JobMessageCallback): Promise<void> {
123
- return await this.engine?.sub(topic, callback);
124
- }
125
- async unsub(topic: string): Promise<void> {
126
- return await this.engine?.unsub(topic);
127
- }
128
- async psub(wild: string, callback: JobMessageCallback): Promise<void> {
129
- return await this.engine?.psub(wild, callback);
130
- }
131
- async punsub(wild: string): Promise<void> {
132
- return await this.engine?.punsub(wild);
133
- }
134
- async pubsub(topic: string, data: JobData = {}, context?: JobState | null, timeout?: number): Promise<JobOutput> {
135
- return await this.engine?.pubsub(topic, data, context, timeout);
136
- }
137
- async add(streamData: StreamData|StreamDataResponse): Promise<string> {
138
- return await this.engine.add(streamData) as string;
139
- }
140
-
141
-
142
- // ************* QUORUM METHODS *************
143
- async rollCall(delay?: number): Promise<QuorumProfile[]> {
144
- return await this.quorum?.rollCall(delay);
145
- }
146
- async throttle(options: ThrottleOptions): Promise<boolean> {
147
- const throttleMessage: ThrottleMessage = {
148
- type: 'throttle',
149
- throttle: options.throttle,
150
- };
151
- if (options.guid) {
152
- throttleMessage.guid = options.guid;
153
- } else if (options.topic) {
154
- throttleMessage.topic = options.topic;
155
- }
156
- return await this.quorum?.pub(throttleMessage);
157
- }
158
-
159
- // ************* COMPILER METHODS *************
160
- async plan(path: string): Promise<HotMeshManifest> {
161
- return await this.engine?.plan(path);
162
- }
163
- async deploy(pathOrYAML: string): Promise<HotMeshManifest> {
164
- return await this.engine?.deploy(pathOrYAML);
165
- }
166
- async activate(version: string, delay?: number): Promise<boolean> {
167
- //activation is a quorum operation
168
- return await this.quorum?.activate(version, delay);
169
- }
170
-
171
- // ************* REPORTER METHODS *************
172
- async export(jobId: string): Promise<JobExport> {
173
- return await this.engine?.export(jobId);
174
- }
175
- async getRaw(jobId: string): Promise<StringStringType> {
176
- return await this.engine?.getRaw(jobId);
177
- }
178
- async getStats(topic: string, query: JobStatsInput): Promise<StatsResponse> {
179
- return await this.engine?.getStats(topic, query);
180
- }
181
- async getStatus(jobId: string): Promise<JobStatus> {
182
- return this.engine?.getStatus(jobId);
183
- }
184
- async getState(topic: string, jobId: string): Promise<JobOutput> {
185
- return this.engine?.getState(topic, jobId);
186
- }
187
- async getQueryState(jobId: string, fields: string[]): Promise<StringAnyType> {
188
- return await this.engine?.getQueryState(jobId, fields);
189
- }
190
- async getIds(topic: string, query: JobStatsInput, queryFacets = []): Promise<IdsResponse> {
191
- return await this.engine?.getIds(topic, query, queryFacets);
192
- }
193
- async resolveQuery(topic: string, query: JobStatsInput): Promise<GetStatsOptions> {
194
- return await this.engine?.resolveQuery(topic, query);
195
- }
196
-
197
- // ****************** `INTERRUPT` ACTIVE JOBS *****************
198
- async interrupt(topic: string, jobId: string, options: JobInterruptOptions = {}): Promise<string> {
199
- return await this.engine?.interrupt(topic, jobId, options);
200
- }
201
-
202
- // ****************** `SCRUB` CLEAN COMPLETED JOBS *****************
203
- async scrub(jobId: string) {
204
- await this.engine?.scrub(jobId);
205
- }
206
-
207
- // ****** `HOOK` ACTIVITY RE-ENTRY POINT ******
208
- async hook(topic: string, data: JobData, status?: StreamStatus, code?: StreamCode): Promise<string> {
209
- return await this.engine?.hook(topic, data, status, code);
210
- }
211
- async hookAll(hookTopic: string, data: JobData, query: JobStatsInput, queryFacets: string[] = []): Promise<string[]> {
212
- return await this.engine?.hookAll(hookTopic, data, query, queryFacets);
213
- }
214
-
215
- static async stop() {
216
- if (!this.disconnecting) {
217
- this.disconnecting = true;
218
- await Router.stopConsuming();
219
- await RedisConnection.disconnectAll();
220
- await IORedisConnection.disconnectAll();
221
- }
222
- }
223
-
224
- stop() {
225
- this.engine?.taskService.cancelCleanup();
226
- this.quorum?.stop();
227
- this.workers?.forEach((worker: WorkerService) => {
228
- worker.stop();
229
- });
230
- }
231
-
232
- async compress(terms: string[]): Promise<boolean> {
233
- return await this.engine?.compress(terms);
234
- }
235
- }
236
-
237
- export { HotMeshService };
@@ -1,79 +0,0 @@
1
- import { Logger, createLogger, transports, format } from 'winston';
2
- import { ILogger } from '../../types/logger';
3
-
4
- class LoggerService implements ILogger {
5
- private logger: Logger;
6
-
7
- constructor(private appId: string = 'appId', private instanceId: string = 'instanceId', private name: string = 'name', private logLevel: string = 'info', customLogger?: Logger) {
8
- this.logger = customLogger || this.createDefaultLogger();
9
- }
10
-
11
- private createDefaultLogger(): Logger {
12
- return createLogger({
13
- level: this.logLevel,
14
- format: format.combine(
15
- format.colorize(),
16
- format.timestamp(),
17
- format.printf((info) => {
18
- const { timestamp, level, message } = info;
19
- // Extract the object from the `info` object's `Symbol(splat)` field
20
- const symbols = Object.getOwnPropertySymbols(info);
21
- const splatSymbol = symbols.find(symbol => symbol.toString() === 'Symbol(splat)');
22
- let splatData = {};
23
- if (splatSymbol) {
24
- splatData = info[splatSymbol][0] || {};
25
- }
26
- // Pass it to the `tagify` method
27
- const tags = this.tagify(splatData);
28
-
29
- return `${timestamp} [${level}] [${this.name || this.appId}:${this.instanceId}] ${message} ${tags}`;
30
- }),
31
- ),
32
- transports: [new transports.Console()],
33
- });
34
- }
35
-
36
- info(message: string, ...meta: any[]): void {
37
- this.logger.info(message, ...meta);
38
- }
39
-
40
- error(message: string, ...meta: any[]): void {
41
- this.logger.error(message, ...meta);
42
- }
43
-
44
- warn(message: string, ...meta: any[]): void {
45
- this.logger.warn(message, ...meta);
46
- }
47
-
48
- debug(message: string, ...meta: any[]): void {
49
- this.logger.debug(message, ...meta);
50
- }
51
-
52
- tagify(obj: Record<string, unknown>): string {
53
- if (!obj) {
54
- return '';
55
- }
56
- const tags: string[] = [];
57
- try {
58
- Object.entries(obj).forEach(([key, val]) => {
59
- let value: any = val;
60
- if (typeof val === 'function') {
61
- val = val();
62
- }
63
- if (val instanceof Date) {
64
- value = val.toISOString();
65
- } else if (typeof val === 'object' && val !== null) {
66
- value = JSON.stringify(val);
67
- } else {
68
- value = value ? value.toString() : value;
69
- }
70
- tags.push(`${key}:${value}`);
71
- });
72
- } catch (err) {
73
- this.error('tagify-error', err);
74
- }
75
- return tags.join(' ');
76
- }
77
- }
78
-
79
- export { LoggerService, ILogger };
@@ -1,89 +0,0 @@
1
- import { Pipe } from '../pipe';
2
- import { JobState } from '../../types/job';
3
- import { Pipe as PipeType } from '../../types/pipe';
4
- import { TransitionMatch, TransitionRule } from '../../types/transition';
5
- import { StreamCode } from '../../types';
6
-
7
- type RuleType = null | undefined | boolean | string | number | Date | Record<string, any>;
8
-
9
- class MapperService {
10
- private rules: Record<string, unknown>;
11
- private data: JobState;
12
-
13
- constructor(rules: Record<string, unknown>, data: JobState) {
14
- this.rules = rules;
15
- this.data = data;
16
- }
17
-
18
- public mapRules(): Record<string, unknown> {
19
- return this.traverseRules(this.rules);
20
- }
21
-
22
- private traverseRules(rules: RuleType): Record<string, unknown> {
23
- if (typeof rules === 'object' && '@pipe' in rules) {
24
- return this.pipe(rules['@pipe'] as PipeType);
25
- } if (typeof rules === 'object' && rules !== null) {
26
- const mappedRules: Record<string, any> = {};
27
- for (const key in rules) {
28
- if (Object.prototype.hasOwnProperty.call(rules, key)) {
29
- mappedRules[key] = this.traverseRules(rules[key]);
30
- }
31
- }
32
- return mappedRules;
33
- } else {
34
- return this.resolve(rules);
35
- }
36
- }
37
-
38
- /**
39
- * resolves a pipe expression of the form: { @pipe: [["{data.foo.bar}", 2, false, "hello world"]] }
40
- * @param value
41
- * @returns
42
- */
43
- private pipe(value: PipeType): any {
44
- const pipe = new Pipe(value, this.data);
45
- return pipe.process();
46
- }
47
-
48
- /**
49
- * resolves a mapping expression in the form: "{data.foo.bar}" or 2 or false or "hello world"
50
- * @param value
51
- * @returns
52
- */
53
- private resolve(value: any): any {
54
- const pipe = new Pipe([[value]], this.data);
55
- return pipe.process();
56
- }
57
-
58
- /**
59
- * Evaluates a transition rule against the current job state and incoming Stream message
60
- * to determine which (if any) transition should be taken.
61
- */
62
- static evaluate(transitionRule: TransitionRule | boolean, context: JobState, code: StreamCode): boolean {
63
- if (typeof transitionRule === 'boolean') {
64
- return transitionRule;
65
- }
66
- if ((Array.isArray(transitionRule.code) && transitionRule.code.includes(code || 200)) || code.toString() === (transitionRule.code || 200).toString()) {
67
- if (!transitionRule.match) {
68
- return true;
69
- }
70
- const orGate = transitionRule.gate === 'or';
71
- let allAreTrue = true;
72
- let someAreTrue = false;
73
- transitionRule.match.forEach(({ expected, actual }: TransitionMatch) => {
74
- if ((orGate && !someAreTrue) || (!orGate && allAreTrue)) {
75
- const result = Pipe.resolve(actual, context) === expected;
76
- if (orGate && result) {
77
- someAreTrue = true;
78
- } else if(!orGate && !result) {
79
- allAreTrue = false;
80
- }
81
- }
82
- });
83
- return orGate ? someAreTrue : allAreTrue;
84
- }
85
- return false;
86
- }
87
- }
88
-
89
- export { MapperService }
@@ -1,78 +0,0 @@
1
- class ArrayHandler {
2
- get(array: any[], index: number): any {
3
- return array?.[index || 0];
4
- }
5
-
6
- length(array: any[]): any {
7
- return array?.length;
8
- }
9
-
10
- concat(array1: any[], array2: any[]): any[] {
11
- return array1.concat(array2);
12
- }
13
-
14
- indexOf(array: any[], searchElement: any, fromIndex?: number): number {
15
- return array.indexOf(searchElement, fromIndex);
16
- }
17
-
18
- join(array: any[], separator: string): string {
19
- return array.join(separator);
20
- }
21
-
22
- lastIndexOf(array: any[], searchElement: any, fromIndex?: number): number {
23
- return array.lastIndexOf(searchElement, fromIndex);
24
- }
25
-
26
- pop(array: any[]): any {
27
- return array.pop();
28
- }
29
-
30
- push(array: any[], ...items: any[]): any[] {
31
- array.push(...items);
32
- return array;
33
- }
34
-
35
- reverse(array: any[]): any[] {
36
- return array.reverse();
37
- }
38
-
39
- shift(array: any[]): any {
40
- return array.shift();
41
- }
42
-
43
- slice(array: any[], start?: number, end?: number): any[] {
44
- return array.slice(start, end);
45
- }
46
-
47
- sort(array: any[], order: 'ASCENDING' | 'DESCENDING' = 'ASCENDING'): any[] {
48
- return array.sort((a, b) => {
49
- if (order === 'ASCENDING') {
50
- if (a === b) return 0;
51
- if (a === null || a === undefined) return -1;
52
- if (b === null || b === undefined) return 1;
53
- if (typeof a === 'string' && typeof b === 'string') {
54
- return a.localeCompare(b);
55
- }
56
- return a < b ? -1 : 1;
57
- } else {
58
- if (a === b) return 0;
59
- if (a === null || a === undefined) return 1;
60
- if (b === null || b === undefined) return -1;
61
- if (typeof a === 'string' && typeof b === 'string') {
62
- return b.localeCompare(a);
63
- }
64
- return a > b ? -1 : 1;
65
- }
66
- });
67
- }
68
-
69
- splice(array: any[], start: number, deleteCount?: number, ...items: any[]): any[] {
70
- return array.splice(start, deleteCount, ...items);
71
- }
72
-
73
- unshift(array: any[], ...items: any[]): number {
74
- return array.unshift(...items);
75
- }
76
- }
77
-
78
- export { ArrayHandler };
@@ -1,27 +0,0 @@
1
- class BitwiseHandler {
2
- and(a: number, b: number): number {
3
- return a & b;
4
- }
5
-
6
- or(a: number, b: number): number {
7
- return a | b;
8
- }
9
-
10
- xor(a: number, b: number): number {
11
- return a ^ b;
12
- }
13
-
14
- leftShift(a: number, b: number): number {
15
- return a << b;
16
- }
17
-
18
- rightShift(a: number, b: number): number {
19
- return a >> b;
20
- }
21
-
22
- unsignedRightShift(a: number, b: number): number {
23
- return a >>> b;
24
- }
25
- }
26
-
27
- export { BitwiseHandler };
@@ -1,35 +0,0 @@
1
- class ConditionalHandler {
2
- ternary(condition: boolean, valueIfTrue: any, valueIfFalse: any): any {
3
- return condition ? valueIfTrue : valueIfFalse;
4
- }
5
-
6
- equality(value1: any, value2: any): boolean {
7
- return value1 == value2;
8
- }
9
-
10
- strict_equality(value1: any, value2: any): boolean {
11
- return value1 === value2;
12
- }
13
-
14
- greater_than(value1: number, value2: number): boolean {
15
- return value1 > value2;
16
- }
17
-
18
- less_than(value1: number, value2: number): boolean {
19
- return value1 < value2;
20
- }
21
-
22
- greater_than_or_equal(value1: number, value2: number): boolean {
23
- return value1 >= value2;
24
- }
25
-
26
- less_than_or_equal(value1: number, value2: number): boolean {
27
- return value1 <= value2;
28
- }
29
-
30
- nullish(value1: any, value2: any): any {
31
- return value1 ?? value2;
32
- }
33
- }
34
-
35
- export { ConditionalHandler };