@lobb-js/core 0.25.0 → 0.26.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/package.json
CHANGED
package/src/api/meta/service.ts
CHANGED
|
@@ -425,6 +425,45 @@ export class ConfigManager {
|
|
|
425
425
|
return [];
|
|
426
426
|
}
|
|
427
427
|
|
|
428
|
+
public getCollectionChildren(collectionName: string): { type: string; collection: string; field?: string }[] {
|
|
429
|
+
const allRelations = this.config.relations ?? [];
|
|
430
|
+
const allCollections = this.config.collections;
|
|
431
|
+
const children: { type: string; collection: string; field?: string }[] = [];
|
|
432
|
+
const seenJunctions = new Set<string>();
|
|
433
|
+
|
|
434
|
+
for (const relation of allRelations) {
|
|
435
|
+
if ((relation as any).type === "polymorphic") continue;
|
|
436
|
+
const reg = relation as RegularRelation;
|
|
437
|
+
if (reg.to.collection !== collectionName) continue;
|
|
438
|
+
|
|
439
|
+
const childCollection = reg.from.collection;
|
|
440
|
+
if ((allCollections[childCollection] as any)?.junction) {
|
|
441
|
+
if (seenJunctions.has(childCollection)) continue;
|
|
442
|
+
seenJunctions.add(childCollection);
|
|
443
|
+
const otherSide = allRelations.find((r) =>
|
|
444
|
+
!("type" in r && r.type === "polymorphic") &&
|
|
445
|
+
(r as RegularRelation).from.collection === childCollection &&
|
|
446
|
+
(r as RegularRelation).from.field !== reg.from.field,
|
|
447
|
+
) as RegularRelation | undefined;
|
|
448
|
+
if (otherSide) {
|
|
449
|
+
children.push({ type: "m2m", collection: otherSide.to.collection });
|
|
450
|
+
}
|
|
451
|
+
} else {
|
|
452
|
+
children.push({ type: "fk", collection: childCollection, field: reg.from.field });
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
for (const relation of allRelations) {
|
|
457
|
+
if (!("type" in relation) || relation.type !== "polymorphic") continue;
|
|
458
|
+
const poly = relation as any;
|
|
459
|
+
if (Array.isArray(poly.to) && poly.to.includes(collectionName)) {
|
|
460
|
+
children.push({ type: "polymorphic", collection: poly.from.collection });
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
return children;
|
|
465
|
+
}
|
|
466
|
+
|
|
428
467
|
public isCollectionSingleton(collectionName: string): boolean {
|
|
429
468
|
const collection = this.config.collections[collectionName];
|
|
430
469
|
if (!collection || collection.virtual) return false;
|