@cdktn/hcl2cdk 0.24.0-pre.45 → 0.24.0-pre.47
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/LICENSE +355 -0
- package/README.md +1 -1
- package/build/__tests__/expressions.test.js +10 -19
- package/build/__tests__/functions.test.js +8 -18
- package/build/__tests__/testHelpers.js +3 -2
- package/build/coerceType.js +11 -21
- package/build/dynamic-blocks.js +3 -3
- package/build/expressions.js +13 -22
- package/build/function-bindings/functions.generated.js +2 -2
- package/build/generation.js +24 -34
- package/build/index.js +15 -25
- package/build/iteration.js +7 -6
- package/build/jsii-rosetta-workarounds.js +6 -5
- package/build/partialCode.js +11 -20
- package/build/provider.js +4 -3
- package/build/references.js +6 -5
- package/build/schema.js +8 -18
- package/build/terraformSchema.js +4 -4
- package/build/utils.js +3 -3
- package/build/variables.js +12 -21
- package/package.json +20 -17
- package/package.sh +1 -1
- package/src/__tests__/coerceType.test.ts +207 -0
- package/src/__tests__/expressionToTs.test.ts +1167 -0
- package/src/__tests__/expressions.test.ts +541 -0
- package/src/__tests__/findExpressionType.test.ts +112 -0
- package/src/__tests__/functions.test.ts +768 -0
- package/src/__tests__/generation.test.ts +72 -0
- package/src/__tests__/jsii-rosetta-workarounds.test.ts +145 -0
- package/src/__tests__/partialCode.test.ts +432 -0
- package/src/__tests__/terraformSchema.test.ts +107 -0
- package/src/__tests__/testHelpers.ts +11 -0
- package/src/coerceType.ts +261 -0
- package/src/dynamic-blocks.ts +61 -0
- package/src/expressions.ts +968 -0
- package/src/function-bindings/functions.generated.ts +1139 -0
- package/src/function-bindings/functions.ts +104 -0
- package/src/generation.ts +1189 -0
- package/src/index.ts +584 -0
- package/src/iteration.ts +156 -0
- package/src/jsii-rosetta-workarounds.ts +145 -0
- package/src/partialCode.ts +132 -0
- package/src/provider.ts +60 -0
- package/src/references.ts +193 -0
- package/src/schema.ts +74 -0
- package/src/terraformSchema.ts +182 -0
- package/src/types.ts +58 -0
- package/src/utils.ts +19 -0
- package/src/variables.ts +214 -0
- package/test/__snapshots__/backends.test.ts.snap +70 -0
- package/test/__snapshots__/externals.test.ts.snap +37 -0
- package/test/__snapshots__/granular-imports.test.ts.snap +180 -0
- package/test/__snapshots__/imports.test.ts.snap +159 -0
- package/test/__snapshots__/iteration.test.ts.snap +532 -0
- package/test/__snapshots__/jsiiLanguage.test.ts.snap +347 -0
- package/test/__snapshots__/locals.test.ts.snap +55 -0
- package/test/__snapshots__/modules.test.ts.snap +127 -0
- package/test/__snapshots__/outputs.test.ts.snap +77 -0
- package/test/__snapshots__/partialCode.test.ts.snap +120 -0
- package/test/__snapshots__/provider.test.ts.snap +128 -0
- package/test/__snapshots__/references.test.ts.snap +376 -0
- package/test/__snapshots__/resource-meta-properties.test.ts.snap +342 -0
- package/test/__snapshots__/resources.test.ts.snap +613 -0
- package/test/__snapshots__/tfExpressions.test.ts.snap +537 -0
- package/test/__snapshots__/typeCoercion.test.ts.snap +253 -0
- package/test/__snapshots__/variables.test.ts.snap +150 -0
- package/test/backends.test.ts +75 -0
- package/test/convertProject.test.ts +257 -0
- package/test/externals.test.ts +35 -0
- package/test/globalSetup.ts +224 -0
- package/test/globalTeardown.ts +11 -0
- package/test/granular-imports.test.ts +161 -0
- package/test/hcl2cdk.test.ts +88 -0
- package/test/helpers/convert.ts +543 -0
- package/test/helpers/tmp.ts +25 -0
- package/test/imports.test.ts +141 -0
- package/test/iteration.test.ts +342 -0
- package/test/jsiiLanguage.test.ts +73 -0
- package/test/locals.test.ts +47 -0
- package/test/modules.test.ts +143 -0
- package/test/outputs.test.ts +69 -0
- package/test/partialCode.test.ts +25 -0
- package/test/provider.test.ts +106 -0
- package/test/references.test.ts +287 -0
- package/test/resource-meta-properties.test.ts +288 -0
- package/test/resources.test.ts +551 -0
- package/test/tfExpressions.test.ts +300 -0
- package/test/typeCoercion.test.ts +154 -0
- package/test/variables.test.ts +96 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) HashiCorp, Inc.
|
|
3
|
+
* SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { AttributeType } from "@cdktn/commons";
|
|
7
|
+
import { functionsMapGenerated } from "./functions.generated";
|
|
8
|
+
import { TFExpressionSyntaxTree as tex } from "@cdktn/hcl2json";
|
|
9
|
+
|
|
10
|
+
type FunctionCall = any; // TODO: this will come from the types for hcl2json (aka from the Terraform AST)
|
|
11
|
+
|
|
12
|
+
type FunctionMeta = {
|
|
13
|
+
name: string;
|
|
14
|
+
returnType: AttributeType;
|
|
15
|
+
parameters: {
|
|
16
|
+
type: AttributeType;
|
|
17
|
+
optional?: boolean;
|
|
18
|
+
variadic?: boolean;
|
|
19
|
+
}[];
|
|
20
|
+
/**
|
|
21
|
+
* Allows transforming the function call before it is handled. This is currently used to handle
|
|
22
|
+
* different APIs between TF supporting join(sep, listA, listB) and CDKTN only supporting join(sep, list)
|
|
23
|
+
* (as the alternative due to JSIIs lack of support for variadic parametes would be join(sep, lists) which
|
|
24
|
+
* would have a worse UX as most often just a single list is passed)
|
|
25
|
+
* In the case of join() the transformer will convert the function call to join(sep, concat(listA, listB))
|
|
26
|
+
* before handling it
|
|
27
|
+
*
|
|
28
|
+
* Caution: Beware of infinite recursion if the returned function call is to the same function that has this
|
|
29
|
+
* transformer. Return the same instance of the passed functionCall to break out of that recursion.
|
|
30
|
+
*/
|
|
31
|
+
transformer?: (functionCall: FunctionCall) => FunctionCall;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const functionsMap: Record<string, FunctionMeta> = {
|
|
35
|
+
...(functionsMapGenerated as any),
|
|
36
|
+
|
|
37
|
+
bcrypt: {
|
|
38
|
+
name: "bcrypt", // this one is not variadic anymore after we mapped it
|
|
39
|
+
returnType: "string",
|
|
40
|
+
parameters: [{ type: "string" }, { type: "number", optional: true }],
|
|
41
|
+
},
|
|
42
|
+
join: {
|
|
43
|
+
name: "join",
|
|
44
|
+
returnType: "string",
|
|
45
|
+
parameters: [{ type: "string" }, { type: ["list", "string"] }],
|
|
46
|
+
/**
|
|
47
|
+
* Terraform supports join(separator, listA, listB)
|
|
48
|
+
* wheras CDKTN only supports join(separator, list) (to make it simpler to use as JSII does not support variadic parameters)
|
|
49
|
+
* and we'd need to convert this to join(separator, concat(listA, listB)) if multiple variadic args are passed
|
|
50
|
+
*/
|
|
51
|
+
transformer: (fc: tex.FunctionCallExpression) => {
|
|
52
|
+
if (fc.children.length <= 2) {
|
|
53
|
+
return fc; // just one child -> nothing to do
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const concatFunction = {
|
|
57
|
+
type: "function",
|
|
58
|
+
meta: {
|
|
59
|
+
name: "concat",
|
|
60
|
+
expandedFinalArgument: fc.meta.expandedFinalArgument,
|
|
61
|
+
nameRange: {},
|
|
62
|
+
openParenRange: {},
|
|
63
|
+
closeParenRange: {},
|
|
64
|
+
argsRanges: [],
|
|
65
|
+
},
|
|
66
|
+
children: fc.children.slice(1),
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
type: "function",
|
|
71
|
+
meta: {
|
|
72
|
+
name: "join",
|
|
73
|
+
},
|
|
74
|
+
children: [
|
|
75
|
+
fc.children[0], // the first parameter is the separator, so keep it as is
|
|
76
|
+
concatFunction,
|
|
77
|
+
],
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
range: {
|
|
82
|
+
name: "range",
|
|
83
|
+
returnType: ["list", "string"], // TODO: Fn.range() currently returns string[] but should return number[] (according to functions.json)
|
|
84
|
+
parameters: [
|
|
85
|
+
{ type: "number" },
|
|
86
|
+
{ type: "number" },
|
|
87
|
+
{ type: "number", optional: true },
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
lookup: {
|
|
91
|
+
name: "lookup",
|
|
92
|
+
returnType: "dynamic",
|
|
93
|
+
parameters: [{ type: "dynamic" }, { type: "string" }, { type: "dynamic" }],
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const tsFunctionsMap = Object.entries(functionsMap).reduce(
|
|
98
|
+
(acc, [name, fnInfo]) => {
|
|
99
|
+
// Swap the names around
|
|
100
|
+
acc[fnInfo.name] = { ...fnInfo, name: name };
|
|
101
|
+
return acc;
|
|
102
|
+
},
|
|
103
|
+
{} as Record<string, FunctionMeta>,
|
|
104
|
+
);
|