fiberx-backend-toolkit 1.0.4 → 1.0.5
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.
|
@@ -14,11 +14,15 @@ const serializeSequelizeDataType = (type) => {
|
|
|
14
14
|
return "undefined";
|
|
15
15
|
if (type.key) {
|
|
16
16
|
const key = type.key;
|
|
17
|
+
if (key === "ENUM") {
|
|
18
|
+
const values = type.options?.values ?? type.values;
|
|
19
|
+
if (Array.isArray(values) && values.length) {
|
|
20
|
+
return `DataTypes.${key}(${values.map((value) => JSON.stringify(value)).join(", ")})`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
17
23
|
if (type.options?.length)
|
|
18
24
|
return `DataTypes.${key}(${type.options.length})`;
|
|
19
|
-
if (type.options?.
|
|
20
|
-
return `DataTypes.${key}(${JSON.stringify(type.options.values)})`;
|
|
21
|
-
if (type.options?.precision && type.options?.scale)
|
|
25
|
+
if (type.options?.precision != null && type.options?.scale != null)
|
|
22
26
|
return `DataTypes.${key}(${type.options.precision}, ${type.options.scale})`;
|
|
23
27
|
return `DataTypes.${key}`;
|
|
24
28
|
}
|
|
@@ -131,7 +135,7 @@ const SEQUELIZE_CREATE_NEW_SCHEMA_MIGRATION_FILE_CODE_TEMPLATE = (schema_table_n
|
|
|
131
135
|
const rendered_columns = serializeSequelizeColumnsObject(schema_definition.columns);
|
|
132
136
|
const rendered_indexes = serializeSequelizeIndexesArray(schema_definition.indexes || []);
|
|
133
137
|
return `
|
|
134
|
-
import { QueryInterface, Sequelize, DataTypes } from "sequelize";
|
|
138
|
+
import { QueryInterface, Sequelize, DataTypes, QueryInterfaceOptions } from "sequelize";
|
|
135
139
|
import { LoggerUtil } from "fiberx-backend-toolkit/utils";
|
|
136
140
|
|
|
137
141
|
class Create${schema_model_name}TableMigration {
|
|
@@ -140,7 +144,7 @@ class Create${schema_model_name}TableMigration {
|
|
|
140
144
|
|
|
141
145
|
constructor() {}
|
|
142
146
|
|
|
143
|
-
public async up(queryInterface: QueryInterface, Sequelize: Sequelize, migration_options:
|
|
147
|
+
public async up(queryInterface: QueryInterface, Sequelize: Sequelize, migration_options: QueryInterfaceOptions = {}) {
|
|
144
148
|
try {
|
|
145
149
|
const table_name = "${schema_table_name}";
|
|
146
150
|
|
|
@@ -172,7 +176,7 @@ class Create${schema_model_name}TableMigration {
|
|
|
172
176
|
}
|
|
173
177
|
}
|
|
174
178
|
|
|
175
|
-
public async down(queryInterface: QueryInterface, Sequelize: Sequelize, migration_options:
|
|
179
|
+
public async down(queryInterface: QueryInterface, Sequelize: Sequelize, migration_options: QueryInterfaceOptions = {}) {
|
|
176
180
|
try {
|
|
177
181
|
await queryInterface.dropTable("${schema_table_name}", migration_options);
|
|
178
182
|
this.logger.success(\`🗑️ Table "${schema_table_name}" dropped successfully.\`);
|
|
@@ -189,7 +193,7 @@ export default Create${schema_model_name}TableMigration;
|
|
|
189
193
|
exports.SEQUELIZE_CREATE_NEW_SCHEMA_MIGRATION_FILE_CODE_TEMPLATE = SEQUELIZE_CREATE_NEW_SCHEMA_MIGRATION_FILE_CODE_TEMPLATE;
|
|
190
194
|
const SEQUELIZE_UPDATE_EXISTING_SCHEMA_MIGRATION_FILE_CODE_TEMPLATE = (table_name, model_name, diff, current_schema, previous_schema) => {
|
|
191
195
|
return `
|
|
192
|
-
import { QueryInterface, Sequelize, DataTypes } from "sequelize";
|
|
196
|
+
import { QueryInterface, Sequelize, DataTypes, QueryInterfaceOptions } from "sequelize";
|
|
193
197
|
import { LoggerUtil } from "fiberx-backend-toolkit/utils";
|
|
194
198
|
|
|
195
199
|
class Update${model_name}TableMigration {
|
|
@@ -198,7 +202,7 @@ class Update${model_name}TableMigration {
|
|
|
198
202
|
|
|
199
203
|
constructor() {}
|
|
200
204
|
|
|
201
|
-
public async up(queryInterface: QueryInterface, Sequelize: Sequelize, migration_options:
|
|
205
|
+
public async up(queryInterface: QueryInterface, Sequelize: Sequelize, migration_options: QueryInterfaceOptions = {}) {
|
|
202
206
|
try {
|
|
203
207
|
let table_name = "${table_name}";
|
|
204
208
|
|
|
@@ -307,7 +311,7 @@ class Update${model_name}TableMigration {
|
|
|
307
311
|
}
|
|
308
312
|
}
|
|
309
313
|
|
|
310
|
-
public async down(queryInterface: QueryInterface, Sequelize: Sequelize, migration_options:
|
|
314
|
+
public async down(queryInterface: QueryInterface, Sequelize: Sequelize, migration_options: QueryInterfaceOptions = {}) {
|
|
311
315
|
try {
|
|
312
316
|
let table_name = "${table_name}";
|
|
313
317
|
|
|
@@ -530,7 +534,7 @@ const model_classes = [
|
|
|
530
534
|
];
|
|
531
535
|
|
|
532
536
|
// Store initialized models
|
|
533
|
-
const initializedModels: Record<string,
|
|
537
|
+
const initializedModels: Record<string, unknown> = {};
|
|
534
538
|
const associationMethods: (() => void)[] = [];
|
|
535
539
|
|
|
536
540
|
// -------------------------
|
|
@@ -563,7 +567,7 @@ for (const register of associationMethods) {
|
|
|
563
567
|
// -------------------------
|
|
564
568
|
// Create named initialized exports
|
|
565
569
|
// -------------------------
|
|
566
|
-
${model_names.map((m) => `const ${m}Model: typeof ${m} = initializedModels["${m}"];`).join("\n")}
|
|
570
|
+
${model_names.map((m) => `const ${m}Model: typeof ${m} = initializedModels["${m}"] as typeof ${m};`).join("\n")}
|
|
567
571
|
|
|
568
572
|
// -------------------------
|
|
569
573
|
// Export raw + initialized
|
|
@@ -66,7 +66,7 @@ class MigrationRunnerScript {
|
|
|
66
66
|
async getAppliedMigrations() {
|
|
67
67
|
const sequelize = await this.getSequelizeInstance();
|
|
68
68
|
const queryInterface = sequelize.getQueryInterface();
|
|
69
|
-
const table_name = queryInterface?.quoteTable(constants_1.SEQUELIZE_META_TABLE_NAME) ?? constants_1.SEQUELIZE_META_TABLE_NAME;
|
|
69
|
+
const table_name = queryInterface?.quoteTable?.(constants_1.SEQUELIZE_META_TABLE_NAME) ?? constants_1.SEQUELIZE_META_TABLE_NAME;
|
|
70
70
|
const column_name = queryInterface.quoteIdentifier("name");
|
|
71
71
|
const results = await sequelize.query(`SELECT ${column_name} FROM ${table_name};`, { type: sequelize_1.QueryTypes.SELECT });
|
|
72
72
|
return results.map((row) => row.name);
|
|
@@ -62,7 +62,7 @@ class SeederRunnerScript {
|
|
|
62
62
|
async getAppliedSeeders() {
|
|
63
63
|
const sequelize = await this.getSequelizeInstance();
|
|
64
64
|
const queryInterface = sequelize.getQueryInterface();
|
|
65
|
-
const table_name = queryInterface?.quoteTable(constants_1.SEQUELIZE_SEEDER_META_TABLE_NAME) ?? constants_1.SEQUELIZE_SEEDER_META_TABLE_NAME;
|
|
65
|
+
const table_name = queryInterface?.quoteTable?.(constants_1.SEQUELIZE_SEEDER_META_TABLE_NAME) ?? constants_1.SEQUELIZE_SEEDER_META_TABLE_NAME;
|
|
66
66
|
const column_name = queryInterface.quoteIdentifier("name");
|
|
67
67
|
const results = await sequelize.query(`SELECT ${column_name} FROM ${table_name};`, { type: sequelize_1.QueryTypes.SELECT });
|
|
68
68
|
return results.map((row) => row.name);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fiberx-backend-toolkit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "A TypeScript backend toolkit providing shared domain logic, infrastructure helpers, and utilities for FiberX server-side applications and services.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/index.js",
|