@hotmeshio/hotmesh 0.0.51 → 0.0.53
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 +13 -9
- package/build/index.d.ts +1 -2
- package/build/index.js +1 -3
- package/build/modules/enums.d.ts +8 -3
- package/build/modules/enums.js +16 -8
- package/build/modules/errors.d.ts +98 -18
- package/build/modules/errors.js +90 -33
- package/build/package.json +7 -2
- package/build/services/activities/activity.d.ts +8 -0
- package/build/services/activities/activity.js +65 -16
- package/build/services/activities/await.js +6 -6
- package/build/services/activities/cycle.d.ts +2 -2
- package/build/services/activities/cycle.js +5 -5
- package/build/services/activities/hook.js +4 -4
- package/build/services/activities/interrupt.d.ts +3 -3
- package/build/services/activities/interrupt.js +15 -6
- package/build/services/activities/signal.d.ts +2 -2
- package/build/services/activities/signal.js +4 -4
- package/build/services/activities/trigger.js +12 -3
- package/build/services/activities/worker.js +6 -6
- package/build/services/compiler/deployer.js +33 -5
- package/build/services/compiler/validator.d.ts +2 -0
- package/build/services/compiler/validator.js +5 -1
- package/build/services/durable/client.d.ts +7 -1
- package/build/services/durable/client.js +56 -30
- package/build/services/durable/exporter.d.ts +7 -72
- package/build/services/durable/exporter.js +105 -295
- package/build/services/durable/handle.d.ts +11 -6
- package/build/services/durable/handle.js +59 -46
- package/build/services/durable/index.d.ts +0 -2
- package/build/services/durable/index.js +0 -2
- package/build/services/durable/schemas/factory.d.ts +33 -0
- package/build/services/durable/schemas/factory.js +2356 -0
- package/build/services/durable/search.js +8 -8
- package/build/services/durable/worker.js +117 -25
- package/build/services/durable/workflow.d.ts +46 -43
- package/build/services/durable/workflow.js +273 -277
- package/build/services/engine/index.js +3 -0
- package/build/services/exporter/index.d.ts +2 -4
- package/build/services/exporter/index.js +4 -5
- package/build/services/mapper/index.d.ts +6 -2
- package/build/services/mapper/index.js +6 -2
- package/build/services/pipe/functions/array.d.ts +2 -10
- package/build/services/pipe/functions/array.js +30 -28
- package/build/services/pipe/functions/conditional.d.ts +1 -0
- package/build/services/pipe/functions/conditional.js +3 -0
- package/build/services/pipe/functions/date.d.ts +1 -0
- package/build/services/pipe/functions/date.js +4 -0
- package/build/services/pipe/functions/index.d.ts +2 -0
- package/build/services/pipe/functions/index.js +2 -0
- package/build/services/pipe/functions/logical.d.ts +5 -0
- package/build/services/pipe/functions/logical.js +12 -0
- package/build/services/pipe/functions/object.d.ts +3 -0
- package/build/services/pipe/functions/object.js +25 -7
- package/build/services/pipe/index.d.ts +20 -3
- package/build/services/pipe/index.js +82 -16
- package/build/services/router/index.js +14 -3
- package/build/services/serializer/index.d.ts +3 -2
- package/build/services/serializer/index.js +11 -4
- package/build/services/store/clients/ioredis.js +6 -6
- package/build/services/store/clients/redis.js +7 -7
- package/build/services/store/index.d.ts +2 -0
- package/build/services/store/index.js +4 -1
- package/build/services/stream/clients/ioredis.js +8 -8
- package/build/services/stream/clients/redis.js +1 -1
- package/build/types/activity.d.ts +60 -5
- package/build/types/durable.d.ts +168 -33
- package/build/types/exporter.d.ts +26 -4
- package/build/types/index.d.ts +2 -2
- package/build/types/job.d.ts +69 -5
- package/build/types/pipe.d.ts +81 -3
- package/build/types/stream.d.ts +61 -1
- package/build/types/stream.js +4 -0
- package/index.ts +1 -2
- package/modules/enums.ts +16 -8
- package/modules/errors.ts +174 -32
- package/package.json +7 -2
- package/services/activities/activity.ts +67 -18
- package/services/activities/await.ts +6 -6
- package/services/activities/cycle.ts +7 -6
- package/services/activities/hook.ts +4 -4
- package/services/activities/interrupt.ts +19 -9
- package/services/activities/signal.ts +6 -5
- package/services/activities/trigger.ts +16 -4
- package/services/activities/worker.ts +7 -7
- package/services/compiler/deployer.ts +33 -6
- package/services/compiler/validator.ts +7 -3
- package/services/durable/client.ts +47 -14
- package/services/durable/exporter.ts +110 -318
- package/services/durable/handle.ts +63 -50
- package/services/durable/index.ts +0 -2
- package/services/durable/schemas/factory.ts +2358 -0
- package/services/durable/search.ts +8 -8
- package/services/durable/worker.ts +128 -29
- package/services/durable/workflow.ts +304 -288
- package/services/engine/index.ts +4 -0
- package/services/exporter/index.ts +10 -12
- package/services/mapper/index.ts +6 -2
- package/services/pipe/functions/array.ts +24 -37
- package/services/pipe/functions/conditional.ts +4 -0
- package/services/pipe/functions/date.ts +6 -0
- package/services/pipe/functions/index.ts +7 -5
- package/services/pipe/functions/logical.ts +11 -0
- package/services/pipe/functions/object.ts +26 -7
- package/services/pipe/index.ts +99 -21
- package/services/quorum/index.ts +1 -3
- package/services/router/index.ts +14 -3
- package/services/serializer/index.ts +12 -5
- package/services/store/clients/ioredis.ts +6 -6
- package/services/store/clients/redis.ts +7 -7
- package/services/store/index.ts +4 -1
- package/services/stream/clients/ioredis.ts +8 -8
- package/services/stream/clients/redis.ts +1 -1
- package/types/activity.ts +87 -15
- package/types/durable.ts +246 -73
- package/types/exporter.ts +31 -5
- package/types/index.ts +6 -7
- package/types/job.ts +130 -36
- package/types/pipe.ts +84 -3
- package/types/stream.ts +82 -23
- package/build/services/durable/factory.d.ts +0 -17
- package/build/services/durable/factory.js +0 -817
- package/build/services/durable/meshos.d.ts +0 -127
- package/build/services/durable/meshos.js +0 -380
- package/services/durable/factory.ts +0 -818
- package/services/durable/meshos.ts +0 -441
|
@@ -305,6 +305,7 @@ class EngineService {
|
|
|
305
305
|
streamData.status = stream_1.StreamStatus.ERROR;
|
|
306
306
|
streamData.data = error;
|
|
307
307
|
streamData.code = error.code;
|
|
308
|
+
streamData.stack = error.stack;
|
|
308
309
|
}
|
|
309
310
|
else if (emit) {
|
|
310
311
|
streamData.status = stream_1.StreamStatus.PENDING;
|
|
@@ -330,7 +331,9 @@ class EngineService {
|
|
|
330
331
|
}
|
|
331
332
|
// ****************** `INTERRUPT` ACTIVE JOBS *****************
|
|
332
333
|
async interrupt(topic, jobId, options = {}) {
|
|
334
|
+
//immediately interrupt the job, going directly to the data source
|
|
333
335
|
await this.store.interrupt(topic, jobId, options);
|
|
336
|
+
//now that the job is interrupted, we can clean up
|
|
334
337
|
const context = await this.getState(topic, jobId);
|
|
335
338
|
const completionOpts = {
|
|
336
339
|
interrupt: options.descend,
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { ILogger } from '../logger';
|
|
2
2
|
import { StoreService } from '../store';
|
|
3
|
-
import { StringStringType, Symbols } from "../../types/serializer";
|
|
4
|
-
import { RedisClient, RedisMulti } from '../../types/redis';
|
|
5
3
|
import { DependencyExport, ExportOptions, JobActionExport, JobExport } from '../../types/exporter';
|
|
6
|
-
import {
|
|
4
|
+
import { RedisClient, RedisMulti } from '../../types/redis';
|
|
5
|
+
import { StringStringType, Symbols } from "../../types/serializer";
|
|
7
6
|
/**
|
|
8
7
|
* Downloads job data from Redis (hscan, hmget, hgetall)
|
|
9
8
|
* Expands process data and includes dependency list
|
|
@@ -11,7 +10,6 @@ import { SerializerService } from '../serializer';
|
|
|
11
10
|
declare class ExporterService {
|
|
12
11
|
appId: string;
|
|
13
12
|
logger: ILogger;
|
|
14
|
-
serializer: SerializerService;
|
|
15
13
|
store: StoreService<RedisClient, RedisMulti>;
|
|
16
14
|
symbols: Promise<Symbols> | Symbols;
|
|
17
15
|
constructor(appId: string, store: StoreService<RedisClient, RedisMulti>, logger: ILogger);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ExporterService = void 0;
|
|
4
|
-
const serializer_1 = require("../serializer");
|
|
5
|
-
const utils_1 = require("../../modules/utils");
|
|
6
4
|
const key_1 = require("../../modules/key");
|
|
5
|
+
const utils_1 = require("../../modules/utils");
|
|
6
|
+
const serializer_1 = require("../serializer");
|
|
7
7
|
/**
|
|
8
8
|
* Downloads job data from Redis (hscan, hmget, hgetall)
|
|
9
9
|
* Expands process data and includes dependency list
|
|
@@ -13,7 +13,6 @@ class ExporterService {
|
|
|
13
13
|
this.appId = appId;
|
|
14
14
|
this.logger = logger;
|
|
15
15
|
this.store = store;
|
|
16
|
-
this.serializer = new serializer_1.SerializerService();
|
|
17
16
|
}
|
|
18
17
|
/**
|
|
19
18
|
* Convert the job hash and dependency list into a JobExport object.
|
|
@@ -63,12 +62,12 @@ class ExporterService {
|
|
|
63
62
|
const [_, letters, numbers] = match;
|
|
64
63
|
const path = this.inflateKey(letters);
|
|
65
64
|
const dimensions = `${numbers.replace(/,/g, '/')}`;
|
|
66
|
-
const resolved =
|
|
65
|
+
const resolved = serializer_1.SerializerService.fromString(value);
|
|
67
66
|
process[`${dimensions}/${path}`] = resolved;
|
|
68
67
|
}
|
|
69
68
|
else if (key.length === 3) {
|
|
70
69
|
//job state
|
|
71
|
-
process[this.inflateKey(key)] =
|
|
70
|
+
process[this.inflateKey(key)] = serializer_1.SerializerService.fromString(value);
|
|
72
71
|
}
|
|
73
72
|
});
|
|
74
73
|
return {
|
|
@@ -8,17 +8,21 @@ declare class MapperService {
|
|
|
8
8
|
mapRules(): Record<string, unknown>;
|
|
9
9
|
private traverseRules;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* resolves a pipe expression of the form: { @pipe: [["{data.foo.bar}", 2, false, "hello world"]] }
|
|
12
12
|
* @param value
|
|
13
13
|
* @returns
|
|
14
14
|
*/
|
|
15
15
|
private pipe;
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* resolves a mapping expression in the form: "{data.foo.bar}" or 2 or false or "hello world"
|
|
18
18
|
* @param value
|
|
19
19
|
* @returns
|
|
20
20
|
*/
|
|
21
21
|
private resolve;
|
|
22
|
+
/**
|
|
23
|
+
* Evaluates a transition rule against the current job state and incoming Stream message
|
|
24
|
+
* to determine which (if any) transition should be taken.
|
|
25
|
+
*/
|
|
22
26
|
static evaluate(transitionRule: TransitionRule | boolean, context: JobState, code: StreamCode): boolean;
|
|
23
27
|
}
|
|
24
28
|
export { MapperService };
|
|
@@ -28,7 +28,7 @@ class MapperService {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* resolves a pipe expression of the form: { @pipe: [["{data.foo.bar}", 2, false, "hello world"]] }
|
|
32
32
|
* @param value
|
|
33
33
|
* @returns
|
|
34
34
|
*/
|
|
@@ -37,7 +37,7 @@ class MapperService {
|
|
|
37
37
|
return pipe.process();
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
40
|
+
* resolves a mapping expression in the form: "{data.foo.bar}" or 2 or false or "hello world"
|
|
41
41
|
* @param value
|
|
42
42
|
* @returns
|
|
43
43
|
*/
|
|
@@ -45,6 +45,10 @@ class MapperService {
|
|
|
45
45
|
const pipe = new pipe_1.Pipe([[value]], this.data);
|
|
46
46
|
return pipe.process();
|
|
47
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Evaluates a transition rule against the current job state and incoming Stream message
|
|
50
|
+
* to determine which (if any) transition should be taken.
|
|
51
|
+
*/
|
|
48
52
|
static evaluate(transitionRule, context, code) {
|
|
49
53
|
if (typeof transitionRule === 'boolean') {
|
|
50
54
|
return transitionRule;
|
|
@@ -2,23 +2,15 @@ declare class ArrayHandler {
|
|
|
2
2
|
get(array: any[], index: number): any;
|
|
3
3
|
length(array: any[]): any;
|
|
4
4
|
concat(array1: any[], array2: any[]): any[];
|
|
5
|
-
every(array: any[], callback: (value: any, index: number, array: any[]) => boolean): boolean;
|
|
6
|
-
filter(array: any[], callback: (value: any, index: number, array: any[]) => boolean): any[];
|
|
7
|
-
find(array: any[], callback: (value: any, index: number, array: any[]) => boolean): any;
|
|
8
|
-
findIndex(array: any[], callback: (value: any, index: number, array: any[]) => boolean): number;
|
|
9
|
-
forEach(array: any[], callback: (value: any, index: number, array: any[]) => void): void;
|
|
10
5
|
indexOf(array: any[], searchElement: any, fromIndex?: number): number;
|
|
11
6
|
join(array: any[], separator: string): string;
|
|
12
7
|
lastIndexOf(array: any[], searchElement: any, fromIndex?: number): number;
|
|
13
|
-
map(array: any[], callback: (value: any, index: number, array: any[]) => any): any[];
|
|
14
8
|
pop(array: any[]): any;
|
|
15
|
-
push(array: any[], ...items: any[]):
|
|
16
|
-
reduce(array: any[], callback: (accumulator: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any;
|
|
9
|
+
push(array: any[], ...items: any[]): any[];
|
|
17
10
|
reverse(array: any[]): any[];
|
|
18
11
|
shift(array: any[]): any;
|
|
19
12
|
slice(array: any[], start?: number, end?: number): any[];
|
|
20
|
-
|
|
21
|
-
sort(array: any[], compareFunction?: (a: any, b: any) => number): any[];
|
|
13
|
+
sort(array: any[], order?: 'ASCENDING' | 'DESCENDING'): any[];
|
|
22
14
|
splice(array: any[], start: number, deleteCount?: number, ...items: any[]): any[];
|
|
23
15
|
unshift(array: any[], ...items: any[]): number;
|
|
24
16
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ArrayHandler = void 0;
|
|
4
4
|
class ArrayHandler {
|
|
5
5
|
get(array, index) {
|
|
6
|
-
return array[index];
|
|
6
|
+
return array?.[index || 0];
|
|
7
7
|
}
|
|
8
8
|
length(array) {
|
|
9
9
|
return array?.length;
|
|
@@ -11,21 +11,6 @@ class ArrayHandler {
|
|
|
11
11
|
concat(array1, array2) {
|
|
12
12
|
return array1.concat(array2);
|
|
13
13
|
}
|
|
14
|
-
every(array, callback) {
|
|
15
|
-
return array.every(callback);
|
|
16
|
-
}
|
|
17
|
-
filter(array, callback) {
|
|
18
|
-
return array.filter(callback);
|
|
19
|
-
}
|
|
20
|
-
find(array, callback) {
|
|
21
|
-
return array.find(callback);
|
|
22
|
-
}
|
|
23
|
-
findIndex(array, callback) {
|
|
24
|
-
return array.findIndex(callback);
|
|
25
|
-
}
|
|
26
|
-
forEach(array, callback) {
|
|
27
|
-
array.forEach(callback);
|
|
28
|
-
}
|
|
29
14
|
indexOf(array, searchElement, fromIndex) {
|
|
30
15
|
return array.indexOf(searchElement, fromIndex);
|
|
31
16
|
}
|
|
@@ -35,17 +20,12 @@ class ArrayHandler {
|
|
|
35
20
|
lastIndexOf(array, searchElement, fromIndex) {
|
|
36
21
|
return array.lastIndexOf(searchElement, fromIndex);
|
|
37
22
|
}
|
|
38
|
-
map(array, callback) {
|
|
39
|
-
return array.map(callback);
|
|
40
|
-
}
|
|
41
23
|
pop(array) {
|
|
42
24
|
return array.pop();
|
|
43
25
|
}
|
|
44
26
|
push(array, ...items) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
reduce(array, callback, initialValue) {
|
|
48
|
-
return array.reduce(callback, initialValue);
|
|
27
|
+
array.push(...items);
|
|
28
|
+
return array;
|
|
49
29
|
}
|
|
50
30
|
reverse(array) {
|
|
51
31
|
return array.reverse();
|
|
@@ -56,11 +36,33 @@ class ArrayHandler {
|
|
|
56
36
|
slice(array, start, end) {
|
|
57
37
|
return array.slice(start, end);
|
|
58
38
|
}
|
|
59
|
-
|
|
60
|
-
return array.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
39
|
+
sort(array, order = 'ASCENDING') {
|
|
40
|
+
return array.sort((a, b) => {
|
|
41
|
+
if (order === 'ASCENDING') {
|
|
42
|
+
if (a === b)
|
|
43
|
+
return 0;
|
|
44
|
+
if (a === null || a === undefined)
|
|
45
|
+
return -1;
|
|
46
|
+
if (b === null || b === undefined)
|
|
47
|
+
return 1;
|
|
48
|
+
if (typeof a === 'string' && typeof b === 'string') {
|
|
49
|
+
return a.localeCompare(b);
|
|
50
|
+
}
|
|
51
|
+
return a < b ? -1 : 1;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
if (a === b)
|
|
55
|
+
return 0;
|
|
56
|
+
if (a === null || a === undefined)
|
|
57
|
+
return 1;
|
|
58
|
+
if (b === null || b === undefined)
|
|
59
|
+
return -1;
|
|
60
|
+
if (typeof a === 'string' && typeof b === 'string') {
|
|
61
|
+
return b.localeCompare(a);
|
|
62
|
+
}
|
|
63
|
+
return a > b ? -1 : 1;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
64
66
|
}
|
|
65
67
|
splice(array, start, deleteCount, ...items) {
|
|
66
68
|
return array.splice(start, deleteCount, ...items);
|
|
@@ -6,5 +6,6 @@ declare class ConditionalHandler {
|
|
|
6
6
|
less_than(value1: number, value2: number): boolean;
|
|
7
7
|
greater_than_or_equal(value1: number, value2: number): boolean;
|
|
8
8
|
less_than_or_equal(value1: number, value2: number): boolean;
|
|
9
|
+
nullish(value1: any, value2: any): any;
|
|
9
10
|
}
|
|
10
11
|
export { ConditionalHandler };
|
|
@@ -46,6 +46,7 @@ declare class DateHandler {
|
|
|
46
46
|
setHours(date: DateInput, hours: number, minutes?: number, seconds?: number, ms?: number): number;
|
|
47
47
|
toDateString(date: DateInput): string;
|
|
48
48
|
toISOString(date: DateInput): string;
|
|
49
|
+
toISOXString(date?: DateInput): string;
|
|
49
50
|
toJSON(date: DateInput): string;
|
|
50
51
|
toLocaleDateString(date: DateInput, locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
|
|
51
52
|
toLocaleString(date: DateInput, locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DateHandler = void 0;
|
|
4
|
+
const utils_1 = require("../../../modules/utils");
|
|
4
5
|
class DateHandler {
|
|
5
6
|
/**
|
|
6
7
|
* It is so common in mapping operations to use a string (ISO) date as input. This helper
|
|
@@ -142,6 +143,9 @@ class DateHandler {
|
|
|
142
143
|
toISOString(date) {
|
|
143
144
|
return DateHandler.getDateInstance(date).toISOString();
|
|
144
145
|
}
|
|
146
|
+
toISOXString(date) {
|
|
147
|
+
return (0, utils_1.formatISODate)(date ? DateHandler.getDateInstance(date) : new Date());
|
|
148
|
+
}
|
|
145
149
|
toJSON(date) {
|
|
146
150
|
return DateHandler.getDateInstance(date).toJSON();
|
|
147
151
|
}
|
|
@@ -3,6 +3,7 @@ import { BitwiseHandler } from './bitwise';
|
|
|
3
3
|
import { ConditionalHandler } from './conditional';
|
|
4
4
|
import { DateHandler } from './date';
|
|
5
5
|
import { JsonHandler } from './json';
|
|
6
|
+
import { LogicalHandler } from './logical';
|
|
6
7
|
import { MathHandler } from './math';
|
|
7
8
|
import { NumberHandler } from './number';
|
|
8
9
|
import { ObjectHandler } from './object';
|
|
@@ -15,6 +16,7 @@ declare const _default: {
|
|
|
15
16
|
conditional: ConditionalHandler;
|
|
16
17
|
date: DateHandler;
|
|
17
18
|
json: JsonHandler;
|
|
19
|
+
logical: LogicalHandler;
|
|
18
20
|
math: MathHandler;
|
|
19
21
|
number: NumberHandler;
|
|
20
22
|
object: ObjectHandler;
|
|
@@ -5,6 +5,7 @@ const bitwise_1 = require("./bitwise");
|
|
|
5
5
|
const conditional_1 = require("./conditional");
|
|
6
6
|
const date_1 = require("./date");
|
|
7
7
|
const json_1 = require("./json");
|
|
8
|
+
const logical_1 = require("./logical");
|
|
8
9
|
const math_1 = require("./math");
|
|
9
10
|
const number_1 = require("./number");
|
|
10
11
|
const object_1 = require("./object");
|
|
@@ -17,6 +18,7 @@ exports.default = {
|
|
|
17
18
|
conditional: new conditional_1.ConditionalHandler(),
|
|
18
19
|
date: new date_1.DateHandler(),
|
|
19
20
|
json: new json_1.JsonHandler(),
|
|
21
|
+
logical: new logical_1.LogicalHandler(),
|
|
20
22
|
math: new math_1.MathHandler(),
|
|
21
23
|
number: new number_1.NumberHandler(),
|
|
22
24
|
object: new object_1.ObjectHandler(),
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogicalHandler = void 0;
|
|
4
|
+
class LogicalHandler {
|
|
5
|
+
and(firstValue, secondValue) {
|
|
6
|
+
return firstValue && secondValue;
|
|
7
|
+
}
|
|
8
|
+
or(firstValue, secondValue) {
|
|
9
|
+
return firstValue || secondValue;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.LogicalHandler = LogicalHandler;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
declare class ObjectHandler {
|
|
2
|
+
get(obj: object, prop: string | symbol): any;
|
|
3
|
+
set(obj: object, prop: string | symbol, value: any): any;
|
|
4
|
+
create(...args: any[]): object;
|
|
2
5
|
keys(obj: object): string[];
|
|
3
6
|
values(obj: object): any[];
|
|
4
7
|
entries(obj: object): [string, any][];
|
|
@@ -2,29 +2,47 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ObjectHandler = void 0;
|
|
4
4
|
class ObjectHandler {
|
|
5
|
+
get(obj, prop) {
|
|
6
|
+
return obj?.[prop];
|
|
7
|
+
}
|
|
8
|
+
set(obj, prop, value) {
|
|
9
|
+
if (!obj)
|
|
10
|
+
obj = {};
|
|
11
|
+
obj[prop] = value;
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
create(...args) {
|
|
15
|
+
const obj = {};
|
|
16
|
+
if (args.length === 0)
|
|
17
|
+
return obj;
|
|
18
|
+
for (let i = 0; i < args.length; i += 2) {
|
|
19
|
+
obj[args[i]] = args[i + 1];
|
|
20
|
+
}
|
|
21
|
+
return obj;
|
|
22
|
+
}
|
|
5
23
|
keys(obj) {
|
|
6
|
-
return Object.keys(obj);
|
|
24
|
+
return obj && Object.keys(obj) || [];
|
|
7
25
|
}
|
|
8
26
|
values(obj) {
|
|
9
|
-
return Object.values(obj);
|
|
27
|
+
return obj && Object.values(obj) || [];
|
|
10
28
|
}
|
|
11
29
|
entries(obj) {
|
|
12
|
-
return Object.entries(obj);
|
|
30
|
+
return obj && Object.entries(obj) || [];
|
|
13
31
|
}
|
|
14
32
|
fromEntries(iterable) {
|
|
15
33
|
return Object.fromEntries(iterable);
|
|
16
34
|
}
|
|
17
35
|
assign(target, ...sources) {
|
|
18
|
-
return Object.assign(target, ...sources);
|
|
36
|
+
return Object.assign(target || {}, ...sources);
|
|
19
37
|
}
|
|
20
38
|
getOwnPropertyNames(obj) {
|
|
21
|
-
return Object.getOwnPropertyNames(obj);
|
|
39
|
+
return Object.getOwnPropertyNames(obj || {});
|
|
22
40
|
}
|
|
23
41
|
getOwnPropertySymbols(obj) {
|
|
24
|
-
return Object.getOwnPropertySymbols(obj);
|
|
42
|
+
return Object.getOwnPropertySymbols(obj || {});
|
|
25
43
|
}
|
|
26
44
|
getOwnPropertyDescriptor(obj, prop) {
|
|
27
|
-
return Object.getOwnPropertyDescriptor(obj, prop);
|
|
45
|
+
return Object.getOwnPropertyDescriptor(obj || {}, prop);
|
|
28
46
|
}
|
|
29
47
|
defineProperty(obj, prop, descriptor) {
|
|
30
48
|
return Object.defineProperty(obj, prop, descriptor);
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { JobState, JobData } from '../../types/job';
|
|
2
|
-
import { PipeItem, PipeItems, Pipe as PipeType } from '../../types/pipe';
|
|
2
|
+
import { PipeContext, PipeItem, PipeItems, Pipe as PipeType } from '../../types/pipe';
|
|
3
3
|
declare class Pipe {
|
|
4
4
|
rules: PipeType;
|
|
5
5
|
jobData: JobData;
|
|
6
|
-
|
|
6
|
+
context: PipeContext;
|
|
7
|
+
constructor(rules: PipeType, jobData: JobData, context?: PipeContext);
|
|
7
8
|
private isPipeType;
|
|
9
|
+
private isreduceType;
|
|
8
10
|
static isPipeObject(obj: {
|
|
9
11
|
[key: string]: unknown;
|
|
10
12
|
} | PipeItem): boolean;
|
|
@@ -15,15 +17,30 @@ declare class Pipe {
|
|
|
15
17
|
* loop through each PipeItem row in this Pipe, resolving and transforming line by line
|
|
16
18
|
* @returns {any} the result of the pipe
|
|
17
19
|
*/
|
|
18
|
-
process(): any;
|
|
20
|
+
process(resolved?: unknown[] | null): any;
|
|
21
|
+
/**
|
|
22
|
+
* Transforms iterable `input` into a single value. Vars $output, $item, $key
|
|
23
|
+
* and $input are available. The final statement in the iterator (the reduction)
|
|
24
|
+
* is assumed to be the return value. A default $output object may be provided
|
|
25
|
+
* to the iterator by placing the the second cell of the preceding row. Otherwise,
|
|
26
|
+
* construct the object during first run and ensure it is the first cell of the
|
|
27
|
+
* last row of the iterator, so it is returned as the $output for the next cycle
|
|
28
|
+
* @param {unknown[]} input
|
|
29
|
+
* @returns {unknown}
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
reduce(input: Array<unknown[]>): unknown;
|
|
19
33
|
private processRow;
|
|
20
34
|
static resolveFunction(functionName: string): any;
|
|
21
35
|
processCells(cells: PipeItems): unknown[];
|
|
22
36
|
private isFunction;
|
|
37
|
+
private isContextVariable;
|
|
23
38
|
private isMappable;
|
|
24
39
|
resolveCellValue(currentCell: PipeItem): unknown;
|
|
25
40
|
private getNestedProperty;
|
|
26
41
|
resolveMappableValue(currentCell: string): unknown;
|
|
42
|
+
resolveContextValue(currentCell: string): unknown;
|
|
43
|
+
resolveContextTerm(currentCell: string): string;
|
|
27
44
|
resolveFunctionTerm(currentCell: string): string;
|
|
28
45
|
resolveMapTerm(currentCell: string): string;
|
|
29
46
|
}
|
|
@@ -6,13 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.Pipe = void 0;
|
|
7
7
|
const functions_1 = __importDefault(require("./functions"));
|
|
8
8
|
class Pipe {
|
|
9
|
-
constructor(rules, jobData) {
|
|
9
|
+
constructor(rules, jobData, context) {
|
|
10
10
|
this.rules = rules;
|
|
11
11
|
this.jobData = jobData;
|
|
12
|
+
this.context = context;
|
|
12
13
|
}
|
|
13
14
|
isPipeType(currentRow) {
|
|
14
15
|
return !Array.isArray(currentRow) && '@pipe' in currentRow;
|
|
15
16
|
}
|
|
17
|
+
isreduceType(currentRow) {
|
|
18
|
+
return !Array.isArray(currentRow) && '@reduce' in currentRow;
|
|
19
|
+
}
|
|
16
20
|
static isPipeObject(obj) {
|
|
17
21
|
return typeof obj === 'object' && obj !== null && !Array.isArray(obj) && '@pipe' in obj;
|
|
18
22
|
}
|
|
@@ -30,36 +34,81 @@ class Pipe {
|
|
|
30
34
|
* loop through each PipeItem row in this Pipe, resolving and transforming line by line
|
|
31
35
|
* @returns {any} the result of the pipe
|
|
32
36
|
*/
|
|
33
|
-
process() {
|
|
34
|
-
let
|
|
37
|
+
process(resolved = null) {
|
|
38
|
+
let index = 0;
|
|
39
|
+
if (!(resolved || this.isPipeType(this.rules[0]) || this.isreduceType(this.rules[0]))) {
|
|
40
|
+
resolved = this.processCells(this.rules[0]); // Add type assertion
|
|
41
|
+
index = 1;
|
|
42
|
+
}
|
|
35
43
|
const len = this.rules.length;
|
|
36
|
-
|
|
37
|
-
|
|
44
|
+
const subPipeQueue = [];
|
|
45
|
+
for (let i = index; i < len; i++) {
|
|
46
|
+
resolved = this.processRow(this.rules[i], resolved, subPipeQueue);
|
|
38
47
|
}
|
|
39
48
|
return resolved[0];
|
|
40
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Transforms iterable `input` into a single value. Vars $output, $item, $key
|
|
52
|
+
* and $input are available. The final statement in the iterator (the reduction)
|
|
53
|
+
* is assumed to be the return value. A default $output object may be provided
|
|
54
|
+
* to the iterator by placing the the second cell of the preceding row. Otherwise,
|
|
55
|
+
* construct the object during first run and ensure it is the first cell of the
|
|
56
|
+
* last row of the iterator, so it is returned as the $output for the next cycle
|
|
57
|
+
* @param {unknown[]} input
|
|
58
|
+
* @returns {unknown}
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
reduce(input) {
|
|
62
|
+
let resolved = input[1] ?? null;
|
|
63
|
+
if (Array.isArray(input[0])) {
|
|
64
|
+
for (let index = 0; index < input[0].length; index++) {
|
|
65
|
+
this.context = { $input: input[0], $output: resolved, $item: input[0][index], $key: index.toString(), $index: index };
|
|
66
|
+
resolved = this.process([resolved]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
let index = -1;
|
|
71
|
+
for (let $key in input[0]) {
|
|
72
|
+
index++;
|
|
73
|
+
this.context = { $input: input[0], $output: resolved, $item: input[0][$key], $key, $index: index };
|
|
74
|
+
resolved = this.process([resolved]);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return [resolved];
|
|
78
|
+
}
|
|
41
79
|
processRow(currentRow, resolvedPriorRow, subPipeQueue) {
|
|
42
|
-
if (this.
|
|
43
|
-
//
|
|
44
|
-
const subPipe = new Pipe(currentRow['@
|
|
80
|
+
if (resolvedPriorRow && this.isreduceType(currentRow)) {
|
|
81
|
+
//reduce the resolvedPriorRow and return the output from the reducer
|
|
82
|
+
const subPipe = new Pipe(currentRow['@reduce'], this.jobData);
|
|
83
|
+
const reduced = subPipe.reduce(resolvedPriorRow);
|
|
84
|
+
return reduced;
|
|
85
|
+
}
|
|
86
|
+
else if (this.isPipeType(currentRow)) {
|
|
87
|
+
//process subPipe and push to subPipeQueue; echo resolvedPriorRow
|
|
88
|
+
const subPipe = new Pipe(currentRow['@pipe'], this.jobData, this.context);
|
|
45
89
|
subPipeQueue.push(subPipe.process());
|
|
46
|
-
//return prior row as if nothing happened
|
|
47
90
|
return resolvedPriorRow;
|
|
48
91
|
}
|
|
49
92
|
else {
|
|
93
|
+
//pivot the subPipeQueue into the arguments array (resolvedPriorRow)
|
|
50
94
|
if (subPipeQueue.length > 0) {
|
|
51
|
-
//if items in subPipeQueue, flush and use as resolvedPriorRow
|
|
52
95
|
resolvedPriorRow = [...subPipeQueue];
|
|
53
96
|
subPipeQueue.length = 0;
|
|
54
97
|
}
|
|
55
|
-
|
|
98
|
+
if (!resolvedPriorRow) {
|
|
56
99
|
//if no prior row, use current row as prior row
|
|
57
|
-
return [].concat(this.processCells([...currentRow]));
|
|
100
|
+
return [].concat(this.processCells(Array.isArray(currentRow) ? [...currentRow] : []));
|
|
58
101
|
}
|
|
59
102
|
else {
|
|
60
|
-
const [functionName, ...params] = currentRow;
|
|
103
|
+
const [functionName, ...params] = currentRow; // Add type assertion
|
|
61
104
|
//use resolved values from prior row (n - 1) as input params to cell 1 function
|
|
62
|
-
|
|
105
|
+
let resolvedValue;
|
|
106
|
+
if (this.isContextVariable(functionName)) {
|
|
107
|
+
resolvedValue = this.resolveContextValue(functionName);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
resolvedValue = Pipe.resolveFunction(functionName)(...resolvedPriorRow);
|
|
111
|
+
}
|
|
63
112
|
//resolve remaining cells in row and return concatenated with resolvedValue
|
|
64
113
|
return [resolvedValue].concat(this.processCells([...params]));
|
|
65
114
|
}
|
|
@@ -80,14 +129,21 @@ class Pipe {
|
|
|
80
129
|
}
|
|
81
130
|
processCells(cells) {
|
|
82
131
|
const resolved = [];
|
|
83
|
-
|
|
84
|
-
|
|
132
|
+
if (Array.isArray(cells)) {
|
|
133
|
+
for (const currentCell of cells) {
|
|
134
|
+
resolved.push(this.resolveCellValue(currentCell));
|
|
135
|
+
}
|
|
85
136
|
}
|
|
86
137
|
return resolved;
|
|
87
138
|
}
|
|
88
139
|
isFunction(currentCell) {
|
|
89
140
|
return typeof currentCell === 'string' && currentCell.startsWith('{@') && currentCell.endsWith('}');
|
|
90
141
|
}
|
|
142
|
+
isContextVariable(currentCell) {
|
|
143
|
+
if (typeof currentCell === 'string' && currentCell.endsWith('}')) {
|
|
144
|
+
return currentCell.startsWith('{$item') || currentCell.startsWith('{$key') || currentCell.startsWith('{$index') || currentCell.startsWith('{$input') || currentCell.startsWith('{$output');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
91
147
|
isMappable(currentCell) {
|
|
92
148
|
return typeof currentCell === 'string' && currentCell.startsWith('{') && currentCell.endsWith('}');
|
|
93
149
|
}
|
|
@@ -96,6 +152,9 @@ class Pipe {
|
|
|
96
152
|
const fn = Pipe.resolveFunction(currentCell);
|
|
97
153
|
return fn.call();
|
|
98
154
|
}
|
|
155
|
+
else if (this.isContextVariable(currentCell)) {
|
|
156
|
+
return this.resolveContextValue(currentCell);
|
|
157
|
+
}
|
|
99
158
|
else if (this.isMappable(currentCell)) {
|
|
100
159
|
return this.resolveMappableValue(currentCell);
|
|
101
160
|
}
|
|
@@ -118,6 +177,13 @@ class Pipe {
|
|
|
118
177
|
const term = this.resolveMapTerm(currentCell);
|
|
119
178
|
return this.getNestedProperty(this.jobData, term);
|
|
120
179
|
}
|
|
180
|
+
resolveContextValue(currentCell) {
|
|
181
|
+
const term = this.resolveContextTerm(currentCell);
|
|
182
|
+
return this.getNestedProperty(this.context, term);
|
|
183
|
+
}
|
|
184
|
+
resolveContextTerm(currentCell) {
|
|
185
|
+
return currentCell.substring(1, currentCell.length - 1);
|
|
186
|
+
}
|
|
121
187
|
resolveFunctionTerm(currentCell) {
|
|
122
188
|
return currentCell.substring(2, currentCell.length - 1);
|
|
123
189
|
}
|