@opra/client 0.29.0 → 0.29.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 +1 -708
- package/cjs/http/http-client-base.js +14 -2
- package/cjs/index.js +0 -1
- package/esm/http/http-client-base.js +15 -3
- package/esm/index.js +0 -1
- package/package.json +2 -2
- package/types/http/http-client-base.d.ts +3 -1
- package/types/index.d.ts +0 -1
- package/cjs/http/http-service-base.js +0 -16
- package/esm/http/http-service-base.js +0 -12
- package/types/http/http-service-base.d.ts +0 -7
package/browser.js
CHANGED
|
@@ -3,711 +3,4 @@
|
|
|
3
3
|
* http://www.panates.com
|
|
4
4
|
*****************************************/
|
|
5
5
|
|
|
6
|
-
var __defProp = Object.defineProperty;
|
|
7
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
-
|
|
9
|
-
// ../../build/client/esm/core/backend.js
|
|
10
|
-
var Backend = class {
|
|
11
|
-
static {
|
|
12
|
-
__name(this, "Backend");
|
|
13
|
-
}
|
|
14
|
-
constructor(options) {
|
|
15
|
-
this.api = options?.api;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
// ../../build/client/esm/constants.js
|
|
20
|
-
var kClient = Symbol.for("kClient");
|
|
21
|
-
var kBackend = Symbol.for("kBackend");
|
|
22
|
-
var kContext = Symbol.for("kContext");
|
|
23
|
-
|
|
24
|
-
// ../../build/client/esm/core/client-base.js
|
|
25
|
-
var ClientBase = class {
|
|
26
|
-
static {
|
|
27
|
-
__name(this, "ClientBase");
|
|
28
|
-
}
|
|
29
|
-
constructor(backend) {
|
|
30
|
-
Object.defineProperty(this, kBackend, {
|
|
31
|
-
enumerable: false,
|
|
32
|
-
value: backend
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// ../../build/client/esm/core/client-error.js
|
|
38
|
-
var ClientError = class extends Error {
|
|
39
|
-
static {
|
|
40
|
-
__name(this, "ClientError");
|
|
41
|
-
}
|
|
42
|
-
constructor(init, cause) {
|
|
43
|
-
super(init.message);
|
|
44
|
-
this.cause = cause;
|
|
45
|
-
this.issues = init.issues || [];
|
|
46
|
-
this.status = init.status;
|
|
47
|
-
if (cause) {
|
|
48
|
-
this.cause = cause;
|
|
49
|
-
if (cause.stack)
|
|
50
|
-
this.stack = cause.stack;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// ../../build/client/esm/http/fetch-backend.js
|
|
56
|
-
import { Observable } from "rxjs";
|
|
57
|
-
import { isReadableStreamLike } from "rxjs/internal/util/isReadableStreamLike";
|
|
58
|
-
import typeIs from "@browsery/type-is";
|
|
59
|
-
import { isBlob } from "@opra/common";
|
|
60
|
-
|
|
61
|
-
// ../../build/client/esm/http/http-backend.js
|
|
62
|
-
var HttpBackend = class extends Backend {
|
|
63
|
-
static {
|
|
64
|
-
__name(this, "HttpBackend");
|
|
65
|
-
}
|
|
66
|
-
constructor(serviceUrl, options) {
|
|
67
|
-
super(options);
|
|
68
|
-
this.serviceUrl = serviceUrl;
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
// ../../build/client/esm/http/http-response.js
|
|
73
|
-
var HttpResponse = class _HttpResponse {
|
|
74
|
-
static {
|
|
75
|
-
__name(this, "HttpResponse");
|
|
76
|
-
}
|
|
77
|
-
constructor(init) {
|
|
78
|
-
this.hasBody = false;
|
|
79
|
-
this.headers = init?.headers instanceof Headers ? init?.headers : new Headers(init?.headers);
|
|
80
|
-
this.status = init?.status || 200;
|
|
81
|
-
this.statusText = init?.statusText || "OK";
|
|
82
|
-
this.url = init?.url || null;
|
|
83
|
-
this.ok = this.status >= 200 && this.status < 300;
|
|
84
|
-
this.body = init?.body;
|
|
85
|
-
this.hasBody = init?.body != null || !!init?.hasBody;
|
|
86
|
-
this.contentType = (this.headers.get("content-type") || "").split(";")[0];
|
|
87
|
-
}
|
|
88
|
-
clone(update) {
|
|
89
|
-
return new _HttpResponse({ ...this, ...update });
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
// ../../build/client/esm/http/interfaces/http-event.js
|
|
94
|
-
var HttpEventType;
|
|
95
|
-
(function(HttpEventType2) {
|
|
96
|
-
HttpEventType2["Sent"] = "Sent";
|
|
97
|
-
HttpEventType2["UploadProgress"] = "UploadProgress";
|
|
98
|
-
HttpEventType2["ResponseHeader"] = "ResponseHeader";
|
|
99
|
-
HttpEventType2["DownloadProgress"] = "DownloadProgress";
|
|
100
|
-
HttpEventType2["Response"] = "Response";
|
|
101
|
-
HttpEventType2["User"] = "User";
|
|
102
|
-
})(HttpEventType || (HttpEventType = {}));
|
|
103
|
-
|
|
104
|
-
// ../../build/client/esm/http/fetch-backend.js
|
|
105
|
-
var FetchBackend = class extends HttpBackend {
|
|
106
|
-
static {
|
|
107
|
-
__name(this, "FetchBackend");
|
|
108
|
-
}
|
|
109
|
-
constructor(serviceUrl, options) {
|
|
110
|
-
super(serviceUrl, options);
|
|
111
|
-
this.interceptors = Array.from(/* @__PURE__ */ new Set([...options?.interceptors || []]));
|
|
112
|
-
this.defaults = {
|
|
113
|
-
...options?.defaults,
|
|
114
|
-
headers: options?.defaults?.headers instanceof Headers ? options?.defaults?.headers : new Headers(options?.defaults?.headers),
|
|
115
|
-
params: options?.defaults?.params instanceof URLSearchParams ? options?.defaults?.params : new URLSearchParams(options?.defaults?.params)
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
handle(init) {
|
|
119
|
-
return new Observable((subscriber) => {
|
|
120
|
-
(async () => {
|
|
121
|
-
let request = this.prepareRequest(init);
|
|
122
|
-
if (request.body && init.reportProgress) {
|
|
123
|
-
const stream = request.body;
|
|
124
|
-
const contentLength = request.headers.get("content-length") || "0";
|
|
125
|
-
const total = parseInt(contentLength, 10) || 0;
|
|
126
|
-
let loaded = 0;
|
|
127
|
-
const progressTrackingStream = new TransformStream({
|
|
128
|
-
transform(chunk, controller) {
|
|
129
|
-
controller.enqueue(chunk);
|
|
130
|
-
loaded += chunk.byteLength;
|
|
131
|
-
subscriber.next({
|
|
132
|
-
type: HttpEventType.UploadProgress,
|
|
133
|
-
request,
|
|
134
|
-
total,
|
|
135
|
-
loaded
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
request = new Request(request.url, {
|
|
140
|
-
cache: request.cache,
|
|
141
|
-
credentials: request.credentials,
|
|
142
|
-
headers: request.headers,
|
|
143
|
-
integrity: request.integrity,
|
|
144
|
-
keepalive: request.keepalive,
|
|
145
|
-
method: request.method,
|
|
146
|
-
mode: request.mode,
|
|
147
|
-
redirect: request.redirect,
|
|
148
|
-
referrer: request.referrer,
|
|
149
|
-
referrerPolicy: request.referrerPolicy,
|
|
150
|
-
signal: request.signal,
|
|
151
|
-
body: stream.pipeThrough(progressTrackingStream),
|
|
152
|
-
window: init.window,
|
|
153
|
-
...{
|
|
154
|
-
// undici library requires
|
|
155
|
-
duplex: "half"
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
const fetchPromise = this.send(request);
|
|
160
|
-
subscriber.next({
|
|
161
|
-
request,
|
|
162
|
-
type: HttpEventType.Sent
|
|
163
|
-
});
|
|
164
|
-
const fetchResponse = await fetchPromise;
|
|
165
|
-
const headersResponse = this.createResponse({
|
|
166
|
-
url: fetchResponse.url,
|
|
167
|
-
headers: fetchResponse.headers,
|
|
168
|
-
status: fetchResponse.status,
|
|
169
|
-
statusText: fetchResponse.statusText,
|
|
170
|
-
hasBody: !!fetchResponse.body
|
|
171
|
-
});
|
|
172
|
-
subscriber.next({
|
|
173
|
-
request,
|
|
174
|
-
type: HttpEventType.ResponseHeader,
|
|
175
|
-
response: headersResponse
|
|
176
|
-
});
|
|
177
|
-
let body;
|
|
178
|
-
if (fetchResponse.body) {
|
|
179
|
-
if (init.reportProgress) {
|
|
180
|
-
const fetchBody = fetchResponse.body;
|
|
181
|
-
const contentLength = fetchResponse.headers.get("content-length") || "0";
|
|
182
|
-
const total = parseInt(contentLength, 10) || 0;
|
|
183
|
-
let loaded = 0;
|
|
184
|
-
const res = new Response(new ReadableStream({
|
|
185
|
-
async start(controller) {
|
|
186
|
-
const reader = fetchBody.getReader();
|
|
187
|
-
for (; ; ) {
|
|
188
|
-
const { done, value } = await reader.read();
|
|
189
|
-
if (done)
|
|
190
|
-
break;
|
|
191
|
-
loaded += value.byteLength;
|
|
192
|
-
controller.enqueue(value);
|
|
193
|
-
subscriber.next({
|
|
194
|
-
type: HttpEventType.DownloadProgress,
|
|
195
|
-
request,
|
|
196
|
-
total,
|
|
197
|
-
loaded
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
controller.close();
|
|
201
|
-
}
|
|
202
|
-
}));
|
|
203
|
-
body = await this.parseBody(res);
|
|
204
|
-
} else {
|
|
205
|
-
body = await this.parseBody(fetchResponse);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
const response = this.createResponse({
|
|
209
|
-
url: fetchResponse.url,
|
|
210
|
-
headers: fetchResponse.headers,
|
|
211
|
-
status: fetchResponse.status,
|
|
212
|
-
statusText: fetchResponse.statusText,
|
|
213
|
-
body
|
|
214
|
-
});
|
|
215
|
-
subscriber.next({
|
|
216
|
-
request,
|
|
217
|
-
type: HttpEventType.Response,
|
|
218
|
-
response
|
|
219
|
-
});
|
|
220
|
-
subscriber.complete();
|
|
221
|
-
})().catch((error) => subscriber.error(error));
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
send(request) {
|
|
225
|
-
return fetch(request);
|
|
226
|
-
}
|
|
227
|
-
prepareRequest(init) {
|
|
228
|
-
const headers = init.headers || new Headers();
|
|
229
|
-
const requestInit = {
|
|
230
|
-
...init,
|
|
231
|
-
headers
|
|
232
|
-
};
|
|
233
|
-
const body = requestInit.body;
|
|
234
|
-
if (body) {
|
|
235
|
-
let contentType;
|
|
236
|
-
if (typeof body === "string" || typeof body === "number" || typeof body === "boolean") {
|
|
237
|
-
contentType = 'text/plain; charset="UTF-8"';
|
|
238
|
-
requestInit.body = new Blob([String(body)], { type: contentType });
|
|
239
|
-
headers.set("Content-Length", String(requestInit.body.size));
|
|
240
|
-
delete requestInit.duplex;
|
|
241
|
-
} else if (isReadableStreamLike(body)) {
|
|
242
|
-
contentType = "application/octet-stream";
|
|
243
|
-
requestInit.duplex = "half";
|
|
244
|
-
} else if (Buffer.isBuffer(body)) {
|
|
245
|
-
contentType = "application/octet-stream";
|
|
246
|
-
headers.set("Content-Length", String(body.length));
|
|
247
|
-
delete requestInit.duplex;
|
|
248
|
-
} else if (isBlob(body)) {
|
|
249
|
-
contentType = body.type || "application/octet-stream";
|
|
250
|
-
headers.set("Content-Length", String(body.size));
|
|
251
|
-
delete requestInit.duplex;
|
|
252
|
-
} else {
|
|
253
|
-
contentType = 'application/json;charset="UTF-8"';
|
|
254
|
-
requestInit.body = new Blob([JSON.stringify(body)], { type: contentType });
|
|
255
|
-
headers.set("Content-Length", String(requestInit.body.size));
|
|
256
|
-
delete requestInit.duplex;
|
|
257
|
-
}
|
|
258
|
-
if (contentType && !headers.has("Content-Type"))
|
|
259
|
-
headers.set("Content-Type", contentType);
|
|
260
|
-
}
|
|
261
|
-
return new Request(requestInit.url.toString(), requestInit);
|
|
262
|
-
}
|
|
263
|
-
createResponse(init) {
|
|
264
|
-
return new HttpResponse(init);
|
|
265
|
-
}
|
|
266
|
-
async parseBody(fetchResponse) {
|
|
267
|
-
let body;
|
|
268
|
-
const contentType = fetchResponse.headers.get("Content-Type") || "";
|
|
269
|
-
if (typeIs.is(contentType, ["json", "application/*+json"])) {
|
|
270
|
-
body = await fetchResponse.json();
|
|
271
|
-
if (typeof body === "string")
|
|
272
|
-
body = JSON.parse(body);
|
|
273
|
-
} else if (typeIs.is(contentType, ["text"]))
|
|
274
|
-
body = await fetchResponse.text();
|
|
275
|
-
else if (typeIs.is(contentType, ["multipart"]))
|
|
276
|
-
body = await fetchResponse.formData();
|
|
277
|
-
else {
|
|
278
|
-
const buf = await fetchResponse.arrayBuffer();
|
|
279
|
-
if (buf.byteLength)
|
|
280
|
-
body = buf;
|
|
281
|
-
}
|
|
282
|
-
return body;
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
// ../../build/client/esm/http/http-client-base.js
|
|
287
|
-
import { ApiDocumentFactory } from "@opra/common";
|
|
288
|
-
|
|
289
|
-
// ../../build/client/esm/http/http-collection-node.js
|
|
290
|
-
import { toArrayDef } from "putil-varhelpers";
|
|
291
|
-
import { OpraURL as OpraURL2 } from "@opra/common";
|
|
292
|
-
|
|
293
|
-
// ../../build/client/esm/http/http-request-observable.js
|
|
294
|
-
import { lastValueFrom, Observable as Observable2 } from "rxjs";
|
|
295
|
-
import typeIs2 from "@browsery/type-is";
|
|
296
|
-
import { OpraURL } from "@opra/common";
|
|
297
|
-
|
|
298
|
-
// ../../build/client/esm/http/enums/http-observable-type.enum.js
|
|
299
|
-
var HttpObserveType;
|
|
300
|
-
(function(HttpObserveType2) {
|
|
301
|
-
HttpObserveType2["ResponseHeader"] = "response-header";
|
|
302
|
-
HttpObserveType2["Response"] = "response";
|
|
303
|
-
HttpObserveType2["Body"] = "body";
|
|
304
|
-
HttpObserveType2["Events"] = "events";
|
|
305
|
-
})(HttpObserveType || (HttpObserveType = {}));
|
|
306
|
-
|
|
307
|
-
// ../../build/client/esm/http/http-interceptor-handler.js
|
|
308
|
-
var HttpInterceptorHandler = class {
|
|
309
|
-
static {
|
|
310
|
-
__name(this, "HttpInterceptorHandler");
|
|
311
|
-
}
|
|
312
|
-
constructor(interceptors, finalHandler) {
|
|
313
|
-
this.chain = interceptors.reduceRight((chainTailFn, interceptor) => (initialRequest, handler) => interceptor.intercept(initialRequest, {
|
|
314
|
-
handle: (downstreamRequest) => chainTailFn(downstreamRequest, handler)
|
|
315
|
-
}), chainEnd);
|
|
316
|
-
this.finalHandler = finalHandler;
|
|
317
|
-
}
|
|
318
|
-
handle(initialRequest) {
|
|
319
|
-
return this.chain(initialRequest, (req) => this.finalHandler.handle(req));
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
function chainEnd(req, handler) {
|
|
323
|
-
return handler(req);
|
|
324
|
-
}
|
|
325
|
-
__name(chainEnd, "chainEnd");
|
|
326
|
-
|
|
327
|
-
// ../../build/client/esm/http/http-request-observable.js
|
|
328
|
-
var HttpRequestObservable = class _HttpRequestObservable extends Observable2 {
|
|
329
|
-
static {
|
|
330
|
-
__name(this, "HttpRequestObservable");
|
|
331
|
-
}
|
|
332
|
-
constructor(backend, init) {
|
|
333
|
-
super((subscriber) => {
|
|
334
|
-
const observe = this[kContext].observe;
|
|
335
|
-
new HttpInterceptorHandler(backend.interceptors || [], this[kBackend]).handle(this[kContext]).subscribe({
|
|
336
|
-
next(event) {
|
|
337
|
-
if (observe === HttpObserveType.Events) {
|
|
338
|
-
subscriber.next(event);
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
if (observe === HttpObserveType.ResponseHeader && event.type === HttpEventType.ResponseHeader) {
|
|
342
|
-
subscriber.next(event.response);
|
|
343
|
-
subscriber.complete();
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
if (event.type === HttpEventType.Response) {
|
|
347
|
-
const { response } = event;
|
|
348
|
-
if (observe === HttpObserveType.Response) {
|
|
349
|
-
subscriber.next(response);
|
|
350
|
-
subscriber.complete();
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
const isOpraResponse = typeIs2.is(event.response.contentType || "", ["application/opra+json"]);
|
|
354
|
-
if (response.status >= 400 && response.status < 600) {
|
|
355
|
-
subscriber.error(new ClientError({
|
|
356
|
-
message: response.status + " " + response.statusText,
|
|
357
|
-
status: response.status,
|
|
358
|
-
issues: isOpraResponse ? response.body.errors : void 0
|
|
359
|
-
}));
|
|
360
|
-
subscriber.complete();
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
subscriber.next(event.response.body);
|
|
364
|
-
subscriber.complete();
|
|
365
|
-
}
|
|
366
|
-
},
|
|
367
|
-
error(error) {
|
|
368
|
-
subscriber.error(error);
|
|
369
|
-
},
|
|
370
|
-
complete() {
|
|
371
|
-
subscriber.complete();
|
|
372
|
-
}
|
|
373
|
-
});
|
|
374
|
-
});
|
|
375
|
-
Object.defineProperty(this, kBackend, {
|
|
376
|
-
enumerable: false,
|
|
377
|
-
value: backend
|
|
378
|
-
});
|
|
379
|
-
const url = new OpraURL(init?.url, backend.serviceUrl.toString());
|
|
380
|
-
Object.defineProperty(this, kContext, {
|
|
381
|
-
enumerable: false,
|
|
382
|
-
value: {
|
|
383
|
-
...init,
|
|
384
|
-
observe: HttpObserveType.Body,
|
|
385
|
-
headers: new Headers(init?.headers),
|
|
386
|
-
url
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
clone() {
|
|
391
|
-
return new _HttpRequestObservable(this[kBackend], this[kContext]);
|
|
392
|
-
}
|
|
393
|
-
options(options) {
|
|
394
|
-
Object.assign(this[kContext], options);
|
|
395
|
-
return this;
|
|
396
|
-
}
|
|
397
|
-
header(arg0, value) {
|
|
398
|
-
const target = this[kContext].headers;
|
|
399
|
-
if (typeof arg0 === "object") {
|
|
400
|
-
const h = arg0 instanceof Headers ? arg0 : new Headers(arg0);
|
|
401
|
-
h.forEach((v, k) => {
|
|
402
|
-
if (k.toLowerCase() === "set-cookie") {
|
|
403
|
-
target.append(k, v);
|
|
404
|
-
} else
|
|
405
|
-
target.set(k, v);
|
|
406
|
-
});
|
|
407
|
-
return this;
|
|
408
|
-
}
|
|
409
|
-
if (value == null || value === "")
|
|
410
|
-
target.delete(arg0);
|
|
411
|
-
else
|
|
412
|
-
target.append(arg0, String(value));
|
|
413
|
-
return this;
|
|
414
|
-
}
|
|
415
|
-
param(arg0, value) {
|
|
416
|
-
const target = this[kContext].url.searchParams;
|
|
417
|
-
if (typeof arg0 === "object") {
|
|
418
|
-
const h = arg0 instanceof URLSearchParams ? arg0 : new URLSearchParams(arg0);
|
|
419
|
-
h.forEach((v, k) => target.set(k, v));
|
|
420
|
-
return this;
|
|
421
|
-
}
|
|
422
|
-
if (value == null)
|
|
423
|
-
target.delete(arg0);
|
|
424
|
-
else
|
|
425
|
-
target.set(arg0, String(value));
|
|
426
|
-
return this;
|
|
427
|
-
}
|
|
428
|
-
observe(observe) {
|
|
429
|
-
if (observe === this[kContext].observe)
|
|
430
|
-
return this;
|
|
431
|
-
const cloned = this.clone();
|
|
432
|
-
cloned[kContext].observe = observe || HttpObserveType.Body;
|
|
433
|
-
return cloned;
|
|
434
|
-
}
|
|
435
|
-
getBody() {
|
|
436
|
-
return lastValueFrom(this.observe(HttpObserveType.Body));
|
|
437
|
-
}
|
|
438
|
-
getResponse() {
|
|
439
|
-
return lastValueFrom(this.observe(HttpObserveType.Response));
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
|
-
|
|
443
|
-
// ../../build/client/esm/http/http-collection-node.js
|
|
444
|
-
var HttpCollectionNode = class {
|
|
445
|
-
static {
|
|
446
|
-
__name(this, "HttpCollectionNode");
|
|
447
|
-
}
|
|
448
|
-
constructor(backend, path) {
|
|
449
|
-
this._backend = backend;
|
|
450
|
-
this._path = path;
|
|
451
|
-
}
|
|
452
|
-
create(data, options) {
|
|
453
|
-
const observable = new HttpRequestObservable(this._backend, {
|
|
454
|
-
method: "POST",
|
|
455
|
-
url: this._path,
|
|
456
|
-
body: data
|
|
457
|
-
});
|
|
458
|
-
if (options?.include)
|
|
459
|
-
observable.param("include", toArrayDef(options.include, []).join(","));
|
|
460
|
-
if (options?.pick)
|
|
461
|
-
observable.param("pick", toArrayDef(options.pick, []).join(","));
|
|
462
|
-
if (options?.omit)
|
|
463
|
-
observable.param("omit", toArrayDef(options.omit, []).join(","));
|
|
464
|
-
return observable;
|
|
465
|
-
}
|
|
466
|
-
delete(id) {
|
|
467
|
-
if (id == null || id === "")
|
|
468
|
-
throw new TypeError(`'id' argument must have a value`);
|
|
469
|
-
const url = new OpraURL2();
|
|
470
|
-
url.join({ resource: this._path, key: id });
|
|
471
|
-
return new HttpRequestObservable(this._backend, {
|
|
472
|
-
method: "DELETE",
|
|
473
|
-
url
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
deleteMany(options) {
|
|
477
|
-
const observable = new HttpRequestObservable(this._backend, {
|
|
478
|
-
method: "DELETE",
|
|
479
|
-
url: this._path
|
|
480
|
-
});
|
|
481
|
-
if (options?.filter)
|
|
482
|
-
observable.param("filter", String(options.filter));
|
|
483
|
-
return observable;
|
|
484
|
-
}
|
|
485
|
-
get(id, options) {
|
|
486
|
-
if (id == null || id === "")
|
|
487
|
-
throw new TypeError(`'id' argument must have a value`);
|
|
488
|
-
const url = new OpraURL2();
|
|
489
|
-
url.join({ resource: this._path, key: id });
|
|
490
|
-
const observable = new HttpRequestObservable(this._backend, {
|
|
491
|
-
method: "GET",
|
|
492
|
-
url
|
|
493
|
-
});
|
|
494
|
-
if (options?.include)
|
|
495
|
-
observable.param("include", toArrayDef(options.include, []).join(","));
|
|
496
|
-
if (options?.pick)
|
|
497
|
-
observable.param("pick", toArrayDef(options.pick, []).join(","));
|
|
498
|
-
if (options?.omit)
|
|
499
|
-
observable.param("omit", toArrayDef(options.omit, []).join(","));
|
|
500
|
-
return observable;
|
|
501
|
-
}
|
|
502
|
-
findMany(options) {
|
|
503
|
-
const observable = new HttpRequestObservable(this._backend, {
|
|
504
|
-
method: "GET",
|
|
505
|
-
url: this._path
|
|
506
|
-
});
|
|
507
|
-
if (options?.include)
|
|
508
|
-
observable.param("include", toArrayDef(options.include, []).join(","));
|
|
509
|
-
if (options?.pick)
|
|
510
|
-
observable.param("pick", toArrayDef(options.pick, []).join(","));
|
|
511
|
-
if (options?.omit)
|
|
512
|
-
observable.param("omit", toArrayDef(options.omit, []).join(","));
|
|
513
|
-
if (options?.sort)
|
|
514
|
-
observable.param("sort", toArrayDef(options.sort, []).join(","));
|
|
515
|
-
if (options?.filter)
|
|
516
|
-
observable.param("filter", String(options.filter));
|
|
517
|
-
if (options?.limit != null)
|
|
518
|
-
observable.param("limit", String(options.limit));
|
|
519
|
-
if (options?.skip != null)
|
|
520
|
-
observable.param("skip", String(options.skip));
|
|
521
|
-
if (options?.count != null)
|
|
522
|
-
observable.param("count", String(options.count));
|
|
523
|
-
if (options?.distinct != null)
|
|
524
|
-
observable.param("distinct", String(options.distinct));
|
|
525
|
-
return observable;
|
|
526
|
-
}
|
|
527
|
-
update(id, data, options) {
|
|
528
|
-
if (id == null)
|
|
529
|
-
throw new TypeError(`'id' argument must have a value`);
|
|
530
|
-
const url = new OpraURL2();
|
|
531
|
-
url.join({ resource: this._path, key: id });
|
|
532
|
-
const observable = new HttpRequestObservable(this._backend, {
|
|
533
|
-
method: "PATCH",
|
|
534
|
-
url,
|
|
535
|
-
body: data
|
|
536
|
-
});
|
|
537
|
-
if (options?.include)
|
|
538
|
-
observable.param("include", toArrayDef(options.include, []).join(","));
|
|
539
|
-
if (options?.pick)
|
|
540
|
-
observable.param("pick", toArrayDef(options.pick, []).join(","));
|
|
541
|
-
if (options?.omit)
|
|
542
|
-
observable.param("omit", toArrayDef(options.omit, []).join(","));
|
|
543
|
-
return observable;
|
|
544
|
-
}
|
|
545
|
-
updateMany(data, options) {
|
|
546
|
-
const observable = new HttpRequestObservable(this._backend, {
|
|
547
|
-
method: "PATCH",
|
|
548
|
-
url: this._path,
|
|
549
|
-
body: data
|
|
550
|
-
});
|
|
551
|
-
if (options?.filter)
|
|
552
|
-
observable.param("filter", String(options.filter));
|
|
553
|
-
return observable;
|
|
554
|
-
}
|
|
555
|
-
};
|
|
556
|
-
|
|
557
|
-
// ../../build/client/esm/http/http-singleton-node.js
|
|
558
|
-
import { toArrayDef as toArrayDef2 } from "putil-varhelpers";
|
|
559
|
-
var HttpSingletonNode = class {
|
|
560
|
-
static {
|
|
561
|
-
__name(this, "HttpSingletonNode");
|
|
562
|
-
}
|
|
563
|
-
constructor(backend, path) {
|
|
564
|
-
this._backend = backend;
|
|
565
|
-
this._path = path;
|
|
566
|
-
}
|
|
567
|
-
create(data, options) {
|
|
568
|
-
const observable = new HttpRequestObservable(this._backend, {
|
|
569
|
-
method: "POST",
|
|
570
|
-
url: this._path,
|
|
571
|
-
body: data
|
|
572
|
-
});
|
|
573
|
-
if (options?.include)
|
|
574
|
-
observable.param("include", toArrayDef2(options.include, []).join(","));
|
|
575
|
-
if (options?.pick)
|
|
576
|
-
observable.param("pick", toArrayDef2(options.pick, []).join(","));
|
|
577
|
-
if (options?.omit)
|
|
578
|
-
observable.param("omit", toArrayDef2(options.omit, []).join(","));
|
|
579
|
-
return observable;
|
|
580
|
-
}
|
|
581
|
-
delete() {
|
|
582
|
-
return new HttpRequestObservable(this._backend, {
|
|
583
|
-
method: "DELETE",
|
|
584
|
-
url: this._path
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
get(options) {
|
|
588
|
-
const observable = new HttpRequestObservable(this._backend, {
|
|
589
|
-
method: "GET",
|
|
590
|
-
url: this._path
|
|
591
|
-
});
|
|
592
|
-
if (options?.include)
|
|
593
|
-
observable.param("include", toArrayDef2(options.include, []).join(","));
|
|
594
|
-
if (options?.pick)
|
|
595
|
-
observable.param("pick", toArrayDef2(options.pick, []).join(","));
|
|
596
|
-
if (options?.omit)
|
|
597
|
-
observable.param("omit", toArrayDef2(options.omit, []).join(","));
|
|
598
|
-
return observable;
|
|
599
|
-
}
|
|
600
|
-
update(data, options) {
|
|
601
|
-
const observable = new HttpRequestObservable(this._backend, {
|
|
602
|
-
method: "PATCH",
|
|
603
|
-
url: this._path,
|
|
604
|
-
body: data
|
|
605
|
-
});
|
|
606
|
-
if (options?.include)
|
|
607
|
-
observable.param("include", toArrayDef2(options.include, []).join(","));
|
|
608
|
-
if (options?.pick)
|
|
609
|
-
observable.param("pick", toArrayDef2(options.pick, []).join(","));
|
|
610
|
-
if (options?.omit)
|
|
611
|
-
observable.param("omit", toArrayDef2(options.omit, []).join(","));
|
|
612
|
-
return observable;
|
|
613
|
-
}
|
|
614
|
-
};
|
|
615
|
-
|
|
616
|
-
// ../../build/client/esm/http/http-client-base.js
|
|
617
|
-
var HttpClientBase = class extends ClientBase {
|
|
618
|
-
static {
|
|
619
|
-
__name(this, "HttpClientBase");
|
|
620
|
-
}
|
|
621
|
-
constructor(backend) {
|
|
622
|
-
super(backend);
|
|
623
|
-
}
|
|
624
|
-
get serviceUrl() {
|
|
625
|
-
return this[kBackend].serviceUrl;
|
|
626
|
-
}
|
|
627
|
-
async getMetadata() {
|
|
628
|
-
let promise = this._metadataPromise;
|
|
629
|
-
if (promise)
|
|
630
|
-
return promise;
|
|
631
|
-
const request = new HttpRequestObservable(this[kBackend], {
|
|
632
|
-
method: "GET",
|
|
633
|
-
url: "/",
|
|
634
|
-
headers: new Headers({ "accept": "application/json" })
|
|
635
|
-
});
|
|
636
|
-
this._metadataPromise = promise = request.getBody();
|
|
637
|
-
return await promise.then(async (body) => {
|
|
638
|
-
if (!body)
|
|
639
|
-
throw new Error(`No response returned.`);
|
|
640
|
-
const api = await ApiDocumentFactory.createDocument(body);
|
|
641
|
-
this[kBackend].api = api;
|
|
642
|
-
return api;
|
|
643
|
-
}).catch((e) => {
|
|
644
|
-
e.message = "Unable to fetch metadata from service url (" + this.serviceUrl + "). " + e.message;
|
|
645
|
-
throw e;
|
|
646
|
-
}).finally(() => delete this._metadataPromise);
|
|
647
|
-
}
|
|
648
|
-
collection(path) {
|
|
649
|
-
return new HttpCollectionNode(this[kBackend], path);
|
|
650
|
-
}
|
|
651
|
-
singleton(path) {
|
|
652
|
-
return new HttpSingletonNode(this[kBackend], path);
|
|
653
|
-
}
|
|
654
|
-
action(path, params) {
|
|
655
|
-
const observable = new HttpRequestObservable(this[kBackend], {
|
|
656
|
-
method: "GET",
|
|
657
|
-
url: path
|
|
658
|
-
});
|
|
659
|
-
if (params) {
|
|
660
|
-
Object.keys(params).forEach((k) => params[k] = String(params[k]));
|
|
661
|
-
observable.param(params);
|
|
662
|
-
}
|
|
663
|
-
return observable;
|
|
664
|
-
}
|
|
665
|
-
};
|
|
666
|
-
|
|
667
|
-
// ../../build/client/esm/http/http-client.js
|
|
668
|
-
var OpraHttpClient = class extends HttpClientBase {
|
|
669
|
-
static {
|
|
670
|
-
__name(this, "OpraHttpClient");
|
|
671
|
-
}
|
|
672
|
-
constructor(serviceUrl, options) {
|
|
673
|
-
super(new FetchBackend(serviceUrl, options));
|
|
674
|
-
}
|
|
675
|
-
get defaults() {
|
|
676
|
-
return this[kBackend].defaults;
|
|
677
|
-
}
|
|
678
|
-
};
|
|
679
|
-
|
|
680
|
-
// ../../build/client/esm/http/http-service-base.js
|
|
681
|
-
var _a;
|
|
682
|
-
var HttpServiceBase = class {
|
|
683
|
-
static {
|
|
684
|
-
__name(this, "HttpServiceBase");
|
|
685
|
-
}
|
|
686
|
-
constructor(client) {
|
|
687
|
-
this[_a] = {
|
|
688
|
-
resources: {},
|
|
689
|
-
node: null
|
|
690
|
-
};
|
|
691
|
-
this[kClient] = client;
|
|
692
|
-
}
|
|
693
|
-
};
|
|
694
|
-
_a = kContext;
|
|
695
|
-
export {
|
|
696
|
-
Backend,
|
|
697
|
-
ClientBase,
|
|
698
|
-
ClientError,
|
|
699
|
-
FetchBackend,
|
|
700
|
-
HttpBackend,
|
|
701
|
-
HttpClientBase,
|
|
702
|
-
HttpCollectionNode,
|
|
703
|
-
HttpEventType,
|
|
704
|
-
HttpObserveType,
|
|
705
|
-
HttpRequestObservable,
|
|
706
|
-
HttpResponse,
|
|
707
|
-
HttpServiceBase,
|
|
708
|
-
HttpSingletonNode,
|
|
709
|
-
OpraHttpClient,
|
|
710
|
-
kBackend,
|
|
711
|
-
kClient,
|
|
712
|
-
kContext
|
|
713
|
-
};
|
|
6
|
+
var $=Object.defineProperty,se=Object.defineProperties;var ce=Object.getOwnPropertyDescriptors;var Y=Object.getOwnPropertySymbols;var le=Object.prototype.hasOwnProperty,de=Object.prototype.propertyIsEnumerable;var Z=(c,e,r)=>e in c?$(c,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):c[e]=r,x=(c,e)=>{for(var r in e||(e={}))le.call(e,r)&&Z(c,r,e[r]);if(Y)for(var r of Y(e))de.call(e,r)&&Z(c,r,e[r]);return c},k=(c,e)=>se(c,ce(e)),l=(c,e)=>$(c,"name",{value:e,configurable:!0});var A=class A{constructor(e){this.api=e==null?void 0:e.api}};l(A,"Backend");var p=A;var he=Symbol.for("kClient"),u=Symbol.for("kBackend"),n=Symbol.for("kContext");var G=class G{constructor(e){Object.defineProperty(this,u,{enumerable:!1,value:e})}};l(G,"ClientBase");var j=G;var M=class M extends Error{constructor(e,r){super(e.message),this.cause=r,this.issues=e.issues||[],this.status=e.status,r&&(this.cause=r,r.stack&&(this.stack=r.stack))}};l(M,"ClientError");var S=M;import{Observable as me}from"rxjs";import{isReadableStreamLike as ue}from"rxjs/internal/util/isReadableStreamLike";import z from"@browsery/type-is";import{isBlob as fe}from"@opra/common";var I=class I extends p{constructor(e,r){super(r),this.serviceUrl=e}};l(I,"HttpBackend");var R=I;var v=class v{constructor(e){this.hasBody=!1,this.headers=(e==null?void 0:e.headers)instanceof Headers?e==null?void 0:e.headers:new Headers(e==null?void 0:e.headers),this.status=(e==null?void 0:e.status)||200,this.statusText=(e==null?void 0:e.statusText)||"OK",this.url=(e==null?void 0:e.url)||null,this.ok=this.status>=200&&this.status<300,this.body=e==null?void 0:e.body,this.hasBody=(e==null?void 0:e.body)!=null||!!(e!=null&&e.hasBody),this.contentType=(this.headers.get("content-type")||"").split(";")[0]}clone(e){return new v(x(x({},this),e))}};l(v,"HttpResponse");var T=v;var y;(function(c){c.Sent="Sent",c.UploadProgress="UploadProgress",c.ResponseHeader="ResponseHeader",c.DownloadProgress="DownloadProgress",c.Response="Response",c.User="User"})(y||(y={}));var F=class F extends R{constructor(e,r){var t,a,s,d,m,w;super(e,r),this.interceptors=Array.from(new Set([...(r==null?void 0:r.interceptors)||[]])),this.defaults=k(x({},r==null?void 0:r.defaults),{headers:((t=r==null?void 0:r.defaults)==null?void 0:t.headers)instanceof Headers?(a=r==null?void 0:r.defaults)==null?void 0:a.headers:new Headers((s=r==null?void 0:r.defaults)==null?void 0:s.headers),params:((d=r==null?void 0:r.defaults)==null?void 0:d.params)instanceof URLSearchParams?(m=r==null?void 0:r.defaults)==null?void 0:m.params:new URLSearchParams((w=r==null?void 0:r.defaults)==null?void 0:w.params)})}handle(e){return new me(r=>{(async()=>{let t=this.prepareRequest(e);if(t.body&&e.reportProgress){let C=t.body,O=t.headers.get("content-length")||"0",D=parseInt(O,10)||0,g=0,q=new TransformStream({transform(b,H){H.enqueue(b),g+=b.byteLength,r.next({type:y.UploadProgress,request:t,total:D,loaded:g})}});t=new Request(t.url,{cache:t.cache,credentials:t.credentials,headers:t.headers,integrity:t.integrity,keepalive:t.keepalive,method:t.method,mode:t.mode,redirect:t.redirect,referrer:t.referrer,referrerPolicy:t.referrerPolicy,signal:t.signal,body:C.pipeThrough(q),window:e.window,duplex:"half"})}let a=this.send(t);r.next({request:t,type:y.Sent});let s=await a,d=this.createResponse({url:s.url,headers:s.headers,status:s.status,statusText:s.statusText,hasBody:!!s.body});r.next({request:t,type:y.ResponseHeader,response:d});let m;if(s.body)if(e.reportProgress){let C=s.body,O=s.headers.get("content-length")||"0",D=parseInt(O,10)||0,g=0,q=new Response(new ReadableStream({async start(b){let H=C.getReader();for(;;){let{done:ae,value:X}=await H.read();if(ae)break;g+=X.byteLength,b.enqueue(X),r.next({type:y.DownloadProgress,request:t,total:D,loaded:g})}b.close()}}));m=await this.parseBody(q)}else m=await this.parseBody(s);let w=this.createResponse({url:s.url,headers:s.headers,status:s.status,statusText:s.statusText,body:m});r.next({request:t,type:y.Response,response:w}),r.complete()})().catch(t=>r.error(t))})}send(e){return fetch(e)}prepareRequest(e){let r=e.headers||new Headers,t=k(x({},e),{headers:r}),a=t.body;if(a){let s;typeof a=="string"||typeof a=="number"||typeof a=="boolean"?(s='text/plain; charset="UTF-8"',t.body=new Blob([String(a)],{type:s}),r.set("Content-Length",String(t.body.size)),delete t.duplex):ue(a)?(s="application/octet-stream",t.duplex="half"):Buffer.isBuffer(a)?(s="application/octet-stream",r.set("Content-Length",String(a.length)),delete t.duplex):fe(a)?(s=a.type||"application/octet-stream",r.set("Content-Length",String(a.size)),delete t.duplex):(s='application/json;charset="UTF-8"',t.body=new Blob([JSON.stringify(a)],{type:s}),r.set("Content-Length",String(t.body.size)),delete t.duplex),s&&!r.has("Content-Type")&&r.set("Content-Type",s)}return new Request(t.url.toString(),t)}createResponse(e){return new T(e)}async parseBody(e){let r,t=e.headers.get("Content-Type")||"";if(z.is(t,["json","application/*+json"]))r=await e.json(),typeof r=="string"&&(r=JSON.parse(r));else if(z.is(t,["text"]))r=await e.text();else if(z.is(t,["multipart"]))r=await e.formData();else{let a=await e.arrayBuffer();a.byteLength&&(r=a)}return r}};l(F,"FetchBackend");var P=F;import{ApiDocumentFactory as xe,ResponsiveMap as re}from"@opra/common";import{toArrayDef as f}from"putil-varhelpers";import{OpraURL as K}from"@opra/common";import{lastValueFrom as ee,Observable as ye}from"rxjs";import ie from"@browsery/type-is";import{OpraURL as oe}from"@opra/common";var i;(function(c){c.ResponseHeader="response-header",c.Response="response",c.Body="body",c.Events="events"})(i||(i={}));var J=class J{constructor(e,r){this.chain=e.reduceRight((t,a)=>(s,d)=>a.intercept(s,{handle:m=>t(m,d)}),ne),this.finalHandler=r}handle(e){return this.chain(e,r=>this.finalHandler.handle(r))}};l(J,"HttpInterceptorHandler");var B=J;function ne(c,e){return e(c)}l(ne,"chainEnd");var E=class E extends ye{constructor(e,r){super(a=>{let s=this[n].observe;new B(e.interceptors||[],this[u]).handle(this[n]).subscribe({next(d){if(s===i.Events){a.next(d);return}if(s===i.ResponseHeader&&d.type===y.ResponseHeader){a.next(d.response),a.complete();return}if(d.type===y.Response){let{response:m}=d;if(s===i.Response){a.next(m),a.complete();return}let w=ie.is(d.response.contentType||"",["application/opra+json"]);if(m.status>=400&&m.status<600){a.error(new S({message:m.status+" "+m.statusText,status:m.status,issues:w?m.body.errors:void 0})),a.complete();return}a.next(d.response.body),a.complete()}},error(d){a.error(d)},complete(){a.complete()}})}),Object.defineProperty(this,u,{enumerable:!1,value:e});let t=new oe(r==null?void 0:r.url,e.serviceUrl.toString());Object.defineProperty(this,n,{enumerable:!1,value:k(x({},r),{observe:i.Body,headers:new Headers(r==null?void 0:r.headers),url:t})})}clone(){return new E(this[u],this[n])}options(e){return Object.assign(this[n],e),this}header(e,r){let t=this[n].headers;return typeof e=="object"?((e instanceof Headers?e:new Headers(e)).forEach((s,d)=>{d.toLowerCase()==="set-cookie"?t.append(d,s):t.set(d,s)}),this):(r==null||r===""?t.delete(e):t.append(e,String(r)),this)}param(e,r){let t=this[n].url.searchParams;return typeof e=="object"?((e instanceof URLSearchParams?e:new URLSearchParams(e)).forEach((s,d)=>t.set(d,s)),this):(r==null?t.delete(e):t.set(e,String(r)),this)}observe(e){if(e===this[n].observe)return this;let r=this.clone();return r[n].observe=e||i.Body,r}getBody(){return ee(this.observe(i.Body))}getResponse(){return ee(this.observe(i.Response))}};l(E,"HttpRequestObservable");var h=E;var N=class N{constructor(e,r){this._backend=e,this._path=r}create(e,r){let t=new h(this._backend,{method:"POST",url:this._path,body:e});return r!=null&&r.include&&t.param("include",f(r.include,[]).join(",")),r!=null&&r.pick&&t.param("pick",f(r.pick,[]).join(",")),r!=null&&r.omit&&t.param("omit",f(r.omit,[]).join(",")),t}delete(e){if(e==null||e==="")throw new TypeError("'id' argument must have a value");let r=new K;return r.join({resource:this._path,key:e}),new h(this._backend,{method:"DELETE",url:r})}deleteMany(e){let r=new h(this._backend,{method:"DELETE",url:this._path});return e!=null&&e.filter&&r.param("filter",String(e.filter)),r}get(e,r){if(e==null||e==="")throw new TypeError("'id' argument must have a value");let t=new K;t.join({resource:this._path,key:e});let a=new h(this._backend,{method:"GET",url:t});return r!=null&&r.include&&a.param("include",f(r.include,[]).join(",")),r!=null&&r.pick&&a.param("pick",f(r.pick,[]).join(",")),r!=null&&r.omit&&a.param("omit",f(r.omit,[]).join(",")),a}findMany(e){let r=new h(this._backend,{method:"GET",url:this._path});return e!=null&&e.include&&r.param("include",f(e.include,[]).join(",")),e!=null&&e.pick&&r.param("pick",f(e.pick,[]).join(",")),e!=null&&e.omit&&r.param("omit",f(e.omit,[]).join(",")),e!=null&&e.sort&&r.param("sort",f(e.sort,[]).join(",")),e!=null&&e.filter&&r.param("filter",String(e.filter)),(e==null?void 0:e.limit)!=null&&r.param("limit",String(e.limit)),(e==null?void 0:e.skip)!=null&&r.param("skip",String(e.skip)),(e==null?void 0:e.count)!=null&&r.param("count",String(e.count)),(e==null?void 0:e.distinct)!=null&&r.param("distinct",String(e.distinct)),r}update(e,r,t){if(e==null)throw new TypeError("'id' argument must have a value");let a=new K;a.join({resource:this._path,key:e});let s=new h(this._backend,{method:"PATCH",url:a,body:r});return t!=null&&t.include&&s.param("include",f(t.include,[]).join(",")),t!=null&&t.pick&&s.param("pick",f(t.pick,[]).join(",")),t!=null&&t.omit&&s.param("omit",f(t.omit,[]).join(",")),s}updateMany(e,r){let t=new h(this._backend,{method:"PATCH",url:this._path,body:e});return r!=null&&r.filter&&t.param("filter",String(r.filter)),t}};l(N,"HttpCollectionNode");var _=N;import{toArrayDef as o}from"putil-varhelpers";var V=class V{constructor(e,r){this._backend=e,this._path=r}create(e,r){let t=new h(this._backend,{method:"POST",url:this._path,body:e});return r!=null&&r.include&&t.param("include",o(r.include,[]).join(",")),r!=null&&r.pick&&t.param("pick",o(r.pick,[]).join(",")),r!=null&&r.omit&&t.param("omit",o(r.omit,[]).join(",")),t}delete(){return new h(this._backend,{method:"DELETE",url:this._path})}get(e){let r=new h(this._backend,{method:"GET",url:this._path});return e!=null&&e.include&&r.param("include",o(e.include,[]).join(",")),e!=null&&e.pick&&r.param("pick",o(e.pick,[]).join(",")),e!=null&&e.omit&&r.param("omit",o(e.omit,[]).join(",")),r}update(e,r){let t=new h(this._backend,{method:"PATCH",url:this._path,body:e});return r!=null&&r.include&&t.param("include",o(r.include,[]).join(",")),r!=null&&r.pick&&t.param("pick",o(r.pick,[]).join(",")),r!=null&&r.omit&&t.param("omit",o(r.omit,[]).join(",")),t}};l(V,"HttpSingletonNode");var L=V;var Q=class Q extends j{constructor(e){super(e),this._collectionCache=new re,this._singletonCache=new re}get serviceUrl(){return this[u].serviceUrl}async getMetadata(){let e=this._metadataPromise;if(e)return e;let r=new h(this[u],{method:"GET",url:"/",headers:new Headers({accept:"application/json"})});return this._metadataPromise=e=r.getBody(),await e.then(async t=>{if(!t)throw new Error("No response returned.");let a=await xe.createDocument(t);return this[u].api=a,a}).catch(t=>{throw t.message="Unable to fetch metadata from service url ("+this.serviceUrl+"). "+t.message,t}).finally(()=>delete this._metadataPromise)}collection(e){let r=this._collectionCache.get(e);return r||(r=new _(this[u],e),this._collectionCache.set(e,r)),r}singleton(e){let r=this._singletonCache.get(e);return r||(r=new L(this[u],e),this._singletonCache.set(e,r)),r}action(e,r){let t=new h(this[u],{method:"GET",url:e});return r&&(Object.keys(r).forEach(a=>r[a]=String(r[a])),t.param(r)),t}};l(Q,"HttpClientBase");var U=Q;var W=class W extends U{constructor(e,r){super(new P(e,r))}get defaults(){return this[u].defaults}};l(W,"OpraHttpClient");var te=W;export{p as Backend,j as ClientBase,S as ClientError,P as FetchBackend,R as HttpBackend,U as HttpClientBase,_ as HttpCollectionNode,y as HttpEventType,i as HttpObserveType,h as HttpRequestObservable,T as HttpResponse,L as HttpSingletonNode,te as OpraHttpClient,u as kBackend,he as kClient,n as kContext};
|
|
@@ -15,6 +15,8 @@ const http_singleton_node_js_1 = require("./http-singleton-node.js");
|
|
|
15
15
|
class HttpClientBase extends client_base_js_1.ClientBase {
|
|
16
16
|
constructor(backend) {
|
|
17
17
|
super(backend);
|
|
18
|
+
this._collectionCache = new common_1.ResponsiveMap();
|
|
19
|
+
this._singletonCache = new common_1.ResponsiveMap();
|
|
18
20
|
}
|
|
19
21
|
get serviceUrl() {
|
|
20
22
|
return this[constants_js_1.kBackend].serviceUrl;
|
|
@@ -44,10 +46,20 @@ class HttpClientBase extends client_base_js_1.ClientBase {
|
|
|
44
46
|
.finally(() => delete this._metadataPromise);
|
|
45
47
|
}
|
|
46
48
|
collection(path) {
|
|
47
|
-
|
|
49
|
+
let node = this._collectionCache.get(path);
|
|
50
|
+
if (!node) {
|
|
51
|
+
node = new http_collection_node_js_1.HttpCollectionNode(this[constants_js_1.kBackend], path);
|
|
52
|
+
this._collectionCache.set(path, node);
|
|
53
|
+
}
|
|
54
|
+
return node;
|
|
48
55
|
}
|
|
49
56
|
singleton(path) {
|
|
50
|
-
|
|
57
|
+
let node = this._singletonCache.get(path);
|
|
58
|
+
if (!node) {
|
|
59
|
+
node = new http_singleton_node_js_1.HttpSingletonNode(this[constants_js_1.kBackend], path);
|
|
60
|
+
this._singletonCache.set(path, node);
|
|
61
|
+
}
|
|
62
|
+
return node;
|
|
51
63
|
}
|
|
52
64
|
action(path, params) {
|
|
53
65
|
const observable = new http_request_observable_js_1.HttpRequestObservable(this[constants_js_1.kBackend], {
|
package/cjs/index.js
CHANGED
|
@@ -13,7 +13,6 @@ tslib_1.__exportStar(require("./http/http-client-base.js"), exports);
|
|
|
13
13
|
tslib_1.__exportStar(require("./http/http-collection-node.js"), exports);
|
|
14
14
|
tslib_1.__exportStar(require("./http/http-request-observable.js"), exports);
|
|
15
15
|
tslib_1.__exportStar(require("./http/http-response.js"), exports);
|
|
16
|
-
tslib_1.__exportStar(require("./http/http-service-base.js"), exports);
|
|
17
16
|
tslib_1.__exportStar(require("./http/http-singleton-node.js"), exports);
|
|
18
17
|
tslib_1.__exportStar(require("./http/enums/http-observable-type.enum.js"), exports);
|
|
19
18
|
tslib_1.__exportStar(require("./http/interfaces/http-event.js"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiDocumentFactory } from '@opra/common';
|
|
1
|
+
import { ApiDocumentFactory, ResponsiveMap } from '@opra/common';
|
|
2
2
|
import { kBackend } from '../constants.js';
|
|
3
3
|
import { ClientBase } from '../core/client-base.js';
|
|
4
4
|
import { HttpCollectionNode } from './http-collection-node.js';
|
|
@@ -12,6 +12,8 @@ import { HttpSingletonNode } from './http-singleton-node.js';
|
|
|
12
12
|
export class HttpClientBase extends ClientBase {
|
|
13
13
|
constructor(backend) {
|
|
14
14
|
super(backend);
|
|
15
|
+
this._collectionCache = new ResponsiveMap();
|
|
16
|
+
this._singletonCache = new ResponsiveMap();
|
|
15
17
|
}
|
|
16
18
|
get serviceUrl() {
|
|
17
19
|
return this[kBackend].serviceUrl;
|
|
@@ -41,10 +43,20 @@ export class HttpClientBase extends ClientBase {
|
|
|
41
43
|
.finally(() => delete this._metadataPromise);
|
|
42
44
|
}
|
|
43
45
|
collection(path) {
|
|
44
|
-
|
|
46
|
+
let node = this._collectionCache.get(path);
|
|
47
|
+
if (!node) {
|
|
48
|
+
node = new HttpCollectionNode(this[kBackend], path);
|
|
49
|
+
this._collectionCache.set(path, node);
|
|
50
|
+
}
|
|
51
|
+
return node;
|
|
45
52
|
}
|
|
46
53
|
singleton(path) {
|
|
47
|
-
|
|
54
|
+
let node = this._singletonCache.get(path);
|
|
55
|
+
if (!node) {
|
|
56
|
+
node = new HttpSingletonNode(this[kBackend], path);
|
|
57
|
+
this._singletonCache.set(path, node);
|
|
58
|
+
}
|
|
59
|
+
return node;
|
|
48
60
|
}
|
|
49
61
|
action(path, params) {
|
|
50
62
|
const observable = new HttpRequestObservable(this[kBackend], {
|
package/esm/index.js
CHANGED
|
@@ -9,7 +9,6 @@ export * from './http/http-client-base.js';
|
|
|
9
9
|
export * from './http/http-collection-node.js';
|
|
10
10
|
export * from './http/http-request-observable.js';
|
|
11
11
|
export * from './http/http-response.js';
|
|
12
|
-
export * from './http/http-service-base.js';
|
|
13
12
|
export * from './http/http-singleton-node.js';
|
|
14
13
|
export * from './http/enums/http-observable-type.enum.js';
|
|
15
14
|
export * from './http/interfaces/http-event.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/client",
|
|
3
|
-
"version": "0.29.
|
|
3
|
+
"version": "0.29.1",
|
|
4
4
|
"description": "Opra Client package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@browsery/stream": "^0.6.0",
|
|
40
40
|
"@browsery/type-is": "^0.6.3",
|
|
41
41
|
"@browsery/util": "^0.4.0",
|
|
42
|
-
"@opra/common": "^0.29.
|
|
42
|
+
"@opra/common": "^0.29.1",
|
|
43
43
|
"accepts": "^1.3.8",
|
|
44
44
|
"buffer": "^6.0.3",
|
|
45
45
|
"cookie": "^0.5.0",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiDocument } from '@opra/common';
|
|
1
|
+
import { ApiDocument, ResponsiveMap } from '@opra/common';
|
|
2
2
|
import { kBackend } from '../constants.js';
|
|
3
3
|
import { ClientBase } from '../core/client-base.js';
|
|
4
4
|
import { HttpBackend } from './http-backend.js';
|
|
@@ -12,6 +12,8 @@ import { HttpSingletonNode } from './http-singleton-node.js';
|
|
|
12
12
|
*/
|
|
13
13
|
export declare abstract class HttpClientBase<TRequestOptions = {}, TResponseExt = {}> extends ClientBase {
|
|
14
14
|
[kBackend]: HttpBackend;
|
|
15
|
+
protected _collectionCache: ResponsiveMap<HttpCollectionNode<any, {}, {}>>;
|
|
16
|
+
protected _singletonCache: ResponsiveMap<HttpCollectionNode<any, {}, {}>>;
|
|
15
17
|
protected _metadataPromise?: Promise<any>;
|
|
16
18
|
protected constructor(backend: HttpBackend);
|
|
17
19
|
get serviceUrl(): string;
|
package/types/index.d.ts
CHANGED
|
@@ -9,7 +9,6 @@ export * from './http/http-client-base.js';
|
|
|
9
9
|
export * from './http/http-collection-node.js';
|
|
10
10
|
export * from './http/http-request-observable.js';
|
|
11
11
|
export * from './http/http-response.js';
|
|
12
|
-
export * from './http/http-service-base.js';
|
|
13
12
|
export * from './http/http-singleton-node.js';
|
|
14
13
|
export * from './http/enums/http-observable-type.enum.js';
|
|
15
14
|
export * from './http/interfaces/http-event.js';
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.HttpServiceBase = void 0;
|
|
5
|
-
const constants_js_1 = require("../constants.js");
|
|
6
|
-
class HttpServiceBase {
|
|
7
|
-
constructor(client) {
|
|
8
|
-
this[_a] = {
|
|
9
|
-
resources: {},
|
|
10
|
-
node: null
|
|
11
|
-
};
|
|
12
|
-
this[constants_js_1.kClient] = client;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.HttpServiceBase = HttpServiceBase;
|
|
16
|
-
_a = constants_js_1.kContext;
|