@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.
- package/{types → dist}/api/create-api.d.ts +6 -6
- package/{types → dist}/api/types.d.ts +17 -17
- package/dist/index.cjs +1 -0
- package/dist/index.mjs +1 -0
- package/dist/index.node.d.ts +137 -0
- package/dist/index.worker.d.ts +137 -0
- package/{types → dist}/sdk/model.d.ts +19 -15
- package/{types → dist}/sdk/record.d.ts +15 -12
- package/{types → dist}/sdk/sdk.d.ts +27 -27
- package/{types → dist}/sdk/transaction.d.ts +2 -2
- package/{types → dist}/types/query.d.ts +15 -8
- package/package.json +36 -39
- package/CHANGELOG.md +0 -180
- package/cjs/api/api.js +0 -328
- package/cjs/api/constants.js +0 -7
- package/cjs/api/create-api.js +0 -323
- package/cjs/api/index.js +0 -8
- package/cjs/api/rest-api-proxy.js +0 -22
- package/cjs/api/types.js +0 -2
- package/cjs/api/utils.js +0 -155
- package/cjs/common/constants.js +0 -10
- package/cjs/common/utils.js +0 -46
- package/cjs/index.cjs.node.js +0 -24
- package/cjs/index.cjs.worker.js +0 -24
- package/cjs/network/FetchHttpClient.js +0 -138
- package/cjs/network/HttpClient.js +0 -59
- package/cjs/network/NodeHttpClient.js +0 -103
- package/cjs/network/index.js +0 -28
- package/cjs/network/types.js +0 -2
- package/cjs/package.json +0 -4
- package/cjs/sdk/constants.js +0 -13
- package/cjs/sdk/errors.js +0 -27
- package/cjs/sdk/index.js +0 -23
- package/cjs/sdk/model.js +0 -147
- package/cjs/sdk/record.js +0 -122
- package/cjs/sdk/sdk.js +0 -46
- package/cjs/sdk/transaction.js +0 -17
- package/cjs/sdk/types.js +0 -2
- package/cjs/sdk/utils.js +0 -103
- package/cjs/types/expressions.js +0 -2
- package/cjs/types/index.js +0 -21
- package/cjs/types/query.js +0 -2
- package/cjs/types/schema.js +0 -2
- package/cjs/types/utils.js +0 -2
- package/cjs/types/value.js +0 -2
- package/esm/api/api.js +0 -324
- package/esm/api/constants.js +0 -4
- package/esm/api/create-api.js +0 -319
- package/esm/api/index.js +0 -2
- package/esm/api/rest-api-proxy.js +0 -18
- package/esm/api/types.js +0 -1
- package/esm/api/utils.js +0 -139
- package/esm/common/constants.js +0 -7
- package/esm/common/utils.js +0 -37
- package/esm/index.esm.node.js +0 -6
- package/esm/index.esm.worker.js +0 -6
- package/esm/network/FetchHttpClient.js +0 -133
- package/esm/network/HttpClient.js +0 -53
- package/esm/network/NodeHttpClient.js +0 -98
- package/esm/network/index.js +0 -24
- package/esm/network/types.js +0 -1
- package/esm/package.json +0 -4
- package/esm/sdk/constants.js +0 -10
- package/esm/sdk/errors.js +0 -21
- package/esm/sdk/index.js +0 -7
- package/esm/sdk/model.js +0 -143
- package/esm/sdk/record.js +0 -115
- package/esm/sdk/sdk.js +0 -42
- package/esm/sdk/transaction.js +0 -13
- package/esm/sdk/types.js +0 -1
- package/esm/sdk/utils.js +0 -93
- package/esm/types/expressions.js +0 -1
- package/esm/types/index.js +0 -5
- package/esm/types/query.js +0 -1
- package/esm/types/schema.js +0 -1
- package/esm/types/utils.js +0 -1
- package/esm/types/value.js +0 -1
- package/types/index.d.ts +0 -60
- /package/{types → dist}/api/api.d.ts +0 -0
- /package/{types → dist}/api/constants.d.ts +0 -0
- /package/{types → dist}/api/index.d.ts +0 -0
- /package/{types → dist}/api/rest-api-proxy.d.ts +0 -0
- /package/{types → dist}/api/utils.d.ts +0 -0
- /package/{types → dist}/common/constants.d.ts +0 -0
- /package/{types → dist}/common/utils.d.ts +0 -0
- /package/{types → dist}/network/FetchHttpClient.d.ts +0 -0
- /package/{types → dist}/network/HttpClient.d.ts +0 -0
- /package/{types → dist}/network/NodeHttpClient.d.ts +0 -0
- /package/{types → dist}/network/index.d.ts +0 -0
- /package/{types → dist}/network/types.d.ts +0 -0
- /package/{types → dist}/sdk/constants.d.ts +0 -0
- /package/{types → dist}/sdk/errors.d.ts +0 -0
- /package/{types → dist}/sdk/index.d.ts +0 -0
- /package/{types → dist}/sdk/types.d.ts +0 -0
- /package/{types → dist}/sdk/utils.d.ts +0 -0
- /package/{types → dist}/types/expressions.d.ts +0 -0
- /package/{types → dist}/types/index.d.ts +0 -0
- /package/{types → dist}/types/schema.d.ts +0 -0
- /package/{types → dist}/types/utils.d.ts +0 -0
- /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);
|
|
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);
|
|
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
|
-
}
|
package/esm/api/constants.js
DELETED
package/esm/api/create-api.js
DELETED
|
@@ -1,319 +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, options, transaction) => {
|
|
59
|
-
const txId = pickTransactionId(transaction);
|
|
60
|
-
const path = `/properties/${id}/values`;
|
|
61
|
-
const { sort, skip, limit } = options !== null && options !== void 0 ? options : {};
|
|
62
|
-
const queryParams = new URLSearchParams();
|
|
63
|
-
if (sort)
|
|
64
|
-
queryParams.append('sort', sort);
|
|
65
|
-
if (skip !== undefined)
|
|
66
|
-
queryParams.append('skip', skip.toString());
|
|
67
|
-
if (limit !== undefined)
|
|
68
|
-
queryParams.append('limit', limit.toString());
|
|
69
|
-
const queryString = queryParams.toString();
|
|
70
|
-
const fullPath = queryString ? `${path}?${queryString}` : path;
|
|
71
|
-
const payload = {
|
|
72
|
-
headers: Object.assign({}, buildTransactionHeader(txId)),
|
|
73
|
-
method: 'GET'
|
|
74
|
-
};
|
|
75
|
-
logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path: fullPath }, payload));
|
|
76
|
-
return fetcher(fullPath, payload);
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
records: {
|
|
80
|
-
async attach(source, idOrIds, options, transaction) {
|
|
81
|
-
const txId = pickTransactionId(transaction);
|
|
82
|
-
const recordId = pickRecordId(source);
|
|
83
|
-
const path = `/records/${recordId}/relations`;
|
|
84
|
-
const payload = {
|
|
85
|
-
headers: Object.assign({}, buildTransactionHeader(txId)),
|
|
86
|
-
method: 'POST',
|
|
87
|
-
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 }))
|
|
88
|
-
};
|
|
89
|
-
logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
|
|
90
|
-
return fetcher(path, payload);
|
|
91
|
-
},
|
|
92
|
-
async create(data, transaction) {
|
|
93
|
-
const txId = pickTransactionId(transaction);
|
|
94
|
-
const path = `/records`;
|
|
95
|
-
const payload = {
|
|
96
|
-
headers: Object.assign({}, buildTransactionHeader(txId)),
|
|
97
|
-
method: 'POST',
|
|
98
|
-
requestData: data instanceof DBRecordDraft ? data.toJson() : data
|
|
99
|
-
};
|
|
100
|
-
logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
|
|
101
|
-
return fetcher(path, payload);
|
|
102
|
-
},
|
|
103
|
-
async createMany(data, transaction) {
|
|
104
|
-
const txId = pickTransactionId(transaction);
|
|
105
|
-
const path = `/records/import/json`;
|
|
106
|
-
const payload = {
|
|
107
|
-
headers: Object.assign({}, buildTransactionHeader(txId)),
|
|
108
|
-
method: 'POST',
|
|
109
|
-
requestData: data instanceof DBRecordsBatchDraft ? data.toJson() : data
|
|
110
|
-
};
|
|
111
|
-
logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
|
|
112
|
-
return fetcher(path, payload);
|
|
113
|
-
},
|
|
114
|
-
delete(searchParams, transaction) {
|
|
115
|
-
const txId = pickTransactionId(transaction);
|
|
116
|
-
const path = `/records/delete`;
|
|
117
|
-
const payload = {
|
|
118
|
-
headers: Object.assign({}, buildTransactionHeader(txId)),
|
|
119
|
-
method: 'PUT',
|
|
120
|
-
requestData: searchParams
|
|
121
|
-
};
|
|
122
|
-
logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
|
|
123
|
-
return fetcher(path, payload);
|
|
124
|
-
},
|
|
125
|
-
deleteById(idOrIds, transaction) {
|
|
126
|
-
const txId = pickTransactionId(transaction);
|
|
127
|
-
const multipleTargets = isArray(idOrIds);
|
|
128
|
-
const path = multipleTargets ? `/records/delete` : `/records/${idOrIds}`;
|
|
129
|
-
const payload = {
|
|
130
|
-
headers: Object.assign({}, buildTransactionHeader(txId)),
|
|
131
|
-
method: multipleTargets ? 'PUT' : 'DELETE',
|
|
132
|
-
requestData: multipleTargets ? { limit: 1000, where: { $id: { $in: idOrIds } } } : undefined
|
|
133
|
-
};
|
|
134
|
-
logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
|
|
135
|
-
return fetcher(path, payload);
|
|
136
|
-
},
|
|
137
|
-
async detach(source, idOrIds, options, transaction) {
|
|
138
|
-
const txId = pickTransactionId(transaction);
|
|
139
|
-
const recordId = pickRecordId(source);
|
|
140
|
-
const path = `/records/${recordId}/relations`;
|
|
141
|
-
const payload = {
|
|
142
|
-
headers: Object.assign({}, buildTransactionHeader(txId)),
|
|
143
|
-
method: 'PUT',
|
|
144
|
-
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 }))
|
|
145
|
-
};
|
|
146
|
-
logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
|
|
147
|
-
return fetcher(path, payload);
|
|
148
|
-
},
|
|
149
|
-
export(searchParams, transaction) {
|
|
150
|
-
const txId = pickTransactionId(transaction);
|
|
151
|
-
const path = `/records/export/csv`;
|
|
152
|
-
const payload = {
|
|
153
|
-
headers: Object.assign({}, buildTransactionHeader(txId)),
|
|
154
|
-
method: 'POST',
|
|
155
|
-
requestData: searchParams
|
|
156
|
-
};
|
|
157
|
-
logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
|
|
158
|
-
return fetcher(path, payload);
|
|
159
|
-
},
|
|
160
|
-
find(params, transaction) {
|
|
161
|
-
const txId = pickTransactionId(transaction);
|
|
162
|
-
const path = (params === null || params === void 0 ? void 0 : params.id) ? `/records/${params.id}/search` : `/records/search`;
|
|
163
|
-
const payload = {
|
|
164
|
-
headers: Object.assign({}, buildTransactionHeader(txId)),
|
|
165
|
-
method: 'POST',
|
|
166
|
-
requestData: params === null || params === void 0 ? void 0 : params.searchParams
|
|
167
|
-
};
|
|
168
|
-
logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
|
|
169
|
-
return fetcher(path, payload);
|
|
170
|
-
},
|
|
171
|
-
findById(idOrIds, transaction) {
|
|
172
|
-
const txId = pickTransactionId(transaction);
|
|
173
|
-
const path = isArray(idOrIds) ? `/records` : `/records/${idOrIds}`;
|
|
174
|
-
const payload = {
|
|
175
|
-
headers: Object.assign({}, buildTransactionHeader(txId)),
|
|
176
|
-
method: isArray(idOrIds) ? 'POST' : 'GET',
|
|
177
|
-
requestData: isArray(idOrIds) ? { ids: idOrIds } : undefined
|
|
178
|
-
};
|
|
179
|
-
logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
|
|
180
|
-
return fetcher(path, payload);
|
|
181
|
-
},
|
|
182
|
-
async findOne(searchParams, transaction) {
|
|
183
|
-
const txId = pickTransactionId(transaction);
|
|
184
|
-
const path = `/records/search`;
|
|
185
|
-
const payload = {
|
|
186
|
-
headers: Object.assign({}, buildTransactionHeader(txId)),
|
|
187
|
-
method: 'POST',
|
|
188
|
-
requestData: Object.assign(Object.assign({}, searchParams), { limit: 1, skip: 0 })
|
|
189
|
-
};
|
|
190
|
-
logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
|
|
191
|
-
const response = await fetcher(path, payload);
|
|
192
|
-
const [record] = response.data;
|
|
193
|
-
return Object.assign(Object.assign({}, response), { data: record });
|
|
194
|
-
},
|
|
195
|
-
async findUniq(searchParams, transaction) {
|
|
196
|
-
const txId = pickTransactionId(transaction);
|
|
197
|
-
const path = `/records/search`;
|
|
198
|
-
const payload = {
|
|
199
|
-
headers: Object.assign({}, buildTransactionHeader(txId)),
|
|
200
|
-
method: 'POST',
|
|
201
|
-
requestData: Object.assign(Object.assign({}, searchParams), { limit: 1, skip: 0 })
|
|
202
|
-
};
|
|
203
|
-
logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
|
|
204
|
-
const response = await fetcher(path, payload);
|
|
205
|
-
if (typeof response.total !== 'undefined' && response.total > 1) {
|
|
206
|
-
throw new NonUniqueResultError(response.total, searchParams);
|
|
207
|
-
}
|
|
208
|
-
const [record] = response.data;
|
|
209
|
-
return Object.assign(Object.assign({}, response), { data: record });
|
|
210
|
-
},
|
|
211
|
-
properties(target, transaction) {
|
|
212
|
-
const txId = pickTransactionId(transaction);
|
|
213
|
-
const recordId = pickRecordId(target);
|
|
214
|
-
const path = `/records/${recordId}/properties`;
|
|
215
|
-
const payload = {
|
|
216
|
-
headers: Object.assign({}, buildTransactionHeader(txId)),
|
|
217
|
-
method: 'GET'
|
|
218
|
-
};
|
|
219
|
-
logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
|
|
220
|
-
return fetcher(path, payload);
|
|
221
|
-
},
|
|
222
|
-
async relations(target, transaction) {
|
|
223
|
-
const txId = pickTransactionId(transaction);
|
|
224
|
-
const recordId = pickRecordId(target);
|
|
225
|
-
const path = `/records/${recordId}/relations`;
|
|
226
|
-
const payload = {
|
|
227
|
-
headers: Object.assign({}, buildTransactionHeader(txId)),
|
|
228
|
-
method: 'GET'
|
|
229
|
-
};
|
|
230
|
-
logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
|
|
231
|
-
return fetcher(path, payload);
|
|
232
|
-
},
|
|
233
|
-
// upsert() {
|
|
234
|
-
// // @TODO
|
|
235
|
-
// }
|
|
236
|
-
set(target, data, transaction) {
|
|
237
|
-
const txId = pickTransactionId(transaction);
|
|
238
|
-
const recordId = pickRecordId(target);
|
|
239
|
-
const path = `/records/${recordId}`;
|
|
240
|
-
const payload = {
|
|
241
|
-
headers: Object.assign({}, buildTransactionHeader(txId)),
|
|
242
|
-
method: 'PUT',
|
|
243
|
-
requestData: data instanceof DBRecordDraft ? data.toJson() : data
|
|
244
|
-
};
|
|
245
|
-
logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
|
|
246
|
-
return fetcher(path, payload);
|
|
247
|
-
},
|
|
248
|
-
update(target, data, transaction) {
|
|
249
|
-
const txId = pickTransactionId(transaction);
|
|
250
|
-
const recordId = pickRecordId(target);
|
|
251
|
-
const path = `/records/${recordId}`;
|
|
252
|
-
const payload = {
|
|
253
|
-
headers: Object.assign({}, buildTransactionHeader(txId)),
|
|
254
|
-
method: 'PATCH',
|
|
255
|
-
requestData: data instanceof DBRecordDraft ? data.toJson() : data
|
|
256
|
-
};
|
|
257
|
-
logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
|
|
258
|
-
return fetcher(path, payload);
|
|
259
|
-
}
|
|
260
|
-
},
|
|
261
|
-
relations: {
|
|
262
|
-
async find(searchParams, pagination, transaction) {
|
|
263
|
-
const txId = pickTransactionId(transaction);
|
|
264
|
-
const queryParams = new URLSearchParams();
|
|
265
|
-
if ((pagination === null || pagination === void 0 ? void 0 : pagination.limit) !== undefined) {
|
|
266
|
-
queryParams.append('limit', pagination.limit.toString());
|
|
267
|
-
}
|
|
268
|
-
if ((pagination === null || pagination === void 0 ? void 0 : pagination.skip) !== undefined) {
|
|
269
|
-
queryParams.append('skip', pagination.skip.toString());
|
|
270
|
-
}
|
|
271
|
-
const queryString = queryParams.toString() ? '?' + queryParams.toString() : '';
|
|
272
|
-
const path = `/records/relations/search${queryString}`;
|
|
273
|
-
const payload = {
|
|
274
|
-
headers: Object.assign({}, buildTransactionHeader(txId)),
|
|
275
|
-
method: 'POST',
|
|
276
|
-
requestData: searchParams
|
|
277
|
-
};
|
|
278
|
-
logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
|
|
279
|
-
return fetcher(path, payload);
|
|
280
|
-
}
|
|
281
|
-
},
|
|
282
|
-
tx: {
|
|
283
|
-
begin(config = {}) {
|
|
284
|
-
const path = `/tx`;
|
|
285
|
-
const payload = {
|
|
286
|
-
method: 'POST',
|
|
287
|
-
requestData: config
|
|
288
|
-
};
|
|
289
|
-
logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
|
|
290
|
-
return fetcher(path, payload);
|
|
291
|
-
},
|
|
292
|
-
commit(id) {
|
|
293
|
-
const path = `/tx/${id}/commit`;
|
|
294
|
-
const payload = {
|
|
295
|
-
method: 'POST',
|
|
296
|
-
requestData: {}
|
|
297
|
-
};
|
|
298
|
-
logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
|
|
299
|
-
return fetcher(path, payload);
|
|
300
|
-
},
|
|
301
|
-
get(id) {
|
|
302
|
-
const path = `/tx/${id}`;
|
|
303
|
-
const payload = {
|
|
304
|
-
method: 'GET'
|
|
305
|
-
};
|
|
306
|
-
logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
|
|
307
|
-
return fetcher(path, payload);
|
|
308
|
-
},
|
|
309
|
-
rollback(id) {
|
|
310
|
-
const path = `/tx/${id}/rollback`;
|
|
311
|
-
const payload = {
|
|
312
|
-
method: 'POST',
|
|
313
|
-
requestData: {}
|
|
314
|
-
};
|
|
315
|
-
logger === null || logger === void 0 ? void 0 : logger(Object.assign({ path }, payload));
|
|
316
|
-
return fetcher(path, payload);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
});
|
package/esm/api/index.js
DELETED
|
@@ -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 {};
|