@fjall/generator 0.88.4

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/dist/src/ast/astComputeParser.d.ts +4 -0
  2. package/dist/src/ast/astComputeParser.js +427 -0
  3. package/dist/src/ast/astInfrastructureParser.d.ts +357 -0
  4. package/dist/src/ast/astInfrastructureParser.js +1925 -0
  5. package/dist/src/ast/astSurgicalModification.d.ts +47 -0
  6. package/dist/src/ast/astSurgicalModification.js +400 -0
  7. package/dist/src/ast/index.d.ts +2 -0
  8. package/dist/src/ast/index.js +2 -0
  9. package/dist/src/aws/regions.d.ts +30 -0
  10. package/dist/src/aws/regions.js +254 -0
  11. package/dist/src/generation/common.d.ts +86 -0
  12. package/dist/src/generation/common.js +187 -0
  13. package/dist/src/generation/compute.d.ts +6 -0
  14. package/dist/src/generation/compute.js +547 -0
  15. package/dist/src/generation/database.d.ts +54 -0
  16. package/dist/src/generation/database.js +201 -0
  17. package/dist/src/generation/index.d.ts +12 -0
  18. package/dist/src/generation/index.js +18 -0
  19. package/dist/src/generation/infrastructure.d.ts +44 -0
  20. package/dist/src/generation/infrastructure.js +389 -0
  21. package/dist/src/generation/storage.d.ts +23 -0
  22. package/dist/src/generation/storage.js +174 -0
  23. package/dist/src/generation/storageConnections.d.ts +37 -0
  24. package/dist/src/generation/storageConnections.js +71 -0
  25. package/dist/src/index.d.ts +10 -0
  26. package/dist/src/index.js +19 -0
  27. package/dist/src/planning/index.d.ts +1 -0
  28. package/dist/src/planning/index.js +1 -0
  29. package/dist/src/planning/resourcePlanning.d.ts +58 -0
  30. package/dist/src/planning/resourcePlanning.js +216 -0
  31. package/dist/src/presets/index.d.ts +3 -0
  32. package/dist/src/presets/index.js +3 -0
  33. package/dist/src/presets/patternTierPresets.d.ts +93 -0
  34. package/dist/src/presets/patternTierPresets.js +131 -0
  35. package/dist/src/presets/storagePresets.d.ts +11 -0
  36. package/dist/src/presets/storagePresets.js +36 -0
  37. package/dist/src/presets/tierPresets.d.ts +59 -0
  38. package/dist/src/presets/tierPresets.js +384 -0
  39. package/dist/src/presets/tierTypes.d.ts +301 -0
  40. package/dist/src/presets/tierTypes.js +7 -0
  41. package/dist/src/schemas/constants.d.ts +74 -0
  42. package/dist/src/schemas/constants.js +208 -0
  43. package/dist/src/schemas/index.d.ts +3 -0
  44. package/dist/src/schemas/index.js +3 -0
  45. package/dist/src/schemas/instanceTypeArchitecture.d.ts +35 -0
  46. package/dist/src/schemas/instanceTypeArchitecture.js +75 -0
  47. package/dist/src/schemas/resourceSchemas.d.ts +3534 -0
  48. package/dist/src/schemas/resourceSchemas.js +2015 -0
  49. package/dist/src/types/Result.d.ts +19 -0
  50. package/dist/src/types/Result.js +31 -0
  51. package/dist/src/util/errorUtils.d.ts +2 -0
  52. package/dist/src/util/errorUtils.js +15 -0
  53. package/dist/src/validation/patterns.d.ts +300 -0
  54. package/dist/src/validation/patterns.js +360 -0
  55. package/dist/src/version.d.ts +1 -0
  56. package/dist/src/version.js +1 -0
  57. package/package.json +32 -0
@@ -0,0 +1,357 @@
1
+ import * as ts from "typescript";
2
+ import { type ApplicationResourcePlan, type StatementType, type CustomCodeBlock, type ExtraProperty } from "../schemas/resourceSchemas.js";
3
+ /** Special marker for identifier references in parsed AST */
4
+ export interface IdentifierRef {
5
+ __identifier: string;
6
+ }
7
+ /** Special marker for property access expressions in parsed AST */
8
+ export interface ExpressionRef {
9
+ __expression: string;
10
+ }
11
+ /** Special marker for function call expressions in parsed AST */
12
+ export interface CallRef {
13
+ __call: string;
14
+ }
15
+ /** Special marker for unknown/unsupported expressions in parsed AST */
16
+ interface UnknownRef {
17
+ __unknown: string;
18
+ }
19
+ /** Union of all possible values that can be parsed from AST expressions */
20
+ export type ParsedValue = string | number | boolean | null | undefined | IdentifierRef | ExpressionRef | CallRef | UnknownRef | ParsedValue[] | ParsedObject;
21
+ /** Object with string keys and parsed values */
22
+ export type ParsedObject = {
23
+ [key: string]: ParsedValue;
24
+ };
25
+ /** Base check for non-null, non-array objects */
26
+ export declare function isPlainObject(value: ParsedValue): value is Record<string, ParsedValue>;
27
+ /** Type guard for identifier references */
28
+ export declare function isIdentifierRef(value: ParsedValue): value is IdentifierRef;
29
+ /** Type guard for expression references */
30
+ export declare function isExpressionRef(value: ParsedValue): value is ExpressionRef;
31
+ /** Type guard for parsed objects */
32
+ export declare function isParsedObject(value: ParsedValue): value is ParsedObject;
33
+ /** Safely extract a string from ParsedValue */
34
+ export declare function asString(value: ParsedValue): string | undefined;
35
+ /** Safely extract a number from ParsedValue */
36
+ export declare function asNumber(value: ParsedValue): number | undefined;
37
+ /** Safely extract a boolean from ParsedValue */
38
+ export declare function asBoolean(value: ParsedValue): boolean | undefined;
39
+ /** Safely extract a string array from ParsedValue */
40
+ export declare function asStringArray(value: ParsedValue): string[] | undefined;
41
+ /** Narrow a string to a union member, returning undefined if not a valid member */
42
+ export declare function asStringUnion<T extends readonly string[]>(value: ParsedValue | undefined, validValues: T): T[number] | undefined;
43
+ /** Type guard for call references */
44
+ export declare function isCallRef(value: ParsedValue): value is CallRef;
45
+ /** Capture properties from a parsed config that are NOT in the known keys set */
46
+ export declare function captureExtraProperties(config: ParsedObject, knownKeys: Set<string>): ExtraProperty[];
47
+ /** Parsed network configuration from App.getApp() options */
48
+ interface ParsedNetworkConfig {
49
+ maxAzs?: number;
50
+ natGateways?: {
51
+ count?: number;
52
+ } | false;
53
+ flowLogs?: {
54
+ destination?: string;
55
+ retentionDays?: number;
56
+ } | false;
57
+ vpcEndpoints?: ParsedObject;
58
+ }
59
+ declare const DYNAMODB_KEY_TYPES: readonly ["S", "N", "B"];
60
+ type DynamoDBKeyType = (typeof DYNAMODB_KEY_TYPES)[number];
61
+ interface DynamoDBKey {
62
+ name: string;
63
+ type: DynamoDBKeyType;
64
+ }
65
+ /** Parsed DynamoDB table resource from app.addDatabase(DatabaseFactory.build("...", { type: "DynamoDB" })) */
66
+ export interface ParsedDynamoDBResource {
67
+ variableName?: string;
68
+ resourceName: string;
69
+ partitionKey: DynamoDBKey;
70
+ sortKey?: DynamoDBKey;
71
+ globalSecondaryIndexes?: Array<{
72
+ indexName: string;
73
+ partitionKey: DynamoDBKey;
74
+ sortKey?: DynamoDBKey;
75
+ }>;
76
+ ttlAttribute?: string;
77
+ stream?: boolean;
78
+ extraProperties?: ExtraProperty[];
79
+ node: ts.Node;
80
+ }
81
+ export interface ParsedInfrastructure {
82
+ sourceFile: ts.SourceFile;
83
+ imports: ImportInfo[];
84
+ appVariableName: string;
85
+ appName: string;
86
+ vpcId?: string;
87
+ network?: ParsedNetworkConfig;
88
+ backup?: {
89
+ tier: string;
90
+ } | false;
91
+ tunnel?: {
92
+ instanceType?: string;
93
+ } | boolean;
94
+ networkResources: ParsedNetworkResource[];
95
+ databaseResources: ParsedDatabaseResource[];
96
+ dynamodbResources: ParsedDynamoDBResource[];
97
+ sqsResources: ParsedSQSResource[];
98
+ cdnResource?: ParsedCDNResource;
99
+ s3Resources: ParsedS3Resource[];
100
+ computeResources: ParsedComputeResource[];
101
+ patternResources: ParsedPatternResource[];
102
+ tags: Record<string, string>;
103
+ /** Custom code blocks (user-written code) to preserve during regeneration */
104
+ customCodeBlocks?: CustomCodeBlock[];
105
+ /** All statements classified as managed or custom */
106
+ classifiedStatements?: ClassifiedStatement[];
107
+ }
108
+ /** Parsed Lambda function configuration */
109
+ export interface ParsedLambdaConfig {
110
+ memorySize?: number;
111
+ timeout?: number;
112
+ ephemeralStorageSize?: number;
113
+ }
114
+ /** Parsed pattern resource from app.addPattern(PatternFactory.build(...)) */
115
+ export interface ParsedPatternResource {
116
+ variableName?: string;
117
+ constructId: string;
118
+ type: "payload" | "nextjs";
119
+ config: {
120
+ name: string;
121
+ domain?: string;
122
+ database?: {
123
+ type?: "Instance" | "Aurora";
124
+ databaseName?: string;
125
+ databaseEngine?: "postgresql" | "mysql";
126
+ deletionProtection?: boolean;
127
+ backupRetention?: number;
128
+ port?: number;
129
+ publiclyAccessible?: boolean;
130
+ allowedIpCidr?: string;
131
+ instanceType?: string;
132
+ allocatedStorage?: number;
133
+ multiAz?: boolean;
134
+ allowVpcAccess?: boolean;
135
+ monitoringInterval?: number;
136
+ preferredMaintenanceWindow?: string;
137
+ snapshotIdentifier?: string;
138
+ snapshotUsername?: string;
139
+ readReplica?: object | false;
140
+ writer?: object;
141
+ readers?: object | false;
142
+ databaseInsights?: object | false;
143
+ proxy?: object | false;
144
+ credentials?: object;
145
+ encryption?: object;
146
+ };
147
+ compute?: {
148
+ server?: ParsedLambdaConfig;
149
+ imageOptimisation?: ParsedLambdaConfig;
150
+ revalidation?: ParsedLambdaConfig;
151
+ };
152
+ storage?: {
153
+ assets?: {
154
+ versioned?: boolean;
155
+ };
156
+ cache?: {
157
+ versioned?: boolean;
158
+ };
159
+ media?: {
160
+ versioned?: boolean;
161
+ };
162
+ };
163
+ messaging?: {
164
+ revalidationQueue?: {
165
+ visibilityTimeout?: number;
166
+ messageRetentionPeriod?: number;
167
+ maxMessageSize?: number;
168
+ deadLetterQueue?: {
169
+ enabled?: boolean;
170
+ maxReceiveCount?: number;
171
+ } | false;
172
+ };
173
+ };
174
+ cdn?: {
175
+ domainNames?: string[];
176
+ certificateArn?: string;
177
+ };
178
+ environment?: Record<string, string>;
179
+ };
180
+ node: ts.Node;
181
+ }
182
+ export interface ImportInfo {
183
+ moduleSpecifier: string;
184
+ namedImports: string[];
185
+ defaultImport?: string;
186
+ }
187
+ interface ParsedProxyConfig {
188
+ maxConnections?: number;
189
+ maxIdleConnections?: number;
190
+ connectionBorrowTimeout?: number;
191
+ requireTLS?: boolean;
192
+ }
193
+ interface ParsedReadReplicaConfig {
194
+ instanceType?: string;
195
+ availabilityZone?: string;
196
+ }
197
+ interface ParsedCredentialsConfig {
198
+ username?: string;
199
+ secretRotation?: {
200
+ automaticallyAfterDays?: number;
201
+ };
202
+ }
203
+ interface ParsedDatabaseInsightsConfig {
204
+ mode?: "standard" | "advanced";
205
+ encryptionKey?: {
206
+ awsManaged: true;
207
+ };
208
+ }
209
+ interface ParsedEncryptionConfig {
210
+ storageKey?: {
211
+ awsManaged: true;
212
+ };
213
+ }
214
+ interface ParsedAuroraWriterConfig {
215
+ enableDatabaseInsights?: boolean;
216
+ identifierSuffix?: string;
217
+ availabilityZone?: string;
218
+ }
219
+ interface ParsedAuroraReadersConfig {
220
+ count?: number;
221
+ defaultEnableDatabaseInsights?: boolean;
222
+ }
223
+ export interface ParsedDatabaseResource {
224
+ variableName?: string;
225
+ resourceName: string;
226
+ type: string;
227
+ databaseName: string;
228
+ databaseEngine?: "postgresql" | "mysql";
229
+ engineExpression?: string;
230
+ port?: number;
231
+ deletionProtection?: boolean;
232
+ instanceType?: string;
233
+ multiAz?: boolean;
234
+ publiclyAccessible?: boolean;
235
+ enableSecretRotation?: boolean;
236
+ encryption?: ParsedEncryptionConfig;
237
+ databaseInsights?: ParsedDatabaseInsightsConfig | false;
238
+ proxy?: ParsedProxyConfig | false;
239
+ readReplica?: ParsedReadReplicaConfig | false;
240
+ credentials?: ParsedCredentialsConfig;
241
+ writer?: ParsedAuroraWriterConfig;
242
+ readers?: ParsedAuroraReadersConfig | false;
243
+ backupRetention?: number;
244
+ preferredMaintenanceWindow?: string;
245
+ primaryRegion?: string;
246
+ secondaryRegions?: string[];
247
+ globalClusterIdentifier?: string;
248
+ enableGlobalWriteForwarding?: boolean;
249
+ snapshotIdentifier?: string;
250
+ snapshotUsername?: string;
251
+ extraProperties?: ExtraProperty[];
252
+ node: ts.Node;
253
+ }
254
+ export interface ParsedS3Resource {
255
+ variableName: string;
256
+ resourceName: string;
257
+ bucketClass: string;
258
+ config: ParsedObject;
259
+ node: ts.Node;
260
+ }
261
+ export interface ParsedComputeResource {
262
+ variableName?: string;
263
+ resourceName: string;
264
+ type: string;
265
+ config: ParsedObject;
266
+ node: ts.Node;
267
+ }
268
+ /** Parsed SQS queue resource from app.addMessaging(MessagingFactory.build(...)) */
269
+ export interface ParsedSQSResource {
270
+ variableName?: string;
271
+ resourceName: string;
272
+ queueType: string;
273
+ visibilityTimeout?: number;
274
+ retentionPeriod?: number;
275
+ contentBasedDeduplication?: boolean;
276
+ extraProperties?: ExtraProperty[];
277
+ node: ts.Node;
278
+ }
279
+ /** Parsed CDN resource from app.addCdn(CdnFactory.build(...)) */
280
+ export interface ParsedCDNResource {
281
+ resourceName: string;
282
+ config: ParsedObject;
283
+ node: ts.Node;
284
+ }
285
+ /** Parsed additional network resource from app.addNetwork() */
286
+ export interface ParsedNetworkResource {
287
+ variableName?: string;
288
+ name: string;
289
+ config: {
290
+ maxAzs?: number;
291
+ natGateways?: {
292
+ count?: number;
293
+ } | false;
294
+ flowLogs?: {
295
+ destination?: string;
296
+ retentionDays?: number;
297
+ } | false;
298
+ vpcEndpoints?: ParsedObject;
299
+ };
300
+ node: ts.Node;
301
+ }
302
+ export declare function parseInfrastructure(content: string, options?: {
303
+ extractCustomCode?: boolean;
304
+ }): ParsedInfrastructure;
305
+ export declare function convertToResourcePlan(parsed: ParsedInfrastructure, appName: string, options?: {
306
+ skipValidation?: boolean;
307
+ }): ApplicationResourcePlan;
308
+ /** Re-export for downstream consumers (e.g. astSurgicalModification) */
309
+ export type { StatementType } from "../schemas/resourceSchemas.js";
310
+ /**
311
+ * A classified statement with its type and metadata.
312
+ */
313
+ export interface ClassifiedStatement {
314
+ /** The statement type */
315
+ type: StatementType;
316
+ /** The AST node */
317
+ node: ts.Statement;
318
+ /** For managed resources, the resource name (e.g., "MyDatabase") */
319
+ resourceName?: string;
320
+ /** Start position in source text */
321
+ startPos: number;
322
+ /** End position in source text */
323
+ endPos: number;
324
+ /** Whether the statement is classified as managed by Fjall */
325
+ isManaged: boolean;
326
+ }
327
+ /** Re-export for downstream consumers (e.g. astSurgicalModification) */
328
+ export type { CustomCodeBlock } from "../schemas/resourceSchemas.js";
329
+ /**
330
+ * Classify all top-level statements in an infrastructure file.
331
+ * This identifies which statements are managed by Fjall vs custom user code.
332
+ */
333
+ export declare function classifyStatements(sourceFile: ts.SourceFile): ClassifiedStatement[];
334
+ /**
335
+ * Extract custom code blocks from an infrastructure file.
336
+ * Returns an array of custom code blocks with their positions relative to managed resources.
337
+ */
338
+ export declare function extractCustomCodeBlocks(sourceFile: ts.SourceFile, precomputedClassifications?: ClassifiedStatement[]): CustomCodeBlock[];
339
+ /**
340
+ * Find the position information for a specific managed resource.
341
+ * Useful for surgical updates.
342
+ */
343
+ export declare function findManagedResourcePosition(sourceFile: ts.SourceFile, resourceType: StatementType, resourceName: string, precomputedClassifications?: ClassifiedStatement[]): {
344
+ startPos: number;
345
+ endPos: number;
346
+ node: ts.Statement;
347
+ } | null;
348
+ /**
349
+ * Get the last managed statement of a specific type.
350
+ * Used to determine insertion points for new resources.
351
+ */
352
+ export declare function getLastManagedStatementOfType(sourceFile: ts.SourceFile, type: StatementType, precomputedClassifications?: ClassifiedStatement[]): ClassifiedStatement | null;
353
+ /**
354
+ * Get all managed resources grouped by type.
355
+ * Useful for understanding the structure of an infrastructure file.
356
+ */
357
+ export declare function getManagedResourcesByType(sourceFile: ts.SourceFile, precomputedClassifications?: ClassifiedStatement[]): Record<StatementType, ClassifiedStatement[]>;