@bettercms-ai/convert 0.6.0 → 0.7.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/dist/index.d.ts CHANGED
@@ -164,7 +164,11 @@ declare function locate(brief: BriefLike, sources: SourceFile[], options?: Locat
164
164
  * sentence appears in three files" and "this field is bound" are different questions — and a path
165
165
  * is only `rewritten` when EVERY located occurrence of it was.
166
166
  */
167
- type PendingReason = "NO_ORIGINAL" | "NOT_IN_SOURCE" | "DIALECT_UNSUPPORTED" | "IN_EXPRESSION" | "IN_SCRIPT_OR_COMMENT" | "IN_DATA_FILE" | "AMBIGUOUS_LITERAL" | "KIND_MISMATCH" | "SUBSTRING_ONLY" | "PROP_TARGET_NOT_FOUND" | "PROP_DRILLED_DEEP" | "REPEATER_FIXED_LENGTH" | "DYNAMIC_PARAMS_UNAVAILABLE" | "BRIEF_META_UNPLACED" | "PARSE_ERROR" | "TIER3_UNVERIFIABLE"
167
+ type PendingReason = "NO_ORIGINAL" | "NOT_IN_SOURCE" | "DIALECT_UNSUPPORTED" | "IN_EXPRESSION" | "IN_SCRIPT_OR_COMMENT" | "IN_DATA_FILE" | "AMBIGUOUS_LITERAL" | "KIND_MISMATCH" | "SUBSTRING_ONLY" | "PROP_TARGET_NOT_FOUND" | "PROP_DRILLED_DEEP" | "REPEATER_FIXED_LENGTH"
168
+ /** One array declaration, two loops over it: the row this leaf belongs to has two homes. */
169
+ | "REPEATER_AMBIGUOUS"
170
+ /** An image whose built url maps to no repository asset, or to more than one. */
171
+ | "IMAGE_ASSET_UNRESOLVED" | "DYNAMIC_PARAMS_UNAVAILABLE" | "BRIEF_META_UNPLACED" | "PARSE_ERROR" | "TIER3_UNVERIFIABLE"
168
172
  /** @see CANVAS_REASONS — these two are about the SITE's live-preview lane, not a brief path. */
169
173
  | "CANVAS_BRIDGE_MANUAL" | "SSR_DRAFT_ROUTE";
170
174
  interface PendingPath {
@@ -712,7 +716,7 @@ declare function attrsFor(path: string, kind: string, props?: AttrBinding[], sco
712
716
  declare function propsAttribute(props: AttrBinding[]): string;
713
717
 
714
718
  /** Bumped whenever the emitted source changes. `isKnownHelper` upgrades anything older. */
715
- declare const HELPER_VERSION = 4;
719
+ declare const HELPER_VERSION = 5;
716
720
  /** Where each dialect's helper lives. Null = this dialect reads nothing at build time. */
717
721
  declare const HELPER_PATH: Record<Dialect, string | null>;
718
722
  /** The directory the snapshots live in, at the repository root. */
@@ -739,6 +743,180 @@ declare function helperSource(dialect: Dialect): string;
739
743
  */
740
744
  declare function isKnownHelper(content: string, dialect: Dialect): number | null;
741
745
 
746
+ /**
747
+ * Copy that lives in a DATA LITERAL beside the markup, rendered through `.map`.
748
+ *
749
+ * 🔴 THE SHAPE EVERY REAL TEMPLATE IS MADE OF. `deriveSchema` reads the BUILT page, so three cards
750
+ * come back as `features[0..2]` whatever produced them — but the repository does not render three
751
+ * `<article>`s, it renders
752
+ *
753
+ * const features = [{ title: "…", text: "…" }, …];
754
+ * … {features.map((feature, i) => <Card><h3>{feature.title}</h3>…</Card>)}
755
+ *
756
+ * The copy is in the FRONTMATTER, the markup renders an expression, and the matcher is blind to
757
+ * both by construction (a string in a program is a program's; an expression may not render at
758
+ * all). So every one of those leaves came back `NOT_IN_SOURCE` with the value in plain sight, and
759
+ * the loop lane never fired either — `emitRepeater` templates repeated SIBLINGS, and here there is
760
+ * exactly one element in the source.
761
+ *
762
+ * WHAT THIS WRITES, and why it is the smallest edit that works:
763
+ *
764
+ * const features = bcmsRowsAs(bcmsHome, "features", [{ title: "…", text: "…" }, …],
765
+ * { title: "h3-field", text: "p-field" });
766
+ * … <h3 data-bcms-field={`features[${i}].h3-field`} data-bcms-kind="text">{feature.title}</h3>
767
+ *
768
+ * The ARRAY is read from the CMS and the ORIGINAL property names are kept, so not one byte of the
769
+ * markup's expressions changes: `feature.tone`, `feature.link` and every other property the brief
770
+ * never heard of keep working, which is what a template does with the half of a row that is
771
+ * styling rather than copy. @see bcmsRowsAs, which merges each CMS row over the row the template
772
+ * shipped with for exactly that reason.
773
+ *
774
+ * WHAT IT REFUSES, by name rather than by guessing: an identifier iterated in two places
775
+ * (`REPEATER_AMBIGUOUS` — one declaration, two loops, and nothing says which one the brief's rows
776
+ * came from), a property that reaches the markup through a component or a transform
777
+ * (`PROP_TARGET_NOT_FOUND` / `IN_EXPRESSION`), and a leaf nested one array deeper
778
+ * (`PROP_DRILLED_DEEP`).
779
+ */
780
+
781
+ /** One brief leaf of one row of one group — the same identity `loops.ts` calls a member. */
782
+ interface DataMember {
783
+ key: string;
784
+ path: string;
785
+ kind: string;
786
+ /** The copy this leaf renders today, whitespace-flattened as the matcher flattens it. */
787
+ literal: string;
788
+ /** The page this leaf belongs to. Its snapshot is what the rows are read from. */
789
+ slug: string;
790
+ }
791
+ /** A byte range to replace, or a point to insert at when `start === end`. */
792
+ interface DataSplice {
793
+ start: number;
794
+ end: number;
795
+ text: string;
796
+ }
797
+ interface DataContext {
798
+ content: string;
799
+ parsed: ParsedFile;
800
+ dialect: Dialect;
801
+ /** The name `bcmsRowsAs` is imported under here. @see scope.ts */
802
+ rowsAs: string;
803
+ /** The name `bcms` is imported under here — the scalar lane's read. @see scope.ts */
804
+ read: string;
805
+ /** The identifier a page's snapshot is imported under in this file. @see scope.ts */
806
+ snapshotName: (slug: string) => string;
807
+ /** How this file reads its route parameter, on a dynamic route. Null off one. */
808
+ slug: string | null;
809
+ }
810
+ interface DataResult {
811
+ splices: DataSplice[];
812
+ /** Did anything here write a `bcms(…)` read, so the file has to import one? @see bindScalar */
813
+ usesRead: boolean;
814
+ /** Did anything here write a `bcmsRowsAs(…)` read? */
815
+ usesRows: boolean;
816
+ /** The page slugs whose snapshot this lane now reads, so the file imports them. */
817
+ slugs: string[];
818
+ /** Target keys this plan bound. */
819
+ bound: string[];
820
+ /** What the file now declares, as a shape and as the bytes that resolve it. @see RepeaterPlan */
821
+ declarations: {
822
+ path: string;
823
+ literal: string;
824
+ }[];
825
+ /** Target keys this plan could not bind, each with the reason it could not. */
826
+ refused: {
827
+ key: string;
828
+ reason: PendingReason;
829
+ }[];
830
+ }
831
+ /**
832
+ * Bind every repeater group whose copy lives in a data literal in this same file.
833
+ *
834
+ * `members` is every indexed brief leaf this file could not otherwise place; groups it cannot
835
+ * account for are returned in `refused` with the reason, and are never partially written — a group
836
+ * half bound is a row whose second field silently stops reflecting.
837
+ */
838
+ declare function bindDataLiterals(ctx: DataContext, members: DataMember[]): DataResult;
839
+
840
+ /**
841
+ * An image whose `original` is a BUILT url, and the import the template actually renders.
842
+ *
843
+ * 🔴 THE BRIEF CANNOT NAME THE FILE. `deriveSchema` reads the built page, where an asset the
844
+ * bundler processed is `/_astro/workspace.do77EGgx_ZNfVA8.jpg` — a name that exists nowhere in the
845
+ * repository, and whose EXTENSION is not even the source's (Astro serves the same `.jpg` as
846
+ * `.webp` on one route and `.avif` on the next). So `locate` found nothing, every such path came
847
+ * back `NOT_IN_SOURCE`, and an image was the one kind of field a converted site never had.
848
+ *
849
+ * What survives the build is the BASE NAME. `workspace.do77EGgx_ZNfVA8.jpg` and
850
+ * `workspace.do77EGgx_YzFJw.webp` are both `workspace`, and the page that renders them says so
851
+ * itself: `import workspaceImage from "../assets/workspace.jpg"`. The import is the evidence —
852
+ * it is in the file being converted, it names a real path, and the element that renders it names
853
+ * the binding — so nothing here has to guess at bytes the scanner never opened (an image is not a
854
+ * source candidate, so the asset file is not in `sources` at all). @see scan.ts
855
+ *
856
+ * Ambiguity is refused rather than resolved: two imports whose base names both match, or an import
857
+ * nothing renders, is `IMAGE_ASSET_UNRESOLVED`.
858
+ */
859
+
860
+ /** One image target: a path whose value is a url and whose element renders an imported asset. */
861
+ interface ImageTarget {
862
+ key: string;
863
+ path: string;
864
+ kind: string;
865
+ /** The brief's `original` — the BUILT url. */
866
+ original: string;
867
+ slug: string;
868
+ }
869
+ interface ImageSplice {
870
+ start: number;
871
+ end: number;
872
+ text: string;
873
+ }
874
+ interface ImageContext {
875
+ content: string;
876
+ parsed: ParsedFile;
877
+ dialect: Dialect;
878
+ /** The name `bcmsImage` is imported under here. @see scope.ts */
879
+ image: string;
880
+ snapshotName: (slug: string) => string;
881
+ /** How this file reads its route parameter, on a dynamic route. Null off one. */
882
+ slug: string | null;
883
+ }
884
+ interface ImageResult {
885
+ splices: ImageSplice[];
886
+ slugs: string[];
887
+ bound: string[];
888
+ refused: {
889
+ key: string;
890
+ reason: "IMAGE_ASSET_UNRESOLVED";
891
+ }[];
892
+ }
893
+ /**
894
+ * Which local binding this built url came from, or null when nothing here says.
895
+ *
896
+ * Exported because the CALLER has to answer the same question one step earlier: an image path is
897
+ * unlocated by construction, so the file that renders it is found by asking every candidate page
898
+ * file whether it imports the asset. @see convertSources
899
+ */
900
+ declare function assetCandidates(parsed: ParsedFile, dialect: Dialect, original: string): string[];
901
+ /**
902
+ * The ONE binding, or null — which covers both "nothing matched" and "two did".
903
+ *
904
+ * 🔴 THE CALLER HAS TO TELL THOSE APART, which is why `assetCandidates` is the exported one.
905
+ * Collapsing them here made the ambiguous case indistinguishable from the absent one, and a
906
+ * repository holding `assets/team/hero.jpg` beside `assets/blog/hero.png` — a base name this
907
+ * cannot separate from one built url — reported `NOT_IN_SOURCE`, which is the opposite of the
908
+ * truth: the source has two of them.
909
+ */
910
+ declare function assetImport(parsed: ParsedFile, dialect: Dialect, original: string): string | null;
911
+ /**
912
+ * Bind every image path whose asset this file imports.
913
+ *
914
+ * The element's `src` becomes `bcmsImage(page, "<path>", <binding>)` — the CMS url when there is
915
+ * one, the import the bundler already optimised when there is not — so a build against the
916
+ * committed `{}` stub renders exactly the image the repository renders today.
917
+ */
918
+ declare function bindImages(ctx: ImageContext, targets: ImageTarget[]): ImageResult;
919
+
742
920
  /** The recipe an Astro site needs instead — never auto-migrate a site to SSR. */
743
921
  declare const SSR_DRAFT_RECIPE: string;
744
922
  interface CanvasSource {
@@ -1292,4 +1470,4 @@ declare function convertSources(briefIn: Brief, sources: SourceFile[], options?:
1292
1470
  receipt: ConversionReceipt;
1293
1471
  }>;
1294
1472
 
1295
- export { ASTRO_LANE_PENDING, type AstNode, type AttrBinding, type Brief, 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 DeclaredPath, type Dialect, type DynamicBinding, type FileDeclaration, type FindSitesResult, HELPER_PATH, HELPER_VERSION, type ImportedFrom, type LlmFallback, type LocatedPath, type Node, PARSE_FILE, type ParsedFile, type ParserError, type PathLocator, 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 SectionsReceipt, type Site, type SiteWhere, type SourceFile, type Splice, type TargetIdentity, type UnlocatedPath, type ValidationCode, ValidationError, aliasesFrom, assertReceipt, assertSections, attrsFor, briefDigest, canvasBridge, carryFor, componentizeSources, convertSources, convertedHere, coverageOf, declaringElements, dialectOf, exportedFunction, findSites, findSitesTolerant, flat, helperSource, importsIn, isDynamicRoute, isKnownHelper, isSourceCandidate, locate, overlapping, pageFilesFor, parseFile, propsAttribute, readBrief, readComponentizePlan, readDeclarations, readExpr, readPlan, relativeImport, resolveSpecifier, rewriteFile, routeOfFile, stripTags, unreadableConfigs, walkAst };
1473
+ export { ASTRO_LANE_PENDING, type AstNode, type AttrBinding, type Brief, 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, type FileDeclaration, type FindSitesResult, 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 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 SectionsReceipt, type Site, type SiteWhere, type SourceFile, type Splice, type TargetIdentity, type UnlocatedPath, type ValidationCode, ValidationError, aliasesFrom, assertReceipt, assertSections, assetCandidates, assetImport, attrsFor, bindDataLiterals, bindImages, briefDigest, canvasBridge, carryFor, componentizeSources, convertSources, convertedHere, coverageOf, declaringElements, dialectOf, exportedFunction, findSites, findSitesTolerant, flat, helperSource, importsIn, isDynamicRoute, isKnownHelper, isSourceCandidate, locate, overlapping, pageFilesFor, parseFile, propsAttribute, readBrief, readComponentizePlan, readDeclarations, readExpr, readPlan, relativeImport, resolveSpecifier, rewriteFile, routeOfFile, stripTags, unreadableConfigs, walkAst };