@opra/client 0.21.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 +174 -115
- package/cjs/{http/http-client.js → client.js} +53 -28
- package/cjs/collection-node.js +124 -0
- package/cjs/constants.js +3 -2
- package/cjs/{http/http-request-observable.js → http-request-observable.js} +10 -10
- package/cjs/{http/http-request.js → http-request.js} +8 -10
- package/cjs/{http/http-response.js → http-response.js} +1 -1
- package/cjs/index.js +8 -8
- package/cjs/singleton-node.js +68 -0
- package/cjs/types.js +44 -0
- package/esm/{http/http-client.js → client.js} +52 -27
- package/esm/collection-node.js +120 -0
- package/esm/constants.js +2 -1
- package/esm/{http/http-request-observable.js → http-request-observable.js} +7 -7
- package/esm/{http/http-request.js → http-request.js} +8 -10
- package/esm/{http/http-response.js → http-response.js} +1 -1
- package/esm/index.js +8 -8
- package/esm/singleton-node.js +64 -0
- package/esm/types.js +41 -0
- package/package.json +2 -2
- package/types/{http/http-client.d.ts → client.d.ts} +7 -7
- package/types/{http/http-collection-node.d.ts → collection-node.d.ts} +24 -24
- package/types/constants.d.ts +2 -1
- package/types/{http/http-request-observable.d.ts → http-request-observable.d.ts} +7 -12
- package/types/{http/http-request.d.ts → http-request.d.ts} +7 -8
- package/types/{http/http-response.d.ts → http-response.d.ts} +2 -2
- package/types/{http/http-service-base.d.ts → http-service-base.d.ts} +1 -1
- package/types/index.d.ts +8 -8
- package/types/{http/http-singleton-node.d.ts → singleton-node.d.ts} +15 -15
- package/types/types.d.ts +114 -0
- package/cjs/http/http-collection-node.js +0 -110
- package/cjs/http/http-singleton-node.js +0 -63
- package/cjs/http/http-types.js +0 -2
- package/esm/http/http-collection-node.js +0 -106
- package/esm/http/http-singleton-node.js +0 -59
- package/esm/http/http-types.js +0 -1
- package/types/http/http-types.d.ts +0 -57
- /package/cjs/{http/batch-request.js → batch-request.js} +0 -0
- /package/cjs/{http/http-service-base.js → http-service-base.js} +0 -0
- /package/esm/{http/batch-request.js → batch-request.js} +0 -0
- /package/esm/{http/http-service-base.js → http-service-base.js} +0 -0
- /package/types/{http/batch-request.d.ts → batch-request.d.ts} +0 -0
|
@@ -4,12 +4,13 @@ exports.OpraHttpClient = void 0;
|
|
|
4
4
|
const rxjs_1 = require("rxjs");
|
|
5
5
|
const isReadableStreamLike_1 = require("rxjs/internal/util/isReadableStreamLike");
|
|
6
6
|
const common_1 = require("@opra/common");
|
|
7
|
-
const client_error_js_1 = require("
|
|
8
|
-
const
|
|
9
|
-
const
|
|
7
|
+
const client_error_js_1 = require("./client-error.js");
|
|
8
|
+
const collection_node_js_1 = require("./collection-node.js");
|
|
9
|
+
const constants_js_1 = require("./constants.js");
|
|
10
10
|
const http_request_js_1 = require("./http-request.js");
|
|
11
11
|
const http_response_js_1 = require("./http-response.js");
|
|
12
|
-
const
|
|
12
|
+
const singleton_node_js_1 = require("./singleton-node.js");
|
|
13
|
+
const types_js_1 = require("./types.js");
|
|
13
14
|
const kAssets = Symbol('kAssets');
|
|
14
15
|
class OpraHttpClient {
|
|
15
16
|
constructor(serviceUrl, options) {
|
|
@@ -26,8 +27,8 @@ class OpraHttpClient {
|
|
|
26
27
|
...options?.defaults,
|
|
27
28
|
headers: options?.defaults?.headers instanceof Headers
|
|
28
29
|
? options?.defaults?.headers : new Headers(options?.defaults?.headers),
|
|
29
|
-
params: options?.defaults?.params instanceof
|
|
30
|
-
? options?.defaults?.params : new
|
|
30
|
+
params: options?.defaults?.params instanceof URLSearchParams
|
|
31
|
+
? options?.defaults?.params : new URLSearchParams(options?.defaults?.params)
|
|
31
32
|
};
|
|
32
33
|
}
|
|
33
34
|
get serviceUrl() {
|
|
@@ -40,7 +41,7 @@ class OpraHttpClient {
|
|
|
40
41
|
if (promise) {
|
|
41
42
|
return promise;
|
|
42
43
|
}
|
|
43
|
-
this[kAssets].metadataPromise = promise = (0, rxjs_1.lastValueFrom)(this._sendRequest('
|
|
44
|
+
this[kAssets].metadataPromise = promise = (0, rxjs_1.lastValueFrom)(this._sendRequest('Singleton', 'get', types_js_1.HttpObserveType.Body, new http_request_js_1.HttpRequest({
|
|
44
45
|
method: 'GET',
|
|
45
46
|
url: '$metadata',
|
|
46
47
|
headers: new Headers({ 'accept': 'application/json' })
|
|
@@ -52,7 +53,7 @@ class OpraHttpClient {
|
|
|
52
53
|
return api;
|
|
53
54
|
})
|
|
54
55
|
.catch((e) => {
|
|
55
|
-
e.message = 'Unable to fetch metadata from ' + this.serviceUrl + '. ' + e.message;
|
|
56
|
+
e.message = 'Unable to fetch metadata from service url (' + this.serviceUrl + '). ' + e.message;
|
|
56
57
|
throw e;
|
|
57
58
|
})
|
|
58
59
|
.finally(() => delete this[kAssets].metadataPromise);
|
|
@@ -67,8 +68,10 @@ class OpraHttpClient {
|
|
|
67
68
|
resourceName = resourceName.name;
|
|
68
69
|
const ctx = {
|
|
69
70
|
client: this,
|
|
71
|
+
resourceKind: 'Collection',
|
|
72
|
+
operation: '',
|
|
70
73
|
resourceName,
|
|
71
|
-
send: (observe, request) => this._sendRequest(observe, request, ctx),
|
|
74
|
+
send: (observe, request) => this._sendRequest('Collection', ctx.operation, observe, request, ctx),
|
|
72
75
|
// requestInterceptors: [
|
|
73
76
|
// // Validate resource exists and is a collection resource
|
|
74
77
|
// async () => {
|
|
@@ -78,7 +81,7 @@ class OpraHttpClient {
|
|
|
78
81
|
// ],
|
|
79
82
|
responseInterceptors: []
|
|
80
83
|
};
|
|
81
|
-
return new
|
|
84
|
+
return new collection_node_js_1.HttpCollectionNode(ctx);
|
|
82
85
|
}
|
|
83
86
|
singleton(resourceName) {
|
|
84
87
|
// If name argument is a class, we extract name from the class
|
|
@@ -86,8 +89,10 @@ class OpraHttpClient {
|
|
|
86
89
|
resourceName = resourceName.name;
|
|
87
90
|
const ctx = {
|
|
88
91
|
client: this,
|
|
92
|
+
resourceKind: 'Singleton',
|
|
93
|
+
operation: '',
|
|
89
94
|
resourceName,
|
|
90
|
-
send: (observe, request) => this._sendRequest(observe, request, ctx),
|
|
95
|
+
send: (observe, request) => this._sendRequest('Singleton', ctx.operation, observe, request, ctx),
|
|
91
96
|
// requestInterceptors: [
|
|
92
97
|
// // Validate resource exists and is a singleton resource
|
|
93
98
|
// async () => {
|
|
@@ -97,13 +102,13 @@ class OpraHttpClient {
|
|
|
97
102
|
// ],
|
|
98
103
|
responseInterceptors: []
|
|
99
104
|
};
|
|
100
|
-
return new
|
|
105
|
+
return new singleton_node_js_1.HttpSingletonNode(ctx);
|
|
101
106
|
}
|
|
102
|
-
_sendRequest(observe, request, ctx) {
|
|
107
|
+
_sendRequest(resourceKind, operation, observe, request, ctx) {
|
|
103
108
|
return new rxjs_1.Observable(subscriber => {
|
|
104
109
|
(async () => {
|
|
105
110
|
request.inset(this.defaults);
|
|
106
|
-
const url =
|
|
111
|
+
const url = new common_1.OpraURL(request.url, this.serviceUrl);
|
|
107
112
|
let body;
|
|
108
113
|
if (request.body) {
|
|
109
114
|
let contentType;
|
|
@@ -149,10 +154,14 @@ class OpraHttpClient {
|
|
|
149
154
|
await interceptor(ctx, request);
|
|
150
155
|
}
|
|
151
156
|
}
|
|
152
|
-
if (observe ===
|
|
153
|
-
subscriber.next({
|
|
154
|
-
|
|
155
|
-
|
|
157
|
+
if (observe === types_js_1.HttpObserveType.Events)
|
|
158
|
+
subscriber.next({
|
|
159
|
+
observe,
|
|
160
|
+
request,
|
|
161
|
+
event: types_js_1.HttpEventType.Sent,
|
|
162
|
+
});
|
|
163
|
+
const response = await this._fetch(url.toString(), request);
|
|
164
|
+
await this._handleResponse(resourceKind, operation, observe, subscriber, request, response, ctx);
|
|
156
165
|
})().catch(error => subscriber.error(error));
|
|
157
166
|
});
|
|
158
167
|
}
|
|
@@ -162,9 +171,9 @@ class OpraHttpClient {
|
|
|
162
171
|
_createResponse(init) {
|
|
163
172
|
return new http_response_js_1.HttpResponse(init);
|
|
164
173
|
}
|
|
165
|
-
async _handleResponse(observe, subscriber, request, fetchResponse, ctx) {
|
|
174
|
+
async _handleResponse(resourceKind, operation, observe, subscriber, request, fetchResponse, ctx) {
|
|
166
175
|
const headers = fetchResponse.headers;
|
|
167
|
-
if (observe ===
|
|
176
|
+
if (observe === types_js_1.HttpObserveType.Events) {
|
|
168
177
|
const response = this._createResponse({
|
|
169
178
|
url: fetchResponse.url,
|
|
170
179
|
headers,
|
|
@@ -172,14 +181,21 @@ class OpraHttpClient {
|
|
|
172
181
|
statusText: fetchResponse.statusText,
|
|
173
182
|
hasBody: !!fetchResponse.body
|
|
174
183
|
});
|
|
175
|
-
subscriber.next({
|
|
184
|
+
subscriber.next({
|
|
185
|
+
observe,
|
|
186
|
+
request,
|
|
187
|
+
event: types_js_1.HttpEventType.ResponseHeader,
|
|
188
|
+
response
|
|
189
|
+
});
|
|
176
190
|
}
|
|
177
191
|
let body;
|
|
192
|
+
let totalCount;
|
|
178
193
|
if (fetchResponse.body) {
|
|
179
194
|
if (constants_js_1.JSON_CONTENT_TYPE_PATTERN.test(headers.get('Content-Type') || '')) {
|
|
180
195
|
body = await fetchResponse.json();
|
|
181
196
|
if (typeof body === 'string')
|
|
182
197
|
body = JSON.parse(body);
|
|
198
|
+
totalCount = body.totalCount;
|
|
183
199
|
}
|
|
184
200
|
else if (constants_js_1.TEXT_CONTENT_TYPE_PATTERN.test(headers.get('Content-Type') || ''))
|
|
185
201
|
body = await fetchResponse.text();
|
|
@@ -191,7 +207,7 @@ class OpraHttpClient {
|
|
|
191
207
|
body = buf;
|
|
192
208
|
}
|
|
193
209
|
}
|
|
194
|
-
if (observe ===
|
|
210
|
+
if (observe === types_js_1.HttpObserveType.Body && fetchResponse.status >= 400 && fetchResponse.status < 600) {
|
|
195
211
|
subscriber.error(new client_error_js_1.ClientError({
|
|
196
212
|
message: fetchResponse.status + ' ' + fetchResponse.statusText,
|
|
197
213
|
status: fetchResponse.status,
|
|
@@ -207,8 +223,8 @@ class OpraHttpClient {
|
|
|
207
223
|
statusText: fetchResponse.statusText,
|
|
208
224
|
body
|
|
209
225
|
};
|
|
210
|
-
if (
|
|
211
|
-
responseInit.
|
|
226
|
+
if (totalCount != null)
|
|
227
|
+
responseInit.totalCount = totalCount;
|
|
212
228
|
const response = this._createResponse(responseInit);
|
|
213
229
|
if (ctx) {
|
|
214
230
|
const responseInterceptors = [
|
|
@@ -219,12 +235,21 @@ class OpraHttpClient {
|
|
|
219
235
|
await interceptor(ctx, observe, request);
|
|
220
236
|
}
|
|
221
237
|
}
|
|
222
|
-
if (observe ===
|
|
223
|
-
|
|
238
|
+
if (observe === types_js_1.HttpObserveType.Body) {
|
|
239
|
+
if ((resourceKind === 'Collection' || resourceKind === 'Singleton') &&
|
|
240
|
+
(operation === 'create' || operation === 'get' || operation === 'findMany' || operation === 'update'))
|
|
241
|
+
subscriber.next(body.data);
|
|
242
|
+
else
|
|
243
|
+
subscriber.next(body);
|
|
224
244
|
}
|
|
225
245
|
else {
|
|
226
|
-
if (observe ===
|
|
227
|
-
subscriber.next({
|
|
246
|
+
if (observe === types_js_1.HttpObserveType.Events)
|
|
247
|
+
subscriber.next({
|
|
248
|
+
observe,
|
|
249
|
+
request,
|
|
250
|
+
event: types_js_1.HttpEventType.Response,
|
|
251
|
+
response
|
|
252
|
+
});
|
|
228
253
|
else
|
|
229
254
|
subscriber.next(response);
|
|
230
255
|
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpCollectionNode = void 0;
|
|
4
|
+
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
5
|
+
const constants_js_1 = require("./constants.js");
|
|
6
|
+
const http_request_observable_js_1 = require("./http-request-observable.js");
|
|
7
|
+
class HttpCollectionNode {
|
|
8
|
+
constructor(context) {
|
|
9
|
+
this[constants_js_1.kContext] = context;
|
|
10
|
+
}
|
|
11
|
+
create(data, options) {
|
|
12
|
+
const context = this[constants_js_1.kContext];
|
|
13
|
+
context.operation = 'create';
|
|
14
|
+
const requestHost = new http_request_observable_js_1.HttpRequestObservable(context, options);
|
|
15
|
+
const request = requestHost[constants_js_1.kRequest];
|
|
16
|
+
request.method = 'POST';
|
|
17
|
+
request.url.resolve(context.resourceName);
|
|
18
|
+
request.body = data;
|
|
19
|
+
if (options?.include)
|
|
20
|
+
request.params.set('$include', (0, putil_varhelpers_1.toArrayDef)(options.include, []).join(','));
|
|
21
|
+
if (options?.pick)
|
|
22
|
+
request.params.set('$pick', (0, putil_varhelpers_1.toArrayDef)(options.pick, []).join(','));
|
|
23
|
+
if (options?.omit)
|
|
24
|
+
request.params.set('$omit', (0, putil_varhelpers_1.toArrayDef)(options.omit, []).join(','));
|
|
25
|
+
return requestHost;
|
|
26
|
+
}
|
|
27
|
+
delete(id, options) {
|
|
28
|
+
if (id == null)
|
|
29
|
+
throw new TypeError(`'id' argument must have a value`);
|
|
30
|
+
const context = this[constants_js_1.kContext];
|
|
31
|
+
context.operation = 'delete';
|
|
32
|
+
const requestHost = new http_request_observable_js_1.HttpRequestObservable(context, options);
|
|
33
|
+
const request = requestHost[constants_js_1.kRequest];
|
|
34
|
+
request.method = 'DELETE';
|
|
35
|
+
request.url.join({ resource: context.resourceName, key: id });
|
|
36
|
+
return requestHost;
|
|
37
|
+
}
|
|
38
|
+
deleteMany(options) {
|
|
39
|
+
const context = this[constants_js_1.kContext];
|
|
40
|
+
context.operation = 'deleteMany';
|
|
41
|
+
const requestHost = new http_request_observable_js_1.HttpRequestObservable(context, options);
|
|
42
|
+
const request = requestHost[constants_js_1.kRequest];
|
|
43
|
+
request.method = 'DELETE';
|
|
44
|
+
request.url.join(context.resourceName);
|
|
45
|
+
if (options?.filter)
|
|
46
|
+
request.params.set('$filter', String(options.filter));
|
|
47
|
+
return requestHost;
|
|
48
|
+
}
|
|
49
|
+
get(id, options) {
|
|
50
|
+
if (id == null)
|
|
51
|
+
throw new TypeError(`'id' argument must have a value`);
|
|
52
|
+
const context = this[constants_js_1.kContext];
|
|
53
|
+
context.operation = 'get';
|
|
54
|
+
const requestHost = new http_request_observable_js_1.HttpRequestObservable(context, options);
|
|
55
|
+
const request = requestHost[constants_js_1.kRequest];
|
|
56
|
+
request.method = 'GET';
|
|
57
|
+
request.url.join({ resource: context.resourceName, key: id });
|
|
58
|
+
if (options?.include)
|
|
59
|
+
request.params.set('$include', (0, putil_varhelpers_1.toArrayDef)(options.include, []).join(','));
|
|
60
|
+
if (options?.pick)
|
|
61
|
+
request.params.set('$pick', (0, putil_varhelpers_1.toArrayDef)(options.pick, []).join(','));
|
|
62
|
+
if (options?.omit)
|
|
63
|
+
request.params.set('$omit', (0, putil_varhelpers_1.toArrayDef)(options.omit, []).join(','));
|
|
64
|
+
return requestHost;
|
|
65
|
+
}
|
|
66
|
+
findMany(options) {
|
|
67
|
+
const context = this[constants_js_1.kContext];
|
|
68
|
+
context.operation = 'findMany';
|
|
69
|
+
const requestHost = new http_request_observable_js_1.HttpRequestObservable(context, options);
|
|
70
|
+
const request = requestHost[constants_js_1.kRequest];
|
|
71
|
+
request.method = 'GET';
|
|
72
|
+
request.url.join(context.resourceName);
|
|
73
|
+
if (options?.include)
|
|
74
|
+
request.params.set('$include', (0, putil_varhelpers_1.toArrayDef)(options.include, []).join(','));
|
|
75
|
+
if (options?.pick)
|
|
76
|
+
request.params.set('$pick', (0, putil_varhelpers_1.toArrayDef)(options.pick, []).join(','));
|
|
77
|
+
if (options?.omit)
|
|
78
|
+
request.params.set('$omit', (0, putil_varhelpers_1.toArrayDef)(options.omit, []).join(','));
|
|
79
|
+
if (options?.sort)
|
|
80
|
+
request.params.set('$sort', (0, putil_varhelpers_1.toArrayDef)(options.sort, []).join(','));
|
|
81
|
+
if (options?.filter)
|
|
82
|
+
request.params.set('$filter', String(options.filter));
|
|
83
|
+
if (options?.limit != null)
|
|
84
|
+
request.params.set('$limit', String(options.limit));
|
|
85
|
+
if (options?.skip != null)
|
|
86
|
+
request.params.set('$skip', String(options.skip));
|
|
87
|
+
if (options?.count != null)
|
|
88
|
+
request.params.set('$count', String(options.count));
|
|
89
|
+
if (options?.distinct != null)
|
|
90
|
+
request.params.set('$distinct', String(options.distinct));
|
|
91
|
+
return requestHost;
|
|
92
|
+
}
|
|
93
|
+
update(id, data, options) {
|
|
94
|
+
if (id == null)
|
|
95
|
+
throw new TypeError(`'id' argument must have a value`);
|
|
96
|
+
const context = this[constants_js_1.kContext];
|
|
97
|
+
context.operation = 'update';
|
|
98
|
+
const requestHost = new http_request_observable_js_1.HttpRequestObservable(context, options);
|
|
99
|
+
const request = requestHost[constants_js_1.kRequest];
|
|
100
|
+
request.method = 'PATCH';
|
|
101
|
+
request.url.join({ resource: context.resourceName, key: id });
|
|
102
|
+
request.body = data;
|
|
103
|
+
if (options?.include)
|
|
104
|
+
request.params.set('$include', String(options.include));
|
|
105
|
+
if (options?.pick)
|
|
106
|
+
request.params.set('$pick', String(options.pick));
|
|
107
|
+
if (options?.omit)
|
|
108
|
+
request.params.set('$omit', String(options.omit));
|
|
109
|
+
return requestHost;
|
|
110
|
+
}
|
|
111
|
+
updateMany(data, options) {
|
|
112
|
+
const context = this[constants_js_1.kContext];
|
|
113
|
+
context.operation = 'updateMany';
|
|
114
|
+
const requestHost = new http_request_observable_js_1.HttpRequestObservable(context, options);
|
|
115
|
+
const request = requestHost[constants_js_1.kRequest];
|
|
116
|
+
request.method = 'PATCH';
|
|
117
|
+
request.url.join(context.resourceName);
|
|
118
|
+
request.body = data;
|
|
119
|
+
if (options?.filter)
|
|
120
|
+
request.params.set('$filter', String(options.filter));
|
|
121
|
+
return requestHost;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.HttpCollectionNode = HttpCollectionNode;
|
package/cjs/constants.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.kContext = exports.kRequest = exports.FORMDATA_CONTENT_TYPE_PATTERN = exports.TEXT_CONTENT_TYPE_PATTERN = exports.JSON_CONTENT_TYPE_PATTERN = void 0;
|
|
4
4
|
exports.JSON_CONTENT_TYPE_PATTERN = /^application\/([\w-]+\+)?\bjson\b/i;
|
|
5
5
|
exports.TEXT_CONTENT_TYPE_PATTERN = /^text\/.*$/i;
|
|
6
6
|
exports.FORMDATA_CONTENT_TYPE_PATTERN = /^multipart\/\bform-data\b/i;
|
|
7
|
-
exports.
|
|
7
|
+
exports.kRequest = Symbol.for('kRequest');
|
|
8
|
+
exports.kContext = Symbol.for('kContext');
|
|
@@ -3,20 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.HttpRequestObservable = void 0;
|
|
4
4
|
const rxjs_1 = require("rxjs");
|
|
5
5
|
const common_1 = require("@opra/common");
|
|
6
|
-
const constants_js_1 = require("
|
|
6
|
+
const constants_js_1 = require("./constants.js");
|
|
7
7
|
const http_request_js_1 = require("./http-request.js");
|
|
8
|
-
const
|
|
8
|
+
const types_js_1 = require("./types.js");
|
|
9
9
|
class HttpRequestObservable extends rxjs_1.Observable {
|
|
10
10
|
constructor(context, options) {
|
|
11
11
|
super((subscriber) => {
|
|
12
|
-
context.send(options?.observe ||
|
|
12
|
+
context.send(options?.observe || types_js_1.HttpObserveType.Body, this[constants_js_1.kRequest])
|
|
13
|
+
.subscribe((subscriber));
|
|
13
14
|
});
|
|
14
|
-
this[constants_js_1.
|
|
15
|
-
this[kRequest] = new http_request_js_1.HttpRequest(options?.http);
|
|
15
|
+
this[constants_js_1.kContext] = context;
|
|
16
|
+
this[constants_js_1.kRequest] = new http_request_js_1.HttpRequest(options?.http);
|
|
16
17
|
this.contentId = (0, common_1.uid)(6);
|
|
17
18
|
}
|
|
18
19
|
header(name, value) {
|
|
19
|
-
const headers = this[kRequest].headers;
|
|
20
|
+
const headers = this[constants_js_1.kRequest].headers;
|
|
20
21
|
if (Array.isArray(value))
|
|
21
22
|
value.forEach(v => headers.append(name, String(v)));
|
|
22
23
|
else
|
|
@@ -24,11 +25,12 @@ class HttpRequestObservable extends rxjs_1.Observable {
|
|
|
24
25
|
return this;
|
|
25
26
|
}
|
|
26
27
|
param(name, value) {
|
|
27
|
-
this[kRequest].params.append(name, value);
|
|
28
|
+
this[constants_js_1.kRequest].params.append(name, value);
|
|
28
29
|
return this;
|
|
29
30
|
}
|
|
30
31
|
async fetch(observe) {
|
|
31
|
-
return (0, rxjs_1.lastValueFrom)(this[constants_js_1.
|
|
32
|
+
return (0, rxjs_1.lastValueFrom)(this[constants_js_1.kContext]
|
|
33
|
+
.send(observe || types_js_1.HttpObserveType.Body, this[constants_js_1.kRequest]));
|
|
32
34
|
}
|
|
33
35
|
with(cb) {
|
|
34
36
|
cb(this);
|
|
@@ -36,5 +38,3 @@ class HttpRequestObservable extends rxjs_1.Observable {
|
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
exports.HttpRequestObservable = HttpRequestObservable;
|
|
39
|
-
HttpRequestObservable.kContext = constants_js_1.kHttpClientContext;
|
|
40
|
-
HttpRequestObservable.kRequest = kRequest;
|
|
@@ -21,24 +21,22 @@ class HttpRequest {
|
|
|
21
21
|
this.referrerPolicy = init?.referrerPolicy || '';
|
|
22
22
|
this.signal = init?.signal || new AbortController().signal;
|
|
23
23
|
this.body = init?.body;
|
|
24
|
-
this.
|
|
25
|
-
if (init?.params)
|
|
26
|
-
|
|
24
|
+
this.parsedUrl = new common_1.OpraURL(init?.url);
|
|
25
|
+
if (init?.params) {
|
|
26
|
+
const params = new URLSearchParams(init.params);
|
|
27
|
+
params.forEach((v, k) => this.params.set(k, v));
|
|
28
|
+
}
|
|
27
29
|
}
|
|
28
30
|
/** Returns the URL of request as a string. */
|
|
29
31
|
get url() {
|
|
30
|
-
return this.
|
|
32
|
+
return this.parsedUrl;
|
|
31
33
|
}
|
|
32
34
|
set url(value) {
|
|
33
|
-
this.
|
|
35
|
+
this.parsedUrl = value;
|
|
34
36
|
}
|
|
35
37
|
/** Returns the searchParams of the URL as OpraURLSearchParams */
|
|
36
38
|
get params() {
|
|
37
|
-
return this.
|
|
38
|
-
}
|
|
39
|
-
/** Returns the path part of URL as OpraURLPath */
|
|
40
|
-
get path() {
|
|
41
|
-
return this.urlInstance.path;
|
|
39
|
+
return this.parsedUrl.searchParams;
|
|
42
40
|
}
|
|
43
41
|
clone(...update) {
|
|
44
42
|
const out = new HttpRequest();
|
|
@@ -15,7 +15,7 @@ class HttpResponse {
|
|
|
15
15
|
this.ok = this.status >= 200 && this.status < 300;
|
|
16
16
|
this.body = init?.body;
|
|
17
17
|
this.hasBody = init?.body != null || !!init?.hasBody;
|
|
18
|
-
this.
|
|
18
|
+
this.totalCount = init?.totalCount;
|
|
19
19
|
}
|
|
20
20
|
clone(update) {
|
|
21
21
|
return new HttpResponse({ ...this, ...update });
|
package/cjs/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./client.js"), exports);
|
|
4
5
|
tslib_1.__exportStar(require("./client-error.js"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./
|
|
6
|
-
tslib_1.__exportStar(require("./http
|
|
7
|
-
tslib_1.__exportStar(require("./http
|
|
8
|
-
tslib_1.__exportStar(require("./http
|
|
9
|
-
tslib_1.__exportStar(require("./http
|
|
10
|
-
tslib_1.__exportStar(require("./
|
|
11
|
-
tslib_1.__exportStar(require("./
|
|
12
|
-
tslib_1.__exportStar(require("./http/http-types.js"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./collection-node.js"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./http-request.js"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./http-request-observable.js"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./http-response.js"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./http-service-base.js"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./singleton-node.js"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./types.js"), exports);
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpSingletonNode = void 0;
|
|
4
|
+
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
5
|
+
const constants_js_1 = require("./constants.js");
|
|
6
|
+
const http_request_observable_js_1 = require("./http-request-observable.js");
|
|
7
|
+
class HttpSingletonNode {
|
|
8
|
+
constructor(context) {
|
|
9
|
+
this[constants_js_1.kContext] = context;
|
|
10
|
+
}
|
|
11
|
+
create(data, options) {
|
|
12
|
+
const context = this[constants_js_1.kContext];
|
|
13
|
+
context.operation = 'create';
|
|
14
|
+
const requestHost = new http_request_observable_js_1.HttpRequestObservable(context, options);
|
|
15
|
+
const request = requestHost[constants_js_1.kRequest];
|
|
16
|
+
request.method = 'POST';
|
|
17
|
+
request.url.join(context.resourceName);
|
|
18
|
+
request.body = data;
|
|
19
|
+
if (options?.include)
|
|
20
|
+
request.params.set('$include', (0, putil_varhelpers_1.toArrayDef)(options.include, []).join(','));
|
|
21
|
+
if (options?.pick)
|
|
22
|
+
request.params.set('$pick', (0, putil_varhelpers_1.toArrayDef)(options.pick, []).join(','));
|
|
23
|
+
if (options?.omit)
|
|
24
|
+
request.params.set('$omit', (0, putil_varhelpers_1.toArrayDef)(options.omit, []).join(','));
|
|
25
|
+
return requestHost;
|
|
26
|
+
}
|
|
27
|
+
delete(options) {
|
|
28
|
+
const context = this[constants_js_1.kContext];
|
|
29
|
+
context.operation = 'delete';
|
|
30
|
+
const requestHost = new http_request_observable_js_1.HttpRequestObservable(context, options);
|
|
31
|
+
const request = requestHost[constants_js_1.kRequest];
|
|
32
|
+
request.method = 'DELETE';
|
|
33
|
+
request.url.join({ resource: context.resourceName });
|
|
34
|
+
return requestHost;
|
|
35
|
+
}
|
|
36
|
+
get(options) {
|
|
37
|
+
const context = this[constants_js_1.kContext];
|
|
38
|
+
context.operation = 'get';
|
|
39
|
+
const requestHost = new http_request_observable_js_1.HttpRequestObservable(context, options);
|
|
40
|
+
const request = requestHost[constants_js_1.kRequest];
|
|
41
|
+
request.method = 'GET';
|
|
42
|
+
request.url.join({ resource: context.resourceName });
|
|
43
|
+
if (options?.include)
|
|
44
|
+
request.params.set('$include', (0, putil_varhelpers_1.toArrayDef)(options.include, []).join(','));
|
|
45
|
+
if (options?.pick)
|
|
46
|
+
request.params.set('$pick', (0, putil_varhelpers_1.toArrayDef)(options.pick, []).join(','));
|
|
47
|
+
if (options?.omit)
|
|
48
|
+
request.params.set('$omit', (0, putil_varhelpers_1.toArrayDef)(options.omit, []).join(','));
|
|
49
|
+
return requestHost;
|
|
50
|
+
}
|
|
51
|
+
update(data, options) {
|
|
52
|
+
const context = this[constants_js_1.kContext];
|
|
53
|
+
context.operation = 'update';
|
|
54
|
+
const requestHost = new http_request_observable_js_1.HttpRequestObservable(context, options);
|
|
55
|
+
const request = requestHost[constants_js_1.kRequest];
|
|
56
|
+
request.method = 'PATCH';
|
|
57
|
+
request.url.join({ resource: context.resourceName });
|
|
58
|
+
request.body = data;
|
|
59
|
+
if (options?.include)
|
|
60
|
+
request.params.set('$include', (0, putil_varhelpers_1.toArrayDef)(options.include, []).join(','));
|
|
61
|
+
if (options?.pick)
|
|
62
|
+
request.params.set('$pick', (0, putil_varhelpers_1.toArrayDef)(options.pick, []).join(','));
|
|
63
|
+
if (options?.omit)
|
|
64
|
+
request.params.set('$omit', (0, putil_varhelpers_1.toArrayDef)(options.omit, []).join(','));
|
|
65
|
+
return requestHost;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.HttpSingletonNode = HttpSingletonNode;
|
package/cjs/types.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpEventType = exports.HttpObserveType = void 0;
|
|
4
|
+
/* **********************
|
|
5
|
+
* Enums
|
|
6
|
+
*********************** */
|
|
7
|
+
var HttpObserveType;
|
|
8
|
+
(function (HttpObserveType) {
|
|
9
|
+
HttpObserveType["Response"] = "response";
|
|
10
|
+
HttpObserveType["Body"] = "body";
|
|
11
|
+
HttpObserveType["Events"] = "events";
|
|
12
|
+
})(HttpObserveType || (exports.HttpObserveType = HttpObserveType = {}));
|
|
13
|
+
/**
|
|
14
|
+
* Type enumeration for the different kinds of `HttpEvent`.
|
|
15
|
+
*/
|
|
16
|
+
var HttpEventType;
|
|
17
|
+
(function (HttpEventType) {
|
|
18
|
+
/**
|
|
19
|
+
* The request was sent out over the wire.
|
|
20
|
+
*/
|
|
21
|
+
HttpEventType["Sent"] = "sent";
|
|
22
|
+
/**
|
|
23
|
+
* An upload progress event was received.
|
|
24
|
+
*
|
|
25
|
+
* Note: The `FetchBackend` doesn't support progress report on uploads.
|
|
26
|
+
*/
|
|
27
|
+
HttpEventType["UploadProgress"] = "upload-progress";
|
|
28
|
+
/**
|
|
29
|
+
* The response status code and headers were received.
|
|
30
|
+
*/
|
|
31
|
+
HttpEventType["ResponseHeader"] = "response-header";
|
|
32
|
+
/**
|
|
33
|
+
* A download progress event was received.
|
|
34
|
+
*/
|
|
35
|
+
HttpEventType["DownloadProgress"] = "download-progress";
|
|
36
|
+
/**
|
|
37
|
+
* The full response including the body was received.
|
|
38
|
+
*/
|
|
39
|
+
HttpEventType["Response"] = "response";
|
|
40
|
+
/**
|
|
41
|
+
* A custom event from an interceptor or a backend.
|
|
42
|
+
*/
|
|
43
|
+
HttpEventType["Custom"] = "custom";
|
|
44
|
+
})(HttpEventType || (exports.HttpEventType = HttpEventType = {}));
|