@entifix/core 0.20.3 → 0.22.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 (29) hide show
  1. package/dist/entity-definition/describe/describe-entity-columns.d.ts +8 -1
  2. package/dist/entity-definition/describe/describe-entity-columns.d.ts.map +1 -1
  3. package/dist/entity-definition/describe/describe-entity-columns.js +78 -4
  4. package/dist/entity-definition/describe/describe-entity-columns.js.map +1 -1
  5. package/dist/entity-definition/describe/index.d.ts +1 -0
  6. package/dist/entity-definition/describe/index.d.ts.map +1 -1
  7. package/dist/entity-definition/describe/index.js +1 -0
  8. package/dist/entity-definition/describe/index.js.map +1 -1
  9. package/dist/entity-definition/describe/query-property.d.ts +11 -0
  10. package/dist/entity-definition/describe/query-property.d.ts.map +1 -1
  11. package/dist/entity-definition/describe/query-property.js +19 -0
  12. package/dist/entity-definition/describe/query-property.js.map +1 -1
  13. package/dist/entity-definition/describe/record-label.d.ts +69 -0
  14. package/dist/entity-definition/describe/record-label.d.ts.map +1 -0
  15. package/dist/entity-definition/describe/record-label.js +97 -0
  16. package/dist/entity-definition/describe/record-label.js.map +1 -0
  17. package/dist/entity-definition/helpers/entity-definition-helpers.d.ts +5 -0
  18. package/dist/entity-definition/helpers/entity-definition-helpers.d.ts.map +1 -1
  19. package/dist/entity-definition/helpers/entity-definition-helpers.js +7 -0
  20. package/dist/entity-definition/helpers/entity-definition-helpers.js.map +1 -1
  21. package/dist/entity-definition/meta-entities/meta-accessor/meta-accessor.d.ts +35 -0
  22. package/dist/entity-definition/meta-entities/meta-accessor/meta-accessor.d.ts.map +1 -1
  23. package/dist/entity-definition/meta-entities/meta-accessor/meta-accessor.js +12 -0
  24. package/dist/entity-definition/meta-entities/meta-accessor/meta-accessor.js.map +1 -1
  25. package/dist/entity-definition/meta-entities/meta-entity/meta-entity.d.ts +12 -0
  26. package/dist/entity-definition/meta-entities/meta-entity/meta-entity.d.ts.map +1 -1
  27. package/dist/entity-definition/meta-entities/meta-entity/meta-entity.js +1 -0
  28. package/dist/entity-definition/meta-entities/meta-entity/meta-entity.js.map +1 -1
  29. package/package.json +1 -1
@@ -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 EnumTone, 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
@@ -29,6 +29,8 @@ export interface EntityFieldDescriptor {
29
29
  enumValues?: readonly string[];
30
30
  /** Catalog prefix for {@link enumValues}; a value reads as `${enumLabelKey}.${value}`. */
31
31
  enumLabelKey?: string;
32
+ /** The tone each value reads in as a status, when the member declares them. */
33
+ enumTones?: Readonly<Record<string, EnumTone>>;
32
34
  /** Property of a `link` target used as its display label. */
33
35
  linkLabelProperty: string;
34
36
  /** Property of a `link` target a picker searches on. Defaults to the label. */
@@ -61,6 +63,11 @@ export interface EntityFieldDescriptor {
61
63
  autocomplete?: string;
62
64
  /** This member holds the parent record's id: the entity forms a tree. */
63
65
  parent?: boolean;
66
+ /**
67
+ * This member holds the id of a record of another entity, named `domain:key`.
68
+ * A screen shows that record's name in its place.
69
+ */
70
+ references?: MemberReference;
64
71
  }
65
72
  /** Types whose values are scalars a user can meaningfully sort/filter on. */
66
73
  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,W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C;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB,EAAE,SAAS,gBAAgB,EAIvD,CAAC;AAoIF;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,SAAS;IAChB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC3B,EAAE,QAQJ;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,SAAS;IAChB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B,EAAE,QAWJ;AAsDD;;;;;;;;;;;;;;;;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,QAAQ,EAEb,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;I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,eAAO,MAAM,gBAAgB,EAAE,SAAS,gBAAgB,EAIvD,CAAC;AA8OF;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,SAAS;IAChB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC3B,EAAE,QAQJ;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,SAAS;IAChB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B,EAAE,QAWJ;AA+DD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,MAAM,EAC1D,iBAAiB,EAAE,gBAAgB,CAAC,OAAO,CAAC,EAC5C,MAAM,CAAC,EAAE,OAAO,GACf,qBAAqB,EAAE,CAqBzB"}
@@ -1,8 +1,9 @@
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';
6
+ import { EnumTones } from '../meta-entities/meta-accessor/index.js';
6
7
  /** Types whose values are scalars a user can meaningfully sort/filter on. */ export const SCALAR_TYPES = [
7
8
  'string',
8
9
  'number',
@@ -93,10 +94,75 @@ import { assertBounds } from '../meta-entities/bounds.js';
93
94
  if (type === 'id' || type === 'string') return;
94
95
  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
96
  }
97
+ /** 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]+)*$/;
98
+ /**
99
+ * A reference holds one record's id, so it is an `id` or a `string` member, and
100
+ * names its target as `domain:key`. On the `parent` member it may only name the
101
+ * entity itself — a parent is a record of the same entity, built into a tree —
102
+ * which is what lets a list show a branch's parent by name.
103
+ */ function assertReference(target, metaAccessor, type) {
104
+ const { references } = metaAccessor;
105
+ if (references === undefined) return;
106
+ const name = String(metaAccessor.name);
107
+ if (type !== 'id' && type !== 'string') {
108
+ 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.`);
109
+ }
110
+ if (!REFERENCE_KEY.test(references.entity)) {
111
+ throw new Error(`"${name}" references "${references.entity}", which is not an entity's "domain:key" — the pair its @entity({ domain, key }) declares.`);
112
+ }
113
+ const own = findMetaEntity(target);
114
+ if (metaAccessor.parent === true && references.entity !== `${own == null ? void 0 : own.domain}:${own == null ? void 0 : own.key}`) {
115
+ 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.`);
116
+ }
117
+ }
118
+ /** Members whose value can name a record: a text, a number, or a reference to one. */ const LABEL_TYPES = [
119
+ 'string',
120
+ 'number',
121
+ 'localized'
122
+ ];
123
+ /**
124
+ * An entity's `labelMember` must be a visible member that holds one value a
125
+ * person can read: a hidden one never reaches the client, and a collection is
126
+ * many names. Checked against every accessor, since a hidden member is exactly
127
+ * the one describing would never see.
128
+ */ function assertLabelMember(target, descriptors) {
129
+ var _findMetaEntity;
130
+ const labelMember = (_findMetaEntity = findMetaEntity(target)) == null ? void 0 : _findMetaEntity.labelMember;
131
+ if (labelMember === undefined) return;
132
+ const declared = extractMetaAccessors(target).some((metaAccessor)=>String(metaAccessor.name) === labelMember);
133
+ const descriptor = descriptors.find((other)=>other.name === labelMember);
134
+ if (descriptor === undefined) {
135
+ 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.`);
136
+ }
137
+ if (descriptor.references === undefined && !LABEL_TYPES.includes(descriptor.type)) {
138
+ 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.`);
139
+ }
140
+ }
96
141
  /** Money is a reading of a number; any other member declaring it is a mistake. */ function assertMoneyType(metaAccessor, type) {
97
142
  if (metaAccessor.money === undefined || type === 'number') return;
98
143
  throw new Error(`"${String(metaAccessor.name)}" is a ${type} and declares money — only a number member can be an amount.`);
99
144
  }
145
+ /**
146
+ * Tones belong to an enum's values: on any other member, or keyed by a value
147
+ * the enum does not have, they would colour nothing — or the wrong thing.
148
+ */ function assertEnumTones(metaAccessor, type) {
149
+ var _metaAccessor_enumValues;
150
+ const { enumTones } = metaAccessor;
151
+ if (enumTones === undefined) return;
152
+ const name = String(metaAccessor.name);
153
+ if (type !== 'enum') {
154
+ throw new Error(`"${name}" is a ${type} and declares enumTones — only an enum member's values have a tone.`);
155
+ }
156
+ const values = (_metaAccessor_enumValues = metaAccessor.enumValues) != null ? _metaAccessor_enumValues : [];
157
+ for (const [value, tone] of Object.entries(enumTones)){
158
+ if (!values.includes(value)) {
159
+ throw new Error(`"${name}" declares a tone for "${value}", which is not one of its enumValues (${values.join(', ')}).`);
160
+ }
161
+ if (!EnumTones.includes(tone)) {
162
+ throw new Error(`"${name}" declares tone "${String(tone)}" for "${value}" — a tone is one of ${EnumTones.join(', ')}.`);
163
+ }
164
+ }
165
+ }
100
166
  /** A width is a positive length; zero or less would never switch layouts. */ function assertMinWidth(metaAccessor) {
101
167
  const { minWidth } = metaAccessor;
102
168
  if (minWidth === undefined || Number.isFinite(minWidth) && minWidth > 0) return;
@@ -138,14 +204,16 @@ import { assertBounds } from '../meta-entities/bounds.js';
138
204
  if (stuck === undefined) return;
139
205
  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
206
  }
141
- function toDescriptor(metaAccessor, index, sample) {
207
+ function toDescriptor(target, metaAccessor, index, sample) {
142
208
  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
209
  const name = String(metaAccessor.name);
144
210
  const type = (_metaAccessor_type = metaAccessor.type) != null ? _metaAccessor_type : inferType(name, sample == null ? void 0 : sample[name]);
145
211
  assertNotQueryable(metaAccessor, type);
146
212
  assertItemCounts(metaAccessor, type);
147
213
  assertParentType(metaAccessor, type);
214
+ assertReference(target, metaAccessor, type);
148
215
  assertMoneyType(metaAccessor, type);
216
+ assertEnumTones(metaAccessor, type);
149
217
  assertMinWidth(metaAccessor);
150
218
  // A localized member is queried one locale at a time (`name.en`), which
151
219
  // makes it as queryable as the text each locale holds.
@@ -163,7 +231,10 @@ function toDescriptor(metaAccessor, index, sample) {
163
231
  readonly: (_metaAccessor_readonly = metaAccessor.readonly) != null ? _metaAccessor_readonly : false,
164
232
  required: (_metaAccessor_required = metaAccessor.required) != null ? _metaAccessor_required : false,
165
233
  enumValues: metaAccessor.enumValues,
166
- enumLabelKey: metaAccessor.enumLabelKey,
234
+ enumLabelKey: metaAccessor.enumLabelKey
235
+ }, metaAccessor.enumTones === undefined ? {} : {
236
+ enumTones: metaAccessor.enumTones
237
+ }, {
167
238
  linkLabelProperty,
168
239
  linkSearchProperty: (_metaAccessor_linkSearchProperty = metaAccessor.linkSearchProperty) != null ? _metaAccessor_linkSearchProperty : linkLabelProperty,
169
240
  linkSerialization: (_metaAccessor_linkSerialization = metaAccessor.linkSerialization) != null ? _metaAccessor_linkSerialization : 'id',
@@ -182,6 +253,8 @@ function toDescriptor(metaAccessor, index, sample) {
182
253
  autocomplete: metaAccessor.autocomplete
183
254
  }, {
184
255
  parent: (_metaAccessor_parent = metaAccessor.parent) != null ? _metaAccessor_parent : false
256
+ }, metaAccessor.references === undefined ? {} : {
257
+ references: metaAccessor.references
185
258
  });
186
259
  }
187
260
  /**
@@ -209,10 +282,11 @@ function toDescriptor(metaAccessor, index, sample) {
209
282
  if (seen.has(name)) return false;
210
283
  seen.add(name);
211
284
  return true;
212
- }).map((metaAccessor, index)=>toDescriptor(metaAccessor, index, sample)).sort((left, right)=>left.order - right.order);
285
+ }).map((metaAccessor, index)=>toDescriptor(entityConstructor, metaAccessor, index, sample)).sort((left, right)=>left.order - right.order);
213
286
  assertNotBefore(descriptors);
214
287
  assertCurrencyMembers(descriptors);
215
288
  assertOneParent(descriptors);
289
+ assertLabelMember(entityConstructor, descriptors);
216
290
  return descriptors;
217
291
  }
218
292
 
@@ -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,SAASC,UAAU,QAAQ,gCAAgC;AAC3D,SAASC,YAAY,QAAQ,6BAA6B;AA0E1D,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,KACJC,OAAO,CAAC,UAAU,KAClBA,OAAO,CAAC,sBAAsB,SAC9BA,OAA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AAS;OAC7BhB,aAAauB,KAAK,KAAKb,YAAY,CAAC,IAAI;QAAEa,OAAOvB,aAAauB,KAAK;IAAC,GACpEvB,aAAayB,QAAQ,KAAKf,YAC1B,CAAC,IACD;QAAEe,UAAUzB,aAAayB,QAAQ;IAAC,GAClCzB,aAAa4D,IAAI,KAAKlD,YAAY,CAAC,IAAI;QAAEkD,MAAM5D,aAAa4D,IAAI;IAAC,GACjE5D,aAAa6D,YAAY,KAAKnD,YAC9B,CAAC,IACD;QAAEmD,cAAc7D,aAAa6D,YAAY;IAAC;QAC9CxC,MAAM,GAAErB,uBAAAA,aAAaqB,MAAM,YAAnBrB,uBAAuB;;AAEnC;AAEA;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,SAAS8D,sBACdC,iBAA4C,EAC5ClB,MAAgB;IAEhB,MAAMmB,OAAO,IAAIC;IACjB1B,oBAAoBvD,qBAAqB+E;IAEzC,MAAMjD,cAAc9B,qBAAqB+E,mBACtC5B,MAAM,CAACnC,CAAAA;QACN,IAAIA,aAAayC,MAAM,IAAIzC,aAAakE,IAAI,KAAK,UAAU,OAAO;QAClE,MAAM3E,OAAOe,OAAON,aAAaT,IAAI;QACrC,IAAIyE,KAAKG,GAAG,CAAC5E,OAAO,OAAO;QAC3ByE,KAAKI,GAAG,CAAC7E;QACT,OAAO;IACT,GACC8C,GAAG,CAAC,CAACrC,cAAc4C,QAAUD,aAAa3C,cAAc4C,OAAOC,SAC/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 EnumTone,\n EnumTones,\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 /** The tone each value reads in as a status, when the member declares them. */\n enumTones?: Readonly<Record<string, EnumTone>>;\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/**\n * Tones belong to an enum's values: on any other member, or keyed by a value\n * the enum does not have, they would colour nothing — or the wrong thing.\n */\nfunction assertEnumTones(metaAccessor: MetaAccessor, type: MetaAccessorType) {\n const { enumTones } = metaAccessor;\n if (enumTones === undefined) return;\n const name = String(metaAccessor.name);\n if (type !== 'enum') {\n throw new Error(\n `\"${name}\" is a ${type} and declares enumTones — only an enum member's values have a tone.`,\n );\n }\n const values = metaAccessor.enumValues ?? [];\n for (const [value, tone] of Object.entries(enumTones)) {\n if (!values.includes(value)) {\n throw new Error(\n `\"${name}\" declares a tone for \"${value}\", which is not one of its enumValues (${values.join(', ')}).`,\n );\n }\n if (!(EnumTones as readonly string[]).includes(tone)) {\n throw new Error(\n `\"${name}\" declares tone \"${String(tone)}\" for \"${value}\" — a tone is one of ${EnumTones.join(', ')}.`,\n );\n }\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 assertEnumTones(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 ...(metaAccessor.enumTones === undefined\n ? {}\n : { enumTones: metaAccessor.enumTones }),\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","EnumTones","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","assertEnumTones","enumTones","values","enumValues","tone","Object","entries","join","assertMinWidth","minWidth","Number","isFinite","assertCurrencyMembers","member","currencyMember","currency","assertOneParent","members","parents","filter","length","map","assertParentVisible","stuck","hidden","readonly","toDescriptor","index","sample","isScalar","linkLabelProperty","alias","label","labelKey","order","required","enumLabelKey","linkSearchProperty","linkSerialization","childType","resetOnClone","card","autocomplete","describeEntityColumns","entityConstructor","seen","Set","kind","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SAASwD,sBACdC,iBAA4C,EAC5ChB,MAAgB;IAEhB,MAAMiB,OAAO,IAAIC;IACjBxB,oBAAoB9E,qBAAqBoG;IAEzC,MAAMpE,cAAchC,qBAAqBoG,mBACtCzB,MAAM,CAACzD,CAAAA;QACN,IAAIA,aAAa8D,MAAM,IAAI9D,aAAaqF,IAAI,KAAK,UAAU,OAAO;QAClE,MAAM9F,OAAOe,OAAON,aAAaT,IAAI;QACrC,IAAI4F,KAAKG,GAAG,CAAC/F,OAAO,OAAO;QAC3B4F,KAAKI,GAAG,CAAChG;QACT,OAAO;IACT,GACCoE,GAAG,CAAC,CAAC3D,cAAciE,QAClBD,aAAakB,mBAAmBlF,cAAciE,OAAOC,SAEtDsB,IAAI,CAAC,CAACC,MAAMC,QAAUD,KAAKjB,KAAK,GAAGkB,MAAMlB,KAAK;IACjD3D,gBAAgBC;IAChBoC,sBAAsBpC;IACtBwC,gBAAgBxC;IAChBkB,kBAAkBkD,mBAAmBpE;IACrC,OAAOA;AACT"}
@@ -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"}
@@ -8,6 +8,17 @@ import type { EntityFieldDescriptor } from './describe-entity-columns.js';
8
8
  * refuses.
9
9
  */
10
10
  export declare function queryPropertyFor(descriptor: EntityFieldDescriptor, locale: Locale): string;
11
+ /**
12
+ * The property a filter or sort names for a member, and how one of its values
13
+ * reads, in a given locale — the pair a control that both queries a member and
14
+ * shows it needs. A `localized` member is queried as `title.<locale>` and read
15
+ * in that locale (falling back to the default one); any other member is its
16
+ * wire key and reads as itself.
17
+ */
18
+ export declare function localizedQueryProperty(descriptor: EntityFieldDescriptor, locale: Locale): {
19
+ readonly property: string;
20
+ readonly read: (value: unknown) => string | undefined;
21
+ };
11
22
  /**
12
23
  * The member an applied filter or sort names — by its accessor name, its wire
13
24
  * key, or a locale path into a `localized` one — so a control can show what is
@@ -1 +1 @@
1
- {"version":3,"file":"query-property.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/describe/query-property.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAE1E;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,qBAAqB,EACjC,MAAM,EAAE,MAAM,GACb,MAAM,CAIR;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,SAAS,qBAAqB,EAAE,EAC7C,QAAQ,EAAE,MAAM,GACf,qBAAqB,GAAG,SAAS,CASnC"}
1
+ {"version":3,"file":"query-property.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/describe/query-property.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAE1E;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,qBAAqB,EACjC,MAAM,EAAE,MAAM,GACb,MAAM,CAIR;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,qBAAqB,EACjC,MAAM,EAAE,MAAM,GACb;IACD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,GAAG,SAAS,CAAC;CACvD,CAWA;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,SAAS,qBAAqB,EAAE,EAC7C,QAAQ,EAAE,MAAM,GACf,qBAAqB,GAAG,SAAS,CASnC"}
@@ -1,3 +1,4 @@
1
+ import { isLocalizedText, localize } from '../../i18n/localized-text.js';
1
2
  /**
2
3
  * The property a filter or sort names for a member: its wire key, or for a
3
4
  * `localized` member the path to one locale's text — the only way one is
@@ -7,6 +8,24 @@
7
8
  */ export function queryPropertyFor(descriptor, locale) {
8
9
  return descriptor.type === 'localized' ? `${descriptor.key}.${locale}` : descriptor.key;
9
10
  }
11
+ /**
12
+ * The property a filter or sort names for a member, and how one of its values
13
+ * reads, in a given locale — the pair a control that both queries a member and
14
+ * shows it needs. A `localized` member is queried as `title.<locale>` and read
15
+ * in that locale (falling back to the default one); any other member is its
16
+ * wire key and reads as itself.
17
+ */ export function localizedQueryProperty(descriptor, locale) {
18
+ return {
19
+ property: queryPropertyFor(descriptor, locale),
20
+ read: (value)=>{
21
+ if (value == null) return undefined;
22
+ if (descriptor.type === 'localized') {
23
+ return isLocalizedText(value) ? localize(value, locale) : undefined;
24
+ }
25
+ return String(value);
26
+ }
27
+ };
28
+ }
10
29
  /**
11
30
  * The member an applied filter or sort names — by its accessor name, its wire
12
31
  * key, or a locale path into a `localized` one — so a control can show what is
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/entity-definition/describe/query-property.ts"],"sourcesContent":["import type { Locale } from '../../i18n/locales.js';\nimport type { EntityFieldDescriptor } from './describe-entity-columns.js';\n\n/**\n * The property a filter or sort names for a member: its wire key, or for a\n * `localized` member the path to one locale's text — the only way one is\n * queried (`title.en`). A control building a query from a descriptor asks this\n * rather than reading `key`, so it never sends the bare object the server\n * refuses.\n */\nexport function queryPropertyFor(\n descriptor: EntityFieldDescriptor,\n locale: Locale,\n): string {\n return descriptor.type === 'localized'\n ? `${descriptor.key}.${locale}`\n : descriptor.key;\n}\n\n/**\n * The member an applied filter or sort names — by its accessor name, its wire\n * key, or a locale path into a `localized` one — so a control can show what is\n * in effect.\n */\nexport function findQueriedDescriptor(\n descriptors: readonly EntityFieldDescriptor[],\n property: string,\n): EntityFieldDescriptor | undefined {\n return descriptors.find(\n descriptor =>\n descriptor.key === property ||\n descriptor.name === property ||\n (descriptor.type === 'localized' &&\n (property.startsWith(`${descriptor.key}.`) ||\n property.startsWith(`${descriptor.name}.`))),\n );\n}\n"],"names":["queryPropertyFor","descriptor","locale","type","key","findQueriedDescriptor","descriptors","property","find","name","startsWith"],"mappings":"AAGA;;;;;;CAMC,GACD,OAAO,SAASA,iBACdC,UAAiC,EACjCC,MAAc;IAEd,OAAOD,WAAWE,IAAI,KAAK,cACvB,GAAGF,WAAWG,GAAG,CAAC,CAAC,EAAEF,QAAQ,GAC7BD,WAAWG,GAAG;AACpB;AAEA;;;;CAIC,GACD,OAAO,SAASC,sBACdC,WAA6C,EAC7CC,QAAgB;IAEhB,OAAOD,YAAYE,IAAI,CACrBP,CAAAA,aACEA,WAAWG,GAAG,KAAKG,YACnBN,WAAWQ,IAAI,KAAKF,YACnBN,WAAWE,IAAI,KAAK,eAClBI,CAAAA,SAASG,UAAU,CAAC,GAAGT,WAAWG,GAAG,CAAC,CAAC,CAAC,KACvCG,SAASG,UAAU,CAAC,GAAGT,WAAWQ,IAAI,CAAC,CAAC,CAAC,CAAA;AAEnD"}
1
+ {"version":3,"sources":["../../../src/entity-definition/describe/query-property.ts"],"sourcesContent":["import type { Locale } from '../../i18n/locales.js';\nimport { isLocalizedText, localize } from '../../i18n/localized-text.js';\nimport type { EntityFieldDescriptor } from './describe-entity-columns.js';\n\n/**\n * The property a filter or sort names for a member: its wire key, or for a\n * `localized` member the path to one locale's text — the only way one is\n * queried (`title.en`). A control building a query from a descriptor asks this\n * rather than reading `key`, so it never sends the bare object the server\n * refuses.\n */\nexport function queryPropertyFor(\n descriptor: EntityFieldDescriptor,\n locale: Locale,\n): string {\n return descriptor.type === 'localized'\n ? `${descriptor.key}.${locale}`\n : descriptor.key;\n}\n\n/**\n * The property a filter or sort names for a member, and how one of its values\n * reads, in a given locale — the pair a control that both queries a member and\n * shows it needs. A `localized` member is queried as `title.<locale>` and read\n * in that locale (falling back to the default one); any other member is its\n * wire key and reads as itself.\n */\nexport function localizedQueryProperty(\n descriptor: EntityFieldDescriptor,\n locale: Locale,\n): {\n readonly property: string;\n readonly read: (value: unknown) => string | undefined;\n} {\n return {\n property: queryPropertyFor(descriptor, locale),\n read: value => {\n if (value == null) return undefined;\n if (descriptor.type === 'localized') {\n return isLocalizedText(value) ? localize(value, locale) : undefined;\n }\n return String(value);\n },\n };\n}\n\n/**\n * The member an applied filter or sort names — by its accessor name, its wire\n * key, or a locale path into a `localized` one — so a control can show what is\n * in effect.\n */\nexport function findQueriedDescriptor(\n descriptors: readonly EntityFieldDescriptor[],\n property: string,\n): EntityFieldDescriptor | undefined {\n return descriptors.find(\n descriptor =>\n descriptor.key === property ||\n descriptor.name === property ||\n (descriptor.type === 'localized' &&\n (property.startsWith(`${descriptor.key}.`) ||\n property.startsWith(`${descriptor.name}.`))),\n );\n}\n"],"names":["isLocalizedText","localize","queryPropertyFor","descriptor","locale","type","key","localizedQueryProperty","property","read","value","undefined","String","findQueriedDescriptor","descriptors","find","name","startsWith"],"mappings":"AACA,SAASA,eAAe,EAAEC,QAAQ,QAAQ,+BAA+B;AAGzE;;;;;;CAMC,GACD,OAAO,SAASC,iBACdC,UAAiC,EACjCC,MAAc;IAEd,OAAOD,WAAWE,IAAI,KAAK,cACvB,GAAGF,WAAWG,GAAG,CAAC,CAAC,EAAEF,QAAQ,GAC7BD,WAAWG,GAAG;AACpB;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,uBACdJ,UAAiC,EACjCC,MAAc;IAKd,OAAO;QACLI,UAAUN,iBAAiBC,YAAYC;QACvCK,MAAMC,CAAAA;YACJ,IAAIA,SAAS,MAAM,OAAOC;YAC1B,IAAIR,WAAWE,IAAI,KAAK,aAAa;gBACnC,OAAOL,gBAAgBU,SAAST,SAASS,OAAON,UAAUO;YAC5D;YACA,OAAOC,OAAOF;QAChB;IACF;AACF;AAEA;;;;CAIC,GACD,OAAO,SAASG,sBACdC,WAA6C,EAC7CN,QAAgB;IAEhB,OAAOM,YAAYC,IAAI,CACrBZ,CAAAA,aACEA,WAAWG,GAAG,KAAKE,YACnBL,WAAWa,IAAI,KAAKR,YACnBL,WAAWE,IAAI,KAAK,eAClBG,CAAAA,SAASS,UAAU,CAAC,GAAGd,WAAWG,GAAG,CAAC,CAAC,CAAC,KACvCE,SAASS,UAAU,CAAC,GAAGd,WAAWa,IAAI,CAAC,CAAC,CAAC,CAAA;AAEnD"}
@@ -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,QAA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,GAAGvC;AACxD;AAEA;;;;;CAKC,GACD,OAAO,SAASwC,mBACdb,iBAA6C;IAE7C,MAAM,EAAEc,MAAM,EAAEC,GAAG,EAAET,IAAI,EAAE,GAAGrC,kBAAkB+B;IAChD,IAAIc,WAAWlC,aAAamC,QAAQnC,WAAW;QAC7C,MAAM,IAAIoC,MACR,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,EAEnB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,iBAAiB;QACzB,QAAQ,CAAC,QAAQ,EAAE,OAAO,MAAM,CAAC;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B,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"],"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,EAEnB,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,QAiDzB;AA8CD;;;;;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;;;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"}
@@ -134,6 +134,13 @@ export function extractMetaEntity(target) {
134
134
  }
135
135
  return metaEntity;
136
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
+ }
137
144
  /**
138
145
  * Every accessor declared on a class.
139
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 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 * 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","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;AAqBtD,OAAO,MAAMC,kBAAkBJ,OAAO,cAAc;AACpD,OAAO,MAAMK,oBAAoBL,OAAO,gBAAgB;AACxD,OAAO,MAAMM,kBAAkBN,OAAO,cAAc;AACpD,OAAO,MAAMO,oBAAoBP,OAAO,eAAe;AACvD,OAAO,MAAMQ,4BAA4BR,OAAO,sBAAsB;AAEtE,SAASS,gBACPR,QAA6C;IAE7C,IAAI,CAACA,UAAU;QACb,MAAM,IAAIS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EtE"}
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,SAASC,WAAW,QAAQ,0BAA0B;AAqBtD,OAAO,MAAMC,kBAAkBJ,OAAO,cAAc;AACpD,OAAO,MAAMK,oBAAoBL,OAAO,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C,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"}
@@ -66,6 +66,15 @@ export interface MetaAccessorOptions {
66
66
  * shared with another member can point both at one vocabulary.
67
67
  */
68
68
  enumLabelKey?: string;
69
+ /**
70
+ * The tone each value reads in where it is shown as a status: `success`,
71
+ * `warning`, `danger`, `info` or `neutral`. Legal only on an `enum` member,
72
+ * and every key must be one of its {@link enumValues}; a value left out reads
73
+ * `neutral`. Declared, a screen shows the value as a tag in that tone beside
74
+ * its words; undeclared, the value stays plain text — not every enum is a
75
+ * status. Presentation only.
76
+ */
77
+ enumTones?: Readonly<Record<string, EnumTone>>;
69
78
  /** Property of a `link` target used as its display label. Default `name`. */
70
79
  linkLabelProperty?: string;
71
80
  /**
@@ -143,6 +152,20 @@ export interface MetaAccessorOptions {
143
152
  * nothing needs. Absent means a root.
144
153
  */
145
154
  parent?: boolean;
155
+ /**
156
+ * This `id` or `string` member holds the id of a record of another entity,
157
+ * named by the `domain:key` pair that entity's `@entity({ domain, key })`
158
+ * declares — so the declaring package imports nothing of the target's. A
159
+ * screen reads the target's name in its place through the host's
160
+ * `ReferenceLabelsTag` registry, rather than showing the key.
161
+ *
162
+ * Not a `link` on purpose: the target may live in another store, and a
163
+ * `link` invites the storage-layer join that would couple the two, while its
164
+ * accessor would import the target's class across a domain boundary.
165
+ * Presentation and resolution only — to validation, queries, serialization
166
+ * and every adapter the member is still its id.
167
+ */
168
+ references?: MemberReference;
146
169
  /**
147
170
  * This `number` member is an amount of money, and how to read it: its
148
171
  * currency, fixed or held by another member of the same record, and whether
@@ -175,6 +198,16 @@ export interface MetaAccessorOptions {
175
198
  */
176
199
  autocomplete?: string;
177
200
  }
201
+ /**
202
+ * The tone an enum value reads in as a status. Words always go beside it — a
203
+ * tone never carries a meaning alone.
204
+ */
205
+ export declare const EnumTones: readonly ["success", "warning", "danger", "info", "neutral"];
206
+ export type EnumTone = (typeof EnumTones)[number];
207
+ /** The entity a reference member points at, as `domain:key`. */
208
+ export interface MemberReference {
209
+ readonly entity: string;
210
+ }
178
211
  /** The part a member plays on a record's card. */
179
212
  export type CardRole = 'title' | 'subtitle' | 'badge' | 'meta' | 'hidden';
180
213
  /**
@@ -206,6 +239,7 @@ export declare class MetaAccessor {
206
239
  readonly order?: number;
207
240
  readonly enumValues?: readonly string[];
208
241
  readonly enumLabelKey?: string;
242
+ readonly enumTones?: Readonly<Record<string, EnumTone>>;
209
243
  readonly linkLabelProperty?: string;
210
244
  readonly linkSearchProperty?: string;
211
245
  readonly linkSerialization?: EntityLinkSerialization;
@@ -215,6 +249,7 @@ export declare class MetaAccessor {
215
249
  readonly maxItems?: number;
216
250
  readonly notBefore?: string;
217
251
  readonly parent?: boolean;
252
+ readonly references?: MemberReference;
218
253
  readonly money?: MoneyFormat;
219
254
  readonly minWidth?: number;
220
255
  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,K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,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;CAuChC"}
@@ -27,6 +27,16 @@
27
27
  'id',
28
28
  'embedded'
29
29
  ];
30
+ /**
31
+ * The tone an enum value reads in as a status. Words always go beside it — a
32
+ * tone never carries a meaning alone.
33
+ */ export const EnumTones = [
34
+ 'success',
35
+ 'warning',
36
+ 'danger',
37
+ 'info',
38
+ 'neutral'
39
+ ];
30
40
  export class MetaAccessor {
31
41
  //#endregion
32
42
  //#region Constructors
@@ -45,6 +55,7 @@ export class MetaAccessor {
45
55
  this.order = options == null ? void 0 : options.order;
46
56
  this.enumValues = options == null ? void 0 : options.enumValues;
47
57
  this.enumLabelKey = options == null ? void 0 : options.enumLabelKey;
58
+ this.enumTones = options == null ? void 0 : options.enumTones;
48
59
  this.linkLabelProperty = options == null ? void 0 : options.linkLabelProperty;
49
60
  this.linkSearchProperty = options == null ? void 0 : options.linkSearchProperty;
50
61
  this.linkSerialization = options == null ? void 0 : options.linkSerialization;
@@ -54,6 +65,7 @@ export class MetaAccessor {
54
65
  this.maxItems = options == null ? void 0 : options.maxItems;
55
66
  this.notBefore = options == null ? void 0 : options.notBefore;
56
67
  this.parent = options == null ? void 0 : options.parent;
68
+ this.references = options == null ? void 0 : options.references;
57
69
  this.money = options == null ? void 0 : options.money;
58
70
  this.minWidth = options == null ? void 0 : options.minWidth;
59
71
  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,CAAC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AAI;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 /**\n * The tone each value reads in where it is shown as a status: `success`,\n * `warning`, `danger`, `info` or `neutral`. Legal only on an `enum` member,\n * and every key must be one of its {@link enumValues}; a value left out reads\n * `neutral`. Declared, a screen shows the value as a tag in that tone beside\n * its words; undeclared, the value stays plain text — not every enum is a\n * status. Presentation only.\n */\n enumTones?: Readonly<Record<string, EnumTone>>;\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/**\n * The tone an enum value reads in as a status. Words always go beside it — a\n * tone never carries a meaning alone.\n */\nexport const EnumTones = [\n 'success',\n 'warning',\n 'danger',\n 'info',\n 'neutral',\n] as const;\nexport type EnumTone = (typeof EnumTones)[number];\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 enumTones?: Readonly<Record<string, EnumTone>>;\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.enumTones = options?.enumTones;\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","EnumTones","MetaAccessor","name","kind","options","alias","type","readonly","hidden","required","label","labelKey","sortable","filterable","order","enumValues","enumLabelKey","enumTones","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;AAwKpE;;;CAGC,GACD,OAAO,MAAMC,YAAY;IACvB;IACA;IACA;IACA;IACA;CACD,CAAU;AAqBX,OAAO,MAAMC;IAiCX,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,SAAS,GAAGb,2BAAAA,QAASa,SAAS;QACnC,IAAI,CAACC,iBAAiB,GAAGd,2BAAAA,QAASc,iBAAiB;QACnD,IAAI,CAACC,kBAAkB,GAAGf,2BAAAA,QAASe,kBAAkB;QACrD,IAAI,CAACC,iBAAiB,GAAGhB,2BAAAA,QAASgB,iBAAiB;QACnD,IAAI,CAACC,SAAS,GAAGjB,2BAAAA,QAASiB,SAAS;QACnC,IAAI,CAACC,YAAY,GAAGlB,2BAAAA,QAASkB,YAAY;QACzC,IAAI,CAACC,QAAQ,GAAGnB,2BAAAA,QAASmB,QAAQ;QACjC,IAAI,CAACC,QAAQ,GAAGpB,2BAAAA,QAASoB,QAAQ;QACjC,IAAI,CAACC,SAAS,GAAGrB,2BAAAA,QAASqB,SAAS;QACnC,IAAI,CAACC,MAAM,GAAGtB,2BAAAA,QAASsB,MAAM;QAC7B,IAAI,CAACC,UAAU,GAAGvB,2BAAAA,QAASuB,UAAU;QACrC,IAAI,CAACC,KAAK,GAAGxB,2BAAAA,QAASwB,KAAK;QAC3B,IAAI,CAACC,QAAQ,GAAGzB,2BAAAA,QAASyB,QAAQ;QACjC,IAAI,CAACC,IAAI,GAAG1B,2BAAAA,QAAS0B,IAAI;QACzB,IAAI,CAACC,YAAY,GAAG3B,2BAAAA,QAAS2B,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;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,C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,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entifix/core",
3
- "version": "0.20.3",
3
+ "version": "0.22.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": {