@opra/client 0.25.5 → 0.26.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 +410 -463
- package/cjs/client.js +49 -234
- package/cjs/constants.js +2 -2
- package/cjs/enums/http-observable-type.enum.js +10 -0
- package/cjs/enums/index.js +4 -0
- package/cjs/impl/collection-node.js +119 -0
- package/cjs/impl/http-request-observable.js +246 -0
- package/cjs/impl/http-request.js +28 -0
- package/cjs/impl/http-service-base.js +16 -0
- package/cjs/impl/singleton-node.js +62 -0
- package/cjs/index.js +12 -6
- package/cjs/interfaces/client-context.interface.js +2 -0
- package/cjs/interfaces/http-event.interface.js +35 -0
- package/cjs/interfaces/http-request-defaults.interface.js +2 -0
- package/cjs/interfaces/index.js +5 -0
- package/cjs/types.js +0 -42
- package/esm/client.js +51 -236
- package/esm/constants.js +1 -1
- package/esm/enums/http-observable-type.enum.js +7 -0
- package/esm/enums/index.js +1 -0
- package/esm/impl/collection-node.js +115 -0
- package/esm/impl/http-request-observable.js +242 -0
- package/esm/impl/http-request.js +24 -0
- package/esm/impl/http-service-base.js +12 -0
- package/esm/impl/singleton-node.js +58 -0
- package/esm/index.js +9 -6
- package/esm/interfaces/client-context.interface.js +1 -0
- package/esm/interfaces/http-event.interface.js +32 -0
- package/esm/interfaces/http-request-defaults.interface.js +1 -0
- package/esm/interfaces/index.js +2 -0
- package/esm/types.js +1 -41
- package/package.json +4 -4
- package/types/client.d.ts +26 -38
- package/types/constants.d.ts +1 -1
- package/types/enums/http-observable-type.enum.d.ts +6 -0
- package/types/enums/index.d.ts +1 -0
- package/types/impl/collection-node.d.ts +66 -0
- package/types/impl/http-request-observable.d.ts +45 -0
- package/types/{http-request.d.ts → impl/http-request.d.ts} +23 -27
- package/types/impl/http-service-base.d.ts +7 -0
- package/types/impl/singleton-node.d.ts +35 -0
- package/types/index.d.ts +9 -6
- package/types/interfaces/client-context.interface.d.ts +13 -0
- package/types/interfaces/http-event.interface.d.ts +88 -0
- package/types/interfaces/http-request-defaults.interface.d.ts +6 -0
- package/types/interfaces/index.d.ts +2 -0
- package/types/types.d.ts +4 -111
- package/cjs/collection-node.js +0 -124
- package/cjs/http-request-observable.js +0 -40
- package/cjs/http-request.js +0 -86
- package/cjs/http-service-base.js +0 -9
- package/cjs/singleton-node.js +0 -68
- package/esm/collection-node.js +0 -120
- package/esm/http-request-observable.js +0 -36
- package/esm/http-request.js +0 -82
- package/esm/http-service-base.js +0 -5
- package/esm/singleton-node.js +0 -64
- package/types/collection-node.d.ts +0 -117
- package/types/http-request-observable.d.ts +0 -23
- package/types/http-service-base.d.ts +0 -5
- package/types/singleton-node.d.ts +0 -65
- /package/cjs/{http-response.js → impl/http-response.js} +0 -0
- /package/esm/{http-response.js → impl/http-response.js} +0 -0
- /package/types/{http-response.d.ts → impl/http-response.d.ts} +0 -0
package/browser.js
CHANGED
|
@@ -7,9 +7,24 @@ var __defProp = Object.defineProperty;
|
|
|
7
7
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
8
|
|
|
9
9
|
// ../../build/client/esm/client.js
|
|
10
|
-
import {
|
|
10
|
+
import { ApiDocumentFactory } from "@opra/common";
|
|
11
|
+
|
|
12
|
+
// ../../build/client/esm/constants.js
|
|
13
|
+
var OPRA_JSON_CONTENT_TYPE_PATTERN = /^application\/\bopra\+json\b/i;
|
|
14
|
+
var JSON_CONTENT_TYPE_PATTERN = /^application\/([\w-]+\+)?\bjson\b/i;
|
|
15
|
+
var TEXT_CONTENT_TYPE_PATTERN = /^text\/.*$/i;
|
|
16
|
+
var FORMDATA_CONTENT_TYPE_PATTERN = /^multipart\/\bform-data\b/i;
|
|
17
|
+
var kClient = Symbol.for("kClient");
|
|
18
|
+
var kContext = Symbol.for("kContext");
|
|
19
|
+
|
|
20
|
+
// ../../build/client/esm/impl/collection-node.js
|
|
21
|
+
import { toArrayDef } from "putil-varhelpers";
|
|
22
|
+
import { OpraURL as OpraURL3 } from "@opra/common";
|
|
23
|
+
|
|
24
|
+
// ../../build/client/esm/impl/http-request-observable.js
|
|
25
|
+
import { lastValueFrom, Observable } from "rxjs";
|
|
11
26
|
import { isReadableStreamLike } from "rxjs/internal/util/isReadableStreamLike";
|
|
12
|
-
import {
|
|
27
|
+
import { isBlob, OpraURL as OpraURL2 } from "@opra/common";
|
|
13
28
|
|
|
14
29
|
// ../../build/client/esm/client-error.js
|
|
15
30
|
var ClientError = class extends Error {
|
|
@@ -29,36 +44,29 @@ var ClientError = class extends Error {
|
|
|
29
44
|
}
|
|
30
45
|
};
|
|
31
46
|
|
|
32
|
-
// ../../build/client/esm/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var kRequest = Symbol.for("kRequest");
|
|
41
|
-
var kContext = Symbol.for("kContext");
|
|
47
|
+
// ../../build/client/esm/enums/http-observable-type.enum.js
|
|
48
|
+
var HttpObserveType;
|
|
49
|
+
(function(HttpObserveType2) {
|
|
50
|
+
HttpObserveType2["ResponseHeader"] = "response-header";
|
|
51
|
+
HttpObserveType2["Response"] = "response";
|
|
52
|
+
HttpObserveType2["Body"] = "body";
|
|
53
|
+
HttpObserveType2["Events"] = "events";
|
|
54
|
+
})(HttpObserveType || (HttpObserveType = {}));
|
|
42
55
|
|
|
43
|
-
// ../../build/client/esm/http-
|
|
44
|
-
|
|
45
|
-
|
|
56
|
+
// ../../build/client/esm/interfaces/http-event.interface.js
|
|
57
|
+
var HttpEventType;
|
|
58
|
+
(function(HttpEventType2) {
|
|
59
|
+
HttpEventType2["Sent"] = "sent";
|
|
60
|
+
HttpEventType2["UploadProgress"] = "upload-progress";
|
|
61
|
+
HttpEventType2["ResponseHeader"] = "response-header";
|
|
62
|
+
HttpEventType2["DownloadProgress"] = "download-progress";
|
|
63
|
+
HttpEventType2["Response"] = "response";
|
|
64
|
+
HttpEventType2["Custom"] = "custom";
|
|
65
|
+
})(HttpEventType || (HttpEventType = {}));
|
|
46
66
|
|
|
47
|
-
// ../../build/client/esm/http-request.js
|
|
67
|
+
// ../../build/client/esm/impl/http-request.js
|
|
48
68
|
import { OpraURL } from "@opra/common";
|
|
49
|
-
var
|
|
50
|
-
"cache",
|
|
51
|
-
"credentials",
|
|
52
|
-
"destination",
|
|
53
|
-
"headers",
|
|
54
|
-
"integrity",
|
|
55
|
-
"keepalive",
|
|
56
|
-
"mode",
|
|
57
|
-
"redirect",
|
|
58
|
-
"referrer",
|
|
59
|
-
"referrerPolicy"
|
|
60
|
-
];
|
|
61
|
-
var HttpRequest = class _HttpRequest {
|
|
69
|
+
var HttpRequest = class {
|
|
62
70
|
static {
|
|
63
71
|
__name(this, "HttpRequest");
|
|
64
72
|
}
|
|
@@ -66,7 +74,6 @@ var HttpRequest = class _HttpRequest {
|
|
|
66
74
|
this.cache = init?.cache || "default";
|
|
67
75
|
this.credentials = init?.credentials || "same-origin";
|
|
68
76
|
this.destination = init?.destination || "";
|
|
69
|
-
this.headers = init?.headers instanceof Headers ? init.headers : new Headers(init?.headers);
|
|
70
77
|
this.integrity = init?.integrity || "";
|
|
71
78
|
this.keepalive = init?.keepalive ?? false;
|
|
72
79
|
this.method = (init?.method || "GET").toUpperCase();
|
|
@@ -77,237 +84,350 @@ var HttpRequest = class _HttpRequest {
|
|
|
77
84
|
this.referrerPolicy = init?.referrerPolicy || "";
|
|
78
85
|
this.signal = init?.signal || new AbortController().signal;
|
|
79
86
|
this.body = init?.body;
|
|
80
|
-
this.
|
|
81
|
-
|
|
82
|
-
const params = new URLSearchParams(init.params);
|
|
83
|
-
params.forEach((v, k) => this.params.set(k, v));
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/** Returns the URL of request as a string. */
|
|
87
|
-
get url() {
|
|
88
|
-
return this.parsedUrl;
|
|
89
|
-
}
|
|
90
|
-
set url(value) {
|
|
91
|
-
this.parsedUrl = value;
|
|
87
|
+
this.url = init?.url instanceof OpraURL ? init.url : new OpraURL(init?.url);
|
|
88
|
+
this.headers = init?.headers instanceof Headers ? init.headers : new Headers(init?.headers);
|
|
92
89
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// ../../build/client/esm/impl/http-request-observable.js
|
|
93
|
+
var directCopyProperties = [
|
|
94
|
+
"cache",
|
|
95
|
+
"credentials",
|
|
96
|
+
"destination",
|
|
97
|
+
"headers",
|
|
98
|
+
"integrity",
|
|
99
|
+
"keepalive",
|
|
100
|
+
"mode",
|
|
101
|
+
"redirect",
|
|
102
|
+
"referrer",
|
|
103
|
+
"referrerPolicy"
|
|
104
|
+
];
|
|
105
|
+
var kIntlObservable = Symbol.for("kIntlObservable");
|
|
106
|
+
var HttpRequestObservable = class extends Observable {
|
|
107
|
+
static {
|
|
108
|
+
__name(this, "HttpRequestObservable");
|
|
96
109
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
110
|
+
constructor(client, init) {
|
|
111
|
+
super((subscriber) => {
|
|
112
|
+
this[kIntlObservable].subscribe((event) => {
|
|
113
|
+
if (event.event === HttpEventType.Response) {
|
|
114
|
+
subscriber.next(event.response.body);
|
|
115
|
+
subscriber.complete();
|
|
116
|
+
}
|
|
117
|
+
}, (error) => subscriber.error(error), () => subscriber.complete());
|
|
118
|
+
});
|
|
119
|
+
Object.defineProperty(this, kClient, {
|
|
120
|
+
enumerable: false,
|
|
121
|
+
value: client
|
|
122
|
+
});
|
|
123
|
+
this.request = new HttpRequest(init);
|
|
124
|
+
if (init?.headers)
|
|
125
|
+
this.header(init.headers);
|
|
126
|
+
this[kIntlObservable] = this._send();
|
|
104
127
|
}
|
|
105
|
-
|
|
128
|
+
httpOptions(options) {
|
|
106
129
|
directCopyProperties.forEach((k) => {
|
|
107
|
-
if (
|
|
108
|
-
this[k] =
|
|
130
|
+
if (options[k] !== void 0)
|
|
131
|
+
this.request[k] = options[k];
|
|
109
132
|
});
|
|
110
|
-
|
|
111
|
-
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
header(arg0, value) {
|
|
136
|
+
const headers = this.request.headers;
|
|
137
|
+
if (typeof arg0 === "object") {
|
|
138
|
+
const h = arg0 instanceof Headers ? arg0 : new Headers(arg0);
|
|
112
139
|
h.forEach((v, k) => {
|
|
113
140
|
if (k.toLowerCase() === "set-cookie") {
|
|
114
|
-
|
|
141
|
+
headers.append(k, v);
|
|
115
142
|
} else
|
|
116
|
-
|
|
143
|
+
headers.set(k, v);
|
|
117
144
|
});
|
|
145
|
+
return this;
|
|
118
146
|
}
|
|
147
|
+
if (value == null)
|
|
148
|
+
headers.delete(arg0);
|
|
149
|
+
else
|
|
150
|
+
headers.append(arg0, String(value));
|
|
151
|
+
return this;
|
|
119
152
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const h = src.headers instanceof Headers ? src.headers : new Headers(src.headers);
|
|
127
|
-
h.forEach((v, k) => {
|
|
128
|
-
if (k.toLowerCase() === "set-cookie") {
|
|
129
|
-
this.headers.append(k, v);
|
|
130
|
-
} else if (!this.headers.has(k))
|
|
131
|
-
this.headers.set(k, v);
|
|
132
|
-
});
|
|
153
|
+
param(arg0, value) {
|
|
154
|
+
const params = this.request.url.searchParams;
|
|
155
|
+
if (typeof arg0 === "object") {
|
|
156
|
+
const h = arg0 instanceof URLSearchParams ? arg0 : new URLSearchParams(arg0);
|
|
157
|
+
h.forEach((v, k) => params.set(k, v));
|
|
158
|
+
return this;
|
|
133
159
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
// ../../build/client/esm/types.js
|
|
138
|
-
var HttpObserveType;
|
|
139
|
-
(function(HttpObserveType2) {
|
|
140
|
-
HttpObserveType2["Response"] = "response";
|
|
141
|
-
HttpObserveType2["Body"] = "body";
|
|
142
|
-
HttpObserveType2["Events"] = "events";
|
|
143
|
-
})(HttpObserveType || (HttpObserveType = {}));
|
|
144
|
-
var HttpEventType;
|
|
145
|
-
(function(HttpEventType2) {
|
|
146
|
-
HttpEventType2["Sent"] = "sent";
|
|
147
|
-
HttpEventType2["UploadProgress"] = "upload-progress";
|
|
148
|
-
HttpEventType2["ResponseHeader"] = "response-header";
|
|
149
|
-
HttpEventType2["DownloadProgress"] = "download-progress";
|
|
150
|
-
HttpEventType2["Response"] = "response";
|
|
151
|
-
HttpEventType2["Custom"] = "custom";
|
|
152
|
-
})(HttpEventType || (HttpEventType = {}));
|
|
153
|
-
|
|
154
|
-
// ../../build/client/esm/http-request-observable.js
|
|
155
|
-
var HttpRequestObservable = class extends Observable {
|
|
156
|
-
static {
|
|
157
|
-
__name(this, "HttpRequestObservable");
|
|
158
|
-
}
|
|
159
|
-
constructor(context, options) {
|
|
160
|
-
super((subscriber) => {
|
|
161
|
-
context.send(options?.observe || HttpObserveType.Body, this[kRequest]).subscribe(subscriber);
|
|
162
|
-
});
|
|
163
|
-
this[kContext] = context;
|
|
164
|
-
this[kRequest] = new HttpRequest(options?.http);
|
|
165
|
-
this.contentId = uid(6);
|
|
166
|
-
}
|
|
167
|
-
header(name, value) {
|
|
168
|
-
const headers = this[kRequest].headers;
|
|
169
|
-
if (Array.isArray(value))
|
|
170
|
-
value.forEach((v) => headers.append(name, String(v)));
|
|
160
|
+
if (value == null)
|
|
161
|
+
params.delete(arg0);
|
|
171
162
|
else
|
|
172
|
-
|
|
163
|
+
params.set(arg0, String(value));
|
|
173
164
|
return this;
|
|
174
165
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
166
|
+
observe(observe) {
|
|
167
|
+
return new Observable((subscriber) => {
|
|
168
|
+
this[kIntlObservable].subscribe((event) => {
|
|
169
|
+
if (observe === HttpObserveType.Events) {
|
|
170
|
+
subscriber.next(event);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (observe === HttpObserveType.ResponseHeader && event.event === HttpEventType.ResponseHeader) {
|
|
174
|
+
subscriber.next(event.response);
|
|
175
|
+
subscriber.complete();
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (observe === HttpObserveType.Body && event.event === HttpEventType.Response) {
|
|
179
|
+
subscriber.next(event.response.body);
|
|
180
|
+
subscriber.complete();
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (event.event === HttpEventType.Response) {
|
|
184
|
+
subscriber.next(event.response);
|
|
185
|
+
subscriber.complete();
|
|
186
|
+
}
|
|
187
|
+
}, (error) => subscriber.error(error), () => subscriber.complete());
|
|
188
|
+
});
|
|
178
189
|
}
|
|
179
|
-
|
|
180
|
-
return
|
|
190
|
+
toPromise() {
|
|
191
|
+
return this.getData();
|
|
181
192
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
193
|
+
getData() {
|
|
194
|
+
return lastValueFrom(this.observe(HttpObserveType.Body));
|
|
195
|
+
}
|
|
196
|
+
getResponse() {
|
|
197
|
+
return lastValueFrom(this.observe(HttpObserveType.Response));
|
|
198
|
+
}
|
|
199
|
+
_send() {
|
|
200
|
+
const request = this.request;
|
|
201
|
+
const clientContext = this[kClient][kContext];
|
|
202
|
+
return new Observable((subscriber) => {
|
|
203
|
+
(async () => {
|
|
204
|
+
this._prepareRequest();
|
|
205
|
+
for (const interceptor of clientContext.requestInterceptors) {
|
|
206
|
+
await interceptor(request);
|
|
207
|
+
}
|
|
208
|
+
subscriber.next({
|
|
209
|
+
request,
|
|
210
|
+
event: HttpEventType.Sent
|
|
211
|
+
});
|
|
212
|
+
const url = new OpraURL2(request.url, clientContext.serviceUrl);
|
|
213
|
+
const fetchResponse = await clientContext.fetch(url.toString(), request);
|
|
214
|
+
const headersResponse = clientContext.createResponse({
|
|
215
|
+
url: fetchResponse.url,
|
|
216
|
+
headers: fetchResponse.headers,
|
|
217
|
+
status: fetchResponse.status,
|
|
218
|
+
statusText: fetchResponse.statusText,
|
|
219
|
+
hasBody: !!fetchResponse.body
|
|
220
|
+
});
|
|
221
|
+
subscriber.next({
|
|
222
|
+
request,
|
|
223
|
+
event: HttpEventType.ResponseHeader,
|
|
224
|
+
response: headersResponse
|
|
225
|
+
});
|
|
226
|
+
const body = fetchResponse.body ? await this._parseBody(fetchResponse) : void 0;
|
|
227
|
+
if (fetchResponse.status >= 400 && fetchResponse.status <= 599) {
|
|
228
|
+
subscriber.error(new ClientError({
|
|
229
|
+
message: fetchResponse.status + " " + fetchResponse.statusText,
|
|
230
|
+
status: fetchResponse.status,
|
|
231
|
+
issues: body.errors
|
|
232
|
+
}));
|
|
233
|
+
subscriber.complete();
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const contentType = fetchResponse.headers.get("Content-Type") || "";
|
|
237
|
+
const responseInit = {
|
|
238
|
+
url: fetchResponse.url,
|
|
239
|
+
headers: fetchResponse.headers,
|
|
240
|
+
status: fetchResponse.status,
|
|
241
|
+
statusText: fetchResponse.statusText,
|
|
242
|
+
body
|
|
243
|
+
};
|
|
244
|
+
if (OPRA_JSON_CONTENT_TYPE_PATTERN.test(contentType)) {
|
|
245
|
+
responseInit.totalCount = body?.totalCount;
|
|
246
|
+
responseInit.affected = body?.affected;
|
|
247
|
+
}
|
|
248
|
+
const response = clientContext.createResponse(responseInit);
|
|
249
|
+
for (const interceptor of clientContext.responseInterceptors) {
|
|
250
|
+
await interceptor(response);
|
|
251
|
+
}
|
|
252
|
+
subscriber.next({
|
|
253
|
+
request,
|
|
254
|
+
event: HttpEventType.Response,
|
|
255
|
+
response
|
|
256
|
+
});
|
|
257
|
+
subscriber.complete();
|
|
258
|
+
})().catch((error) => subscriber.error(error));
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
_prepareRequest() {
|
|
262
|
+
const request = this.request;
|
|
263
|
+
if (request.body) {
|
|
264
|
+
let body;
|
|
265
|
+
let contentType;
|
|
266
|
+
if (typeof request.body === "string" || typeof request.body === "number" || typeof request.body === "boolean") {
|
|
267
|
+
contentType = 'text/plain;charset=UTF-8"';
|
|
268
|
+
body = String(request.body);
|
|
269
|
+
request.headers.delete("Content-Size");
|
|
270
|
+
delete request.duplex;
|
|
271
|
+
} else if (isReadableStreamLike(request.body)) {
|
|
272
|
+
contentType = "application/octet-stream";
|
|
273
|
+
body = request.body;
|
|
274
|
+
request.duplex = "half";
|
|
275
|
+
} else if (Buffer.isBuffer(request.body)) {
|
|
276
|
+
contentType = "application/octet-stream";
|
|
277
|
+
body = request.body;
|
|
278
|
+
request.headers.set("Content-Size", String(request.body.length));
|
|
279
|
+
delete request.duplex;
|
|
280
|
+
} else if (isBlob(request.body)) {
|
|
281
|
+
contentType = request.body.type || "application/octet-stream";
|
|
282
|
+
body = request.body;
|
|
283
|
+
request.headers.set("Content-Size", String(request.body.length));
|
|
284
|
+
delete request.duplex;
|
|
285
|
+
} else {
|
|
286
|
+
contentType = "application/json";
|
|
287
|
+
body = JSON.stringify(request.body);
|
|
288
|
+
request.headers.delete("Content-Size");
|
|
289
|
+
delete request.duplex;
|
|
290
|
+
}
|
|
291
|
+
if (!request.headers.has("Content-Type") && contentType)
|
|
292
|
+
request.headers.set("Content-Type", contentType);
|
|
293
|
+
request.body = body;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
async _parseBody(fetchResponse) {
|
|
297
|
+
let body;
|
|
298
|
+
const contentType = fetchResponse.headers.get("Content-Type") || "";
|
|
299
|
+
if (JSON_CONTENT_TYPE_PATTERN.test(contentType)) {
|
|
300
|
+
body = await fetchResponse.json();
|
|
301
|
+
if (typeof body === "string")
|
|
302
|
+
body = JSON.parse(body);
|
|
303
|
+
} else if (TEXT_CONTENT_TYPE_PATTERN.test(contentType))
|
|
304
|
+
body = await fetchResponse.text();
|
|
305
|
+
else if (FORMDATA_CONTENT_TYPE_PATTERN.test(contentType))
|
|
306
|
+
body = await fetchResponse.formData();
|
|
307
|
+
else {
|
|
308
|
+
const buf = await fetchResponse.arrayBuffer();
|
|
309
|
+
if (buf.byteLength)
|
|
310
|
+
body = buf;
|
|
311
|
+
}
|
|
312
|
+
return body;
|
|
185
313
|
}
|
|
186
314
|
};
|
|
187
315
|
|
|
188
|
-
// ../../build/client/esm/collection-node.js
|
|
316
|
+
// ../../build/client/esm/impl/collection-node.js
|
|
189
317
|
var HttpCollectionNode = class {
|
|
190
318
|
static {
|
|
191
319
|
__name(this, "HttpCollectionNode");
|
|
192
320
|
}
|
|
193
|
-
constructor(
|
|
194
|
-
this
|
|
321
|
+
constructor(client, path) {
|
|
322
|
+
this._client = client;
|
|
323
|
+
this._path = path;
|
|
195
324
|
}
|
|
196
325
|
create(data, options) {
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
request.url.resolve(context.resource);
|
|
203
|
-
request.body = data;
|
|
326
|
+
const observable = new HttpRequestObservable(this._client, {
|
|
327
|
+
method: "POST",
|
|
328
|
+
url: this._path,
|
|
329
|
+
body: data
|
|
330
|
+
});
|
|
204
331
|
if (options?.include)
|
|
205
|
-
|
|
332
|
+
observable.param("include", toArrayDef(options.include, []).join(","));
|
|
206
333
|
if (options?.pick)
|
|
207
|
-
|
|
334
|
+
observable.param("pick", toArrayDef(options.pick, []).join(","));
|
|
208
335
|
if (options?.omit)
|
|
209
|
-
|
|
210
|
-
return
|
|
336
|
+
observable.param("omit", toArrayDef(options.omit, []).join(","));
|
|
337
|
+
return observable;
|
|
211
338
|
}
|
|
212
|
-
delete(id
|
|
213
|
-
if (id == null)
|
|
339
|
+
delete(id) {
|
|
340
|
+
if (id == null || id === "")
|
|
214
341
|
throw new TypeError(`'id' argument must have a value`);
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
return requestHost;
|
|
342
|
+
const url = new OpraURL3();
|
|
343
|
+
url.join({ resource: this._path, key: id });
|
|
344
|
+
return new HttpRequestObservable(this._client, {
|
|
345
|
+
method: "DELETE",
|
|
346
|
+
url
|
|
347
|
+
});
|
|
222
348
|
}
|
|
223
349
|
deleteMany(options) {
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
request.method = "DELETE";
|
|
229
|
-
request.url.join(context.resource);
|
|
350
|
+
const observable = new HttpRequestObservable(this._client, {
|
|
351
|
+
method: "DELETE",
|
|
352
|
+
url: this._path
|
|
353
|
+
});
|
|
230
354
|
if (options?.filter)
|
|
231
|
-
|
|
232
|
-
return
|
|
355
|
+
observable.param("filter", String(options.filter));
|
|
356
|
+
return observable;
|
|
233
357
|
}
|
|
234
358
|
get(id, options) {
|
|
235
|
-
if (id == null)
|
|
359
|
+
if (id == null || id === "")
|
|
236
360
|
throw new TypeError(`'id' argument must have a value`);
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
361
|
+
const url = new OpraURL3();
|
|
362
|
+
url.join({ resource: this._path, key: id });
|
|
363
|
+
const observable = new HttpRequestObservable(this._client, {
|
|
364
|
+
method: "GET",
|
|
365
|
+
url
|
|
366
|
+
});
|
|
243
367
|
if (options?.include)
|
|
244
|
-
|
|
368
|
+
observable.param("include", toArrayDef(options.include, []).join(","));
|
|
245
369
|
if (options?.pick)
|
|
246
|
-
|
|
370
|
+
observable.param("pick", toArrayDef(options.pick, []).join(","));
|
|
247
371
|
if (options?.omit)
|
|
248
|
-
|
|
249
|
-
return
|
|
372
|
+
observable.param("omit", toArrayDef(options.omit, []).join(","));
|
|
373
|
+
return observable;
|
|
250
374
|
}
|
|
251
375
|
findMany(options) {
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
request.method = "GET";
|
|
257
|
-
request.url.join(context.resource);
|
|
376
|
+
const observable = new HttpRequestObservable(this._client, {
|
|
377
|
+
method: "GET",
|
|
378
|
+
url: this._path
|
|
379
|
+
});
|
|
258
380
|
if (options?.include)
|
|
259
|
-
|
|
381
|
+
observable.param("include", toArrayDef(options.include, []).join(","));
|
|
260
382
|
if (options?.pick)
|
|
261
|
-
|
|
383
|
+
observable.param("pick", toArrayDef(options.pick, []).join(","));
|
|
262
384
|
if (options?.omit)
|
|
263
|
-
|
|
385
|
+
observable.param("omit", toArrayDef(options.omit, []).join(","));
|
|
264
386
|
if (options?.sort)
|
|
265
|
-
|
|
387
|
+
observable.param("sort", toArrayDef(options.sort, []).join(","));
|
|
266
388
|
if (options?.filter)
|
|
267
|
-
|
|
389
|
+
observable.param("filter", String(options.filter));
|
|
268
390
|
if (options?.limit != null)
|
|
269
|
-
|
|
391
|
+
observable.param("limit", String(options.limit));
|
|
270
392
|
if (options?.skip != null)
|
|
271
|
-
|
|
393
|
+
observable.param("skip", String(options.skip));
|
|
272
394
|
if (options?.count != null)
|
|
273
|
-
|
|
395
|
+
observable.param("count", String(options.count));
|
|
274
396
|
if (options?.distinct != null)
|
|
275
|
-
|
|
276
|
-
return
|
|
397
|
+
observable.param("distinct", String(options.distinct));
|
|
398
|
+
return observable;
|
|
277
399
|
}
|
|
278
400
|
update(id, data, options) {
|
|
279
401
|
if (id == null)
|
|
280
402
|
throw new TypeError(`'id' argument must have a value`);
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
403
|
+
const url = new OpraURL3();
|
|
404
|
+
url.join({ resource: this._path, key: id });
|
|
405
|
+
const observable = new HttpRequestObservable(this._client, {
|
|
406
|
+
method: "PATCH",
|
|
407
|
+
url,
|
|
408
|
+
body: data
|
|
409
|
+
});
|
|
288
410
|
if (options?.include)
|
|
289
|
-
|
|
411
|
+
observable.param("include", toArrayDef(options.include, []).join(","));
|
|
290
412
|
if (options?.pick)
|
|
291
|
-
|
|
413
|
+
observable.param("pick", toArrayDef(options.pick, []).join(","));
|
|
292
414
|
if (options?.omit)
|
|
293
|
-
|
|
294
|
-
return
|
|
415
|
+
observable.param("omit", toArrayDef(options.omit, []).join(","));
|
|
416
|
+
return observable;
|
|
295
417
|
}
|
|
296
418
|
updateMany(data, options) {
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
request.url.join(context.resource);
|
|
303
|
-
request.body = data;
|
|
419
|
+
const observable = new HttpRequestObservable(this._client, {
|
|
420
|
+
method: "PATCH",
|
|
421
|
+
url: this._path,
|
|
422
|
+
body: data
|
|
423
|
+
});
|
|
304
424
|
if (options?.filter)
|
|
305
|
-
|
|
306
|
-
return
|
|
425
|
+
observable.param("filter", String(options.filter));
|
|
426
|
+
return observable;
|
|
307
427
|
}
|
|
308
428
|
};
|
|
309
429
|
|
|
310
|
-
// ../../build/client/esm/http-response.js
|
|
430
|
+
// ../../build/client/esm/impl/http-response.js
|
|
311
431
|
var HttpResponse = class _HttpResponse {
|
|
312
432
|
static {
|
|
313
433
|
__name(this, "HttpResponse");
|
|
@@ -328,328 +448,153 @@ var HttpResponse = class _HttpResponse {
|
|
|
328
448
|
}
|
|
329
449
|
};
|
|
330
450
|
|
|
331
|
-
// ../../build/client/esm/singleton-node.js
|
|
451
|
+
// ../../build/client/esm/impl/singleton-node.js
|
|
332
452
|
import { toArrayDef as toArrayDef2 } from "putil-varhelpers";
|
|
333
453
|
var HttpSingletonNode = class {
|
|
334
454
|
static {
|
|
335
455
|
__name(this, "HttpSingletonNode");
|
|
336
456
|
}
|
|
337
|
-
constructor(
|
|
338
|
-
this
|
|
457
|
+
constructor(client, path) {
|
|
458
|
+
this._client = client;
|
|
459
|
+
this._path = path;
|
|
339
460
|
}
|
|
340
461
|
create(data, options) {
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
request.url.join(context.resource);
|
|
347
|
-
request.body = data;
|
|
462
|
+
const observable = new HttpRequestObservable(this._client, {
|
|
463
|
+
method: "POST",
|
|
464
|
+
url: this._path,
|
|
465
|
+
body: data
|
|
466
|
+
});
|
|
348
467
|
if (options?.include)
|
|
349
|
-
|
|
468
|
+
observable.param("include", toArrayDef2(options.include, []).join(","));
|
|
350
469
|
if (options?.pick)
|
|
351
|
-
|
|
470
|
+
observable.param("pick", toArrayDef2(options.pick, []).join(","));
|
|
352
471
|
if (options?.omit)
|
|
353
|
-
|
|
354
|
-
return
|
|
355
|
-
}
|
|
356
|
-
delete(
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
request.method = "DELETE";
|
|
362
|
-
request.url.join({ resource: context.resource });
|
|
363
|
-
return requestHost;
|
|
472
|
+
observable.param("omit", toArrayDef2(options.omit, []).join(","));
|
|
473
|
+
return observable;
|
|
474
|
+
}
|
|
475
|
+
delete() {
|
|
476
|
+
return new HttpRequestObservable(this._client, {
|
|
477
|
+
method: "DELETE",
|
|
478
|
+
url: this._path
|
|
479
|
+
});
|
|
364
480
|
}
|
|
365
481
|
get(options) {
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
request.method = "GET";
|
|
371
|
-
request.url.join({ resource: context.resource });
|
|
482
|
+
const observable = new HttpRequestObservable(this._client, {
|
|
483
|
+
method: "GET",
|
|
484
|
+
url: this._path
|
|
485
|
+
});
|
|
372
486
|
if (options?.include)
|
|
373
|
-
|
|
487
|
+
observable.param("include", toArrayDef2(options.include, []).join(","));
|
|
374
488
|
if (options?.pick)
|
|
375
|
-
|
|
489
|
+
observable.param("pick", toArrayDef2(options.pick, []).join(","));
|
|
376
490
|
if (options?.omit)
|
|
377
|
-
|
|
378
|
-
return
|
|
491
|
+
observable.param("omit", toArrayDef2(options.omit, []).join(","));
|
|
492
|
+
return observable;
|
|
379
493
|
}
|
|
380
494
|
update(data, options) {
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
request.url.join({ resource: context.resource });
|
|
387
|
-
request.body = data;
|
|
495
|
+
const observable = new HttpRequestObservable(this._client, {
|
|
496
|
+
method: "PATCH",
|
|
497
|
+
url: this._path,
|
|
498
|
+
body: data
|
|
499
|
+
});
|
|
388
500
|
if (options?.include)
|
|
389
|
-
|
|
501
|
+
observable.param("include", toArrayDef2(options.include, []).join(","));
|
|
390
502
|
if (options?.pick)
|
|
391
|
-
|
|
503
|
+
observable.param("pick", toArrayDef2(options.pick, []).join(","));
|
|
392
504
|
if (options?.omit)
|
|
393
|
-
|
|
394
|
-
return
|
|
505
|
+
observable.param("omit", toArrayDef2(options.omit, []).join(","));
|
|
506
|
+
return observable;
|
|
395
507
|
}
|
|
396
508
|
};
|
|
397
509
|
|
|
398
510
|
// ../../build/client/esm/client.js
|
|
399
|
-
var kAssets = Symbol("kAssets");
|
|
400
511
|
var OpraHttpClient = class {
|
|
401
512
|
static {
|
|
402
513
|
__name(this, "OpraHttpClient");
|
|
403
514
|
}
|
|
404
515
|
constructor(serviceUrl, options) {
|
|
405
|
-
|
|
516
|
+
const context = {
|
|
517
|
+
serviceUrl,
|
|
518
|
+
requestInterceptors: [...options?.requestInterceptors || []],
|
|
519
|
+
responseInterceptors: [...options?.responseInterceptors || []],
|
|
520
|
+
api: options?.api,
|
|
521
|
+
defaults: {
|
|
522
|
+
...options?.defaults,
|
|
523
|
+
headers: options?.defaults?.headers instanceof Headers ? options?.defaults?.headers : new Headers(options?.defaults?.headers),
|
|
524
|
+
params: options?.defaults?.params instanceof URLSearchParams ? options?.defaults?.params : new URLSearchParams(options?.defaults?.params)
|
|
525
|
+
},
|
|
526
|
+
fetch,
|
|
527
|
+
createResponse: (init) => new HttpResponse(init)
|
|
528
|
+
};
|
|
529
|
+
Object.defineProperty(this, kContext, {
|
|
406
530
|
enumerable: false,
|
|
407
|
-
value:
|
|
408
|
-
serviceUrl,
|
|
409
|
-
api: options?.api,
|
|
410
|
-
requestInterceptors: options?.requestInterceptors || [],
|
|
411
|
-
responseInterceptors: options?.responseInterceptors || []
|
|
412
|
-
}
|
|
531
|
+
value: context
|
|
413
532
|
});
|
|
414
|
-
this.defaults = {
|
|
415
|
-
...options?.defaults,
|
|
416
|
-
headers: options?.defaults?.headers instanceof Headers ? options?.defaults?.headers : new Headers(options?.defaults?.headers),
|
|
417
|
-
params: options?.defaults?.params instanceof URLSearchParams ? options?.defaults?.params : new URLSearchParams(options?.defaults?.params)
|
|
418
|
-
};
|
|
419
533
|
}
|
|
420
534
|
get serviceUrl() {
|
|
421
|
-
return this[
|
|
535
|
+
return this[kContext].serviceUrl;
|
|
536
|
+
}
|
|
537
|
+
get api() {
|
|
538
|
+
return this[kContext].api;
|
|
539
|
+
}
|
|
540
|
+
get defaults() {
|
|
541
|
+
return this[kContext].defaults;
|
|
422
542
|
}
|
|
423
543
|
async getMetadata() {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
let promise = this[kAssets].metadataPromise;
|
|
427
|
-
if (promise) {
|
|
544
|
+
let promise = this._metadataPromise;
|
|
545
|
+
if (promise)
|
|
428
546
|
return promise;
|
|
429
|
-
|
|
430
|
-
this[kAssets].metadataPromise = promise = lastValueFrom2(this._sendRequest(HttpObserveType.Body, new HttpRequest({
|
|
547
|
+
const controller = new HttpRequestObservable(this, {
|
|
431
548
|
method: "GET",
|
|
432
549
|
url: "",
|
|
433
|
-
headers:
|
|
434
|
-
})
|
|
550
|
+
headers: { "accept": "application/json" }
|
|
551
|
+
});
|
|
552
|
+
this._metadataPromise = promise = controller.getData();
|
|
435
553
|
return await promise.then(async (body) => {
|
|
436
554
|
if (!body)
|
|
437
555
|
throw new Error(`No response returned.`);
|
|
438
|
-
const api = await
|
|
439
|
-
this[
|
|
556
|
+
const api = await ApiDocumentFactory.createDocument(body);
|
|
557
|
+
this[kContext].api = api;
|
|
440
558
|
return api;
|
|
441
559
|
}).catch((e) => {
|
|
442
560
|
e.message = "Unable to fetch metadata from service url (" + this.serviceUrl + "). " + e.message;
|
|
443
561
|
throw e;
|
|
444
|
-
}).finally(() => delete this
|
|
445
|
-
}
|
|
446
|
-
// batch(requests: HttpRequestHost<any>[]): BatchRequest {
|
|
447
|
-
// this._assertMetadata();
|
|
448
|
-
// return new BatchRequest(request => this._sendRequest('response', request, requests);
|
|
449
|
-
// }
|
|
450
|
-
collection(resourceName) {
|
|
451
|
-
if (typeof resourceName === "function")
|
|
452
|
-
resourceName = resourceName.name;
|
|
453
|
-
const ctx = {
|
|
454
|
-
client: this,
|
|
455
|
-
sourceKind: "Collection",
|
|
456
|
-
endpoint: "",
|
|
457
|
-
resource: resourceName,
|
|
458
|
-
send: (observe, request) => this._sendRequest(observe, request, "Collection", ctx.endpoint, ctx),
|
|
459
|
-
// requestInterceptors: [
|
|
460
|
-
// // Validate resource exists and is a collection resource
|
|
461
|
-
// async () => {
|
|
462
|
-
// const metadata = await this.getMetadata();
|
|
463
|
-
// metadata.getCollection(ctx.sourceName);
|
|
464
|
-
// }
|
|
465
|
-
// ],
|
|
466
|
-
responseInterceptors: []
|
|
467
|
-
};
|
|
468
|
-
return new HttpCollectionNode(ctx);
|
|
469
|
-
}
|
|
470
|
-
singleton(sourceName) {
|
|
471
|
-
if (typeof sourceName === "function")
|
|
472
|
-
sourceName = sourceName.name;
|
|
473
|
-
const ctx = {
|
|
474
|
-
client: this,
|
|
475
|
-
sourceKind: "Singleton",
|
|
476
|
-
endpoint: "",
|
|
477
|
-
resource: sourceName,
|
|
478
|
-
send: (observe, request) => this._sendRequest(observe, request, "Singleton", ctx.endpoint, ctx),
|
|
479
|
-
// requestInterceptors: [
|
|
480
|
-
// // Validate resource exists and is a singleton resource
|
|
481
|
-
// async () => {
|
|
482
|
-
// const metadata = await this.getMetadata();
|
|
483
|
-
// metadata.getSingleton(ctx.sourceName);
|
|
484
|
-
// }
|
|
485
|
-
// ],
|
|
486
|
-
responseInterceptors: []
|
|
487
|
-
};
|
|
488
|
-
return new HttpSingletonNode(ctx);
|
|
562
|
+
}).finally(() => delete this._metadataPromise);
|
|
489
563
|
}
|
|
490
|
-
|
|
491
|
-
return new
|
|
492
|
-
(async () => {
|
|
493
|
-
request.inset(this.defaults);
|
|
494
|
-
const url = new OpraURL2(request.url, this.serviceUrl);
|
|
495
|
-
let body;
|
|
496
|
-
if (request.body) {
|
|
497
|
-
let contentType;
|
|
498
|
-
if (typeof request.body === "string" || typeof request.body === "number" || typeof request.body === "boolean") {
|
|
499
|
-
contentType = 'text/plain;charset=UTF-8"';
|
|
500
|
-
body = String(request.body);
|
|
501
|
-
request.headers.delete("Content-Size");
|
|
502
|
-
delete request.duplex;
|
|
503
|
-
} else if (isReadableStreamLike(request.body)) {
|
|
504
|
-
contentType = "application/octet-stream";
|
|
505
|
-
body = request.body;
|
|
506
|
-
request.duplex = "half";
|
|
507
|
-
} else if (Buffer.isBuffer(request.body)) {
|
|
508
|
-
contentType = "application/octet-stream";
|
|
509
|
-
body = request.body;
|
|
510
|
-
request.headers.set("Content-Size", String(request.body.length));
|
|
511
|
-
delete request.duplex;
|
|
512
|
-
} else if (isBlob(request.body)) {
|
|
513
|
-
contentType = request.body.type || "application/octet-stream";
|
|
514
|
-
body = request.body;
|
|
515
|
-
request.headers.set("Content-Size", String(request.body.length));
|
|
516
|
-
delete request.duplex;
|
|
517
|
-
} else {
|
|
518
|
-
contentType = "application/json";
|
|
519
|
-
body = JSON.stringify(request.body);
|
|
520
|
-
request.headers.delete("Content-Size");
|
|
521
|
-
delete request.duplex;
|
|
522
|
-
}
|
|
523
|
-
if (!request.headers.has("Content-Type") && contentType)
|
|
524
|
-
request.headers.set("Content-Type", contentType);
|
|
525
|
-
request.body = body;
|
|
526
|
-
}
|
|
527
|
-
if (ctx) {
|
|
528
|
-
const requestInterceptors = [
|
|
529
|
-
...this[kAssets].requestInterceptors,
|
|
530
|
-
...ctx.requestInterceptors || []
|
|
531
|
-
];
|
|
532
|
-
for (const interceptor of requestInterceptors) {
|
|
533
|
-
await interceptor(ctx, request);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
if (observe === HttpObserveType.Events)
|
|
537
|
-
subscriber.next({
|
|
538
|
-
observe,
|
|
539
|
-
request,
|
|
540
|
-
event: HttpEventType.Sent
|
|
541
|
-
});
|
|
542
|
-
const response = await this._fetch(url.toString(), request);
|
|
543
|
-
await this._handleResponse(observe, subscriber, request, response, sourceKind, endpoint, ctx);
|
|
544
|
-
})().catch((error) => subscriber.error(error));
|
|
545
|
-
});
|
|
564
|
+
collection(path) {
|
|
565
|
+
return new HttpCollectionNode(this, path);
|
|
546
566
|
}
|
|
547
|
-
|
|
548
|
-
return
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
if (
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
headers,
|
|
559
|
-
status: fetchResponse.status,
|
|
560
|
-
statusText: fetchResponse.statusText,
|
|
561
|
-
hasBody: !!fetchResponse.body
|
|
562
|
-
});
|
|
563
|
-
subscriber.next({
|
|
564
|
-
observe,
|
|
565
|
-
request,
|
|
566
|
-
event: HttpEventType.ResponseHeader,
|
|
567
|
-
response: response2
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
|
-
let body;
|
|
571
|
-
let totalCount;
|
|
572
|
-
let affected;
|
|
573
|
-
const contentType = headers.get("Content-Type") || "";
|
|
574
|
-
if (fetchResponse.body) {
|
|
575
|
-
if (JSON_CONTENT_TYPE_PATTERN.test(contentType)) {
|
|
576
|
-
body = await fetchResponse.json();
|
|
577
|
-
if (typeof body === "string")
|
|
578
|
-
body = JSON.parse(body);
|
|
579
|
-
if (OPRA_JSON_CONTENT_TYPE_PATTERN.test(contentType)) {
|
|
580
|
-
totalCount = body.totalCount;
|
|
581
|
-
affected = body.affected;
|
|
582
|
-
}
|
|
583
|
-
} else if (TEXT_CONTENT_TYPE_PATTERN.test(headers.get("Content-Type") || ""))
|
|
584
|
-
body = await fetchResponse.text();
|
|
585
|
-
else if (FORMDATA_CONTENT_TYPE_PATTERN.test(headers.get("Content-Type") || ""))
|
|
586
|
-
body = await fetchResponse.formData();
|
|
587
|
-
else {
|
|
588
|
-
const buf = await fetchResponse.arrayBuffer();
|
|
589
|
-
if (buf.byteLength)
|
|
590
|
-
body = buf;
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
if (observe === HttpObserveType.Body && fetchResponse.status >= 400 && fetchResponse.status < 600) {
|
|
594
|
-
subscriber.error(new ClientError({
|
|
595
|
-
message: fetchResponse.status + " " + fetchResponse.statusText,
|
|
596
|
-
status: fetchResponse.status,
|
|
597
|
-
issues: body?.errors
|
|
598
|
-
}));
|
|
599
|
-
subscriber.complete();
|
|
600
|
-
return;
|
|
601
|
-
}
|
|
602
|
-
const responseInit = {
|
|
603
|
-
url: fetchResponse.url,
|
|
604
|
-
headers,
|
|
605
|
-
status: fetchResponse.status,
|
|
606
|
-
statusText: fetchResponse.statusText,
|
|
607
|
-
body
|
|
608
|
-
};
|
|
609
|
-
if (totalCount != null)
|
|
610
|
-
responseInit.totalCount = totalCount;
|
|
611
|
-
if (affected != null)
|
|
612
|
-
responseInit.affected = affected;
|
|
613
|
-
const response = this._createResponse(responseInit);
|
|
614
|
-
if (ctx) {
|
|
615
|
-
const responseInterceptors = [
|
|
616
|
-
...this[kAssets].responseInterceptors,
|
|
617
|
-
...ctx.responseInterceptors || []
|
|
618
|
-
];
|
|
619
|
-
for (const interceptor of responseInterceptors) {
|
|
620
|
-
await interceptor(ctx, observe, request);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
if (observe === HttpObserveType.Body) {
|
|
624
|
-
if (OPRA_JSON_CONTENT_TYPE_PATTERN.test(contentType))
|
|
625
|
-
subscriber.next(body.data);
|
|
626
|
-
else
|
|
627
|
-
subscriber.next(body);
|
|
628
|
-
} else {
|
|
629
|
-
if (observe === HttpObserveType.Events)
|
|
630
|
-
subscriber.next({
|
|
631
|
-
observe,
|
|
632
|
-
request,
|
|
633
|
-
event: HttpEventType.Response,
|
|
634
|
-
response
|
|
635
|
-
});
|
|
636
|
-
else
|
|
637
|
-
subscriber.next(response);
|
|
567
|
+
singleton(path) {
|
|
568
|
+
return new HttpSingletonNode(this, path);
|
|
569
|
+
}
|
|
570
|
+
action(path, params) {
|
|
571
|
+
const observable = new HttpRequestObservable(this, {
|
|
572
|
+
method: "GET",
|
|
573
|
+
url: path
|
|
574
|
+
});
|
|
575
|
+
if (params) {
|
|
576
|
+
Object.keys(params).forEach((k) => params[k] = String(params[k]));
|
|
577
|
+
observable.param(params);
|
|
638
578
|
}
|
|
639
|
-
|
|
579
|
+
return observable;
|
|
640
580
|
}
|
|
641
581
|
};
|
|
642
|
-
OpraHttpClient.kAssets = kAssets;
|
|
643
582
|
|
|
644
|
-
// ../../build/client/esm/http-service-base.js
|
|
583
|
+
// ../../build/client/esm/impl/http-service-base.js
|
|
584
|
+
var _a;
|
|
645
585
|
var HttpServiceBase = class {
|
|
646
586
|
static {
|
|
647
587
|
__name(this, "HttpServiceBase");
|
|
648
588
|
}
|
|
649
|
-
constructor(
|
|
650
|
-
this
|
|
589
|
+
constructor(client) {
|
|
590
|
+
this[_a] = {
|
|
591
|
+
resource: {},
|
|
592
|
+
node: null
|
|
593
|
+
};
|
|
594
|
+
this[kClient] = client;
|
|
651
595
|
}
|
|
652
596
|
};
|
|
597
|
+
_a = kContext;
|
|
653
598
|
export {
|
|
654
599
|
ClientError,
|
|
655
600
|
HttpCollectionNode,
|
|
@@ -660,5 +605,7 @@ export {
|
|
|
660
605
|
HttpResponse,
|
|
661
606
|
HttpServiceBase,
|
|
662
607
|
HttpSingletonNode,
|
|
663
|
-
OpraHttpClient
|
|
608
|
+
OpraHttpClient,
|
|
609
|
+
kClient,
|
|
610
|
+
kContext
|
|
664
611
|
};
|