@homepages/concrete 6.2.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/CHANGELOG.md +133 -0
  2. package/codemods/manifest.json +13 -0
  3. package/codemods/object-form-only.mjs +39 -0
  4. package/codemods/steps/list-object-form.mjs +688 -0
  5. package/codemods/steps/select-object-form.mjs +210 -0
  6. package/dist/artifact/playground/client/assets/index-D8eepVr-.js +1101 -0
  7. package/dist/artifact/playground/client/index.html +1 -1
  8. package/dist/artifact/playground/host.mjs +14 -14
  9. package/dist/asset-modules.d.ts +2 -1
  10. package/dist/cli/check/stages/render.js +1 -1
  11. package/dist/cli/check/stages/sections.js +1 -1
  12. package/dist/fixtures/canonical.d.ts +2 -5
  13. package/dist/fixtures/media.js +11 -25
  14. package/dist/fixtures/property.js +28 -16
  15. package/dist/fixtures/resolve.js +31 -17
  16. package/dist/fixtures/rows.js +3 -83
  17. package/dist/fixtures.d.ts +17 -9
  18. package/dist/index.d.ts +9 -9
  19. package/dist/packages/external/concrete/package.js +1 -1
  20. package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +31 -8
  21. package/dist/packages/internal/fill-bake/dist/derive-source.js +15 -4
  22. package/dist/packages/internal/fill-bake/dist/index.js +2 -2
  23. package/dist/packages/internal/fill-vocabulary/dist/origination.js +6 -1
  24. package/dist/packages/internal/fill-vocabulary/dist/row-reads.js +15 -0
  25. package/dist/packages/internal/property-facts/dist/index.js +1 -1
  26. package/dist/packages/internal/property-facts/dist/{property-facts-5pxZnlkh.js → property-facts-Cy7-O4p0.js} +2 -5
  27. package/dist/packages/internal/section-contracts/dist/catalog.js +0 -4
  28. package/dist/packages/internal/section-contracts/dist/choose-select-contract.js +4 -4
  29. package/dist/packages/internal/section-contracts/dist/fill-spec-view.js +5 -1
  30. package/dist/packages/internal/section-contracts/dist/group-contract.js +1 -3
  31. package/dist/packages/internal/section-contracts/dist/index.js +0 -1
  32. package/dist/packages/internal/section-contracts/dist/list-fill-contract.js +3 -3
  33. package/dist/packages/internal/section-contracts/dist/list-scalar-contract.js +1 -5
  34. package/dist/packages/internal/section-contracts/dist/name-title-contract.js +2 -2
  35. package/dist/packages/internal/section-contracts/dist/pooling-field-contract.js +3 -1
  36. package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +14 -0
  37. package/dist/packages/internal/section-contracts/dist/runners.js +0 -5
  38. package/dist/packages/internal/section-contracts/dist/source-contract.js +80 -4
  39. package/dist/packages/internal/section-contracts/dist/writer-reads-fact-contract.js +12 -6
  40. package/dist/packages/internal/source-resolution/dist/index.js +57 -20
  41. package/dist/packages/internal/template-contracts/dist/facts-view.d.ts +16 -17
  42. package/dist/packages/internal/template-contracts/dist/facts-view.js +6 -18
  43. package/dist/packages/internal/template-contracts/dist/row-sources.js +26 -0
  44. package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +362 -380
  45. package/dist/packages/internal/template-contracts/dist/slot-catalog.js +289 -289
  46. package/dist/primitives/slot-bindings.d.ts +7 -40
  47. package/dist/primitives/slot-bindings.js +10 -12
  48. package/dist/schema/define-schema.d.ts +1 -1
  49. package/dist/schema/define-schema.js +13 -1
  50. package/dist/schema/extract-fill-spec.js +15 -13
  51. package/dist/schema/fact.d.ts +2 -19
  52. package/dist/schema/fill-builders.d.ts +4 -3
  53. package/dist/schema/fill-spec.js +9 -1
  54. package/dist/schema/layout.d.ts +6 -8
  55. package/dist/schema/layout.js +3 -9
  56. package/dist/schema/property-facts.d.ts +16 -47
  57. package/dist/schema/row-fields.js +88 -0
  58. package/dist/schema/row-ref.d.ts +59 -0
  59. package/dist/schema/row-ref.js +28 -0
  60. package/dist/schema/runtime-values.d.ts +8 -13
  61. package/dist/schema/section-props.d.ts +19 -26
  62. package/dist/schema/section-schema.d.ts +6 -6
  63. package/dist/schema/section-schema.js +2 -2
  64. package/dist/schema/slot-builders.d.ts +222 -117
  65. package/dist/schema/slot-builders.js +57 -28
  66. package/dist/schema/slot-ref.d.ts +18 -2
  67. package/dist/schema/slot-ref.js +11 -3
  68. package/dist/schema/slot-types.d.ts +7 -7
  69. package/dist/schema/slot-types.js +55 -19
  70. package/dist/section/declare.d.ts +1 -1
  71. package/dist/section/section.d.ts +3 -3
  72. package/dist/template/logic-shim.d.ts +1 -1
  73. package/guide/reference/cli/INDEX.md +2 -2
  74. package/guide/reference/cli/build.md +1 -1
  75. package/guide/reference/cli/check.md +1 -1
  76. package/guide/reference/cli/dev.md +1 -1
  77. package/guide/reference/cli/property-add.md +1 -1
  78. package/guide/reference/cli/property-list.md +1 -1
  79. package/guide/reference/cli/publish.md +1 -1
  80. package/guide/reference/cli/upgrade.md +1 -1
  81. package/guide/reference/rules/INDEX.md +1 -2
  82. package/package.json +1 -1
  83. package/tsconfig.base.json +1 -0
  84. package/dist/artifact/playground/client/assets/index-Cqz-jjVw.js +0 -1101
  85. package/dist/packages/internal/section-contracts/dist/row-contract.js +0 -37
  86. package/dist/packages/internal/template-contracts/dist/layout.js +0 -10
@@ -1,46 +1,13 @@
1
- import { CollectionField } from "../packages/internal/template-contracts/dist/slot-catalog.js";
2
- import { CollectionRowValues } from "../schema/fact.js";
3
1
  import { SectionSchemaShape } from "../schema/section-schema.js";
4
- import { RowValue, SlotValue } from "../schema/section-props.js";
2
+ import { SlotValue } from "../schema/section-props.js";
5
3
  //#region src/primitives/slot-bindings.d.ts
6
4
  /**
7
- * The value shape a binding holds after bind-time normalization: `SlotValue`
8
- * for every kind except a RECORD list, whose bound rows carry the
9
- * editor-stamped `id` plus each DECLARED field, normalized by its definition.
10
- *
11
- * A stored record list's row (`RowValue`) is closed: anything else on it is
12
- * dropped. A record list bound whole-row to a collection
13
- * (`source: fact.property.comparables`) is the other case, because a section's
14
- * render receives bindings and nothing else: its bound row
15
- * ({@link BoundBakedRow}) also keeps every member the platform bakes onto the
16
- * row, so markup reads a comparable's `status` or `lat` off
17
- * `slot.comps.value[n]` (or `bindItems(slot.comps)[n].value`) without
18
- * declaring it as a row field.
19
- */
20
- type BoundSlotValue<D> = D extends {
21
- type: "list";
22
- source: {
23
- kind: "direct";
24
- field: infer F extends CollectionField;
25
- };
26
- fields: infer I;
27
- } ? BoundBakedRow<F, I>[] : D extends {
28
- type: "list";
29
- fields: infer I;
30
- } ? RowValue<I>[] : SlotValue<D>;
31
- type ProjectedImageListKeys<F extends CollectionField, I> = { [K in keyof I & keyof CollectionRowValues[F]]: I[K] extends {
32
- type: "image";
33
- } ? CollectionRowValues[F][K] extends readonly unknown[] ? K : never : never; }[keyof I & keyof CollectionRowValues[F]];
34
- /**
35
- * One bound row of a whole-row-baked record list: every member the collection projects
36
- * onto each row whatever the slot declares (a unit's or comparable's whole record, a
37
- * contact's `id` alone), with each DECLARED field at its normalized kind — except a declared
38
- * `image` field the projection carries as a list (a unit's `floor_plans`, its ordered
39
- * floor-plan assignments), which keeps the projection's list. That field's own
40
- * `FieldBinding` still holds the `image` kind's value, so the primitives read it
41
- * exactly as before.
5
+ * The value shape a binding holds after bind-time normalization — the slot's own
6
+ * `SlotValue`. A record list's bound row is its identity plus each DECLARED field
7
+ * normalized by its definition, and nothing else: a member no field declares is not
8
+ * on the row, whether the row was stored or baked from a collection.
42
9
  */
43
- type BoundBakedRow<F extends CollectionField, I> = Omit<CollectionRowValues[F], keyof I | "id"> & Omit<RowValue<I>, ProjectedImageListKeys<F, I>> & { [K in ProjectedImageListKeys<F, I>]: CollectionRowValues[F][K]; };
10
+ type BoundSlotValue<D> = SlotValue<D>;
44
11
  /**
45
12
  * One slot: its id, the definition the section declared for it, and its runtime value.
46
13
  *
@@ -120,4 +87,4 @@ declare function bindItems<D extends {
120
87
  type: "list";
121
88
  }>(binding: SlotBinding<D> | FieldBinding<D>): ItemBinding<D>[];
122
89
  //#endregion
123
- export { BoundBakedRow, BoundSlotValue, FieldBinding, ItemBinding, RowBinding, SlotBinding, SlotBindingMap, bindItems };
90
+ export { BoundSlotValue, FieldBinding, ItemBinding, RowBinding, SlotBinding, SlotBindingMap, bindItems };
@@ -1,4 +1,4 @@
1
- import { acceptsLink } from "../packages/internal/template-contracts/dist/slot-catalog.js";
1
+ import { COLLECTIONS, acceptsLink } from "../packages/internal/template-contracts/dist/slot-catalog.js";
2
2
 
3
3
  //#region src/primitives/slot-bindings.ts
4
4
  const blankVideo = () => ({
@@ -70,18 +70,16 @@ function normalizeTour(value) {
70
70
  alt: stringField(value.alt)
71
71
  };
72
72
  }
73
- function normalizeRow(fields, row, baked) {
73
+ function normalizeRow(fields, row, idKey) {
74
74
  const source = isRecord(row) ? row : {};
75
- const normalized = {
76
- ...baked ? source : {},
77
- id: stringField(source.id)
78
- };
79
- for (const [field, def] of Object.entries(fields)) {
80
- const value = source[field];
81
- normalized[field] = def.type === "image" && Array.isArray(value) ? value.filter(isRecord) : normalizeValue(def, value);
82
- }
75
+ const normalized = { [idKey]: stringField(source[idKey]) };
76
+ for (const [field, def] of Object.entries(fields)) normalized[field] = normalizeValue(def, source[field]);
83
77
  return normalized;
84
78
  }
79
+ function rowIdKey(source) {
80
+ if (!isRecord(source) || source.kind !== "direct" || typeof source.field !== "string") return "id";
81
+ return Object.hasOwn(COLLECTIONS, source.field) ? COLLECTIONS[source.field].idKey : "id";
82
+ }
85
83
  function normalizeValue(def, value) {
86
84
  const slot = def;
87
85
  switch (slot.type) {
@@ -98,8 +96,8 @@ function normalizeValue(def, value) {
98
96
  if (!Array.isArray(value)) return [];
99
97
  if (isRecord(slot.fields)) {
100
98
  const fields = slot.fields;
101
- const baked = isRecord(slot.source) && slot.source.kind === "direct";
102
- return value.map((row) => normalizeRow(fields, row, baked));
99
+ const idKey = rowIdKey(slot.source);
100
+ return value.map((row) => normalizeRow(fields, row, idKey));
103
101
  }
104
102
  if (slot.element == null) return value;
105
103
  const element = slot.element;
@@ -4,7 +4,7 @@ import { DisplayEntryInput } from "./slot-builders.js";
4
4
  //#region src/schema/define-schema.d.ts
5
5
  /**
6
6
  * The authored `display:` block: section `visibility` and `variant`, each an
7
- * optional entry built by the `select(cases, opts)` display overload. Omitting
7
+ * optional entry built by `select({ options: cases, … })` with no `label`. Omitting
8
8
  * the block, or either entry, reproduces the defaults — always shown, no
9
9
  * variant.
10
10
  */
@@ -82,10 +82,22 @@ function defineSchema(input) {
82
82
  };
83
83
  const slots = {};
84
84
  for (const [key, slot] of Object.entries(input.slots)) {
85
+ if (slot.type !== "list" && slot.unique !== void 0) throw new Error(`defineSchema: slot "${key}" declares \`unique\` — it is legal only inside a list, on its item or a row field.`);
85
86
  let emitted = resolveFillReads(key, slot, resolveReads);
86
87
  const fields = emitted.fields;
87
88
  if (emitted.type === "list" && fields !== void 0) {
88
- const resolvedFields = Object.fromEntries(Object.entries(fields).map(([field, def]) => [field, resolveFillReads(`${key}.${field}`, def, resolveReads)]));
89
+ const resolvedFields = Object.fromEntries(Object.entries(fields).map(([field, def]) => {
90
+ const at = `${key}.${field}`;
91
+ let resolved = resolveFillReads(at, def, resolveReads);
92
+ if (isComputeBinding(def.source)) {
93
+ computed[at] = def.source.fn;
94
+ resolved = {
95
+ ...resolved,
96
+ source: derivedSource(at, resolveReads(at, def.source.reads))
97
+ };
98
+ }
99
+ return [field, resolved];
100
+ }));
89
101
  if (Object.keys(fields).some((field) => resolvedFields[field] !== fields[field])) emitted = {
90
102
  ...emitted,
91
103
  fields: resolvedFields
@@ -1,6 +1,6 @@
1
1
  import { DISPLAY_ENTRIES } from "../packages/internal/template-contracts/dist/slot-catalog.js";
2
2
  import { getFill, getFillSection } from "./fill-declaration.js";
3
- import { isSiblingSlot, serializeRef } from "./slot-ref.js";
3
+ import { isSerializedSlotRef, isSiblingSlot, serializeRef } from "./slot-ref.js";
4
4
  import { byCodeUnit } from "../platform/order.js";
5
5
  import { plannerForField } from "../packages/internal/fill-vocabulary/dist/row-planners.js";
6
6
  import { isListSlot, originationFor } from "../packages/internal/fill-vocabulary/dist/origination.js";
@@ -31,31 +31,33 @@ function serializedReads(reads) {
31
31
  function collectReads(into, binding) {
32
32
  const ownSection = getFillSection(binding);
33
33
  for (const read of serializedReads(binding?.reads)) if (read.kind === "fact") into.facts.add(read.key);
34
- else if (read.section !== ownSection) into.slots.set(`${read.section} ${read.slot}`, read);
34
+ else if (isSerializedSlotRef(read) && read.section !== ownSection) into.slots.set(`${read.section} ${read.slot}`, read);
35
35
  }
36
36
  function editorPickedOrigin(slot) {
37
37
  return slot.type === "poi";
38
38
  }
39
39
  function assertOrigin(key, slot) {
40
- if (slot.source !== void 0) return;
40
+ if (slot.source !== void 0 || getFill(slot) !== void 0) return;
41
41
  if (editorPickedOrigin(slot)) return;
42
42
  throw new Error(`fillSpecFromSchema: slot "${key}" declares no \`source:\` — nothing would ever write it. Bind it to a fact or a slot, \`compute()\` it, or \`fill()\` it.`);
43
43
  }
44
+ function assertRowOrigins(key, slot) {
45
+ for (const [fieldKey, field] of Object.entries(slot.fields ?? {})) {
46
+ if (field.source !== void 0 || getFill(field) !== void 0) continue;
47
+ throw new Error(`fillSpecFromSchema: row field "${key}.${fieldKey}" declares no \`source:\` — nothing would ever write it. Bind it to a member of the row (\`row.<member>\`), \`compute()\` it, or \`fill()\` it.`);
48
+ }
49
+ }
44
50
  function unkeyedMessage(key, origination) {
45
51
  if (origination.pools.length > 1) return `fillSpecFromSchema: record slot "${key}" pools rows from ${origination.pools.map((p) => `"${p}"`).join(" and ")} — a filled record list picks its rows out of ONE asset field, so bind the others with \`source:\` or drop them.`;
46
- if (origination.title !== void 0) return `fillSpecFromSchema: record slot "${key}" is titled by "${origination.title}"` + (origination.titleType === void 0 ? ", which is not a field of the row" : `, a ${origination.titleType} field`) + " — a filled record list is keyed on its `title:` field, which must be a `text` field the model writes or a `select.of([...])` it picks from.";
47
- return `fillSpecFromSchema: record slot "${key}" has no field to key its rows on — title the list by the \`text\` field that names a row, give the row exactly one \`select.of([...])\` field, or give it one unbound \`image\`/\`video\`/\`tour\`/\`document\` field to pick rows from.`;
52
+ if (origination.title !== void 0) return `fillSpecFromSchema: record slot "${key}" is titled by "${origination.title}"` + (origination.titleType === void 0 ? ", which is not a field of the row" : `, a ${origination.titleType} field`) + " — a filled record list is keyed on its `title:` field, which must be a `text` field the model writes or a `select({ options })` it picks from.";
53
+ return `fillSpecFromSchema: record slot "${key}" has no field to key its rows on — title the list by the \`text\` field that names a row, give the row exactly one \`select({ options })\` field, or give it one unbound \`image\`/\`video\`/\`tour\`/\`document\` field to pick rows from.`;
48
54
  }
49
55
  function rowFieldDecision(key, fieldKey, field, binding) {
50
56
  if (plannerForField(field) === void 0) throw new Error(`fillSpecFromSchema: row field "${key}.${fieldKey}" (type "${String(field.type)}") is filled, but a row cannot fill one — a row field is written or picked inside the list's one batched call, which plans text, a select key, an asset, or a list of text, keys or assets.`);
51
57
  return optionsOf(binding);
52
58
  }
53
- function assertKeyFieldTakesNoFill(key, slot, origination) {
54
- if (origination.kind !== "keyed-rows" || origination.keys !== "written") return;
55
- if (getFill(slot.fields?.[origination.keyField]) === void 0) return;
56
- throw new Error(`fillSpecFromSchema: slot "${key}" keys rows by "${origination.keyField}", which is filled itself — the list's own fill writes each row's name into that field, so drop the field's fill and say the name's shape in the list's brief.`);
57
- }
58
59
  function recordListDecision(key, slot, reads) {
60
+ assertRowOrigins(key, slot);
59
61
  const fields = {};
60
62
  for (const [fieldKey, rowField] of Object.entries(slot.fields ?? {})) {
61
63
  const binding = getFill(rowField);
@@ -69,7 +71,7 @@ function recordListDecision(key, slot, reads) {
69
71
  assertOrigin(key, slot);
70
72
  return;
71
73
  }
72
- const origination = originationFor(slot);
74
+ const origination = originationFor(slot, Object.keys(fields));
73
75
  if (binding === void 0) {
74
76
  if (origination?.kind === "bound-rows") return {
75
77
  id: key,
@@ -81,7 +83,6 @@ function recordListDecision(key, slot, reads) {
81
83
  }
82
84
  if (origination?.kind === "unkeyed-rows") throw new Error(unkeyedMessage(key, origination));
83
85
  if (origination === void 0) throw new Error(`fillSpecFromSchema: record slot "${key}" originates no rows.`);
84
- assertKeyFieldTakesNoFill(key, slot, origination);
85
86
  return {
86
87
  id: key,
87
88
  kind: "list",
@@ -115,7 +116,8 @@ function displayDecision(schema, reads) {
115
116
  for (const entry of entries) {
116
117
  const binding = getFill(display[entry]?.fill);
117
118
  collectReads(reads, binding);
118
- for (const read of serializedReads(binding?.reads)) declared.set(read.kind === "fact" ? `fact ${read.key}` : `slot ${read.section} ${read.slot}`, read);
119
+ for (const read of serializedReads(binding?.reads)) if (read.kind === "fact") declared.set(`fact ${read.key}`, read);
120
+ else if (isSerializedSlotRef(read)) declared.set(`slot ${read.section} ${read.slot}`, read);
119
121
  }
120
122
  if (DISPLAY_DECISION_ID in schema.slots) throw new Error(`fillSpecFromSchema: slot "${DISPLAY_DECISION_ID}" collides with the decision id reserved for \`meta.display\`'s own fill — rename the slot.`);
121
123
  return {
@@ -1,26 +1,9 @@
1
1
  import { FACT_GRAPH, FactGraphName, SOURCE_FIELDS, SourceFieldContainer, SourceFieldName } from "../packages/internal/template-contracts/dist/slot-catalog.js";
2
- import { FactValue } from "../packages/internal/template-contracts/dist/facts-view.js";
3
- import { ComparableRow, UnitRow } from "./property-facts.js";
4
- import { ContactRow } from "./runtime-values.js";
5
2
  import { FactRef } from "./slot-ref.js";
3
+ import { FactValue } from "../packages/internal/template-contracts/dist/facts-view.js";
6
4
  //#region src/schema/fact.d.ts
7
5
  type SourceFields = typeof SOURCE_FIELDS;
8
6
  type Graph = typeof FACT_GRAPH;
9
- /**
10
- * The members each bakeable fact array projects onto every row, whatever the
11
- * slot declares — one entry per collection a record list may bind whole-row
12
- * (`source: fact.property.units` / `fact.property.contacts`). `SlotValue` uses
13
- * the bound collection's entry as the base row type for such a slot and adds
14
- * the declared fields the base does not carry, so `SectionProps` types its rows
15
- * as the projection the renderer actually receives. A unit or comparable row
16
- * carries its whole record; a contact row carries only its `id`, every other
17
- * member being a declared field.
18
- */
19
- type CollectionRowValues = {
20
- units: UnitRow;
21
- contacts: ContactRow;
22
- comparables: ComparableRow;
23
- };
24
7
  /**
25
8
  * A slot's `direct` binding: the canonical field itself, writable when the catalog
26
9
  * gives it a writeback — and a typed {@link FactRef} on the very same two runtime
@@ -77,4 +60,4 @@ type FactNamespace = { [C in SourceFieldContainer]: FieldsIn<C> & ProjectionsIn<
77
60
  */
78
61
  declare const fact: FactNamespace;
79
62
  //#endregion
80
- export { CollectionRowValues, DerivedFactRef, DirectFactRef, FactNamespace, fact };
63
+ export { DerivedFactRef, DirectFactRef, FactNamespace, fact };
@@ -71,8 +71,8 @@ type NoOtherKeys<O> = { [K in Exclude<keyof O, keyof FillInput>]: never; };
71
71
  /**
72
72
  * The model produces this slot's value, once, from `brief` and exactly the refs in
73
73
  * `reads`. What it does is the slot's own fact — a `text` slot is written, an
74
- * `image` picked from the property's photos, a `list.of(image())` a subset of them,
75
- * a record list keyed by its `title:` field originated row by row — so one builder
74
+ * `image` picked from the property's photos, a `list({ item: image() })` a subset of them,
75
+ * a record list's set of rows, each row field then filled by its own `fill()` — so one builder
76
76
  * serves every slot, and only the options differ:
77
77
  *
78
78
  * | Option | Legal on |
@@ -99,9 +99,10 @@ type NoOtherKeys<O> = { [K in Exclude<keyof O, keyof FillInput>]: never; };
99
99
  * }),
100
100
  * });
101
101
  *
102
- * list.of(image({ label: "Photo" }), {
102
+ * list({
103
103
  * label: "Gallery",
104
104
  * max: 8,
105
+ * item: image({ label: "Photo" }),
105
106
  * source: fill({
106
107
  * brief: "Every photograph of the property, ordered as a walk through it. Drop anything that is not a photograph of the property; when nothing is, produce nothing.",
107
108
  * none: true,
@@ -11,7 +11,15 @@ const FactReadRef = z.object({
11
11
  kind: z.literal("fact"),
12
12
  key: z.string().min(1)
13
13
  }).strict();
14
- const DecisionReads = z.array(z.union([FactReadRef, SlotReadRef])).min(1).optional();
14
+ const RowReadRef = z.object({
15
+ kind: z.literal("row"),
16
+ field: z.string().min(1)
17
+ }).strict();
18
+ const DecisionReads = z.array(z.union([
19
+ FactReadRef,
20
+ RowReadRef,
21
+ SlotReadRef
22
+ ])).min(1).optional();
15
23
  const Brief = z.string().min(1);
16
24
  const Abstention = z.literal(true).optional();
17
25
  const Count = z.union([
@@ -1,9 +1,7 @@
1
1
  //#region src/schema/layout.d.ts
2
- /** One layout row: a slot key (full-width) or a `[a, b]` 2-up pair, keyed to real slots. */
3
- type LayoutRow<K extends string> = K | readonly [K, K];
4
2
  /**
5
3
  * A sidebar grouping card produced by `group(...)`. Structurally an object, so it
6
- * is distinguishable at runtime from a bare `LayoutRow` (a string or array).
4
+ * is distinguishable at runtime from a bare slot key.
7
5
  *
8
6
  * `Id` is always a literal: `group` takes the id as its first argument, so every
9
7
  * card's id is known at compile time — that literal is the key a Renderer reads
@@ -12,10 +10,10 @@ type LayoutRow<K extends string> = K | readonly [K, K];
12
10
  interface GroupCard<K extends string, Id extends string = string> {
13
11
  id: Id;
14
12
  label: string;
15
- members: readonly LayoutRow<K>[];
13
+ members: readonly K[];
16
14
  }
17
- /** A section-level layout entry: a bare row or a `group(...)` card. */
18
- type SectionLayoutEntry<K extends string> = LayoutRow<K> | GroupCard<K>;
15
+ /** A section-level layout entry: a bare slot key or a `group(...)` card. */
16
+ type SectionLayoutEntry<K extends string> = K | GroupCard<K>;
19
17
  /**
20
18
  * One `meta.groups` entry as emitted from a `group(...)` card: `SlotGroupDefShape`
21
19
  * with the card's id kept literal. That literal is what keeps `bindGroups` over a
@@ -24,9 +22,9 @@ type SectionLayoutEntry<K extends string> = LayoutRow<K> | GroupCard<K>;
24
22
  interface GroupDefOf<Id extends string> {
25
23
  id: Id;
26
24
  label: string;
27
- members: (string | [string, string])[];
25
+ members: string[];
28
26
  }
29
27
  /** The union of group ids a section layout declares; `never` when it holds no cards. */
30
28
  type GroupIdsOfLayout<L extends readonly unknown[]> = Extract<L[number], GroupCard<string, string>>["id"];
31
29
  //#endregion
32
- export { GroupCard, GroupDefOf, GroupIdsOfLayout, LayoutRow, SectionLayoutEntry };
30
+ export { GroupCard, GroupDefOf, GroupIdsOfLayout, SectionLayoutEntry };
@@ -1,20 +1,14 @@
1
1
  //#region src/schema/layout.ts
2
2
  function isGroupCard(entry) {
3
- return typeof entry === "object" && entry !== null && !Array.isArray(entry);
3
+ return typeof entry === "object" && entry !== null;
4
4
  }
5
5
  function groupsFromLayout(layout) {
6
6
  return layout.filter(isGroupCard).map((card) => ({
7
7
  id: card.id,
8
8
  label: card.label,
9
- members: toMembers(card.members)
9
+ members: [...card.members]
10
10
  }));
11
11
  }
12
- function itemLayoutFromRows(rows) {
13
- return toMembers(rows);
14
- }
15
- function toMembers(rows) {
16
- return rows.map((row) => typeof row === "string" ? row : [row[0], row[1]]);
17
- }
18
12
 
19
13
  //#endregion
20
- export { groupsFromLayout, itemLayoutFromRows };
14
+ export { groupsFromLayout };
@@ -1,4 +1,3 @@
1
- import { ResponsiveImage } from "../packages/internal/image-descriptor/dist/index.js";
2
1
  //#region src/schema/property-facts.d.ts
3
2
  /** A geocoded point: latitude and longitude. */
4
3
  type Coordinates = {
@@ -7,53 +6,20 @@ type Coordinates = {
7
6
  };
8
7
  /**
9
8
  * The property's always-on prose description — the substrate every text
10
- * decision is grounded in, and a fact a `compute()` reads directly. A true
11
- * canonical mirror, like `address`: `""` is a real state (nothing written
12
- * yet), never a placeholder.
9
+ * decision is grounded in, and a fact a `compute()` reads directly. `""` is a
10
+ * real state (nothing written yet), never a placeholder.
13
11
  */
14
12
  type Narrative = {
15
13
  description: string;
16
14
  };
17
- /**
18
- * One floor plan attached to a unit, in the fixture/render-time view.
19
- * `url`/`alt`/`responsive` are ATTACHED at render time by a resolution step —
20
- * absent here means "not yet resolved", never "no plan".
21
- */
22
- type FloorplanAssignment = {
23
- id: string;
24
- upload_id?: string;
25
- url?: string;
26
- alt?: string;
27
- floor_label: string | null;
28
- position: number;
29
- responsive?: ResponsiveImage | null;
30
- };
31
- /**
32
- * One property unit in the fixture/render-time view: its scalar facts plus
33
- * its AI-generated `description`/`features` — baked into content by the
34
- * floorplan section's per-unit fill decision, not aggregated from any
35
- * canonical field — and its attached `floor_plans`.
36
- */
37
- type UnitRow = {
38
- unit_id: string;
39
- unit_label: string | null;
40
- beds: number | null;
41
- baths: number | null;
42
- sqft: number | null;
43
- price: string | null;
44
- description: string | null;
45
- features: string[];
46
- position: number;
47
- floor_plans: FloorplanAssignment[];
48
- };
49
15
  /**
50
16
  * One comparable property — a recently sold or currently listed home similar
51
- * to the subject — as the canonical fact bundle carries it. A true canonical
52
- * mirror, like `address` and `contacts`: a `compute()` reads these rows to
53
- * derive every market number a slide shows, so a fixture states them in the
54
- * same shape. `address`, `distance_m` and `price_period` are the three members
17
+ * to the subject — as the canonical fact bundle carries it: the row a
18
+ * `compute()` reading `fact.property.comparables` derives market numbers from.
19
+ * Not a bound record list's row, which is its `id` plus the fields the list
20
+ * declares. `address`, `distance_m` and `price_period` are the three members
55
21
  * the live projection derives (the display line, meters from the subject, and
56
- * what the price is denominated in); a fixture states them directly.
22
+ * what the price is denominated in).
57
23
  */
58
24
  type ComparableRow = {
59
25
  id: string;
@@ -75,9 +41,14 @@ type ComparableRow = {
75
41
  beds: number | null;
76
42
  baths: number | null;
77
43
  sqft: number | null;
78
- photo_url: string | null;
79
- source_url: string | null;
80
- source_name: string | null;
44
+ /**
45
+ * The comp's photo: the id of an upload the comparable itself owns — never one of the
46
+ * property's own photos, so no media pool offers it. `null` when none was uploaded. A
47
+ * section draws it through an `image` value built from the id,
48
+ * `{ photo_id: comp.photo_upload_id, url: "", alt: comp.address }`, and the render
49
+ * attaches the served URL and ladder by `photo_id`, as it does for any image.
50
+ */
51
+ photo_upload_id: string | null;
81
52
  /** The year the comparable was built. */
82
53
  year_built?: number | null;
83
54
  /** Lot size in square feet. */
@@ -87,8 +58,6 @@ type ComparableRow = {
87
58
  units?: number | null;
88
59
  /** Monthly HOA dues in dollars. */
89
60
  hoa_monthly?: number | null;
90
- /** How long the listing has been up. Live listings only; null on a closed sale. */
91
- days_on_market?: number | null;
92
61
  /** The asking price in dollars, beside `price` — the pair is what "sold over asking" reads. */
93
62
  list_price?: number | null;
94
63
  /** ISO `YYYY-MM-DD` — when the listing went live, not when it closed. */
@@ -100,4 +69,4 @@ type ComparableRow = {
100
69
  property_type?: "single_family" | "condo_townhome" | "multi_family" | "investment" | null;
101
70
  };
102
71
  //#endregion
103
- export { ComparableRow, Coordinates, FloorplanAssignment, Narrative, UnitRow };
72
+ export { ComparableRow, Coordinates, Narrative };
@@ -0,0 +1,88 @@
1
+ import { isComputeBinding } from "./compute.js";
2
+ import { FILL, getFill } from "./fill-declaration.js";
3
+ import { isFactRef, isRowRef } from "./slot-ref.js";
4
+ import { boundCollection, collectionMembers } from "./row-ref.js";
5
+
6
+ //#region src/schema/row-fields.ts
7
+ function rowKindOf(source) {
8
+ if (boundCollection(source) !== void 0) return "collection";
9
+ if (source === void 0 || getFillLike(source)) return "own";
10
+ return "value";
11
+ }
12
+ function getFillLike(source) {
13
+ return typeof source === "object" && source !== null && source.kind === "fill";
14
+ }
15
+ function resolveRead(at, read, r, filled) {
16
+ const own = r.byConst.get(read);
17
+ if (own === void 0) return read;
18
+ if (r.rowKind !== "own") throw new Error(`list: row field "${r.list}.${at.key}" reads the row's field "${own.key}" — a row whose source is a collection, a \`compute()\` or a slot offers its members, so read the member \`row.<member>\` instead.`);
19
+ if (own.index >= at.index) {
20
+ const which = own.index === at.index ? "itself" : `"${own.key}", which comes after it`;
21
+ throw new Error(`list: row field "${r.list}.${at.key}" reads ${which} — a row is filled top to bottom in one call, so a field reads only the fields declared before it.`);
22
+ }
23
+ if (filled && own.field.source !== void 0) throw new Error(`list: row field "${r.list}.${at.key}" is filled and reads "${own.key}", which is sourced — a sourced field settles after every fill has run, so the fill would read nothing. Read what that field reads instead.`);
24
+ return {
25
+ kind: "row",
26
+ field: own.key
27
+ };
28
+ }
29
+ function resolveReads(at, reads, r, filled) {
30
+ if (!reads.some((read) => r.byConst.has(read))) return void 0;
31
+ return reads.map((read) => resolveRead(at, read, r, filled));
32
+ }
33
+ function assertRowOrigin(at, field, r) {
34
+ const source = field.source;
35
+ if (isFactRef(source)) throw new Error(`list: row field "${at}" is bound to the fact "${source.field}", which is the same value in every row — bind the row's own member (\`row.<member>\`) instead; \`fact.unit.*\` and \`fact.contact.*\` name the primary row. A property fact belongs in the field's \`fill()\` or \`compute()\` \`reads\`.`);
36
+ if (!isRowRef(source)) return;
37
+ if (r.rowKind === "own") throw new Error(`list: row field "${at}" is bound to the row member "${source.field}", but an AI-built row has no members — fill the field.`);
38
+ }
39
+ function resolveRowFields(list, source, declared) {
40
+ const entries = Object.entries(declared);
41
+ const byConst = new Map(entries.map(([key, field], index) => [field, {
42
+ key,
43
+ index,
44
+ field
45
+ }]));
46
+ const r = {
47
+ list,
48
+ rowKind: rowKindOf(source),
49
+ byConst
50
+ };
51
+ const members = boundCollection(source);
52
+ const offered = members === void 0 ? void 0 : new Set(collectionMembers(members));
53
+ const out = {};
54
+ entries.forEach(([key, field], index) => {
55
+ const at = {
56
+ key,
57
+ index
58
+ };
59
+ assertRowOrigin(`${list}.${key}`, field, r);
60
+ const source = field.source;
61
+ if (offered !== void 0 && isRowRef(source) && !offered.has(source.field)) throw new Error(`list: row field "${list}.${key}" is bound to "${source.field}", which is not a member of the list's row.`);
62
+ let resolved = field;
63
+ const binding = getFill(field);
64
+ const fillReads = binding?.reads === void 0 ? void 0 : resolveReads(at, binding.reads, r, true);
65
+ if (fillReads !== void 0) resolved = {
66
+ ...resolved,
67
+ [FILL]: {
68
+ ...binding,
69
+ reads: fillReads
70
+ }
71
+ };
72
+ if (isComputeBinding(source)) {
73
+ const computeReads = resolveReads(at, source.reads, r, false);
74
+ if (computeReads !== void 0) resolved = {
75
+ ...resolved,
76
+ source: {
77
+ ...source,
78
+ reads: computeReads
79
+ }
80
+ };
81
+ }
82
+ out[key] = resolved;
83
+ });
84
+ return out;
85
+ }
86
+
87
+ //#endregion
88
+ export { resolveRowFields };
@@ -0,0 +1,59 @@
1
+ import { COLLECTIONS, CollectionField, FACT_GRAPH } from "../packages/internal/template-contracts/dist/slot-catalog.js";
2
+ import { FillBinding } from "./fill-builders.js";
3
+ import { RowRef, SiblingSlot, SlotRef } from "./slot-ref.js";
4
+ import { ComputeBinding } from "./compute.js";
5
+ import { ImageValue } from "./runtime-values.js";
6
+ import { SlotValue } from "./section-props.js";
7
+ //#region src/schema/row-ref.d.ts
8
+ type Graph = typeof FACT_GRAPH;
9
+ /** The identity key a collection's baked rows carry — `COLLECTIONS[c].idKey`. */
10
+ type CollectionIdKey<C extends CollectionField> = (typeof COLLECTIONS)[C]["idKey"];
11
+ /** A collection's row descriptor, as the catalog declares it. */
12
+ type RowDescriptorOf<C extends CollectionField> = Graph[C]["row"];
13
+ /**
14
+ * The value a member of `value_type` resolves to on a baked row: a scalar may be
15
+ * absent, an image member resolves to the image value a slot renders, and an image
16
+ * list to the list of them.
17
+ */
18
+ type MemberValue<D> = D extends {
19
+ value_type: "text";
20
+ } ? string | null : D extends {
21
+ value_type: "number";
22
+ } ? number | null : D extends {
23
+ value_type: "boolean";
24
+ } ? boolean | null : D extends {
25
+ value_type: "image";
26
+ } ? ImageValue | null : D extends {
27
+ value_type: "image_list";
28
+ } ? ImageValue[] : unknown;
29
+ /**
30
+ * What `row` offers inside a list bound to collection `C`: one ref per member of the
31
+ * collection's row descriptor, identity aside. The mapping only FILTERS the
32
+ * descriptor's keys, so each member's doc comment is what an author reads hovering
33
+ * `unit.beds`.
34
+ */
35
+ type CollectionRow<C extends CollectionField> = { readonly [M in keyof RowDescriptorOf<C> as M extends CollectionIdKey<C> ? never : M]: RowRef<M & string, MemberValue<RowDescriptorOf<C>[M]>, RowDescriptorOf<C>[M] extends {
36
+ writeback: object;
37
+ } ? true : false>; };
38
+ /**
39
+ * What `row` offers inside a list whose rows are some other value's: one read-only
40
+ * ref per member of that value's row type. Only a baked collection member writes
41
+ * back — a computed row has nowhere to write to.
42
+ */
43
+ type ValueRow<Row> = { readonly [M in keyof Row & string]-?: RowRef<M, Row[M], false>; };
44
+ /** The row type of a list-valued source's value, or `never` when the value is not a list of records. */
45
+ type RowOfList<V> = V extends readonly (infer Row)[] ? (Row extends object ? Row : never) : never;
46
+ /** An AI-built row, or one with no source, offers no member: its fields read one another by const. */
47
+ type NoRow = Readonly<Record<never, never>>;
48
+ /**
49
+ * The row reference a `fields` callback receives, decided by the list's `source`.
50
+ * The list's source is inferred before the callback is typed, so the row's members
51
+ * are known where each field names one — a member the source does not offer is a
52
+ * compile error at that field.
53
+ */
54
+ type RowOf<Source> = Source extends {
55
+ kind: "direct";
56
+ field: infer C extends CollectionField;
57
+ } ? CollectionRow<C> : Source extends ComputeBinding<infer V> ? ValueRow<RowOfList<V>> : Source extends SlotRef<string, string, infer V> ? ValueRow<RowOfList<V>> : Source extends FillBinding ? NoRow : Source extends SiblingSlot ? ValueRow<RowOfList<SlotValue<Source>>> : NoRow;
58
+ //#endregion
59
+ export { CollectionIdKey, CollectionRow, NoRow, RowOf, ValueRow };
@@ -0,0 +1,28 @@
1
+ import { COLLECTIONS, FACT_GRAPH } from "../packages/internal/template-contracts/dist/slot-catalog.js";
2
+ import { isSiblingSlot, isSlotRef } from "./slot-ref.js";
3
+
4
+ //#region src/schema/row-ref.ts
5
+ function boundCollection(source) {
6
+ if (typeof source !== "object" || source === null) return void 0;
7
+ const { kind, field } = source;
8
+ return kind === "direct" && typeof field === "string" && Object.hasOwn(COLLECTIONS, field) ? field : void 0;
9
+ }
10
+ function collectionMembers(c) {
11
+ const row = FACT_GRAPH[c].row;
12
+ return Object.keys(row).filter((member) => member !== COLLECTIONS[c].idKey);
13
+ }
14
+ function rowRef(field) {
15
+ return Object.freeze({
16
+ kind: "row",
17
+ field
18
+ });
19
+ }
20
+ function rowReference(source) {
21
+ const collection = boundCollection(source);
22
+ if (collection !== void 0) return Object.freeze(Object.fromEntries(collectionMembers(collection).map((member) => [member, rowRef(member)])));
23
+ if (!((typeof source === "object" && source !== null ? source.kind : void 0) === "compute" || isSlotRef(source) || isSiblingSlot(source))) return Object.freeze({});
24
+ return new Proxy({}, { get: (_target, member) => typeof member === "string" ? rowRef(member) : void 0 });
25
+ }
26
+
27
+ //#endregion
28
+ export { boundCollection, collectionMembers, rowReference };