@opra/common 0.22.0 → 0.23.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/browser.js +806 -1421
- package/cjs/document/api-document.js +7 -3
- package/cjs/document/data-type/api-field.js +2 -2
- package/cjs/document/data-type/complex-type.js +17 -63
- package/cjs/document/data-type/data-type.js +0 -9
- package/cjs/document/data-type/enum-type.js +2 -8
- package/cjs/document/data-type/mapped-type.js +0 -36
- package/cjs/document/data-type/simple-type.js +2 -8
- package/cjs/document/data-type/union-type.js +0 -36
- package/cjs/document/index.js +2 -0
- package/cjs/document/resource/collection.js +75 -32
- package/cjs/document/resource/singleton.js +31 -20
- package/cjs/document/resource/storage.js +6 -20
- package/cjs/document/utils/generate-codec.js +39 -0
- package/cjs/exception/resource-errors/resource-not-found.error.js +1 -1
- package/cjs/helpers/index.js +1 -1
- package/cjs/helpers/is-url-string.js +14 -0
- package/cjs/helpers/object-utils.js +2 -2
- package/cjs/helpers/responsive-map.js +4 -4
- package/cjs/helpers/type-guards.js +15 -3
- package/cjs/http/index.js +2 -9
- package/cjs/http/opra-url-path.js +251 -0
- package/cjs/{url → http}/opra-url.js +53 -109
- package/cjs/i18n/i18n.js +1 -1
- package/cjs/index.js +0 -2
- package/cjs/schema/opra-schema.ns.js +1 -1
- package/cjs/schema/resource/operation.interface.js +2 -0
- package/esm/document/api-document.js +9 -5
- package/esm/document/data-type/api-field.js +2 -2
- package/esm/document/data-type/complex-type.js +13 -59
- package/esm/document/data-type/data-type.js +0 -9
- package/esm/document/data-type/enum-type.js +2 -8
- package/esm/document/data-type/mapped-type.js +0 -36
- package/esm/document/data-type/simple-type.js +2 -8
- package/esm/document/data-type/union-type.js +0 -36
- package/esm/document/index.js +2 -0
- package/esm/document/resource/collection.js +75 -32
- package/esm/document/resource/singleton.js +31 -20
- package/esm/document/resource/storage.js +6 -20
- package/esm/document/utils/generate-codec.js +33 -0
- package/esm/exception/resource-errors/resource-not-found.error.js +1 -1
- package/esm/helpers/index.js +1 -1
- package/esm/helpers/is-url-string.js +9 -0
- package/esm/helpers/object-utils.js +2 -2
- package/esm/helpers/responsive-map.js +4 -4
- package/esm/helpers/type-guards.js +11 -2
- package/esm/http/index.js +2 -9
- package/esm/http/opra-url-path.js +246 -0
- package/esm/{url → http}/opra-url.js +53 -109
- package/esm/i18n/i18n.js +2 -2
- package/esm/index.js +0 -2
- package/esm/schema/opra-schema.ns.js +1 -1
- package/esm/schema/resource/operation.interface.js +1 -0
- package/package.json +1 -1
- package/types/document/api-document.d.ts +4 -1
- package/types/document/data-type/complex-type.d.ts +6 -11
- package/types/document/data-type/data-type.d.ts +0 -6
- package/types/document/data-type/enum-type.d.ts +2 -4
- package/types/document/data-type/mapped-type.d.ts +0 -4
- package/types/document/data-type/simple-type.d.ts +2 -4
- package/types/document/data-type/union-type.d.ts +0 -5
- package/types/document/index.d.ts +2 -0
- package/types/document/interfaces/collection-resource.interface.d.ts +10 -0
- package/types/document/interfaces/singleton-resource.interface.d.ts +7 -0
- package/types/document/interfaces/storage-resource.interface.d.ts +8 -0
- package/types/document/resource/collection.d.ts +41 -35
- package/types/document/resource/resource.d.ts +2 -1
- package/types/document/resource/singleton.d.ts +24 -21
- package/types/document/resource/storage.d.ts +14 -17
- package/types/document/utils/generate-codec.d.ts +10 -0
- package/types/helpers/index.d.ts +1 -1
- package/types/helpers/is-url-string.d.ts +2 -0
- package/types/helpers/object-utils.d.ts +1 -1
- package/types/helpers/type-guards.d.ts +3 -0
- package/types/http/index.d.ts +2 -9
- package/types/http/opra-url-path.d.ts +54 -0
- package/types/{url → http}/opra-url.d.ts +9 -13
- package/types/index.d.ts +0 -2
- package/types/schema/opra-schema.ns.d.ts +1 -1
- package/types/schema/resource/collection.interface.d.ts +29 -8
- package/types/schema/resource/operation.interface.d.ts +3 -0
- package/types/schema/resource/resource.interface.d.ts +1 -0
- package/types/schema/resource/singleton.interface.d.ts +5 -5
- package/types/schema/resource/storage.interface.d.ts +42 -5
- package/cjs/helpers/is-url.js +0 -8
- package/cjs/http/codecs/boolean-codec.js +0 -24
- package/cjs/http/codecs/date-codec.js +0 -41
- package/cjs/http/codecs/filter-codec.js +0 -17
- package/cjs/http/codecs/integer-codec.js +0 -19
- package/cjs/http/codecs/number-codec.js +0 -24
- package/cjs/http/codecs/string-codec.js +0 -23
- package/cjs/http/http-params.js +0 -353
- package/cjs/http/multipart/batch-multipart.js +0 -170
- package/cjs/http/multipart/http-request-content.js +0 -17
- package/cjs/http/multipart/http-response-content.js +0 -14
- package/cjs/http/multipart/index.js +0 -2
- package/cjs/url/index.js +0 -8
- package/cjs/url/opra-url-path-component.js +0 -30
- package/cjs/url/opra-url-path.js +0 -155
- package/cjs/url/utils/decode-path-component.js +0 -41
- package/cjs/url/utils/encode-path-component.js +0 -27
- package/cjs/utils/path-utils.js +0 -24
- package/esm/helpers/is-url.js +0 -4
- package/esm/http/codecs/boolean-codec.js +0 -20
- package/esm/http/codecs/date-codec.js +0 -37
- package/esm/http/codecs/filter-codec.js +0 -13
- package/esm/http/codecs/integer-codec.js +0 -15
- package/esm/http/codecs/number-codec.js +0 -20
- package/esm/http/codecs/string-codec.js +0 -19
- package/esm/http/http-params.js +0 -348
- package/esm/http/multipart/batch-multipart.js +0 -170
- package/esm/http/multipart/http-request-content.js +0 -17
- package/esm/http/multipart/http-response-content.js +0 -14
- package/esm/http/multipart/index.js +0 -2
- package/esm/url/index.js +0 -5
- package/esm/url/opra-url-path-component.js +0 -26
- package/esm/url/opra-url-path.js +0 -151
- package/esm/url/utils/decode-path-component.js +0 -37
- package/esm/url/utils/encode-path-component.js +0 -22
- package/esm/utils/path-utils.js +0 -19
- package/types/helpers/is-url.d.ts +0 -1
- package/types/http/codecs/boolean-codec.d.ts +0 -5
- package/types/http/codecs/date-codec.d.ts +0 -16
- package/types/http/codecs/filter-codec.d.ts +0 -6
- package/types/http/codecs/integer-codec.d.ts +0 -11
- package/types/http/codecs/number-codec.d.ts +0 -14
- package/types/http/codecs/string-codec.d.ts +0 -16
- package/types/http/http-params.d.ts +0 -114
- package/types/http/interfaces/client-http-headers.interface.d.ts +0 -65
- package/types/http/interfaces/server-http-headers.interface.d.ts +0 -1
- package/types/http/multipart/batch-multipart.d.ts +0 -0
- package/types/http/multipart/http-request-content.d.ts +0 -0
- package/types/http/multipart/http-response-content.d.ts +0 -0
- package/types/http/multipart/index.d.ts +0 -0
- package/types/schema/resource/endpoint.interface.d.ts +0 -29
- package/types/url/index.d.ts +0 -5
- package/types/url/opra-url-path-component.d.ts +0 -15
- package/types/url/opra-url-path.d.ts +0 -36
- package/types/url/utils/decode-path-component.d.ts +0 -5
- package/types/url/utils/encode-path-component.d.ts +0 -1
- package/types/utils/path-utils.d.ts +0 -2
- /package/cjs/{http/interfaces/client-http-headers.interface.js → document/interfaces/collection-resource.interface.js} +0 -0
- /package/cjs/{http/interfaces/server-http-headers.interface.js → document/interfaces/singleton-resource.interface.js} +0 -0
- /package/cjs/{schema/resource/endpoint.interface.js → document/interfaces/storage-resource.interface.js} +0 -0
- /package/esm/{http/interfaces/client-http-headers.interface.js → document/interfaces/collection-resource.interface.js} +0 -0
- /package/esm/{http/interfaces/server-http-headers.interface.js → document/interfaces/singleton-resource.interface.js} +0 -0
- /package/esm/{schema/resource/endpoint.interface.js → document/interfaces/storage-resource.interface.js} +0 -0
package/esm/http/http-params.js
DELETED
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
var _a, _b, _c;
|
|
2
|
-
import { splitString, tokenize } from 'fast-tokenizer';
|
|
3
|
-
import { ResponsiveMap } from '../helpers/index.js';
|
|
4
|
-
import { BooleanCodec } from './codecs/boolean-codec.js';
|
|
5
|
-
import { DateCodec } from './codecs/date-codec.js';
|
|
6
|
-
import { FilterCodec } from './codecs/filter-codec.js';
|
|
7
|
-
import { IntegerCodec } from './codecs/integer-codec.js';
|
|
8
|
-
import { NumberCodec } from './codecs/number-codec.js';
|
|
9
|
-
import { StringCodec } from './codecs/string-codec.js';
|
|
10
|
-
const kEntries = Symbol('kEntries');
|
|
11
|
-
const kSize = Symbol('kSize');
|
|
12
|
-
const kParamDefs = Symbol('kParamDefs');
|
|
13
|
-
const kOptions = Symbol('kOptions');
|
|
14
|
-
export class HttpParams {
|
|
15
|
-
constructor(init, options) {
|
|
16
|
-
this[_a] = new ResponsiveMap();
|
|
17
|
-
this[_b] = 0;
|
|
18
|
-
this[_c] = new Map();
|
|
19
|
-
this[kOptions] = { ...options, onChange: undefined };
|
|
20
|
-
const defineParams = options?.params;
|
|
21
|
-
if (defineParams)
|
|
22
|
-
Object.keys(defineParams).forEach(key => this.define(key, defineParams[key]));
|
|
23
|
-
if (init)
|
|
24
|
-
this.appendAll(init);
|
|
25
|
-
this[kOptions].onChange = options?.onChange;
|
|
26
|
-
}
|
|
27
|
-
get size() {
|
|
28
|
-
return this[kSize];
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Appends a new value to the existing set of values for a parameter
|
|
32
|
-
* and returns this instance
|
|
33
|
-
*/
|
|
34
|
-
append(name, value) {
|
|
35
|
-
this._append(name, value);
|
|
36
|
-
this.changed();
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
appendAll(input) {
|
|
40
|
-
if (typeof input === 'string') {
|
|
41
|
-
if (input && input.startsWith('?'))
|
|
42
|
-
input = input.substring(1);
|
|
43
|
-
if (!input)
|
|
44
|
-
return this;
|
|
45
|
-
const tokenizer = tokenize(input, { delimiters: '&', quotes: true, brackets: true });
|
|
46
|
-
for (const token of tokenizer) {
|
|
47
|
-
if (!token)
|
|
48
|
-
continue;
|
|
49
|
-
const itemTokenizer = tokenize(token, {
|
|
50
|
-
delimiters: '=',
|
|
51
|
-
quotes: true,
|
|
52
|
-
brackets: true
|
|
53
|
-
});
|
|
54
|
-
const k = decodeURIComponent(itemTokenizer.next() || '');
|
|
55
|
-
const v = this.decodeValue(itemTokenizer.join('='), k);
|
|
56
|
-
this._append(k, v);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
else if (input.forEach && typeof input.forEach === 'function')
|
|
60
|
-
input.forEach((value, name) => this._append(name, value));
|
|
61
|
-
else
|
|
62
|
-
Object.keys(input).forEach(name => this._append(name, input[name]));
|
|
63
|
-
return this;
|
|
64
|
-
}
|
|
65
|
-
changed() {
|
|
66
|
-
if (this[kOptions].onChange)
|
|
67
|
-
this[kOptions].onChange();
|
|
68
|
-
}
|
|
69
|
-
clear() {
|
|
70
|
-
if (this[kEntries].size) {
|
|
71
|
-
this[kEntries].clear();
|
|
72
|
-
this[kSize] = 0;
|
|
73
|
-
this.changed();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Deletes values for a given parameter
|
|
78
|
-
*/
|
|
79
|
-
delete(name, value) {
|
|
80
|
-
if (this._delete(name, value))
|
|
81
|
-
this.changed();
|
|
82
|
-
return this;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Returns an iterable of key, value pairs for every entry in the map.
|
|
86
|
-
*/
|
|
87
|
-
entries() {
|
|
88
|
-
const iter = this[kEntries].entries();
|
|
89
|
-
let i = 0;
|
|
90
|
-
let key;
|
|
91
|
-
let values;
|
|
92
|
-
return {
|
|
93
|
-
[Symbol.iterator]() {
|
|
94
|
-
return this;
|
|
95
|
-
},
|
|
96
|
-
next() {
|
|
97
|
-
if (values) {
|
|
98
|
-
if (i >= values.length) {
|
|
99
|
-
values = undefined;
|
|
100
|
-
i = 0;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (!values) {
|
|
104
|
-
const n = iter.next();
|
|
105
|
-
if (n.done)
|
|
106
|
-
return { done: true, value: undefined };
|
|
107
|
-
key = n.value[0];
|
|
108
|
-
values = n.value[1];
|
|
109
|
-
}
|
|
110
|
-
return {
|
|
111
|
-
done: false,
|
|
112
|
-
value: [key, values[i++]]
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
forEach(callbackFn, thisArg) {
|
|
118
|
-
const iterator = this.entries();
|
|
119
|
-
let entry = iterator.next();
|
|
120
|
-
while (!entry.done) {
|
|
121
|
-
callbackFn.call(thisArg || this, entry.value[1], entry.value[0], this);
|
|
122
|
-
entry = iterator.next();
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Retrieves value of a given parameter at given index
|
|
127
|
-
*/
|
|
128
|
-
get(name, index = 0) {
|
|
129
|
-
const values = this[kEntries].get(name);
|
|
130
|
-
return values && values.length > index ? values[index] : null;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Retrieves an array of values for a given parameter.
|
|
134
|
-
*/
|
|
135
|
-
getAll(name) {
|
|
136
|
-
const entry = this[kEntries].get(name);
|
|
137
|
-
return entry ? entry.slice(0) : null;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Retrieves the names of the parameters.
|
|
141
|
-
*/
|
|
142
|
-
keys() {
|
|
143
|
-
return this[kEntries].keys();
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Retrieves the names of the parameters.
|
|
147
|
-
*/
|
|
148
|
-
values() {
|
|
149
|
-
const items = [];
|
|
150
|
-
this.forEach((value) => items.push(value));
|
|
151
|
-
return items.values();
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Checks for existence of a parameter.
|
|
155
|
-
*/
|
|
156
|
-
has(name) {
|
|
157
|
-
return this[kEntries].has(name);
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Sets or modifies a value for a given parameter.
|
|
161
|
-
* If the header already exists, its value is replaced with the given value
|
|
162
|
-
*/
|
|
163
|
-
set(name, value) {
|
|
164
|
-
this._set(name, value);
|
|
165
|
-
this.changed();
|
|
166
|
-
return this;
|
|
167
|
-
}
|
|
168
|
-
sort(compareFn) {
|
|
169
|
-
this[kEntries].sort(compareFn);
|
|
170
|
-
this.changed();
|
|
171
|
-
return this;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Serializes the body to an encoded string, where key-value pairs (separated by `=`) are
|
|
175
|
-
* separated by `&`s.
|
|
176
|
-
*/
|
|
177
|
-
toString() {
|
|
178
|
-
const out = [];
|
|
179
|
-
this.forEach((v, k) => {
|
|
180
|
-
out.push(encodeURIParam(k) +
|
|
181
|
-
(v ? '=' + this.encodeValue(v, k) : ''));
|
|
182
|
-
});
|
|
183
|
-
return out.join('&');
|
|
184
|
-
}
|
|
185
|
-
getProxy() {
|
|
186
|
-
const _this = this;
|
|
187
|
-
return this[kEntries].getProxy({
|
|
188
|
-
get(target, p, receiver) {
|
|
189
|
-
if (typeof p === 'string') {
|
|
190
|
-
const v = _this[kEntries].get(p);
|
|
191
|
-
return v ? (v.length > 1 ? v : v[0]) : null;
|
|
192
|
-
}
|
|
193
|
-
return Reflect.get(target, p, receiver);
|
|
194
|
-
},
|
|
195
|
-
set(target, p, newValue, receiver) {
|
|
196
|
-
if (typeof p === 'string') {
|
|
197
|
-
_this.set(p, newValue);
|
|
198
|
-
return true;
|
|
199
|
-
}
|
|
200
|
-
return Reflect.set(target, p, newValue, receiver);
|
|
201
|
-
},
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
define(arg0, options) {
|
|
205
|
-
if (typeof arg0 === 'object') {
|
|
206
|
-
for (const [name, def] of Object.entries(arg0))
|
|
207
|
-
this.define(name, def);
|
|
208
|
-
return this;
|
|
209
|
-
}
|
|
210
|
-
if (!arg0)
|
|
211
|
-
throw new Error('"name" argument required');
|
|
212
|
-
if (!options)
|
|
213
|
-
throw new Error('"options" argument required');
|
|
214
|
-
if (typeof options.codec === 'string' && !HttpParams.codecs[options.codec])
|
|
215
|
-
throw new Error(`Unknown url parameter format name "${options.codec}"`);
|
|
216
|
-
const codec = (typeof options?.codec === 'string'
|
|
217
|
-
? HttpParams.codecs[options.codec]
|
|
218
|
-
: options?.codec) || HttpParams.codecs.string;
|
|
219
|
-
const meta = {
|
|
220
|
-
...options,
|
|
221
|
-
codec
|
|
222
|
-
};
|
|
223
|
-
this[kParamDefs].set(arg0, meta);
|
|
224
|
-
return this;
|
|
225
|
-
}
|
|
226
|
-
encodeValue(value, key) {
|
|
227
|
-
const prmDef = this[kParamDefs].get(key);
|
|
228
|
-
if (prmDef) {
|
|
229
|
-
const delimReplace = '%' + (prmDef.arrayDelimiter || ',').charCodeAt(0).toString(16).toUpperCase();
|
|
230
|
-
const fn = (x) => encodeURIParam(prmDef.codec.encode(x))
|
|
231
|
-
.replace(/,/g, delimReplace);
|
|
232
|
-
return Array.isArray(value)
|
|
233
|
-
? value.map((v) => fn(v)).join(prmDef.arrayDelimiter || ',')
|
|
234
|
-
: fn(value);
|
|
235
|
-
}
|
|
236
|
-
return encodeURIParam(String(value));
|
|
237
|
-
}
|
|
238
|
-
decodeValue(value, key) {
|
|
239
|
-
const prmDef = this[kParamDefs].get(key);
|
|
240
|
-
let val = value;
|
|
241
|
-
if (prmDef) {
|
|
242
|
-
if (prmDef.array) {
|
|
243
|
-
val = splitString(value, {
|
|
244
|
-
delimiters: prmDef.arrayDelimiter || ',',
|
|
245
|
-
brackets: true,
|
|
246
|
-
quotes: true,
|
|
247
|
-
keepQuotes: false
|
|
248
|
-
}).map((x) => decodeURIComponent(x));
|
|
249
|
-
}
|
|
250
|
-
else
|
|
251
|
-
val = decodeURIComponent(val);
|
|
252
|
-
const fn = (x) => prmDef.codec.decode(decodeURIComponent(x));
|
|
253
|
-
val = Array.isArray(val) ? val.map(fn) : fn(val);
|
|
254
|
-
if (prmDef.array === 'strict')
|
|
255
|
-
val = Array.isArray(val) ? val : [val];
|
|
256
|
-
else if (prmDef.array)
|
|
257
|
-
val = Array.isArray(val) && val.length === 1 ? val[0] : val;
|
|
258
|
-
if (Array.isArray(val)) {
|
|
259
|
-
if (prmDef.minArrayItems && val.length < prmDef.minArrayItems)
|
|
260
|
-
throw new Error(`"${key}" parameter requires at least ${prmDef.minArrayItems} values`);
|
|
261
|
-
if (prmDef.maxArrayItems && val.length > prmDef.maxArrayItems)
|
|
262
|
-
throw new Error(`"${key}" parameter accepts up to ${prmDef.maxArrayItems} values`);
|
|
263
|
-
}
|
|
264
|
-
return val;
|
|
265
|
-
}
|
|
266
|
-
return decodeURIComponent(value);
|
|
267
|
-
}
|
|
268
|
-
[(_a = kEntries, _b = kSize, _c = kParamDefs, Symbol.iterator)]() {
|
|
269
|
-
return this.entries();
|
|
270
|
-
}
|
|
271
|
-
get [Symbol.toStringTag]() {
|
|
272
|
-
return 'HttpParams';
|
|
273
|
-
}
|
|
274
|
-
_append(name, value) {
|
|
275
|
-
let values = this[kEntries].get(name);
|
|
276
|
-
if (!values) {
|
|
277
|
-
values = [];
|
|
278
|
-
this[kEntries].set(name, values);
|
|
279
|
-
}
|
|
280
|
-
values.push(value ?? null);
|
|
281
|
-
this[kSize] += 1;
|
|
282
|
-
}
|
|
283
|
-
_delete(name, value) {
|
|
284
|
-
const oldValues = this[kEntries].get(name);
|
|
285
|
-
if (!oldValues)
|
|
286
|
-
return false;
|
|
287
|
-
const oldSize = this[kSize];
|
|
288
|
-
if (value) {
|
|
289
|
-
const newValues = oldValues.filter(x => x === value);
|
|
290
|
-
this[kEntries].set(name, newValues);
|
|
291
|
-
this[kSize] += -oldValues.length + newValues.length;
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
294
|
-
this[kEntries].delete(name);
|
|
295
|
-
this[kSize] -= oldValues.length;
|
|
296
|
-
}
|
|
297
|
-
return oldSize !== this[kSize];
|
|
298
|
-
}
|
|
299
|
-
_set(name, value, index) {
|
|
300
|
-
if (value === undefined) {
|
|
301
|
-
this._delete(name);
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
const values = this[kEntries].get(name);
|
|
305
|
-
if (!values) {
|
|
306
|
-
this[kEntries].set(name, [value]);
|
|
307
|
-
this[kSize] += 1;
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
if (index == null || index < 0) {
|
|
311
|
-
this[kEntries].set(name, [value]);
|
|
312
|
-
this[kSize] += -(values.length) + 1;
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
const oldLen = values.length;
|
|
316
|
-
values[Math.min(index, values.length)] = value;
|
|
317
|
-
this[kSize] += -oldLen + values.length;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
HttpParams.kEntries = kEntries;
|
|
321
|
-
HttpParams.kSize = kSize;
|
|
322
|
-
HttpParams.kParamDefs = kParamDefs;
|
|
323
|
-
HttpParams.kOptions = kOptions;
|
|
324
|
-
HttpParams.codecs = {
|
|
325
|
-
'boolean': new BooleanCodec(),
|
|
326
|
-
'date': new DateCodec(),
|
|
327
|
-
'filter': new FilterCodec(),
|
|
328
|
-
'integer': new IntegerCodec(),
|
|
329
|
-
'number': new NumberCodec(),
|
|
330
|
-
'string': new StringCodec()
|
|
331
|
-
};
|
|
332
|
-
/**
|
|
333
|
-
* Encode input string with standard encodeURIComponent and then un-encode specific characters.
|
|
334
|
-
*/
|
|
335
|
-
const ENCODING_REGEX = /%(\d[a-f0-9])/gi;
|
|
336
|
-
const ENCODING_REPLACEMENTS = {
|
|
337
|
-
'2C': ',',
|
|
338
|
-
'2F': '/',
|
|
339
|
-
'24': '$',
|
|
340
|
-
'3A': ':',
|
|
341
|
-
'3B': ';',
|
|
342
|
-
'3D': '=',
|
|
343
|
-
'3F': '?',
|
|
344
|
-
'40': '@'
|
|
345
|
-
};
|
|
346
|
-
export function encodeURIParam(v) {
|
|
347
|
-
return encodeURIComponent(v).replace(ENCODING_REGEX, (s, t) => ENCODING_REPLACEMENTS[t] ?? s);
|
|
348
|
-
}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// import Highland from '@browsery/highland';
|
|
3
|
-
// import { Readable } from 'stream';
|
|
4
|
-
// import { uid } from 'uid';
|
|
5
|
-
// import { isReadable } from '../../helpers/index.js';
|
|
6
|
-
// import { HttpHeaderCodes } from '../enums/http-headers-codes.enum.js';
|
|
7
|
-
// import { HttpStatusCodes } from '../enums/http-status-codes.enum.js';
|
|
8
|
-
// import { normalizeHeaders } from '../utils/normalize-headers.js';
|
|
9
|
-
// import { HttpRequestContent, IHttpRequestContent } from './http-request-content.js';
|
|
10
|
-
// import { HttpResponseContent, IHttpResponseContent } from './http-response-content.js';
|
|
11
|
-
//
|
|
12
|
-
// const CRLF = '\r\n';
|
|
13
|
-
// const CHARSET_PATTERN = / *charset=./i;
|
|
14
|
-
//
|
|
15
|
-
// type Part = {
|
|
16
|
-
// headers: Record<string, string | string[]>;
|
|
17
|
-
// contentId?: string;
|
|
18
|
-
// content: HttpRequestContent | HttpResponseContent | BatchMultipart;
|
|
19
|
-
// }
|
|
20
|
-
//
|
|
21
|
-
// export class BatchMultipart {
|
|
22
|
-
// protected _parts: Part[] = [];
|
|
23
|
-
// readonly boundary: string;
|
|
24
|
-
//
|
|
25
|
-
// constructor() {
|
|
26
|
-
// this.boundary = 'batch_' + uid(12);
|
|
27
|
-
// }
|
|
28
|
-
//
|
|
29
|
-
// addRequestPart(content: IHttpRequestContent, part?: {
|
|
30
|
-
// contentId?: string;
|
|
31
|
-
// headers?: Record<string, string | string[]>;
|
|
32
|
-
// }): this {
|
|
33
|
-
// const headers: any = {
|
|
34
|
-
// ...normalizeHeaders(part?.headers || {}, true),
|
|
35
|
-
// [HttpHeaderCodes.Content_Type]: 'application/http',
|
|
36
|
-
// [HttpHeaderCodes.Content_Transfer_Encoding]: 'binary'
|
|
37
|
-
// };
|
|
38
|
-
// if (part?.contentId)
|
|
39
|
-
// headers[HttpHeaderCodes.Content_ID] = part.contentId;
|
|
40
|
-
// this._parts.push({
|
|
41
|
-
// headers,
|
|
42
|
-
// contentId: part?.contentId,
|
|
43
|
-
// content: new HttpRequestContent(content)
|
|
44
|
-
// });
|
|
45
|
-
// return this;
|
|
46
|
-
// }
|
|
47
|
-
//
|
|
48
|
-
// addHttpResponse(content: IHttpResponseContent, part?: {
|
|
49
|
-
// contentId?: string;
|
|
50
|
-
// headers?: Record<string, string | string[]>;
|
|
51
|
-
// }): this {
|
|
52
|
-
// const headers: any = {
|
|
53
|
-
// ...normalizeHeaders(part?.headers || {}, true),
|
|
54
|
-
// [HttpHeaderCodes.Content_Type]: 'application/http',
|
|
55
|
-
// [HttpHeaderCodes.Content_Transfer_Encoding]: 'binary'
|
|
56
|
-
// };
|
|
57
|
-
// if (part?.contentId)
|
|
58
|
-
// headers[HttpHeaderCodes.Content_ID] = part.contentId;
|
|
59
|
-
// this._parts.push({
|
|
60
|
-
// headers,
|
|
61
|
-
// contentId: part?.contentId,
|
|
62
|
-
// content: new HttpResponseContent(content)
|
|
63
|
-
// });
|
|
64
|
-
// return this;
|
|
65
|
-
// }
|
|
66
|
-
//
|
|
67
|
-
// addBatch(batch: BatchMultipart, part?: {
|
|
68
|
-
// contentId?: string;
|
|
69
|
-
// headers?: Record<string, string | string[]>;
|
|
70
|
-
// }): this {
|
|
71
|
-
// const headers: any = {
|
|
72
|
-
// ...normalizeHeaders(part?.headers || {}, true),
|
|
73
|
-
// [HttpHeaderCodes.Content_Type]: 'application/http',
|
|
74
|
-
// [HttpHeaderCodes.Content_Transfer_Encoding]: 'binary'
|
|
75
|
-
// };
|
|
76
|
-
// if (part?.contentId)
|
|
77
|
-
// headers[HttpHeaderCodes.Content_ID] = part.contentId;
|
|
78
|
-
// this._parts.push({
|
|
79
|
-
// headers,
|
|
80
|
-
// contentId: part?.contentId,
|
|
81
|
-
// content: batch
|
|
82
|
-
// });
|
|
83
|
-
// return this;
|
|
84
|
-
// }
|
|
85
|
-
//
|
|
86
|
-
// stream(): NodeJS.ReadableStream {
|
|
87
|
-
// const chunks: (Buffer | Readable)[] = [];
|
|
88
|
-
// this._build(chunks);
|
|
89
|
-
// return Highland(chunks).flatten().toNodeStream();
|
|
90
|
-
// }
|
|
91
|
-
//
|
|
92
|
-
// protected _build(target: (Buffer | Readable)[]) {
|
|
93
|
-
// for (const part of this._parts) {
|
|
94
|
-
// if (part.content instanceof HttpRequestContent || part.content instanceof HttpResponseContent) {
|
|
95
|
-
// let contentBody = part.content.data;
|
|
96
|
-
// let contentLength = 0;
|
|
97
|
-
// const contentHeaders = normalizeHeaders(part.content.headers);
|
|
98
|
-
// if (contentBody) {
|
|
99
|
-
// const contentType = String(contentHeaders['content-type'] || '').split(/\s*;\s*/);
|
|
100
|
-
// let charset = '';
|
|
101
|
-
// if (isReadable(contentBody)) {
|
|
102
|
-
// contentLength = parseInt(String(contentHeaders['content-length']), 10) || 0;
|
|
103
|
-
// // const l = parseInt(String(contentHeaders['content-length']), 10);
|
|
104
|
-
// // if (isNaN(l))
|
|
105
|
-
// // throw new TypeError('"content-length" header required for streamed responses');
|
|
106
|
-
// } else if (typeof contentBody === 'object') {
|
|
107
|
-
// if (typeof contentBody.stream === 'function') { // File and Blob
|
|
108
|
-
// contentType[0] = contentBody.type || 'binary';
|
|
109
|
-
// contentLength = contentBody.size;
|
|
110
|
-
// contentBody = contentBody.stream();
|
|
111
|
-
// } else if (Buffer.isBuffer(contentBody)) {
|
|
112
|
-
// contentHeaders['content-length'] = String(contentBody.length);
|
|
113
|
-
// } else {
|
|
114
|
-
// contentType[0] = contentType[0] || 'application/json';
|
|
115
|
-
// charset = 'utf-8';
|
|
116
|
-
// contentBody = Buffer.from(JSON.stringify(contentBody), 'utf-8');
|
|
117
|
-
// contentLength = contentBody.length;
|
|
118
|
-
// }
|
|
119
|
-
// } else {
|
|
120
|
-
// contentType[0] = contentType[0] || 'text/plain';
|
|
121
|
-
// charset = 'utf-8';
|
|
122
|
-
// contentBody = Buffer.from(String(contentBody), 'utf-8');
|
|
123
|
-
// contentLength = contentBody.length;
|
|
124
|
-
// }
|
|
125
|
-
// if (contentType[0]) {
|
|
126
|
-
// if (charset) {
|
|
127
|
-
// const i = contentType.findIndex(x => CHARSET_PATTERN.test(String(x)));
|
|
128
|
-
// if (i > 0) contentType[i] = 'charset=' + charset;
|
|
129
|
-
// else contentType.join('charset=' + charset);
|
|
130
|
-
// }
|
|
131
|
-
// contentHeaders['content-type'] = contentType.join(';');
|
|
132
|
-
// }
|
|
133
|
-
// if (contentLength)
|
|
134
|
-
// contentHeaders['content-length'] = String(contentLength);
|
|
135
|
-
// }
|
|
136
|
-
//
|
|
137
|
-
// let s = '--' + this.boundary + CRLF;
|
|
138
|
-
// for (const [k, v] of Object.entries(part.headers)) {
|
|
139
|
-
// if (!(v === '' || v == null))
|
|
140
|
-
// s += k + ': ' + (Array.isArray(v) ? v.join(';') : v) + CRLF;
|
|
141
|
-
// }
|
|
142
|
-
// s += CRLF;
|
|
143
|
-
//
|
|
144
|
-
// if (part.content instanceof HttpRequestContent)
|
|
145
|
-
// s += (part.content.method || 'GET').toUpperCase() + ' ' + part.content.url + ' HTTP/1.1' + CRLF;
|
|
146
|
-
// else
|
|
147
|
-
// s += 'HTTP/1.1 ' + part.content.status + (HttpStatusCodes[part.content.status] || 'Unknown') + CRLF;
|
|
148
|
-
// if (part.content.headers) {
|
|
149
|
-
// for (const [k, v] of Object.entries(part.content.headers)) {
|
|
150
|
-
// if (v === '' || v == null)
|
|
151
|
-
// continue;
|
|
152
|
-
// if (k === 'set-cookie' && Array.isArray(v)) {
|
|
153
|
-
// v.forEach(x => s += k + ': ' + x);
|
|
154
|
-
// } else
|
|
155
|
-
// s += k + ': ' + (Array.isArray(v) ? v.join(';') : v) + CRLF;
|
|
156
|
-
// }
|
|
157
|
-
// }
|
|
158
|
-
// s += CRLF;
|
|
159
|
-
// target.push(Buffer.from(s, 'utf-8'));
|
|
160
|
-
//
|
|
161
|
-
// if (contentBody) {
|
|
162
|
-
// target.push(contentBody);
|
|
163
|
-
// target.push(Buffer.from(CRLF + CRLF));
|
|
164
|
-
// }
|
|
165
|
-
// } else throw new Error('Not implemented yet');
|
|
166
|
-
// }
|
|
167
|
-
// target.push(Buffer.from('--' + this.boundary + '--' + CRLF, 'utf-8'));
|
|
168
|
-
// }
|
|
169
|
-
//
|
|
170
|
-
// }
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
//
|
|
3
|
-
// export type IHttpRequestContent = Pick<HttpRequestContent, 'method' | 'url' | 'headers' | 'data'>;
|
|
4
|
-
//
|
|
5
|
-
// export class HttpRequestContent {
|
|
6
|
-
// method: string;
|
|
7
|
-
// url: string;
|
|
8
|
-
// headers?: Record<string, string | string[]>;
|
|
9
|
-
// data?: any;
|
|
10
|
-
//
|
|
11
|
-
// constructor(init: IHttpRequestContent) {
|
|
12
|
-
// this.method = init.method;
|
|
13
|
-
// this.url = encodeURI(decodeURI(init.url));
|
|
14
|
-
// this.headers = init.headers;
|
|
15
|
-
// this.data = init.data;
|
|
16
|
-
// }
|
|
17
|
-
// }
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// export type IHttpResponseContent = Pick<HttpResponseContent, 'status' | 'headers' | 'data'>;
|
|
3
|
-
//
|
|
4
|
-
// export class HttpResponseContent {
|
|
5
|
-
// status: number;
|
|
6
|
-
// headers?: Record<string, string | string[]>;
|
|
7
|
-
// data?: any;
|
|
8
|
-
//
|
|
9
|
-
// constructor(init: IHttpResponseContent) {
|
|
10
|
-
// this.status = init.status;
|
|
11
|
-
// this.headers = init.headers;
|
|
12
|
-
// this.data = init.data;
|
|
13
|
-
// }
|
|
14
|
-
// }
|
package/esm/url/index.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { encodePathComponent } from './utils/encode-path-component.js';
|
|
2
|
-
const nodeInspectCustom = Symbol.for('nodejs.util.inspect.custom');
|
|
3
|
-
export class OpraURLPathComponent {
|
|
4
|
-
constructor(init) {
|
|
5
|
-
this.resource = init.resource;
|
|
6
|
-
this.key = init.key;
|
|
7
|
-
this.typeCast = init.typeCast;
|
|
8
|
-
}
|
|
9
|
-
toString() {
|
|
10
|
-
const obj = encodePathComponent(this.resource, this.key, this.typeCast);
|
|
11
|
-
if (obj)
|
|
12
|
-
Object.setPrototypeOf(obj, OpraURLPathComponent.prototype);
|
|
13
|
-
return obj;
|
|
14
|
-
}
|
|
15
|
-
/* istanbul ignore next */
|
|
16
|
-
[nodeInspectCustom]() {
|
|
17
|
-
const out = {
|
|
18
|
-
resource: this.resource,
|
|
19
|
-
};
|
|
20
|
-
if (this.key != null)
|
|
21
|
-
out.key = this.key;
|
|
22
|
-
if (this.typeCast != null)
|
|
23
|
-
out.typeCast = this.typeCast;
|
|
24
|
-
return out;
|
|
25
|
-
}
|
|
26
|
-
}
|