@homepages/concrete 9.0.0 → 10.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.
- package/CHANGELOG.md +69 -0
- package/README.md +3 -3
- package/codemods/manifest.json +14 -0
- package/codemods/registry-keys-only.mjs +113 -0
- package/codemods/steps/list-object-form.mjs +2 -3
- package/codemods/steps/registry-key-reads.mjs +276 -0
- package/dist/artifact/playground/client/assets/index-BFNHB7VM.css +1 -0
- package/dist/artifact/playground/client/assets/index-Div1yo6s.js +1259 -0
- package/dist/artifact/playground/client/index.html +2 -2
- package/dist/artifact/playground/host.mjs +42 -42
- package/dist/cli/build/artifact.js +2 -1
- package/dist/cli/build/fixtures.js +2 -1
- package/dist/cli/check/render/inputs.js +3 -3
- package/dist/cli/check/stages/sections.js +5 -6
- package/dist/cli/check/stages/workspace.js +2 -0
- package/dist/cli/check/template-key.js +16 -0
- package/dist/cli/dev/workspace-reader.js +9 -2
- package/dist/fixtures/media-store.js +3 -3
- package/dist/fixtures/resolve.js +28 -23
- package/dist/fixtures/synthesize-empties.js +3 -1
- package/dist/fixtures.d.ts +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/packages/external/concrete/package.js +1 -1
- package/dist/packages/internal/capture-settle/dist/island-markers.d.ts +1 -1
- package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +15 -27
- package/dist/packages/internal/fill-bake/dist/compute-reads.js +12 -12
- package/dist/packages/internal/fill-bake/dist/derive-source.js +7 -14
- package/dist/packages/internal/fill-bake/dist/index.js +4 -3
- package/dist/packages/internal/fill-bake/dist/item-merge.js +36 -16
- package/dist/packages/internal/fill-bake/dist/item-overrides.js +1 -28
- package/dist/packages/internal/fill-bake/dist/linked-merge.js +5 -7
- package/dist/packages/internal/fill-bake/dist/list-grammar.js +11 -34
- package/dist/packages/internal/fill-bake/dist/stored-row-reader.js +1 -0
- package/dist/packages/internal/fill-vocabulary/dist/resolved-decision.js +12 -39
- package/dist/packages/internal/fill-vocabulary/dist/verbs.js +2 -17
- package/dist/packages/internal/media-resolution/dist/document.js +16 -15
- package/dist/packages/internal/media-resolution/dist/image.js +38 -94
- package/dist/packages/internal/media-resolution/dist/index.js +1 -1
- package/dist/packages/internal/media-resolution/dist/list.js +12 -12
- package/dist/packages/internal/media-resolution/dist/media.js +17 -16
- package/dist/packages/internal/media-resolution/dist/records.js +4 -2
- package/dist/packages/internal/media-resolution/dist/slot.js +9 -6
- package/dist/packages/internal/media-resolution/dist/tour.js +12 -11
- package/dist/packages/internal/media-resolution/dist/video.js +16 -16
- package/dist/packages/internal/property-facts/dist/registry-facts.js +10 -2
- package/dist/packages/internal/section-contracts/dist/catalog.js +2 -10
- package/dist/packages/internal/section-contracts/dist/directly-linked-list-contract.js +5 -12
- package/dist/packages/internal/section-contracts/dist/fill-spec-view.js +1 -5
- package/dist/packages/internal/section-contracts/dist/fill-verb-contract.js +7 -5
- package/dist/packages/internal/section-contracts/dist/grammar-scope.js +1 -1
- package/dist/packages/internal/section-contracts/dist/index.js +0 -2
- package/dist/packages/internal/section-contracts/dist/list-fill-contract.js +0 -29
- package/dist/packages/internal/section-contracts/dist/list-scalar-contract.js +2 -16
- package/dist/packages/internal/section-contracts/dist/nested-slot-contract.js +6 -6
- package/dist/packages/internal/section-contracts/dist/object-contract.js +4 -2
- package/dist/packages/internal/section-contracts/dist/poi-curation-contract.js +6 -2
- package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +1 -15
- package/dist/packages/internal/section-contracts/dist/row-rule-contract.js +6 -7
- package/dist/packages/internal/section-contracts/dist/row-source-contract.js +7 -8
- package/dist/packages/internal/section-contracts/dist/runners.js +5 -17
- package/dist/packages/internal/section-contracts/dist/select-contract.js +7 -1
- package/dist/packages/internal/section-contracts/dist/source-contract.js +20 -79
- package/dist/packages/internal/section-contracts/dist/sources-contract.js +1 -1
- package/dist/packages/internal/section-contracts/dist/table-member.js +5 -8
- package/dist/packages/internal/section-contracts/dist/writer-reads-fact-contract.js +5 -10
- package/dist/packages/internal/source-resolution/dist/index.js +21 -189
- package/dist/packages/internal/template-artifact/dist/index.js +2 -2
- package/dist/packages/internal/template-artifact/dist/layout.js +3 -1
- package/dist/packages/internal/template-artifact/dist/verify.js +32 -16
- package/dist/packages/internal/template-contracts/dist/content-pick.js +24 -1
- package/dist/packages/internal/template-contracts/dist/decision-fills.js +2 -6
- package/dist/packages/internal/template-contracts/dist/document-value.d.ts +2 -2
- package/dist/packages/internal/template-contracts/dist/fact-keys.d.ts +3 -2
- package/dist/packages/internal/template-contracts/dist/fact-keys.js +19 -43
- package/dist/packages/internal/template-contracts/dist/fact-registry.d.ts +24 -3
- package/dist/packages/internal/template-contracts/dist/fact-registry.js +14 -7
- package/dist/packages/internal/template-contracts/dist/fill-builders.d.ts +1 -1
- package/dist/packages/internal/template-contracts/dist/fill-spec-schema.js +3 -68
- package/dist/packages/internal/template-contracts/dist/fill-spec.js +7 -6
- package/dist/packages/internal/template-contracts/dist/list-editing.js +0 -1
- package/dist/packages/internal/template-contracts/dist/list.d.ts +1 -1
- package/dist/packages/internal/template-contracts/dist/list.js +7 -15
- package/dist/packages/internal/template-contracts/dist/media-candidates.js +1 -1
- package/dist/packages/internal/template-contracts/dist/mirror-kind.js +2 -2
- package/dist/packages/internal/template-contracts/dist/object.js +3 -2
- package/dist/packages/internal/template-contracts/dist/primitive-descriptors.js +2 -2
- package/dist/packages/internal/template-contracts/dist/process-builders.d.ts +2 -2
- package/dist/packages/internal/template-contracts/dist/read-graph.js +14 -51
- package/dist/packages/internal/template-contracts/dist/ref-locate.js +15 -27
- package/dist/packages/internal/template-contracts/dist/registry-facts.d.ts +3 -1
- package/dist/packages/internal/template-contracts/dist/registry-facts.js +13 -24
- package/dist/packages/internal/template-contracts/dist/registry-shape.d.ts +20 -4
- package/dist/packages/internal/template-contracts/dist/registry-shape.js +69 -11
- package/dist/packages/internal/template-contracts/dist/row-planners.js +1 -1
- package/dist/packages/internal/template-contracts/dist/row-ref.d.ts +5 -14
- package/dist/packages/internal/template-contracts/dist/row-ref.js +7 -23
- package/dist/packages/internal/template-contracts/dist/row-sources.js +6 -16
- package/dist/packages/internal/template-contracts/dist/row.d.ts +1 -1
- package/dist/packages/internal/template-contracts/dist/row.js +6 -7
- package/dist/packages/internal/template-contracts/dist/runtime-values.d.ts +5 -20
- package/dist/packages/internal/template-contracts/dist/section-schema-types.d.ts +1 -0
- package/dist/packages/internal/template-contracts/dist/slot-builders.d.ts +29 -37
- package/dist/packages/internal/template-contracts/dist/slot-builders.js +4 -7
- package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +2 -733
- package/dist/packages/internal/template-contracts/dist/slot-catalog.js +2 -502
- package/dist/packages/internal/template-contracts/dist/slot-overrides.js +4 -1
- package/dist/packages/internal/template-contracts/dist/slot-ref.d.ts +4 -4
- package/dist/packages/internal/template-contracts/dist/slot-types.js +1 -2
- package/dist/packages/internal/template-contracts/dist/slot-value.d.ts +9 -10
- package/dist/packages/internal/template-contracts/dist/table-members.d.ts +5 -12
- package/dist/packages/internal/template-contracts/dist/table-members.js +7 -37
- package/dist/packages/internal/template-contracts/dist/tour-value.d.ts +2 -2
- package/dist/primitives/Image.d.ts +3 -3
- package/dist/primitives/slot-bindings.js +2 -2
- package/dist/primitives/slot-download.d.ts +1 -1
- package/dist/primitives/slot-media.d.ts +1 -1
- package/dist/rules/registry.js +6 -0
- package/dist/schema/fact.d.ts +19 -52
- package/dist/schema/fact.js +6 -25
- package/dist/schema/facts-view.d.ts +1 -2
- package/dist/schema/property-facts.d.ts +1 -62
- package/dist/schema/section-schema.d.ts +2 -2
- package/dist/schema/section-schema.js +1 -1
- package/dist/section/section.d.ts +2 -2
- package/guide/reference/cli/INDEX.md +2 -2
- package/guide/reference/cli/build.md +1 -1
- package/guide/reference/cli/check.md +1 -1
- package/guide/reference/cli/dev.md +1 -1
- package/guide/reference/cli/property-add.md +1 -1
- package/guide/reference/cli/property-list.md +1 -1
- package/guide/reference/cli/publish.md +1 -1
- package/guide/reference/cli/upgrade.md +1 -1
- package/guide/reference/rules/INDEX.md +4 -5
- package/package.json +1 -1
- package/dist/artifact/playground/client/assets/index-BUmdDDX5.js +0 -1259
- package/dist/artifact/playground/client/assets/index-DDOcM0zA.css +0 -1
- package/dist/packages/internal/fill-vocabulary/dist/row-reads.js +0 -15
- package/dist/packages/internal/section-contracts/dist/group-contract.js +0 -19
- package/dist/packages/internal/section-contracts/dist/option-source-contract.js +0 -22
- package/dist/packages/internal/template-contracts/dist/comparable-address.js +0 -19
- package/dist/packages/internal/template-contracts/dist/facts-view.d.ts +0 -62
- package/dist/packages/internal/template-contracts/dist/legacy-facts.js +0 -167
- package/dist/packages/internal/template-contracts/dist/registry-aliases.js +0 -77
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,74 @@
|
|
|
1
1
|
# @homepages/concrete
|
|
2
2
|
|
|
3
|
+
## 10.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 1851726: Manual: delete any read of an `ImageValue`'s `rect` or `ar`. A resolved image no longer carries either; a section reads `url`, `alt`, `mobile` and `responsive`, as it always should have.
|
|
8
|
+
|
|
9
|
+
A content document names a slot's media in one of two shapes, each meaning one thing: the slot's own copy `{ file, picked, crop, mobile: { crop }, alt, name, renditions }`, its `crop` a `{ x, y, width, height }` box over the original, or a reference `{ media }` to one of the property's items, beside the context its holder reads (a logo's `mask`, a floor plan's `floor_label`). A fixture's built content doc stores its media as `{ media }` references, the dev playground stores an edit as the slot's copy, and the resolvers read only these two shapes: a value still spelled `{ asset_id }`, or a crop stored as `rect`, names no media. Authored fixtures need no change; rebuild a template to publish it on this version.
|
|
10
|
+
|
|
11
|
+
- 6b4d431: Manual: a section reading `floor_label` off a floor plan's image value reads the plan's floor through a row declared from the unit's floor plans instead (`const plan = row({ label: "Plan", from: unit.floor_plans, source: el })`, then `plan.floor`); `ImageValue` no longer carries it. A `source:` typed as `{ kind: "home", key: "<flat name>" }` by hand is no longer a `SlotSource`: bind the fact through `fact.property.*`.
|
|
12
|
+
|
|
13
|
+
A fact is named by its registry key alone. A section whose slot, read or pick names a fact or a table by a flat name with no home (`description`, `beds`, `units`) fails `concrete check` as an unknown fact, and a row's `from` must name a table by its registry key (`fact.property.units`).
|
|
14
|
+
|
|
15
|
+
A select bound to a fact offers the choices the fact declares: `select({ source: fact.property.listing_intent })` offers "For sale" and "For rent", each with its icon and description, in the dev playground as on the platform. The `concrete/contract/option-source` rule folds into `concrete/contract/select`, which refuses a select naming its choices in two places or none, and one bound to a fact that declares no choices.
|
|
16
|
+
|
|
17
|
+
- 78cf304: Manual: after `concrete upgrade`, finish each read of `fact.contact.address` it reports (the contact row answers an address value, not one line of text), and fix each `compute()` the typecheck names over an address part, which reads `null` where its flat spelling read `""`. Then name what the removed types named: an address as `AddressValue`, a comparable a `compute()` reads as `FactsComparable`, and a `Narrative` as the text `fact.property.description` reads.
|
|
18
|
+
|
|
19
|
+
A section reads a property's facts by their registry keys alone: `fact` is the one branch `fact.property`, spelled as the fact registry declares it. The flat spellings no longer exist, so a section reading one fails to typecheck, and the `sections/legacy-fact-key` hint is gone with them. `concrete upgrade` rewrites each:
|
|
20
|
+
|
|
21
|
+
- `fact.description` becomes `fact.property.description`.
|
|
22
|
+
- A contact's or a unit's member, `fact.contact.<member>` or `fact.unit.<member>`, is read through a locked row of its table, declared once per section (`const contact = row({ label: "Contact", from: fact.property.contacts, locked: true })`, then `contact.phone`).
|
|
23
|
+
- An address part is read off the address: `fact.property.address_street` becomes `fact.property.address.street`, and likewise `address_unit`, `address_city`, `address_state` and `address_postal`; `fact.property.latitude` and `fact.property.longitude` become `fact.property.address.latitude` and `.longitude`.
|
|
24
|
+
|
|
25
|
+
Four exported types are removed, since nothing reads the values they describe: `FactsAddress` (`fact.property.address` reads as `AddressValue | null`), `ComparableRow` (a `compute()` over `fact.property.comparables` receives `FactsComparable` rows), `Narrative` (a `compute()` reads `fact.property.description` as its text) and `DirectFactRef` (a fact ref is typed by its registry key; a scalar fact's is a `RegistryFactRef`).
|
|
26
|
+
|
|
27
|
+
In `concrete dev`, a floor plan in the media picker is an image tile like any other photo, as on the platform.
|
|
28
|
+
|
|
29
|
+
### Minor Changes
|
|
30
|
+
|
|
31
|
+
- 64aec58: `concrete check` hints at a section reading `fact.description`, `fact.contact.<member>` or `fact.unit.<member>` (`sections/legacy-fact-key`): flat spellings a later major removes. Read the description as `fact.property.description`, and a contact's or a unit's member through a locked row of its table, declared as a slot: `const contact = row({ label: "Contact", from: fact.property.contacts, locked: true })`, then `contact.phone`. The hint never fails `check`. A new codemod step rewrites a workspace in one pass: import `codemods/steps/registry-key-reads.mjs` from the installed package and call its default export with the workspace root. It hands back each read of `fact.contact.address` it rewrote, since the row answers an address value rather than one line of text.
|
|
32
|
+
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- 9177b60: Internal platform bookkeeping the package carries inline: the artifact verifier can hold a file under `assets/` or `captures/` by its SHA-256 rather than its bytes, so the platform's publish no longer keeps an artifact's media in memory. `concrete build` verifies its output exactly as before; nothing a template declares, builds or publishes changes.
|
|
36
|
+
- 7b7ae6e: In `concrete dev`, a sidebar edit now settles every compute that reads the edited slot, as the platform does after a user's edit: a display variant or visibility computed from a slot follows the edit (a locked variant included), and the canvas and the section's card follow the new case. A compute reading a sibling slot or another section's slot follows it too, and a computed slot you edited keeps your value.
|
|
37
|
+
- 691327d: The media vocabulary the framework inlines follows the platform's facts API: a home image's crop and an upload's name are fact writes at the place's `crop` and the media's `name`, and the list-noun helpers the slot editors title rows with ("Unit 3") live in the shared registry contracts. Nothing a template author writes changes, and the dev playground behaves as before.
|
|
38
|
+
- fb4d1c0: `concrete build` now writes each fixture's settled doc into the artifact (`fixtures/<id>/settled-doc.json`), so a published template's hosted playground settles a sidebar edit as `concrete dev` does: a display variant, visibility or compute reading the edited slot follows the edit, and the canvas and the section's card follow the new case. An artifact built without the file still publishes; its hosted playground lays an edit over the fixture as before.
|
|
39
|
+
- d7eade8: A content image value is read in its two shapes alone: its cut is its `crop` rendition, never a baked `crop_key`, and a value naming no media (a bare `{ url, alt }`) resolves as an empty image rather than serving its URL. The dev playground's media library answers an upload or a pasted link with the new media's `{ id }`.
|
|
40
|
+
- 974d09a: Internal platform bookkeeping the package carries inline: the job-kind table names seventeen kinds, two of them runs over a whole deliverable, and a status comment names the read it describes. Nothing a template declares, reads or renders changes.
|
|
41
|
+
- 2fdeb47: Internal platform bookkeeping the package carries inline: the job-kind table names fifteen kinds with a lane and a tier each, and a fact registry refuses a fill a home cannot run. Nothing a template declares, reads or renders changes.
|
|
42
|
+
- d5bdfff: The bundled slot vocabulary no longer carries the retired flat fact catalog that nothing in the framework read any more. Authoring is unchanged: every fact is still named by its registry key through `fact.property.*`.
|
|
43
|
+
- ac3181a: In the dev playground's sidebar, a list item's field that declares `when` shows only in the cases it names, at any list depth, and a case switch re-filters it at once. A hidden field's stored value is kept through every edit, add and reorder.
|
|
44
|
+
- a6cb2f9: The sidebar's list editors report a list's order to their host as the user's while a drag leaves it out of its source's order. The dev playground keeps no override markers, so it behaves as before.
|
|
45
|
+
- 50e81d4: The word _asset_ leaves the media vocabulary the framework inlines. The slot editors in the dev playground name an upload's answer `media_id` (was `asset_id`) and call the owned-media routes `…/facts/media/*` and `…/content/media/*`; the playground's own dev host answers in that shape. `concrete check`'s fill-spec messages say media where they said asset ("a write composes, it does not birth media"). Nothing a template author writes changes: author and static assets keep their name, and a template reads none of this wire.
|
|
46
|
+
- 239ab8a: The sidebar's list editors compare a list-valued item field (a unit's floor plans) to its source element by element and field by field, so a reorder or an edit inside it reports the field as the user's to the host. The dev playground keeps no override markers, so it behaves as before.
|
|
47
|
+
- 208ae19: Internal: the platform's property list and detail responses carry the property's facts in place of copied address, pin, listing-intent and contact columns. No authoring or CLI behavior changes.
|
|
48
|
+
- 56b97ee: In the dev playground sidebar, the places search's results now draw over their card's edge instead of being cut off by it, and every sidebar dropdown stays within the sidebar's scroll area, opening upward when the room below is short.
|
|
49
|
+
- 028de23: A section slot's own document reads its name from the slot's content value, so a renamed document shows the name it was given wherever the slot renders. A fact holding media stores it in the place that holds it: an owning value `{ id, file, crop, name, renditions }`, or a reference `{ media }` where the declaration picks.
|
|
50
|
+
- 8d04a2d: Internal platform bookkeeping the package carries inline: the platform's stored fact values are now encoded in one place outside the facts schema module the package inlines, so two unused helpers leave it. Nothing a template declares, builds, checks or publishes changes.
|
|
51
|
+
- c2d0ccb: A table's name, home and membership bounds are read off the fact registry's list declarations rather than a hand-kept list. One visible effect: a list sourced by `fact.property.comparables` now inherits the registry's `max: 50` when it declares none, as a list of contacts already inherits `min: 1` and `max: 12`; an authored `max` on it must be lower than 50. Nothing else a template declares, builds or publishes changes.
|
|
52
|
+
- 81e1622: Internal platform bookkeeping the package carries inline: the test helpers that build a facts document now take it in the document's own spelling (owning values, `{ media }` references and a `files` map) instead of translating a retired per-record spelling. Nothing a template declares, builds or publishes changes.
|
|
53
|
+
- 5ca2be5: Internal: the platform's editor writes a section's "Update everywhere" changes as one all-or-nothing batch, and the separate content-media adopt request goes. No authoring or CLI behavior changes.
|
|
54
|
+
|
|
55
|
+
## 9.1.0
|
|
56
|
+
|
|
57
|
+
### Minor Changes
|
|
58
|
+
|
|
59
|
+
- 7e9064e: `concrete check` refuses a template whose `key` is not its `name` in lowercase kebab-case (`Block Website` → `block-website`), under the new rule `workspace/key-not-name`. `concrete dev` and `concrete build` do not grade it, so a template midway through a rename keeps running. A published template's key is its identity: renaming one publishes a second template, so pick a name that spells the published key, or move the stored key before publishing under the new one.
|
|
60
|
+
|
|
61
|
+
### Patch Changes
|
|
62
|
+
|
|
63
|
+
- 72c366c: A collapsed card in the dev playground's sidebar is inert: Tab passes over its fields, and text pasted or filled into a field now saves whole up to its cap instead of being cut short.
|
|
64
|
+
- 31d8f75: The comparables write's brief counts a property as a comparable only where an upload compares it with the subject, and reads the subject as the building with every unit the uploads market in it, so a building's own unit listing sheets no longer come back as its comparables.
|
|
65
|
+
- 57af6dd: The README's and `section()`'s example binds the address's typed members (`fact.property.address.street`, `fact.property.address.city`) instead of the flat `address_street` / `address_city` aliases.
|
|
66
|
+
- c8fccc6: Concrete reads only what a 9.0.0 build writes. A list item's identity is its `id` (`ItemIdentity` is `{ id }`), so a fixture or binding no longer answers a unit's `unit_id`. A stored media value names its media by `asset_id`. `check` refuses the shapes only an earlier build stored: a list declaring its item as `fields`, a slot's `writeback` key, an object label or a process given as a string, a row with no `from`, the flat fill spelling, a decision or item field with no `fills`, a `count`, the verb `curate`, a media `of` naming one list as a string, a row pick's `of` as one ref, and a row member read with no `slot`. The `group` contract rule is gone with section `groups`, which no 9.0.0 section declares.
|
|
67
|
+
- 0efd102: A place rendition's `over` may carry the `version` of the pass that cut it (the cut-out's), and a fact document's media values keep it when they are read.
|
|
68
|
+
- c514a08: Internal: the reader that resolves a row slot's member off a section's stored rows is now shared by the fill and the editor. Fixtures resolve as before.
|
|
69
|
+
- 6754822: A unit's or a commercial space's `amenities` are what sets it apart from the others in its building: a feature the uploads state for it and not for them. A feature printed for two of them or for the building is the building's and lands on none, however a sheet praises it, so a building's shared deck, its standard fittings and the rooms every unit has no longer pad each unit's list.
|
|
70
|
+
- 781dbef: The units write's brief says a commercial space is never a dwelling, as the commercial spaces' brief says a dwelling is never one.
|
|
71
|
+
|
|
3
72
|
## 9.0.0
|
|
4
73
|
|
|
5
74
|
### Major Changes
|
package/README.md
CHANGED
|
@@ -84,13 +84,13 @@ export const Hero = section(
|
|
|
84
84
|
headline: text.medium({
|
|
85
85
|
cap: 60,
|
|
86
86
|
label: "Headline",
|
|
87
|
-
source: fill.write({ reads: [fact.description], brief: "A confident one-line headline." }),
|
|
87
|
+
source: fill.write({ reads: [fact.property.description], brief: "A confident one-line headline." }),
|
|
88
88
|
}),
|
|
89
89
|
address: object({
|
|
90
90
|
label: "Property address",
|
|
91
91
|
fields: {
|
|
92
|
-
street: text.short({ source: fact.property.
|
|
93
|
-
city: text.short({ source: fact.property.
|
|
92
|
+
street: text.short({ source: fact.property.address.street, label: "Street" }),
|
|
93
|
+
city: text.short({ source: fact.property.address.city, label: "City" }),
|
|
94
94
|
},
|
|
95
95
|
}),
|
|
96
96
|
},
|
package/codemods/manifest.json
CHANGED
|
@@ -148,6 +148,20 @@
|
|
|
148
148
|
"after `concrete upgrade`, write an `account` for each upload it names whose tags were the only statement of what it is, and settle each entry it left because its `caption` and `description` could not be joined as text or it already states an `account`.",
|
|
149
149
|
"where `concrete upgrade` reports a `compute()` that read `fact.property.property_type`, read `fact.property.units` in its place and decide by the count (`units.length === 1` is a single home); where it reports a slot bound to the property type, its registry key as a string, or a read of `property_type` off a fixture `Property`, remove it."
|
|
150
150
|
]
|
|
151
|
+
},
|
|
152
|
+
"9.1.0": {
|
|
153
|
+
"codemods": [],
|
|
154
|
+
"manual": []
|
|
155
|
+
},
|
|
156
|
+
"10.0.0": {
|
|
157
|
+
"codemods": [
|
|
158
|
+
"registry-keys-only"
|
|
159
|
+
],
|
|
160
|
+
"manual": [
|
|
161
|
+
"delete any read of an `ImageValue`'s `rect` or `ar`. A resolved image no longer carries either; a section reads `url`, `alt`, `mobile` and `responsive`, as it always should have.",
|
|
162
|
+
"a section reading `floor_label` off a floor plan's image value reads the plan's floor through a row declared from the unit's floor plans instead (`const plan = row({ label: \"Plan\", from: unit.floor_plans, source: el })`, then `plan.floor`); `ImageValue` no longer carries it. A `source:` typed as `{ kind: \"home\", key: \"<flat name>\" }` by hand is no longer a `SlotSource`: bind the fact through `fact.property.*`.",
|
|
163
|
+
"after `concrete upgrade`, finish each read of `fact.contact.address` it reports (the contact row answers an address value, not one line of text), and fix each `compute()` the typecheck names over an address part, which reads `null` where its flat spelling read `\"\"`. Then name what the removed types named: an address as `AddressValue`, a comparable a `compute()` reads as `FactsComparable`, and a `Narrative` as the text `fact.property.description` reads."
|
|
164
|
+
]
|
|
151
165
|
}
|
|
152
166
|
}
|
|
153
167
|
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// 10.0.0 — a section reads a property's facts by their registry keys alone.
|
|
2
|
+
//
|
|
3
|
+
// 9.x typed flat spellings beside the registry's: `fact.description`,
|
|
4
|
+
// `fact.contact.<member>` and `fact.unit.<member>` (hinted at by
|
|
5
|
+
// `sections/legacy-fact-key`, with the rewrite shipped as a codemod step), and the
|
|
6
|
+
// address's parts as `fact.property.address_street`, `_unit`, `_city`, `_state`,
|
|
7
|
+
// `_postal`, `fact.property.latitude` and `fact.property.longitude`. This release removes
|
|
8
|
+
// every one, so a section reading one fails to typecheck, and drops the public types
|
|
9
|
+
// nothing reads any more: `FactsAddress`, `ComparableRow`, `Narrative` and
|
|
10
|
+
// `DirectFactRef`.
|
|
11
|
+
//
|
|
12
|
+
// What this codemod does, in one pass over the workspace:
|
|
13
|
+
//
|
|
14
|
+
// - runs the step, `steps/registry-key-reads.mjs`: the description becomes
|
|
15
|
+
// `fact.property.description`, and a contact's or a unit's member is read through a
|
|
16
|
+
// locked row of its table, declared once per section;
|
|
17
|
+
// - then reads each address part off the address, in every `.ts` and `.tsx` that
|
|
18
|
+
// imports `fact` from the package: `fact.property.address_street` becomes
|
|
19
|
+
// `fact.property.address.street`, `fact.property.latitude`
|
|
20
|
+
// `fact.property.address.latitude`, and so on for each part.
|
|
21
|
+
//
|
|
22
|
+
// What it leaves to you is what the step reports, per file, and what no rewrite can
|
|
23
|
+
// make: a part reads `null` where the flat spelling read `""`, so a `compute()` over one
|
|
24
|
+
// may need its body changed, which the typecheck names; and the removed types, named
|
|
25
|
+
// otherwise (an address `AddressValue`, a comparable a `compute()` reads
|
|
26
|
+
// `FactsComparable`).
|
|
27
|
+
|
|
28
|
+
import { readdir, readFile, writeFile } from "node:fs/promises";
|
|
29
|
+
import { join, relative, sep } from "node:path";
|
|
30
|
+
|
|
31
|
+
import ts from "typescript";
|
|
32
|
+
|
|
33
|
+
import registryKeyReads from "./steps/registry-key-reads.mjs";
|
|
34
|
+
|
|
35
|
+
const CONCRETE = "@homepages/concrete";
|
|
36
|
+
|
|
37
|
+
const EXTENSIONS = [".ts", ".tsx"];
|
|
38
|
+
const SKIP_DIRS = new Set(["node_modules", ".concrete", ".git", "dist", "build"]);
|
|
39
|
+
|
|
40
|
+
/** Each flat address spelling and the address part it read. */
|
|
41
|
+
const ADDRESS_PARTS = {
|
|
42
|
+
address_street: "street",
|
|
43
|
+
address_unit: "unit",
|
|
44
|
+
address_city: "city",
|
|
45
|
+
address_state: "state",
|
|
46
|
+
address_postal: "postal",
|
|
47
|
+
latitude: "latitude",
|
|
48
|
+
longitude: "longitude",
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
async function sourceFiles(root) {
|
|
52
|
+
const found = [];
|
|
53
|
+
async function walk(dir) {
|
|
54
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
55
|
+
if (entry.isDirectory()) {
|
|
56
|
+
if (!SKIP_DIRS.has(entry.name)) await walk(join(dir, entry.name));
|
|
57
|
+
} else if (EXTENSIONS.some((ext) => entry.name.endsWith(ext)) && !entry.name.endsWith(".d.ts")) {
|
|
58
|
+
found.push(join(dir, entry.name));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
await walk(root);
|
|
63
|
+
return found.sort();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** `text` with each flat address read respelled as a read of its part, or `null` when it has none. */
|
|
67
|
+
function addressParts(text, file) {
|
|
68
|
+
if (!text.includes(CONCRETE)) return null;
|
|
69
|
+
const sf = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, file.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
70
|
+
let factName;
|
|
71
|
+
for (const statement of sf.statements) {
|
|
72
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier) || statement.moduleSpecifier.text !== CONCRETE) continue;
|
|
73
|
+
const bindings = statement.importClause?.namedBindings;
|
|
74
|
+
if (bindings === undefined || !ts.isNamedImports(bindings)) continue;
|
|
75
|
+
for (const element of bindings.elements) if ((element.propertyName ?? element.name).text === "fact") factName = element.name.text;
|
|
76
|
+
}
|
|
77
|
+
if (factName === undefined) return null;
|
|
78
|
+
|
|
79
|
+
const edits = [];
|
|
80
|
+
const visit = (node) => {
|
|
81
|
+
if (
|
|
82
|
+
ts.isPropertyAccessExpression(node) &&
|
|
83
|
+
Object.hasOwn(ADDRESS_PARTS, node.name.text) &&
|
|
84
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
85
|
+
node.expression.name.text === "property" &&
|
|
86
|
+
ts.isIdentifier(node.expression.expression) &&
|
|
87
|
+
node.expression.expression.text === factName
|
|
88
|
+
) {
|
|
89
|
+
edits.push({ start: node.name.getStart(sf), end: node.name.getEnd(), text: `address.${ADDRESS_PARTS[node.name.text]}` });
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
ts.forEachChild(node, visit);
|
|
93
|
+
};
|
|
94
|
+
visit(sf);
|
|
95
|
+
if (edits.length === 0) return null;
|
|
96
|
+
let out = text;
|
|
97
|
+
for (const edit of edits.sort((a, b) => b.start - a.start)) out = out.slice(0, edit.start) + edit.text + out.slice(edit.end);
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** @param {string} root @returns {Promise<{rewritten: string[], notRewritten: {file: string, reason: string}[]}>} */
|
|
102
|
+
export default async function registryKeysOnly(root) {
|
|
103
|
+
const report = await registryKeyReads(root);
|
|
104
|
+
const rewritten = new Set(report.rewritten);
|
|
105
|
+
for (const path of await sourceFiles(root)) {
|
|
106
|
+
const text = await readFile(path, "utf8");
|
|
107
|
+
const out = addressParts(text, path);
|
|
108
|
+
if (out === null) continue;
|
|
109
|
+
await writeFile(path, out, "utf8");
|
|
110
|
+
rewritten.add(relative(root, path).split(sep).join("/"));
|
|
111
|
+
}
|
|
112
|
+
return { rewritten: [...rewritten].sort(), notRewritten: report.notRewritten };
|
|
113
|
+
}
|
|
@@ -50,11 +50,10 @@ const CONCRETE = "@homepages/concrete";
|
|
|
50
50
|
const EXTENSIONS = [".ts", ".tsx"];
|
|
51
51
|
const SKIP_DIRS = new Set(["node_modules", ".concrete", ".git", "dist", "build"]);
|
|
52
52
|
|
|
53
|
-
// What each collection's row offers, as the catalog's row descriptors
|
|
53
|
+
// What each collection's row offers, as the catalog's row descriptors declared it when
|
|
54
54
|
// this step was written: the member's author name, the storage key a field may still be
|
|
55
55
|
// keyed by, its value, and whether it writes back. A codemod is a snapshot of one
|
|
56
|
-
// migration, so it carries its own copy
|
|
57
|
-
// catalog while the step ships.
|
|
56
|
+
// migration, so it carries its own copy — the descriptors it was taken from are gone.
|
|
58
57
|
export const TABLE_ROWS = {
|
|
59
58
|
units: {
|
|
60
59
|
param: "unit",
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
// A section reads a property's facts by their registry keys: the description as
|
|
2
|
+
// `fact.property.description`, and a contact's or a unit's member through a row of its
|
|
3
|
+
// table. `fact.description`, `fact.contact.<member>` and `fact.unit.<member>` are the
|
|
4
|
+
// flat spellings that came before, which 10.0.0 removes.
|
|
5
|
+
//
|
|
6
|
+
// This is a codemod STEP: a workspace runs it by importing this file by path from the
|
|
7
|
+
// installed package and calling its default export with the workspace root, and the
|
|
8
|
+
// 10.0.0 codemod `registry-keys-only` runs it. It honors the release codemod contract:
|
|
9
|
+
// `(root) => { rewritten, notRewritten }`.
|
|
10
|
+
//
|
|
11
|
+
// What it does, in every `.ts` and `.tsx` under the workspace that imports `fact` from
|
|
12
|
+
// the package:
|
|
13
|
+
//
|
|
14
|
+
// - `fact.description` becomes `fact.property.description`, wherever it is read.
|
|
15
|
+
// - Each section reading `fact.contact.<member>` or `fact.unit.<member>` declares the
|
|
16
|
+
// table's first row once, before the statement that first reads it — `const contact =
|
|
17
|
+
// row({ label: "Contact", from: fact.property.contacts, locked: true })` — as a
|
|
18
|
+
// top-level slot of the section, and reads each member through it: `contact.phone`, in
|
|
19
|
+
// a `source:`, a `compute()`'s `reads` and a fill's `reads` alike. The row is locked,
|
|
20
|
+
// so the section keeps reading the first row, as the flat spelling did; no slot moves
|
|
21
|
+
// or is renamed. The row's slot key is no name the section already uses anywhere, since
|
|
22
|
+
// an item's row field is read by the same spelling (`primary_contact` beside an item's
|
|
23
|
+
// `contact`). A unit's `unit_label` reads the row's `label`. A read at module level
|
|
24
|
+
// belongs to the file's one section.
|
|
25
|
+
// - Imports `row` where a rewrite uses it.
|
|
26
|
+
//
|
|
27
|
+
// A second run finds nothing left to rewrite.
|
|
28
|
+
//
|
|
29
|
+
// What it hands back, by line: a read of `fact.contact.address`, which the row answers
|
|
30
|
+
// with an address value rather than one line of text, rewritten for you to finish; and,
|
|
31
|
+
// left as written, a read outside any section in a file declaring none or several, a
|
|
32
|
+
// section whose `slots` is not an object literal, and a read of a whole primary row.
|
|
33
|
+
|
|
34
|
+
import { readdir, readFile, writeFile } from "node:fs/promises";
|
|
35
|
+
import { join, relative, sep } from "node:path";
|
|
36
|
+
|
|
37
|
+
import ts from "typescript";
|
|
38
|
+
|
|
39
|
+
const CONCRETE = "@homepages/concrete";
|
|
40
|
+
|
|
41
|
+
const EXTENSIONS = [".ts", ".tsx"];
|
|
42
|
+
const SKIP_DIRS = new Set(["node_modules", ".concrete", ".git", "dist", "build"]);
|
|
43
|
+
|
|
44
|
+
/** Each flat container and the table whose first row it read. */
|
|
45
|
+
const TABLES = { contact: "contacts", unit: "units" };
|
|
46
|
+
|
|
47
|
+
/** A flat member the table's row names otherwise. */
|
|
48
|
+
const RENAMED = { unit: { unit_label: "label" } };
|
|
49
|
+
|
|
50
|
+
async function sourceFiles(root) {
|
|
51
|
+
const found = [];
|
|
52
|
+
async function walk(dir) {
|
|
53
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
54
|
+
if (entry.isDirectory()) {
|
|
55
|
+
if (!SKIP_DIRS.has(entry.name)) await walk(join(dir, entry.name));
|
|
56
|
+
} else if (EXTENSIONS.some((ext) => entry.name.endsWith(ext)) && !entry.name.endsWith(".d.ts")) {
|
|
57
|
+
found.push(join(dir, entry.name));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
await walk(root);
|
|
62
|
+
return found.sort();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function lineOf(sf, node) {
|
|
66
|
+
return sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function lineIndent(text, pos) {
|
|
70
|
+
const start = text.lastIndexOf("\n", pos - 1) + 1;
|
|
71
|
+
return /^[ \t]*/.exec(text.slice(start, pos))[0];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function propertyKey(property) {
|
|
75
|
+
if (ts.isShorthandPropertyAssignment(property)) return property.name.text;
|
|
76
|
+
if (!ts.isPropertyAssignment(property)) return undefined;
|
|
77
|
+
const { name } = property;
|
|
78
|
+
return ts.isIdentifier(name) || ts.isStringLiteral(name) ? name.text : undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Every name the file declares or imports, in any scope — a new const must shadow none. */
|
|
82
|
+
function declaredNames(sf) {
|
|
83
|
+
const names = new Set();
|
|
84
|
+
const visit = (node) => {
|
|
85
|
+
if ((ts.isVariableDeclaration(node) || ts.isParameter(node) || ts.isBindingElement(node)) && ts.isIdentifier(node.name)) names.add(node.name.text);
|
|
86
|
+
if ((ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node)) && node.name !== undefined) names.add(node.name.text);
|
|
87
|
+
if (ts.isImportSpecifier(node) || ts.isImportClause(node) || ts.isNamespaceImport(node)) if (node.name !== undefined) names.add(node.name.text);
|
|
88
|
+
ts.forEachChild(node, visit);
|
|
89
|
+
};
|
|
90
|
+
visit(sf);
|
|
91
|
+
return names;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const capitalized = (word) => word.charAt(0).toUpperCase() + word.slice(1);
|
|
95
|
+
|
|
96
|
+
/** Text replacements that never overlap, applied last to first. */
|
|
97
|
+
function applyEdits(text, edits) {
|
|
98
|
+
let out = text;
|
|
99
|
+
for (const e of [...edits].sort((a, b) => b.start - a.start || b.end - a.end)) out = out.slice(0, e.start) + e.text + out.slice(e.end);
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function rewrite(text, file) {
|
|
104
|
+
if (!text.includes(CONCRETE)) return null;
|
|
105
|
+
const sf = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, file.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
106
|
+
|
|
107
|
+
let host;
|
|
108
|
+
const imported = new Map();
|
|
109
|
+
for (const statement of sf.statements) {
|
|
110
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) continue;
|
|
111
|
+
if (statement.moduleSpecifier.text !== CONCRETE) continue;
|
|
112
|
+
const bindings = statement.importClause?.namedBindings;
|
|
113
|
+
if (bindings === undefined || !ts.isNamedImports(bindings)) continue;
|
|
114
|
+
if (!statement.importClause.isTypeOnly && host === undefined) host = statement;
|
|
115
|
+
for (const element of bindings.elements) imported.set((element.propertyName ?? element.name).text, element.name.text);
|
|
116
|
+
}
|
|
117
|
+
const factName = imported.get("fact");
|
|
118
|
+
if (factName === undefined) return null;
|
|
119
|
+
|
|
120
|
+
// `fact.<name>` — the flat reads and nothing else off the namespace.
|
|
121
|
+
const isFactAccess = (node, name) =>
|
|
122
|
+
ts.isPropertyAccessExpression(node) && node.name.text === name && ts.isIdentifier(node.expression) && node.expression.text === factName;
|
|
123
|
+
|
|
124
|
+
const edits = [];
|
|
125
|
+
const manual = [];
|
|
126
|
+
const refused = [];
|
|
127
|
+
const rowReads = [];
|
|
128
|
+
const visit = (node) => {
|
|
129
|
+
if (isFactAccess(node, "description")) {
|
|
130
|
+
edits.push({ start: node.getStart(sf), end: node.getEnd(), text: `${factName}.property.description` });
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const container = Object.keys(TABLES).find((name) => isFactAccess(node, name));
|
|
134
|
+
if (container !== undefined) {
|
|
135
|
+
if (ts.isPropertyAccessExpression(node.parent) && node.parent.expression === node) {
|
|
136
|
+
rowReads.push({ container, read: node.parent });
|
|
137
|
+
} else {
|
|
138
|
+
refused.push(`\`${node.getText(sf)}\` at line ${String(lineOf(sf, node))} reads the whole primary ${container} — read its members through \`row({ label, from: ${factName}.property.${TABLES[container]}, locked: true })\``);
|
|
139
|
+
}
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
ts.forEachChild(node, visit);
|
|
143
|
+
};
|
|
144
|
+
visit(sf);
|
|
145
|
+
if (edits.length === 0 && rowReads.length === 0) return { text: null, manual, refused };
|
|
146
|
+
|
|
147
|
+
const sectionName = imported.get("section");
|
|
148
|
+
const sections = [];
|
|
149
|
+
const findSections = (node) => {
|
|
150
|
+
if (ts.isCallExpression(node) && sectionName !== undefined && ts.isIdentifier(node.expression) && node.expression.text === sectionName && node.arguments[0] !== undefined) {
|
|
151
|
+
sections.push(node);
|
|
152
|
+
}
|
|
153
|
+
ts.forEachChild(node, findSections);
|
|
154
|
+
};
|
|
155
|
+
findSections(sf);
|
|
156
|
+
const within = (node, outer) => node.getStart(sf) >= outer.getStart(sf) && node.getEnd() <= outer.getEnd();
|
|
157
|
+
const topStatement = (node) => {
|
|
158
|
+
let at = node;
|
|
159
|
+
while (at.parent !== sf) at = at.parent;
|
|
160
|
+
return at;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// Each read by section and container; a module-level read belongs to the file's one section.
|
|
164
|
+
const bySection = new Map();
|
|
165
|
+
for (const entry of rowReads) {
|
|
166
|
+
let section = sections.find((call) => within(entry.read, call.arguments[0]));
|
|
167
|
+
if (section === undefined) {
|
|
168
|
+
if (sections.length !== 1) {
|
|
169
|
+
refused.push(`\`${entry.read.getText(sf)}\` at line ${String(lineOf(sf, entry.read))} is read outside a section, in a file declaring ${sections.length === 0 ? "none" : "several"} — declare the row in the section that reads it`);
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
section = sections[0];
|
|
173
|
+
}
|
|
174
|
+
const perSection = bySection.get(section) ?? new Map();
|
|
175
|
+
bySection.set(section, perSection);
|
|
176
|
+
const list = perSection.get(entry.container) ?? [];
|
|
177
|
+
list.push(entry.read);
|
|
178
|
+
perSection.set(entry.container, list);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const names = declaredNames(sf);
|
|
182
|
+
const declarationsBefore = new Map();
|
|
183
|
+
let usesRow = false;
|
|
184
|
+
for (const [section, perSection] of bySection) {
|
|
185
|
+
const options = section.arguments[0];
|
|
186
|
+
const slotsProperty = ts.isObjectLiteralExpression(options) ? options.properties.find((p) => propertyKey(p) === "slots") : undefined;
|
|
187
|
+
const slots = slotsProperty !== undefined && ts.isPropertyAssignment(slotsProperty) && ts.isObjectLiteralExpression(slotsProperty.initializer) ? slotsProperty.initializer : undefined;
|
|
188
|
+
if (slots === undefined) {
|
|
189
|
+
for (const container of perSection.keys()) {
|
|
190
|
+
refused.push(`the section at line ${String(lineOf(sf, section))} reads \`${factName}.${container}\`, but its \`slots\` is not an object literal this codemod can read — declare the row by hand`);
|
|
191
|
+
}
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
// A read of a row slot names it by key alone, and an item's row field is read by the same
|
|
195
|
+
// spelling, so the new slot's key is no name the section's declaration or the file
|
|
196
|
+
// already uses anywhere.
|
|
197
|
+
const taken = new Set(names);
|
|
198
|
+
const collectKeys = (node) => {
|
|
199
|
+
if (ts.isPropertyAssignment(node) || ts.isShorthandPropertyAssignment(node)) {
|
|
200
|
+
const key = propertyKey(node);
|
|
201
|
+
if (key !== undefined) taken.add(key);
|
|
202
|
+
}
|
|
203
|
+
ts.forEachChild(node, collectKeys);
|
|
204
|
+
};
|
|
205
|
+
collectKeys(options);
|
|
206
|
+
const entries = [];
|
|
207
|
+
for (const [container, reads] of perSection) {
|
|
208
|
+
const table = TABLES[container];
|
|
209
|
+
let constName = container;
|
|
210
|
+
for (let n = 1; names.has(constName); n += 1) constName = `primary${capitalized(container)}${n === 1 ? "" : String(n)}`;
|
|
211
|
+
names.add(constName);
|
|
212
|
+
let key = container;
|
|
213
|
+
for (let n = 1; taken.has(key); n += 1) key = `primary_${container}${n === 1 ? "" : `_${String(n)}`}`;
|
|
214
|
+
taken.add(key);
|
|
215
|
+
|
|
216
|
+
for (const read of reads) {
|
|
217
|
+
const member = RENAMED[container]?.[read.name.text] ?? read.name.text;
|
|
218
|
+
edits.push({ start: read.getStart(sf), end: read.getEnd(), text: `${constName}.${member}` });
|
|
219
|
+
if (container === "contact" && read.name.text === "address") {
|
|
220
|
+
manual.push(
|
|
221
|
+
`line ${String(lineOf(sf, read))} now reads \`${constName}.address\`, the contact's address value rather than one line of text — bind a text slot reading it as \`address({ label, source: ${constName}.address })\` and print it in \`Slot.Address\`, and handle the value or \`null\` in a \`compute()\``,
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const first = topStatement(reads.reduce((earliest, read) => (read.getStart(sf) < earliest.getStart(sf) ? read : earliest)));
|
|
226
|
+
const statement = first.getStart(sf) < topStatement(section).getStart(sf) ? first : topStatement(section);
|
|
227
|
+
const declarations = declarationsBefore.get(statement) ?? [];
|
|
228
|
+
declarations.push(`const ${constName} = row({ label: ${JSON.stringify(capitalized(container))}, from: ${factName}.property.${table}, locked: true });`);
|
|
229
|
+
declarationsBefore.set(statement, declarations);
|
|
230
|
+
entries.push(key === constName ? constName : `${key}: ${constName}`);
|
|
231
|
+
usesRow = true;
|
|
232
|
+
}
|
|
233
|
+
const firstSlot = slots.properties[0];
|
|
234
|
+
const indent = firstSlot === undefined ? "" : lineIndent(text, firstSlot.getStart(sf));
|
|
235
|
+
// Above the first slot's comments, which stay with it.
|
|
236
|
+
const slotComments = firstSlot === undefined ? [] : (ts.getLeadingCommentRanges(text, firstSlot.getFullStart()) ?? []);
|
|
237
|
+
const at = firstSlot === undefined ? slots.getStart(sf) + 1 : slotComments.length > 0 ? slotComments[0].pos : firstSlot.getStart(sf);
|
|
238
|
+
edits.push({ start: at, end: at, text: entries.map((entry) => `${entry},\n${indent}`).join("") });
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// The rows, each declared once before the statement that first reads it, above its comments.
|
|
242
|
+
for (const [statement, declarations] of declarationsBefore) {
|
|
243
|
+
const comments = ts.getLeadingCommentRanges(text, statement.getFullStart()) ?? [];
|
|
244
|
+
const start = comments.length > 0 ? comments[0].pos : statement.getStart(sf);
|
|
245
|
+
edits.push({ start, end: start, text: `${declarations.join("\n")}\n\n` });
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (usesRow && !imported.has("row")) {
|
|
249
|
+
const bindings = host.importClause.namedBindings;
|
|
250
|
+
const kept = bindings.elements.map((element) => element.getText(sf));
|
|
251
|
+
const all = [...kept, "row"].sort((a, b) => a.replace(/^type\s+/, "").localeCompare(b.replace(/^type\s+/, ""), "en", { sensitivity: "base" }));
|
|
252
|
+
const multiline = bindings.getText(sf).includes("\n");
|
|
253
|
+
const indent = lineIndent(text, bindings.elements[0]?.getStart(sf) ?? bindings.getStart(sf));
|
|
254
|
+
edits.push({ start: bindings.getStart(sf), end: bindings.getEnd(), text: multiline ? `{\n${all.map((k) => `${indent}${k},`).join("\n")}\n}` : `{ ${all.join(", ")} }` });
|
|
255
|
+
}
|
|
256
|
+
return { text: applyEdits(text, edits), manual, refused };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** @param {string} root @returns {Promise<{rewritten: string[], notRewritten: {file: string, reason: string}[]}>} */
|
|
260
|
+
export default async function registryKeyReads(root) {
|
|
261
|
+
const rewritten = [];
|
|
262
|
+
const notRewritten = [];
|
|
263
|
+
const name = (file) => relative(root, file).split(sep).join("/");
|
|
264
|
+
for (const file of await sourceFiles(root)) {
|
|
265
|
+
const text = await readFile(file, "utf8");
|
|
266
|
+
const result = rewrite(text, file);
|
|
267
|
+
if (result === null) continue;
|
|
268
|
+
if (result.text !== null && result.text !== text) {
|
|
269
|
+
await writeFile(file, result.text, "utf8");
|
|
270
|
+
rewritten.push(name(file));
|
|
271
|
+
}
|
|
272
|
+
for (const reason of new Set(result.manual)) notRewritten.push({ file: name(file), reason: `Manual: ${reason}` });
|
|
273
|
+
for (const reason of new Set(result.refused)) notRewritten.push({ file: name(file), reason });
|
|
274
|
+
}
|
|
275
|
+
return { rewritten, notRewritten };
|
|
276
|
+
}
|