@entifix/core 0.20.2 → 0.21.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 (34) hide show
  1. package/README.md +1 -1
  2. package/dist/entity-definition/describe/describe-entity-columns.d.ts +6 -1
  3. package/dist/entity-definition/describe/describe-entity-columns.d.ts.map +1 -1
  4. package/dist/entity-definition/describe/describe-entity-columns.js +51 -3
  5. package/dist/entity-definition/describe/describe-entity-columns.js.map +1 -1
  6. package/dist/entity-definition/describe/describe-entity-use-cases.d.ts +13 -1
  7. package/dist/entity-definition/describe/describe-entity-use-cases.d.ts.map +1 -1
  8. package/dist/entity-definition/describe/describe-entity-use-cases.js +16 -0
  9. package/dist/entity-definition/describe/describe-entity-use-cases.js.map +1 -1
  10. package/dist/entity-definition/describe/index.d.ts +1 -0
  11. package/dist/entity-definition/describe/index.d.ts.map +1 -1
  12. package/dist/entity-definition/describe/index.js +1 -0
  13. package/dist/entity-definition/describe/index.js.map +1 -1
  14. package/dist/entity-definition/describe/record-label.d.ts +69 -0
  15. package/dist/entity-definition/describe/record-label.d.ts.map +1 -0
  16. package/dist/entity-definition/describe/record-label.js +97 -0
  17. package/dist/entity-definition/describe/record-label.js.map +1 -0
  18. package/dist/entity-definition/helpers/entity-definition-helpers.d.ts +5 -0
  19. package/dist/entity-definition/helpers/entity-definition-helpers.d.ts.map +1 -1
  20. package/dist/entity-definition/helpers/entity-definition-helpers.js +37 -0
  21. package/dist/entity-definition/helpers/entity-definition-helpers.js.map +1 -1
  22. package/dist/entity-definition/meta-entities/meta-accessor/meta-accessor.d.ts +19 -0
  23. package/dist/entity-definition/meta-entities/meta-accessor/meta-accessor.d.ts.map +1 -1
  24. package/dist/entity-definition/meta-entities/meta-accessor/meta-accessor.js +1 -0
  25. package/dist/entity-definition/meta-entities/meta-accessor/meta-accessor.js.map +1 -1
  26. package/dist/entity-definition/meta-entities/meta-entity/meta-entity.d.ts +12 -0
  27. package/dist/entity-definition/meta-entities/meta-entity/meta-entity.d.ts.map +1 -1
  28. package/dist/entity-definition/meta-entities/meta-entity/meta-entity.js +1 -0
  29. package/dist/entity-definition/meta-entities/meta-entity/meta-entity.js.map +1 -1
  30. package/dist/entity-definition/meta-entities/meta-use-case/meta-use-case.d.ts +27 -0
  31. package/dist/entity-definition/meta-entities/meta-use-case/meta-use-case.d.ts.map +1 -1
  32. package/dist/entity-definition/meta-entities/meta-use-case/meta-use-case.js +1 -0
  33. package/dist/entity-definition/meta-entities/meta-use-case/meta-use-case.js.map +1 -1
  34. package/package.json +1 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The entity system. A class decorated with `@entity()` and `@accessor()` describes itself — its members, their types and labels, which of them are sortable or filterable — and everything else in entifix reads that description instead of being told it again.
4
4
 
5
- Presentation lives on the class too: `@entity({ creatable })`, and `@accessor({ minWidth, card, autocomplete })` for how a member reads in a table, on a card and to a browser's autofill. A `@useCase()` declares its place in the action hierarchy (`emphasis`, `priority`, `rowInline`, `shortcut`) and, when destructive, how it is undone (`reversible`, `inverse`); a bad shortcut (`parseChord`) or an unsafe destructive verb fails at load.
5
+ Presentation lives on the class too: `@entity({ creatable })`, and `@accessor({ minWidth, card, autocomplete })` for how a member reads in a table, on a card and to a browser's autofill. A `@useCase()` declares its place in the action hierarchy (`emphasis`, `priority`, `rowInline`, `shortcut`), the record states it is offered in (`availableWhen`) and, when destructive, how it is undone (`reversible`, `inverse`); a bad shortcut (`parseChord`) or an unsafe destructive verb fails at load.
6
6
 
7
7
  It also owns what crosses the wire: entity serialization and reconstruction, the envelopes a service answers with, and the RSQL filter and sort protocol a query is written in. Nothing here performs I/O.
8
8
 
@@ -1,4 +1,4 @@
1
- import { type CardRole, type ChildConstructor, type EntityLinkSerialization, MetaAccessorType, type MoneyFormat } from '../meta-entities/meta-accessor/index.js';
1
+ import { type CardRole, type ChildConstructor, type EntityLinkSerialization, type MemberReference, MetaAccessorType, type MoneyFormat } from '../meta-entities/meta-accessor/index.js';
2
2
  /**
3
3
  * A displayable member of an entity, resolved from its accessor metadata. This
4
4
  * is the contract generic UI builds itself from — a table's columns today, a
@@ -61,6 +61,11 @@ export interface EntityFieldDescriptor {
61
61
  autocomplete?: string;
62
62
  /** This member holds the parent record's id: the entity forms a tree. */
63
63
  parent?: boolean;
64
+ /**
65
+ * This member holds the id of a record of another entity, named `domain:key`.
66
+ * A screen shows that record's name in its place.
67
+ */
68
+ references?: MemberReference;
64
69
  }
65
70
  /** Types whose values are scalars a user can meaningfully sort/filter on. */
66
71
  export declare const SCALAR_TYPES: readonly MetaAccessorType[];
@@ -1 +1 @@
1
- {"version":3,"file":"describe-entity-columns.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/describe/describe-entity-columns.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAE5B,gBAAgB,EAChB,KAAK,WAAW,EACjB,MAAM,yCAAyC,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,gBAAgB,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,sEAAsE;IACtE,QAAQ,EAAE,OAAO,CAAC;IAClB,kEAAkE;IAClE,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,0FAA0F;IAC1F,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,6DAA6D;IAC7D,iBAAiB,EAAE,MAAM,CAAC;IAC1B,+EAA+E;IAC/E,kBAAkB,EAAE,MAA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;;GAgBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,MAAM,EAC1D,iBAAiB,EAAE,gBAAgB,CAAC,OAAO,CAAC,EAC5C,MAAM,CAAC,EAAE,OAAO,GACf,qBAAqB,EAAE,CAkBzB"}
1
+ {"version":3,"file":"describe-entity-columns.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/describe/describe-entity-columns.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,eAAe,EAEpB,gBAAgB,EAChB,KAAK,WAAW,EACjB,MAAM,yCAAyC,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,gBAAgB,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,sEAAsE;IACtE,QAAQ,EAAE,OAAO,CAAC;IAClB,kEAAkE;IAClE,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,0FAA0F;IAC1F,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,6DAA6D;IAC7D,iBAAiB,EAAE,MAAM,CAAC;IAC1B,+EAA+E;IAC/E,kBAAkB,EAAE,MAAM,CAAC;IAC3B,0EAA0E;IAC1E,iBAAiB,EAAE,uBAAuB,CAAC;IAC3C;;;OAGG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B;;;OAGG;IACH,YAAY,EAAE,OAAO,CAAC;IACtB,sDAAsD;IACtD,QAAQ,CAAC,EAAE,MAAM,C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CAqBzB"}
@@ -1,5 +1,5 @@
1
1
  import { _ as _extends } from "@swc/helpers/_/_extends";
2
- import { extractMetaAccessors } from '../helpers/index.js';
2
+ import { extractMetaAccessors, findMetaEntity } from '../helpers/index.js';
3
3
  import { EntityCollectionLink } from '../links/entity-collection-link/index.js';
4
4
  import { EntityLink } from '../links/entity-link/index.js';
5
5
  import { assertBounds } from '../meta-entities/bounds.js';
@@ -93,6 +93,50 @@ import { assertBounds } from '../meta-entities/bounds.js';
93
93
  if (type === 'id' || type === 'string') return;
94
94
  throw new Error(`"${String(metaAccessor.name)}" is a ${type} and cannot be the parent member — a parent is one record's id, so it is an id or a string.`);
95
95
  }
96
+ /** A reference's entity, as `@entity({ domain, key })` names it: two kebab-case words. */ const REFERENCE_KEY = /^[a-z0-9]+(?:-[a-z0-9]+)*:[a-z0-9]+(?:-[a-z0-9]+)*$/;
97
+ /**
98
+ * A reference holds one record's id, so it is an `id` or a `string` member, and
99
+ * names its target as `domain:key`. On the `parent` member it may only name the
100
+ * entity itself — a parent is a record of the same entity, built into a tree —
101
+ * which is what lets a list show a branch's parent by name.
102
+ */ function assertReference(target, metaAccessor, type) {
103
+ const { references } = metaAccessor;
104
+ if (references === undefined) return;
105
+ const name = String(metaAccessor.name);
106
+ if (type !== 'id' && type !== 'string') {
107
+ throw new Error(`"${name}" is a ${type} and declares references — a reference holds one record's id, so it is an id or a string.`);
108
+ }
109
+ if (!REFERENCE_KEY.test(references.entity)) {
110
+ throw new Error(`"${name}" references "${references.entity}", which is not an entity's "domain:key" — the pair its @entity({ domain, key }) declares.`);
111
+ }
112
+ const own = findMetaEntity(target);
113
+ if (metaAccessor.parent === true && references.entity !== `${own == null ? void 0 : own.domain}:${own == null ? void 0 : own.key}`) {
114
+ throw new Error(`"${name}" is the parent member and references "${references.entity}" — a parent is a record of the same entity, so it can only reference ${target.name} itself.`);
115
+ }
116
+ }
117
+ /** Members whose value can name a record: a text, a number, or a reference to one. */ const LABEL_TYPES = [
118
+ 'string',
119
+ 'number',
120
+ 'localized'
121
+ ];
122
+ /**
123
+ * An entity's `labelMember` must be a visible member that holds one value a
124
+ * person can read: a hidden one never reaches the client, and a collection is
125
+ * many names. Checked against every accessor, since a hidden member is exactly
126
+ * the one describing would never see.
127
+ */ function assertLabelMember(target, descriptors) {
128
+ var _findMetaEntity;
129
+ const labelMember = (_findMetaEntity = findMetaEntity(target)) == null ? void 0 : _findMetaEntity.labelMember;
130
+ if (labelMember === undefined) return;
131
+ const declared = extractMetaAccessors(target).some((metaAccessor)=>String(metaAccessor.name) === labelMember);
132
+ const descriptor = descriptors.find((other)=>other.name === labelMember);
133
+ if (descriptor === undefined) {
134
+ throw new Error(declared ? `${target.name} is called by "${labelMember}", which is hidden — a hidden member never reaches the client, so nothing could show the name.` : `${target.name} is called by "${labelMember}", which is not a member of the entity.`);
135
+ }
136
+ if (descriptor.references === undefined && !LABEL_TYPES.includes(descriptor.type)) {
137
+ throw new Error(`${target.name} is called by "${labelMember}", a ${descriptor.type} — a record is called by a string, a localized text, a number or a reference.`);
138
+ }
139
+ }
96
140
  /** Money is a reading of a number; any other member declaring it is a mistake. */ function assertMoneyType(metaAccessor, type) {
97
141
  if (metaAccessor.money === undefined || type === 'number') return;
98
142
  throw new Error(`"${String(metaAccessor.name)}" is a ${type} and declares money — only a number member can be an amount.`);
@@ -138,13 +182,14 @@ import { assertBounds } from '../meta-entities/bounds.js';
138
182
  if (stuck === undefined) return;
139
183
  throw new Error(`"${String(stuck.name)}" is the parent member and is ${stuck.hidden === true ? 'hidden' : 'readonly'} — such a member is never serialized, so the tree would arrive flat. Hide it with a slot instead.`);
140
184
  }
141
- function toDescriptor(metaAccessor, index, sample) {
185
+ function toDescriptor(target, metaAccessor, index, sample) {
142
186
  var _metaAccessor_type, _metaAccessor_linkLabelProperty, _metaAccessor_alias, _metaAccessor_label, _metaAccessor_sortable, _metaAccessor_filterable, _metaAccessor_order, _metaAccessor_readonly, _metaAccessor_required, _metaAccessor_linkSearchProperty, _metaAccessor_linkSerialization, _metaAccessor_resetOnClone, _metaAccessor_parent;
143
187
  const name = String(metaAccessor.name);
144
188
  const type = (_metaAccessor_type = metaAccessor.type) != null ? _metaAccessor_type : inferType(name, sample == null ? void 0 : sample[name]);
145
189
  assertNotQueryable(metaAccessor, type);
146
190
  assertItemCounts(metaAccessor, type);
147
191
  assertParentType(metaAccessor, type);
192
+ assertReference(target, metaAccessor, type);
148
193
  assertMoneyType(metaAccessor, type);
149
194
  assertMinWidth(metaAccessor);
150
195
  // A localized member is queried one locale at a time (`name.en`), which
@@ -182,6 +227,8 @@ function toDescriptor(metaAccessor, index, sample) {
182
227
  autocomplete: metaAccessor.autocomplete
183
228
  }, {
184
229
  parent: (_metaAccessor_parent = metaAccessor.parent) != null ? _metaAccessor_parent : false
230
+ }, metaAccessor.references === undefined ? {} : {
231
+ references: metaAccessor.references
185
232
  });
186
233
  }
187
234
  /**
@@ -209,10 +256,11 @@ function toDescriptor(metaAccessor, index, sample) {
209
256
  if (seen.has(name)) return false;
210
257
  seen.add(name);
211
258
  return true;
212
- }).map((metaAccessor, index)=>toDescriptor(metaAccessor, index, sample)).sort((left, right)=>left.order - right.order);
259
+ }).map((metaAccessor, index)=>toDescriptor(entityConstructor, metaAccessor, index, sample)).sort((left, right)=>left.order - right.order);
213
260
  assertNotBefore(descriptors);
214
261
  assertCurrencyMembers(descriptors);
215
262
  assertOneParent(descriptors);
263
+ assertLabelMember(entityConstructor, descriptors);
216
264
  return descriptors;
217
265
  }
218
266
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/entity-definition/describe/describe-entity-columns.ts"],"sourcesContent":["import { extractMetaAccessors } from '../helpers/index.js';\nimport { EntityCollectionLink } from '../links/entity-collection-link/index.js';\nimport { EntityLink } from '../links/entity-link/index.js';\nimport { assertBounds } from '../meta-entities/bounds.js';\nimport {\n type CardRole,\n type ChildConstructor,\n type EntityLinkSerialization,\n MetaAccessor,\n MetaAccessorType,\n type MoneyFormat,\n} from '../meta-entities/meta-accessor/index.js';\n\n/**\n * A displayable member of an entity, resolved from its accessor metadata. This\n * is the contract generic UI builds itself from — a table's columns today, a\n * form's fields later — so it stays framework-free and lives next to the\n * metadata it derives from.\n */\nexport interface EntityFieldDescriptor {\n /** Accessor name. The stable identity used by preferences and slots. */\n name: string;\n /** Wire/property key: `alias ?? name`. */\n key: string;\n label: string;\n /**\n * Catalog key for {@link label}, when the entity declared one. Resolution is\n * the presentation layer's job — core has no locale and no catalogs, and the\n * same descriptor feeds the server-side filter allowlist, where a translated\n * label would be meaningless.\n */\n labelKey?: string;\n type: MetaAccessorType;\n sortable: boolean;\n filterable: boolean;\n order: number;\n /** Cannot be written back. A form shows it but disables its input. */\n readonly: boolean;\n /** Must hold a value. A form rejects submit while it is empty. */\n required: boolean;\n enumValues?: readonly string[];\n /** Catalog prefix for {@link enumValues}; a value reads as `${enumLabelKey}.${value}`. */\n enumLabelKey?: string;\n /** Property of a `link` target used as its display label. */\n linkLabelProperty: string;\n /** Property of a `link` target a picker searches on. Defaults to the label. */\n linkSearchProperty: string;\n /** Whether a `link` writes back its foreign key or the inlined target. */\n linkSerialization: EntityLinkSerialization;\n /**\n * The class describing one row of a `composition` member, resolved from the\n * accessor's thunk. Absent on every other type.\n */\n childType?: ChildConstructor;\n /**\n * The member is dropped when the record is copied — a unique code, an audit\n * stamp. The identity member is always reset and is not flagged.\n */\n resetOnClone: boolean;\n /** The fewest values a collection member may hold. */\n minItems?: number;\n /** The most values a collection member may hold. */\n maxItems?: number;\n /** The `date` member this one may not precede. */\n notBefore?: string;\n /** The member is an amount of money, read as this declares. `number` members only. */\n money?: MoneyFormat;\n /** The narrowest the member's column reads at, in `rem`, when declared. */\n minWidth?: number;\n /** The part the member plays on a record's card, when declared. */\n card?: CardRole;\n /** The member's HTML autofill token, when declared. */\n autocomplete?: string;\n /** This member holds the parent record's id: the entity forms a tree. */\n parent?: boolean;\n}\n\n/** Types whose values are scalars a user can meaningfully sort/filter on. */\nexport const SCALAR_TYPES: readonly MetaAccessorType[] = [\n 'string',\n 'number',\n 'boolean',\n 'date',\n 'enum',\n];\n\n/**\n * Types whose value is a collection. None of them may ever be sorted or\n * filtered: this descriptor is also the **server-side RSQL allowlist**, and an\n * array compared as a scalar matches nothing — so the query would not fail, it\n * would quietly return an empty page.\n *\n * Exported so `describe-entity-columns.spec.ts` can assert that this list,\n * {@link SCALAR_TYPES}, the two reference types and `localized` partition\n * `MetaAccessorTypes` exactly. Nothing in the repo guards `MetaAccessorType`\n * exhaustively — every switch over it has a `default` that treats the value as\n * a string — so that partition spec is what makes an eleventh type impossible\n * to add silently.\n */\nexport const COLLECTION_TYPES: readonly MetaAccessorType[] = [\n 'linkCollection',\n 'composition',\n 'scalarCollection',\n];\n\n/** `productCode` / `product-code` / `product_code` → `Product Code`. */\nfunction humanize(name: string): string {\n return name\n .replace(/[-_]+/g, ' ')\n .replace(/([a-z0-9])([A-Z])/g, '$1 $2')\n .replace(/\\s+/g, ' ')\n .trim()\n .replace(/^./, first => first.toUpperCase());\n}\n\n/**\n * Best-effort type for accessors that did not declare one. Entities are not\n * required to annotate every member, so a sample row keeps a bare `@accessor()`\n * usable; a declared `type` always wins over this.\n */\nfunction inferType(name: string, value: unknown): MetaAccessorType {\n if (value instanceof EntityLink) return 'link';\n if (value instanceof EntityCollectionLink) return 'linkCollection';\n if (value instanceof Date) return 'date';\n if (typeof value === 'number') return 'number';\n if (typeof value === 'boolean') return 'boolean';\n if (name === 'id') return 'id';\n return 'string';\n}\n\n/**\n * A collection member declared queryable is always a mistake, so it breaks the\n * developer rather than the query — the same posture as `applyEntityLinks`\n * throwing on an `embedded` link it cannot build.\n *\n * Silently clamping to `false` was the alternative and is worse: the author\n * keeps a declaration that reads as honoured, and the symptom is an empty\n * result page rather than an error anyone can act on.\n */\nfunction assertNotQueryable(\n metaAccessor: MetaAccessor,\n type: MetaAccessorType,\n) {\n if (!COLLECTION_TYPES.includes(type)) return;\n if (metaAccessor.sortable !== true && metaAccessor.filterable !== true)\n return;\n throw new Error(\n `\"${String(metaAccessor.name)}\" is a ${type} and cannot be sortable or filterable — member metadata is the server-side query allowlist, and a collection compared as a scalar matches nothing.`,\n );\n}\n\n/**\n * Item counts belong to a collection, and must be counts. A `minItems` on a\n * string would read as honoured and constrain nothing.\n */\nfunction assertItemCounts(metaAccessor: MetaAccessor, type: MetaAccessorType) {\n const { minItems, maxItems } = metaAccessor;\n if (minItems === undefined && maxItems === undefined) return;\n const name = String(metaAccessor.name);\n if (!COLLECTION_TYPES.includes(type)) {\n throw new Error(\n `\"${name}\" is a ${type}, and only a collection can declare minItems or maxItems.`,\n );\n }\n assertBounds(`\"${name}\"`, { min: minItems, max: maxItems });\n}\n\n/**\n * `notBefore` compares two instants, so both ends must be `date` members of\n * the same entity. Checked once every member is described, since the one it\n * names may be declared after it.\n */\nfunction assertNotBefore(descriptors: readonly EntityFieldDescriptor[]) {\n for (const descriptor of descriptors) {\n if (descriptor.notBefore === undefined) continue;\n const earlier = descriptors.find(\n other => other.name === descriptor.notBefore,\n );\n if (descriptor.type !== 'date' || earlier?.type !== 'date') {\n throw new Error(\n `\"${descriptor.name}\" declares notBefore \"${descriptor.notBefore}\", and both must be date members of the entity.`,\n );\n }\n }\n}\n\n/**\n * A parent is one record's id, so it is an `id` or a `string` member — a\n * number or a date cannot name a record, and a collection would be two\n * parents. Checked per member, since the type is only known once inferred.\n */\nfunction assertParentType(metaAccessor: MetaAccessor, type: MetaAccessorType) {\n if (metaAccessor.parent !== true) return;\n if (type === 'id' || type === 'string') return;\n throw new Error(\n `\"${String(metaAccessor.name)}\" is a ${type} and cannot be the parent member — a parent is one record's id, so it is an id or a string.`,\n );\n}\n\n/** Money is a reading of a number; any other member declaring it is a mistake. */\nfunction assertMoneyType(metaAccessor: MetaAccessor, type: MetaAccessorType) {\n if (metaAccessor.money === undefined || type === 'number') return;\n throw new Error(\n `\"${String(metaAccessor.name)}\" is a ${type} and declares money — only a number member can be an amount.`,\n );\n}\n\n/** A width is a positive length; zero or less would never switch layouts. */\nfunction assertMinWidth(metaAccessor: MetaAccessor) {\n const { minWidth } = metaAccessor;\n if (minWidth === undefined || (Number.isFinite(minWidth) && minWidth > 0))\n return;\n throw new Error(\n `\"${String(metaAccessor.name)}\" declares minWidth ${String(minWidth)} — a column's narrowest width is a positive number of rem.`,\n );\n}\n\n/**\n * A `currencyMember` must be a visible `string` member of the same entity: a\n * hidden one never reaches the client, so the amount would print with no\n * currency and nothing would say why.\n */\nfunction assertCurrencyMembers(descriptors: readonly EntityFieldDescriptor[]) {\n for (const descriptor of descriptors) {\n const member = descriptor.money?.currencyMember;\n if (member === undefined) continue;\n const currency = descriptors.find(other => other.name === member);\n if (currency?.type !== 'string') {\n throw new Error(\n `\"${descriptor.name}\" reads its currency from \"${member}\", which must be a visible string member of the entity.`,\n );\n }\n }\n}\n\n/**\n * One parent member per entity. Two would be two trees over the same records,\n * and which one a table indents by would depend on declaration order.\n */\nexport function assertOneParent(\n members: readonly {\n readonly name: string | symbol;\n readonly parent?: boolean;\n }[],\n) {\n const parents = members.filter(member => member.parent === true);\n if (parents.length > 1) {\n throw new Error(\n `An entity declares one parent member at most; found ${parents.map(member => `\"${String(member.name)}\"`).join(', ')}.`,\n );\n }\n}\n\n/**\n * ⚠️ **A parent member must travel.** The serializer skips a `hidden` or\n * `readonly` member in both directions, so the parent key would not survive a\n * single trip over the wire and the tree would arrive flat, with nothing\n * failing. Hide it from a table or a form with a slot instead. Checked before\n * hidden members are dropped, since a hidden parent is exactly the one\n * describing would never see.\n */\nexport function assertParentVisible(\n members: readonly {\n readonly name: string | symbol;\n readonly parent?: boolean;\n readonly hidden?: boolean;\n readonly readonly?: boolean;\n }[],\n) {\n const stuck = members.find(\n member =>\n member.parent === true &&\n (member.hidden === true || member.readonly === true),\n );\n if (stuck === undefined) return;\n throw new Error(\n `\"${String(stuck.name)}\" is the parent member and is ${stuck.hidden === true ? 'hidden' : 'readonly'} — such a member is never serialized, so the tree would arrive flat. Hide it with a slot instead.`,\n );\n}\n\nfunction toDescriptor(\n metaAccessor: MetaAccessor,\n index: number,\n sample: unknown,\n): EntityFieldDescriptor {\n const name = String(metaAccessor.name);\n const type =\n metaAccessor.type ??\n inferType(name, (sample as Record<string, unknown> | undefined)?.[name]);\n assertNotQueryable(metaAccessor, type);\n assertItemCounts(metaAccessor, type);\n assertParentType(metaAccessor, type);\n assertMoneyType(metaAccessor, type);\n assertMinWidth(metaAccessor);\n // A localized member is queried one locale at a time (`name.en`), which\n // makes it as queryable as the text each locale holds.\n const isScalar = SCALAR_TYPES.includes(type) || type === 'localized';\n const linkLabelProperty = metaAccessor.linkLabelProperty ?? 'name';\n\n return {\n name,\n key: String(metaAccessor.alias ?? metaAccessor.name),\n label: metaAccessor.label ?? humanize(name),\n labelKey: metaAccessor.labelKey,\n type,\n sortable: metaAccessor.sortable ?? isScalar,\n filterable: metaAccessor.filterable ?? isScalar,\n order: metaAccessor.order ?? index,\n readonly: metaAccessor.readonly ?? false,\n required: metaAccessor.required ?? false,\n enumValues: metaAccessor.enumValues,\n enumLabelKey: metaAccessor.enumLabelKey,\n linkLabelProperty,\n linkSearchProperty: metaAccessor.linkSearchProperty ?? linkLabelProperty,\n linkSerialization: metaAccessor.linkSerialization ?? 'id',\n childType: metaAccessor.childType?.(),\n resetOnClone: metaAccessor.resetOnClone ?? false,\n minItems: metaAccessor.minItems,\n maxItems: metaAccessor.maxItems,\n notBefore: metaAccessor.notBefore,\n ...(metaAccessor.money === undefined ? {} : { money: metaAccessor.money }),\n ...(metaAccessor.minWidth === undefined\n ? {}\n : { minWidth: metaAccessor.minWidth }),\n ...(metaAccessor.card === undefined ? {} : { card: metaAccessor.card }),\n ...(metaAccessor.autocomplete === undefined\n ? {}\n : { autocomplete: metaAccessor.autocomplete }),\n parent: metaAccessor.parent ?? false,\n };\n}\n\n/**\n * Resolves an entity's displayable members from its accessor metadata, sorted by\n * `order` (declaration order when undeclared).\n *\n * Getter-kind and non-`hidden` mirror the filter {@link serializeEntity} walks,\n * minus its `readonly` exclusion: a read-only member is still worth showing,\n * it just cannot be written back.\n *\n * `sample` is an optional instance used only to infer the `type` of accessors\n * that did not declare one.\n *\n * The target is a {@link ChildConstructor} rather than an `EntityConstructor`,\n * which is wider than it looks: nothing here reads `id`, and a `composition`\n * member's child is a **value** with accessors and no identity. So the same\n * walk describes an entity and describes one row of the collection it owns,\n * from one implementation.\n */\nexport function describeEntityColumns<TTarget extends object>(\n entityConstructor: ChildConstructor<TTarget>,\n sample?: TTarget,\n): EntityFieldDescriptor[] {\n const seen = new Set<string>();\n assertParentVisible(extractMetaAccessors(entityConstructor));\n\n const descriptors = extractMetaAccessors(entityConstructor)\n .filter(metaAccessor => {\n if (metaAccessor.hidden || metaAccessor.kind !== 'getter') return false;\n const name = String(metaAccessor.name);\n if (seen.has(name)) return false;\n seen.add(name);\n return true;\n })\n .map((metaAccessor, index) => toDescriptor(metaAccessor, index, sample))\n .sort((left, right) => left.order - right.order);\n assertNotBefore(descriptors);\n assertCurrencyMembers(descriptors);\n assertOneParent(descriptors);\n return descriptors;\n}\n"],"names":["extractMetaAccessors","EntityCollectionLink","EntityLink","assertBounds","SCALAR_TYPES","COLLECTION_TYPES","humanize","name","replace","trim","first","toUpperCase","inferType","value","Date","assertNotQueryable","metaAccessor","type","includes","sortable","filterable","Error","String","assertItemCounts","minItems","maxItems","undefined","min","max","assertNotBefore","descriptors","descriptor","notBefore","earlier","find","other","assertParentType","parent","assertMoneyType","money","assertMinWidth","minWidth","Number","isFinite","assertCurrencyMembers","member","currencyMember","currency","assertOneParent","members","parents","filter","length","map","join","assertParentVisible","stuck","hidden","readonly","toDescriptor","index","sample","isScalar","linkLabelProperty","key","alias","label","labelKey","order","required","enumValues","enumLabelKey","linkSearchProperty","linkSerialization","childType","resetOnClone","card","autocomplete","describeEntityColumns","entityConstructor","seen","Set","kind","has","add","sort","left","right"],"mappings":";AAAA,SAASA,oBAAoB,QAAQ,sBAAsB;AAC3D,SAASC,oBAAoB,QAAQ,2CAA2C;AAChF,SA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/DwB,IAAI,CAAC,CAACC,MAAMC,QAAUD,KAAKlB,KAAK,GAAGmB,MAAMnB,KAAK;IACjDvC,gBAAgBC;IAChBc,sBAAsBd;IACtBkB,gBAAgBlB;IAChB,OAAOA;AACT"}
1
+ {"version":3,"sources":["../../../src/entity-definition/describe/describe-entity-columns.ts"],"sourcesContent":["import { extractMetaAccessors, findMetaEntity } from '../helpers/index.js';\nimport { EntityCollectionLink } from '../links/entity-collection-link/index.js';\nimport { EntityLink } from '../links/entity-link/index.js';\nimport { assertBounds } from '../meta-entities/bounds.js';\nimport {\n type CardRole,\n type ChildConstructor,\n type EntityLinkSerialization,\n type MemberReference,\n MetaAccessor,\n MetaAccessorType,\n type MoneyFormat,\n} from '../meta-entities/meta-accessor/index.js';\n\n/**\n * A displayable member of an entity, resolved from its accessor metadata. This\n * is the contract generic UI builds itself from — a table's columns today, a\n * form's fields later — so it stays framework-free and lives next to the\n * metadata it derives from.\n */\nexport interface EntityFieldDescriptor {\n /** Accessor name. The stable identity used by preferences and slots. */\n name: string;\n /** Wire/property key: `alias ?? name`. */\n key: string;\n label: string;\n /**\n * Catalog key for {@link label}, when the entity declared one. Resolution is\n * the presentation layer's job — core has no locale and no catalogs, and the\n * same descriptor feeds the server-side filter allowlist, where a translated\n * label would be meaningless.\n */\n labelKey?: string;\n type: MetaAccessorType;\n sortable: boolean;\n filterable: boolean;\n order: number;\n /** Cannot be written back. A form shows it but disables its input. */\n readonly: boolean;\n /** Must hold a value. A form rejects submit while it is empty. */\n required: boolean;\n enumValues?: readonly string[];\n /** Catalog prefix for {@link enumValues}; a value reads as `${enumLabelKey}.${value}`. */\n enumLabelKey?: string;\n /** Property of a `link` target used as its display label. */\n linkLabelProperty: string;\n /** Property of a `link` target a picker searches on. Defaults to the label. */\n linkSearchProperty: string;\n /** Whether a `link` writes back its foreign key or the inlined target. */\n linkSerialization: EntityLinkSerialization;\n /**\n * The class describing one row of a `composition` member, resolved from the\n * accessor's thunk. Absent on every other type.\n */\n childType?: ChildConstructor;\n /**\n * The member is dropped when the record is copied — a unique code, an audit\n * stamp. The identity member is always reset and is not flagged.\n */\n resetOnClone: boolean;\n /** The fewest values a collection member may hold. */\n minItems?: number;\n /** The most values a collection member may hold. */\n maxItems?: number;\n /** The `date` member this one may not precede. */\n notBefore?: string;\n /** The member is an amount of money, read as this declares. `number` members only. */\n money?: MoneyFormat;\n /** The narrowest the member's column reads at, in `rem`, when declared. */\n minWidth?: number;\n /** The part the member plays on a record's card, when declared. */\n card?: CardRole;\n /** The member's HTML autofill token, when declared. */\n autocomplete?: string;\n /** This member holds the parent record's id: the entity forms a tree. */\n parent?: boolean;\n /**\n * This member holds the id of a record of another entity, named `domain:key`.\n * A screen shows that record's name in its place.\n */\n references?: MemberReference;\n}\n\n/** Types whose values are scalars a user can meaningfully sort/filter on. */\nexport const SCALAR_TYPES: readonly MetaAccessorType[] = [\n 'string',\n 'number',\n 'boolean',\n 'date',\n 'enum',\n];\n\n/**\n * Types whose value is a collection. None of them may ever be sorted or\n * filtered: this descriptor is also the **server-side RSQL allowlist**, and an\n * array compared as a scalar matches nothing — so the query would not fail, it\n * would quietly return an empty page.\n *\n * Exported so `describe-entity-columns.spec.ts` can assert that this list,\n * {@link SCALAR_TYPES}, the two reference types and `localized` partition\n * `MetaAccessorTypes` exactly. Nothing in the repo guards `MetaAccessorType`\n * exhaustively — every switch over it has a `default` that treats the value as\n * a string — so that partition spec is what makes an eleventh type impossible\n * to add silently.\n */\nexport const COLLECTION_TYPES: readonly MetaAccessorType[] = [\n 'linkCollection',\n 'composition',\n 'scalarCollection',\n];\n\n/** `productCode` / `product-code` / `product_code` → `Product Code`. */\nfunction humanize(name: string): string {\n return name\n .replace(/[-_]+/g, ' ')\n .replace(/([a-z0-9])([A-Z])/g, '$1 $2')\n .replace(/\\s+/g, ' ')\n .trim()\n .replace(/^./, first => first.toUpperCase());\n}\n\n/**\n * Best-effort type for accessors that did not declare one. Entities are not\n * required to annotate every member, so a sample row keeps a bare `@accessor()`\n * usable; a declared `type` always wins over this.\n */\nfunction inferType(name: string, value: unknown): MetaAccessorType {\n if (value instanceof EntityLink) return 'link';\n if (value instanceof EntityCollectionLink) return 'linkCollection';\n if (value instanceof Date) return 'date';\n if (typeof value === 'number') return 'number';\n if (typeof value === 'boolean') return 'boolean';\n if (name === 'id') return 'id';\n return 'string';\n}\n\n/**\n * A collection member declared queryable is always a mistake, so it breaks the\n * developer rather than the query — the same posture as `applyEntityLinks`\n * throwing on an `embedded` link it cannot build.\n *\n * Silently clamping to `false` was the alternative and is worse: the author\n * keeps a declaration that reads as honoured, and the symptom is an empty\n * result page rather than an error anyone can act on.\n */\nfunction assertNotQueryable(\n metaAccessor: MetaAccessor,\n type: MetaAccessorType,\n) {\n if (!COLLECTION_TYPES.includes(type)) return;\n if (metaAccessor.sortable !== true && metaAccessor.filterable !== true)\n return;\n throw new Error(\n `\"${String(metaAccessor.name)}\" is a ${type} and cannot be sortable or filterable — member metadata is the server-side query allowlist, and a collection compared as a scalar matches nothing.`,\n );\n}\n\n/**\n * Item counts belong to a collection, and must be counts. A `minItems` on a\n * string would read as honoured and constrain nothing.\n */\nfunction assertItemCounts(metaAccessor: MetaAccessor, type: MetaAccessorType) {\n const { minItems, maxItems } = metaAccessor;\n if (minItems === undefined && maxItems === undefined) return;\n const name = String(metaAccessor.name);\n if (!COLLECTION_TYPES.includes(type)) {\n throw new Error(\n `\"${name}\" is a ${type}, and only a collection can declare minItems or maxItems.`,\n );\n }\n assertBounds(`\"${name}\"`, { min: minItems, max: maxItems });\n}\n\n/**\n * `notBefore` compares two instants, so both ends must be `date` members of\n * the same entity. Checked once every member is described, since the one it\n * names may be declared after it.\n */\nfunction assertNotBefore(descriptors: readonly EntityFieldDescriptor[]) {\n for (const descriptor of descriptors) {\n if (descriptor.notBefore === undefined) continue;\n const earlier = descriptors.find(\n other => other.name === descriptor.notBefore,\n );\n if (descriptor.type !== 'date' || earlier?.type !== 'date') {\n throw new Error(\n `\"${descriptor.name}\" declares notBefore \"${descriptor.notBefore}\", and both must be date members of the entity.`,\n );\n }\n }\n}\n\n/**\n * A parent is one record's id, so it is an `id` or a `string` member — a\n * number or a date cannot name a record, and a collection would be two\n * parents. Checked per member, since the type is only known once inferred.\n */\nfunction assertParentType(metaAccessor: MetaAccessor, type: MetaAccessorType) {\n if (metaAccessor.parent !== true) return;\n if (type === 'id' || type === 'string') return;\n throw new Error(\n `\"${String(metaAccessor.name)}\" is a ${type} and cannot be the parent member — a parent is one record's id, so it is an id or a string.`,\n );\n}\n\n/** A reference's entity, as `@entity({ domain, key })` names it: two kebab-case words. */\nconst REFERENCE_KEY = /^[a-z0-9]+(?:-[a-z0-9]+)*:[a-z0-9]+(?:-[a-z0-9]+)*$/;\n\n/**\n * A reference holds one record's id, so it is an `id` or a `string` member, and\n * names its target as `domain:key`. On the `parent` member it may only name the\n * entity itself — a parent is a record of the same entity, built into a tree —\n * which is what lets a list show a branch's parent by name.\n */\nfunction assertReference(\n target: ChildConstructor,\n metaAccessor: MetaAccessor,\n type: MetaAccessorType,\n) {\n const { references } = metaAccessor;\n if (references === undefined) return;\n const name = String(metaAccessor.name);\n if (type !== 'id' && type !== 'string') {\n throw new Error(\n `\"${name}\" is a ${type} and declares references — a reference holds one record's id, so it is an id or a string.`,\n );\n }\n if (!REFERENCE_KEY.test(references.entity)) {\n throw new Error(\n `\"${name}\" references \"${references.entity}\", which is not an entity's \"domain:key\" — the pair its @entity({ domain, key }) declares.`,\n );\n }\n const own = findMetaEntity(target);\n if (\n metaAccessor.parent === true &&\n references.entity !== `${own?.domain}:${own?.key}`\n ) {\n throw new Error(\n `\"${name}\" is the parent member and references \"${references.entity}\" — a parent is a record of the same entity, so it can only reference ${target.name} itself.`,\n );\n }\n}\n\n/** Members whose value can name a record: a text, a number, or a reference to one. */\nconst LABEL_TYPES: readonly MetaAccessorType[] = [\n 'string',\n 'number',\n 'localized',\n];\n\n/**\n * An entity's `labelMember` must be a visible member that holds one value a\n * person can read: a hidden one never reaches the client, and a collection is\n * many names. Checked against every accessor, since a hidden member is exactly\n * the one describing would never see.\n */\nfunction assertLabelMember(\n target: ChildConstructor,\n descriptors: readonly EntityFieldDescriptor[],\n) {\n const labelMember = findMetaEntity(target)?.labelMember;\n if (labelMember === undefined) return;\n const declared = extractMetaAccessors(target).some(\n metaAccessor => String(metaAccessor.name) === labelMember,\n );\n const descriptor = descriptors.find(other => other.name === labelMember);\n if (descriptor === undefined) {\n throw new Error(\n declared\n ? `${target.name} is called by \"${labelMember}\", which is hidden — a hidden member never reaches the client, so nothing could show the name.`\n : `${target.name} is called by \"${labelMember}\", which is not a member of the entity.`,\n );\n }\n if (\n descriptor.references === undefined &&\n !LABEL_TYPES.includes(descriptor.type)\n ) {\n throw new Error(\n `${target.name} is called by \"${labelMember}\", a ${descriptor.type} — a record is called by a string, a localized text, a number or a reference.`,\n );\n }\n}\n\n/** Money is a reading of a number; any other member declaring it is a mistake. */\nfunction assertMoneyType(metaAccessor: MetaAccessor, type: MetaAccessorType) {\n if (metaAccessor.money === undefined || type === 'number') return;\n throw new Error(\n `\"${String(metaAccessor.name)}\" is a ${type} and declares money — only a number member can be an amount.`,\n );\n}\n\n/** A width is a positive length; zero or less would never switch layouts. */\nfunction assertMinWidth(metaAccessor: MetaAccessor) {\n const { minWidth } = metaAccessor;\n if (minWidth === undefined || (Number.isFinite(minWidth) && minWidth > 0))\n return;\n throw new Error(\n `\"${String(metaAccessor.name)}\" declares minWidth ${String(minWidth)} — a column's narrowest width is a positive number of rem.`,\n );\n}\n\n/**\n * A `currencyMember` must be a visible `string` member of the same entity: a\n * hidden one never reaches the client, so the amount would print with no\n * currency and nothing would say why.\n */\nfunction assertCurrencyMembers(descriptors: readonly EntityFieldDescriptor[]) {\n for (const descriptor of descriptors) {\n const member = descriptor.money?.currencyMember;\n if (member === undefined) continue;\n const currency = descriptors.find(other => other.name === member);\n if (currency?.type !== 'string') {\n throw new Error(\n `\"${descriptor.name}\" reads its currency from \"${member}\", which must be a visible string member of the entity.`,\n );\n }\n }\n}\n\n/**\n * One parent member per entity. Two would be two trees over the same records,\n * and which one a table indents by would depend on declaration order.\n */\nexport function assertOneParent(\n members: readonly {\n readonly name: string | symbol;\n readonly parent?: boolean;\n }[],\n) {\n const parents = members.filter(member => member.parent === true);\n if (parents.length > 1) {\n throw new Error(\n `An entity declares one parent member at most; found ${parents.map(member => `\"${String(member.name)}\"`).join(', ')}.`,\n );\n }\n}\n\n/**\n * ⚠️ **A parent member must travel.** The serializer skips a `hidden` or\n * `readonly` member in both directions, so the parent key would not survive a\n * single trip over the wire and the tree would arrive flat, with nothing\n * failing. Hide it from a table or a form with a slot instead. Checked before\n * hidden members are dropped, since a hidden parent is exactly the one\n * describing would never see.\n */\nexport function assertParentVisible(\n members: readonly {\n readonly name: string | symbol;\n readonly parent?: boolean;\n readonly hidden?: boolean;\n readonly readonly?: boolean;\n }[],\n) {\n const stuck = members.find(\n member =>\n member.parent === true &&\n (member.hidden === true || member.readonly === true),\n );\n if (stuck === undefined) return;\n throw new Error(\n `\"${String(stuck.name)}\" is the parent member and is ${stuck.hidden === true ? 'hidden' : 'readonly'} — such a member is never serialized, so the tree would arrive flat. Hide it with a slot instead.`,\n );\n}\n\nfunction toDescriptor(\n target: ChildConstructor,\n metaAccessor: MetaAccessor,\n index: number,\n sample: unknown,\n): EntityFieldDescriptor {\n const name = String(metaAccessor.name);\n const type =\n metaAccessor.type ??\n inferType(name, (sample as Record<string, unknown> | undefined)?.[name]);\n assertNotQueryable(metaAccessor, type);\n assertItemCounts(metaAccessor, type);\n assertParentType(metaAccessor, type);\n assertReference(target, metaAccessor, type);\n assertMoneyType(metaAccessor, type);\n assertMinWidth(metaAccessor);\n // A localized member is queried one locale at a time (`name.en`), which\n // makes it as queryable as the text each locale holds.\n const isScalar = SCALAR_TYPES.includes(type) || type === 'localized';\n const linkLabelProperty = metaAccessor.linkLabelProperty ?? 'name';\n\n return {\n name,\n key: String(metaAccessor.alias ?? metaAccessor.name),\n label: metaAccessor.label ?? humanize(name),\n labelKey: metaAccessor.labelKey,\n type,\n sortable: metaAccessor.sortable ?? isScalar,\n filterable: metaAccessor.filterable ?? isScalar,\n order: metaAccessor.order ?? index,\n readonly: metaAccessor.readonly ?? false,\n required: metaAccessor.required ?? false,\n enumValues: metaAccessor.enumValues,\n enumLabelKey: metaAccessor.enumLabelKey,\n linkLabelProperty,\n linkSearchProperty: metaAccessor.linkSearchProperty ?? linkLabelProperty,\n linkSerialization: metaAccessor.linkSerialization ?? 'id',\n childType: metaAccessor.childType?.(),\n resetOnClone: metaAccessor.resetOnClone ?? false,\n minItems: metaAccessor.minItems,\n maxItems: metaAccessor.maxItems,\n notBefore: metaAccessor.notBefore,\n ...(metaAccessor.money === undefined ? {} : { money: metaAccessor.money }),\n ...(metaAccessor.minWidth === undefined\n ? {}\n : { minWidth: metaAccessor.minWidth }),\n ...(metaAccessor.card === undefined ? {} : { card: metaAccessor.card }),\n ...(metaAccessor.autocomplete === undefined\n ? {}\n : { autocomplete: metaAccessor.autocomplete }),\n parent: metaAccessor.parent ?? false,\n ...(metaAccessor.references === undefined\n ? {}\n : { references: metaAccessor.references }),\n };\n}\n\n/**\n * Resolves an entity's displayable members from its accessor metadata, sorted by\n * `order` (declaration order when undeclared).\n *\n * Getter-kind and non-`hidden` mirror the filter {@link serializeEntity} walks,\n * minus its `readonly` exclusion: a read-only member is still worth showing,\n * it just cannot be written back.\n *\n * `sample` is an optional instance used only to infer the `type` of accessors\n * that did not declare one.\n *\n * The target is a {@link ChildConstructor} rather than an `EntityConstructor`,\n * which is wider than it looks: nothing here reads `id`, and a `composition`\n * member's child is a **value** with accessors and no identity. So the same\n * walk describes an entity and describes one row of the collection it owns,\n * from one implementation.\n */\nexport function describeEntityColumns<TTarget extends object>(\n entityConstructor: ChildConstructor<TTarget>,\n sample?: TTarget,\n): EntityFieldDescriptor[] {\n const seen = new Set<string>();\n assertParentVisible(extractMetaAccessors(entityConstructor));\n\n const descriptors = extractMetaAccessors(entityConstructor)\n .filter(metaAccessor => {\n if (metaAccessor.hidden || metaAccessor.kind !== 'getter') return false;\n const name = String(metaAccessor.name);\n if (seen.has(name)) return false;\n seen.add(name);\n return true;\n })\n .map((metaAccessor, index) =>\n toDescriptor(entityConstructor, metaAccessor, index, sample),\n )\n .sort((left, right) => left.order - right.order);\n assertNotBefore(descriptors);\n assertCurrencyMembers(descriptors);\n assertOneParent(descriptors);\n assertLabelMember(entityConstructor, descriptors);\n return descriptors;\n}\n"],"names":["extractMetaAccessors","findMetaEntity","EntityCollectionLink","EntityLink","assertBounds","SCALAR_TYPES","COLLECTION_TYPES","humanize","name","replace","trim","first","toUpperCase","inferType","value","Date","assertNotQueryable","metaAccessor","type","includes","sortable","filterable","Error","String","assertItemCounts","minItems","maxItems","undefined","min","max","assertNotBefore","descriptors","descriptor","notBefore","earlier","find","other","assertParentType","parent","REFERENCE_KEY","assertReference","target","references","test","entity","own","domain","key","LABEL_TYPES","assertLabelMember","labelMember","declared","some","assertMoneyType","money","assertMinWidth","minWidth","Number","isFinite","assertCurrencyMembers","member","currencyMember","currency","assertOneParent","members","parents","filter","length","map","join","assertParentVisible","stuck","hidden","readonly","toDescriptor","index","sample","isScalar","linkLabelProperty","alias","label","labelKey","order","required","enumValues","enumLabelKey","linkSearchProperty","linkSerialization","childType","resetOnClone","card","autocomplete","describeEntityColumns","entityConstructor","seen","Set","kind","has","add","sort","left","right"],"mappings":";AAAA,SAASA,oBAAoB,EAAEC,cAAc,QAAQ,sBAAsB;AAC3E,SAASC,oBAAoB,QAAQ,2CAA2C;AAChF,SAASC,UAAU,QAAQ,gCAAgC;AAC3D,SAASC,YAAY,QAAQ,6BAA6B;AAgF1D,2EAA2E,GAC3E,OAAO,MAAMC,eAA4C;IACvD;IACA;IACA;IACA;IACA;CACD,CAAC;AAEF;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC,mBAAgD;IAC3D;IACA;IACA;CACD,CAAC;AAEF,sEAAsE,GACtE,SAASC,SAASC,IAAY;IAC5B,OAAOA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,CAAAA;QACN,IAAIA,aAAauD,MAAM,IAAIvD,aAAa+E,IAAI,KAAK,UAAU,OAAO;QAClE,MAAMxF,OAAOe,OAAON,aAAaT,IAAI;QACrC,IAAIsF,KAAKG,GAAG,CAACzF,OAAO,OAAO;QAC3BsF,KAAKI,GAAG,CAAC1F;QACT,OAAO;IACT,GACC4D,GAAG,CAAC,CAACnD,cAAc0D,QAClBD,aAAamB,mBAAmB5E,cAAc0D,OAAOC,SAEtDuB,IAAI,CAAC,CAACC,MAAMC,QAAUD,KAAKlB,KAAK,GAAGmB,MAAMnB,KAAK;IACjDpD,gBAAgBC;IAChB4B,sBAAsB5B;IACtBgC,gBAAgBhC;IAChBkB,kBAAkB4C,mBAAmB9D;IACrC,OAAOA;AACT"}
@@ -1,5 +1,5 @@
1
1
  import { Entity, EntityConstructor } from '../../types/Entity.js';
2
- import type { UseCaseBinding, UseCaseCell, UseCaseConfirm, UseCaseHierarchy, UseCasePlacement, UseCaseReversible } from '../meta-entities/meta-use-case/index.js';
2
+ import type { UseCaseAvailability, UseCaseBinding, UseCaseCell, UseCaseConfirm, UseCaseHierarchy, UseCasePlacement, UseCaseReversible } from '../meta-entities/meta-use-case/index.js';
3
3
  /**
4
4
  * An action a caller may take on an entity, resolved from its use-case
5
5
  * metadata. The counterpart to {@link EntityFieldDescriptor}, and like it,
@@ -22,6 +22,8 @@ export interface UseCaseDescriptor extends UseCaseHierarchy {
22
22
  reversible?: UseCaseReversible;
23
23
  /** The verb Undo runs, by key. */
24
24
  inverse?: string;
25
+ /** The states a record must be in for the verb to be offered on it. */
26
+ availableWhen?: UseCaseAvailability;
25
27
  form?: string;
26
28
  /** The named variant set this verb resolves between. */
27
29
  variants?: string;
@@ -54,4 +56,14 @@ export interface UseCaseComposition {
54
56
  * use-case implementation reaches a client bundle.
55
57
  */
56
58
  export declare function describeEntityUseCases<TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>): UseCaseDescriptor[];
59
+ /**
60
+ * Whether a surface offers `descriptor` on `record`: always, for a verb that
61
+ * declares no {@link UseCaseAvailability}; otherwise only once the record has
62
+ * arrived and its member holds one of the declared states. A record still in
63
+ * flight offers none of its state-bound verbs, rather than all of them for a
64
+ * moment.
65
+ *
66
+ * Presentation only — the verb's handler is what refuses an illegal move.
67
+ */
68
+ export declare function isUseCaseAvailable(descriptor: Pick<UseCaseDescriptor, 'availableWhen'>, record: object | undefined): boolean;
57
69
  //# sourceMappingURL=describe-entity-use-cases.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"describe-entity-use-cases.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/describe/describe-entity-use-cases.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAElE,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,yCAAyC,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAkB,SAAQ,gBAAgB;IACzD,sEAAsE;IACtE,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,cAAc,CAAC;IACxB,SAAS,EAAE,gBAAgB,CAAC;IAC5B,0EAA0E;IAC1E,MAAM,CAAC,EAAE,SAAS,WAAW,EAAE,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,qEAAqE;IACrE,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED,wEAAwE;AACxE,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0DAA0D;IAC1D,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC/B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,MAAM,EAC3D,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAC5C,iBAAiB,EAAE,CAmBrB"}
1
+ {"version":3,"file":"describe-entity-use-cases.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/describe/describe-entity-use-cases.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAElE,OAAO,KAAK,EACV,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,yCAAyC,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAkB,SAAQ,gBAAgB;IACzD,sEAAsE;IACtE,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,cAAc,CAAC;IACxB,SAAS,EAAE,gBAAgB,CAAC;IAC5B,0EAA0E;IAC1E,MAAM,CAAC,EAAE,SAAS,WAAW,EAAE,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,qEAAqE;IACrE,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,aAAa,CAAC,EAAE,mBAAmB,CAAC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED,wEAAwE;AACxE,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0DAA0D;IAC1D,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC/B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,MAAM,EAC3D,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAC5C,iBAAiB,EAAE,CAoBrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,IAAI,CAAC,iBAAiB,EAAE,eAAe,CAAC,EACpD,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,OAAO,CAQT"}
@@ -20,6 +20,7 @@ import { extractMetaUseCases } from '../helpers/index.js';
20
20
  confirm: metaUseCase.confirm,
21
21
  reversible: metaUseCase.reversible,
22
22
  inverse: metaUseCase.inverse,
23
+ availableWhen: metaUseCase.availableWhen,
23
24
  emphasis: metaUseCase.emphasis,
24
25
  priority: metaUseCase.priority,
25
26
  rowInline: metaUseCase.rowInline,
@@ -29,5 +30,20 @@ import { extractMetaUseCases } from '../helpers/index.js';
29
30
  recipe: metaUseCase.recipe
30
31
  }));
31
32
  }
33
+ /**
34
+ * Whether a surface offers `descriptor` on `record`: always, for a verb that
35
+ * declares no {@link UseCaseAvailability}; otherwise only once the record has
36
+ * arrived and its member holds one of the declared states. A record still in
37
+ * flight offers none of its state-bound verbs, rather than all of them for a
38
+ * moment.
39
+ *
40
+ * Presentation only — the verb's handler is what refuses an illegal move.
41
+ */ export function isUseCaseAvailable(descriptor, record) {
42
+ const availability = descriptor.availableWhen;
43
+ if (availability === undefined) return true;
44
+ if (record === undefined) return false;
45
+ const state = record[availability.member];
46
+ return typeof state === 'string' && availability.in.includes(state);
47
+ }
32
48
 
33
49
  //# sourceMappingURL=describe-entity-use-cases.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/entity-definition/describe/describe-entity-use-cases.ts"],"sourcesContent":["import { Entity, EntityConstructor } from '../../types/Entity.js';\nimport { extractMetaUseCases } from '../helpers/index.js';\nimport type {\n UseCaseBinding,\n UseCaseCell,\n UseCaseConfirm,\n UseCaseHierarchy,\n UseCasePlacement,\n UseCaseReversible,\n} from '../meta-entities/meta-use-case/index.js';\n\n/**\n * An action a caller may take on an entity, resolved from its use-case\n * metadata. The counterpart to {@link EntityFieldDescriptor}, and like it,\n * framework-free and copy-free — every human-readable member is a catalog key.\n *\n * It carries no `entity`: this is the shape that goes over the wire from\n * `GET /api/<entity>/$metadata`, where the entity is already the address.\n */\nexport interface UseCaseDescriptor extends UseCaseHierarchy {\n /** The verb. Also the third segment of the permission guarding it. */\n key: string;\n binding: UseCaseBinding;\n placement: UseCasePlacement;\n /** Further cells this same verb appears in — see `MetaUseCaseOptions`. */\n alsoAt?: readonly UseCaseCell[];\n labelKey: string;\n keywordsKey?: string;\n confirm?: UseCaseConfirm;\n /** How a destructive verb is made safe — see `UseCaseReversible`. */\n reversible?: UseCaseReversible;\n /** The verb Undo runs, by key. */\n inverse?: string;\n form?: string;\n /** The named variant set this verb resolves between. */\n variants?: string;\n /** The named recipe this verb starts a flow from. */\n recipe?: string;\n /**\n * What this verb resolves to **for the caller asking** — present only on a\n * served `$metadata` document, computed per principal.\n */\n composition?: UseCaseComposition;\n}\n\n/** Which variant, and which flow, a verb resolves to for one caller. */\nexport interface UseCaseComposition {\n useCase: string;\n variant: string;\n recipe?: string;\n slipVersion?: number;\n /** The `id@n` references the recipe can pin, in order. */\n fragments?: readonly string[];\n}\n\n/**\n * Resolves the use cases declared against an entity, in declaration order.\n *\n * Unlike {@link describeEntityColumns}, this is only trustworthy where the\n * use-case modules have been loaded: a `@useCase()` class registers itself when\n * its module evaluates. On a service that is the composition root's job, and\n * a host's register should fail the build on a class its package barrel does\n * not export.\n * A browser never calls this — it fetches the descriptors instead, so no\n * use-case implementation reaches a client bundle.\n */\nexport function describeEntityUseCases<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n): UseCaseDescriptor[] {\n return extractMetaUseCases(entityConstructor).map(metaUseCase => ({\n key: metaUseCase.key,\n binding: metaUseCase.binding,\n placement: metaUseCase.placement,\n alsoAt: metaUseCase.alsoAt,\n labelKey: metaUseCase.labelKey,\n keywordsKey: metaUseCase.keywordsKey,\n confirm: metaUseCase.confirm,\n reversible: metaUseCase.reversible,\n inverse: metaUseCase.inverse,\n emphasis: metaUseCase.emphasis,\n priority: metaUseCase.priority,\n rowInline: metaUseCase.rowInline,\n shortcut: metaUseCase.shortcut,\n form: metaUseCase.form,\n variants: metaUseCase.variants,\n recipe: metaUseCase.recipe,\n }));\n}\n"],"names":["extractMetaUseCases","describeEntityUseCases","entityConstructor","map","metaUseCase","key","binding","placement","alsoAt","labelKey","keywordsKey","confirm","reversible","inverse","emphasis","priority","rowInline","shortcut","form","variants","recipe"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,sBAAsB;AAsD1D;;;;;;;;;;CAUC,GACD,OAAO,SAASC,uBACdC,iBAA6C;IAE7C,OAAOF,oBAAoBE,mBAAmBC,GAAG,CAACC,CAAAA,cAAgB,CAAA;YAChEC,KAAKD,YAAYC,GAAG;YACpBC,SAASF,YAAYE,OAAO;YAC5BC,WAAWH,YAAYG,SAAS;YAChCC,QAAQJ,YAAYI,MAAM;YAC1BC,UAAUL,YAAYK,QAAQ;YAC9BC,aAAaN,YAAYM,WAAW;YACpCC,SAASP,YAAYO,OAAO;YAC5BC,YAAYR,YAAYQ,UAAU;YAClCC,SAAST,YAAYS,OAAO;YAC5BC,UAAUV,YAAYU,QAAQ;YAC9BC,UAAUX,YAAYW,QAAQ;YAC9BC,WAAWZ,YAAYY,SAAS;YAChCC,UAAUb,YAAYa,QAAQ;YAC9BC,MAAMd,YAAYc,IAAI;YACtBC,UAAUf,YAAYe,QAAQ;YAC9BC,QAAQhB,YAAYgB,MAAM;QAC5B,CAAA;AACF"}
1
+ {"version":3,"sources":["../../../src/entity-definition/describe/describe-entity-use-cases.ts"],"sourcesContent":["import { Entity, EntityConstructor } from '../../types/Entity.js';\nimport { extractMetaUseCases } from '../helpers/index.js';\nimport type {\n UseCaseAvailability,\n UseCaseBinding,\n UseCaseCell,\n UseCaseConfirm,\n UseCaseHierarchy,\n UseCasePlacement,\n UseCaseReversible,\n} from '../meta-entities/meta-use-case/index.js';\n\n/**\n * An action a caller may take on an entity, resolved from its use-case\n * metadata. The counterpart to {@link EntityFieldDescriptor}, and like it,\n * framework-free and copy-free — every human-readable member is a catalog key.\n *\n * It carries no `entity`: this is the shape that goes over the wire from\n * `GET /api/<entity>/$metadata`, where the entity is already the address.\n */\nexport interface UseCaseDescriptor extends UseCaseHierarchy {\n /** The verb. Also the third segment of the permission guarding it. */\n key: string;\n binding: UseCaseBinding;\n placement: UseCasePlacement;\n /** Further cells this same verb appears in — see `MetaUseCaseOptions`. */\n alsoAt?: readonly UseCaseCell[];\n labelKey: string;\n keywordsKey?: string;\n confirm?: UseCaseConfirm;\n /** How a destructive verb is made safe — see `UseCaseReversible`. */\n reversible?: UseCaseReversible;\n /** The verb Undo runs, by key. */\n inverse?: string;\n /** The states a record must be in for the verb to be offered on it. */\n availableWhen?: UseCaseAvailability;\n form?: string;\n /** The named variant set this verb resolves between. */\n variants?: string;\n /** The named recipe this verb starts a flow from. */\n recipe?: string;\n /**\n * What this verb resolves to **for the caller asking** — present only on a\n * served `$metadata` document, computed per principal.\n */\n composition?: UseCaseComposition;\n}\n\n/** Which variant, and which flow, a verb resolves to for one caller. */\nexport interface UseCaseComposition {\n useCase: string;\n variant: string;\n recipe?: string;\n slipVersion?: number;\n /** The `id@n` references the recipe can pin, in order. */\n fragments?: readonly string[];\n}\n\n/**\n * Resolves the use cases declared against an entity, in declaration order.\n *\n * Unlike {@link describeEntityColumns}, this is only trustworthy where the\n * use-case modules have been loaded: a `@useCase()` class registers itself when\n * its module evaluates. On a service that is the composition root's job, and\n * a host's register should fail the build on a class its package barrel does\n * not export.\n * A browser never calls this — it fetches the descriptors instead, so no\n * use-case implementation reaches a client bundle.\n */\nexport function describeEntityUseCases<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n): UseCaseDescriptor[] {\n return extractMetaUseCases(entityConstructor).map(metaUseCase => ({\n key: metaUseCase.key,\n binding: metaUseCase.binding,\n placement: metaUseCase.placement,\n alsoAt: metaUseCase.alsoAt,\n labelKey: metaUseCase.labelKey,\n keywordsKey: metaUseCase.keywordsKey,\n confirm: metaUseCase.confirm,\n reversible: metaUseCase.reversible,\n inverse: metaUseCase.inverse,\n availableWhen: metaUseCase.availableWhen,\n emphasis: metaUseCase.emphasis,\n priority: metaUseCase.priority,\n rowInline: metaUseCase.rowInline,\n shortcut: metaUseCase.shortcut,\n form: metaUseCase.form,\n variants: metaUseCase.variants,\n recipe: metaUseCase.recipe,\n }));\n}\n\n/**\n * Whether a surface offers `descriptor` on `record`: always, for a verb that\n * declares no {@link UseCaseAvailability}; otherwise only once the record has\n * arrived and its member holds one of the declared states. A record still in\n * flight offers none of its state-bound verbs, rather than all of them for a\n * moment.\n *\n * Presentation only — the verb's handler is what refuses an illegal move.\n */\nexport function isUseCaseAvailable(\n descriptor: Pick<UseCaseDescriptor, 'availableWhen'>,\n record: object | undefined,\n): boolean {\n const availability = descriptor.availableWhen;\n if (availability === undefined) return true;\n if (record === undefined) return false;\n const state = (record as Readonly<Record<string, unknown>>)[\n availability.member\n ];\n return typeof state === 'string' && availability.in.includes(state);\n}\n"],"names":["extractMetaUseCases","describeEntityUseCases","entityConstructor","map","metaUseCase","key","binding","placement","alsoAt","labelKey","keywordsKey","confirm","reversible","inverse","availableWhen","emphasis","priority","rowInline","shortcut","form","variants","recipe","isUseCaseAvailable","descriptor","record","availability","undefined","state","member","in","includes"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,sBAAsB;AAyD1D;;;;;;;;;;CAUC,GACD,OAAO,SAASC,uBACdC,iBAA6C;IAE7C,OAAOF,oBAAoBE,mBAAmBC,GAAG,CAACC,CAAAA,cAAgB,CAAA;YAChEC,KAAKD,YAAYC,GAAG;YACpBC,SAASF,YAAYE,OAAO;YAC5BC,WAAWH,YAAYG,SAAS;YAChCC,QAAQJ,YAAYI,MAAM;YAC1BC,UAAUL,YAAYK,QAAQ;YAC9BC,aAAaN,YAAYM,WAAW;YACpCC,SAASP,YAAYO,OAAO;YAC5BC,YAAYR,YAAYQ,UAAU;YAClCC,SAAST,YAAYS,OAAO;YAC5BC,eAAeV,YAAYU,aAAa;YACxCC,UAAUX,YAAYW,QAAQ;YAC9BC,UAAUZ,YAAYY,QAAQ;YAC9BC,WAAWb,YAAYa,SAAS;YAChCC,UAAUd,YAAYc,QAAQ;YAC9BC,MAAMf,YAAYe,IAAI;YACtBC,UAAUhB,YAAYgB,QAAQ;YAC9BC,QAAQjB,YAAYiB,MAAM;QAC5B,CAAA;AACF;AAEA;;;;;;;;CAQC,GACD,OAAO,SAASC,mBACdC,UAAoD,EACpDC,MAA0B;IAE1B,MAAMC,eAAeF,WAAWT,aAAa;IAC7C,IAAIW,iBAAiBC,WAAW,OAAO;IACvC,IAAIF,WAAWE,WAAW,OAAO;IACjC,MAAMC,QAAQ,AAACH,MAA4C,CACzDC,aAAaG,MAAM,CACpB;IACD,OAAO,OAAOD,UAAU,YAAYF,aAAaI,EAAE,CAACC,QAAQ,CAACH;AAC/D"}
@@ -3,4 +3,5 @@ export * from './describe-entity-columns.js';
3
3
  export * from './describe-entity-use-cases.js';
4
4
  export * from './entity-view.js';
5
5
  export * from './query-property.js';
6
+ export * from './record-label.js';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/describe/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/describe/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC"}
@@ -3,5 +3,6 @@ export * from './describe-entity-columns.js';
3
3
  export * from './describe-entity-use-cases.js';
4
4
  export * from './entity-view.js';
5
5
  export * from './query-property.js';
6
+ export * from './record-label.js';
6
7
 
7
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/entity-definition/describe/index.ts"],"sourcesContent":["export * from './describe-child-columns.js';\nexport * from './describe-entity-columns.js';\nexport * from './describe-entity-use-cases.js';\nexport * from './entity-view.js';\nexport * from './query-property.js';\n"],"names":[],"mappings":"AAAA,cAAc,8BAA8B;AAC5C,cAAc,+BAA+B;AAC7C,cAAc,iCAAiC;AAC/C,cAAc,mBAAmB;AACjC,cAAc,sBAAsB"}
1
+ {"version":3,"sources":["../../../src/entity-definition/describe/index.ts"],"sourcesContent":["export * from './describe-child-columns.js';\nexport * from './describe-entity-columns.js';\nexport * from './describe-entity-use-cases.js';\nexport * from './entity-view.js';\nexport * from './query-property.js';\nexport * from './record-label.js';\n"],"names":[],"mappings":"AAAA,cAAc,8BAA8B;AAC5C,cAAc,+BAA+B;AAC7C,cAAc,iCAAiC;AAC/C,cAAc,mBAAmB;AACjC,cAAc,sBAAsB;AACpC,cAAc,oBAAoB"}
@@ -0,0 +1,69 @@
1
+ import type { Entity, EntityConstructor } from '../../types/Entity.js';
2
+ import type { ChildConstructor } from '../meta-entities/meta-accessor/index.js';
3
+ import { type EntityFieldDescriptor } from './describe-entity-columns.js';
4
+ /** How many characters of a long id a fallback label shows. A whole UUID never reads. */
5
+ export declare const SHORT_ID_LENGTH = 8;
6
+ /**
7
+ * What a record is called, before it is put into words. Core knows neither the
8
+ * reader's locale nor the entity's translated noun, so it answers with what to
9
+ * show and leaves the words to the presentation layer:
10
+ *
11
+ * - `value` — a member's own value, read through its descriptor (a localized
12
+ * text in the reader's locale, a number formatted);
13
+ * - `reference` — the name of the record another entity holds under `id`,
14
+ * which the host's reference registry resolves;
15
+ * - `fallback` — nothing names the record: the entity's noun with
16
+ * {@link shortId} of its id, when it has one.
17
+ */
18
+ export type RecordLabel = {
19
+ readonly kind: 'value';
20
+ readonly member: EntityFieldDescriptor;
21
+ readonly value: unknown;
22
+ } | {
23
+ readonly kind: 'reference';
24
+ readonly member: EntityFieldDescriptor;
25
+ readonly entity: string;
26
+ readonly id: string;
27
+ } | {
28
+ readonly kind: 'fallback';
29
+ readonly shortId?: string;
30
+ };
31
+ /**
32
+ * Whether a member can name a record it was not declared to name. One that
33
+ * holds a key or a list never can: an id, a reference and a link are keys,
34
+ * and a collection is many values.
35
+ */
36
+ export declare function canNameRecord(descriptor: EntityFieldDescriptor): boolean;
37
+ /**
38
+ * What a record is called — the **one derivation** every surface that names a
39
+ * record goes through: a row's title and checkbox, a card's heading, a confirm
40
+ * dialog's object, a breadcrumb, a toast, the typed delete policy. In order:
41
+ *
42
+ * 1. the entity's declared `labelMember`, or the member it declares the card's
43
+ * `title`, when filled in — a reference is answered as one, to resolve;
44
+ * 2. the first filled-in member that is neither an id, a reference, a link nor
45
+ * a collection;
46
+ * 3. the fallback: the noun and the id's {@link shortId}.
47
+ *
48
+ * `record` is read by member name, so an entity instance, a plain record and a
49
+ * form's draft all work; a record not loaded yet is called by the noun alone.
50
+ */
51
+ export declare function recordLabel(entityConstructor: ChildConstructor, record: object | undefined): RecordLabel;
52
+ /**
53
+ * Ids no longer than this are quoted whole: `offering-12` cut to eight
54
+ * characters would name every offering alike, while a UUID is never short.
55
+ */
56
+ export declare const SHORT_ID_WHOLE = 12;
57
+ /**
58
+ * What a label quotes of an id when nothing names the record: a short id
59
+ * whole, a long one cut to its first {@link SHORT_ID_LENGTH} characters.
60
+ */
61
+ export declare function shortId(id: string): string;
62
+ /**
63
+ * The `domain:key` an entity is referenced by — the pair its
64
+ * `@entity({ domain, key })` declares, which is also its permission namespace.
65
+ * Throws for an entity that declares only one of them: nothing could reference
66
+ * it.
67
+ */
68
+ export declare function entityReferenceKey<TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>): string;
69
+ //# sourceMappingURL=record-label.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record-label.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/describe/record-label.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAEvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAChF,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,8BAA8B,CAAC;AAEtC,yFAAyF;AACzF,eAAO,MAAM,eAAe,IAAI,CAAC;AAEjC;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,WAAW,GACnB;IACE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;IACvC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAyB7D;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,qBAAqB,GAAG,OAAO,CAOxE;AAgBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CACzB,iBAAiB,EAAE,gBAAgB,EACnC,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,WAAW,CAwBb;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,KAAK,CAAC;AAEjC;;;GAGG;AACH,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAE1C;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,SAAS,MAAM,EACvD,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAC5C,MAAM,CAQR"}
@@ -0,0 +1,97 @@
1
+ import { extractMetaEntity, findMetaEntity } from '../helpers/index.js';
2
+ import { COLLECTION_TYPES, describeEntityColumns } from './describe-entity-columns.js';
3
+ /** How many characters of a long id a fallback label shows. A whole UUID never reads. */ export const SHORT_ID_LENGTH = 8;
4
+ const described = new WeakMap();
5
+ function descriptorsOf(target) {
6
+ let descriptors = described.get(target);
7
+ if (descriptors === undefined) {
8
+ descriptors = describeEntityColumns(target);
9
+ described.set(target, descriptors);
10
+ }
11
+ return descriptors;
12
+ }
13
+ /** Holds something a person could read: not empty, and a localized text in at least one locale. */ function isFilled(descriptor, value) {
14
+ if (value === undefined || value === null || value === '') return false;
15
+ if (descriptor.type === 'localized') {
16
+ return typeof value === 'object' && Object.values(value).some((text)=>typeof text === 'string' && text !== '');
17
+ }
18
+ return true;
19
+ }
20
+ /**
21
+ * Whether a member can name a record it was not declared to name. One that
22
+ * holds a key or a list never can: an id, a reference and a link are keys,
23
+ * and a collection is many values.
24
+ */ export function canNameRecord(descriptor) {
25
+ return descriptor.type !== 'id' && descriptor.type !== 'link' && descriptor.references === undefined && !COLLECTION_TYPES.includes(descriptor.type);
26
+ }
27
+ function labelFrom(descriptor, value) {
28
+ return descriptor.references === undefined ? {
29
+ kind: 'value',
30
+ member: descriptor,
31
+ value
32
+ } : {
33
+ kind: 'reference',
34
+ member: descriptor,
35
+ entity: descriptor.references.entity,
36
+ id: String(value)
37
+ };
38
+ }
39
+ /**
40
+ * What a record is called — the **one derivation** every surface that names a
41
+ * record goes through: a row's title and checkbox, a card's heading, a confirm
42
+ * dialog's object, a breadcrumb, a toast, the typed delete policy. In order:
43
+ *
44
+ * 1. the entity's declared `labelMember`, or the member it declares the card's
45
+ * `title`, when filled in — a reference is answered as one, to resolve;
46
+ * 2. the first filled-in member that is neither an id, a reference, a link nor
47
+ * a collection;
48
+ * 3. the fallback: the noun and the id's {@link shortId}.
49
+ *
50
+ * `record` is read by member name, so an entity instance, a plain record and a
51
+ * form's draft all work; a record not loaded yet is called by the noun alone.
52
+ */ export function recordLabel(entityConstructor, record) {
53
+ var _ref;
54
+ var _findMetaEntity, _descriptors_find;
55
+ const values = record != null ? record : {};
56
+ const descriptors = descriptorsOf(entityConstructor);
57
+ const declaredName = (_ref = (_findMetaEntity = findMetaEntity(entityConstructor)) == null ? void 0 : _findMetaEntity.labelMember) != null ? _ref : (_descriptors_find = descriptors.find((descriptor)=>descriptor.card === 'title')) == null ? void 0 : _descriptors_find.name;
58
+ const declared = descriptors.find((descriptor)=>descriptor.name === declaredName);
59
+ if (declared !== undefined && isFilled(declared, values[declared.name])) {
60
+ return labelFrom(declared, values[declared.name]);
61
+ }
62
+ const undeclared = descriptors.find((descriptor)=>canNameRecord(descriptor) && isFilled(descriptor, values[descriptor.name]));
63
+ if (undeclared !== undefined) {
64
+ return labelFrom(undeclared, values[undeclared.name]);
65
+ }
66
+ const id = values['id'];
67
+ return id === undefined || id === null || id === '' ? {
68
+ kind: 'fallback'
69
+ } : {
70
+ kind: 'fallback',
71
+ shortId: shortId(String(id))
72
+ };
73
+ }
74
+ /**
75
+ * Ids no longer than this are quoted whole: `offering-12` cut to eight
76
+ * characters would name every offering alike, while a UUID is never short.
77
+ */ export const SHORT_ID_WHOLE = 12;
78
+ /**
79
+ * What a label quotes of an id when nothing names the record: a short id
80
+ * whole, a long one cut to its first {@link SHORT_ID_LENGTH} characters.
81
+ */ export function shortId(id) {
82
+ return id.length <= SHORT_ID_WHOLE ? id : id.slice(0, SHORT_ID_LENGTH);
83
+ }
84
+ /**
85
+ * The `domain:key` an entity is referenced by — the pair its
86
+ * `@entity({ domain, key })` declares, which is also its permission namespace.
87
+ * Throws for an entity that declares only one of them: nothing could reference
88
+ * it.
89
+ */ export function entityReferenceKey(entityConstructor) {
90
+ const { domain, key, name } = extractMetaEntity(entityConstructor);
91
+ if (domain === undefined || key === undefined) {
92
+ throw new Error(`${name} needs both a domain and a key to be referenced — a reference names its target as "domain:key".`);
93
+ }
94
+ return `${domain}:${key}`;
95
+ }
96
+
97
+ //# sourceMappingURL=record-label.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/entity-definition/describe/record-label.ts"],"sourcesContent":["import type { Entity, EntityConstructor } from '../../types/Entity.js';\nimport { extractMetaEntity, findMetaEntity } from '../helpers/index.js';\nimport type { ChildConstructor } from '../meta-entities/meta-accessor/index.js';\nimport {\n COLLECTION_TYPES,\n describeEntityColumns,\n type EntityFieldDescriptor,\n} from './describe-entity-columns.js';\n\n/** How many characters of a long id a fallback label shows. A whole UUID never reads. */\nexport const SHORT_ID_LENGTH = 8;\n\n/**\n * What a record is called, before it is put into words. Core knows neither the\n * reader's locale nor the entity's translated noun, so it answers with what to\n * show and leaves the words to the presentation layer:\n *\n * - `value` — a member's own value, read through its descriptor (a localized\n * text in the reader's locale, a number formatted);\n * - `reference` — the name of the record another entity holds under `id`,\n * which the host's reference registry resolves;\n * - `fallback` — nothing names the record: the entity's noun with\n * {@link shortId} of its id, when it has one.\n */\nexport type RecordLabel =\n | {\n readonly kind: 'value';\n readonly member: EntityFieldDescriptor;\n readonly value: unknown;\n }\n | {\n readonly kind: 'reference';\n readonly member: EntityFieldDescriptor;\n readonly entity: string;\n readonly id: string;\n }\n | { readonly kind: 'fallback'; readonly shortId?: string };\n\nconst described = new WeakMap<ChildConstructor, EntityFieldDescriptor[]>();\n\nfunction descriptorsOf(target: ChildConstructor): EntityFieldDescriptor[] {\n let descriptors = described.get(target);\n if (descriptors === undefined) {\n descriptors = describeEntityColumns(target);\n described.set(target, descriptors);\n }\n return descriptors;\n}\n\n/** Holds something a person could read: not empty, and a localized text in at least one locale. */\nfunction isFilled(descriptor: EntityFieldDescriptor, value: unknown): boolean {\n if (value === undefined || value === null || value === '') return false;\n if (descriptor.type === 'localized') {\n return (\n typeof value === 'object' &&\n Object.values(value).some(text => typeof text === 'string' && text !== '')\n );\n }\n return true;\n}\n\n/**\n * Whether a member can name a record it was not declared to name. One that\n * holds a key or a list never can: an id, a reference and a link are keys,\n * and a collection is many values.\n */\nexport function canNameRecord(descriptor: EntityFieldDescriptor): boolean {\n return (\n descriptor.type !== 'id' &&\n descriptor.type !== 'link' &&\n descriptor.references === undefined &&\n !COLLECTION_TYPES.includes(descriptor.type)\n );\n}\n\nfunction labelFrom(\n descriptor: EntityFieldDescriptor,\n value: unknown,\n): RecordLabel {\n return descriptor.references === undefined\n ? { kind: 'value', member: descriptor, value }\n : {\n kind: 'reference',\n member: descriptor,\n entity: descriptor.references.entity,\n id: String(value),\n };\n}\n\n/**\n * What a record is called — the **one derivation** every surface that names a\n * record goes through: a row's title and checkbox, a card's heading, a confirm\n * dialog's object, a breadcrumb, a toast, the typed delete policy. In order:\n *\n * 1. the entity's declared `labelMember`, or the member it declares the card's\n * `title`, when filled in — a reference is answered as one, to resolve;\n * 2. the first filled-in member that is neither an id, a reference, a link nor\n * a collection;\n * 3. the fallback: the noun and the id's {@link shortId}.\n *\n * `record` is read by member name, so an entity instance, a plain record and a\n * form's draft all work; a record not loaded yet is called by the noun alone.\n */\nexport function recordLabel(\n entityConstructor: ChildConstructor,\n record: object | undefined,\n): RecordLabel {\n const values = (record ?? {}) as Record<string, unknown>;\n const descriptors = descriptorsOf(entityConstructor);\n const declaredName =\n findMetaEntity(entityConstructor)?.labelMember ??\n descriptors.find(descriptor => descriptor.card === 'title')?.name;\n const declared = descriptors.find(\n descriptor => descriptor.name === declaredName,\n );\n if (declared !== undefined && isFilled(declared, values[declared.name])) {\n return labelFrom(declared, values[declared.name]);\n }\n const undeclared = descriptors.find(\n descriptor =>\n canNameRecord(descriptor) &&\n isFilled(descriptor, values[descriptor.name]),\n );\n if (undeclared !== undefined) {\n return labelFrom(undeclared, values[undeclared.name]);\n }\n const id = values['id'];\n return id === undefined || id === null || id === ''\n ? { kind: 'fallback' }\n : { kind: 'fallback', shortId: shortId(String(id)) };\n}\n\n/**\n * Ids no longer than this are quoted whole: `offering-12` cut to eight\n * characters would name every offering alike, while a UUID is never short.\n */\nexport const SHORT_ID_WHOLE = 12;\n\n/**\n * What a label quotes of an id when nothing names the record: a short id\n * whole, a long one cut to its first {@link SHORT_ID_LENGTH} characters.\n */\nexport function shortId(id: string): string {\n return id.length <= SHORT_ID_WHOLE ? id : id.slice(0, SHORT_ID_LENGTH);\n}\n\n/**\n * The `domain:key` an entity is referenced by — the pair its\n * `@entity({ domain, key })` declares, which is also its permission namespace.\n * Throws for an entity that declares only one of them: nothing could reference\n * it.\n */\nexport function entityReferenceKey<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n): string {\n const { domain, key, name } = extractMetaEntity(entityConstructor);\n if (domain === undefined || key === undefined) {\n throw new Error(\n `${name} needs both a domain and a key to be referenced — a reference names its target as \"domain:key\".`,\n );\n }\n return `${domain}:${key}`;\n}\n"],"names":["extractMetaEntity","findMetaEntity","COLLECTION_TYPES","describeEntityColumns","SHORT_ID_LENGTH","described","WeakMap","descriptorsOf","target","descriptors","get","undefined","set","isFilled","descriptor","value","type","Object","values","some","text","canNameRecord","references","includes","labelFrom","kind","member","entity","id","String","recordLabel","entityConstructor","record","declaredName","labelMember","find","card","name","declared","undeclared","shortId","SHORT_ID_WHOLE","length","slice","entityReferenceKey","domain","key","Error"],"mappings":"AACA,SAASA,iBAAiB,EAAEC,cAAc,QAAQ,sBAAsB;AAExE,SACEC,gBAAgB,EAChBC,qBAAqB,QAEhB,+BAA+B;AAEtC,uFAAuF,GACvF,OAAO,MAAMC,kBAAkB,EAAE;AA4BjC,MAAMC,YAAY,IAAIC;AAEtB,SAASC,cAAcC,MAAwB;IAC7C,IAAIC,cAAcJ,UAAUK,GAAG,CAACF;IAChC,IAAIC,gBAAgBE,WAAW;QAC7BF,cAAcN,sBAAsBK;QACpCH,UAAUO,GAAG,CAACJ,QAAQC;IACxB;IACA,OAAOA;AACT;AAEA,iGAAiG,GACjG,SAASI,SAASC,UAAiC,EAAEC,KAAc;IACjE,IAAIA,UAAUJ,aAAaI,UAAU,QAAQA,UAAU,IAAI,OAAO;IAClE,IAAID,WAAWE,IAAI,KAAK,aAAa;QACnC,OACE,OAAOD,UAAU,YACjBE,OAAOC,MAAM,CAACH,OAAOI,IAAI,CAACC,CAAAA,OAAQ,OAAOA,SAAS,YAAYA,SAAS;IAE3E;IACA,OAAO;AACT;AAEA;;;;CAIC,GACD,OAAO,SAASC,cAAcP,UAAiC;IAC7D,OACEA,WAAWE,IAAI,KAAK,QACpBF,WAAWE,IAAI,KAAK,UACpBF,WAAWQ,UAAU,KAAKX,aAC1B,CAACT,iBAAiBqB,QAAQ,CAACT,WAAWE,IAAI;AAE9C;AAEA,SAASQ,UACPV,UAAiC,EACjCC,KAAc;IAEd,OAAOD,WAAWQ,UAAU,KAAKX,YAC7B;QAAEc,MAAM;QAASC,QAAQZ;QAAYC;IAAM,IAC3C;QACEU,MAAM;QACNC,QAAQZ;QACRa,QAAQb,WAAWQ,UAAU,CAACK,MAAM;QACpCC,IAAIC,OAAOd;IACb;AACN;AAEA;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASe,YACdC,iBAAmC,EACnCC,MAA0B;;QAKxB/B,iBACAQ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,GAAGV,KAAK,+FAA+F,CAAC;IAE5G;IACA,OAAO,GAAGQ,OAAO,CAAC,EAAEC,KAAK;AAC3B"}
@@ -42,6 +42,11 @@ export declare function appendMetaUseCase<TEntity extends Entity>(target: Entity
42
42
  */
43
43
  export declare function setMetaUseCaseBinding(metadata: DecoratorMetadataObject | undefined, binding: MetaUseCaseBinding): void;
44
44
  export declare function extractMetaEntity<TEntity extends Entity>(target: EntityConstructor<TEntity>): MetaEntity;
45
+ /**
46
+ * The `@entity()` metadata of a class, or `undefined` for one that declares
47
+ * none — a `composition` member's child is described without it.
48
+ */
49
+ export declare function findMetaEntity(target: ChildConstructor): MetaEntity | undefined;
45
50
  /**
46
51
  * Every accessor declared on a class.
47
52
  *
@@ -1 +1 @@
1
- {"version":3,"file":"entity-definition-helpers.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/helpers/entity-definition-helpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EACL,KAAK,gBAAgB,EACrB,YAAY,EACb,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EACL,WAAW,EACX,kBAAkB,EACnB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,iBAAiB;QACzB,QAAQ,CAAC,QAAQ,EAAE,OAAO,MAAM,CAAC;KAClC;CACF;AAED,eAAO,MAAM,eAAe,eAAuB,CAAC;AACpD,eAAO,MAAM,iBAAiB,eAAyB,CAAC;AACxD,eAAO,MAAM,eAAe,eAAuB,CAAC;AACpD,eAAO,MAAM,iBAAiB,eAAwB,CAAC;AACvD,eAAO,MAAM,yBAAyB,eAA+B,CAAC;AAatE,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,uBAAuB,GAAG,SAAS,EAC7C,UAAU,EAAE,UAAU,QAGvB;AAED,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,uBAAuB,GAAG,SAAS,EAC7C,YAAY,EAAE,YAAY,QAM3B;AAED,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,uBAAuB,GAAG,SAAS,EAC7C,UAAU,EAAE,UAAU,QAKvB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,MAAM,EACtD,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAClC,WAAW,EAAE,WAAW,QA8CzB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,uBAAuB,GAAG,SAAS,EAC7C,OAAO,EAAE,kBAAkB,QAG5B;AAQD,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,MAAM,EACtD,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACjC,UAAU,CAOZ;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,GAAG,YAAY,EAAE,CAG7E;AAED,wBAAgB,kBAAkB,CAAC,OAAO,SAAS,MAAM,EACvD,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACjC,UAAU,EAAE,CAGd;AAED,8EAA8E;AAC9E,wBAAgB,mBAAmB,CAAC,OAAO,SAAS,MAAM,EACxD,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACjC,WAAW,EAAE,CAGf;AAED,2DAA2D;AAC3D,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,kBAAkB,GACzB,kBAAkB,CAYpB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,kBAAkB,GAAG,WAAW,CAQtE"}
1
+ {"version":3,"file":"entity-definition-helpers.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/helpers/entity-definition-helpers.ts"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,iBAAiB,CAAC,OAAO,SAAS,MAAM,EACtD,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACjC,UAAU,CAOZ;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,gBAAgB,GACvB,UAAU,GAAG,SAAS,CAExB;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,GAAG,YAAY,EAAE,CAG7E;AAED,wBAAgB,kBAAkB,CAAC,OAAO,SAAS,MAAM,EACvD,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACjC,UAAU,EAAE,CAGd;AAED,8EAA8E;AAC9E,wBAAgB,mBAAmB,CAAC,OAAO,SAAS,MAAM,EACxD,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACjC,WAAW,EAAE,CAGf;AAED,2DAA2D;AAC3D,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,kBAAkB,GACzB,kBAAkB,CAYpB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,kBAAkB,GAAG,WAAW,CAQtE"}
@@ -61,6 +61,9 @@ export function appendMetaMethod(metadata, metaMethod) {
61
61
  if (metaUseCase.reversible === 'undo' && metaUseCase.inverse === undefined) {
62
62
  throw new Error(`Use case "${metaUseCase.key}" on ${target.name} is reversible by undo and names no \`inverse\`: Undo has nothing to run.`);
63
63
  }
64
+ if (metaUseCase.availableWhen !== undefined) {
65
+ assertAvailability(target, metaUseCase, metaUseCase.availableWhen);
66
+ }
64
67
  // A shortcut is checked where it is declared, so a chord no reader can use
65
68
  // — a bare key, Option+letter, Mod+C — fails at load rather than on a page.
66
69
  if (metaUseCase.shortcut !== undefined) {
@@ -84,6 +87,33 @@ export function appendMetaMethod(metadata, metaMethod) {
84
87
  metaUseCase
85
88
  ];
86
89
  }
90
+ /**
91
+ * A verb's states are checked where they are declared, against the entity's
92
+ * own member: a misspelt member or state would otherwise hide the verb on every
93
+ * record, which reads as a missing grant rather than a typo.
94
+ */ function assertAvailability(target, { key, binding, alsoAt }, availableWhen) {
95
+ const where = `Use case "${key}" on ${target.name}`;
96
+ // A selection carries no states, so the collection surfaces offer every
97
+ // verb; a verb with no record-bound cell would declare states nothing reads.
98
+ const recordBound = binding === 'entity' || (alsoAt != null ? alsoAt : []).some((cell)=>cell.binding === 'entity');
99
+ if (!recordBound) {
100
+ throw new Error(`${where} declares \`availableWhen\` and sits on no record: a selection carries no states, so nothing would read them.`);
101
+ }
102
+ const member = extractMetaAccessors(target).find((accessor)=>accessor.name === availableWhen.member);
103
+ if ((member == null ? void 0 : member.enumValues) === undefined) {
104
+ throw new Error(`${where} is available when "${availableWhen.member}" holds a state, and ${target.name} has no enum member by that name.`);
105
+ }
106
+ if (availableWhen.in.length === 0) {
107
+ throw new Error(`${where} is available in no state of "${availableWhen.member}": a verb that is never offered is a verb to delete.`);
108
+ }
109
+ const unknown = availableWhen.in.filter((state)=>{
110
+ var _member_enumValues;
111
+ return !((_member_enumValues = member.enumValues) == null ? void 0 : _member_enumValues.includes(state));
112
+ });
113
+ if (unknown.length > 0) {
114
+ throw new Error(`${where} names ${unknown.map((state)=>`"${state}"`).join(', ')}, which "${availableWhen.member}" does not hold.`);
115
+ }
116
+ }
87
117
  /**
88
118
  * Record on the use-case class itself which entity and verb it implements, so
89
119
  * the permission can be derived from the class alone. That is what keeps the
@@ -104,6 +134,13 @@ export function extractMetaEntity(target) {
104
134
  }
105
135
  return metaEntity;
106
136
  }
137
+ /**
138
+ * The `@entity()` metadata of a class, or `undefined` for one that declares
139
+ * none — a `composition` member's child is described without it.
140
+ */ export function findMetaEntity(target) {
141
+ var _readMetadata;
142
+ return (_readMetadata = readMetadata(target)) == null ? void 0 : _readMetadata[META_ENTITY_KEY];
143
+ }
107
144
  /**
108
145
  * Every accessor declared on a class.
109
146
  *
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/entity-definition/helpers/entity-definition-helpers.ts"],"sourcesContent":["(Symbol as { metadata?: symbol }).metadata ??= Symbol.for('Symbol.metadata');\n\nimport { assertChord } from '../../shortcut/chord.js';\nimport { Entity, EntityConstructor } from '../../types/Entity.js';\nimport { UseCaseConstructor } from '../../types/UseCase.js';\nimport {\n type ChildConstructor,\n MetaAccessor,\n} from '../meta-entities/meta-accessor/index.js';\nimport { MetaEntity } from '../meta-entities/meta-entity/index.js';\nimport { MetaMethod } from '../meta-entities/meta-method/index.js';\nimport {\n MetaUseCase,\n MetaUseCaseBinding,\n} from '../meta-entities/meta-use-case/index.js';\n\ndeclare global {\n interface SymbolConstructor {\n readonly metadata: unique symbol;\n }\n}\n\nexport const META_ENTITY_KEY = Symbol('MetaEntity');\nexport const META_ACCESSOR_KEY = Symbol('MetaAccessor');\nexport const META_METHOD_KEY = Symbol('MetaMethod');\nexport const META_USE_CASE_KEY = Symbol('MetaUseCase');\nexport const META_USE_CASE_BINDING_KEY = Symbol('MetaUseCaseBinding');\n\nfunction requireMetadata(\n metadata: DecoratorMetadataObject | undefined,\n): DecoratorMetadataObject {\n if (!metadata) {\n throw new Error(\n 'Decorator metadata unavailable — Symbol.metadata polyfill missing or stage-3 decorator emit not enabled.',\n );\n }\n return metadata;\n}\n\nexport function setMetaEntity(\n metadata: DecoratorMetadataObject | undefined,\n metaEntity: MetaEntity,\n) {\n requireMetadata(metadata)[META_ENTITY_KEY] = metaEntity;\n}\n\nexport function appendMetaAccessor(\n metadata: DecoratorMetadataObject | undefined,\n metaAccessor: MetaAccessor,\n) {\n const meta = requireMetadata(metadata);\n const existing =\n (meta[META_ACCESSOR_KEY] as MetaAccessor[] | undefined) ?? [];\n meta[META_ACCESSOR_KEY] = [...existing, metaAccessor];\n}\n\nexport function appendMetaMethod(\n metadata: DecoratorMetadataObject | undefined,\n metaMethod: MetaMethod,\n) {\n const meta = requireMetadata(metadata);\n const existing = (meta[META_METHOD_KEY] as MetaMethod[] | undefined) ?? [];\n meta[META_METHOD_KEY] = [...existing, metaMethod];\n}\n\n/**\n * Append a use case to the metadata of the entity it acts on.\n *\n * This is the one decorator that writes a bag other than its own: a use case is\n * declared on its own class, but the entity is what a surface holds, so the\n * descriptor has to end up there. The consequence is that a use-case module\n * which is never imported leaves the entity looking as if it had no actions,\n * which is why a host's register should assert every `@useCase()` class is\n * re-exported from its package barrel.\n *\n * It reads the target's **own** metadata rather than going through\n * {@link readMetadata}. `Symbol.metadata` resolves along the prototype chain, so\n * an inherited read would append the verb to a base class's bag and leak it to\n * every subclass. A target with no own metadata is an entity missing\n * `@entity()`, or a circular import that evaluated the use case first.\n */\nexport function appendMetaUseCase<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n metaUseCase: MetaUseCase,\n) {\n const own = Object.getOwnPropertyDescriptor(target, Symbol.metadata)\n ?.value as DecoratorMetadataObject | null | undefined;\n if (!own) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" targets ${target.name}, which has no metadata of its own — it is missing @entity(), or a circular import evaluated the use case first.`,\n );\n }\n if (\n metaUseCase.confirm?.tone === 'destructive' &&\n metaUseCase.reversible === undefined\n ) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" on ${target.name} is destructive and declares no \\`reversible\\`. Say how it is made safe: 'undo' (with an \\`inverse\\`), 'confirm' or 'typed'.`,\n );\n }\n if (metaUseCase.reversible === 'undo' && metaUseCase.inverse === undefined) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" on ${target.name} is reversible by undo and names no \\`inverse\\`: Undo has nothing to run.`,\n );\n }\n // A shortcut is checked where it is declared, so a chord no reader can use\n // — a bare key, Option+letter, Mod+C — fails at load rather than on a page.\n if (metaUseCase.shortcut !== undefined) {\n try {\n assertChord(metaUseCase.shortcut);\n } catch (refused) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" on ${target.name}: ${(refused as Error).message}`,\n { cause: refused },\n );\n }\n }\n const existing = (own[META_USE_CASE_KEY] as MetaUseCase[] | undefined) ?? [];\n // A verb declared on a record and over a selection is one verb under one\n // key, so only a different key makes a second inline verb.\n const inline = existing.find(\n declared => declared.rowInline && declared.key !== metaUseCase.key,\n );\n if (metaUseCase.rowInline && inline) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" on ${target.name} is rowInline, and so is \"${inline.key}\": a row shows at most one verb inline.`,\n );\n }\n own[META_USE_CASE_KEY] = [...existing, metaUseCase];\n}\n\n/**\n * Record on the use-case class itself which entity and verb it implements, so\n * the permission can be derived from the class alone. That is what keeps the\n * verb string written once, at the declaration, instead of being retyped at\n * every guard.\n */\nexport function setMetaUseCaseBinding(\n metadata: DecoratorMetadataObject | undefined,\n binding: MetaUseCaseBinding,\n) {\n requireMetadata(metadata)[META_USE_CASE_BINDING_KEY] = binding;\n}\n\nfunction readMetadata(\n target: ChildConstructor,\n): DecoratorMetadataObject | undefined {\n return target[Symbol.metadata] ?? undefined;\n}\n\nexport function extractMetaEntity<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n): MetaEntity {\n const metadata = readMetadata(target);\n const metaEntity = metadata?.[META_ENTITY_KEY] as MetaEntity | undefined;\n if (!metaEntity) {\n throw new Error(`MetaEntity not found for ${target.name}`);\n }\n return metaEntity;\n}\n\n/**\n * Every accessor declared on a class.\n *\n * The target is a {@link ChildConstructor}, not an `EntityConstructor`: an\n * `@accessor()` writes to its own class's metadata bag with no help from\n * `@entity()`, so a `composition` member's child — a value with no `id` — is\n * described by exactly this walk.\n */\nexport function extractMetaAccessors(target: ChildConstructor): MetaAccessor[] {\n const metadata = readMetadata(target);\n return (metadata?.[META_ACCESSOR_KEY] as MetaAccessor[] | undefined) ?? [];\n}\n\nexport function extractMetaMethods<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n): MetaMethod[] {\n const metadata = readMetadata(target);\n return (metadata?.[META_METHOD_KEY] as MetaMethod[] | undefined) ?? [];\n}\n\n/** Every use case declared against an entity. Empty until one is imported. */\nexport function extractMetaUseCases<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n): MetaUseCase[] {\n const metadata = readMetadata(target);\n return (metadata?.[META_USE_CASE_KEY] as MetaUseCase[] | undefined) ?? [];\n}\n\n/** The entity and verb a `@useCase()` class implements. */\nexport function extractMetaUseCaseBinding(\n target: UseCaseConstructor,\n): MetaUseCaseBinding {\n const metadata = (\n target as { [Symbol.metadata]?: DecoratorMetadataObject | null }\n )[Symbol.metadata];\n const binding = metadata?.[META_USE_CASE_BINDING_KEY] as\n MetaUseCaseBinding | undefined;\n if (!binding) {\n throw new Error(\n `MetaUseCase not found for ${target.name} — is it missing @useCase()?`,\n );\n }\n return binding;\n}\n\n/**\n * The `@useCase()` a class declares, as the entity it is declared against\n * holds it — with its binding and its endpoint contract.\n */\nexport function extractUseCase(target: UseCaseConstructor): MetaUseCase {\n const { entity, key, binding } = extractMetaUseCaseBinding(target);\n // `@useCase()` appends to the entity before it records the binding, so a\n // bound class always has its entry — found by binding as well as key, since\n // one key may be declared on a record and over a selection.\n return extractMetaUseCases(entity).find(\n metaUseCase => metaUseCase.key === key && metaUseCase.binding === binding,\n ) as MetaUseCase;\n}\n"],"names":["Symbol","metadata","for","assertChord","META_ENTITY_KEY","META_ACCESSOR_KEY","META_METHOD_KEY","META_USE_CASE_KEY","META_USE_CASE_BINDING_KEY","requireMetadata","Error","setMetaEntity","metaEntity","appendMetaAccessor","metaAccessor","meta","existing","appendMetaMethod","metaMethod","appendMetaUseCase","target","metaUseCase","own","Object","getOwnPropertyDescriptor","value","key","name","confirm","tone","reversible","undefined","inverse","shortcut","refused","message","cause","inline","find","declared","rowInline","setMetaUseCaseBinding","binding","readMetadata","extractMetaEntity","extractMetaAccessors","extractMetaMethods","extractMetaUseCases","extractMetaUseCaseBinding","extractUseCase","entity"],"mappings":"IAACA,SAAD;CAAA,YAAA,CAACA,UAAAA,QAAiCC,QAAQ,YAA1C,YAAA,AAACD,QAAiCC,QAAQ,GAAKD,OAAOE,GAAG,CAAC;AAE1D,SAASC,WAAW,QAAQ,0BAA0B;AAoBtD,OAAO,MAAMC,kBAAkBJ,OAAO,cAAc;AACpD,OAAO,MAA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AO2B,oBAAoBG,QAAQZ,IAAI,CACrCjB,CAAAA,cAAeA,YAAYK,GAAG,KAAKA,OAAOL,YAAYqB,OAAO,KAAKA;AAEtE"}
1
+ {"version":3,"sources":["../../../src/entity-definition/helpers/entity-definition-helpers.ts"],"sourcesContent":["(Symbol as { metadata?: symbol }).metadata ??= Symbol.for('Symbol.metadata');\n\nimport { assertChord } from '../../shortcut/chord.js';\nimport { Entity, EntityConstructor } from '../../types/Entity.js';\nimport { UseCaseConstructor } from '../../types/UseCase.js';\nimport {\n type ChildConstructor,\n MetaAccessor,\n} from '../meta-entities/meta-accessor/index.js';\nimport { MetaEntity } from '../meta-entities/meta-entity/index.js';\nimport { MetaMethod } from '../meta-entities/meta-method/index.js';\nimport {\n MetaUseCase,\n MetaUseCaseBinding,\n type UseCaseAvailability,\n} from '../meta-entities/meta-use-case/index.js';\n\ndeclare global {\n interface SymbolConstructor {\n readonly metadata: unique symbol;\n }\n}\n\nexport const META_ENTITY_KEY = Symbol('MetaEntity');\nexport const META_ACCESSOR_KEY = Symbol('MetaAccessor');\nexport const META_METHOD_KEY = Symbol('MetaMethod');\nexport const META_USE_CASE_KEY = Symbol('MetaUseCase');\nexport const META_USE_CASE_BINDING_KEY = Symbol('MetaUseCaseBinding');\n\nfunction requireMetadata(\n metadata: DecoratorMetadataObject | undefined,\n): DecoratorMetadataObject {\n if (!metadata) {\n throw new Error(\n 'Decorator metadata unavailable — Symbol.metadata polyfill missing or stage-3 decorator emit not enabled.',\n );\n }\n return metadata;\n}\n\nexport function setMetaEntity(\n metadata: DecoratorMetadataObject | undefined,\n metaEntity: MetaEntity,\n) {\n requireMetadata(metadata)[META_ENTITY_KEY] = metaEntity;\n}\n\nexport function appendMetaAccessor(\n metadata: DecoratorMetadataObject | undefined,\n metaAccessor: MetaAccessor,\n) {\n const meta = requireMetadata(metadata);\n const existing =\n (meta[META_ACCESSOR_KEY] as MetaAccessor[] | undefined) ?? [];\n meta[META_ACCESSOR_KEY] = [...existing, metaAccessor];\n}\n\nexport function appendMetaMethod(\n metadata: DecoratorMetadataObject | undefined,\n metaMethod: MetaMethod,\n) {\n const meta = requireMetadata(metadata);\n const existing = (meta[META_METHOD_KEY] as MetaMethod[] | undefined) ?? [];\n meta[META_METHOD_KEY] = [...existing, metaMethod];\n}\n\n/**\n * Append a use case to the metadata of the entity it acts on.\n *\n * This is the one decorator that writes a bag other than its own: a use case is\n * declared on its own class, but the entity is what a surface holds, so the\n * descriptor has to end up there. The consequence is that a use-case module\n * which is never imported leaves the entity looking as if it had no actions,\n * which is why a host's register should assert every `@useCase()` class is\n * re-exported from its package barrel.\n *\n * It reads the target's **own** metadata rather than going through\n * {@link readMetadata}. `Symbol.metadata` resolves along the prototype chain, so\n * an inherited read would append the verb to a base class's bag and leak it to\n * every subclass. A target with no own metadata is an entity missing\n * `@entity()`, or a circular import that evaluated the use case first.\n */\nexport function appendMetaUseCase<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n metaUseCase: MetaUseCase,\n) {\n const own = Object.getOwnPropertyDescriptor(target, Symbol.metadata)\n ?.value as DecoratorMetadataObject | null | undefined;\n if (!own) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" targets ${target.name}, which has no metadata of its own — it is missing @entity(), or a circular import evaluated the use case first.`,\n );\n }\n if (\n metaUseCase.confirm?.tone === 'destructive' &&\n metaUseCase.reversible === undefined\n ) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" on ${target.name} is destructive and declares no \\`reversible\\`. Say how it is made safe: 'undo' (with an \\`inverse\\`), 'confirm' or 'typed'.`,\n );\n }\n if (metaUseCase.reversible === 'undo' && metaUseCase.inverse === undefined) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" on ${target.name} is reversible by undo and names no \\`inverse\\`: Undo has nothing to run.`,\n );\n }\n if (metaUseCase.availableWhen !== undefined) {\n assertAvailability(target, metaUseCase, metaUseCase.availableWhen);\n }\n // A shortcut is checked where it is declared, so a chord no reader can use\n // — a bare key, Option+letter, Mod+C — fails at load rather than on a page.\n if (metaUseCase.shortcut !== undefined) {\n try {\n assertChord(metaUseCase.shortcut);\n } catch (refused) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" on ${target.name}: ${(refused as Error).message}`,\n { cause: refused },\n );\n }\n }\n const existing = (own[META_USE_CASE_KEY] as MetaUseCase[] | undefined) ?? [];\n // A verb declared on a record and over a selection is one verb under one\n // key, so only a different key makes a second inline verb.\n const inline = existing.find(\n declared => declared.rowInline && declared.key !== metaUseCase.key,\n );\n if (metaUseCase.rowInline && inline) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" on ${target.name} is rowInline, and so is \"${inline.key}\": a row shows at most one verb inline.`,\n );\n }\n own[META_USE_CASE_KEY] = [...existing, metaUseCase];\n}\n\n/**\n * A verb's states are checked where they are declared, against the entity's\n * own member: a misspelt member or state would otherwise hide the verb on every\n * record, which reads as a missing grant rather than a typo.\n */\nfunction assertAvailability(\n target: EntityConstructor<Entity>,\n { key, binding, alsoAt }: MetaUseCase,\n availableWhen: UseCaseAvailability,\n) {\n const where = `Use case \"${key}\" on ${target.name}`;\n // A selection carries no states, so the collection surfaces offer every\n // verb; a verb with no record-bound cell would declare states nothing reads.\n const recordBound =\n binding === 'entity' ||\n (alsoAt ?? []).some(cell => cell.binding === 'entity');\n if (!recordBound) {\n throw new Error(\n `${where} declares \\`availableWhen\\` and sits on no record: a selection carries no states, so nothing would read them.`,\n );\n }\n const member = extractMetaAccessors(target).find(\n accessor => accessor.name === availableWhen.member,\n );\n if (member?.enumValues === undefined) {\n throw new Error(\n `${where} is available when \"${availableWhen.member}\" holds a state, and ${target.name} has no enum member by that name.`,\n );\n }\n if (availableWhen.in.length === 0) {\n throw new Error(\n `${where} is available in no state of \"${availableWhen.member}\": a verb that is never offered is a verb to delete.`,\n );\n }\n const unknown = availableWhen.in.filter(\n state => !member.enumValues?.includes(state),\n );\n if (unknown.length > 0) {\n throw new Error(\n `${where} names ${unknown.map(state => `\"${state}\"`).join(', ')}, which \"${availableWhen.member}\" does not hold.`,\n );\n }\n}\n\n/**\n * Record on the use-case class itself which entity and verb it implements, so\n * the permission can be derived from the class alone. That is what keeps the\n * verb string written once, at the declaration, instead of being retyped at\n * every guard.\n */\nexport function setMetaUseCaseBinding(\n metadata: DecoratorMetadataObject | undefined,\n binding: MetaUseCaseBinding,\n) {\n requireMetadata(metadata)[META_USE_CASE_BINDING_KEY] = binding;\n}\n\nfunction readMetadata(\n target: ChildConstructor,\n): DecoratorMetadataObject | undefined {\n return target[Symbol.metadata] ?? undefined;\n}\n\nexport function extractMetaEntity<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n): MetaEntity {\n const metadata = readMetadata(target);\n const metaEntity = metadata?.[META_ENTITY_KEY] as MetaEntity | undefined;\n if (!metaEntity) {\n throw new Error(`MetaEntity not found for ${target.name}`);\n }\n return metaEntity;\n}\n\n/**\n * The `@entity()` metadata of a class, or `undefined` for one that declares\n * none — a `composition` member's child is described without it.\n */\nexport function findMetaEntity(\n target: ChildConstructor,\n): MetaEntity | undefined {\n return readMetadata(target)?.[META_ENTITY_KEY] as MetaEntity | undefined;\n}\n\n/**\n * Every accessor declared on a class.\n *\n * The target is a {@link ChildConstructor}, not an `EntityConstructor`: an\n * `@accessor()` writes to its own class's metadata bag with no help from\n * `@entity()`, so a `composition` member's child — a value with no `id` — is\n * described by exactly this walk.\n */\nexport function extractMetaAccessors(target: ChildConstructor): MetaAccessor[] {\n const metadata = readMetadata(target);\n return (metadata?.[META_ACCESSOR_KEY] as MetaAccessor[] | undefined) ?? [];\n}\n\nexport function extractMetaMethods<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n): MetaMethod[] {\n const metadata = readMetadata(target);\n return (metadata?.[META_METHOD_KEY] as MetaMethod[] | undefined) ?? [];\n}\n\n/** Every use case declared against an entity. Empty until one is imported. */\nexport function extractMetaUseCases<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n): MetaUseCase[] {\n const metadata = readMetadata(target);\n return (metadata?.[META_USE_CASE_KEY] as MetaUseCase[] | undefined) ?? [];\n}\n\n/** The entity and verb a `@useCase()` class implements. */\nexport function extractMetaUseCaseBinding(\n target: UseCaseConstructor,\n): MetaUseCaseBinding {\n const metadata = (\n target as { [Symbol.metadata]?: DecoratorMetadataObject | null }\n )[Symbol.metadata];\n const binding = metadata?.[META_USE_CASE_BINDING_KEY] as\n MetaUseCaseBinding | undefined;\n if (!binding) {\n throw new Error(\n `MetaUseCase not found for ${target.name} — is it missing @useCase()?`,\n );\n }\n return binding;\n}\n\n/**\n * The `@useCase()` a class declares, as the entity it is declared against\n * holds it — with its binding and its endpoint contract.\n */\nexport function extractUseCase(target: UseCaseConstructor): MetaUseCase {\n const { entity, key, binding } = extractMetaUseCaseBinding(target);\n // `@useCase()` appends to the entity before it records the binding, so a\n // bound class always has its entry — found by binding as well as key, since\n // one key may be declared on a record and over a selection.\n return extractMetaUseCases(entity).find(\n metaUseCase => metaUseCase.key === key && metaUseCase.binding === binding,\n ) as MetaUseCase;\n}\n"],"names":["Symbol","metadata","for","assertChord","META_ENTITY_KEY","META_ACCESSOR_KEY","META_METHOD_KEY","META_USE_CASE_KEY","META_USE_CASE_BINDING_KEY","requireMetadata","Error","setMetaEntity","metaEntity","appendMetaAccessor","metaAccessor","meta","existing","appendMetaMethod","metaMethod","appendMetaUseCase","target","metaUseCase","own","Object","getOwnPropertyDescriptor","value","key","name","confirm","tone","reversible","undefined","inverse","availableWhen","assertAvailability","shortcut","refused","message","cause","inline","find","declared","rowInline","binding","alsoAt","where","recordBound","some","cell","member","extractMetaAccessors","accessor","enumValues","in","length","unknown","filter","state","includes","map","join","setMetaUseCaseBinding","readMetadata","extractMetaEntity","findMetaEntity","extractMetaMethods","extractMetaUseCases","extractMetaUseCaseBinding","extractUseCase","entity"],"mappings":"IAACA,SAAD;CAAA,YAAA,CAACA,UAAAA,QAAiCC,QAAQ,YAA1C,YAAA,AAACD,QAAiCC,QAAQ,GAAKD,OAAOE,GAAG,CAAC;AAE1D,SA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,CAACO,0BAA0B;IAErD,IAAI,CAACmC,SAAS;QACZ,MAAM,IAAIjC,MACR,CAAC,0BAA0B,EAAEU,OAAOO,IAAI,CAAC,4BAA4B,CAAC;IAE1E;IACA,OAAOgB;AACT;AAEA;;;CAGC,GACD,OAAO,SAASyB,eAAehD,MAA0B;IACvD,MAAM,EAAEiD,MAAM,EAAE3C,GAAG,EAAEiB,OAAO,EAAE,GAAGwB,0BAA0B/C;IAC3D,yEAAyE;IACzE,4EAA4E;IAC5E,4DAA4D;IAC5D,OAAO8C,oBAAoBG,QAAQ7B,IAAI,CACrCnB,CAAAA,cAAeA,YAAYK,GAAG,KAAKA,OAAOL,YAAYsB,OAAO,KAAKA;AAEtE"}
@@ -143,6 +143,20 @@ export interface MetaAccessorOptions {
143
143
  * nothing needs. Absent means a root.
144
144
  */
145
145
  parent?: boolean;
146
+ /**
147
+ * This `id` or `string` member holds the id of a record of another entity,
148
+ * named by the `domain:key` pair that entity's `@entity({ domain, key })`
149
+ * declares — so the declaring package imports nothing of the target's. A
150
+ * screen reads the target's name in its place through the host's
151
+ * `ReferenceLabelsTag` registry, rather than showing the key.
152
+ *
153
+ * Not a `link` on purpose: the target may live in another store, and a
154
+ * `link` invites the storage-layer join that would couple the two, while its
155
+ * accessor would import the target's class across a domain boundary.
156
+ * Presentation and resolution only — to validation, queries, serialization
157
+ * and every adapter the member is still its id.
158
+ */
159
+ references?: MemberReference;
146
160
  /**
147
161
  * This `number` member is an amount of money, and how to read it: its
148
162
  * currency, fixed or held by another member of the same record, and whether
@@ -175,6 +189,10 @@ export interface MetaAccessorOptions {
175
189
  */
176
190
  autocomplete?: string;
177
191
  }
192
+ /** The entity a reference member points at, as `domain:key`. */
193
+ export interface MemberReference {
194
+ readonly entity: string;
195
+ }
178
196
  /** The part a member plays on a record's card. */
179
197
  export type CardRole = 'title' | 'subtitle' | 'badge' | 'meta' | 'hidden';
180
198
  /**
@@ -215,6 +233,7 @@ export declare class MetaAccessor {
215
233
  readonly maxItems?: number;
216
234
  readonly notBefore?: string;
217
235
  readonly parent?: boolean;
236
+ readonly references?: MemberReference;
218
237
  readonly money?: MoneyFormat;
219
238
  readonly minWidth?: number;
220
239
  readonly card?: CardRole;
@@ -1 +1 @@
1
- {"version":3,"file":"meta-accessor.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/meta-entities/meta-accessor/meta-accessor.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEnD;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,0IAYpB,CAAC;AACX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAElE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,gBAAgB,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,IAAI,KAI7D,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,MAAM,CAAC;AAEZ;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,6BAA8B,CAAC;AACpE,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,wBAAwB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEhF,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,4DAA4D;IAC5D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,6DAA6D;IAC7D,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,gFAAgF;IAChF,KAAK,CAAC,EAAE,MAAM,CAAC;IAC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kBAAkB,CAAC,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,uBAAuB,CAAC;IACrD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,gBAAgB,CAAC;IAC5C,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,eAAe,CAAC;IACtC,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;gBAM7B,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,IAAI,EAAE,gBAAgB,EACtB,OAAO,CAAC,EAAE,mBAAmB;CAsChC"}
@@ -54,6 +54,7 @@ export class MetaAccessor {
54
54
  this.maxItems = options == null ? void 0 : options.maxItems;
55
55
  this.notBefore = options == null ? void 0 : options.notBefore;
56
56
  this.parent = options == null ? void 0 : options.parent;
57
+ this.references = options == null ? void 0 : options.references;
57
58
  this.money = options == null ? void 0 : options.money;
58
59
  this.minWidth = options == null ? void 0 : options.minWidth;
59
60
  this.card = options == null ? void 0 : options.card;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/entity-definition/meta-entities/meta-accessor/meta-accessor.ts"],"sourcesContent":["export type MetaAccessorKind = 'getter' | 'setter';\n\n/**\n * The kinds of value an accessor can hold, as far as generic UI and adapters\n * care. It is deliberately a presentation/behaviour taxonomy rather than a\n * TypeScript mirror: `id` and `enum` are strings at runtime but are rendered,\n * sorted and filtered differently.\n *\n * `localized` holds a text per locale (`LocalizedText`). It is queried only\n * through one locale at a time — `name.en` — never as the whole object.\n */\nexport const MetaAccessorTypes = [\n 'string',\n 'number',\n 'boolean',\n 'date',\n 'enum',\n 'id',\n 'link',\n 'linkCollection',\n 'composition',\n 'scalarCollection',\n 'localized',\n] as const;\nexport type MetaAccessorType = (typeof MetaAccessorTypes)[number];\n\n/**\n * The class whose accessors describe one row of a `composition` member.\n *\n * Deliberately not `EntityConstructor`: a child of a composition is a **value**,\n * not an entity. It has no identity of its own, is never addressed apart from\n * the master that holds it, and therefore has no `id` for `Entity` to require.\n * What it does have is `@accessor()` metadata, which is written to its own\n * class's `Symbol.metadata` bag independently of `@entity()` — so a child is\n * described by its accessors and by nothing else.\n *\n * ⚠️ It is a **shape declaration, not a runtime constructor contract.** Children\n * arrive off the wire as plain objects — the serializer walks `instanceof\n * EntityLink`, not the declared type, so an embedded array passes straight\n * through — and an autosaved draft may hold nothing that does not survive a\n * JSON round trip anyway. Nothing may branch on `instanceof` against this constructor.\n */\nexport type ChildConstructor<TChild extends object = object> = new (\n // Mirrors `EntityConstructor`: the arguments are the child's business, only\n // the class identity matters here.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: any[]\n) => TChild;\n\n/**\n * The wire shape a relation takes: the target's foreign key, or the whole\n * target inlined. Declared here rather than next to `EntityLink` because it is\n * metadata about a member, not state of a link instance.\n */\nexport const EntityLinkSerializations = ['id', 'embedded'] as const;\nexport type EntityLinkSerialization = (typeof EntityLinkSerializations)[number];\n\nexport interface MetaAccessorOptions {\n alias?: string;\n type?: MetaAccessorType;\n readonly?: boolean;\n hidden?: boolean;\n /** Member must hold a value. Drives form validation; defaults to optional. */\n required?: boolean;\n /** Human label for UI. Falls back to a humanized `name`. */\n label?: string;\n /**\n * Translation key for the label, resolved by the presentation layer. Takes\n * precedence over `label`, which stays as the untranslated fallback for a\n * member that has no catalog entry yet.\n *\n * Keys mirror the entity's own `@entity({ key })`, so they are derivable\n * rather than invented: `entity:product-specification.fields.code`.\n */\n labelKey?: string;\n /** Opt in/out of sorting controls. Defaults per `type`. */\n sortable?: boolean;\n /** Opt in/out of filtering controls. Defaults per `type`. */\n filterable?: boolean;\n /** Default position among the entity's members; ties keep declaration order. */\n order?: number;\n /** Allowed values when `type` is `enum` — drives the filter value control. */\n enumValues?: readonly string[];\n /**\n * Catalog prefix for those values; a value's label is `${enumLabelKey}.${value}`.\n * Explicit rather than derived from `labelKey`, so a member whose values are\n * shared with another member can point both at one vocabulary.\n */\n enumLabelKey?: string;\n /** Property of a `link` target used as its display label. Default `name`. */\n linkLabelProperty?: string;\n /**\n * Property of a `link` target a picker searches on. Defaults to\n * {@link linkLabelProperty} — you search for what you read. It must be\n * `filterable` on the target entity, since member metadata is also the\n * server-side filter allowlist.\n */\n linkSearchProperty?: string;\n /**\n * How a `link` travels when its owner is serialized: as the target's scalar\n * foreign key (`id`, the default) or with the whole target inlined\n * (`embedded`). The serializer decides per *link instance* — it inlines\n * whatever `isLoaded` — so without this the shape a write takes would depend\n * on whether the form happened to hold the target. Declaring it on the entity\n * makes the wire shape a property of the relation instead of an accident of\n * the UI.\n */\n linkSerialization?: EntityLinkSerialization;\n /**\n * The class describing one row of a `composition` member — the child's own\n * `@accessor()` metadata is what a detail grid renders its columns from.\n *\n * A **thunk**, because a child module and the entity that owns it are usually\n * declared in the same package and a direct reference makes the decorator's\n * evaluation order load-bearing. Deferring the read to first use removes the\n * ordering question entirely, which is the same reason a to-one relation's\n * target is reached through a resolver rather than an import.\n *\n * Meaningless on any other type. There is no inference fallback: an empty\n * array cannot be told apart from an empty `string[]` at runtime, so a\n * collection must be declared.\n */\n childType?: () => ChildConstructor;\n /**\n * Reset this member when the record is copied.\n *\n * It lives on the **accessor**, not on a use case's descriptor, and that is a\n * decision already made: `UseCaseDescriptor` is closed against per-verb\n * payloads, and this is the exact case, because a descriptor that\n * grows a field per verb ends up a union of every verb's arguments. Which\n * members a copy must not carry is a property of the *member* — a unique\n * code, an audit stamp, a sequence number — and it is the same answer however\n * the copy is triggered.\n *\n * The identity member is always reset and needs no flag.\n */\n resetOnClone?: boolean;\n /**\n * The fewest values a collection member may hold — `1` for \"not empty\". Only\n * meaningful on a collection type (`scalarCollection`, `linkCollection`,\n * `composition`); declaring it elsewhere fails when the entity is described.\n *\n * Distinct from {@link required}: on a collection `required` already means\n * \"at least one\", and a `minItems` of two is a fact `required` cannot state.\n */\n minItems?: number;\n /** The most values a collection member may hold. Collection types only. */\n maxItems?: number;\n /**\n * Another `date` member this one may not precede — a period's `end` declares\n * `notBefore: 'start'`. Checked only when both hold a value. Both members must\n * be `date`s, or describing the entity fails.\n */\n notBefore?: string;\n /**\n * This member holds the id of the record's **parent**, another record of\n * the same entity — so the entity forms a tree. At most one member per\n * entity, and it must be an `id` or a `string`; describing the entity fails\n * otherwise.\n *\n * An id rather than a `link` on purpose. A tree is always built from the\n * whole set of its records ({@link buildTree}), never by resolving one parent\n * at a time, so a link's lazy resolution would be a fetch per node that\n * nothing needs. Absent means a root.\n */\n parent?: boolean;\n /**\n * This `number` member is an amount of money, and how to read it: its\n * currency, fixed or held by another member of the same record, and whether\n * the number counts the currency's minor units (cents) or its major ones.\n * Presentation only — the member is still a number to validation, queries\n * and every adapter — so a table prints `Q64,99` rather than `6499`, and a\n * form edits the major amount and writes back the stored one.\n */\n money?: MoneyFormat;\n /**\n * The narrowest this member's column reads at, in `rem`. A table whose\n * visible columns no longer fit side by side becomes a list of cards, so the\n * sum of these is where it switches. Undeclared, the member's type decides.\n * Presentation only.\n */\n minWidth?: number;\n /**\n * The part this member plays on a record's card: its `title` — the heading\n * that links to the record — a `subtitle` under it, a `badge`, a line of\n * `meta`, or `hidden` from the card. Undeclared, the record's first\n * filled-in member is the title, an id is hidden, the first enum is the\n * badge and up to three more members are meta. Presentation only.\n */\n card?: CardRole;\n /**\n * What the member holds about the person filling it in, as an HTML autofill\n * token — `email`, `given-name`, `tel`, `street-address` — so a browser can\n * fill it and assistive tech can say what it is for (WCAG 1.3.5).\n * Presentation only.\n */\n autocomplete?: string;\n}\n\n/** The part a member plays on a record's card. */\nexport type CardRole = 'title' | 'subtitle' | 'badge' | 'meta' | 'hidden';\n\n/**\n * How a `number` member reads as money: `currency` fixed, or\n * `currencyMember` naming the record's own ISO 4217 code member; `unit`\n * whether the stored number counts minor units (`6499` for 64.99) or major.\n */\nexport type MoneyFormat = { readonly unit: 'minor' | 'major' } & (\n | { readonly currency: string; readonly currencyMember?: never }\n | { readonly currencyMember: string; readonly currency?: never }\n);\n\nexport class MetaAccessor {\n //#region Properties\n\n readonly name: string | symbol;\n readonly kind: MetaAccessorKind;\n readonly alias?: string;\n readonly type?: MetaAccessorType;\n readonly readonly?: boolean;\n readonly hidden?: boolean;\n readonly required?: boolean;\n readonly label?: string;\n readonly labelKey?: string;\n readonly sortable?: boolean;\n readonly filterable?: boolean;\n readonly order?: number;\n readonly enumValues?: readonly string[];\n readonly enumLabelKey?: string;\n readonly linkLabelProperty?: string;\n readonly linkSearchProperty?: string;\n readonly linkSerialization?: EntityLinkSerialization;\n readonly childType?: () => ChildConstructor;\n readonly resetOnClone?: boolean;\n readonly minItems?: number;\n readonly maxItems?: number;\n readonly notBefore?: string;\n readonly parent?: boolean;\n readonly money?: MoneyFormat;\n readonly minWidth?: number;\n readonly card?: CardRole;\n readonly autocomplete?: string;\n\n //#endregion\n\n //#region Constructors\n constructor(\n name: string | symbol,\n kind: MetaAccessorKind,\n options?: MetaAccessorOptions,\n ) {\n this.name = name;\n this.kind = kind;\n this.alias = options?.alias;\n this.type = options?.type;\n this.readonly = options?.readonly;\n this.hidden = options?.hidden;\n this.required = options?.required;\n this.label = options?.label;\n this.labelKey = options?.labelKey;\n this.sortable = options?.sortable;\n this.filterable = options?.filterable;\n this.order = options?.order;\n this.enumValues = options?.enumValues;\n this.enumLabelKey = options?.enumLabelKey;\n this.linkLabelProperty = options?.linkLabelProperty;\n this.linkSearchProperty = options?.linkSearchProperty;\n this.linkSerialization = options?.linkSerialization;\n this.childType = options?.childType;\n this.resetOnClone = options?.resetOnClone;\n this.minItems = options?.minItems;\n this.maxItems = options?.maxItems;\n this.notBefore = options?.notBefore;\n this.parent = options?.parent;\n this.money = options?.money;\n this.minWidth = options?.minWidth;\n this.card = options?.card;\n this.autocomplete = options?.autocomplete;\n }\n //#endregion\n\n //#region Methods\n //#endregion\n\n //#region Accessors\n //#endregion\n}\n"],"names":["MetaAccessorTypes","EntityLinkSerializations","MetaAccessor","name","kind","options","alias","type","readonly","hidden","required","label","labelKey","sortable","filterable","order","enumValues","enumLabelKey","linkLabelProperty","linkSearchProperty","linkSerialization","childType","resetOnClone","minItems","maxItems","notBefore","parent","money","minWidth","card","autocomplete"],"mappings":"AAEA;;;;;;;;CAQC,GACD,OAAO,MAAMA,oBAAoB;IAC/B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAU;AA0BX;;;;CAIC,GACD,OAAO,MAAMC,2BAA2B;IAAC;IAAM;CAAW,CAAU;AA8JpE,OAAO,MAAMC;IA+BX,YAAY;IAEZ,sBAAsB;IACtB,YACEC,IAAqB,EACrBC,IAAsB,EACtBC,OAA6B,CAC7B;QACA,IAAI,CAACF,IAAI,GAAGA;QACZ,IAAI,CAACC,IAAI,GAAGA;QACZ,IAAI,CAACE,KAAK,GAAGD,2BAAAA,QAASC,KAAK;QAC3B,IAAI,CAACC,IAAI,GAAGF,2BAAAA,QAASE,IAAI;QACzB,IAAI,CAACC,QAAQ,GAAGH,2BAAAA,QAASG,QAAQ;QACjC,IAAI,CAACC,MAAM,GAAGJ,2BAAAA,QAASI,MAAM;QAC7B,IAAI,CAACC,QAAQ,GAAGL,2BAAAA,QAASK,QAAQ;QACjC,IAAI,CAACC,KAAK,GAAGN,2BAAAA,QAASM,KAAK;QAC3B,IAAI,CAACC,QAAQ,GAAGP,2BAAAA,QAASO,QAAQ;QACjC,IAAI,CAACC,QAAQ,GAAGR,2BAAAA,QAASQ,QAAQ;QACjC,IAAI,CAACC,UAAU,GAAGT,2BAAAA,QAASS,UAAU;QACrC,IAAI,CAACC,KAAK,GAAGV,2BAAAA,QAASU,KAAK;QAC3B,IAAI,CAACC,UAAU,GAAGX,2BAAAA,QAASW,UAAU;QACrC,IAAI,CAACC,YAAY,GAAGZ,2BAAAA,QAASY,YAAY;QACzC,IAAI,CAACC,iBAAiB,GAAGb,2BAAAA,QAASa,iBAAiB;QACnD,IAAI,CAACC,kBAAkB,GAAGd,2BAAAA,QAASc,kBAAkB;QACrD,IAAI,CAACC,iBAAiB,GAAGf,2BAAAA,QAASe,iBAAiB;QACnD,IAAI,CAACC,SAAS,GAAGhB,2BAAAA,QAASgB,SAAS;QACnC,IAAI,CAACC,YAAY,GAAGjB,2BAAAA,QAASiB,YAAY;QACzC,IAAI,CAACC,QAAQ,GAAGlB,2BAAAA,QAASkB,QAAQ;QACjC,IAAI,CAACC,QAAQ,GAAGnB,2BAAAA,QAASmB,QAAQ;QACjC,IAAI,CAACC,SAAS,GAAGpB,2BAAAA,QAASoB,SAAS;QACnC,IAAI,CAACC,MAAM,GAAGrB,2BAAAA,QAASqB,MAAM;QAC7B,IAAI,CAACC,KAAK,GAAGtB,2BAAAA,QAASsB,KAAK;QAC3B,IAAI,CAACC,QAAQ,GAAGvB,2BAAAA,QAASuB,QAAQ;QACjC,IAAI,CAACC,IAAI,GAAGxB,2BAAAA,QAASwB,IAAI;QACzB,IAAI,CAACC,YAAY,GAAGzB,2BAAAA,QAASyB,YAAY;IAC3C;AAQF"}
1
+ {"version":3,"sources":["../../../../src/entity-definition/meta-entities/meta-accessor/meta-accessor.ts"],"sourcesContent":["export type MetaAccessorKind = 'getter' | 'setter';\n\n/**\n * The kinds of value an accessor can hold, as far as generic UI and adapters\n * care. It is deliberately a presentation/behaviour taxonomy rather than a\n * TypeScript mirror: `id` and `enum` are strings at runtime but are rendered,\n * sorted and filtered differently.\n *\n * `localized` holds a text per locale (`LocalizedText`). It is queried only\n * through one locale at a time — `name.en` — never as the whole object.\n */\nexport const MetaAccessorTypes = [\n 'string',\n 'number',\n 'boolean',\n 'date',\n 'enum',\n 'id',\n 'link',\n 'linkCollection',\n 'composition',\n 'scalarCollection',\n 'localized',\n] as const;\nexport type MetaAccessorType = (typeof MetaAccessorTypes)[number];\n\n/**\n * The class whose accessors describe one row of a `composition` member.\n *\n * Deliberately not `EntityConstructor`: a child of a composition is a **value**,\n * not an entity. It has no identity of its own, is never addressed apart from\n * the master that holds it, and therefore has no `id` for `Entity` to require.\n * What it does have is `@accessor()` metadata, which is written to its own\n * class's `Symbol.metadata` bag independently of `@entity()` — so a child is\n * described by its accessors and by nothing else.\n *\n * ⚠️ It is a **shape declaration, not a runtime constructor contract.** Children\n * arrive off the wire as plain objects — the serializer walks `instanceof\n * EntityLink`, not the declared type, so an embedded array passes straight\n * through — and an autosaved draft may hold nothing that does not survive a\n * JSON round trip anyway. Nothing may branch on `instanceof` against this constructor.\n */\nexport type ChildConstructor<TChild extends object = object> = new (\n // Mirrors `EntityConstructor`: the arguments are the child's business, only\n // the class identity matters here.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: any[]\n) => TChild;\n\n/**\n * The wire shape a relation takes: the target's foreign key, or the whole\n * target inlined. Declared here rather than next to `EntityLink` because it is\n * metadata about a member, not state of a link instance.\n */\nexport const EntityLinkSerializations = ['id', 'embedded'] as const;\nexport type EntityLinkSerialization = (typeof EntityLinkSerializations)[number];\n\nexport interface MetaAccessorOptions {\n alias?: string;\n type?: MetaAccessorType;\n readonly?: boolean;\n hidden?: boolean;\n /** Member must hold a value. Drives form validation; defaults to optional. */\n required?: boolean;\n /** Human label for UI. Falls back to a humanized `name`. */\n label?: string;\n /**\n * Translation key for the label, resolved by the presentation layer. Takes\n * precedence over `label`, which stays as the untranslated fallback for a\n * member that has no catalog entry yet.\n *\n * Keys mirror the entity's own `@entity({ key })`, so they are derivable\n * rather than invented: `entity:product-specification.fields.code`.\n */\n labelKey?: string;\n /** Opt in/out of sorting controls. Defaults per `type`. */\n sortable?: boolean;\n /** Opt in/out of filtering controls. Defaults per `type`. */\n filterable?: boolean;\n /** Default position among the entity's members; ties keep declaration order. */\n order?: number;\n /** Allowed values when `type` is `enum` — drives the filter value control. */\n enumValues?: readonly string[];\n /**\n * Catalog prefix for those values; a value's label is `${enumLabelKey}.${value}`.\n * Explicit rather than derived from `labelKey`, so a member whose values are\n * shared with another member can point both at one vocabulary.\n */\n enumLabelKey?: string;\n /** Property of a `link` target used as its display label. Default `name`. */\n linkLabelProperty?: string;\n /**\n * Property of a `link` target a picker searches on. Defaults to\n * {@link linkLabelProperty} — you search for what you read. It must be\n * `filterable` on the target entity, since member metadata is also the\n * server-side filter allowlist.\n */\n linkSearchProperty?: string;\n /**\n * How a `link` travels when its owner is serialized: as the target's scalar\n * foreign key (`id`, the default) or with the whole target inlined\n * (`embedded`). The serializer decides per *link instance* — it inlines\n * whatever `isLoaded` — so without this the shape a write takes would depend\n * on whether the form happened to hold the target. Declaring it on the entity\n * makes the wire shape a property of the relation instead of an accident of\n * the UI.\n */\n linkSerialization?: EntityLinkSerialization;\n /**\n * The class describing one row of a `composition` member — the child's own\n * `@accessor()` metadata is what a detail grid renders its columns from.\n *\n * A **thunk**, because a child module and the entity that owns it are usually\n * declared in the same package and a direct reference makes the decorator's\n * evaluation order load-bearing. Deferring the read to first use removes the\n * ordering question entirely, which is the same reason a to-one relation's\n * target is reached through a resolver rather than an import.\n *\n * Meaningless on any other type. There is no inference fallback: an empty\n * array cannot be told apart from an empty `string[]` at runtime, so a\n * collection must be declared.\n */\n childType?: () => ChildConstructor;\n /**\n * Reset this member when the record is copied.\n *\n * It lives on the **accessor**, not on a use case's descriptor, and that is a\n * decision already made: `UseCaseDescriptor` is closed against per-verb\n * payloads, and this is the exact case, because a descriptor that\n * grows a field per verb ends up a union of every verb's arguments. Which\n * members a copy must not carry is a property of the *member* — a unique\n * code, an audit stamp, a sequence number — and it is the same answer however\n * the copy is triggered.\n *\n * The identity member is always reset and needs no flag.\n */\n resetOnClone?: boolean;\n /**\n * The fewest values a collection member may hold — `1` for \"not empty\". Only\n * meaningful on a collection type (`scalarCollection`, `linkCollection`,\n * `composition`); declaring it elsewhere fails when the entity is described.\n *\n * Distinct from {@link required}: on a collection `required` already means\n * \"at least one\", and a `minItems` of two is a fact `required` cannot state.\n */\n minItems?: number;\n /** The most values a collection member may hold. Collection types only. */\n maxItems?: number;\n /**\n * Another `date` member this one may not precede — a period's `end` declares\n * `notBefore: 'start'`. Checked only when both hold a value. Both members must\n * be `date`s, or describing the entity fails.\n */\n notBefore?: string;\n /**\n * This member holds the id of the record's **parent**, another record of\n * the same entity — so the entity forms a tree. At most one member per\n * entity, and it must be an `id` or a `string`; describing the entity fails\n * otherwise.\n *\n * An id rather than a `link` on purpose. A tree is always built from the\n * whole set of its records ({@link buildTree}), never by resolving one parent\n * at a time, so a link's lazy resolution would be a fetch per node that\n * nothing needs. Absent means a root.\n */\n parent?: boolean;\n /**\n * This `id` or `string` member holds the id of a record of another entity,\n * named by the `domain:key` pair that entity's `@entity({ domain, key })`\n * declares — so the declaring package imports nothing of the target's. A\n * screen reads the target's name in its place through the host's\n * `ReferenceLabelsTag` registry, rather than showing the key.\n *\n * Not a `link` on purpose: the target may live in another store, and a\n * `link` invites the storage-layer join that would couple the two, while its\n * accessor would import the target's class across a domain boundary.\n * Presentation and resolution only — to validation, queries, serialization\n * and every adapter the member is still its id.\n */\n references?: MemberReference;\n /**\n * This `number` member is an amount of money, and how to read it: its\n * currency, fixed or held by another member of the same record, and whether\n * the number counts the currency's minor units (cents) or its major ones.\n * Presentation only — the member is still a number to validation, queries\n * and every adapter — so a table prints `Q64,99` rather than `6499`, and a\n * form edits the major amount and writes back the stored one.\n */\n money?: MoneyFormat;\n /**\n * The narrowest this member's column reads at, in `rem`. A table whose\n * visible columns no longer fit side by side becomes a list of cards, so the\n * sum of these is where it switches. Undeclared, the member's type decides.\n * Presentation only.\n */\n minWidth?: number;\n /**\n * The part this member plays on a record's card: its `title` — the heading\n * that links to the record — a `subtitle` under it, a `badge`, a line of\n * `meta`, or `hidden` from the card. Undeclared, the record's first\n * filled-in member is the title, an id is hidden, the first enum is the\n * badge and up to three more members are meta. Presentation only.\n */\n card?: CardRole;\n /**\n * What the member holds about the person filling it in, as an HTML autofill\n * token — `email`, `given-name`, `tel`, `street-address` — so a browser can\n * fill it and assistive tech can say what it is for (WCAG 1.3.5).\n * Presentation only.\n */\n autocomplete?: string;\n}\n\n/** The entity a reference member points at, as `domain:key`. */\nexport interface MemberReference {\n readonly entity: string;\n}\n\n/** The part a member plays on a record's card. */\nexport type CardRole = 'title' | 'subtitle' | 'badge' | 'meta' | 'hidden';\n\n/**\n * How a `number` member reads as money: `currency` fixed, or\n * `currencyMember` naming the record's own ISO 4217 code member; `unit`\n * whether the stored number counts minor units (`6499` for 64.99) or major.\n */\nexport type MoneyFormat = { readonly unit: 'minor' | 'major' } & (\n | { readonly currency: string; readonly currencyMember?: never }\n | { readonly currencyMember: string; readonly currency?: never }\n);\n\nexport class MetaAccessor {\n //#region Properties\n\n readonly name: string | symbol;\n readonly kind: MetaAccessorKind;\n readonly alias?: string;\n readonly type?: MetaAccessorType;\n readonly readonly?: boolean;\n readonly hidden?: boolean;\n readonly required?: boolean;\n readonly label?: string;\n readonly labelKey?: string;\n readonly sortable?: boolean;\n readonly filterable?: boolean;\n readonly order?: number;\n readonly enumValues?: readonly string[];\n readonly enumLabelKey?: string;\n readonly linkLabelProperty?: string;\n readonly linkSearchProperty?: string;\n readonly linkSerialization?: EntityLinkSerialization;\n readonly childType?: () => ChildConstructor;\n readonly resetOnClone?: boolean;\n readonly minItems?: number;\n readonly maxItems?: number;\n readonly notBefore?: string;\n readonly parent?: boolean;\n readonly references?: MemberReference;\n readonly money?: MoneyFormat;\n readonly minWidth?: number;\n readonly card?: CardRole;\n readonly autocomplete?: string;\n\n //#endregion\n\n //#region Constructors\n constructor(\n name: string | symbol,\n kind: MetaAccessorKind,\n options?: MetaAccessorOptions,\n ) {\n this.name = name;\n this.kind = kind;\n this.alias = options?.alias;\n this.type = options?.type;\n this.readonly = options?.readonly;\n this.hidden = options?.hidden;\n this.required = options?.required;\n this.label = options?.label;\n this.labelKey = options?.labelKey;\n this.sortable = options?.sortable;\n this.filterable = options?.filterable;\n this.order = options?.order;\n this.enumValues = options?.enumValues;\n this.enumLabelKey = options?.enumLabelKey;\n this.linkLabelProperty = options?.linkLabelProperty;\n this.linkSearchProperty = options?.linkSearchProperty;\n this.linkSerialization = options?.linkSerialization;\n this.childType = options?.childType;\n this.resetOnClone = options?.resetOnClone;\n this.minItems = options?.minItems;\n this.maxItems = options?.maxItems;\n this.notBefore = options?.notBefore;\n this.parent = options?.parent;\n this.references = options?.references;\n this.money = options?.money;\n this.minWidth = options?.minWidth;\n this.card = options?.card;\n this.autocomplete = options?.autocomplete;\n }\n //#endregion\n\n //#region Methods\n //#endregion\n\n //#region Accessors\n //#endregion\n}\n"],"names":["MetaAccessorTypes","EntityLinkSerializations","MetaAccessor","name","kind","options","alias","type","readonly","hidden","required","label","labelKey","sortable","filterable","order","enumValues","enumLabelKey","linkLabelProperty","linkSearchProperty","linkSerialization","childType","resetOnClone","minItems","maxItems","notBefore","parent","references","money","minWidth","card","autocomplete"],"mappings":"AAEA;;;;;;;;CAQC,GACD,OAAO,MAAMA,oBAAoB;IAC/B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAU;AA0BX;;;;CAIC,GACD,OAAO,MAAMC,2BAA2B;IAAC;IAAM;CAAW,CAAU;AAiLpE,OAAO,MAAMC;IAgCX,YAAY;IAEZ,sBAAsB;IACtB,YACEC,IAAqB,EACrBC,IAAsB,EACtBC,OAA6B,CAC7B;QACA,IAAI,CAACF,IAAI,GAAGA;QACZ,IAAI,CAACC,IAAI,GAAGA;QACZ,IAAI,CAACE,KAAK,GAAGD,2BAAAA,QAASC,KAAK;QAC3B,IAAI,CAACC,IAAI,GAAGF,2BAAAA,Q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AI,GAAGzB,2BAAAA,QAASyB,IAAI;QACzB,IAAI,CAACC,YAAY,GAAG1B,2BAAAA,QAAS0B,YAAY;IAC3C;AAQF"}
@@ -54,6 +54,17 @@ export interface MetaEntityOptions {
54
54
  * ([ADR 0026](../../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)).
55
55
  */
56
56
  creatable?: boolean;
57
+ /**
58
+ * The member a record is called by — a `string`, a `localized`, a `number`
59
+ * or a reference, in which case the record is called by its target's name.
60
+ * Every surface that names a record (a row, a card's heading, a confirm
61
+ * dialog, a breadcrumb, a toast) reads it through `recordLabel()`.
62
+ * Undeclared, the first filled-in member that is not a key is used. Checked
63
+ * when the entity is described: a member that does not exist, is hidden or
64
+ * is a collection fails
65
+ * ([ADR 0030](../../../../../../../docs/adr/0030-a-reference-names-its-target-through-the-owners-read-port.md)).
66
+ */
67
+ labelMember?: string;
57
68
  }
58
69
  export declare class MetaEntity {
59
70
  readonly name: string;
@@ -64,6 +75,7 @@ export declare class MetaEntity {
64
75
  readonly cardinality?: EntityCardinality;
65
76
  readonly views?: Readonly<Record<string, EntityViewOptions>>;
66
77
  readonly creatable: boolean;
78
+ readonly labelMember?: string;
67
79
  constructor(name: string, options?: MetaEntityOptions);
68
80
  }
69
81
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"meta-entity.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/meta-entities/meta-entity/meta-entity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAGrE;;;;;GAKG;AACH,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAElD;;;;;;;;;GASG;AACH,MAAM,WAAW,iBAAiB;IAChC,kEAAkE;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AC7D,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;gBAIhB,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB;CAkBtD"}
1
+ {"version":3,"file":"meta-entity.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/meta-entities/meta-entity/meta-entity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAGrE;;;;;GAKG;AACH,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAElD;;;;;;;;;GASG;AACH,MAAM,WAAW,iBAAiB;IAChC,kEAAkE;IAClE,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,eAAe,CAAC,SAAS,CAAC,EAAE,CAAC;IAC3D,wCAAwC;IACxC,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC;IACvD,sDAAsD;IACtD,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iGAAiG;IACjG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kFAAkF;IAClF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4CAA4C;IAC5C,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,6DAA6D;IAC7D,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC;IACpD;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;;;;;;OASG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,UAAU;IAErB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,CAAC,EAAE,iBAAiB,CAAC;IACzC,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAC7D,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;gBAIlB,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB;CAmBtD"}
@@ -13,6 +13,7 @@ export class MetaEntity {
13
13
  this.cardinality = options == null ? void 0 : options.cardinality;
14
14
  this.views = options == null ? void 0 : options.views;
15
15
  this.creatable = (_ref = options == null ? void 0 : options.creatable) != null ? _ref : true;
16
+ this.labelMember = options == null ? void 0 : options.labelMember;
16
17
  }
17
18
  }
18
19
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/entity-definition/meta-entities/meta-entity/meta-entity.ts"],"sourcesContent":["import type { Entity } from '../../../types/Entity.js';\nimport type { EntityFiltering } from '../../../types/EntityFiltering.js';\nimport type { EntitySorting } from '../../../types/EntitySorting.js';\nimport { assertBounds } from '../bounds.js';\n\n/**\n * An entity a view's filtering names members of. `@entity()` is applied before\n * TypeScript knows which class it decorates, so a view's members cannot be\n * checked against it there; `extractEntityView` checks them when the view is\n * first read instead.\n */\ntype AnyEntity = Entity & Record<string, unknown>;\n\n/**\n * A narrower shape an entity is published in: some records left out, some\n * members omitted — posts without their bodies, drafts left out.\n *\n * Read by `serializeEntityCollection(entity, records, { view })` and by any\n * adapter that publishes records, so the shape is declared once on the entity\n * rather than per consumer. A member a view omits is optional **in that view\n * only**: `validateRecords(…, { view })` does not require it, and `required`\n * keeps its meaning for the full record.\n */\nexport interface EntityViewOptions {\n /** The records the view keeps, as a load request filters them. */\n readonly filtering?: readonly EntityFiltering<AnyEntity>[];\n /** The order the view lists them in. */\n readonly sorting?: readonly EntitySorting<AnyEntity>[];\n /** Members, by accessor name, the view leaves out. */\n readonly omit?: readonly string[];\n}\n\n/**\n * How many records an entity may have: `{ min: 1, max: 1 }` for a site's one\n * profile, `{ min: 1 }` for \"at least one\". Checked by `validateRecords` over a\n * whole set of records — a static build's content, an import — and never by a\n * single save, which cannot see the others.\n */\nexport interface EntityCardinality {\n readonly min?: number;\n readonly max?: number;\n}\n\nexport interface MetaEntityOptions {\n key?: string;\n domain?: string;\n /** Translation key for the entity's singular name, e.g. `entity:product-specification.label`. */\n labelKey?: string;\n /** Translation key for its plural, e.g. `entity:product-specification.plural`. */\n pluralKey?: string;\n /** How many records the entity may have. */\n cardinality?: EntityCardinality;\n /** Named shapes the entity is published in, by view name. */\n views?: Readonly<Record<string, EntityViewOptions>>;\n /**\n * `false` for an entity no person creates — one only ever written by a flow,\n * such as an order a checkout opens. A list of it offers no \"New\", whatever\n * the caller holds; absent, it offers one to a caller who may write it\n * ([ADR 0026](../../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)).\n */\n creatable?: boolean;\n}\n\nexport class MetaEntity {\n //#region Properties\n readonly name: string;\n readonly key?: string;\n readonly domain?: string;\n readonly labelKey?: string;\n readonly pluralKey?: string;\n readonly cardinality?: EntityCardinality;\n readonly views?: Readonly<Record<string, EntityViewOptions>>;\n readonly creatable: boolean;\n //#endregion\n\n //#region Constructors\n constructor(name: string, options?: MetaEntityOptions) {\n this.name = name;\n this.key = options?.key;\n this.domain = options?.domain;\n this.labelKey = options?.labelKey;\n this.pluralKey = options?.pluralKey;\n assertBounds(`${name}'s cardinality`, options?.cardinality);\n this.cardinality = options?.cardinality;\n this.views = options?.views;\n this.creatable = options?.creatable ?? true;\n }\n //#endregion\n\n //#region Methods\n //#endregion\n\n //#region Accessors\n //#endregion\n}\n"],"names":["assertBounds","MetaEntity","name","options","key","domain","labelKey","pluralKey","cardinality","views","creatable"],"mappings":"AAGA,SAASA,YAAY,QAAQ,eAAe;AA4D5C,OAAO,MAAMC;IAUX,YAAY;IAEZ,sBAAsB;IACtB,YAAYC,IAAY,EAAEC,OAA2B,CAAE;;QACrD,IAAI,CAACD,IAAI,GAAGA;QACZ,IAAI,CAACE,GAAG,GAAGD,2BAAAA,QAASC,GAAG;QACvB,IAAI,CAACC,MAAM,GAAGF,2BAAAA,QAASE,MAAM;QAC7B,IAAI,CAACC,QAAQ,GAAGH,2BAAAA,QAASG,QAAQ;QACjC,IAAI,CAACC,SAAS,GAAGJ,2BAAAA,QAASI,SAAS;QACnCP,aAAa,GAAGE,KAAK,cAAc,CAAC,EAAEC,2BAAAA,QAASK,WAAW;QAC1D,IAAI,CAACA,WAAW,GAAGL,2BAAAA,QAASK,WAAW;QACvC,IAAI,CAACC,KAAK,GAAGN,2BAAAA,QAASM,KAAK;QAC3B,IAAI,CAACC,SAAS,WAAGP,2BAAAA,QAASO,SAAS,mBAAI;IACzC;AAQF"}
1
+ {"version":3,"sources":["../../../../src/entity-definition/meta-entities/meta-entity/meta-entity.ts"],"sourcesContent":["import type { Entity } from '../../../types/Entity.js';\nimport type { EntityFiltering } from '../../../types/EntityFiltering.js';\nimport type { EntitySorting } from '../../../types/EntitySorting.js';\nimport { assertBounds } from '../bounds.js';\n\n/**\n * An entity a view's filtering names members of. `@entity()` is applied before\n * TypeScript knows which class it decorates, so a view's members cannot be\n * checked against it there; `extractEntityView` checks them when the view is\n * first read instead.\n */\ntype AnyEntity = Entity & Record<string, unknown>;\n\n/**\n * A narrower shape an entity is published in: some records left out, some\n * members omitted — posts without their bodies, drafts left out.\n *\n * Read by `serializeEntityCollection(entity, records, { view })` and by any\n * adapter that publishes records, so the shape is declared once on the entity\n * rather than per consumer. A member a view omits is optional **in that view\n * only**: `validateRecords(…, { view })` does not require it, and `required`\n * keeps its meaning for the full record.\n */\nexport interface EntityViewOptions {\n /** The records the view keeps, as a load request filters them. */\n readonly filtering?: readonly EntityFiltering<AnyEntity>[];\n /** The order the view lists them in. */\n readonly sorting?: readonly EntitySorting<AnyEntity>[];\n /** Members, by accessor name, the view leaves out. */\n readonly omit?: readonly string[];\n}\n\n/**\n * How many records an entity may have: `{ min: 1, max: 1 }` for a site's one\n * profile, `{ min: 1 }` for \"at least one\". Checked by `validateRecords` over a\n * whole set of records — a static build's content, an import — and never by a\n * single save, which cannot see the others.\n */\nexport interface EntityCardinality {\n readonly min?: number;\n readonly max?: number;\n}\n\nexport interface MetaEntityOptions {\n key?: string;\n domain?: string;\n /** Translation key for the entity's singular name, e.g. `entity:product-specification.label`. */\n labelKey?: string;\n /** Translation key for its plural, e.g. `entity:product-specification.plural`. */\n pluralKey?: string;\n /** How many records the entity may have. */\n cardinality?: EntityCardinality;\n /** Named shapes the entity is published in, by view name. */\n views?: Readonly<Record<string, EntityViewOptions>>;\n /**\n * `false` for an entity no person creates — one only ever written by a flow,\n * such as an order a checkout opens. A list of it offers no \"New\", whatever\n * the caller holds; absent, it offers one to a caller who may write it\n * ([ADR 0026](../../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)).\n */\n creatable?: boolean;\n /**\n * The member a record is called by — a `string`, a `localized`, a `number`\n * or a reference, in which case the record is called by its target's name.\n * Every surface that names a record (a row, a card's heading, a confirm\n * dialog, a breadcrumb, a toast) reads it through `recordLabel()`.\n * Undeclared, the first filled-in member that is not a key is used. Checked\n * when the entity is described: a member that does not exist, is hidden or\n * is a collection fails\n * ([ADR 0030](../../../../../../../docs/adr/0030-a-reference-names-its-target-through-the-owners-read-port.md)).\n */\n labelMember?: string;\n}\n\nexport class MetaEntity {\n //#region Properties\n readonly name: string;\n readonly key?: string;\n readonly domain?: string;\n readonly labelKey?: string;\n readonly pluralKey?: string;\n readonly cardinality?: EntityCardinality;\n readonly views?: Readonly<Record<string, EntityViewOptions>>;\n readonly creatable: boolean;\n readonly labelMember?: string;\n //#endregion\n\n //#region Constructors\n constructor(name: string, options?: MetaEntityOptions) {\n this.name = name;\n this.key = options?.key;\n this.domain = options?.domain;\n this.labelKey = options?.labelKey;\n this.pluralKey = options?.pluralKey;\n assertBounds(`${name}'s cardinality`, options?.cardinality);\n this.cardinality = options?.cardinality;\n this.views = options?.views;\n this.creatable = options?.creatable ?? true;\n this.labelMember = options?.labelMember;\n }\n //#endregion\n\n //#region Methods\n //#endregion\n\n //#region Accessors\n //#endregion\n}\n"],"names":["assertBounds","MetaEntity","name","options","key","domain","labelKey","pluralKey","cardinality","views","creatable","labelMember"],"mappings":"AAGA,SAASA,YAAY,QAAQ,eAAe;AAuE5C,OAAO,MAAMC;IAWX,YAAY;IAEZ,sBAAsB;IACtB,YAAYC,IAAY,EAAEC,OAA2B,CAAE;;QACrD,IAAI,CAACD,IAAI,GAAGA;QACZ,IAAI,CAACE,GAAG,GAAGD,2BAAAA,QAASC,GAAG;QACvB,IAAI,CAACC,MAAM,GAAGF,2BAAAA,QAASE,MAAM;QAC7B,IAAI,CAACC,QAAQ,GAAGH,2BAAAA,QAASG,QAAQ;QACjC,IAAI,CAACC,SAAS,GAAGJ,2BAAAA,QAASI,SAAS;QACnCP,aAAa,GAAGE,KAAK,cAAc,CAAC,EAAEC,2BAAAA,QAASK,WAAW;QAC1D,IAAI,CAACA,WAAW,GAAGL,2BAAAA,QAASK,WAAW;QACvC,IAAI,CAACC,KAAK,GAAGN,2BAAAA,QAASM,KAAK;QAC3B,IAAI,CAACC,SAAS,WAAGP,2BAAAA,QAASO,SAAS,mBAAI;QACvC,IAAI,CAACC,WAAW,GAAGR,2BAAAA,QAASQ,WAAW;IACzC;AAQF"}
@@ -52,6 +52,26 @@ export interface UseCaseConfirm {
52
52
  * surface renders it is one click on one of them.
53
53
  */
54
54
  export type UseCaseReversible = 'undo' | 'confirm' | 'typed';
55
+ /**
56
+ * The states a record must be in for a verb to apply to it: the record's
57
+ * `member` — an `enumValues` accessor, by its own name as the record holds
58
+ * it rather than any wire alias — holds one of `in`.
59
+ *
60
+ * ⚠️ **This is presentation, not authorization.** A surface hides a verb the
61
+ * record's state does not allow, so a shipment awaiting dispatch offers
62
+ * Dispatch and nothing that only a dispatched one can take. The verb's handler
63
+ * still refuses an illegal move — a record can change between the render and
64
+ * the click, and a selection carries no states at all — so a bulk run reports
65
+ * such a row as a failed outcome rather than skipping it on the client.
66
+ *
67
+ * Declared beside the verb rather than derived from a transition table because
68
+ * the framework has no notion of one; a host that keeps a table derives `in`
69
+ * from it, so the states are written once.
70
+ */
71
+ export interface UseCaseAvailability {
72
+ member: string;
73
+ in: readonly string[];
74
+ }
55
75
  /**
56
76
  * How much weight a surface gives a verb. One `primary` per surface — the
57
77
  * thing the surface is for — and every other verb `default`; a second primary
@@ -125,6 +145,12 @@ export interface MetaUseCaseOptions<TKey extends string, TEntity extends Entity>
125
145
  reversible?: UseCaseReversible;
126
146
  /** The verb Undo runs, by key. Required with `reversible: 'undo'`. */
127
147
  inverse?: string;
148
+ /**
149
+ * The states a record must be in for the verb to be offered on it — see
150
+ * {@link UseCaseAvailability}. Refused on an `unbound` verb, which has no
151
+ * record to be in a state.
152
+ */
153
+ availableWhen?: UseCaseAvailability;
128
154
  /** Names a form a surface should open instead of acting immediately. */
129
155
  form?: string;
130
156
  /**
@@ -171,6 +197,7 @@ export declare class MetaUseCase {
171
197
  readonly confirm?: UseCaseConfirm;
172
198
  readonly reversible?: UseCaseReversible;
173
199
  readonly inverse?: string;
200
+ readonly availableWhen?: UseCaseAvailability;
174
201
  readonly emphasis?: UseCaseEmphasis;
175
202
  readonly priority?: number;
176
203
  readonly rowInline?: true;
@@ -1 +1 @@
1
- {"version":3,"file":"meta-use-case.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/meta-entities/meta-use-case/meta-use-case.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE1E,oEAAoE;AACpE,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,YAAY,GAAG,SAAS,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAC1B,mBAAmB,GAAG,qBAAqB,GAAG,aAAa,CAAC;AAE9D;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,cAAc,CAAC;IACxB,SAAS,EAAE,gBAAgB,CAAC;CAC7B;AAED,sEAAsE;AACtE,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,aAAa,GAAG,SAAS,CAAC;IAChC,qDAAqD;IACrD,UAAU,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,SAAS,CAAC;AAEpD;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,SAAS,CAAC,EAAE,IAAI,CAAC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,CAAC;IACzC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,UAAU,CAAC,EAAE,iBAAiB,CAAC;IACxC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,aAAa,CAAC,EAAE,mBAAmB,CAAC;IAC7C,QAAQ,CAAC,QAAQ,CAAC,EAAE,eAAe,CAAC;IACpC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;gBAI9B,OAAO,EAAE,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC;CA8BxD"}
@@ -12,6 +12,7 @@ export class MetaUseCase {
12
12
  this.confirm = options.confirm;
13
13
  this.reversible = options.reversible;
14
14
  this.inverse = options.inverse;
15
+ this.availableWhen = options.availableWhen;
15
16
  this.emphasis = options.emphasis;
16
17
  this.priority = options.priority;
17
18
  this.rowInline = options.rowInline;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/entity-definition/meta-entities/meta-use-case/meta-use-case.ts"],"sourcesContent":["import type { Schema } from 'effect';\n\nimport type { FailureClass } from '../../../failure/failure.js';\nimport type { Entity, EntityConstructor } from '../../../types/Entity.js';\n\n/** What a use case acts on: one record, a selection, or nothing. */\nexport type UseCaseBinding = 'entity' | 'collection' | 'unbound';\n\n/**\n * Where a surface puts the action. Deliberately **not** derivable from\n * {@link UseCaseBinding}: an entity-bound action can be determining (a footer\n * \"Publish\" that finalizes the page) or context-independent (a toolbar action\n * available whenever a record is open). Collapsing the two would force every\n * surface to re-derive a placement the author already knew.\n */\nexport type UseCasePlacement =\n 'context-dependent' | 'context-independent' | 'determining';\n\n/**\n * One place a verb can appear: a binding and a placement together.\n *\n * The pair is the unit rather than either half, because the two answer\n * different questions — placement decides the *surface* and binding decides the\n * *payload* — and a verb reachable from a row and from a selection differs in\n * both at once.\n */\nexport interface UseCaseCell {\n binding: UseCaseBinding;\n placement: UseCasePlacement;\n}\n\n/** Confirmation a surface must obtain before running the use case. */\nexport interface UseCaseConfirm {\n tone: 'destructive' | 'neutral';\n /** Catalog key. Copy never lives in a descriptor. */\n messageKey: string;\n /**\n * Catalog key for the confirming button. Absent, the button repeats the\n * verb's own label: a dialog that says \"Confirm\" makes the reader go back to\n * the title to learn what they are agreeing to.\n */\n confirmLabelKey?: string;\n /**\n * Catalog key for what an `undo` verb's toast says once it has run, in the\n * past tense — \"Invoice voided.\" Absent, a generic sentence names the verb.\n */\n doneKey?: string;\n}\n\n/**\n * How a destructive verb is made safe\n * ([ADR 0026](../../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)):\n * - `undo` acts at once and offers Undo, which runs the verb's `inverse`;\n * - `confirm` asks first, in a dialog that names what will be destroyed;\n * - `typed` asks the reader to type the record's name, or the count, first.\n *\n * Required on every `confirm.tone: 'destructive'` verb, and refused at\n * declaration without it: a destructive verb whose safety is left to whichever\n * surface renders it is one click on one of them.\n */\nexport type UseCaseReversible = 'undo' | 'confirm' | 'typed';\n\n/**\n * How much weight a surface gives a verb. One `primary` per surface — the\n * thing the surface is for — and every other verb `default`; a second primary\n * on one surface throws when it renders\n * ([ADR 0026](../../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)).\n */\nexport type UseCaseEmphasis = 'primary' | 'default';\n\n/**\n * The hierarchy a surface renders a verb in: its weight, its order among the\n * secondaries, whether a row shows it inline, and the chord that reaches it.\n */\nexport interface UseCaseHierarchy {\n emphasis?: UseCaseEmphasis;\n /**\n * Order among the surface's secondaries, lowest first; equal or absent keeps\n * declaration order. The first three stay visible and the rest fold into\n * \"More actions\".\n */\n priority?: number;\n /**\n * Shown on the row itself rather than only in its menu — at most one verb\n * per entity, since a row with two inline buttons is a toolbar per row.\n */\n rowInline?: true;\n /**\n * A modifier chord, `Mod+Shift+P`: `Mod` is ⌘ on macOS and Ctrl elsewhere.\n * Rendered as `aria-keyshortcuts` and listed in the command palette.\n */\n shortcut?: string;\n}\n\n/**\n * What `@useCase()` declares.\n *\n * `entity` is the target the verb is registered against — it is what the\n * decorator appends to, and it is not part of the served descriptor.\n *\n * `labelKey` is mandatory and namespace-qualified, the `GuardedNavItem`\n * convention: i18n is mandatory and `react/jsx-no-literals` fails the build on a\n * string written into JSX, so a descriptor carrying copy could not be rendered.\n *\n * `keywordsKey` is a catalog key rather than a `string[]` so the command palette\n * matches across locales — a user typing an English term reaches a Spanish\n * command.\n */\nexport interface MetaUseCaseOptions<\n TKey extends string,\n TEntity extends Entity,\n> extends UseCaseHierarchy {\n entity: EntityConstructor<TEntity>;\n key: TKey;\n binding: UseCaseBinding;\n placement: UseCasePlacement;\n /**\n * Further places the same verb appears, beyond the {@link binding} and\n * {@link placement} above.\n *\n * ⚠️ **One verb, one permission, several surfaces.** Publishing an offering\n * from its form, from a row menu and over a selection is one act reached three\n * ways, and the alternative was three `@useCase()` classes — which `slices`\n * refuses anyway, since a verb key is the third segment of one permission and\n * two classes cannot share a key. Three classes would have meant three\n * permissions for one act, and a grant that let somebody publish one offering\n * but not twenty.\n *\n * The primary cell stays where it is so that nothing already declared\n * changes, and so a descriptor still reads as \"this verb lives here\" with the\n * rest as additions.\n */\n alsoAt?: readonly UseCaseCell[];\n labelKey: string;\n keywordsKey?: string;\n confirm?: UseCaseConfirm;\n /** How a destructive verb is made safe. Required when `confirm.tone` is `destructive`. */\n reversible?: UseCaseReversible;\n /** The verb Undo runs, by key. Required with `reversible: 'undo'`. */\n inverse?: string;\n /** Names a form a surface should open instead of acting immediately. */\n form?: string;\n /**\n * The use case whose variants this verb resolves between, by name: the\n * service holds the rules, and `$metadata` reports which one this caller\n * resolves to.\n */\n variants?: string;\n /** The recipe this verb starts a flow from, by name — the flow-backed verbs. */\n recipe?: string;\n /**\n * What the verb's endpoint takes, answers and refuses with — the contract\n * the shell derives the endpoint from. Absent `payload` means the verb takes\n * no body; absent `success` means its answer is not described. None of the\n * three reaches a served `$metadata` document.\n */\n payload?: Schema.Top;\n success?: Schema.Top;\n errors?: readonly FailureClass[];\n}\n\n/**\n * What the use-case class's **own** metadata carries, as opposed to what is\n * appended to the entity. Two fields are enough to derive the permission, which\n * is what lets `permissionForUseCase(SomeUC)` take a single argument and keeps\n * the verb string written exactly once.\n */\nexport interface MetaUseCaseBinding {\n entity: EntityConstructor<Entity>;\n key: string;\n /**\n * Which of the entity's verbs under `key` the class is: one key may be\n * declared on a record and over a selection, and each class is one of them.\n */\n binding: UseCaseBinding;\n}\n\nexport class MetaUseCase {\n //#region Properties\n readonly entity: EntityConstructor<Entity>;\n readonly key: string;\n readonly binding: UseCaseBinding;\n readonly placement: UseCasePlacement;\n readonly alsoAt?: readonly UseCaseCell[];\n readonly labelKey: string;\n readonly keywordsKey?: string;\n readonly confirm?: UseCaseConfirm;\n readonly reversible?: UseCaseReversible;\n readonly inverse?: string;\n readonly emphasis?: UseCaseEmphasis;\n readonly priority?: number;\n readonly rowInline?: true;\n readonly shortcut?: string;\n readonly form?: string;\n readonly variants?: string;\n readonly recipe?: string;\n readonly payload?: Schema.Top;\n readonly success?: Schema.Top;\n readonly errors?: readonly FailureClass[];\n //#endregion\n\n //#region Constructors\n constructor(options: MetaUseCaseOptions<string, Entity>) {\n this.entity = options.entity;\n this.key = options.key;\n this.binding = options.binding;\n this.placement = options.placement;\n this.alsoAt = options.alsoAt;\n this.labelKey = options.labelKey;\n this.keywordsKey = options.keywordsKey;\n this.confirm = options.confirm;\n this.reversible = options.reversible;\n this.inverse = options.inverse;\n this.emphasis = options.emphasis;\n this.priority = options.priority;\n this.rowInline = options.rowInline;\n this.shortcut = options.shortcut;\n this.form = options.form;\n this.variants = options.variants;\n this.recipe = options.recipe;\n this.payload = options.payload;\n this.success = options.success;\n this.errors = options.errors;\n }\n //#endregion\n\n //#region Methods\n //#endregion\n\n //#region Accessors\n //#endregion\n}\n"],"names":["MetaUseCase","options","entity","key","binding","placement","alsoAt","labelKey","keywordsKey","confirm","reversible","inverse","emphasis","priority","rowInline","shortcut","form","variants","recipe","payload","success","errors"],"mappings":"AAiLA,OAAO,MAAMA;IAsBX,YAAY;IAEZ,sBAAsB;IACtB,YAAYC,OAA2C,CAAE;QACvD,IAAI,CAACC,MAAM,GAAGD,QAAQC,MAAM;QAC5B,IAAI,CAACC,GAAG,GAAGF,QAAQE,GAAG;QACtB,IAAI,CAACC,OAAO,GAAGH,QAAQG,OAAO;QAC9B,IAAI,CAACC,SAAS,GAAGJ,QAAQI,SAAS;QAClC,IAAI,CAACC,MAAM,GAAGL,QAAQK,MAAM;QAC5B,IAAI,CAACC,QAAQ,GAAGN,QAAQM,QAAQ;QAChC,IAAI,CAACC,WAAW,GAAGP,QAAQO,WAAW;QACtC,IAAI,CAACC,OAAO,GAAGR,QAAQQ,OAAO;QAC9B,IAAI,CAACC,UAAU,GAAGT,QAAQS,UAAU;QACpC,IAAI,CAACC,OAAO,GAAGV,QAAQU,OAAO;QAC9B,IAAI,CAACC,QAAQ,GAAGX,QAAQW,QAAQ;QAChC,IAAI,CAACC,QAAQ,GAAGZ,QAAQY,QAAQ;QAChC,IAAI,CAACC,SAAS,GAAGb,QAAQa,SAAS;QAClC,IAAI,CAACC,QAAQ,GAAGd,QAAQc,QAAQ;QAChC,IAAI,CAACC,IAAI,GAAGf,QAAQe,IAAI;QACxB,IAAI,CAACC,QAAQ,GAAGhB,QAAQgB,QAAQ;QAChC,IAAI,CAACC,MAAM,GAAGjB,QAAQiB,MAAM;QAC5B,IAAI,CAACC,OAAO,GAAGlB,QAAQkB,OAAO;QAC9B,IAAI,CAACC,OAAO,GAAGnB,QAAQmB,OAAO;QAC9B,IAAI,CAACC,MAAM,GAAGpB,QAAQoB,MAAM;IAC9B;AAQF"}
1
+ {"version":3,"sources":["../../../../src/entity-definition/meta-entities/meta-use-case/meta-use-case.ts"],"sourcesContent":["import type { Schema } from 'effect';\n\nimport type { FailureClass } from '../../../failure/failure.js';\nimport type { Entity, EntityConstructor } from '../../../types/Entity.js';\n\n/** What a use case acts on: one record, a selection, or nothing. */\nexport type UseCaseBinding = 'entity' | 'collection' | 'unbound';\n\n/**\n * Where a surface puts the action. Deliberately **not** derivable from\n * {@link UseCaseBinding}: an entity-bound action can be determining (a footer\n * \"Publish\" that finalizes the page) or context-independent (a toolbar action\n * available whenever a record is open). Collapsing the two would force every\n * surface to re-derive a placement the author already knew.\n */\nexport type UseCasePlacement =\n 'context-dependent' | 'context-independent' | 'determining';\n\n/**\n * One place a verb can appear: a binding and a placement together.\n *\n * The pair is the unit rather than either half, because the two answer\n * different questions — placement decides the *surface* and binding decides the\n * *payload* — and a verb reachable from a row and from a selection differs in\n * both at once.\n */\nexport interface UseCaseCell {\n binding: UseCaseBinding;\n placement: UseCasePlacement;\n}\n\n/** Confirmation a surface must obtain before running the use case. */\nexport interface UseCaseConfirm {\n tone: 'destructive' | 'neutral';\n /** Catalog key. Copy never lives in a descriptor. */\n messageKey: string;\n /**\n * Catalog key for the confirming button. Absent, the button repeats the\n * verb's own label: a dialog that says \"Confirm\" makes the reader go back to\n * the title to learn what they are agreeing to.\n */\n confirmLabelKey?: string;\n /**\n * Catalog key for what an `undo` verb's toast says once it has run, in the\n * past tense — \"Invoice voided.\" Absent, a generic sentence names the verb.\n */\n doneKey?: string;\n}\n\n/**\n * How a destructive verb is made safe\n * ([ADR 0026](../../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)):\n * - `undo` acts at once and offers Undo, which runs the verb's `inverse`;\n * - `confirm` asks first, in a dialog that names what will be destroyed;\n * - `typed` asks the reader to type the record's name, or the count, first.\n *\n * Required on every `confirm.tone: 'destructive'` verb, and refused at\n * declaration without it: a destructive verb whose safety is left to whichever\n * surface renders it is one click on one of them.\n */\nexport type UseCaseReversible = 'undo' | 'confirm' | 'typed';\n\n/**\n * The states a record must be in for a verb to apply to it: the record's\n * `member` — an `enumValues` accessor, by its own name as the record holds\n * it rather than any wire alias — holds one of `in`.\n *\n * ⚠️ **This is presentation, not authorization.** A surface hides a verb the\n * record's state does not allow, so a shipment awaiting dispatch offers\n * Dispatch and nothing that only a dispatched one can take. The verb's handler\n * still refuses an illegal move — a record can change between the render and\n * the click, and a selection carries no states at all — so a bulk run reports\n * such a row as a failed outcome rather than skipping it on the client.\n *\n * Declared beside the verb rather than derived from a transition table because\n * the framework has no notion of one; a host that keeps a table derives `in`\n * from it, so the states are written once.\n */\nexport interface UseCaseAvailability {\n member: string;\n in: readonly string[];\n}\n\n/**\n * How much weight a surface gives a verb. One `primary` per surface — the\n * thing the surface is for — and every other verb `default`; a second primary\n * on one surface throws when it renders\n * ([ADR 0026](../../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)).\n */\nexport type UseCaseEmphasis = 'primary' | 'default';\n\n/**\n * The hierarchy a surface renders a verb in: its weight, its order among the\n * secondaries, whether a row shows it inline, and the chord that reaches it.\n */\nexport interface UseCaseHierarchy {\n emphasis?: UseCaseEmphasis;\n /**\n * Order among the surface's secondaries, lowest first; equal or absent keeps\n * declaration order. The first three stay visible and the rest fold into\n * \"More actions\".\n */\n priority?: number;\n /**\n * Shown on the row itself rather than only in its menu — at most one verb\n * per entity, since a row with two inline buttons is a toolbar per row.\n */\n rowInline?: true;\n /**\n * A modifier chord, `Mod+Shift+P`: `Mod` is ⌘ on macOS and Ctrl elsewhere.\n * Rendered as `aria-keyshortcuts` and listed in the command palette.\n */\n shortcut?: string;\n}\n\n/**\n * What `@useCase()` declares.\n *\n * `entity` is the target the verb is registered against — it is what the\n * decorator appends to, and it is not part of the served descriptor.\n *\n * `labelKey` is mandatory and namespace-qualified, the `GuardedNavItem`\n * convention: i18n is mandatory and `react/jsx-no-literals` fails the build on a\n * string written into JSX, so a descriptor carrying copy could not be rendered.\n *\n * `keywordsKey` is a catalog key rather than a `string[]` so the command palette\n * matches across locales — a user typing an English term reaches a Spanish\n * command.\n */\nexport interface MetaUseCaseOptions<\n TKey extends string,\n TEntity extends Entity,\n> extends UseCaseHierarchy {\n entity: EntityConstructor<TEntity>;\n key: TKey;\n binding: UseCaseBinding;\n placement: UseCasePlacement;\n /**\n * Further places the same verb appears, beyond the {@link binding} and\n * {@link placement} above.\n *\n * ⚠️ **One verb, one permission, several surfaces.** Publishing an offering\n * from its form, from a row menu and over a selection is one act reached three\n * ways, and the alternative was three `@useCase()` classes — which `slices`\n * refuses anyway, since a verb key is the third segment of one permission and\n * two classes cannot share a key. Three classes would have meant three\n * permissions for one act, and a grant that let somebody publish one offering\n * but not twenty.\n *\n * The primary cell stays where it is so that nothing already declared\n * changes, and so a descriptor still reads as \"this verb lives here\" with the\n * rest as additions.\n */\n alsoAt?: readonly UseCaseCell[];\n labelKey: string;\n keywordsKey?: string;\n confirm?: UseCaseConfirm;\n /** How a destructive verb is made safe. Required when `confirm.tone` is `destructive`. */\n reversible?: UseCaseReversible;\n /** The verb Undo runs, by key. Required with `reversible: 'undo'`. */\n inverse?: string;\n /**\n * The states a record must be in for the verb to be offered on it — see\n * {@link UseCaseAvailability}. Refused on an `unbound` verb, which has no\n * record to be in a state.\n */\n availableWhen?: UseCaseAvailability;\n /** Names a form a surface should open instead of acting immediately. */\n form?: string;\n /**\n * The use case whose variants this verb resolves between, by name: the\n * service holds the rules, and `$metadata` reports which one this caller\n * resolves to.\n */\n variants?: string;\n /** The recipe this verb starts a flow from, by name — the flow-backed verbs. */\n recipe?: string;\n /**\n * What the verb's endpoint takes, answers and refuses with — the contract\n * the shell derives the endpoint from. Absent `payload` means the verb takes\n * no body; absent `success` means its answer is not described. None of the\n * three reaches a served `$metadata` document.\n */\n payload?: Schema.Top;\n success?: Schema.Top;\n errors?: readonly FailureClass[];\n}\n\n/**\n * What the use-case class's **own** metadata carries, as opposed to what is\n * appended to the entity. Two fields are enough to derive the permission, which\n * is what lets `permissionForUseCase(SomeUC)` take a single argument and keeps\n * the verb string written exactly once.\n */\nexport interface MetaUseCaseBinding {\n entity: EntityConstructor<Entity>;\n key: string;\n /**\n * Which of the entity's verbs under `key` the class is: one key may be\n * declared on a record and over a selection, and each class is one of them.\n */\n binding: UseCaseBinding;\n}\n\nexport class MetaUseCase {\n //#region Properties\n readonly entity: EntityConstructor<Entity>;\n readonly key: string;\n readonly binding: UseCaseBinding;\n readonly placement: UseCasePlacement;\n readonly alsoAt?: readonly UseCaseCell[];\n readonly labelKey: string;\n readonly keywordsKey?: string;\n readonly confirm?: UseCaseConfirm;\n readonly reversible?: UseCaseReversible;\n readonly inverse?: string;\n readonly availableWhen?: UseCaseAvailability;\n readonly emphasis?: UseCaseEmphasis;\n readonly priority?: number;\n readonly rowInline?: true;\n readonly shortcut?: string;\n readonly form?: string;\n readonly variants?: string;\n readonly recipe?: string;\n readonly payload?: Schema.Top;\n readonly success?: Schema.Top;\n readonly errors?: readonly FailureClass[];\n //#endregion\n\n //#region Constructors\n constructor(options: MetaUseCaseOptions<string, Entity>) {\n this.entity = options.entity;\n this.key = options.key;\n this.binding = options.binding;\n this.placement = options.placement;\n this.alsoAt = options.alsoAt;\n this.labelKey = options.labelKey;\n this.keywordsKey = options.keywordsKey;\n this.confirm = options.confirm;\n this.reversible = options.reversible;\n this.inverse = options.inverse;\n this.availableWhen = options.availableWhen;\n this.emphasis = options.emphasis;\n this.priority = options.priority;\n this.rowInline = options.rowInline;\n this.shortcut = options.shortcut;\n this.form = options.form;\n this.variants = options.variants;\n this.recipe = options.recipe;\n this.payload = options.payload;\n this.success = options.success;\n this.errors = options.errors;\n }\n //#endregion\n\n //#region Methods\n //#endregion\n\n //#region Accessors\n //#endregion\n}\n"],"names":["MetaUseCase","options","entity","key","binding","placement","alsoAt","labelKey","keywordsKey","confirm","reversible","inverse","availableWhen","emphasis","priority","rowInline","shortcut","form","variants","recipe","payload","success","errors"],"mappings":"AA4MA,OAAO,MAAMA;IAuBX,YAAY;IAEZ,sBAAsB;IACtB,YAAYC,OAA2C,CAAE;QACvD,IAAI,CAACC,MAAM,GAAGD,QAAQC,MAAM;QAC5B,IAAI,CAACC,GAAG,GAAGF,QAAQE,GAAG;QACtB,IAAI,CAACC,OAAO,GAAGH,QAAQG,OAAO;QAC9B,IAAI,CAACC,SAAS,GAAGJ,QAAQI,SAAS;QAClC,IAAI,CAACC,MAAM,GAAGL,QAAQK,MAAM;QAC5B,IAAI,CAACC,QAAQ,GAAGN,QAAQM,QAAQ;QAChC,IAAI,CAACC,WAAW,GAAGP,QAAQO,WAAW;QACtC,IAAI,CAACC,OAAO,GAAGR,QAAQQ,OAAO;QAC9B,IAAI,CAACC,UAAU,GAAGT,QAAQS,UAAU;QACpC,IAAI,CAACC,OAAO,GAAGV,QAAQU,OAAO;QAC9B,IAAI,CAACC,aAAa,GAAGX,QAAQW,aAAa;QAC1C,IAAI,CAACC,QAAQ,GAAGZ,QAAQY,QAAQ;QAChC,IAAI,CAACC,QAAQ,GAAGb,QAAQa,QAAQ;QAChC,IAAI,CAACC,SAAS,GAAGd,QAAQc,SAAS;QAClC,IAAI,CAACC,QAAQ,GAAGf,QAAQe,QAAQ;QAChC,IAAI,CAACC,IAAI,GAAGhB,QAAQgB,IAAI;QACxB,IAAI,CAACC,QAAQ,GAAGjB,QAAQiB,QAAQ;QAChC,IAAI,CAACC,MAAM,GAAGlB,QAAQkB,MAAM;QAC5B,IAAI,CAACC,OAAO,GAAGnB,QAAQmB,OAAO;QAC9B,IAAI,CAACC,OAAO,GAAGpB,QAAQoB,OAAO;QAC9B,IAAI,CAACC,MAAM,GAAGrB,QAAQqB,MAAM;IAC9B;AAQF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entifix/core",
3
- "version": "0.20.2",
3
+ "version": "0.21.0",
4
4
  "description": "The entity system: decorators that make a class describe itself, entity serialization, the RSQL query protocol and the wire envelopes.",
5
5
  "license": "MIT",
6
6
  "repository": {