@hotmeshio/hotmesh 0.12.1 → 0.14.0

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 (202) hide show
  1. package/README.md +18 -22
  2. package/build/modules/enums.d.ts +60 -5
  3. package/build/modules/enums.js +62 -7
  4. package/build/modules/errors.d.ts +15 -2
  5. package/build/modules/errors.js +17 -1
  6. package/build/modules/storage.d.ts +1 -0
  7. package/build/modules/storage.js +2 -1
  8. package/build/package.json +8 -2
  9. package/build/services/activities/activity/context.d.ts +22 -0
  10. package/build/services/activities/activity/context.js +76 -0
  11. package/build/services/activities/activity/index.d.ts +116 -0
  12. package/build/services/activities/activity/index.js +299 -0
  13. package/build/services/activities/activity/mapping.d.ts +12 -0
  14. package/build/services/activities/activity/mapping.js +63 -0
  15. package/build/services/activities/activity/process.d.ts +28 -0
  16. package/build/services/activities/activity/process.js +100 -0
  17. package/build/services/activities/activity/protocol.d.ts +39 -0
  18. package/build/services/activities/activity/protocol.js +151 -0
  19. package/build/services/activities/activity/state.d.ts +40 -0
  20. package/build/services/activities/activity/state.js +143 -0
  21. package/build/services/activities/activity/transition.d.ts +23 -0
  22. package/build/services/activities/activity/transition.js +71 -0
  23. package/build/services/activities/activity/verify.d.ts +22 -0
  24. package/build/services/activities/activity/verify.js +85 -0
  25. package/build/services/activities/await.d.ts +1 -4
  26. package/build/services/activities/await.js +2 -36
  27. package/build/services/activities/cycle.d.ts +1 -11
  28. package/build/services/activities/cycle.js +3 -46
  29. package/build/services/activities/hook.d.ts +2 -11
  30. package/build/services/activities/hook.js +30 -50
  31. package/build/services/activities/interrupt.d.ts +2 -4
  32. package/build/services/activities/interrupt.js +4 -38
  33. package/build/services/activities/signal.d.ts +1 -11
  34. package/build/services/activities/signal.js +3 -48
  35. package/build/services/activities/trigger.d.ts +1 -3
  36. package/build/services/activities/trigger.js +0 -3
  37. package/build/services/activities/worker.d.ts +3 -6
  38. package/build/services/activities/worker.js +4 -40
  39. package/build/services/connector/factory.d.ts +6 -0
  40. package/build/services/connector/factory.js +24 -0
  41. package/build/services/dba/index.d.ts +14 -4
  42. package/build/services/dba/index.js +57 -18
  43. package/build/services/durable/activity.d.ts +30 -0
  44. package/build/services/durable/activity.js +46 -0
  45. package/build/services/durable/client.d.ts +26 -31
  46. package/build/services/durable/client.js +26 -31
  47. package/build/services/durable/connection.d.ts +13 -7
  48. package/build/services/durable/connection.js +13 -7
  49. package/build/services/durable/exporter.d.ts +2 -2
  50. package/build/services/durable/exporter.js +27 -12
  51. package/build/services/durable/handle.d.ts +59 -41
  52. package/build/services/durable/handle.js +61 -41
  53. package/build/services/durable/index.d.ts +152 -283
  54. package/build/services/durable/index.js +161 -289
  55. package/build/services/durable/interceptor.d.ts +43 -33
  56. package/build/services/durable/interceptor.js +59 -39
  57. package/build/services/durable/schemas/factory.d.ts +2 -3
  58. package/build/services/durable/schemas/factory.js +180 -30
  59. package/build/services/durable/telemetry.d.ts +80 -0
  60. package/build/services/durable/telemetry.js +137 -0
  61. package/build/services/durable/worker.d.ts +100 -21
  62. package/build/services/durable/worker.js +314 -60
  63. package/build/services/durable/workflow/all.d.ts +1 -1
  64. package/build/services/durable/workflow/all.js +1 -1
  65. package/build/services/durable/workflow/cancellationScope.d.ts +104 -0
  66. package/build/services/durable/workflow/cancellationScope.js +139 -0
  67. package/build/services/durable/workflow/common.d.ts +5 -4
  68. package/build/services/durable/workflow/common.js +6 -1
  69. package/build/services/durable/workflow/{waitFor.d.ts → condition.d.ts} +9 -8
  70. package/build/services/durable/workflow/{waitFor.js → condition.js} +44 -11
  71. package/build/services/durable/workflow/continueAsNew.d.ts +65 -0
  72. package/build/services/durable/workflow/continueAsNew.js +92 -0
  73. package/build/services/durable/workflow/didRun.d.ts +2 -2
  74. package/build/services/durable/workflow/didRun.js +4 -4
  75. package/build/services/durable/workflow/enrich.d.ts +5 -0
  76. package/build/services/durable/workflow/enrich.js +5 -0
  77. package/build/services/durable/workflow/entityMethods.d.ts +7 -0
  78. package/build/services/durable/workflow/entityMethods.js +7 -0
  79. package/build/services/durable/workflow/execHook.js +3 -3
  80. package/build/services/durable/workflow/execHookBatch.js +2 -2
  81. package/build/services/durable/workflow/{execChild.d.ts → executeChild.d.ts} +4 -40
  82. package/build/services/durable/workflow/{execChild.js → executeChild.js} +36 -45
  83. package/build/services/durable/workflow/hook.d.ts +1 -1
  84. package/build/services/durable/workflow/hook.js +4 -3
  85. package/build/services/durable/workflow/index.d.ts +45 -50
  86. package/build/services/durable/workflow/index.js +46 -51
  87. package/build/services/durable/workflow/interruption.d.ts +7 -6
  88. package/build/services/durable/workflow/interruption.js +11 -7
  89. package/build/services/durable/workflow/patched.d.ts +72 -0
  90. package/build/services/durable/workflow/patched.js +110 -0
  91. package/build/services/durable/workflow/proxyActivities.d.ts +7 -7
  92. package/build/services/durable/workflow/proxyActivities.js +51 -15
  93. package/build/services/durable/workflow/searchMethods.d.ts +7 -0
  94. package/build/services/durable/workflow/searchMethods.js +7 -0
  95. package/build/services/durable/workflow/signal.d.ts +4 -4
  96. package/build/services/durable/workflow/signal.js +4 -4
  97. package/build/services/durable/workflow/{sleepFor.d.ts → sleep.d.ts} +7 -7
  98. package/build/services/durable/workflow/{sleepFor.js → sleep.js} +39 -10
  99. package/build/services/durable/workflow/terminate.d.ts +55 -0
  100. package/build/services/durable/workflow/{interrupt.js → terminate.js} +21 -21
  101. package/build/services/durable/workflow/trace.js +2 -2
  102. package/build/services/durable/workflow/uuid4.d.ts +14 -0
  103. package/build/services/durable/workflow/uuid4.js +39 -0
  104. package/build/services/durable/workflow/{context.d.ts → workflowInfo.d.ts} +5 -5
  105. package/build/services/durable/workflow/{context.js → workflowInfo.js} +7 -7
  106. package/build/services/engine/compiler.d.ts +19 -0
  107. package/build/services/engine/compiler.js +20 -0
  108. package/build/services/engine/completion.d.ts +46 -0
  109. package/build/services/engine/completion.js +145 -0
  110. package/build/services/engine/dispatch.d.ts +24 -0
  111. package/build/services/engine/dispatch.js +98 -0
  112. package/build/services/engine/index.d.ts +49 -81
  113. package/build/services/engine/index.js +175 -573
  114. package/build/services/engine/init.d.ts +42 -0
  115. package/build/services/engine/init.js +74 -0
  116. package/build/services/engine/pubsub.d.ts +50 -0
  117. package/build/services/engine/pubsub.js +118 -0
  118. package/build/services/engine/reporting.d.ts +20 -0
  119. package/build/services/engine/reporting.js +38 -0
  120. package/build/services/engine/schema.d.ts +23 -0
  121. package/build/services/engine/schema.js +62 -0
  122. package/build/services/engine/signal.d.ts +57 -0
  123. package/build/services/engine/signal.js +117 -0
  124. package/build/services/engine/state.d.ts +35 -0
  125. package/build/services/engine/state.js +61 -0
  126. package/build/services/engine/version.d.ts +31 -0
  127. package/build/services/engine/version.js +73 -0
  128. package/build/services/hotmesh/deployment.d.ts +21 -0
  129. package/build/services/hotmesh/deployment.js +25 -0
  130. package/build/services/hotmesh/index.d.ts +142 -533
  131. package/build/services/hotmesh/index.js +223 -674
  132. package/build/services/hotmesh/init.d.ts +42 -0
  133. package/build/services/hotmesh/init.js +93 -0
  134. package/build/services/hotmesh/jobs.d.ts +67 -0
  135. package/build/services/hotmesh/jobs.js +99 -0
  136. package/build/services/hotmesh/pubsub.d.ts +38 -0
  137. package/build/services/hotmesh/pubsub.js +54 -0
  138. package/build/services/hotmesh/quorum.d.ts +30 -0
  139. package/build/services/hotmesh/quorum.js +62 -0
  140. package/build/services/hotmesh/validation.d.ts +6 -0
  141. package/build/services/hotmesh/validation.js +28 -0
  142. package/build/services/quorum/index.js +1 -0
  143. package/build/services/router/consumption/index.d.ts +11 -5
  144. package/build/services/router/consumption/index.js +24 -17
  145. package/build/services/router/error-handling/index.d.ts +2 -2
  146. package/build/services/router/error-handling/index.js +14 -14
  147. package/build/services/router/index.d.ts +1 -1
  148. package/build/services/router/index.js +2 -2
  149. package/build/services/serializer/index.d.ts +22 -0
  150. package/build/services/serializer/index.js +39 -1
  151. package/build/services/store/index.d.ts +1 -0
  152. package/build/services/store/providers/postgres/exporter-sql.d.ts +2 -2
  153. package/build/services/store/providers/postgres/exporter-sql.js +4 -4
  154. package/build/services/store/providers/postgres/kvtables.js +7 -6
  155. package/build/services/store/providers/postgres/kvtypes/hash/basic.js +67 -52
  156. package/build/services/store/providers/postgres/kvtypes/hash/jsonb.js +87 -72
  157. package/build/services/store/providers/postgres/kvtypes/hash/udata.js +106 -79
  158. package/build/services/store/providers/postgres/kvtypes/hash/utils.d.ts +16 -0
  159. package/build/services/store/providers/postgres/kvtypes/hash/utils.js +29 -16
  160. package/build/services/store/providers/postgres/postgres.d.ts +1 -0
  161. package/build/services/store/providers/postgres/postgres.js +14 -4
  162. package/build/services/stream/factory.d.ts +3 -1
  163. package/build/services/stream/factory.js +2 -2
  164. package/build/services/stream/index.d.ts +1 -0
  165. package/build/services/stream/providers/nats/nats.d.ts +1 -0
  166. package/build/services/stream/providers/nats/nats.js +1 -0
  167. package/build/services/stream/providers/postgres/credentials.d.ts +56 -0
  168. package/build/services/stream/providers/postgres/credentials.js +129 -0
  169. package/build/services/stream/providers/postgres/kvtables.js +18 -0
  170. package/build/services/stream/providers/postgres/messages.js +7 -7
  171. package/build/services/stream/providers/postgres/notifications.js +16 -2
  172. package/build/services/stream/providers/postgres/postgres.d.ts +7 -0
  173. package/build/services/stream/providers/postgres/postgres.js +35 -4
  174. package/build/services/stream/providers/postgres/procedures.d.ts +21 -0
  175. package/build/services/stream/providers/postgres/procedures.js +213 -0
  176. package/build/services/stream/providers/postgres/secured.d.ts +34 -0
  177. package/build/services/stream/providers/postgres/secured.js +146 -0
  178. package/build/services/stream/providers/postgres/stats.d.ts +1 -0
  179. package/build/services/stream/providers/postgres/stats.js +1 -0
  180. package/build/services/stream/registry.d.ts +1 -1
  181. package/build/services/stream/registry.js +5 -2
  182. package/build/services/telemetry/index.d.ts +10 -1
  183. package/build/services/telemetry/index.js +40 -7
  184. package/build/services/worker/credentials.d.ts +51 -0
  185. package/build/services/worker/credentials.js +87 -0
  186. package/build/services/worker/index.d.ts +2 -2
  187. package/build/services/worker/index.js +7 -6
  188. package/build/types/codec.d.ts +84 -0
  189. package/build/types/codec.js +2 -0
  190. package/build/types/dba.d.ts +39 -3
  191. package/build/types/durable.d.ts +123 -25
  192. package/build/types/error.d.ts +10 -0
  193. package/build/types/exporter.d.ts +1 -1
  194. package/build/types/hotmesh.d.ts +67 -4
  195. package/build/types/index.d.ts +2 -1
  196. package/build/types/provider.d.ts +2 -2
  197. package/build/types/quorum.d.ts +35 -1
  198. package/build/types/stream.d.ts +12 -6
  199. package/package.json +8 -2
  200. package/build/services/activities/activity.d.ts +0 -192
  201. package/build/services/activities/activity.js +0 -786
  202. package/build/services/durable/workflow/interrupt.d.ts +0 -55
@@ -0,0 +1,42 @@
1
+ import { EngineService } from '../engine';
2
+ import { ILogger } from '../logger';
3
+ import { QuorumService } from '../quorum';
4
+ import { WorkerService } from '../worker';
5
+ import { HotMeshConfig } from '../../types/hotmesh';
6
+ import { ProviderConfig, ProvidersConfig } from '../../types/provider';
7
+ import { RetryPolicy } from '../../types/stream';
8
+ interface InitContext {
9
+ namespace: string;
10
+ appId: string;
11
+ guid: string;
12
+ engine: EngineService | null;
13
+ quorum: QuorumService | null;
14
+ workers: WorkerService[];
15
+ }
16
+ /**
17
+ * @private
18
+ */
19
+ export declare function initEngine(instance: InitContext, config: HotMeshConfig, logger: ILogger): Promise<void>;
20
+ /**
21
+ * @private
22
+ */
23
+ export declare function initQuorum(instance: InitContext, config: HotMeshConfig, engine: EngineService, logger: ILogger): Promise<void>;
24
+ /**
25
+ * @private
26
+ */
27
+ export declare function doWork(instance: InitContext, config: HotMeshConfig, logger: ILogger): Promise<void>;
28
+ /**
29
+ * Initialize task queue with proper precedence:
30
+ * 1. Use component-specific queue if set (engine/worker)
31
+ * 2. Use global config queue if set
32
+ * 3. Use default queue as fallback
33
+ * @private
34
+ */
35
+ export declare function initTaskQueue(componentQueue?: string, globalQueue?: string): string;
36
+ /**
37
+ * Apply retry policy to the stream connection within a ProviderConfig or ProvidersConfig.
38
+ * Handles both short-form (ProviderConfig) and long-form (ProvidersConfig) connection configs.
39
+ * @private
40
+ */
41
+ export declare function applyRetryPolicy(connection: ProviderConfig | ProvidersConfig, retry: RetryPolicy): void;
42
+ export {};
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyRetryPolicy = exports.initTaskQueue = exports.doWork = exports.initQuorum = exports.initEngine = void 0;
4
+ const factory_1 = require("../connector/factory");
5
+ const engine_1 = require("../engine");
6
+ const quorum_1 = require("../quorum");
7
+ const worker_1 = require("../worker");
8
+ const enums_1 = require("../../modules/enums");
9
+ /**
10
+ * @private
11
+ */
12
+ async function initEngine(instance, config, logger) {
13
+ if (config.engine) {
14
+ //connections that are 'readonly' transfer
15
+ //this property directly to the engine,
16
+ //and ALWAYS take precendence.
17
+ if (config.engine.connection.readonly) {
18
+ config.engine.readonly = true;
19
+ }
20
+ // Apply retry policy to stream connection if provided
21
+ if (config.engine.retry) {
22
+ applyRetryPolicy(config.engine.connection, config.engine.retry);
23
+ }
24
+ // Initialize task queue for engine
25
+ config.engine.taskQueue = initTaskQueue(config.engine.taskQueue, config.taskQueue);
26
+ await factory_1.ConnectorService.initClients(config.engine);
27
+ instance.engine = await engine_1.EngineService.init(instance.namespace, instance.appId, instance.guid, config, logger);
28
+ }
29
+ }
30
+ exports.initEngine = initEngine;
31
+ /**
32
+ * @private
33
+ */
34
+ async function initQuorum(instance, config, engine, logger) {
35
+ if (engine) {
36
+ instance.quorum = await quorum_1.QuorumService.init(instance.namespace, instance.appId, instance.guid, config, engine, logger);
37
+ }
38
+ }
39
+ exports.initQuorum = initQuorum;
40
+ /**
41
+ * @private
42
+ */
43
+ async function doWork(instance, config, logger) {
44
+ // Initialize task queues for workers
45
+ if (config.workers) {
46
+ for (const worker of config.workers) {
47
+ // Apply retry policy to stream connection if provided
48
+ if (worker.retry) {
49
+ applyRetryPolicy(worker.connection, worker.retry);
50
+ }
51
+ worker.taskQueue = initTaskQueue(worker.taskQueue, config.taskQueue);
52
+ }
53
+ }
54
+ instance.workers = await worker_1.WorkerService.init(instance.namespace, instance.appId, instance.guid, config, logger);
55
+ }
56
+ exports.doWork = doWork;
57
+ /**
58
+ * Initialize task queue with proper precedence:
59
+ * 1. Use component-specific queue if set (engine/worker)
60
+ * 2. Use global config queue if set
61
+ * 3. Use default queue as fallback
62
+ * @private
63
+ */
64
+ function initTaskQueue(componentQueue, globalQueue) {
65
+ // Component-specific queue takes precedence
66
+ if (componentQueue) {
67
+ return componentQueue;
68
+ }
69
+ // Global config queue is next
70
+ if (globalQueue) {
71
+ return globalQueue;
72
+ }
73
+ // Default queue as fallback
74
+ return enums_1.DEFAULT_TASK_QUEUE;
75
+ }
76
+ exports.initTaskQueue = initTaskQueue;
77
+ /**
78
+ * Apply retry policy to the stream connection within a ProviderConfig or ProvidersConfig.
79
+ * Handles both short-form (ProviderConfig) and long-form (ProvidersConfig) connection configs.
80
+ * @private
81
+ */
82
+ function applyRetryPolicy(connection, retry) {
83
+ // Check if this is ProvidersConfig (has 'stream' property)
84
+ if ('stream' in connection && connection.stream) {
85
+ // Long-form: apply to the stream sub-config
86
+ connection.stream.retry = retry;
87
+ }
88
+ else {
89
+ // Short-form: apply directly to the connection
90
+ connection.retry = retry;
91
+ }
92
+ }
93
+ exports.applyRetryPolicy = applyRetryPolicy;
@@ -0,0 +1,67 @@
1
+ import { EngineService } from '../engine';
2
+ import { JobData, JobOutput, JobStatus, JobInterruptOptions } from '../../types/job';
3
+ import { ExportOptions, JobExport } from '../../types/exporter';
4
+ import { StringAnyType, StringStringType } from '../../types/serializer';
5
+ import { JobStatsInput, GetStatsOptions, IdsResponse, StatsResponse } from '../../types/stats';
6
+ import { StreamCode, StreamStatus } from '../../types/stream';
7
+ interface JobsContext {
8
+ engine: EngineService | null;
9
+ }
10
+ /**
11
+ * Exports the full job state as a structured JSON object.
12
+ */
13
+ export declare function exportJob(instance: JobsContext, jobId: string, options?: ExportOptions): Promise<JobExport>;
14
+ /**
15
+ * Returns all raw key-value pairs for a job's HASH record.
16
+ */
17
+ export declare function getRaw(instance: JobsContext, jobId: string): Promise<StringStringType>;
18
+ /**
19
+ * Reporter-related method to get the status of a job.
20
+ * @private
21
+ */
22
+ export declare function getStats(instance: JobsContext, topic: string, query: JobStatsInput): Promise<StatsResponse>;
23
+ /**
24
+ * Returns the numeric status semaphore for a job.
25
+ */
26
+ export declare function getStatus(instance: JobsContext, jobId: string): Promise<JobStatus>;
27
+ /**
28
+ * Returns the structured job state (data and metadata) for a job.
29
+ */
30
+ export declare function getState(instance: JobsContext, topic: string, jobId: string): Promise<JobOutput>;
31
+ /**
32
+ * Returns specific searchable fields from a job's HASH record.
33
+ */
34
+ export declare function getQueryState(instance: JobsContext, jobId: string, fields: string[]): Promise<StringAnyType>;
35
+ /**
36
+ * @private
37
+ */
38
+ export declare function getIds(instance: JobsContext, topic: string, query: JobStatsInput, queryFacets?: string[]): Promise<IdsResponse>;
39
+ /**
40
+ * @private
41
+ */
42
+ export declare function resolveQuery(instance: JobsContext, topic: string, query: JobStatsInput): Promise<GetStatsOptions>;
43
+ /**
44
+ * Interrupts (terminates) an active workflow job.
45
+ */
46
+ export declare function interrupt(instance: JobsContext, topic: string, jobId: string, options?: JobInterruptOptions): Promise<string>;
47
+ /**
48
+ * Requests cooperative cancellation of an active workflow job.
49
+ * Writes a durable cancel marker to the job hash via the store.
50
+ * The workflow detects this at its next durable operation and
51
+ * throws CancelledFailure which can be caught for cleanup.
52
+ */
53
+ export declare function cancel(instance: JobsContext, jobId: string): Promise<void>;
54
+ /**
55
+ * Immediately deletes a completed job from the system.
56
+ */
57
+ export declare function scrub(instance: JobsContext, jobId: string): Promise<void>;
58
+ /**
59
+ * Sends a signal to a paused workflow, resuming its execution.
60
+ */
61
+ export declare function signal(instance: JobsContext, topic: string, data: JobData, status?: StreamStatus, code?: StreamCode): Promise<string>;
62
+ /**
63
+ * Fan-out variant of `signal()`.
64
+ * @private
65
+ */
66
+ export declare function signalAll(instance: JobsContext, hookTopic: string, data: JobData, query: JobStatsInput, queryFacets?: string[]): Promise<string[]>;
67
+ export {};
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.signalAll = exports.signal = exports.scrub = exports.cancel = exports.interrupt = exports.resolveQuery = exports.getIds = exports.getQueryState = exports.getState = exports.getStatus = exports.getStats = exports.getRaw = exports.exportJob = void 0;
4
+ /**
5
+ * Exports the full job state as a structured JSON object.
6
+ */
7
+ async function exportJob(instance, jobId, options = {}) {
8
+ return await instance.engine?.export(jobId, options);
9
+ }
10
+ exports.exportJob = exportJob;
11
+ /**
12
+ * Returns all raw key-value pairs for a job's HASH record.
13
+ */
14
+ async function getRaw(instance, jobId) {
15
+ return await instance.engine?.getRaw(jobId);
16
+ }
17
+ exports.getRaw = getRaw;
18
+ /**
19
+ * Reporter-related method to get the status of a job.
20
+ * @private
21
+ */
22
+ async function getStats(instance, topic, query) {
23
+ return await instance.engine?.getStats(topic, query);
24
+ }
25
+ exports.getStats = getStats;
26
+ /**
27
+ * Returns the numeric status semaphore for a job.
28
+ */
29
+ async function getStatus(instance, jobId) {
30
+ return instance.engine?.getStatus(jobId);
31
+ }
32
+ exports.getStatus = getStatus;
33
+ /**
34
+ * Returns the structured job state (data and metadata) for a job.
35
+ */
36
+ async function getState(instance, topic, jobId) {
37
+ return instance.engine?.getState(topic, jobId);
38
+ }
39
+ exports.getState = getState;
40
+ /**
41
+ * Returns specific searchable fields from a job's HASH record.
42
+ */
43
+ async function getQueryState(instance, jobId, fields) {
44
+ return await instance.engine?.getQueryState(jobId, fields);
45
+ }
46
+ exports.getQueryState = getQueryState;
47
+ /**
48
+ * @private
49
+ */
50
+ async function getIds(instance, topic, query, queryFacets = []) {
51
+ return await instance.engine?.getIds(topic, query, queryFacets);
52
+ }
53
+ exports.getIds = getIds;
54
+ /**
55
+ * @private
56
+ */
57
+ async function resolveQuery(instance, topic, query) {
58
+ return await instance.engine?.resolveQuery(topic, query);
59
+ }
60
+ exports.resolveQuery = resolveQuery;
61
+ /**
62
+ * Interrupts (terminates) an active workflow job.
63
+ */
64
+ async function interrupt(instance, topic, jobId, options = {}) {
65
+ return await instance.engine?.interrupt(topic, jobId, options);
66
+ }
67
+ exports.interrupt = interrupt;
68
+ /**
69
+ * Requests cooperative cancellation of an active workflow job.
70
+ * Writes a durable cancel marker to the job hash via the store.
71
+ * The workflow detects this at its next durable operation and
72
+ * throws CancelledFailure which can be caught for cleanup.
73
+ */
74
+ async function cancel(instance, jobId) {
75
+ await instance.engine?.store.setCancel(jobId, instance.engine.appId);
76
+ }
77
+ exports.cancel = cancel;
78
+ /**
79
+ * Immediately deletes a completed job from the system.
80
+ */
81
+ async function scrub(instance, jobId) {
82
+ await instance.engine?.scrub(jobId);
83
+ }
84
+ exports.scrub = scrub;
85
+ /**
86
+ * Sends a signal to a paused workflow, resuming its execution.
87
+ */
88
+ async function signal(instance, topic, data, status, code) {
89
+ return await instance.engine?.signal(topic, data, status, code);
90
+ }
91
+ exports.signal = signal;
92
+ /**
93
+ * Fan-out variant of `signal()`.
94
+ * @private
95
+ */
96
+ async function signalAll(instance, hookTopic, data, query, queryFacets = []) {
97
+ return await instance.engine?.signalAll(hookTopic, data, query, queryFacets);
98
+ }
99
+ exports.signalAll = signalAll;
@@ -0,0 +1,38 @@
1
+ import { EngineService } from '../engine';
2
+ import { JobState, JobData, JobOutput, ExtensionType } from '../../types/job';
3
+ import { JobMessageCallback } from '../../types/quorum';
4
+ import { StreamData, StreamDataResponse } from '../../types/stream';
5
+ interface PubSubContext {
6
+ engine: EngineService | null;
7
+ }
8
+ /**
9
+ * Publishes a message to a workflow topic, starting a new job.
10
+ * Returns the job ID immediately (fire-and-forget).
11
+ */
12
+ export declare function pub(instance: PubSubContext, topic: string, data?: JobData, context?: JobState, extended?: ExtensionType): Promise<string>;
13
+ /**
14
+ * Subscribes to all output and interim emissions from a specific workflow topic.
15
+ */
16
+ export declare function sub(instance: PubSubContext, topic: string, callback: JobMessageCallback): Promise<void>;
17
+ /**
18
+ * Unsubscribes from a single workflow topic previously registered with `sub()`.
19
+ */
20
+ export declare function unsub(instance: PubSubContext, topic: string): Promise<void>;
21
+ /**
22
+ * Subscribes to workflow emissions matching a wildcard pattern.
23
+ */
24
+ export declare function psub(instance: PubSubContext, wild: string, callback: JobMessageCallback): Promise<void>;
25
+ /**
26
+ * Unsubscribes from a wildcard pattern previously registered with `psub()`.
27
+ */
28
+ export declare function punsub(instance: PubSubContext, wild: string): Promise<void>;
29
+ /**
30
+ * Publishes a message to a workflow topic and blocks until the workflow completes.
31
+ */
32
+ export declare function pubsub(instance: PubSubContext, topic: string, data?: JobData, context?: JobState | null, timeout?: number): Promise<JobOutput>;
33
+ /**
34
+ * Adds a transition message to the workstream, resuming Leg 2 of a paused
35
+ * reentrant activity.
36
+ */
37
+ export declare function add(instance: PubSubContext, streamData: StreamData | StreamDataResponse): Promise<string>;
38
+ export {};
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.add = exports.pubsub = exports.punsub = exports.psub = exports.unsub = exports.sub = exports.pub = void 0;
4
+ /**
5
+ * Publishes a message to a workflow topic, starting a new job.
6
+ * Returns the job ID immediately (fire-and-forget).
7
+ */
8
+ async function pub(instance, topic, data = {}, context, extended) {
9
+ return await instance.engine?.pub(topic, data, context, extended);
10
+ }
11
+ exports.pub = pub;
12
+ /**
13
+ * Subscribes to all output and interim emissions from a specific workflow topic.
14
+ */
15
+ async function sub(instance, topic, callback) {
16
+ return await instance.engine?.sub(topic, callback);
17
+ }
18
+ exports.sub = sub;
19
+ /**
20
+ * Unsubscribes from a single workflow topic previously registered with `sub()`.
21
+ */
22
+ async function unsub(instance, topic) {
23
+ return await instance.engine?.unsub(topic);
24
+ }
25
+ exports.unsub = unsub;
26
+ /**
27
+ * Subscribes to workflow emissions matching a wildcard pattern.
28
+ */
29
+ async function psub(instance, wild, callback) {
30
+ return await instance.engine?.psub(wild, callback);
31
+ }
32
+ exports.psub = psub;
33
+ /**
34
+ * Unsubscribes from a wildcard pattern previously registered with `psub()`.
35
+ */
36
+ async function punsub(instance, wild) {
37
+ return await instance.engine?.punsub(wild);
38
+ }
39
+ exports.punsub = punsub;
40
+ /**
41
+ * Publishes a message to a workflow topic and blocks until the workflow completes.
42
+ */
43
+ async function pubsub(instance, topic, data = {}, context, timeout) {
44
+ return await instance.engine?.pubsub(topic, data, context, timeout);
45
+ }
46
+ exports.pubsub = pubsub;
47
+ /**
48
+ * Adds a transition message to the workstream, resuming Leg 2 of a paused
49
+ * reentrant activity.
50
+ */
51
+ async function add(instance, streamData) {
52
+ return (await instance.engine.add(streamData));
53
+ }
54
+ exports.add = add;
@@ -0,0 +1,30 @@
1
+ import { EngineService } from '../engine';
2
+ import { QuorumService } from '../quorum';
3
+ import { WorkerService } from '../worker';
4
+ import { QuorumMessage, QuorumMessageCallback, QuorumProfile, ThrottleOptions } from '../../types/quorum';
5
+ interface QuorumContext {
6
+ engine: EngineService | null;
7
+ quorum: QuorumService | null;
8
+ workers: WorkerService[];
9
+ }
10
+ /**
11
+ * Broadcasts a roll call across the mesh and collects responses.
12
+ */
13
+ export declare function rollCall(instance: QuorumContext, delay?: number): Promise<QuorumProfile[]>;
14
+ /**
15
+ * Broadcasts a throttle command to the mesh via the quorum channel.
16
+ */
17
+ export declare function throttle(instance: QuorumContext, options: ThrottleOptions): Promise<boolean>;
18
+ /**
19
+ * Publishes a message to every mesh member via the quorum channel.
20
+ */
21
+ export declare function pubQuorum(instance: QuorumContext, quorumMessage: QuorumMessage): Promise<boolean>;
22
+ /**
23
+ * Subscribes to the quorum channel.
24
+ */
25
+ export declare function subQuorum(instance: QuorumContext, callback: QuorumMessageCallback): Promise<void>;
26
+ /**
27
+ * Unsubscribes a callback previously registered with `subQuorum()`.
28
+ */
29
+ export declare function unsubQuorum(instance: QuorumContext, callback: QuorumMessageCallback): Promise<void>;
30
+ export {};
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unsubQuorum = exports.subQuorum = exports.pubQuorum = exports.throttle = exports.rollCall = void 0;
4
+ const enums_1 = require("../../modules/enums");
5
+ /**
6
+ * Broadcasts a roll call across the mesh and collects responses.
7
+ */
8
+ async function rollCall(instance, delay) {
9
+ return await instance.quorum?.rollCall(delay);
10
+ }
11
+ exports.rollCall = rollCall;
12
+ /**
13
+ * Broadcasts a throttle command to the mesh via the quorum channel.
14
+ */
15
+ async function throttle(instance, options) {
16
+ let throttleValue;
17
+ if (options.throttle === -1) {
18
+ throttleValue = enums_1.MAX_DELAY;
19
+ }
20
+ else {
21
+ throttleValue = options.throttle;
22
+ }
23
+ if (!Number.isInteger(throttleValue) ||
24
+ throttleValue < 0 ||
25
+ throttleValue > enums_1.MAX_DELAY) {
26
+ throw new Error(`Throttle must be a non-negative integer and not exceed ${enums_1.MAX_DELAY} ms; send -1 to throttle indefinitely`);
27
+ }
28
+ const throttleMessage = {
29
+ type: 'throttle',
30
+ throttle: throttleValue,
31
+ };
32
+ if (options.guid) {
33
+ throttleMessage.guid = options.guid;
34
+ }
35
+ if (options.topic !== undefined) {
36
+ throttleMessage.topic = options.topic;
37
+ }
38
+ await instance.engine.store.setThrottleRate(throttleMessage);
39
+ return await instance.quorum?.pub(throttleMessage);
40
+ }
41
+ exports.throttle = throttle;
42
+ /**
43
+ * Publishes a message to every mesh member via the quorum channel.
44
+ */
45
+ async function pubQuorum(instance, quorumMessage) {
46
+ return await instance.quorum?.pub(quorumMessage);
47
+ }
48
+ exports.pubQuorum = pubQuorum;
49
+ /**
50
+ * Subscribes to the quorum channel.
51
+ */
52
+ async function subQuorum(instance, callback) {
53
+ return await instance.quorum?.sub(callback);
54
+ }
55
+ exports.subQuorum = subQuorum;
56
+ /**
57
+ * Unsubscribes a callback previously registered with `subQuorum()`.
58
+ */
59
+ async function unsubQuorum(instance, callback) {
60
+ return await instance.quorum?.unsub(callback);
61
+ }
62
+ exports.unsubQuorum = unsubQuorum;
@@ -0,0 +1,6 @@
1
+ export declare function verifyAndSetNamespace(instance: {
2
+ namespace: string;
3
+ }, namespace?: string): void;
4
+ export declare function verifyAndSetAppId(instance: {
5
+ appId: string;
6
+ }, appId: string): void;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyAndSetAppId = exports.verifyAndSetNamespace = void 0;
4
+ const key_1 = require("../../modules/key");
5
+ function verifyAndSetNamespace(instance, namespace) {
6
+ if (!namespace) {
7
+ instance.namespace = key_1.HMNS;
8
+ }
9
+ else if (!namespace.match(/^[A-Za-z0-9-]+$/)) {
10
+ throw new Error(`config.namespace [${namespace}] is invalid`);
11
+ }
12
+ else {
13
+ instance.namespace = namespace;
14
+ }
15
+ }
16
+ exports.verifyAndSetNamespace = verifyAndSetNamespace;
17
+ function verifyAndSetAppId(instance, appId) {
18
+ if (!appId?.match(/^[A-Za-z0-9-]+$/)) {
19
+ throw new Error(`config.appId [${appId}] is invalid`);
20
+ }
21
+ else if (appId === 'a') {
22
+ throw new Error(`config.appId [${appId}] is reserved`);
23
+ }
24
+ else {
25
+ instance.appId = appId;
26
+ }
27
+ }
28
+ exports.verifyAndSetAppId = verifyAndSetAppId;
@@ -134,6 +134,7 @@ class QuorumService {
134
134
  app_id: this.appId,
135
135
  stream,
136
136
  counts: this.engine.router.counts,
137
+ error_count: this.engine.router.errorCount,
137
138
  timestamp: (0, utils_1.formatISODate)(new Date()),
138
139
  inited: this.engine.inited,
139
140
  throttle: this.engine.router.throttle,
@@ -15,12 +15,18 @@ export declare class ConsumptionManager<S extends StreamService<ProviderClient,
15
15
  private reclaimCount;
16
16
  private appId;
17
17
  private role;
18
- private errorCount;
19
- private counts;
20
- private hasReachedMaxBackoff;
18
+ /**
19
+ * Consumption stats are written directly to the parent Router so
20
+ * they are visible in quorum rollcall profiles.
21
+ */
22
+ private get errorCount();
23
+ private set errorCount(value);
24
+ private get counts();
25
+ private get hasReachedMaxBackoff();
26
+ private set hasReachedMaxBackoff(value);
21
27
  private router;
22
- private retryPolicy;
23
- constructor(stream: S, logger: ILogger, throttleManager: ThrottleManager, errorHandler: ErrorHandler, lifecycleManager: LifecycleManager<S>, reclaimDelay: number, reclaimCount: number, appId: string, role: any, router: any, retryPolicy?: import('../../../types/stream').RetryPolicy);
28
+ private retry;
29
+ constructor(stream: S, logger: ILogger, throttleManager: ThrottleManager, errorHandler: ErrorHandler, lifecycleManager: LifecycleManager<S>, reclaimDelay: number, reclaimCount: number, appId: string, role: any, router: any, retry?: import('../../../types/stream').RetryPolicy);
24
30
  createGroup(stream: string, group: string): Promise<void>;
25
31
  publishMessage(topic: string, streamData: StreamData | StreamDataResponse, transaction?: ProviderTransaction): Promise<string | ProviderTransaction>;
26
32
  consumeMessages(stream: string, group: string, consumer: string, callback: (streamData: StreamData) => Promise<StreamDataResponse | void>): Promise<void>;