@syntropix/database 0.0.3 → 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/dist/core/dataClient.d.ts +1 -1
- package/dist/core/dataClient.js +2 -1
- package/dist/core/tableClient.d.ts +1 -1
- package/dist/core/tableClient.js +2 -1
- package/dist/types/basemodel.d.ts +1 -1
- package/dist/types/filter.d.ts +8 -0
- package/dist/types/filter.js +24 -0
- package/dist/types/requests.d.ts +2 -41
- package/package.json +5 -2
- package/.editorconfig +0 -8
- package/.env +0 -2
- package/.gitattributes +0 -4
- package/.husky/pre-commit +0 -1
- package/.prettierrc +0 -8
- package/.vscode/settings.json +0 -1
- package/.yarnrc.yml +0 -1
- package/eslint.config.mjs +0 -23
- package/examples/advanced-usage.ts +0 -214
- package/examples/tsconfig.json +0 -13
- package/examples/usage.ts +0 -94
- package/jest.config.ts +0 -9
- package/src/core/client.ts +0 -41
- package/src/core/config.ts +0 -29
- package/src/core/dataClient.ts +0 -78
- package/src/core/syntropix.ts +0 -27
- package/src/core/tableClient.ts +0 -86
- package/src/index.ts +0 -10
- package/src/types/basemodel.ts +0 -558
- package/src/types/common.ts +0 -83
- package/src/types/data-type.ts +0 -23
- package/src/types/dto/base.ts +0 -4
- package/src/types/dto/table.ts +0 -21
- package/src/types/field.ts +0 -277
- package/src/types/filter.ts +0 -281
- package/src/types/requests.ts +0 -91
- package/test.json +0 -48
- package/tests/basic.test.ts +0 -141
- package/tests/tsconfig.json +0 -8
- package/tsconfig.json +0 -18
|
@@ -2,7 +2,7 @@ import { DeleteData, Insert, Query, Update } from '../types/requests';
|
|
|
2
2
|
import { ClientConfig } from './config';
|
|
3
3
|
export declare class DataClient {
|
|
4
4
|
private client;
|
|
5
|
-
constructor(config
|
|
5
|
+
constructor(config?: ClientConfig);
|
|
6
6
|
insertData(data: Insert): Promise<any>;
|
|
7
7
|
insertOne(data: Insert): Promise<any>;
|
|
8
8
|
updateByPrimaryKey(pk: string, data: Update): Promise<any>;
|
package/dist/core/dataClient.js
CHANGED
|
@@ -4,7 +4,7 @@ import { TableAddColumn, TableCreate, TableDrop, TableDropColumn, TableGetSchema
|
|
|
4
4
|
import { ClientConfig } from './config';
|
|
5
5
|
export declare class TableClient {
|
|
6
6
|
private client;
|
|
7
|
-
constructor(config
|
|
7
|
+
constructor(config?: ClientConfig);
|
|
8
8
|
createTable(data: TableCreate): Promise<TableCreateResponse>;
|
|
9
9
|
dropTable(data: TableDrop): Promise<any>;
|
|
10
10
|
renameTable(data: TableRename): Promise<any>;
|
package/dist/core/tableClient.js
CHANGED
|
@@ -51,7 +51,7 @@ export declare class BaseModel {
|
|
|
51
51
|
static get<T extends BaseModel>(this: new (data?: any) => T, filter: Filter, select?: string[], _client?: SyntropixClient | null): Promise<T>;
|
|
52
52
|
static filter<T extends BaseModel>(this: new (data?: any) => T, options: {
|
|
53
53
|
filter: Filter;
|
|
54
|
-
sort?: Sort;
|
|
54
|
+
sort?: Sort[];
|
|
55
55
|
aggregate?: Aggregate[];
|
|
56
56
|
join?: Join;
|
|
57
57
|
limit?: number;
|
package/dist/types/filter.d.ts
CHANGED
|
@@ -16,9 +16,13 @@ export declare enum FilterOperation {
|
|
|
16
16
|
NEQ = "NEQ",
|
|
17
17
|
Between = "Between",
|
|
18
18
|
In = "In",
|
|
19
|
+
Contains = "Contains",
|
|
20
|
+
Overlap = "Overlap",
|
|
19
21
|
NotIn = "NotIn",
|
|
20
22
|
Like = "Like",
|
|
21
23
|
NotLike = "NotLike",
|
|
24
|
+
ILike = "ILike",
|
|
25
|
+
NotILike = "NotILike",
|
|
22
26
|
IsNull = "IsNull",
|
|
23
27
|
IsNotNull = "IsNotNull",
|
|
24
28
|
Similarity = "Similarity",
|
|
@@ -51,6 +55,10 @@ export declare const GTE: (field: string, value: any) => SyntropixDBFilterItem;
|
|
|
51
55
|
export declare const LT: (field: string, value: any) => SyntropixDBFilterItem;
|
|
52
56
|
export declare const LTE: (field: string, value: any) => SyntropixDBFilterItem;
|
|
53
57
|
export declare const IN: (field: string, values: any[]) => SyntropixDBFilterItem;
|
|
58
|
+
export declare const CONTAINS: (field: string, value: any) => SyntropixDBFilterItem;
|
|
59
|
+
export declare const OVERLAP: (field: string, value: any) => SyntropixDBFilterItem;
|
|
60
|
+
export declare const I_LIKE: (field: string, pattern: string) => SyntropixDBFilterItem;
|
|
61
|
+
export declare const NOT_I_LIKE: (field: string, pattern: string) => SyntropixDBFilterItem;
|
|
54
62
|
export declare const NOT_IN: (field: string, values: any[]) => SyntropixDBFilterItem;
|
|
55
63
|
export declare const LIKE: (field: string, pattern: string) => SyntropixDBFilterItem;
|
|
56
64
|
export declare const NOT_LIKE: (field: string, pattern: string) => SyntropixDBFilterItem;
|
package/dist/types/filter.js
CHANGED
|
@@ -14,9 +14,13 @@ export var FilterOperation;
|
|
|
14
14
|
FilterOperation["NEQ"] = "NEQ";
|
|
15
15
|
FilterOperation["Between"] = "Between";
|
|
16
16
|
FilterOperation["In"] = "In";
|
|
17
|
+
FilterOperation["Contains"] = "Contains";
|
|
18
|
+
FilterOperation["Overlap"] = "Overlap";
|
|
17
19
|
FilterOperation["NotIn"] = "NotIn";
|
|
18
20
|
FilterOperation["Like"] = "Like";
|
|
19
21
|
FilterOperation["NotLike"] = "NotLike";
|
|
22
|
+
FilterOperation["ILike"] = "ILike";
|
|
23
|
+
FilterOperation["NotILike"] = "NotILike";
|
|
20
24
|
FilterOperation["IsNull"] = "IsNull";
|
|
21
25
|
FilterOperation["IsNotNull"] = "IsNotNull";
|
|
22
26
|
FilterOperation["Similarity"] = "Similarity";
|
|
@@ -67,6 +71,26 @@ export const IN = (field, values) => ({
|
|
|
67
71
|
operator: FilterOperation.In,
|
|
68
72
|
static_value: values,
|
|
69
73
|
});
|
|
74
|
+
export const CONTAINS = (field, value) => ({
|
|
75
|
+
column: field,
|
|
76
|
+
operator: FilterOperation.Contains,
|
|
77
|
+
static_value: value,
|
|
78
|
+
});
|
|
79
|
+
export const OVERLAP = (field, value) => ({
|
|
80
|
+
column: field,
|
|
81
|
+
operator: FilterOperation.Overlap,
|
|
82
|
+
static_value: value,
|
|
83
|
+
});
|
|
84
|
+
export const I_LIKE = (field, pattern) => ({
|
|
85
|
+
column: field,
|
|
86
|
+
operator: FilterOperation.ILike,
|
|
87
|
+
static_value: pattern,
|
|
88
|
+
});
|
|
89
|
+
export const NOT_I_LIKE = (field, pattern) => ({
|
|
90
|
+
column: field,
|
|
91
|
+
operator: FilterOperation.NotILike,
|
|
92
|
+
static_value: pattern,
|
|
93
|
+
});
|
|
70
94
|
export const NOT_IN = (field, values) => ({
|
|
71
95
|
column: field,
|
|
72
96
|
operator: FilterOperation.NotIn,
|
package/dist/types/requests.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Aggregate, Column, ForeignKey, GroupBy, Index, Join, Sort } from './common';
|
|
2
|
-
import { Filter
|
|
2
|
+
import { Filter } from './filter';
|
|
3
3
|
export interface TableCreate {
|
|
4
4
|
name: string;
|
|
5
5
|
description?: string;
|
|
@@ -58,7 +58,7 @@ export interface DeleteData {
|
|
|
58
58
|
}
|
|
59
59
|
export interface QueryPayload {
|
|
60
60
|
filter?: Filter;
|
|
61
|
-
sort?: Sort;
|
|
61
|
+
sort?: Sort[];
|
|
62
62
|
aggregate?: Aggregate[];
|
|
63
63
|
join?: Join[];
|
|
64
64
|
limit?: number;
|
|
@@ -70,42 +70,3 @@ export interface Query {
|
|
|
70
70
|
table_name: string;
|
|
71
71
|
query: QueryPayload;
|
|
72
72
|
}
|
|
73
|
-
export interface SyntropixDBSortItem {
|
|
74
|
-
column: string;
|
|
75
|
-
direction: SortType;
|
|
76
|
-
}
|
|
77
|
-
export type SyntropixDBSort = SyntropixDBSortItem[];
|
|
78
|
-
export interface SyntropixDBJoin {
|
|
79
|
-
table: string;
|
|
80
|
-
on: string;
|
|
81
|
-
}
|
|
82
|
-
export interface SyntropixDBAggregate {
|
|
83
|
-
function: string;
|
|
84
|
-
column: string;
|
|
85
|
-
alias: string;
|
|
86
|
-
}
|
|
87
|
-
export type SyntropixDBGroupBy = string[];
|
|
88
|
-
export type SyntropixDBDistinct = string[];
|
|
89
|
-
export interface SyntropixDBQuery {
|
|
90
|
-
filter: SyntropixDBFilter;
|
|
91
|
-
sort?: SyntropixDBSort;
|
|
92
|
-
limit?: number;
|
|
93
|
-
offset?: number;
|
|
94
|
-
select?: string[];
|
|
95
|
-
join?: SyntropixDBJoin[];
|
|
96
|
-
aggregate?: SyntropixDBAggregate[];
|
|
97
|
-
group_by?: SyntropixDBGroupBy;
|
|
98
|
-
distinct?: SyntropixDBDistinct;
|
|
99
|
-
}
|
|
100
|
-
export interface SyntropixDBInsert {
|
|
101
|
-
columns: string[];
|
|
102
|
-
values: any[][];
|
|
103
|
-
}
|
|
104
|
-
export interface SyntropixDBUpdate {
|
|
105
|
-
filter: SyntropixDBFilter;
|
|
106
|
-
columns: string[];
|
|
107
|
-
values: any[];
|
|
108
|
-
}
|
|
109
|
-
export interface SyntropixDBDelete {
|
|
110
|
-
filter: SyntropixDBFilter;
|
|
111
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syntropix/database",
|
|
3
|
-
"version": "0.0.
|
|
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
|
-
"
|
|
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
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
package/.husky/pre-commit
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
yarn lint-staged
|
package/.prettierrc
DELETED
package/.vscode/settings.json
DELETED
|
@@ -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);
|
package/examples/tsconfig.json
DELETED
|
@@ -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;
|
package/src/core/client.ts
DELETED
|
@@ -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
|
-
}
|
package/src/core/config.ts
DELETED
|
@@ -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
|
-
}
|