@opra/client 0.25.5 → 0.26.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.
- package/browser.js +410 -463
- package/cjs/client.js +49 -234
- package/cjs/constants.js +2 -2
- package/cjs/enums/http-observable-type.enum.js +10 -0
- package/cjs/enums/index.js +4 -0
- package/cjs/impl/collection-node.js +119 -0
- package/cjs/impl/http-request-observable.js +246 -0
- package/cjs/impl/http-request.js +28 -0
- package/cjs/impl/http-service-base.js +16 -0
- package/cjs/impl/singleton-node.js +62 -0
- package/cjs/index.js +12 -6
- package/cjs/interfaces/client-context.interface.js +2 -0
- package/cjs/interfaces/http-event.interface.js +35 -0
- package/cjs/interfaces/http-request-defaults.interface.js +2 -0
- package/cjs/interfaces/index.js +5 -0
- package/cjs/types.js +0 -42
- package/esm/client.js +51 -236
- package/esm/constants.js +1 -1
- package/esm/enums/http-observable-type.enum.js +7 -0
- package/esm/enums/index.js +1 -0
- package/esm/impl/collection-node.js +115 -0
- package/esm/impl/http-request-observable.js +242 -0
- package/esm/impl/http-request.js +24 -0
- package/esm/impl/http-service-base.js +12 -0
- package/esm/impl/singleton-node.js +58 -0
- package/esm/index.js +9 -6
- package/esm/interfaces/client-context.interface.js +1 -0
- package/esm/interfaces/http-event.interface.js +32 -0
- package/esm/interfaces/http-request-defaults.interface.js +1 -0
- package/esm/interfaces/index.js +2 -0
- package/esm/types.js +1 -41
- package/package.json +2 -2
- package/types/client.d.ts +26 -38
- package/types/constants.d.ts +1 -1
- package/types/enums/http-observable-type.enum.d.ts +6 -0
- package/types/enums/index.d.ts +1 -0
- package/types/impl/collection-node.d.ts +66 -0
- package/types/impl/http-request-observable.d.ts +45 -0
- package/types/{http-request.d.ts → impl/http-request.d.ts} +23 -27
- package/types/impl/http-service-base.d.ts +7 -0
- package/types/impl/singleton-node.d.ts +35 -0
- package/types/index.d.ts +9 -6
- package/types/interfaces/client-context.interface.d.ts +13 -0
- package/types/interfaces/http-event.interface.d.ts +88 -0
- package/types/interfaces/http-request-defaults.interface.d.ts +6 -0
- package/types/interfaces/index.d.ts +2 -0
- package/types/types.d.ts +4 -111
- package/cjs/collection-node.js +0 -124
- package/cjs/http-request-observable.js +0 -40
- package/cjs/http-request.js +0 -86
- package/cjs/http-service-base.js +0 -9
- package/cjs/singleton-node.js +0 -68
- package/esm/collection-node.js +0 -120
- package/esm/http-request-observable.js +0 -36
- package/esm/http-request.js +0 -82
- package/esm/http-service-base.js +0 -5
- package/esm/singleton-node.js +0 -64
- package/types/collection-node.d.ts +0 -117
- package/types/http-request-observable.d.ts +0 -23
- package/types/http-service-base.d.ts +0 -5
- package/types/singleton-node.d.ts +0 -65
- /package/cjs/{http-response.js → impl/http-response.js} +0 -0
- /package/esm/{http-response.js → impl/http-response.js} +0 -0
- /package/types/{http-response.d.ts → impl/http-response.d.ts} +0 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/// <reference lib="dom" />
|
|
2
2
|
import { OpraURL } from '@opra/common';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @namespace HttpRequest
|
|
5
|
+
*/
|
|
4
6
|
export declare namespace HttpRequest {
|
|
5
7
|
interface Initiator {
|
|
6
8
|
cache?: RequestCache;
|
|
@@ -11,65 +13,59 @@ export declare namespace HttpRequest {
|
|
|
11
13
|
keepalive?: boolean;
|
|
12
14
|
method?: string;
|
|
13
15
|
mode?: RequestMode;
|
|
14
|
-
params?: URLSearchParamsInit;
|
|
15
16
|
redirect?: RequestRedirect;
|
|
16
17
|
referrer?: string;
|
|
17
18
|
referrerPolicy?: ReferrerPolicy;
|
|
18
19
|
signal?: AbortSignal;
|
|
19
|
-
url
|
|
20
|
+
url: string | URL | OpraURL;
|
|
20
21
|
body?: any;
|
|
21
22
|
}
|
|
22
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* @class HttpRequest
|
|
26
|
+
*/
|
|
23
27
|
export declare class HttpRequest {
|
|
24
|
-
/**
|
|
28
|
+
/** The url for request */
|
|
29
|
+
url: OpraURL;
|
|
30
|
+
/** Body of the http request */
|
|
31
|
+
body?: any;
|
|
32
|
+
/** The cache mode associated with request, which is a string indicating
|
|
25
33
|
* how the request will interact with the browser's cache when fetching. */
|
|
26
34
|
cache: RequestCache;
|
|
27
|
-
/**
|
|
35
|
+
/** The credentials mode associated with request, which is a string indicating
|
|
28
36
|
* whether credentials will be sent with the request always, never,
|
|
29
37
|
* or only when sent to a same-origin URL. */
|
|
30
38
|
credentials: RequestCredentials;
|
|
31
|
-
/**
|
|
39
|
+
/** The kind of resource requested by request, e.g., "document" or "script". */
|
|
32
40
|
destination: RequestDestination;
|
|
33
|
-
/**
|
|
41
|
+
/** Headers object consisting of the headers associated with request.
|
|
34
42
|
* Note that headers added in the network layer by the user agent will not be accounted for in this object,
|
|
35
43
|
* e.g., the "Host" header. */
|
|
36
44
|
headers: Headers;
|
|
37
|
-
/**
|
|
45
|
+
/** Request's subresource integrity metadata, which is a cryptographic
|
|
38
46
|
* hash of the resource being fetched.
|
|
39
47
|
* Its value consists of multiple hashes separated by whitespace. [SRI] */
|
|
40
48
|
integrity: string;
|
|
41
|
-
/**
|
|
49
|
+
/** A boolean indicating whether or not request can outlive the global in which it was created. */
|
|
42
50
|
keepalive: boolean;
|
|
43
|
-
/**
|
|
51
|
+
/** Request's HTTP method, which is "GET" by default. */
|
|
44
52
|
method: string;
|
|
45
|
-
/**
|
|
53
|
+
/** The mode associated with request, which is a string indicating whether the request will use CORS,
|
|
46
54
|
* or will be restricted to same-origin URLs. */
|
|
47
55
|
mode: RequestMode;
|
|
48
|
-
/**
|
|
56
|
+
/** The redirect mode associated with request, which is a string indicating
|
|
49
57
|
* how redirects for the request will be handled during fetching. A request will follow redirects by default. */
|
|
50
58
|
redirect: RequestRedirect;
|
|
51
|
-
/**
|
|
59
|
+
/** The referrer of request. Its value can be a same-origin URL if explicitly set in init,
|
|
52
60
|
* the empty string to indicate no referrer, and "about:client" when defaulting to the global's default.
|
|
53
61
|
* This is used during fetching to determine the value of the `Referer` header of the request being made. */
|
|
54
62
|
referrer: string;
|
|
55
|
-
/**
|
|
63
|
+
/** The referrer policy associated with request. This is used during fetching
|
|
56
64
|
* to compute the value of the request's referrer. */
|
|
57
65
|
referrerPolicy: ReferrerPolicy;
|
|
58
|
-
/**
|
|
66
|
+
/** The signal associated with request, which is an AbortSignal object indicating
|
|
59
67
|
* whether or not request has been aborted, and its abort event handler. */
|
|
60
68
|
signal?: AbortSignal;
|
|
61
|
-
/** Returns the parsed url as OpraURL instance */
|
|
62
|
-
parsedUrl: OpraURL;
|
|
63
|
-
/** Body of the http request */
|
|
64
|
-
body?: any;
|
|
65
69
|
duplex?: 'half';
|
|
66
70
|
constructor(init?: HttpRequest.Initiator);
|
|
67
|
-
/** Returns the URL of request as a string. */
|
|
68
|
-
get url(): OpraURL;
|
|
69
|
-
set url(value: OpraURL);
|
|
70
|
-
/** Returns the searchParams of the URL as OpraURLSearchParams */
|
|
71
|
-
get params(): URLSearchParams;
|
|
72
|
-
clone(...update: (HttpRequest | HttpRequest.Initiator)[]): HttpRequest;
|
|
73
|
-
merge(update: HttpRequest | HttpRequest.Initiator): void;
|
|
74
|
-
inset(src: HttpRequest | HttpRequest.Initiator): void;
|
|
75
71
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { PartialInput } from '@opra/common';
|
|
2
|
+
import type { OpraHttpClient } from '../client.js';
|
|
3
|
+
import { HttpRequestObservable } from './http-request-observable.js';
|
|
4
|
+
/**
|
|
5
|
+
* @class HttpSingletonNode
|
|
6
|
+
*/
|
|
7
|
+
export declare class HttpSingletonNode<TType, TResponseExt = {}> {
|
|
8
|
+
protected _client: OpraHttpClient;
|
|
9
|
+
protected _path: string;
|
|
10
|
+
constructor(client: OpraHttpClient<any>, path: string);
|
|
11
|
+
create(data: PartialInput<TType>, options?: HttpSingletonNode.CreateOptions): HttpRequestObservable<TType, TResponseExt>;
|
|
12
|
+
delete(): HttpRequestObservable<never, TResponseExt>;
|
|
13
|
+
get(options?: HttpSingletonNode.GetOptions): HttpRequestObservable<TType, TResponseExt>;
|
|
14
|
+
update(data: PartialInput<TType>, options?: HttpSingletonNode.UpdateOptions): HttpRequestObservable<TType, TResponseExt>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @namespace HttpSingletonNode
|
|
18
|
+
*/
|
|
19
|
+
export declare namespace HttpSingletonNode {
|
|
20
|
+
interface CreateOptions {
|
|
21
|
+
pick?: string[];
|
|
22
|
+
omit?: string[];
|
|
23
|
+
include?: string[];
|
|
24
|
+
}
|
|
25
|
+
interface GetOptions {
|
|
26
|
+
pick?: string[];
|
|
27
|
+
omit?: string[];
|
|
28
|
+
include?: string[];
|
|
29
|
+
}
|
|
30
|
+
interface UpdateOptions {
|
|
31
|
+
pick?: string[];
|
|
32
|
+
omit?: string[];
|
|
33
|
+
include?: string[];
|
|
34
|
+
}
|
|
35
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export * from './client.js';
|
|
2
2
|
export * from './client-error.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
3
|
export * from './types.js';
|
|
4
|
+
export * from './enums/index.js';
|
|
5
|
+
export * from './interfaces/index.js';
|
|
6
|
+
export * from './impl/collection-node.js';
|
|
7
|
+
export * from './impl/singleton-node.js';
|
|
8
|
+
export * from './impl/http-request.js';
|
|
9
|
+
export * from './impl/http-response.js';
|
|
10
|
+
export * from './impl/http-service-base.js';
|
|
11
|
+
export * from './impl/http-request-observable.js';
|
|
12
|
+
export { kClient, kContext } from './constants.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ApiDocument } from '@opra/common';
|
|
2
|
+
import type { OpraHttpClient } from '../client.js';
|
|
3
|
+
import type { HttpResponse } from '../impl/http-response.js';
|
|
4
|
+
import type { RequestInterceptor, ResponseInterceptor } from '../types.js';
|
|
5
|
+
export interface OpraHttpClientContext {
|
|
6
|
+
serviceUrl: string;
|
|
7
|
+
requestInterceptors: RequestInterceptor[];
|
|
8
|
+
responseInterceptors: ResponseInterceptor[];
|
|
9
|
+
createResponse: (init?: HttpResponse.Initiator) => HttpResponse<any>;
|
|
10
|
+
fetch: (url: string, init?: RequestInit) => Promise<Response>;
|
|
11
|
+
api?: ApiDocument;
|
|
12
|
+
defaults: OpraHttpClient.Defaults;
|
|
13
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { HttpRequest } from '../impl/http-request.js';
|
|
2
|
+
import type { HttpResponse } from '../impl/http-response.js';
|
|
3
|
+
export type HttpEvent = HttpSentEvent | HttpDownloadProgressEvent | HttpUploadProgressEvent | HttpResponseHeaderEvent | HttpResponseEvent | HttpUserEvent;
|
|
4
|
+
/**
|
|
5
|
+
* Type enumeration for the different kinds of `HttpEvent`.
|
|
6
|
+
*/
|
|
7
|
+
export declare enum HttpEventType {
|
|
8
|
+
/**
|
|
9
|
+
* The request was sent out over the wire.
|
|
10
|
+
*/
|
|
11
|
+
Sent = "sent",
|
|
12
|
+
/**
|
|
13
|
+
* An upload progress event was received.
|
|
14
|
+
*
|
|
15
|
+
* Note: The `FetchBackend` doesn't support progress report on uploads.
|
|
16
|
+
*/
|
|
17
|
+
UploadProgress = "upload-progress",
|
|
18
|
+
/**
|
|
19
|
+
* The response status code and headers were received.
|
|
20
|
+
*/
|
|
21
|
+
ResponseHeader = "response-header",
|
|
22
|
+
/**
|
|
23
|
+
* A download progress event was received.
|
|
24
|
+
*/
|
|
25
|
+
DownloadProgress = "download-progress",
|
|
26
|
+
/**
|
|
27
|
+
* The full response including the body was received.
|
|
28
|
+
*/
|
|
29
|
+
Response = "response",
|
|
30
|
+
/**
|
|
31
|
+
* A custom event from an interceptor or a backend.
|
|
32
|
+
*/
|
|
33
|
+
Custom = "custom"
|
|
34
|
+
}
|
|
35
|
+
interface HttpEventBase {
|
|
36
|
+
request: HttpRequest;
|
|
37
|
+
event: HttpEventType;
|
|
38
|
+
}
|
|
39
|
+
export interface HttpSentEvent extends HttpEventBase {
|
|
40
|
+
event: HttpEventType.Sent;
|
|
41
|
+
}
|
|
42
|
+
export interface HttpDownloadProgressEvent extends HttpEventBase {
|
|
43
|
+
event: HttpEventType.DownloadProgress;
|
|
44
|
+
/**
|
|
45
|
+
* Number of bytes uploaded
|
|
46
|
+
*/
|
|
47
|
+
loaded: number;
|
|
48
|
+
/**
|
|
49
|
+
* Total number of bytes to upload.
|
|
50
|
+
* Depending on the request, this may not be computable and thus may not be present.
|
|
51
|
+
*/
|
|
52
|
+
total?: number;
|
|
53
|
+
}
|
|
54
|
+
export interface HttpUploadProgressEvent extends HttpEventBase {
|
|
55
|
+
event: HttpEventType.UploadProgress;
|
|
56
|
+
/**
|
|
57
|
+
* Response object
|
|
58
|
+
*/
|
|
59
|
+
response: HttpResponse;
|
|
60
|
+
/**
|
|
61
|
+
* Number of bytes uploaded
|
|
62
|
+
*/
|
|
63
|
+
loaded: number;
|
|
64
|
+
/**
|
|
65
|
+
* Total number of bytes to upload.
|
|
66
|
+
* Depending on the request, this may not be computable and thus may not be present.
|
|
67
|
+
*/
|
|
68
|
+
total?: number;
|
|
69
|
+
}
|
|
70
|
+
export interface HttpResponseHeaderEvent extends HttpEventBase {
|
|
71
|
+
event: HttpEventType.ResponseHeader;
|
|
72
|
+
/**
|
|
73
|
+
* Response object
|
|
74
|
+
*/
|
|
75
|
+
response: HttpResponse;
|
|
76
|
+
}
|
|
77
|
+
export interface HttpResponseEvent extends HttpEventBase {
|
|
78
|
+
event: HttpEventType.Response;
|
|
79
|
+
/**
|
|
80
|
+
* Response object
|
|
81
|
+
*/
|
|
82
|
+
response: HttpResponse;
|
|
83
|
+
}
|
|
84
|
+
export interface HttpUserEvent extends HttpEventBase {
|
|
85
|
+
event: HttpEventType.Custom;
|
|
86
|
+
[key: string | number | symbol]: any;
|
|
87
|
+
}
|
|
88
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { HttpRequest } from '../impl/http-request.js';
|
|
2
|
+
import type { URLSearchParamsInit } from '../types.js';
|
|
3
|
+
export interface HttpRequestDefaults extends Partial<Pick<HttpRequest, 'cache' | 'credentials' | 'destination' | 'integrity' | 'keepalive' | 'mode' | 'redirect' | 'referrer' | 'referrerPolicy'>> {
|
|
4
|
+
headers?: HeadersInit;
|
|
5
|
+
params?: URLSearchParamsInit;
|
|
6
|
+
}
|
package/types/types.d.ts
CHANGED
|
@@ -1,114 +1,7 @@
|
|
|
1
1
|
import type { Observable } from 'rxjs';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type { HttpRequest } from './http-request.js';
|
|
5
|
-
import type { HttpResponse } from './http-response.js';
|
|
2
|
+
import type { HttpObserveType } from './enums/http-observable-type.enum.js';
|
|
3
|
+
import type { HttpRequest } from './impl/http-request';
|
|
6
4
|
export type HttpRequestHandler = (observe: HttpObserveType, request: HttpRequest) => Observable<any>;
|
|
7
|
-
export type RequestInterceptor = (
|
|
8
|
-
export type ResponseInterceptor = (
|
|
9
|
-
export type HttpEvent = HttpSentEvent | HttpDownloadProgressEvent | HttpUploadProgressEvent | HttpResponseHeaderEvent | HttpResponseEvent | HttpUserEvent;
|
|
5
|
+
export type RequestInterceptor = (request: HttpRequest) => void | Promise<void>;
|
|
6
|
+
export type ResponseInterceptor = (response: any) => void | Promise<void>;
|
|
10
7
|
export type URLSearchParamsInit = string[][] | Record<string, string> | string | URLSearchParams;
|
|
11
|
-
export declare enum HttpObserveType {
|
|
12
|
-
Response = "response",
|
|
13
|
-
Body = "body",
|
|
14
|
-
Events = "events"
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Type enumeration for the different kinds of `HttpEvent`.
|
|
18
|
-
*/
|
|
19
|
-
export declare enum HttpEventType {
|
|
20
|
-
/**
|
|
21
|
-
* The request was sent out over the wire.
|
|
22
|
-
*/
|
|
23
|
-
Sent = "sent",
|
|
24
|
-
/**
|
|
25
|
-
* An upload progress event was received.
|
|
26
|
-
*
|
|
27
|
-
* Note: The `FetchBackend` doesn't support progress report on uploads.
|
|
28
|
-
*/
|
|
29
|
-
UploadProgress = "upload-progress",
|
|
30
|
-
/**
|
|
31
|
-
* The response status code and headers were received.
|
|
32
|
-
*/
|
|
33
|
-
ResponseHeader = "response-header",
|
|
34
|
-
/**
|
|
35
|
-
* A download progress event was received.
|
|
36
|
-
*/
|
|
37
|
-
DownloadProgress = "download-progress",
|
|
38
|
-
/**
|
|
39
|
-
* The full response including the body was received.
|
|
40
|
-
*/
|
|
41
|
-
Response = "response",
|
|
42
|
-
/**
|
|
43
|
-
* A custom event from an interceptor or a backend.
|
|
44
|
-
*/
|
|
45
|
-
Custom = "custom"
|
|
46
|
-
}
|
|
47
|
-
export interface HttpClientContext {
|
|
48
|
-
client: OpraHttpClient;
|
|
49
|
-
sourceKind: OpraSchema.Resource.Kind;
|
|
50
|
-
resource: string;
|
|
51
|
-
endpoint: string;
|
|
52
|
-
send: HttpRequestHandler;
|
|
53
|
-
requestInterceptors?: RequestInterceptor[];
|
|
54
|
-
responseInterceptors?: ResponseInterceptor[];
|
|
55
|
-
}
|
|
56
|
-
export interface HttpRequestDefaults extends Partial<Pick<HttpRequest, 'cache' | 'credentials' | 'destination' | 'integrity' | 'keepalive' | 'mode' | 'redirect' | 'referrer' | 'referrerPolicy'>> {
|
|
57
|
-
headers?: HeadersInit;
|
|
58
|
-
params?: URLSearchParamsInit;
|
|
59
|
-
}
|
|
60
|
-
interface HttpEventBase {
|
|
61
|
-
observe: HttpObserveType;
|
|
62
|
-
request: HttpRequest;
|
|
63
|
-
event: HttpEventType;
|
|
64
|
-
}
|
|
65
|
-
export interface HttpSentEvent extends HttpEventBase {
|
|
66
|
-
event: HttpEventType.Sent;
|
|
67
|
-
}
|
|
68
|
-
export interface HttpDownloadProgressEvent extends HttpEventBase {
|
|
69
|
-
event: HttpEventType.DownloadProgress;
|
|
70
|
-
/**
|
|
71
|
-
* Number of bytes uploaded
|
|
72
|
-
*/
|
|
73
|
-
loaded: number;
|
|
74
|
-
/**
|
|
75
|
-
* Total number of bytes to upload.
|
|
76
|
-
* Depending on the request, this may not be computable and thus may not be present.
|
|
77
|
-
*/
|
|
78
|
-
total?: number;
|
|
79
|
-
}
|
|
80
|
-
export interface HttpUploadProgressEvent extends HttpEventBase {
|
|
81
|
-
event: HttpEventType.UploadProgress;
|
|
82
|
-
/**
|
|
83
|
-
* Response object
|
|
84
|
-
*/
|
|
85
|
-
response: HttpResponse;
|
|
86
|
-
/**
|
|
87
|
-
* Number of bytes uploaded
|
|
88
|
-
*/
|
|
89
|
-
loaded: number;
|
|
90
|
-
/**
|
|
91
|
-
* Total number of bytes to upload.
|
|
92
|
-
* Depending on the request, this may not be computable and thus may not be present.
|
|
93
|
-
*/
|
|
94
|
-
total?: number;
|
|
95
|
-
}
|
|
96
|
-
export interface HttpResponseHeaderEvent extends HttpEventBase {
|
|
97
|
-
event: HttpEventType.ResponseHeader;
|
|
98
|
-
/**
|
|
99
|
-
* Response object
|
|
100
|
-
*/
|
|
101
|
-
response: HttpResponse;
|
|
102
|
-
}
|
|
103
|
-
export interface HttpResponseEvent extends HttpEventBase {
|
|
104
|
-
event: HttpEventType.Response;
|
|
105
|
-
/**
|
|
106
|
-
* Response object
|
|
107
|
-
*/
|
|
108
|
-
response: HttpResponse;
|
|
109
|
-
}
|
|
110
|
-
export interface HttpUserEvent extends HttpEventBase {
|
|
111
|
-
event: HttpEventType.Custom;
|
|
112
|
-
[key: string | number | symbol]: any;
|
|
113
|
-
}
|
|
114
|
-
export {};
|
package/cjs/collection-node.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpCollectionNode = void 0;
|
|
4
|
-
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
5
|
-
const constants_js_1 = require("./constants.js");
|
|
6
|
-
const http_request_observable_js_1 = require("./http-request-observable.js");
|
|
7
|
-
class HttpCollectionNode {
|
|
8
|
-
constructor(context) {
|
|
9
|
-
this[constants_js_1.kContext] = context;
|
|
10
|
-
}
|
|
11
|
-
create(data, options) {
|
|
12
|
-
const context = this[constants_js_1.kContext];
|
|
13
|
-
context.endpoint = 'create';
|
|
14
|
-
const requestHost = new http_request_observable_js_1.HttpRequestObservable(context, options);
|
|
15
|
-
const request = requestHost[constants_js_1.kRequest];
|
|
16
|
-
request.method = 'POST';
|
|
17
|
-
request.url.resolve(context.resource);
|
|
18
|
-
request.body = data;
|
|
19
|
-
if (options?.include)
|
|
20
|
-
request.params.set('$include', (0, putil_varhelpers_1.toArrayDef)(options.include, []).join(','));
|
|
21
|
-
if (options?.pick)
|
|
22
|
-
request.params.set('$pick', (0, putil_varhelpers_1.toArrayDef)(options.pick, []).join(','));
|
|
23
|
-
if (options?.omit)
|
|
24
|
-
request.params.set('$omit', (0, putil_varhelpers_1.toArrayDef)(options.omit, []).join(','));
|
|
25
|
-
return requestHost;
|
|
26
|
-
}
|
|
27
|
-
delete(id, options) {
|
|
28
|
-
if (id == null)
|
|
29
|
-
throw new TypeError(`'id' argument must have a value`);
|
|
30
|
-
const context = this[constants_js_1.kContext];
|
|
31
|
-
context.endpoint = 'delete';
|
|
32
|
-
const requestHost = new http_request_observable_js_1.HttpRequestObservable(context, options);
|
|
33
|
-
const request = requestHost[constants_js_1.kRequest];
|
|
34
|
-
request.method = 'DELETE';
|
|
35
|
-
request.url.join({ resource: context.resource, key: id });
|
|
36
|
-
return requestHost;
|
|
37
|
-
}
|
|
38
|
-
deleteMany(options) {
|
|
39
|
-
const context = this[constants_js_1.kContext];
|
|
40
|
-
context.endpoint = 'deleteMany';
|
|
41
|
-
const requestHost = new http_request_observable_js_1.HttpRequestObservable(context, options);
|
|
42
|
-
const request = requestHost[constants_js_1.kRequest];
|
|
43
|
-
request.method = 'DELETE';
|
|
44
|
-
request.url.join(context.resource);
|
|
45
|
-
if (options?.filter)
|
|
46
|
-
request.params.set('$filter', String(options.filter));
|
|
47
|
-
return requestHost;
|
|
48
|
-
}
|
|
49
|
-
get(id, options) {
|
|
50
|
-
if (id == null)
|
|
51
|
-
throw new TypeError(`'id' argument must have a value`);
|
|
52
|
-
const context = this[constants_js_1.kContext];
|
|
53
|
-
context.endpoint = 'get';
|
|
54
|
-
const requestHost = new http_request_observable_js_1.HttpRequestObservable(context, options);
|
|
55
|
-
const request = requestHost[constants_js_1.kRequest];
|
|
56
|
-
request.method = 'GET';
|
|
57
|
-
request.url.join({ resource: context.resource, key: id });
|
|
58
|
-
if (options?.include)
|
|
59
|
-
request.params.set('$include', (0, putil_varhelpers_1.toArrayDef)(options.include, []).join(','));
|
|
60
|
-
if (options?.pick)
|
|
61
|
-
request.params.set('$pick', (0, putil_varhelpers_1.toArrayDef)(options.pick, []).join(','));
|
|
62
|
-
if (options?.omit)
|
|
63
|
-
request.params.set('$omit', (0, putil_varhelpers_1.toArrayDef)(options.omit, []).join(','));
|
|
64
|
-
return requestHost;
|
|
65
|
-
}
|
|
66
|
-
findMany(options) {
|
|
67
|
-
const context = this[constants_js_1.kContext];
|
|
68
|
-
context.endpoint = 'findMany';
|
|
69
|
-
const requestHost = new http_request_observable_js_1.HttpRequestObservable(context, options);
|
|
70
|
-
const request = requestHost[constants_js_1.kRequest];
|
|
71
|
-
request.method = 'GET';
|
|
72
|
-
request.url.join(context.resource);
|
|
73
|
-
if (options?.include)
|
|
74
|
-
request.params.set('$include', (0, putil_varhelpers_1.toArrayDef)(options.include, []).join(','));
|
|
75
|
-
if (options?.pick)
|
|
76
|
-
request.params.set('$pick', (0, putil_varhelpers_1.toArrayDef)(options.pick, []).join(','));
|
|
77
|
-
if (options?.omit)
|
|
78
|
-
request.params.set('$omit', (0, putil_varhelpers_1.toArrayDef)(options.omit, []).join(','));
|
|
79
|
-
if (options?.sort)
|
|
80
|
-
request.params.set('$sort', (0, putil_varhelpers_1.toArrayDef)(options.sort, []).join(','));
|
|
81
|
-
if (options?.filter)
|
|
82
|
-
request.params.set('$filter', String(options.filter));
|
|
83
|
-
if (options?.limit != null)
|
|
84
|
-
request.params.set('$limit', String(options.limit));
|
|
85
|
-
if (options?.skip != null)
|
|
86
|
-
request.params.set('$skip', String(options.skip));
|
|
87
|
-
if (options?.count != null)
|
|
88
|
-
request.params.set('$count', String(options.count));
|
|
89
|
-
if (options?.distinct != null)
|
|
90
|
-
request.params.set('$distinct', String(options.distinct));
|
|
91
|
-
return requestHost;
|
|
92
|
-
}
|
|
93
|
-
update(id, data, options) {
|
|
94
|
-
if (id == null)
|
|
95
|
-
throw new TypeError(`'id' argument must have a value`);
|
|
96
|
-
const context = this[constants_js_1.kContext];
|
|
97
|
-
context.endpoint = 'update';
|
|
98
|
-
const requestHost = new http_request_observable_js_1.HttpRequestObservable(context, options);
|
|
99
|
-
const request = requestHost[constants_js_1.kRequest];
|
|
100
|
-
request.method = 'PATCH';
|
|
101
|
-
request.url.join({ resource: context.resource, key: id });
|
|
102
|
-
request.body = data;
|
|
103
|
-
if (options?.include)
|
|
104
|
-
request.params.set('$include', String(options.include));
|
|
105
|
-
if (options?.pick)
|
|
106
|
-
request.params.set('$pick', String(options.pick));
|
|
107
|
-
if (options?.omit)
|
|
108
|
-
request.params.set('$omit', String(options.omit));
|
|
109
|
-
return requestHost;
|
|
110
|
-
}
|
|
111
|
-
updateMany(data, options) {
|
|
112
|
-
const context = this[constants_js_1.kContext];
|
|
113
|
-
context.endpoint = 'updateMany';
|
|
114
|
-
const requestHost = new http_request_observable_js_1.HttpRequestObservable(context, options);
|
|
115
|
-
const request = requestHost[constants_js_1.kRequest];
|
|
116
|
-
request.method = 'PATCH';
|
|
117
|
-
request.url.join(context.resource);
|
|
118
|
-
request.body = data;
|
|
119
|
-
if (options?.filter)
|
|
120
|
-
request.params.set('$filter', String(options.filter));
|
|
121
|
-
return requestHost;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
exports.HttpCollectionNode = HttpCollectionNode;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpRequestObservable = void 0;
|
|
4
|
-
const rxjs_1 = require("rxjs");
|
|
5
|
-
const common_1 = require("@opra/common");
|
|
6
|
-
const constants_js_1 = require("./constants.js");
|
|
7
|
-
const http_request_js_1 = require("./http-request.js");
|
|
8
|
-
const types_js_1 = require("./types.js");
|
|
9
|
-
class HttpRequestObservable extends rxjs_1.Observable {
|
|
10
|
-
constructor(context, options) {
|
|
11
|
-
super((subscriber) => {
|
|
12
|
-
context.send(options?.observe || types_js_1.HttpObserveType.Body, this[constants_js_1.kRequest])
|
|
13
|
-
.subscribe((subscriber));
|
|
14
|
-
});
|
|
15
|
-
this[constants_js_1.kContext] = context;
|
|
16
|
-
this[constants_js_1.kRequest] = new http_request_js_1.HttpRequest(options?.http);
|
|
17
|
-
this.contentId = (0, common_1.uid)(6);
|
|
18
|
-
}
|
|
19
|
-
header(name, value) {
|
|
20
|
-
const headers = this[constants_js_1.kRequest].headers;
|
|
21
|
-
if (Array.isArray(value))
|
|
22
|
-
value.forEach(v => headers.append(name, String(v)));
|
|
23
|
-
else
|
|
24
|
-
headers.append(name, value);
|
|
25
|
-
return this;
|
|
26
|
-
}
|
|
27
|
-
param(name, value) {
|
|
28
|
-
this[constants_js_1.kRequest].params.append(name, value);
|
|
29
|
-
return this;
|
|
30
|
-
}
|
|
31
|
-
async fetch(observe) {
|
|
32
|
-
return (0, rxjs_1.lastValueFrom)(this[constants_js_1.kContext]
|
|
33
|
-
.send(observe || types_js_1.HttpObserveType.Body, this[constants_js_1.kRequest]));
|
|
34
|
-
}
|
|
35
|
-
with(cb) {
|
|
36
|
-
cb(this);
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.HttpRequestObservable = HttpRequestObservable;
|
package/cjs/http-request.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpRequest = void 0;
|
|
4
|
-
/// <reference lib="dom" />
|
|
5
|
-
const common_1 = require("@opra/common");
|
|
6
|
-
const directCopyProperties = ['cache', 'credentials', 'destination', 'headers', 'integrity',
|
|
7
|
-
'keepalive', 'mode', 'redirect', 'referrer', 'referrerPolicy'];
|
|
8
|
-
class HttpRequest {
|
|
9
|
-
constructor(init) {
|
|
10
|
-
this.cache = init?.cache || 'default';
|
|
11
|
-
this.credentials = init?.credentials || 'same-origin';
|
|
12
|
-
this.destination = init?.destination || '';
|
|
13
|
-
this.headers = init?.headers instanceof Headers ? init.headers : new Headers(init?.headers);
|
|
14
|
-
this.integrity = init?.integrity || '';
|
|
15
|
-
this.keepalive = init?.keepalive ?? false;
|
|
16
|
-
this.method = (init?.method || 'GET').toUpperCase();
|
|
17
|
-
this.mode = init?.mode || 'cors';
|
|
18
|
-
this.redirect = init?.redirect || 'follow';
|
|
19
|
-
this.mode = init?.mode || 'cors';
|
|
20
|
-
this.referrer = init?.referrer || '';
|
|
21
|
-
this.referrerPolicy = init?.referrerPolicy || '';
|
|
22
|
-
this.signal = init?.signal || new AbortController().signal;
|
|
23
|
-
this.body = init?.body;
|
|
24
|
-
this.parsedUrl = new common_1.OpraURL(init?.url);
|
|
25
|
-
if (init?.params) {
|
|
26
|
-
const params = new URLSearchParams(init.params);
|
|
27
|
-
params.forEach((v, k) => this.params.set(k, v));
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/** Returns the URL of request as a string. */
|
|
31
|
-
get url() {
|
|
32
|
-
return this.parsedUrl;
|
|
33
|
-
}
|
|
34
|
-
set url(value) {
|
|
35
|
-
this.parsedUrl = value;
|
|
36
|
-
}
|
|
37
|
-
/** Returns the searchParams of the URL as OpraURLSearchParams */
|
|
38
|
-
get params() {
|
|
39
|
-
return this.parsedUrl.searchParams;
|
|
40
|
-
}
|
|
41
|
-
clone(...update) {
|
|
42
|
-
const out = new HttpRequest();
|
|
43
|
-
out.merge(this);
|
|
44
|
-
for (const upd of update) {
|
|
45
|
-
out.merge(upd);
|
|
46
|
-
}
|
|
47
|
-
return out;
|
|
48
|
-
}
|
|
49
|
-
merge(update) {
|
|
50
|
-
directCopyProperties.forEach(k => {
|
|
51
|
-
if (update[k] != null)
|
|
52
|
-
this[k] = update[k];
|
|
53
|
-
});
|
|
54
|
-
if (update.headers) {
|
|
55
|
-
const h = update.headers instanceof Headers
|
|
56
|
-
? update.headers
|
|
57
|
-
: new Headers(update.headers);
|
|
58
|
-
h.forEach((v, k) => {
|
|
59
|
-
if (k.toLowerCase() === 'set-cookie') {
|
|
60
|
-
this.headers.append(k, v);
|
|
61
|
-
}
|
|
62
|
-
else
|
|
63
|
-
this.headers.set(k, v);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
inset(src) {
|
|
68
|
-
directCopyProperties.forEach(k => {
|
|
69
|
-
if (this[k] == null && src[k] != null)
|
|
70
|
-
this[k] = src[k];
|
|
71
|
-
});
|
|
72
|
-
if (src.headers) {
|
|
73
|
-
const h = src.headers instanceof Headers
|
|
74
|
-
? src.headers
|
|
75
|
-
: new Headers(src.headers);
|
|
76
|
-
h.forEach((v, k) => {
|
|
77
|
-
if (k.toLowerCase() === 'set-cookie') {
|
|
78
|
-
this.headers.append(k, v);
|
|
79
|
-
}
|
|
80
|
-
else if (!this.headers.has(k))
|
|
81
|
-
this.headers.set(k, v);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
exports.HttpRequest = HttpRequest;
|
package/cjs/http-service-base.js
DELETED