@cdktn/hcl2cdk 0.26.0-pre.3 → 0.26.0-pre.30

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.
Files changed (94) hide show
  1. package/build/expressions.js +3 -5
  2. package/build/index.js +3 -3
  3. package/package.json +8 -7
  4. package/.spec.swcrc +0 -22
  5. package/build/__tests__/coerceType.test.d.ts +0 -2
  6. package/build/__tests__/coerceType.test.js +0 -165
  7. package/build/__tests__/expressionToTs.test.d.ts +0 -6
  8. package/build/__tests__/expressionToTs.test.js +0 -693
  9. package/build/__tests__/expressions.test.d.ts +0 -4
  10. package/build/__tests__/expressions.test.js +0 -424
  11. package/build/__tests__/findExpressionType.test.d.ts +0 -6
  12. package/build/__tests__/findExpressionType.test.js +0 -105
  13. package/build/__tests__/functions.test.d.ts +0 -6
  14. package/build/__tests__/functions.test.js +0 -615
  15. package/build/__tests__/generation.test.d.ts +0 -6
  16. package/build/__tests__/generation.test.js +0 -45
  17. package/build/__tests__/jsii-rosetta-workarounds.test.d.ts +0 -2
  18. package/build/__tests__/jsii-rosetta-workarounds.test.js +0 -86
  19. package/build/__tests__/partialCode.test.d.ts +0 -6
  20. package/build/__tests__/partialCode.test.js +0 -390
  21. package/build/__tests__/terraformSchema.test.d.ts +0 -6
  22. package/build/__tests__/terraformSchema.test.js +0 -105
  23. package/build/__tests__/testHelpers.d.ts +0 -7
  24. package/build/__tests__/testHelpers.js +0 -15
  25. package/jest.config.js +0 -25
  26. package/package.sh +0 -9
  27. package/src/__tests__/coerceType.test.ts +0 -207
  28. package/src/__tests__/expressionToTs.test.ts +0 -1167
  29. package/src/__tests__/expressions.test.ts +0 -541
  30. package/src/__tests__/findExpressionType.test.ts +0 -112
  31. package/src/__tests__/functions.test.ts +0 -764
  32. package/src/__tests__/generation.test.ts +0 -72
  33. package/src/__tests__/jsii-rosetta-workarounds.test.ts +0 -145
  34. package/src/__tests__/partialCode.test.ts +0 -432
  35. package/src/__tests__/terraformSchema.test.ts +0 -107
  36. package/src/__tests__/testHelpers.ts +0 -11
  37. package/src/coerceType.ts +0 -261
  38. package/src/dynamic-blocks.ts +0 -61
  39. package/src/expressions.ts +0 -968
  40. package/src/function-bindings/functions.generated.ts +0 -1211
  41. package/src/function-bindings/functions.ts +0 -104
  42. package/src/generation.ts +0 -1189
  43. package/src/index.ts +0 -584
  44. package/src/iteration.ts +0 -156
  45. package/src/jsii-rosetta-workarounds.ts +0 -145
  46. package/src/partialCode.ts +0 -132
  47. package/src/provider.ts +0 -60
  48. package/src/references.ts +0 -193
  49. package/src/schema.ts +0 -74
  50. package/src/terraformSchema.ts +0 -182
  51. package/src/types.ts +0 -58
  52. package/src/utils.ts +0 -19
  53. package/src/variables.ts +0 -214
  54. package/test/__snapshots__/backends.test.ts.snap +0 -70
  55. package/test/__snapshots__/externals.test.ts.snap +0 -37
  56. package/test/__snapshots__/granular-imports.test.ts.snap +0 -180
  57. package/test/__snapshots__/imports.test.ts.snap +0 -159
  58. package/test/__snapshots__/iteration.test.ts.snap +0 -532
  59. package/test/__snapshots__/jsiiLanguage.test.ts.snap +0 -347
  60. package/test/__snapshots__/locals.test.ts.snap +0 -55
  61. package/test/__snapshots__/modules.test.ts.snap +0 -127
  62. package/test/__snapshots__/outputs.test.ts.snap +0 -77
  63. package/test/__snapshots__/partialCode.test.ts.snap +0 -120
  64. package/test/__snapshots__/provider.test.ts.snap +0 -128
  65. package/test/__snapshots__/references.test.ts.snap +0 -376
  66. package/test/__snapshots__/resource-meta-properties.test.ts.snap +0 -342
  67. package/test/__snapshots__/resources.test.ts.snap +0 -613
  68. package/test/__snapshots__/tfExpressions.test.ts.snap +0 -537
  69. package/test/__snapshots__/typeCoercion.test.ts.snap +0 -253
  70. package/test/__snapshots__/variables.test.ts.snap +0 -150
  71. package/test/backends.test.ts +0 -75
  72. package/test/convertProject.test.ts +0 -262
  73. package/test/externals.test.ts +0 -35
  74. package/test/globalSetup.ts +0 -224
  75. package/test/globalTeardown.ts +0 -11
  76. package/test/granular-imports.test.ts +0 -161
  77. package/test/hcl2cdk.test.ts +0 -88
  78. package/test/helpers/convert.ts +0 -544
  79. package/test/helpers/tmp.ts +0 -40
  80. package/test/imports.test.ts +0 -141
  81. package/test/iteration.test.ts +0 -342
  82. package/test/jsiiLanguage.test.ts +0 -73
  83. package/test/locals.test.ts +0 -47
  84. package/test/modules.test.ts +0 -143
  85. package/test/outputs.test.ts +0 -69
  86. package/test/partialCode.test.ts +0 -25
  87. package/test/provider.test.ts +0 -106
  88. package/test/references.test.ts +0 -287
  89. package/test/resource-meta-properties.test.ts +0 -288
  90. package/test/resources.test.ts +0 -551
  91. package/test/tfExpressions.test.ts +0 -300
  92. package/test/typeCoercion.test.ts +0 -154
  93. package/test/variables.test.ts +0 -96
  94. package/tsconfig.json +0 -47
@@ -1,72 +0,0 @@
1
- /**
2
- * Copyright (c) HashiCorp, Inc.
3
- * SPDX-License-Identifier: MPL-2.0
4
- */
5
-
6
- import { variableTypeToAst } from "../generation";
7
- import { ProgramScope } from "../types";
8
- import { astToCode } from "./testHelpers";
9
-
10
- describe("variableTypeToAst", () => {
11
- async function run(type: string) {
12
- return astToCode(
13
- await variableTypeToAst(
14
- {
15
- importables: [],
16
- } as unknown as ProgramScope,
17
- type,
18
- ),
19
- );
20
- }
21
-
22
- it("should convert a simple type", async () => {
23
- expect(await run("${string}")).toMatchInlineSnapshot(
24
- `"VariableType.STRING"`,
25
- );
26
- });
27
-
28
- it("should convert a object type", async () => {
29
- expect(
30
- await run(
31
- "${object({\n name = string\n address = string\n })}",
32
- ),
33
- ).toMatchInlineSnapshot(`
34
- "VariableType.object({
35
- "address": VariableType.STRING,
36
- "name": VariableType.STRING
37
- })"
38
- `);
39
- });
40
-
41
- it("should convert a list type", async () => {
42
- expect(
43
- await run(
44
- "${list(object({\n internal = number\n external = number\n protocol = string\n }))}",
45
- ),
46
- ).toMatchInlineSnapshot(`
47
- "VariableType.list(VariableType.object({
48
- "external": VariableType.NUMBER,
49
- "internal": VariableType.NUMBER,
50
- "protocol": VariableType.STRING
51
- }))"
52
- `);
53
- });
54
-
55
- it("should convert a set type", async () => {
56
- expect(await run("${set(string)}")).toMatchInlineSnapshot(
57
- `"VariableType.set(VariableType.STRING)"`,
58
- );
59
- });
60
-
61
- it("should convert a map type", async () => {
62
- expect(await run("${map(string)}")).toMatchInlineSnapshot(
63
- `"VariableType.map(VariableType.STRING)"`,
64
- );
65
- });
66
-
67
- it("should convert a tuple type", async () => {
68
- expect(await run("${tuple(string, number, bool)}")).toMatchInlineSnapshot(
69
- `"VariableType.tuple(VariableType.STRING, VariableType.NUMBER, VariableType.BOOL)"`,
70
- );
71
- });
72
- });
@@ -1,145 +0,0 @@
1
- // Copyright (c) HashiCorp, Inc
2
- // SPDX-License-Identifier: MPL-2.0
3
-
4
- import {
5
- replaceCsharpImports,
6
- replaceGoImports,
7
- replaceJavaImports,
8
- replacePythonImports,
9
- } from "../jsii-rosetta-workarounds";
10
-
11
- describe("jsii-rosetta-workarounds", () => {
12
- describe("replacePythonImports", () => {
13
- it("normal imports", () => {
14
- const code = `
15
- import constructs as constructs
16
- # Provider bindings are generated by running cdktn get.
17
- # See https://cdktn.io/docs/concepts/providers#import-providers for more details.
18
- import ...gen.providers.scaleway as scaleway
19
- class MyConvertedCode(constructs.Construct):
20
- def __init__(self, scope, name):
21
- super().__init__(scope, name)
22
- scaleway.provider.ScalewayProvider(self, "scaleway",
23
- region="fr-par",
24
- zone="fr-par-1"
25
- )`;
26
-
27
- expect(replacePythonImports(code)).toEqual(
28
- expect.stringContaining("import imports.scaleway as scaleway"),
29
- );
30
- });
31
-
32
- it("granular imports", () => {
33
- const code = `from ...gen.providers.aws.lib.rdsCluster import RdsCluster`;
34
-
35
- expect(replacePythonImports(code)).toEqual(
36
- "from imports.aws.rdsCluster import RdsCluster",
37
- );
38
-
39
- const withoutLibCode = `from ...gen.providers.azurerm.resource_group import ResourceGroup`;
40
- expect(replacePythonImports(withoutLibCode)).toEqual(
41
- "from imports.azurerm.resource_group import ResourceGroup",
42
- );
43
- });
44
-
45
- it("resource imports", () => {
46
- const code = `import ...gen.providers.aws.lib.rdsCluster as RdsCluster`;
47
-
48
- expect(replacePythonImports(code)).toEqual(
49
- "import imports.aws.rdsCluster as RdsCluster",
50
- );
51
- });
52
-
53
- it("fixes module imports", () => {
54
- const code = `import ...gen.modules.hello_module as HelloModule`;
55
-
56
- expect(replacePythonImports(code)).toEqual(
57
- "import imports.hello_module as HelloModule",
58
- );
59
- });
60
- });
61
-
62
- describe("replaceCsharpImports", () => {
63
- it("normal imports", () => {
64
- const code = `using Gen.Providers.Aws.Lib.RdsCluster;`;
65
-
66
- expect(replaceCsharpImports(code)).toEqual("using aws.RdsCluster;");
67
- });
68
-
69
- it("fixes module imports", () => {
70
- const code = `using Gen.Modules.HelloModule`;
71
-
72
- expect(replaceCsharpImports(code)).toEqual("using HelloModule");
73
-
74
- const anotherCode = `using Gen.Modules.Hello.Module`;
75
-
76
- expect(replaceCsharpImports(anotherCode)).toEqual("using Hello.Module");
77
- });
78
- });
79
-
80
- describe("replaceJavaImports", () => {
81
- it("normal imports", () => {
82
- const code = `import gen.providers.scaleway.objectResource.*;`;
83
-
84
- expect(replaceJavaImports(code)).toEqual(
85
- "import imports.scaleway.objectResource.*;",
86
- );
87
- });
88
-
89
- it("precise imports", () => {
90
- const code = `import gen.providers.aws.lib.s3Bucket.S3Bucket;`;
91
-
92
- expect(replaceJavaImports(code)).toEqual(
93
- "import imports.aws.s3Bucket.S3Bucket;",
94
- );
95
-
96
- const withoutLibImport = `import gen.providers.aws.s3Bucket.S3Bucket;`;
97
-
98
- expect(replaceJavaImports(withoutLibImport)).toEqual(
99
- "import imports.aws.s3Bucket.S3Bucket;",
100
- );
101
- });
102
-
103
- it("fixes module imports", () => {
104
- const code = `import gen.modules.hello.module.*;`;
105
-
106
- expect(replaceJavaImports(code)).toEqual(
107
- "import imports.hello.module.*;",
108
- );
109
-
110
- const anotherCode = `import gen.modules.helloModule.*;`;
111
-
112
- expect(replaceJavaImports(anotherCode)).toEqual(
113
- "import imports.helloModule.*;",
114
- );
115
- });
116
- });
117
-
118
- describe("replaceGoImports", () => {
119
- it("normal imports", () => {
120
- const code = `import "github.com/aws-samples/dummy/gen/providers/scaleway/objectBucket"`;
121
-
122
- expect(replaceGoImports(code)).toEqual(
123
- `import "cdk.tf/go/stack/generated/scaleway/objectBucket"`,
124
- );
125
- });
126
-
127
- it("precise imports", () => {
128
- const code = `import "github.com/aws-samples/dummy/gen/providers/aws/lib/dbInstance"`;
129
-
130
- expect(replaceGoImports(code)).toEqual(
131
- `import "cdk.tf/go/stack/generated/aws/dbInstance"`,
132
- );
133
- });
134
-
135
- it("fixes module imports", () => {
136
- const code = `import helloModule "github.com/aws-samples/dummy/gen/modules/hello_module"`;
137
-
138
- expect(replaceGoImports(code)).toEqual(
139
- // TODO: Set up cdktn.io/ static redirect?
140
- // "github.com/open-constructs/cdk-terrain/examples/go/documentation/generated/terraform-aws-modules/aws/vpc"
141
- `import helloModule "cdk.tf/go/stack/generated/hello_module"`,
142
- );
143
- });
144
- });
145
- });
@@ -1,432 +0,0 @@
1
- /**
2
- * Copyright (c) HashiCorp, Inc.
3
- * SPDX-License-Identifier: MPL-2.0
4
- */
5
-
6
- import { fillWithConfigAccessors } from "../partialCode";
7
- import { ProgramScope } from "../types";
8
-
9
- const getScope = () =>
10
- ({
11
- providerSchema: {
12
- format_version: "0.1",
13
- provider_schemas: {
14
- aws: {
15
- data_source_schemas: {},
16
- provider: {
17
- block: {
18
- attributes: {},
19
- block_types: {},
20
- },
21
- version: 0,
22
- },
23
- resource_schemas: {
24
- aws_image: {
25
- version: 0,
26
- block: {
27
- block_types: {
28
- c: {
29
- nesting_mode: "single",
30
- block: {
31
- attributes: {
32
- d: {
33
- type: "string",
34
- description_kind: "plain",
35
- optional: true,
36
- required: true,
37
- },
38
- },
39
- block_types: {},
40
- },
41
- },
42
- d: {
43
- nesting_mode: "list",
44
- block: {
45
- attributes: {
46
- e: {
47
- type: "string",
48
- description_kind: "plain",
49
- optional: true,
50
- required: true,
51
- },
52
- },
53
- block_types: {},
54
- },
55
- min_items: 1,
56
- },
57
- timeouts: {
58
- nesting_mode: "single",
59
- block: {
60
- attributes: {
61
- read: {
62
- type: "string",
63
- description_kind: "plain",
64
- optional: true,
65
- },
66
- },
67
- block_types: {},
68
- description_kind: "plain",
69
- },
70
- },
71
- },
72
- attributes: {
73
- a: {
74
- type: "string",
75
- required: true,
76
- },
77
- b: {
78
- type: "string",
79
- required: true,
80
- },
81
- },
82
- },
83
- },
84
- },
85
- },
86
- },
87
- },
88
- constructs: new Set(),
89
- hasTokenBasedTypeCoercion: false,
90
- nodeIds: [],
91
- providerGenerator: {},
92
- variables: {},
93
- importables: [],
94
-
95
- // This should be mutated
96
- topLevelConfig: {},
97
- }) as ProgramScope;
98
-
99
- describe("fillWithConfigAccessors", () => {
100
- it("adds a missing required attributes", () => {
101
- const scope = getScope();
102
- const result = fillWithConfigAccessors(
103
- scope,
104
- {
105
- a: "a",
106
- c: {
107
- d: "d",
108
- },
109
- timeouts: {
110
- read: "20m",
111
- },
112
- d: [{ e: "e" }],
113
- },
114
- "aws.image",
115
- );
116
- expect(scope.topLevelConfig.b).toEqual("aws.image.b");
117
- expect(result).toMatchInlineSnapshot(`
118
- {
119
- "a": "a",
120
- "b": {
121
- "computed": false,
122
- "object": {
123
- "name": "config",
124
- "type": "Identifier",
125
- },
126
- "optional": null,
127
- "property": {
128
- "name": "b",
129
- "type": "Identifier",
130
- },
131
- "type": "MemberExpression",
132
- },
133
- "c": {
134
- "d": "d",
135
- },
136
- "d": [
137
- {
138
- "e": "e",
139
- },
140
- ],
141
- "timeouts": {
142
- "read": "20m",
143
- },
144
- }
145
- `);
146
- });
147
-
148
- it("ignores missing unrequired set block types", () => {
149
- const scope = getScope();
150
- const result = fillWithConfigAccessors(
151
- scope,
152
- {
153
- a: "a",
154
- b: "b",
155
- c: {
156
- d: "d",
157
- },
158
- d: [{ e: "e" }],
159
- },
160
- "aws.image",
161
- );
162
- expect(scope.topLevelConfig).toEqual({});
163
- expect(result).toMatchInlineSnapshot(`
164
- {
165
- "a": "a",
166
- "b": "b",
167
- "c": {
168
- "d": "d",
169
- },
170
- "d": [
171
- {
172
- "e": "e",
173
- },
174
- ],
175
- }
176
- `);
177
- });
178
-
179
- it("fills within a single block type", () => {
180
- const scope = getScope();
181
- const result = fillWithConfigAccessors(
182
- scope,
183
- {
184
- a: "a",
185
- b: "b",
186
- c: {},
187
- d: [{ e: "e" }],
188
- },
189
- "aws.image",
190
- );
191
- expect(scope.topLevelConfig).toEqual({
192
- d: "aws.image.c.d",
193
- });
194
- expect(result).toMatchInlineSnapshot(`
195
- {
196
- "a": "a",
197
- "b": "b",
198
- "c": {
199
- "d": {
200
- "computed": false,
201
- "object": {
202
- "name": "config",
203
- "type": "Identifier",
204
- },
205
- "optional": null,
206
- "property": {
207
- "name": "d",
208
- "type": "Identifier",
209
- },
210
- "type": "MemberExpression",
211
- },
212
- },
213
- "d": [
214
- {
215
- "e": "e",
216
- },
217
- ],
218
- }
219
- `);
220
- });
221
-
222
- it("fills an entire single block type", () => {
223
- const scope = getScope();
224
- const result = fillWithConfigAccessors(
225
- scope,
226
- {
227
- a: "a",
228
- b: "b",
229
- d: [{ e: "e" }],
230
- },
231
- "aws.image",
232
- );
233
- expect(scope.topLevelConfig).toEqual({
234
- c: "aws.image.c",
235
- });
236
- expect(result).toMatchInlineSnapshot(`
237
- {
238
- "a": "a",
239
- "b": "b",
240
- "c": {
241
- "computed": false,
242
- "object": {
243
- "name": "config",
244
- "type": "Identifier",
245
- },
246
- "optional": null,
247
- "property": {
248
- "name": "c",
249
- "type": "Identifier",
250
- },
251
- "type": "MemberExpression",
252
- },
253
- "d": [
254
- {
255
- "e": "e",
256
- },
257
- ],
258
- }
259
- `);
260
- });
261
-
262
- it("fills within a list block type", () => {
263
- const scope = getScope();
264
- const result = fillWithConfigAccessors(
265
- scope,
266
- {
267
- a: "a",
268
- b: "b",
269
- c: { d: "d" },
270
- d: [{}],
271
- },
272
- "aws.image",
273
- );
274
- expect(scope.topLevelConfig).toEqual({
275
- e: "aws.image.d.[].e",
276
- });
277
- expect(result).toMatchInlineSnapshot(`
278
- {
279
- "a": "a",
280
- "b": "b",
281
- "c": {
282
- "d": "d",
283
- },
284
- "d": [
285
- {
286
- "e": {
287
- "computed": false,
288
- "object": {
289
- "name": "config",
290
- "type": "Identifier",
291
- },
292
- "optional": null,
293
- "property": {
294
- "name": "e",
295
- "type": "Identifier",
296
- },
297
- "type": "MemberExpression",
298
- },
299
- },
300
- ],
301
- }
302
- `);
303
- });
304
-
305
- it("fills an entire list block type", () => {
306
- const scope = getScope();
307
- const result = fillWithConfigAccessors(
308
- scope,
309
- {
310
- a: "a",
311
- b: "b",
312
- c: { d: "d" },
313
- },
314
- "aws.image",
315
- );
316
- expect(scope.topLevelConfig).toEqual({
317
- d: "aws.image.d",
318
- });
319
- expect(result).toMatchInlineSnapshot(`
320
- {
321
- "a": "a",
322
- "b": "b",
323
- "c": {
324
- "d": "d",
325
- },
326
- "d": {
327
- "computed": false,
328
- "object": {
329
- "name": "config",
330
- "type": "Identifier",
331
- },
332
- "optional": null,
333
- "property": {
334
- "name": "d",
335
- "type": "Identifier",
336
- },
337
- "type": "MemberExpression",
338
- },
339
- }
340
- `);
341
- });
342
-
343
- it("can handle multiple fills with the same name", () => {
344
- const scope = getScope();
345
- const result = fillWithConfigAccessors(
346
- scope,
347
- {
348
- a: "a",
349
- b: "b",
350
- c: {},
351
- },
352
- "aws.image",
353
- );
354
- expect(scope.topLevelConfig).toEqual({
355
- d: "aws.image.c.d",
356
- d1: "aws.image.d",
357
- });
358
- expect(result).toMatchInlineSnapshot(`
359
- {
360
- "a": "a",
361
- "b": "b",
362
- "c": {
363
- "d": {
364
- "computed": false,
365
- "object": {
366
- "name": "config",
367
- "type": "Identifier",
368
- },
369
- "optional": null,
370
- "property": {
371
- "name": "d",
372
- "type": "Identifier",
373
- },
374
- "type": "MemberExpression",
375
- },
376
- },
377
- "d": {
378
- "computed": false,
379
- "object": {
380
- "name": "config",
381
- "type": "Identifier",
382
- },
383
- "optional": null,
384
- "property": {
385
- "name": "d1",
386
- "type": "Identifier",
387
- },
388
- "type": "MemberExpression",
389
- },
390
- }
391
- `);
392
- });
393
-
394
- it("fills lists with min_items > 0", () => {
395
- const scope = getScope();
396
- const result = fillWithConfigAccessors(
397
- scope,
398
- {
399
- a: "a",
400
- b: "b",
401
- c: { d: "d" },
402
- d: [],
403
- },
404
- "aws.image",
405
- );
406
- expect(scope.topLevelConfig).toEqual({
407
- d: "aws.image.d",
408
- });
409
- expect(result).toMatchInlineSnapshot(`
410
- {
411
- "a": "a",
412
- "b": "b",
413
- "c": {
414
- "d": "d",
415
- },
416
- "d": {
417
- "computed": false,
418
- "object": {
419
- "name": "config",
420
- "type": "Identifier",
421
- },
422
- "optional": null,
423
- "property": {
424
- "name": "d",
425
- "type": "Identifier",
426
- },
427
- "type": "MemberExpression",
428
- },
429
- }
430
- `);
431
- });
432
- });