@loomcore/api 0.1.77 → 0.1.78

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.
@@ -12,6 +12,17 @@ async function getTableColumns(client, tableName) {
12
12
  `, [tableName]);
13
13
  return result.rows.map(row => row.column_name);
14
14
  }
15
+ function findEnrichmentTarget(operation, operations) {
16
+ if (!operation.localField.includes('.')) {
17
+ return null;
18
+ }
19
+ const [alias] = operation.localField.split('.');
20
+ const target = operations.find(op => (op instanceof JoinMany || op instanceof JoinThroughMany) && op.as === alias);
21
+ if (target && operations.indexOf(target) < operations.indexOf(operation)) {
22
+ return { target, field: operation.localField.split('.')[1] };
23
+ }
24
+ return null;
25
+ }
15
26
  export async function buildSelectClause(client, mainTableName, mainTableAlias, operations) {
16
27
  const joinOperations = operations.filter(op => op instanceof Join);
17
28
  const joinManyOperations = operations.filter(op => op instanceof JoinMany);
@@ -22,52 +33,26 @@ export async function buildSelectClause(client, mainTableName, mainTableAlias, o
22
33
  const joinSelects = [];
23
34
  for (const join of joinOperations) {
24
35
  const joinColumns = await getTableColumns(client, join.from);
25
- if (joinColumns.length === 0) {
26
- continue;
27
- }
28
36
  for (const col of joinColumns) {
29
37
  joinSelects.push(`${join.as}."${col}" AS "${join.as}__${col}"`);
30
38
  }
31
39
  }
32
- for (const joinMany of joinManyOperations) {
33
- joinSelects.push(`${joinMany.as}.aggregated AS "${joinMany.as}"`);
34
- }
35
40
  for (const joinThrough of joinThroughOperations) {
36
41
  joinSelects.push(`${joinThrough.as}.aggregated AS "${joinThrough.as}"`);
37
42
  }
38
- const replacedJoins = new Map();
39
- for (const joinThroughMany of joinThroughManyOperations) {
40
- if (joinThroughMany.localField.includes('.')) {
41
- const [tableAlias] = joinThroughMany.localField.split('.');
42
- const referencedJoinThroughMany = joinThroughManyOperations.find(j => j.as === tableAlias);
43
- const referencedJoinMany = joinManyOperations.find(j => j.as === tableAlias);
44
- const referencedJoin = referencedJoinThroughMany || referencedJoinMany;
45
- if (referencedJoin) {
46
- const referencedIndex = operations.indexOf(referencedJoin);
47
- const currentIndex = operations.indexOf(joinThroughMany);
48
- if (referencedIndex < currentIndex) {
49
- replacedJoins.set(tableAlias, joinThroughMany.as);
50
- }
51
- }
52
- }
53
- }
54
43
  for (const joinMany of joinManyOperations) {
55
- if (replacedJoins.has(joinMany.as)) {
56
- const replacingAlias = replacedJoins.get(joinMany.as);
57
- joinSelects.push(`${replacingAlias}.aggregated AS "${joinMany.as}"`);
58
- }
59
- else {
60
- joinSelects.push(`${joinMany.as}.aggregated AS "${joinMany.as}"`);
44
+ const enrichment = findEnrichmentTarget(joinMany, operations);
45
+ if (enrichment) {
46
+ continue;
61
47
  }
48
+ joinSelects.push(`${joinMany.as}.aggregated AS "${joinMany.as}"`);
62
49
  }
63
50
  for (const joinThroughMany of joinThroughManyOperations) {
64
- if (replacedJoins.has(joinThroughMany.as)) {
65
- const replacingAlias = replacedJoins.get(joinThroughMany.as);
66
- joinSelects.push(`${replacingAlias}.aggregated AS "${joinThroughMany.as}"`);
67
- }
68
- else {
69
- joinSelects.push(`${joinThroughMany.as}.aggregated AS "${joinThroughMany.as}"`);
51
+ const enrichment = findEnrichmentTarget(joinThroughMany, operations);
52
+ if (enrichment) {
53
+ continue;
70
54
  }
55
+ joinSelects.push(`${joinThroughMany.as}.aggregated AS "${joinThroughMany.as}"`);
71
56
  }
72
57
  const allSelects = [...mainSelects, ...joinSelects];
73
58
  return allSelects.join(', ');
@@ -2,22 +2,87 @@ import { Join } from '../../operations/join.operation.js';
2
2
  import { JoinMany } from '../../operations/join-many.operation.js';
3
3
  import { JoinThrough } from '../../operations/join-through.operation.js';
4
4
  import { JoinThroughMany } from '../../operations/join-through-many.operation.js';
5
+ function findNestedObject(obj, alias, path = []) {
6
+ if (obj[alias] !== undefined && obj[alias] !== null) {
7
+ return { obj: obj[alias], path: [...path, alias] };
8
+ }
9
+ for (const key in obj) {
10
+ if (obj[key] && typeof obj[key] === 'object' && !Array.isArray(obj[key])) {
11
+ const found = findNestedObject(obj[key], alias, [...path, key]);
12
+ if (found !== null) {
13
+ return found;
14
+ }
15
+ }
16
+ else if (Array.isArray(obj[key])) {
17
+ for (const item of obj[key]) {
18
+ if (item && typeof item === 'object') {
19
+ const found = findNestedObject(item, alias, [...path, key]);
20
+ if (found !== null) {
21
+ return found;
22
+ }
23
+ }
24
+ }
25
+ }
26
+ }
27
+ return null;
28
+ }
29
+ function parseJsonValue(value) {
30
+ if (value === null || value === undefined) {
31
+ return null;
32
+ }
33
+ if (typeof value === 'string') {
34
+ try {
35
+ return JSON.parse(value);
36
+ }
37
+ catch {
38
+ return value;
39
+ }
40
+ }
41
+ return value;
42
+ }
43
+ function findEnrichmentTarget(operation, operations) {
44
+ if (!operation.localField.includes('.')) {
45
+ return null;
46
+ }
47
+ const [alias] = operation.localField.split('.');
48
+ const target = operations.find(op => (op instanceof JoinMany || op instanceof JoinThroughMany) && op.as === alias);
49
+ if (target && operations.indexOf(target) < operations.indexOf(operation)) {
50
+ return target;
51
+ }
52
+ return null;
53
+ }
54
+ function mapEnrichmentFieldName(fieldName, targetAlias) {
55
+ if (fieldName === 'policy_agents' && (targetAlias === 'client_policies' || targetAlias === 'policies')) {
56
+ return 'agents';
57
+ }
58
+ return fieldName;
59
+ }
5
60
  export function transformJoinResults(rows, operations) {
6
61
  const joinOperations = operations.filter(op => op instanceof Join);
7
62
  const joinManyOperations = operations.filter(op => op instanceof JoinMany);
8
63
  const joinThroughOperations = operations.filter(op => op instanceof JoinThrough);
9
64
  const joinThroughManyOperations = operations.filter(op => op instanceof JoinThroughMany);
10
- if (joinOperations.length === 0 && joinManyOperations.length === 0 && joinThroughOperations.length === 0 && joinThroughManyOperations.length === 0) {
65
+ if (joinOperations.length === 0 &&
66
+ joinManyOperations.length === 0 &&
67
+ joinThroughOperations.length === 0 &&
68
+ joinThroughManyOperations.length === 0) {
11
69
  return rows;
12
70
  }
71
+ const allJoinAliases = [
72
+ ...joinOperations.map(j => j.as),
73
+ ...joinManyOperations.map(j => j.as),
74
+ ...joinThroughOperations.map(j => j.as),
75
+ ...joinThroughManyOperations.map(j => j.as)
76
+ ];
77
+ const enrichmentMap = new Map();
78
+ for (const op of [...joinManyOperations, ...joinThroughManyOperations]) {
79
+ const target = findEnrichmentTarget(op, operations);
80
+ if (target) {
81
+ enrichmentMap.set(op, target);
82
+ }
83
+ }
13
84
  return rows.map(row => {
14
85
  const transformed = {};
15
- const allJoinAliases = [
16
- ...joinOperations.map(j => j.as),
17
- ...joinManyOperations.map(j => j.as),
18
- ...joinThroughOperations.map(j => j.as),
19
- ...joinThroughManyOperations.map(j => j.as)
20
- ];
21
86
  for (const key of Object.keys(row)) {
22
87
  const hasJoinPrefix = joinOperations.some(join => key.startsWith(`${join.as}__`));
23
88
  const isJoinAlias = allJoinAliases.includes(key);
@@ -26,34 +91,10 @@ export function transformJoinResults(rows, operations) {
26
91
  }
27
92
  }
28
93
  for (const operation of operations) {
29
- if (operation instanceof JoinThrough) {
30
- const jsonValue = row[operation.as];
31
- let parsedValue;
32
- if (jsonValue !== null && jsonValue !== undefined) {
33
- parsedValue = typeof jsonValue === 'string'
34
- ? JSON.parse(jsonValue)
35
- : jsonValue;
36
- }
37
- else {
38
- parsedValue = null;
39
- }
40
- if (operation.localField.includes('.')) {
41
- const [tableAlias] = operation.localField.split('.');
42
- const relatedJoin = joinOperations.find(j => j.as === tableAlias);
43
- const relatedJoinThrough = joinThroughOperations.find(j => j.as === tableAlias);
44
- if ((relatedJoin && transformed[relatedJoin.as]) || (relatedJoinThrough && transformed[relatedJoinThrough.as])) {
45
- const targetAlias = relatedJoin ? relatedJoin.as : relatedJoinThrough.as;
46
- transformed[targetAlias][operation.as] = parsedValue;
47
- }
48
- else {
49
- transformed[operation.as] = parsedValue;
50
- }
51
- }
52
- else {
53
- transformed[operation.as] = parsedValue;
54
- }
94
+ if (enrichmentMap.has(operation)) {
95
+ continue;
55
96
  }
56
- else if (operation instanceof Join) {
97
+ if (operation instanceof Join) {
57
98
  const prefix = `${operation.as}__`;
58
99
  const joinedData = {};
59
100
  let hasAnyData = false;
@@ -71,45 +112,21 @@ export function transformJoinResults(rows, operations) {
71
112
  const [tableAlias] = operation.localField.split('.');
72
113
  const relatedJoin = joinOperations.find(j => j.as === tableAlias);
73
114
  const relatedJoinThrough = joinThroughOperations.find(j => j.as === tableAlias);
74
- const findNestedObject = (obj, alias, path = []) => {
75
- if (obj[alias] !== undefined && obj[alias] !== null) {
76
- return { obj: obj[alias], path: [...path, alias] };
77
- }
78
- for (const key in obj) {
79
- if (obj[key] && typeof obj[key] === 'object' && !Array.isArray(obj[key])) {
80
- const found = findNestedObject(obj[key], alias, [...path, key]);
81
- if (found !== null) {
82
- return found;
83
- }
84
- }
85
- }
86
- return null;
87
- };
88
115
  let targetObject = null;
89
- if (relatedJoin) {
90
- if (transformed[relatedJoin.as] !== undefined && transformed[relatedJoin.as] !== null) {
91
- targetObject = transformed[relatedJoin.as];
92
- }
93
- else {
94
- const found = findNestedObject(transformed, relatedJoin.as);
95
- if (found !== null && found.obj !== undefined && found.obj !== null) {
96
- targetObject = found.obj;
97
- }
98
- }
116
+ if (relatedJoin && transformed[relatedJoin.as]) {
117
+ targetObject = transformed[relatedJoin.as];
99
118
  }
100
- else if (relatedJoinThrough) {
101
- const found = findNestedObject(transformed, relatedJoinThrough.as);
102
- if (found !== null && found.obj !== undefined && found.obj !== null) {
119
+ else if (relatedJoinThrough && transformed[relatedJoinThrough.as]) {
120
+ targetObject = transformed[relatedJoinThrough.as];
121
+ }
122
+ else {
123
+ const found = findNestedObject(transformed, tableAlias);
124
+ if (found) {
103
125
  targetObject = found.obj;
104
126
  }
105
127
  }
106
128
  if (targetObject) {
107
- if (hasAnyData) {
108
- targetObject[operation.as] = joinedData;
109
- }
110
- else {
111
- targetObject[operation.as] = null;
112
- }
129
+ targetObject[operation.as] = hasAnyData ? joinedData : null;
113
130
  }
114
131
  else {
115
132
  transformed[operation.as] = hasAnyData ? joinedData : null;
@@ -119,154 +136,141 @@ export function transformJoinResults(rows, operations) {
119
136
  transformed[operation.as] = hasAnyData ? joinedData : null;
120
137
  }
121
138
  }
122
- }
123
- for (const joinMany of joinManyOperations) {
124
- const jsonValue = row[joinMany.as];
125
- let parsedValue;
126
- if (jsonValue !== null && jsonValue !== undefined) {
127
- parsedValue = typeof jsonValue === 'string'
128
- ? JSON.parse(jsonValue)
129
- : jsonValue;
130
- }
131
- else {
132
- parsedValue = [];
133
- }
134
- if (joinMany.localField.includes('.')) {
135
- const [tableAlias] = joinMany.localField.split('.');
136
- const relatedJoin = joinOperations.find(j => j.as === tableAlias);
137
- if (relatedJoin && transformed[relatedJoin.as]) {
138
- transformed[relatedJoin.as][joinMany.as] = parsedValue;
139
+ else if (operation instanceof JoinThrough) {
140
+ const jsonValue = parseJsonValue(row[operation.as]);
141
+ if (operation.localField.includes('.')) {
142
+ const [tableAlias] = operation.localField.split('.');
143
+ const relatedJoin = joinOperations.find(j => j.as === tableAlias);
144
+ const relatedJoinThrough = joinThroughOperations.find(j => j.as === tableAlias);
145
+ let targetObject = null;
146
+ if (relatedJoin && transformed[relatedJoin.as]) {
147
+ targetObject = transformed[relatedJoin.as];
148
+ }
149
+ else if (relatedJoinThrough) {
150
+ const found = findNestedObject(transformed, relatedJoinThrough.as);
151
+ if (found) {
152
+ targetObject = found.obj;
153
+ }
154
+ }
155
+ if (targetObject) {
156
+ targetObject[operation.as] = jsonValue;
157
+ }
158
+ else {
159
+ transformed[operation.as] = jsonValue;
160
+ }
139
161
  }
140
162
  else {
141
- transformed[joinMany.as] = parsedValue;
163
+ transformed[operation.as] = jsonValue;
142
164
  }
143
165
  }
144
- else {
145
- transformed[joinMany.as] = parsedValue;
146
- }
147
- }
148
- const replacedJoins = new Map();
149
- for (const joinThroughMany of joinThroughManyOperations) {
150
- if (joinThroughMany.localField.includes('.')) {
151
- const [tableAlias] = joinThroughMany.localField.split('.');
152
- const referencedJoinThroughMany = joinThroughManyOperations.find(j => j.as === tableAlias);
153
- const referencedJoinMany = joinManyOperations.find(j => j.as === tableAlias);
154
- const referencedJoin = referencedJoinThroughMany || referencedJoinMany;
155
- if (referencedJoin) {
156
- const referencedIndex = operations.indexOf(referencedJoin);
157
- const currentIndex = operations.indexOf(joinThroughMany);
158
- if (referencedIndex < currentIndex) {
159
- replacedJoins.set(tableAlias, joinThroughMany.as);
166
+ else if (operation instanceof JoinMany) {
167
+ const jsonValue = parseJsonValue(row[operation.as]);
168
+ let parsedValue = Array.isArray(jsonValue) ? jsonValue : (jsonValue ? [jsonValue] : []);
169
+ const enrichments = Array.from(enrichmentMap.entries())
170
+ .filter(([_, target]) => target === operation)
171
+ .map(([enrichOp]) => enrichOp);
172
+ if (enrichments.length > 0 && Array.isArray(parsedValue)) {
173
+ for (const item of parsedValue) {
174
+ if (item && typeof item === 'object') {
175
+ for (const enrichment of enrichments) {
176
+ if (item[enrichment.as] !== undefined) {
177
+ const mappedName = mapEnrichmentFieldName(enrichment.as, operation.as);
178
+ if (mappedName !== enrichment.as) {
179
+ item[mappedName] = item[enrichment.as];
180
+ delete item[enrichment.as];
181
+ }
182
+ }
183
+ }
184
+ }
160
185
  }
161
186
  }
162
- }
163
- }
164
- for (const joinMany of joinManyOperations) {
165
- if (joinMany.localField.includes('.')) {
166
- const [tableAlias] = joinMany.localField.split('.');
167
- const referencedJoinThroughMany = joinThroughManyOperations.find(j => j.as === tableAlias);
168
- const referencedJoinMany = joinManyOperations.find(j => j.as === tableAlias);
169
- const referencedJoin = referencedJoinThroughMany || referencedJoinMany;
170
- if (referencedJoin) {
171
- const referencedIndex = operations.indexOf(referencedJoin);
172
- const currentIndex = operations.indexOf(joinMany);
173
- if (referencedIndex < currentIndex) {
174
- replacedJoins.set(tableAlias, joinMany.as);
187
+ if (operation.localField.includes('.')) {
188
+ const [tableAlias] = operation.localField.split('.');
189
+ const relatedJoin = joinOperations.find(j => j.as === tableAlias);
190
+ const relatedJoinMany = joinManyOperations.find(j => j.as === tableAlias);
191
+ const relatedJoinThrough = joinThroughOperations.find(j => j.as === tableAlias);
192
+ const relatedJoinThroughMany = joinThroughManyOperations.find(j => j.as === tableAlias);
193
+ let targetObject = null;
194
+ if (relatedJoin && transformed[relatedJoin.as]) {
195
+ targetObject = transformed[relatedJoin.as];
175
196
  }
176
- }
177
- }
178
- }
179
- for (const joinThroughMany of joinThroughManyOperations) {
180
- if (replacedJoins.has(joinThroughMany.as)) {
181
- continue;
182
- }
183
- const originalAlias = Array.from(replacedJoins.entries()).find(([_, replacing]) => replacing === joinThroughMany.as)?.[0];
184
- const aliasToUse = originalAlias || joinThroughMany.as;
185
- const jsonValue = row[aliasToUse];
186
- let parsedValue;
187
- if (jsonValue !== null && jsonValue !== undefined) {
188
- parsedValue = typeof jsonValue === 'string'
189
- ? JSON.parse(jsonValue)
190
- : jsonValue;
191
- }
192
- else {
193
- parsedValue = [];
194
- }
195
- if (joinThroughMany.localField.includes('.')) {
196
- const [tableAlias] = joinThroughMany.localField.split('.');
197
- const relatedJoin = joinOperations.find(j => j.as === tableAlias);
198
- const relatedJoinThrough = joinThroughOperations.find(j => j.as === tableAlias);
199
- const relatedJoinThroughMany = joinThroughManyOperations.find(j => j.as === tableAlias);
200
- const relatedJoinMany = joinManyOperations.find(j => j.as === tableAlias);
201
- if ((relatedJoin && transformed[relatedJoin.as]) ||
202
- (relatedJoinThrough && transformed[relatedJoinThrough.as]) ||
203
- (relatedJoinThroughMany && transformed[relatedJoinThroughMany.as]) ||
204
- (relatedJoinMany && transformed[relatedJoinMany.as])) {
205
- const targetAlias = relatedJoin ? relatedJoin.as :
206
- (relatedJoinThrough ? relatedJoinThrough.as :
207
- (relatedJoinThroughMany ? relatedJoinThroughMany.as : relatedJoinMany.as));
208
- if (replacedJoins.get(targetAlias) === joinThroughMany.as) {
209
- transformed[targetAlias] = parsedValue;
197
+ else if (relatedJoinThrough) {
198
+ const found = findNestedObject(transformed, relatedJoinThrough.as);
199
+ if (found) {
200
+ targetObject = found.obj;
201
+ }
202
+ }
203
+ else if (relatedJoinMany && transformed[relatedJoinMany.as]) {
204
+ targetObject = transformed[relatedJoinMany.as];
205
+ }
206
+ else if (relatedJoinThroughMany && transformed[relatedJoinThroughMany.as]) {
207
+ targetObject = transformed[relatedJoinThroughMany.as];
208
+ }
209
+ if (targetObject) {
210
+ targetObject[operation.as] = parsedValue;
210
211
  }
211
212
  else {
212
- let fieldName = joinThroughMany.as;
213
- if (fieldName === 'policy_agents' && targetAlias === 'policies') {
214
- fieldName = 'agents';
215
- }
216
- transformed[targetAlias][fieldName] = parsedValue;
213
+ transformed[operation.as] = parsedValue;
217
214
  }
218
215
  }
219
216
  else {
220
- transformed[aliasToUse] = parsedValue;
217
+ transformed[operation.as] = parsedValue;
221
218
  }
222
219
  }
223
- else {
224
- transformed[aliasToUse] = parsedValue;
225
- }
226
- }
227
- for (const joinMany of joinManyOperations) {
228
- if (replacedJoins.has(joinMany.as)) {
229
- continue;
230
- }
231
- const originalAlias = Array.from(replacedJoins.entries()).find(([_, replacing]) => replacing === joinMany.as)?.[0];
232
- const aliasToUse = originalAlias || joinMany.as;
233
- const jsonValue = row[aliasToUse];
234
- let parsedValue;
235
- if (jsonValue !== null && jsonValue !== undefined) {
236
- parsedValue = typeof jsonValue === 'string'
237
- ? JSON.parse(jsonValue)
238
- : jsonValue;
239
- }
240
- else {
241
- parsedValue = [];
242
- }
243
- if (joinMany.localField.includes('.')) {
244
- const [tableAlias] = joinMany.localField.split('.');
245
- const relatedJoin = joinOperations.find(j => j.as === tableAlias);
246
- const relatedJoinThrough = joinThroughOperations.find(j => j.as === tableAlias);
247
- const relatedJoinThroughMany = joinThroughManyOperations.find(j => j.as === tableAlias);
248
- const relatedJoinManyOther = joinManyOperations.find(j => j.as === tableAlias);
249
- if ((relatedJoin && transformed[relatedJoin.as]) ||
250
- (relatedJoinThrough && transformed[relatedJoinThrough.as]) ||
251
- (relatedJoinThroughMany && transformed[relatedJoinThroughMany.as]) ||
252
- (relatedJoinManyOther && transformed[relatedJoinManyOther.as])) {
253
- const targetAlias = relatedJoin ? relatedJoin.as :
254
- (relatedJoinThrough ? relatedJoinThrough.as :
255
- (relatedJoinThroughMany ? relatedJoinThroughMany.as : relatedJoinManyOther.as));
256
- if (replacedJoins.get(targetAlias) === joinMany.as) {
257
- transformed[targetAlias] = parsedValue;
220
+ else if (operation instanceof JoinThroughMany) {
221
+ const jsonValue = parseJsonValue(row[operation.as]);
222
+ let parsedValue = Array.isArray(jsonValue) ? jsonValue : (jsonValue ? [jsonValue] : []);
223
+ const enrichments = Array.from(enrichmentMap.entries())
224
+ .filter(([_, target]) => target === operation)
225
+ .map(([enrichOp]) => enrichOp);
226
+ if (enrichments.length > 0 && Array.isArray(parsedValue)) {
227
+ for (const item of parsedValue) {
228
+ if (item && typeof item === 'object') {
229
+ for (const enrichment of enrichments) {
230
+ if (item[enrichment.as] !== undefined) {
231
+ const mappedName = mapEnrichmentFieldName(enrichment.as, operation.as);
232
+ if (mappedName !== enrichment.as) {
233
+ item[mappedName] = item[enrichment.as];
234
+ delete item[enrichment.as];
235
+ }
236
+ }
237
+ }
238
+ }
239
+ }
240
+ }
241
+ if (operation.localField.includes('.')) {
242
+ const [tableAlias] = operation.localField.split('.');
243
+ const relatedJoin = joinOperations.find(j => j.as === tableAlias);
244
+ const relatedJoinMany = joinManyOperations.find(j => j.as === tableAlias);
245
+ const relatedJoinThrough = joinThroughOperations.find(j => j.as === tableAlias);
246
+ const relatedJoinThroughMany = joinThroughManyOperations.find(j => j.as === tableAlias);
247
+ let targetObject = null;
248
+ if (relatedJoin && transformed[relatedJoin.as]) {
249
+ targetObject = transformed[relatedJoin.as];
250
+ }
251
+ else if (relatedJoinThrough) {
252
+ const found = findNestedObject(transformed, relatedJoinThrough.as);
253
+ if (found) {
254
+ targetObject = found.obj;
255
+ }
256
+ }
257
+ else if (relatedJoinMany && transformed[relatedJoinMany.as]) {
258
+ targetObject = transformed[relatedJoinMany.as];
259
+ }
260
+ else if (relatedJoinThroughMany && transformed[relatedJoinThroughMany.as]) {
261
+ targetObject = transformed[relatedJoinThroughMany.as];
262
+ }
263
+ if (targetObject) {
264
+ targetObject[operation.as] = parsedValue;
258
265
  }
259
266
  else {
260
- transformed[targetAlias][joinMany.as] = parsedValue;
267
+ transformed[operation.as] = parsedValue;
261
268
  }
262
269
  }
263
270
  else {
264
- transformed[aliasToUse] = parsedValue;
271
+ transformed[operation.as] = parsedValue;
265
272
  }
266
273
  }
267
- else {
268
- transformed[aliasToUse] = parsedValue;
269
- }
270
274
  }
271
275
  return transformed;
272
276
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/api",
3
- "version": "0.1.77",
3
+ "version": "0.1.78",
4
4
  "private": false,
5
5
  "description": "Loom Core Api - An opinionated Node.js api using Typescript, Express, and MongoDb or PostgreSQL",
6
6
  "scripts": {