Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bring yaml #250

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/canary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -903,3 +903,36 @@ jobs:
cd websockets
wing test
timeout_minutes: 5
canary-yaml:
name: Test yaml
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
sparse-checkout: yaml
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
registry-url: https://registry.npmjs.org
- name: Install winglang and dependencies
uses: nick-fields/retry@v3
with:
max_attempts: 3
command: npm i -g winglang --loglevel verbose
timeout_minutes: 3
- name: Install dependencies
uses: nick-fields/retry@v3
with:
max_attempts: 3
command: cd yaml && npm i --include=dev --loglevel verbose
timeout_minutes: 3
- name: Run tests
uses: nick-fields/retry@v3
with:
max_attempts: 3
command: |-
cd yaml
wing test
timeout_minutes: 5
1 change: 1 addition & 0 deletions .github/workflows/pull-request-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
tsoa
vite
websockets
yaml
subjectPattern: ^[^A-Z][^:]+[^.]$
subjectPatternError: Subject must start with a lowercase, should not include ':'
and should not end with a period
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/yaml-pull.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: yaml-pull
on:
pull_request:
paths:
- yaml/**
jobs:
build-yaml:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
sparse-checkout: yaml
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
registry-url: https://registry.npmjs.org
- name: Install winglang
run: npm i -g winglang
- name: Install dependencies
run: npm install --include=dev
working-directory: yaml
- name: Test
run: wing test
working-directory: yaml
- name: Pack
run: wing pack
working-directory: yaml
54 changes: 54 additions & 0 deletions .github/workflows/yaml-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: yaml-release
on:
push:
branches:
- main
paths:
- yaml/**
- "!yaml/package-lock.json"
jobs:
build-yaml:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
sparse-checkout: yaml
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
registry-url: https://registry.npmjs.org
- name: Install winglang
run: npm i -g winglang
- name: Install dependencies
run: npm install --include=dev
working-directory: yaml
- name: Test
run: wing test
working-directory: yaml
- name: Pack
run: wing pack
working-directory: yaml
- name: Get package version
run: echo WINGLIB_VERSION=$(node -p "require('./package.json').version") >>
"$GITHUB_ENV"
working-directory: yaml
- name: Publish
run: npm publish --access=public --registry https://registry.npmjs.org --tag
latest *.tgz
working-directory: yaml
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Tag commit
uses: tvdias/[email protected]
with:
repo-token: ${{ secrets.PROJEN_GITHUB_TOKEN }}
tag: yaml-v${{ env.WINGLIB_VERSION }}
- name: GitHub release
uses: softprops/action-gh-release@v1
with:
name: yaml v${{ env.WINGLIB_VERSION }}
tag_name: yaml-v${{ env.WINGLIB_VERSION }}
files: "*.tgz"
token: ${{ secrets.PROJEN_GITHUB_TOKEN }}
6 changes: 6 additions & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ pull_request_rules:
- -check-failure=build-websockets
- -check-pending=build-websockets
- -check-stale=build-websockets
- -check-failure=build-yaml
- -check-pending=build-yaml
- -check-stale=build-yaml
- name: requires manual merge
conditions:
- files=.mergify.yml
Expand Down Expand Up @@ -216,6 +219,9 @@ pull_request_rules:
- -check-failure=build-websockets
- -check-pending=build-websockets
- -check-stale=build-websockets
- -check-failure=build-yaml
- -check-pending=build-yaml
- -check-stale=build-yaml
actions:
comment:
message: Thank you for contributing! Your pull request contains mergify
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ publishing them for you.
| [tsoa](./tsoa) | [@winglibs/tsoa](https://www.npmjs.com/package/@winglibs/tsoa) | sim |
| [vite](./vite) | [@winglibs/vite](https://www.npmjs.com/package/@winglibs/vite) | sim, tf-aws |
| [websockets](./websockets) | [@winglibs/websockets](https://www.npmjs.com/package/@winglibs/websockets) | awscdk, sim, tf-aws |
| [yaml](./yaml) | [@winglibs/yaml](https://www.npmjs.com/package/@winglibs/yaml) | * |

_Generated with `mkrepo.sh`. To update the list of supported platforms for a winglib, please update the "wing" section in its package.json file._

Expand Down
2 changes: 2 additions & 0 deletions yaml/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/
node_modules/
21 changes: 21 additions & 0 deletions yaml/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Wing

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
34 changes: 34 additions & 0 deletions yaml/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# yaml

A Wing library for working with yaml.

## Prerequisites

* [winglang](https://winglang.io).

## Installation

```sh
npm i @winglibs/yaml
```

## Usage

```js
bring fs;
bring yaml;
bring cloud;

let file = fs.readFile("./test.yml");
let value = yaml.parseValue(file);
yaml.stringifyValue(json);

new cloud.Function(inflight () => {
let value = yaml.parse(file);
yaml.stringify(json);
});
```
Comment on lines +17 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should totally include this in the built-in standard library!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we already have some yaml stuff in the standard library?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this should be part of the stdlib.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apparently we already have fs.readYaml.. was not aware of it


## License

This library is licensed under the [MIT License](./LICENSE).
19 changes: 19 additions & 0 deletions yaml/lib.test.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
bring fs;
bring expect;
bring "./lib.w" as yaml;

let json = {
key1: ["value1", "value2"],
key2: "value3",
};

let file = fs.readFile(fs.join(@dirname, "./test.yml"));
let value = yaml.parseValue(file);
expect.equal(value, json);
expect.equal(yaml.stringifyValue(json), file);

test "can parse and stringify yaml file" {
let value = yaml.parse(file);
expect.equal(value, json);
expect.equal(yaml.stringify(json), file);
}
33 changes: 33 additions & 0 deletions yaml/lib.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
pub struct ParseOptions {
strict: bool?;
}

pub struct StringifyOptions {
indent: num?;
}

pub class Util {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the benefit of this duplication? Why not just make the extern methods public?

pub static inflight parse(value: str, options: ParseOptions?): Json {
return Extern._parse(value, options);
}

pub static inflight stringify(value: Json, options: StringifyOptions?): Json {
return Extern._stringify(value, options);
}

pub static parseValue(value: str, options: ParseOptions?): Json {
return Extern._preflight_parse(value, options);
}

pub static stringifyValue(value: Json, options: StringifyOptions?): Json {
return Extern._preflight_stringify(value, options);
}
}

class Extern {
pub extern "./yaml.mts" static inflight _parse(value: str, options: ParseOptions?): Json;
pub extern "./yaml.mts" static inflight _stringify(value: Json, options: StringifyOptions?): str;
pub extern "./yaml.mts" static _preflight_parse(value: str, options: ParseOptions?): Json;
pub extern "./yaml.mts" static _preflight_stringify(value: Json, options: StringifyOptions?): str;
}

28 changes: 28 additions & 0 deletions yaml/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions yaml/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@winglibs/yaml",
"description": "yaml library for Wing",
"version": "0.0.1",
"repository": {
"type": "git",
"url": "https://github.com/winglang/winglibs.git",
"directory": "yaml"
},
"author": {
"email": "[email protected]",
"name": "Elad Cohen"
},
"wing": {
"platforms": [
"*"
]
},
"license": "MIT",
"peerDependencies": {
"yaml": "^2.4.2"
}
}
4 changes: 4 additions & 0 deletions yaml/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
key1:
- value1
- value2
key2: value3
12 changes: 12 additions & 0 deletions yaml/yaml.extern.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default interface extern {
_parse: (value: string, options?: (ParseOptions) | undefined) => Promise<Readonly<any>>,
_preflight_parse: (value: string, options?: (ParseOptions) | undefined) => Readonly<any>,
_preflight_stringify: (value: Readonly<any>, options?: (StringifyOptions) | undefined) => string,
_stringify: (value: Readonly<any>, options?: (StringifyOptions) | undefined) => Promise<string>,
}
export interface ParseOptions {
readonly strict?: (boolean) | undefined;
}
export interface StringifyOptions {
readonly indent?: (number) | undefined;
}
5 changes: 5 additions & 0 deletions yaml/yaml.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { parse, stringify } from "yaml";
export const _parse = parse;
export const _stringify = stringify;
export const _preflight_parse = parse;
export const _preflight_stringify = stringify;
Loading