@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,454 @@
|
|
|
1
|
+
// The media pools are no longer facts; `fact.property.uploads` is the one media read.
|
|
2
|
+
//
|
|
3
|
+
// `fact.photos`, `fact.videos`, `fact.tours`, `fact.floor_plans`, `fact.documents` and
|
|
4
|
+
// `fact.document_notes` are gone, with the `FactsPhoto`, `FactsVideo`, `FactsTour`,
|
|
5
|
+
// `FactsFloorPlan`, `FactsDocument` and `FactsDocumentNote` row types. In their place a
|
|
6
|
+
// `compute()` or a fill reads `fact.property.uploads` — every upload's asset record
|
|
7
|
+
// (`readonly Media[]` to a compute) — and narrows it by the record's `kind` and
|
|
8
|
+
// `category`. A slot never names a pool as its `source`: a media slot picks by its kind
|
|
9
|
+
// and `category`.
|
|
10
|
+
//
|
|
11
|
+
// What this codemod does, in every `.ts` and `.tsx` under the workspace that imports this
|
|
12
|
+
// package:
|
|
13
|
+
//
|
|
14
|
+
// - in `compute({ reads: [ … ] }, fn)`, each pool read becomes `fact.property.uploads`,
|
|
15
|
+
// and when `fn` is written inline its parameter for that read is renamed (`uploads`,
|
|
16
|
+
// or `uploads2`, … where the name is taken) and the old name is bound to the subset
|
|
17
|
+
// the pool held as the function's first statement —
|
|
18
|
+
//
|
|
19
|
+
// photos `uploads.filter((asset) => asset.kind === "image" && asset.category === "photo")`
|
|
20
|
+
// floor_plans `uploads.filter((asset) => asset.kind === "image" && asset.category === "floor_plan")`
|
|
21
|
+
// videos `uploads.filter((asset) => asset.kind === "video")`
|
|
22
|
+
// tours `uploads.filter((asset) => asset.kind === "tour")`
|
|
23
|
+
// documents `uploads.filter((asset) => asset.kind === "document")`
|
|
24
|
+
// document_notes `uploads.filter((asset) => asset.kind === "document" && asset.notes !== null)`
|
|
25
|
+
//
|
|
26
|
+
// - any other pool named in an array literal (a fill's `reads`, a shared list of reads)
|
|
27
|
+
// becomes `fact.property.uploads`, named once per literal;
|
|
28
|
+
// - `FactsPhoto` and `FactsFloorPlan` become `ImageMedia`, `FactsVideo` `VideoMedia`,
|
|
29
|
+
// `FactsTour` `TourMedia`, `FactsDocument` and `FactsDocumentNote` `DocumentMedia`, in
|
|
30
|
+
// the import and at every type reference.
|
|
31
|
+
//
|
|
32
|
+
// What it hands back, by line: a pool read anywhere else (a slot's or a list's `source`,
|
|
33
|
+
// an argument, a bare expression); a pool read into a compute's destructured or rest
|
|
34
|
+
// parameter, a function not written inline, or a position after a spread; and a rewritten
|
|
35
|
+
// compute whose body reads a member the record spells otherwise — a video's `source`, a
|
|
36
|
+
// document's `filename`, a floor plan's `unit_assignments`, a note's `upload_id`.
|
|
37
|
+
|
|
38
|
+
import { readdir, readFile, writeFile } from "node:fs/promises";
|
|
39
|
+
import { join, relative, sep } from "node:path";
|
|
40
|
+
|
|
41
|
+
import ts from "typescript";
|
|
42
|
+
|
|
43
|
+
const CONCRETE = "@homepages/concrete";
|
|
44
|
+
const EXTENSIONS = [".ts", ".tsx"];
|
|
45
|
+
const SKIP_DIRS = new Set(["node_modules", ".concrete", ".git", "dist", "build"]);
|
|
46
|
+
|
|
47
|
+
const UPLOADS = "fact.property.uploads";
|
|
48
|
+
|
|
49
|
+
// Each pool: the filter a compute binds its subset with, the builder a slot picking from
|
|
50
|
+
// it states, and the member its rows spelled that the record spells otherwise.
|
|
51
|
+
const POOLS = {
|
|
52
|
+
photos: {
|
|
53
|
+
filter: `(asset) => asset.kind === "image" && asset.category === "photo"`,
|
|
54
|
+
item: `image({ category: "property" })`,
|
|
55
|
+
},
|
|
56
|
+
floor_plans: {
|
|
57
|
+
filter: `(asset) => asset.kind === "image" && asset.category === "floor_plan"`,
|
|
58
|
+
item: `image({ category: "floor_plan" })`,
|
|
59
|
+
renamed: { member: "unit_assignments", record: "a floor plan's record carries no unit assignments; compute them over `fact.property.units`" },
|
|
60
|
+
},
|
|
61
|
+
videos: {
|
|
62
|
+
filter: `(asset) => asset.kind === "video"`,
|
|
63
|
+
item: `video()`,
|
|
64
|
+
renamed: { member: "source", record: "a video's record has no `source`; a hosted upload is one whose `provider` is `null`" },
|
|
65
|
+
},
|
|
66
|
+
tours: { filter: `(asset) => asset.kind === "tour"`, item: `tour()` },
|
|
67
|
+
documents: {
|
|
68
|
+
filter: `(asset) => asset.kind === "document"`,
|
|
69
|
+
item: `document()`,
|
|
70
|
+
renamed: { member: "filename", record: "a document's record spells its file name `name`" },
|
|
71
|
+
},
|
|
72
|
+
document_notes: {
|
|
73
|
+
filter: `(asset) => asset.kind === "document" && asset.notes !== null`,
|
|
74
|
+
item: `document()`,
|
|
75
|
+
renamed: { member: "upload_id", record: "a note is a document's record, whose identity is `id`" },
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const TYPE_RENAMES = {
|
|
80
|
+
FactsPhoto: "ImageMedia",
|
|
81
|
+
FactsFloorPlan: "ImageMedia",
|
|
82
|
+
FactsVideo: "VideoMedia",
|
|
83
|
+
FactsTour: "TourMedia",
|
|
84
|
+
FactsDocument: "DocumentMedia",
|
|
85
|
+
FactsDocumentNote: "DocumentMedia",
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
async function sourceFiles(root) {
|
|
89
|
+
const found = [];
|
|
90
|
+
async function walk(dir) {
|
|
91
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
92
|
+
if (entry.isDirectory()) {
|
|
93
|
+
if (!SKIP_DIRS.has(entry.name)) await walk(join(dir, entry.name));
|
|
94
|
+
} else if (EXTENSIONS.some((ext) => entry.name.endsWith(ext)) && !entry.name.endsWith(".d.ts")) {
|
|
95
|
+
found.push(join(dir, entry.name));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
await walk(root);
|
|
100
|
+
return found.sort();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function lineOf(sf, pos) {
|
|
104
|
+
return sf.getLineAndCharacterOfPosition(pos).line + 1;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function nameOf(property) {
|
|
108
|
+
const name = property.name;
|
|
109
|
+
return name !== undefined && (ts.isIdentifier(name) || ts.isStringLiteral(name)) ? name.text : undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// The framework's imports in a file: its declarations, the local names `fact` and
|
|
113
|
+
// `compute` are bound to, and the receivers of a namespace import (`c` in `c.fact.x`).
|
|
114
|
+
function frameworkImports(sf, isFramework) {
|
|
115
|
+
const declarations = [];
|
|
116
|
+
const locals = { fact: new Set(), compute: new Set() };
|
|
117
|
+
const namespaces = new Set();
|
|
118
|
+
for (const statement of sf.statements) {
|
|
119
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier) || !isFramework(statement.moduleSpecifier.text)) continue;
|
|
120
|
+
declarations.push(statement);
|
|
121
|
+
const bindings = statement.importClause?.namedBindings;
|
|
122
|
+
if (bindings === undefined) continue;
|
|
123
|
+
if (ts.isNamespaceImport(bindings)) {
|
|
124
|
+
namespaces.add(bindings.name.text);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
for (const element of bindings.elements) {
|
|
128
|
+
const imported = (element.propertyName ?? element.name).text;
|
|
129
|
+
if (imported === "fact" || imported === "compute") locals[imported].add(element.name.text);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return { declarations, locals, namespaces };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Whether `node` reaches the framework's export `name`: a local it was imported as, or
|
|
136
|
+
// `c.name` through a namespace import.
|
|
137
|
+
function reaches(node, name, locals, namespaces) {
|
|
138
|
+
if (ts.isIdentifier(node)) return locals[name].has(node.text);
|
|
139
|
+
return (
|
|
140
|
+
ts.isPropertyAccessExpression(node) &&
|
|
141
|
+
node.name.text === name &&
|
|
142
|
+
ts.isIdentifier(node.expression) &&
|
|
143
|
+
namespaces.has(node.expression.text)
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// The pool a `fact.x` (or `c.fact.x`) expression reads, or `undefined`.
|
|
148
|
+
function poolRead(node, locals, namespaces) {
|
|
149
|
+
if (!ts.isPropertyAccessExpression(node) || !Object.hasOwn(POOLS, node.name.text)) return undefined;
|
|
150
|
+
return reaches(node.expression, "fact", locals, namespaces) ? node.name.text : undefined;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Whether `node` is `fact.property.uploads` (or `c.fact.property.uploads`).
|
|
154
|
+
function isUploads(node, locals, namespaces) {
|
|
155
|
+
return (
|
|
156
|
+
ts.isPropertyAccessExpression(node) &&
|
|
157
|
+
node.name.text === "uploads" &&
|
|
158
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
159
|
+
node.expression.name.text === "property" &&
|
|
160
|
+
reaches(node.expression.expression, "fact", locals, namespaces)
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// `fact.property.uploads` spelled through the receiver the pool read was.
|
|
165
|
+
function uploadsLike(node, sf) {
|
|
166
|
+
return `${node.expression.getText(sf)}.property.uploads`;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function indentOf(text, pos) {
|
|
170
|
+
const lineStart = text.lastIndexOf("\n", pos - 1) + 1;
|
|
171
|
+
return /^[ \t]*/.exec(text.slice(lineStart))[0];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// The span a removed array element occupies: its own line when nothing else shares it,
|
|
175
|
+
// else the element and the comma (and space) joining it to its neighbour.
|
|
176
|
+
function elementRemoval(sf, text, literal, index, removed) {
|
|
177
|
+
const element = literal.elements[index];
|
|
178
|
+
const start = element.getStart(sf);
|
|
179
|
+
const end = element.getEnd();
|
|
180
|
+
const lineStart = text.lastIndexOf("\n", start - 1) + 1;
|
|
181
|
+
if (text.slice(lineStart, start).trim() === "") {
|
|
182
|
+
const after = text.slice(end).match(/^,?[ \t]*\n/);
|
|
183
|
+
if (after !== null) return { start: lineStart, end: end + after[0].length, insert: "" };
|
|
184
|
+
}
|
|
185
|
+
const trailing = text.slice(end).match(/^\s*,[ \t]*/);
|
|
186
|
+
if (trailing !== null && index < literal.elements.length - 1) return { start, end: end + trailing[0].length, insert: "" };
|
|
187
|
+
let previous = index - 1;
|
|
188
|
+
while (previous >= 0 && removed.has(previous)) previous -= 1;
|
|
189
|
+
return { start: previous < 0 ? start : literal.elements[previous].getEnd(), end, insert: "" };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Every identifier spelled inside `node`.
|
|
193
|
+
function namesIn(node) {
|
|
194
|
+
const names = new Set();
|
|
195
|
+
const visit = (n) => {
|
|
196
|
+
if (ts.isIdentifier(n)) names.add(n.text);
|
|
197
|
+
ts.forEachChild(n, visit);
|
|
198
|
+
};
|
|
199
|
+
visit(node);
|
|
200
|
+
return names;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function poolHandBack(sf, node, pool) {
|
|
204
|
+
return (
|
|
205
|
+
`line ${String(lineOf(sf, node.getStart(sf)))}: \`${node.getText(sf)}\` — there are no pool reads; a list of media is picked ` +
|
|
206
|
+
`(\`source: fill.pick({ brief })\` with \`item: ${POOLS[pool].item}\`) or sourced by a \`compute()\` over \`${UPLOADS}\` ` +
|
|
207
|
+
`filtered to \`${POOLS[pool].filter}\`, and a single media slot picks by its kind and \`category\``
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Rewrites one file's text; `undefined` when it reads no pool and names no row type this
|
|
213
|
+
* package exported. `isFramework` decides which import specifiers are the framework.
|
|
214
|
+
*/
|
|
215
|
+
export function rewriteSource(fileName, text, isFramework = (specifier) => specifier === CONCRETE) {
|
|
216
|
+
if (!/\b(fact|Facts(Photo|FloorPlan|Video|Tour|Document|DocumentNote))\b/.test(text)) return undefined;
|
|
217
|
+
const kind = fileName.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS;
|
|
218
|
+
const sf = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true, kind);
|
|
219
|
+
const { declarations, locals, namespaces } = frameworkImports(sf, isFramework);
|
|
220
|
+
if (declarations.length === 0) return undefined;
|
|
221
|
+
|
|
222
|
+
const edits = [];
|
|
223
|
+
const reasons = [];
|
|
224
|
+
const handled = new Set();
|
|
225
|
+
|
|
226
|
+
// A compute's reads, and the inline function reading them.
|
|
227
|
+
const rewriteCompute = (call) => {
|
|
228
|
+
const options = call.arguments[0];
|
|
229
|
+
if (options === undefined || !ts.isObjectLiteralExpression(options)) return;
|
|
230
|
+
const readsProperty = options.properties.find((p) => ts.isPropertyAssignment(p) && nameOf(p) === "reads");
|
|
231
|
+
if (readsProperty === undefined || !ts.isArrayLiteralExpression(readsProperty.initializer)) return;
|
|
232
|
+
const reads = readsProperty.initializer;
|
|
233
|
+
const fn = call.arguments[1];
|
|
234
|
+
const inline = fn !== undefined && (ts.isArrowFunction(fn) || ts.isFunctionExpression(fn)) ? fn : undefined;
|
|
235
|
+
const taken = inline === undefined ? new Set() : namesIn(inline);
|
|
236
|
+
const bindings = [];
|
|
237
|
+
reads.elements.forEach((element, index) => {
|
|
238
|
+
const pool = poolRead(element, locals, namespaces);
|
|
239
|
+
if (pool === undefined) return;
|
|
240
|
+
handled.add(element);
|
|
241
|
+
edits.push({ start: element.getStart(sf), end: element.getEnd(), insert: uploadsLike(element, sf) });
|
|
242
|
+
const line = `line ${String(lineOf(sf, element.getStart(sf)))}: \`${element.getText(sf)}\` now reads every upload's record`;
|
|
243
|
+
const narrow = `filter it to \`${POOLS[pool].filter}\``;
|
|
244
|
+
if (inline === undefined) {
|
|
245
|
+
reasons.push(`${line}, and the compute's function is not written inline — ${narrow} where the function reads it`);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (reads.elements.slice(0, index).some((e) => ts.isSpreadElement(e))) {
|
|
249
|
+
reasons.push(`${line}, after a spread the function's parameter for it cannot be found — ${narrow} where the function reads it`);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const params = inline.parameters;
|
|
253
|
+
const restBefore = params.findIndex((p) => p.dotDotDotToken !== undefined);
|
|
254
|
+
if (restBefore !== -1 && restBefore <= index) {
|
|
255
|
+
reasons.push(`${line}, into a rest parameter — ${narrow} where the function reads it`);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
const param = params[index];
|
|
259
|
+
if (param === undefined) return;
|
|
260
|
+
if (!ts.isIdentifier(param.name)) {
|
|
261
|
+
reasons.push(`${line}, into a destructured parameter — ${narrow} where the function reads it`);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
let fresh = "uploads";
|
|
265
|
+
for (let n = 2; taken.has(fresh); n += 1) fresh = `uploads${String(n)}`;
|
|
266
|
+
taken.add(fresh);
|
|
267
|
+
// The parameter now holds every record; a row type it was annotated with no longer fits.
|
|
268
|
+
edits.push({ start: param.name.getStart(sf), end: param.type === undefined ? param.name.getEnd() : param.type.getEnd(), insert: fresh });
|
|
269
|
+
bindings.push({ local: param.name.text, fresh, pool });
|
|
270
|
+
});
|
|
271
|
+
if (inline === undefined || bindings.length === 0) return;
|
|
272
|
+
|
|
273
|
+
// A member the record spells otherwise, read in a rewritten function.
|
|
274
|
+
const renamed = bindings.map((b) => POOLS[b.pool].renamed).filter((r) => r !== undefined);
|
|
275
|
+
if (renamed.length > 0) {
|
|
276
|
+
const visit = (node) => {
|
|
277
|
+
if (ts.isPropertyAccessExpression(node)) {
|
|
278
|
+
const hit = renamed.find((r) => r.member === node.name.text);
|
|
279
|
+
if (hit !== undefined) {
|
|
280
|
+
reasons.push(`line ${String(lineOf(sf, node.name.getStart(sf)))}: \`.${hit.member}\` — ${hit.record}`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
ts.forEachChild(node, visit);
|
|
284
|
+
};
|
|
285
|
+
visit(inline.body);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const indent = indentOf(text, call.getStart(sf));
|
|
289
|
+
const consts = bindings.map((b) => `const ${b.local} = ${b.fresh}.filter(${POOLS[b.pool].filter});`);
|
|
290
|
+
const body = inline.body;
|
|
291
|
+
if (ts.isBlock(body)) {
|
|
292
|
+
const first = body.statements[0];
|
|
293
|
+
if (first !== undefined && lineOf(sf, first.getStart(sf)) > lineOf(sf, body.getStart(sf))) {
|
|
294
|
+
const at = text.lastIndexOf("\n", first.getStart(sf) - 1) + 1;
|
|
295
|
+
const own = indentOf(text, first.getStart(sf));
|
|
296
|
+
edits.push({ start: at, end: at, insert: consts.map((c) => `${own}${c}\n`).join("") });
|
|
297
|
+
} else if (first === undefined && text.slice(body.getStart(sf) + 1, body.getEnd() - 1).includes("\n")) {
|
|
298
|
+
const at = body.getStart(sf) + 1;
|
|
299
|
+
edits.push({ start: at, end: at, insert: consts.map((c) => `\n${indent} ${c}`).join("") });
|
|
300
|
+
} else {
|
|
301
|
+
const at = body.getStart(sf) + 1;
|
|
302
|
+
edits.push({ start: at, end: at, insert: consts.map((c) => ` ${c}`).join("") });
|
|
303
|
+
}
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
const open = `{\n${consts.map((c) => `${indent} ${c}\n`).join("")}${indent} return `;
|
|
307
|
+
const close = `;\n${indent}}`;
|
|
308
|
+
const start = body.getStart(sf);
|
|
309
|
+
const end = body.getEnd();
|
|
310
|
+
// The body opens on the arrow's line, whichever line the expression began on.
|
|
311
|
+
const arrow = inline.equalsGreaterThanToken.getEnd();
|
|
312
|
+
const lead = /^\s*$/.test(text.slice(arrow, start)) ? arrow : start;
|
|
313
|
+
const opener = lead === arrow ? ` ${open}` : open;
|
|
314
|
+
if (ts.isParenthesizedExpression(body)) {
|
|
315
|
+
const inner = body.expression;
|
|
316
|
+
const head = text.slice(start, inner.getStart(sf));
|
|
317
|
+
const tail = text.slice(inner.getEnd(), end);
|
|
318
|
+
if (/^\(\s*$/.test(head) && /^\s*\)$/.test(tail)) {
|
|
319
|
+
edits.push({ start: lead, end: inner.getStart(sf), insert: opener });
|
|
320
|
+
edits.push({ start: inner.getEnd(), end, insert: close });
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
edits.push({ start: lead, end: start, insert: opener });
|
|
325
|
+
edits.push({ start: end, end, insert: close });
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const visit = (node) => {
|
|
329
|
+
if (ts.isCallExpression(node) && reaches(node.expression, "compute", locals, namespaces)) rewriteCompute(node);
|
|
330
|
+
|
|
331
|
+
// A pool read in any other array literal: the uploads, named once per literal.
|
|
332
|
+
if (ts.isArrayLiteralExpression(node) && node.elements.some((e) => !handled.has(e) && poolRead(e, locals, namespaces) !== undefined)) {
|
|
333
|
+
let seen = false;
|
|
334
|
+
const removed = new Set();
|
|
335
|
+
node.elements.forEach((element, index) => {
|
|
336
|
+
const pool = handled.has(element) ? undefined : poolRead(element, locals, namespaces);
|
|
337
|
+
if (pool === undefined && !isUploads(element, locals, namespaces)) return;
|
|
338
|
+
if (pool !== undefined) handled.add(element);
|
|
339
|
+
if (!seen) {
|
|
340
|
+
seen = true;
|
|
341
|
+
if (pool !== undefined) edits.push({ start: element.getStart(sf), end: element.getEnd(), insert: uploadsLike(element, sf) });
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
edits.push(elementRemoval(sf, text, node, index, removed));
|
|
345
|
+
removed.add(index);
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const pool = poolRead(node, locals, namespaces);
|
|
350
|
+
if (pool !== undefined && !handled.has(node)) {
|
|
351
|
+
handled.add(node);
|
|
352
|
+
reasons.push(poolHandBack(sf, node, pool));
|
|
353
|
+
}
|
|
354
|
+
if (ts.isQualifiedName(node) && Object.hasOwn(POOLS, node.right.text)) {
|
|
355
|
+
const left = node.left;
|
|
356
|
+
const viaFact =
|
|
357
|
+
(ts.isIdentifier(left) && locals.fact.has(left.text)) ||
|
|
358
|
+
(ts.isQualifiedName(left) && left.right.text === "fact" && ts.isIdentifier(left.left) && namespaces.has(left.left.text));
|
|
359
|
+
if (viaFact) reasons.push(poolHandBack(sf, node, node.right.text));
|
|
360
|
+
}
|
|
361
|
+
ts.forEachChild(node, visit);
|
|
362
|
+
};
|
|
363
|
+
visit(sf);
|
|
364
|
+
|
|
365
|
+
// The row types: renamed in the import and at every type reference.
|
|
366
|
+
const typeLocals = new Map();
|
|
367
|
+
const seenLocals = new Set();
|
|
368
|
+
for (const statement of declarations) {
|
|
369
|
+
const bindings = statement.importClause?.namedBindings;
|
|
370
|
+
if (bindings === undefined || !ts.isNamedImports(bindings)) continue;
|
|
371
|
+
const dropped = [];
|
|
372
|
+
for (const element of bindings.elements) {
|
|
373
|
+
const imported = (element.propertyName ?? element.name).text;
|
|
374
|
+
const target = TYPE_RENAMES[imported];
|
|
375
|
+
const aliased = element.propertyName !== undefined;
|
|
376
|
+
const local = target !== undefined && !aliased ? target : element.name.text;
|
|
377
|
+
if (target !== undefined && !aliased) typeLocals.set(element.name.text, target);
|
|
378
|
+
if (seenLocals.has(local)) {
|
|
379
|
+
dropped.push(element);
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
seenLocals.add(local);
|
|
383
|
+
if (target !== undefined) {
|
|
384
|
+
const name = element.propertyName ?? element.name;
|
|
385
|
+
edits.push({ start: name.getStart(sf), end: name.getEnd(), insert: target });
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (dropped.length === 0) continue;
|
|
389
|
+
if (dropped.length === bindings.elements.length && statement.importClause.name === undefined) {
|
|
390
|
+
const end = statement.getEnd();
|
|
391
|
+
const after = text.slice(end).match(/^[ \t]*\n/);
|
|
392
|
+
edits.push({ start: statement.getStart(sf), end: end + (after === null ? 0 : after[0].length), insert: "" });
|
|
393
|
+
continue;
|
|
394
|
+
}
|
|
395
|
+
for (const element of dropped) {
|
|
396
|
+
const index = bindings.elements.indexOf(element);
|
|
397
|
+
const removed = new Set(bindings.elements.map((e, i) => (dropped.includes(e) && i < index ? i : -1)).filter((i) => i >= 0));
|
|
398
|
+
edits.push(elementRemoval(sf, text, bindings, index, removed));
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
const renameType = (node) => {
|
|
402
|
+
if (ts.isTypeReferenceNode(node) || ts.isExpressionWithTypeArguments(node)) {
|
|
403
|
+
const name = ts.isTypeReferenceNode(node) ? node.typeName : node.expression;
|
|
404
|
+
if (ts.isIdentifier(name) && typeLocals.has(name.text)) {
|
|
405
|
+
edits.push({ start: name.getStart(sf), end: name.getEnd(), insert: typeLocals.get(name.text) });
|
|
406
|
+
} else if (ts.isQualifiedName(name) && ts.isIdentifier(name.left) && namespaces.has(name.left.text) && Object.hasOwn(TYPE_RENAMES, name.right.text)) {
|
|
407
|
+
edits.push({ start: name.right.getStart(sf), end: name.right.getEnd(), insert: TYPE_RENAMES[name.right.text] });
|
|
408
|
+
} else if (
|
|
409
|
+
ts.isPropertyAccessExpression(name) &&
|
|
410
|
+
ts.isIdentifier(name.expression) &&
|
|
411
|
+
namespaces.has(name.expression.text) &&
|
|
412
|
+
Object.hasOwn(TYPE_RENAMES, name.name.text)
|
|
413
|
+
) {
|
|
414
|
+
edits.push({ start: name.name.getStart(sf), end: name.name.getEnd(), insert: TYPE_RENAMES[name.name.text] });
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
ts.forEachChild(node, renameType);
|
|
418
|
+
};
|
|
419
|
+
for (const statement of sf.statements) if (!declarations.includes(statement)) renameType(statement);
|
|
420
|
+
|
|
421
|
+
if (edits.length === 0) return reasons.length > 0 ? { text, changed: false, reasons } : undefined;
|
|
422
|
+
|
|
423
|
+
// An edit inside a span another edit replaces (a renamed type in a dropped annotation, an
|
|
424
|
+
// element of a removed line) goes with it; an insertion is never inside one.
|
|
425
|
+
const kept = edits.filter(
|
|
426
|
+
(edit) =>
|
|
427
|
+
edit.start === edit.end ||
|
|
428
|
+
!edits.some((other) => other !== edit && other.start < other.end && other.start <= edit.start && edit.end <= other.end && (other.start < edit.start || edit.end < other.end)),
|
|
429
|
+
);
|
|
430
|
+
let out = text;
|
|
431
|
+
for (const edit of kept.sort((a, b) => b.start - a.start || b.end - b.start - (a.end - a.start))) {
|
|
432
|
+
out = out.slice(0, edit.start) + edit.insert + out.slice(edit.end);
|
|
433
|
+
}
|
|
434
|
+
reasons.sort((a, b) => Number(/^line (\d+)/.exec(a)[1]) - Number(/^line (\d+)/.exec(b)[1]));
|
|
435
|
+
return { text: out, changed: out !== text, reasons };
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/** @param {string} root @returns {Promise<{rewritten: string[], notRewritten: {file: string, reason: string}[]}>} */
|
|
439
|
+
export default async function uploadsReplacePoolReads(root) {
|
|
440
|
+
const rewritten = [];
|
|
441
|
+
const notRewritten = [];
|
|
442
|
+
for (const file of await sourceFiles(root)) {
|
|
443
|
+
const before = await readFile(file, "utf8");
|
|
444
|
+
const result = rewriteSource(file, before);
|
|
445
|
+
if (result === undefined) continue;
|
|
446
|
+
const rel = relative(root, file).split(sep).join("/");
|
|
447
|
+
if (result.changed) {
|
|
448
|
+
await writeFile(file, result.text, "utf8");
|
|
449
|
+
rewritten.push(rel);
|
|
450
|
+
}
|
|
451
|
+
for (const reason of result.reasons) notRewritten.push({ file: rel, reason });
|
|
452
|
+
}
|
|
453
|
+
return { rewritten, notRewritten };
|
|
454
|
+
}
|