@rushdb/javascript-sdk 0.9.4 → 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.
- 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 +4 -4
- package/{types → dist}/sdk/record.d.ts +3 -3
- package/{types → dist}/sdk/sdk.d.ts +24 -24
- package/{types → dist}/sdk/transaction.d.ts +2 -2
- package/{types → dist}/types/query.d.ts +1 -2
- package/package.json +10 -34
- 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/create-api.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/types.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/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 {};
|
package/esm/api/utils.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { ISO_8601_FULL, PROPERTY_TYPE_BOOLEAN, PROPERTY_TYPE_DATETIME, PROPERTY_TYPE_NULL, PROPERTY_TYPE_NUMBER, PROPERTY_TYPE_STRING } from '../common/constants.js';
|
|
2
|
-
import { isArray, isObject, isString } from '../common/utils.js';
|
|
3
|
-
import { DBRecordInstance } from '../sdk';
|
|
4
|
-
import { Transaction } from '../sdk/transaction.js';
|
|
5
|
-
import { DEFAULT_BASE_PATH, DEFAULT_HOST, DEFAULT_PORT, DEFAULT_PROTOCOL } from './constants.js';
|
|
6
|
-
export const buildTransactionHeader = (txId) => txId ?
|
|
7
|
-
{
|
|
8
|
-
['x-transaction-id']: txId
|
|
9
|
-
}
|
|
10
|
-
: undefined;
|
|
11
|
-
export const isTransaction = (input) => isString(input) || input instanceof Transaction;
|
|
12
|
-
export const pickTransaction = (input) => (isTransaction(input) ? input : undefined);
|
|
13
|
-
export const pickTransactionId = (input) => isTransaction(input) ?
|
|
14
|
-
input instanceof Transaction ?
|
|
15
|
-
input.id
|
|
16
|
-
: input
|
|
17
|
-
: undefined;
|
|
18
|
-
export const pickRecordId = (input) => {
|
|
19
|
-
if (isString(input)) {
|
|
20
|
-
return input;
|
|
21
|
-
}
|
|
22
|
-
else if (input instanceof DBRecordInstance && input.data) {
|
|
23
|
-
return input.data.__id;
|
|
24
|
-
}
|
|
25
|
-
else if ('__id' in input) {
|
|
26
|
-
return input.__id;
|
|
27
|
-
}
|
|
28
|
-
return undefined;
|
|
29
|
-
};
|
|
30
|
-
export const createSearchParams = (labelOrSearchParams, searchParamsOrTransaction) => {
|
|
31
|
-
var _a, _b, _c;
|
|
32
|
-
const isFirstArgString = isString(labelOrSearchParams);
|
|
33
|
-
const isFirstArgUUID = isUUID(labelOrSearchParams);
|
|
34
|
-
const isSecondArgTransaction = isTransaction(searchParamsOrTransaction);
|
|
35
|
-
const isEmptySearchParams = isSecondArgTransaction || !isObject(searchParamsOrTransaction);
|
|
36
|
-
if (isFirstArgString) {
|
|
37
|
-
const baseParams = isFirstArgUUID ?
|
|
38
|
-
{ id: labelOrSearchParams }
|
|
39
|
-
: { searchParams: { labels: [labelOrSearchParams] } };
|
|
40
|
-
return isEmptySearchParams ? Object.assign(Object.assign({}, baseParams), { searchParams: Object.assign({}, baseParams.searchParams) }) : Object.assign(Object.assign({}, baseParams), { searchParams: Object.assign(Object.assign({}, searchParamsOrTransaction), { labels: [
|
|
41
|
-
...((_b = (_a = baseParams.searchParams) === null || _a === void 0 ? void 0 : _a.labels) !== null && _b !== void 0 ? _b : []),
|
|
42
|
-
...((_c = searchParamsOrTransaction.labels) !== null && _c !== void 0 ? _c : [])
|
|
43
|
-
] }) });
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
return { searchParams: labelOrSearchParams !== null && labelOrSearchParams !== void 0 ? labelOrSearchParams : {} };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
export const isUUID = (value) => {
|
|
50
|
-
const regex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/;
|
|
51
|
-
return regex.test(value);
|
|
52
|
-
};
|
|
53
|
-
export const arrayIsConsistent = (arr) => arr.every((item) => typeof item === typeof arr[0]);
|
|
54
|
-
export const getValueParameters = (value) => {
|
|
55
|
-
if (Array.isArray(value)) {
|
|
56
|
-
return {
|
|
57
|
-
isEmptyArray: value.length === 0,
|
|
58
|
-
isEmptyStringsArray: value.every((v) => v === ''),
|
|
59
|
-
isInconsistentArray: !arrayIsConsistent(value)
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
return { isEmptyString: value === '' };
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
export const suggestPropertyType = (value) => {
|
|
67
|
-
if (typeof value === PROPERTY_TYPE_STRING) {
|
|
68
|
-
return ISO_8601_FULL.test(value) ? PROPERTY_TYPE_DATETIME : PROPERTY_TYPE_STRING;
|
|
69
|
-
}
|
|
70
|
-
else if (typeof value === PROPERTY_TYPE_NUMBER) {
|
|
71
|
-
return PROPERTY_TYPE_NUMBER;
|
|
72
|
-
}
|
|
73
|
-
else if (typeof value === PROPERTY_TYPE_BOOLEAN) {
|
|
74
|
-
return PROPERTY_TYPE_BOOLEAN;
|
|
75
|
-
}
|
|
76
|
-
else if (value === null) {
|
|
77
|
-
return PROPERTY_TYPE_NULL;
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
return PROPERTY_TYPE_STRING;
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
const processArrayValue = (value, suggestTypes) => {
|
|
84
|
-
const { isEmptyArray, isInconsistentArray } = getValueParameters(value);
|
|
85
|
-
if (isEmptyArray) {
|
|
86
|
-
return { type: PROPERTY_TYPE_STRING, value: [] };
|
|
87
|
-
}
|
|
88
|
-
if (isInconsistentArray || !suggestTypes) {
|
|
89
|
-
return { type: PROPERTY_TYPE_STRING, value: value.map(String) };
|
|
90
|
-
}
|
|
91
|
-
return { type: suggestPropertyType(value[0]), value };
|
|
92
|
-
};
|
|
93
|
-
const processNonArrayValue = (value, suggestTypes) => {
|
|
94
|
-
if (!suggestTypes) {
|
|
95
|
-
return { type: PROPERTY_TYPE_STRING, value: String(value) };
|
|
96
|
-
}
|
|
97
|
-
const type = suggestPropertyType(value);
|
|
98
|
-
return { type, value: type === PROPERTY_TYPE_NULL ? null : value };
|
|
99
|
-
};
|
|
100
|
-
export const prepareProperties = (data, options = { suggestTypes: true }) => Object.entries(data).map(([name, value]) => {
|
|
101
|
-
const { type, value: processedValue } = isArray(value) ?
|
|
102
|
-
processArrayValue(value, options.suggestTypes)
|
|
103
|
-
: processNonArrayValue(value, options.suggestTypes);
|
|
104
|
-
return { name, type, value: processedValue };
|
|
105
|
-
});
|
|
106
|
-
export const normalizeRecord = ({ label, options = { suggestTypes: true }, payload }) => ({
|
|
107
|
-
label,
|
|
108
|
-
properties: prepareProperties(payload, options)
|
|
109
|
-
});
|
|
110
|
-
export const buildUrl = (props) => {
|
|
111
|
-
let protocol = DEFAULT_PROTOCOL;
|
|
112
|
-
let host = DEFAULT_HOST;
|
|
113
|
-
let port = DEFAULT_PORT;
|
|
114
|
-
let basePath = DEFAULT_BASE_PATH;
|
|
115
|
-
if ('url' in props) {
|
|
116
|
-
const url = new URL(props.url);
|
|
117
|
-
protocol = url.protocol.replace(':', '');
|
|
118
|
-
host = url.hostname;
|
|
119
|
-
port = parseInt(url.port ||
|
|
120
|
-
(protocol === 'http' ? '80'
|
|
121
|
-
: protocol === 'https' ? '443'
|
|
122
|
-
: ''));
|
|
123
|
-
}
|
|
124
|
-
if ('host' in props && 'port' in props && 'protocol' in props) {
|
|
125
|
-
protocol = props.protocol.replace(':', '');
|
|
126
|
-
host = props.host;
|
|
127
|
-
port = props.port;
|
|
128
|
-
}
|
|
129
|
-
// Ensure the basePath starts with a '/'
|
|
130
|
-
if (basePath && !basePath.startsWith('/')) {
|
|
131
|
-
basePath = '/' + basePath;
|
|
132
|
-
}
|
|
133
|
-
// If the port is the default for the protocol (80 for http, 443 for https), it can be omitted
|
|
134
|
-
let portString = '';
|
|
135
|
-
if (!((protocol === 'http' && port === 80) || (protocol === 'https' && port === 443))) {
|
|
136
|
-
portString = ':' + port;
|
|
137
|
-
}
|
|
138
|
-
return `${protocol}://${host}${portString}${basePath}`;
|
|
139
|
-
};
|
package/esm/common/constants.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export const ISO_8601_FULL = /^(?:\d{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1\d|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:\d{2}(?:[02468][048]|[13579][26])-02-29))Schema(0[0-9]|1[0-9]|2[0-3]):(0[0-9]|[1-5][0-9]):(0[0-9]|[1-5][0-9])?(?:\.([0-9]{1,9}))?([zZ]?|([\+-])(((([0][0-9])|([1][0-3])):?(([03][0])|([14][5])))|14:00)?)$/;
|
|
2
|
-
export const DEFAULT_TIMEOUT = 80000;
|
|
3
|
-
export const PROPERTY_TYPE_STRING = 'string';
|
|
4
|
-
export const PROPERTY_TYPE_DATETIME = 'datetime';
|
|
5
|
-
export const PROPERTY_TYPE_BOOLEAN = 'boolean';
|
|
6
|
-
export const PROPERTY_TYPE_NUMBER = 'number';
|
|
7
|
-
export const PROPERTY_TYPE_NULL = 'null';
|
package/esm/common/utils.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export const isArray = (item) => typeof item === 'object' && Array.isArray(item) && item !== null;
|
|
2
|
-
export const isObject = (input) => input !== null && Object.prototype.toString.call(input) === '[object Object]';
|
|
3
|
-
export const isEmptyObject = (input) => isObject(input) && Object.keys(input).length === 0;
|
|
4
|
-
export const isObjectFlat = (input) => {
|
|
5
|
-
return (isObject(input) &&
|
|
6
|
-
Object.keys(input).every((key) => {
|
|
7
|
-
const value = input[key];
|
|
8
|
-
// Check if the value is an array
|
|
9
|
-
if (isArray(value)) {
|
|
10
|
-
// Check if every element in the array is of an allowed type (string, number, boolean, or null)
|
|
11
|
-
return value.every((element) => typeof element === 'string' ||
|
|
12
|
-
typeof element === 'number' ||
|
|
13
|
-
typeof element === 'boolean' ||
|
|
14
|
-
element === null);
|
|
15
|
-
}
|
|
16
|
-
// Check if the value is a non-null object (excluding arrays, which are also typeof 'object')
|
|
17
|
-
return !(value && typeof value === 'object');
|
|
18
|
-
}));
|
|
19
|
-
};
|
|
20
|
-
export const isString = (input) => typeof input === 'string';
|
|
21
|
-
export const toBoolean = (value) => {
|
|
22
|
-
if (typeof value === 'string') {
|
|
23
|
-
if (value.toLowerCase() === 'true') {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
else if (value.toLowerCase() === 'false') {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (isArray(value) && value.length === 0) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
if (isObject(value) && Object.keys(value).length === 0) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
return Boolean(value);
|
|
37
|
-
};
|
package/esm/index.esm.node.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { HttpClient, HttpClientResponse } from './network/HttpClient.js';
|
|
2
|
-
import { NodeHttpClient } from './network/NodeHttpClient.js';
|
|
3
|
-
import { DBRecordsBatchDraft, Model, DBRecordInstance, DBRecordsArrayInstance, Transaction, EmptyTargetError, NonUniqueResultError, UniquenessError, initSDK, idToDate, idToTimestamp } from './sdk/index.js';
|
|
4
|
-
const RushDB = initSDK(new NodeHttpClient());
|
|
5
|
-
export { RushDB, DBRecordsBatchDraft, Model, DBRecordInstance, DBRecordsArrayInstance, Transaction, EmptyTargetError, HttpClient, HttpClientResponse, NonUniqueResultError, UniquenessError, idToDate, idToTimestamp };
|
|
6
|
-
export default RushDB;
|
package/esm/index.esm.worker.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { FetchHttpClient } from './network/FetchHttpClient.js';
|
|
2
|
-
import { HttpClient, HttpClientResponse } from './network/HttpClient.js';
|
|
3
|
-
import { DBRecordsBatchDraft, Model, DBRecordInstance, DBRecordsArrayInstance, Transaction, EmptyTargetError, NonUniqueResultError, UniquenessError, initSDK, idToDate, idToTimestamp } from './sdk/index.js';
|
|
4
|
-
const RushDB = initSDK(new FetchHttpClient());
|
|
5
|
-
export { RushDB, DBRecordsBatchDraft, Model, DBRecordInstance, DBRecordsArrayInstance, Transaction, EmptyTargetError, HttpClient, HttpClientResponse, NonUniqueResultError, UniquenessError, idToDate, idToTimestamp };
|
|
6
|
-
export default RushDB;
|