@stemy/backend 5.0.7 → 5.0.8
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/esm2020/public_api.mjs +10 -20
- package/esm2020/services/backend-provider.mjs +52 -9
- package/esm2020/services/entities/lazy-asset.mjs +3 -9
- package/esm2020/services/job-manager.mjs +12 -17
- package/fesm2015/stemy-backend.mjs +243 -229
- package/fesm2015/stemy-backend.mjs.map +1 -1
- package/fesm2020/stemy-backend.mjs +239 -222
- package/fesm2020/stemy-backend.mjs.map +1 -1
- package/package.json +1 -1
- package/services/backend-provider.d.ts +13 -4
- package/services/entities/lazy-asset.d.ts +0 -1
- package/services/job-manager.d.ts +3 -2
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { __awaiter, __decorate, __param, __metadata } from 'tslib';
|
|
2
2
|
import { dirname, basename, join, resolve } from 'path';
|
|
3
|
-
import bodyParser from 'body-parser';
|
|
4
3
|
import webToken from 'jsonwebtoken';
|
|
5
4
|
import { injectable, scoped, Lifecycle, singleton, injectAll, inject, isFactoryProvider, container } from 'tsyringe';
|
|
6
5
|
import { HttpError, getMetadataArgsStorage, Authorized, Post, UploadedFile, Body, Get, Param, QueryParam, Res, QueryParams, Controller, UnauthorizedError, CurrentUser, Header, BadRequestError, Middleware, createParamDecorator, useContainer, useExpressServer } from 'routing-controllers';
|
|
@@ -25,15 +24,16 @@ import cron from 'node-cron';
|
|
|
25
24
|
import { socket } from 'zeromq';
|
|
26
25
|
import { filter as filter$1, map, first, timeout } from 'rxjs/operators';
|
|
27
26
|
import { createServer } from 'http';
|
|
28
|
-
import express_ from 'express';
|
|
29
27
|
import { Server } from 'socket.io';
|
|
30
|
-
import
|
|
31
|
-
import
|
|
32
|
-
import * as Handlebars from 'handlebars';
|
|
28
|
+
import express_ from 'express';
|
|
29
|
+
import bodyParser from 'body-parser';
|
|
33
30
|
import { routingControllersToSpec, OpenAPI, getStatusCode } from 'routing-controllers-openapi';
|
|
34
31
|
import { defaultMetadataStorage } from 'class-transformer/cjs/storage';
|
|
35
32
|
import { validationMetadatasToSchemas } from 'class-validator-jsonschema';
|
|
36
33
|
import { ValidatorConstraint, ValidationTypes, Min, Max, IsOptional, IsBoolean } from 'class-validator';
|
|
34
|
+
import { v4 } from 'uuid';
|
|
35
|
+
import { createTransport } from 'nodemailer';
|
|
36
|
+
import * as Handlebars from 'handlebars';
|
|
37
37
|
import { CommandsAddon, AnsiCodes } from '@stemy/terminal-commands-addon';
|
|
38
38
|
import { compare } from 'bcrypt';
|
|
39
39
|
import moment from 'moment';
|
|
@@ -1298,18 +1298,6 @@ class LazyAsset extends BaseEntity {
|
|
|
1298
1298
|
});
|
|
1299
1299
|
});
|
|
1300
1300
|
}
|
|
1301
|
-
load() {
|
|
1302
|
-
const _super = Object.create(null, {
|
|
1303
|
-
load: { get: () => super.load }
|
|
1304
|
-
});
|
|
1305
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1306
|
-
yield _super.load.call(this);
|
|
1307
|
-
if (this.deleted)
|
|
1308
|
-
return this;
|
|
1309
|
-
this.data.jobParams = JSON.parse(yield gunzipPromised(this.data.jobParams));
|
|
1310
|
-
return this;
|
|
1311
|
-
});
|
|
1312
|
-
}
|
|
1313
1301
|
loadAsset() {
|
|
1314
1302
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1315
1303
|
yield this.load();
|
|
@@ -1338,7 +1326,8 @@ class LazyAsset extends BaseEntity {
|
|
|
1338
1326
|
this.data.progressId = (yield this.progresses.create()).id;
|
|
1339
1327
|
this.data.assetId = null;
|
|
1340
1328
|
yield this.save();
|
|
1341
|
-
|
|
1329
|
+
const jobParams = JSON.parse(yield gunzipPromised(this.data.jobParams));
|
|
1330
|
+
yield this.progresses.jobMan.enqueueWithName(this.data.jobName, Object.assign(Object.assign({}, jobParams), { lazyId: this.id, fromLoad }));
|
|
1342
1331
|
});
|
|
1343
1332
|
}
|
|
1344
1333
|
}
|
|
@@ -1384,7 +1373,7 @@ let JobManager = class JobManager {
|
|
|
1384
1373
|
return res;
|
|
1385
1374
|
}, {});
|
|
1386
1375
|
this.messages = new Subject();
|
|
1387
|
-
this.processing =
|
|
1376
|
+
this.processing = null;
|
|
1388
1377
|
this.maxTimeout = this.config.resolve("jobTimeout");
|
|
1389
1378
|
}
|
|
1390
1379
|
on(message, cb) {
|
|
@@ -1437,23 +1426,16 @@ let JobManager = class JobManager {
|
|
|
1437
1426
|
});
|
|
1438
1427
|
});
|
|
1439
1428
|
}
|
|
1440
|
-
|
|
1429
|
+
initProcessing() {
|
|
1441
1430
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1442
|
-
if (this.processing)
|
|
1443
|
-
return null;
|
|
1444
|
-
this.processing = true;
|
|
1445
|
-
if (!this.config.resolve("isWorker")) {
|
|
1446
|
-
this.logger.log("job-manager", colorize(`Processing can not be started because this is NOT a worker process!`, ConsoleColor.FgRed));
|
|
1447
|
-
return null;
|
|
1448
|
-
}
|
|
1449
1431
|
const host = this.config.resolve("zmqRemoteHost");
|
|
1450
1432
|
const pushHost = `${host}:${this.config.resolve("zmqBackPort")}`;
|
|
1451
1433
|
this.workerPush = socket("push");
|
|
1452
|
-
|
|
1434
|
+
this.workerPush.connect(pushHost);
|
|
1453
1435
|
this.logger.log("job-manager", `Worker producer connected to: ${pushHost}`);
|
|
1454
1436
|
const pullHost = `${host}:${this.config.resolve("zmqPort")}`;
|
|
1455
1437
|
this.workerPull = socket("pull");
|
|
1456
|
-
|
|
1438
|
+
this.workerPull.connect(pullHost);
|
|
1457
1439
|
this.logger.log("job-manager", `Worker consumer connected to: ${pullHost}`);
|
|
1458
1440
|
this.workerPull.on("message", (name, args, uniqId) => __awaiter(this, void 0, void 0, function* () {
|
|
1459
1441
|
try {
|
|
@@ -1477,6 +1459,10 @@ let JobManager = class JobManager {
|
|
|
1477
1459
|
}));
|
|
1478
1460
|
});
|
|
1479
1461
|
}
|
|
1462
|
+
startProcessing() {
|
|
1463
|
+
this.processing = this.processing || this.initProcessing();
|
|
1464
|
+
return this.processing;
|
|
1465
|
+
}
|
|
1480
1466
|
tryResolve(jobType, params) {
|
|
1481
1467
|
const jobName = getConstructorName(jobType);
|
|
1482
1468
|
if (!this.jobs[jobName]) {
|
|
@@ -1535,16 +1521,14 @@ let JobManager = class JobManager {
|
|
|
1535
1521
|
}
|
|
1536
1522
|
sendToWorkers(jobName, params) {
|
|
1537
1523
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1538
|
-
const publisher = yield this.apiPush;
|
|
1539
1524
|
const uniqueId = new ObjectId$1().toHexString();
|
|
1540
|
-
|
|
1525
|
+
this.apiPush.send([jobName, JSON.stringify(params), uniqueId]);
|
|
1541
1526
|
return uniqueId;
|
|
1542
1527
|
});
|
|
1543
1528
|
}
|
|
1544
1529
|
};
|
|
1545
1530
|
JobManager = __decorate([
|
|
1546
|
-
|
|
1547
|
-
scoped(Lifecycle.ContainerScoped),
|
|
1531
|
+
singleton(),
|
|
1548
1532
|
__param(2, inject(DI_CONTAINER)),
|
|
1549
1533
|
__param(3, injectAll(JOB)),
|
|
1550
1534
|
__metadata("design:paramtypes", [Configuration,
|
|
@@ -1935,12 +1919,187 @@ AssetResolver = __decorate([
|
|
|
1935
1919
|
__metadata("design:paramtypes", [Assets, LazyAssets])
|
|
1936
1920
|
], AssetResolver);
|
|
1937
1921
|
|
|
1922
|
+
function checkValue(multi, value) {
|
|
1923
|
+
if (multi) {
|
|
1924
|
+
return Array.isArray(value) && value.every(v => {
|
|
1925
|
+
try {
|
|
1926
|
+
const id = new ObjectId$1(v);
|
|
1927
|
+
return id instanceof ObjectId$1;
|
|
1928
|
+
}
|
|
1929
|
+
catch (e) {
|
|
1930
|
+
return false;
|
|
1931
|
+
}
|
|
1932
|
+
});
|
|
1933
|
+
}
|
|
1934
|
+
if (null === value)
|
|
1935
|
+
return true;
|
|
1936
|
+
try {
|
|
1937
|
+
const id = new ObjectId$1(value);
|
|
1938
|
+
return id instanceof ObjectId$1;
|
|
1939
|
+
}
|
|
1940
|
+
catch (e) {
|
|
1941
|
+
return false;
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
let IsFile = class IsFile {
|
|
1945
|
+
validate(value, validationArguments) {
|
|
1946
|
+
const [multi] = (validationArguments.constraints || []);
|
|
1947
|
+
return checkValue(multi, value);
|
|
1948
|
+
}
|
|
1949
|
+
};
|
|
1950
|
+
IsFile = __decorate([
|
|
1951
|
+
ValidatorConstraint()
|
|
1952
|
+
], IsFile);
|
|
1953
|
+
let IsObjectId = class IsObjectId {
|
|
1954
|
+
validate(value, validationArguments) {
|
|
1955
|
+
const [_, multi] = (validationArguments.constraints || []);
|
|
1956
|
+
return checkValue(multi, value);
|
|
1957
|
+
}
|
|
1958
|
+
};
|
|
1959
|
+
IsObjectId = __decorate([
|
|
1960
|
+
ValidatorConstraint()
|
|
1961
|
+
], IsObjectId);
|
|
1962
|
+
|
|
1963
|
+
let OpenApi = class OpenApi {
|
|
1964
|
+
constructor(container, customValidation) {
|
|
1965
|
+
this.container = container;
|
|
1966
|
+
this.customValidation = customValidation;
|
|
1967
|
+
this.docs = null;
|
|
1968
|
+
}
|
|
1969
|
+
get apiDocs() {
|
|
1970
|
+
if (!this.docs)
|
|
1971
|
+
this.docs = this.createApiDocs();
|
|
1972
|
+
return this.docs;
|
|
1973
|
+
}
|
|
1974
|
+
get apiDocsStr() {
|
|
1975
|
+
if (!this.docsStr)
|
|
1976
|
+
this.docsStr = JSON.stringify(this.apiDocs);
|
|
1977
|
+
return this.docsStr;
|
|
1978
|
+
}
|
|
1979
|
+
schemaToExample(src, req) {
|
|
1980
|
+
var _a, _b, _c;
|
|
1981
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1982
|
+
const maybeRef = src;
|
|
1983
|
+
if (maybeRef.$ref) {
|
|
1984
|
+
const schemas = this.apiDocs.components.schemas;
|
|
1985
|
+
const schema = maybeRef.$ref
|
|
1986
|
+
.replace("#/components/schemas/", "")
|
|
1987
|
+
.replace("#/definitions/", "");
|
|
1988
|
+
return this.schemaToExample(schemas[schema], req);
|
|
1989
|
+
}
|
|
1990
|
+
let schema = src;
|
|
1991
|
+
if (schema.oneOf) {
|
|
1992
|
+
schema = Object.assign({}, schema, schema.oneOf[0]);
|
|
1993
|
+
}
|
|
1994
|
+
if (schema.type === "object") {
|
|
1995
|
+
const result = {};
|
|
1996
|
+
yield Promise.all(Object.keys(schema.properties).map((key) => __awaiter(this, void 0, void 0, function* () {
|
|
1997
|
+
result[key] = yield this.schemaToExample(schema.properties[key], req);
|
|
1998
|
+
})));
|
|
1999
|
+
return result;
|
|
2000
|
+
}
|
|
2001
|
+
if (schema.type === "array") {
|
|
2002
|
+
return [yield this.schemaToExample(schema.items, req)];
|
|
2003
|
+
}
|
|
2004
|
+
if (schema.type === "string") {
|
|
2005
|
+
if (isDefined(schema.default)) {
|
|
2006
|
+
if (isFunction(schema.default)) {
|
|
2007
|
+
return schema.default(this.container);
|
|
2008
|
+
}
|
|
2009
|
+
return schema.default;
|
|
2010
|
+
}
|
|
2011
|
+
if (schema.format == "date") {
|
|
2012
|
+
return new Date().toISOString().substr(0, 10);
|
|
2013
|
+
}
|
|
2014
|
+
if (schema.format == "date-time") {
|
|
2015
|
+
return new Date().toISOString();
|
|
2016
|
+
}
|
|
2017
|
+
if (schema.enum) {
|
|
2018
|
+
return schema.enum[0];
|
|
2019
|
+
}
|
|
2020
|
+
return "string";
|
|
2021
|
+
}
|
|
2022
|
+
if (schema.type === "number") {
|
|
2023
|
+
return (_a = schema.default) !== null && _a !== void 0 ? _a : 0;
|
|
2024
|
+
}
|
|
2025
|
+
else if (schema.type === "boolean") {
|
|
2026
|
+
return (_b = schema.default) !== null && _b !== void 0 ? _b : false;
|
|
2027
|
+
}
|
|
2028
|
+
else {
|
|
2029
|
+
return (_c = schema.default) !== null && _c !== void 0 ? _c : null;
|
|
2030
|
+
}
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
2033
|
+
createApiDocs() {
|
|
2034
|
+
const storage = getMetadataArgsStorage();
|
|
2035
|
+
const docs = routingControllersToSpec(storage);
|
|
2036
|
+
docs.basePath = "/api/";
|
|
2037
|
+
docs.definitions = validationMetadatasToSchemas({
|
|
2038
|
+
classTransformerMetadataStorage: defaultMetadataStorage,
|
|
2039
|
+
additionalConverters: {
|
|
2040
|
+
[ValidationTypes.CUSTOM_VALIDATION]: (meta, options) => {
|
|
2041
|
+
const res = isFunction(this.customValidation) ? this.customValidation(meta, options) : this.customValidation;
|
|
2042
|
+
if (isObject(res))
|
|
2043
|
+
return res;
|
|
2044
|
+
const constraints = meta.constraints || [];
|
|
2045
|
+
if (meta.constraintCls === IsFile) {
|
|
2046
|
+
return {
|
|
2047
|
+
multi: constraints[0] || false,
|
|
2048
|
+
type: "file"
|
|
2049
|
+
};
|
|
2050
|
+
}
|
|
2051
|
+
if (meta.constraintCls === IsObjectId) {
|
|
2052
|
+
return {
|
|
2053
|
+
endpoint: constraints[0] || false,
|
|
2054
|
+
multi: constraints[1] || false,
|
|
2055
|
+
type: "list"
|
|
2056
|
+
};
|
|
2057
|
+
}
|
|
2058
|
+
return null;
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
});
|
|
2062
|
+
docs.components.schemas = docs.definitions;
|
|
2063
|
+
return docs;
|
|
2064
|
+
}
|
|
2065
|
+
};
|
|
2066
|
+
OpenApi = __decorate([
|
|
2067
|
+
singleton(),
|
|
2068
|
+
__param(0, inject(DI_CONTAINER)),
|
|
2069
|
+
__param(1, inject(OPENAPI_VALIDATION)),
|
|
2070
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
2071
|
+
], OpenApi);
|
|
2072
|
+
|
|
2073
|
+
let Fixtures = class Fixtures {
|
|
2074
|
+
constructor(fixtures) {
|
|
2075
|
+
this.fixtures = fixtures;
|
|
2076
|
+
}
|
|
2077
|
+
load(output) {
|
|
2078
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2079
|
+
if (!this.fixtures)
|
|
2080
|
+
return;
|
|
2081
|
+
output = output || {
|
|
2082
|
+
write: console.log,
|
|
2083
|
+
writeln: t => console.log(t + "\n")
|
|
2084
|
+
};
|
|
2085
|
+
for (let fixture of this.fixtures) {
|
|
2086
|
+
yield fixture.load(output);
|
|
2087
|
+
}
|
|
2088
|
+
});
|
|
2089
|
+
}
|
|
2090
|
+
};
|
|
2091
|
+
Fixtures = __decorate([
|
|
2092
|
+
injectable(),
|
|
2093
|
+
scoped(Lifecycle.ContainerScoped),
|
|
2094
|
+
__param(0, injectAll(FIXTURE)),
|
|
2095
|
+
__metadata("design:paramtypes", [Array])
|
|
2096
|
+
], Fixtures);
|
|
2097
|
+
|
|
1938
2098
|
const express = express_;
|
|
1939
2099
|
let BackendProvider = class BackendProvider {
|
|
1940
|
-
constructor() {
|
|
1941
|
-
this.
|
|
1942
|
-
this.
|
|
1943
|
-
this.server = createServer(this.express);
|
|
2100
|
+
constructor(config, container) {
|
|
2101
|
+
this.config = config;
|
|
2102
|
+
this.container = container;
|
|
1944
2103
|
}
|
|
1945
2104
|
get io() {
|
|
1946
2105
|
this.ioServer = this.ioServer || new Server(this.server, {
|
|
@@ -1955,10 +2114,50 @@ let BackendProvider = class BackendProvider {
|
|
|
1955
2114
|
});
|
|
1956
2115
|
return this.ioServer;
|
|
1957
2116
|
}
|
|
2117
|
+
get express() {
|
|
2118
|
+
if (!this.expressApp) {
|
|
2119
|
+
this.expressApp = express();
|
|
2120
|
+
this.expressApp.set("trust proxy", true);
|
|
2121
|
+
this.expressApp.use(bodyParser.json({
|
|
2122
|
+
limit: this.config.resolve("jsonLimit")
|
|
2123
|
+
}));
|
|
2124
|
+
this.expressApp.get("/api-docs", (req, res) => {
|
|
2125
|
+
this.openApi = this.openApi || this.container.get(OpenApi);
|
|
2126
|
+
res.header("Content-Type", "application/json")
|
|
2127
|
+
.status(200)
|
|
2128
|
+
.end(this.openApi.apiDocsStr);
|
|
2129
|
+
});
|
|
2130
|
+
}
|
|
2131
|
+
return this.expressApp;
|
|
2132
|
+
}
|
|
2133
|
+
get server() {
|
|
2134
|
+
this.httpServer = this.httpServer || createServer(this.express);
|
|
2135
|
+
return this.httpServer;
|
|
2136
|
+
}
|
|
2137
|
+
quickStart() {
|
|
2138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2139
|
+
const port = this.config.resolve("appPort");
|
|
2140
|
+
const isWorker = this.config.resolve("isWorker");
|
|
2141
|
+
if (isWorker || this.config.resolve("startWorker")) {
|
|
2142
|
+
yield this.container.resolve(JobManager).startProcessing();
|
|
2143
|
+
if (isWorker) {
|
|
2144
|
+
return;
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
if (this.config.resolve("fixtures")) {
|
|
2148
|
+
const fixtures = this.container.resolve(Fixtures);
|
|
2149
|
+
yield fixtures.load();
|
|
2150
|
+
}
|
|
2151
|
+
return new Promise(resolve => {
|
|
2152
|
+
this.server.listen(port, () => resolve(`Service listening on port ${port}!`));
|
|
2153
|
+
});
|
|
2154
|
+
});
|
|
2155
|
+
}
|
|
1958
2156
|
};
|
|
1959
2157
|
BackendProvider = __decorate([
|
|
1960
2158
|
singleton(),
|
|
1961
|
-
|
|
2159
|
+
__param(1, inject(DI_CONTAINER)),
|
|
2160
|
+
__metadata("design:paramtypes", [Configuration, Object])
|
|
1962
2161
|
], BackendProvider);
|
|
1963
2162
|
|
|
1964
2163
|
let CacheProcessor = class CacheProcessor {
|
|
@@ -2060,31 +2259,6 @@ EndpointProvider = __decorate([
|
|
|
2060
2259
|
scoped(Lifecycle.ContainerScoped)
|
|
2061
2260
|
], EndpointProvider);
|
|
2062
2261
|
|
|
2063
|
-
let Fixtures = class Fixtures {
|
|
2064
|
-
constructor(fixtures) {
|
|
2065
|
-
this.fixtures = fixtures;
|
|
2066
|
-
}
|
|
2067
|
-
load(output) {
|
|
2068
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2069
|
-
if (!this.fixtures)
|
|
2070
|
-
return;
|
|
2071
|
-
output = output || {
|
|
2072
|
-
write: console.log,
|
|
2073
|
-
writeln: t => console.log(t + "\n")
|
|
2074
|
-
};
|
|
2075
|
-
for (let fixture of this.fixtures) {
|
|
2076
|
-
yield fixture.load(output);
|
|
2077
|
-
}
|
|
2078
|
-
});
|
|
2079
|
-
}
|
|
2080
|
-
};
|
|
2081
|
-
Fixtures = __decorate([
|
|
2082
|
-
injectable(),
|
|
2083
|
-
scoped(Lifecycle.ContainerScoped),
|
|
2084
|
-
__param(0, injectAll(FIXTURE)),
|
|
2085
|
-
__metadata("design:paramtypes", [Array])
|
|
2086
|
-
], Fixtures);
|
|
2087
|
-
|
|
2088
2262
|
const sharp$1 = sharp_;
|
|
2089
2263
|
const bigSize = 1500;
|
|
2090
2264
|
const thumbSize = 250;
|
|
@@ -2552,157 +2726,6 @@ MemoryCache = __decorate([
|
|
|
2552
2726
|
__metadata("design:paramtypes", [Cache])
|
|
2553
2727
|
], MemoryCache);
|
|
2554
2728
|
|
|
2555
|
-
function checkValue(multi, value) {
|
|
2556
|
-
if (multi) {
|
|
2557
|
-
return Array.isArray(value) && value.every(v => {
|
|
2558
|
-
try {
|
|
2559
|
-
const id = new ObjectId$1(v);
|
|
2560
|
-
return id instanceof ObjectId$1;
|
|
2561
|
-
}
|
|
2562
|
-
catch (e) {
|
|
2563
|
-
return false;
|
|
2564
|
-
}
|
|
2565
|
-
});
|
|
2566
|
-
}
|
|
2567
|
-
if (null === value)
|
|
2568
|
-
return true;
|
|
2569
|
-
try {
|
|
2570
|
-
const id = new ObjectId$1(value);
|
|
2571
|
-
return id instanceof ObjectId$1;
|
|
2572
|
-
}
|
|
2573
|
-
catch (e) {
|
|
2574
|
-
return false;
|
|
2575
|
-
}
|
|
2576
|
-
}
|
|
2577
|
-
let IsFile = class IsFile {
|
|
2578
|
-
validate(value, validationArguments) {
|
|
2579
|
-
const [multi] = (validationArguments.constraints || []);
|
|
2580
|
-
return checkValue(multi, value);
|
|
2581
|
-
}
|
|
2582
|
-
};
|
|
2583
|
-
IsFile = __decorate([
|
|
2584
|
-
ValidatorConstraint()
|
|
2585
|
-
], IsFile);
|
|
2586
|
-
let IsObjectId = class IsObjectId {
|
|
2587
|
-
validate(value, validationArguments) {
|
|
2588
|
-
const [_, multi] = (validationArguments.constraints || []);
|
|
2589
|
-
return checkValue(multi, value);
|
|
2590
|
-
}
|
|
2591
|
-
};
|
|
2592
|
-
IsObjectId = __decorate([
|
|
2593
|
-
ValidatorConstraint()
|
|
2594
|
-
], IsObjectId);
|
|
2595
|
-
|
|
2596
|
-
let OpenApi = class OpenApi {
|
|
2597
|
-
constructor(container, customValidation) {
|
|
2598
|
-
this.container = container;
|
|
2599
|
-
this.customValidation = customValidation;
|
|
2600
|
-
this.docs = null;
|
|
2601
|
-
}
|
|
2602
|
-
get apiDocs() {
|
|
2603
|
-
if (!this.docs)
|
|
2604
|
-
this.docs = this.createApiDocs();
|
|
2605
|
-
return this.docs;
|
|
2606
|
-
}
|
|
2607
|
-
get apiDocsStr() {
|
|
2608
|
-
if (!this.docsStr)
|
|
2609
|
-
this.docsStr = JSON.stringify(this.apiDocs);
|
|
2610
|
-
return this.docsStr;
|
|
2611
|
-
}
|
|
2612
|
-
schemaToExample(src, req) {
|
|
2613
|
-
var _a, _b, _c;
|
|
2614
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2615
|
-
const maybeRef = src;
|
|
2616
|
-
if (maybeRef.$ref) {
|
|
2617
|
-
const schemas = this.apiDocs.components.schemas;
|
|
2618
|
-
const schema = maybeRef.$ref
|
|
2619
|
-
.replace("#/components/schemas/", "")
|
|
2620
|
-
.replace("#/definitions/", "");
|
|
2621
|
-
return this.schemaToExample(schemas[schema], req);
|
|
2622
|
-
}
|
|
2623
|
-
let schema = src;
|
|
2624
|
-
if (schema.oneOf) {
|
|
2625
|
-
schema = Object.assign({}, schema, schema.oneOf[0]);
|
|
2626
|
-
}
|
|
2627
|
-
if (schema.type === "object") {
|
|
2628
|
-
const result = {};
|
|
2629
|
-
yield Promise.all(Object.keys(schema.properties).map((key) => __awaiter(this, void 0, void 0, function* () {
|
|
2630
|
-
result[key] = yield this.schemaToExample(schema.properties[key], req);
|
|
2631
|
-
})));
|
|
2632
|
-
return result;
|
|
2633
|
-
}
|
|
2634
|
-
if (schema.type === "array") {
|
|
2635
|
-
return [yield this.schemaToExample(schema.items, req)];
|
|
2636
|
-
}
|
|
2637
|
-
if (schema.type === "string") {
|
|
2638
|
-
if (isDefined(schema.default)) {
|
|
2639
|
-
if (isFunction(schema.default)) {
|
|
2640
|
-
return schema.default(this.container);
|
|
2641
|
-
}
|
|
2642
|
-
return schema.default;
|
|
2643
|
-
}
|
|
2644
|
-
if (schema.format == "date") {
|
|
2645
|
-
return new Date().toISOString().substr(0, 10);
|
|
2646
|
-
}
|
|
2647
|
-
if (schema.format == "date-time") {
|
|
2648
|
-
return new Date().toISOString();
|
|
2649
|
-
}
|
|
2650
|
-
if (schema.enum) {
|
|
2651
|
-
return schema.enum[0];
|
|
2652
|
-
}
|
|
2653
|
-
return "string";
|
|
2654
|
-
}
|
|
2655
|
-
if (schema.type === "number") {
|
|
2656
|
-
return (_a = schema.default) !== null && _a !== void 0 ? _a : 0;
|
|
2657
|
-
}
|
|
2658
|
-
else if (schema.type === "boolean") {
|
|
2659
|
-
return (_b = schema.default) !== null && _b !== void 0 ? _b : false;
|
|
2660
|
-
}
|
|
2661
|
-
else {
|
|
2662
|
-
return (_c = schema.default) !== null && _c !== void 0 ? _c : null;
|
|
2663
|
-
}
|
|
2664
|
-
});
|
|
2665
|
-
}
|
|
2666
|
-
createApiDocs() {
|
|
2667
|
-
const storage = getMetadataArgsStorage();
|
|
2668
|
-
const docs = routingControllersToSpec(storage);
|
|
2669
|
-
docs.basePath = "/api/";
|
|
2670
|
-
docs.definitions = validationMetadatasToSchemas({
|
|
2671
|
-
classTransformerMetadataStorage: defaultMetadataStorage,
|
|
2672
|
-
additionalConverters: {
|
|
2673
|
-
[ValidationTypes.CUSTOM_VALIDATION]: (meta, options) => {
|
|
2674
|
-
const res = isFunction(this.customValidation) ? this.customValidation(meta, options) : this.customValidation;
|
|
2675
|
-
if (isObject(res))
|
|
2676
|
-
return res;
|
|
2677
|
-
const constraints = meta.constraints || [];
|
|
2678
|
-
if (meta.constraintCls === IsFile) {
|
|
2679
|
-
return {
|
|
2680
|
-
multi: constraints[0] || false,
|
|
2681
|
-
type: "file"
|
|
2682
|
-
};
|
|
2683
|
-
}
|
|
2684
|
-
if (meta.constraintCls === IsObjectId) {
|
|
2685
|
-
return {
|
|
2686
|
-
endpoint: constraints[0] || false,
|
|
2687
|
-
multi: constraints[1] || false,
|
|
2688
|
-
type: "list"
|
|
2689
|
-
};
|
|
2690
|
-
}
|
|
2691
|
-
return null;
|
|
2692
|
-
}
|
|
2693
|
-
}
|
|
2694
|
-
});
|
|
2695
|
-
docs.components.schemas = docs.definitions;
|
|
2696
|
-
return docs;
|
|
2697
|
-
}
|
|
2698
|
-
};
|
|
2699
|
-
OpenApi = __decorate([
|
|
2700
|
-
singleton(),
|
|
2701
|
-
__param(0, inject(DI_CONTAINER)),
|
|
2702
|
-
__param(1, inject(OPENAPI_VALIDATION)),
|
|
2703
|
-
__metadata("design:paramtypes", [Object, Object])
|
|
2704
|
-
], OpenApi);
|
|
2705
|
-
|
|
2706
2729
|
let TerminalManager = class TerminalManager {
|
|
2707
2730
|
constructor(logger, config, commands) {
|
|
2708
2731
|
this.logger = logger;
|
|
@@ -4360,6 +4383,8 @@ function createServices() {
|
|
|
4360
4383
|
new Parameter("zmqBackPort", 3100),
|
|
4361
4384
|
new Parameter("zmqRemoteHost", "tcp://127.0.0.1"),
|
|
4362
4385
|
new Parameter("isWorker", false),
|
|
4386
|
+
new Parameter("startWorker", false),
|
|
4387
|
+
new Parameter("fixtures", true),
|
|
4363
4388
|
new Parameter("mainEndpoint", ""),
|
|
4364
4389
|
new Parameter("idChars", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"),
|
|
4365
4390
|
new Parameter("idSeparator", "-"),
|
|
@@ -4559,25 +4584,14 @@ function setupBackend(config, providers, parent) {
|
|
|
4559
4584
|
const configuration = diContainer.resolve(Configuration);
|
|
4560
4585
|
const bp = diContainer.resolve(BackendProvider);
|
|
4561
4586
|
if (config.restOptions) {
|
|
4562
|
-
bp.express.use(bodyParser.json({
|
|
4563
|
-
limit: configuration.hasParam("jsonLimit")
|
|
4564
|
-
? configuration.resolve("jsonLimit")
|
|
4565
|
-
: "250mb"
|
|
4566
|
-
}));
|
|
4567
4587
|
useContainer(diContainer);
|
|
4568
4588
|
useExpressServer(bp.express, restOptions);
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
res.header("Content-Type", "application/json")
|
|
4574
|
-
.status(200)
|
|
4575
|
-
.end(openApi.apiDocsStr);
|
|
4589
|
+
}
|
|
4590
|
+
if (config.socketOptions) {
|
|
4591
|
+
diContainer.register(SOCKET_CONTROLLERS, {
|
|
4592
|
+
useValue: new SocketControllers(Object.assign({ io: bp.io }, socketOptions))
|
|
4576
4593
|
});
|
|
4577
4594
|
}
|
|
4578
|
-
diContainer.register(SOCKET_CONTROLLERS, {
|
|
4579
|
-
useValue: new SocketControllers(Object.assign({ io: bp.io }, socketOptions))
|
|
4580
|
-
});
|
|
4581
4595
|
// Connect to mongo if necessary
|
|
4582
4596
|
if (configuration.hasParam("mongoUri") && configuration.resolve("mongoUri")) {
|
|
4583
4597
|
console.log("Connecting to MongoDB...");
|