neo4-js
Version:
Neo4j graphdb object graph mapper for javascript
68 lines (67 loc) • 2.03 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("./utils");
exports.relation = {
from: (from) => {
return {
to: (to) => {
return {
via: (via) => {
return {
from,
to,
via,
};
},
};
},
};
},
};
function connectRelationToProp(many) {
return (model, relation, direction) => (target, key) => {
//if (descriptor) descriptor.writable = true;
if (!target._relations)
target._relations = [];
target._relations.push({
dest: model,
relation,
out: direction ? direction === "out" : null,
any: direction ? direction === "any" : null,
propertyName: key,
many,
});
};
}
exports.hasMany = connectRelationToProp(true);
exports.hasOne = connectRelationToProp(false);
exports.model = (model) => (target) => {
utils_1.connectHelper.models.push({
model,
relations: target.prototype._relations,
modelInstance: target,
});
utils_1.connectHelper.tryInject();
};
exports.defaultProps = (props) => {
return (target) => {
if (props) {
target.prototype._defaultProps = props;
}
};
};
function extendModelInstance(instance) {
const i = instance;
i.hasMany = (propertyName, ...args) =>
// @ts-ignore
exports.hasMany(...args)(instance.prototype, propertyName, null);
i.hasOne = (propertyName, ...args) =>
// @ts-ignore
exports.hasOne(...args)(instance.prototype, propertyName, null);
// @ts-ignore
i.model = (...args) => exports.model(...args)(instance, "");
// @ts-ignore
i.defaultProps = (...args) => exports.defaultProps(...args)(instance, "");
return i;
}
exports.extendModelInstance = extendModelInstance;
;