remult 0.14.2 → 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.d.ts +13 -0
- package/index.js +25 -55
- package/inputTypes.js +9 -16
- package/package.json +6 -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
package/server/index.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "JsonEntityFileStorage", { enumerable: true, get: function () { return JsonEntityFileStorage_1.JsonEntityFileStorage; } });
|
|
6
|
-
var expressBridge_1 = require("./expressBridge");
|
|
7
|
-
Object.defineProperty(exports, "SiteArea", { enumerable: true, get: function () { return expressBridge_1.SiteArea; } });
|
|
8
|
-
var register_entities_on_server_1 = require("./register-entities-on-server");
|
|
9
|
-
Object.defineProperty(exports, "registerEntitiesOnServer", { enumerable: true, get: function () { return register_entities_on_server_1.registerEntitiesOnServer; } });
|
|
10
|
-
var register_actions_on_server_1 = require("./register-actions-on-server");
|
|
11
|
-
Object.defineProperty(exports, "registerActionsOnServer", { enumerable: true, get: function () { return register_actions_on_server_1.registerActionsOnServer; } });
|
|
1
|
+
export { JsonEntityFileStorage } from './JsonEntityFileStorage';
|
|
2
|
+
export { SiteArea } from './expressBridge';
|
|
3
|
+
export { registerEntitiesOnServer } from './register-entities-on-server';
|
|
4
|
+
export { registerActionsOnServer } from './register-actions-on-server';
|
|
@@ -1,50 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var server_action_1 = require("../src/server-action");
|
|
6
|
-
function registerActionsOnServer(area, controllers) {
|
|
7
|
-
var e_1, _a, e_2, _b;
|
|
8
|
-
var addAction = function (a) {
|
|
9
|
-
var x = a[server_action_1.serverActionField];
|
|
1
|
+
import { serverActionField, actionInfo, classBackendMethodsArray } from '../src/server-action';
|
|
2
|
+
export function registerActionsOnServer(area, controllers) {
|
|
3
|
+
var addAction = (a) => {
|
|
4
|
+
let x = a[serverActionField];
|
|
10
5
|
if (!x) {
|
|
11
6
|
throw 'failed to set server action, did you forget the BackendMethod Decorator?';
|
|
12
7
|
}
|
|
13
8
|
area.addAction(x);
|
|
14
9
|
};
|
|
15
|
-
|
|
10
|
+
actionInfo.runningOnServer = true;
|
|
16
11
|
if (controllers && controllers.length > 0) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
for (var z_1 = (e_2 = void 0, tslib_1.__values(z)), z_1_1 = z_1.next(); !z_1_1.done; z_1_1 = z_1.next()) {
|
|
24
|
-
var a = z_1_1.value;
|
|
25
|
-
addAction(a);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
29
|
-
finally {
|
|
30
|
-
try {
|
|
31
|
-
if (z_1_1 && !z_1_1.done && (_b = z_1.return)) _b.call(z_1);
|
|
32
|
-
}
|
|
33
|
-
finally { if (e_2) throw e_2.error; }
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
38
|
-
finally {
|
|
39
|
-
try {
|
|
40
|
-
if (controllers_1_1 && !controllers_1_1.done && (_a = controllers_1.return)) _a.call(controllers_1);
|
|
41
|
-
}
|
|
42
|
-
finally { if (e_1) throw e_1.error; }
|
|
12
|
+
for (const c of controllers) {
|
|
13
|
+
let z = c[classBackendMethodsArray];
|
|
14
|
+
if (z)
|
|
15
|
+
for (const a of z) {
|
|
16
|
+
addAction(a);
|
|
17
|
+
}
|
|
43
18
|
}
|
|
44
19
|
}
|
|
45
20
|
else
|
|
46
|
-
|
|
21
|
+
actionInfo.allActions.forEach((a) => {
|
|
47
22
|
addAction(a);
|
|
48
23
|
});
|
|
49
24
|
}
|
|
50
|
-
exports.registerActionsOnServer = registerActionsOnServer;
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var context_1 = require("../src/context");
|
|
6
|
-
var data_api_1 = require("../src/data-api");
|
|
7
|
-
function registerEntitiesOnServer(area, entities) {
|
|
1
|
+
import { getEntityKey } from "../src/remult3";
|
|
2
|
+
import { allEntities } from "../src/context";
|
|
3
|
+
import { DataApi } from "../src/data-api";
|
|
4
|
+
export function registerEntitiesOnServer(area, entities) {
|
|
8
5
|
if (!entities)
|
|
9
|
-
entities =
|
|
6
|
+
entities = allEntities;
|
|
10
7
|
//add Api Entries
|
|
11
|
-
entities.forEach(
|
|
12
|
-
|
|
8
|
+
entities.forEach(e => {
|
|
9
|
+
let key = getEntityKey(e);
|
|
13
10
|
if (key != undefined)
|
|
14
|
-
area.add(key,
|
|
15
|
-
return new
|
|
11
|
+
area.add(key, c => {
|
|
12
|
+
return new DataApi(c.repo(e), c);
|
|
16
13
|
});
|
|
17
14
|
});
|
|
18
15
|
}
|
|
19
|
-
exports.registerEntitiesOnServer = registerEntitiesOnServer;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,72 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var dotenv_1 = require("dotenv");
|
|
10
|
-
var postgres_1 = require("../../postgres");
|
|
11
|
-
var db_tests_setup_1 = require("../shared-tests/db-tests-setup");
|
|
12
|
-
dotenv_1.config();
|
|
1
|
+
import { Remult } from "../context";
|
|
2
|
+
import { KnexDataProvider, KnexSchemaBuilder } from '../../remult-knex';
|
|
3
|
+
import * as Knex from 'knex';
|
|
4
|
+
import { MongoClient } from 'mongodb';
|
|
5
|
+
import { config } from 'dotenv';
|
|
6
|
+
import { createPostgresConnection, PostgresSchemaBuilder } from "../../postgres";
|
|
7
|
+
import { addDatabaseToTest, itWithFocus, testAll } from "../shared-tests/db-tests-setup";
|
|
8
|
+
config();
|
|
13
9
|
function testKnexSqlImpl(knex, name) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var repo, sb, _a, _b, _c;
|
|
29
|
-
return tslib_1.__generator(this, function (_d) {
|
|
30
|
-
switch (_d.label) {
|
|
31
|
-
case 0:
|
|
32
|
-
repo = remult.repo(entity);
|
|
33
|
-
sb = new remult_knex_1.KnexSchemaBuilder(knex);
|
|
34
|
-
_b = (_a = knex.schema).dropTableIfExists;
|
|
35
|
-
return [4 /*yield*/, repo.metadata.getDbName()];
|
|
36
|
-
case 1: return [4 /*yield*/, _b.apply(_a, [_d.sent()])];
|
|
37
|
-
case 2:
|
|
38
|
-
_d.sent();
|
|
39
|
-
return [4 /*yield*/, sb.createIfNotExist(repo.metadata)];
|
|
40
|
-
case 3:
|
|
41
|
-
_d.sent();
|
|
42
|
-
return [4 /*yield*/, sb.verifyAllColumns(repo.metadata)];
|
|
43
|
-
case 4:
|
|
44
|
-
_d.sent();
|
|
45
|
-
_c = knex;
|
|
46
|
-
return [4 /*yield*/, repo.metadata.getDbName()];
|
|
47
|
-
case 5: return [4 /*yield*/, _c.apply(void 0, [_d.sent()]).delete()];
|
|
48
|
-
case 6:
|
|
49
|
-
_d.sent();
|
|
50
|
-
return [2 /*return*/, repo];
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}); }
|
|
54
|
-
})];
|
|
55
|
-
case 1:
|
|
56
|
-
_a.sent();
|
|
57
|
-
return [2 /*return*/];
|
|
10
|
+
return (key, what, focus = false) => {
|
|
11
|
+
itWithFocus(key + " " + name + " - knex", async () => {
|
|
12
|
+
let db = new KnexDataProvider(knex);
|
|
13
|
+
let remult = new Remult(db);
|
|
14
|
+
await what({
|
|
15
|
+
db, remult,
|
|
16
|
+
createEntity: async (entity) => {
|
|
17
|
+
let repo = remult.repo(entity);
|
|
18
|
+
let sb = new KnexSchemaBuilder(knex);
|
|
19
|
+
await knex.schema.dropTableIfExists(await repo.metadata.getDbName());
|
|
20
|
+
await sb.createIfNotExist(repo.metadata);
|
|
21
|
+
await sb.verifyAllColumns(repo.metadata);
|
|
22
|
+
await knex(await repo.metadata.getDbName()).delete();
|
|
23
|
+
return repo;
|
|
58
24
|
}
|
|
59
25
|
});
|
|
60
|
-
}
|
|
26
|
+
}, focus);
|
|
61
27
|
};
|
|
62
28
|
}
|
|
63
|
-
|
|
29
|
+
export const testKnexPGSqlImpl = testKnexSqlImpl(Knex.default({
|
|
64
30
|
client: 'pg',
|
|
65
31
|
connection: process.env.DATABASE_URL,
|
|
66
32
|
}), "postgres");
|
|
67
|
-
|
|
33
|
+
addDatabaseToTest(testKnexPGSqlImpl);
|
|
68
34
|
if (process.env['TESTS_SQL_SERVER'])
|
|
69
|
-
|
|
35
|
+
addDatabaseToTest(testKnexSqlImpl(Knex.default({
|
|
70
36
|
client: 'mssql',
|
|
71
37
|
connection: {
|
|
72
38
|
server: '127.0.0.1',
|
|
@@ -81,151 +47,67 @@ if (process.env['TESTS_SQL_SERVER'])
|
|
|
81
47
|
} //,debug: true
|
|
82
48
|
}), "sql server"));
|
|
83
49
|
if (true)
|
|
84
|
-
|
|
50
|
+
addDatabaseToTest(testKnexSqlImpl(Knex.default({
|
|
85
51
|
client: 'better-sqlite3',
|
|
86
52
|
connection: {
|
|
87
53
|
filename: ":memory:"
|
|
88
54
|
},
|
|
89
55
|
}), "sqlite3"));
|
|
90
|
-
|
|
56
|
+
let pg = createPostgresConnection({
|
|
91
57
|
autoCreateTables: false
|
|
92
58
|
});
|
|
93
|
-
function testPostgresImplementation(key, what, focus) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
createEntity: function (entity) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
108
|
-
var repo, sb, _a, _b, _c, _d, _e, _f;
|
|
109
|
-
return tslib_1.__generator(this, function (_g) {
|
|
110
|
-
switch (_g.label) {
|
|
111
|
-
case 0:
|
|
112
|
-
repo = remult.repo(entity);
|
|
113
|
-
sb = new postgres_1.PostgresSchemaBuilder(db);
|
|
114
|
-
_b = (_a = db).execute;
|
|
115
|
-
_c = "drop table if exists ";
|
|
116
|
-
return [4 /*yield*/, repo.metadata.getDbName()];
|
|
117
|
-
case 1: return [4 /*yield*/, _b.apply(_a, [_c + (_g.sent())])];
|
|
118
|
-
case 2:
|
|
119
|
-
_g.sent();
|
|
120
|
-
return [4 /*yield*/, sb.createIfNotExist(repo.metadata)];
|
|
121
|
-
case 3:
|
|
122
|
-
_g.sent();
|
|
123
|
-
return [4 /*yield*/, sb.verifyAllColumns(repo.metadata)];
|
|
124
|
-
case 4:
|
|
125
|
-
_g.sent();
|
|
126
|
-
_e = (_d = db).execute;
|
|
127
|
-
_f = "delete from ";
|
|
128
|
-
return [4 /*yield*/, repo.metadata.getDbName()];
|
|
129
|
-
case 5: return [4 /*yield*/, _e.apply(_d, [_f + (_g.sent())])];
|
|
130
|
-
case 6:
|
|
131
|
-
_g.sent();
|
|
132
|
-
return [2 /*return*/, repo];
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}); }
|
|
136
|
-
})];
|
|
137
|
-
case 2:
|
|
138
|
-
_a.sent();
|
|
139
|
-
return [2 /*return*/];
|
|
59
|
+
export function testPostgresImplementation(key, what, focus = false) {
|
|
60
|
+
itWithFocus(key + " - postgres", async () => {
|
|
61
|
+
let db = await pg;
|
|
62
|
+
let remult = new Remult(db);
|
|
63
|
+
await what({
|
|
64
|
+
db, remult,
|
|
65
|
+
createEntity: async (entity) => {
|
|
66
|
+
let repo = remult.repo(entity);
|
|
67
|
+
let sb = new PostgresSchemaBuilder(db);
|
|
68
|
+
await db.execute("drop table if exists " + await repo.metadata.getDbName());
|
|
69
|
+
await sb.createIfNotExist(repo.metadata);
|
|
70
|
+
await sb.verifyAllColumns(repo.metadata);
|
|
71
|
+
await db.execute("delete from " + await repo.metadata.getDbName());
|
|
72
|
+
return repo;
|
|
140
73
|
}
|
|
141
74
|
});
|
|
142
|
-
}
|
|
75
|
+
}, focus);
|
|
143
76
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return tslib_1.__generator(this, function (_b) {
|
|
153
|
-
switch (_b.label) {
|
|
154
|
-
case 0: return [4 /*yield*/, createEntity(remult_3_entities_1.Categories)];
|
|
155
|
-
case 1:
|
|
156
|
-
x = _b.sent();
|
|
157
|
-
return [4 /*yield*/, db.transaction(function (db) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
158
|
-
var remult, _a;
|
|
159
|
-
return tslib_1.__generator(this, function (_b) {
|
|
160
|
-
switch (_b.label) {
|
|
161
|
-
case 0:
|
|
162
|
-
remult = new context_1.Remult(db);
|
|
163
|
-
_a = expect;
|
|
164
|
-
return [4 /*yield*/, remult.repo(remult_3_entities_1.Categories).count()];
|
|
165
|
-
case 1:
|
|
166
|
-
_a.apply(void 0, [_b.sent()]).toBe(0);
|
|
167
|
-
return [2 /*return*/];
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
}); })];
|
|
171
|
-
case 2:
|
|
172
|
-
_b.sent();
|
|
173
|
-
return [2 /*return*/];
|
|
174
|
-
}
|
|
175
|
-
});
|
|
77
|
+
addDatabaseToTest(testPostgresImplementation);
|
|
78
|
+
import { Categories } from "../tests/remult-3-entities";
|
|
79
|
+
import { MongoDataProvider } from "../../remult-mongo";
|
|
80
|
+
testAll("transactions", async ({ db, createEntity }) => {
|
|
81
|
+
let x = await createEntity(Categories);
|
|
82
|
+
await db.transaction(async (db) => {
|
|
83
|
+
let remult = new Remult(db);
|
|
84
|
+
expect(await remult.repo(Categories).count()).toBe(0);
|
|
176
85
|
});
|
|
177
86
|
});
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
87
|
+
let client = new MongoClient("mongodb://localhost:27017/local");
|
|
88
|
+
let done;
|
|
89
|
+
let mongoDbPromise = client.connect().then(c => {
|
|
181
90
|
done = c;
|
|
182
91
|
return c.db("test");
|
|
183
92
|
});
|
|
184
|
-
afterAll(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
case 0: return [4 /*yield*/, mongoDbPromise];
|
|
200
|
-
case 1:
|
|
201
|
-
mongoDb = _a.sent();
|
|
202
|
-
db = new remult_mongo_1.MongoDataProvider(mongoDb, client);
|
|
203
|
-
remult = new context_1.Remult(db);
|
|
204
|
-
return [4 /*yield*/, what({
|
|
205
|
-
db: db, remult: remult,
|
|
206
|
-
createEntity: function (entity) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
207
|
-
var repo, _a, _b;
|
|
208
|
-
return tslib_1.__generator(this, function (_c) {
|
|
209
|
-
switch (_c.label) {
|
|
210
|
-
case 0:
|
|
211
|
-
repo = remult.repo(entity);
|
|
212
|
-
_b = (_a = mongoDb).collection;
|
|
213
|
-
return [4 /*yield*/, repo.metadata.getDbName()];
|
|
214
|
-
case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent()]).deleteMany({})];
|
|
215
|
-
case 2:
|
|
216
|
-
_c.sent();
|
|
217
|
-
return [2 /*return*/, repo];
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
}); }
|
|
221
|
-
})];
|
|
222
|
-
case 2:
|
|
223
|
-
_a.sent();
|
|
224
|
-
return [2 /*return*/];
|
|
93
|
+
afterAll(async () => {
|
|
94
|
+
if (done)
|
|
95
|
+
done.close();
|
|
96
|
+
});
|
|
97
|
+
export function testMongo(key, what, focus = false) {
|
|
98
|
+
itWithFocus(key + " - mongo", async () => {
|
|
99
|
+
let mongoDb = await mongoDbPromise;
|
|
100
|
+
let db = new MongoDataProvider(mongoDb, client);
|
|
101
|
+
let remult = new Remult(db);
|
|
102
|
+
await what({
|
|
103
|
+
db, remult,
|
|
104
|
+
createEntity: async (entity) => {
|
|
105
|
+
let repo = remult.repo(entity);
|
|
106
|
+
await mongoDb.collection(await repo.metadata.getDbName()).deleteMany({});
|
|
107
|
+
return repo;
|
|
225
108
|
}
|
|
226
109
|
});
|
|
227
|
-
}
|
|
110
|
+
}, focus);
|
|
228
111
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
require("../shared-tests");
|
|
112
|
+
addDatabaseToTest(testMongo);
|
|
113
|
+
import '../shared-tests';
|
|
@@ -1,118 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return tslib_1.__generator(this, function (_c) {
|
|
15
|
-
switch (_c.label) {
|
|
16
|
-
case 0: return [4 /*yield*/, entityWithValidations_1.entityWithValidations.create4RowsInDp(createEntity)];
|
|
17
|
-
case 1:
|
|
18
|
-
s = _c.sent();
|
|
19
|
-
_b = expect;
|
|
20
|
-
return [4 /*yield*/, s.find({
|
|
21
|
-
where: __1.SqlDatabase.customFilter(function (build) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
22
|
-
return tslib_1.__generator(this, function (_a) {
|
|
23
|
-
build.sql = s.metadata.fields.myId.options.dbName + ' in (1,3)';
|
|
24
|
-
return [2 /*return*/];
|
|
25
|
-
});
|
|
26
|
-
}); })
|
|
27
|
-
})];
|
|
28
|
-
case 2:
|
|
29
|
-
_b.apply(void 0, [(_c.sent()).length]).toBe(2);
|
|
30
|
-
return [2 /*return*/];
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
});
|
|
1
|
+
import { SqlDatabase } from "../..";
|
|
2
|
+
import { KnexDataProvider } from '../../remult-knex';
|
|
3
|
+
import { config } from 'dotenv';
|
|
4
|
+
import { testKnexPGSqlImpl, testPostgresImplementation } from "./backend-database-test-setup.backend-spec";
|
|
5
|
+
import { entityWithValidations } from "../shared-tests/entityWithValidations";
|
|
6
|
+
config();
|
|
7
|
+
testPostgresImplementation("sql filter", async ({ createEntity }) => {
|
|
8
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
9
|
+
expect((await s.find({
|
|
10
|
+
where: SqlDatabase.customFilter(async (build) => {
|
|
11
|
+
build.sql = s.metadata.fields.myId.options.dbName + ' in (1,3)';
|
|
12
|
+
})
|
|
13
|
+
})).length).toBe(2);
|
|
34
14
|
}, false);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return tslib_1.__generator(this, function (_a) {
|
|
50
|
-
build.sql = s.metadata.fields.myId.options.dbName + ' in (1,3)';
|
|
51
|
-
return [2 /*return*/];
|
|
52
|
-
});
|
|
53
|
-
}); }),
|
|
54
|
-
{
|
|
55
|
-
myId: 2
|
|
56
|
-
}
|
|
57
|
-
]
|
|
58
|
-
}
|
|
59
|
-
})];
|
|
60
|
-
case 2:
|
|
61
|
-
_b.apply(void 0, [(_c.sent()).length]).toBe(3);
|
|
62
|
-
return [2 /*return*/];
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
});
|
|
15
|
+
testPostgresImplementation("sql filter2", async ({ createEntity }) => {
|
|
16
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
17
|
+
expect((await s.find({
|
|
18
|
+
where: {
|
|
19
|
+
$or: [
|
|
20
|
+
SqlDatabase.customFilter(async (build) => {
|
|
21
|
+
build.sql = s.metadata.fields.myId.options.dbName + ' in (1,3)';
|
|
22
|
+
}),
|
|
23
|
+
{
|
|
24
|
+
myId: 2
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
})).length).toBe(3);
|
|
66
29
|
}, false);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
case 1:
|
|
75
|
-
s = _c.sent();
|
|
76
|
-
_b = expect;
|
|
77
|
-
return [4 /*yield*/, s.find({
|
|
78
|
-
where: remult_knex_1.KnexDataProvider.customFilter(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
79
|
-
return tslib_1.__generator(this, function (_a) {
|
|
80
|
-
return [2 /*return*/, function (build) { return build.whereIn(s.metadata.fields.myId.options.dbName, [1, 3]); }];
|
|
81
|
-
});
|
|
82
|
-
}); })
|
|
83
|
-
})];
|
|
84
|
-
case 2:
|
|
85
|
-
_b.apply(void 0, [(_c.sent()).length]).toBe(2);
|
|
86
|
-
return [2 /*return*/];
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
});
|
|
30
|
+
testKnexPGSqlImpl("knex filter", async ({ createEntity }) => {
|
|
31
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
32
|
+
expect((await s.find({
|
|
33
|
+
where: KnexDataProvider.customFilter(async () => {
|
|
34
|
+
return build => build.whereIn(s.metadata.fields.myId.options.dbName, [1, 3]);
|
|
35
|
+
})
|
|
36
|
+
})).length).toBe(2);
|
|
90
37
|
}, false);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
where: {
|
|
103
|
-
$or: [remult_knex_1.KnexDataProvider.customFilter(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
104
|
-
return tslib_1.__generator(this, function (_a) {
|
|
105
|
-
return [2 /*return*/, function (build) { return build.whereIn(s.metadata.fields.myId.options.dbName, [1, 3]); }];
|
|
106
|
-
});
|
|
107
|
-
}); }), {
|
|
108
|
-
myId: 4
|
|
109
|
-
}]
|
|
110
|
-
}
|
|
111
|
-
})];
|
|
112
|
-
case 2:
|
|
113
|
-
_b.apply(void 0, [(_c.sent()).length]).toBe(3);
|
|
114
|
-
return [2 /*return*/];
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
});
|
|
38
|
+
testKnexPGSqlImpl("knex filter2", async ({ createEntity }) => {
|
|
39
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
40
|
+
expect((await s.find({
|
|
41
|
+
where: {
|
|
42
|
+
$or: [KnexDataProvider.customFilter(async () => {
|
|
43
|
+
return build => build.whereIn(s.metadata.fields.myId.options.dbName, [1, 3]);
|
|
44
|
+
}), {
|
|
45
|
+
myId: 4
|
|
46
|
+
}]
|
|
47
|
+
}
|
|
48
|
+
})).length).toBe(3);
|
|
118
49
|
}, false);
|
package/src/column-interfaces.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.valueOrExpressionToValue = void 0;
|
|
4
|
-
function valueOrExpressionToValue(f) {
|
|
1
|
+
export function valueOrExpressionToValue(f) {
|
|
5
2
|
if (typeof f === 'function') {
|
|
6
|
-
|
|
3
|
+
let x = f;
|
|
7
4
|
return x();
|
|
8
5
|
}
|
|
9
6
|
return f;
|
|
10
7
|
}
|
|
11
|
-
exports.valueOrExpressionToValue = valueOrExpressionToValue;
|