joist-core 2.0.3-next.2 → 2.0.3-next.21

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.
Files changed (105) hide show
  1. package/build/AliasAssigner.d.ts +3 -0
  2. package/build/AliasAssigner.d.ts.map +1 -1
  3. package/build/AliasAssigner.js +12 -3
  4. package/build/AliasAssigner.js.map +1 -1
  5. package/build/EntityManager.d.ts +20 -9
  6. package/build/EntityManager.d.ts.map +1 -1
  7. package/build/EntityManager.js +94 -58
  8. package/build/EntityManager.js.map +1 -1
  9. package/build/ReactionsManager.d.ts +1 -1
  10. package/build/ReactionsManager.d.ts.map +1 -1
  11. package/build/ReactionsManager.js +7 -5
  12. package/build/ReactionsManager.js.map +1 -1
  13. package/build/batchloaders/BatchLoader.d.ts +14 -0
  14. package/build/batchloaders/BatchLoader.d.ts.map +1 -0
  15. package/build/batchloaders/BatchLoader.js +49 -0
  16. package/build/batchloaders/BatchLoader.js.map +1 -0
  17. package/build/batchloaders/loadBatchLoader.d.ts +17 -0
  18. package/build/batchloaders/loadBatchLoader.d.ts.map +1 -0
  19. package/build/batchloaders/loadBatchLoader.js +55 -0
  20. package/build/batchloaders/loadBatchLoader.js.map +1 -0
  21. package/build/batchloaders/manyToManyBatchLoader.d.ts +7 -0
  22. package/build/batchloaders/manyToManyBatchLoader.d.ts.map +1 -0
  23. package/build/batchloaders/manyToManyBatchLoader.js +57 -0
  24. package/build/batchloaders/manyToManyBatchLoader.js.map +1 -0
  25. package/build/batchloaders/oneToManyBatchLoader.d.ts +7 -0
  26. package/build/batchloaders/oneToManyBatchLoader.d.ts.map +1 -0
  27. package/build/{dataloaders/oneToManyDataLoader.js → batchloaders/oneToManyBatchLoader.js} +9 -18
  28. package/build/batchloaders/oneToManyBatchLoader.js.map +1 -0
  29. package/build/batchloaders/oneToOneBatchLoader.d.ts +7 -0
  30. package/build/batchloaders/oneToOneBatchLoader.d.ts.map +1 -0
  31. package/build/{dataloaders/oneToOneDataLoader.js → batchloaders/oneToOneBatchLoader.js} +10 -16
  32. package/build/batchloaders/oneToOneBatchLoader.js.map +1 -0
  33. package/build/{dataloaders/populateDataLoader.d.ts → batchloaders/populateBatchLoader.d.ts} +5 -5
  34. package/build/batchloaders/populateBatchLoader.d.ts.map +1 -0
  35. package/build/{dataloaders/populateDataLoader.js → batchloaders/populateBatchLoader.js} +97 -54
  36. package/build/batchloaders/populateBatchLoader.js.map +1 -0
  37. package/build/batchloaders/recursiveChildrenBatchLoader.d.ts +7 -0
  38. package/build/batchloaders/recursiveChildrenBatchLoader.d.ts.map +1 -0
  39. package/build/{dataloaders/recursiveChildrenDataLoader.js → batchloaders/recursiveChildrenBatchLoader.js} +4 -6
  40. package/build/batchloaders/recursiveChildrenBatchLoader.js.map +1 -0
  41. package/build/batchloaders/recursiveParentsBatchLoader.d.ts +7 -0
  42. package/build/batchloaders/recursiveParentsBatchLoader.d.ts.map +1 -0
  43. package/build/{dataloaders/recursiveParentsDataLoader.js → batchloaders/recursiveParentsBatchLoader.js} +4 -5
  44. package/build/batchloaders/recursiveParentsBatchLoader.js.map +1 -0
  45. package/build/changes.js +2 -2
  46. package/build/changes.js.map +1 -1
  47. package/build/config.js +1 -1
  48. package/build/config.js.map +1 -1
  49. package/build/dataloaders/findIdsDataLoader.js +2 -2
  50. package/build/dataloaders/findIdsDataLoader.js.map +1 -1
  51. package/build/dataloaders/findOrCreateDataLoader.js +1 -1
  52. package/build/logging/ReactionLogger.d.ts +8 -4
  53. package/build/logging/ReactionLogger.d.ts.map +1 -1
  54. package/build/logging/ReactionLogger.js +11 -4
  55. package/build/logging/ReactionLogger.js.map +1 -1
  56. package/build/preloading/JsonAggregatePreloader.js +29 -24
  57. package/build/preloading/JsonAggregatePreloader.js.map +1 -1
  58. package/build/relations/Collection.d.ts +6 -1
  59. package/build/relations/Collection.d.ts.map +1 -1
  60. package/build/relations/Collection.js.map +1 -1
  61. package/build/relations/ManyToManyCollection.d.ts +8 -1
  62. package/build/relations/ManyToManyCollection.d.ts.map +1 -1
  63. package/build/relations/ManyToManyCollection.js +338 -130
  64. package/build/relations/ManyToManyCollection.js.map +1 -1
  65. package/build/relations/ManyToOneReference.d.ts +2 -6
  66. package/build/relations/ManyToOneReference.d.ts.map +1 -1
  67. package/build/relations/ManyToOneReference.js +115 -78
  68. package/build/relations/ManyToOneReference.js.map +1 -1
  69. package/build/relations/OneToManyCollection.d.ts +8 -4
  70. package/build/relations/OneToManyCollection.d.ts.map +1 -1
  71. package/build/relations/OneToManyCollection.js +415 -173
  72. package/build/relations/OneToManyCollection.js.map +1 -1
  73. package/build/relations/OneToOneReference.d.ts.map +1 -1
  74. package/build/relations/OneToOneReference.js +12 -7
  75. package/build/relations/OneToOneReference.js.map +1 -1
  76. package/build/relations/ReactiveManyToMany.js +4 -4
  77. package/build/relations/ReactiveManyToMany.js.map +1 -1
  78. package/build/relations/ReactiveManyToManyOtherSide.js +3 -3
  79. package/build/relations/ReactiveManyToManyOtherSide.js.map +1 -1
  80. package/build/relations/RecursiveCollection.d.ts.map +1 -1
  81. package/build/relations/RecursiveCollection.js +22 -8
  82. package/build/relations/RecursiveCollection.js.map +1 -1
  83. package/package.json +3 -4
  84. package/build/dataloaders/loadDataLoader.d.ts +0 -11
  85. package/build/dataloaders/loadDataLoader.d.ts.map +0 -1
  86. package/build/dataloaders/loadDataLoader.js +0 -54
  87. package/build/dataloaders/loadDataLoader.js.map +0 -1
  88. package/build/dataloaders/manyToManyDataLoader.d.ts +0 -8
  89. package/build/dataloaders/manyToManyDataLoader.d.ts.map +0 -1
  90. package/build/dataloaders/manyToManyDataLoader.js +0 -74
  91. package/build/dataloaders/manyToManyDataLoader.js.map +0 -1
  92. package/build/dataloaders/oneToManyDataLoader.d.ts +0 -7
  93. package/build/dataloaders/oneToManyDataLoader.d.ts.map +0 -1
  94. package/build/dataloaders/oneToManyDataLoader.js.map +0 -1
  95. package/build/dataloaders/oneToOneDataLoader.d.ts +0 -7
  96. package/build/dataloaders/oneToOneDataLoader.d.ts.map +0 -1
  97. package/build/dataloaders/oneToOneDataLoader.js.map +0 -1
  98. package/build/dataloaders/populateDataLoader.d.ts.map +0 -1
  99. package/build/dataloaders/populateDataLoader.js.map +0 -1
  100. package/build/dataloaders/recursiveChildrenDataLoader.d.ts +0 -7
  101. package/build/dataloaders/recursiveChildrenDataLoader.d.ts.map +0 -1
  102. package/build/dataloaders/recursiveChildrenDataLoader.js.map +0 -1
  103. package/build/dataloaders/recursiveParentsDataLoader.d.ts +0 -7
  104. package/build/dataloaders/recursiveParentsDataLoader.d.ts.map +0 -1
  105. package/build/dataloaders/recursiveParentsDataLoader.js.map +0 -1
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadOperation = void 0;
4
+ exports.loadBatchLoader = loadBatchLoader;
5
+ const BaseEntity_1 = require("../BaseEntity");
6
+ const EntityManager_1 = require("../EntityManager");
7
+ const HintTree_1 = require("../HintTree");
8
+ const QueryParser_1 = require("../QueryParser");
9
+ const keys_1 = require("../keys");
10
+ const utils_1 = require("../utils");
11
+ exports.loadOperation = "load";
12
+ /**
13
+ * Batches em.load-style fetches, writing to identity map (via hydrate) instead of returning values.
14
+ * After the batch resolves, callers retrieve their entity from `em.findExistingInstance`.
15
+ *
16
+ * Accepts tuples of `{ taggedId, hint }` so the preloader can inject join-based
17
+ * preloading into the same SELECT that fetches the entities.
18
+ */
19
+ function loadBatchLoader(em, meta, overwriteExisting = false) {
20
+ return em.getBatchLoader(exports.loadOperation, `${meta.type}-${overwriteExisting}`, async (loads) => {
21
+ const keys = loads.map((l) => (0, keys_1.keyToNumber)(meta, l.taggedId));
22
+ const alias = (0, utils_1.abbreviation)(meta.tableName);
23
+ const query = {
24
+ selects: [`"${alias}".*`],
25
+ tables: [{ alias, join: "primary", table: meta.tableName }],
26
+ condition: {
27
+ kind: "exp",
28
+ op: "and",
29
+ conditions: [{ kind: "column", alias, column: "id", dbType: meta.idDbType, cond: { kind: "in", value: keys } }],
30
+ },
31
+ orderBys: [{ alias, column: "id", order: "ASC" }],
32
+ };
33
+ (0, QueryParser_1.addTablePerClassJoinsAndClassTag)(query, meta, alias, true);
34
+ // Inject preloading joins into the query if enabled
35
+ const { preloader } = (0, EntityManager_1.getEmInternalApi)(em);
36
+ const preloadHydrator = preloader &&
37
+ preloader.addPreloading(meta, (0, HintTree_1.buildHintTree)(loads.map((l) => ({ entity: l.taggedId, hint: l.hint }))), query);
38
+ const rows = await em["executeFind"](meta, exports.loadOperation, query, {});
39
+ const entities = em.hydrate(meta.cstr, rows, { overwriteExisting });
40
+ preloadHydrator && preloadHydrator(rows, entities);
41
+ // If we're missing any requested rows, mark any requested-but-not-found entities as deleted
42
+ if (rows.length !== loads.length) {
43
+ const foundIds = new Set(rows.map((r) => (0, keys_1.tagId)(meta, r.id)));
44
+ for (const load of loads) {
45
+ if (!foundIds.has(load.taggedId)) {
46
+ const existingEntity = em.findExistingInstance(load.taggedId);
47
+ if (existingEntity) {
48
+ (0, BaseEntity_1.getInstanceData)(existingEntity).markDeletedBecauseNotFound();
49
+ }
50
+ }
51
+ }
52
+ }
53
+ });
54
+ }
55
+ //# sourceMappingURL=loadBatchLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadBatchLoader.js","sourceRoot":"","sources":["../../src/batchloaders/loadBatchLoader.ts"],"names":[],"mappings":";;;AAmBA,0CAwCC;AA3DD,8CAAgD;AAChD,oDAAmE;AAEnE,0CAA4C;AAC5C,gDAAmF;AACnF,kCAA6C;AAE7C,oCAAwC;AAG3B,QAAA,aAAa,GAAG,MAAM,CAAC;AAEpC;;;;;;GAMG;AACH,SAAgB,eAAe,CAC7B,EAAiB,EACjB,IAAoB,EACpB,oBAA6B,KAAK;IAElC,OAAO,EAAE,CAAC,cAAc,CAAC,qBAAa,EAAE,GAAG,IAAI,CAAC,IAAI,IAAI,iBAAiB,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;QAC3F,MAA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,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,CAAC,IAAI,EAAE,qBAAa,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QACrE,MAAM,QAAQ,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,iBAAiB,EAAE,CAAC,CAAC;QACpE,eAAe,IAAI,eAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACnD,4FAA4F;QAC5F,IAAI,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC;YACjC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,IAAA,YAAK,EAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAClE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;oBACjC,MAAM,cAAc,GAAG,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;oBAC9D,IAAI,cAAc,EAAE,CAAC;wBACnB,IAAA,4BAAe,EAAC,cAAc,CAAC,CAAC,0BAA0B,EAAE,CAAC;oBAC/D,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { EntityManager } from "../EntityManager";
2
+ import { ManyToManyLike } from "../index";
3
+ import { BatchLoader } from "./BatchLoader";
4
+ export declare const manyToManyLoadOperation = "m2m-load";
5
+ /** Batches m2m.packages/core/src/relations/ReactiveManyToMany.tsload calls via BatchLoader. */
6
+ export declare function manyToManyBatchLoader(em: EntityManager, collection: ManyToManyLike): BatchLoader<string>;
7
+ //# sourceMappingURL=manyToManyBatchLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manyToManyBatchLoader.d.ts","sourceRoot":"","sources":["../../src/batchloaders/manyToManyBatchLoader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAoB,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAA4B,cAAc,EAAmB,MAAM,UAAU,CAAC;AAErF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,eAAO,MAAM,uBAAuB,aAAa,CAAC;AAElD,+FAA+F;AAC/F,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,cAAc,GAAG,WAAW,CAAC,MAAM,CAAC,CAExG"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.manyToManyLoadOperation = void 0;
4
+ exports.manyToManyBatchLoader = manyToManyBatchLoader;
5
+ const EntityManager_1 = require("../EntityManager");
6
+ const index_1 = require("../index");
7
+ const utils_1 = require("../utils");
8
+ exports.manyToManyLoadOperation = "m2m-load";
9
+ /** Batches m2m.packages/core/src/relations/ReactiveManyToMany.tsload calls via BatchLoader. */
10
+ function manyToManyBatchLoader(em, collection) {
11
+ return em.getBatchLoader(exports.manyToManyLoadOperation, collection.joinTableName, (keys) => loadBatch(collection, keys));
12
+ }
13
+ async function loadBatch(collection, keys) {
14
+ const { em } = collection.entity;
15
+ const joinRows = (0, EntityManager_1.getEmInternalApi)(em).joinRows(collection);
16
+ // Break out `column_id=string` keys
17
+ const columns = {};
18
+ const tuples = [];
19
+ keys.forEach((key) => {
20
+ const [columnId, id] = key.split("=");
21
+ (0, utils_1.getOrSet)(columns, columnId, []).push(id);
22
+ tuples.push([columnId, id]);
23
+ });
24
+ const alias = (0, utils_1.abbreviation)(collection.joinTableName);
25
+ const query = {
26
+ selects: [`"${alias}".*`],
27
+ tables: [{ alias, join: "primary", table: collection.joinTableName }],
28
+ condition: {
29
+ kind: "exp",
30
+ op: "or",
31
+ conditions: Object.entries(columns).map(([columnId, values]) => {
32
+ const meta = collection.columnName == columnId ? (0, index_1.getMetadata)(collection.entity) : collection.otherMeta;
33
+ return {
34
+ kind: "column",
35
+ alias,
36
+ column: columnId,
37
+ dbType: meta.idDbType,
38
+ cond: { kind: "in", value: values.map((id) => (0, index_1.keyToNumber)(meta, id)) },
39
+ };
40
+ }),
41
+ },
42
+ orderBys: [{ alias, column: "id", order: "ASC" }],
43
+ };
44
+ const rows = await em["executeFind"](collection.otherMeta, exports.manyToManyLoadOperation, query, {});
45
+ await joinRows.loadRows(tuples, rows);
46
+ const api = (0, EntityManager_1.getEmInternalApi)(em);
47
+ for (const [column, id] of tuples) {
48
+ const entity = em.getEntity(id);
49
+ if (!entity)
50
+ continue;
51
+ const others = joinRows.getOthers(column, entity);
52
+ // Determine the field name from the column
53
+ const fieldName = column === collection.columnName ? collection.fieldName : collection.otherFieldName;
54
+ api.setPreloadedRelation(entity.idTagged, fieldName, others);
55
+ }
56
+ }
57
+ //# sourceMappingURL=manyToManyBatchLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manyToManyBatchLoader.js","sourceRoot":"","sources":["../../src/batchloaders/manyToManyBatchLoader.ts"],"names":[],"mappings":";;;AASA,sDAEC;AAVD,oDAAmE;AACnE,oCAAqF;AACrF,oCAAkD;AAGrC,QAAA,uBAAuB,GAAG,UAAU,CAAC;AAElD,+FAA+F;AAC/F,SAAgB,qBAAqB,CAAC,EAAiB,EAAE,UAA0B;IACjF,OAAO,EAAE,CAAC,cAAc,CAAC,+BAAuB,EAAE,UAAU,CAAC,aAAa,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC;AACrH,CAAC;AAED,KAAK,UAAU,SAAS,CAAmB,UAA0B,EAAE,IAAc;IACnF,MAAM,EAAE,EAAE,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC;IAEjC,MAAM,QAAQ,GAAG,IAAA,g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,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAA,mBAAW,EAAC,IAAI,EAAE,EAAE,CAAE,CAAC,EAAE;iBACxE,CAAC;YACJ,CAAC,CAAC;SACH;QACD,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;KAClD,CAAC;IAEF,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,CAAC,UAAU,CAAC,SAAS,EAAE,+BAAuB,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;IAC/F,MAAM,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAEtC,MAAM,GAAG,GAAG,IAAA,gCAAgB,EAAC,EAAE,CAAC,CAAC;IACjC,KAAK,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,MAAM,EAAE,CAAC;QAClC,MAAM,MAAM,GAAG,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QAChC,IAAI,CAAC,MAAM;YAAE,SAAS;QACtB,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAQ,CAAC;QACzD,2CAA2C;QAC3C,MAAM,SAAS,GAAG,MAAM,KAAK,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,cAAc,CAAC;QACtG,GAAG,CAAC,oBAAoB,CAAC,MAAM,CAAC,QAAS,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAChE,CAAC;AACH,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { Entity } from "../Entity";
2
+ import { EntityManager } from "../EntityManager";
3
+ import { OneToManyCollection } from "../index";
4
+ import { BatchLoader } from "./BatchLoader";
5
+ export declare const oneToManyLoadOperation = "o2m-load";
6
+ export declare function oneToManyBatchLoader<T extends Entity, U extends Entity>(em: EntityManager, collection: OneToManyCollection<T, U>): BatchLoader<string>;
7
+ //# sourceMappingURL=oneToManyBatchLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oneToManyBatchLoader.d.ts","sourceRoot":"","sources":["../../src/batchloaders/oneToManyBatchLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,aAAa,EAAoB,MAAM,kBAAkB,CAAC;AAEnE,OAAO,EAKL,mBAAmB,EAGpB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,eAAO,MAAM,sBAAsB,aAAa,CAAC;AAEjD,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EACrE,EAAE,EAAE,aAAa,EACjB,UAAU,EAAE,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,GACpC,WAAW,CAAC,MAAM,CAAC,CA8CrB"}
@@ -1,17 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.oneToManyLoadOperation = void 0;
4
- exports.oneToManyDataLoader = oneToManyDataLoader;
4
+ exports.oneToManyBatchLoader = oneToManyBatchLoader;
5
+ const EntityManager_1 = require("../EntityManager");
5
6
  const fields_1 = require("../fields");
6
7
  const index_1 = require("../index");
7
8
  const utils_1 = require("../utils");
8
9
  exports.oneToManyLoadOperation = "o2m-load";
9
- function oneToManyDataLoader(em, collection) {
10
- // The metadata for the entity that contains the collection, i.e. Author in author.books
10
+ function oneToManyBatchLoader(em, collection) {
11
11
  const { meta: oneMeta, fieldName } = collection;
12
12
  const batchKey = `${oneMeta.tableName}-${fieldName}`;
13
- return em.getLoader(exports.oneToManyLoadOperation, batchKey, async (_keys) => {
14
- // otherMeta is the entity being fetched, i.e. Book in author.books
13
+ return em.getBatchLoader(exports.oneToManyLoadOperation, batchKey, async (_keys) => {
15
14
  const { otherMeta: meta } = collection;
16
15
  (0, index_1.assertIdsAreTagged)(_keys);
17
16
  const keys = (0, index_1.deTagIds)(oneMeta, _keys);
@@ -37,24 +36,16 @@ function oneToManyDataLoader(em, collection) {
37
36
  orderBys: [{ alias, column: "id", order: "ASC" }],
38
37
  };
39
38
  (0, index_1.addTablePerClassJoinsAndClassTag)(query, meta, alias, true);
40
- // Skip maybeAddOrderBy b/c we'll sort in memory anyway
41
- // maybeAddNotSoftDeleted(conditions, meta, alias, "include");
42
39
  const rows = await em["executeFind"](meta, exports.oneToManyLoadOperation, query, {});
43
40
  const entities = em.hydrate(meta.cstr, rows);
44
- // .filter((e) => !e.isDeletedEntity);
45
41
  const entitiesById = (0, utils_1.groupBy)(entities, (entity) => {
46
- // TODO If this came from the UoW, it may not be an id? I.e. pre-insert.
47
42
  const ownerId = (0, index_1.maybeResolveReferenceToId)((0, fields_1.getField)(entity, collection.otherFieldName));
48
- // We almost always expect ownerId to be found, b/c normally we just hydrated this entity
49
- // directly from a SQL row with owner_id=X, however we might be loading this collection
50
- // (i.e. find all children where owner_id=X) when the SQL thinks a child is still pointing
51
- // at the parent (i.e. owner_id=X in the db), but our already-loaded child has had its
52
- // `child.owner` field either changed to some other owner, or set to undefined. In either,
53
- // that child should no longer be parent of this owner's collection, so just return a
54
- // dummy value.
55
43
  return ownerId ?? "dummyNoLongerOwned";
56
44
  });
57
- return _keys.map((k) => entitiesById.get(k) || []);
45
+ const api = (0, EntityManager_1.getEmInternalApi)(em);
46
+ for (const key of _keys) {
47
+ api.setPreloadedRelation(key, fieldName, entitiesById.get(key) || []);
48
+ }
58
49
  });
59
50
  }
60
- //# sourceMappingURL=oneToManyDataLoader.js.map
51
+ //# sourceMappingURL=oneToManyBatchLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oneToManyBatchLoader.js","sourceRoot":"","sources":["../../src/batchloaders/oneToManyBatchLoader.ts"],"names":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B,MAAM,EAAE,IAAI,CAAC,QAAQ;wBACrB,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;qBAClC;iBACF;aACF;YACD,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;SAClD,CAAC;QAEF,IAAA,wCAAgC,EAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QAE3D,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,CAAC,IAAI,EAAE,8BAAsB,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QAC9E,MAAM,QAAQ,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAE7C,MAAM,YAAY,GAAG,IAAA,eAAO,EAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE;YAChD,MAAM,OAAO,GAAG,IAAA,iCAAyB,EAAC,IAAA,iBAAQ,EAAC,MAAM,EAAE,UAAU,CAAC,cAAc,CAAC,CAAC,CAAC;YACvF,OAAO,OAAO,IAAI,oBAAoB,CAAC;QACzC,CAAC,CAAC,CAAC;QAEH,MAAM,GAAG,GAAG,IAAA,gCAAgB,EAAC,EAAE,CAAC,CAAC;QACjC,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;YACxB,GAAG,CAAC,oBAAoB,CAAC,GAAG,EAAE,SAAS,EAAE,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;QACxE,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { Entity } from "../Entity";
2
+ import { EntityManager } from "../EntityManager";
3
+ import { OneToOneReferenceImpl } from "../relations/OneToOneReference";
4
+ import { BatchLoader } from "./BatchLoader";
5
+ export declare const oneToOneLoadOperation = "o2o-load";
6
+ export declare function oneToOneBatchLoader<T extends Entity, U extends Entity>(em: EntityManager, reference: OneToOneReferenceImpl<T, U>): BatchLoader<string>;
7
+ //# sourceMappingURL=oneToOneBatchLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oneToOneBatchLoader.d.ts","sourceRoot":"","sources":["../../src/batchloaders/oneToOneBatchLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,aAAa,EAAoB,MAAM,kBAAkB,CAAC;AAUnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAEvE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,eAAO,MAAM,qBAAqB,aAAa,CAAC;AAEhD,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EACpE,EAAE,EAAE,aAAa,EACjB,SAAS,EAAE,qBAAqB,CAAC,CAAC,EAAE,CAAC,CAAC,GACrC,WAAW,CAAC,MAAM,CAAC,CA8CrB"}
@@ -1,18 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.oneToOneLoadOperation = void 0;
4
- exports.oneToOneDataLoader = oneToOneDataLoader;
4
+ exports.oneToOneBatchLoader = oneToOneBatchLoader;
5
+ const EntityManager_1 = require("../EntityManager");
5
6
  const EntityMetadata_1 = require("../EntityMetadata");
6
7
  const fields_1 = require("../fields");
7
8
  const index_1 = require("../index");
8
9
  const utils_1 = require("../utils");
9
10
  exports.oneToOneLoadOperation = "o2o-load";
10
- function oneToOneDataLoader(em, reference) {
11
- // The metadata for the entity that contains the reference, i.e. Author.image is the o2o,
12
- // and (otherMeta/otherFieldName) Image.author is the physical m2o/FK column.
11
+ function oneToOneBatchLoader(em, reference) {
13
12
  const meta = (0, EntityMetadata_1.getMetadata)(reference.entity);
14
13
  const batchKey = `${meta.tableName}-${reference.fieldName}`;
15
- return em.getLoader(exports.oneToOneLoadOperation, batchKey, async (_keys) => {
14
+ return em.getBatchLoader(exports.oneToOneLoadOperation, batchKey, async (_keys) => {
16
15
  const { otherMeta, otherFieldName } = reference;
17
16
  (0, index_1.assertIdsAreTagged)(_keys);
18
17
  const keys = (0, index_1.deTagIds)(meta, _keys);
@@ -38,22 +37,17 @@ function oneToOneDataLoader(em, reference) {
38
37
  orderBys: [],
39
38
  };
40
39
  (0, index_1.addTablePerClassJoinsAndClassTag)(query, otherMeta, alias, true);
41
- const { em } = reference.entity;
42
40
  const rows = await em["executeFind"](otherMeta, exports.oneToOneLoadOperation, query, {});
43
41
  const entities = em.hydrate(otherMeta.cstr, rows);
44
42
  const entitiesByOtherId = (0, utils_1.groupBy)(entities, (entity) => {
45
- // TODO If this came from the UoW, it may not be an id? I.e. pre-insert.
46
43
  const ownerId = (0, index_1.maybeResolveReferenceToId)((0, fields_1.getField)(entity, otherFieldName));
47
- // We almost always expect ownerId to be found, b/c normally we just hydrated this entity
48
- // directly from a SQL row with owner_id=X, however we might be loading this reference
49
- // (i.e. find all children where owner_id=X) when the SQL thinks a child is still pointing
50
- // at the parent (i.e. owner_id=X in the db), but our already-loaded child has had its
51
- // `child.owner` field either changed to some other owner, or set to undefined. In either,
52
- // that child should no longer be parent of this owner's collection, so just return a
53
- // dummy value.
54
44
  return ownerId ?? "dummyNoLongerOwned";
55
45
  });
56
- return _keys.map((k) => entitiesByOtherId.get(k)?.[0]);
46
+ const api = (0, EntityManager_1.getEmInternalApi)(em);
47
+ for (const key of _keys) {
48
+ const found = entitiesByOtherId.get(key);
49
+ api.setPreloadedRelation(key, reference.fieldName, found ? [found[0]] : []);
50
+ }
57
51
  });
58
52
  }
59
- //# sourceMappingURL=oneToOneDataLoader.js.map
53
+ //# sourceMappingURL=oneToOneBatchLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oneToOneBatchLoader.js","sourceRoot":"","sources":["../../src/batchloaders/oneToOneBatchLoader.ts"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MAAM,EAAE,GAAG,CAAC,eAAe;wBAC3B,MAAM,EAAE,IAAI,CAAC,QAAQ;wBACrB,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;qBAClC;iBACF;aACF;YACD,QAAQ,EAAE,EAAE;SACb,CAAC;QACF,IAAA,wCAAgC,EAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QAEhE,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,CAAC,SAAS,EAAE,6BAAqB,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QAClF,MAAM,QAAQ,GAAG,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAElD,MAAM,iBAAiB,GAAG,IAAA,eAAO,EAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE;YACrD,MAAM,OAAO,GAAG,IAAA,iCAAyB,EAAC,IAAA,iBAAQ,EAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;YAC5E,OAAO,OAAO,IAAI,oBAAoB,CAAC;QACzC,CAAC,CAAC,CAAC;QAEH,MAAM,GAAG,GAAG,IAAA,gCAAgB,EAAC,EAAE,CAAC,CAAC;QACjC,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;YACxB,MAAM,KAAK,GAAG,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACzC,GAAG,CAAC,oBAAoB,CAAC,GAAG,EAAE,SAAS,CAAC,SAAmB,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACxF,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,13 +1,13 @@
1
- import DataLoader from "dataloader";
2
1
  import { Entity } from "../Entity";
3
2
  import { EntityMetadata } from "../EntityMetadata";
4
3
  import { EntityManager } from "../index";
5
4
  import { LoadHint } from "../loadHints";
5
+ import { BatchLoader } from "./BatchLoader";
6
6
  export declare const populateOperation = "populate";
7
- export declare function populateDataLoader(em: EntityManager, meta: EntityMetadata, hint: LoadHint<any>, mode: "preload" | "intermixed", opts?: {
7
+ export declare function populateBatchLoader(em: EntityManager, meta: EntityMetadata, hint: LoadHint<any>, mode: "preload" | "intermixed", opts?: {
8
8
  forceReload?: boolean;
9
- }): DataLoader<{
9
+ }): BatchLoader<{
10
10
  entity: Entity;
11
11
  hint: LoadHint<any>;
12
- }, any>;
13
- //# sourceMappingURL=populateDataLoader.d.ts.map
12
+ }>;
13
+ //# sourceMappingURL=populateBatchLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"populateBatchLoader.d.ts","sourceRoot":"","sources":["../../src/batchloaders/populateBatchLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAEL,aAAa,EAOd,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAIxC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAM5C,eAAO,MAAM,iBAAiB,aAAa,CAAC;AAE5C,wBAAgB,mBAAmB,CACjC,EAAE,EAAE,aAAa,EACjB,IAAI,EAAE,cAAc,EACpB,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,EACnB,IAAI,EAAE,SAAS,GAAG,YAAY,EAC9B,IAAI,GAAE;IAAE,WAAW,CAAC,EAAE,OAAO,CAAA;CAAO,GACnC,WAAW,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAA;CAAE,CAAC,CA2KtD"}
@@ -1,14 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.populateOperation = void 0;
4
- exports.populateDataLoader = populateDataLoader;
4
+ exports.populateBatchLoader = populateBatchLoader;
5
5
  const HintTree_1 = require("../HintTree");
6
6
  const index_1 = require("../index");
7
7
  const reactiveHints_1 = require("../reactiveHints");
8
8
  const ReactiveField_1 = require("../relations/ReactiveField");
9
9
  const utils_1 = require("../utils");
10
+ const loadBatchLoader_1 = require("./loadBatchLoader");
11
+ const manyToManyBatchLoader_1 = require("./manyToManyBatchLoader");
12
+ const oneToManyBatchLoader_1 = require("./oneToManyBatchLoader");
13
+ const oneToOneBatchLoader_1 = require("./oneToOneBatchLoader");
10
14
  exports.populateOperation = "populate";
11
- function populateDataLoader(em, meta, hint, mode, opts = {}) {
15
+ function populateBatchLoader(em, meta, hint, mode, opts = {}) {
12
16
  // For batching populates, we want different levels of course-ness:
13
17
  // - preloading populates that are only SQL should be batched together as much as possible, but
14
18
  // - intermixed populates (some with custom relations) should be batched as separately as possible
@@ -24,7 +28,7 @@ function populateDataLoader(em, meta, hint, mode, opts = {}) {
24
28
  const batchKey = mode === "preload"
25
29
  ? `${meta.tagName}:${opts.forceReload}`
26
30
  : `${meta.tagName}:${JSON.stringify(hint)}:${opts.forceReload}`;
27
- return em.getLoader(exports.populateOperation, batchKey, async (populates) => {
31
+ return em.getBatchLoader(exports.populateOperation, batchKey, async (populates) => {
28
32
  async function populateLayer(layerMeta, layerNode) {
29
33
  // Skip join-based preloading if nothing in this layer needs loading. If any entity in the list
30
34
  // needs loading, just load everything
@@ -32,7 +36,11 @@ function populateDataLoader(em, meta, hint, mode, opts = {}) {
32
36
  // We may not have a layerMeta if we're going through non-field properties
33
37
  if (preloader && layerMeta) {
34
38
  const preloadThisLayer = Object.entries(layerNode.hints).some(([key, hint]) => {
35
- return [...hint.entities].some((entity) => !!entity[key] && !entity[key].isLoaded && !entity[key].isPreloaded);
39
+ for (const entity of hint.entities) {
40
+ if (entity[key]?.isLoaded === false && !entity[key]?.isPreloaded)
41
+ return true;
42
+ }
43
+ return false;
36
44
  });
37
45
  if (preloadThisLayer) {
38
46
  // Do an up-front SQL call of `select id, ...preloads... from table`,
@@ -67,16 +75,20 @@ function populateDataLoader(em, meta, hint, mode, opts = {}) {
67
75
  }
68
76
  }
69
77
  }
70
- // One breadth-width pass (only 1 level deep, our 2nd pass recurses) to ensure each relation is loaded
71
- const loadPromises = Object.entries(layerNode.hints).flatMap(([key, tree]) => {
72
- return [...tree.entities].map((entity) => {
78
+ // First pass: batch SQL relations directly, fall back to relation.load() for non-SQL
79
+ const batchPromises = new Set();
80
+ const relationsToPreload = [];
81
+ const fallbackPromises = [];
82
+ for (const [key, tree] of Object.entries(layerNode.hints)) {
83
+ const field = layerMeta?.allFields[key];
84
+ for (const entity of tree.entities) {
73
85
  const relation = (0, reactiveHints_1.getRelationFromMaybePolyKey)(entity, key);
74
86
  // This happens to let through non-relation hints like 'name' on user, which wasn't intentional,
75
- // but currently doesn't blow up (somehow), and is not depended on by internal tests.
87
+ // but currently doesn't blow up (somehow), and is depended on by internal tests.
76
88
  if (!relation || typeof relation.load !== "function") {
77
89
  // We don't want to throw on poly hints, because they're not actually loaded on the entity
78
90
  if ((0, reactiveHints_1.isPolyHint)(key))
79
- return;
91
+ continue;
80
92
  throw new Error(`Invalid load hint '${key}' on ${entity}`);
81
93
  }
82
94
  // If we're populating a hasReactiveField, don't bother loading it
@@ -88,61 +100,92 @@ function populateDataLoader(em, meta, hint, mode, opts = {}) {
88
100
  // So we go ahead and call `.load()`, assuming it will just load its cached value, but it
89
101
  // will also check internally if it's marked for recalc, and load its load hint if necessary.
90
102
  if (relation instanceof ReactiveField_1.ReactiveFieldImpl && relation.isSet)
91
- return;
103
+ continue;
92
104
  if (relation.isLoaded && !opts.forceReload)
93
- return undefined;
94
- // Avoid creating a promise for preloaded relations
105
+ continue;
95
106
  if (relation.isPreloaded) {
96
107
  relation.preload();
97
- return undefined;
108
+ continue;
98
109
  }
99
- return relation.load(opts);
100
- });
101
- });
110
+ // For non-derived SQL relations on existing entities, use batch loaders directly
111
+ // (1 shared promise per batch instead of per-entity async overhead).
112
+ // Skip new entities (no id) and derived relations (reactive m2m/m2o have extra logic in load).
113
+ if (!entity.isNewEntity && field) {
114
+ if (field.kind === "o2m") {
115
+ batchPromises.add((0, oneToManyBatchLoader_1.oneToManyBatchLoader)(em, relation).load(entity.idTagged));
116
+ relationsToPreload.push(relation);
117
+ continue;
118
+ }
119
+ else if (field.kind === "m2m" && !field.derived) {
120
+ batchPromises.add((0, manyToManyBatchLoader_1.manyToManyBatchLoader)(em, relation).load(`${relation.columnName}=${entity.id}`));
121
+ relationsToPreload.push(relation);
122
+ continue;
123
+ }
124
+ else if (field.kind === "o2o") {
125
+ batchPromises.add((0, oneToOneBatchLoader_1.oneToOneBatchLoader)(em, relation).load(entity.idTagged));
126
+ relationsToPreload.push(relation);
127
+ continue;
128
+ }
129
+ else if (field.kind === "m2o" && !field.derived) {
130
+ const taggedId = relation.idTaggedMaybe;
131
+ if (taggedId) {
132
+ batchPromises.add((0, loadBatchLoader_1.loadBatchLoader)(em, field.otherMetadata()).load({ taggedId, hint: undefined }));
133
+ relationsToPreload.push(relation);
134
+ continue;
135
+ }
136
+ }
137
+ }
138
+ fallbackPromises.push(relation.load(opts));
139
+ }
140
+ }
141
+ if (batchPromises.size > 0 || fallbackPromises.length > 0) {
142
+ await Promise.all([...batchPromises, ...fallbackPromises]);
143
+ }
144
+ for (const relation of relationsToPreload) {
145
+ relation.preload();
146
+ }
102
147
  // 2nd breadth-width pass to do nested load hints, this will fan out at the sibling level.
103
148
  // i.e. populateLayer(...reviews...) & populateLayer(...comments...)
104
- return Promise.all(loadPromises).then(() => {
105
- // Each of these keys will be fanning out to a new entity, like book -> reviews or book -> comments
106
- const nestedLoadPromises = Object.entries(layerNode.hints).map(([key, tree]) => {
107
- if (Object.keys(tree.hints).length === 0)
108
- return;
109
- // Get the children we found, i.e. [a1, a2, a3] -> all of their books
110
- const childrenByParent = new Map([...tree.entities].map((entity) => {
111
- const relation = (0, reactiveHints_1.getRelationFromMaybePolyKey)(entity, key);
112
- return [entity, relation ? (0, utils_1.toArray)(getEvenDeleted(relation)) : []];
113
- }));
114
- if (childrenByParent.size === 0)
115
- return;
116
- // Rewrite our node.entities to be the next layer of children, i.e. children will be all books, for all of
117
- // `[a1, a2, a3]`, but only the books of `a2` need to recurse into `book: reviews` and only the books of
118
- // `a3` need to recurse into `book: comments`, so swap `node.entities` (which is currently authors)
119
- // with the books. This is what prevents our dataloader-merged TreeHint from over-fetching and loading
120
- // the superset load hint for all entities.
121
- function rewrite(node) {
122
- node.entities = new Set(Array.from(node.entities).flatMap((entity) => childrenByParent.get(entity) ?? []));
123
- Object.values(node.hints).forEach((node) => rewrite(node));
149
+ let nestedLoadPromises;
150
+ for (const [key, tree] of Object.entries(layerNode.hints)) {
151
+ if (Object.keys(tree.hints).length === 0)
152
+ continue;
153
+ // Get the children we found, i.e. [a1, a2, a3] -> all of their books
154
+ const childrenByParent = new Map();
155
+ for (const entity of tree.entities) {
156
+ const relation = (0, reactiveHints_1.getRelationFromMaybePolyKey)(entity, key);
157
+ childrenByParent.set(entity, relation ? (0, utils_1.toArray)(getEvenDeleted(relation)) : []);
158
+ }
159
+ if (childrenByParent.size === 0)
160
+ continue;
161
+ // Rewrite our node.entities to be the next layer of children, i.e. children will be all books, for all of
162
+ // `[a1, a2, a3]`, but only the books of `a2` need to recurse into `book: reviews` and only the books of
163
+ // `a3` need to recurse into `book: comments`, so swap `node.entities` (which is currently authors)
164
+ // with the books. This is what prevents our dataloader-merged TreeHint from over-fetching and loading
165
+ // the superset load hint for all entities.
166
+ function rewrite(node) {
167
+ const next = new Set();
168
+ for (const entity of node.entities) {
169
+ const children = childrenByParent.get(entity);
170
+ if (children)
171
+ for (const child of children)
172
+ next.add(child);
124
173
  }
125
- rewrite(tree);
126
- const nextMeta = layerMeta?.allFields[key]?.otherMetadata?.();
127
- return populateLayer(nextMeta, tree);
128
- });
129
- return Promise.all(nestedLoadPromises);
130
- });
174
+ node.entities = next;
175
+ Object.values(node.hints).forEach((node) => rewrite(node));
176
+ }
177
+ rewrite(tree);
178
+ const nextMeta = layerMeta?.allFields[key]?.otherMetadata?.();
179
+ (nestedLoadPromises ??= []).push(populateLayer(nextMeta, tree));
180
+ }
181
+ if (nestedLoadPromises)
182
+ await Promise.all(nestedLoadPromises);
131
183
  }
132
- return populateLayer(meta, (0, HintTree_1.buildHintTree)(populates)).then(() => populates);
133
- },
134
- // We always disable caching, because during a UoW, having called `populate(author, nestedHint1)`
135
- // once doesn't mean that, on the 2nd call to `populate(author, nestedHint1)`, we can completely
136
- // skip it b/c author's relations may have been changed/mutated to different not-yet-loaded
137
- // entities.
138
- //
139
- // Even though having `{ cache: false }` looks weird here, i.e. why use dataloader at all?, it
140
- // still helps us fan-in resolvers callers that are happening ~simultaneously into the same
141
- // effort.
142
- { cache: false });
184
+ await populateLayer(meta, (0, HintTree_1.buildHintTree)(populates));
185
+ });
143
186
  }
144
187
  /** Probes `relation` to see if it's a m2o/o2m/m2m relation that supports `getWithDeleted`, otherwise calls `get`. */
145
188
  function getEvenDeleted(relation) {
146
189
  return "getWithDeleted" in relation ? relation.getWithDeleted : relation.get;
147
190
  }
148
- //# sourceMappingURL=populateDataLoader.js.map
191
+ //# sourceMappingURL=populateBatchLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"populateBatchLoader.js","sourceRoot":"","sources":["../../src/batchloaders/populateBatchLoader.ts"],"names":[],"mappings":";;;AAyBA,kDAiLC;AAxMD,0CAAsD;AACtD,oCASkB;AAElB,oDAA2E;AAC3E,8DAA+D;AAC/D,oCAAmC;AAEnC,uDAAoD;AACpD,mEAAgE;AAChE,iEAA8D;AAC9D,+DAA4D;AAE/C,QAAA,iBAAiB,GAAG,UAAU,CAAC;AAE5C,SAAgB,mBAAmB,CACjC,EAAiB,EACjB,IAAoB,EACpB,IAAmB,EACnB,IAA8B,EAC9B,OAAkC,EAAE;IAEpC,mEAAmE;IACnE,+FAA+F;IAC/F,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,EAAE,IAAI,CAAC,CAAC,CAAC;YAClE,CAAC;YACD,IAAI,kBAAkB;gBAAE,MAAM,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;QAChE,CAAC;QAED,MAAM,aAAa,CAAC,IAAI,EAAE,IAAA,wBAAa,EAAC,SAAS,CAAC,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;AACL,CAAC;AAED,qHAAqH;AACrH,SAAS,cAAc,CAAC,QAAa;IACnC,OAAO,gBAAgB,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { Entity } from "../Entity";
2
+ import { EntityManager } from "../EntityManager";
3
+ import { RecursiveChildrenCollectionImpl } from "../relations/RecursiveCollection";
4
+ import { BatchLoader } from "./BatchLoader";
5
+ export declare const recursiveChildrenOperation = "o2m-recursive";
6
+ export declare function recursiveChildrenBatchLoader<T extends Entity, U extends Entity>(em: EntityManager, collection: RecursiveChildrenCollectionImpl<T, U>): BatchLoader<Entity>;
7
+ //# sourceMappingURL=recursiveChildrenBatchLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recursiveChildrenBatchLoader.d.ts","sourceRoot":"","sources":["../../src/batchloaders/recursiveChildrenBatchLoader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,aAAa,EAAoB,MAAM,kBAAkB,CAAC;AAcnE,OAAO,EAAE,+BAA+B,EAAE,MAAM,kCAAkC,CAAC;AAEnF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,eAAO,MAAM,0BAA0B,kBAAkB,CAAC;AAE1D,wBAAgB,4BAA4B,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAC7E,EAAE,EAAE,aAAa,EACjB,UAAU,EAAE,+BAA+B,CAAC,CAAC,EAAE,CAAC,CAAC,GAChD,WAAW,CAAC,MAAM,CAAC,CAqErB"}
@@ -1,20 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.recursiveChildrenOperation = void 0;
4
- exports.recursiveChildrenDataLoader = recursiveChildrenDataLoader;
4
+ exports.recursiveChildrenBatchLoader = recursiveChildrenBatchLoader;
5
5
  const configure_1 = require("../configure");
6
6
  const EntityManager_1 = require("../EntityManager");
7
7
  const index_1 = require("../index");
8
8
  const utils_1 = require("../utils");
9
9
  exports.recursiveChildrenOperation = "o2m-recursive";
10
- function recursiveChildrenDataLoader(em, collection) {
10
+ function recursiveChildrenBatchLoader(em, collection) {
11
11
  let { meta, fieldName } = collection;
12
12
  // This could be called from subtypes to get relations defined on the parent. So we need to make sure we are using the
13
13
  // correct meta by walking the inheritance tree until we find the meta that actually has the root o2m field
14
14
  while (!(collection.o2mFieldName in meta.fields) && meta.baseType)
15
15
  meta = (0, configure_1.getMetadataForType)(meta.baseType);
16
16
  const batchKey = `${meta.tableName}-${fieldName}`;
17
- return em.getLoader(exports.recursiveChildrenOperation, batchKey, async (parents) => {
17
+ return em.getBatchLoader(exports.recursiveChildrenOperation, batchKey, async (parents) => {
18
18
  const o2m = meta.allFields[collection.o2mFieldName];
19
19
  const m2o = meta.allFields[o2m.otherFieldName];
20
20
  const { columnName } = m2o.serde.columns[0];
@@ -70,8 +70,6 @@ function recursiveChildrenDataLoader(em, collection) {
70
70
  entity[o2m.fieldName].preload();
71
71
  }
72
72
  }
73
- // We used preloading to load keys + any recursive keys, so the return value doesn't matter
74
- return parents.map(() => []);
75
73
  });
76
74
  }
77
- //# sourceMappingURL=recursiveChildrenDataLoader.js.map
75
+ //# sourceMappingURL=recursiveChildrenBatchLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recursiveChildrenBatchLoader.js","sourceRoot":"","sources":["../../src/batchloaders/recursiveChildrenBatchLoader.ts"],"names":[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YAC5E,OAAO,QAAQ,IAAI,MAAM,CAAC;QAC5B,CAAC,CAAC,CAAC;QAEH,2FAA2F;QAC3F,KAAK,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,YAAY,EAAE,CAAC;YAChD,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;gBACxB,IAAA,gCAAgB,EAAC,EAAE,CAAC,CAAC,oBAAoB,CAAC,QAAQ,EAAE,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;gBAC7E,kGAAkG;gBACjG,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC;YAC3D,CAAC;QACH,CAAC;QAED,iHAAiH;QACjH,KAAK,MAAM,MAAM,IAAI,CAAC,GAAG,OAAO,EAAE,GAAG,QAAQ,CAAC,EAAE,CAAC;YAC/C,IAAI,CAAC,IAAA,0BAAkB,EAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAA,iCAAyB,EAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;gBACpG,IAAA,gCAAgB,EAAC,EAAE,CAAC,CAAC,oBAAoB,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;gBACxE,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC;YAClC,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { Entity } from "../Entity";
2
+ import { EntityManager } from "../EntityManager";
3
+ import { RecursiveParentsCollectionImpl } from "../relations/RecursiveCollection";
4
+ import { BatchLoader } from "./BatchLoader";
5
+ export declare const recursiveParentsOperation = "m2o-recursive";
6
+ export declare function recursiveParentsBatchLoader<T extends Entity, U extends Entity>(em: EntityManager, collection: RecursiveParentsCollectionImpl<T, U>): BatchLoader<Entity>;
7
+ //# sourceMappingURL=recursiveParentsBatchLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recursiveParentsBatchLoader.d.ts","sourceRoot":"","sources":["../../src/batchloaders/recursiveParentsBatchLoader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AASjD,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAElF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,eAAO,MAAM,yBAAyB,kBAAkB,CAAC;AAEzD,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAC5E,EAAE,EAAE,aAAa,EACjB,UAAU,EAAE,8BAA8B,CAAC,CAAC,EAAE,CAAC,CAAC,GAC/C,WAAW,CAAC,MAAM,CAAC,CAmDrB"}