@ronin/compiler 0.17.21-corny-pagination-bug-experimental-422 → 0.17.21-leo-pagination-bug-experimental-424

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,7 +258,7 @@ 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. */
261
+ /** If this is set, the field is used during formatting, but not exposed afterward. */
262
262
  excluded?: boolean;
263
263
  };
264
264
  type ModelIndexField<T extends ModelEntityList<ModelField> = ModelEntityList<ModelField>> = {
package/dist/index.js CHANGED
@@ -141,8 +141,11 @@ var omit = (obj, properties) => Object.fromEntries(
141
141
  var getProperty = (obj, path) => {
142
142
  return path.split(".").reduce((acc, key) => acc?.[key], obj);
143
143
  };
144
+ var getPathSegments = (path) => {
145
+ return path.split(/[.[\]]/g).filter((segment) => segment.trim().length > 0);
146
+ };
144
147
  var setProperty = (obj, path, value) => {
145
- const segments = path.split(/[.[\]]/g).filter((x) => !!x.trim());
148
+ const segments = getPathSegments(path);
146
149
  const _set = (node) => {
147
150
  if (segments.length > 1) {
148
151
  const key = segments.shift();
@@ -157,36 +160,26 @@ var setProperty = (obj, path, value) => {
157
160
  };
158
161
  _set(obj);
159
162
  };
163
+ var deleteProperty = (obj, path) => {
164
+ const segments = getPathSegments(path);
165
+ const _delete = (node, segs) => {
166
+ const key = segs[0];
167
+ if (segs.length === 1) {
168
+ delete node[key];
169
+ } else if (node[key] && typeof node[key] === "object" && node[key] !== null) {
170
+ const shouldCleanup = _delete(node[key], segs.slice(1));
171
+ if (shouldCleanup) delete node[key];
172
+ }
173
+ return Object.keys(node).length === 0;
174
+ };
175
+ _delete(obj, segments);
176
+ };
160
177
  var splitQuery = (query) => {
161
178
  const queryType = Object.keys(query)[0];
162
179
  const queryModel = Object.keys(query[queryType])[0];
163
180
  const queryInstructions = query[queryType][queryModel];
164
181
  return { queryType, queryModel, queryInstructions };
165
182
  };
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
- }
190
183
 
191
184
  // src/utils/pagination.ts
192
185
  var CURSOR_SEPARATOR = ",";
@@ -2349,7 +2342,7 @@ var Transaction = class {
2349
2342
  if (fieldsToDrop.length > 0) {
2350
2343
  for (const record of result.records) {
2351
2344
  for (const field of fieldsToDrop) {
2352
- deleteNestedProperty(record, field.slug);
2345
+ deleteProperty(record, field.slug);
2353
2346
  }
2354
2347
  }
2355
2348
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.17.21-corny-pagination-bug-experimental-422",
3
+ "version": "0.17.21-leo-pagination-bug-experimental-424",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {