node_modules ignore

This commit is contained in:
2025-05-08 23:43:47 +02:00
parent e19d52f172
commit 4574544c9f
65041 changed files with 10593536 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
import type { Database } from '..';
/**
* Validate if the database is in a valid state before starting the server.
*/
export declare function validateDatabase(db: Database): Promise<void>;
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validations/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAEnC;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,EAAE,EAAE,QAAQ,iBAElD"}

View File

@@ -0,0 +1,12 @@
'use strict';
var index = require('./relations/index.js');
/**
* Validate if the database is in a valid state before starting the server.
*/ async function validateDatabase(db) {
await index.validateRelations(db);
}
exports.validateDatabase = validateDatabase;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":["../../src/validations/index.ts"],"sourcesContent":["import { validateRelations } from './relations';\n\nimport type { Database } from '..';\n\n/**\n * Validate if the database is in a valid state before starting the server.\n */\nexport async function validateDatabase(db: Database) {\n await validateRelations(db);\n}\n"],"names":["validateDatabase","db","validateRelations"],"mappings":";;;;AAIA;;IAGO,eAAeA,gBAAAA,CAAiBC,EAAY,EAAA;AACjD,IAAA,MAAMC,uBAAkBD,CAAAA,EAAAA,CAAAA;AAC1B;;;;"}

View File

@@ -0,0 +1,10 @@
import { validateRelations } from './relations/index.mjs';
/**
* Validate if the database is in a valid state before starting the server.
*/ async function validateDatabase(db) {
await validateRelations(db);
}
export { validateDatabase };
//# sourceMappingURL=index.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sources":["../../src/validations/index.ts"],"sourcesContent":["import { validateRelations } from './relations';\n\nimport type { Database } from '..';\n\n/**\n * Validate if the database is in a valid state before starting the server.\n */\nexport async function validateDatabase(db: Database) {\n await validateRelations(db);\n}\n"],"names":["validateDatabase","db","validateRelations"],"mappings":";;AAIA;;IAGO,eAAeA,gBAAAA,CAAiBC,EAAY,EAAA;AACjD,IAAA,MAAMC,iBAAkBD,CAAAA,EAAAA,CAAAA;AAC1B;;;;"}

View File

@@ -0,0 +1,12 @@
import type { Database } from '../..';
/**
* Validates bidirectional relations before starting the server.
* - If both sides use inversedBy, one of the sides must switch to mappedBy.
* When this happens, two join tables exist in the database.
* This makes sure you switch the side which does not delete any data.
*
* @param {*} db
* @return {*}
*/
export declare const validateBidirectionalRelations: (db: Database) => Promise<void>;
//# sourceMappingURL=bidirectional.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"bidirectional.d.ts","sourceRoot":"","sources":["../../../src/validations/relations/bidirectional.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AA+CtC;;;;;;;;GAQG;AACH,eAAO,MAAM,8BAA8B,OAAc,QAAQ,kBAqChE,CAAC"}

View File

@@ -0,0 +1,64 @@
'use strict';
var _ = require('lodash/fp');
var index = require('../../utils/identifiers/index.js');
const getLinksWithoutMappedBy = (db)=>{
const relationsToUpdate = {};
db.metadata.forEach((modelMetadata)=>{
const attributes = modelMetadata.attributes;
// For each relation attribute, add the joinTable name to tablesToUpdate
Object.values(attributes).forEach((attribute)=>{
if (attribute.type !== 'relation') {
return;
}
if ('inversedBy' in attribute && attribute.inversedBy) {
const invRelation = db.metadata.get(attribute.target).attributes[attribute.inversedBy];
// Both relations use inversedBy.
if ('inversedBy' in invRelation && invRelation.inversedBy) {
relationsToUpdate[attribute.joinTable.name] = {
relation: attribute,
invRelation: invRelation
};
}
}
});
});
return Object.values(relationsToUpdate);
};
const isLinkTableEmpty = async (db, linkTableName)=>{
// If the table doesn't exist, it's empty
const exists = await db.getSchemaConnection().hasTable(linkTableName);
if (!exists) return true;
const result = await db.getConnection().from(linkTableName).count('* as count');
return Number(result[0].count) === 0;
};
/**
* Validates bidirectional relations before starting the server.
* - If both sides use inversedBy, one of the sides must switch to mappedBy.
* When this happens, two join tables exist in the database.
* This makes sure you switch the side which does not delete any data.
*
* @param {*} db
* @return {*}
*/ const validateBidirectionalRelations = async (db)=>{
const invalidLinks = getLinksWithoutMappedBy(db);
for (const { relation, invRelation } of invalidLinks){
const modelMetadata = db.metadata.get(invRelation.target);
const invModelMetadata = db.metadata.get(relation.target);
// Generate the join table name based on the relation target table and attribute name.
const joinTableName = index.identifiers.getJoinTableName(_.snakeCase(modelMetadata.tableName), _.snakeCase(invRelation.inversedBy));
const inverseJoinTableName = index.identifiers.getJoinTableName(_.snakeCase(invModelMetadata.tableName), _.snakeCase(relation.inversedBy));
const joinTableEmpty = await isLinkTableEmpty(db, joinTableName);
const inverseJoinTableEmpty = await isLinkTableEmpty(db, inverseJoinTableName);
if (joinTableEmpty) {
process.emitWarning(`Error on attribute "${invRelation.inversedBy}" in model "${modelMetadata.singularName}" (${modelMetadata.uid}).` + ` Please modify your ${modelMetadata.singularName} schema by renaming the key "inversedBy" to "mappedBy".` + ` Ex: { "inversedBy": "${relation.inversedBy}" } -> { "mappedBy": "${relation.inversedBy}" }`);
} else if (inverseJoinTableEmpty) {
// Its safe to delete the inverse join table
process.emitWarning(`Error on attribute "${relation.inversedBy}" in model "${invModelMetadata.singularName}" (${invModelMetadata.uid}).` + ` Please modify your ${invModelMetadata.singularName} schema by renaming the key "inversedBy" to "mappedBy".` + ` Ex: { "inversedBy": "${invRelation.inversedBy}" } -> { "mappedBy": "${invRelation.inversedBy}" }`);
} else ;
}
};
exports.validateBidirectionalRelations = validateBidirectionalRelations;
//# sourceMappingURL=bidirectional.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,62 @@
import { snakeCase } from 'lodash/fp';
import { identifiers } from '../../utils/identifiers/index.mjs';
const getLinksWithoutMappedBy = (db)=>{
const relationsToUpdate = {};
db.metadata.forEach((modelMetadata)=>{
const attributes = modelMetadata.attributes;
// For each relation attribute, add the joinTable name to tablesToUpdate
Object.values(attributes).forEach((attribute)=>{
if (attribute.type !== 'relation') {
return;
}
if ('inversedBy' in attribute && attribute.inversedBy) {
const invRelation = db.metadata.get(attribute.target).attributes[attribute.inversedBy];
// Both relations use inversedBy.
if ('inversedBy' in invRelation && invRelation.inversedBy) {
relationsToUpdate[attribute.joinTable.name] = {
relation: attribute,
invRelation: invRelation
};
}
}
});
});
return Object.values(relationsToUpdate);
};
const isLinkTableEmpty = async (db, linkTableName)=>{
// If the table doesn't exist, it's empty
const exists = await db.getSchemaConnection().hasTable(linkTableName);
if (!exists) return true;
const result = await db.getConnection().from(linkTableName).count('* as count');
return Number(result[0].count) === 0;
};
/**
* Validates bidirectional relations before starting the server.
* - If both sides use inversedBy, one of the sides must switch to mappedBy.
* When this happens, two join tables exist in the database.
* This makes sure you switch the side which does not delete any data.
*
* @param {*} db
* @return {*}
*/ const validateBidirectionalRelations = async (db)=>{
const invalidLinks = getLinksWithoutMappedBy(db);
for (const { relation, invRelation } of invalidLinks){
const modelMetadata = db.metadata.get(invRelation.target);
const invModelMetadata = db.metadata.get(relation.target);
// Generate the join table name based on the relation target table and attribute name.
const joinTableName = identifiers.getJoinTableName(snakeCase(modelMetadata.tableName), snakeCase(invRelation.inversedBy));
const inverseJoinTableName = identifiers.getJoinTableName(snakeCase(invModelMetadata.tableName), snakeCase(relation.inversedBy));
const joinTableEmpty = await isLinkTableEmpty(db, joinTableName);
const inverseJoinTableEmpty = await isLinkTableEmpty(db, inverseJoinTableName);
if (joinTableEmpty) {
process.emitWarning(`Error on attribute "${invRelation.inversedBy}" in model "${modelMetadata.singularName}" (${modelMetadata.uid}).` + ` Please modify your ${modelMetadata.singularName} schema by renaming the key "inversedBy" to "mappedBy".` + ` Ex: { "inversedBy": "${relation.inversedBy}" } -> { "mappedBy": "${relation.inversedBy}" }`);
} else if (inverseJoinTableEmpty) {
// Its safe to delete the inverse join table
process.emitWarning(`Error on attribute "${relation.inversedBy}" in model "${invModelMetadata.singularName}" (${invModelMetadata.uid}).` + ` Please modify your ${invModelMetadata.singularName} schema by renaming the key "inversedBy" to "mappedBy".` + ` Ex: { "inversedBy": "${invRelation.inversedBy}" } -> { "mappedBy": "${invRelation.inversedBy}" }`);
} else ;
}
};
export { validateBidirectionalRelations };
//# sourceMappingURL=bidirectional.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,7 @@
import type { Database } from '../..';
/**
* Validates if relations data and tables are in a valid state before
* starting the server.
*/
export declare const validateRelations: (db: Database) => Promise<void>;
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/validations/relations/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEtC;;;GAGG;AACH,eAAO,MAAM,iBAAiB,OAAc,QAAQ,kBAEnD,CAAC"}

View File

@@ -0,0 +1,13 @@
'use strict';
var bidirectional = require('./bidirectional.js');
/**
* Validates if relations data and tables are in a valid state before
* starting the server.
*/ const validateRelations = async (db)=>{
await bidirectional.validateBidirectionalRelations(db);
};
exports.validateRelations = validateRelations;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":["../../../src/validations/relations/index.ts"],"sourcesContent":["import { validateBidirectionalRelations } from './bidirectional';\n\nimport type { Database } from '../..';\n\n/**\n * Validates if relations data and tables are in a valid state before\n * starting the server.\n */\nexport const validateRelations = async (db: Database) => {\n await validateBidirectionalRelations(db);\n};\n"],"names":["validateRelations","db","validateBidirectionalRelations"],"mappings":";;;;AAIA;;;IAIaA,MAAAA,iBAAAA,GAAoB,OAAOC,EAAAA,GAAAA;AACtC,IAAA,MAAMC,4CAA+BD,CAAAA,EAAAA,CAAAA;AACvC;;;;"}

View File

@@ -0,0 +1,11 @@
import { validateBidirectionalRelations } from './bidirectional.mjs';
/**
* Validates if relations data and tables are in a valid state before
* starting the server.
*/ const validateRelations = async (db)=>{
await validateBidirectionalRelations(db);
};
export { validateRelations };
//# sourceMappingURL=index.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sources":["../../../src/validations/relations/index.ts"],"sourcesContent":["import { validateBidirectionalRelations } from './bidirectional';\n\nimport type { Database } from '../..';\n\n/**\n * Validates if relations data and tables are in a valid state before\n * starting the server.\n */\nexport const validateRelations = async (db: Database) => {\n await validateBidirectionalRelations(db);\n};\n"],"names":["validateRelations","db","validateBidirectionalRelations"],"mappings":";;AAIA;;;IAIaA,MAAAA,iBAAAA,GAAoB,OAAOC,EAAAA,GAAAA;AACtC,IAAA,MAAMC,8BAA+BD,CAAAA,EAAAA,CAAAA;AACvC;;;;"}