@entifix/core 0.10.1 → 0.11.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 (41) hide show
  1. package/dist/entity-definition/describe/describe-entity-use-cases.d.ts +18 -0
  2. package/dist/entity-definition/describe/describe-entity-use-cases.d.ts.map +1 -1
  3. package/dist/entity-definition/describe/describe-entity-use-cases.js +3 -1
  4. package/dist/entity-definition/describe/describe-entity-use-cases.js.map +1 -1
  5. package/dist/entity-definition/meta-entities/meta-use-case/meta-use-case.d.ts +10 -0
  6. package/dist/entity-definition/meta-entities/meta-use-case/meta-use-case.d.ts.map +1 -1
  7. package/dist/entity-definition/meta-entities/meta-use-case/meta-use-case.js +2 -0
  8. package/dist/entity-definition/meta-entities/meta-use-case/meta-use-case.js.map +1 -1
  9. package/dist/envelope/codec.d.ts +123 -0
  10. package/dist/envelope/codec.d.ts.map +1 -0
  11. package/dist/envelope/codec.js +203 -0
  12. package/dist/envelope/codec.js.map +1 -0
  13. package/dist/envelope/index.d.ts +2 -0
  14. package/dist/envelope/index.d.ts.map +1 -1
  15. package/dist/envelope/index.js +2 -0
  16. package/dist/envelope/index.js.map +1 -1
  17. package/dist/envelope/read-envelope.d.ts +17 -34
  18. package/dist/envelope/read-envelope.d.ts.map +1 -1
  19. package/dist/envelope/read-envelope.js +30 -126
  20. package/dist/envelope/read-envelope.js.map +1 -1
  21. package/dist/envelope/registry.d.ts +45 -0
  22. package/dist/envelope/registry.d.ts.map +1 -0
  23. package/dist/envelope/registry.js +55 -0
  24. package/dist/envelope/registry.js.map +1 -0
  25. package/dist/envelope/types.d.ts +48 -33
  26. package/dist/envelope/types.d.ts.map +1 -1
  27. package/dist/envelope/types.js +1 -1
  28. package/dist/envelope/types.js.map +1 -1
  29. package/dist/idempotency/idempotency-key.d.ts +20 -0
  30. package/dist/idempotency/idempotency-key.d.ts.map +1 -0
  31. package/dist/idempotency/idempotency-key.js +42 -0
  32. package/dist/idempotency/idempotency-key.js.map +1 -0
  33. package/dist/idempotency/index.d.ts +2 -0
  34. package/dist/idempotency/index.d.ts.map +1 -0
  35. package/dist/idempotency/index.js +3 -0
  36. package/dist/idempotency/index.js.map +1 -0
  37. package/dist/index.d.ts +1 -0
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +1 -0
  40. package/dist/index.js.map +1 -1
  41. package/package.json +1 -1
@@ -19,6 +19,24 @@ export interface UseCaseDescriptor {
19
19
  keywordsKey?: string;
20
20
  confirm?: UseCaseConfirm;
21
21
  form?: string;
22
+ /** The named variant set this verb resolves between. */
23
+ variants?: string;
24
+ /** The named recipe this verb starts a flow from. */
25
+ recipe?: string;
26
+ /**
27
+ * What this verb resolves to **for the caller asking** — present only on a
28
+ * served `$metadata` document, computed per principal.
29
+ */
30
+ composition?: UseCaseComposition;
31
+ }
32
+ /** Which variant, and which flow, a verb resolves to for one caller. */
33
+ export interface UseCaseComposition {
34
+ useCase: string;
35
+ variant: string;
36
+ recipe?: string;
37
+ slipVersion?: number;
38
+ /** The `id@n` references the recipe can pin, in order. */
39
+ fragments?: readonly string[];
22
40
  }
23
41
  /**
24
42
  * Resolves the use cases declared against an entity, in declaration order.
@@ -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,EACjB,MAAM,yCAAyC,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC,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,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,MAAM,EAC3D,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAC5C,iBAAiB,EAAE,CAWrB"}
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,EACjB,MAAM,yCAAyC,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC,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,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,CAarB"}
@@ -18,7 +18,9 @@ import { extractMetaUseCases } from '../helpers/index.js';
18
18
  labelKey: metaUseCase.labelKey,
19
19
  keywordsKey: metaUseCase.keywordsKey,
20
20
  confirm: metaUseCase.confirm,
21
- form: metaUseCase.form
21
+ form: metaUseCase.form,
22
+ variants: metaUseCase.variants,
23
+ recipe: metaUseCase.recipe
22
24
  }));
23
25
  }
24
26
 
@@ -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 UseCasePlacement,\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 {\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 form?: 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 form: metaUseCase.form,\n }));\n}\n"],"names":["extractMetaUseCases","describeEntityUseCases","entityConstructor","map","metaUseCase","key","binding","placement","alsoAt","labelKey","keywordsKey","confirm","form"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,sBAAsB;AA6B1D;;;;;;;;;;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,MAAMR,YAAYQ,IAAI;QACxB,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 UseCaseBinding,\n UseCaseCell,\n UseCaseConfirm,\n UseCasePlacement,\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 {\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 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 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","form","variants","recipe"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,sBAAsB;AAgD1D;;;;;;;;;;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,MAAMR,YAAYQ,IAAI;YACtBC,UAAUT,YAAYS,QAAQ;YAC9BC,QAAQV,YAAYU,MAAM;QAC5B,CAAA;AACF"}
@@ -68,6 +68,14 @@ export interface MetaUseCaseOptions<TKey extends string, TEntity extends Entity>
68
68
  confirm?: UseCaseConfirm;
69
69
  /** Names a form a surface should open instead of acting immediately. */
70
70
  form?: string;
71
+ /**
72
+ * The use case whose variants this verb resolves between, by name: the
73
+ * service holds the rules, and `$metadata` reports which one this caller
74
+ * resolves to.
75
+ */
76
+ variants?: string;
77
+ /** The recipe this verb starts a flow from, by name — the flow-backed verbs. */
78
+ recipe?: string;
71
79
  }
72
80
  /**
73
81
  * What the use-case class's **own** metadata carries, as opposed to what is
@@ -89,6 +97,8 @@ export declare class MetaUseCase {
89
97
  readonly keywordsKey?: string;
90
98
  readonly confirm?: UseCaseConfirm;
91
99
  readonly form?: string;
100
+ readonly variants?: string;
101
+ readonly recipe?: string;
92
102
  constructor(options: MetaUseCaseOptions<string, Entity>);
93
103
  }
94
104
  //# sourceMappingURL=meta-use-case.d.ts.map
@@ -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,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE1E,oEAAoE;AACpE,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,YAAY,GAAG,SAAS,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QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;gBAIX,OAAO,EAAE,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC;CAkBxD"}
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,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE1E,oEAAoE;AACpE,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,YAAY,GAAG,SAAS,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAC1B,mBAAmB,GAAG,qBAAqB,GAAG,aAAa,CAAC;AAE9D;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,cAAc,CAAC;IACxB,SAAS,EAAE,gBAAgB,CAAC;CAC7B;AAED,sEAAsE;AACtE,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,aAAa,GAAG,SAAS,CAAC;IAChC,qDAAqD;IACrD,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,kBAAkB,CACjC,IAAI,SAAS,MAAM,EACnB,OAAO,SAAS,MAAM;IAEtB,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACnC,GAAG,EAAE,IAAI,CAAC;IACV,OAAO,EAAE,cAAc,CAAC;IACxB,SAAS,EAAE,gBAAgB,CAAC;IAC5B;;;;;;;;;;;;;;;OAeG;IACH,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,wEAAwE;IACxE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gFAAgF;IAChF,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAClC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,qBAAa,WAAW;IAEtB,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC3C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC;IACrC,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,WAAW,EAAE,CAAC;IACzC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBAIb,OAAO,EAAE,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC;CAoBxD"}
@@ -11,6 +11,8 @@ export class MetaUseCase {
11
11
  this.keywordsKey = options.keywordsKey;
12
12
  this.confirm = options.confirm;
13
13
  this.form = options.form;
14
+ this.variants = options.variants;
15
+ this.recipe = options.recipe;
14
16
  }
15
17
  }
16
18
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/entity-definition/meta-entities/meta-use-case/meta-use-case.ts"],"sourcesContent":["import 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\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> {\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 /** Names a form a surface should open instead of acting immediately. */\n form?: string;\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\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 form?: string;\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.form = options.form;\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","form"],"mappings":"AA4FA,OAAO,MAAMA;IAWX,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,IAAI,GAAGT,QAAQS,IAAI;IAC1B;AAQF"}
1
+ {"version":3,"sources":["../../../../src/entity-definition/meta-entities/meta-use-case/meta-use-case.ts"],"sourcesContent":["import 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\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> {\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 /** 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\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\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 form?: string;\n readonly variants?: string;\n readonly recipe?: string;\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.form = options.form;\n this.variants = options.variants;\n this.recipe = options.recipe;\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","form","variants","recipe"],"mappings":"AAoGA,OAAO,MAAMA;IAaX,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,IAAI,GAAGT,QAAQS,IAAI;QACxB,IAAI,CAACC,QAAQ,GAAGV,QAAQU,QAAQ;QAChC,IAAI,CAACC,MAAM,GAAGX,QAAQW,MAAM;IAC9B;AAQF"}
@@ -0,0 +1,123 @@
1
+ import { Effect, Schema } from 'effect';
2
+ import { ProtocolFailure } from '../failure/generic.js';
3
+ import type { AudienceEntry, DomainEvent, EntifixEnvelope, EventEnvelope } from './types.js';
4
+ /**
5
+ * A struct that keeps members it does not name: a newer peer's field is not
6
+ * ours to drop. What a registered message schema should usually be, since a
7
+ * plain `Schema.Struct` strips every unknown key on decode.
8
+ */
9
+ export declare const openStruct: <S extends Schema.Struct.Fields>(fields: S) => Schema.StructWithRest<Schema.Struct<S>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
10
+ /**
11
+ * The envelope frame around one `data` schema — for a reader that knows the
12
+ * one shape it accepts, such as a channel that only ever carries entity
13
+ * changes, and so needs no registry lookup.
14
+ */
15
+ export declare const Envelope: {
16
+ readonly codec: <A, I>(data: Schema.Codec<A, I>) => Schema.Struct<{
17
+ readonly meta: Schema.StructWithRest<Schema.Struct<{
18
+ type: Schema.NonEmptyString;
19
+ entity: Schema.optional<Schema.String>;
20
+ links: Schema.optional<Schema.mutable<Schema.$Array<Schema.Struct<{
21
+ readonly rel: Schema.String;
22
+ readonly href: Schema.String;
23
+ readonly method: Schema.optional<Schema.Literals<readonly ["GET", "POST", "PUT", "PATCH", "DELETE"]>>;
24
+ }>>>>;
25
+ event: Schema.optional<Schema.StructWithRest<Schema.Struct<{
26
+ name: Schema.NonEmptyString;
27
+ id: Schema.NonEmptyString;
28
+ source: Schema.NonEmptyString;
29
+ at: Schema.NonEmptyString;
30
+ correlationId: Schema.optional<Schema.String>;
31
+ aggregate: Schema.optional<Schema.Struct<{
32
+ readonly type: Schema.String;
33
+ readonly id: Schema.String;
34
+ }>>;
35
+ version: Schema.optional<Schema.Int>;
36
+ audience: Schema.optional<Schema.$Array<Schema.Struct<{
37
+ readonly kind: Schema.Literals<readonly ["organization", "party", "flow"]>;
38
+ readonly id: Schema.String;
39
+ readonly digest: Schema.optional<Schema.String>;
40
+ }>>>;
41
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>;
42
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
43
+ readonly data: Schema.Codec<A, I, never, never>;
44
+ }>;
45
+ };
46
+ /**
47
+ * Decodes an arbitrary body into an envelope whose `data` has been decoded
48
+ * against the schema registered for it.
49
+ *
50
+ * Nothing is cast: a body that is not an envelope, names a type nothing
51
+ * registered, or carries `data` its schema refuses fails with a
52
+ * {@link ProtocolFailure} — poison on a bus, a dropped frame in a browser, a
53
+ * typed failure at an HTTP client. `expected` narrows the accepted `meta.type`.
54
+ */
55
+ export declare const decodeEnvelope: (body: unknown, expected?: string) => Effect.Effect<EntifixEnvelope, ProtocolFailure>;
56
+ /**
57
+ * Decodes a bus or stream message into a {@link DomainEvent}: an `event`
58
+ * envelope whose metadata is complete and whose `data` decoded against its
59
+ * registered schema.
60
+ */
61
+ export declare const decodeEvent: <TData = unknown>(body: unknown) => Effect.Effect<DomainEvent<TData>, ProtocolFailure>;
62
+ /**
63
+ * Encodes an envelope for the wire: its `data` through the registered schema,
64
+ * after checking what the registration requires of `meta` — a version on a
65
+ * versioned message, an audience on an event that needs one. A publisher learns
66
+ * here, at the write, that a message would be unreadable or undeliverable.
67
+ */
68
+ export declare const encodeEnvelope: <TData>(envelope: EntifixEnvelope<TData>) => Effect.Effect<EntifixEnvelope, ProtocolFailure>;
69
+ /** Frames a {@link DomainEvent} as an `event` envelope and encodes it. */
70
+ export declare const encodeEvent: <TData>(event: DomainEvent<TData>) => Effect.Effect<EventEnvelope, ProtocolFailure>;
71
+ /** Who may receive a message: one organization, one party, or one flow's holder. */
72
+ export interface AudienceRecipient {
73
+ readonly organizationId?: string;
74
+ readonly partyId?: string;
75
+ /** The SHA-256 digest of a flow capability the recipient presented. */
76
+ readonly flowDigests?: readonly string[];
77
+ }
78
+ /**
79
+ * Whether `recipient` is in the message's audience.
80
+ *
81
+ * ⚠️ Fails closed: a message with no audience, or an empty one, admits nobody.
82
+ * A stream that broadcast what nobody declared a recipient for would leak the
83
+ * first event someone forgot to address.
84
+ */
85
+ export declare const audienceAdmits: (audience: readonly AudienceEntry[] | undefined, recipient: AudienceRecipient) => boolean;
86
+ /** The `data` of an entity-change event, as a schema. */
87
+ export declare const EntityChangeEventSchema: Schema.Struct<{
88
+ readonly entity: Schema.String;
89
+ readonly change: Schema.Literals<readonly ["created", "updated", "deleted"]>;
90
+ readonly id: Schema.Union<readonly [Schema.String, Schema.Number]>;
91
+ }>;
92
+ /**
93
+ * The one shape the browser's entity-change channel accepts: an `event`
94
+ * envelope with complete `meta.event` and an entity change in `data`.
95
+ */
96
+ export declare const EntityChangeEnvelope: Schema.Struct<{
97
+ readonly meta: Schema.StructWithRest<Schema.Struct<{
98
+ type: Schema.Literal<"event">;
99
+ event: Schema.StructWithRest<Schema.Struct<{
100
+ name: Schema.NonEmptyString;
101
+ id: Schema.NonEmptyString;
102
+ source: Schema.NonEmptyString;
103
+ at: Schema.NonEmptyString;
104
+ correlationId: Schema.optional<Schema.String>;
105
+ aggregate: Schema.optional<Schema.Struct<{
106
+ readonly type: Schema.String;
107
+ readonly id: Schema.String;
108
+ }>>;
109
+ version: Schema.optional<Schema.Int>;
110
+ audience: Schema.optional<Schema.$Array<Schema.Struct<{
111
+ readonly kind: Schema.Literals<readonly ["organization", "party", "flow"]>;
112
+ readonly id: Schema.String;
113
+ readonly digest: Schema.optional<Schema.String>;
114
+ }>>>;
115
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
116
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>;
117
+ readonly data: Schema.Struct<{
118
+ readonly entity: Schema.String;
119
+ readonly change: Schema.Literals<readonly ["created", "updated", "deleted"]>;
120
+ readonly id: Schema.Union<readonly [Schema.String, Schema.Number]>;
121
+ }>;
122
+ }>;
123
+ //# sourceMappingURL=codec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/envelope/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAExC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAOxD,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,eAAe,EAEf,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,sGAGhE,CAAC;AAyCL;;;;GAIG;AACH,eAAO,MAAM,QAAQ;qBACX,CAAC,EAAE,CAAC,QAAQ,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAE9B,CAAC;AA6CX;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,GACzB,MAAM,OAAO,EACb,WAAW,MAAM,KAChB,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,eAAe,CA6B7C,CAAC;AAEL;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,KAAK,GAAG,OAAO,EACzC,MAAM,OAAO,KACZ,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,eAAe,CAI/C,CAAC;AAEN;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,KAAK,EAClC,UAAU,eAAe,CAAC,KAAK,CAAC,KAC/B,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,eAAe,CAiB7C,CAAC;AAEL,0EAA0E;AAC1E,eAAO,MAAM,WAAW,GAAI,KAAK,EAC/B,OAAO,WAAW,CAAC,KAAK,CAAC,KACxB,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,eAAe,CAM9C,CAAC;AAEF,oFAAoF;AACpF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,uEAAuE;IACvE,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1C;AAED;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GACzB,UAAU,SAAS,aAAa,EAAE,GAAG,SAAS,EAC9C,WAAW,iBAAiB,KAC3B,OAaC,CAAC;AAoCL,yDAAyD;AACzD,eAAO,MAAM,uBAAuB;;;;EAIlC,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;EAM/B,CAAC"}
@@ -0,0 +1,203 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ import { _ as _object_without_properties_loose } from "@swc/helpers/_/_object_without_properties_loose";
3
+ import { Effect, Schema } from 'effect';
4
+ import { ProtocolFailure } from '../failure/generic.js';
5
+ import { lookupEvent, lookupMessage, registerMessage } from './registry.js';
6
+ /**
7
+ * A struct that keeps members it does not name: a newer peer's field is not
8
+ * ours to drop. What a registered message schema should usually be, since a
9
+ * plain `Schema.Struct` strips every unknown key on decode.
10
+ */ export const openStruct = (fields)=>Schema.StructWithRest(Schema.Struct(fields), [
11
+ Schema.Record(Schema.String, Schema.Unknown)
12
+ ]);
13
+ const AudienceEntrySchema = Schema.Struct({
14
+ kind: Schema.Literals([
15
+ 'organization',
16
+ 'party',
17
+ 'flow'
18
+ ]),
19
+ id: Schema.String,
20
+ digest: Schema.optional(Schema.String)
21
+ });
22
+ const EventMetaSchema = openStruct({
23
+ name: Schema.NonEmptyString,
24
+ id: Schema.NonEmptyString,
25
+ source: Schema.NonEmptyString,
26
+ at: Schema.NonEmptyString,
27
+ correlationId: Schema.optional(Schema.String),
28
+ aggregate: Schema.optional(Schema.Struct({
29
+ type: Schema.String,
30
+ id: Schema.String
31
+ })),
32
+ version: Schema.optional(Schema.Int),
33
+ audience: Schema.optional(Schema.Array(AudienceEntrySchema))
34
+ });
35
+ const LinkSchema = Schema.Struct({
36
+ rel: Schema.String,
37
+ href: Schema.String,
38
+ method: Schema.optional(Schema.Literals([
39
+ 'GET',
40
+ 'POST',
41
+ 'PUT',
42
+ 'PATCH',
43
+ 'DELETE'
44
+ ]))
45
+ });
46
+ const MetaSchema = openStruct({
47
+ type: Schema.NonEmptyString,
48
+ entity: Schema.optional(Schema.String),
49
+ links: Schema.optional(Schema.mutable(Schema.Array(LinkSchema))),
50
+ event: Schema.optional(EventMetaSchema)
51
+ });
52
+ const FrameSchema = Schema.Struct({
53
+ meta: MetaSchema,
54
+ data: Schema.Unknown
55
+ });
56
+ /**
57
+ * The envelope frame around one `data` schema — for a reader that knows the
58
+ * one shape it accepts, such as a channel that only ever carries entity
59
+ * changes, and so needs no registry lookup.
60
+ */ export const Envelope = {
61
+ codec: (data)=>Schema.Struct({
62
+ meta: MetaSchema,
63
+ data
64
+ })
65
+ };
66
+ const protocol = (reason)=>new ProtocolFailure({
67
+ reason
68
+ });
69
+ const describe = (error)=>error.message;
70
+ /** The registration a frame names: its `meta.type`, or its event name. */ const registrationFor = (meta)=>{
71
+ var _lookupMessage;
72
+ if (meta.type === 'event') {
73
+ var _lookupEvent;
74
+ if (meta.event === undefined) return "an 'event' envelope carried no meta.event";
75
+ return (_lookupEvent = lookupEvent(meta.event.name)) != null ? _lookupEvent : `no schema is registered for event '${meta.event.name}'`;
76
+ }
77
+ return (_lookupMessage = lookupMessage(meta.type)) != null ? _lookupMessage : `no schema is registered for message type '${meta.type}'`;
78
+ };
79
+ const checkRequirements = (registered, event, direction)=>{
80
+ if (registered.versioned && ((event == null ? void 0 : event.version) === undefined || event.aggregate === undefined)) return `'${registered.name}' describes an aggregate version and carried no aggregate or no version`;
81
+ if (direction === 'encode' && registered.kind === 'event' && registered.audience === 'required' && ((event == null ? void 0 : event.audience) === undefined || event.audience.length === 0)) return `'${registered.name}' must name its audience; an empty one reaches nobody`;
82
+ return undefined;
83
+ };
84
+ /**
85
+ * Decodes an arbitrary body into an envelope whose `data` has been decoded
86
+ * against the schema registered for it.
87
+ *
88
+ * Nothing is cast: a body that is not an envelope, names a type nothing
89
+ * registered, or carries `data` its schema refuses fails with a
90
+ * {@link ProtocolFailure} — poison on a bus, a dropped frame in a browser, a
91
+ * typed failure at an HTTP client. `expected` narrows the accepted `meta.type`.
92
+ */ export const decodeEnvelope = (body, expected)=>Effect.gen(function*() {
93
+ const frame = yield* Schema.decodeUnknownEffect(FrameSchema)(body).pipe(Effect.mapError((error)=>protocol(`the body is not an envelope: ${describe(error)}`)));
94
+ if (expected !== undefined && frame.meta.type !== expected) return yield* Effect.fail(protocol(`expected an envelope of type '${expected}' but got '${frame.meta.type}'`));
95
+ const registered = registrationFor(frame.meta);
96
+ if (typeof registered === 'string') return yield* Effect.fail(protocol(registered));
97
+ const meta = frame.meta;
98
+ const unmet = checkRequirements(registered, meta.event, 'decode');
99
+ if (unmet !== undefined) return yield* Effect.fail(protocol(unmet));
100
+ const data = yield* Schema.decodeUnknownEffect(registered.schema)(frame.data).pipe(Effect.mapError((error)=>protocol(`the data of '${registered.name}' does not decode: ${describe(error)}`)));
101
+ return {
102
+ meta,
103
+ data
104
+ };
105
+ });
106
+ /**
107
+ * Decodes a bus or stream message into a {@link DomainEvent}: an `event`
108
+ * envelope whose metadata is complete and whose `data` decoded against its
109
+ * registered schema.
110
+ */ export const decodeEvent = (body)=>Effect.map(decodeEnvelope(body, 'event'), (envelope)=>_extends({}, envelope.meta.event, {
111
+ data: envelope.data
112
+ }));
113
+ /**
114
+ * Encodes an envelope for the wire: its `data` through the registered schema,
115
+ * after checking what the registration requires of `meta` — a version on a
116
+ * versioned message, an audience on an event that needs one. A publisher learns
117
+ * here, at the write, that a message would be unreadable or undeliverable.
118
+ */ export const encodeEnvelope = (envelope)=>Effect.gen(function*() {
119
+ const registered = registrationFor(envelope.meta);
120
+ if (typeof registered === 'string') return yield* Effect.fail(protocol(registered));
121
+ const unmet = checkRequirements(registered, envelope.meta.event, 'encode');
122
+ if (unmet !== undefined) return yield* Effect.fail(protocol(unmet));
123
+ const data = yield* Schema.encodeUnknownEffect(registered.schema)(envelope.data).pipe(Effect.mapError((error)=>protocol(`the data of '${registered.name}' does not encode: ${describe(error)}`)));
124
+ return {
125
+ meta: envelope.meta,
126
+ data
127
+ };
128
+ });
129
+ /** Frames a {@link DomainEvent} as an `event` envelope and encodes it. */ export const encodeEvent = (event)=>{
130
+ const { data } = event, eventMeta = _object_without_properties_loose(event, [
131
+ "data"
132
+ ]);
133
+ return encodeEnvelope({
134
+ meta: {
135
+ type: 'event',
136
+ event: eventMeta
137
+ },
138
+ data
139
+ });
140
+ };
141
+ /**
142
+ * Whether `recipient` is in the message's audience.
143
+ *
144
+ * ⚠️ Fails closed: a message with no audience, or an empty one, admits nobody.
145
+ * A stream that broadcast what nobody declared a recipient for would leak the
146
+ * first event someone forgot to address.
147
+ */ export const audienceAdmits = (audience, recipient)=>(audience != null ? audience : []).some((entry)=>{
148
+ switch(entry.kind){
149
+ case 'organization':
150
+ return entry.id === recipient.organizationId;
151
+ case 'party':
152
+ return entry.id === recipient.partyId;
153
+ case 'flow':
154
+ var _recipient_flowDigests;
155
+ return entry.digest !== undefined && ((_recipient_flowDigests = recipient.flowDigests) != null ? _recipient_flowDigests : []).includes(entry.digest);
156
+ }
157
+ });
158
+ // What core owns, and therefore registers. Every other shape is registered by
159
+ // the package that owns it.
160
+ const SerializedEntitySchema = Schema.Record(Schema.String, Schema.Unknown);
161
+ registerMessage('entity', SerializedEntitySchema);
162
+ registerMessage('entityCollection', Schema.Array(SerializedEntitySchema));
163
+ registerMessage('entityPage', openStruct({
164
+ items: Schema.Array(SerializedEntitySchema),
165
+ total: Schema.Number,
166
+ request: Schema.optionalKey(Schema.Unknown)
167
+ }));
168
+ registerMessage('entityMetadata', openStruct({
169
+ actions: Schema.Array(Schema.Unknown),
170
+ useCases: Schema.Array(Schema.Unknown)
171
+ }));
172
+ registerMessage('entityFacets', Schema.Record(Schema.String, Schema.Array(Schema.Struct({
173
+ value: Schema.Union([
174
+ Schema.String,
175
+ Schema.Number,
176
+ Schema.Boolean
177
+ ]),
178
+ count: Schema.Number
179
+ }))));
180
+ /** The `data` of an entity-change event, as a schema. */ export const EntityChangeEventSchema = Schema.Struct({
181
+ entity: Schema.String,
182
+ change: Schema.Literals([
183
+ 'created',
184
+ 'updated',
185
+ 'deleted'
186
+ ]),
187
+ id: Schema.Union([
188
+ Schema.String,
189
+ Schema.Number
190
+ ])
191
+ });
192
+ /**
193
+ * The one shape the browser's entity-change channel accepts: an `event`
194
+ * envelope with complete `meta.event` and an entity change in `data`.
195
+ */ export const EntityChangeEnvelope = Schema.Struct({
196
+ meta: openStruct({
197
+ type: Schema.Literal('event'),
198
+ event: EventMetaSchema
199
+ }),
200
+ data: EntityChangeEventSchema
201
+ });
202
+
203
+ //# sourceMappingURL=codec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/envelope/codec.ts"],"sourcesContent":["import { Effect, Schema } from 'effect';\n\nimport { ProtocolFailure } from '../failure/generic.js';\nimport {\n lookupEvent,\n lookupMessage,\n type RegisteredMessage,\n registerMessage,\n} from './registry.js';\nimport type {\n AudienceEntry,\n DomainEvent,\n EntifixEnvelope,\n EntifixEventMeta,\n EventEnvelope,\n} from './types.js';\n\n/**\n * A struct that keeps members it does not name: a newer peer's field is not\n * ours to drop. What a registered message schema should usually be, since a\n * plain `Schema.Struct` strips every unknown key on decode.\n */\nexport const openStruct = <S extends Schema.Struct.Fields>(fields: S) =>\n Schema.StructWithRest(Schema.Struct(fields), [\n Schema.Record(Schema.String, Schema.Unknown),\n ]);\n\nconst AudienceEntrySchema = Schema.Struct({\n kind: Schema.Literals(['organization', 'party', 'flow']),\n id: Schema.String,\n digest: Schema.optional(Schema.String),\n});\n\nconst EventMetaSchema = openStruct({\n name: Schema.NonEmptyString,\n id: Schema.NonEmptyString,\n source: Schema.NonEmptyString,\n at: Schema.NonEmptyString,\n correlationId: Schema.optional(Schema.String),\n aggregate: Schema.optional(\n Schema.Struct({ type: Schema.String, id: Schema.String }),\n ),\n version: Schema.optional(Schema.Int),\n audience: Schema.optional(Schema.Array(AudienceEntrySchema)),\n});\n\nconst LinkSchema = Schema.Struct({\n rel: Schema.String,\n href: Schema.String,\n method: Schema.optional(\n Schema.Literals(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']),\n ),\n});\n\nconst MetaSchema = openStruct({\n type: Schema.NonEmptyString,\n entity: Schema.optional(Schema.String),\n links: Schema.optional(Schema.mutable(Schema.Array(LinkSchema))),\n event: Schema.optional(EventMetaSchema),\n});\n\nconst FrameSchema = Schema.Struct({\n meta: MetaSchema,\n data: Schema.Unknown,\n});\n\n/**\n * The envelope frame around one `data` schema — for a reader that knows the\n * one shape it accepts, such as a channel that only ever carries entity\n * changes, and so needs no registry lookup.\n */\nexport const Envelope = {\n codec: <A, I>(data: Schema.Codec<A, I>) =>\n Schema.Struct({ meta: MetaSchema, data }),\n} as const;\n\nconst protocol = (reason: string) => new ProtocolFailure({ reason });\n\nconst describe = (error: { readonly message: string }): string => error.message;\n\n/** The registration a frame names: its `meta.type`, or its event name. */\nconst registrationFor = (meta: {\n readonly type: string;\n readonly event?: { readonly name: string } | undefined;\n}): RegisteredMessage | string => {\n if (meta.type === 'event') {\n if (meta.event === undefined)\n return \"an 'event' envelope carried no meta.event\";\n return (\n lookupEvent(meta.event.name) ??\n `no schema is registered for event '${meta.event.name}'`\n );\n }\n return (\n lookupMessage(meta.type) ??\n `no schema is registered for message type '${meta.type}'`\n );\n};\n\nconst checkRequirements = (\n registered: RegisteredMessage,\n event: EntifixEventMeta | undefined,\n direction: 'decode' | 'encode',\n): string | undefined => {\n if (\n registered.versioned &&\n (event?.version === undefined || event.aggregate === undefined)\n )\n return `'${registered.name}' describes an aggregate version and carried no aggregate or no version`;\n if (\n direction === 'encode' &&\n registered.kind === 'event' &&\n registered.audience === 'required' &&\n (event?.audience === undefined || event.audience.length === 0)\n )\n return `'${registered.name}' must name its audience; an empty one reaches nobody`;\n return undefined;\n};\n\n/**\n * Decodes an arbitrary body into an envelope whose `data` has been decoded\n * against the schema registered for it.\n *\n * Nothing is cast: a body that is not an envelope, names a type nothing\n * registered, or carries `data` its schema refuses fails with a\n * {@link ProtocolFailure} — poison on a bus, a dropped frame in a browser, a\n * typed failure at an HTTP client. `expected` narrows the accepted `meta.type`.\n */\nexport const decodeEnvelope = (\n body: unknown,\n expected?: string,\n): Effect.Effect<EntifixEnvelope, ProtocolFailure> =>\n Effect.gen(function* () {\n const frame = yield* Schema.decodeUnknownEffect(FrameSchema)(body).pipe(\n Effect.mapError(error =>\n protocol(`the body is not an envelope: ${describe(error)}`),\n ),\n );\n if (expected !== undefined && frame.meta.type !== expected)\n return yield* Effect.fail(\n protocol(\n `expected an envelope of type '${expected}' but got '${frame.meta.type}'`,\n ),\n );\n const registered = registrationFor(frame.meta);\n if (typeof registered === 'string')\n return yield* Effect.fail(protocol(registered));\n const meta: EntifixEnvelope['meta'] = frame.meta;\n const unmet = checkRequirements(registered, meta.event, 'decode');\n if (unmet !== undefined) return yield* Effect.fail(protocol(unmet));\n const data = yield* Schema.decodeUnknownEffect(registered.schema)(\n frame.data,\n ).pipe(\n Effect.mapError(error =>\n protocol(\n `the data of '${registered.name}' does not decode: ${describe(error)}`,\n ),\n ),\n );\n return { meta, data };\n });\n\n/**\n * Decodes a bus or stream message into a {@link DomainEvent}: an `event`\n * envelope whose metadata is complete and whose `data` decoded against its\n * registered schema.\n */\nexport const decodeEvent = <TData = unknown>(\n body: unknown,\n): Effect.Effect<DomainEvent<TData>, ProtocolFailure> =>\n Effect.map(decodeEnvelope(body, 'event'), envelope => ({\n ...(envelope.meta.event as EntifixEventMeta),\n data: envelope.data as TData,\n }));\n\n/**\n * Encodes an envelope for the wire: its `data` through the registered schema,\n * after checking what the registration requires of `meta` — a version on a\n * versioned message, an audience on an event that needs one. A publisher learns\n * here, at the write, that a message would be unreadable or undeliverable.\n */\nexport const encodeEnvelope = <TData>(\n envelope: EntifixEnvelope<TData>,\n): Effect.Effect<EntifixEnvelope, ProtocolFailure> =>\n Effect.gen(function* () {\n const registered = registrationFor(envelope.meta);\n if (typeof registered === 'string')\n return yield* Effect.fail(protocol(registered));\n const unmet = checkRequirements(registered, envelope.meta.event, 'encode');\n if (unmet !== undefined) return yield* Effect.fail(protocol(unmet));\n const data = yield* Schema.encodeUnknownEffect(registered.schema)(\n envelope.data,\n ).pipe(\n Effect.mapError(error =>\n protocol(\n `the data of '${registered.name}' does not encode: ${describe(error)}`,\n ),\n ),\n );\n return { meta: envelope.meta, data };\n });\n\n/** Frames a {@link DomainEvent} as an `event` envelope and encodes it. */\nexport const encodeEvent = <TData>(\n event: DomainEvent<TData>,\n): Effect.Effect<EventEnvelope, ProtocolFailure> => {\n const { data, ...eventMeta } = event;\n return encodeEnvelope({\n meta: { type: 'event', event: eventMeta },\n data,\n }) as Effect.Effect<EventEnvelope, ProtocolFailure>;\n};\n\n/** Who may receive a message: one organization, one party, or one flow's holder. */\nexport interface AudienceRecipient {\n readonly organizationId?: string;\n readonly partyId?: string;\n /** The SHA-256 digest of a flow capability the recipient presented. */\n readonly flowDigests?: readonly string[];\n}\n\n/**\n * Whether `recipient` is in the message's audience.\n *\n * ⚠️ Fails closed: a message with no audience, or an empty one, admits nobody.\n * A stream that broadcast what nobody declared a recipient for would leak the\n * first event someone forgot to address.\n */\nexport const audienceAdmits = (\n audience: readonly AudienceEntry[] | undefined,\n recipient: AudienceRecipient,\n): boolean =>\n (audience ?? []).some(entry => {\n switch (entry.kind) {\n case 'organization':\n return entry.id === recipient.organizationId;\n case 'party':\n return entry.id === recipient.partyId;\n case 'flow':\n return (\n entry.digest !== undefined &&\n (recipient.flowDigests ?? []).includes(entry.digest)\n );\n }\n });\n\n// What core owns, and therefore registers. Every other shape is registered by\n// the package that owns it.\nconst SerializedEntitySchema = Schema.Record(Schema.String, Schema.Unknown);\n\nregisterMessage('entity', SerializedEntitySchema);\nregisterMessage('entityCollection', Schema.Array(SerializedEntitySchema));\nregisterMessage(\n 'entityPage',\n openStruct({\n items: Schema.Array(SerializedEntitySchema),\n total: Schema.Number,\n request: Schema.optionalKey(Schema.Unknown),\n }),\n);\nregisterMessage(\n 'entityMetadata',\n openStruct({\n actions: Schema.Array(Schema.Unknown),\n useCases: Schema.Array(Schema.Unknown),\n }),\n);\nregisterMessage(\n 'entityFacets',\n Schema.Record(\n Schema.String,\n Schema.Array(\n Schema.Struct({\n value: Schema.Union([Schema.String, Schema.Number, Schema.Boolean]),\n count: Schema.Number,\n }),\n ),\n ),\n);\n\n/** The `data` of an entity-change event, as a schema. */\nexport const EntityChangeEventSchema = Schema.Struct({\n entity: Schema.String,\n change: Schema.Literals(['created', 'updated', 'deleted']),\n id: Schema.Union([Schema.String, Schema.Number]),\n});\n\n/**\n * The one shape the browser's entity-change channel accepts: an `event`\n * envelope with complete `meta.event` and an entity change in `data`.\n */\nexport const EntityChangeEnvelope = Schema.Struct({\n meta: openStruct({\n type: Schema.Literal('event'),\n event: EventMetaSchema,\n }),\n data: EntityChangeEventSchema,\n});\n"],"names":["Effect","Schema","ProtocolFailure","lookupEvent","lookupMessage","registerMessage","openStruct","fields","StructWithRest","Struct","Record","String","Unknown","AudienceEntrySchema","kind","Literals","id","digest","optional","EventMetaSchema","name","NonEmptyString","source","at","correlationId","aggregate","type","version","Int","audience","Array","LinkSchema","rel","href","method","MetaSchema","entity","links","mutable","event","FrameSchema","meta","data","Envelope","codec","protocol","reason","describe","error","message","registrationFor","undefined","checkRequirements","registered","direction","versioned","length","decodeEnvelope","body","expected","gen","frame","decodeUnknownEffect","pipe","mapError","fail","unmet","schema","decodeEvent","map","envelope","encodeEnvelope","encodeUnknownEffect","encodeEvent","eventMeta","audienceAdmits","recipient","some","entry","organizationId","partyId","flowDigests","includes","SerializedEntitySchema","items","total","Number","request","optionalKey","actions","useCases","value","Union","Boolean","count","EntityChangeEventSchema","change","EntityChangeEnvelope","Literal"],"mappings":";;AAAA,SAASA,MAAM,EAAEC,MAAM,QAAQ,SAAS;AAExC,SAASC,eAAe,QAAQ,wBAAwB;AACxD,SACEC,WAAW,EACXC,aAAa,EAEbC,eAAe,QACV,gBAAgB;AASvB;;;;CAIC,GACD,OAAO,MAAMC,aAAa,CAAiCC,SACzDN,OAAOO,cAAc,CAACP,OAAOQ,MAAM,CAACF,SAAS;QAC3CN,OAAOS,MAAM,CAACT,OAAOU,MAAM,EAAEV,OAAOW,OAAO;KAC5C,EAAE;AAEL,MAAMC,sBAAsBZ,OAAOQ,MAAM,CAAC;IACxCK,MAAMb,OAAOc,QAAQ,CAAC;QAAC;QAAgB;QAAS;KAAO;IACvDC,IAAIf,OAAOU,MAAM;IACjBM,QAAQhB,OAAOiB,QAAQ,CAACjB,OAAOU,MAAM;AACvC;AAEA,MAAMQ,kBAAkBb,WAAW;IACjCc,MAAMnB,OAAOoB,cAAc;IAC3BL,I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C7B,OAAOW,OAAO;IACpC8E,UAAUzF,OAAO6B,KAAK,CAAC7B,OAAOW,OAAO;AACvC;AAEFP,gBACE,gBACAJ,OAAOS,MAAM,CACXT,OAAOU,MAAM,EACbV,OAAO6B,KAAK,CACV7B,OAAOQ,MAAM,CAAC;IACZkF,OAAO1F,OAAO2F,KAAK,CAAC;QAAC3F,OAAOU,MAAM;QAAEV,OAAOqF,MAAM;QAAErF,OAAO4F,OAAO;KAAC;IAClEC,OAAO7F,OAAOqF,MAAM;AACtB;AAKN,uDAAuD,GACvD,OAAO,MAAMS,0BAA0B9F,OAAOQ,MAAM,CAAC;IACnD2B,QAAQnC,OAAOU,MAAM;IACrBqF,QAAQ/F,OAAOc,QAAQ,CAAC;QAAC;QAAW;QAAW;KAAU;IACzDC,IAAIf,OAAO2F,KAAK,CAAC;QAAC3F,OAAOU,MAAM;QAAEV,OAAOqF,MAAM;KAAC;AACjD,GAAG;AAEH;;;CAGC,GACD,OAAO,MAAMW,uBAAuBhG,OAAOQ,MAAM,CAAC;IAChDgC,MAAMnC,WAAW;QACfoB,MAAMzB,OAAOiG,OAAO,CAAC;QACrB3D,OAAOpB;IACT;IACAuB,MAAMqD;AACR,GAAG"}
@@ -1,5 +1,7 @@
1
+ export * from './codec.js';
1
2
  export * from './event-pattern.js';
2
3
  export * from './make-envelope.js';
3
4
  export * from './read-envelope.js';
5
+ export * from './registry.js';
4
6
  export * from './types.js';
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/envelope/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/envelope/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC"}
@@ -1,6 +1,8 @@
1
+ export * from './codec.js';
1
2
  export * from './event-pattern.js';
2
3
  export * from './make-envelope.js';
3
4
  export * from './read-envelope.js';
5
+ export * from './registry.js';
4
6
  export * from './types.js';
5
7
 
6
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/envelope/index.ts"],"sourcesContent":["export * from './event-pattern.js';\nexport * from './make-envelope.js';\nexport * from './read-envelope.js';\nexport * from './types.js';\n"],"names":[],"mappings":"AAAA,cAAc,qBAAqB;AACnC,cAAc,qBAAqB;AACnC,cAAc,qBAAqB;AACnC,cAAc,aAAa"}
1
+ {"version":3,"sources":["../../src/envelope/index.ts"],"sourcesContent":["export * from './codec.js';\nexport * from './event-pattern.js';\nexport * from './make-envelope.js';\nexport * from './read-envelope.js';\nexport * from './registry.js';\nexport * from './types.js';\n"],"names":[],"mappings":"AAAA,cAAc,aAAa;AAC3B,cAAc,qBAAqB;AACnC,cAAc,qBAAqB;AACnC,cAAc,qBAAqB;AACnC,cAAc,gBAAgB;AAC9B,cAAc,aAAa"}
@@ -2,19 +2,18 @@ import { Effect } from 'effect';
2
2
  import type { EntityMetadataDocument } from '../entity-definition/metadata/index.js';
3
3
  import { InvalidEnvelope } from '../failure/generic.js';
4
4
  import type { Entity, EntityConstructor } from '../types/Entity.js';
5
- import type { EntityFacetValue } from '../types/EntityFacets.js';
6
- import type { DomainEvent, EntifixEnvelope, EntifixEnvelopeType } from './types.js';
5
+ import type { EntifixEnvelope, EntifixEnvelopeType } from './types.js';
7
6
  /**
8
- * Structural check only — `meta.type` is validated separately so a mismatch
9
- * reports the expected/actual types rather than a generic "not an envelope".
10
- */
11
- export declare function isEntifixEnvelope(body: unknown): body is EntifixEnvelope;
12
- /**
13
- * Narrows an arbitrary body to an envelope of the expected `meta.type` without
14
- * requiring an entity constructor — for `command`/`transactionRecord` messages
15
- * whose `data` is not a serialized entity. `label` only sharpens error text.
7
+ * Decodes a body a **caller sent** — a request to this service — into an
8
+ * envelope of the expected type, its `data` decoded against the registered
9
+ * schema.
10
+ *
11
+ * The same decode as {@link decodeEnvelope}, failing with an
12
+ * {@link InvalidEnvelope} instead of a protocol failure: a malformed request is
13
+ * the sender's fault and answers `400`, where a peer's malformed *answer* is a
14
+ * `502`.
16
15
  */
17
- export declare function readEnvelope<TData>(body: unknown, expected: EntifixEnvelopeType, label?: string): Effect.Effect<EntifixEnvelope<TData>, InvalidEnvelope>;
16
+ export declare const decodeRequestEnvelope: (body: unknown, expected: EntifixEnvelopeType, label?: string) => Effect.Effect<EntifixEnvelope, InvalidEnvelope>;
18
17
  export declare const readEntityEnvelope: <TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>, body: unknown) => Effect.Effect<TEntity, import("../index.js").EntifixBuildError | InvalidEnvelope, never>;
19
18
  export declare const readEntityCollectionEnvelope: <TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>, body: unknown) => Effect.Effect<TEntity[], import("../index.js").EntifixBuildError | InvalidEnvelope, never>;
20
19
  export declare const readEntityPageEnvelope: <TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>, body: unknown) => Effect.Effect<{
@@ -25,31 +24,15 @@ export declare const readEntityPageEnvelope: <TEntity extends Entity>(entityCons
25
24
  /**
26
25
  * Reads a `$metadata` response back into its document.
27
26
  *
28
- * No deserialization step, and no defaulting of the members either: an envelope
29
- * whose `data` is missing a list would leave a form guessing whether "no
30
- * actions" meant "denied" or "malformed", so a broken payload fails loudly here
31
- * the way a half-populated entity does.
27
+ * No defaulting of the members: the registered schema refuses a document
28
+ * missing either list, so a form never has to guess whether "no actions" meant
29
+ * "denied" or "malformed".
32
30
  */
33
31
  export declare const readEntityMetadataEnvelope: <TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>, body: unknown) => Effect.Effect<EntityMetadataDocument, InvalidEnvelope, never>;
34
32
  /**
35
- * Reads a `$facets` response back into its counts, refusing a body whose lists
36
- * are not `{ value, count }` rows — a panel that rendered a malformed count
37
- * would show a number nobody computed.
38
- */
39
- export declare const readEntityFacetsEnvelope: <TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>, body: unknown) => Effect.Effect<Readonly<Record<string, readonly EntityFacetValue[]>>, InvalidEnvelope, never>;
40
- /**
41
- * Reads a bus message back into a {@link DomainEvent}.
42
- *
43
- * The metadata is validated rather than defaulted, and that is the point: a
44
- * message missing `id` cannot be deduplicated and a message missing `name`
45
- * cannot be routed, so both are failures a consumer must see rather than
46
- * absences it silently works around. It is the same call
47
- * {@link readEntityMetadataEnvelope} makes — a broken payload fails loudly
48
- * instead of arriving half-populated.
49
- *
50
- * Note this does not validate `data`. The transport has no idea what a
51
- * `catalog.published` payload should look like, and inventing an opinion here
52
- * is how the bus would start knowing about domains.
33
+ * Reads a `$facets` response back into its counts. The registered schema
34
+ * refuses a body whose lists are not `{ value, count }` rows — a panel that
35
+ * rendered a malformed count would show a number nobody computed.
53
36
  */
54
- export declare function readEventEnvelope<TData = unknown>(body: unknown): Effect.Effect<DomainEvent<TData>, InvalidEnvelope>;
37
+ export declare const readEntityFacetsEnvelope: <TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>, body: unknown) => Effect.Effect<Readonly<Record<string, readonly import("../index.js").EntityFacetValue[]>>, InvalidEnvelope, never>;
55
38
  //# sourceMappingURL=read-envelope.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"read-envelope.d.ts","sourceRoot":"","sources":["../../src/envelope/read-envelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAKrF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM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