Skip to content

Commit

Permalink
Merge pull request #19 from tabkram/engine-id-as-execution-id
Browse files Browse the repository at this point in the history
feat: rename `getOrderedNarratives` to `getNarratives`
  • Loading branch information
tabkram committed Dec 15, 2023
2 parents 726db14 + ec8aea9 commit e52d57a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/engine/executionEngineDecorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ export function engine(options?: { id: string }): ClassDecorator {

/**
* A method decorator that enables tracing for the decorated method.
* @param options - Trace options for the execution.
* @returns A decorator function.
*
* @param {TraceOptions<Array<any>, O> | TraceOptions<Array<any>, O>['trace']} [options] - Optional tracing options.
* @returns {Function} - A decorator function.
*/
export function run<O>(options?: TraceOptions<Array<any>, O>) {
export function run<O>(options?: TraceOptions<Array<any>, O> | TraceOptions<Array<any>, O>['trace']) {
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
// Store the original method
const originalMethod = descriptor.value;
Expand Down
2 changes: 1 addition & 1 deletion src/trace/traceableExecution.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ describe('TraceableExecution', () => {
]);

// Get the ordered narratives and verify their content
const orderedNarratives = traceableExecution.getOrderedNarratives();
const orderedNarratives = traceableExecution.getNarratives();
expect(orderedNarratives).toEqual([
'Narrative 0',
'Narrative 0 with Result: InputParam',
Expand Down
16 changes: 12 additions & 4 deletions src/trace/traceableExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,17 @@ export class TraceableExecution {
}
}

initTrace(initialTrace: Trace) {
/**
* Initializes the trace with given initialTrace.
*
* @param {Trace} initialTrace - The initial trace to initialize: the nodes and edges.
* @return {TraceableExecution} - The traceable execution object after initialization.
*/
initTrace(initialTrace: Trace): TraceableExecution {
this.nodes = (initialTrace?.filter((b) => b.group === 'nodes') as Array<Node>) ?? [];
this.edges = (initialTrace?.filter((b) => b.group === 'edges') as Array<Edge>) ?? [];
this.narrativesForNonFoundNodes = {};
return this;
}

/**
Expand Down Expand Up @@ -302,10 +309,11 @@ export class TraceableExecution {
}

/**
* Gets an ordered array of narratives.
* @returns An array containing ordered narratives.
* Retrieves an ordered array of narratives.
*
* @returns {Array<string>} An array that contains the ordered narratives. If no narratives are found, an empty array is returned.
*/
getOrderedNarratives(): Array<string> {
getNarratives(): Array<string> {
return this.nodes?.flatMap?.((n) => n.data?.narratives)?.filter((n) => !!n);
}

Expand Down

1 comment on commit e52d57a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 92.37% 242/262
🟢 Branches 86.21% 175/203
🟢 Functions 91.78% 67/73
🟢 Lines 93.09% 229/246

Test suite run success

33 tests passing in 5 suites.

Report generated by 🧪jest coverage report action from e52d57a

Please sign in to comment.