@react-router/node 7.0.0-pre.2 → 7.0.0-pre.4
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 +14 -0
- package/dist/index.d.mts +32 -0
- package/dist/index.d.ts +32 -2
- package/dist/index.js +238 -12
- package/dist/{stream.js → index.mjs} +88 -24
- package/package.json +49 -7
- package/dist/sessions/fileStorage.d.ts +0 -23
- package/dist/sessions/fileStorage.js +0 -132
- package/dist/stream.d.ts +0 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# `@remix-run/node`
|
|
2
2
|
|
|
3
|
+
## 7.0.0-pre.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies:
|
|
8
|
+
- `react-router@7.0.0-pre.4`
|
|
9
|
+
|
|
10
|
+
## 7.0.0-pre.3
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies:
|
|
15
|
+
- `react-router@7.0.0-pre.3`
|
|
16
|
+
|
|
3
17
|
## 7.0.0-pre.2
|
|
4
18
|
|
|
5
19
|
### Major Changes
|
package/dist/index.d.mts
ADDED
|
@@ -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,2 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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.
|
|
2
|
+
* @react-router/node v7.0.0-pre.4
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -8,17 +8,243 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
|
|
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
|
-
|
|
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
|
-
|
|
16
|
-
var
|
|
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
|
+
}
|
|
17
113
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/node v7.0.0-pre.
|
|
2
|
+
* @react-router/node v7.0.0-pre.4
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -8,21 +8,78 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
'use strict';
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
+
}
|
|
16
74
|
|
|
75
|
+
// stream.ts
|
|
76
|
+
import { Stream } from "node:stream";
|
|
17
77
|
async function writeReadableStreamToWritable(stream, writable) {
|
|
18
78
|
let reader = stream.getReader();
|
|
19
79
|
let flushable = writable;
|
|
20
80
|
try {
|
|
21
81
|
while (true) {
|
|
22
|
-
let {
|
|
23
|
-
done,
|
|
24
|
-
value
|
|
25
|
-
} = await reader.read();
|
|
82
|
+
let { done, value } = await reader.read();
|
|
26
83
|
if (done) {
|
|
27
84
|
writable.end();
|
|
28
85
|
break;
|
|
@@ -52,10 +109,7 @@ async function readableStreamToString(stream, encoding) {
|
|
|
52
109
|
let reader = stream.getReader();
|
|
53
110
|
let chunks = [];
|
|
54
111
|
while (true) {
|
|
55
|
-
let {
|
|
56
|
-
done,
|
|
57
|
-
value
|
|
58
|
-
} = await reader.read();
|
|
112
|
+
let { done, value } = await reader.read();
|
|
59
113
|
if (done) {
|
|
60
114
|
break;
|
|
61
115
|
}
|
|
@@ -65,14 +119,18 @@ async function readableStreamToString(stream, encoding) {
|
|
|
65
119
|
}
|
|
66
120
|
return Buffer.concat(chunks).toString(encoding);
|
|
67
121
|
}
|
|
68
|
-
|
|
122
|
+
var createReadableStreamFromReadable = (source) => {
|
|
69
123
|
let pump = new StreamPump(source);
|
|
70
124
|
let stream = new ReadableStream(pump, pump);
|
|
71
125
|
return stream;
|
|
72
126
|
};
|
|
73
|
-
|
|
127
|
+
var StreamPump = class {
|
|
128
|
+
highWaterMark;
|
|
129
|
+
accumalatedSize;
|
|
130
|
+
stream;
|
|
131
|
+
controller;
|
|
74
132
|
constructor(stream) {
|
|
75
|
-
this.highWaterMark = stream.readableHighWaterMark || new
|
|
133
|
+
this.highWaterMark = stream.readableHighWaterMark || new Stream.Readable().readableHighWaterMark;
|
|
76
134
|
this.accumalatedSize = 0;
|
|
77
135
|
this.stream = stream;
|
|
78
136
|
this.enqueue = this.enqueue.bind(this);
|
|
@@ -80,7 +138,7 @@ class StreamPump {
|
|
|
80
138
|
this.close = this.close.bind(this);
|
|
81
139
|
}
|
|
82
140
|
size(chunk) {
|
|
83
|
-
return
|
|
141
|
+
return chunk?.byteLength || 0;
|
|
84
142
|
}
|
|
85
143
|
start(controller) {
|
|
86
144
|
this.controller = controller;
|
|
@@ -111,7 +169,11 @@ class StreamPump {
|
|
|
111
169
|
this.pause();
|
|
112
170
|
}
|
|
113
171
|
} catch (error) {
|
|
114
|
-
this.controller.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
|
+
);
|
|
115
177
|
this.cancel();
|
|
116
178
|
}
|
|
117
179
|
}
|
|
@@ -138,9 +200,11 @@ class StreamPump {
|
|
|
138
200
|
delete this.controller;
|
|
139
201
|
}
|
|
140
202
|
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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.
|
|
3
|
+
"version": "7.0.0-pre.4",
|
|
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,12 +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
|
-
"
|
|
19
|
-
|
|
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
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"./install": {
|
|
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
|
+
}
|
|
20
46
|
},
|
|
21
47
|
"./package.json": "./package.json"
|
|
22
48
|
},
|
|
@@ -24,6 +50,20 @@
|
|
|
24
50
|
"./dist/install.js",
|
|
25
51
|
"./dist/install.mjs"
|
|
26
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
|
+
},
|
|
27
67
|
"dependencies": {
|
|
28
68
|
"@web3-storage/multipart-parser": "^1.0.0",
|
|
29
69
|
"source-map-support": "^0.5.21",
|
|
@@ -32,12 +72,14 @@
|
|
|
32
72
|
},
|
|
33
73
|
"devDependencies": {
|
|
34
74
|
"@types/source-map-support": "^0.5.4",
|
|
75
|
+
"tsup": "^8.3.0",
|
|
35
76
|
"typescript": "^5.1.6",
|
|
36
|
-
"
|
|
77
|
+
"wireit": "0.14.9",
|
|
78
|
+
"react-router": "7.0.0-pre.4"
|
|
37
79
|
},
|
|
38
80
|
"peerDependencies": {
|
|
39
81
|
"typescript": "^5.1.0",
|
|
40
|
-
"react-router": "7.0.0-pre.
|
|
82
|
+
"react-router": "7.0.0-pre.4"
|
|
41
83
|
},
|
|
42
84
|
"peerDependenciesMeta": {
|
|
43
85
|
"typescript": {
|
|
@@ -57,6 +99,6 @@
|
|
|
57
99
|
"README.md"
|
|
58
100
|
],
|
|
59
101
|
"scripts": {
|
|
60
|
-
"
|
|
102
|
+
"build": "wireit"
|
|
61
103
|
}
|
|
62
104
|
}
|
|
@@ -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.2
|
|
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;
|
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>;
|