@stemy/backend 5.0.6 → 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.
@@ -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';
@@ -10,6 +9,7 @@ import sharp_ from 'sharp';
10
9
  import { ObjectId as ObjectId$1 } from 'bson';
11
10
  import axios from 'axios';
12
11
  import { mkdir, unlink, readFile as readFile$1, writeFile as writeFile$1, lstat, readdir, access, constants, lstatSync, readFileSync, existsSync } from 'fs';
12
+ import { gzip, gunzip } from 'zlib';
13
13
  import { fileURLToPath } from 'url';
14
14
  import { exec } from 'child_process';
15
15
  import { createHash } from 'crypto';
@@ -24,15 +24,16 @@ import cron from 'node-cron';
24
24
  import { socket } from 'zeromq';
25
25
  import { filter as filter$1, map, first, timeout } from 'rxjs/operators';
26
26
  import { createServer } from 'http';
27
- import express_ from 'express';
28
27
  import { Server } from 'socket.io';
29
- import { v4 } from 'uuid';
30
- import { createTransport } from 'nodemailer';
31
- import * as Handlebars from 'handlebars';
28
+ import express_ from 'express';
29
+ import bodyParser from 'body-parser';
32
30
  import { routingControllersToSpec, OpenAPI, getStatusCode } from 'routing-controllers-openapi';
33
31
  import { defaultMetadataStorage } from 'class-transformer/cjs/storage';
34
32
  import { validationMetadatasToSchemas } from 'class-validator-jsonschema';
35
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';
36
37
  import { CommandsAddon, AnsiCodes } from '@stemy/terminal-commands-addon';
37
38
  import { compare } from 'bcrypt';
38
39
  import moment from 'moment';
@@ -601,6 +602,28 @@ function padRight(value, count = 3, padWith = "0") {
601
602
  function camelCaseToDash(str) {
602
603
  return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
603
604
  }
605
+ function gzipPromised(data, opts) {
606
+ return new Promise((resolve, reject) => {
607
+ gzip(data, opts, (err, result) => {
608
+ if (err) {
609
+ reject(err);
610
+ return;
611
+ }
612
+ resolve(result.toString("base64"));
613
+ });
614
+ });
615
+ }
616
+ function gunzipPromised(data, opts) {
617
+ return new Promise((resolve, reject) => {
618
+ gunzip(Buffer.from(data, "base64"), opts, (err, result) => {
619
+ if (err) {
620
+ reject(err);
621
+ return;
622
+ }
623
+ resolve(result.toString("utf8"));
624
+ });
625
+ });
626
+ }
604
627
  function deleteFromBucket(bucket, fileId) {
605
628
  return new Promise(((resolve, reject) => {
606
629
  bucket.delete(fileId, error => {
@@ -617,20 +640,22 @@ function deleteFromBucket(bucket, fileId) {
617
640
  }));
618
641
  }
619
642
  const defaultPredicate = () => true;
620
- function copyRecursive(target, source, predicate) {
621
- predicate = predicate || defaultPredicate;
643
+ function copyRecursive(target, source, predicate, copies) {
622
644
  if (isPrimitive(source) || isDate(source) || isFunction(source))
623
645
  return source;
646
+ if (copies.has(source))
647
+ return copies.get(source);
624
648
  if (isArray(source)) {
625
649
  target = isArray(target) ? Array.from(target) : [];
626
650
  source.forEach((item, index) => {
627
651
  if (!predicate(item, index, target, source))
628
652
  return;
629
653
  if (target.length > index)
630
- target[index] = copyRecursive(target[index], item, predicate);
654
+ target[index] = copyRecursive(target[index], item, predicate, copies);
631
655
  else
632
- target.push(copyRecursive(null, item, predicate));
656
+ target.push(copyRecursive(null, item, predicate, copies));
633
657
  });
658
+ copies.set(source, target);
634
659
  return target;
635
660
  }
636
661
  if (isBuffer(source))
@@ -654,24 +679,25 @@ function copyRecursive(target, source, predicate) {
654
679
  else {
655
680
  target = Object.assign({}, target || {});
656
681
  }
682
+ // Set to copies to prevent circular references
683
+ copies.set(source, target);
657
684
  // Copy map entries
658
685
  if (target instanceof Map) {
659
686
  if (source instanceof Map) {
660
687
  for (let [key, value] of source.entries()) {
661
688
  if (!predicate(value, key, target, source))
662
689
  continue;
663
- target.set(key, !shouldCopy(key, value) ? value : copyRecursive(target.get(key), value, predicate));
690
+ target.set(key, !shouldCopy(key, value) ? value : copyRecursive(target.get(key), value, predicate, copies));
664
691
  }
665
692
  }
666
693
  return target;
667
694
  }
668
695
  // Copy object members
669
696
  let keys = Object.keys(source);
670
- target = keys.reduce((result, key) => {
671
- if (!predicate(source[key], key, result, source))
672
- return result;
673
- result[key] = !shouldCopy(key, source[key]) ? source[key] : copyRecursive(result[key], source[key], predicate);
674
- return result;
697
+ keys.forEach(key => {
698
+ if (!predicate(source[key], key, target, source))
699
+ return;
700
+ target[key] = !shouldCopy(key, source[key]) ? source[key] : copyRecursive(target[key], source[key], predicate, copies);
675
701
  }, target);
676
702
  // Copy object properties
677
703
  const descriptors = Object.getOwnPropertyDescriptors(source);
@@ -682,13 +708,13 @@ function copyRecursive(target, source, predicate) {
682
708
  return target;
683
709
  }
684
710
  function filter(obj, predicate) {
685
- return copyRecursive(null, obj, predicate);
711
+ return copyRecursive(null, obj, predicate || defaultPredicate, new Map());
686
712
  }
687
713
  function copy(obj) {
688
- return copyRecursive(null, obj);
714
+ return copyRecursive(null, obj, defaultPredicate, new Map());
689
715
  }
690
716
  function assign(target, source, predicate) {
691
- return copyRecursive(target, source, predicate);
717
+ return copyRecursive(target, source, predicate, new Map());
692
718
  }
693
719
  function md5(data) {
694
720
  if (isObject(data)) {
@@ -1300,7 +1326,8 @@ class LazyAsset extends BaseEntity {
1300
1326
  this.data.progressId = (yield this.progresses.create()).id;
1301
1327
  this.data.assetId = null;
1302
1328
  yield this.save();
1303
- yield this.progresses.jobMan.enqueueWithName(this.data.jobName, Object.assign(Object.assign({}, this.data.jobParams), { lazyId: this.id, fromLoad }));
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 }));
1304
1331
  });
1305
1332
  }
1306
1333
  }
@@ -1346,7 +1373,7 @@ let JobManager = class JobManager {
1346
1373
  return res;
1347
1374
  }, {});
1348
1375
  this.messages = new Subject();
1349
- this.processing = false;
1376
+ this.processing = null;
1350
1377
  this.maxTimeout = this.config.resolve("jobTimeout");
1351
1378
  }
1352
1379
  on(message, cb) {
@@ -1399,23 +1426,16 @@ let JobManager = class JobManager {
1399
1426
  });
1400
1427
  });
1401
1428
  }
1402
- startProcessing() {
1429
+ initProcessing() {
1403
1430
  return __awaiter(this, void 0, void 0, function* () {
1404
- if (this.processing)
1405
- return null;
1406
- this.processing = true;
1407
- if (!this.config.resolve("isWorker")) {
1408
- this.logger.log("job-manager", colorize(`Processing can not be started because this is NOT a worker process!`, ConsoleColor.FgRed));
1409
- return null;
1410
- }
1411
1431
  const host = this.config.resolve("zmqRemoteHost");
1412
1432
  const pushHost = `${host}:${this.config.resolve("zmqBackPort")}`;
1413
1433
  this.workerPush = socket("push");
1414
- yield this.workerPush.connect(pushHost);
1434
+ this.workerPush.connect(pushHost);
1415
1435
  this.logger.log("job-manager", `Worker producer connected to: ${pushHost}`);
1416
1436
  const pullHost = `${host}:${this.config.resolve("zmqPort")}`;
1417
1437
  this.workerPull = socket("pull");
1418
- yield this.workerPull.connect(pullHost);
1438
+ this.workerPull.connect(pullHost);
1419
1439
  this.logger.log("job-manager", `Worker consumer connected to: ${pullHost}`);
1420
1440
  this.workerPull.on("message", (name, args, uniqId) => __awaiter(this, void 0, void 0, function* () {
1421
1441
  try {
@@ -1439,6 +1459,10 @@ let JobManager = class JobManager {
1439
1459
  }));
1440
1460
  });
1441
1461
  }
1462
+ startProcessing() {
1463
+ this.processing = this.processing || this.initProcessing();
1464
+ return this.processing;
1465
+ }
1442
1466
  tryResolve(jobType, params) {
1443
1467
  const jobName = getConstructorName(jobType);
1444
1468
  if (!this.jobs[jobName]) {
@@ -1497,16 +1521,14 @@ let JobManager = class JobManager {
1497
1521
  }
1498
1522
  sendToWorkers(jobName, params) {
1499
1523
  return __awaiter(this, void 0, void 0, function* () {
1500
- const publisher = yield this.apiPush;
1501
1524
  const uniqueId = new ObjectId$1().toHexString();
1502
- yield publisher.send([jobName, JSON.stringify(params), uniqueId]);
1525
+ this.apiPush.send([jobName, JSON.stringify(params), uniqueId]);
1503
1526
  return uniqueId;
1504
1527
  });
1505
1528
  }
1506
1529
  };
1507
1530
  JobManager = __decorate([
1508
- injectable(),
1509
- scoped(Lifecycle.ContainerScoped),
1531
+ singleton(),
1510
1532
  __param(2, inject(DI_CONTAINER)),
1511
1533
  __param(3, injectAll(JOB)),
1512
1534
  __metadata("design:paramtypes", [Configuration,
@@ -1818,9 +1840,10 @@ let LazyAssets = class LazyAssets {
1818
1840
  this.jobMan = jobMan;
1819
1841
  this.collection = connector.database.collection("lazyassets");
1820
1842
  }
1821
- create(jobType, jobParams = {}, jobQue = "main") {
1843
+ create(jobType, jobParamsObj = {}, jobQue = "main") {
1822
1844
  return __awaiter(this, void 0, void 0, function* () {
1823
- const jobName = this.jobMan.tryResolve(jobType, Object.assign(Object.assign({}, jobParams), { lazyId: "" }));
1845
+ const jobName = this.jobMan.tryResolve(jobType, Object.assign(Object.assign({}, jobParamsObj), { lazyId: "" }));
1846
+ const jobParams = yield gzipPromised(JSON.stringify(jobParamsObj));
1824
1847
  const data = {
1825
1848
  jobName,
1826
1849
  jobParams,
@@ -1896,12 +1919,187 @@ AssetResolver = __decorate([
1896
1919
  __metadata("design:paramtypes", [Assets, LazyAssets])
1897
1920
  ], AssetResolver);
1898
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
+
1899
2098
  const express = express_;
1900
2099
  let BackendProvider = class BackendProvider {
1901
- constructor() {
1902
- this.express = express();
1903
- this.express.set("trust proxy", true);
1904
- this.server = createServer(this.express);
2100
+ constructor(config, container) {
2101
+ this.config = config;
2102
+ this.container = container;
1905
2103
  }
1906
2104
  get io() {
1907
2105
  this.ioServer = this.ioServer || new Server(this.server, {
@@ -1916,10 +2114,50 @@ let BackendProvider = class BackendProvider {
1916
2114
  });
1917
2115
  return this.ioServer;
1918
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
+ }
1919
2156
  };
1920
2157
  BackendProvider = __decorate([
1921
2158
  singleton(),
1922
- __metadata("design:paramtypes", [])
2159
+ __param(1, inject(DI_CONTAINER)),
2160
+ __metadata("design:paramtypes", [Configuration, Object])
1923
2161
  ], BackendProvider);
1924
2162
 
1925
2163
  let CacheProcessor = class CacheProcessor {
@@ -2021,31 +2259,6 @@ EndpointProvider = __decorate([
2021
2259
  scoped(Lifecycle.ContainerScoped)
2022
2260
  ], EndpointProvider);
2023
2261
 
2024
- let Fixtures = class Fixtures {
2025
- constructor(fixtures) {
2026
- this.fixtures = fixtures;
2027
- }
2028
- load(output) {
2029
- return __awaiter(this, void 0, void 0, function* () {
2030
- if (!this.fixtures)
2031
- return;
2032
- output = output || {
2033
- write: console.log,
2034
- writeln: t => console.log(t + "\n")
2035
- };
2036
- for (let fixture of this.fixtures) {
2037
- yield fixture.load(output);
2038
- }
2039
- });
2040
- }
2041
- };
2042
- Fixtures = __decorate([
2043
- injectable(),
2044
- scoped(Lifecycle.ContainerScoped),
2045
- __param(0, injectAll(FIXTURE)),
2046
- __metadata("design:paramtypes", [Array])
2047
- ], Fixtures);
2048
-
2049
2262
  const sharp$1 = sharp_;
2050
2263
  const bigSize = 1500;
2051
2264
  const thumbSize = 250;
@@ -2513,157 +2726,6 @@ MemoryCache = __decorate([
2513
2726
  __metadata("design:paramtypes", [Cache])
2514
2727
  ], MemoryCache);
2515
2728
 
2516
- function checkValue(multi, value) {
2517
- if (multi) {
2518
- return Array.isArray(value) && value.every(v => {
2519
- try {
2520
- const id = new ObjectId$1(v);
2521
- return id instanceof ObjectId$1;
2522
- }
2523
- catch (e) {
2524
- return false;
2525
- }
2526
- });
2527
- }
2528
- if (null === value)
2529
- return true;
2530
- try {
2531
- const id = new ObjectId$1(value);
2532
- return id instanceof ObjectId$1;
2533
- }
2534
- catch (e) {
2535
- return false;
2536
- }
2537
- }
2538
- let IsFile = class IsFile {
2539
- validate(value, validationArguments) {
2540
- const [multi] = (validationArguments.constraints || []);
2541
- return checkValue(multi, value);
2542
- }
2543
- };
2544
- IsFile = __decorate([
2545
- ValidatorConstraint()
2546
- ], IsFile);
2547
- let IsObjectId = class IsObjectId {
2548
- validate(value, validationArguments) {
2549
- const [_, multi] = (validationArguments.constraints || []);
2550
- return checkValue(multi, value);
2551
- }
2552
- };
2553
- IsObjectId = __decorate([
2554
- ValidatorConstraint()
2555
- ], IsObjectId);
2556
-
2557
- let OpenApi = class OpenApi {
2558
- constructor(container, customValidation) {
2559
- this.container = container;
2560
- this.customValidation = customValidation;
2561
- this.docs = null;
2562
- }
2563
- get apiDocs() {
2564
- if (!this.docs)
2565
- this.docs = this.createApiDocs();
2566
- return this.docs;
2567
- }
2568
- get apiDocsStr() {
2569
- if (!this.docsStr)
2570
- this.docsStr = JSON.stringify(this.apiDocs);
2571
- return this.docsStr;
2572
- }
2573
- schemaToExample(src, req) {
2574
- var _a, _b, _c;
2575
- return __awaiter(this, void 0, void 0, function* () {
2576
- const maybeRef = src;
2577
- if (maybeRef.$ref) {
2578
- const schemas = this.apiDocs.components.schemas;
2579
- const schema = maybeRef.$ref
2580
- .replace("#/components/schemas/", "")
2581
- .replace("#/definitions/", "");
2582
- return this.schemaToExample(schemas[schema], req);
2583
- }
2584
- let schema = src;
2585
- if (schema.oneOf) {
2586
- schema = Object.assign({}, schema, schema.oneOf[0]);
2587
- }
2588
- if (schema.type === "object") {
2589
- const result = {};
2590
- yield Promise.all(Object.keys(schema.properties).map((key) => __awaiter(this, void 0, void 0, function* () {
2591
- result[key] = yield this.schemaToExample(schema.properties[key], req);
2592
- })));
2593
- return result;
2594
- }
2595
- if (schema.type === "array") {
2596
- return [yield this.schemaToExample(schema.items, req)];
2597
- }
2598
- if (schema.type === "string") {
2599
- if (isDefined(schema.default)) {
2600
- if (isFunction(schema.default)) {
2601
- return schema.default(this.container);
2602
- }
2603
- return schema.default;
2604
- }
2605
- if (schema.format == "date") {
2606
- return new Date().toISOString().substr(0, 10);
2607
- }
2608
- if (schema.format == "date-time") {
2609
- return new Date().toISOString();
2610
- }
2611
- if (schema.enum) {
2612
- return schema.enum[0];
2613
- }
2614
- return "string";
2615
- }
2616
- if (schema.type === "number") {
2617
- return (_a = schema.default) !== null && _a !== void 0 ? _a : 0;
2618
- }
2619
- else if (schema.type === "boolean") {
2620
- return (_b = schema.default) !== null && _b !== void 0 ? _b : false;
2621
- }
2622
- else {
2623
- return (_c = schema.default) !== null && _c !== void 0 ? _c : null;
2624
- }
2625
- });
2626
- }
2627
- createApiDocs() {
2628
- const storage = getMetadataArgsStorage();
2629
- const docs = routingControllersToSpec(storage);
2630
- docs.basePath = "/api/";
2631
- docs.definitions = validationMetadatasToSchemas({
2632
- classTransformerMetadataStorage: defaultMetadataStorage,
2633
- additionalConverters: {
2634
- [ValidationTypes.CUSTOM_VALIDATION]: (meta, options) => {
2635
- const res = isFunction(this.customValidation) ? this.customValidation(meta, options) : this.customValidation;
2636
- if (isObject(res))
2637
- return res;
2638
- const constraints = meta.constraints || [];
2639
- if (meta.constraintCls === IsFile) {
2640
- return {
2641
- multi: constraints[0] || false,
2642
- type: "file"
2643
- };
2644
- }
2645
- if (meta.constraintCls === IsObjectId) {
2646
- return {
2647
- endpoint: constraints[0] || false,
2648
- multi: constraints[1] || false,
2649
- type: "list"
2650
- };
2651
- }
2652
- return null;
2653
- }
2654
- }
2655
- });
2656
- docs.components.schemas = docs.definitions;
2657
- return docs;
2658
- }
2659
- };
2660
- OpenApi = __decorate([
2661
- singleton(),
2662
- __param(0, inject(DI_CONTAINER)),
2663
- __param(1, inject(OPENAPI_VALIDATION)),
2664
- __metadata("design:paramtypes", [Object, Object])
2665
- ], OpenApi);
2666
-
2667
2729
  let TerminalManager = class TerminalManager {
2668
2730
  constructor(logger, config, commands) {
2669
2731
  this.logger = logger;
@@ -4321,6 +4383,8 @@ function createServices() {
4321
4383
  new Parameter("zmqBackPort", 3100),
4322
4384
  new Parameter("zmqRemoteHost", "tcp://127.0.0.1"),
4323
4385
  new Parameter("isWorker", false),
4386
+ new Parameter("startWorker", false),
4387
+ new Parameter("fixtures", true),
4324
4388
  new Parameter("mainEndpoint", ""),
4325
4389
  new Parameter("idChars", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"),
4326
4390
  new Parameter("idSeparator", "-"),
@@ -4520,25 +4584,14 @@ function setupBackend(config, providers, parent) {
4520
4584
  const configuration = diContainer.resolve(Configuration);
4521
4585
  const bp = diContainer.resolve(BackendProvider);
4522
4586
  if (config.restOptions) {
4523
- bp.express.use(bodyParser.json({
4524
- limit: configuration.hasParam("jsonLimit")
4525
- ? configuration.resolve("jsonLimit")
4526
- : "250mb"
4527
- }));
4528
4587
  useContainer(diContainer);
4529
4588
  useExpressServer(bp.express, restOptions);
4530
- // Setup rest ai docs
4531
- let openApi = null;
4532
- bp.express.get("/api-docs", (req, res) => {
4533
- openApi = openApi || diContainer.get(OpenApi);
4534
- res.header("Content-Type", "application/json")
4535
- .status(200)
4536
- .end(openApi.apiDocsStr);
4589
+ }
4590
+ if (config.socketOptions) {
4591
+ diContainer.register(SOCKET_CONTROLLERS, {
4592
+ useValue: new SocketControllers(Object.assign({ io: bp.io }, socketOptions))
4537
4593
  });
4538
4594
  }
4539
- diContainer.register(SOCKET_CONTROLLERS, {
4540
- useValue: new SocketControllers(Object.assign({ io: bp.io }, socketOptions))
4541
- });
4542
4595
  // Connect to mongo if necessary
4543
4596
  if (configuration.hasParam("mongoUri") && configuration.resolve("mongoUri")) {
4544
4597
  console.log("Connecting to MongoDB...");
@@ -4555,5 +4608,5 @@ function setupBackend(config, providers, parent) {
4555
4608
  * Generated bundle index. Do not edit.
4556
4609
  */
4557
4610
 
4558
- export { AssetImageParams, AssetProcessor, AssetResolver, Assets, AuthController, BackendProvider, BaseDoc, Cache, CacheProcessor, Configuration, ConsoleColor, DI_CONTAINER, DocumentArray, EXPRESS, EndpointProvider, ErrorHandlerMiddleware, FIXTURE, Fixtures, Gallery, GalleryCache, GalleryController, HTTP_SERVER, IdGenerator, IsDocumented, IsFile, IsObjectId, JOB, JobManager, JsonResponse, LanguageMiddleware, LazyAssetGenerator, LazyAssets, Logger, MailSender, MemoryCache, MongoConnector, OPENAPI_VALIDATION, OpenApi, PARAMETER, Parameter, PrimitiveArray, Progresses, ResolveEntity, ResponseType, SOCKET_CONTROLLERS, SOCKET_SERVER, TERMINAL_COMMAND, TemplateRenderer, TerminalManager, TokenGenerator, TranslationProvider, Translator, Type, UserManager, assign, broadcast, bufferToStream, camelCaseToDash, colorize, convertValue, copy, copyStream, createIdString, createServices, createTransformer, deleteFile, deleteFromBucket, fileTypeFromBuffer, fileTypeFromStream, filter, firstItem, flatten, getConstructorName, getDirName, getExtension, getFileName, getFunctionParams, getType, getValue, groupBy, hydratePopulated, idToString, injectServices, isArray, isBoolean, isBuffer, isConstructor, isDate, isDefined, isFunction, isInterface, isNullOrUndefined, isObject, isObjectId, isPrimitive, isString, isType, jsonHighlight, lastItem, lcFirst, letsLookupStage, lookupStages, matchField, matchFieldStages, matchStage, md5, mkdirRecursive, multiSubscription, observableFromFunction, padLeft, padRight, paginate, paginateAggregations, prepareUrl, prepareUrlEmpty, prepareUrlSlash, projectStage, promiseTimeout, rand, random, readAndDeleteFile, readFile, regexEscape, regroup, replaceSpecialChars, resolveUser, runCommand, service, setupBackend, streamToBuffer, toImage, ucFirst, uniqueItems, unwindStage, valueToPromise, wrapError, writeFile };
4611
+ export { AssetImageParams, AssetProcessor, AssetResolver, Assets, AuthController, BackendProvider, BaseDoc, Cache, CacheProcessor, Configuration, ConsoleColor, DI_CONTAINER, DocumentArray, EXPRESS, EndpointProvider, ErrorHandlerMiddleware, FIXTURE, Fixtures, Gallery, GalleryCache, GalleryController, HTTP_SERVER, IdGenerator, IsDocumented, IsFile, IsObjectId, JOB, JobManager, JsonResponse, LanguageMiddleware, LazyAssetGenerator, LazyAssets, Logger, MailSender, MemoryCache, MongoConnector, OPENAPI_VALIDATION, OpenApi, PARAMETER, Parameter, PrimitiveArray, Progresses, ResolveEntity, ResponseType, SOCKET_CONTROLLERS, SOCKET_SERVER, TERMINAL_COMMAND, TemplateRenderer, TerminalManager, TokenGenerator, TranslationProvider, Translator, Type, UserManager, assign, broadcast, bufferToStream, camelCaseToDash, colorize, convertValue, copy, copyStream, createIdString, createServices, createTransformer, deleteFile, deleteFromBucket, fileTypeFromBuffer, fileTypeFromStream, filter, firstItem, flatten, getConstructorName, getDirName, getExtension, getFileName, getFunctionParams, getType, getValue, groupBy, gunzipPromised, gzipPromised, hydratePopulated, idToString, injectServices, isArray, isBoolean, isBuffer, isConstructor, isDate, isDefined, isFunction, isInterface, isNullOrUndefined, isObject, isObjectId, isPrimitive, isString, isType, jsonHighlight, lastItem, lcFirst, letsLookupStage, lookupStages, matchField, matchFieldStages, matchStage, md5, mkdirRecursive, multiSubscription, observableFromFunction, padLeft, padRight, paginate, paginateAggregations, prepareUrl, prepareUrlEmpty, prepareUrlSlash, projectStage, promiseTimeout, rand, random, readAndDeleteFile, readFile, regexEscape, regroup, replaceSpecialChars, resolveUser, runCommand, service, setupBackend, streamToBuffer, toImage, ucFirst, uniqueItems, unwindStage, valueToPromise, wrapError, writeFile };
4559
4612
  //# sourceMappingURL=stemy-backend.mjs.map