@ts-awesome/orm 1.7.0 → 2.0.0-alpha.0
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/builder.d.ts +1 -9
- package/dist/builder.js +1 -1
- package/dist/builder.js.map +1 -1
- package/dist/compiler.d.ts +55 -0
- package/dist/compiler.js +481 -0
- package/dist/compiler.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/intermediate.d.ts +9 -1
- package/dist/operators.js +2 -2
- package/dist/operators.js.map +1 -1
- package/dist/reader.js +1 -0
- package/dist/reader.js.map +1 -1
- package/jest.config.js +2 -2
- package/package.json +31 -1
- package/tests/builder.spec.ts +0 -1068
- package/tests/executor.spec.ts +0 -24
- package/tests/function-operators.spec.js +0 -172
- package/tests/models.ts +0 -88
- package/tests/prototype-operations.spec.js +0 -346
- package/tests/reader.spec.ts +0 -108
package/tests/reader.spec.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { reader, IQueryData, dbTable, IDbField, dbField, DbValueType } from '../dist';
|
|
2
|
-
import { Person } from './models';
|
|
3
|
-
|
|
4
|
-
const DB_JSON: IDbField = {
|
|
5
|
-
reader(raw: DbValueType): any {
|
|
6
|
-
return typeof raw === 'string' ? JSON.parse(raw) : raw;
|
|
7
|
-
},
|
|
8
|
-
writer(value: any): DbValueType {
|
|
9
|
-
return JSON.stringify(value);
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
function generatePersons(quantity: number): IQueryData[] {
|
|
14
|
-
const res = [];
|
|
15
|
-
for (let i = 1; i <= quantity; i++) {
|
|
16
|
-
const person = new Person();
|
|
17
|
-
person['id'] = i;
|
|
18
|
-
person['city'] = `TestCity${i}`;
|
|
19
|
-
person['age'] = 18;
|
|
20
|
-
person['name'] = `TestName${i}`;
|
|
21
|
-
person['uid'] = `uid${i}`;
|
|
22
|
-
// person['profiles'] = ['profile-a'];
|
|
23
|
-
res.push(person);
|
|
24
|
-
}
|
|
25
|
-
return res;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
describe('DbReader', () => {
|
|
29
|
-
|
|
30
|
-
const persons = generatePersons(5);
|
|
31
|
-
|
|
32
|
-
it('read raw', () => {
|
|
33
|
-
const result = reader(persons);
|
|
34
|
-
expect(result).toStrictEqual(persons);
|
|
35
|
-
result.map(person => {
|
|
36
|
-
expect(person).toBeInstanceOf(Person);
|
|
37
|
-
expect(person).toStrictEqual(persons.find(p => p.id === person.id))
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('read Model', () => {
|
|
42
|
-
@dbTable
|
|
43
|
-
class Model {
|
|
44
|
-
@dbField public readonly id!: number;
|
|
45
|
-
@dbField('raw') public readonly value!: string;
|
|
46
|
-
@dbField({kind: DB_JSON, model: [Person]}) public readonly personal!: Person[];
|
|
47
|
-
|
|
48
|
-
constructor(id, raw, personal) {
|
|
49
|
-
this.id = id;
|
|
50
|
-
this.value = raw;
|
|
51
|
-
this.personal = personal
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const model = {
|
|
56
|
-
id: "5",
|
|
57
|
-
raw: false,
|
|
58
|
-
personal: JSON.stringify(persons)
|
|
59
|
-
}
|
|
60
|
-
const expected = new Model(5, 'false', persons);
|
|
61
|
-
|
|
62
|
-
const results = reader([model], Model);
|
|
63
|
-
expect(results.length).toBe(1);
|
|
64
|
-
const [result] = results;
|
|
65
|
-
expect(result).toBeInstanceOf(Model);
|
|
66
|
-
expect(result).toEqual(expected);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('read Model from no data', () => {
|
|
70
|
-
@dbTable
|
|
71
|
-
class Model {
|
|
72
|
-
@dbField public readonly id!: number;
|
|
73
|
-
@dbField('raw') public readonly value!: string;
|
|
74
|
-
@dbField({kind: DB_JSON, model: [Person]}) public readonly personal!: Person[];
|
|
75
|
-
|
|
76
|
-
constructor(id, raw, personal) {
|
|
77
|
-
this.id = id;
|
|
78
|
-
this.value = raw;
|
|
79
|
-
this.personal = personal
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const results = reader([], Model);
|
|
84
|
-
expect(results.length).toBe(0);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('read scalar', () => {
|
|
88
|
-
const count = 10;
|
|
89
|
-
const correctResult = reader([{field: count}], true);
|
|
90
|
-
expect(correctResult).toBe(count);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('read scalar from no data', () => {
|
|
94
|
-
const fieldValue = 'string';
|
|
95
|
-
const emptyData = reader([], true);
|
|
96
|
-
expect(emptyData).toBe(0);
|
|
97
|
-
expect(() => {
|
|
98
|
-
reader([{field: fieldValue as any}], true)
|
|
99
|
-
}).toThrowError(`Invalid scalar "${fieldValue}", number expected.`);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('read scalar from invalid data', () => {
|
|
103
|
-
const fieldValue = 'string';
|
|
104
|
-
expect(() => {
|
|
105
|
-
reader([{field: fieldValue as any}], true)
|
|
106
|
-
}).toThrowError(`Invalid scalar "${fieldValue}", number expected.`);
|
|
107
|
-
});
|
|
108
|
-
});
|