• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tabkram / execution-engine / 14387781488

10 Apr 2025 06:33PM UTC coverage: 92.964% (-0.4%) from 93.367%
14387781488

push

github

web-flow
Merge pull request #70 from tabkram/feature/cache

fix: add bypass argument to cache execution

237 of 271 branches covered (87.45%)

Branch coverage included in aggregate %.

5 of 5 new or added lines in 1 file covered. (100.0%)

2 existing lines in 1 file now uncovered.

384 of 397 relevant lines covered (96.73%)

95.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.49
/src/engine/executionEngine.ts
1
import { TraceableEngine } from './traceableEngine';
2✔
2
import { EngineTrace } from '../common/models/engineTrace.model';
3

4
/**
5
 * Represents a Contextual Execution with traceability features.
6
 *
7
 * @template CXT - Type of the context object.
8
 */
9
export class ExecutionEngine<
2✔
10
  CXT extends { [key: string]: unknown } = {
11
    [key: string]: unknown;
12
  }
13
> extends TraceableEngine {
14
  protected context: CXT;
15

16
  protected executionDate: Date;
17
  protected executionId: string;
18

19
  /**
20
   * Creates an instance of ContextualExecution.
21
   *
22
   * @param {Object} [options] - Options for initializing the execution.
23
   * @param {Date} [options.executionDate] - Date of the execution.
24
   * @param {string} [options.executionId] - Unique identifier for the execution.
25
   * @param {string} [options.initialTrace] - The initial trace for the execution.
26
   */
27
  constructor(options?: { executionDate?: Date; executionId?: string; initialTrace?: EngineTrace }) {
28
    super(options?.initialTrace);
10✔
29
    this.executionDate = options?.executionDate ?? new Date();
10✔
30
    this.executionId =
10✔
31
      options?.executionId ??
11✔
32
      [
33
        'exec',
34
        this.executionDate
35
          .toISOString()
36
          .replace(/[-:.Z]/g, '')
37
          .replace('T', '_'),
38
        crypto.randomUUID()
39
      ].join('_');
40

41
    return this;
10✔
42
  }
43

44
  /**
45
   * Get the current options of the Execution Engine.
46
   *
47
   * @returns {Object} An object containing the execution date and ID.
48
   * @public
49
   */
50
  getOptions(): { executionDate: Date; executionId: string } {
51
    return { executionDate: this.executionDate, executionId: this.executionId };
8✔
52
  }
53

54
  setContext(value: CXT): ExecutionEngine<CXT> {
55
    this.context = this.deepClone(value);
3✔
56
    return this;
3✔
57
  }
58

59
  getContext(): CXT {
60
    return this.context;
4✔
61
  }
62

63
  /**
64
   * Update the context of the execution with partial information.
65
   *
66
   * @param {Partial<CXT>} partialContext - Partial context information to update.
67
   * @returns {ExecutionEngine} - The updated ContextualExecution instance.
68
   */
69
  updateContext(partialContext: Partial<CXT>): ExecutionEngine {
70
    this.context = {
1✔
71
      ...this.context,
72
      ...partialContext
73
    };
74
    return this;
1✔
75
  }
76

77
  /**
78
   * Update a specific attribute of the context object.
79
   *
80
   * @param {K} key - The key of the attribute to update.
81
   * @param {CXT[K]} partialContextAttribute - Partial information to update for the attribute.
82
   * @returns {ExecutionEngine} - The updated ContextualExecution instance.
83
   */
84
  updateContextAttribute<K extends keyof CXT>(key: K, partialContextAttribute: CXT[K]): ExecutionEngine {
85
    if (partialContextAttribute === null || typeof partialContextAttribute !== 'object') {
1!
86
      // If the provided attribute is not an object or is null,
87
      // directly update the attribute in the context.
UNCOV
88
      this.context[key] = partialContextAttribute;
×
89
    } else {
90
      // If the provided attribute is an object, merge it with the existing attribute.
91
      this.context[key] = {
1✔
92
        ...(this.context?.[key] ?? {}),
1!
93
        ...partialContextAttribute
94
      };
95
    }
96
    return this;
1✔
97
  }
98

99
  /**
100
   * Deep clone function to copy nested objects.
101
   *
102
   * @private
103
   * @template T - Type of the object to clone.
104
   * @param {T} obj - The object to clone.
105
   * @returns {T} - The cloned object.
106
   */
107
  private deepClone<T>(obj: T): T {
108
    if (obj === null || typeof obj !== 'object') {
9✔
109
      return obj;
3✔
110
    }
111

112
    if (Array.isArray(obj)) {
6!
UNCOV
113
      return obj.map((item) => this.deepClone(item)) as T;
×
114
    }
115

116
    return Object.entries(obj).reduce((acc, [key, value]) => {
6✔
117
      acc[key] = this.deepClone(value);
6✔
118
      return acc;
6✔
119
    }, {} as T);
120
  }
121
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc