@fjall/generator 0.89.5 → 0.94.0

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 (168) hide show
  1. package/LICENSE +50 -21
  2. package/README.md +28 -0
  3. package/dist/.minified +1 -0
  4. package/dist/src/ast/astCdnParser.d.ts +5 -0
  5. package/dist/src/ast/astCdnParser.js +1 -114
  6. package/dist/src/ast/astCommonParser.d.ts +6 -17
  7. package/dist/src/ast/astCommonParser.js +1 -351
  8. package/dist/src/ast/astComputeConnectionParser.d.ts +18 -0
  9. package/dist/src/ast/astComputeConnectionParser.js +1 -0
  10. package/dist/src/ast/astComputeParser.d.ts +6 -0
  11. package/dist/src/ast/astComputeParser.js +1 -473
  12. package/dist/src/ast/astComputeParserHelpers.d.ts +21 -0
  13. package/dist/src/ast/astComputeParserHelpers.js +1 -0
  14. package/dist/src/ast/astDatabaseParser.d.ts +9 -24
  15. package/dist/src/ast/astDatabaseParser.js +1 -275
  16. package/dist/src/ast/astDomainParser.d.ts +139 -0
  17. package/dist/src/ast/astDomainParser.js +1 -0
  18. package/dist/src/ast/astDynamoDBParser.d.ts +35 -0
  19. package/dist/src/ast/astDynamoDBParser.js +1 -0
  20. package/dist/src/ast/astExpressionEvaluator.d.ts +23 -0
  21. package/dist/src/ast/astExpressionEvaluator.js +1 -0
  22. package/dist/src/ast/astInfrastructureParser.d.ts +12 -49
  23. package/dist/src/ast/astInfrastructureParser.js +1 -552
  24. package/dist/src/ast/astMessagingParser.d.ts +5 -0
  25. package/dist/src/ast/astMessagingParser.js +1 -78
  26. package/dist/src/ast/astNetworkParser.d.ts +6 -0
  27. package/dist/src/ast/astNetworkParser.js +1 -219
  28. package/dist/src/ast/astPatternParser.d.ts +6 -0
  29. package/dist/src/ast/astPatternParser.js +1 -155
  30. package/dist/src/ast/astPlanConverter.d.ts +11 -0
  31. package/dist/src/ast/astPlanConverter.js +2 -0
  32. package/dist/src/ast/astStatementClassifier.d.ts +24 -0
  33. package/dist/src/ast/astStatementClassifier.js +1 -0
  34. package/dist/src/ast/astStatementQueries.d.ts +21 -0
  35. package/dist/src/ast/astStatementQueries.js +3 -0
  36. package/dist/src/ast/astStorageParser.d.ts +5 -0
  37. package/dist/src/ast/astStorageParser.js +1 -164
  38. package/dist/src/ast/astSurgicalModification.js +19 -400
  39. package/dist/src/ast/astTestHelpers.d.ts +635 -0
  40. package/dist/src/ast/astTestHelpers.js +1 -0
  41. package/dist/src/ast/index.d.ts +1 -0
  42. package/dist/src/ast/index.js +1 -6
  43. package/dist/src/aws/regions.js +1 -254
  44. package/dist/src/codemod/_internal.d.ts +12 -0
  45. package/dist/src/codemod/_internal.js +1 -0
  46. package/dist/src/codemod/edits/addResource/bodyIndex.d.ts +34 -0
  47. package/dist/src/codemod/edits/addResource/bodyIndex.js +1 -0
  48. package/dist/src/codemod/edits/addResource/propertyBuilder.d.ts +7 -0
  49. package/dist/src/codemod/edits/addResource/propertyBuilder.js +1 -0
  50. package/dist/src/codemod/edits/addResource.d.ts +9 -0
  51. package/dist/src/codemod/edits/addResource.js +1 -0
  52. package/dist/src/codemod/edits/ensureImports.d.ts +26 -0
  53. package/dist/src/codemod/edits/ensureImports.js +1 -0
  54. package/dist/src/codemod/edits/findInsertionPosition.d.ts +39 -0
  55. package/dist/src/codemod/edits/findInsertionPosition.js +1 -0
  56. package/dist/src/codemod/edits/index.d.ts +5 -0
  57. package/dist/src/codemod/edits/index.js +1 -0
  58. package/dist/src/codemod/edits/modifyResource/literalConversion.d.ts +37 -0
  59. package/dist/src/codemod/edits/modifyResource/literalConversion.js +1 -0
  60. package/dist/src/codemod/edits/modifyResource.d.ts +9 -0
  61. package/dist/src/codemod/edits/modifyResource.js +1 -0
  62. package/dist/src/codemod/edits/removeResource/commentHeuristic.d.ts +31 -0
  63. package/dist/src/codemod/edits/removeResource/commentHeuristic.js +1 -0
  64. package/dist/src/codemod/edits/removeResource/importPruning.d.ts +8 -0
  65. package/dist/src/codemod/edits/removeResource/importPruning.js +1 -0
  66. package/dist/src/codemod/edits/removeResource.d.ts +10 -0
  67. package/dist/src/codemod/edits/removeResource.js +1 -0
  68. package/dist/src/codemod/fileRewriter/builders.d.ts +57 -0
  69. package/dist/src/codemod/fileRewriter/builders.js +1 -0
  70. package/dist/src/codemod/fileRewriter/index.d.ts +4 -0
  71. package/dist/src/codemod/fileRewriter/index.js +1 -0
  72. package/dist/src/codemod/fileRewriter/locateByRange.d.ts +65 -0
  73. package/dist/src/codemod/fileRewriter/locateByRange.js +1 -0
  74. package/dist/src/codemod/fileRewriter/parse.d.ts +18 -0
  75. package/dist/src/codemod/fileRewriter/parse.js +2 -0
  76. package/dist/src/codemod/fileRewriter/print.d.ts +46 -0
  77. package/dist/src/codemod/fileRewriter/print.js +4 -0
  78. package/dist/src/codemod/historyPaths.d.ts +2 -0
  79. package/dist/src/codemod/historyPaths.js +1 -0
  80. package/dist/src/codemod/index.d.ts +7 -0
  81. package/dist/src/codemod/index.js +1 -0
  82. package/dist/src/codemod/listResources.d.ts +4 -0
  83. package/dist/src/codemod/listResources.js +1 -0
  84. package/dist/src/codemod/registry.d.ts +42 -0
  85. package/dist/src/codemod/registry.js +1 -0
  86. package/dist/src/codemod/semanticIndex/findReferences.d.ts +15 -0
  87. package/dist/src/codemod/semanticIndex/findReferences.js +2 -0
  88. package/dist/src/codemod/semanticIndex/index.d.ts +4 -0
  89. package/dist/src/codemod/semanticIndex/index.js +1 -0
  90. package/dist/src/codemod/semanticIndex/listImports.d.ts +24 -0
  91. package/dist/src/codemod/semanticIndex/listImports.js +1 -0
  92. package/dist/src/codemod/semanticIndex/locateByShape.d.ts +28 -0
  93. package/dist/src/codemod/semanticIndex/locateByShape.js +1 -0
  94. package/dist/src/codemod/semanticIndex/projectCache.d.ts +14 -0
  95. package/dist/src/codemod/semanticIndex/projectCache.js +1 -0
  96. package/dist/src/codemod/types.d.ts +172 -0
  97. package/dist/src/codemod/types.js +1 -0
  98. package/dist/src/dns/bindParser.js +2 -224
  99. package/dist/src/dns/bindWriter.js +3 -52
  100. package/dist/src/dns/domainFileGenerator.d.ts +20 -0
  101. package/dist/src/dns/domainFileGenerator.js +207 -0
  102. package/dist/src/dns/domainRecords.d.ts +164 -0
  103. package/dist/src/dns/domainRecords.js +1 -0
  104. package/dist/src/dns/index.d.ts +2 -1
  105. package/dist/src/dns/index.js +1 -4
  106. package/dist/src/dns/types.js +1 -52
  107. package/dist/src/generation/common.js +6 -161
  108. package/dist/src/generation/compute.js +82 -590
  109. package/dist/src/generation/database.js +12 -198
  110. package/dist/src/generation/generatePatternCode.d.ts +58 -0
  111. package/dist/src/generation/generatePatternCode.js +33 -0
  112. package/dist/src/generation/index.js +1 -20
  113. package/dist/src/generation/infrastructure.d.ts +1 -5
  114. package/dist/src/generation/infrastructure.js +35 -377
  115. package/dist/src/generation/messagingConnections.js +1 -73
  116. package/dist/src/generation/storage.d.ts +0 -15
  117. package/dist/src/generation/storage.js +35 -168
  118. package/dist/src/generation/storageConnections.js +1 -75
  119. package/dist/src/planning/generateResourceChange.d.ts +21 -0
  120. package/dist/src/planning/generateResourceChange.js +1 -0
  121. package/dist/src/planning/index.d.ts +3 -0
  122. package/dist/src/planning/index.js +1 -1
  123. package/dist/src/planning/resourceAddition.d.ts +154 -0
  124. package/dist/src/planning/resourceAddition.js +1 -0
  125. package/dist/src/planning/resourceConnections.d.ts +19 -0
  126. package/dist/src/planning/resourceConnections.js +1 -0
  127. package/dist/src/planning/resourcePlanning.js +1 -214
  128. package/dist/src/presets/index.js +1 -3
  129. package/dist/src/presets/patternTierPresets.js +1 -131
  130. package/dist/src/presets/storagePresets.js +1 -36
  131. package/dist/src/presets/tierPresets.d.ts +5 -8
  132. package/dist/src/presets/tierPresets.js +1 -384
  133. package/dist/src/presets/tierTypes.d.ts +1 -1
  134. package/dist/src/presets/tierTypes.js +0 -7
  135. package/dist/src/schemas/alarmSchemas.d.ts +19 -0
  136. package/dist/src/schemas/alarmSchemas.js +1 -0
  137. package/dist/src/schemas/applicationSchemas.d.ts +22 -6
  138. package/dist/src/schemas/applicationSchemas.js +1 -80
  139. package/dist/src/schemas/baseSchemas.d.ts +8 -3
  140. package/dist/src/schemas/baseSchemas.js +2 -248
  141. package/dist/src/schemas/cdnSchemas.js +1 -62
  142. package/dist/src/schemas/computeSchemas.d.ts +25 -3
  143. package/dist/src/schemas/computeSchemas.js +1 -727
  144. package/dist/src/schemas/constants.d.ts +5 -7
  145. package/dist/src/schemas/constants.js +1 -218
  146. package/dist/src/schemas/databaseSchemas.d.ts +6 -1
  147. package/dist/src/schemas/databaseSchemas.js +1 -366
  148. package/dist/src/schemas/index.js +1 -3
  149. package/dist/src/schemas/instanceTypeArchitecture.js +1 -75
  150. package/dist/src/schemas/messagingSchemas.js +1 -29
  151. package/dist/src/schemas/networkSchemas.js +1 -125
  152. package/dist/src/schemas/patternSchemas.d.ts +1 -1
  153. package/dist/src/schemas/patternSchemas.js +1 -294
  154. package/dist/src/schemas/resourceSchemas.d.ts +1 -0
  155. package/dist/src/schemas/resourceSchemas.js +1 -28
  156. package/dist/src/schemas/sharedTypes.d.ts +18 -0
  157. package/dist/src/schemas/sharedTypes.js +1 -0
  158. package/dist/src/schemas/storageSchemas.d.ts +1 -0
  159. package/dist/src/schemas/storageSchemas.js +1 -119
  160. package/dist/src/types/Result.js +1 -31
  161. package/dist/src/util/errorUtils.js +1 -1
  162. package/dist/src/validation/patterns.d.ts +9 -0
  163. package/dist/src/validation/patterns.js +1 -369
  164. package/dist/src/version.d.ts +1 -1
  165. package/dist/src/version.js +1 -1
  166. package/package.json +29 -9
  167. package/dist/src/dns/infrastructureWriter.d.ts +0 -2
  168. package/dist/src/dns/infrastructureWriter.js +0 -58
@@ -1,389 +1,47 @@
1
- /**
2
- * Infrastructure Code Generation
3
- *
4
- * Functions for generating infrastructure setup code including
5
- * network configuration, tags, imports, CDN, and app initialisation.
6
- */
7
- import { toVariableName, toPascalCase, formatValue, resolveResourceVariable, emitExtraProperties, } from "./common.js";
8
- import { COMPUTE_TYPE } from "../schemas/constants.js";
9
- export const COST_ALLOCATION_TAG = "fjall:costAllocation:owner";
10
- export const DEFAULT_COST_ALLOCATION_OWNER = "engineering";
11
- /**
12
- * Check if value is an empty object {}.
13
- * Used to filter out meaningless config like `flowLogs: {}`.
14
- */
15
- function isEmptyObject(value) {
16
- return (typeof value === "object" &&
17
- value !== null &&
18
- Object.keys(value).length === 0);
19
- }
20
- /**
21
- * Clean network config by removing empty flowLogs.
22
- * `flowLogs: {}` means "use defaults" which is the same as omitting it.
23
- * Only keep flowLogs when it's `false` (explicitly disabled) or has config.
24
- */
25
- function cleanNetworkConfig(network) {
26
- const cleaned = { ...network };
27
- if (isEmptyObject(cleaned.flowLogs)) {
28
- delete cleaned.flowLogs;
29
- }
30
- return cleaned;
31
- }
32
- /**
33
- * Generate network infrastructure code for additional networks
34
- */
35
- export function generateNetworkCode(plan) {
36
- if (!plan.additionalNetworks || plan.additionalNetworks.length === 0) {
37
- return "";
38
- }
39
- let code = "";
40
- for (const network of plan.additionalNetworks) {
41
- const varName = toVariableName(network.name);
42
- const config = {};
43
- if (network.maxAzs !== undefined)
44
- config.maxAzs = network.maxAzs;
45
- if (network.natGateways !== undefined)
46
- config.natGateways = network.natGateways;
47
- if (network.flowLogs !== undefined)
48
- config.flowLogs = network.flowLogs;
49
- if (network.vpcEndpoints !== undefined)
50
- config.vpcEndpoints = network.vpcEndpoints;
51
- const cleanedConfig = cleanNetworkConfig(config);
52
- code += `const ${varName} = app.addNetwork(
53
- NetworkFactory.build("${network.name}", ${formatValue(cleanedConfig, " ")})
1
+ import{toVariableName as m,formatValue as a,resolveResourceVariable as f,emitExtraProperties as g}from"./common.js";import{COMPUTE_TYPE as d}from"../schemas/constants.js";import{OPENNEXT_DEFAULTS as O,generatePatternCodeWithComments as P}from"./generatePatternCode.js";const u="fjall:costAllocation:owner",h="engineering";function l(e){return typeof e=="object"&&e!==null&&Object.keys(e).length===0}function p(e){const t={...e};return l(t.flowLogs)&&delete t.flowLogs,t}function A(e){if(!e.additionalNetworks||e.additionalNetworks.length===0)return"";let t="";for(const n of e.additionalNetworks){const i=m(n.name),o={};n.maxAzs!==void 0&&(o.maxAzs=n.maxAzs),n.natGateways!==void 0&&(o.natGateways=n.natGateways),n.flowLogs!==void 0&&(o.flowLogs=n.flowLogs),n.vpcEndpoints!==void 0&&(o.vpcEndpoints=n.vpcEndpoints);const c=p(o);t+=`const ${i} = app.addNetwork(
2
+ NetworkFactory.build("${n.name}", ${a(c," ")})
54
3
  );
55
4
 
56
- `;
57
- }
58
- return code;
59
- }
60
- /**
61
- * Generate tags infrastructure code
62
- */
63
- export function generateTags(plan) {
64
- const tags = {};
65
- if (plan.tags && Object.keys(plan.tags).length > 0) {
66
- Object.assign(tags, plan.tags);
67
- }
68
- if (!tags[COST_ALLOCATION_TAG]) {
69
- tags[COST_ALLOCATION_TAG] = plan.owner || DEFAULT_COST_ALLOCATION_OWNER;
70
- }
71
- const tagEntries = Object.entries(tags)
72
- .map(([key, value]) => ` "${key}": "${value}"`)
73
- .join(",\n");
74
- return `app.addTags({
75
- ${tagEntries}
5
+ `}return t}function $(e){const t={};return e.tags&&Object.keys(e.tags).length>0&&Object.assign(t,e.tags),t[u]||(t[u]=e.owner||h),`app.addTags({
6
+ ${Object.entries(t).map(([i,o])=>` "${i}": "${o}"`).join(`,
7
+ `)}
76
8
  });
77
9
 
78
- `;
79
- }
80
- /**
81
- * Generate app initialisation code
82
- */
83
- export function generateAppInit(plan) {
84
- let code = `
85
- const appName = "${plan.appName}";
86
- `;
87
- const backupConfig = plan.backup && typeof plan.backup === "object" ? plan.backup : undefined;
88
- const tunnelConfig = plan.tunnel && typeof plan.tunnel === "object" ? plan.tunnel : undefined;
89
- const tunnelSnippet = tunnelConfig
90
- ? tunnelConfig.instanceType
91
- ? `tunnel: { instanceType: "${tunnelConfig.instanceType}" }`
92
- : "tunnel: true"
93
- : undefined;
94
- if (plan.vpcId) {
95
- code += `const app = App.getApp(appName, {
96
- network: { useExisting: "${plan.vpcId}" }`;
97
- if (backupConfig) {
98
- code += `,
99
- backup: { tier: "${backupConfig.tier}" }`;
100
- }
101
- if (tunnelSnippet) {
102
- code += `,
103
- ${tunnelSnippet}`;
104
- }
105
- code += `
10
+ `}function w(e){let t=`
11
+ const appName = "${e.appName}";
12
+ `;const n=e.backup&&typeof e.backup=="object"?e.backup:void 0,i=e.tunnel&&typeof e.tunnel=="object"?e.tunnel:void 0,o=i?i.instanceType?`tunnel: { instanceType: "${i.instanceType}" }`:"tunnel: true":void 0;if(e.vpcId)t+=`const app = App.getApp(appName, {
13
+ network: { useExisting: "${e.vpcId}" }`,n&&(t+=`,
14
+ backup: { tier: "${n.tier}" }`),o&&(t+=`,
15
+ ${o}`),t+=`
106
16
  });
107
- `;
108
- }
109
- else if (plan.network) {
110
- const cleanedNetwork = cleanNetworkConfig(plan.network);
111
- code += `const app = App.getApp(appName, {
112
- network: ${formatValue(cleanedNetwork, " ")}`;
113
- if (backupConfig) {
114
- code += `,
115
- backup: { tier: "${backupConfig.tier}" }`;
116
- }
117
- if (tunnelSnippet) {
118
- code += `,
119
- ${tunnelSnippet}`;
120
- }
121
- code += `
17
+ `;else if(e.network){const c=p(e.network);t+=`const app = App.getApp(appName, {
18
+ network: ${a(c," ")}`,n&&(t+=`,
19
+ backup: { tier: "${n.tier}" }`),o&&(t+=`,
20
+ ${o}`),t+=`
122
21
  });
123
- `;
124
- }
125
- else {
126
- code += `const app = App.getApp(appName, { network: false`;
127
- if (backupConfig) {
128
- code += `, backup: { tier: "${backupConfig.tier}" }`;
129
- }
130
- if (tunnelSnippet) {
131
- code += `, ${tunnelSnippet}`;
132
- }
133
- code += ` });
134
- `;
135
- }
136
- code += `
137
- `;
138
- return code;
139
- }
140
- /**
141
- * Generate import statements for the infrastructure file
142
- */
143
- export function generateImports(plan) {
144
- const imports = [];
145
- if (plan.patternConfig) {
146
- imports.push("PatternFactory");
147
- }
148
- else {
149
- if (plan.database.length > 0) {
150
- imports.push("DatabaseFactory");
151
- }
152
- if (plan.s3.length > 0) {
153
- imports.push("StorageFactory");
154
- }
155
- if (plan.compute.length > 0) {
156
- imports.push("ComputeFactory");
157
- imports.push("getConfig");
158
- }
159
- if (plan.dynamodb &&
160
- plan.dynamodb.length > 0 &&
161
- plan.database.length === 0) {
162
- imports.push("DatabaseFactory");
163
- }
164
- if (plan.sqs && plan.sqs.length > 0) {
165
- imports.push("MessagingFactory");
166
- }
167
- if (plan.cdn) {
168
- imports.push("CdnFactory");
169
- }
170
- const hasCodeBasedLambda = plan.compute.some((c) => c.type === COMPUTE_TYPE.LAMBDA && c.deployment === "code");
171
- if (hasCodeBasedLambda) {
172
- imports.push("Code");
173
- imports.push("Runtime");
174
- }
175
- const hasFunctionUrl = plan.compute.some((c) => c.type === COMPUTE_TYPE.LAMBDA && c.functionUrl);
176
- if (hasFunctionUrl) {
177
- imports.push("FunctionUrlAuthType");
178
- }
179
- const hasArchitecture = plan.compute.some((c) => c.type === COMPUTE_TYPE.LAMBDA &&
180
- (c.architecture || c.deployment === "container"));
181
- if (hasArchitecture) {
182
- imports.push("Architecture");
183
- }
184
- }
185
- if (plan.additionalNetworks && plan.additionalNetworks.length > 0) {
186
- imports.push("NetworkFactory");
187
- }
188
- // Merge additional named imports for @fjall/components-infrastructure
189
- if (plan.additionalManagedImports) {
190
- for (const extra of plan.additionalManagedImports) {
191
- if (extra.moduleSpecifier === "@fjall/components-infrastructure" ||
192
- extra.moduleSpecifier === "@fjall/infrastructure") {
193
- for (const name of extra.namedImports) {
194
- if (!imports.includes(name)) {
195
- imports.push(name);
196
- }
197
- }
198
- }
199
- }
200
- }
201
- const importList = imports.length > 0 ? `, ${imports.join(", ")}` : "";
202
- let code = `#!/usr/bin/env node
22
+ `}else t+="const app = App.getApp(appName, { network: false",n&&(t+=`, backup: { tier: "${n.tier}" }`),o&&(t+=`, ${o}`),t+=` });
23
+ `;return t+=`
24
+ `,t}function k(e){const t=[];if(e.patternConfig?t.push("PatternFactory"):(e.database.length>0&&t.push("DatabaseFactory"),e.s3.length>0&&t.push("StorageFactory"),e.compute.length>0&&t.push("ComputeFactory"),(e.compute.length>0||e.database.length>0)&&t.push("getConfig"),e.dynamodb&&e.dynamodb.length>0&&e.database.length===0&&t.push("DatabaseFactory"),e.sqs&&e.sqs.length>0&&t.push("MessagingFactory"),e.cdn&&t.push("CdnFactory"),e.compute.some(r=>r.type===d.LAMBDA&&r.deployment==="code")&&(t.push("Code"),t.push("Runtime")),e.compute.some(r=>r.type===d.LAMBDA&&r.functionUrl)&&t.push("FunctionUrlAuthType"),e.compute.some(r=>r.type===d.LAMBDA&&(r.architecture||r.deployment==="container"))&&t.push("Architecture")),e.additionalNetworks&&e.additionalNetworks.length>0&&t.push("NetworkFactory"),e.additionalManagedImports){for(const o of e.additionalManagedImports)if(o.moduleSpecifier==="@fjall/components-infrastructure"||o.moduleSpecifier==="@fjall/infrastructure")for(const c of o.namedImports)t.includes(c)||t.push(c)}let i=`#!/usr/bin/env node
203
25
 
204
- import { App${importList} } from "@fjall/components-infrastructure";
205
- `;
206
- // Append separate lines for other managed modules (aws-cdk-lib/*, constructs)
207
- if (plan.additionalManagedImports) {
208
- for (const extra of plan.additionalManagedImports) {
209
- if (extra.moduleSpecifier === "@fjall/components-infrastructure" ||
210
- extra.moduleSpecifier === "@fjall/infrastructure") {
211
- continue;
212
- }
213
- const namedPart = extra.namedImports.length > 0
214
- ? `{ ${extra.namedImports.join(", ")} }`
215
- : "";
216
- const defaultPart = extra.defaultImport ?? "";
217
- const importParts = [defaultPart, namedPart].filter(Boolean).join(", ");
218
- if (importParts) {
219
- code += `import ${importParts} from "${extra.moduleSpecifier}";\n`;
220
- }
221
- }
222
- }
223
- return code;
224
- }
225
- /**
226
- * Generate CDN infrastructure code
227
- */
228
- export function generateCDNCode(plan) {
229
- if (!plan.cdn)
230
- return "";
231
- const defaultOriginVar = resolveResourceVariable(plan, plan.cdn.defaultOriginRef);
232
- let code = `
26
+ import { App${t.length>0?`, ${t.join(", ")}`:""} } from "@fjall/components-infrastructure";
27
+ `;if(e.additionalManagedImports)for(const o of e.additionalManagedImports){if(o.moduleSpecifier==="@fjall/components-infrastructure"||o.moduleSpecifier==="@fjall/infrastructure")continue;const c=o.namedImports.length>0?`{ ${o.namedImports.join(", ")} }`:"",r=[o.defaultImport??"",c].filter(Boolean).join(", ");r&&(i+=`import ${r} from "${o.moduleSpecifier}";
28
+ `)}return i}function C(e){if(!e.cdn)return"";const t=f(e,e.cdn.defaultOriginRef);let n=`
233
29
  app.addCdn(
234
- CdnFactory.build("${plan.cdn.name}", {
30
+ CdnFactory.build("${e.cdn.name}", {
235
31
  originType: "auto",
236
- origin: ${defaultOriginVar}`;
237
- if (plan.cdn.behaviours && plan.cdn.behaviours.length > 0) {
238
- const behavioursStr = plan.cdn.behaviours
239
- .map((b) => {
240
- const originVar = resolveResourceVariable(plan, b.originRef);
241
- let bCode = `{\n pathPattern: "${b.pathPattern}",\n origin: ${originVar},`;
242
- if (b.cachePolicy) {
243
- bCode += `\n cachePolicy: "${b.cachePolicy}",`;
244
- }
245
- bCode += `\n }`;
246
- return bCode;
247
- })
248
- .join(",\n ");
249
- code += `,
32
+ origin: ${t}`;if(e.cdn.behaviours&&e.cdn.behaviours.length>0){const i=e.cdn.behaviours.map(o=>{const c=f(e,o.originRef);let s=`{
33
+ pathPattern: "${o.pathPattern}",
34
+ origin: ${c},`;return o.cachePolicy&&(s+=`
35
+ cachePolicy: "${o.cachePolicy}",`),s+=`
36
+ }`,s}).join(`,
37
+ `);n+=`,
250
38
  behaviours: [
251
- ${behavioursStr}
252
- ]`;
253
- }
254
- if (plan.cdn.customDomain) {
255
- code += `,
256
- domainNames: ["${plan.cdn.customDomain}"]`;
257
- }
258
- if (plan.cdn.certificateArn) {
259
- code += `,
260
- certificateArn: "${plan.cdn.certificateArn}"`;
261
- }
262
- if (plan.cdn.accessGate !== undefined) {
263
- if (plan.cdn.accessGate === false) {
264
- code += `,
265
- accessGate: false`;
266
- }
267
- else {
268
- code += `,
269
- accessGate: ${formatValue(plan.cdn.accessGate, " ")}`;
270
- }
271
- }
272
- code += emitExtraProperties(plan.cdn.extraProperties);
273
- code += `
39
+ ${i}
40
+ ]`}return e.cdn.customDomain&&(n+=`,
41
+ domainNames: ["${e.cdn.customDomain}"]`),e.cdn.certificateArn&&(n+=`,
42
+ certificateArn: "${e.cdn.certificateArn}"`),e.cdn.accessGate!==void 0&&(e.cdn.accessGate===!1?n+=`,
43
+ accessGate: false`:n+=`,
44
+ accessGate: ${a(e.cdn.accessGate," ")}`),n+=g(e.cdn.extraProperties),n+=`
274
45
  })
275
46
  );
276
- `;
277
- return code;
278
- }
279
- /**
280
- * Collect CDN-referenced resources for compute variable naming
281
- */
282
- export function collectCdnReferencedResources(plan) {
283
- const cdnReferencedResources = new Set();
284
- if (plan.cdn) {
285
- if (plan.cdn.defaultOriginRef) {
286
- cdnReferencedResources.add(plan.cdn.defaultOriginRef);
287
- }
288
- if (plan.cdn.behaviours) {
289
- for (const behaviour of plan.cdn.behaviours) {
290
- cdnReferencedResources.add(behaviour.originRef);
291
- }
292
- }
293
- }
294
- return cdnReferencedResources;
295
- }
296
- /**
297
- * Check if a plan uses the pattern approach (PatternFactory).
298
- * When patternConfig is present, we generate a single PatternFactory.build() call
299
- * instead of individual factory calls for each resource.
300
- */
301
- export function usesPatternApproach(plan) {
302
- return plan.patternConfig !== undefined;
303
- }
304
- /** Default values for OpenNext pattern code generation (matches tier presets). */
305
- const OPENNEXT_DEFAULTS = Object.freeze({
306
- database: {
307
- type: "Instance",
308
- backupRetention: 7,
309
- deletionProtection: true,
310
- },
311
- compute: {
312
- server: { memorySize: 1536, timeout: 30 },
313
- imageOptimisation: { memorySize: 1536, timeout: 30 },
314
- revalidation: { memorySize: 768, timeout: 300 },
315
- },
316
- });
317
- /**
318
- * Generate pattern infrastructure code with clean formatting.
319
- * Handles both Payload and Next.js OpenNext patterns.
320
- */
321
- export function generatePatternCodeWithComments(plan) {
322
- if (!plan.patternConfig)
323
- return "";
324
- const config = plan.patternConfig;
325
- const pascalName = toPascalCase(config.name);
326
- const typeSuffix = config.type === "payload" ? "Payload" : "Nextjs";
327
- const constructId = `${pascalName}${typeSuffix}`;
328
- let code = `app.addPattern(
329
- PatternFactory.build("${constructId}", {
330
- type: "${config.type}",
331
- name: "${config.name}",`;
332
- if (config.domain) {
333
- code += `
334
- domain: "${config.domain}",`;
335
- }
336
- if (config.type === "payload" || config.type === "nextjs") {
337
- const db = config.database || {};
338
- const compute = config.compute || {};
339
- const dbType = db.type || OPENNEXT_DEFAULTS.database.type;
340
- const backupRetention = db.backupRetention ?? OPENNEXT_DEFAULTS.database.backupRetention;
341
- const deletionProtection = db.deletionProtection ?? OPENNEXT_DEFAULTS.database.deletionProtection;
342
- code += `
343
- database: {
344
- type: "${dbType}",`;
345
- if (db.databaseName) {
346
- code += `
347
- databaseName: "${db.databaseName}",`;
348
- }
349
- if (dbType === "Instance" && db.instanceType) {
350
- code += `
351
- instanceType: "${db.instanceType}",`;
352
- }
353
- code += `
354
- backupRetention: ${backupRetention},
355
- deletionProtection: ${deletionProtection},
356
- },`;
357
- const serverMemory = compute.server?.memorySize ?? OPENNEXT_DEFAULTS.compute.server.memorySize;
358
- const serverTimeout = compute.server?.timeout ?? OPENNEXT_DEFAULTS.compute.server.timeout;
359
- const imageMemory = compute.imageOptimisation?.memorySize ??
360
- OPENNEXT_DEFAULTS.compute.imageOptimisation.memorySize;
361
- const imageTimeout = compute.imageOptimisation?.timeout ??
362
- OPENNEXT_DEFAULTS.compute.imageOptimisation.timeout;
363
- const revalidationMemory = compute.revalidation?.memorySize ??
364
- OPENNEXT_DEFAULTS.compute.revalidation.memorySize;
365
- const revalidationTimeout = compute.revalidation?.timeout ??
366
- OPENNEXT_DEFAULTS.compute.revalidation.timeout;
367
- code += `
368
- compute: {
369
- server: {
370
- memorySize: ${serverMemory},
371
- timeout: ${serverTimeout},
372
- },
373
- imageOptimisation: {
374
- memorySize: ${imageMemory},
375
- timeout: ${imageTimeout},
376
- },
377
- revalidation: {
378
- memorySize: ${revalidationMemory},
379
- timeout: ${revalidationTimeout},
380
- },
381
- },`;
382
- }
383
- code += `
384
- })
385
- );
386
-
387
- `;
388
- return code;
389
- }
47
+ `,n}function N(e){const t=new Set;if(e.cdn&&(e.cdn.defaultOriginRef&&t.add(e.cdn.defaultOriginRef),e.cdn.behaviours))for(const n of e.cdn.behaviours)t.add(n.originRef);return t}function j(e){return e.patternConfig!==void 0}export{u as COST_ALLOCATION_TAG,h as DEFAULT_COST_ALLOCATION_OWNER,O as OPENNEXT_DEFAULTS,N as collectCdnReferencedResources,w as generateAppInit,C as generateCDNCode,k as generateImports,A as generateNetworkCode,P as generatePatternCodeWithComments,$ as generateTags,j as usesPatternApproach};
@@ -1,73 +1 @@
1
- /**
2
- * Messaging Connection Code Generation
3
- *
4
- * Functions for generating messaging connection code (env vars, connections array)
5
- * following the same pattern as database and storage connections.
6
- */
7
- import { getVariableName } from "./common.js";
8
- export const MESSAGING_ENV_VARS = Object.freeze({
9
- URL: "QUEUE_URL",
10
- ARN: "QUEUE_ARN",
11
- });
12
- /**
13
- * Get SQS queues connected to a compute resource
14
- */
15
- export function getConnectedMessaging(plan, compute) {
16
- const { connectedMessaging } = compute;
17
- if (!connectedMessaging?.length)
18
- return [];
19
- return (plan.sqs ?? []).filter((queue) => connectedMessaging.includes(queue.name));
20
- }
21
- /**
22
- * Generate messaging environment variable entries for a list of connected queues.
23
- * SQS uses IAM-based access, so there are no secrets — only QUEUE_URL and QUEUE_ARN env vars.
24
- */
25
- export function generateMessagingEnvVarEntries(connectedMessaging) {
26
- const entries = [];
27
- if (connectedMessaging.length === 1) {
28
- const queue = connectedMessaging[0];
29
- if (!queue)
30
- return entries;
31
- const queueVar = getVariableName(queue);
32
- entries.push({
33
- key: MESSAGING_ENV_VARS.URL,
34
- expression: `${queueVar}.getQueueUrl()`,
35
- });
36
- entries.push({
37
- key: MESSAGING_ENV_VARS.ARN,
38
- expression: `${queueVar}.getQueueArn()`,
39
- });
40
- }
41
- else {
42
- for (const [index, queue] of connectedMessaging.entries()) {
43
- const queueVar = getVariableName(queue);
44
- const suffix = index === 0 ? "" : `_${index + 1}`;
45
- entries.push({
46
- key: `${MESSAGING_ENV_VARS.URL}${suffix}`,
47
- expression: `${queueVar}.getQueueUrl()`,
48
- });
49
- entries.push({
50
- key: `${MESSAGING_ENV_VARS.ARN}${suffix}`,
51
- expression: `${queueVar}.getQueueArn()`,
52
- });
53
- }
54
- }
55
- return entries;
56
- }
57
- /**
58
- * Build messaging environment variables for a compute resource.
59
- * SQS always uses IAM — secrets is always empty.
60
- */
61
- export function buildMessagingEnvVars(plan, compute) {
62
- const env = {};
63
- const secrets = {};
64
- if (!compute.connectedMessaging?.length) {
65
- return { env, secrets };
66
- }
67
- const connectedMessaging = getConnectedMessaging(plan, compute);
68
- const entries = generateMessagingEnvVarEntries(connectedMessaging);
69
- for (const entry of entries) {
70
- env[entry.key] = { __expression: entry.expression };
71
- }
72
- return { env, secrets };
73
- }
1
+ import{getVariableName as c}from"./common.js";const u=Object.freeze({URL:"QUEUE_URL",ARN:"QUEUE_ARN"});function g(t,n){const{connectedMessaging:e}=n;return e?.length?(t.sqs??[]).filter(s=>e.includes(s.name)):[]}function f(t){const n=[];if(t.length===1){const e=t[0];if(!e)return n;const s=c(e);n.push({key:u.URL,expression:`${s}.getQueueUrl()`}),n.push({key:u.ARN,expression:`${s}.getQueueArn()`})}else for(const[e,s]of t.entries()){const r=c(s),o=e===0?"":`_${e+1}`;n.push({key:`${u.URL}${o}`,expression:`${r}.getQueueUrl()`}),n.push({key:`${u.ARN}${o}`,expression:`${r}.getQueueArn()`})}return n}function a(t,n){const e={},s={};if(!n.connectedMessaging?.length)return{env:e,secrets:s};const r=g(t,n),o=f(r);for(const i of o)e[i.key]={__expression:i.expression};return{env:e,secrets:s}}export{u as MESSAGING_ENV_VARS,a as buildMessagingEnvVars,f as generateMessagingEnvVarEntries,g as getConnectedMessaging};
@@ -1,27 +1,12 @@
1
- /**
2
- * Storage Code Generation
3
- *
4
- * Functions for generating storage infrastructure code including
5
- * S3 buckets, DynamoDB tables, and SQS queues.
6
- */
7
1
  import type { ApplicationResourcePlan, S3ResourcePlan, SQSResourcePlan } from "../schemas/resourceSchemas.js";
8
2
  /**
9
3
  * Check if an S3 bucket needs a variable assignment (referenced by compute or CDN)
10
4
  */
11
5
  export declare function s3NeedsVariable(bucket: S3ResourcePlan, plan: ApplicationResourcePlan): boolean;
12
- /**
13
- * Generate S3 bucket infrastructure code
14
- */
15
6
  export declare function generateS3Code(plan: ApplicationResourcePlan): string;
16
- /**
17
- * Generate DynamoDB table infrastructure code
18
- */
19
7
  export declare function generateDynamoDBCode(plan: ApplicationResourcePlan): string;
20
8
  /**
21
9
  * Check if an SQS queue needs a variable assignment (referenced by compute)
22
10
  */
23
11
  export declare function sqsNeedsVariable(queue: SQSResourcePlan, plan: ApplicationResourcePlan): boolean;
24
- /**
25
- * Generate SQS queue infrastructure code
26
- */
27
12
  export declare function generateSQSCode(plan: ApplicationResourcePlan): string;