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