-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates the Wing docs. See details in [workflow run]. [Workflow Run]: https://github.com/winglang/docsite/actions/runs/11111023832 ------ *Automatically created via the "update-docs" workflow* Signed-off-by: monabot <[email protected]>
- Loading branch information
Showing
9 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
title: Type reflection | ||
id: type-reflection | ||
slug: /type-reflection | ||
sidebar_label: Type reflection | ||
description: Type reflection | ||
keywords: [Wing language, Type reflection] | ||
image: /img/wing-by-example.png | ||
--- | ||
|
||
The `@type` intrinsic function returns a reflection of the type passed to it. | ||
|
||
You can access its `.kind` property to get the kind of the type, and use various helper methods like `.asStruct()`, `.asClass()`, `.asInterface()`, etc. to access related properties. | ||
|
||
```js playground example title="main.w" | ||
let generateJsonSchema = (structType: std.reflect.Type): str => { | ||
if let st = structType.asStruct() { | ||
let schema = MutJson { | ||
type: "object", | ||
properties: {}, | ||
required: [] | ||
}; | ||
|
||
for name in st.fields.keys() { | ||
let fieldSchema = MutJson {}; | ||
let var field = st.fields[name].child; | ||
let var required = true; | ||
if let opt = field.asOptional() { | ||
required = false; | ||
field = opt.child; | ||
} | ||
|
||
if field.kind == "str" { | ||
fieldSchema["type"] = "string"; | ||
} else if field.kind == "num" { | ||
fieldSchema["type"] = "number"; | ||
} // ...handle other types | ||
|
||
schema["properties"][name] = fieldSchema; | ||
if required { | ||
// TODO: https://github.com/winglang/wing/issues/6929 | ||
unsafeCast(schema["required"])?.push(name); | ||
} | ||
} | ||
|
||
return Json.stringify(schema); | ||
} | ||
|
||
throw "input must be a struct type"; | ||
}; | ||
|
||
struct User { | ||
name: str; | ||
age: num; | ||
email: str?; | ||
} | ||
|
||
log(generateJsonSchema(@type(User))); | ||
``` | ||
```bash title="Wing console output" | ||
# Run locally with wing console | ||
{"type":"object","properties":{"age":{"type":"number"},"email":{"type":"string"},"name":{"type":"string"}},"required":["age","name"]} | ||
``` | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
title: "QuickShare: Demo application built with Wing" | ||
subtitle: "A demo application showcasing cloud resources with a frontend application" | ||
type: | ||
- "pattern" | ||
platform: | ||
- "awscdk" | ||
- "tf-aws" | ||
- "sim" | ||
language: | ||
- "wing" | ||
githubURL: "https://github.com/winglang/website-with-file-uploader" | ||
repoDirectory: "/" | ||
coverImage: "/img/examples/quickshare.png" | ||
coverImageInPage: true | ||
resources: | ||
- label: "Deploy your own version of this application" | ||
href: "https://github.com/winglang/website-with-file-uploader" | ||
authors: | ||
- name: "David Boyne" | ||
role: "Developer Advocate, Wing" | ||
twitter: "https://twitter.com/boyney123" | ||
github: "https://github.com/boyney123" | ||
cloudResources: | ||
- api | ||
--- | ||
|
||
This demo application shows how you can write Wing applications with cloud primitives and custom abstractions into services, routes and listening to database changes. | ||
|
||
To use the application | ||
|
||
- Make sure you have Wing installed and clone the repo. | ||
- Run `wing it` in the `backend` project directory | ||
- The wing console will load in your browser. | ||
- Go to http://localhost:5173/ to load the Vite application. | ||
- Click `Create Magical Space` | ||
- Add email address and files into the application. | ||
- Click `Share with Friends` to send emails to your selected friends. | ||
|
||
This application consists of a collection of cloud primitives with Wing and winglibs: | ||
|
||
- [Cloud API](https://www.winglang.io/docs/api/standard-library/cloud/api) - API for the frontend to add/edit and delete friends/spaces. | ||
- [Cloud functions](https://www.winglang.io/docs/api/standard-library/cloud/function) - Compute to process API requests, queues and database changes. | ||
- [Queues](https://www.winglang.io/docs/api/standard-library/cloud/queue) - To handle sending the email, configured DLQ on the queue | ||
- [winglib DynamoDB](https://www.winglang.io/docs/winglibs/dynamodb) - Single table design to store friends and spaces into the database. | ||
- [winglib email](https://www.winglang.io/docs/winglibs/email) - To send emails to friends. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions
53
versioned_docs/version-latest/04-winglibs/01-what-are-winglibs.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- | ||
title: Wing Libraries | ||
id: what-are-winglibs | ||
description: Documentation about Wing libraries (winglibs) | ||
sidebar_label: What are winglibs? | ||
keywords: [Wing reference, Wing libraries, libraries, packaging, packages] | ||
--- | ||
|
||
As you write larger Wing applications, organizing your code becomes increasingly important. | ||
By grouping related functionality and separating code with distinct features, you'll make it easier to find code that implements a particular feature and where to go to change how a feature works. | ||
As the project grows further, you can extract parts into separate libraries that become external dependencies. | ||
|
||
Any Wing project can be packaged as a library, which will export all public types (like classes and structs) so that they can be used by multiple applications. | ||
|
||
Wing libraries are also known as [**winglibs**](https://github.com/winglang/winglibs). | ||
|
||
The [Wing Trusted Library Ecosystem](https://github.com/winglang/winglibs) has an open source list of winglibs you can use including [openai](https://github.com/winglang/winglibs/tree/main/openai), [cognito](https://github.com/winglang/winglibs/tree/main/cognito), [dynamodb](https://github.com/winglang/winglibs/tree/main/dynamodb), and [many more](https://github.com/winglang/winglibs). | ||
|
||
### How to use a Wing library | ||
|
||
Wing libraries ([winglibs](https://github.com/winglang/winglibs)) can be installed using the npm command line tool. | ||
|
||
Here is an example of installing the [wing-redis winglib](https://github.com/winglang/winglibs/tree/main/redis). | ||
|
||
``` | ||
npm i wing-redis | ||
``` | ||
|
||
Then in your Wing source code, the library can be imported by name using a `bring` statement: | ||
|
||
```js | ||
bring "wing-redis" as redis; | ||
|
||
new redis.Redis(); | ||
``` | ||
|
||
Libraries can expose the following kinds of API elements: | ||
|
||
- Classes | ||
- Structs | ||
- Interfaces | ||
- Enums | ||
- Constants (coming soon - see https://github.com/winglang/wing/issues/3606 to track) | ||
|
||
APIs in libraries can also be organized hierarchically for better organization. | ||
For example, a library may split up its API elements between multiple modules (also sometimes called "namespaces"): | ||
|
||
```js | ||
bring "my-wing-payments-library" as payments; | ||
|
||
new payments.charges.Charge(); | ||
new payments.customer.Customer(); | ||
``` |
42 changes: 42 additions & 0 deletions
42
versioned_docs/version-latest/04-winglibs/02-using-winglibs.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: Using winglibs | ||
id: using-winglibs | ||
description: Documentation for using winglibs | ||
sidebar_label: Importing winglibs | ||
keywords: [Wing reference, Wing libraries, libraries, packaging, packages] | ||
--- | ||
|
||
|
||
Wing libraries ([winglibs](https://github.com/winglang/winglibs)) can be installed using the npm command line tool. | ||
|
||
Here is an example of installing the [redis winglib](https://github.com/winglang/winglibs/tree/main/redis). | ||
|
||
``` | ||
npm i @winglibs/redis | ||
``` | ||
|
||
Then in your Wing source code, the library can be imported by name using a `bring` statement: | ||
|
||
```js | ||
bring "@winglibs/redis" as redis; | ||
|
||
new redis.Redis(); | ||
``` | ||
|
||
Libraries can expose the following kinds of API elements: | ||
|
||
- Classes | ||
- Structs | ||
- Interfaces | ||
- Enums | ||
- Constants (coming soon - see https://github.com/winglang/wing/issues/3606 to track) | ||
|
||
APIs in libraries can also be organized hierarchically for better organization. | ||
For example, a library may split up its API elements between multiple modules (also sometimes called "namespaces"): | ||
|
||
```js | ||
bring "my-wing-payments-library" as payments; | ||
|
||
new payments.charges.Charge(); | ||
new payments.customer.Customer(); | ||
``` |
27 changes: 27 additions & 0 deletions
27
versioned_docs/version-latest/04-winglibs/03-creating-winglibs.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
title: Creating winglibs | ||
id: creating-winglibs | ||
description: Documentation for creating winglibs | ||
sidebar_label: Creating winglibs | ||
keywords: [Wing reference, Wing libraries, libraries, packaging, packages] | ||
--- | ||
|
||
Packaging your own Wing code as a library is straightforward. | ||
Let's walk through it step by step. | ||
|
||
First, check that your project is organized based on how you want to structure your library. | ||
There are two main rules to be aware of: | ||
|
||
1. APIs can only be exported from non-entrypoint files (files that do not end in `.main.w` or `.test.w`). | ||
Entrypoint files are perfect for writing tests and deployment scenarios that can be executed as-is - but if you have classes and other APIs you want to share, they have to be defined in non-entrypoint files (also known as module files). | ||
|
||
2. APIs are organized based on the project's directory structure. | ||
If you want a group of classes to be part of a namespace named "storage", define them in a directory named "storage" (for example, some classes could be defined in `storage/file1.w`, several more in `storage/file2.w`, and so on). | ||
All public APIs defined at the root of your project will be available at top-level namespace in your library. | ||
|
||
Next, run `npm init` to create a `package.json` file with information about your library. | ||
Make sure you fill out the "name", "version", "description", "author", and "license" fields. | ||
|
||
Finally, run `wing pack` at the root of your project directory. | ||
`wing pack` will compile your project and create a .tgz file that can be published to [npm](https://www.npmjs.com/), [GitHub Packages](https://github.com/features/packages), or any other Node.js package managing service. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
label: Wing Libraries (winglibs) | ||
collapsible: true | ||
collapsed: true | ||
link: | ||
type: generated-index | ||
title: Wing Libraries (winglibs) |