@opra/client 0.33.13 → 1.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser.js +3 -3
- package/cjs/core/backend.js +1 -1
- package/cjs/http/fetch-backend.js +15 -13
- package/cjs/http/http-backend.js +4 -1
- package/cjs/http/http-client-base.js +59 -65
- package/cjs/http/http-interceptor-handler.js +2 -2
- package/cjs/http/http-request-observable.js +14 -18
- package/cjs/http/http-response.js +2 -2
- package/cjs/http/http-utils.js +12 -0
- package/cjs/index.js +1 -5
- package/esm/core/backend.js +1 -1
- package/esm/http/fetch-backend.js +17 -15
- package/esm/http/http-backend.js +4 -1
- package/esm/http/http-client-base.js +60 -66
- package/esm/http/http-interceptor-handler.js +2 -2
- package/esm/http/http-request-observable.js +15 -19
- package/esm/http/http-response.js +2 -2
- package/esm/http/http-utils.js +8 -0
- package/esm/index.js +1 -5
- package/package.json +14 -12
- package/types/core/backend.d.ts +2 -2
- package/types/http/http-backend.d.ts +3 -2
- package/types/http/http-client-base.d.ts +24 -25
- package/types/http/http-request-observable.d.ts +3 -4
- package/types/http/http-response.d.ts +1 -0
- package/types/http/http-utils.d.ts +1 -0
- package/types/index.d.ts +1 -5
- package/cjs/core/client-base.js +0 -18
- package/cjs/http/http-collection-node.js +0 -119
- package/cjs/http/http-singleton-node.js +0 -62
- package/cjs/http/http-storage-node.js +0 -55
- package/cjs/types.js +0 -3
- package/esm/core/client-base.js +0 -14
- package/esm/http/http-collection-node.js +0 -115
- package/esm/http/http-singleton-node.js +0 -58
- package/esm/http/http-storage-node.js +0 -51
- package/esm/types.js +0 -2
- package/types/core/client-base.d.ts +0 -21
- package/types/http/http-collection-node.d.ts +0 -55
- package/types/http/http-singleton-node.d.ts +0 -35
- package/types/http/http-storage-node.d.ts +0 -14
- package/types/types.d.ts +0 -1
|
@@ -1,88 +1,82 @@
|
|
|
1
|
-
import { ApiDocumentFactory
|
|
1
|
+
import { ApiDocumentFactory } from '@opra/common';
|
|
2
2
|
import { kBackend } from '../constants.js';
|
|
3
|
-
import { ClientBase } from '../core/client-base.js';
|
|
4
|
-
import { HttpCollectionNode } from './http-collection-node.js';
|
|
5
3
|
import { HttpRequestObservable } from './http-request-observable.js';
|
|
6
|
-
import { HttpSingletonNode } from './http-singleton-node.js';
|
|
7
|
-
import { HttpStorageNode } from './http-storage-node.js';
|
|
8
4
|
/**
|
|
9
5
|
*
|
|
10
6
|
* @class OpraClientBase
|
|
11
7
|
* @abstract
|
|
12
8
|
*/
|
|
13
|
-
export class HttpClientBase
|
|
9
|
+
export class HttpClientBase {
|
|
14
10
|
constructor(backend) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
Object.defineProperty(this, kBackend, {
|
|
12
|
+
enumerable: false,
|
|
13
|
+
value: backend,
|
|
14
|
+
});
|
|
19
15
|
}
|
|
20
16
|
get serviceUrl() {
|
|
21
17
|
return this[kBackend].serviceUrl;
|
|
22
18
|
}
|
|
23
|
-
async
|
|
24
|
-
if (this.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this._metadataPromise = request.getBody();
|
|
34
|
-
body = await this._metadataPromise;
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
e.message = 'Error fetching metadata from url (' + this.serviceUrl + ').\n' + e.message;
|
|
38
|
-
throw e;
|
|
39
|
-
}
|
|
40
|
-
finally {
|
|
41
|
-
this._metadataPromise = undefined;
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
const api = await ApiDocumentFactory.createDocument(body);
|
|
45
|
-
this[kBackend].api = api;
|
|
46
|
-
return api;
|
|
19
|
+
async getSchema() {
|
|
20
|
+
if (!this._schemaRequest) {
|
|
21
|
+
this._schemaRequest = this.request('$schema', {
|
|
22
|
+
headers: new Headers({ accept: 'application/json' }),
|
|
23
|
+
})
|
|
24
|
+
.getBody()
|
|
25
|
+
.catch(e => {
|
|
26
|
+
e.message = 'Error fetching api schema from url (' + this.serviceUrl + ').\n' + e.message;
|
|
27
|
+
throw e;
|
|
28
|
+
});
|
|
47
29
|
}
|
|
48
|
-
|
|
30
|
+
const body = await this._schemaRequest;
|
|
31
|
+
const document = await ApiDocumentFactory.createDocument(body).catch(e => {
|
|
49
32
|
e.message = 'Error loading api document.\n' + e.message;
|
|
50
33
|
throw e;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (!node) {
|
|
56
|
-
node = new HttpCollectionNode(this[kBackend], path);
|
|
57
|
-
this._collectionCache.set(path, node);
|
|
58
|
-
}
|
|
59
|
-
return node;
|
|
34
|
+
});
|
|
35
|
+
this[kBackend].document = document;
|
|
36
|
+
this._schemaRequest = undefined;
|
|
37
|
+
return document;
|
|
60
38
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
39
|
+
request(path, options) {
|
|
40
|
+
const observable = new HttpRequestObservable(this[kBackend], {
|
|
41
|
+
...options,
|
|
42
|
+
method: options?.method || 'GET',
|
|
43
|
+
url: new URL(path, this.serviceUrl),
|
|
44
|
+
});
|
|
45
|
+
if (options?.params)
|
|
46
|
+
observable.param(options.params);
|
|
47
|
+
return observable;
|
|
68
48
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
return node;
|
|
49
|
+
delete(path, options) {
|
|
50
|
+
return this.request(path, {
|
|
51
|
+
...options,
|
|
52
|
+
method: 'DELETE',
|
|
53
|
+
});
|
|
76
54
|
}
|
|
77
|
-
|
|
78
|
-
|
|
55
|
+
get(path, options) {
|
|
56
|
+
return this.request(path, {
|
|
57
|
+
...options,
|
|
79
58
|
method: 'GET',
|
|
80
|
-
url: path
|
|
81
59
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
60
|
+
}
|
|
61
|
+
patch(path, requestBody, options) {
|
|
62
|
+
return this.request(path, {
|
|
63
|
+
...options,
|
|
64
|
+
method: 'PATCH',
|
|
65
|
+
body: requestBody,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
post(path, requestBody, options) {
|
|
69
|
+
return this.request(path, {
|
|
70
|
+
...options,
|
|
71
|
+
method: 'POST',
|
|
72
|
+
body: requestBody,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
put(path, requestBody, options) {
|
|
76
|
+
return this.request(path, {
|
|
77
|
+
...options,
|
|
78
|
+
method: 'PUT',
|
|
79
|
+
body: requestBody,
|
|
80
|
+
});
|
|
87
81
|
}
|
|
88
82
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export class HttpInterceptorHandler {
|
|
2
2
|
constructor(interceptors, finalHandler) {
|
|
3
3
|
this.chain = interceptors.reduceRight((chainTailFn, interceptor) => (initialRequest, handler) => interceptor.intercept(initialRequest, {
|
|
4
|
-
handle:
|
|
4
|
+
handle: downstreamRequest => chainTailFn(downstreamRequest, handler),
|
|
5
5
|
}), chainEnd);
|
|
6
6
|
this.finalHandler = finalHandler;
|
|
7
7
|
}
|
|
8
8
|
handle(initialRequest) {
|
|
9
|
-
return this.chain(initialRequest,
|
|
9
|
+
return this.chain(initialRequest, req => this.finalHandler.handle(req));
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
function chainEnd(req, handler) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { lastValueFrom, Observable } from 'rxjs';
|
|
2
2
|
import typeIs from '@browsery/type-is';
|
|
3
|
-
import {
|
|
3
|
+
import { MimeTypes } from '@opra/common';
|
|
4
4
|
import { kBackend, kContext } from '../constants.js';
|
|
5
5
|
import { ClientError } from '../core/client-error.js';
|
|
6
6
|
import { HttpObserveType } from './enums/http-observable-type.enum.js';
|
|
@@ -12,11 +12,9 @@ import { HttpEventType } from './interfaces/http-event.js';
|
|
|
12
12
|
*/
|
|
13
13
|
export class HttpRequestObservable extends Observable {
|
|
14
14
|
constructor(backend, init) {
|
|
15
|
-
super(
|
|
15
|
+
super(subscriber => {
|
|
16
16
|
const observe = this[kContext].observe;
|
|
17
|
-
new HttpInterceptorHandler(backend.interceptors || [], this[kBackend])
|
|
18
|
-
.handle(this[kContext])
|
|
19
|
-
.subscribe({
|
|
17
|
+
new HttpInterceptorHandler(backend.interceptors || [], this[kBackend]).handle(this[kContext]).subscribe({
|
|
20
18
|
next(event) {
|
|
21
19
|
if (observe === HttpObserveType.Events) {
|
|
22
20
|
subscriber.next(event);
|
|
@@ -34,12 +32,12 @@ export class HttpRequestObservable extends Observable {
|
|
|
34
32
|
subscriber.complete();
|
|
35
33
|
return;
|
|
36
34
|
}
|
|
37
|
-
const isOpraResponse = typeIs.is(event.response.contentType || '', [
|
|
35
|
+
const isOpraResponse = typeIs.is(event.response.contentType || '', [MimeTypes.opra_response_json]);
|
|
38
36
|
if (response.status >= 400 && response.status < 600) {
|
|
39
37
|
subscriber.error(new ClientError({
|
|
40
38
|
message: response.status + ' ' + response.statusText,
|
|
41
39
|
status: response.status,
|
|
42
|
-
issues: isOpraResponse ? response.body.errors : undefined
|
|
40
|
+
issues: isOpraResponse ? response.body.errors : undefined,
|
|
43
41
|
}));
|
|
44
42
|
subscriber.complete();
|
|
45
43
|
return;
|
|
@@ -53,22 +51,20 @@ export class HttpRequestObservable extends Observable {
|
|
|
53
51
|
},
|
|
54
52
|
complete() {
|
|
55
53
|
subscriber.complete();
|
|
56
|
-
}
|
|
54
|
+
},
|
|
57
55
|
});
|
|
58
56
|
});
|
|
59
57
|
Object.defineProperty(this, kBackend, {
|
|
60
58
|
enumerable: false,
|
|
61
|
-
value: backend
|
|
59
|
+
value: backend,
|
|
62
60
|
});
|
|
63
|
-
const url = new OpraURL(init?.url);
|
|
64
61
|
Object.defineProperty(this, kContext, {
|
|
65
62
|
enumerable: false,
|
|
66
63
|
value: {
|
|
67
64
|
...init,
|
|
68
65
|
observe: HttpObserveType.Body,
|
|
69
66
|
headers: new Headers(init?.headers),
|
|
70
|
-
|
|
71
|
-
}
|
|
67
|
+
},
|
|
72
68
|
});
|
|
73
69
|
}
|
|
74
70
|
clone() {
|
|
@@ -81,9 +77,7 @@ export class HttpRequestObservable extends Observable {
|
|
|
81
77
|
header(arg0, value) {
|
|
82
78
|
const target = this[kContext].headers;
|
|
83
79
|
if (typeof arg0 === 'object') {
|
|
84
|
-
const h = arg0 instanceof Headers
|
|
85
|
-
? arg0
|
|
86
|
-
: new Headers(arg0);
|
|
80
|
+
const h = arg0 instanceof Headers ? arg0 : new Headers(arg0);
|
|
87
81
|
h.forEach((v, k) => {
|
|
88
82
|
if (k.toLowerCase() === 'set-cookie') {
|
|
89
83
|
target.append(k, v);
|
|
@@ -105,10 +99,12 @@ export class HttpRequestObservable extends Observable {
|
|
|
105
99
|
}
|
|
106
100
|
const target = this[kContext].url.searchParams;
|
|
107
101
|
if (typeof arg0 === 'object') {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
102
|
+
if (typeof arg0.forEach === 'function') {
|
|
103
|
+
arg0.forEach((v, k) => target.set(String(k), String(v)));
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
Object.entries(arg0).forEach(entry => target.set(String(entry[0]), String(entry[1])));
|
|
107
|
+
}
|
|
112
108
|
return this;
|
|
113
109
|
}
|
|
114
110
|
if (value == null)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
1
2
|
export class HttpResponse {
|
|
2
3
|
constructor(init) {
|
|
3
4
|
/**
|
|
4
5
|
* Returns true if response has body to be received
|
|
5
6
|
*/
|
|
6
7
|
this.hasBody = false;
|
|
7
|
-
this.headers = init?.headers instanceof Headers ? init?.headers
|
|
8
|
-
: new Headers(init?.headers);
|
|
8
|
+
this.headers = init?.headers instanceof Headers ? init?.headers : 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/esm/index.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
export * from './types.js';
|
|
2
1
|
export * from './core/backend.js';
|
|
3
|
-
export * from './core/client-base.js';
|
|
4
2
|
export * from './core/client-error.js';
|
|
5
3
|
export * from './http/fetch-backend.js';
|
|
6
4
|
export * from './http/http-backend.js';
|
|
7
5
|
export * from './http/http-client.js';
|
|
8
6
|
export * from './http/http-client-base.js';
|
|
9
|
-
export * from './http/http-collection-node.js';
|
|
10
7
|
export * from './http/http-request-observable.js';
|
|
11
8
|
export * from './http/http-response.js';
|
|
12
|
-
export * from './http/http-
|
|
13
|
-
export * from './http/http-storage-node.js';
|
|
9
|
+
export * from './http/http-utils.js';
|
|
14
10
|
export * from './http/enums/http-observable-type.enum.js';
|
|
15
11
|
export * from './http/interfaces/http-event.js';
|
|
16
12
|
export * from './http/interfaces/http-handler.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-alpha.2",
|
|
4
4
|
"description": "Opra Client package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"postbuild": "cp README.md package.json ../../LICENSE ../../build/client && cp ../../package.cjs.json ../../build/client/cjs/package.json",
|
|
20
20
|
"lint": "eslint . --max-warnings=0",
|
|
21
21
|
"check": "madge --circular src/**",
|
|
22
|
+
"format": "prettier . --write --log-level=warn",
|
|
22
23
|
"test": "jest",
|
|
23
24
|
"cover": "jest --collect-coverage",
|
|
24
25
|
"clean": "npm run clean:src && npm run clean:test && npm run clean:dist && npm run clean:cover",
|
|
@@ -34,20 +35,20 @@
|
|
|
34
35
|
"types": "./types/index.d.ts",
|
|
35
36
|
"dependencies": {
|
|
36
37
|
"@browsery/fs": "^0.4.0",
|
|
37
|
-
"@browsery/highland": "^
|
|
38
|
-
"@browsery/http-parser": "^0.
|
|
39
|
-
"@browsery/i18next": "^
|
|
40
|
-
"@browsery/stream": "^
|
|
41
|
-
"@browsery/type-is": "^
|
|
42
|
-
"@browsery/util": "^0.
|
|
43
|
-
"@opra/common": "^0.
|
|
38
|
+
"@browsery/highland": "^2.13.5",
|
|
39
|
+
"@browsery/http-parser": "^0.5.8",
|
|
40
|
+
"@browsery/i18next": "^23.8.2",
|
|
41
|
+
"@browsery/stream": "^4.3.0",
|
|
42
|
+
"@browsery/type-is": "^1.6.18-r2",
|
|
43
|
+
"@browsery/util": "^0.12.5",
|
|
44
|
+
"@opra/common": "^1.0.0-alpha.2",
|
|
44
45
|
"accepts": "^1.3.8",
|
|
45
46
|
"buffer": "^6.0.3",
|
|
46
47
|
"cookie": "^0.6.0",
|
|
47
48
|
"crypto-browserify": "^3.12.0",
|
|
48
|
-
"encodeurl": "^
|
|
49
|
+
"encodeurl": "^2.0.0",
|
|
49
50
|
"events": "^3.3.0",
|
|
50
|
-
"fast-tokenizer": "^1.
|
|
51
|
+
"fast-tokenizer": "^1.3.0",
|
|
51
52
|
"lodash.omit": "^4.5.0",
|
|
52
53
|
"path-browserify": "^1.0.1",
|
|
53
54
|
"process": "^0.11.10",
|
|
@@ -55,8 +56,9 @@
|
|
|
55
56
|
"putil-merge": "^3.12.1",
|
|
56
57
|
"putil-promisify": "^1.10.1",
|
|
57
58
|
"putil-varhelpers": "^1.6.5",
|
|
58
|
-
"reflect-metadata": "^0.
|
|
59
|
+
"reflect-metadata": "^0.2.2",
|
|
59
60
|
"rxjs": ">=7.0.0",
|
|
61
|
+
"ts-gems": "^3.4.0",
|
|
60
62
|
"ts-lib": "^0.0.5",
|
|
61
63
|
"uid": "^2.0.1"
|
|
62
64
|
},
|
|
@@ -78,4 +80,4 @@
|
|
|
78
80
|
"request",
|
|
79
81
|
"fetch"
|
|
80
82
|
]
|
|
81
|
-
}
|
|
83
|
+
}
|
package/types/core/backend.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Observable } from 'rxjs';
|
|
|
2
2
|
import { ApiDocument } from '@opra/common';
|
|
3
3
|
import { HttpEvent } from '../http/interfaces/http-event.js';
|
|
4
4
|
export declare abstract class Backend implements Backend {
|
|
5
|
-
|
|
5
|
+
document?: ApiDocument;
|
|
6
6
|
protected constructor(options?: Backend.Options);
|
|
7
7
|
abstract handle(init: Backend.RequestInit): Observable<HttpEvent>;
|
|
8
8
|
}
|
|
@@ -11,7 +11,7 @@ export declare abstract class Backend implements Backend {
|
|
|
11
11
|
*/
|
|
12
12
|
export declare namespace Backend {
|
|
13
13
|
interface Options {
|
|
14
|
-
|
|
14
|
+
document?: ApiDocument;
|
|
15
15
|
}
|
|
16
16
|
interface RequestInit {
|
|
17
17
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ApiDocument } from '@opra/common';
|
|
2
2
|
import { Backend } from '../core/backend.js';
|
|
3
3
|
import type { HttpHandler } from './interfaces/http-handler.js';
|
|
4
4
|
import type { HttpInterceptor } from './interfaces/http-interceptor.js';
|
|
@@ -9,6 +9,7 @@ import type { HttpInterceptor } from './interfaces/http-interceptor.js';
|
|
|
9
9
|
export declare abstract class HttpBackend extends Backend implements HttpHandler {
|
|
10
10
|
readonly serviceUrl: string;
|
|
11
11
|
interceptors: HttpInterceptor<any>[];
|
|
12
|
+
document?: ApiDocument;
|
|
12
13
|
protected constructor(serviceUrl: string, options?: HttpBackend.Options);
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
@@ -20,7 +21,7 @@ export declare namespace HttpBackend {
|
|
|
20
21
|
}
|
|
21
22
|
interface RequestInit extends Backend.RequestInit {
|
|
22
23
|
method: string;
|
|
23
|
-
url: string | URL
|
|
24
|
+
url: string | URL;
|
|
24
25
|
headers?: Headers;
|
|
25
26
|
body?: any;
|
|
26
27
|
}
|
|
@@ -1,36 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StrictOmit } from 'ts-gems';
|
|
2
|
+
import { ApiDocument, URLSearchParamsInit } from '@opra/common';
|
|
2
3
|
import { kBackend } from '../constants.js';
|
|
3
|
-
import { ClientBase } from '../core/client-base.js';
|
|
4
4
|
import { HttpBackend } from './http-backend.js';
|
|
5
|
-
import { HttpCollectionNode } from './http-collection-node.js';
|
|
6
5
|
import { HttpRequestObservable } from './http-request-observable.js';
|
|
7
|
-
import { HttpSingletonNode } from './http-singleton-node.js';
|
|
8
|
-
import { HttpStorageNode } from './http-storage-node.js';
|
|
9
6
|
/**
|
|
10
7
|
*
|
|
11
|
-
* @
|
|
12
|
-
* @abstract
|
|
8
|
+
* @namespace OpraClientBase
|
|
13
9
|
*/
|
|
14
|
-
export declare
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
get serviceUrl(): string;
|
|
22
|
-
getMetadata(): Promise<ApiDocument>;
|
|
23
|
-
collection<TType = any>(path: string): HttpCollectionNode<TType, TRequestOptions, TResponseExt>;
|
|
24
|
-
singleton<TType = any>(path: string): HttpSingletonNode<TType, TRequestOptions, TResponseExt>;
|
|
25
|
-
storage<TType = any>(path: string): HttpStorageNode<TType, TRequestOptions, TResponseExt>;
|
|
26
|
-
action<T = any>(path: string, params?: Record<string, any>): HttpRequestObservable<T, T, TRequestOptions, TResponseExt>;
|
|
10
|
+
export declare namespace OpraClientBase {
|
|
11
|
+
interface Options {
|
|
12
|
+
document?: ApiDocument;
|
|
13
|
+
}
|
|
14
|
+
type RequestOptions = Partial<StrictOmit<HttpBackend.RequestInit, 'url'>> & {
|
|
15
|
+
params?: URLSearchParamsInit;
|
|
16
|
+
};
|
|
27
17
|
}
|
|
28
18
|
/**
|
|
29
19
|
*
|
|
30
|
-
* @
|
|
20
|
+
* @class OpraClientBase
|
|
21
|
+
* @abstract
|
|
31
22
|
*/
|
|
32
|
-
export declare
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
23
|
+
export declare abstract class HttpClientBase<TRequestOptions = {}, TResponseExt = {}> {
|
|
24
|
+
protected [kBackend]: HttpBackend;
|
|
25
|
+
protected _schemaRequest?: Promise<any>;
|
|
26
|
+
protected constructor(backend: HttpBackend);
|
|
27
|
+
get serviceUrl(): string;
|
|
28
|
+
getSchema(): Promise<ApiDocument>;
|
|
29
|
+
request<TBody = any>(path: string, options?: OpraClientBase.RequestOptions): HttpRequestObservable<TBody, TBody, TRequestOptions, TResponseExt>;
|
|
30
|
+
delete<TBody = any>(path: string, options?: StrictOmit<OpraClientBase.RequestOptions, 'method' | 'body'>): HttpRequestObservable<TBody, TBody, TRequestOptions, TResponseExt>;
|
|
31
|
+
get<TBody = any>(path: string, options?: StrictOmit<OpraClientBase.RequestOptions, 'method' | 'body'>): HttpRequestObservable<TBody, TBody, TRequestOptions, TResponseExt>;
|
|
32
|
+
patch<TBody = any>(path: string, requestBody: any, options?: StrictOmit<OpraClientBase.RequestOptions, 'method' | 'body'>): HttpRequestObservable<TBody, TBody, TRequestOptions, TResponseExt>;
|
|
33
|
+
post<TBody = any>(path: string, requestBody: any, options?: StrictOmit<OpraClientBase.RequestOptions, 'method' | 'body'>): HttpRequestObservable<TBody, TBody, TRequestOptions, TResponseExt>;
|
|
34
|
+
put<TBody = any>(path: string, requestBody: any, options?: StrictOmit<OpraClientBase.RequestOptions, 'method' | 'body'>): HttpRequestObservable<TBody, TBody, TRequestOptions, TResponseExt>;
|
|
36
35
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
|
-
import {
|
|
2
|
+
import { URLSearchParamsInit } from '@opra/common';
|
|
3
3
|
import { kBackend, kContext } from '../constants.js';
|
|
4
|
-
import { URLSearchParamsInit } from '../types.js';
|
|
5
4
|
import { HttpObserveType } from './enums/http-observable-type.enum.js';
|
|
6
5
|
import { HttpBackend } from './http-backend.js';
|
|
7
6
|
import { HttpResponse } from './http-response.js';
|
|
@@ -15,7 +14,7 @@ export declare class HttpRequestObservable<T, TBody = T, TRequestOptions = {}, T
|
|
|
15
14
|
[kContext]: {
|
|
16
15
|
observe: HttpObserveType;
|
|
17
16
|
method: string;
|
|
18
|
-
url:
|
|
17
|
+
url: URL;
|
|
19
18
|
headers: Headers;
|
|
20
19
|
[key: string]: any;
|
|
21
20
|
};
|
|
@@ -24,7 +23,7 @@ export declare class HttpRequestObservable<T, TBody = T, TRequestOptions = {}, T
|
|
|
24
23
|
options(options: TRequestOptions): HttpRequestObservable<T, TBody, TRequestOptions, TResponseExt>;
|
|
25
24
|
header(headers: HeadersInit): this;
|
|
26
25
|
header(name: string, value?: string | number | boolean | null): this;
|
|
27
|
-
param(params: URLSearchParamsInit): this;
|
|
26
|
+
param(params: URLSearchParamsInit | Record<string, string | number | boolean | Date>): this;
|
|
28
27
|
param(name: string, value: any): this;
|
|
29
28
|
observe(observe: HttpObserveType.Body): HttpRequestObservable<TBody, TBody, TRequestOptions, TResponseExt>;
|
|
30
29
|
observe(observe: HttpObserveType.ResponseHeader): HttpRequestObservable<HttpResponse<void> & TResponseExt, TBody, TRequestOptions, TResponseExt>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function urlPath(strings: string[], ...values: any[]): string;
|
package/types/index.d.ts
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
export * from './types.js';
|
|
2
1
|
export * from './core/backend.js';
|
|
3
|
-
export * from './core/client-base.js';
|
|
4
2
|
export * from './core/client-error.js';
|
|
5
3
|
export * from './http/fetch-backend.js';
|
|
6
4
|
export * from './http/http-backend.js';
|
|
7
5
|
export * from './http/http-client.js';
|
|
8
6
|
export * from './http/http-client-base.js';
|
|
9
|
-
export * from './http/http-collection-node.js';
|
|
10
7
|
export * from './http/http-request-observable.js';
|
|
11
8
|
export * from './http/http-response.js';
|
|
12
|
-
export * from './http/http-
|
|
13
|
-
export * from './http/http-storage-node.js';
|
|
9
|
+
export * from './http/http-utils.js';
|
|
14
10
|
export * from './http/enums/http-observable-type.enum.js';
|
|
15
11
|
export * from './http/interfaces/http-event.js';
|
|
16
12
|
export * from './http/interfaces/http-handler.js';
|
package/cjs/core/client-base.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ClientBase = void 0;
|
|
4
|
-
const constants_js_1 = require("../constants.js");
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @class ClientBase
|
|
8
|
-
* @abstract
|
|
9
|
-
*/
|
|
10
|
-
class ClientBase {
|
|
11
|
-
constructor(backend) {
|
|
12
|
-
Object.defineProperty(this, constants_js_1.kBackend, {
|
|
13
|
-
enumerable: false,
|
|
14
|
-
value: backend
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.ClientBase = ClientBase;
|