@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,4 +1,5 @@
1
- import { COLLECTIONS, SOURCE_FIELDS, isWritableSourceField } from "../../template-contracts/dist/slot-catalog.js";
1
+ import { COLLECTIONS, FACT_GRAPH, SOURCE_FIELDS, isWritableSourceField } from "../../template-contracts/dist/slot-catalog.js";
2
+ import { usesRowSources } from "../../template-contracts/dist/row-sources.js";
2
3
 
3
4
  //#region ../../internal/section-contracts/dist/source-contract.js
4
5
  function rowContainerOf(desc) {
@@ -30,20 +31,31 @@ function assertOne(path, key, slot, rowContainer) {
30
31
  if (src.transform !== key) throw new Error(`${path}: unknown transform "${String(src.transform)}". A "derived" source is a compute() binding, and its transform must equal its own slot key ("${key}") — it does not, which means the schema was hand-authored with a mismatched transform rather than produced by defineSchema's compute() path. Author a derived value with compute() ("slot({ source: compute({ reads }, fn) })").`);
31
32
  assertDeclaredRefs(path, src.reads);
32
33
  }
33
- function assertDeclaredRefs(path, reads) {
34
+ function assertDeclaredRefs(path, reads, rowMember) {
34
35
  if (reads === void 0) return;
35
36
  if (!Array.isArray(reads)) throw new Error(`${path}: "reads" is not a list of refs.`);
36
37
  reads.forEach((entry, i) => {
37
- const { kind, key, section, slot } = entry ?? {};
38
+ const { kind, key, section, slot, field } = entry ?? {};
38
39
  if (kind === "fact" && typeof key === "string") return;
39
40
  if (kind === "slot" && typeof section === "string" && typeof slot === "string") return;
41
+ if (kind === "row" && typeof field === "string") {
42
+ if (rowMember === void 0) throw new Error(`${path}: reads[${String(i)}] reads the row member "${field}" outside a record list's row — only a row field's compute runs once per row.`);
43
+ rowMember(field);
44
+ return;
45
+ }
40
46
  throw new Error(kind === void 0 ? `${path}: reads[${String(i)}] is a ref without a "kind" — this framework reads only kind-tagged fact and slot refs. Run \`concrete upgrade\`, then build again.` : `${path}: reads[${String(i)}] is not a fact ref ({ kind: "fact", key }) or a slot ref ({ kind: "slot", section, slot }).`);
41
47
  });
42
48
  }
43
49
  function assertSourceContract(schema) {
44
50
  for (const [name, slot] of Object.entries(schema.slots)) {
45
- assertOne(`${schema.key}.${name}`, name, slot, null);
51
+ const at = `${schema.key}.${name}`;
52
+ if (slot.source?.kind === "row") throw new Error(`${at}: a row source on a top-level slot — a row member or marker names a field of a record list's row, and a top-level slot has no row. Bind the slot to a fact instead.`);
53
+ assertOne(at, name, slot, null);
46
54
  if (slot.type !== "list" || slot.fields === void 0) continue;
55
+ if (usesRowSources(slot.fields)) {
56
+ assertRowSourceList(at, name, slot, slot.fields);
57
+ continue;
58
+ }
47
59
  const hostField = slot.source?.kind === "direct" ? slot.source.field : void 0;
48
60
  const hostDesc = hostField !== void 0 ? SOURCE_FIELDS[hostField] : void 0;
49
61
  const rowContainer = hostDesc !== void 0 ? rowContainerOf(hostDesc) : null;
@@ -54,6 +66,70 @@ function assertSourceContract(schema) {
54
66
  }
55
67
  }
56
68
  }
69
+ function memberFits(valueType, field) {
70
+ switch (valueType) {
71
+ case "image": return field.type === "image";
72
+ case "image_list": return field.type === "list" && field.fields === void 0 && field.element?.type === "image";
73
+ case "number": return field.type === "number";
74
+ case "text": return field.type === "text" || field.type === "url" || field.type === "select";
75
+ default: return false;
76
+ }
77
+ }
78
+ function fittingTypes(valueType) {
79
+ switch (valueType) {
80
+ case "image": return "an `image` field";
81
+ case "image_list": return "a list of images (`list({ item: image() })`)";
82
+ case "number": return "a `number` field";
83
+ case "text": return "a `text`, `url` or `select` field";
84
+ default: return "no field — it is not offered to a row";
85
+ }
86
+ }
87
+ function assertRowSourceList(at, listKey, list, fields) {
88
+ const listSource = list.source;
89
+ const boundField = listSource?.kind === "direct" ? listSource.field ?? "" : void 0;
90
+ if (boundField !== void 0 && !Object.hasOwn(COLLECTIONS, boundField)) throw new Error(`${at}: row sources on a list bound to "${boundField}", which is not a fact collection — a row member names a member of the row a collection supplies.`);
91
+ const collection = boundField;
92
+ const computed = listSource?.kind === "derived";
93
+ const filled = listSource === void 0;
94
+ const assertMember = (path, member) => {
95
+ if (filled) throw new Error(`${path}: row member "${member}" on a list a fill() builds — its rows do not exist until the fill answers, so they offer no members. Give the field its own fill() instead.`);
96
+ if (collection === void 0) return void 0;
97
+ if (member === COLLECTIONS[collection].idKey) throw new Error(`${path}: row member "${member}" is the row's identity, which every baked "${collection}" row carries as "${member}" already — drop the field.`);
98
+ const row = FACT_GRAPH[collection].row;
99
+ const descriptor = row[member];
100
+ if (descriptor === void 0) throw new Error(`${path}: unknown row member "${member}" — a "${collection}" row offers ${Object.keys(row).filter((name) => name !== COLLECTIONS[collection].idKey).map((name) => `"${name}"`).join(", ")}.`);
101
+ return descriptor;
102
+ };
103
+ for (const [fieldKey, field] of Object.entries(fields)) {
104
+ const path = `${at}.${fieldKey}`;
105
+ const src = field.source;
106
+ if (src === void 0 || src.kind === "authored") {
107
+ if (field.writeback !== void 0) throw new Error(`${path}: "writeback" without a source. Only a field bound to a row member answers whether edits propagate — remove the key.`);
108
+ continue;
109
+ }
110
+ if (src.kind === "direct") throw new Error(`${path}: a direct source on a row field of a list whose other fields name row members — one list declares its rows one way. Name this field's member too (\`source: <row>.<member>\`).`);
111
+ if (src.kind === "derived") {
112
+ if (field.writeback !== void 0) throw new Error(`${path}: "writeback" on a derived (compute) source. Nothing can write back through a derivation — remove the key.`);
113
+ const handle = `${listKey}.${fieldKey}`;
114
+ if (src.transform !== handle) throw new Error(`${path}: unknown transform "${String(src.transform)}". A row field's compute() is held under "${handle}" — its list's key and its own — which this declaration does not name, so it was not produced by the framework's compute() path.`);
115
+ assertDeclaredRefs(path, src.reads, (member) => {
116
+ assertMember(path, member);
117
+ });
118
+ continue;
119
+ }
120
+ if (src.kind !== "row") continue;
121
+ if (typeof src.field !== "string") throw new Error(`${path}: a row source names no member — it is \`{ kind: "row", field: "<member>" }\`.`);
122
+ const member = src.field;
123
+ const descriptor = assertMember(path, member);
124
+ if (field.writeback !== void 0 && typeof field.writeback !== "boolean") throw new Error(`${path}: "writeback" is not a boolean — declare whether edits propagate to row member "${member}".`);
125
+ if (descriptor === void 0) {
126
+ if (computed && field.writeback === true) throw new Error(`${path}: "writeback: true" on a row of a computed list — nothing can write back through a derivation; declare "writeback: false".`);
127
+ continue;
128
+ }
129
+ if (!memberFits(descriptor.value_type, field)) throw new Error(`${path}: row member "${member}" is a ${descriptor.value_type} value and cannot sit on a "${String(field.type)}" field — it belongs on ${fittingTypes(descriptor.value_type)}.`);
130
+ if (field.writeback === true && descriptor.writeback === void 0) throw new Error(`${path}: "writeback: true" on read-only row member "${member}" — the catalog has no write path for it; declare "writeback: false".`);
131
+ }
132
+ }
57
133
 
58
134
  //#endregion
59
135
  export { assertDeclaredRefs, assertSourceContract };
@@ -1,29 +1,35 @@
1
1
  import { originationFor } from "../../fill-vocabulary/dist/origination.js";
2
+ import { plannedFieldsOf } from "./fill-spec-view.js";
2
3
 
3
4
  //#region ../../internal/section-contracts/dist/writer-reads-fact-contract.js
4
5
  const WRITES = ["write", "write-items"];
5
- function writes(slot) {
6
+ function writes(slot, planned = []) {
6
7
  if (slot === void 0) return false;
7
- const origination = originationFor(slot);
8
+ const origination = originationFor(slot, planned);
8
9
  if (origination === void 0) return false;
9
10
  return WRITES.includes(origination.kind) || origination.kind === "keyed-rows" && origination.keys === "written";
10
11
  }
11
- function readsAFact(reads) {
12
- return (reads ?? []).some((ref) => ref?.kind === "fact");
12
+ function readsAFact(reads, rowsAreFacts) {
13
+ return (reads ?? []).some((ref) => {
14
+ const kind = ref?.kind;
15
+ return kind === "fact" || rowsAreFacts && kind === "row";
16
+ });
13
17
  }
14
18
  function assertWriterReadsFactContract(schema, decision, sectionKey) {
15
19
  if (decision.kind !== "text" && decision.kind !== "list") return;
16
20
  const fill = decision;
17
21
  const writing = [];
22
+ let rowsAreFacts = false;
18
23
  for (const slotId of decision.produces) {
19
24
  const slot = schema.slots[slotId];
20
25
  if (slot === void 0) continue;
21
- if (decision.kind === "text" || writes(slot)) writing.push(slotId);
26
+ if (originationFor(slot)?.kind === "bound-rows") rowsAreFacts = true;
27
+ if (decision.kind === "text" || writes(slot, plannedFieldsOf(decision))) writing.push(slotId);
22
28
  for (const field of Object.keys(fill.fields ?? {})) if (writes(slot.fields?.[field])) writing.push(`${slotId}.${field}`);
23
29
  }
24
30
  if (writing.length === 0) return;
25
31
  const fields = Object.values(fill.fields ?? {});
26
- if (readsAFact(fill.reads) || fields.some((field) => readsAFact(field.reads))) return;
32
+ if (readsAFact(fill.reads, false) || fields.some((field) => readsAFact(field.reads, rowsAreFacts))) return;
27
33
  throw new Error(`Section "${sectionKey}": fill "${decision.id}" writes ${writing.map((w) => `"${w}"`).join(", ")} but reads no fact — its model call is shown exactly its \`reads\`, so it would write from the brief alone. Declare the facts it writes from (\`reads: [fact.description]\`), on the fill or on the row field that writes.`);
28
34
  }
29
35
 
@@ -1,10 +1,14 @@
1
- import { FACT_GRAPH, REFERRAL_IMAGE_FIELDS, SOURCE_FIELDS } from "../../template-contracts/dist/slot-catalog.js";
1
+ import { COLLECTIONS, FACT_GRAPH, FACT_PROJECTIONS, REFERRAL_FIELDS, REFERRAL_IMAGE_FIELDS, SOURCE_FIELDS } from "../../template-contracts/dist/slot-catalog.js";
2
+ import { rowMemberOf, rowMemberSources, usesRowSources } from "../../template-contracts/dist/row-sources.js";
2
3
  import { projectFactsView } from "../../template-contracts/dist/facts-view.js";
3
4
 
4
5
  //#region ../../internal/source-resolution/dist/index.js
5
6
  function rowFieldSources(fields) {
6
7
  const map = {};
7
- for (const [key, field] of Object.entries(fields ?? {})) if (field.source?.kind === "direct" && typeof field.source.field === "string") map[key] = field.source.field;
8
+ for (const [key, field] of Object.entries(fields ?? {})) {
9
+ const source = field.source;
10
+ if (source?.kind === "direct" && typeof source.field === "string") map[key] = source.field;
11
+ }
8
12
  return map;
9
13
  }
10
14
  function primaryContact(facts) {
@@ -18,29 +22,16 @@ function comparablesOf(facts) {
18
22
  const raw = facts.comparables;
19
23
  return Array.isArray(raw) ? raw : [];
20
24
  }
21
- const REFERRAL_FIELD_TO_CONTACT_KEY = {
22
- name: "name",
23
- title: "title",
24
- org_name: "org_name",
25
- email: "email",
26
- phone: "phone",
27
- website: "website_url",
28
- instagram: "instagram_url",
29
- linkedin: "linkedin_url",
30
- x: "x_url",
31
- facebook: "facebook_url",
32
- headshot: "avatar_upload_id",
33
- logo_dark: "logo_dark_upload_id",
34
- logo_light: "logo_light_upload_id"
35
- };
25
+ const CONTACT_ROW = FACT_GRAPH.contacts.row;
26
+ const REFERRAL_FIELD_TO_CONTACT_KEY = Object.fromEntries(REFERRAL_FIELDS.map((field) => [field, CONTACT_ROW[field].path]));
36
27
  const REFERRAL_IMAGE_FIELD_SET = new Set(REFERRAL_IMAGE_FIELDS);
37
28
  const LOGO_VARIANT_FALLBACK = {
38
29
  logo_dark: {
39
- other: "logo_light_upload_id",
30
+ other: CONTACT_ROW.logo_light.path,
40
31
  mask: "black"
41
32
  },
42
33
  logo_light: {
43
- other: "logo_dark_upload_id",
34
+ other: CONTACT_ROW.logo_dark.path,
44
35
  mask: "white"
45
36
  }
46
37
  };
@@ -133,6 +124,52 @@ const COLLECTION_PROJECTIONS = {
133
124
  contacts: buildContactsList,
134
125
  comparables: buildComparablesList
135
126
  };
127
+ function collectionRowsOf(collection, facts) {
128
+ switch (collection) {
129
+ case "units": return [...facts.units].sort((a, b) => a.position - b.position);
130
+ case "contacts": return contactsOf(facts);
131
+ case "comparables": return comparablesOf(facts);
132
+ }
133
+ }
134
+ const CONTACT_MEMBER_FACT = Object.fromEntries(Object.entries(CONTACT_ROW).filter(([, member]) => member.strength !== void 0).map(([name]) => [name, FACT_PROJECTIONS.contact[name] ?? name]));
135
+ function mediaRefOf(raw) {
136
+ if (typeof raw !== "string") return null;
137
+ const assetId = raw.trim();
138
+ return assetId.length > 0 ? { asset_id: assetId } : null;
139
+ }
140
+ function mediaRefListOf(raw) {
141
+ if (!Array.isArray(raw)) return [];
142
+ return [...raw].sort((a, b) => (typeof a["position"] === "number" ? a["position"] : 0) - (typeof b["position"] === "number" ? b["position"] : 0)).flatMap((element) => {
143
+ const ref = mediaRefOf(element["id"]);
144
+ if (ref === null) return [];
145
+ if ("floor_label" in element) ref.floor_label = typeof element["floor_label"] === "string" ? element["floor_label"] : null;
146
+ return [ref];
147
+ });
148
+ }
149
+ function readRowMember(collection, row, member, facts) {
150
+ const descriptor = FACT_GRAPH[collection].row[member];
151
+ if (descriptor === void 0) return null;
152
+ if (collection === "contacts") {
153
+ const fact = CONTACT_MEMBER_FACT[member];
154
+ if (fact !== void 0) return resolveContactScalar(row, fact);
155
+ }
156
+ if (collection === "units" && member === "unit_label") return row["unit_label"] ?? singleUnitLabelDefault(facts.property_type);
157
+ const raw = row[descriptor.path] ?? null;
158
+ if (descriptor.value_type === "image") return mediaRefOf(raw);
159
+ if (descriptor.value_type === "image_list") return mediaRefListOf(raw);
160
+ return raw;
161
+ }
162
+ function projectCollectionRows(collection, facts, fields, rowComputes = {}) {
163
+ if (!usesRowSources(fields)) return COLLECTION_PROJECTIONS[collection](facts, rowFieldSources(fields));
164
+ const idKey = COLLECTIONS[collection].idKey;
165
+ const members = rowMemberSources(fields);
166
+ return collectionRowsOf(collection, facts).map((row) => {
167
+ const out = { [idKey]: row[idKey] };
168
+ for (const [key, member] of Object.entries(members)) out[key] = readRowMember(collection, row, member, facts);
169
+ for (const [key, compute] of Object.entries(rowComputes)) out[key] = compute((member) => readRowMember(collection, row, member, facts));
170
+ return out;
171
+ });
172
+ }
136
173
  function firstUnit(facts) {
137
174
  if (facts.units.length === 0) return void 0;
138
175
  return [...facts.units].sort((a, b) => a.position - b.position)[0];
@@ -194,4 +231,4 @@ function readAddressPart(address, part) {
194
231
  }
195
232
 
196
233
  //#endregion
197
- export { COLLECTION_PROJECTIONS, buildComparablesList, buildContactsList, buildUnitFloorplanList, buildUnitsList, primaryContact, primaryContactFactValue, projectFactsView, readFrom, resolveContactCardField, rowFieldSources, singleUnitLabelDefault };
234
+ export { COLLECTION_PROJECTIONS, buildComparablesList, buildContactsList, buildUnitFloorplanList, buildUnitsList, primaryContact, primaryContactFactValue, projectCollectionRows, projectFactsView, readFrom, readRowMember, resolveContactCardField, rowFieldSources, rowMemberSources, singleUnitLabelDefault, usesRowSources };
@@ -1,4 +1,4 @@
1
- import { FACT_GRAPH, FactGraphName, FactMemberDescriptor, FactProjections, FactShapeDescriptor, FactValueType, SourceFieldContainer } from "./slot-catalog.js";
1
+ import { FACT_GRAPH, FactGraphName, FactMemberDescriptor, FactProjections, FactShapeDescriptor, FactValueType } from "./slot-catalog.js";
2
2
  //#region ../../internal/template-contracts/dist/facts-view.d.ts
3
3
  type Graph = typeof FACT_GRAPH;
4
4
  type ScalarType<V extends FactValueType> = V extends "number" ? number | null : V extends "boolean" ? boolean : V extends "text_list" ? readonly string[] : string | null;
@@ -13,25 +13,24 @@ type FactPoolName = { [K in FactGraphName]: Graph[K] extends {
13
13
  type PoolRow<P extends FactPoolName> = Graph[P] extends {
14
14
  row: infer R extends FactShapeDescriptor;
15
15
  } ? R : never;
16
- type RowBindableName<P extends FactPoolName> = { [K in FactGraphName]: Graph[K] extends {
17
- role: "bindable";
18
- path: `${P}[].${string}`;
19
- } ? K : never; }[FactGraphName];
20
- type BoundRowMember<P extends FactPoolName, K> = K extends FactGraphName ? Graph[K]["path"] extends `${P}[].${infer M}` ? M : never : never;
21
- type BoundMembers<P extends FactPoolName> = { [K in RowBindableName<P>]: BoundRowMember<P, K>; }[RowBindableName<P>];
22
- type ContainerOf<K extends FactGraphName> = Graph[K] extends {
23
- container: infer C extends SourceFieldContainer;
24
- } ? C : never;
25
- type AliasNameFor<C, K> = C extends keyof FactProjections ? { [A in keyof FactProjections[C]]: FactProjections[C][A] extends K ? A : never; }[keyof FactProjections[C]] : never;
26
- type AuthorFacingName<K extends FactGraphName> = [AliasNameFor<ContainerOf<K>, K>] extends [never] ? K : AliasNameFor<ContainerOf<K>, K>;
16
+ type HasPrimaryRow<P extends FactPoolName> = { [K in FactGraphName]: Graph[K] extends {
17
+ primary_of: P;
18
+ } ? K : never; }[FactGraphName] extends never ? false : true;
19
+ type StoredUnderOtherName<P extends FactPoolName> = HasPrimaryRow<P> extends true ? never : { [M in keyof PoolRow<P>]: PoolRow<P>[M] extends {
20
+ path: infer S extends string;
21
+ } ? S extends M ? never : M : never; }[keyof PoolRow<P>];
22
+ type StoredName<P extends FactPoolName, M> = M extends keyof PoolRow<P> ? PoolRow<P>[M] extends {
23
+ path: infer S extends string;
24
+ } ? S : never : never;
27
25
  /**
28
26
  * One row of pool `P`, as the derive-time view carries it: exactly the
29
- * registry row descriptor's members, each member a bindable entry binds into
30
- * renamed to that entry's author-facing spelling (`website` ←
31
- * `contacts[].website_url`; the alias table applies, so `address` ←
32
- * `contacts[].address` via `contact_address`).
27
+ * registry row descriptor's members, each under its author-facing name —
28
+ * `website`, stored as `website_url`; a comparable's `photo`, stored as
29
+ * `photo_upload_id` — so one spelling serves `fact.contact.*`, a row reference
30
+ * and the row. A pool with no primary row also carries a renamed member under
31
+ * its storage key, for computes written before its rows took author names.
33
32
  */
34
- type FactsRow<P extends FactPoolName> = { readonly [K in RowBindableName<P> as AuthorFacingName<K>]: MemberType<PoolRow<P>[BoundRowMember<P, K> & keyof PoolRow<P>]>; } & { readonly [M in keyof PoolRow<P> as M extends BoundMembers<P> ? never : M]: MemberType<PoolRow<P>[M]>; };
33
+ type FactsRow<P extends FactPoolName> = { readonly [M in keyof PoolRow<P>]: MemberType<PoolRow<P>[M]>; } & { readonly [M in keyof PoolRow<P> as M extends StoredUnderOtherName<P> ? StoredName<P, M> : never]: MemberType<PoolRow<P>[M]>; };
35
34
  type EntryValue<K extends FactGraphName> = Graph[K] extends {
36
35
  primary_of: infer P extends FactPoolName;
37
36
  } ? FactsRow<P> | null : Graph[K] extends {
@@ -41,28 +41,16 @@ function authorFacingName(key, container) {
41
41
  }
42
42
  return key;
43
43
  }
44
- const ROW_BINDABLES = {};
45
- for (const [key, entry] of Object.entries(FACT_GRAPH)) {
46
- if (entry.role !== "bindable") continue;
47
- const match = /^(\w+)\[\]\.(\w+)$/.exec(entry.path);
48
- if (match === null) continue;
49
- (ROW_BINDABLES[match[1]] ??= []).push({
50
- name: authorFacingName(key, entry.container),
51
- member: match[2]
52
- });
53
- }
44
+ const PRIMARY_ROW_POOLS = new Set(Object.values(FACT_GRAPH).flatMap((entry) => entry.role === "readable" && entry.primary_of !== void 0 ? [entry.primary_of] : []));
54
45
  function rowValue(pool, shape, raw) {
55
46
  const source = raw !== null && typeof raw === "object" ? raw : {};
56
- const bound = ROW_BINDABLES[pool] ?? [];
57
- const boundMembers = new Set(bound.map((b) => b.member));
47
+ const keepsStoredName = !PRIMARY_ROW_POOLS.has(pool);
58
48
  const out = {};
59
49
  for (const [member, desc] of Object.entries(shape)) {
60
- if (boundMembers.has(member)) continue;
61
- out[member] = memberValue(desc, source[member]);
62
- }
63
- for (const { name, member } of bound) {
64
- const desc = shape[member];
65
- out[name] = desc === void 0 ? null : memberValue(desc, source[member]);
50
+ const stored = desc.path ?? member;
51
+ const value = memberValue(desc, source[stored]);
52
+ out[member] = value;
53
+ if (keepsStoredName && stored !== member) out[stored] = value;
66
54
  }
67
55
  return out;
68
56
  }
@@ -0,0 +1,26 @@
1
+ //#region ../../internal/template-contracts/dist/row-sources.js
2
+ function sourceRecord(source) {
3
+ return source !== null && typeof source === "object" ? source : null;
4
+ }
5
+ function rowMemberOf(source) {
6
+ const src = sourceRecord(source);
7
+ if (src?.["kind"] !== "row") return null;
8
+ return typeof src["field"] === "string" ? src["field"] : null;
9
+ }
10
+ function usesRowSources(fields) {
11
+ return Object.values(fields ?? {}).some((field) => {
12
+ const kind = sourceRecord(field.source)?.["kind"];
13
+ return kind === "row" || kind === "derived";
14
+ });
15
+ }
16
+ function rowMemberSources(fields) {
17
+ const map = {};
18
+ for (const [key, field] of Object.entries(fields ?? {})) {
19
+ const member = rowMemberOf(field.source);
20
+ if (member !== null) map[key] = member;
21
+ }
22
+ return map;
23
+ }
24
+
25
+ //#endregion
26
+ export { rowMemberOf, rowMemberSources, usesRowSources };