@syntropix/database 0.0.4 → 0.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syntropix/database",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "description": "TypeScript SDK for database operations with ORM support",
6
6
  "main": "dist/index.js",
@@ -10,11 +10,14 @@
10
10
  "access": "public",
11
11
  "registry": "https://registry.npmjs.org/"
12
12
  },
13
+ "files": [
14
+ "dist"
15
+ ],
13
16
  "scripts": {
14
17
  "build": "tsc",
15
18
  "dev": "tsc --watch",
16
19
  "test": "node --experimental-vm-modules $(yarn bin jest)",
17
- "publish": "npm publish --access public",
20
+ "release": "yarn install && yarn build && npm publish --access public",
18
21
  "example": "tsx --tsconfig examples/tsconfig.json examples/usage.ts",
19
22
  "lint": "eslint",
20
23
  "lint:fix": "eslint --fix",
package/.editorconfig DELETED
@@ -1,8 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- charset = utf-8
5
- end_of_line = lf
6
- indent_size = 2
7
- indent_style = space
8
- insert_final_newline = true
package/.env DELETED
@@ -1,2 +0,0 @@
1
- SYNTROPIX_API_KEY = "MrxxQ9nzk9LNSHMTBLGP1YpTVr+sT+sldRYASP0r/v7qPB16Qaksv3GU3ns/viLTyHDVgh1dN1ihtns+GXPu8pR4CjUuqpjXaowI5glQt2VbDXdScRQOkBs4YfJ9HBCts+Ri/32QYeOIjtWYWh52+349zi34rA91btmDw/0yzSv4mG9esygDm2zCSSvSEh/XZY1VhC+97/gxXwKOEVwINI2Twd/DOV3zvmQxfY733Ono1+2qWbLMLY/0rEKDx16eyRlud1PwauZXKzA1VdVpxC6O1RLwVXkfS7LNkr5QxhaWPdQWcbeJ9fPboFFbGNzICs5hBTEBDGnqbSnqwD6CfsqqgVpl5YM1DGzQyfvjb88="
2
- SYNTROPIX_API_URL = "http://149.248.14.64:8080"
package/.gitattributes DELETED
@@ -1,4 +0,0 @@
1
- /.yarn/** linguist-vendored
2
- /.yarn/releases/* binary
3
- /.yarn/plugins/**/* binary
4
- /.pnp.* binary linguist-generated
package/.husky/pre-commit DELETED
@@ -1 +0,0 @@
1
- yarn lint-staged
package/.prettierrc DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "tabWidth": 2,
3
- "useTabs": false,
4
- "singleQuote": true,
5
- "trailingComma": "all",
6
- "printWidth": 120,
7
- "plugins": ["prettier-plugin-tailwindcss", "prettier-plugin-organize-imports"]
8
- }
@@ -1 +0,0 @@
1
- {}
package/.yarnrc.yml DELETED
@@ -1 +0,0 @@
1
- nodeLinker: node-modules
package/eslint.config.mjs DELETED
@@ -1,23 +0,0 @@
1
- import eslint from '@eslint/js';
2
- import { defineConfig, globalIgnores } from 'eslint/config';
3
- import tseslint from 'typescript-eslint';
4
-
5
- export default defineConfig([
6
- globalIgnores(['dist/**', 'node_modules/**', 'examples/**', 'tests/**', 'jest.config.ts']),
7
- eslint.configs.recommended,
8
- ...tseslint.configs.recommended,
9
- {
10
- files: ['**/*.ts', '**/*.tsx'],
11
- languageOptions: {
12
- parser: tseslint.parser,
13
- parserOptions: {
14
- project: './tsconfig.json',
15
- },
16
- },
17
- rules: {
18
- 'no-unused-vars': 'off',
19
- '@typescript-eslint/no-unused-vars': 'off',
20
- '@typescript-eslint/no-explicit-any': 'off',
21
- },
22
- },
23
- ]);
@@ -1,214 +0,0 @@
1
- import 'dotenv/config';
2
- import { ClientConfig } from '../src/core/config';
3
- import { SyntropixClient } from '../src/core/syntropix';
4
- import { BaseModel, Column, ForeignKey } from '../src/types/basemodel';
5
- import { AND, GTE, OR } from '../src/types/filter';
6
-
7
- export class CompanyGroup extends BaseModel {
8
- static tableName = 'syntropix_company_groups';
9
- static description = 'Company groups';
10
-
11
- @Column({
12
- type: 'Integer',
13
- primary: true,
14
- auto_increment: true,
15
- description: 'Group ID',
16
- })
17
- id!: number;
18
-
19
- @Column({ type: { String: 256 }, description: 'Group Name' })
20
- name!: string;
21
-
22
- @Column({ type: 'Text', description: 'Group Description' })
23
- description!: string;
24
- }
25
-
26
- export class CompanyGroupMember extends BaseModel {
27
- static tableName = 'syntropix_company_group_members';
28
- static description = 'Company group members';
29
-
30
- @Column({
31
- type: 'Integer',
32
- primary: true,
33
- auto_increment: true,
34
- description: 'Member ID',
35
- })
36
- id!: number;
37
-
38
- @ForeignKey('syntropix_company_groups', 'id', { description: 'Group ID' })
39
- groupId!: number;
40
-
41
- @ForeignKey('syntropix_company_members', 'id', { description: 'Member ID' })
42
- memberId!: number;
43
- }
44
-
45
- export class CompanyMember extends BaseModel {
46
- static tableName = 'syntropix_company_members';
47
- static description = 'Company members';
48
-
49
- @Column({
50
- type: 'Integer',
51
- primary: true,
52
- auto_increment: true,
53
- description: 'Member ID',
54
- })
55
- id!: number;
56
-
57
- @Column({
58
- type: { String: 256 },
59
- description: 'User id in mongodb',
60
- nullable: false,
61
- name: 'user_id',
62
- })
63
- userId!: string;
64
-
65
- @Column({
66
- type: { String: 256 },
67
- description: 'First Name',
68
- nullable: false,
69
- name: 'first_name',
70
- })
71
- firstName!: string;
72
- @Column({
73
- type: { String: 256 },
74
- description: 'Last Name',
75
- nullable: false,
76
- name: 'last_name',
77
- })
78
- lastName!: string;
79
- @Column({
80
- type: { String: 256 },
81
- description: 'Middle Name',
82
- nullable: true,
83
- name: 'middle_name',
84
- })
85
- middleName!: string | null;
86
- @Column({
87
- type: { String: 256 },
88
- description: 'Email',
89
- nullable: false,
90
- name: 'email',
91
- })
92
- email!: string;
93
- @Column({
94
- type: { String: 256 },
95
- description: 'Avatar',
96
- nullable: true,
97
- name: 'avatar',
98
- })
99
- avatar!: string | null;
100
- @Column({ type: 'Text', description: 'Bio', nullable: true, name: 'bio' })
101
- bio!: string;
102
- @Column({
103
- type: { String: 32 },
104
- description: 'Role',
105
- nullable: false,
106
- name: 'role',
107
- })
108
- role!: 'admin' | 'user';
109
- @Column({
110
- type: { String: 256 },
111
- description: 'Personal Key',
112
- nullable: false,
113
- name: 'personal_key',
114
- })
115
- personalKey!: string;
116
- }
117
-
118
- export class CompanyApiKey extends BaseModel {
119
- static tableName = 'syntropix_company_api_keys';
120
- static description = 'Company API keys';
121
-
122
- @Column({
123
- type: 'Integer',
124
- primary: true,
125
- auto_increment: true,
126
- description: 'API Key ID',
127
- })
128
- id!: number;
129
- @Column({
130
- type: { String: 256 },
131
- description: 'Name',
132
- nullable: false,
133
- name: 'name',
134
- })
135
- name!: string;
136
- @Column({
137
- type: 'Text',
138
- description: 'Description',
139
- nullable: true,
140
- name: 'description',
141
- })
142
- description!: string | null;
143
- @Column({
144
- type: { String: 256 },
145
- description: 'Key',
146
- nullable: false,
147
- name: 'key',
148
- })
149
- key!: string;
150
- @Column({
151
- type: 'DateTime',
152
- description: 'Created At',
153
- nullable: false,
154
- name: 'created_at',
155
- })
156
- createdAt!: Date | string;
157
-
158
- @Column({
159
- type: 'Boolean',
160
- description: 'Is Personal',
161
- nullable: false,
162
- name: 'is_personal',
163
- })
164
- isPersonal!: boolean;
165
-
166
- @ForeignKey('syntropix_company_members', 'id', { description: 'Created By', name: 'created_by' })
167
- createdBy!: number;
168
- }
169
-
170
- // Example usage
171
- async function examples() {
172
- const _client = new SyntropixClient(new ClientConfig());
173
- console.log(CompanyApiKey.getDescription());
174
- const member = await CompanyMember.filter({
175
- filter: OR(AND(GTE('id', 0))),
176
- });
177
- console.log(member);
178
- // await CompanyMember.dropTable(_client);
179
- // await CompanyApiKey.dropTable(_client);
180
- // await CompanyMember.createTable(_client);
181
- // await CompanyGroup.createTable(_client);
182
- // await CompanyApiKey.createTable(_client);
183
- // await CompanyGroupMember.createTable(_client);
184
-
185
- // await CompanyMember.create(
186
- // {
187
- // userId: "1234567890",
188
- // firstName: "John",
189
- // lastName: "Doe",
190
- // middleName: "Doe",
191
- // email: "john.doe@example.com",
192
- // avatar: "https://example.com/avatar.png",
193
- // bio: "",
194
- // role: "admin",
195
- // personalKey: "1234567890",
196
- // },
197
- // _client
198
- // );
199
-
200
- // await CompanyApiKey.create(
201
- // {
202
- // name: "Admin API Key for John Doe",
203
- // description: "Admin API Key for John Doe",
204
- // key: "1234567890",
205
- // createdAt: new Date(),
206
- // createdBy: 1,
207
- // isPersonal: true,
208
- // },
209
- // _client
210
- // );
211
- }
212
-
213
- // Run examples
214
- examples().catch(console.error);
@@ -1,13 +0,0 @@
1
- // This file is used to let VSCode respect the tsconfig.json for this test folder
2
- {
3
- "extends": "../tsconfig.json",
4
- "include": [".", "../src"],
5
- "compilerOptions": {
6
- "noEmit": true,
7
- "baseUrl": ".",
8
- "paths": {
9
- "@syntropix/database": ["../src/index.ts"],
10
- "@syntropix/database/*": ["../src/*"]
11
- }
12
- }
13
- }
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
- }