@opra/client 1.0.0-alpha.21 → 1.0.0-alpha.23
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/index.cjs +617 -0
- package/browser/index.min.cjs +8 -0
- package/browser/index.min.mjs +8 -0
- package/browser/index.mjs +576 -0
- package/package.json +45 -40
- package/browser.js +0 -8
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
/****************************************
|
|
2
|
+
* All rights reserved Panates® 2022-2024
|
|
3
|
+
* http://www.panates.com
|
|
4
|
+
*****************************************/
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
|
|
9
|
+
// ../../build/client/esm/index.js
|
|
10
|
+
import { Buffer as Buffer2 } from "buffer";
|
|
11
|
+
|
|
12
|
+
// ../../build/client/esm/constants.js
|
|
13
|
+
var kClient = Symbol.for("kClient");
|
|
14
|
+
var kBackend = Symbol.for("kBackend");
|
|
15
|
+
var kContext = Symbol.for("kContext");
|
|
16
|
+
|
|
17
|
+
// ../../build/client/esm/core/backend.js
|
|
18
|
+
var _Backend = class _Backend {
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.document = options == null ? void 0 : options.document;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
__name(_Backend, "Backend");
|
|
24
|
+
var Backend = _Backend;
|
|
25
|
+
|
|
26
|
+
// ../../build/client/esm/core/client-error.js
|
|
27
|
+
var _ClientError = class _ClientError extends Error {
|
|
28
|
+
constructor(init, cause) {
|
|
29
|
+
super(init.message);
|
|
30
|
+
this.cause = cause;
|
|
31
|
+
this.issues = init.issues || [];
|
|
32
|
+
this.status = init.status;
|
|
33
|
+
if (cause) {
|
|
34
|
+
this.cause = cause;
|
|
35
|
+
if (cause.stack)
|
|
36
|
+
this.stack = cause.stack;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
__name(_ClientError, "ClientError");
|
|
41
|
+
var ClientError = _ClientError;
|
|
42
|
+
|
|
43
|
+
// ../../build/client/esm/http/enums/http-observable-type.enum.js
|
|
44
|
+
var HttpObserveType;
|
|
45
|
+
(function(HttpObserveType2) {
|
|
46
|
+
HttpObserveType2["ResponseHeader"] = "response-header";
|
|
47
|
+
HttpObserveType2["Response"] = "response";
|
|
48
|
+
HttpObserveType2["Body"] = "body";
|
|
49
|
+
HttpObserveType2["Events"] = "events";
|
|
50
|
+
})(HttpObserveType || (HttpObserveType = {}));
|
|
51
|
+
|
|
52
|
+
// ../../build/client/esm/http/fetch-backend.js
|
|
53
|
+
import typeIs from "@browsery/type-is";
|
|
54
|
+
import { isBlob, isFormData } from "@opra/common";
|
|
55
|
+
import { Observable } from "rxjs";
|
|
56
|
+
import { isReadableStreamLike } from "rxjs/internal/util/isReadableStreamLike";
|
|
57
|
+
|
|
58
|
+
// ../../build/client/esm/http/http-backend.js
|
|
59
|
+
var _HttpBackend = class _HttpBackend extends Backend {
|
|
60
|
+
constructor(serviceUrl, options) {
|
|
61
|
+
super(options);
|
|
62
|
+
const u = new URL(serviceUrl);
|
|
63
|
+
this.serviceUrl = u.toString().split("?")[0].split("#")[0];
|
|
64
|
+
if (!this.serviceUrl.endsWith("/"))
|
|
65
|
+
this.serviceUrl += "/";
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
__name(_HttpBackend, "HttpBackend");
|
|
69
|
+
var HttpBackend = _HttpBackend;
|
|
70
|
+
|
|
71
|
+
// ../../build/client/esm/http/http-response.js
|
|
72
|
+
var _HttpResponse = class _HttpResponse {
|
|
73
|
+
constructor(init) {
|
|
74
|
+
this.hasBody = false;
|
|
75
|
+
this.headers = (init == null ? void 0 : init.headers) instanceof Headers ? init == null ? void 0 : init.headers : new Headers(init == null ? void 0 : init.headers);
|
|
76
|
+
this.status = (init == null ? void 0 : init.status) || 200;
|
|
77
|
+
this.statusText = (init == null ? void 0 : init.statusText) || "OK";
|
|
78
|
+
this.url = (init == null ? void 0 : init.url) || null;
|
|
79
|
+
this.ok = this.status >= 200 && this.status < 300;
|
|
80
|
+
this.body = init == null ? void 0 : init.body;
|
|
81
|
+
this.hasBody = (init == null ? void 0 : init.body) != null || !!(init == null ? void 0 : init.hasBody);
|
|
82
|
+
this.contentType = (this.headers.get("content-type") || "").split(";")[0];
|
|
83
|
+
}
|
|
84
|
+
clone(update) {
|
|
85
|
+
return new _HttpResponse({ ...this, ...update });
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
__name(_HttpResponse, "HttpResponse");
|
|
89
|
+
var HttpResponse = _HttpResponse;
|
|
90
|
+
|
|
91
|
+
// ../../build/client/esm/http/interfaces/http-event.js
|
|
92
|
+
var HttpEventType;
|
|
93
|
+
(function(HttpEventType2) {
|
|
94
|
+
HttpEventType2["Sent"] = "Sent";
|
|
95
|
+
HttpEventType2["UploadProgress"] = "UploadProgress";
|
|
96
|
+
HttpEventType2["ResponseHeader"] = "ResponseHeader";
|
|
97
|
+
HttpEventType2["DownloadProgress"] = "DownloadProgress";
|
|
98
|
+
HttpEventType2["Response"] = "Response";
|
|
99
|
+
HttpEventType2["User"] = "User";
|
|
100
|
+
})(HttpEventType || (HttpEventType = {}));
|
|
101
|
+
|
|
102
|
+
// ../../build/client/esm/http/fetch-backend.js
|
|
103
|
+
var _FetchBackend = class _FetchBackend extends HttpBackend {
|
|
104
|
+
constructor(serviceUrl, options) {
|
|
105
|
+
var _a, _b, _c, _d, _e, _f;
|
|
106
|
+
super(serviceUrl, options);
|
|
107
|
+
this.interceptors = Array.from(/* @__PURE__ */ new Set([...(options == null ? void 0 : options.interceptors) || []]));
|
|
108
|
+
this.defaults = {
|
|
109
|
+
...options == null ? void 0 : options.defaults,
|
|
110
|
+
headers: ((_a = options == null ? void 0 : options.defaults) == null ? void 0 : _a.headers) instanceof Headers ? (_b = options == null ? void 0 : options.defaults) == null ? void 0 : _b.headers : new Headers((_c = options == null ? void 0 : options.defaults) == null ? void 0 : _c.headers),
|
|
111
|
+
params: ((_d = options == null ? void 0 : options.defaults) == null ? void 0 : _d.params) instanceof URLSearchParams ? (_e = options == null ? void 0 : options.defaults) == null ? void 0 : _e.params : new URLSearchParams((_f = options == null ? void 0 : options.defaults) == null ? void 0 : _f.params)
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
handle(init) {
|
|
115
|
+
return new Observable((subscriber) => {
|
|
116
|
+
(async () => {
|
|
117
|
+
let request = this.prepareRequest(init);
|
|
118
|
+
if (request.body && init.reportProgress) {
|
|
119
|
+
const stream = request.body;
|
|
120
|
+
const contentLength = request.headers.get("content-length") || "0";
|
|
121
|
+
const total = parseInt(contentLength, 10) || 0;
|
|
122
|
+
let loaded = 0;
|
|
123
|
+
const progressTrackingStream = new TransformStream({
|
|
124
|
+
transform(chunk, controller) {
|
|
125
|
+
controller.enqueue(chunk);
|
|
126
|
+
loaded += chunk.byteLength;
|
|
127
|
+
subscriber.next({
|
|
128
|
+
type: HttpEventType.UploadProgress,
|
|
129
|
+
request,
|
|
130
|
+
total,
|
|
131
|
+
loaded
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
request = new Request(request.url, {
|
|
136
|
+
cache: request.cache,
|
|
137
|
+
credentials: request.credentials,
|
|
138
|
+
headers: request.headers,
|
|
139
|
+
integrity: request.integrity,
|
|
140
|
+
keepalive: request.keepalive,
|
|
141
|
+
method: request.method,
|
|
142
|
+
mode: request.mode,
|
|
143
|
+
redirect: request.redirect,
|
|
144
|
+
referrer: request.referrer,
|
|
145
|
+
referrerPolicy: request.referrerPolicy,
|
|
146
|
+
signal: request.signal,
|
|
147
|
+
body: stream.pipeThrough(progressTrackingStream),
|
|
148
|
+
window: init.window,
|
|
149
|
+
...{
|
|
150
|
+
// undici library requires
|
|
151
|
+
duplex: "half"
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
const fetchPromise = this.send(request);
|
|
156
|
+
subscriber.next({
|
|
157
|
+
request,
|
|
158
|
+
type: HttpEventType.Sent
|
|
159
|
+
});
|
|
160
|
+
const fetchResponse = await fetchPromise;
|
|
161
|
+
const headersResponse = this.createResponse({
|
|
162
|
+
url: fetchResponse.url,
|
|
163
|
+
headers: fetchResponse.headers,
|
|
164
|
+
status: fetchResponse.status,
|
|
165
|
+
statusText: fetchResponse.statusText,
|
|
166
|
+
hasBody: !!fetchResponse.body
|
|
167
|
+
});
|
|
168
|
+
subscriber.next({
|
|
169
|
+
request,
|
|
170
|
+
type: HttpEventType.ResponseHeader,
|
|
171
|
+
response: headersResponse
|
|
172
|
+
});
|
|
173
|
+
let body;
|
|
174
|
+
if (fetchResponse.body) {
|
|
175
|
+
if (init.reportProgress) {
|
|
176
|
+
const fetchBody = fetchResponse.body;
|
|
177
|
+
const contentLength = fetchResponse.headers.get("content-length") || "0";
|
|
178
|
+
const total = parseInt(contentLength, 10) || 0;
|
|
179
|
+
let loaded = 0;
|
|
180
|
+
const res = new Response(new ReadableStream({
|
|
181
|
+
async start(controller) {
|
|
182
|
+
const reader = fetchBody.getReader();
|
|
183
|
+
for (; ; ) {
|
|
184
|
+
const { done, value } = await reader.read();
|
|
185
|
+
if (done)
|
|
186
|
+
break;
|
|
187
|
+
loaded += value.byteLength;
|
|
188
|
+
controller.enqueue(value);
|
|
189
|
+
subscriber.next({
|
|
190
|
+
type: HttpEventType.DownloadProgress,
|
|
191
|
+
request,
|
|
192
|
+
total,
|
|
193
|
+
loaded
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
controller.close();
|
|
197
|
+
}
|
|
198
|
+
}));
|
|
199
|
+
body = await this.parseBody(res);
|
|
200
|
+
} else {
|
|
201
|
+
body = await this.parseBody(fetchResponse);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const response = this.createResponse({
|
|
205
|
+
url: fetchResponse.url,
|
|
206
|
+
headers: fetchResponse.headers,
|
|
207
|
+
status: fetchResponse.status,
|
|
208
|
+
statusText: fetchResponse.statusText,
|
|
209
|
+
body
|
|
210
|
+
});
|
|
211
|
+
subscriber.next({
|
|
212
|
+
request,
|
|
213
|
+
type: HttpEventType.Response,
|
|
214
|
+
response
|
|
215
|
+
});
|
|
216
|
+
subscriber.complete();
|
|
217
|
+
})().catch((error) => subscriber.error(error));
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
send(request) {
|
|
221
|
+
return fetch(request);
|
|
222
|
+
}
|
|
223
|
+
prepareRequest(init) {
|
|
224
|
+
const headers = init.headers || new Headers();
|
|
225
|
+
const requestInit = {
|
|
226
|
+
...init,
|
|
227
|
+
headers
|
|
228
|
+
};
|
|
229
|
+
this.defaults.headers.forEach((val, key) => {
|
|
230
|
+
if (!headers.has(key))
|
|
231
|
+
headers.set(key, val);
|
|
232
|
+
});
|
|
233
|
+
const url = new URL(requestInit.url, this.serviceUrl);
|
|
234
|
+
if (this.defaults.params.size) {
|
|
235
|
+
this.defaults.params.forEach((val, key) => {
|
|
236
|
+
if (!url.searchParams.has(key))
|
|
237
|
+
url.searchParams.set(key, val);
|
|
238
|
+
});
|
|
239
|
+
requestInit.url = url.toString();
|
|
240
|
+
}
|
|
241
|
+
const body = requestInit.body;
|
|
242
|
+
if (body) {
|
|
243
|
+
let contentType = "";
|
|
244
|
+
if (typeof body === "string" || typeof body === "number" || typeof body === "boolean") {
|
|
245
|
+
contentType = 'text/plain; charset="UTF-8"';
|
|
246
|
+
requestInit.body = new Blob([String(body)], { type: contentType });
|
|
247
|
+
headers.set("Content-Length", String(requestInit.body.size));
|
|
248
|
+
delete requestInit.duplex;
|
|
249
|
+
} else if (isReadableStreamLike(body)) {
|
|
250
|
+
contentType = "application/octet-stream";
|
|
251
|
+
requestInit.duplex = "half";
|
|
252
|
+
} else if (Buffer.isBuffer(body)) {
|
|
253
|
+
contentType = "application/octet-stream";
|
|
254
|
+
headers.set("Content-Length", String(body.length));
|
|
255
|
+
delete requestInit.duplex;
|
|
256
|
+
} else if (isBlob(body)) {
|
|
257
|
+
contentType = body.type || "application/octet-stream";
|
|
258
|
+
headers.set("Content-Length", String(body.size));
|
|
259
|
+
delete requestInit.duplex;
|
|
260
|
+
} else if (isFormData(body)) {
|
|
261
|
+
delete requestInit.duplex;
|
|
262
|
+
} else {
|
|
263
|
+
contentType = 'application/json;charset="UTF-8"';
|
|
264
|
+
requestInit.body = new Blob([JSON.stringify(body)], { type: contentType });
|
|
265
|
+
headers.set("Content-Length", String(requestInit.body.size));
|
|
266
|
+
delete requestInit.duplex;
|
|
267
|
+
}
|
|
268
|
+
if (contentType && !headers.has("Content-Type"))
|
|
269
|
+
headers.set("Content-Type", contentType);
|
|
270
|
+
}
|
|
271
|
+
return new Request(url.toString(), requestInit);
|
|
272
|
+
}
|
|
273
|
+
createResponse(init) {
|
|
274
|
+
return new HttpResponse(init);
|
|
275
|
+
}
|
|
276
|
+
async parseBody(fetchResponse) {
|
|
277
|
+
let body;
|
|
278
|
+
const contentType = fetchResponse.headers.get("Content-Type") || "";
|
|
279
|
+
if (typeIs.is(contentType, ["json", "application/*+json"])) {
|
|
280
|
+
body = await fetchResponse.json();
|
|
281
|
+
if (typeof body === "string")
|
|
282
|
+
body = JSON.parse(body);
|
|
283
|
+
} else if (typeIs.is(contentType, ["text"]))
|
|
284
|
+
body = await fetchResponse.text();
|
|
285
|
+
else if (typeIs.is(contentType, ["multipart"]))
|
|
286
|
+
body = await fetchResponse.formData();
|
|
287
|
+
else {
|
|
288
|
+
const buf = await fetchResponse.arrayBuffer();
|
|
289
|
+
if (buf.byteLength)
|
|
290
|
+
body = buf;
|
|
291
|
+
}
|
|
292
|
+
return body;
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
__name(_FetchBackend, "FetchBackend");
|
|
296
|
+
var FetchBackend = _FetchBackend;
|
|
297
|
+
|
|
298
|
+
// ../../build/client/esm/http/http-client-base.js
|
|
299
|
+
import { ApiDocumentFactory } from "@opra/common";
|
|
300
|
+
|
|
301
|
+
// ../../build/client/esm/http/http-request-observable.js
|
|
302
|
+
import typeIs2 from "@browsery/type-is";
|
|
303
|
+
import { MimeTypes } from "@opra/common";
|
|
304
|
+
import { lastValueFrom, Observable as Observable2 } from "rxjs";
|
|
305
|
+
|
|
306
|
+
// ../../build/client/esm/http/http-interceptor-handler.js
|
|
307
|
+
var _HttpInterceptorHandler = class _HttpInterceptorHandler {
|
|
308
|
+
constructor(interceptors, finalHandler) {
|
|
309
|
+
this.chain = interceptors.reduceRight((chainTailFn, interceptor) => (initialRequest, handler) => interceptor.intercept(initialRequest, {
|
|
310
|
+
handle: /* @__PURE__ */ __name((downstreamRequest) => chainTailFn(downstreamRequest, handler), "handle")
|
|
311
|
+
}), chainEnd);
|
|
312
|
+
this.finalHandler = finalHandler;
|
|
313
|
+
}
|
|
314
|
+
handle(initialRequest) {
|
|
315
|
+
return this.chain(initialRequest, (req) => this.finalHandler.handle(req));
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
__name(_HttpInterceptorHandler, "HttpInterceptorHandler");
|
|
319
|
+
var HttpInterceptorHandler = _HttpInterceptorHandler;
|
|
320
|
+
function chainEnd(req, handler) {
|
|
321
|
+
return handler(req);
|
|
322
|
+
}
|
|
323
|
+
__name(chainEnd, "chainEnd");
|
|
324
|
+
|
|
325
|
+
// ../../build/client/esm/http/http-request-observable.js
|
|
326
|
+
var _HttpRequestObservable = class _HttpRequestObservable extends Observable2 {
|
|
327
|
+
constructor(backend, init) {
|
|
328
|
+
super((subscriber) => {
|
|
329
|
+
const observe = this[kContext].observe;
|
|
330
|
+
new HttpInterceptorHandler(backend.interceptors || [], this[kBackend]).handle(this[kContext]).subscribe({
|
|
331
|
+
next(event) {
|
|
332
|
+
if (observe === HttpObserveType.Events) {
|
|
333
|
+
subscriber.next(event);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
if (observe === HttpObserveType.ResponseHeader && event.type === HttpEventType.ResponseHeader) {
|
|
337
|
+
subscriber.next(event.response);
|
|
338
|
+
subscriber.complete();
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (event.type === HttpEventType.Response) {
|
|
342
|
+
const { response } = event;
|
|
343
|
+
if (observe === HttpObserveType.Response) {
|
|
344
|
+
subscriber.next(response);
|
|
345
|
+
subscriber.complete();
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const isOpraResponse = typeIs2.is(event.response.contentType || "", [MimeTypes.opra_response_json]);
|
|
349
|
+
if (response.status >= 400 && response.status < 600) {
|
|
350
|
+
subscriber.error(new ClientError({
|
|
351
|
+
message: response.status + " " + response.statusText,
|
|
352
|
+
status: response.status,
|
|
353
|
+
issues: isOpraResponse ? response.body.errors : void 0
|
|
354
|
+
}));
|
|
355
|
+
subscriber.complete();
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
subscriber.next(event.response.body);
|
|
359
|
+
subscriber.complete();
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
error(error) {
|
|
363
|
+
subscriber.error(error);
|
|
364
|
+
},
|
|
365
|
+
complete() {
|
|
366
|
+
subscriber.complete();
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
Object.defineProperty(this, kBackend, {
|
|
371
|
+
enumerable: false,
|
|
372
|
+
value: backend
|
|
373
|
+
});
|
|
374
|
+
Object.defineProperty(this, kContext, {
|
|
375
|
+
enumerable: false,
|
|
376
|
+
value: {
|
|
377
|
+
...init,
|
|
378
|
+
observe: HttpObserveType.Body,
|
|
379
|
+
headers: new Headers(init == null ? void 0 : init.headers)
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
clone() {
|
|
384
|
+
return new _HttpRequestObservable(this[kBackend], this[kContext]);
|
|
385
|
+
}
|
|
386
|
+
options(options) {
|
|
387
|
+
Object.assign(this[kContext], options);
|
|
388
|
+
return this;
|
|
389
|
+
}
|
|
390
|
+
header(arg0, value) {
|
|
391
|
+
const target = this[kContext].headers;
|
|
392
|
+
if (typeof arg0 === "object") {
|
|
393
|
+
const h = arg0 instanceof Headers ? arg0 : new Headers(arg0);
|
|
394
|
+
h.forEach((v, k) => {
|
|
395
|
+
if (k.toLowerCase() === "set-cookie") {
|
|
396
|
+
target.append(k, v);
|
|
397
|
+
} else
|
|
398
|
+
target.set(k, v);
|
|
399
|
+
});
|
|
400
|
+
return this;
|
|
401
|
+
}
|
|
402
|
+
if (value == null || value === "")
|
|
403
|
+
target.delete(arg0);
|
|
404
|
+
else
|
|
405
|
+
target.append(arg0, String(value));
|
|
406
|
+
return this;
|
|
407
|
+
}
|
|
408
|
+
param(arg0, value) {
|
|
409
|
+
if (value && typeof value === "object") {
|
|
410
|
+
value = JSON.stringify(value);
|
|
411
|
+
}
|
|
412
|
+
const target = this[kContext].url.searchParams;
|
|
413
|
+
if (typeof arg0 === "object") {
|
|
414
|
+
if (typeof arg0.forEach === "function") {
|
|
415
|
+
arg0.forEach((v, k) => target.set(String(k), String(v)));
|
|
416
|
+
} else {
|
|
417
|
+
Object.entries(arg0).forEach((entry) => target.set(String(entry[0]), String(entry[1])));
|
|
418
|
+
}
|
|
419
|
+
return this;
|
|
420
|
+
}
|
|
421
|
+
if (value == null)
|
|
422
|
+
target.delete(arg0);
|
|
423
|
+
else
|
|
424
|
+
target.set(arg0, String(value));
|
|
425
|
+
return this;
|
|
426
|
+
}
|
|
427
|
+
observe(observe) {
|
|
428
|
+
if (observe === this[kContext].observe)
|
|
429
|
+
return this;
|
|
430
|
+
const cloned = this.clone();
|
|
431
|
+
cloned[kContext].observe = observe || HttpObserveType.Body;
|
|
432
|
+
return cloned;
|
|
433
|
+
}
|
|
434
|
+
getBody() {
|
|
435
|
+
return lastValueFrom(this.observe(HttpObserveType.Body));
|
|
436
|
+
}
|
|
437
|
+
getResponse() {
|
|
438
|
+
return lastValueFrom(this.observe(HttpObserveType.Response));
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
__name(_HttpRequestObservable, "HttpRequestObservable");
|
|
442
|
+
var HttpRequestObservable = _HttpRequestObservable;
|
|
443
|
+
|
|
444
|
+
// ../../build/client/esm/http/http-client-base.js
|
|
445
|
+
var SPLIT_BACKSLASH_PATTERN = /^(\/*)(.+)/;
|
|
446
|
+
var _HttpClientBase = class _HttpClientBase {
|
|
447
|
+
constructor(backend) {
|
|
448
|
+
Object.defineProperty(this, kBackend, {
|
|
449
|
+
enumerable: false,
|
|
450
|
+
value: backend
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
get serviceUrl() {
|
|
454
|
+
return this[kBackend].serviceUrl;
|
|
455
|
+
}
|
|
456
|
+
async fetchDocument(options) {
|
|
457
|
+
const documentMap = {};
|
|
458
|
+
const getDocument = /* @__PURE__ */ __name(async (documentId) => {
|
|
459
|
+
const req = this.request("$schema", {
|
|
460
|
+
headers: new Headers({ accept: "application/json" })
|
|
461
|
+
});
|
|
462
|
+
if (documentId)
|
|
463
|
+
req.param("id", documentId);
|
|
464
|
+
const body2 = await req.getBody().catch((e) => {
|
|
465
|
+
e.message = "Error fetching api schema from url (" + this.serviceUrl + ").\n" + e.message;
|
|
466
|
+
throw e;
|
|
467
|
+
});
|
|
468
|
+
if (body2.references) {
|
|
469
|
+
const oldReferences = body2.references;
|
|
470
|
+
body2.references = {};
|
|
471
|
+
for (const [ns, obj] of Object.entries(oldReferences)) {
|
|
472
|
+
if (documentMap[obj.id] === null)
|
|
473
|
+
throw new Error("Circular reference detected");
|
|
474
|
+
documentMap[obj.id] = null;
|
|
475
|
+
const x = await getDocument(obj.id);
|
|
476
|
+
body2.references[ns] = documentMap[obj.id] = x;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
return body2;
|
|
480
|
+
}, "getDocument");
|
|
481
|
+
const body = await getDocument(options == null ? void 0 : options.documentId);
|
|
482
|
+
return await ApiDocumentFactory.createDocument(body).catch((e) => {
|
|
483
|
+
e.message = "Error loading api document.\n" + e.message;
|
|
484
|
+
throw e;
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
request(path, options) {
|
|
488
|
+
var _a;
|
|
489
|
+
path = ((_a = SPLIT_BACKSLASH_PATTERN.exec(path)) == null ? void 0 : _a[2]) || "";
|
|
490
|
+
const observable = new HttpRequestObservable(this[kBackend], {
|
|
491
|
+
...options,
|
|
492
|
+
method: (options == null ? void 0 : options.method) || "GET",
|
|
493
|
+
url: new URL(path, this.serviceUrl)
|
|
494
|
+
});
|
|
495
|
+
if (options == null ? void 0 : options.params)
|
|
496
|
+
observable.param(options.params);
|
|
497
|
+
return observable;
|
|
498
|
+
}
|
|
499
|
+
delete(path, options) {
|
|
500
|
+
return this.request(path, {
|
|
501
|
+
...options,
|
|
502
|
+
method: "DELETE"
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
get(path, options) {
|
|
506
|
+
return this.request(path, {
|
|
507
|
+
...options,
|
|
508
|
+
method: "GET"
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
patch(path, requestBody, options) {
|
|
512
|
+
return this.request(path, {
|
|
513
|
+
...options,
|
|
514
|
+
method: "PATCH",
|
|
515
|
+
body: requestBody
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
post(path, requestBody, options) {
|
|
519
|
+
return this.request(path, {
|
|
520
|
+
...options,
|
|
521
|
+
method: "POST",
|
|
522
|
+
body: requestBody
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
put(path, requestBody, options) {
|
|
526
|
+
return this.request(path, {
|
|
527
|
+
...options,
|
|
528
|
+
method: "PUT",
|
|
529
|
+
body: requestBody
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
__name(_HttpClientBase, "HttpClientBase");
|
|
534
|
+
var HttpClientBase = _HttpClientBase;
|
|
535
|
+
|
|
536
|
+
// ../../build/client/esm/http/http-client.js
|
|
537
|
+
var _OpraHttpClient = class _OpraHttpClient extends HttpClientBase {
|
|
538
|
+
constructor(serviceUrl, options) {
|
|
539
|
+
super(new FetchBackend(serviceUrl, options));
|
|
540
|
+
}
|
|
541
|
+
get defaults() {
|
|
542
|
+
return this[kBackend].defaults;
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
__name(_OpraHttpClient, "OpraHttpClient");
|
|
546
|
+
var OpraHttpClient = _OpraHttpClient;
|
|
547
|
+
|
|
548
|
+
// ../../build/client/esm/http/http-utils.js
|
|
549
|
+
function urlPath(strings, ...values) {
|
|
550
|
+
let str = "";
|
|
551
|
+
let i;
|
|
552
|
+
for (i = 0; i < strings.length; i++) {
|
|
553
|
+
str += strings[0] + encodeURIComponent(values[i]);
|
|
554
|
+
}
|
|
555
|
+
return str;
|
|
556
|
+
}
|
|
557
|
+
__name(urlPath, "urlPath");
|
|
558
|
+
|
|
559
|
+
// ../../build/client/esm/index.js
|
|
560
|
+
globalThis.Buffer = Buffer2;
|
|
561
|
+
export {
|
|
562
|
+
Backend,
|
|
563
|
+
ClientError,
|
|
564
|
+
FetchBackend,
|
|
565
|
+
HttpBackend,
|
|
566
|
+
HttpClientBase,
|
|
567
|
+
HttpEventType,
|
|
568
|
+
HttpObserveType,
|
|
569
|
+
HttpRequestObservable,
|
|
570
|
+
HttpResponse,
|
|
571
|
+
OpraHttpClient,
|
|
572
|
+
kBackend,
|
|
573
|
+
kClient,
|
|
574
|
+
kContext,
|
|
575
|
+
urlPath
|
|
576
|
+
};
|
package/package.json
CHANGED
|
@@ -1,57 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/client",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.23",
|
|
4
4
|
"description": "Opra Client package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "https://github.com/panates/opra.git",
|
|
10
|
-
"directory": "packages/client"
|
|
11
|
-
},
|
|
12
|
-
"scripts": {
|
|
13
|
-
"compile": "tsc",
|
|
14
|
-
"prebuild": "npm run check && npm run lint && npm run clean",
|
|
15
|
-
"build": "npm run build:cjs && npm run build:esm && npm run build:browser",
|
|
16
|
-
"build:cjs": "tsc -b tsconfig-build-cjs.json",
|
|
17
|
-
"build:esm": "tsc -b tsconfig-build-esm.json",
|
|
18
|
-
"build:browser": "node esbuild.mjs",
|
|
19
|
-
"postbuild": "cp README.md package.json ../../LICENSE ../../build/client && cp ../../package.cjs.json ../../build/client/cjs/package.json",
|
|
20
|
-
"lint": "eslint . --max-warnings=0",
|
|
21
|
-
"lint:fix": "eslint . --max-warnings=0 --fix",
|
|
22
|
-
"format": "prettier . --write --log-level=warn",
|
|
23
|
-
"check": "madge --circular src/**",
|
|
24
|
-
"test": "jest --passWithNoTests",
|
|
25
|
-
"cover": "jest --passWithNoTests --collect-coverage",
|
|
26
|
-
"clean": "npm run clean:src && npm run clean:test && npm run clean:dist && npm run clean:cover",
|
|
27
|
-
"clean:src": "ts-cleanup -s src --all",
|
|
28
|
-
"clean:test": "ts-cleanup -s test --all",
|
|
29
|
-
"clean:dist": "rimraf ../../build/client",
|
|
30
|
-
"clean:cover": "rimraf ../../coverage/client"
|
|
31
|
-
},
|
|
32
7
|
"type": "module",
|
|
33
8
|
"module": "./esm/index.js",
|
|
34
9
|
"main": "./cjs/index.js",
|
|
35
|
-
"browser": "./browser.js",
|
|
36
10
|
"types": "./types/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./esm/index.js",
|
|
14
|
+
"browser": "./cjs/index.js",
|
|
15
|
+
"require": "./cjs/index.js",
|
|
16
|
+
"types": "./types/index.d.ts"
|
|
17
|
+
},
|
|
18
|
+
"./esm": {
|
|
19
|
+
"browser": "./browser/index.mjs",
|
|
20
|
+
"types": "./types/index.d.ts",
|
|
21
|
+
"default": "./browser/index.mjs"
|
|
22
|
+
},
|
|
23
|
+
"./cjs": {
|
|
24
|
+
"browser": "./browser/index.cjs",
|
|
25
|
+
"types": "./types/index.d.ts",
|
|
26
|
+
"default": "./cjs/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./browser": {
|
|
29
|
+
"import": "./browser/index.mjs",
|
|
30
|
+
"types": "./types/index.d.ts",
|
|
31
|
+
"default": "./browser/index.cjs"
|
|
32
|
+
},
|
|
33
|
+
"./browser-cjs-min": "./browser/cjs.min.cjs",
|
|
34
|
+
"./browser-esm-min": "./browser/esm.min.mjs"
|
|
35
|
+
},
|
|
37
36
|
"dependencies": {
|
|
38
|
-
"@
|
|
39
|
-
"@browsery/highland": "^2.13.5",
|
|
40
|
-
"@browsery/http-parser": "^0.5.8",
|
|
41
|
-
"@browsery/i18next": "^23.11.5",
|
|
42
|
-
"@browsery/stream": "^4.3.0",
|
|
43
|
-
"@browsery/type-is": "^1.6.18-r2",
|
|
44
|
-
"@browsery/util": "^0.12.5",
|
|
45
|
-
"@opra/common": "^1.0.0-alpha.21",
|
|
37
|
+
"@opra/common": "^1.0.0-alpha.23",
|
|
46
38
|
"accepts": "^1.3.8",
|
|
47
|
-
"buffer": "^6.0.3",
|
|
48
39
|
"cookie": "^0.6.0",
|
|
49
|
-
"crypto-browserify": "^3.12.0",
|
|
50
40
|
"encodeurl": "^2.0.0",
|
|
51
|
-
"events": "^3.3.0",
|
|
52
41
|
"fast-tokenizer": "^1.3.0",
|
|
53
42
|
"lodash.omit": "^4.5.0",
|
|
54
|
-
"path-browserify": "^1.0.1",
|
|
55
43
|
"process": "^0.11.10",
|
|
56
44
|
"putil-isplainobject": "^1.1.5",
|
|
57
45
|
"putil-merge": "^3.12.1",
|
|
@@ -64,13 +52,30 @@
|
|
|
64
52
|
"uid": "^2.0.1"
|
|
65
53
|
},
|
|
66
54
|
"devDependencies": {
|
|
55
|
+
"@browsery/fs": "^0.4.0",
|
|
56
|
+
"@browsery/highland": "^2.13.5",
|
|
57
|
+
"@browsery/http-parser": "^0.5.8",
|
|
58
|
+
"@browsery/i18next": "^23.11.5",
|
|
59
|
+
"@browsery/stream": "^4.3.0",
|
|
60
|
+
"@browsery/type-is": "^1.6.18-r2",
|
|
61
|
+
"@browsery/util": "^0.12.5",
|
|
62
|
+
"buffer": "^6.0.3",
|
|
63
|
+
"events": "^3.3.0",
|
|
64
|
+
"path-browserify": "^1.0.1",
|
|
65
|
+
"crypto-browserify": "^3.12.0",
|
|
67
66
|
"body-parser": "^1.20.2",
|
|
68
67
|
"express": "^4.19.2"
|
|
69
68
|
},
|
|
69
|
+
"repository": {
|
|
70
|
+
"type": "git",
|
|
71
|
+
"url": "https://github.com/panates/opra.git",
|
|
72
|
+
"directory": "packages/client"
|
|
73
|
+
},
|
|
70
74
|
"sideEffects": false,
|
|
71
75
|
"files": [
|
|
72
76
|
"cjs/",
|
|
73
77
|
"esm/",
|
|
78
|
+
"browser/",
|
|
74
79
|
"types/",
|
|
75
80
|
"browser.js",
|
|
76
81
|
"LICENSE",
|
|
@@ -85,4 +90,4 @@
|
|
|
85
90
|
"request",
|
|
86
91
|
"fetch"
|
|
87
92
|
]
|
|
88
|
-
}
|
|
93
|
+
}
|