-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.d.ts
More file actions
114 lines (107 loc) · 3.54 KB
/
index.d.ts
File metadata and controls
114 lines (107 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* tslint:disable */
/* eslint-disable */
import type { Node } from 'estree';
/**
* Create a new instrumentation matcher from an array of instrumentation configs.
*/
export function create(configs: InstrumentationConfig[], dc_module?: string | null): InstrumentationMatcher;
/**
* Output of a transformation operation
*/
export interface TransformOutput {
/**
* The transformed JavaScript code
*/
code: string;
/**
* The sourcemap for the transformation (if generated)
*/
map: string | undefined;
}
/**
* The kind of function
*/
export type FunctionKind = "Sync" | "Async" | "AsyncIterator" | "Callback" | "Iterator";
/**
* Describes which function to instrument
*/
export type FunctionQuery = { className: string; methodName: string; kind: FunctionKind; index?: number; isExportAlias?: boolean } | { className: string; privateMethodName: string; kind: FunctionKind; index?: number } | { className: string; index?: number; isExportAlias?: boolean } | { methodName: string; kind: FunctionKind; index?: number } | { functionName: string; kind: FunctionKind; index?: number; isExportAlias?: boolean } | { expressionName: string; kind: FunctionKind; index?: number; isExportAlias?: boolean };
/**
* A custom transform function registered via `addTransform`.
* Receives the instrumentation state and the matched AST node.
*/
export type CustomTransform = (state: unknown, node: Node, parent: Node, ancestry: Node[]) => void;
/**
* Configuration for injecting instrumentation code
*/
export interface InstrumentationConfig {
/**
* The name of the diagnostics channel to publish to
*/
channelName: string;
/**
* The module matcher to identify the module and file to instrument
*/
module: ModuleMatcher;
/**
* The function query to identify the function to instrument
*/
functionQuery: FunctionQuery;
/**
* The name of a custom transform registered via `addTransform`.
* When set, takes precedence over `functionQuery.kind`.
*/
transform?: string;
}
/**
* Describes the module and file path you would like to match
*/
export interface ModuleMatcher {
/**
* The name of the module you want to match
*/
name: string;
/**
* The semver range that you want to match
*/
versionRange: string;
/**
* The path of the file you want to match from the module root
*/
filePath: string;
}
/**
* The type of module being passed - ESM, CJS or unknown
*/
export type ModuleType = "esm" | "cjs" | "unknown";
/**
* The InstrumentationMatcher is responsible for matching specific modules
*/
export class InstrumentationMatcher {
private constructor();
free(): void;
/**
* Get a transformer for the given module name, version and file path.
* Returns `undefined` if no matching instrumentations are found.
*/
getTransformer(module_name: string, version: string, file_path: string): Transformer | undefined;
/**
* Register a custom transform function under the given name.
* The name can then be referenced via the `transform` option in an `InstrumentationConfig`.
*/
addTransform(name: string, fn: CustomTransform): void;
}
/**
* The Transformer is responsible for transforming JavaScript code.
*/
export class Transformer {
private constructor();
free(): void;
/**
* Transform JavaScript code and optionally sourcemap.
*
* # Errors
* Returns an error if the transformation fails to find injection points.
*/
transform(code: string, module_type: ModuleType, sourcemap?: string | null): TransformOutput;
}