@trpc/server 11.0.0-next-beta.205 → 11.0.0-next-beta.208

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.
Files changed (57) hide show
  1. package/dist/adapters/aws-lambda/index.js +14 -105
  2. package/dist/adapters/aws-lambda/index.mjs +1 -90
  3. package/dist/adapters/aws-lambda/utils.js +100 -0
  4. package/dist/adapters/aws-lambda/utils.mjs +93 -0
  5. package/dist/adapters/express.js +1 -7
  6. package/dist/adapters/express.mjs +1 -5
  7. package/dist/adapters/fastify/fastifyRequestHandler.js +81 -0
  8. package/dist/adapters/fastify/fastifyRequestHandler.mjs +79 -0
  9. package/dist/adapters/fastify/fastifyTRPCPlugin.js +51 -0
  10. package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +49 -0
  11. package/dist/adapters/fastify/index.js +4 -128
  12. package/dist/adapters/fastify/index.mjs +2 -128
  13. package/dist/adapters/fetch/fetchRequestHandler.js +118 -0
  14. package/dist/adapters/fetch/fetchRequestHandler.mjs +116 -0
  15. package/dist/adapters/fetch/index.js +2 -115
  16. package/dist/adapters/fetch/index.mjs +1 -116
  17. package/dist/adapters/next.js +1 -6
  18. package/dist/adapters/next.mjs +1 -4
  19. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.js +161 -0
  20. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +157 -0
  21. package/dist/adapters/node-http/content-type/form-data/index.js +20 -646
  22. package/dist/adapters/node-http/content-type/form-data/index.mjs +9 -631
  23. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.js +29 -0
  24. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.mjs +27 -0
  25. package/dist/adapters/node-http/content-type/form-data/streamSlice.js +46 -0
  26. package/dist/adapters/node-http/content-type/form-data/streamSlice.mjs +44 -0
  27. package/dist/adapters/node-http/content-type/form-data/uploadHandler.js +30 -0
  28. package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +26 -0
  29. package/dist/adapters/node-http/content-type/json/getPostBody.js +42 -0
  30. package/dist/adapters/node-http/content-type/json/getPostBody.mjs +40 -0
  31. package/dist/adapters/node-http/content-type/json/index.js +3 -42
  32. package/dist/adapters/node-http/content-type/json/index.mjs +2 -39
  33. package/dist/adapters/node-http/index.js +1 -7
  34. package/dist/adapters/node-http/index.mjs +1 -5
  35. package/dist/{contentType-72ed9df5.mjs → adapters/node-http/internals/contentType.mjs} +1 -1
  36. package/dist/{nodeHTTPRequestHandler-83441c73.js → adapters/node-http/nodeHTTPRequestHandler.js} +2 -2
  37. package/dist/{nodeHTTPRequestHandler-0223fac5.mjs → adapters/node-http/nodeHTTPRequestHandler.mjs} +2 -2
  38. package/dist/adapters/standalone.js +2 -12
  39. package/dist/adapters/standalone.mjs +2 -6
  40. package/dist/adapters/ws.js +0 -2
  41. package/dist/bundle-analysis.json +99 -99
  42. package/dist/http.js +1 -3
  43. package/dist/index.js +10 -12
  44. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.js +203 -0
  45. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.mjs +201 -0
  46. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.js +167 -0
  47. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.mjs +163 -0
  48. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.js +35 -0
  49. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.mjs +30 -0
  50. package/dist/observable.js +1 -3
  51. package/dist/rpc.js +1 -3
  52. package/dist/shared.js +2 -4
  53. package/package.json +4 -4
  54. package/src/adapters/standalone.ts +1 -1
  55. package/dist/contentType-24c44bba.js +0 -5
  56. package/dist/nodeHTTPRequestHandler-aa0dce4e.js +0 -105
  57. /package/dist/{contentType-d9d22104.js → adapters/node-http/internals/contentType.js} +0 -0
@@ -1,18 +1,14 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var fs = require('node:fs/promises');
6
4
  var node_stream = require('node:stream');
7
- var contentType = require('../../../../contentType-d9d22104.js');
8
- var node_crypto = require('node:crypto');
9
- var node_fs = require('node:fs');
10
- var node_os = require('node:os');
11
- var node_path = require('node:path');
12
- var node_util = require('node:util');
5
+ var index = require('../../../../node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.js');
6
+ var contentType = require('../../internals/contentType.js');
7
+ var fileUploadHandler = require('./fileUploadHandler.js');
8
+ var uploadHandler = require('./uploadHandler.js');
9
+ var memoryUploadHandler = require('./memoryUploadHandler.js');
13
10
 
14
- function _interopNamespace(e) {
15
- if (e && e.__esModule) return e;
11
+ function _interopNamespaceDefault(e) {
16
12
  var n = Object.create(null);
17
13
  if (e) {
18
14
  Object.keys(e).forEach(function (k) {
@@ -25,633 +21,11 @@ function _interopNamespace(e) {
25
21
  }
26
22
  });
27
23
  }
28
- n["default"] = e;
24
+ n.default = e;
29
25
  return Object.freeze(n);
30
26
  }
31
27
 
32
- var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
33
-
34
- function stringToArray(s) {
35
- const utf8 = unescape(encodeURIComponent(s));
36
- return Uint8Array.from(utf8, (_, i) => utf8.charCodeAt(i));
37
- }
38
- function arrayToString(a) {
39
- const utf8 = String.fromCharCode.apply(null, a);
40
- return decodeURIComponent(escape(utf8));
41
- }
42
- function mergeArrays(...arrays) {
43
- const out = new Uint8Array(arrays.reduce((total, arr) => total + arr.length, 0));
44
- let offset = 0;
45
- for (const arr of arrays) {
46
- out.set(arr, offset);
47
- offset += arr.length;
48
- }
49
- return out;
50
- }
51
- function arraysEqual(a, b) {
52
- if (a.length !== b.length) {
53
- return false;
54
- }
55
- for (let i = 0; i < a.length; i++) {
56
- if (a[i] !== b[i]) {
57
- return false;
58
- }
59
- }
60
- return true;
61
- }
62
-
63
- function coerce(a) {
64
- if (a instanceof Uint8Array) {
65
- return index => a[index];
66
- }
67
- return a;
68
- }
69
- function jsmemcmp(buf1, pos1, buf2, pos2, len) {
70
- const fn1 = coerce(buf1);
71
- const fn2 = coerce(buf2);
72
- for (let i = 0; i < len; ++i) {
73
- if (fn1(pos1 + i) !== fn2(pos2 + i)) {
74
- return false;
75
- }
76
- }
77
- return true;
78
- }
79
- function createOccurenceTable(s) {
80
- const table = new Array(256).fill(s.length);
81
- if (s.length > 1) {
82
- for (let i = 0; i < s.length - 1; i++) {
83
- table[s[i]] = s.length - 1 - i;
84
- }
85
- }
86
- return table;
87
- }
88
- const MATCH = Symbol('Match');
89
- class StreamSearch {
90
- constructor(needle) {
91
- this._lookbehind = new Uint8Array();
92
- if (typeof needle === 'string') {
93
- this._needle = needle = stringToArray(needle);
94
- } else {
95
- this._needle = needle;
96
- }
97
- this._lastChar = needle[needle.length - 1];
98
- this._occ = createOccurenceTable(needle);
99
- }
100
- feed(chunk) {
101
- let pos = 0;
102
- let tokens;
103
- const allTokens = [];
104
- while (pos !== chunk.length) {
105
- [pos, ...tokens] = this._feed(chunk, pos);
106
- allTokens.push(...tokens);
107
- }
108
- return allTokens;
109
- }
110
- end() {
111
- const tail = this._lookbehind;
112
- this._lookbehind = new Uint8Array();
113
- return tail;
114
- }
115
- _feed(data, bufPos) {
116
- const tokens = [];
117
- let pos = -this._lookbehind.length;
118
- if (pos < 0) {
119
- while (pos < 0 && pos <= data.length - this._needle.length) {
120
- const ch = this._charAt(data, pos + this._needle.length - 1);
121
- if (ch === this._lastChar && this._memcmp(data, pos, this._needle.length - 1)) {
122
- if (pos > -this._lookbehind.length) {
123
- tokens.push(this._lookbehind.slice(0, this._lookbehind.length + pos));
124
- }
125
- tokens.push(MATCH);
126
- this._lookbehind = new Uint8Array();
127
- return [
128
- pos + this._needle.length,
129
- ...tokens
130
- ];
131
- } else {
132
- pos += this._occ[ch];
133
- }
134
- }
135
- if (pos < 0) {
136
- while (pos < 0 && !this._memcmp(data, pos, data.length - pos)) {
137
- pos++;
138
- }
139
- }
140
- if (pos >= 0) {
141
- tokens.push(this._lookbehind);
142
- this._lookbehind = new Uint8Array();
143
- } else {
144
- const bytesToCutOff = this._lookbehind.length + pos;
145
- if (bytesToCutOff > 0) {
146
- tokens.push(this._lookbehind.slice(0, bytesToCutOff));
147
- this._lookbehind = this._lookbehind.slice(bytesToCutOff);
148
- }
149
- this._lookbehind = Uint8Array.from(new Array(this._lookbehind.length + data.length), (_, i) => this._charAt(data, i - this._lookbehind.length));
150
- return [
151
- data.length,
152
- ...tokens
153
- ];
154
- }
155
- }
156
- pos += bufPos;
157
- while (pos <= data.length - this._needle.length) {
158
- const ch = data[pos + this._needle.length - 1];
159
- if (ch === this._lastChar && data[pos] === this._needle[0] && jsmemcmp(this._needle, 0, data, pos, this._needle.length - 1)) {
160
- if (pos > bufPos) {
161
- tokens.push(data.slice(bufPos, pos));
162
- }
163
- tokens.push(MATCH);
164
- return [
165
- pos + this._needle.length,
166
- ...tokens
167
- ];
168
- } else {
169
- pos += this._occ[ch];
170
- }
171
- }
172
- if (pos < data.length) {
173
- while (pos < data.length && (data[pos] !== this._needle[0] || !jsmemcmp(data, pos, this._needle, 0, data.length - pos))) {
174
- ++pos;
175
- }
176
- if (pos < data.length) {
177
- this._lookbehind = data.slice(pos);
178
- }
179
- }
180
- if (pos > 0) {
181
- tokens.push(data.slice(bufPos, pos < data.length ? pos : data.length));
182
- }
183
- return [
184
- data.length,
185
- ...tokens
186
- ];
187
- }
188
- _charAt(data, pos) {
189
- if (pos < 0) {
190
- return this._lookbehind[this._lookbehind.length + pos];
191
- }
192
- return data[pos];
193
- }
194
- _memcmp(data, pos, len) {
195
- return jsmemcmp(this._charAt.bind(this, data), pos, this._needle, 0, len);
196
- }
197
- }
198
- class ReadableStreamSearch {
199
- constructor(needle, _readableStream) {
200
- this._readableStream = _readableStream;
201
- this._search = new StreamSearch(needle);
202
- }
203
- async *[Symbol.asyncIterator]() {
204
- const reader = this._readableStream.getReader();
205
- try {
206
- while (true) {
207
- const result = await reader.read();
208
- if (result.done) {
209
- break;
210
- }
211
- yield* this._search.feed(result.value);
212
- }
213
- const tail = this._search.end();
214
- if (tail.length) {
215
- yield tail;
216
- }
217
- } finally {
218
- reader.releaseLock();
219
- }
220
- }
221
- }
222
-
223
- const mergeArrays2 = Function.prototype.apply.bind(mergeArrays, undefined);
224
- const dash = stringToArray('--');
225
- const CRLF = stringToArray('\r\n');
226
- function parseContentDisposition(header) {
227
- const parts = header.split(';').map(part => part.trim());
228
- if (parts.shift() !== 'form-data') {
229
- throw new Error('malformed content-disposition header: missing "form-data" in `' + JSON.stringify(parts) + '`');
230
- }
231
- const out = {};
232
- for (const part of parts) {
233
- const kv = part.split('=', 2);
234
- if (kv.length !== 2) {
235
- throw new Error('malformed content-disposition header: key-value pair not found - ' + part + ' in `' + header + '`');
236
- }
237
- const [name, value] = kv;
238
- if (value[0] === '"' && value[value.length - 1] === '"') {
239
- out[name] = value.slice(1, -1).replace(/\\"/g, '"');
240
- } else if (value[0] !== '"' && value[value.length - 1] !== '"') {
241
- out[name] = value;
242
- } else if (value[0] === '"' && value[value.length - 1] !== '"' || value[0] !== '"' && value[value.length - 1] === '"') {
243
- throw new Error('malformed content-disposition header: mismatched quotations in `' + header + '`');
244
- }
245
- }
246
- if (!out.name) {
247
- throw new Error('malformed content-disposition header: missing field name in `' + header + '`');
248
- }
249
- return out;
250
- }
251
- function parsePartHeaders(lines) {
252
- const entries = [];
253
- let disposition = false;
254
- let line;
255
- while (typeof (line = lines.shift()) !== 'undefined') {
256
- const colon = line.indexOf(':');
257
- if (colon === -1) {
258
- throw new Error('malformed multipart-form header: missing colon');
259
- }
260
- const header = line.slice(0, colon).trim().toLowerCase();
261
- const value = line.slice(colon + 1).trim();
262
- switch (header) {
263
- case 'content-disposition':
264
- disposition = true;
265
- entries.push(...Object.entries(parseContentDisposition(value)));
266
- break;
267
- case 'content-type':
268
- entries.push([
269
- 'contentType',
270
- value
271
- ]);
272
- }
273
- }
274
- if (!disposition) {
275
- throw new Error('malformed multipart-form header: missing content-disposition');
276
- }
277
- return Object.fromEntries(entries);
278
- }
279
- async function readHeaderLines(it, needle) {
280
- let firstChunk = true;
281
- let lastTokenWasMatch = false;
282
- const headerLines = [[]];
283
- const crlfSearch = new StreamSearch(CRLF);
284
- for (;;) {
285
- const result = await it.next();
286
- if (result.done) {
287
- throw new Error('malformed multipart-form data: unexpected end of stream');
288
- }
289
- if (firstChunk && result.value !== MATCH && arraysEqual(result.value.slice(0, 2), dash)) {
290
- return [
291
- undefined,
292
- new Uint8Array()
293
- ];
294
- }
295
- let chunk;
296
- if (result.value !== MATCH) {
297
- chunk = result.value;
298
- } else if (!lastTokenWasMatch) {
299
- chunk = needle;
300
- } else {
301
- throw new Error('malformed multipart-form data: unexpected boundary');
302
- }
303
- if (!chunk.length) {
304
- continue;
305
- }
306
- if (firstChunk) {
307
- firstChunk = false;
308
- }
309
- const tokens = crlfSearch.feed(chunk);
310
- for (const [i, token] of tokens.entries()) {
311
- const isMatch = token === MATCH;
312
- if (!isMatch && !token.length) {
313
- continue;
314
- }
315
- if (lastTokenWasMatch && isMatch) {
316
- tokens.push(crlfSearch.end());
317
- return [
318
- headerLines.filter(chunks => chunks.length).map(mergeArrays2).map(arrayToString),
319
- mergeArrays(...tokens.slice(i + 1).map(token => token === MATCH ? CRLF : token))
320
- ];
321
- }
322
- if (lastTokenWasMatch = isMatch) {
323
- headerLines.push([]);
324
- } else {
325
- headerLines[headerLines.length - 1].push(token);
326
- }
327
- }
328
- }
329
- }
330
- async function* streamMultipart(body, boundary) {
331
- const needle = mergeArrays(dash, stringToArray(boundary));
332
- const it = new ReadableStreamSearch(needle, body)[Symbol.asyncIterator]();
333
- for (;;) {
334
- const result = await it.next();
335
- if (result.done) {
336
- return;
337
- }
338
- if (result.value === MATCH) {
339
- break;
340
- }
341
- }
342
- const crlfSearch = new StreamSearch(CRLF);
343
- for (;;) {
344
- const [headerLines, tail] = await readHeaderLines(it, needle);
345
- if (!headerLines) {
346
- return;
347
- }
348
- async function nextToken() {
349
- const result = await it.next();
350
- if (result.done) {
351
- throw new Error('malformed multipart-form data: unexpected end of stream');
352
- }
353
- return result;
354
- }
355
- let trailingCRLF = false;
356
- function feedChunk(chunk) {
357
- const chunks = [];
358
- for (const token of crlfSearch.feed(chunk)) {
359
- if (trailingCRLF) {
360
- chunks.push(CRLF);
361
- }
362
- if (!(trailingCRLF = token === MATCH)) {
363
- chunks.push(token);
364
- }
365
- }
366
- return mergeArrays(...chunks);
367
- }
368
- let done = false;
369
- async function nextChunk() {
370
- const result = await nextToken();
371
- let chunk;
372
- if (result.value !== MATCH) {
373
- chunk = result.value;
374
- } else if (!trailingCRLF) {
375
- chunk = CRLF;
376
- } else {
377
- done = true;
378
- return { value: crlfSearch.end() };
379
- }
380
- return { value: feedChunk(chunk) };
381
- }
382
- const bufferedChunks = [{ value: feedChunk(tail) }];
383
- yield {
384
- ...parsePartHeaders(headerLines),
385
- data: {
386
- [Symbol.asyncIterator]() {
387
- return this;
388
- },
389
- async next() {
390
- for (;;) {
391
- const result = bufferedChunks.shift();
392
- if (!result) {
393
- break;
394
- }
395
- if (result.value.length > 0) {
396
- return result;
397
- }
398
- }
399
- for (;;) {
400
- if (done) {
401
- return {
402
- done,
403
- value: undefined
404
- };
405
- }
406
- const result = await nextChunk();
407
- if (result.value.length > 0) {
408
- return result;
409
- }
410
- }
411
- }
412
- }
413
- };
414
- while (!done) {
415
- bufferedChunks.push(await nextChunk());
416
- }
417
- }
418
- }
419
-
420
- class SliceStream extends node_stream.Transform {
421
- _transform(chunk, _, done) {
422
- this.indexOffset += chunk.length;
423
- if (!this.emitUp && this.indexOffset >= this.startIndex) {
424
- this.emitUp = true;
425
- const start = chunk.length - (this.indexOffset - this.startIndex);
426
- if (this.indexOffset > this.endIndex) {
427
- const end = chunk.length - (this.indexOffset - this.endIndex);
428
- this.emitDown = true;
429
- this.push(chunk.slice(start, end));
430
- } else {
431
- this.push(chunk.slice(start, chunk.length));
432
- }
433
- done();
434
- return;
435
- }
436
- if (this.emitUp && !this.emitDown) {
437
- if (this.indexOffset >= this.endIndex) {
438
- this.emitDown = true;
439
- this.push(chunk.slice(0, chunk.length - (this.indexOffset - this.endIndex)));
440
- } else {
441
- this.push(chunk);
442
- }
443
- done();
444
- return;
445
- }
446
- done();
447
- }
448
- constructor(startIndex = 0, endIndex = Infinity){
449
- super();
450
- this.startIndex = startIndex;
451
- this.endIndex = endIndex;
452
- this.indexOffset = 0;
453
- this.emitUp = false;
454
- this.emitDown = false;
455
- }
456
- }
457
- function streamSlice(startIndex = 0, endIndex = Infinity) {
458
- return new SliceStream(startIndex, endIndex);
459
- }
460
-
461
- function composeUploadHandlers(...handlers) {
462
- return async (part)=>{
463
- for (const handler of handlers){
464
- const value = await handler(part);
465
- if (typeof value !== 'undefined' && value !== null) {
466
- return value;
467
- }
468
- }
469
- return undefined;
470
- };
471
- }
472
- class MaxPartSizeExceededError extends Error {
473
- constructor(field, maxBytes){
474
- super(`Field "${field}" exceeded upload size of ${maxBytes} bytes.`);
475
- this.field = field;
476
- this.maxBytes = maxBytes;
477
- }
478
- }
479
- class MaxBodySizeExceededError extends Error {
480
- constructor(maxBytes){
481
- super(`Body exceeded upload size of ${maxBytes} bytes.`);
482
- this.maxBytes = maxBytes;
483
- }
484
- }
485
-
486
- async function readableStreamToString(stream, encoding) {
487
- const reader = stream.getReader();
488
- const chunks = [];
489
- async function read() {
490
- const { done , value } = await reader.read();
491
- if (done) {
492
- return;
493
- } else if (value) {
494
- chunks.push(value);
495
- }
496
- await read();
497
- }
498
- await read();
499
- return Buffer.concat(chunks).toString(encoding);
500
- }
501
- const defaultFilePathResolver = ({ filename , })=>{
502
- const ext = filename ? node_path.extname(filename) : '';
503
- return 'upload_' + node_crypto.randomBytes(4).readUInt32LE(0) + ext;
504
- };
505
- async function uniqueFile(filepath) {
506
- const ext = node_path.extname(filepath);
507
- let uniqueFilepath = filepath;
508
- for(let i = 1; await fs.stat(uniqueFilepath).then(()=>true).catch(()=>false); i++){
509
- uniqueFilepath = (ext ? filepath.slice(0, -ext.length) : filepath) + `-${new Date().getTime()}${ext}`;
510
- }
511
- return uniqueFilepath;
512
- }
513
- function createFileUploadHandler({ directory =node_os.tmpdir() , avoidFileConflicts =true , file =defaultFilePathResolver , filter , maxPartSize =3000000 } = {}) {
514
- return async ({ name , filename , contentType , data })=>{
515
- if (!filename || filter && !await filter({
516
- name,
517
- filename,
518
- contentType
519
- })) {
520
- return undefined;
521
- }
522
- const dir = typeof directory === 'string' ? directory : directory({
523
- name,
524
- filename,
525
- contentType
526
- });
527
- if (!dir) {
528
- return undefined;
529
- }
530
- const filedir = node_path.resolve(dir);
531
- const path = typeof file === 'string' ? file : file({
532
- name,
533
- filename,
534
- contentType
535
- });
536
- if (!path) {
537
- return undefined;
538
- }
539
- let filepath = node_path.resolve(filedir, path);
540
- if (avoidFileConflicts) {
541
- filepath = await uniqueFile(filepath);
542
- }
543
- await fs.mkdir(node_path.dirname(filepath), {
544
- recursive: true
545
- }).catch(()=>{});
546
- const writeFileStream = node_fs.createWriteStream(filepath);
547
- let size = 0;
548
- let deleteFile = false;
549
- try {
550
- for await (const chunk of data){
551
- size += chunk.byteLength;
552
- if (size > maxPartSize) {
553
- deleteFile = true;
554
- throw new MaxPartSizeExceededError(name, maxPartSize);
555
- }
556
- writeFileStream.write(chunk);
557
- }
558
- } finally{
559
- writeFileStream.end();
560
- await node_util.promisify(node_stream.finished)(writeFileStream);
561
- if (deleteFile) {
562
- await fs.rm(filepath).catch(()=>{});
563
- }
564
- }
565
- return new NodeOnDiskFile(filepath, contentType);
566
- };
567
- }
568
- let _toStringTag = Symbol.toStringTag;
569
- class NodeOnDiskFile {
570
- get size() {
571
- const stats = node_fs.statSync(this.filepath);
572
- if (this.slicer) {
573
- const slice = this.slicer.end - this.slicer.start;
574
- return slice < 0 ? 0 : slice > stats.size ? stats.size : slice;
575
- }
576
- return stats.size;
577
- }
578
- slice(start, end, type) {
579
- if (typeof start === 'number' && start < 0) start = this.size + start;
580
- if (typeof end === 'number' && end < 0) end = this.size + end;
581
- const startOffset = this.slicer?.start ?? 0;
582
- start = startOffset + (start ?? 0);
583
- end = startOffset + (end ?? this.size);
584
- return new NodeOnDiskFile(this.filepath, typeof type === 'string' ? type : this.type, {
585
- start,
586
- end
587
- });
588
- }
589
- async arrayBuffer() {
590
- let stream = node_fs.createReadStream(this.filepath);
591
- if (this.slicer) {
592
- stream = stream.pipe(streamSlice(this.slicer.start, this.slicer.end));
593
- }
594
- return new Promise((resolve, reject)=>{
595
- const buf = [];
596
- stream.on('data', (chunk)=>buf.push(chunk));
597
- stream.on('end', ()=>{
598
- resolve(Buffer.concat(buf));
599
- });
600
- stream.on('error', (err)=>{
601
- reject(err);
602
- });
603
- });
604
- }
605
- stream() {
606
- let stream = node_fs.createReadStream(this.filepath);
607
- if (this.slicer) {
608
- stream = stream.pipe(streamSlice(this.slicer.start, this.slicer.end));
609
- }
610
- return node_stream.Readable.toWeb(stream);
611
- }
612
- async text() {
613
- return readableStreamToString(this.stream());
614
- }
615
- remove() {
616
- return fs.unlink(this.filepath);
617
- }
618
- getFilePath() {
619
- return this.filepath;
620
- }
621
- constructor(filepath, type, slicer){
622
- this.filepath = filepath;
623
- this.type = type;
624
- this.slicer = slicer;
625
- this.lastModified = 0;
626
- this.webkitRelativePath = '';
627
- this[_toStringTag] = 'File';
628
- this.name = node_path.basename(filepath);
629
- }
630
- }
631
-
632
- function createMemoryUploadHandler({ filter , maxPartSize =3000000 } = {}) {
633
- return async ({ filename , contentType , name , data })=>{
634
- if (filter && !await filter({
635
- filename,
636
- contentType,
637
- name
638
- })) {
639
- return undefined;
640
- }
641
- let size = 0;
642
- const chunks = [];
643
- for await (const chunk of data){
644
- size += chunk.byteLength;
645
- if (size > maxPartSize) {
646
- throw new MaxPartSizeExceededError(name, maxPartSize);
647
- }
648
- chunks.push(chunk);
649
- }
650
- return new File(chunks, filename, {
651
- type: contentType
652
- });
653
- };
654
- }
28
+ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
655
29
 
656
30
  const utfTextDecoder = new TextDecoder('utf-8');
657
31
  /**
@@ -663,14 +37,14 @@ const utfTextDecoder = new TextDecoder('utf-8');
663
37
  * @param maxBodySize The maximum size of the request body in bytes. Defaults to Infinity.
664
38
  *
665
39
  * @link https://remix.run/utils/parse-multipart-form-data
666
- */ async function parseMultipartFormData(request, uploadHandler, maxBodySize = Infinity) {
40
+ */ async function parseMultipartFormData(request, uploadHandler$1, maxBodySize = Infinity) {
667
41
  const contentType = request.headers['content-type'] ?? '';
668
42
  const [type, boundary] = contentType.split(/\s*;\s*boundary=/);
669
43
  if (!boundary || type !== 'multipart/form-data') {
670
44
  throw new TypeError('Could not parse content as FormData.');
671
45
  }
672
46
  const formData = new FormData();
673
- const parts = streamMultipart(node_stream.Readable.toWeb(request), boundary);
47
+ const parts = index.streamMultipart(node_stream.Readable.toWeb(request), boundary);
674
48
  let currentBodySize = 0;
675
49
  const nodeOnDiskFiles = [];
676
50
  try {
@@ -681,18 +55,18 @@ const utfTextDecoder = new TextDecoder('utf-8');
681
55
  // only pass basename as the multipart/form-data spec recommends
682
56
  // https://datatracker.ietf.org/doc/html/rfc7578#section-4.2
683
57
  part.filename = part.filename.split(/[/\\]/).pop();
684
- const value = await uploadHandler(part);
58
+ const value = await uploadHandler$1(part);
685
59
  if (typeof value === 'undefined' || value === null) {
686
60
  continue;
687
61
  }
688
62
  // add to cleanup array in case of error
689
- if (value instanceof NodeOnDiskFile) {
63
+ if (value instanceof fileUploadHandler.NodeOnDiskFile) {
690
64
  nodeOnDiskFiles.push(value);
691
65
  }
692
66
  // if the combined size of the body exceeds the max size, throw an error
693
67
  currentBodySize += value.size;
694
68
  if (currentBodySize > maxBodySize) {
695
- throw new MaxBodySizeExceededError(maxBodySize);
69
+ throw new uploadHandler.MaxBodySizeExceededError(maxBodySize);
696
70
  }
697
71
  // add the file to the form data
698
72
  formData.append(part.name, value);
@@ -703,7 +77,7 @@ const utfTextDecoder = new TextDecoder('utf-8');
703
77
  // if the combined size of the body exceeds the max size, throw an error
704
78
  currentBodySize += chunk.length;
705
79
  if (currentBodySize > maxBodySize) {
706
- throw new MaxBodySizeExceededError(maxBodySize);
80
+ throw new uploadHandler.MaxBodySizeExceededError(maxBodySize);
707
81
  }
708
82
  textualPart += utfTextDecoder.decode(chunk);
709
83
  }
@@ -750,12 +124,12 @@ const nodeHTTPFormDataContentTypeHandler = contentType.createNodeHTTPContentType
750
124
  }
751
125
  });
752
126
 
753
- exports.MaxBodySizeExceededError = MaxBodySizeExceededError;
754
- exports.MaxPartSizeExceededError = MaxPartSizeExceededError;
755
- exports.experimental_NodeOnDiskFile = NodeOnDiskFile;
756
- exports.experimental_composeUploadHandlers = composeUploadHandlers;
757
- exports.experimental_createFileUploadHandler = createFileUploadHandler;
758
- exports.experimental_createMemoryUploadHandler = createMemoryUploadHandler;
127
+ exports.experimental_NodeOnDiskFile = fileUploadHandler.NodeOnDiskFile;
128
+ exports.experimental_createFileUploadHandler = fileUploadHandler.createFileUploadHandler;
129
+ exports.MaxBodySizeExceededError = uploadHandler.MaxBodySizeExceededError;
130
+ exports.MaxPartSizeExceededError = uploadHandler.MaxPartSizeExceededError;
131
+ exports.experimental_composeUploadHandlers = uploadHandler.composeUploadHandlers;
132
+ exports.experimental_createMemoryUploadHandler = memoryUploadHandler.createMemoryUploadHandler;
759
133
  exports.experimental_isMultipartFormDataRequest = isMultipartFormDataRequest;
760
134
  exports.experimental_parseMultipartFormData = parseMultipartFormData;
761
135
  exports.nodeHTTPFormDataContentTypeHandler = nodeHTTPFormDataContentTypeHandler;