@bettercms-ai/convert 0.6.0 → 0.8.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 {
@@ -279,9 +283,15 @@ interface DynamicBinding {
279
283
  * later reason may name the wrong cause. `TSCONFIG_UNREADABLE` is the first — a project config this
280
284
  * package could not parse declares no `paths` aliases as far as it is concerned, so every aliased
281
285
  * import resolves to nothing and the component behind it reads as one the page does not import.
286
+ *
287
+ * `PRIMITIVE_LIST` is the second, and it is about a CONVERSION rather than a silence: an array of
288
+ * primitives or tuples renders exactly the paths the codemod wrote into it, so every row's text is
289
+ * editable and the NUMBER of rows is still the template's — a row added in the CMS does not appear
290
+ * and a deleted one falls back to the template's own copy. The paths are `rewritten` and true; what
291
+ * the note adds is that ceiling. @see bindLists
282
292
  */
283
293
  interface ReceiptNote {
284
- code: "TSCONFIG_UNREADABLE";
294
+ code: "TSCONFIG_UNREADABLE" | "TSCONFIG_EXTENDS_ONLY" | "PRIMITIVE_LIST";
285
295
  file: string;
286
296
  message: string;
287
297
  }
@@ -712,7 +722,7 @@ declare function attrsFor(path: string, kind: string, props?: AttrBinding[], sco
712
722
  declare function propsAttribute(props: AttrBinding[]): string;
713
723
 
714
724
  /** Bumped whenever the emitted source changes. `isKnownHelper` upgrades anything older. */
715
- declare const HELPER_VERSION = 4;
725
+ declare const HELPER_VERSION = 6;
716
726
  /** Where each dialect's helper lives. Null = this dialect reads nothing at build time. */
717
727
  declare const HELPER_PATH: Record<Dialect, string | null>;
718
728
  /** The directory the snapshots live in, at the repository root. */
@@ -739,6 +749,231 @@ declare function helperSource(dialect: Dialect): string;
739
749
  */
740
750
  declare function isKnownHelper(content: string, dialect: Dialect): number | null;
741
751
 
752
+ /**
753
+ * Copy that lives in a DATA LITERAL beside the markup, rendered through `.map`.
754
+ *
755
+ * 🔴 THE SHAPE EVERY REAL TEMPLATE IS MADE OF. `deriveSchema` reads the BUILT page, so three cards
756
+ * come back as `features[0..2]` whatever produced them — but the repository does not render three
757
+ * `<article>`s, it renders
758
+ *
759
+ * const features = [{ title: "…", text: "…" }, …];
760
+ * … {features.map((feature, i) => <Card><h3>{feature.title}</h3>…</Card>)}
761
+ *
762
+ * The copy is in the FRONTMATTER, the markup renders an expression, and the matcher is blind to
763
+ * both by construction (a string in a program is a program's; an expression may not render at
764
+ * all). So every one of those leaves came back `NOT_IN_SOURCE` with the value in plain sight, and
765
+ * the loop lane never fired either — `emitRepeater` templates repeated SIBLINGS, and here there is
766
+ * exactly one element in the source.
767
+ *
768
+ * WHAT THIS WRITES, and why it is the smallest edit that works:
769
+ *
770
+ * const features = bcmsRowsAs(bcmsHome, "features", [{ title: "…", text: "…" }, …],
771
+ * { title: "h3-field", text: "p-field" });
772
+ * … <h3 data-bcms-field={`features[${i}].h3-field`} data-bcms-kind="text">{feature.title}</h3>
773
+ *
774
+ * The ARRAY is read from the CMS and the ORIGINAL property names are kept, so not one byte of the
775
+ * markup's expressions changes: `feature.tone`, `feature.link` and every other property the brief
776
+ * never heard of keep working, which is what a template does with the half of a row that is
777
+ * styling rather than copy. @see bcmsRowsAs, which merges each CMS row over the row the template
778
+ * shipped with for exactly that reason.
779
+ *
780
+ * WHAT IT REFUSES, by name rather than by guessing: an identifier iterated in two places
781
+ * (`REPEATER_AMBIGUOUS` — one declaration, two loops, and nothing says which one the brief's rows
782
+ * came from), a property that reaches the markup through a component or a transform
783
+ * (`PROP_TARGET_NOT_FOUND` / `IN_EXPRESSION`), and a leaf nested one array deeper
784
+ * (`PROP_DRILLED_DEEP`).
785
+ */
786
+
787
+ /** One brief leaf of one row of one group — the same identity `loops.ts` calls a member. */
788
+ interface DataMember {
789
+ key: string;
790
+ path: string;
791
+ kind: string;
792
+ /** The copy this leaf renders today, whitespace-flattened as the matcher flattens it. */
793
+ literal: string;
794
+ /** The page this leaf belongs to. Its snapshot is what the rows are read from. */
795
+ slug: string;
796
+ }
797
+ /** A byte range to replace, or a point to insert at when `start === end`. */
798
+ interface DataSplice {
799
+ start: number;
800
+ end: number;
801
+ text: string;
802
+ }
803
+ /** What one drill did, or why it could not. @see drillProp, which is the implementation. */
804
+ type DrillOutcome = {
805
+ ok: true;
806
+ edits: {
807
+ file: string;
808
+ splices: DataSplice[];
809
+ }[];
810
+ } | {
811
+ ok: false;
812
+ reason: PendingReason;
813
+ };
814
+ interface DataContext {
815
+ content: string;
816
+ parsed: ParsedFile;
817
+ dialect: Dialect;
818
+ /** The name `bcmsRowsAs` is imported under here. @see scope.ts */
819
+ rowsAs: string;
820
+ /** The names `bcmsList` and `bcmsTuples` are imported under here. @see bindLists */
821
+ list: string;
822
+ tuples: string;
823
+ /** The name `bcms` is imported under here — the scalar lane's read. @see scope.ts */
824
+ read: string;
825
+ /** The identifier a page's snapshot is imported under in this file. @see scope.ts */
826
+ snapshotName: (slug: string) => string;
827
+ /** How this file reads its route parameter, on a dynamic route. Null off one. */
828
+ slug: string | null;
829
+ /**
830
+ * Follow one prop from a call site in THIS file into the component that renders it.
831
+ *
832
+ * Handed in rather than imported: the drill needs every source file, the alias table and the set
833
+ * of files this conversion already rewrites, and none of that is one file's business. Absent on
834
+ * a caller that cannot drill (the tests of this lane alone), which makes a row leaf passed as a
835
+ * prop the refusal it was before. @see index.ts
836
+ */
837
+ drill?: (component: string, prop: string, kind: string) => Promise<DrillOutcome>;
838
+ }
839
+ interface DataResult {
840
+ splices: DataSplice[];
841
+ /** Did anything here write a `bcms(…)` read, so the file has to import one? @see bindScalar */
842
+ usesRead: boolean;
843
+ /** Did anything here write a `bcmsRowsAs(…)` read? */
844
+ usesRows: boolean;
845
+ /** Did anything here write a `bcmsList(…)` / `bcmsTuples(…)` read? @see bindLists */
846
+ usesList: boolean;
847
+ usesTuples: boolean;
848
+ /**
849
+ * One sentence per list this lane bound, for the receipt's `PRIMITIVE_LIST` notes.
850
+ *
851
+ * The FILE is the caller's to add: this lane is handed one file's bytes and does not know its
852
+ * name, exactly as `findSites` does not. @see ReceiptNote
853
+ */
854
+ notes: string[];
855
+ /** The page slugs whose snapshot this lane now reads, so the file imports them. */
856
+ slugs: string[];
857
+ /** Target keys this plan bound. */
858
+ bound: string[];
859
+ /** What the file now declares, as a shape and as the bytes that resolve it. @see RepeaterPlan */
860
+ declarations: {
861
+ path: string;
862
+ literal: string;
863
+ }[];
864
+ /** Target keys this plan could not bind, each with the reason it could not. */
865
+ refused: {
866
+ key: string;
867
+ reason: PendingReason;
868
+ }[];
869
+ /** Edits to the COMPONENT files this lane drilled a row leaf into. @see DataContext.drill */
870
+ componentEdits: {
871
+ file: string;
872
+ splices: DataSplice[];
873
+ }[];
874
+ /**
875
+ * One drilled row leaf: the component file that now declares it, and the call site's own entry.
876
+ *
877
+ * The receipt records both halves of a prop conversion — the element is in another file and the
878
+ * path it reads is at the call site — and a reader cannot verify either half from the other
879
+ * alone. @see DynamicBinding
880
+ */
881
+ props: {
882
+ file: string;
883
+ prop: string;
884
+ path: string;
885
+ literal: string;
886
+ }[];
887
+ }
888
+ /**
889
+ * Bind every repeater group whose copy lives in a data literal in this same file.
890
+ *
891
+ * `members` is every indexed brief leaf this file could not otherwise place; groups it cannot
892
+ * account for are returned in `refused` with the reason, and are never partially written — a group
893
+ * half bound is a row whose second field silently stops reflecting.
894
+ */
895
+ declare function bindDataLiterals(ctx: DataContext, members: DataMember[]): Promise<DataResult>;
896
+
897
+ /**
898
+ * An image whose `original` is a BUILT url, and the import the template actually renders.
899
+ *
900
+ * 🔴 THE BRIEF CANNOT NAME THE FILE. `deriveSchema` reads the built page, where an asset the
901
+ * bundler processed is `/_astro/workspace.do77EGgx_ZNfVA8.jpg` — a name that exists nowhere in the
902
+ * repository, and whose EXTENSION is not even the source's (Astro serves the same `.jpg` as
903
+ * `.webp` on one route and `.avif` on the next). So `locate` found nothing, every such path came
904
+ * back `NOT_IN_SOURCE`, and an image was the one kind of field a converted site never had.
905
+ *
906
+ * What survives the build is the BASE NAME. `workspace.do77EGgx_ZNfVA8.jpg` and
907
+ * `workspace.do77EGgx_YzFJw.webp` are both `workspace`, and the page that renders them says so
908
+ * itself: `import workspaceImage from "../assets/workspace.jpg"`. The import is the evidence —
909
+ * it is in the file being converted, it names a real path, and the element that renders it names
910
+ * the binding — so nothing here has to guess at bytes the scanner never opened (an image is not a
911
+ * source candidate, so the asset file is not in `sources` at all). @see scan.ts
912
+ *
913
+ * Ambiguity is refused rather than resolved: two imports whose base names both match, or an import
914
+ * nothing renders, is `IMAGE_ASSET_UNRESOLVED`.
915
+ */
916
+
917
+ /** One image target: a path whose value is a url and whose element renders an imported asset. */
918
+ interface ImageTarget {
919
+ key: string;
920
+ path: string;
921
+ kind: string;
922
+ /** The brief's `original` — the BUILT url. */
923
+ original: string;
924
+ slug: string;
925
+ }
926
+ interface ImageSplice {
927
+ start: number;
928
+ end: number;
929
+ text: string;
930
+ }
931
+ interface ImageContext {
932
+ content: string;
933
+ parsed: ParsedFile;
934
+ dialect: Dialect;
935
+ /** The name `bcmsImage` is imported under here. @see scope.ts */
936
+ image: string;
937
+ snapshotName: (slug: string) => string;
938
+ /** How this file reads its route parameter, on a dynamic route. Null off one. */
939
+ slug: string | null;
940
+ }
941
+ interface ImageResult {
942
+ splices: ImageSplice[];
943
+ slugs: string[];
944
+ bound: string[];
945
+ refused: {
946
+ key: string;
947
+ reason: "IMAGE_ASSET_UNRESOLVED";
948
+ }[];
949
+ }
950
+ /**
951
+ * Which local binding this built url came from, or null when nothing here says.
952
+ *
953
+ * Exported because the CALLER has to answer the same question one step earlier: an image path is
954
+ * unlocated by construction, so the file that renders it is found by asking every candidate page
955
+ * file whether it imports the asset. @see convertSources
956
+ */
957
+ declare function assetCandidates(parsed: ParsedFile, dialect: Dialect, original: string): string[];
958
+ /**
959
+ * The ONE binding, or null — which covers both "nothing matched" and "two did".
960
+ *
961
+ * 🔴 THE CALLER HAS TO TELL THOSE APART, which is why `assetCandidates` is the exported one.
962
+ * Collapsing them here made the ambiguous case indistinguishable from the absent one, and a
963
+ * repository holding `assets/team/hero.jpg` beside `assets/blog/hero.png` — a base name this
964
+ * cannot separate from one built url — reported `NOT_IN_SOURCE`, which is the opposite of the
965
+ * truth: the source has two of them.
966
+ */
967
+ declare function assetImport(parsed: ParsedFile, dialect: Dialect, original: string): string | null;
968
+ /**
969
+ * Bind every image path whose asset this file imports.
970
+ *
971
+ * The element's `src` becomes `bcmsImage(page, "<path>", <binding>)` — the CMS url when there is
972
+ * one, the import the bundler already optimised when there is not — so a build against the
973
+ * committed `{}` stub renders exactly the image the repository renders today.
974
+ */
975
+ declare function bindImages(ctx: ImageContext, targets: ImageTarget[]): ImageResult;
976
+
742
977
  /** The recipe an Astro site needs instead — never auto-migrate a site to SSR. */
743
978
  declare const SSR_DRAFT_RECIPE: string;
744
979
  interface CanvasSource {
@@ -808,6 +1043,17 @@ declare function aliasesFrom(sources: SourceFile[]): Map<string, string[]>;
808
1043
  * The note says which file to look at. @see ConversionReceipt.notes
809
1044
  */
810
1045
  declare function unreadableConfigs(sources: SourceFile[]): string[];
1046
+ /**
1047
+ * Project configs whose aliases are NOT in them — they `extends` another file.
1048
+ *
1049
+ * 🔴 AN ABSENT ALIAS TABLE LOOKS EXACTLY LIKE A PROJECT THAT HAS NONE, and the two have opposite
1050
+ * consequences: the second converts relative imports and is complete, the first refuses every
1051
+ * component reached through `@components/*` with the file sitting right there. `extends` chains
1052
+ * are not followed — the base may be a published package (`@tsconfig/strict`) rather than a file
1053
+ * in the tree — so the honest answer is to say so in the receipt rather than to resolve nothing
1054
+ * silently. @see aliasesFrom
1055
+ */
1056
+ declare function extendedConfigs(sources: SourceFile[]): string[];
811
1057
  /** The repository path a specifier names, or null when it is not among the files we were given. */
812
1058
  declare function resolveSpecifier(fromFile: string, specifier: string, files: Set<string>, aliases: Map<string, string[]>): string | null;
813
1059
  /** What one local name was imported from, and WHICH export of it. */
@@ -1292,4 +1538,4 @@ declare function convertSources(briefIn: Brief, sources: SourceFile[], options?:
1292
1538
  receipt: ConversionReceipt;
1293
1539
  }>;
1294
1540
 
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 };
1541
+ 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, extendedConfigs, 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 };