@opra/client 0.20.1 → 0.21.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 +20 -17
- package/cjs/http/http-client.js +10 -10
- package/cjs/http/http-request-observable.js +5 -1
- package/cjs/http/http-request.js +5 -5
- package/cjs/http/http-response.js +2 -2
- package/esm/http/http-client.js +11 -11
- package/esm/http/http-request-observable.js +5 -1
- package/esm/http/http-request.js +6 -6
- package/esm/http/http-response.js +2 -2
- package/package.json +2 -2
- package/types/http/http-client.d.ts +2 -2
- package/types/http/http-collection-node.d.ts +2 -1
- package/types/http/http-request-observable.d.ts +2 -2
- package/types/http/http-request.d.ts +24 -22
- package/types/http/http-response.d.ts +2 -3
- package/types/http/http-singleton-node.d.ts +1 -1
- package/types/http/http-types.d.ts +2 -2
package/browser.js
CHANGED
|
@@ -27,7 +27,7 @@ var ClientError = class extends Error {
|
|
|
27
27
|
// ../../build/client/esm/http/http-client.js
|
|
28
28
|
import { lastValueFrom as lastValueFrom2, Observable as Observable2 } from "rxjs";
|
|
29
29
|
import { isReadableStreamLike } from "rxjs/internal/util/isReadableStreamLike";
|
|
30
|
-
import { DocumentFactory, HttpHeaderCodes,
|
|
30
|
+
import { DocumentFactory, HttpHeaderCodes, HttpParams, isBlob, joinPath } from "@opra/common";
|
|
31
31
|
|
|
32
32
|
// ../../build/client/esm/constants.js
|
|
33
33
|
var JSON_CONTENT_TYPE_PATTERN = /^application\/([\w-]+\+)?\bjson\b/i;
|
|
@@ -40,7 +40,7 @@ import { lastValueFrom, Observable } from "rxjs";
|
|
|
40
40
|
import { uid } from "@opra/common";
|
|
41
41
|
|
|
42
42
|
// ../../build/client/esm/http/http-request.js
|
|
43
|
-
import {
|
|
43
|
+
import { OpraURL } from "@opra/common";
|
|
44
44
|
var directCopyProperties = [
|
|
45
45
|
"cache",
|
|
46
46
|
"credentials",
|
|
@@ -61,7 +61,7 @@ var HttpRequest = class _HttpRequest {
|
|
|
61
61
|
this.cache = init?.cache || "default";
|
|
62
62
|
this.credentials = init?.credentials || "same-origin";
|
|
63
63
|
this.destination = init?.destination || "";
|
|
64
|
-
this.headers = new
|
|
64
|
+
this.headers = init?.headers instanceof Headers ? init.headers : new Headers(init?.headers);
|
|
65
65
|
this.integrity = init?.integrity || "";
|
|
66
66
|
this.keepalive = init?.keepalive ?? false;
|
|
67
67
|
this.method = (init?.method || "GET").toUpperCase();
|
|
@@ -105,7 +105,7 @@ var HttpRequest = class _HttpRequest {
|
|
|
105
105
|
this[k] = update[k];
|
|
106
106
|
});
|
|
107
107
|
if (update.headers) {
|
|
108
|
-
const h = update.headers instanceof
|
|
108
|
+
const h = update.headers instanceof Headers ? update.headers : new Headers(update.headers);
|
|
109
109
|
h.forEach((v, k) => {
|
|
110
110
|
if (k.toLowerCase() === "set-cookie") {
|
|
111
111
|
this.headers.append(k, v);
|
|
@@ -120,7 +120,7 @@ var HttpRequest = class _HttpRequest {
|
|
|
120
120
|
this[k] = src[k];
|
|
121
121
|
});
|
|
122
122
|
if (src.headers) {
|
|
123
|
-
const h = src.headers instanceof
|
|
123
|
+
const h = src.headers instanceof Headers ? src.headers : new Headers(src.headers);
|
|
124
124
|
h.forEach((v, k) => {
|
|
125
125
|
if (k.toLowerCase() === "set-cookie") {
|
|
126
126
|
this.headers.append(k, v);
|
|
@@ -146,7 +146,11 @@ var HttpRequestObservable = class extends Observable {
|
|
|
146
146
|
this.contentId = uid(6);
|
|
147
147
|
}
|
|
148
148
|
header(name, value) {
|
|
149
|
-
this[kRequest].headers
|
|
149
|
+
const headers = this[kRequest].headers;
|
|
150
|
+
if (Array.isArray(value))
|
|
151
|
+
value.forEach((v) => headers.append(name, String(v)));
|
|
152
|
+
else
|
|
153
|
+
headers.append(name, value);
|
|
150
154
|
return this;
|
|
151
155
|
}
|
|
152
156
|
param(name, value) {
|
|
@@ -274,14 +278,13 @@ var HttpCollectionNode = class {
|
|
|
274
278
|
};
|
|
275
279
|
|
|
276
280
|
// ../../build/client/esm/http/http-response.js
|
|
277
|
-
import { HttpHeaders as HttpHeaders2 } from "@opra/common";
|
|
278
281
|
var HttpResponse = class _HttpResponse {
|
|
279
282
|
static {
|
|
280
283
|
__name(this, "HttpResponse");
|
|
281
284
|
}
|
|
282
285
|
constructor(init) {
|
|
283
286
|
this.hasBody = false;
|
|
284
|
-
this.headers = new
|
|
287
|
+
this.headers = init?.headers instanceof Headers ? init?.headers : new Headers(init?.headers);
|
|
285
288
|
this.status = init?.status || 200;
|
|
286
289
|
this.statusText = init?.statusText || "OK";
|
|
287
290
|
this.url = init?.url || null;
|
|
@@ -375,7 +378,7 @@ var OpraHttpClient = class {
|
|
|
375
378
|
});
|
|
376
379
|
this.defaults = {
|
|
377
380
|
...options?.defaults,
|
|
378
|
-
headers: options?.defaults?.headers instanceof
|
|
381
|
+
headers: options?.defaults?.headers instanceof Headers ? options?.defaults?.headers : new Headers(options?.defaults?.headers),
|
|
379
382
|
params: options?.defaults?.params instanceof HttpParams ? options?.defaults?.params : new HttpParams(options?.defaults?.params)
|
|
380
383
|
};
|
|
381
384
|
}
|
|
@@ -392,7 +395,7 @@ var OpraHttpClient = class {
|
|
|
392
395
|
this[kAssets].metadataPromise = promise = lastValueFrom2(this._sendRequest("body", new HttpRequest({
|
|
393
396
|
method: "GET",
|
|
394
397
|
url: "$metadata",
|
|
395
|
-
headers: new
|
|
398
|
+
headers: new Headers({ "accept": "application/json" })
|
|
396
399
|
})));
|
|
397
400
|
return await promise.then(async (body) => {
|
|
398
401
|
const api = await DocumentFactory.createDocument(body);
|
|
@@ -463,12 +466,12 @@ var OpraHttpClient = class {
|
|
|
463
466
|
} else if (Buffer.isBuffer(request.body)) {
|
|
464
467
|
contentType = "application/octet-stream";
|
|
465
468
|
body = request.body;
|
|
466
|
-
request.headers.set("Content-Size", request.body.length);
|
|
469
|
+
request.headers.set("Content-Size", String(request.body.length));
|
|
467
470
|
delete request.duplex;
|
|
468
471
|
} else if (isBlob(request.body)) {
|
|
469
472
|
contentType = request.body.type || "application/octet-stream";
|
|
470
473
|
body = request.body;
|
|
471
|
-
request.headers.set("Content-Size", request.body.length);
|
|
474
|
+
request.headers.set("Content-Size", String(request.body.length));
|
|
472
475
|
delete request.duplex;
|
|
473
476
|
} else {
|
|
474
477
|
contentType = "application/json";
|
|
@@ -491,7 +494,7 @@ var OpraHttpClient = class {
|
|
|
491
494
|
}
|
|
492
495
|
if (observe === "events")
|
|
493
496
|
subscriber.next({ event: "sent", request });
|
|
494
|
-
const response = await this._fetch(url,
|
|
497
|
+
const response = await this._fetch(url, request);
|
|
495
498
|
await this._handleResponse(observe, subscriber, request, response);
|
|
496
499
|
})().catch((error) => subscriber.error(error));
|
|
497
500
|
});
|
|
@@ -503,7 +506,7 @@ var OpraHttpClient = class {
|
|
|
503
506
|
return new HttpResponse(init);
|
|
504
507
|
}
|
|
505
508
|
async _handleResponse(observe, subscriber, request, fetchResponse, ctx) {
|
|
506
|
-
const headers =
|
|
509
|
+
const headers = fetchResponse.headers;
|
|
507
510
|
if (observe === "events") {
|
|
508
511
|
const response2 = this._createResponse({
|
|
509
512
|
url: fetchResponse.url,
|
|
@@ -516,13 +519,13 @@ var OpraHttpClient = class {
|
|
|
516
519
|
}
|
|
517
520
|
let body;
|
|
518
521
|
if (fetchResponse.body) {
|
|
519
|
-
if (JSON_CONTENT_TYPE_PATTERN.test(
|
|
522
|
+
if (JSON_CONTENT_TYPE_PATTERN.test(headers.get("Content-Type") || "")) {
|
|
520
523
|
body = await fetchResponse.json();
|
|
521
524
|
if (typeof body === "string")
|
|
522
525
|
body = JSON.parse(body);
|
|
523
|
-
} else if (TEXT_CONTENT_TYPE_PATTERN.test(
|
|
526
|
+
} else if (TEXT_CONTENT_TYPE_PATTERN.test(headers.get("Content-Type") || ""))
|
|
524
527
|
body = await fetchResponse.text();
|
|
525
|
-
else if (FORMDATA_CONTENT_TYPE_PATTERN.test(
|
|
528
|
+
else if (FORMDATA_CONTENT_TYPE_PATTERN.test(headers.get("Content-Type") || ""))
|
|
526
529
|
body = await fetchResponse.formData();
|
|
527
530
|
else {
|
|
528
531
|
const buf = await fetchResponse.arrayBuffer();
|
package/cjs/http/http-client.js
CHANGED
|
@@ -24,8 +24,8 @@ class OpraHttpClient {
|
|
|
24
24
|
});
|
|
25
25
|
this.defaults = {
|
|
26
26
|
...options?.defaults,
|
|
27
|
-
headers: options?.defaults?.headers instanceof
|
|
28
|
-
? options?.defaults?.headers : new
|
|
27
|
+
headers: options?.defaults?.headers instanceof Headers
|
|
28
|
+
? options?.defaults?.headers : new Headers(options?.defaults?.headers),
|
|
29
29
|
params: options?.defaults?.params instanceof common_1.HttpParams
|
|
30
30
|
? options?.defaults?.params : new common_1.HttpParams(options?.defaults?.params)
|
|
31
31
|
};
|
|
@@ -43,7 +43,7 @@ class OpraHttpClient {
|
|
|
43
43
|
this[kAssets].metadataPromise = promise = (0, rxjs_1.lastValueFrom)(this._sendRequest('body', new http_request_js_1.HttpRequest({
|
|
44
44
|
method: 'GET',
|
|
45
45
|
url: '$metadata',
|
|
46
|
-
headers: new
|
|
46
|
+
headers: new Headers({ 'accept': 'application/json' })
|
|
47
47
|
})));
|
|
48
48
|
return await promise
|
|
49
49
|
.then(async (body) => {
|
|
@@ -121,13 +121,13 @@ class OpraHttpClient {
|
|
|
121
121
|
else if (Buffer.isBuffer(request.body)) {
|
|
122
122
|
contentType = 'application/octet-stream';
|
|
123
123
|
body = request.body;
|
|
124
|
-
request.headers.set('Content-Size', request.body.length);
|
|
124
|
+
request.headers.set('Content-Size', String(request.body.length));
|
|
125
125
|
delete request.duplex;
|
|
126
126
|
}
|
|
127
127
|
else if ((0, common_1.isBlob)(request.body)) {
|
|
128
128
|
contentType = request.body.type || 'application/octet-stream';
|
|
129
129
|
body = request.body;
|
|
130
|
-
request.headers.set('Content-Size', request.body.length);
|
|
130
|
+
request.headers.set('Content-Size', String(request.body.length));
|
|
131
131
|
delete request.duplex;
|
|
132
132
|
}
|
|
133
133
|
else {
|
|
@@ -151,7 +151,7 @@ class OpraHttpClient {
|
|
|
151
151
|
}
|
|
152
152
|
if (observe === 'events')
|
|
153
153
|
subscriber.next({ event: 'sent', request });
|
|
154
|
-
const response = await this._fetch(url,
|
|
154
|
+
const response = await this._fetch(url, request);
|
|
155
155
|
await this._handleResponse(observe, subscriber, request, response);
|
|
156
156
|
})().catch(error => subscriber.error(error));
|
|
157
157
|
});
|
|
@@ -163,7 +163,7 @@ class OpraHttpClient {
|
|
|
163
163
|
return new http_response_js_1.HttpResponse(init);
|
|
164
164
|
}
|
|
165
165
|
async _handleResponse(observe, subscriber, request, fetchResponse, ctx) {
|
|
166
|
-
const headers =
|
|
166
|
+
const headers = fetchResponse.headers;
|
|
167
167
|
if (observe === 'events') {
|
|
168
168
|
const response = this._createResponse({
|
|
169
169
|
url: fetchResponse.url,
|
|
@@ -176,14 +176,14 @@ class OpraHttpClient {
|
|
|
176
176
|
}
|
|
177
177
|
let body;
|
|
178
178
|
if (fetchResponse.body) {
|
|
179
|
-
if (constants_js_1.JSON_CONTENT_TYPE_PATTERN.test(
|
|
179
|
+
if (constants_js_1.JSON_CONTENT_TYPE_PATTERN.test(headers.get('Content-Type') || '')) {
|
|
180
180
|
body = await fetchResponse.json();
|
|
181
181
|
if (typeof body === 'string')
|
|
182
182
|
body = JSON.parse(body);
|
|
183
183
|
}
|
|
184
|
-
else if (constants_js_1.TEXT_CONTENT_TYPE_PATTERN.test(
|
|
184
|
+
else if (constants_js_1.TEXT_CONTENT_TYPE_PATTERN.test(headers.get('Content-Type') || ''))
|
|
185
185
|
body = await fetchResponse.text();
|
|
186
|
-
else if (constants_js_1.FORMDATA_CONTENT_TYPE_PATTERN.test(
|
|
186
|
+
else if (constants_js_1.FORMDATA_CONTENT_TYPE_PATTERN.test(headers.get('Content-Type') || ''))
|
|
187
187
|
body = await fetchResponse.formData();
|
|
188
188
|
else {
|
|
189
189
|
const buf = await fetchResponse.arrayBuffer();
|
|
@@ -16,7 +16,11 @@ class HttpRequestObservable extends rxjs_1.Observable {
|
|
|
16
16
|
this.contentId = (0, common_1.uid)(6);
|
|
17
17
|
}
|
|
18
18
|
header(name, value) {
|
|
19
|
-
this[kRequest].headers
|
|
19
|
+
const headers = this[kRequest].headers;
|
|
20
|
+
if (Array.isArray(value))
|
|
21
|
+
value.forEach(v => headers.append(name, String(v)));
|
|
22
|
+
else
|
|
23
|
+
headers.append(name, value);
|
|
20
24
|
return this;
|
|
21
25
|
}
|
|
22
26
|
param(name, value) {
|
package/cjs/http/http-request.js
CHANGED
|
@@ -10,7 +10,7 @@ class HttpRequest {
|
|
|
10
10
|
this.cache = init?.cache || 'default';
|
|
11
11
|
this.credentials = init?.credentials || 'same-origin';
|
|
12
12
|
this.destination = init?.destination || '';
|
|
13
|
-
this.headers = new
|
|
13
|
+
this.headers = init?.headers instanceof Headers ? init.headers : new Headers(init?.headers);
|
|
14
14
|
this.integrity = init?.integrity || '';
|
|
15
15
|
this.keepalive = init?.keepalive ?? false;
|
|
16
16
|
this.method = (init?.method || 'GET').toUpperCase();
|
|
@@ -54,9 +54,9 @@ class HttpRequest {
|
|
|
54
54
|
this[k] = update[k];
|
|
55
55
|
});
|
|
56
56
|
if (update.headers) {
|
|
57
|
-
const h = update.headers instanceof
|
|
57
|
+
const h = update.headers instanceof Headers
|
|
58
58
|
? update.headers
|
|
59
|
-
: new
|
|
59
|
+
: new Headers(update.headers);
|
|
60
60
|
h.forEach((v, k) => {
|
|
61
61
|
if (k.toLowerCase() === 'set-cookie') {
|
|
62
62
|
this.headers.append(k, v);
|
|
@@ -72,9 +72,9 @@ class HttpRequest {
|
|
|
72
72
|
this[k] = src[k];
|
|
73
73
|
});
|
|
74
74
|
if (src.headers) {
|
|
75
|
-
const h = src.headers instanceof
|
|
75
|
+
const h = src.headers instanceof Headers
|
|
76
76
|
? src.headers
|
|
77
|
-
: new
|
|
77
|
+
: new Headers(src.headers);
|
|
78
78
|
h.forEach((v, k) => {
|
|
79
79
|
if (k.toLowerCase() === 'set-cookie') {
|
|
80
80
|
this.headers.append(k, v);
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HttpResponse = void 0;
|
|
4
|
-
const common_1 = require("@opra/common");
|
|
5
4
|
class HttpResponse {
|
|
6
5
|
constructor(init) {
|
|
7
6
|
/**
|
|
8
7
|
* Returns true if response has body to be received
|
|
9
8
|
*/
|
|
10
9
|
this.hasBody = false;
|
|
11
|
-
this.headers =
|
|
10
|
+
this.headers = init?.headers instanceof Headers ? init?.headers
|
|
11
|
+
: new Headers(init?.headers);
|
|
12
12
|
this.status = init?.status || 200;
|
|
13
13
|
this.statusText = init?.statusText || 'OK';
|
|
14
14
|
this.url = init?.url || null;
|
package/esm/http/http-client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { lastValueFrom, Observable } from 'rxjs';
|
|
2
2
|
import { isReadableStreamLike } from 'rxjs/internal/util/isReadableStreamLike';
|
|
3
|
-
import { DocumentFactory, HttpHeaderCodes,
|
|
3
|
+
import { DocumentFactory, HttpHeaderCodes, HttpParams, isBlob, joinPath, } from '@opra/common';
|
|
4
4
|
import { ClientError } from '../client-error.js';
|
|
5
5
|
import { FORMDATA_CONTENT_TYPE_PATTERN, JSON_CONTENT_TYPE_PATTERN, TEXT_CONTENT_TYPE_PATTERN } from '../constants.js';
|
|
6
6
|
import { HttpCollectionNode } from './http-collection-node.js';
|
|
@@ -21,8 +21,8 @@ export class OpraHttpClient {
|
|
|
21
21
|
});
|
|
22
22
|
this.defaults = {
|
|
23
23
|
...options?.defaults,
|
|
24
|
-
headers: options?.defaults?.headers instanceof
|
|
25
|
-
? options?.defaults?.headers : new
|
|
24
|
+
headers: options?.defaults?.headers instanceof Headers
|
|
25
|
+
? options?.defaults?.headers : new Headers(options?.defaults?.headers),
|
|
26
26
|
params: options?.defaults?.params instanceof HttpParams
|
|
27
27
|
? options?.defaults?.params : new HttpParams(options?.defaults?.params)
|
|
28
28
|
};
|
|
@@ -40,7 +40,7 @@ export class OpraHttpClient {
|
|
|
40
40
|
this[kAssets].metadataPromise = promise = lastValueFrom(this._sendRequest('body', new HttpRequest({
|
|
41
41
|
method: 'GET',
|
|
42
42
|
url: '$metadata',
|
|
43
|
-
headers: new
|
|
43
|
+
headers: new Headers({ 'accept': 'application/json' })
|
|
44
44
|
})));
|
|
45
45
|
return await promise
|
|
46
46
|
.then(async (body) => {
|
|
@@ -118,13 +118,13 @@ export class OpraHttpClient {
|
|
|
118
118
|
else if (Buffer.isBuffer(request.body)) {
|
|
119
119
|
contentType = 'application/octet-stream';
|
|
120
120
|
body = request.body;
|
|
121
|
-
request.headers.set('Content-Size', request.body.length);
|
|
121
|
+
request.headers.set('Content-Size', String(request.body.length));
|
|
122
122
|
delete request.duplex;
|
|
123
123
|
}
|
|
124
124
|
else if (isBlob(request.body)) {
|
|
125
125
|
contentType = request.body.type || 'application/octet-stream';
|
|
126
126
|
body = request.body;
|
|
127
|
-
request.headers.set('Content-Size', request.body.length);
|
|
127
|
+
request.headers.set('Content-Size', String(request.body.length));
|
|
128
128
|
delete request.duplex;
|
|
129
129
|
}
|
|
130
130
|
else {
|
|
@@ -148,7 +148,7 @@ export class OpraHttpClient {
|
|
|
148
148
|
}
|
|
149
149
|
if (observe === 'events')
|
|
150
150
|
subscriber.next({ event: 'sent', request });
|
|
151
|
-
const response = await this._fetch(url,
|
|
151
|
+
const response = await this._fetch(url, request);
|
|
152
152
|
await this._handleResponse(observe, subscriber, request, response);
|
|
153
153
|
})().catch(error => subscriber.error(error));
|
|
154
154
|
});
|
|
@@ -160,7 +160,7 @@ export class OpraHttpClient {
|
|
|
160
160
|
return new HttpResponse(init);
|
|
161
161
|
}
|
|
162
162
|
async _handleResponse(observe, subscriber, request, fetchResponse, ctx) {
|
|
163
|
-
const headers =
|
|
163
|
+
const headers = fetchResponse.headers;
|
|
164
164
|
if (observe === 'events') {
|
|
165
165
|
const response = this._createResponse({
|
|
166
166
|
url: fetchResponse.url,
|
|
@@ -173,14 +173,14 @@ export class OpraHttpClient {
|
|
|
173
173
|
}
|
|
174
174
|
let body;
|
|
175
175
|
if (fetchResponse.body) {
|
|
176
|
-
if (JSON_CONTENT_TYPE_PATTERN.test(
|
|
176
|
+
if (JSON_CONTENT_TYPE_PATTERN.test(headers.get('Content-Type') || '')) {
|
|
177
177
|
body = await fetchResponse.json();
|
|
178
178
|
if (typeof body === 'string')
|
|
179
179
|
body = JSON.parse(body);
|
|
180
180
|
}
|
|
181
|
-
else if (TEXT_CONTENT_TYPE_PATTERN.test(
|
|
181
|
+
else if (TEXT_CONTENT_TYPE_PATTERN.test(headers.get('Content-Type') || ''))
|
|
182
182
|
body = await fetchResponse.text();
|
|
183
|
-
else if (FORMDATA_CONTENT_TYPE_PATTERN.test(
|
|
183
|
+
else if (FORMDATA_CONTENT_TYPE_PATTERN.test(headers.get('Content-Type') || ''))
|
|
184
184
|
body = await fetchResponse.formData();
|
|
185
185
|
else {
|
|
186
186
|
const buf = await fetchResponse.arrayBuffer();
|
|
@@ -13,7 +13,11 @@ export class HttpRequestObservable extends Observable {
|
|
|
13
13
|
this.contentId = uid(6);
|
|
14
14
|
}
|
|
15
15
|
header(name, value) {
|
|
16
|
-
this[kRequest].headers
|
|
16
|
+
const headers = this[kRequest].headers;
|
|
17
|
+
if (Array.isArray(value))
|
|
18
|
+
value.forEach(v => headers.append(name, String(v)));
|
|
19
|
+
else
|
|
20
|
+
headers.append(name, value);
|
|
17
21
|
return this;
|
|
18
22
|
}
|
|
19
23
|
param(name, value) {
|
package/esm/http/http-request.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference lib="dom" />
|
|
2
|
-
import {
|
|
2
|
+
import { OpraURL } from '@opra/common';
|
|
3
3
|
const directCopyProperties = ['cache', 'credentials', 'destination', 'headers', 'integrity',
|
|
4
4
|
'keepalive', 'mode', 'redirect', 'referrer', 'referrerPolicy'];
|
|
5
5
|
export class HttpRequest {
|
|
@@ -7,7 +7,7 @@ export class HttpRequest {
|
|
|
7
7
|
this.cache = init?.cache || 'default';
|
|
8
8
|
this.credentials = init?.credentials || 'same-origin';
|
|
9
9
|
this.destination = init?.destination || '';
|
|
10
|
-
this.headers = new
|
|
10
|
+
this.headers = init?.headers instanceof Headers ? init.headers : new Headers(init?.headers);
|
|
11
11
|
this.integrity = init?.integrity || '';
|
|
12
12
|
this.keepalive = init?.keepalive ?? false;
|
|
13
13
|
this.method = (init?.method || 'GET').toUpperCase();
|
|
@@ -51,9 +51,9 @@ export class HttpRequest {
|
|
|
51
51
|
this[k] = update[k];
|
|
52
52
|
});
|
|
53
53
|
if (update.headers) {
|
|
54
|
-
const h = update.headers instanceof
|
|
54
|
+
const h = update.headers instanceof Headers
|
|
55
55
|
? update.headers
|
|
56
|
-
: new
|
|
56
|
+
: new Headers(update.headers);
|
|
57
57
|
h.forEach((v, k) => {
|
|
58
58
|
if (k.toLowerCase() === 'set-cookie') {
|
|
59
59
|
this.headers.append(k, v);
|
|
@@ -69,9 +69,9 @@ export class HttpRequest {
|
|
|
69
69
|
this[k] = src[k];
|
|
70
70
|
});
|
|
71
71
|
if (src.headers) {
|
|
72
|
-
const h = src.headers instanceof
|
|
72
|
+
const h = src.headers instanceof Headers
|
|
73
73
|
? src.headers
|
|
74
|
-
: new
|
|
74
|
+
: new Headers(src.headers);
|
|
75
75
|
h.forEach((v, k) => {
|
|
76
76
|
if (k.toLowerCase() === 'set-cookie') {
|
|
77
77
|
this.headers.append(k, v);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { HttpHeaders } from '@opra/common';
|
|
2
1
|
export class HttpResponse {
|
|
3
2
|
constructor(init) {
|
|
4
3
|
/**
|
|
5
4
|
* Returns true if response has body to be received
|
|
6
5
|
*/
|
|
7
6
|
this.hasBody = false;
|
|
8
|
-
this.headers =
|
|
7
|
+
this.headers = init?.headers instanceof Headers ? init?.headers
|
|
8
|
+
: new Headers(init?.headers);
|
|
9
9
|
this.status = init?.status || 200;
|
|
10
10
|
this.statusText = init?.statusText || 'OK';
|
|
11
11
|
this.url = init?.url || null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Opra Client package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@browsery/i18next": "^0.6.0",
|
|
47
47
|
"@browsery/stream": "^0.5.0",
|
|
48
48
|
"@browsery/util": "^0.4.0",
|
|
49
|
-
"@opra/common": "^0.
|
|
49
|
+
"@opra/common": "^0.21.0",
|
|
50
50
|
"accepts": "^1.3.8",
|
|
51
51
|
"buffer": "^6.0.3",
|
|
52
52
|
"cookie": "^0.5.0",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Observable, Subscriber } from 'rxjs';
|
|
2
2
|
import { StrictOmit, Type } from 'ts-gems';
|
|
3
|
-
import { ApiDocument,
|
|
3
|
+
import { ApiDocument, HttpParams } from '@opra/common';
|
|
4
4
|
import { HttpCollectionNode } from './http-collection-node.js';
|
|
5
5
|
import { HttpRequest } from './http-request.js';
|
|
6
6
|
import { HttpResponse } from './http-response.js';
|
|
@@ -29,7 +29,7 @@ export declare class OpraHttpClient {
|
|
|
29
29
|
responseInterceptors: ResponseInterceptor[];
|
|
30
30
|
};
|
|
31
31
|
defaults: StrictOmit<HttpRequestDefaults, 'headers' | 'params'> & {
|
|
32
|
-
headers:
|
|
32
|
+
headers: Headers;
|
|
33
33
|
params: HttpParams;
|
|
34
34
|
};
|
|
35
35
|
constructor(serviceUrl: string, options?: OpraHttpClientOptions);
|
|
@@ -47,7 +47,7 @@ export declare namespace HttpCollectionNode {
|
|
|
47
47
|
affected: number;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
export declare class HttpCollectionNode<TType, TResponseExt =
|
|
50
|
+
export declare class HttpCollectionNode<TType, TResponseExt = {}> {
|
|
51
51
|
protected [kHttpClientContext]: HttpClientContext;
|
|
52
52
|
constructor(context: HttpClientContext);
|
|
53
53
|
create(data: PartialInput<TType>, options?: StrictOmit<HttpCollectionNode.CreateOptions, 'observe'> & {
|
|
@@ -86,6 +86,7 @@ export declare class HttpCollectionNode<TType, TResponseExt = any> {
|
|
|
86
86
|
get(id: any, options?: StrictOmit<HttpCollectionNode.GetOptions, 'observe'> & {
|
|
87
87
|
observe: 'events';
|
|
88
88
|
}): HttpRequestObservable<HttpEvent, TType, TResponseExt>;
|
|
89
|
+
findMany(options?: StrictOmit<HttpCollectionNode.FindManyOptions, 'observe'>): HttpRequestObservable<TType[], TType, TResponseExt>;
|
|
89
90
|
findMany(options?: StrictOmit<HttpCollectionNode.FindManyOptions, 'observe'> & {
|
|
90
91
|
observe?: 'body';
|
|
91
92
|
}): HttpRequestObservable<TType[], TType, TResponseExt>;
|
|
@@ -11,7 +11,7 @@ export declare namespace HttpRequestObservable {
|
|
|
11
11
|
http?: HttpRequestDefaults;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
export declare class HttpRequestObservable<T, TBody, TResponseExt =
|
|
14
|
+
export declare class HttpRequestObservable<T, TBody, TResponseExt = {}> extends Observable<T> {
|
|
15
15
|
static kContext: symbol;
|
|
16
16
|
static kRequest: symbol;
|
|
17
17
|
readonly contentId: string;
|
|
@@ -22,7 +22,7 @@ export declare class HttpRequestObservable<T, TBody, TResponseExt = never, TResp
|
|
|
22
22
|
param(name: string, value: any): this;
|
|
23
23
|
fetch(): Promise<TBody>;
|
|
24
24
|
fetch(observe: 'body'): Promise<TBody>;
|
|
25
|
-
fetch(observe: 'response'): Promise<
|
|
25
|
+
fetch(observe: 'response'): Promise<HttpResponse<TBody> & TResponseExt>;
|
|
26
26
|
with(cb: (_this: this) => void): this;
|
|
27
27
|
}
|
|
28
28
|
export {};
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
/// <reference lib="dom" />
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
import { HttpParams, OpraURL, OpraURLPath } from '@opra/common';
|
|
3
|
+
export declare namespace HttpRequest {
|
|
4
|
+
interface Initiator {
|
|
5
|
+
cache?: RequestCache;
|
|
6
|
+
credentials?: RequestCredentials;
|
|
7
|
+
destination?: RequestDestination;
|
|
8
|
+
headers?: HeadersInit;
|
|
9
|
+
integrity?: string;
|
|
10
|
+
keepalive?: boolean;
|
|
11
|
+
method?: string;
|
|
12
|
+
mode?: RequestMode;
|
|
13
|
+
params?: HttpParams.Initiator;
|
|
14
|
+
redirect?: RequestRedirect;
|
|
15
|
+
referrer?: string;
|
|
16
|
+
referrerPolicy?: ReferrerPolicy;
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
url?: string;
|
|
19
|
+
body?: any;
|
|
20
|
+
}
|
|
19
21
|
}
|
|
20
22
|
export declare class HttpRequest {
|
|
21
23
|
/** Returns the cache mode associated with request, which is a string indicating
|
|
@@ -30,7 +32,7 @@ export declare class HttpRequest {
|
|
|
30
32
|
/** Returns a Headers object consisting of the headers associated with request.
|
|
31
33
|
* Note that headers added in the network layer by the user agent will not be accounted for in this object,
|
|
32
34
|
* e.g., the "Host" header. */
|
|
33
|
-
headers:
|
|
35
|
+
headers: Headers;
|
|
34
36
|
/** Returns request's subresource integrity metadata, which is a cryptographic
|
|
35
37
|
* hash of the resource being fetched.
|
|
36
38
|
* Its value consists of multiple hashes separated by whitespace. [SRI] */
|
|
@@ -60,7 +62,7 @@ export declare class HttpRequest {
|
|
|
60
62
|
/** Body of the http request */
|
|
61
63
|
body?: any;
|
|
62
64
|
duplex?: 'half';
|
|
63
|
-
constructor(init?:
|
|
65
|
+
constructor(init?: HttpRequest.Initiator);
|
|
64
66
|
/** Returns the URL of request as a string. */
|
|
65
67
|
get url(): string;
|
|
66
68
|
set url(value: string);
|
|
@@ -68,7 +70,7 @@ export declare class HttpRequest {
|
|
|
68
70
|
get params(): HttpParams;
|
|
69
71
|
/** Returns the path part of URL as OpraURLPath */
|
|
70
72
|
get path(): OpraURLPath;
|
|
71
|
-
clone(...update: (HttpRequest |
|
|
72
|
-
merge(update: HttpRequest |
|
|
73
|
-
inset(src: HttpRequest |
|
|
73
|
+
clone(...update: (HttpRequest | HttpRequest.Initiator)[]): HttpRequest;
|
|
74
|
+
merge(update: HttpRequest | HttpRequest.Initiator): void;
|
|
75
|
+
inset(src: HttpRequest | HttpRequest.Initiator): void;
|
|
74
76
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { HttpHeaders } from '@opra/common';
|
|
2
1
|
export declare namespace HttpResponse {
|
|
3
2
|
interface Initiator {
|
|
4
|
-
headers?:
|
|
3
|
+
headers?: HeadersInit;
|
|
5
4
|
status?: number;
|
|
6
5
|
statusText?: string;
|
|
7
6
|
url?: string;
|
|
@@ -14,7 +13,7 @@ export declare class HttpResponse<TBody = any> {
|
|
|
14
13
|
/**
|
|
15
14
|
* Contains the Headers object associated with the response.
|
|
16
15
|
*/
|
|
17
|
-
readonly headers:
|
|
16
|
+
readonly headers: Headers;
|
|
18
17
|
/**
|
|
19
18
|
* Contains a Boolean stating whether the response was successful (status in the range 200-299) or not.
|
|
20
19
|
*/
|
|
@@ -23,7 +23,7 @@ export declare namespace HttpSingletonNode {
|
|
|
23
23
|
include?: string[];
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
export declare class HttpSingletonNode<TType, TResponseExt =
|
|
26
|
+
export declare class HttpSingletonNode<TType, TResponseExt = {}> {
|
|
27
27
|
protected [kHttpClientContext]: HttpClientContext;
|
|
28
28
|
constructor(context: HttpClientContext);
|
|
29
29
|
create(data: PartialInput<TType>, options?: StrictOmit<HttpSingletonNode.CreateOptions, 'observe'> & {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Observable } from 'rxjs';
|
|
2
|
-
import type {
|
|
2
|
+
import type { HttpParams } from '@opra/common';
|
|
3
3
|
import type { OpraHttpClient } from './http-client.js';
|
|
4
4
|
import type { HttpRequest } from './http-request.js';
|
|
5
5
|
import type { HttpResponse } from './http-response.js';
|
|
@@ -16,7 +16,7 @@ export interface HttpClientContext {
|
|
|
16
16
|
responseInterceptors?: ResponseInterceptor[];
|
|
17
17
|
}
|
|
18
18
|
export type HttpRequestDefaults = Partial<Pick<HttpRequest, 'cache' | 'credentials' | 'destination' | 'integrity' | 'keepalive' | 'mode' | 'redirect' | 'referrer' | 'referrerPolicy'>> & {
|
|
19
|
-
headers?:
|
|
19
|
+
headers?: HeadersInit;
|
|
20
20
|
params?: HttpParams.Initiator;
|
|
21
21
|
};
|
|
22
22
|
export interface HttpEvent {
|