@strapi/database 5.23.6 → 5.24.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.
- package/dist/repairs/index.d.ts +1 -0
- package/dist/repairs/index.d.ts.map +1 -1
- package/dist/repairs/index.js +3 -1
- package/dist/repairs/index.js.map +1 -1
- package/dist/repairs/index.mjs +3 -1
- package/dist/repairs/index.mjs.map +1 -1
- package/dist/repairs/operations/process-unidirectional-join-tables.d.ts +14 -0
- package/dist/repairs/operations/process-unidirectional-join-tables.d.ts.map +1 -0
- package/dist/repairs/operations/process-unidirectional-join-tables.js +57 -0
- package/dist/repairs/operations/process-unidirectional-join-tables.js.map +1 -0
- package/dist/repairs/operations/process-unidirectional-join-tables.mjs +55 -0
- package/dist/repairs/operations/process-unidirectional-join-tables.mjs.map +1 -0
- package/package.json +4 -4
package/dist/repairs/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Database } from '..';
|
|
2
2
|
export declare const createRepairManager: (db: Database) => {
|
|
3
3
|
removeOrphanMorphType: (arg: import("./operations/remove-orphan-morph-types").RemoveOrphanMorphTypeOptions) => Promise<void>;
|
|
4
|
+
processUnidirectionalJoinTables: (arg: (db: Database, joinTableName: string, relation: any, sourceModel: any) => Promise<number>) => Promise<number>;
|
|
4
5
|
};
|
|
5
6
|
export type RepairManager = ReturnType<typeof createRepairManager>;
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/repairs/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/repairs/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAKnC,eAAO,MAAM,mBAAmB,OAAQ,QAAQ;;;CAK/C,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
|
package/dist/repairs/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var removeOrphanMorphTypes = require('./operations/remove-orphan-morph-types.js');
|
|
4
|
+
var processUnidirectionalJoinTables = require('./operations/process-unidirectional-join-tables.js');
|
|
4
5
|
var asyncCurry = require('../utils/async-curry.js');
|
|
5
6
|
|
|
6
7
|
const createRepairManager = (db)=>{
|
|
7
8
|
return {
|
|
8
|
-
removeOrphanMorphType: asyncCurry.asyncCurry(removeOrphanMorphTypes.removeOrphanMorphType)(db)
|
|
9
|
+
removeOrphanMorphType: asyncCurry.asyncCurry(removeOrphanMorphTypes.removeOrphanMorphType)(db),
|
|
10
|
+
processUnidirectionalJoinTables: asyncCurry.asyncCurry(processUnidirectionalJoinTables.processUnidirectionalJoinTables)(db)
|
|
9
11
|
};
|
|
10
12
|
};
|
|
11
13
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/repairs/index.ts"],"sourcesContent":["import type { Database } from '..';\nimport { removeOrphanMorphType as removeOrphanMorphTypeFunc } from './operations/remove-orphan-morph-types';\nimport { asyncCurry } from '../utils/async-curry';\n\nexport const createRepairManager = (db: Database) => {\n return {\n removeOrphanMorphType: asyncCurry(removeOrphanMorphTypeFunc)(db),\n };\n};\n\nexport type RepairManager = ReturnType<typeof createRepairManager>;\n"],"names":["createRepairManager","db","removeOrphanMorphType","asyncCurry","removeOrphanMorphTypeFunc"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/repairs/index.ts"],"sourcesContent":["import type { Database } from '..';\nimport { removeOrphanMorphType as removeOrphanMorphTypeFunc } from './operations/remove-orphan-morph-types';\nimport { processUnidirectionalJoinTables } from './operations/process-unidirectional-join-tables';\nimport { asyncCurry } from '../utils/async-curry';\n\nexport const createRepairManager = (db: Database) => {\n return {\n removeOrphanMorphType: asyncCurry(removeOrphanMorphTypeFunc)(db),\n processUnidirectionalJoinTables: asyncCurry(processUnidirectionalJoinTables)(db),\n };\n};\n\nexport type RepairManager = ReturnType<typeof createRepairManager>;\n"],"names":["createRepairManager","db","removeOrphanMorphType","asyncCurry","removeOrphanMorphTypeFunc","processUnidirectionalJoinTables"],"mappings":";;;;;;AAKO,MAAMA,sBAAsB,CAACC,EAAAA,GAAAA;IAClC,OAAO;AACLC,QAAAA,qBAAAA,EAAuBC,sBAAWC,4CAA2BH,CAAAA,CAAAA,EAAAA,CAAAA;AAC7DI,QAAAA,+BAAAA,EAAiCF,sBAAWE,+DAAiCJ,CAAAA,CAAAA,EAAAA;AAC/E,KAAA;AACF;;;;"}
|
package/dist/repairs/index.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { removeOrphanMorphType } from './operations/remove-orphan-morph-types.mjs';
|
|
2
|
+
import { processUnidirectionalJoinTables } from './operations/process-unidirectional-join-tables.mjs';
|
|
2
3
|
import { asyncCurry } from '../utils/async-curry.mjs';
|
|
3
4
|
|
|
4
5
|
const createRepairManager = (db)=>{
|
|
5
6
|
return {
|
|
6
|
-
removeOrphanMorphType: asyncCurry(removeOrphanMorphType)(db)
|
|
7
|
+
removeOrphanMorphType: asyncCurry(removeOrphanMorphType)(db),
|
|
8
|
+
processUnidirectionalJoinTables: asyncCurry(processUnidirectionalJoinTables)(db)
|
|
7
9
|
};
|
|
8
10
|
};
|
|
9
11
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/repairs/index.ts"],"sourcesContent":["import type { Database } from '..';\nimport { removeOrphanMorphType as removeOrphanMorphTypeFunc } from './operations/remove-orphan-morph-types';\nimport { asyncCurry } from '../utils/async-curry';\n\nexport const createRepairManager = (db: Database) => {\n return {\n removeOrphanMorphType: asyncCurry(removeOrphanMorphTypeFunc)(db),\n };\n};\n\nexport type RepairManager = ReturnType<typeof createRepairManager>;\n"],"names":["createRepairManager","db","removeOrphanMorphType","asyncCurry","removeOrphanMorphTypeFunc"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/repairs/index.ts"],"sourcesContent":["import type { Database } from '..';\nimport { removeOrphanMorphType as removeOrphanMorphTypeFunc } from './operations/remove-orphan-morph-types';\nimport { processUnidirectionalJoinTables } from './operations/process-unidirectional-join-tables';\nimport { asyncCurry } from '../utils/async-curry';\n\nexport const createRepairManager = (db: Database) => {\n return {\n removeOrphanMorphType: asyncCurry(removeOrphanMorphTypeFunc)(db),\n processUnidirectionalJoinTables: asyncCurry(processUnidirectionalJoinTables)(db),\n };\n};\n\nexport type RepairManager = ReturnType<typeof createRepairManager>;\n"],"names":["createRepairManager","db","removeOrphanMorphType","asyncCurry","removeOrphanMorphTypeFunc","processUnidirectionalJoinTables"],"mappings":";;;;AAKO,MAAMA,sBAAsB,CAACC,EAAAA,GAAAA;IAClC,OAAO;AACLC,QAAAA,qBAAAA,EAAuBC,WAAWC,qBAA2BH,CAAAA,CAAAA,EAAAA,CAAAA;AAC7DI,QAAAA,+BAAAA,EAAiCF,WAAWE,+BAAiCJ,CAAAA,CAAAA,EAAAA;AAC/E,KAAA;AACF;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Database } from '../..';
|
|
2
|
+
/**
|
|
3
|
+
* Iterates over all models and their unidirectional relations, invoking a provided operation on each join table.
|
|
4
|
+
*
|
|
5
|
+
* This function does not perform any cleaning or modification itself. Instead, it identifies all unidirectional
|
|
6
|
+
* relations (relations without inversedBy or mappedBy) that use join tables, and delegates any join table operation
|
|
7
|
+
* (such as cleaning, validation, or analysis) to the provided operateOnJoinTable function.
|
|
8
|
+
*
|
|
9
|
+
* @param db - The database instance
|
|
10
|
+
* @param operateOnJoinTable - A function to execute for each unidirectional join table relation
|
|
11
|
+
* @returns The sum of results returned by operateOnJoinTable for all processed relations
|
|
12
|
+
*/
|
|
13
|
+
export declare const processUnidirectionalJoinTables: (db: Database, operateOnJoinTable: (db: Database, joinTableName: string, relation: any, sourceModel: any) => Promise<number>) => Promise<number>;
|
|
14
|
+
//# sourceMappingURL=process-unidirectional-join-tables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-unidirectional-join-tables.d.ts","sourceRoot":"","sources":["../../../src/repairs/operations/process-unidirectional-join-tables.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEtC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,+BAA+B,OACtC,QAAQ,sBACQ,CAClB,EAAE,EAAE,QAAQ,EACZ,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,GAAG,EACb,WAAW,EAAE,GAAG,KACb,QAAQ,MAAM,CAAC,KACnB,QAAQ,MAAM,CA4BhB,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Iterates over all models and their unidirectional relations, invoking a provided operation on each join table.
|
|
5
|
+
*
|
|
6
|
+
* This function does not perform any cleaning or modification itself. Instead, it identifies all unidirectional
|
|
7
|
+
* relations (relations without inversedBy or mappedBy) that use join tables, and delegates any join table operation
|
|
8
|
+
* (such as cleaning, validation, or analysis) to the provided operateOnJoinTable function.
|
|
9
|
+
*
|
|
10
|
+
* @param db - The database instance
|
|
11
|
+
* @param operateOnJoinTable - A function to execute for each unidirectional join table relation
|
|
12
|
+
* @returns The sum of results returned by operateOnJoinTable for all processed relations
|
|
13
|
+
*/ const processUnidirectionalJoinTables = async (db, operateOnJoinTable)=>{
|
|
14
|
+
let totalResult = 0;
|
|
15
|
+
const mdValues = db.metadata.values();
|
|
16
|
+
const mdArray = Array.from(mdValues);
|
|
17
|
+
if (mdArray.length === 0) {
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
db.logger.debug('Starting unidirectional join table operation');
|
|
21
|
+
for (const model of mdArray){
|
|
22
|
+
const unidirectionalRelations = getUnidirectionalRelations(model.attributes || {});
|
|
23
|
+
for (const relation of unidirectionalRelations){
|
|
24
|
+
if (hasJoinTable(relation) && hasTarget(relation)) {
|
|
25
|
+
const result = await operateOnJoinTable(db, relation.joinTable.name, relation, model);
|
|
26
|
+
totalResult += result;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
db.logger.debug(`Unidirectional join table operation completed. Processed ${totalResult} entries.`);
|
|
31
|
+
return totalResult;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Identifies unidirectional relations (relations without inversedBy or mappedBy)
|
|
35
|
+
* Uses same logic as prevention fix in unidirectional-relations.ts:54-61
|
|
36
|
+
*/ const getUnidirectionalRelations = (attributes)=>{
|
|
37
|
+
return Object.values(attributes).filter((attribute)=>{
|
|
38
|
+
if (attribute.type !== 'relation') {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
// Check if it's unidirectional (no inversedBy or mappedBy) - same as prevention logic
|
|
42
|
+
return !attribute.inversedBy && !attribute.mappedBy;
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Type guard to check if a relation has a joinTable property
|
|
47
|
+
*/ const hasJoinTable = (relation)=>{
|
|
48
|
+
return 'joinTable' in relation && relation.joinTable != null;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Type guard to check if a relation has a target property
|
|
52
|
+
*/ const hasTarget = (relation)=>{
|
|
53
|
+
return 'target' in relation && typeof relation.target === 'string';
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
exports.processUnidirectionalJoinTables = processUnidirectionalJoinTables;
|
|
57
|
+
//# sourceMappingURL=process-unidirectional-join-tables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-unidirectional-join-tables.js","sources":["../../../src/repairs/operations/process-unidirectional-join-tables.ts"],"sourcesContent":["import type { Database } from '../..';\n\n/**\n * Iterates over all models and their unidirectional relations, invoking a provided operation on each join table.\n *\n * This function does not perform any cleaning or modification itself. Instead, it identifies all unidirectional\n * relations (relations without inversedBy or mappedBy) that use join tables, and delegates any join table operation\n * (such as cleaning, validation, or analysis) to the provided operateOnJoinTable function.\n *\n * @param db - The database instance\n * @param operateOnJoinTable - A function to execute for each unidirectional join table relation\n * @returns The sum of results returned by operateOnJoinTable for all processed relations\n */\nexport const processUnidirectionalJoinTables = async (\n db: Database,\n operateOnJoinTable: (\n db: Database,\n joinTableName: string,\n relation: any,\n sourceModel: any\n ) => Promise<number>\n): Promise<number> => {\n let totalResult = 0;\n\n const mdValues = db.metadata.values();\n const mdArray = Array.from(mdValues);\n\n if (mdArray.length === 0) {\n return 0;\n }\n\n db.logger.debug('Starting unidirectional join table operation');\n\n for (const model of mdArray) {\n const unidirectionalRelations = getUnidirectionalRelations(model.attributes || {});\n\n for (const relation of unidirectionalRelations) {\n if (hasJoinTable(relation) && hasTarget(relation)) {\n const result = await operateOnJoinTable(db, relation.joinTable.name, relation, model);\n totalResult += result;\n }\n }\n }\n\n db.logger.debug(\n `Unidirectional join table operation completed. Processed ${totalResult} entries.`\n );\n\n return totalResult;\n};\n\n/**\n * Identifies unidirectional relations (relations without inversedBy or mappedBy)\n * Uses same logic as prevention fix in unidirectional-relations.ts:54-61\n */\nconst getUnidirectionalRelations = (attributes: Record<string, any>): any[] => {\n return Object.values(attributes).filter((attribute) => {\n if (attribute.type !== 'relation') {\n return false;\n }\n\n // Check if it's unidirectional (no inversedBy or mappedBy) - same as prevention logic\n return !attribute.inversedBy && !attribute.mappedBy;\n });\n};\n\n/**\n * Type guard to check if a relation has a joinTable property\n */\nconst hasJoinTable = (relation: any): boolean => {\n return 'joinTable' in relation && relation.joinTable != null;\n};\n\n/**\n * Type guard to check if a relation has a target property\n */\nconst hasTarget = (relation: any): boolean => {\n return 'target' in relation && typeof relation.target === 'string';\n};\n"],"names":["processUnidirectionalJoinTables","db","operateOnJoinTable","totalResult","mdValues","metadata","values","mdArray","Array","from","length","logger","debug","model","unidirectionalRelations","getUnidirectionalRelations","attributes","relation","hasJoinTable","hasTarget","result","joinTable","name","Object","filter","attribute","type","inversedBy","mappedBy","target"],"mappings":";;AAEA;;;;;;;;;;AAUC,IACM,MAAMA,+BAAkC,GAAA,OAC7CC,EACAC,EAAAA,kBAAAA,GAAAA;AAOA,IAAA,IAAIC,WAAc,GAAA,CAAA;AAElB,IAAA,MAAMC,QAAWH,GAAAA,EAAAA,CAAGI,QAAQ,CAACC,MAAM,EAAA;IACnC,MAAMC,OAAAA,GAAUC,KAAMC,CAAAA,IAAI,CAACL,QAAAA,CAAAA;IAE3B,IAAIG,OAAAA,CAAQG,MAAM,KAAK,CAAG,EAAA;QACxB,OAAO,CAAA;AACT;IAEAT,EAAGU,CAAAA,MAAM,CAACC,KAAK,CAAC,8CAAA,CAAA;IAEhB,KAAK,MAAMC,SAASN,OAAS,CAAA;AAC3B,QAAA,MAAMO,uBAA0BC,GAAAA,0BAAAA,CAA2BF,KAAMG,CAAAA,UAAU,IAAI,EAAC,CAAA;QAEhF,KAAK,MAAMC,YAAYH,uBAAyB,CAAA;YAC9C,IAAII,YAAAA,CAAaD,QAAaE,CAAAA,IAAAA,SAAAA,CAAUF,QAAW,CAAA,EAAA;gBACjD,MAAMG,MAAAA,GAAS,MAAMlB,kBAAmBD,CAAAA,EAAAA,EAAIgB,SAASI,SAAS,CAACC,IAAI,EAAEL,QAAUJ,EAAAA,KAAAA,CAAAA;gBAC/EV,WAAeiB,IAAAA,MAAAA;AACjB;AACF;AACF;IAEAnB,EAAGU,CAAAA,MAAM,CAACC,KAAK,CACb,CAAC,yDAAyD,EAAET,WAAY,CAAA,SAAS,CAAC,CAAA;IAGpF,OAAOA,WAAAA;AACT;AAEA;;;IAIA,MAAMY,6BAA6B,CAACC,UAAAA,GAAAA;AAClC,IAAA,OAAOO,OAAOjB,MAAM,CAACU,UAAYQ,CAAAA,CAAAA,MAAM,CAAC,CAACC,SAAAA,GAAAA;QACvC,IAAIA,SAAAA,CAAUC,IAAI,KAAK,UAAY,EAAA;YACjC,OAAO,KAAA;AACT;;AAGA,QAAA,OAAO,CAACD,SAAUE,CAAAA,UAAU,IAAI,CAACF,UAAUG,QAAQ;AACrD,KAAA,CAAA;AACF,CAAA;AAEA;;IAGA,MAAMV,eAAe,CAACD,QAAAA,GAAAA;AACpB,IAAA,OAAO,WAAeA,IAAAA,QAAAA,IAAYA,QAASI,CAAAA,SAAS,IAAI,IAAA;AAC1D,CAAA;AAEA;;IAGA,MAAMF,YAAY,CAACF,QAAAA,GAAAA;AACjB,IAAA,OAAO,QAAYA,IAAAA,QAAAA,IAAY,OAAOA,QAAAA,CAASY,MAAM,KAAK,QAAA;AAC5D,CAAA;;;;"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterates over all models and their unidirectional relations, invoking a provided operation on each join table.
|
|
3
|
+
*
|
|
4
|
+
* This function does not perform any cleaning or modification itself. Instead, it identifies all unidirectional
|
|
5
|
+
* relations (relations without inversedBy or mappedBy) that use join tables, and delegates any join table operation
|
|
6
|
+
* (such as cleaning, validation, or analysis) to the provided operateOnJoinTable function.
|
|
7
|
+
*
|
|
8
|
+
* @param db - The database instance
|
|
9
|
+
* @param operateOnJoinTable - A function to execute for each unidirectional join table relation
|
|
10
|
+
* @returns The sum of results returned by operateOnJoinTable for all processed relations
|
|
11
|
+
*/ const processUnidirectionalJoinTables = async (db, operateOnJoinTable)=>{
|
|
12
|
+
let totalResult = 0;
|
|
13
|
+
const mdValues = db.metadata.values();
|
|
14
|
+
const mdArray = Array.from(mdValues);
|
|
15
|
+
if (mdArray.length === 0) {
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
db.logger.debug('Starting unidirectional join table operation');
|
|
19
|
+
for (const model of mdArray){
|
|
20
|
+
const unidirectionalRelations = getUnidirectionalRelations(model.attributes || {});
|
|
21
|
+
for (const relation of unidirectionalRelations){
|
|
22
|
+
if (hasJoinTable(relation) && hasTarget(relation)) {
|
|
23
|
+
const result = await operateOnJoinTable(db, relation.joinTable.name, relation, model);
|
|
24
|
+
totalResult += result;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
db.logger.debug(`Unidirectional join table operation completed. Processed ${totalResult} entries.`);
|
|
29
|
+
return totalResult;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Identifies unidirectional relations (relations without inversedBy or mappedBy)
|
|
33
|
+
* Uses same logic as prevention fix in unidirectional-relations.ts:54-61
|
|
34
|
+
*/ const getUnidirectionalRelations = (attributes)=>{
|
|
35
|
+
return Object.values(attributes).filter((attribute)=>{
|
|
36
|
+
if (attribute.type !== 'relation') {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
// Check if it's unidirectional (no inversedBy or mappedBy) - same as prevention logic
|
|
40
|
+
return !attribute.inversedBy && !attribute.mappedBy;
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Type guard to check if a relation has a joinTable property
|
|
45
|
+
*/ const hasJoinTable = (relation)=>{
|
|
46
|
+
return 'joinTable' in relation && relation.joinTable != null;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Type guard to check if a relation has a target property
|
|
50
|
+
*/ const hasTarget = (relation)=>{
|
|
51
|
+
return 'target' in relation && typeof relation.target === 'string';
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export { processUnidirectionalJoinTables };
|
|
55
|
+
//# sourceMappingURL=process-unidirectional-join-tables.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-unidirectional-join-tables.mjs","sources":["../../../src/repairs/operations/process-unidirectional-join-tables.ts"],"sourcesContent":["import type { Database } from '../..';\n\n/**\n * Iterates over all models and their unidirectional relations, invoking a provided operation on each join table.\n *\n * This function does not perform any cleaning or modification itself. Instead, it identifies all unidirectional\n * relations (relations without inversedBy or mappedBy) that use join tables, and delegates any join table operation\n * (such as cleaning, validation, or analysis) to the provided operateOnJoinTable function.\n *\n * @param db - The database instance\n * @param operateOnJoinTable - A function to execute for each unidirectional join table relation\n * @returns The sum of results returned by operateOnJoinTable for all processed relations\n */\nexport const processUnidirectionalJoinTables = async (\n db: Database,\n operateOnJoinTable: (\n db: Database,\n joinTableName: string,\n relation: any,\n sourceModel: any\n ) => Promise<number>\n): Promise<number> => {\n let totalResult = 0;\n\n const mdValues = db.metadata.values();\n const mdArray = Array.from(mdValues);\n\n if (mdArray.length === 0) {\n return 0;\n }\n\n db.logger.debug('Starting unidirectional join table operation');\n\n for (const model of mdArray) {\n const unidirectionalRelations = getUnidirectionalRelations(model.attributes || {});\n\n for (const relation of unidirectionalRelations) {\n if (hasJoinTable(relation) && hasTarget(relation)) {\n const result = await operateOnJoinTable(db, relation.joinTable.name, relation, model);\n totalResult += result;\n }\n }\n }\n\n db.logger.debug(\n `Unidirectional join table operation completed. Processed ${totalResult} entries.`\n );\n\n return totalResult;\n};\n\n/**\n * Identifies unidirectional relations (relations without inversedBy or mappedBy)\n * Uses same logic as prevention fix in unidirectional-relations.ts:54-61\n */\nconst getUnidirectionalRelations = (attributes: Record<string, any>): any[] => {\n return Object.values(attributes).filter((attribute) => {\n if (attribute.type !== 'relation') {\n return false;\n }\n\n // Check if it's unidirectional (no inversedBy or mappedBy) - same as prevention logic\n return !attribute.inversedBy && !attribute.mappedBy;\n });\n};\n\n/**\n * Type guard to check if a relation has a joinTable property\n */\nconst hasJoinTable = (relation: any): boolean => {\n return 'joinTable' in relation && relation.joinTable != null;\n};\n\n/**\n * Type guard to check if a relation has a target property\n */\nconst hasTarget = (relation: any): boolean => {\n return 'target' in relation && typeof relation.target === 'string';\n};\n"],"names":["processUnidirectionalJoinTables","db","operateOnJoinTable","totalResult","mdValues","metadata","values","mdArray","Array","from","length","logger","debug","model","unidirectionalRelations","getUnidirectionalRelations","attributes","relation","hasJoinTable","hasTarget","result","joinTable","name","Object","filter","attribute","type","inversedBy","mappedBy","target"],"mappings":"AAEA;;;;;;;;;;AAUC,IACM,MAAMA,+BAAkC,GAAA,OAC7CC,EACAC,EAAAA,kBAAAA,GAAAA;AAOA,IAAA,IAAIC,WAAc,GAAA,CAAA;AAElB,IAAA,MAAMC,QAAWH,GAAAA,EAAAA,CAAGI,QAAQ,CAACC,MAAM,EAAA;IACnC,MAAMC,OAAAA,GAAUC,KAAMC,CAAAA,IAAI,CAACL,QAAAA,CAAAA;IAE3B,IAAIG,OAAAA,CAAQG,MAAM,KAAK,CAAG,EAAA;QACxB,OAAO,CAAA;AACT;IAEAT,EAAGU,CAAAA,MAAM,CAACC,KAAK,CAAC,8CAAA,CAAA;IAEhB,KAAK,MAAMC,SAASN,OAAS,CAAA;AAC3B,QAAA,MAAMO,uBAA0BC,GAAAA,0BAAAA,CAA2BF,KAAMG,CAAAA,UAAU,IAAI,EAAC,CAAA;QAEhF,KAAK,MAAMC,YAAYH,uBAAyB,CAAA;YAC9C,IAAII,YAAAA,CAAaD,QAAaE,CAAAA,IAAAA,SAAAA,CAAUF,QAAW,CAAA,EAAA;gBACjD,MAAMG,MAAAA,GAAS,MAAMlB,kBAAmBD,CAAAA,EAAAA,EAAIgB,SAASI,SAAS,CAACC,IAAI,EAAEL,QAAUJ,EAAAA,KAAAA,CAAAA;gBAC/EV,WAAeiB,IAAAA,MAAAA;AACjB;AACF;AACF;IAEAnB,EAAGU,CAAAA,MAAM,CAACC,KAAK,CACb,CAAC,yDAAyD,EAAET,WAAY,CAAA,SAAS,CAAC,CAAA;IAGpF,OAAOA,WAAAA;AACT;AAEA;;;IAIA,MAAMY,6BAA6B,CAACC,UAAAA,GAAAA;AAClC,IAAA,OAAOO,OAAOjB,MAAM,CAACU,UAAYQ,CAAAA,CAAAA,MAAM,CAAC,CAACC,SAAAA,GAAAA;QACvC,IAAIA,SAAAA,CAAUC,IAAI,KAAK,UAAY,EAAA;YACjC,OAAO,KAAA;AACT;;AAGA,QAAA,OAAO,CAACD,SAAUE,CAAAA,UAAU,IAAI,CAACF,UAAUG,QAAQ;AACrD,KAAA,CAAA;AACF,CAAA;AAEA;;IAGA,MAAMV,eAAe,CAACD,QAAAA,GAAAA;AACpB,IAAA,OAAO,WAAeA,IAAAA,QAAAA,IAAYA,QAASI,CAAAA,SAAS,IAAI,IAAA;AAC1D,CAAA;AAEA;;IAGA,MAAMF,YAAY,CAACF,QAAAA,GAAAA;AACjB,IAAA,OAAO,QAAYA,IAAAA,QAAAA,IAAY,OAAOA,QAAAA,CAASY,MAAM,KAAK,QAAA;AAC5D,CAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/database",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.24.0",
|
|
4
4
|
"description": "Strapi's database layer",
|
|
5
5
|
"homepage": "https://strapi.io",
|
|
6
6
|
"bugs": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@paralleldrive/cuid2": "2.2.2",
|
|
45
|
-
"@strapi/utils": "5.
|
|
45
|
+
"@strapi/utils": "5.24.0",
|
|
46
46
|
"ajv": "8.16.0",
|
|
47
47
|
"date-fns": "2.30.0",
|
|
48
48
|
"debug": "4.3.4",
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/fs-extra": "11.0.4",
|
|
57
|
-
"eslint-config-custom": "5.
|
|
58
|
-
"tsconfig": "5.
|
|
57
|
+
"eslint-config-custom": "5.24.0",
|
|
58
|
+
"tsconfig": "5.24.0"
|
|
59
59
|
},
|
|
60
60
|
"engines": {
|
|
61
61
|
"node": ">=18.0.0 <=22.x.x",
|