@awsless/awsless 0.0.226 → 0.0.227

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
@@ -671,36 +671,51 @@ var TablesSchema = z17.record(
671
671
 
672
672
  // src/feature/store/schema.ts
673
673
  import { z as z18 } from "zod";
674
- import { seconds as seconds3 } from "@awsless/duration";
675
- var CorsSchema = z18.array(
676
- z18.object({
677
- maxAge: DurationSchema.refine(durationMin(seconds3(0))).optional().describe(
678
- "The time in seconds that your browser is to cache the preflight response for the specified resource."
679
- ),
680
- origins: z18.array(z18.string()).describe("One or more origins you want customers to be able to access the bucket from."),
681
- methods: z18.array(z18.enum(["GET", "PUT", "HEAD", "POST", "DELETE"])).describe("An HTTP method that you allow the origin to run."),
682
- headers: z18.array(z18.string()).optional().describe(
683
- "Headers that are specified in the Access-Control-Request-Headers header. These headers are allowed in a preflight OPTIONS request. In response to any preflight OPTIONS request, Amazon S3 returns any requested headers that are allowed."
684
- ),
685
- exposeHeaders: z18.array(z18.string()).optional().describe(
686
- "One or more headers in the response that you want customers to be able to access from their applications (for example, from a JavaScript XMLHttpRequest object)."
687
- )
688
- })
689
- ).max(100).optional().describe("Describes the AWS Lambda functions to invoke and the events for which to invoke them.");
690
- var LambdaConfigsSchema = z18.array(
691
- z18.object({
692
- event: z18.enum(["created", "removed"]).describe("The Amazon S3 bucket event for which to invoke the AWS Lambda function."),
693
- consumer: FunctionSchema.describe("The consuming lambda function properties.")
694
- })
695
- ).optional().describe("Describes the AWS Lambda functions to invoke and the events for which to invoke them.");
696
- var StoresSchema = z18.record(
697
- ResourceIdSchema,
698
- z18.object({
699
- lambdaConfigs: LambdaConfigsSchema,
700
- cors: CorsSchema,
701
- versioning: z18.boolean().default(false)
702
- })
703
- ).optional().describe("Define the stores in your stack.");
674
+ var StoresSchema = z18.union([
675
+ z18.array(ResourceIdSchema).transform((list4) => {
676
+ const stores = {};
677
+ for (const key in list4) {
678
+ stores[key] = {};
679
+ }
680
+ return stores;
681
+ }),
682
+ z18.record(
683
+ ResourceIdSchema,
684
+ z18.object({
685
+ // lambdaConfigs: LambdaConfigsSchema,
686
+ // cors: CorsSchema,
687
+ versioning: z18.boolean().default(false).describe("Enable versioning of your store."),
688
+ events: z18.object({
689
+ // create
690
+ "created:*": FunctionSchema.describe(
691
+ "Subscribe to notifications regardless of the API that was used to create an object."
692
+ ),
693
+ "created:put": FunctionSchema.describe(
694
+ "Subscribe to notifications when an object is created using the PUT API operation."
695
+ ),
696
+ "created:post": FunctionSchema.describe(
697
+ "Subscribe to notifications when an object is created using the POST API operation."
698
+ ),
699
+ "created:copy": FunctionSchema.describe(
700
+ "Subscribe to notifications when an object is created using the COPY API operation."
701
+ ),
702
+ "created:upload": FunctionSchema.describe(
703
+ "Subscribe to notifications when an object multipart upload has been completed."
704
+ ),
705
+ // remove
706
+ "removed:*": FunctionSchema.describe(
707
+ "Subscribe to notifications when an object is deleted or a delete marker for a versioned object is created."
708
+ ),
709
+ "removed:delete": FunctionSchema.describe(
710
+ "Subscribe to notifications when an object is deleted"
711
+ ),
712
+ "removed:marker": FunctionSchema.describe(
713
+ "Subscribe to notifications when a delete marker for a versioned object is created."
714
+ )
715
+ }).optional().describe("Describes the store events you want to subscribe too.")
716
+ })
717
+ )
718
+ ]).optional().describe("Define the stores in your stack.");
704
719
 
705
720
  // src/feature/pubsub/schema.ts
706
721
  import { z as z19 } from "zod";
@@ -3195,35 +3210,39 @@ var storeFeature = defineFeature({
3195
3210
  for (const [id, props] of Object.entries(ctx.stackConfig.stores ?? {})) {
3196
3211
  const group = new Node10(ctx.stack, "store", id);
3197
3212
  const lambdaConfigs = [];
3198
- for (const [_, lambdaConfig] of Object.entries(props.lambdaConfigs ?? {})) {
3199
- const { lambda } = createLambdaFunction(group, ctx, `store`, id, lambdaConfig.consumer);
3213
+ const eventMap = {
3214
+ "created:*": "s3:ObjectCreated:*",
3215
+ "created:put": "s3:ObjectCreated:Put",
3216
+ "created:post": "s3:ObjectCreated:Post",
3217
+ "created:copy": "s3:ObjectCreated:Copy",
3218
+ "created:upload": "s3:ObjectCreated:CompleteMultipartUpload",
3219
+ "removed:*": "s3:ObjectRemoved:*",
3220
+ "removed:delete": "s3:ObjectRemoved:Delete",
3221
+ "removed:marker": "s3:ObjectRemoved:DeleteMarkerCreated"
3222
+ };
3223
+ for (const [event, funcProps] of Object.entries(props.events ?? {})) {
3224
+ const { lambda } = createLambdaFunction(group, ctx, `store`, id, funcProps);
3200
3225
  lambda.addEnvironment("LOG_VIEWABLE_ERROR", "1");
3201
- let event;
3202
- if (lambdaConfig.event === "created") {
3203
- event = "s3:ObjectCreated:*";
3204
- } else if (lambdaConfig.event === "removed") {
3205
- event = "s3:ObjectRemoved:*";
3206
- }
3207
3226
  lambdaConfigs.push({
3208
- event,
3227
+ event: eventMap[event],
3209
3228
  function: lambda.arn
3210
3229
  });
3211
3230
  }
3212
3231
  const bucket = new aws10.s3.Bucket(group, "store", {
3213
3232
  name: formatLocalResourceName(ctx.appConfig.name, ctx.stack.name, "store", id),
3214
3233
  versioning: props.versioning,
3215
- cors: props.cors,
3216
- lambdaConfigs
3217
- // cors: [
3218
- // // ---------------------------------------------
3219
- // // Support for presigned post requests
3220
- // // ---------------------------------------------
3221
- // {
3222
- // origins: ['*'],
3223
- // methods: ['POST'],
3224
- // },
3225
- // // ---------------------------------------------
3226
- // ],
3234
+ lambdaConfigs,
3235
+ // cors: props.cors,
3236
+ cors: [
3237
+ // ---------------------------------------------
3238
+ // Support for presigned post requests
3239
+ // ---------------------------------------------
3240
+ {
3241
+ origins: ["*"],
3242
+ methods: ["POST"]
3243
+ }
3244
+ // ---------------------------------------------
3245
+ ]
3227
3246
  });
3228
3247
  ctx.onFunction(({ policy }) => {
3229
3248
  policy.addStatement(bucket.permissions);
@@ -3787,7 +3806,7 @@ var searchFeature = defineFeature({
3787
3806
 
3788
3807
  // src/feature/site/index.ts
3789
3808
  import { Asset as Asset3, Node as Node17, aws as aws17 } from "@awsless/formation";
3790
- import { days as days3, seconds as seconds4 } from "@awsless/duration";
3809
+ import { days as days3, seconds as seconds3 } from "@awsless/duration";
3791
3810
  import { glob as glob2 } from "glob";
3792
3811
  import { join as join8 } from "path";
3793
3812
 
@@ -3900,7 +3919,7 @@ var siteFeature = defineFeature({
3900
3919
  }
3901
3920
  const cache = new aws17.cloudFront.CachePolicy(group, "cache", {
3902
3921
  name,
3903
- minTtl: seconds4(1),
3922
+ minTtl: seconds3(1),
3904
3923
  maxTtl: days3(365),
3905
3924
  defaultTtl: days3(1),
3906
3925
  ...props.cache
@@ -4575,7 +4594,7 @@ var del2 = (program2) => {
4575
4594
  import { confirm as confirm4 } from "@clack/prompts";
4576
4595
 
4577
4596
  // src/cli/ui/complex/run-tests.ts
4578
- import { join as join10 } from "path";
4597
+ import { join as join11 } from "path";
4579
4598
  import { mkdir as mkdir3, readFile as readFile7, writeFile as writeFile3 } from "fs/promises";
4580
4599
 
4581
4600
  // src/test/reporter.ts
@@ -4633,14 +4652,8 @@ var CustomReporter = class {
4633
4652
  this.cache = cache;
4634
4653
  }
4635
4654
  }
4636
- onUserConsoleLog(log10) {
4637
- if (log10.taskId) {
4638
- const test2 = this.ctx?.state.idMap.get(log10.taskId);
4639
- if (test2) {
4640
- test2.name;
4641
- }
4642
- }
4643
- this.logs.push(log10.content.trimEnd());
4655
+ onUserConsoleLog(log9) {
4656
+ this.logs.push(log9.content.trimEnd());
4644
4657
  }
4645
4658
  runningTask(tasks) {
4646
4659
  return tasks.find((t) => t.result?.state === "run");
@@ -4664,7 +4677,10 @@ import { startVitest } from "vitest/node";
4664
4677
  import commonjs3 from "@rollup/plugin-commonjs";
4665
4678
  import nodeResolve3 from "@rollup/plugin-node-resolve";
4666
4679
  import json3 from "@rollup/plugin-json";
4680
+ import { dirname as dirname9, join as join10 } from "path";
4681
+ import { fileURLToPath } from "url";
4667
4682
  var startTest = async (props) => {
4683
+ const __dirname = dirname9(fileURLToPath(import.meta.url));
4668
4684
  const result = await startVitest(
4669
4685
  "test",
4670
4686
  props.filters,
@@ -4677,7 +4693,11 @@ var startTest = async (props) => {
4677
4693
  include: ["**/*.{js,jsx,ts,tsx}"],
4678
4694
  exclude: ["**/_*", "**/_*/**", ...configDefaults.exclude],
4679
4695
  globals: true,
4680
- reporters: props.reporter
4696
+ reporters: props.reporter,
4697
+ globalSetup: join10(__dirname, "test-global-setup.js")
4698
+ // env: {
4699
+ // TZ: 'UTC',
4700
+ // },
4681
4701
  // typecheck: {
4682
4702
  // enabled: true,
4683
4703
  // // ignoreSourceErrors: false,
@@ -4732,7 +4752,7 @@ var logTestLogs = (event) => {
4732
4752
  log8.message(color.info.bold.inverse(" LOGS "), {
4733
4753
  symbol: color.dim(icon.dot)
4734
4754
  });
4735
- log8.message(event.logs.map((log10) => wrap(log10, { hard: true })).join("\n"));
4755
+ log8.message(event.logs.map((log9) => wrap(log9, { hard: true })).join("\n"));
4736
4756
  }
4737
4757
  };
4738
4758
  var logTestErrors = (event) => {
@@ -4770,7 +4790,7 @@ var logTestErrors = (event) => {
4770
4790
  var runTest = async (stack, dir, filters) => {
4771
4791
  await mkdir3(directories.test, { recursive: true });
4772
4792
  const fingerprint = await fingerprintFromDirectory(dir);
4773
- const file = join10(directories.test, `${stack}.json`);
4793
+ const file = join11(directories.test, `${stack}.json`);
4774
4794
  const exists = await fileExist(file);
4775
4795
  if (exists && !process.env.NO_CACHE) {
4776
4796
  const raw = await readFile7(file, { encoding: "utf8" });
@@ -4945,12 +4965,9 @@ var diff = (program2) => {
4945
4965
  });
4946
4966
  };
4947
4967
 
4948
- // src/cli/ui/complex/build-types.ts
4949
- import { log as log9 } from "@clack/prompts";
4950
-
4951
4968
  // src/type-gen/generate.ts
4952
4969
  import { mkdir as mkdir4, writeFile as writeFile4 } from "fs/promises";
4953
- import { dirname as dirname9, join as join11, relative as relative5 } from "path";
4970
+ import { dirname as dirname10, join as join12, relative as relative5 } from "path";
4954
4971
  var generateTypes = async (props) => {
4955
4972
  const files = [];
4956
4973
  await Promise.all(
@@ -4959,12 +4976,12 @@ var generateTypes = async (props) => {
4959
4976
  ...props,
4960
4977
  async write(file, data, include = false) {
4961
4978
  const code = data?.toString("utf8");
4962
- const path = join11(directories.types, file);
4979
+ const path = join12(directories.types, file);
4963
4980
  if (code) {
4964
4981
  if (include) {
4965
4982
  files.push(relative5(directories.root, path));
4966
4983
  }
4967
- await mkdir4(dirname9(path), { recursive: true });
4984
+ await mkdir4(dirname10(path), { recursive: true });
4968
4985
  await writeFile4(path, code);
4969
4986
  }
4970
4987
  }
@@ -4973,14 +4990,16 @@ var generateTypes = async (props) => {
4973
4990
  );
4974
4991
  if (files.length) {
4975
4992
  const code = files.map((file) => `/// <reference path='${file}' />`).join("\n");
4976
- await writeFile4(join11(directories.root, `awsless.d.ts`), code);
4993
+ await writeFile4(join12(directories.root, `awsless.d.ts`), code);
4977
4994
  }
4978
4995
  };
4979
4996
 
4980
4997
  // src/cli/ui/complex/build-types.ts
4981
4998
  var buildTypes = async (props) => {
4982
- await generateTypes(props);
4983
- log9.step("Done generating type definition files.");
4999
+ await task("Generate type definition files", async (update) => {
5000
+ await generateTypes(props);
5001
+ update("Done generating type definition files.");
5002
+ });
4984
5003
  };
4985
5004
 
4986
5005
  // src/cli/command/types.ts
@@ -309,40 +309,55 @@ var TablesSchema = z8.record(
309
309
 
310
310
  // src/feature/store/schema.ts
311
311
  import { z as z9 } from "zod";
312
- import { seconds as seconds2 } from "@awsless/duration";
313
- var CorsSchema = z9.array(
314
- z9.object({
315
- maxAge: DurationSchema.refine(durationMin(seconds2(0))).optional().describe(
316
- "The time in seconds that your browser is to cache the preflight response for the specified resource."
317
- ),
318
- origins: z9.array(z9.string()).describe("One or more origins you want customers to be able to access the bucket from."),
319
- methods: z9.array(z9.enum(["GET", "PUT", "HEAD", "POST", "DELETE"])).describe("An HTTP method that you allow the origin to run."),
320
- headers: z9.array(z9.string()).optional().describe(
321
- "Headers that are specified in the Access-Control-Request-Headers header. These headers are allowed in a preflight OPTIONS request. In response to any preflight OPTIONS request, Amazon S3 returns any requested headers that are allowed."
322
- ),
323
- exposeHeaders: z9.array(z9.string()).optional().describe(
324
- "One or more headers in the response that you want customers to be able to access from their applications (for example, from a JavaScript XMLHttpRequest object)."
325
- )
326
- })
327
- ).max(100).optional().describe("Describes the AWS Lambda functions to invoke and the events for which to invoke them.");
328
- var LambdaConfigsSchema = z9.array(
329
- z9.object({
330
- event: z9.enum(["created", "removed"]).describe("The Amazon S3 bucket event for which to invoke the AWS Lambda function."),
331
- consumer: FunctionSchema.describe("The consuming lambda function properties.")
332
- })
333
- ).optional().describe("Describes the AWS Lambda functions to invoke and the events for which to invoke them.");
334
- var StoresSchema = z9.record(
335
- ResourceIdSchema,
336
- z9.object({
337
- lambdaConfigs: LambdaConfigsSchema,
338
- cors: CorsSchema,
339
- versioning: z9.boolean().default(false)
340
- })
341
- ).optional().describe("Define the stores in your stack.");
312
+ var StoresSchema = z9.union([
313
+ z9.array(ResourceIdSchema).transform((list) => {
314
+ const stores = {};
315
+ for (const key in list) {
316
+ stores[key] = {};
317
+ }
318
+ return stores;
319
+ }),
320
+ z9.record(
321
+ ResourceIdSchema,
322
+ z9.object({
323
+ // lambdaConfigs: LambdaConfigsSchema,
324
+ // cors: CorsSchema,
325
+ versioning: z9.boolean().default(false).describe("Enable versioning of your store."),
326
+ events: z9.object({
327
+ // create
328
+ "created:*": FunctionSchema.describe(
329
+ "Subscribe to notifications regardless of the API that was used to create an object."
330
+ ),
331
+ "created:put": FunctionSchema.describe(
332
+ "Subscribe to notifications when an object is created using the PUT API operation."
333
+ ),
334
+ "created:post": FunctionSchema.describe(
335
+ "Subscribe to notifications when an object is created using the POST API operation."
336
+ ),
337
+ "created:copy": FunctionSchema.describe(
338
+ "Subscribe to notifications when an object is created using the COPY API operation."
339
+ ),
340
+ "created:upload": FunctionSchema.describe(
341
+ "Subscribe to notifications when an object multipart upload has been completed."
342
+ ),
343
+ // remove
344
+ "removed:*": FunctionSchema.describe(
345
+ "Subscribe to notifications when an object is deleted or a delete marker for a versioned object is created."
346
+ ),
347
+ "removed:delete": FunctionSchema.describe(
348
+ "Subscribe to notifications when an object is deleted"
349
+ ),
350
+ "removed:marker": FunctionSchema.describe(
351
+ "Subscribe to notifications when a delete marker for a versioned object is created."
352
+ )
353
+ }).optional().describe("Describes the store events you want to subscribe too.")
354
+ })
355
+ )
356
+ ]).optional().describe("Define the stores in your stack.");
342
357
 
343
358
  // src/feature/queue/schema.ts
344
359
  import { z as z10 } from "zod";
345
- import { days as days2, hours, minutes as minutes2, seconds as seconds3 } from "@awsless/duration";
360
+ import { days as days2, hours, minutes as minutes2, seconds as seconds2 } from "@awsless/duration";
346
361
  import { kibibytes } from "@awsless/size";
347
362
  var RetentionPeriodSchema = DurationSchema.refine(
348
363
  durationMin(minutes2(1)),
@@ -363,9 +378,9 @@ var DeliveryDelaySchema = DurationSchema.refine(
363
378
  "The time in seconds for which the delivery of all messages in the queue is delayed. You can specify a duration from 0 to 15 minutes."
364
379
  );
365
380
  var ReceiveMessageWaitTimeSchema = DurationSchema.refine(
366
- durationMin(seconds3(1)),
381
+ durationMin(seconds2(1)),
367
382
  "Minimum receive message wait time is 1 second"
368
- ).refine(durationMax(seconds3(20)), "Maximum receive message wait time is 20 seconds").describe(
383
+ ).refine(durationMax(seconds2(20)), "Maximum receive message wait time is 20 seconds").describe(
369
384
  "Specifies the duration, that the ReceiveMessage action call waits until a message is in the queue in order to include it in the response, rather than returning an empty response if a message isn't yet available. You can specify a duration from 1 to 20 seconds. Short polling is used as the default."
370
385
  );
371
386
  var MaxMessageSizeSchema = SizeSchema.refine(sizeMin(kibibytes(1)), "Minimum max message size is 1 KB").refine(sizeMax(kibibytes(256)), "Maximum max message size is 256 KB").describe(