@ronin/compiler 0.14.2-leo-ron-1099-1-experimental-321 → 0.14.3-leo-ron-1099-1-experimental-322
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +25 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -26,6 +26,10 @@ var CURRENT_TIME_EXPRESSION = {
|
|
26
26
|
var composeIncludedTableAlias = (fieldSlug) => {
|
27
27
|
return `including_${fieldSlug}`;
|
28
28
|
};
|
29
|
+
var MOUNTING_PATH_SUFFIX = /(.*?)(\{(\d+)\})?$/;
|
30
|
+
var composeMountingPath = (input) => {
|
31
|
+
return input.replace(MOUNTING_PATH_SUFFIX, (_, p, __, n) => `${p}{${n ? +n + 1 : 1}}`);
|
32
|
+
};
|
29
33
|
var MODEL_ENTITY_ERROR_CODES = {
|
30
34
|
field: "FIELD_NOT_FOUND",
|
31
35
|
index: "INDEX_NOT_FOUND",
|
@@ -299,7 +303,7 @@ var handleFor = (model, instructions) => {
|
|
299
303
|
};
|
300
304
|
|
301
305
|
// src/instructions/including.ts
|
302
|
-
var handleIncluding = (models, model, statementParams, single, instruction) => {
|
306
|
+
var handleIncluding = (models, model, statementParams, single, instruction, options = {}) => {
|
303
307
|
let statement = "";
|
304
308
|
let tableSubQuery;
|
305
309
|
for (const ephemeralFieldSlug in instruction) {
|
@@ -311,8 +315,9 @@ var handleIncluding = (models, model, statementParams, single, instruction) => {
|
|
311
315
|
const relatedModel = getModelBySlug(models, queryModel);
|
312
316
|
let joinType = "LEFT";
|
313
317
|
let relatedTableSelector = `"${relatedModel.table}"`;
|
314
|
-
const tableAlias = composeIncludedTableAlias(ephemeralFieldSlug);
|
315
318
|
const subSingle = queryModel !== relatedModel.pluralSlug;
|
319
|
+
const subMountingPath = ephemeralFieldSlug === "ronin_root" ? options.mountingPath ? composeMountingPath(options.mountingPath) : void 0 : `${options?.mountingPath ? `${options?.mountingPath}.` : ""}${subSingle ? ephemeralFieldSlug : `${ephemeralFieldSlug}[0]`}`;
|
320
|
+
const tableAlias = composeIncludedTableAlias(subMountingPath || ephemeralFieldSlug);
|
316
321
|
if (!modifiableQueryInstructions?.with) {
|
317
322
|
joinType = "CROSS";
|
318
323
|
if (subSingle) {
|
@@ -332,7 +337,7 @@ var handleIncluding = (models, model, statementParams, single, instruction) => {
|
|
332
337
|
);
|
333
338
|
relatedTableSelector = `(${subSelect.main.statement})`;
|
334
339
|
}
|
335
|
-
statement += `${joinType} JOIN ${relatedTableSelector} as ${tableAlias}`;
|
340
|
+
statement += `${joinType} JOIN ${relatedTableSelector} as "${tableAlias}"`;
|
336
341
|
model.tableAlias = model.tableAlias || model.table;
|
337
342
|
if (joinType === "LEFT") {
|
338
343
|
const subStatement = composeConditions(
|
@@ -356,7 +361,8 @@ var handleIncluding = (models, model, statementParams, single, instruction) => {
|
|
356
361
|
{ ...relatedModel, tableAlias },
|
357
362
|
statementParams,
|
358
363
|
subSingle,
|
359
|
-
modifiableQueryInstructions.including
|
364
|
+
modifiableQueryInstructions.including,
|
365
|
+
{ mountingPath: subMountingPath }
|
360
366
|
);
|
361
367
|
statement += ` ${subIncluding.statement}`;
|
362
368
|
}
|
@@ -409,7 +415,7 @@ var handleSelecting = (models, model, statementParams, single, instructions, opt
|
|
409
415
|
).filter((field) => !(field.type === "link" && field.kind === "many")).map((field) => {
|
410
416
|
const newField = { ...field, mountingPath: field.slug };
|
411
417
|
if (options.mountingPath) {
|
412
|
-
newField.mountingPath = `${options.mountingPath}.${field.slug}`;
|
418
|
+
newField.mountingPath = `${options.mountingPath.replace(/\{\d+\}/g, "")}.${field.slug}`;
|
413
419
|
}
|
414
420
|
return newField;
|
415
421
|
});
|
@@ -430,11 +436,11 @@ var handleSelecting = (models, model, statementParams, single, instructions, opt
|
|
430
436
|
const subQueryModel = getModelBySlug(models, queryModel);
|
431
437
|
isJoining = true;
|
432
438
|
if (queryInstructions?.selecting) options.expandColumns = true;
|
433
|
-
const tableAlias = composeIncludedTableAlias(key);
|
434
439
|
const subSingle = queryModel !== subQueryModel.pluralSlug;
|
435
440
|
if (!model.tableAlias)
|
436
441
|
model.tableAlias = single && !subSingle ? `sub_${model.table}` : model.table;
|
437
|
-
const subMountingPath = key === "ronin_root" ? options.mountingPath : `${options?.mountingPath ? `${options?.mountingPath}.` : ""}${subSingle ? key : `${key}[0]`}`;
|
442
|
+
const subMountingPath = key === "ronin_root" ? options.mountingPath ? composeMountingPath(options.mountingPath) : void 0 : `${options?.mountingPath ? `${options?.mountingPath}.` : ""}${subSingle ? key : `${key}[0]`}`;
|
443
|
+
const tableAlias = composeIncludedTableAlias(subMountingPath || key);
|
438
444
|
const { columns: nestedColumns, selectedFields: nestedSelectedFields } = handleSelecting(
|
439
445
|
models,
|
440
446
|
{ ...subQueryModel, tableAlias },
|
@@ -2022,7 +2028,18 @@ var Transaction = class {
|
|
2022
2028
|
for (const arrayField of joinFields.values()) {
|
2023
2029
|
const currentValue = existingRecord[arrayField];
|
2024
2030
|
const newValue = record[arrayField];
|
2025
|
-
|
2031
|
+
for (const newRecord of newValue) {
|
2032
|
+
if ("id" in newRecord) {
|
2033
|
+
const existingIndex = currentValue.findIndex((value) => {
|
2034
|
+
return value.id === newRecord.id;
|
2035
|
+
});
|
2036
|
+
if (existingIndex > -1) {
|
2037
|
+
Object.assign(currentValue[existingIndex], newRecord);
|
2038
|
+
continue;
|
2039
|
+
}
|
2040
|
+
}
|
2041
|
+
currentValue.push(newRecord);
|
2042
|
+
}
|
2026
2043
|
}
|
2027
2044
|
}
|
2028
2045
|
return single ? records[0] : records;
|
package/package.json
CHANGED