@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.
Files changed (168) hide show
  1. package/README.md +5 -6
  2. package/dist/context.d.ts +1 -1
  3. package/dist/context.js +1 -1
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +2 -2
  7. package/dist/lib/download-request.d.ts.map +1 -1
  8. package/dist/lib/download-request.js +2 -3
  9. package/dist/lib/map-share.d.ts +1 -1
  10. package/dist/lib/map-share.d.ts.map +1 -1
  11. package/dist/lib/map-share.js +2 -2
  12. package/dist/lib/secret-stream-fetch.d.ts +1 -1
  13. package/dist/lib/secret-stream-fetch.d.ts.map +1 -1
  14. package/dist/lib/secret-stream-fetch.js +2 -1
  15. package/dist/lib/utils.d.ts +1 -0
  16. package/dist/lib/utils.d.ts.map +1 -1
  17. package/dist/lib/utils.js +6 -2
  18. package/dist/routes/downloads.d.ts +1 -1
  19. package/dist/routes/map-shares.d.ts +1 -1
  20. package/dist/routes/map-shares.d.ts.map +1 -1
  21. package/dist/routes/map-shares.js +7 -2
  22. package/dist/routes/maps.js +1 -1
  23. package/dist/types.d.ts +8 -8
  24. package/dist/types.d.ts.map +1 -1
  25. package/dist/types.js +4 -4
  26. package/node_modules/@fastify/busboy/LICENSE +24 -0
  27. package/node_modules/@fastify/busboy/README.md +270 -0
  28. package/node_modules/@fastify/busboy/deps/dicer/LICENSE +19 -0
  29. package/node_modules/@fastify/busboy/deps/dicer/lib/Dicer.js +213 -0
  30. package/node_modules/@fastify/busboy/deps/dicer/lib/HeaderParser.js +100 -0
  31. package/node_modules/@fastify/busboy/deps/dicer/lib/PartStream.js +13 -0
  32. package/node_modules/@fastify/busboy/deps/dicer/lib/dicer.d.ts +164 -0
  33. package/node_modules/@fastify/busboy/deps/streamsearch/sbmh.js +230 -0
  34. package/node_modules/@fastify/busboy/lib/main.d.ts +196 -0
  35. package/node_modules/@fastify/busboy/lib/main.js +85 -0
  36. package/node_modules/@fastify/busboy/lib/types/multipart.js +306 -0
  37. package/node_modules/@fastify/busboy/lib/types/urlencoded.js +190 -0
  38. package/node_modules/@fastify/busboy/lib/utils/Decoder.js +54 -0
  39. package/node_modules/@fastify/busboy/lib/utils/basename.js +14 -0
  40. package/node_modules/@fastify/busboy/lib/utils/decodeText.js +114 -0
  41. package/node_modules/@fastify/busboy/lib/utils/getLimit.js +16 -0
  42. package/node_modules/@fastify/busboy/lib/utils/parseParams.js +201 -0
  43. package/node_modules/@fastify/busboy/package.json +81 -0
  44. package/node_modules/@whatwg-node/fetch/CHANGELOG.md +941 -0
  45. package/node_modules/@whatwg-node/fetch/README.md +141 -0
  46. package/node_modules/@whatwg-node/fetch/dist/create-node-ponyfill.js +100 -0
  47. package/node_modules/@whatwg-node/fetch/dist/esm-ponyfill.js +71 -0
  48. package/node_modules/@whatwg-node/fetch/dist/global-ponyfill.js +22 -0
  49. package/node_modules/@whatwg-node/fetch/dist/index.d.ts +73 -0
  50. package/node_modules/@whatwg-node/fetch/dist/node-ponyfill.js +35 -0
  51. package/node_modules/@whatwg-node/fetch/dist/shouldSkipPonyfill.js +17 -0
  52. package/node_modules/@whatwg-node/fetch/package.json +31 -0
  53. package/node_modules/@whatwg-node/node-fetch/cjs/AbortError.js +19 -0
  54. package/node_modules/@whatwg-node/node-fetch/cjs/Blob.js +291 -0
  55. package/node_modules/@whatwg-node/node-fetch/cjs/Body.js +529 -0
  56. package/node_modules/@whatwg-node/node-fetch/cjs/CompressionStream.js +34 -0
  57. package/node_modules/@whatwg-node/node-fetch/cjs/DecompressionStream.js +34 -0
  58. package/node_modules/@whatwg-node/node-fetch/cjs/File.js +15 -0
  59. package/node_modules/@whatwg-node/node-fetch/cjs/FormData.js +150 -0
  60. package/node_modules/@whatwg-node/node-fetch/cjs/Headers.js +309 -0
  61. package/node_modules/@whatwg-node/node-fetch/cjs/IteratorObject.js +134 -0
  62. package/node_modules/@whatwg-node/node-fetch/cjs/ReadableStream.js +245 -0
  63. package/node_modules/@whatwg-node/node-fetch/cjs/Request.js +128 -0
  64. package/node_modules/@whatwg-node/node-fetch/cjs/Response.js +108 -0
  65. package/node_modules/@whatwg-node/node-fetch/cjs/TextEncoderDecoder.js +49 -0
  66. package/node_modules/@whatwg-node/node-fetch/cjs/TextEncoderDecoderStream.js +40 -0
  67. package/node_modules/@whatwg-node/node-fetch/cjs/TransformStream.js +79 -0
  68. package/node_modules/@whatwg-node/node-fetch/cjs/URL.js +28 -0
  69. package/node_modules/@whatwg-node/node-fetch/cjs/URLSearchParams.js +4 -0
  70. package/node_modules/@whatwg-node/node-fetch/cjs/WritableStream.js +115 -0
  71. package/node_modules/@whatwg-node/node-fetch/cjs/fetch.js +107 -0
  72. package/node_modules/@whatwg-node/node-fetch/cjs/fetchCurl.js +142 -0
  73. package/node_modules/@whatwg-node/node-fetch/cjs/fetchNodeHttp.js +152 -0
  74. package/node_modules/@whatwg-node/node-fetch/cjs/index.js +42 -0
  75. package/node_modules/@whatwg-node/node-fetch/cjs/package.json +1 -0
  76. package/node_modules/@whatwg-node/node-fetch/cjs/utils.js +125 -0
  77. package/node_modules/@whatwg-node/node-fetch/esm/AbortError.js +15 -0
  78. package/node_modules/@whatwg-node/node-fetch/esm/Blob.js +279 -0
  79. package/node_modules/@whatwg-node/node-fetch/esm/Body.js +525 -0
  80. package/node_modules/@whatwg-node/node-fetch/esm/CompressionStream.js +29 -0
  81. package/node_modules/@whatwg-node/node-fetch/esm/DecompressionStream.js +29 -0
  82. package/node_modules/@whatwg-node/node-fetch/esm/File.js +11 -0
  83. package/node_modules/@whatwg-node/node-fetch/esm/FormData.js +145 -0
  84. package/node_modules/@whatwg-node/node-fetch/esm/Headers.js +304 -0
  85. package/node_modules/@whatwg-node/node-fetch/esm/IteratorObject.js +130 -0
  86. package/node_modules/@whatwg-node/node-fetch/esm/ReadableStream.js +241 -0
  87. package/node_modules/@whatwg-node/node-fetch/esm/Request.js +124 -0
  88. package/node_modules/@whatwg-node/node-fetch/esm/Response.js +104 -0
  89. package/node_modules/@whatwg-node/node-fetch/esm/TextEncoderDecoder.js +43 -0
  90. package/node_modules/@whatwg-node/node-fetch/esm/TextEncoderDecoderStream.js +35 -0
  91. package/node_modules/@whatwg-node/node-fetch/esm/TransformStream.js +75 -0
  92. package/node_modules/@whatwg-node/node-fetch/esm/URL.js +24 -0
  93. package/node_modules/@whatwg-node/node-fetch/esm/URLSearchParams.js +1 -0
  94. package/node_modules/@whatwg-node/node-fetch/esm/WritableStream.js +111 -0
  95. package/node_modules/@whatwg-node/node-fetch/esm/fetch.js +104 -0
  96. package/node_modules/@whatwg-node/node-fetch/esm/fetchCurl.js +139 -0
  97. package/node_modules/@whatwg-node/node-fetch/esm/fetchNodeHttp.js +148 -0
  98. package/node_modules/@whatwg-node/node-fetch/esm/index.js +18 -0
  99. package/node_modules/@whatwg-node/node-fetch/esm/utils.js +110 -0
  100. package/node_modules/@whatwg-node/node-fetch/package.json +46 -0
  101. package/node_modules/@whatwg-node/node-fetch/typings/AbortError.d.cts +4 -0
  102. package/node_modules/@whatwg-node/node-fetch/typings/AbortError.d.ts +4 -0
  103. package/node_modules/@whatwg-node/node-fetch/typings/Blob.d.cts +63 -0
  104. package/node_modules/@whatwg-node/node-fetch/typings/Blob.d.ts +63 -0
  105. package/node_modules/@whatwg-node/node-fetch/typings/Body.d.cts +54 -0
  106. package/node_modules/@whatwg-node/node-fetch/typings/Body.d.ts +54 -0
  107. package/node_modules/@whatwg-node/node-fetch/typings/CompressionStream.d.cts +6 -0
  108. package/node_modules/@whatwg-node/node-fetch/typings/CompressionStream.d.ts +6 -0
  109. package/node_modules/@whatwg-node/node-fetch/typings/DecompressionStream.d.cts +6 -0
  110. package/node_modules/@whatwg-node/node-fetch/typings/DecompressionStream.d.ts +6 -0
  111. package/node_modules/@whatwg-node/node-fetch/typings/File.d.cts +7 -0
  112. package/node_modules/@whatwg-node/node-fetch/typings/File.d.ts +7 -0
  113. package/node_modules/@whatwg-node/node-fetch/typings/FormData.d.cts +22 -0
  114. package/node_modules/@whatwg-node/node-fetch/typings/FormData.d.ts +22 -0
  115. package/node_modules/@whatwg-node/node-fetch/typings/Headers.d.cts +26 -0
  116. package/node_modules/@whatwg-node/node-fetch/typings/Headers.d.ts +26 -0
  117. package/node_modules/@whatwg-node/node-fetch/typings/IteratorObject.d.cts +20 -0
  118. package/node_modules/@whatwg-node/node-fetch/typings/IteratorObject.d.ts +20 -0
  119. package/node_modules/@whatwg-node/node-fetch/typings/ReadableStream.d.cts +27 -0
  120. package/node_modules/@whatwg-node/node-fetch/typings/ReadableStream.d.ts +27 -0
  121. package/node_modules/@whatwg-node/node-fetch/typings/Request.d.cts +38 -0
  122. package/node_modules/@whatwg-node/node-fetch/typings/Request.d.ts +38 -0
  123. package/node_modules/@whatwg-node/node-fetch/typings/Response.d.cts +23 -0
  124. package/node_modules/@whatwg-node/node-fetch/typings/Response.d.ts +23 -0
  125. package/node_modules/@whatwg-node/node-fetch/typings/TextEncoderDecoder.d.cts +15 -0
  126. package/node_modules/@whatwg-node/node-fetch/typings/TextEncoderDecoder.d.ts +15 -0
  127. package/node_modules/@whatwg-node/node-fetch/typings/TextEncoderDecoderStream.d.cts +14 -0
  128. package/node_modules/@whatwg-node/node-fetch/typings/TextEncoderDecoderStream.d.ts +14 -0
  129. package/node_modules/@whatwg-node/node-fetch/typings/TransformStream.d.cts +9 -0
  130. package/node_modules/@whatwg-node/node-fetch/typings/TransformStream.d.ts +9 -0
  131. package/node_modules/@whatwg-node/node-fetch/typings/URL.d.cts +16 -0
  132. package/node_modules/@whatwg-node/node-fetch/typings/URL.d.ts +16 -0
  133. package/node_modules/@whatwg-node/node-fetch/typings/URLSearchParams.d.cts +4 -0
  134. package/node_modules/@whatwg-node/node-fetch/typings/URLSearchParams.d.ts +4 -0
  135. package/node_modules/@whatwg-node/node-fetch/typings/WritableStream.d.cts +9 -0
  136. package/node_modules/@whatwg-node/node-fetch/typings/WritableStream.d.ts +9 -0
  137. package/node_modules/@whatwg-node/node-fetch/typings/fetch.d.cts +3 -0
  138. package/node_modules/@whatwg-node/node-fetch/typings/fetch.d.ts +3 -0
  139. package/node_modules/@whatwg-node/node-fetch/typings/fetchCurl.d.cts +3 -0
  140. package/node_modules/@whatwg-node/node-fetch/typings/fetchCurl.d.ts +3 -0
  141. package/node_modules/@whatwg-node/node-fetch/typings/fetchNodeHttp.d.cts +3 -0
  142. package/node_modules/@whatwg-node/node-fetch/typings/fetchNodeHttp.d.ts +3 -0
  143. package/node_modules/@whatwg-node/node-fetch/typings/index.d.cts +18 -0
  144. package/node_modules/@whatwg-node/node-fetch/typings/index.d.ts +18 -0
  145. package/node_modules/@whatwg-node/node-fetch/typings/utils.d.cts +21 -0
  146. package/node_modules/@whatwg-node/node-fetch/typings/utils.d.ts +21 -0
  147. package/node_modules/@whatwg-node/server/cjs/index.js +0 -3
  148. package/node_modules/@whatwg-node/server/esm/index.js +0 -2
  149. package/node_modules/@whatwg-node/server/package.json +2 -1
  150. package/node_modules/urlpattern-polyfill/LICENSE +19 -0
  151. package/node_modules/urlpattern-polyfill/README.md +242 -0
  152. package/node_modules/urlpattern-polyfill/dist/index.d.ts +9 -0
  153. package/node_modules/urlpattern-polyfill/dist/types.d.ts +49 -0
  154. package/node_modules/urlpattern-polyfill/dist/urlpattern.cjs +1 -0
  155. package/node_modules/urlpattern-polyfill/dist/urlpattern.js +1 -0
  156. package/node_modules/urlpattern-polyfill/index.cjs +7 -0
  157. package/node_modules/urlpattern-polyfill/index.js +7 -0
  158. package/node_modules/urlpattern-polyfill/package.json +149 -0
  159. package/package.json +19 -10
  160. package/src/context.ts +1 -1
  161. package/src/index.ts +3 -2
  162. package/src/lib/download-request.ts +3 -4
  163. package/src/lib/map-share.ts +3 -3
  164. package/src/lib/secret-stream-fetch.ts +3 -2
  165. package/src/lib/utils.ts +9 -2
  166. package/src/routes/map-shares.ts +12 -3
  167. package/src/routes/maps.ts +1 -1
  168. package/src/types.ts +9 -7
@@ -0,0 +1,241 @@
1
+ import { Buffer } from 'node:buffer';
2
+ import { once } from 'node:events';
3
+ import { Readable } from 'node:stream';
4
+ import { pipeline } from 'node:stream/promises';
5
+ import { handleMaybePromise } from '@whatwg-node/promise-helpers';
6
+ import { fakePromise } from './utils.js';
7
+ function createController(desiredSize, readable) {
8
+ let chunks = [];
9
+ let _closed = false;
10
+ let flushed = false;
11
+ return {
12
+ desiredSize,
13
+ enqueue(chunk) {
14
+ const buf = typeof chunk === 'string' ? Buffer.from(chunk) : chunk;
15
+ if (!flushed) {
16
+ chunks.push(buf);
17
+ }
18
+ else {
19
+ readable.push(buf);
20
+ }
21
+ },
22
+ close() {
23
+ if (chunks.length > 0) {
24
+ this._flush();
25
+ }
26
+ readable.push(null);
27
+ _closed = true;
28
+ },
29
+ error(error) {
30
+ if (chunks.length > 0) {
31
+ this._flush();
32
+ }
33
+ readable.destroy(error);
34
+ },
35
+ get _closed() {
36
+ return _closed;
37
+ },
38
+ _flush() {
39
+ flushed = true;
40
+ if (chunks.length > 0) {
41
+ const concatenated = chunks.length > 1 ? Buffer.concat(chunks) : chunks[0];
42
+ readable.push(concatenated);
43
+ chunks = [];
44
+ }
45
+ },
46
+ };
47
+ }
48
+ function isNodeReadable(obj) {
49
+ return obj?.read != null;
50
+ }
51
+ function isReadableStream(obj) {
52
+ return obj?.getReader != null;
53
+ }
54
+ export class PonyfillReadableStream {
55
+ readable;
56
+ constructor(underlyingSource) {
57
+ if (underlyingSource instanceof PonyfillReadableStream && underlyingSource.readable != null) {
58
+ this.readable = underlyingSource.readable;
59
+ }
60
+ else if (isNodeReadable(underlyingSource)) {
61
+ this.readable = underlyingSource;
62
+ }
63
+ else if (isReadableStream(underlyingSource)) {
64
+ this.readable = Readable.fromWeb(underlyingSource);
65
+ }
66
+ else {
67
+ let started = false;
68
+ let ongoing = false;
69
+ const handleStart = (desiredSize) => {
70
+ if (!started) {
71
+ const controller = createController(desiredSize, this.readable);
72
+ started = true;
73
+ return handleMaybePromise(() => underlyingSource?.start?.(controller), () => {
74
+ controller._flush();
75
+ if (controller._closed) {
76
+ return false;
77
+ }
78
+ return true;
79
+ });
80
+ }
81
+ return true;
82
+ };
83
+ const readImpl = (desiredSize) => {
84
+ return handleMaybePromise(() => handleStart(desiredSize), shouldContinue => {
85
+ if (!shouldContinue) {
86
+ return;
87
+ }
88
+ const controller = createController(desiredSize, this.readable);
89
+ return handleMaybePromise(() => underlyingSource?.pull?.(controller), () => {
90
+ controller._flush();
91
+ ongoing = false;
92
+ });
93
+ });
94
+ };
95
+ this.readable = new Readable({
96
+ read(desiredSize) {
97
+ if (ongoing) {
98
+ return;
99
+ }
100
+ ongoing = true;
101
+ return readImpl(desiredSize);
102
+ },
103
+ destroy(err, callback) {
104
+ if (underlyingSource?.cancel) {
105
+ try {
106
+ const res$ = underlyingSource.cancel(err);
107
+ if (res$?.then) {
108
+ return res$.then(() => {
109
+ callback(null);
110
+ }, err => {
111
+ callback(err);
112
+ });
113
+ }
114
+ }
115
+ catch (err) {
116
+ callback(err);
117
+ return;
118
+ }
119
+ }
120
+ callback(null);
121
+ },
122
+ });
123
+ }
124
+ }
125
+ cancel(reason) {
126
+ this.readable.destroy(reason);
127
+ // @ts-expect-error - we know it is void
128
+ return once(this.readable, 'close');
129
+ }
130
+ locked = false;
131
+ getReader(_options) {
132
+ const iterator = this.readable[Symbol.asyncIterator]();
133
+ this.locked = true;
134
+ const thisReadable = this.readable;
135
+ return {
136
+ read() {
137
+ return iterator.next();
138
+ },
139
+ releaseLock: () => {
140
+ if (iterator.return) {
141
+ const retResult$ = iterator.return();
142
+ if (retResult$.then) {
143
+ retResult$.then(() => {
144
+ this.locked = false;
145
+ });
146
+ return;
147
+ }
148
+ }
149
+ this.locked = false;
150
+ },
151
+ cancel: reason => {
152
+ if (iterator.return) {
153
+ const retResult$ = iterator.return(reason);
154
+ if (retResult$.then) {
155
+ return retResult$.then(() => {
156
+ this.locked = false;
157
+ });
158
+ }
159
+ }
160
+ this.locked = false;
161
+ return fakePromise();
162
+ },
163
+ get closed() {
164
+ return Promise.race([
165
+ once(thisReadable, 'end'),
166
+ once(thisReadable, 'error').then(err => Promise.reject(err)),
167
+ ]);
168
+ },
169
+ };
170
+ }
171
+ [Symbol.asyncIterator]() {
172
+ const iterator = this.readable[Symbol.asyncIterator]();
173
+ return {
174
+ [Symbol.asyncIterator]() {
175
+ return this;
176
+ },
177
+ next: () => iterator.next(),
178
+ return: () => {
179
+ if (!this.readable.destroyed) {
180
+ this.readable.destroy();
181
+ }
182
+ return iterator.return?.() || fakePromise({ done: true, value: undefined });
183
+ },
184
+ throw: (err) => {
185
+ if (!this.readable.destroyed) {
186
+ this.readable.destroy(err);
187
+ }
188
+ return iterator.throw?.(err) || fakePromise({ done: true, value: undefined });
189
+ },
190
+ };
191
+ }
192
+ tee() {
193
+ throw new Error('Not implemented');
194
+ }
195
+ async pipeToWriter(writer) {
196
+ try {
197
+ for await (const chunk of this) {
198
+ await writer.write(chunk);
199
+ }
200
+ await writer.close();
201
+ }
202
+ catch (err) {
203
+ await writer.abort(err);
204
+ }
205
+ }
206
+ pipeTo(destination) {
207
+ if (isPonyfillWritableStream(destination)) {
208
+ return pipeline(this.readable, destination.writable, {
209
+ end: true,
210
+ });
211
+ }
212
+ else {
213
+ const writer = destination.getWriter();
214
+ return this.pipeToWriter(writer);
215
+ }
216
+ }
217
+ pipeThrough({ writable, readable, }) {
218
+ this.pipeTo(writable).catch(err => {
219
+ this.readable.destroy(err);
220
+ });
221
+ if (isPonyfillReadableStream(readable)) {
222
+ readable.readable.once('error', err => this.readable.destroy(err));
223
+ readable.readable.once('finish', () => this.readable.push(null));
224
+ readable.readable.once('close', () => this.readable.push(null));
225
+ }
226
+ return readable;
227
+ }
228
+ static [Symbol.hasInstance](instance) {
229
+ return isReadableStream(instance);
230
+ }
231
+ static from(iterable) {
232
+ return new PonyfillReadableStream(Readable.from(iterable));
233
+ }
234
+ [Symbol.toStringTag] = 'ReadableStream';
235
+ }
236
+ function isPonyfillReadableStream(obj) {
237
+ return obj?.readable != null;
238
+ }
239
+ function isPonyfillWritableStream(obj) {
240
+ return obj?.writable != null;
241
+ }
@@ -0,0 +1,124 @@
1
+ import { Agent as HTTPAgent } from 'node:http';
2
+ import { Agent as HTTPSAgent } from 'node:https';
3
+ import { PonyfillBody } from './Body.js';
4
+ import { isHeadersLike, PonyfillHeaders } from './Headers.js';
5
+ import { PonyfillURL } from './URL.js';
6
+ function isRequest(input) {
7
+ return input[Symbol.toStringTag] === 'Request';
8
+ }
9
+ function isURL(obj) {
10
+ return obj?.href != null;
11
+ }
12
+ export class PonyfillRequest extends PonyfillBody {
13
+ constructor(input, options) {
14
+ let _url;
15
+ let _parsedUrl;
16
+ let bodyInit = null;
17
+ let requestInit;
18
+ if (typeof input === 'string') {
19
+ _url = input;
20
+ }
21
+ else if (isURL(input)) {
22
+ _parsedUrl = input;
23
+ }
24
+ else if (isRequest(input)) {
25
+ if (input._parsedUrl) {
26
+ _parsedUrl = input._parsedUrl;
27
+ }
28
+ else if (input._url) {
29
+ _url = input._url;
30
+ }
31
+ else {
32
+ _url = input.url;
33
+ }
34
+ bodyInit = input.body;
35
+ requestInit = input;
36
+ }
37
+ if (options != null) {
38
+ bodyInit = options.body || null;
39
+ requestInit = options;
40
+ }
41
+ super(bodyInit, requestInit);
42
+ this._url = _url;
43
+ this._parsedUrl = _parsedUrl;
44
+ this.cache = requestInit?.cache || 'default';
45
+ this.credentials = requestInit?.credentials || 'same-origin';
46
+ this.headers =
47
+ requestInit?.headers && isHeadersLike(requestInit.headers)
48
+ ? requestInit.headers
49
+ : new PonyfillHeaders(requestInit?.headers);
50
+ this.integrity = requestInit?.integrity || '';
51
+ this.keepalive = requestInit?.keepalive != null ? requestInit?.keepalive : false;
52
+ this.method = requestInit?.method?.toUpperCase() || 'GET';
53
+ this.mode = requestInit?.mode || 'cors';
54
+ this.redirect = requestInit?.redirect || 'follow';
55
+ this.referrer = requestInit?.referrer || 'about:client';
56
+ this.referrerPolicy = requestInit?.referrerPolicy || 'no-referrer';
57
+ this.headersSerializer = requestInit?.headersSerializer;
58
+ this.duplex = requestInit?.duplex || 'half';
59
+ this.destination = 'document';
60
+ this.priority = 'auto';
61
+ if (this.method !== 'GET' && this.method !== 'HEAD') {
62
+ this.handleContentLengthHeader(true);
63
+ }
64
+ if (requestInit?.agent != null) {
65
+ const protocol = _parsedUrl?.protocol || _url || this.url;
66
+ if (requestInit.agent === false) {
67
+ this.agent = false;
68
+ }
69
+ else if (protocol.startsWith('http:') && requestInit.agent instanceof HTTPAgent) {
70
+ this.agent = requestInit.agent;
71
+ }
72
+ else if (protocol.startsWith('https:') && requestInit.agent instanceof HTTPSAgent) {
73
+ this.agent = requestInit.agent;
74
+ }
75
+ }
76
+ }
77
+ headersSerializer;
78
+ cache;
79
+ credentials;
80
+ destination;
81
+ headers;
82
+ integrity;
83
+ keepalive;
84
+ method;
85
+ mode;
86
+ priority;
87
+ redirect;
88
+ referrer;
89
+ referrerPolicy;
90
+ _url;
91
+ get signal() {
92
+ this._signal ||= new AbortController().signal;
93
+ return this._signal;
94
+ }
95
+ get url() {
96
+ if (this._url == null) {
97
+ if (this._parsedUrl) {
98
+ this._url = this._parsedUrl.toString();
99
+ }
100
+ else {
101
+ throw new TypeError('Invalid URL');
102
+ }
103
+ }
104
+ return this._url;
105
+ }
106
+ _parsedUrl;
107
+ get parsedUrl() {
108
+ if (this._parsedUrl == null) {
109
+ if (this._url != null) {
110
+ this._parsedUrl = new PonyfillURL(this._url, 'http://localhost');
111
+ }
112
+ else {
113
+ throw new TypeError('Invalid URL');
114
+ }
115
+ }
116
+ return this._parsedUrl;
117
+ }
118
+ duplex;
119
+ agent;
120
+ clone() {
121
+ return this;
122
+ }
123
+ [Symbol.toStringTag] = 'Request';
124
+ }
@@ -0,0 +1,104 @@
1
+ import { STATUS_CODES } from 'node:http';
2
+ import { PonyfillBody } from './Body.js';
3
+ import { isHeadersLike, PonyfillHeaders } from './Headers.js';
4
+ const JSON_CONTENT_TYPE = 'application/json; charset=utf-8';
5
+ export class PonyfillResponse extends PonyfillBody {
6
+ headers;
7
+ constructor(body, init) {
8
+ super(body || null, init);
9
+ this.headers =
10
+ init?.headers && isHeadersLike(init.headers)
11
+ ? init.headers
12
+ : new PonyfillHeaders(init?.headers);
13
+ this.status = init?.status || 200;
14
+ this.statusText = init?.statusText || STATUS_CODES[this.status] || 'OK';
15
+ this.url = init?.url || '';
16
+ this.redirected = init?.redirected || false;
17
+ this.type = init?.type || 'default';
18
+ this.handleContentLengthHeader();
19
+ }
20
+ get ok() {
21
+ return this.status >= 200 && this.status < 300;
22
+ }
23
+ status;
24
+ statusText;
25
+ url;
26
+ redirected;
27
+ type;
28
+ clone() {
29
+ return this;
30
+ }
31
+ static error() {
32
+ return new PonyfillResponse(null, {
33
+ status: 500,
34
+ statusText: 'Internal Server Error',
35
+ });
36
+ }
37
+ static redirect(url, status = 302) {
38
+ if (status < 300 || status > 399) {
39
+ throw new RangeError('Invalid status code');
40
+ }
41
+ return new PonyfillResponse(null, {
42
+ headers: {
43
+ location: url,
44
+ },
45
+ status,
46
+ });
47
+ }
48
+ static json(data, init) {
49
+ const bodyInit = JSON.stringify(data);
50
+ if (!init) {
51
+ init = {
52
+ headers: {
53
+ 'content-type': JSON_CONTENT_TYPE,
54
+ 'content-length': Buffer.byteLength(bodyInit).toString(),
55
+ },
56
+ };
57
+ }
58
+ else if (!init.headers) {
59
+ init.headers = {
60
+ 'content-type': JSON_CONTENT_TYPE,
61
+ 'content-length': Buffer.byteLength(bodyInit).toString(),
62
+ };
63
+ }
64
+ else if (isHeadersLike(init.headers)) {
65
+ if (!init.headers.has('content-type')) {
66
+ init.headers.set('content-type', JSON_CONTENT_TYPE);
67
+ }
68
+ if (!init.headers.has('content-length')) {
69
+ init.headers.set('content-length', Buffer.byteLength(bodyInit).toString());
70
+ }
71
+ }
72
+ else if (Array.isArray(init.headers)) {
73
+ let contentTypeExists = false;
74
+ let contentLengthExists = false;
75
+ for (const [key] of init.headers) {
76
+ if (contentLengthExists && contentTypeExists) {
77
+ break;
78
+ }
79
+ if (!contentTypeExists && key.toLowerCase() === 'content-type') {
80
+ contentTypeExists = true;
81
+ }
82
+ else if (!contentLengthExists && key.toLowerCase() === 'content-length') {
83
+ contentLengthExists = true;
84
+ }
85
+ }
86
+ if (!contentTypeExists) {
87
+ init.headers.push(['content-type', JSON_CONTENT_TYPE]);
88
+ }
89
+ if (!contentLengthExists) {
90
+ init.headers.push(['content-length', Buffer.byteLength(bodyInit).toString()]);
91
+ }
92
+ }
93
+ else if (typeof init.headers === 'object') {
94
+ if (init.headers?.['content-type'] == null) {
95
+ init.headers['content-type'] = JSON_CONTENT_TYPE;
96
+ }
97
+ if (init.headers?.['content-length'] == null) {
98
+ init.headers['content-length'] = Buffer.byteLength(bodyInit).toString();
99
+ }
100
+ }
101
+ return new PonyfillResponse(bodyInit, init);
102
+ }
103
+ [Symbol.toStringTag] = 'Response';
104
+ }
@@ -0,0 +1,43 @@
1
+ import { Buffer } from 'node:buffer';
2
+ import { isArrayBufferView } from './utils.js';
3
+ export class PonyfillTextEncoder {
4
+ encoding;
5
+ constructor(encoding = 'utf-8') {
6
+ this.encoding = encoding;
7
+ }
8
+ encode(input) {
9
+ return Buffer.from(input, this.encoding);
10
+ }
11
+ encodeInto(source, destination) {
12
+ const buffer = this.encode(source);
13
+ const copied = buffer.copy(destination);
14
+ return {
15
+ read: copied,
16
+ written: copied,
17
+ };
18
+ }
19
+ }
20
+ export class PonyfillTextDecoder {
21
+ encoding;
22
+ fatal = false;
23
+ ignoreBOM = false;
24
+ constructor(encoding = 'utf-8', options) {
25
+ this.encoding = encoding;
26
+ if (options) {
27
+ this.fatal = options.fatal || false;
28
+ this.ignoreBOM = options.ignoreBOM || false;
29
+ }
30
+ }
31
+ decode(input) {
32
+ if (Buffer.isBuffer(input)) {
33
+ return input.toString(this.encoding);
34
+ }
35
+ if (isArrayBufferView(input)) {
36
+ return Buffer.from(input.buffer, input.byteOffset, input.byteLength).toString(this.encoding);
37
+ }
38
+ return Buffer.from(input).toString(this.encoding);
39
+ }
40
+ }
41
+ export function PonyfillBtoa(input) {
42
+ return Buffer.from(input, 'binary').toString('base64');
43
+ }
@@ -0,0 +1,35 @@
1
+ import { PonyfillTextDecoder, PonyfillTextEncoder } from './TextEncoderDecoder.js';
2
+ import { PonyfillTransformStream } from './TransformStream.js';
3
+ export class PonyfillTextDecoderStream extends PonyfillTransformStream {
4
+ textDecoder;
5
+ constructor(encoding, options) {
6
+ super({
7
+ transform: (chunk, controller) => controller.enqueue(this.textDecoder.decode(chunk, { stream: true })),
8
+ });
9
+ this.textDecoder = new PonyfillTextDecoder(encoding, options);
10
+ }
11
+ get encoding() {
12
+ return this.textDecoder.encoding;
13
+ }
14
+ get fatal() {
15
+ return this.textDecoder.fatal;
16
+ }
17
+ get ignoreBOM() {
18
+ return this.textDecoder.ignoreBOM;
19
+ }
20
+ }
21
+ export class PonyfillTextEncoderStream extends PonyfillTransformStream {
22
+ textEncoder;
23
+ constructor(encoding) {
24
+ super({
25
+ transform: (chunk, controller) => controller.enqueue(this.textEncoder.encode(chunk)),
26
+ });
27
+ this.textEncoder = new PonyfillTextEncoder(encoding);
28
+ }
29
+ get encoding() {
30
+ return this.textEncoder.encoding;
31
+ }
32
+ encode(input) {
33
+ return this.textEncoder.encode(input);
34
+ }
35
+ }
@@ -0,0 +1,75 @@
1
+ import { Transform } from 'node:stream';
2
+ import { PonyfillReadableStream } from './ReadableStream.js';
3
+ import { endStream } from './utils.js';
4
+ import { PonyfillWritableStream } from './WritableStream.js';
5
+ export class PonyfillTransformStream {
6
+ transform;
7
+ writable;
8
+ readable;
9
+ constructor(transformer) {
10
+ if (transformer instanceof Transform) {
11
+ this.transform = transformer;
12
+ }
13
+ else if (transformer) {
14
+ const controller = {
15
+ enqueue(chunk) {
16
+ transform.push(chunk);
17
+ },
18
+ error(reason) {
19
+ transform.destroy(reason);
20
+ },
21
+ terminate() {
22
+ endStream(transform);
23
+ },
24
+ get desiredSize() {
25
+ return transform.writableLength;
26
+ },
27
+ };
28
+ const transform = new Transform({
29
+ read() { },
30
+ write(chunk, _encoding, callback) {
31
+ try {
32
+ const result = transformer.transform?.(chunk, controller);
33
+ if (result instanceof Promise) {
34
+ result.then(() => {
35
+ callback();
36
+ }, err => {
37
+ callback(err);
38
+ });
39
+ }
40
+ else {
41
+ callback();
42
+ }
43
+ }
44
+ catch (err) {
45
+ callback(err);
46
+ }
47
+ },
48
+ final(callback) {
49
+ try {
50
+ const result = transformer.flush?.(controller);
51
+ if (result instanceof Promise) {
52
+ result.then(() => {
53
+ callback();
54
+ }, err => {
55
+ callback(err);
56
+ });
57
+ }
58
+ else {
59
+ callback();
60
+ }
61
+ }
62
+ catch (err) {
63
+ callback(err);
64
+ }
65
+ },
66
+ });
67
+ this.transform = transform;
68
+ }
69
+ else {
70
+ this.transform = new Transform();
71
+ }
72
+ this.writable = new PonyfillWritableStream(this.transform);
73
+ this.readable = new PonyfillReadableStream(this.transform);
74
+ }
75
+ }
@@ -0,0 +1,24 @@
1
+ import NodeBuffer from 'node:buffer';
2
+ import { randomUUID } from 'node:crypto';
3
+ const NativeURL = globalThis.URL;
4
+ class URL extends NativeURL {
5
+ // This part is only needed to handle `PonyfillBlob` objects
6
+ static blobRegistry = new Map();
7
+ static createObjectURL(blob) {
8
+ const blobUrl = `blob:whatwgnode:${randomUUID()}`;
9
+ this.blobRegistry.set(blobUrl, blob);
10
+ return blobUrl;
11
+ }
12
+ static revokeObjectURL(url) {
13
+ if (!this.blobRegistry.has(url)) {
14
+ NativeURL.revokeObjectURL(url);
15
+ }
16
+ else {
17
+ this.blobRegistry.delete(url);
18
+ }
19
+ }
20
+ static getBlobFromURL(url) {
21
+ return (this.blobRegistry.get(url) || NodeBuffer?.resolveObjectURL?.(url));
22
+ }
23
+ }
24
+ export { URL as PonyfillURL };
@@ -0,0 +1 @@
1
+ export const PonyfillURLSearchParams = globalThis.URLSearchParams;