@ronin/compiler 0.17.18 → 0.17.19-corny-pagination-bug-experimental-412
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 +4 -2
- package/dist/index.js +58 -19
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -484,11 +484,13 @@ declare class Transaction {
|
|
484
484
|
*
|
485
485
|
* @returns A formatted RONIN result for a particular query.
|
486
486
|
*/
|
487
|
-
formatIndividualResult<RecordType>(queryType: QueryType, queryInstructions: CombinedInstructions, model: Model, rows: Array<Array<RawRow>>, selectedFields: Array<InternalModelField
|
487
|
+
formatIndividualResult<RecordType>(queryType: QueryType, queryInstructions: CombinedInstructions, model: Model, rows: Array<Array<RawRow>>, selectedFields: Array<InternalModelField & {
|
488
|
+
drop?: boolean;
|
489
|
+
}>, single: boolean): RegularResult<RecordType>;
|
488
490
|
formatResults<RecordType>(results: Array<Array<ObjectRow>>, raw?: false): Array<Result<RecordType>>;
|
489
491
|
formatResults<RecordType>(results: Array<Array<RawRow>>, raw?: true): Array<Result<RecordType>>;
|
490
492
|
}
|
491
493
|
|
492
494
|
declare const CLEAN_ROOT_MODEL: PublicModel;
|
493
495
|
|
494
|
-
export { type AddInstructions, type AddQuery, type AddInstructions as AddQueryInstructions, type AlterQuery, type CombinedInstructions, type CountInstructions, type CountQuery, type CountInstructions as CountQueryInstructions, type CreateQuery, DDL_QUERY_TYPES, DML_QUERY_TYPES, DML_QUERY_TYPES_READ, DML_QUERY_TYPES_WRITE, type DropQuery, type ExpandedResult, type GetInstructions, type GetQuery, type GetInstructions as GetQueryInstructions, type PublicModel as Model, type ModelField, type ModelIndex, type ModelPreset, type ModelTrigger, QUERY_SYMBOLS, QUERY_TYPES, type Query, type QueryInstructionType as QueryInstruction, type QuerySchemaType, type QueryType, CLEAN_ROOT_MODEL as ROOT_MODEL, type RegularResult, type RemoveInstructions, type RemoveQuery, type RemoveInstructions as RemoveQueryInstructions, type Result, type ResultRecord, RoninError, type SetInstructions, type SetQuery, type SetInstructions as SetQueryInstructions, type Statement, type StoredObject, Transaction, type WithInstruction, getQuerySymbol };
|
496
|
+
export { type AddInstructions, type AddQuery, type AddInstructions as AddQueryInstructions, type AlterQuery, type CombinedInstructions, type CountInstructions, type CountQuery, type CountInstructions as CountQueryInstructions, type CreateQuery, DDL_QUERY_TYPES, DML_QUERY_TYPES, DML_QUERY_TYPES_READ, DML_QUERY_TYPES_WRITE, type DropQuery, type ExpandedResult, type GetInstructions, type GetQuery, type GetInstructions as GetQueryInstructions, type PublicModel as Model, type ModelField, type ModelIndex, type ModelPreset, type ModelTrigger, QUERY_SYMBOLS, QUERY_TYPES, type Query, type QueryInstructionType as QueryInstruction, type QuerySchemaType, type QueryType, CLEAN_ROOT_MODEL as ROOT_MODEL, type RegularResult, type RemoveInstructions, type RemoveQuery, type RemoveInstructions as RemoveQueryInstructions, type Result, type ResultRecord, type ResultRecordBase, RoninError, type SetInstructions, type SetQuery, type SetInstructions as SetQueryInstructions, type Statement, type StoredObject, Transaction, type WithInstruction, getQuerySymbol };
|
package/dist/index.js
CHANGED
@@ -379,12 +379,9 @@ var handleOrderedBy = (model, instruction) => {
|
|
379
379
|
};
|
380
380
|
|
381
381
|
// src/instructions/selecting.ts
|
382
|
-
var handleSelecting = (models, model, statementParams, single, instructions, options = { inlineDefaults: false }) => {
|
382
|
+
var handleSelecting = (models, model, statementParams, single, instructions, queryType, options = { inlineDefaults: false }) => {
|
383
383
|
let isJoining = false;
|
384
|
-
const selectedFields = filterSelectedFields(
|
385
|
-
model,
|
386
|
-
instructions.selecting
|
387
|
-
).filter((field) => !(field.type === "link" && field.kind === "many")).map((field) => {
|
384
|
+
const selectedFields = filterSelectedFields(model, instructions.selecting).filter((field) => !(field.type === "link" && field.kind === "many")).map((field) => {
|
388
385
|
const newField = { ...field, mountingPath: field.slug };
|
389
386
|
if (options.mountingPath && options.mountingPath !== "ronin_root") {
|
390
387
|
newField.mountingPath = `${options.mountingPath.replace(/\{\d+\}/g, "")}.${field.slug}`;
|
@@ -403,9 +400,9 @@ var handleSelecting = (models, model, statementParams, single, instructions, opt
|
|
403
400
|
for (const [key, value] of Object.entries(flatObject)) {
|
404
401
|
const symbol2 = getQuerySymbol(value);
|
405
402
|
if (symbol2?.type === "query") {
|
406
|
-
const { queryType, queryModel, queryInstructions } = splitQuery(symbol2.value);
|
403
|
+
const { queryType: queryType2, queryModel, queryInstructions } = splitQuery(symbol2.value);
|
407
404
|
const subQueryModel = getModelBySlug(models, queryModel);
|
408
|
-
if (
|
405
|
+
if (queryType2 === "count") {
|
409
406
|
const subSelect = compileQueryInput(symbol2.value, models, statementParams, {
|
410
407
|
parentModel: { ...model, tableAlias: model.table },
|
411
408
|
inlineDefaults: options.inlineDefaults
|
@@ -432,6 +429,7 @@ var handleSelecting = (models, model, statementParams, single, instructions, opt
|
|
432
429
|
selecting: queryInstructions?.selecting,
|
433
430
|
including: queryInstructions?.including
|
434
431
|
},
|
432
|
+
queryType2,
|
435
433
|
{ ...options, mountingPath: subMountingPath }
|
436
434
|
);
|
437
435
|
if (nestedColumns !== "*") joinedColumns.push(nestedColumns);
|
@@ -454,6 +452,14 @@ var handleSelecting = (models, model, statementParams, single, instructions, opt
|
|
454
452
|
});
|
455
453
|
}
|
456
454
|
}
|
455
|
+
if (queryType === "get" && !single && !selectedFields.some((field) => field.slug === "ronin.createdAt")) {
|
456
|
+
selectedFields.push({
|
457
|
+
...getSystemFields(model.idPrefix)["ronin.createdAt"],
|
458
|
+
slug: "ronin.createdAt",
|
459
|
+
drop: true,
|
460
|
+
mountingPath: "ronin.createdAt"
|
461
|
+
});
|
462
|
+
}
|
457
463
|
const columns = selectedFields.map((selectedField) => {
|
458
464
|
if (selectedField.mountedValue) {
|
459
465
|
return `${selectedField.mountedValue} as "${selectedField.slug}"`;
|
@@ -1077,6 +1083,18 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
|
|
1077
1083
|
}
|
1078
1084
|
});
|
1079
1085
|
}
|
1086
|
+
if (!single && (queryType === "get" && instructions?.limitedTo || queryType === "count" && (instructions?.before || instructions?.after))) {
|
1087
|
+
instructions = instructions || {};
|
1088
|
+
instructions.orderedBy = instructions.orderedBy || {};
|
1089
|
+
instructions.orderedBy.ascending = instructions.orderedBy.ascending || [];
|
1090
|
+
instructions.orderedBy.descending = instructions.orderedBy.descending || [];
|
1091
|
+
if (![
|
1092
|
+
...instructions.orderedBy.ascending,
|
1093
|
+
...instructions.orderedBy.descending
|
1094
|
+
].includes("ronin.createdAt")) {
|
1095
|
+
instructions.orderedBy.descending.push("ronin.createdAt");
|
1096
|
+
}
|
1097
|
+
}
|
1080
1098
|
const { columns, isJoining, selectedFields } = handleSelecting(
|
1081
1099
|
models,
|
1082
1100
|
model,
|
@@ -1086,6 +1104,7 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
|
|
1086
1104
|
selecting: instructions?.selecting,
|
1087
1105
|
including: instructions?.including
|
1088
1106
|
},
|
1107
|
+
queryType,
|
1089
1108
|
// biome-ignore lint/complexity/useSimplifiedLogicExpression: This is needed.
|
1090
1109
|
{ inlineDefaults: options?.inlineDefaults || false }
|
1091
1110
|
);
|
@@ -1156,18 +1175,6 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
|
|
1156
1175
|
);
|
1157
1176
|
if (withStatement.length > 0) conditions.push(withStatement);
|
1158
1177
|
}
|
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
1178
|
if (instructions && (typeof instructions.before !== "undefined" || typeof instructions.after !== "undefined")) {
|
1172
1179
|
if (single) {
|
1173
1180
|
throw new RoninError({
|
@@ -2308,6 +2315,38 @@ var Transaction = class {
|
|
2308
2315
|
);
|
2309
2316
|
}
|
2310
2317
|
}
|
2318
|
+
const fieldsToDrop = selectedFields.filter((field) => field.drop === true);
|
2319
|
+
const deleteNestedProperty = (obj, path) => {
|
2320
|
+
const parts = path.split(".");
|
2321
|
+
const lastPart = parts.pop();
|
2322
|
+
let current = obj;
|
2323
|
+
for (const part of parts) {
|
2324
|
+
if (!current || typeof current !== "object") return;
|
2325
|
+
const currentAsRecord = current;
|
2326
|
+
if (!(part in currentAsRecord)) return;
|
2327
|
+
current = currentAsRecord[part];
|
2328
|
+
}
|
2329
|
+
if (typeof current === "object" && current !== null) {
|
2330
|
+
delete current[lastPart];
|
2331
|
+
}
|
2332
|
+
if (parts.length > 0 && typeof current === "object" && current !== null && Object.keys(current).length === 0) {
|
2333
|
+
let temp = obj;
|
2334
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
2335
|
+
temp = temp[parts[i]];
|
2336
|
+
}
|
2337
|
+
const lastPart2 = parts.at(-1);
|
2338
|
+
if (lastPart2) {
|
2339
|
+
delete temp[lastPart2];
|
2340
|
+
}
|
2341
|
+
}
|
2342
|
+
};
|
2343
|
+
if (fieldsToDrop.length > 0) {
|
2344
|
+
for (const record of result.records) {
|
2345
|
+
for (const field of fieldsToDrop) {
|
2346
|
+
deleteNestedProperty(record, field.slug);
|
2347
|
+
}
|
2348
|
+
}
|
2349
|
+
}
|
2311
2350
|
return result;
|
2312
2351
|
}
|
2313
2352
|
/**
|