( params: FinalizeLambdaParams )
| 94 | * supportsResponseStreaming). |
| 95 | */ |
| 96 | export async function finalizeLambda( |
| 97 | params: FinalizeLambdaParams |
| 98 | ): Promise<FinalizeLambdaResult> { |
| 99 | const { |
| 100 | lambda, |
| 101 | encryptedEnvFilename, |
| 102 | encryptedEnvContent, |
| 103 | bytecodeCachingOptions, |
| 104 | forceStreamingRuntime, |
| 105 | enableUncompressedLambdaSizeCheck, |
| 106 | trace = defaultTrace, |
| 107 | createZip: createZipOverride, |
| 108 | validateZip, |
| 109 | } = params; |
| 110 | |
| 111 | // 1. Encrypted env injection |
| 112 | const encryptedEnv = getEncryptedEnv( |
| 113 | encryptedEnvFilename, |
| 114 | encryptedEnvContent |
| 115 | ); |
| 116 | if (encryptedEnv) { |
| 117 | const [envFilename, envFile] = encryptedEnv; |
| 118 | lambda.zipBuffer = undefined; |
| 119 | lambda.files = { |
| 120 | ...lambda.files, |
| 121 | [envFilename]: envFile, |
| 122 | }; |
| 123 | } |
| 124 | |
| 125 | // 2. Uncompressed size collection |
| 126 | let uncompressedBytes = 0; |
| 127 | if (enableUncompressedLambdaSizeCheck) { |
| 128 | if (lambda.files) { |
| 129 | uncompressedBytes = await trace('collectUncompressedSize', () => |
| 130 | collectUncompressedSize(lambda.files ?? {}) |
| 131 | ); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | // 3. ZIP creation (pluggable strategy) |
| 136 | const zipTags: Record<string, string> = { |
| 137 | fileCount: String(Object.keys(lambda.files ?? {}).length), |
| 138 | uncompressedBytes: String(uncompressedBytes), |
| 139 | }; |
| 140 | |
| 141 | let zipResult: CreateZipResult; |
| 142 | if (createZipOverride) { |
| 143 | // Custom path (e.g. file-based): digest already computed by callback |
| 144 | zipResult = await trace( |
| 145 | 'createZip', |
| 146 | () => createZipOverride(lambda), |
| 147 | zipTags |
| 148 | ); |
| 149 | } else { |
| 150 | // Default in-memory path: create buffer first, digest deferred to step 5 |
| 151 | const buffer = |
| 152 | lambda.zipBuffer || |
| 153 | (await trace('createZip', () => lambda.createZip(), zipTags)); |
no test coverage detected