@contentrain/wp-import 0.9.4 → 0.10.0

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/README.md CHANGED
@@ -231,6 +231,16 @@ result's `gaps` contains `acf_partial`: groups without REST exposure, options
231
231
  pages and fields on post types outside REST are not visible to REST — the
232
232
  Bridge reads those.
233
233
 
234
+ Options pages arrive from the Bridge as `RawIR.acf_options`. Their fields go to
235
+ the `site` entry, typed and resolved like a post's ACF fields. A name that is a
236
+ core `site` field (`title`, `tagline`, `url`, `language`) or sits on more than
237
+ one options page takes the page's slug as a prefix, without ACF's default
238
+ `acf-options-` (`acf-options-footer` gives `footer_phone`), so no page overwrites
239
+ another. A name that is still taken, say a field literally called `footer_phone`
240
+ on another page, gets a counter (`footer_phone_2`) rather than being dropped; the
241
+ report's `acf_options_renamed` lists each one with its page and field. The
242
+ report's `acf_options` lists each field written.
243
+
234
244
  With an Application Password, post types are read with `context=edit` so their
235
245
  `viewable` flag is known: a type that is in REST but not publicly queryable (a
236
246
  testimonial post type, say) keeps its content but gets no address (`link` is
package/dist/index.d.mts CHANGED
@@ -90,6 +90,10 @@ interface ImportReport {
90
90
  title_fallback: number;
91
91
  meta_fields: Record<string, string>;
92
92
  acf_fields: Record<string, string>;
93
+ /** ACF Options Page fields written to the `site` entry (`field: type`), prefixed `<page>_` on a name clash. */
94
+ acf_options: Record<string, string>;
95
+ /** ACF Options Page fields whose name was already taken, written under a counter (`new name: <page slug>.<field>`). */
96
+ acf_options_renamed: Record<string, string>;
93
97
  /** ACF select/checkbox values outside their field's stated choices, left out (`field: count`). */
94
98
  acf_outside_choices: Record<string, number>;
95
99
  /** ACF date-times written without a zone because the source named none (`timezone_string` / `gmt_offset`). */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/wxr.ts","../src/rest.ts","../src/contentrain.ts","../src/comments.ts","../src/php-unserialize.ts","../src/core.ts","../src/delta.ts"],"mappings":";;;;U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,SAAA;AAAA,IAAuB,iBAAA;;;;;;AF7E7E;;;iBGbgB,cAAA,CAAe,GAAA,EAAK,KAAA;EAAU,QAAA,EAAU,UAAA;EAAc,QAAA,EAAU,WAAA,CAAY,cAAA;AAAA;AAAA,iBAgB5E,mBAAA,CAAoB,GAAA,EAAK,KAAA,EAAO,OAAA,EAAS,cAAA,EAAgB,IAAA;EAAS,YAAA;AAAA,IAA0B,cAAA;;iBAiB5F,iBAAA,CAAkB,GAAA,EAAK,cAAA,GAAiB,eAAA;;;UC3CvC,iBAAA;EACf,EAAA;EACA,UAAA;EACA,KAAA;EACA,KAAA;AAAA;AAAA,iBAGc,eAAA,CAAgB,CAAA,YAAa,CAAA;AAAA,iBAI7B,cAAA,CAAe,GAAA;;iBAyFf,cAAA,CAAe,CAAA,WAAY,iBAAA;;;cC9F9B,KAAA,GAAS,CAAA;;cAST,KAAA,GAAS,CAAA;;cAcT,KAAA,GAAS,CAAA;;;;;;;;;ALCtB;cK8Ba,UAAA,EAAU,MAAA;;cAIV,WAAA,EAAW,MAAA;;cAOX,UAAA,GAAc,CAAA;AAAA,cAGd,OAAA,GAAW,CAAA;;;;UC3DP,UAAA;EACf,KAAA,EAAO,MAAA;EACP,gBAAA,EAAkB,cAAA;AAAA;AAAA,UAGH,oBAAA;ENOD;EMLd,KAAA,EAAO,eAAA;ENEO;EMAd,KAAA,EAAO,UAAA;ENA0C;EMEjD,QAAA,GAAW,UAAA;ENDX;;;;;EMOA,UAAA;ENFe;;;;EMOf,SAAA;AAAA;AAAA,cAGW,kBAAA;AAAA,cACA,iBAAA;;;ANQb;;;;;;;;;;iBM8NgB,eAAA,CAAgB,KAAA,EAAO,oBAAA,GAAuB,eAAA;;iBAkC9C,uBAAA,CAAwB,IAAA,EAAM,eAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/wxr.ts","../src/rest.ts","../src/contentrain.ts","../src/comments.ts","../src/php-unserialize.ts","../src/core.ts","../src/delta.ts"],"mappings":";;;;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w, opts) {
2135
2135
  title_fallback: 0,
2136
2136
  meta_fields: {},
2137
2137
  acf_fields: {},
2138
+ acf_options: {},
2139
+ acf_options_renamed: {},
2138
2140
  acf_outside_choices: {},
2139
2141
  acf_datetime_unzoned: 0,
2140
2142
  skipped_types: [],
@@ -2295,6 +2297,20 @@ function rawToContentrain(raw, opts) {
2295
2297
  const t = postById.get(v);
2296
2298
  return t && t.status === "publish" && !t.password ? t.link ?? void 0 : void 0;
2297
2299
  };
2300
+ /** An ACF value as the store holds it: typed by the plan, references resolved; `undefined` = nothing to write. */
2301
+ const acfEntryValue = (k, plan, value) => {
2302
+ const ctx = {
2303
+ timeZone: raw.site.timezone,
2304
+ gmtOffset: raw.site.gmt_offset,
2305
+ dropped: () => {
2306
+ report.acf_outside_choices[k] = (report.acf_outside_choices[k] ?? 0) + 1;
2307
+ },
2308
+ unzoned: () => {
2309
+ report.acf_datetime_unzoned++;
2310
+ }
2311
+ };
2312
+ return plan.def ? acfValue(plan.def, plan.kind === "address" ? addressOf(value) : acfRows(acfScrub(value)), ctx) : acfRefs(plan, value);
2313
+ };
2298
2314
  const titleOf = (p) => {
2299
2315
  const t = strip(p.title);
2300
2316
  if (t) return t;
@@ -2711,17 +2727,7 @@ function rawToContentrain(raw, opts) {
2711
2727
  for (const [k, acf] of Object.entries(p.acf ?? {})) {
2712
2728
  const plan = acfFields.get(k);
2713
2729
  if (!plan || k in e) continue;
2714
- const ctx = {
2715
- timeZone: raw.site.timezone,
2716
- gmtOffset: raw.site.gmt_offset,
2717
- dropped: () => {
2718
- report.acf_outside_choices[k] = (report.acf_outside_choices[k] ?? 0) + 1;
2719
- },
2720
- unzoned: () => {
2721
- report.acf_datetime_unzoned++;
2722
- }
2723
- };
2724
- const v = plan.def ? acfValue(plan.def, plan.kind === "address" ? addressOf(acf.value) : acfRows(acfScrub(acf.value)), ctx) : acfRefs(plan, acf.value);
2730
+ const v = acfEntryValue(k, plan, acf.value);
2725
2731
  if (v !== void 0) e[k] = v;
2726
2732
  }
2727
2733
  contentBucket[id] = e;
@@ -2987,6 +2993,58 @@ function rawToContentrain(raw, opts) {
2987
2993
  metas.comments[cRef(c.id)] = importMeta(c.approved === "1" ? "published" : c.approved === "spam" || c.approved === "trash" ? "archived" : "in_review");
2988
2994
  }
2989
2995
  }
2996
+ const siteFields = {
2997
+ title: {
2998
+ type: "string",
2999
+ required: true,
3000
+ label: "Site title",
3001
+ order: 10
3002
+ },
3003
+ tagline: {
3004
+ type: "string",
3005
+ label: "Tagline",
3006
+ order: 20
3007
+ },
3008
+ url: {
3009
+ type: "url",
3010
+ label: "URL",
3011
+ order: 30
3012
+ },
3013
+ language: {
3014
+ type: "string",
3015
+ label: "Language",
3016
+ order: 40
3017
+ }
3018
+ };
3019
+ const optionPages = raw.acf_options ?? [];
3020
+ const pagesOf = /* @__PURE__ */ new Map();
3021
+ for (const page of optionPages) for (const k of Object.keys(page.fields)) pagesOf.set(k, (pagesOf.get(k) ?? 0) + 1);
3022
+ const optionFields = {};
3023
+ const claim = (page, k, want) => {
3024
+ let name = want;
3025
+ for (let n = 2; siteFields[name] || name in optionFields; n++) name = `${want}_${n}`;
3026
+ if (name !== want) report.acf_options_renamed[name] = `${page.slug}.${k}`;
3027
+ optionFields[name] = page.fields[k];
3028
+ };
3029
+ const prefixed = [];
3030
+ for (const page of optionPages) for (const k of Object.keys(page.fields)) if (siteFields[k] || pagesOf.get(k) > 1) prefixed.push([page, k]);
3031
+ else claim(page, k, k);
3032
+ for (const [page, k] of prefixed) claim(page, k, `${page.slug.replace(/^acf-options-(?=.)/, "").replace(/-/g, "_")}_${k}`);
3033
+ const optionPlan = acfPlan([{ acf: optionFields }], (k) => !!siteFields[k]);
3034
+ let so = 40;
3035
+ for (const [k, plan] of optionPlan) {
3036
+ const def = plan.def ?? {
3037
+ type: plan.multiple ? "relations" : "relation",
3038
+ model: plan.models.size > 1 ? [...plan.models].toSorted() : [...plan.models][0]
3039
+ };
3040
+ siteFields[k] = {
3041
+ ...def,
3042
+ ...def.label ? {} : { label: k },
3043
+ description: def.description ?? "ACF",
3044
+ order: so += 10
3045
+ };
3046
+ report.acf_options[k] = plan.def ? plan.def.type : `${def.type}:${[...plan.models].toSorted().join("|")}`;
3047
+ }
2990
3048
  addModel({
2991
3049
  id: "site",
2992
3050
  name: "Site",
@@ -2994,29 +3052,7 @@ function rawToContentrain(raw, opts) {
2994
3052
  domain: "site",
2995
3053
  i18n: false,
2996
3054
  title_field: "title",
2997
- fields: {
2998
- title: {
2999
- type: "string",
3000
- required: true,
3001
- label: "Site title",
3002
- order: 10
3003
- },
3004
- tagline: {
3005
- type: "string",
3006
- label: "Tagline",
3007
- order: 20
3008
- },
3009
- url: {
3010
- type: "url",
3011
- label: "URL",
3012
- order: 30
3013
- },
3014
- language: {
3015
- type: "string",
3016
- label: "Language",
3017
- order: 40
3018
- }
3019
- }
3055
+ fields: siteFields
3020
3056
  });
3021
3057
  siteEntry = pick({
3022
3058
  title: strip(raw.site.title),
@@ -3029,6 +3065,10 @@ function rawToContentrain(raw, opts) {
3029
3065
  "url",
3030
3066
  "language"
3031
3067
  ]));
3068
+ for (const [k, plan] of optionPlan) {
3069
+ const v = acfEntryValue(k, plan, optionFields[k].value);
3070
+ if (v !== void 0) siteEntry[k] = v;
3071
+ }
3032
3072
  siteMeta = importMeta("published");
3033
3073
  report.site_title_missing = !siteEntry.title;
3034
3074
  const vocabTerms = {};