@open-norantec/herbal 1.0.2-alpha.2 → 1.0.2-alpha.3
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 +4 -8
- package/dist/sequelize-di.js +14 -31
- package/package.json +1 -1
package/dist/sequelize-di.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { BelongsToOptions, ModelAttributeColumnOptions } from 'sequelize';
|
|
1
|
+
import { BelongsToOptions, IndexesOptions, ModelAttributeColumnOptions } from 'sequelize';
|
|
2
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 interface TableOptions<M extends Model = Model> extends SequelizeTableOptions<M> {
|
|
6
|
-
|
|
7
|
-
field: string;
|
|
8
|
-
name?: string;
|
|
9
|
-
unique?: string;
|
|
10
|
-
}>;
|
|
5
|
+
export interface TableOptions<M extends Model = Model> extends Omit<SequelizeTableOptions<M>, 'indexes'> {
|
|
6
|
+
indexes?: Array<IndexesOptions | string>;
|
|
11
7
|
}
|
|
12
|
-
export declare function Table<M extends Model = Model>({
|
|
8
|
+
export declare function Table<M extends Model = Model>({ indexes, ...options }: TableOptions<M>): (target: Constructor<M>) => void;
|
|
13
9
|
export declare function BelongsTo(associatedClassGetter: ModelClassGetter<{}, {}>, options?: BelongsToOptions): Function;
|
|
14
10
|
export declare function DateColumn(options: Partial<ModelAttributeColumnOptions>): Function;
|
package/dist/sequelize-di.js
CHANGED
|
@@ -37,44 +37,27 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.DateColumn = exports.BelongsTo = exports.Table = void 0;
|
|
40
|
-
var string_util_class_1 = require("@open-norantec/utilities/dist/string-util.class");
|
|
41
40
|
var sequelize_typescript_1 = require("sequelize-typescript");
|
|
42
41
|
__exportStar(require("sequelize-typescript"), exports);
|
|
43
42
|
function Table(_a) {
|
|
44
|
-
var
|
|
43
|
+
var indexes = _a.indexes, options = __rest(_a, ["indexes"]);
|
|
45
44
|
return function (target) {
|
|
46
45
|
var newOptions = !options ? {} : options;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
newOptions.indexes = [];
|
|
47
|
+
newOptions.indexes = Array.from(Array.isArray(indexes) ? indexes : []).map(function (item, index) {
|
|
48
|
+
if (typeof item === 'string') {
|
|
49
|
+
return [
|
|
50
|
+
{
|
|
51
|
+
name: "sidx__".concat(index),
|
|
52
|
+
fields: [item],
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
return item;
|
|
57
|
+
}).concat({
|
|
51
58
|
name: 'pagination',
|
|
52
59
|
fields: ['id', 'created_at'],
|
|
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
|
-
: []);
|
|
60
|
+
});
|
|
78
61
|
(0, sequelize_typescript_1.Table)(__assign(__assign({}, newOptions), { tableName: newOptions === null || newOptions === void 0 ? void 0 : newOptions.modelName, modelName: target.name }))(target);
|
|
79
62
|
};
|
|
80
63
|
}
|