@fjall/generator 0.89.4 → 0.89.6
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 +50 -21
- package/README.md +28 -0
- package/dist/.minified +1 -0
- package/dist/src/ast/astCdnParser.d.ts +5 -0
- package/dist/src/ast/astCdnParser.js +1 -114
- package/dist/src/ast/astCommonParser.d.ts +6 -17
- package/dist/src/ast/astCommonParser.js +1 -351
- package/dist/src/ast/astComputeConnectionParser.d.ts +18 -0
- package/dist/src/ast/astComputeConnectionParser.js +1 -0
- package/dist/src/ast/astComputeParser.d.ts +6 -0
- package/dist/src/ast/astComputeParser.js +1 -473
- package/dist/src/ast/astComputeParserHelpers.d.ts +21 -0
- package/dist/src/ast/astComputeParserHelpers.js +1 -0
- package/dist/src/ast/astDatabaseParser.d.ts +9 -24
- package/dist/src/ast/astDatabaseParser.js +1 -275
- package/dist/src/ast/astDomainParser.d.ts +139 -0
- package/dist/src/ast/astDomainParser.js +1 -0
- package/dist/src/ast/astDynamoDBParser.d.ts +35 -0
- package/dist/src/ast/astDynamoDBParser.js +1 -0
- package/dist/src/ast/astExpressionEvaluator.d.ts +23 -0
- package/dist/src/ast/astExpressionEvaluator.js +1 -0
- package/dist/src/ast/astInfrastructureParser.d.ts +12 -49
- package/dist/src/ast/astInfrastructureParser.js +1 -552
- package/dist/src/ast/astMessagingParser.d.ts +5 -0
- package/dist/src/ast/astMessagingParser.js +1 -78
- package/dist/src/ast/astNetworkParser.d.ts +6 -0
- package/dist/src/ast/astNetworkParser.js +1 -219
- package/dist/src/ast/astPatternParser.d.ts +6 -0
- package/dist/src/ast/astPatternParser.js +1 -155
- package/dist/src/ast/astPlanConverter.d.ts +11 -0
- package/dist/src/ast/astPlanConverter.js +2 -0
- package/dist/src/ast/astStatementClassifier.d.ts +24 -0
- package/dist/src/ast/astStatementClassifier.js +1 -0
- package/dist/src/ast/astStatementQueries.d.ts +21 -0
- package/dist/src/ast/astStatementQueries.js +3 -0
- package/dist/src/ast/astStorageParser.d.ts +5 -0
- package/dist/src/ast/astStorageParser.js +1 -164
- package/dist/src/ast/astSurgicalModification.js +19 -400
- package/dist/src/ast/astTestHelpers.d.ts +635 -0
- package/dist/src/ast/astTestHelpers.js +1 -0
- package/dist/src/ast/index.d.ts +1 -0
- package/dist/src/ast/index.js +1 -6
- package/dist/src/aws/regions.js +1 -254
- package/dist/src/codemod/_internal.d.ts +12 -0
- package/dist/src/codemod/_internal.js +1 -0
- package/dist/src/codemod/edits/addResource/bodyIndex.d.ts +34 -0
- package/dist/src/codemod/edits/addResource/bodyIndex.js +1 -0
- package/dist/src/codemod/edits/addResource/propertyBuilder.d.ts +7 -0
- package/dist/src/codemod/edits/addResource/propertyBuilder.js +1 -0
- package/dist/src/codemod/edits/addResource.d.ts +9 -0
- package/dist/src/codemod/edits/addResource.js +1 -0
- package/dist/src/codemod/edits/ensureImports.d.ts +26 -0
- package/dist/src/codemod/edits/ensureImports.js +1 -0
- package/dist/src/codemod/edits/findInsertionPosition.d.ts +39 -0
- package/dist/src/codemod/edits/findInsertionPosition.js +1 -0
- package/dist/src/codemod/edits/index.d.ts +6 -0
- package/dist/src/codemod/edits/index.js +1 -0
- package/dist/src/codemod/edits/modifyResource/literalConversion.d.ts +37 -0
- package/dist/src/codemod/edits/modifyResource/literalConversion.js +1 -0
- package/dist/src/codemod/edits/modifyResource.d.ts +9 -0
- package/dist/src/codemod/edits/modifyResource.js +1 -0
- package/dist/src/codemod/edits/removeResource/commentHeuristic.d.ts +31 -0
- package/dist/src/codemod/edits/removeResource/commentHeuristic.js +1 -0
- package/dist/src/codemod/edits/removeResource/importPruning.d.ts +8 -0
- package/dist/src/codemod/edits/removeResource/importPruning.js +1 -0
- package/dist/src/codemod/edits/removeResource.d.ts +10 -0
- package/dist/src/codemod/edits/removeResource.js +1 -0
- package/dist/src/codemod/edits/schemaFragments.d.ts +9 -0
- package/dist/src/codemod/edits/schemaFragments.js +1 -0
- package/dist/src/codemod/fileRewriter/builders.d.ts +57 -0
- package/dist/src/codemod/fileRewriter/builders.js +1 -0
- package/dist/src/codemod/fileRewriter/index.d.ts +4 -0
- package/dist/src/codemod/fileRewriter/index.js +1 -0
- package/dist/src/codemod/fileRewriter/locateByRange.d.ts +65 -0
- package/dist/src/codemod/fileRewriter/locateByRange.js +1 -0
- package/dist/src/codemod/fileRewriter/parse.d.ts +18 -0
- package/dist/src/codemod/fileRewriter/parse.js +2 -0
- package/dist/src/codemod/fileRewriter/print.d.ts +46 -0
- package/dist/src/codemod/fileRewriter/print.js +4 -0
- package/dist/src/codemod/historyPaths.d.ts +2 -0
- package/dist/src/codemod/historyPaths.js +1 -0
- package/dist/src/codemod/index.d.ts +7 -0
- package/dist/src/codemod/index.js +1 -0
- package/dist/src/codemod/listResources.d.ts +4 -0
- package/dist/src/codemod/listResources.js +1 -0
- package/dist/src/codemod/semanticIndex/findReferences.d.ts +15 -0
- package/dist/src/codemod/semanticIndex/findReferences.js +2 -0
- package/dist/src/codemod/semanticIndex/index.d.ts +4 -0
- package/dist/src/codemod/semanticIndex/index.js +1 -0
- package/dist/src/codemod/semanticIndex/listImports.d.ts +24 -0
- package/dist/src/codemod/semanticIndex/listImports.js +1 -0
- package/dist/src/codemod/semanticIndex/locateByShape.d.ts +28 -0
- package/dist/src/codemod/semanticIndex/locateByShape.js +1 -0
- package/dist/src/codemod/semanticIndex/projectCache.d.ts +14 -0
- package/dist/src/codemod/semanticIndex/projectCache.js +1 -0
- package/dist/src/codemod/types.d.ts +172 -0
- package/dist/src/codemod/types.js +1 -0
- package/dist/src/dns/bindParser.js +2 -224
- package/dist/src/dns/bindWriter.js +3 -52
- package/dist/src/dns/domainFileGenerator.d.ts +20 -0
- package/dist/src/dns/domainFileGenerator.js +207 -0
- package/dist/src/dns/domainRecords.d.ts +164 -0
- package/dist/src/dns/domainRecords.js +1 -0
- package/dist/src/dns/index.d.ts +2 -1
- package/dist/src/dns/index.js +1 -4
- package/dist/src/dns/types.js +1 -52
- package/dist/src/generation/common.js +6 -161
- package/dist/src/generation/compute.js +82 -590
- package/dist/src/generation/database.js +12 -198
- package/dist/src/generation/generatePatternCode.d.ts +58 -0
- package/dist/src/generation/generatePatternCode.js +33 -0
- package/dist/src/generation/index.js +1 -20
- package/dist/src/generation/infrastructure.d.ts +1 -5
- package/dist/src/generation/infrastructure.js +35 -377
- package/dist/src/generation/messagingConnections.js +1 -73
- package/dist/src/generation/storage.d.ts +0 -15
- package/dist/src/generation/storage.js +35 -168
- package/dist/src/generation/storageConnections.js +1 -75
- package/dist/src/planning/generateResourceChange.d.ts +21 -0
- package/dist/src/planning/generateResourceChange.js +1 -0
- package/dist/src/planning/index.d.ts +3 -0
- package/dist/src/planning/index.js +1 -1
- package/dist/src/planning/resourceAddition.d.ts +154 -0
- package/dist/src/planning/resourceAddition.js +1 -0
- package/dist/src/planning/resourceConnections.d.ts +19 -0
- package/dist/src/planning/resourceConnections.js +1 -0
- package/dist/src/planning/resourcePlanning.js +1 -214
- package/dist/src/presets/index.js +1 -3
- package/dist/src/presets/patternTierPresets.js +1 -131
- package/dist/src/presets/storagePresets.js +1 -36
- package/dist/src/presets/tierPresets.d.ts +5 -8
- package/dist/src/presets/tierPresets.js +1 -384
- package/dist/src/presets/tierTypes.d.ts +1 -1
- package/dist/src/presets/tierTypes.js +0 -7
- package/dist/src/schemas/alarmSchemas.d.ts +19 -0
- package/dist/src/schemas/alarmSchemas.js +1 -0
- package/dist/src/schemas/applicationSchemas.d.ts +22 -6
- package/dist/src/schemas/applicationSchemas.js +1 -80
- package/dist/src/schemas/baseSchemas.d.ts +8 -3
- package/dist/src/schemas/baseSchemas.js +2 -248
- package/dist/src/schemas/cdnSchemas.js +1 -62
- package/dist/src/schemas/computeSchemas.d.ts +25 -3
- package/dist/src/schemas/computeSchemas.js +1 -727
- package/dist/src/schemas/constants.d.ts +5 -7
- package/dist/src/schemas/constants.js +1 -218
- package/dist/src/schemas/databaseSchemas.d.ts +6 -1
- package/dist/src/schemas/databaseSchemas.js +1 -366
- package/dist/src/schemas/index.js +1 -3
- package/dist/src/schemas/instanceTypeArchitecture.js +1 -75
- package/dist/src/schemas/messagingSchemas.js +1 -29
- package/dist/src/schemas/networkSchemas.js +1 -125
- package/dist/src/schemas/patternSchemas.d.ts +1 -1
- package/dist/src/schemas/patternSchemas.js +1 -294
- package/dist/src/schemas/resourceSchemas.d.ts +1 -0
- package/dist/src/schemas/resourceSchemas.js +1 -28
- package/dist/src/schemas/sharedTypes.d.ts +18 -0
- package/dist/src/schemas/sharedTypes.js +1 -0
- package/dist/src/schemas/storageSchemas.d.ts +1 -0
- package/dist/src/schemas/storageSchemas.js +1 -119
- package/dist/src/types/Result.js +1 -31
- package/dist/src/util/errorUtils.js +1 -1
- package/dist/src/validation/patterns.d.ts +9 -0
- package/dist/src/validation/patterns.js +1 -369
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +29 -9
- package/dist/src/dns/infrastructureWriter.d.ts +0 -2
- package/dist/src/dns/infrastructureWriter.js +0 -58
|
@@ -1,201 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* RDS Instance, Aurora, and GlobalAurora configurations.
|
|
6
|
-
*/
|
|
7
|
-
import { buildProperty, getVariableName, emitExtraProperties, } from "./common.js";
|
|
8
|
-
export const DATABASE_ENV_VARS = Object.freeze({
|
|
9
|
-
HOST: "DATABASE_HOST",
|
|
10
|
-
PORT: "DATABASE_PORT",
|
|
11
|
-
NAME: "DATABASE_NAME",
|
|
12
|
-
SSL: "DATABASE_SSL",
|
|
13
|
-
USERNAME: "DATABASE_USERNAME",
|
|
14
|
-
PASSWORD: "DATABASE_PASSWORD",
|
|
15
|
-
});
|
|
16
|
-
export const CREDENTIAL_KEYS = Object.freeze({
|
|
17
|
-
USERNAME: "username",
|
|
18
|
-
PASSWORD: "password",
|
|
19
|
-
});
|
|
20
|
-
/**
|
|
21
|
-
* Get databases connected to a compute resource
|
|
22
|
-
*/
|
|
23
|
-
export function getConnectedDatabases(plan, compute) {
|
|
24
|
-
const connected = compute.connectedDatabase;
|
|
25
|
-
if (!connected?.length)
|
|
26
|
-
return [];
|
|
27
|
-
return plan.database.filter((db) => connected.includes(db.name));
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Generate credential expression for database secrets.
|
|
31
|
-
* Both ECS and Lambda now use the unified getImport() API.
|
|
32
|
-
* The infrastructure layer handles the difference:
|
|
33
|
-
* - ECS: native Secrets Manager injection via EcsSecret.fromSecretsManager()
|
|
34
|
-
* - Lambda: CloudFormation dynamic reference resolved at deploy time
|
|
35
|
-
*/
|
|
36
|
-
function getCredentialExpression(dbVar, credentialKey) {
|
|
37
|
-
return `${dbVar}.getCredentials().getImport("${credentialKey}")`;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Generate database environment variable entries for a list of connected databases.
|
|
41
|
-
* Both ECS and Lambda use containerSecretsImport with getImport() for credentials.
|
|
42
|
-
* Credential entries are always marked as secrets (isSecret: true).
|
|
43
|
-
*/
|
|
44
|
-
export function generateDatabaseEnvVarEntries(connectedDatabases) {
|
|
45
|
-
const entries = [];
|
|
46
|
-
const addEntry = (key, expression, isSecret) => {
|
|
47
|
-
entries.push({ key, expression, isSecret });
|
|
48
|
-
};
|
|
49
|
-
if (connectedDatabases.length === 1) {
|
|
50
|
-
const dbVar = getVariableName(connectedDatabases[0]);
|
|
51
|
-
addEntry(DATABASE_ENV_VARS.HOST, `${dbVar}.getHostEndpoint()`, false);
|
|
52
|
-
addEntry(DATABASE_ENV_VARS.PORT, `${dbVar}.getHostPort()`, false);
|
|
53
|
-
addEntry(DATABASE_ENV_VARS.NAME, `${dbVar}.getDatabaseName()`, false);
|
|
54
|
-
addEntry(DATABASE_ENV_VARS.SSL, `"true"`, false);
|
|
55
|
-
addEntry(DATABASE_ENV_VARS.USERNAME, getCredentialExpression(dbVar, CREDENTIAL_KEYS.USERNAME), true);
|
|
56
|
-
addEntry(DATABASE_ENV_VARS.PASSWORD, getCredentialExpression(dbVar, CREDENTIAL_KEYS.PASSWORD), true);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
for (const [index, database] of connectedDatabases.entries()) {
|
|
60
|
-
const dbVar = getVariableName(database);
|
|
61
|
-
const suffix = index === 0 ? "" : `_${index + 1}`;
|
|
62
|
-
addEntry(`${DATABASE_ENV_VARS.HOST}${suffix}`, `${dbVar}.getHostEndpoint()`, false);
|
|
63
|
-
addEntry(`${DATABASE_ENV_VARS.PORT}${suffix}`, `${dbVar}.getHostPort()`, false);
|
|
64
|
-
addEntry(`${DATABASE_ENV_VARS.NAME}${suffix}`, `${dbVar}.getDatabaseName()`, false);
|
|
65
|
-
addEntry(`${DATABASE_ENV_VARS.SSL}${suffix}`, `"true"`, false);
|
|
66
|
-
addEntry(`${DATABASE_ENV_VARS.USERNAME}${suffix}`, getCredentialExpression(dbVar, CREDENTIAL_KEYS.USERNAME), true);
|
|
67
|
-
addEntry(`${DATABASE_ENV_VARS.PASSWORD}${suffix}`, getCredentialExpression(dbVar, CREDENTIAL_KEYS.PASSWORD), true);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return entries;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Format database connections array for generated infrastructure code
|
|
74
|
-
*/
|
|
75
|
-
export function formatConnectionsCode(connectedDatabases) {
|
|
76
|
-
const dbVars = connectedDatabases.map((db) => getVariableName(db)).join(", ");
|
|
77
|
-
return `connections: [${dbVars}],`;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Build database environment variables for a compute resource
|
|
81
|
-
*/
|
|
82
|
-
export function buildDatabaseEnvVars(plan, compute) {
|
|
83
|
-
const env = {};
|
|
84
|
-
const secrets = {};
|
|
85
|
-
if (!compute.needsConnection || !compute.connectedDatabase?.length) {
|
|
86
|
-
return { env, secrets };
|
|
87
|
-
}
|
|
88
|
-
const connectedDatabases = getConnectedDatabases(plan, compute);
|
|
89
|
-
const entries = generateDatabaseEnvVarEntries(connectedDatabases);
|
|
90
|
-
for (const entry of entries) {
|
|
91
|
-
const value = entry.expression === `"true"`
|
|
92
|
-
? "true"
|
|
93
|
-
: { __expression: entry.expression };
|
|
94
|
-
if (entry.isSecret) {
|
|
95
|
-
secrets[entry.key] = { __expression: entry.expression };
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
env[entry.key] = value;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return { env, secrets };
|
|
102
|
-
}
|
|
103
|
-
function generateDatabaseSharedProps(database) {
|
|
104
|
-
let code = "";
|
|
105
|
-
code += buildProperty(database.port !== undefined, "port", database.port);
|
|
106
|
-
code += buildProperty(database.deletionProtection !== undefined, "deletionProtection", database.deletionProtection);
|
|
107
|
-
code += buildProperty(database.snapshotIdentifier !== undefined, "snapshotIdentifier", database.snapshotIdentifier, "string");
|
|
108
|
-
code += buildProperty(database.snapshotUsername !== undefined, "snapshotUsername", database.snapshotUsername, "string");
|
|
109
|
-
return code;
|
|
110
|
-
}
|
|
111
|
-
function generateDatabaseInstanceProps(database) {
|
|
112
|
-
if (database.type !== "Instance")
|
|
113
|
-
return "";
|
|
114
|
-
let code = "";
|
|
115
|
-
code += buildProperty(database.instanceType !== undefined, "instanceType", database.instanceType, "string");
|
|
116
|
-
code += buildProperty(database.multiAz !== undefined, "multiAz", database.multiAz);
|
|
117
|
-
code += buildProperty(database.publiclyAccessible !== undefined, "publiclyAccessible", database.publiclyAccessible);
|
|
118
|
-
code += buildProperty(database.enableSecretRotation !== undefined, "enableSecretRotation", database.enableSecretRotation);
|
|
119
|
-
code += buildProperty(database.encryption !== undefined, "encryption", database.encryption, "object");
|
|
120
|
-
code += buildProperty(database.databaseInsights !== undefined, "databaseInsights", database.databaseInsights, "boolean-or-object");
|
|
121
|
-
code += buildProperty(database.proxy !== undefined, "proxy", database.proxy, "boolean-or-object");
|
|
122
|
-
code += buildProperty(database.readReplica !== undefined, "readReplica", database.readReplica, "boolean-or-object");
|
|
123
|
-
code += buildProperty(database.credentials !== undefined, "credentials", database.credentials, "object");
|
|
124
|
-
code += buildProperty(database.backupRetention !== undefined, "backupRetention", database.backupRetention);
|
|
125
|
-
return code;
|
|
126
|
-
}
|
|
127
|
-
function generateDatabaseAuroraProps(database) {
|
|
128
|
-
if (database.type !== "Aurora" && database.type !== "GlobalAurora")
|
|
129
|
-
return "";
|
|
130
|
-
let code = "";
|
|
131
|
-
code += buildProperty(database.encryption !== undefined, "encryption", database.encryption, "object");
|
|
132
|
-
code += buildProperty(database.databaseInsights !== undefined, "databaseInsights", database.databaseInsights, "boolean-or-object");
|
|
133
|
-
code += buildProperty(database.proxy !== undefined, "proxy", database.proxy, "boolean-or-object");
|
|
134
|
-
code += buildProperty(database.credentials !== undefined, "credentials", database.credentials, "object");
|
|
135
|
-
code += buildProperty(database.writer !== undefined, "writer", database.writer, "object");
|
|
136
|
-
code += buildProperty(database.readers !== undefined, "readers", database.readers, "boolean-or-object");
|
|
137
|
-
code += buildProperty(database.backupRetention !== undefined, "backupRetention", database.backupRetention);
|
|
138
|
-
code += buildProperty(database.preferredMaintenanceWindow !== undefined, "preferredMaintenanceWindow", database.preferredMaintenanceWindow, "string");
|
|
139
|
-
return code;
|
|
140
|
-
}
|
|
141
|
-
function generateDatabaseGlobalAuroraProps(database) {
|
|
142
|
-
if (database.type !== "GlobalAurora")
|
|
143
|
-
return "";
|
|
144
|
-
let code = "";
|
|
145
|
-
code += buildProperty(database.primaryRegion !== undefined, "primaryRegion", database.primaryRegion, "string");
|
|
146
|
-
if (database.secondaryRegions !== undefined &&
|
|
147
|
-
database.secondaryRegions.length > 0) {
|
|
148
|
-
code += `
|
|
149
|
-
secondaryRegions: [${database.secondaryRegions.map((r) => `"${r}"`).join(", ")}],`;
|
|
150
|
-
}
|
|
151
|
-
code += buildProperty(database.globalClusterIdentifier !== undefined, "globalClusterIdentifier", database.globalClusterIdentifier, "string");
|
|
152
|
-
code += buildProperty(database.enableGlobalWriteForwarding !== undefined, "enableGlobalWriteForwarding", database.enableGlobalWriteForwarding);
|
|
153
|
-
return code;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Check if a database needs a variable assignment (referenced by compute)
|
|
157
|
-
*/
|
|
158
|
-
export function databaseNeedsVariable(database, plan) {
|
|
159
|
-
return plan.compute.some((compute) => compute.needsConnection &&
|
|
160
|
-
compute.connectedDatabase?.includes(database.name));
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Generate database infrastructure code
|
|
164
|
-
*/
|
|
165
|
-
export function generateDatabaseCode(plan) {
|
|
166
|
-
if (plan.database.length === 0)
|
|
167
|
-
return "";
|
|
168
|
-
let code = "";
|
|
169
|
-
for (let dbIndex = 0; dbIndex < plan.database.length; dbIndex++) {
|
|
170
|
-
const database = plan.database[dbIndex];
|
|
171
|
-
const databaseVariable = getVariableName(database);
|
|
172
|
-
const hasConnections = databaseNeedsVariable(database, plan);
|
|
173
|
-
const needsLeadingNewline = dbIndex > 0;
|
|
174
|
-
const prefix = hasConnections ? `const ${databaseVariable} = ` : "";
|
|
175
|
-
const leadingNewline = needsLeadingNewline ? "\n" : "";
|
|
176
|
-
code += `${leadingNewline}${prefix}app.addDatabase(
|
|
177
|
-
DatabaseFactory.build("${database.name}", {
|
|
1
|
+
import{buildProperty as o,formatValue as p,getVariableName as d,emitExtraProperties as g}from"./common.js";const s=Object.freeze({HOST:"DATABASE_HOST",PORT:"DATABASE_PORT",NAME:"DATABASE_NAME",SSL:"DATABASE_SSL",USERNAME:"DATABASE_USERNAME",PASSWORD:"DATABASE_PASSWORD"}),u=Object.freeze({USERNAME:"username",PASSWORD:"password"});function A(e,n){const t=n.connectedDatabase;return t?.length?e.database.filter(r=>t.includes(r.name)):[]}function a(e,n){return`${e}.getCredentials().getImport("${n}")`}function S(e){const n=[],t=(r,l,c)=>{n.push({key:r,expression:l,isSecret:c})};if(e.length===1){const r=d(e[0]);t(s.HOST,`${r}.getHostEndpoint()`,!1),t(s.PORT,`${r}.getHostPort()`,!1),t(s.NAME,`${r}.getDatabaseName()`,!1),t(s.SSL,'"true"',!1),t(s.USERNAME,a(r,u.USERNAME),!0),t(s.PASSWORD,a(r,u.PASSWORD),!0)}else for(const[r,l]of e.entries()){const c=d(l),i=r===0?"":`_${r+1}`;t(`${s.HOST}${i}`,`${c}.getHostEndpoint()`,!1),t(`${s.PORT}${i}`,`${c}.getHostPort()`,!1),t(`${s.NAME}${i}`,`${c}.getDatabaseName()`,!1),t(`${s.SSL}${i}`,'"true"',!1),t(`${s.USERNAME}${i}`,a(c,u.USERNAME),!0),t(`${s.PASSWORD}${i}`,a(c,u.PASSWORD),!0)}return n}function x(e){return`connections: [${e.map(t=>d(t)).join(", ")}],`}function P(e,n){const t={},r={};if(!n.needsConnection||!n.connectedDatabase?.length)return{env:t,secrets:r};const l=A(e,n),c=S(l);for(const i of c){const f=i.expression==='"true"'?"true":{__expression:i.expression};i.isSecret?r[i.key]={__expression:i.expression}:t[i.key]=f}return{env:t,secrets:r}}function E(e){let n="";return n+=o(e.port!==void 0,"port",e.port),n+=o(e.deletionProtection!==void 0,"deletionProtection",e.deletionProtection),n+=o(e.snapshotIdentifier!==void 0,"snapshotIdentifier",e.snapshotIdentifier,"string"),n+=o(e.snapshotUsername!==void 0,"snapshotUsername",e.snapshotUsername,"string"),n+=o(e.monitoringInterval!==void 0,"monitoringInterval",e.monitoringInterval),n}function y(e){if(e.type!=="Instance")return"";let n="";return n+=o(e.instanceType!==void 0,"instanceType",e.instanceType,"string"),n+=o(e.allocatedStorage!==void 0,"allocatedStorage",e.allocatedStorage),n+=o(e.multiAz!==void 0,"multiAz",e.multiAz),n+=o(e.publiclyAccessible!==void 0,"publiclyAccessible",e.publiclyAccessible),n+=o(e.encryption!==void 0,"encryption",e.encryption,"object"),n+=o(e.databaseInsights!==void 0,"databaseInsights",e.databaseInsights,"boolean-or-object"),n+=o(e.proxy!==void 0,"proxy",e.proxy,"boolean-or-object"),n+=o(e.readReplica!==void 0,"readReplica",e.readReplica,"boolean-or-object"),n+=o(e.credentials!==void 0,"credentials",e.credentials,"object"),n+=o(e.backupRetention!==void 0,"backupRetention",e.backupRetention),n}function m(e){if(e.type!=="Aurora"&&e.type!=="GlobalAurora")return"";let n="";return n+=o(e.encryption!==void 0,"encryption",e.encryption,"object"),n+=o(e.databaseInsights!==void 0,"databaseInsights",e.databaseInsights,"boolean-or-object"),n+=o(e.proxy!==void 0,"proxy",e.proxy,"boolean-or-object"),n+=o(e.credentials!==void 0,"credentials",e.credentials,"object"),n+=o(e.writer!==void 0,"writer",e.writer,"object"),n+=o(e.readers!==void 0,"readers",e.readers,"boolean-or-object"),n+=o(e.backupRetention!==void 0,"backupRetention",e.backupRetention),n+=o(e.preferredMaintenanceWindow!==void 0,"preferredMaintenanceWindow",e.preferredMaintenanceWindow,"string"),n}function R(e){if(e.type!=="GlobalAurora")return"";let n="";return n+=o(e.primaryRegion!==void 0,"primaryRegion",e.primaryRegion,"string"),e.secondaryRegions!==void 0&&e.secondaryRegions.length>0&&(n+=`
|
|
2
|
+
secondaryRegions: [${e.secondaryRegions.map(t=>`"${t}"`).join(", ")}],`),n+=o(e.globalClusterIdentifier!==void 0,"globalClusterIdentifier",e.globalClusterIdentifier,"string"),n+=o(e.enableGlobalWriteForwarding!==void 0,"enableGlobalWriteForwarding",e.enableGlobalWriteForwarding),n}function b(e,n){return n.compute.some(t=>t.needsConnection&&t.connectedDatabase?.includes(e.name))}function h(e){if(e.database.length===0)return"";let n="";for(let t=0;t<e.database.length;t++){const r=e.database[t],l=d(r),c=b(r,e),i=t>0,f=c?`const ${l} = `:"";n+=`${i?`
|
|
3
|
+
`:""}${f}app.addDatabase(
|
|
4
|
+
DatabaseFactory.build("${r.name}", {
|
|
178
5
|
vpc: app.getVpc(),
|
|
179
|
-
type: "${
|
|
180
|
-
databaseName: "${
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
else if (database.databaseEngine) {
|
|
187
|
-
code += `
|
|
188
|
-
databaseEngine: "${database.databaseEngine}",`;
|
|
189
|
-
}
|
|
190
|
-
code += generateDatabaseSharedProps(database);
|
|
191
|
-
code += generateDatabaseInstanceProps(database);
|
|
192
|
-
code += generateDatabaseAuroraProps(database);
|
|
193
|
-
code += generateDatabaseGlobalAuroraProps(database);
|
|
194
|
-
code += emitExtraProperties(database.extraProperties);
|
|
195
|
-
code += `
|
|
6
|
+
type: "${r.type}",
|
|
7
|
+
databaseName: "${r.databaseName}",`,r.engineExpression?n+=`
|
|
8
|
+
engine: ${r.engineExpression},`:r.databaseEngine&&(n+=`
|
|
9
|
+
databaseEngine: "${r.databaseEngine}",`),n+=E(r),n+=y(r),n+=m(r),n+=R(r),n+=g(r.extraProperties),r.alarms===!1?n+=`
|
|
10
|
+
alarms: false,`:typeof r.alarms=="object"&&(n+=`
|
|
11
|
+
alarms: ${p(r.alarms," ")},`),r.type!=="GlobalAurora"&&(n+=`
|
|
12
|
+
...(getConfig().environment === "production" ? { alertsTopic: "import:SharedAlarmTopicArn" } : {}),`),n+=`
|
|
196
13
|
})
|
|
197
14
|
);
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
return code;
|
|
201
|
-
}
|
|
15
|
+
`}return n}export{u as CREDENTIAL_KEYS,s as DATABASE_ENV_VARS,P as buildDatabaseEnvVars,b as databaseNeedsVariable,x as formatConnectionsCode,h as generateDatabaseCode,S as generateDatabaseEnvVarEntries,A as getConnectedDatabases};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pattern Infrastructure Code Generation
|
|
3
|
+
*
|
|
4
|
+
* Generates `app.addPattern(PatternFactory.build(...))` blocks for Payload
|
|
5
|
+
* and Next.js OpenNext patterns. Emits every populated field of the pattern
|
|
6
|
+
* config using the Zod schema fragment in `schemas/patternSchemas.ts` as
|
|
7
|
+
* the source of truth (types are `z.infer`-derived).
|
|
8
|
+
*
|
|
9
|
+
* Field-emission policy (Phase 1 BLOCKER B-2 / T13a):
|
|
10
|
+
*
|
|
11
|
+
* - Emit a field only when its value is defined per the Zod schema's
|
|
12
|
+
* `.optional()` semantics. Zod's `.optional()` means "property absent",
|
|
13
|
+
* NOT "property undefined" — we therefore guard every read with an
|
|
14
|
+
* explicit `!== undefined` check, never a truthy check.
|
|
15
|
+
* - Primitive fields (`port`, `databaseEngine`, `multiAz`, …) emit when
|
|
16
|
+
* present.
|
|
17
|
+
* - Object-valued fields (`readReplica`, `writer`, `readers`,
|
|
18
|
+
* `encryption`, `credentials`, `databaseInsights`, `proxy`,
|
|
19
|
+
* `storage`, `messaging`, `cdn`, `environment`) delegate to
|
|
20
|
+
* `formatValue` for deterministic inline/multiline formatting.
|
|
21
|
+
* - `false` literals on union fields (`readReplica`, `readers`,
|
|
22
|
+
* `databaseInsights`, `proxy`, `deadLetterQueue`) are emitted verbatim
|
|
23
|
+
* as `false` — they encode explicit disablement.
|
|
24
|
+
*/
|
|
25
|
+
import type { ApplicationResourcePlan } from "../schemas/resourceSchemas.js";
|
|
26
|
+
/**
|
|
27
|
+
* Default values for OpenNext pattern code generation (matches tier
|
|
28
|
+
* presets). Exposed in case tooling needs to know the baked-in defaults
|
|
29
|
+
* — emission logic treats these as fall-through values, not as a
|
|
30
|
+
* reason to drop user-supplied overrides.
|
|
31
|
+
*/
|
|
32
|
+
export declare const OPENNEXT_DEFAULTS: Readonly<{
|
|
33
|
+
readonly database: {
|
|
34
|
+
readonly type: "Instance";
|
|
35
|
+
readonly backupRetention: 7;
|
|
36
|
+
readonly deletionProtection: true;
|
|
37
|
+
};
|
|
38
|
+
readonly compute: {
|
|
39
|
+
readonly server: {
|
|
40
|
+
readonly memorySize: 1536;
|
|
41
|
+
readonly timeout: 30;
|
|
42
|
+
};
|
|
43
|
+
readonly imageOptimisation: {
|
|
44
|
+
readonly memorySize: 1536;
|
|
45
|
+
readonly timeout: 30;
|
|
46
|
+
};
|
|
47
|
+
readonly revalidation: {
|
|
48
|
+
readonly memorySize: 768;
|
|
49
|
+
readonly timeout: 300;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* Generate pattern infrastructure code with clean formatting.
|
|
55
|
+
* Handles both Payload and Next.js OpenNext patterns and emits every
|
|
56
|
+
* populated field from `plan.patternConfig` (Phase 1 BLOCKER B-2 fix).
|
|
57
|
+
*/
|
|
58
|
+
export declare function generatePatternCodeWithComments(plan: ApplicationResourcePlan): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import{toPascalCase as f,formatValue as p}from"./common.js";const a=Object.freeze({database:{type:"Instance",backupRetention:7,deletionProtection:!0},compute:{server:{memorySize:1536,timeout:30},imageOptimisation:{memorySize:1536,timeout:30},revalidation:{memorySize:768,timeout:300}}});function c(i,e,t){return e===void 0?"":`
|
|
2
|
+
${t}${i}: ${e},`}function r(i,e,t){return e===void 0?"":`
|
|
3
|
+
${t}${i}: ${JSON.stringify(e)},`}function u(i,e,t){return e===void 0?"":e===!1?`
|
|
4
|
+
${t}${i}: false,`:`
|
|
5
|
+
${t}${i}: ${p(e,t)},`}function m(i,e,t){return e===void 0||Object.keys(e).length===0?"":`
|
|
6
|
+
${t}${i}: ${p(e,t)},`}function y(i){const e=i??{},t=" ",s=e.type??a.database.type,d=e.backupRetention??a.database.backupRetention,o=e.deletionProtection??a.database.deletionProtection;let n=`
|
|
7
|
+
${t}type: "${s}",`;return n+=r("databaseName",e.databaseName,t),n+=r("databaseEngine",e.databaseEngine,t),s==="Instance"&&e.instanceType!==void 0&&(n+=r("instanceType",e.instanceType,t)),n+=c("allocatedStorage",e.allocatedStorage,t),n+=c("port",e.port,t),n+=`
|
|
8
|
+
${t}backupRetention: ${d},`,n+=`
|
|
9
|
+
${t}deletionProtection: ${o},`,n+=c("publiclyAccessible",e.publiclyAccessible,t),n+=r("allowedIpCidr",e.allowedIpCidr,t),n+=c("multiAz",e.multiAz,t),n+=c("allowVpcAccess",e.allowVpcAccess,t),n+=c("monitoringInterval",e.monitoringInterval,t),n+=r("preferredMaintenanceWindow",e.preferredMaintenanceWindow,t),n+=r("snapshotIdentifier",e.snapshotIdentifier,t),n+=r("snapshotUsername",e.snapshotUsername,t),n+=u("readReplica",e.readReplica,t),n+=m("writer",e.writer,t),n+=u("readers",e.readers,t),n+=u("databaseInsights",e.databaseInsights,t),n+=u("proxy",e.proxy,t),n+=m("credentials",e.credentials,t),n+=m("encryption",e.encryption,t),`
|
|
10
|
+
database: {${n}
|
|
11
|
+
},`}function $(i){const e=i??{},t=e.server?.memorySize??a.compute.server.memorySize,s=e.server?.timeout??a.compute.server.timeout,d=e.imageOptimisation?.memorySize??a.compute.imageOptimisation.memorySize,o=e.imageOptimisation?.timeout??a.compute.imageOptimisation.timeout,n=e.revalidation?.memorySize??a.compute.revalidation.memorySize,l=e.revalidation?.timeout??a.compute.revalidation.timeout;return`
|
|
12
|
+
compute: {
|
|
13
|
+
server: {
|
|
14
|
+
memorySize: ${t},
|
|
15
|
+
timeout: ${s},
|
|
16
|
+
},
|
|
17
|
+
imageOptimisation: {
|
|
18
|
+
memorySize: ${d},
|
|
19
|
+
timeout: ${o},
|
|
20
|
+
},
|
|
21
|
+
revalidation: {
|
|
22
|
+
memorySize: ${n},
|
|
23
|
+
timeout: ${l},
|
|
24
|
+
},
|
|
25
|
+
},`}function g(i){return m("storage",i," ")}function b(i){return m("messaging",i," ")}function S(i){return m("cdn",i," ")}function v(i){return m("environment",i," ")}function O(i){if(!i.patternConfig)return"";const e=i.patternConfig,t=f(e.name),s=e.type==="payload"?"Payload":"Nextjs";let o=`app.addPattern(
|
|
26
|
+
PatternFactory.build("${`${t}${s}`}", {
|
|
27
|
+
type: "${e.type}",
|
|
28
|
+
name: "${e.name}",`;return e.domain!==void 0&&e.domain!==""&&(o+=`
|
|
29
|
+
domain: "${e.domain}",`),(e.type==="payload"||e.type==="nextjs")&&(o+=y(e.database),o+=$(e.compute),o+=g(e.storage),o+=b(e.messaging),o+=S(e.cdn),o+=v(e.environment)),o+=`
|
|
30
|
+
})
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
`,o}export{a as OPENNEXT_DEFAULTS,O as generatePatternCodeWithComments};
|
|
@@ -1,20 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Code Generation Modules
|
|
3
|
-
*
|
|
4
|
-
* This module re-exports all code generation utilities for generating
|
|
5
|
-
* infrastructure code from resource plans.
|
|
6
|
-
*/
|
|
7
|
-
// Common utilities
|
|
8
|
-
export { isSpecialValue, toPascalCase, toKebab, toValidDatabaseName, toVariableName, formatValue, buildProperty, getVariableName, resolveResourceVariable, emitExtraProperties, } from "./common.js";
|
|
9
|
-
// Database generation
|
|
10
|
-
export { DATABASE_ENV_VARS, CREDENTIAL_KEYS, getConnectedDatabases, generateDatabaseEnvVarEntries, formatConnectionsCode, buildDatabaseEnvVars, databaseNeedsVariable, generateDatabaseCode, } from "./database.js";
|
|
11
|
-
// Storage connections
|
|
12
|
-
export { STORAGE_ENV_VARS, getConnectedStorage, generateStorageEnvVarEntries, buildStorageEnvVars, formatAllConnectionsCode, } from "./storageConnections.js";
|
|
13
|
-
// Messaging connections
|
|
14
|
-
export { MESSAGING_ENV_VARS, getConnectedMessaging, generateMessagingEnvVarEntries, buildMessagingEnvVars, } from "./messagingConnections.js";
|
|
15
|
-
// Compute generation
|
|
16
|
-
export { generateLambdaCode, generateLambdaConnectionsCode, generateEc2Code, generateEcsCode, generateComputeCode, } from "./compute.js";
|
|
17
|
-
// Storage generation
|
|
18
|
-
export { generateS3Code, generateDynamoDBCode, generateSQSCode, s3NeedsVariable, sqsNeedsVariable, } from "./storage.js";
|
|
19
|
-
// Infrastructure generation
|
|
20
|
-
export { generateNetworkCode, generateTags, generateAppInit, generateImports, generateCDNCode, collectCdnReferencedResources, usesPatternApproach, generatePatternCodeWithComments, } from "./infrastructure.js";
|
|
1
|
+
import{isSpecialValue as t,toPascalCase as r,toKebab as o,toValidDatabaseName as n,toVariableName as s,formatValue as g,buildProperty as d,getVariableName as i,resolveResourceVariable as C,emitExtraProperties as m}from"./common.js";import{DATABASE_ENV_VARS as V,CREDENTIAL_KEYS as b,getConnectedDatabases as l,generateDatabaseEnvVarEntries as c,formatConnectionsCode as p,buildDatabaseEnvVars as S,databaseNeedsVariable as N,generateDatabaseCode as A}from"./database.js";import{STORAGE_ENV_VARS as u,getConnectedStorage as D,generateStorageEnvVarEntries as x,buildStorageEnvVars as R,formatAllConnectionsCode as v}from"./storageConnections.js";import{MESSAGING_ENV_VARS as P,getConnectedMessaging as I,generateMessagingEnvVarEntries as M,buildMessagingEnvVars as T}from"./messagingConnections.js";import{generateLambdaCode as L,generateLambdaConnectionsCode as h,generateEc2Code as y,generateEcsCode as B,generateComputeCode as K}from"./compute.js";import{generateS3Code as q,generateDynamoDBCode as w,generateSQSCode as O,s3NeedsVariable as Q,sqsNeedsVariable as W}from"./storage.js";import{generateNetworkCode as j,generateTags as z,generateAppInit as F,generateImports as H,generateCDNCode as J,collectCdnReferencedResources as U,usesPatternApproach as X,generatePatternCodeWithComments as Z}from"./infrastructure.js";export{b as CREDENTIAL_KEYS,V as DATABASE_ENV_VARS,P as MESSAGING_ENV_VARS,u as STORAGE_ENV_VARS,S as buildDatabaseEnvVars,T as buildMessagingEnvVars,d as buildProperty,R as buildStorageEnvVars,U as collectCdnReferencedResources,N as databaseNeedsVariable,m as emitExtraProperties,v as formatAllConnectionsCode,p as formatConnectionsCode,g as formatValue,F as generateAppInit,J as generateCDNCode,K as generateComputeCode,A as generateDatabaseCode,c as generateDatabaseEnvVarEntries,w as generateDynamoDBCode,y as generateEc2Code,B as generateEcsCode,H as generateImports,L as generateLambdaCode,h as generateLambdaConnectionsCode,M as generateMessagingEnvVarEntries,j as generateNetworkCode,Z as generatePatternCodeWithComments,q as generateS3Code,O as generateSQSCode,x as generateStorageEnvVarEntries,z as generateTags,l as getConnectedDatabases,I as getConnectedMessaging,D as getConnectedStorage,i as getVariableName,t as isSpecialValue,C as resolveResourceVariable,Q as s3NeedsVariable,W as sqsNeedsVariable,o as toKebab,r as toPascalCase,n as toValidDatabaseName,s as toVariableName,X as usesPatternApproach};
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* network configuration, tags, imports, CDN, and app initialisation.
|
|
6
6
|
*/
|
|
7
7
|
import type { ApplicationResourcePlan } from "../schemas/resourceSchemas.js";
|
|
8
|
+
export { OPENNEXT_DEFAULTS, generatePatternCodeWithComments, } from "./generatePatternCode.js";
|
|
8
9
|
export declare const COST_ALLOCATION_TAG: "fjall:costAllocation:owner";
|
|
9
10
|
export declare const DEFAULT_COST_ALLOCATION_OWNER: "engineering";
|
|
10
11
|
/**
|
|
@@ -37,8 +38,3 @@ export declare function collectCdnReferencedResources(plan: ApplicationResourceP
|
|
|
37
38
|
* instead of individual factory calls for each resource.
|
|
38
39
|
*/
|
|
39
40
|
export declare function usesPatternApproach(plan: ApplicationResourcePlan): boolean;
|
|
40
|
-
/**
|
|
41
|
-
* Generate pattern infrastructure code with clean formatting.
|
|
42
|
-
* Handles both Payload and Next.js OpenNext patterns.
|
|
43
|
-
*/
|
|
44
|
-
export declare function generatePatternCodeWithComments(plan: ApplicationResourcePlan): string;
|