@elsikora/nestjs-crud-config 5.0.0 → 5.1.0

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.
@@ -146,17 +146,24 @@ function createConfigDataEntity(options) {
146
146
  ],
147
147
  },
148
148
  name: "ConfigData",
149
+ primaryKeyConstraintName: `PK_${options.tableName}`,
149
150
  relations: {
150
151
  section: {
151
152
  decorator: { target: options.configSectionEntity },
152
153
  eager: false,
154
+ foreignKeyConstraintName: `FK_${options.tableName}_section`,
153
155
  nullable: false,
154
156
  onDelete: "CASCADE",
155
157
  type: "ManyToOne",
156
158
  },
157
159
  },
158
160
  tableName: options.tableName,
159
- uniques: [["name", "environment", "section"]],
161
+ uniques: [
162
+ {
163
+ columns: ["name", "environment", "section"],
164
+ name: `UQ_${options.tableName}_name_environment_section`,
165
+ },
166
+ ],
160
167
  });
161
168
  }
162
169
 
@@ -130,13 +130,14 @@ function createConfigMigrationEntity(options) {
130
130
  ],
131
131
  },
132
132
  indexes: [
133
- { columns: ["status"], name: "idx_config_migration_status" },
134
- { columns: ["startedAt"], name: "idx_config_migration_started_at" },
135
- { columns: ["createdAt"], name: "idx_config_migration_created_at" },
133
+ { columns: ["status"], name: `IDX_${options.tableName}_status` },
134
+ { columns: ["startedAt"], name: `IDX_${options.tableName}_started_at` },
135
+ { columns: ["createdAt"], name: `IDX_${options.tableName}_created_at` },
136
136
  ],
137
137
  name: "ConfigMigration",
138
+ primaryKeyConstraintName: `PK_${options.tableName}`,
138
139
  tableName: options.tableName,
139
- uniques: [["name"]],
140
+ uniques: [{ columns: ["name"], name: `UQ_${options.tableName}_name` }],
140
141
  });
141
142
  }
142
143
 
@@ -94,6 +94,7 @@ function createConfigSectionEntity(options) {
94
94
  ],
95
95
  },
96
96
  name: "ConfigSection",
97
+ primaryKeyConstraintName: `PK_${options.tableName}`,
97
98
  tableName: options.tableName,
98
99
  });
99
100
  }
@@ -13,7 +13,12 @@ export interface ICreateDynamicEntityOptions {
13
13
  name: string;
14
14
  }>;
15
15
  name: string;
16
+ /** Name of the primary key constraint of the generated `id` column; a declared `id` column names its own. */
17
+ primaryKeyConstraintName?: string;
16
18
  relations?: Record<string, ICreateDynamicEntityRelationOptions>;
17
19
  tableName: string;
18
- uniques?: Array<Array<string>>;
20
+ uniques?: Array<{
21
+ columns: Array<string>;
22
+ name: string;
23
+ }>;
19
24
  }
@@ -4,6 +4,8 @@ export interface ICreateDynamicEntityRelationOptions extends RelationOptions {
4
4
  decorator?: {
5
5
  target: Type<unknown>;
6
6
  };
7
+ /** Name of the foreign key constraint of the join column. */
8
+ foreignKeyConstraintName?: string;
7
9
  hasJoinColumn?: boolean;
8
10
  type?: string;
9
11
  }
@@ -10,7 +10,7 @@ import { Entity, Unique, Index, PrimaryGeneratedColumn, getMetadataArgsStorage,
10
10
  * @returns {TDynamicEntity<unknown>} Dynamically created entity class with all decorators applied
11
11
  */
12
12
  function createDynamicEntityClass(options) {
13
- const { classDecorators = [], columns, decorators = {}, indexes = [], name, relations = {}, tableName, uniques = [], } = options;
13
+ const { classDecorators = [], columns, decorators = {}, indexes = [], name, primaryKeyConstraintName, relations = {}, tableName, uniques = [], } = options;
14
14
  const DynamicEntity = class {
15
15
  };
16
16
  Object.defineProperty(DynamicEntity, "name", { value: name });
@@ -18,15 +18,15 @@ function createDynamicEntityClass(options) {
18
18
  Entity(entityOptions)(DynamicEntity);
19
19
  for (const decorator of classDecorators)
20
20
  decorator(DynamicEntity);
21
- for (const uniqueColumns of uniques) {
22
- Unique(uniqueColumns)(DynamicEntity);
21
+ for (const unique of uniques) {
22
+ Unique(unique.name, unique.columns)(DynamicEntity);
23
23
  }
24
24
  for (const index of indexes) {
25
25
  Index(index.name, index.columns)(DynamicEntity);
26
26
  }
27
27
  if (!columns.id) {
28
28
  // eslint-disable-next-line @elsikora/typescript/no-unsafe-argument
29
- PrimaryGeneratedColumn("uuid")(DynamicEntity.prototype, "id");
29
+ PrimaryGeneratedColumn("uuid", { primaryKeyConstraintName })(DynamicEntity.prototype, "id");
30
30
  if (decorators.id) {
31
31
  // eslint-disable-next-line @elsikora/typescript/no-unsafe-argument
32
32
  for (const decorator of decorators.id)
@@ -58,13 +58,13 @@ function createDynamicEntityClass(options) {
58
58
  }
59
59
  for (const [propertyKey, relationOptions] of Object.entries(relations)) {
60
60
  const extendedOptions = relationOptions;
61
- const { decorator, type, ...options } = extendedOptions;
61
+ const { decorator, foreignKeyConstraintName, type, ...options } = extendedOptions;
62
62
  if (type === "ManyToOne" && decorator) {
63
63
  // eslint-disable-next-line @elsikora/typescript/no-unsafe-argument
64
64
  ManyToOne(() => decorator.target, options)(DynamicEntity.prototype, propertyKey);
65
65
  if (options.hasJoinColumn !== false) {
66
66
  // eslint-disable-next-line @elsikora/typescript/no-unsafe-argument
67
- JoinColumn()(DynamicEntity.prototype, propertyKey);
67
+ JoinColumn({ foreignKeyConstraintName })(DynamicEntity.prototype, propertyKey);
68
68
  }
69
69
  }
70
70
  if (decorators[propertyKey]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elsikora/nestjs-crud-config",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "NestJS application configuration via database storage",
5
5
  "homepage": "https://github.com/ElsiKora/NestJS-Crud-Config#readme",
6
6
  "bugs": {