uranio 0.1.19 → 0.1.21
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/.uranio/.infisical.json +5 -0
- package/.uranio/package.json +10 -2
- package/.uranio/src/{atom.ts → atom/mongodb.ts} +36 -32
- package/.uranio/src/atom/mysql.ts +112 -0
- package/.uranio/src/client/mongodb.ts +40 -0
- package/.uranio/src/client/mysql.ts +71 -0
- package/.uranio/src/client.ts +30 -27
- package/.uranio/src/index.ts +6 -3
- package/.uranio/src/run.ts +7 -0
- package/.uranio/src/sql/full_query.ts +328 -0
- package/.uranio/src/sql/index.ts +13 -0
- package/.uranio/src/sql/param_query.ts +245 -0
- package/.uranio/src/types/atom.ts +28 -0
- package/.uranio/src/types/index.ts +33 -0
- package/.uranio/src/types/sql.ts +34 -0
- package/.uranio/src/{query.ts → types/where.ts} +10 -7
- package/.uranio/tests/client.mysql.test.ts +130 -0
- package/.uranio/tests/sql.full.test.ts +185 -0
- package/.uranio/tests/sql.param.test.ts +108 -0
- package/dist/bin.js +0 -0
- package/package.json +2 -1
- package/src/cli/generate/index.ts +71 -12
- package/.uranio/src/types.ts +0 -25
- package/.uranio/src/uranio-client.ts +0 -25
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
*
|
|
3
|
-
*
|
|
3
|
+
* Where type module
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {atom} from './
|
|
7
|
+
import {atom, primary} from './index';
|
|
8
8
|
|
|
9
|
-
export type
|
|
9
|
+
export type Where<A extends atom> = {
|
|
10
10
|
[P in keyof A]?: Condition<A[P]>;
|
|
11
11
|
} & RootFilterOperators<A>;
|
|
12
12
|
|
|
13
13
|
type Condition<T> = AlternativeType<T> | FilterOperators<AlternativeType<T>>;
|
|
14
14
|
|
|
15
|
-
type AlternativeType<T> =
|
|
15
|
+
type AlternativeType<T> =
|
|
16
|
+
T extends primary<infer P> ?
|
|
17
|
+
P | RegExpOrString<P> :
|
|
18
|
+
T extends ReadonlyArray<infer U>
|
|
16
19
|
? T | RegExpOrString<U>
|
|
17
20
|
: RegExpOrString<T>;
|
|
18
21
|
|
|
@@ -41,9 +44,9 @@ interface FilterOperators<T> {
|
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
interface RootFilterOperators<A extends atom> {
|
|
44
|
-
$and?:
|
|
45
|
-
$nor?:
|
|
46
|
-
$or?:
|
|
47
|
+
$and?: Where<A>[];
|
|
48
|
+
$nor?: Where<A>[];
|
|
49
|
+
$or?: Where<A>[];
|
|
47
50
|
$text?: {
|
|
48
51
|
$search: string;
|
|
49
52
|
$language?: string;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import {describe, it, before} from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
|
|
4
|
+
import mysql from 'mysql2/promise';
|
|
5
|
+
|
|
6
|
+
import {UranioMySQLClient as MySQLClient} from '../src/client';
|
|
7
|
+
|
|
8
|
+
import * as sql from '../src/sql/index';
|
|
9
|
+
|
|
10
|
+
const mysql_uri = process.env.MYSQL_URI || '';
|
|
11
|
+
|
|
12
|
+
type Pippo = {
|
|
13
|
+
_id: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe('MySQL Client Mocked', () => {
|
|
17
|
+
|
|
18
|
+
before(() => {});
|
|
19
|
+
|
|
20
|
+
it('should return the mocked rows MYSQL POOL', async () => {
|
|
21
|
+
const mysql_urn = new MySQLClient({
|
|
22
|
+
uri: mysql_uri,
|
|
23
|
+
use_pool: true
|
|
24
|
+
});
|
|
25
|
+
const mock_rows = [{ id: 1, name: 'John' }, {id: 2, name: 'Franco'}];
|
|
26
|
+
const mock_pool = {
|
|
27
|
+
getConnection: async () => {
|
|
28
|
+
return {
|
|
29
|
+
execute: async () => {
|
|
30
|
+
const fields = {};
|
|
31
|
+
return [mock_rows, fields];
|
|
32
|
+
},
|
|
33
|
+
threadId: 0,
|
|
34
|
+
release: () => {}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
mysql_urn.pool = mock_pool as any;
|
|
39
|
+
const query = sql.full.compose_select<Pippo>({table: 'pippo'});
|
|
40
|
+
try{
|
|
41
|
+
const [rows_00] = await mysql_urn.exe(query);
|
|
42
|
+
assert.strictEqual(rows_00, mock_rows);
|
|
43
|
+
}catch(e){
|
|
44
|
+
const err = e as Error;
|
|
45
|
+
assert.fail(`Unexpected error: ${err.message}`);
|
|
46
|
+
}finally{
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should return the mocked rows MYSQL MAIN', async () => {
|
|
51
|
+
const mysql_urn = new MySQLClient({
|
|
52
|
+
uri: mysql_uri
|
|
53
|
+
});
|
|
54
|
+
const mock_rows = [{ id: 1, name: 'John' }, {id: 2, name: 'Franco'}];
|
|
55
|
+
const mock_create_connection = async () => {
|
|
56
|
+
return {
|
|
57
|
+
execute: async () => {
|
|
58
|
+
const fields = {};
|
|
59
|
+
return [mock_rows, fields];
|
|
60
|
+
},
|
|
61
|
+
end: () => {}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const original_create_connection = mysql.createConnection;
|
|
65
|
+
mysql.createConnection = mock_create_connection as any;
|
|
66
|
+
|
|
67
|
+
const query = sql.full.compose_select<Pippo>({table: 'pippo'});
|
|
68
|
+
|
|
69
|
+
try{
|
|
70
|
+
const [rows_00] = await mysql_urn.exe(query);
|
|
71
|
+
assert.strictEqual(rows_00, mock_rows);
|
|
72
|
+
}catch(e){
|
|
73
|
+
const err = e as Error;
|
|
74
|
+
assert.fail(`Unexpected error: ${err.message}`);
|
|
75
|
+
}finally{
|
|
76
|
+
mysql.createConnection = original_create_connection;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('MySQL Client Integration Real DB', () => {
|
|
83
|
+
|
|
84
|
+
before(() => {});
|
|
85
|
+
|
|
86
|
+
it('should return the rows MYSQL POOL', async () => {
|
|
87
|
+
const mysql_urn = new MySQLClient({
|
|
88
|
+
uri: mysql_uri,
|
|
89
|
+
use_pool: true
|
|
90
|
+
});
|
|
91
|
+
const expected_row = {
|
|
92
|
+
age: 28,
|
|
93
|
+
email: 'john.doe@example.com',
|
|
94
|
+
id: 1,
|
|
95
|
+
name: 'John Doe',
|
|
96
|
+
};
|
|
97
|
+
const query = sql.full.compose_select<Pippo>({table: 'pippo'});
|
|
98
|
+
try{
|
|
99
|
+
const [rows_00] = await mysql_urn.exe(query);
|
|
100
|
+
assert.deepEqual(rows_00[0], expected_row);
|
|
101
|
+
}catch(e){
|
|
102
|
+
const err = e as Error;
|
|
103
|
+
assert.fail(`Unexpected error: ${err.message}`);
|
|
104
|
+
}finally{
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should return the rows MYSQL MAIN', async () => {
|
|
109
|
+
const mysql_urn = new MySQLClient({
|
|
110
|
+
uri: mysql_uri
|
|
111
|
+
});
|
|
112
|
+
const expected_row = {
|
|
113
|
+
age: 28,
|
|
114
|
+
email: 'john.doe@example.com',
|
|
115
|
+
id: 1,
|
|
116
|
+
name: 'John Doe',
|
|
117
|
+
};
|
|
118
|
+
const query = sql.full.compose_select<Pippo>({table: 'pippo'});
|
|
119
|
+
try{
|
|
120
|
+
const [rows_00] = await mysql_urn.exe(query);
|
|
121
|
+
assert.deepEqual(rows_00[0], expected_row);
|
|
122
|
+
}catch(e){
|
|
123
|
+
const err = e as Error;
|
|
124
|
+
assert.fail(`Unexpected error: ${err.message}`);
|
|
125
|
+
}finally{
|
|
126
|
+
mysql_urn.disconnect();
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
});
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import {describe, it} from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
|
|
4
|
+
import * as sql from '../src/sql/index';
|
|
5
|
+
|
|
6
|
+
type ATable = {
|
|
7
|
+
_id: string
|
|
8
|
+
foo: number
|
|
9
|
+
boo: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
describe('Testing SQL full query SELECT', () => {
|
|
13
|
+
it('should generate the same query SELECT', () => {
|
|
14
|
+
let final_query = '';
|
|
15
|
+
final_query += 'SELECT foo, boo FROM `a-table` WHERE';
|
|
16
|
+
final_query += ' `foo` > 2 AND `foo` <= 100 AND `boo` = "str"';
|
|
17
|
+
final_query += ' ORDER BY `foo` DESC';
|
|
18
|
+
final_query += ' LIMIT 10, 100';
|
|
19
|
+
const projection = ['foo', 'boo'];
|
|
20
|
+
const table = 'a-table';
|
|
21
|
+
const where = {foo: {$gt: 2, $lte: 100}, boo: 'str'};
|
|
22
|
+
const order = {foo: 'desc'} as const;
|
|
23
|
+
const limit = '10, 100';
|
|
24
|
+
const full_query = sql.full.compose_select<ATable>({
|
|
25
|
+
projection,
|
|
26
|
+
table,
|
|
27
|
+
where,
|
|
28
|
+
order,
|
|
29
|
+
limit
|
|
30
|
+
});
|
|
31
|
+
assert.strictEqual(final_query, full_query);
|
|
32
|
+
});
|
|
33
|
+
it('should generate the same query SELECT', () => {
|
|
34
|
+
let final_query = '';
|
|
35
|
+
final_query += 'SELECT foo, boo FROM `a-table` WHERE';
|
|
36
|
+
final_query += ' (`foo` > 2 AND `foo` <= 100 AND `boo` = "123")';
|
|
37
|
+
final_query += ' ORDER BY `foo` DESC';
|
|
38
|
+
final_query += ' LIMIT 10, 100';
|
|
39
|
+
const projection = ['foo', 'boo'];
|
|
40
|
+
const table = 'a-table';
|
|
41
|
+
const where = {$and: [{foo: {$gt: 2}}, {foo: {$lte: 100}}, {boo: '123'}]};
|
|
42
|
+
const order = {foo: 'desc'} as const;
|
|
43
|
+
const limit = '10, 100';
|
|
44
|
+
const full_query = sql.full.compose_select<ATable>({
|
|
45
|
+
projection,
|
|
46
|
+
table,
|
|
47
|
+
where,
|
|
48
|
+
order,
|
|
49
|
+
limit
|
|
50
|
+
});
|
|
51
|
+
assert.strictEqual(final_query, full_query);
|
|
52
|
+
});
|
|
53
|
+
it('should generate the same query SELECT', () => {
|
|
54
|
+
let final_query = '';
|
|
55
|
+
final_query += 'SELECT foo, boo FROM `a-table` WHERE';
|
|
56
|
+
final_query += ' (`boo` = "a" OR `boo` IN [1,2,3])';
|
|
57
|
+
final_query += ' ORDER BY `foo` DESC';
|
|
58
|
+
final_query += ' LIMIT 10, 100';
|
|
59
|
+
const projection = ['foo', 'boo'];
|
|
60
|
+
const table = 'a-table';
|
|
61
|
+
const where = {$or: [{boo: 'a'}, {boo: {$in: ['1','2','3']}}]};
|
|
62
|
+
const order = {foo: 'desc'} as const;
|
|
63
|
+
const limit = '10, 100';
|
|
64
|
+
const full_query = sql.full.compose_select<ATable>({
|
|
65
|
+
projection,
|
|
66
|
+
table,
|
|
67
|
+
where,
|
|
68
|
+
order,
|
|
69
|
+
limit
|
|
70
|
+
});
|
|
71
|
+
assert.strictEqual(final_query, full_query);
|
|
72
|
+
});
|
|
73
|
+
it('should generate the same query SELECT', () => {
|
|
74
|
+
let final_query = '';
|
|
75
|
+
final_query += 'SELECT * FROM `a-table` WHERE';
|
|
76
|
+
final_query += ' (';
|
|
77
|
+
final_query += '`boo` = "a" OR `boo` IN [1,2,3]';
|
|
78
|
+
final_query += ' OR';
|
|
79
|
+
final_query += ' (`foo` = 2 AND `foo` = 1)'
|
|
80
|
+
final_query += ')';
|
|
81
|
+
const table = 'a-table';
|
|
82
|
+
const where = {
|
|
83
|
+
$or: [
|
|
84
|
+
{boo: 'a'},
|
|
85
|
+
{boo: {$in: ['1','2','3']}},
|
|
86
|
+
{
|
|
87
|
+
$and: [
|
|
88
|
+
{foo: 2},{foo: 1}
|
|
89
|
+
]
|
|
90
|
+
},
|
|
91
|
+
]
|
|
92
|
+
};
|
|
93
|
+
const full_query = sql.full.compose_select<ATable>({
|
|
94
|
+
table,
|
|
95
|
+
where,
|
|
96
|
+
});
|
|
97
|
+
assert.strictEqual(final_query, full_query);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe('Testing SQL full query UPDATE', () => {
|
|
102
|
+
it('should generate the same query UPDATE', () => {
|
|
103
|
+
const table = 'uranio-table';
|
|
104
|
+
const update = {
|
|
105
|
+
boo: '1',
|
|
106
|
+
foo: 2
|
|
107
|
+
};
|
|
108
|
+
const where = {
|
|
109
|
+
$or: [
|
|
110
|
+
{boo: 'a'},
|
|
111
|
+
{boo: {$in: ['1','2','3']}},
|
|
112
|
+
{
|
|
113
|
+
$and: [
|
|
114
|
+
{foo: 2},{foo: 1}
|
|
115
|
+
]
|
|
116
|
+
},
|
|
117
|
+
]
|
|
118
|
+
};
|
|
119
|
+
const full_query = sql.full.compose_update<ATable>({
|
|
120
|
+
table,
|
|
121
|
+
update,
|
|
122
|
+
where
|
|
123
|
+
});
|
|
124
|
+
let final_query = '';
|
|
125
|
+
final_query += 'UPDATE `uranio-table` SET';
|
|
126
|
+
final_query += ' boo = "1", foo = 2 WHERE';
|
|
127
|
+
final_query += ' (';
|
|
128
|
+
final_query += '`boo` = "a" OR `boo` IN [1,2,3]';
|
|
129
|
+
final_query += ' OR ';
|
|
130
|
+
final_query += '(`foo` = 2 AND `foo` = 1)';
|
|
131
|
+
final_query += ')';
|
|
132
|
+
assert.strictEqual(final_query, full_query);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('Testing SQL full query DELETE', () => {
|
|
137
|
+
it('should generate the same query DELETE', () => {
|
|
138
|
+
const table = 'uranio-table';
|
|
139
|
+
const where = {
|
|
140
|
+
$or: [
|
|
141
|
+
{boo: 'a'},
|
|
142
|
+
{boo: {$in: ['1','2','3']}},
|
|
143
|
+
{
|
|
144
|
+
$and: [
|
|
145
|
+
{foo: 2},{foo: 1}
|
|
146
|
+
]
|
|
147
|
+
},
|
|
148
|
+
]
|
|
149
|
+
};
|
|
150
|
+
const full_query = sql.full.compose_delete<ATable>({
|
|
151
|
+
table,
|
|
152
|
+
where
|
|
153
|
+
});
|
|
154
|
+
let final_query = '';
|
|
155
|
+
final_query += 'DELETE FROM `uranio-table`';
|
|
156
|
+
final_query += ' WHERE';
|
|
157
|
+
final_query += ' (';
|
|
158
|
+
final_query += '`boo` = "a" OR `boo` IN [1,2,3]';
|
|
159
|
+
final_query += ' OR ';
|
|
160
|
+
final_query += '(`foo` = 2 AND `foo` = 1)';
|
|
161
|
+
final_query += ')';
|
|
162
|
+
assert.strictEqual(final_query, full_query);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe('Testing SQL full query INSERT', () => {
|
|
167
|
+
it('should generate the same query INSERT', () => {
|
|
168
|
+
const table = 'uranio-table';
|
|
169
|
+
const columns = ['boo', 'foo'] as (keyof ATable)[];
|
|
170
|
+
const records = [
|
|
171
|
+
{boo: 'u', foo: 9},
|
|
172
|
+
{boo: 'w', foo: 19},
|
|
173
|
+
];
|
|
174
|
+
const full_query = sql.full.compose_insert<ATable>({
|
|
175
|
+
table,
|
|
176
|
+
columns,
|
|
177
|
+
records
|
|
178
|
+
});
|
|
179
|
+
let final_query = '';
|
|
180
|
+
final_query += 'INSERT INTO `uranio-table` (`boo`, `foo`)';
|
|
181
|
+
final_query += ' VALUES';
|
|
182
|
+
final_query += ' ("u", 9), ("w", 19)';
|
|
183
|
+
assert.strictEqual(final_query, full_query);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {describe, it} from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
|
|
4
|
+
import * as sql from '../src/sql/index';
|
|
5
|
+
|
|
6
|
+
type ATable = {
|
|
7
|
+
_id: string
|
|
8
|
+
foo: number
|
|
9
|
+
boo: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
describe('Testing SQL param query SELECT', () => {
|
|
13
|
+
it('should generate the same query SELECT', () => {
|
|
14
|
+
const projection = ['foo', 'boo'];
|
|
15
|
+
const table = 'a-table';
|
|
16
|
+
const where = {foo: {$gt: 2, $lte: 100}, boo: 'str'};
|
|
17
|
+
const order = {foo: 'desc'} as const;
|
|
18
|
+
const limit = '10, 100';
|
|
19
|
+
const {query} = sql.param.compose_select<ATable>({
|
|
20
|
+
projection,
|
|
21
|
+
table,
|
|
22
|
+
where,
|
|
23
|
+
order,
|
|
24
|
+
limit
|
|
25
|
+
});
|
|
26
|
+
let final_query = '';
|
|
27
|
+
final_query += 'SELECT foo, boo FROM `a-table` WHERE';
|
|
28
|
+
final_query += ' `foo` > :x0002 AND `foo` <= :x0003 AND `boo` = :x0004';
|
|
29
|
+
final_query += ' ORDER BY `foo` DESC LIMIT 10, :x0003';
|
|
30
|
+
assert.strictEqual(query, final_query);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('Testing SQL param query UPDATE', () => {
|
|
35
|
+
it('should generate the same query UPDATE', () => {
|
|
36
|
+
const table = 'uranio-table';
|
|
37
|
+
const update = {
|
|
38
|
+
boo: '1',
|
|
39
|
+
foo: 2
|
|
40
|
+
};
|
|
41
|
+
const where = {
|
|
42
|
+
$or: [
|
|
43
|
+
{boo: 'a'},
|
|
44
|
+
{boo: {$in: ['1','2','3']}},
|
|
45
|
+
{
|
|
46
|
+
$and: [
|
|
47
|
+
{foo: 2},{foo: 1}
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
]
|
|
51
|
+
};
|
|
52
|
+
const {query} = sql.param.compose_update<ATable>({
|
|
53
|
+
table,
|
|
54
|
+
update,
|
|
55
|
+
where
|
|
56
|
+
});
|
|
57
|
+
let final_query = '';
|
|
58
|
+
final_query += 'UPDATE `uranio-table` SET boo = :x0016, foo = :x0014 WHERE';
|
|
59
|
+
final_query += ' (`boo` = :x0012 OR `boo` IN :x0013 OR';
|
|
60
|
+
final_query += ' (`foo` = :x0014 AND `foo` = :x0015))';
|
|
61
|
+
assert.strictEqual(query, final_query);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('Testing SQL param query DELETE', () => {
|
|
66
|
+
it('should generate the same query DELETE', () => {
|
|
67
|
+
const table = 'uranio-table';
|
|
68
|
+
const where = {
|
|
69
|
+
$or: [
|
|
70
|
+
{boo: 'a'},
|
|
71
|
+
{boo: {$in: ['1','2','3']}},
|
|
72
|
+
{
|
|
73
|
+
$and: [
|
|
74
|
+
{foo: 2},{foo: 1}
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
]
|
|
78
|
+
};
|
|
79
|
+
const {query} = sql.param.compose_delete<ATable>({
|
|
80
|
+
table,
|
|
81
|
+
where
|
|
82
|
+
});
|
|
83
|
+
let final_query = '';
|
|
84
|
+
final_query += 'DELETE FROM `uranio-table` WHERE';
|
|
85
|
+
final_query += ' (`boo` = :x0025 OR `boo` IN :x0026 OR';
|
|
86
|
+
final_query += ' (`foo` = :x0027 AND `foo` = :x0028))';
|
|
87
|
+
assert.strictEqual(query, final_query);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('Testing SQL param query INSERT', () => {
|
|
92
|
+
it('should generate the same query INSERT', () => {
|
|
93
|
+
const table = 'uranio-table';
|
|
94
|
+
const columns = ['boo', 'foo'] as (keyof ATable)[];
|
|
95
|
+
const records = [
|
|
96
|
+
{boo: 'u', foo: 9},
|
|
97
|
+
{boo: 'w', foo: 19},
|
|
98
|
+
];
|
|
99
|
+
const {query} = sql.param.compose_insert<ATable>({
|
|
100
|
+
table,
|
|
101
|
+
columns,
|
|
102
|
+
records
|
|
103
|
+
});
|
|
104
|
+
let final_query = '';
|
|
105
|
+
final_query += 'INSERT INTO `uranio-table` (`boo`, `foo`) VALUES ?';
|
|
106
|
+
assert.strictEqual(query, final_query);
|
|
107
|
+
});
|
|
108
|
+
});
|
package/dist/bin.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uranio",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "Uranio is a type-safe ODM for MongoDB",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"app-root-path": "^3.1.0",
|
|
57
57
|
"i0n": "^0.8.1",
|
|
58
58
|
"mongodb": "^6.3.0",
|
|
59
|
+
"mysql2": "^3.7.0",
|
|
59
60
|
"plutonio": "^0.5.1",
|
|
60
61
|
"r4y": "^0.6.0"
|
|
61
62
|
}
|
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
*
|
|
3
3
|
* Generate index module
|
|
4
4
|
*
|
|
5
|
+
* `generate` command do the following:
|
|
6
|
+
*
|
|
7
|
+
* - copy the directory `.uranio` from its root directory into the
|
|
8
|
+
* `node_modules` of the project where the command is run.
|
|
9
|
+
*
|
|
10
|
+
* - After parsing the types with `plutonio` it updates the copied typescript
|
|
11
|
+
* files.
|
|
12
|
+
*
|
|
13
|
+
* - It then build the updated `.uranio` files as a typescript project.
|
|
14
|
+
*
|
|
5
15
|
* @packageDocumentation
|
|
6
16
|
*/
|
|
7
17
|
|
|
@@ -65,7 +75,7 @@ async function _update_dot_uranio(params: GenerateParams) {
|
|
|
65
75
|
log.spinner.text(`Updating dot uranio files...`);
|
|
66
76
|
const uranio_extended_interfaces = _get_uranio_extended_interfaces(params);
|
|
67
77
|
const text = _generate_uranio_client_module_text(uranio_extended_interfaces);
|
|
68
|
-
const uranio_client_path = `${params.root}/node_modules/.uranio/src/
|
|
78
|
+
const uranio_client_path = `${params.root}/node_modules/.uranio/src/client.ts`;
|
|
69
79
|
fs.writeFileSync(uranio_client_path, text);
|
|
70
80
|
log.debug(`Updated dot uranio files`);
|
|
71
81
|
}
|
|
@@ -116,6 +126,7 @@ function _get_uranio_extended_interfaces(params: GenerateParams) {
|
|
|
116
126
|
}
|
|
117
127
|
}
|
|
118
128
|
// log.trace(uranio_extended_interfaces);
|
|
129
|
+
_debug_interfaces(uranio_extended_interfaces);
|
|
119
130
|
return uranio_extended_interfaces;
|
|
120
131
|
}
|
|
121
132
|
|
|
@@ -129,16 +140,40 @@ function _generate_uranio_client_module_text(interfaces: plutonio.Interfaces) {
|
|
|
129
140
|
text += ` *\n`;
|
|
130
141
|
text += ` */\n`;
|
|
131
142
|
text += `\n`;
|
|
132
|
-
text += `import {
|
|
133
|
-
text += `import {
|
|
134
|
-
text +=
|
|
143
|
+
text += `import {MongoDBClient, MongoDBClientParams} from './client/mongodb';`;
|
|
144
|
+
text += `import {MySQLClient, MySQLClientParams} from './client/mysql';`;
|
|
145
|
+
text += `\n`;
|
|
146
|
+
text += `import {MongoDBAtomClient} from './atom/mongodb';`;
|
|
147
|
+
text += `import {MySQLAtomClient} from './atom/mysql';`;
|
|
148
|
+
text += `\n`;
|
|
149
|
+
text += `import * as t from './types/index';`;
|
|
135
150
|
text += `\n`;
|
|
136
151
|
text += _generate_interface_definitions(interfaces);
|
|
137
|
-
text +=
|
|
138
|
-
text +=
|
|
139
|
-
text +=
|
|
152
|
+
text += _generate_mongodb_client(interfaces);
|
|
153
|
+
text += _generate_mysql_client(interfaces);
|
|
154
|
+
text += `\n`;
|
|
155
|
+
return text;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function _generate_mongodb_client(interfaces: plutonio.Interfaces){
|
|
159
|
+
let text = '';
|
|
160
|
+
text += `export class UranioMongoDBClient extends MongoDBClient{\n`;
|
|
161
|
+
text += _generate_mongodb_client_attributes(interfaces);
|
|
162
|
+
text += ` constructor(params: MongoDBClientParams) {\n`;
|
|
163
|
+
text += ` super(params);\n`;
|
|
164
|
+
text += _generate_mongodb_client_initialization(interfaces);
|
|
165
|
+
text += ` }\n`;
|
|
166
|
+
text += `}\n`;
|
|
167
|
+
return text;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function _generate_mysql_client(interfaces: plutonio.Interfaces){
|
|
171
|
+
let text = '';
|
|
172
|
+
text += `export class UranioMySQLClient extends MySQLClient{\n`;
|
|
173
|
+
text += _generate_mysql_client_attributes(interfaces);
|
|
174
|
+
text += ` constructor(params: MySQLClientParams) {\n`;
|
|
140
175
|
text += ` super(params);\n`;
|
|
141
|
-
text +=
|
|
176
|
+
text += _generate_mysql_client_initialization(interfaces);
|
|
142
177
|
text += ` }\n`;
|
|
143
178
|
text += `}\n`;
|
|
144
179
|
return text;
|
|
@@ -162,20 +197,38 @@ function _generate_interface_definitions(interfaces: plutonio.Interfaces) {
|
|
|
162
197
|
return text;
|
|
163
198
|
}
|
|
164
199
|
|
|
165
|
-
function
|
|
200
|
+
function _generate_mongodb_client_attributes(interfaces: plutonio.Interfaces) {
|
|
166
201
|
let text = '';
|
|
167
202
|
for (const [name, _inter] of Object.entries(interfaces)) {
|
|
168
203
|
let lc = _first_letter_lowercase(name);
|
|
169
|
-
text += ` public ${lc}:
|
|
204
|
+
text += ` public ${lc}: MongoDBAtomClient<${name}>;\n`;
|
|
170
205
|
}
|
|
171
206
|
return text;
|
|
172
207
|
}
|
|
173
208
|
|
|
174
|
-
function
|
|
209
|
+
function _generate_mongodb_client_initialization(interfaces: plutonio.Interfaces) {
|
|
175
210
|
let text = '';
|
|
176
211
|
for (const [name, _inter] of Object.entries(interfaces)) {
|
|
177
212
|
let lc = _first_letter_lowercase(name);
|
|
178
|
-
text += ` this.${lc} = new
|
|
213
|
+
text += ` this.${lc} = new MongoDBAtomClient<${name}>(this.db, '${lc}');\n`;
|
|
214
|
+
}
|
|
215
|
+
return text;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function _generate_mysql_client_attributes(interfaces: plutonio.Interfaces) {
|
|
219
|
+
let text = '';
|
|
220
|
+
for (const [name, _inter] of Object.entries(interfaces)) {
|
|
221
|
+
let lc = _first_letter_lowercase(name);
|
|
222
|
+
text += ` public ${lc}: MySQLAtomClient<${name}>;\n`;
|
|
223
|
+
}
|
|
224
|
+
return text;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function _generate_mysql_client_initialization(interfaces: plutonio.Interfaces) {
|
|
228
|
+
let text = '';
|
|
229
|
+
for (const [name, _inter] of Object.entries(interfaces)) {
|
|
230
|
+
let lc = _first_letter_lowercase(name);
|
|
231
|
+
text += ` this.${lc} = new MySQLAtomClient<${name}>(this.db, '${lc}');\n`;
|
|
179
232
|
}
|
|
180
233
|
return text;
|
|
181
234
|
}
|
|
@@ -186,3 +239,9 @@ function _first_letter_lowercase(str: string): string {
|
|
|
186
239
|
}
|
|
187
240
|
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
188
241
|
}
|
|
242
|
+
|
|
243
|
+
function _debug_interfaces(uranio_extended_interfaces: plutonio.Interfaces){
|
|
244
|
+
for(let [key, _value] of Object.entries(uranio_extended_interfaces)){
|
|
245
|
+
log.info(`Processing Interface: ${key}`);
|
|
246
|
+
}
|
|
247
|
+
}
|
package/.uranio/src/types.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Types module
|
|
4
|
-
*
|
|
5
|
-
* @packageDocumentation
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export * from './query';
|
|
10
|
-
|
|
11
|
-
export interface atom {
|
|
12
|
-
_id: string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// export type primary<T> = T & {__uranio: 'primary'};
|
|
16
|
-
|
|
17
|
-
export type unique<T> = T & {__uranio: 'unique'};
|
|
18
|
-
|
|
19
|
-
// type PrimaryAttribute<A extends atom> = {
|
|
20
|
-
// [K in keyof A]: A[K] extends {__uranio: 'primary'} ? K : never;
|
|
21
|
-
// }[keyof A];
|
|
22
|
-
|
|
23
|
-
// export type Shape<A extends atom> = Omit<A, PrimaryAttribute<A>>;
|
|
24
|
-
|
|
25
|
-
export type Shape<A extends atom> = Omit<A, '_id'>;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* UranioClient module
|
|
4
|
-
*
|
|
5
|
-
* @packageDocumentation
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import {Client, ClientParams} from './client';
|
|
10
|
-
// import {AtomClient} from './atom';
|
|
11
|
-
// import {atom} from './types';
|
|
12
|
-
|
|
13
|
-
// interface Product extends atom {
|
|
14
|
-
// title: string;
|
|
15
|
-
// price: number;
|
|
16
|
-
// }
|
|
17
|
-
|
|
18
|
-
export class UranioClient extends Client{
|
|
19
|
-
// public product: AtomClient<Product>;
|
|
20
|
-
constructor(params: ClientParams) {
|
|
21
|
-
super(params);
|
|
22
|
-
// this.product = new AtomClient<Product>(this.db, 'product');
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|