@open-norantec/herbal 1.0.2-alpha.1 → 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.
@@ -1,7 +1,14 @@
1
1
  import { BelongsToOptions, ModelAttributeColumnOptions } from 'sequelize';
2
- import { Model, TableOptions, ModelClassGetter } from 'sequelize-typescript';
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 declare function Table<M extends Model = Model>(options: TableOptions<M>): (target: Constructor<M>) => void;
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;
7
14
  export declare function DateColumn(options: Partial<ModelAttributeColumnOptions>): Function;
@@ -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
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(options) {
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).concat({
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-norantec/herbal",
3
- "version": "1.0.2-alpha.1",
3
+ "version": "1.0.2-alpha.2",
4
4
  "description": "Herbal is a builder and toolchain for Nest.js applications",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {