@react-router/node 7.0.0-pre.1 → 7.0.0-pre.3

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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # `@remix-run/node`
2
2
 
3
+ ## 7.0.0-pre.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies:
8
+ - `react-router@7.0.0-pre.3`
9
+
10
+ ## 7.0.0-pre.2
11
+
12
+ ### Major Changes
13
+
14
+ - Drop support for Node 18, update minimum Node vestion to 20 ([#12171](https://github.com/remix-run/react-router/pull/12171))
15
+
16
+ - Remove `installGlobals()` as this should no longer be necessary
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies:
21
+ - `react-router@7.0.0-pre.2`
22
+
3
23
  ## 7.0.0-pre.1
4
24
 
5
25
  ### Patch Changes
@@ -0,0 +1,32 @@
1
+ import { SessionData, SessionStorage, SessionIdStorageStrategy } from 'react-router';
2
+ import { Writable, Readable } from 'node:stream';
3
+
4
+ interface FileSessionStorageOptions {
5
+ /**
6
+ * The Cookie used to store the session id on the client, or options used
7
+ * to automatically create one.
8
+ */
9
+ cookie?: SessionIdStorageStrategy["cookie"];
10
+ /**
11
+ * The directory to use to store session files.
12
+ */
13
+ dir: string;
14
+ }
15
+ /**
16
+ * Creates a SessionStorage that stores session data on a filesystem.
17
+ *
18
+ * The advantage of using this instead of cookie session storage is that
19
+ * files may contain much more data than cookies.
20
+ *
21
+ * @see https://remix.run/utils/sessions#createfilesessionstorage-node
22
+ */
23
+ declare function createFileSessionStorage<Data = SessionData, FlashData = Data>({ cookie, dir, }: FileSessionStorageOptions): SessionStorage<Data, FlashData>;
24
+
25
+ declare function writeReadableStreamToWritable(stream: ReadableStream, writable: Writable): Promise<void>;
26
+ declare function writeAsyncIterableToWritable(iterable: AsyncIterable<Uint8Array>, writable: Writable): Promise<void>;
27
+ declare function readableStreamToString(stream: ReadableStream<Uint8Array>, encoding?: BufferEncoding): Promise<string>;
28
+ declare const createReadableStreamFromReadable: (source: Readable & {
29
+ readableHighWaterMark?: number;
30
+ }) => ReadableStream<Uint8Array>;
31
+
32
+ export { createFileSessionStorage, createReadableStreamFromReadable, readableStreamToString, writeAsyncIterableToWritable, writeReadableStreamToWritable };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,32 @@
1
- export { installGlobals } from "./globals";
2
- export { createFileSessionStorage } from "./sessions/fileStorage";
3
- export { createReadableStreamFromReadable, readableStreamToString, writeAsyncIterableToWritable, writeReadableStreamToWritable, } from "./stream";
1
+ import { SessionData, SessionStorage, SessionIdStorageStrategy } from 'react-router';
2
+ import { Writable, Readable } from 'node:stream';
3
+
4
+ interface FileSessionStorageOptions {
5
+ /**
6
+ * The Cookie used to store the session id on the client, or options used
7
+ * to automatically create one.
8
+ */
9
+ cookie?: SessionIdStorageStrategy["cookie"];
10
+ /**
11
+ * The directory to use to store session files.
12
+ */
13
+ dir: string;
14
+ }
15
+ /**
16
+ * Creates a SessionStorage that stores session data on a filesystem.
17
+ *
18
+ * The advantage of using this instead of cookie session storage is that
19
+ * files may contain much more data than cookies.
20
+ *
21
+ * @see https://remix.run/utils/sessions#createfilesessionstorage-node
22
+ */
23
+ declare function createFileSessionStorage<Data = SessionData, FlashData = Data>({ cookie, dir, }: FileSessionStorageOptions): SessionStorage<Data, FlashData>;
24
+
25
+ declare function writeReadableStreamToWritable(stream: ReadableStream, writable: Writable): Promise<void>;
26
+ declare function writeAsyncIterableToWritable(iterable: AsyncIterable<Uint8Array>, writable: Writable): Promise<void>;
27
+ declare function readableStreamToString(stream: ReadableStream<Uint8Array>, encoding?: BufferEncoding): Promise<string>;
28
+ declare const createReadableStreamFromReadable: (source: Readable & {
29
+ readableHighWaterMark?: number;
30
+ }) => ReadableStream<Uint8Array>;
31
+
32
+ export { createFileSessionStorage, createReadableStreamFromReadable, readableStreamToString, writeAsyncIterableToWritable, writeReadableStreamToWritable };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/node v7.0.0-pre.1
2
+ * @react-router/node v7.0.0-pre.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -8,19 +8,243 @@
8
8
  *
9
9
  * @license MIT
10
10
  */
11
- 'use strict';
11
+ "use strict";
12
+ var __create = Object.create;
13
+ var __defProp = Object.defineProperty;
14
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
15
+ var __getOwnPropNames = Object.getOwnPropertyNames;
16
+ var __getProtoOf = Object.getPrototypeOf;
17
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
18
+ var __export = (target, all) => {
19
+ for (var name in all)
20
+ __defProp(target, name, { get: all[name], enumerable: true });
21
+ };
22
+ var __copyProps = (to, from, except, desc) => {
23
+ if (from && typeof from === "object" || typeof from === "function") {
24
+ for (let key of __getOwnPropNames(from))
25
+ if (!__hasOwnProp.call(to, key) && key !== except)
26
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
27
+ }
28
+ return to;
29
+ };
30
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
31
+ // If the importer is in node compatibility mode or this is not an ESM
32
+ // file that has been converted to a CommonJS file using a Babel-
33
+ // compatible transform (i.e. "__esModule" has not been set), then set
34
+ // "default" to the CommonJS "module.exports" for node compatibility.
35
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
36
+ mod
37
+ ));
38
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
12
39
 
13
- Object.defineProperty(exports, '__esModule', { value: true });
40
+ // index.ts
41
+ var react_router_node_exports = {};
42
+ __export(react_router_node_exports, {
43
+ createFileSessionStorage: () => createFileSessionStorage,
44
+ createReadableStreamFromReadable: () => createReadableStreamFromReadable,
45
+ readableStreamToString: () => readableStreamToString,
46
+ writeAsyncIterableToWritable: () => writeAsyncIterableToWritable,
47
+ writeReadableStreamToWritable: () => writeReadableStreamToWritable
48
+ });
49
+ module.exports = __toCommonJS(react_router_node_exports);
14
50
 
15
- var globals = require('./globals.js');
16
- var fileStorage = require('./sessions/fileStorage.js');
17
- var stream = require('./stream.js');
51
+ // sessions/fileStorage.ts
52
+ var import_node_fs = require("fs");
53
+ var path = __toESM(require("path"));
54
+ var import_react_router = require("react-router");
55
+ function createFileSessionStorage({
56
+ cookie,
57
+ dir
58
+ }) {
59
+ return (0, import_react_router.createSessionStorage)({
60
+ cookie,
61
+ async createData(data, expires) {
62
+ let content = JSON.stringify({ data, expires });
63
+ while (true) {
64
+ let randomBytes = crypto.getRandomValues(new Uint8Array(8));
65
+ let id = Buffer.from(randomBytes).toString("hex");
66
+ try {
67
+ let file = getFile(dir, id);
68
+ await import_node_fs.promises.mkdir(path.dirname(file), { recursive: true });
69
+ await import_node_fs.promises.writeFile(file, content, { encoding: "utf-8", flag: "wx" });
70
+ return id;
71
+ } catch (error) {
72
+ if (error.code !== "EEXIST") throw error;
73
+ }
74
+ }
75
+ },
76
+ async readData(id) {
77
+ try {
78
+ let file = getFile(dir, id);
79
+ let content = JSON.parse(await import_node_fs.promises.readFile(file, "utf-8"));
80
+ let data = content.data;
81
+ let expires = typeof content.expires === "string" ? new Date(content.expires) : null;
82
+ if (!expires || expires > /* @__PURE__ */ new Date()) {
83
+ return data;
84
+ }
85
+ if (expires) await import_node_fs.promises.unlink(file);
86
+ return null;
87
+ } catch (error) {
88
+ if (error.code !== "ENOENT") throw error;
89
+ return null;
90
+ }
91
+ },
92
+ async updateData(id, data, expires) {
93
+ let content = JSON.stringify({ data, expires });
94
+ let file = getFile(dir, id);
95
+ await import_node_fs.promises.mkdir(path.dirname(file), { recursive: true });
96
+ await import_node_fs.promises.writeFile(file, content, "utf-8");
97
+ },
98
+ async deleteData(id) {
99
+ if (!id) {
100
+ return;
101
+ }
102
+ try {
103
+ await import_node_fs.promises.unlink(getFile(dir, id));
104
+ } catch (error) {
105
+ if (error.code !== "ENOENT") throw error;
106
+ }
107
+ }
108
+ });
109
+ }
110
+ function getFile(dir, id) {
111
+ return path.join(dir, id.slice(0, 4), id.slice(4));
112
+ }
18
113
 
19
-
20
-
21
- exports.installGlobals = globals.installGlobals;
22
- exports.createFileSessionStorage = fileStorage.createFileSessionStorage;
23
- exports.createReadableStreamFromReadable = stream.createReadableStreamFromReadable;
24
- exports.readableStreamToString = stream.readableStreamToString;
25
- exports.writeAsyncIterableToWritable = stream.writeAsyncIterableToWritable;
26
- exports.writeReadableStreamToWritable = stream.writeReadableStreamToWritable;
114
+ // stream.ts
115
+ var import_node_stream = require("stream");
116
+ async function writeReadableStreamToWritable(stream, writable) {
117
+ let reader = stream.getReader();
118
+ let flushable = writable;
119
+ try {
120
+ while (true) {
121
+ let { done, value } = await reader.read();
122
+ if (done) {
123
+ writable.end();
124
+ break;
125
+ }
126
+ writable.write(value);
127
+ if (typeof flushable.flush === "function") {
128
+ flushable.flush();
129
+ }
130
+ }
131
+ } catch (error) {
132
+ writable.destroy(error);
133
+ throw error;
134
+ }
135
+ }
136
+ async function writeAsyncIterableToWritable(iterable, writable) {
137
+ try {
138
+ for await (let chunk of iterable) {
139
+ writable.write(chunk);
140
+ }
141
+ writable.end();
142
+ } catch (error) {
143
+ writable.destroy(error);
144
+ throw error;
145
+ }
146
+ }
147
+ async function readableStreamToString(stream, encoding) {
148
+ let reader = stream.getReader();
149
+ let chunks = [];
150
+ while (true) {
151
+ let { done, value } = await reader.read();
152
+ if (done) {
153
+ break;
154
+ }
155
+ if (value) {
156
+ chunks.push(value);
157
+ }
158
+ }
159
+ return Buffer.concat(chunks).toString(encoding);
160
+ }
161
+ var createReadableStreamFromReadable = (source) => {
162
+ let pump = new StreamPump(source);
163
+ let stream = new ReadableStream(pump, pump);
164
+ return stream;
165
+ };
166
+ var StreamPump = class {
167
+ highWaterMark;
168
+ accumalatedSize;
169
+ stream;
170
+ controller;
171
+ constructor(stream) {
172
+ this.highWaterMark = stream.readableHighWaterMark || new import_node_stream.Stream.Readable().readableHighWaterMark;
173
+ this.accumalatedSize = 0;
174
+ this.stream = stream;
175
+ this.enqueue = this.enqueue.bind(this);
176
+ this.error = this.error.bind(this);
177
+ this.close = this.close.bind(this);
178
+ }
179
+ size(chunk) {
180
+ return chunk?.byteLength || 0;
181
+ }
182
+ start(controller) {
183
+ this.controller = controller;
184
+ this.stream.on("data", this.enqueue);
185
+ this.stream.once("error", this.error);
186
+ this.stream.once("end", this.close);
187
+ this.stream.once("close", this.close);
188
+ }
189
+ pull() {
190
+ this.resume();
191
+ }
192
+ cancel(reason) {
193
+ if (this.stream.destroy) {
194
+ this.stream.destroy(reason);
195
+ }
196
+ this.stream.off("data", this.enqueue);
197
+ this.stream.off("error", this.error);
198
+ this.stream.off("end", this.close);
199
+ this.stream.off("close", this.close);
200
+ }
201
+ enqueue(chunk) {
202
+ if (this.controller) {
203
+ try {
204
+ let bytes = chunk instanceof Uint8Array ? chunk : Buffer.from(chunk);
205
+ let available = (this.controller.desiredSize || 0) - bytes.byteLength;
206
+ this.controller.enqueue(bytes);
207
+ if (available <= 0) {
208
+ this.pause();
209
+ }
210
+ } catch (error) {
211
+ this.controller.error(
212
+ new Error(
213
+ "Could not create Buffer, chunk must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object"
214
+ )
215
+ );
216
+ this.cancel();
217
+ }
218
+ }
219
+ }
220
+ pause() {
221
+ if (this.stream.pause) {
222
+ this.stream.pause();
223
+ }
224
+ }
225
+ resume() {
226
+ if (this.stream.readable && this.stream.resume) {
227
+ this.stream.resume();
228
+ }
229
+ }
230
+ close() {
231
+ if (this.controller) {
232
+ this.controller.close();
233
+ delete this.controller;
234
+ }
235
+ }
236
+ error(error) {
237
+ if (this.controller) {
238
+ this.controller.error(error);
239
+ delete this.controller;
240
+ }
241
+ }
242
+ };
243
+ // Annotate the CommonJS export names for ESM import in node:
244
+ 0 && (module.exports = {
245
+ createFileSessionStorage,
246
+ createReadableStreamFromReadable,
247
+ readableStreamToString,
248
+ writeAsyncIterableToWritable,
249
+ writeReadableStreamToWritable
250
+ });
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/node v7.0.0-pre.1
2
+ * @react-router/node v7.0.0-pre.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -8,6 +8,203 @@
8
8
  *
9
9
  * @license MIT
10
10
  */
11
- export { installGlobals } from './globals.mjs';
12
- export { createFileSessionStorage } from './sessions/fileStorage.mjs';
13
- export { createReadableStreamFromReadable, readableStreamToString, writeAsyncIterableToWritable, writeReadableStreamToWritable } from './stream.mjs';
11
+
12
+ // sessions/fileStorage.ts
13
+ import { promises as fsp } from "node:fs";
14
+ import * as path from "node:path";
15
+ import { createSessionStorage } from "react-router";
16
+ function createFileSessionStorage({
17
+ cookie,
18
+ dir
19
+ }) {
20
+ return createSessionStorage({
21
+ cookie,
22
+ async createData(data, expires) {
23
+ let content = JSON.stringify({ data, expires });
24
+ while (true) {
25
+ let randomBytes = crypto.getRandomValues(new Uint8Array(8));
26
+ let id = Buffer.from(randomBytes).toString("hex");
27
+ try {
28
+ let file = getFile(dir, id);
29
+ await fsp.mkdir(path.dirname(file), { recursive: true });
30
+ await fsp.writeFile(file, content, { encoding: "utf-8", flag: "wx" });
31
+ return id;
32
+ } catch (error) {
33
+ if (error.code !== "EEXIST") throw error;
34
+ }
35
+ }
36
+ },
37
+ async readData(id) {
38
+ try {
39
+ let file = getFile(dir, id);
40
+ let content = JSON.parse(await fsp.readFile(file, "utf-8"));
41
+ let data = content.data;
42
+ let expires = typeof content.expires === "string" ? new Date(content.expires) : null;
43
+ if (!expires || expires > /* @__PURE__ */ new Date()) {
44
+ return data;
45
+ }
46
+ if (expires) await fsp.unlink(file);
47
+ return null;
48
+ } catch (error) {
49
+ if (error.code !== "ENOENT") throw error;
50
+ return null;
51
+ }
52
+ },
53
+ async updateData(id, data, expires) {
54
+ let content = JSON.stringify({ data, expires });
55
+ let file = getFile(dir, id);
56
+ await fsp.mkdir(path.dirname(file), { recursive: true });
57
+ await fsp.writeFile(file, content, "utf-8");
58
+ },
59
+ async deleteData(id) {
60
+ if (!id) {
61
+ return;
62
+ }
63
+ try {
64
+ await fsp.unlink(getFile(dir, id));
65
+ } catch (error) {
66
+ if (error.code !== "ENOENT") throw error;
67
+ }
68
+ }
69
+ });
70
+ }
71
+ function getFile(dir, id) {
72
+ return path.join(dir, id.slice(0, 4), id.slice(4));
73
+ }
74
+
75
+ // stream.ts
76
+ import { Stream } from "node:stream";
77
+ async function writeReadableStreamToWritable(stream, writable) {
78
+ let reader = stream.getReader();
79
+ let flushable = writable;
80
+ try {
81
+ while (true) {
82
+ let { done, value } = await reader.read();
83
+ if (done) {
84
+ writable.end();
85
+ break;
86
+ }
87
+ writable.write(value);
88
+ if (typeof flushable.flush === "function") {
89
+ flushable.flush();
90
+ }
91
+ }
92
+ } catch (error) {
93
+ writable.destroy(error);
94
+ throw error;
95
+ }
96
+ }
97
+ async function writeAsyncIterableToWritable(iterable, writable) {
98
+ try {
99
+ for await (let chunk of iterable) {
100
+ writable.write(chunk);
101
+ }
102
+ writable.end();
103
+ } catch (error) {
104
+ writable.destroy(error);
105
+ throw error;
106
+ }
107
+ }
108
+ async function readableStreamToString(stream, encoding) {
109
+ let reader = stream.getReader();
110
+ let chunks = [];
111
+ while (true) {
112
+ let { done, value } = await reader.read();
113
+ if (done) {
114
+ break;
115
+ }
116
+ if (value) {
117
+ chunks.push(value);
118
+ }
119
+ }
120
+ return Buffer.concat(chunks).toString(encoding);
121
+ }
122
+ var createReadableStreamFromReadable = (source) => {
123
+ let pump = new StreamPump(source);
124
+ let stream = new ReadableStream(pump, pump);
125
+ return stream;
126
+ };
127
+ var StreamPump = class {
128
+ highWaterMark;
129
+ accumalatedSize;
130
+ stream;
131
+ controller;
132
+ constructor(stream) {
133
+ this.highWaterMark = stream.readableHighWaterMark || new Stream.Readable().readableHighWaterMark;
134
+ this.accumalatedSize = 0;
135
+ this.stream = stream;
136
+ this.enqueue = this.enqueue.bind(this);
137
+ this.error = this.error.bind(this);
138
+ this.close = this.close.bind(this);
139
+ }
140
+ size(chunk) {
141
+ return chunk?.byteLength || 0;
142
+ }
143
+ start(controller) {
144
+ this.controller = controller;
145
+ this.stream.on("data", this.enqueue);
146
+ this.stream.once("error", this.error);
147
+ this.stream.once("end", this.close);
148
+ this.stream.once("close", this.close);
149
+ }
150
+ pull() {
151
+ this.resume();
152
+ }
153
+ cancel(reason) {
154
+ if (this.stream.destroy) {
155
+ this.stream.destroy(reason);
156
+ }
157
+ this.stream.off("data", this.enqueue);
158
+ this.stream.off("error", this.error);
159
+ this.stream.off("end", this.close);
160
+ this.stream.off("close", this.close);
161
+ }
162
+ enqueue(chunk) {
163
+ if (this.controller) {
164
+ try {
165
+ let bytes = chunk instanceof Uint8Array ? chunk : Buffer.from(chunk);
166
+ let available = (this.controller.desiredSize || 0) - bytes.byteLength;
167
+ this.controller.enqueue(bytes);
168
+ if (available <= 0) {
169
+ this.pause();
170
+ }
171
+ } catch (error) {
172
+ this.controller.error(
173
+ new Error(
174
+ "Could not create Buffer, chunk must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object"
175
+ )
176
+ );
177
+ this.cancel();
178
+ }
179
+ }
180
+ }
181
+ pause() {
182
+ if (this.stream.pause) {
183
+ this.stream.pause();
184
+ }
185
+ }
186
+ resume() {
187
+ if (this.stream.readable && this.stream.resume) {
188
+ this.stream.resume();
189
+ }
190
+ }
191
+ close() {
192
+ if (this.controller) {
193
+ this.controller.close();
194
+ delete this.controller;
195
+ }
196
+ }
197
+ error(error) {
198
+ if (this.controller) {
199
+ this.controller.error(error);
200
+ delete this.controller;
201
+ }
202
+ }
203
+ };
204
+ export {
205
+ createFileSessionStorage,
206
+ createReadableStreamFromReadable,
207
+ readableStreamToString,
208
+ writeAsyncIterableToWritable,
209
+ writeReadableStreamToWritable
210
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-router/node",
3
- "version": "7.0.0-pre.1",
3
+ "version": "7.0.0-pre.3",
4
4
  "description": "Node.js platform abstractions for React Router",
5
5
  "bugs": {
6
6
  "url": "https://github.com/remix-run/react-router/issues"
@@ -11,18 +11,38 @@
11
11
  "directory": "packages/react-router-node"
12
12
  },
13
13
  "license": "MIT",
14
+ "types": "dist/index.d.ts",
14
15
  "main": "dist/index.js",
15
- "typings": "dist/index.d.ts",
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/index.d.ts",
19
- "import": "./dist/index.mjs",
20
- "require": "./dist/index.js"
18
+ "node": {
19
+ "types": "./dist/index.d.ts",
20
+ "module-sync": "./dist/index.mjs",
21
+ "default": "./dist/index.js"
22
+ },
23
+ "import": {
24
+ "types": "./dist/index.d.mts",
25
+ "default": "./dist/index.mjs"
26
+ },
27
+ "default": {
28
+ "types": "./dist/index.d.ts",
29
+ "default": "./dist/index.js"
30
+ }
21
31
  },
22
32
  "./install": {
23
- "types": "./dist/install.d.ts",
24
- "import": "./dist/install.mjs",
25
- "require": "./dist/install.js"
33
+ "node": {
34
+ "types": "./dist/install.d.ts",
35
+ "module-sync": "./dist/install.mjs",
36
+ "default": "./dist/install.js"
37
+ },
38
+ "import": {
39
+ "types": "./dist/install.d.mts",
40
+ "default": "./dist/install.mjs"
41
+ },
42
+ "default": {
43
+ "types": "./dist/install.d.ts",
44
+ "default": "./dist/install.js"
45
+ }
26
46
  },
27
47
  "./package.json": "./package.json"
28
48
  },
@@ -30,6 +50,20 @@
30
50
  "./dist/install.js",
31
51
  "./dist/install.mjs"
32
52
  ],
53
+ "wireit": {
54
+ "build": {
55
+ "command": "tsup",
56
+ "files": [
57
+ "sessions/**",
58
+ "*.ts",
59
+ "tsconfig.json",
60
+ "package.json"
61
+ ],
62
+ "output": [
63
+ "dist/**"
64
+ ]
65
+ }
66
+ },
33
67
  "dependencies": {
34
68
  "@web3-storage/multipart-parser": "^1.0.0",
35
69
  "source-map-support": "^0.5.21",
@@ -38,12 +72,14 @@
38
72
  },
39
73
  "devDependencies": {
40
74
  "@types/source-map-support": "^0.5.4",
75
+ "tsup": "^8.3.0",
41
76
  "typescript": "^5.1.6",
42
- "react-router": "7.0.0-pre.1"
77
+ "wireit": "0.14.9",
78
+ "react-router": "7.0.0-pre.3"
43
79
  },
44
80
  "peerDependencies": {
45
81
  "typescript": "^5.1.0",
46
- "react-router": "7.0.0-pre.1"
82
+ "react-router": "7.0.0-pre.3"
47
83
  },
48
84
  "peerDependenciesMeta": {
49
85
  "typescript": {
@@ -51,7 +87,7 @@
51
87
  }
52
88
  },
53
89
  "engines": {
54
- "node": ">=18.0.0"
90
+ "node": ">=20.0.0"
55
91
  },
56
92
  "files": [
57
93
  "dist/",
@@ -63,6 +99,6 @@
63
99
  "README.md"
64
100
  ],
65
101
  "scripts": {
66
- "tsc": "tsc"
102
+ "build": "wireit"
67
103
  }
68
104
  }
package/dist/globals.d.ts DELETED
@@ -1,24 +0,0 @@
1
- /// <reference types="node" />
2
- import { webcrypto as nodeWebCrypto } from "node:crypto";
3
- declare global {
4
- namespace NodeJS {
5
- interface ProcessEnv {
6
- NODE_ENV: "development" | "production" | "test";
7
- }
8
- interface Global {
9
- File: typeof File;
10
- Headers: typeof Headers;
11
- Request: typeof Request;
12
- Response: typeof Response;
13
- fetch: typeof fetch;
14
- FormData: typeof FormData;
15
- ReadableStream: typeof ReadableStream;
16
- WritableStream: typeof WritableStream;
17
- crypto: typeof nodeWebCrypto;
18
- }
19
- }
20
- interface RequestInit {
21
- duplex?: "half";
22
- }
23
- }
24
- export declare function installGlobals(): void;
package/dist/globals.js DELETED
@@ -1,36 +0,0 @@
1
- /**
2
- * @react-router/node v7.0.0-pre.1
3
- *
4
- * Copyright (c) Remix Software Inc.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- 'use strict';
12
-
13
- Object.defineProperty(exports, '__esModule', { value: true });
14
-
15
- var undici = require('undici');
16
- var node_crypto = require('node:crypto');
17
-
18
- function installGlobals() {
19
- global.File = undici.File;
20
- // @ts-ignore - this shows as an error in VSCode but is not an error via TSC so we can't use `ts-expect-error`
21
- global.Headers = undici.Headers;
22
- // @ts-expect-error - overriding globals
23
- global.Request = undici.Request;
24
- // @ts-expect-error - overriding globals
25
- global.Response = undici.Response;
26
- // @ts-expect-error - overriding globals
27
- global.fetch = undici.fetch;
28
- // @ts-expect-error - overriding globals
29
- global.FormData = undici.FormData;
30
- if (!global.crypto) {
31
- // @ts-expect-error - overriding globals
32
- global.crypto = node_crypto.webcrypto;
33
- }
34
- }
35
-
36
- exports.installGlobals = installGlobals;
package/dist/globals.mjs DELETED
@@ -1,32 +0,0 @@
1
- /**
2
- * @react-router/node v7.0.0-pre.1
3
- *
4
- * Copyright (c) Remix Software Inc.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- import { File, Headers, Request, Response, fetch, FormData } from 'undici';
12
- import { webcrypto } from 'node:crypto';
13
-
14
- function installGlobals() {
15
- global.File = File;
16
- // @ts-ignore - this shows as an error in VSCode but is not an error via TSC so we can't use `ts-expect-error`
17
- global.Headers = Headers;
18
- // @ts-expect-error - overriding globals
19
- global.Request = Request;
20
- // @ts-expect-error - overriding globals
21
- global.Response = Response;
22
- // @ts-expect-error - overriding globals
23
- global.fetch = fetch;
24
- // @ts-expect-error - overriding globals
25
- global.FormData = FormData;
26
- if (!global.crypto) {
27
- // @ts-expect-error - overriding globals
28
- global.crypto = webcrypto;
29
- }
30
- }
31
-
32
- export { installGlobals };
package/dist/install.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/install.js DELETED
@@ -1,15 +0,0 @@
1
- /**
2
- * @react-router/node v7.0.0-pre.1
3
- *
4
- * Copyright (c) Remix Software Inc.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- 'use strict';
12
-
13
- var globals = require('./globals.js');
14
-
15
- globals.installGlobals();
package/dist/install.mjs DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * @react-router/node v7.0.0-pre.1
3
- *
4
- * Copyright (c) Remix Software Inc.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- import { installGlobals } from './globals.mjs';
12
-
13
- installGlobals();
@@ -1,23 +0,0 @@
1
- import type { SessionStorage, SessionIdStorageStrategy, SessionData } from "react-router";
2
- interface FileSessionStorageOptions {
3
- /**
4
- * The Cookie used to store the session id on the client, or options used
5
- * to automatically create one.
6
- */
7
- cookie?: SessionIdStorageStrategy["cookie"];
8
- /**
9
- * The directory to use to store session files.
10
- */
11
- dir: string;
12
- }
13
- /**
14
- * Creates a SessionStorage that stores session data on a filesystem.
15
- *
16
- * The advantage of using this instead of cookie session storage is that
17
- * files may contain much more data than cookies.
18
- *
19
- * @see https://remix.run/utils/sessions#createfilesessionstorage-node
20
- */
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;
23
- export {};
@@ -1,132 +0,0 @@
1
- /**
2
- * @react-router/node v7.0.0-pre.1
3
- *
4
- * Copyright (c) Remix Software Inc.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- 'use strict';
12
-
13
- Object.defineProperty(exports, '__esModule', { value: true });
14
-
15
- var node_fs = require('node:fs');
16
- var path = require('node:path');
17
- var reactRouter = require('react-router');
18
-
19
- function _interopNamespace(e) {
20
- if (e && e.__esModule) return e;
21
- var n = Object.create(null);
22
- if (e) {
23
- Object.keys(e).forEach(function (k) {
24
- if (k !== 'default') {
25
- var d = Object.getOwnPropertyDescriptor(e, k);
26
- Object.defineProperty(n, k, d.get ? d : {
27
- enumerable: true,
28
- get: function () { return e[k]; }
29
- });
30
- }
31
- });
32
- }
33
- n["default"] = e;
34
- return Object.freeze(n);
35
- }
36
-
37
- var path__namespace = /*#__PURE__*/_interopNamespace(path);
38
-
39
- /**
40
- * Creates a SessionStorage that stores session data on a filesystem.
41
- *
42
- * The advantage of using this instead of cookie session storage is that
43
- * files may contain much more data than cookies.
44
- *
45
- * @see https://remix.run/utils/sessions#createfilesessionstorage-node
46
- */
47
- function createFileSessionStorage({
48
- cookie,
49
- dir
50
- }) {
51
- return reactRouter.createSessionStorage({
52
- cookie,
53
- async createData(data, expires) {
54
- let content = JSON.stringify({
55
- data,
56
- expires
57
- });
58
- while (true) {
59
- let randomBytes = crypto.getRandomValues(new Uint8Array(8));
60
- // This storage manages an id space of 2^64 ids, which is far greater
61
- // than the maximum number of files allowed on an NTFS or ext4 volume
62
- // (2^32). However, the larger id space should help to avoid collisions
63
- // with existing ids when creating new sessions, which speeds things up.
64
- let id = Buffer.from(randomBytes).toString("hex");
65
- try {
66
- let file = getFile(dir, id);
67
- await node_fs.promises.mkdir(path__namespace.dirname(file), {
68
- recursive: true
69
- });
70
- await node_fs.promises.writeFile(file, content, {
71
- encoding: "utf-8",
72
- flag: "wx"
73
- });
74
- return id;
75
- } catch (error) {
76
- if (error.code !== "EEXIST") throw error;
77
- }
78
- }
79
- },
80
- async readData(id) {
81
- try {
82
- let file = getFile(dir, id);
83
- let content = JSON.parse(await node_fs.promises.readFile(file, "utf-8"));
84
- let data = content.data;
85
- let expires = typeof content.expires === "string" ? new Date(content.expires) : null;
86
- if (!expires || expires > new Date()) {
87
- return data;
88
- }
89
-
90
- // Remove expired session data.
91
- if (expires) await node_fs.promises.unlink(file);
92
- return null;
93
- } catch (error) {
94
- if (error.code !== "ENOENT") throw error;
95
- return null;
96
- }
97
- },
98
- async updateData(id, data, expires) {
99
- let content = JSON.stringify({
100
- data,
101
- expires
102
- });
103
- let file = getFile(dir, id);
104
- await node_fs.promises.mkdir(path__namespace.dirname(file), {
105
- recursive: true
106
- });
107
- await node_fs.promises.writeFile(file, content, "utf-8");
108
- },
109
- async deleteData(id) {
110
- // Return early if the id is empty, otherwise we'll end up trying to
111
- // unlink the dir, which will cause the EPERM error.
112
- if (!id) {
113
- return;
114
- }
115
- try {
116
- await node_fs.promises.unlink(getFile(dir, id));
117
- } catch (error) {
118
- if (error.code !== "ENOENT") throw error;
119
- }
120
- }
121
- });
122
- }
123
- function getFile(dir, id) {
124
- // Divide the session id up into a directory (first 2 bytes) and filename
125
- // (remaining 6 bytes) to reduce the chance of having very large directories,
126
- // which should speed up file access. This is a maximum of 2^16 directories,
127
- // each with 2^48 files.
128
- return path__namespace.join(dir, id.slice(0, 4), id.slice(4));
129
- }
130
-
131
- exports.createFileSessionStorage = createFileSessionStorage;
132
- exports.getFile = getFile;
@@ -1,106 +0,0 @@
1
- /**
2
- * @react-router/node v7.0.0-pre.1
3
- *
4
- * Copyright (c) Remix Software Inc.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- import { promises } from 'node:fs';
12
- import * as path from 'node:path';
13
- import { createSessionStorage } from 'react-router';
14
-
15
- /**
16
- * Creates a SessionStorage that stores session data on a filesystem.
17
- *
18
- * The advantage of using this instead of cookie session storage is that
19
- * files may contain much more data than cookies.
20
- *
21
- * @see https://remix.run/utils/sessions#createfilesessionstorage-node
22
- */
23
- function createFileSessionStorage({
24
- cookie,
25
- dir
26
- }) {
27
- return createSessionStorage({
28
- cookie,
29
- async createData(data, expires) {
30
- let content = JSON.stringify({
31
- data,
32
- expires
33
- });
34
- while (true) {
35
- let randomBytes = crypto.getRandomValues(new Uint8Array(8));
36
- // This storage manages an id space of 2^64 ids, which is far greater
37
- // than the maximum number of files allowed on an NTFS or ext4 volume
38
- // (2^32). However, the larger id space should help to avoid collisions
39
- // with existing ids when creating new sessions, which speeds things up.
40
- let id = Buffer.from(randomBytes).toString("hex");
41
- try {
42
- let file = getFile(dir, id);
43
- await promises.mkdir(path.dirname(file), {
44
- recursive: true
45
- });
46
- await promises.writeFile(file, content, {
47
- encoding: "utf-8",
48
- flag: "wx"
49
- });
50
- return id;
51
- } catch (error) {
52
- if (error.code !== "EEXIST") throw error;
53
- }
54
- }
55
- },
56
- async readData(id) {
57
- try {
58
- let file = getFile(dir, id);
59
- let content = JSON.parse(await promises.readFile(file, "utf-8"));
60
- let data = content.data;
61
- let expires = typeof content.expires === "string" ? new Date(content.expires) : null;
62
- if (!expires || expires > new Date()) {
63
- return data;
64
- }
65
- // Remove expired session data.
66
- if (expires) await promises.unlink(file);
67
- return null;
68
- } catch (error) {
69
- if (error.code !== "ENOENT") throw error;
70
- return null;
71
- }
72
- },
73
- async updateData(id, data, expires) {
74
- let content = JSON.stringify({
75
- data,
76
- expires
77
- });
78
- let file = getFile(dir, id);
79
- await promises.mkdir(path.dirname(file), {
80
- recursive: true
81
- });
82
- await promises.writeFile(file, content, "utf-8");
83
- },
84
- async deleteData(id) {
85
- // Return early if the id is empty, otherwise we'll end up trying to
86
- // unlink the dir, which will cause the EPERM error.
87
- if (!id) {
88
- return;
89
- }
90
- try {
91
- await promises.unlink(getFile(dir, id));
92
- } catch (error) {
93
- if (error.code !== "ENOENT") throw error;
94
- }
95
- }
96
- });
97
- }
98
- function getFile(dir, id) {
99
- // Divide the session id up into a directory (first 2 bytes) and filename
100
- // (remaining 6 bytes) to reduce the chance of having very large directories,
101
- // which should speed up file access. This is a maximum of 2^16 directories,
102
- // each with 2^48 files.
103
- return path.join(dir, id.slice(0, 4), id.slice(4));
104
- }
105
-
106
- export { createFileSessionStorage, getFile };
package/dist/stream.d.ts DELETED
@@ -1,9 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import type { Readable, Writable } from "node:stream";
4
- export declare function writeReadableStreamToWritable(stream: ReadableStream, writable: Writable): Promise<void>;
5
- export declare function writeAsyncIterableToWritable(iterable: AsyncIterable<Uint8Array>, writable: Writable): Promise<void>;
6
- export declare function readableStreamToString(stream: ReadableStream<Uint8Array>, encoding?: BufferEncoding): Promise<string>;
7
- export declare const createReadableStreamFromReadable: (source: Readable & {
8
- readableHighWaterMark?: number;
9
- }) => ReadableStream<Uint8Array>;
package/dist/stream.js DELETED
@@ -1,146 +0,0 @@
1
- /**
2
- * @react-router/node v7.0.0-pre.1
3
- *
4
- * Copyright (c) Remix Software Inc.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- 'use strict';
12
-
13
- Object.defineProperty(exports, '__esModule', { value: true });
14
-
15
- var node_stream = require('node:stream');
16
-
17
- async function writeReadableStreamToWritable(stream, writable) {
18
- let reader = stream.getReader();
19
- let flushable = writable;
20
- try {
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
- }
35
- } catch (error) {
36
- writable.destroy(error);
37
- throw error;
38
- }
39
- }
40
- async function writeAsyncIterableToWritable(iterable, writable) {
41
- try {
42
- for await (let chunk of iterable) {
43
- writable.write(chunk);
44
- }
45
- writable.end();
46
- } catch (error) {
47
- writable.destroy(error);
48
- throw error;
49
- }
50
- }
51
- async function readableStreamToString(stream, encoding) {
52
- let reader = stream.getReader();
53
- let chunks = [];
54
- while (true) {
55
- let {
56
- done,
57
- value
58
- } = await reader.read();
59
- if (done) {
60
- break;
61
- }
62
- if (value) {
63
- chunks.push(value);
64
- }
65
- }
66
- return Buffer.concat(chunks).toString(encoding);
67
- }
68
- const createReadableStreamFromReadable = source => {
69
- let pump = new StreamPump(source);
70
- let stream = new ReadableStream(pump, pump);
71
- return stream;
72
- };
73
- class StreamPump {
74
- constructor(stream) {
75
- this.highWaterMark = stream.readableHighWaterMark || new node_stream.Stream.Readable().readableHighWaterMark;
76
- this.accumalatedSize = 0;
77
- this.stream = stream;
78
- this.enqueue = this.enqueue.bind(this);
79
- this.error = this.error.bind(this);
80
- this.close = this.close.bind(this);
81
- }
82
- size(chunk) {
83
- return (chunk === null || chunk === void 0 ? void 0 : chunk.byteLength) || 0;
84
- }
85
- start(controller) {
86
- this.controller = controller;
87
- this.stream.on("data", this.enqueue);
88
- this.stream.once("error", this.error);
89
- this.stream.once("end", this.close);
90
- this.stream.once("close", this.close);
91
- }
92
- pull() {
93
- this.resume();
94
- }
95
- cancel(reason) {
96
- if (this.stream.destroy) {
97
- this.stream.destroy(reason);
98
- }
99
- this.stream.off("data", this.enqueue);
100
- this.stream.off("error", this.error);
101
- this.stream.off("end", this.close);
102
- this.stream.off("close", this.close);
103
- }
104
- enqueue(chunk) {
105
- if (this.controller) {
106
- try {
107
- let bytes = chunk instanceof Uint8Array ? chunk : Buffer.from(chunk);
108
- let available = (this.controller.desiredSize || 0) - bytes.byteLength;
109
- this.controller.enqueue(bytes);
110
- if (available <= 0) {
111
- this.pause();
112
- }
113
- } catch (error) {
114
- this.controller.error(new Error("Could not create Buffer, chunk must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object"));
115
- this.cancel();
116
- }
117
- }
118
- }
119
- pause() {
120
- if (this.stream.pause) {
121
- this.stream.pause();
122
- }
123
- }
124
- resume() {
125
- if (this.stream.readable && this.stream.resume) {
126
- this.stream.resume();
127
- }
128
- }
129
- close() {
130
- if (this.controller) {
131
- this.controller.close();
132
- delete this.controller;
133
- }
134
- }
135
- error(error) {
136
- if (this.controller) {
137
- this.controller.error(error);
138
- delete this.controller;
139
- }
140
- }
141
- }
142
-
143
- exports.createReadableStreamFromReadable = createReadableStreamFromReadable;
144
- exports.readableStreamToString = readableStreamToString;
145
- exports.writeAsyncIterableToWritable = writeAsyncIterableToWritable;
146
- exports.writeReadableStreamToWritable = writeReadableStreamToWritable;
package/dist/stream.mjs DELETED
@@ -1,139 +0,0 @@
1
- /**
2
- * @react-router/node v7.0.0-pre.1
3
- *
4
- * Copyright (c) Remix Software Inc.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- import { Stream } from 'node:stream';
12
-
13
- async function writeReadableStreamToWritable(stream, writable) {
14
- let reader = stream.getReader();
15
- let flushable = writable;
16
- try {
17
- while (true) {
18
- let {
19
- done,
20
- value
21
- } = await reader.read();
22
- if (done) {
23
- writable.end();
24
- break;
25
- }
26
- writable.write(value);
27
- if (typeof flushable.flush === "function") {
28
- flushable.flush();
29
- }
30
- }
31
- } catch (error) {
32
- writable.destroy(error);
33
- throw error;
34
- }
35
- }
36
- async function writeAsyncIterableToWritable(iterable, writable) {
37
- try {
38
- for await (let chunk of iterable) {
39
- writable.write(chunk);
40
- }
41
- writable.end();
42
- } catch (error) {
43
- writable.destroy(error);
44
- throw error;
45
- }
46
- }
47
- async function readableStreamToString(stream, encoding) {
48
- let reader = stream.getReader();
49
- let chunks = [];
50
- while (true) {
51
- let {
52
- done,
53
- value
54
- } = await reader.read();
55
- if (done) {
56
- break;
57
- }
58
- if (value) {
59
- chunks.push(value);
60
- }
61
- }
62
- return Buffer.concat(chunks).toString(encoding);
63
- }
64
- const createReadableStreamFromReadable = source => {
65
- let pump = new StreamPump(source);
66
- let stream = new ReadableStream(pump, pump);
67
- return stream;
68
- };
69
- class StreamPump {
70
- constructor(stream) {
71
- this.highWaterMark = stream.readableHighWaterMark || new Stream.Readable().readableHighWaterMark;
72
- this.accumalatedSize = 0;
73
- this.stream = stream;
74
- this.enqueue = this.enqueue.bind(this);
75
- this.error = this.error.bind(this);
76
- this.close = this.close.bind(this);
77
- }
78
- size(chunk) {
79
- return (chunk === null || chunk === void 0 ? void 0 : chunk.byteLength) || 0;
80
- }
81
- start(controller) {
82
- this.controller = controller;
83
- this.stream.on("data", this.enqueue);
84
- this.stream.once("error", this.error);
85
- this.stream.once("end", this.close);
86
- this.stream.once("close", this.close);
87
- }
88
- pull() {
89
- this.resume();
90
- }
91
- cancel(reason) {
92
- if (this.stream.destroy) {
93
- this.stream.destroy(reason);
94
- }
95
- this.stream.off("data", this.enqueue);
96
- this.stream.off("error", this.error);
97
- this.stream.off("end", this.close);
98
- this.stream.off("close", this.close);
99
- }
100
- enqueue(chunk) {
101
- if (this.controller) {
102
- try {
103
- let bytes = chunk instanceof Uint8Array ? chunk : Buffer.from(chunk);
104
- let available = (this.controller.desiredSize || 0) - bytes.byteLength;
105
- this.controller.enqueue(bytes);
106
- if (available <= 0) {
107
- this.pause();
108
- }
109
- } catch (error) {
110
- this.controller.error(new Error("Could not create Buffer, chunk must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object"));
111
- this.cancel();
112
- }
113
- }
114
- }
115
- pause() {
116
- if (this.stream.pause) {
117
- this.stream.pause();
118
- }
119
- }
120
- resume() {
121
- if (this.stream.readable && this.stream.resume) {
122
- this.stream.resume();
123
- }
124
- }
125
- close() {
126
- if (this.controller) {
127
- this.controller.close();
128
- delete this.controller;
129
- }
130
- }
131
- error(error) {
132
- if (this.controller) {
133
- this.controller.error(error);
134
- delete this.controller;
135
- }
136
- }
137
- }
138
-
139
- export { createReadableStreamFromReadable, readableStreamToString, writeAsyncIterableToWritable, writeReadableStreamToWritable };