@comapeo/map-server 1.0.0-pre.0 → 1.0.0-pre.2
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/dist/context.d.ts +1 -1
- package/dist/context.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/lib/map-share.js +1 -1
- package/dist/routes/maps.js +1 -1
- package/dist/types.d.ts +5 -5
- package/dist/types.js +2 -2
- package/node_modules/@fastify/busboy/LICENSE +24 -0
- package/node_modules/@fastify/busboy/README.md +270 -0
- package/node_modules/@fastify/busboy/deps/dicer/LICENSE +19 -0
- package/node_modules/@fastify/busboy/deps/dicer/lib/Dicer.js +213 -0
- package/node_modules/@fastify/busboy/deps/dicer/lib/HeaderParser.js +100 -0
- package/node_modules/@fastify/busboy/deps/dicer/lib/PartStream.js +13 -0
- package/node_modules/@fastify/busboy/deps/dicer/lib/dicer.d.ts +164 -0
- package/node_modules/@fastify/busboy/deps/streamsearch/sbmh.js +230 -0
- package/node_modules/@fastify/busboy/lib/main.d.ts +196 -0
- package/node_modules/@fastify/busboy/lib/main.js +85 -0
- package/node_modules/@fastify/busboy/lib/types/multipart.js +306 -0
- package/node_modules/@fastify/busboy/lib/types/urlencoded.js +190 -0
- package/node_modules/@fastify/busboy/lib/utils/Decoder.js +54 -0
- package/node_modules/@fastify/busboy/lib/utils/basename.js +14 -0
- package/node_modules/@fastify/busboy/lib/utils/decodeText.js +114 -0
- package/node_modules/@fastify/busboy/lib/utils/getLimit.js +16 -0
- package/node_modules/@fastify/busboy/lib/utils/parseParams.js +201 -0
- package/node_modules/@fastify/busboy/package.json +81 -0
- package/node_modules/@whatwg-node/fetch/CHANGELOG.md +941 -0
- package/node_modules/@whatwg-node/fetch/README.md +141 -0
- package/node_modules/@whatwg-node/fetch/dist/create-node-ponyfill.js +100 -0
- package/node_modules/@whatwg-node/fetch/dist/esm-ponyfill.js +71 -0
- package/node_modules/@whatwg-node/fetch/dist/global-ponyfill.js +22 -0
- package/node_modules/@whatwg-node/fetch/dist/index.d.ts +73 -0
- package/node_modules/@whatwg-node/fetch/dist/node-ponyfill.js +35 -0
- package/node_modules/@whatwg-node/fetch/dist/shouldSkipPonyfill.js +17 -0
- package/node_modules/@whatwg-node/fetch/package.json +31 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/AbortError.js +19 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/Blob.js +291 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/Body.js +529 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/CompressionStream.js +34 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/DecompressionStream.js +34 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/File.js +15 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/FormData.js +150 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/Headers.js +309 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/IteratorObject.js +134 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/ReadableStream.js +245 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/Request.js +128 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/Response.js +108 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/TextEncoderDecoder.js +49 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/TextEncoderDecoderStream.js +40 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/TransformStream.js +79 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/URL.js +28 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/URLSearchParams.js +4 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/WritableStream.js +115 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/fetch.js +107 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/fetchCurl.js +142 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/fetchNodeHttp.js +152 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/index.js +42 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/package.json +1 -0
- package/node_modules/@whatwg-node/node-fetch/cjs/utils.js +125 -0
- package/node_modules/@whatwg-node/node-fetch/esm/AbortError.js +15 -0
- package/node_modules/@whatwg-node/node-fetch/esm/Blob.js +279 -0
- package/node_modules/@whatwg-node/node-fetch/esm/Body.js +525 -0
- package/node_modules/@whatwg-node/node-fetch/esm/CompressionStream.js +29 -0
- package/node_modules/@whatwg-node/node-fetch/esm/DecompressionStream.js +29 -0
- package/node_modules/@whatwg-node/node-fetch/esm/File.js +11 -0
- package/node_modules/@whatwg-node/node-fetch/esm/FormData.js +145 -0
- package/node_modules/@whatwg-node/node-fetch/esm/Headers.js +304 -0
- package/node_modules/@whatwg-node/node-fetch/esm/IteratorObject.js +130 -0
- package/node_modules/@whatwg-node/node-fetch/esm/ReadableStream.js +241 -0
- package/node_modules/@whatwg-node/node-fetch/esm/Request.js +124 -0
- package/node_modules/@whatwg-node/node-fetch/esm/Response.js +104 -0
- package/node_modules/@whatwg-node/node-fetch/esm/TextEncoderDecoder.js +43 -0
- package/node_modules/@whatwg-node/node-fetch/esm/TextEncoderDecoderStream.js +35 -0
- package/node_modules/@whatwg-node/node-fetch/esm/TransformStream.js +75 -0
- package/node_modules/@whatwg-node/node-fetch/esm/URL.js +24 -0
- package/node_modules/@whatwg-node/node-fetch/esm/URLSearchParams.js +1 -0
- package/node_modules/@whatwg-node/node-fetch/esm/WritableStream.js +111 -0
- package/node_modules/@whatwg-node/node-fetch/esm/fetch.js +104 -0
- package/node_modules/@whatwg-node/node-fetch/esm/fetchCurl.js +139 -0
- package/node_modules/@whatwg-node/node-fetch/esm/fetchNodeHttp.js +148 -0
- package/node_modules/@whatwg-node/node-fetch/esm/index.js +18 -0
- package/node_modules/@whatwg-node/node-fetch/esm/utils.js +110 -0
- package/node_modules/@whatwg-node/node-fetch/package.json +46 -0
- package/node_modules/@whatwg-node/node-fetch/typings/AbortError.d.cts +4 -0
- package/node_modules/@whatwg-node/node-fetch/typings/AbortError.d.ts +4 -0
- package/node_modules/@whatwg-node/node-fetch/typings/Blob.d.cts +63 -0
- package/node_modules/@whatwg-node/node-fetch/typings/Blob.d.ts +63 -0
- package/node_modules/@whatwg-node/node-fetch/typings/Body.d.cts +54 -0
- package/node_modules/@whatwg-node/node-fetch/typings/Body.d.ts +54 -0
- package/node_modules/@whatwg-node/node-fetch/typings/CompressionStream.d.cts +6 -0
- package/node_modules/@whatwg-node/node-fetch/typings/CompressionStream.d.ts +6 -0
- package/node_modules/@whatwg-node/node-fetch/typings/DecompressionStream.d.cts +6 -0
- package/node_modules/@whatwg-node/node-fetch/typings/DecompressionStream.d.ts +6 -0
- package/node_modules/@whatwg-node/node-fetch/typings/File.d.cts +7 -0
- package/node_modules/@whatwg-node/node-fetch/typings/File.d.ts +7 -0
- package/node_modules/@whatwg-node/node-fetch/typings/FormData.d.cts +22 -0
- package/node_modules/@whatwg-node/node-fetch/typings/FormData.d.ts +22 -0
- package/node_modules/@whatwg-node/node-fetch/typings/Headers.d.cts +26 -0
- package/node_modules/@whatwg-node/node-fetch/typings/Headers.d.ts +26 -0
- package/node_modules/@whatwg-node/node-fetch/typings/IteratorObject.d.cts +20 -0
- package/node_modules/@whatwg-node/node-fetch/typings/IteratorObject.d.ts +20 -0
- package/node_modules/@whatwg-node/node-fetch/typings/ReadableStream.d.cts +27 -0
- package/node_modules/@whatwg-node/node-fetch/typings/ReadableStream.d.ts +27 -0
- package/node_modules/@whatwg-node/node-fetch/typings/Request.d.cts +38 -0
- package/node_modules/@whatwg-node/node-fetch/typings/Request.d.ts +38 -0
- package/node_modules/@whatwg-node/node-fetch/typings/Response.d.cts +23 -0
- package/node_modules/@whatwg-node/node-fetch/typings/Response.d.ts +23 -0
- package/node_modules/@whatwg-node/node-fetch/typings/TextEncoderDecoder.d.cts +15 -0
- package/node_modules/@whatwg-node/node-fetch/typings/TextEncoderDecoder.d.ts +15 -0
- package/node_modules/@whatwg-node/node-fetch/typings/TextEncoderDecoderStream.d.cts +14 -0
- package/node_modules/@whatwg-node/node-fetch/typings/TextEncoderDecoderStream.d.ts +14 -0
- package/node_modules/@whatwg-node/node-fetch/typings/TransformStream.d.cts +9 -0
- package/node_modules/@whatwg-node/node-fetch/typings/TransformStream.d.ts +9 -0
- package/node_modules/@whatwg-node/node-fetch/typings/URL.d.cts +16 -0
- package/node_modules/@whatwg-node/node-fetch/typings/URL.d.ts +16 -0
- package/node_modules/@whatwg-node/node-fetch/typings/URLSearchParams.d.cts +4 -0
- package/node_modules/@whatwg-node/node-fetch/typings/URLSearchParams.d.ts +4 -0
- package/node_modules/@whatwg-node/node-fetch/typings/WritableStream.d.cts +9 -0
- package/node_modules/@whatwg-node/node-fetch/typings/WritableStream.d.ts +9 -0
- package/node_modules/@whatwg-node/node-fetch/typings/fetch.d.cts +3 -0
- package/node_modules/@whatwg-node/node-fetch/typings/fetch.d.ts +3 -0
- package/node_modules/@whatwg-node/node-fetch/typings/fetchCurl.d.cts +3 -0
- package/node_modules/@whatwg-node/node-fetch/typings/fetchCurl.d.ts +3 -0
- package/node_modules/@whatwg-node/node-fetch/typings/fetchNodeHttp.d.cts +3 -0
- package/node_modules/@whatwg-node/node-fetch/typings/fetchNodeHttp.d.ts +3 -0
- package/node_modules/@whatwg-node/node-fetch/typings/index.d.cts +18 -0
- package/node_modules/@whatwg-node/node-fetch/typings/index.d.ts +18 -0
- package/node_modules/@whatwg-node/node-fetch/typings/utils.d.cts +21 -0
- package/node_modules/@whatwg-node/node-fetch/typings/utils.d.ts +21 -0
- package/node_modules/@whatwg-node/server/package.json +2 -1
- package/node_modules/urlpattern-polyfill/LICENSE +19 -0
- package/node_modules/urlpattern-polyfill/README.md +242 -0
- package/node_modules/urlpattern-polyfill/dist/index.d.ts +9 -0
- package/node_modules/urlpattern-polyfill/dist/types.d.ts +49 -0
- package/node_modules/urlpattern-polyfill/dist/urlpattern.cjs +1 -0
- package/node_modules/urlpattern-polyfill/dist/urlpattern.js +1 -0
- package/node_modules/urlpattern-polyfill/index.cjs +7 -0
- package/node_modules/urlpattern-polyfill/index.js +7 -0
- package/node_modules/urlpattern-polyfill/package.json +149 -0
- package/package.json +18 -8
- package/src/context.ts +1 -1
- package/src/index.ts +2 -0
- package/src/lib/map-share.ts +1 -1
- package/src/routes/maps.ts +1 -1
- package/src/types.ts +2 -2
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
import { Buffer } from 'node:buffer';
|
|
3
|
+
import { addAbortSignal, Readable } from 'node:stream';
|
|
4
|
+
import { Busboy } from '@fastify/busboy';
|
|
5
|
+
import { handleMaybePromise } from '@whatwg-node/promise-helpers';
|
|
6
|
+
import { hasArrayBufferMethod, hasBufferMethod, hasBytesMethod, PonyfillBlob } from './Blob.js';
|
|
7
|
+
import { PonyfillFile } from './File.js';
|
|
8
|
+
import { getStreamFromFormData, PonyfillFormData } from './FormData.js';
|
|
9
|
+
import { PonyfillReadableStream } from './ReadableStream.js';
|
|
10
|
+
import { fakePromise, isArrayBufferView } from './utils.js';
|
|
11
|
+
var BodyInitType;
|
|
12
|
+
(function (BodyInitType) {
|
|
13
|
+
BodyInitType["ReadableStream"] = "ReadableStream";
|
|
14
|
+
BodyInitType["Blob"] = "Blob";
|
|
15
|
+
BodyInitType["FormData"] = "FormData";
|
|
16
|
+
BodyInitType["String"] = "String";
|
|
17
|
+
BodyInitType["Readable"] = "Readable";
|
|
18
|
+
BodyInitType["Buffer"] = "Buffer";
|
|
19
|
+
BodyInitType["AsyncIterable"] = "AsyncIterable";
|
|
20
|
+
})(BodyInitType || (BodyInitType = {}));
|
|
21
|
+
export class PonyfillBody {
|
|
22
|
+
bodyInit;
|
|
23
|
+
options;
|
|
24
|
+
bodyUsed = false;
|
|
25
|
+
contentType = null;
|
|
26
|
+
contentLength = null;
|
|
27
|
+
constructor(bodyInit, options = {}) {
|
|
28
|
+
this.bodyInit = bodyInit;
|
|
29
|
+
this.options = options;
|
|
30
|
+
const { bodyFactory, contentType, contentLength, bodyType, buffer } = processBodyInit(bodyInit);
|
|
31
|
+
this._bodyFactory = bodyFactory;
|
|
32
|
+
this.contentType = contentType;
|
|
33
|
+
this.contentLength = contentLength;
|
|
34
|
+
this.bodyType = bodyType;
|
|
35
|
+
this._buffer = buffer;
|
|
36
|
+
this._signal = options.signal;
|
|
37
|
+
}
|
|
38
|
+
bodyType;
|
|
39
|
+
_bodyFactory = () => null;
|
|
40
|
+
_generatedBody = null;
|
|
41
|
+
_buffer;
|
|
42
|
+
_signal;
|
|
43
|
+
generateBody() {
|
|
44
|
+
if (this._generatedBody?.readable?.destroyed && this._buffer) {
|
|
45
|
+
this._generatedBody.readable = Readable.from(this._buffer);
|
|
46
|
+
}
|
|
47
|
+
if (this._generatedBody) {
|
|
48
|
+
return this._generatedBody;
|
|
49
|
+
}
|
|
50
|
+
const body = this._bodyFactory();
|
|
51
|
+
this._generatedBody = body;
|
|
52
|
+
return body;
|
|
53
|
+
}
|
|
54
|
+
handleContentLengthHeader(forceSet = false) {
|
|
55
|
+
const contentTypeInHeaders = this.headers.get('content-type');
|
|
56
|
+
if (!contentTypeInHeaders) {
|
|
57
|
+
if (this.contentType) {
|
|
58
|
+
this.headers.set('content-type', this.contentType);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
this.contentType = contentTypeInHeaders;
|
|
63
|
+
}
|
|
64
|
+
const contentLengthInHeaders = this.headers.get('content-length');
|
|
65
|
+
if (forceSet && this.bodyInit == null && !contentLengthInHeaders) {
|
|
66
|
+
this.contentLength = 0;
|
|
67
|
+
this.headers.set('content-length', '0');
|
|
68
|
+
}
|
|
69
|
+
if (!contentLengthInHeaders) {
|
|
70
|
+
if (this.contentLength) {
|
|
71
|
+
this.headers.set('content-length', this.contentLength.toString());
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
this.contentLength = parseInt(contentLengthInHeaders, 10);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
get body() {
|
|
79
|
+
const _body = this.generateBody();
|
|
80
|
+
if (_body != null) {
|
|
81
|
+
const ponyfillReadableStream = _body;
|
|
82
|
+
const readable = _body.readable;
|
|
83
|
+
return new Proxy(_body.readable, {
|
|
84
|
+
get(_, prop) {
|
|
85
|
+
if (prop in ponyfillReadableStream) {
|
|
86
|
+
const ponyfillReadableStreamProp = ponyfillReadableStream[prop];
|
|
87
|
+
if (typeof ponyfillReadableStreamProp === 'function') {
|
|
88
|
+
return ponyfillReadableStreamProp.bind(ponyfillReadableStream);
|
|
89
|
+
}
|
|
90
|
+
return ponyfillReadableStreamProp;
|
|
91
|
+
}
|
|
92
|
+
if (prop in readable) {
|
|
93
|
+
const readableProp = readable[prop];
|
|
94
|
+
if (typeof readableProp === 'function') {
|
|
95
|
+
return readableProp.bind(readable);
|
|
96
|
+
}
|
|
97
|
+
return readableProp;
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
_chunks = null;
|
|
105
|
+
_doCollectChunksFromReadableJob() {
|
|
106
|
+
if (this.bodyType === BodyInitType.AsyncIterable) {
|
|
107
|
+
if (Array.fromAsync) {
|
|
108
|
+
return handleMaybePromise(() => Array.fromAsync(this.bodyInit), chunks => {
|
|
109
|
+
this._chunks = chunks;
|
|
110
|
+
return this._chunks;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
const iterator = this.bodyInit[Symbol.asyncIterator]();
|
|
114
|
+
const chunks = [];
|
|
115
|
+
const collectValue = () => handleMaybePromise(() => iterator.next(), ({ value, done }) => {
|
|
116
|
+
if (value) {
|
|
117
|
+
chunks.push(value);
|
|
118
|
+
}
|
|
119
|
+
if (!done) {
|
|
120
|
+
return collectValue();
|
|
121
|
+
}
|
|
122
|
+
this._chunks = chunks;
|
|
123
|
+
return this._chunks;
|
|
124
|
+
});
|
|
125
|
+
return collectValue();
|
|
126
|
+
}
|
|
127
|
+
const _body = this.generateBody();
|
|
128
|
+
if (!_body) {
|
|
129
|
+
this._chunks = [];
|
|
130
|
+
return fakePromise(this._chunks);
|
|
131
|
+
}
|
|
132
|
+
if (_body.readable.destroyed) {
|
|
133
|
+
return fakePromise((this._chunks = []));
|
|
134
|
+
}
|
|
135
|
+
const chunks = [];
|
|
136
|
+
return new Promise((resolve, reject) => {
|
|
137
|
+
_body.readable.on('data', chunk => {
|
|
138
|
+
chunks.push(chunk);
|
|
139
|
+
});
|
|
140
|
+
_body.readable.once('error', reject);
|
|
141
|
+
_body.readable.once('end', () => {
|
|
142
|
+
resolve((this._chunks = chunks));
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
_collectChunksFromReadable() {
|
|
147
|
+
if (this._chunks) {
|
|
148
|
+
return fakePromise(this._chunks);
|
|
149
|
+
}
|
|
150
|
+
this._chunks ||= this._doCollectChunksFromReadableJob();
|
|
151
|
+
return this._chunks;
|
|
152
|
+
}
|
|
153
|
+
_blob = null;
|
|
154
|
+
blob() {
|
|
155
|
+
if (this._blob) {
|
|
156
|
+
return fakePromise(this._blob);
|
|
157
|
+
}
|
|
158
|
+
if (this.bodyType === BodyInitType.String) {
|
|
159
|
+
this._text = this.bodyInit;
|
|
160
|
+
this._blob = new PonyfillBlob([this._text], {
|
|
161
|
+
type: this.contentType || 'text/plain;charset=UTF-8',
|
|
162
|
+
size: this.contentLength,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
if (this.bodyType === BodyInitType.Blob) {
|
|
166
|
+
this._blob = this.bodyInit;
|
|
167
|
+
return fakePromise(this._blob);
|
|
168
|
+
}
|
|
169
|
+
if (this._buffer) {
|
|
170
|
+
this._blob = new PonyfillBlob([this._buffer], {
|
|
171
|
+
type: this.contentType || '',
|
|
172
|
+
size: this.contentLength,
|
|
173
|
+
});
|
|
174
|
+
return fakePromise(this._blob);
|
|
175
|
+
}
|
|
176
|
+
return fakePromise(handleMaybePromise(() => this._collectChunksFromReadable(), chunks => {
|
|
177
|
+
this._blob = new PonyfillBlob(chunks, {
|
|
178
|
+
type: this.contentType || '',
|
|
179
|
+
size: this.contentLength,
|
|
180
|
+
});
|
|
181
|
+
return this._blob;
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
_formData = null;
|
|
185
|
+
formData(opts) {
|
|
186
|
+
if (this._formData) {
|
|
187
|
+
return fakePromise(this._formData);
|
|
188
|
+
}
|
|
189
|
+
if (this.bodyType === BodyInitType.FormData) {
|
|
190
|
+
this._formData = this.bodyInit;
|
|
191
|
+
return fakePromise(this._formData);
|
|
192
|
+
}
|
|
193
|
+
this._formData = new PonyfillFormData();
|
|
194
|
+
const _body = this.generateBody();
|
|
195
|
+
if (_body == null) {
|
|
196
|
+
return fakePromise(this._formData);
|
|
197
|
+
}
|
|
198
|
+
const formDataLimits = {
|
|
199
|
+
...this.options.formDataLimits,
|
|
200
|
+
...opts?.formDataLimits,
|
|
201
|
+
};
|
|
202
|
+
return new Promise((resolve, reject) => {
|
|
203
|
+
const stream = this.body?.readable;
|
|
204
|
+
if (!stream) {
|
|
205
|
+
return reject(new Error('No stream available'));
|
|
206
|
+
}
|
|
207
|
+
// form data file that is currently being processed, it's
|
|
208
|
+
// important to keep track of it in case the stream ends early
|
|
209
|
+
let currFile = null;
|
|
210
|
+
const bb = new Busboy({
|
|
211
|
+
headers: {
|
|
212
|
+
'content-length': typeof this.contentLength === 'number'
|
|
213
|
+
? this.contentLength.toString()
|
|
214
|
+
: this.contentLength || '',
|
|
215
|
+
'content-type': this.contentType || '',
|
|
216
|
+
},
|
|
217
|
+
limits: formDataLimits,
|
|
218
|
+
defCharset: 'utf-8',
|
|
219
|
+
});
|
|
220
|
+
if (this._signal) {
|
|
221
|
+
addAbortSignal(this._signal, bb);
|
|
222
|
+
}
|
|
223
|
+
let completed = false;
|
|
224
|
+
const complete = (err) => {
|
|
225
|
+
if (completed)
|
|
226
|
+
return;
|
|
227
|
+
completed = true;
|
|
228
|
+
stream.unpipe(bb);
|
|
229
|
+
bb.destroy();
|
|
230
|
+
if (currFile) {
|
|
231
|
+
currFile.destroy();
|
|
232
|
+
currFile = null;
|
|
233
|
+
}
|
|
234
|
+
if (err) {
|
|
235
|
+
reject(err);
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
// no error occured, this is a successful end/complete/finish
|
|
239
|
+
resolve(this._formData);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
// we dont need to listen to the stream close event because bb will close or error when necessary
|
|
243
|
+
// stream.on('close', complete);
|
|
244
|
+
// stream can be aborted, for example
|
|
245
|
+
stream.on('error', complete);
|
|
246
|
+
bb.on('field', (name, value, fieldnameTruncated, valueTruncated) => {
|
|
247
|
+
if (fieldnameTruncated) {
|
|
248
|
+
return complete(new Error(`Field name size exceeded: ${formDataLimits?.fieldNameSize} bytes`));
|
|
249
|
+
}
|
|
250
|
+
if (valueTruncated) {
|
|
251
|
+
return complete(new Error(`Field value size exceeded: ${formDataLimits?.fieldSize} bytes`));
|
|
252
|
+
}
|
|
253
|
+
this._formData.set(name, value);
|
|
254
|
+
});
|
|
255
|
+
bb.on('file', (name, fileStream, filename, _transferEncoding, mimeType) => {
|
|
256
|
+
currFile = fileStream;
|
|
257
|
+
const chunks = [];
|
|
258
|
+
fileStream.on('data', chunk => {
|
|
259
|
+
chunks.push(chunk);
|
|
260
|
+
});
|
|
261
|
+
fileStream.on('error', complete);
|
|
262
|
+
fileStream.on('limit', () => {
|
|
263
|
+
complete(new Error(`File size limit exceeded: ${formDataLimits?.fileSize} bytes`));
|
|
264
|
+
});
|
|
265
|
+
fileStream.on('close', () => {
|
|
266
|
+
if (fileStream.truncated) {
|
|
267
|
+
complete(new Error(`File size limit exceeded: ${formDataLimits?.fileSize} bytes`));
|
|
268
|
+
}
|
|
269
|
+
currFile = null;
|
|
270
|
+
const file = new PonyfillFile(chunks, filename, { type: mimeType });
|
|
271
|
+
this._formData.set(name, file);
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
bb.on('fieldsLimit', () => {
|
|
275
|
+
complete(new Error(`Fields limit exceeded: ${formDataLimits?.fields}`));
|
|
276
|
+
});
|
|
277
|
+
bb.on('filesLimit', () => {
|
|
278
|
+
complete(new Error(`Files limit exceeded: ${formDataLimits?.files}`));
|
|
279
|
+
});
|
|
280
|
+
bb.on('partsLimit', () => {
|
|
281
|
+
complete(new Error(`Parts limit exceeded: ${formDataLimits?.parts}`));
|
|
282
|
+
});
|
|
283
|
+
bb.on('end', complete);
|
|
284
|
+
bb.on('finish', complete);
|
|
285
|
+
bb.on('close', complete);
|
|
286
|
+
bb.on('error', complete);
|
|
287
|
+
stream.pipe(bb);
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
buffer() {
|
|
291
|
+
if (this._buffer) {
|
|
292
|
+
return fakePromise(this._buffer);
|
|
293
|
+
}
|
|
294
|
+
if (this._text) {
|
|
295
|
+
this._buffer = Buffer.from(this._text, 'utf-8');
|
|
296
|
+
return fakePromise(this._buffer);
|
|
297
|
+
}
|
|
298
|
+
if (this.bodyType === BodyInitType.String) {
|
|
299
|
+
return this.text().then(text => {
|
|
300
|
+
this._text = text;
|
|
301
|
+
this._buffer = Buffer.from(text, 'utf-8');
|
|
302
|
+
return this._buffer;
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
if (this.bodyType === BodyInitType.Blob) {
|
|
306
|
+
if (hasBufferMethod(this.bodyInit)) {
|
|
307
|
+
return this.bodyInit.buffer().then(buf => {
|
|
308
|
+
this._buffer = buf;
|
|
309
|
+
return this._buffer;
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
if (hasBytesMethod(this.bodyInit)) {
|
|
313
|
+
return this.bodyInit.bytes().then(bytes => {
|
|
314
|
+
this._buffer = Buffer.from(bytes);
|
|
315
|
+
return this._buffer;
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
if (hasArrayBufferMethod(this.bodyInit)) {
|
|
319
|
+
return this.bodyInit.arrayBuffer().then(buf => {
|
|
320
|
+
this._buffer = Buffer.from(buf, undefined, buf.byteLength);
|
|
321
|
+
return this._buffer;
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return fakePromise(handleMaybePromise(() => this._collectChunksFromReadable(), chunks => {
|
|
326
|
+
if (chunks.length === 1) {
|
|
327
|
+
this._buffer = chunks[0];
|
|
328
|
+
return this._buffer;
|
|
329
|
+
}
|
|
330
|
+
this._buffer = Buffer.concat(chunks);
|
|
331
|
+
return this._buffer;
|
|
332
|
+
}));
|
|
333
|
+
}
|
|
334
|
+
bytes() {
|
|
335
|
+
return this.buffer();
|
|
336
|
+
}
|
|
337
|
+
arrayBuffer() {
|
|
338
|
+
// @ts-ignore - Mismatch between Buffer and ArrayBuffer
|
|
339
|
+
return this.buffer();
|
|
340
|
+
}
|
|
341
|
+
_json = null;
|
|
342
|
+
json() {
|
|
343
|
+
if (this._json) {
|
|
344
|
+
return fakePromise(this._json);
|
|
345
|
+
}
|
|
346
|
+
return this.text().then(text => {
|
|
347
|
+
try {
|
|
348
|
+
this._json = JSON.parse(text);
|
|
349
|
+
}
|
|
350
|
+
catch (e) {
|
|
351
|
+
if (e instanceof SyntaxError) {
|
|
352
|
+
e.message += `, "${text}" is not valid JSON`;
|
|
353
|
+
}
|
|
354
|
+
throw e;
|
|
355
|
+
}
|
|
356
|
+
return this._json;
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
_text = null;
|
|
360
|
+
text() {
|
|
361
|
+
if (this._text) {
|
|
362
|
+
return fakePromise(this._text);
|
|
363
|
+
}
|
|
364
|
+
if (this.bodyType === BodyInitType.String) {
|
|
365
|
+
this._text = this.bodyInit;
|
|
366
|
+
return fakePromise(this._text);
|
|
367
|
+
}
|
|
368
|
+
return this.buffer().then(buffer => {
|
|
369
|
+
this._text = buffer.toString('utf-8');
|
|
370
|
+
return this._text;
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
function processBodyInit(bodyInit) {
|
|
375
|
+
if (bodyInit == null) {
|
|
376
|
+
return {
|
|
377
|
+
bodyFactory: () => null,
|
|
378
|
+
contentType: null,
|
|
379
|
+
contentLength: null,
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
if (typeof bodyInit === 'string') {
|
|
383
|
+
const contentLength = Buffer.byteLength(bodyInit);
|
|
384
|
+
return {
|
|
385
|
+
bodyType: BodyInitType.String,
|
|
386
|
+
contentType: 'text/plain;charset=UTF-8',
|
|
387
|
+
contentLength,
|
|
388
|
+
bodyFactory() {
|
|
389
|
+
const readable = Readable.from(Buffer.from(bodyInit, 'utf-8'));
|
|
390
|
+
return new PonyfillReadableStream(readable);
|
|
391
|
+
},
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
if (Buffer.isBuffer(bodyInit)) {
|
|
395
|
+
const buffer = bodyInit;
|
|
396
|
+
return {
|
|
397
|
+
bodyType: BodyInitType.Buffer,
|
|
398
|
+
contentType: null,
|
|
399
|
+
contentLength: bodyInit.length,
|
|
400
|
+
buffer: bodyInit,
|
|
401
|
+
bodyFactory() {
|
|
402
|
+
const readable = Readable.from(buffer);
|
|
403
|
+
const body = new PonyfillReadableStream(readable);
|
|
404
|
+
return body;
|
|
405
|
+
},
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
if (isArrayBufferView(bodyInit)) {
|
|
409
|
+
const buffer = Buffer.from(bodyInit.buffer, bodyInit.byteOffset, bodyInit.byteLength);
|
|
410
|
+
return {
|
|
411
|
+
bodyType: BodyInitType.Buffer,
|
|
412
|
+
contentLength: bodyInit.byteLength,
|
|
413
|
+
contentType: null,
|
|
414
|
+
buffer,
|
|
415
|
+
bodyFactory() {
|
|
416
|
+
const readable = Readable.from(buffer);
|
|
417
|
+
const body = new PonyfillReadableStream(readable);
|
|
418
|
+
return body;
|
|
419
|
+
},
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
if (bodyInit instanceof PonyfillReadableStream && bodyInit.readable != null) {
|
|
423
|
+
const readableStream = bodyInit;
|
|
424
|
+
return {
|
|
425
|
+
bodyType: BodyInitType.ReadableStream,
|
|
426
|
+
bodyFactory: () => readableStream,
|
|
427
|
+
contentType: null,
|
|
428
|
+
contentLength: null,
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
if (isBlob(bodyInit)) {
|
|
432
|
+
const blob = bodyInit;
|
|
433
|
+
return {
|
|
434
|
+
bodyType: BodyInitType.Blob,
|
|
435
|
+
contentType: bodyInit.type,
|
|
436
|
+
contentLength: bodyInit.size,
|
|
437
|
+
bodyFactory() {
|
|
438
|
+
return blob.stream();
|
|
439
|
+
},
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
if (bodyInit instanceof ArrayBuffer) {
|
|
443
|
+
const contentLength = bodyInit.byteLength;
|
|
444
|
+
const buffer = Buffer.from(bodyInit, undefined, bodyInit.byteLength);
|
|
445
|
+
return {
|
|
446
|
+
bodyType: BodyInitType.Buffer,
|
|
447
|
+
contentType: null,
|
|
448
|
+
contentLength,
|
|
449
|
+
buffer,
|
|
450
|
+
bodyFactory() {
|
|
451
|
+
const readable = Readable.from(buffer);
|
|
452
|
+
const body = new PonyfillReadableStream(readable);
|
|
453
|
+
return body;
|
|
454
|
+
},
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
if (bodyInit instanceof Readable) {
|
|
458
|
+
return {
|
|
459
|
+
bodyType: BodyInitType.Readable,
|
|
460
|
+
contentType: null,
|
|
461
|
+
contentLength: null,
|
|
462
|
+
bodyFactory() {
|
|
463
|
+
const body = new PonyfillReadableStream(bodyInit);
|
|
464
|
+
return body;
|
|
465
|
+
},
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
if (isURLSearchParams(bodyInit)) {
|
|
469
|
+
const contentType = 'application/x-www-form-urlencoded;charset=UTF-8';
|
|
470
|
+
return {
|
|
471
|
+
bodyType: BodyInitType.String,
|
|
472
|
+
contentType,
|
|
473
|
+
contentLength: null,
|
|
474
|
+
bodyFactory() {
|
|
475
|
+
const body = new PonyfillReadableStream(Readable.from(bodyInit.toString()));
|
|
476
|
+
return body;
|
|
477
|
+
},
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
if (isFormData(bodyInit)) {
|
|
481
|
+
const boundary = Math.random().toString(36).substr(2);
|
|
482
|
+
const contentType = `multipart/form-data; boundary=${boundary}`;
|
|
483
|
+
return {
|
|
484
|
+
bodyType: BodyInitType.FormData,
|
|
485
|
+
contentType,
|
|
486
|
+
contentLength: null,
|
|
487
|
+
bodyFactory() {
|
|
488
|
+
return getStreamFromFormData(bodyInit, boundary);
|
|
489
|
+
},
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
if (isReadableStream(bodyInit)) {
|
|
493
|
+
return {
|
|
494
|
+
contentType: null,
|
|
495
|
+
contentLength: null,
|
|
496
|
+
bodyFactory() {
|
|
497
|
+
return new PonyfillReadableStream(bodyInit);
|
|
498
|
+
},
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
if (bodyInit[Symbol.iterator] || bodyInit[Symbol.asyncIterator]) {
|
|
502
|
+
return {
|
|
503
|
+
contentType: null,
|
|
504
|
+
contentLength: null,
|
|
505
|
+
bodyType: BodyInitType.AsyncIterable,
|
|
506
|
+
bodyFactory() {
|
|
507
|
+
const readable = Readable.from(bodyInit);
|
|
508
|
+
return new PonyfillReadableStream(readable);
|
|
509
|
+
},
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
throw new Error('Unknown body type');
|
|
513
|
+
}
|
|
514
|
+
function isFormData(value) {
|
|
515
|
+
return value?.forEach != null;
|
|
516
|
+
}
|
|
517
|
+
function isBlob(value) {
|
|
518
|
+
return value?.stream != null && typeof value.stream === 'function';
|
|
519
|
+
}
|
|
520
|
+
function isURLSearchParams(value) {
|
|
521
|
+
return value?.sort != null;
|
|
522
|
+
}
|
|
523
|
+
function isReadableStream(value) {
|
|
524
|
+
return value?.getReader != null;
|
|
525
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import zlib from 'node:zlib';
|
|
2
|
+
import { PonyfillTransformStream } from './TransformStream.js';
|
|
3
|
+
import { getSupportedFormats } from './utils.js';
|
|
4
|
+
export class PonyfillCompressionStream extends PonyfillTransformStream {
|
|
5
|
+
static supportedFormats = getSupportedFormats();
|
|
6
|
+
constructor(compressionFormat) {
|
|
7
|
+
switch (compressionFormat) {
|
|
8
|
+
case 'x-gzip':
|
|
9
|
+
case 'gzip':
|
|
10
|
+
super(zlib.createGzip());
|
|
11
|
+
break;
|
|
12
|
+
case 'x-deflate':
|
|
13
|
+
case 'deflate':
|
|
14
|
+
super(zlib.createDeflate());
|
|
15
|
+
break;
|
|
16
|
+
case 'deflate-raw':
|
|
17
|
+
super(zlib.createDeflateRaw());
|
|
18
|
+
break;
|
|
19
|
+
case 'br':
|
|
20
|
+
super(zlib.createBrotliCompress());
|
|
21
|
+
break;
|
|
22
|
+
case 'zstd':
|
|
23
|
+
super(zlib.createZstdCompress());
|
|
24
|
+
break;
|
|
25
|
+
default:
|
|
26
|
+
throw new Error(`Unsupported compression format: ${compressionFormat}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import zlib from 'node:zlib';
|
|
2
|
+
import { PonyfillTransformStream } from './TransformStream.js';
|
|
3
|
+
import { getSupportedFormats } from './utils.js';
|
|
4
|
+
export class PonyfillDecompressionStream extends PonyfillTransformStream {
|
|
5
|
+
static supportedFormats = getSupportedFormats();
|
|
6
|
+
constructor(compressionFormat) {
|
|
7
|
+
switch (compressionFormat) {
|
|
8
|
+
case 'x-gzip':
|
|
9
|
+
case 'gzip':
|
|
10
|
+
super(zlib.createGunzip());
|
|
11
|
+
break;
|
|
12
|
+
case 'x-deflate':
|
|
13
|
+
case 'deflate':
|
|
14
|
+
super(zlib.createInflate());
|
|
15
|
+
break;
|
|
16
|
+
case 'deflate-raw':
|
|
17
|
+
super(zlib.createInflateRaw());
|
|
18
|
+
break;
|
|
19
|
+
case 'br':
|
|
20
|
+
super(zlib.createBrotliDecompress());
|
|
21
|
+
break;
|
|
22
|
+
case 'zstd':
|
|
23
|
+
super(zlib.createZstdDecompress());
|
|
24
|
+
break;
|
|
25
|
+
default:
|
|
26
|
+
throw new TypeError(`Unsupported compression format: '${compressionFormat}'`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PonyfillBlob } from './Blob.js';
|
|
2
|
+
export class PonyfillFile extends PonyfillBlob {
|
|
3
|
+
name;
|
|
4
|
+
lastModified;
|
|
5
|
+
constructor(fileBits, name, options) {
|
|
6
|
+
super(fileBits, options);
|
|
7
|
+
this.name = name;
|
|
8
|
+
this.lastModified = options?.lastModified || Date.now();
|
|
9
|
+
}
|
|
10
|
+
webkitRelativePath = '';
|
|
11
|
+
}
|