@entifix/core 0.11.0 → 0.12.1

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 (36) hide show
  1. package/dist/endpoint/endpoint.d.ts +154 -0
  2. package/dist/endpoint/endpoint.d.ts.map +1 -0
  3. package/dist/endpoint/endpoint.js +61 -0
  4. package/dist/endpoint/endpoint.js.map +1 -0
  5. package/dist/endpoint/index.d.ts +2 -0
  6. package/dist/endpoint/index.d.ts.map +1 -0
  7. package/dist/endpoint/index.js +3 -0
  8. package/dist/endpoint/index.js.map +1 -0
  9. package/dist/entity-definition/decorators/use-case/use-case.d.ts.map +1 -1
  10. package/dist/entity-definition/decorators/use-case/use-case.js +2 -1
  11. package/dist/entity-definition/decorators/use-case/use-case.js.map +1 -1
  12. package/dist/entity-definition/helpers/entity-definition-helpers.d.ts +5 -0
  13. package/dist/entity-definition/helpers/entity-definition-helpers.d.ts.map +1 -1
  14. package/dist/entity-definition/helpers/entity-definition-helpers.js +10 -0
  15. package/dist/entity-definition/helpers/entity-definition-helpers.js.map +1 -1
  16. package/dist/entity-definition/meta-entities/meta-use-case/meta-use-case.d.ts +19 -0
  17. package/dist/entity-definition/meta-entities/meta-use-case/meta-use-case.d.ts.map +1 -1
  18. package/dist/entity-definition/meta-entities/meta-use-case/meta-use-case.js +3 -0
  19. package/dist/entity-definition/meta-entities/meta-use-case/meta-use-case.js.map +1 -1
  20. package/dist/envelope/read-envelope.d.ts +3 -3
  21. package/dist/envelope/read-envelope.d.ts.map +1 -1
  22. package/dist/envelope/read-envelope.js +10 -3
  23. package/dist/envelope/read-envelope.js.map +1 -1
  24. package/dist/index.d.ts +2 -0
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +2 -0
  27. package/dist/index.js.map +1 -1
  28. package/dist/use-case-runner/index.d.ts +2 -0
  29. package/dist/use-case-runner/index.d.ts.map +1 -0
  30. package/dist/use-case-runner/index.js +3 -0
  31. package/dist/use-case-runner/index.js.map +1 -0
  32. package/dist/use-case-runner/use-case-runner.d.ts +29 -0
  33. package/dist/use-case-runner/use-case-runner.d.ts.map +1 -0
  34. package/dist/use-case-runner/use-case-runner.js +10 -0
  35. package/dist/use-case-runner/use-case-runner.js.map +1 -0
  36. package/package.json +1 -1
@@ -0,0 +1,154 @@
1
+ import { type Effect, Schema } from 'effect';
2
+ import type { EntifixFailure, FailureClass, TechnicalCategory } from '../failure/failure.js';
3
+ import type { Entity, EntityConstructor } from '../types/Entity.js';
4
+ /**
5
+ * Who may call an endpoint, and with which credential
6
+ * ([ADR 0020](../../../../../docs/adr/0020-endpoints-are-descriptors-and-the-shell-builds-an-httpapi.md)).
7
+ * Exactly one per endpoint. The shell implements each kind once.
8
+ *
9
+ * - `public` — no credential.
10
+ * - `session` — a verified session, and nothing more.
11
+ * - `permission` — a session whose roles grant `permission`.
12
+ * - `organization` — the same, acting for the session's active organization.
13
+ * - `crossing` — a service crossing token and `permission`. With
14
+ * `organization: true` the caller names the organization, because the data's
15
+ * owner was handed to it rather than chosen.
16
+ * - `fleet` — the shared token one service of the fleet presents to another.
17
+ */
18
+ /** A permission as `<domain>:<entityKey>:<action>`. */
19
+ export type EndpointPermission = `${string}:${string}:${string}`;
20
+ export type EndpointGuard = {
21
+ readonly kind: 'public';
22
+ } | {
23
+ readonly kind: 'session';
24
+ } | {
25
+ readonly kind: 'permission';
26
+ readonly permission: EndpointPermission;
27
+ } | {
28
+ readonly kind: 'organization';
29
+ readonly permission: EndpointPermission;
30
+ } | {
31
+ readonly kind: 'crossing';
32
+ readonly permission: EndpointPermission;
33
+ readonly organization: boolean;
34
+ } | {
35
+ readonly kind: 'fleet';
36
+ };
37
+ export type EndpointGuardKind = EndpointGuard['kind'];
38
+ /**
39
+ * Which layer remembers an `Idempotency-Key`. One write is recorded by one
40
+ * layer, never both: `unit` when the handler writes through a unit of work,
41
+ * which claims the key in the same transaction as the write; `edge` when it
42
+ * does not, and the shell's idempotency store remembers the answer.
43
+ */
44
+ export type EndpointIdempotency = 'unit' | 'edge';
45
+ export type EndpointMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
46
+ /** A schema, or the fields of a struct — normalised to a schema when served. */
47
+ export type EndpointSchema = Schema.Top | Schema.Struct.Fields;
48
+ /** The schema an {@link EndpointSchema} stands for. */
49
+ export type SchemaOf<S> = S extends Schema.Top ? S : S extends Schema.Struct.Fields ? Schema.Struct<S> : never;
50
+ type TypeOf<S> = SchemaOf<S>['Type'];
51
+ /**
52
+ * An endpoint, described with Schema and nothing about HTTP beyond its method
53
+ * and path: no status, no content type, no annotation. A cell exports these;
54
+ * the shell turns them into an API.
55
+ */
56
+ export interface EndpointDescriptor<Name extends string = string, Method extends EndpointMethod = EndpointMethod, Path extends `/${string}` = `/${string}`, Params extends EndpointSchema | undefined = EndpointSchema | undefined, Query extends EndpointSchema | undefined = EndpointSchema | undefined, Payload extends EndpointSchema | undefined = EndpointSchema | undefined, Success extends Schema.Top = Schema.Top, Errors extends ReadonlyArray<FailureClass> = ReadonlyArray<FailureClass>, Guard extends EndpointGuard = EndpointGuard, Idempotency extends EndpointIdempotency | undefined = EndpointIdempotency | undefined, Headers extends EndpointSchema | undefined = EndpointSchema | undefined> {
57
+ readonly name: Name;
58
+ readonly method: Method;
59
+ readonly path: Path;
60
+ readonly params?: Params;
61
+ readonly query?: Query;
62
+ readonly payload?: Payload;
63
+ /**
64
+ * The request headers the handler reads, by lower-case name. Most endpoints
65
+ * declare none: a header an endpoint does not name is not its input.
66
+ */
67
+ readonly headers?: Headers;
68
+ readonly success: Success;
69
+ /**
70
+ * Every business failure the handler may answer with. Only failure classes:
71
+ * a refusal with no category does not compile. Technical failures are not
72
+ * listed — every endpoint may answer with one.
73
+ */
74
+ readonly errors: Errors;
75
+ readonly guard: Guard;
76
+ readonly idempotent?: Idempotency;
77
+ /** The `@useCase()` this endpoint serves, when it is a verb. */
78
+ readonly useCase?: string;
79
+ }
80
+ /** Any descriptor. */
81
+ export type AnyEndpoint = EndpointDescriptor<string, EndpointMethod, `/${string}`, EndpointSchema | undefined, EndpointSchema | undefined, EndpointSchema | undefined, Schema.Top, ReadonlyArray<FailureClass>, EndpointGuard, EndpointIdempotency | undefined, EndpointSchema | undefined>;
82
+ /**
83
+ * Declare one endpoint. The literal types of its name, path and schemas are
84
+ * kept, so a handler and a client are typed from it.
85
+ */
86
+ export declare const defineEndpoint: <const Name extends string, const Method extends EndpointMethod, const Path extends `/${string}`, Success extends Schema.Top, const Errors extends ReadonlyArray<FailureClass> = readonly [], Params extends EndpointSchema | undefined = undefined, Query extends EndpointSchema | undefined = undefined, Payload extends EndpointSchema | undefined = undefined, const Guard extends EndpointGuard = EndpointGuard, const Idempotency extends EndpointIdempotency | undefined = undefined, Headers extends EndpointSchema | undefined = undefined>(descriptor: EndpointDescriptor<Name, Method, Path, Params, Query, Payload, Success, Errors, Guard, Idempotency, Headers>) => EndpointDescriptor<Name, Method, Path, Params, Query, Payload, Success, Errors, Guard, Idempotency, Headers>;
87
+ /** Declare several endpoints, keeping each one's literal types. */
88
+ export declare const defineEndpoints: <const Endpoints extends ReadonlyArray<AnyEndpoint>>(...endpoints: Endpoints) => Endpoints;
89
+ /** A technical failure: a non-answer every endpoint may produce undeclared. */
90
+ export type TechnicalFailure = EntifixFailure<string, string, TechnicalCategory>;
91
+ /** The business failures a descriptor declares, as instances. */
92
+ export type DeclaredFailure<D> = D extends EndpointDescriptor<string, EndpointMethod, `/${string}`, EndpointSchema | undefined, EndpointSchema | undefined, EndpointSchema | undefined, Schema.Top, infer Errors, EndpointGuard, EndpointIdempotency | undefined> ? InstanceType<Errors[number]> : never;
93
+ /** What a handler receives: the decoded parts the descriptor declares. */
94
+ export type EndpointRequest<D> = D extends EndpointDescriptor<string, EndpointMethod, `/${string}`, infer Params, infer Query, infer Payload, Schema.Top, ReadonlyArray<FailureClass>, EndpointGuard, EndpointIdempotency | undefined, infer Headers> ? (Params extends EndpointSchema ? {
95
+ readonly params: TypeOf<Params>;
96
+ } : unknown) & (Query extends EndpointSchema ? {
97
+ readonly query: TypeOf<Query>;
98
+ } : unknown) & (Payload extends EndpointSchema ? {
99
+ readonly payload: TypeOf<Payload>;
100
+ } : unknown) & (Headers extends EndpointSchema ? {
101
+ readonly headers: TypeOf<Headers>;
102
+ } : unknown) : never;
103
+ /** What a handler answers with. */
104
+ export type EndpointSuccess<D> = D extends EndpointDescriptor<string, EndpointMethod, `/${string}`, EndpointSchema | undefined, EndpointSchema | undefined, EndpointSchema | undefined, infer Success, ReadonlyArray<FailureClass>, EndpointGuard, EndpointIdempotency | undefined> ? Success['Type'] : never;
105
+ /** A handler for `D`: a plain effect, with no transport in its type. */
106
+ export type EndpointHandler<D, R> = (request: EndpointRequest<D>) => Effect.Effect<EndpointSuccess<D>, DeclaredFailure<D> | TechnicalFailure, R>;
107
+ /** A descriptor paired with the handler that serves it. */
108
+ export interface Implemented<D extends AnyEndpoint = AnyEndpoint, R = unknown> {
109
+ readonly descriptor: D;
110
+ readonly handler: EndpointHandler<D, R>;
111
+ }
112
+ /**
113
+ * Pair a descriptor with its handler. A handler failing with a business
114
+ * failure the descriptor does not declare does not compile.
115
+ */
116
+ export declare const implement: <D extends AnyEndpoint, R>(descriptor: D, handler: EndpointHandler<D, R>) => Implemented<D, R>;
117
+ /**
118
+ * The entity's key as a literal, checked against `@entity({ key })` when the
119
+ * module loads, so a path built from it cannot name a key the entity does not
120
+ * carry.
121
+ */
122
+ export declare const entityKey: <T extends Entity, const K extends string>(entityConstructor: EntityConstructor<T>, key: K) => K;
123
+ /**
124
+ * A body an endpoint sends without describing it: whatever the handler
125
+ * answers, as its JSON — `Date`s as ISO strings, `undefined` members dropped,
126
+ * the way `JSON.stringify` writes it. For a record whose shape the entity
127
+ * describes rather than a schema, and for an opaque document such as an
128
+ * OpenAPI one. A body the endpoint can describe should be a schema instead.
129
+ */
130
+ export declare const JsonBody: Schema.Codec<unknown, unknown>;
131
+ /** The annotation a body schema carries when it is not JSON on the wire. */
132
+ export declare const BODY_ENCODING = "entifix/bodyEncoding";
133
+ /** How a payload travels when it is not decoded as JSON, and under which media type. */
134
+ export interface BodyEncoding {
135
+ readonly kind: 'text' | 'form';
136
+ readonly contentType: string;
137
+ }
138
+ /**
139
+ * A payload taken as the exact text that arrived, for an endpoint whose
140
+ * authentication is a signature over those bytes: a decoded object
141
+ * re-serialised is a different byte sequence, and the MAC would not verify.
142
+ * `contentType` is the media type the caller sends — a provider that signs a
143
+ * JSON body still sends `application/json`, and the bytes are what matter.
144
+ */
145
+ export declare const textBody: (contentType?: string) => Schema.String;
146
+ /**
147
+ * A form-encoded payload (`application/x-www-form-urlencoded`), for a caller
148
+ * a specification makes post one — an OpenID back-channel logout, say.
149
+ */
150
+ export declare const formBody: <const Fields extends Schema.Struct.Fields>(fields: Fields) => Schema.Struct<Fields>;
151
+ /** The wire encoding a payload schema declared, or `undefined` for JSON. */
152
+ export declare const bodyEncodingOf: (schema: Schema.Top) => BodyEncoding | undefined;
153
+ export {};
154
+ //# sourceMappingURL=endpoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../src/endpoint/endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,EAAwB,MAAM,QAAQ,CAAC;AAGnE,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEpE;;;;;;;;;;;;;GAaG;AACH,uDAAuD;AACvD,MAAM,MAAM,kBAAkB,GAAG,GAAG,MAAM,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;AAEjE,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GAC5B;IAAE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BAAyB,CAAC;AAEpD,wFAAwF;AACxF,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,oBAA0B,KAAG,MAAM,CAAC,MAGzD,CAAC;AAEL;;;GAGG;AACH,eAAO,MAAM,QAAQ,GAAI,KAAK,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,CAAC,MAAM,EAChE,QAAQ,MAAM,KACb,MAAM,CAAC,MAAM,CAAC,MAAM,CAMnB,CAAC;AAEL,4EAA4E;AAC5E,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,CAAC,GAAG,KAAG,YAAY,GAAG,SAGpC,CAAC"}
@@ -0,0 +1,61 @@
1
+ import { Schema, SchemaTransformation } from 'effect';
2
+ import { extractMetaEntity } from '../entity-definition/helpers/entity-definition-helpers.js';
3
+ /**
4
+ * Declare one endpoint. The literal types of its name, path and schemas are
5
+ * kept, so a handler and a client are typed from it.
6
+ */ export const defineEndpoint = (descriptor)=>descriptor;
7
+ /** Declare several endpoints, keeping each one's literal types. */ export const defineEndpoints = (...endpoints)=>endpoints;
8
+ /**
9
+ * Pair a descriptor with its handler. A handler failing with a business
10
+ * failure the descriptor does not declare does not compile.
11
+ */ export const implement = (descriptor, handler)=>({
12
+ descriptor,
13
+ handler
14
+ });
15
+ /**
16
+ * The entity's key as a literal, checked against `@entity({ key })` when the
17
+ * module loads, so a path built from it cannot name a key the entity does not
18
+ * carry.
19
+ */ export const entityKey = (entityConstructor, key)=>{
20
+ const declared = extractMetaEntity(entityConstructor).key;
21
+ if (declared !== key) throw new Error(`entityKey(${entityConstructor.name}, '${key}') does not match ` + `@entity({ key: ${declared === undefined ? 'undefined' : `'${declared}'`} })`);
22
+ return key;
23
+ };
24
+ /**
25
+ * A body an endpoint sends without describing it: whatever the handler
26
+ * answers, as its JSON — `Date`s as ISO strings, `undefined` members dropped,
27
+ * the way `JSON.stringify` writes it. For a record whose shape the entity
28
+ * describes rather than a schema, and for an opaque document such as an
29
+ * OpenAPI one. A body the endpoint can describe should be a schema instead.
30
+ */ export const JsonBody = Schema.Unknown.pipe(Schema.decodeTo(Schema.Unknown, SchemaTransformation.transform({
31
+ decode: (value)=>value,
32
+ encode: (value)=>value === undefined ? null : JSON.parse(JSON.stringify(value))
33
+ })));
34
+ /** The annotation a body schema carries when it is not JSON on the wire. */ export const BODY_ENCODING = 'entifix/bodyEncoding';
35
+ /**
36
+ * A payload taken as the exact text that arrived, for an endpoint whose
37
+ * authentication is a signature over those bytes: a decoded object
38
+ * re-serialised is a different byte sequence, and the MAC would not verify.
39
+ * `contentType` is the media type the caller sends — a provider that signs a
40
+ * JSON body still sends `application/json`, and the bytes are what matter.
41
+ */ export const textBody = (contentType = 'text/plain')=>Schema.String.annotate({
42
+ [BODY_ENCODING]: {
43
+ kind: 'text',
44
+ contentType
45
+ }
46
+ });
47
+ /**
48
+ * A form-encoded payload (`application/x-www-form-urlencoded`), for a caller
49
+ * a specification makes post one — an OpenID back-channel logout, say.
50
+ */ export const formBody = (fields)=>Schema.Struct(fields).annotate({
51
+ [BODY_ENCODING]: {
52
+ kind: 'form',
53
+ contentType: 'application/x-www-form-urlencoded'
54
+ }
55
+ });
56
+ /** The wire encoding a payload schema declared, or `undefined` for JSON. */ export const bodyEncodingOf = (schema)=>{
57
+ var _schema_ast_annotations;
58
+ return (_schema_ast_annotations = schema.ast.annotations) == null ? void 0 : _schema_ast_annotations[BODY_ENCODING];
59
+ };
60
+
61
+ //# sourceMappingURL=endpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/endpoint/endpoint.ts"],"sourcesContent":["import { type Effect, Schema, SchemaTransformation } from 'effect';\n\nimport { extractMetaEntity } from '../entity-definition/helpers/entity-definition-helpers.js';\nimport type {\n EntifixFailure,\n FailureClass,\n TechnicalCategory,\n} from '../failure/failure.js';\nimport type { Entity, EntityConstructor } from '../types/Entity.js';\n\n/**\n * Who may call an endpoint, and with which credential\n * ([ADR 0020](../../../../../docs/adr/0020-endpoints-are-descriptors-and-the-shell-builds-an-httpapi.md)).\n * Exactly one per endpoint. The shell implements each kind once.\n *\n * - `public` — no credential.\n * - `session` — a verified session, and nothing more.\n * - `permission` — a session whose roles grant `permission`.\n * - `organization` — the same, acting for the session's active organization.\n * - `crossing` — a service crossing token and `permission`. With\n * `organization: true` the caller names the organization, because the data's\n * owner was handed to it rather than chosen.\n * - `fleet` — the shared token one service of the fleet presents to another.\n */\n/** A permission as `<domain>:<entityKey>:<action>`. */\nexport type EndpointPermission = `${string}:${string}:${string}`;\n\nexport type EndpointGuard =\n | { readonly kind: 'public' }\n | { readonly kind: 'session' }\n | { readonly kind: 'permission'; readonly permission: EndpointPermission }\n | { readonly kind: 'organization'; readonly permission: EndpointPermission }\n | {\n readonly kind: 'crossing';\n readonly permission: EndpointPermission;\n readonly organization: boolean;\n }\n | { readonly kind: 'fleet' };\n\nexport type EndpointGuardKind = EndpointGuard['kind'];\n\n/**\n * Which layer remembers an `Idempotency-Key`. One write is recorded by one\n * layer, never both: `unit` when the handler writes through a unit of work,\n * which claims the key in the same transaction as the write; `edge` when it\n * does not, and the shell's idempotency store remembers the answer.\n */\nexport type EndpointIdempotency = 'unit' | 'edge';\n\nexport type EndpointMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n\n/** A schema, or the fields of a struct — normalised to a schema when served. */\nexport type EndpointSchema = Schema.Top | Schema.Struct.Fields;\n\n/** The schema an {@link EndpointSchema} stands for. */\nexport type SchemaOf<S> = S extends Schema.Top\n ? S\n : S extends Schema.Struct.Fields\n ? Schema.Struct<S>\n : never;\n\ntype TypeOf<S> = SchemaOf<S>['Type'];\n\n/**\n * An endpoint, described with Schema and nothing about HTTP beyond its method\n * and path: no status, no content type, no annotation. A cell exports these;\n * the shell turns them into an API.\n */\nexport interface EndpointDescriptor<\n Name extends string = string,\n Method extends EndpointMethod = EndpointMethod,\n Path extends `/${string}` = `/${string}`,\n Params extends EndpointSchema | undefined = EndpointSchema | undefined,\n Query extends EndpointSchema | undefined = EndpointSchema | undefined,\n Payload extends EndpointSchema | undefined = EndpointSchema | undefined,\n Success extends Schema.Top = Schema.Top,\n Errors extends ReadonlyArray<FailureClass> = ReadonlyArray<FailureClass>,\n Guard extends EndpointGuard = EndpointGuard,\n Idempotency extends EndpointIdempotency | undefined =\n EndpointIdempotency | undefined,\n Headers extends EndpointSchema | undefined = EndpointSchema | undefined,\n> {\n readonly name: Name;\n readonly method: Method;\n readonly path: Path;\n readonly params?: Params;\n readonly query?: Query;\n readonly payload?: Payload;\n /**\n * The request headers the handler reads, by lower-case name. Most endpoints\n * declare none: a header an endpoint does not name is not its input.\n */\n readonly headers?: Headers;\n readonly success: Success;\n /**\n * Every business failure the handler may answer with. Only failure classes:\n * a refusal with no category does not compile. Technical failures are not\n * listed — every endpoint may answer with one.\n */\n readonly errors: Errors;\n readonly guard: Guard;\n readonly idempotent?: Idempotency;\n /** The `@useCase()` this endpoint serves, when it is a verb. */\n readonly useCase?: string;\n}\n\n/** Any descriptor. */\nexport type AnyEndpoint = EndpointDescriptor<\n string,\n EndpointMethod,\n `/${string}`,\n EndpointSchema | undefined,\n EndpointSchema | undefined,\n EndpointSchema | undefined,\n Schema.Top,\n ReadonlyArray<FailureClass>,\n EndpointGuard,\n EndpointIdempotency | undefined,\n EndpointSchema | undefined\n>;\n\n/**\n * Declare one endpoint. The literal types of its name, path and schemas are\n * kept, so a handler and a client are typed from it.\n */\nexport const defineEndpoint = <\n const Name extends string,\n const Method extends EndpointMethod,\n const Path extends `/${string}`,\n Success extends Schema.Top,\n const Errors extends ReadonlyArray<FailureClass> = readonly [],\n Params extends EndpointSchema | undefined = undefined,\n Query extends EndpointSchema | undefined = undefined,\n Payload extends EndpointSchema | undefined = undefined,\n const Guard extends EndpointGuard = EndpointGuard,\n const Idempotency extends EndpointIdempotency | undefined = undefined,\n Headers extends EndpointSchema | undefined = undefined,\n>(\n descriptor: EndpointDescriptor<\n Name,\n Method,\n Path,\n Params,\n Query,\n Payload,\n Success,\n Errors,\n Guard,\n Idempotency,\n Headers\n >,\n): EndpointDescriptor<\n Name,\n Method,\n Path,\n Params,\n Query,\n Payload,\n Success,\n Errors,\n Guard,\n Idempotency,\n Headers\n> => descriptor;\n\n/** Declare several endpoints, keeping each one's literal types. */\nexport const defineEndpoints = <\n const Endpoints extends ReadonlyArray<AnyEndpoint>,\n>(\n ...endpoints: Endpoints\n): Endpoints => endpoints;\n\n/** A technical failure: a non-answer every endpoint may produce undeclared. */\nexport type TechnicalFailure = EntifixFailure<\n string,\n string,\n TechnicalCategory\n>;\n\n/** The business failures a descriptor declares, as instances. */\nexport type DeclaredFailure<D> =\n D extends EndpointDescriptor<\n string,\n EndpointMethod,\n `/${string}`,\n EndpointSchema | undefined,\n EndpointSchema | undefined,\n EndpointSchema | undefined,\n Schema.Top,\n infer Errors,\n EndpointGuard,\n EndpointIdempotency | undefined\n >\n ? InstanceType<Errors[number]>\n : never;\n\n/** What a handler receives: the decoded parts the descriptor declares. */\nexport type EndpointRequest<D> =\n D extends EndpointDescriptor<\n string,\n EndpointMethod,\n `/${string}`,\n infer Params,\n infer Query,\n infer Payload,\n Schema.Top,\n ReadonlyArray<FailureClass>,\n EndpointGuard,\n EndpointIdempotency | undefined,\n infer Headers\n >\n ? (Params extends EndpointSchema\n ? { readonly params: TypeOf<Params> }\n : unknown) &\n (Query extends EndpointSchema\n ? { readonly query: TypeOf<Query> }\n : unknown) &\n (Payload extends EndpointSchema\n ? { readonly payload: TypeOf<Payload> }\n : unknown) &\n (Headers extends EndpointSchema\n ? { readonly headers: TypeOf<Headers> }\n : unknown)\n : never;\n\n/** What a handler answers with. */\nexport type EndpointSuccess<D> =\n D extends EndpointDescriptor<\n string,\n EndpointMethod,\n `/${string}`,\n EndpointSchema | undefined,\n EndpointSchema | undefined,\n EndpointSchema | undefined,\n infer Success,\n ReadonlyArray<FailureClass>,\n EndpointGuard,\n EndpointIdempotency | undefined\n >\n ? Success['Type']\n : never;\n\n/** A handler for `D`: a plain effect, with no transport in its type. */\nexport type EndpointHandler<D, R> = (\n request: EndpointRequest<D>,\n) => Effect.Effect<\n EndpointSuccess<D>,\n DeclaredFailure<D> | TechnicalFailure,\n R\n>;\n\n/** A descriptor paired with the handler that serves it. */\nexport interface Implemented<D extends AnyEndpoint = AnyEndpoint, R = unknown> {\n readonly descriptor: D;\n readonly handler: EndpointHandler<D, R>;\n}\n\n/**\n * Pair a descriptor with its handler. A handler failing with a business\n * failure the descriptor does not declare does not compile.\n */\nexport const implement = <D extends AnyEndpoint, R>(\n descriptor: D,\n handler: EndpointHandler<D, R>,\n): Implemented<D, R> => ({ descriptor, handler });\n\n/**\n * The entity's key as a literal, checked against `@entity({ key })` when the\n * module loads, so a path built from it cannot name a key the entity does not\n * carry.\n */\nexport const entityKey = <T extends Entity, const K extends string>(\n entityConstructor: EntityConstructor<T>,\n key: K,\n): K => {\n const declared = extractMetaEntity(entityConstructor).key;\n if (declared !== key)\n throw new Error(\n `entityKey(${entityConstructor.name}, '${key}') does not match ` +\n `@entity({ key: ${declared === undefined ? 'undefined' : `'${declared}'`} })`,\n );\n return key;\n};\n\n/**\n * A body an endpoint sends without describing it: whatever the handler\n * answers, as its JSON — `Date`s as ISO strings, `undefined` members dropped,\n * the way `JSON.stringify` writes it. For a record whose shape the entity\n * describes rather than a schema, and for an opaque document such as an\n * OpenAPI one. A body the endpoint can describe should be a schema instead.\n */\nexport const JsonBody: Schema.Codec<unknown, unknown> = Schema.Unknown.pipe(\n Schema.decodeTo(\n Schema.Unknown,\n SchemaTransformation.transform({\n decode: value => value,\n encode: value =>\n value === undefined\n ? null\n : (JSON.parse(JSON.stringify(value)) as unknown),\n }),\n ),\n);\n\n/** The annotation a body schema carries when it is not JSON on the wire. */\nexport const BODY_ENCODING = 'entifix/bodyEncoding';\n\n/** How a payload travels when it is not decoded as JSON, and under which media type. */\nexport interface BodyEncoding {\n readonly kind: 'text' | 'form';\n readonly contentType: string;\n}\n\n/**\n * A payload taken as the exact text that arrived, for an endpoint whose\n * authentication is a signature over those bytes: a decoded object\n * re-serialised is a different byte sequence, and the MAC would not verify.\n * `contentType` is the media type the caller sends — a provider that signs a\n * JSON body still sends `application/json`, and the bytes are what matter.\n */\nexport const textBody = (contentType = 'text/plain'): Schema.String =>\n Schema.String.annotate({\n [BODY_ENCODING]: { kind: 'text', contentType } satisfies BodyEncoding,\n });\n\n/**\n * A form-encoded payload (`application/x-www-form-urlencoded`), for a caller\n * a specification makes post one — an OpenID back-channel logout, say.\n */\nexport const formBody = <const Fields extends Schema.Struct.Fields>(\n fields: Fields,\n): Schema.Struct<Fields> =>\n Schema.Struct(fields).annotate({\n [BODY_ENCODING]: {\n kind: 'form',\n contentType: 'application/x-www-form-urlencoded',\n } satisfies BodyEncoding,\n });\n\n/** The wire encoding a payload schema declared, or `undefined` for JSON. */\nexport const bodyEncodingOf = (schema: Schema.Top): BodyEncoding | undefined =>\n (schema.ast.annotations as Record<string, unknown> | undefined)?.[\n BODY_ENCODING\n ] as BodyEncoding | undefined;\n"],"names":["Schema","SchemaTransformation","extractMetaEntity","defineEndpoint","descriptor","defineEndpoints","endpoints","implement","handler","entityKey","entityConstructor","key","declared","Error","name","undefined","JsonBody","Unknown","pipe","decodeTo","transform","decode","value","encode","JSON","parse","stringify","BODY_ENCODING","textBody","contentType","String","annotate","kind","formBody","fields","Struct","bodyEncodingOf","schema","ast","annotations"],"mappings":"AAAA,SAAsBA,MAAM,EAAEC,oBAAoB,QAAQ,SAAS;AAEnE,SAASC,iBAAiB,QAAQ,4DAA4D;AAuH9F;;;CAGC,GACD,OAAO,MAAMC,iBAAiB,CAa5BC,aAyBGA,WAAW;AAEhB,iEAAiE,GACjE,OAAO,MAAMC,kBAAkB,CAG7B,GAAGC,YACWA,UAAU;AAuF1B;;;CAGC,GACD,OAAO,MAAMC,YAAY,CACv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oint.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/endpoint/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './endpoint.js';
2
+
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/endpoint/index.ts"],"sourcesContent":["export * from './endpoint.js';\n"],"names":[],"mappings":"AAAA,cAAc,gBAAgB"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-case.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/decorators/use-case/use-case.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAKvD,OAAO,EAEL,kBAAkB,EACnB,MAAM,4CAA4C,CAAC;AAEpD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,OAAO,CAAC,KAAK,CAAC,IAAI,SAAS,MAAM,EAAE,OAAO,SAAS,MAAM,EACvE,OAAO,EAAE,kBAAkB,CAAC,IAAI,EAAE,OAAO,CAAC,IAElC,SAAS,OAAO,EAAE,SAAS,qBAAqB,UAOzD"}
1
+ {"version":3,"file":"use-case.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/decorators/use-case/use-case.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAKvD,OAAO,EAEL,kBAAkB,EACnB,MAAM,4CAA4C,CAAC;AAEpD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,OAAO,CAAC,KAAK,CAAC,IAAI,SAAS,MAAM,EAAE,OAAO,SAAS,MAAM,EACvE,OAAO,EAAE,kBAAkB,CAAC,IAAI,EAAE,OAAO,CAAC,IAElC,SAAS,OAAO,EAAE,SAAS,qBAAqB,UAQzD"}
@@ -18,7 +18,8 @@ import { MetaUseCase } from '../../meta-entities/meta-use-case/index.js';
18
18
  appendMetaUseCase(options.entity, new MetaUseCase(options));
19
19
  setMetaUseCaseBinding(context.metadata, {
20
20
  entity: options.entity,
21
- key: options.key
21
+ key: options.key,
22
+ binding: options.binding
22
23
  });
23
24
  };
24
25
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/entity-definition/decorators/use-case/use-case.ts"],"sourcesContent":["import type { Entity } from '../../../types/Entity.js';\nimport {\n appendMetaUseCase,\n setMetaUseCaseBinding,\n} from '../../helpers/index.js';\nimport {\n MetaUseCase,\n MetaUseCaseOptions,\n} from '../../meta-entities/meta-use-case/index.js';\n\n/**\n * Declares a use case: a verb on an entity beyond the `read`/`write`/`delete`\n * triple, with everything a surface needs to render it.\n *\n * It writes twice, and the two writes have different jobs. The descriptor is\n * appended to the **entity's** metadata, because that is what a form, a table or\n * the palette holds. The entity/verb pair is written to the **class's own**\n * metadata, which is what lets `permissionForUseCase(SomeUC)` derive the\n * permission from one argument.\n *\n * The `const` type parameter keeps `key` a literal at the declaration site.\n * Write it inline — `@useCase({ ...DESCRIPTOR })` would compile and would make\n * a host's source scan stop seeing the declaration.\n */\nexport function useCase<const TKey extends string, TEntity extends Entity>(\n options: MetaUseCaseOptions<TKey, TEntity>,\n) {\n return (_target: unknown, context: ClassDecoratorContext) => {\n appendMetaUseCase(options.entity, new MetaUseCase(options));\n setMetaUseCaseBinding(context.metadata, {\n entity: options.entity,\n key: options.key,\n });\n };\n}\n"],"names":["appendMetaUseCase","setMetaUseCaseBinding","MetaUseCase","useCase","options","_target","context","entity","metadata","key"],"mappings":"AACA,SACEA,iBAAiB,EACjBC,qBAAqB,QAChB,yBAAyB;AAChC,SACEC,WAAW,QAEN,6CAA6C;AAEpD;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASC,QACdC,OAA0C;IAE1C,OAAO,CAACC,SAAkBC;QACxBN,kBAAkBI,QAAQG,MAAM,EAAE,IAAIL,YAAYE;QAClDH,sBAAsBK,QAAQE,QAAQ,EAAE;YACtCD,QAAQH,QAAQG,MAAM;YACtBE,KAAKL,QAAQK,GAAG;QAClB;IACF;AACF"}
1
+ {"version":3,"sources":["../../../../src/entity-definition/decorators/use-case/use-case.ts"],"sourcesContent":["import type { Entity } from '../../../types/Entity.js';\nimport {\n appendMetaUseCase,\n setMetaUseCaseBinding,\n} from '../../helpers/index.js';\nimport {\n MetaUseCase,\n MetaUseCaseOptions,\n} from '../../meta-entities/meta-use-case/index.js';\n\n/**\n * Declares a use case: a verb on an entity beyond the `read`/`write`/`delete`\n * triple, with everything a surface needs to render it.\n *\n * It writes twice, and the two writes have different jobs. The descriptor is\n * appended to the **entity's** metadata, because that is what a form, a table or\n * the palette holds. The entity/verb pair is written to the **class's own**\n * metadata, which is what lets `permissionForUseCase(SomeUC)` derive the\n * permission from one argument.\n *\n * The `const` type parameter keeps `key` a literal at the declaration site.\n * Write it inline — `@useCase({ ...DESCRIPTOR })` would compile and would make\n * a host's source scan stop seeing the declaration.\n */\nexport function useCase<const TKey extends string, TEntity extends Entity>(\n options: MetaUseCaseOptions<TKey, TEntity>,\n) {\n return (_target: unknown, context: ClassDecoratorContext) => {\n appendMetaUseCase(options.entity, new MetaUseCase(options));\n setMetaUseCaseBinding(context.metadata, {\n entity: options.entity,\n key: options.key,\n binding: options.binding,\n });\n };\n}\n"],"names":["appendMetaUseCase","setMetaUseCaseBinding","MetaUseCase","useCase","options","_target","context","entity","metadata","key","binding"],"mappings":"AACA,SACEA,iBAAiB,EACjBC,qBAAqB,QAChB,yBAAyB;AAChC,SACEC,WAAW,QAEN,6CAA6C;AAEpD;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASC,QACdC,OAA0C;IAE1C,OAAO,CAACC,SAAkBC;QACxBN,kBAAkBI,QAAQG,MAAM,EAAE,IAAIL,YAAYE;QAClDH,sBAAsBK,QAAQE,QAAQ,EAAE;YACtCD,QAAQH,QAAQG,MAAM;YACtBE,KAAKL,QAAQK,GAAG;YAChBC,SAASN,QAAQM,OAAO;QAC1B;IACF;AACF"}
@@ -56,4 +56,9 @@ export declare function extractMetaMethods<TEntity extends Entity>(target: Entit
56
56
  export declare function extractMetaUseCases<TEntity extends Entity>(target: EntityConstructor<TEntity>): MetaUseCase[];
57
57
  /** The entity and verb a `@useCase()` class implements. */
58
58
  export declare function extractMetaUseCaseBinding(target: UseCaseConstructor): MetaUseCaseBinding;
59
+ /**
60
+ * The `@useCase()` a class declares, as the entity it is declared against
61
+ * holds it — with its binding and its endpoint contract.
62
+ */
63
+ export declare function extractUseCase(target: UseCaseConstructor): MetaUseCase;
59
64
  //# sourceMappingURL=entity-definition-helpers.d.ts.map
@@ -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,QAWzB;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"}
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,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B,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"}
@@ -111,5 +111,15 @@ export function extractMetaMethods(target) {
111
111
  }
112
112
  return binding;
113
113
  }
114
+ /**
115
+ * The `@useCase()` a class declares, as the entity it is declared against
116
+ * holds it — with its binding and its endpoint contract.
117
+ */ export function extractUseCase(target) {
118
+ const { entity, key, binding } = extractMetaUseCaseBinding(target);
119
+ // `@useCase()` appends to the entity before it records the binding, so a
120
+ // bound class always has its entry — found by binding as well as key, since
121
+ // one key may be declared on a record and over a selection.
122
+ return extractMetaUseCases(entity).find((metaUseCase)=>metaUseCase.key === key && metaUseCase.binding === binding);
123
+ }
114
124
 
115
125
  //# sourceMappingURL=entity-definition-helpers.js.map
@@ -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 { EntifixBuildError } from '../../base-entities/entifix-error/index.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 EntifixBuildError(\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 EntifixBuildError(\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 const existing = (own[META_USE_CASE_KEY] as MetaUseCase[] | undefined) ?? [];\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 EntifixBuildError(`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 EntifixBuildError(\n `MetaUseCase not found for ${target.name} — is it missing @useCase()?`,\n );\n }\n return binding;\n}\n"],"names":["Symbol","metadata","for","EntifixBuildError","META_ENTITY_KEY","META_ACCESSOR_KEY","META_METHOD_KEY","META_USE_CASE_KEY","META_USE_CASE_BINDING_KEY","requireMetadata","setMetaEntity","metaEntity","appendMetaAccessor","metaAccessor","meta","existing","appendMetaMethod","metaMethod","appendMetaUseCase","target","metaUseCase","own","Object","getOwnPropertyDescriptor","value","key","name","setMetaUseCaseBinding","binding","readMetadata","undefined","extractMetaEntity","extractMetaAccessors","extractMetaMethods","extractMetaUseCases","extractMetaUseCaseBinding"],"mappings":"IAACA,SAAD;CAAA,YAAA,CAACA,UAAAA,QAAiCC,QAAQ,YAA1C,YAAA,AAACD,QAAiCC,QAAQ,GAAKD,OAAOE,GAAG,CAAC;AAE1D,SAASC,iBAAiB,QAAQ,6CAA6C;AAoB/E,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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AA0B,GAAGoB;AACzD;AAEA,SAASC,aACPV,MAAwB;QAEjBA;IAAP,QAAOA,0BAAAA,MAAM,CAACnB,OAAOC,QAAQ,CAAC,YAAvBkB,0BAA2BW;AACpC;AAEA,OAAO,SAASC,kBACdZ,MAAkC;IAElC,MAAMlB,WAAW4B,aAAaV;IAC9B,MAAMR,aAAaV,4BAAAA,QAAU,CAACG,gBAAgB;IAC9C,IAAI,CAACO,YAAY;QACf,MAAM,IAAIR,kBAAkB,CAAC,yBAAyB,EAAEgB,OAAOO,IAAI,EAAE;IACvE;IACA,OAAOf;AACT;AAEA;;;;;;;CAOC,GACD,OAAO,SAASqB,qBAAqBb,MAAwB;;IAC3D,MAAMlB,WAAW4B,aAAaV;IAC9B,eAAQlB,4BAAAA,QAAU,CAACI,kBAAkB,mBAAmC,EAAE;AAC5E;AAEA,OAAO,SAAS4B,mBACdd,MAAkC;;IAElC,MAAMlB,WAAW4B,aAAaV;IAC9B,eAAQlB,4BAAAA,QAAU,CAACK,gBAAgB,mBAAiC,EAAE;AACxE;AAEA,4EAA4E,GAC5E,OAAO,SAAS4B,oBACdf,MAAkC;;IAElC,MAAMlB,WAAW4B,aAAaV;IAC9B,eAAQlB,4BAAAA,QAAU,CAACM,kBAAkB,mBAAkC,EAAE;AAC3E;AAEA,yDAAyD,GACzD,OAAO,SAAS4B,0BACdhB,MAA0B;IAE1B,MAAMlB,WAAW,AACfkB,MACD,CAACnB,OAAOC,QAAQ,CAAC;IAClB,MAAM2B,UAAU3B,4BAAAA,QAAU,CAACO,0BAA0B;IAErD,IAAI,CAACoB,SAAS;QACZ,MAAM,IAAIzB,kBACR,CAAC,0BAA0B,EAAEgB,OAAOO,IAAI,CAAC,4BAA4B,CAAC;IAE1E;IACA,OAAOE;AACT"}
1
+ {"version":3,"sources":["../../../src/entity-definition/helpers/entity-definition-helpers.ts"],"sourcesContent":["(Symbol as { metadata?: symbol }).metadata ??= Symbol.for('Symbol.metadata');\n\nimport { EntifixBuildError } from '../../base-entities/entifix-error/index.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 EntifixBuildError(\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 EntifixBuildError(\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 const existing = (own[META_USE_CASE_KEY] as MetaUseCase[] | undefined) ?? [];\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 EntifixBuildError(`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 EntifixBuildError(\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","EntifixBuildError","META_ENTITY_KEY","META_ACCESSOR_KEY","META_METHOD_KEY","META_USE_CASE_KEY","META_USE_CASE_BINDING_KEY","requireMetadata","setMetaEntity","metaEntity","appendMetaAccessor","metaAccessor","meta","existing","appendMetaMethod","metaMethod","appendMetaUseCase","target","metaUseCase","own","Object","getOwnPropertyDescriptor","value","key","name","setMetaUseCaseBinding","binding","readMetadata","undefined","extractMetaEntity","extractMetaAccessors","extractMetaMethods","extractMetaUseCases","extractMetaUseCaseBinding","extractUseCase","entity","find"],"mappings":"IAACA,SAAD;CAAA,YAAA,CAACA,UAAAA,QAAiCC,QAAQ,YAA1C,YAAA,AAACD,QAAiCC,QAAQ,GAAKD,OAAOE,GAAG,CAAC;AAE1D,SAASC,iBAAiB,QAAQ,6CAA6C;AAoB/E,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,IAAIE,kBACR;IAEJ;IACA,OAAOF;AACT;AAEA,OAAO,SAASS,cACdT,QAA6C,EAC7CU,UAAsB;IAEtBF,gBAAgBR,SAAS,CAACG,gBAAgB,GAAGO;AAC/C;AAEA,OAAO,SAASC,mBACdX,QAA6C,EAC7CY,YAA0B;QAIvBC;IAFH,MAAMA,OAAOL,gBAAgBR;IAC7B,MAAMc,YACHD,0BAAAA,IAAI,CAACT,kBAAkB,YAAvBS,0BAA0D,EAAE;IAC/DA,IAAI,CAACT,kBAAkB,GAAG;WAAIU;QAAUF;KAAa;AACvD;AAEA,OAAO,SAASG,iBACdf,QAA6C,EAC7CgB,UAAsB;QAGJH;IADlB,MAAMA,OAAOL,gBAAgBR;IAC7B,MAAMc,YAAYD,wBAAAA,IAAI,CAACR,gBAAgB,YAArBQ,wBAAsD,EAAE;IAC1EA,IAAI,CAACR,gBAAgB,GAAG;WAAIS;QAAUE;KAAW;AACnD;AAEA;;;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SAAS4B,oBACdf,MAAkC;;IAElC,MAAMlB,WAAW4B,aAAaV;IAC9B,eAAQlB,4BAAAA,QAAU,CAACM,kBAAkB,mBAAkC,EAAE;AAC3E;AAEA,yDAAyD,GACzD,OAAO,SAAS4B,0BACdhB,MAA0B;IAE1B,MAAMlB,WAAW,AACfkB,MACD,CAACnB,OAAOC,QAAQ,CAAC;IAClB,MAAM2B,UAAU3B,4BAAAA,QAAU,CAACO,0BAA0B;IAErD,IAAI,CAACoB,SAAS;QACZ,MAAM,IAAIzB,kBACR,CAAC,0BAA0B,EAAEgB,OAAOO,IAAI,CAAC,4BAA4B,CAAC;IAE1E;IACA,OAAOE;AACT;AAEA;;;CAGC,GACD,OAAO,SAASQ,eAAejB,MAA0B;IACvD,MAAM,EAAEkB,MAAM,EAAEZ,GAAG,EAAEG,OAAO,EAAE,GAAGO,0BAA0BhB;IAC3D,yEAAyE;IACzE,4EAA4E;IAC5E,4DAA4D;IAC5D,OAAOe,oBAAoBG,QAAQC,IAAI,CACrClB,CAAAA,cAAeA,YAAYK,GAAG,KAAKA,OAAOL,YAAYQ,OAAO,KAAKA;AAEtE"}
@@ -1,3 +1,5 @@
1
+ import type { Schema } from 'effect';
2
+ import type { FailureClass } from '../../../failure/failure.js';
1
3
  import type { Entity, EntityConstructor } from '../../../types/Entity.js';
2
4
  /** What a use case acts on: one record, a selection, or nothing. */
3
5
  export type UseCaseBinding = 'entity' | 'collection' | 'unbound';
@@ -76,6 +78,15 @@ export interface MetaUseCaseOptions<TKey extends string, TEntity extends Entity>
76
78
  variants?: string;
77
79
  /** The recipe this verb starts a flow from, by name — the flow-backed verbs. */
78
80
  recipe?: string;
81
+ /**
82
+ * What the verb's endpoint takes, answers and refuses with — the contract
83
+ * the shell derives the endpoint from. Absent `payload` means the verb takes
84
+ * no body; absent `success` means its answer is not described. None of the
85
+ * three reaches a served `$metadata` document.
86
+ */
87
+ payload?: Schema.Top;
88
+ success?: Schema.Top;
89
+ errors?: readonly FailureClass[];
79
90
  }
80
91
  /**
81
92
  * What the use-case class's **own** metadata carries, as opposed to what is
@@ -86,6 +97,11 @@ export interface MetaUseCaseOptions<TKey extends string, TEntity extends Entity>
86
97
  export interface MetaUseCaseBinding {
87
98
  entity: EntityConstructor<Entity>;
88
99
  key: string;
100
+ /**
101
+ * Which of the entity's verbs under `key` the class is: one key may be
102
+ * declared on a record and over a selection, and each class is one of them.
103
+ */
104
+ binding: UseCaseBinding;
89
105
  }
90
106
  export declare class MetaUseCase {
91
107
  readonly entity: EntityConstructor<Entity>;
@@ -99,6 +115,9 @@ export declare class MetaUseCase {
99
115
  readonly form?: string;
100
116
  readonly variants?: string;
101
117
  readonly recipe?: string;
118
+ readonly payload?: Schema.Top;
119
+ readonly success?: Schema.Top;
120
+ readonly errors?: readonly FailureClass[];
102
121
  constructor(options: MetaUseCaseOptions<string, Entity>);
103
122
  }
104
123
  //# 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,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,kBA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C;gBAIb,OAAO,EAAE,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC;CAoBxD"}
1
+ {"version":3,"file":"meta-use-case.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/meta-entities/meta-use-case/meta-use-case.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE1E,oEAAoE;AACpE,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,YAAY,GAAG,SAAS,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAC1B,mBAAmB,GAAG,qBAAqB,GAAG,aAAa,CAAC;AAE9D;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,cAAc,CAAC;IACxB,SAAS,EAAE,gBAAgB,CAAC;CAC7B;AAED,sEAAsE;AACtE,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,aAAa,GAAG,SAAS,CAAC;IAChC,qDAAqD;IACrD,UAAU,EAAE,MAAM,CAAC;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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EAAE,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC;CAuBxD"}
@@ -13,6 +13,9 @@ export class MetaUseCase {
13
13
  this.form = options.form;
14
14
  this.variants = options.variants;
15
15
  this.recipe = options.recipe;
16
+ this.payload = options.payload;
17
+ this.success = options.success;
18
+ this.errors = options.errors;
16
19
  }
17
20
  }
18
21
 
@@ -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 * 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"}
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\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 * 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 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.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","form","variants","recipe","payload","success","errors"],"mappings":"AAqHA,OAAO,MAAMA;IAgBX,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;QAC5B,IAAI,CAACC,OAAO,GAAGZ,QAAQY,OAAO;QAC9B,IAAI,CAACC,OAAO,GAAGb,QAAQa,OAAO;QAC9B,IAAI,CAACC,MAAM,GAAGd,QAAQc,MAAM;IAC9B;AAQF"}
@@ -14,13 +14,13 @@ import type { EntifixEnvelope, EntifixEnvelopeType } from './types.js';
14
14
  * `502`.
15
15
  */
16
16
  export declare const decodeRequestEnvelope: (body: unknown, expected: EntifixEnvelopeType, label?: string) => Effect.Effect<EntifixEnvelope, InvalidEnvelope>;
17
- export declare const readEntityEnvelope: <TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>, body: unknown) => Effect.Effect<TEntity, import("../index.js").EntifixBuildError | InvalidEnvelope, never>;
18
- export declare const readEntityCollectionEnvelope: <TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>, body: unknown) => Effect.Effect<TEntity[], import("../index.js").EntifixBuildError | InvalidEnvelope, never>;
17
+ export declare const readEntityEnvelope: <TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>, body: unknown) => Effect.Effect<TEntity, InvalidEnvelope, never>;
18
+ export declare const readEntityCollectionEnvelope: <TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>, body: unknown) => Effect.Effect<TEntity[], InvalidEnvelope, never>;
19
19
  export declare const readEntityPageEnvelope: <TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>, body: unknown) => Effect.Effect<{
20
20
  items: TEntity[];
21
21
  total: number;
22
22
  request: import("../index.js").EntityLoadRequest<TEntity>;
23
- }, import("../index.js").EntifixBuildError | InvalidEnvelope, never>;
23
+ }, InvalidEnvelope, never>;
24
24
  /**
25
25
  * Reads a `$metadata` response back into its document.
26
26
  *
@@ -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,oBAAoB,CAAC;AAKpE,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EAEpB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,GAChC,MAAM,OAAO,EACb,UAAU,mBAAmB,EAC7B,cAAiB,KAChB,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,eAAe,CAO9C,CAAC;AAaJ,eAAO,MAAM,kBAAkB,GAAI,OAAO,SAAS,MAAM,EACvD,mBAAmB,iBAAiB,CAAC,OAAO,CAAC,EAC7C,MAAM,OAAO,6FAcX,CAAC;AAEL,eAAO,MAAM,4BAA4B,GAAI,OAAO,SAAS,MAAM,EACjE,mBAAmB,iBAAiB,CAAC,OAAO,CAAC,EAC7C,MAAM,OAAO,+FAaX,CAAC;AAEL,eAAO,MAAM,sBAAsB,GAAI,OAAO,SAAS,MAAM,EAC3D,mBAAmB,iBAAiB,CAAC,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AC,EAC7C,MAAM,OAAO;WAaO,OAAO,EAAE;;;0BAI3B,CAAC;AAEL;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GAAI,OAAO,SAAS,MAAM,EAC/D,mBAAmB,iBAAiB,CAAC,OAAO,CAAC,EAC7C,MAAM,OAAO,kEASZ,CAAC;AAEJ;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GAAI,OAAO,SAAS,MAAM,EAC7D,mBAAmB,iBAAiB,CAAC,OAAO,CAAC,EAC7C,MAAM,OAAO,uHASZ,CAAC"}
@@ -16,21 +16,28 @@ import { envelopeEntityName } from './make-envelope.js';
16
16
  reason: `"${label}": ${failure.reason}`
17
17
  }));
18
18
  const decodeFor = (entityConstructor, body, expected)=>decodeRequestEnvelope(body, expected, envelopeEntityName(entityConstructor));
19
+ /**
20
+ * A record the entity cannot be built from — a member of the wrong type — is
21
+ * the sender's fault exactly as a malformed envelope is, so it answers the
22
+ * same `400` rather than leaving the deserializer's own error to the caller.
23
+ */ const refusedRecord = (entityConstructor)=>(error)=>new InvalidEnvelope({
24
+ reason: `"${envelopeEntityName(entityConstructor)}": ${error.message}`
25
+ });
19
26
  export const readEntityEnvelope = (entityConstructor, body)=>Effect.gen(function*() {
20
27
  const envelope = yield* decodeFor(entityConstructor, body, 'entity');
21
28
  // The registered schema already refused a missing or non-object `data`,
22
29
  // so the deserializer always has a record to build from.
23
- return yield* deserializeSingleEntity(entityConstructor, envelope.data);
30
+ return yield* deserializeSingleEntity(entityConstructor, envelope.data).pipe(Effect.mapError(refusedRecord(entityConstructor)));
24
31
  });
25
32
  export const readEntityCollectionEnvelope = (entityConstructor, body)=>Effect.gen(function*() {
26
33
  const envelope = yield* decodeFor(entityConstructor, body, 'entityCollection');
27
- const items = yield* deserializeEntityCollection(entityConstructor, envelope.data);
34
+ const items = yield* deserializeEntityCollection(entityConstructor, envelope.data).pipe(Effect.mapError(refusedRecord(entityConstructor)));
28
35
  return items;
29
36
  });
30
37
  export const readEntityPageEnvelope = (entityConstructor, body)=>Effect.gen(function*() {
31
38
  var _envelope_data_request;
32
39
  const envelope = yield* decodeFor(entityConstructor, body, 'entityPage');
33
- const items = yield* deserializeEntityCollection(entityConstructor, envelope.data.items);
40
+ const items = yield* deserializeEntityCollection(entityConstructor, envelope.data.items).pipe(Effect.mapError(refusedRecord(entityConstructor)));
34
41
  return {
35
42
  items: items,
36
43
  total: envelope.data.total,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/envelope/read-envelope.ts"],"sourcesContent":["import { Effect } from 'effect';\n\nimport type { EntityMetadataDocument } from '../entity-definition/metadata/index.js';\nimport {\n deserializeEntityCollection,\n deserializeSingleEntity,\n} from '../entity-definition/serializer/index.js';\nimport { InvalidEnvelope } from '../failure/generic.js';\nimport type { Entity, EntityConstructor } from '../types/Entity.js';\nimport type { EntityFacetCounts } from '../types/EntityFacets.js';\nimport type { EntityPage } from '../types/EntityPage.js';\nimport { decodeEnvelope } from './codec.js';\nimport { envelopeEntityName } from './make-envelope.js';\nimport type {\n EntifixEnvelope,\n EntifixEnvelopeType,\n SerializedEntityPage,\n} from './types.js';\n\n/**\n * Decodes a body a **caller sent** — a request to this service — into an\n * envelope of the expected type, its `data` decoded against the registered\n * schema.\n *\n * The same decode as {@link decodeEnvelope}, failing with an\n * {@link InvalidEnvelope} instead of a protocol failure: a malformed request is\n * the sender's fault and answers `400`, where a peer's malformed *answer* is a\n * `502`.\n */\nexport const decodeRequestEnvelope = (\n body: unknown,\n expected: EntifixEnvelopeType,\n label = 'message',\n): Effect.Effect<EntifixEnvelope, InvalidEnvelope> =>\n Effect.mapError(\n decodeEnvelope(body, expected),\n failure =>\n new InvalidEnvelope({\n reason: `\"${label}\": ${failure.reason}`,\n }),\n );\n\nconst decodeFor = <TEntity extends Entity, TData>(\n entityConstructor: EntityConstructor<TEntity>,\n body: unknown,\n expected: EntifixEnvelopeType,\n): Effect.Effect<EntifixEnvelope<TData>, InvalidEnvelope> =>\n decodeRequestEnvelope(\n body,\n expected,\n envelopeEntityName(entityConstructor),\n ) as Effect.Effect<EntifixEnvelope<TData>, InvalidEnvelope>;\n\nexport const readEntityEnvelope = <TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n body: unknown,\n) =>\n Effect.gen(function* () {\n const envelope = yield* decodeFor<TEntity, unknown>(\n entityConstructor,\n body,\n 'entity',\n );\n // The registered schema already refused a missing or non-object `data`,\n // so the deserializer always has a record to build from.\n return (yield* deserializeSingleEntity(\n entityConstructor,\n envelope.data,\n )) as TEntity;\n });\n\nexport const readEntityCollectionEnvelope = <TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n body: unknown,\n) =>\n Effect.gen(function* () {\n const envelope = yield* decodeFor<TEntity, unknown>(\n entityConstructor,\n body,\n 'entityCollection',\n );\n const items = yield* deserializeEntityCollection(\n entityConstructor,\n envelope.data,\n );\n return items as TEntity[];\n });\n\nexport const readEntityPageEnvelope = <TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n body: unknown,\n) =>\n Effect.gen(function* () {\n const envelope = yield* decodeFor<TEntity, SerializedEntityPage<TEntity>>(\n entityConstructor,\n body,\n 'entityPage',\n );\n const items = yield* deserializeEntityCollection(\n entityConstructor,\n envelope.data.items,\n );\n return {\n items: items as TEntity[],\n total: envelope.data.total,\n request: envelope.data.request ?? {},\n } satisfies EntityPage<TEntity>;\n });\n\n/**\n * Reads a `$metadata` response back into its document.\n *\n * No defaulting of the members: the registered schema refuses a document\n * missing either list, so a form never has to guess whether \"no actions\" meant\n * \"denied\" or \"malformed\".\n */\nexport const readEntityMetadataEnvelope = <TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n body: unknown,\n) =>\n Effect.map(\n decodeFor<TEntity, EntityMetadataDocument>(\n entityConstructor,\n body,\n 'entityMetadata',\n ),\n envelope => envelope.data,\n );\n\n/**\n * Reads a `$facets` response back into its counts. The registered schema\n * refuses a body whose lists are not `{ value, count }` rows — a panel that\n * rendered a malformed count would show a number nobody computed.\n */\nexport const readEntityFacetsEnvelope = <TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n body: unknown,\n) =>\n Effect.map(\n decodeFor<TEntity, EntityFacetCounts>(\n entityConstructor,\n body,\n 'entityFacets',\n ),\n envelope => envelope.data,\n );\n"],"names":["Effect","deserializeEntityCollection","deserializeSingleEntity","InvalidEnvelope","decodeEnvelope","envelopeEntityName","decodeRequestEnvelope","body","expected","label","mapError","failure","reason","decodeFor","entityConstructor","readEntityEnvelope","gen","envelope","data","readEntityCollectionEnvelope","items","readEntityPageEnvelope","total","request","readEntityMetadataEnvelope","map","readEntityFacetsEnvelope"],"mappings":"AAAA,SAASA,MAAM,QAAQ,SAAS;AAGhC,SACEC,2BAA2B,EAC3BC,uBAAuB,QAClB,2CAA2C;AAClD,SAASC,eAAe,QAAQ,wBAAwB;AAIxD,SAASC,cAAc,QAAQ,aAAa;AAC5C,SAASC,kBAAkB,QAAQ,qBAAqB;AAOxD;;;;;;;;;CASC,GACD,OAAO,MAAMC,wBAAwB,CACnCC,MACAC,UACAC,QAAQ,SAAS,GAEjBT,OAAOU,QAAQ,CACbN,eAAeG,MAAMC,WACrBG,CAAAA,UACE,IAAIR,gBAAgB;YAClBS,QAAQ,CAAC,CAAC,EAAEH,MAAM,GAAG,EAAEE,QAAQC,MAAM,EAAE;QACzC,IACF;AAEJ,MAAMC,YAAY,CAChBC,mBACAP,MACAC,WAEAF,sBACEC,MACAC,UACAH,mBAAmBS;AAGvB,OAAO,MAAMC,qBAAqB,CAChCD,mBACAP,OAEAP,OAAOgB,GAAG,CAAC;QACT,MAAMC,WAAW,OAAOJ,UACtBC,mBACAP,MACA;QAEF,wEAAwE;QACxE,yDAAyD;QACzD,OAAQ,OAAOL,wBACbY,mBACAG,SAASC,IAAI;IAEjB,GAAG;AAEL,OAAO,MAAMC,+BAA+B,CAC1CL,mBACAP,OAEAP,OAAOgB,GAAG,CAAC;QACT,MAAMC,WAAW,OAAOJ,UACtBC,mBACAP,MACA;QAEF,MAAMa,QAAQ,OAAOnB,4BACnBa,mBACAG,SAASC,IAAI;QAEf,OAAOE;IACT,GAAG;AAEL,OAAO,MAAMC,yBAAyB,CACpCP,mBACAP,OAEAP,OAAOgB,GAAG,CAAC;YAaEC;QAZX,MAAMA,WAAW,OAAOJ,UACtBC,mBACAP,MACA;QAEF,MAAMa,QAAQ,OAAOnB,4BACnBa,mBACAG,SAASC,IAAI,CAACE,KAAK;QAErB,OAAO;YACLA,OAAOA;YACPE,OAAOL,SAASC,IAAI,CAACI,KAAK;YAC1BC,OAAO,GAAEN,yBAAAA,SAASC,IAAI,CAACK,OAAO,YAArBN,yBAAyB,CAAC;QACrC;IACF,GAAG;AAEL;;;;;;CAMC,GACD,OAAO,MAAMO,6BAA6B,CACxCV,mBACAP,OAEAP,OAAOyB,GAAG,CACRZ,UACEC,mBACAP,MACA,mBAEFU,CAAAA,WAAYA,SAASC,IAAI,EACzB;AAEJ;;;;CAIC,GACD,OAAO,MAAMQ,2BAA2B,CACtCZ,mBACAP,OAEAP,OAAOyB,GAAG,CACRZ,UACEC,mBACAP,MACA,iBAEFU,CAAAA,WAAYA,SAASC,IAAI,EACzB"}
1
+ {"version":3,"sources":["../../src/envelope/read-envelope.ts"],"sourcesContent":["import { Effect } from 'effect';\n\nimport type { EntityMetadataDocument } from '../entity-definition/metadata/index.js';\nimport {\n deserializeEntityCollection,\n deserializeSingleEntity,\n} from '../entity-definition/serializer/index.js';\nimport { InvalidEnvelope } from '../failure/generic.js';\nimport type { Entity, EntityConstructor } from '../types/Entity.js';\nimport type { EntityFacetCounts } from '../types/EntityFacets.js';\nimport type { EntityPage } from '../types/EntityPage.js';\nimport { decodeEnvelope } from './codec.js';\nimport { envelopeEntityName } from './make-envelope.js';\nimport type {\n EntifixEnvelope,\n EntifixEnvelopeType,\n SerializedEntityPage,\n} from './types.js';\n\n/**\n * Decodes a body a **caller sent** — a request to this service — into an\n * envelope of the expected type, its `data` decoded against the registered\n * schema.\n *\n * The same decode as {@link decodeEnvelope}, failing with an\n * {@link InvalidEnvelope} instead of a protocol failure: a malformed request is\n * the sender's fault and answers `400`, where a peer's malformed *answer* is a\n * `502`.\n */\nexport const decodeRequestEnvelope = (\n body: unknown,\n expected: EntifixEnvelopeType,\n label = 'message',\n): Effect.Effect<EntifixEnvelope, InvalidEnvelope> =>\n Effect.mapError(\n decodeEnvelope(body, expected),\n failure =>\n new InvalidEnvelope({\n reason: `\"${label}\": ${failure.reason}`,\n }),\n );\n\nconst decodeFor = <TEntity extends Entity, TData>(\n entityConstructor: EntityConstructor<TEntity>,\n body: unknown,\n expected: EntifixEnvelopeType,\n): Effect.Effect<EntifixEnvelope<TData>, InvalidEnvelope> =>\n decodeRequestEnvelope(\n body,\n expected,\n envelopeEntityName(entityConstructor),\n ) as Effect.Effect<EntifixEnvelope<TData>, InvalidEnvelope>;\n\n/**\n * A record the entity cannot be built from — a member of the wrong type — is\n * the sender's fault exactly as a malformed envelope is, so it answers the\n * same `400` rather than leaving the deserializer's own error to the caller.\n */\nconst refusedRecord =\n <TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>) =>\n (error: { readonly message: string }) =>\n new InvalidEnvelope({\n reason: `\"${envelopeEntityName(entityConstructor)}\": ${error.message}`,\n });\n\nexport const readEntityEnvelope = <TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n body: unknown,\n) =>\n Effect.gen(function* () {\n const envelope = yield* decodeFor<TEntity, unknown>(\n entityConstructor,\n body,\n 'entity',\n );\n // The registered schema already refused a missing or non-object `data`,\n // so the deserializer always has a record to build from.\n return (yield* deserializeSingleEntity(\n entityConstructor,\n envelope.data,\n ).pipe(Effect.mapError(refusedRecord(entityConstructor)))) as TEntity;\n });\n\nexport const readEntityCollectionEnvelope = <TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n body: unknown,\n) =>\n Effect.gen(function* () {\n const envelope = yield* decodeFor<TEntity, unknown>(\n entityConstructor,\n body,\n 'entityCollection',\n );\n const items = yield* deserializeEntityCollection(\n entityConstructor,\n envelope.data,\n ).pipe(Effect.mapError(refusedRecord(entityConstructor)));\n return items as TEntity[];\n });\n\nexport const readEntityPageEnvelope = <TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n body: unknown,\n) =>\n Effect.gen(function* () {\n const envelope = yield* decodeFor<TEntity, SerializedEntityPage<TEntity>>(\n entityConstructor,\n body,\n 'entityPage',\n );\n const items = yield* deserializeEntityCollection(\n entityConstructor,\n envelope.data.items,\n ).pipe(Effect.mapError(refusedRecord(entityConstructor)));\n return {\n items: items as TEntity[],\n total: envelope.data.total,\n request: envelope.data.request ?? {},\n } satisfies EntityPage<TEntity>;\n });\n\n/**\n * Reads a `$metadata` response back into its document.\n *\n * No defaulting of the members: the registered schema refuses a document\n * missing either list, so a form never has to guess whether \"no actions\" meant\n * \"denied\" or \"malformed\".\n */\nexport const readEntityMetadataEnvelope = <TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n body: unknown,\n) =>\n Effect.map(\n decodeFor<TEntity, EntityMetadataDocument>(\n entityConstructor,\n body,\n 'entityMetadata',\n ),\n envelope => envelope.data,\n );\n\n/**\n * Reads a `$facets` response back into its counts. The registered schema\n * refuses a body whose lists are not `{ value, count }` rows — a panel that\n * rendered a malformed count would show a number nobody computed.\n */\nexport const readEntityFacetsEnvelope = <TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n body: unknown,\n) =>\n Effect.map(\n decodeFor<TEntity, EntityFacetCounts>(\n entityConstructor,\n body,\n 'entityFacets',\n ),\n envelope => envelope.data,\n );\n"],"names":["Effect","deserializeEntityCollection","deserializeSingleEntity","InvalidEnvelope","decodeEnvelope","envelopeEntityName","decodeRequestEnvelope","body","expected","label","mapError","failure","reason","decodeFor","entityConstructor","refusedRecord","error","message","readEntityEnvelope","gen","envelope","data","pipe","readEntityCollectionEnvelope","items","readEntityPageEnvelope","total","request","readEntityMetadataEnvelope","map","readEntityFacetsEnvelope"],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mB,GAAG,CAAC;YAaEC;QAZX,MAAMA,WAAW,OAAOP,UACtBC,mBACAP,MACA;QAEF,MAAMiB,QAAQ,OAAOvB,4BACnBa,mBACAM,SAASC,IAAI,CAACG,KAAK,EACnBF,IAAI,CAACtB,OAAOU,QAAQ,CAACK,cAAcD;QACrC,OAAO;YACLU,OAAOA;YACPE,OAAON,SAASC,IAAI,CAACK,KAAK;YAC1BC,OAAO,GAAEP,yBAAAA,SAASC,IAAI,CAACM,OAAO,YAArBP,yBAAyB,CAAC;QACrC;IACF,GAAG;AAEL;;;;;;CAMC,GACD,OAAO,MAAMQ,6BAA6B,CACxCd,mBACAP,OAEAP,OAAO6B,GAAG,CACRhB,UACEC,mBACAP,MACA,mBAEFa,CAAAA,WAAYA,SAASC,IAAI,EACzB;AAEJ;;;;CAIC,GACD,OAAO,MAAMS,2BAA2B,CACtChB,mBACAP,OAEAP,OAAO6B,GAAG,CACRhB,UACEC,mBACAP,MACA,iBAEFa,CAAAA,WAAYA,SAASC,IAAI,EACzB"}
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from './base-entities/configuration-client/index.js';
2
2
  export * from './base-entities/entifix-error/index.js';
3
3
  export * from './command-palette/index.js';
4
4
  export * from './deadline/deadline.js';
5
+ export * from './endpoint/index.js';
5
6
  export * from './entity-definition/decorators/accessor/index.js';
6
7
  export * from './entity-definition/decorators/entity/index.js';
7
8
  export * from './entity-definition/decorators/method/index.js';
@@ -48,5 +49,6 @@ export * from './types/EntitySorting.js';
48
49
  export * from './types/Json.js';
49
50
  export * from './types/StandardSchema.js';
50
51
  export * from './types/UseCase.js';
52
+ export * from './use-case-runner/index.js';
51
53
  export * from './wizard/index.js';
52
54
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+CAA+C,CAAC;AAC9D,cAAc,wCAAwC,CAAC;AACvD,cAAc,4BAA4B,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,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ export * from './base-entities/configuration-client/index.js';
2
2
  export * from './base-entities/entifix-error/index.js';
3
3
  export * from './command-palette/index.js';
4
4
  export * from './deadline/deadline.js';
5
+ export * from './endpoint/index.js';
5
6
  export * from './entity-definition/decorators/accessor/index.js';
6
7
  export * from './entity-definition/decorators/entity/index.js';
7
8
  export * from './entity-definition/decorators/method/index.js';
@@ -48,6 +49,7 @@ export * from './types/EntitySorting.js';
48
49
  export * from './types/Json.js';
49
50
  export * from './types/StandardSchema.js';
50
51
  export * from './types/UseCase.js';
52
+ export * from './use-case-runner/index.js';
51
53
  export * from './wizard/index.js';
52
54
 
53
55
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './base-entities/configuration-client/index.js';\nexport * from './base-entities/entifix-error/index.js';\nexport * from './command-palette/index.js';\nexport * from './deadline/deadline.js';\nexport * from './entity-definition/decorators/accessor/index.js';\nexport * from './entity-definition/decorators/entity/index.js';\nexport * from './entity-definition/decorators/method/index.js';\nexport * from './entity-definition/decorators/use-case/index.js';\nexport * from './entity-definition/describe/index.js';\nexport * from './entity-definition/field-path.js';\nexport * from './entity-definition/helpers/index.js';\nexport * from './entity-definition/links/apply-entity-links/index.js';\nexport * from './entity-definition/links/entity-collection-link/index.js';\nexport * from './entity-definition/links/entity-link/index.js';\nexport * from './entity-definition/links/entity-link-source/index.js';\nexport * from './entity-definition/links/link-targets/index.js';\nexport * from './entity-definition/meta-entities/meta-accessor/index.js';\nexport * from './entity-definition/meta-entities/meta-entity/index.js';\nexport * from './entity-definition/meta-entities/meta-method/index.js';\nexport * from './entity-definition/meta-entities/meta-use-case/index.js';\nexport * from './entity-definition/metadata/index.js';\nexport * from './entity-definition/reconstruct/index.js';\nexport * from './entity-definition/serializer/index.js';\nexport * from './entity-definition/validate/index.js';\nexport * from './envelope/index.js';\nexport * from './failure/index.js';\nexport * from './hierarchy/index.js';\nexport * from './http/session-cookies.js';\nexport * from './i18n/format.js';\nexport * from './i18n/locales.js';\nexport * from './i18n/localized-text.js';\nexport * from './i18n/negotiate.js';\nexport * from './idempotency/index.js';\nexport * from './query/fold.js';\nexport * from './query/in-memory-query.js';\nexport * from './rsql/index.js';\nexport * from './types/BulkOutcome.js';\nexport * from './types/Entity.js';\nexport * from './types/EntityAction.js';\nexport * from './types/EntityDraft.js';\nexport * from './types/EntityFacets.js';\nexport * from './types/EntityFiltering.js';\nexport * from './types/EntityLoadRequest.js';\nexport * from './types/EntityPage.js';\nexport * from './types/EntityRowDraft.js';\nexport * from './types/EntitySelection.js';\nexport * from './types/EntitySorting.js';\nexport * from './types/Json.js';\nexport * from './types/StandardSchema.js';\nexport * from './types/UseCase.js';\nexport * from './wizard/index.js';\n"],"names":[],"mappings":"AAAA,cAAc,gDAAgD;AAC9D,cAAc,yCAAyC;AACvD,cAAc,6BAA6B;AAC3C,cAAc,yBAAyB;AACvC,cAAc,mDAAmD;AACjE,cAAc,iDAAiD;AAC/D,cAAc,iDAAiD;AAC/D,cAAc,mDAAmD;AACjE,cAAc,wCAAwC;AACtD,cAAc,oCAAoC;AAClD,cAAc,uCAAuC;AACrD,cAAc,wDAAwD;AACtE,cAAc,4DAA4D;AAC1E,cAAc,iDAAiD;AAC/D,cAAc,wDAAwD;AACtE,cAAc,kDAAkD;AAChE,cAAc,2DAA2D;AACzE,cAAc,yDAAyD;AACvE,cAAc,yDAAyD;AACvE,cAAc,2DAA2D;AACzE,cAAc,wCAAwC;AACtD,cAAc,2CAA2C;AACzD,cAAc,0CAA0C;AACxD,cAAc,wCAAwC;AACtD,cAAc,sBAAsB;AACpC,cAAc,qBAAqB;AACnC,cAAc,uBAAuB;AACrC,cAAc,4BAA4B;AAC1C,cAAc,mBAAmB;AACjC,cAAc,oBAAoB;AAClC,cAAc,2BAA2B;AACzC,cAAc,sBAAsB;AACpC,cAAc,yBAAyB;AACvC,cAAc,kBAAkB;AAChC,cAAc,6BAA6B;AAC3C,cAAc,kBAAkB;AAChC,cAAc,yBAAyB;AACvC,cAAc,oBAAoB;AAClC,cAAc,0BAA0B;AACxC,cAAc,yBAAyB;AACvC,cAAc,0BAA0B;AACxC,cAAc,6BAA6B;AAC3C,cAAc,+BAA+B;AAC7C,cAAc,wBAAwB;AACtC,cAAc,4BAA4B;AAC1C,cAAc,6BAA6B;AAC3C,cAAc,2BAA2B;AACzC,cAAc,kBAAkB;AAChC,cAAc,4BAA4B;AAC1C,cAAc,qBAAqB;AACnC,cAAc,oBAAoB"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './base-entities/configuration-client/index.js';\nexport * from './base-entities/entifix-error/index.js';\nexport * from './command-palette/index.js';\nexport * from './deadline/deadline.js';\nexport * from './endpoint/index.js';\nexport * from './entity-definition/decorators/accessor/index.js';\nexport * from './entity-definition/decorators/entity/index.js';\nexport * from './entity-definition/decorators/method/index.js';\nexport * from './entity-definition/decorators/use-case/index.js';\nexport * from './entity-definition/describe/index.js';\nexport * from './entity-definition/field-path.js';\nexport * from './entity-definition/helpers/index.js';\nexport * from './entity-definition/links/apply-entity-links/index.js';\nexport * from './entity-definition/links/entity-collection-link/index.js';\nexport * from './entity-definition/links/entity-link/index.js';\nexport * from './entity-definition/links/entity-link-source/index.js';\nexport * from './entity-definition/links/link-targets/index.js';\nexport * from './entity-definition/meta-entities/meta-accessor/index.js';\nexport * from './entity-definition/meta-entities/meta-entity/index.js';\nexport * from './entity-definition/meta-entities/meta-method/index.js';\nexport * from './entity-definition/meta-entities/meta-use-case/index.js';\nexport * from './entity-definition/metadata/index.js';\nexport * from './entity-definition/reconstruct/index.js';\nexport * from './entity-definition/serializer/index.js';\nexport * from './entity-definition/validate/index.js';\nexport * from './envelope/index.js';\nexport * from './failure/index.js';\nexport * from './hierarchy/index.js';\nexport * from './http/session-cookies.js';\nexport * from './i18n/format.js';\nexport * from './i18n/locales.js';\nexport * from './i18n/localized-text.js';\nexport * from './i18n/negotiate.js';\nexport * from './idempotency/index.js';\nexport * from './query/fold.js';\nexport * from './query/in-memory-query.js';\nexport * from './rsql/index.js';\nexport * from './types/BulkOutcome.js';\nexport * from './types/Entity.js';\nexport * from './types/EntityAction.js';\nexport * from './types/EntityDraft.js';\nexport * from './types/EntityFacets.js';\nexport * from './types/EntityFiltering.js';\nexport * from './types/EntityLoadRequest.js';\nexport * from './types/EntityPage.js';\nexport * from './types/EntityRowDraft.js';\nexport * from './types/EntitySelection.js';\nexport * from './types/EntitySorting.js';\nexport * from './types/Json.js';\nexport * from './types/StandardSchema.js';\nexport * from './types/UseCase.js';\nexport * from './use-case-runner/index.js';\nexport * from './wizard/index.js';\n"],"names":[],"mappings":"AAAA,cAAc,gDAAgD;AAC9D,cAAc,yCAAyC;AACvD,cAAc,6BAA6B;AAC3C,cAAc,yBAAyB;AACvC,cAAc,sBAAsB;AACpC,cAAc,mDAAmD;AACjE,cAAc,iDAAiD;AAC/D,cAAc,iDAAiD;AAC/D,cAAc,mDAAmD;AACjE,cAAc,wCAAwC;AACtD,cAAc,oCAAoC;AAClD,cAAc,uCAAuC;AACrD,cAAc,wDAAwD;AACtE,cAAc,4DAA4D;AAC1E,cAAc,iDAAiD;AAC/D,cAAc,wDAAwD;AACtE,cAAc,kDAAkD;AAChE,cAAc,2DAA2D;AACzE,cAAc,yDAAyD;AACvE,cAAc,yDAAyD;AACvE,cAAc,2DAA2D;AACzE,cAAc,wCAAwC;AACtD,cAAc,2CAA2C;AACzD,cAAc,0CAA0C;AACxD,cAAc,wCAAwC;AACtD,cAAc,sBAAsB;AACpC,cAAc,qBAAqB;AACnC,cAAc,uBAAuB;AACrC,cAAc,4BAA4B;AAC1C,cAAc,mBAAmB;AACjC,cAAc,oBAAoB;AAClC,cAAc,2BAA2B;AACzC,cAAc,sBAAsB;AACpC,cAAc,yBAAyB;AACvC,cAAc,kBAAkB;AAChC,cAAc,6BAA6B;AAC3C,cAAc,kBAAkB;AAChC,cAAc,yBAAyB;AACvC,cAAc,oBAAoB;AAClC,cAAc,0BAA0B;AACxC,cAAc,yBAAyB;AACvC,cAAc,0BAA0B;AACxC,cAAc,6BAA6B;AAC3C,cAAc,+BAA+B;AAC7C,cAAc,wBAAwB;AACtC,cAAc,4BAA4B;AAC1C,cAAc,6BAA6B;AAC3C,cAAc,2BAA2B;AACzC,cAAc,kBAAkB;AAChC,cAAc,4BAA4B;AAC1C,cAAc,qBAAqB;AACnC,cAAc,6BAA6B;AAC3C,cAAc,oBAAoB"}
@@ -0,0 +1,2 @@
1
+ export * from './use-case-runner.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/use-case-runner/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './use-case-runner.js';
2
+
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/use-case-runner/index.ts"],"sourcesContent":["export * from './use-case-runner.js';\n"],"names":[],"mappings":"AAAA,cAAc,uBAAuB"}
@@ -0,0 +1,29 @@
1
+ import type { Effect } from 'effect';
2
+ import type { UseCaseDescriptor } from '../entity-definition/describe/describe-entity-use-cases.js';
3
+ import type { UseCaseBinding } from '../entity-definition/meta-entities/meta-use-case/meta-use-case.js';
4
+ import type { TransitionalFailure } from '../failure/failure.js';
5
+ import type { BulkOutcome } from '../types/BulkOutcome.js';
6
+ import type { Entity, EntityId } from '../types/Entity.js';
7
+ import type { EntitySelection } from '../types/EntitySelection.js';
8
+ /**
9
+ * The path a verb is served at, from its entity's key, its own key and its
10
+ * binding
11
+ * ([ADR 0020](../../../../../docs/adr/0020-endpoints-are-descriptors-and-the-shell-builds-an-httpapi.md)):
12
+ * a verb on one record is `POST /api/<entity>/:id/<verb>`, one on a selection
13
+ * or on nothing is `POST /api/<entity>/<verb>`. The shell serves it there and a
14
+ * client calls it there, so the two cannot disagree.
15
+ */
16
+ export declare const verbPath: (entityKey: string, useCaseKey: string, binding: UseCaseBinding) => `/${string}`;
17
+ /**
18
+ * Runs an entity's verbs for a screen — over REST against the service that
19
+ * serves them, or in-process for a host whose records live in the browser.
20
+ * Chosen at composition, the way a repository is, so a generated screen runs
21
+ * a verb without knowing which.
22
+ */
23
+ export interface EntityUseCaseRunner {
24
+ /** Runs a verb on one record, or on nothing for an unbound verb. */
25
+ run(useCase: UseCaseDescriptor, id?: EntityId): Effect.Effect<void, TransitionalFailure>;
26
+ /** Runs a collection verb on a selection, one outcome per record. */
27
+ bulk(useCase: UseCaseDescriptor, selection: EntitySelection<Entity>): Effect.Effect<readonly BulkOutcome[], TransitionalFailure>;
28
+ }
29
+ //# sourceMappingURL=use-case-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-case-runner.d.ts","sourceRoot":"","sources":["../../src/use-case-runner/use-case-runner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4DAA4D,CAAC;AACpG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mEAAmE,CAAC;AACxG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAEnE;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,GACnB,WAAW,MAAM,EACjB,YAAY,MAAM,EAClB,SAAS,cAAc,KACtB,IAAI,MAAM,EAG0B,CAAC;AAExC;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,oEAAoE;IACpE,GAAG,CACD,OAAO,EAAE,iBAAiB,EAC1B,EAAE,CAAC,EAAE,QAAQ,GACZ,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;IAC5C,qEAAqE;IACrE,IAAI,CACF,OAAO,EAAE,iBAAiB,EAC1B,SAAS,EAAE,eAAe,CAAC,MAAM,CAAC,GACjC,MAAM,CAAC,MAAM,CAAC,SAAS,WAAW,EAAE,EAAE,mBAAmB,CAAC,CAAC;CAC/D"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The path a verb is served at, from its entity's key, its own key and its
3
+ * binding
4
+ * ([ADR 0020](../../../../../docs/adr/0020-endpoints-are-descriptors-and-the-shell-builds-an-httpapi.md)):
5
+ * a verb on one record is `POST /api/<entity>/:id/<verb>`, one on a selection
6
+ * or on nothing is `POST /api/<entity>/<verb>`. The shell serves it there and a
7
+ * client calls it there, so the two cannot disagree.
8
+ */ export const verbPath = (entityKey, useCaseKey, binding)=>binding === 'entity' ? `/api/${entityKey}/:id/${useCaseKey}` : `/api/${entityKey}/${useCaseKey}`;
9
+
10
+ //# sourceMappingURL=use-case-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/use-case-runner/use-case-runner.ts"],"sourcesContent":["import type { Effect } from 'effect';\n\nimport type { UseCaseDescriptor } from '../entity-definition/describe/describe-entity-use-cases.js';\nimport type { UseCaseBinding } from '../entity-definition/meta-entities/meta-use-case/meta-use-case.js';\nimport type { TransitionalFailure } from '../failure/failure.js';\nimport type { BulkOutcome } from '../types/BulkOutcome.js';\nimport type { Entity, EntityId } from '../types/Entity.js';\nimport type { EntitySelection } from '../types/EntitySelection.js';\n\n/**\n * The path a verb is served at, from its entity's key, its own key and its\n * binding\n * ([ADR 0020](../../../../../docs/adr/0020-endpoints-are-descriptors-and-the-shell-builds-an-httpapi.md)):\n * a verb on one record is `POST /api/<entity>/:id/<verb>`, one on a selection\n * or on nothing is `POST /api/<entity>/<verb>`. The shell serves it there and a\n * client calls it there, so the two cannot disagree.\n */\nexport const verbPath = (\n entityKey: string,\n useCaseKey: string,\n binding: UseCaseBinding,\n): `/${string}` =>\n binding === 'entity'\n ? `/api/${entityKey}/:id/${useCaseKey}`\n : `/api/${entityKey}/${useCaseKey}`;\n\n/**\n * Runs an entity's verbs for a screen — over REST against the service that\n * serves them, or in-process for a host whose records live in the browser.\n * Chosen at composition, the way a repository is, so a generated screen runs\n * a verb without knowing which.\n */\nexport interface EntityUseCaseRunner {\n /** Runs a verb on one record, or on nothing for an unbound verb. */\n run(\n useCase: UseCaseDescriptor,\n id?: EntityId,\n ): Effect.Effect<void, TransitionalFailure>;\n /** Runs a collection verb on a selection, one outcome per record. */\n bulk(\n useCase: UseCaseDescriptor,\n selection: EntitySelection<Entity>,\n ): Effect.Effect<readonly BulkOutcome[], TransitionalFailure>;\n}\n"],"names":["verbPath","entityKey","useCaseKey","binding"],"mappings":"AASA;;;;;;;CAOC,GACD,OAAO,MAAMA,WAAW,CACtBC,WACAC,YACAC,UAEAA,YAAY,WACR,CAAC,KAAK,EAAEF,UAAU,KAAK,EAAEC,YAAY,GACrC,CAAC,KAAK,EAAED,UAAU,CAAC,EAAEC,YAAY,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entifix/core",
3
- "version": "0.11.0",
3
+ "version": "0.12.1",
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": {