@syntropix/database 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var axios = require('axios');
4
3
  require('reflect-metadata');
4
+ var axios = require('axios');
5
+ var bson = require('bson');
5
6
 
6
7
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
8
 
@@ -9,9 +10,78 @@ var axios__default = /*#__PURE__*/_interopDefault(axios);
9
10
 
10
11
  var __defProp = Object.defineProperty;
11
12
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
12
- var Client = class {
13
+
14
+ // src/types/model/filter.ts
15
+ var SortType = {
16
+ Descending: "Descending",
17
+ Ascending: "Ascending"
18
+ };
19
+ var AggregateFunction = /* @__PURE__ */ (function(AggregateFunction2) {
20
+ AggregateFunction2["Count"] = "Count";
21
+ AggregateFunction2["Sum"] = "Sum";
22
+ AggregateFunction2["Avg"] = "Avg";
23
+ AggregateFunction2["Min"] = "Min";
24
+ AggregateFunction2["Max"] = "Max";
25
+ AggregateFunction2["CountDistinct"] = "CountDistinct";
26
+ return AggregateFunction2;
27
+ })({});
28
+ var FilterOperation = /* @__PURE__ */ (function(FilterOperation2) {
29
+ FilterOperation2["LT"] = "LT";
30
+ FilterOperation2["LTE"] = "LTE";
31
+ FilterOperation2["GT"] = "GT";
32
+ FilterOperation2["GTE"] = "GTE";
33
+ FilterOperation2["EQ"] = "EQ";
34
+ FilterOperation2["NEQ"] = "NEQ";
35
+ FilterOperation2["Between"] = "Between";
36
+ FilterOperation2["In"] = "In";
37
+ FilterOperation2["Contains"] = "Contains";
38
+ FilterOperation2["Overlap"] = "Overlap";
39
+ FilterOperation2["NotIn"] = "NotIn";
40
+ FilterOperation2["Like"] = "Like";
41
+ FilterOperation2["NotLike"] = "NotLike";
42
+ FilterOperation2["ILike"] = "ILike";
43
+ FilterOperation2["NotILike"] = "NotILike";
44
+ FilterOperation2["IsNull"] = "IsNull";
45
+ FilterOperation2["IsNotNull"] = "IsNotNull";
46
+ FilterOperation2["Similarity"] = "Similarity";
47
+ FilterOperation2["SimilarityDistance"] = "SimilarityDistance";
48
+ FilterOperation2["WordSimilarity"] = "WordSimilarity";
49
+ FilterOperation2["WordSimilarityDistance"] = "WordSimilarityDistance";
50
+ FilterOperation2["StrictWordSimilarity"] = "StrictWordSimilarity";
51
+ FilterOperation2["StrictWordSimilarityDistance"] = "StrictWordSimilarityDistance";
52
+ FilterOperation2["EuclideanDistance"] = "EuclideanDistance";
53
+ FilterOperation2["NegativeInnerProduct"] = "NegativeInnerProduct";
54
+ FilterOperation2["CosineDistance"] = "CosineDistance";
55
+ return FilterOperation2;
56
+ })({});
57
+
58
+ // src/types/model/foreign-key.ts
59
+ var ForeignKeyAction = {
60
+ Cascade: "Cascade",
61
+ Restrict: "Restrict",
62
+ SetNull: "SetNull",
63
+ NoAction: "NoAction",
64
+ SetDefault: "SetDefault"
65
+ };
66
+
67
+ // src/types/model/shared.ts
68
+ var AccessType = {
69
+ None: "None",
70
+ Read: "Read",
71
+ Write: "Write",
72
+ Admin: "Admin"
73
+ };
74
+ function handleError(error) {
75
+ const axiosErr = error;
76
+ if (axiosErr.response?.data?.status === "error") {
77
+ throw new Error(axiosErr.response.data.message);
78
+ }
79
+ throw new Error(axiosErr.message);
80
+ }
81
+ __name(handleError, "handleError");
82
+ var BaseClient = class {
13
83
  static {
14
- __name(this, "Client");
84
+ __name(this, "BaseClient");
15
85
  }
16
86
  config;
17
87
  constructor(config) {
@@ -30,23 +100,41 @@ var Client = class {
30
100
  return `${this.config.baseUrl}${path}`;
31
101
  }
32
102
  async get(path, data = {}) {
33
- const response = await axios__default.default.get(this.url(path), {
34
- headers: this.headers(),
35
- params: data
36
- });
37
- if (response.status !== 200) {
38
- throw new Error(`Failed to get data: ${response.statusText}`);
103
+ try {
104
+ const response = await axios__default.default.get(this.url(path), {
105
+ headers: this.headers(),
106
+ params: data
107
+ });
108
+ const content = bson.EJSON.parse(JSON.stringify(response.data));
109
+ if (content.status !== "success") {
110
+ throw new Error(content.message);
111
+ }
112
+ return content.data;
113
+ } catch (error) {
114
+ if (axios__default.default.isAxiosError(error)) {
115
+ handleError(error);
116
+ }
117
+ console.error(error);
118
+ throw new Error("Failed to get data: Unknown error");
39
119
  }
40
- return response.data;
41
120
  }
42
121
  async post(path, data = {}) {
43
- const response = await axios__default.default.post(this.url(path), data, {
44
- headers: this.headers()
45
- });
46
- if (response.status !== 200) {
47
- throw new Error(`Failed to post data: ${response.statusText}`);
122
+ try {
123
+ const response = await axios__default.default.post(this.url(path), data, {
124
+ headers: this.headers()
125
+ });
126
+ const content = bson.EJSON.parse(JSON.stringify(response.data));
127
+ if (content.status !== "success") {
128
+ throw new Error(content.message);
129
+ }
130
+ return content.data;
131
+ } catch (error) {
132
+ if (axios__default.default.isAxiosError(error)) {
133
+ handleError(error);
134
+ }
135
+ console.error(error);
136
+ throw new Error("Failed to post data: Unknown error");
48
137
  }
49
- return response.data;
50
138
  }
51
139
  };
52
140
 
@@ -79,210 +167,176 @@ var ClientConfig = class {
79
167
  }
80
168
  };
81
169
 
82
- // src/types/filter.ts
83
- var SortType = /* @__PURE__ */ (function(SortType2) {
84
- SortType2["Descending"] = "Descending";
85
- SortType2["Ascending"] = "Ascending";
86
- return SortType2;
87
- })({});
88
- var FilterOperation = /* @__PURE__ */ (function(FilterOperation2) {
89
- FilterOperation2["LT"] = "LT";
90
- FilterOperation2["LTE"] = "LTE";
91
- FilterOperation2["GT"] = "GT";
92
- FilterOperation2["GTE"] = "GTE";
93
- FilterOperation2["EQ"] = "EQ";
94
- FilterOperation2["NEQ"] = "NEQ";
95
- FilterOperation2["Between"] = "Between";
96
- FilterOperation2["In"] = "In";
97
- FilterOperation2["Contains"] = "Contains";
98
- FilterOperation2["Overlap"] = "Overlap";
99
- FilterOperation2["NotIn"] = "NotIn";
100
- FilterOperation2["Like"] = "Like";
101
- FilterOperation2["NotLike"] = "NotLike";
102
- FilterOperation2["ILike"] = "ILike";
103
- FilterOperation2["NotILike"] = "NotILike";
104
- FilterOperation2["IsNull"] = "IsNull";
105
- FilterOperation2["IsNotNull"] = "IsNotNull";
106
- FilterOperation2["Similarity"] = "Similarity";
107
- FilterOperation2["SimilarityDistance"] = "SimilarityDistance";
108
- FilterOperation2["WordSimilarity"] = "WordSimilarity";
109
- FilterOperation2["WordSimilarityDistance"] = "WordSimilarityDistance";
110
- FilterOperation2["StrictWordSimilarity"] = "StrictWordSimilarity";
111
- FilterOperation2["StrictWordSimilarityDistance"] = "StrictWordSimilarityDistance";
112
- FilterOperation2["EuclideanDistance"] = "EuclideanDistance";
113
- FilterOperation2["NegativeInnerProduct"] = "NegativeInnerProduct";
114
- FilterOperation2["CosineDistance"] = "CosineDistance";
115
- return FilterOperation2;
116
- })({});
170
+ // src/core/filter-builder.ts
117
171
  var AND = /* @__PURE__ */ __name((...conditions) => conditions, "AND");
118
172
  var OR = /* @__PURE__ */ __name((...conditions) => conditions, "OR");
119
173
  var EQ = /* @__PURE__ */ __name((field, value) => ({
120
- column: field,
121
- operator: "EQ",
174
+ columnName: field,
175
+ operator: FilterOperation.EQ,
122
176
  staticValue: value
123
177
  }), "EQ");
124
178
  var NE = /* @__PURE__ */ __name((field, value) => ({
125
- column: field,
126
- operator: "NEQ",
179
+ columnName: field,
180
+ operator: FilterOperation.NEQ,
127
181
  staticValue: value
128
182
  }), "NE");
129
183
  var GT = /* @__PURE__ */ __name((field, value) => ({
130
- column: field,
131
- operator: "GT",
184
+ columnName: field,
185
+ operator: FilterOperation.GT,
132
186
  staticValue: value
133
187
  }), "GT");
134
188
  var GTE = /* @__PURE__ */ __name((field, value) => ({
135
- column: field,
136
- operator: "GTE",
189
+ columnName: field,
190
+ operator: FilterOperation.GTE,
137
191
  staticValue: value
138
192
  }), "GTE");
139
193
  var LT = /* @__PURE__ */ __name((field, value) => ({
140
- column: field,
141
- operator: "LT",
194
+ columnName: field,
195
+ operator: FilterOperation.LT,
142
196
  staticValue: value
143
197
  }), "LT");
144
198
  var LTE = /* @__PURE__ */ __name((field, value) => ({
145
- column: field,
146
- operator: "LTE",
199
+ columnName: field,
200
+ operator: FilterOperation.LTE,
147
201
  staticValue: value
148
202
  }), "LTE");
149
203
  var IN = /* @__PURE__ */ __name((field, values) => ({
150
- column: field,
151
- operator: "In",
204
+ columnName: field,
205
+ operator: FilterOperation.In,
152
206
  staticValue: values
153
207
  }), "IN");
154
208
  var CONTAINS = /* @__PURE__ */ __name((field, value) => ({
155
- column: field,
156
- operator: "Contains",
209
+ columnName: field,
210
+ operator: FilterOperation.Contains,
157
211
  staticValue: value
158
212
  }), "CONTAINS");
159
213
  var OVERLAP = /* @__PURE__ */ __name((field, value) => ({
160
- column: field,
161
- operator: "Overlap",
214
+ columnName: field,
215
+ operator: FilterOperation.Overlap,
162
216
  staticValue: value
163
217
  }), "OVERLAP");
164
218
  var I_LIKE = /* @__PURE__ */ __name((field, pattern) => ({
165
- column: field,
166
- operator: "ILike",
219
+ columnName: field,
220
+ operator: FilterOperation.ILike,
167
221
  staticValue: pattern
168
222
  }), "I_LIKE");
169
223
  var NOT_I_LIKE = /* @__PURE__ */ __name((field, pattern) => ({
170
- column: field,
171
- operator: "NotILike",
224
+ columnName: field,
225
+ operator: FilterOperation.NotILike,
172
226
  staticValue: pattern
173
227
  }), "NOT_I_LIKE");
174
228
  var NOT_IN = /* @__PURE__ */ __name((field, values) => ({
175
- column: field,
176
- operator: "NotIn",
229
+ columnName: field,
230
+ operator: FilterOperation.NotIn,
177
231
  staticValue: values
178
232
  }), "NOT_IN");
179
233
  var LIKE = /* @__PURE__ */ __name((field, pattern) => ({
180
- column: field,
181
- operator: "Like",
234
+ columnName: field,
235
+ operator: FilterOperation.Like,
182
236
  staticValue: pattern
183
237
  }), "LIKE");
184
238
  var NOT_LIKE = /* @__PURE__ */ __name((field, pattern) => ({
185
- column: field,
186
- operator: "NotLike",
239
+ columnName: field,
240
+ operator: FilterOperation.NotLike,
187
241
  staticValue: pattern
188
242
  }), "NOT_LIKE");
189
243
  var IS_NULL = /* @__PURE__ */ __name((field) => ({
190
- column: field,
191
- operator: "IsNull"
244
+ columnName: field,
245
+ operator: FilterOperation.IsNull
192
246
  }), "IS_NULL");
193
247
  var IS_NOT_NULL = /* @__PURE__ */ __name((field) => ({
194
- column: field,
195
- operator: "IsNotNull"
248
+ columnName: field,
249
+ operator: FilterOperation.IsNotNull
196
250
  }), "IS_NOT_NULL");
197
251
  var BETWEEN = /* @__PURE__ */ __name((field, min, max) => ({
198
- column: field,
199
- operator: "Between",
252
+ columnName: field,
253
+ operator: FilterOperation.Between,
200
254
  staticValue: [
201
255
  min,
202
256
  max
203
257
  ]
204
258
  }), "BETWEEN");
205
259
  var EQ_COL = /* @__PURE__ */ __name((field, otherField) => ({
206
- column: field,
207
- operator: "EQ",
260
+ columnName: field,
261
+ operator: FilterOperation.EQ,
208
262
  columnValue: otherField
209
263
  }), "EQ_COL");
210
264
  var NE_COL = /* @__PURE__ */ __name((field, otherField) => ({
211
- column: field,
212
- operator: "NEQ",
265
+ columnName: field,
266
+ operator: FilterOperation.NEQ,
213
267
  columnValue: otherField
214
268
  }), "NE_COL");
215
269
  var GT_COL = /* @__PURE__ */ __name((field, otherField) => ({
216
- column: field,
217
- operator: "GT",
270
+ columnName: field,
271
+ operator: FilterOperation.GT,
218
272
  columnValue: otherField
219
273
  }), "GT_COL");
220
274
  var GTE_COL = /* @__PURE__ */ __name((field, otherField) => ({
221
- column: field,
222
- operator: "GTE",
275
+ columnName: field,
276
+ operator: FilterOperation.GTE,
223
277
  columnValue: otherField
224
278
  }), "GTE_COL");
225
279
  var LT_COL = /* @__PURE__ */ __name((field, otherField) => ({
226
- column: field,
227
- operator: "LT",
280
+ columnName: field,
281
+ operator: FilterOperation.LT,
228
282
  columnValue: otherField
229
283
  }), "LT_COL");
230
284
  var LTE_COL = /* @__PURE__ */ __name((field, otherField) => ({
231
- column: field,
232
- operator: "LTE",
285
+ columnName: field,
286
+ operator: FilterOperation.LTE,
233
287
  columnValue: otherField
234
288
  }), "LTE_COL");
235
289
  var SIMILARITY = /* @__PURE__ */ __name((field, value, options) => ({
236
- column: field,
237
- operator: "Similarity",
290
+ columnName: field,
291
+ operator: FilterOperation.Similarity,
238
292
  staticValue: value,
239
293
  simiarityOptions: options
240
294
  }), "SIMILARITY");
241
295
  var SIMILARITY_DISTANCE = /* @__PURE__ */ __name((field, value, options) => ({
242
- column: field,
243
- operator: "SimilarityDistance",
296
+ columnName: field,
297
+ operator: FilterOperation.SimilarityDistance,
244
298
  staticValue: value,
245
299
  simiarityOptions: options
246
300
  }), "SIMILARITY_DISTANCE");
247
301
  var WORD_SIMILARITY = /* @__PURE__ */ __name((field, value, options) => ({
248
- column: field,
249
- operator: "WordSimilarity",
302
+ columnName: field,
303
+ operator: FilterOperation.WordSimilarity,
250
304
  staticValue: value,
251
305
  simiarityOptions: options
252
306
  }), "WORD_SIMILARITY");
253
307
  var WORD_SIMILARITY_DISTANCE = /* @__PURE__ */ __name((field, value, options) => ({
254
- column: field,
255
- operator: "WordSimilarityDistance",
308
+ columnName: field,
309
+ operator: FilterOperation.WordSimilarityDistance,
256
310
  staticValue: value,
257
311
  simiarityOptions: options
258
312
  }), "WORD_SIMILARITY_DISTANCE");
259
313
  var STRICT_WORD_SIMILARITY = /* @__PURE__ */ __name((field, value, options) => ({
260
- column: field,
261
- operator: "StrictWordSimilarity",
314
+ columnName: field,
315
+ operator: FilterOperation.StrictWordSimilarity,
262
316
  staticValue: value,
263
317
  simiarityOptions: options
264
318
  }), "STRICT_WORD_SIMILARITY");
265
319
  var STRICT_WORD_SIMILARITY_DISTANCE = /* @__PURE__ */ __name((field, value, options) => ({
266
- column: field,
267
- operator: "StrictWordSimilarityDistance",
320
+ columnName: field,
321
+ operator: FilterOperation.StrictWordSimilarityDistance,
268
322
  staticValue: value,
269
323
  simiarityOptions: options
270
324
  }), "STRICT_WORD_SIMILARITY_DISTANCE");
271
325
  var EUCLIDEAN_DISTANCE = /* @__PURE__ */ __name((field, value, options) => ({
272
- column: field,
273
- operator: "EuclideanDistance",
326
+ columnName: field,
327
+ operator: FilterOperation.EuclideanDistance,
274
328
  staticValue: value,
275
329
  simiarityOptions: options
276
330
  }), "EUCLIDEAN_DISTANCE");
277
331
  var NEGATIVE_INNER_PRODUCT = /* @__PURE__ */ __name((field, value, options) => ({
278
- column: field,
279
- operator: "NegativeInnerProduct",
332
+ columnName: field,
333
+ operator: FilterOperation.NegativeInnerProduct,
280
334
  staticValue: value,
281
335
  simiarityOptions: options
282
336
  }), "NEGATIVE_INNER_PRODUCT");
283
337
  var COSINE_DISTANCE = /* @__PURE__ */ __name((field, value, options) => ({
284
- column: field,
285
- operator: "CosineDistance",
338
+ columnName: field,
339
+ operator: FilterOperation.CosineDistance,
286
340
  staticValue: value,
287
341
  simiarityOptions: options
288
342
  }), "COSINE_DISTANCE");
@@ -301,155 +355,91 @@ function FilterWrapper(filter) {
301
355
  }
302
356
  __name(FilterWrapper, "FilterWrapper");
303
357
 
304
- // src/core/data-client.ts
358
+ // src/core/client/data-client.ts
305
359
  var DataClient = class {
306
360
  static {
307
361
  __name(this, "DataClient");
308
362
  }
309
363
  client;
310
364
  constructor(config = new ClientConfig()) {
311
- this.client = new Client(config);
365
+ this.client = new BaseClient(config);
312
366
  }
313
367
  async insertData(data) {
314
- const response = await this.client.post("/insert", data);
315
- if (response.status === "success") {
316
- return response.data;
317
- }
318
- throw new Error(response.message);
368
+ return await this.client.post("/insert", data);
319
369
  }
320
370
  async insertOne(data) {
321
- const response = await this.client.post("/insert/one", data);
322
- if (response.status === "success") {
323
- return response.data;
324
- }
325
- throw new Error(response.message);
371
+ return await this.client.post("/insert/one", data);
326
372
  }
327
373
  async updateByPrimaryKey(pk, data) {
328
- const response = await this.client.post(`/update/${pk}`, data);
329
- if (response.status === "success") {
330
- return response.data;
331
- }
332
- throw new Error(response.message);
374
+ return await this.client.post(`/update/${pk}`, data);
333
375
  }
334
376
  async queryOne(data, model) {
335
377
  data.query.filter = FilterWrapper(data.query.filter);
336
378
  const response = await this.client.post("/query", {
337
379
  One: data
338
380
  });
339
- if (response.status === "success") {
340
- const responseData = response.data;
341
- if (model !== void 0) {
342
- return new model(responseData);
343
- }
344
- return responseData;
381
+ if (model !== void 0) {
382
+ return new model(response);
345
383
  }
346
- throw new Error(response.message);
384
+ return response;
347
385
  }
348
386
  async queryMany(data, model) {
349
387
  data.query.filter = FilterWrapper(data.query.filter);
350
388
  const response = await this.client.post("/query", {
351
389
  Many: data
352
390
  });
353
- if (response.status === "success") {
354
- const responseData = response.data;
355
- if (model !== void 0) {
356
- return responseData.map((item) => new model(item));
357
- }
358
- return responseData;
391
+ if (model !== void 0) {
392
+ return response.map((item) => new model(item));
359
393
  }
360
- throw new Error(response.message);
394
+ return response;
361
395
  }
362
396
  async updateData(data) {
363
- const response = await this.client.post("/update", data);
364
- if (response.status === "success") {
365
- return response.data;
366
- }
367
- throw new Error(response.message);
397
+ return await this.client.post("/update", data);
368
398
  }
369
399
  async deleteData(data) {
370
- const response = await this.client.post("/delete", data);
371
- if (response.status === "success") {
372
- return response.data;
373
- }
374
- throw new Error(response.message);
400
+ return await this.client.post("/delete", data);
375
401
  }
376
402
  };
377
403
 
378
- // src/core/table-client.ts
404
+ // src/core/client/table-client.ts
379
405
  var TableClient = class {
380
406
  static {
381
407
  __name(this, "TableClient");
382
408
  }
383
409
  client;
384
410
  constructor(config = new ClientConfig()) {
385
- this.client = new Client(config);
411
+ this.client = new BaseClient(config);
386
412
  }
387
413
  async createTable(data) {
388
- const response = await this.client.post("/table/create", data);
389
- if (response.status === "success") {
390
- return response.data;
391
- }
392
- throw new Error(response.message);
414
+ return await this.client.post("/table/create", data);
393
415
  }
394
416
  async dropTable(data) {
395
- const response = await this.client.post("/table/drop", data);
396
- if (response.status === "success") {
397
- return response.data;
398
- }
399
- throw new Error(response.message);
417
+ return await this.client.post("/table/drop", data);
400
418
  }
401
419
  async renameTable(data) {
402
- const response = await this.client.post("/table/rename", data);
403
- if (response.status === "success") {
404
- return response.data;
405
- }
406
- throw new Error(response.message);
420
+ return await this.client.post("/table/rename", data);
407
421
  }
408
422
  async truncateTable(data) {
409
- const response = await this.client.post("/table/truncate", data);
410
- if (response.status === "success") {
411
- return response.data;
412
- }
413
- throw new Error(response.message);
423
+ return await this.client.post("/table/truncate", data);
414
424
  }
415
425
  async addColumn(data) {
416
- const response = await this.client.post("/table/column/add", data);
417
- if (response.status === "success") {
418
- return response.data;
419
- }
420
- throw new Error(response.message);
426
+ return await this.client.post("/table/column/add", data);
421
427
  }
422
428
  async dropColumn(data) {
423
- const response = await this.client.post("/table/column/drop", data);
424
- if (response.status === "success") {
425
- return response.data;
426
- }
427
- throw new Error(response.message);
429
+ return await this.client.post("/table/column/drop", data);
428
430
  }
429
431
  async modifyColumn(data) {
430
- const response = await this.client.post("/table/column/modify", data);
431
- if (response.status === "success") {
432
- return response.data;
433
- }
434
- throw new Error(response.message);
432
+ return await this.client.post("/table/column/modify", data);
435
433
  }
436
434
  async getTableSchema(data) {
437
- const response = await this.client.post("/table/schema", data);
438
- if (response.status === "success") {
439
- return response.data;
440
- }
441
- throw new Error(response.message);
435
+ return await this.client.get("/table/schema", data);
442
436
  }
443
437
  async getTableList(data) {
444
- const response = await this.client.get("/table/list", data);
445
- if (response.status === "success") {
446
- return response.data;
447
- }
448
- throw new Error(response.message);
438
+ return await this.client.get("/table/list", data);
449
439
  }
450
440
  };
451
441
 
452
- // src/core/syntropix.ts
442
+ // src/core/client/syntropix-client.ts
453
443
  var SyntropixClient = class {
454
444
  static {
455
445
  __name(this, "SyntropixClient");
@@ -474,26 +464,40 @@ var SyntropixClient = class {
474
464
  }
475
465
  };
476
466
 
477
- // src/types/common.ts
478
- var ForeignKeyAction = /* @__PURE__ */ (function(ForeignKeyAction2) {
479
- ForeignKeyAction2["Cascade"] = "Cascade";
480
- ForeignKeyAction2["Restrict"] = "Restrict";
481
- ForeignKeyAction2["SetNull"] = "SetNull";
482
- ForeignKeyAction2["NoAction"] = "NoAction";
483
- ForeignKeyAction2["SetDefault"] = "SetDefault";
484
- return ForeignKeyAction2;
485
- })({});
486
- var AggregateFunction = /* @__PURE__ */ (function(AggregateFunction2) {
487
- AggregateFunction2["Count"] = "Count";
488
- AggregateFunction2["Sum"] = "Sum";
489
- AggregateFunction2["Avg"] = "Avg";
490
- AggregateFunction2["Min"] = "Min";
491
- AggregateFunction2["Max"] = "Max";
492
- AggregateFunction2["CountDistinct"] = "CountDistinct";
493
- return AggregateFunction2;
494
- })({});
495
-
496
- // src/types/data-type.ts
467
+ // src/core/data-type.ts
468
+ var ArrayDataType = {
469
+ String: /* @__PURE__ */ __name((maxLength) => ({
470
+ String: maxLength
471
+ }), "String"),
472
+ Decimal: /* @__PURE__ */ __name((precision, scale) => ({
473
+ Decimal: precision && scale ? [
474
+ precision,
475
+ scale
476
+ ] : null
477
+ }), "Decimal"),
478
+ Text: "Text",
479
+ Integer: "Integer",
480
+ BigInteger: "BigInteger",
481
+ Double: "Double",
482
+ DateTime: "DateTime",
483
+ Timestamp: "Timestamp",
484
+ Date: "Date",
485
+ Boolean: "Boolean",
486
+ Money: /* @__PURE__ */ __name((precision, scale) => ({
487
+ Money: precision && scale ? [
488
+ precision,
489
+ scale
490
+ ] : null
491
+ }), "Money"),
492
+ Uuid: "Uuid",
493
+ Enum: /* @__PURE__ */ __name((name, variants) => ({
494
+ Enum: {
495
+ name,
496
+ variants
497
+ }
498
+ }), "Enum"),
499
+ Json: "Json"
500
+ };
497
501
  var ColumnDataType = {
498
502
  Integer: "Integer",
499
503
  String: /* @__PURE__ */ __name((maxLength) => ({
@@ -533,12 +537,13 @@ var ColumnDataType = {
533
537
  }), "Decimal")
534
538
  };
535
539
 
536
- // src/types/field.ts
540
+ // src/core/field.ts
537
541
  var Field = class {
538
542
  static {
539
543
  __name(this, "Field");
540
544
  }
541
545
  name = "";
546
+ displayName = "";
542
547
  description = "";
543
548
  columnType;
544
549
  isPrimaryKey = false;
@@ -549,6 +554,7 @@ var Field = class {
549
554
  constructor(columnType, options = {}) {
550
555
  this.columnType = columnType;
551
556
  this.name = options.name?.toLowerCase() || "";
557
+ this.displayName = options.displayName || "";
552
558
  this.description = options.description || "";
553
559
  this.isPrimaryKey = options.isPrimaryKey || false;
554
560
  this.isNullable = options.isNullable || false;
@@ -556,9 +562,10 @@ var Field = class {
556
562
  this.default = options.default;
557
563
  this.defaultAccess = options.defaultAccess;
558
564
  }
559
- into() {
565
+ intoColumnCreateDto() {
560
566
  return {
561
567
  name: this.name,
568
+ displayName: this.displayName,
562
569
  columnType: this.columnType,
563
570
  description: this.description,
564
571
  isPrimaryKey: this.isPrimaryKey,
@@ -705,8 +712,11 @@ var DoubleField = class extends Field {
705
712
  super(ColumnDataType.Double, options);
706
713
  }
707
714
  };
715
+
716
+ // src/core/base-model.ts
708
717
  var FIELDS_KEY = Symbol("fields");
709
718
  var TABLE_NAME_KEY = Symbol("tableName");
719
+ var TABLE_DISPLAY_NAME_KEY = Symbol("displayTableName");
710
720
  var DESCRIPTION_KEY = Symbol("description");
711
721
  var INDEXES_KEY = Symbol("indexes");
712
722
  function Column(options = {}) {
@@ -718,11 +728,13 @@ function Column(options = {}) {
718
728
  constructor() {
719
729
  super(columnType, {
720
730
  name: fieldName,
731
+ displayName: options.displayName,
721
732
  description: options.description,
722
733
  isPrimaryKey: options.primary,
723
734
  isNullable: options.nullable,
724
735
  autoIncrement: options.autoIncrement,
725
- default: options.default
736
+ default: options.default,
737
+ defaultAccess: options.defaultAccess
726
738
  });
727
739
  }
728
740
  }();
@@ -731,15 +743,22 @@ function Column(options = {}) {
731
743
  };
732
744
  }
733
745
  __name(Column, "Column");
746
+ function Description(description) {
747
+ return function(target) {
748
+ Reflect.defineMetadata(DESCRIPTION_KEY, description, target);
749
+ };
750
+ }
751
+ __name(Description, "Description");
734
752
  function ForeignKey(tableName, columnName, options = {}) {
735
753
  return function(target, propertyKey) {
736
754
  const fields = Reflect.getMetadata(FIELDS_KEY, target.constructor) || {};
737
755
  const field = new ForeignKeyField(options.type || ColumnDataType.Integer, tableName, columnName, {
738
- onDelete: options.onDelete,
739
- onUpdate: options.onUpdate,
756
+ displayName: options.displayName,
740
757
  description: options.description,
741
758
  isNullable: options.nullable,
742
- default: options.default
759
+ default: options.default,
760
+ onDelete: options.onDelete,
761
+ onUpdate: options.onUpdate
743
762
  });
744
763
  field.name = options.name || propertyKey.toLowerCase();
745
764
  fields[propertyKey] = field;
@@ -778,6 +797,14 @@ var BaseModel = class {
778
797
  }
779
798
  return this.name.toLowerCase();
780
799
  }
800
+ static getDisplayName() {
801
+ const displayName = Reflect.getMetadata(TABLE_DISPLAY_NAME_KEY, this);
802
+ if (displayName) return displayName;
803
+ if ("displayName" in this && typeof this.displayName === "string") {
804
+ return this.displayName;
805
+ }
806
+ return this.name;
807
+ }
781
808
  static getDescription() {
782
809
  const metadataDescription = Reflect.getMetadata(DESCRIPTION_KEY, this);
783
810
  if (metadataDescription) return metadataDescription;
@@ -830,6 +857,9 @@ var BaseModel = class {
830
857
  getTableName() {
831
858
  return this.constructor.getTableName();
832
859
  }
860
+ getDisplayName() {
861
+ return this.constructor.getDisplayName();
862
+ }
833
863
  getPrimaryKeyName() {
834
864
  return this.constructor.getPrimaryKeyName();
835
865
  }
@@ -845,14 +875,14 @@ var BaseModel = class {
845
875
  // Client getter
846
876
  get client() {
847
877
  if (!this._client) {
848
- this._client = new SyntropixClient(new ClientConfig());
878
+ this._client = new SyntropixClient();
849
879
  }
850
880
  return this._client;
851
881
  }
852
882
  // Table operations
853
- static async createTable(_client) {
883
+ static async createTable(client = new SyntropixClient()) {
854
884
  const fields = this.getFields();
855
- const columns = Object.values(fields).map((f) => f.into());
885
+ const columns = Object.values(fields).map((f) => f.intoColumnCreateDto());
856
886
  const foreignKeys = this.getAssociations().map((f) => ({
857
887
  fromTableName: this.getTableName(),
858
888
  fromColumnName: f.name,
@@ -862,36 +892,38 @@ var BaseModel = class {
862
892
  onUpdate: f.onUpdate
863
893
  }));
864
894
  const indexes = this.getIndexes();
865
- const client = _client || new SyntropixClient(new ClientConfig());
866
- return client.table.createTable({
895
+ return await client.table.createTable({
867
896
  name: this.getTableName(),
897
+ displayName: this.getDisplayName(),
868
898
  description: this.getDescription() || "No description",
869
899
  columns,
870
900
  foreignKeys,
871
901
  indexes
872
902
  });
873
903
  }
874
- static async dropTable(_client) {
875
- const client = _client || new SyntropixClient(new ClientConfig());
876
- return client.table.dropTable({
904
+ static async dropTable(client = new SyntropixClient()) {
905
+ return await client.table.dropTable({
877
906
  tableName: this.getTableName()
878
907
  });
879
908
  }
880
- static async renameTable(newName, _client) {
881
- const client = _client || new SyntropixClient(new ClientConfig());
882
- return client.table.renameTable({
909
+ static async renameTable(newName, client = new SyntropixClient()) {
910
+ return await client.table.renameTable({
883
911
  tableName: this.getTableName(),
884
912
  newTableName: newName
885
913
  });
886
914
  }
887
- static async truncateTable(_client) {
888
- const client = _client || new SyntropixClient(new ClientConfig());
889
- return client.table.truncateTable({
915
+ static async truncateTable(client = new SyntropixClient()) {
916
+ return await client.table.truncateTable({
917
+ tableName: this.getTableName()
918
+ });
919
+ }
920
+ static async getTableSchema(client = new SyntropixClient()) {
921
+ return await client.table.getTableSchema({
890
922
  tableName: this.getTableName()
891
923
  });
892
924
  }
893
925
  // Data operations
894
- static async create(data, _client) {
926
+ static async create(data, client = new SyntropixClient()) {
895
927
  const model = this;
896
928
  const fields = model.getFields();
897
929
  const columns = [];
@@ -904,7 +936,6 @@ var BaseModel = class {
904
936
  throw new Error(`Invalid field: ${key}`);
905
937
  }
906
938
  }
907
- const client = _client || new SyntropixClient(new ClientConfig());
908
939
  return client.data.insertOne({
909
940
  tableName: model.getTableName(),
910
941
  data: {
@@ -915,7 +946,7 @@ var BaseModel = class {
915
946
  }
916
947
  });
917
948
  }
918
- async save(_client) {
949
+ async save(client = new SyntropixClient()) {
919
950
  const pk = this.getPrimaryKey();
920
951
  const pkValue = this[this.getPrimaryKeyName()];
921
952
  const fields = this.getFields();
@@ -924,7 +955,7 @@ var BaseModel = class {
924
955
  for (const [key, field] of Object.entries(fields)) {
925
956
  data[key] = this[key];
926
957
  }
927
- return this.constructor.create(data, _client);
958
+ return this.constructor.create(data, client);
928
959
  }
929
960
  const columns = [];
930
961
  const values = [];
@@ -934,7 +965,7 @@ var BaseModel = class {
934
965
  values.push(this[key]);
935
966
  }
936
967
  }
937
- return _client || this.client.data.updateByPrimaryKey(pkValue, {
968
+ return client || this.client.data.updateByPrimaryKey(pkValue, {
938
969
  tableName: this.getTableName(),
939
970
  payload: {
940
971
  filter: [
@@ -971,7 +1002,7 @@ var BaseModel = class {
971
1002
  }
972
1003
  }
973
1004
  let values = [];
974
- const client = _client || new SyntropixClient(new ClientConfig());
1005
+ const client = _client || new SyntropixClient();
975
1006
  for (const data of datas) {
976
1007
  if (columnsSet.size !== new Set(Object.keys(data)).size || !columns.every((c) => c in data)) {
977
1008
  throw new Error("All data must have the same columns");
@@ -1012,7 +1043,7 @@ var BaseModel = class {
1012
1043
  }
1013
1044
  }
1014
1045
  const values = columns.map((c) => data[c]);
1015
- const client = _client || new SyntropixClient(new ClientConfig());
1046
+ const client = _client || new SyntropixClient();
1016
1047
  return client.data.updateData({
1017
1048
  tableName: model.getTableName(),
1018
1049
  payload: {
@@ -1024,7 +1055,7 @@ var BaseModel = class {
1024
1055
  }
1025
1056
  static async delete(filter, _client) {
1026
1057
  const model = this;
1027
- const client = _client || new SyntropixClient(new ClientConfig());
1058
+ const client = _client || new SyntropixClient();
1028
1059
  return client.data.deleteData({
1029
1060
  tableName: model.getTableName(),
1030
1061
  payload: {
@@ -1035,7 +1066,7 @@ var BaseModel = class {
1035
1066
  static async get(filter, select, _client) {
1036
1067
  const model = this;
1037
1068
  const fields = model.getFields();
1038
- const client = _client || new SyntropixClient(new ClientConfig());
1069
+ const client = _client || new SyntropixClient();
1039
1070
  const data = await client.data.queryOne({
1040
1071
  tableName: model.getTableName(),
1041
1072
  query: {
@@ -1048,7 +1079,7 @@ var BaseModel = class {
1048
1079
  }
1049
1080
  static async filter(options) {
1050
1081
  const model = this;
1051
- const client = options._client || new SyntropixClient(new ClientConfig());
1082
+ const client = options._client || new SyntropixClient();
1052
1083
  const data = await client.data.queryMany({
1053
1084
  tableName: model.getTableName(),
1054
1085
  query: {
@@ -1068,7 +1099,7 @@ var BaseModel = class {
1068
1099
  }
1069
1100
  static async count(options = {}) {
1070
1101
  const model = this;
1071
- const client = options._client || new SyntropixClient(new ClientConfig());
1102
+ const client = options._client || new SyntropixClient();
1072
1103
  const data = await client.data.queryMany({
1073
1104
  tableName: model.getTableName(),
1074
1105
  query: {
@@ -1122,29 +1153,25 @@ var BaseModel = class {
1122
1153
  }
1123
1154
  };
1124
1155
 
1125
- // src/types/requests.ts
1126
- var SyntropixDBAccessType = {
1127
- None: "None",
1128
- Read: "Read",
1129
- Write: "Write",
1130
- Admin: "Admin"
1131
- };
1132
-
1133
1156
  exports.AND = AND;
1157
+ exports.AccessType = AccessType;
1134
1158
  exports.AggregateFunction = AggregateFunction;
1159
+ exports.ArrayDataType = ArrayDataType;
1135
1160
  exports.ArrayField = ArrayField;
1136
1161
  exports.BETWEEN = BETWEEN;
1162
+ exports.BaseClient = BaseClient;
1137
1163
  exports.BaseModel = BaseModel;
1138
1164
  exports.BooleanField = BooleanField;
1139
1165
  exports.CONTAINS = CONTAINS;
1140
1166
  exports.COSINE_DISTANCE = COSINE_DISTANCE;
1141
- exports.Client = Client;
1142
1167
  exports.ClientConfig = ClientConfig;
1143
1168
  exports.Column = Column;
1144
1169
  exports.ColumnDataType = ColumnDataType;
1170
+ exports.DataClient = DataClient;
1145
1171
  exports.DateField = DateField;
1146
1172
  exports.DateTimeField = DateTimeField;
1147
1173
  exports.DecimalField = DecimalField;
1174
+ exports.Description = Description;
1148
1175
  exports.DoubleField = DoubleField;
1149
1176
  exports.EQ = EQ;
1150
1177
  exports.EQ_COL = EQ_COL;
@@ -1187,7 +1214,7 @@ exports.STRICT_WORD_SIMILARITY_DISTANCE = STRICT_WORD_SIMILARITY_DISTANCE;
1187
1214
  exports.SortType = SortType;
1188
1215
  exports.StringField = StringField;
1189
1216
  exports.SyntropixClient = SyntropixClient;
1190
- exports.SyntropixDBAccessType = SyntropixDBAccessType;
1217
+ exports.TableClient = TableClient;
1191
1218
  exports.TextField = TextField;
1192
1219
  exports.TimestampField = TimestampField;
1193
1220
  exports.UuidField = UuidField;