Skip to content

Commit

Permalink
Merge pull request #28 from lambdalisue/fix
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
lambdalisue authored May 12, 2024
2 parents b91c718 + b8348a3 commit 8624663
Show file tree
Hide file tree
Showing 17 changed files with 265 additions and 115 deletions.
84 changes: 51 additions & 33 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,65 @@
name: Test

env:
DENO_VERSION: 1.x

on:
schedule:
- cron: "0 7 * * 0"
push:
branches:
- main
pull_request:
paths:
- "**.md"
- "**.ts"
- "deno.jsonc"
- ".github/workflows/test.yml"
workflow_dispatch:

jobs:
test:
strategy:
matrix:
runner:
- ubuntu-latest
version:
- "1.x"
- "1.28.x"
runs-on: ${{ matrix.runner }}
check:
runs-on: ubuntu-latest
steps:
- run: git config --global core.autocrlf false
if: runner.os == 'Windows'
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v1
with:
deno-version: "${{ matrix.version }}"
- uses: actions/cache@v3
with:
key: ${{ runner.os }}-deno-${{ hashFiles('**/*.ts') }}
restore-keys: |
${{ runner.os }}-deno-
path: |
/home/runner/.deno
/home/runner/.cache/deno/deps/https/deno.land
- name: Test
deno-version: ${{ env.DENO_VERSION }}
- name: Format
run: |
deno task test
deno fmt --check
- name: Lint
run: deno lint
- name: Type check
run: deno task check

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v1
with:
deno-version: ${{ env.DENO_VERSION }}
- name: Test
run: |
deno task check
- name: Lint check
run: |
deno lint
- name: Format check
deno task test:coverage
timeout-minutes: 5
- run: |
deno task coverage --lcov > coverage.lcov
- uses: codecov/codecov-action@v4
with:
os: ${{ runner.os }}
files: ./coverage.lcov
token: ${{ secrets.CODECOV_TOKEN }}

bench:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v1
with:
deno-version: ${{ env.DENO_VERSION }}
- name: Install aha
run: |
deno fmt && git diff --exit-code
- name: Bench
sudo apt-get install aha
- name: Benchmark
run: |
deno task bench
deno task bench | aha --no-header >> $GITHUB_STEP_SUMMARY
50 changes: 0 additions & 50 deletions .github/workflows/udd.yml

This file was deleted.

48 changes: 48 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: update

on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v1
with:
deno-version: 1.x
- name: Configure Git
run: |
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
- name: Update dependencies and commit changes
run: deno task -q upgrade:commit --summary ../title.txt --report ../body.md
- name: Check result
id: result
uses: andstor/file-existence-action@v2
with:
files: ../title.txt, ../body.md
- name: Read title.txt
id: title
if: steps.result.outputs.files_exists == 'true'
uses: juliangruber/read-file-action@v1
with:
path: ../title.txt
- name: Read body.md
id: body
if: steps.result.outputs.files_exists == 'true'
uses: juliangruber/read-file-action@v1
with:
path: ../body.md
- name: Create a pull request
if: steps.result.outputs.files_exists == 'true'
uses: peter-evans/create-pull-request@v6
with:
author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
branch: automation/update-dependencies
title: ${{ steps.title.outputs.content }}
body: ${{ steps.body.outputs.content }}
labels: automation
delete-branch: true
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.tool-versions
/.tools
deno.lock
.coverage
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![deno land](http://img.shields.io/badge/available%20on-deno.land/x-lightgrey.svg?logo=deno)](https://deno.land/x/workerio)
[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/workerio/mod.ts)
[![Test](https://github.com/lambdalisue/deno-workerio/actions/workflows/test.yml/badge.svg)](https://github.com/lambdalisue/deno-workerio/actions/workflows/test.yml)
[![codecov](https://codecov.io/gh/lambdalisue/deno-workerio/graph/badge.svg?token=6Q1iOBg2Ka)](https://codecov.io/gh/lambdalisue/deno-workerio)

[Deno][deno] module to translate Worker's system of messages into
[`ReadableStream<Uint8Array>`][readablestream] and
Expand All @@ -25,7 +26,7 @@
import {
readableStreamFromWorker,
writableStreamFromWorker,
} from "https://deno.land/x/workerio/mod.ts";
} from "https://deno.land/x/workerio@$MODULE_VERSION/mod.ts";

const decoder = new TextDecoder();
const encoder = new TextEncoder();
Expand Down Expand Up @@ -54,7 +55,7 @@ for await (const data of reader) {
import {
readableStreamFromWorker,
writableStreamFromWorker,
} from "https://deno.land/x/workerio/mod.ts";
} from "https://deno.land/x/workerio@$MODULE_VERSION/mod.ts";

const decoder = new TextDecoder();
const encoder = new TextEncoder();
Expand Down Expand Up @@ -83,7 +84,7 @@ main().catch((e) => console.error(e));
import {
WorkerReader,
WorkerWriter,
} from "https://deno.land/x/workerio/mod.ts";
} from "https://deno.land/x/workerio@$MODULE_VERSION/mod.ts";

const decoder = new TextDecoder();
const encoder = new TextEncoder();
Expand All @@ -110,7 +111,7 @@ for await (const data of Deno.iter(reader)) {
import {
WorkerReader,
WorkerWriter,
} from "https://deno.land/x/workerio/mod.ts";
} from "https://deno.land/x/workerio@$MODULE_VERSION/mod.ts";

const decoder = new TextDecoder();
const encoder = new TextEncoder();
Expand Down
12 changes: 9 additions & 3 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"tasks": {
"test": "deno test -A --parallel",
"check": "deno check **/*.ts",
"test": "deno test -A --doc --parallel --shuffle",
"test:coverage": "deno task test --coverage=.coverage",
"coverage": "deno coverage .coverage",
"bench": "deno bench -A",
"check": "deno check $(find . -name '*.ts')",
"upgrade": "deno run -A https://deno.land/x/udd/main.ts $(find . -name '*.ts')"
"update": "deno run --allow-env --allow-read --allow-write=. --allow-run=git,deno --allow-net=jsr.io,registry.npmjs.org jsr:@molt/cli ./*.ts",
"update:commit": "deno task -q update --commit --pre-commit=fmt,lint"
},
"imports": {
"https://deno.land/x/workerio@$MODULE_VERSION/": "./"
}
}
128 changes: 128 additions & 0 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,131 @@
/**
* [Deno] module to translate Worker's system of messages into
* [`ReadableStream<Uint8Array>`][readablestream] and
* [`WritableStream<Uint8Array>`][writablestream] or [`Deno.Reader`][reader] and
* [`Deno.Writer`][writer].
*
* [Deno]: https://deno.land/
* [reader]: https://doc.deno.land/builtin/stable#Deno.Reader
* [writer]: https://doc.deno.land/builtin/stable#Deno.Writer
* [ReadableStream]: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream
* [WritableStream]: https://developer.mozilla.org/en-US/docs/Web/API/WritableStream
*
* ## Example
*
* ### ReadableStream/WritableStream
*
* #### Server
*
* ```typescript
* import {
* readableStreamFromWorker,
* writableStreamFromWorker,
* } from "https://deno.land/x/workerio@$MODULE_VERSION/mod.ts";
*
* const decoder = new TextDecoder();
* const encoder = new TextEncoder();
*
* const worker = new Worker(new URL("./worker.ts", import.meta.url).href, {
* type: "module",
* });
*
* const reader = readableStreamFromWorker(worker);
* const writer = writableStreamFromWorker(worker);
* const w = writer.getWriter();
*
* await w.write(encoder.encode("Hello"));
* await w.write(encoder.encode("World"));
* w.releaseLock();
*
* for await (const data of reader) {
* const text = decoder.decode(data);
* console.log(text);
* }
* ```
*
* #### Worker
*
* ```typescript
* import {
* readableStreamFromWorker,
* writableStreamFromWorker,
* } from "https://deno.land/x/workerio@$MODULE_VERSION/mod.ts";
*
* const decoder = new TextDecoder();
* const encoder = new TextEncoder();
*
* async function main(): Promise<void> {
* const worker = self as unknown as Worker;
* const reader = readableStreamFromWorker(worker);
* const writer = writableStreamFromWorker(worker);
* const w = writer.getWriter();
*
* for await (const data of reader) {
* const text = decoder.decode(data);
* await w.write(encoder.encode(`!!! ${text} !!!`));
* }
* w.releaseLock();
* }
*
* main().catch((e) => console.error(e));
* ```
*
* ### Deno.Reader/Deno.Writer
*
* #### Server
*
* ```typescript
* import {
* WorkerReader,
* WorkerWriter,
* } from "https://deno.land/x/workerio@$MODULE_VERSION/mod.ts";
*
* const decoder = new TextDecoder();
* const encoder = new TextEncoder();
*
* const worker = new Worker(new URL("./worker.ts", import.meta.url).href, {
* type: "module",
* });
*
* const reader = new WorkerReader(worker);
* const writer = new WorkerWriter(worker);
*
* await writer.write(encoder.encode("Hello"));
* await writer.write(encoder.encode("World"));
*
* for await (const data of Deno.iter(reader)) {
* const text = decoder.decode(data);
* console.log(text);
* }
* ```
*
* #### Worker
*
* ```typescript
* import {
* WorkerReader,
* WorkerWriter,
* } from "https://deno.land/x/workerio@$MODULE_VERSION/mod.ts";
*
* const decoder = new TextDecoder();
* const encoder = new TextEncoder();
*
* async function main(): Promise<void> {
* const worker = self as unknown as Worker;
* const reader = new WorkerReader(worker);
* const writer = new WorkerWriter(worker);
*
* for await (const data of Deno.iter(reader)) {
* const text = decoder.decode(data);
* await writer.write(encoder.encode(`!!! ${text} !!!`));
* }
* }
*
* main().catch((e) => console.error(e));
* ```
*
* @module
*/
export * from "./readable_stream.ts";
export * from "./reader.ts";
export * from "./writable_stream.ts";
Expand Down
Loading

0 comments on commit 8624663

Please sign in to comment.