fiberx-backend-toolkit 0.0.64 → 0.0.65
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.
|
@@ -24,7 +24,7 @@ const serializeSequelizeDataType = (type) => {
|
|
|
24
24
|
}
|
|
25
25
|
return "undefined";
|
|
26
26
|
};
|
|
27
|
-
const serializeSequelizeColumnDefinition = (column) => {
|
|
27
|
+
const serializeSequelizeColumnDefinition = (column, indent = 4) => {
|
|
28
28
|
const parts = [];
|
|
29
29
|
for (const [key, value] of Object.entries(column)) {
|
|
30
30
|
if (key === "type") {
|
|
@@ -44,8 +44,9 @@ const serializeSequelizeColumnDefinition = (column) => {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
return `{
|
|
47
|
-
${indentBlock(parts.join(",\n"),
|
|
48
|
-
}
|
|
47
|
+
${indentBlock(parts.join(",\n"), indent)}
|
|
48
|
+
${indentBlock("}", indent === 1 ? 0 : 3)}
|
|
49
|
+
`;
|
|
49
50
|
};
|
|
50
51
|
const serializeIndexDefinition = (index) => {
|
|
51
52
|
const clone = { ...index };
|
|
@@ -60,13 +61,14 @@ const serializeIndexDefinition = (index) => {
|
|
|
60
61
|
const serializeSequelizeColumnsObject = (columns) => {
|
|
61
62
|
const rendered = Object.entries(columns)
|
|
62
63
|
.map(([col_name, col_def]) => {
|
|
63
|
-
const col_code = serializeSequelizeColumnDefinition(col_def);
|
|
64
|
+
const col_code = serializeSequelizeColumnDefinition(col_def, 1);
|
|
64
65
|
return `"${col_name}": ${col_code}`;
|
|
65
66
|
})
|
|
66
67
|
.join(",\n");
|
|
67
68
|
return `{
|
|
68
|
-
${indentBlock(rendered,
|
|
69
|
-
}
|
|
69
|
+
${indentBlock(rendered, 4)}
|
|
70
|
+
${indentBlock("}", 3)}
|
|
71
|
+
`;
|
|
70
72
|
};
|
|
71
73
|
const serializeSequelizeIndexesArray = (indexes) => {
|
|
72
74
|
return indexes.map(index => {
|
|
@@ -142,17 +144,16 @@ class Create${schema_model_name}TableMigration {
|
|
|
142
144
|
|
|
143
145
|
await queryInterface.createTable(
|
|
144
146
|
table_name,
|
|
145
|
-
|
|
147
|
+
${indentBlock(rendered_columns, 1)}
|
|
146
148
|
);
|
|
147
149
|
|
|
148
|
-
|
|
149
150
|
${schema_definition.indexes?.map(index => `
|
|
150
151
|
await queryInterface.addIndex(
|
|
151
152
|
table_name,
|
|
152
153
|
${JSON.stringify(index.fields)},
|
|
153
154
|
{
|
|
154
155
|
name: "${index.name}",
|
|
155
|
-
${indentBlock(serializeIndexDefinition(index),
|
|
156
|
+
${indentBlock(serializeIndexDefinition(index), 1)}
|
|
156
157
|
}
|
|
157
158
|
);
|
|
158
159
|
`).join("")}
|
|
@@ -182,7 +183,7 @@ export default Create${schema_model_name}TableMigration;
|
|
|
182
183
|
exports.SEQUELIZE_CREATE_NEW_SCHEMA_MIGRATION_FILE_CODE_TEMPLATE = SEQUELIZE_CREATE_NEW_SCHEMA_MIGRATION_FILE_CODE_TEMPLATE;
|
|
183
184
|
const SEQUELIZE_UPDATE_EXISTING_SCHEMA_MIGRATION_FILE_CODE_TEMPLATE = (table_name, model_name, diff, current_schema, previous_schema) => {
|
|
184
185
|
return `
|
|
185
|
-
import { QueryInterface, Sequelize } from "sequelize";
|
|
186
|
+
import { QueryInterface, Sequelize, DataTypes } from "sequelize";
|
|
186
187
|
import { LoggerUtil } from "fiberx-backend-toolkit/dist/utils/main";
|
|
187
188
|
|
|
188
189
|
class Update${model_name}TableMigration {
|
|
@@ -208,7 +209,7 @@ class Update${model_name}TableMigration {
|
|
|
208
209
|
await queryInterface.addColumn(
|
|
209
210
|
table_name,
|
|
210
211
|
"${col}",
|
|
211
|
-
|
|
212
|
+
${indentBlock(serializeSequelizeColumnDefinition(current_schema.columns[col]), 1)}
|
|
212
213
|
);
|
|
213
214
|
`).join("")}
|
|
214
215
|
|
|
@@ -217,7 +218,7 @@ class Update${model_name}TableMigration {
|
|
|
217
218
|
await queryInterface.changeColumn(
|
|
218
219
|
table_name,
|
|
219
220
|
"${col}",
|
|
220
|
-
|
|
221
|
+
${indentBlock(serializeSequelizeColumnDefinition(current_schema.columns[col]), 1)}
|
|
221
222
|
);
|
|
222
223
|
`).join("")}
|
|
223
224
|
|
|
@@ -239,7 +240,7 @@ class Update${model_name}TableMigration {
|
|
|
239
240
|
${JSON.stringify(idx.fields)},
|
|
240
241
|
{
|
|
241
242
|
name: "${idx.name}",
|
|
242
|
-
${indentBlock(serializeIndexDefinition(idx).replace(/^{|}$/g, ""),
|
|
243
|
+
${indentBlock(serializeIndexDefinition(idx).replace(/^{|}$/g, ""), 1)}
|
|
243
244
|
}
|
|
244
245
|
);
|
|
245
246
|
` : "";
|
|
@@ -257,7 +258,7 @@ class Update${model_name}TableMigration {
|
|
|
257
258
|
${JSON.stringify(idx.fields)},
|
|
258
259
|
{
|
|
259
260
|
name: "${idx.name}",
|
|
260
|
-
${indentBlock(serializeIndexDefinition(idx).replace(/^{|}$/g, ""),
|
|
261
|
+
${indentBlock(serializeIndexDefinition(idx).replace(/^{|}$/g, ""), 1)}
|
|
261
262
|
}
|
|
262
263
|
);
|
|
263
264
|
` : "";
|
|
@@ -296,7 +297,7 @@ class Update${model_name}TableMigration {
|
|
|
296
297
|
${JSON.stringify(idx.fields)},
|
|
297
298
|
{
|
|
298
299
|
name: "${idx.name}",
|
|
299
|
-
${indentBlock(serializeIndexDefinition(idx).replace(/^{|}$/g, ""),
|
|
300
|
+
${indentBlock(serializeIndexDefinition(idx).replace(/^{|}$/g, ""), 1)}
|
|
300
301
|
}
|
|
301
302
|
);
|
|
302
303
|
` : "";
|
|
@@ -311,7 +312,7 @@ class Update${model_name}TableMigration {
|
|
|
311
312
|
${JSON.stringify(idx.fields)},
|
|
312
313
|
{
|
|
313
314
|
name: "${idx.name}",
|
|
314
|
-
${indentBlock(serializeIndexDefinition(idx).replace(/^{|}$/g, ""),
|
|
315
|
+
${indentBlock(serializeIndexDefinition(idx).replace(/^{|}$/g, ""), 1)}
|
|
315
316
|
}
|
|
316
317
|
);
|
|
317
318
|
` : "";
|
|
@@ -45,20 +45,20 @@ class SchemaDiffUtil {
|
|
|
45
45
|
// Indexes
|
|
46
46
|
const prev_indexes = prev?.indexes || [];
|
|
47
47
|
const curr_indexes = curr?.indexes || [];
|
|
48
|
-
const prev_map = new Map(prev_indexes.map(i => [i
|
|
49
|
-
const curr_map = new Map(curr_indexes.map(i => [i
|
|
50
|
-
for (const [
|
|
51
|
-
const prev_idx = prev_map.get(
|
|
48
|
+
const prev_map = new Map(prev_indexes.map(i => [SchemaDiffUtil.indexKey(i), i]));
|
|
49
|
+
const curr_map = new Map(curr_indexes.map(i => [SchemaDiffUtil.indexKey(i), i]));
|
|
50
|
+
for (const [key, curr_idx] of curr_map) {
|
|
51
|
+
const prev_idx = prev_map.get(key);
|
|
52
52
|
if (!prev_idx) {
|
|
53
|
-
diff.indexes.added.push(name);
|
|
53
|
+
diff.indexes.added.push(curr_idx.name);
|
|
54
54
|
}
|
|
55
55
|
else if (!input_validator_util_1.default.isDeepEqual(prev_idx, curr_idx)) {
|
|
56
|
-
diff.indexes.modified.push(name);
|
|
56
|
+
diff.indexes.modified.push(curr_idx.name);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
for (const [
|
|
60
|
-
if (!curr_map.has(
|
|
61
|
-
diff.indexes.removed.push(name);
|
|
59
|
+
for (const [key, prev_idx] of prev_map) {
|
|
60
|
+
if (!curr_map.has(key)) {
|
|
61
|
+
diff.indexes.removed.push(prev_idx.name);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
return diff;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fiberx-backend-toolkit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.65",
|
|
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",
|