@react-router/node 0.0.0-experimental-c0856287f
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 +581 -0
- package/LICENSE.md +23 -0
- package/README.md +13 -0
- package/dist/crypto.d.ts +3 -0
- package/dist/crypto.js +29 -0
- package/dist/globals.d.ts +21 -0
- package/dist/globals.js +31 -0
- package/dist/implementations.d.ts +4 -0
- package/dist/implementations.js +29 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +83 -0
- package/dist/sessions/fileStorage.d.ts +23 -0
- package/dist/sessions/fileStorage.js +135 -0
- package/dist/stream.d.ts +9 -0
- package/dist/stream.js +146 -0
- package/dist/upload/fileUploadHandler.d.ts +68 -0
- package/dist/upload/fileUploadHandler.js +199 -0
- package/install.d.ts +1 -0
- package/install.js +8 -0
- package/package.json +55 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @react-router/node v0.0.0-experimental-c0856287f
|
|
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 crypto = require('node:crypto');
|
|
16
|
+
var node_fs = require('node:fs');
|
|
17
|
+
var promises = require('node:fs/promises');
|
|
18
|
+
var node_os = require('node:os');
|
|
19
|
+
var path = require('node:path');
|
|
20
|
+
var node_stream = require('node:stream');
|
|
21
|
+
var node_util = require('node:util');
|
|
22
|
+
var serverRuntime = require('@react-router/server-runtime');
|
|
23
|
+
var streamSlice = require('stream-slice');
|
|
24
|
+
var stream = require('../stream.js');
|
|
25
|
+
|
|
26
|
+
function _interopNamespace(e) {
|
|
27
|
+
if (e && e.__esModule) return e;
|
|
28
|
+
var n = Object.create(null);
|
|
29
|
+
if (e) {
|
|
30
|
+
Object.keys(e).forEach(function (k) {
|
|
31
|
+
if (k !== 'default') {
|
|
32
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
33
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function () { return e[k]; }
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
n["default"] = e;
|
|
41
|
+
return Object.freeze(n);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
var streamSlice__namespace = /*#__PURE__*/_interopNamespace(streamSlice);
|
|
45
|
+
|
|
46
|
+
let defaultFilePathResolver = ({
|
|
47
|
+
filename
|
|
48
|
+
}) => {
|
|
49
|
+
let ext = filename ? path.extname(filename) : "";
|
|
50
|
+
return "upload_" + crypto.randomBytes(4).readUInt32LE(0) + ext;
|
|
51
|
+
};
|
|
52
|
+
async function uniqueFile(filepath) {
|
|
53
|
+
let ext = path.extname(filepath);
|
|
54
|
+
let uniqueFilepath = filepath;
|
|
55
|
+
for (let i = 1; await promises.stat(uniqueFilepath).then(() => true).catch(() => false); i++) {
|
|
56
|
+
uniqueFilepath = (ext ? filepath.slice(0, -ext.length) : filepath) + `-${new Date().getTime()}${ext}`;
|
|
57
|
+
}
|
|
58
|
+
return uniqueFilepath;
|
|
59
|
+
}
|
|
60
|
+
function createFileUploadHandler({
|
|
61
|
+
directory = node_os.tmpdir(),
|
|
62
|
+
avoidFileConflicts = true,
|
|
63
|
+
file = defaultFilePathResolver,
|
|
64
|
+
filter,
|
|
65
|
+
maxPartSize = 3000000
|
|
66
|
+
} = {}) {
|
|
67
|
+
return async ({
|
|
68
|
+
name,
|
|
69
|
+
filename,
|
|
70
|
+
contentType,
|
|
71
|
+
data
|
|
72
|
+
}) => {
|
|
73
|
+
if (!filename || filter && !(await filter({
|
|
74
|
+
name,
|
|
75
|
+
filename,
|
|
76
|
+
contentType
|
|
77
|
+
}))) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
let dir = typeof directory === "string" ? directory : directory({
|
|
81
|
+
name,
|
|
82
|
+
filename,
|
|
83
|
+
contentType
|
|
84
|
+
});
|
|
85
|
+
if (!dir) {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
let filedir = path.resolve(dir);
|
|
89
|
+
let path$1 = typeof file === "string" ? file : file({
|
|
90
|
+
name,
|
|
91
|
+
filename,
|
|
92
|
+
contentType
|
|
93
|
+
});
|
|
94
|
+
if (!path$1) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
let filepath = path.resolve(filedir, path$1);
|
|
98
|
+
if (avoidFileConflicts) {
|
|
99
|
+
filepath = await uniqueFile(filepath);
|
|
100
|
+
}
|
|
101
|
+
await promises.mkdir(path.dirname(filepath), {
|
|
102
|
+
recursive: true
|
|
103
|
+
}).catch(() => {});
|
|
104
|
+
let writeFileStream = node_fs.createWriteStream(filepath);
|
|
105
|
+
let size = 0;
|
|
106
|
+
let deleteFile = false;
|
|
107
|
+
try {
|
|
108
|
+
for await (let chunk of data) {
|
|
109
|
+
size += chunk.byteLength;
|
|
110
|
+
if (size > maxPartSize) {
|
|
111
|
+
deleteFile = true;
|
|
112
|
+
throw new serverRuntime.MaxPartSizeExceededError(name, maxPartSize);
|
|
113
|
+
}
|
|
114
|
+
writeFileStream.write(chunk);
|
|
115
|
+
}
|
|
116
|
+
} finally {
|
|
117
|
+
writeFileStream.end();
|
|
118
|
+
await node_util.promisify(node_stream.finished)(writeFileStream);
|
|
119
|
+
if (deleteFile) {
|
|
120
|
+
await promises.rm(filepath).catch(() => {});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// TODO: remove this typecast once TS fixed File class regression
|
|
124
|
+
// https://github.com/microsoft/TypeScript/issues/52166
|
|
125
|
+
return new NodeOnDiskFile(filepath, contentType);
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
// TODO: remove this `Omit` usage once TS fixed File class regression
|
|
129
|
+
// https://github.com/microsoft/TypeScript/issues/52166
|
|
130
|
+
class NodeOnDiskFile {
|
|
131
|
+
lastModified = 0;
|
|
132
|
+
webkitRelativePath = "";
|
|
133
|
+
// TODO: remove this property once TS fixed File class regression
|
|
134
|
+
// https://github.com/microsoft/TypeScript/issues/52166
|
|
135
|
+
prototype = File.prototype;
|
|
136
|
+
constructor(filepath, type, slicer) {
|
|
137
|
+
this.filepath = filepath;
|
|
138
|
+
this.type = type;
|
|
139
|
+
this.slicer = slicer;
|
|
140
|
+
this.name = path.basename(filepath);
|
|
141
|
+
}
|
|
142
|
+
get size() {
|
|
143
|
+
let stats = node_fs.statSync(this.filepath);
|
|
144
|
+
if (this.slicer) {
|
|
145
|
+
let slice = this.slicer.end - this.slicer.start;
|
|
146
|
+
return slice < 0 ? 0 : slice > stats.size ? stats.size : slice;
|
|
147
|
+
}
|
|
148
|
+
return stats.size;
|
|
149
|
+
}
|
|
150
|
+
slice(start, end, type) {
|
|
151
|
+
var _this$slicer;
|
|
152
|
+
if (typeof start === "number" && start < 0) start = this.size + start;
|
|
153
|
+
if (typeof end === "number" && end < 0) end = this.size + end;
|
|
154
|
+
let startOffset = ((_this$slicer = this.slicer) === null || _this$slicer === void 0 ? void 0 : _this$slicer.start) || 0;
|
|
155
|
+
start = startOffset + (start || 0);
|
|
156
|
+
end = startOffset + (end || this.size);
|
|
157
|
+
return new NodeOnDiskFile(this.filepath, typeof type === "string" ? type : this.type, {
|
|
158
|
+
start,
|
|
159
|
+
end
|
|
160
|
+
}
|
|
161
|
+
// TODO: remove this typecast once TS fixed File class regression
|
|
162
|
+
// https://github.com/microsoft/TypeScript/issues/52166
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
async arrayBuffer() {
|
|
166
|
+
let stream = node_fs.createReadStream(this.filepath);
|
|
167
|
+
if (this.slicer) {
|
|
168
|
+
stream = stream.pipe(streamSlice__namespace.slice(this.slicer.start, this.slicer.end));
|
|
169
|
+
}
|
|
170
|
+
return new Promise((resolve, reject) => {
|
|
171
|
+
let buf = [];
|
|
172
|
+
stream.on("data", chunk => buf.push(chunk));
|
|
173
|
+
stream.on("end", () => resolve(Buffer.concat(buf)));
|
|
174
|
+
stream.on("error", err => reject(err));
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
stream() {
|
|
178
|
+
let stream$1 = node_fs.createReadStream(this.filepath);
|
|
179
|
+
if (this.slicer) {
|
|
180
|
+
stream$1 = stream$1.pipe(streamSlice__namespace.slice(this.slicer.start, this.slicer.end));
|
|
181
|
+
}
|
|
182
|
+
return stream.createReadableStreamFromReadable(stream$1);
|
|
183
|
+
}
|
|
184
|
+
async text() {
|
|
185
|
+
return stream.readableStreamToString(this.stream());
|
|
186
|
+
}
|
|
187
|
+
get [Symbol.toStringTag]() {
|
|
188
|
+
return "File";
|
|
189
|
+
}
|
|
190
|
+
remove() {
|
|
191
|
+
return promises.unlink(this.filepath);
|
|
192
|
+
}
|
|
193
|
+
getFilePath() {
|
|
194
|
+
return this.filepath;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
exports.NodeOnDiskFile = NodeOnDiskFile;
|
|
199
|
+
exports.createFileUploadHandler = createFileUploadHandler;
|
package/install.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/install.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-router/node",
|
|
3
|
+
"version": "0.0.0-experimental-c0856287f",
|
|
4
|
+
"description": "Node.js platform abstractions for React Router",
|
|
5
|
+
"bugs": {
|
|
6
|
+
"url": "https://github.com/remix-run/react-router/issues"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/remix-run/react-router",
|
|
11
|
+
"directory": "packages/remix-node"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"main": "dist/index.js",
|
|
15
|
+
"typings": "dist/index.d.ts",
|
|
16
|
+
"sideEffects": [
|
|
17
|
+
"./install.js"
|
|
18
|
+
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@web3-storage/multipart-parser": "^1.0.0",
|
|
21
|
+
"cookie-signature": "^1.1.0",
|
|
22
|
+
"source-map-support": "^0.5.21",
|
|
23
|
+
"stream-slice": "^0.1.2",
|
|
24
|
+
"undici": "^6.10.1",
|
|
25
|
+
"@react-router/server-runtime": "0.0.0-experimental-c0856287f"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/cookie-signature": "^1.0.3",
|
|
29
|
+
"@types/source-map-support": "^0.5.4",
|
|
30
|
+
"typescript": "^5.1.6"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"typescript": "^5.1.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependenciesMeta": {
|
|
36
|
+
"typescript": {
|
|
37
|
+
"optional": true
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18.0.0"
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"dist/",
|
|
45
|
+
"globals.d.ts",
|
|
46
|
+
"install.d.ts",
|
|
47
|
+
"install.js",
|
|
48
|
+
"CHANGELOG.md",
|
|
49
|
+
"LICENSE.md",
|
|
50
|
+
"README.md"
|
|
51
|
+
],
|
|
52
|
+
"scripts": {
|
|
53
|
+
"tsc": "tsc"
|
|
54
|
+
}
|
|
55
|
+
}
|