@entifix/core 0.20.1 → 0.20.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The entity system. A class decorated with `@entity()` and `@accessor()` describes itself — its members, their types and labels, which of them are sortable or filterable — and everything else in entifix reads that description instead of being told it again.
4
4
 
5
- Presentation lives on the class too: `@entity({ creatable })`, and `@accessor({ minWidth, card, autocomplete })` for how a member reads in a table, on a card and to a browser's autofill. A `@useCase()` declares its place in the action hierarchy (`emphasis`, `priority`, `rowInline`, `shortcut`) and, when destructive, how it is undone (`reversible`, `inverse`); a bad shortcut (`parseChord`) or an unsafe destructive verb fails at load.
5
+ Presentation lives on the class too: `@entity({ creatable })`, and `@accessor({ minWidth, card, autocomplete })` for how a member reads in a table, on a card and to a browser's autofill. A `@useCase()` declares its place in the action hierarchy (`emphasis`, `priority`, `rowInline`, `shortcut`), the record states it is offered in (`availableWhen`) and, when destructive, how it is undone (`reversible`, `inverse`); a bad shortcut (`parseChord`) or an unsafe destructive verb fails at load.
6
6
 
7
7
  It also owns what crosses the wire: entity serialization and reconstruction, the envelopes a service answers with, and the RSQL filter and sort protocol a query is written in. Nothing here performs I/O.
8
8
 
@@ -1,5 +1,5 @@
1
1
  import { Entity, EntityConstructor } from '../../types/Entity.js';
2
- import type { UseCaseBinding, UseCaseCell, UseCaseConfirm, UseCaseHierarchy, UseCasePlacement, UseCaseReversible } from '../meta-entities/meta-use-case/index.js';
2
+ import type { UseCaseAvailability, UseCaseBinding, UseCaseCell, UseCaseConfirm, UseCaseHierarchy, UseCasePlacement, UseCaseReversible } from '../meta-entities/meta-use-case/index.js';
3
3
  /**
4
4
  * An action a caller may take on an entity, resolved from its use-case
5
5
  * metadata. The counterpart to {@link EntityFieldDescriptor}, and like it,
@@ -22,6 +22,8 @@ export interface UseCaseDescriptor extends UseCaseHierarchy {
22
22
  reversible?: UseCaseReversible;
23
23
  /** The verb Undo runs, by key. */
24
24
  inverse?: string;
25
+ /** The states a record must be in for the verb to be offered on it. */
26
+ availableWhen?: UseCaseAvailability;
25
27
  form?: string;
26
28
  /** The named variant set this verb resolves between. */
27
29
  variants?: string;
@@ -54,4 +56,14 @@ export interface UseCaseComposition {
54
56
  * use-case implementation reaches a client bundle.
55
57
  */
56
58
  export declare function describeEntityUseCases<TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>): UseCaseDescriptor[];
59
+ /**
60
+ * Whether a surface offers `descriptor` on `record`: always, for a verb that
61
+ * declares no {@link UseCaseAvailability}; otherwise only once the record has
62
+ * arrived and its member holds one of the declared states. A record still in
63
+ * flight offers none of its state-bound verbs, rather than all of them for a
64
+ * moment.
65
+ *
66
+ * Presentation only — the verb's handler is what refuses an illegal move.
67
+ */
68
+ export declare function isUseCaseAvailable(descriptor: Pick<UseCaseDescriptor, 'availableWhen'>, record: object | undefined): boolean;
57
69
  //# sourceMappingURL=describe-entity-use-cases.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"describe-entity-use-cases.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/describe/describe-entity-use-cases.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAElE,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,yCAAyC,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAkB,SAAQ,gBAAgB;IACzD,sEAAsE;IACtE,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,cAAc,CAAC;IACxB,SAAS,EAAE,gBAAgB,CAAC;IAC5B,0EAA0E;IAC1E,MAAM,CAAC,EAAE,SAAS,WAAW,EAAE,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,qEAAqE;IACrE,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED,wEAAwE;AACxE,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0DAA0D;IAC1D,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC/B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,MAAM,EAC3D,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAC5C,iBAAiB,EAAE,CAmBrB"}
1
+ {"version":3,"file":"describe-entity-use-cases.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/describe/describe-entity-use-cases.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAElE,OAAO,KAAK,EACV,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,yCAAyC,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAkB,SAAQ,gBAAgB;IACzD,sEAAsE;IACtE,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,cAAc,CAAC;IACxB,SAAS,EAAE,gBAAgB,CAAC;IAC5B,0EAA0E;IAC1E,MAAM,CAAC,EAAE,SAAS,WAAW,EAAE,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,qEAAqE;IACrE,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,aAAa,CAAC,EAAE,mBAAmB,CAAC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED,wEAAwE;AACxE,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0DAA0D;IAC1D,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC/B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,MAAM,EAC3D,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAC5C,iBAAiB,EAAE,CAoBrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,IAAI,CAAC,iBAAiB,EAAE,eAAe,CAAC,EACpD,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,OAAO,CAQT"}
@@ -20,6 +20,7 @@ import { extractMetaUseCases } from '../helpers/index.js';
20
20
  confirm: metaUseCase.confirm,
21
21
  reversible: metaUseCase.reversible,
22
22
  inverse: metaUseCase.inverse,
23
+ availableWhen: metaUseCase.availableWhen,
23
24
  emphasis: metaUseCase.emphasis,
24
25
  priority: metaUseCase.priority,
25
26
  rowInline: metaUseCase.rowInline,
@@ -29,5 +30,20 @@ import { extractMetaUseCases } from '../helpers/index.js';
29
30
  recipe: metaUseCase.recipe
30
31
  }));
31
32
  }
33
+ /**
34
+ * Whether a surface offers `descriptor` on `record`: always, for a verb that
35
+ * declares no {@link UseCaseAvailability}; otherwise only once the record has
36
+ * arrived and its member holds one of the declared states. A record still in
37
+ * flight offers none of its state-bound verbs, rather than all of them for a
38
+ * moment.
39
+ *
40
+ * Presentation only — the verb's handler is what refuses an illegal move.
41
+ */ export function isUseCaseAvailable(descriptor, record) {
42
+ const availability = descriptor.availableWhen;
43
+ if (availability === undefined) return true;
44
+ if (record === undefined) return false;
45
+ const state = record[availability.member];
46
+ return typeof state === 'string' && availability.in.includes(state);
47
+ }
32
48
 
33
49
  //# sourceMappingURL=describe-entity-use-cases.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/entity-definition/describe/describe-entity-use-cases.ts"],"sourcesContent":["import { Entity, EntityConstructor } from '../../types/Entity.js';\nimport { extractMetaUseCases } from '../helpers/index.js';\nimport type {\n UseCaseBinding,\n UseCaseCell,\n UseCaseConfirm,\n UseCaseHierarchy,\n UseCasePlacement,\n UseCaseReversible,\n} from '../meta-entities/meta-use-case/index.js';\n\n/**\n * An action a caller may take on an entity, resolved from its use-case\n * metadata. The counterpart to {@link EntityFieldDescriptor}, and like it,\n * framework-free and copy-free — every human-readable member is a catalog key.\n *\n * It carries no `entity`: this is the shape that goes over the wire from\n * `GET /api/<entity>/$metadata`, where the entity is already the address.\n */\nexport interface UseCaseDescriptor extends UseCaseHierarchy {\n /** The verb. Also the third segment of the permission guarding it. */\n key: string;\n binding: UseCaseBinding;\n placement: UseCasePlacement;\n /** Further cells this same verb appears in — see `MetaUseCaseOptions`. */\n alsoAt?: readonly UseCaseCell[];\n labelKey: string;\n keywordsKey?: string;\n confirm?: UseCaseConfirm;\n /** How a destructive verb is made safe — see `UseCaseReversible`. */\n reversible?: UseCaseReversible;\n /** The verb Undo runs, by key. */\n inverse?: string;\n form?: string;\n /** The named variant set this verb resolves between. */\n variants?: string;\n /** The named recipe this verb starts a flow from. */\n recipe?: string;\n /**\n * What this verb resolves to **for the caller asking** — present only on a\n * served `$metadata` document, computed per principal.\n */\n composition?: UseCaseComposition;\n}\n\n/** Which variant, and which flow, a verb resolves to for one caller. */\nexport interface UseCaseComposition {\n useCase: string;\n variant: string;\n recipe?: string;\n slipVersion?: number;\n /** The `id@n` references the recipe can pin, in order. */\n fragments?: readonly string[];\n}\n\n/**\n * Resolves the use cases declared against an entity, in declaration order.\n *\n * Unlike {@link describeEntityColumns}, this is only trustworthy where the\n * use-case modules have been loaded: a `@useCase()` class registers itself when\n * its module evaluates. On a service that is the composition root's job, and\n * a host's register should fail the build on a class its package barrel does\n * not export.\n * A browser never calls this — it fetches the descriptors instead, so no\n * use-case implementation reaches a client bundle.\n */\nexport function describeEntityUseCases<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n): UseCaseDescriptor[] {\n return extractMetaUseCases(entityConstructor).map(metaUseCase => ({\n key: metaUseCase.key,\n binding: metaUseCase.binding,\n placement: metaUseCase.placement,\n alsoAt: metaUseCase.alsoAt,\n labelKey: metaUseCase.labelKey,\n keywordsKey: metaUseCase.keywordsKey,\n confirm: metaUseCase.confirm,\n reversible: metaUseCase.reversible,\n inverse: metaUseCase.inverse,\n emphasis: metaUseCase.emphasis,\n priority: metaUseCase.priority,\n rowInline: metaUseCase.rowInline,\n shortcut: metaUseCase.shortcut,\n form: metaUseCase.form,\n variants: metaUseCase.variants,\n recipe: metaUseCase.recipe,\n }));\n}\n"],"names":["extractMetaUseCases","describeEntityUseCases","entityConstructor","map","metaUseCase","key","binding","placement","alsoAt","labelKey","keywordsKey","confirm","reversible","inverse","emphasis","priority","rowInline","shortcut","form","variants","recipe"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,sBAAsB;AAsD1D;;;;;;;;;;CAUC,GACD,OAAO,SAASC,uBACdC,iBAA6C;IAE7C,OAAOF,oBAAoBE,mBAAmBC,GAAG,CAACC,CAAAA,cAAgB,CAAA;YAChEC,KAAKD,YAAYC,GAAG;YACpBC,SAASF,YAAYE,OAAO;YAC5BC,WAAWH,YAAYG,SAAS;YAChCC,QAAQJ,YAAYI,MAAM;YAC1BC,UAAUL,YAAYK,QAAQ;YAC9BC,aAAaN,YAAYM,WAAW;YACpCC,SAASP,YAAYO,OAAO;YAC5BC,YAAYR,YAAYQ,UAAU;YAClCC,SAAST,YAAYS,OAAO;YAC5BC,UAAUV,YAAYU,QAAQ;YAC9BC,UAAUX,YAAYW,QAAQ;YAC9BC,WAAWZ,YAAYY,SAAS;YAChCC,UAAUb,YAAYa,QAAQ;YAC9BC,MAAMd,YAAYc,IAAI;YACtBC,UAAUf,YAAYe,QAAQ;YAC9BC,QAAQhB,YAAYgB,MAAM;QAC5B,CAAA;AACF"}
1
+ {"version":3,"sources":["../../../src/entity-definition/describe/describe-entity-use-cases.ts"],"sourcesContent":["import { Entity, EntityConstructor } from '../../types/Entity.js';\nimport { extractMetaUseCases } from '../helpers/index.js';\nimport type {\n UseCaseAvailability,\n UseCaseBinding,\n UseCaseCell,\n UseCaseConfirm,\n UseCaseHierarchy,\n UseCasePlacement,\n UseCaseReversible,\n} from '../meta-entities/meta-use-case/index.js';\n\n/**\n * An action a caller may take on an entity, resolved from its use-case\n * metadata. The counterpart to {@link EntityFieldDescriptor}, and like it,\n * framework-free and copy-free — every human-readable member is a catalog key.\n *\n * It carries no `entity`: this is the shape that goes over the wire from\n * `GET /api/<entity>/$metadata`, where the entity is already the address.\n */\nexport interface UseCaseDescriptor extends UseCaseHierarchy {\n /** The verb. Also the third segment of the permission guarding it. */\n key: string;\n binding: UseCaseBinding;\n placement: UseCasePlacement;\n /** Further cells this same verb appears in — see `MetaUseCaseOptions`. */\n alsoAt?: readonly UseCaseCell[];\n labelKey: string;\n keywordsKey?: string;\n confirm?: UseCaseConfirm;\n /** How a destructive verb is made safe — see `UseCaseReversible`. */\n reversible?: UseCaseReversible;\n /** The verb Undo runs, by key. */\n inverse?: string;\n /** The states a record must be in for the verb to be offered on it. */\n availableWhen?: UseCaseAvailability;\n form?: string;\n /** The named variant set this verb resolves between. */\n variants?: string;\n /** The named recipe this verb starts a flow from. */\n recipe?: string;\n /**\n * What this verb resolves to **for the caller asking** — present only on a\n * served `$metadata` document, computed per principal.\n */\n composition?: UseCaseComposition;\n}\n\n/** Which variant, and which flow, a verb resolves to for one caller. */\nexport interface UseCaseComposition {\n useCase: string;\n variant: string;\n recipe?: string;\n slipVersion?: number;\n /** The `id@n` references the recipe can pin, in order. */\n fragments?: readonly string[];\n}\n\n/**\n * Resolves the use cases declared against an entity, in declaration order.\n *\n * Unlike {@link describeEntityColumns}, this is only trustworthy where the\n * use-case modules have been loaded: a `@useCase()` class registers itself when\n * its module evaluates. On a service that is the composition root's job, and\n * a host's register should fail the build on a class its package barrel does\n * not export.\n * A browser never calls this — it fetches the descriptors instead, so no\n * use-case implementation reaches a client bundle.\n */\nexport function describeEntityUseCases<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n): UseCaseDescriptor[] {\n return extractMetaUseCases(entityConstructor).map(metaUseCase => ({\n key: metaUseCase.key,\n binding: metaUseCase.binding,\n placement: metaUseCase.placement,\n alsoAt: metaUseCase.alsoAt,\n labelKey: metaUseCase.labelKey,\n keywordsKey: metaUseCase.keywordsKey,\n confirm: metaUseCase.confirm,\n reversible: metaUseCase.reversible,\n inverse: metaUseCase.inverse,\n availableWhen: metaUseCase.availableWhen,\n emphasis: metaUseCase.emphasis,\n priority: metaUseCase.priority,\n rowInline: metaUseCase.rowInline,\n shortcut: metaUseCase.shortcut,\n form: metaUseCase.form,\n variants: metaUseCase.variants,\n recipe: metaUseCase.recipe,\n }));\n}\n\n/**\n * Whether a surface offers `descriptor` on `record`: always, for a verb that\n * declares no {@link UseCaseAvailability}; otherwise only once the record has\n * arrived and its member holds one of the declared states. A record still in\n * flight offers none of its state-bound verbs, rather than all of them for a\n * moment.\n *\n * Presentation only — the verb's handler is what refuses an illegal move.\n */\nexport function isUseCaseAvailable(\n descriptor: Pick<UseCaseDescriptor, 'availableWhen'>,\n record: object | undefined,\n): boolean {\n const availability = descriptor.availableWhen;\n if (availability === undefined) return true;\n if (record === undefined) return false;\n const state = (record as Readonly<Record<string, unknown>>)[\n availability.member\n ];\n return typeof state === 'string' && availability.in.includes(state);\n}\n"],"names":["extractMetaUseCases","describeEntityUseCases","entityConstructor","map","metaUseCase","key","binding","placement","alsoAt","labelKey","keywordsKey","confirm","reversible","inverse","availableWhen","emphasis","priority","rowInline","shortcut","form","variants","recipe","isUseCaseAvailable","descriptor","record","availability","undefined","state","member","in","includes"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,sBAAsB;AAyD1D;;;;;;;;;;CAUC,GACD,OAAO,SAASC,uBACdC,iBAA6C;IAE7C,OAAOF,oBAAoBE,mBAAmBC,GAAG,CAACC,CAAAA,cAAgB,CAAA;YAChEC,KAAKD,YAAYC,GAAG;YACpBC,SAASF,YAAYE,OAAO;YAC5BC,WAAWH,YAAYG,SAAS;YAChCC,QAAQJ,YAAYI,MAAM;YAC1BC,UAAUL,YAAYK,QAAQ;YAC9BC,aAAaN,YAAYM,WAAW;YACpCC,SAASP,YAAYO,OAAO;YAC5BC,YAAYR,YAAYQ,UAAU;YAClCC,SAAST,YAAYS,OAAO;YAC5BC,eAAeV,YAAYU,aAAa;YACxCC,UAAUX,YAAYW,QAAQ;YAC9BC,UAAUZ,YAAYY,QAAQ;YAC9BC,WAAWb,YAAYa,SAAS;YAChCC,UAAUd,YAAYc,QAAQ;YAC9BC,MAAMf,YAAYe,IAAI;YACtBC,UAAUhB,YAAYgB,QAAQ;YAC9BC,QAAQjB,YAAYiB,MAAM;QAC5B,CAAA;AACF;AAEA;;;;;;;;CAQC,GACD,OAAO,SAASC,mBACdC,UAAoD,EACpDC,MAA0B;IAE1B,MAAMC,eAAeF,WAAWT,aAAa;IAC7C,IAAIW,iBAAiBC,WAAW,OAAO;IACvC,IAAIF,WAAWE,WAAW,OAAO;IACjC,MAAMC,QAAQ,AAACH,MAA4C,CACzDC,aAAaG,MAAM,CACpB;IACD,OAAO,OAAOD,UAAU,YAAYF,aAAaI,EAAE,CAACC,QAAQ,CAACH;AAC/D"}
@@ -1 +1 @@
1
- {"version":3,"file":"entity-definition-helpers.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/helpers/entity-definition-helpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EACL,KAAK,gBAAgB,EACrB,YAAY,EACb,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EACL,WAAW,EACX,kBAAkB,EACnB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,iBAAiB;QACzB,QAAQ,CAAC,QAAQ,EAAE,OAAO,MAAM,CAAC;KAClC;CACF;AAED,eAAO,MAAM,eAAe,eAAuB,CAAC;AACpD,eAAO,MAAM,iBAAiB,eAAyB,CAAC;AACxD,eAAO,MAAM,eAAe,eAAuB,CAAC;AACpD,eAAO,MAAM,iBAAiB,eAAwB,CAAC;AACvD,eAAO,MAAM,yBAAyB,eAA+B,CAAC;AAatE,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,uBAAuB,GAAG,SAAS,EAC7C,UAAU,EAAE,UAAU,QAGvB;AAED,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,uBAAuB,GAAG,SAAS,EAC7C,YAAY,EAAE,YAAY,QAM3B;AAED,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,uBAAuB,GAAG,SAAS,EAC7C,UAAU,EAAE,UAAU,QAKvB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,MAAM,EACtD,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAClC,WAAW,EAAE,WAAW,QA8CzB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,uBAAuB,GAAG,SAAS,EAC7C,OAAO,EAAE,kBAAkB,QAG5B;AAQD,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,MAAM,EACtD,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACjC,UAAU,CAOZ;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,GAAG,YAAY,EAAE,CAG7E;AAED,wBAAgB,kBAAkB,CAAC,OAAO,SAAS,MAAM,EACvD,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACjC,UAAU,EAAE,CAGd;AAED,8EAA8E;AAC9E,wBAAgB,mBAAmB,CAAC,OAAO,SAAS,MAAM,EACxD,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACjC,WAAW,EAAE,CAGf;AAED,2DAA2D;AAC3D,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,kBAAkB,GACzB,kBAAkB,CAYpB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,kBAAkB,GAAG,WAAW,CAQtE"}
1
+ {"version":3,"file":"entity-definition-helpers.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/helpers/entity-definition-helpers.ts"],"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,uCA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AAE,CAGd;AAED,8EAA8E;AAC9E,wBAAgB,mBAAmB,CAAC,OAAO,SAAS,MAAM,EACxD,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACjC,WAAW,EAAE,CAGf;AAED,2DAA2D;AAC3D,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,kBAAkB,GACzB,kBAAkB,CAYpB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,kBAAkB,GAAG,WAAW,CAQtE"}
@@ -61,6 +61,9 @@ export function appendMetaMethod(metadata, metaMethod) {
61
61
  if (metaUseCase.reversible === 'undo' && metaUseCase.inverse === undefined) {
62
62
  throw new Error(`Use case "${metaUseCase.key}" on ${target.name} is reversible by undo and names no \`inverse\`: Undo has nothing to run.`);
63
63
  }
64
+ if (metaUseCase.availableWhen !== undefined) {
65
+ assertAvailability(target, metaUseCase, metaUseCase.availableWhen);
66
+ }
64
67
  // A shortcut is checked where it is declared, so a chord no reader can use
65
68
  // — a bare key, Option+letter, Mod+C — fails at load rather than on a page.
66
69
  if (metaUseCase.shortcut !== undefined) {
@@ -84,6 +87,33 @@ export function appendMetaMethod(metadata, metaMethod) {
84
87
  metaUseCase
85
88
  ];
86
89
  }
90
+ /**
91
+ * A verb's states are checked where they are declared, against the entity's
92
+ * own member: a misspelt member or state would otherwise hide the verb on every
93
+ * record, which reads as a missing grant rather than a typo.
94
+ */ function assertAvailability(target, { key, binding, alsoAt }, availableWhen) {
95
+ const where = `Use case "${key}" on ${target.name}`;
96
+ // A selection carries no states, so the collection surfaces offer every
97
+ // verb; a verb with no record-bound cell would declare states nothing reads.
98
+ const recordBound = binding === 'entity' || (alsoAt != null ? alsoAt : []).some((cell)=>cell.binding === 'entity');
99
+ if (!recordBound) {
100
+ throw new Error(`${where} declares \`availableWhen\` and sits on no record: a selection carries no states, so nothing would read them.`);
101
+ }
102
+ const member = extractMetaAccessors(target).find((accessor)=>accessor.name === availableWhen.member);
103
+ if ((member == null ? void 0 : member.enumValues) === undefined) {
104
+ throw new Error(`${where} is available when "${availableWhen.member}" holds a state, and ${target.name} has no enum member by that name.`);
105
+ }
106
+ if (availableWhen.in.length === 0) {
107
+ throw new Error(`${where} is available in no state of "${availableWhen.member}": a verb that is never offered is a verb to delete.`);
108
+ }
109
+ const unknown = availableWhen.in.filter((state)=>{
110
+ var _member_enumValues;
111
+ return !((_member_enumValues = member.enumValues) == null ? void 0 : _member_enumValues.includes(state));
112
+ });
113
+ if (unknown.length > 0) {
114
+ throw new Error(`${where} names ${unknown.map((state)=>`"${state}"`).join(', ')}, which "${availableWhen.member}" does not hold.`);
115
+ }
116
+ }
87
117
  /**
88
118
  * Record on the use-case class itself which entity and verb it implements, so
89
119
  * the permission can be derived from the class alone. That is what keeps the
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/entity-definition/helpers/entity-definition-helpers.ts"],"sourcesContent":["(Symbol as { metadata?: symbol }).metadata ??= Symbol.for('Symbol.metadata');\n\nimport { assertChord } from '../../shortcut/chord.js';\nimport { Entity, EntityConstructor } from '../../types/Entity.js';\nimport { UseCaseConstructor } from '../../types/UseCase.js';\nimport {\n type ChildConstructor,\n MetaAccessor,\n} from '../meta-entities/meta-accessor/index.js';\nimport { MetaEntity } from '../meta-entities/meta-entity/index.js';\nimport { MetaMethod } from '../meta-entities/meta-method/index.js';\nimport {\n MetaUseCase,\n MetaUseCaseBinding,\n} from '../meta-entities/meta-use-case/index.js';\n\ndeclare global {\n interface SymbolConstructor {\n readonly metadata: unique symbol;\n }\n}\n\nexport const META_ENTITY_KEY = Symbol('MetaEntity');\nexport const META_ACCESSOR_KEY = Symbol('MetaAccessor');\nexport const META_METHOD_KEY = Symbol('MetaMethod');\nexport const META_USE_CASE_KEY = Symbol('MetaUseCase');\nexport const META_USE_CASE_BINDING_KEY = Symbol('MetaUseCaseBinding');\n\nfunction requireMetadata(\n metadata: DecoratorMetadataObject | undefined,\n): DecoratorMetadataObject {\n if (!metadata) {\n throw new Error(\n 'Decorator metadata unavailable — Symbol.metadata polyfill missing or stage-3 decorator emit not enabled.',\n );\n }\n return metadata;\n}\n\nexport function setMetaEntity(\n metadata: DecoratorMetadataObject | undefined,\n metaEntity: MetaEntity,\n) {\n requireMetadata(metadata)[META_ENTITY_KEY] = metaEntity;\n}\n\nexport function appendMetaAccessor(\n metadata: DecoratorMetadataObject | undefined,\n metaAccessor: MetaAccessor,\n) {\n const meta = requireMetadata(metadata);\n const existing =\n (meta[META_ACCESSOR_KEY] as MetaAccessor[] | undefined) ?? [];\n meta[META_ACCESSOR_KEY] = [...existing, metaAccessor];\n}\n\nexport function appendMetaMethod(\n metadata: DecoratorMetadataObject | undefined,\n metaMethod: MetaMethod,\n) {\n const meta = requireMetadata(metadata);\n const existing = (meta[META_METHOD_KEY] as MetaMethod[] | undefined) ?? [];\n meta[META_METHOD_KEY] = [...existing, metaMethod];\n}\n\n/**\n * Append a use case to the metadata of the entity it acts on.\n *\n * This is the one decorator that writes a bag other than its own: a use case is\n * declared on its own class, but the entity is what a surface holds, so the\n * descriptor has to end up there. The consequence is that a use-case module\n * which is never imported leaves the entity looking as if it had no actions,\n * which is why a host's register should assert every `@useCase()` class is\n * re-exported from its package barrel.\n *\n * It reads the target's **own** metadata rather than going through\n * {@link readMetadata}. `Symbol.metadata` resolves along the prototype chain, so\n * an inherited read would append the verb to a base class's bag and leak it to\n * every subclass. A target with no own metadata is an entity missing\n * `@entity()`, or a circular import that evaluated the use case first.\n */\nexport function appendMetaUseCase<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n metaUseCase: MetaUseCase,\n) {\n const own = Object.getOwnPropertyDescriptor(target, Symbol.metadata)\n ?.value as DecoratorMetadataObject | null | undefined;\n if (!own) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" targets ${target.name}, which has no metadata of its own — it is missing @entity(), or a circular import evaluated the use case first.`,\n );\n }\n if (\n metaUseCase.confirm?.tone === 'destructive' &&\n metaUseCase.reversible === undefined\n ) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" on ${target.name} is destructive and declares no \\`reversible\\`. Say how it is made safe: 'undo' (with an \\`inverse\\`), 'confirm' or 'typed'.`,\n );\n }\n if (metaUseCase.reversible === 'undo' && metaUseCase.inverse === undefined) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" on ${target.name} is reversible by undo and names no \\`inverse\\`: Undo has nothing to run.`,\n );\n }\n // A shortcut is checked where it is declared, so a chord no reader can use\n // — a bare key, Option+letter, Mod+C — fails at load rather than on a page.\n if (metaUseCase.shortcut !== undefined) {\n try {\n assertChord(metaUseCase.shortcut);\n } catch (refused) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" on ${target.name}: ${(refused as Error).message}`,\n { cause: refused },\n );\n }\n }\n const existing = (own[META_USE_CASE_KEY] as MetaUseCase[] | undefined) ?? [];\n // A verb declared on a record and over a selection is one verb under one\n // key, so only a different key makes a second inline verb.\n const inline = existing.find(\n declared => declared.rowInline && declared.key !== metaUseCase.key,\n );\n if (metaUseCase.rowInline && inline) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" on ${target.name} is rowInline, and so is \"${inline.key}\": a row shows at most one verb inline.`,\n );\n }\n own[META_USE_CASE_KEY] = [...existing, metaUseCase];\n}\n\n/**\n * Record on the use-case class itself which entity and verb it implements, so\n * the permission can be derived from the class alone. That is what keeps the\n * verb string written once, at the declaration, instead of being retyped at\n * every guard.\n */\nexport function setMetaUseCaseBinding(\n metadata: DecoratorMetadataObject | undefined,\n binding: MetaUseCaseBinding,\n) {\n requireMetadata(metadata)[META_USE_CASE_BINDING_KEY] = binding;\n}\n\nfunction readMetadata(\n target: ChildConstructor,\n): DecoratorMetadataObject | undefined {\n return target[Symbol.metadata] ?? undefined;\n}\n\nexport function extractMetaEntity<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n): MetaEntity {\n const metadata = readMetadata(target);\n const metaEntity = metadata?.[META_ENTITY_KEY] as MetaEntity | undefined;\n if (!metaEntity) {\n throw new Error(`MetaEntity not found for ${target.name}`);\n }\n return metaEntity;\n}\n\n/**\n * Every accessor declared on a class.\n *\n * The target is a {@link ChildConstructor}, not an `EntityConstructor`: an\n * `@accessor()` writes to its own class's metadata bag with no help from\n * `@entity()`, so a `composition` member's child — a value with no `id` — is\n * described by exactly this walk.\n */\nexport function extractMetaAccessors(target: ChildConstructor): MetaAccessor[] {\n const metadata = readMetadata(target);\n return (metadata?.[META_ACCESSOR_KEY] as MetaAccessor[] | undefined) ?? [];\n}\n\nexport function extractMetaMethods<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n): MetaMethod[] {\n const metadata = readMetadata(target);\n return (metadata?.[META_METHOD_KEY] as MetaMethod[] | undefined) ?? [];\n}\n\n/** Every use case declared against an entity. Empty until one is imported. */\nexport function extractMetaUseCases<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n): MetaUseCase[] {\n const metadata = readMetadata(target);\n return (metadata?.[META_USE_CASE_KEY] as MetaUseCase[] | undefined) ?? [];\n}\n\n/** The entity and verb a `@useCase()` class implements. */\nexport function extractMetaUseCaseBinding(\n target: UseCaseConstructor,\n): MetaUseCaseBinding {\n const metadata = (\n target as { [Symbol.metadata]?: DecoratorMetadataObject | null }\n )[Symbol.metadata];\n const binding = metadata?.[META_USE_CASE_BINDING_KEY] as\n MetaUseCaseBinding | undefined;\n if (!binding) {\n throw new Error(\n `MetaUseCase not found for ${target.name} — is it missing @useCase()?`,\n );\n }\n return binding;\n}\n\n/**\n * The `@useCase()` a class declares, as the entity it is declared against\n * holds it — with its binding and its endpoint contract.\n */\nexport function extractUseCase(target: UseCaseConstructor): MetaUseCase {\n const { entity, key, binding } = extractMetaUseCaseBinding(target);\n // `@useCase()` appends to the entity before it records the binding, so a\n // bound class always has its entry — found by binding as well as key, since\n // one key may be declared on a record and over a selection.\n return extractMetaUseCases(entity).find(\n metaUseCase => metaUseCase.key === key && metaUseCase.binding === binding,\n ) as MetaUseCase;\n}\n"],"names":["Symbol","metadata","for","assertChord","META_ENTITY_KEY","META_ACCESSOR_KEY","META_METHOD_KEY","META_USE_CASE_KEY","META_USE_CASE_BINDING_KEY","requireMetadata","Error","setMetaEntity","metaEntity","appendMetaAccessor","metaAccessor","meta","existing","appendMetaMethod","metaMethod","appendMetaUseCase","target","metaUseCase","own","Object","getOwnPropertyDescriptor","value","key","name","confirm","tone","reversible","undefined","inverse","shortcut","refused","message","cause","inline","find","declared","rowInline","setMetaUseCaseBinding","binding","readMetadata","extractMetaEntity","extractMetaAccessors","extractMetaMethods","extractMetaUseCases","extractMetaUseCaseBinding","extractUseCase","entity"],"mappings":"IAACA,SAAD;CAAA,YAAA,CAACA,UAAAA,QAAiCC,QAAQ,YAA1C,YAAA,AAACD,QAAiCC,QAAQ,GAAKD,OAAOE,GAAG,CAAC;AAE1D,SAASC,WAAW,QAAQ,0BAA0B;AAoBtD,OAAO,MAAMC,kBAAkBJ,OAAO,cAAc;AACpD,OAAO,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,MACR;IAEJ;IACA,OAAOT;AACT;AAEA,OAAO,SAASU,cACdV,QAA6C,EAC7CW,UAAsB;IAEtBH,gBAAgBR,SAAS,CAACG,gBAAgB,GAAGQ;AAC/C;AAEA,OAAO,SAASC,mBACdZ,QAA6C,EAC7Ca,YAA0B;QAIvBC;IAFH,MAAMA,OAAON,gBAAgBR;IAC7B,MAAMe,YACHD,0BAAAA,IAAI,CAACV,kBAAkB,YAAvBU,0BAA0D,EAAE;IAC/DA,IAAI,CAACV,kBAAkB,GAAG;WAAIW;QAAUF;KAAa;AACvD;AAEA,OAAO,SAASG,iBACdhB,QAA6C,EAC7CiB,UAAsB;QAGJH;IADlB,MAAMA,OAAON,gBAAgBR;IAC7B,M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AMnB,WAAW0C,aAAavB;IAC9B,eAAQnB,4BAAAA,QAAU,CAACM,kBAAkB,mBAAkC,EAAE;AAC3E;AAEA,yDAAyD,GACzD,OAAO,SAASyC,0BACd5B,MAA0B;IAE1B,MAAMnB,WAAW,AACfmB,MACD,CAACpB,OAAOC,QAAQ,CAAC;IAClB,MAAMyC,UAAUzC,4BAAAA,QAAU,CAACO,0BAA0B;IAErD,IAAI,CAACkC,SAAS;QACZ,MAAM,IAAIhC,MACR,CAAC,0BAA0B,EAAEU,OAAOO,IAAI,CAAC,4BAA4B,CAAC;IAE1E;IACA,OAAOe;AACT;AAEA;;;CAGC,GACD,OAAO,SAASO,eAAe7B,MAA0B;IACvD,MAAM,EAAE8B,MAAM,EAAExB,GAAG,EAAEgB,OAAO,EAAE,GAAGM,0BAA0B5B;IAC3D,yEAAyE;IACzE,4EAA4E;IAC5E,4DAA4D;IAC5D,OAAO2B,oBAAoBG,QAAQZ,IAAI,CACrCjB,CAAAA,cAAeA,YAAYK,GAAG,KAAKA,OAAOL,YAAYqB,OAAO,KAAKA;AAEtE"}
1
+ {"version":3,"sources":["../../../src/entity-definition/helpers/entity-definition-helpers.ts"],"sourcesContent":["(Symbol as { metadata?: symbol }).metadata ??= Symbol.for('Symbol.metadata');\n\nimport { assertChord } from '../../shortcut/chord.js';\nimport { Entity, EntityConstructor } from '../../types/Entity.js';\nimport { UseCaseConstructor } from '../../types/UseCase.js';\nimport {\n type ChildConstructor,\n MetaAccessor,\n} from '../meta-entities/meta-accessor/index.js';\nimport { MetaEntity } from '../meta-entities/meta-entity/index.js';\nimport { MetaMethod } from '../meta-entities/meta-method/index.js';\nimport {\n MetaUseCase,\n MetaUseCaseBinding,\n type UseCaseAvailability,\n} from '../meta-entities/meta-use-case/index.js';\n\ndeclare global {\n interface SymbolConstructor {\n readonly metadata: unique symbol;\n }\n}\n\nexport const META_ENTITY_KEY = Symbol('MetaEntity');\nexport const META_ACCESSOR_KEY = Symbol('MetaAccessor');\nexport const META_METHOD_KEY = Symbol('MetaMethod');\nexport const META_USE_CASE_KEY = Symbol('MetaUseCase');\nexport const META_USE_CASE_BINDING_KEY = Symbol('MetaUseCaseBinding');\n\nfunction requireMetadata(\n metadata: DecoratorMetadataObject | undefined,\n): DecoratorMetadataObject {\n if (!metadata) {\n throw new Error(\n 'Decorator metadata unavailable — Symbol.metadata polyfill missing or stage-3 decorator emit not enabled.',\n );\n }\n return metadata;\n}\n\nexport function setMetaEntity(\n metadata: DecoratorMetadataObject | undefined,\n metaEntity: MetaEntity,\n) {\n requireMetadata(metadata)[META_ENTITY_KEY] = metaEntity;\n}\n\nexport function appendMetaAccessor(\n metadata: DecoratorMetadataObject | undefined,\n metaAccessor: MetaAccessor,\n) {\n const meta = requireMetadata(metadata);\n const existing =\n (meta[META_ACCESSOR_KEY] as MetaAccessor[] | undefined) ?? [];\n meta[META_ACCESSOR_KEY] = [...existing, metaAccessor];\n}\n\nexport function appendMetaMethod(\n metadata: DecoratorMetadataObject | undefined,\n metaMethod: MetaMethod,\n) {\n const meta = requireMetadata(metadata);\n const existing = (meta[META_METHOD_KEY] as MetaMethod[] | undefined) ?? [];\n meta[META_METHOD_KEY] = [...existing, metaMethod];\n}\n\n/**\n * Append a use case to the metadata of the entity it acts on.\n *\n * This is the one decorator that writes a bag other than its own: a use case is\n * declared on its own class, but the entity is what a surface holds, so the\n * descriptor has to end up there. The consequence is that a use-case module\n * which is never imported leaves the entity looking as if it had no actions,\n * which is why a host's register should assert every `@useCase()` class is\n * re-exported from its package barrel.\n *\n * It reads the target's **own** metadata rather than going through\n * {@link readMetadata}. `Symbol.metadata` resolves along the prototype chain, so\n * an inherited read would append the verb to a base class's bag and leak it to\n * every subclass. A target with no own metadata is an entity missing\n * `@entity()`, or a circular import that evaluated the use case first.\n */\nexport function appendMetaUseCase<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n metaUseCase: MetaUseCase,\n) {\n const own = Object.getOwnPropertyDescriptor(target, Symbol.metadata)\n ?.value as DecoratorMetadataObject | null | undefined;\n if (!own) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" targets ${target.name}, which has no metadata of its own — it is missing @entity(), or a circular import evaluated the use case first.`,\n );\n }\n if (\n metaUseCase.confirm?.tone === 'destructive' &&\n metaUseCase.reversible === undefined\n ) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" on ${target.name} is destructive and declares no \\`reversible\\`. Say how it is made safe: 'undo' (with an \\`inverse\\`), 'confirm' or 'typed'.`,\n );\n }\n if (metaUseCase.reversible === 'undo' && metaUseCase.inverse === undefined) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" on ${target.name} is reversible by undo and names no \\`inverse\\`: Undo has nothing to run.`,\n );\n }\n if (metaUseCase.availableWhen !== undefined) {\n assertAvailability(target, metaUseCase, metaUseCase.availableWhen);\n }\n // A shortcut is checked where it is declared, so a chord no reader can use\n // — a bare key, Option+letter, Mod+C — fails at load rather than on a page.\n if (metaUseCase.shortcut !== undefined) {\n try {\n assertChord(metaUseCase.shortcut);\n } catch (refused) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" on ${target.name}: ${(refused as Error).message}`,\n { cause: refused },\n );\n }\n }\n const existing = (own[META_USE_CASE_KEY] as MetaUseCase[] | undefined) ?? [];\n // A verb declared on a record and over a selection is one verb under one\n // key, so only a different key makes a second inline verb.\n const inline = existing.find(\n declared => declared.rowInline && declared.key !== metaUseCase.key,\n );\n if (metaUseCase.rowInline && inline) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" on ${target.name} is rowInline, and so is \"${inline.key}\": a row shows at most one verb inline.`,\n );\n }\n own[META_USE_CASE_KEY] = [...existing, metaUseCase];\n}\n\n/**\n * A verb's states are checked where they are declared, against the entity's\n * own member: a misspelt member or state would otherwise hide the verb on every\n * record, which reads as a missing grant rather than a typo.\n */\nfunction assertAvailability(\n target: EntityConstructor<Entity>,\n { key, binding, alsoAt }: MetaUseCase,\n availableWhen: UseCaseAvailability,\n) {\n const where = `Use case \"${key}\" on ${target.name}`;\n // A selection carries no states, so the collection surfaces offer every\n // verb; a verb with no record-bound cell would declare states nothing reads.\n const recordBound =\n binding === 'entity' ||\n (alsoAt ?? []).some(cell => cell.binding === 'entity');\n if (!recordBound) {\n throw new Error(\n `${where} declares \\`availableWhen\\` and sits on no record: a selection carries no states, so nothing would read them.`,\n );\n }\n const member = extractMetaAccessors(target).find(\n accessor => accessor.name === availableWhen.member,\n );\n if (member?.enumValues === undefined) {\n throw new Error(\n `${where} is available when \"${availableWhen.member}\" holds a state, and ${target.name} has no enum member by that name.`,\n );\n }\n if (availableWhen.in.length === 0) {\n throw new Error(\n `${where} is available in no state of \"${availableWhen.member}\": a verb that is never offered is a verb to delete.`,\n );\n }\n const unknown = availableWhen.in.filter(\n state => !member.enumValues?.includes(state),\n );\n if (unknown.length > 0) {\n throw new Error(\n `${where} names ${unknown.map(state => `\"${state}\"`).join(', ')}, which \"${availableWhen.member}\" does not hold.`,\n );\n }\n}\n\n/**\n * Record on the use-case class itself which entity and verb it implements, so\n * the permission can be derived from the class alone. That is what keeps the\n * verb string written once, at the declaration, instead of being retyped at\n * every guard.\n */\nexport function setMetaUseCaseBinding(\n metadata: DecoratorMetadataObject | undefined,\n binding: MetaUseCaseBinding,\n) {\n requireMetadata(metadata)[META_USE_CASE_BINDING_KEY] = binding;\n}\n\nfunction readMetadata(\n target: ChildConstructor,\n): DecoratorMetadataObject | undefined {\n return target[Symbol.metadata] ?? undefined;\n}\n\nexport function extractMetaEntity<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n): MetaEntity {\n const metadata = readMetadata(target);\n const metaEntity = metadata?.[META_ENTITY_KEY] as MetaEntity | undefined;\n if (!metaEntity) {\n throw new Error(`MetaEntity not found for ${target.name}`);\n }\n return metaEntity;\n}\n\n/**\n * 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,MACR;IAEJ;IACA,OAAOT;AACT;AAEA,OAAO,SAASU,cACdV,QAA6C,EAC7CW,UAAsB;IAEtBH,gBAAgBR,SAAS,CAACG,gBAAgB,GAAGQ;AAC/C;AAEA,OAAO,SAASC,mBACdZ,QAA6C,EAC7Ca,YAA0B;QAIvBC;IAFH,MAAMA,OAAON,gBAAgBR;IAC7B,MAAMe,YACHD,0BAAAA,IAAI,CAACV,kBAAkB,YAAvBU,0BAA0D,EAAE;IAC/DA,IAAI,CAACV,kBAAkB,GAAG;WAAIW;QAAUF;KAAa;AACvD;AAEA,OAAO,SAASG,iBACdhB,QAA6C,EAC7CiB,UAAsB;QAGJH;IADlB,MAAMA,OAAON,gBAAgBR;IAC7B,MAAMe,YAAYD,wBAAAA,IAAI,CAACT,gBAAgB,YAArBS,wBAAsD,EAAE;IAC1EA,IAAI,CAACT,gB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BACd7C,MAAkC;;IAElC,MAAMnB,WAAW6D,aAAa1C;IAC9B,eAAQnB,4BAAAA,QAAU,CAACM,kBAAkB,mBAAkC,EAAE;AAC3E;AAEA,yDAAyD,GACzD,OAAO,SAAS2D,0BACd9C,MAA0B;IAE1B,MAAMnB,WAAW,AACfmB,MACD,CAACpB,OAAOC,QAAQ,CAAC;IAClB,MAAM0C,UAAU1C,4BAAAA,QAAU,CAACO,0BAA0B;IAErD,IAAI,CAACmC,SAAS;QACZ,MAAM,IAAIjC,MACR,CAAC,0BAA0B,EAAEU,OAAOO,IAAI,CAAC,4BAA4B,CAAC;IAE1E;IACA,OAAOgB;AACT;AAEA;;;CAGC,GACD,OAAO,SAASwB,eAAe/C,MAA0B;IACvD,MAAM,EAAEgD,MAAM,EAAE1C,GAAG,EAAEiB,OAAO,EAAE,GAAGuB,0BAA0B9C;IAC3D,yEAAyE;IACzE,4EAA4E;IAC5E,4DAA4D;IAC5D,OAAO6C,oBAAoBG,QAAQ5B,IAAI,CACrCnB,CAAAA,cAAeA,YAAYK,GAAG,KAAKA,OAAOL,YAAYsB,OAAO,KAAKA;AAEtE"}
@@ -52,6 +52,26 @@ export interface UseCaseConfirm {
52
52
  * surface renders it is one click on one of them.
53
53
  */
54
54
  export type UseCaseReversible = 'undo' | 'confirm' | 'typed';
55
+ /**
56
+ * The states a record must be in for a verb to apply to it: the record's
57
+ * `member` — an `enumValues` accessor, by its own name as the record holds
58
+ * it rather than any wire alias — holds one of `in`.
59
+ *
60
+ * ⚠️ **This is presentation, not authorization.** A surface hides a verb the
61
+ * record's state does not allow, so a shipment awaiting dispatch offers
62
+ * Dispatch and nothing that only a dispatched one can take. The verb's handler
63
+ * still refuses an illegal move — a record can change between the render and
64
+ * the click, and a selection carries no states at all — so a bulk run reports
65
+ * such a row as a failed outcome rather than skipping it on the client.
66
+ *
67
+ * Declared beside the verb rather than derived from a transition table because
68
+ * the framework has no notion of one; a host that keeps a table derives `in`
69
+ * from it, so the states are written once.
70
+ */
71
+ export interface UseCaseAvailability {
72
+ member: string;
73
+ in: readonly string[];
74
+ }
55
75
  /**
56
76
  * How much weight a surface gives a verb. One `primary` per surface — the
57
77
  * thing the surface is for — and every other verb `default`; a second primary
@@ -125,6 +145,12 @@ export interface MetaUseCaseOptions<TKey extends string, TEntity extends Entity>
125
145
  reversible?: UseCaseReversible;
126
146
  /** The verb Undo runs, by key. Required with `reversible: 'undo'`. */
127
147
  inverse?: string;
148
+ /**
149
+ * The states a record must be in for the verb to be offered on it — see
150
+ * {@link UseCaseAvailability}. Refused on an `unbound` verb, which has no
151
+ * record to be in a state.
152
+ */
153
+ availableWhen?: UseCaseAvailability;
128
154
  /** Names a form a surface should open instead of acting immediately. */
129
155
  form?: string;
130
156
  /**
@@ -171,6 +197,7 @@ export declare class MetaUseCase {
171
197
  readonly confirm?: UseCaseConfirm;
172
198
  readonly reversible?: UseCaseReversible;
173
199
  readonly inverse?: string;
200
+ readonly availableWhen?: UseCaseAvailability;
174
201
  readonly emphasis?: UseCaseEmphasis;
175
202
  readonly priority?: number;
176
203
  readonly rowInline?: true;
@@ -1 +1 @@
1
- {"version":3,"file":"meta-use-case.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/meta-entities/meta-use-case/meta-use-case.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE1E,oEAAoE;AACpE,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,YAAY,GAAG,SAAS,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAC1B,mBAAmB,GAAG,qBAAqB,GAAG,aAAa,CAAC;AAE9D;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,cAAc,CAAC;IACxB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,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;gBAI9B,OAAO,EAAE,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC;CA8BxD"}
@@ -12,6 +12,7 @@ export class MetaUseCase {
12
12
  this.confirm = options.confirm;
13
13
  this.reversible = options.reversible;
14
14
  this.inverse = options.inverse;
15
+ this.availableWhen = options.availableWhen;
15
16
  this.emphasis = options.emphasis;
16
17
  this.priority = options.priority;
17
18
  this.rowInline = options.rowInline;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/entity-definition/meta-entities/meta-use-case/meta-use-case.ts"],"sourcesContent":["import type { Schema } from 'effect';\n\nimport type { FailureClass } from '../../../failure/failure.js';\nimport type { Entity, EntityConstructor } from '../../../types/Entity.js';\n\n/** What a use case acts on: one record, a selection, or nothing. */\nexport type UseCaseBinding = 'entity' | 'collection' | 'unbound';\n\n/**\n * Where a surface puts the action. Deliberately **not** derivable from\n * {@link UseCaseBinding}: an entity-bound action can be determining (a footer\n * \"Publish\" that finalizes the page) or context-independent (a toolbar action\n * available whenever a record is open). Collapsing the two would force every\n * surface to re-derive a placement the author already knew.\n */\nexport type UseCasePlacement =\n 'context-dependent' | 'context-independent' | 'determining';\n\n/**\n * One place a verb can appear: a binding and a placement together.\n *\n * The pair is the unit rather than either half, because the two answer\n * different questions — placement decides the *surface* and binding decides the\n * *payload* — and a verb reachable from a row and from a selection differs in\n * both at once.\n */\nexport interface UseCaseCell {\n binding: UseCaseBinding;\n placement: UseCasePlacement;\n}\n\n/** Confirmation a surface must obtain before running the use case. */\nexport interface UseCaseConfirm {\n tone: 'destructive' | 'neutral';\n /** Catalog key. Copy never lives in a descriptor. */\n messageKey: string;\n /**\n * Catalog key for the confirming button. Absent, the button repeats the\n * verb's own label: a dialog that says \"Confirm\" makes the reader go back to\n * the title to learn what they are agreeing to.\n */\n confirmLabelKey?: string;\n /**\n * Catalog key for what an `undo` verb's toast says once it has run, in the\n * past tense — \"Invoice voided.\" Absent, a generic sentence names the verb.\n */\n doneKey?: string;\n}\n\n/**\n * How a destructive verb is made safe\n * ([ADR 0026](../../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)):\n * - `undo` acts at once and offers Undo, which runs the verb's `inverse`;\n * - `confirm` asks first, in a dialog that names what will be destroyed;\n * - `typed` asks the reader to type the record's name, or the count, first.\n *\n * Required on every `confirm.tone: 'destructive'` verb, and refused at\n * declaration without it: a destructive verb whose safety is left to whichever\n * surface renders it is one click on one of them.\n */\nexport type UseCaseReversible = 'undo' | 'confirm' | 'typed';\n\n/**\n * How much weight a surface gives a verb. One `primary` per surface — the\n * thing the surface is for — and every other verb `default`; a second primary\n * on one surface throws when it renders\n * ([ADR 0026](../../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)).\n */\nexport type UseCaseEmphasis = 'primary' | 'default';\n\n/**\n * The hierarchy a surface renders a verb in: its weight, its order among the\n * secondaries, whether a row shows it inline, and the chord that reaches it.\n */\nexport interface UseCaseHierarchy {\n emphasis?: UseCaseEmphasis;\n /**\n * Order among the surface's secondaries, lowest first; equal or absent keeps\n * declaration order. The first three stay visible and the rest fold into\n * \"More actions\".\n */\n priority?: number;\n /**\n * Shown on the row itself rather than only in its menu — at most one verb\n * per entity, since a row with two inline buttons is a toolbar per row.\n */\n rowInline?: true;\n /**\n * A modifier chord, `Mod+Shift+P`: `Mod` is ⌘ on macOS and Ctrl elsewhere.\n * Rendered as `aria-keyshortcuts` and listed in the command palette.\n */\n shortcut?: string;\n}\n\n/**\n * What `@useCase()` declares.\n *\n * `entity` is the target the verb is registered against — it is what the\n * decorator appends to, and it is not part of the served descriptor.\n *\n * `labelKey` is mandatory and namespace-qualified, the `GuardedNavItem`\n * convention: i18n is mandatory and `react/jsx-no-literals` fails the build on a\n * string written into JSX, so a descriptor carrying copy could not be rendered.\n *\n * `keywordsKey` is a catalog key rather than a `string[]` so the command palette\n * matches across locales — a user typing an English term reaches a Spanish\n * command.\n */\nexport interface MetaUseCaseOptions<\n TKey extends string,\n TEntity extends Entity,\n> extends UseCaseHierarchy {\n entity: EntityConstructor<TEntity>;\n key: TKey;\n binding: UseCaseBinding;\n placement: UseCasePlacement;\n /**\n * Further places the same verb appears, beyond the {@link binding} and\n * {@link placement} above.\n *\n * ⚠️ **One verb, one permission, several surfaces.** Publishing an offering\n * from its form, from a row menu and over a selection is one act reached three\n * ways, and the alternative was three `@useCase()` classes — which `slices`\n * refuses anyway, since a verb key is the third segment of one permission and\n * two classes cannot share a key. Three classes would have meant three\n * permissions for one act, and a grant that let somebody publish one offering\n * but not twenty.\n *\n * The primary cell stays where it is so that nothing already declared\n * changes, and so a descriptor still reads as \"this verb lives here\" with the\n * rest as additions.\n */\n alsoAt?: readonly UseCaseCell[];\n labelKey: string;\n keywordsKey?: string;\n confirm?: UseCaseConfirm;\n /** How a destructive verb is made safe. Required when `confirm.tone` is `destructive`. */\n reversible?: UseCaseReversible;\n /** The verb Undo runs, by key. Required with `reversible: 'undo'`. */\n inverse?: string;\n /** Names a form a surface should open instead of acting immediately. */\n form?: string;\n /**\n * The use case whose variants this verb resolves between, by name: the\n * service holds the rules, and `$metadata` reports which one this caller\n * resolves to.\n */\n variants?: string;\n /** The recipe this verb starts a flow from, by name — the flow-backed verbs. */\n recipe?: string;\n /**\n * What the verb's endpoint takes, answers and refuses with — the contract\n * the shell derives the endpoint from. Absent `payload` means the verb takes\n * no body; absent `success` means its answer is not described. None of the\n * three reaches a served `$metadata` document.\n */\n payload?: Schema.Top;\n success?: Schema.Top;\n errors?: readonly FailureClass[];\n}\n\n/**\n * What the use-case class's **own** metadata carries, as opposed to what is\n * appended to the entity. Two fields are enough to derive the permission, which\n * is what lets `permissionForUseCase(SomeUC)` take a single argument and keeps\n * the verb string written exactly once.\n */\nexport interface MetaUseCaseBinding {\n entity: EntityConstructor<Entity>;\n key: string;\n /**\n * Which of the entity's verbs under `key` the class is: one key may be\n * declared on a record and over a selection, and each class is one of them.\n */\n binding: UseCaseBinding;\n}\n\nexport class MetaUseCase {\n //#region Properties\n readonly entity: EntityConstructor<Entity>;\n readonly key: string;\n readonly binding: UseCaseBinding;\n readonly placement: UseCasePlacement;\n readonly alsoAt?: readonly UseCaseCell[];\n readonly labelKey: string;\n readonly keywordsKey?: string;\n readonly confirm?: UseCaseConfirm;\n readonly reversible?: UseCaseReversible;\n readonly inverse?: string;\n readonly emphasis?: UseCaseEmphasis;\n readonly priority?: number;\n readonly rowInline?: true;\n readonly shortcut?: string;\n readonly form?: string;\n readonly variants?: string;\n readonly recipe?: string;\n readonly payload?: Schema.Top;\n readonly success?: Schema.Top;\n readonly errors?: readonly FailureClass[];\n //#endregion\n\n //#region Constructors\n constructor(options: MetaUseCaseOptions<string, Entity>) {\n this.entity = options.entity;\n this.key = options.key;\n this.binding = options.binding;\n this.placement = options.placement;\n this.alsoAt = options.alsoAt;\n this.labelKey = options.labelKey;\n this.keywordsKey = options.keywordsKey;\n this.confirm = options.confirm;\n this.reversible = options.reversible;\n this.inverse = options.inverse;\n this.emphasis = options.emphasis;\n this.priority = options.priority;\n this.rowInline = options.rowInline;\n this.shortcut = options.shortcut;\n this.form = options.form;\n this.variants = options.variants;\n this.recipe = options.recipe;\n this.payload = options.payload;\n this.success = options.success;\n this.errors = options.errors;\n }\n //#endregion\n\n //#region Methods\n //#endregion\n\n //#region Accessors\n //#endregion\n}\n"],"names":["MetaUseCase","options","entity","key","binding","placement","alsoAt","labelKey","keywordsKey","confirm","reversible","inverse","emphasis","priority","rowInline","shortcut","form","variants","recipe","payload","success","errors"],"mappings":"AAiLA,OAAO,MAAMA;IAsBX,YAAY;IAEZ,sBAAsB;IACtB,YAAYC,OAA2C,CAAE;QACvD,IAAI,CAACC,MAAM,GAAGD,QAAQC,MAAM;QAC5B,IAAI,CAACC,GAAG,GAAGF,QAAQE,GAAG;QACtB,IAAI,CAACC,OAAO,GAAGH,QAAQG,OAAO;QAC9B,IAAI,CAACC,SAAS,GAAGJ,QAAQI,SAAS;QAClC,IAAI,CAACC,MAAM,GAAGL,QAAQK,MAAM;QAC5B,IAAI,CAACC,QAAQ,GAAGN,QAAQM,QAAQ;QAChC,IAAI,CAACC,WAAW,GAAGP,QAAQO,WAAW;QACtC,IAAI,CAACC,OAAO,GAAGR,QAAQQ,OAAO;QAC9B,IAAI,CAACC,UAAU,GAAGT,QAAQS,UAAU;QACpC,IAAI,CAACC,OAAO,GAAGV,QAAQU,OAAO;QAC9B,IAAI,CAACC,QAAQ,GAAGX,QAAQW,QAAQ;QAChC,IAAI,CAACC,QAAQ,GAAGZ,QAAQY,QAAQ;QAChC,IAAI,CAACC,SAAS,GAAGb,QAAQa,SAAS;QAClC,IAAI,CAACC,QAAQ,GAAGd,QAAQc,QAAQ;QAChC,IAAI,CAACC,IAAI,GAAGf,QAAQe,IAAI;QACxB,IAAI,CAACC,QAAQ,GAAGhB,QAAQgB,QAAQ;QAChC,IAAI,CAACC,MAAM,GAAGjB,QAAQiB,MAAM;QAC5B,IAAI,CAACC,OAAO,GAAGlB,QAAQkB,OAAO;QAC9B,IAAI,CAACC,OAAO,GAAGnB,QAAQmB,OAAO;QAC9B,IAAI,CAACC,MAAM,GAAGpB,QAAQoB,MAAM;IAC9B;AAQF"}
1
+ {"version":3,"sources":["../../../../src/entity-definition/meta-entities/meta-use-case/meta-use-case.ts"],"sourcesContent":["import type { Schema } from 'effect';\n\nimport type { FailureClass } from '../../../failure/failure.js';\nimport type { Entity, EntityConstructor } from '../../../types/Entity.js';\n\n/** What a use case acts on: one record, a selection, or nothing. */\nexport type UseCaseBinding = 'entity' | 'collection' | 'unbound';\n\n/**\n * Where a surface puts the action. Deliberately **not** derivable from\n * {@link UseCaseBinding}: an entity-bound action can be determining (a footer\n * \"Publish\" that finalizes the page) or context-independent (a toolbar action\n * available whenever a record is open). Collapsing the two would force every\n * surface to re-derive a placement the author already knew.\n */\nexport type UseCasePlacement =\n 'context-dependent' | 'context-independent' | 'determining';\n\n/**\n * One place a verb can appear: a binding and a placement together.\n *\n * The pair is the unit rather than either half, because the two answer\n * different questions — placement decides the *surface* and binding decides the\n * *payload* — and a verb reachable from a row and from a selection differs in\n * both at once.\n */\nexport interface UseCaseCell {\n binding: UseCaseBinding;\n placement: UseCasePlacement;\n}\n\n/** Confirmation a surface must obtain before running the use case. */\nexport interface UseCaseConfirm {\n tone: 'destructive' | 'neutral';\n /** Catalog key. Copy never lives in a descriptor. */\n messageKey: string;\n /**\n * Catalog key for the confirming button. Absent, the button repeats the\n * verb's own label: a dialog that says \"Confirm\" makes the reader go back to\n * the title to learn what they are agreeing to.\n */\n confirmLabelKey?: string;\n /**\n * Catalog key for what an `undo` verb's toast says once it has run, in the\n * past tense — \"Invoice voided.\" Absent, a generic sentence names the verb.\n */\n doneKey?: string;\n}\n\n/**\n * How a destructive verb is made safe\n * ([ADR 0026](../../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)):\n * - `undo` acts at once and offers Undo, which runs the verb's `inverse`;\n * - `confirm` asks first, in a dialog that names what will be destroyed;\n * - `typed` asks the reader to type the record's name, or the count, first.\n *\n * Required on every `confirm.tone: 'destructive'` verb, and refused at\n * declaration without it: a destructive verb whose safety is left to whichever\n * surface renders it is one click on one of them.\n */\nexport type UseCaseReversible = 'undo' | 'confirm' | 'typed';\n\n/**\n * The states a record must be in for a verb to apply to it: the record's\n * `member` — an `enumValues` accessor, by its own name as the record holds\n * it rather than any wire alias — holds one of `in`.\n *\n * ⚠️ **This is presentation, not authorization.** A surface hides a verb the\n * record's state does not allow, so a shipment awaiting dispatch offers\n * Dispatch and nothing that only a dispatched one can take. The verb's handler\n * still refuses an illegal move — a record can change between the render and\n * the click, and a selection carries no states at all — so a bulk run reports\n * such a row as a failed outcome rather than skipping it on the client.\n *\n * Declared beside the verb rather than derived from a transition table because\n * the framework has no notion of one; a host that keeps a table derives `in`\n * from it, so the states are written once.\n */\nexport interface UseCaseAvailability {\n member: string;\n in: readonly string[];\n}\n\n/**\n * How much weight a surface gives a verb. One `primary` per surface — the\n * thing the surface is for — and every other verb `default`; a second primary\n * on one surface throws when it renders\n * ([ADR 0026](../../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)).\n */\nexport type UseCaseEmphasis = 'primary' | 'default';\n\n/**\n * The hierarchy a surface renders a verb in: its weight, its order among the\n * secondaries, whether a row shows it inline, and the chord that reaches it.\n */\nexport interface UseCaseHierarchy {\n emphasis?: UseCaseEmphasis;\n /**\n * Order among the surface's secondaries, lowest first; equal or absent keeps\n * declaration order. The first three stay visible and the rest fold into\n * \"More actions\".\n */\n priority?: number;\n /**\n * Shown on the row itself rather than only in its menu — at most one verb\n * per entity, since a row with two inline buttons is a toolbar per row.\n */\n rowInline?: true;\n /**\n * A modifier chord, `Mod+Shift+P`: `Mod` is ⌘ on macOS and Ctrl elsewhere.\n * Rendered as `aria-keyshortcuts` and listed in the command palette.\n */\n shortcut?: string;\n}\n\n/**\n * What `@useCase()` declares.\n *\n * `entity` is the target the verb is registered against — it is what the\n * decorator appends to, and it is not part of the served descriptor.\n *\n * `labelKey` is mandatory and namespace-qualified, the `GuardedNavItem`\n * convention: i18n is mandatory and `react/jsx-no-literals` fails the build on a\n * string written into JSX, so a descriptor carrying copy could not be rendered.\n *\n * `keywordsKey` is a catalog key rather than a `string[]` so the command palette\n * matches across locales — a user typing an English term reaches a Spanish\n * command.\n */\nexport interface MetaUseCaseOptions<\n TKey extends string,\n TEntity extends Entity,\n> extends UseCaseHierarchy {\n entity: EntityConstructor<TEntity>;\n key: TKey;\n binding: UseCaseBinding;\n placement: UseCasePlacement;\n /**\n * Further places the same verb appears, beyond the {@link binding} and\n * {@link placement} above.\n *\n * ⚠️ **One verb, one permission, several surfaces.** Publishing an offering\n * from its form, from a row menu and over a selection is one act reached three\n * ways, and the alternative was three `@useCase()` classes — which `slices`\n * refuses anyway, since a verb key is the third segment of one permission and\n * two classes cannot share a key. Three classes would have meant three\n * permissions for one act, and a grant that let somebody publish one offering\n * but not twenty.\n *\n * The primary cell stays where it is so that nothing already declared\n * changes, and so a descriptor still reads as \"this verb lives here\" with the\n * rest as additions.\n */\n alsoAt?: readonly UseCaseCell[];\n labelKey: string;\n keywordsKey?: string;\n confirm?: UseCaseConfirm;\n /** How a destructive verb is made safe. Required when `confirm.tone` is `destructive`. */\n reversible?: UseCaseReversible;\n /** The verb Undo runs, by key. Required with `reversible: 'undo'`. */\n inverse?: string;\n /**\n * The states a record must be in for the verb to be offered on it — see\n * {@link UseCaseAvailability}. Refused on an `unbound` verb, which has no\n * record to be in a state.\n */\n availableWhen?: UseCaseAvailability;\n /** Names a form a surface should open instead of acting immediately. */\n form?: string;\n /**\n * The use case whose variants this verb resolves between, by name: the\n * service holds the rules, and `$metadata` reports which one this caller\n * resolves to.\n */\n variants?: string;\n /** The recipe this verb starts a flow from, by name — the flow-backed verbs. */\n recipe?: string;\n /**\n * What the verb's endpoint takes, answers and refuses with — the contract\n * the shell derives the endpoint from. Absent `payload` means the verb takes\n * no body; absent `success` means its answer is not described. None of the\n * three reaches a served `$metadata` document.\n */\n payload?: Schema.Top;\n success?: Schema.Top;\n errors?: readonly FailureClass[];\n}\n\n/**\n * What the use-case class's **own** metadata carries, as opposed to what is\n * appended to the entity. Two fields are enough to derive the permission, which\n * is what lets `permissionForUseCase(SomeUC)` take a single argument and keeps\n * the verb string written exactly once.\n */\nexport interface MetaUseCaseBinding {\n entity: EntityConstructor<Entity>;\n key: string;\n /**\n * Which of the entity's verbs under `key` the class is: one key may be\n * declared on a record and over a selection, and each class is one of them.\n */\n binding: UseCaseBinding;\n}\n\nexport class MetaUseCase {\n //#region Properties\n readonly entity: EntityConstructor<Entity>;\n readonly key: string;\n readonly binding: UseCaseBinding;\n readonly placement: UseCasePlacement;\n readonly alsoAt?: readonly UseCaseCell[];\n readonly labelKey: string;\n readonly keywordsKey?: string;\n readonly confirm?: UseCaseConfirm;\n readonly reversible?: UseCaseReversible;\n readonly inverse?: string;\n readonly availableWhen?: UseCaseAvailability;\n readonly emphasis?: UseCaseEmphasis;\n readonly priority?: number;\n readonly rowInline?: true;\n readonly shortcut?: string;\n readonly form?: string;\n readonly variants?: string;\n readonly recipe?: string;\n readonly payload?: Schema.Top;\n readonly success?: Schema.Top;\n readonly errors?: readonly FailureClass[];\n //#endregion\n\n //#region Constructors\n constructor(options: MetaUseCaseOptions<string, Entity>) {\n this.entity = options.entity;\n this.key = options.key;\n this.binding = options.binding;\n this.placement = options.placement;\n this.alsoAt = options.alsoAt;\n this.labelKey = options.labelKey;\n this.keywordsKey = options.keywordsKey;\n this.confirm = options.confirm;\n this.reversible = options.reversible;\n this.inverse = options.inverse;\n this.availableWhen = options.availableWhen;\n this.emphasis = options.emphasis;\n this.priority = options.priority;\n this.rowInline = options.rowInline;\n this.shortcut = options.shortcut;\n this.form = options.form;\n this.variants = options.variants;\n this.recipe = options.recipe;\n this.payload = options.payload;\n this.success = options.success;\n this.errors = options.errors;\n }\n //#endregion\n\n //#region Methods\n //#endregion\n\n //#region Accessors\n //#endregion\n}\n"],"names":["MetaUseCase","options","entity","key","binding","placement","alsoAt","labelKey","keywordsKey","confirm","reversible","inverse","availableWhen","emphasis","priority","rowInline","shortcut","form","variants","recipe","payload","success","errors"],"mappings":"AA4MA,OAAO,MAAMA;IAuBX,YAAY;IAEZ,sBAAsB;IACtB,YAAYC,OAA2C,CAAE;QACvD,IAAI,CAACC,MAAM,GAAGD,QAAQC,MAAM;QAC5B,IAAI,CAACC,GAAG,GAAGF,QAAQE,GAAG;QACtB,IAAI,CAACC,OAAO,GAAGH,QAAQG,OAAO;QAC9B,IAAI,CAACC,SAAS,GAAGJ,QAAQI,SAAS;QAClC,IAAI,CAACC,MAAM,GAAGL,QAAQK,MAAM;QAC5B,IAAI,CAACC,QAAQ,GAAGN,QAAQM,QAAQ;QAChC,IAAI,CAACC,WAAW,GAAGP,QAAQO,WAAW;QACtC,IAAI,CAACC,OAAO,GAAGR,QAAQQ,OAAO;QAC9B,IAAI,CAACC,UAAU,GAAGT,QAAQS,UAAU;QACpC,IAAI,CAACC,OAAO,GAAGV,QAAQU,OAAO;QAC9B,IAAI,CAACC,aAAa,GAAGX,QAAQW,aAAa;QAC1C,IAAI,CAACC,QAAQ,GAAGZ,QAAQY,QAAQ;QAChC,IAAI,CAACC,QAAQ,GAAGb,QAAQa,QAAQ;QAChC,IAAI,CAACC,SAAS,GAAGd,QAAQc,SAAS;QAClC,IAAI,CAACC,QAAQ,GAAGf,QAAQe,QAAQ;QAChC,IAAI,CAACC,IAAI,GAAGhB,QAAQgB,IAAI;QACxB,IAAI,CAACC,QAAQ,GAAGjB,QAAQiB,QAAQ;QAChC,IAAI,CAACC,MAAM,GAAGlB,QAAQkB,MAAM;QAC5B,IAAI,CAACC,OAAO,GAAGnB,QAAQmB,OAAO;QAC9B,IAAI,CAACC,OAAO,GAAGpB,QAAQoB,OAAO;QAC9B,IAAI,CAACC,MAAM,GAAGrB,QAAQqB,MAAM;IAC9B;AAQF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entifix/core",
3
- "version": "0.20.1",
3
+ "version": "0.20.3",
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": {