Code coverage report for dist\lib\Decorators.js

Statements: 100% (46 / 46)      Branches: 73.33% (22 / 30)      Functions: 100% (14 / 14)      Lines: 100% (45 / 45)      Ignored: none     

All files » dist/lib/ » Decorators.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67  1 1 1 1 1 1     1 1 2 2     1 1 2 23     1 1 5 5 9   5 5 2 5 5 2   3 3   5 5 5 2   3     1 1 1 1 1           1 1 1 1 1 1 1     1    
/// <reference path="../_references.d.ts" />
var MongoDB = require('mongodb');
var _ = require('lodash');
var skmatc = require('skmatc');
function Collection(name) {
    return function (target) {
        target.collection = name;
    };
}
exports.Collection = Collection;
function Index(spec, options) {
    return function (target) {
        target.indexes = (target.indexes || []).concat({ spec: spec, options: options || {} });
    };
}
exports.Index = Index;
function Validate(forType, validate) {
    return function (target) {
        target.validators = (target.validators || []).concat(skmatc.create(function (schema) { return schema === forType; }, validate));
    };
}
exports.Validate = Validate;
function Property() {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i - 0] = arguments[_i];
    }
    var name = null, asType = false, required = true;
    if (args.length > 1 && typeof args[args.length - 1] === 'boolean')
        required = args.pop();
    return function (target, property) {
        if (!property)
            name = args.shift();
        else {
            name = property;
            target = target.constructor;
        }
        asType = args.pop() || false;
        target.schema = _.clone(target.schema || {});
        if (!required && typeof asType !== 'boolean')
            target.schema[name] = { $required: required, $type: asType };
        else
            target.schema[name] = asType;
    };
}
exports.Property = Property;
function Transform(fromDB, toDB) {
    return function (target, property) {
        target.constructor.transforms = _.clone(target.constructor.transforms || {});
        target.constructor.transforms[property] = {
            fromDB: fromDB,
            toDB: toDB
        };
    };
}
exports.Transform = Transform;
function ObjectID(target, name) {
    target.constructor.schema = _.clone(target.constructor.schema || {});
    target.constructor.schema[name] = MongoDB.ObjectID;
    target.constructor.transforms[name] = {
        fromDB: function (value) { return value._bsontype == 'ObjectID' ? new MongoDB.ObjectID(value.id).toHexString() : value; },
        toDB: function (value) { return value && typeof value === 'string' ? new MongoDB.ObjectID(value) : value; }
    };
}
exports.ObjectID = ObjectID;
 
//# sourceMappingURL=../lib/Decorators.js.map