@hotmeshio/hotmesh 0.0.54 → 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.
- package/README.md +0 -3
- package/build/modules/enums.js +1 -10
- package/build/modules/key.d.ts +0 -38
- package/build/modules/key.js +4 -46
- package/build/modules/utils.d.ts +0 -8
- package/build/modules/utils.js +0 -14
- package/build/package.json +11 -4
- package/build/services/activities/activity.d.ts +0 -28
- package/build/services/activities/activity.js +1 -46
- package/build/services/activities/await.js +0 -4
- package/build/services/activities/cycle.d.ts +0 -7
- package/build/services/activities/cycle.js +1 -16
- package/build/services/activities/hook.d.ts +0 -6
- package/build/services/activities/hook.js +2 -12
- package/build/services/activities/interrupt.js +0 -8
- package/build/services/activities/signal.d.ts +0 -6
- package/build/services/activities/signal.js +0 -15
- package/build/services/activities/trigger.d.ts +0 -4
- package/build/services/activities/trigger.js +1 -7
- package/build/services/activities/worker.js +0 -4
- package/build/services/collator/index.d.ts +0 -70
- package/build/services/collator/index.js +1 -91
- package/build/services/compiler/deployer.js +6 -38
- package/build/services/compiler/index.d.ts +0 -15
- package/build/services/compiler/index.js +0 -20
- package/build/services/compiler/validator.d.ts +0 -3
- package/build/services/compiler/validator.js +0 -25
- package/build/services/connector/clients/ioredis.d.ts +2 -2
- package/build/services/connector/clients/ioredis.js +0 -2
- package/build/services/connector/clients/redis.d.ts +4 -4
- package/build/services/connector/clients/redis.js +1 -3
- package/build/services/connector/index.d.ts +1 -1
- package/build/services/connector/index.js +0 -2
- package/build/services/durable/client.d.ts +1 -26
- package/build/services/durable/client.js +0 -56
- package/build/services/durable/exporter.d.ts +0 -22
- package/build/services/durable/exporter.js +1 -30
- package/build/services/durable/handle.d.ts +0 -36
- package/build/services/durable/handle.js +0 -46
- package/build/services/durable/index.d.ts +0 -4
- package/build/services/durable/index.js +0 -4
- package/build/services/durable/schemas/factory.d.ts +0 -29
- package/build/services/durable/schemas/factory.js +0 -29
- package/build/services/durable/search.d.ts +1 -36
- package/build/services/durable/search.js +57 -56
- package/build/services/durable/worker.js +2 -22
- package/build/services/durable/workflow.d.ts +0 -114
- package/build/services/durable/workflow.js +4 -144
- package/build/services/engine/index.d.ts +1 -6
- package/build/services/engine/index.js +1 -43
- package/build/services/exporter/index.d.ts +0 -27
- package/build/services/exporter/index.js +0 -33
- package/build/services/hotmesh/index.d.ts +2 -2
- package/build/services/hotmesh/index.js +1 -9
- package/build/services/logger/index.js +0 -2
- package/build/services/mapper/index.d.ts +0 -14
- package/build/services/mapper/index.js +0 -14
- package/build/services/pipe/functions/date.d.ts +0 -7
- package/build/services/pipe/functions/date.js +0 -7
- package/build/services/pipe/functions/math.js +0 -2
- package/build/services/pipe/index.d.ts +0 -15
- package/build/services/pipe/index.js +2 -23
- package/build/services/quorum/index.d.ts +0 -7
- package/build/services/quorum/index.js +0 -21
- package/build/services/reporter/index.d.ts +0 -5
- package/build/services/reporter/index.js +0 -9
- package/build/services/router/index.d.ts +0 -9
- package/build/services/router/index.js +2 -38
- package/build/services/serializer/index.js +7 -26
- package/build/services/store/cache.d.ts +0 -18
- package/build/services/store/cache.js +0 -18
- package/build/services/store/clients/ioredis.d.ts +1 -1
- package/build/services/store/clients/ioredis.js +0 -1
- package/build/services/store/clients/redis.d.ts +1 -1
- package/build/services/store/index.d.ts +0 -55
- package/build/services/store/index.js +5 -81
- package/build/services/stream/clients/ioredis.d.ts +1 -1
- package/build/services/stream/clients/ioredis.js +1 -4
- package/build/services/stream/clients/redis.d.ts +1 -1
- package/build/services/sub/clients/ioredis.d.ts +1 -1
- package/build/services/sub/clients/redis.d.ts +1 -1
- package/build/services/task/index.d.ts +0 -9
- package/build/services/task/index.js +0 -31
- package/build/services/telemetry/index.d.ts +0 -7
- package/build/services/telemetry/index.js +1 -13
- package/build/services/worker/index.d.ts +0 -4
- package/build/services/worker/index.js +2 -6
- package/build/types/activity.d.ts +0 -81
- package/build/types/durable.d.ts +25 -177
- package/build/types/exporter.d.ts +0 -13
- package/build/types/hotmesh.d.ts +4 -16
- package/build/types/hotmesh.js +0 -3
- package/build/types/index.d.ts +4 -6
- package/build/types/index.js +4 -3
- package/build/types/job.d.ts +1 -86
- package/build/types/pipe.d.ts +0 -65
- package/build/types/quorum.d.ts +15 -10
- package/build/types/redis.d.ts +225 -7
- package/build/types/redis.js +9 -0
- package/build/types/stream.d.ts +0 -58
- package/build/types/stream.js +0 -4
- package/package.json +11 -4
- package/types/durable.ts +121 -3
- package/types/hotmesh.ts +3 -6
- package/types/index.ts +23 -10
- package/types/job.ts +1 -1
- package/types/quorum.ts +22 -0
- package/types/redis.ts +267 -18
- package/build/types/ioredisclient.d.ts +0 -5
- package/build/types/ioredisclient.js +0 -5
- package/build/types/redisclient.d.ts +0 -26
- package/build/types/redisclient.js +0 -2
- package/modules/enums.ts +0 -62
- package/modules/errors.ts +0 -280
- package/modules/key.ts +0 -101
- package/modules/storage.ts +0 -3
- package/modules/utils.ts +0 -242
- package/services/activities/activity.ts +0 -589
- package/services/activities/await.ts +0 -113
- package/services/activities/cycle.ts +0 -115
- package/services/activities/hook.ts +0 -197
- package/services/activities/index.ts +0 -19
- package/services/activities/interrupt.ts +0 -172
- package/services/activities/signal.ts +0 -148
- package/services/activities/trigger.ts +0 -295
- package/services/activities/worker.ts +0 -107
- package/services/collator/README.md +0 -102
- package/services/collator/index.ts +0 -291
- package/services/compiler/deployer.ts +0 -504
- package/services/compiler/index.ts +0 -98
- package/services/compiler/validator.ts +0 -158
- package/services/connector/clients/ioredis.ts +0 -57
- package/services/connector/clients/redis.ts +0 -72
- package/services/connector/index.ts +0 -42
- package/services/durable/client.ts +0 -266
- package/services/durable/connection.ts +0 -10
- package/services/durable/exporter.ts +0 -232
- package/services/durable/handle.ts +0 -160
- package/services/durable/index.ts +0 -27
- package/services/durable/schemas/factory.ts +0 -2358
- package/services/durable/search.ts +0 -196
- package/services/durable/worker.ts +0 -401
- package/services/durable/workflow.ts +0 -557
- package/services/engine/index.ts +0 -761
- package/services/exporter/index.ts +0 -146
- package/services/hotmesh/index.ts +0 -237
- package/services/logger/index.ts +0 -79
- package/services/mapper/index.ts +0 -89
- package/services/pipe/functions/array.ts +0 -78
- package/services/pipe/functions/bitwise.ts +0 -27
- package/services/pipe/functions/conditional.ts +0 -35
- package/services/pipe/functions/date.ts +0 -220
- package/services/pipe/functions/index.ts +0 -27
- package/services/pipe/functions/json.ts +0 -11
- package/services/pipe/functions/logical.ts +0 -11
- package/services/pipe/functions/math.ts +0 -217
- package/services/pipe/functions/number.ts +0 -75
- package/services/pipe/functions/object.ts +0 -98
- package/services/pipe/functions/string.ts +0 -86
- package/services/pipe/functions/symbol.ts +0 -39
- package/services/pipe/functions/unary.ts +0 -19
- package/services/pipe/index.ts +0 -216
- package/services/quorum/index.ts +0 -319
- package/services/reporter/index.ts +0 -387
- package/services/router/index.ts +0 -426
- package/services/serializer/README.md +0 -10
- package/services/serializer/index.ts +0 -285
- package/services/store/cache.ts +0 -172
- package/services/store/clients/ioredis.ts +0 -145
- package/services/store/clients/redis.ts +0 -191
- package/services/store/index.ts +0 -1091
- package/services/stream/clients/ioredis.ts +0 -157
- package/services/stream/clients/redis.ts +0 -158
- package/services/stream/index.ts +0 -58
- package/services/sub/clients/ioredis.ts +0 -83
- package/services/sub/clients/redis.ts +0 -74
- package/services/sub/index.ts +0 -25
- package/services/task/index.ts +0 -250
- package/services/telemetry/index.ts +0 -273
- package/services/worker/index.ts +0 -248
- package/types/ioredisclient.ts +0 -10
- package/types/redisclient.ts +0 -30
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
import { getSymVal } from '../../modules/utils';
|
|
2
|
-
import { Consumes } from '../../types/activity';
|
|
3
|
-
import {
|
|
4
|
-
StringStringType,
|
|
5
|
-
StringAnyType,
|
|
6
|
-
SymbolMap,
|
|
7
|
-
SymbolMaps,
|
|
8
|
-
SymbolSets,
|
|
9
|
-
Symbols } from '../../types/serializer';
|
|
10
|
-
|
|
11
|
-
const dateReg = /^"\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z)?"$/;
|
|
12
|
-
|
|
13
|
-
export const MDATA_SYMBOLS = {
|
|
14
|
-
SLOTS: 26,
|
|
15
|
-
ACTIVITY: {
|
|
16
|
-
KEYS: ['aid', 'dad', 'as', 'atp', 'stp', 'ac', 'au', 'err','l1s','l2s']
|
|
17
|
-
},
|
|
18
|
-
ACTIVITY_UPDATE: {
|
|
19
|
-
KEYS: ['au', 'err', 'l2s']
|
|
20
|
-
},
|
|
21
|
-
JOB: {
|
|
22
|
-
KEYS: ['ngn', 'tpc', 'pj', 'pg', 'pd', 'px', 'pa', 'key', 'app', 'vrs', 'jid', 'gid', 'aid', 'ts', 'jc', 'ju', 'js', 'err', 'trc']
|
|
23
|
-
},
|
|
24
|
-
JOB_UPDATE: {
|
|
25
|
-
KEYS: ['ju', 'err']
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export class SerializerService {
|
|
30
|
-
dIds: StringStringType;
|
|
31
|
-
symKeys: SymbolMaps;
|
|
32
|
-
symReverseKeys: SymbolMaps;
|
|
33
|
-
symValMaps: SymbolMap;
|
|
34
|
-
symValReverseMaps: SymbolMap;
|
|
35
|
-
|
|
36
|
-
constructor() {
|
|
37
|
-
this.resetSymbols({}, {}, {});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
abbreviate(consumes: Consumes, symbolNames: string[], fields: string[] = []): string[] {
|
|
41
|
-
for (const symbolName of symbolNames) {
|
|
42
|
-
const symbolSet = this.symKeys.get(symbolName);
|
|
43
|
-
const symbolPaths = consumes[symbolName];
|
|
44
|
-
for (const symbolPath of symbolPaths) {
|
|
45
|
-
const abbreviation = symbolSet.get(symbolPath);
|
|
46
|
-
if (abbreviation) {
|
|
47
|
-
const dimensionalIndex = this.resolveDimensionalIndex(symbolPath);
|
|
48
|
-
fields.push(`${abbreviation}${dimensionalIndex}`);
|
|
49
|
-
} else {
|
|
50
|
-
fields.push(symbolPath);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return fields;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
resolveDimensionalIndex(path: string): string {
|
|
58
|
-
if (this.isJobPath(path)) {
|
|
59
|
-
return '';
|
|
60
|
-
} else {
|
|
61
|
-
const [activityId] = path.split('/');
|
|
62
|
-
if (activityId in this.dIds) {
|
|
63
|
-
return this.dIds[activityId];
|
|
64
|
-
} else if ('$ADJACENT' in this.dIds) {
|
|
65
|
-
//else=> pre-authorizing adjacent activity entry
|
|
66
|
-
return this.dIds['$ADJACENT'];
|
|
67
|
-
}
|
|
68
|
-
return ',0';
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
isJobPath(path: string): boolean {
|
|
73
|
-
return path.startsWith('data/') || path.startsWith('metadata/');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
resetSymbols(symKeys: SymbolSets, symVals: Symbols, dIds: StringStringType): void {
|
|
77
|
-
this.symKeys = new Map();
|
|
78
|
-
this.symReverseKeys = new Map();
|
|
79
|
-
for (const id in symKeys) {
|
|
80
|
-
this.symKeys.set(id, new Map(Object.entries(symKeys[id])));
|
|
81
|
-
}
|
|
82
|
-
this.symValMaps = new Map(Object.entries(symVals));
|
|
83
|
-
this.symValReverseMaps = this.getReverseValueMap(this.symValMaps);
|
|
84
|
-
this.dIds = dIds;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
getReverseKeyMap(keyMap: SymbolMap, id?: string): SymbolMap {
|
|
88
|
-
let map = this.symReverseKeys.get(id);
|
|
89
|
-
if (!map) {
|
|
90
|
-
map = new Map();
|
|
91
|
-
for (let [key, val] of keyMap.entries()) {
|
|
92
|
-
map.set(val, key);
|
|
93
|
-
}
|
|
94
|
-
this.symReverseKeys.set(id, map);
|
|
95
|
-
}
|
|
96
|
-
return map;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
getReverseValueMap(valueMap: SymbolMap): SymbolMap {
|
|
100
|
-
const map = new Map();
|
|
101
|
-
for (let [key, val] of valueMap.entries()) {
|
|
102
|
-
map.set(val, key);
|
|
103
|
-
}
|
|
104
|
-
return map;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
static filterSymVals(startIndex: number, maxIndex: number, existingSymbolValues: Symbols, proposedValues: Set<string>): Symbols {
|
|
108
|
-
let newSymbolValues: Symbols = {};
|
|
109
|
-
let currentSymbolValues: Symbols = { ...existingSymbolValues };
|
|
110
|
-
let currentValuesSet: Set<string> = new Set(Object.values(currentSymbolValues));
|
|
111
|
-
for (let value of proposedValues) {
|
|
112
|
-
if (!currentValuesSet.has(value)) {
|
|
113
|
-
if (startIndex > maxIndex) {
|
|
114
|
-
return newSymbolValues;
|
|
115
|
-
}
|
|
116
|
-
const symbol = getSymVal(startIndex);
|
|
117
|
-
startIndex++;
|
|
118
|
-
newSymbolValues[symbol] = value;
|
|
119
|
-
currentValuesSet.add(value);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return newSymbolValues;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
compress(document: StringStringType, ids: string[]): StringStringType {
|
|
126
|
-
if (this.symKeys.size === 0) {
|
|
127
|
-
return document;
|
|
128
|
-
}
|
|
129
|
-
let source: StringStringType = { ...document };
|
|
130
|
-
let result: StringStringType = { };
|
|
131
|
-
|
|
132
|
-
const compressWithMap = (abbreviationMap: SymbolMap, id: string) => {
|
|
133
|
-
for (let key in source) {
|
|
134
|
-
if (key.startsWith(`${id}/`) || (id.startsWith('$') && ['data', 'metadata'].includes(key.split('/')[0]))) {
|
|
135
|
-
const dimensionalIndex = this.resolveDimensionalIndex(key);
|
|
136
|
-
let shortKey = abbreviationMap.get(key) || key;
|
|
137
|
-
const shortDimensionalKey = `${shortKey}${dimensionalIndex}`;
|
|
138
|
-
result[shortDimensionalKey] = source[key];
|
|
139
|
-
} else if (!(key in result) && this.isLiteralKeyType(key)) {
|
|
140
|
-
//mark (-) and search (_)
|
|
141
|
-
result[key] = source[key];
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
for (let id of ids) {
|
|
146
|
-
const abbreviationMap = this.symKeys.get(id);
|
|
147
|
-
if (abbreviationMap) {
|
|
148
|
-
compressWithMap(abbreviationMap, id);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return result;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
isLiteralKeyType(key: string): boolean {
|
|
155
|
-
return key.startsWith('-') || key.startsWith('_');
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
decompress(document: StringStringType, ids: string[]): StringStringType {
|
|
159
|
-
if (this.symKeys.size === 0) {
|
|
160
|
-
return document;
|
|
161
|
-
}
|
|
162
|
-
let result: StringStringType = { ...document };
|
|
163
|
-
|
|
164
|
-
const inflateWithMap = (abbreviationMap: SymbolMap, id: string) => {
|
|
165
|
-
const reversedAbbreviationMap = this.getReverseKeyMap(abbreviationMap, id);
|
|
166
|
-
for (let key in result) {
|
|
167
|
-
//strip dimensional index from key
|
|
168
|
-
const shortKey = key.split(',')[0];
|
|
169
|
-
let longKey = reversedAbbreviationMap.get(shortKey);
|
|
170
|
-
if (longKey) {
|
|
171
|
-
result[longKey] = result[key];
|
|
172
|
-
delete result[key];
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
for (let id of ids) {
|
|
177
|
-
const abbreviationMap = this.symKeys.get(id);
|
|
178
|
-
if (abbreviationMap) {
|
|
179
|
-
inflateWithMap(abbreviationMap, id);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
return result;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
//stringify: convert a multi-dimensional document to a 2-d hash
|
|
186
|
-
stringify(document: Record<string, any>): StringStringType {
|
|
187
|
-
let result: StringStringType = {};
|
|
188
|
-
for (let key in document) {
|
|
189
|
-
let value = SerializerService.toString(document[key]);
|
|
190
|
-
if (value) {
|
|
191
|
-
if (/^:*[a-zA-Z]{2}$/.test(value)) {
|
|
192
|
-
value = ':' + value;
|
|
193
|
-
} else if (this.symValReverseMaps.has(value)) {
|
|
194
|
-
value = this.symValReverseMaps.get(value);
|
|
195
|
-
}
|
|
196
|
-
result[key] = value;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return result;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
//parse: convert a 2-d hash to a multi-dimensional document
|
|
203
|
-
parse(document: StringStringType): any {
|
|
204
|
-
let result: any = {};
|
|
205
|
-
for (let [key, value] of Object.entries(document)) {
|
|
206
|
-
if (value === undefined || value === null) continue;
|
|
207
|
-
if (/^:+[a-zA-Z]{2}$/.test(value)) {
|
|
208
|
-
result[key] = value.slice(1);
|
|
209
|
-
} else {
|
|
210
|
-
if (value?.length === 2 && this.symValMaps.has(value)) {
|
|
211
|
-
value = this.symValMaps.get(value);
|
|
212
|
-
}
|
|
213
|
-
result[key] = SerializerService.fromString(value);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
return result;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
static toString(value: any): string|undefined {
|
|
220
|
-
switch (typeof value) {
|
|
221
|
-
case 'string':
|
|
222
|
-
break;
|
|
223
|
-
case 'boolean':
|
|
224
|
-
value = value ? '/t' : '/f';
|
|
225
|
-
break;
|
|
226
|
-
case 'number':
|
|
227
|
-
value = '/d' + value.toString();
|
|
228
|
-
break;
|
|
229
|
-
case 'undefined':
|
|
230
|
-
return undefined;
|
|
231
|
-
case 'object':
|
|
232
|
-
if (value === null) {
|
|
233
|
-
value = '/n';
|
|
234
|
-
} else {
|
|
235
|
-
value = '/s' + JSON.stringify(value);
|
|
236
|
-
}
|
|
237
|
-
break;
|
|
238
|
-
}
|
|
239
|
-
return value;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
static fromString(value: string|undefined): any {
|
|
243
|
-
if (typeof value !== 'string') return undefined;
|
|
244
|
-
const prefix = value.slice(0, 2);
|
|
245
|
-
const rest = value.slice(2);
|
|
246
|
-
switch (prefix) {
|
|
247
|
-
case '/t': // boolean true
|
|
248
|
-
return true;
|
|
249
|
-
case '/f': // boolean false
|
|
250
|
-
return false;
|
|
251
|
-
case '/d': // number
|
|
252
|
-
return Number(rest);
|
|
253
|
-
case '/n': // null
|
|
254
|
-
return null;
|
|
255
|
-
case '/s': // object (JSON string)
|
|
256
|
-
if (dateReg.exec(rest)) {
|
|
257
|
-
return new Date(JSON.parse(rest));
|
|
258
|
-
}
|
|
259
|
-
return JSON.parse(rest);
|
|
260
|
-
default: // string
|
|
261
|
-
return value;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
public package(multiDimensionalDocument: StringAnyType, ids: string[]): StringStringType {
|
|
266
|
-
const flatDocument = this.stringify(multiDimensionalDocument);
|
|
267
|
-
return this.compress(flatDocument, ids);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
public unpackage(document: StringStringType, ids: string[]): StringAnyType {
|
|
271
|
-
const multiDimensionalDocument = this.decompress(document, ids);
|
|
272
|
-
return this.parse(multiDimensionalDocument);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
public export(): SymbolSets {
|
|
276
|
-
const obj: {[key: string]: StringStringType} = {};
|
|
277
|
-
for (const [id, map] of this.symKeys.entries()) {
|
|
278
|
-
obj[id] = {};
|
|
279
|
-
for (const [key, value] of map.entries()) {
|
|
280
|
-
obj[id][key] = value;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
return obj;
|
|
284
|
-
}
|
|
285
|
-
}
|
package/services/store/cache.ts
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The Cache is a key/value store and used to store commonly accessed Redis metadata
|
|
3
|
-
* (mainly the execution rules for the app) to save time accessing them as they
|
|
4
|
-
* are immutable per verison. The only time the rules are ejected are when
|
|
5
|
-
* a new version is deployed to the quorum and the cache is invalidated/cleared.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { ActivityType } from "../../types/activity";
|
|
9
|
-
import { HookRule } from "../../types/hook";
|
|
10
|
-
import { HotMeshApp, HotMeshSettings } from "../../types/hotmesh";
|
|
11
|
-
import { Symbols } from "../../types/serializer";
|
|
12
|
-
import { Transitions } from "../../types/transition";
|
|
13
|
-
|
|
14
|
-
class Cache {
|
|
15
|
-
settings: HotMeshSettings;
|
|
16
|
-
appId: string;
|
|
17
|
-
apps: Record<string, HotMeshApp>;
|
|
18
|
-
schemas: Record<string, ActivityType>;
|
|
19
|
-
subscriptions: Record<string, Record<string, string>>;
|
|
20
|
-
symbols: Record<string, Symbols>;
|
|
21
|
-
symvals: Record<string, Symbols>;
|
|
22
|
-
transitions: Record<string, Record<string, unknown>>;
|
|
23
|
-
hookRules: Record<string, Record<string, HookRule[]>>;
|
|
24
|
-
workItems: Record<string, string>;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* The cache is ALWAYS initialized with HotMeshSettings. The other parameters are optional.
|
|
28
|
-
* @param settings
|
|
29
|
-
* @param apps
|
|
30
|
-
* @param schemas
|
|
31
|
-
* @param subscriptions
|
|
32
|
-
* @param transitions
|
|
33
|
-
* @param hookRules
|
|
34
|
-
*/
|
|
35
|
-
constructor(appId: string, settings: HotMeshSettings, apps: Record<string, HotMeshApp> = {}, schemas: Record<string, ActivityType> = {}, subscriptions: Record<string, Record<string, string>> = {}, symbols: Record<string, Symbols> = {}, symvals: Record<string, Symbols> = {}, transitions: Record<string, Record<string, unknown>> = {}, hookRules: Record<string, Record<string, HookRule[]>> = {}, workItems: Record<string, string> = {}) {
|
|
36
|
-
this.appId = appId;
|
|
37
|
-
this.settings = settings;
|
|
38
|
-
this.apps = apps;
|
|
39
|
-
this.schemas = schemas;
|
|
40
|
-
this.subscriptions = subscriptions;
|
|
41
|
-
this.symbols = symbols;
|
|
42
|
-
this.symvals = symvals;
|
|
43
|
-
this.transitions = transitions;
|
|
44
|
-
this.hookRules = hookRules;
|
|
45
|
-
this.workItems = workItems;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* invalidate the cache; settings are not invalidated!
|
|
50
|
-
*/
|
|
51
|
-
invalidate(): void {
|
|
52
|
-
this.apps = {} as Record<string, HotMeshApp>;
|
|
53
|
-
this.schemas = {};
|
|
54
|
-
this.subscriptions = {};
|
|
55
|
-
this.transitions = {};
|
|
56
|
-
this.hookRules = {};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
getSettings(): HotMeshSettings {
|
|
60
|
-
return this.settings;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
setSettings(settings: HotMeshSettings): void {
|
|
64
|
-
this.settings = settings;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
getApps(): Record<string, HotMeshApp> {
|
|
68
|
-
return this.apps;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
getApp(appId: string): HotMeshApp {
|
|
72
|
-
return this.apps[appId] as HotMeshApp;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
setApps(apps: Record<string, HotMeshApp>): void {
|
|
76
|
-
this.apps = apps;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
setApp(appId: string, app: HotMeshApp): void {
|
|
80
|
-
this.apps[appId] = app;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
getSchemas(appId: string, version: string): Record<string, ActivityType> {
|
|
84
|
-
return this.schemas[`${appId}/${version}`] as unknown as Record<string, ActivityType>;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
getSchema(appId: string, version: string, activityId: string): ActivityType {
|
|
88
|
-
return this.schemas?.[`${appId}/${version}`]?.[activityId] as ActivityType;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
setSchemas(appId: string, version: string, schemas: Record<string, ActivityType>): void {
|
|
92
|
-
this.schemas[`${appId}/${version}`] = schemas as unknown as Record<string, ActivityType>;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
setSchema(appId: string, version: string, activityId: string, schema: ActivityType): void {
|
|
96
|
-
this.schemas[`${appId}/${version}`][activityId] = schema;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
getSubscriptions(appId: string, version: string): Record<string, string> {
|
|
100
|
-
return this.subscriptions[`${appId}/${version}`];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
getSubscription(appId: string, version: string, topic: string): unknown {
|
|
104
|
-
return this.subscriptions?.[`${appId}/${version}`]?.[topic];
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
setSubscriptions(appId: string, version: string, subscriptions: Record<string, string>): void {
|
|
108
|
-
this.subscriptions[`${appId}/${version}`] = subscriptions;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
getSymbols(appId: string, targetEntityId: string): Symbols {
|
|
112
|
-
return this.symbols[`${appId}/${targetEntityId}`] as Symbols;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
setSymbols(appId: string, targetEntityId: string, symbols: Symbols): void {
|
|
116
|
-
this.symbols[`${appId}/${targetEntityId}`] = symbols;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
deleteSymbols(appId: string, targetEntityId: string): void {
|
|
120
|
-
delete this.symbols[`${appId}/${targetEntityId}`];
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
getSymbolValues(appId: string): Symbols {
|
|
124
|
-
return this.symvals[`${appId}`] as Symbols;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
setSymbolValues(appId: string, symvals: Symbols): void {
|
|
128
|
-
this.symvals[`${appId}`] = symvals;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
deleteSymbolValues(appId: string): void {
|
|
132
|
-
delete this.symvals[`${appId}`];
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
getTransitions(appId: string, version: string): Transitions {
|
|
136
|
-
return this.transitions[`${appId}/${version}`] as Transitions;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
setTransitions(appId: string, version: string, transitions: Transitions): void {
|
|
140
|
-
this.transitions[`${appId}/${version}`] = transitions;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
getHookRules(appId: string): Record<string, HookRule[]> {
|
|
144
|
-
return this.hookRules[`${appId}`];
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
setHookRules(appId: string, hookRules: Record<string, HookRule[]>): void {
|
|
148
|
-
this.hookRules[`${appId}`] = hookRules;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
getSignals(appId: string, version: string): Record<string, unknown> {
|
|
152
|
-
throw new Error("SIGNAL (getHooks) is not supported");
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
setSignals(appId: string, version: string): Record<string, unknown> {
|
|
156
|
-
throw new Error("SIGNAL (setHook) is not supported");
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
getActiveTaskQueue(appId: string): string {
|
|
160
|
-
return this.workItems[appId];
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
setWorkItem(appId: string, workItem: string): void {
|
|
164
|
-
this.workItems[appId] = workItem;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
removeWorkItem(appId: string): void {
|
|
168
|
-
delete this.workItems[appId];
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export { Cache };
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { KeyType } from '../../../modules/key';
|
|
2
|
-
import { ILogger } from '../../logger';
|
|
3
|
-
import { SerializerService as Serializer } from '../../serializer';
|
|
4
|
-
import { Cache } from '../cache';
|
|
5
|
-
import { StoreService } from '../index';
|
|
6
|
-
import { RedisClientType, RedisMultiType } from '../../../types/ioredisclient';
|
|
7
|
-
import { ReclaimedMessageType } from '../../../types/stream';
|
|
8
|
-
|
|
9
|
-
class IORedisStoreService extends StoreService<RedisClientType, RedisMultiType> {
|
|
10
|
-
redisClient: RedisClientType;
|
|
11
|
-
cache: Cache;
|
|
12
|
-
namespace: string;
|
|
13
|
-
appId: string;
|
|
14
|
-
logger: ILogger;
|
|
15
|
-
serializer: Serializer;
|
|
16
|
-
|
|
17
|
-
constructor(redisClient: RedisClientType) {
|
|
18
|
-
super(redisClient);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
getMulti(): RedisMultiType {
|
|
22
|
-
return this.redisClient.multi();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async exec(...args: any[]): Promise<string|string[]|string[][]> {
|
|
26
|
-
const response = await this.redisClient.call.apply(this.redisClient, args as any);
|
|
27
|
-
if (typeof response === 'string') {
|
|
28
|
-
return response as string;
|
|
29
|
-
} else if (Array.isArray(response)) {
|
|
30
|
-
if (Array.isArray(response[0])) {
|
|
31
|
-
return response as string[][];
|
|
32
|
-
}
|
|
33
|
-
return response as string[];
|
|
34
|
-
}
|
|
35
|
-
return response;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
hGetAllResult(result: any) {
|
|
39
|
-
//ioredis response signature is [null, {}] or [null, null]
|
|
40
|
-
return result[1];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async addTaskQueues(keys: string[]): Promise<void> {
|
|
44
|
-
const multi = this.redisClient.multi();
|
|
45
|
-
const zsetKey = this.mintKey(KeyType.WORK_ITEMS, { appId: this.appId });
|
|
46
|
-
for (const key of keys) {
|
|
47
|
-
multi.zadd(zsetKey, 'NX', Date.now(), key);
|
|
48
|
-
}
|
|
49
|
-
await multi.exec();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async publish(keyType: KeyType.QUORUM, message: Record<string, any>, appId: string, engineId?: string): Promise<boolean> {
|
|
53
|
-
const topic = this.mintKey(keyType, { appId, engineId });
|
|
54
|
-
const status: number = await this.redisClient.publish(topic, JSON.stringify(message));
|
|
55
|
-
return status === 1;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async xgroup(command: 'CREATE', key: string, groupName: string, id: string, mkStream?: 'MKSTREAM'): Promise<boolean> {
|
|
59
|
-
if (mkStream === 'MKSTREAM') {
|
|
60
|
-
try {
|
|
61
|
-
return (await this.redisClient.xgroup(command, key, groupName, id, mkStream)) === 'OK';
|
|
62
|
-
} catch (err) {
|
|
63
|
-
this.logger.debug(`Consumer group not created with MKSTREAM for key: ${key} and group: ${groupName}`);
|
|
64
|
-
throw err;
|
|
65
|
-
}
|
|
66
|
-
} else {
|
|
67
|
-
try {
|
|
68
|
-
return (await this.redisClient.xgroup(command, key, groupName, id)) === 'OK';
|
|
69
|
-
} catch (err) {
|
|
70
|
-
this.logger.debug(`Consumer group not created for key: ${key} and group: ${groupName}`);
|
|
71
|
-
throw err;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async xadd(key: string, id: string, messageId: string, messageValue: string, multi?: RedisMultiType): Promise<string | RedisMultiType> {
|
|
77
|
-
try {
|
|
78
|
-
return await (multi || this.redisClient).xadd(key, id, messageId, messageValue);
|
|
79
|
-
} catch (error) {
|
|
80
|
-
this.logger.error(`Error publishing 'xadd'; key: ${key}`, { ...error });
|
|
81
|
-
throw error;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async xpending(
|
|
86
|
-
key: string,
|
|
87
|
-
group: string,
|
|
88
|
-
start?: string,
|
|
89
|
-
end?: string,
|
|
90
|
-
count?: number,
|
|
91
|
-
consumer?: string
|
|
92
|
-
): Promise<[string, string, number, [string, number][]][] | [string, string, number, number] | unknown[]> {
|
|
93
|
-
try {
|
|
94
|
-
return await this.redisClient.xpending(key, group, start, end, count, consumer);
|
|
95
|
-
} catch (error) {
|
|
96
|
-
this.logger.error(`Error in retrieving pending messages for [stream ${key}], [group ${group}]`, { ...error });
|
|
97
|
-
throw error;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async xclaim(
|
|
102
|
-
key: string,
|
|
103
|
-
group: string,
|
|
104
|
-
consumer: string,
|
|
105
|
-
minIdleTime: number,
|
|
106
|
-
id: string,
|
|
107
|
-
...args: string[]
|
|
108
|
-
): Promise<ReclaimedMessageType> {
|
|
109
|
-
try {
|
|
110
|
-
return await this.redisClient.xclaim(key, group, consumer, minIdleTime, id, ...args) as unknown as ReclaimedMessageType;
|
|
111
|
-
} catch (error) {
|
|
112
|
-
this.logger.error(`Error in claiming message with id: ${id} in group: ${group} for key: ${key}`, { ...error });
|
|
113
|
-
throw error;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
async xack(key: string, group: string, id: string, multi? : RedisMultiType): Promise<number|RedisMultiType> {
|
|
118
|
-
try {
|
|
119
|
-
return await (multi || this.redisClient).xack(key, group, id);
|
|
120
|
-
} catch (error) {
|
|
121
|
-
this.logger.error(`Error in acknowledging messages in group: ${group} for key: ${key}`, { ...error });
|
|
122
|
-
throw error;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
async xdel(key: string, id: string, multi? : RedisMultiType): Promise<number|RedisMultiType> {
|
|
127
|
-
try {
|
|
128
|
-
return await (multi || this.redisClient).xdel(key, id);
|
|
129
|
-
} catch (error) {
|
|
130
|
-
this.logger.error(`Error in deleting messages with id: ${id} for key: ${key}`, { ...error });
|
|
131
|
-
throw error;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async xlen(key: string, multi? : RedisMultiType): Promise<number|RedisMultiType> {
|
|
136
|
-
try {
|
|
137
|
-
return await (multi || this.redisClient).xlen(key);
|
|
138
|
-
} catch (error) {
|
|
139
|
-
this.logger.error(`Error getting stream depth: ${key}`, { ...error });
|
|
140
|
-
throw error;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export { IORedisStoreService };
|