1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | exports.referencesOne = exports.embedsMany = exports.embedsOne = exports.getModelRelations = exports.relation = exports.RELATIONS_KEY = void 0;
|
8 | const core_1 = require("@loopback/core");
|
9 | const decorators_1 = require("../decorators");
|
10 | const relation_types_1 = require("./relation.types");
|
11 | exports.RELATIONS_KEY = 'loopback:relations';
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | function relation(definition) {
|
18 |
|
19 | return core_1.PropertyDecoratorFactory.createDecorator(exports.RELATIONS_KEY, definition, {
|
20 | decoratorName: '@relation',
|
21 | });
|
22 | }
|
23 | exports.relation = relation;
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | function getModelRelations(modelCtor) {
|
31 |
|
32 | const modelDef = (0, decorators_1.buildModelDefinition)(modelCtor);
|
33 | return (modelDef === null || modelDef === void 0 ? void 0 : modelDef.relations) || {};
|
34 | }
|
35 | exports.getModelRelations = getModelRelations;
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | function embedsOne(definition) {
|
46 | const rel = Object.assign({ type: relation_types_1.RelationType.embedsOne }, definition);
|
47 | return core_1.PropertyDecoratorFactory.createDecorator(exports.RELATIONS_KEY, rel, {
|
48 | decoratorName: '@embedsOne',
|
49 | });
|
50 | }
|
51 | exports.embedsOne = embedsOne;
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | function embedsMany(definition) {
|
58 | const rel = Object.assign({ type: relation_types_1.RelationType.embedsMany }, definition);
|
59 | return core_1.PropertyDecoratorFactory.createDecorator(exports.RELATIONS_KEY, rel, {
|
60 | decoratorName: '@embedsMany',
|
61 | });
|
62 | }
|
63 | exports.embedsMany = embedsMany;
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | function referencesOne(definition) {
|
70 | const rel = Object.assign({ type: relation_types_1.RelationType.referencesOne }, definition);
|
71 | return core_1.PropertyDecoratorFactory.createDecorator(exports.RELATIONS_KEY, rel, {
|
72 | decoratorName: '@referencesOne',
|
73 | });
|
74 | }
|
75 | exports.referencesOne = referencesOne;
|
76 |
|
\ | No newline at end of file |