UNPKG

pims

Version:

An ORM for document-oriented database systems, written in and for TypeScript.

40 lines 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const model_1 = require("./model"); var Relationship; (function (Relationship) { Relationship[Relationship["HasMany"] = 0] = "HasMany"; Relationship[Relationship["BelongsTo"] = 1] = "BelongsTo"; Relationship[Relationship["HasOne"] = 2] = "HasOne"; Relationship[Relationship["HasAndBelongsToMany"] = 3] = "HasAndBelongsToMany"; })(Relationship = exports.Relationship || (exports.Relationship = {})); function HasMany(model, foreignKey) { return RelationshipDecorator(Relationship.HasMany, model, foreignKey); } exports.HasMany = HasMany; function HasOne(model, foreignKey) { return RelationshipDecorator(Relationship.HasOne, model, foreignKey); } exports.HasOne = HasOne; function BelongsTo(model, localKey) { return RelationshipDecorator(Relationship.BelongsTo, model, localKey); } exports.BelongsTo = BelongsTo; function HasAndBelongsToMany(model) { return RelationshipDecorator(Relationship.HasAndBelongsToMany, model); } exports.HasAndBelongsToMany = HasAndBelongsToMany; function RelationshipDecorator(kind, model, foreignKey) { return (target, key) => { const relationship = { kind, model, key: key, foreignKey, }; model_1.createModelInfo(target.constructor, { relationships: [relationship], }); }; } //# sourceMappingURL=relationships.js.map