@homepages/concrete 7.0.0 → 9.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 +1007 -0
- package/README.md +20 -9
- package/codemods/list-grammar.mjs +923 -0
- package/codemods/manifest.json +66 -0
- package/codemods/process-builders.mjs +198 -0
- package/codemods/slot-object.mjs +1097 -0
- package/codemods/steps/content-object-fields.mjs +324 -0
- package/codemods/steps/list-object-form.mjs +6 -7
- package/codemods/table-rows.mjs +568 -0
- package/codemods/unwrap-object-fields.mjs +310 -0
- package/codemods/viewer-slot-document.mjs +131 -0
- package/codemods/write-property-as-facts-document.mjs +716 -0
- package/codemods/write-the-address-line.mjs +255 -0
- package/codemods/write-the-registry-members.mjs +653 -0
- package/codemods/write-the-select-from.mjs +141 -0
- package/codemods/write-the-sole-from.mjs +369 -0
- package/codemods/write-the-table-from.mjs +267 -0
- package/codemods/write-the-whole-item.mjs +512 -0
- package/codemods/writeback-drop.mjs +168 -0
- package/codemods/written-contact-address.mjs +162 -0
- package/codemods/written-media-category.mjs +227 -0
- package/codemods/written-ref-kinds-name-the-layer.mjs +172 -0
- package/codemods/written-uploads-replace-pool-reads.mjs +454 -0
- package/codemods/written-uploads-sort-into-lists.mjs +405 -0
- package/codemods/written-uploads-stated-in-sorted-lists.mjs +295 -0
- package/codemods/written-video-sources-drop.mjs +144 -0
- package/codemods/written-without-pick-none.mjs +146 -0
- package/codemods/written-without-retired-knowledge.mjs +223 -0
- package/codemods/written-without-the-media-key.mjs +202 -0
- package/codemods/written-without-the-property-type.mjs +249 -0
- package/dist/artifact/playground/client/assets/index-BUmdDDX5.js +1259 -0
- package/dist/artifact/playground/client/assets/index-DDOcM0zA.css +1 -0
- package/dist/artifact/playground/client/index.html +2 -2
- package/dist/artifact/playground/client/island-canvas-host.mjs +1 -1
- package/dist/artifact/playground/host.mjs +61 -27
- package/dist/base.css +58 -1
- package/dist/cli/build/artifact.js +6 -9
- package/dist/cli/build/captures.js +2 -12
- package/dist/cli/build/esbuild.js +1 -25
- package/dist/cli/build/fixtures.js +2 -1
- package/dist/cli/build/icons.js +1 -1
- package/dist/cli/build/static.js +2 -2
- package/dist/cli/capture/capture.js +8 -9
- package/dist/cli/check/analyze.js +8 -1
- package/dist/cli/check/load-outdir.js +47 -0
- package/dist/cli/check/load-workspace.js +4 -4
- package/dist/cli/check/render/html.js +1 -2
- package/dist/cli/check/render/inputs.js +10 -3
- package/dist/cli/check/render/island-frames.js +2 -1
- package/dist/cli/check/render/marker-coverage.js +23 -15
- package/dist/cli/check/report.js +5 -0
- package/dist/cli/check/stages/bundles.js +1 -1
- package/dist/cli/check/stages/relations.js +1 -1
- package/dist/cli/check/stages/render.js +48 -33
- package/dist/cli/check/stages/sections.js +83 -31
- package/dist/cli/commands.js +1 -1
- package/dist/cli/dev/crop.js +1 -1
- package/dist/cli/dev/fixture-ladders.js +96 -0
- package/dist/cli/dev/islands.js +12 -123
- package/dist/cli/dev/listen.js +20 -1
- package/dist/cli/dev/load-template.js +1 -1
- package/dist/cli/dev/server.js +35 -10
- package/dist/cli/dev/vite.js +9 -7
- package/dist/cli/dev/workspace-reader.js +16 -16
- package/dist/cli/media/derive.js +43 -57
- package/dist/cli/media/frame-rung-floor.js +0 -1
- package/dist/cli/property/index.js +1 -6
- package/dist/css/inline.js +1 -22
- package/dist/eslint/rules/no-marker-literal.js +1 -1
- package/dist/fixtures/load.js +16 -7
- package/dist/fixtures/media-plugin.js +17 -12
- package/dist/fixtures/media-store.js +115 -0
- package/dist/fixtures/property.js +345 -126
- package/dist/fixtures/resolve.js +263 -251
- package/dist/fixtures/rows.js +4 -11
- package/dist/fixtures.d.ts +234 -109
- package/dist/index.d.ts +25 -16
- package/dist/index.js +10 -6
- package/dist/islands/marker.js +2 -1
- package/dist/packages/external/concrete/package.js +1 -1
- package/dist/packages/internal/canvas-core/dist/island-host.js +62 -0
- package/dist/packages/internal/canvas-core/dist/island-shields.js +30 -0
- package/dist/packages/internal/capture-settle/dist/index.js +3 -0
- package/dist/packages/internal/capture-settle/dist/island-markers.d.ts +13 -0
- package/dist/packages/internal/capture-settle/dist/island-markers.js +6 -0
- package/dist/packages/internal/capture-settle/dist/settle.js +150 -0
- package/dist/packages/internal/{image-ladder/dist/crop.js → crop-region/dist/index.js} +21 -20
- package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +252 -35
- package/dist/packages/internal/fill-bake/dist/compute-reads.js +365 -4
- package/dist/packages/internal/fill-bake/dist/derive-source.js +35 -21
- package/dist/packages/internal/fill-bake/dist/index.js +8 -3
- package/dist/packages/internal/fill-bake/dist/item-merge.js +119 -0
- package/dist/packages/internal/fill-bake/dist/item-overrides.js +28 -0
- package/dist/packages/internal/fill-bake/dist/linked-merge.js +40 -0
- package/dist/packages/internal/fill-bake/dist/list-grammar.js +175 -0
- package/dist/packages/internal/fill-vocabulary/dist/holder.js +51 -0
- package/dist/packages/internal/fill-vocabulary/dist/resolved-decision.js +390 -0
- package/dist/packages/internal/fill-vocabulary/dist/row-planners.js +1 -23
- package/dist/packages/internal/fill-vocabulary/dist/row-reads.js +1 -1
- package/dist/packages/internal/fill-vocabulary/dist/verbs.js +75 -0
- package/dist/packages/internal/format-geometry/dist/capture.js +11 -147
- package/dist/packages/internal/format-geometry/dist/format.d.ts +8 -2
- package/dist/packages/internal/format-geometry/dist/geometry.js +13 -2
- package/dist/packages/internal/image-ladder/dist/encode.js +27 -14
- package/dist/packages/internal/image-ladder/dist/index.js +3 -3
- package/dist/packages/internal/image-ladder/dist/policy.js +28 -53
- package/dist/packages/internal/island-runtime/dist/capture-holds.js +1 -1
- package/dist/packages/internal/island-runtime/dist/contract.d.ts +3 -12
- package/dist/packages/internal/island-runtime/dist/contract.js +2 -2
- package/dist/packages/internal/island-runtime/dist/index.d.ts +3 -7
- package/dist/packages/internal/island-runtime/dist/index.js +2 -1
- package/dist/packages/internal/island-runtime/dist/viewport-schedule.js +1 -1
- package/dist/packages/internal/media-resolution/dist/crop-key.js +7 -0
- package/dist/packages/internal/media-resolution/dist/document.js +63 -0
- package/dist/packages/internal/media-resolution/dist/image.js +228 -0
- package/dist/packages/internal/media-resolution/dist/index.js +11 -0
- package/dist/packages/internal/media-resolution/dist/list.js +112 -0
- package/dist/packages/internal/media-resolution/dist/media.js +59 -0
- package/dist/packages/internal/media-resolution/dist/records.js +7 -0
- package/dist/packages/internal/media-resolution/dist/slot.js +34 -0
- package/dist/packages/internal/media-resolution/dist/store.js +19 -0
- package/dist/packages/internal/media-resolution/dist/tour.js +59 -0
- package/dist/packages/internal/media-resolution/dist/video.js +93 -0
- package/dist/packages/internal/property-facts/dist/registry-facts.js +244 -0
- package/dist/packages/internal/section-contracts/dist/cap-contract.js +8 -17
- package/dist/packages/internal/section-contracts/dist/catalog.js +35 -27
- package/dist/packages/internal/section-contracts/dist/count-bounds-contract.js +11 -2
- package/dist/packages/internal/section-contracts/dist/directly-linked-list-contract.js +27 -0
- package/dist/packages/internal/section-contracts/dist/fill-options.js +12 -0
- package/dist/packages/internal/section-contracts/dist/fill-spec-view.js +1 -0
- package/dist/packages/internal/section-contracts/dist/fill-verb-contract.js +95 -0
- package/dist/packages/internal/section-contracts/dist/grammar-scope.js +154 -0
- package/dist/packages/internal/section-contracts/dist/index.js +7 -5
- package/dist/packages/internal/section-contracts/dist/list-fill-contract.js +23 -19
- package/dist/packages/internal/section-contracts/dist/list-scalar-contract.js +12 -7
- package/dist/packages/internal/section-contracts/dist/list-source-contract.js +46 -0
- package/dist/packages/internal/section-contracts/dist/nested-slot-contract.js +11 -2
- package/dist/packages/internal/section-contracts/dist/object-contract.js +92 -0
- package/dist/packages/internal/section-contracts/dist/poi-curation-contract.js +5 -5
- package/dist/packages/internal/section-contracts/dist/reads-acyclic-contract.js +63 -0
- package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +7 -4
- package/dist/packages/internal/section-contracts/dist/row-rule-contract.js +83 -0
- package/dist/packages/internal/section-contracts/dist/row-source-contract.js +67 -0
- package/dist/packages/internal/section-contracts/dist/runners.js +77 -33
- package/dist/packages/internal/section-contracts/dist/select-contract.js +0 -8
- package/dist/packages/internal/section-contracts/dist/source-contract.js +120 -66
- package/dist/packages/internal/section-contracts/dist/sources-contract.js +47 -17
- package/dist/packages/internal/section-contracts/dist/table-member.js +16 -0
- package/dist/packages/internal/section-contracts/dist/writer-reads-fact-contract.js +43 -18
- package/dist/packages/internal/source-resolution/dist/index.js +113 -118
- package/dist/packages/internal/static-assets-binding/dist/section-asset-url.js +16 -0
- package/dist/packages/internal/street-address/dist/index.js +72 -0
- package/dist/packages/internal/template-artifact/dist/asset-mime.js +30 -0
- package/dist/packages/internal/template-artifact/dist/layout.js +1 -2
- package/dist/packages/internal/template-artifact/dist/manifest.js +1 -1
- package/dist/packages/internal/template-artifact/dist/verify.js +12 -29
- package/dist/packages/internal/template-contracts/dist/address-value.d.ts +52 -0
- package/dist/packages/internal/template-contracts/dist/address-value.js +90 -0
- package/dist/packages/internal/template-contracts/dist/comparable-address.js +19 -0
- package/dist/{schema → packages/internal/template-contracts/dist}/compute.d.ts +29 -6
- package/dist/{schema → packages/internal/template-contracts/dist}/compute.js +11 -13
- package/dist/packages/internal/template-contracts/dist/content-pick.js +51 -0
- package/dist/packages/internal/template-contracts/dist/decision-fills.js +85 -0
- package/dist/packages/internal/template-contracts/dist/display-overrides.js +7 -0
- package/dist/packages/internal/template-contracts/dist/document-value.d.ts +16 -5
- package/dist/packages/internal/template-contracts/dist/fact-compute.d.ts +24 -0
- package/dist/packages/internal/template-contracts/dist/fact-compute.js +30 -0
- package/dist/packages/internal/template-contracts/dist/fact-keys.d.ts +44 -0
- package/dist/packages/internal/template-contracts/dist/fact-keys.js +88 -0
- package/dist/packages/internal/template-contracts/dist/fact-registry.d.ts +290 -0
- package/dist/packages/internal/template-contracts/dist/fact-registry.js +598 -0
- package/dist/packages/internal/template-contracts/dist/facts-view.d.ts +12 -36
- package/dist/packages/internal/template-contracts/dist/fill-builders.d.ts +157 -0
- package/dist/packages/internal/template-contracts/dist/fill-builders.js +79 -0
- package/dist/packages/internal/template-contracts/dist/fill-declaration.d.ts +14 -0
- package/dist/{schema → packages/internal/template-contracts/dist}/fill-declaration.js +6 -5
- package/dist/packages/internal/template-contracts/dist/fill-spec-schema.js +158 -0
- package/dist/packages/internal/template-contracts/dist/fill-spec.js +291 -0
- package/dist/packages/internal/template-contracts/dist/findable.js +8 -0
- package/dist/packages/internal/template-contracts/dist/floor-presets.js +13 -0
- package/dist/packages/internal/template-contracts/dist/icon-names.d.ts +5 -0
- package/dist/packages/internal/template-contracts/dist/icon-names.js +70 -0
- package/dist/packages/internal/template-contracts/dist/legacy-facts.js +167 -0
- package/dist/packages/internal/template-contracts/dist/list-editing.js +94 -0
- package/dist/packages/internal/template-contracts/dist/list.d.ts +215 -0
- package/dist/packages/internal/template-contracts/dist/list.js +258 -0
- package/dist/packages/internal/template-contracts/dist/markers.d.ts +2 -2
- package/dist/packages/internal/template-contracts/dist/media-candidates.js +38 -0
- package/dist/packages/internal/template-contracts/dist/mirror-kind.js +48 -0
- package/dist/packages/internal/template-contracts/dist/number-display.js +10 -0
- package/dist/packages/internal/template-contracts/dist/object.d.ts +89 -0
- package/dist/packages/internal/template-contracts/dist/object.js +131 -0
- package/dist/packages/internal/template-contracts/dist/poi-row.d.ts +1 -1
- package/dist/packages/internal/template-contracts/dist/primitive-descriptors.d.ts +1 -0
- package/dist/packages/internal/template-contracts/dist/primitive-descriptors.js +162 -0
- package/dist/packages/internal/template-contracts/dist/process-builders.d.ts +77 -0
- package/dist/packages/internal/template-contracts/dist/process-builders.js +73 -0
- package/dist/packages/internal/template-contracts/dist/read-graph.js +250 -0
- package/dist/packages/internal/template-contracts/dist/ref-locate.js +192 -0
- package/dist/packages/internal/template-contracts/dist/registry-aliases.js +77 -0
- package/dist/packages/internal/template-contracts/dist/registry-facts.d.ts +268 -0
- package/dist/packages/internal/template-contracts/dist/registry-facts.js +202 -0
- package/dist/packages/internal/template-contracts/dist/registry-shape.d.ts +41 -0
- package/dist/packages/internal/template-contracts/dist/registry-shape.js +135 -0
- package/dist/packages/internal/template-contracts/dist/resolve-scope.js +103 -0
- package/dist/packages/internal/{image-descriptor/dist/index.d.ts → template-contracts/dist/responsive-image.d.ts} +1 -1
- package/dist/packages/internal/template-contracts/dist/row-planners.js +29 -0
- package/dist/packages/internal/template-contracts/dist/row-ref.d.ts +133 -0
- package/dist/packages/internal/template-contracts/dist/row-ref.js +101 -0
- package/dist/packages/internal/template-contracts/dist/row-sources.js +48 -8
- package/dist/packages/internal/template-contracts/dist/row.d.ts +155 -0
- package/dist/packages/internal/template-contracts/dist/row.js +84 -0
- package/dist/packages/internal/template-contracts/dist/runtime-values.d.ts +97 -0
- package/dist/packages/internal/template-contracts/dist/slot-builders.d.ts +782 -0
- package/dist/packages/internal/template-contracts/dist/slot-builders.js +233 -0
- package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +243 -384
- package/dist/packages/internal/template-contracts/dist/slot-catalog.js +334 -230
- package/dist/packages/internal/template-contracts/dist/slot-overrides.js +21 -0
- package/dist/packages/internal/template-contracts/dist/slot-ref.d.ts +155 -0
- package/dist/packages/internal/template-contracts/dist/slot-ref.js +76 -0
- package/dist/packages/internal/template-contracts/dist/slot-types.d.ts +163 -0
- package/dist/packages/internal/template-contracts/dist/slot-types.js +140 -0
- package/dist/packages/internal/template-contracts/dist/slot-value.d.ts +97 -0
- package/dist/packages/internal/template-contracts/dist/table-members.d.ts +25 -0
- package/dist/packages/internal/template-contracts/dist/table-members.js +90 -0
- package/dist/packages/internal/template-contracts/dist/tour-value.d.ts +5 -5
- package/dist/packages/internal/template-contracts/dist/value-contracts.js +15 -0
- package/dist/packages/internal/template-contracts/dist/video-value.d.ts +2 -2
- package/dist/platform/fs.js +5 -2
- package/dist/playground/canvas-island-host.d.ts +11 -0
- package/dist/playground/canvas-island-host.js +29 -0
- package/dist/playground/canvas-markers.js +14 -0
- package/dist/playground-island-runtime.d.ts +3 -2
- package/dist/playground-island-runtime.js +3 -2
- package/dist/primitives/FrameShell.js +0 -1
- package/dist/primitives/Image.d.ts +5 -4
- package/dist/primitives/Tour.d.ts +1 -1
- package/dist/primitives/Video.d.ts +2 -2
- package/dist/primitives/index.d.ts +2 -3
- package/dist/primitives/picture-sources.js +2 -2
- package/dist/primitives/probe-context.js +2 -12
- package/dist/primitives/slot-address.d.ts +44 -0
- package/dist/primitives/slot-address.js +19 -0
- package/dist/primitives/slot-bindings.d.ts +65 -26
- package/dist/primitives/slot-bindings.js +104 -46
- package/dist/primitives/slot-document.d.ts +23 -18
- package/dist/primitives/slot-document.js +39 -14
- package/dist/primitives/slot-download.d.ts +39 -0
- package/dist/primitives/slot-download.js +39 -0
- package/dist/primitives/slot-list.d.ts +3 -3
- package/dist/primitives/slot-list.js +0 -2
- package/dist/primitives/slot-media.d.ts +24 -5
- package/dist/primitives/slot-media.js +6 -9
- package/dist/primitives/slot-object.d.ts +49 -0
- package/dist/primitives/slot-object.js +20 -0
- package/dist/primitives/slot-scalar.d.ts +27 -2
- package/dist/primitives/slot-scalar.js +50 -7
- package/dist/primitives/slot.d.ts +13 -6
- package/dist/primitives/slot.js +10 -3
- package/dist/rules/registry.js +19 -30
- package/dist/schema/define-schema.d.ts +4 -8
- package/dist/schema/define-schema.js +178 -79
- package/dist/schema/extract-fill-spec.js +2 -158
- package/dist/schema/fact.d.ts +57 -15
- package/dist/schema/fact.js +42 -7
- package/dist/schema/facts-view.d.ts +14 -0
- package/dist/schema/format.d.ts +1 -0
- package/dist/schema/format.js +2 -1
- package/dist/schema/manifest.js +24 -0
- package/dist/schema/property-facts.d.ts +8 -11
- package/dist/schema/section-props.d.ts +2 -66
- package/dist/schema/section-schema.d.ts +8 -11
- package/dist/schema/section-schema.js +27 -10
- package/dist/section/declare.d.ts +18 -7
- package/dist/section/declare.js +18 -5
- package/dist/section/materialize.js +3 -8
- package/dist/section/section.d.ts +12 -8
- package/dist/section/section.js +1 -1
- package/dist/template/logic-shim.d.ts +14 -7
- package/dist/template/logic-shim.js +14 -7
- package/dist/template/materialize.js +17 -18
- package/dist/template/mirror-types.js +30 -31
- package/dist/template/section-reads.js +85 -9
- 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 +2 -2
- package/guide/reference/cli/publish.md +1 -1
- package/guide/reference/cli/upgrade.md +1 -1
- package/guide/reference/rules/INDEX.md +29 -29
- package/package.json +9 -8
- package/dist/artifact/playground/client/assets/index-CckS2ONm.css +0 -1
- package/dist/artifact/playground/client/assets/index-D8eepVr-.js +0 -1101
- package/dist/fixtures/canonical.d.ts +0 -166
- package/dist/fixtures/media.js +0 -163
- package/dist/packages/internal/fill-vocabulary/dist/origination.js +0 -111
- package/dist/packages/internal/format-geometry/dist/index.js +0 -4
- package/dist/packages/internal/property-facts/dist/derive-facts-view.js +0 -10
- package/dist/packages/internal/property-facts/dist/index.js +0 -3
- package/dist/packages/internal/property-facts/dist/property-facts-Cy7-O4p0.js +0 -189
- package/dist/packages/internal/section-contracts/dist/choose-select-contract.js +0 -20
- package/dist/packages/internal/section-contracts/dist/name-title-contract.js +0 -20
- package/dist/packages/internal/section-contracts/dist/pooling-field-contract.js +0 -22
- package/dist/packages/internal/section-contracts/dist/record-collection-contract.js +0 -24
- package/dist/packages/internal/section-contracts/dist/source-filter-contract.js +0 -15
- package/dist/packages/internal/template-contracts/dist/collection-editing.js +0 -22
- package/dist/packages/internal/template-contracts/dist/facts-view.js +0 -111
- package/dist/packages/internal/template-contracts/dist/select-key.js +0 -7
- package/dist/primitives/slot-group.d.ts +0 -40
- package/dist/primitives/slot-group.js +0 -36
- package/dist/schema/extract-used-facts.js +0 -34
- package/dist/schema/fill-builders.d.ts +0 -115
- package/dist/schema/fill-builders.js +0 -25
- package/dist/schema/fill-declaration.d.ts +0 -14
- package/dist/schema/fill-spec.js +0 -89
- package/dist/schema/layout.d.ts +0 -30
- package/dist/schema/layout.js +0 -14
- package/dist/schema/row-fields.js +0 -88
- package/dist/schema/row-ref.d.ts +0 -59
- package/dist/schema/row-ref.js +0 -28
- package/dist/schema/runtime-values.d.ts +0 -71
- package/dist/schema/section-nav.js +0 -14
- package/dist/schema/slot-builders.d.ts +0 -613
- package/dist/schema/slot-builders.js +0 -177
- package/dist/schema/slot-ref.d.ts +0 -79
- package/dist/schema/slot-ref.js +0 -41
- package/dist/schema/slot-types.d.ts +0 -111
- package/dist/schema/slot-types.js +0 -214
- package/dist/section/groups.js +0 -68
|
@@ -0,0 +1,716 @@
|
|
|
1
|
+
// 9.0.0 — a fixture property is written in the shape of the platform's facts document.
|
|
2
|
+
//
|
|
3
|
+
// Before this break a `Property` restated the platform's older facts shape: five pool
|
|
4
|
+
// lists, a `narrative`, `lat`/`lon` beside the address, a unit's `unit_id`, a contact's
|
|
5
|
+
// `avatar` and `website_url`, a comparable's flat `address_*` members, and members the
|
|
6
|
+
// platform derives (an address's `display`, a comp's `status`) stated by hand. A property
|
|
7
|
+
// is now spelled the way a template reads facts: one `uploads` list whose entries say
|
|
8
|
+
// their `kind`, the address holding its pin, a unit's floor plans picked by value, and
|
|
9
|
+
// nothing derived stated.
|
|
10
|
+
//
|
|
11
|
+
// What this codemod does, in every `.ts` and `.tsx` under the workspace that imports
|
|
12
|
+
// `@homepages/concrete/fixtures`, bar `sections/` — a row a section's module builds is
|
|
13
|
+
// the facts that section reads, never a fixture's:
|
|
14
|
+
// - a property: `narrative: { description }` becomes `description`; `lat`/`lon` move
|
|
15
|
+
// into `address` as `latitude`/`longitude`, and the address drops `display` and
|
|
16
|
+
// `street_no_type`; `photos`, `floor_plans`, `videos`, `tours` and `documents` become
|
|
17
|
+
// one `uploads` list, in that order;
|
|
18
|
+
// - an upload entry (a photo, plan, video, tour or document the property lists, or a
|
|
19
|
+
// `const` typed as one): it gains its `kind` (and an image's `category`); a plan drops
|
|
20
|
+
// `unit_assignments`, which the units now say; a document's `notes: ""` becomes `null`;
|
|
21
|
+
// - a unit: `unit_id` → `id`, `unit_label` → `label`, `position` dropped, each floor
|
|
22
|
+
// plan `{ id, floor_label, position }` → `{ image: <the plan's entry>, floor }`;
|
|
23
|
+
// - a contact: `avatar` → `headshot`, `website_url` → `website`, each `*_url` social →
|
|
24
|
+
// its bare name, `primary` dropped with the primary contact moved first;
|
|
25
|
+
// - a comparable: `address_*`, `lat` and `lng` → `address: { street, city, state,
|
|
26
|
+
// postal, latitude, longitude }`; `address` (its display line), `status`,
|
|
27
|
+
// `distance_m` and `price_period` dropped — the platform derives each;
|
|
28
|
+
// - a content entry naming a contact's image: `field: "avatar"` → `field: "headshot"`.
|
|
29
|
+
//
|
|
30
|
+
// What it hands back, by line, with the member-by-member rename table: what it cannot
|
|
31
|
+
// rewrite where it stands — rows built by a helper function, a floor plan a unit names by
|
|
32
|
+
// an id it cannot find an entry for, a property assembled by spreading another, and
|
|
33
|
+
// entries it cannot trace to a declaration.
|
|
34
|
+
|
|
35
|
+
import { readdir, readFile, writeFile } from "node:fs/promises";
|
|
36
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
37
|
+
|
|
38
|
+
import ts from "typescript";
|
|
39
|
+
|
|
40
|
+
const FIXTURES = "@homepages/concrete/fixtures";
|
|
41
|
+
const EXTENSIONS = [".ts", ".tsx"];
|
|
42
|
+
const SKIP_DIRS = new Set(["node_modules", ".concrete", ".git", "dist", "build"]);
|
|
43
|
+
|
|
44
|
+
/** The old pools, in the order the platform lists uploads. */
|
|
45
|
+
const POOLS = ["photos", "floor_plans", "videos", "tours", "documents"];
|
|
46
|
+
/** What each pool's entry states so the uploads list can tell it apart. */
|
|
47
|
+
const KIND_OF = {
|
|
48
|
+
photos: [["kind", '"image"'], ["category", '"photo"']],
|
|
49
|
+
floor_plans: [["kind", '"image"'], ["category", '"floor_plan"']],
|
|
50
|
+
videos: [["kind", '"video"']],
|
|
51
|
+
tours: [["kind", '"tour"']],
|
|
52
|
+
documents: [["kind", '"document"']],
|
|
53
|
+
};
|
|
54
|
+
/** The entry types an author annotates a `const` with, and the pool each belongs to. */
|
|
55
|
+
const ENTRY_TYPES = {
|
|
56
|
+
PhotoEntry: "photos",
|
|
57
|
+
FloorPlanEntry: "floor_plans",
|
|
58
|
+
UploadVideoEntry: "videos",
|
|
59
|
+
LinkVideoEntry: "videos",
|
|
60
|
+
VideoEntry: "videos",
|
|
61
|
+
TourEntry: "tours",
|
|
62
|
+
DocumentEntry: "documents",
|
|
63
|
+
};
|
|
64
|
+
const CONTACT_RENAMES = {
|
|
65
|
+
avatar: "headshot",
|
|
66
|
+
website_url: "website",
|
|
67
|
+
instagram_url: "instagram",
|
|
68
|
+
linkedin_url: "linkedin",
|
|
69
|
+
x_url: "x",
|
|
70
|
+
facebook_url: "facebook",
|
|
71
|
+
};
|
|
72
|
+
/** The members a property states only in its older shape. */
|
|
73
|
+
const OLD_PROPERTY_KEYS = new Set(["narrative", "lat", "lon", ...POOLS]);
|
|
74
|
+
|
|
75
|
+
/** The member-by-member rename table a report hands back, by what it is about. */
|
|
76
|
+
const TABLE = {
|
|
77
|
+
property:
|
|
78
|
+
"a property's `narrative.description` → `description`; `lat`, `lon` → `address.latitude`, `address.longitude`; " +
|
|
79
|
+
"`address.display`, `address.street_no_type` → dropped (derived); `photos`, `floor_plans`, `videos`, `tours`, " +
|
|
80
|
+
'`documents` → one `uploads` list, each entry stating its `kind` ("image", with `category` "photo" or ' +
|
|
81
|
+
'"floor_plan"; "video"; "tour"; "document")',
|
|
82
|
+
unit:
|
|
83
|
+
"a unit's `unit_id` → `id`; `unit_label` → `label`; `position` → dropped (the item's index); " +
|
|
84
|
+
"`floor_plans[].{ id, floor_label, position }` → `floor_plans[].{ image: <the floor plan's entry>, floor }`",
|
|
85
|
+
contact:
|
|
86
|
+
"a contact's `avatar` → `headshot`; `website_url` → `website`; `instagram_url`, `linkedin_url`, `x_url`, " +
|
|
87
|
+
"`facebook_url` → `instagram`, `linkedin`, `x`, `facebook`; `primary` → dropped (the first contact is the primary)",
|
|
88
|
+
comparable:
|
|
89
|
+
"a comparable's `address_street`, `address_city`, `address_state`, `address_postal`, `lat`, `lng` → " +
|
|
90
|
+
"`address: { street, city, state, postal, latitude, longitude }`; `address` (its display line), `status`, " +
|
|
91
|
+
"`distance_m`, `price_period` → dropped (derived)",
|
|
92
|
+
entry: 'an upload entry states its `kind` (and an image its `category`); a floor plan drops `unit_assignments`; a document with no notes states `notes: null`',
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
async function sourceFiles(root) {
|
|
96
|
+
const found = [];
|
|
97
|
+
async function walk(dir) {
|
|
98
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
99
|
+
if (entry.isDirectory()) {
|
|
100
|
+
if (dir === root && entry.name === "sections") continue;
|
|
101
|
+
if (!SKIP_DIRS.has(entry.name)) await walk(join(dir, entry.name));
|
|
102
|
+
} else if (EXTENSIONS.some((ext) => entry.name.endsWith(ext)) && !entry.name.endsWith(".d.ts")) {
|
|
103
|
+
found.push(join(dir, entry.name));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
await walk(root);
|
|
108
|
+
return found.sort();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function parse(file, text) {
|
|
112
|
+
return ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, file.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Whether a statement imports the fixture declarations. */
|
|
116
|
+
function isFixturesImport(statement) {
|
|
117
|
+
return ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier) && statement.moduleSpecifier.text === FIXTURES;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Whether a module imports the fixture declarations — the files a property or a fixture lives in. */
|
|
121
|
+
function importsFixtures(source) {
|
|
122
|
+
return source.statements.some(isFixturesImport);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Non-overlapping text replacements, applied back to front. */
|
|
126
|
+
class Edits {
|
|
127
|
+
constructor(name) {
|
|
128
|
+
this.name = name;
|
|
129
|
+
this.list = [];
|
|
130
|
+
}
|
|
131
|
+
add(start, end, text) {
|
|
132
|
+
this.list.push({ start, end, text });
|
|
133
|
+
}
|
|
134
|
+
apply(source) {
|
|
135
|
+
const sorted = [...this.list].sort((a, b) => b.start - a.start || b.end - a.end);
|
|
136
|
+
let out = source;
|
|
137
|
+
let floor = Infinity;
|
|
138
|
+
for (const edit of sorted) {
|
|
139
|
+
if (edit.end > floor) throw new Error(`write-property-as-facts-document: overlapping rewrites at ${String(edit.start)} (${this.name})`);
|
|
140
|
+
out = out.slice(0, edit.start) + edit.text + out.slice(edit.end);
|
|
141
|
+
floor = edit.start;
|
|
142
|
+
}
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ---- reading literals ---------------------------------------------------------------
|
|
148
|
+
|
|
149
|
+
function unwrap(node) {
|
|
150
|
+
let at = node;
|
|
151
|
+
while (at !== undefined && (ts.isParenthesizedExpression(at) || ts.isAsExpression(at) || ts.isSatisfiesExpression(at) || ts.isTypeAssertionExpression(at))) {
|
|
152
|
+
at = at.expression;
|
|
153
|
+
}
|
|
154
|
+
return at;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function keyOf(member) {
|
|
158
|
+
if (!(ts.isPropertyAssignment(member) || ts.isShorthandPropertyAssignment(member))) return undefined;
|
|
159
|
+
const name = member.name;
|
|
160
|
+
if (ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isNumericLiteral(name)) return name.text;
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** The members of an object literal by key, and whether it spreads anything in. */
|
|
165
|
+
function membersOf(literal) {
|
|
166
|
+
const byKey = new Map();
|
|
167
|
+
let spreads = false;
|
|
168
|
+
for (const member of literal.properties) {
|
|
169
|
+
if (ts.isSpreadAssignment(member)) spreads = true;
|
|
170
|
+
const key = keyOf(member);
|
|
171
|
+
if (key !== undefined) byKey.set(key, member);
|
|
172
|
+
}
|
|
173
|
+
return { byKey, spreads };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** The source text of a member's value — a shorthand member's is its name. */
|
|
177
|
+
function valueText(member, source) {
|
|
178
|
+
return ts.isShorthandPropertyAssignment(member) ? member.name.text : member.initializer.getText(source);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function valueOf(member) {
|
|
182
|
+
return ts.isShorthandPropertyAssignment(member) ? member.name : member.initializer;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function stringValue(member) {
|
|
186
|
+
if (member === undefined) return undefined;
|
|
187
|
+
const value = unwrap(valueOf(member));
|
|
188
|
+
return ts.isStringLiteralLike(value) ? value.text : undefined;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function lineOf(source, node) {
|
|
192
|
+
return source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function lineIndent(text, pos) {
|
|
196
|
+
const start = text.lastIndexOf("\n", pos - 1) + 1;
|
|
197
|
+
return /^[ \t]*/.exec(text.slice(start, pos))[0];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Whether a literal lays its members out one per line. */
|
|
201
|
+
function isMultiLine(literal, source) {
|
|
202
|
+
const first = literal.properties[0];
|
|
203
|
+
if (first === undefined) return false;
|
|
204
|
+
const open = source.getLineAndCharacterOfPosition(literal.getStart(source)).line;
|
|
205
|
+
return source.getLineAndCharacterOfPosition(first.getStart(source)).line > open;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** The span that removes `member` from its literal: its line when it has one alone, else the member and its comma. */
|
|
209
|
+
function memberSpan(member, text) {
|
|
210
|
+
let start = member.getStart();
|
|
211
|
+
let end = member.getEnd();
|
|
212
|
+
const lineStart = text.lastIndexOf("\n", start - 1) + 1;
|
|
213
|
+
const ownsLine = /^[ \t]*$/.test(text.slice(lineStart, start));
|
|
214
|
+
let at = end;
|
|
215
|
+
while (at < text.length && (text[at] === " " || text[at] === "\t")) at++;
|
|
216
|
+
const hasComma = text[at] === ",";
|
|
217
|
+
if (hasComma) end = at + 1;
|
|
218
|
+
if (ownsLine) {
|
|
219
|
+
let after = end;
|
|
220
|
+
while (after < text.length && (text[after] === " " || text[after] === "\t")) after++;
|
|
221
|
+
if (text[after] === "\n") return { start: lineStart, end: after + 1 };
|
|
222
|
+
}
|
|
223
|
+
if (!hasComma) {
|
|
224
|
+
// The literal's last member, with no comma of its own: take the comma before it.
|
|
225
|
+
let before = start;
|
|
226
|
+
while (before > 0 && /\s/.test(text[before - 1])) before--;
|
|
227
|
+
if (text[before - 1] === ",") return { start: before - 1, end };
|
|
228
|
+
}
|
|
229
|
+
while (end < text.length && text[end] === " ") end++;
|
|
230
|
+
return { start, end };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** Text that inserts `fields` right after `member` in its literal, laid out as the literal is. */
|
|
234
|
+
function insertAfter(member, literal, source, text, fields) {
|
|
235
|
+
const multi = isMultiLine(literal, source);
|
|
236
|
+
let end = member.getEnd();
|
|
237
|
+
let at = end;
|
|
238
|
+
while (at < text.length && (text[at] === " " || text[at] === "\t")) at++;
|
|
239
|
+
const hasComma = text[at] === ",";
|
|
240
|
+
if (hasComma) end = at + 1;
|
|
241
|
+
const body = fields.map(([key, value]) => `${key}: ${value}`);
|
|
242
|
+
if (multi) {
|
|
243
|
+
const indent = lineIndent(text, member.getStart());
|
|
244
|
+
return { at: end, text: (hasComma ? "" : ",") + body.map((line) => `\n${indent}${line},`).join("") };
|
|
245
|
+
}
|
|
246
|
+
const isLast = literal.properties[literal.properties.length - 1] === member;
|
|
247
|
+
if (isLast && !hasComma) return { at: end, text: `, ${body.join(", ")}` };
|
|
248
|
+
return { at: end, text: ` ${body.join(", ")},` };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** An object literal's text from `[key, valueText]` pairs, laid out on one line or one member per line. */
|
|
252
|
+
function objectText(fields, multi, indent) {
|
|
253
|
+
if (fields.length === 0) return "{}";
|
|
254
|
+
if (!multi) return `{ ${fields.map(([key, value]) => `${key}: ${value}`).join(", ")} }`;
|
|
255
|
+
return `{\n${fields.map(([key, value]) => `${indent} ${key}: ${value},`).join("\n")}\n${indent}}`;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// ---- tracing entries to their declarations --------------------------------------------
|
|
259
|
+
|
|
260
|
+
/** A module's top-level `const`s by name, and its imports by local name. */
|
|
261
|
+
function declarationsOf(source, file, files) {
|
|
262
|
+
const consts = new Map();
|
|
263
|
+
const imports = new Map();
|
|
264
|
+
for (const statement of source.statements) {
|
|
265
|
+
if (ts.isVariableStatement(statement)) {
|
|
266
|
+
for (const decl of statement.declarationList.declarations) {
|
|
267
|
+
if (ts.isIdentifier(decl.name) && decl.initializer !== undefined) consts.set(decl.name.text, decl);
|
|
268
|
+
}
|
|
269
|
+
} else if (ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier)) {
|
|
270
|
+
const spec = statement.moduleSpecifier.text;
|
|
271
|
+
if (!spec.startsWith(".")) continue;
|
|
272
|
+
const target = resolveModule(resolve(dirname(file), spec), files);
|
|
273
|
+
const named = statement.importClause?.namedBindings;
|
|
274
|
+
if (target === undefined || named === undefined || !ts.isNamedImports(named)) continue;
|
|
275
|
+
for (const element of named.elements) {
|
|
276
|
+
imports.set(element.name.text, { file: target, name: (element.propertyName ?? element.name).text });
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return { consts, imports };
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function resolveModule(path, files) {
|
|
284
|
+
const bare = path.replace(/\.(?:js|ts|tsx|mjs)$/, "");
|
|
285
|
+
for (const candidate of [path, `${bare}.ts`, `${bare}.tsx`, join(bare, "index.ts")]) {
|
|
286
|
+
if (files.has(candidate)) return candidate;
|
|
287
|
+
}
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function typeNameOf(decl) {
|
|
292
|
+
let type = decl.type;
|
|
293
|
+
if (type !== undefined && ts.isArrayTypeNode(type)) type = type.elementType;
|
|
294
|
+
return type !== undefined && ts.isTypeReferenceNode(type) && ts.isIdentifier(type.typeName) ? type.typeName.text : undefined;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// ---- recognizing literals by shape ----------------------------------------------------
|
|
298
|
+
|
|
299
|
+
function isPropertyLiteral(byKey, spreads) {
|
|
300
|
+
const old = [...byKey.keys()].some((key) => OLD_PROPERTY_KEYS.has(key));
|
|
301
|
+
if (!old || byKey.has("unit_id")) return false;
|
|
302
|
+
return spreads || byKey.has("property_type") || byKey.has("listing_intent") || byKey.has("narrative");
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// A content entry's item may state a field named `unit_id`, and a plan's `unit_assignments`
|
|
306
|
+
// row carries a `unit_label`; a unit also carries its figures.
|
|
307
|
+
const isUnitLiteral = (byKey) =>
|
|
308
|
+
(byKey.has("unit_id") && ["beds", "baths", "sqft", "price", "position", "floor_plans"].some((key) => byKey.has(key))) ||
|
|
309
|
+
(byKey.has("unit_label") && byKey.has("beds"));
|
|
310
|
+
const isContactLiteral = (byKey) => byKey.has("website_url") || byKey.has("instagram_url") || (byKey.has("avatar") && byKey.has("org_name"));
|
|
311
|
+
const isComparableLiteral = (byKey) => byKey.has("address_street") || byKey.has("address_city");
|
|
312
|
+
|
|
313
|
+
/** Every object literal in a module, outermost first. */
|
|
314
|
+
function objectLiterals(source) {
|
|
315
|
+
const found = [];
|
|
316
|
+
const visit = (node) => {
|
|
317
|
+
if (ts.isObjectLiteralExpression(node)) found.push(node);
|
|
318
|
+
ts.forEachChild(node, visit);
|
|
319
|
+
};
|
|
320
|
+
visit(source);
|
|
321
|
+
return found;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// ---- pass A: the primary contact first -------------------------------------------------
|
|
325
|
+
|
|
326
|
+
function reorderContacts(text, file) {
|
|
327
|
+
const source = parse(file, text);
|
|
328
|
+
const edits = new Edits(`contacts of ${file}`);
|
|
329
|
+
for (const literal of objectLiterals(source)) {
|
|
330
|
+
const { byKey, spreads } = membersOf(literal);
|
|
331
|
+
if (!isPropertyLiteral(byKey, spreads)) continue;
|
|
332
|
+
const contacts = byKey.get("contacts");
|
|
333
|
+
const list = contacts === undefined ? undefined : unwrap(valueOf(contacts));
|
|
334
|
+
if (list === undefined || !ts.isArrayLiteralExpression(list)) continue;
|
|
335
|
+
const elements = list.elements;
|
|
336
|
+
const primaryAt = elements.findIndex((element) => {
|
|
337
|
+
const item = unwrap(element);
|
|
338
|
+
if (!ts.isObjectLiteralExpression(item)) return false;
|
|
339
|
+
const primary = membersOf(item).byKey.get("primary");
|
|
340
|
+
return primary !== undefined && unwrap(valueOf(primary)).kind === ts.SyntaxKind.TrueKeyword;
|
|
341
|
+
});
|
|
342
|
+
if (primaryAt <= 0) continue;
|
|
343
|
+
// Each element keeps its own text; the slots they sit in keep theirs, so the layout holds.
|
|
344
|
+
const texts = elements.map((element) => element.getText(source));
|
|
345
|
+
const order = [primaryAt, ...elements.map((_, i) => i).filter((i) => i !== primaryAt)];
|
|
346
|
+
elements.forEach((element, slot) => edits.add(element.getStart(source), element.getEnd(), texts[order[slot]]));
|
|
347
|
+
}
|
|
348
|
+
return edits.list.length === 0 ? text : edits.apply(text);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// ---- pass B: entries, units, contacts, comparables, content ------------------------------
|
|
352
|
+
|
|
353
|
+
/** The entry type an untyped `const` holding `initializer` of `pool` is annotated with. */
|
|
354
|
+
function entryTypeOf(initializer, pool) {
|
|
355
|
+
const value = unwrap(initializer);
|
|
356
|
+
if (ts.isArrayLiteralExpression(value)) return `${pool === "videos" ? "VideoEntry" : entryTypeOf(value.elements[0] ?? value, pool)}[]`;
|
|
357
|
+
if (pool !== "videos") return Object.entries(ENTRY_TYPES).find(([, of]) => of === pool)[0];
|
|
358
|
+
const source = ts.isObjectLiteralExpression(value) ? stringValue(membersOf(value).byKey.get("source")) : undefined;
|
|
359
|
+
return source === "upload" ? "UploadVideoEntry" : source === "link" ? "LinkVideoEntry" : "VideoEntry";
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Tag every upload entry literal in the workspace with its pool, by `file:start`, and name
|
|
364
|
+
* every untyped `const` holding one: once an entry states its `kind`, an untyped `const`
|
|
365
|
+
* widens it to `string`, which the property's type refuses, so each is annotated.
|
|
366
|
+
*/
|
|
367
|
+
function tagEntries(parsed, report) {
|
|
368
|
+
const tags = new Map();
|
|
369
|
+
const annotations = new Map();
|
|
370
|
+
const tag = (file, literal, pool) => tags.set(`${file}:${String(literal.getStart())}`, pool);
|
|
371
|
+
const annotate = (file, decl, pool) => {
|
|
372
|
+
if (decl.type !== undefined || !ts.isIdentifier(decl.name)) return;
|
|
373
|
+
const list = annotations.get(file) ?? [];
|
|
374
|
+
if (list.some((entry) => entry.decl === decl)) return;
|
|
375
|
+
annotations.set(file, [...list, { decl, type: entryTypeOf(decl.initializer, pool) }]);
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
const traceValue = (file, node, pool, seen) => {
|
|
379
|
+
const value = unwrap(node);
|
|
380
|
+
const { source, decls } = parsed.get(file);
|
|
381
|
+
if (ts.isObjectLiteralExpression(value)) {
|
|
382
|
+
tag(file, value, pool);
|
|
383
|
+
} else if (ts.isArrayLiteralExpression(value)) {
|
|
384
|
+
for (const element of value.elements) {
|
|
385
|
+
traceValue(file, ts.isSpreadElement(element) ? element.expression : element, pool, seen);
|
|
386
|
+
}
|
|
387
|
+
} else if (ts.isIdentifier(value)) {
|
|
388
|
+
const key = `${file}:${value.text}`;
|
|
389
|
+
if (seen.has(key)) return;
|
|
390
|
+
seen.add(key);
|
|
391
|
+
const local = decls.consts.get(value.text);
|
|
392
|
+
if (local !== undefined) {
|
|
393
|
+
annotate(file, local, pool);
|
|
394
|
+
return traceValue(file, local.initializer, pool, seen);
|
|
395
|
+
}
|
|
396
|
+
const imported = decls.imports.get(value.text);
|
|
397
|
+
const there = imported === undefined ? undefined : parsed.get(imported.file);
|
|
398
|
+
const decl = there?.decls.consts.get(imported.name);
|
|
399
|
+
if (decl !== undefined) {
|
|
400
|
+
annotate(imported.file, decl, pool);
|
|
401
|
+
return traceValue(imported.file, decl.initializer, pool, seen);
|
|
402
|
+
}
|
|
403
|
+
report(file, lineOf(source, value), `\`${value.text}\` is listed in the property's \`${pool}\`, but is declared outside this workspace — ${TABLE.entry}`);
|
|
404
|
+
} else {
|
|
405
|
+
report(file, lineOf(source, value), `the property's \`${pool}\` holds an expression this codemod cannot trace — ${TABLE.entry}`);
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
for (const [file, { source, decls }] of parsed) {
|
|
410
|
+
for (const decl of decls.consts.values()) {
|
|
411
|
+
const pool = ENTRY_TYPES[typeNameOf(decl)];
|
|
412
|
+
if (pool !== undefined) traceValue(file, decl.initializer, pool, new Set());
|
|
413
|
+
}
|
|
414
|
+
for (const literal of objectLiterals(source)) {
|
|
415
|
+
const { byKey, spreads } = membersOf(literal);
|
|
416
|
+
if (!isPropertyLiteral(byKey, spreads)) continue;
|
|
417
|
+
for (const pool of POOLS) {
|
|
418
|
+
const member = byKey.get(pool);
|
|
419
|
+
if (member !== undefined) traceValue(file, valueOf(member), pool, new Set());
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return { tags, annotations };
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** The entry a unit's floor plan `id` names, as this module can spell it: the name of the `const` holding it. */
|
|
427
|
+
function planNames(file, parsed, tags) {
|
|
428
|
+
const names = new Map();
|
|
429
|
+
const { decls } = parsed.get(file);
|
|
430
|
+
const consider = (localName, declFile, decl) => {
|
|
431
|
+
const literal = unwrap(decl.initializer);
|
|
432
|
+
if (!ts.isObjectLiteralExpression(literal)) return;
|
|
433
|
+
if (tags.get(`${declFile}:${String(literal.getStart())}`) !== "floor_plans") return;
|
|
434
|
+
const id = stringValue(membersOf(literal).byKey.get("id"));
|
|
435
|
+
if (id !== undefined) names.set(id, localName);
|
|
436
|
+
};
|
|
437
|
+
for (const [name, decl] of decls.consts) consider(name, file, decl);
|
|
438
|
+
for (const [name, { file: from, name: exported }] of decls.imports) {
|
|
439
|
+
const decl = parsed.get(from)?.decls.consts.get(exported);
|
|
440
|
+
if (decl !== undefined) consider(name, from, decl);
|
|
441
|
+
}
|
|
442
|
+
return names;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/** Import `names` as types from the fixture declarations: into the module's import of them where it has a named one, else in an import of their own. */
|
|
446
|
+
function addTypeImports(source, names, edits) {
|
|
447
|
+
const statement = source.statements.find(isFixturesImport);
|
|
448
|
+
const named = statement?.importClause?.namedBindings;
|
|
449
|
+
if (statement !== undefined && named !== undefined && ts.isNamedImports(named)) {
|
|
450
|
+
const have = new Set(named.elements.map((element) => element.name.text));
|
|
451
|
+
const missing = names.filter((name) => !have.has(name));
|
|
452
|
+
if (missing.length === 0) return;
|
|
453
|
+
const prefix = statement.importClause.isTypeOnly ? "" : "type ";
|
|
454
|
+
// The list re-sorted by imported name, as the import-order lint keeps it.
|
|
455
|
+
const specifiers = [
|
|
456
|
+
...named.elements.map((element) => ({ name: element.name.text, text: element.getText(source) })),
|
|
457
|
+
...missing.map((name) => ({ name, text: `${prefix}${name}` })),
|
|
458
|
+
].sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
|
|
459
|
+
const multi = named.getText(source).includes("\n");
|
|
460
|
+
const indent = multi && named.elements.length > 0 ? lineIndent(source.text, named.elements[0].getStart(source)) : " ";
|
|
461
|
+
const list = multi ? `{\n${specifiers.map(({ text }) => `${indent}${text},`).join("\n")}\n}` : `{ ${specifiers.map(({ text }) => text).join(", ")} }`;
|
|
462
|
+
edits.add(named.getStart(source), named.getEnd(), list);
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
const after = statement ?? source.statements.filter(ts.isImportDeclaration).at(-1);
|
|
466
|
+
const at = after === undefined ? 0 : after.getEnd();
|
|
467
|
+
const spec = statement !== undefined ? statement.moduleSpecifier.getText(source) : JSON.stringify(FIXTURES);
|
|
468
|
+
edits.add(at, at, `${after === undefined ? "" : "\n"}import type { ${[...names].sort().join(", ")} } from ${spec};${after === undefined ? "\n" : ""}`);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function rewriteLeaves(file, text, parsed, tags, annotations, report) {
|
|
472
|
+
const { source } = parsed.get(file);
|
|
473
|
+
const edits = new Edits(`leaves of ${file}`);
|
|
474
|
+
const plans = planNames(file, parsed, tags);
|
|
475
|
+
const remove = (member) => {
|
|
476
|
+
const span = memberSpan(member, text);
|
|
477
|
+
edits.add(span.start, span.end, "");
|
|
478
|
+
};
|
|
479
|
+
const rename = (member, to) => {
|
|
480
|
+
if (ts.isShorthandPropertyAssignment(member)) return edits.add(member.name.getStart(source), member.name.getEnd(), `${to}: ${member.name.text}`);
|
|
481
|
+
// `avatar: headshot` reads `headshot` once it is renamed.
|
|
482
|
+
if (ts.isIdentifier(member.initializer) && member.initializer.text === to) return edits.add(member.getStart(source), member.getEnd(), to);
|
|
483
|
+
return edits.add(member.name.getStart(source), member.name.getEnd(), to);
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
// Each untyped `const` holding an entry takes its entry type, imported beside the rest.
|
|
487
|
+
for (const { decl, type } of annotations) edits.add(decl.name.getEnd(), decl.name.getEnd(), `: ${type}`);
|
|
488
|
+
const needed = [...new Set(annotations.map(({ type }) => type.replace(/\[\]$/, "")))];
|
|
489
|
+
if (needed.length > 0) addTypeImports(source, needed, edits);
|
|
490
|
+
|
|
491
|
+
// A row literal a property lists is that row whatever its members — a contact spread from
|
|
492
|
+
// another states only what differs — beside every literal its own members identify.
|
|
493
|
+
const listed = new Map();
|
|
494
|
+
for (const literal of objectLiterals(source)) {
|
|
495
|
+
const { byKey, spreads } = membersOf(literal);
|
|
496
|
+
if (!isPropertyLiteral(byKey, spreads)) continue;
|
|
497
|
+
for (const list of ["units", "contacts", "comparables"]) {
|
|
498
|
+
const value = byKey.has(list) ? unwrap(valueOf(byKey.get(list))) : undefined;
|
|
499
|
+
if (value === undefined || !ts.isArrayLiteralExpression(value)) continue;
|
|
500
|
+
for (const element of value.elements) {
|
|
501
|
+
const item = unwrap(element);
|
|
502
|
+
if (ts.isObjectLiteralExpression(item)) listed.set(item, list);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
for (const literal of objectLiterals(source)) {
|
|
508
|
+
const { byKey } = membersOf(literal);
|
|
509
|
+
const pool = tags.get(`${file}:${String(literal.getStart())}`);
|
|
510
|
+
const row = listed.get(literal);
|
|
511
|
+
|
|
512
|
+
if (pool !== undefined) {
|
|
513
|
+
if (byKey.has("kind")) continue;
|
|
514
|
+
const anchor = byKey.get("id") ?? literal.properties[0];
|
|
515
|
+
if (anchor === undefined) continue;
|
|
516
|
+
const insert = insertAfter(anchor, literal, source, text, KIND_OF[pool]);
|
|
517
|
+
edits.add(insert.at, insert.at, insert.text);
|
|
518
|
+
if (pool === "floor_plans" && byKey.has("unit_assignments")) remove(byKey.get("unit_assignments"));
|
|
519
|
+
if (pool === "documents" && stringValue(byKey.get("notes")) === "") {
|
|
520
|
+
const notes = valueOf(byKey.get("notes"));
|
|
521
|
+
edits.add(notes.getStart(source), notes.getEnd(), "null");
|
|
522
|
+
}
|
|
523
|
+
} else if (row === "units" || (row === undefined && isUnitLiteral(byKey))) {
|
|
524
|
+
if (byKey.has("unit_id")) rename(byKey.get("unit_id"), "id");
|
|
525
|
+
if (byKey.has("unit_label")) rename(byKey.get("unit_label"), "label");
|
|
526
|
+
if (byKey.has("position")) remove(byKey.get("position"));
|
|
527
|
+
const floorPlans = byKey.get("floor_plans");
|
|
528
|
+
const list = floorPlans === undefined ? undefined : unwrap(valueOf(floorPlans));
|
|
529
|
+
if (list !== undefined && ts.isArrayLiteralExpression(list)) {
|
|
530
|
+
for (const element of list.elements) {
|
|
531
|
+
const ref = unwrap(element);
|
|
532
|
+
const refMembers = ts.isObjectLiteralExpression(ref) ? membersOf(ref).byKey : undefined;
|
|
533
|
+
// Already a pick by value.
|
|
534
|
+
if (refMembers?.has("image")) continue;
|
|
535
|
+
const id = stringValue(refMembers?.get("id"));
|
|
536
|
+
const name = id === undefined ? undefined : plans.get(id);
|
|
537
|
+
if (name === undefined) {
|
|
538
|
+
report(
|
|
539
|
+
file,
|
|
540
|
+
lineOf(source, element),
|
|
541
|
+
id === undefined
|
|
542
|
+
? `a unit's floor plan is not a \`{ id, floor_label, position }\` literal this codemod can read — ${TABLE.unit}`
|
|
543
|
+
: `a unit's floor plan names "${id}", but no \`const\` in this module holds that floor plan's entry; declare one and name it — ${TABLE.unit}`,
|
|
544
|
+
);
|
|
545
|
+
continue;
|
|
546
|
+
}
|
|
547
|
+
const floor = refMembers.get("floor_label");
|
|
548
|
+
edits.add(element.getStart(source), element.getEnd(), `{ image: ${name}, floor: ${floor === undefined ? "null" : valueText(floor, source)} }`);
|
|
549
|
+
}
|
|
550
|
+
} else if (floorPlans !== undefined) {
|
|
551
|
+
const built = unwrap(valueOf(floorPlans));
|
|
552
|
+
const by = ts.isCallExpression(built) ? `${built.expression.getText(source)}(…)` : valueText(floorPlans, source);
|
|
553
|
+
report(file, lineOf(source, floorPlans), `a unit's \`floor_plans\` is built by \`${by}\`; rewrite what it returns by hand — ${TABLE.unit}`);
|
|
554
|
+
}
|
|
555
|
+
} else if (row === "contacts" || (row === undefined && isContactLiteral(byKey))) {
|
|
556
|
+
for (const [from, to] of Object.entries(CONTACT_RENAMES)) {
|
|
557
|
+
if (byKey.has(from)) rename(byKey.get(from), to);
|
|
558
|
+
}
|
|
559
|
+
if (byKey.has("primary")) remove(byKey.get("primary"));
|
|
560
|
+
} else if (row === "comparables" || (row === undefined && isComparableLiteral(byKey))) {
|
|
561
|
+
const part = (key) => (byKey.has(key) ? valueText(byKey.get(key), source) : "null");
|
|
562
|
+
const fields = [
|
|
563
|
+
["street", part("address_street")],
|
|
564
|
+
["city", part("address_city")],
|
|
565
|
+
["state", part("address_state")],
|
|
566
|
+
["postal", part("address_postal")],
|
|
567
|
+
["latitude", part("lat")],
|
|
568
|
+
["longitude", part("lng")],
|
|
569
|
+
];
|
|
570
|
+
const status = stringValue(byKey.get("status"));
|
|
571
|
+
const sale = byKey.get("sale_date");
|
|
572
|
+
const saleIsNull = sale === undefined || unwrap(valueOf(sale)).kind === ts.SyntaxKind.NullKeyword;
|
|
573
|
+
if ((status === "sold" && saleIsNull) || (status === "active" && sale !== undefined && !saleIsNull)) {
|
|
574
|
+
report(file, lineOf(source, literal), `Manual: a comparable stated \`status: "${status}"\`, which its sale date now decides — a comp with a \`sale_date\` is sold, one without is active; give it the sale date its status meant`);
|
|
575
|
+
}
|
|
576
|
+
const anchor = byKey.get("address_street") ?? byKey.get("address_city");
|
|
577
|
+
if (anchor !== undefined) edits.add(anchor.getStart(source), anchor.getEnd(), `address: ${objectText(fields, false, "")}`);
|
|
578
|
+
for (const key of ["address_city", "address_state", "address_postal", "address", "lat", "lng", "status", "distance_m", "price_period"]) {
|
|
579
|
+
const member = byKey.get(key);
|
|
580
|
+
if (member !== undefined && member !== anchor) remove(member);
|
|
581
|
+
}
|
|
582
|
+
} else if (byKey.has("contact") && stringValue(byKey.get("field")) === "avatar" && literal.properties.length === 2) {
|
|
583
|
+
const field = valueOf(byKey.get("field"));
|
|
584
|
+
edits.add(field.getStart(source), field.getEnd(), '"headshot"');
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
return edits.list.length === 0 ? text : edits.apply(text);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
// ---- pass C: the property's own members ----------------------------------------------------
|
|
591
|
+
|
|
592
|
+
function rewriteProperties(file, text, report) {
|
|
593
|
+
const source = parse(file, text);
|
|
594
|
+
const edits = new Edits(`property of ${file}`);
|
|
595
|
+
for (const literal of objectLiterals(source)) {
|
|
596
|
+
const { byKey, spreads } = membersOf(literal);
|
|
597
|
+
if (!isPropertyLiteral(byKey, spreads)) continue;
|
|
598
|
+
if (spreads) {
|
|
599
|
+
report(file, lineOf(source, literal), `a property spread from another states \`${[...byKey.keys()].filter((key) => OLD_PROPERTY_KEYS.has(key)).join("`, `")}\`; write the variation as a whole property — ${TABLE.property}`);
|
|
600
|
+
continue;
|
|
601
|
+
}
|
|
602
|
+
const multi = isMultiLine(literal, source);
|
|
603
|
+
const remove = (member) => {
|
|
604
|
+
const span = memberSpan(member, text);
|
|
605
|
+
edits.add(span.start, span.end, "");
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
// The address holds its pin; its derived lines are the platform's.
|
|
609
|
+
const address = byKey.get("address");
|
|
610
|
+
const addressValue = address === undefined ? undefined : unwrap(valueOf(address));
|
|
611
|
+
const lat = byKey.get("lat");
|
|
612
|
+
const lon = byKey.get("lon");
|
|
613
|
+
if (addressValue !== undefined && ts.isObjectLiteralExpression(addressValue)) {
|
|
614
|
+
const parts = membersOf(addressValue).byKey;
|
|
615
|
+
const fields = [];
|
|
616
|
+
for (const key of ["street", "unit", "city", "state", "postal"]) {
|
|
617
|
+
if (parts.has(key)) fields.push([key, valueText(parts.get(key), source)]);
|
|
618
|
+
}
|
|
619
|
+
fields.push(["latitude", lat === undefined ? "null" : valueText(lat, source)]);
|
|
620
|
+
fields.push(["longitude", lon === undefined ? "null" : valueText(lon, source)]);
|
|
621
|
+
const indent = lineIndent(text, address.getStart(source));
|
|
622
|
+
edits.add(addressValue.getStart(source), addressValue.getEnd(), objectText(fields, isMultiLine(addressValue, source), indent));
|
|
623
|
+
if (lat !== undefined) remove(lat);
|
|
624
|
+
if (lon !== undefined) remove(lon);
|
|
625
|
+
} else if (lat !== undefined || lon !== undefined) {
|
|
626
|
+
report(file, lineOf(source, literal), `the property's \`address\` is not an object literal, so its \`lat\`/\`lon\` stay where they are — ${TABLE.property}`);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// The description is a fact of its own.
|
|
630
|
+
const narrative = byKey.get("narrative");
|
|
631
|
+
if (narrative !== undefined) {
|
|
632
|
+
const value = unwrap(valueOf(narrative));
|
|
633
|
+
const description = ts.isObjectLiteralExpression(value) ? membersOf(value).byKey.get("description") : undefined;
|
|
634
|
+
const text_ = description !== undefined ? valueText(description, source) : `${valueText(narrative, source)}.description`;
|
|
635
|
+
edits.add(narrative.getStart(source), narrative.getEnd(), `description: ${text_}`);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// One uploads list, pool by pool in the platform's order.
|
|
639
|
+
const pools = POOLS.map((pool) => byKey.get(pool)).filter((member) => member !== undefined);
|
|
640
|
+
if (pools.length > 0) {
|
|
641
|
+
const groups = [];
|
|
642
|
+
let spanLines = false;
|
|
643
|
+
for (const member of POOLS.map((pool) => byKey.get(pool))) {
|
|
644
|
+
if (member === undefined) continue;
|
|
645
|
+
const value = unwrap(valueOf(member));
|
|
646
|
+
if (ts.isArrayLiteralExpression(value)) {
|
|
647
|
+
if (value.elements.length === 0) continue;
|
|
648
|
+
const inner = text.slice(value.elements[0].getStart(source), value.elements[value.elements.length - 1].getEnd());
|
|
649
|
+
if (inner.includes("\n")) spanLines = true;
|
|
650
|
+
groups.push(inner);
|
|
651
|
+
} else {
|
|
652
|
+
groups.push(`...${ts.isIdentifier(value) ? value.text : `(${valueText(member, source)})`}`);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
const first = pools.reduce((a, b) => (a.getStart(source) < b.getStart(source) ? a : b));
|
|
656
|
+
const indent = lineIndent(text, first.getStart(source));
|
|
657
|
+
const joined = groups.join(", ");
|
|
658
|
+
const list =
|
|
659
|
+
groups.length === 0
|
|
660
|
+
? "[]"
|
|
661
|
+
: spanLines || (multi && joined.length + indent.length > 110)
|
|
662
|
+
? `[\n${groups.map((group) => `${indent} ${group.replace(/,\s*$/, "")},`).join("\n")}\n${indent}]`
|
|
663
|
+
: `[${joined}]`;
|
|
664
|
+
edits.add(first.getStart(source), first.getEnd(), `uploads: ${list}`);
|
|
665
|
+
for (const member of pools) if (member !== first) remove(member);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
return edits.list.length === 0 ? text : edits.apply(text);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/** @param {string} root @returns {Promise<{rewritten: string[], notRewritten: {file: string, reason: string}[]}>} */
|
|
672
|
+
export default async function writePropertyAsFactsDocument(root) {
|
|
673
|
+
// One report per file and reason, naming every line it holds for.
|
|
674
|
+
const reports = new Map();
|
|
675
|
+
const report = (file, line, reason) => {
|
|
676
|
+
const key = `${file}\0${reason}`;
|
|
677
|
+
const lines = reports.get(key)?.lines ?? [];
|
|
678
|
+
reports.set(key, { file: relative(root, file).split("\\").join("/"), reason, lines: [...lines, line] });
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
// Only modules that import the fixture declarations carry a property or a fixture.
|
|
682
|
+
const original = new Map();
|
|
683
|
+
for (const file of await sourceFiles(root)) {
|
|
684
|
+
const text = await readFile(file, "utf8");
|
|
685
|
+
if (!text.includes(FIXTURES)) continue;
|
|
686
|
+
if (importsFixtures(parse(file, text))) original.set(file, text);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// A: the primary contact first, while `primary` still says which it is.
|
|
690
|
+
const afterA = new Map([...original].map(([file, text]) => [file, reorderContacts(text, file)]));
|
|
691
|
+
|
|
692
|
+
// B: the leaves, with every upload entry traced to its pool across the workspace first.
|
|
693
|
+
const files = new Set(afterA.keys());
|
|
694
|
+
const parsed = new Map();
|
|
695
|
+
for (const [file, text] of afterA) {
|
|
696
|
+
const source = parse(file, text);
|
|
697
|
+
parsed.set(file, { source, decls: declarationsOf(source, file, files) });
|
|
698
|
+
}
|
|
699
|
+
const { tags, annotations } = tagEntries(parsed, report);
|
|
700
|
+
const afterB = new Map([...afterA].map(([file, text]) => [file, rewriteLeaves(file, text, parsed, tags, annotations.get(file) ?? [], report)]));
|
|
701
|
+
|
|
702
|
+
// C: the property's own members, over the leaves' result.
|
|
703
|
+
const rewritten = [];
|
|
704
|
+
for (const [file, text] of afterB) {
|
|
705
|
+
const out = rewriteProperties(file, text, report);
|
|
706
|
+
if (out === original.get(file)) continue;
|
|
707
|
+
await writeFile(file, out);
|
|
708
|
+
rewritten.push(relative(root, file).split("\\").join("/"));
|
|
709
|
+
}
|
|
710
|
+
const notRewritten = [...reports.values()].map(({ file, reason, lines }) => {
|
|
711
|
+
// A `Manual:` follow-up keeps its label first, where the upgrade's reader looks for it.
|
|
712
|
+
const where = `${lines.length === 1 ? "line" : "lines"} ${lines.join(", ")}`;
|
|
713
|
+
return { file, reason: reason.startsWith("Manual: ") ? `Manual: ${where}: ${reason.slice("Manual: ".length)}` : `${where}: ${reason}` };
|
|
714
|
+
});
|
|
715
|
+
return { rewritten, notRewritten };
|
|
716
|
+
}
|