@ronin/compiler 0.17.20-leo-ron-1120-experimental-421 → 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 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 (queryType === "count") {
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({
@@ -2309,6 +2345,14 @@ var Transaction = class {
2309
2345
  );
2310
2346
  }
2311
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
+ }
2312
2356
  return result;
2313
2357
  }
2314
2358
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.17.20-leo-ron-1120-experimental-421",
3
+ "version": "0.17.21-corny-pagination-bug-experimental-422",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {