remult 0.14.7 → 0.14.8
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/esm/assign.d.ts +1 -0
- package/esm/assign.js +5 -0
- package/esm/classType.d.ts +3 -0
- package/esm/classType.js +1 -0
- package/esm/graphql.d.ts +5 -0
- package/esm/graphql.js +102 -0
- package/esm/index.d.ts +36 -0
- package/esm/index.js +30 -0
- package/esm/inputTypes.d.ts +9 -0
- package/esm/inputTypes.js +9 -0
- package/esm/postgres/index.d.ts +2 -0
- package/esm/postgres/index.js +2 -0
- package/esm/postgres/postgres-data-provider.d.ts +28 -0
- package/esm/postgres/postgres-data-provider.js +97 -0
- package/esm/postgres/schema-builder.d.ts +15 -0
- package/esm/postgres/schema-builder.js +128 -0
- package/esm/remult-express.d.ts +5 -0
- package/esm/remult-express.js +16 -0
- package/esm/remult-knex/index.d.ts +51 -0
- package/esm/remult-knex/index.js +381 -0
- package/esm/remult-middleware.d.ts +2 -0
- package/esm/remult-middleware.js +63 -0
- package/esm/remult-mongo.d.ts +9 -0
- package/esm/remult-mongo.js +220 -0
- package/esm/server/JsonEntityFileStorage.d.ts +7 -0
- package/esm/server/JsonEntityFileStorage.js +20 -0
- package/esm/server/expressBridge.d.ts +140 -0
- package/esm/server/expressBridge.js +668 -0
- package/esm/server/index.d.ts +4 -0
- package/esm/server/index.js +4 -0
- package/esm/server/register-actions-on-server.d.ts +3 -0
- package/esm/server/register-actions-on-server.js +24 -0
- package/esm/server/register-entities-on-server.d.ts +3 -0
- package/esm/server/register-entities-on-server.js +15 -0
- package/esm/src/__EntityValueProvider.d.ts +10 -0
- package/esm/src/__EntityValueProvider.js +1 -0
- package/esm/src/__RowsOfDataForTesting.d.ts +3 -0
- package/esm/src/__RowsOfDataForTesting.js +1 -0
- package/esm/src/backend-tests/backend-database-test-setup.backend-spec.d.ts +5 -0
- package/esm/src/backend-tests/backend-database-test-setup.backend-spec.js +113 -0
- package/esm/src/backend-tests/my-test.backend-spec.d.ts +1 -0
- package/esm/src/backend-tests/my-test.backend-spec.js +49 -0
- package/esm/src/column-interfaces.d.ts +95 -0
- package/esm/src/column-interfaces.js +7 -0
- package/esm/src/column.d.ts +49 -0
- package/esm/src/column.js +133 -0
- package/esm/src/context.d.ts +124 -0
- package/esm/src/context.js +285 -0
- package/esm/src/data-api.d.ts +33 -0
- package/esm/src/data-api.js +204 -0
- package/esm/src/data-interfaces.d.ts +37 -0
- package/esm/src/data-interfaces.js +12 -0
- package/esm/src/data-providers/array-entity-data-provider.d.ts +22 -0
- package/esm/src/data-providers/array-entity-data-provider.js +264 -0
- package/esm/src/data-providers/in-memory-database.d.ts +9 -0
- package/esm/src/data-providers/in-memory-database.js +16 -0
- package/esm/src/data-providers/json-data-provider.d.ts +12 -0
- package/esm/src/data-providers/json-data-provider.js +52 -0
- package/esm/src/data-providers/rest-data-provider.d.ts +35 -0
- package/esm/src/data-providers/rest-data-provider.js +188 -0
- package/esm/src/data-providers/sql-database.d.ts +16 -0
- package/esm/src/data-providers/sql-database.js +261 -0
- package/esm/src/data-providers/web-sql-data-provider.d.ts +18 -0
- package/esm/src/data-providers/web-sql-data-provider.js +121 -0
- package/esm/src/entity.d.ts +82 -0
- package/esm/src/entity.js +1 -0
- package/esm/src/filter/filter-consumer-bridge-to-sql-request.d.ts +50 -0
- package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +139 -0
- package/esm/src/filter/filter-consumer-bridge-to-url-builder.d.ts +1 -0
- package/esm/src/filter/filter-consumer-bridge-to-url-builder.js +1 -0
- package/esm/src/filter/filter-interfaces.d.ts +85 -0
- package/esm/src/filter/filter-interfaces.js +467 -0
- package/esm/src/id-entity.d.ts +4 -0
- package/esm/src/id-entity.js +8 -0
- package/esm/src/remult3/RepositoryImplementation.d.ts +326 -0
- package/esm/src/remult3/RepositoryImplementation.js +1806 -0
- package/esm/src/remult3/index.d.ts +2 -0
- package/esm/src/remult3/index.js +2 -0
- package/esm/src/remult3/remult3.d.ts +312 -0
- package/esm/src/remult3/remult3.js +1 -0
- package/esm/src/server-action.d.ts +70 -0
- package/esm/src/server-action.js +365 -0
- package/esm/src/shared-tests/db-tests-setup.d.ts +23 -0
- package/esm/src/shared-tests/db-tests-setup.js +66 -0
- package/esm/src/shared-tests/db-tests.db-tests.d.ts +26 -0
- package/esm/src/shared-tests/db-tests.db-tests.js +723 -0
- package/esm/src/shared-tests/deleteAll.d.ts +2 -0
- package/esm/src/shared-tests/deleteAll.js +4 -0
- package/esm/src/shared-tests/entityWithValidations.d.ts +14 -0
- package/esm/src/shared-tests/entityWithValidations.js +53 -0
- package/esm/src/shared-tests/index.d.ts +4 -0
- package/esm/src/shared-tests/index.js +4 -0
- package/esm/src/shared-tests/test-custom-id-column.spec.d.ts +1 -0
- package/esm/src/shared-tests/test-custom-id-column.spec.js +62 -0
- package/esm/src/shared-tests/test-special-value.spec.d.ts +10 -0
- package/esm/src/shared-tests/test-special-value.spec.js +88 -0
- package/esm/src/shared-tests/test-update-with-null.spec.d.ts +1 -0
- package/esm/src/shared-tests/test-update-with-null.spec.js +47 -0
- package/esm/src/sort.d.ts +15 -0
- package/esm/src/sort.js +82 -0
- package/esm/src/sql-command.d.ts +15 -0
- package/esm/src/sql-command.js +1 -0
- package/esm/src/tests/Done.d.ts +5 -0
- package/esm/src/tests/Done.js +11 -0
- package/esm/src/tests/TestDataApiResponse.d.ts +10 -0
- package/esm/src/tests/TestDataApiResponse.js +22 -0
- package/esm/src/tests/c.d.ts +8 -0
- package/esm/src/tests/c.js +22 -0
- package/esm/src/tests/createData.d.ts +7 -0
- package/esm/src/tests/createData.js +22 -0
- package/esm/src/tests/d.d.ts +6 -0
- package/esm/src/tests/d.js +19 -0
- package/esm/src/tests/dWithPrefilter.d.ts +7 -0
- package/esm/src/tests/dWithPrefilter.js +32 -0
- package/esm/src/tests/entityForCustomFilter.d.ts +16 -0
- package/esm/src/tests/entityForCustomFilter.js +44 -0
- package/esm/src/tests/entityWithValidationsOnColumn.d.ts +5 -0
- package/esm/src/tests/entityWithValidationsOnColumn.js +21 -0
- package/esm/src/tests/frontend-database-tests-setup.spec.d.ts +4 -0
- package/esm/src/tests/frontend-database-tests-setup.spec.js +38 -0
- package/esm/src/tests/h.d.ts +6 -0
- package/esm/src/tests/h.js +35 -0
- package/esm/src/tests/remult-3-entities.d.ts +23 -0
- package/esm/src/tests/remult-3-entities.js +72 -0
- package/esm/src/tests/tasks.d.ts +6 -0
- package/esm/src/tests/tasks.js +24 -0
- package/esm/src/tests/testHelper.spec.d.ts +34 -0
- package/esm/src/tests/testHelper.spec.js +217 -0
- package/esm/src/tests/testModel/models.d.ts +16 -0
- package/esm/src/tests/testModel/models.js +31 -0
- package/esm/src/validators.d.ts +14 -0
- package/esm/src/validators.js +33 -0
- package/esm/urlBuilder.d.ts +6 -0
- package/esm/urlBuilder.js +19 -0
- package/esm/valueConverters.d.ts +12 -0
- package/esm/valueConverters.js +169 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +22 -1
- package/postgres/index.d.ts +1 -0
- package/postgres/index.js +1 -0
- package/postgres/postgres-data-provider.d.ts +1 -13
- package/postgres/postgres-data-provider.js +28 -262
- package/postgres/schema-builder.d.ts +15 -0
- package/postgres/schema-builder.js +270 -0
- package/readme.md +68 -30
- package/src/data-providers/web-sql-data-provider.js +4 -3
- package/src/entity.d.ts +9 -2
- package/src/remult3/RepositoryImplementation.js +11 -3
- package/src/shared-tests/test-update-with-null.spec.js +38 -0
- package/valueConverters.js +4 -0
|
@@ -0,0 +1,723 @@
|
|
|
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);
|
|
24
|
+
}, false);
|
|
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);
|
|
28
|
+
}, false);
|
|
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);
|
|
32
|
+
}, false);
|
|
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);
|
|
36
|
+
}, false);
|
|
37
|
+
testAll("test empty in", async ({ createEntity }) => {
|
|
38
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
39
|
+
expect((await s.find({ where: { myId: [] } })).length).toBe(0);
|
|
40
|
+
}, false);
|
|
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);
|
|
44
|
+
}, false);
|
|
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);
|
|
48
|
+
}, false);
|
|
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);
|
|
52
|
+
}, false);
|
|
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);
|
|
63
|
+
}, false);
|
|
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');
|
|
72
|
+
}, false);
|
|
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);
|
|
82
|
+
}, false);
|
|
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);
|
|
91
|
+
}, false);
|
|
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');
|
|
104
|
+
}, false);
|
|
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');
|
|
126
|
+
});
|
|
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);
|
|
134
|
+
}, false);
|
|
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);
|
|
138
|
+
});
|
|
139
|
+
let testDateWithNull = class testDateWithNull extends EntityBase {
|
|
140
|
+
constructor() {
|
|
141
|
+
super(...arguments);
|
|
142
|
+
this.id = 0;
|
|
143
|
+
}
|
|
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();
|
|
162
|
+
});
|
|
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);
|
|
180
|
+
}, false);
|
|
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);
|
|
188
|
+
}, false);
|
|
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);
|
|
207
|
+
});
|
|
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);
|
|
212
|
+
});
|
|
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);
|
|
225
|
+
});
|
|
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);
|
|
238
|
+
});
|
|
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);
|
|
247
|
+
});
|
|
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');
|
|
267
|
+
});
|
|
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');
|
|
280
|
+
}, false);
|
|
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);
|
|
289
|
+
}, false);
|
|
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);
|
|
306
|
+
}, false);
|
|
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);
|
|
335
|
+
});
|
|
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;
|
|
353
|
+
}
|
|
354
|
+
catch (err) {
|
|
355
|
+
expect(cat._.fields.a.error).toEqual("already exists");
|
|
356
|
+
}
|
|
357
|
+
expect(saved).toBe(false);
|
|
358
|
+
});
|
|
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);
|
|
379
|
+
});
|
|
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();
|
|
418
|
+
}, false);
|
|
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);
|
|
442
|
+
}, false);
|
|
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);
|
|
471
|
+
});
|
|
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);
|
|
490
|
+
});
|
|
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);
|
|
512
|
+
}, false);
|
|
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);
|
|
517
|
+
}, false);
|
|
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);
|
|
525
|
+
}, false);
|
|
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));
|
|
531
|
+
}, false);
|
|
532
|
+
let testFilter = class testFilter {
|
|
533
|
+
constructor() {
|
|
534
|
+
this.id = 0;
|
|
535
|
+
this.a = '';
|
|
536
|
+
this.b = '';
|
|
537
|
+
this.c = '';
|
|
538
|
+
}
|
|
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;
|
|
572
|
+
}
|
|
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 = '';
|
|
590
|
+
}
|
|
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;
|
|
608
|
+
}
|
|
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;
|
|
632
|
+
}
|
|
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;
|
|
653
|
+
(function (Priority) {
|
|
654
|
+
Priority[Priority["Low"] = 0] = "Low";
|
|
655
|
+
Priority[Priority["High"] = 1] = "High";
|
|
656
|
+
Priority[Priority["Critical"] = 2] = "Critical";
|
|
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);
|
|
668
|
+
});
|
|
669
|
+
let tasksWithStringEnum = class tasksWithStringEnum extends IdEntity {
|
|
670
|
+
constructor() {
|
|
671
|
+
super(...arguments);
|
|
672
|
+
this.title = '';
|
|
673
|
+
this.completed = false;
|
|
674
|
+
this.priority = PriorityWithString.Low;
|
|
675
|
+
}
|
|
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;
|
|
696
|
+
(function (PriorityWithString) {
|
|
697
|
+
PriorityWithString["Low"] = "Low";
|
|
698
|
+
PriorityWithString["High"] = "High";
|
|
699
|
+
PriorityWithString["Critical"] = "Critical";
|
|
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);
|
|
711
|
+
});
|
|
712
|
+
testAll("test transaction rollback", async ({ db }) => {
|
|
713
|
+
let fail = true;
|
|
714
|
+
try {
|
|
715
|
+
await db.transaction(async () => {
|
|
716
|
+
throw "error";
|
|
717
|
+
});
|
|
718
|
+
fail = false;
|
|
719
|
+
}
|
|
720
|
+
catch {
|
|
721
|
+
}
|
|
722
|
+
expect(fail).toBe(true);
|
|
723
|
+
});
|