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