remult 0.25.8 → 0.26.0
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/README.md +194 -129
- package/esm/graphql.js +131 -59
- package/esm/index.js +1 -1
- package/esm/migrations/compare-migration-snapshots.js +61 -0
- package/esm/migrations/generate-migrations.js +68 -0
- package/esm/migrations/index.js +2 -0
- package/esm/migrations/migrate.js +90 -0
- package/esm/migrations/migration-types.js +36 -0
- package/esm/migrations/update-migrations-ts-file.js +115 -0
- package/esm/postgres/postgres-data-provider.js +24 -3
- package/esm/postgres/schema-builder.js +35 -26
- package/esm/remult-better-sqlite3.js +47 -0
- package/esm/remult-bun-sqlite.js +41 -0
- package/esm/remult-knex/index.js +180 -51
- package/esm/remult-mongo.js +2 -2
- package/esm/remult-sql-js.js +3 -78
- package/esm/remult-sqlite-core.js +104 -0
- package/esm/server/expressBridge.js +130 -29
- package/esm/server/initAsyncHooks.js +75 -1
- package/esm/src/CompoundIdField.js +8 -2
- package/esm/src/context.js +20 -24
- package/esm/src/data-api.js +71 -30
- package/esm/src/data-providers/rest-data-provider.js +17 -15
- package/esm/src/data-providers/sql-database.js +32 -7
- package/esm/src/data-providers/web-sql-data-provider.js +1 -9
- package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +37 -11
- package/esm/src/filter/filter-interfaces.js +229 -17
- package/esm/src/isOfType.js +9 -0
- package/esm/src/remult3/Fields.js +70 -18
- package/esm/src/remult3/RepositoryImplementation.js +47 -21
- package/esm/src/remult3/addValidator.js +15 -0
- package/esm/src/remult3/remult3.js +28 -57
- package/esm/src/server-action.js +4 -4
- package/esm/src/validators.js +6 -3
- package/esm/src/valueConverters.js +1 -1
- package/graphql.js +156 -71
- package/index.d.ts +4 -4
- package/index.js +2 -1
- package/migrations/compare-migration-snapshots.d.ts +27 -0
- package/migrations/compare-migration-snapshots.js +165 -0
- package/migrations/generate-migrations.d.ts +21 -0
- package/migrations/generate-migrations.js +104 -0
- package/migrations/index.d.ts +3 -0
- package/migrations/index.js +7 -0
- package/migrations/migrate.d.ts +27 -0
- package/migrations/migrate.js +175 -0
- package/migrations/migration-types.d.ts +48 -0
- package/migrations/migration-types.js +88 -0
- package/migrations/update-migrations-ts-file.d.ts +1 -0
- package/migrations/update-migrations-ts-file.js +141 -0
- package/package.json +21 -1
- package/postgres/postgres-data-provider.d.ts +8 -3
- package/postgres/postgres-data-provider.js +46 -3
- package/postgres/schema-builder.js +81 -48
- package/remult-better-sqlite3.d.ts +12 -0
- package/remult-better-sqlite3.js +64 -0
- package/remult-bun-sqlite.d.ts +11 -0
- package/remult-bun-sqlite.js +56 -0
- package/remult-knex/index.d.ts +12 -5
- package/remult-knex/index.js +257 -90
- package/remult-mongo.d.ts +2 -2
- package/remult-mongo.js +2 -2
- package/remult-sql-js.d.ts +2 -15
- package/remult-sql-js.js +11 -152
- package/remult-sqlite-core.d.ts +21 -0
- package/remult-sqlite-core.js +217 -0
- package/server/expressBridge.d.ts +30 -1
- package/server/expressBridge.js +140 -32
- package/server/initAsyncHooks.d.ts +16 -0
- package/server/initAsyncHooks.js +128 -2
- package/src/CompoundIdField.js +8 -2
- package/src/column-interfaces.d.ts +9 -3
- package/src/context.d.ts +8 -6
- package/src/context.js +27 -36
- package/src/data-api.d.ts +13 -9
- package/src/data-api.js +184 -135
- package/src/data-providers/rest-data-provider.js +26 -15
- package/src/data-providers/sql-database.d.ts +17 -5
- package/src/data-providers/sql-database.js +31 -7
- package/src/data-providers/web-sql-data-provider.d.ts +1 -2
- package/src/data-providers/web-sql-data-provider.js +4 -8
- package/src/entity.d.ts +64 -6
- package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +31 -7
- package/src/filter/filter-consumer-bridge-to-sql-request.js +46 -21
- package/src/filter/filter-interfaces.d.ts +106 -39
- package/src/filter/filter-interfaces.js +312 -32
- package/src/isOfType.d.ts +2 -0
- package/src/isOfType.js +14 -0
- package/src/remult3/Fields.d.ts +36 -0
- package/src/remult3/Fields.js +81 -19
- package/src/remult3/RepositoryImplementation.d.ts +7 -3
- package/src/remult3/RepositoryImplementation.js +106 -71
- package/src/remult3/addValidator.d.ts +2 -0
- package/src/remult3/addValidator.js +20 -0
- package/src/remult3/remult3.d.ts +6 -2
- package/src/remult3/remult3.js +28 -57
- package/src/server-action.d.ts +1 -1
- package/src/server-action.js +5 -4
- package/src/sql-command.d.ts +6 -1
- package/src/validators.d.ts +1 -0
- package/src/validators.js +10 -4
- package/src/valueConverters.js +1 -1
package/src/data-api.js
CHANGED
|
@@ -25,13 +25,23 @@ var DataApi = /** @class */ (function () {
|
|
|
25
25
|
};
|
|
26
26
|
DataApi.prototype.httpPost = function (res, req, body, serializeContext) {
|
|
27
27
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
28
|
+
function validateWhereInBody() {
|
|
29
|
+
if (!(body === null || body === void 0 ? void 0 : body.where)) {
|
|
30
|
+
throw {
|
|
31
|
+
message: "POST with action ".concat(action, " must have a where clause in the body"),
|
|
32
|
+
httpStatusCode: 400,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
28
36
|
var action, _a;
|
|
29
37
|
return tslib_1.__generator(this, function (_b) {
|
|
30
38
|
switch (_b.label) {
|
|
31
39
|
case 0:
|
|
32
40
|
action = req === null || req === void 0 ? void 0 : req.get('__action');
|
|
33
|
-
if (action === null || action === void 0 ? void 0 : action.startsWith(rest_data_provider_js_1.liveQueryAction))
|
|
41
|
+
if (action === null || action === void 0 ? void 0 : action.startsWith(rest_data_provider_js_1.liveQueryAction)) {
|
|
42
|
+
validateWhereInBody();
|
|
34
43
|
return [2 /*return*/, this.liveQuery(res, req, body, serializeContext, action.substring(rest_data_provider_js_1.liveQueryAction.length))];
|
|
44
|
+
}
|
|
35
45
|
_a = action;
|
|
36
46
|
switch (_a) {
|
|
37
47
|
case 'get': return [3 /*break*/, 1];
|
|
@@ -41,10 +51,18 @@ var DataApi = /** @class */ (function () {
|
|
|
41
51
|
case 'endLiveQuery': return [3 /*break*/, 5];
|
|
42
52
|
}
|
|
43
53
|
return [3 /*break*/, 7];
|
|
44
|
-
case 1:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
case
|
|
54
|
+
case 1:
|
|
55
|
+
validateWhereInBody();
|
|
56
|
+
return [2 /*return*/, this.getArray(res, req, body)];
|
|
57
|
+
case 2:
|
|
58
|
+
validateWhereInBody();
|
|
59
|
+
return [2 /*return*/, this.count(res, req, body)];
|
|
60
|
+
case 3:
|
|
61
|
+
validateWhereInBody();
|
|
62
|
+
return [2 /*return*/, this.deleteMany(res, req, body)];
|
|
63
|
+
case 4:
|
|
64
|
+
validateWhereInBody();
|
|
65
|
+
return [2 /*return*/, this.updateManyImplementation(res, req, body)];
|
|
48
66
|
case 5: return [4 /*yield*/, this.remult.liveQueryStorage.remove(body.id)];
|
|
49
67
|
case 6:
|
|
50
68
|
_b.sent();
|
|
@@ -75,7 +93,7 @@ var DataApi = /** @class */ (function () {
|
|
|
75
93
|
});
|
|
76
94
|
});
|
|
77
95
|
};
|
|
78
|
-
DataApi.prototype.count = function (response, request,
|
|
96
|
+
DataApi.prototype.count = function (response, request, body) {
|
|
79
97
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
80
98
|
var _a, _b, _c, _d, err_1;
|
|
81
99
|
var _e;
|
|
@@ -92,7 +110,7 @@ var DataApi = /** @class */ (function () {
|
|
|
92
110
|
_b = (_a = response).success;
|
|
93
111
|
_e = {};
|
|
94
112
|
_d = (_c = this.repository).count;
|
|
95
|
-
return [4 /*yield*/, this.buildWhere(request,
|
|
113
|
+
return [4 /*yield*/, this.buildWhere(request, body)];
|
|
96
114
|
case 2: return [4 /*yield*/, _d.apply(_c, [_f.sent()])];
|
|
97
115
|
case 3:
|
|
98
116
|
_b.apply(_a, [(_e.count = +(_f.sent()),
|
|
@@ -100,89 +118,86 @@ var DataApi = /** @class */ (function () {
|
|
|
100
118
|
return [3 /*break*/, 5];
|
|
101
119
|
case 4:
|
|
102
120
|
err_1 = _f.sent();
|
|
103
|
-
response.error(err_1);
|
|
121
|
+
response.error(err_1, this.repository.metadata);
|
|
104
122
|
return [3 /*break*/, 5];
|
|
105
123
|
case 5: return [2 /*return*/];
|
|
106
124
|
}
|
|
107
125
|
});
|
|
108
126
|
});
|
|
109
127
|
};
|
|
110
|
-
DataApi.prototype.deleteMany = function (response, request,
|
|
128
|
+
DataApi.prototype.deleteMany = function (response, request, body) {
|
|
111
129
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
112
|
-
var err_2;
|
|
130
|
+
var deleted_1, where_1, err_2;
|
|
113
131
|
var _this = this;
|
|
114
132
|
return tslib_1.__generator(this, function (_a) {
|
|
115
133
|
switch (_a.label) {
|
|
116
134
|
case 0:
|
|
117
|
-
_a.trys.push([0,
|
|
135
|
+
_a.trys.push([0, 3, , 4]);
|
|
136
|
+
deleted_1 = 0;
|
|
137
|
+
return [4 /*yield*/, this.buildWhere(request, body)];
|
|
138
|
+
case 1:
|
|
139
|
+
where_1 = _a.sent();
|
|
140
|
+
filter_interfaces_js_1.Filter.throwErrorIfFilterIsEmpty(where_1, 'deleteMany');
|
|
118
141
|
return [4 /*yield*/, (0, context_js_1.doTransaction)(this.remult, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
119
|
-
var
|
|
120
|
-
var _f;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
switch (_k.label) {
|
|
142
|
+
var _a, _b, _c, x, e_1_1;
|
|
143
|
+
var _d, e_1, _e, _f;
|
|
144
|
+
return tslib_1.__generator(this, function (_g) {
|
|
145
|
+
switch (_g.label) {
|
|
124
146
|
case 0:
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return [4 /*yield*/, this.buildWhere(request, filterBody)];
|
|
147
|
+
_g.trys.push([0, 6, 7, 12]);
|
|
148
|
+
_a = true, _b = tslib_1.__asyncValues(this.repository.query({
|
|
149
|
+
where: where_1,
|
|
150
|
+
include: this.includeNone(),
|
|
151
|
+
}));
|
|
152
|
+
_g.label = 1;
|
|
153
|
+
case 1: return [4 /*yield*/, _b.next()];
|
|
133
154
|
case 2:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
_f)])]);
|
|
137
|
-
_k.label = 3;
|
|
138
|
-
case 3: return [4 /*yield*/, _b.next()];
|
|
139
|
-
case 4:
|
|
140
|
-
if (!(_c = _k.sent(), _g = _c.done, !_g)) return [3 /*break*/, 7];
|
|
141
|
-
_j = _c.value;
|
|
155
|
+
if (!(_c = _g.sent(), _d = _c.done, !_d)) return [3 /*break*/, 5];
|
|
156
|
+
_f = _c.value;
|
|
142
157
|
_a = false;
|
|
143
|
-
x =
|
|
158
|
+
x = _f;
|
|
144
159
|
return [4 /*yield*/, this.actualDelete(x)];
|
|
145
|
-
case
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
case
|
|
160
|
+
case 3:
|
|
161
|
+
_g.sent();
|
|
162
|
+
deleted_1++;
|
|
163
|
+
_g.label = 4;
|
|
164
|
+
case 4:
|
|
150
165
|
_a = true;
|
|
151
|
-
return [3 /*break*/,
|
|
152
|
-
case
|
|
153
|
-
case
|
|
154
|
-
e_1_1 =
|
|
166
|
+
return [3 /*break*/, 1];
|
|
167
|
+
case 5: return [3 /*break*/, 12];
|
|
168
|
+
case 6:
|
|
169
|
+
e_1_1 = _g.sent();
|
|
155
170
|
e_1 = { error: e_1_1 };
|
|
156
|
-
return [3 /*break*/,
|
|
157
|
-
case
|
|
158
|
-
|
|
159
|
-
if (!(!_a && !
|
|
160
|
-
return [4 /*yield*/,
|
|
171
|
+
return [3 /*break*/, 12];
|
|
172
|
+
case 7:
|
|
173
|
+
_g.trys.push([7, , 10, 11]);
|
|
174
|
+
if (!(!_a && !_d && (_e = _b.return))) return [3 /*break*/, 9];
|
|
175
|
+
return [4 /*yield*/, _e.call(_b)];
|
|
176
|
+
case 8:
|
|
177
|
+
_g.sent();
|
|
178
|
+
_g.label = 9;
|
|
179
|
+
case 9: return [3 /*break*/, 11];
|
|
161
180
|
case 10:
|
|
162
|
-
_k.sent();
|
|
163
|
-
_k.label = 11;
|
|
164
|
-
case 11: return [3 /*break*/, 13];
|
|
165
|
-
case 12:
|
|
166
181
|
if (e_1) throw e_1.error;
|
|
167
182
|
return [7 /*endfinally*/];
|
|
168
|
-
case
|
|
169
|
-
case
|
|
170
|
-
response.success({ deleted:
|
|
183
|
+
case 11: return [7 /*endfinally*/];
|
|
184
|
+
case 12:
|
|
185
|
+
response.success({ deleted: deleted_1 });
|
|
171
186
|
return [2 /*return*/];
|
|
172
187
|
}
|
|
173
188
|
});
|
|
174
189
|
}); })];
|
|
175
|
-
case
|
|
176
|
-
case
|
|
190
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
191
|
+
case 3:
|
|
177
192
|
err_2 = _a.sent();
|
|
178
|
-
response.error(err_2);
|
|
179
|
-
return [3 /*break*/,
|
|
180
|
-
case
|
|
193
|
+
response.error(err_2, this.repository.metadata);
|
|
194
|
+
return [3 /*break*/, 4];
|
|
195
|
+
case 4: return [2 /*return*/];
|
|
181
196
|
}
|
|
182
197
|
});
|
|
183
198
|
});
|
|
184
199
|
};
|
|
185
|
-
DataApi.prototype.getArrayImpl = function (response, request,
|
|
200
|
+
DataApi.prototype.getArrayImpl = function (response, request, body) {
|
|
186
201
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
187
202
|
var findOptions, _a, sort, dir, limit, hasId_1, w, r;
|
|
188
203
|
var _this = this;
|
|
@@ -194,7 +209,7 @@ var DataApi = /** @class */ (function () {
|
|
|
194
209
|
include: this.includeNone(),
|
|
195
210
|
};
|
|
196
211
|
_a = findOptions;
|
|
197
|
-
return [4 /*yield*/, this.buildWhere(request,
|
|
212
|
+
return [4 /*yield*/, this.buildWhere(request, body)];
|
|
198
213
|
case 1:
|
|
199
214
|
_a.where = _b.sent();
|
|
200
215
|
if (request) {
|
|
@@ -281,7 +296,7 @@ var DataApi = /** @class */ (function () {
|
|
|
281
296
|
}
|
|
282
297
|
return include;
|
|
283
298
|
};
|
|
284
|
-
DataApi.prototype.getArray = function (response, request,
|
|
299
|
+
DataApi.prototype.getArray = function (response, request, body) {
|
|
285
300
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
286
301
|
var r, err_3;
|
|
287
302
|
return tslib_1.__generator(this, function (_a) {
|
|
@@ -294,7 +309,7 @@ var DataApi = /** @class */ (function () {
|
|
|
294
309
|
_a.label = 1;
|
|
295
310
|
case 1:
|
|
296
311
|
_a.trys.push([1, 3, , 4]);
|
|
297
|
-
return [4 /*yield*/, this.getArrayImpl(response, request,
|
|
312
|
+
return [4 /*yield*/, this.getArrayImpl(response, request, body)];
|
|
298
313
|
case 2:
|
|
299
314
|
r = (_a.sent()).r;
|
|
300
315
|
response.success(r);
|
|
@@ -304,14 +319,14 @@ var DataApi = /** @class */ (function () {
|
|
|
304
319
|
if (err_3.isForbiddenError)
|
|
305
320
|
response.forbidden();
|
|
306
321
|
else
|
|
307
|
-
response.error(err_3);
|
|
322
|
+
response.error(err_3, this.repository.metadata);
|
|
308
323
|
return [3 /*break*/, 4];
|
|
309
324
|
case 4: return [2 /*return*/];
|
|
310
325
|
}
|
|
311
326
|
});
|
|
312
327
|
});
|
|
313
328
|
};
|
|
314
|
-
DataApi.prototype.liveQuery = function (response, request,
|
|
329
|
+
DataApi.prototype.liveQuery = function (response, request, body, serializeContext, queryChannel) {
|
|
315
330
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
316
331
|
var r, data, err_4;
|
|
317
332
|
var _a;
|
|
@@ -326,7 +341,7 @@ var DataApi = /** @class */ (function () {
|
|
|
326
341
|
_b.label = 1;
|
|
327
342
|
case 1:
|
|
328
343
|
_b.trys.push([1, 5, , 6]);
|
|
329
|
-
return [4 /*yield*/, this.getArrayImpl(response, request,
|
|
344
|
+
return [4 /*yield*/, this.getArrayImpl(response, request, body)];
|
|
330
345
|
case 2:
|
|
331
346
|
r = _b.sent();
|
|
332
347
|
_a = {};
|
|
@@ -350,16 +365,17 @@ var DataApi = /** @class */ (function () {
|
|
|
350
365
|
if (err_4.isForbiddenError)
|
|
351
366
|
response.forbidden();
|
|
352
367
|
else
|
|
353
|
-
response.error(err_4);
|
|
368
|
+
response.error(err_4, this.repository.metadata);
|
|
354
369
|
return [3 /*break*/, 6];
|
|
355
370
|
case 6: return [2 /*return*/];
|
|
356
371
|
}
|
|
357
372
|
});
|
|
358
373
|
});
|
|
359
374
|
};
|
|
360
|
-
DataApi.prototype.buildWhere = function (request,
|
|
375
|
+
DataApi.prototype.buildWhere = function (request, body) {
|
|
361
376
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
362
|
-
var where, _a, _b;
|
|
377
|
+
var where, _a, _b, f_1;
|
|
378
|
+
var _this = this;
|
|
363
379
|
return tslib_1.__generator(this, function (_c) {
|
|
364
380
|
switch (_c.label) {
|
|
365
381
|
case 0:
|
|
@@ -375,21 +391,37 @@ var DataApi = /** @class */ (function () {
|
|
|
375
391
|
where.push(this.repository.metadata.options.apiPrefilter);
|
|
376
392
|
_c.label = 3;
|
|
377
393
|
case 3:
|
|
378
|
-
if (request)
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
typeof result === 'string')
|
|
385
|
-
return JSON.parse(result);
|
|
394
|
+
if (!request) return [3 /*break*/, 6];
|
|
395
|
+
f_1 = (0, filter_interfaces_js_1.buildFilterFromRequestParameters)(this.repository.metadata, {
|
|
396
|
+
get: function (key) {
|
|
397
|
+
var _a;
|
|
398
|
+
var result = (_a = body === null || body === void 0 ? void 0 : body.where) === null || _a === void 0 ? void 0 : _a[key];
|
|
399
|
+
if (result !== undefined)
|
|
386
400
|
return result;
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
401
|
+
result = request.get(key);
|
|
402
|
+
if (key.startsWith(filter_interfaces_js_1.customUrlToken) &&
|
|
403
|
+
result &&
|
|
404
|
+
typeof result === 'string')
|
|
405
|
+
return JSON.parse(result);
|
|
406
|
+
return result;
|
|
407
|
+
},
|
|
408
|
+
});
|
|
409
|
+
if (!this.repository.metadata.options.apiPreprocessFilter) return [3 /*break*/, 5];
|
|
410
|
+
return [4 /*yield*/, this.repository.metadata.options.apiPreprocessFilter(f_1, {
|
|
411
|
+
metadata: this.repository.metadata,
|
|
412
|
+
getFilterPreciseValues: function (filter) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
413
|
+
return tslib_1.__generator(this, function (_a) {
|
|
414
|
+
return [2 /*return*/, filter_interfaces_js_1.Filter.getPreciseValues(this.repository.metadata, filter || f_1)];
|
|
415
|
+
});
|
|
416
|
+
}); },
|
|
417
|
+
})];
|
|
418
|
+
case 4:
|
|
419
|
+
f_1 = _c.sent();
|
|
420
|
+
_c.label = 5;
|
|
421
|
+
case 5:
|
|
422
|
+
where.push(f_1);
|
|
423
|
+
_c.label = 6;
|
|
424
|
+
case 6: return [2 /*return*/, { $and: where }];
|
|
393
425
|
}
|
|
394
426
|
});
|
|
395
427
|
});
|
|
@@ -429,7 +461,10 @@ var DataApi = /** @class */ (function () {
|
|
|
429
461
|
return [3 /*break*/, 4];
|
|
430
462
|
case 1:
|
|
431
463
|
if (!(r.length > 1)) return [3 /*break*/, 2];
|
|
432
|
-
response.error({
|
|
464
|
+
response.error({
|
|
465
|
+
message: "id \"".concat(id, "\" is not unique for entity ") +
|
|
466
|
+
this.repository.metadata.key,
|
|
467
|
+
}, this.repository.metadata, 500);
|
|
433
468
|
return [3 /*break*/, 4];
|
|
434
469
|
case 2: return [4 /*yield*/, what(r[0])];
|
|
435
470
|
case 3:
|
|
@@ -444,84 +479,98 @@ var DataApi = /** @class */ (function () {
|
|
|
444
479
|
return [3 /*break*/, 6];
|
|
445
480
|
case 5:
|
|
446
481
|
err_5 = _c.sent();
|
|
447
|
-
response.error(err_5);
|
|
482
|
+
response.error(err_5, this.repository.metadata);
|
|
448
483
|
return [3 /*break*/, 6];
|
|
449
484
|
case 6: return [2 /*return*/];
|
|
450
485
|
}
|
|
451
486
|
});
|
|
452
487
|
});
|
|
453
488
|
};
|
|
454
|
-
DataApi.prototype.
|
|
489
|
+
DataApi.prototype.updateManyThroughPutRequest = function (response, request, body) {
|
|
455
490
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
456
|
-
var
|
|
491
|
+
var action;
|
|
492
|
+
return tslib_1.__generator(this, function (_a) {
|
|
493
|
+
action = request === null || request === void 0 ? void 0 : request.get('__action');
|
|
494
|
+
if (action == 'emptyId') {
|
|
495
|
+
return [2 /*return*/, this.put(response, '', body)];
|
|
496
|
+
}
|
|
497
|
+
return [2 /*return*/, this.updateManyImplementation(response, request, {
|
|
498
|
+
where: undefined,
|
|
499
|
+
set: body,
|
|
500
|
+
})];
|
|
501
|
+
});
|
|
502
|
+
});
|
|
503
|
+
};
|
|
504
|
+
DataApi.prototype.updateManyImplementation = function (response, request, body) {
|
|
505
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
506
|
+
var where_2, err_6;
|
|
457
507
|
var _this = this;
|
|
458
508
|
return tslib_1.__generator(this, function (_a) {
|
|
459
509
|
switch (_a.label) {
|
|
460
510
|
case 0:
|
|
461
|
-
_a.trys.push([0,
|
|
511
|
+
_a.trys.push([0, 3, , 4]);
|
|
512
|
+
return [4 /*yield*/, this.buildWhere(request, body)];
|
|
513
|
+
case 1:
|
|
514
|
+
where_2 = _a.sent();
|
|
515
|
+
filter_interfaces_js_1.Filter.throwErrorIfFilterIsEmpty(where_2, 'deleteMany');
|
|
462
516
|
return [4 /*yield*/, (0, context_js_1.doTransaction)(this.remult, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
463
|
-
var updated, _a, _b, _c,
|
|
464
|
-
var _f;
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
switch (_k.label) {
|
|
517
|
+
var updated, _a, _b, _c, x, e_3_1;
|
|
518
|
+
var _d, e_3, _e, _f;
|
|
519
|
+
return tslib_1.__generator(this, function (_g) {
|
|
520
|
+
switch (_g.label) {
|
|
468
521
|
case 0:
|
|
469
522
|
updated = 0;
|
|
470
|
-
|
|
523
|
+
_g.label = 1;
|
|
471
524
|
case 1:
|
|
472
|
-
|
|
473
|
-
_a = true
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
case 3: return [4 /*yield*/, _b.next()];
|
|
483
|
-
case 4:
|
|
484
|
-
if (!(_c = _k.sent(), _g = _c.done, !_g)) return [3 /*break*/, 7];
|
|
485
|
-
_j = _c.value;
|
|
525
|
+
_g.trys.push([1, 7, 8, 13]);
|
|
526
|
+
_a = true, _b = tslib_1.__asyncValues(this.repository.query({
|
|
527
|
+
where: where_2,
|
|
528
|
+
include: this.includeNone(),
|
|
529
|
+
}));
|
|
530
|
+
_g.label = 2;
|
|
531
|
+
case 2: return [4 /*yield*/, _b.next()];
|
|
532
|
+
case 3:
|
|
533
|
+
if (!(_c = _g.sent(), _d = _c.done, !_d)) return [3 /*break*/, 6];
|
|
534
|
+
_f = _c.value;
|
|
486
535
|
_a = false;
|
|
487
|
-
x =
|
|
536
|
+
x = _f;
|
|
488
537
|
return [4 /*yield*/, this.actualUpdate(x, body.set)];
|
|
489
|
-
case
|
|
490
|
-
|
|
538
|
+
case 4:
|
|
539
|
+
_g.sent();
|
|
491
540
|
updated++;
|
|
492
|
-
|
|
493
|
-
case
|
|
541
|
+
_g.label = 5;
|
|
542
|
+
case 5:
|
|
494
543
|
_a = true;
|
|
495
|
-
return [3 /*break*/,
|
|
496
|
-
case
|
|
497
|
-
case
|
|
498
|
-
e_3_1 =
|
|
544
|
+
return [3 /*break*/, 2];
|
|
545
|
+
case 6: return [3 /*break*/, 13];
|
|
546
|
+
case 7:
|
|
547
|
+
e_3_1 = _g.sent();
|
|
499
548
|
e_3 = { error: e_3_1 };
|
|
500
|
-
return [3 /*break*/,
|
|
549
|
+
return [3 /*break*/, 13];
|
|
550
|
+
case 8:
|
|
551
|
+
_g.trys.push([8, , 11, 12]);
|
|
552
|
+
if (!(!_a && !_d && (_e = _b.return))) return [3 /*break*/, 10];
|
|
553
|
+
return [4 /*yield*/, _e.call(_b)];
|
|
501
554
|
case 9:
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
case
|
|
506
|
-
_k.sent();
|
|
507
|
-
_k.label = 11;
|
|
508
|
-
case 11: return [3 /*break*/, 13];
|
|
509
|
-
case 12:
|
|
555
|
+
_g.sent();
|
|
556
|
+
_g.label = 10;
|
|
557
|
+
case 10: return [3 /*break*/, 12];
|
|
558
|
+
case 11:
|
|
510
559
|
if (e_3) throw e_3.error;
|
|
511
560
|
return [7 /*endfinally*/];
|
|
512
|
-
case
|
|
513
|
-
case
|
|
561
|
+
case 12: return [7 /*endfinally*/];
|
|
562
|
+
case 13:
|
|
514
563
|
response.success({ updated: updated });
|
|
515
564
|
return [2 /*return*/];
|
|
516
565
|
}
|
|
517
566
|
});
|
|
518
567
|
}); })];
|
|
519
|
-
case
|
|
520
|
-
case
|
|
568
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
569
|
+
case 3:
|
|
521
570
|
err_6 = _a.sent();
|
|
522
|
-
response.error(err_6);
|
|
523
|
-
return [3 /*break*/,
|
|
524
|
-
case
|
|
571
|
+
response.error(err_6, this.repository.metadata);
|
|
572
|
+
return [3 /*break*/, 4];
|
|
573
|
+
case 4: return [2 /*return*/];
|
|
525
574
|
}
|
|
526
575
|
});
|
|
527
576
|
});
|
|
@@ -688,9 +737,9 @@ var DataApi = /** @class */ (function () {
|
|
|
688
737
|
case 5:
|
|
689
738
|
err_7 = _c.sent();
|
|
690
739
|
if (err_7.isForbiddenError)
|
|
691
|
-
response.forbidden();
|
|
740
|
+
response.forbidden(err_7.message);
|
|
692
741
|
else
|
|
693
|
-
response.error(err_7);
|
|
742
|
+
response.error(err_7, this.repository.metadata);
|
|
694
743
|
return [3 /*break*/, 6];
|
|
695
744
|
case 6: return [2 /*return*/];
|
|
696
745
|
}
|
|
@@ -165,7 +165,7 @@ var RestEntityDataProvider = /** @class */ (function () {
|
|
|
165
165
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
166
166
|
var run;
|
|
167
167
|
return tslib_1.__generator(this, function (_a) {
|
|
168
|
-
run = this.buildFindRequest({ where: where },
|
|
168
|
+
run = this.buildFindRequest({ where: where }, 'delete').run;
|
|
169
169
|
return [2 /*return*/, run('deleteMany').then(function (r) { return +r.deleted; })];
|
|
170
170
|
});
|
|
171
171
|
});
|
|
@@ -174,8 +174,8 @@ var RestEntityDataProvider = /** @class */ (function () {
|
|
|
174
174
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
175
175
|
var run;
|
|
176
176
|
return tslib_1.__generator(this, function (_a) {
|
|
177
|
-
run = this.buildFindRequest({ where: where },
|
|
178
|
-
return [2 /*return*/, run('updateMany',
|
|
177
|
+
run = this.buildFindRequest({ where: where }, 'put').run;
|
|
178
|
+
return [2 /*return*/, run('updateMany', this.toJsonOfIncludedKeys(data)).then(function (r) { return +r.updated; })];
|
|
179
179
|
});
|
|
180
180
|
});
|
|
181
181
|
};
|
|
@@ -185,16 +185,16 @@ var RestEntityDataProvider = /** @class */ (function () {
|
|
|
185
185
|
return run().then(function (x) { return x.map(function (y) { return _this.translateFromJson(y); }); });
|
|
186
186
|
};
|
|
187
187
|
//@internal
|
|
188
|
-
RestEntityDataProvider.prototype.buildFindRequest = function (options,
|
|
188
|
+
RestEntityDataProvider.prototype.buildFindRequest = function (options, method) {
|
|
189
189
|
var _this = this;
|
|
190
|
-
if (
|
|
190
|
+
if (!method)
|
|
191
|
+
method = 'get';
|
|
191
192
|
var url = new urlBuilder_js_1.UrlBuilder(this.url());
|
|
192
193
|
var filterObject;
|
|
193
194
|
if (options) {
|
|
194
195
|
if (options.where) {
|
|
195
196
|
filterObject = options.where.toJson(); // options.where.__applyToConsumer(new FilterConsumnerBridgeToUrlBuilder(url));
|
|
196
|
-
if (
|
|
197
|
-
addFilterToUrlAndReturnTrueIfSuccessful(filterObject, url))
|
|
197
|
+
if (addFilterToUrlAndReturnTrueIfSuccessful(filterObject, url))
|
|
198
198
|
filterObject = undefined;
|
|
199
199
|
}
|
|
200
200
|
if (options.orderBy && options.orderBy.Segments) {
|
|
@@ -228,15 +228,12 @@ var RestEntityDataProvider = /** @class */ (function () {
|
|
|
228
228
|
}
|
|
229
229
|
if (action)
|
|
230
230
|
u.add('__action', action);
|
|
231
|
-
if (filterObject
|
|
232
|
-
|
|
233
|
-
body = filterObject;
|
|
234
|
-
else
|
|
235
|
-
body = tslib_1.__assign(tslib_1.__assign({}, body), { where: filterObject });
|
|
231
|
+
if (filterObject) {
|
|
232
|
+
body = { set: body, where: filterObject };
|
|
236
233
|
return _this.http().post(u.url, body);
|
|
237
234
|
}
|
|
238
235
|
else
|
|
239
|
-
return _this.http()
|
|
236
|
+
return _this.http()[method](u.url, body);
|
|
240
237
|
};
|
|
241
238
|
return {
|
|
242
239
|
createKey: function () { return JSON.stringify({ url: url, filterObject: filterObject }); },
|
|
@@ -270,7 +267,8 @@ var RestEntityDataProvider = /** @class */ (function () {
|
|
|
270
267
|
RestEntityDataProvider.prototype.update = function (id, data) {
|
|
271
268
|
var _this = this;
|
|
272
269
|
return this.http()
|
|
273
|
-
.put(this.url() +
|
|
270
|
+
.put(this.url() +
|
|
271
|
+
(id != '' ? '/' + encodeURIComponent(id) : '?__action=emptyId'), this.toJsonOfIncludedKeys(data))
|
|
274
272
|
.then(function (y) { return _this.translateFromJson(y); });
|
|
275
273
|
};
|
|
276
274
|
RestEntityDataProvider.prototype.toJsonOfIncludedKeys = function (data) {
|
|
@@ -294,7 +292,20 @@ var RestEntityDataProvider = /** @class */ (function () {
|
|
|
294
292
|
return result;
|
|
295
293
|
};
|
|
296
294
|
RestEntityDataProvider.prototype.delete = function (id) {
|
|
297
|
-
return
|
|
295
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
296
|
+
return tslib_1.__generator(this, function (_a) {
|
|
297
|
+
switch (_a.label) {
|
|
298
|
+
case 0:
|
|
299
|
+
if (!(id == '')) return [3 /*break*/, 2];
|
|
300
|
+
return [4 /*yield*/, this.deleteMany(filter_interfaces_js_1.Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)))];
|
|
301
|
+
case 1:
|
|
302
|
+
_a.sent();
|
|
303
|
+
return [3 /*break*/, 3];
|
|
304
|
+
case 2: return [2 /*return*/, this.http().delete(this.url() + '/' + encodeURIComponent(id))];
|
|
305
|
+
case 3: return [2 /*return*/];
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
});
|
|
298
309
|
};
|
|
299
310
|
RestEntityDataProvider.prototype.insert = function (data) {
|
|
300
311
|
var _this = this;
|
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
import type { DataProvider, EntityDataProvider } from '../data-interfaces.js';
|
|
2
|
-
import type { HasWrapIdentifier, SqlCommand, SqlCommandWithParameters, SqlImplementation, SqlResult } from '../sql-command.js';
|
|
3
|
-
import type { Remult } from '../context.js';
|
|
2
|
+
import type { HasWrapIdentifier, SqlCommand, SqlCommandFactory, SqlCommandWithParameters, SqlImplementation, SqlResult } from '../sql-command.js';
|
|
4
3
|
import type { CustomSqlFilterBuilderFunction, EntityDbNamesBase } from '../filter/filter-consumer-bridge-to-sql-request.js';
|
|
5
4
|
import type { EntityFilter, EntityMetadata } from '../remult3/remult3.js';
|
|
6
5
|
import type { RepositoryOverloads } from '../remult3/RepositoryImplementation.js';
|
|
7
|
-
|
|
6
|
+
import type { CanBuildMigrations, MigrationBuilder, MigrationCode } from '../../migrations/migration-types.js';
|
|
7
|
+
export declare class SqlDatabase implements DataProvider, HasWrapIdentifier, CanBuildMigrations, SqlCommandFactory {
|
|
8
8
|
private sql;
|
|
9
|
-
static getDb(
|
|
9
|
+
static getDb(dataProvider?: DataProvider): SqlDatabase;
|
|
10
10
|
createCommand(): SqlCommand;
|
|
11
11
|
execute(sql: string): Promise<SqlResult>;
|
|
12
12
|
wrapIdentifier: (name: string) => string;
|
|
13
13
|
ensureSchema(entities: EntityMetadata<any>[]): Promise<void>;
|
|
14
14
|
getEntityDataProvider(entity: EntityMetadata): EntityDataProvider;
|
|
15
15
|
transaction(action: (dataProvider: DataProvider) => Promise<void>): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a raw filter for entity filtering.
|
|
18
|
+
* @param {CustomSqlFilterBuilderFunction} build - The custom SQL filter builder function.
|
|
19
|
+
* @returns {EntityFilter<any>} - The entity filter with a custom SQL filter.
|
|
20
|
+
* @example
|
|
21
|
+
* SqlDatabase.rawFilter(({param}) =>
|
|
22
|
+
`"customerId" in (select id from customers where city = ${param(customerCity)})`
|
|
23
|
+
)
|
|
24
|
+
* @see [Leveraging Database Capabilities with Raw SQL in Custom Filters](https://remult.dev/docs/custom-filter.html#leveraging-database-capabilities-with-raw-sql-in-custom-filters)
|
|
25
|
+
*/
|
|
16
26
|
static rawFilter(build: CustomSqlFilterBuilderFunction): EntityFilter<any>;
|
|
17
|
-
static filterToRaw<entityType>(repo: RepositoryOverloads<entityType>, condition: EntityFilter<entityType>, sqlCommand?: SqlCommandWithParameters, dbNames?: EntityDbNamesBase): Promise<string>;
|
|
27
|
+
static filterToRaw<entityType>(repo: RepositoryOverloads<entityType>, condition: EntityFilter<entityType>, sqlCommand?: SqlCommandWithParameters, dbNames?: EntityDbNamesBase, wrapIdentifier?: (name: string) => string): Promise<string>;
|
|
18
28
|
/**
|
|
19
29
|
* `false` _(default)_ - No logging
|
|
20
30
|
*
|
|
@@ -30,5 +40,7 @@ export declare class SqlDatabase implements DataProvider, HasWrapIdentifier {
|
|
|
30
40
|
*/
|
|
31
41
|
static durationThreshold: number;
|
|
32
42
|
constructor(sql: SqlImplementation);
|
|
43
|
+
provideMigrationBuilder: (builder: MigrationCode) => MigrationBuilder;
|
|
33
44
|
private createdEntities;
|
|
45
|
+
end: () => Promise<void>;
|
|
34
46
|
}
|