@ronin/compiler 0.17.20 → 0.17.21-corny-pagination-bug-experimental-422
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.d.ts +2 -0
- package/dist/index.js +66 -21
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -258,6 +258,8 @@ type InternalModelField = ModelField & {
|
|
258
258
|
mountingPath: string;
|
259
259
|
/** A custom value that was provided in the query, which is not stored in the DB. */
|
260
260
|
mountedValue?: unknown;
|
261
|
+
/** Indicator if the field should be excluded from the final records. */
|
262
|
+
excluded?: boolean;
|
261
263
|
};
|
262
264
|
type ModelIndexField<T extends ModelEntityList<ModelField> = ModelEntityList<ModelField>> = {
|
263
265
|
/** The collating sequence used for text placed inside the field. */
|
package/dist/index.js
CHANGED
@@ -163,6 +163,30 @@ var splitQuery = (query) => {
|
|
163
163
|
const queryInstructions = query[queryType][queryModel];
|
164
164
|
return { queryType, queryModel, queryInstructions };
|
165
165
|
};
|
166
|
+
function deleteNestedProperty(obj, path) {
|
167
|
+
const parts = path.split(".");
|
168
|
+
const lastPart = parts.pop();
|
169
|
+
let current = obj;
|
170
|
+
for (const part of parts) {
|
171
|
+
if (!current || typeof current !== "object") return;
|
172
|
+
const currentAsRecord = current;
|
173
|
+
if (!(part in currentAsRecord)) return;
|
174
|
+
current = currentAsRecord[part];
|
175
|
+
}
|
176
|
+
if (typeof current === "object" && current !== null) {
|
177
|
+
delete current[lastPart];
|
178
|
+
}
|
179
|
+
if (parts.length > 0 && typeof current === "object" && current !== null && Object.keys(current).length === 0) {
|
180
|
+
let temp = obj;
|
181
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
182
|
+
temp = temp[parts[i]];
|
183
|
+
}
|
184
|
+
const lastPart2 = parts.at(-1);
|
185
|
+
if (lastPart2) {
|
186
|
+
delete temp[lastPart2];
|
187
|
+
}
|
188
|
+
}
|
189
|
+
}
|
166
190
|
|
167
191
|
// src/utils/pagination.ts
|
168
192
|
var CURSOR_SEPARATOR = ",";
|
@@ -379,7 +403,7 @@ var handleOrderedBy = (model, instruction) => {
|
|
379
403
|
};
|
380
404
|
|
381
405
|
// src/instructions/selecting.ts
|
382
|
-
var handleSelecting = (models, model, statementParams, single, instructions, options = { inlineDefaults: false }) => {
|
406
|
+
var handleSelecting = (models, model, statementParams, single, instructions, queryType, options = { inlineDefaults: false }) => {
|
383
407
|
let isJoining = false;
|
384
408
|
const selectedFields = filterSelectedFields(
|
385
409
|
model,
|
@@ -403,9 +427,9 @@ var handleSelecting = (models, model, statementParams, single, instructions, opt
|
|
403
427
|
for (const [key, value] of Object.entries(flatObject)) {
|
404
428
|
const symbol2 = getQuerySymbol(value);
|
405
429
|
if (symbol2?.type === "query") {
|
406
|
-
const { queryType, queryModel, queryInstructions } = splitQuery(symbol2.value);
|
430
|
+
const { queryType: queryType2, queryModel, queryInstructions } = splitQuery(symbol2.value);
|
407
431
|
const subQueryModel = getModelBySlug(models, queryModel);
|
408
|
-
if (
|
432
|
+
if (queryType2 === "count") {
|
409
433
|
const subSelect = compileQueryInput(symbol2.value, models, statementParams, {
|
410
434
|
parentModel: { ...model, tableAlias: model.table },
|
411
435
|
inlineDefaults: options.inlineDefaults
|
@@ -430,8 +454,10 @@ var handleSelecting = (models, model, statementParams, single, instructions, opt
|
|
430
454
|
subSingle,
|
431
455
|
{
|
432
456
|
selecting: queryInstructions?.selecting,
|
433
|
-
including: queryInstructions?.including
|
457
|
+
including: queryInstructions?.including,
|
458
|
+
limitedTo: instructions.limitedTo
|
434
459
|
},
|
460
|
+
queryType2,
|
435
461
|
{ ...options, mountingPath: subMountingPath }
|
436
462
|
);
|
437
463
|
if (nestedColumns !== "*") joinedColumns.push(nestedColumns);
|
@@ -454,6 +480,14 @@ var handleSelecting = (models, model, statementParams, single, instructions, opt
|
|
454
480
|
});
|
455
481
|
}
|
456
482
|
}
|
483
|
+
if (queryType === "get" && !single && !selectedFields.some((field) => field.slug === "ronin.createdAt") && instructions.limitedTo) {
|
484
|
+
selectedFields.push({
|
485
|
+
...getSystemFields(model.idPrefix)["ronin.createdAt"],
|
486
|
+
slug: "ronin.createdAt",
|
487
|
+
excluded: true,
|
488
|
+
mountingPath: "ronin.createdAt"
|
489
|
+
});
|
490
|
+
}
|
457
491
|
const columns = selectedFields.map((selectedField) => {
|
458
492
|
if (selectedField.mountedValue) {
|
459
493
|
return `${selectedField.mountedValue} as "${selectedField.slug}"`;
|
@@ -1077,6 +1111,18 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
|
|
1077
1111
|
}
|
1078
1112
|
});
|
1079
1113
|
}
|
1114
|
+
if (!single && (queryType === "get" && instructions?.limitedTo || queryType === "count" && (instructions?.before || instructions?.after))) {
|
1115
|
+
instructions = instructions || {};
|
1116
|
+
instructions.orderedBy = instructions.orderedBy || {};
|
1117
|
+
instructions.orderedBy.ascending = instructions.orderedBy.ascending || [];
|
1118
|
+
instructions.orderedBy.descending = instructions.orderedBy.descending || [];
|
1119
|
+
if (![
|
1120
|
+
...instructions.orderedBy.ascending,
|
1121
|
+
...instructions.orderedBy.descending
|
1122
|
+
].includes("ronin.createdAt")) {
|
1123
|
+
instructions.orderedBy.descending.push("ronin.createdAt");
|
1124
|
+
}
|
1125
|
+
}
|
1080
1126
|
const { columns, isJoining, selectedFields } = handleSelecting(
|
1081
1127
|
models,
|
1082
1128
|
model,
|
@@ -1084,8 +1130,10 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
|
|
1084
1130
|
single,
|
1085
1131
|
{
|
1086
1132
|
selecting: instructions?.selecting,
|
1087
|
-
including: instructions?.including
|
1133
|
+
including: instructions?.including,
|
1134
|
+
limitedTo: instructions?.limitedTo
|
1088
1135
|
},
|
1136
|
+
queryType,
|
1089
1137
|
// biome-ignore lint/complexity/useSimplifiedLogicExpression: This is needed.
|
1090
1138
|
{ inlineDefaults: options?.inlineDefaults || false }
|
1091
1139
|
);
|
@@ -1156,18 +1204,6 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
|
|
1156
1204
|
);
|
1157
1205
|
if (withStatement.length > 0) conditions.push(withStatement);
|
1158
1206
|
}
|
1159
|
-
if (!single && (queryType === "get" && instructions?.limitedTo || queryType === "count" && (instructions?.before || instructions?.after))) {
|
1160
|
-
instructions = instructions || {};
|
1161
|
-
instructions.orderedBy = instructions.orderedBy || {};
|
1162
|
-
instructions.orderedBy.ascending = instructions.orderedBy.ascending || [];
|
1163
|
-
instructions.orderedBy.descending = instructions.orderedBy.descending || [];
|
1164
|
-
if (![
|
1165
|
-
...instructions.orderedBy.ascending,
|
1166
|
-
...instructions.orderedBy.descending
|
1167
|
-
].includes("ronin.createdAt")) {
|
1168
|
-
instructions.orderedBy.descending.push("ronin.createdAt");
|
1169
|
-
}
|
1170
|
-
}
|
1171
1207
|
if (instructions && (typeof instructions.before !== "undefined" || typeof instructions.after !== "undefined")) {
|
1172
1208
|
if (single) {
|
1173
1209
|
throw new RoninError({
|
@@ -1577,10 +1613,10 @@ var ROOT_MODEL = {
|
|
1577
1613
|
// Providing an empty object as a default value allows us to use `json_insert`
|
1578
1614
|
// without needing to fall back to an empty object in the insertion statement,
|
1579
1615
|
// which makes the statement shorter.
|
1580
|
-
fields: { type: "json", defaultValue:
|
1581
|
-
indexes: { type: "json", defaultValue:
|
1582
|
-
triggers: { type: "json", defaultValue:
|
1583
|
-
presets: { type: "json", defaultValue:
|
1616
|
+
fields: { type: "json", defaultValue: {} },
|
1617
|
+
indexes: { type: "json", defaultValue: {} },
|
1618
|
+
triggers: { type: "json", defaultValue: {} },
|
1619
|
+
presets: { type: "json", defaultValue: {} }
|
1584
1620
|
}
|
1585
1621
|
};
|
1586
1622
|
var ROOT_MODEL_WITH_ATTRIBUTES = addDefaultModelAttributes(ROOT_MODEL, true);
|
@@ -1642,6 +1678,7 @@ var getFieldStatement = (models, model, field) => {
|
|
1642
1678
|
const symbol = getQuerySymbol(field.defaultValue);
|
1643
1679
|
let value = typeof field.defaultValue === "string" ? `'${field.defaultValue}'` : field.defaultValue;
|
1644
1680
|
if (symbol) value = `(${parseFieldExpression(model, "to", symbol.value)})`;
|
1681
|
+
if (field.type === "json") value = `'${JSON.stringify(field.defaultValue)}'`;
|
1645
1682
|
statement += ` DEFAULT ${value}`;
|
1646
1683
|
}
|
1647
1684
|
if (field.type === "string" && field.collation) {
|
@@ -2308,6 +2345,14 @@ var Transaction = class {
|
|
2308
2345
|
);
|
2309
2346
|
}
|
2310
2347
|
}
|
2348
|
+
const fieldsToDrop = selectedFields.filter((field) => field.excluded === true);
|
2349
|
+
if (fieldsToDrop.length > 0) {
|
2350
|
+
for (const record of result.records) {
|
2351
|
+
for (const field of fieldsToDrop) {
|
2352
|
+
deleteNestedProperty(record, field.slug);
|
2353
|
+
}
|
2354
|
+
}
|
2355
|
+
}
|
2311
2356
|
return result;
|
2312
2357
|
}
|
2313
2358
|
/**
|