Skip to content

Commit

Permalink
feat(docs): update docs (#978)
Browse files Browse the repository at this point in the history
feat(docs): update docs

Updates the Wing docs. See details in [workflow run].

[Workflow Run]: https://github.com/winglang/docsite/actions/runs/10262297812

------

*Automatically created via the "update-docs" workflow*
  • Loading branch information
monadabot authored Aug 6, 2024
1 parent 4225123 commit 38967e6
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,75 +4,6 @@ id: using-javascript
keywords: [example, javascript, extern, typescript, js, ts]
---

## Creating inflight function from JavaScript/TypeScript file

Inflight closures are an extremely important Wing functionality. Consider the following simple wing program:

```wing example
// main.w
bring cloud;
let bucket = new cloud.Bucket();
bucket.onCreate(inflight (file) => {
log(file);
});
```

Being able to write inflight wing alongside the preflight code is beautiful, but you may want to write the inflight function in a separate file and *language*. The `@inflight` intrinsic function can be used to create an inflight closure from a JavaScript/TypeScript:

```wing
// main.w
bring cloud;
let bucket = new cloud.Bucket();
bucket.onCreate(@inflight("./bucket_create.ts"));
// ^ onCreate expects an `inflight (str): void` function, so the file must export a function with a typescript signature that matches
// ^ Relative (to current file) path to javascript or typescript file
// Note: This must be a static string
```

`wing compile` will generate `.bucket_create.inflight.ts` which will contain all of the information needed for TypeScript type checking and IDE support.
With that, you can create the `bucket_create.ts` file:

```ts
// bucket_create.ts
import inflight from "./.bucket_create.inflight";

export default inflight(async ({}, file) => {
// ^ This is known to be a string, the first positional argument needed for `onCreate`
console.log(file);
});
```

Something missing here is the ability to reference preflight resources inside an inflight function.
Let's create a Queue and pass it to the inflight function while exploring other options:

```wing
// main.w
bring cloud;
let bucket = new cloud.Bucket();
let queue = new cloud.Queue();
bucket.onCreate(@inflight("./bucket_create.ts",
export: "default",
// ^ Optional named export from the file, "default" is the default export
lifts:[{ obj: queue, alias: "myQueue", ops: ["push"] }],
// ^ object to lift, can be any preflight expression
// ^ Optional alias, by default, this will be the variable name passed to obj
// ^ methods to lift, if not provided then all methods will be granted
));
```

```ts
// bucket_create.ts
import inflight from "./bucket_create.inflight";

export default inflight(async ({ myQueue }, file) => {
// ^ inflight interface to your preflight queue
await myQueue.push(file);
});
```

## Using `extern` to expose JavaScript/TypeScript functions in preflight and inflight

When you want to use a JavaScript/TypeScript file anywhere in Wing, you can use the `extern` keyword to expose functions from that file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,6 @@ id: resource

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

### ImportInflightOptions <a name="ImportInflightOptions" id="@winglang/sdk.std.ImportInflightOptions"></a>

Options for the `@inflight` intrinsic.

#### Initializer <a name="Initializer" id="@winglang/sdk.std.ImportInflightOptions.Initializer"></a>

```wing
let ImportInflightOptions = ImportInflightOptions{ ... };
```

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

| **Name** | **Type** | **Description** |
| --- | --- | --- |
| <code><a href="#@winglang/sdk.std.ImportInflightOptions.property.export">export</a></code> | <code>str</code> | Name of exported function. |
| <code><a href="#@winglang/sdk.std.ImportInflightOptions.property.lifts">lifts</a></code> | <code>MutArray&lt;<a href="#@winglang/sdk.std.LiftAnnotation">LiftAnnotation</a>&gt;</code> | Mapping of available symbols to a lift declaration. |

---

##### `export`<sup>Optional</sup> <a name="export" id="@winglang/sdk.std.ImportInflightOptions.property.export"></a>

```wing
export: str;
```

- *Type:* str
- *Default:* "default"

Name of exported function.

---

##### `lifts`<sup>Optional</sup> <a name="lifts" id="@winglang/sdk.std.ImportInflightOptions.property.lifts"></a>

```wing
lifts: MutArray<LiftAnnotation>;
```

- *Type:* MutArray&lt;<a href="#@winglang/sdk.std.LiftAnnotation">LiftAnnotation</a>&gt;
- *Default:* * All possible operations will be available

Mapping of available symbols to a lift declaration.

---

### LiftAnnotation <a name="LiftAnnotation" id="@winglang/sdk.std.LiftAnnotation"></a>

Annotations about preflight data and desired inflight operations.
Expand Down
4 changes: 2 additions & 2 deletions versioned_docs/version-latest/04-winglibs/04-toc.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ keywords: [winglib, Wing library]

| Library | Package name | Version | Description | Supported Wing platforms |
| -------- | ------- | ------- | ------- | ------- |
| [Amazon Bedrock](/docs/winglibs/winglibs/bedrock) | [@winglibs/bedrock](/docs/winglibs/winglibs/bedrock) | v0.0.9 | A Wing library for Amazon Bedrock | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [Amazon Bedrock](/docs/winglibs/winglibs/bedrock) | [@winglibs/bedrock](/docs/winglibs/winglibs/bedrock) | v0.1.0 | A Wing library for Amazon Bedrock | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [AWS Budget](/docs/winglibs/winglibs/budget) | [@winglibs/budget](/docs/winglibs/winglibs/budget) | v0.1.5 | A Wing library for working with [AWS Budgets] | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [Cloud checks](/docs/winglibs/winglibs/checks) | [@winglibs/checks](/docs/winglibs/winglibs/checks) | v0.0.16 | A self-validation mechanism for cloud applications | [*](/docs/platforms/platforms) |
| [cloudv2](/docs/winglibs/winglibs/cloudv2) | [@winglibs/cloudv2](/docs/winglibs/winglibs/cloudv2) | v0.0.2 | Standard cloud library for Wing | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [cloudv2](/docs/winglibs/winglibs/cloudv2) | [@winglibs/cloudv2](/docs/winglibs/winglibs/cloudv2) | v0.1.0 | Standard cloud library for Wing | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [Amazon Cognito](/docs/winglibs/winglibs/cognito) | [@winglibs/cognito](/docs/winglibs/winglibs/cognito) | v0.0.14 | A wing library to work with Amazon Cognito | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [Containers](/docs/winglibs/winglibs/containers) | [@winglibs/containers](/docs/winglibs/winglibs/containers) | v0.1.5 | Deploy containers with Wing | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
| [Amazon DynamoDB](/docs/winglibs/winglibs/dynamodb) | [@winglibs/dynamodb](/docs/winglibs/winglibs/dynamodb) | v0.2.1 | A Wing library for Amazon DynamoDB | [sim](/docs/platforms/sim), [tf-aws](/docs/platforms/AWS/tf-aws) |
Expand Down

0 comments on commit 38967e6

Please sign in to comment.