@opra/client 0.27.2 → 0.28.1
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 +400 -303
- package/cjs/constants.js +2 -1
- package/cjs/core/backend.js +9 -0
- package/cjs/core/client-base.js +18 -0
- package/cjs/http/fetch-backend.js +210 -0
- package/cjs/http/http-backend.js +15 -0
- package/cjs/http/http-client-base.js +64 -0
- package/cjs/http/http-client.js +19 -0
- package/cjs/{impl/collection-node.js → http/http-collection-node.js} +9 -9
- package/cjs/http/http-fetch-client.js +19 -0
- package/cjs/http/http-interceptor-handler.js +18 -0
- package/cjs/http/http-request-observable.js +135 -0
- package/cjs/{impl → http}/http-response.js +1 -0
- package/cjs/{impl → http}/http-service-base.js +1 -1
- package/cjs/{impl/singleton-node.js → http/http-singleton-node.js} +6 -6
- package/cjs/{interfaces/http-event.interface.js → http/interfaces/http-event.js} +9 -10
- package/cjs/index.js +19 -12
- package/cjs/types.js +1 -0
- package/esm/constants.js +1 -0
- package/esm/core/backend.js +5 -0
- package/esm/core/client-base.js +14 -0
- package/esm/http/fetch-backend.js +205 -0
- package/esm/http/http-backend.js +11 -0
- package/esm/http/http-client-base.js +60 -0
- package/esm/http/http-client.js +15 -0
- package/esm/{impl/collection-node.js → http/http-collection-node.js} +9 -9
- package/esm/http/http-fetch-client.js +15 -0
- package/esm/http/http-interceptor-handler.js +14 -0
- package/esm/http/http-request-observable.js +130 -0
- package/esm/{impl → http}/http-response.js +1 -0
- package/esm/{impl → http}/http-service-base.js +1 -1
- package/esm/{impl/singleton-node.js → http/http-singleton-node.js} +6 -6
- package/esm/{interfaces/http-event.interface.js → http/interfaces/http-event.js} +9 -10
- package/esm/index.js +17 -11
- package/esm/types.js +1 -0
- package/package.json +3 -3
- package/types/constants.d.ts +1 -0
- package/types/core/backend.d.ts +18 -0
- package/types/core/client-base.d.ts +21 -0
- package/types/http/fetch-backend.d.ts +42 -0
- package/types/http/http-backend.d.ts +27 -0
- package/types/http/http-client-base.d.ts +31 -0
- package/types/http/http-client.d.ts +12 -0
- package/types/{impl/collection-node.d.ts → http/http-collection-node.d.ts} +11 -11
- package/types/http/http-fetch-client.d.ts +12 -0
- package/types/http/http-interceptor-handler.d.ts +11 -0
- package/types/http/http-request-observable.d.ts +35 -0
- package/types/{impl → http}/http-response.d.ts +0 -1
- package/types/{impl → http}/http-service-base.d.ts +1 -1
- package/types/{impl/singleton-node.d.ts → http/http-singleton-node.d.ts} +8 -8
- package/types/http/interfaces/http-event.d.ts +108 -0
- package/types/http/interfaces/http-handler.d.ts +7 -0
- package/types/http/interfaces/http-interceptor.d.ts +8 -0
- package/types/index.d.ts +17 -11
- package/types/types.d.ts +0 -4
- package/cjs/client.js +0 -83
- package/cjs/enums/index.js +0 -4
- package/cjs/impl/http-request-observable.js +0 -257
- package/cjs/impl/http-request.js +0 -27
- package/cjs/interfaces/index.js +0 -5
- package/esm/client.js +0 -79
- package/esm/enums/index.js +0 -1
- package/esm/impl/http-request-observable.js +0 -252
- package/esm/impl/http-request.js +0 -23
- package/esm/interfaces/index.js +0 -2
- package/types/client.d.ts +0 -33
- package/types/enums/index.d.ts +0 -1
- package/types/impl/http-request-observable.d.ts +0 -47
- package/types/impl/http-request.d.ts +0 -71
- package/types/interfaces/client-context.interface.d.ts +0 -13
- package/types/interfaces/http-event.interface.d.ts +0 -88
- package/types/interfaces/http-request-defaults.interface.d.ts +0 -6
- package/types/interfaces/index.d.ts +0 -2
- /package/cjs/{client-error.js → core/client-error.js} +0 -0
- /package/cjs/{enums → http/enums}/http-observable-type.enum.js +0 -0
- /package/cjs/{interfaces/client-context.interface.js → http/interfaces/http-handler.js} +0 -0
- /package/cjs/{interfaces/http-request-defaults.interface.js → http/interfaces/http-interceptor.js} +0 -0
- /package/esm/{client-error.js → core/client-error.js} +0 -0
- /package/esm/{enums → http/enums}/http-observable-type.enum.js +0 -0
- /package/esm/{interfaces/client-context.interface.js → http/interfaces/http-handler.js} +0 -0
- /package/esm/{interfaces/http-request-defaults.interface.js → http/interfaces/http-interceptor.js} +0 -0
- /package/types/{client-error.d.ts → core/client-error.d.ts} +0 -0
- /package/types/{enums → http/enums}/http-observable-type.enum.d.ts +0 -0
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import { lastValueFrom, Observable } from 'rxjs';
|
|
2
|
-
import { isReadableStreamLike } from 'rxjs/internal/util/isReadableStreamLike';
|
|
3
|
-
import typeIs from '@browsery/type-is';
|
|
4
|
-
import { isBlob, OpraURL } from '@opra/common';
|
|
5
|
-
import { ClientError } from '../client-error.js';
|
|
6
|
-
import { kClient, kContext } from '../constants.js';
|
|
7
|
-
import { HttpObserveType } from '../enums/index.js';
|
|
8
|
-
import { HttpEventType } from '../interfaces/index.js';
|
|
9
|
-
import { HttpRequest } from './http-request.js';
|
|
10
|
-
const directCopyProperties = ['cache', 'credentials', 'destination', 'headers', 'integrity',
|
|
11
|
-
'keepalive', 'mode', 'redirect', 'referrer', 'referrerPolicy'];
|
|
12
|
-
const kIntlObservable = Symbol.for('kIntlObservable');
|
|
13
|
-
/**
|
|
14
|
-
* @class HttpRequestObservable
|
|
15
|
-
*/
|
|
16
|
-
export class HttpRequestObservable extends Observable {
|
|
17
|
-
constructor(client, init) {
|
|
18
|
-
super((subscriber) => {
|
|
19
|
-
this[kIntlObservable].subscribe((event) => {
|
|
20
|
-
if (event.event === HttpEventType.Response) {
|
|
21
|
-
subscriber.next(event.response.body);
|
|
22
|
-
subscriber.complete();
|
|
23
|
-
}
|
|
24
|
-
}, (error) => subscriber.error(error), () => subscriber.complete());
|
|
25
|
-
});
|
|
26
|
-
const url = new OpraURL(init?.url);
|
|
27
|
-
Object.defineProperty(this, kContext, {
|
|
28
|
-
enumerable: false,
|
|
29
|
-
value: {
|
|
30
|
-
headers: new Headers(init?.headers),
|
|
31
|
-
params: url.searchParams,
|
|
32
|
-
requestInit: { ...init }
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
Object.defineProperty(this, kClient, {
|
|
36
|
-
enumerable: false,
|
|
37
|
-
value: client
|
|
38
|
-
});
|
|
39
|
-
this.request = new HttpRequest(init);
|
|
40
|
-
if (init?.headers)
|
|
41
|
-
this.header(init.headers);
|
|
42
|
-
this[kIntlObservable] = this._send();
|
|
43
|
-
}
|
|
44
|
-
httpOptions(options) {
|
|
45
|
-
directCopyProperties.forEach(k => {
|
|
46
|
-
if (options[k] !== undefined)
|
|
47
|
-
this.request[k] = options[k];
|
|
48
|
-
});
|
|
49
|
-
return this;
|
|
50
|
-
}
|
|
51
|
-
header(arg0, value) {
|
|
52
|
-
const headers = this.request.headers;
|
|
53
|
-
if (typeof arg0 === 'object') {
|
|
54
|
-
const h = arg0 instanceof Headers
|
|
55
|
-
? arg0
|
|
56
|
-
: new Headers(arg0);
|
|
57
|
-
h.forEach((v, k) => {
|
|
58
|
-
if (k.toLowerCase() === 'set-cookie') {
|
|
59
|
-
headers.append(k, v);
|
|
60
|
-
}
|
|
61
|
-
else
|
|
62
|
-
headers.set(k, v);
|
|
63
|
-
});
|
|
64
|
-
return this;
|
|
65
|
-
}
|
|
66
|
-
if (value == null)
|
|
67
|
-
headers.delete(arg0);
|
|
68
|
-
else
|
|
69
|
-
headers.append(arg0, String(value));
|
|
70
|
-
return this;
|
|
71
|
-
}
|
|
72
|
-
param(arg0, value) {
|
|
73
|
-
const params = this.request.url.searchParams;
|
|
74
|
-
if (typeof arg0 === 'object') {
|
|
75
|
-
const h = arg0 instanceof URLSearchParams
|
|
76
|
-
? arg0
|
|
77
|
-
: new URLSearchParams(arg0);
|
|
78
|
-
h.forEach((v, k) => params.set(k, v));
|
|
79
|
-
return this;
|
|
80
|
-
}
|
|
81
|
-
if (value == null)
|
|
82
|
-
params.delete(arg0);
|
|
83
|
-
else
|
|
84
|
-
params.set(arg0, String(value));
|
|
85
|
-
return this;
|
|
86
|
-
}
|
|
87
|
-
observe(observe) {
|
|
88
|
-
observe = observe || HttpObserveType.Body;
|
|
89
|
-
return new Observable((subscriber) => {
|
|
90
|
-
this[kIntlObservable].subscribe((event) => {
|
|
91
|
-
if (observe === HttpObserveType.Events) {
|
|
92
|
-
subscriber.next(event);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
if (observe === HttpObserveType.ResponseHeader && event.event === HttpEventType.ResponseHeader) {
|
|
96
|
-
subscriber.next(event.response);
|
|
97
|
-
subscriber.complete();
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
if (event.event === HttpEventType.Response) {
|
|
101
|
-
const { response } = event;
|
|
102
|
-
const isOpraResponse = typeIs.is(event.response.contentType || '', ['application/opra+json']);
|
|
103
|
-
if (observe === HttpObserveType.Response) {
|
|
104
|
-
subscriber.next(response);
|
|
105
|
-
subscriber.complete();
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
if (response.status >= 400 && response.status < 600) {
|
|
109
|
-
subscriber.error(new ClientError({
|
|
110
|
-
message: response.status + ' ' + response.statusText,
|
|
111
|
-
status: response.status,
|
|
112
|
-
issues: isOpraResponse ? response.body.errors : undefined
|
|
113
|
-
}));
|
|
114
|
-
subscriber.complete();
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
subscriber.next(event.response.body);
|
|
118
|
-
subscriber.complete();
|
|
119
|
-
}
|
|
120
|
-
}, (error) => subscriber.error(error), () => subscriber.complete());
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
toPromise() {
|
|
124
|
-
return this.getBody();
|
|
125
|
-
}
|
|
126
|
-
getBody() {
|
|
127
|
-
return lastValueFrom(this.observe(HttpObserveType.Body));
|
|
128
|
-
}
|
|
129
|
-
getResponse() {
|
|
130
|
-
return lastValueFrom(this.observe(HttpObserveType.Response));
|
|
131
|
-
}
|
|
132
|
-
_send() {
|
|
133
|
-
const request = this.request;
|
|
134
|
-
const clientContext = this[kClient][kContext];
|
|
135
|
-
return new Observable(subscriber => {
|
|
136
|
-
(async () => {
|
|
137
|
-
// Prepare request
|
|
138
|
-
this._prepareRequest();
|
|
139
|
-
// Call request Interceptors
|
|
140
|
-
for (const interceptor of clientContext.requestInterceptors) {
|
|
141
|
-
await interceptor(request);
|
|
142
|
-
}
|
|
143
|
-
// Emit 'sent' event
|
|
144
|
-
subscriber.next({
|
|
145
|
-
request,
|
|
146
|
-
event: HttpEventType.Sent,
|
|
147
|
-
});
|
|
148
|
-
// Send request
|
|
149
|
-
const url = new OpraURL(request.url, clientContext.serviceUrl);
|
|
150
|
-
const fetchResponse = await clientContext.fetch(url.toString(), request);
|
|
151
|
-
const contentType = (fetchResponse.headers.get('content-type') || '').split(';')[0];
|
|
152
|
-
// Emit 'response-header' event
|
|
153
|
-
const headersResponse = clientContext.createResponse({
|
|
154
|
-
url: fetchResponse.url,
|
|
155
|
-
headers: fetchResponse.headers,
|
|
156
|
-
status: fetchResponse.status,
|
|
157
|
-
statusText: fetchResponse.statusText,
|
|
158
|
-
hasBody: !!fetchResponse.body,
|
|
159
|
-
contentType
|
|
160
|
-
});
|
|
161
|
-
subscriber.next({
|
|
162
|
-
request,
|
|
163
|
-
event: HttpEventType.ResponseHeader,
|
|
164
|
-
response: headersResponse
|
|
165
|
-
});
|
|
166
|
-
// Parse body
|
|
167
|
-
const body = fetchResponse.body
|
|
168
|
-
? await this._parseBody(fetchResponse)
|
|
169
|
-
: undefined;
|
|
170
|
-
// Create response
|
|
171
|
-
const responseInit = {
|
|
172
|
-
url: fetchResponse.url,
|
|
173
|
-
headers: fetchResponse.headers,
|
|
174
|
-
status: fetchResponse.status,
|
|
175
|
-
statusText: fetchResponse.statusText,
|
|
176
|
-
contentType,
|
|
177
|
-
body,
|
|
178
|
-
};
|
|
179
|
-
const response = clientContext.createResponse(responseInit);
|
|
180
|
-
// Call response Interceptors
|
|
181
|
-
for (const interceptor of clientContext.responseInterceptors) {
|
|
182
|
-
await interceptor(response, request);
|
|
183
|
-
}
|
|
184
|
-
// Emit 'response' event
|
|
185
|
-
subscriber.next({
|
|
186
|
-
request,
|
|
187
|
-
event: HttpEventType.Response,
|
|
188
|
-
response
|
|
189
|
-
});
|
|
190
|
-
subscriber.complete();
|
|
191
|
-
})().catch(error => subscriber.error(error));
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
_prepareRequest() {
|
|
195
|
-
const request = this.request;
|
|
196
|
-
if (request.body) {
|
|
197
|
-
let body;
|
|
198
|
-
let contentType;
|
|
199
|
-
if (typeof request.body === 'string' || typeof request.body === 'number' || typeof request.body === 'boolean') {
|
|
200
|
-
contentType = 'text/plain;charset=UTF-8"';
|
|
201
|
-
body = String(request.body);
|
|
202
|
-
request.headers.delete('Content-Size');
|
|
203
|
-
delete request.duplex;
|
|
204
|
-
}
|
|
205
|
-
else if (isReadableStreamLike(request.body)) {
|
|
206
|
-
contentType = 'application/octet-stream';
|
|
207
|
-
body = request.body;
|
|
208
|
-
request.duplex = 'half';
|
|
209
|
-
}
|
|
210
|
-
else if (Buffer.isBuffer(request.body)) {
|
|
211
|
-
contentType = 'application/octet-stream';
|
|
212
|
-
body = request.body;
|
|
213
|
-
request.headers.set('Content-Size', String(request.body.length));
|
|
214
|
-
delete request.duplex;
|
|
215
|
-
}
|
|
216
|
-
else if (isBlob(request.body)) {
|
|
217
|
-
contentType = request.body.type || 'application/octet-stream';
|
|
218
|
-
body = request.body;
|
|
219
|
-
request.headers.set('Content-Size', String(request.body.size));
|
|
220
|
-
delete request.duplex;
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
contentType = 'application/json';
|
|
224
|
-
body = JSON.stringify(request.body);
|
|
225
|
-
request.headers.delete('Content-Size');
|
|
226
|
-
delete request.duplex;
|
|
227
|
-
}
|
|
228
|
-
if (!request.headers.has('Content-Type') && contentType)
|
|
229
|
-
request.headers.set('Content-Type', contentType);
|
|
230
|
-
request.body = body;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
async _parseBody(fetchResponse) {
|
|
234
|
-
let body;
|
|
235
|
-
const contentType = (fetchResponse.headers.get('Content-Type') || '');
|
|
236
|
-
if (typeIs.is(contentType, ['json', 'application/*+json'])) {
|
|
237
|
-
body = await fetchResponse.json();
|
|
238
|
-
if (typeof body === 'string')
|
|
239
|
-
body = JSON.parse(body);
|
|
240
|
-
}
|
|
241
|
-
else if (typeIs.is(contentType, ['text']))
|
|
242
|
-
body = await fetchResponse.text();
|
|
243
|
-
else if (typeIs.is(contentType, ['multipart']))
|
|
244
|
-
body = await fetchResponse.formData();
|
|
245
|
-
else {
|
|
246
|
-
const buf = await fetchResponse.arrayBuffer();
|
|
247
|
-
if (buf.byteLength)
|
|
248
|
-
body = buf;
|
|
249
|
-
}
|
|
250
|
-
return body;
|
|
251
|
-
}
|
|
252
|
-
}
|
package/esm/impl/http-request.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/// <reference lib="dom" />
|
|
2
|
-
import { OpraURL } from '@opra/common';
|
|
3
|
-
/**
|
|
4
|
-
* @class HttpRequest
|
|
5
|
-
*/
|
|
6
|
-
export class HttpRequest {
|
|
7
|
-
constructor(init) {
|
|
8
|
-
this.cache = init?.cache || 'default';
|
|
9
|
-
this.credentials = init?.credentials || 'same-origin';
|
|
10
|
-
this.destination = init?.destination || '';
|
|
11
|
-
this.integrity = init?.integrity || '';
|
|
12
|
-
this.keepalive = init?.keepalive ?? false;
|
|
13
|
-
this.method = (init?.method || 'GET').toUpperCase();
|
|
14
|
-
this.mode = init?.mode || 'cors';
|
|
15
|
-
this.redirect = init?.redirect || 'follow';
|
|
16
|
-
this.referrer = init?.referrer || '';
|
|
17
|
-
this.referrerPolicy = init?.referrerPolicy || '';
|
|
18
|
-
this.signal = init?.signal || new AbortController().signal;
|
|
19
|
-
this.body = init?.body;
|
|
20
|
-
this.url = init?.url instanceof OpraURL ? init.url : new OpraURL(init?.url);
|
|
21
|
-
this.headers = init?.headers instanceof Headers ? init.headers : new Headers(init?.headers);
|
|
22
|
-
}
|
|
23
|
-
}
|
package/esm/interfaces/index.js
DELETED
package/types/client.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { StrictOmit } from 'ts-gems';
|
|
2
|
-
import { ApiDocument } from '@opra/common';
|
|
3
|
-
import { kContext } from './constants.js';
|
|
4
|
-
import { HttpCollectionNode } from './impl/collection-node.js';
|
|
5
|
-
import { HttpRequestObservable } from './impl/http-request-observable.js';
|
|
6
|
-
import { HttpSingletonNode } from './impl/singleton-node.js';
|
|
7
|
-
import { OpraHttpClientContext } from './interfaces/client-context.interface.js';
|
|
8
|
-
import { HttpRequestDefaults } from './interfaces/index.js';
|
|
9
|
-
import { RequestInterceptor, ResponseInterceptor } from './types.js';
|
|
10
|
-
export declare namespace OpraHttpClient {
|
|
11
|
-
interface Options {
|
|
12
|
-
api?: ApiDocument;
|
|
13
|
-
requestInterceptors?: RequestInterceptor[];
|
|
14
|
-
responseInterceptors?: ResponseInterceptor[];
|
|
15
|
-
defaults?: HttpRequestDefaults;
|
|
16
|
-
}
|
|
17
|
-
type Defaults = StrictOmit<HttpRequestDefaults, 'headers' | 'params'> & {
|
|
18
|
-
headers: Headers;
|
|
19
|
-
params: URLSearchParams;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
export declare class OpraHttpClient<TResponseExt = {}> {
|
|
23
|
-
protected _metadataPromise?: Promise<any>;
|
|
24
|
-
[kContext]: OpraHttpClientContext;
|
|
25
|
-
constructor(serviceUrl: string, options?: OpraHttpClient.Options);
|
|
26
|
-
get serviceUrl(): string;
|
|
27
|
-
get api(): ApiDocument | undefined;
|
|
28
|
-
get defaults(): OpraHttpClient.Defaults;
|
|
29
|
-
getMetadata(): Promise<ApiDocument>;
|
|
30
|
-
collection<TType = any>(path: string): HttpCollectionNode<TType, TResponseExt>;
|
|
31
|
-
singleton<TType = any>(path: string): HttpSingletonNode<TType, TResponseExt>;
|
|
32
|
-
action<T = any>(path: string, params?: Record<string, any>): HttpRequestObservable<T, TResponseExt>;
|
|
33
|
-
}
|
package/types/enums/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './http-observable-type.enum.js';
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Observable } from 'rxjs';
|
|
2
|
-
import type { OpraHttpClient } from '../client.js';
|
|
3
|
-
import { kClient, kContext } from '../constants.js';
|
|
4
|
-
import { HttpObserveType } from '../enums/index.js';
|
|
5
|
-
import { HttpEvent } from '../interfaces/index.js';
|
|
6
|
-
import { URLSearchParamsInit } from '../types.js';
|
|
7
|
-
import { HttpRequest } from './http-request.js';
|
|
8
|
-
import { HttpResponse } from './http-response.js';
|
|
9
|
-
/**
|
|
10
|
-
* @namespace HttpRequestObservable
|
|
11
|
-
*/
|
|
12
|
-
export declare namespace HttpRequestObservable {
|
|
13
|
-
interface HttpOptions extends Partial<Pick<HttpRequest, 'cache' | 'credentials' | 'destination' | 'integrity' | 'keepalive' | 'mode' | 'redirect' | 'referrer' | 'referrerPolicy'>> {
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
declare const kIntlObservable: unique symbol;
|
|
17
|
-
/**
|
|
18
|
-
* @class HttpRequestObservable
|
|
19
|
-
*/
|
|
20
|
-
export declare class HttpRequestObservable<TPayload = any, TResponseExt = {}> extends Observable<TPayload> {
|
|
21
|
-
[kClient]: OpraHttpClient;
|
|
22
|
-
[kContext]: {
|
|
23
|
-
headers: Headers;
|
|
24
|
-
params: URLSearchParams;
|
|
25
|
-
requestInit: any;
|
|
26
|
-
};
|
|
27
|
-
[kIntlObservable]: Observable<HttpEvent>;
|
|
28
|
-
request: HttpRequest;
|
|
29
|
-
constructor(client: OpraHttpClient<any>, init?: HttpRequest.Initiator);
|
|
30
|
-
httpOptions(options: HttpRequestObservable.HttpOptions): this;
|
|
31
|
-
header(headers: HeadersInit): this;
|
|
32
|
-
header(name: string, value?: string | number | boolean | null): this;
|
|
33
|
-
param(params: URLSearchParamsInit): this;
|
|
34
|
-
param(name: string, value: any): this;
|
|
35
|
-
observe(): Observable<TPayload>;
|
|
36
|
-
observe(observe: HttpObserveType.Body): Observable<any>;
|
|
37
|
-
observe(observe: HttpObserveType.ResponseHeader): Observable<HttpResponse<void> & TResponseExt>;
|
|
38
|
-
observe(observe: HttpObserveType.Response): Observable<HttpResponse<any> & TResponseExt>;
|
|
39
|
-
observe(observe: HttpObserveType.Events): Observable<HttpEvent>;
|
|
40
|
-
toPromise(): Promise<TPayload>;
|
|
41
|
-
getBody(): Promise<TPayload>;
|
|
42
|
-
getResponse(): Promise<HttpResponse<TPayload> & TResponseExt>;
|
|
43
|
-
protected _send(): Observable<HttpEvent>;
|
|
44
|
-
protected _prepareRequest(): void;
|
|
45
|
-
protected _parseBody(fetchResponse: Response): Promise<TPayload>;
|
|
46
|
-
}
|
|
47
|
-
export {};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/// <reference lib="dom" />
|
|
2
|
-
import { OpraURL } from '@opra/common';
|
|
3
|
-
/**
|
|
4
|
-
* @namespace HttpRequest
|
|
5
|
-
*/
|
|
6
|
-
export declare namespace HttpRequest {
|
|
7
|
-
interface Initiator {
|
|
8
|
-
cache?: RequestCache;
|
|
9
|
-
credentials?: RequestCredentials;
|
|
10
|
-
destination?: RequestDestination;
|
|
11
|
-
headers?: HeadersInit;
|
|
12
|
-
integrity?: string;
|
|
13
|
-
keepalive?: boolean;
|
|
14
|
-
method?: string;
|
|
15
|
-
mode?: RequestMode;
|
|
16
|
-
redirect?: RequestRedirect;
|
|
17
|
-
referrer?: string;
|
|
18
|
-
referrerPolicy?: ReferrerPolicy;
|
|
19
|
-
signal?: AbortSignal;
|
|
20
|
-
url: string | URL | OpraURL;
|
|
21
|
-
body?: any;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* @class HttpRequest
|
|
26
|
-
*/
|
|
27
|
-
export declare class HttpRequest {
|
|
28
|
-
/** The url for request */
|
|
29
|
-
url: OpraURL;
|
|
30
|
-
/** Body of the http request */
|
|
31
|
-
body?: any;
|
|
32
|
-
/** The cache mode associated with request, which is a string indicating
|
|
33
|
-
* how the request will interact with the browser's cache when fetching. */
|
|
34
|
-
cache: RequestCache;
|
|
35
|
-
/** The credentials mode associated with request, which is a string indicating
|
|
36
|
-
* whether credentials will be sent with the request always, never,
|
|
37
|
-
* or only when sent to a same-origin URL. */
|
|
38
|
-
credentials: RequestCredentials;
|
|
39
|
-
/** The kind of resource requested by request, e.g., "document" or "script". */
|
|
40
|
-
destination: RequestDestination;
|
|
41
|
-
/** Headers object consisting of the headers associated with request.
|
|
42
|
-
* Note that headers added in the network layer by the user agent will not be accounted for in this object,
|
|
43
|
-
* e.g., the "Host" header. */
|
|
44
|
-
headers: Headers;
|
|
45
|
-
/** Request's subresource integrity metadata, which is a cryptographic
|
|
46
|
-
* hash of the resource being fetched.
|
|
47
|
-
* Its value consists of multiple hashes separated by whitespace. [SRI] */
|
|
48
|
-
integrity: string;
|
|
49
|
-
/** A boolean indicating whether or not request can outlive the global in which it was created. */
|
|
50
|
-
keepalive: boolean;
|
|
51
|
-
/** Request's HTTP method, which is "GET" by default. */
|
|
52
|
-
method: string;
|
|
53
|
-
/** The mode associated with request, which is a string indicating whether the request will use CORS,
|
|
54
|
-
* or will be restricted to same-origin URLs. */
|
|
55
|
-
mode: RequestMode;
|
|
56
|
-
/** The redirect mode associated with request, which is a string indicating
|
|
57
|
-
* how redirects for the request will be handled during fetching. A request will follow redirects by default. */
|
|
58
|
-
redirect: RequestRedirect;
|
|
59
|
-
/** The referrer of request. Its value can be a same-origin URL if explicitly set in init,
|
|
60
|
-
* the empty string to indicate no referrer, and "about:client" when defaulting to the global's default.
|
|
61
|
-
* This is used during fetching to determine the value of the `Referer` header of the request being made. */
|
|
62
|
-
referrer: string;
|
|
63
|
-
/** The referrer policy associated with request. This is used during fetching
|
|
64
|
-
* to compute the value of the request's referrer. */
|
|
65
|
-
referrerPolicy: ReferrerPolicy;
|
|
66
|
-
/** The signal associated with request, which is an AbortSignal object indicating
|
|
67
|
-
* whether or not request has been aborted, and its abort event handler. */
|
|
68
|
-
signal?: AbortSignal;
|
|
69
|
-
duplex?: 'half';
|
|
70
|
-
constructor(init?: HttpRequest.Initiator);
|
|
71
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ApiDocument } from '@opra/common';
|
|
2
|
-
import type { OpraHttpClient } from '../client.js';
|
|
3
|
-
import type { HttpResponse } from '../impl/http-response.js';
|
|
4
|
-
import type { RequestInterceptor, ResponseInterceptor } from '../types.js';
|
|
5
|
-
export interface OpraHttpClientContext {
|
|
6
|
-
serviceUrl: string;
|
|
7
|
-
requestInterceptors: RequestInterceptor[];
|
|
8
|
-
responseInterceptors: ResponseInterceptor[];
|
|
9
|
-
createResponse: (init?: HttpResponse.Initiator) => HttpResponse<any>;
|
|
10
|
-
fetch: (url: string, init?: RequestInit) => Promise<Response>;
|
|
11
|
-
api?: ApiDocument;
|
|
12
|
-
defaults: OpraHttpClient.Defaults;
|
|
13
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import type { HttpRequest } from '../impl/http-request.js';
|
|
2
|
-
import type { HttpResponse } from '../impl/http-response.js';
|
|
3
|
-
export type HttpEvent = HttpSentEvent | HttpDownloadProgressEvent | HttpUploadProgressEvent | HttpResponseHeaderEvent | HttpResponseEvent | HttpUserEvent;
|
|
4
|
-
/**
|
|
5
|
-
* Type enumeration for the different kinds of `HttpEvent`.
|
|
6
|
-
*/
|
|
7
|
-
export declare enum HttpEventType {
|
|
8
|
-
/**
|
|
9
|
-
* The request was sent out over the wire.
|
|
10
|
-
*/
|
|
11
|
-
Sent = "sent",
|
|
12
|
-
/**
|
|
13
|
-
* An upload progress event was received.
|
|
14
|
-
*
|
|
15
|
-
* Note: The `FetchBackend` doesn't support progress report on uploads.
|
|
16
|
-
*/
|
|
17
|
-
UploadProgress = "upload-progress",
|
|
18
|
-
/**
|
|
19
|
-
* The response status code and headers were received.
|
|
20
|
-
*/
|
|
21
|
-
ResponseHeader = "response-header",
|
|
22
|
-
/**
|
|
23
|
-
* A download progress event was received.
|
|
24
|
-
*/
|
|
25
|
-
DownloadProgress = "download-progress",
|
|
26
|
-
/**
|
|
27
|
-
* The full response including the body was received.
|
|
28
|
-
*/
|
|
29
|
-
Response = "response",
|
|
30
|
-
/**
|
|
31
|
-
* A custom event from an interceptor or a backend.
|
|
32
|
-
*/
|
|
33
|
-
Custom = "custom"
|
|
34
|
-
}
|
|
35
|
-
interface HttpEventBase {
|
|
36
|
-
request: HttpRequest;
|
|
37
|
-
event: HttpEventType;
|
|
38
|
-
}
|
|
39
|
-
export interface HttpSentEvent extends HttpEventBase {
|
|
40
|
-
event: HttpEventType.Sent;
|
|
41
|
-
}
|
|
42
|
-
export interface HttpDownloadProgressEvent extends HttpEventBase {
|
|
43
|
-
event: HttpEventType.DownloadProgress;
|
|
44
|
-
/**
|
|
45
|
-
* Number of bytes uploaded
|
|
46
|
-
*/
|
|
47
|
-
loaded: number;
|
|
48
|
-
/**
|
|
49
|
-
* Total number of bytes to upload.
|
|
50
|
-
* Depending on the request, this may not be computable and thus may not be present.
|
|
51
|
-
*/
|
|
52
|
-
total?: number;
|
|
53
|
-
}
|
|
54
|
-
export interface HttpUploadProgressEvent extends HttpEventBase {
|
|
55
|
-
event: HttpEventType.UploadProgress;
|
|
56
|
-
/**
|
|
57
|
-
* Response object
|
|
58
|
-
*/
|
|
59
|
-
response: HttpResponse;
|
|
60
|
-
/**
|
|
61
|
-
* Number of bytes uploaded
|
|
62
|
-
*/
|
|
63
|
-
loaded: number;
|
|
64
|
-
/**
|
|
65
|
-
* Total number of bytes to upload.
|
|
66
|
-
* Depending on the request, this may not be computable and thus may not be present.
|
|
67
|
-
*/
|
|
68
|
-
total?: number;
|
|
69
|
-
}
|
|
70
|
-
export interface HttpResponseHeaderEvent extends HttpEventBase {
|
|
71
|
-
event: HttpEventType.ResponseHeader;
|
|
72
|
-
/**
|
|
73
|
-
* Response object
|
|
74
|
-
*/
|
|
75
|
-
response: HttpResponse;
|
|
76
|
-
}
|
|
77
|
-
export interface HttpResponseEvent extends HttpEventBase {
|
|
78
|
-
event: HttpEventType.Response;
|
|
79
|
-
/**
|
|
80
|
-
* Response object
|
|
81
|
-
*/
|
|
82
|
-
response: HttpResponse;
|
|
83
|
-
}
|
|
84
|
-
export interface HttpUserEvent extends HttpEventBase {
|
|
85
|
-
event: HttpEventType.Custom;
|
|
86
|
-
[key: string | number | symbol]: any;
|
|
87
|
-
}
|
|
88
|
-
export {};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { HttpRequest } from '../impl/http-request.js';
|
|
2
|
-
import type { URLSearchParamsInit } from '../types.js';
|
|
3
|
-
export interface HttpRequestDefaults extends Partial<Pick<HttpRequest, 'cache' | 'credentials' | 'destination' | 'integrity' | 'keepalive' | 'mode' | 'redirect' | 'referrer' | 'referrerPolicy'>> {
|
|
4
|
-
headers?: HeadersInit;
|
|
5
|
-
params?: URLSearchParamsInit;
|
|
6
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/cjs/{interfaces/http-request-defaults.interface.js → http/interfaces/http-interceptor.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/esm/{interfaces/http-request-defaults.interface.js → http/interfaces/http-interceptor.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|