remult 0.14.6 → 0.14.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assign.js +5 -1
- package/classType.js +2 -1
- package/graphql.js +146 -84
- package/index.js +73 -25
- package/inputTypes.js +16 -9
- package/package.json +1 -2
- package/postgres/index.js +4 -1
- package/postgres/postgres-data-provider.d.ts +4 -1
- package/postgres/postgres-data-provider.js +364 -165
- package/postgres/postgresColumnSyntax.d.ts +1 -1
- package/postgres/postgresColumnSyntax.js +8 -4
- package/remult-express.js +10 -6
- package/remult-knex/index.d.ts +5 -2
- package/remult-knex/index.js +720 -300
- package/remult-middleware.js +29 -24
- package/remult-mongo.js +406 -172
- package/server/JsonEntityFileStorage.js +15 -10
- package/server/expressBridge.d.ts +4 -2
- package/server/expressBridge.js +570 -383
- package/server/index.js +11 -4
- package/server/register-actions-on-server.js +38 -12
- package/server/register-entities-on-server.js +13 -9
- package/src/__EntityValueProvider.js +2 -1
- package/src/__RowsOfDataForTesting.js +2 -1
- package/src/backend-tests/backend-database-test-setup.backend-spec.js +190 -72
- package/src/backend-tests/my-test.backend-spec.js +114 -45
- package/src/column-interfaces.js +6 -2
- package/src/column.js +113 -71
- package/src/context.js +330 -174
- package/src/data-api.js +326 -162
- package/src/data-interfaces.js +11 -7
- package/src/data-providers/array-entity-data-provider.js +286 -171
- package/src/data-providers/in-memory-database.js +27 -12
- package/src/data-providers/json-data-provider.js +77 -41
- package/src/data-providers/rest-data-provider.js +189 -102
- package/src/data-providers/sql-database.js +403 -223
- package/src/data-providers/web-sql-data-provider.js +139 -78
- package/src/entity.js +2 -1
- package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +1 -1
- package/src/filter/filter-consumer-bridge-to-sql-request.js +248 -106
- package/src/filter/filter-consumer-bridge-to-url-builder.js +2 -1
- package/src/filter/filter-interfaces.js +440 -277
- package/src/id-entity.js +17 -8
- package/src/remult3/RepositoryImplementation.js +2367 -1191
- package/src/remult3/index.js +5 -2
- package/src/remult3/remult3.js +2 -1
- package/src/server-action.js +528 -294
- package/src/shared-tests/db-tests-setup.js +153 -49
- package/src/shared-tests/db-tests.db-tests.js +1566 -660
- package/src/shared-tests/deleteAll.js +20 -3
- package/src/shared-tests/entityWithValidations.js +79 -52
- package/src/shared-tests/index.js +6 -4
- package/src/shared-tests/test-custom-id-column.spec.js +85 -37
- package/src/shared-tests/test-special-value.spec.js +104 -64
- package/src/shared-tests/test-update-with-null.spec.js +49 -28
- package/src/sort.js +95 -38
- package/src/sql-command.js +2 -1
- package/src/tests/Done.js +13 -7
- package/src/tests/TestDataApiResponse.js +22 -15
- package/src/tests/c.js +27 -21
- package/src/tests/createData.js +48 -20
- package/src/tests/d.js +27 -19
- package/src/tests/dWithPrefilter.js +44 -31
- package/src/tests/entityForCustomFilter.js +66 -42
- package/src/tests/entityWithValidationsOnColumn.js +29 -21
- package/src/tests/frontend-database-tests-setup.spec.js +98 -35
- package/src/tests/h.js +44 -35
- package/src/tests/remult-3-entities.js +80 -71
- package/src/tests/tasks.js +29 -23
- package/src/tests/testHelper.spec.js +322 -170
- package/src/tests/testModel/models.js +33 -25
- package/src/validators.js +59 -32
- package/urlBuilder.js +14 -8
- package/valueConverters.js +160 -161
package/remult-mongo.js
CHANGED
|
@@ -1,211 +1,444 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MongoDataProvider = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
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) {
|
|
5
9
|
this.db = db;
|
|
6
10
|
this.client = client;
|
|
7
11
|
}
|
|
8
|
-
getEntityDataProvider(entity) {
|
|
12
|
+
MongoDataProvider.prototype.getEntityDataProvider = function (entity) {
|
|
9
13
|
return new MongoEntityDataProvider(this.db, entity);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
};
|
|
15
|
+
MongoDataProvider.prototype.transaction = function (action) {
|
|
16
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
17
|
+
var session, err_1;
|
|
18
|
+
return tslib_1.__generator(this, function (_a) {
|
|
19
|
+
switch (_a.label) {
|
|
20
|
+
case 0: return [4 /*yield*/, this.client.startSession()];
|
|
21
|
+
case 1:
|
|
22
|
+
session = _a.sent();
|
|
23
|
+
session.startTransaction();
|
|
24
|
+
_a.label = 2;
|
|
25
|
+
case 2:
|
|
26
|
+
_a.trys.push([2, 5, , 7]);
|
|
27
|
+
return [4 /*yield*/, action(new MongoDataProvider(this.db, undefined))];
|
|
28
|
+
case 3:
|
|
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" };
|
|
25
49
|
function isNull(x) {
|
|
26
|
-
return x
|
|
50
|
+
return (x === null || x === void 0 ? void 0 : x.$null) === NULL.$null;
|
|
27
51
|
}
|
|
28
|
-
|
|
29
|
-
|
|
52
|
+
var MongoEntityDataProvider = /** @class */ (function () {
|
|
53
|
+
function MongoEntityDataProvider(db, entity) {
|
|
30
54
|
this.db = db;
|
|
31
55
|
this.entity = entity;
|
|
32
56
|
}
|
|
33
|
-
translateFromJson(row, nameProvider) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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;
|
|
49
|
-
}
|
|
50
|
-
return result;
|
|
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;
|
|
57
|
+
MongoEntityDataProvider.prototype.translateFromJson = function (row, nameProvider) {
|
|
58
|
+
var e_1, _a;
|
|
59
|
+
var result = {};
|
|
60
|
+
try {
|
|
61
|
+
for (var _b = tslib_1.__values(this.entity.fields), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
62
|
+
var col = _c.value;
|
|
63
|
+
result[col.key] = col.valueConverter.fromDb(row[nameProvider.nameOf(col)]);
|
|
64
|
+
if (isNull(result[col.key]))
|
|
65
|
+
result[col.key] = null;
|
|
70
66
|
}
|
|
71
67
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
69
|
+
finally {
|
|
70
|
+
try {
|
|
71
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
76
72
|
}
|
|
73
|
+
finally { if (e_1) throw e_1.error; }
|
|
77
74
|
}
|
|
78
|
-
return
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
75
|
+
return result;
|
|
76
|
+
};
|
|
77
|
+
MongoEntityDataProvider.prototype.translateToJson = function (row, nameProvider) {
|
|
78
|
+
var e_2, _a;
|
|
79
|
+
var result = {};
|
|
80
|
+
try {
|
|
81
|
+
for (var _b = tslib_1.__values(this.entity.fields), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
82
|
+
var col = _c.value;
|
|
83
|
+
var val = col.valueConverter.toDb(row[col.key]);
|
|
84
|
+
if (val === null)
|
|
85
|
+
val = NULL;
|
|
86
|
+
result[nameProvider.nameOf(col)] = val;
|
|
90
87
|
}
|
|
91
88
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (keys.includes(f.key)) {
|
|
97
|
-
newR[f.key] = f.valueConverter.toJson(data[f.key]);
|
|
98
|
-
}
|
|
89
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
90
|
+
finally {
|
|
91
|
+
try {
|
|
92
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
99
93
|
}
|
|
94
|
+
finally { if (e_2) throw e_2.error; }
|
|
100
95
|
}
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
return result;
|
|
97
|
+
};
|
|
98
|
+
MongoEntityDataProvider.prototype.count = function (where) {
|
|
99
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
100
|
+
var _a, collection, e, x, w;
|
|
101
|
+
return tslib_1.__generator(this, function (_b) {
|
|
102
|
+
switch (_b.label) {
|
|
103
|
+
case 0: return [4 /*yield*/, this.collection()];
|
|
104
|
+
case 1:
|
|
105
|
+
_a = _b.sent(), collection = _a.collection, e = _a.e;
|
|
106
|
+
x = new FilterConsumerBridgeToMongo(e);
|
|
107
|
+
where.__applyToConsumer(x);
|
|
108
|
+
return [4 /*yield*/, x.resolveWhere()];
|
|
109
|
+
case 2:
|
|
110
|
+
w = _b.sent();
|
|
111
|
+
return [4 /*yield*/, collection.countDocuments(w)];
|
|
112
|
+
case 3: return [2 /*return*/, _b.sent()];
|
|
113
|
+
}
|
|
114
|
+
});
|
|
103
115
|
});
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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 }];
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
};
|
|
278
|
+
return MongoEntityDataProvider;
|
|
279
|
+
}());
|
|
280
|
+
var FilterConsumerBridgeToMongo = /** @class */ (function () {
|
|
281
|
+
function FilterConsumerBridgeToMongo(nameProvider) {
|
|
125
282
|
this.nameProvider = nameProvider;
|
|
126
283
|
this._addWhere = true;
|
|
127
284
|
this.promises = [];
|
|
128
285
|
this.result = [];
|
|
129
286
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
287
|
+
FilterConsumerBridgeToMongo.prototype.resolveWhere = function () {
|
|
288
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
289
|
+
var p, p_1, p_1_1, pr, e_6_1;
|
|
290
|
+
var e_6, _a;
|
|
291
|
+
return tslib_1.__generator(this, function (_b) {
|
|
292
|
+
switch (_b.label) {
|
|
293
|
+
case 0:
|
|
294
|
+
if (!(this.promises.length > 0)) return [3 /*break*/, 9];
|
|
295
|
+
p = this.promises;
|
|
296
|
+
this.promises = [];
|
|
297
|
+
_b.label = 1;
|
|
298
|
+
case 1:
|
|
299
|
+
_b.trys.push([1, 6, 7, 8]);
|
|
300
|
+
p_1 = (e_6 = void 0, tslib_1.__values(p)), p_1_1 = p_1.next();
|
|
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) {
|
|
144
335
|
throw new Error("Custom filter should be translated before it gets here");
|
|
145
|
-
}
|
|
146
|
-
or(orElements) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
336
|
+
};
|
|
337
|
+
FilterConsumerBridgeToMongo.prototype.or = function (orElements) {
|
|
338
|
+
var _this = this;
|
|
339
|
+
this.promises.push((function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
340
|
+
var result, orElements_1, orElements_1_1, element, f, where, e_7_1;
|
|
341
|
+
var e_7, _a;
|
|
342
|
+
var _b;
|
|
343
|
+
return tslib_1.__generator(this, function (_c) {
|
|
344
|
+
switch (_c.label) {
|
|
345
|
+
case 0:
|
|
346
|
+
result = [];
|
|
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*/];
|
|
156
386
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
$or: result
|
|
162
|
-
}));
|
|
163
|
-
})());
|
|
164
|
-
}
|
|
165
|
-
isNull(col) {
|
|
387
|
+
});
|
|
388
|
+
}); })());
|
|
389
|
+
};
|
|
390
|
+
FilterConsumerBridgeToMongo.prototype.isNull = function (col) {
|
|
166
391
|
this.add(col, NULL, "$eq");
|
|
167
|
-
}
|
|
168
|
-
isNotNull(col) {
|
|
392
|
+
};
|
|
393
|
+
FilterConsumerBridgeToMongo.prototype.isNotNull = function (col) {
|
|
169
394
|
this.add(col, NULL, "$ne");
|
|
170
|
-
}
|
|
171
|
-
isIn(col, val) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
395
|
+
};
|
|
396
|
+
FilterConsumerBridgeToMongo.prototype.isIn = function (col, val) {
|
|
397
|
+
var _this = this;
|
|
398
|
+
this.result.push(function () {
|
|
399
|
+
var _a;
|
|
400
|
+
return (_a = {},
|
|
401
|
+
_a[_this.nameProvider.nameOf(col)] = {
|
|
402
|
+
$in: val.map(function (x) { return col.valueConverter.toDb(x); })
|
|
403
|
+
},
|
|
404
|
+
_a);
|
|
405
|
+
});
|
|
406
|
+
};
|
|
407
|
+
FilterConsumerBridgeToMongo.prototype.isEqualTo = function (col, val) {
|
|
179
408
|
this.add(col, val, "$eq");
|
|
180
|
-
}
|
|
181
|
-
isDifferentFrom(col, val) {
|
|
409
|
+
};
|
|
410
|
+
FilterConsumerBridgeToMongo.prototype.isDifferentFrom = function (col, val) {
|
|
182
411
|
this.add(col, val, "$ne");
|
|
183
|
-
}
|
|
184
|
-
isGreaterOrEqualTo(col, val) {
|
|
412
|
+
};
|
|
413
|
+
FilterConsumerBridgeToMongo.prototype.isGreaterOrEqualTo = function (col, val) {
|
|
185
414
|
this.add(col, val, "$gte");
|
|
186
|
-
}
|
|
187
|
-
isGreaterThan(col, val) {
|
|
415
|
+
};
|
|
416
|
+
FilterConsumerBridgeToMongo.prototype.isGreaterThan = function (col, val) {
|
|
188
417
|
this.add(col, val, "$gt");
|
|
189
|
-
}
|
|
190
|
-
isLessOrEqualTo(col, val) {
|
|
418
|
+
};
|
|
419
|
+
FilterConsumerBridgeToMongo.prototype.isLessOrEqualTo = function (col, val) {
|
|
191
420
|
this.add(col, val, "$lte");
|
|
192
|
-
}
|
|
193
|
-
isLessThan(col, val) {
|
|
421
|
+
};
|
|
422
|
+
FilterConsumerBridgeToMongo.prototype.isLessThan = function (col, val) {
|
|
194
423
|
this.add(col, val, "$lt");
|
|
195
|
-
}
|
|
196
|
-
containsCaseInsensitive(col, val) {
|
|
424
|
+
};
|
|
425
|
+
FilterConsumerBridgeToMongo.prototype.containsCaseInsensitive = function (col, val) {
|
|
197
426
|
throw "containsCaseInsensitive not yet implemented";
|
|
198
427
|
// this.promises.push(col.getDbName().then(colName => {
|
|
199
428
|
// this.result.push(b => b.whereRaw(
|
|
200
429
|
// 'lower (' + colName + ") like lower ('%" + val.replace(/'/g, '\'\'') + "%')"));
|
|
201
430
|
// }));
|
|
202
|
-
}
|
|
203
|
-
add(col, val, operator) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
431
|
+
};
|
|
432
|
+
FilterConsumerBridgeToMongo.prototype.add = function (col, val, operator) {
|
|
433
|
+
var _this = this;
|
|
434
|
+
this.result.push(function () {
|
|
435
|
+
var _a, _b;
|
|
436
|
+
return (_a = {},
|
|
437
|
+
_a[_this.nameProvider.nameOf(col)] = (_b = {}, _b[operator] = isNull(val) ? val : col.valueConverter.toDb(val), _b),
|
|
438
|
+
_a);
|
|
439
|
+
});
|
|
440
|
+
};
|
|
441
|
+
FilterConsumerBridgeToMongo.prototype.databaseCustom = function (databaseCustom) {
|
|
209
442
|
throw "error";
|
|
210
443
|
// this.promises.push((async () => {
|
|
211
444
|
// if (databaseCustom?.buildSql) {
|
|
@@ -216,5 +449,6 @@ class FilterConsumerBridgeToMongo {
|
|
|
216
449
|
// }
|
|
217
450
|
// }
|
|
218
451
|
// })());
|
|
219
|
-
}
|
|
220
|
-
|
|
452
|
+
};
|
|
453
|
+
return FilterConsumerBridgeToMongo;
|
|
454
|
+
}());
|
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonEntityFileStorage = void 0;
|
|
4
|
+
var path = require("path");
|
|
5
|
+
var fs = require("fs");
|
|
6
|
+
var JsonEntityFileStorage = /** @class */ (function () {
|
|
7
|
+
function JsonEntityFileStorage(folderPath) {
|
|
5
8
|
this.folderPath = folderPath;
|
|
6
9
|
}
|
|
7
|
-
getItem(entityDbName) {
|
|
8
|
-
|
|
10
|
+
JsonEntityFileStorage.prototype.getItem = function (entityDbName) {
|
|
11
|
+
var fn = path.join(this.folderPath, entityDbName) + '.json';
|
|
9
12
|
if (fs.existsSync(fn)) {
|
|
10
13
|
return fs.readFileSync(fn).toString();
|
|
11
14
|
}
|
|
12
15
|
return undefined;
|
|
13
|
-
}
|
|
14
|
-
setItem(entityDbName, json) {
|
|
16
|
+
};
|
|
17
|
+
JsonEntityFileStorage.prototype.setItem = function (entityDbName, json) {
|
|
15
18
|
if (!fs.existsSync(this.folderPath)) {
|
|
16
19
|
fs.mkdirSync(this.folderPath);
|
|
17
20
|
}
|
|
18
21
|
return fs.writeFileSync(path.join(this.folderPath, entityDbName) + '.json', json);
|
|
19
|
-
}
|
|
20
|
-
|
|
22
|
+
};
|
|
23
|
+
return JsonEntityFileStorage;
|
|
24
|
+
}());
|
|
25
|
+
exports.JsonEntityFileStorage = JsonEntityFileStorage;
|