Comparing version 0.15.1 to 0.16.0
@@ -9,4 +9,5 @@ declare global { | ||
var canMagicallyEditCode: boolean; | ||
var verbose: boolean; | ||
} | ||
} | ||
export {}; |
@@ -47,3 +47,3 @@ "use strict"; | ||
const newType = stripOperatorsFromType(property); | ||
return `${propertyName}${getMandatoryOperator(property, defaultMandatory, optionalFieldsType)} ${newType.type}${newType.isArray ? "[]" : ""}${getNullOption(property, defaultMandatory)}`; | ||
return `${propertyName}${getMandatoryOperator(property, defaultMandatory, optionalFieldsType)} ${newType.type}${newType.isArray ? "[]" : ""}${getNullOption(property, defaultMandatory, optionalFieldsType)}`; | ||
} | ||
@@ -53,3 +53,3 @@ if (property.enum) { | ||
.map((e) => `"${e}"`) | ||
.join(" | ")}${getNullOption(property, defaultMandatory)}`; | ||
.join(" | ")}${getNullOption(property, defaultMandatory, optionalFieldsType)}`; | ||
} | ||
@@ -61,3 +61,3 @@ if (!((_a = property === null || property === void 0 ? void 0 : property.type) === null || _a === void 0 ? void 0 : _a.includes("object"))) { | ||
const refValue = (_e = (_d = property === null || property === void 0 ? void 0 : property.items) === null || _d === void 0 ? void 0 : _d.$ref) === null || _e === void 0 ? void 0 : _e.split("/").pop(); | ||
return `${propertyName}${getMandatoryOperator(property, defaultMandatory, optionalFieldsType)} Efesto.${refValue}[] ${getNullOption(property, defaultMandatory)}`; | ||
return `${propertyName}${getMandatoryOperator(property, defaultMandatory, optionalFieldsType)} Efesto.${refValue}[] ${getNullOption(property, defaultMandatory, optionalFieldsType)}`; | ||
} | ||
@@ -69,3 +69,3 @@ if ((_f = property === null || property === void 0 ? void 0 : property.items) === null || _f === void 0 ? void 0 : _f.properties) { | ||
}); | ||
return `${propertyName}${getMandatoryOperator(property, defaultMandatory, optionalFieldsType)}{${properties.join(";\n")}${getNullOption(property, defaultMandatory)}[]}`; | ||
return `${propertyName}${getMandatoryOperator(property, defaultMandatory, optionalFieldsType)}{${properties.join(";\n")}${getNullOption(property, defaultMandatory, optionalFieldsType)}[]}`; | ||
} | ||
@@ -81,3 +81,3 @@ return `${propertyName}:any[]`; | ||
const refValue = property.$ref.split("/").pop(); | ||
return `${propertyName}${getMandatoryOperator(property, defaultMandatory, optionalFieldsType)} Efesto.${refValue} ${getNullOption(property, defaultMandatory)}`; | ||
return `${propertyName}${getMandatoryOperator(property, defaultMandatory, optionalFieldsType)} Efesto.${refValue} ${getNullOption(property, defaultMandatory, optionalFieldsType)}`; | ||
} | ||
@@ -89,3 +89,3 @@ if (property === null || property === void 0 ? void 0 : property.properties) { | ||
}); | ||
return `${propertyName}${getMandatoryOperator(property, defaultMandatory, optionalFieldsType)}{${properties.join(";\n")}} ${getNullOption(property, defaultMandatory)}`; | ||
return `${propertyName}${getMandatoryOperator(property, defaultMandatory, optionalFieldsType)}{${properties.join(";\n")}} ${getNullOption(property, defaultMandatory, optionalFieldsType)}`; | ||
} | ||
@@ -105,3 +105,5 @@ return `${propertyName}?: any`; | ||
} | ||
function getNullOption(property, defaultMandatory) { | ||
function getNullOption(property, defaultMandatory, optionalFieldsType) { | ||
if (optionalFieldsType === "undefined") | ||
return ""; | ||
if (isPropertyMandatory(property, defaultMandatory)) { | ||
@@ -108,0 +110,0 @@ return ""; |
@@ -11,2 +11,3 @@ export * from "./serviceUtils/types"; | ||
canMagicallyEditCode?: boolean; | ||
verbose?: boolean; | ||
abacPermissions?: { | ||
@@ -13,0 +14,0 @@ actions?: string[]; |
@@ -14,2 +14,3 @@ "use strict"; | ||
const yaml_1 = tslib_1.__importDefault(require("yaml")); | ||
const utils_1 = require("./engine/utils"); | ||
const wrapperResolver_1 = tslib_1.__importDefault(require("./engine/wrapperResolver")); | ||
@@ -23,4 +24,3 @@ const typeGenerator_1 = require("./generators/typeGenerator"); | ||
function efesto(params) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t; | ||
(0, console_1.printEfestoLogoToConsole)(); | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w; | ||
global.Efesto = { | ||
@@ -33,3 +33,7 @@ generatedTypesFolder: (_a = params.options) === null || _a === void 0 ? void 0 : _a.generatedTypesFolder, | ||
canMagicallyEditCode: (_o = (_m = (_l = params.options) === null || _l === void 0 ? void 0 : _l.config) === null || _m === void 0 ? void 0 : _m.canMagicallyEditCode) !== null && _o !== void 0 ? _o : true, | ||
verbose: (_r = (_q = (_p = params.options) === null || _p === void 0 ? void 0 : _p.config) === null || _q === void 0 ? void 0 : _q.verbose) !== null && _r !== void 0 ? _r : false, | ||
}; | ||
if (global.Efesto.verbose) | ||
console.time("EFESTO TIME TO START".red); | ||
(0, console_1.printEfestoLogoToConsole)(); | ||
if (global.Efesto.mustGeneratedTypes && !fs_1.default.existsSync(global.Efesto.generatedTypesFolder)) { | ||
@@ -41,3 +45,3 @@ fs_1.default.mkdirSync(global.Efesto.generatedTypesFolder, { recursive: true }); | ||
} | ||
const config = (_p = params === null || params === void 0 ? void 0 : params.options) === null || _p === void 0 ? void 0 : _p.config; | ||
const config = (_s = params === null || params === void 0 ? void 0 : params.options) === null || _s === void 0 ? void 0 : _s.config; | ||
const upload = (0, multer_1.default)(); | ||
@@ -59,3 +63,3 @@ const router = (0, express_promise_router_1.default)(); | ||
} | ||
const baseSwagger = ((_q = params === null || params === void 0 ? void 0 : params.options) === null || _q === void 0 ? void 0 : _q.relativeDirSwaggerDeclarationsPath) || "swagger-declarations"; | ||
const baseSwagger = ((_t = params === null || params === void 0 ? void 0 : params.options) === null || _t === void 0 ? void 0 : _t.relativeDirSwaggerDeclarationsPath) || "swagger-declarations"; | ||
const baseApiURI = `${baseSwagger}/baseIndex.yaml`; | ||
@@ -76,3 +80,3 @@ const destinationURI = `${baseSwagger}/index.yaml`; | ||
catch (err) { } | ||
const paramsAbsoluteDirRouter = ((_r = params === null || params === void 0 ? void 0 : params.options) === null || _r === void 0 ? void 0 : _r.absoluteDirRoutes) || []; | ||
const paramsAbsoluteDirRouter = ((_u = params === null || params === void 0 ? void 0 : params.options) === null || _u === void 0 ? void 0 : _u.absoluteDirRoutes) || []; | ||
const baseDir = (0, isArray_1.default)(paramsAbsoluteDirRouter) | ||
@@ -82,7 +86,7 @@ ? paramsAbsoluteDirRouter | ||
const redisAndPermissionMiddleware = (options) => (req, res, next) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
var _u, _v, _w, _x, _y, _z; | ||
const abilityField = ((_u = config === null || config === void 0 ? void 0 : config.abacPermissions) === null || _u === void 0 ? void 0 : _u.reqAbilityField) || "ability"; | ||
const hasToCheckPermissions = (_w = (_v = config === null || config === void 0 ? void 0 : config.abacPermissions) === null || _v === void 0 ? void 0 : _v.checkPermissionBeforeResolver) !== null && _w !== void 0 ? _w : true; | ||
var _x, _y, _z, _0, _1, _2; | ||
const abilityField = ((_x = config === null || config === void 0 ? void 0 : config.abacPermissions) === null || _x === void 0 ? void 0 : _x.reqAbilityField) || "ability"; | ||
const hasToCheckPermissions = (_z = (_y = config === null || config === void 0 ? void 0 : config.abacPermissions) === null || _y === void 0 ? void 0 : _y.checkPermissionBeforeResolver) !== null && _z !== void 0 ? _z : true; | ||
if (hasToCheckPermissions && (options === null || options === void 0 ? void 0 : options.permission) && req[abilityField]) { | ||
ability_1.ForbiddenError.from(req[abilityField]).throwUnlessCan((_x = options === null || options === void 0 ? void 0 : options.permission) === null || _x === void 0 ? void 0 : _x.action, (_y = options === null || options === void 0 ? void 0 : options.permission) === null || _y === void 0 ? void 0 : _y.model); | ||
ability_1.ForbiddenError.from(req[abilityField]).throwUnlessCan((_0 = options === null || options === void 0 ? void 0 : options.permission) === null || _0 === void 0 ? void 0 : _0.action, (_1 = options === null || options === void 0 ? void 0 : options.permission) === null || _1 === void 0 ? void 0 : _1.model); | ||
} | ||
@@ -120,3 +124,3 @@ try { | ||
if (options === null || options === void 0 ? void 0 : options.cache) { | ||
const key = eval((_z = options === null || options === void 0 ? void 0 : options.cache) === null || _z === void 0 ? void 0 : _z.key); | ||
const key = eval((_2 = options === null || options === void 0 ? void 0 : options.cache) === null || _2 === void 0 ? void 0 : _2.key); | ||
const value = yield redisClient.get(key); | ||
@@ -157,3 +161,3 @@ if (value) | ||
const rawDuplicatedOperationIds = allOperationsIds.filter((value, index) => allOperationsIds.findIndex((x) => x.id === value.id) !== index); | ||
const promisesPath = rawDuplicatedOperationIds.map((x) => completePathWithIndexPosition(x)); | ||
const promisesPath = rawDuplicatedOperationIds.map((x) => (0, utils_1.completePathWithIndexPosition)(x)); | ||
Promise.all(promisesPath) | ||
@@ -176,4 +180,4 @@ .then((duplicatedOperationIds) => { | ||
export type ParamNames = string;`, () => { }); | ||
const actions = (_s = config === null || config === void 0 ? void 0 : config.abacPermissions) === null || _s === void 0 ? void 0 : _s.actions; | ||
const models = (_t = config === null || config === void 0 ? void 0 : config.abacPermissions) === null || _t === void 0 ? void 0 : _t.models; | ||
const actions = (_v = config === null || config === void 0 ? void 0 : config.abacPermissions) === null || _v === void 0 ? void 0 : _v.actions; | ||
const models = (_w = config === null || config === void 0 ? void 0 : config.abacPermissions) === null || _w === void 0 ? void 0 : _w.models; | ||
fs_1.default.writeFile(`${__dirname}/serviceUtils/permission.d.ts`, `export type ABACActions = ${(actions !== null && actions !== void 0 ? actions : ["readOne", "readAll", "read", "update", "create", "delete", "manage"]) | ||
@@ -183,5 +187,9 @@ .map((x) => `"${x}"`) | ||
export type ABACModels = ${models ? models === null || models === void 0 ? void 0 : models.map((x) => `"${x}"`).join(" | ") : "string"}`, () => { }); | ||
if (global.Efesto.verbose) | ||
console.timeEnd("EFESTO TIME TO START".red); | ||
return router; | ||
// FUNCTIONS after this | ||
function recursiveReadDir(baseDir, dir, deep = 0, cnfg) { | ||
if (global.Efesto.verbose) | ||
console.log("FORGING DIR:".bgYellow.black, dir); | ||
const files = fs_1.default.readdirSync(dir); | ||
@@ -824,4 +832,4 @@ files.sort((a, b) => { | ||
function getAllFuncs(toCheck) { | ||
var props = []; | ||
var obj = toCheck; | ||
let props = []; | ||
let obj = toCheck; | ||
do { | ||
@@ -874,26 +882,2 @@ props = props.concat(Object.getOwnPropertyNames(obj)); | ||
exports.default = efesto; | ||
function completePathWithIndexPosition(options) { | ||
return new Promise((resolve, reject) => { | ||
fs_1.default.readFile(options.path, "utf8", (err, content) => { | ||
var _a; | ||
if (err) | ||
return reject(err); | ||
const test = new RegExp(options.id, "g"); | ||
const index = ((_a = test.exec(content)) === null || _a === void 0 ? void 0 : _a.index) || 0; | ||
const fileSplittedByNewLine = content.split("\n"); | ||
let charsChecked = 0; | ||
let foundRow = -1; | ||
for (let i = 0; i < fileSplittedByNewLine.length && foundRow === -1; i++) { | ||
if (charsChecked >= index) { | ||
foundRow = i; | ||
} | ||
charsChecked += fileSplittedByNewLine[i].length + 1; | ||
} | ||
resolve({ | ||
id: options.id, | ||
path: `${options.path}:${foundRow}:${charsChecked - index}`, | ||
}); | ||
}); | ||
}); | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -45,3 +45,3 @@ "use strict"; | ||
Efesto Version: ${pjson.version} - ${` ${pjson.weapon} `.bgYellow.black}`); | ||
Efesto Version: ${pjson.version} - ${` ${pjson.weapon} `.bgCyan.black}`); | ||
} | ||
@@ -66,3 +66,3 @@ function logoOver50Under80() { | ||
Efesto Version: ${pjson.version} - ${` ${pjson.weapon} `.bgYellow.black}`); | ||
Efesto Version: ${pjson.version} - ${` ${pjson.weapon} `.bgCyan.black}`); | ||
} | ||
@@ -86,4 +86,4 @@ function logoOver80() { | ||
Efesto Version: ${pjson.version} - ${` ${pjson.weapon} `.bgYellow.black}`); | ||
Efesto Version: ${pjson.version} - ${` ${pjson.weapon} `.bgCyan.black}`); | ||
} | ||
//# sourceMappingURL=console.js.map |
{ | ||
"name": "efesto", | ||
"version": "0.15.1", | ||
"version": "0.16.0", | ||
"description": "", | ||
"main": "dist/index.js", | ||
"weapon": "Tridente Neptuni", | ||
"weapon": "Fulgur Iovis", | ||
"scripts": { | ||
@@ -8,0 +8,0 @@ "build": "tsc", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
170441
32
1649
4