@sincpro/client-framework 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/AGENTS.md +38 -21
  2. package/MANIFESTO.md +4 -4
  3. package/README.md +183 -158
  4. package/dist/client/services/propagation.js +4 -3
  5. package/dist/codegen/services/scaffold.d.ts +12 -10
  6. package/dist/codegen/services/scaffold.js +23 -40
  7. package/dist/core/domain/bus.d.ts +5 -3
  8. package/dist/core/domain/bus.js +8 -1
  9. package/dist/core/domain/dto.d.ts +68 -6
  10. package/dist/core/domain/dto.js +22 -2
  11. package/dist/core/domain/pipeline.d.ts +5 -2
  12. package/dist/core/domain/services.d.ts +39 -13
  13. package/dist/core/domain/services.js +30 -6
  14. package/dist/core/entrypoint/bounded-context.d.ts +54 -35
  15. package/dist/core/entrypoint/bounded-context.js +120 -52
  16. package/dist/core/entrypoint/screens.js +0 -5
  17. package/dist/core/index.d.ts +4 -3
  18. package/dist/core/index.js +4 -3
  19. package/dist/core/infrastructure/listeners.d.ts +5 -4
  20. package/dist/core/infrastructure/listeners.js +1 -1
  21. package/dist/core/services/dto-keys.d.ts +44 -0
  22. package/dist/core/services/dto-keys.js +97 -0
  23. package/dist/core/services/execution.d.ts +10 -21
  24. package/dist/core/services/execution.js +29 -32
  25. package/dist/core/services/interceptors.d.ts +2 -2
  26. package/dist/core/services/interceptors.js +5 -5
  27. package/dist/core/services/listening.d.ts +6 -8
  28. package/dist/core/services/listening.js +3 -2
  29. package/dist/event_driven/adapters/stored-queue.d.ts +5 -5
  30. package/dist/event_driven/adapters/stored-queue.js +5 -10
  31. package/dist/event_driven/domain/envelope.d.ts +2 -2
  32. package/dist/event_driven/domain/envelope.js +7 -1
  33. package/dist/event_driven/domain/messages.d.ts +34 -0
  34. package/dist/event_driven/domain/messages.js +1 -0
  35. package/dist/event_driven/domain/queue.d.ts +9 -5
  36. package/dist/event_driven/entrypoint/publisher.d.ts +2 -2
  37. package/dist/event_driven/entrypoint/publisher.js +4 -0
  38. package/dist/event_driven/entrypoint/subscriber.d.ts +66 -27
  39. package/dist/event_driven/entrypoint/subscriber.js +117 -21
  40. package/dist/event_driven/index.d.ts +11 -10
  41. package/dist/event_driven/index.js +9 -9
  42. package/dist/event_driven/services/messages.d.ts +41 -0
  43. package/dist/event_driven/services/messages.js +147 -0
  44. package/dist/observability/domain/logging.d.ts +4 -8
  45. package/dist/observability/services/logging.d.ts +3 -3
  46. package/dist/observability/services/logging.js +1 -1
  47. package/dist/observability/services/trace-context.d.ts +10 -0
  48. package/dist/observability/services/trace-context.js +29 -0
  49. package/package.json +2 -2
  50. package/dist/event_driven/entrypoint/subscriptions.d.ts +0 -110
  51. package/dist/event_driven/entrypoint/subscriptions.js +0 -184
@@ -1,20 +1,22 @@
1
1
  import type { Metamodel } from "../domain/metamodel.js";
2
2
  /**
3
3
  * A bounded context's skeleton, written ONCE beside what is generated — the files that are the
4
- * application's from then on:
4
+ * application's from then on, laid out as the backend's (`sincpro_mcp_odoo/domains/helpdesk`):
5
5
  *
6
6
  * domains/project/
7
7
  * generated/ `sincpro-client generate` — regenerated, never edited
8
- * infrastructure/dependencies.ts what the services can count on: the generated client
9
- * infrastructure/bounded_context.ts its Feature and ApplicationService, and how it is made
10
- * services/index.ts registers command classes and their services
11
- * index.ts `export const projectBoundedContext` — ready to use
8
+ * infrastructure/dependencies.ts what its services count on, and who supplies it
9
+ * infrastructure/framework.ts its Feature and ApplicationService — every dependency
10
+ * typed on `this` — and `projectBoundedContext`
11
+ * services/index.ts imports each service, which registers itself
12
+ * index.ts `projectBoundedContext`, ready to use
12
13
  *
13
- * Context: the layout sincpro_framework gives a service (`dependencies.py`, `framework.py`,
14
- * `services/`, `__init__.py`), so a bounded context starts the way every other does and nobody
15
- * copies it by hand from another. It is the application's to change: the CLI writes a file only
16
- * when it is not there, and never touches one that is — unlike `generated/`, which is written
17
- * whole every time.
14
+ * Context: `dependencies.py`, `framework.py`, `services/` and `__init__.py` — a bounded context
15
+ * starts the way every other does. The instance lives in `framework.ts`, not `index.ts`: a service
16
+ * imports it to register itself (`@projectBoundedContext.feature(Command)`), and ES modules run
17
+ * their imports first, so `index.ts` importing the services could not also define it. It is the
18
+ * application's to change: the CLI writes a file only when it is not there, and never touches one
19
+ * that is — unlike `generated/`, which is written whole every time.
18
20
  */
19
21
  export type ScaffoldOptions = {
20
22
  /**
@@ -10,6 +10,10 @@ function pascalOf(alias) {
10
10
  }
11
11
  /** A module the skeleton imports, built in parts — see `FRAMEWORK` (`codegen/names.ts`). */
12
12
  const at = (...parts) => parts.join("/");
13
+ /** A path given from the bounded context's folder, as `infrastructure/` reaches it. */
14
+ function fromInfrastructure(path) {
15
+ return path.startsWith(".") ? at("..", path) : path;
16
+ }
13
17
  const HEADER = (what) => `// ${what} — written once by \`sincpro-client scaffold\`; the application's to change.`;
14
18
  export function scaffoldFilesOf(metamodel, options = {}) {
15
19
  const alias = aliasOf(metamodel);
@@ -45,69 +49,48 @@ export function scaffoldFilesOf(metamodel, options = {}) {
45
49
  "}",
46
50
  "",
47
51
  ].join("\n");
48
- const boundedContext = [
52
+ const framework = [
49
53
  HEADER(`How «${alias}» is made`),
50
54
  "",
51
- "import {",
52
- " ApplicationService as BaseApplicationService,",
53
- " Feature as BaseFeature,",
54
- " BoundedContext,",
55
- " type Command,",
56
- " type DomainEvent,",
57
- `} from "${at(FRAMEWORK, "core")}";`,
58
- `import type { OperationTransport } from "${FRAMEWORK}";`,
55
+ `import { type OperationTransport } from "${FRAMEWORK}";`,
56
+ `import { BoundedContext, servicesWith } from "${at(FRAMEWORK, "core")}";`,
59
57
  "",
58
+ `import { operations } from "${fromInfrastructure(operations)}";`,
60
59
  `import { type ${Dependencies}, registerDependencies } from "${at(".", "dependencies")}";`,
61
60
  "",
62
- `/** A Feature of «${alias}» — of a Command, or a use case of an event: its dependencies typed on \`this\`, and \`this.context\`. */`,
63
- "export abstract class Feature<C extends Command<R> | DomainEvent, R> extends BaseFeature<C, R> {",
64
- ...(client ? [` declare readonly client: ${Dependencies}["client"];`] : []),
65
- "}",
61
+ `/** The Feature and ApplicationService of «${alias}»: every dependency typed on \`this\`, declared nowhere else. */`,
62
+ `export const { Feature, ApplicationService } = servicesWith<${Dependencies}>();`,
66
63
  "",
67
- `/** An ApplicationService of «${alias}»: the same, and \`this.featureBus.execute(dto)\`. */`,
68
- "export abstract class ApplicationService<C extends Command<R> | DomainEvent, R> extends BaseApplicationService<C, R> {",
69
- ...(client ? [` declare readonly client: ${Dependencies}["client"];`] : []),
64
+ `export function config${Name}BoundedContext(name: string, transport: OperationTransport) {`,
65
+ ` return registerDependencies(new BoundedContext<${Dependencies}>(name), transport);`,
70
66
  "}",
71
67
  "",
72
- `export function config${Name}BoundedContext(name: string, operations: OperationTransport) {`,
73
- ` return registerDependencies(new BoundedContext<${Dependencies}>(name), operations);`,
74
- "}",
68
+ `/** «${alias}»: \`${name}.execute(new Command(...))\`; a service registers itself with \`@${name}.feature(Command)\`. */`,
69
+ `export const ${name} = config${Name}BoundedContext(${JSON.stringify(alias)}, operations);`,
75
70
  "",
76
71
  ].join("\n");
77
72
  const services = [
78
73
  HEADER(`What «${alias}» offers`),
79
74
  "",
80
- `import type { BoundedContext } from "${at(FRAMEWORK, "core")}";`,
81
- `import type { ${Dependencies} } from "${at("..", "infrastructure", "dependencies")}";`,
82
- "",
83
- "/** Register local Command classes with their Features and ApplicationServices.",
84
- " * Generated DTO types are remote contracts, not runtime command constructors: import",
85
- ` * them under their own name — \`import type * as remote from "${at("..", "generated", "domain")}"\` —`,
86
- " * and let a local Command implement one (`implements remote.CommandCancelIssue`).",
87
- " * Register with boundedContext.feature(CommandClass)(FeatureClass) or",
88
- " * boundedContext.appService(CommandClass)(ApplicationServiceClass); the services live in",
89
- " * one folder per aggregate (`services/<aggregate>/`), and an entity of that aggregate with",
90
- " * use cases of its own in a folder inside it (`services/<aggregate>/<entity>/`).",
91
- " */",
92
- `export function registerServices(_boundedContext: BoundedContext<${Dependencies}>): void {}`,
75
+ "// One file per use case, in its aggregate's folder (`services/<aggregate>/`, a related entity",
76
+ "// with use cases of its own in a folder inside it). Each registers itself with",
77
+ `// \`@${name}.feature(CommandX)\` — or a list: \`@${name}.feature([CommandX, EventY])\` — and is`,
78
+ "// imported here, so it is registered before anyone executes. A generated DTO is a remote",
79
+ `// contract (a type): \`import type * as remote from "${at("..", "generated", "domain")}"\`.`,
80
+ "export {};",
93
81
  "",
94
82
  ].join("\n");
95
83
  const index = [
96
84
  HEADER(`«${alias}», ready to use`),
97
85
  "",
98
- `import { operations } from "${operations}";`,
86
+ `import "${at(".", "services")}";`,
99
87
  "",
100
- `import { config${Name}BoundedContext } from "${at(".", "infrastructure", "bounded_context")}";`,
101
- `import { registerServices } from "${at(".", "services")}";`,
102
- "",
103
- `/** «${alias}»: \`${name}.execute(new Command(...))\`. */`,
104
- `export const ${name} = config${Name}BoundedContext(${JSON.stringify(alias)}, operations);`,
105
- `registerServices(${name});`,
88
+ `export { ApplicationService, Feature, ${name} } from "${at(".", "infrastructure", "framework")}";`,
106
89
  "",
107
90
  ].join("\n");
108
91
  return {
109
92
  "infrastructure/dependencies.ts": dependencies,
110
- "infrastructure/bounded_context.ts": boundedContext,
93
+ "infrastructure/framework.ts": framework,
111
94
  "services/index.ts": services,
112
95
  "index.ts": index,
113
96
  };
@@ -1,4 +1,4 @@
1
- import type { Command, DomainEvent, Executable, ResponseClass } from "./dto.js";
1
+ import type { Command, DomainEvent, Executable, RemoteCommand, RemoteEvent, ResponseClass } from "./dto.js";
2
2
  import type { Cause, ExecuteOptions } from "./pipeline.js";
3
3
  /** What the second argument of `execute` is: options, a delivered event's cause, or a type. */
4
4
  export declare function optionsOf(second: unknown): ExecuteOptions;
@@ -10,7 +10,8 @@ export declare function optionsOf(second: unknown): ExecuteOptions;
10
10
  export interface CommandBus {
11
11
  execute<R>(command: Command<R>, returnType?: ResponseClass<NoInfer<R>>): Promise<R>;
12
12
  execute<R>(command: Command<R>, options: ExecuteOptions): Promise<R>;
13
- execute(event: DomainEvent, options?: ExecuteOptions | Cause): Promise<unknown>;
13
+ execute<I, R>(command: RemoteCommand<I, R>, options?: ExecuteOptions): Promise<R>;
14
+ execute(event: DomainEvent | RemoteEvent, options?: ExecuteOptions | Cause): Promise<unknown>;
14
15
  }
15
16
  /** @internal — how a bus hands what it executes to its generation. */
16
17
  export type Dispatch = (executable: Executable, options: ExecuteOptions) => Promise<unknown>;
@@ -23,5 +24,6 @@ export declare class FeatureBus implements CommandBus {
23
24
  constructor(dispatch: Dispatch);
24
25
  execute<R>(command: Command<R>, returnType?: ResponseClass<NoInfer<R>>): Promise<R>;
25
26
  execute<R>(command: Command<R>, options: ExecuteOptions): Promise<R>;
26
- execute(event: DomainEvent, options?: ExecuteOptions | Cause): Promise<unknown>;
27
+ execute<I, R>(command: RemoteCommand<I, R>, options?: ExecuteOptions): Promise<R>;
28
+ execute(event: DomainEvent | RemoteEvent, options?: ExecuteOptions | Cause): Promise<unknown>;
27
29
  }
@@ -4,7 +4,14 @@ export function optionsOf(second) {
4
4
  return {};
5
5
  const given = second;
6
6
  if (typeof given.id === "string" && typeof given.correlationId === "string")
7
- return { cause: { id: given.id, correlationId: given.correlationId } };
7
+ return {
8
+ cause: {
9
+ id: given.id,
10
+ correlationId: given.correlationId,
11
+ ...(given.traceparent ? { traceparent: given.traceparent } : {}),
12
+ ...(given.tracestate ? { tracestate: given.tracestate } : {}),
13
+ },
14
+ };
8
15
  return {
9
16
  ...(given.signal ? { signal: given.signal } : {}),
10
17
  ...(given.cause ? { cause: given.cause } : {}),
@@ -18,6 +18,12 @@ export declare abstract class DataTransferObject {
18
18
  export declare abstract class Response extends DataTransferObject {
19
19
  }
20
20
  declare const responseType: unique symbol;
21
+ /**
22
+ * A request for work, to one bus. Its identity is the framework's, taken when a bounded context
23
+ * registers it — `<context>.<Command>`, as the backend's `registered_name` —: what its message
24
+ * says (`type`), what the receiving bus finds its class by, and what a generated contract's
25
+ * `operations` carry. A production build keeps class names; `static commandName` fixes another.
26
+ */
21
27
  export declare abstract class Command<R> extends DataTransferObject {
22
28
  /** Type-only association: absent from serialized DTOs and not a runtime validator. */
23
29
  readonly [responseType]: R;
@@ -35,8 +41,8 @@ export declare abstract class Command<R> extends DataTransferObject {
35
41
  * await projectBoundedContext.execute(new OrderPaid("o-1"));
36
42
  *
37
43
  * Context: the backend names an event on the wire by `name`, `<context>.<aggregate>.vN.<fact>`,
38
- * and defaults it to the class's name; a client is minified, so the name is declared, as
39
- * `serviceName` is. `name` is reserved, as the backend reserves it: every event reads its class's
44
+ * and defaults it to the class's name; here it is declared: it is the contract other processes
45
+ * read, with its version, not a class's name. `name` is reserved, as the backend reserves it: every event reads its class's
40
46
  * `eventName` there, and a subclass cannot make it a field.
41
47
  */
42
48
  export declare abstract class DomainEvent extends DataTransferObject {
@@ -44,19 +50,75 @@ export declare abstract class DomainEvent extends DataTransferObject {
44
50
  /** Its wire name: its class's `eventName`. */
45
51
  get name(): string;
46
52
  }
53
+ /** An event's wire name: dotted, as the backend's `<context>.<aggregate>.vN.<fact>`. */
54
+ export declare const EVENT_NAME: RegExp;
47
55
  /** What an event class declares: the name it is known by on the wire. */
48
56
  type EventNamed = {
49
57
  readonly eventName: string;
50
58
  };
51
59
  export type AnyCommand = Command<unknown>;
52
- /** What a service is registered for and executes: a Command, or a domain event. */
53
- export type Executable = AnyCommand | DomainEvent;
54
- /** What it answers: a Command's Response; whatever its subscriber returns, for an event. */
55
- export type Answer<T> = T extends Command<infer R> ? R : unknown;
60
+ /**
61
+ * A generated event as it travels: plain data with its wire name — the type a contract exported
62
+ * with `--events` describes (`dto.OrderPaid`), no class written for it.
63
+ */
64
+ export type RemoteEvent = {
65
+ readonly name: string;
66
+ /** A DTO class's instance is not a generated event: it is a Command, a Response or a DomainEvent. */
67
+ readonly dtoBrand?: never;
68
+ /** Whatever else the contract says it carries. */
69
+ readonly [field: string]: unknown;
70
+ };
71
+ /** What a generated Command carries beside its input: the contract's identity. Never serialized with its data. */
72
+ export declare const COMMAND_IDENTITY: unique symbol;
73
+ declare const remoteAnswer: unique symbol;
74
+ /**
75
+ * A generated Command as the bus executes it: its input, as the contract types it, tagged with
76
+ * the operation's identity (`commandOf(operations.CommandSendIssue, input)`).
77
+ */
78
+ export type RemoteCommand<I = unknown, R = unknown> = Readonly<I> & {
79
+ readonly [COMMAND_IDENTITY]: string;
80
+ /** Type-only: what it answers. */
81
+ readonly [remoteAnswer]?: R;
82
+ };
83
+ /** A generated event a service is registered for: its entry in the contract's `events` (`events.OrderPaid`). */
84
+ export type EventDescriptor = {
85
+ readonly name: string;
86
+ readonly prototype?: never;
87
+ };
88
+ /** A generated Command a service is registered for: its entry in the contract's `operations`. */
89
+ export type CommandDescriptor = {
90
+ readonly identity: string;
91
+ readonly prototype?: never;
92
+ };
93
+ /**
94
+ * The generated Command `operation` names, with `input`, as the bus executes it:
95
+ *
96
+ * await projectBoundedContext.execute(commandOf(operations.CommandSendIssue, input));
97
+ */
98
+ export declare function commandOf<I extends object, R = unknown>(operation: CommandDescriptor, input: I): RemoteCommand<I, R>;
99
+ /**
100
+ * What a service is registered for and executes: a Command, a domain event — or a generated
101
+ * one, recognized by its identity or its wire name.
102
+ */
103
+ export type Executable = AnyCommand | DomainEvent | RemoteEvent | RemoteCommand;
104
+ /** What it answers: a Command's Response; whatever its use case returns, for an event. */
105
+ export type Answer<T> = T extends Command<infer R> ? R : T extends RemoteCommand<unknown, infer R> ? R : unknown;
56
106
  /** A Command's class: what a service is registered for, by exact constructor identity. */
57
107
  export type CommandClass<C extends AnyCommand> = abstract new (...args: never[]) => C;
108
+ /** What a Command class that travels declares: its identity, `<context>.<Command>`. */
109
+ export type CommandNamed = {
110
+ readonly commandName?: string;
111
+ };
58
112
  /** A domain event's class, with its wire name. */
59
113
  export type EventClass<E extends DomainEvent> = (abstract new (...args: never[]) => E) & EventNamed;
60
114
  /** A Response's class: the backend's `return_type`, accepted for the same reading. */
61
115
  export type ResponseClass<R> = abstract new (...args: never[]) => R;
116
+ /**
117
+ * What a service is registered for — a Command's class, a domain event's class, or a generated
118
+ * one's entry in the contract (`operations.X`, `events.X`) —, one or a list of them, as the
119
+ * backend's `DTORegistration`.
120
+ */
121
+ export type DtoKey = CommandClass<AnyCommand> | EventClass<DomainEvent> | EventDescriptor | CommandDescriptor;
122
+ /** What a service registered for `K` receives. */
123
+ export type ExecutableOf<K> = K extends abstract new (...args: never[]) => infer E ? E extends Executable ? E : never : K extends CommandDescriptor ? RemoteCommand : K extends EventDescriptor ? RemoteEvent : never;
62
124
  export {};
@@ -16,6 +16,12 @@ export class DataTransferObject {
16
16
  }
17
17
  export class Response extends DataTransferObject {
18
18
  }
19
+ /**
20
+ * A request for work, to one bus. Its identity is the framework's, taken when a bounded context
21
+ * registers it — `<context>.<Command>`, as the backend's `registered_name` —: what its message
22
+ * says (`type`), what the receiving bus finds its class by, and what a generated contract's
23
+ * `operations` carry. A production build keeps class names; `static commandName` fixes another.
24
+ */
19
25
  export class Command extends DataTransferObject {
20
26
  }
21
27
  /**
@@ -31,8 +37,8 @@ export class Command extends DataTransferObject {
31
37
  * await projectBoundedContext.execute(new OrderPaid("o-1"));
32
38
  *
33
39
  * Context: the backend names an event on the wire by `name`, `<context>.<aggregate>.vN.<fact>`,
34
- * and defaults it to the class's name; a client is minified, so the name is declared, as
35
- * `serviceName` is. `name` is reserved, as the backend reserves it: every event reads its class's
40
+ * and defaults it to the class's name; here it is declared: it is the contract other processes
41
+ * read, with its version, not a class's name. `name` is reserved, as the backend reserves it: every event reads its class's
36
42
  * `eventName` there, and a subclass cannot make it a field.
37
43
  */
38
44
  export class DomainEvent extends DataTransferObject {
@@ -41,3 +47,17 @@ export class DomainEvent extends DataTransferObject {
41
47
  return this.constructor.eventName ?? "";
42
48
  }
43
49
  }
50
+ /** An event's wire name: dotted, as the backend's `<context>.<aggregate>.vN.<fact>`. */
51
+ export const EVENT_NAME = /^[\w-]+(\.[\w-]+)+$/;
52
+ /** What a generated Command carries beside its input: the contract's identity. Never serialized with its data. */
53
+ export const COMMAND_IDENTITY = Symbol.for("sincpro.client-framework.command");
54
+ /**
55
+ * The generated Command `operation` names, with `input`, as the bus executes it:
56
+ *
57
+ * await projectBoundedContext.execute(commandOf(operations.CommandSendIssue, input));
58
+ */
59
+ export function commandOf(operation, input) {
60
+ const command = { ...input };
61
+ Object.defineProperty(command, COMMAND_IDENTITY, { value: operation.identity });
62
+ return command;
63
+ }
@@ -23,10 +23,13 @@ import type { Outcome } from "../../observability/domain/tracing.js";
23
23
  export type PipelineLayer = "feature" | "application_service";
24
24
  /** What caused a run from outside: an event delivered with its envelope continues its chain. */
25
25
  export type Cause = {
26
- /** The id of what caused it — a delivered event's. */
26
+ /** The id of what caused it — a delivered message's. */
27
27
  readonly id: string;
28
28
  /** The chain it continues. */
29
29
  readonly correlationId: string;
30
+ /** The trace it continues (W3C), when the message carried one: the run's span is its child. */
31
+ readonly traceparent?: string;
32
+ readonly tracestate?: string;
30
33
  };
31
34
  /**
32
35
  * How a Command or an event is executed: what cancels it, and — for a delivered event — what
@@ -45,7 +48,7 @@ export type ExecuteOptions = {
45
48
  /** The run an interceptor wraps: who runs, inside which execution, writing where. */
46
49
  export type InterceptedRun = {
47
50
  readonly boundedContext: string;
48
- /** `<bounded context>.<serviceName>`. */
51
+ /** `<bounded context>.<Service>`: the service's name as registered. */
49
52
  readonly useCase: string;
50
53
  readonly layer: PipelineLayer;
51
54
  /** Its id, span, context and chain. */
@@ -1,17 +1,18 @@
1
1
  import type { Execution } from "../../context/domain/execution.js";
2
2
  import type { ContextValues } from "../../context/domain/store.js";
3
3
  import type { FeatureBus } from "./bus.js";
4
- import type { Command, DomainEvent } from "./dto.js";
4
+ import type { Command, DomainEvent, RemoteCommand, RemoteEvent } from "./dto.js";
5
5
  import type { LayerLogger } from "../../observability/domain/logging.js";
6
6
  import type { Span } from "../../observability/domain/tracing.js";
7
+ /** What a service executes: a Command, a domain event, or a generated one. */
8
+ export type ServiceInput<R> = Command<R> | DomainEvent | RemoteEvent | RemoteCommand;
7
9
  /**
8
- * The services of the application layer, as sincpro_framework's: a Feature executes one
9
- * registered Command — or domain event, as its subscriber —; an ApplicationService composes its
10
- * context's Features.
10
+ * The services of the application layer, as sincpro_framework's: a Feature executes the DTOs it
11
+ * is registered for — Commands, domain events, generated ones —; an ApplicationService composes
12
+ * its context's Features.
11
13
  *
12
14
  * @projectBoundedContext.feature(CommandCancelIssue)
13
15
  * class CancelIssue extends Feature<CommandCancelIssue, ResponseCancelIssue> {
14
- * static readonly serviceName = "CancelIssue";
15
16
  * async execute(command: CommandCancelIssue) {
16
17
  * this.logger.info("Cancelling"); // bound to this run
17
18
  * return new ResponseCancelIssue(await this.client.cancelIssue(command));
@@ -19,10 +20,10 @@ import type { Span } from "../../observability/domain/tracing.js";
19
20
  * }
20
21
  *
21
22
  * Context: while a method runs, `this.context`, `this.span`, `this.logger`, `this.featureBus` and
22
- * every dependency are that run's (`executeService`). `serviceName` is stable metadata, never
23
- * `constructor.name`, which a minifier renames.
23
+ * every dependency are that run's (`executeService`). Its name — its use case in spans and
24
+ * logs — is the framework's to take when it is registered: nothing on the class declares it.
24
25
  */
25
- export declare abstract class Feature<C extends Command<R> | DomainEvent, R, Context extends object = ContextValues> {
26
+ export declare abstract class Feature<C extends ServiceInput<R>, R, Context extends object = ContextValues> {
26
27
  /** What this run reads: the process's context, its bounded context's, its scope's. */
27
28
  readonly context: Readonly<Partial<Context>>;
28
29
  /** This run's span: `this.span.set({...})` says more about the use case. */
@@ -32,17 +33,42 @@ export declare abstract class Feature<C extends Command<R> | DomainEvent, R, Con
32
33
  /** What cancels this run, when it was executed with one: check it in a long loop. */
33
34
  readonly signal: AbortSignal | undefined;
34
35
  /**
35
- * This run: its id, use case, flow (`correlationId`) and cause. A use case of a delivered event
36
- * finds the envelope's id as `causationId` — the key that makes executing it twice harmless; a
37
- * use case an `EventSubscriber` executes finds the subscriber's run, so the subscriber hands the
38
- * envelope's id in the Command when the effect must not repeat.
36
+ * This run: its id, use case, flow (`correlationId`) and cause. A delivered event or Command
37
+ * finds its message's id as `causationId` — the key that makes executing it twice harmless.
39
38
  */
40
39
  readonly execution: Execution;
41
40
  abstract execute(command: C): R | Promise<R>;
42
41
  }
43
- export declare abstract class ApplicationService<C extends Command<R> | DomainEvent, R, Context extends object = ContextValues> extends Feature<C, R, Context> {
42
+ export declare abstract class ApplicationService<C extends ServiceInput<R>, R, Context extends object = ContextValues> extends Feature<C, R, Context> {
44
43
  /** The context's Features, run as children of this execution. */
45
44
  protected readonly featureBus: FeatureBus;
46
45
  }
46
+ /** A Feature base whose instances find every dependency of `D` on `this`, typed. */
47
+ export type FeatureWith<D extends object, Context extends object = ContextValues> = abstract new <C extends ServiceInput<R>, R>() => Feature<C, R, Context> & Readonly<D>;
48
+ /** An ApplicationService base whose instances find every dependency of `D` on `this`, typed. */
49
+ export type ApplicationServiceWith<D extends object, Context extends object = ContextValues> = abstract new <C extends ServiceInput<R>, R>() => ApplicationService<C, R, Context> & Readonly<D>;
50
+ /**
51
+ * The Feature and ApplicationService of a bounded context, typed with its dependencies — the
52
+ * backend's `class Feature(_Feature, DependencyContextType)`, in its `infrastructure/framework.py`:
53
+ *
54
+ * // infrastructure/framework.ts
55
+ * export const { Feature, ApplicationService } = servicesWith<HelpdeskDependencies>();
56
+ *
57
+ * // services/ticket/update_stage.feature.ts
58
+ * @helpdeskBoundedContext.feature(CommandUpdateStage)
59
+ * export class UpdateStage extends Feature<CommandUpdateStage, ResponseUpdateStage> {
60
+ * async execute(command: CommandUpdateStage) {
61
+ * return this.odooWrite.stage(command); // typed, declared nowhere else
62
+ * }
63
+ * }
64
+ *
65
+ * Context: a service never declares its dependencies again: they are the bounded context's, and
66
+ * `addDependency` supplies them at runtime (a missing one fails explicitly). This is the same
67
+ * class, typed — no other runtime behaviour.
68
+ */
69
+ export declare function servicesWith<D extends object, Context extends object = ContextValues>(): {
70
+ Feature: FeatureWith<D, Context>;
71
+ ApplicationService: ApplicationServiceWith<D, Context>;
72
+ };
47
73
  /** @internal — what a run finds on `this` that no dependency may take. */
48
74
  export declare const RESERVED_MEMBERS: ReadonlySet<string>;
@@ -1,11 +1,10 @@
1
1
  /**
2
- * The services of the application layer, as sincpro_framework's: a Feature executes one
3
- * registered Command — or domain event, as its subscriber —; an ApplicationService composes its
4
- * context's Features.
2
+ * The services of the application layer, as sincpro_framework's: a Feature executes the DTOs it
3
+ * is registered for — Commands, domain events, generated ones —; an ApplicationService composes
4
+ * its context's Features.
5
5
  *
6
6
  * @projectBoundedContext.feature(CommandCancelIssue)
7
7
  * class CancelIssue extends Feature<CommandCancelIssue, ResponseCancelIssue> {
8
- * static readonly serviceName = "CancelIssue";
9
8
  * async execute(command: CommandCancelIssue) {
10
9
  * this.logger.info("Cancelling"); // bound to this run
11
10
  * return new ResponseCancelIssue(await this.client.cancelIssue(command));
@@ -13,13 +12,38 @@
13
12
  * }
14
13
  *
15
14
  * Context: while a method runs, `this.context`, `this.span`, `this.logger`, `this.featureBus` and
16
- * every dependency are that run's (`executeService`). `serviceName` is stable metadata, never
17
- * `constructor.name`, which a minifier renames.
15
+ * every dependency are that run's (`executeService`). Its name — its use case in spans and
16
+ * logs — is the framework's to take when it is registered: nothing on the class declares it.
18
17
  */
19
18
  export class Feature {
20
19
  }
21
20
  export class ApplicationService extends Feature {
22
21
  }
22
+ /**
23
+ * The Feature and ApplicationService of a bounded context, typed with its dependencies — the
24
+ * backend's `class Feature(_Feature, DependencyContextType)`, in its `infrastructure/framework.py`:
25
+ *
26
+ * // infrastructure/framework.ts
27
+ * export const { Feature, ApplicationService } = servicesWith<HelpdeskDependencies>();
28
+ *
29
+ * // services/ticket/update_stage.feature.ts
30
+ * @helpdeskBoundedContext.feature(CommandUpdateStage)
31
+ * export class UpdateStage extends Feature<CommandUpdateStage, ResponseUpdateStage> {
32
+ * async execute(command: CommandUpdateStage) {
33
+ * return this.odooWrite.stage(command); // typed, declared nowhere else
34
+ * }
35
+ * }
36
+ *
37
+ * Context: a service never declares its dependencies again: they are the bounded context's, and
38
+ * `addDependency` supplies them at runtime (a missing one fails explicitly). This is the same
39
+ * class, typed — no other runtime behaviour.
40
+ */
41
+ export function servicesWith() {
42
+ return {
43
+ Feature: Feature,
44
+ ApplicationService: ApplicationService,
45
+ };
46
+ }
23
47
  /** @internal — what a run finds on `this` that no dependency may take. */
24
48
  export const RESERVED_MEMBERS = new Set([
25
49
  "featureBus",