@opra/client 0.4.0 → 0.5.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 (58) hide show
  1. package/cjs/client-request.js +48 -0
  2. package/cjs/client.js +111 -68
  3. package/cjs/index.js +13 -3
  4. package/cjs/requests/batch-request.js +136 -0
  5. package/cjs/requests/collection-create-request.js +28 -15
  6. package/cjs/requests/collection-delete-many-request.js +21 -7
  7. package/cjs/requests/collection-delete-request.js +29 -0
  8. package/cjs/requests/collection-get-request.js +28 -15
  9. package/cjs/requests/collection-search-request.js +38 -40
  10. package/cjs/requests/collection-update-many-request.js +24 -7
  11. package/cjs/requests/collection-update-request.js +31 -15
  12. package/cjs/requests/singleton-get-request.js +25 -15
  13. package/cjs/services/collection-node.js +42 -0
  14. package/cjs/services/singleton-node.js +18 -0
  15. package/cjs/types.js +0 -9
  16. package/esm/client-request.d.ts +17 -0
  17. package/esm/client-request.js +44 -0
  18. package/esm/client.d.ts +27 -18
  19. package/esm/client.js +112 -69
  20. package/esm/index.d.ts +13 -3
  21. package/esm/index.js +13 -3
  22. package/esm/requests/batch-request.d.ts +19 -0
  23. package/esm/requests/batch-request.js +131 -0
  24. package/esm/requests/collection-create-request.d.ts +12 -7
  25. package/esm/requests/collection-create-request.js +28 -15
  26. package/esm/requests/collection-delete-many-request.d.ts +11 -6
  27. package/esm/requests/collection-delete-many-request.js +21 -7
  28. package/esm/requests/collection-delete-request.d.ts +13 -0
  29. package/esm/requests/collection-delete-request.js +25 -0
  30. package/esm/requests/collection-get-request.d.ts +12 -7
  31. package/esm/requests/collection-get-request.js +28 -15
  32. package/esm/requests/collection-search-request.d.ts +11 -14
  33. package/esm/requests/collection-search-request.js +38 -40
  34. package/esm/requests/collection-update-many-request.d.ts +12 -6
  35. package/esm/requests/collection-update-many-request.js +24 -7
  36. package/esm/requests/collection-update-request.d.ts +13 -7
  37. package/esm/requests/collection-update-request.js +31 -15
  38. package/esm/requests/singleton-get-request.d.ts +11 -7
  39. package/esm/requests/singleton-get-request.js +25 -15
  40. package/esm/services/collection-node.d.ts +24 -0
  41. package/esm/services/collection-node.js +38 -0
  42. package/esm/services/singleton-node.d.ts +12 -0
  43. package/esm/services/singleton-node.js +14 -0
  44. package/esm/types.d.ts +33 -6
  45. package/esm/types.js +0 -9
  46. package/package.json +13 -6
  47. package/cjs/observable-promise.js +0 -10
  48. package/cjs/response.js +0 -2
  49. package/cjs/services/collection-service.js +0 -192
  50. package/cjs/services/singleton-service.js +0 -43
  51. package/esm/observable-promise.d.ts +0 -2
  52. package/esm/observable-promise.js +0 -6
  53. package/esm/response.d.ts +0 -9
  54. package/esm/response.js +0 -1
  55. package/esm/services/collection-service.d.ts +0 -31
  56. package/esm/services/collection-service.js +0 -188
  57. package/esm/services/singleton-service.d.ts +0 -14
  58. package/esm/services/singleton-service.js +0 -39
package/esm/index.js CHANGED
@@ -1,5 +1,15 @@
1
1
  export * from './client.js';
2
- export * from './response.js';
2
+ export * from './client-request.js';
3
3
  export * from './types.js';
4
- export * from './services/collection-service.js';
5
- export * from './services/singleton-service.js';
4
+ export * from './client-error.js';
5
+ export * from './services/collection-node.js';
6
+ export * from './services/singleton-node.js';
7
+ export * from './requests/batch-request.js';
8
+ export * from './requests/collection-create-request.js';
9
+ export * from './requests/collection-delete-request.js';
10
+ export * from './requests/collection-delete-many-request.js';
11
+ export * from './requests/collection-get-request.js';
12
+ export * from './requests/collection-search-request.js';
13
+ export * from './requests/collection-update-request.js';
14
+ export * from './requests/collection-update-many-request.js';
15
+ export * from './requests/singleton-get-request.js';
@@ -0,0 +1,19 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import type { OpraClient } from '../client.js';
3
+ import { OpraClientRequest } from '../client-request.js';
4
+ import { ClientResponse, CommonQueryOptions, OpraBatchRequestOptions } from '../types.js';
5
+ export declare const CRLF = "\r\n";
6
+ export declare class BatchRequest<TResponse extends ClientResponse = ClientResponse>// todo
7
+ extends OpraClientRequest<any, TResponse> {
8
+ readonly client: OpraClient;
9
+ readonly requests: OpraClientRequest[];
10
+ options: OpraBatchRequestOptions & CommonQueryOptions;
11
+ protected _results: WeakMap<OpraClientRequest<any, ClientResponse<any>>, {
12
+ error?: Error | undefined;
13
+ response?: ClientResponse<any> | undefined;
14
+ }>;
15
+ protected _listeners: Set<(error: Error | undefined, response?: ClientResponse) => void>;
16
+ constructor(client: OpraClient, requests: OpraClientRequest[], send: (req: AxiosRequestConfig) => Promise<TResponse>, options?: OpraBatchRequestOptions & CommonQueryOptions);
17
+ prepare(): AxiosRequestConfig;
18
+ protected _execute(): Promise<TResponse>;
19
+ }
@@ -0,0 +1,131 @@
1
+ import Highland from 'highland';
2
+ import { uid } from 'uid';
3
+ import { HeadersMap } from '@opra/common';
4
+ import { OpraURL } from '@opra/url';
5
+ import { OpraClientRequest } from '../client-request.js';
6
+ export const CRLF = '\r\n';
7
+ export class BatchRequest// todo
8
+ extends OpraClientRequest {
9
+ client;
10
+ requests;
11
+ options;
12
+ _results = new WeakMap();
13
+ _listeners = new Set();
14
+ constructor(client, requests, send, options = {}) {
15
+ super(client, send, options);
16
+ this.client = client;
17
+ this.requests = requests;
18
+ this.options = options;
19
+ requests.forEach(request => {
20
+ Object.defineProperty(request, '_execute', {
21
+ writable: true,
22
+ enumerable: false,
23
+ configurable: true,
24
+ value: () => {
25
+ return new Promise((resolve, reject) => {
26
+ const x = this._results.get(request);
27
+ if (x) {
28
+ if (x.error)
29
+ return reject(x.error);
30
+ return resolve(x.response);
31
+ }
32
+ const callback = (e, r) => {
33
+ this._listeners.delete(callback);
34
+ if (e)
35
+ return reject(e);
36
+ resolve(r);
37
+ };
38
+ this._listeners.add(callback);
39
+ });
40
+ }
41
+ });
42
+ });
43
+ }
44
+ prepare() {
45
+ const { boundary, stream } = buildBatchStream(this);
46
+ const headers = {
47
+ 'Content-Type': 'multipart/mixed;boundary=' + boundary
48
+ };
49
+ const url = new OpraURL(this.client.serviceUrl);
50
+ url.path.join('/$batch');
51
+ return {
52
+ method: 'POST',
53
+ url: url.address,
54
+ params: url.searchParams,
55
+ headers,
56
+ data: stream
57
+ };
58
+ }
59
+ async _execute() {
60
+ const req = this.prepare();
61
+ return this._send(req);
62
+ }
63
+ }
64
+ function buildBatchStream(batch) {
65
+ const chunks = [];
66
+ let batchIndex = 0;
67
+ let level = 0;
68
+ const processBatch = (_batch) => {
69
+ const boundary = `batch_${++batchIndex}_L${level}_${uid(10)}`;
70
+ for (const req of _batch.requests) {
71
+ chunks.push('--' + boundary + CRLF);
72
+ if (req instanceof BatchRequest) {
73
+ const contentHeaderIndex = chunks.push('');
74
+ chunks.push('Content-Transfer-Encoding: binary' + CRLF + CRLF);
75
+ level++;
76
+ const subBoundary = processBatch(req);
77
+ level--;
78
+ processBatch[contentHeaderIndex] = 'Content-Type: multipart/mixed;boundary=' + subBoundary + CRLF;
79
+ continue;
80
+ }
81
+ const prepared = req.prepare();
82
+ let s = 'Content-Type: application/http' + CRLF +
83
+ 'Content-Transfer-Encoding: binary' + CRLF +
84
+ 'Content-ID:' + req.id + CRLF +
85
+ CRLF +
86
+ (prepared.method || 'GET').toUpperCase() + ' ' + prepared.url + ' HTTP/1.1' + CRLF;
87
+ const headers = new HeadersMap(prepared.headers);
88
+ let data;
89
+ let contentType = '';
90
+ if (prepared.data) {
91
+ if (typeof prepared.data === 'string') {
92
+ contentType = 'text/plain; charset=utf-8';
93
+ data = prepared.data;
94
+ }
95
+ else if (Highland.isStream(prepared.data) || Buffer.isBuffer(prepared.data)) {
96
+ data = prepared.data;
97
+ }
98
+ else if (typeof prepared.data.stream === 'function') {
99
+ contentType = prepared.data.type || 'binary';
100
+ data = prepared.data.stream(); // File and Blob
101
+ }
102
+ else if (typeof prepared.data === 'object') {
103
+ contentType = 'application/json; charset=utf-8';
104
+ data = JSON.stringify(prepared.data);
105
+ }
106
+ else
107
+ throw new TypeError(`Invalid data type ${typeof prepared.data}`);
108
+ }
109
+ if (contentType && !headers.has('Content-Type'))
110
+ headers.set('Content-Type', contentType);
111
+ headers.forEach((v, k) => {
112
+ s += k + ': ' + (Array.isArray(v) ? v.join(';') : v) + CRLF;
113
+ });
114
+ if (data) {
115
+ if (typeof data === 'string')
116
+ chunks.push(s + CRLF + data + CRLF + CRLF);
117
+ else {
118
+ chunks.push(s + CRLF);
119
+ chunks.push(data);
120
+ chunks.push(CRLF + CRLF);
121
+ }
122
+ }
123
+ else
124
+ chunks.push(s + CRLF + CRLF);
125
+ }
126
+ chunks.push('--' + boundary + '--' + CRLF);
127
+ return boundary;
128
+ };
129
+ const boundary = processBatch(batch);
130
+ return { boundary, stream: Highland(chunks).flatten() };
131
+ }
@@ -1,8 +1,13 @@
1
- import { CollectionCreateQueryOptions } from '@opra/schema';
2
- export declare class CollectionCreateRequest {
3
- protected _options: CollectionCreateQueryOptions;
4
- constructor(_options?: CollectionCreateQueryOptions);
5
- omit(...fields: (string | string[])[]): this;
6
- pick(...fields: (string | string[])[]): this;
7
- include(...fields: (string | string[])[]): this;
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { CollectionCreateQueryOptions, CollectionResourceInfo } from '@opra/schema';
3
+ import type { OpraClient } from '../client.js';
4
+ import { OpraClientRequest } from '../client-request.js';
5
+ import { ClientResponse, CommonQueryOptions, PartialInput } from '../types.js';
6
+ export declare class CollectionCreateRequest<T, TResponse extends ClientResponse<T>> extends OpraClientRequest<T, TResponse> {
7
+ readonly client: OpraClient;
8
+ readonly resource: CollectionResourceInfo;
9
+ data: PartialInput<T>;
10
+ options: CollectionCreateQueryOptions & CommonQueryOptions;
11
+ constructor(client: OpraClient, send: (req: AxiosRequestConfig) => Promise<TResponse>, resource: CollectionResourceInfo, data: PartialInput<T>, options?: CollectionCreateQueryOptions & CommonQueryOptions);
12
+ prepare(): AxiosRequestConfig;
8
13
  }
@@ -1,18 +1,31 @@
1
- export class CollectionCreateRequest {
2
- _options;
3
- constructor(_options = {}) {
4
- this._options = _options;
1
+ import { OpraURL } from '@opra/url';
2
+ import { OpraClientRequest } from '../client-request.js';
3
+ export class CollectionCreateRequest extends OpraClientRequest {
4
+ client;
5
+ resource;
6
+ data;
7
+ options;
8
+ constructor(client, send, resource, data, options = {}) {
9
+ super(client, send, options);
10
+ this.client = client;
11
+ this.resource = resource;
12
+ this.data = data;
13
+ this.options = options;
5
14
  }
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;
15
+ prepare() {
16
+ const url = new OpraURL(this.client.serviceUrl);
17
+ url.path.join(this.resource.name);
18
+ if (this.options.include)
19
+ url.searchParams.set('$include', this.options.include);
20
+ if (this.options.pick)
21
+ url.searchParams.set('$pick', this.options.pick);
22
+ if (this.options.omit)
23
+ url.searchParams.set('$omit', this.options.omit);
24
+ return {
25
+ method: 'POST',
26
+ url: url.address,
27
+ data: this.data,
28
+ params: url.searchParams
29
+ };
17
30
  }
18
31
  }
@@ -1,7 +1,12 @@
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;
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { CollectionDeleteManyQueryOptions, CollectionResourceInfo } from '@opra/schema';
3
+ import type { OpraClient } from '../client.js';
4
+ import { OpraClientRequest } from '../client-request.js';
5
+ import { ClientResponse, CommonQueryOptions } from '../types.js';
6
+ export declare class CollectionDeleteManyRequest<T, TResponse extends ClientResponse<T>> extends OpraClientRequest<T, TResponse> {
7
+ readonly client: OpraClient;
8
+ readonly resource: CollectionResourceInfo;
9
+ options: CollectionDeleteManyQueryOptions & CommonQueryOptions;
10
+ constructor(client: OpraClient, send: (req: AxiosRequestConfig) => Promise<TResponse>, resource: CollectionResourceInfo, options?: CollectionDeleteManyQueryOptions & CommonQueryOptions);
11
+ prepare(): AxiosRequestConfig;
7
12
  }
@@ -1,10 +1,24 @@
1
- export class CollectionDeleteManyRequest {
2
- _options;
3
- constructor(_options = {}) {
4
- this._options = _options;
1
+ import { OpraURL } from '@opra/url';
2
+ import { OpraClientRequest } from '../client-request.js';
3
+ export class CollectionDeleteManyRequest extends OpraClientRequest {
4
+ client;
5
+ resource;
6
+ options;
7
+ constructor(client, send, resource, options = {}) {
8
+ super(client, send, options);
9
+ this.client = client;
10
+ this.resource = resource;
11
+ this.options = options;
5
12
  }
6
- filter(value) {
7
- this._options.filter = value;
8
- return this;
13
+ prepare() {
14
+ const url = new OpraURL(this.client.serviceUrl);
15
+ url.path.join(this.resource.name);
16
+ if (this.options.filter)
17
+ url.searchParams.set('$filter', this.options.filter);
18
+ return {
19
+ method: 'DELETE',
20
+ url: url.address,
21
+ params: url.searchParams
22
+ };
9
23
  }
10
24
  }
@@ -0,0 +1,13 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { CollectionResourceInfo } from '@opra/schema';
3
+ import type { OpraClient } from '../client.js';
4
+ import { OpraClientRequest } from '../client-request.js';
5
+ import { ClientResponse, CommonQueryOptions } from '../types.js';
6
+ export declare class CollectionDeleteRequest<T, TResponse extends ClientResponse<T>> extends OpraClientRequest<T, TResponse> {
7
+ readonly client: OpraClient;
8
+ readonly resource: CollectionResourceInfo;
9
+ keyValue: any;
10
+ options: CommonQueryOptions;
11
+ constructor(client: OpraClient, send: (req: AxiosRequestConfig) => Promise<TResponse>, resource: CollectionResourceInfo, keyValue: any, options?: CommonQueryOptions);
12
+ prepare(): AxiosRequestConfig;
13
+ }
@@ -0,0 +1,25 @@
1
+ import { OpraURL } from '@opra/url';
2
+ import { OpraClientRequest } from '../client-request.js';
3
+ export class CollectionDeleteRequest extends OpraClientRequest {
4
+ client;
5
+ resource;
6
+ keyValue;
7
+ options;
8
+ constructor(client, send, resource, keyValue, options = {}) {
9
+ super(client, send, options);
10
+ this.client = client;
11
+ this.resource = resource;
12
+ this.keyValue = keyValue;
13
+ this.options = options;
14
+ }
15
+ prepare() {
16
+ const url = new OpraURL(this.client.serviceUrl);
17
+ url.path.join(this.resource.name);
18
+ url.path.get(url.path.size - 1).key = this.keyValue;
19
+ return {
20
+ method: 'DELETE',
21
+ url: url.address,
22
+ params: url.searchParams
23
+ };
24
+ }
25
+ }
@@ -1,8 +1,13 @@
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;
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { CollectionGetQueryOptions, CollectionResourceInfo } from '@opra/schema';
3
+ import type { OpraClient } from '../client.js';
4
+ import { OpraClientRequest } from '../client-request.js';
5
+ import { ClientResponse, CommonQueryOptions } from '../types.js';
6
+ export declare class CollectionGetRequest<T, TResponse extends ClientResponse<T>> extends OpraClientRequest<T, TResponse> {
7
+ readonly client: OpraClient;
8
+ readonly resource: CollectionResourceInfo;
9
+ keyValue: any;
10
+ options: CollectionGetQueryOptions & CommonQueryOptions;
11
+ constructor(client: OpraClient, send: (req: AxiosRequestConfig) => Promise<TResponse>, resource: CollectionResourceInfo, keyValue: any, options?: CollectionGetQueryOptions & CommonQueryOptions);
12
+ prepare(): AxiosRequestConfig;
8
13
  }
@@ -1,18 +1,31 @@
1
- export class CollectionGetRequest {
2
- _options;
3
- constructor(_options = {}) {
4
- this._options = _options;
1
+ import { OpraURL } from '@opra/url';
2
+ import { OpraClientRequest } from '../client-request.js';
3
+ export class CollectionGetRequest extends OpraClientRequest {
4
+ client;
5
+ resource;
6
+ keyValue;
7
+ options;
8
+ constructor(client, send, resource, keyValue, options = {}) {
9
+ super(client, send, options);
10
+ this.client = client;
11
+ this.resource = resource;
12
+ this.keyValue = keyValue;
13
+ this.options = options;
5
14
  }
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;
15
+ prepare() {
16
+ const url = new OpraURL(this.client.serviceUrl);
17
+ url.path.join(this.resource.name);
18
+ url.path.get(url.path.size - 1).key = this.keyValue;
19
+ if (this.options.include)
20
+ url.searchParams.set('$include', this.options.include);
21
+ if (this.options.pick)
22
+ url.searchParams.set('$pick', this.options.pick);
23
+ if (this.options.omit)
24
+ url.searchParams.set('$omit', this.options.omit);
25
+ return {
26
+ method: 'GET',
27
+ url: url.address,
28
+ params: url.searchParams
29
+ };
17
30
  }
18
31
  }
@@ -1,15 +1,12 @@
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;
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { CollectionResourceInfo, CollectionSearchQueryOptions } from '@opra/schema';
3
+ import type { OpraClient } from '../client.js';
4
+ import { OpraClientRequest } from '../client-request.js';
5
+ import { ClientResponse, CommonQueryOptions } from '../types.js';
6
+ export declare class CollectionSearchRequest<T, TResponse extends ClientResponse<T>> extends OpraClientRequest<T, TResponse> {
7
+ readonly client: OpraClient;
8
+ readonly resource: CollectionResourceInfo;
9
+ options: CollectionSearchQueryOptions & CommonQueryOptions;
10
+ constructor(client: OpraClient, send: (req: AxiosRequestConfig) => Promise<TResponse>, resource: CollectionResourceInfo, options?: CollectionSearchQueryOptions & CommonQueryOptions);
11
+ prepare(): AxiosRequestConfig;
15
12
  }
@@ -1,42 +1,40 @@
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;
1
+ import { OpraURL } from '@opra/url';
2
+ import { OpraClientRequest } from '../client-request.js';
3
+ export class CollectionSearchRequest extends OpraClientRequest {
4
+ client;
5
+ resource;
6
+ options;
7
+ constructor(client, send, resource, options = {}) {
8
+ super(client, send, options);
9
+ this.client = client;
10
+ this.resource = resource;
11
+ this.options = options;
12
+ }
13
+ prepare() {
14
+ const url = new OpraURL(this.client.serviceUrl);
15
+ url.path.join(this.resource.name);
16
+ if (this.options.include)
17
+ url.searchParams.set('$include', this.options.include);
18
+ if (this.options.pick)
19
+ url.searchParams.set('$pick', this.options.pick);
20
+ if (this.options.omit)
21
+ url.searchParams.set('$omit', this.options.omit);
22
+ if (this.options.sort)
23
+ url.searchParams.set('$sort', this.options.sort);
24
+ if (this.options.filter)
25
+ url.searchParams.set('$filter', this.options.filter);
26
+ if (this.options.limit != null)
27
+ url.searchParams.set('$limit', this.options.limit);
28
+ if (this.options.skip != null)
29
+ url.searchParams.set('$skip', this.options.skip);
30
+ if (this.options.count != null)
31
+ url.searchParams.set('$count', this.options.count);
32
+ if (this.options.distinct != null)
33
+ url.searchParams.set('$distinct', this.options.distinct);
34
+ return {
35
+ method: 'GET',
36
+ url: url.address,
37
+ params: url.searchParams
38
+ };
41
39
  }
42
40
  }
@@ -1,7 +1,13 @@
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;
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { CollectionResourceInfo, CollectionUpdateManyQueryOptions } from '@opra/schema';
3
+ import type { OpraClient } from '../client.js';
4
+ import { OpraClientRequest } from '../client-request.js';
5
+ import { ClientResponse, CommonQueryOptions, PartialInput } from '../types.js';
6
+ export declare class CollectionUpdateManyRequest<T, TResponse extends ClientResponse<T>> extends OpraClientRequest<T, TResponse> {
7
+ readonly client: OpraClient;
8
+ readonly resource: CollectionResourceInfo;
9
+ data: PartialInput<T>;
10
+ options: CollectionUpdateManyQueryOptions & CommonQueryOptions;
11
+ constructor(client: OpraClient, send: (req: AxiosRequestConfig) => Promise<TResponse>, resource: CollectionResourceInfo, data: PartialInput<T>, options?: CollectionUpdateManyQueryOptions & CommonQueryOptions);
12
+ prepare(): AxiosRequestConfig;
7
13
  }
@@ -1,10 +1,27 @@
1
- export class CollectionUpdateManyRequest {
2
- _options;
3
- constructor(_options = {}) {
4
- this._options = _options;
1
+ import { OpraURL } from '@opra/url';
2
+ import { OpraClientRequest } from '../client-request.js';
3
+ export class CollectionUpdateManyRequest extends OpraClientRequest {
4
+ client;
5
+ resource;
6
+ data;
7
+ options;
8
+ constructor(client, send, resource, data, options = {}) {
9
+ super(client, send, options);
10
+ this.client = client;
11
+ this.resource = resource;
12
+ this.data = data;
13
+ this.options = options;
5
14
  }
6
- filter(value) {
7
- this._options.filter = value;
8
- return this;
15
+ prepare() {
16
+ const url = new OpraURL(this.client.serviceUrl);
17
+ url.path.join(this.resource.name);
18
+ if (this.options.filter)
19
+ url.searchParams.set('$filter', this.options.filter);
20
+ return {
21
+ method: 'PATCH',
22
+ url: url.address,
23
+ data: this.data,
24
+ params: url.searchParams
25
+ };
9
26
  }
10
27
  }
@@ -1,8 +1,14 @@
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;
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { CollectionResourceInfo, CollectionUpdateQueryOptions } from '@opra/schema';
3
+ import type { OpraClient } from '../client.js';
4
+ import { OpraClientRequest } from '../client-request.js';
5
+ import { ClientResponse, CommonQueryOptions, PartialInput } from '../types.js';
6
+ export declare class CollectionUpdateRequest<T, TResponse extends ClientResponse<T>> extends OpraClientRequest<T, TResponse> {
7
+ readonly client: OpraClient;
8
+ readonly resource: CollectionResourceInfo;
9
+ keyValue: any;
10
+ data: PartialInput<T>;
11
+ options: CollectionUpdateQueryOptions & CommonQueryOptions;
12
+ constructor(client: OpraClient, send: (req: AxiosRequestConfig) => Promise<TResponse>, resource: CollectionResourceInfo, keyValue: any, data: PartialInput<T>, options?: CollectionUpdateQueryOptions & CommonQueryOptions);
13
+ prepare(): AxiosRequestConfig;
8
14
  }