@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.
Files changed (100) hide show
  1. package/cjs/constants.js +6 -0
  2. package/cjs/http/http-client.js +164 -0
  3. package/cjs/http/http-collection-service.js +40 -0
  4. package/cjs/http/http-request.js +66 -0
  5. package/cjs/{response.js → http/http-response.js} +0 -0
  6. package/cjs/http/http-singleton-service.js +16 -0
  7. package/cjs/http/http-types.js +2 -0
  8. package/cjs/http/requests/batch-request.js +80 -0
  9. package/cjs/http/requests/collection-create-request.js +35 -0
  10. package/cjs/http/requests/collection-delete-many-request.js +28 -0
  11. package/cjs/http/requests/collection-delete-request.js +29 -0
  12. package/cjs/http/requests/collection-get-request.js +37 -0
  13. package/cjs/http/requests/collection-search-request.js +44 -0
  14. package/cjs/http/requests/collection-update-many-request.js +31 -0
  15. package/cjs/http/requests/collection-update-request.js +40 -0
  16. package/cjs/http/requests/http-singleton-get-request.js +31 -0
  17. package/cjs/http/utils/merge-raw-http-requests.util.js +29 -0
  18. package/cjs/index.js +16 -4
  19. package/cjs/interfaces/http-options.interface.js +2 -0
  20. package/cjs/interfaces/http-request-config.interface.js +2 -0
  21. package/cjs/types.js +0 -9
  22. package/esm/client-error.d.ts +1 -1
  23. package/esm/constants.d.ts +3 -0
  24. package/esm/constants.js +3 -0
  25. package/esm/http/http-client.d.ts +26 -0
  26. package/esm/http/http-client.js +160 -0
  27. package/esm/http/http-collection-service.d.ts +22 -0
  28. package/esm/http/http-collection-service.js +36 -0
  29. package/esm/http/http-request.d.ts +25 -0
  30. package/esm/http/http-request.js +62 -0
  31. package/esm/http/http-response.d.ts +14 -0
  32. package/esm/{response.js → http/http-response.js} +0 -0
  33. package/esm/http/http-singleton-service.d.ts +10 -0
  34. package/esm/http/http-singleton-service.js +12 -0
  35. package/esm/http/http-types.d.ts +26 -0
  36. package/esm/http/http-types.js +1 -0
  37. package/esm/http/requests/batch-request.d.ts +18 -0
  38. package/esm/http/requests/batch-request.js +76 -0
  39. package/esm/http/requests/collection-create-request.d.ts +12 -0
  40. package/esm/http/requests/collection-create-request.js +31 -0
  41. package/esm/http/requests/collection-delete-many-request.d.ts +11 -0
  42. package/esm/http/requests/collection-delete-many-request.js +24 -0
  43. package/esm/http/requests/collection-delete-request.d.ts +12 -0
  44. package/esm/http/requests/collection-delete-request.js +25 -0
  45. package/esm/http/requests/collection-get-request.d.ts +12 -0
  46. package/esm/http/requests/collection-get-request.js +33 -0
  47. package/esm/http/requests/collection-search-request.d.ts +11 -0
  48. package/esm/http/requests/collection-search-request.js +40 -0
  49. package/esm/http/requests/collection-update-many-request.d.ts +12 -0
  50. package/esm/http/requests/collection-update-many-request.js +27 -0
  51. package/esm/http/requests/collection-update-request.d.ts +13 -0
  52. package/esm/http/requests/collection-update-request.js +36 -0
  53. package/esm/http/requests/http-singleton-get-request.d.ts +11 -0
  54. package/esm/http/requests/http-singleton-get-request.js +27 -0
  55. package/esm/http/utils/merge-raw-http-requests.util.d.ts +2 -0
  56. package/esm/http/utils/merge-raw-http-requests.util.js +25 -0
  57. package/esm/index.d.ts +16 -4
  58. package/esm/index.js +16 -4
  59. package/esm/interfaces/http-options.interface.d.ts +20 -0
  60. package/esm/interfaces/http-options.interface.js +1 -0
  61. package/esm/interfaces/http-request-config.interface.d.ts +23 -0
  62. package/esm/interfaces/http-request-config.interface.js +1 -0
  63. package/esm/types.d.ts +7 -10
  64. package/esm/types.js +0 -9
  65. package/package.json +25 -16
  66. package/umd/opra-client.umd.min.js +1 -0
  67. package/cjs/client.js +0 -96
  68. package/cjs/observable-promise.js +0 -10
  69. package/cjs/requests/collection-create-request.js +0 -22
  70. package/cjs/requests/collection-delete-many-request.js +0 -14
  71. package/cjs/requests/collection-get-request.js +0 -22
  72. package/cjs/requests/collection-search-request.js +0 -46
  73. package/cjs/requests/collection-update-many-request.js +0 -14
  74. package/cjs/requests/collection-update-request.js +0 -22
  75. package/cjs/requests/singleton-get-request.js +0 -22
  76. package/cjs/services/collection-service.js +0 -192
  77. package/cjs/services/singleton-service.js +0 -43
  78. package/esm/client.d.ts +0 -25
  79. package/esm/client.js +0 -91
  80. package/esm/observable-promise.d.ts +0 -2
  81. package/esm/observable-promise.js +0 -6
  82. package/esm/requests/collection-create-request.d.ts +0 -8
  83. package/esm/requests/collection-create-request.js +0 -18
  84. package/esm/requests/collection-delete-many-request.d.ts +0 -7
  85. package/esm/requests/collection-delete-many-request.js +0 -10
  86. package/esm/requests/collection-get-request.d.ts +0 -8
  87. package/esm/requests/collection-get-request.js +0 -18
  88. package/esm/requests/collection-search-request.d.ts +0 -15
  89. package/esm/requests/collection-search-request.js +0 -42
  90. package/esm/requests/collection-update-many-request.d.ts +0 -7
  91. package/esm/requests/collection-update-many-request.js +0 -10
  92. package/esm/requests/collection-update-request.d.ts +0 -8
  93. package/esm/requests/collection-update-request.js +0 -18
  94. package/esm/requests/singleton-get-request.d.ts +0 -8
  95. package/esm/requests/singleton-get-request.js +0 -18
  96. package/esm/response.d.ts +0 -9
  97. package/esm/services/collection-service.d.ts +0 -31
  98. package/esm/services/collection-service.js +0 -188
  99. package/esm/services/singleton-service.d.ts +0 -14
  100. package/esm/services/singleton-service.js +0 -39
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FORMDATA_CONTENT_TYPE_PATTERN = exports.TEXT_CONTENT_TYPE_PATTERN = exports.JSON_CONTENT_TYPE_PATTERN = void 0;
4
+ exports.JSON_CONTENT_TYPE_PATTERN = /^application\/([\w-]+\+)?\bjson\b/i;
5
+ exports.TEXT_CONTENT_TYPE_PATTERN = /^text\/.*$/i;
6
+ exports.FORMDATA_CONTENT_TYPE_PATTERN = /^multipart\/\bform-data\b/i;
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpraHttpClient = void 0;
4
+ const common_1 = require("@opra/common");
5
+ const client_error_js_1 = require("../client-error.js");
6
+ const constants_js_1 = require("../constants.js");
7
+ const http_collection_service_js_1 = require("./http-collection-service.js");
8
+ const http_singleton_service_js_1 = require("./http-singleton-service.js");
9
+ const batch_request_js_1 = require("./requests/batch-request.js");
10
+ const merge_raw_http_requests_util_js_1 = require("./utils/merge-raw-http-requests.util.js");
11
+ const documentCache = new Map();
12
+ const documentResolverCaches = new Map();
13
+ class OpraHttpClient {
14
+ _serviceUrl;
15
+ _metadata;
16
+ defaults;
17
+ constructor(serviceUrl, options) {
18
+ this._serviceUrl = serviceUrl;
19
+ this._metadata = options?.document;
20
+ if (!this._metadata) {
21
+ const document = documentCache.get(this.serviceUrl.toLowerCase());
22
+ if (document)
23
+ this._metadata = document;
24
+ }
25
+ this.defaults = options?.defaults || {};
26
+ }
27
+ get serviceUrl() {
28
+ return this._serviceUrl;
29
+ }
30
+ get initialized() {
31
+ return !!this._metadata;
32
+ }
33
+ get metadata() {
34
+ this._assertMetadata();
35
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
36
+ return this._metadata;
37
+ }
38
+ async init(forceRefresh) {
39
+ if (!forceRefresh && this.initialized)
40
+ return;
41
+ const cacheName = this.serviceUrl.toLowerCase();
42
+ let promise = documentResolverCaches.get(cacheName);
43
+ if (promise) {
44
+ await promise;
45
+ return;
46
+ }
47
+ promise = this._resolveMetadata();
48
+ documentResolverCaches.set(cacheName, promise);
49
+ return promise
50
+ .catch(() => void 0)
51
+ .finally(() => documentResolverCaches.delete(cacheName));
52
+ }
53
+ batch(requests) {
54
+ this._assertMetadata();
55
+ return new batch_request_js_1.BatchRequest(req => this._handleRequest(req), requests);
56
+ }
57
+ collection(name) {
58
+ this._assertMetadata();
59
+ // If name argument is a class, we extract name from the class
60
+ if (typeof name === 'function')
61
+ name = name.name;
62
+ const resource = this.metadata.getCollectionResource(name);
63
+ return new http_collection_service_js_1.HttpCollectionService(resource, req => this._handleRequest(req));
64
+ }
65
+ singleton(name) {
66
+ this._assertMetadata();
67
+ // If name argument is a class, we extract name from the class
68
+ if (typeof name === 'function')
69
+ name = name.name;
70
+ const resource = this.metadata.getSingletonResource(name);
71
+ return new http_singleton_service_js_1.HttpSingletonService(resource, req => this._handleRequest(req));
72
+ }
73
+ async _resolveMetadata() {
74
+ const resp = await this._handleRequest({
75
+ method: 'GET',
76
+ path: '/$metadata',
77
+ headers: { 'accept': 'application/json' }
78
+ });
79
+ this._metadata = new common_1.OpraDocument(resp.data);
80
+ }
81
+ async _handleRequest(req) {
82
+ (0, merge_raw_http_requests_util_js_1.mergeRawHttpRequests)(req, this.defaults);
83
+ let url = (0, common_1.joinPath)(this.serviceUrl, req.path);
84
+ if (req.params)
85
+ url += '?' + req.params.toString();
86
+ if (req.body) {
87
+ if (typeof req.body === 'object') {
88
+ if (!((0, common_1.isReadable)(req.body) || (0, common_1.isReadableStream)(req.body) || Buffer.isBuffer(req.body))) {
89
+ if (!req.headers?.['content-type']) {
90
+ req.headers = req.headers || {};
91
+ req.headers['content-type'] = 'application/json';
92
+ }
93
+ req.body = JSON.stringify(req.body);
94
+ }
95
+ }
96
+ }
97
+ return this._fetch(url, req);
98
+ }
99
+ async _fetch(url, req) {
100
+ const resp = await fetch(url, req);
101
+ let data;
102
+ if (resp.body) {
103
+ if (constants_js_1.JSON_CONTENT_TYPE_PATTERN.test(resp.headers.get('Content-Type') || '')) {
104
+ data = await resp.json();
105
+ if (typeof data === 'string')
106
+ data = JSON.parse(data);
107
+ }
108
+ else if (constants_js_1.TEXT_CONTENT_TYPE_PATTERN.test(resp.headers.get('Content-Type') || ''))
109
+ data = await resp.text();
110
+ else if (constants_js_1.FORMDATA_CONTENT_TYPE_PATTERN.test(resp.headers.get('Content-Type') || ''))
111
+ data = await resp.formData();
112
+ else
113
+ data = await resp.arrayBuffer();
114
+ }
115
+ if (resp.status >= 400 && resp.status < 600) {
116
+ throw new client_error_js_1.ClientError({
117
+ message: resp.status + ' ' + resp.statusText,
118
+ status: resp.status,
119
+ issues: data?.errors
120
+ });
121
+ }
122
+ const out = {
123
+ get headers() {
124
+ return resp.headers;
125
+ },
126
+ get ok() {
127
+ return resp.ok;
128
+ },
129
+ get redirected() {
130
+ return resp.redirected;
131
+ },
132
+ get status() {
133
+ return resp.status;
134
+ },
135
+ get statusText() {
136
+ return resp.statusText;
137
+ },
138
+ get type() {
139
+ return resp.type;
140
+ },
141
+ get url() {
142
+ return resp.url;
143
+ },
144
+ get contentId() {
145
+ return resp.headers.get('Content-ID');
146
+ },
147
+ get data() {
148
+ return data;
149
+ }
150
+ };
151
+ return out;
152
+ }
153
+ _assertMetadata() {
154
+ if (!this._metadata)
155
+ throw new Error('You must call init() to before using the client instance');
156
+ }
157
+ static async create(serviceUrl, options) {
158
+ const client = new this(serviceUrl, options);
159
+ if (!client._metadata)
160
+ await client.init();
161
+ return client;
162
+ }
163
+ }
164
+ exports.OpraHttpClient = OpraHttpClient;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpCollectionService = void 0;
4
+ const collection_create_request_js_1 = require("./requests/collection-create-request.js");
5
+ const collection_delete_many_request_js_1 = require("./requests/collection-delete-many-request.js");
6
+ const collection_delete_request_js_1 = require("./requests/collection-delete-request.js");
7
+ const collection_get_request_js_1 = require("./requests/collection-get-request.js");
8
+ const collection_search_request_js_1 = require("./requests/collection-search-request.js");
9
+ const collection_update_many_request_js_1 = require("./requests/collection-update-many-request.js");
10
+ const collection_update_request_js_1 = require("./requests/collection-update-request.js");
11
+ class HttpCollectionService {
12
+ resource;
13
+ _handler;
14
+ constructor(resource, _handler) {
15
+ this.resource = resource;
16
+ this._handler = _handler;
17
+ }
18
+ create(data, options) {
19
+ return new collection_create_request_js_1.CollectionCreateRequest(this._handler, this.resource, data, options);
20
+ }
21
+ delete(keyValue, options) {
22
+ return new collection_delete_request_js_1.CollectionDeleteRequest(this._handler, this.resource, keyValue, options);
23
+ }
24
+ deleteMany(options) {
25
+ return new collection_delete_many_request_js_1.CollectionDeleteManyRequest(this._handler, this.resource, options);
26
+ }
27
+ get(keyValue, options) {
28
+ return new collection_get_request_js_1.CollectionGetRequest(this._handler, this.resource, keyValue, options);
29
+ }
30
+ search(options) {
31
+ return new collection_search_request_js_1.CollectionSearchRequest(this._handler, this.resource, options);
32
+ }
33
+ update(keyValue, data, options) {
34
+ return new collection_update_request_js_1.CollectionUpdateRequest(this._handler, this.resource, keyValue, data, options);
35
+ }
36
+ updateMany(data, options) {
37
+ return new collection_update_many_request_js_1.CollectionUpdateManyRequest(this._handler, this.resource, data, options);
38
+ }
39
+ }
40
+ exports.HttpCollectionService = HttpCollectionService;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpRequest = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ const common_1 = require("@opra/common");
6
+ class HttpRequest extends rxjs_1.Observable {
7
+ _handler;
8
+ options;
9
+ contentId;
10
+ _promise;
11
+ _headers;
12
+ constructor(_handler, options = {}) {
13
+ super((subscriber) => {
14
+ if (options.observe === 'response') {
15
+ this.fetch().then(v => {
16
+ subscriber.next(v);
17
+ subscriber.complete();
18
+ }).catch(e => subscriber.error(e));
19
+ return;
20
+ }
21
+ this.resolve().then(v => {
22
+ subscriber.next(v);
23
+ subscriber.complete();
24
+ }).catch(e => subscriber.error(e));
25
+ });
26
+ this._handler = _handler;
27
+ this.options = options;
28
+ this.contentId = (0, common_1.uid)(6);
29
+ this.options = options;
30
+ }
31
+ header(name, value) {
32
+ this._headers = this._headers || {};
33
+ this._headers[name] = value;
34
+ return this;
35
+ }
36
+ /**
37
+ * Sends the request
38
+ */
39
+ async fetch() {
40
+ const promise = this._promise || (this._promise = new Promise((resolve, reject) => {
41
+ setTimeout(() => {
42
+ this._execute().then(resolve).catch(reject);
43
+ }, 0);
44
+ }));
45
+ return await promise;
46
+ }
47
+ /**
48
+ * Sends the request and returns response data
49
+ */
50
+ async resolve() {
51
+ const resp = await this.fetch();
52
+ return resp.data;
53
+ }
54
+ with(cb) {
55
+ cb(this);
56
+ return this;
57
+ }
58
+ binding() {
59
+ return {};
60
+ }
61
+ async _execute() {
62
+ const req = this.prepare();
63
+ return await this._handler(req);
64
+ }
65
+ }
66
+ exports.HttpRequest = HttpRequest;
File without changes
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpSingletonService = void 0;
4
+ const http_singleton_get_request_js_1 = require("./requests/http-singleton-get-request.js");
5
+ class HttpSingletonService {
6
+ resource;
7
+ _handler;
8
+ constructor(resource, _handler) {
9
+ this.resource = resource;
10
+ this._handler = _handler;
11
+ }
12
+ get(options) {
13
+ return new http_singleton_get_request_js_1.HttpSingletonGetRequest(this._handler, this.resource, options);
14
+ }
15
+ }
16
+ exports.HttpSingletonService = HttpSingletonService;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BatchRequest = void 0;
4
+ const common_1 = require("@opra/common");
5
+ const http_request_js_1 = require("../http-request.js");
6
+ const merge_raw_http_requests_util_js_1 = require("../utils/merge-raw-http-requests.util.js");
7
+ class BatchRequest extends http_request_js_1.HttpRequest {
8
+ _handler;
9
+ requests;
10
+ options;
11
+ _results = new WeakMap();
12
+ _listeners = new Set();
13
+ constructor(_handler, requests, options = {}) {
14
+ super(_handler, options);
15
+ this._handler = _handler;
16
+ this.requests = requests;
17
+ this.options = options;
18
+ requests.forEach(request => {
19
+ // Overwrite the _execute method
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 = (error, response) => {
33
+ this._listeners.delete(callback);
34
+ if (error)
35
+ return reject(error);
36
+ resolve(response);
37
+ };
38
+ this._listeners.add(callback);
39
+ });
40
+ }
41
+ });
42
+ });
43
+ }
44
+ prepare() {
45
+ const batch = this._buildBatchMultipart(this);
46
+ const headers = {
47
+ 'content-type': 'multipart/mixed;boundary=' + batch.boundary
48
+ };
49
+ return (0, merge_raw_http_requests_util_js_1.mergeRawHttpRequests)({
50
+ method: 'POST',
51
+ path: '/$batch',
52
+ headers,
53
+ body: batch.stream()
54
+ }, this.options.http);
55
+ }
56
+ _buildBatchMultipart(batch) {
57
+ const multipart = new common_1.BatchMultipart();
58
+ for (const req of batch.requests) {
59
+ const prepared = req.prepare();
60
+ if (req instanceof BatchRequest) {
61
+ const subMultipart = this._buildBatchMultipart(req);
62
+ multipart.addBatch(subMultipart);
63
+ continue;
64
+ }
65
+ multipart.addRequestPart({
66
+ method: prepared.method,
67
+ url: prepared.path,
68
+ headers: prepared.headers,
69
+ data: prepared.body
70
+ });
71
+ }
72
+ return multipart;
73
+ }
74
+ async _execute() {
75
+ const req = this.prepare();
76
+ const resp = await this._handler(req);
77
+ return resp;
78
+ }
79
+ }
80
+ exports.BatchRequest = BatchRequest;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CollectionCreateRequest = void 0;
4
+ const common_1 = require("@opra/common");
5
+ const http_request_js_1 = require("../http-request.js");
6
+ const merge_raw_http_requests_util_js_1 = require("../utils/merge-raw-http-requests.util.js");
7
+ class CollectionCreateRequest extends http_request_js_1.HttpRequest {
8
+ _handler;
9
+ resource;
10
+ data;
11
+ options;
12
+ constructor(_handler, resource, data, options = {}) {
13
+ super(_handler, options);
14
+ this._handler = _handler;
15
+ this.resource = resource;
16
+ this.data = data;
17
+ this.options = options;
18
+ }
19
+ prepare() {
20
+ const searchParams = new common_1.OpraURLSearchParams();
21
+ if (this.options.include)
22
+ searchParams.set('$include', this.options.include);
23
+ if (this.options.pick)
24
+ searchParams.set('$pick', this.options.pick);
25
+ if (this.options.omit)
26
+ searchParams.set('$omit', this.options.omit);
27
+ return (0, merge_raw_http_requests_util_js_1.mergeRawHttpRequests)({
28
+ method: 'POST',
29
+ path: this.resource.name,
30
+ params: searchParams,
31
+ body: this.data,
32
+ }, this.options.http);
33
+ }
34
+ }
35
+ exports.CollectionCreateRequest = CollectionCreateRequest;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CollectionDeleteManyRequest = void 0;
4
+ const common_1 = require("@opra/common");
5
+ const http_request_js_1 = require("../http-request.js");
6
+ const merge_raw_http_requests_util_js_1 = require("../utils/merge-raw-http-requests.util.js");
7
+ class CollectionDeleteManyRequest extends http_request_js_1.HttpRequest {
8
+ _handler;
9
+ resource;
10
+ options;
11
+ constructor(_handler, resource, options = {}) {
12
+ super(_handler, options);
13
+ this._handler = _handler;
14
+ this.resource = resource;
15
+ this.options = options;
16
+ }
17
+ prepare() {
18
+ const searchParams = new common_1.OpraURLSearchParams();
19
+ if (this.options.filter)
20
+ searchParams.set('$filter', this.options.filter);
21
+ return (0, merge_raw_http_requests_util_js_1.mergeRawHttpRequests)({
22
+ method: 'DELETE',
23
+ path: this.resource.name,
24
+ params: searchParams,
25
+ }, this.options.http);
26
+ }
27
+ }
28
+ exports.CollectionDeleteManyRequest = CollectionDeleteManyRequest;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CollectionDeleteRequest = void 0;
4
+ const common_1 = require("@opra/common");
5
+ const http_request_js_1 = require("../http-request.js");
6
+ const merge_raw_http_requests_util_js_1 = require("../utils/merge-raw-http-requests.util.js");
7
+ class CollectionDeleteRequest extends http_request_js_1.HttpRequest {
8
+ _handler;
9
+ resource;
10
+ keyValue;
11
+ options;
12
+ constructor(_handler, resource, keyValue, options = {}) {
13
+ super(_handler, options);
14
+ this._handler = _handler;
15
+ this.resource = resource;
16
+ this.keyValue = keyValue;
17
+ this.options = options;
18
+ }
19
+ prepare() {
20
+ if (this.keyValue == null || this.keyValue === '')
21
+ throw new TypeError('Key value required to perform "delete" request');
22
+ const path = new common_1.OpraURLPath({ resource: this.resource.name, key: this.keyValue });
23
+ return (0, merge_raw_http_requests_util_js_1.mergeRawHttpRequests)({
24
+ method: 'DELETE',
25
+ path: path.toString(),
26
+ }, this.options.http);
27
+ }
28
+ }
29
+ exports.CollectionDeleteRequest = CollectionDeleteRequest;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CollectionGetRequest = void 0;
4
+ const common_1 = require("@opra/common");
5
+ const http_request_js_1 = require("../http-request.js");
6
+ const merge_raw_http_requests_util_js_1 = require("../utils/merge-raw-http-requests.util.js");
7
+ class CollectionGetRequest extends http_request_js_1.HttpRequest {
8
+ _handler;
9
+ resource;
10
+ keyValue;
11
+ options;
12
+ constructor(_handler, resource, keyValue, options = {}) {
13
+ super(_handler, options);
14
+ this._handler = _handler;
15
+ this.resource = resource;
16
+ this.keyValue = keyValue;
17
+ this.options = options;
18
+ }
19
+ prepare() {
20
+ if (this.keyValue == null || this.keyValue === '')
21
+ throw new TypeError('Key value required to perform "get" request');
22
+ const path = new common_1.OpraURLPath({ resource: this.resource.name, key: this.keyValue });
23
+ const searchParams = new common_1.OpraURLSearchParams();
24
+ if (this.options.include)
25
+ searchParams.set('$include', this.options.include);
26
+ if (this.options.pick)
27
+ searchParams.set('$pick', this.options.pick);
28
+ if (this.options.omit)
29
+ searchParams.set('$omit', this.options.omit);
30
+ return (0, merge_raw_http_requests_util_js_1.mergeRawHttpRequests)({
31
+ method: 'GET',
32
+ path: path.toString(),
33
+ params: searchParams
34
+ }, this.options.http);
35
+ }
36
+ }
37
+ exports.CollectionGetRequest = CollectionGetRequest;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CollectionSearchRequest = void 0;
4
+ const common_1 = require("@opra/common");
5
+ const http_request_js_1 = require("../http-request.js");
6
+ const merge_raw_http_requests_util_js_1 = require("../utils/merge-raw-http-requests.util.js");
7
+ class CollectionSearchRequest extends http_request_js_1.HttpRequest {
8
+ _handler;
9
+ resource;
10
+ options;
11
+ constructor(_handler, resource, options = {}) {
12
+ super(_handler, options);
13
+ this._handler = _handler;
14
+ this.resource = resource;
15
+ this.options = options;
16
+ }
17
+ prepare() {
18
+ const searchParams = new common_1.OpraURLSearchParams();
19
+ if (this.options.include)
20
+ searchParams.set('$include', this.options.include);
21
+ if (this.options.pick)
22
+ searchParams.set('$pick', this.options.pick);
23
+ if (this.options.omit)
24
+ searchParams.set('$omit', this.options.omit);
25
+ if (this.options.sort)
26
+ searchParams.set('$sort', this.options.sort);
27
+ if (this.options.filter)
28
+ searchParams.set('$filter', this.options.filter);
29
+ if (this.options.limit != null)
30
+ searchParams.set('$limit', this.options.limit);
31
+ if (this.options.skip != null)
32
+ searchParams.set('$skip', this.options.skip);
33
+ if (this.options.count != null)
34
+ searchParams.set('$count', this.options.count);
35
+ if (this.options.distinct != null)
36
+ searchParams.set('$distinct', this.options.distinct);
37
+ return (0, merge_raw_http_requests_util_js_1.mergeRawHttpRequests)({
38
+ method: 'GET',
39
+ path: this.resource.name,
40
+ params: searchParams
41
+ }, this.options.http);
42
+ }
43
+ }
44
+ exports.CollectionSearchRequest = CollectionSearchRequest;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CollectionUpdateManyRequest = void 0;
4
+ const common_1 = require("@opra/common");
5
+ const http_request_js_1 = require("../http-request.js");
6
+ const merge_raw_http_requests_util_js_1 = require("../utils/merge-raw-http-requests.util.js");
7
+ class CollectionUpdateManyRequest extends http_request_js_1.HttpRequest {
8
+ _handler;
9
+ resource;
10
+ data;
11
+ options;
12
+ constructor(_handler, resource, data, options = {}) {
13
+ super(_handler, options);
14
+ this._handler = _handler;
15
+ this.resource = resource;
16
+ this.data = data;
17
+ this.options = options;
18
+ }
19
+ prepare() {
20
+ const searchParams = new common_1.OpraURLSearchParams();
21
+ if (this.options.filter)
22
+ searchParams.set('$filter', this.options.filter);
23
+ return (0, merge_raw_http_requests_util_js_1.mergeRawHttpRequests)({
24
+ method: 'PATCH',
25
+ path: this.resource.name,
26
+ params: searchParams,
27
+ body: this.data
28
+ }, this.options.http);
29
+ }
30
+ }
31
+ exports.CollectionUpdateManyRequest = CollectionUpdateManyRequest;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CollectionUpdateRequest = void 0;
4
+ const common_1 = require("@opra/common");
5
+ const http_request_js_1 = require("../http-request.js");
6
+ const merge_raw_http_requests_util_js_1 = require("../utils/merge-raw-http-requests.util.js");
7
+ class CollectionUpdateRequest extends http_request_js_1.HttpRequest {
8
+ _handler;
9
+ resource;
10
+ keyValue;
11
+ data;
12
+ options;
13
+ constructor(_handler, resource, keyValue, data, options = {}) {
14
+ super(_handler, options);
15
+ this._handler = _handler;
16
+ this.resource = resource;
17
+ this.keyValue = keyValue;
18
+ this.data = data;
19
+ this.options = options;
20
+ }
21
+ prepare() {
22
+ if (this.keyValue == null || this.keyValue === '')
23
+ throw new TypeError('Key value required to perform "get" request');
24
+ const path = new common_1.OpraURLPath({ resource: this.resource.name, key: this.keyValue });
25
+ const searchParams = new common_1.OpraURLSearchParams();
26
+ if (this.options.include)
27
+ searchParams.set('$include', this.options.include);
28
+ if (this.options.pick)
29
+ searchParams.set('$pick', this.options.pick);
30
+ if (this.options.omit)
31
+ searchParams.set('$omit', this.options.omit);
32
+ return (0, merge_raw_http_requests_util_js_1.mergeRawHttpRequests)({
33
+ method: 'PATCH',
34
+ path: path.toString(),
35
+ params: searchParams,
36
+ body: this.data
37
+ }, this.options.http);
38
+ }
39
+ }
40
+ exports.CollectionUpdateRequest = CollectionUpdateRequest;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpSingletonGetRequest = void 0;
4
+ const http_request_js_1 = require("../http-request.js");
5
+ const merge_raw_http_requests_util_js_1 = require("../utils/merge-raw-http-requests.util.js");
6
+ class HttpSingletonGetRequest extends http_request_js_1.HttpRequest {
7
+ _handler;
8
+ resource;
9
+ options;
10
+ constructor(_handler, resource, options = {}) {
11
+ super(_handler, options);
12
+ this._handler = _handler;
13
+ this.resource = resource;
14
+ this.options = options;
15
+ }
16
+ prepare() {
17
+ const searchParams = new URLSearchParams();
18
+ if (this.options.include)
19
+ searchParams.set('$include', '' + this.options.include);
20
+ if (this.options.pick)
21
+ searchParams.set('$pick', '' + this.options.pick);
22
+ if (this.options.omit)
23
+ searchParams.set('$omit', '' + this.options.omit);
24
+ return (0, merge_raw_http_requests_util_js_1.mergeRawHttpRequests)({
25
+ method: 'GET',
26
+ path: this.resource.name,
27
+ params: searchParams
28
+ }, this.options.http);
29
+ }
30
+ }
31
+ exports.HttpSingletonGetRequest = HttpSingletonGetRequest;