@opra/client 0.4.0 → 0.6.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/cjs/constants.js +6 -0
- package/cjs/http/http-client.js +164 -0
- package/cjs/http/http-collection-service.js +40 -0
- package/cjs/http/http-request.js +66 -0
- package/cjs/{response.js → http/http-response.js} +0 -0
- package/cjs/http/http-singleton-service.js +16 -0
- package/cjs/http/http-types.js +2 -0
- package/cjs/http/requests/batch-request.js +80 -0
- package/cjs/http/requests/collection-create-request.js +35 -0
- package/cjs/http/requests/collection-delete-many-request.js +28 -0
- package/cjs/http/requests/collection-delete-request.js +29 -0
- package/cjs/http/requests/collection-get-request.js +37 -0
- package/cjs/http/requests/collection-search-request.js +44 -0
- package/cjs/http/requests/collection-update-many-request.js +31 -0
- package/cjs/http/requests/collection-update-request.js +40 -0
- package/cjs/http/requests/http-singleton-get-request.js +31 -0
- package/cjs/http/utils/merge-raw-http-requests.util.js +29 -0
- package/cjs/index.js +16 -4
- package/cjs/interfaces/http-options.interface.js +2 -0
- package/cjs/interfaces/http-request-config.interface.js +2 -0
- package/cjs/types.js +0 -9
- package/esm/client-error.d.ts +1 -1
- package/esm/constants.d.ts +3 -0
- package/esm/constants.js +3 -0
- package/esm/http/http-client.d.ts +26 -0
- package/esm/http/http-client.js +160 -0
- package/esm/http/http-collection-service.d.ts +22 -0
- package/esm/http/http-collection-service.js +36 -0
- package/esm/http/http-request.d.ts +25 -0
- package/esm/http/http-request.js +62 -0
- package/esm/http/http-response.d.ts +14 -0
- package/esm/{response.js → http/http-response.js} +0 -0
- package/esm/http/http-singleton-service.d.ts +10 -0
- package/esm/http/http-singleton-service.js +12 -0
- package/esm/http/http-types.d.ts +26 -0
- package/esm/http/http-types.js +1 -0
- package/esm/http/requests/batch-request.d.ts +18 -0
- package/esm/http/requests/batch-request.js +76 -0
- package/esm/http/requests/collection-create-request.d.ts +12 -0
- package/esm/http/requests/collection-create-request.js +31 -0
- package/esm/http/requests/collection-delete-many-request.d.ts +11 -0
- package/esm/http/requests/collection-delete-many-request.js +24 -0
- package/esm/http/requests/collection-delete-request.d.ts +12 -0
- package/esm/http/requests/collection-delete-request.js +25 -0
- package/esm/http/requests/collection-get-request.d.ts +12 -0
- package/esm/http/requests/collection-get-request.js +33 -0
- package/esm/http/requests/collection-search-request.d.ts +11 -0
- package/esm/http/requests/collection-search-request.js +40 -0
- package/esm/http/requests/collection-update-many-request.d.ts +12 -0
- package/esm/http/requests/collection-update-many-request.js +27 -0
- package/esm/http/requests/collection-update-request.d.ts +13 -0
- package/esm/http/requests/collection-update-request.js +36 -0
- package/esm/http/requests/http-singleton-get-request.d.ts +11 -0
- package/esm/http/requests/http-singleton-get-request.js +27 -0
- package/esm/http/utils/merge-raw-http-requests.util.d.ts +2 -0
- package/esm/http/utils/merge-raw-http-requests.util.js +25 -0
- package/esm/index.d.ts +16 -4
- package/esm/index.js +16 -4
- package/esm/interfaces/http-options.interface.d.ts +20 -0
- package/esm/interfaces/http-options.interface.js +1 -0
- package/esm/interfaces/http-request-config.interface.d.ts +23 -0
- package/esm/interfaces/http-request-config.interface.js +1 -0
- package/esm/types.d.ts +7 -10
- package/esm/types.js +0 -9
- package/package.json +25 -16
- package/umd/opra-client.umd.min.js +1 -0
- package/cjs/client.js +0 -96
- package/cjs/observable-promise.js +0 -10
- package/cjs/requests/collection-create-request.js +0 -22
- package/cjs/requests/collection-delete-many-request.js +0 -14
- package/cjs/requests/collection-get-request.js +0 -22
- package/cjs/requests/collection-search-request.js +0 -46
- package/cjs/requests/collection-update-many-request.js +0 -14
- package/cjs/requests/collection-update-request.js +0 -22
- package/cjs/requests/singleton-get-request.js +0 -22
- package/cjs/services/collection-service.js +0 -192
- package/cjs/services/singleton-service.js +0 -43
- package/esm/client.d.ts +0 -25
- package/esm/client.js +0 -91
- package/esm/observable-promise.d.ts +0 -2
- package/esm/observable-promise.js +0 -6
- package/esm/requests/collection-create-request.d.ts +0 -8
- package/esm/requests/collection-create-request.js +0 -18
- package/esm/requests/collection-delete-many-request.d.ts +0 -7
- package/esm/requests/collection-delete-many-request.js +0 -10
- package/esm/requests/collection-get-request.d.ts +0 -8
- package/esm/requests/collection-get-request.js +0 -18
- package/esm/requests/collection-search-request.d.ts +0 -15
- package/esm/requests/collection-search-request.js +0 -42
- package/esm/requests/collection-update-many-request.d.ts +0 -7
- package/esm/requests/collection-update-many-request.js +0 -10
- package/esm/requests/collection-update-request.d.ts +0 -8
- package/esm/requests/collection-update-request.js +0 -18
- package/esm/requests/singleton-get-request.d.ts +0 -8
- package/esm/requests/singleton-get-request.js +0 -18
- package/esm/response.d.ts +0 -9
- package/esm/services/collection-service.d.ts +0 -31
- package/esm/services/collection-service.js +0 -188
- package/esm/services/singleton-service.d.ts +0 -14
- package/esm/services/singleton-service.js +0 -39
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { CollectionDeleteManyQueryOptions } from '@opra/schema';
|
|
2
|
-
import { Expression } from '@opra/url';
|
|
3
|
-
export declare class CollectionDeleteManyRequest {
|
|
4
|
-
protected _options: CollectionDeleteManyQueryOptions;
|
|
5
|
-
constructor(_options?: CollectionDeleteManyQueryOptions);
|
|
6
|
-
filter(value: string | Expression): this;
|
|
7
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { CollectionGetQueryOptions } from '@opra/schema';
|
|
2
|
-
export declare class CollectionGetRequest {
|
|
3
|
-
protected _options: CollectionGetQueryOptions;
|
|
4
|
-
constructor(_options?: CollectionGetQueryOptions);
|
|
5
|
-
omit(...fields: (string | string[])[]): this;
|
|
6
|
-
pick(...fields: (string | string[])[]): this;
|
|
7
|
-
include(...fields: (string | string[])[]): this;
|
|
8
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export class CollectionGetRequest {
|
|
2
|
-
_options;
|
|
3
|
-
constructor(_options = {}) {
|
|
4
|
-
this._options = _options;
|
|
5
|
-
}
|
|
6
|
-
omit(...fields) {
|
|
7
|
-
this._options.omit = fields.flat();
|
|
8
|
-
return this;
|
|
9
|
-
}
|
|
10
|
-
pick(...fields) {
|
|
11
|
-
this._options.pick = fields.flat();
|
|
12
|
-
return this;
|
|
13
|
-
}
|
|
14
|
-
include(...fields) {
|
|
15
|
-
this._options.include = fields.flat();
|
|
16
|
-
return this;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { CollectionSearchQueryOptions } from '@opra/schema';
|
|
2
|
-
import { Expression } from '@opra/url';
|
|
3
|
-
export declare class CollectionSearchRequest {
|
|
4
|
-
protected _options: CollectionSearchQueryOptions;
|
|
5
|
-
constructor(_options?: CollectionSearchQueryOptions);
|
|
6
|
-
omit(...fields: (string | string[])[]): this;
|
|
7
|
-
pick(...fields: (string | string[])[]): this;
|
|
8
|
-
include(...fields: (string | string[])[]): this;
|
|
9
|
-
limit(value: number): this;
|
|
10
|
-
skip(value: number): this;
|
|
11
|
-
count(value?: boolean): this;
|
|
12
|
-
distinct(value: boolean): this;
|
|
13
|
-
sort(...fields: (string | string[])[]): this;
|
|
14
|
-
filter(value: string | Expression): this;
|
|
15
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
export class CollectionSearchRequest {
|
|
2
|
-
_options;
|
|
3
|
-
constructor(_options = {}) {
|
|
4
|
-
this._options = _options;
|
|
5
|
-
}
|
|
6
|
-
omit(...fields) {
|
|
7
|
-
this._options.omit = fields.flat();
|
|
8
|
-
return this;
|
|
9
|
-
}
|
|
10
|
-
pick(...fields) {
|
|
11
|
-
this._options.pick = fields.flat();
|
|
12
|
-
return this;
|
|
13
|
-
}
|
|
14
|
-
include(...fields) {
|
|
15
|
-
this._options.include = fields.flat();
|
|
16
|
-
return this;
|
|
17
|
-
}
|
|
18
|
-
limit(value) {
|
|
19
|
-
this._options.limit = value;
|
|
20
|
-
return this;
|
|
21
|
-
}
|
|
22
|
-
skip(value) {
|
|
23
|
-
this._options.skip = value;
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
count(value = true) {
|
|
27
|
-
this._options.count = value;
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
|
-
distinct(value) {
|
|
31
|
-
this._options.distinct = value;
|
|
32
|
-
return this;
|
|
33
|
-
}
|
|
34
|
-
sort(...fields) {
|
|
35
|
-
this._options.sort = fields.flat();
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
filter(value) {
|
|
39
|
-
this._options.filter = value;
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { CollectionUpdateManyQueryOptions } from '@opra/schema';
|
|
2
|
-
import { Expression } from '@opra/url';
|
|
3
|
-
export declare class CollectionUpdateManyRequest {
|
|
4
|
-
protected _options: CollectionUpdateManyQueryOptions;
|
|
5
|
-
constructor(_options?: CollectionUpdateManyQueryOptions);
|
|
6
|
-
filter(value: string | Expression): this;
|
|
7
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { CollectionUpdateQueryOptions } from '@opra/schema';
|
|
2
|
-
export declare class CollectionUpdateRequest {
|
|
3
|
-
protected _options: CollectionUpdateQueryOptions;
|
|
4
|
-
constructor(_options?: CollectionUpdateQueryOptions);
|
|
5
|
-
omit(...fields: (string | string[])[]): this;
|
|
6
|
-
pick(...fields: (string | string[])[]): this;
|
|
7
|
-
include(...fields: (string | string[])[]): this;
|
|
8
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export class CollectionUpdateRequest {
|
|
2
|
-
_options;
|
|
3
|
-
constructor(_options = {}) {
|
|
4
|
-
this._options = _options;
|
|
5
|
-
}
|
|
6
|
-
omit(...fields) {
|
|
7
|
-
this._options.omit = fields.flat();
|
|
8
|
-
return this;
|
|
9
|
-
}
|
|
10
|
-
pick(...fields) {
|
|
11
|
-
this._options.pick = fields.flat();
|
|
12
|
-
return this;
|
|
13
|
-
}
|
|
14
|
-
include(...fields) {
|
|
15
|
-
this._options.include = fields.flat();
|
|
16
|
-
return this;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { SingletonGetQueryOptions } from '@opra/schema';
|
|
2
|
-
export declare class SingletonGetRequest {
|
|
3
|
-
protected _options: SingletonGetQueryOptions;
|
|
4
|
-
constructor(_options?: SingletonGetQueryOptions);
|
|
5
|
-
omit(...fields: (string | string[])[]): this;
|
|
6
|
-
pick(...fields: (string | string[])[]): this;
|
|
7
|
-
include(...fields: (string | string[])[]): this;
|
|
8
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export class SingletonGetRequest {
|
|
2
|
-
_options;
|
|
3
|
-
constructor(_options = {}) {
|
|
4
|
-
this._options = _options;
|
|
5
|
-
}
|
|
6
|
-
omit(...fields) {
|
|
7
|
-
this._options.omit = fields.flat();
|
|
8
|
-
return this;
|
|
9
|
-
}
|
|
10
|
-
pick(...fields) {
|
|
11
|
-
this._options.pick = fields.flat();
|
|
12
|
-
return this;
|
|
13
|
-
}
|
|
14
|
-
include(...fields) {
|
|
15
|
-
this._options.include = fields.flat();
|
|
16
|
-
return this;
|
|
17
|
-
}
|
|
18
|
-
}
|
package/esm/response.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ResponsiveMap } from '@opra/common';
|
|
2
|
-
import { ResponseHeaders } from './types.js';
|
|
3
|
-
export declare type OpraResponse<T = any> = {
|
|
4
|
-
status: number;
|
|
5
|
-
statusText: string;
|
|
6
|
-
rawHeaders: ResponseHeaders;
|
|
7
|
-
headers: ResponsiveMap<string, string | string[]>;
|
|
8
|
-
data?: T;
|
|
9
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { CollectionCreateQueryOptions, CollectionDeleteManyQueryOptions, CollectionGetQueryOptions, CollectionResourceInfo, CollectionSearchQueryOptions, CollectionUpdateManyQueryOptions, CollectionUpdateQueryOptions, OpraDocument } from '@opra/schema';
|
|
3
|
-
import { CollectionCreateRequest } from '../requests/collection-create-request.js';
|
|
4
|
-
import { CollectionDeleteManyRequest } from '../requests/collection-delete-many-request.js';
|
|
5
|
-
import { CollectionGetRequest } from '../requests/collection-get-request.js';
|
|
6
|
-
import { CollectionSearchRequest } from '../requests/collection-search-request.js';
|
|
7
|
-
import { CollectionUpdateManyRequest } from '../requests/collection-update-many-request.js';
|
|
8
|
-
import { CollectionUpdateRequest } from '../requests/collection-update-request.js';
|
|
9
|
-
import { OpraResponse } from '../response.js';
|
|
10
|
-
import { ObservablePromiseLike, PartialInput, RequestConfig } from '../types.js';
|
|
11
|
-
export declare class CollectionService<T, TResponse extends OpraResponse<T>> {
|
|
12
|
-
protected _serviceUrl: string;
|
|
13
|
-
protected _document: OpraDocument;
|
|
14
|
-
protected _handler: (req: AxiosRequestConfig) => Promise<any>;
|
|
15
|
-
protected _resource: CollectionResourceInfo;
|
|
16
|
-
constructor(_serviceUrl: string, _document: OpraDocument, _handler: (req: AxiosRequestConfig) => Promise<any>, _resource: CollectionResourceInfo);
|
|
17
|
-
create(data: PartialInput<T>, options?: CollectionCreateQueryOptions | ((req: CollectionCreateRequest) => void)): ObservablePromiseLike<TResponse>;
|
|
18
|
-
delete(keyValue: any): ObservablePromiseLike<TResponse>;
|
|
19
|
-
deleteMany(options?: CollectionDeleteManyQueryOptions | ((req: CollectionDeleteManyRequest) => void)): ObservablePromiseLike<TResponse>;
|
|
20
|
-
get(keyValue: any, options?: CollectionGetQueryOptions | ((req: CollectionGetRequest) => void)): ObservablePromiseLike<TResponse>;
|
|
21
|
-
search(options?: CollectionSearchQueryOptions | ((req: CollectionSearchRequest) => void)): ObservablePromiseLike<TResponse>;
|
|
22
|
-
update(keyValue: any, data: PartialInput<T>, options?: CollectionUpdateQueryOptions | ((req: CollectionUpdateRequest) => void)): ObservablePromiseLike<TResponse>;
|
|
23
|
-
updateMany(data: PartialInput<T>, options?: CollectionUpdateManyQueryOptions | ((req: CollectionUpdateManyRequest) => void)): ObservablePromiseLike<TResponse>;
|
|
24
|
-
protected _prepareCreateRequest(data: any, options: CollectionCreateQueryOptions): AxiosRequestConfig;
|
|
25
|
-
protected _prepareDeleteRequest(keyValue: any): AxiosRequestConfig;
|
|
26
|
-
protected _prepareDeleteManyRequest(options: CollectionDeleteManyQueryOptions): AxiosRequestConfig;
|
|
27
|
-
protected _prepareGetRequest(keyValue: any, options: CollectionGetQueryOptions): RequestConfig;
|
|
28
|
-
protected _prepareSearchRequest(options: CollectionSearchQueryOptions): AxiosRequestConfig;
|
|
29
|
-
protected _prepareUpdateRequest(keyValue: any, data: any, options: CollectionUpdateQueryOptions): RequestConfig;
|
|
30
|
-
protected _prepareUpdateManyRequest(data: any, options: CollectionUpdateManyQueryOptions): RequestConfig;
|
|
31
|
-
}
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import { OpraURL } from '@opra/url';
|
|
2
|
-
import { observablePromise } from '../observable-promise.js';
|
|
3
|
-
import { CollectionCreateRequest } from '../requests/collection-create-request.js';
|
|
4
|
-
import { CollectionDeleteManyRequest } from '../requests/collection-delete-many-request.js';
|
|
5
|
-
import { CollectionGetRequest } from '../requests/collection-get-request.js';
|
|
6
|
-
import { CollectionSearchRequest } from '../requests/collection-search-request.js';
|
|
7
|
-
import { CollectionUpdateManyRequest } from '../requests/collection-update-many-request.js';
|
|
8
|
-
import { CollectionUpdateRequest } from '../requests/collection-update-request.js';
|
|
9
|
-
export class CollectionService {
|
|
10
|
-
_serviceUrl;
|
|
11
|
-
_document;
|
|
12
|
-
_handler;
|
|
13
|
-
_resource;
|
|
14
|
-
constructor(_serviceUrl, _document, _handler, _resource) {
|
|
15
|
-
this._serviceUrl = _serviceUrl;
|
|
16
|
-
this._document = _document;
|
|
17
|
-
this._handler = _handler;
|
|
18
|
-
this._resource = _resource;
|
|
19
|
-
}
|
|
20
|
-
create(data, options) {
|
|
21
|
-
const requestOptions = options && typeof options === 'object' ? options : {};
|
|
22
|
-
const requestWrapper = new CollectionCreateRequest(requestOptions);
|
|
23
|
-
if (typeof options === 'function')
|
|
24
|
-
options(requestWrapper);
|
|
25
|
-
const req = this._prepareCreateRequest(data, requestOptions);
|
|
26
|
-
const promise = this._handler(req);
|
|
27
|
-
return observablePromise(promise);
|
|
28
|
-
}
|
|
29
|
-
delete(keyValue) {
|
|
30
|
-
const req = this._prepareDeleteRequest(keyValue);
|
|
31
|
-
const promise = this._handler(req);
|
|
32
|
-
return observablePromise(promise);
|
|
33
|
-
}
|
|
34
|
-
deleteMany(options) {
|
|
35
|
-
const requestOptions = options && typeof options === 'object' ? options : {};
|
|
36
|
-
const requestWrapper = new CollectionDeleteManyRequest(requestOptions);
|
|
37
|
-
if (typeof options === 'function')
|
|
38
|
-
options(requestWrapper);
|
|
39
|
-
const req = this._prepareDeleteManyRequest(requestOptions);
|
|
40
|
-
const promise = this._handler(req);
|
|
41
|
-
return observablePromise(promise);
|
|
42
|
-
}
|
|
43
|
-
get(keyValue, options) {
|
|
44
|
-
const requestOptions = options && typeof options === 'object' ? options : {};
|
|
45
|
-
const requestWrapper = new CollectionGetRequest(requestOptions);
|
|
46
|
-
if (typeof options === 'function')
|
|
47
|
-
options(requestWrapper);
|
|
48
|
-
const req = this._prepareGetRequest(keyValue, requestOptions);
|
|
49
|
-
const promise = this._handler(req);
|
|
50
|
-
return observablePromise(promise);
|
|
51
|
-
}
|
|
52
|
-
search(options) {
|
|
53
|
-
const requestOptions = options && typeof options === 'object' ? options : {};
|
|
54
|
-
const requestWrapper = new CollectionSearchRequest(requestOptions);
|
|
55
|
-
if (typeof options === 'function')
|
|
56
|
-
options(requestWrapper);
|
|
57
|
-
const req = this._prepareSearchRequest(requestOptions);
|
|
58
|
-
const promise = this._handler(req);
|
|
59
|
-
return observablePromise(promise);
|
|
60
|
-
}
|
|
61
|
-
update(keyValue, data, options) {
|
|
62
|
-
const requestOptions = options && typeof options === 'object' ? options : {};
|
|
63
|
-
const requestWrapper = new CollectionUpdateRequest(requestOptions);
|
|
64
|
-
if (typeof options === 'function')
|
|
65
|
-
options(requestWrapper);
|
|
66
|
-
const req = this._prepareUpdateRequest(keyValue, data, requestOptions);
|
|
67
|
-
const promise = this._handler(req);
|
|
68
|
-
return observablePromise(promise);
|
|
69
|
-
}
|
|
70
|
-
updateMany(data, options) {
|
|
71
|
-
const requestOptions = options && typeof options === 'object' ? options : {};
|
|
72
|
-
const requestWrapper = new CollectionUpdateManyRequest(requestOptions);
|
|
73
|
-
if (typeof options === 'function')
|
|
74
|
-
options(requestWrapper);
|
|
75
|
-
const req = this._prepareUpdateManyRequest(data, requestOptions);
|
|
76
|
-
const promise = this._handler(req);
|
|
77
|
-
return observablePromise(promise);
|
|
78
|
-
}
|
|
79
|
-
_prepareCreateRequest(data, options) {
|
|
80
|
-
const url = new OpraURL(this._serviceUrl);
|
|
81
|
-
url.path.join(this._resource.name);
|
|
82
|
-
if (options.include)
|
|
83
|
-
url.searchParams.set('$include', options.include);
|
|
84
|
-
if (options.pick)
|
|
85
|
-
url.searchParams.set('$pick', options.pick);
|
|
86
|
-
if (options.omit)
|
|
87
|
-
url.searchParams.set('$omit', options.omit);
|
|
88
|
-
return {
|
|
89
|
-
method: 'POST',
|
|
90
|
-
url: url.address,
|
|
91
|
-
data,
|
|
92
|
-
params: url.searchParams
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
_prepareDeleteRequest(keyValue) {
|
|
96
|
-
const url = new OpraURL(this._serviceUrl);
|
|
97
|
-
url.path.join(this._resource.name);
|
|
98
|
-
url.path.get(url.path.size - 1).key = keyValue;
|
|
99
|
-
return {
|
|
100
|
-
method: 'DELETE',
|
|
101
|
-
url: url.address,
|
|
102
|
-
params: url.searchParams
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
_prepareDeleteManyRequest(options) {
|
|
106
|
-
const url = new OpraURL(this._serviceUrl);
|
|
107
|
-
url.path.join(this._resource.name);
|
|
108
|
-
if (options.filter)
|
|
109
|
-
url.searchParams.set('$filter', options.filter);
|
|
110
|
-
return {
|
|
111
|
-
method: 'DELETE',
|
|
112
|
-
url: url.address,
|
|
113
|
-
params: url.searchParams
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
_prepareGetRequest(keyValue, options) {
|
|
117
|
-
const url = new OpraURL(this._serviceUrl);
|
|
118
|
-
url.path.join(this._resource.name);
|
|
119
|
-
url.path.get(url.path.size - 1).key = keyValue;
|
|
120
|
-
if (options.include)
|
|
121
|
-
url.searchParams.set('$include', options.include);
|
|
122
|
-
if (options.pick)
|
|
123
|
-
url.searchParams.set('$pick', options.pick);
|
|
124
|
-
if (options.omit)
|
|
125
|
-
url.searchParams.set('$omit', options.omit);
|
|
126
|
-
return {
|
|
127
|
-
method: 'GET',
|
|
128
|
-
url: url.address,
|
|
129
|
-
params: url.searchParams
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
_prepareSearchRequest(options) {
|
|
133
|
-
const url = new OpraURL(this._serviceUrl);
|
|
134
|
-
url.path.join(this._resource.name);
|
|
135
|
-
if (options.include)
|
|
136
|
-
url.searchParams.set('$include', options.include);
|
|
137
|
-
if (options.pick)
|
|
138
|
-
url.searchParams.set('$pick', options.pick);
|
|
139
|
-
if (options.omit)
|
|
140
|
-
url.searchParams.set('$omit', options.omit);
|
|
141
|
-
if (options.sort)
|
|
142
|
-
url.searchParams.set('$sort', options.sort);
|
|
143
|
-
if (options.filter)
|
|
144
|
-
url.searchParams.set('$filter', options.filter);
|
|
145
|
-
if (options.limit != null)
|
|
146
|
-
url.searchParams.set('$limit', options.limit);
|
|
147
|
-
if (options.skip != null)
|
|
148
|
-
url.searchParams.set('$skip', options.skip);
|
|
149
|
-
if (options.count != null)
|
|
150
|
-
url.searchParams.set('$count', options.count);
|
|
151
|
-
if (options.distinct != null)
|
|
152
|
-
url.searchParams.set('$distinct', options.distinct);
|
|
153
|
-
return {
|
|
154
|
-
method: 'GET',
|
|
155
|
-
url: url.address,
|
|
156
|
-
params: url.searchParams
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
_prepareUpdateRequest(keyValue, data, options) {
|
|
160
|
-
const url = new OpraURL(this._serviceUrl);
|
|
161
|
-
url.path.join(this._resource.name);
|
|
162
|
-
url.path.get(url.path.size - 1).key = keyValue;
|
|
163
|
-
if (options.include)
|
|
164
|
-
url.searchParams.set('$include', options.include);
|
|
165
|
-
if (options.pick)
|
|
166
|
-
url.searchParams.set('$pick', options.pick);
|
|
167
|
-
if (options.omit)
|
|
168
|
-
url.searchParams.set('$omit', options.omit);
|
|
169
|
-
return {
|
|
170
|
-
method: 'PATCH',
|
|
171
|
-
url: url.address,
|
|
172
|
-
data,
|
|
173
|
-
params: url.searchParams
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
_prepareUpdateManyRequest(data, options) {
|
|
177
|
-
const url = new OpraURL(this._serviceUrl);
|
|
178
|
-
url.path.join(this._resource.name);
|
|
179
|
-
if (options.filter)
|
|
180
|
-
url.searchParams.set('$filter', options.filter);
|
|
181
|
-
return {
|
|
182
|
-
method: 'PATCH',
|
|
183
|
-
url: url.address,
|
|
184
|
-
data,
|
|
185
|
-
params: url.searchParams
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { OpraDocument, SingletonGetQueryOptions, SingletonResourceInfo } from '@opra/schema';
|
|
3
|
-
import { SingletonGetRequest } from '../requests/singleton-get-request.js';
|
|
4
|
-
import { OpraResponse } from '../response.js';
|
|
5
|
-
import { ObservablePromiseLike, RequestConfig } from '../types.js';
|
|
6
|
-
export declare class SingletonService<T, TResponse extends OpraResponse<T> = OpraResponse<T>> {
|
|
7
|
-
protected _serviceUrl: string;
|
|
8
|
-
protected _document: OpraDocument;
|
|
9
|
-
protected _handler: (req: AxiosRequestConfig) => Promise<any>;
|
|
10
|
-
protected _resource: SingletonResourceInfo;
|
|
11
|
-
constructor(_serviceUrl: string, _document: OpraDocument, _handler: (req: AxiosRequestConfig) => Promise<any>, _resource: SingletonResourceInfo);
|
|
12
|
-
get(options?: SingletonGetQueryOptions | ((req: SingletonGetRequest) => void)): ObservablePromiseLike<TResponse>;
|
|
13
|
-
protected _prepareGetRequest(options: SingletonGetQueryOptions): RequestConfig;
|
|
14
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { OpraURL } from '@opra/url';
|
|
2
|
-
import { observablePromise } from '../observable-promise.js';
|
|
3
|
-
import { SingletonGetRequest } from '../requests/singleton-get-request.js';
|
|
4
|
-
export class SingletonService {
|
|
5
|
-
_serviceUrl;
|
|
6
|
-
_document;
|
|
7
|
-
_handler;
|
|
8
|
-
_resource;
|
|
9
|
-
constructor(_serviceUrl, _document, _handler, _resource) {
|
|
10
|
-
this._serviceUrl = _serviceUrl;
|
|
11
|
-
this._document = _document;
|
|
12
|
-
this._handler = _handler;
|
|
13
|
-
this._resource = _resource;
|
|
14
|
-
}
|
|
15
|
-
get(options) {
|
|
16
|
-
const requestOptions = options && typeof options === 'object' ? options : {};
|
|
17
|
-
const requestWrapper = new SingletonGetRequest(requestOptions);
|
|
18
|
-
if (typeof options === 'function')
|
|
19
|
-
options(requestWrapper);
|
|
20
|
-
const req = this._prepareGetRequest(requestOptions);
|
|
21
|
-
const promise = this._handler(req);
|
|
22
|
-
return observablePromise(promise);
|
|
23
|
-
}
|
|
24
|
-
_prepareGetRequest(options) {
|
|
25
|
-
const url = new OpraURL(this._serviceUrl);
|
|
26
|
-
url.path.join(this._resource.name);
|
|
27
|
-
if (options.include)
|
|
28
|
-
url.searchParams.set('$include', options.include);
|
|
29
|
-
if (options.pick)
|
|
30
|
-
url.searchParams.set('$pick', options.pick);
|
|
31
|
-
if (options.omit)
|
|
32
|
-
url.searchParams.set('$omit', options.omit);
|
|
33
|
-
return {
|
|
34
|
-
method: 'GET',
|
|
35
|
-
url: url.address,
|
|
36
|
-
params: url.searchParams
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}
|