fiberx-backend-toolkit 0.0.29 → 0.0.31
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.
|
@@ -7,6 +7,7 @@ import { DataTypes } from "sequelize";
|
|
|
7
7
|
import { SchemaDefinitionInterface } from "fiberx-backend-toolkit/dist/types/schema_type";
|
|
8
8
|
|
|
9
9
|
const ${schema_name}: SchemaDefinitionInterface = {
|
|
10
|
+
connection_name: "default",
|
|
10
11
|
database_name: "public",
|
|
11
12
|
migration_priority: ${migration_priority},
|
|
12
13
|
|
|
@@ -328,14 +329,19 @@ const SEQUELIZE_MODEL_CODE_TEMPLATE = (schema_model_name, schema_file_name, sche
|
|
|
328
329
|
return `
|
|
329
330
|
import { Model, Sequelize } from "sequelize";
|
|
330
331
|
import ${schema_model_name}Schema from "@/database/schemas/${schema_file_name.replace(".ts", "")}";
|
|
332
|
+
import { SchemaDefinitionInterface } from "fiberx-backend-toolkit";
|
|
331
333
|
|
|
332
334
|
|
|
333
335
|
class ${schema_model_name} extends Model {
|
|
334
336
|
${attributes}
|
|
335
337
|
|
|
338
|
+
public static schema_def: SchemaDefinitionInterface = ${schema_model_name}Schema
|
|
339
|
+
|
|
336
340
|
public static initModel(sequelize: Sequelize): typeof ${schema_model_name} {
|
|
337
|
-
sequelize
|
|
338
|
-
|
|
341
|
+
if (!sequelize) {
|
|
342
|
+
throw new Error("Sequelize instance is required to initialize the ${schema_model_name} model.");
|
|
343
|
+
}
|
|
344
|
+
|
|
339
345
|
${schema_model_name}.init(
|
|
340
346
|
${schema_model_name}Schema.columns,
|
|
341
347
|
{
|
|
@@ -363,28 +369,36 @@ export default ${schema_model_name}
|
|
|
363
369
|
};
|
|
364
370
|
exports.SEQUELIZE_MODEL_CODE_TEMPLATE = SEQUELIZE_MODEL_CODE_TEMPLATE;
|
|
365
371
|
const SEQUELIZE_MODELS_INDEX_CODE_TEMPLATE = (model_names, imports) => {
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
${
|
|
372
|
+
const model_initializers = model_names.map((model_name) => {
|
|
373
|
+
return `
|
|
374
|
+
export const ${model_name}Model = (): typeof ${model_name} => {
|
|
375
|
+
const connection_name = ${model_name}.schema_def?.connection_name || "default";
|
|
370
376
|
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
|
|
377
|
+
const sequelize = seqelize_connector.getConnection(connection_name);
|
|
378
|
+
|
|
379
|
+
if (!sequelize) {
|
|
380
|
+
throw new Error(
|
|
381
|
+
"Sequelize connection not available for ${model_name} model."
|
|
382
|
+
);
|
|
383
|
+
}
|
|
374
384
|
|
|
375
|
-
|
|
376
|
-
Object.values(models).forEach(model => {
|
|
377
|
-
model.initModel(sequelize);
|
|
378
|
-
});
|
|
385
|
+
const initialized = ${model_name}.initModel(sequelize);
|
|
379
386
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
}
|
|
387
|
+
if (${model_name}.registerAssociations) {
|
|
388
|
+
${model_name}.registerAssociations();
|
|
389
|
+
}
|
|
383
390
|
|
|
384
|
-
return
|
|
391
|
+
return initialized;
|
|
385
392
|
};
|
|
393
|
+
`;
|
|
394
|
+
}).join("\n");
|
|
395
|
+
return `
|
|
396
|
+
import { SequelizeConnector } from "fiberx-backend-toolkit/dist/database/main";
|
|
397
|
+
${imports}
|
|
398
|
+
|
|
399
|
+
const seqelize_connector = SequelizeConnector.getInstance();
|
|
386
400
|
|
|
387
|
-
|
|
401
|
+
${model_initializers}
|
|
388
402
|
`;
|
|
389
403
|
};
|
|
390
404
|
exports.SEQUELIZE_MODELS_INDEX_CODE_TEMPLATE = SEQUELIZE_MODELS_INDEX_CODE_TEMPLATE;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fiberx-backend-toolkit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.31",
|
|
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",
|