@homepages/concrete 9.1.0 → 11.0.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.
Files changed (171) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/README.md +1 -1
  3. package/codemods/manifest.json +5 -148
  4. package/dist/artifact/playground/client/assets/index-ByeGGedv.js +1259 -0
  5. package/dist/artifact/playground/client/assets/index-CxWPYOH2.css +1 -0
  6. package/dist/artifact/playground/client/index.html +2 -2
  7. package/dist/artifact/playground/client/island-canvas-host.mjs +1 -1
  8. package/dist/artifact/playground/host.mjs +42 -42
  9. package/dist/base.css +1 -8
  10. package/dist/cli/build/artifact.js +3 -2
  11. package/dist/cli/build/fixtures.js +2 -0
  12. package/dist/cli/check/render/inputs.js +3 -3
  13. package/dist/cli/check/stages/sections.js +6 -7
  14. package/dist/cli/dev/workspace-reader.js +10 -2
  15. package/dist/css/compile.js +3 -6
  16. package/dist/css/rules.js +1 -51
  17. package/dist/design-system/format-variants.js +1 -1
  18. package/dist/fixtures/media-store.js +3 -3
  19. package/dist/fixtures/resolve.js +28 -16
  20. package/dist/fixtures/rows.js +2 -2
  21. package/dist/fixtures/synthesize-empties.js +3 -1
  22. package/dist/fixtures.d.ts +1 -1
  23. package/dist/index.d.ts +7 -8
  24. package/dist/packages/external/concrete/package.js +1 -1
  25. package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +8 -6
  26. package/dist/packages/internal/fill-bake/dist/compute-reads.js +8 -4
  27. package/dist/packages/internal/fill-bake/dist/index.js +1 -1
  28. package/dist/packages/internal/fill-bake/dist/item-merge.js +32 -6
  29. package/dist/packages/internal/fill-bake/dist/linked-merge.js +5 -5
  30. package/dist/packages/internal/fill-bake/dist/list-grammar.js +4 -26
  31. package/dist/packages/internal/fill-vocabulary/dist/holder.js +3 -14
  32. package/dist/packages/internal/fill-vocabulary/dist/resolved-decision.js +1 -1
  33. package/dist/packages/internal/media-resolution/dist/document.js +17 -16
  34. package/dist/packages/internal/media-resolution/dist/image.js +41 -95
  35. package/dist/packages/internal/media-resolution/dist/index.js +1 -1
  36. package/dist/packages/internal/media-resolution/dist/list.js +11 -11
  37. package/dist/packages/internal/media-resolution/dist/media.js +17 -16
  38. package/dist/packages/internal/media-resolution/dist/records.js +4 -2
  39. package/dist/packages/internal/media-resolution/dist/slot.js +5 -5
  40. package/dist/packages/internal/media-resolution/dist/tour.js +17 -16
  41. package/dist/packages/internal/media-resolution/dist/video.js +24 -24
  42. package/dist/packages/internal/property-facts/dist/registry-facts.js +8 -1
  43. package/dist/packages/internal/section-contracts/dist/catalog.js +1 -5
  44. package/dist/packages/internal/section-contracts/dist/directly-linked-list-contract.js +2 -3
  45. package/dist/packages/internal/section-contracts/dist/fill-verb-contract.js +6 -3
  46. package/dist/packages/internal/section-contracts/dist/index.js +0 -1
  47. package/dist/packages/internal/section-contracts/dist/object-contract.js +4 -2
  48. package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +1 -1
  49. package/dist/packages/internal/section-contracts/dist/row-rule-contract.js +4 -2
  50. package/dist/packages/internal/section-contracts/dist/row-source-contract.js +7 -8
  51. package/dist/packages/internal/section-contracts/dist/runners.js +2 -11
  52. package/dist/packages/internal/section-contracts/dist/select-contract.js +7 -1
  53. package/dist/packages/internal/section-contracts/dist/source-contract.js +14 -10
  54. package/dist/packages/internal/section-contracts/dist/sources-contract.js +0 -2
  55. package/dist/packages/internal/section-contracts/dist/table-member.js +5 -8
  56. package/dist/packages/internal/source-resolution/dist/index.js +21 -188
  57. package/dist/packages/internal/template-artifact/dist/index.js +1 -1
  58. package/dist/packages/internal/template-artifact/dist/layout.js +12 -10
  59. package/dist/packages/internal/template-artifact/dist/manifest.js +1 -1
  60. package/dist/packages/internal/template-artifact/dist/verify.js +26 -14
  61. package/dist/packages/internal/template-contracts/dist/content-pick.js +24 -1
  62. package/dist/packages/internal/template-contracts/dist/document-value.d.ts +4 -6
  63. package/dist/packages/internal/template-contracts/dist/fact-keys.d.ts +3 -2
  64. package/dist/packages/internal/template-contracts/dist/fact-keys.js +19 -43
  65. package/dist/packages/internal/template-contracts/dist/fact-registry.d.ts +24 -3
  66. package/dist/packages/internal/template-contracts/dist/fact-registry.js +10 -3
  67. package/dist/packages/internal/template-contracts/dist/fill-builders.d.ts +1 -1
  68. package/dist/packages/internal/template-contracts/dist/fill-builders.js +2 -6
  69. package/dist/packages/internal/template-contracts/dist/fill-spec-schema.js +4 -1
  70. package/dist/packages/internal/template-contracts/dist/fill-spec.js +7 -6
  71. package/dist/packages/internal/template-contracts/dist/list.d.ts +1 -1
  72. package/dist/packages/internal/template-contracts/dist/list.js +7 -29
  73. package/dist/packages/internal/template-contracts/dist/mirror-kind.js +2 -2
  74. package/dist/packages/internal/template-contracts/dist/object.js +3 -2
  75. package/dist/packages/internal/template-contracts/dist/primitive-descriptors.js +1 -1
  76. package/dist/packages/internal/template-contracts/dist/process-builders.d.ts +2 -2
  77. package/dist/packages/internal/template-contracts/dist/read-graph.js +5 -32
  78. package/dist/packages/internal/template-contracts/dist/ref-locate.js +10 -6
  79. package/dist/packages/internal/template-contracts/dist/registry-facts.d.ts +1 -1
  80. package/dist/packages/internal/template-contracts/dist/registry-facts.js +13 -24
  81. package/dist/packages/internal/template-contracts/dist/registry-shape.d.ts +20 -4
  82. package/dist/packages/internal/template-contracts/dist/registry-shape.js +69 -11
  83. package/dist/packages/internal/template-contracts/dist/row-planners.js +1 -1
  84. package/dist/packages/internal/template-contracts/dist/row-ref.d.ts +4 -7
  85. package/dist/packages/internal/template-contracts/dist/row-ref.js +7 -23
  86. package/dist/packages/internal/template-contracts/dist/row-sources.js +3 -3
  87. package/dist/packages/internal/template-contracts/dist/row.d.ts +1 -1
  88. package/dist/packages/internal/template-contracts/dist/row.js +6 -7
  89. package/dist/packages/internal/template-contracts/dist/runtime-values.d.ts +11 -27
  90. package/dist/packages/internal/template-contracts/dist/section-schema-types.d.ts +1 -0
  91. package/dist/packages/internal/template-contracts/dist/slot-builders.d.ts +29 -37
  92. package/dist/packages/internal/template-contracts/dist/slot-builders.js +3 -8
  93. package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +2 -702
  94. package/dist/packages/internal/template-contracts/dist/slot-catalog.js +2 -498
  95. package/dist/packages/internal/template-contracts/dist/slot-overrides.js +4 -1
  96. package/dist/packages/internal/template-contracts/dist/slot-ref.d.ts +10 -5
  97. package/dist/packages/internal/template-contracts/dist/slot-value.d.ts +2 -1
  98. package/dist/packages/internal/template-contracts/dist/table-members.d.ts +5 -12
  99. package/dist/packages/internal/template-contracts/dist/table-members.js +7 -37
  100. package/dist/packages/internal/template-contracts/dist/tour-value.d.ts +4 -6
  101. package/dist/packages/internal/template-contracts/dist/video-value.d.ts +3 -4
  102. package/dist/primitives/Image.d.ts +4 -4
  103. package/dist/primitives/Tour.d.ts +2 -2
  104. package/dist/primitives/Video.d.ts +2 -2
  105. package/dist/primitives/slot-bindings.js +6 -13
  106. package/dist/primitives/slot-document.d.ts +1 -1
  107. package/dist/primitives/slot-download.d.ts +4 -2
  108. package/dist/primitives/slot-media.d.ts +6 -3
  109. package/dist/primitives/slot-media.js +1 -1
  110. package/dist/rules/registry.js +0 -6
  111. package/dist/schema/fact.d.ts +19 -52
  112. package/dist/schema/fact.js +6 -25
  113. package/dist/schema/facts-view.d.ts +1 -2
  114. package/dist/schema/format-presets.d.ts +1 -1
  115. package/dist/schema/property-facts.d.ts +1 -62
  116. package/dist/schema/section-schema.d.ts +6 -6
  117. package/dist/schema/section-schema.js +1 -1
  118. package/dist/styles.css +4 -4
  119. package/dist/template/define-template.js +0 -1
  120. package/guide/reference/cli/INDEX.md +2 -2
  121. package/guide/reference/cli/build.md +1 -1
  122. package/guide/reference/cli/check.md +1 -1
  123. package/guide/reference/cli/dev.md +1 -1
  124. package/guide/reference/cli/property-add.md +1 -1
  125. package/guide/reference/cli/property-list.md +1 -1
  126. package/guide/reference/cli/publish.md +1 -1
  127. package/guide/reference/cli/upgrade.md +1 -1
  128. package/guide/reference/rules/INDEX.md +2 -4
  129. package/package.json +2 -2
  130. package/codemods/fill-is-a-source.mjs +0 -533
  131. package/codemods/framework-namespace.mjs +0 -107
  132. package/codemods/list-grammar.mjs +0 -923
  133. package/codemods/object-form-only.mjs +0 -39
  134. package/codemods/platform-namespace.mjs +0 -83
  135. package/codemods/process-builders.mjs +0 -198
  136. package/codemods/reads-replace-reconcile.mjs +0 -285
  137. package/codemods/slot-object.mjs +0 -1097
  138. package/codemods/steps/content-object-fields.mjs +0 -324
  139. package/codemods/steps/list-object-form.mjs +0 -687
  140. package/codemods/steps/select-object-form.mjs +0 -210
  141. package/codemods/table-rows.mjs +0 -568
  142. package/codemods/theme-collapse.mjs +0 -396
  143. package/codemods/unlayer-author-css.mjs +0 -194
  144. package/codemods/unwrap-object-fields.mjs +0 -310
  145. package/codemods/viewer-slot-document.mjs +0 -131
  146. package/codemods/write-property-as-facts-document.mjs +0 -716
  147. package/codemods/write-the-address-line.mjs +0 -255
  148. package/codemods/write-the-registry-members.mjs +0 -653
  149. package/codemods/write-the-select-from.mjs +0 -141
  150. package/codemods/write-the-sole-from.mjs +0 -369
  151. package/codemods/write-the-table-from.mjs +0 -267
  152. package/codemods/write-the-whole-item.mjs +0 -512
  153. package/codemods/writeback-drop.mjs +0 -168
  154. package/codemods/written-contact-address.mjs +0 -162
  155. package/codemods/written-media-category.mjs +0 -227
  156. package/codemods/written-ref-kinds-name-the-layer.mjs +0 -172
  157. package/codemods/written-uploads-replace-pool-reads.mjs +0 -454
  158. package/codemods/written-uploads-sort-into-lists.mjs +0 -405
  159. package/codemods/written-uploads-stated-in-sorted-lists.mjs +0 -295
  160. package/codemods/written-video-sources-drop.mjs +0 -144
  161. package/codemods/written-without-pick-none.mjs +0 -146
  162. package/codemods/written-without-retired-knowledge.mjs +0 -223
  163. package/codemods/written-without-the-media-key.mjs +0 -202
  164. package/codemods/written-without-the-property-type.mjs +0 -249
  165. package/dist/artifact/playground/client/assets/index-BOYbgBnP.js +0 -1259
  166. package/dist/artifact/playground/client/assets/index-DDOcM0zA.css +0 -1
  167. package/dist/packages/internal/section-contracts/dist/option-source-contract.js +0 -22
  168. package/dist/packages/internal/template-contracts/dist/comparable-address.js +0 -19
  169. package/dist/packages/internal/template-contracts/dist/facts-view.d.ts +0 -62
  170. package/dist/packages/internal/template-contracts/dist/legacy-facts.js +0 -167
  171. package/dist/packages/internal/template-contracts/dist/registry-aliases.js +0 -77
@@ -3,7 +3,7 @@ purpose: The `concrete check` command — its flags, exit codes and constraints.
3
3
  mode: reference
4
4
  status: generated
5
5
  generated_from: the concrete command table
6
- applies_to: "@homepages/concrete >=9.0.0 <10.0.0"
6
+ applies_to: "@homepages/concrete >=11.0.0 <12.0.0"
7
7
  related: [reference/cli/INDEX.md]
8
8
  ---
9
9
  # concrete check
@@ -3,7 +3,7 @@ purpose: The `concrete dev` command — its flags, exit codes and constraints.
3
3
  mode: reference
4
4
  status: generated
5
5
  generated_from: the concrete command table
6
- applies_to: "@homepages/concrete >=9.0.0 <10.0.0"
6
+ applies_to: "@homepages/concrete >=11.0.0 <12.0.0"
7
7
  related: [reference/cli/INDEX.md]
8
8
  ---
9
9
  # concrete dev
@@ -3,7 +3,7 @@ purpose: The `concrete property add` command — its flags, exit codes and const
3
3
  mode: reference
4
4
  status: generated
5
5
  generated_from: the concrete command table
6
- applies_to: "@homepages/concrete >=9.0.0 <10.0.0"
6
+ applies_to: "@homepages/concrete >=11.0.0 <12.0.0"
7
7
  related: [reference/cli/INDEX.md]
8
8
  ---
9
9
  # concrete property add
@@ -3,7 +3,7 @@ purpose: The `concrete property list` command — its flags, exit codes and cons
3
3
  mode: reference
4
4
  status: generated
5
5
  generated_from: the concrete command table
6
- applies_to: "@homepages/concrete >=9.0.0 <10.0.0"
6
+ applies_to: "@homepages/concrete >=11.0.0 <12.0.0"
7
7
  related: [reference/cli/INDEX.md]
8
8
  ---
9
9
  # concrete property list
@@ -3,7 +3,7 @@ purpose: The `concrete publish` command — its flags, exit codes and constraint
3
3
  mode: reference
4
4
  status: generated
5
5
  generated_from: the concrete command table
6
- applies_to: "@homepages/concrete >=9.0.0 <10.0.0"
6
+ applies_to: "@homepages/concrete >=11.0.0 <12.0.0"
7
7
  related: [reference/cli/INDEX.md]
8
8
  ---
9
9
  # concrete publish
@@ -3,7 +3,7 @@ purpose: The `concrete upgrade` command — its flags, exit codes and constraint
3
3
  mode: reference
4
4
  status: generated
5
5
  generated_from: the concrete command table
6
- applies_to: "@homepages/concrete >=9.0.0 <10.0.0"
6
+ applies_to: "@homepages/concrete >=11.0.0 <12.0.0"
7
7
  related: [reference/cli/INDEX.md]
8
8
  ---
9
9
  # concrete upgrade
@@ -3,7 +3,7 @@ purpose: Every rule `concrete check` grades, by the stage that grades it, in the
3
3
  mode: reference
4
4
  status: generated
5
5
  generated_from: the concrete rule registry
6
- applies_to: "@homepages/concrete >=9.0.0 <10.0.0"
6
+ applies_to: "@homepages/concrete >=11.0.0 <12.0.0"
7
7
  related: [reference/cli/check.md]
8
8
  ---
9
9
  # Rule reference
@@ -100,7 +100,6 @@ The CSS import graph of `template.ts` compiles into the template stylesheet exac
100
100
  | `concrete/css/tailwind-import` | tree | The CSS import graph of template.ts carries no `@import "tailwindcss"`, or more than one. |
101
101
  | `concrete/css/external-url` | tree | A rendered template's compiled stylesheet references an external URL, which the renderer cannot reach. |
102
102
  | `concrete/css/compile-failed` | tree | A stylesheet reachable from template.ts fails to resolve or compile, so no stylesheet rule could grade it. |
103
- | `concrete/css/retired-layer` | tree | A stylesheet declares `@layer sections` or `@layer template`, the layers the framework retired; author CSS is unlayered. |
104
103
 
105
104
  ## logic
106
105
 
@@ -161,8 +160,7 @@ Every placed section's schema and fill spec satisfy the contract assertions publ
161
160
  | `concrete/contract/record-collection` | contract | A list bound to a fact binds a registry table and may only narrow its min and max. |
162
161
  | `concrete/contract/nested-slot-types` | contract | An object's fields, a nested list item's included, are each a value slot, a row or a list, of a kind the catalog declares. |
163
162
  | `concrete/contract/list-scalar` | contract | A list declares exactly one legal item, a value element, an object or a row, with satisfiable bounds. |
164
- | `concrete/contract/select` | contract | A select declares exactly one of values or options. |
165
- | `concrete/contract/option-source` | contract | A select with an option source names a source the platform provides. |
163
+ | `concrete/contract/select` | contract | A select names its choices in exactly one place: its values, or a fact it is bound to that declares them. |
166
164
  | `concrete/contract/url` | contract | A url slot's accepts names a link kind or provider that a registered provider implements. |
167
165
  | `concrete/contract/sources` | contract | No slot declares sources, since a media slot takes a pasted link wherever a link provider claims its kind; a media slot picks `from` a media list of the property, or owns its asset without one, and processes only what its kind takes; a slot bound to a fact states neither. |
168
166
  | `concrete/contract/interpolation` | contract | A fill brief refers to its facts through reads and never interpolates one. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homepages/concrete",
3
- "version": "9.1.0",
3
+ "version": "11.0.0",
4
4
  "description": "Concrete, the HomePages template framework: the authoring API, the contract primitives, the styles, the lint preset and the `concrete` command in one package that owns its whole toolchain.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -88,7 +88,7 @@
88
88
  "optionalDependencies": {
89
89
  "sharp": "^0.35.3"
90
90
  },
91
- "$comment:devDependencies": "Every `@homepages/*` entry is a private workspace package compiled INTO dist by tsdown, which externalizes only dependencies, peerDependencies and optionalDependencies: nothing about them survives into a consumer's dependency graph, and the packed tarball declares no `workspace:*` edge in any block a consumer installs (src/package-boundary.test.ts). The set is every internal package the old kit and CLI inline, declared here once so the command, check, dev and build modules that follow reach them without a manifest change; a module the shipped entries do not reach today is simply not in dist yet. One entry is never inlined: `@homepages/portability-lint` is imported by eslint.config.mjs alone, the lint rules that grade this package's own source.",
91
+ "$comment:devDependencies": "Every `@homepages/*` entry is a private workspace package compiled INTO dist by tsdown, which externalizes only dependencies, peerDependencies and optionalDependencies: nothing about them survives into a consumer's dependency graph, and the packed tarball declares no `workspace:*` edge in any block a consumer installs (src/package-boundary.test.ts). The set is every internal package Concrete inlines, declared here once so the command, check, dev and build modules that follow reach them without a manifest change; a module the shipped entries do not reach today is simply not in dist yet. One entry is never inlined: `@homepages/portability-lint` is imported by eslint.config.mjs alone, the lint rules that grade this package's own source.",
92
92
  "devDependencies": {
93
93
  "@arethetypeswrong/cli": "^0.18.5",
94
94
  "@eslint/js": "^10.0.1",
@@ -1,533 +0,0 @@
1
- // 6.0.0 — one `fill()`, declared as a kind of `source:`.
2
- //
3
- // Before this release a slot's fill was one of eleven builders (`textBlock`, `listFill`,
4
- // `imageAssign`, `videoAssign`, `tourAssign`, `documentAssign`, `contactAssign`,
5
- // `chooseFrom`, `nameRows`) under its own `fill:` key, its instruction split across up
6
- // to six prose keys (`voice`, `content`, `pick`, `structureHint`, and the two enums
7
- // `structure` and `perspective`). Now a slot declares its origin once, in `source:`, and
8
- // a fill is `fill({ brief, none?, count?, cap?, reads? })`: what the model DOES is the
9
- // slot's own fact, the one prose key is `brief`, and `none` is the switch `true`.
10
- //
11
- // What this codemod does, in every `.ts` and `.tsx` under the workspace:
12
- //
13
- // - Rewrites each builder call whose argument is an object literal to `fill({…})`: the
14
- // prose keys merge into `brief` exactly as the platform merges a stored decision's, one
15
- // paragraph each — `content` (else `pick`), `Voice: <voice>`, `Form: <structureHint>`,
16
- // then each enum as the canonical sentence below (`third` is the default and is
17
- // dropped), then the `none` bar as `Produce nothing when: <none>`. A ported fill and
18
- // one published before this release read the same. `none` becomes `true` (a blank
19
- // one, which never switched anything on, is dropped); `cap` and `reads` carry over;
20
- // `count` carries over, with a `min: 0` dropped (zero is reachable only through
21
- // `none`).
22
- // - Renames a slot builder's `fill:` option to `source:`.
23
- // - Gives every decision that used to read the platform's standing slice of property
24
- // facts that slice as an explicit `reads`: a fill now sees exactly its own `reads`, so
25
- // a migrated one sees what it saw. The eight refs are hoisted once, into
26
- // `fill-reads.ts` at the workspace root, as `PROPERTY` — yours to prune per decision.
27
- // - Rewrites the imports: the old builder names out, `fill` and `PROPERTY` in.
28
- //
29
- // What it leaves to you, reported per file:
30
- //
31
- // - Each `none` bar it folded into a brief, by line: the joined paragraph restates the
32
- // brief's own exclusion more often than not, so rewrite it as the brief's last
33
- // sentence saying when producing nothing is right.
34
- // - `order: "walkthrough"` is dropped. A walkthrough seated EVERY photo; a pick keeps
35
- // what its brief admits, so add a clause dropping anything that is not a photograph
36
- // of the property (a logo, a flyer).
37
- // - `fallback` is dropped: a pick that abstains now lands empty. Re-author the chain as
38
- // a `none` pick plus a contact-bound slot and a `compute()` over the pick.
39
- // - `contactAssign` has no replacement: bind the contact's field with
40
- // `source: fact.contact.*`, or write the choice as a text fill reading the contacts.
41
- // - A brief interpolating `${facts.…}`: declare the fact in `reads` and refer to it by
42
- // name instead.
43
- // - A builder call whose argument is not an object literal (a hoisted options object, a
44
- // spread) — the prose keys cannot be merged without seeing them.
45
-
46
- import { readdir, readFile, stat, writeFile } from "node:fs/promises";
47
- import { dirname, join, relative, sep } from "node:path";
48
-
49
- import ts from "typescript";
50
-
51
- const CONCRETE = "@homepages/concrete";
52
-
53
- /** The builders `fill()` replaced. */
54
- const BUILDERS = new Set([
55
- "textBlock",
56
- "listFill",
57
- "imageAssign",
58
- "videoAssign",
59
- "tourAssign",
60
- "documentAssign",
61
- "contactAssign",
62
- "chooseFrom",
63
- "nameRows",
64
- ]);
65
-
66
- /** The types that went with them. */
67
- const RETIRED_TYPES = new Set(["BuiltDecision", "ChosenRows", "DecisionKind", "DisplayChoice", "NamedRows", "RowOrigination", "TextStructure"]);
68
-
69
- /** The builders whose executor read the standing slice — the ones a migrated fill gives `reads: PROPERTY`. */
70
- const SLICE_READERS = new Set(["textBlock", "listFill", "chooseFrom", "nameRows"]);
71
-
72
- /** The slot builders whose options object carries the origin. */
73
- const SLOT_BUILDERS = new Set(["text.short", "text.medium", "text.long", "image", "video", "tour", "document", "list.of", "select", "select.of", "number", "url"]);
74
-
75
- /**
76
- * The canonical sentence each enum value becomes — the platform's own merge of a
77
- * stored decision's prose keys uses the same words in the same order, so a template
78
- * ported here and a section published before this release send the model the same
79
- * brief. `third` is the default person and has no sentence.
80
- */
81
- const STRUCTURE_SENTENCE = {
82
- single_sentence: "Write one sentence.",
83
- paragraph: "Write one paragraph.",
84
- bullet_list: "Write a bulleted list.",
85
- value: "Answer with the bare value alone, never a sentence.",
86
- };
87
- const PERSPECTIVE_SENTENCE = {
88
- first: "Write in the first person.",
89
- second: "Write in the second person, addressing the reader.",
90
- third: null,
91
- };
92
-
93
- /** The standing slice, as refs. */
94
- const PROPERTY_REFS = [
95
- "fact.property.address",
96
- "fact.property.latitude",
97
- "fact.property.longitude",
98
- "fact.property.property_type",
99
- "fact.property.listing_intent",
100
- "fact.property.units",
101
- "fact.description",
102
- "fact.document_notes",
103
- ];
104
-
105
- const READS_MODULE = "fill-reads.ts";
106
- const READS_CONST = "PROPERTY";
107
-
108
- const READS_SOURCE = `// The property facts every fill was shown before \`fill()\` read exactly its own
109
- // \`reads\`: the platform's standing slice, hoisted here once by the 6.0.0 upgrade so
110
- // each migrated fill still sees what it saw. It is yours: drop from a fill's \`reads\`
111
- // whatever its brief does not use, and delete this file once nothing imports it.
112
- import { fact } from "${CONCRETE}";
113
-
114
- export const ${READS_CONST} = [
115
- ${PROPERTY_REFS.map((ref) => ` ${ref},`).join("\n")}
116
- ] as const;
117
- `;
118
-
119
- /** The column a rewritten `fill({…})` must end by to stay on one line. */
120
- const LINE_WIDTH = 140;
121
-
122
- const EXTENSIONS = [".ts", ".tsx"];
123
- const SKIP_DIRS = new Set(["node_modules", ".concrete", ".git", "dist", "build"]);
124
-
125
- async function sourceFiles(root) {
126
- const found = [];
127
- async function walk(dir) {
128
- for (const entry of await readdir(dir, { withFileTypes: true })) {
129
- if (entry.isDirectory()) {
130
- if (!SKIP_DIRS.has(entry.name)) await walk(join(dir, entry.name));
131
- } else if (EXTENSIONS.some((ext) => entry.name.endsWith(ext)) && !entry.name.endsWith(".d.ts")) {
132
- found.push(join(dir, entry.name));
133
- }
134
- }
135
- }
136
- await walk(root);
137
- return found.sort();
138
- }
139
-
140
- async function exists(path) {
141
- try {
142
- await stat(path);
143
- return true;
144
- } catch {
145
- return false;
146
- }
147
- }
148
-
149
- // ----- prose ---------------------------------------------------------------
150
-
151
- /** One piece of the brief: literal text, or an expression the author computed. */
152
- function prosePart(node, sf) {
153
- if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) return { text: node.text };
154
- if (ts.isTemplateExpression(node)) return { template: node.getText(sf).slice(1, -1) };
155
- return { expr: node.getText(sf) };
156
- }
157
-
158
- /**
159
- * The label the `none` bar is folded into the brief under. The platform folds a stored
160
- * decision's bar the same way, so a ported fill and a published one read the same.
161
- */
162
- const NONE_LABEL = "Produce nothing when: ";
163
-
164
- const escapeTemplate = (text) => text.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
165
-
166
- /** Each piece becomes one paragraph of the brief, as the platform's own merge joins them. */
167
- const PARAGRAPH = "\n\n";
168
-
169
- /**
170
- * The merged brief as source text, and its literal content for the interpolation scan.
171
- * A piece carries an optional `label` (`Voice: `, `Form: `) the merge prefixes it with.
172
- */
173
- function briefSource(parts) {
174
- const kept = parts.filter((p) => p.text === undefined || p.text.trim() !== "");
175
- const label = (p) => p.label ?? "";
176
- if (kept.every((p) => p.text !== undefined)) {
177
- const text = kept.map((p) => `${label(p)}${p.text.trim()}`).join(PARAGRAPH);
178
- return { source: JSON.stringify(text), scanned: text };
179
- }
180
- const pieces = kept.map((p) => {
181
- if (p.text !== undefined) return escapeTemplate(`${label(p)}${p.text.trim()}`);
182
- if (p.template !== undefined) return `${escapeTemplate(label(p))}${p.template}`;
183
- return `${escapeTemplate(label(p))}\${${p.expr}}`;
184
- });
185
- const scanned = kept.map((p) => `${label(p)}${p.text ?? p.template ?? ""}`).join(PARAGRAPH);
186
- return { source: `\`${pieces.join("\\n\\n")}\``, scanned };
187
- }
188
-
189
- // ----- one builder call ------------------------------------------------------
190
-
191
- /** The object literal's members by name, or why the call cannot be read. */
192
- function membersOf(arg, sf) {
193
- if (arg === undefined) return { members: new Map() };
194
- if (!ts.isObjectLiteralExpression(arg)) return { refused: "its options are not an object literal, so the prose keys cannot be merged" };
195
- const members = new Map();
196
- const properties = new Map();
197
- for (const property of arg.properties) {
198
- if (ts.isPropertyAssignment(property) && (ts.isIdentifier(property.name) || ts.isStringLiteral(property.name))) {
199
- members.set(property.name.text, property.initializer);
200
- properties.set(property.name.text, property);
201
- } else if (ts.isShorthandPropertyAssignment(property)) {
202
- members.set(property.name.text, property.name);
203
- properties.set(property.name.text, property);
204
- } else {
205
- return { refused: `its options carry \`${property.getText(sf).slice(0, 40)}\`, which cannot be merged without seeing it` };
206
- }
207
- }
208
- return { members, properties };
209
- }
210
-
211
- /**
212
- * The comments an author wrote inside a builder's options, by the key each sits above,
213
- * so the port can carry them to the entry that key became. Those after the last key are
214
- * filed under `""`.
215
- */
216
- function commentsOf(arg, properties, sf) {
217
- const byKey = new Map();
218
- if (arg === undefined || !ts.isObjectLiteralExpression(arg)) return byKey;
219
- const grab = (pos) => (ts.getLeadingCommentRanges(sf.text, pos) ?? []).map((range) => sf.text.slice(range.pos, range.end));
220
- for (const [key, property] of properties) {
221
- const found = grab(property.getFullStart());
222
- if (found.length > 0) byKey.set(key, found);
223
- }
224
- const last = arg.properties.at(-1);
225
- if (last !== undefined) {
226
- const after = arg.properties.hasTrailingComma ? sf.text.indexOf(",", last.getEnd()) + 1 : last.getEnd();
227
- const found = grab(after);
228
- if (found.length > 0) byKey.set("", found);
229
- }
230
- return byKey;
231
- }
232
-
233
- /** `{ min: 0, max: N }` → `{ max: N }`; everything else as written. */
234
- function countSource(node, sf, yours) {
235
- if (!ts.isObjectLiteralExpression(node)) return node.getText(sf);
236
- const { members, refused } = membersOf(node, sf);
237
- if (refused !== undefined) return node.getText(sf);
238
- const min = members.get("min");
239
- const max = members.get("max");
240
- if (max === undefined) {
241
- yours.push("a `count` with no `max` — a count is `N`, `{ max }` or `{ min, max }`; state the ceiling");
242
- return node.getText(sf);
243
- }
244
- if (min === undefined || (ts.isNumericLiteral(min) && Number(min.text) === 0)) return `{ max: ${max.getText(sf)} }`;
245
- return `{ min: ${min.getText(sf)}, max: ${max.getText(sf)} }`;
246
- }
247
-
248
- /**
249
- * The `fill({…})` text one builder call becomes, or `refused` with the reason. `yours`
250
- * collects what the port leaves to the author.
251
- */
252
- function fillCall(name, call, sf, yours) {
253
- const indent = lineIndent(sf, call.getStart(sf));
254
- const column = sf.getLineAndCharacterOfPosition(call.getStart(sf)).character;
255
- if (name === "contactAssign") {
256
- return { refused: "`contactAssign` has no replacement — bind the contact's field with `source: fact.contact.*`, or write the choice as a text fill reading the contacts" };
257
- }
258
- if (call.arguments.length > 1) return { refused: `\`${name}\` takes one options object` };
259
- const { members, properties, refused } = membersOf(call.arguments[0], sf);
260
- if (refused !== undefined) return { refused: `\`${name}(…)\`: ${refused}` };
261
-
262
- const part = (key) => (members.has(key) ? prosePart(members.get(key), sf) : undefined);
263
- const enumSentence = (key, table) => {
264
- const node = members.get(key);
265
- if (node === undefined) return undefined;
266
- if (!ts.isStringLiteral(node)) return prosePart(node, sf);
267
- const sentence = table[node.text];
268
- return sentence === null || sentence === undefined ? undefined : { text: sentence };
269
- };
270
-
271
- // The platform's own merge, piece for piece: `content ?? pick` (one brief under two
272
- // names — an executor always read them as one), then the voice, the form, the
273
- // structure's sentence and the person's.
274
- const content = part("content");
275
- const body = content !== undefined && (content.text === undefined || content.text.trim() !== "") ? content : part("pick");
276
- const labelled = (key, label) => {
277
- const piece = part(key);
278
- return piece === undefined ? undefined : { ...piece, label };
279
- };
280
- // `none` was a second brief; it is a switch now, and its bar joins the one brief. A
281
- // blank one never switched abstention on, so it folds nothing and is dropped.
282
- const bar = labelled("none", NONE_LABEL);
283
- const abstains = bar !== undefined && (bar.text === undefined || bar.text.trim() !== "");
284
- const parts = [
285
- body,
286
- labelled("voice", "Voice: "),
287
- labelled("structureHint", "Form: "),
288
- enumSentence("structure", STRUCTURE_SENTENCE),
289
- enumSentence("perspective", PERSPECTIVE_SENTENCE),
290
- ].filter((p) => p !== undefined);
291
- if (parts.length === 0) return { refused: `\`${name}(…)\` states no prose at all — write its \`brief\`` };
292
- if (abstains) {
293
- parts.push(bar);
294
- const line = sf.getLineAndCharacterOfPosition(members.get("none").getStart(sf)).line + 1;
295
- yours.push(
296
- `\`none\` is \`true\` now, and its bar is the brief's last paragraph (\`${NONE_LABEL.trim()} …\`) — rewrite it as the brief's own sentence saying when producing nothing is right, at line ${line}`,
297
- );
298
- }
299
- const brief = briefSource(parts);
300
- if (/\$\{\s*facts\./.test(brief.scanned)) {
301
- yours.push("a brief interpolates `${facts.…}` — declare that fact in `reads` and refer to it by name");
302
- }
303
-
304
- if (members.has("order")) {
305
- yours.push(
306
- "`order: \"walkthrough\"` is gone and a pick keeps only what its brief admits — say to keep and order every photograph, and to drop anything that is not a photograph of the property",
307
- );
308
- }
309
- if (members.has("fallback")) {
310
- yours.push(
311
- "`fallback` is gone — a pick that abstains lands empty. Keep the `none` pick, bind the fallback's slot with `source: fact.contact.*`, and choose between them with `compute({ reads: [pick] }, …)`",
312
- );
313
- }
314
-
315
- // Each entry keeps the comments written above the key(s) it came from — the prose
316
- // keys' and the dropped keys' above the brief — so nothing the author wrote is lost.
317
- const comments = commentsOf(call.arguments[0], properties, sf);
318
- const entries = [];
319
- const entry = (text, ...keys) => entries.push({ text, comments: keys.flatMap((key) => comments.get(key) ?? []) });
320
- if (SLICE_READERS.has(name)) {
321
- const declared = members.get("reads");
322
- if (declared === undefined) entry(`reads: ${READS_CONST}`);
323
- else if (ts.isArrayLiteralExpression(declared)) {
324
- const items = declared.elements.map((e) => e.getText(sf));
325
- entry(`reads: [...${READS_CONST}${items.length === 0 ? "" : `, ${items.join(", ")}`}]`, "reads");
326
- } else entry(`reads: [...${READS_CONST}, ...${declared.getText(sf)}]`, "reads");
327
- } else if (members.has("reads")) {
328
- entry(`reads: ${members.get("reads").getText(sf)}`, "reads");
329
- }
330
- const carried = new Set(["reads", "count", "cap", ...(abstains ? ["none"] : [])]);
331
- entry(`brief: ${brief.source}`, ...[...members.keys()].filter((key) => !carried.has(key)));
332
- if (abstains) entry("none: true", "none");
333
- if (members.has("count")) entry(`count: ${countSource(members.get("count"), sf, yours)}`, "count");
334
- if (members.has("cap")) entry(`cap: ${members.get("cap").getText(sf)}`, "cap");
335
- const trailing = comments.get("") ?? [];
336
-
337
- const inner = `${indent} `;
338
- const place = (comment) => `${inner}${comment}`;
339
- const commented = trailing.length > 0 || entries.some((e) => e.comments.length > 0);
340
- const oneLine = `fill({ ${entries.map((e) => e.text).join(", ")} })`;
341
- const text =
342
- !commented && column + oneLine.length <= LINE_WIDTH && !oneLine.includes("\n")
343
- ? oneLine
344
- : `fill({\n${[...entries.flatMap((e) => [...e.comments.map(place), `${inner}${e.text},`]), ...trailing.map(place)].join("\n")}\n${indent}})`;
345
- return { text, readsSlice: SLICE_READERS.has(name) };
346
- }
347
-
348
- // ----- one file --------------------------------------------------------------
349
-
350
- /** The dotted callee name of a call: `text.medium`, `list.of`, `image`. */
351
- function calleeName(call) {
352
- const callee = call.expression;
353
- if (ts.isIdentifier(callee)) return callee.text;
354
- if (ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression)) return `${callee.expression.text}.${callee.name.text}`;
355
- return undefined;
356
- }
357
-
358
- function lineIndent(sf, pos) {
359
- const { line } = sf.getLineAndCharacterOfPosition(pos);
360
- const start = sf.getPositionOfLineAndCharacter(line, 0);
361
- return /^[ \t]*/.exec(sf.text.slice(start))[0];
362
- }
363
-
364
- // Where `fill` joins an import list: its sorted place when the author kept the list
365
- // sorted, else where the first builder it replaces stood.
366
- function insertionIndex(kept, fillAt) {
367
- const key = (specifier) => specifier.replace(/^type\s+/, "").toLowerCase();
368
- const sorted = kept.every((k, i) => i === 0 || key(kept[i - 1]) <= key(k));
369
- if (!sorted) return fillAt ?? kept.length;
370
- const at = kept.findIndex((k) => key(k) > "fill");
371
- return at === -1 ? kept.length : at;
372
- }
373
-
374
- /** Rewrites one file's text, or returns `null` when nothing in it is this codemod's. */
375
- function rewrite(text, fileName, readsImport) {
376
- const sf = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true, fileName.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
377
-
378
- // The builder names this file imports from the framework — a local function that
379
- // happens to share one is not ours to touch.
380
- const imported = new Map();
381
- const importDecls = [];
382
- for (const statement of sf.statements) {
383
- if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) continue;
384
- if (statement.moduleSpecifier.text !== CONCRETE) continue;
385
- const bindings = statement.importClause?.namedBindings;
386
- if (bindings === undefined || !ts.isNamedImports(bindings)) continue;
387
- importDecls.push(statement);
388
- for (const element of bindings.elements) imported.set(element.name.text, (element.propertyName ?? element.name).text);
389
- }
390
- const builderOf = (identifier) => {
391
- const original = imported.get(identifier);
392
- return original !== undefined && BUILDERS.has(original) ? original : undefined;
393
- };
394
-
395
- const edits = [];
396
- const yours = [];
397
- const refusedNames = new Set();
398
- let usesFill = false;
399
- let usesReads = false;
400
-
401
- function visit(node) {
402
- if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
403
- const builder = builderOf(node.expression.text);
404
- if (builder !== undefined) {
405
- const result = fillCall(builder, node, sf, yours);
406
- if (result.refused !== undefined) {
407
- yours.push(result.refused);
408
- refusedNames.add(node.expression.text);
409
- ts.forEachChild(node, visit);
410
- return;
411
- }
412
- edits.push({ start: node.getStart(sf), end: node.getEnd(), text: result.text });
413
- usesFill = true;
414
- if (result.readsSlice) usesReads = true;
415
- return;
416
- }
417
- }
418
- // A slot builder's `fill:` option is its `source:` now.
419
- if (ts.isCallExpression(node) && SLOT_BUILDERS.has(calleeName(node) ?? "")) {
420
- for (const arg of node.arguments) {
421
- if (!ts.isObjectLiteralExpression(arg)) continue;
422
- const hasSource = arg.properties.some((p) => p.name !== undefined && ts.isIdentifier(p.name) && p.name.text === "source");
423
- for (const property of arg.properties) {
424
- if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name) || property.name.text !== "fill") continue;
425
- if (hasSource) {
426
- yours.push("a slot declares both `source:` and `fill:` — keep the one origin it has");
427
- continue;
428
- }
429
- edits.push({ start: property.name.getStart(sf), end: property.name.getEnd(), text: "source" });
430
- }
431
- }
432
- }
433
- ts.forEachChild(node, visit);
434
- }
435
- visit(sf);
436
-
437
- // The imports: the builders that were rewritten and the retired types out of every
438
- // framework import, `fill` into the first that imports values — never an
439
- // `import type`, where it would type-check as nothing and the call would not bind.
440
- const importYours = [];
441
- if (importDecls.length > 0) {
442
- const fillHost = importDecls.find((decl) => !decl.importClause.isTypeOnly);
443
- const alreadyFill = importDecls.some(
444
- (decl) => !decl.importClause.isTypeOnly && decl.importClause.namedBindings.elements.some((e) => !e.isTypeOnly && e.name.text === "fill"),
445
- );
446
- for (const decl of importDecls) {
447
- const bindings = decl.importClause.namedBindings;
448
- const kept = [];
449
- let fillAt;
450
- for (const element of bindings.elements) {
451
- const original = (element.propertyName ?? element.name).text;
452
- if (BUILDERS.has(original) && !refusedNames.has(element.name.text)) {
453
- fillAt ??= kept.length;
454
- continue;
455
- }
456
- if (RETIRED_TYPES.has(original)) {
457
- importYours.push(`\`${original}\` is gone — a fill is typed \`FillBinding\`, and nothing else from the old builders survives`);
458
- fillAt ??= kept.length;
459
- continue;
460
- }
461
- kept.push(element.getText(sf));
462
- }
463
- if (decl === fillHost && usesFill && !alreadyFill) kept.splice(insertionIndex(kept, fillAt), 0, "fill");
464
- const changed = kept.length !== bindings.elements.length || kept.some((k, i) => k !== bindings.elements[i].getText(sf));
465
- if (!changed) continue;
466
- if (kept.length === 0) {
467
- edits.push({ start: decl.getFullStart(), end: decl.getEnd(), text: "" });
468
- continue;
469
- }
470
- const multiline = bindings.getText(sf).includes("\n");
471
- const indent = lineIndent(sf, bindings.elements[0]?.getStart(sf) ?? bindings.getStart(sf));
472
- const clause = multiline ? `{\n${kept.map((k) => `${indent}${k},`).join("\n")}\n}` : `{ ${kept.join(", ")} }`;
473
- edits.push({ start: bindings.getStart(sf), end: bindings.getEnd(), text: clause });
474
- }
475
- const lastDecl = importDecls.at(-1);
476
- const added = [];
477
- if (usesFill && !alreadyFill && fillHost === undefined) added.push(`\nimport { fill } from "${CONCRETE}";`);
478
- // A file a first run already ported in part (a call it could not see, fixed by hand
479
- // and run again) already imports the hoisted reads.
480
- const importsReads = sf.statements.some(
481
- (s) =>
482
- ts.isImportDeclaration(s) &&
483
- s.importClause?.namedBindings !== undefined &&
484
- ts.isNamedImports(s.importClause.namedBindings) &&
485
- s.importClause.namedBindings.elements.some((e) => e.name.text === READS_CONST),
486
- );
487
- if (usesReads && readsImport !== undefined && !importsReads) added.push(`\nimport { ${READS_CONST} } from "${readsImport}";`);
488
- if (added.length > 0) edits.push({ start: lastDecl.getEnd(), end: lastDecl.getEnd(), text: added.join("") });
489
- }
490
-
491
- if (edits.length === 0 && yours.length === 0 && importYours.length === 0) return null;
492
- edits.sort((a, b) => b.start - a.start);
493
- let out = text;
494
- for (const edit of edits) out = out.slice(0, edit.start) + edit.text + out.slice(edit.end);
495
- return { text: edits.length === 0 ? null : out, yours: [...new Set([...yours, ...importYours])], usesReads };
496
- }
497
-
498
- /** The extensionless relative specifier from `file` to the hoisted reads module. */
499
- function readsSpecifier(root, file) {
500
- const target = join(root, READS_MODULE.replace(/\.ts$/, ""));
501
- let rel = relative(dirname(file), target).split(sep).join("/");
502
- if (!rel.startsWith(".")) rel = `./${rel}`;
503
- return rel;
504
- }
505
-
506
- /** @param {string} root @returns {Promise<{rewritten: string[], notRewritten: {file: string, reason: string}[]}>} */
507
- export default async function fillIsASource(root) {
508
- const rewritten = [];
509
- const notRewritten = [];
510
- const readsFile = join(root, READS_MODULE);
511
- let needsReads = false;
512
- const name = (file) => relative(root, file).split(sep).join("/");
513
-
514
- for (const file of await sourceFiles(root)) {
515
- if (file === readsFile) continue;
516
- const text = await readFile(file, "utf8");
517
- if (![...BUILDERS, ...RETIRED_TYPES].some((b) => text.includes(b)) && !/\bfill\s*:/.test(text)) continue;
518
- const result = rewrite(text, file, readsSpecifier(root, file));
519
- if (result === null) continue;
520
- if (result.text !== null && result.text !== text) {
521
- await writeFile(file, result.text, "utf8");
522
- rewritten.push(name(file));
523
- if (result.usesReads) needsReads = true;
524
- }
525
- for (const reason of result.yours) notRewritten.push({ file: name(file), reason: `by hand: ${reason}` });
526
- }
527
-
528
- if (needsReads && !(await exists(readsFile))) {
529
- await writeFile(readsFile, READS_SOURCE, "utf8");
530
- rewritten.push(READS_MODULE);
531
- }
532
- return { rewritten, notRewritten };
533
- }