@zimic/http 0.0.1-canary.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/LICENSE.md +16 -0
- package/README.md +230 -0
- package/dist/chunk-VHQRAQPQ.mjs +1371 -0
- package/dist/chunk-VHQRAQPQ.mjs.map +1 -0
- package/dist/chunk-VUDGONB5.js +1382 -0
- package/dist/chunk-VUDGONB5.js.map +1 -0
- package/dist/cli.js +116 -0
- package/dist/cli.js.map +1 -0
- package/dist/cli.mjs +109 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/index.d.ts +1306 -0
- package/dist/index.js +544 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +537 -0
- package/dist/index.mjs.map +1 -0
- package/dist/typegen.d.ts +86 -0
- package/dist/typegen.js +12 -0
- package/dist/typegen.js.map +1 -0
- package/dist/typegen.mjs +3 -0
- package/dist/typegen.mjs.map +1 -0
- package/index.d.ts +1 -0
- package/package.json +110 -0
- package/src/cli/cli.ts +92 -0
- package/src/cli/index.ts +4 -0
- package/src/cli/typegen/openapi.ts +24 -0
- package/src/formData/HttpFormData.ts +300 -0
- package/src/formData/types.ts +110 -0
- package/src/headers/HttpHeaders.ts +217 -0
- package/src/headers/types.ts +65 -0
- package/src/index.ts +55 -0
- package/src/pathParams/types.ts +67 -0
- package/src/searchParams/HttpSearchParams.ts +258 -0
- package/src/searchParams/types.ts +133 -0
- package/src/typegen/index.ts +12 -0
- package/src/typegen/namespace/TypegenNamespace.ts +18 -0
- package/src/typegen/openapi/generate.ts +168 -0
- package/src/typegen/openapi/transform/components.ts +481 -0
- package/src/typegen/openapi/transform/context.ts +67 -0
- package/src/typegen/openapi/transform/filters.ts +71 -0
- package/src/typegen/openapi/transform/imports.ts +15 -0
- package/src/typegen/openapi/transform/io.ts +86 -0
- package/src/typegen/openapi/transform/methods.ts +803 -0
- package/src/typegen/openapi/transform/operations.ts +120 -0
- package/src/typegen/openapi/transform/paths.ts +119 -0
- package/src/typegen/openapi/utils/types.ts +45 -0
- package/src/types/arrays.d.ts +4 -0
- package/src/types/json.ts +89 -0
- package/src/types/objects.d.ts +14 -0
- package/src/types/requests.ts +96 -0
- package/src/types/schema.ts +834 -0
- package/src/types/strings.d.ts +9 -0
- package/src/types/utils.ts +64 -0
- package/src/utils/console.ts +7 -0
- package/src/utils/data.ts +13 -0
- package/src/utils/files.ts +28 -0
- package/src/utils/imports.ts +12 -0
- package/src/utils/prettier.ts +13 -0
- package/src/utils/strings.ts +3 -0
- package/src/utils/time.ts +25 -0
- package/src/utils/urls.ts +52 -0
- package/typegen.d.ts +1 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
|
|
6
|
+
// src/utils/data.ts
|
|
7
|
+
async function blobEquals(blob, otherBlob) {
|
|
8
|
+
return blob.type === otherBlob.type && blob.size === otherBlob.size && await blob.text() === await otherBlob.text();
|
|
9
|
+
}
|
|
10
|
+
__name(blobEquals, "blobEquals");
|
|
11
|
+
|
|
12
|
+
// src/utils/imports.ts
|
|
13
|
+
function createCachedDynamicImport(importModuleDynamically) {
|
|
14
|
+
let cachedImportResult;
|
|
15
|
+
return /* @__PURE__ */ __name(async function importModuleDynamicallyWithCache() {
|
|
16
|
+
if (cachedImportResult === undefined) {
|
|
17
|
+
cachedImportResult = await importModuleDynamically();
|
|
18
|
+
}
|
|
19
|
+
return cachedImportResult;
|
|
20
|
+
}, "importModuleDynamicallyWithCache");
|
|
21
|
+
}
|
|
22
|
+
__name(createCachedDynamicImport, "createCachedDynamicImport");
|
|
23
|
+
async function fileEquals(file, otherFile) {
|
|
24
|
+
return file.name === otherFile.name && await blobEquals(file, otherFile);
|
|
25
|
+
}
|
|
26
|
+
__name(fileEquals, "fileEquals");
|
|
27
|
+
|
|
28
|
+
// src/formData/HttpFormData.ts
|
|
29
|
+
var HttpFormData = class extends FormData {
|
|
30
|
+
static {
|
|
31
|
+
__name(this, "HttpFormData");
|
|
32
|
+
}
|
|
33
|
+
set(name, blobOrValue, fileName) {
|
|
34
|
+
if (fileName === undefined) {
|
|
35
|
+
super.set(name, blobOrValue);
|
|
36
|
+
} else {
|
|
37
|
+
super.set(name, blobOrValue, fileName);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
append(name, blobOrValue, fileName) {
|
|
41
|
+
if (fileName === undefined) {
|
|
42
|
+
super.append(name, blobOrValue);
|
|
43
|
+
} else {
|
|
44
|
+
super.append(name, blobOrValue, fileName);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get the value of the entry associated to a key name.
|
|
49
|
+
*
|
|
50
|
+
* If the key might have multiple values, use {@link HttpFormData#getAll} instead.
|
|
51
|
+
*
|
|
52
|
+
* @param name The name of the key to get the value of.
|
|
53
|
+
* @returns The value associated with the key name, or `null` if the key does not exist.
|
|
54
|
+
* @see {@link https://developer.mozilla.org/docs/Web/API/FormData/get MDN Reference}
|
|
55
|
+
*/
|
|
56
|
+
get(name) {
|
|
57
|
+
return super.get(name);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get all the values of the entry associated with a key name.
|
|
61
|
+
*
|
|
62
|
+
* If the key has at most a single value, use {@link HttpFormData#get} instead.
|
|
63
|
+
*
|
|
64
|
+
* @param name The name of the key to get the values of.
|
|
65
|
+
* @returns An array of values associated with the key name, or an empty array if the key does not exist.
|
|
66
|
+
* @see {@link https://developer.mozilla.org/docs/Web/API/FormData/getAll MDN Reference}
|
|
67
|
+
*/
|
|
68
|
+
getAll(name) {
|
|
69
|
+
return super.getAll(name);
|
|
70
|
+
}
|
|
71
|
+
/** @see {@link https://developer.mozilla.org/docs/Web/API/FormData/has MDN Reference} */
|
|
72
|
+
has(name) {
|
|
73
|
+
return super.has(name);
|
|
74
|
+
}
|
|
75
|
+
/** @see {@link https://developer.mozilla.org/docs/Web/API/FormData/delete MDN Reference} */
|
|
76
|
+
delete(name) {
|
|
77
|
+
super.delete(name);
|
|
78
|
+
}
|
|
79
|
+
forEach(callback, thisArg) {
|
|
80
|
+
super.forEach(callback, thisArg);
|
|
81
|
+
}
|
|
82
|
+
/** @see {@link https://developer.mozilla.org/docs/Web/API/FormData/keys MDN Reference} */
|
|
83
|
+
keys() {
|
|
84
|
+
return super.keys();
|
|
85
|
+
}
|
|
86
|
+
/** @see {@link https://developer.mozilla.org/docs/Web/API/FormData/values MDN Reference} */
|
|
87
|
+
values() {
|
|
88
|
+
return super.values();
|
|
89
|
+
}
|
|
90
|
+
/** @see {@link https://developer.mozilla.org/docs/Web/API/FormData/entries MDN Reference} */
|
|
91
|
+
entries() {
|
|
92
|
+
return super.entries();
|
|
93
|
+
}
|
|
94
|
+
[Symbol.iterator]() {
|
|
95
|
+
return super[Symbol.iterator]();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Checks if the data is equal to the other data. Equality is defined as having the same keys and values, regardless
|
|
99
|
+
* of the order of keys.
|
|
100
|
+
*
|
|
101
|
+
* @param otherData The other data to compare.
|
|
102
|
+
* @returns A promise that resolves with `true` if the data is equal to the other data, or `false` otherwise.
|
|
103
|
+
* Important: both form data might be read while comparing.
|
|
104
|
+
*/
|
|
105
|
+
async equals(otherData) {
|
|
106
|
+
for (const [otherKey, otherValue] of otherData.entries()) {
|
|
107
|
+
const values = super.getAll.call(this, otherKey);
|
|
108
|
+
const haveSameNumberOfValues = values.length === super.getAll.call(otherData, otherKey).length;
|
|
109
|
+
if (!haveSameNumberOfValues) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
let valueExists = false;
|
|
113
|
+
for (const value of values) {
|
|
114
|
+
if (value === otherValue || value instanceof Blob && otherValue instanceof Blob && await fileEquals(value, otherValue)) {
|
|
115
|
+
valueExists = true;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (!valueExists) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
for (const key of this.keys()) {
|
|
124
|
+
const otherHasKey = super.has.call(otherData, key);
|
|
125
|
+
if (!otherHasKey) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Checks if the data contains the other data. This method is less strict than {@link HttpFormData#equals} and only
|
|
133
|
+
* requires that all keys and values in the other data are present in this data.
|
|
134
|
+
*
|
|
135
|
+
* @param otherData The other data to compare.
|
|
136
|
+
* @returns A promise that resolves with `true` if this data contains the other data, or `false` otherwise. Important:
|
|
137
|
+
* both form data might be read while comparing.
|
|
138
|
+
*/
|
|
139
|
+
async contains(otherData) {
|
|
140
|
+
for (const [otherKey, otherValue] of otherData.entries()) {
|
|
141
|
+
const values = super.getAll.call(this, otherKey);
|
|
142
|
+
const haveCompatibleNumberOfValues = values.length >= super.getAll.call(otherData, otherKey).length;
|
|
143
|
+
if (!haveCompatibleNumberOfValues) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
let valueExists = false;
|
|
147
|
+
for (const value of values) {
|
|
148
|
+
if (value === otherValue || typeof value === "string" && typeof otherValue === "string" && value === otherValue || value instanceof Blob && otherValue instanceof Blob && await fileEquals(value, otherValue)) {
|
|
149
|
+
valueExists = true;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (!valueExists) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Converts this form data into a plain object. This method is useful for serialization and debugging purposes.
|
|
161
|
+
*
|
|
162
|
+
* **NOTE**: If a key has multiple values, the object will contain an array of values for that key. If the key has
|
|
163
|
+
* only one value, the object will contain its value directly, without an array, regardless of how the value was
|
|
164
|
+
* initialized when creating the form data.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* const formData = new HttpFormData<{
|
|
168
|
+
* title: string;
|
|
169
|
+
* descriptions: string[];
|
|
170
|
+
* content: Blob;
|
|
171
|
+
* }>();
|
|
172
|
+
*
|
|
173
|
+
* formData.set('title', 'My title');
|
|
174
|
+
* formData.append('descriptions', 'Description 1');
|
|
175
|
+
* formData.append('descriptions', 'Description 2');
|
|
176
|
+
* formData.set('content', new Blob(['content'], { type: 'text/plain' }));
|
|
177
|
+
*
|
|
178
|
+
* const object = formData.toObject();
|
|
179
|
+
* console.log(object); // { title: 'My title', descriptions: ['Description 1', 'Description 2'], content: Blob { type: 'text/plain' } }
|
|
180
|
+
*
|
|
181
|
+
* @returns A plain object representation of this form data.
|
|
182
|
+
*/
|
|
183
|
+
toObject() {
|
|
184
|
+
const object = {};
|
|
185
|
+
for (const [key, value] of this.entries()) {
|
|
186
|
+
if (key in object) {
|
|
187
|
+
const existingValue = object[key];
|
|
188
|
+
if (Array.isArray(existingValue)) {
|
|
189
|
+
existingValue.push(value);
|
|
190
|
+
} else {
|
|
191
|
+
object[key] = [existingValue, value];
|
|
192
|
+
}
|
|
193
|
+
} else {
|
|
194
|
+
object[key] = value;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return object;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
var HttpFormData_default = HttpFormData;
|
|
201
|
+
|
|
202
|
+
// src/headers/HttpHeaders.ts
|
|
203
|
+
function pickPrimitiveProperties(schema) {
|
|
204
|
+
return Object.entries(schema).reduce((accumulated, [key, value]) => {
|
|
205
|
+
if (value !== undefined) {
|
|
206
|
+
accumulated[key] = value;
|
|
207
|
+
}
|
|
208
|
+
return accumulated;
|
|
209
|
+
}, {});
|
|
210
|
+
}
|
|
211
|
+
__name(pickPrimitiveProperties, "pickPrimitiveProperties");
|
|
212
|
+
var HttpHeaders = class extends Headers {
|
|
213
|
+
static {
|
|
214
|
+
__name(this, "HttpHeaders");
|
|
215
|
+
}
|
|
216
|
+
constructor(init) {
|
|
217
|
+
if (init instanceof Headers || Array.isArray(init) || !init) {
|
|
218
|
+
super(init);
|
|
219
|
+
} else {
|
|
220
|
+
super(pickPrimitiveProperties(init));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/set MDN Reference} */
|
|
224
|
+
set(name, value) {
|
|
225
|
+
super.set(name, value);
|
|
226
|
+
}
|
|
227
|
+
/** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/append MDN Reference} */
|
|
228
|
+
append(name, value) {
|
|
229
|
+
super.append(name, value);
|
|
230
|
+
}
|
|
231
|
+
/** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/get MDN Reference} */
|
|
232
|
+
get(name) {
|
|
233
|
+
return super.get(name);
|
|
234
|
+
}
|
|
235
|
+
/** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/has MDN Reference} */
|
|
236
|
+
getSetCookie() {
|
|
237
|
+
return super.getSetCookie();
|
|
238
|
+
}
|
|
239
|
+
/** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/has MDN Reference} */
|
|
240
|
+
has(name) {
|
|
241
|
+
return super.has(name);
|
|
242
|
+
}
|
|
243
|
+
/** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/delete MDN Reference} */
|
|
244
|
+
delete(name) {
|
|
245
|
+
super.delete(name);
|
|
246
|
+
}
|
|
247
|
+
forEach(callback, thisArg) {
|
|
248
|
+
super.forEach(callback, thisArg);
|
|
249
|
+
}
|
|
250
|
+
/** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/keys MDN Reference} */
|
|
251
|
+
keys() {
|
|
252
|
+
return super.keys();
|
|
253
|
+
}
|
|
254
|
+
/** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/values MDN Reference} */
|
|
255
|
+
values() {
|
|
256
|
+
return super.values();
|
|
257
|
+
}
|
|
258
|
+
/** @see {@link https://developer.mozilla.org/docs/Web/API/Headers/entries MDN Reference} */
|
|
259
|
+
entries() {
|
|
260
|
+
return super.entries();
|
|
261
|
+
}
|
|
262
|
+
[Symbol.iterator]() {
|
|
263
|
+
return super[Symbol.iterator]();
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Checks if this headers object is equal to another set of headers. Equality is defined as having the same keys and
|
|
267
|
+
* values, regardless of the order of keys.
|
|
268
|
+
*
|
|
269
|
+
* @param otherHeaders The other headers object to compare against.
|
|
270
|
+
* @returns `true` if the headers are equal, `false` otherwise.
|
|
271
|
+
*/
|
|
272
|
+
equals(otherHeaders) {
|
|
273
|
+
for (const [key, otherValue] of otherHeaders.entries()) {
|
|
274
|
+
const value = super.get.call(this, key);
|
|
275
|
+
if (value === null) {
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
const valueItems = this.splitHeaderValues(value);
|
|
279
|
+
const otherValueItems = this.splitHeaderValues(otherValue);
|
|
280
|
+
const haveCompatibleNumberOfValues = valueItems.length === otherValueItems.length;
|
|
281
|
+
if (!haveCompatibleNumberOfValues) {
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
for (const otherValueItem of otherValueItems) {
|
|
285
|
+
if (!valueItems.includes(otherValueItem)) {
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
for (const key of this.keys()) {
|
|
291
|
+
const otherHasKey = super.has.call(otherHeaders, key);
|
|
292
|
+
if (!otherHasKey) {
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Checks if this headers object contains another set of headers. This method is less strict than
|
|
300
|
+
* {@link HttpHeaders#equals} and only requires that all keys and values in the other headers are present in these
|
|
301
|
+
* headers.
|
|
302
|
+
*
|
|
303
|
+
* @param otherHeaders The other headers object to compare against.
|
|
304
|
+
* @returns `true` if these headers contain the other headers, `false` otherwise.
|
|
305
|
+
*/
|
|
306
|
+
contains(otherHeaders) {
|
|
307
|
+
for (const [key, otherValue] of otherHeaders.entries()) {
|
|
308
|
+
const value = super.get.call(this, key);
|
|
309
|
+
if (value === null) {
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
const valueItems = this.splitHeaderValues(value);
|
|
313
|
+
const otherValueItems = this.splitHeaderValues(otherValue);
|
|
314
|
+
const haveCompatibleNumberOfValues = valueItems.length >= otherValueItems.length;
|
|
315
|
+
if (!haveCompatibleNumberOfValues) {
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
for (const otherValueItem of otherValueItems) {
|
|
319
|
+
if (!valueItems.includes(otherValueItem)) {
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return true;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Converts these headers into a plain object. This method is useful for serialization and debugging purposes.
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* const headers = new HttpHeaders({
|
|
331
|
+
* accept: 'application/json',
|
|
332
|
+
* 'content-type': 'application/json',
|
|
333
|
+
* });
|
|
334
|
+
* const object = headers.toObject();
|
|
335
|
+
* console.log(object); // { accept: 'application/json', 'content-type': 'application/json' }
|
|
336
|
+
*
|
|
337
|
+
* @returns A plain object representation of these headers.
|
|
338
|
+
*/
|
|
339
|
+
toObject() {
|
|
340
|
+
const object = {};
|
|
341
|
+
for (const [key, value] of this.entries()) {
|
|
342
|
+
object[key] = value;
|
|
343
|
+
}
|
|
344
|
+
return object;
|
|
345
|
+
}
|
|
346
|
+
splitHeaderValues(value) {
|
|
347
|
+
return value.split(",").map((item) => item.trim()).filter((item) => item.length > 0);
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
var HttpHeaders_default = HttpHeaders;
|
|
351
|
+
|
|
352
|
+
// src/searchParams/HttpSearchParams.ts
|
|
353
|
+
function pickPrimitiveProperties2(schema) {
|
|
354
|
+
const schemaWithPrimitiveProperties = Object.entries(schema).reduce(
|
|
355
|
+
(accumulated, [key, value]) => {
|
|
356
|
+
if (value !== undefined && !Array.isArray(value)) {
|
|
357
|
+
accumulated[key] = value;
|
|
358
|
+
}
|
|
359
|
+
return accumulated;
|
|
360
|
+
},
|
|
361
|
+
{}
|
|
362
|
+
);
|
|
363
|
+
return schemaWithPrimitiveProperties;
|
|
364
|
+
}
|
|
365
|
+
__name(pickPrimitiveProperties2, "pickPrimitiveProperties");
|
|
366
|
+
var HttpSearchParams = class extends URLSearchParams {
|
|
367
|
+
static {
|
|
368
|
+
__name(this, "HttpSearchParams");
|
|
369
|
+
}
|
|
370
|
+
constructor(init) {
|
|
371
|
+
if (init instanceof URLSearchParams || Array.isArray(init) || typeof init === "string" || !init) {
|
|
372
|
+
super(init);
|
|
373
|
+
} else {
|
|
374
|
+
super(pickPrimitiveProperties2(init));
|
|
375
|
+
this.populateInitArrayProperties(init);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
populateInitArrayProperties(init) {
|
|
379
|
+
for (const [key, value] of Object.entries(init)) {
|
|
380
|
+
if (Array.isArray(value)) {
|
|
381
|
+
for (const item of value) {
|
|
382
|
+
super.append(key, item);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
/** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/set MDN Reference} */
|
|
388
|
+
set(name, value) {
|
|
389
|
+
super.set(name, value);
|
|
390
|
+
}
|
|
391
|
+
/** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/append MDN Reference} */
|
|
392
|
+
append(name, value) {
|
|
393
|
+
super.append(name, value);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Get the value of the entry associated to a key name.
|
|
397
|
+
*
|
|
398
|
+
* If the key might have multiple values, use {@link HttpSearchParams#getAll} instead.
|
|
399
|
+
*
|
|
400
|
+
* @param name The name of the key to get the value of.
|
|
401
|
+
* @returns The value associated with the key name, or `null` if the key does not exist.
|
|
402
|
+
* @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/get MDN Reference}
|
|
403
|
+
*/
|
|
404
|
+
get(name) {
|
|
405
|
+
return super.get(name);
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Get all the values of the entry associated with a key name.
|
|
409
|
+
*
|
|
410
|
+
* If the key has at most one value, use {@link HttpSearchParams#get} instead.
|
|
411
|
+
*
|
|
412
|
+
* @param name The name of the key to get the values of.
|
|
413
|
+
* @returns An array of values associated with the key name, or an empty array if the key does not exist.
|
|
414
|
+
* @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/getAll MDN Reference}
|
|
415
|
+
*/
|
|
416
|
+
getAll(name) {
|
|
417
|
+
return super.getAll(name);
|
|
418
|
+
}
|
|
419
|
+
/** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/has MDN Reference} */
|
|
420
|
+
has(name, value) {
|
|
421
|
+
return super.has(name, value);
|
|
422
|
+
}
|
|
423
|
+
/** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/delete MDN Reference} */
|
|
424
|
+
delete(name, value) {
|
|
425
|
+
super.delete(name, value);
|
|
426
|
+
}
|
|
427
|
+
forEach(callback, thisArg) {
|
|
428
|
+
super.forEach(callback, thisArg);
|
|
429
|
+
}
|
|
430
|
+
/** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/keys MDN Reference} */
|
|
431
|
+
keys() {
|
|
432
|
+
return super.keys();
|
|
433
|
+
}
|
|
434
|
+
/** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/values MDN Reference} */
|
|
435
|
+
values() {
|
|
436
|
+
return super.values();
|
|
437
|
+
}
|
|
438
|
+
/** @see {@link https://developer.mozilla.org/docs/Web/API/URLSearchParams/entries MDN Reference} */
|
|
439
|
+
entries() {
|
|
440
|
+
return super.entries();
|
|
441
|
+
}
|
|
442
|
+
[Symbol.iterator]() {
|
|
443
|
+
return super[Symbol.iterator]();
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Checks if these search params are equal to another set of search parameters. Equality is defined as having the same
|
|
447
|
+
* keys and values, regardless of the order of the keys.
|
|
448
|
+
*
|
|
449
|
+
* @param otherParams The other search parameters to compare against.
|
|
450
|
+
* @returns `true` if the search parameters are equal, `false` otherwise.
|
|
451
|
+
*/
|
|
452
|
+
equals(otherParams) {
|
|
453
|
+
for (const [key, otherValue] of otherParams.entries()) {
|
|
454
|
+
const values = super.getAll.call(this, key);
|
|
455
|
+
const haveSameNumberOfValues = values.length === super.getAll.call(otherParams, key).length;
|
|
456
|
+
if (!haveSameNumberOfValues) {
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
const valueExists = values.includes(otherValue);
|
|
460
|
+
if (!valueExists) {
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return this.size === otherParams.size;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Checks if these search params contain another set of search parameters. This method is less strict than
|
|
468
|
+
* {@link HttpSearchParams#equals} and only requires that all keys and values in the other search parameters are
|
|
469
|
+
* present in these search parameters.
|
|
470
|
+
*
|
|
471
|
+
* @param otherParams The other search parameters to check for containment.
|
|
472
|
+
* @returns `true` if these search parameters contain the other search parameters, `false` otherwise.
|
|
473
|
+
*/
|
|
474
|
+
contains(otherParams) {
|
|
475
|
+
for (const [key, otherValue] of otherParams.entries()) {
|
|
476
|
+
const values = super.getAll.call(this, key);
|
|
477
|
+
const haveCompatibleNumberOfValues = values.length >= super.getAll.call(otherParams, key).length;
|
|
478
|
+
if (!haveCompatibleNumberOfValues) {
|
|
479
|
+
return false;
|
|
480
|
+
}
|
|
481
|
+
const valueExists = values.includes(otherValue);
|
|
482
|
+
if (!valueExists) {
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return true;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Converts these search params into a plain object. This method is useful for serialization and debugging purposes.
|
|
490
|
+
*
|
|
491
|
+
* **NOTE**: If a key has multiple values, the object will contain an array of values for that key. If the key has
|
|
492
|
+
* only one value, the object will contain its value directly, without an array, regardless of how the value was
|
|
493
|
+
* initialized when creating the search params object.
|
|
494
|
+
*
|
|
495
|
+
* @example
|
|
496
|
+
* const searchParams = new HttpSearchParams({
|
|
497
|
+
* names: ['user 1', 'user 2'],
|
|
498
|
+
* name: ['user 3'],
|
|
499
|
+
* page: '1',
|
|
500
|
+
* });
|
|
501
|
+
* const object = searchParams.toObject();
|
|
502
|
+
* console.log(object); // { names: ['user 1', 'user 2'], name: 'user 3', page: '1' }
|
|
503
|
+
*
|
|
504
|
+
* @returns A plain object representation of these search params.
|
|
505
|
+
*/
|
|
506
|
+
toObject() {
|
|
507
|
+
const object = {};
|
|
508
|
+
for (const [key, value] of this.entries()) {
|
|
509
|
+
if (key in object) {
|
|
510
|
+
const existingValue = object[key];
|
|
511
|
+
if (Array.isArray(existingValue)) {
|
|
512
|
+
existingValue.push(value);
|
|
513
|
+
} else {
|
|
514
|
+
object[key] = [existingValue, value];
|
|
515
|
+
}
|
|
516
|
+
} else {
|
|
517
|
+
object[key] = value;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return object;
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
var HttpSearchParams_default = HttpSearchParams;
|
|
524
|
+
|
|
525
|
+
// src/types/schema.ts
|
|
526
|
+
var HTTP_METHODS_WITH_REQUEST_BODY = Object.freeze(["POST", "PUT", "PATCH", "DELETE"]);
|
|
527
|
+
var HTTP_METHODS_WITH_RESPONSE_BODY = Object.freeze([
|
|
528
|
+
"GET",
|
|
529
|
+
"POST",
|
|
530
|
+
"PUT",
|
|
531
|
+
"PATCH",
|
|
532
|
+
"DELETE",
|
|
533
|
+
"OPTIONS"
|
|
534
|
+
]);
|
|
535
|
+
var HTTP_METHODS = Object.freeze(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"]);
|
|
536
|
+
|
|
537
|
+
exports.HTTP_METHODS = HTTP_METHODS;
|
|
538
|
+
exports.HTTP_METHODS_WITH_REQUEST_BODY = HTTP_METHODS_WITH_REQUEST_BODY;
|
|
539
|
+
exports.HTTP_METHODS_WITH_RESPONSE_BODY = HTTP_METHODS_WITH_RESPONSE_BODY;
|
|
540
|
+
exports.HttpFormData = HttpFormData_default;
|
|
541
|
+
exports.HttpHeaders = HttpHeaders_default;
|
|
542
|
+
exports.HttpSearchParams = HttpSearchParams_default;
|
|
543
|
+
//# sourceMappingURL=index.js.map
|
|
544
|
+
//# sourceMappingURL=index.js.map
|