@gravito/flux 3.0.3 → 4.0.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.
package/dist/bun.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkZE2RDS47cjs = require('./chunk-ZE2RDS47.cjs');
3
+ var _chunkOAJWPPYGcjs = require('./chunk-OAJWPPYG.cjs');
4
4
 
5
5
 
6
- exports.BunSQLiteStorage = _chunkZE2RDS47cjs.BunSQLiteStorage;
6
+ exports.BunSQLiteStorage = _chunkOAJWPPYGcjs.BunSQLiteStorage;
7
7
  //# sourceMappingURL=bun.cjs.map
package/dist/bun.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  BunSQLiteStorage
3
- } from "./chunk-EZGSU6AW.js";
3
+ } from "./chunk-UZKSACBE.js";
4
4
  export {
5
5
  BunSQLiteStorage
6
6
  };
@@ -1,117 +1,17 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9;
2
2
 
3
- var _chunkZE2RDS47cjs = require('./chunk-ZE2RDS47.cjs');
4
3
 
5
- // src/errors.ts
6
- var FluxErrorCode = /* @__PURE__ */ ((FluxErrorCode2) => {
7
- FluxErrorCode2["WORKFLOW_NOT_FOUND"] = "WORKFLOW_NOT_FOUND";
8
- FluxErrorCode2["WORKFLOW_INVALID_INPUT"] = "WORKFLOW_INVALID_INPUT";
9
- FluxErrorCode2["WORKFLOW_DEFINITION_CHANGED"] = "WORKFLOW_DEFINITION_CHANGED";
10
- FluxErrorCode2["WORKFLOW_NAME_MISMATCH"] = "WORKFLOW_NAME_MISMATCH";
11
- FluxErrorCode2["INVALID_STATE_TRANSITION"] = "INVALID_STATE_TRANSITION";
12
- FluxErrorCode2["WORKFLOW_NOT_SUSPENDED"] = "WORKFLOW_NOT_SUSPENDED";
13
- FluxErrorCode2["INVALID_STEP_INDEX"] = "INVALID_STEP_INDEX";
14
- FluxErrorCode2["STEP_TIMEOUT"] = "STEP_TIMEOUT";
15
- FluxErrorCode2["STEP_NOT_FOUND"] = "STEP_NOT_FOUND";
16
- FluxErrorCode2["CONCURRENT_MODIFICATION"] = "CONCURRENT_MODIFICATION";
17
- FluxErrorCode2["EMPTY_WORKFLOW"] = "EMPTY_WORKFLOW";
18
- FluxErrorCode2["NO_RECOVERY_ACTION"] = "NO_RECOVERY_ACTION";
19
- FluxErrorCode2["INVALID_JSON_POINTER"] = "INVALID_JSON_POINTER";
20
- FluxErrorCode2["INVALID_PATH_TRAVERSAL"] = "INVALID_PATH_TRAVERSAL";
21
- FluxErrorCode2["CANNOT_REPLACE_ROOT"] = "CANNOT_REPLACE_ROOT";
22
- FluxErrorCode2["CANNOT_REMOVE_ROOT"] = "CANNOT_REMOVE_ROOT";
23
- return FluxErrorCode2;
24
- })(FluxErrorCode || {});
25
- var FluxError = class extends Error {
26
- /**
27
- * Creates a new FluxError.
28
- *
29
- * @param message - Human-readable error description.
30
- * @param code - Machine-readable error code.
31
- * @param context - Additional metadata related to the error.
32
- */
33
- constructor(message, code, context) {
34
- super(message);
35
- this.code = code;
36
- this.context = context;
37
- this.name = "FluxError";
38
- }
39
- };
40
- function workflowNotFound(id) {
41
- return new FluxError(`Workflow not found: ${id}`, "WORKFLOW_NOT_FOUND" /* WORKFLOW_NOT_FOUND */, {
42
- workflowId: id
43
- });
44
- }
45
- function invalidStateTransition(from, to) {
46
- return new FluxError(
47
- `Invalid state transition: ${from} \u2192 ${to}`,
48
- "INVALID_STATE_TRANSITION" /* INVALID_STATE_TRANSITION */,
49
- { from, to }
50
- );
51
- }
52
- function invalidInput(workflowName) {
53
- return new FluxError(
54
- `Invalid input for workflow "${workflowName}"`,
55
- "WORKFLOW_INVALID_INPUT" /* WORKFLOW_INVALID_INPUT */,
56
- { workflowName }
57
- );
58
- }
59
- function workflowNameMismatch(expected, received) {
60
- return new FluxError(
61
- `Workflow name mismatch: ${received} !== ${expected}`,
62
- "WORKFLOW_NAME_MISMATCH" /* WORKFLOW_NAME_MISMATCH */,
63
- { expected, received }
64
- );
65
- }
66
- function workflowDefinitionChanged() {
67
- return new FluxError(
68
- "Workflow definition changed; operation is not safe",
69
- "WORKFLOW_DEFINITION_CHANGED" /* WORKFLOW_DEFINITION_CHANGED */
70
- );
71
- }
72
- function workflowNotSuspended(status) {
73
- return new FluxError(
74
- `Workflow is not suspended (status: ${status})`,
75
- "WORKFLOW_NOT_SUSPENDED" /* WORKFLOW_NOT_SUSPENDED */,
76
- { status }
77
- );
78
- }
79
- function stepNotFound(step) {
80
- return new FluxError(`Step not found: ${step}`, "STEP_NOT_FOUND" /* STEP_NOT_FOUND */, { step });
81
- }
82
- function invalidStepIndex(index) {
83
- return new FluxError(`Invalid step index: ${index}`, "INVALID_STEP_INDEX" /* INVALID_STEP_INDEX */, { index });
84
- }
85
- function emptyWorkflow(workflowName) {
86
- return new FluxError(`Workflow "${workflowName}" has no steps`, "EMPTY_WORKFLOW" /* EMPTY_WORKFLOW */, {
87
- workflowName
88
- });
89
- }
90
- function noRecoveryAction(stepName) {
91
- return new FluxError(
92
- `No recovery action registered for step: ${stepName}`,
93
- "NO_RECOVERY_ACTION" /* NO_RECOVERY_ACTION */,
94
- { stepName }
95
- );
96
- }
97
- function invalidJsonPointer(path) {
98
- return new FluxError(`Invalid JSON Pointer: ${path}`, "INVALID_JSON_POINTER" /* INVALID_JSON_POINTER */, {
99
- path
100
- });
101
- }
102
- function invalidPathTraversal(segment, current) {
103
- return new FluxError(
104
- `Cannot access property '${segment}' on ${current}`,
105
- "INVALID_PATH_TRAVERSAL" /* INVALID_PATH_TRAVERSAL */,
106
- { segment, currentType: typeof current }
107
- );
108
- }
109
- function cannotReplaceRoot() {
110
- return new FluxError("Cannot replace root object", "CANNOT_REPLACE_ROOT" /* CANNOT_REPLACE_ROOT */);
111
- }
112
- function cannotRemoveRoot() {
113
- return new FluxError("Cannot remove root object", "CANNOT_REMOVE_ROOT" /* CANNOT_REMOVE_ROOT */);
114
- }
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+ var _chunkOAJWPPYGcjs = require('./chunk-OAJWPPYG.cjs');
115
15
 
116
16
  // src/builder/WorkflowBuilder.ts
117
17
  var WorkflowBuilder = (_class = class {
@@ -244,7 +144,7 @@ var WorkflowBuilder = (_class = class {
244
144
  */
245
145
  build() {
246
146
  if (this._steps.length === 0) {
247
- throw emptyWorkflow(this._name);
147
+ throw _chunkOAJWPPYGcjs.emptyWorkflow.call(void 0, this._name);
248
148
  }
249
149
  return {
250
150
  name: this._name,
@@ -713,7 +613,7 @@ var StateMachine = (_class3 = class extends EventTarget {constructor(...args2) {
713
613
  */
714
614
  transition(to) {
715
615
  if (!this.canTransition(to)) {
716
- throw invalidStateTransition(this._status, to);
616
+ throw _chunkOAJWPPYGcjs.invalidStateTransition.call(void 0, this._status, to);
717
617
  }
718
618
  const from = this._status;
719
619
  this._status = to;
@@ -1522,14 +1422,14 @@ function resolveDefinition(workflow) {
1522
1422
  function resolveStartIndex(definition, fromStep, fallback) {
1523
1423
  if (typeof fromStep === "number") {
1524
1424
  if (fromStep < 0 || fromStep >= definition.steps.length) {
1525
- throw invalidStepIndex(fromStep);
1425
+ throw _chunkOAJWPPYGcjs.invalidStepIndex.call(void 0, fromStep);
1526
1426
  }
1527
1427
  return fromStep;
1528
1428
  }
1529
1429
  if (typeof fromStep === "string") {
1530
1430
  const index = definition.steps.findIndex((step) => step.name === fromStep);
1531
1431
  if (index === -1) {
1532
- throw stepNotFound(fromStep);
1432
+ throw _chunkOAJWPPYGcjs.stepNotFound.call(void 0, fromStep);
1533
1433
  }
1534
1434
  return index;
1535
1435
  }
@@ -1585,7 +1485,7 @@ async function persistContext(ctx, storage, contextManager, definitionVersion) {
1585
1485
  const state = contextManager.toState(ctx);
1586
1486
  const stored = await storage.load(state.id);
1587
1487
  if (stored && stored.version !== state.version) {
1588
- throw new FluxError(
1488
+ throw new (0, _chunkOAJWPPYGcjs.FluxError)(
1589
1489
  "Concurrent modification detected",
1590
1490
  "CONCURRENT_MODIFICATION" /* CONCURRENT_MODIFICATION */
1591
1491
  );
@@ -1860,7 +1760,7 @@ var RecoveryManager = (_class6 = class {constructor() { _class6.prototype.__init
1860
1760
  async executeRecovery(stepName) {
1861
1761
  const action = this.actions.get(stepName);
1862
1762
  if (!action) {
1863
- throw noRecoveryAction(stepName);
1763
+ throw _chunkOAJWPPYGcjs.noRecoveryAction.call(void 0, stepName);
1864
1764
  }
1865
1765
  if (action.type === "manual") {
1866
1766
  await action.handler();
@@ -2657,7 +2557,7 @@ var FluxEngine = class {
2657
2557
  async execute(workflow, input) {
2658
2558
  const definition = resolveDefinition(workflow);
2659
2559
  if (definition.validateInput && !definition.validateInput(input)) {
2660
- throw invalidInput(definition.name);
2560
+ throw _chunkOAJWPPYGcjs.invalidInput.call(void 0, definition.name);
2661
2561
  }
2662
2562
  let ctx = this.contextManager.create(
2663
2563
  definition.name,
@@ -2701,10 +2601,10 @@ var FluxEngine = class {
2701
2601
  if (!state) {
2702
2602
  return null;
2703
2603
  }
2704
- throw workflowNameMismatch(definition.name, state.name);
2604
+ throw _chunkOAJWPPYGcjs.workflowNameMismatch.call(void 0, definition.name, state.name);
2705
2605
  }
2706
2606
  if (state.history.length !== definition.steps.length) {
2707
- throw workflowDefinitionChanged();
2607
+ throw _chunkOAJWPPYGcjs.workflowDefinitionChanged.call(void 0, );
2708
2608
  }
2709
2609
  if (state.definitionVersion && definition.version && state.definitionVersion !== definition.version) {
2710
2610
  _optionalChain([this, 'access', _109 => _109.config, 'access', _110 => _110.logger, 'optionalAccess', _111 => _111.warn, 'call', _112 => _112(
@@ -2724,10 +2624,10 @@ var FluxEngine = class {
2724
2624
  const definition = resolveDefinition(workflow);
2725
2625
  const state = await this.storage.load(workflowId);
2726
2626
  if (!state) {
2727
- throw workflowNotFound(workflowId);
2627
+ throw _chunkOAJWPPYGcjs.workflowNotFound.call(void 0, workflowId);
2728
2628
  }
2729
2629
  if (state.status !== "suspended") {
2730
- throw workflowNotSuspended(state.status);
2630
+ throw _chunkOAJWPPYGcjs.workflowNotSuspended.call(void 0, state.status);
2731
2631
  }
2732
2632
  let ctx = this.contextManager.restore(
2733
2633
  state
@@ -2736,7 +2636,7 @@ var FluxEngine = class {
2736
2636
  const exec = ctx.history[idx];
2737
2637
  if (!exec || exec.status !== "suspended" || exec.waitingFor !== signalName) {
2738
2638
  const isSuspended = _optionalChain([exec, 'optionalAccess', _114 => _114.status]) === "suspended";
2739
- throw new FluxError(
2639
+ throw new (0, _chunkOAJWPPYGcjs.FluxError)(
2740
2640
  isSuspended ? `Workflow waiting for signal "${exec.waitingFor}", received "${signalName}"` : "Workflow state invalid: no suspended step found",
2741
2641
  isSuspended ? "INVALID_STATE_TRANSITION" /* INVALID_STATE_TRANSITION */ : "STEP_NOT_FOUND" /* STEP_NOT_FOUND */
2742
2642
  );
@@ -2770,10 +2670,10 @@ var FluxEngine = class {
2770
2670
  if (!state) {
2771
2671
  return null;
2772
2672
  }
2773
- throw workflowNameMismatch(definition.name, state.name);
2673
+ throw _chunkOAJWPPYGcjs.workflowNameMismatch.call(void 0, definition.name, state.name);
2774
2674
  }
2775
2675
  if (state.history.length !== definition.steps.length) {
2776
- throw workflowDefinitionChanged();
2676
+ throw _chunkOAJWPPYGcjs.workflowDefinitionChanged.call(void 0, );
2777
2677
  }
2778
2678
  let ctx = this.contextManager.restore(
2779
2679
  state
@@ -2796,7 +2696,7 @@ var FluxEngine = class {
2796
2696
  async saveState(state) {
2797
2697
  const stored = await this.storage.load(state.id);
2798
2698
  if (stored && stored.version !== state.version) {
2799
- throw new FluxError(
2699
+ throw new (0, _chunkOAJWPPYGcjs.FluxError)(
2800
2700
  "Concurrent modification detected",
2801
2701
  "CONCURRENT_MODIFICATION" /* CONCURRENT_MODIFICATION */
2802
2702
  );
@@ -3096,8 +2996,10 @@ var PostgreSQLStorage = (_class7 = class {
3096
2996
  }, _class7);
3097
2997
  function validateSqlIdentifier(value, field) {
3098
2998
  if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(value)) {
3099
- throw new Error(
3100
- `Invalid ${field}: "${value}". Only letters, numbers, and underscores are allowed.`
2999
+ throw new (0, _chunkOAJWPPYGcjs.FluxError)(
3000
+ `Invalid ${field}: "${value}". Only letters, numbers, and underscores are allowed.`,
3001
+ "WORKFLOW_INVALID_INPUT" /* WORKFLOW_INVALID_INPUT */,
3002
+ { field, value }
3101
3003
  );
3102
3004
  }
3103
3005
  return value;
@@ -3484,7 +3386,7 @@ var OrbitFlux = class _OrbitFlux {
3484
3386
  if (typeof storage === "string") {
3485
3387
  switch (storage) {
3486
3388
  case "sqlite":
3487
- storageAdapter = new (0, _chunkZE2RDS47cjs.BunSQLiteStorage)({ path: dbPath });
3389
+ storageAdapter = new (0, _chunkOAJWPPYGcjs.BunSQLiteStorage)({ path: dbPath });
3488
3390
  break;
3489
3391
  default:
3490
3392
  storageAdapter = new MemoryStorage();
@@ -3523,6 +3425,16 @@ var OrbitFlux = class _OrbitFlux {
3523
3425
  };
3524
3426
  this.engine = new FluxEngine(engineConfig);
3525
3427
  core.container.instance(exposeAs, this.engine);
3428
+ const health = core.container.make("health");
3429
+ if (health) {
3430
+ const engine = this.engine;
3431
+ health.register("flux", async () => ({
3432
+ status: engine ? "healthy" : "unhealthy",
3433
+ details: {
3434
+ storage: typeof storage === "string" ? storage : "custom"
3435
+ }
3436
+ }));
3437
+ }
3526
3438
  core.logger.info(
3527
3439
  `[OrbitFlux] Initialized (Storage: ${typeof storage === "string" ? storage : "custom"})`
3528
3440
  );
@@ -3566,21 +3478,5 @@ var OrbitFlux = class _OrbitFlux {
3566
3478
 
3567
3479
 
3568
3480
 
3569
-
3570
-
3571
-
3572
-
3573
-
3574
-
3575
-
3576
-
3577
-
3578
-
3579
-
3580
-
3581
-
3582
-
3583
-
3584
-
3585
- exports.FluxErrorCode = FluxErrorCode; exports.FluxError = FluxError; exports.workflowNotFound = workflowNotFound; exports.invalidStateTransition = invalidStateTransition; exports.invalidInput = invalidInput; exports.workflowNameMismatch = workflowNameMismatch; exports.workflowDefinitionChanged = workflowDefinitionChanged; exports.workflowNotSuspended = workflowNotSuspended; exports.stepNotFound = stepNotFound; exports.invalidStepIndex = invalidStepIndex; exports.emptyWorkflow = emptyWorkflow; exports.noRecoveryAction = noRecoveryAction; exports.invalidJsonPointer = invalidJsonPointer; exports.invalidPathTraversal = invalidPathTraversal; exports.cannotReplaceRoot = cannotReplaceRoot; exports.cannotRemoveRoot = cannotRemoveRoot; exports.WorkflowBuilder = WorkflowBuilder; exports.createWorkflow = createWorkflow; exports.BatchExecutor = BatchExecutor; exports.ContextManager = ContextManager; exports.StateMachine = StateMachine; exports.CronTrigger = CronTrigger; exports.MemoryStorage = MemoryStorage; exports.StepExecutor = StepExecutor; exports.FluxEngine = FluxEngine; exports.PostgreSQLStorage = PostgreSQLStorage; exports.JsonFileTraceSink = JsonFileTraceSink; exports.MemoryLockProvider = MemoryLockProvider; exports.RedisLockProvider = RedisLockProvider; exports.FluxConsoleLogger = FluxConsoleLogger; exports.FluxSilentLogger = FluxSilentLogger; exports.OrbitFlux = OrbitFlux;
3586
- //# sourceMappingURL=chunk-DN7SIQ34.cjs.map
3481
+ exports.WorkflowBuilder = WorkflowBuilder; exports.createWorkflow = createWorkflow; exports.BatchExecutor = BatchExecutor; exports.ContextManager = ContextManager; exports.StateMachine = StateMachine; exports.CronTrigger = CronTrigger; exports.MemoryStorage = MemoryStorage; exports.StepExecutor = StepExecutor; exports.FluxEngine = FluxEngine; exports.PostgreSQLStorage = PostgreSQLStorage; exports.JsonFileTraceSink = JsonFileTraceSink; exports.MemoryLockProvider = MemoryLockProvider; exports.RedisLockProvider = RedisLockProvider; exports.FluxConsoleLogger = FluxConsoleLogger; exports.FluxSilentLogger = FluxSilentLogger; exports.OrbitFlux = OrbitFlux;
3482
+ //# sourceMappingURL=chunk-AVWZYY7U.cjs.map