@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.js CHANGED
@@ -1,11 +1,81 @@
1
- import axios from 'axios';
2
1
  import 'reflect-metadata';
2
+ import axios from 'axios';
3
+ import { EJSON } from 'bson';
3
4
 
4
5
  var __defProp = Object.defineProperty;
5
6
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
- var Client = class {
7
+
8
+ // src/types/model/filter.ts
9
+ var SortType = {
10
+ Descending: "Descending",
11
+ Ascending: "Ascending"
12
+ };
13
+ var AggregateFunction = /* @__PURE__ */ (function(AggregateFunction2) {
14
+ AggregateFunction2["Count"] = "Count";
15
+ AggregateFunction2["Sum"] = "Sum";
16
+ AggregateFunction2["Avg"] = "Avg";
17
+ AggregateFunction2["Min"] = "Min";
18
+ AggregateFunction2["Max"] = "Max";
19
+ AggregateFunction2["CountDistinct"] = "CountDistinct";
20
+ return AggregateFunction2;
21
+ })({});
22
+ var FilterOperation = /* @__PURE__ */ (function(FilterOperation2) {
23
+ FilterOperation2["LT"] = "LT";
24
+ FilterOperation2["LTE"] = "LTE";
25
+ FilterOperation2["GT"] = "GT";
26
+ FilterOperation2["GTE"] = "GTE";
27
+ FilterOperation2["EQ"] = "EQ";
28
+ FilterOperation2["NEQ"] = "NEQ";
29
+ FilterOperation2["Between"] = "Between";
30
+ FilterOperation2["In"] = "In";
31
+ FilterOperation2["Contains"] = "Contains";
32
+ FilterOperation2["Overlap"] = "Overlap";
33
+ FilterOperation2["NotIn"] = "NotIn";
34
+ FilterOperation2["Like"] = "Like";
35
+ FilterOperation2["NotLike"] = "NotLike";
36
+ FilterOperation2["ILike"] = "ILike";
37
+ FilterOperation2["NotILike"] = "NotILike";
38
+ FilterOperation2["IsNull"] = "IsNull";
39
+ FilterOperation2["IsNotNull"] = "IsNotNull";
40
+ FilterOperation2["Similarity"] = "Similarity";
41
+ FilterOperation2["SimilarityDistance"] = "SimilarityDistance";
42
+ FilterOperation2["WordSimilarity"] = "WordSimilarity";
43
+ FilterOperation2["WordSimilarityDistance"] = "WordSimilarityDistance";
44
+ FilterOperation2["StrictWordSimilarity"] = "StrictWordSimilarity";
45
+ FilterOperation2["StrictWordSimilarityDistance"] = "StrictWordSimilarityDistance";
46
+ FilterOperation2["EuclideanDistance"] = "EuclideanDistance";
47
+ FilterOperation2["NegativeInnerProduct"] = "NegativeInnerProduct";
48
+ FilterOperation2["CosineDistance"] = "CosineDistance";
49
+ return FilterOperation2;
50
+ })({});
51
+
52
+ // src/types/model/foreign-key.ts
53
+ var ForeignKeyAction = {
54
+ Cascade: "Cascade",
55
+ Restrict: "Restrict",
56
+ SetNull: "SetNull",
57
+ NoAction: "NoAction",
58
+ SetDefault: "SetDefault"
59
+ };
60
+
61
+ // src/types/model/shared.ts
62
+ var AccessType = {
63
+ None: "None",
64
+ Read: "Read",
65
+ Write: "Write",
66
+ Admin: "Admin"
67
+ };
68
+ function handleError(error) {
69
+ const axiosErr = error;
70
+ if (axiosErr.response?.data?.status === "error") {
71
+ throw new Error(axiosErr.response.data.message);
72
+ }
73
+ throw new Error(axiosErr.message);
74
+ }
75
+ __name(handleError, "handleError");
76
+ var BaseClient = class {
7
77
  static {
8
- __name(this, "Client");
78
+ __name(this, "BaseClient");
9
79
  }
10
80
  config;
11
81
  constructor(config) {
@@ -24,23 +94,41 @@ var Client = class {
24
94
  return `${this.config.baseUrl}${path}`;
25
95
  }
26
96
  async get(path, data = {}) {
27
- const response = await axios.get(this.url(path), {
28
- headers: this.headers(),
29
- params: data
30
- });
31
- if (response.status !== 200) {
32
- throw new Error(`Failed to get data: ${response.statusText}`);
97
+ try {
98
+ const response = await axios.get(this.url(path), {
99
+ headers: this.headers(),
100
+ params: data
101
+ });
102
+ const content = EJSON.parse(JSON.stringify(response.data));
103
+ if (content.status !== "success") {
104
+ throw new Error(content.message);
105
+ }
106
+ return content.data;
107
+ } catch (error) {
108
+ if (axios.isAxiosError(error)) {
109
+ handleError(error);
110
+ }
111
+ console.error(error);
112
+ throw new Error("Failed to get data: Unknown error");
33
113
  }
34
- return response.data;
35
114
  }
36
115
  async post(path, data = {}) {
37
- const response = await axios.post(this.url(path), data, {
38
- headers: this.headers()
39
- });
40
- if (response.status !== 200) {
41
- throw new Error(`Failed to post data: ${response.statusText}`);
116
+ try {
117
+ const response = await axios.post(this.url(path), data, {
118
+ headers: this.headers()
119
+ });
120
+ const content = EJSON.parse(JSON.stringify(response.data));
121
+ if (content.status !== "success") {
122
+ throw new Error(content.message);
123
+ }
124
+ return content.data;
125
+ } catch (error) {
126
+ if (axios.isAxiosError(error)) {
127
+ handleError(error);
128
+ }
129
+ console.error(error);
130
+ throw new Error("Failed to post data: Unknown error");
42
131
  }
43
- return response.data;
44
132
  }
45
133
  };
46
134
 
@@ -73,210 +161,176 @@ var ClientConfig = class {
73
161
  }
74
162
  };
75
163
 
76
- // src/types/filter.ts
77
- var SortType = /* @__PURE__ */ (function(SortType2) {
78
- SortType2["Descending"] = "Descending";
79
- SortType2["Ascending"] = "Ascending";
80
- return SortType2;
81
- })({});
82
- var FilterOperation = /* @__PURE__ */ (function(FilterOperation2) {
83
- FilterOperation2["LT"] = "LT";
84
- FilterOperation2["LTE"] = "LTE";
85
- FilterOperation2["GT"] = "GT";
86
- FilterOperation2["GTE"] = "GTE";
87
- FilterOperation2["EQ"] = "EQ";
88
- FilterOperation2["NEQ"] = "NEQ";
89
- FilterOperation2["Between"] = "Between";
90
- FilterOperation2["In"] = "In";
91
- FilterOperation2["Contains"] = "Contains";
92
- FilterOperation2["Overlap"] = "Overlap";
93
- FilterOperation2["NotIn"] = "NotIn";
94
- FilterOperation2["Like"] = "Like";
95
- FilterOperation2["NotLike"] = "NotLike";
96
- FilterOperation2["ILike"] = "ILike";
97
- FilterOperation2["NotILike"] = "NotILike";
98
- FilterOperation2["IsNull"] = "IsNull";
99
- FilterOperation2["IsNotNull"] = "IsNotNull";
100
- FilterOperation2["Similarity"] = "Similarity";
101
- FilterOperation2["SimilarityDistance"] = "SimilarityDistance";
102
- FilterOperation2["WordSimilarity"] = "WordSimilarity";
103
- FilterOperation2["WordSimilarityDistance"] = "WordSimilarityDistance";
104
- FilterOperation2["StrictWordSimilarity"] = "StrictWordSimilarity";
105
- FilterOperation2["StrictWordSimilarityDistance"] = "StrictWordSimilarityDistance";
106
- FilterOperation2["EuclideanDistance"] = "EuclideanDistance";
107
- FilterOperation2["NegativeInnerProduct"] = "NegativeInnerProduct";
108
- FilterOperation2["CosineDistance"] = "CosineDistance";
109
- return FilterOperation2;
110
- })({});
164
+ // src/core/filter-builder.ts
111
165
  var AND = /* @__PURE__ */ __name((...conditions) => conditions, "AND");
112
166
  var OR = /* @__PURE__ */ __name((...conditions) => conditions, "OR");
113
167
  var EQ = /* @__PURE__ */ __name((field, value) => ({
114
- column: field,
115
- operator: "EQ",
168
+ columnName: field,
169
+ operator: FilterOperation.EQ,
116
170
  staticValue: value
117
171
  }), "EQ");
118
172
  var NE = /* @__PURE__ */ __name((field, value) => ({
119
- column: field,
120
- operator: "NEQ",
173
+ columnName: field,
174
+ operator: FilterOperation.NEQ,
121
175
  staticValue: value
122
176
  }), "NE");
123
177
  var GT = /* @__PURE__ */ __name((field, value) => ({
124
- column: field,
125
- operator: "GT",
178
+ columnName: field,
179
+ operator: FilterOperation.GT,
126
180
  staticValue: value
127
181
  }), "GT");
128
182
  var GTE = /* @__PURE__ */ __name((field, value) => ({
129
- column: field,
130
- operator: "GTE",
183
+ columnName: field,
184
+ operator: FilterOperation.GTE,
131
185
  staticValue: value
132
186
  }), "GTE");
133
187
  var LT = /* @__PURE__ */ __name((field, value) => ({
134
- column: field,
135
- operator: "LT",
188
+ columnName: field,
189
+ operator: FilterOperation.LT,
136
190
  staticValue: value
137
191
  }), "LT");
138
192
  var LTE = /* @__PURE__ */ __name((field, value) => ({
139
- column: field,
140
- operator: "LTE",
193
+ columnName: field,
194
+ operator: FilterOperation.LTE,
141
195
  staticValue: value
142
196
  }), "LTE");
143
197
  var IN = /* @__PURE__ */ __name((field, values) => ({
144
- column: field,
145
- operator: "In",
198
+ columnName: field,
199
+ operator: FilterOperation.In,
146
200
  staticValue: values
147
201
  }), "IN");
148
202
  var CONTAINS = /* @__PURE__ */ __name((field, value) => ({
149
- column: field,
150
- operator: "Contains",
203
+ columnName: field,
204
+ operator: FilterOperation.Contains,
151
205
  staticValue: value
152
206
  }), "CONTAINS");
153
207
  var OVERLAP = /* @__PURE__ */ __name((field, value) => ({
154
- column: field,
155
- operator: "Overlap",
208
+ columnName: field,
209
+ operator: FilterOperation.Overlap,
156
210
  staticValue: value
157
211
  }), "OVERLAP");
158
212
  var I_LIKE = /* @__PURE__ */ __name((field, pattern) => ({
159
- column: field,
160
- operator: "ILike",
213
+ columnName: field,
214
+ operator: FilterOperation.ILike,
161
215
  staticValue: pattern
162
216
  }), "I_LIKE");
163
217
  var NOT_I_LIKE = /* @__PURE__ */ __name((field, pattern) => ({
164
- column: field,
165
- operator: "NotILike",
218
+ columnName: field,
219
+ operator: FilterOperation.NotILike,
166
220
  staticValue: pattern
167
221
  }), "NOT_I_LIKE");
168
222
  var NOT_IN = /* @__PURE__ */ __name((field, values) => ({
169
- column: field,
170
- operator: "NotIn",
223
+ columnName: field,
224
+ operator: FilterOperation.NotIn,
171
225
  staticValue: values
172
226
  }), "NOT_IN");
173
227
  var LIKE = /* @__PURE__ */ __name((field, pattern) => ({
174
- column: field,
175
- operator: "Like",
228
+ columnName: field,
229
+ operator: FilterOperation.Like,
176
230
  staticValue: pattern
177
231
  }), "LIKE");
178
232
  var NOT_LIKE = /* @__PURE__ */ __name((field, pattern) => ({
179
- column: field,
180
- operator: "NotLike",
233
+ columnName: field,
234
+ operator: FilterOperation.NotLike,
181
235
  staticValue: pattern
182
236
  }), "NOT_LIKE");
183
237
  var IS_NULL = /* @__PURE__ */ __name((field) => ({
184
- column: field,
185
- operator: "IsNull"
238
+ columnName: field,
239
+ operator: FilterOperation.IsNull
186
240
  }), "IS_NULL");
187
241
  var IS_NOT_NULL = /* @__PURE__ */ __name((field) => ({
188
- column: field,
189
- operator: "IsNotNull"
242
+ columnName: field,
243
+ operator: FilterOperation.IsNotNull
190
244
  }), "IS_NOT_NULL");
191
245
  var BETWEEN = /* @__PURE__ */ __name((field, min, max) => ({
192
- column: field,
193
- operator: "Between",
246
+ columnName: field,
247
+ operator: FilterOperation.Between,
194
248
  staticValue: [
195
249
  min,
196
250
  max
197
251
  ]
198
252
  }), "BETWEEN");
199
253
  var EQ_COL = /* @__PURE__ */ __name((field, otherField) => ({
200
- column: field,
201
- operator: "EQ",
254
+ columnName: field,
255
+ operator: FilterOperation.EQ,
202
256
  columnValue: otherField
203
257
  }), "EQ_COL");
204
258
  var NE_COL = /* @__PURE__ */ __name((field, otherField) => ({
205
- column: field,
206
- operator: "NEQ",
259
+ columnName: field,
260
+ operator: FilterOperation.NEQ,
207
261
  columnValue: otherField
208
262
  }), "NE_COL");
209
263
  var GT_COL = /* @__PURE__ */ __name((field, otherField) => ({
210
- column: field,
211
- operator: "GT",
264
+ columnName: field,
265
+ operator: FilterOperation.GT,
212
266
  columnValue: otherField
213
267
  }), "GT_COL");
214
268
  var GTE_COL = /* @__PURE__ */ __name((field, otherField) => ({
215
- column: field,
216
- operator: "GTE",
269
+ columnName: field,
270
+ operator: FilterOperation.GTE,
217
271
  columnValue: otherField
218
272
  }), "GTE_COL");
219
273
  var LT_COL = /* @__PURE__ */ __name((field, otherField) => ({
220
- column: field,
221
- operator: "LT",
274
+ columnName: field,
275
+ operator: FilterOperation.LT,
222
276
  columnValue: otherField
223
277
  }), "LT_COL");
224
278
  var LTE_COL = /* @__PURE__ */ __name((field, otherField) => ({
225
- column: field,
226
- operator: "LTE",
279
+ columnName: field,
280
+ operator: FilterOperation.LTE,
227
281
  columnValue: otherField
228
282
  }), "LTE_COL");
229
283
  var SIMILARITY = /* @__PURE__ */ __name((field, value, options) => ({
230
- column: field,
231
- operator: "Similarity",
284
+ columnName: field,
285
+ operator: FilterOperation.Similarity,
232
286
  staticValue: value,
233
287
  simiarityOptions: options
234
288
  }), "SIMILARITY");
235
289
  var SIMILARITY_DISTANCE = /* @__PURE__ */ __name((field, value, options) => ({
236
- column: field,
237
- operator: "SimilarityDistance",
290
+ columnName: field,
291
+ operator: FilterOperation.SimilarityDistance,
238
292
  staticValue: value,
239
293
  simiarityOptions: options
240
294
  }), "SIMILARITY_DISTANCE");
241
295
  var WORD_SIMILARITY = /* @__PURE__ */ __name((field, value, options) => ({
242
- column: field,
243
- operator: "WordSimilarity",
296
+ columnName: field,
297
+ operator: FilterOperation.WordSimilarity,
244
298
  staticValue: value,
245
299
  simiarityOptions: options
246
300
  }), "WORD_SIMILARITY");
247
301
  var WORD_SIMILARITY_DISTANCE = /* @__PURE__ */ __name((field, value, options) => ({
248
- column: field,
249
- operator: "WordSimilarityDistance",
302
+ columnName: field,
303
+ operator: FilterOperation.WordSimilarityDistance,
250
304
  staticValue: value,
251
305
  simiarityOptions: options
252
306
  }), "WORD_SIMILARITY_DISTANCE");
253
307
  var STRICT_WORD_SIMILARITY = /* @__PURE__ */ __name((field, value, options) => ({
254
- column: field,
255
- operator: "StrictWordSimilarity",
308
+ columnName: field,
309
+ operator: FilterOperation.StrictWordSimilarity,
256
310
  staticValue: value,
257
311
  simiarityOptions: options
258
312
  }), "STRICT_WORD_SIMILARITY");
259
313
  var STRICT_WORD_SIMILARITY_DISTANCE = /* @__PURE__ */ __name((field, value, options) => ({
260
- column: field,
261
- operator: "StrictWordSimilarityDistance",
314
+ columnName: field,
315
+ operator: FilterOperation.StrictWordSimilarityDistance,
262
316
  staticValue: value,
263
317
  simiarityOptions: options
264
318
  }), "STRICT_WORD_SIMILARITY_DISTANCE");
265
319
  var EUCLIDEAN_DISTANCE = /* @__PURE__ */ __name((field, value, options) => ({
266
- column: field,
267
- operator: "EuclideanDistance",
320
+ columnName: field,
321
+ operator: FilterOperation.EuclideanDistance,
268
322
  staticValue: value,
269
323
  simiarityOptions: options
270
324
  }), "EUCLIDEAN_DISTANCE");
271
325
  var NEGATIVE_INNER_PRODUCT = /* @__PURE__ */ __name((field, value, options) => ({
272
- column: field,
273
- operator: "NegativeInnerProduct",
326
+ columnName: field,
327
+ operator: FilterOperation.NegativeInnerProduct,
274
328
  staticValue: value,
275
329
  simiarityOptions: options
276
330
  }), "NEGATIVE_INNER_PRODUCT");
277
331
  var COSINE_DISTANCE = /* @__PURE__ */ __name((field, value, options) => ({
278
- column: field,
279
- operator: "CosineDistance",
332
+ columnName: field,
333
+ operator: FilterOperation.CosineDistance,
280
334
  staticValue: value,
281
335
  simiarityOptions: options
282
336
  }), "COSINE_DISTANCE");
@@ -295,155 +349,91 @@ function FilterWrapper(filter) {
295
349
  }
296
350
  __name(FilterWrapper, "FilterWrapper");
297
351
 
298
- // src/core/data-client.ts
352
+ // src/core/client/data-client.ts
299
353
  var DataClient = class {
300
354
  static {
301
355
  __name(this, "DataClient");
302
356
  }
303
357
  client;
304
358
  constructor(config = new ClientConfig()) {
305
- this.client = new Client(config);
359
+ this.client = new BaseClient(config);
306
360
  }
307
361
  async insertData(data) {
308
- const response = await this.client.post("/insert", data);
309
- if (response.status === "success") {
310
- return response.data;
311
- }
312
- throw new Error(response.message);
362
+ return await this.client.post("/insert", data);
313
363
  }
314
364
  async insertOne(data) {
315
- const response = await this.client.post("/insert/one", data);
316
- if (response.status === "success") {
317
- return response.data;
318
- }
319
- throw new Error(response.message);
365
+ return await this.client.post("/insert/one", data);
320
366
  }
321
367
  async updateByPrimaryKey(pk, data) {
322
- const response = await this.client.post(`/update/${pk}`, data);
323
- if (response.status === "success") {
324
- return response.data;
325
- }
326
- throw new Error(response.message);
368
+ return await this.client.post(`/update/${pk}`, data);
327
369
  }
328
370
  async queryOne(data, model) {
329
371
  data.query.filter = FilterWrapper(data.query.filter);
330
372
  const response = await this.client.post("/query", {
331
373
  One: data
332
374
  });
333
- if (response.status === "success") {
334
- const responseData = response.data;
335
- if (model !== void 0) {
336
- return new model(responseData);
337
- }
338
- return responseData;
375
+ if (model !== void 0) {
376
+ return new model(response);
339
377
  }
340
- throw new Error(response.message);
378
+ return response;
341
379
  }
342
380
  async queryMany(data, model) {
343
381
  data.query.filter = FilterWrapper(data.query.filter);
344
382
  const response = await this.client.post("/query", {
345
383
  Many: data
346
384
  });
347
- if (response.status === "success") {
348
- const responseData = response.data;
349
- if (model !== void 0) {
350
- return responseData.map((item) => new model(item));
351
- }
352
- return responseData;
385
+ if (model !== void 0) {
386
+ return response.map((item) => new model(item));
353
387
  }
354
- throw new Error(response.message);
388
+ return response;
355
389
  }
356
390
  async updateData(data) {
357
- const response = await this.client.post("/update", data);
358
- if (response.status === "success") {
359
- return response.data;
360
- }
361
- throw new Error(response.message);
391
+ return await this.client.post("/update", data);
362
392
  }
363
393
  async deleteData(data) {
364
- const response = await this.client.post("/delete", data);
365
- if (response.status === "success") {
366
- return response.data;
367
- }
368
- throw new Error(response.message);
394
+ return await this.client.post("/delete", data);
369
395
  }
370
396
  };
371
397
 
372
- // src/core/table-client.ts
398
+ // src/core/client/table-client.ts
373
399
  var TableClient = class {
374
400
  static {
375
401
  __name(this, "TableClient");
376
402
  }
377
403
  client;
378
404
  constructor(config = new ClientConfig()) {
379
- this.client = new Client(config);
405
+ this.client = new BaseClient(config);
380
406
  }
381
407
  async createTable(data) {
382
- const response = await this.client.post("/table/create", data);
383
- if (response.status === "success") {
384
- return response.data;
385
- }
386
- throw new Error(response.message);
408
+ return await this.client.post("/table/create", data);
387
409
  }
388
410
  async dropTable(data) {
389
- const response = await this.client.post("/table/drop", data);
390
- if (response.status === "success") {
391
- return response.data;
392
- }
393
- throw new Error(response.message);
411
+ return await this.client.post("/table/drop", data);
394
412
  }
395
413
  async renameTable(data) {
396
- const response = await this.client.post("/table/rename", data);
397
- if (response.status === "success") {
398
- return response.data;
399
- }
400
- throw new Error(response.message);
414
+ return await this.client.post("/table/rename", data);
401
415
  }
402
416
  async truncateTable(data) {
403
- const response = await this.client.post("/table/truncate", data);
404
- if (response.status === "success") {
405
- return response.data;
406
- }
407
- throw new Error(response.message);
417
+ return await this.client.post("/table/truncate", data);
408
418
  }
409
419
  async addColumn(data) {
410
- const response = await this.client.post("/table/column/add", data);
411
- if (response.status === "success") {
412
- return response.data;
413
- }
414
- throw new Error(response.message);
420
+ return await this.client.post("/table/column/add", data);
415
421
  }
416
422
  async dropColumn(data) {
417
- const response = await this.client.post("/table/column/drop", data);
418
- if (response.status === "success") {
419
- return response.data;
420
- }
421
- throw new Error(response.message);
423
+ return await this.client.post("/table/column/drop", data);
422
424
  }
423
425
  async modifyColumn(data) {
424
- const response = await this.client.post("/table/column/modify", data);
425
- if (response.status === "success") {
426
- return response.data;
427
- }
428
- throw new Error(response.message);
426
+ return await this.client.post("/table/column/modify", data);
429
427
  }
430
428
  async getTableSchema(data) {
431
- const response = await this.client.post("/table/schema", data);
432
- if (response.status === "success") {
433
- return response.data;
434
- }
435
- throw new Error(response.message);
429
+ return await this.client.get("/table/schema", data);
436
430
  }
437
431
  async getTableList(data) {
438
- const response = await this.client.get("/table/list", data);
439
- if (response.status === "success") {
440
- return response.data;
441
- }
442
- throw new Error(response.message);
432
+ return await this.client.get("/table/list", data);
443
433
  }
444
434
  };
445
435
 
446
- // src/core/syntropix.ts
436
+ // src/core/client/syntropix-client.ts
447
437
  var SyntropixClient = class {
448
438
  static {
449
439
  __name(this, "SyntropixClient");
@@ -468,26 +458,40 @@ var SyntropixClient = class {
468
458
  }
469
459
  };
470
460
 
471
- // src/types/common.ts
472
- var ForeignKeyAction = /* @__PURE__ */ (function(ForeignKeyAction2) {
473
- ForeignKeyAction2["Cascade"] = "Cascade";
474
- ForeignKeyAction2["Restrict"] = "Restrict";
475
- ForeignKeyAction2["SetNull"] = "SetNull";
476
- ForeignKeyAction2["NoAction"] = "NoAction";
477
- ForeignKeyAction2["SetDefault"] = "SetDefault";
478
- return ForeignKeyAction2;
479
- })({});
480
- var AggregateFunction = /* @__PURE__ */ (function(AggregateFunction2) {
481
- AggregateFunction2["Count"] = "Count";
482
- AggregateFunction2["Sum"] = "Sum";
483
- AggregateFunction2["Avg"] = "Avg";
484
- AggregateFunction2["Min"] = "Min";
485
- AggregateFunction2["Max"] = "Max";
486
- AggregateFunction2["CountDistinct"] = "CountDistinct";
487
- return AggregateFunction2;
488
- })({});
489
-
490
- // src/types/data-type.ts
461
+ // src/core/data-type.ts
462
+ var ArrayDataType = {
463
+ String: /* @__PURE__ */ __name((maxLength) => ({
464
+ String: maxLength
465
+ }), "String"),
466
+ Decimal: /* @__PURE__ */ __name((precision, scale) => ({
467
+ Decimal: precision && scale ? [
468
+ precision,
469
+ scale
470
+ ] : null
471
+ }), "Decimal"),
472
+ Text: "Text",
473
+ Integer: "Integer",
474
+ BigInteger: "BigInteger",
475
+ Double: "Double",
476
+ DateTime: "DateTime",
477
+ Timestamp: "Timestamp",
478
+ Date: "Date",
479
+ Boolean: "Boolean",
480
+ Money: /* @__PURE__ */ __name((precision, scale) => ({
481
+ Money: precision && scale ? [
482
+ precision,
483
+ scale
484
+ ] : null
485
+ }), "Money"),
486
+ Uuid: "Uuid",
487
+ Enum: /* @__PURE__ */ __name((name, variants) => ({
488
+ Enum: {
489
+ name,
490
+ variants
491
+ }
492
+ }), "Enum"),
493
+ Json: "Json"
494
+ };
491
495
  var ColumnDataType = {
492
496
  Integer: "Integer",
493
497
  String: /* @__PURE__ */ __name((maxLength) => ({
@@ -527,12 +531,13 @@ var ColumnDataType = {
527
531
  }), "Decimal")
528
532
  };
529
533
 
530
- // src/types/field.ts
534
+ // src/core/field.ts
531
535
  var Field = class {
532
536
  static {
533
537
  __name(this, "Field");
534
538
  }
535
539
  name = "";
540
+ displayName = "";
536
541
  description = "";
537
542
  columnType;
538
543
  isPrimaryKey = false;
@@ -543,6 +548,7 @@ var Field = class {
543
548
  constructor(columnType, options = {}) {
544
549
  this.columnType = columnType;
545
550
  this.name = options.name?.toLowerCase() || "";
551
+ this.displayName = options.displayName || "";
546
552
  this.description = options.description || "";
547
553
  this.isPrimaryKey = options.isPrimaryKey || false;
548
554
  this.isNullable = options.isNullable || false;
@@ -550,9 +556,10 @@ var Field = class {
550
556
  this.default = options.default;
551
557
  this.defaultAccess = options.defaultAccess;
552
558
  }
553
- into() {
559
+ intoColumnCreateDto() {
554
560
  return {
555
561
  name: this.name,
562
+ displayName: this.displayName,
556
563
  columnType: this.columnType,
557
564
  description: this.description,
558
565
  isPrimaryKey: this.isPrimaryKey,
@@ -699,8 +706,11 @@ var DoubleField = class extends Field {
699
706
  super(ColumnDataType.Double, options);
700
707
  }
701
708
  };
709
+
710
+ // src/core/base-model.ts
702
711
  var FIELDS_KEY = Symbol("fields");
703
712
  var TABLE_NAME_KEY = Symbol("tableName");
713
+ var TABLE_DISPLAY_NAME_KEY = Symbol("displayTableName");
704
714
  var DESCRIPTION_KEY = Symbol("description");
705
715
  var INDEXES_KEY = Symbol("indexes");
706
716
  function Column(options = {}) {
@@ -712,11 +722,13 @@ function Column(options = {}) {
712
722
  constructor() {
713
723
  super(columnType, {
714
724
  name: fieldName,
725
+ displayName: options.displayName,
715
726
  description: options.description,
716
727
  isPrimaryKey: options.primary,
717
728
  isNullable: options.nullable,
718
729
  autoIncrement: options.autoIncrement,
719
- default: options.default
730
+ default: options.default,
731
+ defaultAccess: options.defaultAccess
720
732
  });
721
733
  }
722
734
  }();
@@ -725,15 +737,22 @@ function Column(options = {}) {
725
737
  };
726
738
  }
727
739
  __name(Column, "Column");
740
+ function Description(description) {
741
+ return function(target) {
742
+ Reflect.defineMetadata(DESCRIPTION_KEY, description, target);
743
+ };
744
+ }
745
+ __name(Description, "Description");
728
746
  function ForeignKey(tableName, columnName, options = {}) {
729
747
  return function(target, propertyKey) {
730
748
  const fields = Reflect.getMetadata(FIELDS_KEY, target.constructor) || {};
731
749
  const field = new ForeignKeyField(options.type || ColumnDataType.Integer, tableName, columnName, {
732
- onDelete: options.onDelete,
733
- onUpdate: options.onUpdate,
750
+ displayName: options.displayName,
734
751
  description: options.description,
735
752
  isNullable: options.nullable,
736
- default: options.default
753
+ default: options.default,
754
+ onDelete: options.onDelete,
755
+ onUpdate: options.onUpdate
737
756
  });
738
757
  field.name = options.name || propertyKey.toLowerCase();
739
758
  fields[propertyKey] = field;
@@ -772,6 +791,14 @@ var BaseModel = class {
772
791
  }
773
792
  return this.name.toLowerCase();
774
793
  }
794
+ static getDisplayName() {
795
+ const displayName = Reflect.getMetadata(TABLE_DISPLAY_NAME_KEY, this);
796
+ if (displayName) return displayName;
797
+ if ("displayName" in this && typeof this.displayName === "string") {
798
+ return this.displayName;
799
+ }
800
+ return this.name;
801
+ }
775
802
  static getDescription() {
776
803
  const metadataDescription = Reflect.getMetadata(DESCRIPTION_KEY, this);
777
804
  if (metadataDescription) return metadataDescription;
@@ -824,6 +851,9 @@ var BaseModel = class {
824
851
  getTableName() {
825
852
  return this.constructor.getTableName();
826
853
  }
854
+ getDisplayName() {
855
+ return this.constructor.getDisplayName();
856
+ }
827
857
  getPrimaryKeyName() {
828
858
  return this.constructor.getPrimaryKeyName();
829
859
  }
@@ -839,14 +869,14 @@ var BaseModel = class {
839
869
  // Client getter
840
870
  get client() {
841
871
  if (!this._client) {
842
- this._client = new SyntropixClient(new ClientConfig());
872
+ this._client = new SyntropixClient();
843
873
  }
844
874
  return this._client;
845
875
  }
846
876
  // Table operations
847
- static async createTable(_client) {
877
+ static async createTable(client = new SyntropixClient()) {
848
878
  const fields = this.getFields();
849
- const columns = Object.values(fields).map((f) => f.into());
879
+ const columns = Object.values(fields).map((f) => f.intoColumnCreateDto());
850
880
  const foreignKeys = this.getAssociations().map((f) => ({
851
881
  fromTableName: this.getTableName(),
852
882
  fromColumnName: f.name,
@@ -856,36 +886,38 @@ var BaseModel = class {
856
886
  onUpdate: f.onUpdate
857
887
  }));
858
888
  const indexes = this.getIndexes();
859
- const client = _client || new SyntropixClient(new ClientConfig());
860
- return client.table.createTable({
889
+ return await client.table.createTable({
861
890
  name: this.getTableName(),
891
+ displayName: this.getDisplayName(),
862
892
  description: this.getDescription() || "No description",
863
893
  columns,
864
894
  foreignKeys,
865
895
  indexes
866
896
  });
867
897
  }
868
- static async dropTable(_client) {
869
- const client = _client || new SyntropixClient(new ClientConfig());
870
- return client.table.dropTable({
898
+ static async dropTable(client = new SyntropixClient()) {
899
+ return await client.table.dropTable({
871
900
  tableName: this.getTableName()
872
901
  });
873
902
  }
874
- static async renameTable(newName, _client) {
875
- const client = _client || new SyntropixClient(new ClientConfig());
876
- return client.table.renameTable({
903
+ static async renameTable(newName, client = new SyntropixClient()) {
904
+ return await client.table.renameTable({
877
905
  tableName: this.getTableName(),
878
906
  newTableName: newName
879
907
  });
880
908
  }
881
- static async truncateTable(_client) {
882
- const client = _client || new SyntropixClient(new ClientConfig());
883
- return client.table.truncateTable({
909
+ static async truncateTable(client = new SyntropixClient()) {
910
+ return await client.table.truncateTable({
911
+ tableName: this.getTableName()
912
+ });
913
+ }
914
+ static async getTableSchema(client = new SyntropixClient()) {
915
+ return await client.table.getTableSchema({
884
916
  tableName: this.getTableName()
885
917
  });
886
918
  }
887
919
  // Data operations
888
- static async create(data, _client) {
920
+ static async create(data, client = new SyntropixClient()) {
889
921
  const model = this;
890
922
  const fields = model.getFields();
891
923
  const columns = [];
@@ -898,7 +930,6 @@ var BaseModel = class {
898
930
  throw new Error(`Invalid field: ${key}`);
899
931
  }
900
932
  }
901
- const client = _client || new SyntropixClient(new ClientConfig());
902
933
  return client.data.insertOne({
903
934
  tableName: model.getTableName(),
904
935
  data: {
@@ -909,7 +940,7 @@ var BaseModel = class {
909
940
  }
910
941
  });
911
942
  }
912
- async save(_client) {
943
+ async save(client = new SyntropixClient()) {
913
944
  const pk = this.getPrimaryKey();
914
945
  const pkValue = this[this.getPrimaryKeyName()];
915
946
  const fields = this.getFields();
@@ -918,7 +949,7 @@ var BaseModel = class {
918
949
  for (const [key, field] of Object.entries(fields)) {
919
950
  data[key] = this[key];
920
951
  }
921
- return this.constructor.create(data, _client);
952
+ return this.constructor.create(data, client);
922
953
  }
923
954
  const columns = [];
924
955
  const values = [];
@@ -928,7 +959,7 @@ var BaseModel = class {
928
959
  values.push(this[key]);
929
960
  }
930
961
  }
931
- return _client || this.client.data.updateByPrimaryKey(pkValue, {
962
+ return client || this.client.data.updateByPrimaryKey(pkValue, {
932
963
  tableName: this.getTableName(),
933
964
  payload: {
934
965
  filter: [
@@ -965,7 +996,7 @@ var BaseModel = class {
965
996
  }
966
997
  }
967
998
  let values = [];
968
- const client = _client || new SyntropixClient(new ClientConfig());
999
+ const client = _client || new SyntropixClient();
969
1000
  for (const data of datas) {
970
1001
  if (columnsSet.size !== new Set(Object.keys(data)).size || !columns.every((c) => c in data)) {
971
1002
  throw new Error("All data must have the same columns");
@@ -1006,7 +1037,7 @@ var BaseModel = class {
1006
1037
  }
1007
1038
  }
1008
1039
  const values = columns.map((c) => data[c]);
1009
- const client = _client || new SyntropixClient(new ClientConfig());
1040
+ const client = _client || new SyntropixClient();
1010
1041
  return client.data.updateData({
1011
1042
  tableName: model.getTableName(),
1012
1043
  payload: {
@@ -1018,7 +1049,7 @@ var BaseModel = class {
1018
1049
  }
1019
1050
  static async delete(filter, _client) {
1020
1051
  const model = this;
1021
- const client = _client || new SyntropixClient(new ClientConfig());
1052
+ const client = _client || new SyntropixClient();
1022
1053
  return client.data.deleteData({
1023
1054
  tableName: model.getTableName(),
1024
1055
  payload: {
@@ -1029,7 +1060,7 @@ var BaseModel = class {
1029
1060
  static async get(filter, select, _client) {
1030
1061
  const model = this;
1031
1062
  const fields = model.getFields();
1032
- const client = _client || new SyntropixClient(new ClientConfig());
1063
+ const client = _client || new SyntropixClient();
1033
1064
  const data = await client.data.queryOne({
1034
1065
  tableName: model.getTableName(),
1035
1066
  query: {
@@ -1042,7 +1073,7 @@ var BaseModel = class {
1042
1073
  }
1043
1074
  static async filter(options) {
1044
1075
  const model = this;
1045
- const client = options._client || new SyntropixClient(new ClientConfig());
1076
+ const client = options._client || new SyntropixClient();
1046
1077
  const data = await client.data.queryMany({
1047
1078
  tableName: model.getTableName(),
1048
1079
  query: {
@@ -1062,7 +1093,7 @@ var BaseModel = class {
1062
1093
  }
1063
1094
  static async count(options = {}) {
1064
1095
  const model = this;
1065
- const client = options._client || new SyntropixClient(new ClientConfig());
1096
+ const client = options._client || new SyntropixClient();
1066
1097
  const data = await client.data.queryMany({
1067
1098
  tableName: model.getTableName(),
1068
1099
  query: {
@@ -1116,14 +1147,6 @@ var BaseModel = class {
1116
1147
  }
1117
1148
  };
1118
1149
 
1119
- // src/types/requests.ts
1120
- var SyntropixDBAccessType = {
1121
- None: "None",
1122
- Read: "Read",
1123
- Write: "Write",
1124
- Admin: "Admin"
1125
- };
1126
-
1127
- export { AND, AggregateFunction, ArrayField, BETWEEN, BaseModel, BooleanField, CONTAINS, COSINE_DISTANCE, Client, ClientConfig, Column, ColumnDataType, DateField, DateTimeField, DecimalField, DoubleField, EQ, EQ_COL, EUCLIDEAN_DISTANCE, EnumField, Field, FilterOperation, FilterWrapper, ForeignKey, ForeignKeyAction, ForeignKeyField, GT, GTE, GTE_COL, GT_COL, IN, IS_NOT_NULL, IS_NULL, I_LIKE, IntegerField, JsonField, LIKE, LT, LTE, LTE_COL, LT_COL, MoneyField, NE, NEGATIVE_INNER_PRODUCT, NE_COL, NOT_IN, NOT_I_LIKE, NOT_LIKE, OR, OVERLAP, SIMILARITY, SIMILARITY_DISTANCE, STRICT_WORD_SIMILARITY, STRICT_WORD_SIMILARITY_DISTANCE, SortType, StringField, SyntropixClient, SyntropixDBAccessType, TextField, TimestampField, UuidField, Value, VectorField, WORD_SIMILARITY, WORD_SIMILARITY_DISTANCE };
1150
+ export { AND, AccessType, AggregateFunction, ArrayDataType, ArrayField, BETWEEN, BaseClient, BaseModel, BooleanField, CONTAINS, COSINE_DISTANCE, ClientConfig, Column, ColumnDataType, DataClient, DateField, DateTimeField, DecimalField, Description, DoubleField, EQ, EQ_COL, EUCLIDEAN_DISTANCE, EnumField, Field, FilterOperation, FilterWrapper, ForeignKey, ForeignKeyAction, ForeignKeyField, GT, GTE, GTE_COL, GT_COL, IN, IS_NOT_NULL, IS_NULL, I_LIKE, IntegerField, JsonField, LIKE, LT, LTE, LTE_COL, LT_COL, MoneyField, NE, NEGATIVE_INNER_PRODUCT, NE_COL, NOT_IN, NOT_I_LIKE, NOT_LIKE, OR, OVERLAP, SIMILARITY, SIMILARITY_DISTANCE, STRICT_WORD_SIMILARITY, STRICT_WORD_SIMILARITY_DISTANCE, SortType, StringField, SyntropixClient, TableClient, TextField, TimestampField, UuidField, Value, VectorField, WORD_SIMILARITY, WORD_SIMILARITY_DISTANCE };
1128
1151
  //# sourceMappingURL=index.js.map
1129
1152
  //# sourceMappingURL=index.js.map