@d1g1tal/transportr 1.4.2 → 2.0.0
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 +329 -76
- package/dist/transportr.d.ts +1799 -0
- package/dist/transportr.js +2753 -1503
- package/dist/transportr.js.map +7 -0
- package/package.json +72 -49
- package/dist/iife/transportr.js +0 -2656
- package/dist/iife/transportr.min.js +0 -3
- package/dist/iife/transportr.min.js.map +0 -7
- package/dist/transportr.min.js +0 -3
- package/dist/transportr.min.js.map +0 -7
- package/src/abort-signal.js +0 -124
- package/src/constants.js +0 -61
- package/src/http-error.js +0 -75
- package/src/http-media-type.js +0 -162
- package/src/http-request-headers.js +0 -312
- package/src/http-request-methods.js +0 -277
- package/src/http-response-headers.js +0 -350
- package/src/parameter-map.js +0 -221
- package/src/response-status.js +0 -62
- package/src/transportr.js +0 -838
package/src/parameter-map.js
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {Map<string, Array<*>>} ParameterMap
|
|
3
|
-
* @extends Map
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A {@link Map} that can contain multiple, unique, values for the same key.
|
|
8
|
-
*
|
|
9
|
-
* @type {ParameterMap<string, Array<*>>}
|
|
10
|
-
*/
|
|
11
|
-
export default class ParameterMap extends Map {
|
|
12
|
-
/**
|
|
13
|
-
* @param {Iterable<[string, *]>|Object} parameters The initial parameters to set.
|
|
14
|
-
* @returns {ParameterMap<string, *>} The ParameterMap with the updated key and value.
|
|
15
|
-
*/
|
|
16
|
-
constructor(parameters = {}) {
|
|
17
|
-
super();
|
|
18
|
-
for (const [key, value] of ParameterMap.#entries(parameters)) {
|
|
19
|
-
this.append(key, value);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Adds a new element with a specified key and value to the ParameterMap.
|
|
25
|
-
* If an element with the same key already exists, the value will be replaced in the underlying {@link Set}.
|
|
26
|
-
*
|
|
27
|
-
* @override
|
|
28
|
-
* @param {string} key The key to set.
|
|
29
|
-
* @param {*} value The value to add to the ParameterMap
|
|
30
|
-
* @returns {ParameterMap<string, *>} The ParameterMap with the updated key and value.
|
|
31
|
-
*/
|
|
32
|
-
set(key, value) {
|
|
33
|
-
const array = super.get(key);
|
|
34
|
-
if (array?.length > 0) {
|
|
35
|
-
array.length = 0;
|
|
36
|
-
array[0] = value;
|
|
37
|
-
} else {
|
|
38
|
-
super.set(key, [value]);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return this;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Adds all key-value pairs from an iterable or object to the ParameterMap.
|
|
46
|
-
* If a key already exists, the value will be replaced in the underlying {@link Array}.
|
|
47
|
-
*
|
|
48
|
-
* @param {Iterable<[string, *]>|Object} parameters The parameters to set.
|
|
49
|
-
* @returns {ParameterMap<string, *>} The ParameterMap with the updated key and value.
|
|
50
|
-
*/
|
|
51
|
-
setAll(parameters) {
|
|
52
|
-
for (const [key, value] of ParameterMap.#entries(parameters)) {
|
|
53
|
-
this.set(key, value);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return this;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Returns the value associated to the key, or undefined if there is none.
|
|
61
|
-
* If the key has multiple values, the first value will be returned.
|
|
62
|
-
* If the key has no values, undefined will be returned.
|
|
63
|
-
*
|
|
64
|
-
* @override
|
|
65
|
-
* @param {string} key The key to get.
|
|
66
|
-
* @returns {*} The value associated to the key, or undefined if there is none.
|
|
67
|
-
*/
|
|
68
|
-
get(key) {
|
|
69
|
-
return super.get(key)?.[0];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Returns an array of all values associated to the key, or undefined if there are none.
|
|
74
|
-
*
|
|
75
|
-
* @param {string} key The key to get.
|
|
76
|
-
* @returns {Array<*>} An array of all values associated to the key, or undefined if there are none.
|
|
77
|
-
*/
|
|
78
|
-
getAll(key) {
|
|
79
|
-
return super.get(key);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Appends a new value to an existing key inside a ParameterMap, or adds the new key if it does not exist.
|
|
84
|
-
*
|
|
85
|
-
* @param {string} key The key to append.
|
|
86
|
-
* @param {*} value The value to append.
|
|
87
|
-
* @returns {ParameterMap<string, *>} The ParameterMap with the updated key and value to allow chaining.
|
|
88
|
-
*/
|
|
89
|
-
append(key, value) {
|
|
90
|
-
const array = super.get(key);
|
|
91
|
-
if (array?.length > 0) {
|
|
92
|
-
array.push(value);
|
|
93
|
-
} else {
|
|
94
|
-
super.set(key, [value]);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return this;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Appends all key-value pairs from an iterable or object to the ParameterMap.
|
|
102
|
-
* If a key already exists, the value will be appended to the underlying {@link Array}.
|
|
103
|
-
* If a key does not exist, the key and value will be added to the ParameterMap.
|
|
104
|
-
*
|
|
105
|
-
* @param {Iterable<[string, *]>|Object} parameters The parameters to append.
|
|
106
|
-
* @returns {ParameterMap<string, *>} The ParameterMap with the updated key and value.
|
|
107
|
-
*/
|
|
108
|
-
appendAll(parameters) {
|
|
109
|
-
for (const [key, value] of ParameterMap.#entries(parameters)) {
|
|
110
|
-
this.append(key, value);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return this;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Checks if a specific key has a specific value.
|
|
118
|
-
*
|
|
119
|
-
* @param {*} value The value to check.
|
|
120
|
-
* @returns {boolean} True if the key has the value, false otherwise.
|
|
121
|
-
*/
|
|
122
|
-
hasValue(value) {
|
|
123
|
-
for (const array of super.values()) {
|
|
124
|
-
if (array.includes(value)) {
|
|
125
|
-
return true;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Removes a specific value from a specific key.
|
|
134
|
-
*
|
|
135
|
-
* @param {*} value The value to remove.
|
|
136
|
-
* @returns {boolean} True if the value was removed, false otherwise.
|
|
137
|
-
*/
|
|
138
|
-
deleteValue(value) {
|
|
139
|
-
for (const array of this.values()) {
|
|
140
|
-
if (array.includes(value)) {
|
|
141
|
-
return array.splice(array.indexOf(value), 1).length > 0;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Determines whether the ParameterMap contains anything.
|
|
150
|
-
*
|
|
151
|
-
* @returns {boolean} True if the ParameterMap size is greater than 0, false otherwise.
|
|
152
|
-
*/
|
|
153
|
-
isEmpty() {
|
|
154
|
-
return this.size === 0;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Returns an Object that can be serialized to JSON.
|
|
159
|
-
* If a key has only one value, the value will be a single value.
|
|
160
|
-
* If a key has multiple values, the value will be an array of values.
|
|
161
|
-
* If a key has no values, the value will be undefined.
|
|
162
|
-
*
|
|
163
|
-
* @override
|
|
164
|
-
* @returns {Object} The Object to be serialized to JSON.
|
|
165
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#toJSON_behavior}
|
|
166
|
-
*/
|
|
167
|
-
toJSON() {
|
|
168
|
-
const obj = Object.create(null);
|
|
169
|
-
|
|
170
|
-
for (const [key, values] of super.entries()) {
|
|
171
|
-
obj[key] = values.length === 1 ? values[0] : values;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return obj;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Returns an iterator that yields all key-value pairs in the map as arrays in their insertion order.
|
|
179
|
-
*
|
|
180
|
-
* @override
|
|
181
|
-
* @yields {[string, *]} An iterator for the key-value pairs in the map.
|
|
182
|
-
*/
|
|
183
|
-
*entries() {
|
|
184
|
-
for (const [key, array] of super.entries()) {
|
|
185
|
-
for (const value of array) { yield [key, value] }
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Returns an iterator that yields all key-value pairs in the map as arrays in their insertion order.
|
|
191
|
-
*
|
|
192
|
-
* @override
|
|
193
|
-
* @yields {[string, *]} An iterator for the key-value pairs in the map.
|
|
194
|
-
*/
|
|
195
|
-
*[Symbol.iterator]() {
|
|
196
|
-
yield* this.entries();
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Returns an iterable of key, value pairs for every entry in the parameters object.
|
|
201
|
-
*
|
|
202
|
-
* @private
|
|
203
|
-
* @static
|
|
204
|
-
* @param {Iterable<[string, *]>|Object} parameters The parameters to set.
|
|
205
|
-
* @returns {Iterable<[string, *]>} An iterable of key, value pairs for every entry in the parameters object.
|
|
206
|
-
*/
|
|
207
|
-
static #entries(parameters) {
|
|
208
|
-
return parameters[Symbol.iterator] ? parameters : Object.entries(parameters);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* A String value that is used in the creation of the default string description of an object.
|
|
213
|
-
* Called by the built-in method {@link Object.prototype.toString}.
|
|
214
|
-
*
|
|
215
|
-
* @override
|
|
216
|
-
* @returns {string} The default string description of this object.
|
|
217
|
-
*/
|
|
218
|
-
get [Symbol.toStringTag]() {
|
|
219
|
-
return 'ParameterMap';
|
|
220
|
-
}
|
|
221
|
-
}
|
package/src/response-status.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A class that holds a status code and a status text
|
|
3
|
-
*
|
|
4
|
-
* @module ResponseStatus
|
|
5
|
-
* @author D1g1talEntr0py <jason.dimeo@gmail.com>
|
|
6
|
-
*/
|
|
7
|
-
export default class ResponseStatus {
|
|
8
|
-
/** @type {number} */
|
|
9
|
-
#code;
|
|
10
|
-
/** @type {string} */
|
|
11
|
-
#text;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
* @param {number} code The status code from the {@link Response}
|
|
16
|
-
* @param {string} text The status text from the {@link Response}
|
|
17
|
-
*/
|
|
18
|
-
constructor(code, text) {
|
|
19
|
-
this.#code = code;
|
|
20
|
-
this.#text = text;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Returns the status code from the {@link Response}
|
|
25
|
-
*
|
|
26
|
-
* @returns {number} The status code.
|
|
27
|
-
*/
|
|
28
|
-
get code() {
|
|
29
|
-
return this.#code;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Returns the status text from the {@link Response}.
|
|
34
|
-
*
|
|
35
|
-
* @returns {string} The status text.
|
|
36
|
-
*/
|
|
37
|
-
get text() {
|
|
38
|
-
return this.#text;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* A String value that is used in the creation of the default string
|
|
43
|
-
* description of an object. Called by the built-in method {@link Object.prototype.toString}.
|
|
44
|
-
*
|
|
45
|
-
* @override
|
|
46
|
-
* @returns {string} The default string description of this object.
|
|
47
|
-
*/
|
|
48
|
-
get [Symbol.toStringTag]() {
|
|
49
|
-
return 'ResponseStatus';
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* tostring method for the class.
|
|
54
|
-
*
|
|
55
|
-
* @override
|
|
56
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString|Object.prototype.toString}
|
|
57
|
-
* @returns {string} The status code and status text.
|
|
58
|
-
*/
|
|
59
|
-
toString() {
|
|
60
|
-
return `${this.#code} ${this.#text}`;
|
|
61
|
-
}
|
|
62
|
-
}
|