@rushdb/javascript-sdk 0.9.3 → 0.9.5

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/{types → dist}/api/create-api.d.ts +6 -2
  2. package/dist/index.cjs +1 -0
  3. package/dist/index.mjs +1 -0
  4. package/dist/index.node.d.ts +137 -0
  5. package/dist/index.worker.d.ts +137 -0
  6. package/{types → dist}/sdk/model.d.ts +4 -4
  7. package/{types → dist}/sdk/record.d.ts +14 -12
  8. package/{types → dist}/sdk/sdk.d.ts +24 -24
  9. package/{types → dist}/sdk/transaction.d.ts +2 -2
  10. package/{types → dist}/types/query.d.ts +3 -3
  11. package/package.json +10 -34
  12. package/CHANGELOG.md +0 -174
  13. package/cjs/api/api.js +0 -328
  14. package/cjs/api/constants.js +0 -7
  15. package/cjs/api/create-api.js +0 -313
  16. package/cjs/api/index.js +0 -8
  17. package/cjs/api/rest-api-proxy.js +0 -22
  18. package/cjs/api/types.js +0 -2
  19. package/cjs/api/utils.js +0 -155
  20. package/cjs/common/constants.js +0 -10
  21. package/cjs/common/utils.js +0 -46
  22. package/cjs/index.cjs.node.js +0 -24
  23. package/cjs/index.cjs.worker.js +0 -24
  24. package/cjs/network/FetchHttpClient.js +0 -138
  25. package/cjs/network/HttpClient.js +0 -59
  26. package/cjs/network/NodeHttpClient.js +0 -103
  27. package/cjs/network/index.js +0 -28
  28. package/cjs/network/types.js +0 -2
  29. package/cjs/package.json +0 -4
  30. package/cjs/sdk/constants.js +0 -13
  31. package/cjs/sdk/errors.js +0 -27
  32. package/cjs/sdk/index.js +0 -23
  33. package/cjs/sdk/model.js +0 -147
  34. package/cjs/sdk/record.js +0 -84
  35. package/cjs/sdk/sdk.js +0 -46
  36. package/cjs/sdk/transaction.js +0 -17
  37. package/cjs/sdk/types.js +0 -2
  38. package/cjs/sdk/utils.js +0 -103
  39. package/cjs/types/expressions.js +0 -2
  40. package/cjs/types/index.js +0 -21
  41. package/cjs/types/query.js +0 -2
  42. package/cjs/types/schema.js +0 -2
  43. package/cjs/types/utils.js +0 -2
  44. package/cjs/types/value.js +0 -2
  45. package/esm/api/api.js +0 -324
  46. package/esm/api/constants.js +0 -4
  47. package/esm/api/create-api.js +0 -309
  48. package/esm/api/index.js +0 -2
  49. package/esm/api/rest-api-proxy.js +0 -18
  50. package/esm/api/types.js +0 -1
  51. package/esm/api/utils.js +0 -139
  52. package/esm/common/constants.js +0 -7
  53. package/esm/common/utils.js +0 -37
  54. package/esm/index.esm.node.js +0 -6
  55. package/esm/index.esm.worker.js +0 -6
  56. package/esm/network/FetchHttpClient.js +0 -133
  57. package/esm/network/HttpClient.js +0 -53
  58. package/esm/network/NodeHttpClient.js +0 -98
  59. package/esm/network/index.js +0 -24
  60. package/esm/network/types.js +0 -1
  61. package/esm/package.json +0 -4
  62. package/esm/sdk/constants.js +0 -10
  63. package/esm/sdk/errors.js +0 -21
  64. package/esm/sdk/index.js +0 -7
  65. package/esm/sdk/model.js +0 -143
  66. package/esm/sdk/record.js +0 -77
  67. package/esm/sdk/sdk.js +0 -42
  68. package/esm/sdk/transaction.js +0 -13
  69. package/esm/sdk/types.js +0 -1
  70. package/esm/sdk/utils.js +0 -93
  71. package/esm/types/expressions.js +0 -1
  72. package/esm/types/index.js +0 -5
  73. package/esm/types/query.js +0 -1
  74. package/esm/types/schema.js +0 -1
  75. package/esm/types/utils.js +0 -1
  76. package/esm/types/value.js +0 -1
  77. package/types/index.d.ts +0 -60
  78. /package/{types → dist}/api/api.d.ts +0 -0
  79. /package/{types → dist}/api/constants.d.ts +0 -0
  80. /package/{types → dist}/api/index.d.ts +0 -0
  81. /package/{types → dist}/api/rest-api-proxy.d.ts +0 -0
  82. /package/{types → dist}/api/types.d.ts +0 -0
  83. /package/{types → dist}/api/utils.d.ts +0 -0
  84. /package/{types → dist}/common/constants.d.ts +0 -0
  85. /package/{types → dist}/common/utils.d.ts +0 -0
  86. /package/{types → dist}/network/FetchHttpClient.d.ts +0 -0
  87. /package/{types → dist}/network/HttpClient.d.ts +0 -0
  88. /package/{types → dist}/network/NodeHttpClient.d.ts +0 -0
  89. /package/{types → dist}/network/index.d.ts +0 -0
  90. /package/{types → dist}/network/types.d.ts +0 -0
  91. /package/{types → dist}/sdk/constants.d.ts +0 -0
  92. /package/{types → dist}/sdk/errors.d.ts +0 -0
  93. /package/{types → dist}/sdk/index.d.ts +0 -0
  94. /package/{types → dist}/sdk/types.d.ts +0 -0
  95. /package/{types → dist}/sdk/utils.d.ts +0 -0
  96. /package/{types → dist}/types/expressions.d.ts +0 -0
  97. /package/{types → dist}/types/index.d.ts +0 -0
  98. /package/{types → dist}/types/schema.d.ts +0 -0
  99. /package/{types → dist}/types/utils.d.ts +0 -0
  100. /package/{types → dist}/types/value.d.ts +0 -0
package/esm/api/api.js DELETED
@@ -1,324 +0,0 @@
1
- import { isArray, isEmptyObject, isObject, isObjectFlat, isString, toBoolean } from '../common/utils.js';
2
- import { createFetcher } from '../network/index.js';
3
- import { EmptyTargetError } from '../sdk/errors.js';
4
- import { DBRecordsBatchDraft, DBRecordDraft, DBRecordInstance, DBRecordsArrayInstance } from '../sdk/record.js';
5
- import { Transaction } from '../sdk/transaction.js';
6
- import { createApi } from './create-api.js';
7
- import { buildUrl, createSearchParams, isTransaction, normalizeRecord, pickTransaction, prepareProperties } from './utils.js';
8
- export class RestAPI {
9
- constructor(token, config) {
10
- this.relations = {
11
- find: async ({ pagination, search, transaction }) => {
12
- const { searchParams } = createSearchParams(search);
13
- const tx = pickTransaction(transaction);
14
- return await this.api.relations.find(searchParams, pagination, tx);
15
- }
16
- };
17
- this.properties = {
18
- delete: async (id, transaction) => {
19
- var _a;
20
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.properties.delete(id, transaction);
21
- },
22
- find: async (searchParams, transaction) => {
23
- var _a;
24
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.properties.find(searchParams, transaction);
25
- },
26
- findById: async (id, transaction) => {
27
- var _a;
28
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.properties.findById(id, transaction);
29
- },
30
- values: async (id, transaction) => {
31
- var _a;
32
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.properties.values(id, transaction);
33
- }
34
- };
35
- this.labels = {
36
- find: async (searchParams, transaction) => {
37
- return this.api.labels.find(searchParams, transaction);
38
- }
39
- };
40
- this.tx = {
41
- begin: async (config) => {
42
- var _a;
43
- const transaction = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.tx.begin(config));
44
- const result = new Transaction(transaction.data.id);
45
- result.init(this);
46
- return result;
47
- },
48
- commit: async (id) => { var _a; return (_a = this.api) === null || _a === void 0 ? void 0 : _a.tx.commit(id); },
49
- get: async (id) => {
50
- var _a;
51
- const transaction = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.tx.get(id));
52
- const result = new Transaction(transaction.data.id);
53
- result.init(this);
54
- return result;
55
- },
56
- rollback: async (id) => { var _a; return (_a = this.api) === null || _a === void 0 ? void 0 : _a.tx.commit(id); }
57
- };
58
- this.fetcher = null;
59
- if (config === null || config === void 0 ? void 0 : config.httpClient) {
60
- const url = buildUrl(config);
61
- this.fetcher = createFetcher({
62
- httpClient: config.httpClient,
63
- token,
64
- url
65
- });
66
- }
67
- this.api = createApi(this.fetcher, config === null || config === void 0 ? void 0 : config.logger);
68
- this.records = {
69
- attach: async (sourceId, target, options, transaction) => {
70
- var _a, _b;
71
- // target is MaybeArray<DBRecordInstance>
72
- if (target instanceof DBRecordInstance) {
73
- const id = (_a = target.data) === null || _a === void 0 ? void 0 : _a.__id;
74
- if (id) {
75
- return await this.api.records.attach(sourceId, id, options, transaction);
76
- }
77
- else {
78
- throw new EmptyTargetError('Attach error: Target id is empty');
79
- }
80
- }
81
- else if (isArray(target) && target.every((r) => r instanceof DBRecordInstance)) {
82
- const ids = target.map((r) => { var _a; return (_a = r.data) === null || _a === void 0 ? void 0 : _a.__id; }).filter(toBoolean);
83
- if (ids.length) {
84
- return await this.api.records.attach(sourceId, ids, options, transaction);
85
- }
86
- else {
87
- throw new EmptyTargetError('Attach error: Target ids are empty');
88
- }
89
- }
90
- // target is DBRecordsArrayInstance
91
- else if (target instanceof DBRecordsArrayInstance) {
92
- const ids = (_b = target.data) === null || _b === void 0 ? void 0 : _b.map((r) => r.__id).filter(Boolean);
93
- if (ids === null || ids === void 0 ? void 0 : ids.length) {
94
- return await this.api.records.attach(sourceId, ids, options, transaction);
95
- }
96
- else {
97
- throw new EmptyTargetError('Attach error: Target ids are empty');
98
- }
99
- }
100
- // target is MaybeArray<DBRecord>
101
- else if (isObject(target) && '__id' in target) {
102
- return await this.api.records.attach(sourceId, target.__id, options, transaction);
103
- }
104
- else if (isArray(target) && target.every((r) => isObject(r) && '__id' in r)) {
105
- const ids = target === null || target === void 0 ? void 0 : target.map((r) => r.__id).filter(Boolean);
106
- if (ids === null || ids === void 0 ? void 0 : ids.length) {
107
- return await this.api.records.attach(sourceId, ids, options, transaction);
108
- }
109
- else {
110
- throw new EmptyTargetError('Attach error: Target ids are empty');
111
- }
112
- }
113
- // target is MaybeArray<string>
114
- else {
115
- return await this.api.records.attach(sourceId, target, options, transaction);
116
- }
117
- },
118
- create: async (labelOrData, maybeDataOrTransaction, transaction) => {
119
- var _a, _b;
120
- let response;
121
- if (labelOrData instanceof DBRecordDraft) {
122
- response = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.create(labelOrData, pickTransaction(maybeDataOrTransaction)));
123
- }
124
- if (!response && isString(labelOrData)) {
125
- if (isObjectFlat(maybeDataOrTransaction)) {
126
- const normalizedRecord = normalizeRecord({
127
- label: labelOrData,
128
- payload: maybeDataOrTransaction
129
- });
130
- response = await ((_b = this.api) === null || _b === void 0 ? void 0 : _b.records.create(new DBRecordDraft(normalizedRecord), transaction));
131
- }
132
- else if (isObject(maybeDataOrTransaction)) {
133
- throw Error('Provided data is not a flat object. Consider to use `createMany` method.');
134
- }
135
- }
136
- if ((response === null || response === void 0 ? void 0 : response.success) && (response === null || response === void 0 ? void 0 : response.data)) {
137
- const result = new DBRecordInstance(response.data);
138
- result.init(this);
139
- return result;
140
- }
141
- return new DBRecordInstance();
142
- },
143
- createMany: async (labelOrData, maybeDataOrTransaction, transaction) => {
144
- var _a, _b;
145
- let response;
146
- if (labelOrData instanceof DBRecordsBatchDraft) {
147
- response = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.createMany(labelOrData, pickTransaction(maybeDataOrTransaction)));
148
- }
149
- if (!response &&
150
- isString(labelOrData) &&
151
- (isArray(maybeDataOrTransaction) || isObject(maybeDataOrTransaction))) {
152
- const data = new DBRecordsBatchDraft({
153
- label: labelOrData,
154
- payload: maybeDataOrTransaction
155
- });
156
- response = await ((_b = this.api) === null || _b === void 0 ? void 0 : _b.records.createMany(data, transaction));
157
- }
158
- if ((response === null || response === void 0 ? void 0 : response.success) && (response === null || response === void 0 ? void 0 : response.data)) {
159
- const result = new DBRecordsArrayInstance(response.data, response.total);
160
- result.init(this);
161
- return result;
162
- }
163
- return new DBRecordsArrayInstance([]);
164
- },
165
- delete: async (searchParams, transaction) => {
166
- var _a;
167
- if (isEmptyObject(searchParams.where)) {
168
- throw new EmptyTargetError(`You must specify criteria to delete records. Empty criteria are not allowed. If this was intentional, use the Dashboard instead.`);
169
- }
170
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.records.delete(searchParams, transaction);
171
- },
172
- deleteById: async (idOrIds, transaction) => {
173
- var _a;
174
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.records.deleteById(idOrIds, transaction);
175
- },
176
- detach: async (sourceId, target, options, transaction) => {
177
- var _a, _b;
178
- // target is MaybeArray<DBRecordInstance>
179
- if (target instanceof DBRecordInstance) {
180
- const id = (_a = target.data) === null || _a === void 0 ? void 0 : _a.__id;
181
- if (id) {
182
- return await this.api.records.detach(sourceId, id, options, transaction);
183
- }
184
- else {
185
- throw new EmptyTargetError('Detach error: Target id is empty');
186
- }
187
- }
188
- else if (isArray(target) && target.every((r) => r instanceof DBRecordInstance)) {
189
- const ids = target.map((r) => { var _a; return (_a = r.data) === null || _a === void 0 ? void 0 : _a.__id; }).filter(Boolean);
190
- if (ids.length) {
191
- return await this.api.records.detach(sourceId, ids, options, transaction);
192
- }
193
- else {
194
- throw new EmptyTargetError('Detach error: Target ids are empty');
195
- }
196
- }
197
- // target is DBRecordsArrayInstance
198
- else if (target instanceof DBRecordsArrayInstance) {
199
- const ids = (_b = target.data) === null || _b === void 0 ? void 0 : _b.map((r) => r.__id).filter(Boolean);
200
- if (ids === null || ids === void 0 ? void 0 : ids.length) {
201
- return await this.api.records.detach(sourceId, ids, options, transaction);
202
- }
203
- else {
204
- throw new EmptyTargetError('Detach error: Target ids are empty');
205
- }
206
- }
207
- // target is MaybeArray<DBRecord>
208
- else if (isObject(target) && '__id' in target) {
209
- return await this.api.records.detach(sourceId, target.__id, options, transaction);
210
- }
211
- else if (isArray(target) && target.every((r) => isObject(r) && '__id' in r)) {
212
- const ids = target === null || target === void 0 ? void 0 : target.map((r) => r.__id).filter(Boolean);
213
- if (ids === null || ids === void 0 ? void 0 : ids.length) {
214
- return await this.api.records.detach(sourceId, ids, options, transaction);
215
- }
216
- else {
217
- throw new EmptyTargetError('Detach error: Target ids are empty');
218
- }
219
- }
220
- // target is MaybeArray<string>
221
- else {
222
- return await this.api.records.detach(sourceId, target, options, transaction);
223
- }
224
- },
225
- export: async (searchParams, transaction) => {
226
- var _a;
227
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.records.export(searchParams, transaction);
228
- },
229
- find: async (labelOrSearchParams, searchParamsOrTransaction, transaction) => {
230
- var _a;
231
- const isTransactionParam = isTransaction(searchParamsOrTransaction);
232
- const { id, searchParams } = createSearchParams(labelOrSearchParams, searchParamsOrTransaction);
233
- const tx = isTransactionParam ? searchParamsOrTransaction : transaction;
234
- const response = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.find({ id, searchParams }, tx));
235
- const result = new DBRecordsArrayInstance(response.data, response.total, searchParamsOrTransaction);
236
- result.init(this);
237
- return result;
238
- },
239
- findById: async (idOrIds, transaction) => {
240
- var _a, _b;
241
- if (isArray(idOrIds)) {
242
- const response = (await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.findById(idOrIds, transaction)));
243
- const result = new DBRecordsArrayInstance(response.data, response.total);
244
- result.init(this);
245
- return result;
246
- }
247
- else {
248
- const response = (await ((_b = this.api) === null || _b === void 0 ? void 0 : _b.records.findById(idOrIds, transaction)));
249
- const result = new DBRecordInstance(response.data);
250
- result.init(this);
251
- return result;
252
- }
253
- },
254
- findOne: async (labelOrSearchParams, searchParamsOrTransaction, transaction) => {
255
- var _a;
256
- const isTransactionParam = isTransaction(searchParamsOrTransaction);
257
- const { searchParams } = createSearchParams(labelOrSearchParams, searchParamsOrTransaction);
258
- const tx = isTransactionParam ? searchParamsOrTransaction : transaction;
259
- const response = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.findOne(searchParams, tx));
260
- const result = new DBRecordInstance(response.data, searchParamsOrTransaction);
261
- result.init(this);
262
- return result;
263
- },
264
- findUniq: async (labelOrSearchParams, searchParamsOrTransaction, transaction) => {
265
- var _a;
266
- const isTransactionParam = isTransaction(searchParamsOrTransaction);
267
- const { searchParams } = createSearchParams(labelOrSearchParams, searchParamsOrTransaction);
268
- const tx = isTransactionParam ? searchParamsOrTransaction : transaction;
269
- const response = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.findUniq(searchParams, tx));
270
- const result = new DBRecordInstance(response.data, searchParamsOrTransaction);
271
- result.init(this);
272
- return result;
273
- },
274
- properties: async (id, transaction) => {
275
- var _a;
276
- return (_a = this.api) === null || _a === void 0 ? void 0 : _a.records.properties(id, transaction);
277
- },
278
- relations: async (id, transaction) => {
279
- return await this.api.records.relations(id, transaction);
280
- },
281
- set: async (id, data, transaction) => {
282
- var _a, _b;
283
- let response;
284
- if (data instanceof DBRecordDraft) {
285
- response = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.set(id, data, transaction));
286
- }
287
- else if (isObjectFlat(data)) {
288
- const properties = prepareProperties(data);
289
- response = await ((_b = this.api) === null || _b === void 0 ? void 0 : _b.records.set(id, new DBRecordDraft({ properties }), transaction));
290
- }
291
- else if (isObject(data)) {
292
- throw Error('Provided data is not a flat object. Consider to use `createMany` method.');
293
- }
294
- if ((response === null || response === void 0 ? void 0 : response.success) && (response === null || response === void 0 ? void 0 : response.data)) {
295
- const result = new DBRecordInstance(response.data);
296
- result.init(this);
297
- return result;
298
- }
299
- return new DBRecordInstance();
300
- },
301
- update: async (id, data, transaction) => {
302
- var _a, _b;
303
- let response;
304
- if (data instanceof DBRecordDraft) {
305
- response = await ((_a = this.api) === null || _a === void 0 ? void 0 : _a.records.update(id, data, transaction));
306
- }
307
- else if (isObjectFlat(data)) {
308
- const properties = prepareProperties(data);
309
- const recordDraft = new DBRecordDraft({ properties });
310
- response = await ((_b = this.api) === null || _b === void 0 ? void 0 : _b.records.update(id, recordDraft, transaction));
311
- }
312
- else if (isObject(data)) {
313
- throw Error('Provided data is not a flat object. Consider to use `createMany` method.');
314
- }
315
- if ((response === null || response === void 0 ? void 0 : response.success) && (response === null || response === void 0 ? void 0 : response.data)) {
316
- const result = new DBRecordInstance(response.data);
317
- result.init(this);
318
- return result;
319
- }
320
- return new DBRecordInstance();
321
- }
322
- };
323
- }
324
- }
@@ -1,4 +0,0 @@
1
- export const DEFAULT_HOST = 'api.rushdb.com';
2
- export const DEFAULT_PORT = 443;
3
- export const DEFAULT_PROTOCOL = 'https';
4
- export const DEFAULT_BASE_PATH = '/api/v1';
@@ -1,309 +0,0 @@
1
- import { isArray } from '../common/utils.js';
2
- import { NonUniqueResultError } from '../sdk/errors.js';
3
- import { DBRecordsBatchDraft, DBRecordDraft } from '../sdk/record.js';
4
- import { buildTransactionHeader, pickRecordId, pickTransactionId } from './utils.js';
5
- // POST /api/v1/records/:id @TODO
6
- export const createApi = (fetcher, logger) => ({
7
- labels: {
8
- async find(searchParams, transaction) {
9
- const txId = pickTransactionId(transaction);
10
- const path = '/labels';
11
- const payload = {
12
- headers: Object.assign({}, buildTransactionHeader(txId)),
13
- method: 'POST',
14
- requestData: searchParams
15
- };
16
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
17
- return fetcher(path, payload);
18
- }
19
- },
20
- properties: {
21
- delete: (id, transaction) => {
22
- const txId = pickTransactionId(transaction);
23
- const path = `/properties/${id}`;
24
- const payload = {
25
- headers: Object.assign({}, buildTransactionHeader(txId)),
26
- method: 'DELETE'
27
- };
28
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
29
- return fetcher(path, payload);
30
- },
31
- find: (searchParams, transaction) => {
32
- const txId = pickTransactionId(transaction);
33
- const path = `/properties`;
34
- const payload = {
35
- headers: Object.assign({}, buildTransactionHeader(txId)),
36
- method: 'POST',
37
- requestData: searchParams
38
- };
39
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
40
- return fetcher(path, payload);
41
- },
42
- findById: (id, transaction) => {
43
- const txId = pickTransactionId(transaction);
44
- const path = `/properties/${id}`;
45
- const payload = {
46
- headers: Object.assign({}, buildTransactionHeader(txId)),
47
- method: 'GET'
48
- };
49
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
50
- return fetcher(path, payload);
51
- },
52
- // update: () => {
53
- // // @TODO
54
- // },
55
- // updateValues: (id: string, transaction?: Transaction | string) => {
56
- // // @TODO
57
- // },
58
- values: (id, transaction) => {
59
- const txId = pickTransactionId(transaction);
60
- const path = `/properties/${id}/values`;
61
- const payload = {
62
- headers: Object.assign({}, buildTransactionHeader(txId)),
63
- method: 'GET'
64
- };
65
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
66
- return fetcher(path, payload);
67
- }
68
- },
69
- records: {
70
- async attach(source, idOrIds, options, transaction) {
71
- const txId = pickTransactionId(transaction);
72
- const recordId = pickRecordId(source);
73
- const path = `/records/${recordId}/relations`;
74
- const payload = {
75
- headers: Object.assign({}, buildTransactionHeader(txId)),
76
- method: 'POST',
77
- requestData: Object.assign(Object.assign({ targetIds: idOrIds }, ((options === null || options === void 0 ? void 0 : options.type) && { type: options.type })), ((options === null || options === void 0 ? void 0 : options.direction) && { direction: options.direction }))
78
- };
79
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
80
- return fetcher(path, payload);
81
- },
82
- async create(data, transaction) {
83
- const txId = pickTransactionId(transaction);
84
- const path = `/records`;
85
- const payload = {
86
- headers: Object.assign({}, buildTransactionHeader(txId)),
87
- method: 'POST',
88
- requestData: data instanceof DBRecordDraft ? data.toJson() : data
89
- };
90
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
91
- return fetcher(path, payload);
92
- },
93
- async createMany(data, transaction) {
94
- const txId = pickTransactionId(transaction);
95
- const path = `/records/import/json`;
96
- const payload = {
97
- headers: Object.assign({}, buildTransactionHeader(txId)),
98
- method: 'POST',
99
- requestData: data instanceof DBRecordsBatchDraft ? data.toJson() : data
100
- };
101
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
102
- return fetcher(path, payload);
103
- },
104
- delete(searchParams, transaction) {
105
- const txId = pickTransactionId(transaction);
106
- const path = `/records/delete`;
107
- const payload = {
108
- headers: Object.assign({}, buildTransactionHeader(txId)),
109
- method: 'PUT',
110
- requestData: searchParams
111
- };
112
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
113
- return fetcher(path, payload);
114
- },
115
- deleteById(idOrIds, transaction) {
116
- const txId = pickTransactionId(transaction);
117
- const multipleTargets = isArray(idOrIds);
118
- const path = multipleTargets ? `/records/delete` : `/records/${idOrIds}`;
119
- const payload = {
120
- headers: Object.assign({}, buildTransactionHeader(txId)),
121
- method: multipleTargets ? 'PUT' : 'DELETE',
122
- requestData: multipleTargets ? { limit: 1000, where: { $id: { $in: idOrIds } } } : undefined
123
- };
124
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
125
- return fetcher(path, payload);
126
- },
127
- async detach(source, idOrIds, options, transaction) {
128
- const txId = pickTransactionId(transaction);
129
- const recordId = pickRecordId(source);
130
- const path = `/records/${recordId}/relations`;
131
- const payload = {
132
- headers: Object.assign({}, buildTransactionHeader(txId)),
133
- method: 'PUT',
134
- requestData: Object.assign(Object.assign({ targetIds: idOrIds }, ((options === null || options === void 0 ? void 0 : options.typeOrTypes) && { typeOrTypes: options.typeOrTypes })), ((options === null || options === void 0 ? void 0 : options.direction) && { direction: options.direction }))
135
- };
136
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
137
- return fetcher(path, payload);
138
- },
139
- export(searchParams, transaction) {
140
- const txId = pickTransactionId(transaction);
141
- const path = `/records/export/csv`;
142
- const payload = {
143
- headers: Object.assign({}, buildTransactionHeader(txId)),
144
- method: 'POST',
145
- requestData: searchParams
146
- };
147
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
148
- return fetcher(path, payload);
149
- },
150
- find(params, transaction) {
151
- const txId = pickTransactionId(transaction);
152
- const path = (params === null || params === void 0 ? void 0 : params.id) ? `/records/${params.id}/search` : `/records/search`;
153
- const payload = {
154
- headers: Object.assign({}, buildTransactionHeader(txId)),
155
- method: 'POST',
156
- requestData: params === null || params === void 0 ? void 0 : params.searchParams
157
- };
158
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
159
- return fetcher(path, payload);
160
- },
161
- findById(idOrIds, transaction) {
162
- const txId = pickTransactionId(transaction);
163
- const path = isArray(idOrIds) ? `/records` : `/records/${idOrIds}`;
164
- const payload = {
165
- headers: Object.assign({}, buildTransactionHeader(txId)),
166
- method: isArray(idOrIds) ? 'POST' : 'GET',
167
- requestData: isArray(idOrIds) ? { ids: idOrIds } : undefined
168
- };
169
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
170
- return fetcher(path, payload);
171
- },
172
- async findOne(searchParams, transaction) {
173
- const txId = pickTransactionId(transaction);
174
- const path = `/records/search`;
175
- const payload = {
176
- headers: Object.assign({}, buildTransactionHeader(txId)),
177
- method: 'POST',
178
- requestData: Object.assign(Object.assign({}, searchParams), { limit: 1, skip: 0 })
179
- };
180
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
181
- const response = await fetcher(path, payload);
182
- const [record] = response.data;
183
- return Object.assign(Object.assign({}, response), { data: record });
184
- },
185
- async findUniq(searchParams, transaction) {
186
- const txId = pickTransactionId(transaction);
187
- const path = `/records/search`;
188
- const payload = {
189
- headers: Object.assign({}, buildTransactionHeader(txId)),
190
- method: 'POST',
191
- requestData: Object.assign(Object.assign({}, searchParams), { limit: 1, skip: 0 })
192
- };
193
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
194
- const response = await fetcher(path, payload);
195
- if (typeof response.total !== 'undefined' && response.total > 1) {
196
- throw new NonUniqueResultError(response.total, searchParams);
197
- }
198
- const [record] = response.data;
199
- return Object.assign(Object.assign({}, response), { data: record });
200
- },
201
- properties(target, transaction) {
202
- const txId = pickTransactionId(transaction);
203
- const recordId = pickRecordId(target);
204
- const path = `/records/${recordId}/properties`;
205
- const payload = {
206
- headers: Object.assign({}, buildTransactionHeader(txId)),
207
- method: 'GET'
208
- };
209
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
210
- return fetcher(path, payload);
211
- },
212
- async relations(target, transaction) {
213
- const txId = pickTransactionId(transaction);
214
- const recordId = pickRecordId(target);
215
- const path = `/records/${recordId}/relations`;
216
- const payload = {
217
- headers: Object.assign({}, buildTransactionHeader(txId)),
218
- method: 'GET'
219
- };
220
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
221
- return fetcher(path, payload);
222
- },
223
- // upsert() {
224
- // // @TODO
225
- // }
226
- set(target, data, transaction) {
227
- const txId = pickTransactionId(transaction);
228
- const recordId = pickRecordId(target);
229
- const path = `/records/${recordId}`;
230
- const payload = {
231
- headers: Object.assign({}, buildTransactionHeader(txId)),
232
- method: 'PUT',
233
- requestData: data instanceof DBRecordDraft ? data.toJson() : data
234
- };
235
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
236
- return fetcher(path, payload);
237
- },
238
- update(target, data, transaction) {
239
- const txId = pickTransactionId(transaction);
240
- const recordId = pickRecordId(target);
241
- const path = `/records/${recordId}`;
242
- const payload = {
243
- headers: Object.assign({}, buildTransactionHeader(txId)),
244
- method: 'PATCH',
245
- requestData: data instanceof DBRecordDraft ? data.toJson() : data
246
- };
247
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
248
- return fetcher(path, payload);
249
- }
250
- },
251
- relations: {
252
- async find(searchParams, pagination, transaction) {
253
- const txId = pickTransactionId(transaction);
254
- const queryParams = new URLSearchParams();
255
- if ((pagination === null || pagination === void 0 ? void 0 : pagination.limit) !== undefined) {
256
- queryParams.append('limit', pagination.limit.toString());
257
- }
258
- if ((pagination === null || pagination === void 0 ? void 0 : pagination.skip) !== undefined) {
259
- queryParams.append('skip', pagination.skip.toString());
260
- }
261
- const queryString = queryParams.toString() ? '?' + queryParams.toString() : '';
262
- const path = `/records/relations/search${queryString}`;
263
- const payload = {
264
- headers: Object.assign({}, buildTransactionHeader(txId)),
265
- method: 'POST',
266
- requestData: searchParams
267
- };
268
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
269
- return fetcher(path, payload);
270
- }
271
- },
272
- tx: {
273
- begin(config = {}) {
274
- const path = `/tx`;
275
- const payload = {
276
- method: 'POST',
277
- requestData: config
278
- };
279
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
280
- return fetcher(path, payload);
281
- },
282
- commit(id) {
283
- const path = `/tx/${id}/commit`;
284
- const payload = {
285
- method: 'POST',
286
- requestData: {}
287
- };
288
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
289
- return fetcher(path, payload);
290
- },
291
- get(id) {
292
- const path = `/tx/${id}`;
293
- const payload = {
294
- method: 'GET'
295
- };
296
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
297
- return fetcher(path, payload);
298
- },
299
- rollback(id) {
300
- const path = `/tx/${id}/rollback`;
301
- const payload = {
302
- method: 'POST',
303
- requestData: {}
304
- };
305
- logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
306
- return fetcher(path, payload);
307
- }
308
- }
309
- });
package/esm/api/index.js DELETED
@@ -1,2 +0,0 @@
1
- export { DBRecordsBatchDraft, DBRecordDraft } from '../sdk/record.js';
2
- export { RestAPI } from './api.js';
@@ -1,18 +0,0 @@
1
- export class RestApiProxy {
2
- constructor() {
3
- this.apiProxy = {};
4
- return new Proxy(this, {
5
- get: (target, prop, receiver) => {
6
- if (prop in target) {
7
- return Reflect.get(target, prop, receiver);
8
- }
9
- if (this.apiProxy && prop in this.apiProxy) {
10
- return Reflect.get(this.apiProxy, prop, receiver);
11
- }
12
- }
13
- });
14
- }
15
- init(api, methodsWhiteList) {
16
- this.apiProxy = api;
17
- }
18
- }
package/esm/api/types.js DELETED
@@ -1 +0,0 @@
1
- export {};