From 2cb7c131531cf79e228819c21f5304a30540c687 Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Tue, 10 Sep 2024 10:47:57 -0400 Subject: [PATCH] change maxAgeSeconds to maxAge --- docs/api/04-standard-library/cloud/bucket.md | 134 ++++++++++++++++++ packages/@winglang/sdk/src/cloud/bucket.ts | 2 +- .../@winglang/sdk/src/target-sim/bucket.ts | 2 +- .../@winglang/sdk/src/target-tf-aws/bucket.ts | 15 +- .../incomplete_inflight_namespace.snap | 2 +- .../completions/namespace_middle_dot.snap | 2 +- .../partial_type_reference_annotation.snap | 2 +- .../variable_type_annotation_namespace.snap | 2 +- tests/valid/external_ts.extern.d.ts | 26 +++- 9 files changed, 175 insertions(+), 12 deletions(-) diff --git a/docs/api/04-standard-library/cloud/bucket.md b/docs/api/04-standard-library/cloud/bucket.md index 8844346e31e..3821c76417a 100644 --- a/docs/api/04-standard-library/cloud/bucket.md +++ b/docs/api/04-standard-library/cloud/bucket.md @@ -150,6 +150,7 @@ new cloud.Bucket(props?: BucketProps); | **Name** | **Description** | | --- | --- | +| addCorsConfiguration | Add cors configuration to the bucket. | | addFile | Add a file to the bucket from system folder. | | addObject | Add a file to the bucket that is uploaded when the app is deployed. | | onCreate | Run an inflight whenever a file is uploaded to the bucket. | @@ -179,6 +180,22 @@ new cloud.Bucket(props?: BucketProps); --- +##### `addCorsConfiguration` + +```wing +addCorsConfiguration(value: BucketCorsOptions): void +``` + +Add cors configuration to the bucket. + +###### `value`Required + +- *Type:* BucketCorsOptions + +The cors configuration. + +--- + ##### `addFile` ```wing @@ -713,6 +730,123 @@ The tree node. ## Structs +### BucketCorsOptions + +Cors Options for `Bucket`. + +#### Initializer + +```wing +bring cloud; + +let BucketCorsOptions = cloud.BucketCorsOptions{ ... }; +``` + +#### Properties + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| allowedMethods | MutArray<HttpMethod> | The list of allowed methods. | +| allowedOrigins | MutArray<str> | The allowed origin. | +| allowedHeaders | MutArray<str> | The list of allowed headers. | +| exposeHeaders | MutArray<str> | The list of exposed headers. | +| maxAge | duration | How long the browser should cache preflight request results. | + +--- + +##### `allowedMethods`Required + +```wing +allowedMethods: MutArray; +``` + +- *Type:* MutArray<HttpMethod> +- *Default:* [HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.PATCH, HttpMethod.DELETE, HttpMethod.HEAD, HttpMethod.OPTIONS] + +The list of allowed methods. + +--- + +*Example* + +```wing +[HttpMethod.GET, HttpMethod.POST] +``` + + +##### `allowedOrigins`Required + +```wing +allowedOrigins: MutArray; +``` + +- *Type:* MutArray<str> +- *Default:* ["*"] + +The allowed origin. + +--- + +*Example* + +```wing +"https://example.com" +``` + + +##### `allowedHeaders`Optional + +```wing +allowedHeaders: MutArray; +``` + +- *Type:* MutArray<str> +- *Default:* ["Content-Type", "Authorization"] + +The list of allowed headers. + +--- + +*Example* + +```wing +["Content-Type"] +``` + + +##### `exposeHeaders`Optional + +```wing +exposeHeaders: MutArray; +``` + +- *Type:* MutArray<str> +- *Default:* [] + +The list of exposed headers. + +--- + +*Example* + +```wing +["Content-Type"] +``` + + +##### `maxAge`Optional + +```wing +maxAge: duration; +``` + +- *Type:* duration +- *Default:* 300 seconds + +How long the browser should cache preflight request results. + +--- + ### BucketDeleteOptions Options for `Bucket.delete()`. diff --git a/packages/@winglang/sdk/src/cloud/bucket.ts b/packages/@winglang/sdk/src/cloud/bucket.ts index 53c310b31e7..eff37e64e89 100644 --- a/packages/@winglang/sdk/src/cloud/bucket.ts +++ b/packages/@winglang/sdk/src/cloud/bucket.ts @@ -83,7 +83,7 @@ export interface BucketCorsOptions { * How long the browser should cache preflight request results. * @default - 300 seconds */ - readonly maxAgeSeconds?: Number; + readonly maxAge?: Duration; } /** diff --git a/packages/@winglang/sdk/src/target-sim/bucket.ts b/packages/@winglang/sdk/src/target-sim/bucket.ts index 795541fd987..86b2b8268c3 100644 --- a/packages/@winglang/sdk/src/target-sim/bucket.ts +++ b/packages/@winglang/sdk/src/target-sim/bucket.ts @@ -10,9 +10,9 @@ import { } from "./util"; import * as cloud from "../cloud"; import { LiftMap, lift } from "../core"; +import { NotImplementedError } from "../core/errors"; import { ToSimulatorOutput } from "../simulator/simulator"; import { IInflightHost } from "../std"; -import { NotImplementedError } from "../core/errors"; /** * Simulator implementation of `cloud.Bucket`. diff --git a/packages/@winglang/sdk/src/target-tf-aws/bucket.ts b/packages/@winglang/sdk/src/target-tf-aws/bucket.ts index f49b2d52e7b..6677a090153 100644 --- a/packages/@winglang/sdk/src/target-tf-aws/bucket.ts +++ b/packages/@winglang/sdk/src/target-tf-aws/bucket.ts @@ -3,10 +3,7 @@ import { Construct } from "constructs"; import { App } from "./app"; import { Topic as AWSTopic } from "./topic"; import { S3Bucket } from "../.gen/providers/aws/s3-bucket"; -import { - S3BucketCorsConfiguration, - S3BucketCorsConfigurationCorsRule, -} from "../.gen/providers/aws/s3-bucket-cors-configuration"; +import { S3BucketCorsConfiguration } from "../.gen/providers/aws/s3-bucket-cors-configuration"; import { S3BucketNotification, @@ -89,7 +86,15 @@ export class Bucket extends cloud.Bucket implements IAwsBucket { `CorsConfiguration-${this.node.addr.slice(-8)}`, { bucket: this.bucket.id, - corsRule: [value as S3BucketCorsConfigurationCorsRule], + corsRule: [ + { + allowedMethods: value.allowedMethods, + allowedOrigins: value.allowedOrigins, + allowedHeaders: value.allowedHeaders, + maxAgeSeconds: value.maxAge?.seconds, + exposeHeaders: value.exposeHeaders, + }, + ], } ); } diff --git a/packages/@winglang/wingc/src/lsp/snapshots/completions/incomplete_inflight_namespace.snap b/packages/@winglang/wingc/src/lsp/snapshots/completions/incomplete_inflight_namespace.snap index 783399e4d80..a3a773a0ff2 100644 --- a/packages/@winglang/wingc/src/lsp/snapshots/completions/incomplete_inflight_namespace.snap +++ b/packages/@winglang/wingc/src/lsp/snapshots/completions/incomplete_inflight_namespace.snap @@ -167,7 +167,7 @@ source: packages/@winglang/wingc/src/lsp/completions.rs kind: 22 documentation: kind: markdown - value: "```wing\nstruct BucketCorsOptions {\n allowedHeaders?: Array;\n exposeHeaders?: Array;\n maxAgeSeconds?: num;\n allowedMethods: Array;\n allowedOrigins: Array;\n}\n```\n---\nCors Options for `Bucket`." + value: "```wing\nstruct BucketCorsOptions {\n allowedHeaders?: Array;\n exposeHeaders?: Array;\n maxAge?: duration;\n allowedMethods: Array;\n allowedOrigins: Array;\n}\n```\n---\nCors Options for `Bucket`." sortText: hh|BucketCorsOptions - label: BucketDeleteOptions kind: 22 diff --git a/packages/@winglang/wingc/src/lsp/snapshots/completions/namespace_middle_dot.snap b/packages/@winglang/wingc/src/lsp/snapshots/completions/namespace_middle_dot.snap index 783399e4d80..a3a773a0ff2 100644 --- a/packages/@winglang/wingc/src/lsp/snapshots/completions/namespace_middle_dot.snap +++ b/packages/@winglang/wingc/src/lsp/snapshots/completions/namespace_middle_dot.snap @@ -167,7 +167,7 @@ source: packages/@winglang/wingc/src/lsp/completions.rs kind: 22 documentation: kind: markdown - value: "```wing\nstruct BucketCorsOptions {\n allowedHeaders?: Array;\n exposeHeaders?: Array;\n maxAgeSeconds?: num;\n allowedMethods: Array;\n allowedOrigins: Array;\n}\n```\n---\nCors Options for `Bucket`." + value: "```wing\nstruct BucketCorsOptions {\n allowedHeaders?: Array;\n exposeHeaders?: Array;\n maxAge?: duration;\n allowedMethods: Array;\n allowedOrigins: Array;\n}\n```\n---\nCors Options for `Bucket`." sortText: hh|BucketCorsOptions - label: BucketDeleteOptions kind: 22 diff --git a/packages/@winglang/wingc/src/lsp/snapshots/completions/partial_type_reference_annotation.snap b/packages/@winglang/wingc/src/lsp/snapshots/completions/partial_type_reference_annotation.snap index 783399e4d80..a3a773a0ff2 100644 --- a/packages/@winglang/wingc/src/lsp/snapshots/completions/partial_type_reference_annotation.snap +++ b/packages/@winglang/wingc/src/lsp/snapshots/completions/partial_type_reference_annotation.snap @@ -167,7 +167,7 @@ source: packages/@winglang/wingc/src/lsp/completions.rs kind: 22 documentation: kind: markdown - value: "```wing\nstruct BucketCorsOptions {\n allowedHeaders?: Array;\n exposeHeaders?: Array;\n maxAgeSeconds?: num;\n allowedMethods: Array;\n allowedOrigins: Array;\n}\n```\n---\nCors Options for `Bucket`." + value: "```wing\nstruct BucketCorsOptions {\n allowedHeaders?: Array;\n exposeHeaders?: Array;\n maxAge?: duration;\n allowedMethods: Array;\n allowedOrigins: Array;\n}\n```\n---\nCors Options for `Bucket`." sortText: hh|BucketCorsOptions - label: BucketDeleteOptions kind: 22 diff --git a/packages/@winglang/wingc/src/lsp/snapshots/completions/variable_type_annotation_namespace.snap b/packages/@winglang/wingc/src/lsp/snapshots/completions/variable_type_annotation_namespace.snap index 783399e4d80..a3a773a0ff2 100644 --- a/packages/@winglang/wingc/src/lsp/snapshots/completions/variable_type_annotation_namespace.snap +++ b/packages/@winglang/wingc/src/lsp/snapshots/completions/variable_type_annotation_namespace.snap @@ -167,7 +167,7 @@ source: packages/@winglang/wingc/src/lsp/completions.rs kind: 22 documentation: kind: markdown - value: "```wing\nstruct BucketCorsOptions {\n allowedHeaders?: Array;\n exposeHeaders?: Array;\n maxAgeSeconds?: num;\n allowedMethods: Array;\n allowedOrigins: Array;\n}\n```\n---\nCors Options for `Bucket`." + value: "```wing\nstruct BucketCorsOptions {\n allowedHeaders?: Array;\n exposeHeaders?: Array;\n maxAge?: duration;\n allowedMethods: Array;\n allowedOrigins: Array;\n}\n```\n---\nCors Options for `Bucket`." sortText: hh|BucketCorsOptions - label: BucketDeleteOptions kind: 22 diff --git a/tests/valid/external_ts.extern.d.ts b/tests/valid/external_ts.extern.d.ts index 4ea9105e1ba..fde33de3721 100644 --- a/tests/valid/external_ts.extern.d.ts +++ b/tests/valid/external_ts.extern.d.ts @@ -79,6 +79,30 @@ export enum HttpMethod { CONNECT = 7, TRACE = 8, } +/** Represents a length of time. */ +export class Duration implements ILiftable { + /** Return the total number of days in this Duration. + @returns the value of this `Duration` expressed in Days. */ + readonly days: number; + /** Return the total number of hours in this Duration. + @returns the value of this `Duration` expressed in Hours. */ + readonly hours: number; + /** Return the total number of milliseconds in this Duration. + @returns the value of this `Duration` expressed in Milliseconds. */ + readonly milliseconds: number; + /** Return the total number of minutes in this Duration. + @returns the value of this `Duration` expressed in Minutes. */ + readonly minutes: number; + /** Return the total number of months in this Duration. + @returns the value of this `Duration` expressed in Months. */ + readonly months: number; + /** Return the total number of seconds in this Duration. + @returns the value of this `Duration` expressed in Seconds. */ + readonly seconds: number; + /** Return the total number of years in this Duration. + @returns the value of this `Duration` expressed in Years. */ + readonly years: number; +} /** Cors Options for `Bucket`. */ export interface BucketCorsOptions { /** The list of allowed headers. @@ -94,7 +118,7 @@ export interface BucketCorsOptions { ["Content-Type"] */ readonly exposeHeaders?: ((readonly (string)[])) | undefined; /** How long the browser should cache preflight request results. */ - readonly maxAgeSeconds?: (number) | undefined; + readonly maxAge?: (Duration) | undefined; } /** Code that runs at runtime and implements your application's behavior. For example, handling API requests, processing queue messages, etc.