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/src/server-action.js
CHANGED
|
@@ -1,599 +1,365 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var sql_database_1 = require("./data-providers/sql-database");
|
|
8
|
-
var remult3_1 = require("./remult3");
|
|
9
|
-
var Action = /** @class */ (function () {
|
|
10
|
-
function Action(actionUrl, queue, allowed) {
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { Remult, allEntities, classHelpers, ClassHelper, MethodHelper, setControllerSettings } from './context';
|
|
3
|
+
import { SqlDatabase } from './data-providers/sql-database';
|
|
4
|
+
import { getEntityRef, decorateColumnSettings, getEntitySettings, getControllerRef } from './remult3';
|
|
5
|
+
export class Action {
|
|
6
|
+
constructor(actionUrl, queue, allowed) {
|
|
11
7
|
this.actionUrl = actionUrl;
|
|
12
8
|
this.queue = queue;
|
|
13
9
|
this.allowed = allowed;
|
|
14
10
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return [2 /*return*/, runningJob_1.result];
|
|
59
|
-
case 4:
|
|
60
|
-
progress_1.close();
|
|
61
|
-
return [7 /*endfinally*/];
|
|
62
|
-
case 5: return [3 /*break*/, 7];
|
|
63
|
-
case 6: return [2 /*return*/, r];
|
|
64
|
-
case 7: return [2 /*return*/];
|
|
65
|
-
}
|
|
66
|
-
});
|
|
11
|
+
async run(pIn) {
|
|
12
|
+
let r = await Action.provider.post(Remult.apiBaseUrl + '/' + this.actionUrl, pIn);
|
|
13
|
+
let p = r;
|
|
14
|
+
if (p && p.queuedJobId) {
|
|
15
|
+
let progress = actionInfo.startBusyWithProgress();
|
|
16
|
+
try {
|
|
17
|
+
let runningJob;
|
|
18
|
+
await actionInfo.runActionWithoutBlockingUI(async () => {
|
|
19
|
+
while (!runningJob || !runningJob.done) {
|
|
20
|
+
if (runningJob)
|
|
21
|
+
await new Promise(res => setTimeout(() => {
|
|
22
|
+
res(undefined);
|
|
23
|
+
}, 200));
|
|
24
|
+
runningJob = await Action.provider.post(Remult.apiBaseUrl + '/' + Action.apiUrlForJobStatus, { queuedJobId: r.queuedJobId });
|
|
25
|
+
if (runningJob.progress) {
|
|
26
|
+
progress.progress(runningJob.progress);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
if (runningJob.error)
|
|
31
|
+
throw runningJob.error;
|
|
32
|
+
progress.progress(1);
|
|
33
|
+
return runningJob.result;
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
progress.close();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else
|
|
40
|
+
return r;
|
|
41
|
+
}
|
|
42
|
+
__register(reg) {
|
|
43
|
+
reg(this.actionUrl, this.queue, this.allowed, async (d, req, res) => {
|
|
44
|
+
try {
|
|
45
|
+
var r = await this.execute(d, req, res);
|
|
46
|
+
res.success(r);
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
if (err instanceof ForbiddenError)
|
|
50
|
+
res.forbidden();
|
|
51
|
+
else
|
|
52
|
+
res.error(err);
|
|
53
|
+
}
|
|
67
54
|
});
|
|
68
|
-
};
|
|
69
|
-
Action.prototype.__register = function (reg) {
|
|
70
|
-
var _this = this;
|
|
71
|
-
reg(this.actionUrl, this.queue, this.allowed, function (d, req, res) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
72
|
-
var r, err_1;
|
|
73
|
-
return tslib_1.__generator(this, function (_a) {
|
|
74
|
-
switch (_a.label) {
|
|
75
|
-
case 0:
|
|
76
|
-
_a.trys.push([0, 2, , 3]);
|
|
77
|
-
return [4 /*yield*/, this.execute(d, req, res)];
|
|
78
|
-
case 1:
|
|
79
|
-
r = _a.sent();
|
|
80
|
-
res.success(r);
|
|
81
|
-
return [3 /*break*/, 3];
|
|
82
|
-
case 2:
|
|
83
|
-
err_1 = _a.sent();
|
|
84
|
-
if (err_1 instanceof ForbiddenError)
|
|
85
|
-
res.forbidden();
|
|
86
|
-
else
|
|
87
|
-
res.error(err_1);
|
|
88
|
-
return [3 /*break*/, 3];
|
|
89
|
-
case 3: return [2 /*return*/];
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}); });
|
|
93
|
-
};
|
|
94
|
-
Action.apiUrlForJobStatus = 'jobStatusInQueue';
|
|
95
|
-
return Action;
|
|
96
|
-
}());
|
|
97
|
-
exports.Action = Action;
|
|
98
|
-
var ForbiddenError = /** @class */ (function (_super) {
|
|
99
|
-
tslib_1.__extends(ForbiddenError, _super);
|
|
100
|
-
function ForbiddenError() {
|
|
101
|
-
return _super.call(this, "Forbidden") || this;
|
|
102
55
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
var _this = _super.call(this, name, options.queue, options.allowed) || this;
|
|
109
|
-
_this.types = types;
|
|
110
|
-
_this.options = options;
|
|
111
|
-
_this.originalMethod = originalMethod;
|
|
112
|
-
return _this;
|
|
56
|
+
}
|
|
57
|
+
Action.apiUrlForJobStatus = 'jobStatusInQueue';
|
|
58
|
+
class ForbiddenError extends Error {
|
|
59
|
+
constructor() {
|
|
60
|
+
super("Forbidden");
|
|
113
61
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
case 2:
|
|
137
|
-
_c.trys.push([2, 4, , 5]);
|
|
138
|
-
_b = result;
|
|
139
|
-
return [4 /*yield*/, this.originalMethod(info.args)];
|
|
140
|
-
case 3:
|
|
141
|
-
_b.data = _c.sent();
|
|
142
|
-
return [3 /*break*/, 5];
|
|
143
|
-
case 4:
|
|
144
|
-
err_2 = _c.sent();
|
|
145
|
-
throw err_2;
|
|
146
|
-
case 5: return [2 /*return*/];
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}); })];
|
|
150
|
-
case 1:
|
|
151
|
-
_a.sent();
|
|
152
|
-
return [2 /*return*/, result];
|
|
153
|
-
}
|
|
154
|
-
});
|
|
62
|
+
}
|
|
63
|
+
export class myServerAction extends Action {
|
|
64
|
+
constructor(name, types, options, originalMethod) {
|
|
65
|
+
super(name, options.queue, options.allowed);
|
|
66
|
+
this.types = types;
|
|
67
|
+
this.options = options;
|
|
68
|
+
this.originalMethod = originalMethod;
|
|
69
|
+
}
|
|
70
|
+
async execute(info, remult, res) {
|
|
71
|
+
let result = { data: {} };
|
|
72
|
+
let ds = remult._dataSource;
|
|
73
|
+
await ds.transaction(async (ds) => {
|
|
74
|
+
remult.setDataProvider(ds);
|
|
75
|
+
if (!remult.isAllowedForInstance(undefined, this.options.allowed))
|
|
76
|
+
throw new ForbiddenError();
|
|
77
|
+
info.args = await prepareReceivedArgs(this.types, info.args, remult, ds, res);
|
|
78
|
+
try {
|
|
79
|
+
result.data = await this.originalMethod(info.args);
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
155
84
|
});
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
exports.actionInfo = {
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export const actionInfo = {
|
|
161
89
|
allActions: [],
|
|
162
90
|
runningOnServer: false,
|
|
163
|
-
runActionWithoutBlockingUI:
|
|
164
|
-
startBusyWithProgress:
|
|
165
|
-
progress:
|
|
166
|
-
close:
|
|
167
|
-
})
|
|
91
|
+
runActionWithoutBlockingUI: (what) => { return what(); },
|
|
92
|
+
startBusyWithProgress: () => ({
|
|
93
|
+
progress: (percent) => { },
|
|
94
|
+
close: () => { }
|
|
95
|
+
})
|
|
168
96
|
};
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
function Controller(key) {
|
|
97
|
+
export const serverActionField = Symbol('serverActionField');
|
|
98
|
+
const methodHelpers = new Map();
|
|
99
|
+
const classOptions = new Map();
|
|
100
|
+
export function Controller(key) {
|
|
173
101
|
return function (target) {
|
|
174
|
-
|
|
175
|
-
classOptions.set(r, { key
|
|
176
|
-
|
|
102
|
+
let r = target;
|
|
103
|
+
classOptions.set(r, { key });
|
|
104
|
+
setControllerSettings(target, { key });
|
|
177
105
|
return target;
|
|
178
106
|
};
|
|
179
107
|
}
|
|
180
|
-
exports.Controller = Controller;
|
|
181
108
|
/** Indicates that the decorated methods runs on the backend. See: [Backend Methods](https://remult.dev/docs/backendMethods.html) */
|
|
182
|
-
function BackendMethod(options) {
|
|
183
|
-
return
|
|
109
|
+
export function BackendMethod(options) {
|
|
110
|
+
return (target, key, descriptor) => {
|
|
184
111
|
if (target.prototype !== undefined) {
|
|
185
112
|
var originalMethod = descriptor.value;
|
|
186
113
|
var types = Reflect.getMetadata("design:paramtypes", target, key);
|
|
187
114
|
// if types are undefined - you've forgot to set: "emitDecoratorMetadata":true
|
|
188
|
-
|
|
189
|
-
descriptor.value = function () {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
115
|
+
let serverAction = new myServerAction(key, types, options, args => originalMethod.apply(undefined, args));
|
|
116
|
+
descriptor.value = async function (...args) {
|
|
117
|
+
if (!actionInfo.runningOnServer) {
|
|
118
|
+
args = prepareArgsToSend(types, args);
|
|
119
|
+
if (options.blockUser === false) {
|
|
120
|
+
return await actionInfo.runActionWithoutBlockingUI(async () => (await serverAction.run({ args })).data);
|
|
121
|
+
}
|
|
122
|
+
else
|
|
123
|
+
return (await serverAction.run({ args })).data;
|
|
193
124
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
return tslib_1.__generator(this, function (_a) {
|
|
197
|
-
switch (_a.label) {
|
|
198
|
-
case 0:
|
|
199
|
-
if (!!exports.actionInfo.runningOnServer) return [3 /*break*/, 5];
|
|
200
|
-
args = prepareArgsToSend(types, args);
|
|
201
|
-
if (!(options.blockUser === false)) return [3 /*break*/, 2];
|
|
202
|
-
return [4 /*yield*/, exports.actionInfo.runActionWithoutBlockingUI(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
203
|
-
switch (_a.label) {
|
|
204
|
-
case 0: return [4 /*yield*/, serverAction_1.run({ args: args })];
|
|
205
|
-
case 1: return [2 /*return*/, (_a.sent()).data];
|
|
206
|
-
}
|
|
207
|
-
}); }); })];
|
|
208
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
209
|
-
case 2: return [4 /*yield*/, serverAction_1.run({ args: args })];
|
|
210
|
-
case 3: return [2 /*return*/, (_a.sent()).data];
|
|
211
|
-
case 4: return [3 /*break*/, 7];
|
|
212
|
-
case 5: return [4 /*yield*/, originalMethod.apply(undefined, args)];
|
|
213
|
-
case 6: return [2 /*return*/, (_a.sent())];
|
|
214
|
-
case 7: return [2 /*return*/];
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
});
|
|
125
|
+
else
|
|
126
|
+
return (await originalMethod.apply(undefined, args));
|
|
218
127
|
};
|
|
219
128
|
registerAction(target, descriptor);
|
|
220
|
-
descriptor.value[
|
|
129
|
+
descriptor.value[serverActionField] = serverAction;
|
|
221
130
|
return descriptor;
|
|
222
131
|
}
|
|
223
132
|
var types = Reflect.getMetadata("design:paramtypes", target, key);
|
|
224
|
-
|
|
133
|
+
let x = classHelpers.get(target.constructor);
|
|
225
134
|
if (!x) {
|
|
226
|
-
x = new
|
|
227
|
-
|
|
135
|
+
x = new ClassHelper();
|
|
136
|
+
classHelpers.set(target.constructor, x);
|
|
228
137
|
}
|
|
229
|
-
|
|
138
|
+
let mh = new MethodHelper();
|
|
230
139
|
methodHelpers.set(descriptor, mh);
|
|
231
140
|
x.methods.push(mh);
|
|
232
141
|
var originalMethod = descriptor.value;
|
|
233
|
-
|
|
234
|
-
__register
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
var _loop_1 = function (constructor) {
|
|
239
|
-
var controllerOptions = mh.classes.get(constructor);
|
|
142
|
+
let serverAction = {
|
|
143
|
+
__register(reg) {
|
|
144
|
+
let c = new Remult();
|
|
145
|
+
for (const constructor of mh.classes.keys()) {
|
|
146
|
+
let controllerOptions = mh.classes.get(constructor);
|
|
240
147
|
if (!controllerOptions.key) {
|
|
241
148
|
controllerOptions.key = c.repo(constructor).metadata.key;
|
|
242
149
|
}
|
|
243
|
-
reg(controllerOptions.key + '/' + key, options ? options.queue : false, options.allowed,
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
_d.result = _e.sent();
|
|
335
|
-
return [4 /*yield*/, controllerRef.toApiJson()];
|
|
336
|
-
case 18:
|
|
337
|
-
r_1 = (_d.fields = _e.sent(),
|
|
338
|
-
_d);
|
|
339
|
-
return [3 /*break*/, 20];
|
|
340
|
-
case 19:
|
|
341
|
-
err_5 = _e.sent();
|
|
342
|
-
throw controllerRef.catchSaveErrors(err_5);
|
|
343
|
-
case 20: return [2 /*return*/];
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
}); })];
|
|
347
|
-
case 2:
|
|
348
|
-
_a.sent();
|
|
349
|
-
res.success(r_1);
|
|
350
|
-
return [3 /*break*/, 4];
|
|
351
|
-
case 3:
|
|
352
|
-
err_3 = _a.sent();
|
|
353
|
-
res.error(err_3);
|
|
354
|
-
return [3 /*break*/, 4];
|
|
355
|
-
case 4: return [2 /*return*/];
|
|
150
|
+
reg(controllerOptions.key + '/' + key, options ? options.queue : false, options.allowed, async (d, req, res) => {
|
|
151
|
+
d.args = d.args.map(x => isCustomUndefined(x) ? undefined : x);
|
|
152
|
+
let allowed = options.allowed;
|
|
153
|
+
try {
|
|
154
|
+
let remult = req;
|
|
155
|
+
let ds = remult._dataSource;
|
|
156
|
+
let r;
|
|
157
|
+
await ds.transaction(async (ds) => {
|
|
158
|
+
remult.setDataProvider(ds);
|
|
159
|
+
d.args = await prepareReceivedArgs(types, d.args, remult, ds, res);
|
|
160
|
+
if (allEntities.includes(constructor)) {
|
|
161
|
+
let repo = remult.repo(constructor);
|
|
162
|
+
let y;
|
|
163
|
+
if (d.rowInfo.isNewRow) {
|
|
164
|
+
y = repo.create();
|
|
165
|
+
let rowHelper = repo.getEntityRef(y);
|
|
166
|
+
await rowHelper._updateEntityBasedOnApi(d.rowInfo.data);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
let rows = await repo.find({
|
|
170
|
+
where: {
|
|
171
|
+
...repo.metadata.idMetadata.getIdFilter(d.rowInfo.id),
|
|
172
|
+
$and: [repo.metadata.options.apiPrefilter]
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
if (rows.length != 1)
|
|
176
|
+
throw new Error("not found or too many matches");
|
|
177
|
+
y = rows[0];
|
|
178
|
+
await repo.getEntityRef(y)._updateEntityBasedOnApi(d.rowInfo.data);
|
|
179
|
+
}
|
|
180
|
+
if (!remult.isAllowedForInstance(y, allowed))
|
|
181
|
+
throw new ForbiddenError();
|
|
182
|
+
let defs = getEntityRef(y);
|
|
183
|
+
await defs.__validateEntity();
|
|
184
|
+
try {
|
|
185
|
+
r = {
|
|
186
|
+
result: await originalMethod.apply(y, d.args),
|
|
187
|
+
rowInfo: {
|
|
188
|
+
data: await defs.toApiJson(),
|
|
189
|
+
isNewRow: defs.isNew(),
|
|
190
|
+
wasChanged: defs.wasChanged(),
|
|
191
|
+
id: defs.getOriginalId()
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
catch (err) {
|
|
196
|
+
throw defs.catchSaveErrors(err);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
let y = new constructor(remult, ds);
|
|
201
|
+
let controllerRef = getControllerRef(y, remult);
|
|
202
|
+
await controllerRef._updateEntityBasedOnApi(d.fields);
|
|
203
|
+
if (!remult.isAllowedForInstance(y, allowed))
|
|
204
|
+
throw new ForbiddenError();
|
|
205
|
+
await controllerRef.__validateEntity();
|
|
206
|
+
try {
|
|
207
|
+
r = {
|
|
208
|
+
result: await originalMethod.apply(y, d.args),
|
|
209
|
+
fields: await controllerRef.toApiJson()
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
catch (err) {
|
|
213
|
+
throw controllerRef.catchSaveErrors(err);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
res.success(r);
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
res.error(err);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
descriptor.value = async function (...args) {
|
|
227
|
+
if (!actionInfo.runningOnServer) {
|
|
228
|
+
let self = this;
|
|
229
|
+
args = prepareArgsToSend(types, args);
|
|
230
|
+
if (allEntities.includes(target.constructor)) {
|
|
231
|
+
let defs = getEntityRef(self);
|
|
232
|
+
await defs.__validateEntity();
|
|
233
|
+
let classOptions = mh.classes.get(self.constructor);
|
|
234
|
+
if (!classOptions.key) {
|
|
235
|
+
classOptions.key = defs.repository.metadata.key + "_methods";
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
let r = await (new class extends Action {
|
|
239
|
+
async execute(a, b) {
|
|
240
|
+
throw ('should get here');
|
|
356
241
|
}
|
|
357
|
-
})
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
242
|
+
}(classOptions.key + "/" + key, options ? options.queue : false, options.allowed).run({
|
|
243
|
+
args,
|
|
244
|
+
rowInfo: {
|
|
245
|
+
data: await defs.toApiJson(),
|
|
246
|
+
isNewRow: defs.isNew(),
|
|
247
|
+
wasChanged: defs.wasChanged(),
|
|
248
|
+
id: defs.getOriginalId()
|
|
249
|
+
}
|
|
250
|
+
}));
|
|
251
|
+
await defs._updateEntityBasedOnApi(r.rowInfo.data);
|
|
252
|
+
return r.result;
|
|
253
|
+
}
|
|
254
|
+
catch (err) {
|
|
255
|
+
defs.catchSaveErrors(err);
|
|
256
|
+
throw err;
|
|
364
257
|
}
|
|
365
258
|
}
|
|
366
|
-
|
|
367
|
-
|
|
259
|
+
else {
|
|
260
|
+
let defs = getControllerRef(self, undefined);
|
|
368
261
|
try {
|
|
369
|
-
|
|
262
|
+
await defs.__validateEntity();
|
|
263
|
+
let r = await (new class extends Action {
|
|
264
|
+
async execute(a, b) {
|
|
265
|
+
throw ('should get here');
|
|
266
|
+
}
|
|
267
|
+
}(mh.classes.get(this.constructor).key + "/" + key, options ? options.queue : false, options.allowed).run({
|
|
268
|
+
args,
|
|
269
|
+
fields: await defs.toApiJson()
|
|
270
|
+
}));
|
|
271
|
+
await defs._updateEntityBasedOnApi(r.fields);
|
|
272
|
+
return r.result;
|
|
273
|
+
}
|
|
274
|
+
catch (e) {
|
|
275
|
+
throw defs.catchSaveErrors(e);
|
|
370
276
|
}
|
|
371
|
-
finally { if (e_1) throw e_1.error; }
|
|
372
277
|
}
|
|
373
278
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
var args = [];
|
|
377
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
378
|
-
args[_i] = arguments[_i];
|
|
379
|
-
}
|
|
380
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
381
|
-
var self_1, defs, classOptions_1, r, _a, _b, err_6, defs, r, _c, _d, e_2;
|
|
382
|
-
var _e, _f, _g;
|
|
383
|
-
return tslib_1.__generator(this, function (_h) {
|
|
384
|
-
switch (_h.label) {
|
|
385
|
-
case 0:
|
|
386
|
-
if (!!exports.actionInfo.runningOnServer) return [3 /*break*/, 16];
|
|
387
|
-
self_1 = this;
|
|
388
|
-
args = prepareArgsToSend(types, args);
|
|
389
|
-
if (!context_1.allEntities.includes(target.constructor)) return [3 /*break*/, 8];
|
|
390
|
-
defs = remult3_1.getEntityRef(self_1);
|
|
391
|
-
return [4 /*yield*/, defs.__validateEntity()];
|
|
392
|
-
case 1:
|
|
393
|
-
_h.sent();
|
|
394
|
-
classOptions_1 = mh.classes.get(self_1.constructor);
|
|
395
|
-
if (!classOptions_1.key) {
|
|
396
|
-
classOptions_1.key = defs.repository.metadata.key + "_methods";
|
|
397
|
-
}
|
|
398
|
-
_h.label = 2;
|
|
399
|
-
case 2:
|
|
400
|
-
_h.trys.push([2, 6, , 7]);
|
|
401
|
-
_b = (_a = new /** @class */ (function (_super) {
|
|
402
|
-
tslib_1.__extends(class_1, _super);
|
|
403
|
-
function class_1() {
|
|
404
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
405
|
-
}
|
|
406
|
-
class_1.prototype.execute = function (a, b) {
|
|
407
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
408
|
-
return tslib_1.__generator(this, function (_a) {
|
|
409
|
-
throw ('should get here');
|
|
410
|
-
});
|
|
411
|
-
});
|
|
412
|
-
};
|
|
413
|
-
return class_1;
|
|
414
|
-
}(Action))(classOptions_1.key + "/" + key, options ? options.queue : false, options.allowed)).run;
|
|
415
|
-
_e = {
|
|
416
|
-
args: args
|
|
417
|
-
};
|
|
418
|
-
_f = {};
|
|
419
|
-
return [4 /*yield*/, defs.toApiJson()];
|
|
420
|
-
case 3: return [4 /*yield*/, (_b.apply(_a, [(_e.rowInfo = (_f.data = _h.sent(),
|
|
421
|
-
_f.isNewRow = defs.isNew(),
|
|
422
|
-
_f.wasChanged = defs.wasChanged(),
|
|
423
|
-
_f.id = defs.getOriginalId(),
|
|
424
|
-
_f),
|
|
425
|
-
_e)]))];
|
|
426
|
-
case 4:
|
|
427
|
-
r = _h.sent();
|
|
428
|
-
return [4 /*yield*/, defs._updateEntityBasedOnApi(r.rowInfo.data)];
|
|
429
|
-
case 5:
|
|
430
|
-
_h.sent();
|
|
431
|
-
return [2 /*return*/, r.result];
|
|
432
|
-
case 6:
|
|
433
|
-
err_6 = _h.sent();
|
|
434
|
-
defs.catchSaveErrors(err_6);
|
|
435
|
-
throw err_6;
|
|
436
|
-
case 7: return [3 /*break*/, 15];
|
|
437
|
-
case 8:
|
|
438
|
-
defs = remult3_1.getControllerRef(self_1, undefined);
|
|
439
|
-
_h.label = 9;
|
|
440
|
-
case 9:
|
|
441
|
-
_h.trys.push([9, 14, , 15]);
|
|
442
|
-
return [4 /*yield*/, defs.__validateEntity()];
|
|
443
|
-
case 10:
|
|
444
|
-
_h.sent();
|
|
445
|
-
_d = (_c = new /** @class */ (function (_super) {
|
|
446
|
-
tslib_1.__extends(class_2, _super);
|
|
447
|
-
function class_2() {
|
|
448
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
449
|
-
}
|
|
450
|
-
class_2.prototype.execute = function (a, b) {
|
|
451
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
452
|
-
return tslib_1.__generator(this, function (_a) {
|
|
453
|
-
throw ('should get here');
|
|
454
|
-
});
|
|
455
|
-
});
|
|
456
|
-
};
|
|
457
|
-
return class_2;
|
|
458
|
-
}(Action))(mh.classes.get(this.constructor).key + "/" + key, options ? options.queue : false, options.allowed)).run;
|
|
459
|
-
_g = {
|
|
460
|
-
args: args
|
|
461
|
-
};
|
|
462
|
-
return [4 /*yield*/, defs.toApiJson()];
|
|
463
|
-
case 11: return [4 /*yield*/, (_d.apply(_c, [(_g.fields = _h.sent(),
|
|
464
|
-
_g)]))];
|
|
465
|
-
case 12:
|
|
466
|
-
r = _h.sent();
|
|
467
|
-
return [4 /*yield*/, defs._updateEntityBasedOnApi(r.fields)];
|
|
468
|
-
case 13:
|
|
469
|
-
_h.sent();
|
|
470
|
-
return [2 /*return*/, r.result];
|
|
471
|
-
case 14:
|
|
472
|
-
e_2 = _h.sent();
|
|
473
|
-
throw defs.catchSaveErrors(e_2);
|
|
474
|
-
case 15: return [3 /*break*/, 18];
|
|
475
|
-
case 16: return [4 /*yield*/, originalMethod.apply(this, args)];
|
|
476
|
-
case 17: return [2 /*return*/, (_h.sent())];
|
|
477
|
-
case 18: return [2 /*return*/];
|
|
478
|
-
}
|
|
479
|
-
});
|
|
480
|
-
});
|
|
279
|
+
else
|
|
280
|
+
return (await originalMethod.apply(this, args));
|
|
481
281
|
};
|
|
482
282
|
registerAction(target.constructor, descriptor);
|
|
483
|
-
descriptor.value[
|
|
283
|
+
descriptor.value[serverActionField] = serverAction;
|
|
484
284
|
return descriptor;
|
|
485
285
|
};
|
|
486
286
|
}
|
|
487
|
-
|
|
488
|
-
var customUndefined = {
|
|
287
|
+
const customUndefined = {
|
|
489
288
|
_isUndefined: true
|
|
490
289
|
};
|
|
491
290
|
function registerAction(target, descriptor) {
|
|
492
|
-
(target[
|
|
493
|
-
|
|
291
|
+
(target[classBackendMethodsArray] || (target[classBackendMethodsArray] = [])).push(descriptor.value);
|
|
292
|
+
actionInfo.allActions.push(descriptor.value);
|
|
494
293
|
}
|
|
495
294
|
function isCustomUndefined(x) {
|
|
496
295
|
return x && x._isUndefined;
|
|
497
296
|
}
|
|
498
|
-
|
|
499
|
-
|
|
297
|
+
export class ProgressListener {
|
|
298
|
+
constructor(res) {
|
|
500
299
|
this.res = res;
|
|
501
300
|
}
|
|
502
|
-
|
|
301
|
+
progress(progress) {
|
|
503
302
|
this.res.progress(progress);
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
exports.ProgressListener = ProgressListener;
|
|
508
|
-
function prepareArgsToSend(types, args) {
|
|
509
|
-
var e_3, _a;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
export function prepareArgsToSend(types, args) {
|
|
510
306
|
if (types) {
|
|
511
|
-
for (
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
else if (paramType == type) {
|
|
519
|
-
args[index] = undefined;
|
|
520
|
-
}
|
|
307
|
+
for (let index = 0; index < types.length; index++) {
|
|
308
|
+
const paramType = types[index];
|
|
309
|
+
for (const type of [Remult, SqlDatabase]) {
|
|
310
|
+
if (args[index] instanceof type)
|
|
311
|
+
args[index] = undefined;
|
|
312
|
+
else if (paramType == type) {
|
|
313
|
+
args[index] = undefined;
|
|
521
314
|
}
|
|
522
315
|
}
|
|
523
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
524
|
-
finally {
|
|
525
|
-
try {
|
|
526
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
527
|
-
}
|
|
528
|
-
finally { if (e_3) throw e_3.error; }
|
|
529
|
-
}
|
|
530
316
|
if (args[index] != undefined) {
|
|
531
|
-
|
|
532
|
-
x =
|
|
317
|
+
let x = { valueType: paramType };
|
|
318
|
+
x = decorateColumnSettings(x, new Remult());
|
|
533
319
|
if (x.valueConverter)
|
|
534
320
|
args[index] = x.valueConverter.toJson(args[index]);
|
|
535
|
-
|
|
321
|
+
let eo = getEntitySettings(paramType, false);
|
|
536
322
|
if (eo != null) {
|
|
537
|
-
|
|
323
|
+
let rh = getEntityRef(args[index]);
|
|
538
324
|
args[index] = rh.getId();
|
|
539
325
|
}
|
|
540
326
|
}
|
|
541
327
|
}
|
|
542
328
|
}
|
|
543
|
-
return args.map(
|
|
329
|
+
return args.map(x => x !== undefined ? x : customUndefined);
|
|
544
330
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
args[index] = undefined;
|
|
556
|
-
}
|
|
557
|
-
if (!types) return [3 /*break*/, 7];
|
|
558
|
-
i = 0;
|
|
559
|
-
_c.label = 1;
|
|
560
|
-
case 1:
|
|
561
|
-
if (!(i < types.length)) return [3 /*break*/, 7];
|
|
562
|
-
if (args.length < i) {
|
|
563
|
-
args.push(undefined);
|
|
564
|
-
}
|
|
565
|
-
if (!(types[i] == context_1.Remult || types[i] == context_1.Remult)) return [3 /*break*/, 2];
|
|
566
|
-
args[i] = remult;
|
|
567
|
-
return [3 /*break*/, 6];
|
|
568
|
-
case 2:
|
|
569
|
-
if (!(types[i] == sql_database_1.SqlDatabase && ds)) return [3 /*break*/, 3];
|
|
570
|
-
args[i] = ds;
|
|
571
|
-
return [3 /*break*/, 6];
|
|
572
|
-
case 3:
|
|
573
|
-
if (!(types[i] == ProgressListener)) return [3 /*break*/, 4];
|
|
574
|
-
args[i] = new ProgressListener(res);
|
|
575
|
-
return [3 /*break*/, 6];
|
|
576
|
-
case 4:
|
|
577
|
-
x = { valueType: types[i] };
|
|
578
|
-
x = remult3_1.decorateColumnSettings(x, remult);
|
|
579
|
-
if (x.valueConverter)
|
|
580
|
-
args[i] = x.valueConverter.fromJson(args[i]);
|
|
581
|
-
eo = remult3_1.getEntitySettings(types[i], false);
|
|
582
|
-
if (!(eo != null)) return [3 /*break*/, 6];
|
|
583
|
-
if (!!(args[i] === null || args[i] === undefined)) return [3 /*break*/, 6];
|
|
584
|
-
_a = args;
|
|
585
|
-
_b = i;
|
|
586
|
-
return [4 /*yield*/, remult.repo(types[i]).findId(args[i])];
|
|
587
|
-
case 5:
|
|
588
|
-
_a[_b] = _c.sent();
|
|
589
|
-
_c.label = 6;
|
|
590
|
-
case 6:
|
|
591
|
-
i++;
|
|
592
|
-
return [3 /*break*/, 1];
|
|
593
|
-
case 7: return [2 /*return*/, args];
|
|
331
|
+
export async function prepareReceivedArgs(types, args, remult, ds, res) {
|
|
332
|
+
for (let index = 0; index < args.length; index++) {
|
|
333
|
+
const element = args[index];
|
|
334
|
+
if (isCustomUndefined(element))
|
|
335
|
+
args[index] = undefined;
|
|
336
|
+
}
|
|
337
|
+
if (types)
|
|
338
|
+
for (let i = 0; i < types.length; i++) {
|
|
339
|
+
if (args.length < i) {
|
|
340
|
+
args.push(undefined);
|
|
594
341
|
}
|
|
595
|
-
|
|
596
|
-
|
|
342
|
+
if (types[i] == Remult || types[i] == Remult) {
|
|
343
|
+
args[i] = remult;
|
|
344
|
+
}
|
|
345
|
+
else if (types[i] == SqlDatabase && ds) {
|
|
346
|
+
args[i] = ds;
|
|
347
|
+
}
|
|
348
|
+
else if (types[i] == ProgressListener) {
|
|
349
|
+
args[i] = new ProgressListener(res);
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
let x = { valueType: types[i] };
|
|
353
|
+
x = decorateColumnSettings(x, remult);
|
|
354
|
+
if (x.valueConverter)
|
|
355
|
+
args[i] = x.valueConverter.fromJson(args[i]);
|
|
356
|
+
let eo = getEntitySettings(types[i], false);
|
|
357
|
+
if (eo != null) {
|
|
358
|
+
if (!(args[i] === null || args[i] === undefined))
|
|
359
|
+
args[i] = await remult.repo(types[i]).findId(args[i]);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return args;
|
|
597
364
|
}
|
|
598
|
-
|
|
599
|
-
exports.classBackendMethodsArray = Symbol('classBackendMethodsArray');
|
|
365
|
+
export const classBackendMethodsArray = Symbol('classBackendMethodsArray');
|