openapi-metadata
Version:
Auto-Generate OpenAPI specifications from Typescript decorators
27 lines (24 loc) • 893 B
JavaScript
import { NoExplicitTypeError } from '../errors/no-explicit-type.mjs';
import { ReflectMetadataMissingError } from '../errors/reflect-metadata-missing.mjs';
function assertReflectMetadata() {
if (typeof Reflect !== "object" || typeof Reflect.getMetadata !== "function") {
throw new ReflectMetadataMissingError();
}
}
function findType({ metadataKey, prototype, propertyKey }) {
assertReflectMetadata();
const reflectedType = Reflect.getMetadata(metadataKey, prototype, propertyKey);
if (!reflectedType) {
throw new NoExplicitTypeError(prototype.constructor.name, propertyKey);
}
return reflectedType;
}
const IS_THUNK_REG = /^.+=>[\w\d\s\t\n\r]*/;
function isThunk(value) {
if (typeof value !== "function") {
return false;
}
return Boolean(IS_THUNK_REG.exec(value));
}
export { assertReflectMetadata, findType, isThunk };
//# sourceMappingURL=metadata.mjs.map