@opra/client 0.20.3 → 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 +79 -43
  2. package/cjs/{http/http-client.js → client.js} +42 -27
  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} +9 -4
  5. package/cjs/{http/http-request.js → http-request.js} +5 -5
  6. package/cjs/{http/http-response.js → http-response.js} +3 -4
  7. package/cjs/index.js +8 -8
  8. package/cjs/{http/http-singleton-node.js → singleton-node.js} +1 -1
  9. package/cjs/types.js +44 -0
  10. package/esm/{http/http-client.js → client.js} +41 -26
  11. package/esm/{http/http-collection-node.js → collection-node.js} +1 -1
  12. package/esm/{http/http-request-observable.js → http-request-observable.js} +9 -4
  13. package/esm/{http/http-request.js → http-request.js} +6 -6
  14. package/esm/{http/http-response.js → http-response.js} +3 -4
  15. package/esm/index.js +8 -8
  16. package/esm/{http/http-singleton-node.js → singleton-node.js} +1 -1
  17. package/esm/types.js +41 -0
  18. package/package.json +2 -2
  19. package/types/{http/http-client.d.ts → client.d.ts} +7 -7
  20. package/types/{http/http-collection-node.d.ts → collection-node.d.ts} +23 -23
  21. package/types/{http/http-request-observable.d.ts → http-request-observable.d.ts} +5 -5
  22. package/types/{http/http-request.d.ts → http-request.d.ts} +24 -22
  23. package/types/{http/http-response.d.ts → http-response.d.ts} +4 -5
  24. package/types/{http/http-service-base.d.ts → http-service-base.d.ts} +1 -1
  25. package/types/index.d.ts +8 -8
  26. package/types/{http/http-singleton-node.d.ts → singleton-node.d.ts} +14 -14
  27. package/types/types.d.ts +111 -0
  28. package/cjs/http/http-types.js +0 -2
  29. package/esm/http/http-types.js +0 -1
  30. package/types/http/http-types.d.ts +0 -57
  31. /package/cjs/{http/batch-request.js → batch-request.js} +0 -0
  32. /package/cjs/{http/http-service-base.js → http-service-base.js} +0 -0
  33. /package/esm/{http/batch-request.js → batch-request.js} +0 -0
  34. /package/esm/{http/http-service-base.js → http-service-base.js} +0 -0
  35. /package/types/{http/batch-request.d.ts → batch-request.d.ts} +0 -0
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, HttpHeaders, 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) {
@@ -21,8 +22,8 @@ export class OpraHttpClient {
21
22
  });
22
23
  this.defaults = {
23
24
  ...options?.defaults,
24
- headers: options?.defaults?.headers instanceof HttpHeaders
25
- ? options?.defaults?.headers : new HttpHeaders(options?.defaults?.headers),
25
+ headers: options?.defaults?.headers instanceof Headers
26
+ ? options?.defaults?.headers : new Headers(options?.defaults?.headers),
26
27
  params: options?.defaults?.params instanceof HttpParams
27
28
  ? options?.defaults?.params : new HttpParams(options?.defaults?.params)
28
29
  };
@@ -37,10 +38,10 @@ 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
- headers: new HttpHeaders({ 'accept': 'application/json' })
44
+ headers: new Headers({ 'accept': 'application/json' })
44
45
  })));
45
46
  return await promise
46
47
  .then(async (body) => {
@@ -118,13 +119,13 @@ export class OpraHttpClient {
118
119
  else if (Buffer.isBuffer(request.body)) {
119
120
  contentType = 'application/octet-stream';
120
121
  body = request.body;
121
- request.headers.set('Content-Size', request.body.length);
122
+ request.headers.set('Content-Size', String(request.body.length));
122
123
  delete request.duplex;
123
124
  }
124
125
  else if (isBlob(request.body)) {
125
126
  contentType = request.body.type || 'application/octet-stream';
126
127
  body = request.body;
127
- request.headers.set('Content-Size', request.body.length);
128
+ request.headers.set('Content-Size', String(request.body.length));
128
129
  delete request.duplex;
129
130
  }
130
131
  else {
@@ -146,9 +147,13 @@ export class OpraHttpClient {
146
147
  await interceptor(ctx, request);
147
148
  }
148
149
  }
149
- if (observe === 'events')
150
- subscriber.next({ event: 'sent', request });
151
- const response = await this._fetch(url, { ...request, headers: request.headers.toObject() });
150
+ if (observe === HttpObserveType.Events)
151
+ subscriber.next({
152
+ observe,
153
+ request,
154
+ event: HttpEventType.Sent,
155
+ });
156
+ const response = await this._fetch(url, request);
152
157
  await this._handleResponse(observe, subscriber, request, response);
153
158
  })().catch(error => subscriber.error(error));
154
159
  });
@@ -160,8 +165,8 @@ export class OpraHttpClient {
160
165
  return new HttpResponse(init);
161
166
  }
162
167
  async _handleResponse(observe, subscriber, request, fetchResponse, ctx) {
163
- const headers = new HttpHeaders(fetchResponse.headers);
164
- if (observe === 'events') {
168
+ const headers = fetchResponse.headers;
169
+ if (observe === HttpObserveType.Events) {
165
170
  const response = this._createResponse({
166
171
  url: fetchResponse.url,
167
172
  headers,
@@ -169,18 +174,23 @@ 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) {
176
- if (JSON_CONTENT_TYPE_PATTERN.test(fetchResponse.headers.get('Content-Type') || '')) {
186
+ if (JSON_CONTENT_TYPE_PATTERN.test(headers.get('Content-Type') || '')) {
177
187
  body = await fetchResponse.json();
178
188
  if (typeof body === 'string')
179
189
  body = JSON.parse(body);
180
190
  }
181
- else if (TEXT_CONTENT_TYPE_PATTERN.test(fetchResponse.headers.get('Content-Type') || ''))
191
+ else if (TEXT_CONTENT_TYPE_PATTERN.test(headers.get('Content-Type') || ''))
182
192
  body = await fetchResponse.text();
183
- else if (FORMDATA_CONTENT_TYPE_PATTERN.test(fetchResponse.headers.get('Content-Type') || ''))
193
+ else if (FORMDATA_CONTENT_TYPE_PATTERN.test(headers.get('Content-Type') || ''))
184
194
  body = await fetchResponse.formData();
185
195
  else {
186
196
  const buf = await fetchResponse.arrayBuffer();
@@ -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,19 +1,24 @@
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);
13
14
  this.contentId = uid(6);
14
15
  }
15
16
  header(name, value) {
16
- this[kRequest].headers.append(name, value);
17
+ const headers = this[kRequest].headers;
18
+ if (Array.isArray(value))
19
+ value.forEach(v => headers.append(name, String(v)));
20
+ else
21
+ headers.append(name, value);
17
22
  return this;
18
23
  }
19
24
  param(name, value) {
@@ -21,7 +26,7 @@ export class HttpRequestObservable extends Observable {
21
26
  return this;
22
27
  }
23
28
  async fetch(observe) {
24
- return lastValueFrom(this[kHttpClientContext].send(observe || 'body', this[kRequest]));
29
+ return lastValueFrom(this[kHttpClientContext].send(observe || HttpObserveType.Body, this[kRequest]));
25
30
  }
26
31
  with(cb) {
27
32
  cb(this);
@@ -1,5 +1,5 @@
1
1
  /// <reference lib="dom" />
2
- import { HttpHeaders, OpraURL } from '@opra/common';
2
+ import { OpraURL } from '@opra/common';
3
3
  const directCopyProperties = ['cache', 'credentials', 'destination', 'headers', 'integrity',
4
4
  'keepalive', 'mode', 'redirect', 'referrer', 'referrerPolicy'];
5
5
  export class HttpRequest {
@@ -7,7 +7,7 @@ export class HttpRequest {
7
7
  this.cache = init?.cache || 'default';
8
8
  this.credentials = init?.credentials || 'same-origin';
9
9
  this.destination = init?.destination || '';
10
- this.headers = new HttpHeaders(init?.headers);
10
+ this.headers = init?.headers instanceof Headers ? init.headers : new Headers(init?.headers);
11
11
  this.integrity = init?.integrity || '';
12
12
  this.keepalive = init?.keepalive ?? false;
13
13
  this.method = (init?.method || 'GET').toUpperCase();
@@ -51,9 +51,9 @@ export class HttpRequest {
51
51
  this[k] = update[k];
52
52
  });
53
53
  if (update.headers) {
54
- const h = update.headers instanceof HttpHeaders
54
+ const h = update.headers instanceof Headers
55
55
  ? update.headers
56
- : new HttpHeaders(update.headers);
56
+ : new Headers(update.headers);
57
57
  h.forEach((v, k) => {
58
58
  if (k.toLowerCase() === 'set-cookie') {
59
59
  this.headers.append(k, v);
@@ -69,9 +69,9 @@ export class HttpRequest {
69
69
  this[k] = src[k];
70
70
  });
71
71
  if (src.headers) {
72
- const h = src.headers instanceof HttpHeaders
72
+ const h = src.headers instanceof Headers
73
73
  ? src.headers
74
- : new HttpHeaders(src.headers);
74
+ : new Headers(src.headers);
75
75
  h.forEach((v, k) => {
76
76
  if (k.toLowerCase() === 'set-cookie') {
77
77
  this.headers.append(k, v);
@@ -1,19 +1,18 @@
1
- import { HttpHeaders } from '@opra/common';
2
1
  export class HttpResponse {
3
2
  constructor(init) {
4
3
  /**
5
4
  * Returns true if response has body to be received
6
5
  */
7
6
  this.hasBody = false;
8
- this.headers = init?.headers instanceof HttpHeaders ? init?.headers
9
- : new HttpHeaders(init?.headers);
7
+ this.headers = init?.headers instanceof Headers ? init?.headers
8
+ : new Headers(init?.headers);
10
9
  this.status = init?.status || 200;
11
10
  this.statusText = init?.statusText || 'OK';
12
11
  this.url = init?.url || null;
13
12
  this.ok = this.status >= 200 && this.status < 300;
14
13
  this.body = init?.body;
15
14
  this.hasBody = init?.body != null || !!init?.hasBody;
16
- this.totalMatches = init?.totalMatches;
15
+ this.totalCount = init?.totalCount;
17
16
  }
18
17
  clone(update) {
19
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.20.3",
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.20.3",
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
- import { ApiDocument, HttpHeaders, HttpParams } from '@opra/common';
4
- import { HttpCollectionNode } from './http-collection-node.js';
3
+ import { ApiDocument, HttpParams } from '@opra/common';
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
@@ -29,7 +29,7 @@ export declare class OpraHttpClient {
29
29
  responseInterceptors: ResponseInterceptor[];
30
30
  };
31
31
  defaults: StrictOmit<HttpRequestDefaults, 'headers' | 'params'> & {
32
- headers: HttpHeaders;
32
+ headers: Headers;
33
33
  params: HttpParams;
34
34
  };
35
35
  constructor(serviceUrl: string, options?: OpraHttpClientOptions);
@@ -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 {};
@@ -1,21 +1,23 @@
1
1
  /// <reference lib="dom" />
2
- import { HttpHeaders, HttpParams, OpraURL, OpraURLPath } from '@opra/common';
3
- export interface HttpRequestInit {
4
- cache?: RequestCache;
5
- credentials?: RequestCredentials;
6
- destination?: RequestDestination;
7
- headers?: HttpHeaders.Initiator;
8
- integrity?: string;
9
- keepalive?: boolean;
10
- method?: string;
11
- mode?: RequestMode;
12
- params?: HttpParams.Initiator;
13
- redirect?: RequestRedirect;
14
- referrer?: string;
15
- referrerPolicy?: ReferrerPolicy;
16
- signal?: AbortSignal;
17
- url?: string;
18
- body?: any;
2
+ import { HttpParams, OpraURL, OpraURLPath } from '@opra/common';
3
+ export declare namespace HttpRequest {
4
+ interface Initiator {
5
+ cache?: RequestCache;
6
+ credentials?: RequestCredentials;
7
+ destination?: RequestDestination;
8
+ headers?: HeadersInit;
9
+ integrity?: string;
10
+ keepalive?: boolean;
11
+ method?: string;
12
+ mode?: RequestMode;
13
+ params?: HttpParams.Initiator;
14
+ redirect?: RequestRedirect;
15
+ referrer?: string;
16
+ referrerPolicy?: ReferrerPolicy;
17
+ signal?: AbortSignal;
18
+ url?: string;
19
+ body?: any;
20
+ }
19
21
  }
20
22
  export declare class HttpRequest {
21
23
  /** Returns the cache mode associated with request, which is a string indicating
@@ -30,7 +32,7 @@ export declare class HttpRequest {
30
32
  /** Returns a Headers object consisting of the headers associated with request.
31
33
  * Note that headers added in the network layer by the user agent will not be accounted for in this object,
32
34
  * e.g., the "Host" header. */
33
- headers: HttpHeaders;
35
+ headers: Headers;
34
36
  /** Returns request's subresource integrity metadata, which is a cryptographic
35
37
  * hash of the resource being fetched.
36
38
  * Its value consists of multiple hashes separated by whitespace. [SRI] */
@@ -60,7 +62,7 @@ export declare class HttpRequest {
60
62
  /** Body of the http request */
61
63
  body?: any;
62
64
  duplex?: 'half';
63
- constructor(init?: HttpRequestInit);
65
+ constructor(init?: HttpRequest.Initiator);
64
66
  /** Returns the URL of request as a string. */
65
67
  get url(): string;
66
68
  set url(value: string);
@@ -68,7 +70,7 @@ export declare class HttpRequest {
68
70
  get params(): HttpParams;
69
71
  /** Returns the path part of URL as OpraURLPath */
70
72
  get path(): OpraURLPath;
71
- clone(...update: (HttpRequest | HttpRequestInit)[]): HttpRequest;
72
- merge(update: HttpRequest | HttpRequestInit): void;
73
- inset(src: HttpRequest | HttpRequestInit): void;
73
+ clone(...update: (HttpRequest | HttpRequest.Initiator)[]): HttpRequest;
74
+ merge(update: HttpRequest | HttpRequest.Initiator): void;
75
+ inset(src: HttpRequest | HttpRequest.Initiator): void;
74
76
  }