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