@opra/client 0.21.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/browser.js +60 -27
  2. package/cjs/{http/http-client.js → client.js} +32 -17
  3. package/cjs/{http/http-collection-node.js → collection-node.js} +1 -1
  4. package/cjs/{http/http-request-observable.js → http-request-observable.js} +4 -3
  5. package/cjs/{http/http-response.js → http-response.js} +1 -1
  6. package/cjs/index.js +8 -8
  7. package/cjs/{http/http-singleton-node.js → singleton-node.js} +1 -1
  8. package/cjs/types.js +44 -0
  9. package/esm/{http/http-client.js → client.js} +31 -16
  10. package/esm/{http/http-collection-node.js → collection-node.js} +1 -1
  11. package/esm/{http/http-request-observable.js → http-request-observable.js} +4 -3
  12. package/esm/{http/http-response.js → http-response.js} +1 -1
  13. package/esm/index.js +8 -8
  14. package/esm/{http/http-singleton-node.js → singleton-node.js} +1 -1
  15. package/esm/types.js +41 -0
  16. package/package.json +2 -2
  17. package/types/{http/http-client.d.ts → client.d.ts} +5 -5
  18. package/types/{http/http-collection-node.d.ts → collection-node.d.ts} +23 -23
  19. package/types/{http/http-request-observable.d.ts → http-request-observable.d.ts} +5 -5
  20. package/types/{http/http-response.d.ts → http-response.d.ts} +2 -2
  21. package/types/{http/http-service-base.d.ts → http-service-base.d.ts} +1 -1
  22. package/types/index.d.ts +8 -8
  23. package/types/{http/http-singleton-node.d.ts → singleton-node.d.ts} +14 -14
  24. package/types/types.d.ts +111 -0
  25. package/cjs/http/http-types.js +0 -2
  26. package/esm/http/http-types.js +0 -1
  27. package/types/http/http-types.d.ts +0 -57
  28. /package/cjs/{http/batch-request.js → batch-request.js} +0 -0
  29. /package/cjs/{http/http-request.js → http-request.js} +0 -0
  30. /package/cjs/{http/http-service-base.js → http-service-base.js} +0 -0
  31. /package/esm/{http/batch-request.js → batch-request.js} +0 -0
  32. /package/esm/{http/http-request.js → http-request.js} +0 -0
  33. /package/esm/{http/http-service-base.js → http-service-base.js} +0 -0
  34. /package/types/{http/batch-request.d.ts → batch-request.d.ts} +0 -0
  35. /package/types/{http/http-request.d.ts → http-request.d.ts} +0 -0
package/browser.js CHANGED
@@ -6,6 +6,11 @@
6
6
  var __defProp = Object.defineProperty;
7
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
8
 
9
+ // ../../build/client/esm/client.js
10
+ import { lastValueFrom as lastValueFrom2, Observable as Observable2 } from "rxjs";
11
+ import { isReadableStreamLike } from "rxjs/internal/util/isReadableStreamLike";
12
+ import { DocumentFactory, HttpHeaderCodes, HttpParams, isBlob, joinPath } from "@opra/common";
13
+
9
14
  // ../../build/client/esm/client-error.js
10
15
  var ClientError = class extends Error {
11
16
  static {
@@ -24,22 +29,17 @@ var ClientError = class extends Error {
24
29
  }
25
30
  };
26
31
 
27
- // ../../build/client/esm/http/http-client.js
28
- import { lastValueFrom as lastValueFrom2, Observable as Observable2 } from "rxjs";
29
- import { isReadableStreamLike } from "rxjs/internal/util/isReadableStreamLike";
30
- import { DocumentFactory, HttpHeaderCodes, HttpParams, isBlob, joinPath } from "@opra/common";
31
-
32
32
  // ../../build/client/esm/constants.js
33
33
  var JSON_CONTENT_TYPE_PATTERN = /^application\/([\w-]+\+)?\bjson\b/i;
34
34
  var TEXT_CONTENT_TYPE_PATTERN = /^text\/.*$/i;
35
35
  var FORMDATA_CONTENT_TYPE_PATTERN = /^multipart\/\bform-data\b/i;
36
36
  var kHttpClientContext = Symbol("kContext");
37
37
 
38
- // ../../build/client/esm/http/http-request-observable.js
38
+ // ../../build/client/esm/http-request-observable.js
39
39
  import { lastValueFrom, Observable } from "rxjs";
40
40
  import { uid } from "@opra/common";
41
41
 
42
- // ../../build/client/esm/http/http-request.js
42
+ // ../../build/client/esm/http-request.js
43
43
  import { OpraURL } from "@opra/common";
44
44
  var directCopyProperties = [
45
45
  "cache",
@@ -131,7 +131,24 @@ var HttpRequest = class _HttpRequest {
131
131
  }
132
132
  };
133
133
 
134
- // ../../build/client/esm/http/http-request-observable.js
134
+ // ../../build/client/esm/types.js
135
+ var HttpObserveType;
136
+ (function(HttpObserveType2) {
137
+ HttpObserveType2["Response"] = "response";
138
+ HttpObserveType2["Body"] = "body";
139
+ HttpObserveType2["Events"] = "events";
140
+ })(HttpObserveType || (HttpObserveType = {}));
141
+ var HttpEventType;
142
+ (function(HttpEventType2) {
143
+ HttpEventType2["Sent"] = "sent";
144
+ HttpEventType2["UploadProgress"] = "upload-progress";
145
+ HttpEventType2["ResponseHeader"] = "response-header";
146
+ HttpEventType2["DownloadProgress"] = "download-progress";
147
+ HttpEventType2["Response"] = "response";
148
+ HttpEventType2["Custom"] = "custom";
149
+ })(HttpEventType || (HttpEventType = {}));
150
+
151
+ // ../../build/client/esm/http-request-observable.js
135
152
  var kRequest = Symbol("kRequest");
136
153
  var HttpRequestObservable = class extends Observable {
137
154
  static {
@@ -139,7 +156,7 @@ var HttpRequestObservable = class extends Observable {
139
156
  }
140
157
  constructor(context, options) {
141
158
  super((subscriber) => {
142
- context.send(options?.observe || "body", this[kRequest]).subscribe(subscriber);
159
+ context.send(options?.observe || HttpObserveType.Body, this[kRequest]).subscribe(subscriber);
143
160
  });
144
161
  this[kHttpClientContext] = context;
145
162
  this[kRequest] = new HttpRequest(options?.http);
@@ -158,7 +175,7 @@ var HttpRequestObservable = class extends Observable {
158
175
  return this;
159
176
  }
160
177
  async fetch(observe) {
161
- return lastValueFrom(this[kHttpClientContext].send(observe || "body", this[kRequest]));
178
+ return lastValueFrom(this[kHttpClientContext].send(observe || HttpObserveType.Body, this[kRequest]));
162
179
  }
163
180
  with(cb) {
164
181
  cb(this);
@@ -168,7 +185,7 @@ var HttpRequestObservable = class extends Observable {
168
185
  HttpRequestObservable.kContext = kHttpClientContext;
169
186
  HttpRequestObservable.kRequest = kRequest;
170
187
 
171
- // ../../build/client/esm/http/http-collection-node.js
188
+ // ../../build/client/esm/collection-node.js
172
189
  var HttpCollectionNode = class {
173
190
  static {
174
191
  __name(this, "HttpCollectionNode");
@@ -277,7 +294,7 @@ var HttpCollectionNode = class {
277
294
  }
278
295
  };
279
296
 
280
- // ../../build/client/esm/http/http-response.js
297
+ // ../../build/client/esm/http-response.js
281
298
  var HttpResponse = class _HttpResponse {
282
299
  static {
283
300
  __name(this, "HttpResponse");
@@ -291,14 +308,14 @@ var HttpResponse = class _HttpResponse {
291
308
  this.ok = this.status >= 200 && this.status < 300;
292
309
  this.body = init?.body;
293
310
  this.hasBody = init?.body != null || !!init?.hasBody;
294
- this.totalMatches = init?.totalMatches;
311
+ this.totalCount = init?.totalCount;
295
312
  }
296
313
  clone(update) {
297
314
  return new _HttpResponse({ ...this, ...update });
298
315
  }
299
316
  };
300
317
 
301
- // ../../build/client/esm/http/http-singleton-node.js
318
+ // ../../build/client/esm/singleton-node.js
302
319
  var HttpSingletonNode = class {
303
320
  static {
304
321
  __name(this, "HttpSingletonNode");
@@ -360,7 +377,7 @@ var HttpSingletonNode = class {
360
377
  }
361
378
  };
362
379
 
363
- // ../../build/client/esm/http/http-client.js
380
+ // ../../build/client/esm/client.js
364
381
  var kAssets = Symbol("kAssets");
365
382
  var OpraHttpClient = class {
366
383
  static {
@@ -392,7 +409,7 @@ var OpraHttpClient = class {
392
409
  if (promise) {
393
410
  return promise;
394
411
  }
395
- this[kAssets].metadataPromise = promise = lastValueFrom2(this._sendRequest("body", new HttpRequest({
412
+ this[kAssets].metadataPromise = promise = lastValueFrom2(this._sendRequest(HttpObserveType.Body, new HttpRequest({
396
413
  method: "GET",
397
414
  url: "$metadata",
398
415
  headers: new Headers({ "accept": "application/json" })
@@ -492,8 +509,12 @@ var OpraHttpClient = class {
492
509
  await interceptor(ctx, request);
493
510
  }
494
511
  }
495
- if (observe === "events")
496
- subscriber.next({ event: "sent", request });
512
+ if (observe === HttpObserveType.Events)
513
+ subscriber.next({
514
+ observe,
515
+ request,
516
+ event: HttpEventType.Sent
517
+ });
497
518
  const response = await this._fetch(url, request);
498
519
  await this._handleResponse(observe, subscriber, request, response);
499
520
  })().catch((error) => subscriber.error(error));
@@ -507,7 +528,7 @@ var OpraHttpClient = class {
507
528
  }
508
529
  async _handleResponse(observe, subscriber, request, fetchResponse, ctx) {
509
530
  const headers = fetchResponse.headers;
510
- if (observe === "events") {
531
+ if (observe === HttpObserveType.Events) {
511
532
  const response2 = this._createResponse({
512
533
  url: fetchResponse.url,
513
534
  headers,
@@ -515,7 +536,12 @@ var OpraHttpClient = class {
515
536
  statusText: fetchResponse.statusText,
516
537
  hasBody: !!fetchResponse.body
517
538
  });
518
- subscriber.next({ event: "headers-received", request, response: response2 });
539
+ subscriber.next({
540
+ observe,
541
+ request,
542
+ event: HttpEventType.ResponseHeader,
543
+ response: response2
544
+ });
519
545
  }
520
546
  let body;
521
547
  if (fetchResponse.body) {
@@ -533,7 +559,7 @@ var OpraHttpClient = class {
533
559
  body = buf;
534
560
  }
535
561
  }
536
- if (observe === "body" && fetchResponse.status >= 400 && fetchResponse.status < 600) {
562
+ if (observe === HttpObserveType.Body && fetchResponse.status >= 400 && fetchResponse.status < 600) {
537
563
  subscriber.error(new ClientError({
538
564
  message: fetchResponse.status + " " + fetchResponse.statusText,
539
565
  status: fetchResponse.status,
@@ -549,8 +575,8 @@ var OpraHttpClient = class {
549
575
  statusText: fetchResponse.statusText,
550
576
  body
551
577
  };
552
- if (fetchResponse.headers.has(HttpHeaderCodes.X_Opra_Total_Matches))
553
- responseInit.totalMatches = parseInt(fetchResponse.headers.get(HttpHeaderCodes.X_Opra_Total_Matches), 10);
578
+ if (fetchResponse.headers.has(HttpHeaderCodes.X_Total_Count))
579
+ responseInit.totalCount = parseInt(fetchResponse.headers.get(HttpHeaderCodes.X_Total_Count), 10);
554
580
  const response = this._createResponse(responseInit);
555
581
  if (ctx) {
556
582
  const responseInterceptors = [
@@ -561,11 +587,16 @@ var OpraHttpClient = class {
561
587
  await interceptor(ctx, observe, request);
562
588
  }
563
589
  }
564
- if (observe === "body") {
590
+ if (observe === HttpObserveType.Body) {
565
591
  subscriber.next(body);
566
592
  } else {
567
- if (observe === "events")
568
- subscriber.next({ event: "response", request, response });
593
+ if (observe === HttpObserveType.Events)
594
+ subscriber.next({
595
+ observe,
596
+ request,
597
+ event: HttpEventType.Response,
598
+ response
599
+ });
569
600
  else
570
601
  subscriber.next(response);
571
602
  }
@@ -574,7 +605,7 @@ var OpraHttpClient = class {
574
605
  };
575
606
  OpraHttpClient.kAssets = kAssets;
576
607
 
577
- // ../../build/client/esm/http/http-service-base.js
608
+ // ../../build/client/esm/http-service-base.js
578
609
  var HttpServiceBase = class {
579
610
  static {
580
611
  __name(this, "HttpServiceBase");
@@ -586,6 +617,8 @@ var HttpServiceBase = class {
586
617
  export {
587
618
  ClientError,
588
619
  HttpCollectionNode,
620
+ HttpEventType,
621
+ HttpObserveType,
589
622
  HttpRequest,
590
623
  HttpRequestObservable,
591
624
  HttpResponse,
@@ -4,12 +4,13 @@ exports.OpraHttpClient = void 0;
4
4
  const rxjs_1 = require("rxjs");
5
5
  const isReadableStreamLike_1 = require("rxjs/internal/util/isReadableStreamLike");
6
6
  const common_1 = require("@opra/common");
7
- const client_error_js_1 = require("../client-error.js");
8
- const constants_js_1 = require("../constants.js");
9
- const http_collection_node_js_1 = require("./http-collection-node.js");
7
+ const client_error_js_1 = require("./client-error.js");
8
+ const collection_node_js_1 = require("./collection-node.js");
9
+ const constants_js_1 = require("./constants.js");
10
10
  const http_request_js_1 = require("./http-request.js");
11
11
  const http_response_js_1 = require("./http-response.js");
12
- const http_singleton_node_js_1 = require("./http-singleton-node.js");
12
+ const singleton_node_js_1 = require("./singleton-node.js");
13
+ const types_js_1 = require("./types.js");
13
14
  const kAssets = Symbol('kAssets');
14
15
  class OpraHttpClient {
15
16
  constructor(serviceUrl, options) {
@@ -40,7 +41,7 @@ class OpraHttpClient {
40
41
  if (promise) {
41
42
  return promise;
42
43
  }
43
- this[kAssets].metadataPromise = promise = (0, rxjs_1.lastValueFrom)(this._sendRequest('body', new http_request_js_1.HttpRequest({
44
+ this[kAssets].metadataPromise = promise = (0, rxjs_1.lastValueFrom)(this._sendRequest(types_js_1.HttpObserveType.Body, new http_request_js_1.HttpRequest({
44
45
  method: 'GET',
45
46
  url: '$metadata',
46
47
  headers: new Headers({ 'accept': 'application/json' })
@@ -78,7 +79,7 @@ class OpraHttpClient {
78
79
  // ],
79
80
  responseInterceptors: []
80
81
  };
81
- return new http_collection_node_js_1.HttpCollectionNode(ctx);
82
+ return new collection_node_js_1.HttpCollectionNode(ctx);
82
83
  }
83
84
  singleton(resourceName) {
84
85
  // If name argument is a class, we extract name from the class
@@ -97,7 +98,7 @@ class OpraHttpClient {
97
98
  // ],
98
99
  responseInterceptors: []
99
100
  };
100
- return new http_singleton_node_js_1.HttpSingletonNode(ctx);
101
+ return new singleton_node_js_1.HttpSingletonNode(ctx);
101
102
  }
102
103
  _sendRequest(observe, request, ctx) {
103
104
  return new rxjs_1.Observable(subscriber => {
@@ -149,8 +150,12 @@ class OpraHttpClient {
149
150
  await interceptor(ctx, request);
150
151
  }
151
152
  }
152
- if (observe === 'events')
153
- subscriber.next({ event: 'sent', request });
153
+ if (observe === types_js_1.HttpObserveType.Events)
154
+ subscriber.next({
155
+ observe,
156
+ request,
157
+ event: types_js_1.HttpEventType.Sent,
158
+ });
154
159
  const response = await this._fetch(url, request);
155
160
  await this._handleResponse(observe, subscriber, request, response);
156
161
  })().catch(error => subscriber.error(error));
@@ -164,7 +169,7 @@ class OpraHttpClient {
164
169
  }
165
170
  async _handleResponse(observe, subscriber, request, fetchResponse, ctx) {
166
171
  const headers = fetchResponse.headers;
167
- if (observe === 'events') {
172
+ if (observe === types_js_1.HttpObserveType.Events) {
168
173
  const response = this._createResponse({
169
174
  url: fetchResponse.url,
170
175
  headers,
@@ -172,7 +177,12 @@ class OpraHttpClient {
172
177
  statusText: fetchResponse.statusText,
173
178
  hasBody: !!fetchResponse.body
174
179
  });
175
- subscriber.next({ event: 'headers-received', request, response });
180
+ subscriber.next({
181
+ observe,
182
+ request,
183
+ event: types_js_1.HttpEventType.ResponseHeader,
184
+ response
185
+ });
176
186
  }
177
187
  let body;
178
188
  if (fetchResponse.body) {
@@ -191,7 +201,7 @@ class OpraHttpClient {
191
201
  body = buf;
192
202
  }
193
203
  }
194
- if (observe === 'body' && fetchResponse.status >= 400 && fetchResponse.status < 600) {
204
+ if (observe === types_js_1.HttpObserveType.Body && fetchResponse.status >= 400 && fetchResponse.status < 600) {
195
205
  subscriber.error(new client_error_js_1.ClientError({
196
206
  message: fetchResponse.status + ' ' + fetchResponse.statusText,
197
207
  status: fetchResponse.status,
@@ -207,8 +217,8 @@ class OpraHttpClient {
207
217
  statusText: fetchResponse.statusText,
208
218
  body
209
219
  };
210
- if (fetchResponse.headers.has(common_1.HttpHeaderCodes.X_Opra_Total_Matches))
211
- responseInit.totalMatches = parseInt(fetchResponse.headers.get(common_1.HttpHeaderCodes.X_Opra_Total_Matches), 10);
220
+ if (fetchResponse.headers.has(common_1.HttpHeaderCodes.X_Total_Count))
221
+ responseInit.totalCount = parseInt(fetchResponse.headers.get(common_1.HttpHeaderCodes.X_Total_Count), 10);
212
222
  const response = this._createResponse(responseInit);
213
223
  if (ctx) {
214
224
  const responseInterceptors = [
@@ -219,12 +229,17 @@ class OpraHttpClient {
219
229
  await interceptor(ctx, observe, request);
220
230
  }
221
231
  }
222
- if (observe === 'body') {
232
+ if (observe === types_js_1.HttpObserveType.Body) {
223
233
  subscriber.next(body);
224
234
  }
225
235
  else {
226
- if (observe === 'events')
227
- subscriber.next({ event: 'response', request, response });
236
+ if (observe === types_js_1.HttpObserveType.Events)
237
+ subscriber.next({
238
+ observe,
239
+ request,
240
+ event: types_js_1.HttpEventType.Response,
241
+ response
242
+ });
228
243
  else
229
244
  subscriber.next(response);
230
245
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HttpCollectionNode = void 0;
4
- const constants_js_1 = require("../constants.js");
4
+ const constants_js_1 = require("./constants.js");
5
5
  const http_request_observable_js_1 = require("./http-request-observable.js");
6
6
  class HttpCollectionNode {
7
7
  constructor(context) {
@@ -3,13 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HttpRequestObservable = void 0;
4
4
  const rxjs_1 = require("rxjs");
5
5
  const common_1 = require("@opra/common");
6
- const constants_js_1 = require("../constants.js");
6
+ const constants_js_1 = require("./constants.js");
7
7
  const http_request_js_1 = require("./http-request.js");
8
+ const types_js_1 = require("./types.js");
8
9
  const kRequest = Symbol('kRequest');
9
10
  class HttpRequestObservable extends rxjs_1.Observable {
10
11
  constructor(context, options) {
11
12
  super((subscriber) => {
12
- context.send(options?.observe || 'body', this[kRequest]).subscribe((subscriber));
13
+ context.send(options?.observe || types_js_1.HttpObserveType.Body, this[kRequest]).subscribe((subscriber));
13
14
  });
14
15
  this[constants_js_1.kHttpClientContext] = context;
15
16
  this[kRequest] = new http_request_js_1.HttpRequest(options?.http);
@@ -28,7 +29,7 @@ class HttpRequestObservable extends rxjs_1.Observable {
28
29
  return this;
29
30
  }
30
31
  async fetch(observe) {
31
- return (0, rxjs_1.lastValueFrom)(this[constants_js_1.kHttpClientContext].send(observe || 'body', this[kRequest]));
32
+ return (0, rxjs_1.lastValueFrom)(this[constants_js_1.kHttpClientContext].send(observe || types_js_1.HttpObserveType.Body, this[kRequest]));
32
33
  }
33
34
  with(cb) {
34
35
  cb(this);
@@ -15,7 +15,7 @@ class HttpResponse {
15
15
  this.ok = this.status >= 200 && this.status < 300;
16
16
  this.body = init?.body;
17
17
  this.hasBody = init?.body != null || !!init?.hasBody;
18
- this.totalMatches = init?.totalMatches;
18
+ this.totalCount = init?.totalCount;
19
19
  }
20
20
  clone(update) {
21
21
  return new HttpResponse({ ...this, ...update });
package/cjs/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./client.js"), exports);
4
5
  tslib_1.__exportStar(require("./client-error.js"), exports);
5
- tslib_1.__exportStar(require("./http/http-client.js"), exports);
6
- tslib_1.__exportStar(require("./http/http-collection-node.js"), exports);
7
- tslib_1.__exportStar(require("./http/http-request.js"), exports);
8
- tslib_1.__exportStar(require("./http/http-request-observable.js"), exports);
9
- tslib_1.__exportStar(require("./http/http-response.js"), exports);
10
- tslib_1.__exportStar(require("./http/http-service-base.js"), exports);
11
- tslib_1.__exportStar(require("./http/http-singleton-node.js"), exports);
12
- tslib_1.__exportStar(require("./http/http-types.js"), exports);
6
+ tslib_1.__exportStar(require("./collection-node.js"), exports);
7
+ tslib_1.__exportStar(require("./http-request.js"), exports);
8
+ tslib_1.__exportStar(require("./http-request-observable.js"), exports);
9
+ tslib_1.__exportStar(require("./http-response.js"), exports);
10
+ tslib_1.__exportStar(require("./http-service-base.js"), exports);
11
+ tslib_1.__exportStar(require("./singleton-node.js"), exports);
12
+ tslib_1.__exportStar(require("./types.js"), exports);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HttpSingletonNode = void 0;
4
- const constants_js_1 = require("../constants.js");
4
+ const constants_js_1 = require("./constants.js");
5
5
  const http_request_observable_js_1 = require("./http-request-observable.js");
6
6
  class HttpSingletonNode {
7
7
  constructor(context) {
package/cjs/types.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpEventType = exports.HttpObserveType = void 0;
4
+ /* **********************
5
+ * Enums
6
+ *********************** */
7
+ var HttpObserveType;
8
+ (function (HttpObserveType) {
9
+ HttpObserveType["Response"] = "response";
10
+ HttpObserveType["Body"] = "body";
11
+ HttpObserveType["Events"] = "events";
12
+ })(HttpObserveType || (exports.HttpObserveType = HttpObserveType = {}));
13
+ /**
14
+ * Type enumeration for the different kinds of `HttpEvent`.
15
+ */
16
+ var HttpEventType;
17
+ (function (HttpEventType) {
18
+ /**
19
+ * The request was sent out over the wire.
20
+ */
21
+ HttpEventType["Sent"] = "sent";
22
+ /**
23
+ * An upload progress event was received.
24
+ *
25
+ * Note: The `FetchBackend` doesn't support progress report on uploads.
26
+ */
27
+ HttpEventType["UploadProgress"] = "upload-progress";
28
+ /**
29
+ * The response status code and headers were received.
30
+ */
31
+ HttpEventType["ResponseHeader"] = "response-header";
32
+ /**
33
+ * A download progress event was received.
34
+ */
35
+ HttpEventType["DownloadProgress"] = "download-progress";
36
+ /**
37
+ * The full response including the body was received.
38
+ */
39
+ HttpEventType["Response"] = "response";
40
+ /**
41
+ * A custom event from an interceptor or a backend.
42
+ */
43
+ HttpEventType["Custom"] = "custom";
44
+ })(HttpEventType || (exports.HttpEventType = HttpEventType = {}));
@@ -1,12 +1,13 @@
1
1
  import { lastValueFrom, Observable } from 'rxjs';
2
2
  import { isReadableStreamLike } from 'rxjs/internal/util/isReadableStreamLike';
3
- import { DocumentFactory, HttpHeaderCodes, HttpParams, isBlob, joinPath, } from '@opra/common';
4
- import { ClientError } from '../client-error.js';
5
- import { FORMDATA_CONTENT_TYPE_PATTERN, JSON_CONTENT_TYPE_PATTERN, TEXT_CONTENT_TYPE_PATTERN } from '../constants.js';
6
- import { HttpCollectionNode } from './http-collection-node.js';
3
+ import { DocumentFactory, HttpHeaderCodes, HttpParams, isBlob, joinPath } from '@opra/common';
4
+ import { ClientError } from './client-error.js';
5
+ import { HttpCollectionNode } from './collection-node.js';
6
+ import { FORMDATA_CONTENT_TYPE_PATTERN, JSON_CONTENT_TYPE_PATTERN, TEXT_CONTENT_TYPE_PATTERN } from './constants.js';
7
7
  import { HttpRequest } from './http-request.js';
8
8
  import { HttpResponse } from './http-response.js';
9
- import { HttpSingletonNode } from './http-singleton-node.js';
9
+ import { HttpSingletonNode } from './singleton-node.js';
10
+ import { HttpEventType, HttpObserveType, } from './types.js';
10
11
  const kAssets = Symbol('kAssets');
11
12
  export class OpraHttpClient {
12
13
  constructor(serviceUrl, options) {
@@ -37,7 +38,7 @@ export class OpraHttpClient {
37
38
  if (promise) {
38
39
  return promise;
39
40
  }
40
- this[kAssets].metadataPromise = promise = lastValueFrom(this._sendRequest('body', new HttpRequest({
41
+ this[kAssets].metadataPromise = promise = lastValueFrom(this._sendRequest(HttpObserveType.Body, new HttpRequest({
41
42
  method: 'GET',
42
43
  url: '$metadata',
43
44
  headers: new Headers({ 'accept': 'application/json' })
@@ -146,8 +147,12 @@ export class OpraHttpClient {
146
147
  await interceptor(ctx, request);
147
148
  }
148
149
  }
149
- if (observe === 'events')
150
- subscriber.next({ event: 'sent', request });
150
+ if (observe === HttpObserveType.Events)
151
+ subscriber.next({
152
+ observe,
153
+ request,
154
+ event: HttpEventType.Sent,
155
+ });
151
156
  const response = await this._fetch(url, request);
152
157
  await this._handleResponse(observe, subscriber, request, response);
153
158
  })().catch(error => subscriber.error(error));
@@ -161,7 +166,7 @@ export class OpraHttpClient {
161
166
  }
162
167
  async _handleResponse(observe, subscriber, request, fetchResponse, ctx) {
163
168
  const headers = fetchResponse.headers;
164
- if (observe === 'events') {
169
+ if (observe === HttpObserveType.Events) {
165
170
  const response = this._createResponse({
166
171
  url: fetchResponse.url,
167
172
  headers,
@@ -169,7 +174,12 @@ export class OpraHttpClient {
169
174
  statusText: fetchResponse.statusText,
170
175
  hasBody: !!fetchResponse.body
171
176
  });
172
- subscriber.next({ event: 'headers-received', request, response });
177
+ subscriber.next({
178
+ observe,
179
+ request,
180
+ event: HttpEventType.ResponseHeader,
181
+ response
182
+ });
173
183
  }
174
184
  let body;
175
185
  if (fetchResponse.body) {
@@ -188,7 +198,7 @@ export class OpraHttpClient {
188
198
  body = buf;
189
199
  }
190
200
  }
191
- if (observe === 'body' && fetchResponse.status >= 400 && fetchResponse.status < 600) {
201
+ if (observe === HttpObserveType.Body && fetchResponse.status >= 400 && fetchResponse.status < 600) {
192
202
  subscriber.error(new ClientError({
193
203
  message: fetchResponse.status + ' ' + fetchResponse.statusText,
194
204
  status: fetchResponse.status,
@@ -204,8 +214,8 @@ export class OpraHttpClient {
204
214
  statusText: fetchResponse.statusText,
205
215
  body
206
216
  };
207
- if (fetchResponse.headers.has(HttpHeaderCodes.X_Opra_Total_Matches))
208
- responseInit.totalMatches = parseInt(fetchResponse.headers.get(HttpHeaderCodes.X_Opra_Total_Matches), 10);
217
+ if (fetchResponse.headers.has(HttpHeaderCodes.X_Total_Count))
218
+ responseInit.totalCount = parseInt(fetchResponse.headers.get(HttpHeaderCodes.X_Total_Count), 10);
209
219
  const response = this._createResponse(responseInit);
210
220
  if (ctx) {
211
221
  const responseInterceptors = [
@@ -216,12 +226,17 @@ export class OpraHttpClient {
216
226
  await interceptor(ctx, observe, request);
217
227
  }
218
228
  }
219
- if (observe === 'body') {
229
+ if (observe === HttpObserveType.Body) {
220
230
  subscriber.next(body);
221
231
  }
222
232
  else {
223
- if (observe === 'events')
224
- subscriber.next({ event: 'response', request, response });
233
+ if (observe === HttpObserveType.Events)
234
+ subscriber.next({
235
+ observe,
236
+ request,
237
+ event: HttpEventType.Response,
238
+ response
239
+ });
225
240
  else
226
241
  subscriber.next(response);
227
242
  }
@@ -1,4 +1,4 @@
1
- import { kHttpClientContext } from '../constants.js';
1
+ import { kHttpClientContext } from './constants.js';
2
2
  import { HttpRequestObservable } from './http-request-observable.js';
3
3
  export class HttpCollectionNode {
4
4
  constructor(context) {
@@ -1,12 +1,13 @@
1
1
  import { lastValueFrom, Observable } from 'rxjs';
2
2
  import { uid } from '@opra/common';
3
- import { kHttpClientContext } from '../constants.js';
3
+ import { kHttpClientContext } from './constants.js';
4
4
  import { HttpRequest } from './http-request.js';
5
+ import { HttpObserveType } from './types.js';
5
6
  const kRequest = Symbol('kRequest');
6
7
  export class HttpRequestObservable extends Observable {
7
8
  constructor(context, options) {
8
9
  super((subscriber) => {
9
- context.send(options?.observe || 'body', this[kRequest]).subscribe((subscriber));
10
+ context.send(options?.observe || HttpObserveType.Body, this[kRequest]).subscribe((subscriber));
10
11
  });
11
12
  this[kHttpClientContext] = context;
12
13
  this[kRequest] = new HttpRequest(options?.http);
@@ -25,7 +26,7 @@ export class HttpRequestObservable extends Observable {
25
26
  return this;
26
27
  }
27
28
  async fetch(observe) {
28
- return lastValueFrom(this[kHttpClientContext].send(observe || 'body', this[kRequest]));
29
+ return lastValueFrom(this[kHttpClientContext].send(observe || HttpObserveType.Body, this[kRequest]));
29
30
  }
30
31
  with(cb) {
31
32
  cb(this);
@@ -12,7 +12,7 @@ export class HttpResponse {
12
12
  this.ok = this.status >= 200 && this.status < 300;
13
13
  this.body = init?.body;
14
14
  this.hasBody = init?.body != null || !!init?.hasBody;
15
- this.totalMatches = init?.totalMatches;
15
+ this.totalCount = init?.totalCount;
16
16
  }
17
17
  clone(update) {
18
18
  return new HttpResponse({ ...this, ...update });
package/esm/index.js CHANGED
@@ -1,9 +1,9 @@
1
+ export * from './client.js';
1
2
  export * from './client-error.js';
2
- export * from './http/http-client.js';
3
- export * from './http/http-collection-node.js';
4
- export * from './http/http-request.js';
5
- export * from './http/http-request-observable.js';
6
- export * from './http/http-response.js';
7
- export * from './http/http-service-base.js';
8
- export * from './http/http-singleton-node.js';
9
- export * from './http/http-types.js';
3
+ export * from './collection-node.js';
4
+ export * from './http-request.js';
5
+ export * from './http-request-observable.js';
6
+ export * from './http-response.js';
7
+ export * from './http-service-base.js';
8
+ export * from './singleton-node.js';
9
+ export * from './types.js';
@@ -1,4 +1,4 @@
1
- import { kHttpClientContext } from '../constants.js';
1
+ import { kHttpClientContext } from './constants.js';
2
2
  import { HttpRequestObservable } from './http-request-observable.js';
3
3
  export class HttpSingletonNode {
4
4
  constructor(context) {
package/esm/types.js ADDED
@@ -0,0 +1,41 @@
1
+ /* **********************
2
+ * Enums
3
+ *********************** */
4
+ export var HttpObserveType;
5
+ (function (HttpObserveType) {
6
+ HttpObserveType["Response"] = "response";
7
+ HttpObserveType["Body"] = "body";
8
+ HttpObserveType["Events"] = "events";
9
+ })(HttpObserveType || (HttpObserveType = {}));
10
+ /**
11
+ * Type enumeration for the different kinds of `HttpEvent`.
12
+ */
13
+ export var HttpEventType;
14
+ (function (HttpEventType) {
15
+ /**
16
+ * The request was sent out over the wire.
17
+ */
18
+ HttpEventType["Sent"] = "sent";
19
+ /**
20
+ * An upload progress event was received.
21
+ *
22
+ * Note: The `FetchBackend` doesn't support progress report on uploads.
23
+ */
24
+ HttpEventType["UploadProgress"] = "upload-progress";
25
+ /**
26
+ * The response status code and headers were received.
27
+ */
28
+ HttpEventType["ResponseHeader"] = "response-header";
29
+ /**
30
+ * A download progress event was received.
31
+ */
32
+ HttpEventType["DownloadProgress"] = "download-progress";
33
+ /**
34
+ * The full response including the body was received.
35
+ */
36
+ HttpEventType["Response"] = "response";
37
+ /**
38
+ * A custom event from an interceptor or a backend.
39
+ */
40
+ HttpEventType["Custom"] = "custom";
41
+ })(HttpEventType || (HttpEventType = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/client",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "description": "Opra Client package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -46,7 +46,7 @@
46
46
  "@browsery/i18next": "^0.6.0",
47
47
  "@browsery/stream": "^0.5.0",
48
48
  "@browsery/util": "^0.4.0",
49
- "@opra/common": "^0.21.0",
49
+ "@opra/common": "^0.22.0",
50
50
  "accepts": "^1.3.8",
51
51
  "buffer": "^6.0.3",
52
52
  "cookie": "^0.5.0",
@@ -1,11 +1,11 @@
1
1
  import { Observable, Subscriber } from 'rxjs';
2
2
  import { StrictOmit, Type } from 'ts-gems';
3
3
  import { ApiDocument, HttpParams } from '@opra/common';
4
- import { HttpCollectionNode } from './http-collection-node.js';
4
+ import { HttpCollectionNode } from './collection-node.js';
5
5
  import { HttpRequest } from './http-request.js';
6
6
  import { HttpResponse } from './http-response.js';
7
- import { HttpSingletonNode } from './http-singleton-node.js';
8
- import { HttpClientContext, HttpEvent, HttpRequestDefaults, ObserveType, RequestInterceptor, ResponseInterceptor } from './http-types.js';
7
+ import { HttpSingletonNode } from './singleton-node.js';
8
+ import { HttpClientContext, HttpEvent, HttpObserveType, HttpRequestDefaults, RequestInterceptor, ResponseInterceptor } from './types.js';
9
9
  export interface OpraHttpClientOptions {
10
10
  /**
11
11
  * Opra Service Metadata Document
@@ -37,9 +37,9 @@ export declare class OpraHttpClient {
37
37
  getMetadata(): Promise<ApiDocument>;
38
38
  collection<TType = any>(resourceName: string | Type<TType>): HttpCollectionNode<TType>;
39
39
  singleton<TType = any>(resourceName: string | Type<TType>): HttpSingletonNode<TType>;
40
- protected _sendRequest<TBody>(observe: ObserveType, request: HttpRequest, ctx?: HttpClientContext): Observable<HttpResponse<TBody> | TBody | HttpEvent>;
40
+ protected _sendRequest<TBody>(observe: HttpObserveType, request: HttpRequest, ctx?: HttpClientContext): Observable<HttpResponse<TBody> | TBody | HttpEvent>;
41
41
  protected _fetch(url: string, init?: RequestInit): Promise<Response>;
42
42
  protected _createResponse(init?: HttpResponse.Initiator): HttpResponse;
43
- protected _handleResponse(observe: ObserveType, subscriber: Subscriber<any>, request: HttpRequest, fetchResponse: Response, ctx?: HttpClientContext): Promise<void>;
43
+ protected _handleResponse(observe: HttpObserveType, subscriber: Subscriber<any>, request: HttpRequest, fetchResponse: Response, ctx?: HttpClientContext): Promise<void>;
44
44
  }
45
45
  export {};
@@ -1,10 +1,10 @@
1
1
  import { StrictOmit } from 'ts-gems';
2
2
  import type { PartialInput } from '@opra/common';
3
3
  import { OpraFilter } from '@opra/common';
4
- import { kHttpClientContext } from '../constants.js';
4
+ import { kHttpClientContext } from './constants.js';
5
5
  import { HttpRequestObservable } from './http-request-observable.js';
6
6
  import { HttpResponse } from './http-response.js';
7
- import { HttpClientContext, HttpEvent } from './http-types.js';
7
+ import { HttpClientContext, HttpEvent, HttpObserveType } from './types.js';
8
8
  export declare namespace HttpCollectionNode {
9
9
  interface CreateOptions extends HttpRequestObservable.Options {
10
10
  pick?: string[];
@@ -51,67 +51,67 @@ export declare class HttpCollectionNode<TType, TResponseExt = {}> {
51
51
  protected [kHttpClientContext]: HttpClientContext;
52
52
  constructor(context: HttpClientContext);
53
53
  create(data: PartialInput<TType>, options?: StrictOmit<HttpCollectionNode.CreateOptions, 'observe'> & {
54
- observe?: 'body';
54
+ observe?: HttpObserveType.Body;
55
55
  }): HttpRequestObservable<TType, TType, TResponseExt>;
56
56
  create(data: PartialInput<TType>, options?: StrictOmit<HttpCollectionNode.CreateOptions, 'observe'> & {
57
- observe: 'response';
57
+ observe: HttpObserveType.Response;
58
58
  }): HttpRequestObservable<HttpResponse<TType>, TType, TResponseExt>;
59
59
  create(data: PartialInput<TType>, options?: StrictOmit<HttpCollectionNode.CreateOptions, 'observe'> & {
60
- observe: 'events';
60
+ observe: HttpObserveType.Events;
61
61
  }): HttpRequestObservable<HttpEvent, TType, TResponseExt>;
62
62
  delete(id: any, options?: StrictOmit<HttpCollectionNode.DeleteOptions, 'observe'> & {
63
- observe?: 'body';
63
+ observe?: HttpObserveType.Body;
64
64
  }): HttpRequestObservable<never, never, TResponseExt>;
65
65
  delete(id: any, options?: StrictOmit<HttpCollectionNode.DeleteOptions, 'observe'> & {
66
- observe: 'response';
66
+ observe: HttpObserveType.Response;
67
67
  }): HttpRequestObservable<HttpResponse<never>, never, TResponseExt>;
68
68
  delete(id: any, options?: StrictOmit<HttpCollectionNode.DeleteOptions, 'observe'> & {
69
- observe: 'events';
69
+ observe: HttpObserveType.Events;
70
70
  }): HttpRequestObservable<HttpEvent, never, TResponseExt>;
71
71
  deleteMany(options?: StrictOmit<HttpCollectionNode.DeleteManyOptions, 'observe'> & {
72
- observe?: 'body';
72
+ observe?: HttpObserveType.Body;
73
73
  }): HttpRequestObservable<HttpCollectionNode.DeleteManyBody, HttpCollectionNode.DeleteManyBody, TResponseExt>;
74
74
  deleteMany(options?: StrictOmit<HttpCollectionNode.DeleteManyOptions, 'observe'> & {
75
- observe: 'response';
75
+ observe: HttpObserveType.Response;
76
76
  }): HttpRequestObservable<HttpResponse<HttpCollectionNode.DeleteManyBody>, HttpCollectionNode.DeleteManyBody, TResponseExt>;
77
77
  deleteMany(options?: StrictOmit<HttpCollectionNode.DeleteManyOptions, 'observe'> & {
78
- observe: 'events';
78
+ observe: HttpObserveType.Events;
79
79
  }): HttpRequestObservable<HttpEvent, HttpCollectionNode.DeleteManyBody, TResponseExt>;
80
80
  get(id: any, options?: StrictOmit<HttpCollectionNode.GetOptions, 'observe'> & {
81
- observe?: 'body';
81
+ observe?: HttpObserveType.Body;
82
82
  }): HttpRequestObservable<TType, TType, TResponseExt>;
83
83
  get(id: any, options?: StrictOmit<HttpCollectionNode.GetOptions, 'observe'> & {
84
- observe: 'response';
84
+ observe: HttpObserveType.Response;
85
85
  }): HttpRequestObservable<HttpResponse<TType>, TType, TResponseExt>;
86
86
  get(id: any, options?: StrictOmit<HttpCollectionNode.GetOptions, 'observe'> & {
87
- observe: 'events';
87
+ observe: HttpObserveType.Events;
88
88
  }): HttpRequestObservable<HttpEvent, TType, TResponseExt>;
89
89
  findMany(options?: StrictOmit<HttpCollectionNode.FindManyOptions, 'observe'>): HttpRequestObservable<TType[], TType, TResponseExt>;
90
90
  findMany(options?: StrictOmit<HttpCollectionNode.FindManyOptions, 'observe'> & {
91
- observe?: 'body';
91
+ observe?: HttpObserveType.Body;
92
92
  }): HttpRequestObservable<TType[], TType, TResponseExt>;
93
93
  findMany(options?: StrictOmit<HttpCollectionNode.FindManyOptions, 'observe'> & {
94
- observe: 'response';
94
+ observe: HttpObserveType.Response;
95
95
  }): HttpRequestObservable<HttpResponse<TType[]>, TType, TResponseExt>;
96
96
  findMany(options?: StrictOmit<HttpCollectionNode.FindManyOptions, 'observe'> & {
97
- observe: 'events';
97
+ observe: HttpObserveType.Events;
98
98
  }): HttpRequestObservable<HttpEvent, TType, TResponseExt>;
99
99
  update(id: any, data: PartialInput<TType>, options?: StrictOmit<HttpCollectionNode.UpdateOptions, 'observe'> & {
100
- observe?: 'body';
100
+ observe?: HttpObserveType.Body;
101
101
  }): HttpRequestObservable<TType, TType, TResponseExt>;
102
102
  update(id: any, data: PartialInput<TType>, options?: StrictOmit<HttpCollectionNode.UpdateOptions, 'observe'> & {
103
- observe: 'response';
103
+ observe: HttpObserveType.Response;
104
104
  }): HttpRequestObservable<HttpResponse<TType>, TType, TResponseExt>;
105
105
  update(id: any, data: PartialInput<TType>, options?: StrictOmit<HttpCollectionNode.UpdateOptions, 'observe'> & {
106
- observe: 'events';
106
+ observe: HttpObserveType.Events;
107
107
  }): HttpRequestObservable<HttpEvent, TType, TResponseExt>;
108
108
  updateMany(data: PartialInput<TType>, options?: StrictOmit<HttpCollectionNode.UpdateManyOptions, 'observe'> & {
109
- observe?: 'body';
109
+ observe?: HttpObserveType.Body;
110
110
  }): HttpRequestObservable<HttpCollectionNode.UpdateManyBody, HttpCollectionNode.DeleteManyBody, TResponseExt>;
111
111
  updateMany(data: PartialInput<TType>, options?: StrictOmit<HttpCollectionNode.UpdateManyOptions, 'observe'> & {
112
- observe: 'response';
112
+ observe: HttpObserveType.Response;
113
113
  }): HttpRequestObservable<HttpResponse<HttpCollectionNode.UpdateManyBody>, HttpCollectionNode.DeleteManyBody, TResponseExt>;
114
114
  updateMany(data: PartialInput<TType>, options?: StrictOmit<HttpCollectionNode.UpdateManyOptions, 'observe'> & {
115
- observe: 'events';
115
+ observe: HttpObserveType.Events;
116
116
  }): HttpRequestObservable<HttpEvent, HttpCollectionNode.UpdateManyBody, TResponseExt>;
117
117
  }
@@ -1,13 +1,13 @@
1
1
  import { Observable } from 'rxjs';
2
2
  import { ClientHttpHeaders } from '@opra/common';
3
- import { kHttpClientContext } from '../constants.js';
3
+ import { kHttpClientContext } from './constants.js';
4
4
  import { HttpRequest } from './http-request.js';
5
5
  import { HttpResponse } from './http-response.js';
6
- import { HttpClientContext, HttpRequestDefaults, ObserveType } from './http-types.js';
6
+ import { HttpClientContext, HttpObserveType, HttpRequestDefaults } from './types.js';
7
7
  declare const kRequest: unique symbol;
8
8
  export declare namespace HttpRequestObservable {
9
9
  interface Options {
10
- observe?: ObserveType;
10
+ observe?: HttpObserveType;
11
11
  http?: HttpRequestDefaults;
12
12
  }
13
13
  }
@@ -21,8 +21,8 @@ export declare class HttpRequestObservable<T, TBody, TResponseExt = {}> extends
21
21
  header<K extends keyof ClientHttpHeaders>(name: K, value: ClientHttpHeaders[K]): this;
22
22
  param(name: string, value: any): this;
23
23
  fetch(): Promise<TBody>;
24
- fetch(observe: 'body'): Promise<TBody>;
25
- fetch(observe: 'response'): Promise<HttpResponse<TBody> & TResponseExt>;
24
+ fetch(observe: HttpObserveType.Body): Promise<TBody>;
25
+ fetch(observe: HttpObserveType.Response): Promise<HttpResponse<TBody> & TResponseExt>;
26
26
  with(cb: (_this: this) => void): this;
27
27
  }
28
28
  export {};
@@ -6,7 +6,7 @@ export declare namespace HttpResponse {
6
6
  url?: string;
7
7
  body?: any;
8
8
  hasBody?: boolean;
9
- totalMatches?: number;
9
+ totalCount?: number;
10
10
  }
11
11
  }
12
12
  export declare class HttpResponse<TBody = any> {
@@ -34,7 +34,7 @@ export declare class HttpResponse<TBody = any> {
34
34
  * Body contents
35
35
  */
36
36
  readonly body: TBody | null;
37
- readonly totalMatches?: number;
37
+ readonly totalCount?: number;
38
38
  /**
39
39
  * Returns true if response has body to be received
40
40
  */
@@ -1,4 +1,4 @@
1
- import { OpraHttpClient } from './http-client.js';
1
+ import { OpraHttpClient } from './client.js';
2
2
  export declare class HttpServiceBase {
3
3
  $client: OpraHttpClient;
4
4
  constructor($client: OpraHttpClient);
package/types/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
+ export * from './client.js';
1
2
  export * from './client-error.js';
2
- export * from './http/http-client.js';
3
- export * from './http/http-collection-node.js';
4
- export * from './http/http-request.js';
5
- export * from './http/http-request-observable.js';
6
- export * from './http/http-response.js';
7
- export * from './http/http-service-base.js';
8
- export * from './http/http-singleton-node.js';
9
- export * from './http/http-types.js';
3
+ export * from './collection-node.js';
4
+ export * from './http-request.js';
5
+ export * from './http-request-observable.js';
6
+ export * from './http-response.js';
7
+ export * from './http-service-base.js';
8
+ export * from './singleton-node.js';
9
+ export * from './types.js';
@@ -1,9 +1,9 @@
1
1
  import { StrictOmit } from 'ts-gems';
2
2
  import { PartialInput } from '@opra/common';
3
- import { kHttpClientContext } from '../constants.js';
3
+ import { kHttpClientContext } from './constants.js';
4
4
  import { HttpRequestObservable } from './http-request-observable.js';
5
5
  import { HttpResponse } from './http-response.js';
6
- import { HttpClientContext, HttpEvent } from './http-types.js';
6
+ import { HttpClientContext, HttpEvent, HttpObserveType } from './types.js';
7
7
  export declare namespace HttpSingletonNode {
8
8
  interface CreateOptions extends HttpRequestObservable.Options {
9
9
  pick?: string[];
@@ -27,39 +27,39 @@ export declare class HttpSingletonNode<TType, TResponseExt = {}> {
27
27
  protected [kHttpClientContext]: HttpClientContext;
28
28
  constructor(context: HttpClientContext);
29
29
  create(data: PartialInput<TType>, options?: StrictOmit<HttpSingletonNode.CreateOptions, 'observe'> & {
30
- observe?: 'body';
30
+ observe?: HttpObserveType.Body;
31
31
  }): HttpRequestObservable<TType, TType, TResponseExt>;
32
32
  create(data: PartialInput<TType>, options?: StrictOmit<HttpSingletonNode.CreateOptions, 'observe'> & {
33
- observe: 'response';
33
+ observe: HttpObserveType.Response;
34
34
  }): HttpRequestObservable<HttpResponse<TType>, TType, TResponseExt>;
35
35
  create(data: PartialInput<TType>, options?: StrictOmit<HttpSingletonNode.CreateOptions, 'observe'> & {
36
- observe: 'events';
36
+ observe: HttpObserveType.Events;
37
37
  }): HttpRequestObservable<HttpEvent, TType, TResponseExt>;
38
38
  delete(options?: StrictOmit<HttpSingletonNode.DeleteOptions, 'observe'> & {
39
- observe?: 'body';
39
+ observe?: HttpObserveType.Body;
40
40
  }): HttpRequestObservable<never, never, TResponseExt>;
41
41
  delete(options?: StrictOmit<HttpSingletonNode.DeleteOptions, 'observe'> & {
42
- observe: 'response';
42
+ observe: HttpObserveType.Response;
43
43
  }): HttpRequestObservable<HttpResponse<never>, never, TResponseExt>;
44
44
  delete(options?: StrictOmit<HttpSingletonNode.DeleteOptions, 'observe'> & {
45
- observe: 'events';
45
+ observe: HttpObserveType.Events;
46
46
  }): HttpRequestObservable<HttpEvent, never, TResponseExt>;
47
47
  get(options?: StrictOmit<HttpSingletonNode.GetOptions, 'observe'> & {
48
- observe?: 'body';
48
+ observe?: HttpObserveType.Body;
49
49
  }): HttpRequestObservable<TType, TType, TResponseExt>;
50
50
  get(options?: StrictOmit<HttpSingletonNode.GetOptions, 'observe'> & {
51
- observe: 'response';
51
+ observe: HttpObserveType.Response;
52
52
  }): HttpRequestObservable<HttpResponse<TType>, TType, TResponseExt>;
53
53
  get(options?: StrictOmit<HttpSingletonNode.GetOptions, 'observe'> & {
54
- observe: 'events';
54
+ observe: HttpObserveType.Events;
55
55
  }): HttpRequestObservable<HttpEvent, TType, TResponseExt>;
56
56
  update(data: PartialInput<TType>, options?: StrictOmit<HttpSingletonNode.UpdateOptions, 'observe'> & {
57
- observe?: 'body';
57
+ observe?: HttpObserveType.Body;
58
58
  }): HttpRequestObservable<TType, TType, TResponseExt>;
59
59
  update(data: PartialInput<TType>, options?: StrictOmit<HttpSingletonNode.UpdateOptions, 'observe'> & {
60
- observe: 'response';
60
+ observe: HttpObserveType.Response;
61
61
  }): HttpRequestObservable<HttpResponse<TType>, TType, TResponseExt>;
62
62
  update(data: PartialInput<TType>, options?: StrictOmit<HttpSingletonNode.UpdateOptions, 'observe'> & {
63
- observe: 'events';
63
+ observe: HttpObserveType.Events;
64
64
  }): HttpRequestObservable<HttpEvent, TType, TResponseExt>;
65
65
  }
@@ -0,0 +1,111 @@
1
+ import type { Observable } from 'rxjs';
2
+ import type { HttpParams } from '@opra/common';
3
+ import type { OpraHttpClient } from './client';
4
+ import type { HttpRequest } from './http-request.js';
5
+ import type { HttpResponse } from './http-response.js';
6
+ export type HttpRequestHandler = (observe: HttpObserveType, request: HttpRequest) => Observable<any>;
7
+ export type RequestInterceptor = (ctx: HttpClientContext, request: HttpRequest) => void | Promise<void>;
8
+ export type ResponseInterceptor = ((ctx: HttpClientContext, observe: HttpObserveType, response: any) => void | Promise<void>);
9
+ export type HttpEvent = HttpSentEvent | HttpDownloadProgressEvent | HttpUploadProgressEvent | HttpResponseHeaderEvent | HttpResponseEvent | HttpUserEvent;
10
+ export declare enum HttpObserveType {
11
+ Response = "response",
12
+ Body = "body",
13
+ Events = "events"
14
+ }
15
+ /**
16
+ * Type enumeration for the different kinds of `HttpEvent`.
17
+ */
18
+ export declare enum HttpEventType {
19
+ /**
20
+ * The request was sent out over the wire.
21
+ */
22
+ Sent = "sent",
23
+ /**
24
+ * An upload progress event was received.
25
+ *
26
+ * Note: The `FetchBackend` doesn't support progress report on uploads.
27
+ */
28
+ UploadProgress = "upload-progress",
29
+ /**
30
+ * The response status code and headers were received.
31
+ */
32
+ ResponseHeader = "response-header",
33
+ /**
34
+ * A download progress event was received.
35
+ */
36
+ DownloadProgress = "download-progress",
37
+ /**
38
+ * The full response including the body was received.
39
+ */
40
+ Response = "response",
41
+ /**
42
+ * A custom event from an interceptor or a backend.
43
+ */
44
+ Custom = "custom"
45
+ }
46
+ export interface HttpClientContext {
47
+ readonly client: OpraHttpClient;
48
+ readonly resourceName: string;
49
+ send: HttpRequestHandler;
50
+ requestInterceptors?: RequestInterceptor[];
51
+ responseInterceptors?: ResponseInterceptor[];
52
+ }
53
+ export interface HttpRequestDefaults extends Partial<Pick<HttpRequest, 'cache' | 'credentials' | 'destination' | 'integrity' | 'keepalive' | 'mode' | 'redirect' | 'referrer' | 'referrerPolicy'>> {
54
+ headers?: HeadersInit;
55
+ params?: HttpParams.Initiator;
56
+ }
57
+ interface HttpEventBase {
58
+ observe: HttpObserveType;
59
+ request: HttpRequest;
60
+ event: HttpEventType;
61
+ }
62
+ export interface HttpSentEvent extends HttpEventBase {
63
+ event: HttpEventType.Sent;
64
+ }
65
+ export interface HttpDownloadProgressEvent extends HttpEventBase {
66
+ event: HttpEventType.DownloadProgress;
67
+ /**
68
+ * Number of bytes uploaded
69
+ */
70
+ loaded: number;
71
+ /**
72
+ * Total number of bytes to upload.
73
+ * Depending on the request, this may not be computable and thus may not be present.
74
+ */
75
+ total?: number;
76
+ }
77
+ export interface HttpUploadProgressEvent extends HttpEventBase {
78
+ event: HttpEventType.UploadProgress;
79
+ /**
80
+ * Response object
81
+ */
82
+ response: HttpResponse;
83
+ /**
84
+ * Number of bytes uploaded
85
+ */
86
+ loaded: number;
87
+ /**
88
+ * Total number of bytes to upload.
89
+ * Depending on the request, this may not be computable and thus may not be present.
90
+ */
91
+ total?: number;
92
+ }
93
+ export interface HttpResponseHeaderEvent extends HttpEventBase {
94
+ event: HttpEventType.ResponseHeader;
95
+ /**
96
+ * Response object
97
+ */
98
+ response: HttpResponse;
99
+ }
100
+ export interface HttpResponseEvent extends HttpEventBase {
101
+ event: HttpEventType.Response;
102
+ /**
103
+ * Response object
104
+ */
105
+ response: HttpResponse;
106
+ }
107
+ export interface HttpUserEvent extends HttpEventBase {
108
+ event: HttpEventType.Custom;
109
+ [key: string | number | symbol]: any;
110
+ }
111
+ export {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +0,0 @@
1
- export {};
@@ -1,57 +0,0 @@
1
- import type { Observable } from 'rxjs';
2
- import type { HttpParams } from '@opra/common';
3
- import type { OpraHttpClient } from './http-client.js';
4
- import type { HttpRequest } from './http-request.js';
5
- import type { HttpResponse } from './http-response.js';
6
- export type ObserveType = 'response' | 'body' | 'events';
7
- export type HttpEventType = 'request' | 'upload-progress' | 'headers-received' | 'download-progress' | 'response';
8
- export type HttpRequestHandler = (observe: ObserveType, request: HttpRequest) => Observable<any>;
9
- export type RequestInterceptor = (ctx: HttpClientContext, request: HttpRequest) => void | Promise<void>;
10
- export type ResponseInterceptor = ((ctx: HttpClientContext, observe: ObserveType, response: any) => void | Promise<void>);
11
- export interface HttpClientContext {
12
- readonly client: OpraHttpClient;
13
- readonly resourceName: string;
14
- send: HttpRequestHandler;
15
- requestInterceptors?: RequestInterceptor[];
16
- responseInterceptors?: ResponseInterceptor[];
17
- }
18
- export type HttpRequestDefaults = Partial<Pick<HttpRequest, 'cache' | 'credentials' | 'destination' | 'integrity' | 'keepalive' | 'mode' | 'redirect' | 'referrer' | 'referrerPolicy'>> & {
19
- headers?: HeadersInit;
20
- params?: HttpParams.Initiator;
21
- };
22
- export interface HttpEvent {
23
- event: HttpEventType | string;
24
- request: HttpRequest;
25
- }
26
- export interface HttpHeadersReceivedEvent extends HttpEvent {
27
- event: 'headers-received';
28
- response: HttpResponse;
29
- }
30
- export interface HttpResponseEvent extends HttpEvent {
31
- event: 'response';
32
- response: HttpResponse;
33
- }
34
- export interface HttpUploadProgressEvent extends HttpEvent {
35
- event: 'upload-progress';
36
- /**
37
- * Number of bytes uploaded
38
- */
39
- loaded: number;
40
- /**
41
- * Total number of bytes to upload.
42
- * Depending on the request, this may not be computable and thus may not be present.
43
- */
44
- total?: number;
45
- }
46
- export interface HttpDownloadProgressEvent extends HttpEvent {
47
- event: 'download-progress';
48
- /**
49
- * Number of bytes download
50
- */
51
- loaded: number;
52
- /**
53
- * Total number of bytes to download.
54
- * Depending on the response, this may not be computable and thus may not be present.
55
- */
56
- total?: number;
57
- }
File without changes
File without changes
File without changes
File without changes