effortless-aws 0.3.0 → 0.4.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/cli/index.js CHANGED
@@ -70597,6 +70597,12 @@ var handlerRegistry = {
70597
70597
  handlerProps: ["onRecord", "onBatch"],
70598
70598
  wrapperFn: "wrapTableStream",
70599
70599
  wrapperPath: "~/runtime/wrap-table-stream"
70600
+ },
70601
+ site: {
70602
+ defineFn: "defineSite",
70603
+ handlerProps: [],
70604
+ wrapperFn: "wrapSite",
70605
+ wrapperPath: "~/runtime/wrap-site"
70600
70606
  }
70601
70607
  };
70602
70608
  var extractHandlerConfigs = (source, type2) => {
@@ -70661,6 +70667,7 @@ export const handler = ${wrapperFn}(${importName});
70661
70667
  // src/build/bundle.ts
70662
70668
  var extractConfigs = (source) => extractHandlerConfigs(source, "http");
70663
70669
  var extractTableConfigs = (source) => extractHandlerConfigs(source, "table");
70670
+ var extractSiteConfigs = (source) => extractHandlerConfigs(source, "site");
70664
70671
  var runtimeDir = path5.resolve(path5.dirname(fileURLToPath2(import.meta.url)), "../../dist/runtime");
70665
70672
  var bundle = (input) => Effect_exports.gen(function* () {
70666
70673
  const exportName = input.exportName ?? "default";
@@ -70734,15 +70741,18 @@ var findHandlerFiles = (patterns, cwd) => {
70734
70741
  var discoverHandlers = (files) => {
70735
70742
  const httpHandlers = [];
70736
70743
  const tableHandlers = [];
70744
+ const siteHandlers = [];
70737
70745
  for (const file6 of files) {
70738
70746
  if (!fsSync2.statSync(file6).isFile()) continue;
70739
70747
  const source = fsSync2.readFileSync(file6, "utf-8");
70740
70748
  const http = extractConfigs(source);
70741
70749
  const table3 = extractTableConfigs(source);
70750
+ const site = extractSiteConfigs(source);
70742
70751
  if (http.length > 0) httpHandlers.push({ file: file6, exports: http });
70743
70752
  if (table3.length > 0) tableHandlers.push({ file: file6, exports: table3 });
70753
+ if (site.length > 0) siteHandlers.push({ file: file6, exports: site });
70744
70754
  }
70745
- return { httpHandlers, tableHandlers };
70755
+ return { httpHandlers, tableHandlers, siteHandlers };
70746
70756
  };
70747
70757
 
70748
70758
  // src/deploy/shared.ts
@@ -71091,6 +71101,35 @@ var deployAllTables = (input) => Effect_exports.gen(function* () {
71091
71101
  )
71092
71102
  );
71093
71103
 
71104
+ // src/deploy/deploy-site.ts
71105
+ import { execSync } from "child_process";
71106
+ var deploySiteLambda = ({ input, fn: fn2, layerArn, external, depsEnv, depsPermissions }) => Effect_exports.gen(function* () {
71107
+ const { exportName, config: config2 } = fn2;
71108
+ const handlerName = config2.name ?? exportName;
71109
+ if (config2.build) {
71110
+ yield* Effect_exports.logInfo(`Building site: ${config2.build}`);
71111
+ yield* Effect_exports.try({
71112
+ try: () => execSync(config2.build, { cwd: input.projectDir, stdio: "inherit" }),
71113
+ catch: (error4) => new Error(`Site build failed: ${error4}`)
71114
+ });
71115
+ }
71116
+ const staticGlobs = [`${config2.dir}/**/*`];
71117
+ const { functionArn } = yield* deployCoreLambda({
71118
+ input,
71119
+ exportName,
71120
+ handlerName,
71121
+ bundleType: "site",
71122
+ ...config2.memory ? { memory: config2.memory } : {},
71123
+ timeout: config2.timeout ?? 5,
71124
+ ...layerArn ? { layerArn } : {},
71125
+ ...external ? { external } : {},
71126
+ ...depsEnv ? { depsEnv } : {},
71127
+ ...depsPermissions ? { depsPermissions } : {},
71128
+ staticGlobs
71129
+ });
71130
+ return { exportName, functionArn, config: config2, handlerName };
71131
+ });
71132
+
71094
71133
  // src/deploy/deploy.ts
71095
71134
  var prepareLayer = (input) => Effect_exports.gen(function* () {
71096
71135
  const layerResult = yield* ensureLayer({
@@ -71295,19 +71334,86 @@ var deployTableHandlers = (ctx) => Effect_exports.gen(function* () {
71295
71334
  }
71296
71335
  return results;
71297
71336
  });
71337
+ var deploySiteHandlers = (ctx) => Effect_exports.gen(function* () {
71338
+ const results = [];
71339
+ for (const { file: file6, exports } of ctx.handlers) {
71340
+ yield* Effect_exports.logInfo(`Processing ${path7.basename(file6)} (${exports.length} site handler(s))`);
71341
+ const deployInput = {
71342
+ projectDir: ctx.input.projectDir,
71343
+ file: file6,
71344
+ project: ctx.input.project,
71345
+ region: ctx.input.region
71346
+ };
71347
+ if (ctx.input.stage) deployInput.stage = ctx.input.stage;
71348
+ for (const fn2 of exports) {
71349
+ const withPlatform = {
71350
+ depsEnv: { ...ctx.platformEnv },
71351
+ depsPermissions: [...ctx.platformPermissions]
71352
+ };
71353
+ const { exportName, functionArn, config: config2, handlerName } = yield* deploySiteLambda({
71354
+ input: deployInput,
71355
+ fn: fn2,
71356
+ ...ctx.layerArn ? { layerArn: ctx.layerArn } : {},
71357
+ ...ctx.external.length > 0 ? { external: ctx.external } : {},
71358
+ depsEnv: withPlatform.depsEnv,
71359
+ depsPermissions: withPlatform.depsPermissions
71360
+ }).pipe(
71361
+ Effect_exports.provide(
71362
+ clients_exports.makeClients({
71363
+ lambda: { region: ctx.input.region },
71364
+ iam: { region: ctx.input.region }
71365
+ })
71366
+ )
71367
+ );
71368
+ const basePath = config2.path.replace(/\/+$/, "") || "/";
71369
+ const { apiUrl: rootUrl } = yield* addRouteToApi({
71370
+ apiId: ctx.apiId,
71371
+ region: ctx.input.region,
71372
+ functionArn,
71373
+ method: "GET",
71374
+ path: basePath
71375
+ }).pipe(
71376
+ Effect_exports.provide(
71377
+ clients_exports.makeClients({
71378
+ lambda: { region: ctx.input.region },
71379
+ apigatewayv2: { region: ctx.input.region }
71380
+ })
71381
+ )
71382
+ );
71383
+ yield* addRouteToApi({
71384
+ apiId: ctx.apiId,
71385
+ region: ctx.input.region,
71386
+ functionArn,
71387
+ method: "GET",
71388
+ path: `${basePath}/{file+}`
71389
+ }).pipe(
71390
+ Effect_exports.provide(
71391
+ clients_exports.makeClients({
71392
+ lambda: { region: ctx.input.region },
71393
+ apigatewayv2: { region: ctx.input.region }
71394
+ })
71395
+ )
71396
+ );
71397
+ results.push({ exportName, url: rootUrl, functionArn });
71398
+ yield* Effect_exports.logInfo(` GET ${basePath} \u2192 ${handlerName} (site)`);
71399
+ }
71400
+ }
71401
+ return results;
71402
+ });
71298
71403
  var deployProject = (input) => Effect_exports.gen(function* () {
71299
71404
  const files = findHandlerFiles(input.patterns, input.projectDir);
71300
71405
  if (files.length === 0) {
71301
71406
  return yield* Effect_exports.fail(new Error(`No files match patterns: ${input.patterns.join(", ")}`));
71302
71407
  }
71303
71408
  yield* Effect_exports.logInfo(`Found ${files.length} file(s) matching patterns`);
71304
- const { httpHandlers, tableHandlers } = discoverHandlers(files);
71409
+ const { httpHandlers, tableHandlers, siteHandlers } = discoverHandlers(files);
71305
71410
  const totalHttpHandlers = httpHandlers.reduce((acc, h) => acc + h.exports.length, 0);
71306
71411
  const totalTableHandlers = tableHandlers.reduce((acc, h) => acc + h.exports.length, 0);
71307
- if (totalHttpHandlers === 0 && totalTableHandlers === 0) {
71412
+ const totalSiteHandlers = siteHandlers.reduce((acc, h) => acc + h.exports.length, 0);
71413
+ if (totalHttpHandlers === 0 && totalTableHandlers === 0 && totalSiteHandlers === 0) {
71308
71414
  return yield* Effect_exports.fail(new Error("No handlers found in matched files"));
71309
71415
  }
71310
- yield* Effect_exports.logInfo(`Discovered ${totalHttpHandlers} HTTP handler(s) and ${totalTableHandlers} table handler(s)`);
71416
+ yield* Effect_exports.logInfo(`Discovered ${totalHttpHandlers} HTTP, ${totalTableHandlers} table, ${totalSiteHandlers} site handler(s)`);
71311
71417
  const tableNameMap = buildTableNameMap(tableHandlers, input.project, resolveStage(input.stage));
71312
71418
  const { layerArn, external } = yield* prepareLayer({
71313
71419
  project: input.project,
@@ -71320,7 +71426,7 @@ var deployProject = (input) => Effect_exports.gen(function* () {
71320
71426
  const platformEnv = { EFF_PLATFORM_TABLE: platformTableName };
71321
71427
  let apiId;
71322
71428
  let apiUrl;
71323
- if (totalHttpHandlers > 0) {
71429
+ if (totalHttpHandlers > 0 || totalSiteHandlers > 0) {
71324
71430
  const tagCtx = {
71325
71431
  project: input.project,
71326
71432
  stage: resolveStage(input.stage),
@@ -71361,10 +71467,19 @@ var deployProject = (input) => Effect_exports.gen(function* () {
71361
71467
  platformEnv,
71362
71468
  platformPermissions: PLATFORM_PERMISSIONS
71363
71469
  });
71470
+ const siteResults = apiId ? yield* deploySiteHandlers({
71471
+ handlers: siteHandlers,
71472
+ apiId,
71473
+ input,
71474
+ layerArn,
71475
+ external,
71476
+ platformEnv,
71477
+ platformPermissions: PLATFORM_PERMISSIONS
71478
+ }) : [];
71364
71479
  if (apiUrl) {
71365
71480
  yield* Effect_exports.logInfo(`Deployment complete! API: ${apiUrl}`);
71366
71481
  }
71367
- return { apiId, apiUrl, httpResults, tableResults };
71482
+ return { apiId, apiUrl, httpResults, tableResults, siteResults };
71368
71483
  });
71369
71484
 
71370
71485
  // src/cli/config.ts
@@ -71483,7 +71598,7 @@ var deployCommand = Command_exports.make(
71483
71598
  stage: finalStage,
71484
71599
  region: finalRegion
71485
71600
  });
71486
- const total = results.httpResults.length + results.tableResults.length;
71601
+ const total = results.httpResults.length + results.tableResults.length + results.siteResults.length;
71487
71602
  yield* Console_exports.log(`
71488
71603
  Deployed ${total} handler(s):`);
71489
71604
  for (const r of results.httpResults) {
@@ -71492,6 +71607,9 @@ Deployed ${total} handler(s):`);
71492
71607
  for (const r of results.tableResults) {
71493
71608
  yield* Console_exports.log(` [table] ${r.exportName}: ${r.tableArn}`);
71494
71609
  }
71610
+ for (const r of results.siteResults) {
71611
+ yield* Console_exports.log(` [site] ${r.exportName}: ${r.url}`);
71612
+ }
71495
71613
  }),
71496
71614
  onSome: (targetValue) => Effect_exports.gen(function* () {
71497
71615
  if (isFilePath(targetValue)) {
@@ -71544,7 +71662,7 @@ Deployed ${tableResults.length} table handler(s):`);
71544
71662
  const discovered = discoverHandlers(files);
71545
71663
  let foundFile = null;
71546
71664
  let foundExport = null;
71547
- let isTableHandler = false;
71665
+ let handlerType = "http";
71548
71666
  for (const { file: file6, exports } of discovered.httpHandlers) {
71549
71667
  for (const { exportName, config: handlerConfig } of exports) {
71550
71668
  if (handlerConfig.name === targetValue) {
@@ -71561,7 +71679,20 @@ Deployed ${tableResults.length} table handler(s):`);
71561
71679
  if (handlerConfig.name === targetValue) {
71562
71680
  foundFile = file6;
71563
71681
  foundExport = exportName;
71564
- isTableHandler = true;
71682
+ handlerType = "table";
71683
+ break;
71684
+ }
71685
+ }
71686
+ if (foundFile) break;
71687
+ }
71688
+ }
71689
+ if (!foundFile) {
71690
+ for (const { file: file6, exports } of discovered.siteHandlers) {
71691
+ for (const { exportName, config: handlerConfig } of exports) {
71692
+ if (handlerConfig.name === targetValue) {
71693
+ foundFile = file6;
71694
+ foundExport = exportName;
71695
+ handlerType = "site";
71565
71696
  break;
71566
71697
  }
71567
71698
  }
@@ -71581,6 +71712,11 @@ Deployed ${tableResults.length} table handler(s):`);
71581
71712
  yield* Console_exports.log(` [table] ${c.name}`);
71582
71713
  }
71583
71714
  }
71715
+ for (const { exports } of discovered.siteHandlers) {
71716
+ for (const { config: c } of exports) {
71717
+ yield* Console_exports.log(` [site] ${c.name}`);
71718
+ }
71719
+ }
71584
71720
  return;
71585
71721
  }
71586
71722
  yield* Console_exports.log(`Found handler "${targetValue}" in ${path9.relative(projectDir, foundFile)}`);
@@ -71592,7 +71728,7 @@ Deployed ${tableResults.length} table handler(s):`);
71592
71728
  region: finalRegion,
71593
71729
  exportName: foundExport
71594
71730
  };
71595
- if (isTableHandler) {
71731
+ if (handlerType === "table") {
71596
71732
  const result = yield* deployTable(input);
71597
71733
  yield* Console_exports.log(`
71598
71734
  Table deployed: ${result.tableArn}`);