@horietakehiro/aws-cdk-utul 0.35.6 → 0.40.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -74,12 +74,40 @@ template.hasOutput("VPCARN", {
74
74
 
75
75
  ---
76
76
 
77
+ `ExtraMatch.{arrayWith,arrayLike,objectLike,objectEquals,not,exact}` are same method as those of `Match` class but additionally provide type hints. These are useful to type-safely use `Matcher`
78
+
79
+ ![](./docs/ExtraMatch-type-hints-right.png)
80
+
81
+ ![](./docs/ExtraMatch-type-hints-wrong.png)
82
+
83
+ ---
84
+
77
85
  ## Install
78
86
 
79
87
  ```bash
80
88
  npm install @horietakehiro/aws-cdk-utul
81
89
  ```
82
90
 
91
+ By default, you may feel difficult to use this library because import path is too long for type hits to fit in IDE dialog box like below.
92
+
93
+ ![](./docs//default-tsconfig.png)
94
+
95
+ So I recommend that you add module alias settings in your `tsconfig.json` file like below.
96
+
97
+ ```json
98
+ {
99
+ "compilerOptions": {
100
+ "baseUrl": ".",
101
+ "paths": {
102
+ "@/cfn-types": ["node_modules/@horietakehiro/aws-cdk-utul/lib/types/cfn-resource-types"],
103
+ "@/cfn-types/*": ["node_modules/@horietakehiro/aws-cdk-utul/lib/types/cfn-resource-types/*"]
104
+ }
105
+ }
106
+ }
107
+ ```
108
+
109
+ ![](./docs/customized-tsconfig.png)
110
+
83
111
  ---
84
112
 
85
113
  ## Release policy
@@ -1,4 +1,4 @@
1
- import { Template, Match, Matcher } from "aws-cdk-lib/assertions";
1
+ import { Template, Matcher } from "aws-cdk-lib/assertions";
2
2
  import { Condition, InputResource, Mapping, OutputResource, InputParamter, OutputParameter, ReturnValue, InputOutput, OutputOutput, InputResourceWithoutType, IAMPolicyDocument, AlsoMatcher, TypedMatcher } from "./typed-resource";
3
3
  /**
4
4
  * almost same class as `Template` class at "aws-cdk-lib/assertions", but you can use this with proper type definitions
@@ -141,7 +141,7 @@ export interface JoinProps {
141
141
  /**
142
142
  * provides some syntax sugars for `Match` class at `aws-cdk-lib/assertions`
143
143
  */
144
- export declare class ExtraMatch extends Match {
144
+ export declare class ExtraMatch {
145
145
  /**
146
146
  * same function as `Match.objectEquals({ Ref: logicalId })`
147
147
  * @param logicalId
@@ -161,16 +161,6 @@ export declare class ExtraMatch extends Match {
161
161
  * @returns
162
162
  */
163
163
  static getAttArn(logicalId: string): Matcher;
164
- static arrayWith<T extends any[]>(pattern: AlsoMatcher<T>): TypedMatcher<T>;
165
- static arrayEquals<T extends any[]>(pattern: AlsoMatcher<T>): TypedMatcher<T>;
166
- static objectLike<T extends {
167
- [key: string]: any;
168
- }>(pattern: AlsoMatcher<T>): TypedMatcher<T>;
169
- static objectEquals<T extends {
170
- [key: string]: any;
171
- }>(pattern: AlsoMatcher<T>): TypedMatcher<T>;
172
- static not<T>(pattern: AlsoMatcher<T>): TypedMatcher<T>;
173
- static exact<T>(pattern: AlsoMatcher<T>): TypedMatcher<T>;
174
164
  /**
175
165
  * same function as below:
176
166
  *
@@ -183,5 +173,222 @@ export declare class ExtraMatch extends Match {
183
173
  * @returns
184
174
  */
185
175
  static joinLike(props: JoinProps): Matcher;
176
+ /**
177
+ You can define Matcher for IAM Policy Document with type hints.
178
+ ```js
179
+ template.hasResource(
180
+ AWS_IAM_ROLE({
181
+ Properties: {
182
+ AssumeRolePolicyDocument: ExtraMatch.iamPolicyLike({
183
+ Statement: [
184
+ {
185
+ Principal: { Service: "ec2.amazonaws.com" },
186
+ },
187
+ ],
188
+ }),
189
+ },
190
+ })
191
+ );
192
+ ```
193
+ * @param doc
194
+ * @returns
195
+ */
186
196
  static iamPolicyLike(doc: AlsoMatcher<IAMPolicyDocument>): Matcher;
197
+ /**
198
+ Same method as `Match.arrayWith` but provides type hints and validate type match
199
+ ```js
200
+ // this is a right code
201
+ template.hasResource(
202
+ AWS_EC2_EIP({
203
+ Properties: {
204
+ Tags: ExtraMatch.arrayWith<Tag[]>([
205
+ {
206
+ Key: "key2",
207
+ Value: "val2",
208
+ },
209
+ ]),
210
+ },
211
+ })
212
+ );
213
+ // this is a wrong code(type mismatch will be detected and ts-error will be raised)
214
+ template.hasResource(
215
+ AWS_EC2_EIP({
216
+ Properties: {
217
+ Tags: ExtraMatch.arrayWith<string[]>([
218
+ "hoge", "fuga"
219
+ ]),
220
+ },
221
+ })
222
+ );
223
+ ```
224
+ * @param pattern
225
+ * @returns
226
+ */
227
+ static arrayWith<T extends any[]>(pattern: AlsoMatcher<T>): TypedMatcher<T>;
228
+ /**
229
+ * Same method as `Match.arrayEquals` but provides type hints and validate type match
230
+ ```js
231
+ // this is a right code
232
+ template.hasResource(
233
+ AWS_EC2_EIP({
234
+ Properties: {
235
+ Tags: ExtraMatch.arrayEquals<Tag[]>([
236
+ {
237
+ Key: "key1",
238
+ Value: "val1",
239
+ },
240
+ {
241
+ Key: "key2",
242
+ Value: "val2",
243
+ },
244
+ ]),
245
+ },
246
+ })
247
+ );
248
+ // this is a wrong code(type mismatch will be detected and ts-error will be raised)
249
+ template.hasResource(
250
+ AWS_EC2_EIP({
251
+ Properties: {
252
+ Tags: ExtraMatch.arrayEquals<Tag[]>([
253
+ {
254
+ Key: "key1",
255
+ Value: "val1",
256
+ },
257
+ {
258
+ Key: 100,
259
+ Value: 200,
260
+ },
261
+ ]),
262
+ },
263
+ })
264
+ );
265
+ ```
266
+ * @param pattern
267
+ * @returns
268
+ */
269
+ static arrayEquals<T extends any[]>(pattern: AlsoMatcher<T>): TypedMatcher<T>;
270
+ /**
271
+ * Same method as `Match.objectLike` but provides type hints and validate type match
272
+ ```js
273
+ // this is a right code
274
+ template.hasResource(
275
+ AWS_EC2_INSTANCE({
276
+ Properties: {
277
+ BlockDeviceMappings: [
278
+ {
279
+ DeviceName: "test",
280
+ Ebs: ExtraMatch.objectLike<Ebs>({
281
+ VolumeSize: 10,
282
+ }),
283
+ },
284
+ ],
285
+ },
286
+ })
287
+ );
288
+ // this is a wrong code(type mismatch will be detected and ts-error will be raised)
289
+ template.hasResource(
290
+ AWS_EC2_INSTANCE({
291
+ Properties: {
292
+ BlockDeviceMappings: [
293
+ {
294
+ DeviceName: "test",
295
+ Ebs: ExtraMatch.objectLike<Ebs>({
296
+ VolumeSize: "10",
297
+ }),
298
+ },
299
+ ],
300
+ },
301
+ })
302
+ );
303
+ * @param pattern
304
+ * @returns
305
+ */
306
+ static objectLike<T extends {
307
+ [key: string]: any;
308
+ }>(pattern: AlsoMatcher<T>): TypedMatcher<T>;
309
+ /**
310
+ * Same method as `Match.objectEquals` but provides type hints and validate type match
311
+ ```js
312
+ // this is a right code
313
+ template.hasResource(
314
+ AWS_EC2_EIP({
315
+ Properties: {
316
+ // You can nest TypedMatcher(use TypedMatcher inside TypedMatcher)
317
+ Tags: ExtraMatch.arrayWith<Tag[]>([
318
+ ExtraMatch.objectEquals<Tag>({
319
+ Key: "key1",
320
+ Value: "val1",
321
+ }),
322
+ ]),
323
+ },
324
+ })
325
+ );
326
+ // this is a wrong code(type mismatch will be detected and ts-error will be raised)
327
+ template.hasResource(
328
+ AWS_EC2_EIP({
329
+ Properties: {
330
+ Tags: ExtraMatch.arrayWith<Tag[]>([
331
+ ExtraMatch.objectEquals<Tag>({
332
+ Key: "key1",
333
+ Value: 100,
334
+ }),
335
+ ]),
336
+ },
337
+ })
338
+ );
339
+ * @param pattern
340
+ * @returns
341
+ */
342
+ static objectEquals<T extends {
343
+ [key: string]: any;
344
+ }>(pattern: AlsoMatcher<T>): TypedMatcher<T>;
345
+ /**
346
+ * Same method as `Match.not` but provides type hints and validate type match
347
+ ```js
348
+ // this is a right code
349
+ template.hasResource(
350
+ AWS_EC2_INSTANCE({
351
+ Properties: {
352
+ ImageId: ExtraMatch.not("ami-12345"),
353
+ },
354
+ })
355
+ );
356
+ // this is a wrong code(type mismatch will be detected and ts-error will be raised)
357
+ template.hasResource(
358
+ AWS_EC2_INSTANCE({
359
+ Properties: {
360
+ ImageId: ExtraMatch.not(100),
361
+ },
362
+ })
363
+ );
364
+ ```
365
+ * Same method as `Match.not` but provides type hints and validate type match
366
+ * @param pattern
367
+ * @returns
368
+ */
369
+ static not<T>(pattern: AlsoMatcher<T extends never ? never : T>): TypedMatcher<T>;
370
+ /**
371
+ * Same method as `Match.exact` but provides type hints and validate type match
372
+ ```js
373
+ // this is a right code
374
+ template.hasResource(
375
+ AWS_EC2_INSTANCE({
376
+ Properties: {
377
+ InstanceType: ExtraMatch.exact("t2.micro"),
378
+ },
379
+ })
380
+ );
381
+ // this is a wrong code(type mismatch will be detected and ts-error will be raised)
382
+ template.hasResource(
383
+ AWS_EC2_INSTANCE({
384
+ Properties: {
385
+ InstanceType: ExtraMatch.exact(false),
386
+ },
387
+ })
388
+ );
389
+ ```
390
+ * @param pattern
391
+ * @returns
392
+ */
393
+ static exact<T>(pattern: AlsoMatcher<T extends never ? never : T>): TypedMatcher<T>;
187
394
  }