@syntropix/database 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/.env +1 -1
  2. package/.vscode/settings.json +1 -8
  3. package/dist/core/client.d.ts +0 -1
  4. package/dist/core/client.js +2 -6
  5. package/dist/core/config.d.ts +0 -1
  6. package/dist/core/config.js +5 -6
  7. package/dist/core/dataClient.d.ts +0 -1
  8. package/dist/core/dataClient.js +4 -13
  9. package/dist/core/syntropix.d.ts +0 -1
  10. package/dist/core/syntropix.js +8 -10
  11. package/dist/core/tableClient.d.ts +2 -2
  12. package/dist/core/tableClient.js +4 -8
  13. package/dist/index.d.ts +0 -1
  14. package/dist/index.js +9 -33
  15. package/dist/types/basemodel.d.ts +2 -2
  16. package/dist/types/basemodel.js +32 -39
  17. package/dist/types/common.d.ts +1 -2
  18. package/dist/types/common.js +4 -8
  19. package/dist/types/data-type.d.ts +0 -1
  20. package/dist/types/data-type.js +18 -23
  21. package/dist/types/dto/base.d.ts +4 -0
  22. package/dist/types/dto/base.js +1 -0
  23. package/dist/types/dto/table.d.ts +22 -0
  24. package/dist/types/dto/table.js +1 -0
  25. package/dist/types/field.d.ts +0 -1
  26. package/dist/types/field.js +47 -62
  27. package/dist/types/filter.d.ts +0 -1
  28. package/dist/types/filter.js +35 -70
  29. package/dist/types/requests.d.ts +0 -1
  30. package/dist/types/requests.js +1 -3
  31. package/eslint.config.mjs +23 -23
  32. package/examples/tsconfig.json +13 -0
  33. package/examples/usage.ts +73 -52
  34. package/jest.config.ts +9 -0
  35. package/package.json +6 -5
  36. package/src/core/dataClient.ts +1 -6
  37. package/src/core/tableClient.ts +3 -2
  38. package/src/types/basemodel.ts +3 -2
  39. package/src/types/common.ts +83 -83
  40. package/src/types/dto/base.ts +4 -0
  41. package/src/types/dto/table.ts +21 -0
  42. package/src/types/filter.ts +28 -1
  43. package/src/types/requests.ts +2 -52
  44. package/tests/basic.test.ts +130 -62
  45. package/tests/tsconfig.json +8 -0
  46. package/tsconfig.json +18 -50
  47. package/dist/core/client.d.ts.map +0 -1
  48. package/dist/core/client.js.map +0 -1
  49. package/dist/core/config.d.ts.map +0 -1
  50. package/dist/core/config.js.map +0 -1
  51. package/dist/core/dataClient.d.ts.map +0 -1
  52. package/dist/core/dataClient.js.map +0 -1
  53. package/dist/core/syntropix.d.ts.map +0 -1
  54. package/dist/core/syntropix.js.map +0 -1
  55. package/dist/core/tableClient.d.ts.map +0 -1
  56. package/dist/core/tableClient.js.map +0 -1
  57. package/dist/index.d.ts.map +0 -1
  58. package/dist/index.js.map +0 -1
  59. package/dist/types/basemodel.d.ts.map +0 -1
  60. package/dist/types/basemodel.js.map +0 -1
  61. package/dist/types/common.d.ts.map +0 -1
  62. package/dist/types/common.js.map +0 -1
  63. package/dist/types/data-type.d.ts.map +0 -1
  64. package/dist/types/data-type.js.map +0 -1
  65. package/dist/types/field.d.ts.map +0 -1
  66. package/dist/types/field.js.map +0 -1
  67. package/dist/types/filter.d.ts.map +0 -1
  68. package/dist/types/filter.js.map +0 -1
  69. package/dist/types/requests.d.ts.map +0 -1
  70. package/dist/types/requests.js.map +0 -1
  71. package/examples/advanced-usage.d.ts +0 -42
  72. package/examples/advanced-usage.d.ts.map +0 -1
  73. package/examples/advanced-usage.js +0 -257
  74. package/examples/advanced-usage.js.map +0 -1
  75. package/examples/usage.d.ts +0 -11
  76. package/examples/usage.d.ts.map +0 -1
  77. package/examples/usage.js +0 -91
  78. package/examples/usage.js.map +0 -1
  79. package/jest.config.js +0 -11
package/.env CHANGED
@@ -1,2 +1,2 @@
1
- SYNTROPIX_API_KEY = "MrxxQ9nzk9LNSHMTBLGP1WXx705aTMMyBj8D9tUMoant7UNf/NDVAVH34Pt7dcU+dLFAwglN33hK6u1gItyJTS3TnK4jYzJ3gaiiLTLxcLjNXfnv5PfJTta3MbKrWDFr9DH0JCu0C97ShCigv3XNiZzSvH+MrXHa+XF4pF3wotLZsWU6fhAfgOS2+xXagoSv3aHT8t/tqtx+grJVeNu5aFxBQ3gG9vns2L3Vw8IkaFRck32DEQPMfC9kO0KmvP6wmCKx5Z+1A0tl2+RCLebXcJE/RYv0oseSshe3B3IEnu/NgYaH6+PEYRTyidRBjcNu"
1
+ SYNTROPIX_API_KEY = "MrxxQ9nzk9LNSHMTBLGP1YpTVr+sT+sldRYASP0r/v7qPB16Qaksv3GU3ns/viLTyHDVgh1dN1ihtns+GXPu8pR4CjUuqpjXaowI5glQt2VbDXdScRQOkBs4YfJ9HBCts+Ri/32QYeOIjtWYWh52+349zi34rA91btmDw/0yzSv4mG9esygDm2zCSSvSEh/XZY1VhC+97/gxXwKOEVwINI2Twd/DOV3zvmQxfY733Ono1+2qWbLMLY/0rEKDx16eyRlud1PwauZXKzA1VdVpxC6O1RLwVXkfS7LNkr5QxhaWPdQWcbeJ9fPboFFbGNzICs5hBTEBDGnqbSnqwD6CfsqqgVpl5YM1DGzQyfvjb88="
2
2
  SYNTROPIX_API_URL = "http://149.248.14.64:8080"
@@ -1,8 +1 @@
1
- {
2
- "editor.defaultFormatter": "esbenp.prettier-vscode",
3
- "editor.formatOnSave": true,
4
- "[json]": {
5
- "editor.defaultFormatter": "esbenp.prettier-vscode",
6
- "editor.formatOnSave": true
7
- }
8
- }
1
+ {}
@@ -7,4 +7,3 @@ export declare class Client {
7
7
  get(path: string, data?: Record<string, any>): Promise<Record<string, any>>;
8
8
  post(path: string, data?: Record<string, any>): Promise<Record<string, any>>;
9
9
  }
10
- //# sourceMappingURL=client.d.ts.map
@@ -1,7 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Client = void 0;
4
- class Client {
1
+ export class Client {
2
+ config;
5
3
  constructor(config) {
6
4
  this.config = config;
7
5
  }
@@ -34,5 +32,3 @@ class Client {
34
32
  return response.json();
35
33
  }
36
34
  }
37
- exports.Client = Client;
38
- //# sourceMappingURL=client.js.map
@@ -5,4 +5,3 @@ export declare class ClientConfig {
5
5
  retries?: number;
6
6
  constructor(config?: any);
7
7
  }
8
- //# sourceMappingURL=config.d.ts.map
@@ -1,7 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClientConfig = void 0;
4
- class ClientConfig {
1
+ export class ClientConfig {
2
+ apiKey;
3
+ baseUrl;
4
+ timeout;
5
+ retries;
5
6
  constructor(config) {
6
7
  this.apiKey = config?.apiKey || process.env.SYNTROPIX_API_KEY;
7
8
  this.baseUrl = config?.baseUrl || process.env.SYNTROPIX_API_URL;
@@ -21,5 +22,3 @@ class ClientConfig {
21
22
  }
22
23
  }
23
24
  }
24
- exports.ClientConfig = ClientConfig;
25
- //# sourceMappingURL=config.js.map
@@ -11,4 +11,3 @@ export declare class DataClient {
11
11
  updateData(data: Update): Promise<any>;
12
12
  deleteData(data: DeleteData): Promise<any>;
13
13
  }
14
- //# sourceMappingURL=dataClient.d.ts.map
@@ -1,10 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DataClient = void 0;
4
- const client_1 = require("./client");
5
- class DataClient {
1
+ import { Client } from './client';
2
+ export class DataClient {
3
+ client;
6
4
  constructor(config) {
7
- this.client = new client_1.Client(config);
5
+ this.client = new Client(config);
8
6
  }
9
7
  async insertData(data) {
10
8
  const response = await this.client.post('/insert', data);
@@ -21,8 +19,6 @@ class DataClient {
21
19
  throw new Error(response.message);
22
20
  }
23
21
  async updateByPrimaryKey(pk, data) {
24
- console.log(pk);
25
- console.log(data);
26
22
  const response = await this.client.post(`/update/${pk}`, data);
27
23
  if (response.status === 'success') {
28
24
  return response.data;
@@ -34,9 +30,6 @@ class DataClient {
34
30
  if (response.status === 'success') {
35
31
  const responseData = response.data;
36
32
  if (model !== undefined) {
37
- // In TypeScript, we would typically use a validation library or manual validation
38
- // For now, we'll return the data as-is, but in a real implementation you might want to use
39
- // a library like class-validator or zod for validation
40
33
  return new model(responseData);
41
34
  }
42
35
  return responseData;
@@ -72,5 +65,3 @@ class DataClient {
72
65
  throw new Error(response.message);
73
66
  }
74
67
  }
75
- exports.DataClient = DataClient;
76
- //# sourceMappingURL=dataClient.js.map
@@ -9,4 +9,3 @@ export declare class SyntropixClient {
9
9
  get table(): TableClient;
10
10
  get data(): DataClient;
11
11
  }
12
- //# sourceMappingURL=syntropix.d.ts.map
@@ -1,24 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SyntropixClient = void 0;
4
- const dataClient_1 = require("./dataClient");
5
- const tableClient_1 = require("./tableClient");
6
- class SyntropixClient {
1
+ import { DataClient } from './dataClient';
2
+ import { TableClient } from './tableClient';
3
+ export class SyntropixClient {
4
+ config;
5
+ _tableClient;
6
+ _dataClient;
7
7
  constructor(config) {
8
8
  this.config = config;
9
9
  }
10
10
  get table() {
11
11
  if (!this._tableClient) {
12
- this._tableClient = new tableClient_1.TableClient(this.config);
12
+ this._tableClient = new TableClient(this.config);
13
13
  }
14
14
  return this._tableClient;
15
15
  }
16
16
  get data() {
17
17
  if (!this._dataClient) {
18
- this._dataClient = new dataClient_1.DataClient(this.config);
18
+ this._dataClient = new DataClient(this.config);
19
19
  }
20
20
  return this._dataClient;
21
21
  }
22
22
  }
23
- exports.SyntropixClient = SyntropixClient;
24
- //# sourceMappingURL=syntropix.js.map
@@ -1,10 +1,11 @@
1
+ import { TableCreateResponse } from '@/types/dto/table';
1
2
  import { SyntropixDBTable } from '../types/common';
2
3
  import { TableAddColumn, TableCreate, TableDrop, TableDropColumn, TableGetSchema, TableModifyColumn, TableRename, TableTruncate } from '../types/requests';
3
4
  import { ClientConfig } from './config';
4
5
  export declare class TableClient {
5
6
  private client;
6
7
  constructor(config: ClientConfig);
7
- createTable(data: TableCreate): Promise<any>;
8
+ createTable(data: TableCreate): Promise<TableCreateResponse>;
8
9
  dropTable(data: TableDrop): Promise<any>;
9
10
  renameTable(data: TableRename): Promise<any>;
10
11
  truncateTable(data: TableTruncate): Promise<any>;
@@ -13,4 +14,3 @@ export declare class TableClient {
13
14
  modifyColumn(data: TableModifyColumn): Promise<any>;
14
15
  getTableSchema(data: TableGetSchema): Promise<SyntropixDBTable>;
15
16
  }
16
- //# sourceMappingURL=tableClient.d.ts.map
@@ -1,10 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TableClient = void 0;
4
- const client_1 = require("./client");
5
- class TableClient {
1
+ import { Client } from './client';
2
+ export class TableClient {
3
+ client;
6
4
  constructor(config) {
7
- this.client = new client_1.Client(config);
5
+ this.client = new Client(config);
8
6
  }
9
7
  async createTable(data) {
10
8
  const response = await this.client.post('/table/create', data);
@@ -63,5 +61,3 @@ class TableClient {
63
61
  throw new Error(response.message);
64
62
  }
65
63
  }
66
- exports.TableClient = TableClient;
67
- //# sourceMappingURL=tableClient.js.map
package/dist/index.d.ts CHANGED
@@ -7,4 +7,3 @@ export { DataType } from './types/data-type';
7
7
  export * from './types/field';
8
8
  export * from './types/filter';
9
9
  export * from './types/requests';
10
- //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,34 +1,10 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.DataType = exports.ForeignKey = exports.Column = exports.BaseModel = exports.SyntropixClient = exports.Client = void 0;
18
1
  // Main entry point for the SDK
19
- var client_1 = require("./core/client");
20
- Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
21
- __exportStar(require("./core/config"), exports);
22
- var syntropix_1 = require("./core/syntropix");
23
- Object.defineProperty(exports, "SyntropixClient", { enumerable: true, get: function () { return syntropix_1.SyntropixClient; } });
24
- var basemodel_1 = require("./types/basemodel");
25
- Object.defineProperty(exports, "BaseModel", { enumerable: true, get: function () { return basemodel_1.BaseModel; } });
26
- Object.defineProperty(exports, "Column", { enumerable: true, get: function () { return basemodel_1.Column; } });
27
- Object.defineProperty(exports, "ForeignKey", { enumerable: true, get: function () { return basemodel_1.ForeignKey; } });
28
- __exportStar(require("./types/common"), exports);
29
- var data_type_1 = require("./types/data-type");
30
- Object.defineProperty(exports, "DataType", { enumerable: true, get: function () { return data_type_1.DataType; } });
31
- __exportStar(require("./types/field"), exports);
32
- __exportStar(require("./types/filter"), exports);
33
- __exportStar(require("./types/requests"), exports);
34
- //# sourceMappingURL=index.js.map
2
+ export { Client } from './core/client';
3
+ export * from './core/config';
4
+ export { SyntropixClient } from './core/syntropix';
5
+ export { BaseModel, Column, ForeignKey } from './types/basemodel';
6
+ export * from './types/common';
7
+ export { DataType } from './types/data-type';
8
+ export * from './types/field';
9
+ export * from './types/filter';
10
+ export * from './types/requests';
@@ -1,6 +1,7 @@
1
1
  import 'reflect-metadata';
2
2
  import { SyntropixClient } from '../core/syntropix';
3
3
  import { Aggregate, GroupBy, Index, Join, Sort } from './common';
4
+ import { TableCreateResponse } from './dto/table';
4
5
  import { Field, ForeignKeyField } from './field';
5
6
  import { Filter } from './filter';
6
7
  export declare function Column(options?: {
@@ -37,7 +38,7 @@ export declare class BaseModel {
37
38
  protected getPrimaryKeyName(): string;
38
39
  protected getPrimaryKey(): Field | undefined;
39
40
  protected get client(): SyntropixClient;
40
- static createTable(_client?: SyntropixClient | null): Promise<any>;
41
+ static createTable(_client?: SyntropixClient | null): Promise<TableCreateResponse>;
41
42
  static dropTable(_client?: SyntropixClient | null): Promise<any>;
42
43
  static renameTable(newName: string, _client?: SyntropixClient | null): Promise<any>;
43
44
  static truncateTable(_client?: SyntropixClient | null): Promise<any>;
@@ -68,4 +69,3 @@ export declare class BaseModel {
68
69
  toString(): string;
69
70
  toJSON(): Record<string, any>;
70
71
  }
71
- //# sourceMappingURL=basemodel.d.ts.map
@@ -1,28 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseModel = void 0;
4
- exports.Column = Column;
5
- exports.Description = Description;
6
- exports.ForeignKey = ForeignKey;
7
1
  // BaseModel implementation with decorator support
8
- require("reflect-metadata");
9
- const config_1 = require("../core/config");
10
- const syntropix_1 = require("../core/syntropix");
11
- const common_1 = require("./common");
12
- const field_1 = require("./field");
13
- const filter_1 = require("./filter");
2
+ import 'reflect-metadata';
3
+ import { ClientConfig } from '../core/config';
4
+ import { SyntropixClient } from '../core/syntropix';
5
+ import { AggregateFunction } from './common';
6
+ import { Field, ForeignKeyField, IntegerField } from './field';
7
+ import { AND, EQ, GTE, OR, Value } from './filter';
14
8
  // Metadata keys
15
9
  const FIELDS_KEY = Symbol('fields');
16
10
  const TABLE_NAME_KEY = Symbol('tableName');
17
11
  const DESCRIPTION_KEY = Symbol('description');
18
12
  const INDEXES_KEY = Symbol('indexes');
19
13
  // Column decorator
20
- function Column(options = {}) {
14
+ export function Column(options = {}) {
21
15
  return function (target, propertyKey) {
22
16
  const fields = Reflect.getMetadata(FIELDS_KEY, target.constructor) || {};
23
17
  const fieldName = options.name || propertyKey.toLowerCase();
24
18
  const column_type = options.type || 'Text';
25
- const field = new (class extends field_1.Field {
19
+ const field = new (class extends Field {
26
20
  constructor() {
27
21
  super(column_type, {
28
22
  name: fieldName,
@@ -39,16 +33,16 @@ function Column(options = {}) {
39
33
  };
40
34
  }
41
35
  // Description decorator
42
- function Description(description) {
36
+ export function Description(description) {
43
37
  return function (target) {
44
38
  Reflect.defineMetadata(DESCRIPTION_KEY, description, target);
45
39
  };
46
40
  }
47
41
  // ForeignKey decorator
48
- function ForeignKey(tableName, columnName, options = {}) {
42
+ export function ForeignKey(tableName, columnName, options = {}) {
49
43
  return function (target, propertyKey) {
50
44
  const fields = Reflect.getMetadata(FIELDS_KEY, target.constructor) || {};
51
- const field = new field_1.ForeignKeyField(options.type || 'Integer', tableName, columnName, {
45
+ const field = new ForeignKeyField(options.type || 'Integer', tableName, columnName, {
52
46
  onDelete: options.onDelete,
53
47
  onUpdate: options.onUpdate,
54
48
  description: options.description,
@@ -60,9 +54,10 @@ function ForeignKey(tableName, columnName, options = {}) {
60
54
  Reflect.defineMetadata(FIELDS_KEY, fields, target.constructor);
61
55
  };
62
56
  }
63
- class BaseModel {
57
+ export class BaseModel {
58
+ _client;
59
+ _extra = {};
64
60
  constructor(data = {}) {
65
- this._extra = {};
66
61
  const fields = this.getFields();
67
62
  // Create a mapping from column names to property names
68
63
  const columnToPropertyMap = {};
@@ -121,7 +116,7 @@ class BaseModel {
121
116
  }
122
117
  // If no primary key, add default 'id' field
123
118
  if (!hasPrimaryKey && !('id' in fields)) {
124
- fields['id'] = new field_1.IntegerField({
119
+ fields['id'] = new IntegerField({
125
120
  is_primary_key: true,
126
121
  is_nullable: false,
127
122
  auto_increment: true,
@@ -142,7 +137,7 @@ class BaseModel {
142
137
  }
143
138
  static getAssociations() {
144
139
  const fields = this.getFields();
145
- return Object.values(fields).filter((f) => f instanceof field_1.ForeignKeyField);
140
+ return Object.values(fields).filter((f) => f instanceof ForeignKeyField);
146
141
  }
147
142
  // Instance metadata getters
148
143
  getFields() {
@@ -166,7 +161,7 @@ class BaseModel {
166
161
  // Client getter
167
162
  get client() {
168
163
  if (!this._client) {
169
- this._client = new syntropix_1.SyntropixClient(new config_1.ClientConfig());
164
+ this._client = new SyntropixClient(new ClientConfig());
170
165
  }
171
166
  return this._client;
172
167
  }
@@ -183,7 +178,7 @@ class BaseModel {
183
178
  on_update: f.onUpdate,
184
179
  }));
185
180
  const indexes = this.getIndexes();
186
- const client = _client || new syntropix_1.SyntropixClient(new config_1.ClientConfig());
181
+ const client = _client || new SyntropixClient(new ClientConfig());
187
182
  return client.table.createTable({
188
183
  name: this.getTableName(),
189
184
  description: this.getDescription() || 'No description',
@@ -193,18 +188,18 @@ class BaseModel {
193
188
  });
194
189
  }
195
190
  static async dropTable(_client) {
196
- const client = _client || new syntropix_1.SyntropixClient(new config_1.ClientConfig());
191
+ const client = _client || new SyntropixClient(new ClientConfig());
197
192
  return client.table.dropTable({ name: this.getTableName() });
198
193
  }
199
194
  static async renameTable(newName, _client) {
200
- const client = _client || new syntropix_1.SyntropixClient(new config_1.ClientConfig());
195
+ const client = _client || new SyntropixClient(new ClientConfig());
201
196
  return client.table.renameTable({
202
197
  name: this.getTableName(),
203
198
  new_name: newName,
204
199
  });
205
200
  }
206
201
  static async truncateTable(_client) {
207
- const client = _client || new syntropix_1.SyntropixClient(new config_1.ClientConfig());
202
+ const client = _client || new SyntropixClient(new ClientConfig());
208
203
  return client.table.truncateTable({ name: this.getTableName() });
209
204
  }
210
205
  // Data operations
@@ -222,7 +217,7 @@ class BaseModel {
222
217
  throw new Error(`Invalid field: ${key}`);
223
218
  }
224
219
  }
225
- const client = _client || new syntropix_1.SyntropixClient(new config_1.ClientConfig());
220
+ const client = _client || new SyntropixClient(new ClientConfig());
226
221
  return client.data.insertOne({
227
222
  table_name: model.getTableName(),
228
223
  data: {
@@ -263,7 +258,7 @@ class BaseModel {
263
258
  async remove(filter, _client) {
264
259
  const pk = this.getPrimaryKey();
265
260
  const pkValue = this[this.getPrimaryKeyName()];
266
- const finalFilter = filter || (0, filter_1.OR)((0, filter_1.AND)((0, filter_1.EQ)(pk?.name || 'id', pkValue)));
261
+ const finalFilter = filter || OR(AND(EQ(pk?.name || 'id', pkValue)));
267
262
  return (_client ||
268
263
  this.client.data.deleteData({
269
264
  table_name: this.getTableName(),
@@ -289,7 +284,7 @@ class BaseModel {
289
284
  }
290
285
  }
291
286
  let values = [];
292
- const client = _client || new syntropix_1.SyntropixClient(new config_1.ClientConfig());
287
+ const client = _client || new SyntropixClient(new ClientConfig());
293
288
  for (const data of datas) {
294
289
  if (columnsSet.size !== new Set(Object.keys(data)).size || !columns.every((c) => c in data)) {
295
290
  throw new Error('All data must have the same columns');
@@ -324,7 +319,7 @@ class BaseModel {
324
319
  }
325
320
  }
326
321
  const values = columns.map((c) => data[c]);
327
- const client = _client || new syntropix_1.SyntropixClient(new config_1.ClientConfig());
322
+ const client = _client || new SyntropixClient(new ClientConfig());
328
323
  return client.data.updateData({
329
324
  table_name: model.getTableName(),
330
325
  payload: {
@@ -336,7 +331,7 @@ class BaseModel {
336
331
  }
337
332
  static async delete(filter, _client) {
338
333
  const model = this;
339
- const client = _client || new syntropix_1.SyntropixClient(new config_1.ClientConfig());
334
+ const client = _client || new SyntropixClient(new ClientConfig());
340
335
  return client.data.deleteData({
341
336
  table_name: model.getTableName(),
342
337
  payload: { filter },
@@ -345,7 +340,7 @@ class BaseModel {
345
340
  static async get(filter, select, _client) {
346
341
  const model = this;
347
342
  const fields = model.getFields();
348
- const client = _client || new syntropix_1.SyntropixClient(new config_1.ClientConfig());
343
+ const client = _client || new SyntropixClient(new ClientConfig());
349
344
  const data = await client.data.queryOne({
350
345
  table_name: model.getTableName(),
351
346
  query: {
@@ -358,7 +353,7 @@ class BaseModel {
358
353
  }
359
354
  static async filter(options) {
360
355
  const model = this;
361
- const client = options._client || new syntropix_1.SyntropixClient(new config_1.ClientConfig());
356
+ const client = options._client || new SyntropixClient(new ClientConfig());
362
357
  const data = await client.data.queryMany({
363
358
  table_name: model.getTableName(),
364
359
  query: {
@@ -376,15 +371,15 @@ class BaseModel {
376
371
  }
377
372
  static async count(options = {}) {
378
373
  const model = this;
379
- const client = options._client || new syntropix_1.SyntropixClient(new config_1.ClientConfig());
374
+ const client = options._client || new SyntropixClient(new ClientConfig());
380
375
  const data = await client.data.queryMany({
381
376
  table_name: model.getTableName(),
382
377
  query: {
383
- filter: options.filter || [[(0, filter_1.GTE)('id', (0, filter_1.Value)(0))]],
378
+ filter: options.filter || [[GTE('id', Value(0))]],
384
379
  aggregate: [
385
380
  {
386
381
  column: 'id',
387
- function: common_1.AggregateFunction.COUNT,
382
+ function: AggregateFunction.COUNT,
388
383
  alias: 'count',
389
384
  },
390
385
  ],
@@ -402,7 +397,7 @@ class BaseModel {
402
397
  const data = {};
403
398
  for (const key of Object.keys(fields)) {
404
399
  const value = this[key];
405
- if (!(value instanceof field_1.Field)) {
400
+ if (!(value instanceof Field)) {
406
401
  data[key] = value;
407
402
  }
408
403
  }
@@ -418,5 +413,3 @@ class BaseModel {
418
413
  return { ...data, ...this._extra };
419
414
  }
420
415
  }
421
- exports.BaseModel = BaseModel;
422
- //# sourceMappingURL=basemodel.js.map
@@ -15,7 +15,7 @@ export declare enum AggregateFunction {
15
15
  }
16
16
  export interface Sort {
17
17
  column: string;
18
- order: 'ASC' | 'DESC';
18
+ direction: 'ASCENDING' | 'DESCENDING';
19
19
  }
20
20
  export interface Join {
21
21
  type: 'INNER' | 'LEFT' | 'RIGHT' | 'FULL';
@@ -69,4 +69,3 @@ export interface SyntropixDBTable {
69
69
  created_at: Date;
70
70
  columns: SyntropixDBColumn[];
71
71
  }
72
- //# sourceMappingURL=common.d.ts.map
@@ -1,16 +1,13 @@
1
- "use strict";
2
1
  // Common types used across the SDK
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.AggregateFunction = exports.ForeignKeyAction = void 0;
5
- var ForeignKeyAction;
2
+ export var ForeignKeyAction;
6
3
  (function (ForeignKeyAction) {
7
4
  ForeignKeyAction["CASCADE"] = "Cascade";
8
5
  ForeignKeyAction["RESTRICT"] = "Restrict";
9
6
  ForeignKeyAction["SET_NULL"] = "SetNull";
10
7
  ForeignKeyAction["NO_ACTION"] = "NoAction";
11
8
  ForeignKeyAction["SET_DEFAULT"] = "SetDefault";
12
- })(ForeignKeyAction || (exports.ForeignKeyAction = ForeignKeyAction = {}));
13
- var AggregateFunction;
9
+ })(ForeignKeyAction || (ForeignKeyAction = {}));
10
+ export var AggregateFunction;
14
11
  (function (AggregateFunction) {
15
12
  AggregateFunction["COUNT"] = "Count";
16
13
  AggregateFunction["SUM"] = "Sum";
@@ -18,5 +15,4 @@ var AggregateFunction;
18
15
  AggregateFunction["MIN"] = "Min";
19
16
  AggregateFunction["MAX"] = "Max";
20
17
  AggregateFunction["COUNT_DISTINCT"] = "CountDistinct";
21
- })(AggregateFunction || (exports.AggregateFunction = AggregateFunction = {}));
22
- //# sourceMappingURL=common.js.map
18
+ })(AggregateFunction || (AggregateFunction = {}));
@@ -37,4 +37,3 @@ export declare class DataType {
37
37
  };
38
38
  }
39
39
  export type ColumnType = string | Record<string, any>;
40
- //# sourceMappingURL=data-type.d.ts.map
@@ -1,25 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DataType = void 0;
4
1
  // Data type definitions for database columns
5
- class DataType {
2
+ export class DataType {
3
+ // Basic types
4
+ static Integer = 'Integer';
5
+ static String = (maxLength) => ({ type: 'String', maxLength });
6
+ static Text = 'Text';
7
+ static Boolean = 'Boolean';
8
+ static DateTime = 'DateTime';
9
+ static Timestamp = 'Timestamp';
10
+ static Date = 'Date';
11
+ static Json = 'Json';
12
+ static Uuid = 'Uuid';
13
+ static Double = 'Double';
14
+ // Complex types
15
+ static Vector = (dimensions) => ({ type: 'Vector', dimensions });
16
+ static Array = (dataType) => ({ type: 'Array', dataType });
17
+ static Enum = (name, variants) => ({ type: 'Enum', name, variants });
18
+ static Money = (precision, scale) => ({ type: 'Money', precision, scale });
19
+ static Decimal = (precision, scale) => ({ type: 'Decimal', precision, scale });
6
20
  }
7
- exports.DataType = DataType;
8
- // Basic types
9
- DataType.Integer = 'Integer';
10
- DataType.String = (maxLength) => ({ type: 'String', maxLength });
11
- DataType.Text = 'Text';
12
- DataType.Boolean = 'Boolean';
13
- DataType.DateTime = 'DateTime';
14
- DataType.Timestamp = 'Timestamp';
15
- DataType.Date = 'Date';
16
- DataType.Json = 'Json';
17
- DataType.Uuid = 'Uuid';
18
- DataType.Double = 'Double';
19
- // Complex types
20
- DataType.Vector = (dimensions) => ({ type: 'Vector', dimensions });
21
- DataType.Array = (dataType) => ({ type: 'Array', dataType });
22
- DataType.Enum = (name, variants) => ({ type: 'Enum', name, variants });
23
- DataType.Money = (precision, scale) => ({ type: 'Money', precision, scale });
24
- DataType.Decimal = (precision, scale) => ({ type: 'Decimal', precision, scale });
25
- //# sourceMappingURL=data-type.js.map
@@ -0,0 +1,4 @@
1
+ export interface ApiResponse<T> {
2
+ status: string;
3
+ data: T;
4
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ import { Column, ForeignKey, Index } from '../common';
2
+ export interface TableCreateResponse {
3
+ _id: {
4
+ $oid: string;
5
+ };
6
+ table: {
7
+ id: string;
8
+ name: string;
9
+ description: string;
10
+ created_at: any;
11
+ columns: Column[];
12
+ foreign_keys: ForeignKey[];
13
+ indexes: Index[];
14
+ schema: string;
15
+ default_access: string | null;
16
+ };
17
+ created_at: any;
18
+ updated_at: any;
19
+ created_by: string;
20
+ metadata: Record<string, any>;
21
+ triggers: any[];
22
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -153,4 +153,3 @@ export declare class DoubleField extends Field {
153
153
  default?: number;
154
154
  });
155
155
  }
156
- //# sourceMappingURL=field.d.ts.map