@goatlab/fluent-formio 0.6.5 → 0.6.7
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/LICENSE +21 -0
- package/README.md +22 -4
- package/package.json +21 -108
- package/dist/FormioConnector.d.ts +0 -37
- package/dist/FormioConnector.js +0 -344
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -5
- package/dist/test/advanced/advancedTestSuite.d.ts +0 -1
- package/dist/test/advanced/advancedTestSuite.js +0 -114
- package/dist/test/advanced/typeOrm.entity.d.ts +0 -16
- package/dist/test/advanced/typeOrm.entity.js +0 -57
- package/dist/test/advanced/typeOrm.repository.d.ts +0 -5
- package/dist/test/advanced/typeOrm.repository.js +0 -11
- package/dist/test/basic/basicTestSuite.d.ts +0 -1
- package/dist/test/basic/basicTestSuite.js +0 -45
- package/dist/test/basic/goat.dto.d.ts +0 -8
- package/dist/test/basic/goat.dto.js +0 -18
- package/dist/test/basic/goat.entity.d.ts +0 -10
- package/dist/test/basic/goat.entity.js +0 -41
- package/dist/test/basic/goat.repository.d.ts +0 -6
- package/dist/test/basic/goat.repository.js +0 -11
- package/dist/test/flock.d.ts +0 -4
- package/dist/test/flock.js +0 -25
- package/dist/test/relations/car/car.dto.d.ts +0 -5
- package/dist/test/relations/car/car.dto.js +0 -12
- package/dist/test/relations/car/car.entity.d.ts +0 -7
- package/dist/test/relations/car/car.entity.js +0 -32
- package/dist/test/relations/car/car.repositoryTypeOrm.d.ts +0 -8
- package/dist/test/relations/car/car.repositoryTypeOrm.js +0 -13
- package/dist/test/relations/relationsTestsSuite.d.ts +0 -1
- package/dist/test/relations/relationsTestsSuite.js +0 -93
- package/dist/test/relations/roles/role.dto.d.ts +0 -5
- package/dist/test/relations/roles/role.dto.js +0 -12
- package/dist/test/relations/roles/roles.entity.d.ts +0 -6
- package/dist/test/relations/roles/roles.entity.js +0 -29
- package/dist/test/relations/roles/roles.repositoryTypeOrm.d.ts +0 -8
- package/dist/test/relations/roles/roles.repositoryTypeOrm.js +0 -14
- package/dist/test/relations/roles/roles_user.dto.d.ts +0 -5
- package/dist/test/relations/roles/roles_user.dto.js +0 -12
- package/dist/test/relations/roles/roles_user.entity.d.ts +0 -5
- package/dist/test/relations/roles/roles_user.entity.js +0 -23
- package/dist/test/relations/roles/roles_users.repositoryTypeOrm.d.ts +0 -6
- package/dist/test/relations/roles/roles_users.repositoryTypeOrm.js +0 -11
- package/dist/test/relations/user/user.dto.d.ts +0 -5
- package/dist/test/relations/user/user.dto.js +0 -12
- package/dist/test/relations/user/user.entity.d.ts +0 -14
- package/dist/test/relations/user/user.entity.js +0 -56
- package/dist/test/relations/user/user.repositoryTypeOrm.d.ts +0 -10
- package/dist/test/relations/user/user.repositoryTypeOrm.js +0 -16
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.advancedTestSuite = void 0;
|
|
4
|
-
const advancedTestSuite = Model => {
|
|
5
|
-
beforeAll(() => {
|
|
6
|
-
try {
|
|
7
|
-
Model = new Model();
|
|
8
|
-
}
|
|
9
|
-
catch (error) { }
|
|
10
|
-
});
|
|
11
|
-
const insertTestData = async (Repository) => {
|
|
12
|
-
await Repository.insert({
|
|
13
|
-
created: '2018-12-03',
|
|
14
|
-
nestedTest: {
|
|
15
|
-
a: [6, 5, 4],
|
|
16
|
-
b: { c: true, d: [2, 1, 0] },
|
|
17
|
-
c: 4
|
|
18
|
-
},
|
|
19
|
-
order: 1,
|
|
20
|
-
test: true
|
|
21
|
-
});
|
|
22
|
-
await Repository.insert({
|
|
23
|
-
created: '2017-12-03',
|
|
24
|
-
nestedTest: {
|
|
25
|
-
a: [3, 2, 1],
|
|
26
|
-
b: { c: true, d: [1, 1, 0] },
|
|
27
|
-
c: 3
|
|
28
|
-
},
|
|
29
|
-
order: 2,
|
|
30
|
-
test: false
|
|
31
|
-
});
|
|
32
|
-
await Repository.insert({
|
|
33
|
-
created: '2016-12-03',
|
|
34
|
-
nestedTest: {
|
|
35
|
-
a: [0, -1, -2],
|
|
36
|
-
b: { c: true, d: [0, 1, 0] },
|
|
37
|
-
c: 2
|
|
38
|
-
},
|
|
39
|
-
order: 3,
|
|
40
|
-
test: false
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
it('Should get local data', async () => {
|
|
44
|
-
await insertTestData(Model);
|
|
45
|
-
const data = await Model.all();
|
|
46
|
-
expect(Array.isArray(data)).toBe(true);
|
|
47
|
-
expect(typeof data[0].nestedTest.b.c).toBe('boolean');
|
|
48
|
-
});
|
|
49
|
-
it('pluck() should return a single array', async () => {
|
|
50
|
-
await insertTestData(Model);
|
|
51
|
-
const data = await Model.pluck(Model._keys.test);
|
|
52
|
-
expect(typeof data[0]).toBe('boolean');
|
|
53
|
-
});
|
|
54
|
-
it('orderBy() should order results desc', async () => {
|
|
55
|
-
await insertTestData(Model);
|
|
56
|
-
const forms = await Model.select(Model._keys.test, Model._keys.nestedTest.b.c, Model._keys.order)
|
|
57
|
-
.orderBy(Model._keys.order, 'desc')
|
|
58
|
-
.get();
|
|
59
|
-
expect(forms[0].order).toBe(3);
|
|
60
|
-
expect(forms[0].nestedTest.b.c).toBe(true);
|
|
61
|
-
});
|
|
62
|
-
it('orderBy() should order results asc', async () => {
|
|
63
|
-
await insertTestData(Model);
|
|
64
|
-
const forms = await Model.select(Model._keys.test, Model._keys.nestedTest.b.c, Model._keys.order)
|
|
65
|
-
.orderBy(Model._keys.order, 'asc')
|
|
66
|
-
.get();
|
|
67
|
-
expect(forms[0].order).toBe(1);
|
|
68
|
-
});
|
|
69
|
-
it('orderBy() should order by Dates with Select()', async () => {
|
|
70
|
-
await insertTestData(Model);
|
|
71
|
-
const forms = await Model.select(Model._keys.created, Model._keys.order)
|
|
72
|
-
.orderBy(Model._keys.created, 'asc', 'date')
|
|
73
|
-
.get();
|
|
74
|
-
expect(forms[0].order).toBe(3);
|
|
75
|
-
});
|
|
76
|
-
it('orderBy() should order by Dates without Select()', async () => {
|
|
77
|
-
await insertTestData(Model);
|
|
78
|
-
const forms = await Model.orderBy(Model._keys.created, 'asc', 'date').get();
|
|
79
|
-
expect(forms[0].order).toBe(3);
|
|
80
|
-
});
|
|
81
|
-
it('limit() should limit the amount of results', async () => {
|
|
82
|
-
await insertTestData(Model);
|
|
83
|
-
const forms = await Model.select(Model._keys.created, Model._keys.order)
|
|
84
|
-
.orderBy(Model._keys.created, 'asc', 'date')
|
|
85
|
-
.limit(2)
|
|
86
|
-
.get();
|
|
87
|
-
expect(forms.length > 0).toBe(true);
|
|
88
|
-
expect(forms.length <= 2).toBe(true);
|
|
89
|
-
});
|
|
90
|
-
it('offset() should start at the given position', async () => {
|
|
91
|
-
await insertTestData(Model);
|
|
92
|
-
const forms = await Model.select(Model._keys.created, Model._keys.order)
|
|
93
|
-
.offset(1)
|
|
94
|
-
.limit(1)
|
|
95
|
-
.get();
|
|
96
|
-
expect(forms.length).toBe(1);
|
|
97
|
-
});
|
|
98
|
-
it('where() should filter the data', async () => {
|
|
99
|
-
await insertTestData(Model);
|
|
100
|
-
const forms = await Model.where(Model._keys.nestedTest.c, '>=', 3).get();
|
|
101
|
-
expect(forms.length > 0).toBe(true);
|
|
102
|
-
forms.forEach(form => {
|
|
103
|
-
expect(form.nestedTest.c >= 3).toBe(true);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
it('first() should take the first result from data', async () => {
|
|
107
|
-
await insertTestData(Model);
|
|
108
|
-
const form = await Model.select(Model._keys.nestedTest.c, Model._keys.id)
|
|
109
|
-
.where(Model._keys.nestedTest.c, '>=', 3)
|
|
110
|
-
.first();
|
|
111
|
-
expect(typeof form.nestedTest.c).toBe('number');
|
|
112
|
-
});
|
|
113
|
-
};
|
|
114
|
-
exports.advancedTestSuite = advancedTestSuite;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export declare class FurtherNested {
|
|
2
|
-
c: boolean;
|
|
3
|
-
d: number[];
|
|
4
|
-
}
|
|
5
|
-
export declare class Nested {
|
|
6
|
-
a: number[];
|
|
7
|
-
c: number;
|
|
8
|
-
b?: FurtherNested;
|
|
9
|
-
}
|
|
10
|
-
export declare class TypeORMDataModel {
|
|
11
|
-
id: string;
|
|
12
|
-
created?: string;
|
|
13
|
-
nestedTest?: Nested;
|
|
14
|
-
order?: number;
|
|
15
|
-
test: boolean;
|
|
16
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TypeORMDataModel = exports.Nested = exports.FurtherNested = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const fluent_1 = require("@goatlab/fluent");
|
|
6
|
-
class FurtherNested {
|
|
7
|
-
}
|
|
8
|
-
tslib_1.__decorate([
|
|
9
|
-
fluent_1.Decorators.property({ required: true }),
|
|
10
|
-
tslib_1.__metadata("design:type", Boolean)
|
|
11
|
-
], FurtherNested.prototype, "c", void 0);
|
|
12
|
-
tslib_1.__decorate([
|
|
13
|
-
fluent_1.Decorators.array({ required: true }),
|
|
14
|
-
tslib_1.__metadata("design:type", Array)
|
|
15
|
-
], FurtherNested.prototype, "d", void 0);
|
|
16
|
-
exports.FurtherNested = FurtherNested;
|
|
17
|
-
class Nested {
|
|
18
|
-
}
|
|
19
|
-
tslib_1.__decorate([
|
|
20
|
-
fluent_1.Decorators.array({ required: true }),
|
|
21
|
-
tslib_1.__metadata("design:type", Array)
|
|
22
|
-
], Nested.prototype, "a", void 0);
|
|
23
|
-
tslib_1.__decorate([
|
|
24
|
-
fluent_1.Decorators.property({ required: true }),
|
|
25
|
-
tslib_1.__metadata("design:type", Number)
|
|
26
|
-
], Nested.prototype, "c", void 0);
|
|
27
|
-
tslib_1.__decorate([
|
|
28
|
-
fluent_1.Decorators.embed(FurtherNested),
|
|
29
|
-
tslib_1.__metadata("design:type", FurtherNested)
|
|
30
|
-
], Nested.prototype, "b", void 0);
|
|
31
|
-
exports.Nested = Nested;
|
|
32
|
-
let TypeORMDataModel = class TypeORMDataModel {
|
|
33
|
-
};
|
|
34
|
-
tslib_1.__decorate([
|
|
35
|
-
fluent_1.Decorators.id(),
|
|
36
|
-
tslib_1.__metadata("design:type", String)
|
|
37
|
-
], TypeORMDataModel.prototype, "id", void 0);
|
|
38
|
-
tslib_1.__decorate([
|
|
39
|
-
fluent_1.Decorators.property({ required: false }),
|
|
40
|
-
tslib_1.__metadata("design:type", String)
|
|
41
|
-
], TypeORMDataModel.prototype, "created", void 0);
|
|
42
|
-
tslib_1.__decorate([
|
|
43
|
-
fluent_1.Decorators.embed(Nested),
|
|
44
|
-
tslib_1.__metadata("design:type", Nested)
|
|
45
|
-
], TypeORMDataModel.prototype, "nestedTest", void 0);
|
|
46
|
-
tslib_1.__decorate([
|
|
47
|
-
fluent_1.Decorators.property({ required: false }),
|
|
48
|
-
tslib_1.__metadata("design:type", Number)
|
|
49
|
-
], TypeORMDataModel.prototype, "order", void 0);
|
|
50
|
-
tslib_1.__decorate([
|
|
51
|
-
fluent_1.Decorators.property({ required: true }),
|
|
52
|
-
tslib_1.__metadata("design:type", Boolean)
|
|
53
|
-
], TypeORMDataModel.prototype, "test", void 0);
|
|
54
|
-
TypeORMDataModel = tslib_1.__decorate([
|
|
55
|
-
fluent_1.Decorators.entity('numbers')
|
|
56
|
-
], TypeORMDataModel);
|
|
57
|
-
exports.TypeORMDataModel = TypeORMDataModel;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TypeOrmRepository = void 0;
|
|
4
|
-
const typeOrm_entity_1 = require("./typeOrm.entity");
|
|
5
|
-
const fluent_1 = require("@goatlab/fluent");
|
|
6
|
-
class TypeOrmRepository extends fluent_1.TypeOrmConnector {
|
|
7
|
-
constructor(relations) {
|
|
8
|
-
super(typeOrm_entity_1.TypeORMDataModel, relations, 'runningTest');
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.TypeOrmRepository = TypeOrmRepository;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const basicTestSuite: (Model: any) => void;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.basicTestSuite = void 0;
|
|
4
|
-
const flock_1 = require("../flock");
|
|
5
|
-
const basicTestSuite = Model => {
|
|
6
|
-
let storedId;
|
|
7
|
-
beforeAll(() => {
|
|
8
|
-
Model = new Model();
|
|
9
|
-
});
|
|
10
|
-
test('Get - Should GET data', async () => {
|
|
11
|
-
const storedGoats = await Model.get();
|
|
12
|
-
expect(Array.isArray(storedGoats)).toBe(true);
|
|
13
|
-
});
|
|
14
|
-
test('Insert - Should insert data', async () => {
|
|
15
|
-
const a = await Model.insert({ name: 'myGoat', age: 13 });
|
|
16
|
-
expect(typeof a.id).toBe('string');
|
|
17
|
-
expect(a.name).toBe('myGoat');
|
|
18
|
-
expect(0).toBe(0);
|
|
19
|
-
});
|
|
20
|
-
it('Create Multiple - Should insert Multiple elements', async () => {
|
|
21
|
-
const insertedFlock = await Model.insertMany(flock_1.flock);
|
|
22
|
-
expect(insertedFlock[0].name).toBe('Goatee');
|
|
23
|
-
storedId = insertedFlock[0].id;
|
|
24
|
-
});
|
|
25
|
-
it('UpdateById - Should Update a single element', async () => {
|
|
26
|
-
await Model.insertMany(flock_1.flock);
|
|
27
|
-
const goats = await Model.get();
|
|
28
|
-
const data = await Model.updateById(goats[0].id, {
|
|
29
|
-
age: 99,
|
|
30
|
-
name: 'MyUpdatedGoat'
|
|
31
|
-
});
|
|
32
|
-
expect(data.name).toBe('MyUpdatedGoat');
|
|
33
|
-
expect(data.id).toBe(goats[0].id);
|
|
34
|
-
});
|
|
35
|
-
it('ReplaceById - Should Update a single element', async () => {
|
|
36
|
-
await Model.insertMany(flock_1.flock);
|
|
37
|
-
const goats = await Model.get();
|
|
38
|
-
const data = await Model.updateById(goats[0].id, {
|
|
39
|
-
name: 'MyUpdatedGoat'
|
|
40
|
-
});
|
|
41
|
-
expect(data.name).toBe('MyUpdatedGoat');
|
|
42
|
-
expect(data.id).toBe(goats[0].id);
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
exports.basicTestSuite = basicTestSuite;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { GoatEntity } from './goat.entity';
|
|
2
|
-
declare const GoatEntityOut_base: import("@goatlab/fluent/dist/core/Nestjs/types/common").Type<Omit<GoatEntity, never>>;
|
|
3
|
-
export declare class GoatEntityOut extends GoatEntityOut_base {
|
|
4
|
-
}
|
|
5
|
-
declare const GoatEntityIn_base: import("@goatlab/fluent/dist/core/Nestjs/types/common").Type<Omit<GoatEntity, "id">>;
|
|
6
|
-
export declare class GoatEntityIn extends GoatEntityIn_base {
|
|
7
|
-
}
|
|
8
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GoatEntityIn = exports.GoatEntityOut = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const goat_entity_1 = require("./goat.entity");
|
|
6
|
-
const fluent_1 = require("@goatlab/fluent");
|
|
7
|
-
let GoatEntityOut = class GoatEntityOut extends (0, fluent_1.OmitType)(goat_entity_1.GoatEntity, []) {
|
|
8
|
-
};
|
|
9
|
-
GoatEntityOut = tslib_1.__decorate([
|
|
10
|
-
(0, fluent_1.InputType)()
|
|
11
|
-
], GoatEntityOut);
|
|
12
|
-
exports.GoatEntityOut = GoatEntityOut;
|
|
13
|
-
let GoatEntityIn = class GoatEntityIn extends (0, fluent_1.OmitType)(goat_entity_1.GoatEntity, ['id']) {
|
|
14
|
-
};
|
|
15
|
-
GoatEntityIn = tslib_1.__decorate([
|
|
16
|
-
(0, fluent_1.InputType)()
|
|
17
|
-
], GoatEntityIn);
|
|
18
|
-
exports.GoatEntityIn = GoatEntityIn;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GoatEntity = exports.Breed = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const fluent_1 = require("@goatlab/fluent");
|
|
6
|
-
let Breed = class Breed {
|
|
7
|
-
};
|
|
8
|
-
tslib_1.__decorate([
|
|
9
|
-
fluent_1.Decorators.property({ required: false }),
|
|
10
|
-
tslib_1.__metadata("design:type", String)
|
|
11
|
-
], Breed.prototype, "family", void 0);
|
|
12
|
-
tslib_1.__decorate([
|
|
13
|
-
fluent_1.Decorators.property({ required: false }),
|
|
14
|
-
tslib_1.__metadata("design:type", Number)
|
|
15
|
-
], Breed.prototype, "members", void 0);
|
|
16
|
-
Breed = tslib_1.__decorate([
|
|
17
|
-
(0, fluent_1.ObjectType)()
|
|
18
|
-
], Breed);
|
|
19
|
-
exports.Breed = Breed;
|
|
20
|
-
let GoatEntity = class GoatEntity {
|
|
21
|
-
};
|
|
22
|
-
tslib_1.__decorate([
|
|
23
|
-
fluent_1.Decorators.id(),
|
|
24
|
-
tslib_1.__metadata("design:type", String)
|
|
25
|
-
], GoatEntity.prototype, "id", void 0);
|
|
26
|
-
tslib_1.__decorate([
|
|
27
|
-
fluent_1.Decorators.property({ required: true }),
|
|
28
|
-
tslib_1.__metadata("design:type", String)
|
|
29
|
-
], GoatEntity.prototype, "name", void 0);
|
|
30
|
-
tslib_1.__decorate([
|
|
31
|
-
fluent_1.Decorators.property({ required: false }),
|
|
32
|
-
tslib_1.__metadata("design:type", Number)
|
|
33
|
-
], GoatEntity.prototype, "age", void 0);
|
|
34
|
-
tslib_1.__decorate([
|
|
35
|
-
fluent_1.Decorators.embed(Breed),
|
|
36
|
-
tslib_1.__metadata("design:type", Breed)
|
|
37
|
-
], GoatEntity.prototype, "breed", void 0);
|
|
38
|
-
GoatEntity = tslib_1.__decorate([
|
|
39
|
-
fluent_1.Decorators.entity('goat')
|
|
40
|
-
], GoatEntity);
|
|
41
|
-
exports.GoatEntity = GoatEntity;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { GoatEntityIn, GoatEntityOut } from './goat.dto';
|
|
2
|
-
import { GoatEntity } from './goat.entity';
|
|
3
|
-
import { TypeOrmConnector } from '@goatlab/fluent';
|
|
4
|
-
export declare class GoatRepository extends TypeOrmConnector<GoatEntity, GoatEntityIn, GoatEntityOut> {
|
|
5
|
-
constructor(relations?: any);
|
|
6
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GoatRepository = void 0;
|
|
4
|
-
const goat_entity_1 = require("./goat.entity");
|
|
5
|
-
const fluent_1 = require("@goatlab/fluent");
|
|
6
|
-
class GoatRepository extends fluent_1.TypeOrmConnector {
|
|
7
|
-
constructor(relations) {
|
|
8
|
-
super(goat_entity_1.GoatEntity, relations, 'runningTest');
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.GoatRepository = GoatRepository;
|
package/dist/test/flock.d.ts
DELETED
package/dist/test/flock.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.flock = void 0;
|
|
4
|
-
exports.flock = [
|
|
5
|
-
{
|
|
6
|
-
age: 3,
|
|
7
|
-
name: 'Goatee'
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
age: 4,
|
|
11
|
-
name: 'GoaToHell'
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
age: 5,
|
|
15
|
-
name: 'Oh!MyGoat'
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
age: 3,
|
|
19
|
-
name: 'A'
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
age: 2,
|
|
23
|
-
name: 'B'
|
|
24
|
-
}
|
|
25
|
-
];
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CarsEntityIn = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const fluent_1 = require("@goatlab/fluent");
|
|
6
|
-
const car_entity_1 = require("./car.entity");
|
|
7
|
-
let CarsEntityIn = class CarsEntityIn extends (0, fluent_1.OmitType)(car_entity_1.CarsEntity, ['id']) {
|
|
8
|
-
};
|
|
9
|
-
CarsEntityIn = tslib_1.__decorate([
|
|
10
|
-
(0, fluent_1.InputType)()
|
|
11
|
-
], CarsEntityIn);
|
|
12
|
-
exports.CarsEntityIn = CarsEntityIn;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CarsEntity = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const fluent_1 = require("@goatlab/fluent");
|
|
6
|
-
const user_entity_1 = require("../user/user.entity");
|
|
7
|
-
let CarsEntity = class CarsEntity {
|
|
8
|
-
};
|
|
9
|
-
tslib_1.__decorate([
|
|
10
|
-
fluent_1.Decorators.id(),
|
|
11
|
-
tslib_1.__metadata("design:type", String)
|
|
12
|
-
], CarsEntity.prototype, "id", void 0);
|
|
13
|
-
tslib_1.__decorate([
|
|
14
|
-
fluent_1.Decorators.property({ required: true }),
|
|
15
|
-
tslib_1.__metadata("design:type", String)
|
|
16
|
-
], CarsEntity.prototype, "name", void 0);
|
|
17
|
-
tslib_1.__decorate([
|
|
18
|
-
fluent_1.Decorators.property({ required: true }),
|
|
19
|
-
tslib_1.__metadata("design:type", String)
|
|
20
|
-
], CarsEntity.prototype, "userId", void 0);
|
|
21
|
-
tslib_1.__decorate([
|
|
22
|
-
fluent_1.Decorators.belongsTo({
|
|
23
|
-
entity: () => user_entity_1.UsersEntity,
|
|
24
|
-
inverse: user => user.cars,
|
|
25
|
-
pivotColumnName: 'userId'
|
|
26
|
-
}),
|
|
27
|
-
tslib_1.__metadata("design:type", user_entity_1.UsersEntity)
|
|
28
|
-
], CarsEntity.prototype, "user", void 0);
|
|
29
|
-
CarsEntity = tslib_1.__decorate([
|
|
30
|
-
fluent_1.Decorators.entity('cars')
|
|
31
|
-
], CarsEntity);
|
|
32
|
-
exports.CarsEntity = CarsEntity;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { CarsEntity } from './car.entity';
|
|
2
|
-
import { CarsEntityIn } from './car.dto';
|
|
3
|
-
import { TypeOrmConnector } from '@goatlab/fluent';
|
|
4
|
-
import { UserRepository } from '../user/user.repositoryTypeOrm';
|
|
5
|
-
export declare class CarsRepository extends TypeOrmConnector<CarsEntity, CarsEntityIn> {
|
|
6
|
-
constructor(relationQuery?: any);
|
|
7
|
-
user: () => UserRepository;
|
|
8
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CarsRepository = void 0;
|
|
4
|
-
const car_entity_1 = require("./car.entity");
|
|
5
|
-
const fluent_1 = require("@goatlab/fluent");
|
|
6
|
-
const user_repositoryTypeOrm_1 = require("../user/user.repositoryTypeOrm");
|
|
7
|
-
class CarsRepository extends fluent_1.TypeOrmConnector {
|
|
8
|
-
constructor(relationQuery) {
|
|
9
|
-
super(car_entity_1.CarsEntity, relationQuery, 'runningTest');
|
|
10
|
-
this.user = () => this.belongsTo(user_repositoryTypeOrm_1.UserRepository, 'user');
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.CarsRepository = CarsRepository;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const relationsTestSuite: (Model: any, BelongsToModel: any, ManyToManyModel: any) => void;
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.relationsTestSuite = void 0;
|
|
4
|
-
const relationsTestSuite = (Model, BelongsToModel, ManyToManyModel) => {
|
|
5
|
-
beforeAll(() => {
|
|
6
|
-
Model = new Model();
|
|
7
|
-
BelongsToModel = new BelongsToModel();
|
|
8
|
-
ManyToManyModel = new ManyToManyModel();
|
|
9
|
-
});
|
|
10
|
-
test('Attach - OneToMany - Should insert data', async () => {
|
|
11
|
-
const insertedUser = await Model.insert({
|
|
12
|
-
name: 'testUser',
|
|
13
|
-
age: 20
|
|
14
|
-
});
|
|
15
|
-
expect(typeof insertedUser.id).toBe('string');
|
|
16
|
-
const user = await Model.where(Model.cars()._keys.id, '=', insertedUser.id).load();
|
|
17
|
-
const cars = await user.cars().attach({ name: 'Another new car' });
|
|
18
|
-
expect(Array.isArray(cars)).toBe(true);
|
|
19
|
-
expect(cars[0].name).toBe('Another new car');
|
|
20
|
-
});
|
|
21
|
-
test('Query related model - OneToMany', async () => {
|
|
22
|
-
const insertedUser = await Model.insert({
|
|
23
|
-
name: 'testUser',
|
|
24
|
-
age: 20
|
|
25
|
-
});
|
|
26
|
-
expect(typeof insertedUser.id).toBe('string');
|
|
27
|
-
const user1 = await Model.where(Model._keys.id, '=', insertedUser.id).load();
|
|
28
|
-
const cars = await user1.cars().attach({ name: 'My new car' });
|
|
29
|
-
expect(Array.isArray(cars)).toBe(true);
|
|
30
|
-
const searchUserWithRelation = await Model.where(Model._keys.id, '=', insertedUser.id)
|
|
31
|
-
.with({ cars: true })
|
|
32
|
-
.get();
|
|
33
|
-
expect(Array.isArray(searchUserWithRelation[0].cars)).toBe(true);
|
|
34
|
-
expect(searchUserWithRelation[0].cars.length > 0).toBe(true);
|
|
35
|
-
const searchCar = await user1
|
|
36
|
-
.cars()
|
|
37
|
-
.where(Model.cars()._keys.name, '=', 'My new car')
|
|
38
|
-
.get();
|
|
39
|
-
expect(Array.isArray(searchCar)).toBe(true);
|
|
40
|
-
expect(searchCar.length > 0).toBe(true);
|
|
41
|
-
const searchCar2 = await user1
|
|
42
|
-
.cars()
|
|
43
|
-
.where(Model.cars()._keys.name, '=', 'My.......')
|
|
44
|
-
.get();
|
|
45
|
-
expect(Array.isArray(searchCar2)).toBe(true);
|
|
46
|
-
expect(searchCar2.length === 0).toBe(true);
|
|
47
|
-
});
|
|
48
|
-
test('Query related model - BelongTo', async () => {
|
|
49
|
-
const insertedUser = await Model.insert({
|
|
50
|
-
name: 'testUser',
|
|
51
|
-
age: 20
|
|
52
|
-
});
|
|
53
|
-
expect(typeof insertedUser.id).toBe('string');
|
|
54
|
-
const user1 = await Model.where(Model.cars()._keys.id, '=', insertedUser.id).load();
|
|
55
|
-
await user1.cars().attach({ name: 'My new car' });
|
|
56
|
-
const results = await BelongsToModel.with({ users: true }).get();
|
|
57
|
-
expect(Array.isArray(results)).toBe(true);
|
|
58
|
-
expect(results.length > 0).toBe(true);
|
|
59
|
-
expect(typeof results[0].user.name).toBe('string');
|
|
60
|
-
});
|
|
61
|
-
test('Query related model - ManyToMany', async () => {
|
|
62
|
-
const insertedUser = await Model.insert({
|
|
63
|
-
name: 'testUser',
|
|
64
|
-
age: 20
|
|
65
|
-
});
|
|
66
|
-
expect(typeof insertedUser.id).toBe('string');
|
|
67
|
-
const adminRole = await ManyToManyModel.insert({
|
|
68
|
-
name: 'Administrator'
|
|
69
|
-
});
|
|
70
|
-
const user = await Model.where(Model._keys.id, '=', insertedUser.id).load();
|
|
71
|
-
const associated = await user.roles().associate(adminRole.id);
|
|
72
|
-
expect(associated[0].userId).toBe(insertedUser.id);
|
|
73
|
-
expect(associated[0].roleId).toBe(adminRole.id);
|
|
74
|
-
const searchUserWithRelation = await Model.where(Model._keys.id, '=', insertedUser.id)
|
|
75
|
-
.with({
|
|
76
|
-
roles: true
|
|
77
|
-
})
|
|
78
|
-
.get();
|
|
79
|
-
expect(Array.isArray(searchUserWithRelation[0].roles)).toBe(true);
|
|
80
|
-
expect(searchUserWithRelation[0].roles.length > 0).toBe(true);
|
|
81
|
-
expect(typeof searchUserWithRelation[0].roles[0].name).toBe('string');
|
|
82
|
-
const roles = await ManyToManyModel.where(ManyToManyModel._keys.name, '=', 'Administrator')
|
|
83
|
-
.with({
|
|
84
|
-
users: true
|
|
85
|
-
})
|
|
86
|
-
.get();
|
|
87
|
-
expect(Array.isArray(roles)).toBe(true);
|
|
88
|
-
expect(roles.length > 0).toBe(true);
|
|
89
|
-
expect(typeof roles[0].users[0].name).toBe('string');
|
|
90
|
-
expect(typeof roles[0].users[0].age).toBe('number');
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
exports.relationsTestSuite = relationsTestSuite;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RoleEntityIn = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const fluent_1 = require("@goatlab/fluent");
|
|
6
|
-
const roles_entity_1 = require("./roles.entity");
|
|
7
|
-
let RoleEntityIn = class RoleEntityIn extends (0, fluent_1.OmitType)(roles_entity_1.RoleEntity, ['id']) {
|
|
8
|
-
};
|
|
9
|
-
RoleEntityIn = tslib_1.__decorate([
|
|
10
|
-
(0, fluent_1.InputType)()
|
|
11
|
-
], RoleEntityIn);
|
|
12
|
-
exports.RoleEntityIn = RoleEntityIn;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RoleEntity = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const fluent_1 = require("@goatlab/fluent");
|
|
6
|
-
const user_entity_1 = require("../user/user.entity");
|
|
7
|
-
let RoleEntity = class RoleEntity {
|
|
8
|
-
};
|
|
9
|
-
tslib_1.__decorate([
|
|
10
|
-
fluent_1.Decorators.id(),
|
|
11
|
-
tslib_1.__metadata("design:type", String)
|
|
12
|
-
], RoleEntity.prototype, "id", void 0);
|
|
13
|
-
tslib_1.__decorate([
|
|
14
|
-
fluent_1.Decorators.property({ required: true }),
|
|
15
|
-
tslib_1.__metadata("design:type", String)
|
|
16
|
-
], RoleEntity.prototype, "name", void 0);
|
|
17
|
-
tslib_1.__decorate([
|
|
18
|
-
fluent_1.Decorators.belongsToMany({
|
|
19
|
-
entity: () => user_entity_1.UsersEntity,
|
|
20
|
-
joinTableName: 'roles_users',
|
|
21
|
-
foreignKey: 'roleId',
|
|
22
|
-
inverseForeignKey: 'userId'
|
|
23
|
-
}),
|
|
24
|
-
tslib_1.__metadata("design:type", Array)
|
|
25
|
-
], RoleEntity.prototype, "users", void 0);
|
|
26
|
-
RoleEntity = tslib_1.__decorate([
|
|
27
|
-
fluent_1.Decorators.entity('roles')
|
|
28
|
-
], RoleEntity);
|
|
29
|
-
exports.RoleEntity = RoleEntity;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { RoleEntity } from './roles.entity';
|
|
2
|
-
import { RoleEntityIn } from './role.dto';
|
|
3
|
-
import { TypeOrmConnector } from '@goatlab/fluent';
|
|
4
|
-
import { UserRepository } from '../user/user.repositoryTypeOrm';
|
|
5
|
-
export declare class RoleRepository extends TypeOrmConnector<RoleEntity, RoleEntityIn> {
|
|
6
|
-
constructor(relations?: any);
|
|
7
|
-
users: () => UserRepository;
|
|
8
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RoleRepository = void 0;
|
|
4
|
-
const roles_entity_1 = require("./roles.entity");
|
|
5
|
-
const roles_users_repositoryTypeOrm_1 = require("./roles_users.repositoryTypeOrm");
|
|
6
|
-
const fluent_1 = require("@goatlab/fluent");
|
|
7
|
-
const user_repositoryTypeOrm_1 = require("../user/user.repositoryTypeOrm");
|
|
8
|
-
class RoleRepository extends fluent_1.TypeOrmConnector {
|
|
9
|
-
constructor(relations) {
|
|
10
|
-
super(roles_entity_1.RoleEntity, relations, 'runningTest');
|
|
11
|
-
this.users = () => this.belongsToMany(user_repositoryTypeOrm_1.UserRepository, roles_users_repositoryTypeOrm_1.RoleUsersRepository, 'users');
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
exports.RoleRepository = RoleRepository;
|