1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.addAttributeOptions = exports.addAttribute = exports.setAttributes = exports.getAttributes = void 0;
|
4 | const object_1 = require("../../shared/object");
|
5 | const ATTRIBUTES_KEY = 'sequelize:attributes';
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | function getAttributes(target) {
|
11 | const attributes = Reflect.getMetadata(ATTRIBUTES_KEY, target);
|
12 | if (attributes) {
|
13 | return Object.keys(attributes).reduce((copy, key) => {
|
14 | copy[key] = Object.assign({}, attributes[key]);
|
15 | return copy;
|
16 | }, {});
|
17 | }
|
18 | }
|
19 | exports.getAttributes = getAttributes;
|
20 |
|
21 |
|
22 |
|
23 | function setAttributes(target, attributes) {
|
24 | Reflect.defineMetadata(ATTRIBUTES_KEY, Object.assign({}, attributes), target);
|
25 | }
|
26 | exports.setAttributes = setAttributes;
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | function addAttribute(target, name, options) {
|
33 | let attributes = getAttributes(target);
|
34 | if (!attributes) {
|
35 | attributes = {};
|
36 | }
|
37 | attributes[name] = Object.assign({}, options);
|
38 | setAttributes(target, attributes);
|
39 | }
|
40 | exports.addAttribute = addAttribute;
|
41 |
|
42 |
|
43 |
|
44 | function addAttributeOptions(target, propertyName, options) {
|
45 | const attributes = getAttributes(target);
|
46 | if (!attributes || !attributes[propertyName]) {
|
47 | throw new Error(`@Column annotation is missing for "${propertyName}" of class "${target.constructor.name}"` +
|
48 | ` or annotation order is wrong.`);
|
49 | }
|
50 | attributes[propertyName] = (0, object_1.deepAssign)(attributes[propertyName], options);
|
51 | setAttributes(target, attributes);
|
52 | }
|
53 | exports.addAttributeOptions = addAttributeOptions;
|
54 |
|
\ | No newline at end of file |