UNPKG

@starrah/mongo-ts-struct

Version:

Mongoose wrapper for Typescript supports

20 lines 1.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const helpers_1 = require("../../../helpers"); const field_definition_map_1 = require("../../../field-definition-map"); function createPropertyDecorator(callerDecorator, cb) { return (targetPrototype, propertyName) => { const name = targetPrototype.constructor.name; if (!helpers_1.MetadataAgent.has(targetPrototype, `isProcessed:${name}`)) { const { type, definition } = cb(targetPrototype, propertyName); const customDefaultDefinition = field_definition_map_1.getDefaultDefinition(propertyName, type, callerDecorator); const mergedDefinition = Object.assign({}, customDefaultDefinition, definition); helpers_1.MetadataAgent.assign(targetPrototype, [ `schemaDefinitions.${propertyName}`, type ? Object.assign({}, mergedDefinition, { type }) : Object.assign({}, mergedDefinition) ]); } }; } exports.createPropertyDecorator = createPropertyDecorator; //# sourceMappingURL=create-property-decorator.js.map