@contentrain/wp-import 0.11.13 → 0.11.15

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.mjs CHANGED
@@ -2316,6 +2316,7 @@ function rawToContentrain(raw, opts) {
2316
2316
  /** Every ACF field on these posts: its definition, or — for a reference — its kind and target models. */
2317
2317
  const acfPlan = (items, taken) => {
2318
2318
  const out = /* @__PURE__ */ new Map();
2319
+ const untyped = /* @__PURE__ */ new Map();
2319
2320
  for (const p of items) for (const [k, acf] of Object.entries(p.acf ?? {})) {
2320
2321
  if (taken(k) || acf.value === null || acf.value === void 0 || acf.value === "" || acf.value === false && acf.type !== "true_false") continue;
2321
2322
  const kind = acf.type ? ACF_REFERENCE_TYPES[acf.type] : void 0;
@@ -2350,6 +2351,12 @@ function rawToContentrain(raw, opts) {
2350
2351
  out.set(k, cur);
2351
2352
  continue;
2352
2353
  }
2354
+ const seen = untyped.get(k) ?? untyped.set(k, {
2355
+ values: [],
2356
+ typed: false
2357
+ }).get(k);
2358
+ if (acf.type) seen.typed = true;
2359
+ else seen.values.push(acf.value);
2353
2360
  const def = acfFieldDef(k, acfScrub(acf.value), {
2354
2361
  type: acf.type,
2355
2362
  label: acf.label
@@ -2362,6 +2369,15 @@ function rawToContentrain(raw, opts) {
2362
2369
  models: /* @__PURE__ */ new Set()
2363
2370
  });
2364
2371
  }
2372
+ const isMediaId = (v) => (typeof v === "number" ? Number.isSafeInteger(v) && v > 0 : typeof v === "string" && /^\d+$/.test(v)) && mediaRef(Number(v)) !== null;
2373
+ for (const [k, seen] of untyped) {
2374
+ if (!out.get(k)?.def || seen.typed || !seen.values.length) continue;
2375
+ if (seen.values.every((v) => Array.isArray(v) ? v.length > 0 && v.every(isMediaId) : isMediaId(v))) out.set(k, {
2376
+ kind: "media",
2377
+ multiple: seen.values.some(Array.isArray),
2378
+ models: new Set(["media"])
2379
+ });
2380
+ }
2365
2381
  for (const [k, plan] of out) if (!plan.def && !plan.models.size) out.delete(k);
2366
2382
  return out;
2367
2383
  };