@syntropix/database 0.1.1 → 0.2.1

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