effortless-aws 0.11.0 → 0.13.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.
- package/dist/{chunk-WGORLS4M.js → chunk-SSEPES5N.js} +97 -12
- package/dist/cli/index.js +252 -62
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +243 -47
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -1
- package/dist/runtime/wrap-app.js +1 -1
- package/dist/runtime/wrap-bucket.js +66 -0
- package/dist/runtime/wrap-fifo-queue.js +1 -1
- package/dist/runtime/wrap-http.js +1 -1
- package/dist/runtime/wrap-table-stream.js +5 -4
- package/package.json +1 -1
|
@@ -183,6 +183,74 @@ var createTableClient = (tableName, options) => {
|
|
|
183
183
|
};
|
|
184
184
|
};
|
|
185
185
|
|
|
186
|
+
// src/runtime/bucket-client.ts
|
|
187
|
+
import { S3 } from "@aws-sdk/client-s3";
|
|
188
|
+
var createBucketClient = (bucketName) => {
|
|
189
|
+
let client2 = null;
|
|
190
|
+
const getClient2 = () => client2 ??= new S3({});
|
|
191
|
+
return {
|
|
192
|
+
bucketName,
|
|
193
|
+
async put(key, body, options) {
|
|
194
|
+
await getClient2().putObject({
|
|
195
|
+
Bucket: bucketName,
|
|
196
|
+
Key: key,
|
|
197
|
+
Body: typeof body === "string" ? Buffer.from(body) : body,
|
|
198
|
+
...options?.contentType ? { ContentType: options.contentType } : {}
|
|
199
|
+
});
|
|
200
|
+
},
|
|
201
|
+
async get(key) {
|
|
202
|
+
try {
|
|
203
|
+
const result = await getClient2().getObject({
|
|
204
|
+
Bucket: bucketName,
|
|
205
|
+
Key: key
|
|
206
|
+
});
|
|
207
|
+
const chunks = [];
|
|
208
|
+
const stream = result.Body;
|
|
209
|
+
for await (const chunk of stream) {
|
|
210
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
body: Buffer.concat(chunks),
|
|
214
|
+
contentType: result.ContentType
|
|
215
|
+
};
|
|
216
|
+
} catch (error) {
|
|
217
|
+
if (error instanceof Error && (error.name === "NoSuchKey" || error.$metadata?.httpStatusCode === 404)) {
|
|
218
|
+
return void 0;
|
|
219
|
+
}
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
async delete(key) {
|
|
224
|
+
await getClient2().deleteObject({
|
|
225
|
+
Bucket: bucketName,
|
|
226
|
+
Key: key
|
|
227
|
+
});
|
|
228
|
+
},
|
|
229
|
+
async list(prefix) {
|
|
230
|
+
const items = [];
|
|
231
|
+
let continuationToken;
|
|
232
|
+
do {
|
|
233
|
+
const result = await getClient2().listObjectsV2({
|
|
234
|
+
Bucket: bucketName,
|
|
235
|
+
...prefix ? { Prefix: prefix } : {},
|
|
236
|
+
...continuationToken ? { ContinuationToken: continuationToken } : {}
|
|
237
|
+
});
|
|
238
|
+
for (const obj of result.Contents ?? []) {
|
|
239
|
+
if (obj.Key) {
|
|
240
|
+
items.push({
|
|
241
|
+
key: obj.Key,
|
|
242
|
+
size: obj.Size ?? 0,
|
|
243
|
+
lastModified: obj.LastModified
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
continuationToken = result.IsTruncated ? result.NextContinuationToken : void 0;
|
|
248
|
+
} while (continuationToken);
|
|
249
|
+
return items;
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
|
|
186
254
|
// src/runtime/handler-utils.ts
|
|
187
255
|
import { readFileSync } from "fs";
|
|
188
256
|
import { join } from "path";
|
|
@@ -209,7 +277,7 @@ var getParameters = async (names) => {
|
|
|
209
277
|
};
|
|
210
278
|
|
|
211
279
|
// src/runtime/handler-utils.ts
|
|
212
|
-
var
|
|
280
|
+
var ENV_DEP_PREFIX = "EFF_DEP_";
|
|
213
281
|
var ENV_PARAM_PREFIX = "EFF_PARAM_";
|
|
214
282
|
var LOG_RANK = { error: 0, info: 1, debug: 2 };
|
|
215
283
|
var truncate = (value, maxLength = 4096) => {
|
|
@@ -218,17 +286,27 @@ var truncate = (value, maxLength = 4096) => {
|
|
|
218
286
|
if (str.length <= maxLength) return value;
|
|
219
287
|
return str.slice(0, maxLength) + "...[truncated]";
|
|
220
288
|
};
|
|
289
|
+
var DEP_FACTORIES = {
|
|
290
|
+
table: (name, depHandler) => {
|
|
291
|
+
const tagField = depHandler?.__spec?.tagField;
|
|
292
|
+
return createTableClient(name, tagField ? { tagField } : void 0);
|
|
293
|
+
},
|
|
294
|
+
bucket: (name) => createBucketClient(name)
|
|
295
|
+
};
|
|
296
|
+
var parseDepValue = (raw) => {
|
|
297
|
+
const idx = raw.indexOf(":");
|
|
298
|
+
return { type: raw.slice(0, idx), name: raw.slice(idx + 1) };
|
|
299
|
+
};
|
|
221
300
|
var buildDeps = (deps) => {
|
|
222
301
|
if (!deps) return void 0;
|
|
223
302
|
const result = {};
|
|
224
303
|
for (const key of Object.keys(deps)) {
|
|
225
|
-
const
|
|
226
|
-
if (!
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
result[key] = createTableClient(tableName, tagField ? { tagField } : void 0);
|
|
304
|
+
const raw = process.env[`${ENV_DEP_PREFIX}${key}`];
|
|
305
|
+
if (!raw) throw new Error(`Missing environment variable ${ENV_DEP_PREFIX}${key} for dep "${key}"`);
|
|
306
|
+
const { type, name } = parseDepValue(raw);
|
|
307
|
+
const factory = DEP_FACTORIES[type];
|
|
308
|
+
if (!factory) throw new Error(`Unknown dep type "${type}" for dep "${key}"`);
|
|
309
|
+
result[key] = factory(name, deps[key]);
|
|
232
310
|
}
|
|
233
311
|
return result;
|
|
234
312
|
};
|
|
@@ -252,7 +330,12 @@ var buildParams = async (params) => {
|
|
|
252
330
|
}
|
|
253
331
|
return result;
|
|
254
332
|
};
|
|
255
|
-
var
|
|
333
|
+
var resolvePath = (filePath) => join(process.cwd(), filePath);
|
|
334
|
+
var staticFiles = {
|
|
335
|
+
read: (filePath) => readFileSync(resolvePath(filePath), "utf-8"),
|
|
336
|
+
readBuffer: (filePath) => readFileSync(resolvePath(filePath)),
|
|
337
|
+
path: resolvePath
|
|
338
|
+
};
|
|
256
339
|
var createHandlerRuntime = (handler, handlerType, logLevel = "info", extraSetupArgs) => {
|
|
257
340
|
const handlerName = process.env.EFF_HANDLER ?? "unknown";
|
|
258
341
|
const rank = LOG_RANK[logLevel];
|
|
@@ -273,8 +356,9 @@ var createHandlerRuntime = (handler, handlerType, logLevel = "info", extraSetupA
|
|
|
273
356
|
const args = {};
|
|
274
357
|
if (params) args.config = params;
|
|
275
358
|
if (deps) args.deps = deps;
|
|
359
|
+
if (handler.static) args.files = staticFiles;
|
|
276
360
|
if (extraSetupArgs) Object.assign(args, extraSetupArgs());
|
|
277
|
-
ctx =
|
|
361
|
+
ctx = await handler.setup(args);
|
|
278
362
|
}
|
|
279
363
|
return ctx;
|
|
280
364
|
};
|
|
@@ -285,7 +369,7 @@ var createHandlerRuntime = (handler, handlerType, logLevel = "info", extraSetupA
|
|
|
285
369
|
if (deps) args.deps = deps;
|
|
286
370
|
const params = await getParams();
|
|
287
371
|
if (params) args.config = params;
|
|
288
|
-
if (handler.static) args.
|
|
372
|
+
if (handler.static) args.files = staticFiles;
|
|
289
373
|
return args;
|
|
290
374
|
};
|
|
291
375
|
const logExecution = (startTime, input, output) => {
|
|
@@ -317,7 +401,7 @@ var createHandlerRuntime = (handler, handlerType, logLevel = "info", extraSetupA
|
|
|
317
401
|
};
|
|
318
402
|
const noop = () => {
|
|
319
403
|
};
|
|
320
|
-
const saved = { log: console.log, info: console.info, debug: console.debug
|
|
404
|
+
const saved = { log: console.log, info: console.info, debug: console.debug };
|
|
321
405
|
const patchConsole = () => {
|
|
322
406
|
if (rank < LOG_RANK.debug) console.debug = noop;
|
|
323
407
|
if (rank < LOG_RANK.info) {
|
|
@@ -335,5 +419,6 @@ var createHandlerRuntime = (handler, handlerType, logLevel = "info", extraSetupA
|
|
|
335
419
|
|
|
336
420
|
export {
|
|
337
421
|
createTableClient,
|
|
422
|
+
createBucketClient,
|
|
338
423
|
createHandlerRuntime
|
|
339
424
|
};
|