@cdktn/provider-generator 0.24.0-pre.5 → 0.24.0-pre.50
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/.spec.swcrc +22 -0
- package/LICENSE +355 -0
- package/README.md +1 -1
- package/build/__tests__/edge-provider-schema/cli.js +8 -3
- package/build/get/__tests__/generator/import-style.test.d.ts +2 -0
- package/build/get/__tests__/generator/import-style.test.js +101 -0
- package/build/get/__tests__/generator/module-generator.test.js +12 -12
- package/build/get/constructs-maker.d.ts +5 -1
- package/build/get/constructs-maker.js +14 -6
- package/build/get/generator/emitter/struct-emitter.d.ts +2 -1
- package/build/get/generator/emitter/struct-emitter.js +14 -11
- package/build/get/generator/module-generator.js +3 -3
- package/build/get/generator/provider-generator.d.ts +9 -1
- package/build/get/generator/provider-generator.js +9 -6
- package/jest.config.js +16 -9
- package/package.json +24 -23
- package/package.sh +1 -1
- package/src/__tests__/__snapshots__/edge-provider-schema.test.ts.snap +8 -8
- package/src/__tests__/__snapshots__/provider.test.ts.snap +2951 -2951
- package/src/__tests__/edge-provider-schema/builder.ts +185 -0
- package/src/__tests__/edge-provider-schema/cli.ts +51 -0
- package/src/__tests__/edge-provider-schema/index.ts +161 -0
- package/src/__tests__/edge-provider-schema.test.ts +24 -0
- package/src/__tests__/provider.test.ts +180 -0
- package/src/get/__tests__/constructs-maker.test.ts +118 -0
- package/src/get/__tests__/generator/__snapshots__/complex-computed-types.test.ts.snap +5 -5
- package/src/get/__tests__/generator/__snapshots__/export-sharding.test.ts.snap +3310 -3310
- package/src/get/__tests__/generator/__snapshots__/module-generator.test.ts.snap +355 -355
- package/src/get/__tests__/generator/__snapshots__/nested-types.test.ts.snap +8 -8
- package/src/get/__tests__/generator/__snapshots__/provider.test.ts.snap +8 -8
- package/src/get/__tests__/generator/__snapshots__/resource-types.test.ts.snap +126 -126
- package/src/get/__tests__/generator/__snapshots__/skipped-attributes.test.ts.snap +17 -17
- package/src/get/__tests__/generator/__snapshots__/types.test.ts.snap +65 -65
- package/src/get/__tests__/generator/complex-computed-types.test.ts +28 -0
- package/src/get/__tests__/generator/deep-nested-attributes.test.ts +56 -0
- package/src/get/__tests__/generator/description-escaping.test.ts +84 -0
- package/src/get/__tests__/generator/empty-provider-resources.test.ts +26 -0
- package/src/get/__tests__/generator/export-sharding.test.ts +169 -0
- package/src/get/__tests__/generator/import-style.test.ts +129 -0
- package/src/get/__tests__/generator/module-generator.test.ts +528 -0
- package/src/get/__tests__/generator/nested-types.test.ts +54 -0
- package/src/get/__tests__/generator/provider.test.ts +51 -0
- package/src/get/__tests__/generator/resource-types.test.ts +118 -0
- package/src/get/__tests__/generator/skipped-attributes.test.ts +72 -0
- package/src/get/__tests__/generator/types.test.ts +611 -0
- package/src/get/__tests__/generator/versions-file.test.ts +72 -0
- package/src/get/__tests__/util.ts +75 -0
- package/src/get/constructs-maker.ts +822 -0
- package/src/get/generator/custom-defaults.ts +493 -0
- package/src/get/generator/emitter/attributes-emitter.ts +225 -0
- package/src/get/generator/emitter/index.ts +5 -0
- package/src/get/generator/emitter/resource-emitter.ts +226 -0
- package/src/get/generator/emitter/struct-emitter.ts +683 -0
- package/src/get/generator/loop-detection.ts +81 -0
- package/src/get/generator/models/attribute-model.ts +216 -0
- package/src/get/generator/models/attribute-type-model.ts +448 -0
- package/src/get/generator/models/index.ts +7 -0
- package/src/get/generator/models/resource-model.ts +161 -0
- package/src/get/generator/models/scope.ts +54 -0
- package/src/get/generator/models/struct.ts +116 -0
- package/src/get/generator/module-generator.ts +234 -0
- package/src/get/generator/provider-generator.ts +355 -0
- package/src/get/generator/resource-parser.ts +762 -0
- package/src/get/generator/sanitized-comments.ts +49 -0
- package/src/get/generator/skipped-attributes.ts +27 -0
- package/src/index.ts +40 -0
- package/src/util.ts +26 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Copyright (c) HashiCorp, Inc
|
|
2
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
3
|
+
import * as fs from "fs-extra";
|
|
4
|
+
import * as os from "os";
|
|
5
|
+
import * as path from "path";
|
|
6
|
+
import {
|
|
7
|
+
Language,
|
|
8
|
+
ConstructsMakerModuleTarget,
|
|
9
|
+
ConstructsMakerProviderTarget,
|
|
10
|
+
} from "@cdktn/commons";
|
|
11
|
+
import { determineGoModuleName } from "../constructs-maker";
|
|
12
|
+
|
|
13
|
+
describe("constructsMaker", () => {
|
|
14
|
+
describe("determineGoModuleName", () => {
|
|
15
|
+
let tmpDir: string;
|
|
16
|
+
let emptySubDir: string, validSubdir: string, invalidSubdir: string;
|
|
17
|
+
|
|
18
|
+
beforeAll(async () => {
|
|
19
|
+
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "cdktf.test"));
|
|
20
|
+
/* test directory layout
|
|
21
|
+
* <tmpDir>
|
|
22
|
+
* ├── go.mod
|
|
23
|
+
* └── subdir
|
|
24
|
+
* ├── empty
|
|
25
|
+
* ├── valid
|
|
26
|
+
* │ └── go.mod
|
|
27
|
+
* └── invalid
|
|
28
|
+
* └── go.mod
|
|
29
|
+
*/
|
|
30
|
+
emptySubDir = path.join(tmpDir, "subdir", "empty");
|
|
31
|
+
validSubdir = path.join(tmpDir, "subdir", "valid");
|
|
32
|
+
invalidSubdir = path.join(tmpDir, "subdir", "invalid");
|
|
33
|
+
|
|
34
|
+
await fs.mkdirs(emptySubDir);
|
|
35
|
+
await fs.mkdirs(validSubdir);
|
|
36
|
+
await fs.mkdirs(invalidSubdir);
|
|
37
|
+
|
|
38
|
+
const root = `module cdk.tf/test/go`;
|
|
39
|
+
const valid = `module cdk.tf/test/go-valid-subdir`;
|
|
40
|
+
const invalid = `malformed go mod`;
|
|
41
|
+
|
|
42
|
+
await fs.writeFile(path.join(tmpDir, "go.mod"), root);
|
|
43
|
+
await fs.writeFile(path.join(validSubdir, "go.mod"), valid);
|
|
44
|
+
await fs.writeFile(path.join(invalidSubdir, "go.mod"), invalid);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
afterAll(async () => {
|
|
48
|
+
await fs.remove(tmpDir);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("works in root directory", async () => {
|
|
52
|
+
const moduleName = await determineGoModuleName(tmpDir);
|
|
53
|
+
expect(moduleName).toBe("cdk.tf/test/go");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("can walk upwards from empty directory", async () => {
|
|
57
|
+
const moduleName = await determineGoModuleName(emptySubDir);
|
|
58
|
+
expect(moduleName).toBe("cdk.tf/test/go/subdir/empty");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("works in subdirectory with go.mod", async () => {
|
|
62
|
+
const moduleName = await determineGoModuleName(validSubdir);
|
|
63
|
+
expect(moduleName).toBe("cdk.tf/test/go-valid-subdir");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("throws if go.mod is invalid", async () => {
|
|
67
|
+
await expect(determineGoModuleName(invalidSubdir)).rejects.toThrow(
|
|
68
|
+
`Could not determine the root Go module name. Found ${path.join(
|
|
69
|
+
invalidSubdir,
|
|
70
|
+
"go.mod",
|
|
71
|
+
)} but failed to regex match the module name directive`,
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("works from subdirectory that does not exist yet", async () => {
|
|
76
|
+
const moduleName = await determineGoModuleName(
|
|
77
|
+
path.join(tmpDir, "subdir", "that", "does", "not", "exist", "yet"),
|
|
78
|
+
);
|
|
79
|
+
expect(moduleName).toBe("cdk.tf/test/go/subdir/that/does/not/exist/yet");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("throws if nothing could be found", async () => {
|
|
83
|
+
const dir = "/cdktf-test/this/dir/does/not/exist"; //... and has no go.mod in any parent dir
|
|
84
|
+
await expect(determineGoModuleName(dir)).rejects.toThrow(
|
|
85
|
+
`Could not determine the root Go module name. No go.mod found in ${dir} and any parent directories`,
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
describe("ConstructsMakerProviderTarget", () => {
|
|
90
|
+
it("returns valid package name for Go", () => {
|
|
91
|
+
const target = new ConstructsMakerProviderTarget(
|
|
92
|
+
{
|
|
93
|
+
name: "google-beta",
|
|
94
|
+
fqn: "google-beta",
|
|
95
|
+
source: "google-beta",
|
|
96
|
+
version: "~> 4.0",
|
|
97
|
+
},
|
|
98
|
+
Language.GO,
|
|
99
|
+
);
|
|
100
|
+
expect(target.srcMakName).toEqual("google_beta");
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
describe("ConstructsMakerModuleTarget", () => {
|
|
104
|
+
it("returns valid package name for Go", () => {
|
|
105
|
+
const target = new ConstructsMakerModuleTarget(
|
|
106
|
+
{
|
|
107
|
+
name: "security-group",
|
|
108
|
+
source: "terraform-aws-modules/security-group/aws",
|
|
109
|
+
fqn: "terraform-aws-modules/security-group/aws",
|
|
110
|
+
version: "4.9.0",
|
|
111
|
+
namespace: "terraform-aws-modules/aws",
|
|
112
|
+
},
|
|
113
|
+
Language.GO,
|
|
114
|
+
);
|
|
115
|
+
expect(target.srcMakName).toEqual("security_group");
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -62,7 +62,7 @@ export interface AcmCertificateDomainValidationOptions {
|
|
|
62
62
|
export function acmCertificateDomainValidationOptionsToTerraform(struct?: AcmCertificateDomainValidationOptions): any {
|
|
63
63
|
if (!cdktn.canInspect(struct) || cdktn.Tokenization.isResolvable(struct)) { return struct; }
|
|
64
64
|
if (cdktn.isComplexElement(struct)) {
|
|
65
|
-
throw new Error("A complex element was used as configuration, this is not supported: https://
|
|
65
|
+
throw new Error("A complex element was used as configuration, this is not supported: https://cdktn.io/docs/concepts/resources#references");
|
|
66
66
|
}
|
|
67
67
|
return {
|
|
68
68
|
}
|
|
@@ -72,7 +72,7 @@ export function acmCertificateDomainValidationOptionsToTerraform(struct?: AcmCer
|
|
|
72
72
|
export function acmCertificateDomainValidationOptionsToHclTerraform(struct?: AcmCertificateDomainValidationOptions): any {
|
|
73
73
|
if (!cdktn.canInspect(struct) || cdktn.Tokenization.isResolvable(struct)) { return struct; }
|
|
74
74
|
if (cdktn.isComplexElement(struct)) {
|
|
75
|
-
throw new Error("A complex element was used as configuration, this is not supported: https://
|
|
75
|
+
throw new Error("A complex element was used as configuration, this is not supported: https://cdktn.io/docs/concepts/resources#references");
|
|
76
76
|
}
|
|
77
77
|
const attrs = {
|
|
78
78
|
};
|
|
@@ -136,7 +136,7 @@ export class AcmCertificateDomainValidationOptionsList extends cdktn.ComplexList
|
|
|
136
136
|
* @param wrapsSet whether the list is wrapping a set (will add tolist() to be able to access an item via an index)
|
|
137
137
|
*/
|
|
138
138
|
constructor(terraformResource: cdktn.IInterpolatingParent, terraformAttribute: string, wrapsSet: boolean) {
|
|
139
|
-
super(terraformResource, terraformAttribute, wrapsSet)
|
|
139
|
+
super(terraformResource, terraformAttribute, wrapsSet);
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
/**
|
|
@@ -156,7 +156,7 @@ export interface AcmCertificateOptions {
|
|
|
156
156
|
export function acmCertificateOptionsToTerraform(struct?: AcmCertificateOptionsOutputReference | AcmCertificateOptions): any {
|
|
157
157
|
if (!cdktn.canInspect(struct) || cdktn.Tokenization.isResolvable(struct)) { return struct; }
|
|
158
158
|
if (cdktn.isComplexElement(struct)) {
|
|
159
|
-
throw new Error("A complex element was used as configuration, this is not supported: https://
|
|
159
|
+
throw new Error("A complex element was used as configuration, this is not supported: https://cdktn.io/docs/concepts/resources#references");
|
|
160
160
|
}
|
|
161
161
|
return {
|
|
162
162
|
certificate_transparency_logging_preference: cdktn.stringToTerraform(struct!.certificateTransparencyLoggingPreference),
|
|
@@ -167,7 +167,7 @@ export function acmCertificateOptionsToTerraform(struct?: AcmCertificateOptionsO
|
|
|
167
167
|
export function acmCertificateOptionsToHclTerraform(struct?: AcmCertificateOptionsOutputReference | AcmCertificateOptions): any {
|
|
168
168
|
if (!cdktn.canInspect(struct) || cdktn.Tokenization.isResolvable(struct)) { return struct; }
|
|
169
169
|
if (cdktn.isComplexElement(struct)) {
|
|
170
|
-
throw new Error("A complex element was used as configuration, this is not supported: https://
|
|
170
|
+
throw new Error("A complex element was used as configuration, this is not supported: https://cdktn.io/docs/concepts/resources#references");
|
|
171
171
|
}
|
|
172
172
|
const attrs = {
|
|
173
173
|
certificate_transparency_logging_preference: {
|