@loopback/repository 4.1.0 → 5.0.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.
Files changed (149) hide show
  1. package/dist/connectors/index.js +3 -3
  2. package/dist/connectors/index.js.map +1 -1
  3. package/dist/decorators/index.js +3 -3
  4. package/dist/decorators/index.js.map +1 -1
  5. package/dist/decorators/repository.decorator.js +1 -1
  6. package/dist/decorators/repository.decorator.js.map +1 -1
  7. package/dist/define-model-class.js +1 -1
  8. package/dist/define-model-class.js.map +1 -1
  9. package/dist/define-repository-class.js +1 -1
  10. package/dist/define-repository-class.js.map +1 -1
  11. package/dist/errors/index.d.ts +1 -0
  12. package/dist/errors/index.js +3 -2
  13. package/dist/errors/index.js.map +1 -1
  14. package/dist/errors/invalid-polymorphism.error.d.ts +5 -0
  15. package/dist/errors/invalid-polymorphism.error.js +22 -0
  16. package/dist/errors/invalid-polymorphism.error.js.map +1 -0
  17. package/dist/index.js +16 -16
  18. package/dist/index.js.map +1 -1
  19. package/dist/mixins/index.js +1 -1
  20. package/dist/mixins/index.js.map +1 -1
  21. package/dist/mixins/repository.mixin.js +1 -1
  22. package/dist/mixins/repository.mixin.js.map +1 -1
  23. package/dist/model.d.ts +7 -1
  24. package/dist/model.js +14 -0
  25. package/dist/model.js.map +1 -1
  26. package/dist/relations/belongs-to/belongs-to.accessor.d.ts +6 -2
  27. package/dist/relations/belongs-to/belongs-to.accessor.js +19 -6
  28. package/dist/relations/belongs-to/belongs-to.accessor.js.map +1 -1
  29. package/dist/relations/belongs-to/belongs-to.helpers.d.ts +3 -0
  30. package/dist/relations/belongs-to/belongs-to.helpers.js +33 -9
  31. package/dist/relations/belongs-to/belongs-to.helpers.js.map +1 -1
  32. package/dist/relations/belongs-to/belongs-to.inclusion-resolver.d.ts +5 -2
  33. package/dist/relations/belongs-to/belongs-to.inclusion-resolver.js +81 -8
  34. package/dist/relations/belongs-to/belongs-to.inclusion-resolver.js.map +1 -1
  35. package/dist/relations/belongs-to/belongs-to.repository.d.ts +28 -5
  36. package/dist/relations/belongs-to/belongs-to.repository.js +49 -10
  37. package/dist/relations/belongs-to/belongs-to.repository.js.map +1 -1
  38. package/dist/relations/belongs-to/index.js +4 -4
  39. package/dist/relations/belongs-to/index.js.map +1 -1
  40. package/dist/relations/has-many/has-many-through.helpers.d.ts +3 -0
  41. package/dist/relations/has-many/has-many-through.helpers.js +26 -2
  42. package/dist/relations/has-many/has-many-through.helpers.js.map +1 -1
  43. package/dist/relations/has-many/has-many-through.inclusion-resolver.d.ts +3 -1
  44. package/dist/relations/has-many/has-many-through.inclusion-resolver.js +93 -22
  45. package/dist/relations/has-many/has-many-through.inclusion-resolver.js.map +1 -1
  46. package/dist/relations/has-many/has-many-through.repository-factory.d.ts +3 -1
  47. package/dist/relations/has-many/has-many-through.repository-factory.js +7 -1
  48. package/dist/relations/has-many/has-many-through.repository-factory.js.map +1 -1
  49. package/dist/relations/has-many/has-many-through.repository.d.ts +66 -11
  50. package/dist/relations/has-many/has-many-through.repository.js +211 -35
  51. package/dist/relations/has-many/has-many-through.repository.js.map +1 -1
  52. package/dist/relations/has-many/has-many.helpers.js +1 -1
  53. package/dist/relations/has-many/has-many.helpers.js.map +1 -1
  54. package/dist/relations/has-many/has-many.inclusion-resolver.js +1 -1
  55. package/dist/relations/has-many/has-many.inclusion-resolver.js.map +1 -1
  56. package/dist/relations/has-many/has-many.repository-factory.js +1 -1
  57. package/dist/relations/has-many/has-many.repository-factory.js.map +1 -1
  58. package/dist/relations/has-many/index.js +6 -6
  59. package/dist/relations/has-many/index.js.map +1 -1
  60. package/dist/relations/has-one/has-one.helpers.d.ts +3 -0
  61. package/dist/relations/has-one/has-one.helpers.js +35 -9
  62. package/dist/relations/has-one/has-one.helpers.js.map +1 -1
  63. package/dist/relations/has-one/has-one.inclusion-resolver.d.ts +6 -3
  64. package/dist/relations/has-one/has-one.inclusion-resolver.js +82 -7
  65. package/dist/relations/has-one/has-one.inclusion-resolver.js.map +1 -1
  66. package/dist/relations/has-one/has-one.repository-factory.d.ts +9 -3
  67. package/dist/relations/has-one/has-one.repository-factory.js +14 -4
  68. package/dist/relations/has-one/has-one.repository-factory.js.map +1 -1
  69. package/dist/relations/has-one/has-one.repository.d.ts +58 -11
  70. package/dist/relations/has-one/has-one.repository.js +118 -15
  71. package/dist/relations/has-one/has-one.repository.js.map +1 -1
  72. package/dist/relations/has-one/index.js +3 -3
  73. package/dist/relations/has-one/index.js.map +1 -1
  74. package/dist/relations/index.d.ts +2 -0
  75. package/dist/relations/index.js +8 -6
  76. package/dist/relations/index.js.map +1 -1
  77. package/dist/relations/references-many/index.d.ts +4 -0
  78. package/dist/relations/references-many/index.js +12 -0
  79. package/dist/relations/references-many/index.js.map +1 -0
  80. package/dist/relations/references-many/references-many.accessor.d.ts +17 -0
  81. package/dist/relations/references-many/references-many.accessor.js +40 -0
  82. package/dist/relations/references-many/references-many.accessor.js.map +1 -0
  83. package/dist/relations/references-many/references-many.decorator.d.ts +11 -0
  84. package/dist/relations/references-many/references-many.decorator.js +73 -0
  85. package/dist/relations/references-many/references-many.decorator.js.map +1 -0
  86. package/dist/relations/references-many/references-many.helpers.d.ts +17 -0
  87. package/dist/relations/references-many/references-many.helpers.js +63 -0
  88. package/dist/relations/references-many/references-many.helpers.js.map +1 -0
  89. package/dist/relations/references-many/references-many.inclusion-resolver.d.ts +14 -0
  90. package/dist/relations/references-many/references-many.inclusion-resolver.js +42 -0
  91. package/dist/relations/references-many/references-many.inclusion-resolver.js.map +1 -0
  92. package/dist/relations/references-many/references-many.repository.d.ts +28 -0
  93. package/dist/relations/references-many/references-many.repository.js +33 -0
  94. package/dist/relations/references-many/references-many.repository.js.map +1 -0
  95. package/dist/relations/relation.decorator.d.ts +0 -6
  96. package/dist/relations/relation.decorator.js +1 -13
  97. package/dist/relations/relation.decorator.js.map +1 -1
  98. package/dist/relations/relation.filter.solver.d.ts +2 -0
  99. package/dist/relations/relation.filter.solver.js +57 -0
  100. package/dist/relations/relation.filter.solver.js.map +1 -0
  101. package/dist/relations/relation.helpers.js +19 -4
  102. package/dist/relations/relation.helpers.js.map +1 -1
  103. package/dist/relations/relation.types.d.ts +52 -1
  104. package/dist/relations/relation.types.js.map +1 -1
  105. package/dist/repositories/index.js +5 -5
  106. package/dist/repositories/index.js.map +1 -1
  107. package/dist/repositories/legacy-juggler-bridge.d.ts +35 -8
  108. package/dist/repositories/legacy-juggler-bridge.js +38 -16
  109. package/dist/repositories/legacy-juggler-bridge.js.map +1 -1
  110. package/dist/types/array.js +1 -1
  111. package/dist/types/array.js.map +1 -1
  112. package/dist/types/buffer.js +1 -1
  113. package/dist/types/buffer.js.map +1 -1
  114. package/dist/types/date.js +1 -1
  115. package/dist/types/date.js.map +1 -1
  116. package/dist/types/number.js +1 -1
  117. package/dist/types/number.js.map +1 -1
  118. package/dist/types/object.js +1 -1
  119. package/dist/types/object.js.map +1 -1
  120. package/dist/types/union.js +1 -1
  121. package/dist/types/union.js.map +1 -1
  122. package/package.json +16 -16
  123. package/src/errors/index.ts +1 -0
  124. package/src/errors/invalid-polymorphism.error.ts +28 -0
  125. package/src/model.ts +19 -0
  126. package/src/relations/belongs-to/belongs-to.accessor.ts +35 -6
  127. package/src/relations/belongs-to/belongs-to.helpers.ts +36 -9
  128. package/src/relations/belongs-to/belongs-to.inclusion-resolver.ts +108 -17
  129. package/src/relations/belongs-to/belongs-to.repository.ts +77 -17
  130. package/src/relations/has-many/has-many-through.helpers.ts +27 -1
  131. package/src/relations/has-many/has-many-through.inclusion-resolver.ts +117 -26
  132. package/src/relations/has-many/has-many-through.repository-factory.ts +21 -3
  133. package/src/relations/has-many/has-many-through.repository.ts +343 -76
  134. package/src/relations/has-one/has-one.helpers.ts +40 -13
  135. package/src/relations/has-one/has-one.inclusion-resolver.ts +109 -15
  136. package/src/relations/has-one/has-one.repository-factory.ts +34 -6
  137. package/src/relations/has-one/has-one.repository.ts +188 -35
  138. package/src/relations/index.ts +2 -0
  139. package/src/relations/references-many/index.ts +9 -0
  140. package/src/relations/references-many/references-many.accessor.ts +76 -0
  141. package/src/relations/references-many/references-many.decorator.ts +100 -0
  142. package/src/relations/references-many/references-many.helpers.ts +82 -0
  143. package/src/relations/references-many/references-many.inclusion-resolver.ts +80 -0
  144. package/src/relations/references-many/references-many.repository.ts +55 -0
  145. package/src/relations/relation.decorator.ts +0 -12
  146. package/src/relations/relation.filter.solver.ts +56 -0
  147. package/src/relations/relation.helpers.ts +16 -1
  148. package/src/relations/relation.types.ts +51 -0
  149. package/src/repositories/legacy-juggler-bridge.ts +78 -14
@@ -5,6 +5,7 @@
5
5
  // License text available at https://opensource.org/licenses/MIT
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.createBelongsToInclusionResolver = void 0;
8
+ const __1 = require("../../");
8
9
  const relation_helpers_1 = require("../relation.helpers");
9
10
  const belongs_to_helpers_1 = require("./belongs-to.helpers");
10
11
  /**
@@ -15,21 +16,93 @@ const belongs_to_helpers_1 = require("./belongs-to.helpers");
15
16
  * Notice: scope field for inclusion is not supported yet
16
17
  *
17
18
  * @param meta - resolved BelongsToMetadata
18
- * @param getTargetRepo - target repository i.e where related instances are
19
+ * @param getTargetRepoDict - dictionary of target model type - target repository
20
+ * i.e where related instances for different types are
19
21
  */
20
- function createBelongsToInclusionResolver(meta, getTargetRepo) {
22
+ function createBelongsToInclusionResolver(meta, getTargetRepoDict) {
21
23
  const relationMeta = (0, belongs_to_helpers_1.resolveBelongsToMetadata)(meta);
22
- return async function fetchIncludedModels(entities, inclusion, options) {
24
+ return async function fetchBelongsToModel(entities, inclusion, options) {
23
25
  if (!entities.length)
24
26
  return [];
27
+ // Source ids are grouped by their target polymorphic types
28
+ // Each type search for target instances and then merge together in a merge-sort-like manner
25
29
  const sourceKey = relationMeta.keyFrom;
26
- const sourceIds = entities.map(e => e[sourceKey]);
27
30
  const targetKey = relationMeta.keyTo;
28
- const dedupedSourceIds = (0, relation_helpers_1.deduplicate)(sourceIds);
31
+ const targetDiscriminator = relationMeta.polymorphic
32
+ ? relationMeta.polymorphic.discriminator
33
+ : undefined;
29
34
  const scope = typeof inclusion === 'string' ? {} : inclusion.scope;
30
- const targetRepo = await getTargetRepo();
31
- const targetsFound = await (0, relation_helpers_1.findByForeignKeys)(targetRepo, targetKey, dedupedSourceIds.filter(e => e), scope, options);
32
- return (0, relation_helpers_1.flattenTargetsOfOneToOneRelation)(sourceIds, targetsFound, targetKey);
35
+ // sourceIds in {targetType -> sourceId}
36
+ const sourceIdsCategorized = {};
37
+ if (targetDiscriminator) {
38
+ entities.forEach((value, index, allEntites) => {
39
+ const concreteType = String(value[targetDiscriminator]);
40
+ if (!getTargetRepoDict[concreteType]) {
41
+ throw new __1.InvalidPolymorphismError(concreteType, targetDiscriminator);
42
+ }
43
+ if (!sourceIdsCategorized[concreteType]) {
44
+ sourceIdsCategorized[concreteType] = [];
45
+ }
46
+ sourceIdsCategorized[concreteType].push(value[sourceKey]);
47
+ });
48
+ }
49
+ else {
50
+ const concreteType = relationMeta.target().name;
51
+ if (!getTargetRepoDict[concreteType]) {
52
+ throw new __1.InvalidPolymorphismError(concreteType);
53
+ }
54
+ entities.forEach((value, index, allEntites) => {
55
+ if (!sourceIdsCategorized[concreteType]) {
56
+ sourceIdsCategorized[concreteType] = [];
57
+ }
58
+ sourceIdsCategorized[concreteType].push(value[sourceKey]);
59
+ });
60
+ }
61
+ // Ensure targetKey is included otherwise flatten function cannot work
62
+ const changedTargetKeyField = (0, __1.includeFieldIfNot)(scope === null || scope === void 0 ? void 0 : scope.fields, targetKey);
63
+ let needToRemoveTargetKeyFieldLater = false;
64
+ if (changedTargetKeyField !== false) {
65
+ scope.fields = changedTargetKeyField;
66
+ needToRemoveTargetKeyFieldLater = true;
67
+ }
68
+ // Each sourceIds array with same target type extract target instances
69
+ const targetCategorized = {};
70
+ for (const k of Object.keys(sourceIdsCategorized)) {
71
+ const targetRepo = await getTargetRepoDict[k]();
72
+ const targetsFound = await (0, relation_helpers_1.findByForeignKeys)(targetRepo, targetKey, (0, relation_helpers_1.deduplicate)(sourceIdsCategorized[k]).filter(e => e), scope, options);
73
+ targetCategorized[k] = (0, relation_helpers_1.flattenTargetsOfOneToOneRelation)(sourceIdsCategorized[k], targetsFound, targetKey);
74
+ // Remove targetKey if should be excluded but included above
75
+ if (needToRemoveTargetKeyFieldLater) {
76
+ targetCategorized[k] = targetCategorized[k].map(e => {
77
+ if (e) {
78
+ delete e[targetKey];
79
+ }
80
+ return e;
81
+ });
82
+ }
83
+ }
84
+ // Merge
85
+ // Why the order is correct:
86
+ // e.g. target model 1 = a, target model 2 = b
87
+ // all entities: [S(a-1), S(a-2), S(b-3), S(a-4), S(b-5)]
88
+ // a-result: [a-1, a-2, a-4]
89
+ // b-result: [b-3, b-4]
90
+ // merged:
91
+ // entities[1]->a => targets: [a-1 from a-result.shift()]
92
+ // entities[2]->a => targets: [a-1, a-2 from a-result.shift()]
93
+ // entities[3]->b => targets: [a-1, a-2, b-3 from b-result.shift()]
94
+ // entities[4]->a => targets: [a-1, a-2, b-3, a-4 from a-result.shift()]
95
+ // entities[5]->b => targets: [a-1, a-2, b-3, a-4, b-5 from b-result.shift()]
96
+ if (targetDiscriminator) {
97
+ const allTargets = [];
98
+ entities.forEach((value, index, allEntites) => {
99
+ allTargets.push(targetCategorized[String(value[targetDiscriminator])].shift());
100
+ });
101
+ return allTargets;
102
+ }
103
+ else {
104
+ return targetCategorized[relationMeta.target().name];
105
+ }
33
106
  };
34
107
  }
35
108
  exports.createBelongsToInclusionResolver = createBelongsToInclusionResolver;
@@ -1 +1 @@
1
- {"version":3,"file":"belongs-to.inclusion-resolver.js","sourceRoot":"","sources":["../../../src/relations/belongs-to/belongs-to.inclusion-resolver.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAMhE,0DAK6B;AAM7B,6DAA8D;AAE9D;;;;;;;;;GASG;AACH,SAAgB,gCAAgC,CAK9C,IAAyB,EACzB,aAEC;IAED,MAAM,YAAY,GAAG,IAAA,6CAAwB,EAAC,IAAI,CAAC,CAAC;IAEpD,OAAO,KAAK,UAAU,mBAAmB,CACvC,QAAkB,EAClB,SAA0B,EAC1B,OAAiB;QAEjB,IAAI,CAAC,QAAQ,CAAC,MAAM;YAAE,OAAO,EAAE,CAAC;QAEhC,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC;QACvC,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAE,CAAe,CAAC,SAAS,CAAC,CAAC,CAAC;QACjE,MAAM,SAAS,GAAG,YAAY,CAAC,KAA4B,CAAC;QAC5D,MAAM,gBAAgB,GAAG,IAAA,8BAAW,EAAC,SAAS,CAAC,CAAC;QAEhD,MAAM,KAAK,GACT,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAE,SAAS,CAAC,KAAwB,CAAC;QAE3E,MAAM,UAAU,GAAG,MAAM,aAAa,EAAE,CAAC;QACzC,MAAM,YAAY,GAAG,MAAM,IAAA,oCAAiB,EAC1C,UAAU,EACV,SAAS,EACT,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAC/B,KAAK,EACL,OAAO,CACR,CAAC;QAEF,OAAO,IAAA,mDAAgC,EAAC,SAAS,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;IAC9E,CAAC,CAAC;AACJ,CAAC;AAtCD,4EAsCC"}
1
+ {"version":3,"file":"belongs-to.inclusion-resolver.js","sourceRoot":"","sources":["../../../src/relations/belongs-to/belongs-to.inclusion-resolver.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAGhE,8BAAmE;AAInE,0DAK6B;AAM7B,6DAA8D;AAE9D;;;;;;;;;;GAUG;AACH,SAAgB,gCAAgC,CAK9C,IAAyB,EACzB,iBAIC;IAED,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F,4DAA4D;YAC5D,IAAI,+BAA+B,EAAE;gBACnC,iBAAiB,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;oBAClD,IAAI,CAAC,EAAE;wBACL,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC;qBACrB;oBACD,OAAO,CAAC,CAAC;gBACX,CAAC,CAAC,CAAC;aACJ;SACF;QAED,QAAQ;QACR,4BAA4B;QAC5B,8CAA8C;QAC9C,yDAAyD;QACzD,4BAA4B;QAC5B,uBAAuB;QACvB,UAAU;QACV,yDAAyD;QACzD,8DAA8D;QAC9D,mEAAmE;QACnE,wEAAwE;QACxE,6EAA6E;QAC7E,IAAI,mBAAmB,EAAE;YACvB,MAAM,UAAU,GAA+C,EAAE,CAAC;YAClE,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE;gBAC5C,UAAU,CAAC,IAAI,CACb,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAC9D,CAAC;YACJ,CAAC,CAAC,CAAC;YACH,OAAO,UAAU,CAAC;SACnB;aAAM;YACL,OAAO,iBAAiB,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC;SACtD;IACH,CAAC,CAAC;AACJ,CAAC;AA/HD,4EA+HC"}
@@ -1,4 +1,5 @@
1
1
  import { Getter } from '@loopback/core';
2
+ import { TypeResolver } from '../../';
2
3
  import { DataObject, Options } from '../../common-types';
3
4
  import { Entity } from '../../model';
4
5
  import { EntityCrudRepository } from '../../repositories';
@@ -9,20 +10,42 @@ export interface BelongsToRepository<Target extends Entity> {
9
10
  /**
10
11
  * Gets the target model instance
11
12
  * @param options
13
+ * options.polymorphicType - a string or a string array of polymorphic type names
14
+ * to specify which repositories should are expected to be searched
15
+ * It is highly recommended to contain this param especially for
16
+ * datasources using deplicated ids across tables
12
17
  * @returns A promise resolved with the target object or rejected
13
18
  * with an EntityNotFoundError when target model instance was not found.
14
19
  */
15
- get(options?: Options): Promise<Target>;
20
+ get(options?: Options & {
21
+ polymorphicType?: string | string[];
22
+ }): Promise<Target>;
16
23
  }
17
24
  export declare class DefaultBelongsToRepository<TargetEntity extends Entity, TargetId, TargetRepository extends EntityCrudRepository<TargetEntity, TargetId>> implements BelongsToRepository<TargetEntity> {
18
- getTargetRepository: Getter<TargetRepository>;
25
+ getTargetRepository: Getter<TargetRepository> | {
26
+ [repoType: string]: Getter<TargetRepository>;
27
+ };
19
28
  constraint: DataObject<TargetEntity>;
29
+ targetResolver: TypeResolver<Entity, typeof Entity>;
20
30
  /**
21
31
  * Constructor of DefaultBelongsToEntityCrudRepository
22
- * @param getTargetRepository - the getter of the related target model repository instance
32
+ * @param getTargetRepository - either a dictionary of target model type - target repository instance
33
+ * or a single target repository instance
34
+ * e.g. if the target is of a non-polymorphic type "Student", put the studentRepositoryGetterInstance
35
+ * if the target is of a polymorphic type "Person" which can be either a "Student" or a "Teacher"
36
+ * then put "{Student: studentRepositoryGetterInstance, Teacher: teacherRepositoryGetterInstance}"
23
37
  * @param constraint - the key value pair representing foreign key name to constrain
24
38
  * the target repository instance
39
+ * @param targetResolver - () => Target to resolve the target class
40
+ * e.g. if the target is of type "Student", then put "() => Student"
25
41
  */
26
- constructor(getTargetRepository: Getter<TargetRepository>, constraint: DataObject<TargetEntity>);
27
- get(options?: Options): Promise<TargetEntity>;
42
+ constructor(getTargetRepository: Getter<TargetRepository> | {
43
+ [repoType: string]: Getter<TargetRepository>;
44
+ }, constraint: DataObject<TargetEntity>, targetResolver: TypeResolver<Entity, typeof Entity>);
45
+ getTargetRepositoryDict: {
46
+ [repoType: string]: Getter<TargetRepository>;
47
+ };
48
+ get(options?: Options & {
49
+ polymorphicType?: string | string[];
50
+ }): Promise<TargetEntity>;
28
51
  }
@@ -5,28 +5,67 @@
5
5
  // License text available at https://opensource.org/licenses/MIT
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.DefaultBelongsToRepository = void 0;
8
- const errors_1 = require("../../errors");
8
+ const lodash_1 = require("lodash");
9
+ const __1 = require("../../");
9
10
  const repositories_1 = require("../../repositories");
10
11
  class DefaultBelongsToRepository {
11
12
  /**
12
13
  * Constructor of DefaultBelongsToEntityCrudRepository
13
- * @param getTargetRepository - the getter of the related target model repository instance
14
+ * @param getTargetRepository - either a dictionary of target model type - target repository instance
15
+ * or a single target repository instance
16
+ * e.g. if the target is of a non-polymorphic type "Student", put the studentRepositoryGetterInstance
17
+ * if the target is of a polymorphic type "Person" which can be either a "Student" or a "Teacher"
18
+ * then put "{Student: studentRepositoryGetterInstance, Teacher: teacherRepositoryGetterInstance}"
14
19
  * @param constraint - the key value pair representing foreign key name to constrain
15
20
  * the target repository instance
21
+ * @param targetResolver - () => Target to resolve the target class
22
+ * e.g. if the target is of type "Student", then put "() => Student"
16
23
  */
17
- constructor(getTargetRepository, constraint) {
24
+ constructor(getTargetRepository, constraint, targetResolver) {
18
25
  this.getTargetRepository = getTargetRepository;
19
26
  this.constraint = constraint;
27
+ this.targetResolver = targetResolver;
28
+ if (typeof getTargetRepository === 'function') {
29
+ this.getTargetRepositoryDict = {
30
+ [targetResolver().name]: getTargetRepository,
31
+ };
32
+ }
33
+ else {
34
+ this.getTargetRepositoryDict = getTargetRepository;
35
+ }
20
36
  }
21
37
  async get(options) {
22
- const targetRepo = await this.getTargetRepository();
23
- const result = await targetRepo.find((0, repositories_1.constrainFilter)(undefined, this.constraint), options);
24
- if (!result.length) {
25
- // We don't have a direct access to the foreign key value here :(
26
- const id = 'constraint ' + JSON.stringify(this.constraint);
27
- throw new errors_1.EntityNotFoundError(targetRepo.entityClass, id);
38
+ let polymorphicTypes = options === null || options === void 0 ? void 0 : options.polymorphicType;
39
+ let allKeys;
40
+ if (Object.keys(this.getTargetRepositoryDict).length <= 1) {
41
+ allKeys = Object.keys(this.getTargetRepositoryDict);
42
+ }
43
+ else if (!polymorphicTypes || polymorphicTypes.length === 0) {
44
+ console.warn('It is highly recommended to specify the polymorphicTypes param when using polymorphic types.');
45
+ allKeys = Object.keys(this.getTargetRepositoryDict);
46
+ }
47
+ else {
48
+ if (typeof polymorphicTypes === 'string') {
49
+ polymorphicTypes = [polymorphicTypes];
50
+ }
51
+ allKeys = [];
52
+ new Set(polymorphicTypes).forEach(element => {
53
+ if (Object.keys(this.getTargetRepositoryDict).includes(element)) {
54
+ allKeys.push(element);
55
+ }
56
+ });
57
+ }
58
+ let result = [];
59
+ for (const key of allKeys) {
60
+ const targetRepository = await this.getTargetRepositoryDict[key]();
61
+ result = result.concat(await targetRepository.find((0, repositories_1.constrainFilter)(undefined, this.constraint), Object.assign((0, lodash_1.cloneDeep)(options !== null && options !== void 0 ? options : {}), { polymorphicType: key })));
62
+ if (result.length >= 1) {
63
+ return result[0];
64
+ }
28
65
  }
29
- return result[0];
66
+ // We don't have a direct access to the foreign key value here :(
67
+ const id = 'constraint ' + JSON.stringify(this.constraint);
68
+ throw new __1.EntityNotFoundError(this.targetResolver().name, id);
30
69
  }
31
70
  }
32
71
  exports.DefaultBelongsToRepository = DefaultBelongsToRepository;
@@ -1 +1 @@
1
- {"version":3,"file":"belongs-to.repository.js","sourceRoot":"","sources":["../../../src/relations/belongs-to/belongs-to.repository.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAIhE,yCAAiD;AAEjD,qDAAyE;AAezE,MAAa,0BAA0B;IAMrC;;;;;OAKG;IACH,YACS,mBAA6C,EAC7C,UAAoC;QADpC,wBAAmB,GAAnB,mBAAmB,CAA0B;QAC7C,eAAU,GAAV,UAAU,CAA0B;IAC1C,CAAC;IAEJ,KAAK,CAAC,GAAG,CAAC,OAAiB;QACzB,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACpD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,IAAI,CAClC,IAAA,8BAAe,EAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,EAC3C,OAAO,CACR,CAAC;QACF,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;YAClB,iEAAiE;YACjE,MAAM,EAAE,GAAG,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC3D,MAAM,IAAI,4BAAmB,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;SAC3D;QACD,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC;CACF;AA9BD,gEA8BC"}
1
+ {"version":3,"file":"belongs-to.repository.js","sourceRoot":"","sources":["../../../src/relations/belongs-to/belongs-to.repository.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAGhE,mCAAiC;AACjC,8BAAyD;AAGzD,qDAAyE;AAoBzE,MAAa,0BAA0B;IAMrC;;;;;;;;;;;OAWG;IAEH,YACS,mBAIF,EACE,UAAoC,EACpC,cAAmD;QANnD,wBAAmB,GAAnB,mBAAmB,CAIrB;QACE,eAAU,GAAV,UAAU,CAA0B;QACpC,mBAAc,GAAd,cAAc,CAAqC;QAE1D,IAAI,OAAO,mBAAmB,KAAK,UAAU,EAAE;YAC7C,IAAI,CAAC,uBAAuB,GAAG;gBAC7B,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,EACrB,mBAA+C;aAClD,CAAC;SACH;aAAM;YACL,IAAI,CAAC,uBAAuB,GAAG,mBAE9B,CAAC;SACH;IACH,CAAC;IAMD,KAAK,CAAC,GAAG,CACP,OAAyD;QAEzD,IAAI,gBAAgB,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,eAAe,CAAC;QAChD,IAAI,OAAiB,CAAC;QACtB,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC,MAAM,IA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;aAClB;SACF;QACD,iEAAiE;QACjE,MAAM,EAAE,GAAG,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC3D,MAAM,IAAI,uBAAmB,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAChE,CAAC;CACF;AApFD,gEAoFC"}
@@ -5,8 +5,8 @@
5
5
  // License text available at https://opensource.org/licenses/MIT
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const tslib_1 = require("tslib");
8
- (0, tslib_1.__exportStar)(require("./belongs-to.decorator"), exports);
9
- (0, tslib_1.__exportStar)(require("./belongs-to.repository"), exports);
10
- (0, tslib_1.__exportStar)(require("./belongs-to.accessor"), exports);
11
- (0, tslib_1.__exportStar)(require("./belongs-to.inclusion-resolver"), exports);
8
+ tslib_1.__exportStar(require("./belongs-to.decorator"), exports);
9
+ tslib_1.__exportStar(require("./belongs-to.repository"), exports);
10
+ tslib_1.__exportStar(require("./belongs-to.accessor"), exports);
11
+ tslib_1.__exportStar(require("./belongs-to.inclusion-resolver"), exports);
12
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/relations/belongs-to/index.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAEhE,sEAAuC;AACvC,uEAAwC;AACxC,qEAAsC;AACtC,+EAAgD"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/relations/belongs-to/index.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAEhE,iEAAuC;AACvC,kEAAwC;AACxC,gEAAsC;AACtC,0EAAgD"}
@@ -5,6 +5,9 @@ export declare type HasManyThroughResolvedDefinition = HasManyDefinition & {
5
5
  through: {
6
6
  keyTo: string;
7
7
  keyFrom: string;
8
+ polymorphic: false | {
9
+ discriminator: string;
10
+ };
8
11
  };
9
12
  };
10
13
  /**
@@ -6,7 +6,7 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.resolveHasManyThroughMetadata = exports.createThroughConstraintFromTarget = exports.getTargetIdsFromTargetModels = exports.createThroughConstraintFromSource = exports.getTargetKeysFromThroughModels = exports.createTargetConstraintFromThrough = void 0;
8
8
  const tslib_1 = require("tslib");
9
- const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
9
+ const debug_1 = tslib_1.__importDefault(require("debug"));
10
10
  const lodash_1 = require("lodash");
11
11
  const __1 = require("../..");
12
12
  const has_many_helpers_1 = require("./has-many.helpers");
@@ -246,7 +246,10 @@ function resolveHasManyThroughMetadata(relationMeta) {
246
246
  relationMeta.through.keyFrom &&
247
247
  throughModelProperties[relationMeta.through.keyFrom] &&
248
248
  relationMeta.keyTo &&
249
- targetModelProperties[relationMeta.keyTo]) {
249
+ targetModelProperties[relationMeta.keyTo] &&
250
+ (relationMeta.through.polymorphic === false ||
251
+ (typeof relationMeta.through.polymorphic === 'object' &&
252
+ relationMeta.through.polymorphic.discriminator.length > 0))) {
250
253
  // The explicit cast is needed because of a limitation of type inference
251
254
  return relationMeta;
252
255
  }
@@ -268,6 +271,26 @@ function resolveHasManyThroughMetadata(relationMeta) {
268
271
  const reason = `target model ${targetModel.modelName} does not have any primary key (id property)`;
269
272
  throw new __1.InvalidRelationError(reason, relationMeta);
270
273
  }
274
+ let throughPolymorphic;
275
+ if (relationMeta.through.polymorphic === undefined ||
276
+ relationMeta.through.polymorphic === false ||
277
+ !relationMeta.through.polymorphic) {
278
+ const polymorphicFalse = false;
279
+ throughPolymorphic = polymorphicFalse;
280
+ }
281
+ else {
282
+ if (relationMeta.through.polymorphic === true) {
283
+ const polymorphicObject = {
284
+ discriminator: (0, lodash_1.camelCase)(relationMeta.target().name + '_type'),
285
+ };
286
+ throughPolymorphic = polymorphicObject;
287
+ }
288
+ else {
289
+ const polymorphicObject = relationMeta.through
290
+ .polymorphic;
291
+ throughPolymorphic = polymorphicObject;
292
+ }
293
+ }
271
294
  return Object.assign(relationMeta, {
272
295
  keyTo: targetPrimaryKey,
273
296
  keyFrom: relationMeta.keyFrom,
@@ -275,6 +298,7 @@ function resolveHasManyThroughMetadata(relationMeta) {
275
298
  ...relationMeta.through,
276
299
  keyTo: targetFkName,
277
300
  keyFrom: sourceFkName,
301
+ polymorphic: throughPolymorphic,
278
302
  },
279
303
  });
280
304
  }
@@ -1 +1 @@
1
- {"version":3,"file":"has-many-through.helpers.js","sourceRoot":"","sources":["../../../src/relations/has-many/has-many-through.helpers.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,+DAAiC;AACjC,mCAAiC;AACjC,6BAOe;AACf,yDAA4D;AAE5D,MAAM,KAAK,GAAG,IAAA,eAAY,EACxB,wDAAwD,CACzD,CAAC;AAWF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,SAAgB,iCAAiC,CAI/C,YAA8C,EAC9C,gBAA2B;IAE3B,MAAM,QAAQ,GAAG,8BAA8B,CAC7C,YAAY,EACZ,gBAAgB,CACjB,CAAC;IACF,MAAM,gBAAgB,GAAG,YAAY,CAAC,KAAK,CAAC;IAE5C,8DAA8D;IAC9D,MAAM,UAAU,GAAQ;QACtB,CAAC,gBAAgB,CAAC,EAAE,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC,GAAG,EAAE,QAAQ,EAAC;KAC1E,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,CAAC;AAlBD,8EAkBC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,SAAgB,8BAA8B,CAI5C,YAA8C,EAC9C,gBAA2B;IAE3B,MAAM,YAAY,GAAG,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AAC;QACnG,MAAM,IAAI,wBAAoB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;KACtD;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE;QACjC,KAAK,EAAE,gBAAgB;QACvB,OAAO,EAAE,YAAY,CAAC,OAAQ;QAC9B,OAAO,EAAE;YACP,GAAG,YAAY,CAAC,OAAO;YACvB,KAAK,EAAE,YAAY;YACnB,OAAO,EAAE,YAAY;SACtB;KACF,CAAC,CAAC;AACL,CAAC;AA9ED,sEA8EC"}
1
+ {"version":3,"file":"has-many-through.helpers.js","sourceRoot":"","sources":["../../../src/relations/has-many/has-many-through.helpers.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,0DAAiC;AACjC,mCAAiC;AACjC,6BAOe;AACf,yDAA4D;AAE5D,MAAM,KAAK,GAAG,IAAA,eAAY,EACxB,wDAAwD,CACzD,CAAC;AAYF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,SAAgB,iCAAiC,CAI/C,YAA8C,EAC9C,gBAA2B;IAE3B,MAAM,QAAQ,GAAG,8BAA8B,CAC7C,YAAY,EACZ,gBAAgB,CACjB,CAAC;IACF,MAAM,gBAAgB,GAAG,YAAY,CAAC,KAAK,CAAC;IAE5C,8DAA8D;IAC9D,MAAM,UAAU,GAAQ;QACtB,CAAC,gBAAgB,CAAC,EAAE,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC,GAAG,EAAE,QAAQ,EAAC;KAC1E,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,CAAC;AAlBD,8EAkBC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,SAAgB,8BAA8B,CAI5C,YAA8C,EAC9C,gBAA2B;IAE3B,MAAM,YAAY,GAAG,YA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
  * @param getTargetRepo - target repository getter i.e where target instances
14
14
  * are
15
15
  */
16
- export declare function createHasManyThroughInclusionResolver<Through extends Entity, ThroughID, ThroughRelations extends object, Target extends Entity, TargetID, TargetRelations extends object>(meta: HasManyDefinition, getThroughRepo: Getter<EntityCrudRepository<Through, ThroughID, ThroughRelations>>, getTargetRepo: Getter<EntityCrudRepository<Target, TargetID, TargetRelations>>): InclusionResolver<Entity, Target>;
16
+ export declare function createHasManyThroughInclusionResolver<Through extends Entity, ThroughID, ThroughRelations extends object, Target extends Entity, TargetID, TargetRelations extends object>(meta: HasManyDefinition, getThroughRepo: Getter<EntityCrudRepository<Through, ThroughID, ThroughRelations>>, getTargetRepoDict: {
17
+ [repoType: string]: Getter<EntityCrudRepository<Target, TargetID, TargetRelations>>;
18
+ }): InclusionResolver<Entity, Target>;
@@ -6,9 +6,10 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.createHasManyThroughInclusionResolver = void 0;
8
8
  const tslib_1 = require("tslib");
9
- const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
9
+ const debug_1 = tslib_1.__importDefault(require("debug"));
10
+ const __1 = require("../..");
10
11
  const relation_helpers_1 = require("../relation.helpers");
11
- const has_many_helpers_1 = require("./has-many.helpers");
12
+ const has_many_through_helpers_1 = require("./has-many-through.helpers");
12
13
  const debug = (0, debug_1.default)('loopback:repository:relations:has-many-through:inclusion-resolver');
13
14
  /**
14
15
  * Creates InclusionResolver for HasManyThrough relation.
@@ -22,9 +23,12 @@ const debug = (0, debug_1.default)('loopback:repository:relations:has-many-throu
22
23
  * @param getTargetRepo - target repository getter i.e where target instances
23
24
  * are
24
25
  */
25
- function createHasManyThroughInclusionResolver(meta, getThroughRepo, getTargetRepo) {
26
- const relationMeta = (0, has_many_helpers_1.resolveHasManyMetadata)(meta);
26
+ function createHasManyThroughInclusionResolver(meta, getThroughRepo, getTargetRepoDict) {
27
+ const relationMeta = (0, has_many_through_helpers_1.resolveHasManyThroughMetadata)(meta);
27
28
  return async function fetchHasManyThroughModels(entities, inclusion, options) {
29
+ if (!relationMeta.through) {
30
+ throw new Error(`relationMeta.through must be defined on ${relationMeta}`);
31
+ }
28
32
  if (!entities.length)
29
33
  return [];
30
34
  debug('Fetching target models for entities:', entities);
@@ -46,32 +50,99 @@ function createHasManyThroughInclusionResolver(meta, getThroughRepo, getTargetRe
46
50
  });
47
51
  debug('sourceId types', sourceIds.map(i => typeof i));
48
52
  const throughRepo = await getThroughRepo();
49
- const targetRepo = await getTargetRepo();
50
53
  // find through models
51
54
  const throughFound = await (0, relation_helpers_1.findByForeignKeys)(throughRepo, throughKeyFrom, sourceIds, {}, // scope will be applied at the target level
52
55
  options);
53
56
  const throughResult = (0, relation_helpers_1.flattenTargetsOfOneToManyRelation)(sourceIds, throughFound, throughKeyFrom);
54
- const result = [];
55
57
  const scope = typeof inclusion === 'string' ? {} : inclusion.scope;
56
- // convert from through entities to the target entities
57
- for (const entityList of throughResult) {
58
- if (entityList) {
59
- // get target ids from the through entities by foreign key
60
- const targetIds = entityList.map(entity => entity[throughKeyTo]);
61
- // the explicit types and casts are needed
62
- const targetEntityList = await (0, relation_helpers_1.findByForeignKeys)(targetRepo, targetKey, targetIds, scope, {
63
- ...options,
64
- isThroughModelInclude: true,
65
- });
66
- result.push(targetEntityList);
58
+ // whether the polymorphism is configured
59
+ const targetDiscriminator = relationMeta.through.polymorphic
60
+ ? relationMeta.through.polymorphic.discriminator
61
+ : undefined;
62
+ if (targetDiscriminator) {
63
+ // put through results into arrays based on the target polymorphic types
64
+ const throughArrayByTargetType = {};
65
+ for (const throughArray of throughResult) {
66
+ if (throughArray) {
67
+ for (const throughItem of throughArray) {
68
+ const targetType = String(throughItem[targetDiscriminator]);
69
+ if (!getTargetRepoDict[targetType]) {
70
+ throw new __1.InvalidPolymorphismError(targetType, String(targetDiscriminator));
71
+ }
72
+ if (!throughArrayByTargetType[targetType]) {
73
+ throughArrayByTargetType[targetType] = [];
74
+ }
75
+ throughArrayByTargetType[targetType].push(throughItem);
76
+ }
77
+ }
67
78
  }
68
- else {
69
- // no entities found, add undefined to results
70
- result.push(entityList);
79
+ // get targets based on their polymorphic types
80
+ const targetOfTypes = {};
81
+ for (const targetType of Object.keys(throughArrayByTargetType)) {
82
+ const targetIds = throughArrayByTargetType[targetType].map(throughItem => throughItem[throughKeyTo]);
83
+ const targetRepo = await getTargetRepoDict[targetType]();
84
+ const targetEntityList = await (0, relation_helpers_1.findByForeignKeys)(targetRepo, targetKey, targetIds, scope, options);
85
+ targetOfTypes[targetType] = targetEntityList;
86
+ }
87
+ // put targets into arrays reflecting their throughs
88
+ // Why the order is correct:
89
+ // e.g. through model = T(target instance), target model 1 = a, target model 2 = b
90
+ // all entities: [S1, S2, S2]
91
+ // through-result: [[T(b-11), T(a-12), T(b-13), T(b-14)], [T(a-21), T(a-22), T(b-23)], [T(b-31), T(b-32), T(a-33)]]
92
+ // through-array-by-target-type: {a:[T(a-12), T(a-21), T(a-22), T(a-33)] b: [T(b-11), T(b-13), T(b-14), T(b-23), T(b-31), T(b-32)]}
93
+ // target-array-by-target-type: {a:[a-12, a-21, a-22, a-33] b: [b-11, b-13, b-14, b-23, b-31, b-32]}
94
+ // merged:
95
+ // through-result[0][0]->b => targets: [[b-11 from b.shift()]]
96
+ // through-result[0][1]->a => targets: [[b-11, a-12 from a.shift()]]
97
+ // through-result[0][2]->b => targets: [[b-11, a-12, b-13 from b.shift()]]
98
+ // through-result[0][3]->b => targets: [[b-11, a-12, b-13, b-14 from b.shift()]]
99
+ // through-result[1][0]->a => targets: [[b-11, a-12, b-13, b-14], [a-21, from a.shift()]]
100
+ // through-result[1][1]->a => targets: [[b-11, a-12, b-13, b-14], [a-21, a-22 from a.shift()]]
101
+ // through-result[1][2]->b => targets: [[b-11, a-12, b-13, b-14], [a-21, a-22, b-23 from b.shift()]]
102
+ // through-result[2][0]->b => targets: [[b-11, a-12, b-13, b-14], [a-21, a-22, b-23], [b-31, from b.shift()]]
103
+ // through-result[2][1]->b => targets: [[b-11, a-12, b-13, b-14], [a-21, a-22, b-23], [b-31, b-32 from b.shift()]]
104
+ // through-result[2][1]->b => targets: [[b-11, a-12, b-13, b-14], [a-21, a-22, b-23], [b-31, b-32, a-33 from a.shift()]]
105
+ const allTargetsOfThrough = [];
106
+ for (const throughArray of throughResult) {
107
+ if (throughArray && throughArray.length > 0) {
108
+ const currentTargetThroughArray = [];
109
+ for (const throughItem of throughArray) {
110
+ const itemToAdd = targetOfTypes[String(throughItem[targetDiscriminator])].shift();
111
+ if (itemToAdd) {
112
+ currentTargetThroughArray.push(itemToAdd);
113
+ }
114
+ }
115
+ allTargetsOfThrough.push(currentTargetThroughArray);
116
+ }
117
+ else {
118
+ allTargetsOfThrough.push(undefined);
119
+ }
120
+ }
121
+ return allTargetsOfThrough;
122
+ }
123
+ else {
124
+ const targetRepo = await getTargetRepoDict[relationMeta.target().name]();
125
+ const result = [];
126
+ // convert from through entities to the target entities
127
+ for (const entityList of throughResult) {
128
+ if (entityList) {
129
+ // get target ids from the through entities by foreign key
130
+ const targetIds = entityList.map(entity => entity[throughKeyTo]);
131
+ // the explicit types and casts are needed
132
+ const targetEntityList = await (0, relation_helpers_1.findByForeignKeys)(targetRepo, targetKey, targetIds, scope, {
133
+ ...options,
134
+ isThroughModelInclude: true,
135
+ });
136
+ result.push(targetEntityList);
137
+ }
138
+ else {
139
+ // no entities found, add undefined to results
140
+ result.push(entityList);
141
+ }
71
142
  }
143
+ debug('fetchHasManyThroughModels result', result);
144
+ return result;
72
145
  }
73
- debug('fetchHasManyThroughModels result', result);
74
- return result;
75
146
  };
76
147
  }
77
148
  exports.createHasManyThroughInclusionResolver = createHasManyThroughInclusionResolver;
@@ -1 +1 @@
1
- {"version":3,"file":"has-many-through.inclusion-resolver.js","sourceRoot":"","sources":["../../../src/relations/has-many/has-many-through.inclusion-resolver.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;;AAG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EAAE,CAAC;QAEzC,sBAAsB;QACtB,MAAM,YAAY,GAAG,MAAM,IAAA,oCAAiB,EAC1C,WAAW,EACX,cAAc,EACd,SAAS,EACT,EAAE,EAAE,4CAA4C;QAChD,OAAO,CACR,CAAC;QAEF,MAAM,aAAa,GAAG,IAAA,oDAAiC,EACrD,SAAS,EACT,YAAY,EACZ,cAAc,CACf,CAAC;QAEF,MAAM,MAAM,GAAG,EAAE,CAAC;QAElB,MAAM,KAAK,GACT,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAE,SAAS,CAAC,KAAwB,CAAC;QAE3E,uDAAuD;QACvD,KAAK,MAAM,UAAU,IAAI,aAAa,EAAE;YACtC,IAAI,UAAU,EAAE;gBACd,0DAA0D;gBAC1D,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;gBAEjE,0CAA0C;gBAC1C,MAAM,gBAAgB,GAAG,MAAM,IAAA,oCAAiB,EAI9C,UAAU,EAAE,SAAS,EAAE,SAA0B,EAAE,KAAK,EAAE;oBAC1D,GAAG,OAAO;oBACV,qBAAqB,EAAE,IAAI;iBAC5B,CAAC,CAAC;gBACH,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;aAC/B;iBAAM;gBACL,8CAA8C;gBAC9C,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;aACzB;SACF;QAED,KAAK,CAAC,kCAAkC,EAAE,MAAM,CAAC,CAAC;QAClD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AApGD,sFAoGC"}
1
+ {"version":3,"file":"has-many-through.inclusion-resolver.js","sourceRoot":"","sources":["../../../src/relations/has-many/has-many-through.inclusion-resolver.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;;AAGhE,0DAAiC;A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,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;iBACrC;aACF;YACD,OAAO,mBAAmB,CAAC;SAC5B;aAAM;YACL,MAAM,UAAU,GAAG,MAAM,iBAAiB,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YACzE,MAAM,MAAM,GAAG,EAAE,CAAC;YAElB,uDAAuD;YACvD,KAAK,MAAM,UAAU,IAAI,aAAa,EAAE;gBACtC,IAAI,UAAU,EAAE;oBACd,0DAA0D;oBAC1D,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;oBAEjE,0CAA0C;oBAC1C,MAAM,gBAAgB,GAAG,MAAM,IAAA,oCAAiB,EAI9C,UAAU,EAAE,SAAS,EAAE,SAA0B,EAAE,KAAK,EAAE;wBAC1D,GAAG,OAAO;wBACV,qBAAqB,EAAE,IAAI;qBAC5B,CAAC,CAAC;oBACH,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;iBAC/B;qBAAM;oBACL,8CAA8C;oBAC9C,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;iBACzB;aACF;YAED,KAAK,CAAC,kCAAkC,EAAE,MAAM,CAAC,CAAC;YAClD,OAAO,MAAM,CAAC;SACf;IACH,CAAC,CAAC;AACJ,CAAC;AA9LD,sFA8LC"}
@@ -14,4 +14,6 @@ export declare type HasManyThroughRepositoryFactory<TargetEntity extends Entity,
14
14
  */
15
15
  inclusionResolver: InclusionResolver<Entity, TargetEntity>;
16
16
  };
17
- export declare function createHasManyThroughRepositoryFactory<Target extends Entity, TargetID, Through extends Entity, ThroughID, SourceID>(relationMetadata: HasManyDefinition, targetRepositoryGetter: Getter<EntityCrudRepository<Target, TargetID>>, throughRepositoryGetter: Getter<EntityCrudRepository<Through, ThroughID>>): HasManyThroughRepositoryFactory<Target, TargetID, Through, SourceID>;
17
+ export declare function createHasManyThroughRepositoryFactory<Target extends Entity, TargetID, Through extends Entity, ThroughID, SourceID>(relationMetadata: HasManyDefinition, targetRepositoryGetter: Getter<EntityCrudRepository<Target, TargetID>> | {
18
+ [repoType: string]: Getter<EntityCrudRepository<Target, TargetID>>;
19
+ }, throughRepositoryGetter: Getter<EntityCrudRepository<Through, ThroughID>>): HasManyThroughRepositoryFactory<Target, TargetID, Through, SourceID>;
@@ -10,6 +10,12 @@ const has_many_through_inclusion_resolver_1 = require("./has-many-through.inclus
10
10
  const has_many_through_repository_1 = require("./has-many-through.repository");
11
11
  function createHasManyThroughRepositoryFactory(relationMetadata, targetRepositoryGetter, throughRepositoryGetter) {
12
12
  const meta = (0, has_many_through_helpers_1.resolveHasManyThroughMetadata)(relationMetadata);
13
+ // resolve the repositoryGetter into a dictionary
14
+ if (typeof targetRepositoryGetter === 'function') {
15
+ targetRepositoryGetter = {
16
+ [meta.target().name]: targetRepositoryGetter,
17
+ };
18
+ }
13
19
  const result = function (fkValue) {
14
20
  function getTargetConstraintFromThroughModels(throughInstances) {
15
21
  return (0, has_many_through_helpers_1.createTargetConstraintFromThrough)(meta, throughInstances);
@@ -28,7 +34,7 @@ function createHasManyThroughRepositoryFactory(relationMetadata, targetRepositor
28
34
  const constraint = (0, has_many_through_helpers_1.createThroughConstraintFromTarget)(meta, fkValues);
29
35
  return constraint;
30
36
  }
31
- return new has_many_through_repository_1.DefaultHasManyThroughRepository(targetRepositoryGetter, throughRepositoryGetter, getTargetConstraintFromThroughModels, getTargetKeys, getThroughConstraintFromSource, getTargetIds, getThroughConstraintFromTarget);
37
+ return new has_many_through_repository_1.DefaultHasManyThroughRepository(targetRepositoryGetter, throughRepositoryGetter, getTargetConstraintFromThroughModels, getTargetKeys, getThroughConstraintFromSource, getTargetIds, getThroughConstraintFromTarget, relationMetadata.target, relationMetadata.through.model);
32
38
  };
33
39
  result.inclusionResolver = (0, has_many_through_inclusion_resolver_1.createHasManyThroughInclusionResolver)(meta, throughRepositoryGetter, targetRepositoryGetter);
34
40
  return result;
@@ -1 +1 @@
1
- {"version":3,"file":"has-many-through.repository-factory.js","sourceRoot":"","sources":["../../../src/relations/has-many/has-many-through.repository-factory.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAUhE,yEAOoC;AACpC,+FAA4F;AAC5F,+EAGuC;AA4BvC,SAAgB,qCAAqC,CAOnD,gBAAmC,EACnC,sBAAsE,EACtE,uBAAyE;IAEzE,MAAM,IAAI,GAAG,IAAA,wDAA6B,EAAC,gBAAgB,CAAC,CAAC;IAC7D,MAAM,MAAM,GAAG,UAAU,OAAiB;QACxC,SAAS,oCAAoC,CAC3C,gBAA2B;YAE3B,OAAO,IAAA,4DAAiC,EACtC,IAAI,EACJ,gBAAgB,CACjB,CAAC;QACJ,CAAC;QACD,SAAS,aAAa,CAAC,gBAA2B;YAChD,OAAO,IAAA,yDAA8B,EAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;QAChE,CAAC;QACD,SAAS,8BAA8B;YACrC,MAAM,UAAU,GAAwB,IAAA,4DAAiC,EAGvE,IAAI,EAAE,OAAO,CAAC,CAAC;YACjB,OAAO,UAAU,CAAC;QACpB,CAAC;QACD,SAAS,YAAY,CAAC,eAAyB;YAC7C,OAAO,IAAA,uDAA4B,EAAC,IAAI,EAAE,eAAe,CAAC,CAAC;QAC7D,CAAC;QACD,SAAS,8BAA8B,CACrC,QAAoB;YAEpB,MAAM,UAAU,GAAwB,IAAA,4DAAiC,EAGvE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAClB,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,OAAO,IAAI,6DAA+B,CAQxC,sBAAsB,EACtB,uBAAuB,EACvB,oCAAoC,EACpC,aAAa,EACb,8BAA8B,EAC9B,YAAY,EACZ,8BAA8B,CAC/B,CAAC;IACJ,CAAC,CAAC;IACF,MAAM,CAAC,iBAAiB,GAAG,IAAA,2EAAqC,EAC9D,IAAI,EACJ,uBAAuB,EACvB,sBAAsB,CACvB,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC;AAnED,sFAmEC"}
1
+ {"version":3,"file":"has-many-through.repository-factory.js","sourceRoot":"","sources":["../../../src/relations/has-many/has-many-through.repository-factory.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAUhE,yEAOoC;AACpC,+FAA4F;AAC5F,+EAGuC;AA4BvC,SAAgB,qCAAqC,CAOnD,gBAAmC,EACnC,sBAIK,EACL,uBAAyE;IAEzE,MAAM,IAAI,GAAG,IAAA,wDAA6B,EAAC,gBAAgB,CAAC,CAAC;IAC7D,iDAAiD;IACjD,IAAI,OAAO,sBAAsB,KAAK,UAAU,EAAE;QAChD,sBAAsB,GAAG;YACvB,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,sBAErB;SACF,CAAC;KACH;IACD,MAAM,MAAM,GAAG,UAAU,OAAiB;QACxC,SAAS,oCAAoC,CAC3C,gBAA2B;YAE3B,OAAO,IAAA,4DAAiC,EACtC,IAAI,EACJ,gBAAgB,CACjB,CAAC;QACJ,CAAC;QACD,SAAS,aAAa,CAAC,gBAA2B;YAChD,OAAO,IAAA,yDAA8B,EAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;QAChE,CAAC;QACD,SAAS,8BAA8B;YACrC,MAAM,UAAU,GAAwB,IAAA,4DAAiC,EAGvE,IAAI,EAAE,OAAO,CAAC,CAAC;YACjB,OAAO,UAAU,CAAC;QACpB,CAAC;QACD,SAAS,YAAY,CAAC,eAAyB;YAC7C,OAAO,IAAA,uDAA4B,EAAC,IAAI,EAAE,eAAe,CAAC,CAAC;QAC7D,CAAC;QACD,SAAS,8BAA8B,CACrC,QAAoB;YAEpB,MAAM,UAAU,GAAwB,IAAA,4DAAiC,EAGvE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAClB,OAAO,UAAU,CAAC;QAC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