@cdktn/provider-generator 0.26.0-pre.20 → 0.26.0-pre.22

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 (57) hide show
  1. package/build/get/generator/models/scope.js +2 -14
  2. package/jest.config.js +0 -1
  3. package/package.json +5 -5
  4. package/package.sh +0 -0
  5. package/src/__tests__/edge-provider-schema/builder.ts +0 -201
  6. package/src/__tests__/edge-provider-schema/cli.ts +0 -51
  7. package/src/__tests__/edge-provider-schema/index.ts +0 -284
  8. package/src/__tests__/edge-provider-schema.test.ts +0 -24
  9. package/src/__tests__/erasable-syntax.test.ts +0 -81
  10. package/src/__tests__/provider.test.ts +0 -208
  11. package/src/get/__tests__/constructs-maker.test.ts +0 -242
  12. package/src/get/__tests__/generator/complex-computed-types.test.ts +0 -28
  13. package/src/get/__tests__/generator/deep-nested-attributes.test.ts +0 -56
  14. package/src/get/__tests__/generator/description-escaping.test.ts +0 -84
  15. package/src/get/__tests__/generator/empty-provider-resources.test.ts +0 -26
  16. package/src/get/__tests__/generator/ephemeral-resources.test.ts +0 -46
  17. package/src/get/__tests__/generator/export-sharding.test.ts +0 -169
  18. package/src/get/__tests__/generator/import-style.test.ts +0 -129
  19. package/src/get/__tests__/generator/module-docs-registry.test.ts +0 -89
  20. package/src/get/__tests__/generator/module-generator.test.ts +0 -528
  21. package/src/get/__tests__/generator/nested-types.test.ts +0 -54
  22. package/src/get/__tests__/generator/provider-functions-name-collision.test.ts +0 -84
  23. package/src/get/__tests__/generator/provider-functions.test.ts +0 -262
  24. package/src/get/__tests__/generator/provider-source-matching.test.ts +0 -84
  25. package/src/get/__tests__/generator/provider.test.ts +0 -59
  26. package/src/get/__tests__/generator/resource-types.test.ts +0 -118
  27. package/src/get/__tests__/generator/skipped-attributes.test.ts +0 -72
  28. package/src/get/__tests__/generator/supported-stored-classes.test.ts +0 -147
  29. package/src/get/__tests__/generator/types.test.ts +0 -686
  30. package/src/get/__tests__/generator/versions-file.test.ts +0 -77
  31. package/src/get/__tests__/generator/write-only.test.ts +0 -71
  32. package/src/get/__tests__/registry-class-invalidation.test.ts +0 -123
  33. package/src/get/__tests__/target-versions.test.ts +0 -249
  34. package/src/get/__tests__/util.ts +0 -80
  35. package/src/get/constructs-maker.ts +0 -991
  36. package/src/get/generator/custom-defaults.ts +0 -494
  37. package/src/get/generator/emitter/attributes-emitter.ts +0 -316
  38. package/src/get/generator/emitter/index.ts +0 -6
  39. package/src/get/generator/emitter/provider-functions-emitter.ts +0 -117
  40. package/src/get/generator/emitter/resource-emitter.ts +0 -330
  41. package/src/get/generator/emitter/struct-emitter.ts +0 -683
  42. package/src/get/generator/loop-detection.ts +0 -81
  43. package/src/get/generator/models/attribute-model.ts +0 -273
  44. package/src/get/generator/models/attribute-type-model.ts +0 -559
  45. package/src/get/generator/models/index.ts +0 -8
  46. package/src/get/generator/models/provider-function-model.ts +0 -872
  47. package/src/get/generator/models/resource-model.ts +0 -206
  48. package/src/get/generator/models/scope.ts +0 -54
  49. package/src/get/generator/models/struct.ts +0 -124
  50. package/src/get/generator/models/supported-stored-classes.ts +0 -88
  51. package/src/get/generator/module-generator.ts +0 -236
  52. package/src/get/generator/provider-generator.ts +0 -451
  53. package/src/get/generator/resource-parser.ts +0 -782
  54. package/src/get/generator/sanitized-comments.ts +0 -49
  55. package/src/get/generator/skipped-attributes.ts +0 -27
  56. package/src/index.ts +0 -40
  57. package/src/util.ts +0 -26
@@ -1,26 +0,0 @@
1
- // Copyright (c) HashiCorp, Inc
2
- // SPDX-License-Identifier: MPL-2.0
3
- import * as fs from "fs";
4
- import * as path from "path";
5
- import { TerraformProviderGenerator } from "../../generator/provider-generator";
6
- import { CodeMaker } from "codemaker";
7
- import { createTmpHelper } from "../util";
8
-
9
- const tmp = createTmpHelper();
10
-
11
- test("provider with no resources", async () => {
12
- const code = new CodeMaker();
13
- const workdir = tmp("empty-provider-resources.test");
14
- const spec = JSON.parse(
15
- fs.readFileSync(
16
- path.join(
17
- __dirname,
18
- "fixtures",
19
- "empty-provider-resources.test.fixture.json",
20
- ),
21
- "utf-8",
22
- ),
23
- );
24
- new TerraformProviderGenerator(code, spec).generateAll();
25
- await code.save(workdir);
26
- });
@@ -1,46 +0,0 @@
1
- // Copyright (c) HashiCorp, Inc
2
- // SPDX-License-Identifier: MPL-2.0
3
- import * as fs from "fs";
4
- import * as path from "path";
5
- import { TerraformProviderGenerator } from "../../generator/provider-generator";
6
- import { CodeMaker } from "codemaker";
7
- import { createTmpHelper } from "../util";
8
-
9
- const tmp = createTmpHelper();
10
-
11
- test("generate an ephemeral random_password resource alongside a regular random_uuid resource", async () => {
12
- const code = new CodeMaker();
13
- const workdir = tmp("ephemeral.test");
14
- const spec = JSON.parse(
15
- fs.readFileSync(
16
- path.join(__dirname, "fixtures", "ephemeral-resources.test.fixture.json"),
17
- "utf-8",
18
- ),
19
- );
20
- new TerraformProviderGenerator(code, spec).generateAll();
21
- await code.save(workdir);
22
-
23
- const ephemeralOutput = fs.readFileSync(
24
- path.join(workdir, "providers/random/ephemeral-random-password/index.ts"),
25
- "utf-8",
26
- );
27
- expect(ephemeralOutput).toMatchSnapshot("ephemeral-random-password");
28
-
29
- const resourceOutput = fs.readFileSync(
30
- path.join(workdir, "providers/random/uuid/index.ts"),
31
- "utf-8",
32
- );
33
- expect(resourceOutput).toMatchSnapshot("random-uuid");
34
-
35
- const providerIndex = fs.readFileSync(
36
- path.join(workdir, "providers/random/index.ts"),
37
- "utf-8",
38
- );
39
- expect(providerIndex).toMatchSnapshot("provider-index");
40
-
41
- const providerLazyIndex = fs.readFileSync(
42
- path.join(workdir, "providers/random/lazy-index.ts"),
43
- "utf-8",
44
- );
45
- expect(providerLazyIndex).toMatchSnapshot("provider-lazy-index");
46
- });
@@ -1,169 +0,0 @@
1
- // Copyright (c) HashiCorp, Inc
2
- // SPDX-License-Identifier: MPL-2.0
3
- import * as fs from "fs";
4
- import * as path from "path";
5
- import { TerraformProviderGenerator } from "../../generator/provider-generator";
6
- import { CodeMaker } from "codemaker";
7
- import { createTmpHelper } from "../util";
8
-
9
- const tmp = createTmpHelper();
10
-
11
- // this is a workaround for a bug introduced in TS 3.9.x and seems to be unlikely to get fixed.
12
- // Since jsii relies on TS < 4 at the moment we can't use newer TS versions which have this fixed (^4.1).
13
- // see https://github.com/hashicorp/terraform-cdk/pull/1248 for more context
14
- test("shard exports across multiple files to avoid generating files with more than a 1000 exports", async () => {
15
- const code = new CodeMaker();
16
- const workdir = tmp("export-sharding.test");
17
-
18
- const spec = JSON.parse(
19
- fs.readFileSync(
20
- path.join(__dirname, "fixtures", "aws_wafv2_web_acl.test.fixture.json"),
21
- "utf-8",
22
- ),
23
- );
24
- new TerraformProviderGenerator(code, spec).generateAll();
25
- await code.save(workdir);
26
-
27
- const output = fs.readFileSync(
28
- path.join(workdir, "providers/test/wafv2-web-acl/index.ts"),
29
- "utf-8",
30
- );
31
- expect(output).toMatchSnapshot(`wafv2-web-acl-resource`);
32
-
33
- const outputStructsIndex = fs.readFileSync(
34
- path.join(workdir, "providers/test/wafv2-web-acl/index-structs/index.ts"),
35
- "utf-8",
36
- );
37
- expect(outputStructsIndex).toMatchSnapshot(`structs-index`);
38
-
39
- const outputStructs0 = fs.readFileSync(
40
- path.join(
41
- workdir,
42
- "providers/test/wafv2-web-acl/index-structs/structs0.ts",
43
- ),
44
- "utf-8",
45
- );
46
- expect(outputStructs0).toMatchSnapshot(`structs0`);
47
-
48
- const outputStructs400 = fs.readFileSync(
49
- path.join(
50
- workdir,
51
- "providers/test/wafv2-web-acl/index-structs/structs400.ts",
52
- ),
53
- "utf-8",
54
- );
55
- expect(outputStructs400).toMatchSnapshot(`structs400`);
56
-
57
- const outputStructs800 = fs.readFileSync(
58
- path.join(
59
- workdir,
60
- "providers/test/wafv2-web-acl/index-structs/structs800.ts",
61
- ),
62
- "utf-8",
63
- );
64
- expect(outputStructs800).toMatchSnapshot(`structs800`);
65
-
66
- const outputStructs1200 = fs.readFileSync(
67
- path.join(
68
- workdir,
69
- "providers/test/wafv2-web-acl/index-structs/structs1200.ts",
70
- ),
71
- "utf-8",
72
- );
73
- expect(outputStructs1200).toMatchSnapshot(`structs1200`);
74
-
75
- const outputStructs1600 = fs.readFileSync(
76
- path.join(
77
- workdir,
78
- "providers/test/wafv2-web-acl/index-structs/structs1600.ts",
79
- ),
80
- "utf-8",
81
- );
82
- expect(outputStructs1600).toMatchSnapshot(`structs1600`);
83
-
84
- const outputStructs2000 = fs.readFileSync(
85
- path.join(
86
- workdir,
87
- "providers/test/wafv2-web-acl/index-structs/structs2000.ts",
88
- ),
89
- "utf-8",
90
- );
91
- expect(outputStructs2000).toMatchSnapshot(`structs2000`);
92
-
93
- const outputStructs2400 = fs.readFileSync(
94
- path.join(
95
- workdir,
96
- "providers/test/wafv2-web-acl/index-structs/structs2400.ts",
97
- ),
98
- "utf-8",
99
- );
100
- expect(outputStructs2400).toMatchSnapshot(`structs2400`);
101
-
102
- const outputStructs2800 = fs.readFileSync(
103
- path.join(
104
- workdir,
105
- "providers/test/wafv2-web-acl/index-structs/structs2800.ts",
106
- ),
107
- "utf-8",
108
- );
109
- expect(outputStructs2800).toMatchSnapshot(`structs2800`);
110
-
111
- const outputStructs3200 = fs.readFileSync(
112
- path.join(
113
- workdir,
114
- "providers/test/wafv2-web-acl/index-structs/structs3200.ts",
115
- ),
116
- "utf-8",
117
- );
118
- expect(outputStructs3200).toMatchSnapshot(`structs3200`);
119
-
120
- const outputStructs3600 = fs.readFileSync(
121
- path.join(
122
- workdir,
123
- "providers/test/wafv2-web-acl/index-structs/structs3600.ts",
124
- ),
125
- "utf-8",
126
- );
127
- expect(outputStructs3600).toMatchSnapshot(`structs3600`);
128
- });
129
-
130
- test("shard exports across multiple files to avoid generating files with more than a 1000 exports in a provider without namespaces", async () => {
131
- const code = new CodeMaker();
132
- const workdir = tmp("export-sharding-no-namespace.test");
133
-
134
- const spec = JSON.parse(
135
- fs.readFileSync(
136
- path.join(__dirname, "fixtures", "datadog_dashboard.test.fixture.json"),
137
- "utf-8",
138
- ),
139
- );
140
- new TerraformProviderGenerator(code, spec).generateAll();
141
- await code.save(workdir);
142
-
143
- const output = fs.readFileSync(
144
- path.join(workdir, "providers/datadog/dashboard/index.ts"),
145
- "utf-8",
146
- );
147
- expect(output).toMatchSnapshot(`dashboard-resource`);
148
-
149
- const outputStructsIndex = fs.readFileSync(
150
- path.join(workdir, "providers/datadog/dashboard/index-structs/index.ts"),
151
- "utf-8",
152
- );
153
- expect(outputStructsIndex).toMatchSnapshot(`structs-index`);
154
-
155
- const outputStructs0 = fs.readFileSync(
156
- path.join(workdir, "providers/datadog/dashboard/index-structs/structs0.ts"),
157
- "utf-8",
158
- );
159
- expect(outputStructs0).toMatchSnapshot(`structs0`);
160
-
161
- const outputStructs400 = fs.readFileSync(
162
- path.join(
163
- workdir,
164
- "providers/datadog/dashboard/index-structs/structs400.ts",
165
- ),
166
- "utf-8",
167
- );
168
- expect(outputStructs400).toMatchSnapshot(`structs400`);
169
- });
@@ -1,129 +0,0 @@
1
- // Copyright (c) HashiCorp, Inc
2
- // SPDX-License-Identifier: MPL-2.0
3
- import * as fs from "fs";
4
- import * as os from "os";
5
- import * as path from "path";
6
- import { CodeMaker } from "codemaker";
7
- import {
8
- TerraformProviderGenerator,
9
- type TerraformProviderGeneratorOptions,
10
- } from "../../generator/provider-generator";
11
-
12
- const fixture = JSON.parse(
13
- fs.readFileSync(
14
- path.join(__dirname, "fixtures", "aws_wafv2_web_acl.test.fixture.json"),
15
- "utf-8",
16
- ),
17
- );
18
-
19
- async function generate(options: TerraformProviderGeneratorOptions = {}) {
20
- const code = new CodeMaker();
21
- const workdir = fs.mkdtempSync(path.join(os.tmpdir(), "import-style.test"));
22
- new TerraformProviderGenerator(code, fixture, options).generateAll();
23
- await code.save(workdir);
24
- return workdir;
25
- }
26
-
27
- const RESOURCE_INDEX = "providers/test/wafv2-web-acl/index.ts";
28
- const STRUCTS_INDEX = "providers/test/wafv2-web-acl/index-structs/index.ts";
29
- const STRUCTS_DIR = "providers/test/wafv2-web-acl/index-structs";
30
- const PROVIDER_INDEX = "providers/test/index.ts";
31
-
32
- function readAllShards(workdir: string): string {
33
- return fs
34
- .readdirSync(path.join(workdir, STRUCTS_DIR))
35
- .filter((f) => /^structs\d+\.ts$/.test(f))
36
- .map((f) => fs.readFileSync(path.join(workdir, STRUCTS_DIR, f), "utf-8"))
37
- .join("\n");
38
- }
39
-
40
- test("default (no importExtension): emits explicit /index for folders, bare for files", async () => {
41
- const workdir = await generate();
42
-
43
- const resource = fs.readFileSync(path.join(workdir, RESOURCE_INDEX), "utf-8");
44
- expect(resource).toContain(`} from './index-structs/index'`);
45
- expect(resource).toContain(`export * from './index-structs/index'`);
46
- expect(resource).not.toMatch(/from '\.\/[^']*\.(js|ts)'/);
47
-
48
- const structsIndex = fs.readFileSync(
49
- path.join(workdir, STRUCTS_INDEX),
50
- "utf-8",
51
- );
52
- expect(structsIndex).toContain(`export * from './structs0'`);
53
- expect(structsIndex).not.toMatch(/from '\.\/[^']*\.(js|ts)'/);
54
-
55
- const providerIndex = fs.readFileSync(
56
- path.join(workdir, PROVIDER_INDEX),
57
- "utf-8",
58
- );
59
- expect(providerIndex).toMatch(/from '\.\/[^']+\/index';/);
60
- });
61
-
62
- test("importExtension '.js': emits fully-qualified ./<folder>/index.js and ./<file>.js", async () => {
63
- const workdir = await generate({ importExtension: ".js" });
64
-
65
- const resource = fs.readFileSync(path.join(workdir, RESOURCE_INDEX), "utf-8");
66
- expect(resource).toContain(`} from './index-structs/index.js'`);
67
- expect(resource).toContain(`export * from './index-structs/index.js'`);
68
-
69
- const structsIndex = fs.readFileSync(
70
- path.join(workdir, STRUCTS_INDEX),
71
- "utf-8",
72
- );
73
- expect(structsIndex).toContain(`export * from './structs0.js'`);
74
-
75
- const allShards = readAllShards(workdir);
76
- expect(allShards).toMatch(/from '\.\/structs\d+\.js'/);
77
-
78
- const providerIndex = fs.readFileSync(
79
- path.join(workdir, PROVIDER_INDEX),
80
- "utf-8",
81
- );
82
- expect(providerIndex).toMatch(/from '\.\/[^']+\/index\.js';/);
83
- });
84
-
85
- test("importExtension '.ts': emits fully-qualified ./<folder>/index.ts and ./<file>.ts", async () => {
86
- const workdir = await generate({ importExtension: ".ts" });
87
-
88
- const resource = fs.readFileSync(path.join(workdir, RESOURCE_INDEX), "utf-8");
89
- expect(resource).toContain(`} from './index-structs/index.ts'`);
90
- expect(resource).toContain(`export * from './index-structs/index.ts'`);
91
-
92
- const structsIndex = fs.readFileSync(
93
- path.join(workdir, STRUCTS_INDEX),
94
- "utf-8",
95
- );
96
- expect(structsIndex).toContain(`export * from './structs0.ts'`);
97
-
98
- const allShards = readAllShards(workdir);
99
- expect(allShards).toMatch(/from '\.\/structs\d+\.ts'/);
100
-
101
- const providerIndex = fs.readFileSync(
102
- path.join(workdir, PROVIDER_INDEX),
103
- "utf-8",
104
- );
105
- expect(providerIndex).toMatch(/from '\.\/[^']+\/index\.ts';/);
106
- });
107
-
108
- test("importExtension '': emits explicit /index for folders, bare for files", async () => {
109
- const workdir = await generate({ importExtension: "" });
110
-
111
- const resource = fs.readFileSync(path.join(workdir, RESOURCE_INDEX), "utf-8");
112
- expect(resource).toContain(`} from './index-structs/index'`);
113
- expect(resource).toContain(`export * from './index-structs/index'`);
114
- expect(resource).not.toMatch(/from '\.\/[^']*\.(js|ts)'/);
115
-
116
- const structsIndex = fs.readFileSync(
117
- path.join(workdir, STRUCTS_INDEX),
118
- "utf-8",
119
- );
120
- // file targets get the (empty) extension, so they stay bare
121
- expect(structsIndex).toContain(`export * from './structs0'`);
122
- expect(structsIndex).not.toMatch(/from '\.\/[^']*\.(js|ts)'/);
123
-
124
- const providerIndex = fs.readFileSync(
125
- path.join(workdir, PROVIDER_INDEX),
126
- "utf-8",
127
- );
128
- expect(providerIndex).toMatch(/from '\.\/[^']+\/index';/);
129
- });
@@ -1,89 +0,0 @@
1
- // Copyright (c) HashiCorp, Inc
2
- // SPDX-License-Identifier: MPL-2.0
3
- import * as fs from "fs";
4
- import * as path from "path";
5
- import { CodeMaker } from "codemaker";
6
- import {
7
- ConstructsMakerModuleTarget,
8
- Language,
9
- TerraformModuleConstraint,
10
- TerraformTargetVersions,
11
- } from "@cdktn/commons";
12
- import { ModuleGenerator } from "../../generator/module-generator";
13
- import { createTmpHelper } from "../util";
14
-
15
- const tmp = createTmpHelper();
16
-
17
- async function docsComment(
18
- source: string,
19
- targetVersions?: TerraformTargetVersions,
20
- ): Promise<string> {
21
- const workdir = tmp("module-docs-registry");
22
- const target = ConstructsMakerModuleTarget.from(
23
- new TerraformModuleConstraint(source),
24
- Language.TYPESCRIPT,
25
- ) as ConstructsMakerModuleTarget;
26
- target.spec = { name: target.name, inputs: [], outputs: [] };
27
-
28
- const code = new CodeMaker();
29
- new ModuleGenerator(code, [target], targetVersions);
30
- await code.save(workdir);
31
-
32
- const emitted = fs.readFileSync(path.join(workdir, target.fileName), "utf-8");
33
- const line = emitted
34
- .split("\n")
35
- .find((l) => l.includes("Docs at") || l.includes("Source at"));
36
- return (line ?? "").trim();
37
- }
38
-
39
- describe("generated module docs links", () => {
40
- const module = "terraform-aws-modules/vpc/aws@3.19.0";
41
- const submodule =
42
- "terraform-aws-modules/vpc/aws//modules/vpc-endpoints@3.19.0";
43
-
44
- it("uses the Terraform Registry when nothing is declared", async () => {
45
- expect(await docsComment(module)).toContain(
46
- "https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/3.19.0",
47
- );
48
- });
49
-
50
- it("uses the OpenTofu Registry when only OpenTofu is declared", async () => {
51
- const comment = await docsComment(module, { opentofu: ">=1.6.0" });
52
- expect(comment).toContain("Docs at OpenTofu Registry");
53
- expect(comment).toContain(
54
- "https://search.opentofu.org/module/terraform-aws-modules/vpc/aws/v3.19.0",
55
- );
56
- });
57
-
58
- it("links an OpenTofu submodule with the singular segment", async () => {
59
- expect(await docsComment(submodule, { opentofu: ">=1.6.0" })).toContain(
60
- "https://search.opentofu.org/module/terraform-aws-modules/vpc/aws/v3.19.0/submodule/vpc-endpoints",
61
- );
62
- });
63
-
64
- // Registries serve submodule pages only for a direct child of `modules/`
65
- // (checked against rendered pages); anything else links to the module.
66
- it.each([
67
- [
68
- "an examples path",
69
- "terraform-aws-modules/vpc/aws//examples/complete@3.19.0",
70
- ],
71
- [
72
- "a nested modules path",
73
- "terraform-aws-modules/vpc/aws//modules/x/y@3.19.0",
74
- ],
75
- ])("links %s to the module page", async (_name, source) => {
76
- expect(await docsComment(source)).toContain(
77
- "{@link https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/3.19.0 ",
78
- );
79
- expect(await docsComment(source, { opentofu: ">=1.6.0" })).toContain(
80
- "{@link https://search.opentofu.org/module/terraform-aws-modules/vpc/aws/v3.19.0 ",
81
- );
82
- });
83
-
84
- it("keeps the Terraform submodule shape unchanged", async () => {
85
- expect(await docsComment(submodule)).toContain(
86
- "https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/3.19.0/submodules/vpc-endpoints",
87
- );
88
- });
89
- });