-
Notifications
You must be signed in to change notification settings - Fork 154
/
Copy pathtypes.ts
203 lines (187 loc) · 4.21 KB
/
types.ts
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import type { App, Stack } from 'aws-cdk-lib';
import type { AttributeType, TableProps } from 'aws-cdk-lib/aws-dynamodb';
import type { NodejsFunctionProps } from 'aws-cdk-lib/aws-lambda-nodejs';
import type { LogLevel } from './constants.js';
interface ExtraTestProps {
/**
* The suffix to be added to the resource name.
*
* For example, if the resource name is `fn-12345` and the suffix is `BasicFeatures`,
* the output will be `fn-12345-BasicFeatures`.
*
* Note that the maximum length of the name is 64 characters, so the suffix might be truncated.
*/
nameSuffix: string;
/**
* The output format of the bundled code.
*
* @default 'CJS'
*/
outputFormat?: 'CJS' | 'ESM';
}
type TestDynamodbTableProps = Omit<
TableProps,
'removalPolicy' | 'tableName' | 'billingMode' | 'partitionKey'
> & {
partitionKey?: {
name: string;
type: AttributeType;
};
};
type TestNodejsFunctionProps = Omit<
NodejsFunctionProps,
'logRetention' | 'runtime' | 'functionName' | 'bundling'
> & {
bundling?: Omit<
NodejsFunctionProps['bundling'],
'minify' | 'mainFields' | 'sourceMap' | 'format' | 'banner'
>;
};
type InvokeTestFunctionOptions = {
functionName: string;
times?: number;
invocationMode?: 'PARALLEL' | 'SEQUENTIAL';
payload?: Record<string, unknown> | Array<Record<string, unknown>>;
};
type ErrorField = {
name: string;
message: string;
stack: string;
};
type FunctionLog = {
level: keyof typeof LogLevel;
error: ErrorField;
} & { [key: string]: unknown };
type StackNameProps = {
/**
* Prefix for the stack name.
*/
stackNamePrefix: string;
/**
* Name of the test.
*/
testName: string;
};
interface TestStackProps {
/**
* Name of the test stack.
*/
stackNameProps: StackNameProps;
/**
* Reference to the AWS CDK App object.
* @default new App()
*/
app?: App;
/**
* Reference to the AWS CDK Stack object.
* @default new Stack(this.app, stackName)
*/
stack?: Stack;
}
// #region X-Ray Trace Utils
type GetXRayTraceIdsOptions = {
startTime: Date;
resourceName: string;
expectedTracesCount: number;
};
type XRayTraceDocumentParsed = {
name: string;
id: string;
start_time: number;
end_time?: number;
// This flag may be set if the segment hasn't been fully processed
// The trace may have already appeared in the `getTraceSummaries` response
// but a segment may still be in_progress
in_progress?: boolean;
aws?: {
request_id: string;
};
http?: {
request: {
url: string;
method: string;
};
response?: {
status: number;
content_length?: number;
};
};
origin?: string;
resource_arn?: string;
trace_id?: string;
subsegments?: XRayTraceDocumentParsed[];
annotations?: {
[key: string]: string | boolean | number;
};
metadata?: {
[key: string]: {
[key: string]: unknown;
};
};
fault?: boolean;
cause?: {
working_directory: string;
exceptions: {
message: string;
type: string;
remote: boolean;
stack: {
path: string;
line: number;
label: string;
}[];
}[];
};
exception: {
message: string;
};
error?: boolean;
namespace?: string;
};
type XRaySegmentParsed = {
Id: string;
Document: XRayTraceDocumentParsed;
};
type XRayTraceParsed = {
Id: string;
Segments: XRaySegmentParsed[];
};
type GetXRayTraceDetailsOptions = {
/**
* The trace IDs to get details for
*/
traceIds: string[];
/**
* The expected number of segments in each trace
*/
expectedSegmentsCount: number;
/**
* The name of the function that the trace is expected to be associated with
*/
functionName: string;
};
/**
* Enriched X-Ray trace document parsed with subsegments as a map
*/
type EnrichedXRayTraceDocumentParsed = Omit<
XRayTraceDocumentParsed,
'subsegments'
> & {
subsegments: Map<string, XRayTraceDocumentParsed>;
};
export type {
ExtraTestProps,
TestDynamodbTableProps,
TestNodejsFunctionProps,
InvokeTestFunctionOptions,
ErrorField,
FunctionLog,
StackNameProps,
TestStackProps,
GetXRayTraceIdsOptions,
GetXRayTraceDetailsOptions,
XRayTraceDocumentParsed,
XRaySegmentParsed,
XRayTraceParsed,
EnrichedXRayTraceDocumentParsed,
};