@trpc/server 11.0.0-alpha-tmp-export-from-main.221 → 11.0.0-alpha-tmp-export-from-main.222

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