Skip to content

Commit

Permalink
change maxAgeSeconds to maxAge
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriscbr committed Sep 10, 2024
1 parent f260599 commit 2cb7c13
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 12 deletions.
134 changes: 134 additions & 0 deletions docs/api/04-standard-library/cloud/bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ new cloud.Bucket(props?: BucketProps);

| **Name** | **Description** |
| --- | --- |
| <code><a href="#@winglang/sdk.cloud.Bucket.addCorsConfiguration">addCorsConfiguration</a></code> | Add cors configuration to the bucket. |
| <code><a href="#@winglang/sdk.cloud.Bucket.addFile">addFile</a></code> | Add a file to the bucket from system folder. |
| <code><a href="#@winglang/sdk.cloud.Bucket.addObject">addObject</a></code> | Add a file to the bucket that is uploaded when the app is deployed. |
| <code><a href="#@winglang/sdk.cloud.Bucket.onCreate">onCreate</a></code> | Run an inflight whenever a file is uploaded to the bucket. |
Expand Down Expand Up @@ -179,6 +180,22 @@ new cloud.Bucket(props?: BucketProps);

---

##### `addCorsConfiguration` <a name="addCorsConfiguration" id="@winglang/sdk.cloud.Bucket.addCorsConfiguration"></a>

```wing
addCorsConfiguration(value: BucketCorsOptions): void
```

Add cors configuration to the bucket.

###### `value`<sup>Required</sup> <a name="value" id="@winglang/sdk.cloud.Bucket.addCorsConfiguration.parameter.value"></a>

- *Type:* <a href="#@winglang/sdk.cloud.BucketCorsOptions">BucketCorsOptions</a>

The cors configuration.

---

##### `addFile` <a name="addFile" id="@winglang/sdk.cloud.Bucket.addFile"></a>

```wing
Expand Down Expand Up @@ -713,6 +730,123 @@ The tree node.

## Structs <a name="Structs" id="Structs"></a>

### BucketCorsOptions <a name="BucketCorsOptions" id="@winglang/sdk.cloud.BucketCorsOptions"></a>

Cors Options for `Bucket`.

#### Initializer <a name="Initializer" id="@winglang/sdk.cloud.BucketCorsOptions.Initializer"></a>

```wing
bring cloud;
let BucketCorsOptions = cloud.BucketCorsOptions{ ... };
```

#### Properties <a name="Properties" id="Properties"></a>

| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.cloud.BucketCorsOptions.property.allowedMethods">allowedMethods</a></code> | <code>MutArray&lt;<a href="#@winglang/sdk.http.HttpMethod">HttpMethod</a>&gt;</code> | The list of allowed methods. |
| <code><a href="#@winglang/sdk.cloud.BucketCorsOptions.property.allowedOrigins">allowedOrigins</a></code> | <code>MutArray&lt;str&gt;</code> | The allowed origin. |
| <code><a href="#@winglang/sdk.cloud.BucketCorsOptions.property.allowedHeaders">allowedHeaders</a></code> | <code>MutArray&lt;str&gt;</code> | The list of allowed headers. |
| <code><a href="#@winglang/sdk.cloud.BucketCorsOptions.property.exposeHeaders">exposeHeaders</a></code> | <code>MutArray&lt;str&gt;</code> | The list of exposed headers. |
| <code><a href="#@winglang/sdk.cloud.BucketCorsOptions.property.maxAge">maxAge</a></code> | <code><a href="#@winglang/sdk.std.Duration">duration</a></code> | How long the browser should cache preflight request results. |

---

##### `allowedMethods`<sup>Required</sup> <a name="allowedMethods" id="@winglang/sdk.cloud.BucketCorsOptions.property.allowedMethods"></a>

```wing
allowedMethods: MutArray<HttpMethod>;
```

- *Type:* MutArray&lt;<a href="#@winglang/sdk.http.HttpMethod">HttpMethod</a>&gt;
- *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`<sup>Required</sup> <a name="allowedOrigins" id="@winglang/sdk.cloud.BucketCorsOptions.property.allowedOrigins"></a>

```wing
allowedOrigins: MutArray<str>;
```

- *Type:* MutArray&lt;str&gt;
- *Default:* ["*"]

The allowed origin.

---

*Example*

```wing
"https://example.com"
```


##### `allowedHeaders`<sup>Optional</sup> <a name="allowedHeaders" id="@winglang/sdk.cloud.BucketCorsOptions.property.allowedHeaders"></a>

```wing
allowedHeaders: MutArray<str>;
```

- *Type:* MutArray&lt;str&gt;
- *Default:* ["Content-Type", "Authorization"]

The list of allowed headers.

---

*Example*

```wing
["Content-Type"]
```


##### `exposeHeaders`<sup>Optional</sup> <a name="exposeHeaders" id="@winglang/sdk.cloud.BucketCorsOptions.property.exposeHeaders"></a>

```wing
exposeHeaders: MutArray<str>;
```

- *Type:* MutArray&lt;str&gt;
- *Default:* []

The list of exposed headers.

---

*Example*

```wing
["Content-Type"]
```


##### `maxAge`<sup>Optional</sup> <a name="maxAge" id="@winglang/sdk.cloud.BucketCorsOptions.property.maxAge"></a>

```wing
maxAge: duration;
```

- *Type:* <a href="#@winglang/sdk.std.Duration">duration</a>
- *Default:* 300 seconds

How long the browser should cache preflight request results.

---

### BucketDeleteOptions <a name="BucketDeleteOptions" id="@winglang/sdk.cloud.BucketDeleteOptions"></a>

Options for `Bucket.delete()`.
Expand Down
2 changes: 1 addition & 1 deletion packages/@winglang/sdk/src/cloud/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/@winglang/sdk/src/target-sim/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
15 changes: 10 additions & 5 deletions packages/@winglang/sdk/src/target-tf-aws/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
],
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ source: packages/@winglang/wingc/src/lsp/completions.rs
kind: 22
documentation:
kind: markdown
value: "```wing\nstruct BucketCorsOptions {\n allowedHeaders?: Array<str>;\n exposeHeaders?: Array<str>;\n maxAgeSeconds?: num;\n allowedMethods: Array<HttpMethod>;\n allowedOrigins: Array<str>;\n}\n```\n---\nCors Options for `Bucket`."
value: "```wing\nstruct BucketCorsOptions {\n allowedHeaders?: Array<str>;\n exposeHeaders?: Array<str>;\n maxAge?: duration;\n allowedMethods: Array<HttpMethod>;\n allowedOrigins: Array<str>;\n}\n```\n---\nCors Options for `Bucket`."
sortText: hh|BucketCorsOptions
- label: BucketDeleteOptions
kind: 22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ source: packages/@winglang/wingc/src/lsp/completions.rs
kind: 22
documentation:
kind: markdown
value: "```wing\nstruct BucketCorsOptions {\n allowedHeaders?: Array<str>;\n exposeHeaders?: Array<str>;\n maxAgeSeconds?: num;\n allowedMethods: Array<HttpMethod>;\n allowedOrigins: Array<str>;\n}\n```\n---\nCors Options for `Bucket`."
value: "```wing\nstruct BucketCorsOptions {\n allowedHeaders?: Array<str>;\n exposeHeaders?: Array<str>;\n maxAge?: duration;\n allowedMethods: Array<HttpMethod>;\n allowedOrigins: Array<str>;\n}\n```\n---\nCors Options for `Bucket`."
sortText: hh|BucketCorsOptions
- label: BucketDeleteOptions
kind: 22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ source: packages/@winglang/wingc/src/lsp/completions.rs
kind: 22
documentation:
kind: markdown
value: "```wing\nstruct BucketCorsOptions {\n allowedHeaders?: Array<str>;\n exposeHeaders?: Array<str>;\n maxAgeSeconds?: num;\n allowedMethods: Array<HttpMethod>;\n allowedOrigins: Array<str>;\n}\n```\n---\nCors Options for `Bucket`."
value: "```wing\nstruct BucketCorsOptions {\n allowedHeaders?: Array<str>;\n exposeHeaders?: Array<str>;\n maxAge?: duration;\n allowedMethods: Array<HttpMethod>;\n allowedOrigins: Array<str>;\n}\n```\n---\nCors Options for `Bucket`."
sortText: hh|BucketCorsOptions
- label: BucketDeleteOptions
kind: 22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ source: packages/@winglang/wingc/src/lsp/completions.rs
kind: 22
documentation:
kind: markdown
value: "```wing\nstruct BucketCorsOptions {\n allowedHeaders?: Array<str>;\n exposeHeaders?: Array<str>;\n maxAgeSeconds?: num;\n allowedMethods: Array<HttpMethod>;\n allowedOrigins: Array<str>;\n}\n```\n---\nCors Options for `Bucket`."
value: "```wing\nstruct BucketCorsOptions {\n allowedHeaders?: Array<str>;\n exposeHeaders?: Array<str>;\n maxAge?: duration;\n allowedMethods: Array<HttpMethod>;\n allowedOrigins: Array<str>;\n}\n```\n---\nCors Options for `Bucket`."
sortText: hh|BucketCorsOptions
- label: BucketDeleteOptions
kind: 22
Expand Down
26 changes: 25 additions & 1 deletion tests/valid/external_ts.extern.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 2cb7c13

Please sign in to comment.