mp-holistic
Version:
si prefigge l'umile compito di aiutare nella creazione di : - un server API REST mediante express - un semplice ORM per Postgres Questo tramite decoratori o classi particolari.
331 lines (330 loc) • 14 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ListaExpressClasse = exports.ExpressClasse = void 0;
const express_1 = __importDefault(require("express"));
const classe_metadata_1 = require("../metadata/classe.metadata");
const metodo_express_1 = require("./metodo.express");
const fs_1 = __importDefault(require("fs"));
class ExpressClasse extends classe_metadata_1.MetadataClasse {
constructor(item) {
super(item);
this.listaMetodi = new metodo_express_1.ListaExpressMetodo();
this.id = '';
this.nome = '';
this.rotte = (0, express_1.default)();
this.path = '';
this.percorsi = { pathGlobal: '', patheader: '', porta: 0 };
this.html = [];
if (item.id != undefined)
this.id = item.id;
if (item.nome != undefined)
this.nome = item.nome;
if (item.rotte != undefined)
this.rotte = item.rotte;
if (item.path != undefined)
this.path = item.path;
if (this.path == undefined || this.path == '')
this.path = this.nomeVariante;
if (item.percorsi)
this.percorsi = item.percorsi;
if (item.html) {
this.html = [];
for (let index = 0; index < item.html.length; index++) {
const element = item.html[index];
if (element.percorsoIndipendente == undefined)
element.percorsoIndipendente = false;
if (element.html != undefined && element.htmlPath == undefined
&& this.html.find(x => { if (x.path == element.path)
return true;
else
return false; }) == undefined) {
this.html.push({
contenuto: element.html,
path: element.path,
percorsoIndipendente: element.percorsoIndipendente
});
}
else if (element.html == undefined && element.htmlPath != undefined
&& this.html.find(x => { if (x.path == element.path)
return true;
else
return false; }) == undefined) {
try {
this.html.push({
contenuto: fs_1.default.readFileSync(element.htmlPath).toString(),
path: element.path,
percorsoIndipendente: element.percorsoIndipendente
});
}
catch (error) {
this.html.push({
contenuto: 'Nessun contenuto',
path: element.path,
percorsoIndipendente: element.percorsoIndipendente
});
}
}
}
}
if (item.LogGenerale) {
this.listaMetodi.forEach(element => {
if (element.metodoEventi.onLog == undefined)
element.metodoEventi.onLog = item.LogGenerale;
});
this.LogGenerale = item.LogGenerale;
}
if (item.Istanziatore) {
this.listaMetodi.forEach(metodo => {
let contiene = false;
metodo.listaParametri.forEach(parametro => {
if (parametro.autenticatore == true)
contiene = true;
});
if (contiene)
metodo.metodoEventi.Istanziatore = item.Istanziatore;
});
this.Istanziatore = item.Istanziatore;
}
if (item.cacheOptionMemory) {
this.listaMetodi.forEach(element => {
var _a;
if (element.metodoLimitazioni.cacheOptionMemory == undefined) {
element.metodoLimitazioni.cacheOptionMemory = (_a = item.cacheOptionMemory) !== null && _a !== void 0 ? _a : { durationSecondi: 1 };
}
});
this.cacheOptionMemory = item.cacheOptionMemory;
}
/* if (item.classeSwagger && item.classeSwagger != '') {
this.classeSwagger = item.classeSwagger;
this.metaRif.listaMetodi.forEach(element => {
if (element.metodoExpress.swaggerClassi) {
const ris = element.swaggerClassi.find(x => { if (x == this.classeSwagger) return true; else return false; })
if (ris == undefined && this.classeSwagger) {
element.swaggerClassi.push(this.classeSwagger);
}
}
});
} */
}
GetThis() { return this; }
Mergia(item) {
super.Mergia(item);
if (item.id != undefined && item.id != '')
this.id = item.id;
if (item.nome != undefined && item.nome != '')
this.nome = item.nome;
if (item.rotte != undefined)
this.rotte = item.rotte;
if (item.path != undefined && item.path != '')
this.path = item.path;
if (item.percorsi)
this.percorsi = item.percorsi;
if (item.html) {
this.html = [];
for (let index = 0; index < item.html.length; index++) {
const element = item.html[index];
if (element.percorsoIndipendente == undefined)
element.percorsoIndipendente = false;
if (element.html != undefined && element.htmlPath == undefined
&& this.html.find(x => { if (x.path == element.path)
return true;
else
return false; }) == undefined) {
this.html.push({
contenuto: element.html,
path: element.path,
percorsoIndipendente: element.percorsoIndipendente
});
}
else if (element.html == undefined && element.htmlPath != undefined
&& this.html.find(x => { if (x.path == element.path)
return true;
else
return false; }) == undefined) {
try {
this.html.push({
contenuto: fs_1.default.readFileSync(element.htmlPath).toString(),
path: element.path,
percorsoIndipendente: element.percorsoIndipendente
});
}
catch (error) {
this.html.push({
contenuto: 'Nessun contenuto',
path: element.path,
percorsoIndipendente: element.percorsoIndipendente
});
}
}
else if (this.html.find(x => { if (x.path == element.path)
return true;
else
return false; }) != undefined) {
this.html.find(x => { if (x.path == element.path)
return true;
else
return false; });
//debugger;
}
}
}
if (item.LogGenerale) {
this.listaMetodi.forEach(element => {
if (element.metodoEventi.onLog == undefined)
element.metodoEventi.onLog = item.LogGenerale;
});
this.LogGenerale = item.LogGenerale;
}
if (item.Istanziatore) {
this.listaMetodi.forEach(metodo => {
let contiene = false;
metodo.listaParametri.forEach(parametro => {
if (parametro.autenticatore == true)
contiene = true;
});
if (contiene)
metodo.metodoEventi.Istanziatore = item.Istanziatore;
});
this.Istanziatore = item.Istanziatore;
}
if (item.cacheOptionMemory) {
this.listaMetodi.forEach(element => {
var _a;
if (element.metodoLimitazioni.cacheOptionMemory == undefined) {
element.metodoLimitazioni.cacheOptionMemory = (_a = item.cacheOptionMemory) !== null && _a !== void 0 ? _a : { durationSecondi: 1 };
}
});
this.cacheOptionMemory = item.cacheOptionMemory;
}
}
SettaPathRoot_e_Global(item, percorsi, app) {
/* */
if (percorsi.patheader == undefined)
this.percorsi.patheader = "localhost";
else
this.percorsi.patheader = percorsi.patheader;
if (percorsi.porta == undefined)
this.percorsi.porta = 3000;
else
this.percorsi.porta = percorsi.porta;
const pathGlobal = percorsi.pathGlobal + '/' + this.path;
this.percorsi.pathGlobal = pathGlobal;
/* */
this.ConfiguraListaRotteHTML(app, pathGlobal);
this.listaMetodi.ConfiguraListaRotteApplicazione(app, this.percorsi);
}
ConfiguraListaRotteHTML(app, pathGlobal) {
for (let index = 0; index < this.html.length; index++) {
const element = this.html[index];
//element.ConfiguraRotteHtml(app, this.percorsi.pathGlobal,)
let percorsoTmp = '';
if (element.percorsoIndipendente)
'/' + element.path;
else
percorsoTmp = pathGlobal + '/' + element.path;
app.get(percorsoTmp,
//this.cors,
//this.helmet,
(req, res) => __awaiter(this, void 0, void 0, function* () {
if (this.html)
res.send(element.contenuto);
else
res.sendStatus(404);
}));
}
}
}
exports.ExpressClasse = ExpressClasse;
class ListaExpressClasse extends classe_metadata_1.ListaMetadataClasse {
/* static nomeMetadataKeyTargetFor_Express = "ListaExpressClasse"; */
constructor() {
super();
}
Mergia(item) {
const t = super.Mergia(item);
return t;
/*
for (let index = 0; index < item.length; index++) {
const element = item[index];
const elementoCercato = this.Cerca(element);
if (elementoCercato == undefined) {
const tmp = element;
this.push(tmp);
}
else {
elementoCercato.Mergia(elementoCercato);
}
} */
}
CercaSeNoAggiungi(item) {
const t = super.CercaSeNoAggiungi(item);
return t;
/*
let classe = undefined;
for (let index = 0; index < this.length && classe == undefined; index++) {
const element = this[index];
if (Meta.Compara(element, item) == 0) classe = element;
}
if (classe == undefined) {
classe = new ExpressClasse(item);
this.AggiungiElemento(classe);
}
return classe; */
}
Cerca(item) {
const t = super.CercaSeNoAggiungi(item);
return t;
/*
for (let index = 0; index < this.length; index++) {
const element = this[index];
if (Meta.Compara(element, item) == 0) return <ExpressClasse>element;
}
return undefined; */
}
AggiungiElemento(item) {
const t = super.AggiungiElemento(item);
return t;
/*
for (let index = 0; index < this.length; index++) {
const element = this[index];
if (Meta.Compara(element, item) == 0) {
this[index].Mergia(item);
return this[index];
}
}
this.push(item);
return item; */
}
ConfiguraListaRotteApplicazione(path, percorsi, serverExpressDecorato) {
for (let index = 0; index < this.length; index++) {
const element = this[index];
element.SettaPathRoot_e_Global(path, percorsi, serverExpressDecorato);
}
}
}
exports.ListaExpressClasse = ListaExpressClasse;
/*
export function GetListaClasseExpress() {
let tmp: ListaExpressClasse | undefined = undefined;
tmp = Reflect.getMetadata(ListaExpressClasse.nomeMetadataKeyTargetFor_Express, targetTerminale);
if (tmp == undefined) {
tmp = new ListaExpressClasse();
}
return tmp;
}
export function SalvaListaClasseExpress(tmp: ListaExpressClasse) {
Reflect.defineMetadata(ListaExpressClasse.nomeMetadataKeyTargetFor_Express, tmp, targetTerminale);
} */
//# sourceMappingURL=classe.express.js.map