From b6f175f139747611bcbf4548f790dc62d26413c4 Mon Sep 17 00:00:00 2001 From: cmorten Date: Sat, 27 Aug 2022 09:58:54 +0100 Subject: [PATCH] fix: support `ReadableStream` in `res.send()` --- .github/API/application.md | 12 ++++++------ .github/API/middlewares.md | 8 ++++---- .github/API/opine.md | 4 ++-- .github/API/request.md | 4 ++-- .github/API/router.md | 4 ++-- .github/CHANGELOG.md | 4 ++++ README.md | 6 +++--- docs/index.html | 6 +++--- egg.json | 2 +- src/response.ts | 9 ++++----- src/types.ts | 11 ++++++++--- version.ts | 2 +- 12 files changed, 40 insertions(+), 32 deletions(-) diff --git a/.github/API/application.md b/.github/API/application.md index 554eeccb..aad0b79b 100644 --- a/.github/API/application.md +++ b/.github/API/application.md @@ -8,7 +8,7 @@ The `app` object conventionally denotes the Opine application. Create it by calling the top-level `opine()` function exported by the Opine module: ```ts -import opine from "https://deno.land/x/opine@2.3.2/mod.ts"; +import opine from "https://deno.land/x/opine@2.3.3/mod.ts"; const app = opine(); @@ -69,7 +69,7 @@ sub-app was mounted. > to a route. ```ts -import opine from "https://deno.land/x/opine@2.3.2/mod.ts"; +import opine from "https://deno.land/x/opine@2.3.3/mod.ts"; const app = opine(); // the main app const admin = opine(); // the sub app @@ -487,7 +487,7 @@ starts listening for requests - this is provided for legacy reasons to aid in transitions from Express on Node. ```ts -import opine from "https://deno.land/x/opine@2.3.2/mod.ts"; +import opine from "https://deno.land/x/opine@2.3.3/mod.ts"; const app = opine(); @@ -523,7 +523,7 @@ This method is supported for legacy reasons to aid in transitions from Express on Node. ```ts -import opine from "https://deno.land/x/opine@2.3.2/mod.ts"; +import opine from "https://deno.land/x/opine@2.3.3/mod.ts"; const app = opine(); const PORT = 3000; @@ -542,7 +542,7 @@ starts listening for requests - this is provided for legacy reasons to aid in transitions from Express on Node. ```ts -import opine from "https://deno.land/x/opine@2.3.2/mod.ts"; +import opine from "https://deno.land/x/opine@2.3.3/mod.ts"; const app = opine(); @@ -560,7 +560,7 @@ starts listening for requests - this is provided for legacy reasons to aid in transitions from Express on Node. ```ts -import opine from "https://deno.land/x/opine@2.3.2/mod.ts"; +import opine from "https://deno.land/x/opine@2.3.3/mod.ts"; const app = opine(); diff --git a/.github/API/middlewares.md b/.github/API/middlewares.md index 8aaabe65..cb6caf04 100644 --- a/.github/API/middlewares.md +++ b/.github/API/middlewares.md @@ -28,7 +28,7 @@ reasons. > `toString` may not be a function and instead a string or other user-input. ```ts -import { json, opine } from "https://deno.land/x/opine@2.3.2/mod.ts"; +import { json, opine } from "https://deno.land/x/opine@2.3.3/mod.ts"; const app = opine(); @@ -77,7 +77,7 @@ reasons. > recommended. ```ts -import { opine, raw } from "https://deno.land/x/opine@2.3.2/mod.ts"; +import { opine, raw } from "https://deno.land/x/opine@2.3.3/mod.ts"; const app = opine(); @@ -230,7 +230,7 @@ reasons. > recommended. ```ts -import { opine, text } from "https://deno.land/x/opine@2.3.2/mod.ts"; +import { opine, text } from "https://deno.land/x/opine@2.3.3/mod.ts"; const app = opine(); @@ -277,7 +277,7 @@ reasons. > `toString` may not be a function and instead a string or other user-input. ```ts -import { opine, urlencoded } from "https://deno.land/x/opine@2.3.2/mod.ts"; +import { opine, urlencoded } from "https://deno.land/x/opine@2.3.3/mod.ts"; const app = opine(); diff --git a/.github/API/opine.md b/.github/API/opine.md index 20444294..1082023e 100644 --- a/.github/API/opine.md +++ b/.github/API/opine.md @@ -8,7 +8,7 @@ Creates an Opine application. The `opine()` function is a top-level function exported by the Opine module: ```ts -import opine from "https://deno.land/x/opine@2.3.2/mod.ts"; +import opine from "https://deno.land/x/opine@2.3.3/mod.ts"; const app = opine(); ``` @@ -16,7 +16,7 @@ const app = opine(); The `opine()` function is also exported as a named export: ```ts -import { opine } from "https://deno.land/x/opine@2.3.2/mod.ts"; +import { opine } from "https://deno.land/x/opine@2.3.3/mod.ts"; const app = opine(); ``` diff --git a/.github/API/request.md b/.github/API/request.md index cbebcb6c..561337e0 100644 --- a/.github/API/request.md +++ b/.github/API/request.md @@ -101,7 +101,7 @@ import { json, opine, urlencoded, -} from "https://deno.land/x/opine@2.3.2/mod.ts"; +} from "https://deno.land/x/opine@2.3.3/mod.ts"; const app = opine(); @@ -118,7 +118,7 @@ The following example shows how to implement your own simple body-parsing middleware to transform `req.body` into a raw string: ```ts -import opine from "https://deno.land/x/opine@2.3.2/mod.ts"; +import opine from "https://deno.land/x/opine@2.3.3/mod.ts"; import { readAll } from "https://deno.land/std@0.120.0/streams/conversion.ts"; diff --git a/.github/API/router.md b/.github/API/router.md index f1b8d4d1..1fc395c8 100644 --- a/.github/API/router.md +++ b/.github/API/router.md @@ -16,7 +16,7 @@ Opine has a top-level named function export `Router()` that creates a new `router` object. ```ts -import { Router } from "https://deno.land/x/opine@2.3.2/mod.ts"; +import { Router } from "https://deno.land/x/opine@2.3.3/mod.ts"; const router = Router(options); ``` @@ -260,7 +260,7 @@ function defined and work their way "down" the middleware stack processing for each path they match. ```ts -import opine, { Router } from "https://deno.land/x/opine@2.3.2/mod.ts"; +import opine, { Router } from "https://deno.land/x/opine@2.3.3/mod.ts"; const app = opine(); const router = Router(); diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 8b03fd10..f40a5658 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -1,5 +1,9 @@ # ChangeLog +## [2.3.3] - 27-08-2022 + +- fix: support `ReadableStream` in `res.send()` + ## [2.3.2] - 27-08-2022 - fix: replace `Deno.statSync` with `Deno.stat` to allow views to be used on Deno Deploy diff --git a/README.md b/README.md index ba7c819e..9d1bfa71 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Express not working for you? [Raise an issue on Deno](https://github.com/denolan ## Getting Started ```ts -import { opine } from "https://deno.land/x/opine@2.3.2/mod.ts"; +import { opine } from "https://deno.land/x/opine@2.3.3/mod.ts"; const app = opine(); @@ -75,14 +75,14 @@ Before importing, [download and install Deno](https://deno.land/#installation). You can then import Opine straight into your project: ```ts -import { opine } from "https://deno.land/x/opine@2.3.2/mod.ts"; +import { opine } from "https://deno.land/x/opine@2.3.3/mod.ts"; ``` Opine is also available on [nest.land](https://nest.land/package/opine), a package registry for Deno on the Blockchain. ```ts -import { opine } from "https://x.nest.land/opine@2.3.2/mod.ts"; +import { opine } from "https://x.nest.land/opine@2.3.3/mod.ts"; ``` ## Features diff --git a/docs/index.html b/docs/index.html index 4e4af251..f2ad8226 100644 --- a/docs/index.html +++ b/docs/index.html @@ -111,7 +111,7 @@

Table of Contents

Getting Started

-
import { opine } from "https://deno.land/x/opine@2.3.2/mod.ts";
+				
import { opine } from "https://deno.land/x/opine@2.3.3/mod.ts";
 
 const app = opine();
 
@@ -130,11 +130,11 @@ 

Installation

repo and via the Deno Registry.

Before importing, download and install Deno.

You can then import Opine straight into your project:

-
import { opine } from "https://deno.land/x/opine@2.3.2/mod.ts";
+				
import { opine } from "https://deno.land/x/opine@2.3.3/mod.ts";
 

Opine is also available on nest.land, a package registry for Deno on the Blockchain.

-
import { opine } from "https://x.nest.land/opine@2.3.2/mod.ts";
+				
import { opine } from "https://x.nest.land/opine@2.3.3/mod.ts";
 

Features

diff --git a/egg.json b/egg.json index ced0710f..8c1bba8b 100644 --- a/egg.json +++ b/egg.json @@ -1,7 +1,7 @@ { "name": "opine", "description": "Minimalist web framework for Deno ported from ExpressJS.", - "version": "2.3.2", + "version": "2.3.3", "repository": "https://github.com/cmorten/opine", "stable": true, "checkFormat": false, diff --git a/src/response.ts b/src/response.ts index 8432337e..c6fd6183 100644 --- a/src/response.ts +++ b/src/response.ts @@ -244,9 +244,7 @@ export class Response implements OpineResponse { * @return {Promise} * @public */ - async end( - body?: DenoResponseBody, - ): Promise { + async end(body?: DenoResponseBody): Promise { if (body) { this.body = body; } @@ -678,9 +676,10 @@ export class Response implements OpineResponse { default: if ( body instanceof Uint8Array || - typeof (body as Deno.Reader).read === "function" + typeof (body as Deno.Reader).read === "function" || + typeof (body as ReadableStream).getReader === "function" ) { - chunk = body as Uint8Array | Deno.Reader; + chunk = body as Uint8Array | Deno.Reader | ReadableStream; if (!this.get("Content-Type")) { this.type("bin"); diff --git a/src/types.ts b/src/types.ts index 33197cfe..380bd02e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -24,7 +24,12 @@ export type HTTPSOptions = Omit< "transport" >; -export type DenoResponseBody = undefined | string | Uint8Array | Deno.Reader; +export type DenoResponseBody = + | undefined + | string + | Uint8Array + | Deno.Reader + | ReadableStream; export type ResponseBody = | null | undefined @@ -613,7 +618,7 @@ export interface OpineRequest< status?: number; statusText?: string; headers?: Headers; - body?: Uint8Array | Deno.Reader | string; + body?: Uint8Array | Deno.Reader | string | ReadableStream; trailers?: () => Promise | Headers; }): void; @@ -638,7 +643,7 @@ export interface OpineResponse extends Opine.Response { status?: number; statusText?: string; headers?: Headers; - body?: Uint8Array | Deno.Reader | string; + body?: Uint8Array | Deno.Reader | string | ReadableStream; app: Application; diff --git a/version.ts b/version.ts index 2eaab12b..a621057d 100644 --- a/version.ts +++ b/version.ts @@ -1,7 +1,7 @@ /** * Version of Opine. */ -export const VERSION = "2.3.2"; +export const VERSION = "2.3.3"; /** * Supported version of Deno.