@awsless/awsless 0.0.315 → 0.0.317

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/bin.js CHANGED
@@ -457,7 +457,9 @@ var ArchitectureSchema = z5.enum(["x86_64", "arm64"]).describe("The instruction
457
457
  var RetryAttemptsSchema = z5.number().int().min(0).max(2).describe(
458
458
  "The maximum number of times to retry when the function returns an error. You can specify a number from 0 to 2."
459
459
  );
460
- var RuntimeSchema = z5.enum(["nodejs18.x", "nodejs20.x"]).describe("The identifier of the function's runtime.");
460
+ var NodeRuntimeSchema = z5.enum(["nodejs18.x", "nodejs20.x"]).describe("The identifier of the function's runtime.");
461
+ var ContainerRuntimeSchema = z5.literal("container").describe("The identifier of the function's runtime.");
462
+ var RuntimeSchema = NodeRuntimeSchema.or(ContainerRuntimeSchema);
461
463
  var ActionSchema = z5.string();
462
464
  var ActionsSchema = z5.union([ActionSchema.transform((v) => [v]), ActionSchema.array()]);
463
465
  var ArnSchema = z5.string().startsWith("arn:").transform((v) => v);
@@ -500,7 +502,7 @@ var LayersSchema = ArnSchema.array().describe(
500
502
  `A list of function layers to add to the function's execution environment. Specify each layer by its ARN, including the version.`
501
503
  );
502
504
  var BuildSchema = z5.object({
503
- // minify: z.boolean().optional().describe('')
505
+ minify: MinifySchema.default(true),
504
506
  external: z5.string().array().optional().describe(`A list of external packages that won't be included in the bundle.`)
505
507
  }).describe(`Options for the function bundler`);
506
508
  var FunctionSchema = z5.union([
@@ -509,29 +511,36 @@ var FunctionSchema = z5.union([
509
511
  })),
510
512
  z5.object({
511
513
  file: FileSchema,
512
- description: DescriptionSchema.optional(),
514
+ // node
513
515
  handler: HandlerSchema.optional(),
514
- minify: MinifySchema.optional(),
516
+ build: BuildSchema.optional(),
517
+ // container
518
+ // ...
519
+ runtime: RuntimeSchema.optional(),
520
+ description: DescriptionSchema.optional(),
515
521
  warm: WarmSchema.optional(),
516
522
  vpc: VPCSchema.optional(),
517
523
  log: LogSchema.optional(),
518
524
  timeout: TimeoutSchema.optional(),
519
- runtime: RuntimeSchema.optional(),
520
525
  memorySize: MemorySizeSchema.optional(),
521
526
  architecture: ArchitectureSchema.optional(),
522
527
  ephemeralStorageSize: EphemeralStorageSizeSchema.optional(),
523
528
  retryAttempts: RetryAttemptsSchema.optional(),
524
529
  reserved: ReservedConcurrentExecutionsSchema.optional(),
525
530
  layers: LayersSchema.optional(),
526
- build: BuildSchema.optional(),
527
531
  environment: EnvironmentSchema.optional(),
528
532
  permissions: PermissionsSchema.optional()
529
533
  })
530
534
  ]);
531
535
  var FunctionsSchema = z5.record(ResourceIdSchema, FunctionSchema).optional().describe("Define the functions in your stack.");
532
536
  var FunctionDefaultSchema = z5.object({
537
+ runtime: RuntimeSchema.default("nodejs20.x"),
538
+ // node
533
539
  handler: HandlerSchema.default("index.default"),
534
- minify: MinifySchema.default(true),
540
+ build: BuildSchema.default({
541
+ minify: true
542
+ }),
543
+ // container
535
544
  warm: WarmSchema.default(0),
536
545
  vpc: VPCSchema.default(false),
537
546
  log: LogSchema.default({
@@ -541,14 +550,12 @@ var FunctionDefaultSchema = z5.object({
541
550
  format: "json"
542
551
  }),
543
552
  timeout: TimeoutSchema.default("10 seconds"),
544
- runtime: RuntimeSchema.default("nodejs20.x"),
545
553
  memorySize: MemorySizeSchema.default("128 MB"),
546
554
  architecture: ArchitectureSchema.default("arm64"),
547
555
  ephemeralStorageSize: EphemeralStorageSizeSchema.default("512 MB"),
548
556
  retryAttempts: RetryAttemptsSchema.default(2),
549
557
  reserved: ReservedConcurrentExecutionsSchema.optional(),
550
558
  layers: LayersSchema.optional(),
551
- build: BuildSchema.optional(),
552
559
  environment: EnvironmentSchema.optional(),
553
560
  permissions: PermissionsSchema.optional()
554
561
  }).default({});
@@ -1961,7 +1968,7 @@ var formatLocalResourceName = (appName, stackName, ns, id, seperator = "--") =>
1961
1968
  import { Asset, aws as aws2 } from "@awsless/formation";
1962
1969
  import { generateFileHash } from "@awsless/ts-file-cache";
1963
1970
  import deepmerge from "deepmerge";
1964
- import { basename as basename3, dirname as dirname6, extname as extname2 } from "path";
1971
+ import { dirname as dirname6 } from "path";
1965
1972
  import { exec } from "promisify-child-process";
1966
1973
 
1967
1974
  // src/build/index.ts
@@ -2160,36 +2167,9 @@ var createLambdaFunction = (group, ctx, ns, id, local2) => {
2160
2167
  name = formatGlobalResourceName(ctx.appConfig.name, ns, id);
2161
2168
  }
2162
2169
  const props = deepmerge(ctx.appConfig.defaults.function, local2);
2163
- const ext = extname2(props.file);
2164
2170
  let code;
2165
2171
  let sourceCodeHash;
2166
- if ([".ts", ".js", ".tsx", ".sx"].includes(ext)) {
2167
- ctx.registerBuild("function", name, async (build3, { packageVersions }) => {
2168
- const version = await generateFileHash(props.file, {
2169
- packageVersions
2170
- });
2171
- return build3(version, async (write) => {
2172
- const bundle = await bundleTypeScript({
2173
- file: props.file,
2174
- external: props.build?.external
2175
- });
2176
- const archive = await zipFiles(bundle.files);
2177
- await Promise.all([
2178
- write("bundle.zip", archive),
2179
- ...bundle.files.map((file) => write(`files/${file.name}`, file.code)),
2180
- ...bundle.files.map((file) => file.map && write(`files/${file.name}.map`, file.map))
2181
- ]);
2182
- return {
2183
- size: formatByteSize(archive.byteLength)
2184
- };
2185
- });
2186
- });
2187
- code = new aws2.s3.BucketObject(group, "code", {
2188
- bucket: ctx.shared.get("function-bucket-name"),
2189
- key: `/lambda/${name}.zip`,
2190
- body: Asset.fromFile(getBuildPath("function", name, "bundle.zip"))
2191
- });
2192
- } else if (basename3(props.file) === "dockerfile") {
2172
+ if (props.runtime === "container") {
2193
2173
  ctx.registerBuild("function", name, async (build3) => {
2194
2174
  const basePath2 = dirname6(props.file);
2195
2175
  const version = await hashElement(basePath2, {
@@ -2199,7 +2179,8 @@ var createLambdaFunction = (group, ctx, ns, id, local2) => {
2199
2179
  });
2200
2180
  return build3(version.hash, async (write) => {
2201
2181
  const repoName = formatGlobalResourceName(ctx.appConfig.name, "function", "repository", "-");
2202
- await exec(`docker build -t ${name} .`, {
2182
+ const platform = props.architecture === "arm64" ? "linux/arm64" : "linux/x86_64";
2183
+ await exec(`docker buildx build --platform ${platform} -t ${name} .`, {
2203
2184
  cwd: basePath2
2204
2185
  });
2205
2186
  await exec(
@@ -2223,7 +2204,32 @@ var createLambdaFunction = (group, ctx, ns, id, local2) => {
2223
2204
  imageUri: image.uri
2224
2205
  };
2225
2206
  } else {
2226
- throw new Error("Unknown Lambda Function type.");
2207
+ ctx.registerBuild("function", name, async (build3, { packageVersions }) => {
2208
+ const version = await generateFileHash(props.file, {
2209
+ packageVersions
2210
+ });
2211
+ return build3(version, async (write) => {
2212
+ const bundle = await bundleTypeScript({
2213
+ file: props.file,
2214
+ external: props.build.external,
2215
+ minify: props.build.minify
2216
+ });
2217
+ const archive = await zipFiles(bundle.files);
2218
+ await Promise.all([
2219
+ write("bundle.zip", archive),
2220
+ ...bundle.files.map((file) => write(`files/${file.name}`, file.code)),
2221
+ ...bundle.files.map((file) => file.map && write(`files/${file.name}.map`, file.map))
2222
+ ]);
2223
+ return {
2224
+ size: formatByteSize(archive.byteLength)
2225
+ };
2226
+ });
2227
+ });
2228
+ code = new aws2.s3.BucketObject(group, "code", {
2229
+ bucket: ctx.shared.get("function-bucket-name"),
2230
+ key: `/lambda/${name}.zip`,
2231
+ body: Asset.fromFile(getBuildPath("function", name, "bundle.zip"))
2232
+ });
2227
2233
  }
2228
2234
  const role = new aws2.iam.Role(group, "role", {
2229
2235
  name,
@@ -2248,6 +2254,7 @@ var createLambdaFunction = (group, ctx, ns, id, local2) => {
2248
2254
  role: role.arn,
2249
2255
  code,
2250
2256
  sourceCodeHash,
2257
+ runtime: props.runtime === "container" ? void 0 : props.runtime,
2251
2258
  // Remove conflicting props.
2252
2259
  vpc: void 0,
2253
2260
  log: props.log
@@ -2827,6 +2834,7 @@ var domainFeature = defineFeature({
2827
2834
  import { aws as aws7, Node as Node6 } from "@awsless/formation";
2828
2835
  import { camelCase as camelCase3 } from "change-case";
2829
2836
  import { relative } from "path";
2837
+ import deepmerge2 from "deepmerge";
2830
2838
  var typeGenCode2 = `
2831
2839
  import { InvokeOptions, InvokeResponse } from '@awsless/lambda'
2832
2840
  import type { PartialDeep } from 'type-fest'
@@ -2865,14 +2873,17 @@ var functionFeature = defineFeature({
2865
2873
  const resource2 = new TypeObject(2);
2866
2874
  const mock = new TypeObject(2);
2867
2875
  const mockResponse = new TypeObject(2);
2868
- for (const [name, props] of Object.entries(stack.functions || {})) {
2869
- const varName = camelCase3(`${stack.name}-${name}`);
2870
- const funcName = formatLocalResourceName(ctx.appConfig.name, stack.name, "function", name);
2871
- const relFile = relative(directories.types, props.file);
2872
- types2.addImport(varName, relFile);
2873
- resource2.addType(name, `Invoke<'${funcName}', typeof ${varName}>`);
2874
- mock.addType(name, `MockBuilder<typeof ${varName}>`);
2875
- mockResponse.addType(name, `MockObject<typeof ${varName}>`);
2876
+ for (const [name, local2] of Object.entries(stack.functions || {})) {
2877
+ const props = deepmerge2(ctx.appConfig.defaults.function, local2);
2878
+ if (props.runtime !== "container") {
2879
+ const varName = camelCase3(`${stack.name}-${name}`);
2880
+ const funcName = formatLocalResourceName(ctx.appConfig.name, stack.name, "function", name);
2881
+ const relFile = relative(directories.types, props.file);
2882
+ types2.addImport(varName, relFile);
2883
+ resource2.addType(name, `Invoke<'${funcName}', typeof ${varName}>`);
2884
+ mock.addType(name, `MockBuilder<typeof ${varName}>`);
2885
+ mockResponse.addType(name, `MockObject<typeof ${varName}>`);
2886
+ }
2876
2887
  }
2877
2888
  mocks.addType(stack.name, mock);
2878
2889
  resources.addType(stack.name, resource2);
@@ -3705,7 +3716,7 @@ var pubsubFeature = defineFeature({
3705
3716
  // src/feature/queue/index.ts
3706
3717
  import { aws as aws13, Node as Node12 } from "@awsless/formation";
3707
3718
  import { camelCase as camelCase5, constantCase as constantCase7 } from "change-case";
3708
- import deepmerge2 from "deepmerge";
3719
+ import deepmerge3 from "deepmerge";
3709
3720
  import { relative as relative3 } from "path";
3710
3721
  var typeGenCode3 = `
3711
3722
  import { SendMessageOptions, SendMessageBatchOptions, BatchItem } from '@awsless/sqs'
@@ -3757,7 +3768,7 @@ var queueFeature = defineFeature({
3757
3768
  },
3758
3769
  onStack(ctx) {
3759
3770
  for (const [id, local2] of Object.entries(ctx.stackConfig.queues || {})) {
3760
- const props = deepmerge2(ctx.appConfig.defaults.queue, local2);
3771
+ const props = deepmerge3(ctx.appConfig.defaults.queue, local2);
3761
3772
  const group = new Node12(ctx.stack, "queue", id);
3762
3773
  const queue2 = new aws13.sqs.Queue(group, "queue", {
3763
3774
  name: formatLocalResourceName(ctx.appConfig.name, ctx.stack.name, "queue", id),
@@ -3949,7 +3960,7 @@ import { join as join7 } from "path";
3949
3960
 
3950
3961
  // src/feature/site/util.ts
3951
3962
  import { lookup, contentType } from "mime-types";
3952
- import { extname as extname3 } from "path";
3963
+ import { extname as extname2 } from "path";
3953
3964
  var getCacheControl = (file) => {
3954
3965
  switch (lookup(file)) {
3955
3966
  case false:
@@ -3964,7 +3975,7 @@ var getCacheControl = (file) => {
3964
3975
  }
3965
3976
  };
3966
3977
  var getContentType = (file) => {
3967
- return contentType(extname3(file)) || "text/html; charset=utf-8";
3978
+ return contentType(extname2(file)) || "text/html; charset=utf-8";
3968
3979
  };
3969
3980
 
3970
3981
  // src/feature/site/index.ts
@@ -4212,7 +4223,10 @@ var storeFeature = defineFeature({
4212
4223
  for (const [event, funcProps] of Object.entries(props.events ?? {})) {
4213
4224
  const eventGroup = new Node16(group, "event", event);
4214
4225
  const eventId = paramCase6(`${id}-${shortId(event)}`);
4215
- const { lambda } = createAsyncLambdaFunction(eventGroup, ctx, `store`, eventId, funcProps);
4226
+ const { lambda } = createAsyncLambdaFunction(eventGroup, ctx, `store`, eventId, {
4227
+ ...funcProps,
4228
+ description: `${id} event "${event}"`
4229
+ });
4216
4230
  new aws17.lambda.Permission(eventGroup, "permission", {
4217
4231
  action: "lambda:InvokeFunction",
4218
4232
  principal: "s3.amazonaws.com",
@@ -5053,7 +5067,7 @@ import { join as join10 } from "path";
5053
5067
  // src/build/__fingerprint.ts
5054
5068
  import { createHash as createHash4 } from "crypto";
5055
5069
  import { readdir, readFile as readFile5, stat as stat3 } from "fs/promises";
5056
- import { basename as basename4, dirname as dirname9, extname as extname4, join as join8 } from "path";
5070
+ import { basename as basename3, dirname as dirname9, extname as extname3, join as join8 } from "path";
5057
5071
  import parseStaticImports from "parse-static-imports";
5058
5072
  var extensions = ["js", "mjs", "jsx", "ts", "mts", "tsx"];
5059
5073
  var generateFileHashes = async (file, hashes) => {
@@ -5074,7 +5088,7 @@ var fingerprintFromDirectory = async (dir) => {
5074
5088
  const hashes = /* @__PURE__ */ new Map();
5075
5089
  const files = await readdir(dir, { recursive: true });
5076
5090
  for (const file of files) {
5077
- if (extensions.includes(extname4(file).substring(1)) && file.at(0) !== "_") {
5091
+ if (extensions.includes(extname3(file).substring(1)) && file.at(0) !== "_") {
5078
5092
  await generateFileHashes(join8(dir, file), hashes);
5079
5093
  }
5080
5094
  }
@@ -5085,7 +5099,7 @@ var readModuleFile = (file) => {
5085
5099
  if (file.endsWith(".js")) {
5086
5100
  return readFiles([file, file.substring(0, file.length - 3) + ".ts"]);
5087
5101
  }
5088
- if (!basename4(file).includes(".")) {
5102
+ if (!basename3(file).includes(".")) {
5089
5103
  return readFiles([
5090
5104
  file,
5091
5105
  ...extensions.map((exp) => `${file}.${exp}`),
@@ -5821,7 +5835,7 @@ var state = (program2) => {
5821
5835
  // src/cli/command/test.ts
5822
5836
  var test = (program2) => {
5823
5837
  program2.command("test").argument("[stacks...]", "Optionally filter stacks to test").option("-f --filters <string...>", "Optionally filter test files").description("Test your app").action(async (stacks, options) => {
5824
- await layout("test", async (props) => {
5838
+ await layout(`test ${stacks ?? ""}`, async (props) => {
5825
5839
  const region = props.appConfig.region;
5826
5840
  const credentials = getCredentials(props.appConfig.profile);
5827
5841
  const accountId = await getAccountId(credentials, region);
@@ -114,7 +114,9 @@ var ArchitectureSchema = z5.enum(["x86_64", "arm64"]).describe("The instruction
114
114
  var RetryAttemptsSchema = z5.number().int().min(0).max(2).describe(
115
115
  "The maximum number of times to retry when the function returns an error. You can specify a number from 0 to 2."
116
116
  );
117
- var RuntimeSchema = z5.enum(["nodejs18.x", "nodejs20.x"]).describe("The identifier of the function's runtime.");
117
+ var NodeRuntimeSchema = z5.enum(["nodejs18.x", "nodejs20.x"]).describe("The identifier of the function's runtime.");
118
+ var ContainerRuntimeSchema = z5.literal("container").describe("The identifier of the function's runtime.");
119
+ var RuntimeSchema = NodeRuntimeSchema.or(ContainerRuntimeSchema);
118
120
  var ActionSchema = z5.string();
119
121
  var ActionsSchema = z5.union([ActionSchema.transform((v) => [v]), ActionSchema.array()]);
120
122
  var ArnSchema = z5.string().startsWith("arn:").transform((v) => v);
@@ -157,7 +159,7 @@ var LayersSchema = ArnSchema.array().describe(
157
159
  `A list of function layers to add to the function's execution environment. Specify each layer by its ARN, including the version.`
158
160
  );
159
161
  var BuildSchema = z5.object({
160
- // minify: z.boolean().optional().describe('')
162
+ minify: MinifySchema.default(true),
161
163
  external: z5.string().array().optional().describe(`A list of external packages that won't be included in the bundle.`)
162
164
  }).describe(`Options for the function bundler`);
163
165
  var FunctionSchema = z5.union([
@@ -166,29 +168,36 @@ var FunctionSchema = z5.union([
166
168
  })),
167
169
  z5.object({
168
170
  file: FileSchema,
169
- description: DescriptionSchema.optional(),
171
+ // node
170
172
  handler: HandlerSchema.optional(),
171
- minify: MinifySchema.optional(),
173
+ build: BuildSchema.optional(),
174
+ // container
175
+ // ...
176
+ runtime: RuntimeSchema.optional(),
177
+ description: DescriptionSchema.optional(),
172
178
  warm: WarmSchema.optional(),
173
179
  vpc: VPCSchema.optional(),
174
180
  log: LogSchema.optional(),
175
181
  timeout: TimeoutSchema.optional(),
176
- runtime: RuntimeSchema.optional(),
177
182
  memorySize: MemorySizeSchema.optional(),
178
183
  architecture: ArchitectureSchema.optional(),
179
184
  ephemeralStorageSize: EphemeralStorageSizeSchema.optional(),
180
185
  retryAttempts: RetryAttemptsSchema.optional(),
181
186
  reserved: ReservedConcurrentExecutionsSchema.optional(),
182
187
  layers: LayersSchema.optional(),
183
- build: BuildSchema.optional(),
184
188
  environment: EnvironmentSchema.optional(),
185
189
  permissions: PermissionsSchema.optional()
186
190
  })
187
191
  ]);
188
192
  var FunctionsSchema = z5.record(ResourceIdSchema, FunctionSchema).optional().describe("Define the functions in your stack.");
189
193
  var FunctionDefaultSchema = z5.object({
194
+ runtime: RuntimeSchema.default("nodejs20.x"),
195
+ // node
190
196
  handler: HandlerSchema.default("index.default"),
191
- minify: MinifySchema.default(true),
197
+ build: BuildSchema.default({
198
+ minify: true
199
+ }),
200
+ // container
192
201
  warm: WarmSchema.default(0),
193
202
  vpc: VPCSchema.default(false),
194
203
  log: LogSchema.default({
@@ -198,14 +207,12 @@ var FunctionDefaultSchema = z5.object({
198
207
  format: "json"
199
208
  }),
200
209
  timeout: TimeoutSchema.default("10 seconds"),
201
- runtime: RuntimeSchema.default("nodejs20.x"),
202
210
  memorySize: MemorySizeSchema.default("128 MB"),
203
211
  architecture: ArchitectureSchema.default("arm64"),
204
212
  ephemeralStorageSize: EphemeralStorageSizeSchema.default("512 MB"),
205
213
  retryAttempts: RetryAttemptsSchema.default(2),
206
214
  reserved: ReservedConcurrentExecutionsSchema.optional(),
207
215
  layers: LayersSchema.optional(),
208
- build: BuildSchema.optional(),
209
216
  environment: EnvironmentSchema.optional(),
210
217
  permissions: PermissionsSchema.optional()
211
218
  }).default({});