@hotmeshio/hotmesh 0.1.14 → 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +623 -209
  2. package/build/index.d.ts +14 -3
  3. package/build/index.js +17 -4
  4. package/build/modules/enums.d.ts +12 -12
  5. package/build/modules/enums.js +15 -25
  6. package/build/modules/errors.d.ts +16 -16
  7. package/build/modules/errors.js +28 -28
  8. package/build/modules/key.d.ts +0 -37
  9. package/build/modules/key.js +4 -45
  10. package/build/modules/utils.d.ts +7 -15
  11. package/build/modules/utils.js +21 -44
  12. package/build/package.json +18 -15
  13. package/build/services/activities/activity.d.ts +0 -31
  14. package/build/services/activities/activity.js +1 -50
  15. package/build/services/activities/await.js +0 -4
  16. package/build/services/activities/cycle.d.ts +0 -7
  17. package/build/services/activities/cycle.js +1 -16
  18. package/build/services/activities/hook.d.ts +0 -6
  19. package/build/services/activities/hook.js +2 -12
  20. package/build/services/activities/interrupt.js +0 -8
  21. package/build/services/activities/signal.d.ts +0 -6
  22. package/build/services/activities/signal.js +0 -15
  23. package/build/services/activities/trigger.d.ts +4 -5
  24. package/build/services/activities/trigger.js +22 -16
  25. package/build/services/activities/worker.js +0 -4
  26. package/build/services/collator/index.d.ts +0 -70
  27. package/build/services/collator/index.js +1 -91
  28. package/build/services/compiler/deployer.js +6 -38
  29. package/build/services/compiler/index.d.ts +0 -15
  30. package/build/services/compiler/index.js +0 -20
  31. package/build/services/compiler/validator.d.ts +0 -3
  32. package/build/services/compiler/validator.js +0 -25
  33. package/build/services/connector/clients/ioredis.js +0 -2
  34. package/build/services/connector/clients/redis.js +0 -2
  35. package/build/services/connector/index.js +0 -2
  36. package/build/services/engine/index.d.ts +1 -10
  37. package/build/services/engine/index.js +1 -48
  38. package/build/services/exporter/index.d.ts +0 -27
  39. package/build/services/exporter/index.js +0 -33
  40. package/build/services/hotmesh/index.d.ts +8 -4
  41. package/build/services/hotmesh/index.js +20 -19
  42. package/build/services/logger/index.js +0 -2
  43. package/build/services/mapper/index.d.ts +0 -14
  44. package/build/services/mapper/index.js +0 -14
  45. package/build/services/meshcall/index.d.ts +21 -0
  46. package/build/services/meshcall/index.js +202 -0
  47. package/build/services/meshcall/schemas/factory.d.ts +2 -0
  48. package/build/services/meshcall/schemas/factory.js +179 -0
  49. package/build/services/meshdata/index.d.ts +75 -0
  50. package/build/services/meshdata/index.js +541 -0
  51. package/build/services/meshflow/client.d.ts +18 -0
  52. package/build/services/{durable → meshflow}/client.js +9 -40
  53. package/build/services/{durable → meshflow}/connection.d.ts +2 -1
  54. package/build/services/{durable → meshflow}/connection.js +1 -0
  55. package/build/services/meshflow/exporter.d.ts +29 -0
  56. package/build/services/{durable → meshflow}/exporter.js +0 -29
  57. package/build/services/meshflow/handle.d.ts +22 -0
  58. package/build/services/{durable → meshflow}/handle.js +0 -46
  59. package/build/services/meshflow/index.d.ts +17 -0
  60. package/build/services/meshflow/index.js +23 -0
  61. package/build/services/meshflow/schemas/factory.d.ts +4 -0
  62. package/build/services/{durable → meshflow}/schemas/factory.js +3 -31
  63. package/build/services/meshflow/search.d.ts +23 -0
  64. package/build/services/{durable → meshflow}/search.js +0 -99
  65. package/build/services/{durable → meshflow}/worker.d.ts +3 -2
  66. package/build/services/{durable → meshflow}/worker.js +23 -39
  67. package/build/services/meshflow/workflow.d.ts +27 -0
  68. package/build/services/{durable → meshflow}/workflow.js +27 -169
  69. package/build/services/pipe/functions/date.d.ts +0 -7
  70. package/build/services/pipe/functions/date.js +0 -7
  71. package/build/services/pipe/functions/math.js +0 -2
  72. package/build/services/pipe/index.d.ts +0 -15
  73. package/build/services/pipe/index.js +2 -23
  74. package/build/services/quorum/index.d.ts +1 -7
  75. package/build/services/quorum/index.js +0 -21
  76. package/build/services/reporter/index.d.ts +0 -5
  77. package/build/services/reporter/index.js +0 -9
  78. package/build/services/router/index.d.ts +0 -9
  79. package/build/services/router/index.js +2 -30
  80. package/build/services/serializer/index.js +6 -23
  81. package/build/services/store/cache.d.ts +0 -19
  82. package/build/services/store/cache.js +0 -19
  83. package/build/services/store/clients/ioredis.d.ts +0 -6
  84. package/build/services/store/clients/ioredis.js +0 -7
  85. package/build/services/store/clients/redis.d.ts +0 -6
  86. package/build/services/store/clients/redis.js +0 -6
  87. package/build/services/store/index.d.ts +0 -55
  88. package/build/services/store/index.js +14 -87
  89. package/build/services/stream/clients/ioredis.js +1 -4
  90. package/build/services/task/index.d.ts +0 -9
  91. package/build/services/task/index.js +0 -31
  92. package/build/services/telemetry/index.d.ts +0 -7
  93. package/build/services/telemetry/index.js +1 -13
  94. package/build/services/worker/index.d.ts +1 -4
  95. package/build/services/worker/index.js +0 -6
  96. package/build/types/activity.d.ts +0 -81
  97. package/build/types/error.d.ts +5 -5
  98. package/build/types/exporter.d.ts +1 -14
  99. package/build/types/hotmesh.d.ts +4 -12
  100. package/build/types/hotmesh.js +0 -3
  101. package/build/types/index.d.ts +5 -3
  102. package/build/types/index.js +1 -1
  103. package/build/types/job.d.ts +1 -95
  104. package/build/types/meshcall.d.ts +54 -0
  105. package/build/types/meshdata.d.ts +59 -0
  106. package/build/types/meshdata.js +2 -0
  107. package/build/types/meshflow.d.ts +202 -0
  108. package/build/types/meshflow.js +2 -0
  109. package/build/types/pipe.d.ts +0 -65
  110. package/build/types/quorum.d.ts +0 -12
  111. package/build/types/redis.d.ts +0 -6
  112. package/build/types/stream.d.ts +0 -59
  113. package/build/types/stream.js +0 -4
  114. package/index.ts +22 -3
  115. package/package.json +18 -15
  116. package/typedoc.json +38 -0
  117. package/types/error.ts +5 -5
  118. package/types/exporter.ts +1 -1
  119. package/types/hotmesh.ts +3 -2
  120. package/types/index.ts +25 -7
  121. package/types/job.ts +19 -1
  122. package/types/meshcall.ts +123 -0
  123. package/types/meshdata.ts +273 -0
  124. package/types/{durable.ts → meshflow.ts} +33 -9
  125. package/build/services/durable/client.d.ts +0 -49
  126. package/build/services/durable/exporter.d.ts +0 -51
  127. package/build/services/durable/handle.d.ts +0 -58
  128. package/build/services/durable/index.d.ts +0 -19
  129. package/build/services/durable/index.js +0 -25
  130. package/build/services/durable/schemas/factory.d.ts +0 -33
  131. package/build/services/durable/search.d.ts +0 -120
  132. package/build/services/durable/workflow.d.ts +0 -143
  133. package/build/types/durable.d.ts +0 -467
  134. /package/build/types/{durable.js → meshcall.js} +0 -0
@@ -8,13 +8,7 @@ declare class Signal extends Activity {
8
8
  process(): Promise<string>;
9
9
  mapSignalData(): Record<string, any>;
10
10
  mapResolverData(): Record<string, any>;
11
- /**
12
- * The signal activity will hook one
13
- */
14
11
  hookOne(): Promise<string>;
15
- /**
16
- * The signal activity will hook all paused jobs that share the same job key.
17
- */
18
12
  hookAll(): Promise<string[]>;
19
13
  }
20
14
  export { Signal };
@@ -11,7 +11,6 @@ class Signal extends activity_1.Activity {
11
11
  constructor(config, data, metadata, hook, engine, context) {
12
12
  super(config, data, metadata, hook, engine, context);
13
13
  }
14
- //******** LEG 1 ENTRY ********//
15
14
  async process() {
16
15
  this.logger.debug('signal-process', {
17
16
  jid: this.context.metadata.jid,
@@ -23,7 +22,6 @@ class Signal extends activity_1.Activity {
23
22
  await this.verifyEntry();
24
23
  telemetry = new telemetry_1.TelemetryService(this.engine.appId, this.config, this.metadata, this.context);
25
24
  telemetry.startActivitySpan(this.leg);
26
- //save state and notarize early completion (signals only run leg1)
27
25
  const multi = this.store.getMulti();
28
26
  this.adjacencyList = await this.filterAdjacent();
29
27
  this.mapOutputData();
@@ -32,14 +30,12 @@ class Signal extends activity_1.Activity {
32
30
  await collator_1.CollatorService.notarizeEarlyCompletion(this, multi);
33
31
  await this.setStatus(this.adjacencyList.length - 1, multi);
34
32
  const multiResponse = (await multi.exec());
35
- //todo: this should execute BEFORE the status is decremented
36
33
  if (this.config.subtype === 'all') {
37
34
  await this.hookAll();
38
35
  }
39
36
  else {
40
37
  await this.hookOne();
41
38
  }
42
- //transition to adjacent activities
43
39
  const jobStatus = this.resolveStatus(multiResponse);
44
40
  const attrs = { 'app.job.jss': jobStatus };
45
41
  const messageIds = await this.transition(this.adjacencyList, jobStatus);
@@ -90,9 +86,6 @@ class Signal extends activity_1.Activity {
90
86
  return mapper.mapRules();
91
87
  }
92
88
  }
93
- /**
94
- * The signal activity will hook one
95
- */
96
89
  async hookOne() {
97
90
  const topic = pipe_1.Pipe.resolve(this.config.topic, this.context);
98
91
  const signalInputData = this.mapSignalData();
@@ -100,23 +93,15 @@ class Signal extends activity_1.Activity {
100
93
  const code = pipe_1.Pipe.resolve(this.config.code, this.context);
101
94
  return await this.engine.hook(topic, signalInputData, status, code);
102
95
  }
103
- /**
104
- * The signal activity will hook all paused jobs that share the same job key.
105
- */
106
96
  async hookAll() {
107
- //prep 1) generate `input signal data` (essentially the webhook payload)
108
97
  const signalInputData = this.mapSignalData();
109
- //prep 2) generate data that resolves the job key (per the YAML config)
110
98
  const keyResolverData = this.mapResolverData();
111
99
  if (this.config.scrub) {
112
- //self-clean the indexes upon use if configured
113
100
  keyResolverData.scrub = true;
114
101
  }
115
- //prep 3) jobKeys can contain multiple indexes (per the YAML config)
116
102
  const key_name = pipe_1.Pipe.resolve(this.config.key_name, this.context);
117
103
  const key_value = pipe_1.Pipe.resolve(this.config.key_value, this.context);
118
104
  const indexQueryFacets = [`${key_name}:${key_value}`];
119
- //execute: `hookAll` will now resume all paused jobs that share the same job key
120
105
  return await this.engine.hookAll(this.config.topic, signalInputData, keyResolverData, indexQueryFacets);
121
106
  }
122
107
  }
@@ -1,12 +1,15 @@
1
1
  import { EngineService } from '../engine';
2
2
  import { ActivityData, ActivityMetadata, ActivityType, TriggerActivity } from '../../types/activity';
3
- import { JobState, ExtensionType } from '../../types/job';
3
+ import { JobState, ExtensionType, JobStatus } from '../../types/job';
4
4
  import { RedisMulti } from '../../types/redis';
5
+ import { StringScalarType } from '../../types/serializer';
5
6
  import { Activity } from './activity';
6
7
  declare class Trigger extends Activity {
7
8
  config: TriggerActivity;
8
9
  constructor(config: ActivityType, data: ActivityData, metadata: ActivityMetadata, hook: ActivityData | null, engine: EngineService, context?: JobState);
9
10
  process(options?: ExtensionType): Promise<string>;
11
+ transitionAndLogAdjacent(options: ExtensionType, jobStatus: JobStatus, attrs: StringScalarType): Promise<void>;
12
+ initStatus(options: ExtensionType, count: number): number;
10
13
  setExpired(seconds: number, multi: RedisMulti): Promise<void>;
11
14
  safeKey(key: string): string;
12
15
  bindSearchData(options?: ExtensionType): void;
@@ -22,10 +25,6 @@ declare class Trigger extends Activity {
22
25
  resolveJobId(context: Partial<JobState>): string;
23
26
  resolveJobKey(context: Partial<JobState>): string;
24
27
  setStateNX(status?: number): Promise<void>;
25
- /**
26
- * Registers this job as a dependent of the parent job; when the
27
- * parent job is interrupted, this job will be interrupted
28
- */
29
28
  registerJobDependency(multi?: RedisMulti): Promise<void>;
30
29
  setStats(multi?: RedisMulti): Promise<void>;
31
30
  }
@@ -25,9 +25,10 @@ class Trigger extends activity_1.Activity {
25
25
  telemetry.startJobSpan();
26
26
  telemetry.startActivitySpan(this.leg);
27
27
  this.mapJobData();
28
- await this.setStateNX(options?.pending ? -1 : undefined);
29
28
  this.adjacencyList = await this.filterAdjacent();
30
- await this.setStatus(options?.pending ? -1 : this.adjacencyList.length);
29
+ const initialStatus = this.initStatus(options, this.adjacencyList.length);
30
+ await this.setStateNX(initialStatus);
31
+ await this.setStatus(initialStatus);
31
32
  this.bindSearchData(options);
32
33
  this.bindMarkerData(options);
33
34
  const multi = this.store.getMulti();
@@ -40,20 +41,12 @@ class Trigger extends activity_1.Activity {
40
41
  await this.registerJobDependency(multi);
41
42
  }
42
43
  await multi.exec();
43
- //if the parent (spawner) chose not to await,
44
- // emit the job_id as the data payload { job_id }
45
44
  this.execAdjacentParent();
46
45
  telemetry.mapActivityAttributes();
47
46
  const jobStatus = Number(this.context.metadata.js);
48
47
  telemetry.setJobAttributes({ 'app.job.jss': jobStatus });
49
48
  const attrs = { 'app.job.jss': jobStatus };
50
- //todo: enable resume from pending state
51
- if (jobStatus !== -1) {
52
- const messageIds = await this.transition(this.adjacencyList, jobStatus);
53
- if (messageIds.length) {
54
- attrs['app.activity.mids'] = messageIds.join(',');
55
- }
56
- }
49
+ await this.transitionAndLogAdjacent(options, jobStatus, attrs);
57
50
  telemetry.setActivityAttributes(attrs);
58
51
  return this.context.metadata.jid;
59
52
  }
@@ -77,6 +70,23 @@ class Trigger extends activity_1.Activity {
77
70
  });
78
71
  }
79
72
  }
73
+ async transitionAndLogAdjacent(options = {}, jobStatus, attrs) {
74
+ if (isNaN(options.pending)) {
75
+ const messageIds = await this.transition(this.adjacencyList, jobStatus);
76
+ if (messageIds.length) {
77
+ attrs['app.activity.mids'] = messageIds.join(',');
78
+ }
79
+ }
80
+ }
81
+ initStatus(options = {}, count) {
82
+ if (options.pending) {
83
+ return -1;
84
+ }
85
+ else if (options.statusThreshold) {
86
+ return 1000000 - options.statusThreshold + count;
87
+ }
88
+ return count;
89
+ }
80
90
  async setExpired(seconds, multi) {
81
91
  await this.store.expireJob(this.context.metadata.jid, seconds, multi);
82
92
  }
@@ -179,7 +189,7 @@ class Trigger extends activity_1.Activity {
179
189
  },
180
190
  };
181
191
  this.context['$self'] = this.context[this.metadata.aid];
182
- this.context['$job'] = this.context; //NEVER call STRINGIFY! (circular)
192
+ this.context['$job'] = this.context;
183
193
  }
184
194
  bindJobMetadataPaths() {
185
195
  return serializer_1.MDATA_SYMBOLS.JOB.KEYS.map((key) => `metadata/${key}`);
@@ -207,10 +217,6 @@ class Trigger extends activity_1.Activity {
207
217
  throw new errors_1.DuplicateJobError(jobId);
208
218
  }
209
219
  }
210
- /**
211
- * Registers this job as a dependent of the parent job; when the
212
- * parent job is interrupted, this job will be interrupted
213
- */
214
220
  async registerJobDependency(multi) {
215
221
  const depKey = this.config.stats?.parent ?? this.context.metadata.pj;
216
222
  let resolvedDepKey = depKey ? pipe_1.Pipe.resolve(depKey, this.context) : '';
@@ -11,7 +11,6 @@ class Worker extends activity_1.Activity {
11
11
  constructor(config, data, metadata, hook, engine, context) {
12
12
  super(config, data, metadata, hook, engine, context);
13
13
  }
14
- //******** INITIAL ENTRY POINT (A) ********//
15
14
  async process() {
16
15
  this.logger.debug('worker-process', {
17
16
  jid: this.context.metadata.jid,
@@ -24,15 +23,12 @@ class Worker extends activity_1.Activity {
24
23
  telemetry = new telemetry_1.TelemetryService(this.engine.appId, this.config, this.metadata, this.context);
25
24
  telemetry.startActivitySpan(this.leg);
26
25
  this.mapInputData();
27
- //save state and authorize reentry
28
26
  const multi = this.store.getMulti();
29
- //todo: await this.registerTimeout();
30
27
  const messageId = await this.execActivity(multi);
31
28
  await collator_1.CollatorService.authorizeReentry(this, multi);
32
29
  await this.setState(multi);
33
30
  await this.setStatus(0, multi);
34
31
  const multiResponse = (await multi.exec());
35
- //telemetry
36
32
  telemetry.mapActivityAttributes();
37
33
  const jobStatus = this.resolveStatus(multiResponse);
38
34
  telemetry.setActivityAttributes({
@@ -6,40 +6,13 @@ import { Activity } from '../activities/activity';
6
6
  import { Cycle } from '../activities/cycle';
7
7
  declare class CollatorService {
8
8
  static targetLength: number;
9
- /**
10
- * Upon re/entry, verify that the job status is active
11
- */
12
9
  static assertJobActive(status: number, jobId: string, activityId: string, threshold?: number): void;
13
- /**
14
- * returns the dimensional address (dad) for the target; due
15
- * to the nature of the notary system, the dad for leg 2 entry
16
- * must target the `0` index while leg 2 exit must target the
17
- * current index (0)
18
- */
19
10
  static getDimensionalAddress(activity: Activity, isEntry?: boolean): Record<string, string>;
20
- /**
21
- * resolves the dimensional address for the
22
- * ancestor in the graph to go back to. this address
23
- * is determined by trimming the last digits from
24
- * the `dad` (including the target).
25
- * the target activity index is then set to `0`, so that
26
- * the origin node can be queried for approval/entry.
27
- */
28
11
  static resolveReentryDimension(activity: Cycle): string;
29
12
  static notarizeEntry(activity: Activity, multi?: RedisMulti): Promise<number>;
30
13
  static authorizeReentry(activity: Activity, multi?: RedisMulti): Promise<number>;
31
14
  static notarizeEarlyExit(activity: Activity, multi?: RedisMulti): Promise<number>;
32
15
  static notarizeEarlyCompletion(activity: Activity, multi?: RedisMulti): Promise<number>;
33
- /**
34
- * verifies both the concrete and synthetic keys for the activity; concrete keys
35
- * exist in the original model and are effectively the 'real' keys. In reality,
36
- * hook activities are atomized during compilation to create a synthetic DAG that
37
- * is used to track the status of the graph in a distributed environment. The
38
- * synthetic key represents different dimensional realities and is used to
39
- * track re-entry overages (it distinguishes between the original and re-entry).
40
- * The essential challenge is: is this a re-entry that is purposeful in
41
- * order to induce cycles, or is the re-entry due to a failure in the system?
42
- */
43
16
  static notarizeReentry(activity: Activity, guid: string, multi?: RedisMulti): Promise<number>;
44
17
  static notarizeContinuation(activity: Activity, multi?: RedisMulti): Promise<number>;
45
18
  static notarizeCompletion(activity: Activity, multi?: RedisMulti): Promise<number>;
@@ -48,56 +21,13 @@ declare class CollatorService {
48
21
  static isDuplicate(num: number, targetDigitIndex: number): boolean;
49
22
  static isInactive(num: number): boolean;
50
23
  static isPrimed(amount: number, leg: ActivityDuplex): boolean;
51
- /**
52
- * During compilation, the graphs are compiled into structures necessary
53
- * for distributed processing; these are referred to as 'synthetic DAGs',
54
- * because they are not part of the original graph, but are used to track
55
- * the status of the graph in a distributed environment. This check ensures
56
- * that the 'synthetic key' is not a duplicate. (which is different than
57
- * saying the 'key' is not a duplicate)
58
- */
59
24
  static verifySyntheticInteger(amount: number): void;
60
25
  static verifyInteger(amount: number, leg: ActivityDuplex, stage: CollationStage): void;
61
26
  static getDimensionsById(ancestors: string[], dad: string): Record<string, string>;
62
- /**
63
- * All non-trigger activities are assigned a status seed by their parent
64
- */
65
27
  static getSeed(): string;
66
- /**
67
- * All trigger activities are assigned a status seed in a completed state
68
- */
69
28
  static getTriggerSeed(): string;
70
- /**
71
- * entry point for compiler-type activities. This is called by the compiler
72
- * to bind the sorted activity IDs to the trigger activity. These are then used
73
- * at runtime by the activities to track job/activity status.
74
- * @param graphs
75
- */
76
29
  static compile(graphs: HotMeshGraph[]): void;
77
- /**
78
- * binds the ancestor array to each activity.
79
- * Used in conjunction with the dimensional
80
- * address (dad). If dad is `,0,1,0,0` and the
81
- * ancestor array is `['t1', 'a1', 'a2']` for
82
- * activity 'a3', then the SAVED DAD
83
- * will always have the trailing
84
- * 0's removed. This ensures that the addressing
85
- * remains consistent even if the graph changes.
86
- * id DAD SAVED DAD
87
- * * t1 => ,0 => [empty]
88
- * * a1 => ,0,1 => ,0,1
89
- * * a2 => ,0,1,0 => ,0,1
90
- * * a3 => ,0,1,0,0 => ,0,1
91
- *
92
- */
93
30
  static bindAncestorArray(graphs: HotMeshGraph[]): void;
94
- /**
95
- * All activities exist on a dimensional plane. Zero
96
- * is the default. A value of
97
- * `AxY,0,0,0,0,1,0,0` would reflect that
98
- * an ancestor activity was dimensionalized beyond
99
- * the default.
100
- */
101
31
  static getDimensionalSeed(index?: number): string;
102
32
  }
103
33
  export { CollatorService };
@@ -4,20 +4,11 @@ exports.CollatorService = void 0;
4
4
  const errors_1 = require("../../modules/errors");
5
5
  const collator_1 = require("../../types/collator");
6
6
  class CollatorService {
7
- /**
8
- * Upon re/entry, verify that the job status is active
9
- */
10
7
  static assertJobActive(status, jobId, activityId, threshold = 0) {
11
8
  if (status <= threshold) {
12
9
  throw new errors_1.InactiveJobError(jobId, status, activityId);
13
10
  }
14
11
  }
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
12
  static getDimensionalAddress(activity, isEntry = false) {
22
13
  let dad = activity.context.metadata.dad || activity.metadata.dad;
23
14
  if (isEntry && dad && activity.leg === 2) {
@@ -25,61 +16,36 @@ class CollatorService {
25
16
  }
26
17
  return CollatorService.getDimensionsById([...activity.config.ancestors, activity.metadata.aid], dad);
27
18
  }
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
19
  static resolveReentryDimension(activity) {
37
20
  const targetActivityId = activity.config.ancestor;
38
21
  const ancestors = activity.config.ancestors;
39
22
  const ancestorIndex = ancestors.indexOf(targetActivityId);
40
- const dimensions = activity.metadata.dad.split(','); //e.g., `,0,0,1,0`
23
+ const dimensions = activity.metadata.dad.split(',');
41
24
  dimensions.length = ancestorIndex + 1;
42
25
  dimensions.push('0');
43
26
  return dimensions.join(',');
44
27
  }
45
28
  static async notarizeEntry(activity, multi) {
46
- //decrement by -100_000_000_000_000
47
29
  const amount = await activity.store.collate(activity.context.metadata.jid, activity.metadata.aid, -100000000000000, this.getDimensionalAddress(activity), multi);
48
30
  this.verifyInteger(amount, 1, 'enter');
49
31
  return amount;
50
32
  }
51
33
  static async authorizeReentry(activity, multi) {
52
- //set second digit to 8, allowing for re-entry
53
- //decrement by -10_000_000_000_000
54
34
  const amount = await activity.store.collate(activity.context.metadata.jid, activity.metadata.aid, -10000000000000, this.getDimensionalAddress(activity), multi);
55
35
  return amount;
56
36
  }
57
37
  static async notarizeEarlyExit(activity, multi) {
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
38
  return await activity.store.collate(activity.context.metadata.jid, activity.metadata.aid, -11000000000000, this.getDimensionalAddress(activity), multi);
60
39
  }
61
40
  static async notarizeEarlyCompletion(activity, multi) {
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
41
  const decrement = activity.config.cycle
65
42
  ? 10000000000000
66
43
  : 11000000000000;
67
44
  return await activity.store.collate(activity.context.metadata.jid, activity.metadata.aid, 1000001 - decrement, this.getDimensionalAddress(activity), multi);
68
45
  }
69
- /**
70
- * verifies both the concrete and synthetic keys for the activity; concrete keys
71
- * exist in the original model and are effectively the 'real' keys. In reality,
72
- * hook activities are atomized during compilation to create a synthetic DAG that
73
- * is used to track the status of the graph in a distributed environment. The
74
- * synthetic key represents different dimensional realities and is used to
75
- * track re-entry overages (it distinguishes between the original and re-entry).
76
- * The essential challenge is: is this a re-entry that is purposeful in
77
- * order to induce cycles, or is the re-entry due to a failure in the system?
78
- */
79
46
  static async notarizeReentry(activity, guid, multi) {
80
47
  const jid = activity.context.metadata.jid;
81
48
  const localMulti = multi || activity.store.getMulti();
82
- //increment by 1_000_000 (indicates re-entry and is used to drive the 'dimensional address' for adjacent activities (minus 1))
83
49
  await activity.store.collate(jid, activity.metadata.aid, 1000000, this.getDimensionalAddress(activity, true), localMulti);
84
50
  await activity.store.collateSynthetic(jid, guid, 1000000, localMulti);
85
51
  const [_amountConcrete, _amountSynthetic] = await localMulti.exec();
@@ -94,12 +60,9 @@ class CollatorService {
94
60
  return amountConcrete;
95
61
  }
96
62
  static async notarizeContinuation(activity, multi) {
97
- //keep open; actualize the leg2 dimension (+1)
98
63
  return await activity.store.collate(activity.context.metadata.jid, activity.metadata.aid, 1, this.getDimensionalAddress(activity), multi);
99
64
  }
100
65
  static async notarizeCompletion(activity, multi) {
101
- //1) ALWAYS actualize leg2 dimension (+1)
102
- //2) IF the activity is used in a cycle, don't close leg 2!
103
66
  const decrement = activity.config.cycle ? 0 : 1000000000000;
104
67
  return await activity.store.collate(activity.context.metadata.jid, activity.metadata.aid, 1 - decrement, this.getDimensionalAddress(activity), multi);
105
68
  }
@@ -127,7 +90,6 @@ class CollatorService {
127
90
  return this.getDigitAtIndex(num, 2) < 9;
128
91
  }
129
92
  static isPrimed(amount, leg) {
130
- //activity entry is not allowed if paths not properly pre-set
131
93
  if (leg == 1) {
132
94
  return amount != -100000000000000;
133
95
  }
@@ -136,23 +98,13 @@ class CollatorService {
136
98
  this.getDigitAtIndex(amount, 1) < 9);
137
99
  }
138
100
  }
139
- /**
140
- * During compilation, the graphs are compiled into structures necessary
141
- * for distributed processing; these are referred to as 'synthetic DAGs',
142
- * because they are not part of the original graph, but are used to track
143
- * the status of the graph in a distributed environment. This check ensures
144
- * that the 'synthetic key' is not a duplicate. (which is different than
145
- * saying the 'key' is not a duplicate)
146
- */
147
101
  static verifySyntheticInteger(amount) {
148
102
  const samount = amount.toString();
149
103
  const isCompletedValue = parseInt(samount[samount.length - 1], 10);
150
104
  if (isCompletedValue > 0) {
151
- //already done error (ack/delete clearly failed; this is a duplicate)
152
105
  throw new errors_1.CollationError(amount, 2, 'enter', collator_1.CollationFaultType.INACTIVE);
153
106
  }
154
107
  else if (amount >= 2000000) {
155
- //duplicate synthetic key (todo: need to resolve/fix this!!)
156
108
  throw new errors_1.CollationError(amount, 2, 'enter', collator_1.CollationFaultType.DUPLICATE);
157
109
  }
158
110
  }
@@ -190,11 +142,6 @@ class CollatorService {
190
142
  }
191
143
  }
192
144
  static getDimensionsById(ancestors, dad) {
193
- //ancestors is an ordered list of all ancestors, starting with the trigger (['t1', 'a1', 'a2'])
194
- //dad is the dimensional address of the ancestors list (',0,5,3')
195
- //loop through the ancestors list and create a map of the ancestor to the dimensional address.
196
- //return { 't1': ',0', 'a1': ',0,5', 'a1': ',0,5,3', $ADJACENT: ',0,5,3,0' };
197
- // `adjacent` is a special key that is used to track the dimensional address of adjacent activities
198
145
  const map = { $ADJACENT: `${dad},0` };
199
146
  let dadStr = dad;
200
147
  ancestors.reverse().forEach((ancestor) => {
@@ -203,43 +150,15 @@ class CollatorService {
203
150
  });
204
151
  return map;
205
152
  }
206
- /**
207
- * All non-trigger activities are assigned a status seed by their parent
208
- */
209
153
  static getSeed() {
210
154
  return '999000000000000';
211
155
  }
212
- /**
213
- * All trigger activities are assigned a status seed in a completed state
214
- */
215
156
  static getTriggerSeed() {
216
157
  return '888000001000001';
217
158
  }
218
- /**
219
- * entry point for compiler-type activities. This is called by the compiler
220
- * to bind the sorted activity IDs to the trigger activity. These are then used
221
- * at runtime by the activities to track job/activity status.
222
- * @param graphs
223
- */
224
159
  static compile(graphs) {
225
160
  CollatorService.bindAncestorArray(graphs);
226
161
  }
227
- /**
228
- * binds the ancestor array to each activity.
229
- * Used in conjunction with the dimensional
230
- * address (dad). If dad is `,0,1,0,0` and the
231
- * ancestor array is `['t1', 'a1', 'a2']` for
232
- * activity 'a3', then the SAVED DAD
233
- * will always have the trailing
234
- * 0's removed. This ensures that the addressing
235
- * remains consistent even if the graph changes.
236
- * id DAD SAVED DAD
237
- * * t1 => ,0 => [empty]
238
- * * a1 => ,0,1 => ,0,1
239
- * * a2 => ,0,1,0 => ,0,1
240
- * * a3 => ,0,1,0,0 => ,0,1
241
- *
242
- */
243
162
  static bindAncestorArray(graphs) {
244
163
  graphs.forEach((graph) => {
245
164
  const ancestors = {};
@@ -255,21 +174,12 @@ class CollatorService {
255
174
  dfs(transition.to, [...parentList, node]);
256
175
  });
257
176
  };
258
- // Start the DFS traversal
259
177
  dfs(startingNode, []);
260
178
  });
261
179
  }
262
- /**
263
- * All activities exist on a dimensional plane. Zero
264
- * is the default. A value of
265
- * `AxY,0,0,0,0,1,0,0` would reflect that
266
- * an ancestor activity was dimensionalized beyond
267
- * the default.
268
- */
269
180
  static getDimensionalSeed(index = 0) {
270
181
  return `,${index}`;
271
182
  }
272
183
  }
273
184
  exports.CollatorService = CollatorService;
274
- //max int digit count that supports `hincrby`
275
185
  CollatorService.targetLength = 15;