@syntropix/database 0.0.4 → 0.0.6

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 (49) hide show
  1. package/dist/core/dataClient.js +3 -0
  2. package/dist/core/syntropix.d.ts +1 -1
  3. package/dist/core/syntropix.js +2 -1
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/types/basemodel.d.ts +4 -3
  7. package/dist/types/basemodel.js +36 -35
  8. package/dist/types/common.d.ts +32 -28
  9. package/dist/types/common.js +11 -12
  10. package/dist/types/data-type.d.ts +48 -38
  11. package/dist/types/data-type.js +17 -18
  12. package/dist/types/dto/table.d.ts +6 -6
  13. package/dist/types/field.d.ts +60 -41
  14. package/dist/types/field.js +35 -32
  15. package/dist/types/filter.d.ts +43 -44
  16. package/dist/types/filter.js +56 -41
  17. package/dist/types/requests.d.ts +25 -14
  18. package/dist/types/requests.js +6 -1
  19. package/package.json +5 -2
  20. package/.editorconfig +0 -8
  21. package/.env +0 -2
  22. package/.gitattributes +0 -4
  23. package/.husky/pre-commit +0 -1
  24. package/.prettierrc +0 -8
  25. package/.vscode/settings.json +0 -1
  26. package/.yarnrc.yml +0 -1
  27. package/eslint.config.mjs +0 -23
  28. package/examples/advanced-usage.ts +0 -214
  29. package/examples/tsconfig.json +0 -13
  30. package/examples/usage.ts +0 -94
  31. package/jest.config.ts +0 -9
  32. package/src/core/client.ts +0 -41
  33. package/src/core/config.ts +0 -29
  34. package/src/core/dataClient.ts +0 -78
  35. package/src/core/syntropix.ts +0 -27
  36. package/src/core/tableClient.ts +0 -86
  37. package/src/index.ts +0 -10
  38. package/src/types/basemodel.ts +0 -558
  39. package/src/types/common.ts +0 -83
  40. package/src/types/data-type.ts +0 -23
  41. package/src/types/dto/base.ts +0 -4
  42. package/src/types/dto/table.ts +0 -21
  43. package/src/types/field.ts +0 -277
  44. package/src/types/filter.ts +0 -281
  45. package/src/types/requests.ts +0 -91
  46. package/test.json +0 -48
  47. package/tests/basic.test.ts +0 -141
  48. package/tests/tsconfig.json +0 -8
  49. package/tsconfig.json +0 -18
package/examples/usage.ts DELETED
@@ -1,94 +0,0 @@
1
- import { AND, BaseModel, Column, EQ, IN, OR } from '@syntropix/database';
2
- import { DataClient } from '@syntropix/database/core/dataClient';
3
- import { TableClient } from '@syntropix/database/core/tableClient';
4
- import 'dotenv/config';
5
-
6
- class User extends BaseModel {
7
- static tableName = 'users';
8
-
9
- @Column({ type: 'Integer', primary: true, auto_increment: true })
10
- declare id: number;
11
-
12
- @Column()
13
- declare email: string;
14
-
15
- @Column({ name: 'full_name' })
16
- declare fullName: string;
17
-
18
- @Column({ type: 'Json', nullable: true })
19
- declare profile: any;
20
-
21
- @Column({ type: 'Boolean', name: 'is_active' })
22
- declare isActive: boolean;
23
- }
24
-
25
- async function ORMExample() {
26
- // Create table
27
- // await User.createTable();
28
-
29
- // Create a new user
30
- // const newUser = await User.create({
31
- // id: 1,
32
- // email: 'user@example.com',
33
- // fullName: 'John Doe',
34
- // isActive: true,
35
- // });
36
- // console.log(newUser);
37
-
38
- // // Get a user
39
- // const user = await User.get(OR(AND(EQ('email', 'user@example.com'))));
40
- // console.log(user);
41
-
42
- // // Update user
43
- // user.fullName = 'Jane Doe1';
44
- // await user.save();
45
-
46
- // Filter users
47
- const activeUsers = await User.filter({
48
- filter: OR(AND(IN('email', ['user@example.com', 'user3@example.com']))),
49
- limit: 10,
50
- });
51
-
52
- console.log(activeUsers);
53
-
54
- // // // Count users
55
- // const userCount = await User.count({
56
- // filter: OR(AND(EQ('is_active', true))),
57
- // });
58
- // console.log(activeUsers);
59
- // console.log(userCount);
60
- // // // Delete user
61
- // await user.remove();
62
-
63
- // // // Bulk create
64
- // await User.bulkCreate([
65
- // {
66
- // id: 2,
67
- // email: 'user2@example.com',
68
- // fullName: 'User 2',
69
- // isActive: true,
70
- // },
71
- // {
72
- // id: 3,
73
- // email: 'user3@example.com',
74
- // fullName: 'User 3',
75
- // isActive: false,
76
- // },
77
- // ]);
78
- }
79
-
80
- async function ClientExample() {
81
- const tableClient = new TableClient();
82
- const dataClient = new DataClient();
83
- const data = await dataClient.queryMany({
84
- table_name: 'users',
85
- query: {
86
- filter: OR(AND(EQ('is_active', true))),
87
- },
88
- });
89
- console.log(data);
90
- }
91
-
92
- // Run examples
93
- ORMExample().catch(console.error);
94
- // ClientExample().catch(console.error);
package/jest.config.ts DELETED
@@ -1,9 +0,0 @@
1
- import type { Config } from 'jest';
2
- import { createDefaultEsmPreset, pathsToModuleNameMapper } from 'ts-jest';
3
-
4
- const presetConfig = createDefaultEsmPreset({});
5
-
6
- export default {
7
- ...presetConfig,
8
- moduleNameMapper: pathsToModuleNameMapper({ '@/*': ['src/*'] }, { prefix: '<rootDir>/' }),
9
- } satisfies Config;
@@ -1,41 +0,0 @@
1
- import { ClientConfig } from './config';
2
-
3
- export class Client {
4
- protected config: ClientConfig;
5
-
6
- constructor(config: ClientConfig) {
7
- this.config = config;
8
- }
9
-
10
- private headers() {
11
- return {
12
- 'Content-Type': 'application/json',
13
- Authorization: this.config.apiKey || '',
14
- };
15
- }
16
-
17
- private url(path: string) {
18
- if (path.startsWith('/')) {
19
- path = path.slice(1);
20
- }
21
- return `${this.config.baseUrl}${path}`;
22
- }
23
-
24
- public async get(path: string, data: Record<string, any> = {}): Promise<Record<string, any>> {
25
- const response = await fetch(this.url(path), {
26
- method: 'GET',
27
- headers: this.headers(),
28
- body: JSON.stringify(data),
29
- });
30
- return response.json();
31
- }
32
-
33
- public async post(path: string, data: Record<string, any> = {}): Promise<Record<string, any>> {
34
- const response = await fetch(this.url(path), {
35
- method: 'POST',
36
- headers: this.headers(),
37
- body: JSON.stringify(data),
38
- });
39
- return response.json();
40
- }
41
- }
@@ -1,29 +0,0 @@
1
- export class ClientConfig {
2
- public apiKey?: string;
3
- public baseUrl?: string;
4
- public timeout?: number;
5
- public retries?: number;
6
-
7
- constructor(config?: any) {
8
- this.apiKey = config?.apiKey || process.env.SYNTROPIX_API_KEY;
9
- this.baseUrl = config?.baseUrl || process.env.SYNTROPIX_API_URL;
10
- this.timeout = config?.timeout || process.env.SYNTROPIX_API_TIMEOUT;
11
- this.retries = config?.retries || process.env.SYNTROPIX_API_RETRIES;
12
-
13
- if (!this.apiKey || !this.baseUrl) {
14
- throw new Error('API key and base URL are required');
15
- }
16
-
17
- if (!this.timeout) {
18
- this.timeout = 10000;
19
- }
20
-
21
- if (!this.retries) {
22
- this.retries = 3;
23
- }
24
-
25
- if (!this.baseUrl.endsWith('/')) {
26
- this.baseUrl += '/';
27
- }
28
- }
29
- }
@@ -1,78 +0,0 @@
1
- import { DeleteData, Insert, Query, Update } from '../types/requests';
2
- import { Client } from './client';
3
- import { ClientConfig } from './config';
4
-
5
- export class DataClient {
6
- private client: Client;
7
-
8
- constructor(config: ClientConfig = new ClientConfig()) {
9
- this.client = new Client(config);
10
- }
11
-
12
- async insertData(data: Insert): Promise<any> {
13
- const response = await this.client.post('/insert', data);
14
- if (response.status === 'success') {
15
- return response.data;
16
- }
17
- throw new Error(response.message);
18
- }
19
-
20
- async insertOne(data: Insert): Promise<any> {
21
- const response = await this.client.post('/insert/one', data);
22
- if (response.status === 'success') {
23
- return response.data;
24
- }
25
- throw new Error(response.message);
26
- }
27
-
28
- async updateByPrimaryKey(pk: string, data: Update): Promise<any> {
29
- const response = await this.client.post(`/update/${pk}`, data);
30
- if (response.status === 'success') {
31
- return response.data;
32
- }
33
- throw new Error(response.message);
34
- }
35
-
36
- async queryOne(data: Query, model?: any): Promise<any> {
37
- const response = await this.client.post('/query', { One: data });
38
- if (response.status === 'success') {
39
- const responseData = response.data;
40
- if (model !== undefined) {
41
- return new model(responseData);
42
- }
43
- return responseData;
44
- }
45
- throw new Error(response.message);
46
- }
47
-
48
- async queryMany(data: Query, model?: any): Promise<any> {
49
- const response = await this.client.post('/query', { Many: data });
50
- if (response.status === 'success') {
51
- const responseData = response.data;
52
- if (model !== undefined) {
53
- // In TypeScript, we would typically use a validation library or manual validation
54
- // For now, we'll return the data as-is, but in a real implementation you might want to use
55
- // a library like class-validator or zod for validation
56
- return responseData.map((item: any) => new model(item));
57
- }
58
- return responseData;
59
- }
60
- throw new Error(response.message);
61
- }
62
-
63
- async updateData(data: Update): Promise<any> {
64
- const response = await this.client.post('/update', data);
65
- if (response.status === 'success') {
66
- return response.data;
67
- }
68
- throw new Error(response.message);
69
- }
70
-
71
- async deleteData(data: DeleteData): Promise<any> {
72
- const response = await this.client.post('/delete', data);
73
- if (response.status === 'success') {
74
- return response.data;
75
- }
76
- throw new Error(response.message);
77
- }
78
- }
@@ -1,27 +0,0 @@
1
- import { ClientConfig } from './config';
2
- import { DataClient } from './dataClient';
3
- import { TableClient } from './tableClient';
4
-
5
- export class SyntropixClient {
6
- private config: ClientConfig;
7
- private _tableClient?: TableClient;
8
- private _dataClient?: DataClient;
9
-
10
- constructor(config: ClientConfig) {
11
- this.config = config;
12
- }
13
-
14
- get table(): TableClient {
15
- if (!this._tableClient) {
16
- this._tableClient = new TableClient(this.config);
17
- }
18
- return this._tableClient;
19
- }
20
-
21
- get data(): DataClient {
22
- if (!this._dataClient) {
23
- this._dataClient = new DataClient(this.config);
24
- }
25
- return this._dataClient;
26
- }
27
- }
@@ -1,86 +0,0 @@
1
- import { TableCreateResponse } from '@/types/dto/table';
2
- import { SyntropixDBTable } from '../types/common';
3
- import {
4
- TableAddColumn,
5
- TableCreate,
6
- TableDrop,
7
- TableDropColumn,
8
- TableGetSchema,
9
- TableModifyColumn,
10
- TableRename,
11
- TableTruncate,
12
- } from '../types/requests';
13
- import { Client } from './client';
14
- import { ClientConfig } from './config';
15
-
16
- export class TableClient {
17
- private client: Client;
18
-
19
- constructor(config: ClientConfig = new ClientConfig()) {
20
- this.client = new Client(config);
21
- }
22
-
23
- async createTable(data: TableCreate): Promise<TableCreateResponse> {
24
- const response = await this.client.post('/table/create', data);
25
- if (response.status === 'success') {
26
- return response.data;
27
- }
28
- throw new Error(response.message);
29
- }
30
-
31
- async dropTable(data: TableDrop): Promise<any> {
32
- const response = await this.client.post('/table/drop', data);
33
- if (response.status === 'success') {
34
- return response.data;
35
- }
36
- throw new Error(response.message);
37
- }
38
-
39
- async renameTable(data: TableRename): Promise<any> {
40
- const response = await this.client.post('/table/rename', data);
41
- if (response.status === 'success') {
42
- return response.data;
43
- }
44
- throw new Error(response.message);
45
- }
46
-
47
- async truncateTable(data: TableTruncate): Promise<any> {
48
- const response = await this.client.post('/table/truncate', data);
49
- if (response.status === 'success') {
50
- return response.data;
51
- }
52
- throw new Error(response.message);
53
- }
54
-
55
- async addColumn(data: TableAddColumn): Promise<any> {
56
- const response = await this.client.post('/table/column/add', data);
57
- if (response.status === 'success') {
58
- return response.data;
59
- }
60
- throw new Error(response.message);
61
- }
62
-
63
- async dropColumn(data: TableDropColumn): Promise<any> {
64
- const response = await this.client.post('/table/column/drop', data);
65
- if (response.status === 'success') {
66
- return response.data;
67
- }
68
- throw new Error(response.message);
69
- }
70
-
71
- async modifyColumn(data: TableModifyColumn): Promise<any> {
72
- const response = await this.client.post('/table/column/modify', data);
73
- if (response.status === 'success') {
74
- return response.data;
75
- }
76
- throw new Error(response.message);
77
- }
78
-
79
- async getTableSchema(data: TableGetSchema): Promise<SyntropixDBTable> {
80
- const response = await this.client.post('/table/schema', data);
81
- if (response.status === 'success') {
82
- return response.data as SyntropixDBTable;
83
- }
84
- throw new Error(response.message);
85
- }
86
- }
package/src/index.ts DELETED
@@ -1,10 +0,0 @@
1
- // Main entry point for the SDK
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';