UNPKG

miter

Version:

A typescript web framework based on ExpressJs based loosely on SailsJs

32 lines 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const has_one_1 = require("../../../metadata/orm/associations/has-one"); function isStaticModelT(test) { return test && !!test.db; } function isForeignModelSource(test) { return test && (isStaticModelT(test) || !!test.modelName || !!test.tableName || typeof test === 'function'); } function HasOne(propMeta) { let meta = {}; if (isForeignModelSource(propMeta)) meta = { foreignModel: propMeta }; else if (propMeta) meta = propMeta; return function (model, propertyName) { if (!isForeignModelSource(meta.foreignModel)) { meta.foreignModel = Reflect.getMetadata('design:type', model, propertyName); if (meta.foreignModel === Object) meta.foreignModel = undefined; else if (!isStaticModelT(meta.foreignModel)) throw new Error(`Cannot infer relation type for has-one association ${model.name || model}.${propertyName}.`); } meta.as = propertyName; let props = Reflect.getOwnMetadata(has_one_1.ModelHasOneAssociationsSym, model) || []; props.push(propertyName); Reflect.defineMetadata(has_one_1.ModelHasOneAssociationsSym, props, model); Reflect.defineMetadata(has_one_1.HasOneMetadataSym, meta, model, propertyName); }; } exports.HasOne = HasOne; //# sourceMappingURL=has-one.decorator.js.map