diagnostics

This commit is contained in:
Ben Irvin 2023-06-27 12:24:58 +02:00
parent b6a7792d8f
commit a58a2f9a51
2 changed files with 21 additions and 3 deletions

View File

@ -197,9 +197,27 @@ The following events are available:
### Diagnostics events
`engine.diagnostics.onDiagnostic(formatDiagnostic('export'));`
The engine includes a diagnostics reporter which can be used to listen for diagnostics information (debug messages, errors, etc).
**TODO**
Here is an example for creating a diagnostics listener:
```
// your listener
engine.diagnostics.onDiagnostic(async (data: GenericDiagnostic) => {
// handle the diagnostics, for example with custom logging
});
// engine/diagnostics.ts - format of the data sent to the listener
export type GenericDiagnostic<K extends DiagnosticKind, T = unknown> = {
kind: K;
details: {
message: string;
createdAt: Date;
} & T;
};
export type DiagnosticKind = 'error' | 'warning' | 'info';
```
### Transforms

View File

@ -15,7 +15,7 @@ export type GenericDiagnostic<K extends DiagnosticKind, T = unknown> = {
export type DiagnosticKind = 'error' | 'warning' | 'info';
export type DiagnosticListener<T extends DiagnosticKind = DiagnosticKind> = (
diagnostic: { kind: T } & Diagnostic extends infer U ? U : 'foo'
diagnostic: { kind: T } & Diagnostic extends infer U ? U : never
) => void | Promise<void>;
export type DiagnosticEvent = 'diagnostic' | `diagnostic.${DiagnosticKind}`;