@bettercms-ai/convert 0.23.0 → 0.24.1

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
@@ -955,7 +955,7 @@ declare function attrsFor(path: string, kind: string, props?: AttrBinding[], sco
955
955
  declare function propsAttribute(props: AttrBinding[]): string;
956
956
 
957
957
  /** Bumped whenever the emitted source changes. `isKnownHelper` upgrades anything older. */
958
- declare const HELPER_VERSION = 11;
958
+ declare const HELPER_VERSION = 13;
959
959
  /** Where each dialect's helper lives. Null = this dialect reads nothing at build time. */
960
960
  declare const HELPER_PATH: Record<Dialect, string | null>;
961
961
  /** The directory the snapshots live in, at the repository root. */
@@ -981,6 +981,22 @@ declare function helperSource(dialect: Dialect): string;
981
981
  * treats them the same way, because it cannot tell them apart and must not overwrite either.
982
982
  */
983
983
  declare function isKnownHelper(content: string, dialect: Dialect): number | null;
984
+ /** One committed helper a build may replace: where it lives, what replaces it, and which bytes qualify. */
985
+ interface HelperUpgrade {
986
+ path: string;
987
+ source: string;
988
+ /** sha256 of every OLDER helper this package wrote at `path`. Anything else is left alone. */
989
+ digests: string[];
990
+ }
991
+ /**
992
+ * What a BetterCMS build swaps in for a helper this package wrote at an older version.
993
+ *
994
+ * The hosting builder applies these to its own throwaway checkout — never to the repository — so a
995
+ * site converted before the helper read published content at request time gets that reader on its
996
+ * next build, with no commit and no codemod run. The rule is `isKnownHelper`'s: only bytes this
997
+ * package produced are replaced, so an edited or foreign module at the same path is never touched.
998
+ */
999
+ declare function helperUpgrades(): HelperUpgrade[];
984
1000
 
985
1001
  /**
986
1002
  * The submit runtime, LIFTED VERBATIM from `src/lib/sites/render-page.ts` `FORM_SCRIPT`.
@@ -1949,4 +1965,4 @@ declare function convertSources(briefIn: Brief, sources: SourceFile[], options?:
1949
1965
  receipt: ConversionReceipt;
1950
1966
  }>;
1951
1967
 
1952
- export { ASTRO_LANE_PENDING, type AstNode, type AttrBinding, type Brief, type BriefForm, type BriefPage, type BriefPath, COMPONENT_DIR, CONTENT_DIR, type CanvasResult, type CanvasSource, type Carried, type ComponentizeOptions, type ComponentizePlan, type ComponentizePlanComponent, type ComponentizePlanField, type ComponentizePlanPage, type ComponentizePlanSection, type ComponentizeReceipt, type ConversionReceipt, ConvertError, type ConvertErrorCode, type ConvertOptions, DIALECT_RULES, type DataMember, type DataResult, type DeclaredPath, type Dialect, type DynamicBinding, FORM_SCRIPT, type FileDeclaration, type FindSitesResult, type FixAction, FormInvariantError, type FormPendingReason, type FormsReceipt, HELPER_PATH, HELPER_VERSION, type ImageResult, type ImageTarget, type ImportedFrom, type LlmFallback, type LocatedPath, type Node, PARSE_FILE, type ParsedFile, type ParserError, type PathLocator, type PendingFix, type PendingForm, type PendingPath, type PendingReason, type PendingSection, type PlanFile, REGISTRY_MARKER, type ReceiptFile, ReceiptInvariantError, type ReceiptNote, type Rewrite, SECTIONS_LIB, SECTION_MARKER, SKIP_DIRS, SKIP_FILES, SOURCE_EXTENSIONS, SSR_DRAFT_RECIPE, STUB_CONTENT, SectionInvariantError, type SectionPendingReason, type SectionUpgradeReceipt, type SectionsReceipt, type Site, type SiteWhere, type SkippedRoot, type SourceFile, type Splice, type TargetIdentity, type UnlocatedPath, UpgradeError, type UpgradeOptions, type UpgradeRootRef, type UpgradeSkipReason, type UpgradedRoot, type ValidationCode, ValidationError, type Xray, type XrayBucket, aliasesFrom, assertForms, assertReceipt, assertSections, assetCandidates, assetImport, attrsFor, bindDataLiterals, bindImages, briefDigest, canvasBridge, carryFor, componentizeSources, convertSources, convertedHere, coverageOf, declaringElements, dialectOf, exportedFunction, extendedConfigs, findLiteral, findSites, findSitesTolerant, fixFor, flat, helperSource, importsIn, isDecorativeGlyph, isDynamicRoute, isKnownHelper, isSourceCandidate, locate, measureUnaddressable, overlapping, pageFilesFor, parseFile, propsAttribute, readBrief, readComponentizePlan, readDeclarations, readExpr, readPlan, relativeImport, resolveSpecifier, rewriteFile, routeCounts, routeOfFile, stripTags, unreadableConfigs, upgradeSections, walkAst, wireForms };
1968
+ export { ASTRO_LANE_PENDING, type AstNode, type AttrBinding, type Brief, type BriefForm, type BriefPage, type BriefPath, COMPONENT_DIR, CONTENT_DIR, type CanvasResult, type CanvasSource, type Carried, type ComponentizeOptions, type ComponentizePlan, type ComponentizePlanComponent, type ComponentizePlanField, type ComponentizePlanPage, type ComponentizePlanSection, type ComponentizeReceipt, type ConversionReceipt, ConvertError, type ConvertErrorCode, type ConvertOptions, DIALECT_RULES, type DataMember, type DataResult, type DeclaredPath, type Dialect, type DynamicBinding, FORM_SCRIPT, type FileDeclaration, type FindSitesResult, type FixAction, FormInvariantError, type FormPendingReason, type FormsReceipt, HELPER_PATH, HELPER_VERSION, type HelperUpgrade, type ImageResult, type ImageTarget, type ImportedFrom, type LlmFallback, type LocatedPath, type Node, PARSE_FILE, type ParsedFile, type ParserError, type PathLocator, type PendingFix, type PendingForm, type PendingPath, type PendingReason, type PendingSection, type PlanFile, REGISTRY_MARKER, type ReceiptFile, ReceiptInvariantError, type ReceiptNote, type Rewrite, SECTIONS_LIB, SECTION_MARKER, SKIP_DIRS, SKIP_FILES, SOURCE_EXTENSIONS, SSR_DRAFT_RECIPE, STUB_CONTENT, SectionInvariantError, type SectionPendingReason, type SectionUpgradeReceipt, type SectionsReceipt, type Site, type SiteWhere, type SkippedRoot, type SourceFile, type Splice, type TargetIdentity, type UnlocatedPath, UpgradeError, type UpgradeOptions, type UpgradeRootRef, type UpgradeSkipReason, type UpgradedRoot, type ValidationCode, ValidationError, type Xray, type XrayBucket, aliasesFrom, assertForms, assertReceipt, assertSections, assetCandidates, assetImport, attrsFor, bindDataLiterals, bindImages, briefDigest, canvasBridge, carryFor, componentizeSources, convertSources, convertedHere, coverageOf, declaringElements, dialectOf, exportedFunction, extendedConfigs, findLiteral, findSites, findSitesTolerant, fixFor, flat, helperSource, helperUpgrades, importsIn, isDecorativeGlyph, isDynamicRoute, isKnownHelper, isSourceCandidate, locate, measureUnaddressable, overlapping, pageFilesFor, parseFile, propsAttribute, readBrief, readComponentizePlan, readDeclarations, readExpr, readPlan, relativeImport, resolveSpecifier, rewriteFile, routeCounts, routeOfFile, stripTags, unreadableConfigs, upgradeSections, walkAst, wireForms };
package/dist/index.js CHANGED
@@ -4187,7 +4187,7 @@ async function bindImages(ctx, targets) {
4187
4187
 
4188
4188
  // src/helper.ts
4189
4189
  import { createHash as createHash2 } from "crypto";
4190
- var HELPER_VERSION = 11;
4190
+ var HELPER_VERSION = 13;
4191
4191
  var HEADER = "// @bettercms-ai/convert helper v";
4192
4192
  var HELPER_PATH = Object.fromEntries(
4193
4193
  Object.keys(DIALECT_RULES).map((d) => [d, DIALECT_RULES[d].helper])
@@ -4233,9 +4233,16 @@ function readPath(root: unknown, path: string): unknown {
4233
4233
  return cursor;
4234
4234
  }
4235
4235
 
4236
+ /**
4237
+ * A repository image path \u2014 \`@/images/x.avif\`, \`~/assets/x.png\`, \`../assets/x.jpg\`, \`/src/x.png\`.
4238
+ * The bundler resolves one at build and nothing else can, so as a value it is never rendered: the
4239
+ * template's own fallback (the picture the build already imported) shows instead of a broken image.
4240
+ */
4241
+ const REPO_IMAGE_PATH = /^(?:@[\\w-]*|~|\\.{1,2}|\\/?src)\\/[^\\s?#"'<>]*\\.(?:avif|png|jpe?g|webp|gif|svg|bmp|ico|tiff?|jxl|heic)(?:[?#]\\S*)?$/i;
4242
+
4236
4243
  /** A stored value as a template renders it: richtext is its html, an image is its url. */
4237
4244
  function render(value: unknown): string | undefined {
4238
- if (typeof value === "string") return value;
4245
+ if (typeof value === "string") return REPO_IMAGE_PATH.test(value.trim()) ? undefined : value;
4239
4246
  if (typeof value === "number" || typeof value === "boolean") return String(value);
4240
4247
  if (isRecord(value)) {
4241
4248
  if (typeof value.html === "string") return value.html;
@@ -4244,8 +4251,69 @@ function render(value: unknown): string | undefined {
4244
4251
  return undefined;
4245
4252
  }
4246
4253
 
4254
+ /**
4255
+ * The PUBLISHED copy, on a server BetterCMS hosts \u2014 read at request time, not at build time.
4256
+ *
4257
+ * BetterCMS keeps one file current for a running server app (\`BCMS_CONTENT_FILE\`, the same
4258
+ * bcms-content.json the build was given) and rewrites it on every publish, so a server-rendered
4259
+ * page shows a publish within seconds instead of after a rebuild. Each snapshot this module reads
4260
+ * resolves to its live counterpart: the shared layout by identity, a page by its \`slug\`.
4261
+ *
4262
+ * Nowhere else does anything change: with no variable (a build, \`astro dev\`, a browser, an edge
4263
+ * runtime) every snapshot is the one the bundle imported, exactly as before. A file that cannot be
4264
+ * read keeps the last good copy; it is checked at most once a second.
4265
+ */
4266
+ type BcmsLiveContent = { stamp: number; bySlug: Map<string, unknown>; layout: unknown };
4267
+ let bcmsLive: BcmsLiveContent | null = null;
4268
+ let bcmsLiveCheckedAt = 0;
4269
+
4270
+ function liveContent(): BcmsLiveContent | null {
4271
+ const proc = (globalThis as {
4272
+ process?: { env?: Record<string, string | undefined>; getBuiltinModule?: (id: string) => unknown };
4273
+ }).process;
4274
+ const file = proc?.env?.BCMS_CONTENT_FILE;
4275
+ if (!file || typeof proc?.getBuiltinModule !== "function") return null;
4276
+ const now = Date.now();
4277
+ if (now - bcmsLiveCheckedAt < 1000) return bcmsLive;
4278
+ bcmsLiveCheckedAt = now;
4279
+ try {
4280
+ const fs = proc.getBuiltinModule("node:fs") as {
4281
+ statSync(path: string): { mtimeMs: number };
4282
+ readFileSync(path: string, encoding: "utf8"): string;
4283
+ };
4284
+ const stamp = fs.statSync(file).mtimeMs;
4285
+ if (bcmsLive && bcmsLive.stamp === stamp) return bcmsLive;
4286
+ const snapshot: unknown = JSON.parse(fs.readFileSync(file, "utf8"));
4287
+ const bySlug = new Map<string, unknown>();
4288
+ const collections = isRecord(snapshot) && isRecord(snapshot.collections) ? snapshot.collections : {};
4289
+ for (const rows of Object.values(collections)) {
4290
+ if (!Array.isArray(rows)) continue;
4291
+ for (const row of rows) {
4292
+ if (isRecord(row) && typeof row.slug === "string" && !bySlug.has(row.slug)) bySlug.set(row.slug, row);
4293
+ }
4294
+ }
4295
+ const pages = isRecord(snapshot) && Array.isArray(snapshot.pages) ? snapshot.pages : [];
4296
+ const withLayout = pages.find((page: unknown) => isRecord(page) && isRecord(page.layout));
4297
+ const layout = isRecord(withLayout) ? withLayout.layout : isRecord(snapshot) ? snapshot.layout : undefined;
4298
+ bcmsLive = { stamp, bySlug, layout };
4299
+ } catch {
4300
+ // Unreadable, or caught mid-write: keep serving the last good copy.
4301
+ }
4302
+ return bcmsLive;
4303
+ }
4304
+
4305
+ /** The published counterpart of a snapshot this module was handed, or the snapshot itself. */
4306
+ function live(page: unknown): unknown {
4307
+ const content = liveContent();
4308
+ if (!content) return page;
4309
+ if (page === layoutSnapshot) return isRecord(content.layout) ? content.layout : page;
4310
+ if (isRecord(page) && typeof page.slug === "string") return content.bySlug.get(page.slug) ?? page;
4311
+ return page;
4312
+ }
4313
+
4247
4314
  /** One field of one page. \`slug\` selects the entry on a dynamic route. */
4248
4315
  export function bcms(page: unknown, path: string, fallback: string, slug?: string): string {
4316
+ page = live(page);
4249
4317
  const entries = isRecord(page) ? page.entries : undefined;
4250
4318
  const root = slug !== undefined && isRecord(entries) ? entries[slug] : page;
4251
4319
  return render(readPath(root, path)) ?? fallback;
@@ -4253,7 +4321,7 @@ export function bcms(page: unknown, path: string, fallback: string, slug?: strin
4253
4321
 
4254
4322
  /** One field of the shared layout \u2014 the header and footer every route renders. */
4255
4323
  export function bcmsLayout(path: string, fallback: string): string {
4256
- return render(readPath(layoutSnapshot, path)) ?? fallback;
4324
+ return render(readPath(live(layoutSnapshot), path)) ?? fallback;
4257
4325
  }
4258
4326
 
4259
4327
  /**
@@ -4261,6 +4329,7 @@ export function bcmsLayout(path: string, fallback: string): string {
4261
4329
  * an empty snapshot still renders the same number of cards it always did.
4262
4330
  */
4263
4331
  export function bcmsRows<T>(page: unknown, path: string, fallback: T[], slug?: string): T[] {
4332
+ page = live(page);
4264
4333
  const entries = isRecord(page) ? page.entries : undefined;
4265
4334
  const root = slug !== undefined && isRecord(entries) ? entries[slug] : page;
4266
4335
  const value = readPath(root, path);
@@ -4306,6 +4375,7 @@ export function bcmsRowsAs<T>(
4306
4375
  * this out loud rather than leaving an editor to discover it.
4307
4376
  */
4308
4377
  export function bcmsList(page: unknown, paths: string[], fallback: string[], slug?: string): string[] {
4378
+ page = live(page);
4309
4379
  const entries = isRecord(page) ? page.entries : undefined;
4310
4380
  const root = slug !== undefined && isRecord(entries) ? entries[slug] : page;
4311
4381
  return paths.map((path, index) => render(readPath(root, path)) ?? fallback[index] ?? "");
@@ -4330,6 +4400,7 @@ export function bcmsTuples(page: unknown, paths: string[][], fallback: string[][
4330
4400
  * no such rule and takes the CMS url directly.
4331
4401
  */
4332
4402
  export function bcmsImage<T>(page: unknown, path: string, fallback: T, slug?: string): T | string {
4403
+ page = live(page);
4333
4404
  if (fallback !== null && typeof fallback === "object") return fallback;
4334
4405
  const entries = isRecord(page) ? page.entries : undefined;
4335
4406
  const root = slug !== undefined && isRecord(entries) ? entries[slug] : page;
@@ -4358,6 +4429,7 @@ export function bcmsSection(
4358
4429
  overrides?: unknown,
4359
4430
  bindPaths?: Record<string, string>,
4360
4431
  ): Record<string, unknown> {
4432
+ page = live(page);
4361
4433
  const group = bind ? readPath(page, bind) : undefined;
4362
4434
  const base: Record<string, unknown> = isRecord(group) ? { ...group } : {};
4363
4435
  // A locale copy on its twin's component spells its fields its own way: each prop's copy is
@@ -4429,6 +4501,7 @@ export function bcmsSectionPaths(
4429
4501
  map: BcmsPathMap,
4430
4502
  bindPaths?: Record<string, string>,
4431
4503
  ): Record<string, unknown> {
4504
+ page = live(page);
4432
4505
  const out: Record<string, unknown> = isRecord(page) ? { ...page } : {};
4433
4506
  const own = isRecord(overrides) ? overrides : {};
4434
4507
  const separator = prefix.slice(-1);
@@ -4662,7 +4735,9 @@ var HISTORICAL = {
4662
4735
  7: "f22514ef48c50230985e605bea6cf9bf41756384a7dc80603e347baba9b65d93",
4663
4736
  8: "484e72852d2b496e016a1f2a2b1a77bb993f8a163b290781522d6114b6519bb9",
4664
4737
  9: "d6441db2ff4578c3c5d4b7d461f3374b89247ef6ba9e0d535791e840d803e4f3",
4665
- 10: "ffcb59862972b15a67c5951e9f3b94ce5b8b50345e6aac2bfa5789cfc3136910"
4738
+ 10: "ffcb59862972b15a67c5951e9f3b94ce5b8b50345e6aac2bfa5789cfc3136910",
4739
+ 11: "ceb2a932d4c2761a5045ff35032e0b45130a0b5034547ff37579c72c9ce3594e",
4740
+ 12: "10f71724484c84af12aa3eb90db44bf6acbf71fcf8ddff5b6361c1190ba16528"
4666
4741
  },
4667
4742
  "src/lib/bcms-content.ts": {
4668
4743
  1: "ae72ae14d706943d481c880d70da5789b4816ba1ba319a10fbc63ded4d0b42f2",
@@ -4674,7 +4749,9 @@ var HISTORICAL = {
4674
4749
  7: "ed92fb88de953d9951abbe6a1edae1d048f4050eaf6fb607ac08167f94d8bcc7",
4675
4750
  8: "1a6f669d76d42effe77f082436e9d21c0efa6fc499e919e3d116bc3a27a7f3d5",
4676
4751
  9: "eee9fb1635ae7d6f8f33676a1f390600ca24a62ee992775252273c73a011c494",
4677
- 10: "35bb7c0e30f5c41fe68e52259ec4764de6de2734064fa0e1521f3338eef0a09e"
4752
+ 10: "35bb7c0e30f5c41fe68e52259ec4764de6de2734064fa0e1521f3338eef0a09e",
4753
+ 11: "818784f2088150d64d91b42eac944dc9503f104d32a0e7a18c753d2982a5adc0",
4754
+ 12: "79dafc525a541feae55ada5dbe2ea966cac82acd741a4b41d61fe9e0cdfaa208"
4678
4755
  },
4679
4756
  "composables/bcms-content.ts": {
4680
4757
  1: "c272412532efed7db64b6cf313b2bed4291f9951430412289c8a588b7f565407",
@@ -4686,7 +4763,9 @@ var HISTORICAL = {
4686
4763
  7: "f22514ef48c50230985e605bea6cf9bf41756384a7dc80603e347baba9b65d93",
4687
4764
  8: "484e72852d2b496e016a1f2a2b1a77bb993f8a163b290781522d6114b6519bb9",
4688
4765
  9: "d6441db2ff4578c3c5d4b7d461f3374b89247ef6ba9e0d535791e840d803e4f3",
4689
- 10: "ffcb59862972b15a67c5951e9f3b94ce5b8b50345e6aac2bfa5789cfc3136910"
4766
+ 10: "ffcb59862972b15a67c5951e9f3b94ce5b8b50345e6aac2bfa5789cfc3136910",
4767
+ 11: "ceb2a932d4c2761a5045ff35032e0b45130a0b5034547ff37579c72c9ce3594e",
4768
+ 12: "10f71724484c84af12aa3eb90db44bf6acbf71fcf8ddff5b6361c1190ba16528"
4690
4769
  }
4691
4770
  };
4692
4771
  var sha256 = (value) => createHash2("sha256").update(value, "utf8").digest("hex");
@@ -4700,6 +4779,15 @@ function isKnownHelper(content, dialect) {
4700
4779
  }
4701
4780
  return null;
4702
4781
  }
4782
+ function helperUpgrades() {
4783
+ const out = /* @__PURE__ */ new Map();
4784
+ for (const dialect of Object.keys(HELPER_PATH)) {
4785
+ const path = HELPER_PATH[dialect];
4786
+ if (!path || out.has(path)) continue;
4787
+ out.set(path, { path, source: helperSource(dialect), digests: Object.values(HISTORICAL[path] ?? {}) });
4788
+ }
4789
+ return [...out.values()];
4790
+ }
4703
4791
 
4704
4792
  // src/locate.ts
4705
4793
  var flat = (value) => value.replace(/\s+/g, " ").trim();
@@ -10719,6 +10807,7 @@ export {
10719
10807
  fixFor,
10720
10808
  flat,
10721
10809
  helperSource,
10810
+ helperUpgrades,
10722
10811
  importsIn,
10723
10812
  isDecorativeGlyph,
10724
10813
  isDynamicRoute,