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
package/remult-mongo.js
CHANGED
|
@@ -1,444 +1,211 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var _1 = require(".");
|
|
6
|
-
var filter_consumer_bridge_to_sql_request_1 = require("./src/filter/filter-consumer-bridge-to-sql-request");
|
|
7
|
-
var MongoDataProvider = /** @class */ (function () {
|
|
8
|
-
function MongoDataProvider(db, client) {
|
|
1
|
+
import { CompoundIdField, Filter } from '.';
|
|
2
|
+
import { getDbNameProvider } from './src/filter/filter-consumer-bridge-to-sql-request';
|
|
3
|
+
export class MongoDataProvider {
|
|
4
|
+
constructor(db, client) {
|
|
9
5
|
this.db = db;
|
|
10
6
|
this.client = client;
|
|
11
7
|
}
|
|
12
|
-
|
|
8
|
+
getEntityDataProvider(entity) {
|
|
13
9
|
return new MongoEntityDataProvider(this.db, entity);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
_a.sent();
|
|
30
|
-
return [4 /*yield*/, session.commitTransaction()];
|
|
31
|
-
case 4:
|
|
32
|
-
_a.sent();
|
|
33
|
-
return [3 /*break*/, 7];
|
|
34
|
-
case 5:
|
|
35
|
-
err_1 = _a.sent();
|
|
36
|
-
return [4 /*yield*/, session.abortTransaction()];
|
|
37
|
-
case 6:
|
|
38
|
-
_a.sent();
|
|
39
|
-
throw err_1;
|
|
40
|
-
case 7: return [2 /*return*/];
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
return MongoDataProvider;
|
|
46
|
-
}());
|
|
47
|
-
exports.MongoDataProvider = MongoDataProvider;
|
|
48
|
-
var NULL = { $null: "$null" };
|
|
10
|
+
}
|
|
11
|
+
async transaction(action) {
|
|
12
|
+
let session = await this.client.startSession();
|
|
13
|
+
session.startTransaction();
|
|
14
|
+
try {
|
|
15
|
+
await action(new MongoDataProvider(this.db, undefined));
|
|
16
|
+
await session.commitTransaction();
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
await session.abortTransaction();
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const NULL = { $null: "$null" };
|
|
49
25
|
function isNull(x) {
|
|
50
|
-
return
|
|
26
|
+
return x?.$null === NULL.$null;
|
|
51
27
|
}
|
|
52
|
-
|
|
53
|
-
|
|
28
|
+
class MongoEntityDataProvider {
|
|
29
|
+
constructor(db, entity) {
|
|
54
30
|
this.db = db;
|
|
55
31
|
this.entity = entity;
|
|
56
32
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
result[col.key] = col.valueConverter.fromDb(row[nameProvider.nameOf(col)]);
|
|
64
|
-
if (isNull(result[col.key]))
|
|
65
|
-
result[col.key] = null;
|
|
66
|
-
}
|
|
33
|
+
translateFromJson(row, nameProvider) {
|
|
34
|
+
let result = {};
|
|
35
|
+
for (const col of this.entity.fields) {
|
|
36
|
+
result[col.key] = col.valueConverter.fromDb(row[nameProvider.nameOf(col)]);
|
|
37
|
+
if (isNull(result[col.key]))
|
|
38
|
+
result[col.key] = null;
|
|
67
39
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
translateToJson(row, nameProvider) {
|
|
43
|
+
let result = {};
|
|
44
|
+
for (const col of this.entity.fields) {
|
|
45
|
+
let val = col.valueConverter.toDb(row[col.key]);
|
|
46
|
+
if (val === null)
|
|
47
|
+
val = NULL;
|
|
48
|
+
result[nameProvider.nameOf(col)] = val;
|
|
74
49
|
}
|
|
75
50
|
return result;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
51
|
+
}
|
|
52
|
+
async count(where) {
|
|
53
|
+
const { collection, e } = await this.collection();
|
|
54
|
+
let x = new FilterConsumerBridgeToMongo(e);
|
|
55
|
+
where.__applyToConsumer(x);
|
|
56
|
+
let w = await x.resolveWhere();
|
|
57
|
+
return await collection.countDocuments(w);
|
|
58
|
+
}
|
|
59
|
+
async find(options) {
|
|
60
|
+
let { collection, e } = await this.collection();
|
|
61
|
+
let x = new FilterConsumerBridgeToMongo(e);
|
|
62
|
+
if (options?.where)
|
|
63
|
+
options.where.__applyToConsumer(x);
|
|
64
|
+
let where = await x.resolveWhere();
|
|
65
|
+
let op = {};
|
|
66
|
+
if (options.limit) {
|
|
67
|
+
op.limit = options.limit;
|
|
68
|
+
if (options.page) {
|
|
69
|
+
op.skip = (options.page - 1) * options.limit;
|
|
87
70
|
}
|
|
88
71
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
72
|
+
if (options.orderBy) {
|
|
73
|
+
op.sort = {};
|
|
74
|
+
for (const s of options.orderBy.Segments) {
|
|
75
|
+
op.sort[e.nameOf(s.field)] = s.isDescending ? -1 : 1;
|
|
93
76
|
}
|
|
94
|
-
finally { if (e_2) throw e_2.error; }
|
|
95
77
|
}
|
|
96
|
-
return
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
};
|
|
117
|
-
MongoEntityDataProvider.prototype.find = function (options) {
|
|
118
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
119
|
-
var _a, collection, e, x, where, op, _b, _c, s, _d, _e;
|
|
120
|
-
var e_3, _f;
|
|
121
|
-
var _this = this;
|
|
122
|
-
return tslib_1.__generator(this, function (_g) {
|
|
123
|
-
switch (_g.label) {
|
|
124
|
-
case 0: return [4 /*yield*/, this.collection()];
|
|
125
|
-
case 1:
|
|
126
|
-
_a = _g.sent(), collection = _a.collection, e = _a.e;
|
|
127
|
-
x = new FilterConsumerBridgeToMongo(e);
|
|
128
|
-
if (options === null || options === void 0 ? void 0 : options.where)
|
|
129
|
-
options.where.__applyToConsumer(x);
|
|
130
|
-
return [4 /*yield*/, x.resolveWhere()];
|
|
131
|
-
case 2:
|
|
132
|
-
where = _g.sent();
|
|
133
|
-
op = {};
|
|
134
|
-
if (options.limit) {
|
|
135
|
-
op.limit = options.limit;
|
|
136
|
-
if (options.page) {
|
|
137
|
-
op.skip = (options.page - 1) * options.limit;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
if (options.orderBy) {
|
|
141
|
-
op.sort = {};
|
|
142
|
-
try {
|
|
143
|
-
for (_b = tslib_1.__values(options.orderBy.Segments), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
144
|
-
s = _c.value;
|
|
145
|
-
op.sort[e.nameOf(s.field)] = s.isDescending ? -1 : 1;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
149
|
-
finally {
|
|
150
|
-
try {
|
|
151
|
-
if (_c && !_c.done && (_f = _b.return)) _f.call(_b);
|
|
152
|
-
}
|
|
153
|
-
finally { if (e_3) throw e_3.error; }
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
_e = (_d = Promise).all;
|
|
157
|
-
return [4 /*yield*/, collection.find(where, op).map(function (x) { return _this.translateFromJson(x, e); }).toArray()];
|
|
158
|
-
case 3: return [4 /*yield*/, _e.apply(_d, [_g.sent()])];
|
|
159
|
-
case 4: return [2 /*return*/, _g.sent()];
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
};
|
|
164
|
-
MongoEntityDataProvider.prototype.update = function (id, data) {
|
|
165
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
166
|
-
var _a, collection, e, f, resultFilter, _b, _c, x, newR, keys, _d, _e, f_1, r, _f, _g;
|
|
167
|
-
var e_4, _h, e_5, _j;
|
|
168
|
-
return tslib_1.__generator(this, function (_k) {
|
|
169
|
-
switch (_k.label) {
|
|
170
|
-
case 0: return [4 /*yield*/, this.collection()];
|
|
171
|
-
case 1:
|
|
172
|
-
_a = _k.sent(), collection = _a.collection, e = _a.e;
|
|
173
|
-
f = new FilterConsumerBridgeToMongo(e);
|
|
174
|
-
_1.Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)).__applyToConsumer(f);
|
|
175
|
-
resultFilter = this.entity.idMetadata.getIdFilter(id);
|
|
176
|
-
if (data.id != undefined)
|
|
177
|
-
resultFilter = this.entity.idMetadata.getIdFilter(data.id);
|
|
178
|
-
try {
|
|
179
|
-
for (_b = tslib_1.__values(this.entity.fields), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
180
|
-
x = _c.value;
|
|
181
|
-
if (x instanceof _1.CompoundIdField) {
|
|
182
|
-
resultFilter = x.resultIdFilter(id, data);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
187
|
-
finally {
|
|
188
|
-
try {
|
|
189
|
-
if (_c && !_c.done && (_h = _b.return)) _h.call(_b);
|
|
190
|
-
}
|
|
191
|
-
finally { if (e_4) throw e_4.error; }
|
|
192
|
-
}
|
|
193
|
-
newR = {};
|
|
194
|
-
keys = Object.keys(data);
|
|
195
|
-
try {
|
|
196
|
-
for (_d = tslib_1.__values(this.entity.fields), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
197
|
-
f_1 = _e.value;
|
|
198
|
-
if (!f_1.dbReadOnly && !f_1.isServerExpression) {
|
|
199
|
-
if (keys.includes(f_1.key)) {
|
|
200
|
-
newR[f_1.key] = f_1.valueConverter.toJson(data[f_1.key]);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
206
|
-
finally {
|
|
207
|
-
try {
|
|
208
|
-
if (_e && !_e.done && (_j = _d.return)) _j.call(_d);
|
|
209
|
-
}
|
|
210
|
-
finally { if (e_5) throw e_5.error; }
|
|
211
|
-
}
|
|
212
|
-
_g = (_f = collection).updateOne;
|
|
213
|
-
return [4 /*yield*/, f.resolveWhere()];
|
|
214
|
-
case 2: return [4 /*yield*/, _g.apply(_f, [_k.sent(), {
|
|
215
|
-
$set: newR
|
|
216
|
-
}])];
|
|
217
|
-
case 3:
|
|
218
|
-
r = _k.sent();
|
|
219
|
-
return [2 /*return*/, this.find({ where: _1.Filter.fromEntityFilter(this.entity, resultFilter) }).then(function (y) { return y[0]; })];
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
};
|
|
224
|
-
MongoEntityDataProvider.prototype.delete = function (id) {
|
|
225
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
226
|
-
var _a, e, collection, f, _b, _c;
|
|
227
|
-
return tslib_1.__generator(this, function (_d) {
|
|
228
|
-
switch (_d.label) {
|
|
229
|
-
case 0: return [4 /*yield*/, this.collection()];
|
|
230
|
-
case 1:
|
|
231
|
-
_a = _d.sent(), e = _a.e, collection = _a.collection;
|
|
232
|
-
f = new FilterConsumerBridgeToMongo(e);
|
|
233
|
-
_1.Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)).__applyToConsumer(f);
|
|
234
|
-
_c = (_b = collection).deleteOne;
|
|
235
|
-
return [4 /*yield*/, f.resolveWhere()];
|
|
236
|
-
case 2:
|
|
237
|
-
_c.apply(_b, [_d.sent()]);
|
|
238
|
-
return [2 /*return*/];
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
};
|
|
243
|
-
MongoEntityDataProvider.prototype.insert = function (data) {
|
|
244
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
245
|
-
var _a, collection, e, r, _b, _c, _d;
|
|
246
|
-
return tslib_1.__generator(this, function (_e) {
|
|
247
|
-
switch (_e.label) {
|
|
248
|
-
case 0: return [4 /*yield*/, this.collection()];
|
|
249
|
-
case 1:
|
|
250
|
-
_a = _e.sent(), collection = _a.collection, e = _a.e;
|
|
251
|
-
_c = (_b = collection).insertOne;
|
|
252
|
-
return [4 /*yield*/, this.translateToJson(data, e)];
|
|
253
|
-
case 2: return [4 /*yield*/, _c.apply(_b, [_e.sent()])];
|
|
254
|
-
case 3:
|
|
255
|
-
r = _e.sent();
|
|
256
|
-
_d = this.translateFromJson;
|
|
257
|
-
return [4 /*yield*/, collection.findOne({ _id: r.insertedId })];
|
|
258
|
-
case 4: return [4 /*yield*/, _d.apply(this, [_e.sent(), e])];
|
|
259
|
-
case 5: return [2 /*return*/, _e.sent()];
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
});
|
|
263
|
-
};
|
|
264
|
-
MongoEntityDataProvider.prototype.collection = function () {
|
|
265
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
266
|
-
var e, collection;
|
|
267
|
-
return tslib_1.__generator(this, function (_a) {
|
|
268
|
-
switch (_a.label) {
|
|
269
|
-
case 0: return [4 /*yield*/, filter_consumer_bridge_to_sql_request_1.getDbNameProvider(this.entity)];
|
|
270
|
-
case 1:
|
|
271
|
-
e = _a.sent();
|
|
272
|
-
collection = this.db.collection(e.entityName);
|
|
273
|
-
return [2 /*return*/, { e: e, collection: collection }];
|
|
78
|
+
return await Promise.all(await collection.find(where, op).map(x => this.translateFromJson(x, e)).toArray());
|
|
79
|
+
}
|
|
80
|
+
async update(id, data) {
|
|
81
|
+
let { collection, e } = await this.collection();
|
|
82
|
+
let f = new FilterConsumerBridgeToMongo(e);
|
|
83
|
+
Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)).__applyToConsumer(f);
|
|
84
|
+
let resultFilter = this.entity.idMetadata.getIdFilter(id);
|
|
85
|
+
if (data.id != undefined)
|
|
86
|
+
resultFilter = this.entity.idMetadata.getIdFilter(data.id);
|
|
87
|
+
for (const x of this.entity.fields) {
|
|
88
|
+
if (x instanceof CompoundIdField) {
|
|
89
|
+
resultFilter = x.resultIdFilter(id, data);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
let newR = {};
|
|
93
|
+
let keys = Object.keys(data);
|
|
94
|
+
for (const f of this.entity.fields) {
|
|
95
|
+
if (!f.dbReadOnly && !f.isServerExpression) {
|
|
96
|
+
if (keys.includes(f.key)) {
|
|
97
|
+
newR[f.key] = f.valueConverter.toJson(data[f.key]);
|
|
274
98
|
}
|
|
275
|
-
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
let r = await collection.updateOne(await f.resolveWhere(), {
|
|
102
|
+
$set: newR
|
|
276
103
|
});
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
104
|
+
return this.find({ where: Filter.fromEntityFilter(this.entity, resultFilter) }).then(y => y[0]);
|
|
105
|
+
}
|
|
106
|
+
async delete(id) {
|
|
107
|
+
const { e, collection } = await this.collection();
|
|
108
|
+
let f = new FilterConsumerBridgeToMongo(e);
|
|
109
|
+
Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)).__applyToConsumer(f);
|
|
110
|
+
collection.deleteOne(await f.resolveWhere());
|
|
111
|
+
}
|
|
112
|
+
async insert(data) {
|
|
113
|
+
let { collection, e } = await this.collection();
|
|
114
|
+
let r = await collection.insertOne(await this.translateToJson(data, e));
|
|
115
|
+
return await this.translateFromJson(await collection.findOne({ _id: r.insertedId }), e);
|
|
116
|
+
}
|
|
117
|
+
async collection() {
|
|
118
|
+
const e = await getDbNameProvider(this.entity);
|
|
119
|
+
const collection = this.db.collection(e.entityName);
|
|
120
|
+
return { e, collection };
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
class FilterConsumerBridgeToMongo {
|
|
124
|
+
constructor(nameProvider) {
|
|
282
125
|
this.nameProvider = nameProvider;
|
|
283
126
|
this._addWhere = true;
|
|
284
127
|
this.promises = [];
|
|
285
128
|
this.result = [];
|
|
286
129
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
_b.label = 2;
|
|
302
|
-
case 2:
|
|
303
|
-
if (!!p_1_1.done) return [3 /*break*/, 5];
|
|
304
|
-
pr = p_1_1.value;
|
|
305
|
-
return [4 /*yield*/, pr];
|
|
306
|
-
case 3:
|
|
307
|
-
_b.sent();
|
|
308
|
-
_b.label = 4;
|
|
309
|
-
case 4:
|
|
310
|
-
p_1_1 = p_1.next();
|
|
311
|
-
return [3 /*break*/, 2];
|
|
312
|
-
case 5: return [3 /*break*/, 8];
|
|
313
|
-
case 6:
|
|
314
|
-
e_6_1 = _b.sent();
|
|
315
|
-
e_6 = { error: e_6_1 };
|
|
316
|
-
return [3 /*break*/, 8];
|
|
317
|
-
case 7:
|
|
318
|
-
try {
|
|
319
|
-
if (p_1_1 && !p_1_1.done && (_a = p_1.return)) _a.call(p_1);
|
|
320
|
-
}
|
|
321
|
-
finally { if (e_6) throw e_6.error; }
|
|
322
|
-
return [7 /*endfinally*/];
|
|
323
|
-
case 8: return [3 /*break*/, 0];
|
|
324
|
-
case 9:
|
|
325
|
-
if (this.result.length > 0)
|
|
326
|
-
return [2 /*return*/, { $and: this.result.map(function (x) { return x(); }) }];
|
|
327
|
-
else
|
|
328
|
-
return [2 /*return*/, {}];
|
|
329
|
-
return [2 /*return*/];
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
});
|
|
333
|
-
};
|
|
334
|
-
FilterConsumerBridgeToMongo.prototype.custom = function (key, customItem) {
|
|
130
|
+
async resolveWhere() {
|
|
131
|
+
while (this.promises.length > 0) {
|
|
132
|
+
let p = this.promises;
|
|
133
|
+
this.promises = [];
|
|
134
|
+
for (const pr of p) {
|
|
135
|
+
await pr;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (this.result.length > 0)
|
|
139
|
+
return { $and: this.result.map(x => x()) };
|
|
140
|
+
else
|
|
141
|
+
return {};
|
|
142
|
+
}
|
|
143
|
+
custom(key, customItem) {
|
|
335
144
|
throw new Error("Custom filter should be translated before it gets here");
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
_c.label = 1;
|
|
348
|
-
case 1:
|
|
349
|
-
_c.trys.push([1, 6, 7, 8]);
|
|
350
|
-
orElements_1 = tslib_1.__values(orElements), orElements_1_1 = orElements_1.next();
|
|
351
|
-
_c.label = 2;
|
|
352
|
-
case 2:
|
|
353
|
-
if (!!orElements_1_1.done) return [3 /*break*/, 5];
|
|
354
|
-
element = orElements_1_1.value;
|
|
355
|
-
f = new FilterConsumerBridgeToMongo(this.nameProvider);
|
|
356
|
-
f._addWhere = false;
|
|
357
|
-
element.__applyToConsumer(f);
|
|
358
|
-
return [4 /*yield*/, f.resolveWhere()];
|
|
359
|
-
case 3:
|
|
360
|
-
where = _c.sent();
|
|
361
|
-
if (((_b = where === null || where === void 0 ? void 0 : where.$and) === null || _b === void 0 ? void 0 : _b.length) > 0) {
|
|
362
|
-
result.push(where);
|
|
363
|
-
}
|
|
364
|
-
else
|
|
365
|
-
return [2 /*return*/]; //since empty or is all rows;
|
|
366
|
-
_c.label = 4;
|
|
367
|
-
case 4:
|
|
368
|
-
orElements_1_1 = orElements_1.next();
|
|
369
|
-
return [3 /*break*/, 2];
|
|
370
|
-
case 5: return [3 /*break*/, 8];
|
|
371
|
-
case 6:
|
|
372
|
-
e_7_1 = _c.sent();
|
|
373
|
-
e_7 = { error: e_7_1 };
|
|
374
|
-
return [3 /*break*/, 8];
|
|
375
|
-
case 7:
|
|
376
|
-
try {
|
|
377
|
-
if (orElements_1_1 && !orElements_1_1.done && (_a = orElements_1.return)) _a.call(orElements_1);
|
|
378
|
-
}
|
|
379
|
-
finally { if (e_7) throw e_7.error; }
|
|
380
|
-
return [7 /*endfinally*/];
|
|
381
|
-
case 8:
|
|
382
|
-
this.result.push(function () { return ({
|
|
383
|
-
$or: result
|
|
384
|
-
}); });
|
|
385
|
-
return [2 /*return*/];
|
|
145
|
+
}
|
|
146
|
+
or(orElements) {
|
|
147
|
+
this.promises.push((async () => {
|
|
148
|
+
let result = [];
|
|
149
|
+
for (const element of orElements) {
|
|
150
|
+
let f = new FilterConsumerBridgeToMongo(this.nameProvider);
|
|
151
|
+
f._addWhere = false;
|
|
152
|
+
element.__applyToConsumer(f);
|
|
153
|
+
let where = await f.resolveWhere();
|
|
154
|
+
if (where?.$and?.length > 0) {
|
|
155
|
+
result.push(where);
|
|
386
156
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
157
|
+
else
|
|
158
|
+
return; //since empty or is all rows;
|
|
159
|
+
}
|
|
160
|
+
this.result.push(() => ({
|
|
161
|
+
$or: result
|
|
162
|
+
}));
|
|
163
|
+
})());
|
|
164
|
+
}
|
|
165
|
+
isNull(col) {
|
|
391
166
|
this.add(col, NULL, "$eq");
|
|
392
|
-
}
|
|
393
|
-
|
|
167
|
+
}
|
|
168
|
+
isNotNull(col) {
|
|
394
169
|
this.add(col, NULL, "$ne");
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
_a);
|
|
405
|
-
});
|
|
406
|
-
};
|
|
407
|
-
FilterConsumerBridgeToMongo.prototype.isEqualTo = function (col, val) {
|
|
170
|
+
}
|
|
171
|
+
isIn(col, val) {
|
|
172
|
+
this.result.push(() => ({
|
|
173
|
+
[this.nameProvider.nameOf(col)]: {
|
|
174
|
+
$in: val.map(x => col.valueConverter.toDb(x))
|
|
175
|
+
}
|
|
176
|
+
}));
|
|
177
|
+
}
|
|
178
|
+
isEqualTo(col, val) {
|
|
408
179
|
this.add(col, val, "$eq");
|
|
409
|
-
}
|
|
410
|
-
|
|
180
|
+
}
|
|
181
|
+
isDifferentFrom(col, val) {
|
|
411
182
|
this.add(col, val, "$ne");
|
|
412
|
-
}
|
|
413
|
-
|
|
183
|
+
}
|
|
184
|
+
isGreaterOrEqualTo(col, val) {
|
|
414
185
|
this.add(col, val, "$gte");
|
|
415
|
-
}
|
|
416
|
-
|
|
186
|
+
}
|
|
187
|
+
isGreaterThan(col, val) {
|
|
417
188
|
this.add(col, val, "$gt");
|
|
418
|
-
}
|
|
419
|
-
|
|
189
|
+
}
|
|
190
|
+
isLessOrEqualTo(col, val) {
|
|
420
191
|
this.add(col, val, "$lte");
|
|
421
|
-
}
|
|
422
|
-
|
|
192
|
+
}
|
|
193
|
+
isLessThan(col, val) {
|
|
423
194
|
this.add(col, val, "$lt");
|
|
424
|
-
}
|
|
425
|
-
|
|
195
|
+
}
|
|
196
|
+
containsCaseInsensitive(col, val) {
|
|
426
197
|
throw "containsCaseInsensitive not yet implemented";
|
|
427
198
|
// this.promises.push(col.getDbName().then(colName => {
|
|
428
199
|
// this.result.push(b => b.whereRaw(
|
|
429
200
|
// 'lower (' + colName + ") like lower ('%" + val.replace(/'/g, '\'\'') + "%')"));
|
|
430
201
|
// }));
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
_a);
|
|
439
|
-
});
|
|
440
|
-
};
|
|
441
|
-
FilterConsumerBridgeToMongo.prototype.databaseCustom = function (databaseCustom) {
|
|
202
|
+
}
|
|
203
|
+
add(col, val, operator) {
|
|
204
|
+
this.result.push(() => ({
|
|
205
|
+
[this.nameProvider.nameOf(col)]: { [operator]: isNull(val) ? val : col.valueConverter.toDb(val) }
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
databaseCustom(databaseCustom) {
|
|
442
209
|
throw "error";
|
|
443
210
|
// this.promises.push((async () => {
|
|
444
211
|
// if (databaseCustom?.buildSql) {
|
|
@@ -449,6 +216,5 @@ var FilterConsumerBridgeToMongo = /** @class */ (function () {
|
|
|
449
216
|
// }
|
|
450
217
|
// }
|
|
451
218
|
// })());
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
}());
|
|
219
|
+
}
|
|
220
|
+
}
|
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var fs = require("fs");
|
|
6
|
-
var JsonEntityFileStorage = /** @class */ (function () {
|
|
7
|
-
function JsonEntityFileStorage(folderPath) {
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
export class JsonEntityFileStorage {
|
|
4
|
+
constructor(folderPath) {
|
|
8
5
|
this.folderPath = folderPath;
|
|
9
6
|
}
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
getItem(entityDbName) {
|
|
8
|
+
let fn = path.join(this.folderPath, entityDbName) + '.json';
|
|
12
9
|
if (fs.existsSync(fn)) {
|
|
13
10
|
return fs.readFileSync(fn).toString();
|
|
14
11
|
}
|
|
15
12
|
return undefined;
|
|
16
|
-
}
|
|
17
|
-
|
|
13
|
+
}
|
|
14
|
+
setItem(entityDbName, json) {
|
|
18
15
|
if (!fs.existsSync(this.folderPath)) {
|
|
19
16
|
fs.mkdirSync(this.folderPath);
|
|
20
17
|
}
|
|
21
18
|
return fs.writeFileSync(path.join(this.folderPath, entityDbName) + '.json', json);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
}());
|
|
25
|
-
exports.JsonEntityFileStorage = JsonEntityFileStorage;
|
|
19
|
+
}
|
|
20
|
+
}
|