@open-norantec/herbal 1.0.2-alpha.0 → 1.0.2-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/sequelize-di.d.ts +11 -3
- package/dist/sequelize-di.js +51 -4
- package/package.json +1 -1
package/dist/sequelize-di.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import { BelongsToOptions } from 'sequelize';
|
|
2
|
-
import { Model, TableOptions, ModelClassGetter } from 'sequelize-typescript';
|
|
1
|
+
import { BelongsToOptions, ModelAttributeColumnOptions } from 'sequelize';
|
|
2
|
+
import { Model, TableOptions as SequelizeTableOptions, ModelClassGetter } from 'sequelize-typescript';
|
|
3
3
|
import { Constructor } from 'type-fest';
|
|
4
4
|
export * from 'sequelize-typescript';
|
|
5
|
-
export
|
|
5
|
+
export interface TableOptions<M extends Model = Model> extends SequelizeTableOptions<M> {
|
|
6
|
+
standaloneIndexes?: Array<string | {
|
|
7
|
+
field: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
unique?: string;
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
12
|
+
export declare function Table<M extends Model = Model>({ standaloneIndexes, ...options }: TableOptions<M>): (target: Constructor<M>) => void;
|
|
6
13
|
export declare function BelongsTo(associatedClassGetter: ModelClassGetter<{}, {}>, options?: BelongsToOptions): Function;
|
|
14
|
+
export declare function DateColumn(options: Partial<ModelAttributeColumnOptions>): Function;
|
package/dist/sequelize-di.js
CHANGED
|
@@ -24,19 +24,57 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
24
24
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
25
25
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
26
26
|
};
|
|
27
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
28
|
+
var t = {};
|
|
29
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
30
|
+
t[p] = s[p];
|
|
31
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
32
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
33
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
34
|
+
t[p[i]] = s[p[i]];
|
|
35
|
+
}
|
|
36
|
+
return t;
|
|
37
|
+
};
|
|
27
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.BelongsTo = exports.Table = void 0;
|
|
39
|
+
exports.DateColumn = exports.BelongsTo = exports.Table = void 0;
|
|
40
|
+
var string_util_class_1 = require("@open-norantec/utilities/dist/string-util.class");
|
|
29
41
|
var sequelize_typescript_1 = require("sequelize-typescript");
|
|
30
42
|
__exportStar(require("sequelize-typescript"), exports);
|
|
31
|
-
function Table(
|
|
43
|
+
function Table(_a) {
|
|
44
|
+
var standaloneIndexes = _a.standaloneIndexes, options = __rest(_a, ["standaloneIndexes"]);
|
|
32
45
|
return function (target) {
|
|
33
46
|
var newOptions = !options ? {} : options;
|
|
34
47
|
if (!Array.isArray(newOptions === null || newOptions === void 0 ? void 0 : newOptions.indexes))
|
|
35
48
|
newOptions.indexes = [];
|
|
36
|
-
newOptions.indexes = Array.from(newOptions.indexes)
|
|
49
|
+
newOptions.indexes = Array.from(newOptions.indexes)
|
|
50
|
+
.concat({
|
|
37
51
|
name: 'pagination',
|
|
38
52
|
fields: ['id', 'created_at'],
|
|
39
|
-
})
|
|
53
|
+
})
|
|
54
|
+
.concat(Array.isArray(standaloneIndexes)
|
|
55
|
+
? standaloneIndexes
|
|
56
|
+
.map(function (item, index) {
|
|
57
|
+
if (typeof item === 'string') {
|
|
58
|
+
if (item.length === 0)
|
|
59
|
+
return null;
|
|
60
|
+
return {
|
|
61
|
+
name: "idx_standalone__".concat(index),
|
|
62
|
+
fields: [item],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
else if (typeof (item === null || item === void 0 ? void 0 : item.field) === 'string' && item.field.length > 0) {
|
|
66
|
+
return {
|
|
67
|
+
fields: [item.field],
|
|
68
|
+
name: string_util_class_1.StringUtil.isFalsyString(item === null || item === void 0 ? void 0 : item.name) ? "idx_standalone__".concat(index) : item.name,
|
|
69
|
+
unique: typeof (item === null || item === void 0 ? void 0 : item.unique) === 'boolean' ? item.unique : false,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
.filter(function (item) { return item !== null; })
|
|
77
|
+
: []);
|
|
40
78
|
(0, sequelize_typescript_1.Table)(__assign(__assign({}, newOptions), { tableName: newOptions === null || newOptions === void 0 ? void 0 : newOptions.modelName, modelName: target.name }))(target);
|
|
41
79
|
};
|
|
42
80
|
}
|
|
@@ -45,3 +83,12 @@ function BelongsTo(associatedClassGetter, options) {
|
|
|
45
83
|
return (0, sequelize_typescript_1.BelongsTo)(associatedClassGetter, __assign({ onUpdate: 'CASCADE', onDelete: 'CASCADE' }, options));
|
|
46
84
|
}
|
|
47
85
|
exports.BelongsTo = BelongsTo;
|
|
86
|
+
function DateColumn(options) {
|
|
87
|
+
return function (target, propertyName, propertyDescriptor) {
|
|
88
|
+
(0, sequelize_typescript_1.Column)(__assign(__assign({}, options), { type: sequelize_typescript_1.DataType.DATE, get: function () {
|
|
89
|
+
var _a, _b, _c, _d;
|
|
90
|
+
return (_d = (_c = (_b = (_a = this.getDataValue) === null || _a === void 0 ? void 0 : _a.call(this, propertyName)) === null || _b === void 0 ? void 0 : _b.toISOString) === null || _c === void 0 ? void 0 : _c.call(_b)) !== null && _d !== void 0 ? _d : null;
|
|
91
|
+
} }))(target, propertyName, propertyDescriptor);
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
exports.DateColumn = DateColumn;
|