@rushdb/javascript-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +21 -0
  3. package/README.md +119 -0
  4. package/cjs/api/api.js +328 -0
  5. package/cjs/api/constants.js +7 -0
  6. package/cjs/api/create-api.js +258 -0
  7. package/cjs/api/index.js +8 -0
  8. package/cjs/api/rest-api-proxy.js +22 -0
  9. package/cjs/api/types.js +2 -0
  10. package/cjs/api/utils.js +154 -0
  11. package/cjs/common/constants.js +10 -0
  12. package/cjs/common/utils.js +46 -0
  13. package/cjs/index.cjs.node.js +24 -0
  14. package/cjs/index.cjs.worker.js +24 -0
  15. package/cjs/network/FetchHttpClient.js +138 -0
  16. package/cjs/network/HttpClient.js +59 -0
  17. package/cjs/network/NodeHttpClient.js +103 -0
  18. package/cjs/network/index.js +28 -0
  19. package/cjs/network/types.js +2 -0
  20. package/cjs/package.json +4 -0
  21. package/cjs/sdk/constants.js +12 -0
  22. package/cjs/sdk/errors.js +27 -0
  23. package/cjs/sdk/index.js +23 -0
  24. package/cjs/sdk/model.js +147 -0
  25. package/cjs/sdk/record.js +77 -0
  26. package/cjs/sdk/sdk.js +46 -0
  27. package/cjs/sdk/transaction.js +17 -0
  28. package/cjs/sdk/types.js +2 -0
  29. package/cjs/sdk/utils.js +103 -0
  30. package/cjs/types/expressions.js +2 -0
  31. package/cjs/types/index.js +21 -0
  32. package/cjs/types/query.js +2 -0
  33. package/cjs/types/schema.js +2 -0
  34. package/cjs/types/utils.js +2 -0
  35. package/cjs/types/value.js +2 -0
  36. package/esm/api/api.js +324 -0
  37. package/esm/api/constants.js +4 -0
  38. package/esm/api/create-api.js +254 -0
  39. package/esm/api/index.js +2 -0
  40. package/esm/api/rest-api-proxy.js +18 -0
  41. package/esm/api/types.js +1 -0
  42. package/esm/api/utils.js +138 -0
  43. package/esm/common/constants.js +7 -0
  44. package/esm/common/utils.js +37 -0
  45. package/esm/index.esm.node.js +6 -0
  46. package/esm/index.esm.worker.js +6 -0
  47. package/esm/network/FetchHttpClient.js +133 -0
  48. package/esm/network/HttpClient.js +53 -0
  49. package/esm/network/NodeHttpClient.js +98 -0
  50. package/esm/network/index.js +24 -0
  51. package/esm/network/types.js +1 -0
  52. package/esm/package.json +4 -0
  53. package/esm/sdk/constants.js +9 -0
  54. package/esm/sdk/errors.js +21 -0
  55. package/esm/sdk/index.js +7 -0
  56. package/esm/sdk/model.js +143 -0
  57. package/esm/sdk/record.js +70 -0
  58. package/esm/sdk/sdk.js +42 -0
  59. package/esm/sdk/transaction.js +13 -0
  60. package/esm/sdk/types.js +1 -0
  61. package/esm/sdk/utils.js +93 -0
  62. package/esm/types/expressions.js +1 -0
  63. package/esm/types/index.js +5 -0
  64. package/esm/types/query.js +1 -0
  65. package/esm/types/schema.js +1 -0
  66. package/esm/types/utils.js +1 -0
  67. package/esm/types/value.js +1 -0
  68. package/package.json +59 -0
  69. package/types/api/api.d.ts +43 -0
  70. package/types/api/constants.d.ts +4 -0
  71. package/types/api/create-api.d.ts +67 -0
  72. package/types/api/index.d.ts +3 -0
  73. package/types/api/rest-api-proxy.d.ts +6 -0
  74. package/types/api/types.d.ts +65 -0
  75. package/types/api/utils.d.ts +43 -0
  76. package/types/common/constants.d.ts +7 -0
  77. package/types/common/utils.d.ts +7 -0
  78. package/types/index.d.ts +72 -0
  79. package/types/network/FetchHttpClient.d.ts +26 -0
  80. package/types/network/HttpClient.d.ts +48 -0
  81. package/types/network/NodeHttpClient.d.ts +16 -0
  82. package/types/network/index.d.ts +6 -0
  83. package/types/network/types.d.ts +4 -0
  84. package/types/sdk/constants.d.ts +1 -0
  85. package/types/sdk/errors.d.ts +9 -0
  86. package/types/sdk/index.d.ts +7 -0
  87. package/types/sdk/model.d.ts +72 -0
  88. package/types/sdk/record.d.ts +109 -0
  89. package/types/sdk/sdk.d.ts +136 -0
  90. package/types/sdk/transaction.d.ts +11 -0
  91. package/types/sdk/types.d.ts +19 -0
  92. package/types/sdk/utils.d.ts +9 -0
  93. package/types/types/expressions.d.ts +23 -0
  94. package/types/types/index.d.ts +5 -0
  95. package/types/types/query.d.ts +102 -0
  96. package/types/types/schema.d.ts +48 -0
  97. package/types/types/utils.d.ts +9 -0
  98. package/types/types/value.d.ts +35 -0
@@ -0,0 +1,258 @@
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) => ({
10
+ labels: {
11
+ async find(searchParams, transaction) {
12
+ const txId = (0, utils_js_2.pickTransactionId)(transaction);
13
+ return fetcher(`/labels`, {
14
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
15
+ method: 'POST',
16
+ requestData: searchParams
17
+ });
18
+ }
19
+ },
20
+ properties: {
21
+ delete: (id, transaction) => {
22
+ const txId = (0, utils_js_2.pickTransactionId)(transaction);
23
+ return fetcher(`/properties/${id}`, {
24
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
25
+ method: 'DELETE'
26
+ });
27
+ },
28
+ find: (searchParams, transaction) => {
29
+ const txId = (0, utils_js_2.pickTransactionId)(transaction);
30
+ return fetcher(`/properties`, {
31
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
32
+ method: 'POST',
33
+ requestData: searchParams
34
+ });
35
+ },
36
+ findById: (id, transaction) => {
37
+ const txId = (0, utils_js_2.pickTransactionId)(transaction);
38
+ return fetcher(`/properties/${id}`, {
39
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
40
+ method: 'GET'
41
+ });
42
+ },
43
+ // update: () => {
44
+ // // @TODO
45
+ // },
46
+ // updateValues: (id: string, transaction?: Transaction | string) => {
47
+ // // @TODO
48
+ // },
49
+ values: (id, transaction) => {
50
+ const txId = (0, utils_js_2.pickTransactionId)(transaction);
51
+ return fetcher(`/properties/${id}/values`, {
52
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
53
+ method: 'GET'
54
+ });
55
+ }
56
+ },
57
+ records: {
58
+ attach: async (source, idOrIds, options, transaction) => {
59
+ const txId = (0, utils_js_2.pickTransactionId)(transaction);
60
+ const recordId = (0, utils_js_2.pickRecordId)(source);
61
+ return fetcher(`/records/${recordId}/relations`, {
62
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
63
+ method: 'POST',
64
+ requestData: Object.assign(Object.assign({ targetIds: idOrIds }, ((options === null || options === void 0 ? void 0 : options.type) && { type: options === null || options === void 0 ? void 0 : options.type })), ((options === null || options === void 0 ? void 0 : options.direction) && { direction: options === null || options === void 0 ? void 0 : options.direction }))
65
+ });
66
+ },
67
+ async create(data, transaction) {
68
+ const txId = (0, utils_js_2.pickTransactionId)(transaction);
69
+ if (data instanceof record_js_1.DBRecordDraft) {
70
+ return fetcher(`/records`, {
71
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
72
+ method: 'POST',
73
+ requestData: data.toJson()
74
+ });
75
+ }
76
+ return { data: undefined, success: false };
77
+ },
78
+ async createMany(data, transaction) {
79
+ const txId = (0, utils_js_2.pickTransactionId)(transaction);
80
+ if (data instanceof record_js_1.DBRecordsBatchDraft) {
81
+ return fetcher(`/records/import/json`, {
82
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
83
+ method: 'POST',
84
+ requestData: data.toJson()
85
+ });
86
+ }
87
+ return { data: [], success: false };
88
+ },
89
+ delete(searchParams, transaction) {
90
+ const txId = (0, utils_js_2.pickTransactionId)(transaction);
91
+ return fetcher(`/records/delete`, {
92
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
93
+ method: 'PUT',
94
+ requestData: searchParams
95
+ });
96
+ },
97
+ deleteById(idOrIds, transaction) {
98
+ const txId = (0, utils_js_2.pickTransactionId)(transaction);
99
+ if ((0, utils_js_1.isArray)(idOrIds)) {
100
+ return fetcher(`/records/delete`, {
101
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
102
+ method: 'PUT',
103
+ requestData: { limit: 1000, where: { $id: { $in: idOrIds } } }
104
+ });
105
+ }
106
+ else {
107
+ return fetcher(`/records/${idOrIds}`, {
108
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
109
+ method: 'DELETE'
110
+ });
111
+ }
112
+ },
113
+ detach: async (source, idOrIds, options, transaction) => {
114
+ const txId = (0, utils_js_2.pickTransactionId)(transaction);
115
+ const recordId = (0, utils_js_2.pickRecordId)(source);
116
+ return fetcher(`/records/${recordId}/relations`, {
117
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
118
+ method: 'PUT',
119
+ requestData: Object.assign(Object.assign({ targetIds: idOrIds }, ((options === null || options === void 0 ? void 0 : options.typeOrTypes) && { typeOrTypes: options === null || options === void 0 ? void 0 : options.typeOrTypes })), ((options === null || options === void 0 ? void 0 : options.direction) && { direction: options === null || options === void 0 ? void 0 : options.direction }))
120
+ });
121
+ },
122
+ export(searchParams, transaction) {
123
+ const txId = (0, utils_js_2.pickTransactionId)(transaction);
124
+ return fetcher(`/records/export/csv`, {
125
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
126
+ method: 'POST',
127
+ requestData: searchParams
128
+ });
129
+ },
130
+ find(params, transaction) {
131
+ const txId = (0, utils_js_2.pickTransactionId)(transaction);
132
+ const url = (params === null || params === void 0 ? void 0 : params.id) ? `/records/${params === null || params === void 0 ? void 0 : params.id}/search` : `/records/search`;
133
+ return fetcher(url, {
134
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
135
+ method: 'POST',
136
+ requestData: params === null || params === void 0 ? void 0 : params.searchParams
137
+ });
138
+ },
139
+ findById(idOrIds, transaction) {
140
+ const txId = (0, utils_js_2.pickTransactionId)(transaction);
141
+ if ((0, utils_js_1.isArray)(idOrIds)) {
142
+ return fetcher(`/records`, {
143
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
144
+ method: 'POST',
145
+ requestData: { ids: idOrIds }
146
+ });
147
+ }
148
+ return fetcher(`/records/${idOrIds}`, {
149
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
150
+ method: 'GET'
151
+ });
152
+ },
153
+ async findOne(searchParams, transaction) {
154
+ const txId = (0, utils_js_2.pickTransactionId)(transaction);
155
+ const response = await fetcher(`/records/search`, {
156
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
157
+ method: 'POST',
158
+ requestData: Object.assign(Object.assign({}, searchParams), { limit: 1, skip: 0 })
159
+ });
160
+ const [record] = response.data;
161
+ return Object.assign(Object.assign({}, response), { data: record });
162
+ },
163
+ async findUniq(searchParams, transaction) {
164
+ const txId = (0, utils_js_2.pickTransactionId)(transaction);
165
+ const response = await fetcher(`/records/search`, {
166
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
167
+ method: 'POST',
168
+ requestData: Object.assign(Object.assign({}, searchParams), { limit: 1, skip: 0 })
169
+ });
170
+ if (typeof response.total !== 'undefined' && response.total > 1) {
171
+ throw new errors_js_1.NonUniqueResultError(response.total, searchParams);
172
+ }
173
+ const [record] = response.data;
174
+ return Object.assign(Object.assign({}, response), { data: record });
175
+ },
176
+ properties(target, transaction) {
177
+ const txId = (0, utils_js_2.pickTransactionId)(transaction);
178
+ const recordId = (0, utils_js_2.pickRecordId)(target);
179
+ return fetcher(`/records/${recordId}/properties`, {
180
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
181
+ method: 'GET'
182
+ });
183
+ },
184
+ relations: async (target, transaction) => {
185
+ const txId = (0, utils_js_2.pickTransactionId)(transaction);
186
+ const recordId = (0, utils_js_2.pickRecordId)(target);
187
+ return fetcher(`/records/${recordId}/relations`, {
188
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
189
+ method: 'GET'
190
+ });
191
+ },
192
+ // upsert() {
193
+ // // @TODO
194
+ // }
195
+ set(target, data, transaction) {
196
+ const txId = (0, utils_js_2.pickTransactionId)(transaction);
197
+ const recordId = (0, utils_js_2.pickRecordId)(target);
198
+ return fetcher(`/records/${recordId}`, {
199
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
200
+ method: 'PUT',
201
+ requestData: data instanceof record_js_1.DBRecordDraft ? data.toJson() : data
202
+ });
203
+ },
204
+ update(target, data, transaction) {
205
+ const txId = (0, utils_js_2.pickTransactionId)(transaction);
206
+ const recordId = (0, utils_js_2.pickRecordId)(target);
207
+ return fetcher(`/records/${recordId}`, {
208
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
209
+ method: 'PATCH',
210
+ requestData: data instanceof record_js_1.DBRecordDraft ? data.toJson() : data
211
+ });
212
+ }
213
+ },
214
+ relations: {
215
+ find: async (searchParams, pagination, transaction) => {
216
+ const txId = (0, utils_js_2.pickTransactionId)(transaction);
217
+ const queryParams = new URLSearchParams();
218
+ if (typeof (pagination === null || pagination === void 0 ? void 0 : pagination.limit) !== 'undefined') {
219
+ queryParams.append('limit', pagination.limit.toString());
220
+ }
221
+ if (typeof (pagination === null || pagination === void 0 ? void 0 : pagination.skip) !== 'undefined') {
222
+ queryParams.append('skip', pagination === null || pagination === void 0 ? void 0 : pagination.skip.toString());
223
+ }
224
+ const queryString = queryParams.toString() ? '?' + queryParams.toString() : '';
225
+ return fetcher(`/records/relations/search${queryString}`, {
226
+ headers: Object.assign({}, (0, utils_js_2.buildTransactionHeader)(txId)),
227
+ method: 'POST',
228
+ requestData: searchParams
229
+ });
230
+ }
231
+ },
232
+ tx: {
233
+ begin(config = {}) {
234
+ return fetcher(`/tx`, {
235
+ method: 'POST',
236
+ requestData: config
237
+ });
238
+ },
239
+ commit(id) {
240
+ return fetcher(`/tx/${id}/commit`, {
241
+ method: 'POST',
242
+ requestData: {}
243
+ });
244
+ },
245
+ get(id) {
246
+ return fetcher(`/tx/${id}`, {
247
+ method: 'GET'
248
+ });
249
+ },
250
+ rollback(id) {
251
+ return fetcher(`/tx/${id}/rollback`, {
252
+ method: 'POST',
253
+ requestData: {}
254
+ });
255
+ }
256
+ }
257
+ });
258
+ exports.createApi = createApi;
@@ -0,0 +1,8 @@
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; } });
@@ -0,0 +1,22 @@
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;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,154 @@
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 || protocol === 'http' ? '80'
135
+ : protocol === 'https' ? '443'
136
+ : '');
137
+ }
138
+ if ('host' in props && 'port' in props && 'protocol' in props) {
139
+ protocol = props.protocol.replace(':', '');
140
+ host = props.host;
141
+ port = props.port;
142
+ }
143
+ // Ensure the basePath starts with a '/'
144
+ if (basePath && !basePath.startsWith('/')) {
145
+ basePath = '/' + basePath;
146
+ }
147
+ // If the port is the default for the protocol (80 for http, 443 for https), it can be omitted
148
+ let portString = '';
149
+ if (!((protocol === 'http' && port === 80) || (protocol === 'https' && port === 443))) {
150
+ portString = ':' + port;
151
+ }
152
+ return `${protocol}://${host}${portString}${basePath}`;
153
+ };
154
+ exports.buildUrl = buildUrl;
@@ -0,0 +1,10 @@
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';
@@ -0,0 +1,46 @@
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;
@@ -0,0 +1,24 @@
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;
@@ -0,0 +1,24 @@
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;