remult 0.14.3 → 0.14.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assign.js +1 -5
- package/classType.js +1 -2
- package/graphql.js +84 -146
- package/index.d.ts +1 -1
- package/index.js +25 -71
- 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/server/expressBridge.js
CHANGED
|
@@ -1,77 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var context_1 = require("../src/context");
|
|
12
|
-
var remult3_1 = require("../src/remult3");
|
|
13
|
-
function remultMiddlewareBase(app, options) {
|
|
14
|
-
var _this = this;
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Remult, IdEntity, Entity, Fields, JsonDataProvider } from '../';
|
|
3
|
+
import { registerActionsOnServer } from './register-actions-on-server';
|
|
4
|
+
import { registerEntitiesOnServer } from './register-entities-on-server';
|
|
5
|
+
import { JsonEntityFileStorage } from './JsonEntityFileStorage';
|
|
6
|
+
import { Action, actionInfo } from '../src/server-action';
|
|
7
|
+
import { DataApi, serializeError } from '../src/data-api';
|
|
8
|
+
import { allEntities } from '../src/context';
|
|
9
|
+
import { getEntityKey } from '../src/remult3';
|
|
10
|
+
export function remultMiddlewareBase(app, options) {
|
|
15
11
|
if (!options) {
|
|
16
12
|
options = {};
|
|
17
13
|
}
|
|
18
|
-
|
|
14
|
+
actionInfo.runningOnServer = true;
|
|
19
15
|
if (options.defaultGetLimit) {
|
|
20
|
-
|
|
16
|
+
DataApi.defaultGetLimit = options.defaultGetLimit;
|
|
21
17
|
}
|
|
22
18
|
if (!options.queueStorage) {
|
|
23
19
|
options.queueStorage = new InMemoryQueueStorage();
|
|
24
20
|
}
|
|
25
|
-
|
|
21
|
+
let dataProvider;
|
|
26
22
|
if (typeof options.dataProvider === "function") {
|
|
27
23
|
dataProvider = options.dataProvider();
|
|
28
24
|
}
|
|
29
25
|
else
|
|
30
26
|
dataProvider = Promise.resolve(options.dataProvider);
|
|
31
|
-
dataProvider = dataProvider.then(
|
|
27
|
+
dataProvider = dataProvider.then(dp => {
|
|
32
28
|
if (dp)
|
|
33
29
|
return dp;
|
|
34
|
-
return new
|
|
30
|
+
return new JsonDataProvider(new JsonEntityFileStorage('./db'));
|
|
35
31
|
});
|
|
36
32
|
if (options.initApi) {
|
|
37
|
-
dataProvider = dataProvider.then(
|
|
38
|
-
var remult;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
remult = new __1.Remult(dp);
|
|
43
|
-
return [4 /*yield*/, options.initApi(remult)];
|
|
44
|
-
case 1:
|
|
45
|
-
_a.sent();
|
|
46
|
-
return [2 /*return*/, dp];
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}); });
|
|
33
|
+
dataProvider = dataProvider.then(async (dp) => {
|
|
34
|
+
var remult = new Remult(dp);
|
|
35
|
+
await options.initApi(remult);
|
|
36
|
+
return dp;
|
|
37
|
+
});
|
|
50
38
|
}
|
|
51
|
-
|
|
39
|
+
let bridge = new ExpressBridge(app, new inProcessQueueHandler(options.queueStorage), options.initRequest, dataProvider);
|
|
52
40
|
if (options.logApiEndPoints !== undefined)
|
|
53
41
|
bridge.logApiEndPoints = options.logApiEndPoints;
|
|
54
42
|
if (options.rootPath === undefined)
|
|
55
|
-
options.rootPath =
|
|
56
|
-
|
|
43
|
+
options.rootPath = Remult.apiBaseUrl;
|
|
44
|
+
let apiArea = bridge.addArea(options.rootPath);
|
|
57
45
|
if (!options.disableAutoApi) {
|
|
58
|
-
|
|
46
|
+
let actions = [];
|
|
59
47
|
if (options.entities)
|
|
60
|
-
actions.push
|
|
48
|
+
actions.push(...options.entities);
|
|
61
49
|
if (options.controllers)
|
|
62
|
-
actions.push
|
|
63
|
-
|
|
64
|
-
|
|
50
|
+
actions.push(...options.controllers);
|
|
51
|
+
registerActionsOnServer(apiArea, actions);
|
|
52
|
+
registerEntitiesOnServer(apiArea, options.entities);
|
|
65
53
|
}
|
|
66
54
|
return Object.assign(app, {
|
|
67
|
-
getRemult:
|
|
68
|
-
openApiDoc:
|
|
69
|
-
addArea:
|
|
55
|
+
getRemult: (req) => bridge.getRemult(req),
|
|
56
|
+
openApiDoc: (options) => bridge.openApiDoc(options),
|
|
57
|
+
addArea: x => bridge.addArea(x)
|
|
70
58
|
});
|
|
71
59
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
function ExpressBridge(app, queue, initRequest, dataProvider) {
|
|
60
|
+
class ExpressBridge {
|
|
61
|
+
constructor(app, queue, initRequest, dataProvider) {
|
|
75
62
|
this.app = app;
|
|
76
63
|
this.queue = queue;
|
|
77
64
|
this.initRequest = initRequest;
|
|
@@ -80,12 +67,11 @@ var ExpressBridge = /** @class */ (function () {
|
|
|
80
67
|
this.backendMethodsOpenApi = [];
|
|
81
68
|
this.logApiEndPoints = true;
|
|
82
69
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
var r = new __1.Remult();
|
|
70
|
+
openApiDoc(options) {
|
|
71
|
+
let r = new Remult();
|
|
86
72
|
if (!options.version)
|
|
87
73
|
options.version = "1.0.0";
|
|
88
|
-
|
|
74
|
+
let spec = {
|
|
89
75
|
info: { title: options.title, version: options.version },
|
|
90
76
|
openapi: "3.0.0",
|
|
91
77
|
//swagger: "2.0",
|
|
@@ -101,7 +87,7 @@ var ExpressBridge = /** @class */ (function () {
|
|
|
101
87
|
},
|
|
102
88
|
paths: {}
|
|
103
89
|
};
|
|
104
|
-
|
|
90
|
+
let validationError = {
|
|
105
91
|
"400": {
|
|
106
92
|
"description": "Error: Bad Request",
|
|
107
93
|
"content": {
|
|
@@ -113,86 +99,75 @@ var ExpressBridge = /** @class */ (function () {
|
|
|
113
99
|
}
|
|
114
100
|
}
|
|
115
101
|
};
|
|
116
|
-
|
|
102
|
+
let security = {
|
|
117
103
|
"security": [
|
|
118
104
|
{
|
|
119
105
|
"bearerAuth": []
|
|
120
106
|
}
|
|
121
107
|
]
|
|
122
108
|
};
|
|
123
|
-
|
|
109
|
+
let secureBase = (condition, def, item) => {
|
|
124
110
|
if (condition === undefined)
|
|
125
111
|
condition = def;
|
|
126
112
|
if (condition != false) {
|
|
127
113
|
if (condition != true) {
|
|
128
|
-
item =
|
|
114
|
+
item = { ...item, ...security };
|
|
129
115
|
item.responses["403"] = { description: "forbidden" };
|
|
130
116
|
}
|
|
131
117
|
return item;
|
|
132
118
|
}
|
|
133
119
|
};
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
var parameters = [];
|
|
120
|
+
for (const e of allEntities) {
|
|
121
|
+
let meta = r.repo(e).metadata;
|
|
122
|
+
let key = getEntityKey(e);
|
|
123
|
+
let parameters = [];
|
|
139
124
|
if (key) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
type: type
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
171
|
-
finally {
|
|
172
|
-
try {
|
|
173
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
174
|
-
}
|
|
175
|
-
finally { if (e_3) throw e_3.error; }
|
|
125
|
+
let properties = {};
|
|
126
|
+
for (const f of meta.fields) {
|
|
127
|
+
let type = f.valueType == String ? "string" :
|
|
128
|
+
f.valueType == Boolean ? "boolean" :
|
|
129
|
+
f.valueType == Date ? "string" :
|
|
130
|
+
f.valueType == Number ? "number" :
|
|
131
|
+
"object";
|
|
132
|
+
properties[f.key] = {
|
|
133
|
+
type
|
|
134
|
+
};
|
|
135
|
+
parameters.push({
|
|
136
|
+
"name": f.key,
|
|
137
|
+
"in": "query",
|
|
138
|
+
"description": "filter equal to " + f.key,
|
|
139
|
+
"required": false,
|
|
140
|
+
"style": "simple",
|
|
141
|
+
type
|
|
142
|
+
});
|
|
143
|
+
parameters.push({
|
|
144
|
+
"name": f.key + "_ne",
|
|
145
|
+
"in": "query",
|
|
146
|
+
"description": "filter not equal to " + f.key,
|
|
147
|
+
"required": false,
|
|
148
|
+
"style": "simple",
|
|
149
|
+
type
|
|
150
|
+
});
|
|
176
151
|
}
|
|
177
152
|
spec.components.schemas[key] = {
|
|
178
153
|
type: "object",
|
|
179
|
-
properties
|
|
154
|
+
properties
|
|
180
155
|
};
|
|
181
|
-
|
|
156
|
+
let definition = {
|
|
182
157
|
"$ref": "#/components/schemas/" + key
|
|
183
158
|
};
|
|
184
|
-
|
|
159
|
+
let secure = (condition, def, item) => {
|
|
185
160
|
item.tags = [meta.key];
|
|
186
161
|
if (condition === undefined)
|
|
187
162
|
condition = meta.options.allowApiCrud;
|
|
188
163
|
return secureBase(condition, def, item);
|
|
189
164
|
};
|
|
190
|
-
|
|
191
|
-
|
|
165
|
+
let apiPath = spec.paths['/api/' + key] = {};
|
|
166
|
+
let apiPathWithId = spec.paths['/api/' + key + "/{id}"] = {};
|
|
192
167
|
//https://github.com/2fd/open-api.d.ts
|
|
193
168
|
apiPath.get = secure(meta.options.allowApiRead, true, {
|
|
194
169
|
description: "return an array of " + key + ". supports filter operators. For more info on filtering [see this article](https://remult.dev/docs/rest-api.html#filter)",
|
|
195
|
-
parameters:
|
|
170
|
+
parameters: [{
|
|
196
171
|
"name": "_limit",
|
|
197
172
|
"in": "query",
|
|
198
173
|
"description": "limit the number of returned rows, default 100",
|
|
@@ -220,7 +195,7 @@ var ExpressBridge = /** @class */ (function () {
|
|
|
220
195
|
"description": "the sort order to user for the columns in `_sort`",
|
|
221
196
|
"required": false,
|
|
222
197
|
"schema": { "type": "string" }
|
|
223
|
-
}
|
|
198
|
+
}, ...parameters],
|
|
224
199
|
responses: {
|
|
225
200
|
"200": {
|
|
226
201
|
"description": "returns an array of " + key,
|
|
@@ -235,14 +210,14 @@ var ExpressBridge = /** @class */ (function () {
|
|
|
235
210
|
},
|
|
236
211
|
}
|
|
237
212
|
});
|
|
238
|
-
|
|
213
|
+
let idParameter = {
|
|
239
214
|
"name": "id",
|
|
240
215
|
"in": "path",
|
|
241
216
|
"description": "id of " + key,
|
|
242
217
|
"required": true,
|
|
243
218
|
"schema": { "type": "string" },
|
|
244
219
|
};
|
|
245
|
-
|
|
220
|
+
let itemInBody = {
|
|
246
221
|
"requestBody": {
|
|
247
222
|
"content": {
|
|
248
223
|
"application/json": {
|
|
@@ -253,10 +228,13 @@ var ExpressBridge = /** @class */ (function () {
|
|
|
253
228
|
}
|
|
254
229
|
}
|
|
255
230
|
};
|
|
256
|
-
apiPath.post = secure(meta.options.allowApiInsert, false,
|
|
231
|
+
apiPath.post = secure(meta.options.allowApiInsert, false, {
|
|
257
232
|
//"summary": "insert a " + key,
|
|
258
233
|
//"description": "insert a " + key,
|
|
259
|
-
"produces": ["application/json"]
|
|
234
|
+
"produces": ["application/json"],
|
|
235
|
+
...itemInBody,
|
|
236
|
+
"responses": {
|
|
237
|
+
"201": {
|
|
260
238
|
"description": "Created",
|
|
261
239
|
"content": {
|
|
262
240
|
"application/json": {
|
|
@@ -265,7 +243,10 @@ var ExpressBridge = /** @class */ (function () {
|
|
|
265
243
|
}
|
|
266
244
|
}
|
|
267
245
|
}
|
|
268
|
-
}
|
|
246
|
+
},
|
|
247
|
+
...validationError
|
|
248
|
+
}
|
|
249
|
+
});
|
|
269
250
|
apiPathWithId.get = secure(meta.options.allowApiRead, true, {
|
|
270
251
|
parameters: [idParameter],
|
|
271
252
|
responses: {
|
|
@@ -281,12 +262,16 @@ var ExpressBridge = /** @class */ (function () {
|
|
|
281
262
|
},
|
|
282
263
|
}
|
|
283
264
|
});
|
|
284
|
-
apiPathWithId.put = secure(meta.options.allowApiUpdate, false,
|
|
265
|
+
apiPathWithId.put = secure(meta.options.allowApiUpdate, false, {
|
|
285
266
|
//"summary": "Update a " + key,
|
|
286
267
|
//"description": "Update a " + key,
|
|
287
|
-
"produces": ["application/json"],
|
|
268
|
+
"produces": ["application/json"],
|
|
269
|
+
"parameters": [
|
|
288
270
|
idParameter
|
|
289
|
-
]
|
|
271
|
+
],
|
|
272
|
+
...itemInBody,
|
|
273
|
+
"responses": {
|
|
274
|
+
"200": {
|
|
290
275
|
"description": "successful operation",
|
|
291
276
|
"content": {
|
|
292
277
|
"application/json": {
|
|
@@ -295,7 +280,10 @@ var ExpressBridge = /** @class */ (function () {
|
|
|
295
280
|
}
|
|
296
281
|
}
|
|
297
282
|
}
|
|
298
|
-
}
|
|
283
|
+
},
|
|
284
|
+
...validationError
|
|
285
|
+
}
|
|
286
|
+
});
|
|
299
287
|
apiPathWithId.delete = secure(meta.options.allowApiDelete, false, {
|
|
300
288
|
// "summary": "Delete a " + key,
|
|
301
289
|
// "description": "Delete a " + key,
|
|
@@ -303,72 +291,55 @@ var ExpressBridge = /** @class */ (function () {
|
|
|
303
291
|
"parameters": [
|
|
304
292
|
idParameter
|
|
305
293
|
],
|
|
306
|
-
"responses":
|
|
294
|
+
"responses": {
|
|
295
|
+
"204": {
|
|
307
296
|
"description": "Deleted"
|
|
308
|
-
}
|
|
297
|
+
},
|
|
298
|
+
...validationError
|
|
299
|
+
}
|
|
309
300
|
});
|
|
310
301
|
}
|
|
311
|
-
};
|
|
312
|
-
try {
|
|
313
|
-
for (var allEntities_1 = tslib_1.__values(context_1.allEntities), allEntities_1_1 = allEntities_1.next(); !allEntities_1_1.done; allEntities_1_1 = allEntities_1.next()) {
|
|
314
|
-
var e = allEntities_1_1.value;
|
|
315
|
-
_loop_1(e);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
319
|
-
finally {
|
|
320
|
-
try {
|
|
321
|
-
if (allEntities_1_1 && !allEntities_1_1.done && (_a = allEntities_1.return)) _a.call(allEntities_1);
|
|
322
|
-
}
|
|
323
|
-
finally { if (e_1) throw e_1.error; }
|
|
324
302
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
"
|
|
332
|
-
|
|
303
|
+
for (const b of this.backendMethodsOpenApi) {
|
|
304
|
+
spec.paths[b.path] = {
|
|
305
|
+
post: secureBase(b.allowed, false, {
|
|
306
|
+
"produces": ["application/json"],
|
|
307
|
+
"tags": [b.tag],
|
|
308
|
+
"requestBody": {
|
|
309
|
+
"content": {
|
|
310
|
+
"application/json": {
|
|
311
|
+
"schema": {
|
|
312
|
+
"type": "object",
|
|
313
|
+
properties: {
|
|
314
|
+
"args": {
|
|
315
|
+
"type": "array",
|
|
316
|
+
"items": { "type": "string" }
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
"responses": {
|
|
324
|
+
"201": {
|
|
325
|
+
"description": "Created",
|
|
333
326
|
"content": {
|
|
334
327
|
"application/json": {
|
|
335
328
|
"schema": {
|
|
336
329
|
"type": "object",
|
|
337
330
|
properties: {
|
|
338
|
-
"
|
|
339
|
-
"type": "
|
|
340
|
-
"items": { "type": "string" }
|
|
331
|
+
"data": {
|
|
332
|
+
"type": "object"
|
|
341
333
|
}
|
|
342
334
|
}
|
|
343
335
|
}
|
|
344
336
|
}
|
|
345
337
|
}
|
|
346
338
|
},
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
"schema": {
|
|
352
|
-
"type": "object",
|
|
353
|
-
properties: {
|
|
354
|
-
"data": {
|
|
355
|
-
"type": "object"
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
} }, validationError)
|
|
362
|
-
})
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
367
|
-
finally {
|
|
368
|
-
try {
|
|
369
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
370
|
-
}
|
|
371
|
-
finally { if (e_2) throw e_2.error; }
|
|
339
|
+
...validationError
|
|
340
|
+
}
|
|
341
|
+
})
|
|
342
|
+
};
|
|
372
343
|
}
|
|
373
344
|
spec.components.schemas["InvalidResponse"] = {
|
|
374
345
|
"type": "object",
|
|
@@ -382,472 +353,315 @@ var ExpressBridge = /** @class */ (function () {
|
|
|
382
353
|
}
|
|
383
354
|
};
|
|
384
355
|
return spec;
|
|
385
|
-
}
|
|
386
|
-
|
|
356
|
+
}
|
|
357
|
+
addArea(rootUrl) {
|
|
387
358
|
var r = new SiteArea(this, this.app, rootUrl, this.logApiEndPoints);
|
|
388
359
|
if (!this.firstArea) {
|
|
389
360
|
this.firstArea = r;
|
|
390
361
|
}
|
|
391
362
|
return r;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
return
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
};
|
|
400
|
-
return ExpressBridge;
|
|
401
|
-
}());
|
|
402
|
-
var SiteArea = /** @class */ (function () {
|
|
403
|
-
function SiteArea(bridge, app, rootUrl, logApiEndpoints) {
|
|
363
|
+
}
|
|
364
|
+
async getRemult(req) {
|
|
365
|
+
return this.firstArea.getRemult(req);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
export class SiteArea {
|
|
369
|
+
constructor(bridge, app, rootUrl, logApiEndpoints) {
|
|
404
370
|
this.bridge = bridge;
|
|
405
371
|
this.app = app;
|
|
406
372
|
this.rootUrl = rootUrl;
|
|
407
373
|
this.logApiEndpoints = logApiEndpoints;
|
|
408
374
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
var myRoute = this.rootUrl + '/' + key;
|
|
375
|
+
add(key, dataApiFactory) {
|
|
376
|
+
let myRoute = this.rootUrl + '/' + key;
|
|
412
377
|
if (this.logApiEndpoints)
|
|
413
378
|
console.log(myRoute);
|
|
414
379
|
this.app.route(myRoute)
|
|
415
|
-
.get(this.process(
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
return [2 /*return*/, dataApiFactory(c).put(res, '', orig.body)];
|
|
419
|
-
}); }); }))
|
|
420
|
-
.delete(this.process(function (c, req, res, orig) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
421
|
-
return [2 /*return*/, dataApiFactory(c).delete(res, '')];
|
|
422
|
-
}); }); }))
|
|
423
|
-
.post(this.process(function (c, req, res, orig) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
424
|
-
return [2 /*return*/, dataApiFactory(c).httpPost(res, req, orig.body)];
|
|
425
|
-
}); }); }));
|
|
380
|
+
.get(this.process((c, req, res) => dataApiFactory(c).httpGet(res, req))).put(this.process(async (c, req, res, orig) => dataApiFactory(c).put(res, '', orig.body)))
|
|
381
|
+
.delete(this.process(async (c, req, res, orig) => dataApiFactory(c).delete(res, '')))
|
|
382
|
+
.post(this.process(async (c, req, res, orig) => dataApiFactory(c).httpPost(res, req, orig.body)));
|
|
426
383
|
this.app.route(myRoute + '/:id')
|
|
427
384
|
//@ts-ignore
|
|
428
|
-
.get(this.process(
|
|
429
|
-
return [2 /*return*/, dataApiFactory(c).get(res, orig.params.id)];
|
|
430
|
-
}); }); }))
|
|
385
|
+
.get(this.process(async (c, req, res, orig) => dataApiFactory(c).get(res, orig.params.id)))
|
|
431
386
|
//@ts-ignore
|
|
432
|
-
.put(this.process(
|
|
433
|
-
return [2 /*return*/, dataApiFactory(c).put(res, orig.params.id, orig.body)];
|
|
434
|
-
}); }); }))
|
|
387
|
+
.put(this.process(async (c, req, res, orig) => dataApiFactory(c).put(res, orig.params.id, orig.body)))
|
|
435
388
|
//@ts-ignore
|
|
436
|
-
.delete(this.process(
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
user = req['auth'];
|
|
458
|
-
if (user)
|
|
459
|
-
remult.setUser(user);
|
|
460
|
-
}
|
|
461
|
-
if (!this.bridge.initRequest) return [3 /*break*/, 3];
|
|
462
|
-
return [4 /*yield*/, this.bridge.initRequest(remult, req)];
|
|
463
|
-
case 2:
|
|
464
|
-
_c.sent();
|
|
465
|
-
_c.label = 3;
|
|
466
|
-
case 3:
|
|
467
|
-
what(remult, myReq, myRes, req);
|
|
468
|
-
return [2 /*return*/];
|
|
469
|
-
}
|
|
470
|
-
});
|
|
471
|
-
}); };
|
|
472
|
-
};
|
|
389
|
+
.delete(this.process(async (c, req, res, orig) => dataApiFactory(c).delete(res, orig.params.id)));
|
|
390
|
+
}
|
|
391
|
+
process(what) {
|
|
392
|
+
return async (req, res) => {
|
|
393
|
+
let myReq = new ExpressRequestBridgeToDataApiRequest(req);
|
|
394
|
+
let myRes = new ExpressResponseBridgeToDataApiResponse(res, req);
|
|
395
|
+
let remult = new Remult();
|
|
396
|
+
remult.setDataProvider(await this.bridge.dataProvider);
|
|
397
|
+
if (req) {
|
|
398
|
+
let user = req['user'];
|
|
399
|
+
if (!user)
|
|
400
|
+
user = req['auth'];
|
|
401
|
+
if (user)
|
|
402
|
+
remult.setUser(user);
|
|
403
|
+
}
|
|
404
|
+
if (this.bridge.initRequest) {
|
|
405
|
+
await this.bridge.initRequest(remult, req);
|
|
406
|
+
}
|
|
407
|
+
what(remult, myReq, myRes, req);
|
|
408
|
+
};
|
|
409
|
+
}
|
|
473
410
|
;
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
remult = c;
|
|
483
|
-
return [2 /*return*/];
|
|
484
|
-
});
|
|
485
|
-
}); })(req, undefined)];
|
|
486
|
-
case 1:
|
|
487
|
-
_a.sent();
|
|
488
|
-
return [2 /*return*/, remult];
|
|
489
|
-
}
|
|
490
|
-
});
|
|
491
|
-
});
|
|
492
|
-
};
|
|
493
|
-
SiteArea.prototype.initQueue = function () {
|
|
494
|
-
var _this = this;
|
|
411
|
+
async getRemult(req) {
|
|
412
|
+
let remult;
|
|
413
|
+
await this.process(async (c) => {
|
|
414
|
+
remult = c;
|
|
415
|
+
})(req, undefined);
|
|
416
|
+
return remult;
|
|
417
|
+
}
|
|
418
|
+
initQueue() {
|
|
495
419
|
this.addAction({
|
|
496
|
-
__register:
|
|
497
|
-
x(
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
if (userId != job.userId)
|
|
510
|
-
res.forbidden();
|
|
511
|
-
else
|
|
512
|
-
res.success(job.info);
|
|
513
|
-
return [2 /*return*/];
|
|
514
|
-
}
|
|
515
|
-
});
|
|
516
|
-
}); });
|
|
420
|
+
__register: x => {
|
|
421
|
+
x(Action.apiUrlForJobStatus, false, () => true, async (data, req, res) => {
|
|
422
|
+
let job = await this.bridge.queue.getJobInfo(data.queuedJobId);
|
|
423
|
+
let userId = undefined;
|
|
424
|
+
if (req?.user)
|
|
425
|
+
userId = req.user.id;
|
|
426
|
+
if (job.userId == '')
|
|
427
|
+
job.userId = undefined;
|
|
428
|
+
if (userId != job.userId)
|
|
429
|
+
res.forbidden();
|
|
430
|
+
else
|
|
431
|
+
res.success(job.info);
|
|
432
|
+
});
|
|
517
433
|
}
|
|
518
434
|
});
|
|
519
|
-
this.initQueue =
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
var split = url.split('/');
|
|
435
|
+
this.initQueue = () => { };
|
|
436
|
+
}
|
|
437
|
+
addAction(action) {
|
|
438
|
+
action.__register((url, queue, allowed, what) => {
|
|
439
|
+
let myUrl = this.rootUrl + '/' + url;
|
|
440
|
+
let tag = (() => {
|
|
441
|
+
let split = url.split('/');
|
|
527
442
|
if (split.length == 1)
|
|
528
443
|
return 'Static Backend Methods';
|
|
529
444
|
else
|
|
530
445
|
return split[0];
|
|
531
446
|
})();
|
|
532
|
-
|
|
533
|
-
if (
|
|
447
|
+
this.bridge.backendMethodsOpenApi.push({ path: myUrl, allowed, tag });
|
|
448
|
+
if (this.logApiEndpoints)
|
|
534
449
|
console.log(myUrl);
|
|
535
450
|
if (queue) {
|
|
536
|
-
|
|
537
|
-
|
|
451
|
+
this.initQueue();
|
|
452
|
+
this.bridge.queue.mapQueuedAction(myUrl, what);
|
|
538
453
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
r = (_a.queuedJobId = _b.sent(),
|
|
550
|
-
_a);
|
|
551
|
-
res.success(r);
|
|
552
|
-
return [3 /*break*/, 3];
|
|
553
|
-
case 2: return [2 /*return*/, what(orig.body, remult, res)];
|
|
554
|
-
case 3: return [2 /*return*/];
|
|
555
|
-
}
|
|
556
|
-
});
|
|
557
|
-
}); }));
|
|
454
|
+
this.app.route(myUrl).post(this.process(async (remult, req, res, orig) => {
|
|
455
|
+
if (queue) {
|
|
456
|
+
let r = {
|
|
457
|
+
queuedJobId: await this.bridge.queue.submitJob(myUrl, remult, orig.body)
|
|
458
|
+
};
|
|
459
|
+
res.success(r);
|
|
460
|
+
}
|
|
461
|
+
else
|
|
462
|
+
return what(orig.body, remult, res);
|
|
463
|
+
}));
|
|
558
464
|
});
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
var ExpressRequestBridgeToDataApiRequest = /** @class */ (function () {
|
|
564
|
-
function ExpressRequestBridgeToDataApiRequest(r) {
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
export class ExpressRequestBridgeToDataApiRequest {
|
|
468
|
+
constructor(r) {
|
|
565
469
|
this.r = r;
|
|
566
470
|
}
|
|
567
|
-
|
|
471
|
+
get(key) {
|
|
568
472
|
return this.r.query[key];
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
var ExpressResponseBridgeToDataApiResponse = /** @class */ (function () {
|
|
574
|
-
function ExpressResponseBridgeToDataApiResponse(r, req) {
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
class ExpressResponseBridgeToDataApiResponse {
|
|
476
|
+
constructor(r, req) {
|
|
575
477
|
this.r = r;
|
|
576
478
|
this.req = req;
|
|
577
479
|
}
|
|
578
|
-
|
|
480
|
+
forbidden() {
|
|
579
481
|
this.sendStatus(403);
|
|
580
|
-
}
|
|
581
|
-
|
|
482
|
+
}
|
|
483
|
+
sendStatus(status) {
|
|
582
484
|
this.r.writeHead(status).end();
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
}
|
|
586
|
-
|
|
485
|
+
}
|
|
486
|
+
progress(progress) {
|
|
487
|
+
}
|
|
488
|
+
success(data) {
|
|
587
489
|
this.r.json(data);
|
|
588
|
-
}
|
|
589
|
-
|
|
490
|
+
}
|
|
491
|
+
created(data) {
|
|
590
492
|
this.r.statusCode = 201;
|
|
591
493
|
this.r.json(data);
|
|
592
|
-
}
|
|
593
|
-
|
|
494
|
+
}
|
|
495
|
+
deleted() {
|
|
594
496
|
this.sendStatus(204);
|
|
595
|
-
}
|
|
596
|
-
|
|
497
|
+
}
|
|
498
|
+
notFound() {
|
|
597
499
|
this.sendStatus(404);
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
data = data_api_1.serializeError(data);
|
|
500
|
+
}
|
|
501
|
+
error(data) {
|
|
502
|
+
data = serializeError(data);
|
|
602
503
|
console.error({
|
|
603
504
|
message: data.message,
|
|
604
|
-
stack:
|
|
605
|
-
url:
|
|
505
|
+
stack: data.stack?.split('\n'),
|
|
506
|
+
url: this.req.originalUrl ?? this.req.path,
|
|
606
507
|
method: this.req.method
|
|
607
508
|
});
|
|
608
509
|
this.r.status(400).json(data);
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
}());
|
|
510
|
+
}
|
|
511
|
+
}
|
|
612
512
|
function throwError() {
|
|
613
513
|
throw "Invalid";
|
|
614
514
|
}
|
|
615
|
-
|
|
616
|
-
|
|
515
|
+
class inProcessQueueHandler {
|
|
516
|
+
constructor(storage) {
|
|
617
517
|
this.storage = storage;
|
|
618
518
|
this.actions = new Map();
|
|
619
519
|
}
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
id = _a.sent();
|
|
628
|
-
return [4 /*yield*/, this.storage.getJobInfo(id)];
|
|
629
|
-
case 2:
|
|
630
|
-
job = _a.sent();
|
|
631
|
-
this.actions.get(url)(body, req, {
|
|
632
|
-
error: function (error) { return job.setErrorResult(data_api_1.serializeError(error)); },
|
|
633
|
-
success: function (result) { return job.setResult(result); },
|
|
634
|
-
progress: function (progress) { return job.setProgress(progress); }
|
|
635
|
-
});
|
|
636
|
-
return [2 /*return*/, id];
|
|
637
|
-
}
|
|
638
|
-
});
|
|
520
|
+
async submitJob(url, req, body) {
|
|
521
|
+
let id = await this.storage.createJob(url, req.user ? req.user.id : undefined);
|
|
522
|
+
let job = await this.storage.getJobInfo(id);
|
|
523
|
+
this.actions.get(url)(body, req, {
|
|
524
|
+
error: error => job.setErrorResult(serializeError(error)),
|
|
525
|
+
success: result => job.setResult(result),
|
|
526
|
+
progress: progress => job.setProgress(progress)
|
|
639
527
|
});
|
|
640
|
-
|
|
641
|
-
|
|
528
|
+
return id;
|
|
529
|
+
}
|
|
530
|
+
mapQueuedAction(url, what) {
|
|
642
531
|
this.actions.set(url, what);
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
return
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
}
|
|
651
|
-
});
|
|
652
|
-
});
|
|
653
|
-
};
|
|
654
|
-
return inProcessQueueHandler;
|
|
655
|
-
}());
|
|
656
|
-
var InMemoryQueueStorage = /** @class */ (function () {
|
|
657
|
-
function InMemoryQueueStorage() {
|
|
532
|
+
}
|
|
533
|
+
async getJobInfo(queuedJobId) {
|
|
534
|
+
return await this.storage.getJobInfo(queuedJobId);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
class InMemoryQueueStorage {
|
|
538
|
+
constructor() {
|
|
658
539
|
this.jobs = new Map();
|
|
659
540
|
}
|
|
660
|
-
|
|
661
|
-
return
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
var job = _this.jobs.get(id);
|
|
685
|
-
job.info.done = true;
|
|
686
|
-
job.info.result = result;
|
|
687
|
-
},
|
|
688
|
-
setProgress: function (progress) {
|
|
689
|
-
var job = _this.jobs.get(id);
|
|
690
|
-
job.info.progress = progress;
|
|
691
|
-
}
|
|
692
|
-
});
|
|
693
|
-
return [2 /*return*/, id];
|
|
694
|
-
});
|
|
541
|
+
async getJobInfo(queuedJobId) {
|
|
542
|
+
return this.jobs.get(queuedJobId);
|
|
543
|
+
}
|
|
544
|
+
async createJob(url, userId) {
|
|
545
|
+
let id = this.jobs.size.toString();
|
|
546
|
+
this.jobs.set(id, {
|
|
547
|
+
info: {
|
|
548
|
+
done: false
|
|
549
|
+
},
|
|
550
|
+
userId: userId,
|
|
551
|
+
setErrorResult: (error) => {
|
|
552
|
+
let job = this.jobs.get(id);
|
|
553
|
+
job.info.done = true;
|
|
554
|
+
job.info.error = error;
|
|
555
|
+
},
|
|
556
|
+
setResult: (result) => {
|
|
557
|
+
let job = this.jobs.get(id);
|
|
558
|
+
job.info.done = true;
|
|
559
|
+
job.info.result = result;
|
|
560
|
+
},
|
|
561
|
+
setProgress: (progress) => {
|
|
562
|
+
let job = this.jobs.get(id);
|
|
563
|
+
job.info.progress = progress;
|
|
564
|
+
}
|
|
695
565
|
});
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
566
|
+
return id;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
let test = 0;
|
|
570
|
+
export class EntityQueueStorage {
|
|
571
|
+
constructor(repo) {
|
|
702
572
|
this.repo = repo;
|
|
703
573
|
this.sync = Promise.resolve();
|
|
704
574
|
}
|
|
705
|
-
|
|
706
|
-
return this.sync = this.sync.then(
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
case 1:
|
|
799
|
-
_a.sent();
|
|
800
|
-
return [2 /*return*/, q.id];
|
|
801
|
-
}
|
|
802
|
-
});
|
|
803
|
-
});
|
|
804
|
-
};
|
|
805
|
-
return EntityQueueStorage;
|
|
806
|
-
}());
|
|
807
|
-
exports.EntityQueueStorage = EntityQueueStorage;
|
|
808
|
-
var JobsInQueueEntity = /** @class */ (function (_super) {
|
|
809
|
-
tslib_1.__extends(JobsInQueueEntity, _super);
|
|
810
|
-
function JobsInQueueEntity() {
|
|
811
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
812
|
-
}
|
|
813
|
-
tslib_1.__decorate([
|
|
814
|
-
__1.Fields.string(),
|
|
815
|
-
tslib_1.__metadata("design:type", String)
|
|
816
|
-
], JobsInQueueEntity.prototype, "userId", void 0);
|
|
817
|
-
tslib_1.__decorate([
|
|
818
|
-
__1.Fields.string(),
|
|
819
|
-
tslib_1.__metadata("design:type", String)
|
|
820
|
-
], JobsInQueueEntity.prototype, "url", void 0);
|
|
821
|
-
tslib_1.__decorate([
|
|
822
|
-
__1.Fields.date(),
|
|
823
|
-
tslib_1.__metadata("design:type", Date)
|
|
824
|
-
], JobsInQueueEntity.prototype, "submitTime", void 0);
|
|
825
|
-
tslib_1.__decorate([
|
|
826
|
-
__1.Fields.date(),
|
|
827
|
-
tslib_1.__metadata("design:type", Date)
|
|
828
|
-
], JobsInQueueEntity.prototype, "doneTime", void 0);
|
|
829
|
-
tslib_1.__decorate([
|
|
830
|
-
__1.Fields.string(),
|
|
831
|
-
tslib_1.__metadata("design:type", String)
|
|
832
|
-
], JobsInQueueEntity.prototype, "result", void 0);
|
|
833
|
-
tslib_1.__decorate([
|
|
834
|
-
__1.Fields.boolean(),
|
|
835
|
-
tslib_1.__metadata("design:type", Boolean)
|
|
836
|
-
], JobsInQueueEntity.prototype, "done", void 0);
|
|
837
|
-
tslib_1.__decorate([
|
|
838
|
-
__1.Fields.boolean(),
|
|
839
|
-
tslib_1.__metadata("design:type", Boolean)
|
|
840
|
-
], JobsInQueueEntity.prototype, "error", void 0);
|
|
841
|
-
tslib_1.__decorate([
|
|
842
|
-
__1.Fields.number(),
|
|
843
|
-
tslib_1.__metadata("design:type", Number)
|
|
844
|
-
], JobsInQueueEntity.prototype, "progress", void 0);
|
|
845
|
-
JobsInQueueEntity = tslib_1.__decorate([
|
|
846
|
-
__1.Entity(undefined, {
|
|
847
|
-
dbName: 'jobsInQueue'
|
|
848
|
-
})
|
|
849
|
-
], JobsInQueueEntity);
|
|
850
|
-
return JobsInQueueEntity;
|
|
851
|
-
}(__1.IdEntity));
|
|
852
|
-
exports.JobsInQueueEntity = JobsInQueueEntity;
|
|
853
|
-
context_1.allEntities.splice(context_1.allEntities.indexOf(JobsInQueueEntity), 1);
|
|
575
|
+
doSync(what) {
|
|
576
|
+
return this.sync = this.sync.then(() => what());
|
|
577
|
+
}
|
|
578
|
+
async getJobInfo(queuedJobId) {
|
|
579
|
+
let q = await this.repo.findId(queuedJobId);
|
|
580
|
+
let lastProgress = undefined;
|
|
581
|
+
return {
|
|
582
|
+
userId: q.userId,
|
|
583
|
+
info: {
|
|
584
|
+
done: q.done,
|
|
585
|
+
error: q.error ? JSON.parse(q.result) : undefined,
|
|
586
|
+
result: q.done && !q.error ? JSON.parse(q.result) : undefined,
|
|
587
|
+
progress: q.progress
|
|
588
|
+
},
|
|
589
|
+
setErrorResult: async (error) => {
|
|
590
|
+
await this.sync;
|
|
591
|
+
q.error = true;
|
|
592
|
+
q.done = true;
|
|
593
|
+
q.result = JSON.stringify(error);
|
|
594
|
+
q.doneTime = new Date();
|
|
595
|
+
q.progress = 1;
|
|
596
|
+
await this.doSync(() => q._.save());
|
|
597
|
+
},
|
|
598
|
+
setResult: async (result) => {
|
|
599
|
+
await this.sync;
|
|
600
|
+
q.done = true;
|
|
601
|
+
q.result = JSON.stringify(result);
|
|
602
|
+
q.doneTime = new Date();
|
|
603
|
+
await this.doSync(() => q._.save());
|
|
604
|
+
},
|
|
605
|
+
setProgress: async (progress) => {
|
|
606
|
+
if (progress === 0)
|
|
607
|
+
return;
|
|
608
|
+
let now = new Date();
|
|
609
|
+
if (lastProgress && now.valueOf() - lastProgress.valueOf() < 200)
|
|
610
|
+
return;
|
|
611
|
+
lastProgress = new Date();
|
|
612
|
+
await this.sync;
|
|
613
|
+
q.progress = progress;
|
|
614
|
+
await this.doSync(() => q._.save());
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
async createJob(url, userId) {
|
|
619
|
+
let q = this.repo.create();
|
|
620
|
+
q.userId = userId;
|
|
621
|
+
q.submitTime = new Date();
|
|
622
|
+
q.url = url;
|
|
623
|
+
await q._.save();
|
|
624
|
+
return q.id;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
let JobsInQueueEntity = class JobsInQueueEntity extends IdEntity {
|
|
628
|
+
};
|
|
629
|
+
__decorate([
|
|
630
|
+
Fields.string(),
|
|
631
|
+
__metadata("design:type", String)
|
|
632
|
+
], JobsInQueueEntity.prototype, "userId", void 0);
|
|
633
|
+
__decorate([
|
|
634
|
+
Fields.string(),
|
|
635
|
+
__metadata("design:type", String)
|
|
636
|
+
], JobsInQueueEntity.prototype, "url", void 0);
|
|
637
|
+
__decorate([
|
|
638
|
+
Fields.date(),
|
|
639
|
+
__metadata("design:type", Date)
|
|
640
|
+
], JobsInQueueEntity.prototype, "submitTime", void 0);
|
|
641
|
+
__decorate([
|
|
642
|
+
Fields.date(),
|
|
643
|
+
__metadata("design:type", Date)
|
|
644
|
+
], JobsInQueueEntity.prototype, "doneTime", void 0);
|
|
645
|
+
__decorate([
|
|
646
|
+
Fields.string(),
|
|
647
|
+
__metadata("design:type", String)
|
|
648
|
+
], JobsInQueueEntity.prototype, "result", void 0);
|
|
649
|
+
__decorate([
|
|
650
|
+
Fields.boolean(),
|
|
651
|
+
__metadata("design:type", Boolean)
|
|
652
|
+
], JobsInQueueEntity.prototype, "done", void 0);
|
|
653
|
+
__decorate([
|
|
654
|
+
Fields.boolean(),
|
|
655
|
+
__metadata("design:type", Boolean)
|
|
656
|
+
], JobsInQueueEntity.prototype, "error", void 0);
|
|
657
|
+
__decorate([
|
|
658
|
+
Fields.number(),
|
|
659
|
+
__metadata("design:type", Number)
|
|
660
|
+
], JobsInQueueEntity.prototype, "progress", void 0);
|
|
661
|
+
JobsInQueueEntity = __decorate([
|
|
662
|
+
Entity(undefined, {
|
|
663
|
+
dbName: 'jobsInQueue'
|
|
664
|
+
})
|
|
665
|
+
], JobsInQueueEntity);
|
|
666
|
+
export { JobsInQueueEntity };
|
|
667
|
+
allEntities.splice(allEntities.indexOf(JobsInQueueEntity), 1);
|