remult 0.14.4 → 0.14.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/assign.js +1 -5
- package/classType.js +1 -2
- package/graphql.js +84 -146
- package/index.js +25 -73
- package/inputTypes.js +9 -16
- package/package.json +2 -1
- package/postgres/index.js +1 -4
- package/postgres/postgres-data-provider.js +165 -364
- package/postgres/postgresColumnSyntax.js +4 -8
- package/remult-express.js +6 -10
- package/remult-knex/index.js +300 -720
- package/remult-middleware.js +24 -30
- package/remult-mongo.js +172 -406
- package/server/JsonEntityFileStorage.js +10 -15
- package/server/expressBridge.js +383 -569
- package/server/index.js +4 -11
- package/server/register-actions-on-server.js +12 -38
- package/server/register-entities-on-server.js +9 -13
- package/src/__EntityValueProvider.js +1 -2
- package/src/__RowsOfDataForTesting.js +1 -2
- package/src/backend-tests/backend-database-test-setup.backend-spec.js +72 -190
- package/src/backend-tests/my-test.backend-spec.js +45 -114
- package/src/column-interfaces.js +2 -6
- package/src/column.js +71 -113
- package/src/context.js +174 -330
- package/src/data-api.js +162 -326
- package/src/data-interfaces.js +7 -11
- package/src/data-providers/array-entity-data-provider.js +171 -286
- package/src/data-providers/in-memory-database.js +12 -27
- package/src/data-providers/json-data-provider.js +41 -77
- package/src/data-providers/rest-data-provider.js +102 -189
- package/src/data-providers/sql-database.js +223 -403
- package/src/data-providers/web-sql-data-provider.js +78 -139
- package/src/entity.js +1 -2
- package/src/filter/filter-consumer-bridge-to-sql-request.js +106 -248
- package/src/filter/filter-consumer-bridge-to-url-builder.js +1 -2
- package/src/filter/filter-interfaces.js +277 -440
- package/src/id-entity.js +8 -17
- package/src/remult3/RepositoryImplementation.js +1191 -2367
- package/src/remult3/index.js +2 -5
- package/src/remult3/remult3.js +1 -2
- package/src/server-action.js +294 -528
- package/src/shared-tests/db-tests-setup.js +49 -153
- package/src/shared-tests/db-tests.db-tests.js +660 -1566
- package/src/shared-tests/deleteAll.js +3 -20
- package/src/shared-tests/entityWithValidations.js +52 -79
- package/src/shared-tests/index.js +4 -6
- package/src/shared-tests/test-custom-id-column.spec.js +37 -85
- package/src/shared-tests/test-special-value.spec.js +64 -104
- package/src/shared-tests/test-update-with-null.spec.js +28 -49
- package/src/sort.js +38 -95
- package/src/sql-command.js +1 -2
- package/src/tests/Done.js +7 -13
- package/src/tests/TestDataApiResponse.js +15 -22
- package/src/tests/c.js +21 -27
- package/src/tests/createData.js +20 -48
- package/src/tests/d.js +19 -27
- package/src/tests/dWithPrefilter.js +31 -44
- package/src/tests/entityForCustomFilter.js +42 -66
- package/src/tests/entityWithValidationsOnColumn.js +21 -29
- package/src/tests/frontend-database-tests-setup.spec.js +35 -98
- package/src/tests/h.js +35 -44
- package/src/tests/remult-3-entities.js +71 -80
- package/src/tests/tasks.js +23 -29
- package/src/tests/testHelper.spec.js +170 -322
- package/src/tests/testModel/models.js +25 -33
- package/src/validators.js +32 -59
- package/urlBuilder.js +8 -14
- package/valueConverters.js +161 -160
|
@@ -1,1629 +1,723 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
db_tests_setup_1.testAll("what", function (_a) {
|
|
25
|
-
var remult = _a.remult, createEntity = _a.createEntity;
|
|
26
|
-
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
27
|
-
var _b;
|
|
28
|
-
return tslib_1.__generator(this, function (_c) {
|
|
29
|
-
switch (_c.label) {
|
|
30
|
-
case 0: return [4 /*yield*/, createEntity(stam)];
|
|
31
|
-
case 1: return [4 /*yield*/, (_c.sent()).create({ id: 1, title: 'noam' }).save()];
|
|
32
|
-
case 2:
|
|
33
|
-
_c.sent();
|
|
34
|
-
_b = expect;
|
|
35
|
-
return [4 /*yield*/, remult.repo(stam).count()];
|
|
36
|
-
case 3:
|
|
37
|
-
_b.apply(void 0, [_c.sent()]).toBe(1);
|
|
38
|
-
return [2 /*return*/];
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
});
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { DataApi } from "../data-api";
|
|
3
|
+
import { Fields, Entity, EntityBase, Field } from "../remult3";
|
|
4
|
+
import { c } from "../tests/c";
|
|
5
|
+
import { Done } from "../tests/Done";
|
|
6
|
+
import { h } from "../tests/h";
|
|
7
|
+
import { Categories as newCategories } from "../tests/remult-3-entities";
|
|
8
|
+
import { tasks } from "../tests/tasks";
|
|
9
|
+
import { TestDataApiResponse } from "../tests/TestDataApiResponse";
|
|
10
|
+
import { testAll, testAllDbs } from "./db-tests-setup";
|
|
11
|
+
import { entityWithValidations, testConfiguration } from "./entityWithValidations";
|
|
12
|
+
import { Remult } from "../context";
|
|
13
|
+
import { dWithPrefilter } from "../tests/dWithPrefilter";
|
|
14
|
+
import { entityFilterToJson, Filter } from "../filter/filter-interfaces";
|
|
15
|
+
import { d } from "../tests/d";
|
|
16
|
+
import { entityForCustomFilter1 } from "../tests/entityForCustomFilter";
|
|
17
|
+
import { entityWithValidationsOnColumn } from "../tests/entityWithValidationsOnColumn";
|
|
18
|
+
import { Validators } from "../validators";
|
|
19
|
+
import { Status } from "../tests/testModel/models";
|
|
20
|
+
import { IdEntity } from "../id-entity";
|
|
21
|
+
testAll("what", async ({ remult, createEntity }) => {
|
|
22
|
+
await (await createEntity(stam)).create({ id: 1, title: 'noam' }).save();
|
|
23
|
+
expect(await remult.repo(stam).count()).toBe(1);
|
|
42
24
|
}, false);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var s, _b;
|
|
47
|
-
return tslib_1.__generator(this, function (_c) {
|
|
48
|
-
switch (_c.label) {
|
|
49
|
-
case 0: return [4 /*yield*/, entityWithValidations_1.entityWithValidations.create4RowsInDp(createEntity)];
|
|
50
|
-
case 1:
|
|
51
|
-
s = _c.sent();
|
|
52
|
-
_b = expect;
|
|
53
|
-
return [4 /*yield*/, s.find({ where: { myId: [1, 3] } })];
|
|
54
|
-
case 2:
|
|
55
|
-
_b.apply(void 0, [(_c.sent()).length]).toBe(2);
|
|
56
|
-
return [2 /*return*/];
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
});
|
|
25
|
+
testAll("filter works on all db", async ({ createEntity }) => {
|
|
26
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
27
|
+
expect((await s.find({ where: { myId: [1, 3] } })).length).toBe(2);
|
|
60
28
|
}, false);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
var repo, _b;
|
|
65
|
-
return tslib_1.__generator(this, function (_c) {
|
|
66
|
-
switch (_c.label) {
|
|
67
|
-
case 0: return [4 /*yield*/, entityWithValidations_1.entityWithValidations.create4RowsInDp(createEntity)];
|
|
68
|
-
case 1:
|
|
69
|
-
repo = _c.sent();
|
|
70
|
-
_b = expect;
|
|
71
|
-
return [4 /*yield*/, repo.count({ myId: [1, 3], $and: [{ myId: [3] }] })];
|
|
72
|
-
case 2:
|
|
73
|
-
_b.apply(void 0, [_c.sent()]).toBe(1);
|
|
74
|
-
return [2 /*return*/];
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
});
|
|
29
|
+
testAll("test in statement and ", async ({ createEntity }) => {
|
|
30
|
+
const repo = await entityWithValidations.create4RowsInDp(createEntity);
|
|
31
|
+
expect(await repo.count({ myId: [1, 3], $and: [{ myId: [3] }] })).toBe(1);
|
|
78
32
|
}, false);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
var s, _b;
|
|
83
|
-
return tslib_1.__generator(this, function (_c) {
|
|
84
|
-
switch (_c.label) {
|
|
85
|
-
case 0: return [4 /*yield*/, entityWithValidations_1.entityWithValidations.create4RowsInDp(createEntity)];
|
|
86
|
-
case 1:
|
|
87
|
-
s = _c.sent();
|
|
88
|
-
_b = expect;
|
|
89
|
-
return [4 /*yield*/, s.find({ where: { $and: [{ myId: 1 }, { myId: 3 }] } })];
|
|
90
|
-
case 2:
|
|
91
|
-
_b.apply(void 0, [(_c.sent()).length]).toBe(0);
|
|
92
|
-
return [2 /*return*/];
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
});
|
|
33
|
+
testAll("filter with and", async ({ createEntity }) => {
|
|
34
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
35
|
+
expect((await s.find({ where: { $and: [{ myId: 1 }, { myId: 3 }] } })).length).toBe(0);
|
|
96
36
|
}, false);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
var s, _b;
|
|
101
|
-
return tslib_1.__generator(this, function (_c) {
|
|
102
|
-
switch (_c.label) {
|
|
103
|
-
case 0: return [4 /*yield*/, entityWithValidations_1.entityWithValidations.create4RowsInDp(createEntity)];
|
|
104
|
-
case 1:
|
|
105
|
-
s = _c.sent();
|
|
106
|
-
_b = expect;
|
|
107
|
-
return [4 /*yield*/, s.find({ where: { myId: [] } })];
|
|
108
|
-
case 2:
|
|
109
|
-
_b.apply(void 0, [(_c.sent()).length]).toBe(0);
|
|
110
|
-
return [2 /*return*/];
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
});
|
|
37
|
+
testAll("test empty in", async ({ createEntity }) => {
|
|
38
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
39
|
+
expect((await s.find({ where: { myId: [] } })).length).toBe(0);
|
|
114
40
|
}, false);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
var s, _b;
|
|
119
|
-
return tslib_1.__generator(this, function (_c) {
|
|
120
|
-
switch (_c.label) {
|
|
121
|
-
case 0: return [4 /*yield*/, entityWithValidations_1.entityWithValidations.create4RowsInDp(createEntity)];
|
|
122
|
-
case 1:
|
|
123
|
-
s = _c.sent();
|
|
124
|
-
_b = expect;
|
|
125
|
-
return [4 /*yield*/, s.find({ where: { $or: [{ myId: 1 }, { myId: 3 }] } })];
|
|
126
|
-
case 2:
|
|
127
|
-
_b.apply(void 0, [(_c.sent()).length]).toBe(2);
|
|
128
|
-
return [2 /*return*/];
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
});
|
|
41
|
+
testAll("filter works on all db or", async ({ createEntity }) => {
|
|
42
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
43
|
+
expect((await s.find({ where: { $or: [{ myId: 1 }, { myId: 3 }] } })).length).toBe(2);
|
|
132
44
|
}, false);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
var s, _b;
|
|
137
|
-
return tslib_1.__generator(this, function (_c) {
|
|
138
|
-
switch (_c.label) {
|
|
139
|
-
case 0: return [4 /*yield*/, entityWithValidations_1.entityWithValidations.create4RowsInDp(createEntity)];
|
|
140
|
-
case 1:
|
|
141
|
-
s = _c.sent();
|
|
142
|
-
_b = expect;
|
|
143
|
-
return [4 /*yield*/, s.find({ where: { $or: [{}, {}] } })];
|
|
144
|
-
case 2:
|
|
145
|
-
_b.apply(void 0, [(_c.sent()).length]).toBe(4);
|
|
146
|
-
return [2 /*return*/];
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
});
|
|
45
|
+
testAll("filter works on all db or_1", async ({ createEntity }) => {
|
|
46
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
47
|
+
expect((await s.find({ where: { $or: [{}, {}] } })).length).toBe(4);
|
|
150
48
|
}, false);
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
var s, _b;
|
|
155
|
-
return tslib_1.__generator(this, function (_c) {
|
|
156
|
-
switch (_c.label) {
|
|
157
|
-
case 0: return [4 /*yield*/, entityWithValidations_1.entityWithValidations.create4RowsInDp(createEntity)];
|
|
158
|
-
case 1:
|
|
159
|
-
s = _c.sent();
|
|
160
|
-
_b = expect;
|
|
161
|
-
return [4 /*yield*/, s.find({ where: { $or: [{}, { myId: 3 }] } })];
|
|
162
|
-
case 2:
|
|
163
|
-
_b.apply(void 0, [(_c.sent()).length]).toBe(4);
|
|
164
|
-
return [2 /*return*/];
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
});
|
|
49
|
+
testAll("filter works on all db or_2", async ({ createEntity }) => {
|
|
50
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
51
|
+
expect((await s.find({ where: { $or: [{}, { myId: 3 }] } })).length).toBe(4);
|
|
168
52
|
}, false);
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
c.myId = 1;
|
|
180
|
-
c.name = 'noam';
|
|
181
|
-
return [4 /*yield*/, c._.save()];
|
|
182
|
-
case 2:
|
|
183
|
-
_c.sent();
|
|
184
|
-
c.name = 'yael';
|
|
185
|
-
return [4 /*yield*/, c._.save()];
|
|
186
|
-
case 3:
|
|
187
|
-
_c.sent();
|
|
188
|
-
expect(c.name).toBe('yael');
|
|
189
|
-
_b = expect;
|
|
190
|
-
return [4 /*yield*/, s.find()];
|
|
191
|
-
case 4:
|
|
192
|
-
_b.apply(void 0, [(_c.sent()).length]).toBe(1);
|
|
193
|
-
return [2 /*return*/];
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
});
|
|
53
|
+
testAll("entity with different id column still works well", async ({ createEntity }) => {
|
|
54
|
+
let s = await createEntity(entityWithValidations);
|
|
55
|
+
let c = s.create();
|
|
56
|
+
c.myId = 1;
|
|
57
|
+
c.name = 'noam';
|
|
58
|
+
await c._.save();
|
|
59
|
+
c.name = 'yael';
|
|
60
|
+
await c._.save();
|
|
61
|
+
expect(c.name).toBe('yael');
|
|
62
|
+
expect((await s.find()).length).toBe(1);
|
|
197
63
|
}, false);
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
c = (_b.sent()).create();
|
|
207
|
-
c.id = 5;
|
|
208
|
-
c.categoryName = 'test';
|
|
209
|
-
return [4 /*yield*/, c._.save()];
|
|
210
|
-
case 2:
|
|
211
|
-
_b.sent();
|
|
212
|
-
return [4 /*yield*/, remult.repo(remult_3_entities_1.Categories).find()];
|
|
213
|
-
case 3:
|
|
214
|
-
l = _b.sent();
|
|
215
|
-
expect(l.length).toBe(1);
|
|
216
|
-
expect(l[0].categoryName).toBe('test');
|
|
217
|
-
return [2 /*return*/];
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
});
|
|
64
|
+
testAll("empty find works", async ({ remult, createEntity }) => {
|
|
65
|
+
let c = (await createEntity(newCategories)).create();
|
|
66
|
+
c.id = 5;
|
|
67
|
+
c.categoryName = 'test';
|
|
68
|
+
await c._.save();
|
|
69
|
+
let l = await remult.repo(newCategories).find();
|
|
70
|
+
expect(l.length).toBe(1);
|
|
71
|
+
expect(l[0].categoryName).toBe('test');
|
|
221
72
|
}, false);
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
return [4 /*yield*/, repo.create({ id: 1, categoryName: 'a' }).save()];
|
|
232
|
-
case 2:
|
|
233
|
-
_b.sent();
|
|
234
|
-
return [4 /*yield*/, repo.create({ id: 2, categoryName: 'b' }).save()];
|
|
235
|
-
case 3:
|
|
236
|
-
_b.sent();
|
|
237
|
-
return [4 /*yield*/, repo.find({
|
|
238
|
-
orderBy: { categoryName: 'desc' },
|
|
239
|
-
page: -1
|
|
240
|
-
})];
|
|
241
|
-
case 4:
|
|
242
|
-
rows = _b.sent();
|
|
243
|
-
expect(rows[0].id).toBe(2);
|
|
244
|
-
return [2 /*return*/];
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
});
|
|
73
|
+
testAll("test descending", async ({ createEntity }) => {
|
|
74
|
+
const repo = await createEntity(newCategories);
|
|
75
|
+
await repo.create({ id: 1, categoryName: 'a' }).save();
|
|
76
|
+
await repo.create({ id: 2, categoryName: 'b' }).save();
|
|
77
|
+
const rows = await repo.find({
|
|
78
|
+
orderBy: { categoryName: 'desc' },
|
|
79
|
+
page: -1
|
|
80
|
+
});
|
|
81
|
+
expect(rows[0].id).toBe(2);
|
|
248
82
|
}, false);
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
repo = _b.sent();
|
|
258
|
-
return [4 /*yield*/, repo.insert([{ id: 1, categoryName: 'a' }, { id: 2, categoryName: 'b' }])];
|
|
259
|
-
case 2:
|
|
260
|
-
_b.sent();
|
|
261
|
-
return [4 /*yield*/, repo.find({
|
|
262
|
-
orderBy: { categoryName: 'desc' },
|
|
263
|
-
page: -1
|
|
264
|
-
})];
|
|
265
|
-
case 3:
|
|
266
|
-
rows = _b.sent();
|
|
267
|
-
expect(rows[0].id).toBe(2);
|
|
268
|
-
return [2 /*return*/];
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
});
|
|
83
|
+
testAll("test descending 2", async ({ createEntity }) => {
|
|
84
|
+
const repo = await createEntity(newCategories);
|
|
85
|
+
await repo.insert([{ id: 1, categoryName: 'a' }, { id: 2, categoryName: 'b' }]);
|
|
86
|
+
const rows = await repo.find({
|
|
87
|
+
orderBy: { categoryName: 'desc' },
|
|
88
|
+
page: -1
|
|
89
|
+
});
|
|
90
|
+
expect(rows[0].id).toBe(2);
|
|
272
91
|
}, false);
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
case 2:
|
|
286
|
-
_b.sent();
|
|
287
|
-
return [4 /*yield*/, remult.repo(remult_3_entities_1.Categories).findId(5)];
|
|
288
|
-
case 3:
|
|
289
|
-
l = _b.sent();
|
|
290
|
-
c.categoryName = 'newname';
|
|
291
|
-
l.description = 'new desc';
|
|
292
|
-
return [4 /*yield*/, c.save()];
|
|
293
|
-
case 4:
|
|
294
|
-
_b.sent();
|
|
295
|
-
return [4 /*yield*/, l.save()];
|
|
296
|
-
case 5:
|
|
297
|
-
_b.sent();
|
|
298
|
-
expect(l.categoryName).toBe('newname');
|
|
299
|
-
expect(l.description).toBe('new desc');
|
|
300
|
-
return [2 /*return*/];
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
});
|
|
92
|
+
testAll("partial updates", async ({ remult, createEntity }) => {
|
|
93
|
+
let c = (await createEntity(newCategories)).create({
|
|
94
|
+
id: 5, categoryName: 'test', description: 'desc'
|
|
95
|
+
});
|
|
96
|
+
await c._.save();
|
|
97
|
+
let l = await remult.repo(newCategories).findId(5);
|
|
98
|
+
c.categoryName = 'newname';
|
|
99
|
+
l.description = 'new desc';
|
|
100
|
+
await c.save();
|
|
101
|
+
await l.save();
|
|
102
|
+
expect(l.categoryName).toBe('newname');
|
|
103
|
+
expect(l.description).toBe('new desc');
|
|
304
104
|
}, false);
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
d.ok();
|
|
327
|
-
return [2 /*return*/];
|
|
328
|
-
});
|
|
329
|
-
}); };
|
|
330
|
-
return [4 /*yield*/, api.put(t, 1, {
|
|
331
|
-
name: '1'
|
|
332
|
-
})];
|
|
333
|
-
case 3:
|
|
334
|
-
_b.sent();
|
|
335
|
-
d.test();
|
|
336
|
-
return [4 /*yield*/, s.find({ where: { myId: 1 } })];
|
|
337
|
-
case 4:
|
|
338
|
-
x = _b.sent();
|
|
339
|
-
expect(x[0].name).toBe('noam');
|
|
340
|
-
return [4 /*yield*/, s.find({ where: { myId: 1 } })];
|
|
341
|
-
case 5:
|
|
342
|
-
x = _b.sent();
|
|
343
|
-
expect(x[0].name).toBe('noam');
|
|
344
|
-
return [2 /*return*/];
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
});
|
|
105
|
+
testAll("put with validations on entity fails", async ({ remult, createEntity }) => {
|
|
106
|
+
let s = await createEntity(entityWithValidations);
|
|
107
|
+
let c = s.create();
|
|
108
|
+
c.myId = 1;
|
|
109
|
+
c.name = 'noam';
|
|
110
|
+
await c._.save();
|
|
111
|
+
let api = new DataApi(s, remult);
|
|
112
|
+
let t = new TestDataApiResponse();
|
|
113
|
+
let d = new Done();
|
|
114
|
+
t.error = async (data) => {
|
|
115
|
+
expect(data.modelState.name).toBe('invalid');
|
|
116
|
+
d.ok();
|
|
117
|
+
};
|
|
118
|
+
await api.put(t, 1, {
|
|
119
|
+
name: '1'
|
|
120
|
+
});
|
|
121
|
+
d.test();
|
|
122
|
+
var x = await s.find({ where: { myId: 1 } });
|
|
123
|
+
expect(x[0].name).toBe('noam');
|
|
124
|
+
x = await s.find({ where: { myId: 1 } });
|
|
125
|
+
expect(x[0].name).toBe('noam');
|
|
348
126
|
});
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
case 1:
|
|
357
|
-
repo = _c.sent();
|
|
358
|
-
r = repo.create({ id: 0 });
|
|
359
|
-
return [4 /*yield*/, r.save()];
|
|
360
|
-
case 2:
|
|
361
|
-
_c.sent();
|
|
362
|
-
return [4 /*yield*/, repo.findFirst()];
|
|
363
|
-
case 3:
|
|
364
|
-
r = _c.sent();
|
|
365
|
-
expect(r.d).toBeNull();
|
|
366
|
-
_b = expect;
|
|
367
|
-
return [4 /*yield*/, repo.count({ d: null })];
|
|
368
|
-
case 4:
|
|
369
|
-
_b.apply(void 0, [_c.sent()]).toBe(1);
|
|
370
|
-
return [2 /*return*/];
|
|
371
|
-
}
|
|
372
|
-
});
|
|
373
|
-
});
|
|
127
|
+
testAll("test date with null works", async ({ createEntity }) => {
|
|
128
|
+
let repo = await createEntity(testDateWithNull);
|
|
129
|
+
let r = repo.create({ id: 0 });
|
|
130
|
+
await r.save();
|
|
131
|
+
r = await repo.findFirst();
|
|
132
|
+
expect(r.d).toBeNull();
|
|
133
|
+
expect(await repo.count({ d: null })).toBe(1);
|
|
374
134
|
}, false);
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
var r;
|
|
379
|
-
return tslib_1.__generator(this, function (_b) {
|
|
380
|
-
switch (_b.label) {
|
|
381
|
-
case 0: return [4 /*yield*/, createEntity(testDateWithNull)];
|
|
382
|
-
case 1: return [4 /*yield*/, (_b.sent()).create({ id: 1, d: new Date(1976, 6, 16) }).save()];
|
|
383
|
-
case 2:
|
|
384
|
-
r = _b.sent();
|
|
385
|
-
expect(r.$.d.originalValue.getFullYear()).toBe(1976);
|
|
386
|
-
return [2 /*return*/];
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
});
|
|
135
|
+
testAll("test original value of date", async ({ createEntity }) => {
|
|
136
|
+
let r = await (await createEntity(testDateWithNull)).create({ id: 1, d: new Date(1976, 6, 16) }).save();
|
|
137
|
+
expect(r.$.d.originalValue.getFullYear()).toBe(1976);
|
|
390
138
|
});
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
_this.id = 0;
|
|
396
|
-
return _this;
|
|
139
|
+
let testDateWithNull = class testDateWithNull extends EntityBase {
|
|
140
|
+
constructor() {
|
|
141
|
+
super(...arguments);
|
|
142
|
+
this.id = 0;
|
|
397
143
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
switch (_b.label) {
|
|
417
|
-
case 0: return [4 /*yield*/, createEntity(testStringWithNull)];
|
|
418
|
-
case 1:
|
|
419
|
-
repo = _b.sent();
|
|
420
|
-
r = repo.create({ id: 0 });
|
|
421
|
-
return [4 /*yield*/, r.save()];
|
|
422
|
-
case 2:
|
|
423
|
-
_b.sent();
|
|
424
|
-
return [4 /*yield*/, repo.findFirst()];
|
|
425
|
-
case 3:
|
|
426
|
-
r = _b.sent();
|
|
427
|
-
expect(r.d).toBeNull();
|
|
428
|
-
return [2 /*return*/];
|
|
429
|
-
}
|
|
430
|
-
});
|
|
431
|
-
});
|
|
144
|
+
};
|
|
145
|
+
__decorate([
|
|
146
|
+
Fields.integer(),
|
|
147
|
+
__metadata("design:type", Number)
|
|
148
|
+
], testDateWithNull.prototype, "id", void 0);
|
|
149
|
+
__decorate([
|
|
150
|
+
Fields.dateOnly({ allowNull: true }),
|
|
151
|
+
__metadata("design:type", Date)
|
|
152
|
+
], testDateWithNull.prototype, "d", void 0);
|
|
153
|
+
testDateWithNull = __decorate([
|
|
154
|
+
Entity('testDateWithNull', { allowApiCrud: true })
|
|
155
|
+
], testDateWithNull);
|
|
156
|
+
testAll("test string with null works", async ({ createEntity }) => {
|
|
157
|
+
let repo = await createEntity(testStringWithNull);
|
|
158
|
+
let r = repo.create({ id: 0 });
|
|
159
|
+
await r.save();
|
|
160
|
+
r = await repo.findFirst();
|
|
161
|
+
expect(r.d).toBeNull();
|
|
432
162
|
});
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
return [4 /*yield*/, t._.save()];
|
|
451
|
-
case 3:
|
|
452
|
-
_e.sent();
|
|
453
|
-
t = c.create();
|
|
454
|
-
t.id = 3;
|
|
455
|
-
t.completed = true;
|
|
456
|
-
return [4 /*yield*/, t._.save()];
|
|
457
|
-
case 4:
|
|
458
|
-
_e.sent();
|
|
459
|
-
return [4 /*yield*/, c.create({ id: 4, completed: false }).save()];
|
|
460
|
-
case 5:
|
|
461
|
-
_e.sent();
|
|
462
|
-
_b = expect;
|
|
463
|
-
return [4 /*yield*/, c.count({ completed: false })];
|
|
464
|
-
case 6:
|
|
465
|
-
_b.apply(void 0, [_e.sent()]).toBe(2);
|
|
466
|
-
_c = expect;
|
|
467
|
-
return [4 /*yield*/, c.count({ completed: { $ne: true } })];
|
|
468
|
-
case 7:
|
|
469
|
-
_c.apply(void 0, [_e.sent()]).toBe(2);
|
|
470
|
-
_d = expect;
|
|
471
|
-
return [4 /*yield*/, c.count({ completed: true })];
|
|
472
|
-
case 8:
|
|
473
|
-
_d.apply(void 0, [_e.sent()]).toBe(2);
|
|
474
|
-
return [2 /*return*/];
|
|
475
|
-
}
|
|
476
|
-
});
|
|
477
|
-
});
|
|
163
|
+
testAll("test tasks", async ({ createEntity }) => {
|
|
164
|
+
let c = await createEntity(tasks);
|
|
165
|
+
let t = c.create();
|
|
166
|
+
t.id = 1;
|
|
167
|
+
await t._.save();
|
|
168
|
+
t = c.create();
|
|
169
|
+
t.id = 2;
|
|
170
|
+
t.completed = true;
|
|
171
|
+
await t._.save();
|
|
172
|
+
t = c.create();
|
|
173
|
+
t.id = 3;
|
|
174
|
+
t.completed = true;
|
|
175
|
+
await t._.save();
|
|
176
|
+
await c.create({ id: 4, completed: false }).save();
|
|
177
|
+
expect(await c.count({ completed: false })).toBe(2);
|
|
178
|
+
expect(await c.count({ completed: { $ne: true } })).toBe(2);
|
|
179
|
+
expect(await c.count({ completed: true })).toBe(2);
|
|
478
180
|
}, false);
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
case 1:
|
|
487
|
-
repo = _d.sent();
|
|
488
|
-
return [4 /*yield*/, repo.create({ id: 'a' }).save()];
|
|
489
|
-
case 2:
|
|
490
|
-
a = _d.sent();
|
|
491
|
-
return [4 /*yield*/, repo.create({ id: 'b' }).save()];
|
|
492
|
-
case 3:
|
|
493
|
-
b = _d.sent();
|
|
494
|
-
return [4 /*yield*/, repo.create({ id: 'c', refH: b }).save()];
|
|
495
|
-
case 4:
|
|
496
|
-
c = _d.sent();
|
|
497
|
-
_b = expect;
|
|
498
|
-
return [4 /*yield*/, repo.count({ refH: null })];
|
|
499
|
-
case 5:
|
|
500
|
-
_b.apply(void 0, [_d.sent()]).toBe(2);
|
|
501
|
-
_c = expect;
|
|
502
|
-
return [4 /*yield*/, repo.count({ refH: { "!=": null } })];
|
|
503
|
-
case 6:
|
|
504
|
-
_c.apply(void 0, [_d.sent()]).toBe(1);
|
|
505
|
-
return [2 /*return*/];
|
|
506
|
-
}
|
|
507
|
-
});
|
|
508
|
-
});
|
|
181
|
+
testAll("test filtering of null/''", async ({ createEntity }) => {
|
|
182
|
+
let repo = await createEntity(h);
|
|
183
|
+
let a = await repo.create({ id: 'a' }).save();
|
|
184
|
+
let b = await repo.create({ id: 'b' }).save();
|
|
185
|
+
let c = await repo.create({ id: 'c', refH: b }).save();
|
|
186
|
+
expect(await repo.count({ refH: null })).toBe(2);
|
|
187
|
+
expect(await repo.count({ refH: { "!=": null } })).toBe(1);
|
|
509
188
|
}, false);
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
c2 = _e.sent();
|
|
529
|
-
return [4 /*yield*/, remult.repo(c_1.c).create({ id: 3, name: 'c3' }).save()];
|
|
530
|
-
case 5:
|
|
531
|
-
c3 = _e.sent();
|
|
532
|
-
return [4 /*yield*/, remult.repo(p).create({ id: 1, name: 'p1', c: c1 }).save()];
|
|
533
|
-
case 6:
|
|
534
|
-
_e.sent();
|
|
535
|
-
return [4 /*yield*/, remult.repo(p).create({ id: 2, name: 'p2', c: c2 }).save()];
|
|
536
|
-
case 7:
|
|
537
|
-
_e.sent();
|
|
538
|
-
return [4 /*yield*/, remult.repo(p).create({ id: 3, name: 'p3', c: c3 }).save()];
|
|
539
|
-
case 8:
|
|
540
|
-
_e.sent();
|
|
541
|
-
return [4 /*yield*/, remult.repo(p).create({ id: 4, name: 'p4', c: c3 }).save()];
|
|
542
|
-
case 9:
|
|
543
|
-
_e.sent();
|
|
544
|
-
return [4 /*yield*/, remult.repo(p).create({ id: 5, name: 'p5', c: c3 }).save()];
|
|
545
|
-
case 10:
|
|
546
|
-
_e.sent();
|
|
547
|
-
i = 0;
|
|
548
|
-
_e.label = 11;
|
|
549
|
-
case 11:
|
|
550
|
-
_e.trys.push([11, 16, 17, 22]);
|
|
551
|
-
_b = tslib_1.__asyncValues(remult.repo(p).query({
|
|
552
|
-
orderBy: { c: "asc", id: "asc" }
|
|
553
|
-
}));
|
|
554
|
-
_e.label = 12;
|
|
555
|
-
case 12: return [4 /*yield*/, _b.next()];
|
|
556
|
-
case 13:
|
|
557
|
-
if (!(_c = _e.sent(), !_c.done)) return [3 /*break*/, 15];
|
|
558
|
-
x = _c.value;
|
|
559
|
-
i++;
|
|
560
|
-
_e.label = 14;
|
|
561
|
-
case 14: return [3 /*break*/, 12];
|
|
562
|
-
case 15: return [3 /*break*/, 22];
|
|
563
|
-
case 16:
|
|
564
|
-
e_1_1 = _e.sent();
|
|
565
|
-
e_1 = { error: e_1_1 };
|
|
566
|
-
return [3 /*break*/, 22];
|
|
567
|
-
case 17:
|
|
568
|
-
_e.trys.push([17, , 20, 21]);
|
|
569
|
-
if (!(_c && !_c.done && (_d = _b.return))) return [3 /*break*/, 19];
|
|
570
|
-
return [4 /*yield*/, _d.call(_b)];
|
|
571
|
-
case 18:
|
|
572
|
-
_e.sent();
|
|
573
|
-
_e.label = 19;
|
|
574
|
-
case 19: return [3 /*break*/, 21];
|
|
575
|
-
case 20:
|
|
576
|
-
if (e_1) throw e_1.error;
|
|
577
|
-
return [7 /*endfinally*/];
|
|
578
|
-
case 21: return [7 /*endfinally*/];
|
|
579
|
-
case 22:
|
|
580
|
-
expect(i).toBe(5);
|
|
581
|
-
return [2 /*return*/];
|
|
582
|
-
}
|
|
583
|
-
});
|
|
584
|
-
});
|
|
189
|
+
testAll("test paging with complex object", async ({ remult, createEntity }) => {
|
|
190
|
+
await createEntity(c);
|
|
191
|
+
await createEntity(p);
|
|
192
|
+
let c1 = await remult.repo(c).create({ id: 1, name: 'c1' }).save();
|
|
193
|
+
let c2 = await remult.repo(c).create({ id: 2, name: 'c2' }).save();
|
|
194
|
+
let c3 = await remult.repo(c).create({ id: 3, name: 'c3' }).save();
|
|
195
|
+
await remult.repo(p).create({ id: 1, name: 'p1', c: c1 }).save();
|
|
196
|
+
await remult.repo(p).create({ id: 2, name: 'p2', c: c2 }).save();
|
|
197
|
+
await remult.repo(p).create({ id: 3, name: 'p3', c: c3 }).save();
|
|
198
|
+
await remult.repo(p).create({ id: 4, name: 'p4', c: c3 }).save();
|
|
199
|
+
await remult.repo(p).create({ id: 5, name: 'p5', c: c3 }).save();
|
|
200
|
+
let i = 0;
|
|
201
|
+
for await (const x of remult.repo(p).query({
|
|
202
|
+
orderBy: { c: "asc", id: "asc" }
|
|
203
|
+
})) {
|
|
204
|
+
i++;
|
|
205
|
+
}
|
|
206
|
+
expect(i).toBe(5);
|
|
585
207
|
});
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
return tslib_1.__generator(this, function (_c) {
|
|
591
|
-
switch (_c.label) {
|
|
592
|
-
case 0: return [4 /*yield*/, createEntity(c_1.c)];
|
|
593
|
-
case 1: return [4 /*yield*/, (_c.sent()).create({ id: 1, name: 'c1' }).save()];
|
|
594
|
-
case 2:
|
|
595
|
-
c1 = _c.sent();
|
|
596
|
-
return [4 /*yield*/, createEntity(p)];
|
|
597
|
-
case 3: return [4 /*yield*/, (_c.sent()).create({ id: 1, name: 'p1', c: c1 }).save()];
|
|
598
|
-
case 4:
|
|
599
|
-
_c.sent();
|
|
600
|
-
_b = expect;
|
|
601
|
-
return [4 /*yield*/, remult.repo(p).findFirst({ c: c1 })];
|
|
602
|
-
case 5:
|
|
603
|
-
_b.apply(void 0, [(_c.sent()).id]).toBe(1);
|
|
604
|
-
return [2 /*return*/];
|
|
605
|
-
}
|
|
606
|
-
});
|
|
607
|
-
});
|
|
208
|
+
testAll("test paging with complex object_2", async ({ remult, createEntity }) => {
|
|
209
|
+
let c1 = await (await createEntity(c)).create({ id: 1, name: 'c1' }).save();
|
|
210
|
+
await (await createEntity(p)).create({ id: 1, name: 'p1', c: c1 }).save();
|
|
211
|
+
expect((await remult.repo(p).findFirst({ c: c1 })).id).toBe(1);
|
|
608
212
|
});
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
return [4 /*yield*/, repo.create({ id: 2, b: 2 }).save()];
|
|
622
|
-
case 3:
|
|
623
|
-
_f.sent();
|
|
624
|
-
return [4 /*yield*/, repo.create({ id: 4, b: 2 }).save()];
|
|
625
|
-
case 4:
|
|
626
|
-
d4 = _f.sent();
|
|
627
|
-
f = { id: 1, $and: [{ id: 2 }] };
|
|
628
|
-
_b = expect;
|
|
629
|
-
return [4 /*yield*/, repo.count(f)];
|
|
630
|
-
case 5:
|
|
631
|
-
_b.apply(void 0, [_f.sent()]).toBe(0);
|
|
632
|
-
_c = expect;
|
|
633
|
-
return [4 /*yield*/, repo.find({ where: f })];
|
|
634
|
-
case 6:
|
|
635
|
-
_c.apply(void 0, [(_f.sent()).length]).toBe(0);
|
|
636
|
-
json = filter_interfaces_1.Filter.entityFilterToJson(repo.metadata, f);
|
|
637
|
-
f = filter_interfaces_1.Filter.entityFilterFromJson(repo.metadata, json);
|
|
638
|
-
_d = expect;
|
|
639
|
-
return [4 /*yield*/, repo.count(f)];
|
|
640
|
-
case 7:
|
|
641
|
-
_d.apply(void 0, [_f.sent()]).toBe(0);
|
|
642
|
-
_e = expect;
|
|
643
|
-
return [4 /*yield*/, repo.find({ where: f })];
|
|
644
|
-
case 8:
|
|
645
|
-
_e.apply(void 0, [(_f.sent()).length]).toBe(0);
|
|
646
|
-
return [2 /*return*/];
|
|
647
|
-
}
|
|
648
|
-
});
|
|
649
|
-
});
|
|
213
|
+
testAll("test filter doesn't collapse", async ({ createEntity }) => {
|
|
214
|
+
let repo = await createEntity(dWithPrefilter);
|
|
215
|
+
let d1 = await repo.create({ id: 1, b: 1 }).save();
|
|
216
|
+
await repo.create({ id: 2, b: 2 }).save();
|
|
217
|
+
let d4 = await repo.create({ id: 4, b: 2 }).save();
|
|
218
|
+
let f = { id: 1, $and: [{ id: 2 }] };
|
|
219
|
+
expect(await repo.count(f)).toBe(0);
|
|
220
|
+
expect((await repo.find({ where: f })).length).toBe(0);
|
|
221
|
+
let json = Filter.entityFilterToJson(repo.metadata, f);
|
|
222
|
+
f = Filter.entityFilterFromJson(repo.metadata, json);
|
|
223
|
+
expect(await repo.count(f)).toBe(0);
|
|
224
|
+
expect((await repo.find({ where: f })).length).toBe(0);
|
|
650
225
|
});
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
return [4 /*yield*/, repo.create({ id: 2, b: 2 }).save()];
|
|
664
|
-
case 3:
|
|
665
|
-
_f.sent();
|
|
666
|
-
return [4 /*yield*/, repo.create({ id: 4, b: 2 }).save()];
|
|
667
|
-
case 4:
|
|
668
|
-
d4 = _f.sent();
|
|
669
|
-
f = { id: [1, 2] };
|
|
670
|
-
_b = expect;
|
|
671
|
-
return [4 /*yield*/, repo.count(f)];
|
|
672
|
-
case 5:
|
|
673
|
-
_b.apply(void 0, [_f.sent()]).toBe(2);
|
|
674
|
-
_c = expect;
|
|
675
|
-
return [4 /*yield*/, repo.find({ where: f })];
|
|
676
|
-
case 6:
|
|
677
|
-
_c.apply(void 0, [(_f.sent()).length]).toBe(2);
|
|
678
|
-
json = filter_interfaces_1.Filter.entityFilterToJson(repo.metadata, f);
|
|
679
|
-
f = filter_interfaces_1.Filter.entityFilterFromJson(repo.metadata, json);
|
|
680
|
-
_d = expect;
|
|
681
|
-
return [4 /*yield*/, repo.count(f)];
|
|
682
|
-
case 7:
|
|
683
|
-
_d.apply(void 0, [_f.sent()]).toBe(2);
|
|
684
|
-
_e = expect;
|
|
685
|
-
return [4 /*yield*/, repo.find({ where: f })];
|
|
686
|
-
case 8:
|
|
687
|
-
_e.apply(void 0, [(_f.sent()).length]).toBe(2);
|
|
688
|
-
return [2 /*return*/];
|
|
689
|
-
}
|
|
690
|
-
});
|
|
691
|
-
});
|
|
226
|
+
testAll("test filter doesn't collapse", async ({ createEntity }) => {
|
|
227
|
+
let repo = await createEntity(d);
|
|
228
|
+
let d1 = await repo.create({ id: 1, b: 1 }).save();
|
|
229
|
+
await repo.create({ id: 2, b: 2 }).save();
|
|
230
|
+
let d4 = await repo.create({ id: 4, b: 2 }).save();
|
|
231
|
+
let f = { id: [1, 2] };
|
|
232
|
+
expect(await repo.count(f)).toBe(2);
|
|
233
|
+
expect((await repo.find({ where: f })).length).toBe(2);
|
|
234
|
+
let json = Filter.entityFilterToJson(repo.metadata, f);
|
|
235
|
+
f = Filter.entityFilterFromJson(repo.metadata, json);
|
|
236
|
+
expect(await repo.count(f)).toBe(2);
|
|
237
|
+
expect((await repo.find({ where: f })).length).toBe(2);
|
|
692
238
|
});
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
c = _e.sent();
|
|
702
|
-
id = 0;
|
|
703
|
-
_e.label = 2;
|
|
704
|
-
case 2:
|
|
705
|
-
if (!(id < 5)) return [3 /*break*/, 5];
|
|
706
|
-
return [4 /*yield*/, c.create({ id: id }).save()];
|
|
707
|
-
case 3:
|
|
708
|
-
_e.sent();
|
|
709
|
-
_e.label = 4;
|
|
710
|
-
case 4:
|
|
711
|
-
id++;
|
|
712
|
-
return [3 /*break*/, 2];
|
|
713
|
-
case 5:
|
|
714
|
-
_b = expect;
|
|
715
|
-
return [4 /*yield*/, (c.count(entityForCustomFilter_1.entityForCustomFilter1.oneAndThree()))];
|
|
716
|
-
case 6:
|
|
717
|
-
_b.apply(void 0, [_e.sent()]).toBe(2);
|
|
718
|
-
_c = expect;
|
|
719
|
-
return [4 /*yield*/, (c.findFirst(entityForCustomFilter_1.entityForCustomFilter1.testNumericValue(2)))];
|
|
720
|
-
case 7:
|
|
721
|
-
_c.apply(void 0, [(_e.sent()).id]).toBe(2);
|
|
722
|
-
_d = expect;
|
|
723
|
-
return [4 /*yield*/, (c.findFirst(entityForCustomFilter_1.entityForCustomFilter1.testObjectValue({ val: 2 })))];
|
|
724
|
-
case 8:
|
|
725
|
-
_d.apply(void 0, [(_e.sent()).id]).toBe(2);
|
|
726
|
-
return [2 /*return*/];
|
|
727
|
-
}
|
|
728
|
-
});
|
|
729
|
-
});
|
|
239
|
+
testAll("test that it works with inheritance", async ({ createEntity }) => {
|
|
240
|
+
let c = await createEntity(entityForCustomFilter1);
|
|
241
|
+
for (let id = 0; id < 5; id++) {
|
|
242
|
+
await c.create({ id }).save();
|
|
243
|
+
}
|
|
244
|
+
expect(await (c.count(entityForCustomFilter1.oneAndThree()))).toBe(2);
|
|
245
|
+
expect((await (c.findFirst(entityForCustomFilter1.testNumericValue(2)))).id).toBe(2);
|
|
246
|
+
expect((await (c.findFirst(entityForCustomFilter1.testObjectValue({ val: 2 })))).id).toBe(2);
|
|
730
247
|
});
|
|
731
|
-
|
|
732
|
-
var
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
return tslib_1.__generator(this, function (_a) {
|
|
751
|
-
expect(data.modelState.name).toBe('invalid on column');
|
|
752
|
-
d.ok();
|
|
753
|
-
return [2 /*return*/];
|
|
754
|
-
});
|
|
755
|
-
}); };
|
|
756
|
-
return [4 /*yield*/, api.put(t, 1, {
|
|
757
|
-
name: '1'
|
|
758
|
-
})];
|
|
759
|
-
case 3:
|
|
760
|
-
_b.sent();
|
|
761
|
-
d.test();
|
|
762
|
-
return [4 /*yield*/, s.find({ where: { myId: 1 } })];
|
|
763
|
-
case 4:
|
|
764
|
-
x = _b.sent();
|
|
765
|
-
expect(x[0].name).toBe('noam');
|
|
766
|
-
return [2 /*return*/];
|
|
767
|
-
}
|
|
768
|
-
});
|
|
769
|
-
});
|
|
248
|
+
testAll("put with validations on column fails", async ({ remult, createEntity }) => {
|
|
249
|
+
var s = await createEntity(entityWithValidationsOnColumn);
|
|
250
|
+
let c = s.create();
|
|
251
|
+
c.myId = 1;
|
|
252
|
+
c.name = 'noam';
|
|
253
|
+
await c._.save();
|
|
254
|
+
let api = new DataApi(s, remult);
|
|
255
|
+
let t = new TestDataApiResponse();
|
|
256
|
+
let d = new Done();
|
|
257
|
+
t.error = async (data) => {
|
|
258
|
+
expect(data.modelState.name).toBe('invalid on column');
|
|
259
|
+
d.ok();
|
|
260
|
+
};
|
|
261
|
+
await api.put(t, 1, {
|
|
262
|
+
name: '1'
|
|
263
|
+
});
|
|
264
|
+
d.test();
|
|
265
|
+
var x = await s.find({ where: { myId: 1 } });
|
|
266
|
+
expect(x[0].name).toBe('noam');
|
|
770
267
|
});
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
case 2:
|
|
784
|
-
rows = _b.sent();
|
|
785
|
-
expect(rows.length).toBe(0);
|
|
786
|
-
c = forCat.create();
|
|
787
|
-
c.id = 1;
|
|
788
|
-
c.categoryName = 'noam';
|
|
789
|
-
return [4 /*yield*/, c._.save()];
|
|
790
|
-
case 3:
|
|
791
|
-
_b.sent();
|
|
792
|
-
return [4 /*yield*/, forCat.find()];
|
|
793
|
-
case 4:
|
|
794
|
-
rows = _b.sent();
|
|
795
|
-
expect(rows.length).toBe(1);
|
|
796
|
-
expect(rows[0].id).toBe(1);
|
|
797
|
-
expect(rows[0].categoryName).toBe('noam');
|
|
798
|
-
return [2 /*return*/];
|
|
799
|
-
}
|
|
800
|
-
});
|
|
801
|
-
});
|
|
268
|
+
testAllDbs("Insert", async ({ createData }) => {
|
|
269
|
+
let forCat = await createData(async (x) => { });
|
|
270
|
+
let rows = await forCat.find();
|
|
271
|
+
expect(rows.length).toBe(0);
|
|
272
|
+
let c = forCat.create();
|
|
273
|
+
c.id = 1;
|
|
274
|
+
c.categoryName = 'noam';
|
|
275
|
+
await c._.save();
|
|
276
|
+
rows = await forCat.find();
|
|
277
|
+
expect(rows.length).toBe(1);
|
|
278
|
+
expect(rows[0].id).toBe(1);
|
|
279
|
+
expect(rows[0].categoryName).toBe('noam');
|
|
802
280
|
}, false);
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
case 0: return [4 /*yield*/, insert(5, 'noam')];
|
|
812
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
813
|
-
}
|
|
814
|
-
}); }); })];
|
|
815
|
-
case 1:
|
|
816
|
-
c = _b.sent();
|
|
817
|
-
return [4 /*yield*/, c.find()];
|
|
818
|
-
case 2:
|
|
819
|
-
rows = _b.sent();
|
|
820
|
-
expect(rows.length).toBe(1);
|
|
821
|
-
expect(rows[0].id).toBe(5);
|
|
822
|
-
return [4 /*yield*/, rows[0]._.delete()];
|
|
823
|
-
case 3:
|
|
824
|
-
_b.sent();
|
|
825
|
-
return [4 /*yield*/, c.find()];
|
|
826
|
-
case 4:
|
|
827
|
-
rows = _b.sent();
|
|
828
|
-
expect(rows.length).toBe(0);
|
|
829
|
-
return [2 /*return*/];
|
|
830
|
-
}
|
|
831
|
-
});
|
|
832
|
-
});
|
|
281
|
+
testAllDbs("test delete", async ({ createData }) => {
|
|
282
|
+
let c = await createData(async (insert) => await insert(5, 'noam'));
|
|
283
|
+
let rows = await c.find();
|
|
284
|
+
expect(rows.length).toBe(1);
|
|
285
|
+
expect(rows[0].id).toBe(5);
|
|
286
|
+
await rows[0]._.delete();
|
|
287
|
+
rows = await c.find();
|
|
288
|
+
expect(rows.length).toBe(0);
|
|
833
289
|
}, false);
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
case 3:
|
|
851
|
-
rows = _b.sent();
|
|
852
|
-
expect(rows.length).toBe(2);
|
|
853
|
-
return [4 /*yield*/, r.find({ where: filter_interfaces_1.Filter.entityFilterFromJson(r.metadata, filter_interfaces_1.entityFilterToJson(r.metadata, { id: 4 })) })];
|
|
854
|
-
case 4:
|
|
855
|
-
rows = _b.sent();
|
|
856
|
-
expect(rows.length).toBe(1);
|
|
857
|
-
expect(rows[0].categoryName).toBe('yael');
|
|
858
|
-
return [4 /*yield*/, r.find({ where: filter_interfaces_1.Filter.entityFilterFromJson(r.metadata, filter_interfaces_1.entityFilterToJson(r.metadata, { description: 'y', categoryName: 'yoni' })) })];
|
|
859
|
-
case 5:
|
|
860
|
-
rows = _b.sent();
|
|
861
|
-
expect(rows.length).toBe(1);
|
|
862
|
-
expect(rows[0].id).toBe(2);
|
|
863
|
-
return [4 /*yield*/, r.find({ where: filter_interfaces_1.Filter.entityFilterFromJson(r.metadata, filter_interfaces_1.entityFilterToJson(r.metadata, { id: { $ne: [2, 4] } })) })];
|
|
864
|
-
case 6:
|
|
865
|
-
rows = _b.sent();
|
|
866
|
-
expect(rows.length).toBe(2);
|
|
867
|
-
return [2 /*return*/];
|
|
868
|
-
}
|
|
869
|
-
});
|
|
870
|
-
});
|
|
290
|
+
testAllDbs("test filter packer", async ({ insertFourRows }) => {
|
|
291
|
+
let r = await insertFourRows();
|
|
292
|
+
let rows = await r.find();
|
|
293
|
+
expect(rows.length).toBe(4);
|
|
294
|
+
rows = await r.find({
|
|
295
|
+
where: Filter.entityFilterFromJson(r.metadata, entityFilterToJson(r.metadata, { description: 'x' }))
|
|
296
|
+
});
|
|
297
|
+
expect(rows.length).toBe(2);
|
|
298
|
+
rows = await r.find({ where: Filter.entityFilterFromJson(r.metadata, entityFilterToJson(r.metadata, { id: 4 })) });
|
|
299
|
+
expect(rows.length).toBe(1);
|
|
300
|
+
expect(rows[0].categoryName).toBe('yael');
|
|
301
|
+
rows = await r.find({ where: Filter.entityFilterFromJson(r.metadata, entityFilterToJson(r.metadata, { description: 'y', categoryName: 'yoni' })) });
|
|
302
|
+
expect(rows.length).toBe(1);
|
|
303
|
+
expect(rows[0].id).toBe(2);
|
|
304
|
+
rows = await r.find({ where: Filter.entityFilterFromJson(r.metadata, entityFilterToJson(r.metadata, { id: { $ne: [2, 4] } })) });
|
|
305
|
+
expect(rows.length).toBe(2);
|
|
871
306
|
}, false);
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
});
|
|
901
|
-
}); }
|
|
902
|
-
})(type.prototype, "a");
|
|
903
|
-
return [4 /*yield*/, createEntity(type)];
|
|
904
|
-
case 1:
|
|
905
|
-
c = _b.sent();
|
|
906
|
-
cat = c.create();
|
|
907
|
-
cat.a = '12';
|
|
908
|
-
cat.id = 1;
|
|
909
|
-
return [4 /*yield*/, cat._.save()];
|
|
910
|
-
case 2:
|
|
911
|
-
_b.sent();
|
|
912
|
-
cat = c.create();
|
|
913
|
-
cat.a = '12';
|
|
914
|
-
saved = false;
|
|
915
|
-
_b.label = 3;
|
|
916
|
-
case 3:
|
|
917
|
-
_b.trys.push([3, 5, , 6]);
|
|
918
|
-
return [4 /*yield*/, cat._.save()];
|
|
919
|
-
case 4:
|
|
920
|
-
_b.sent();
|
|
921
|
-
saved = true;
|
|
922
|
-
return [3 /*break*/, 6];
|
|
923
|
-
case 5:
|
|
924
|
-
err_1 = _b.sent();
|
|
925
|
-
expect(cat._.fields.a.error).toEqual("already exists");
|
|
926
|
-
return [3 /*break*/, 6];
|
|
927
|
-
case 6:
|
|
928
|
-
expect(saved).toBe(false);
|
|
929
|
-
return [2 /*return*/];
|
|
930
|
-
}
|
|
931
|
-
});
|
|
932
|
-
});
|
|
933
|
-
});
|
|
934
|
-
db_tests_setup_1.testAll("Test unique Validation 2", function (_a) {
|
|
935
|
-
var createEntity = _a.createEntity;
|
|
936
|
-
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
937
|
-
var type, c, cat, saved, err_2;
|
|
938
|
-
return tslib_1.__generator(this, function (_b) {
|
|
939
|
-
switch (_b.label) {
|
|
940
|
-
case 0:
|
|
941
|
-
type = /** @class */ (function (_super) {
|
|
942
|
-
tslib_1.__extends(class_2, _super);
|
|
943
|
-
function class_2() {
|
|
944
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
945
|
-
}
|
|
946
|
-
return class_2;
|
|
947
|
-
}(remult_3_entities_1.Categories));
|
|
948
|
-
remult3_1.Entity('sdfgds')(type);
|
|
949
|
-
remult3_1.Fields.string({
|
|
950
|
-
validate: validators_1.Validators.unique
|
|
951
|
-
})(type.prototype, "a");
|
|
952
|
-
return [4 /*yield*/, createEntity(type)];
|
|
953
|
-
case 1:
|
|
954
|
-
c = _b.sent();
|
|
955
|
-
cat = c.create();
|
|
956
|
-
cat.a = '12';
|
|
957
|
-
return [4 /*yield*/, cat._.save()];
|
|
958
|
-
case 2:
|
|
959
|
-
_b.sent();
|
|
960
|
-
cat = c.create();
|
|
961
|
-
cat.a = '12';
|
|
962
|
-
saved = false;
|
|
963
|
-
_b.label = 3;
|
|
964
|
-
case 3:
|
|
965
|
-
_b.trys.push([3, 5, , 6]);
|
|
966
|
-
return [4 /*yield*/, cat._.save()];
|
|
967
|
-
case 4:
|
|
968
|
-
_b.sent();
|
|
969
|
-
saved = true;
|
|
970
|
-
return [3 /*break*/, 6];
|
|
971
|
-
case 5:
|
|
972
|
-
err_2 = _b.sent();
|
|
973
|
-
expect(cat._.fields.a.error).toEqual("already exists");
|
|
974
|
-
return [3 /*break*/, 6];
|
|
975
|
-
case 6:
|
|
976
|
-
expect(saved).toBe(false);
|
|
977
|
-
return [2 /*return*/];
|
|
978
|
-
}
|
|
979
|
-
});
|
|
980
|
-
});
|
|
307
|
+
testAll("Test unique Validation,", async ({ createEntity }) => {
|
|
308
|
+
let type = class extends newCategories {
|
|
309
|
+
};
|
|
310
|
+
Entity('categories')(type);
|
|
311
|
+
Fields.string({
|
|
312
|
+
validate: async (en, col) => {
|
|
313
|
+
if (en._.isNew() || en.a != en._.fields.a.originalValue) {
|
|
314
|
+
if (await c.count({ a: en.a }))
|
|
315
|
+
en._.fields.a.error = 'already exists';
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
})(type.prototype, "a");
|
|
319
|
+
var c = await createEntity(type);
|
|
320
|
+
var cat = c.create();
|
|
321
|
+
cat.a = '12';
|
|
322
|
+
cat.id = 1;
|
|
323
|
+
await cat._.save();
|
|
324
|
+
cat = c.create();
|
|
325
|
+
cat.a = '12';
|
|
326
|
+
var saved = false;
|
|
327
|
+
try {
|
|
328
|
+
await cat._.save();
|
|
329
|
+
saved = true;
|
|
330
|
+
}
|
|
331
|
+
catch (err) {
|
|
332
|
+
expect(cat._.fields.a.error).toEqual("already exists");
|
|
333
|
+
}
|
|
334
|
+
expect(saved).toBe(false);
|
|
981
335
|
});
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
336
|
+
testAll("Test unique Validation 2", async ({ createEntity }) => {
|
|
337
|
+
let type = class extends newCategories {
|
|
338
|
+
};
|
|
339
|
+
Entity('sdfgds')(type);
|
|
340
|
+
Fields.string({
|
|
341
|
+
validate: Validators.unique
|
|
342
|
+
})(type.prototype, "a");
|
|
343
|
+
var c = await createEntity(type);
|
|
344
|
+
var cat = c.create();
|
|
345
|
+
cat.a = '12';
|
|
346
|
+
await cat._.save();
|
|
347
|
+
cat = c.create();
|
|
348
|
+
cat.a = '12';
|
|
349
|
+
var saved = false;
|
|
350
|
+
try {
|
|
351
|
+
await cat._.save();
|
|
352
|
+
saved = true;
|
|
986
353
|
}
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
tslib_1.__decorate([
|
|
992
|
-
remult3_1.Fields.number(),
|
|
993
|
-
tslib_1.__metadata("design:type", Number)
|
|
994
|
-
], testNumbers.prototype, "a", void 0);
|
|
995
|
-
testNumbers = tslib_1.__decorate([
|
|
996
|
-
remult3_1.Entity('testNumbers', { allowApiCrud: true })
|
|
997
|
-
], testNumbers);
|
|
998
|
-
return testNumbers;
|
|
999
|
-
}(remult3_1.EntityBase));
|
|
1000
|
-
db_tests_setup_1.testAll("test that integer and int work", function (_a) {
|
|
1001
|
-
var createEntity = _a.createEntity;
|
|
1002
|
-
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
1003
|
-
var e;
|
|
1004
|
-
return tslib_1.__generator(this, function (_b) {
|
|
1005
|
-
switch (_b.label) {
|
|
1006
|
-
case 0: return [4 /*yield*/, createEntity(testNumbers)];
|
|
1007
|
-
case 1: return [4 /*yield*/, (_b.sent()).create({
|
|
1008
|
-
id: 1.5,
|
|
1009
|
-
a: 1.5
|
|
1010
|
-
}).save()];
|
|
1011
|
-
case 2:
|
|
1012
|
-
e = _b.sent();
|
|
1013
|
-
expect(e.id).toBe(2);
|
|
1014
|
-
expect(e.a).toBe(1.5);
|
|
1015
|
-
return [2 /*return*/];
|
|
1016
|
-
}
|
|
1017
|
-
});
|
|
1018
|
-
});
|
|
354
|
+
catch (err) {
|
|
355
|
+
expect(cat._.fields.a.error).toEqual("already exists");
|
|
356
|
+
}
|
|
357
|
+
expect(saved).toBe(false);
|
|
1019
358
|
});
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
entityWithValidations_1.entityWithValidations.savingRowCount = 0;
|
|
1041
|
-
return [4 /*yield*/, api.post(t, { name: 'noam honig', myId: 1 })];
|
|
1042
|
-
case 2:
|
|
1043
|
-
_b.sent();
|
|
1044
|
-
expect(entityWithValidations_1.entityWithValidations.savingRowCount).toBe(1);
|
|
1045
|
-
d.test();
|
|
1046
|
-
return [2 /*return*/];
|
|
1047
|
-
}
|
|
1048
|
-
});
|
|
1049
|
-
});
|
|
359
|
+
let testNumbers = class testNumbers extends EntityBase {
|
|
360
|
+
};
|
|
361
|
+
__decorate([
|
|
362
|
+
Fields.integer(),
|
|
363
|
+
__metadata("design:type", Number)
|
|
364
|
+
], testNumbers.prototype, "id", void 0);
|
|
365
|
+
__decorate([
|
|
366
|
+
Fields.number(),
|
|
367
|
+
__metadata("design:type", Number)
|
|
368
|
+
], testNumbers.prototype, "a", void 0);
|
|
369
|
+
testNumbers = __decorate([
|
|
370
|
+
Entity('testNumbers', { allowApiCrud: true })
|
|
371
|
+
], testNumbers);
|
|
372
|
+
testAll("test that integer and int work", async ({ createEntity }) => {
|
|
373
|
+
let e = await (await createEntity(testNumbers)).create({
|
|
374
|
+
id: 1.5,
|
|
375
|
+
a: 1.5
|
|
376
|
+
}).save();
|
|
377
|
+
expect(e.id).toBe(2);
|
|
378
|
+
expect(e.a).toBe(1.5);
|
|
1050
379
|
});
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
status_in: '[1, 2]'
|
|
1090
|
-
})];
|
|
1091
|
-
case 2:
|
|
1092
|
-
_b.sent();
|
|
1093
|
-
d.test();
|
|
1094
|
-
return [2 /*return*/];
|
|
1095
|
-
}
|
|
1096
|
-
});
|
|
1097
|
-
});
|
|
380
|
+
testAll("post with logic works and max in entity", async ({ remult, createEntity }) => {
|
|
381
|
+
let c = await createEntity(entityWithValidations);
|
|
382
|
+
var api = new DataApi(c, remult);
|
|
383
|
+
let t = new TestDataApiResponse();
|
|
384
|
+
let d = new Done();
|
|
385
|
+
t.created = async (data) => {
|
|
386
|
+
expect(data.name).toBe('noam honig');
|
|
387
|
+
expect(data.myId).toBe(1);
|
|
388
|
+
d.ok();
|
|
389
|
+
};
|
|
390
|
+
entityWithValidations.savingRowCount = 0;
|
|
391
|
+
await api.post(t, { name: 'noam honig', myId: 1 });
|
|
392
|
+
expect(entityWithValidations.savingRowCount).toBe(1);
|
|
393
|
+
d.test();
|
|
394
|
+
});
|
|
395
|
+
testAllDbs("get array works with filter in body", async ({ createData, remult }) => {
|
|
396
|
+
let c = await createData(async (i) => {
|
|
397
|
+
await i(1, 'noam', undefined, Status.open);
|
|
398
|
+
await i(2, 'yael', undefined, Status.closed);
|
|
399
|
+
await i(3, 'yoni', undefined, Status.hold);
|
|
400
|
+
});
|
|
401
|
+
var api = new DataApi(c, remult);
|
|
402
|
+
let t = new TestDataApiResponse();
|
|
403
|
+
let d = new Done();
|
|
404
|
+
t.success = data => {
|
|
405
|
+
expect(data.length).toBe(2);
|
|
406
|
+
expect(data[0].id).toBe(2);
|
|
407
|
+
expect(data[1].id).toBe(3);
|
|
408
|
+
d.ok();
|
|
409
|
+
};
|
|
410
|
+
await api.getArray(t, {
|
|
411
|
+
get: x => {
|
|
412
|
+
return undefined;
|
|
413
|
+
}
|
|
414
|
+
}, {
|
|
415
|
+
status_in: '[1, 2]'
|
|
416
|
+
});
|
|
417
|
+
d.test();
|
|
1098
418
|
}, false);
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
return [4 /*yield*/, insert(2, "yoni")];
|
|
1123
|
-
case 2:
|
|
1124
|
-
_a.sent();
|
|
1125
|
-
return [4 /*yield*/, insert(3, "yael")];
|
|
1126
|
-
case 3:
|
|
1127
|
-
_a.sent();
|
|
1128
|
-
return [2 /*return*/];
|
|
1129
|
-
}
|
|
1130
|
-
});
|
|
1131
|
-
}); }, type)];
|
|
1132
|
-
case 1:
|
|
1133
|
-
c = _b.sent();
|
|
1134
|
-
return [4 /*yield*/, c.find()];
|
|
1135
|
-
case 2:
|
|
1136
|
-
x = _b.sent();
|
|
1137
|
-
expect(x[0].id).toBe(1);
|
|
1138
|
-
expect(x[1].id).toBe(3);
|
|
1139
|
-
expect(x[2].id).toBe(2);
|
|
1140
|
-
return [4 /*yield*/, c.find({ orderBy: {} })];
|
|
1141
|
-
case 3:
|
|
1142
|
-
x = _b.sent();
|
|
1143
|
-
expect(x[0].id).toBe(1);
|
|
1144
|
-
expect(x[1].id).toBe(3);
|
|
1145
|
-
expect(x[2].id).toBe(2);
|
|
1146
|
-
return [4 /*yield*/, c.query({ orderBy: {}, pageSize: 100 }).paginator()];
|
|
1147
|
-
case 4:
|
|
1148
|
-
x = (_b.sent()).items;
|
|
1149
|
-
expect(x[0].id).toBe(1);
|
|
1150
|
-
expect(x[1].id).toBe(3);
|
|
1151
|
-
expect(x[2].id).toBe(2);
|
|
1152
|
-
return [2 /*return*/];
|
|
1153
|
-
}
|
|
1154
|
-
});
|
|
1155
|
-
});
|
|
419
|
+
testAllDbs("entity order by works", async ({ createData }) => {
|
|
420
|
+
let type = class extends newCategories {
|
|
421
|
+
};
|
|
422
|
+
Entity('', {
|
|
423
|
+
defaultOrderBy: { categoryName: "asc" },
|
|
424
|
+
})(type);
|
|
425
|
+
let c = await createData(async (insert) => {
|
|
426
|
+
await insert(1, 'noam');
|
|
427
|
+
await insert(2, "yoni");
|
|
428
|
+
await insert(3, "yael");
|
|
429
|
+
}, type);
|
|
430
|
+
var x = await c.find();
|
|
431
|
+
expect(x[0].id).toBe(1);
|
|
432
|
+
expect(x[1].id).toBe(3);
|
|
433
|
+
expect(x[2].id).toBe(2);
|
|
434
|
+
var x = await c.find({ orderBy: {} });
|
|
435
|
+
expect(x[0].id).toBe(1);
|
|
436
|
+
expect(x[1].id).toBe(3);
|
|
437
|
+
expect(x[2].id).toBe(2);
|
|
438
|
+
var x = (await c.query({ orderBy: {}, pageSize: 100 }).paginator()).items;
|
|
439
|
+
expect(x[0].id).toBe(1);
|
|
440
|
+
expect(x[1].id).toBe(3);
|
|
441
|
+
expect(x[2].id).toBe(2);
|
|
1156
442
|
}, false);
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
case 1:
|
|
1186
|
-
c = _b.sent();
|
|
1187
|
-
api = new data_api_1.DataApi(c, remult);
|
|
1188
|
-
t = new TestDataApiResponse_1.TestDataApiResponse();
|
|
1189
|
-
d = new Done_1.Done();
|
|
1190
|
-
t.success = function (data) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
1191
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1192
|
-
d.ok();
|
|
1193
|
-
return [2 /*return*/];
|
|
1194
|
-
});
|
|
1195
|
-
}); };
|
|
1196
|
-
count = 0;
|
|
1197
|
-
return [4 /*yield*/, api.put(t, 1, {
|
|
1198
|
-
categoryName: 'noam 1'
|
|
1199
|
-
})];
|
|
1200
|
-
case 2:
|
|
1201
|
-
_b.sent();
|
|
1202
|
-
d.test();
|
|
1203
|
-
return [4 /*yield*/, c.find({
|
|
1204
|
-
where: { id: 1 }
|
|
1205
|
-
})];
|
|
1206
|
-
case 3:
|
|
1207
|
-
x = _b.sent();
|
|
1208
|
-
expect(x[0].categoryName).toBe('noam 1');
|
|
1209
|
-
expect(count).toBe(1);
|
|
1210
|
-
return [2 /*return*/];
|
|
1211
|
-
}
|
|
1212
|
-
});
|
|
1213
|
-
});
|
|
443
|
+
testAllDbs("put with validation works", async ({ createData, remult }) => {
|
|
444
|
+
let count = 0;
|
|
445
|
+
let type = class extends newCategories {
|
|
446
|
+
};
|
|
447
|
+
Entity(undefined, {
|
|
448
|
+
allowApiCrud: true,
|
|
449
|
+
saving: () => {
|
|
450
|
+
if (!testConfiguration.restDbRunningOnServer)
|
|
451
|
+
count++;
|
|
452
|
+
}
|
|
453
|
+
})(type);
|
|
454
|
+
let c = await createData(async (insert) => await insert(1, 'noam'), type);
|
|
455
|
+
var api = new DataApi(c, remult);
|
|
456
|
+
let t = new TestDataApiResponse();
|
|
457
|
+
let d = new Done();
|
|
458
|
+
t.success = async (data) => {
|
|
459
|
+
d.ok();
|
|
460
|
+
};
|
|
461
|
+
count = 0;
|
|
462
|
+
await api.put(t, 1, {
|
|
463
|
+
categoryName: 'noam 1'
|
|
464
|
+
});
|
|
465
|
+
d.test();
|
|
466
|
+
var x = await c.find({
|
|
467
|
+
where: { id: 1 }
|
|
468
|
+
});
|
|
469
|
+
expect(x[0].categoryName).toBe('noam 1');
|
|
470
|
+
expect(count).toBe(1);
|
|
1214
471
|
});
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
remult3_1.Fields.boolean()(type.prototype, "ok");
|
|
1234
|
-
return [4 /*yield*/, createEntity(type)];
|
|
1235
|
-
case 1:
|
|
1236
|
-
r = (_b.sent()).create();
|
|
1237
|
-
r.id = 1;
|
|
1238
|
-
r.ok = true;
|
|
1239
|
-
return [4 /*yield*/, r._.save()];
|
|
1240
|
-
case 2:
|
|
1241
|
-
_b.sent();
|
|
1242
|
-
expect(r.ok).toBe(true);
|
|
1243
|
-
r.ok = false;
|
|
1244
|
-
return [4 /*yield*/, r._.save()];
|
|
1245
|
-
case 3:
|
|
1246
|
-
_b.sent();
|
|
1247
|
-
expect(r.ok).toBe(false);
|
|
1248
|
-
return [2 /*return*/];
|
|
1249
|
-
}
|
|
1250
|
-
});
|
|
1251
|
-
});
|
|
472
|
+
testAll("saves correctly to db", async ({ createEntity }) => {
|
|
473
|
+
let type = class extends EntityBase {
|
|
474
|
+
constructor() {
|
|
475
|
+
super(...arguments);
|
|
476
|
+
this.ok = false;
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
Entity('asdf', { allowApiCrud: true })(type);
|
|
480
|
+
Fields.number()(type.prototype, 'id');
|
|
481
|
+
Fields.boolean()(type.prototype, "ok");
|
|
482
|
+
let r = (await createEntity(type)).create();
|
|
483
|
+
r.id = 1;
|
|
484
|
+
r.ok = true;
|
|
485
|
+
await r._.save();
|
|
486
|
+
expect(r.ok).toBe(true);
|
|
487
|
+
r.ok = false;
|
|
488
|
+
await r._.save();
|
|
489
|
+
expect(r.ok).toBe(false);
|
|
1252
490
|
});
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
var repo, r, x;
|
|
1275
|
-
return tslib_1.__generator(this, function (_b) {
|
|
1276
|
-
switch (_b.label) {
|
|
1277
|
-
case 0: return [4 /*yield*/, createEntity(autoIncrement)];
|
|
1278
|
-
case 1:
|
|
1279
|
-
repo = _b.sent();
|
|
1280
|
-
return [4 /*yield*/, repo.create({ id: 1234, stam: 1 }).save()];
|
|
1281
|
-
case 2:
|
|
1282
|
-
r = _b.sent();
|
|
1283
|
-
x = r.id;
|
|
1284
|
-
expect(x == 1234).toBe(false);
|
|
1285
|
-
r.id = 4321;
|
|
1286
|
-
return [4 /*yield*/, r.save()];
|
|
1287
|
-
case 3:
|
|
1288
|
-
_b.sent();
|
|
1289
|
-
expect(r.id).toBe(x);
|
|
1290
|
-
return [2 /*return*/];
|
|
1291
|
-
}
|
|
1292
|
-
});
|
|
1293
|
-
});
|
|
491
|
+
let autoIncrement = class autoIncrement extends EntityBase {
|
|
492
|
+
};
|
|
493
|
+
__decorate([
|
|
494
|
+
Fields.autoIncrement(),
|
|
495
|
+
__metadata("design:type", Number)
|
|
496
|
+
], autoIncrement.prototype, "id", void 0);
|
|
497
|
+
__decorate([
|
|
498
|
+
Fields.integer(),
|
|
499
|
+
__metadata("design:type", Number)
|
|
500
|
+
], autoIncrement.prototype, "stam", void 0);
|
|
501
|
+
autoIncrement = __decorate([
|
|
502
|
+
Entity("autoi", { allowApiCrud: true })
|
|
503
|
+
], autoIncrement);
|
|
504
|
+
testAll("auto increment can't be affected by insert or update", async ({ createEntity }) => {
|
|
505
|
+
let repo = await createEntity(autoIncrement);
|
|
506
|
+
let r = await repo.create({ id: 1234, stam: 1 }).save();
|
|
507
|
+
let x = r.id;
|
|
508
|
+
expect(x == 1234).toBe(false);
|
|
509
|
+
r.id = 4321;
|
|
510
|
+
await r.save();
|
|
511
|
+
expect(r.id).toBe(x);
|
|
1294
512
|
}, false);
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
return tslib_1.__generator(this, function (_d) {
|
|
1300
|
-
switch (_d.label) {
|
|
1301
|
-
case 0: return [4 /*yield*/, entityWithValidations_1.entityWithValidations.create4RowsInDp(createEntity)];
|
|
1302
|
-
case 1:
|
|
1303
|
-
s = _d.sent();
|
|
1304
|
-
_b = expect;
|
|
1305
|
-
return [4 /*yield*/, s.find({ limit: 3, orderBy: { myId: "asc" } })];
|
|
1306
|
-
case 2:
|
|
1307
|
-
_b.apply(void 0, [(_d.sent()).length]).toBe(3);
|
|
1308
|
-
_c = expect;
|
|
1309
|
-
return [4 /*yield*/, s.find({ limit: 3, orderBy: { myId: "asc" }, page: 2 })];
|
|
1310
|
-
case 3:
|
|
1311
|
-
_c.apply(void 0, [(_d.sent()).length]).toBe(1);
|
|
1312
|
-
return [2 /*return*/];
|
|
1313
|
-
}
|
|
1314
|
-
});
|
|
1315
|
-
});
|
|
513
|
+
testAll("Paging", async ({ createEntity }) => {
|
|
514
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
515
|
+
expect((await s.find({ limit: 3, orderBy: { myId: "asc" } })).length).toBe(3);
|
|
516
|
+
expect((await s.find({ limit: 3, orderBy: { myId: "asc" }, page: 2 })).length).toBe(1);
|
|
1316
517
|
}, false);
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
case 1:
|
|
1325
|
-
s = _c.sent();
|
|
1326
|
-
return [4 /*yield*/, s.insert({ id: 1, a: 'a', b: 'b', c: 'c' })];
|
|
1327
|
-
case 2:
|
|
1328
|
-
_c.sent();
|
|
1329
|
-
_b = expect;
|
|
1330
|
-
return [4 /*yield*/, s.count({
|
|
1331
|
-
a: 'z',
|
|
1332
|
-
$and: [testFilter.search('')]
|
|
1333
|
-
})];
|
|
1334
|
-
case 3:
|
|
1335
|
-
_b.apply(void 0, [_c.sent()]).toBe(0);
|
|
1336
|
-
return [2 /*return*/];
|
|
1337
|
-
}
|
|
1338
|
-
});
|
|
1339
|
-
});
|
|
518
|
+
testAll("filter", async ({ createEntity }) => {
|
|
519
|
+
const s = await createEntity(testFilter);
|
|
520
|
+
await s.insert({ id: 1, a: 'a', b: 'b', c: 'c' });
|
|
521
|
+
expect(await s.count({
|
|
522
|
+
a: 'z',
|
|
523
|
+
$and: [testFilter.search('')]
|
|
524
|
+
})).toBe(0);
|
|
1340
525
|
}, false);
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
switch (_b.label) {
|
|
1347
|
-
case 0: return [4 /*yield*/, createEntity(stam)];
|
|
1348
|
-
case 1:
|
|
1349
|
-
s = _b.sent();
|
|
1350
|
-
return [4 /*yield*/, s.insert({ title: "1234567890".repeat(100) })];
|
|
1351
|
-
case 2:
|
|
1352
|
-
_b.sent();
|
|
1353
|
-
return [4 /*yield*/, s.findFirst()];
|
|
1354
|
-
case 3:
|
|
1355
|
-
r = _b.sent();
|
|
1356
|
-
expect(r.title).toBe("1234567890".repeat(100));
|
|
1357
|
-
return [2 /*return*/];
|
|
1358
|
-
}
|
|
1359
|
-
});
|
|
1360
|
-
});
|
|
526
|
+
testAll("large string field", async ({ createEntity }) => {
|
|
527
|
+
const s = await createEntity(stam);
|
|
528
|
+
await s.insert({ title: "1234567890".repeat(100) });
|
|
529
|
+
const r = await s.findFirst();
|
|
530
|
+
expect(r.title).toBe("1234567890".repeat(100));
|
|
1361
531
|
}, false);
|
|
1362
|
-
|
|
1363
|
-
|
|
532
|
+
let testFilter = class testFilter {
|
|
533
|
+
constructor() {
|
|
1364
534
|
this.id = 0;
|
|
1365
535
|
this.a = '';
|
|
1366
536
|
this.b = '';
|
|
1367
537
|
this.c = '';
|
|
1368
538
|
}
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1403
|
-
_this.id = 0;
|
|
1404
|
-
return _this;
|
|
539
|
+
};
|
|
540
|
+
testFilter.search = Filter.createCustom((remult, str) => ({
|
|
541
|
+
$and: [{
|
|
542
|
+
$or: [
|
|
543
|
+
{ a: 'a' },
|
|
544
|
+
{ b: 'a' },
|
|
545
|
+
{ c: 'a' }
|
|
546
|
+
]
|
|
547
|
+
}]
|
|
548
|
+
}));
|
|
549
|
+
__decorate([
|
|
550
|
+
Fields.integer(),
|
|
551
|
+
__metadata("design:type", Number)
|
|
552
|
+
], testFilter.prototype, "id", void 0);
|
|
553
|
+
__decorate([
|
|
554
|
+
Fields.string(),
|
|
555
|
+
__metadata("design:type", String)
|
|
556
|
+
], testFilter.prototype, "a", void 0);
|
|
557
|
+
__decorate([
|
|
558
|
+
Fields.string(),
|
|
559
|
+
__metadata("design:type", String)
|
|
560
|
+
], testFilter.prototype, "b", void 0);
|
|
561
|
+
__decorate([
|
|
562
|
+
Fields.string(),
|
|
563
|
+
__metadata("design:type", String)
|
|
564
|
+
], testFilter.prototype, "c", void 0);
|
|
565
|
+
testFilter = __decorate([
|
|
566
|
+
Entity("testfilter", { allowApiCrud: true })
|
|
567
|
+
], testFilter);
|
|
568
|
+
let testStringWithNull = class testStringWithNull extends EntityBase {
|
|
569
|
+
constructor() {
|
|
570
|
+
super(...arguments);
|
|
571
|
+
this.id = 0;
|
|
1405
572
|
}
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
_this.id = 0;
|
|
1424
|
-
_this.title = '';
|
|
1425
|
-
return _this;
|
|
573
|
+
};
|
|
574
|
+
__decorate([
|
|
575
|
+
Fields.integer(),
|
|
576
|
+
__metadata("design:type", Number)
|
|
577
|
+
], testStringWithNull.prototype, "id", void 0);
|
|
578
|
+
__decorate([
|
|
579
|
+
Fields.string({ allowNull: true }),
|
|
580
|
+
__metadata("design:type", String)
|
|
581
|
+
], testStringWithNull.prototype, "d", void 0);
|
|
582
|
+
testStringWithNull = __decorate([
|
|
583
|
+
Entity('teststringWithNull', { allowApiCrud: true })
|
|
584
|
+
], testStringWithNull);
|
|
585
|
+
let stam = class stam extends EntityBase {
|
|
586
|
+
constructor() {
|
|
587
|
+
super(...arguments);
|
|
588
|
+
this.id = 0;
|
|
589
|
+
this.title = '';
|
|
1426
590
|
}
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
}
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
var _this = _super.call(this) || this;
|
|
1445
|
-
_this.remult = remult;
|
|
1446
|
-
return _this;
|
|
591
|
+
};
|
|
592
|
+
__decorate([
|
|
593
|
+
Fields.integer(),
|
|
594
|
+
__metadata("design:type", Number)
|
|
595
|
+
], stam.prototype, "id", void 0);
|
|
596
|
+
__decorate([
|
|
597
|
+
Fields.string({ maxLength: 1500 }),
|
|
598
|
+
__metadata("design:type", String)
|
|
599
|
+
], stam.prototype, "title", void 0);
|
|
600
|
+
stam = __decorate([
|
|
601
|
+
Entity("a", { allowApiCrud: true })
|
|
602
|
+
], stam);
|
|
603
|
+
export { stam };
|
|
604
|
+
let p = class p extends EntityBase {
|
|
605
|
+
constructor(remult) {
|
|
606
|
+
super();
|
|
607
|
+
this.remult = remult;
|
|
1447
608
|
}
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
_this.completed = false;
|
|
1472
|
-
_this.priority = Priority.Low;
|
|
1473
|
-
return _this;
|
|
609
|
+
};
|
|
610
|
+
__decorate([
|
|
611
|
+
Fields.integer(),
|
|
612
|
+
__metadata("design:type", Number)
|
|
613
|
+
], p.prototype, "id", void 0);
|
|
614
|
+
__decorate([
|
|
615
|
+
Fields.string(),
|
|
616
|
+
__metadata("design:type", String)
|
|
617
|
+
], p.prototype, "name", void 0);
|
|
618
|
+
__decorate([
|
|
619
|
+
Field(() => c),
|
|
620
|
+
__metadata("design:type", c)
|
|
621
|
+
], p.prototype, "c", void 0);
|
|
622
|
+
p = __decorate([
|
|
623
|
+
Entity('p', { allowApiCrud: true }),
|
|
624
|
+
__metadata("design:paramtypes", [Remult])
|
|
625
|
+
], p);
|
|
626
|
+
let tasksWithEnum = class tasksWithEnum extends IdEntity {
|
|
627
|
+
constructor() {
|
|
628
|
+
super(...arguments);
|
|
629
|
+
this.title = '';
|
|
630
|
+
this.completed = false;
|
|
631
|
+
this.priority = Priority.Low;
|
|
1474
632
|
}
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
}
|
|
1494
|
-
|
|
1495
|
-
var Priority;
|
|
633
|
+
};
|
|
634
|
+
__decorate([
|
|
635
|
+
Fields.string(),
|
|
636
|
+
__metadata("design:type", Object)
|
|
637
|
+
], tasksWithEnum.prototype, "title", void 0);
|
|
638
|
+
__decorate([
|
|
639
|
+
Fields.boolean(),
|
|
640
|
+
__metadata("design:type", Object)
|
|
641
|
+
], tasksWithEnum.prototype, "completed", void 0);
|
|
642
|
+
__decorate([
|
|
643
|
+
Fields.object(),
|
|
644
|
+
__metadata("design:type", Object)
|
|
645
|
+
], tasksWithEnum.prototype, "priority", void 0);
|
|
646
|
+
tasksWithEnum = __decorate([
|
|
647
|
+
Entity('tasksWithEnum', {
|
|
648
|
+
allowApiCrud: true
|
|
649
|
+
})
|
|
650
|
+
], tasksWithEnum);
|
|
651
|
+
export { tasksWithEnum };
|
|
652
|
+
export var Priority;
|
|
1496
653
|
(function (Priority) {
|
|
1497
654
|
Priority[Priority["Low"] = 0] = "Low";
|
|
1498
655
|
Priority[Priority["High"] = 1] = "High";
|
|
1499
656
|
Priority[Priority["Critical"] = 2] = "Critical";
|
|
1500
|
-
})(Priority
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
title: 'a',
|
|
1512
|
-
priority: Priority.Critical
|
|
1513
|
-
})];
|
|
1514
|
-
case 2:
|
|
1515
|
-
_d.sent();
|
|
1516
|
-
return [4 /*yield*/, r.findFirst()];
|
|
1517
|
-
case 3:
|
|
1518
|
-
item = _d.sent();
|
|
1519
|
-
expect(item.priority).toBe(Priority.Critical);
|
|
1520
|
-
_b = expect;
|
|
1521
|
-
return [4 /*yield*/, r.count({ priority: Priority.Critical })];
|
|
1522
|
-
case 4:
|
|
1523
|
-
_b.apply(void 0, [_d.sent()]).toBe(1);
|
|
1524
|
-
_c = expect;
|
|
1525
|
-
return [4 /*yield*/, r.count({ priority: Priority.Low })];
|
|
1526
|
-
case 5:
|
|
1527
|
-
_c.apply(void 0, [_d.sent()]).toBe(0);
|
|
1528
|
-
return [2 /*return*/];
|
|
1529
|
-
}
|
|
1530
|
-
});
|
|
1531
|
-
});
|
|
657
|
+
})(Priority || (Priority = {}));
|
|
658
|
+
testAll("task with enum", async ({ createEntity }) => {
|
|
659
|
+
const r = await createEntity(tasksWithEnum);
|
|
660
|
+
await r.insert({
|
|
661
|
+
title: 'a',
|
|
662
|
+
priority: Priority.Critical
|
|
663
|
+
});
|
|
664
|
+
const item = await r.findFirst();
|
|
665
|
+
expect(item.priority).toBe(Priority.Critical);
|
|
666
|
+
expect(await r.count({ priority: Priority.Critical })).toBe(1);
|
|
667
|
+
expect(await r.count({ priority: Priority.Low })).toBe(0);
|
|
1532
668
|
});
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
_this.priority = PriorityWithString.Low;
|
|
1540
|
-
return _this;
|
|
669
|
+
let tasksWithStringEnum = class tasksWithStringEnum extends IdEntity {
|
|
670
|
+
constructor() {
|
|
671
|
+
super(...arguments);
|
|
672
|
+
this.title = '';
|
|
673
|
+
this.completed = false;
|
|
674
|
+
this.priority = PriorityWithString.Low;
|
|
1541
675
|
}
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
}
|
|
1561
|
-
|
|
1562
|
-
var PriorityWithString;
|
|
676
|
+
};
|
|
677
|
+
__decorate([
|
|
678
|
+
Fields.string(),
|
|
679
|
+
__metadata("design:type", Object)
|
|
680
|
+
], tasksWithStringEnum.prototype, "title", void 0);
|
|
681
|
+
__decorate([
|
|
682
|
+
Fields.boolean(),
|
|
683
|
+
__metadata("design:type", Object)
|
|
684
|
+
], tasksWithStringEnum.prototype, "completed", void 0);
|
|
685
|
+
__decorate([
|
|
686
|
+
Fields.object(),
|
|
687
|
+
__metadata("design:type", Object)
|
|
688
|
+
], tasksWithStringEnum.prototype, "priority", void 0);
|
|
689
|
+
tasksWithStringEnum = __decorate([
|
|
690
|
+
Entity('tasksWithStringEnum', {
|
|
691
|
+
allowApiCrud: true
|
|
692
|
+
})
|
|
693
|
+
], tasksWithStringEnum);
|
|
694
|
+
export { tasksWithStringEnum };
|
|
695
|
+
export var PriorityWithString;
|
|
1563
696
|
(function (PriorityWithString) {
|
|
1564
697
|
PriorityWithString["Low"] = "Low";
|
|
1565
698
|
PriorityWithString["High"] = "High";
|
|
1566
699
|
PriorityWithString["Critical"] = "Critical";
|
|
1567
|
-
})(PriorityWithString
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
title: 'a',
|
|
1579
|
-
priority: PriorityWithString.Critical
|
|
1580
|
-
})];
|
|
1581
|
-
case 2:
|
|
1582
|
-
_d.sent();
|
|
1583
|
-
return [4 /*yield*/, r.findFirst()];
|
|
1584
|
-
case 3:
|
|
1585
|
-
item = _d.sent();
|
|
1586
|
-
expect(item.priority).toBe(PriorityWithString.Critical);
|
|
1587
|
-
_b = expect;
|
|
1588
|
-
return [4 /*yield*/, r.count({ priority: PriorityWithString.Critical })];
|
|
1589
|
-
case 4:
|
|
1590
|
-
_b.apply(void 0, [_d.sent()]).toBe(1);
|
|
1591
|
-
_c = expect;
|
|
1592
|
-
return [4 /*yield*/, r.count({ priority: PriorityWithString.Low })];
|
|
1593
|
-
case 5:
|
|
1594
|
-
_c.apply(void 0, [_d.sent()]).toBe(0);
|
|
1595
|
-
return [2 /*return*/];
|
|
1596
|
-
}
|
|
1597
|
-
});
|
|
1598
|
-
});
|
|
700
|
+
})(PriorityWithString || (PriorityWithString = {}));
|
|
701
|
+
testAll("task with enum string", async ({ createEntity }) => {
|
|
702
|
+
const r = await createEntity(tasksWithStringEnum);
|
|
703
|
+
await r.insert({
|
|
704
|
+
title: 'a',
|
|
705
|
+
priority: PriorityWithString.Critical
|
|
706
|
+
});
|
|
707
|
+
const item = await r.findFirst();
|
|
708
|
+
expect(item.priority).toBe(PriorityWithString.Critical);
|
|
709
|
+
expect(await r.count({ priority: PriorityWithString.Critical })).toBe(1);
|
|
710
|
+
expect(await r.count({ priority: PriorityWithString.Low })).toBe(0);
|
|
1599
711
|
});
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
switch (_c.label) {
|
|
1606
|
-
case 0:
|
|
1607
|
-
fail = true;
|
|
1608
|
-
_c.label = 1;
|
|
1609
|
-
case 1:
|
|
1610
|
-
_c.trys.push([1, 3, , 4]);
|
|
1611
|
-
return [4 /*yield*/, db.transaction(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
1612
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1613
|
-
throw "error";
|
|
1614
|
-
});
|
|
1615
|
-
}); })];
|
|
1616
|
-
case 2:
|
|
1617
|
-
_c.sent();
|
|
1618
|
-
fail = false;
|
|
1619
|
-
return [3 /*break*/, 4];
|
|
1620
|
-
case 3:
|
|
1621
|
-
_b = _c.sent();
|
|
1622
|
-
return [3 /*break*/, 4];
|
|
1623
|
-
case 4:
|
|
1624
|
-
expect(fail).toBe(true);
|
|
1625
|
-
return [2 /*return*/];
|
|
1626
|
-
}
|
|
712
|
+
testAll("test transaction rollback", async ({ db }) => {
|
|
713
|
+
let fail = true;
|
|
714
|
+
try {
|
|
715
|
+
await db.transaction(async () => {
|
|
716
|
+
throw "error";
|
|
1627
717
|
});
|
|
1628
|
-
|
|
718
|
+
fail = false;
|
|
719
|
+
}
|
|
720
|
+
catch {
|
|
721
|
+
}
|
|
722
|
+
expect(fail).toBe(true);
|
|
1629
723
|
});
|