@stemy/backend 3.2.6 → 3.4.1

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.
@@ -0,0 +1,36 @@
1
+ import { Document, FilterQuery, Model, PipelineStage, Query, Schema } from "mongoose";
2
+ import { DocumentType, ReturnModelType } from "@typegoose/typegoose";
3
+ import { Action } from "routing-controllers";
4
+ import { InjectionToken } from "tsyringe";
5
+ import { IMatchField, InferGeneric, IPaginationBase, IPaginationParams, IProjectOptions, IUnwindOptions, Type } from "../common-types";
6
+ /**
7
+ * A mongoose/typegoose plugin to inject services from the main di container to a schema as virtuals
8
+ * @param schema
9
+ * @param services
10
+ */
11
+ export declare function injectServices(schema: Schema<any>, services?: {
12
+ [prop: string]: InjectionToken<any>;
13
+ }): void;
14
+ /**
15
+ * Decorates a property to inject a service with the help of the injectServices mongoose/typegoose plugin
16
+ * @param token optional InjectionToken to use
17
+ * @return PropertyDecorator
18
+ */
19
+ export declare function service(token?: InjectionToken<any>): PropertyDecorator;
20
+ /**
21
+ * Paginate using a typegoose model using a simple where query and pagination params
22
+ * @param model Typegoose model
23
+ * @param where Simple query to filter the results
24
+ * @param params Pagination params
25
+ */
26
+ export declare function paginate<T extends Type<any>, U = InferGeneric<T>>(model: ReturnModelType<T>, where: FilterQuery<DocumentType<U>>, params: IPaginationParams): Promise<IPaginationBase<DocumentType<U>>>;
27
+ export declare function lookupStages(from: string, localField: string, as?: string, foreignField?: string, shouldUnwind?: boolean): [PipelineStage.Lookup, PipelineStage.Unwind];
28
+ export declare function letsLookupStage(from: string, pipeline: Exclude<PipelineStage, PipelineStage.Merge | PipelineStage.Out | PipelineStage.Search>[], as?: string, letFields?: any): PipelineStage.Lookup;
29
+ export declare function matchStage(match: FilterQuery<any>): PipelineStage.Match;
30
+ export declare function matchField(field: string, filter: any, when: boolean): IMatchField;
31
+ export declare function matchFieldStages(...fields: IMatchField[]): ReadonlyArray<PipelineStage.Match>;
32
+ export declare function projectStage(fields: IProjectOptions): PipelineStage.Project;
33
+ export declare function unwindStage(fieldOrOpts: string | IUnwindOptions): PipelineStage.Unwind;
34
+ export declare function hydratePopulated<T extends Document>(modelType: Model<T>, json: any): T;
35
+ export declare function paginateAggregations<T extends Type<any>, U = InferGeneric<T>>(model: ReturnModelType<T>, aggregations: PipelineStage[], params: IPaginationParams, metaProjection?: any): Promise<IPaginationBase<DocumentType<U>>>;
36
+ export declare function ResolveEntity<T extends Type<any>, U = InferGeneric<T>>(model: ReturnModelType<T>, extraCheck?: (query: Query<DocumentType<U>, any>, action: Action) => Promise<DocumentType<U>>): ParameterDecorator;
package/utils.d.ts CHANGED
@@ -1,13 +1,11 @@
1
1
  /// <reference types="node" />
2
- import { DependencyContainer, InjectionToken } from "tsyringe";
2
+ import { DependencyContainer } from "tsyringe";
3
3
  import { Observable, Subscription } from "rxjs";
4
4
  import { Server } from "socket.io";
5
- import { GridFSBucket } from "mongodb";
6
- import { Document, Expression, FilterQuery, Model, PipelineStage, Query, Schema } from "mongoose";
5
+ import { GridFSBucket, ObjectId } from "mongodb";
6
+ import { Document } from "mongoose";
7
7
  import { Readable, ReadableOptions } from "stream";
8
- import { ObjectId } from "bson";
9
- import { Action } from "routing-controllers";
10
- import { IAssetImageParams, IAssetMeta, IClientSocket, IMatchField, IPaginationBase, IPaginationParams, IProjectOptions, IUnwindOptions, Type } from "./common-types";
8
+ import { IAssetImageParams, IAssetMeta, IClientSocket, Type } from "./common-types";
11
9
  export interface IDIContainers {
12
10
  appContainer: DependencyContainer;
13
11
  }
@@ -38,19 +36,6 @@ export declare function uniqueItems<T>(value: T[]): T[];
38
36
  export declare function getValue(obj: any, key: string, defaultValue?: any, treeFallback?: boolean): any;
39
37
  export declare function groupBy<T>(items: T[], cb: (item: T) => string): {};
40
38
  export declare function convertValue(value: any, type: string): any;
41
- export declare function injectServices(schema: Schema<any>, services: {
42
- [prop: string]: InjectionToken<any>;
43
- }): void;
44
- export declare function paginate<T extends Document>(model: Model<T>, where: FilterQuery<T>, params: IPaginationParams): Promise<IPaginationBase<T>>;
45
- export declare function lookupStages(from: string, localField: string, as?: string, foreignField?: string, shouldUnwind?: boolean): [PipelineStage.Lookup, PipelineStage.Unwind];
46
- export declare function letsLookupStage(from: string, pipeline: Exclude<PipelineStage, PipelineStage.Merge | PipelineStage.Out | PipelineStage.Search>[], as?: string, letFields?: any): PipelineStage.Lookup;
47
- export declare function matchStage(match: Expression | Record<string, Expression>): PipelineStage.Match;
48
- export declare function matchField(field: string, filter: any, when: boolean): IMatchField;
49
- export declare function matchFieldStages(...fields: IMatchField[]): ReadonlyArray<PipelineStage.Match>;
50
- export declare function projectStage(fields: IProjectOptions): PipelineStage.Project;
51
- export declare function unwindStage(fieldOrOpts: string | IUnwindOptions): PipelineStage.Unwind;
52
- export declare function hydratePopulated<T extends Document>(modelType: Model<T>, json: any): T;
53
- export declare function paginateAggregations<T extends Document>(model: Model<T>, aggregations: PipelineStage[], params: IPaginationParams, metaProjection?: any): Promise<IPaginationBase<T>>;
54
39
  export declare function toImage<T = Buffer | Readable>(src: T, params?: IAssetImageParams, meta?: IAssetMeta): Promise<T>;
55
40
  export declare function bufferToStream(buffer: Buffer): Readable;
56
41
  export declare function streamToBuffer(stream: Readable): Promise<Buffer>;
@@ -64,9 +49,6 @@ export declare function valueToPromise(value: any): Promise<any>;
64
49
  export declare function promiseTimeout(timeout?: number, error?: boolean): Promise<string>;
65
50
  export declare function getConstructorName(type: Type<any>): string;
66
51
  export declare function getFunctionParams(func: Function): string[];
67
- export declare function proxyFunction(name: string): Function;
68
- export declare function proxyFunctions(schema: Schema, helper: Type<any>, paramName?: string): void;
69
- export declare function ResolveEntity<T extends Document>(model: Model<T>, extraCheck?: (query: Query<T, any>, action: Action) => T | Promise<T>): ParameterDecorator;
70
52
  export declare function getFileName(path: string, withExtension?: boolean): string;
71
53
  export declare function getExtension(path: string): string;
72
54
  export declare function idToString(value: any): any;
@@ -1,2 +0,0 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("path"),require("body-parser"),require("jsonwebtoken"),require("tsyringe"),require("routing-controllers"),require("socket-controllers"),require("routing-controllers-openapi"),require("class-transformer/storage"),require("class-validator"),require("class-validator-jsonschema"),require("child_process"),require("crypto"),require("rxjs"),require("rxjs/internal/util/canReportError"),require("fs"),require("mongoose"),require("mongoose/lib/utils"),require("stream"),require("bson"),require("sharp"),require("fontkit"),require("file-type"),require("axios"),require("mongodb"),require("dotenv"),require("node-cron"),require("zeromq"),require("rxjs/operators"),require("http"),require("express"),require("socket.io"),require("uuid"),require("nodemailer"),require("handlebars"),require("bcrypt"),require("moment")):"function"==typeof define&&define.amd?define("@stemy/backend",["exports","path","body-parser","jsonwebtoken","tsyringe","routing-controllers","socket-controllers","routing-controllers-openapi","class-transformer/storage","class-validator","class-validator-jsonschema","child_process","crypto","rxjs","rxjs/internal/util/canReportError","fs","mongoose","mongoose/lib/utils","stream","bson","sharp","fontkit","file-type","axios","mongodb","dotenv","node-cron","zeromq","rxjs/operators","http","express","socket.io","uuid","nodemailer","handlebars","bcrypt","moment"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).stemy=e.stemy||{},e.stemy.backend={}),e.path,e["body-parser"],e.jsonwebtoken,e.tsyringe,e["routing-controllers"],e["socket-controllers"],e["routing-controllers-openapi"],e["class-transformer/storage"],e["class-validator"],e["class-validator-jsonschema"],e.child_process,e.crypto,e.rxjs,e.rxjs["internal/util/canReportError"],e.fs,e.mongoose,e["mongoose-lib-utils"],e.stream,e.bson,e.sharp,e.fontkit,e["file-type"],e.axios,e.mongodb,e.dotenv,e["node-cron"],e.zeromq,e.rxjs.operators,e.http,e.express,e.socket.io,e.uuid,e.nodemailer,e.handlebars,e.bcrypt,e.moment)}(this,(function(e,t,n,r,o,i,s,a,c,u,l,f,h,d,p,g,y,v,m,b,w,j,P,O,R,_,x,C,S,k,M,A,T,F,I,N,E){"use strict";function D(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function B(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var q=D(w),z=D(j),L=D(O),H=D(_),J=D(M),G=D(A),U=B(I),$=D(E),V=function(e,t){return(V=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)};function Y(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}V(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function W(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}Object.create;function X(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function Q(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function Z(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(Q(arguments[t]));return e}Object.create;var K=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},ee=q.default,te={appContainer:null};function ne(e){return null==e||void 0===e}function re(e){return!ne(e)}function oe(e){var t=new RegExp("\\s([a-zA-Z]+)");return Object.prototype.toString.call(e).match(t)[1].toLowerCase()}function ie(e){return"object"==oe(e)}function se(e){return Array.isArray(e)}function ae(e){return"boolean"==typeof e}function ce(e){return!!e&&e[Symbol.toPrimitive]&&!isNaN(e)&&void 0!==e.getDate}function ue(e){var t=typeof e;return null==e||"object"!==t&&"function"!==t}function le(e){return"string"==typeof e}function fe(e){return"function"==typeof e}function he(e){return(e&&"function"==typeof e&&e.prototype&&e.prototype.constructor)===e&&"Object"!==e.name}function de(e){return he(e)}function pe(e,t){var n,r;if(!e||"object"!=typeof e||se(e)||!ie(t))return!1;var o=Object.keys(t);try{for(var i=X(o),s=i.next();!s.done;s=i.next()){var a=s.value,c=t[a]||"";if(c.startsWith("*")){if(c=c.substr(1),e.hasOwnProperty(a)&&oe(e[a])!==c)return!1}else if(!e.hasOwnProperty(a)||oe(e[a])!==c)return!1}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}return!0}function ge(e){return e?e[0].toLowerCase()+e.substr(1):""}function ye(e,t,n,r){void 0===r&&(r=!1);var o=(t=t||"").split("."),i="";do{i+=o.shift(),!re(e)||!re(e[i])||"object"!=typeof e[i]&&o.length?o.length?i+=".":(n=void 0===n?t.replace(new RegExp(i+"$"),"{"+i+"}"):n,e=r&&e||n):(e=e[i],i="")}while(o.length);return e}function ve(e,t){switch(t){case"boolean":return"no"!=(e="string"==typeof e?e.toLowerCase():e)&&"false"!=e&&"0"!=e&&!!e;case"number":var n=parseFloat(e);return isNaN(n)?0:n;case"array":try{return JSON.parse(e)}catch(t){return(""+e).split(", ")}}return e}function me(e,t){var n={};Object.keys(t).forEach((function(r){e.virtual(r).get((function(){var e=te.appContainer;return n[r]=n[r]||(e?e.resolve(t[r]):{}),n[r]}))}))}function be(e){return{$match:e}}function we(e,t){var n,r,o=e.hydrate(t),i=function(e,n){var r=n.ref,i=n.type;if(Array.isArray(i)&&i.length>0&&(r=i[0].ref),!r)return"continue";var s=v.getValue(e,t),a=function(e){return null==e||e instanceof y.Types.ObjectId?e:we(y.model(r),e)};if(Array.isArray(s))return v.setValue(e,s.map(a),o),"continue";v.setValue(e,a(s),o)};try{for(var s=X(Object.entries(e.schema.obj)),a=s.next();!a.done;a=s.next()){var c=Q(a.value,2);i(c[0],c[1])}}catch(e){n={error:e}}finally{try{a&&!a.done&&(r=s.return)&&r.call(s)}finally{if(n)throw n.error}}return o}var je={x:"number",y:"number",w:"number",h:"number"};function Pe(e){var t=e;if(le(e))try{t=JSON.parse(e)}catch(e){return null}return pe(t,je)?{width:Math.round(t.w),height:Math.round(t.h),top:Math.round(t.y),left:Math.round(t.x)}:null}function Oe(e,t,n){return K(this,void 0,void 0,(function(){var r,o,i,s,a,c,u,l,f,h,d,p;return W(this,(function(g){switch(g.label){case 0:return t=t||{},r=Pe((n=n||{}).crop),"svg"===n.extension||0==Object.keys(t).length&&!r?[2,e]:(t.rotation=isNaN(t.rotation)?0:90*Math.round(t.rotation/90),t.canvasScaleX=isNaN(t.canvasScaleX)?1:Number(t.canvasScaleX),t.canvasScaleY=isNaN(t.canvasScaleY)?1:Number(t.canvasScaleY),t.scaleX=isNaN(t.scaleX)?1:Number(t.scaleX),t.scaleY=isNaN(t.scaleY)?1:Number(t.scaleY),t.crop=ae(t.crop)?t.crop:"true"==t.crop,e instanceof m.Readable?[4,_e(e)]:[3,2]);case 1:return i=g.sent(),[3,3];case 2:i=e,g.label=3;case 3:o=i,g.label=4;case 4:return g.trys.push([4,9,,10]),s=Pe(t.cropBefore||(t.crop?n.cropBefore:null)),a=Pe(t.cropAfter||(t.crop?n.cropAfter:null)),[4,(c=ee(o)).metadata()];case 5:return u=g.sent(),l=u.width,f=u.height,s?(l=s.width,f=s.height,c=c.extract(s)):r&&(l=r.width,f=r.height,c=c.extract(r)),h=(null==n?void 0:n.canvasScaleX)||1,d=(null==n?void 0:n.canvasScaleY)||1,t.canvasScaleX===h&&t.canvasScaleY===d||(l=Math.round(l*t.canvasScaleX),f=Math.round(f*t.canvasScaleY),c=c.resize({width:l,height:f,background:"#00000000",fit:"contain"})),1===t.scaleX&&1===t.scaleY||(l=Math.round(l*t.scaleX),f=Math.round(f*t.scaleY),c=c.resize({width:l,height:f,background:"#00000000",fit:"fill"})),a&&(c=c.extract(a)),0===t.rotation?[3,7]:[4,c.toBuffer()];case 6:o=g.sent(),c=ee(o).rotate(t.rotation),g.label=7;case 7:return[4,c.toBuffer()];case 8:return o=g.sent(),[2,e=e instanceof m.Readable?Re(o):o];case 9:return p=g.sent(),console.log("Image conversion error",p),[2,e=e instanceof m.Readable?Re(o):o];case 10:return[2]}}))}))}function Re(e){var t=new m.PassThrough;return t.end(e),t}function _e(e){return new Promise((function(t,n){var r=[];e.on("data",(function(e){r.push(e)})),e.on("error",n),e.on("end",(function(){return t(Buffer.concat(r))}))}))}var xe=function(e){function t(t,n){var r=e.call(this,n)||this;return null==t||t.on("data",(function(e){r.push(e)})),null==t||t.on("end",(function(){r.push(null)})),null==t||t.on("error",(function(e){r.emit("error",e)})),r}return Y(t,e),t.prototype._read=function(e){},t}(m.Readable);function Ce(e,t){return new xe(e,t)}function Se(e,t){return void 0===t&&(t=null),new Promise((function(n,r){g.mkdir(e,{mode:t||511,recursive:!0},(function(e){e?r(e):n()}))}))}function ke(e){return new Promise((function(t,n){g.readFile(e,(function(e,r){e?n(e):t(r)}))}))}function Me(e){return e instanceof Promise?e:Promise.resolve(e)}function Ae(e,t){return void 0===e&&(e=1e3),void 0===t&&(t=!1),new Promise((function(n,r){setTimeout((function(){t?r("Timeout exceeded: "+e+"ms"):n("Timeout: "+e+"ms")}),e)}))}function Te(e){return e.prototype.constructor.name}function Fe(e){var t=e.toString().replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/(.)*/g,"").replace(/{[\s\S]*}/,"").replace(/=>/g,"").trim(),n=t.indexOf("(")+1,r=t.length-1,o=t.substring(n,r).split(", "),i=[];return o.forEach((function(e){(e=e.replace(/=[\s\S]*/g,"").trim()).length>0&&i.push(e)})),i}function Ie(e){return function(){var t=Array.from(arguments);return t.unshift(this),this.helper[e].apply(this.helper,t)}}function Ne(e){return Array.isArray(e)?e.map(Ne):e instanceof b.ObjectId?e.toHexString():null}function Ee(e,t){Array.from(Object.values(e.sockets.sockets)).forEach(t)}function De(e,t){return Math.round(Be(e,t))}function Be(e,t){return e+Math.random()*(t-e)}function qe(e,t){return new Promise((function(n,r){e.delete(t,(function(e){var o=e;!e||le(o=e.message||e||"")&&o.startsWith("FileNotFound")?n(t.toHexString()):r(o)}))}))}var ze,Le=function(){return!0};function He(e,t,n){var r,o;if(n=n||Le,ue(t)||ce(t)||fe(t))return t;if(se(t))return e=se(e)?Array.from(e):[],t.forEach((function(r,o){n(r,o,e,t)&&(e.length>o?e[o]=He(e[o],r,n):e.push(He(null,r,n)))})),e;var i=fe(t.__shouldCopy)?t.__shouldCopy:function(){return!0};if(he(t.constructor)){if(!1===t.__shouldCopy)return t;if(!e)try{e=new t.constructor}catch(n){var s=t.constructor.prototype||t.prototype;e=Object.create(s)}}else e=Object.assign({},e||{});if(e instanceof Map){if(t instanceof Map)try{for(var a=X(t.entries()),c=a.next();!c.done;c=a.next()){var u=Q(c.value,2),l=u[0],f=u[1];n(f,l,e,t)&&e.set(l,i(l,f)?He(e.get(l),f,n):f)}}catch(e){r={error:e}}finally{try{c&&!c.done&&(o=a.return)&&o.call(a)}finally{if(r)throw r.error}}return e}var h=Object.keys(t);e=h.reduce((function(e,r){return n(t[r],r,e,t)?(e[r]=i(r,t[r])?He(e[r],t[r],n):t[r],e):e}),e);var d=Object.getOwnPropertyDescriptors(t);return(h=Object.keys(d).filter((function(e){return h.indexOf(e)<0}))).forEach((function(t){Object.defineProperty(e,t,d[t])})),e}e.ConsoleColor=void 0,(ze=e.ConsoleColor||(e.ConsoleColor={})).Reset="",ze.Bright="",ze.Dim="",ze.Underscore="",ze.Blink="",ze.Reverse="",ze.Hidden="",ze.FgBlack="",ze.FgRed="",ze.FgGreen="",ze.FgYellow="",ze.FgBlue="",ze.FgMagenta="",ze.FgCyan="",ze.FgWhite="",ze.FgDefault="",ze.BgBlack="",ze.BgRed="",ze.BgGreen="",ze.BgYellow="",ze.BgBlue="",ze.BgMagenta="",ze.BgCyan="",ze.BgWhite="",ze.BgDefault="";var Je={keyColor:e.ConsoleColor.FgWhite,numberColor:e.ConsoleColor.FgBlue,stringColor:e.ConsoleColor.FgYellow,trueColor:e.ConsoleColor.FgGreen,falseColor:e.ConsoleColor.FgRed,nullColor:e.ConsoleColor.BgMagenta};function Ge(t,n){return""+n+t+e.ConsoleColor.Reset}function Ue(t,n){var r=Object.assign({},Je,n);return(le(t)?t:JSON.stringify(t,null,2)).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+]?\d+)?)/g,(function(t){var n=r.numberColor;return/^"/.test(t)?/:$/.test(t)?n=r.keyColor:(n=r.stringColor,t='"'+t.substr(1,t.length-2)+'"'):n=/true/.test(t)?r.trueColor:/false/.test(t)?r.falseColor:/null/.test(t)?r.nullColor:n,""+n+t+e.ConsoleColor.Reset}))}var $e=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s};function Ve(e,t){if(e)return Array.isArray(t)&&t.every((function(e){try{return new b.ObjectId(e)instanceof b.ObjectId}catch(e){return!1}}));if(null===t)return!0;try{return new b.ObjectId(t)instanceof b.ObjectId}catch(e){return!1}}e.IsFile=function(){function e(){}return e.prototype.validate=function(e,t){return Ve(Q(t.constraints||[],1)[0],e)},e}(),e.IsFile=$e([u.ValidatorConstraint()],e.IsFile),e.IsObjectId=function(){function e(){}return e.prototype.validate=function(e,t){var n=Q(t.constraints||[],2);n[0];return Ve(n[1],e)},e}(),e.IsObjectId=$e([u.ValidatorConstraint()],e.IsObjectId);var Ye=null;var We,Xe=Function,Qe=Symbol.for("fixture-token"),Ze=Symbol.for("job-token"),Ke=Symbol.for("express-token"),et=Symbol.for("http-server-token"),tt=Symbol.for("socket-server-token"),nt=Symbol.for("parameter-token"),rt=Symbol.for("di-container-token"),ot=function(e,t,n){void 0===n&&(n=null),this.name=e,this.defaultValue=t,this.resolver=n},it=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},st=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},at=q.default,ct=z.default,ut=["application/font-woff","application/font-woff2","application/x-font-opentype","application/x-font-truetype","application/x-font-datafork","font/woff","font/woff2","font/otf","font/ttf","font/datafork"],lt=["image/jpeg","image/jpg","image/png","image/svg+xml"],ft=["postscriptName","fullName","familyName","subfamilyName","copyright","version","unitsPerEm","ascent","descent","lineGap","underlinePosition","underlineThickness","italicAngle","capHeight","xHeight","numGlyphs","characterSet","availableFeatures"];e.AssetProcessor=We=function(){function e(){}return e.checkTextFileType=function(e){return e.mime.indexOf("text")>=0||e.mime.indexOf("xml")>=0},e.fixTextFileType=function(e,t){return t.toString("utf8").indexOf("<svg")>=0?{ext:"svg",mime:"image/svg+xml"}:e},e.fileTypeFromBuffer=function(e){var t;return st(this,void 0,void 0,(function(){var n;return W(this,(function(r){switch(r.label){case 0:return[4,P.fromBuffer(e)];case 1:return n=null!==(t=r.sent())&&void 0!==t?t:{ext:"txt",mime:"text/plain"},We.checkTextFileType(n)?[2,We.fixTextFileType(n,e)]:[2,n]}}))}))},e.extractFontFormat=function(e){var t=e.constructor.name,n=e.directory.tag;switch(t){case"TTFFont":return"OTTO"===n?"opentype":"truetype";case"WOFF2Font":return"woff2";case"WOFFFont":return"woff";case"DFont":return"datafork"}return null},e.isImage=function(e){return lt.indexOf(e)>=0},e.copyImageMeta=function(e,t,n){return st(this,void 0,void 0,(function(){var r,o,i;return W(this,(function(s){switch(s.label){case 0:return"image/svg+xml"===n.mime?((r=/<svg([^<>]+)>/gi.exec(e.toString("utf8")))&&r.length>1&&(r[1].match(/([a-z]+)="([^"]+)"/gi).forEach((function(e){if(!(e.length<5)){var n=Q(e.split("="),2),r=n[0],o=n[1].replace(/"/gi,"");t[r]=isNaN(o)?o:Number(o)}})),t.viewBox&&(isNaN(t.width)||isNaN(t.height))&&(o=t.viewBox.split(" "),t.width=Number(o[0])+Number(o[2]),t.height=Number(o[1])+Number(o[3])),isNaN(t.width)||isNaN(t.height)||(t.svgSize={x:t.width,y:t.height})),[2,e]):[4,at(e).rotate().toBuffer({resolveWithObject:!0})];case 1:return i=s.sent(),Object.assign(t,i.info),[2,i.data]}}))}))},e.isFont=function(e){return ut.indexOf(e)>=0},e.copyFontMeta=function(e,t){var n=ct.create(e);t.format=We.extractFontFormat(n),ft.forEach((function(e){t[e]=n[e]}))},e.prototype.process=function(e,t,n){return st(this,void 0,void 0,(function(){return W(this,(function(r){switch(r.label){case 0:return We.isImage(n.mime)?[4,We.copyImageMeta(e,t,n)]:[3,2];case 1:e=r.sent(),r.label=2;case 2:return We.isFont(n.mime)&&We.copyFontMeta(e,t),[2,e]}}))}))},e}(),e.AssetProcessor=We=it([o.injectable(),o.scoped(o.Lifecycle.ContainerScoped)],e.AssetProcessor);var ht=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},dt=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},pt=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};e.Configuration=function(){function e(e){var t=this;H.default.config(),this.paramMap={},(e||[]).forEach((function(e){return t.add(e)}))}return e.prototype.add=function(e){var t=this.paramMap[e.name]||e;t.defaultValue=e.defaultValue,t.resolver=e.resolver||t.resolver,this.paramMap[e.name]=t},e.prototype.hasParam=function(e){return!!this.paramMap[e]},e.prototype.resolve=function(e){var t=this.paramMap[e];if(!t)throw new Error("Parameter with name: '"+e+"' does not exists in configuration");var n=t.name.replace(/\.?([A-Z|0-9]+)/g,(function(e,t){return"_"+t.toLowerCase()})).replace(/\./gi,"_").replace(/^_/,"").toUpperCase(),r=process.env[n];if(void 0!==r){var o=fe(t.resolver)?t.resolver(r):ve(r,oe(t.defaultValue));return console.log("Processing param value",e,n,r,o),o}return t.defaultValue},e}(),e.Configuration=ht([o.injectable(),o.scoped(o.Lifecycle.ContainerScoped),pt(0,o.injectAll(nt)),dt("design:paramtypes",[Array])],e.Configuration);var gt=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},yt=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},vt=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))};e.MongoConnector=function(){function e(e){this.configuration=e,this.conn=null,this.db=null,this.fsBucket=null}return Object.defineProperty(e.prototype,"connection",{get:function(){return this.conn},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"database",{get:function(){return this.db},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"bucket",{get:function(){return this.fsBucket},enumerable:!1,configurable:!0}),e.prototype.connect=function(){return vt(this,void 0,void 0,(function(){var e;return W(this,(function(t){switch(t.label){case 0:return this.db?[2,this.db]:(e=this,[4,y.connect(this.configuration.resolve("mongoUri"),{dbName:this.configuration.resolve("mongoDb"),user:this.configuration.resolve("mongoUser"),pass:this.configuration.resolve("mongoPassword"),useNewUrlParser:!0,useUnifiedTopology:!0})]);case 1:return e.conn=t.sent().connection,this.db=this.conn.db,this.fsBucket=new R.GridFSBucket(this.db,{bucketName:"assets"}),[2]}}))}))},e}(),e.MongoConnector=gt([o.injectable(),o.singleton(),yt("design:paramtypes",[e.Configuration])],e.MongoConnector);var mt=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},bt=function(){function e(e,t,n){this.mId=e,this.data=t,this.collection=n}return Object.defineProperty(e.prototype,"id",{get:function(){return this.mId.toHexString()},enumerable:!1,configurable:!0}),e.prototype.save=function(){return this.collection.updateOne({_id:this.mId},{$set:this.toJSON()})},e.prototype.load=function(){return mt(this,void 0,void 0,(function(){var e;return W(this,(function(t){switch(t.label){case 0:return[4,this.collection.findOne({_id:this.mId})];case 1:return e=t.sent(),this.deleted=!e,this.data=e||{},[2,this]}}))}))},e.prototype.toJSON=function(){var e=Object.assign({},this.data);return delete e._id,e.id=this.id,e},e}(),wt=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},jt=function(e){function t(t,n,r,o){var i=e.call(this,t,n,r)||this;return i.bucket=o,i}return Y(t,e),Object.defineProperty(t.prototype,"filename",{get:function(){return this.data.filename},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"contentType",{get:function(){return this.data.contentType},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"metadata",{get:function(){return this.data.metadata},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"stream",{get:function(){return this.bucket.openDownloadStream(this.mId)},enumerable:!1,configurable:!0}),t.prototype.unlink=function(){return wt(this,void 0,void 0,(function(){return W(this,(function(e){return[2,qe(this.bucket,this.mId)]}))}))},t.prototype.getBuffer=function(){return _e(this.stream)},t.prototype.download=function(e){return wt(this,void 0,void 0,(function(){return W(this,(function(t){switch(t.label){case 0:return(e=Object.assign(this.metadata,e||{})).downloadCount=isNaN(e.downloadCount)||!e.firstDownload?1:e.downloadCount+1,e.firstDownload=e.firstDownload||new Date,e.lastDownload=new Date,[4,this.collection.updateOne({_id:this.mId},{$set:{metadata:e}})];case 1:return t.sent(),[2,this.stream]}}))}))},t.prototype.getImage=function(e){return void 0===e&&(e=null),wt(this,void 0,void 0,(function(){return W(this,(function(t){return[2,Oe(this.stream,e,this.metadata)]}))}))},t.prototype.downloadImage=function(e,t){return wt(this,void 0,void 0,(function(){var n;return W(this,(function(r){switch(r.label){case 0:return n=Oe,[4,this.download(t)];case 1:return[2,n.apply(void 0,[r.sent(),e,this.metadata])]}}))}))},t}(bt),Pt=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},Ot=function(){function e(e,t,n,r){this.buffer=e,this.filename=t,this.contentType=n,this.metadata=r,this.id=(new b.ObjectId).toHexString()}return Object.defineProperty(e.prototype,"stream",{get:function(){return Re(this.buffer)},enumerable:!1,configurable:!0}),e.prototype.unlink=function(){return Pt(this,void 0,void 0,(function(){return W(this,(function(e){throw new Error("Temp asset '"+this.id+"' can not be removed!")}))}))},e.prototype.getBuffer=function(){return Pt(this,void 0,void 0,(function(){return W(this,(function(e){return[2,this.buffer]}))}))},e.prototype.download=function(e){return Pt(this,void 0,void 0,(function(){return W(this,(function(e){return[2,this.stream]}))}))},e.prototype.downloadImage=function(e,t){return Object.assign(this.metadata,t||{}),Oe(this.stream,e,this.metadata)},e.prototype.getImage=function(e){return this.downloadImage(e)},e.prototype.save=function(){return Pt(this,void 0,void 0,(function(){return W(this,(function(e){return[2,this]}))}))},e.prototype.load=function(){return Pt(this,void 0,void 0,(function(){return W(this,(function(e){return[2,this]}))}))},e.prototype.toJSON=function(){return{id:this.id,filename:this.filename,contentType:this.contentType,metadata:this.metadata}},e}(),Rt=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},_t=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},xt=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))};e.Assets=function(){function t(e,t){var n;this.connector=e,this.assetProcessor=t,this.bucket=e.bucket,this.collection=null===(n=e.database)||void 0===n?void 0:n.collection("assets.files")}return t.prototype.write=function(t,n,r){return void 0===n&&(n=null),void 0===r&&(r=null),xt(this,void 0,void 0,(function(){var o,i,s,a;return W(this,(function(c){switch(c.label){case 0:return o=Ce(t),[4,_e(t)];case 1:i=c.sent(),s={ext:"",mime:n},c.label=2;case 2:return c.trys.push([2,4,,5]),[4,e.AssetProcessor.fileTypeFromBuffer(i)];case 3:return s=c.sent(),[3,5];case 4:if(a=c.sent(),!s.mime)throw"Can't determine mime type";return console.log("Can't determine mime type",a),[3,5];case 5:return r=r||{},[2,this.upload(o,s,r)]}}))}))},t.prototype.writeBuffer=function(t,n,r){return void 0===n&&(n=null),void 0===r&&(r=null),xt(this,void 0,void 0,(function(){var o,i;return W(this,(function(s){switch(s.label){case 0:o={ext:"",mime:r},s.label=1;case 1:return s.trys.push([1,3,,4]),[4,e.AssetProcessor.fileTypeFromBuffer(t)];case 2:return o=s.sent(),[3,4];case 3:if(i=s.sent(),!o.mime)throw"Can't determine mime type";return console.log("Can't determine mime type",i),[3,4];case 4:return n=n||{},[4,this.assetProcessor.process(t,n,o)];case 5:return t=s.sent(),[2,this.upload(Re(t),o,n)]}}))}))},t.prototype.writeUrl=function(e,t){return void 0===t&&(t=null),xt(this,void 0,void 0,(function(){var n;return W(this,(function(r){switch(r.label){case 0:return[4,L.default({url:e,responseType:"arraybuffer"})];case 1:return n=r.sent().data,[2,this.writeBuffer(n,t)]}}))}))},t.prototype.download=function(t,n){return void 0===n&&(n=null),xt(this,void 0,void 0,(function(){var r,o,i,s;return W(this,(function(a){switch(a.label){case 0:return[4,L.default({url:t,responseType:"arraybuffer"})];case 1:r=a.sent().data,o={ext:"",mime:n},a.label=2;case 2:return a.trys.push([2,4,,5]),[4,e.AssetProcessor.fileTypeFromBuffer(r)];case 3:return o=a.sent(),[3,5];case 4:if(i=a.sent(),!o.mime)throw"Can't determine mime type";return console.log("Can't determine mime type",i),[3,5];case 5:return s={filename:t,extension:(o.ext||"").trim()},[4,this.assetProcessor.process(r,s,o)];case 6:return r=a.sent(),[2,new Ot(r,t,o.mime,s)]}}))}))},t.prototype.read=function(e){return xt(this,void 0,void 0,(function(){return W(this,(function(t){return[2,e?this.find({_id:new b.ObjectId(e)}):null]}))}))},t.prototype.find=function(e){return xt(this,void 0,void 0,(function(){var t;return W(this,(function(n){switch(n.label){case 0:return[4,this.collection.findOne(e)];case 1:return[2,(t=n.sent())?new jt(t._id,t,this.collection,this.bucket):null]}}))}))},t.prototype.findMany=function(e){return xt(this,void 0,void 0,(function(){var t,n,r,o,i,s,a;return W(this,(function(c){switch(c.label){case 0:return[4,this.collection.find(e).toArray()];case 1:t=c.sent()||[],n=[];try{for(r=X(t),o=r.next();!o.done;o=r.next())(i=o.value)&&n.push(new jt(i._id,i,this.collection,this.bucket))}catch(e){s={error:e}}finally{try{o&&!o.done&&(a=r.return)&&a.call(r)}finally{if(s)throw s.error}}return[2,n]}}))}))},t.prototype.deleteMany=function(e){return xt(this,void 0,void 0,(function(){var t;return W(this,(function(n){switch(n.label){case 0:return[4,this.findMany(e)];case 1:return t=n.sent(),[2,Promise.all(t.map((function(e){return e.unlink()})))]}}))}))},t.prototype.unlink=function(e){return xt(this,void 0,void 0,(function(){var t;return W(this,(function(n){switch(n.label){case 0:return[4,this.read(e)];case 1:return(t=n.sent())?[2,t.unlink()]:[2,null]}}))}))},t.prototype.upload=function(e,t,n){return xt(this,void 0,void 0,(function(){var r,o=this;return W(this,(function(i){return r=t.mime.trim(),(n=Object.assign({downloadCount:0,firstDownload:null,lastDownload:null},n||{})).filename=n.filename||(new b.ObjectId).toHexString(),n.extension=(t.ext||"").trim(),[2,new Promise((function(t,i){var s=o.bucket.openUploadStream(n.filename);e.pipe(s).on("error",(function(e){i(e.message||e)})).on("finish",(function(){var e=new jt(s.id,{filename:n.filename,contentType:r,metadata:n},o.collection,o.bucket);e.save().then((function(){t(e)}),(function(e){i(e.message||e)}))}))}))]}))}))},t}(),e.Assets=Rt([o.injectable(),o.scoped(o.Lifecycle.ContainerScoped),_t("design:paramtypes",[e.MongoConnector,e.AssetProcessor])],e.Assets);var Ct=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},St=function(e){function t(t,n,r,o,i){var s=e.call(this,t,n,r)||this;return s.assets=o,s.progresses=i,s}return Y(t,e),Object.defineProperty(t.prototype,"jobName",{get:function(){return this.data.jobName},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"jobParams",{get:function(){return this.data.jobParams},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"jobQue",{get:function(){return this.data.jobQue},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"progressId",{get:function(){return this.data.progressId},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"assetId",{get:function(){return this.data.assetId},enumerable:!1,configurable:!0}),t.prototype.unlink=function(){return Ct(this,void 0,void 0,(function(){return W(this,(function(e){switch(e.label){case 0:return[4,this.load()];case 1:return e.sent(),this.progressId?[3,3]:[4,this.collection.deleteOne({_id:this.mId})];case 2:e.sent(),e.label=3;case 3:return[2,qe(this.assets.bucket,new b.ObjectId(this.assetId))]}}))}))},t.prototype.startWorking=function(){var e=this;this.load().then((function(){e.deleted||(e.progresses.get(e.progressId).then((function(e){null==e||e.cancel()})),e.startWorkingOnAsset(!1).then((function(){console.log("Started working on lazy asset: "+e.id)})).catch((function(t){console.log("Can't start working on lazy asset: "+e.id+"\nReason: "+t)})))}))},t.prototype.loadAsset=function(){return Ct(this,void 0,void 0,(function(){return W(this,(function(e){switch(e.label){case 0:return[4,this.load()];case 1:return e.sent(),this.deleted?[2,null]:this.assetId?[2,this.assets.read(this.assetId)]:this.progressId?[4,this.progresses.waitToFinish(this.progressId)]:[3,3];case 2:return e.sent(),[2,this.loadAsset()];case 3:return[4,this.startWorkingOnAsset(!0)];case 4:return e.sent(),[2,this.loadAsset()]}}))}))},t.prototype.writeAsset=function(e){return Ct(this,void 0,void 0,(function(){return W(this,(function(t){switch(t.label){case 0:return this.data.assetId=e.id,[4,this.save()];case 1:return t.sent(),[2,e]}}))}))},t.prototype.startWorkingOnAsset=function(e){return Ct(this,void 0,void 0,(function(){var t;return W(this,(function(n){switch(n.label){case 0:return t=this.data,[4,this.progresses.create()];case 1:return t.progressId=n.sent().id,this.data.assetId=null,[4,this.save()];case 2:return n.sent(),[4,this.progresses.jobMan.enqueueWithName(this.data.jobName,Object.assign(Object.assign({},this.data.jobParams),{lazyId:this.id,fromLoad:e}))];case 3:return n.sent(),[2]}}))}))},t}(bt),kt=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},Mt=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},At=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}},Tt=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))};e.JobManager=function(){function t(e,t,n){var r=this;this.config=e,this.container=t,this.jobTypes=n||[],this.jobs=this.jobTypes.reduce((function(e,t){var n=Te(t);return e[n]=function(e,o){var i=r.resolveJobInstance(t,e,o),s={sendMessage:function(e,t){t.uniqueId=o,r.workerPush.send([e,JSON.stringify(t)])}};return s.sendMessage("job-started",{name:n}),i.process(s)},e}),{}),this.messages=new d.Subject,this.processing=!1,this.maxTimeout=this.config.resolve("jobTimeout")}return t.prototype.on=function(e,t){return this.messages.pipe(S.filter((function(t){return t.message===e}))).pipe(S.map((function(e){return e.params}))).subscribe(t)},t.prototype.process=function(e,t){return void 0===t&&(t={}),Tt(this,void 0,void 0,(function(){var n;return W(this,(function(r){n=null;try{n=this.resolveJobInstance(e,t)}catch(n){throw"Can't resolve params for job: "+Te(e)+", with params: "+JSON.stringify(t)+". Reason: "+n}return[2,n.process()]}))}))},t.prototype.enqueueWithName=function(e,t){return void 0===t&&(t={}),Tt(this,void 0,void 0,(function(){return W(this,(function(n){return[2,this.sendToWorkers(this.tryResolveFromName(e,t),t)]}))}))},t.prototype.enqueue=function(e,t){return void 0===t&&(t={}),Tt(this,void 0,void 0,(function(){return W(this,(function(n){return[2,this.sendToWorkers(this.tryResolveAndInit(e,t),t)]}))}))},t.prototype.schedule=function(e,t,n,r,o,i,s){var a=this;void 0===s&&(s={});var c=[e,t,n,r,o].map((function(e){if(ie(e)){var t=e;return(t.min||0)+"-"+(t.max||0)}return se(e)?e.join(","):""+e})).join(" "),u=Te(i);return x.validate(c)?x.schedule(c,(function(){a.enqueue(i,s).catch((function(e){console.log("Can't enqueue job: '"+u+"' because: "+e)}))})):(console.log("Can't schedule the task: '"+u+"' because time expression is invalid."),null)},t.prototype.startProcessing=function(){return Tt(this,void 0,void 0,(function(){var t,n,r,o=this;return W(this,(function(i){switch(i.label){case 0:return this.processing?[2,null]:(this.processing=!0,this.config.resolve("isWorker")?(t=this.config.resolve("zmqRemoteHost"),n=t+":"+this.config.resolve("zmqBackPort"),this.workerPush=C.socket("push"),[4,this.workerPush.connect(n)]):(console.log(Ge("Processing can not be started because this is NOT a worker process!",e.ConsoleColor.FgRed)),[2,null]));case 1:return i.sent(),console.log("Worker producer connected to: "+n),r=t+":"+this.config.resolve("zmqPort"),this.workerPull=C.socket("pull"),[4,this.workerPull.connect(r)];case 2:return i.sent(),console.log("Worker consumer connected to: "+r),this.workerPull.on("message",(function(t,n,r){return Tt(o,void 0,void 0,(function(){var o,i,s,a,c;return W(this,(function(u){switch(u.label){case 0:u.trys.push([0,5,,6]),o=t.toString("utf8"),i=JSON.parse(n.toString("utf8")),s=null==r?void 0:r.toString("utf8"),console.time(s),console.timeLog(s,"Started working on background job: "+Ge(o,e.ConsoleColor.FgCyan)+" with args: \n"+Ue(i)+"\n\n"),u.label=1;case 1:return u.trys.push([1,3,,4]),[4,Promise.race([this.jobs[o](i,s),Ae(this.maxTimeout,!0)])];case 2:return u.sent(),console.timeLog(s,"Finished working on background job: "+Ge(o,e.ConsoleColor.FgCyan)+"\n\n"),[3,4];case 3:return a=u.sent(),console.timeLog(s,"Background job failed: "+Ge(o,e.ConsoleColor.FgRed)+"\n"+a+"\n\n"),[3,4];case 4:return console.timeEnd(s),[3,6];case 5:return c=u.sent(),console.log("Failed to start job: "+c.message),[3,6];case 6:return[2]}}))}))})),[2]}}))}))},t.prototype.tryResolve=function(e,t){var n=Te(e);if(!this.jobs[n])throw"Can't find job with name: "+n+" so it can't be enqueued!";try{this.resolveJobInstance(e,t)}catch(e){throw"Can't resolve params for job: "+n+", with params: "+JSON.stringify(t)+". Reason: "+e}return n},t.prototype.tryResolveFromName=function(e,t){var n=this.jobTypes.find((function(t){return Te(t)==e}));if(!n)throw"Can't find job type with name: "+e+" so it can't be enqueued!";return this.tryResolveAndInit(n,t)},t.prototype.tryResolveAndInit=function(t,n){var r=this;if(!this.apiPush){var o=this.config.resolve("zmqPort");this.apiPush=C.socket("push"),this.apiPush.bind("tcp://0.0.0.0:"+o),console.log("API producer bound to port: "+o)}if(!this.apiPull){var i=this.config.resolve("zmqBackPort");this.apiPull=C.socket("pull"),this.apiPull.bind("tcp://0.0.0.0:"+i),this.apiPull.on("message",(function(t,n){var o=t.toString("utf8"),i=JSON.parse((null==n?void 0:n.toString("utf8"))||"{}"),s=Object.keys(i).reduce((function(e,t){return e[t]=oe(i[t]),e}),{});console.log('Received a message from worker: "'+Ge(o,e.ConsoleColor.FgCyan)+'" with args: '+Ue(s)+"\n\n"),r.messages.next({message:o,params:i})})),console.log("API consumer bound to port: "+i)}return this.tryResolve(t,n)},t.prototype.resolveJobInstance=function(e,t,n){void 0===n&&(n="");var r=this.container.createChildContainer();return Object.keys(t).map((function(e){r.register(e,{useValue:t[e]})})),r.register("uniqueId",{useValue:n}),r.register(e,e),r.resolve(e)},t.prototype.sendToWorkers=function(e,t){return Tt(this,void 0,void 0,(function(){var n,r;return W(this,(function(o){switch(o.label){case 0:return[4,this.apiPush];case 1:return n=o.sent(),r=(new b.ObjectId).toHexString(),[4,n.send([e,JSON.stringify(t),r])];case 2:return o.sent(),[2,r]}}))}))},t}(),e.JobManager=kt([o.injectable(),o.scoped(o.Lifecycle.ContainerScoped),At(1,o.inject(rt)),At(2,o.injectAll(Ze)),Mt("design:paramtypes",[e.Configuration,Object,Array])],e.JobManager);var Ft=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},It=function(e){function t(t,n,r){return e.call(this,t,n,r)||this}return Y(t,e),Object.defineProperty(t.prototype,"current",{get:function(){return this.data.current},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"max",{get:function(){return this.data.max},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"message",{get:function(){return this.data.message},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"error",{get:function(){return this.data.error},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"canceled",{get:function(){return this.data.canceled},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"percent",{get:function(){return this.max>0?Math.round(this.current/this.max*100):0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"remaining",{get:function(){return this.max>0?this.max-this.current:0},enumerable:!1,configurable:!0}),t.prototype.setMessageBridge=function(e){return this.messageBridge=e||this.messageBridge,this},t.prototype.createSubProgress=function(e,t,n){return Ft(this,void 0,void 0,(function(){return W(this,(function(r){switch(r.label){case 0:return t<=0&&e>0?[4,this.advance(e)]:[3,2];case 1:r.sent(),r.label=2;case 2:return null===n?[3,4]:(this.data.message=n,[4,this.save()]);case 3:r.sent(),r.label=4;case 4:return[2,new Nt(this,this.current,e,Math.max(t,1))]}}))}))},t.prototype.setMax=function(e){return Ft(this,void 0,void 0,(function(){return W(this,(function(t){switch(t.label){case 0:if(isNaN(e)||e<=0)throw"Max progress value must be bigger than zero";return this.data.max=e,[4,this.save()];case 1:return t.sent(),[2]}}))}))},t.prototype.setMessage=function(e){return Ft(this,void 0,void 0,(function(){return W(this,(function(t){switch(t.label){case 0:return this.data.message=e,[4,this.save()];case 1:return t.sent(),[2]}}))}))},t.prototype.setError=function(e){return Ft(this,void 0,void 0,(function(){return W(this,(function(t){switch(t.label){case 0:return this.data.error=e,[4,this.save()];case 1:return t.sent(),[2]}}))}))},t.prototype.advance=function(e){return void 0===e&&(e=1),Ft(this,void 0,void 0,(function(){return W(this,(function(t){switch(t.label){case 0:if(isNaN(e)||e<=0)throw"Advance value must be bigger than zero";return[4,this.load()];case 1:return t.sent(),this.deleted||this.canceled?[2,null]:(this.data.current=Math.min(this.max,this.current+e),[4,this.save()]);case 2:return t.sent(),[2]}}))}))},t.prototype.cancel=function(){return Ft(this,void 0,void 0,(function(){return W(this,(function(e){switch(e.label){case 0:return this.data.canceled=!0,[4,this.save()];case 1:return e.sent(),[2]}}))}))},t.prototype.save=function(){return this.messageBridge&&this.messageBridge.sendMessage("progress-changed",this.toJSON()),e.prototype.save.call(this)},t}(bt),Nt=function(){function e(e,t,n,r){if(void 0===r&&(r=100),this.parent=e,this.progressFrom=t,this.progressValue=n,this.mMax=r,t<0)throw"Progress from must be bigger than or zero";if(n<=0)throw"Progress value must be bigger than zero";this.mCurrent=0}return Object.defineProperty(e.prototype,"id",{get:function(){return this.parent.id},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"current",{get:function(){return this.mCurrent},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"max",{get:function(){return this.mMax},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"message",{get:function(){return this.parent.message},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"error",{get:function(){return this.parent.error},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"percent",{get:function(){return this.parent.percent},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"remaining",{get:function(){return this.max-this.mCurrent},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"canceled",{get:function(){return!this.parent||this.parent.canceled},enumerable:!1,configurable:!0}),e.prototype.setMessageBridge=function(e){return this.parent?(this.parent.setMessageBridge(e),this):this},e.prototype.createSubProgress=function(t,n,r){return Ft(this,void 0,void 0,(function(){return W(this,(function(o){switch(o.label){case 0:return n<=0&&t>0?[4,this.advance(t)]:[3,2];case 1:o.sent(),o.label=2;case 2:return null===r?[3,4]:[4,this.setMessage(r)];case 3:o.sent(),o.label=4;case 4:return[2,new e(this,this.current,t,Math.max(n,1))]}}))}))},e.prototype.setMax=function(e){return Ft(this,void 0,void 0,(function(){return W(this,(function(t){switch(t.label){case 0:if(isNaN(e)||e<=0)throw"Max progress value must be bigger than zero";return this.mMax=e,[4,this.save()];case 1:return t.sent(),[2]}}))}))},e.prototype.setMessage=function(e){return Ft(this,void 0,void 0,(function(){return W(this,(function(t){switch(t.label){case 0:return this.parent?[4,this.parent.setMessage(e)]:[2,null];case 1:return t.sent(),[2]}}))}))},e.prototype.setError=function(e){return Ft(this,void 0,void 0,(function(){return W(this,(function(t){switch(t.label){case 0:return this.parent?[4,this.parent.setError(e)]:[2,null];case 1:return t.sent(),[2]}}))}))},e.prototype.advance=function(e){return void 0===e&&(e=1),Ft(this,void 0,void 0,(function(){return W(this,(function(t){switch(t.label){case 0:if(isNaN(e)||e<=0)throw"Advance value must be bigger than zero";return this.mCurrent=Math.min(this.max,this.mCurrent+e),[4,this.save()];case 1:return t.sent(),[2]}}))}))},e.prototype.cancel=function(){return Ft(this,void 0,void 0,(function(){return W(this,(function(e){switch(e.label){case 0:return this.parent?[4,this.parent.cancel()]:[2,null];case 1:return e.sent(),[2]}}))}))},e.prototype.save=function(){return Ft(this,void 0,void 0,(function(){var e,t,n;return W(this,(function(r){switch(r.label){case 0:return e=this.max>0?this.mCurrent/this.max:0,t=this.progressFrom+Math.round(this.progressValue*e),n=this.parent.current,t<=n?[2,null]:[4,this.parent.advance(t)];case 1:return r.sent(),[2]}}))}))},e.prototype.load=function(){return Ft(this,void 0,void 0,(function(){return W(this,(function(e){return[2,null]}))}))},e.prototype.toJSON=function(){return this.parent.toJSON()},e}(),Et=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},Dt=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},Bt=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))};e.Progresses=function(){function e(e,t){var n=this;this.connector=e,this.jobMan=t,this.collection=e.database.collection("progresses"),this.progresses={},this.jobMan.on("progress-changed",(function(e){var t=e.id;n.progresses[t]=new It(new b.ObjectId(t),e,n.collection)}))}return e.prototype.waitToFinish=function(e){return Bt(this,void 0,void 0,(function(){var t=this;return W(this,(function(n){return[2,Promise.race([this.waitForProgress(e,(function(){return Bt(t,void 0,void 0,(function(){var t;return W(this,(function(n){switch(n.label){case 0:return!(t=this.progresses[e])||t.percent<100?[4,this.get(e)]:[3,2];case 1:t=n.sent(),n.label=2;case 2:if(!t)throw new Error("Progress does not exists with id: "+e);return[2,t]}}))}))}),500),this.waitForProgress(e,(function(){return Bt(t,void 0,void 0,(function(){return W(this,(function(t){return[2,this.progresses[e]||null]}))}))}),25)])]}))}))},e.prototype.get=function(e){return Bt(this,void 0,void 0,(function(){return W(this,(function(t){return[2,e?this.find({_id:new b.ObjectId(e)}):null]}))}))},e.prototype.find=function(e){return Bt(this,void 0,void 0,(function(){var t;return W(this,(function(n){switch(n.label){case 0:return[4,this.collection.findOne(e)];case 1:return[2,(t=n.sent())?new It(t._id,t,this.collection):null]}}))}))},e.prototype.create=function(e){return void 0===e&&(e=100),Bt(this,void 0,void 0,(function(){var t,n;return W(this,(function(r){switch(r.label){case 0:if(isNaN(e)||e<=0)throw new Error("Max progress value must be bigger than zero");return t={current:0,max:e,message:"",error:"",canceled:!1},[4,this.collection.insertOne(t)];case 1:return n=r.sent(),[2,new It(n.insertedId,t,this.collection)]}}))}))},e.prototype.remove=function(e){return Bt(this,void 0,void 0,(function(){return W(this,(function(t){switch(t.label){case 0:return[4,this.collection.deleteOne({_id:new b.ObjectId(e)})];case 1:return t.sent(),[2,e]}}))}))},e.prototype.waitForProgress=function(e,t,n){return Bt(this,void 0,void 0,(function(){var r,o,i;return W(this,(function(s){switch(s.label){case 0:r=!1,o=null,i=0,s.label=1;case 1:return r?[3,5]:[4,t()];case 2:if(o=s.sent(),i+=n,o){if(o.error)throw new Error(o.error);r=o.percent>=100}if(r)return[3,4];if(i>=this.jobMan.maxTimeout)throw new Error("Progress with id: "+e+" probably never will be finished!");return[4,Ae(n)];case 3:s.sent(),s.label=4;case 4:return[3,1];case 5:return[2,o]}}))}))},e}(),e.Progresses=Et([o.injectable(),o.singleton(),Dt("design:paramtypes",[e.MongoConnector,e.JobManager])],e.Progresses);var qt=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},zt=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},Lt=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))};e.LazyAssets=function(){function e(e,t,n,r){this.connector=e,this.assets=t,this.progresses=n,this.jobMan=r,this.collection=e.database.collection("lazyassets")}return e.prototype.create=function(e,t,n){return void 0===t&&(t={}),void 0===n&&(n="main"),Lt(this,void 0,void 0,(function(){var r,o,i,s;return W(this,(function(a){switch(a.label){case 0:return r=this.jobMan.tryResolve(e,Object.assign(Object.assign({},t),{lazyId:""})),o={jobName:r,jobParams:t,jobQue:n},[4,this.find(o)];case 1:return(i=a.sent())?[2,i]:[4,this.collection.insertOne(o)];case 2:return s=a.sent(),[2,new St(s.insertedId,o,this.collection,this.assets,this.progresses)]}}))}))},e.prototype.read=function(e){return Lt(this,void 0,void 0,(function(){return W(this,(function(t){return[2,e?this.find({_id:new b.ObjectId(e)}):null]}))}))},e.prototype.find=function(e){return Lt(this,void 0,void 0,(function(){var t;return W(this,(function(n){switch(n.label){case 0:return[4,this.collection.findOne(e)];case 1:return[2,(t=n.sent())?new St(t._id,t,this.collection,this.assets,this.progresses):null]}}))}))},e.prototype.unlink=function(e){return Lt(this,void 0,void 0,(function(){var t;return W(this,(function(n){switch(n.label){case 0:return[4,this.read(e)];case 1:return(t=n.sent())?[2,t.unlink()]:[2,null]}}))}))},e}(),e.LazyAssets=qt([o.injectable(),o.scoped(o.Lifecycle.ContainerScoped),zt("design:paramtypes",[e.MongoConnector,e.Assets,e.Progresses,e.JobManager])],e.LazyAssets);var Ht=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},Jt=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},Gt=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))};e.AssetResolver=function(){function e(e,t){this.assets=e,this.lazyAssets=t}return e.prototype.resolve=function(e,t){return void 0===t&&(t=!1),Gt(this,void 0,void 0,(function(){var n,r;return W(this,(function(o){switch(o.label){case 0:return n=null,t?[4,this.lazyAssets.read(e)]:[3,2];case 1:return(r=o.sent())?[2,r.loadAsset()]:[2,null];case 2:return[4,this.assets.read(e)];case 3:return(n=o.sent())?[3,5]:[4,this.lazyAssets.read(e)];case 4:return(r=o.sent())?[2,r.loadAsset()]:[2,null];case 5:return[2,n]}}))}))},e}(),e.AssetResolver=Ht([o.injectable(),o.scoped(o.Lifecycle.ContainerScoped),Jt("design:paramtypes",[e.Assets,e.LazyAssets])],e.AssetResolver);var Ut=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},$t=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},Vt=J.default,Yt=G.default;e.BackendProvider=function(){function e(){this.express=Vt(),this.server=k.createServer(this.express)}return Object.defineProperty(e.prototype,"io",{get:function(){return this.ioServer=this.ioServer||Yt(this.server,{path:"/socket"}),this.ioServer},enumerable:!1,configurable:!0}),e}(),e.BackendProvider=Ut([o.injectable(),o.singleton(),$t("design:paramtypes",[])],e.BackendProvider);var Wt=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},Xt=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))};e.CacheProcessor=function(){function e(){}return e.prototype.serialize=function(e){return Xt(this,void 0,void 0,(function(){return W(this,(function(t){return[2,e]}))}))},e.prototype.deserialize=function(e){return Xt(this,void 0,void 0,(function(){return W(this,(function(t){return[2,e]}))}))},e}(),e.CacheProcessor=Wt([o.injectable(),o.scoped(o.Lifecycle.ContainerScoped)],e.CacheProcessor);var Qt=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},Zt=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},Kt=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))};e.Cache=function(){function e(e,t,n){this.connector=e,this.config=t,this.cacheProcessor=n}return e.prototype.prepare=function(){return Kt(this,void 0,void 0,(function(){return W(this,(function(e){switch(e.label){case 0:if(this.collection)return[2];if(!this.connector.database)throw new Error("You can't use cache without mongo connection!");return this.collection=this.connector.database.collection(this.config.resolve("cacheCollection")),[4,this.collection.createIndex({expiresAt:1},{expireAfterSeconds:0})];case 1:return e.sent(),[2]}}))}))},e.prototype.set=function(e,t,n,r,o){return void 0===r&&(r=null),void 0===o&&(o={}),Kt(this,void 0,void 0,(function(){var i,s,a;return W(this,(function(c){switch(c.label){case 0:return[4,this.prepare()];case 1:return c.sent(),s={_id:e},[4,this.cacheProcessor.serialize(t)];case 2:return s.data=c.sent(),[4,this.cacheProcessor.serialize(o)];case 3:return s.tags=c.sent(),s.expirationTimestamp=r,i=s,n&&(a=Math.round((new Date).getTime()/1e3),i.expiresAt=a+n),[4,this.collection.updateOne({_id:e},{$set:i},{upsert:!0})];case 4:return c.sent(),[2,t]}}))}))},e.prototype.get=function(e){return Kt(this,void 0,void 0,(function(){var t,n;return W(this,(function(r){switch(r.label){case 0:return[4,this.prepare()];case 1:return r.sent(),[4,this.collection.findOne({_id:e})];case 2:if(t=r.sent(),n=Math.round((new Date).getTime()/1e3),t&&t.expiresAt&&t.expiresAt<n&&(t=null),!t)throw new Error("Cache probably doesn't exists with key: "+e);return[4,this.cacheProcessor.deserialize(t.data)];case 3:return[2,r.sent()]}}))}))},e.prototype.getOrSet=function(e,t,n,r,o){return void 0===r&&(r=null),void 0===o&&(o={}),Kt(this,void 0,void 0,(function(){var i,s;return W(this,(function(a){switch(a.label){case 0:return a.trys.push([0,2,,5]),[4,this.get(e)];case 1:return[2,a.sent()];case 2:return a.sent(),i=this.set,s=[e],[4,t()];case 3:return[4,i.apply(this,s.concat([a.sent(),n,r,o]))];case 4:return[2,a.sent()];case 5:return[2]}}))}))},e.prototype.delete=function(e){return Kt(this,void 0,void 0,(function(){return W(this,(function(t){switch(t.label){case 0:return[4,this.prepare()];case 1:return t.sent(),[4,this.collection.deleteOne({_id:e})];case 2:return t.sent(),[2]}}))}))},e}(),e.Cache=Qt([o.injectable(),o.scoped(o.Lifecycle.ContainerScoped),Zt("design:paramtypes",[e.MongoConnector,e.Configuration,e.CacheProcessor])],e.Cache);var en=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},tn=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))};e.EndpointProvider=function(){function e(){}return e.prototype.configure=function(e){return tn(this,void 0,void 0,(function(){return W(this,(function(t){return console.log("Express app is mounted to: "+e.mountpath),[2]}))}))},e}(),e.EndpointProvider=en([o.injectable(),o.scoped(o.Lifecycle.ContainerScoped)],e.EndpointProvider);var nn=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},rn=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},on=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}},sn=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))};e.Fixtures=function(){function e(e){this.fixtures=e}return e.prototype.load=function(){return sn(this,void 0,void 0,(function(){var e,t,n,r,o;return W(this,(function(i){switch(i.label){case 0:if(!this.fixtures)return[2];i.label=1;case 1:i.trys.push([1,6,7,8]),e=X(this.fixtures),t=e.next(),i.label=2;case 2:return t.done?[3,5]:[4,t.value.load()];case 3:i.sent(),i.label=4;case 4:return t=e.next(),[3,2];case 5:return[3,8];case 6:return n=i.sent(),r={error:n},[3,8];case 7:try{t&&!t.done&&(o=e.return)&&o.call(e)}finally{if(r)throw r.error}return[7];case 8:return[2]}}))}))},e}(),e.Fixtures=nn([o.injectable(),o.scoped(o.Lifecycle.ContainerScoped),on(0,o.injectAll(Qe)),rn("design:paramtypes",[Array])],e.Fixtures);var an=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},cn=q.default,un=function(){function e(e,t,n){this.folder=e,this.handler=n,this.thumb=T.v4(),this.big=T.v4(),this.targetSize=t||{width:250,height:250}}return e.prototype.serve=function(e){return an(this,void 0,void 0,(function(){var t,n,r,o,i,s,a,c,u,l,f;return W(this,(function(h){switch(h.label){case 0:return t=e==this.thumb,[4,this.handler.hasResult(t)];case 1:return h.sent()?[2,this.handler.serveResult(t)]:(r=cn,[4,this.handler.getOriginal()]);case 2:return[4,(n=r.apply(void 0,[h.sent()]).rotate()).metadata()];case 3:return o=h.sent(),i=o.width/o.height,s=t?this.targetSize.width/this.targetSize.height:1,a=t?Math.max(this.targetSize.width,this.targetSize.height):1500,c=i>s?a:Math.round(a/i),u=Math.round(c*i),l=n.resize(u,c),[4,t?l.extract({left:Math.floor((u-this.targetSize.width)/2),top:Math.floor((c-this.targetSize.height)/2),width:this.targetSize.width,height:this.targetSize.height}).toBuffer():l.toBuffer()];case 4:return f=h.sent(),[4,this.handler.writeResult(t,f)];case 5:return h.sent(),[2,this.handler.serveResult(t)]}}))}))},e}(),ln=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},fn=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};e.GalleryCache=function(){function e(){this.imgCache={}}return e.prototype.put=function(e){this.imgCache[e.thumb]=e,this.imgCache[e.big]=e},e.prototype.serve=function(e){var t=this.imgCache[e];return t?t.serve(e):null},e.prototype.create=function(e,t,n){var r=new un(e,t,n);return this.put(r),r},e}(),e.GalleryCache=ln([o.injectable(),o.scoped(o.Lifecycle.ContainerScoped),fn("design:paramtypes",[])],e.GalleryCache);var hn=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},dn=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},pn=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},gn=q.default;e.Gallery=function(){function e(e,n){this.config=e,this.galleryCache=n,this.cache={},this.dir=this.config.resolve("galleryDir"),this.output=t.join(this.config.resolve("cacheDir"),"gallery")}return e.prototype.getFolder=function(e,n){return void 0===n&&(n=null),pn(this,void 0,void 0,(function(){var r=this;return W(this,(function(o){return this.cache[e]=this.cache[e]||new Promise((function(o){g.lstat(t.join(r.dir,e),(function(t,i){!t&&i.isDirectory()?r.readRecursive(e,"",n).then(o,(function(){return o([])})):o([])}))})),[2,this.cache[e]]}))}))},e.prototype.readRecursive=function(e,n,r){var o=this;return new Promise((function(i){g.readdir(t.join(o.dir,e),(function(s,a){if(s)i([]);else{var c=a.map((function(i){return new Promise((function(s){return pn(o,void 0,void 0,(function(){var o,a,c=this;return W(this,(function(u){return o=t.join(e,i),a=t.join(this.dir,o),g.lstat(a,(function(e,u){e?s([]):u.isDirectory()?c.readRecursive(o,t.join(n,i),r).then(s):gn(a).rotate().metadata().then((function(){var e=function(e){return t.join(c.output,o.replace(/.([a-z|A-Z]+)$/gi,(function(t){return"-"+(e?"thumb":"big")+t})))};s([c.galleryCache.create(n,r,{getOriginal:function(){return new Promise((function(e,t){g.readFile(a,(function(n,r){n?t(n):e(r)}))}))},writeResult:function(n,r){return new Promise((function(o,i){return pn(c,void 0,void 0,(function(){var s;return W(this,(function(a){switch(a.label){case 0:return s=e(n),[4,Se(t.dirname(s))];case 1:return a.sent(),g.writeFile(s,r,(function(e){e?i(e):o()})),[2]}}))}))}))},hasResult:function(t){return new Promise((function(n){g.access(e(t),g.constants.R_OK,(function(e){n(!e)}))}))},serveResult:function(t){return new Promise((function(n,r){g.readFile(e(t),(function(e,t){e?r(e):n(t)}))}))}})])}),(function(){return s([])}))})),[2]}))}))}))}));Promise.all(c).then((function(e){i([].concat.apply([],e))}))}}))}))},e}(),e.Gallery=hn([o.injectable(),o.scoped(o.Lifecycle.ContainerScoped),dn("design:paramtypes",[e.Configuration,e.GalleryCache])],e.Gallery);var yn=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},vn=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},mn=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))};e.IdGenerator=function(){function e(e){this.config=e,this.prefix=e.resolve("idPrefix"),this.separator=e.resolve("idSeparator"),this.chars=e.resolve("idChars"),this.parts=e.resolve("idParts")}return e.prototype.generate=function(e){return mn(this,void 0,void 0,(function(){var t,n,r;return W(this,(function(o){switch(o.label){case 0:t=null,n=0,r=!0,o.label=1;case 1:return r&&n<5?(t=this.generateId(),[4,e(t)]):[3,3];case 2:return r=o.sent(),n++,[3,1];case 3:if(r)throw"Couldn't generate an unique id..";return[2,t]}}))}))},e.prototype.generateId=function(){var e=this;return this.prefix+this.parts.map((function(t){for(var n="",r=0;r<t;r++){var o=De(0,e.chars.length-1);n+=e.chars[o]}return n})).join(this.separator)},e}(),e.IdGenerator=yn([o.injectable(),o.scoped(o.Lifecycle.ContainerScoped),vn("design:paramtypes",[e.Configuration])],e.IdGenerator);var bn=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},wn=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};e.TranslationProvider=function(){function e(e){this.config=e,this.cache={}}return e.prototype.getDictionary=function(e){return this.cache[e]=this.cache[e]||L.default.get(this.config.resolve("translationsTemplate").replace("[lang]",e)).then((function(e){return e.data}),(function(e){return{message:e}})),this.cache[e]},e}(),e.TranslationProvider=bn([o.injectable(),o.singleton(),wn("design:paramtypes",[e.Configuration])],e.TranslationProvider);var jn=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},Pn=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},On=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))};e.Translator=function(){function e(e){this.translationProvider=e,this.cache={}}return e.prototype.getDictionary=function(e){return On(this,void 0,void 0,(function(){var t;return W(this,(function(n){switch(n.label){case 0:return[4,this.translationProvider.getDictionary(e)];case 1:return t=n.sent(),this.cache[e]=t,[2,t]}}))}))},e.prototype.getTranslationSync=function(e,t,n){if(!le(t)||!t.length)throw new Error('Parameter "key" required');var r=ye(this.cache[e],t,t)||t;return this.interpolate(r,n)},e.prototype.getTranslation=function(e,t,n){var r=this;if(!le(t)||!t.length)throw new Error('Parameter "key" required');return this.getDictionary(e).then((function(e){var o=ye(e,t,t)||t;return r.interpolate(o,n)}))},e.prototype.getTranslations=function(e){for(var t=this,n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return new Promise((function(r){Promise.all(n.map((function(n){return t.getTranslation(e,n)}))).then((function(e){r(n.reduce((function(t,n,r){return t[n]=e[r],t}),{}))}))}))},e.prototype.interpolate=function(e,t){return"string"==typeof e?this.interpolateString(e,t):"function"==typeof e?e(t):e},e.prototype.interpolateString=function(e,t){return e&&t?e.replace(/{{\s?([^{}\s]*)\s?}}/g,(function(e,n){var r=ye(t,n);return re(r)?r:e})):e},e}(),e.Translator=jn([o.injectable(),o.singleton(),Pn("design:paramtypes",[e.TranslationProvider])],e.Translator);var Rn=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},_n=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},xn=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))};e.TemplateRenderer=function(){function e(e,t){this.translator=e,this.config=t,this.templates={},U.registerHelper("object",(function(e){return e.hash})),U.registerHelper("now",(function(){return(new Date).getTime()})),U.registerHelper("keys",(function(e){return e?Object.keys(e):[]})),U.registerHelper("translate",(function(t,n){return e.getTranslationSync(this.language,t,n)}))}return e.prototype.init=function(){return this.initPromise=this.initPromise||this.parseTemplates(this.config.resolve("templatesDir"),[]),this.initPromise},e.prototype.parseTemplates=function(e,n){return xn(this,void 0,void 0,(function(){var r=this;return W(this,(function(o){return[2,new Promise((function(o){g.readdir(e,(function(i,s){return xn(r,void 0,void 0,(function(){var r,i,a,c,u,l,f,h,d,p,y;return W(this,(function(v){switch(v.label){case 0:v.trys.push([0,6,7,8]),r=X(s),i=r.next(),v.label=1;case 1:return i.done?[3,5]:(a=i.value,c=t.join(e,a),g.lstatSync(c).isDirectory()?[4,this.parseTemplates(t.join(e,a),n.concat([a]))]:[3,3]);case 2:return v.sent(),[3,4];case 3:(u=a.split(".")).pop(),l=u.join("."),f=n.concat([l]).join("-"),h=g.readFileSync(c).toString("utf8"),this.templates[f]=U.compile(h),U.registerPartial(f,h),v.label=4;case 4:return i=r.next(),[3,1];case 5:return[3,8];case 6:return d=v.sent(),p={error:d},[3,8];case 7:try{i&&!i.done&&(y=r.return)&&y.call(r)}finally{if(p)throw p.error}return[7];case 8:return o(),[2]}}))}))}))}))]}))}))},e.prototype.render=function(e,t,n){return xn(this,void 0,void 0,(function(){var r,o;return W(this,(function(i){switch(i.label){case 0:return[4,this.init()];case 1:return i.sent(),[4,this.translator.getDictionary(t)];case 2:return i.sent(),this.templates[e]?(n=Object.assign({language:t},n||{}),(r=this.templates[e](n))instanceof Error?[4,Promise.reject(r)]:[3,4]):[2,Promise.reject("Template not found with name: "+e)];case 3:return o=i.sent(),[3,5];case 4:o=r,i.label=5;case 5:return[2,o]}}))}))},e}(),e.TemplateRenderer=Rn([o.injectable(),o.singleton(),_n("design:paramtypes",[e.Translator,e.Configuration])],e.TemplateRenderer);var Cn=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},Sn=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},kn=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))};e.MailSender=function(){function e(e,t){this.config=e,this.renderer=t,this.transporter=F.createTransport({host:this.config.resolve("smtpHost"),port:this.config.resolve("smtpPort"),auth:{user:this.config.resolve("smtpUser"),pass:this.config.resolve("smtpPassword")}})}return Object.defineProperty(e.prototype,"translator",{get:function(){return this.renderer.translator},enumerable:!1,configurable:!0}),e.prototype.sendMail=function(e,t){return kn(this,void 0,void 0,(function(){var n,r;return W(this,(function(o){switch(o.label){case 0:return[4,this.translator.getTranslation(e,t.subject||"-")];case 1:return n=o.sent(),[4,this.renderer.render(t.template,e,t.context)];case 2:return r=o.sent(),[2,this.transporter.sendMail({from:t.from||this.config.resolve("mailSenderAddress"),to:t.to,attachments:t.attachments,subject:n,html:r})]}}))}))},e}(),e.MailSender=Cn([o.injectable(),o.singleton(),Sn("design:paramtypes",[e.Configuration,e.TemplateRenderer])],e.MailSender);var Mn=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},An=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},Tn=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))};e.MemoryCache=function(){function e(e){this.cache=e,this.cacheMap=new Map}return e.prototype.set=function(e,t,n,r,o){return void 0===r&&(r=null),void 0===o&&(o={}),Tn(this,void 0,void 0,(function(){var i,s;return W(this,(function(a){return i=Math.round((new Date).getTime()/1e3),s=Math.min(isNaN(n)?Number.MAX_SAFE_INTEGER:n,3600),this.cacheMap.set(e,{_id:e,data:t,expirationTimestamp:s,expiresAt:i+s}),[2,this.cache.set(e,t,n,r,o)]}))}))},e.prototype.get=function(e){return Tn(this,void 0,void 0,(function(){var t,n,r,o;return W(this,(function(i){switch(i.label){case 0:return t=this.cacheMap.get(e),n=Math.round((new Date).getTime()/1e3),r=3600,t&&t.expiresAt&&t.expiresAt<n&&(r=t.expirationTimestamp,t=null),t?[3,2]:[4,this.cache.get(e)];case 1:return o=i.sent(),this.cacheMap.set(e,{_id:e,data:o,expirationTimestamp:r,expiresAt:n+r}),[2,o];case 2:return[2,t.data]}}))}))},e.prototype.getOrSet=function(e,t,n,r,o){return void 0===r&&(r=null),void 0===o&&(o={}),Tn(this,void 0,void 0,(function(){var i,s;return W(this,(function(a){switch(a.label){case 0:return a.trys.push([0,2,,5]),[4,this.get(e)];case 1:return[2,a.sent()];case 2:return a.sent(),i=this.set,s=[e],[4,t()];case 3:return[4,i.apply(this,s.concat([a.sent(),n,r,o]))];case 4:return[2,a.sent()];case 5:return[2]}}))}))},e.prototype.delete=function(e){return Tn(this,void 0,void 0,(function(){return W(this,(function(t){switch(t.label){case 0:return this.cacheMap.delete(e),[4,this.cacheMap.delete(e)];case 1:return t.sent(),[2]}}))}))},e}(),e.MemoryCache=Mn([o.injectable(),o.scoped(o.Lifecycle.ContainerScoped),An("design:paramtypes",[e.Cache])],e.MemoryCache);var Fn=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},In=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},Nn={id:"5a3cdf7c6a9cf0ba32feccdf",email:"admin@site.com",password:"",roles:["admin"]};e.UserManager=function(){function e(){}return e.prototype.getByCredentials=function(e){return In(this,void 0,void 0,(function(){var t;return W(this,(function(n){switch(n.label){case 0:return Nn.email!=e.email?[3,1]:(t=Nn,[3,3]);case 1:return[4,Promise.reject("message.login.error")];case 2:t=n.sent(),n.label=3;case 3:return[2,t]}}))}))},e.prototype.getById=function(e){return In(this,void 0,void 0,(function(){return W(this,(function(t){return[2,Nn.id==e?Nn:null]}))}))},e.prototype.serialize=function(e){return In(this,void 0,void 0,(function(){var t;return W(this,(function(n){return delete(t=Object.assign({},e)).password,[2,t]}))}))},e}(),e.UserManager=Fn([o.injectable(),o.scoped(o.Lifecycle.ContainerScoped)],e.UserManager);var En=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},Dn=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},Bn=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}},qn=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},zn=function(){function e(e,t){this.assets=e,this.assetResolver=t}return e.prototype.upload=function(e){return qn(this,void 0,void 0,(function(){var t,n,r;return W(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),t="application/octet-stream"===e.mimetype?null:e.mimetype,[4,this.assets.writeBuffer(e.buffer,{filename:e.filename},t)];case 1:return[2,o.sent().toJSON()];case 2:throw n=o.sent(),r=(null==n?void 0:n.message)||n||"Unknown error",new i.HttpError(400,"Asset can't be uploaded.\n"+r);case 3:return[2]}}))}))},e.prototype.uploadUrl=function(e){return qn(this,void 0,void 0,(function(){var t,n;return W(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.assets.writeUrl(e.url,e)];case 1:return[2,r.sent().toJSON()];case 2:throw t=r.sent(),n=(null==t?void 0:t.message)||t||"Unknown error",new i.HttpError(400,"Asset can't be uploaded.\n"+n);case 3:return[2]}}))}))},e.prototype.getFile=function(e,t,n){return qn(this,void 0,void 0,(function(){return W(this,(function(r){switch(r.label){case 0:return[4,this.getAsset("Asset",e,t,n)];case 1:return[2,r.sent().download()]}}))}))},e.prototype.getImageRotation=function(e,t,n,r){return void 0===r&&(r=0),qn(this,void 0,void 0,(function(){var o;return W(this,(function(i){switch(i.label){case 0:return[4,this.getAsset("Image",e,t.lazy,n)];case 1:return o=i.sent(),0!==r&&(t.rotation=t.rotation||r),[2,o.downloadImage(t)]}}))}))},e.prototype.getImage=function(e,t,n){return qn(this,void 0,void 0,(function(){return W(this,(function(r){return[2,this.getImageRotation(e,t,n)]}))}))},e.prototype.getFileByName=function(e,t){return qn(this,void 0,void 0,(function(){return W(this,(function(n){switch(n.label){case 0:return[4,this.getAssetByName("Asset",e,t)];case 1:return[2,n.sent().download()]}}))}))},e.prototype.getImageByName=function(e,t,n){return qn(this,void 0,void 0,(function(){return W(this,(function(r){switch(r.label){case 0:return[4,this.getAssetByName("Image",e,n)];case 1:return[2,r.sent().downloadImage(t)]}}))}))},e.prototype.setAssetHeaders=function(e,t,n){var r,o;if(null===(r=t.metadata)||void 0===r?void 0:r.classified)throw new i.HttpError(403,e+" is classified, and can be only downloaded from a custom url.");var s=null===(o=t.metadata)||void 0===o?void 0:o.extension;s&&n.header("content-disposition","inline; filename="+t.filename+"."+s),t.contentType&&n.header("content-type",t.contentType)},e.prototype.getAsset=function(e,t,n,r){return qn(this,void 0,void 0,(function(){var o;return W(this,(function(s){switch(s.label){case 0:return[4,this.assetResolver.resolve(t,n)];case 1:if(!(o=s.sent()))throw new i.HttpError(404,e+" with id: '"+t+"' not found.");return this.setAssetHeaders(e,o,r),[2,o]}}))}))},e.prototype.getAssetByName=function(e,t,n){return qn(this,void 0,void 0,(function(){var r;return W(this,(function(o){switch(o.label){case 0:return[4,this.assets.find({filename:t})];case 1:if(!(r=o.sent()))throw new i.HttpError(404,e+" with filename: '"+t+"' not found.");return this.setAssetHeaders(e,r,n),[2,r]}}))}))},e}();En([i.Authorized(),i.Post(""),Bn(0,i.UploadedFile("file")),Dn("design:type",Function),Dn("design:paramtypes",[Object]),Dn("design:returntype",Promise)],zn.prototype,"upload",null),En([i.Authorized(),i.Post("url"),Bn(0,i.Body()),Dn("design:type",Function),Dn("design:paramtypes",[Object]),Dn("design:returntype",Promise)],zn.prototype,"uploadUrl",null),En([i.Get("/:id"),Bn(0,i.Param("id")),Bn(1,i.QueryParam("lazy")),Bn(2,i.Res()),Dn("design:type",Function),Dn("design:paramtypes",[String,Boolean,Object]),Dn("design:returntype",Promise)],zn.prototype,"getFile",null),En([i.Get("/image/:id/:rotation"),Bn(0,i.Param("id")),Bn(1,i.QueryParams()),Bn(2,i.Res()),Bn(3,i.Param("rotation")),Dn("design:type",Function),Dn("design:paramtypes",[String,Object,Object,Number]),Dn("design:returntype",Promise)],zn.prototype,"getImageRotation",null),En([i.Get("/image/:id"),Bn(0,i.Param("id")),Bn(1,i.QueryParams()),Bn(2,i.Res()),Dn("design:type",Function),Dn("design:paramtypes",[String,Object,Object]),Dn("design:returntype",Promise)],zn.prototype,"getImage",null),En([i.Get("/by-name/:name"),Bn(0,i.Param("name")),Bn(1,i.Res()),Dn("design:type",Function),Dn("design:paramtypes",[String,Object]),Dn("design:returntype",Promise)],zn.prototype,"getFileByName",null),En([i.Get("/by-name/image/:name"),Bn(0,i.Param("name")),Bn(1,i.QueryParams()),Bn(2,i.Res()),Dn("design:type",Function),Dn("design:paramtypes",[String,Object,Object]),Dn("design:returntype",Promise)],zn.prototype,"getImageByName",null),zn=En([o.injectable(),i.Controller("/assets"),Dn("design:paramtypes",[e.Assets,e.AssetResolver])],zn);var Ln=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},Hn=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},Jn=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}},Gn=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))};e.AuthController=function(){function e(e,t){this.config=e,this.userManager=t}return e.prototype.login=function(e,t){return Gn(this,void 0,void 0,(function(){var t,n,o;return W(this,(function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),[4,this.userManager.getByCredentials(e)];case 1:return t=s.sent(),[4,N.compare(e.password,t.password)];case 2:if(!0!==s.sent())throw"message.login.error";return n={token:r.sign({id:t._id||t.id},this.config.resolve("jwtSecret"))},[4,this.userManager.serialize(t)];case 3:return[2,(n.user=s.sent(),n)];case 4:throw o=s.sent(),new i.HttpError(401,o);case 5:return[2]}}))}))},e.prototype.getProfile=function(e){return this.userManager.serialize(e)},e}(),Ln([i.Post("/login"),Jn(0,i.Body()),Jn(1,i.Res()),Hn("design:type",Function),Hn("design:paramtypes",[Object,Object]),Hn("design:returntype",Promise)],e.AuthController.prototype,"login",null),Ln([i.Authorized(),i.Get("/user"),Jn(0,i.CurrentUser()),Hn("design:type",Function),Hn("design:paramtypes",[Object]),Hn("design:returntype",void 0)],e.AuthController.prototype,"getProfile",null),e.AuthController=Ln([o.injectable(),i.Controller(),Hn("design:paramtypes",[e.Configuration,e.UserManager])],e.AuthController);var Un=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},$n=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},Vn=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}};e.GalleryController=function(){function e(e){this.galleryCache=e}return e.prototype.getFile=function(e){return this.galleryCache.serve(e)},e}(),Un([i.Get("/:id"),Vn(0,i.Param("id")),$n("design:type",Function),$n("design:paramtypes",[String]),$n("design:returntype",void 0)],e.GalleryController.prototype,"getFile",null),e.GalleryController=Un([o.injectable(),i.Controller("/gallery"),$n("design:paramtypes",[e.GalleryCache])],e.GalleryController);var Yn=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},Wn=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},Xn=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}},Qn=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},Zn=function(){function e(e,t){this.progresses=e,this.config=t;var n=this.config.resolve("mainEndpoint");this.connectionType=n?"socket":"polling"}return e.prototype.getProgress=function(e){return Qn(this,void 0,void 0,(function(){var t,n;return W(this,(function(r){switch(r.label){case 0:return[4,this.progresses.get(e)];case 1:return(t=r.sent())?((n=t.toJSON()).connectionType=this.connectionType,[2,n]):[2,null]}}))}))},e}();Yn([i.Get("/:id"),Xn(0,i.Param("id")),Wn("design:type",Function),Wn("design:paramtypes",[String]),Wn("design:returntype",Promise)],Zn.prototype,"getProgress",null),Zn=Yn([o.injectable(),i.Controller("/progresses"),Wn("design:paramtypes",[e.Progresses,e.Configuration])],Zn);var Kn=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},er=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},tr=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))};e.ErrorHandlerMiddleware=function(){function e(e,t){this.configuration=e,this.translator=t}return Object.defineProperty(e.prototype,"isDev",{get:function(){return"development"===this.configuration.resolve("nodeEnv")},enumerable:!1,configurable:!0}),e.prototype.error=function(e,t,n,r){return tr(this,void 0,void 0,(function(){var r;return W(this,(function(o){switch(o.label){case 0:return[4,this.getResult(e,t,n)];case 1:return r=o.sent(),this.isDev&&console.log("ERROR",r,n.statusCode),n.json(r),[2]}}))}))},e.prototype.getResult=function(e,t,n){return tr(this,void 0,void 0,(function(){var r,o,s,a;return W(this,(function(c){switch(c.label){case 0:return r={},e instanceof i.BadRequestError?(n.status(400),"ParamRequiredError"!==e.constructor.name?[3,2]:(o=r,[4,this.translator.getTranslation(t.language,"message.parameter-required.error")])):[3,6];case 1:return o.message=c.sent(),r.param=e.message,[3,5];case 2:return s=r,(a=e.message)?[3,4]:[4,this.translator.getTranslation(t.language,"message.form-validation.error")];case 3:a=c.sent(),c.label=4;case 4:s.message=a,r.errors=e.errors,this.isDev&&(r.stack=e.stack),c.label=5;case 5:return[2,r];case 6:return n.status(e.httpCode||500),e instanceof Error?(e.name&&(r.name=e.name),e.message&&(r.message=e.message),e.stack&&this.isDev&&(r.stack=e.stack)):"string"==typeof e&&(r.message=e),[2,r]}}))}))},e}(),e.ErrorHandlerMiddleware=Kn([o.injectable(),i.Middleware({type:"after"}),er("design:paramtypes",[e.Configuration,e.Translator])],e.ErrorHandlerMiddleware);var nr=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},rr=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},or=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}},ir=function(){function e(e){this.container=e}return e.prototype.use=function(e,t,n){e.container=this.container,n(null)},e}();ir=nr([o.injectable(),i.Middleware({type:"before"}),or(0,o.inject(rt)),rr("design:paramtypes",[Object])],ir);var sr=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},ar=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};e.LanguageMiddleware=function(){function e(e){this.config=e}return e.prototype.use=function(e,t,n){e.language=e.query.language||this.config.resolve("defaultLanguage"),n(null)},e}(),e.LanguageMiddleware=sr([o.injectable(),i.Middleware({type:"before"}),ar("design:paramtypes",[e.Configuration])],e.LanguageMiddleware);var cr=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},ur=function(){function e(){}return e.prototype.use=function(e,t,n){e.ended=$.default();var r=e.ended.diff(e.started),o=$.default.duration(r);console.log("Request '"+e.id+"' ended at: "+e.ended.format("YYYY-MM-DD HH:mm:ss")+" ["+e.method+"] "+e.url),console.log("Request '"+e.id+"' lasted: "+o.asMilliseconds()+"ms"),n(null)},e}();ur=cr([o.injectable(),i.Middleware({type:"after"})],ur);var lr=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},fr=function(){function e(){}return e.prototype.use=function(e,t,n){e.id=(new b.ObjectId).toHexString(),e.started=$.default(),console.log("Request '"+e.id+"' started at: "+e.started.format("YYYY-MM-DD HH:mm:ss")+" ["+e.method+"] "+e.url),n(null)},e}();fr=lr([o.injectable(),i.Middleware({type:"before"})],fr);var hr=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},dr=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},pr=this&&this.__param||function(e,t){return function(n,r){t(n,r,e)}},gr=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},yr=function(){function e(e,t){this.progresses=e,this.socketServer=t}return e.prototype.advanceProgress=function(e,t){return gr(this,void 0,void 0,(function(){var n,r;return W(this,(function(o){switch(o.label){case 0:return[4,this.progresses.get(t)];case 1:return(n=o.sent())?(r=n.toJSON(),Ee(this.socketServer,(function(n){n.interestedProgresses instanceof Set&&n.interestedProgresses.has(t)&&e.emit("background-progress-changed",r)})),console.log("progress changed: "+e.id+", data: "+JSON.stringify(r)),[2]):[2]}}))}))},e.prototype.setProgressInterest=function(e,t){return gr(this,void 0,void 0,(function(){var n,r;return W(this,(function(o){switch(o.label){case 0:return[4,this.progresses.get(t)];case 1:return(n=o.sent())?(r=n.toJSON(),e.interestedProgresses=e.interestedProgresses||new Set,e.interestedProgresses.has(t)||(e.interestedProgresses.add(t),e.emit("background-progress-changed",r),console.log("progress interest added: "+e.id+", data: "+JSON.stringify(r))),[2]):[2]}}))}))},e}();hr([s.OnMessage("background-progress"),pr(0,s.ConnectedSocket()),pr(1,s.MessageBody()),dr("design:type",Function),dr("design:paramtypes",[Object,String]),dr("design:returntype",Promise)],yr.prototype,"advanceProgress",null),hr([s.OnMessage("background-progress-interest"),pr(0,s.ConnectedSocket()),pr(1,s.MessageBody()),dr("design:type",Function),dr("design:paramtypes",[Object,String]),dr("design:returntype",Promise)],yr.prototype,"setProgressInterest",null),yr=hr([o.injectable(),s.SocketController(),pr(1,o.inject(tt)),dr("design:paramtypes",[e.Progresses,Object])],yr);var vr=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},mr=function(){function e(){}return e.prototype.use=function(e,t){t()},e}();mr=vr([o.injectable(),s.Middleware()],mr);var br=function(){function e(e,t,n){this.container=e,this.exists=t,this.path=n,this.map=new Map}return Object.defineProperty(e.prototype,"parentTree",{get:function(){return this.container.parent.tree},enumerable:!1,configurable:!0}),e.prototype.resolveService=function(){return this.exists?this.container.resolve(this.path):null},e.prototype.resolveLeaves=function(){var e;try{var t=this.parentTree.resolvePath(this.path);e=t.resolveLeaves()}catch(t){e=new Map}var n=function(t,r){t.forEach((function(t,o){var i=r?r+"."+o:o;0!=t.map.size?n(t.map,i):e.set(i,t)}))};return n(this.map,""),e},e.prototype.resolveServices=function(){var e=new Map;return this.resolveLeaves().forEach((function(t,n){e.set(n,t.resolveService())})),e},e.prototype.resolveAncestor=function(t){var n,r,o;if(!le(t)||0==t.length)return this;try{o=(o=this.parentTree.resolvePath(this.path)).resolveAncestor(t)}catch(t){o=new e(this.container,!1,"")}var i=t.split("."),s=this,a=this;try{for(var c=X(i),u=c.next();!u.done;u=c.next()){var l=u.value;if(!(s=s.map.get(l))){if(a==this){if(o.path.length>0)return o;throw new Error("Ancestor '"+t+"' not found in current tree: '"+this.path+"'")}return a}a=s}}catch(e){n={error:e}}finally{try{u&&!u.done&&(r=c.return)&&r.call(c)}finally{if(n)throw n.error}}return o.path.length>a.path.length?o:a},e.prototype.resolvePath=function(t,n){void 0===n&&(n=!0);var r=this.path?this.path+"."+t:t,o=new e(this.container,!1,r);try{o=this.resolveAncestor(t)}catch(e){if(n)throw new Error("Path '"+t+"' not found in current tree: '"+this.path+"'");return o}if(o.path!==r){if(n)throw new Error("Path '"+t+"' not found in current tree: '"+this.path+"'");return o}return o},e.prototype.addPath=function(t){if(!le(t)||0==t.length)return this;var n=t.split("."),r=n.length-1,o=this;t=this.path;for(var i=0;i<=r;i++){var s=n[i];o.map.has(s)||o.map.set(s,new e(this.container,!1,t?t+"."+s:s)),(o=o.map.get(s)).exists=o.exists||i==r,t=o.path}return this},e}(),wr=function(){function e(e,t){void 0===t&&(t=null),this.container=e,this.parent=t,e.wrapperContainer=this,this.tokens=[],this.tokenSet=new Set,this.root=new br(this,!1,"")}return Object.defineProperty(e.prototype,"registeredTokens",{get:function(){var e;return((null===(e=this.parent)||void 0===e?void 0:e.registeredTokens)||[]).concat(this.tokens)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"tree",{get:function(){return this.root},enumerable:!1,configurable:!0}),e.prototype.beforeResolution=function(e,t,n){this.container.beforeResolution(e,t,n)},e.prototype.afterResolution=function(e,t,n){this.container.afterResolution(e,t,n)},e.prototype.clearInstances=function(){this.container.clearInstances()},e.prototype.createChildContainer=function(){return new e(this.container.createChildContainer(),this)},e.prototype.isRegistered=function(e,t){return this.container.isRegistered(e,t)},e.prototype.register=function(e,t,n){return o.isFactoryProvider(t)?(this.container.register(e,{useFactory:function(e){return t.useFactory(e.wrapperContainer)}}),this.addToken(e)):(this.container.register(e,t),this.addToken(e))},e.prototype.registerInstance=function(e,t){return this.container.registerInstance(e,t),this.addToken(e)},e.prototype.registerSingleton=function(e,t){return this.container.registerSingleton(e,t),this.addToken(e)},e.prototype.registerType=function(e,t){return this.container.registerType(e,t),this.addToken(e)},e.prototype.reset=function(){this.tokens=[],this.tokenSet=new Set,this.container.reset()},e.prototype.resolve=function(e){return this.container.resolve(e)},e.prototype.resolveAll=function(e){return this.container.resolveAll(e)},e.prototype.get=function(e){return this.container.resolve(e)},e.prototype.addToken=function(e){return this.tokenSet.has(e)||(this.tokenSet.add(e),this.tokens.push(e),le(e)&&this.root.addPath(e)),this},e}(),jr=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))};function Pr(n,r){return jr(this,void 0,void 0,(function(){var o,i,s;return W(this,(function(a){switch(a.label){case 0:return o=t.resolve(n||__dirname,"public_html"),i=r.get(Ke),s=r.get(e.EndpointProvider),console.log(o,g.existsSync(o)),g.existsSync(o)?(console.log("public_html exists. setting up static files serving..."),i.use(M.static(o,{maxAge:"1y"}))):console.log('public_html does not exist on path: "'+o+'"'),[4,s.configure(i)];case 1:return a.sent(),[2]}}))}))}var Or=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},Rr=function(){function e(e,t,n){this.assetResolver=e,this.progresses=t,this.lazyId=n}return Object.defineProperty(e.prototype,"assets",{get:function(){return this.assetResolver.assets},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"lazyAssets",{get:function(){return this.assetResolver.lazyAssets},enumerable:!1,configurable:!0}),e.prototype.process=function(e){return Or(this,void 0,void 0,(function(){var t,n,r,o;return W(this,(function(i){switch(i.label){case 0:return[4,this.lazyAssets.read(this.lazyId)];case 1:return t=i.sent(),[4,this.progresses.get(t.progressId)];case 2:if(!(n=i.sent())||n.canceled)return[2,null];n.setMessageBridge(e),i.label=3;case 3:return i.trys.push([3,7,,9]),[4,this.generate(n,e)];case 4:return r=i.sent(),[4,n.load()];case 5:return!(n=i.sent())||n.canceled?[2,null]:[4,t.writeAsset(r)];case 6:return i.sent(),[3,9];case 7:return o=i.sent(),[4,n.setError(o.message||o)];case 8:throw i.sent(),o;case 9:return n.remaining>0?[4,n.advance(n.remaining)]:[3,11];case 10:i.sent(),i.label=11;case 11:return[2]}}))}))},e}(),_r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))};function xr(t,n){return _r(this,void 0,void 0,(function(){var o,s,a,c;return W(this,(function(u){switch(u.label){case 0:if(n.user)return[2,n.user];o=n.header("Authorization")||"",s=null;try{a=t.resolve(e.Configuration),s=r.verify(o.split(" ")[1],a.resolve("jwtSecret"))}catch(e){throw new i.HttpError(401,"Authentication failed. ("+e.message+")")}if(!s)throw new i.HttpError(401,"Authentication failed. (Maybe invalid token)");return c=n,[4,t.resolve(e.UserManager).getById(s.id)];case 1:return c.user=u.sent(),[2,n.user]}}))}))}function Cr(){var n=[new ot("templatesDir",t.join(__dirname,"templates")),new ot("galleryDir",t.join(__dirname,"gallery")),new ot("cacheDir",t.join(__dirname,"cache")),new ot("defaultLanguage","en"),new ot("smtpHost","smtp.sendgrid.net"),new ot("smtpPort",587),new ot("smtpUser","apikey"),new ot("smtpPassword",""),new ot("mailSenderAddress","info@stemy.hu"),new ot("translationsTemplate","https://translation.service/[lang]"),new ot("jwtSecret","eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9"),new ot("mongoUri",""),new ot("mongoDb","node-backend"),new ot("mongoUser",null),new ot("mongoPassword",null),new ot("nodeEnv","production"),new ot("appPort",80),new ot("zmqPort",3e3),new ot("zmqBackPort",3100),new ot("zmqRemoteHost","tcp://127.0.0.1"),new ot("isWorker",!1),new ot("mainEndpoint",""),new ot("idChars","0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"),new ot("idSeparator","-"),new ot("idPrefix","ID-"),new ot("idParts",[4,4]),new ot("jsonLimit","250mb"),new ot("jobTimeout",3e5),new ot("cacheCollection","cache")].map((function(e){return{provide:nt,useValue:e}})),r=[e.AssetProcessor,e.AssetResolver,e.Assets,e.BackendProvider,e.Cache,e.CacheProcessor,e.Configuration,e.EndpointProvider,e.Fixtures,e.Gallery,e.GalleryCache,e.IdGenerator,e.JobManager,e.LazyAssets,e.MailSender,e.MemoryCache,e.MongoConnector,e.Progresses,e.TemplateRenderer,e.TranslationProvider,e.Translator,e.UserManager],i=new wr(o.container.createChildContainer());return n.forEach((function(e){i.register(e.provide,e)})),r.forEach((function(e){o.container.isRegistered(e)||i.register(e,e)})),i}e.DI_CONTAINER=rt,e.EXPRESS=Ke,e.FIXTURE=Qe,e.HTTP_SERVER=et,e.JOB=Ze,e.LazyAssetGenerator=Rr,e.PARAMETER=nt,e.Parameter=ot,e.ResolveEntity=function(e,t){var n=this,r=e.modelName,o=r.toLowerCase();return i.createParamDecorator({required:!1,value:function(s){return K(n,void 0,void 0,(function(){var n,a,c,u,l,f,h,d;return W(this,(function(p){switch(p.label){case 0:if(n=s.request,a=n.header("x-"+o+"-token"),!(c=n.params[o+"Id"])&&!a)throw new i.BadRequestError(r+" id or token should be defined!");return[4,u=a?e.findOne({token:a}):e.findById(c)];case 1:if(!(l=p.sent()))throw new i.HttpError(404,a?r+" could not be found with token: "+a:r+" could not be found with id: "+c);if(!fe(t))return[3,5];p.label=2;case 2:return p.trys.push([2,4,,5]),f=s.request,h=o,[4,Me(t(u,s))];case 3:return f[h]=p.sent()||l,[2,s.request[o]];case 4:throw d=p.sent(),new i.BadRequestError(r+" check error: "+(d.message||d));case 5:return s.request[o]=l,[2,l]}}))}))}})},e.SOCKET_SERVER=tt,e.Type=Xe,e.assign=function(e,t,n){return He(e,t,n)},e.broadcast=Ee,e.bufferToStream=Re,e.colorize=Ge,e.convertValue=ve,e.copy=function(e){return He(null,e)},e.copyStream=Ce,e.createServices=Cr,e.createTransformer=function(e){return function(t,n,r){return n.id=Ne(n.id)||n.id,t._id&&(n._id=Ne(t._id),n.id=n.id||n._id),delete n.__v,fe(e)&&e(t,n,r)||n}},e.deleteFile=function(e){return new Promise((function(t,n){g.unlink(e,(function(e){e?n(e):t()}))}))},e.deleteFromBucket=qe,e.filter=function(e,t){return He(null,e,t)},e.firstItem=function(e){return e[0]},e.getConstructorName=Te,e.getExtension=function(e){return t.basename(e||"").split(".").pop()},e.getFileName=function(e,n){void 0===n&&(n=!1);var r=t.basename(e||"");return n?r:r.split(".").slice(0,-1).join(".")},e.getFunctionParams=Fe,e.getType=oe,e.getValue=ye,e.groupBy=function(e,t){return e.reduce((function(e,n){var r=t(n);return e[r]=e[r]||[],e[r].push(n),e}),{})},e.hydratePopulated=we,e.idToString=Ne,e.injectServices=me,e.isArray=se,e.isBoolean=ae,e.isConstructor=he,e.isDate=ce,e.isDefined=re,e.isFunction=fe,e.isInterface=pe,e.isNullOrUndefined=ne,e.isObject=ie,e.isObjectId=function(e){return"string"==typeof e&&24==e.length&&!isNaN(Number("0x"+e))},e.isPrimitive=ue,e.isString=le,e.isType=de,e.jsonHighlight=Ue,e.lastItem=function(e){return e[e.length-1]},e.lcFirst=ge,e.letsLookupStage=function(e,t,n,r){return void 0===n&&(n=null),void 0===r&&(r=null),{$lookup:{from:e,let:r=r||{id:"$_id"},pipeline:t,as:n=n||e}}},e.lookupStages=function(e,t,n,r,o){void 0===n&&(n=null),void 0===r&&(r="_id"),void 0===o&&(o=!0),n=n||t.replace("Id","");var i=[{$lookup:{from:e,localField:t,foreignField:r,as:n}},{$unwind:{path:"$"+n,preserveNullAndEmptyArrays:!0}}];return o||i.splice(1,1),i},e.matchField=function(e,t,n){return{field:e,filter:t,when:n}},e.matchFieldStages=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={};return e.forEach((function(e){e.when&&(n[e.field]=e.filter)})),Object.keys(n).length>0?[be(n)]:[]},e.matchStage=be,e.md5=function(e){if(ie(e)&&(e=JSON.stringify(e)),!le(e))throw"Can't md5 other that raw object or string";return h.createHash("md5").update(e).digest("hex")},e.mkdirRecursive=Se,e.multiSubscription=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return new d.Subscription((function(){e.forEach((function(e){e.unsubscribe()}))}))},e.observableFromFunction=function(e){var t;return new d.Observable((function(n){if(!t){t=new d.Subject;try{t=d.from(e())}catch(e){p.canReportError(t)?t.error(e):console.warn(e)}}return t.subscribe(n)}))},e.padLeft=function(e,t,n){return void 0===t&&(t=3),void 0===n&&(n="0"),(""+e).padStart(t,n)},e.padRight=function(e,t,n){return void 0===t&&(t=3),void 0===n&&(n="0"),(""+e).padEnd(t,n)},e.paginate=function(e,t,n){return e.countDocuments(t).then((function(r){var o=e.find(t);return le(n.sort)&&(o=o.sort(n.sort)),se(n.populate)&&n.populate.forEach((function(e){o=o.populate(e)})),console.log("PAGINATE",e.modelName,n.limit,n.limit>0),(n.limit>0?o.skip(n.page*n.limit).limit(n.limit):o).then((function(e){return{count:r,items:e,meta:{total:r}}}))}))},e.paginateAggregations=function(e,t,n,r){return void 0===r&&(r={}),K(this,void 0,void 0,(function(){var o,i,s,a,c;return W(this,(function(u){switch(u.label){case 0:return o=le(n.sort)&&n.sort?n.sort.startsWith("-")?n.sort.substr(1):n.sort:null,i=o?[{$sort:(c={},c[o]=o==n.sort?1:-1,c)}]:[],[4,e.aggregate(Z(t,i,[{$group:{_id:"results",result:{$push:"$$CURRENT"}}},{$project:{_id:0,items:n.limit>0?{$slice:["$result",n.page*n.limit,n.limit]}:"$result",count:{$size:"$result"},meta:Object.assign({total:{$size:"$result"}},r)}}]))];case 1:return s=u.sent(),(a=s[0])?(a.items=a.items.map((function(t){return we(e,t)})),[2,a]):[2,{items:[],count:0,meta:{total:0}}]}}))}))},e.projectStage=function(e){return{$project:e}},e.promiseTimeout=Ae,e.proxyFunction=Ie,e.proxyFunctions=function(e,t,n){void 0===n&&(n=null),n=n||ge(Te(t)).replace(/helper$/gi,"");var r=Object.getOwnPropertyDescriptors(t.prototype);Object.keys(r).forEach((function(t){var o=r[t].value;fe(o)&&"constructor"!==t&&(Fe(o)[0]==n&&(e.methods[t]=Ie(t)))})),me(e,{helper:t})},e.rand=De,e.random=Be,e.readAndDeleteFile=function(e,t){return void 0===t&&(t=5e3),K(this,void 0,void 0,(function(){var n;return W(this,(function(r){switch(r.label){case 0:return[4,ke(e)];case 1:return n=r.sent(),setTimeout((function(){g.unlink(e,(function(){}))}),t),[2,n]}}))}))},e.readFile=ke,e.regroup=function(e,t){var n=[];return se(e)&&0!=e.length?(e=Array.from(e),n.push([e.shift()]),e.forEach((function(e){var r=n.find((function(n){return n.some((function(n){return t(n,e)}))}));r?r.push(e):n.push([e])})),n):n},e.replaceSpecialChars=function(e,t){return void 0===t&&(t="-"),(""+e).replace(/[&\/\\#, +()$~%.@'":*?<>{}]/g,t)},e.runCommand=function(e,t){return void 0===t&&(t=0),new Promise((function(n,r){var o=f.exec(e,(function(e,o){if(e&&t!==e.code)return console.log(e),void r(e);for(var i=(o||"").split("\n"),s=null;!s&&i.length>0;)s=i.pop();n(s)}));o.stdout.on("data",(function(e){console.log(e.toString())})),o.stderr.on("data",(function(e){console.error(e.toString())}))}))},e.setupBackend=function(t,r,f){return _r(this,void 0,void 0,(function(){var h,d,p,g,y,v,m,b,w,j,P=this;return W(this,(function(O){switch(O.label){case 0:return r=Array.isArray(r)?r:[],f=f||Cr(),h=t.fixtures||[],d=h.map((function(e){return{provide:Qe,useClass:e}})),p=(t.params||[]).map((function(e){return{provide:nt,useValue:e}})),g=(t.jobs||[]).map((function(e){return{provide:Ze,useValue:e}})),(y=t.restOptions||{}).defaultErrorHandler=!1,y.cors=Object.assign({credentials:!0,exposedHeaders:["content-disposition"],origin:function(e,t){t(null,!0)}},y.cors||{}),y.routePrefix=t.routePrefix||"/api",y.routePrefix="/"==y.routePrefix?"":y.routePrefix,y.middlewares=[e.ErrorHandlerMiddleware,ir,e.LanguageMiddleware,fr,ur].concat(y.middlewares||[]),y.controllers=[zn,e.AuthController,e.GalleryController,Zn].concat(y.controllers||[]),(v=t.socketOptions||{}).middlewares=[mr].concat(v.middlewares||[]),v.controllers=[yr].concat(v.controllers||[]),m=[],[nt].forEach((function(e){f.resolveAll(e).forEach((function(t){m.push({provide:e,useValue:t})}))})),m.push.apply(m,Z(h,d,p,g,y.middlewares,y.controllers,v.middlewares,v.controllers,r,[{provide:Ke,useFactory:function(t){return t.resolve(e.BackendProvider).express}},{provide:et,useFactory:function(t){return t.resolve(e.BackendProvider).server}},{provide:tt,useFactory:function(t){return t.resolve(e.BackendProvider).io}}])),b=f.createChildContainer(),m.forEach((function(e){if(de(e)){if(o.container.isRegistered(e))return;b.register(e,e)}else b.register(e.provide,e)})),b.register(rt,{useValue:b}),te.appContainer=te.appContainer||b,y.authorizationChecker=function(e,t){return _r(P,void 0,void 0,(function(){var n,r,o,s,a,c,u,l,f,h,d;return W(this,(function(p){switch(p.label){case 0:return[4,xr(b,e.request)];case 1:if(!(n=p.sent()))throw new i.HttpError(401,"Authentication failed. (User can't be found.)");if(r=Array.isArray(n.roles)?n.roles:[],!(Array.isArray(t)&&t.length>0))return[3,13];o=null,p.label=2;case 2:p.trys.push([2,10,11,12]),s=X(t),a=s.next(),p.label=3;case 3:if(a.done)return[3,9];if(!fe(c=a.value))return[3,7];p.label=4;case 4:return p.trys.push([4,6,,7]),[4,Me(c(n,e))];case 5:return p.sent()?[2,!0]:[3,7];case 6:return u=p.sent(),o=u,[3,7];case 7:if(r.indexOf(c)>=0)return[2,!0];p.label=8;case 8:return a=s.next(),[3,3];case 9:return[3,12];case 10:return l=p.sent(),h={error:l},[3,12];case 11:try{a&&!a.done&&(d=s.return)&&d.call(s)}finally{if(h)throw h.error}return[7];case 12:throw f=o&&(o.message||le(o))?o.message||o:"User doesn't have access to this resource",new i.HttpError(401,"Authentication failed. ("+f+")");case 13:return[2,!0]}}))}))},y.currentUserChecker=function(e){return _r(P,void 0,void 0,(function(){return W(this,(function(t){return[2,xr(b,e.request)]}))}))},w=b.resolve(e.Configuration),j=b.resolve(e.BackendProvider),t.restOptions&&(j.express.use(n.json({limit:w.hasParam("jsonLimit")?w.resolve("jsonLimit"):"250mb"})),i.useContainer(b),i.useExpressServer(j.express,y),j.express.get("/api-docs",(function(n,r){r.status(200).end(function(t){var n;if(Ye)return Ye;var r=i.getMetadataArgsStorage(),o=a.routingControllersToSpec(r);return o.basePath="/api/",o.definitions=l.validationMetadatasToSchemas({classTransformerMetadataStorage:c.defaultMetadataStorage,additionalConverters:(n={},n[u.ValidationTypes.CUSTOM_VALIDATION]=function(n,r){var o=fe(t)?t(n,r):t;if(o)return o;var i=n.constraints||[];return n.constraintCls===e.IsFile?{multi:i[0]||!1,type:"file"}:n.constraintCls===e.IsObjectId?{endpoint:i[0]||!1,multi:i[1]||!1,type:"list"}:null},n)}),o.components.schemas=o.definitions,Ye=JSON.stringify(o)}(t.customValidation))}))),t.socketOptions&&(s.useContainer(b),s.useSocketServer(j.io,v)),w.hasParam("mongoUri")&&w.resolve("mongoUri")?(console.log("Connecting to MongoDB..."),[4,b.resolve(e.MongoConnector).connect()]):[3,2];case 1:O.sent(),console.log("Successfully connected to MongoDB."),O.label=2;case 2:return[4,Pr(t.rootFolder,b)];case 3:return O.sent(),[2,b]}}))}))},e.streamToBuffer=_e,e.toImage=Oe,e.ucFirst=function(e){return e?e[0].toUpperCase()+e.substr(1):""},e.uniqueItems=function(e){return e.filter((function(t,n){return e.indexOf(t)===n}))},e.unwindStage=function(e){return{$unwind:e}},e.valueToPromise=Me,e.writeFile=function(e,n){return K(this,void 0,void 0,(function(){return W(this,(function(r){switch(r.label){case 0:return[4,Se(t.dirname(e))];case 1:return r.sent(),[2,new Promise((function(t,r){g.writeFile(e,n,(function(e){e?r(e):t(n)}))}))]}}))}))},Object.defineProperty(e,"__esModule",{value:!0})}));
2
- //# sourceMappingURL=stemy-backend.umd.min.js.map