@nestjs/mongoose
Version:
Nest - modern, fast, powerful node.js web framework (@mongoose)
28 lines • 1.11 kB
JavaScript
import { CannotDetermineTypeError } from '../errors/index.js';
import { RAW_OBJECT_DEFINITION } from '../mongoose.constants.js';
import { TypeMetadataStorage } from '../storages/type-metadata.storage.js';
const TYPE_METADATA_KEY = 'design:type';
export function Prop(options) {
return (target, propertyKey) => {
options = (options || {});
const isRawDefinition = options[RAW_OBJECT_DEFINITION];
if (!options.type && !Array.isArray(options) && !isRawDefinition) {
const type = Reflect.getMetadata(TYPE_METADATA_KEY, target, propertyKey);
if (type === Array) {
options.type = [];
}
else if (type && type !== Object) {
options.type = type;
}
else {
throw new CannotDetermineTypeError(target.constructor?.name, propertyKey);
}
}
TypeMetadataStorage.addPropertyMetadata({
target: target.constructor,
propertyKey: propertyKey,
options: options,
});
};
}
//# sourceMappingURL=prop.decorator.js.map