@remix-run/node 1.19.3-pre.0 → 2.0.0-pre.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +88 -2
- package/dist/base64.js +1 -1
- package/dist/crypto.js +1 -1
- package/dist/fetch.d.ts +6 -4
- package/dist/fetch.js +3 -20
- package/dist/globals.d.ts +0 -1
- package/dist/globals.js +1 -3
- package/dist/implementations.js +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.js +5 -11
- package/dist/sessions/fileStorage.d.ts +1 -0
- package/dist/sessions/fileStorage.js +14 -13
- package/dist/stream.d.ts +1 -1
- package/dist/stream.js +24 -29
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/upload/fileUploadHandler.d.ts +2 -1
- package/dist/upload/fileUploadHandler.js +33 -19
- package/package.json +14 -6
- package/dist/magicExports/esm/remix.js +0 -11
- package/dist/magicExports/remix.d.ts +0 -42
- package/dist/magicExports/remix.js +0 -36
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,97 @@
|
|
|
1
1
|
# `@remix-run/node`
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 2.0.0-pre.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- Require Node >=18.0.0 ([#6939](https://github.com/remix-run/remix/pull/6939))
|
|
8
|
+
- We have made a few important changes to the route `meta` API as reflected in the v1 implementation when using the `future.v2_meta` config option. ([#6958](https://github.com/remix-run/remix/pull/6958))
|
|
9
|
+
|
|
10
|
+
- The `meta` function should no longer return an object, but an array of objects that map to the HTML tag's respective attributes. This provides more flexibility and control over how certain tags are rendered, and the order in which they appear.
|
|
11
|
+
- In most cases, `meta` descriptor objects render a `<meta>` tag. There are a few notable exceptions:
|
|
12
|
+
- `{ title: "My app" }` will render `<title>My app</title>`.
|
|
13
|
+
- `{ 'script:ld+json': { /* ... */ } }` will render `<script type="application/ld+json">/* ... */</script>`, where the value is serialized to JSON and rendered inside the `<script>` tag.
|
|
14
|
+
- `{ tagName: 'link', ...attributes }` will render `<link {...attributes} />`
|
|
15
|
+
- This is useful for things like setting canonical URLs. For loading assets, we encourage you to use the `links` export instead.
|
|
16
|
+
- It's important to note that `tagName` may only accept `meta` or `link`, so other arbitrary elements will be ignored.
|
|
17
|
+
- `<Meta />` will no longer render the `meta` output from the entire route hierarchy. Only the output from the leaf (current) route will be rendered unless that route does not export a `meta` function, in which case the output from the nearest ancestor route with `meta` will be rendered.
|
|
18
|
+
- This change comes from user feedback that auto-merging meta made effective SEO difficult to implement. Our goal is to give you as much control as you need over meta tags for each individual route.
|
|
19
|
+
- Our suggested approach is to **only export a `meta` function from leaf route modules**. However, if you do want to render a tag from another matched route, `meta` now accepts a `matches` argument for you to merge or override parent route meta as you'd like.
|
|
20
|
+
```tsx
|
|
21
|
+
export function meta({ matches }) {
|
|
22
|
+
return [
|
|
23
|
+
// render all ancestor route meta except for title tags
|
|
24
|
+
...matches
|
|
25
|
+
.flatMap((match) => match.meta)
|
|
26
|
+
.filter((match) => !("title" in match)),
|
|
27
|
+
{ title: "Override the title!" },
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
- The `parentsData` argument has been removed. If you need to access data from a parent route, you can use `matches` instead.
|
|
32
|
+
```tsx
|
|
33
|
+
// before
|
|
34
|
+
export function meta({ parentsData }) {
|
|
35
|
+
return [{ title: parentsData["routes/some-route"].title }];
|
|
36
|
+
}
|
|
37
|
+
// after
|
|
38
|
+
export function meta({ matches }) {
|
|
39
|
+
return [
|
|
40
|
+
{
|
|
41
|
+
title: matches.find((match) => match.id === "routes/some-route").data
|
|
42
|
+
.title,
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
- For preparation of using Node's built in fetch implementation, installing the fetch globals is now a responsibility of the app server. If you are using `remix-serve`, nothing is required. If you are using your own app server, you will need to install the globals yourself. ([#7009](https://github.com/remix-run/remix/pull/7009))
|
|
49
|
+
|
|
50
|
+
```js filename=server.js
|
|
51
|
+
import { installGlobals } from "@remix-run/node";
|
|
52
|
+
|
|
53
|
+
installGlobals();
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
source-map-support is now a responsibility of the app server. If you are using `remix-serve`, nothing is required. If you are using your own app server, you will need to install [`source-map-support`](https://www.npmjs.com/package/source-map-support) yourself.
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
npm i source-map-support
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```js filename=server.js
|
|
63
|
+
import sourceMapSupport from "source-map-support";
|
|
64
|
+
sourceMapSupport.install();
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
- Removed support for "magic exports" from the `remix` package. This package can be removed from your `package.json` and you should update all imports to use the source `@remix-run/*` packages: ([#6895](https://github.com/remix-run/remix/pull/6895))
|
|
68
|
+
|
|
69
|
+
```diff
|
|
70
|
+
- import type { ActionArgs } from "remix";
|
|
71
|
+
- import { json, useLoaderData } from "remix";
|
|
72
|
+
+ import type { ActionArgs } from "@remix-run/node";
|
|
73
|
+
+ import { json } from "@remix-run/node";
|
|
74
|
+
+ import { useLoaderData } from "@remix-run/react";
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Minor Changes
|
|
78
|
+
|
|
79
|
+
- Re-export new `redirectDocument` method from React Router ([#7040](https://github.com/remix-run/remix/pull/7040), [#6842](https://github.com/remix-run/remix/pull/6842)) ([#7040](https://github.com/remix-run/remix/pull/7040))
|
|
80
|
+
|
|
81
|
+
### Patch Changes
|
|
82
|
+
|
|
83
|
+
- Export proper `ErrorResponse` type for usage alongside `isRouteErrorResponse` ([#7244](https://github.com/remix-run/remix/pull/7244))
|
|
84
|
+
- ensures fetch() return is instanceof global Response by removing extended classes for NodeRequest and NodeResponse in favor of custom interface type cast. ([#7109](https://github.com/remix-run/remix/pull/7109))
|
|
85
|
+
- remove recursion from stream utilities ([#7245](https://github.com/remix-run/remix/pull/7245))
|
|
86
|
+
- Updated dependencies:
|
|
87
|
+
- `@remix-run/server-runtime@2.0.0-pre.0`
|
|
88
|
+
|
|
89
|
+
## 1.19.3
|
|
4
90
|
|
|
5
91
|
### Patch Changes
|
|
6
92
|
|
|
7
93
|
- Updated dependencies:
|
|
8
|
-
- `@remix-run/server-runtime@1.19.3
|
|
94
|
+
- `@remix-run/server-runtime@1.19.3`
|
|
9
95
|
|
|
10
96
|
## 1.19.2
|
|
11
97
|
|
package/dist/base64.js
CHANGED
package/dist/crypto.js
CHANGED
package/dist/fetch.d.ts
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type { Readable } from "stream";
|
|
2
|
+
import type { Readable } from "node:stream";
|
|
3
3
|
import { fetch as webFetch, Headers as WebHeaders, Request as WebRequest, Response as WebResponse } from "@remix-run/web-fetch";
|
|
4
4
|
export { FormData } from "@remix-run/web-fetch";
|
|
5
5
|
export { File, Blob } from "@remix-run/web-file";
|
|
6
6
|
type NodeHeadersInit = ConstructorParameters<typeof WebHeaders>[0];
|
|
7
|
+
type NodeResponseInfo = ConstructorParameters<typeof WebResponse>[0];
|
|
7
8
|
type NodeResponseInit = NonNullable<ConstructorParameters<typeof WebResponse>[1]>;
|
|
8
9
|
type NodeRequestInfo = ConstructorParameters<typeof WebRequest>[0] | NodeRequest;
|
|
9
10
|
type NodeRequestInit = Omit<NonNullable<ConstructorParameters<typeof WebRequest>[1]>, "body"> & {
|
|
10
11
|
body?: NonNullable<ConstructorParameters<typeof WebRequest>[1]>["body"] | Readable;
|
|
11
12
|
};
|
|
12
13
|
export type { NodeHeadersInit as HeadersInit, NodeRequestInfo as RequestInfo, NodeRequestInit as RequestInit, NodeResponseInit as ResponseInit, };
|
|
13
|
-
|
|
14
|
-
constructor(info: NodeRequestInfo, init?: NodeRequestInit);
|
|
14
|
+
interface NodeRequest extends WebRequest {
|
|
15
15
|
get headers(): WebHeaders;
|
|
16
16
|
clone(): NodeRequest;
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
interface NodeResponse extends WebResponse {
|
|
19
19
|
get headers(): WebHeaders;
|
|
20
20
|
clone(): NodeResponse;
|
|
21
21
|
}
|
|
22
|
+
declare const NodeRequest: new (info: NodeRequestInfo, init?: NodeRequestInit) => NodeRequest;
|
|
23
|
+
declare const NodeResponse: new (info: NodeResponseInfo, init?: NodeResponseInit) => NodeResponse;
|
|
22
24
|
export { WebHeaders as Headers, NodeRequest as Request, NodeResponse as Response, };
|
|
23
25
|
export declare const fetch: typeof webFetch;
|
package/dist/fetch.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/node
|
|
2
|
+
* @remix-run/node v2.0.0-pre.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -15,25 +15,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
15
15
|
var webFetch = require('@remix-run/web-fetch');
|
|
16
16
|
var webFile = require('@remix-run/web-file');
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
super(info, init);
|
|
21
|
-
}
|
|
22
|
-
get headers() {
|
|
23
|
-
return super.headers;
|
|
24
|
-
}
|
|
25
|
-
clone() {
|
|
26
|
-
return new NodeRequest(this);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
class NodeResponse extends webFetch.Response {
|
|
30
|
-
get headers() {
|
|
31
|
-
return super.headers;
|
|
32
|
-
}
|
|
33
|
-
clone() {
|
|
34
|
-
return super.clone();
|
|
35
|
-
}
|
|
36
|
-
}
|
|
18
|
+
const NodeRequest = webFetch.Request;
|
|
19
|
+
const NodeResponse = webFetch.Response;
|
|
37
20
|
const fetch = (info, init) => {
|
|
38
21
|
init = {
|
|
39
22
|
// Disable compression handling so people can return the result of a fetch
|
package/dist/globals.d.ts
CHANGED
package/dist/globals.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/node
|
|
2
|
+
* @remix-run/node v2.0.0-pre.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
14
|
|
|
15
15
|
var webStream = require('@remix-run/web-stream');
|
|
16
|
-
var abortController = require('abort-controller');
|
|
17
16
|
var base64 = require('./base64.js');
|
|
18
17
|
var fetch = require('./fetch.js');
|
|
19
18
|
var webFile = require('@remix-run/web-file');
|
|
@@ -31,7 +30,6 @@ function installGlobals() {
|
|
|
31
30
|
global.FormData = webFetch.FormData;
|
|
32
31
|
global.ReadableStream = webStream.ReadableStream;
|
|
33
32
|
global.WritableStream = webStream.WritableStream;
|
|
34
|
-
global.AbortController = global.AbortController || abortController.AbortController;
|
|
35
33
|
}
|
|
36
34
|
|
|
37
35
|
exports.installGlobals = installGlobals;
|
package/dist/implementations.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { AbortController } from "abort-controller";
|
|
2
1
|
export type { HeadersInit, RequestInfo, RequestInit, ResponseInit, } from "./fetch";
|
|
3
2
|
export { fetch, FormData, Headers, Request, Response } from "./fetch";
|
|
4
3
|
export { installGlobals } from "./globals";
|
|
@@ -6,5 +5,5 @@ export { createFileSessionStorage } from "./sessions/fileStorage";
|
|
|
6
5
|
export { createFileUploadHandler as unstable_createFileUploadHandler, NodeOnDiskFile, } from "./upload/fileUploadHandler";
|
|
7
6
|
export { createCookie, createCookieSessionStorage, createMemorySessionStorage, createSessionStorage, } from "./implementations";
|
|
8
7
|
export { createReadableStreamFromReadable, readableStreamToString, writeAsyncIterableToWritable, writeReadableStreamToWritable, } from "./stream";
|
|
9
|
-
export { createRequestHandler, createSession, defer, broadcastDevReady, logDevReady, isCookie, isSession, json, MaxPartSizeExceededError, redirect, unstable_composeUploadHandlers, unstable_createMemoryUploadHandler, unstable_parseMultipartFormData, } from "@remix-run/server-runtime";
|
|
10
|
-
export type { ActionArgs, ActionFunction, AppData, AppLoadContext, Cookie, CookieOptions, CookieParseOptions, CookieSerializeOptions, CookieSignatureOptions, DataFunctionArgs, EntryContext,
|
|
8
|
+
export { createRequestHandler, createSession, defer, broadcastDevReady, logDevReady, isCookie, isSession, json, MaxPartSizeExceededError, redirect, redirectDocument, unstable_composeUploadHandlers, unstable_createMemoryUploadHandler, unstable_parseMultipartFormData, } from "@remix-run/server-runtime";
|
|
9
|
+
export type { ActionArgs, ActionFunction, AppData, AppLoadContext, Cookie, CookieOptions, CookieParseOptions, CookieSerializeOptions, CookieSignatureOptions, DataFunctionArgs, EntryContext, ErrorResponse, HandleDataRequestFunction, HandleDocumentRequestFunction, HeadersArgs, HeadersFunction, HtmlLinkDescriptor, JsonFunction, LinkDescriptor, LinksFunction, LoaderArgs, LoaderFunction, MemoryUploadHandlerFilterArgs, MemoryUploadHandlerOptions, HandleErrorFunction, PageLinkDescriptor, RequestHandler, RouteHandle, SerializeFrom, ServerBuild, ServerEntryModule, ServerRuntimeMetaArgs as MetaArgs, ServerRuntimeMetaDescriptor as MetaDescriptor, ServerRuntimeMetaFunction as MetaFunction, Session, SessionData, SessionIdStorageStrategy, SessionStorage, SignFunction, TypedDeferredData, TypedResponse, UnsignFunction, UploadHandler, UploadHandlerPart, } from "@remix-run/server-runtime";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/node
|
|
2
|
+
* @remix-run/node v2.0.0-pre.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -12,8 +12,6 @@
|
|
|
12
12
|
|
|
13
13
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
14
|
|
|
15
|
-
var sourceMapSupport = require('source-map-support');
|
|
16
|
-
var abortController = require('abort-controller');
|
|
17
15
|
var fetch = require('./fetch.js');
|
|
18
16
|
var globals = require('./globals.js');
|
|
19
17
|
var fileStorage = require('./sessions/fileStorage.js');
|
|
@@ -23,16 +21,8 @@ var stream = require('./stream.js');
|
|
|
23
21
|
var serverRuntime = require('@remix-run/server-runtime');
|
|
24
22
|
var webFetch = require('@remix-run/web-fetch');
|
|
25
23
|
|
|
26
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
27
24
|
|
|
28
|
-
var sourceMapSupport__default = /*#__PURE__*/_interopDefaultLegacy(sourceMapSupport);
|
|
29
25
|
|
|
30
|
-
sourceMapSupport__default["default"].install();
|
|
31
|
-
|
|
32
|
-
Object.defineProperty(exports, 'AbortController', {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () { return abortController.AbortController; }
|
|
35
|
-
});
|
|
36
26
|
exports.Request = fetch.Request;
|
|
37
27
|
exports.Response = fetch.Response;
|
|
38
28
|
exports.fetch = fetch.fetch;
|
|
@@ -88,6 +78,10 @@ Object.defineProperty(exports, 'redirect', {
|
|
|
88
78
|
enumerable: true,
|
|
89
79
|
get: function () { return serverRuntime.redirect; }
|
|
90
80
|
});
|
|
81
|
+
Object.defineProperty(exports, 'redirectDocument', {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
get: function () { return serverRuntime.redirectDocument; }
|
|
84
|
+
});
|
|
91
85
|
Object.defineProperty(exports, 'unstable_composeUploadHandlers', {
|
|
92
86
|
enumerable: true,
|
|
93
87
|
get: function () { return serverRuntime.unstable_composeUploadHandlers; }
|
|
@@ -19,4 +19,5 @@ interface FileSessionStorageOptions {
|
|
|
19
19
|
* @see https://remix.run/utils/sessions#createfilesessionstorage-node
|
|
20
20
|
*/
|
|
21
21
|
export declare function createFileSessionStorage<Data = SessionData, FlashData = Data>({ cookie, dir, }: FileSessionStorageOptions): SessionStorage<Data, FlashData>;
|
|
22
|
+
export declare function getFile(dir: string, id: string): string;
|
|
22
23
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/node
|
|
2
|
+
* @remix-run/node v2.0.0-pre.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
|
|
13
13
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
14
|
|
|
15
|
-
var crypto = require('crypto');
|
|
16
|
-
var
|
|
17
|
-
var path = require('path');
|
|
15
|
+
var crypto = require('node:crypto');
|
|
16
|
+
var node_fs = require('node:fs');
|
|
17
|
+
var path = require('node:path');
|
|
18
18
|
var implementations = require('../implementations.js');
|
|
19
19
|
|
|
20
20
|
function _interopNamespace(e) {
|
|
@@ -58,8 +58,8 @@ function createFileSessionStorage({
|
|
|
58
58
|
expires
|
|
59
59
|
});
|
|
60
60
|
while (true) {
|
|
61
|
-
// TODO: Once
|
|
62
|
-
// API's crypto.getRandomValues() function here instead.
|
|
61
|
+
// TODO: Once Node v19 is supported we should use the globally provided
|
|
62
|
+
// Web Crypto API's crypto.getRandomValues() function here instead.
|
|
63
63
|
let randomBytes = crypto__namespace.randomBytes(8);
|
|
64
64
|
// This storage manages an id space of 2^64 ids, which is far greater
|
|
65
65
|
// than the maximum number of files allowed on an NTFS or ext4 volume
|
|
@@ -68,10 +68,10 @@ function createFileSessionStorage({
|
|
|
68
68
|
let id = Buffer.from(randomBytes).toString("hex");
|
|
69
69
|
try {
|
|
70
70
|
let file = getFile(dir, id);
|
|
71
|
-
await
|
|
71
|
+
await node_fs.promises.mkdir(path__namespace.dirname(file), {
|
|
72
72
|
recursive: true
|
|
73
73
|
});
|
|
74
|
-
await
|
|
74
|
+
await node_fs.promises.writeFile(file, content, {
|
|
75
75
|
encoding: "utf-8",
|
|
76
76
|
flag: "wx"
|
|
77
77
|
});
|
|
@@ -84,7 +84,7 @@ function createFileSessionStorage({
|
|
|
84
84
|
async readData(id) {
|
|
85
85
|
try {
|
|
86
86
|
let file = getFile(dir, id);
|
|
87
|
-
let content = JSON.parse(await
|
|
87
|
+
let content = JSON.parse(await node_fs.promises.readFile(file, "utf-8"));
|
|
88
88
|
let data = content.data;
|
|
89
89
|
let expires = typeof content.expires === "string" ? new Date(content.expires) : null;
|
|
90
90
|
if (!expires || expires > new Date()) {
|
|
@@ -92,7 +92,7 @@ function createFileSessionStorage({
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
// Remove expired session data.
|
|
95
|
-
if (expires) await
|
|
95
|
+
if (expires) await node_fs.promises.unlink(file);
|
|
96
96
|
return null;
|
|
97
97
|
} catch (error) {
|
|
98
98
|
if (error.code !== "ENOENT") throw error;
|
|
@@ -105,10 +105,10 @@ function createFileSessionStorage({
|
|
|
105
105
|
expires
|
|
106
106
|
});
|
|
107
107
|
let file = getFile(dir, id);
|
|
108
|
-
await
|
|
108
|
+
await node_fs.promises.mkdir(path__namespace.dirname(file), {
|
|
109
109
|
recursive: true
|
|
110
110
|
});
|
|
111
|
-
await
|
|
111
|
+
await node_fs.promises.writeFile(file, content, "utf-8");
|
|
112
112
|
},
|
|
113
113
|
async deleteData(id) {
|
|
114
114
|
// Return early if the id is empty, otherwise we'll end up trying to
|
|
@@ -117,7 +117,7 @@ function createFileSessionStorage({
|
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
119
|
try {
|
|
120
|
-
await
|
|
120
|
+
await node_fs.promises.unlink(getFile(dir, id));
|
|
121
121
|
} catch (error) {
|
|
122
122
|
if (error.code !== "ENOENT") throw error;
|
|
123
123
|
}
|
|
@@ -133,3 +133,4 @@ function getFile(dir, id) {
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
exports.createFileSessionStorage = createFileSessionStorage;
|
|
136
|
+
exports.getFile = getFile;
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import type { Readable, Writable } from "stream";
|
|
3
|
+
import type { Readable, Writable } from "node:stream";
|
|
4
4
|
export declare function writeReadableStreamToWritable(stream: ReadableStream, writable: Writable): Promise<void>;
|
|
5
5
|
export declare function writeAsyncIterableToWritable(iterable: AsyncIterable<Uint8Array>, writable: Writable): Promise<void>;
|
|
6
6
|
export declare function readableStreamToString(stream: ReadableStream<Uint8Array>, encoding?: BufferEncoding): Promise<string>;
|
package/dist/stream.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/node
|
|
2
|
+
* @remix-run/node v2.0.0-pre.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -12,30 +12,26 @@
|
|
|
12
12
|
|
|
13
13
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var node_stream = require('node:stream');
|
|
16
16
|
|
|
17
17
|
async function writeReadableStreamToWritable(stream, writable) {
|
|
18
18
|
let reader = stream.getReader();
|
|
19
|
-
|
|
20
|
-
let {
|
|
21
|
-
done,
|
|
22
|
-
value
|
|
23
|
-
} = await reader.read();
|
|
24
|
-
if (done) {
|
|
25
|
-
writable.end();
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
writable.write(value);
|
|
29
|
-
|
|
30
|
-
// If the stream is flushable, flush it to allow streaming to continue.
|
|
31
|
-
let flushable = writable;
|
|
32
|
-
if (typeof flushable.flush === "function") {
|
|
33
|
-
flushable.flush();
|
|
34
|
-
}
|
|
35
|
-
await read();
|
|
36
|
-
}
|
|
19
|
+
let flushable = writable;
|
|
37
20
|
try {
|
|
38
|
-
|
|
21
|
+
while (true) {
|
|
22
|
+
let {
|
|
23
|
+
done,
|
|
24
|
+
value
|
|
25
|
+
} = await reader.read();
|
|
26
|
+
if (done) {
|
|
27
|
+
writable.end();
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
writable.write(value);
|
|
31
|
+
if (typeof flushable.flush === "function") {
|
|
32
|
+
flushable.flush();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
39
35
|
} catch (error) {
|
|
40
36
|
writable.destroy(error);
|
|
41
37
|
throw error;
|
|
@@ -55,19 +51,18 @@ async function writeAsyncIterableToWritable(iterable, writable) {
|
|
|
55
51
|
async function readableStreamToString(stream, encoding) {
|
|
56
52
|
let reader = stream.getReader();
|
|
57
53
|
let chunks = [];
|
|
58
|
-
|
|
54
|
+
while (true) {
|
|
59
55
|
let {
|
|
60
56
|
done,
|
|
61
57
|
value
|
|
62
58
|
} = await reader.read();
|
|
63
59
|
if (done) {
|
|
64
|
-
|
|
65
|
-
}
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
if (value) {
|
|
66
63
|
chunks.push(value);
|
|
67
64
|
}
|
|
68
|
-
await read();
|
|
69
65
|
}
|
|
70
|
-
await read();
|
|
71
66
|
return Buffer.concat(chunks).toString(encoding);
|
|
72
67
|
}
|
|
73
68
|
const createReadableStreamFromReadable = source => {
|
|
@@ -76,10 +71,10 @@ const createReadableStreamFromReadable = source => {
|
|
|
76
71
|
return stream;
|
|
77
72
|
};
|
|
78
73
|
class StreamPump {
|
|
79
|
-
constructor(stream
|
|
80
|
-
this.highWaterMark = stream
|
|
74
|
+
constructor(stream) {
|
|
75
|
+
this.highWaterMark = stream.readableHighWaterMark || new node_stream.Stream.Readable().readableHighWaterMark;
|
|
81
76
|
this.accumalatedSize = 0;
|
|
82
|
-
this.stream = stream
|
|
77
|
+
this.stream = stream;
|
|
83
78
|
this.enqueue = this.enqueue.bind(this);
|
|
84
79
|
this.error = this.error.bind(this);
|
|
85
80
|
this.close = this.close.bind(this);
|