@syntropix/database 0.0.2 → 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.
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
+ {}
@@ -19,8 +19,6 @@ export class DataClient {
19
19
  throw new Error(response.message);
20
20
  }
21
21
  async updateByPrimaryKey(pk, data) {
22
- console.log(pk);
23
- console.log(data);
24
22
  const response = await this.client.post(`/update/${pk}`, data);
25
23
  if (response.status === 'success') {
26
24
  return response.data;
@@ -32,9 +30,6 @@ export class DataClient {
32
30
  if (response.status === 'success') {
33
31
  const responseData = response.data;
34
32
  if (model !== undefined) {
35
- // In TypeScript, we would typically use a validation library or manual validation
36
- // For now, we'll return the data as-is, but in a real implementation you might want to use
37
- // a library like class-validator or zod for validation
38
33
  return new model(responseData);
39
34
  }
40
35
  return responseData;
@@ -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>;
@@ -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>;
@@ -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 {};
package/eslint.config.mjs CHANGED
@@ -1,23 +1,23 @@
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/**']),
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
+ 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
+ ]);
@@ -0,0 +1,13 @@
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 CHANGED
@@ -1,73 +1,94 @@
1
- // Example usage of the BaseModel ORM
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';
2
4
  import 'dotenv/config';
3
- import { BaseModel, Column } from '../dist/types/basemodel.js';
4
- import { AND, EQ, OR } from '../dist/types/filter.js';
5
5
 
6
- // User model extending Audited
7
- export class User extends BaseModel {
6
+ class User extends BaseModel {
8
7
  static tableName = 'users';
9
8
 
10
- @Column({ type: 'Integer', primary: true, auto_increment: true }) id!: number;
11
- @Column() email!: string;
12
- @Column({ name: 'full_name' }) fullName!: string;
13
- @Column({ type: 'Json', nullable: true }) profile?: any;
14
- @Column({ type: 'Boolean', name: 'is_active' }) isActive!: boolean;
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;
15
23
  }
16
24
 
17
- // Example usage
18
- async function examples() {
25
+ async function ORMExample() {
19
26
  // Create table
20
- await User.createTable();
27
+ // await User.createTable();
21
28
 
22
29
  // Create a new user
23
- const newUser = await User.create({
24
- id: 1,
25
- email: 'user@example.com',
26
- fullName: 'John Doe',
27
- isActive: true,
28
- });
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);
29
37
 
30
- // Get a user
31
- const user = await User.get(OR(AND(EQ('email', 'user@example.com'))));
32
- console.log(user);
38
+ // // Get a user
39
+ // const user = await User.get(OR(AND(EQ('email', 'user@example.com'))));
40
+ // console.log(user);
33
41
 
34
- // Update user
35
- user.fullName = 'Jane Doe1';
36
- await user.save();
42
+ // // Update user
43
+ // user.fullName = 'Jane Doe1';
44
+ // await user.save();
37
45
 
38
- // // Filter users
46
+ // Filter users
39
47
  const activeUsers = await User.filter({
40
- filter: OR(AND(EQ('is_active', true))),
48
+ filter: OR(AND(IN('email', ['user@example.com', 'user3@example.com']))),
41
49
  limit: 10,
42
50
  });
43
51
 
44
- // // Count users
45
- const userCount = await User.count({
46
- filter: OR(AND(EQ('is_active', true))),
47
- });
48
52
  console.log(activeUsers);
49
- console.log(userCount);
50
- // // Delete user
51
- await user.remove();
52
-
53
- // // Bulk create
54
- await User.bulkCreate([
55
- {
56
- id: 2,
57
- email: 'user2@example.com',
58
- fullName: 'User 2',
59
- isActive: true,
60
- },
61
- {
62
- id: 3,
63
- email: 'user3@example.com',
64
- fullName: 'User 3',
65
- isActive: false,
66
- },
67
- ]);
68
53
 
69
- // console.log('All operations completed successfully!');
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);
70
90
  }
71
91
 
72
92
  // Run examples
73
- examples().catch(console.error);
93
+ ORMExample().catch(console.error);
94
+ // ClientExample().catch(console.error);
package/jest.config.ts CHANGED
@@ -1,10 +1,9 @@
1
- import type { Config } from 'jest';
2
- import { createDefaultEsmPreset } from 'ts-jest';
3
-
4
- const presetConfig = createDefaultEsmPreset({
5
- tsconfig: 'tsconfig.test.json',
6
- });
7
-
8
- export default {
9
- ...presetConfig,
10
- } satisfies Config;
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syntropix/database",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "description": "TypeScript SDK for database operations with ORM support",
6
6
  "main": "dist/index.js",
@@ -14,8 +14,8 @@
14
14
  "build": "tsc",
15
15
  "dev": "tsc --watch",
16
16
  "test": "node --experimental-vm-modules $(yarn bin jest)",
17
- "example": "ts-node examples/usage.ts",
18
- "advanced": "ts-node examples/advanced-usage.ts",
17
+ "publish": "npm publish --access public",
18
+ "example": "tsx --tsconfig examples/tsconfig.json examples/usage.ts",
19
19
  "lint": "eslint",
20
20
  "lint:fix": "eslint --fix",
21
21
  "format": "prettier --write .",
@@ -27,7 +27,7 @@
27
27
  "typescript",
28
28
  "sdk"
29
29
  ],
30
- "author": "Syntropix",
30
+ "author": "Syntropix, Inc.",
31
31
  "license": "MIT",
32
32
  "dependencies": {
33
33
  "dotenv": "^17.2.3",
@@ -5,7 +5,7 @@ import { ClientConfig } from './config';
5
5
  export class DataClient {
6
6
  private client: Client;
7
7
 
8
- constructor(config: ClientConfig) {
8
+ constructor(config: ClientConfig = new ClientConfig()) {
9
9
  this.client = new Client(config);
10
10
  }
11
11
 
@@ -26,8 +26,6 @@ export class DataClient {
26
26
  }
27
27
 
28
28
  async updateByPrimaryKey(pk: string, data: Update): Promise<any> {
29
- console.log(pk);
30
- console.log(data);
31
29
  const response = await this.client.post(`/update/${pk}`, data);
32
30
  if (response.status === 'success') {
33
31
  return response.data;
@@ -40,9 +38,6 @@ export class DataClient {
40
38
  if (response.status === 'success') {
41
39
  const responseData = response.data;
42
40
  if (model !== undefined) {
43
- // In TypeScript, we would typically use a validation library or manual validation
44
- // For now, we'll return the data as-is, but in a real implementation you might want to use
45
- // a library like class-validator or zod for validation
46
41
  return new model(responseData);
47
42
  }
48
43
  return responseData;
@@ -1,3 +1,4 @@
1
+ import { TableCreateResponse } from '@/types/dto/table';
1
2
  import { SyntropixDBTable } from '../types/common';
2
3
  import {
3
4
  TableAddColumn,
@@ -15,11 +16,11 @@ import { ClientConfig } from './config';
15
16
  export class TableClient {
16
17
  private client: Client;
17
18
 
18
- constructor(config: ClientConfig) {
19
+ constructor(config: ClientConfig = new ClientConfig()) {
19
20
  this.client = new Client(config);
20
21
  }
21
22
 
22
- async createTable(data: TableCreate): Promise<any> {
23
+ async createTable(data: TableCreate): Promise<TableCreateResponse> {
23
24
  const response = await this.client.post('/table/create', data);
24
25
  if (response.status === 'success') {
25
26
  return response.data;
@@ -3,6 +3,7 @@ import 'reflect-metadata';
3
3
  import { ClientConfig } from '../core/config';
4
4
  import { SyntropixClient } from '../core/syntropix';
5
5
  import { Aggregate, AggregateFunction, ForeignKey, GroupBy, Index, Join, Sort } from './common';
6
+ import { TableCreateResponse } from './dto/table';
6
7
  import { Field, ForeignKeyField, IntegerField } from './field';
7
8
  import { AND, EQ, Filter, GTE, OR, Value } from './filter';
8
9
 
@@ -218,7 +219,7 @@ export class BaseModel {
218
219
  }
219
220
 
220
221
  // Table operations
221
- static async createTable(_client?: SyntropixClient | null): Promise<any> {
222
+ static async createTable(_client?: SyntropixClient | null): Promise<TableCreateResponse> {
222
223
  const fields = this.getFields();
223
224
  const columns = Object.values(fields).map((f) => f.into());
224
225
  const foreignKeys: ForeignKey[] = this.getAssociations().map((f) => ({
@@ -465,7 +466,7 @@ export class BaseModel {
465
466
  this: new (data?: any) => T,
466
467
  options: {
467
468
  filter: Filter;
468
- sort?: Sort;
469
+ sort?: Sort[];
469
470
  aggregate?: Aggregate[];
470
471
  join?: Join;
471
472
  limit?: number;
@@ -1,83 +1,83 @@
1
- // Common types used across the SDK
2
-
3
- export enum ForeignKeyAction {
4
- CASCADE = 'Cascade',
5
- RESTRICT = 'Restrict',
6
- SET_NULL = 'SetNull',
7
- NO_ACTION = 'NoAction',
8
- SET_DEFAULT = 'SetDefault',
9
- }
10
-
11
- export enum AggregateFunction {
12
- COUNT = 'Count',
13
- SUM = 'Sum',
14
- AVG = 'AVG',
15
- MIN = 'Min',
16
- MAX = 'Max',
17
- COUNT_DISTINCT = 'CountDistinct',
18
- }
19
-
20
- export interface Sort {
21
- column: string;
22
- direction: 'ASCENDING' | 'DESCENDING';
23
- }
24
-
25
- export interface Join {
26
- type: 'INNER' | 'LEFT' | 'RIGHT' | 'FULL';
27
- table: string;
28
- on: any;
29
- }
30
-
31
- export interface Aggregate {
32
- column: string;
33
- function: AggregateFunction;
34
- alias: string;
35
- }
36
-
37
- export interface GroupBy {
38
- columns: string[];
39
- }
40
-
41
- export interface ForeignKey {
42
- from_table: string;
43
- from_column: string;
44
- to_table: string;
45
- to_column: string;
46
- on_delete?: ForeignKeyAction;
47
- on_update?: ForeignKeyAction;
48
- }
49
-
50
- export interface Column {
51
- name: string;
52
- column_type: string | Record<string, any>;
53
- description?: string;
54
- is_primary_key?: boolean;
55
- is_nullable?: boolean;
56
- auto_increment?: boolean;
57
- default?: any;
58
- }
59
-
60
- export interface Index {
61
- name: string;
62
- columns: string[];
63
- unique?: boolean;
64
- }
65
-
66
- export interface SyntropixDBColumn {
67
- id: string; // UUID as string in TypeScript
68
- name: string;
69
- description: string;
70
- column_type: string | Record<string, any>;
71
- is_nullable: boolean;
72
- is_primary_key: boolean;
73
- auto_increment: boolean;
74
- default?: any; // Optional field
75
- }
76
-
77
- export interface SyntropixDBTable {
78
- id: string; // UUID as string in TypeScript
79
- name: string;
80
- description: string;
81
- created_at: Date;
82
- columns: SyntropixDBColumn[];
83
- }
1
+ // Common types used across the SDK
2
+
3
+ export enum ForeignKeyAction {
4
+ CASCADE = 'Cascade',
5
+ RESTRICT = 'Restrict',
6
+ SET_NULL = 'SetNull',
7
+ NO_ACTION = 'NoAction',
8
+ SET_DEFAULT = 'SetDefault',
9
+ }
10
+
11
+ export enum AggregateFunction {
12
+ COUNT = 'Count',
13
+ SUM = 'Sum',
14
+ AVG = 'AVG',
15
+ MIN = 'Min',
16
+ MAX = 'Max',
17
+ COUNT_DISTINCT = 'CountDistinct',
18
+ }
19
+
20
+ export interface Sort {
21
+ column: string;
22
+ direction: 'ASCENDING' | 'DESCENDING';
23
+ }
24
+
25
+ export interface Join {
26
+ type: 'INNER' | 'LEFT' | 'RIGHT' | 'FULL';
27
+ table: string;
28
+ on: any;
29
+ }
30
+
31
+ export interface Aggregate {
32
+ column: string;
33
+ function: AggregateFunction;
34
+ alias: string;
35
+ }
36
+
37
+ export interface GroupBy {
38
+ columns: string[];
39
+ }
40
+
41
+ export interface ForeignKey {
42
+ from_table: string;
43
+ from_column: string;
44
+ to_table: string;
45
+ to_column: string;
46
+ on_delete?: ForeignKeyAction;
47
+ on_update?: ForeignKeyAction;
48
+ }
49
+
50
+ export interface Column {
51
+ name: string;
52
+ column_type: string | Record<string, any>;
53
+ description?: string;
54
+ is_primary_key?: boolean;
55
+ is_nullable?: boolean;
56
+ auto_increment?: boolean;
57
+ default?: any;
58
+ }
59
+
60
+ export interface Index {
61
+ name: string;
62
+ columns: string[];
63
+ unique?: boolean;
64
+ }
65
+
66
+ export interface SyntropixDBColumn {
67
+ id: string; // UUID as string in TypeScript
68
+ name: string;
69
+ description: string;
70
+ column_type: string | Record<string, any>;
71
+ is_nullable: boolean;
72
+ is_primary_key: boolean;
73
+ auto_increment: boolean;
74
+ default?: any; // Optional field
75
+ }
76
+
77
+ export interface SyntropixDBTable {
78
+ id: string; // UUID as string in TypeScript
79
+ name: string;
80
+ description: string;
81
+ created_at: Date;
82
+ columns: SyntropixDBColumn[];
83
+ }
@@ -0,0 +1,4 @@
1
+ export interface ApiResponse<T> {
2
+ status: string;
3
+ data: T;
4
+ }
@@ -0,0 +1,21 @@
1
+ import { Column, ForeignKey, Index } from '../common';
2
+
3
+ export interface TableCreateResponse {
4
+ _id: { $oid: string };
5
+ table: {
6
+ id: string;
7
+ name: string;
8
+ description: string;
9
+ created_at: any;
10
+ columns: Column[];
11
+ foreign_keys: ForeignKey[];
12
+ indexes: Index[];
13
+ schema: string;
14
+ default_access: string | null;
15
+ };
16
+ created_at: any;
17
+ updated_at: any;
18
+ created_by: string;
19
+ metadata: Record<string, any>;
20
+ triggers: any[];
21
+ }