@monkeyplus/flow 6.0.51 → 6.0.52

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.
@@ -311,37 +311,50 @@ export function processContentQuery(entries, query, allEntries) {
311
311
  if (query.with) {
312
312
  try {
313
313
  const withRelations = JSON.parse(query.with);
314
- const hydrateValue = (val, instruction) => {
314
+ const hydrateValue = (val, instruction, isRootEntry = false) => {
315
315
  if (Array.isArray(val)) {
316
- return val.map((v) => hydrateValue(v, instruction));
316
+ return val.map((v) => hydrateValue(v, instruction, isRootEntry));
317
317
  }
318
318
  if (typeof val === "string") {
319
319
  const found = allEntries.find((e) => e.path === val);
320
320
  if (!found) return val;
321
321
  let hydratedFound = { ...found, data: JSON.parse(JSON.stringify(found.data)) };
322
322
  if (typeof instruction === "object" && instruction !== null && instruction.with) {
323
- hydratedFound = hydrateEntry(hydratedFound, instruction.with);
323
+ hydratedFound = hydrateEntry(hydratedFound, instruction.with, true);
324
324
  }
325
325
  if (instruction === "raw" || typeof instruction === "object" && instruction !== null && instruction.raw) {
326
326
  return hydratedFound;
327
327
  }
328
328
  return hydratedFound.data;
329
329
  }
330
+ if (typeof val === "object" && val !== null) {
331
+ if (typeof instruction === "object" && instruction !== null && instruction.with) {
332
+ const hydratedObj = { ...val };
333
+ for (const [field, subInstruction] of Object.entries(instruction.with)) {
334
+ if (!subInstruction) continue;
335
+ const actualField = isRootEntry && !field.startsWith("data.") ? `data.${field}` : field;
336
+ const rawValue = getField(hydratedObj, actualField);
337
+ const resolved = hydrateValue(rawValue, subInstruction, false);
338
+ setField(hydratedObj, actualField, resolved);
339
+ }
340
+ return hydratedObj;
341
+ }
342
+ }
330
343
  return val;
331
344
  };
332
- const hydrateEntry = (entry, relations) => {
345
+ const hydrateEntry = (entry, relations, isRootEntry = true) => {
333
346
  for (const [field, instruction] of Object.entries(relations)) {
334
347
  if (!instruction) continue;
335
- const actualField = field.startsWith("data.") ? field : `data.${field}`;
348
+ const actualField = isRootEntry && !field.startsWith("data.") ? `data.${field}` : field;
336
349
  const rawValue = getField(entry, actualField);
337
- const resolved = hydrateValue(rawValue, instruction);
350
+ const resolved = hydrateValue(rawValue, instruction, false);
338
351
  setField(entry, actualField, resolved);
339
352
  }
340
353
  return entry;
341
354
  };
342
355
  entries = entries.map((entry) => {
343
356
  const hydratedEntry = { ...entry, data: JSON.parse(JSON.stringify(entry.data)) };
344
- return hydrateEntry(hydratedEntry, withRelations);
357
+ return hydrateEntry(hydratedEntry, withRelations, true);
345
358
  });
346
359
  } catch {
347
360
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monkeyplus/flow",
3
- "version": "6.0.51",
3
+ "version": "6.0.52",
4
4
  "description": "@monkeyplus/flow package-first runtime with Vite, Nitro, Vue and a workspace playground.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {