trapi
Version:
The main package and contains bundled functionality of all other package and a CLI to interact with them.
43 lines • 1.92 kB
JavaScript
;
/*
* Copyright (c) 2021.
* Author Peter Placzek (tada5hi)
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseConfig = exports.useConfigValidator = void 0;
const yup_1 = require("yup");
const metadata_1 = require("@trapi/metadata");
const swagger_1 = require("@trapi/swagger");
let validatorInstance;
function useConfigValidator() {
if (typeof validatorInstance !== 'undefined') {
return validatorInstance;
}
validatorInstance = (0, yup_1.object)({
metadata: (0, metadata_1.useConfigValidator)(),
swagger: (0, swagger_1.useConfigValidator)(),
decorator: (0, metadata_1.useDecoratorConfigValidator)()
});
return validatorInstance;
}
exports.useConfigValidator = useConfigValidator;
function parseConfig(value) {
return __awaiter(this, void 0, void 0, function* () {
const validator = useConfigValidator();
yield validator.validate(value);
return validator.cast(value);
});
}
exports.parseConfig = parseConfig;
//# sourceMappingURL=validator.js.map