@hotmeshio/hotmesh 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/modules/enums.d.ts +110 -0
- package/build/modules/enums.js +134 -0
- package/build/modules/errors.d.ts +124 -0
- package/build/modules/errors.js +191 -0
- package/build/modules/key.d.ts +66 -0
- package/build/modules/key.js +190 -0
- package/build/modules/storage.d.ts +3 -0
- package/build/modules/storage.js +5 -0
- package/build/modules/utils.d.ts +119 -0
- package/build/modules/utils.js +374 -0
- package/build/package.json +1 -1
- package/build/services/activities/activity.d.ts +104 -0
- package/build/services/activities/activity.js +549 -0
- package/build/services/activities/await.d.ts +12 -0
- package/build/services/activities/await.js +114 -0
- package/build/services/activities/cycle.d.ts +19 -0
- package/build/services/activities/cycle.js +112 -0
- package/build/services/activities/hook.d.ts +27 -0
- package/build/services/activities/hook.js +168 -0
- package/build/services/activities/index.d.ts +19 -0
- package/build/services/activities/index.js +20 -0
- package/build/services/activities/interrupt.d.ts +16 -0
- package/build/services/activities/interrupt.js +158 -0
- package/build/services/activities/signal.d.ts +20 -0
- package/build/services/activities/signal.js +134 -0
- package/build/services/activities/trigger.d.ts +37 -0
- package/build/services/activities/trigger.js +246 -0
- package/build/services/activities/worker.d.ts +12 -0
- package/build/services/activities/worker.js +106 -0
- package/build/services/collator/index.d.ts +111 -0
- package/build/services/collator/index.js +293 -0
- package/build/services/compiler/deployer.d.ts +40 -0
- package/build/services/compiler/deployer.js +488 -0
- package/build/services/compiler/index.d.ts +32 -0
- package/build/services/compiler/index.js +112 -0
- package/build/services/compiler/validator.d.ts +34 -0
- package/build/services/compiler/validator.js +147 -0
- package/build/services/connector/factory.d.ts +22 -0
- package/build/services/connector/factory.js +99 -0
- package/build/services/connector/index.d.ts +30 -0
- package/build/services/connector/index.js +54 -0
- package/build/services/connector/providers/ioredis.d.ts +9 -0
- package/build/services/connector/providers/ioredis.js +26 -0
- package/build/services/connector/providers/nats.d.ts +9 -0
- package/build/services/connector/providers/nats.js +34 -0
- package/build/services/connector/providers/postgres.d.ts +20 -0
- package/build/services/connector/providers/postgres.js +102 -0
- package/build/services/connector/providers/redis.d.ts +9 -0
- package/build/services/connector/providers/redis.js +38 -0
- package/build/services/engine/index.d.ts +264 -0
- package/build/services/engine/index.js +761 -0
- package/build/services/exporter/index.d.ts +44 -0
- package/build/services/exporter/index.js +126 -0
- package/build/services/hotmesh/index.d.ts +483 -0
- package/build/services/hotmesh/index.js +622 -0
- package/build/services/logger/index.d.ts +16 -0
- package/build/services/logger/index.js +54 -0
- package/build/services/mapper/index.d.ts +28 -0
- package/build/services/mapper/index.js +81 -0
- package/build/services/memflow/client.d.ts +108 -0
- package/build/services/memflow/client.js +372 -0
- package/build/services/memflow/connection.d.ts +23 -0
- package/build/services/memflow/connection.js +33 -0
- package/build/services/memflow/context.d.ts +143 -0
- package/build/services/memflow/context.js +299 -0
- package/build/services/memflow/exporter.d.ts +51 -0
- package/build/services/memflow/exporter.js +215 -0
- package/build/services/memflow/handle.d.ts +90 -0
- package/build/services/memflow/handle.js +176 -0
- package/build/services/memflow/index.d.ts +116 -0
- package/build/services/memflow/index.js +122 -0
- package/build/services/memflow/schemas/factory.d.ts +29 -0
- package/build/services/memflow/schemas/factory.js +2492 -0
- package/build/services/memflow/search.d.ts +142 -0
- package/build/services/memflow/search.js +320 -0
- package/build/services/memflow/worker.d.ts +124 -0
- package/build/services/memflow/worker.js +514 -0
- package/build/services/memflow/workflow/all.d.ts +7 -0
- package/build/services/memflow/workflow/all.js +15 -0
- package/build/services/memflow/workflow/common.d.ts +20 -0
- package/build/services/memflow/workflow/common.js +47 -0
- package/build/services/memflow/workflow/context.d.ts +6 -0
- package/build/services/memflow/workflow/context.js +45 -0
- package/build/services/memflow/workflow/contextMethods.d.ts +14 -0
- package/build/services/memflow/workflow/contextMethods.js +33 -0
- package/build/services/memflow/workflow/didRun.d.ts +7 -0
- package/build/services/memflow/workflow/didRun.js +22 -0
- package/build/services/memflow/workflow/emit.d.ts +11 -0
- package/build/services/memflow/workflow/emit.js +29 -0
- package/build/services/memflow/workflow/enrich.d.ts +9 -0
- package/build/services/memflow/workflow/enrich.js +17 -0
- package/build/services/memflow/workflow/execChild.d.ts +18 -0
- package/build/services/memflow/workflow/execChild.js +102 -0
- package/build/services/memflow/workflow/execHook.d.ts +65 -0
- package/build/services/memflow/workflow/execHook.js +73 -0
- package/build/services/memflow/workflow/hook.d.ts +9 -0
- package/build/services/memflow/workflow/hook.js +56 -0
- package/build/services/memflow/workflow/index.d.ts +74 -0
- package/build/services/memflow/workflow/index.js +87 -0
- package/build/services/memflow/workflow/interrupt.d.ts +9 -0
- package/build/services/memflow/workflow/interrupt.js +24 -0
- package/build/services/memflow/workflow/isSideEffectAllowed.d.ts +10 -0
- package/build/services/memflow/workflow/isSideEffectAllowed.js +33 -0
- package/build/services/memflow/workflow/proxyActivities.d.ts +20 -0
- package/build/services/memflow/workflow/proxyActivities.js +97 -0
- package/build/services/memflow/workflow/random.d.ts +6 -0
- package/build/services/memflow/workflow/random.js +16 -0
- package/build/services/memflow/workflow/searchMethods.d.ts +6 -0
- package/build/services/memflow/workflow/searchMethods.js +25 -0
- package/build/services/memflow/workflow/signal.d.ts +7 -0
- package/build/services/memflow/workflow/signal.js +28 -0
- package/build/services/memflow/workflow/sleepFor.d.ts +8 -0
- package/build/services/memflow/workflow/sleepFor.js +35 -0
- package/build/services/memflow/workflow/trace.d.ts +14 -0
- package/build/services/memflow/workflow/trace.js +33 -0
- package/build/services/memflow/workflow/waitFor.d.ts +8 -0
- package/build/services/memflow/workflow/waitFor.js +35 -0
- package/build/services/meshcall/index.d.ts +194 -0
- package/build/services/meshcall/index.js +452 -0
- package/build/services/meshcall/schemas/factory.d.ts +9 -0
- package/build/services/meshcall/schemas/factory.js +189 -0
- package/build/services/meshdata/index.d.ts +795 -0
- package/build/services/meshdata/index.js +1235 -0
- package/build/services/meshos/index.d.ts +293 -0
- package/build/services/meshos/index.js +547 -0
- package/build/services/pipe/functions/array.d.ts +17 -0
- package/build/services/pipe/functions/array.js +74 -0
- package/build/services/pipe/functions/bitwise.d.ts +9 -0
- package/build/services/pipe/functions/bitwise.js +24 -0
- package/build/services/pipe/functions/conditional.d.ts +13 -0
- package/build/services/pipe/functions/conditional.js +36 -0
- package/build/services/pipe/functions/cron.d.ts +12 -0
- package/build/services/pipe/functions/cron.js +40 -0
- package/build/services/pipe/functions/date.d.ts +58 -0
- package/build/services/pipe/functions/date.js +171 -0
- package/build/services/pipe/functions/index.d.ts +29 -0
- package/build/services/pipe/functions/index.js +30 -0
- package/build/services/pipe/functions/json.d.ts +5 -0
- package/build/services/pipe/functions/json.js +12 -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/math.d.ts +42 -0
- package/build/services/pipe/functions/math.js +184 -0
- package/build/services/pipe/functions/number.d.ts +21 -0
- package/build/services/pipe/functions/number.js +60 -0
- package/build/services/pipe/functions/object.d.ts +25 -0
- package/build/services/pipe/functions/object.js +81 -0
- package/build/services/pipe/functions/string.d.ts +23 -0
- package/build/services/pipe/functions/string.js +69 -0
- package/build/services/pipe/functions/symbol.d.ts +12 -0
- package/build/services/pipe/functions/symbol.js +33 -0
- package/build/services/pipe/functions/unary.d.ts +7 -0
- package/build/services/pipe/functions/unary.js +18 -0
- package/build/services/pipe/index.d.ts +48 -0
- package/build/services/pipe/index.js +242 -0
- package/build/services/quorum/index.d.ts +90 -0
- package/build/services/quorum/index.js +263 -0
- package/build/services/reporter/index.d.ts +50 -0
- package/build/services/reporter/index.js +348 -0
- package/build/services/router/config/index.d.ts +11 -0
- package/build/services/router/config/index.js +36 -0
- package/build/services/router/consumption/index.d.ts +34 -0
- package/build/services/router/consumption/index.js +395 -0
- package/build/services/router/error-handling/index.d.ts +8 -0
- package/build/services/router/error-handling/index.js +98 -0
- package/build/services/router/index.d.ts +57 -0
- package/build/services/router/index.js +121 -0
- package/build/services/router/lifecycle/index.d.ts +27 -0
- package/build/services/router/lifecycle/index.js +80 -0
- package/build/services/router/telemetry/index.d.ts +11 -0
- package/build/services/router/telemetry/index.js +32 -0
- package/build/services/router/throttling/index.d.ts +23 -0
- package/build/services/router/throttling/index.js +76 -0
- package/build/services/search/factory.d.ts +7 -0
- package/build/services/search/factory.js +24 -0
- package/build/services/search/index.d.ts +23 -0
- package/build/services/search/index.js +10 -0
- package/build/services/search/providers/postgres/postgres.d.ts +25 -0
- package/build/services/search/providers/postgres/postgres.js +149 -0
- package/build/services/search/providers/redis/ioredis.d.ts +19 -0
- package/build/services/search/providers/redis/ioredis.js +121 -0
- package/build/services/search/providers/redis/redis.d.ts +19 -0
- package/build/services/search/providers/redis/redis.js +134 -0
- package/build/services/serializer/index.d.ts +42 -0
- package/build/services/serializer/index.js +282 -0
- package/build/services/store/cache.d.ts +67 -0
- package/build/services/store/cache.js +128 -0
- package/build/services/store/factory.d.ts +8 -0
- package/build/services/store/factory.js +24 -0
- package/build/services/store/index.d.ts +89 -0
- package/build/services/store/index.js +9 -0
- package/build/services/store/providers/postgres/kvsql.d.ts +168 -0
- package/build/services/store/providers/postgres/kvsql.js +198 -0
- package/build/services/store/providers/postgres/kvtables.d.ts +20 -0
- package/build/services/store/providers/postgres/kvtables.js +441 -0
- package/build/services/store/providers/postgres/kvtransaction.d.ts +36 -0
- package/build/services/store/providers/postgres/kvtransaction.js +248 -0
- package/build/services/store/providers/postgres/kvtypes/hash.d.ts +60 -0
- package/build/services/store/providers/postgres/kvtypes/hash.js +1287 -0
- package/build/services/store/providers/postgres/kvtypes/list.d.ts +33 -0
- package/build/services/store/providers/postgres/kvtypes/list.js +194 -0
- package/build/services/store/providers/postgres/kvtypes/string.d.ts +20 -0
- package/build/services/store/providers/postgres/kvtypes/string.js +115 -0
- package/build/services/store/providers/postgres/kvtypes/zset.d.ts +41 -0
- package/build/services/store/providers/postgres/kvtypes/zset.js +214 -0
- package/build/services/store/providers/postgres/postgres.d.ts +145 -0
- package/build/services/store/providers/postgres/postgres.js +1036 -0
- package/build/services/store/providers/redis/_base.d.ts +137 -0
- package/build/services/store/providers/redis/_base.js +980 -0
- package/build/services/store/providers/redis/ioredis.d.ts +20 -0
- package/build/services/store/providers/redis/ioredis.js +180 -0
- package/build/services/store/providers/redis/redis.d.ts +18 -0
- package/build/services/store/providers/redis/redis.js +199 -0
- package/build/services/store/providers/store-initializable.d.ts +5 -0
- package/build/services/store/providers/store-initializable.js +2 -0
- package/build/services/stream/factory.d.ts +8 -0
- package/build/services/stream/factory.js +37 -0
- package/build/services/stream/index.d.ts +69 -0
- package/build/services/stream/index.js +11 -0
- package/build/services/stream/providers/nats/nats.d.ts +60 -0
- package/build/services/stream/providers/nats/nats.js +225 -0
- package/build/services/stream/providers/postgres/kvtables.d.ts +3 -0
- package/build/services/stream/providers/postgres/kvtables.js +146 -0
- package/build/services/stream/providers/postgres/postgres.d.ts +107 -0
- package/build/services/stream/providers/postgres/postgres.js +519 -0
- package/build/services/stream/providers/redis/ioredis.d.ts +61 -0
- package/build/services/stream/providers/redis/ioredis.js +272 -0
- package/build/services/stream/providers/redis/redis.d.ts +61 -0
- package/build/services/stream/providers/redis/redis.js +305 -0
- package/build/services/stream/providers/stream-initializable.d.ts +4 -0
- package/build/services/stream/providers/stream-initializable.js +2 -0
- package/build/services/sub/factory.d.ts +7 -0
- package/build/services/sub/factory.js +29 -0
- package/build/services/sub/index.d.ts +22 -0
- package/build/services/sub/index.js +10 -0
- package/build/services/sub/providers/nats/nats.d.ts +19 -0
- package/build/services/sub/providers/nats/nats.js +105 -0
- package/build/services/sub/providers/postgres/postgres.d.ts +19 -0
- package/build/services/sub/providers/postgres/postgres.js +92 -0
- package/build/services/sub/providers/redis/ioredis.d.ts +17 -0
- package/build/services/sub/providers/redis/ioredis.js +81 -0
- package/build/services/sub/providers/redis/redis.d.ts +17 -0
- package/build/services/sub/providers/redis/redis.js +72 -0
- package/build/services/task/index.d.ts +36 -0
- package/build/services/task/index.js +206 -0
- package/build/services/telemetry/index.d.ts +52 -0
- package/build/services/telemetry/index.js +306 -0
- package/build/services/worker/index.d.ts +77 -0
- package/build/services/worker/index.js +197 -0
- package/package.json +1 -1
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/typedoc.json +0 -47
- package/types/activity.ts +0 -268
- package/types/app.ts +0 -20
- package/types/async.ts +0 -6
- package/types/cache.ts +0 -1
- package/types/collator.ts +0 -9
- package/types/error.ts +0 -56
- package/types/exporter.ts +0 -102
- package/types/hook.ts +0 -44
- package/types/hotmesh.ts +0 -314
- package/types/index.ts +0 -306
- package/types/job.ts +0 -233
- package/types/logger.ts +0 -8
- package/types/manifest.ts +0 -70
- package/types/map.ts +0 -5
- package/types/memflow.ts +0 -645
- package/types/meshcall.ts +0 -235
- package/types/meshdata.ts +0 -278
- package/types/ms.d.ts +0 -7
- package/types/nats.ts +0 -270
- package/types/pipe.ts +0 -90
- package/types/postgres.ts +0 -114
- package/types/provider.ts +0 -161
- package/types/quorum.ts +0 -167
- package/types/redis.ts +0 -404
- package/types/serializer.ts +0 -40
- package/types/stats.ts +0 -117
- package/types/stream.ts +0 -231
- package/types/task.ts +0 -7
- package/types/telemetry.ts +0 -16
- package/types/transition.ts +0 -20
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CollatorService = void 0;
|
|
4
|
+
const errors_1 = require("../../modules/errors");
|
|
5
|
+
const collator_1 = require("../../types/collator");
|
|
6
|
+
class CollatorService {
|
|
7
|
+
/**
|
|
8
|
+
* Upon re/entry, verify that the job status is active
|
|
9
|
+
*/
|
|
10
|
+
static assertJobActive(status, jobId, activityId, threshold = 0) {
|
|
11
|
+
if (status <= threshold) {
|
|
12
|
+
throw new errors_1.InactiveJobError(jobId, status, activityId);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* returns the dimensional address (dad) for the target; due
|
|
17
|
+
* to the nature of the notary system, the dad for leg 2 entry
|
|
18
|
+
* must target the `0` index while leg 2 exit must target the
|
|
19
|
+
* current index (0)
|
|
20
|
+
*/
|
|
21
|
+
static getDimensionalAddress(activity, isEntry = false) {
|
|
22
|
+
let dad = activity.context.metadata.dad || activity.metadata.dad;
|
|
23
|
+
if (isEntry && dad && activity.leg === 2) {
|
|
24
|
+
dad = `${dad.substring(0, dad.lastIndexOf(','))},0`;
|
|
25
|
+
}
|
|
26
|
+
return CollatorService.getDimensionsById([...activity.config.ancestors, activity.metadata.aid], dad);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* resolves the dimensional address for the
|
|
30
|
+
* ancestor in the graph to go back to. this address
|
|
31
|
+
* is determined by trimming the last digits from
|
|
32
|
+
* the `dad` (including the target).
|
|
33
|
+
* the target activity index is then set to `0`, so that
|
|
34
|
+
* the origin node can be queried for approval/entry.
|
|
35
|
+
*/
|
|
36
|
+
static resolveReentryDimension(activity) {
|
|
37
|
+
const targetActivityId = activity.config.ancestor;
|
|
38
|
+
const ancestors = activity.config.ancestors;
|
|
39
|
+
const ancestorIndex = ancestors.indexOf(targetActivityId);
|
|
40
|
+
const dimensions = activity.metadata.dad.split(','); //e.g., `,0,0,1,0`
|
|
41
|
+
dimensions.length = ancestorIndex + 1;
|
|
42
|
+
dimensions.push('0');
|
|
43
|
+
return dimensions.join(',');
|
|
44
|
+
}
|
|
45
|
+
static async notarizeEntry(activity, transaction) {
|
|
46
|
+
//decrement by -100_000_000_000_000
|
|
47
|
+
const amount = await activity.store.collate(activity.context.metadata.jid, activity.metadata.aid, -100000000000000, this.getDimensionalAddress(activity), transaction);
|
|
48
|
+
this.verifyInteger(amount, 1, 'enter');
|
|
49
|
+
return amount;
|
|
50
|
+
}
|
|
51
|
+
static async authorizeReentry(activity, transaction) {
|
|
52
|
+
//set second digit to 8, allowing for re-entry
|
|
53
|
+
//decrement by -10_000_000_000_000
|
|
54
|
+
const amount = await activity.store.collate(activity.context.metadata.jid, activity.metadata.aid, -10000000000000, this.getDimensionalAddress(activity), transaction);
|
|
55
|
+
return amount;
|
|
56
|
+
}
|
|
57
|
+
static async notarizeEarlyExit(activity, transaction) {
|
|
58
|
+
//decrement the 2nd and 3rd digits to fully deactivate (`cycle` activities use this command to fully exit after leg 1) (should result in `888000000000000`)
|
|
59
|
+
return await activity.store.collate(activity.context.metadata.jid, activity.metadata.aid, -11000000000000, this.getDimensionalAddress(activity), transaction);
|
|
60
|
+
}
|
|
61
|
+
static async notarizeEarlyCompletion(activity, transaction) {
|
|
62
|
+
//initialize both `possible` (1m) and `actualized` (1) zero dimension, while decrementing the 2nd
|
|
63
|
+
//3rd digit is optionally kept open if the activity might be used in a cycle
|
|
64
|
+
const decrement = activity.config.cycle
|
|
65
|
+
? 10000000000000
|
|
66
|
+
: 11000000000000;
|
|
67
|
+
return await activity.store.collate(activity.context.metadata.jid, activity.metadata.aid, 1000001 - decrement, this.getDimensionalAddress(activity), transaction);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* sets the synthetic inception key (in case of an overage occurs).
|
|
71
|
+
*/
|
|
72
|
+
static async notarizeInception(activity, guid, transaction) {
|
|
73
|
+
if (guid) {
|
|
74
|
+
await activity.store.collateSynthetic(activity.context.metadata.jid, guid, 1000000, transaction);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* ignore those ID collisions that are due to re-entry overages
|
|
79
|
+
*/
|
|
80
|
+
static async isInceptionOverage(activity, guid) {
|
|
81
|
+
if (guid) {
|
|
82
|
+
const amount = await activity.store.collateSynthetic(activity.context.metadata.jid, guid, 1000000);
|
|
83
|
+
return amount > 1000000;
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* verifies both the concrete and synthetic keys for the activity; concrete keys
|
|
89
|
+
* exist in the original model and are effectively the 'real' keys. In reality,
|
|
90
|
+
* hook activities are atomized during compilation to create a synthetic DAG that
|
|
91
|
+
* is used to track the status of the graph in a distributed environment. The
|
|
92
|
+
* synthetic key represents different dimensional realities and is used to
|
|
93
|
+
* track re-entry overages (it distinguishes between the original and re-entry).
|
|
94
|
+
* The essential challenge is: is this a re-entry that is purposeful in
|
|
95
|
+
* order to induce cycles, or is the re-entry due to a failure in the system?
|
|
96
|
+
*/
|
|
97
|
+
static async notarizeReentry(activity, guid, transaction) {
|
|
98
|
+
const jid = activity.context.metadata.jid;
|
|
99
|
+
const localMulti = transaction || activity.store.transact();
|
|
100
|
+
//increment by 1_000_000 (indicates re-entry and is used to drive the 'dimensional address' for adjacent activities (minus 1))
|
|
101
|
+
await activity.store.collate(jid, activity.metadata.aid, 1000000, this.getDimensionalAddress(activity, true), localMulti);
|
|
102
|
+
await activity.store.collateSynthetic(jid, guid, 1000000, localMulti);
|
|
103
|
+
const [_amountConcrete, _amountSynthetic] = await localMulti.exec();
|
|
104
|
+
const amountConcrete = Array.isArray(_amountConcrete)
|
|
105
|
+
? _amountConcrete[1]
|
|
106
|
+
: _amountConcrete;
|
|
107
|
+
const amountSynthetic = Array.isArray(_amountSynthetic)
|
|
108
|
+
? _amountSynthetic[1]
|
|
109
|
+
: _amountSynthetic;
|
|
110
|
+
this.verifyInteger(amountConcrete, 2, 'enter');
|
|
111
|
+
this.verifySyntheticInteger(amountSynthetic);
|
|
112
|
+
return amountConcrete;
|
|
113
|
+
}
|
|
114
|
+
static async notarizeContinuation(activity, transaction) {
|
|
115
|
+
//keep open; actualize the leg2 dimension (+1)
|
|
116
|
+
return await activity.store.collate(activity.context.metadata.jid, activity.metadata.aid, 1, this.getDimensionalAddress(activity), transaction);
|
|
117
|
+
}
|
|
118
|
+
static async notarizeCompletion(activity, transaction) {
|
|
119
|
+
//1) ALWAYS actualize leg2 dimension (+1)
|
|
120
|
+
//2) IF the activity is used in a cycle, don't close leg 2!
|
|
121
|
+
const decrement = activity.config.cycle ? 0 : 1000000000000;
|
|
122
|
+
return await activity.store.collate(activity.context.metadata.jid, activity.metadata.aid, 1 - decrement, this.getDimensionalAddress(activity), transaction);
|
|
123
|
+
}
|
|
124
|
+
static getDigitAtIndex(num, targetDigitIndex) {
|
|
125
|
+
const numStr = num.toString();
|
|
126
|
+
if (targetDigitIndex < 0 || targetDigitIndex >= numStr.length) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
const digit = parseInt(numStr[targetDigitIndex], 10);
|
|
130
|
+
return digit;
|
|
131
|
+
}
|
|
132
|
+
static getDimensionalIndex(num) {
|
|
133
|
+
const numStr = num.toString();
|
|
134
|
+
if (numStr.length < 9) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
const extractedStr = numStr.substring(3, 9);
|
|
138
|
+
const extractedInt = parseInt(extractedStr, 10);
|
|
139
|
+
return extractedInt - 1;
|
|
140
|
+
}
|
|
141
|
+
static isDuplicate(num, targetDigitIndex) {
|
|
142
|
+
return this.getDigitAtIndex(num, targetDigitIndex) < 8;
|
|
143
|
+
}
|
|
144
|
+
static isInactive(num) {
|
|
145
|
+
return this.getDigitAtIndex(num, 2) < 9;
|
|
146
|
+
}
|
|
147
|
+
static isPrimed(amount, leg) {
|
|
148
|
+
//activity entry is not allowed if paths not properly pre-set
|
|
149
|
+
if (leg == 1) {
|
|
150
|
+
return amount != -100000000000000;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
return (this.getDigitAtIndex(amount, 0) < 9 &&
|
|
154
|
+
this.getDigitAtIndex(amount, 1) < 9);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* During compilation, the graphs are compiled into structures necessary
|
|
159
|
+
* for distributed processing; these are referred to as 'synthetic DAGs',
|
|
160
|
+
* because they are not part of the original graph, but are used to track
|
|
161
|
+
* the status of the graph in a distributed environment. This check ensures
|
|
162
|
+
* that the 'synthetic key' is not a duplicate. (which is different than
|
|
163
|
+
* saying the 'key' is not a duplicate)
|
|
164
|
+
*/
|
|
165
|
+
static verifySyntheticInteger(amount) {
|
|
166
|
+
const samount = amount.toString();
|
|
167
|
+
const isCompletedValue = parseInt(samount[samount.length - 1], 10);
|
|
168
|
+
if (isCompletedValue > 0) {
|
|
169
|
+
//already done error (ack/delete clearly failed; this is a duplicate)
|
|
170
|
+
throw new errors_1.CollationError(amount, 2, 'enter', collator_1.CollationFaultType.INACTIVE);
|
|
171
|
+
}
|
|
172
|
+
else if (amount >= 2000000) {
|
|
173
|
+
//duplicate synthetic key (this is a duplicate job ID)
|
|
174
|
+
throw new errors_1.CollationError(amount, 2, 'enter', collator_1.CollationFaultType.DUPLICATE);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
static verifyInteger(amount, leg, stage) {
|
|
178
|
+
let faultType;
|
|
179
|
+
if (leg === 1 && stage === 'enter') {
|
|
180
|
+
if (!this.isPrimed(amount, 1)) {
|
|
181
|
+
faultType = collator_1.CollationFaultType.MISSING;
|
|
182
|
+
}
|
|
183
|
+
else if (this.isDuplicate(amount, 0)) {
|
|
184
|
+
faultType = collator_1.CollationFaultType.DUPLICATE;
|
|
185
|
+
}
|
|
186
|
+
else if (amount != 899000000000000) {
|
|
187
|
+
faultType = collator_1.CollationFaultType.INVALID;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else if (leg === 1 && stage === 'exit') {
|
|
191
|
+
if (amount === -10000000000000) {
|
|
192
|
+
faultType = collator_1.CollationFaultType.MISSING;
|
|
193
|
+
}
|
|
194
|
+
else if (this.isDuplicate(amount, 1)) {
|
|
195
|
+
faultType = collator_1.CollationFaultType.DUPLICATE;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else if (leg === 2 && stage === 'enter') {
|
|
199
|
+
if (!this.isPrimed(amount, 2)) {
|
|
200
|
+
faultType = collator_1.CollationFaultType.FORBIDDEN;
|
|
201
|
+
}
|
|
202
|
+
else if (this.isInactive(amount)) {
|
|
203
|
+
faultType = collator_1.CollationFaultType.INACTIVE;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (faultType) {
|
|
207
|
+
throw new errors_1.CollationError(amount, leg, stage, faultType);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
static getDimensionsById(ancestors, dad) {
|
|
211
|
+
//ancestors is an ordered list of all ancestors, starting with the trigger (['t1', 'a1', 'a2'])
|
|
212
|
+
//dad is the dimensional address of the ancestors list (',0,5,3')
|
|
213
|
+
//loop through the ancestors list and create a map of the ancestor to the dimensional address.
|
|
214
|
+
//return { 't1': ',0', 'a1': ',0,5', 'a1': ',0,5,3', $ADJACENT: ',0,5,3,0' };
|
|
215
|
+
// `adjacent` is a special key that is used to track the dimensional address of adjacent activities
|
|
216
|
+
const map = { $ADJACENT: `${dad},0` };
|
|
217
|
+
let dadStr = dad;
|
|
218
|
+
ancestors.reverse().forEach((ancestor) => {
|
|
219
|
+
map[ancestor] = dadStr;
|
|
220
|
+
dadStr = dadStr.substring(0, dadStr.lastIndexOf(','));
|
|
221
|
+
});
|
|
222
|
+
return map;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* All non-trigger activities are assigned a status seed by their parent
|
|
226
|
+
*/
|
|
227
|
+
static getSeed() {
|
|
228
|
+
return '999000000000000';
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* All trigger activities are assigned a status seed in a completed state
|
|
232
|
+
*/
|
|
233
|
+
static getTriggerSeed() {
|
|
234
|
+
return '888000001000001';
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* entry point for compiler-type activities. This is called by the compiler
|
|
238
|
+
* to bind the sorted activity IDs to the trigger activity. These are then used
|
|
239
|
+
* at runtime by the activities to track job/activity status.
|
|
240
|
+
* @param graphs
|
|
241
|
+
*/
|
|
242
|
+
static compile(graphs) {
|
|
243
|
+
CollatorService.bindAncestorArray(graphs);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* binds the ancestor array to each activity.
|
|
247
|
+
* Used in conjunction with the dimensional
|
|
248
|
+
* address (dad). If dad is `,0,1,0,0` and the
|
|
249
|
+
* ancestor array is `['t1', 'a1', 'a2']` for
|
|
250
|
+
* activity 'a3', then the SAVED DAD
|
|
251
|
+
* will always have the trailing
|
|
252
|
+
* 0's removed. This ensures that the addressing
|
|
253
|
+
* remains consistent even if the graph changes.
|
|
254
|
+
* id DAD SAVED DAD
|
|
255
|
+
* * t1 => ,0 => [empty]
|
|
256
|
+
* * a1 => ,0,1 => ,0,1
|
|
257
|
+
* * a2 => ,0,1,0 => ,0,1
|
|
258
|
+
* * a3 => ,0,1,0,0 => ,0,1
|
|
259
|
+
*
|
|
260
|
+
*/
|
|
261
|
+
static bindAncestorArray(graphs) {
|
|
262
|
+
graphs.forEach((graph) => {
|
|
263
|
+
const ancestors = {};
|
|
264
|
+
const startingNode = Object.keys(graph.activities).find((activity) => graph.activities[activity].type === 'trigger');
|
|
265
|
+
if (!startingNode) {
|
|
266
|
+
throw new Error('collator-trigger-activity-not-found');
|
|
267
|
+
}
|
|
268
|
+
const dfs = (node, parentList) => {
|
|
269
|
+
ancestors[node] = parentList;
|
|
270
|
+
graph.activities[node]['ancestors'] = parentList;
|
|
271
|
+
const transitions = graph.transitions?.[node] || [];
|
|
272
|
+
transitions.forEach((transition) => {
|
|
273
|
+
dfs(transition.to, [...parentList, node]);
|
|
274
|
+
});
|
|
275
|
+
};
|
|
276
|
+
// Start the DFS traversal
|
|
277
|
+
dfs(startingNode, []);
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* All activities exist on a dimensional plane. Zero
|
|
282
|
+
* is the default. A value of
|
|
283
|
+
* `AxY,0,0,0,0,1,0,0` would reflect that
|
|
284
|
+
* an ancestor activity was dimensionalized beyond
|
|
285
|
+
* the default.
|
|
286
|
+
*/
|
|
287
|
+
static getDimensionalSeed(index = 0) {
|
|
288
|
+
return `,${index}`;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
exports.CollatorService = CollatorService;
|
|
292
|
+
//max int digit count that supports `hincrby`
|
|
293
|
+
CollatorService.targetLength = 15;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { StoreService } from '../store';
|
|
2
|
+
import { HotMeshGraph, HotMeshManifest } from '../../types/hotmesh';
|
|
3
|
+
import { ProviderClient, ProviderTransaction } from '../../types/provider';
|
|
4
|
+
import { Symbols } from '../../types/serializer';
|
|
5
|
+
import { StreamService } from '../stream';
|
|
6
|
+
declare class Deployer {
|
|
7
|
+
manifest: HotMeshManifest | null;
|
|
8
|
+
store: StoreService<ProviderClient, ProviderTransaction> | null;
|
|
9
|
+
stream: StreamService<ProviderClient, ProviderTransaction> | null;
|
|
10
|
+
constructor(manifest: HotMeshManifest);
|
|
11
|
+
deploy(store: StoreService<ProviderClient, ProviderTransaction>, stream: StreamService<ProviderClient, ProviderTransaction>): Promise<void>;
|
|
12
|
+
getVID(): {
|
|
13
|
+
id: string;
|
|
14
|
+
version: string;
|
|
15
|
+
};
|
|
16
|
+
generateSymKeys(): Promise<void>;
|
|
17
|
+
bindSelf(consumes: Record<string, string[]>, produces: string[], activityId: string): void;
|
|
18
|
+
bindSymbols(startIndex: number, maxIndex: number, existingSymbols: Symbols, prefix: string, produces: string[]): Symbols;
|
|
19
|
+
copyJobSchemas(): void;
|
|
20
|
+
bindBackRefs(): void;
|
|
21
|
+
bindCycleTarget(): void;
|
|
22
|
+
convertTopicsToTypes(): void;
|
|
23
|
+
convertActivitiesToHooks(): void;
|
|
24
|
+
bindParents(): Promise<void>;
|
|
25
|
+
collectValues(schema: Record<string, any>, values: Set<string>): void;
|
|
26
|
+
traverse(obj: any, values: Set<string>): void;
|
|
27
|
+
generateSymVals(): Promise<void>;
|
|
28
|
+
resolveJobMapsPaths(): void;
|
|
29
|
+
resolveMappingDependencies(): void;
|
|
30
|
+
groupMappingRules(rules: string[]): Record<string, string[]>;
|
|
31
|
+
resolveMappableValue(mappable: string): [string, string];
|
|
32
|
+
deployActivitySchemas(): Promise<void>;
|
|
33
|
+
deploySubscriptions(): Promise<void>;
|
|
34
|
+
findTrigger(graph: HotMeshGraph): [string, Record<string, any>] | null;
|
|
35
|
+
deployTransitions(): Promise<void>;
|
|
36
|
+
deployHookPatterns(): Promise<void>;
|
|
37
|
+
deployConsumerGroups(): Promise<void>;
|
|
38
|
+
deployConsumerGroup(stream: string, group: string): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
export { Deployer };
|