-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Implemented correct default export generation
- Loading branch information
Showing
12 changed files
with
241 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export { Kestra as default } from './kestra'; | ||
import Kestra from './kestra/kestra'; | ||
|
||
export default Kestra; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import ConsoleLogger from '../logging/console-logger'; | ||
import { KestraFunction, Logger } from '../types'; | ||
|
||
const Kestra: KestraFunction = function () {} as KestraFunction; | ||
|
||
/** | ||
* Formats a map object as a string by converting it to a JSON string | ||
* and surrounding it with "::" delimiters. | ||
* | ||
* @param map - The map object to format. | ||
* @returns The formatted string. | ||
*/ | ||
Kestra.format = (map: Record<string, any>): string => { | ||
return '::' + JSON.stringify(map) + '::'; | ||
}; | ||
|
||
/** | ||
* Sends a log message to the standard output. | ||
* | ||
* @param map - The map object containing the log data. | ||
*/ | ||
Kestra._send = (map: Record<string, any>) => { | ||
console.log(Kestra.format(map)); | ||
}; | ||
|
||
/** | ||
* Sends a metric to the standard output. | ||
* | ||
* @param name - The name of the metric. | ||
* @param type - The type of the metric. | ||
* @param value - The value of the metric. | ||
* @param tags - The tags of the metric. | ||
*/ | ||
Kestra._metrics = (name: string, type: string, value: any, tags: any) => { | ||
Kestra._send({ | ||
metrics: [ | ||
{ | ||
name: name, | ||
type: type, | ||
value: value, | ||
tags: tags || {}, | ||
}, | ||
], | ||
}); | ||
}; | ||
|
||
Kestra.outputs = (outputs: any) => { | ||
Kestra._send({ | ||
outputs: outputs, | ||
}); | ||
}; | ||
|
||
/** | ||
* Sends a counter metric to the standard output. | ||
* | ||
* @param name - The name of the metric. | ||
* @param value - The value of the metric. | ||
* @param tags - The tags of the metric. | ||
*/ | ||
Kestra.counter = (name: string, value: any, tags: any) => { | ||
Kestra._metrics(name, 'counter', value, tags); | ||
}; | ||
|
||
/** | ||
* Measures the duration of a timer and sends the metric. | ||
* | ||
* @param name - The name of the timer. | ||
* @param duration - The duration in seconds or a function to measure the duration. | ||
* @param tags - Additional metadata tags for the timer. | ||
*/ | ||
Kestra.timer = (name: string, duration: number | ((func: () => void) => void), tags: any) => { | ||
// Check if duration is a function to execute for measuring time | ||
if (typeof duration === 'function') { | ||
const start = new Date(); | ||
// Execute the function and calculate elapsed time | ||
duration(() => { | ||
const elapsedTime = (new Date().getTime() - start.getTime()) / 1000; | ||
Kestra._metrics(name, 'timer', elapsedTime, tags); | ||
}); | ||
} else { | ||
// Directly use the provided duration value | ||
Kestra._metrics(name, 'timer', duration, tags); | ||
} | ||
}; | ||
|
||
/** | ||
* Provides an instance of the Logger. | ||
* | ||
* @returns A Logger instance. | ||
*/ | ||
Kestra.logger = (): Logger => { | ||
return new ConsoleLogger(Kestra); | ||
}; | ||
|
||
export default Kestra; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { KestraFunction, Log, Logger } from '../types'; | ||
|
||
export default class ConsoleLogger implements Logger { | ||
constructor(private readonly Kestra: KestraFunction) {} | ||
|
||
trace(...message: any): void { | ||
console.trace(this.Kestra.format(this._log('TRACE', message))); | ||
} | ||
|
||
debug(...message: any): void { | ||
console.debug(this.Kestra.format(this._log('DEBUG', message))); | ||
} | ||
|
||
info(...message: any): void { | ||
console.info(this.Kestra.format(this._log('INFO', message))); | ||
} | ||
|
||
warn(...message: any): void { | ||
console.warn(this.Kestra.format(this._log('WARN', message))); | ||
} | ||
|
||
error(...message: any): void { | ||
console.error(this.Kestra.format(this._log('ERROR', message))); | ||
} | ||
|
||
_log(level: string, message: string | string[]): { logs: Log[] } { | ||
return { | ||
logs: (Array.isArray(message) ? message : [message]).map((value: string) => { | ||
return { | ||
level: level, | ||
message: value, | ||
}; | ||
}), | ||
}; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './logging'; | ||
export * from './kestra'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Logger } from './logging'; | ||
|
||
export interface KestraFunction { | ||
(): void; | ||
format(map: Record<string, any>): string; | ||
_send(map: Record<string, any>): void; | ||
_metrics(name: string, type: string, value: any, tags: any): void; | ||
outputs(outputs: any): void; | ||
counter(name: string, value: any, tags: any): void; | ||
timer(name: string, duration: number | ((callback: () => void) => void), tags: any): void; | ||
logger(): Logger; | ||
} |
Oops, something went wrong.