@afora/core 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/application/start.d.ts +25 -1
- package/dist/core/application/types/application.interface.d.ts +45 -2
- package/dist/core/command/types/command.interface.d.ts +6 -0
- package/dist/core/entity/event.d.ts +12 -2
- package/dist/core/logger/exceptions.d.ts +4 -0
- package/dist/core/logger/logger.d.ts +106 -0
- package/dist/core/use-case/scope.d.ts +3 -0
- package/dist/core/use-case/use-case.d.ts +5 -4
- package/dist/{index-sw2b9ehx.js → index-ewm6r4nw.js} +533 -217
- package/dist/index.d.ts +6 -3
- package/dist/index.js +30 -12
- package/dist/testing/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type AnyEnvironment, type EnvironmentDependencies, type MergedEnvironment } from "../environment/environment.js";
|
|
2
|
+
import type { LogSettings } from "../logger/logger.js";
|
|
2
3
|
import type { IRepositoryProvider } from "../repository/types/repository.interface.js";
|
|
3
4
|
import { Kind } from "../symbols/kind.js";
|
|
5
|
+
import type { ApplicationContext } from "./types/application.interface.js";
|
|
4
6
|
/**
|
|
5
7
|
* A provider an application creates when it starts, from the variables of
|
|
6
8
|
* its environments: what `providerFrom` makes.
|
|
@@ -10,6 +12,8 @@ export interface ProviderFactory<Environment extends EnvironmentDependencies = E
|
|
|
10
12
|
/** The environments whose variables `create` gets, as a list. */
|
|
11
13
|
readonly environments: readonly AnyEnvironment[];
|
|
12
14
|
readonly create: (env: MergedEnvironment<Environment>) => IRepositoryProvider | Promise<IRepositoryProvider>;
|
|
15
|
+
/** Whether `create` takes the context of the application instead of variables. */
|
|
16
|
+
readonly withContext: boolean;
|
|
13
17
|
}
|
|
14
18
|
/**
|
|
15
19
|
* A provider made on `app.start()`: `create` gets the variables of
|
|
@@ -18,6 +22,26 @@ export interface ProviderFactory<Environment extends EnvironmentDependencies = E
|
|
|
18
22
|
* `providerFrom(Database, (env) => drizzleProvider({ db: connect(env.DATABASE_URL), tables }))`.
|
|
19
23
|
*/
|
|
20
24
|
export declare function providerFrom<const Environment extends EnvironmentDependencies>(environmentDependencies: Environment, create: (env: MergedEnvironment<Environment>) => IRepositoryProvider | Promise<IRepositoryProvider>): ProviderFactory<Environment>;
|
|
25
|
+
/**
|
|
26
|
+
* A provider made on `app.start()` from the context of the application:
|
|
27
|
+
* `ctx.env(Database)` gives the variables of a registered environment and
|
|
28
|
+
* `ctx.logger` its logger, e.g.
|
|
29
|
+
* `providerFrom((ctx) => drizzleProvider({ db: connect(ctx.env(Database).DATABASE_URL), tables }))`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function providerFrom(create: (context: ApplicationContext) => IRepositoryProvider | Promise<IRepositoryProvider>): ProviderFactory<readonly []>;
|
|
32
|
+
/** A `log` an application makes on `app.start()`: what `logFrom` makes. */
|
|
33
|
+
export interface LogFactory {
|
|
34
|
+
readonly [Kind]: "log-factory";
|
|
35
|
+
readonly create: (context: ApplicationContext) => LogSettings | Promise<LogSettings>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A `log` made on `app.start()` from the context of the application, before
|
|
39
|
+
* its provider, e.g. `logFrom((ctx) => ({ level: ctx.env(Logging).LOG_LEVEL,
|
|
40
|
+
* providers: [jsonLogProvider()] }))`. Until then the application logs nothing.
|
|
41
|
+
*/
|
|
42
|
+
export declare function logFrom(create: (context: ApplicationContext) => LogSettings | Promise<LogSettings>): LogFactory;
|
|
43
|
+
/** Whether `value` was made by `logFrom`. */
|
|
44
|
+
export declare function isLogFactory(value: unknown): value is LogFactory;
|
|
21
45
|
/** Whether `value` was made by `providerFrom`. */
|
|
22
46
|
export declare function isProviderFactory(value: unknown): value is ProviderFactory;
|
|
23
47
|
/**
|
|
@@ -36,7 +60,7 @@ export declare function deferredEnvironments(provider: unknown): readonly AnyEnv
|
|
|
36
60
|
* environments (already validated by the caller); later calls give the same.
|
|
37
61
|
* @internal
|
|
38
62
|
*/
|
|
39
|
-
export declare function startDeferred(provider: IRepositoryProvider): Promise<IRepositoryProvider> | undefined;
|
|
63
|
+
export declare function startDeferred(provider: IRepositoryProvider, context: ApplicationContext): Promise<IRepositoryProvider> | undefined;
|
|
40
64
|
/**
|
|
41
65
|
* Closes the provider made on start and forgets it, so that calls throw
|
|
42
66
|
* `ApplicationNotStarted` again; a provider that is not deferred is closed.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AnyCommand } from "../../command/types/command.interface.js";
|
|
2
2
|
import type { AnyEnvironment, EnvironmentValue } from "../../environment/environment.js";
|
|
3
3
|
import type { ExceptionLayers } from "../../exception/enums/exception-layers.js";
|
|
4
|
+
import type { ILogger, LogLevel, LogSettings } from "../../logger/logger.js";
|
|
4
5
|
import type { AnyOutput, StageDescription } from "../../output/types/output.interface.js";
|
|
5
6
|
import type { RecordPluginDescriptor } from "../../record/types/plugin.interface.js";
|
|
6
7
|
import type { ProviderDescription } from "../../repository/types/query.interface.js";
|
|
@@ -8,7 +9,7 @@ import type { AnyRepository, IRepositoryProvider } from "../../repository/types/
|
|
|
8
9
|
import type { Kind } from "../../symbols/kind.js";
|
|
9
10
|
import type { UseCaseStepDescription } from "../../use-case/steps/types/steps.interface.js";
|
|
10
11
|
import type { AnyExceptionClass, AnyUseCaseClass } from "../../use-case/use-case.js";
|
|
11
|
-
import type { ProviderFactory } from "../start.js";
|
|
12
|
+
import type { LogFactory, ProviderFactory } from "../start.js";
|
|
12
13
|
type Named<Value> = Readonly<Record<string, Value>>;
|
|
13
14
|
/** The declarations of an application, by name, one collection for each kind. */
|
|
14
15
|
export interface ApplicationCollections {
|
|
@@ -55,6 +56,28 @@ export interface ApplicationSettings<Name extends string, Extended extends reado
|
|
|
55
56
|
* environments, and calls before that throw `ApplicationNotStarted`.
|
|
56
57
|
*/
|
|
57
58
|
readonly provider?: IRepositoryProvider | ProviderFactory;
|
|
59
|
+
/**
|
|
60
|
+
* How it logs: the providers its lines go to and the lowest level kept.
|
|
61
|
+
* Use cases, commands and repository calls of the application are logged
|
|
62
|
+
* through it, and a use case gets it as its `Logger` dependency. Without
|
|
63
|
+
* it, the one of the last extended application that has one; none by default.
|
|
64
|
+
*/
|
|
65
|
+
readonly log?: LogSettings | LogFactory;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* What an application gives the factories it runs on start (`providerFrom`,
|
|
69
|
+
* `logFrom`) and your code (`app.context`).
|
|
70
|
+
*/
|
|
71
|
+
export interface ApplicationContext {
|
|
72
|
+
/** The name of the application. */
|
|
73
|
+
readonly name: string;
|
|
74
|
+
/**
|
|
75
|
+
* The variables of an environment registered in the application, typed by
|
|
76
|
+
* its blueprint; one that is not registered throws `UnregisteredApplicationReference`.
|
|
77
|
+
*/
|
|
78
|
+
env<Environment extends AnyEnvironment>(environment: Environment): EnvironmentValue<Environment>;
|
|
79
|
+
/** Its logger; a `log` of `logFrom` writes nothing before `start()`. */
|
|
80
|
+
readonly logger: ILogger;
|
|
58
81
|
}
|
|
59
82
|
type UnionToIntersection<Union> = (Union extends unknown ? (value: Union) => void : never) extends (value: infer Intersection) => void ? Intersection : never;
|
|
60
83
|
/**
|
|
@@ -72,6 +95,10 @@ export interface IApplication<Name extends string, Collections extends Applicati
|
|
|
72
95
|
readonly extends: readonly AnyApplication[];
|
|
73
96
|
/** The default provider of its repositories, if any. */
|
|
74
97
|
readonly provider: IRepositoryProvider | undefined;
|
|
98
|
+
/** Logs through the providers of its `log`; writes nothing without one. */
|
|
99
|
+
readonly logger: ILogger;
|
|
100
|
+
/** Its context: its name, the variables of its environments and its logger. */
|
|
101
|
+
readonly context: ApplicationContext;
|
|
75
102
|
readonly properties: Collections["properties"];
|
|
76
103
|
readonly blueprints: Collections["blueprints"];
|
|
77
104
|
readonly records: Collections["records"];
|
|
@@ -223,7 +250,8 @@ export interface RecordDescription {
|
|
|
223
250
|
}
|
|
224
251
|
/** What a use case depends on, by the name it has in the application. */
|
|
225
252
|
export interface UseCaseDependencyDescription {
|
|
226
|
-
|
|
253
|
+
/** `logger` is the core's `Logger`, whose `ref` is always `"Logger"`. */
|
|
254
|
+
readonly kind: "use-case" | "repository" | "environment" | "logger";
|
|
227
255
|
readonly ref: string;
|
|
228
256
|
}
|
|
229
257
|
/** A use case: its metadata, fields and what it depends on. */
|
|
@@ -306,6 +334,17 @@ export interface ExceptionDescription {
|
|
|
306
334
|
readonly layer: ExceptionLayers;
|
|
307
335
|
readonly message?: string;
|
|
308
336
|
}
|
|
337
|
+
/** How `describe` gives the `log` of an application. */
|
|
338
|
+
export interface LogDescription {
|
|
339
|
+
readonly level: LogLevel;
|
|
340
|
+
/** The name of each provider made by `logProviderOf` with one; `opaque` otherwise (and for a `logFrom` before start). */
|
|
341
|
+
readonly providers: readonly ({
|
|
342
|
+
readonly kind: "log-provider";
|
|
343
|
+
readonly name: string;
|
|
344
|
+
} | {
|
|
345
|
+
readonly kind: "opaque";
|
|
346
|
+
})[];
|
|
347
|
+
}
|
|
309
348
|
/** The graph `describe` gives: every declaration by name, with its origin in `from`. */
|
|
310
349
|
export interface ApplicationDescription {
|
|
311
350
|
readonly name: string;
|
|
@@ -313,6 +352,10 @@ export interface ApplicationDescription {
|
|
|
313
352
|
readonly extends: readonly string[];
|
|
314
353
|
/** The provider of the application (or of the last extended one), present only when configured. */
|
|
315
354
|
readonly provider?: ProviderDescription;
|
|
355
|
+
/** Its `log` (or the one of the last extended application), present only when configured. */
|
|
356
|
+
readonly log?: LogDescription | {
|
|
357
|
+
readonly kind: "opaque";
|
|
358
|
+
};
|
|
316
359
|
readonly properties: Readonly<Record<string, PropertyDescription & {
|
|
317
360
|
readonly from: string;
|
|
318
361
|
}>>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { BlueprintInput, IBlueprint, IBlueprintCollection } from "../../blueprint/types/blueprint.interface.js";
|
|
2
2
|
import type { EntityEvent } from "../../entity/event.js";
|
|
3
3
|
import type { AnyEnvironment, EnvironmentDependencies, MergedEnvironment } from "../../environment/environment.js";
|
|
4
|
+
import type { ILogger } from "../../logger/logger.js";
|
|
4
5
|
import type { Kind } from "../../symbols/kind.js";
|
|
5
6
|
import type { AnyUseCaseClass, UseCaseInput, UseCaseOptions, UseCaseResponse } from "../../use-case/use-case.js";
|
|
6
7
|
/** The use cases of a command, by operation name. */
|
|
@@ -13,6 +14,11 @@ export interface CommandEventInfo {
|
|
|
13
14
|
readonly context: unknown;
|
|
14
15
|
/** The variables of the command's environments, with the `env` of the call over them. */
|
|
15
16
|
readonly env: Readonly<Record<string, unknown>>;
|
|
17
|
+
/**
|
|
18
|
+
* The logger of the application that bound the command, else the started
|
|
19
|
+
* application's; a logger that writes nothing without either.
|
|
20
|
+
*/
|
|
21
|
+
readonly logger: ILogger;
|
|
16
22
|
}
|
|
17
23
|
/** Handles all the events of a call, once it succeeded. */
|
|
18
24
|
export type CommandEventHandler = (events: readonly EntityEvent[], info: CommandEventInfo) => void | Promise<void>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ILogger } from "../logger/logger.js";
|
|
1
2
|
/** A class made by `entityOf`, including subclasses. */
|
|
2
3
|
export declare const EntityClassBrand: unique symbol;
|
|
3
4
|
export type AnyEntityClass = (abstract new (value: never) => object) & {
|
|
@@ -9,11 +10,20 @@ export interface EventDefinition {
|
|
|
9
10
|
readonly name: string;
|
|
10
11
|
readonly [EventBrand]: true;
|
|
11
12
|
}
|
|
13
|
+
/** What the handler of an event gets next to the entity. */
|
|
14
|
+
export interface EventHandlerContext {
|
|
15
|
+
/**
|
|
16
|
+
* The logger of the application whose command raised the event; else the
|
|
17
|
+
* started application's; a logger that writes nothing without either.
|
|
18
|
+
*/
|
|
19
|
+
readonly logger: ILogger;
|
|
20
|
+
}
|
|
12
21
|
/** One queued occurrence, referencing the original entity rather than a snapshot. */
|
|
13
22
|
export interface EntityEvent<Entity = object> {
|
|
14
23
|
readonly name: string;
|
|
15
24
|
readonly entity: Entity;
|
|
16
|
-
|
|
25
|
+
/** Runs the handler; `logger` replaces the one it would get. */
|
|
26
|
+
handle(context?: Partial<EventHandlerContext>): Promise<void>;
|
|
17
27
|
}
|
|
18
28
|
export type EntityEventReference = EventDefinition | readonly EventDefinition[] | (() => EventDefinition | readonly EventDefinition[]);
|
|
19
29
|
export interface EntityEvents {
|
|
@@ -23,7 +33,7 @@ export interface EntityEvents {
|
|
|
23
33
|
}
|
|
24
34
|
export declare const EntityEventSettings: unique symbol;
|
|
25
35
|
/** Defines an event without executing its handler. */
|
|
26
|
-
export declare function eventOf<Class extends AnyEntityClass>(name: string, entityClass: Class, handler: (entity: InstanceType<Class
|
|
36
|
+
export declare function eventOf<Class extends AnyEntityClass>(name: string, entityClass: Class, handler: (entity: InstanceType<Class>, context: EventHandlerContext) => Promise<void>): EventDefinition;
|
|
27
37
|
export declare function enqueueEvent(entity: object, event: EventDefinition): void;
|
|
28
38
|
export declare function pullEntityEvents<Entity extends object>(entity: Entity): EntityEvent<Entity>[];
|
|
29
39
|
export declare function enqueueLifecycle(entity: object, cycle: keyof EntityEvents): void;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Kind } from "../symbols/kind.js";
|
|
2
|
+
/** What a log line carries besides its event. */
|
|
3
|
+
export type LogFields = Readonly<Record<string, unknown>>;
|
|
4
|
+
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
5
|
+
export declare const LogLevels: readonly LogLevel[];
|
|
6
|
+
/** What logs: an application, a use case through its `Logger` dependency, your code. */
|
|
7
|
+
export interface ILogger {
|
|
8
|
+
debug(event: string, fields?: LogFields): void;
|
|
9
|
+
info(event: string, fields?: LogFields): void;
|
|
10
|
+
warn(event: string, fields?: LogFields): void;
|
|
11
|
+
error(event: string, fields?: LogFields): void;
|
|
12
|
+
}
|
|
13
|
+
/** One line, as a log provider gets it. */
|
|
14
|
+
export interface LogEntry {
|
|
15
|
+
/** ISO 8601. */
|
|
16
|
+
readonly at: string;
|
|
17
|
+
readonly level: LogLevel;
|
|
18
|
+
readonly event: string;
|
|
19
|
+
readonly fields: LogFields;
|
|
20
|
+
/** The name of the application that logged it. */
|
|
21
|
+
readonly application: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Where lines go: the console, JSON on stdout, a log service, memory. An
|
|
25
|
+
* application writes each line to every provider of its `log`.
|
|
26
|
+
*/
|
|
27
|
+
export interface ILogProvider {
|
|
28
|
+
write(entry: LogEntry): void | Promise<void>;
|
|
29
|
+
/** Called on `app.stop()`, to send what is still buffered. */
|
|
30
|
+
flush?(): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
/** The `log` of an application. */
|
|
33
|
+
export interface LogSettings {
|
|
34
|
+
/** Lines below it are dropped. `"info"` by default. */
|
|
35
|
+
readonly level?: LogLevel;
|
|
36
|
+
readonly providers: readonly ILogProvider[];
|
|
37
|
+
}
|
|
38
|
+
/** What `logProviderOf` takes. */
|
|
39
|
+
export interface LogProviderSettings<Provider extends ILogProvider> {
|
|
40
|
+
/** Shown by `app.describe()`; anonymous providers are opaque. */
|
|
41
|
+
readonly name?: string;
|
|
42
|
+
readonly write: Provider["write"];
|
|
43
|
+
readonly flush?: Provider["flush"];
|
|
44
|
+
}
|
|
45
|
+
/** A log provider, checked, and named for `describe()` when `name` is given. */
|
|
46
|
+
export declare function logProviderOf(settings: LogProviderSettings<ILogProvider>): ILogProvider;
|
|
47
|
+
/** The name `logProviderOf` gave a provider, if any. */
|
|
48
|
+
export declare function logProviderNameOf(provider: ILogProvider): string | undefined;
|
|
49
|
+
/** A readable line on the console, by level: for local development. */
|
|
50
|
+
export declare function consoleLogProvider(): ILogProvider;
|
|
51
|
+
/** One JSON object per line on stdout: for Lambda, containers, CloudWatch. */
|
|
52
|
+
export declare function jsonLogProvider(): ILogProvider;
|
|
53
|
+
/** A provider that keeps the lines, for tests. */
|
|
54
|
+
export interface MemoryLogProvider extends ILogProvider {
|
|
55
|
+
readonly entries: readonly LogEntry[];
|
|
56
|
+
clear(): void;
|
|
57
|
+
}
|
|
58
|
+
/** Keeps every line in `entries`, for tests. */
|
|
59
|
+
export declare function memoryLogProvider(): MemoryLogProvider;
|
|
60
|
+
/** Throws unless `settings` is a usable `log`; gives it with the default level. */
|
|
61
|
+
export declare function checkLogSettings(settings: unknown): Required<LogSettings>;
|
|
62
|
+
/** A logger that writes nothing. */
|
|
63
|
+
export declare const silentLogger: ILogger;
|
|
64
|
+
/**
|
|
65
|
+
* The logger of an application: drops what is below `level`, writes the rest
|
|
66
|
+
* to every provider, and never lets a provider break the call or the others.
|
|
67
|
+
* `settings` can be set later (a `log` made on start) and unset on stop.
|
|
68
|
+
*/
|
|
69
|
+
export declare function applicationLogger(application: string): {
|
|
70
|
+
logger: ILogger;
|
|
71
|
+
readonly settings: Required<LogSettings> | undefined;
|
|
72
|
+
set(settings: Required<LogSettings> | undefined): void;
|
|
73
|
+
flush(): Promise<void>;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* The `Logger` dependency of a use case: `dependencies: { logger: Logger }`
|
|
77
|
+
* gives an `ILogger`, the one of the application it runs in.
|
|
78
|
+
*/
|
|
79
|
+
export interface LoggerDeclaration {
|
|
80
|
+
readonly [Kind]: "logger";
|
|
81
|
+
}
|
|
82
|
+
export declare const Logger: LoggerDeclaration;
|
|
83
|
+
export declare function isLoggerDeclaration(value: unknown): value is LoggerDeclaration;
|
|
84
|
+
/** Whether `value` can stand for a logger (an override in `execute`). */
|
|
85
|
+
export declare function isLogger(value: unknown): value is ILogger;
|
|
86
|
+
/**
|
|
87
|
+
* Carries the logger of an application, when it has a `log`: on the
|
|
88
|
+
* application and on the use case classes it binds.
|
|
89
|
+
*/
|
|
90
|
+
export declare const ApplicationLoggerKey: unique symbol;
|
|
91
|
+
/**
|
|
92
|
+
* The logger a call writes to: the one its scope carries, else the one of
|
|
93
|
+
* the application its class was bound by, else the started application's.
|
|
94
|
+
*/
|
|
95
|
+
export declare function resolveLogger(scoped: ILogger | undefined, owner: unknown): ILogger | undefined;
|
|
96
|
+
/** Milliseconds, for timing; `Date.now` where there is no `performance`. */
|
|
97
|
+
export declare function clock(): number;
|
|
98
|
+
export declare function elapsed(since: number): number;
|
|
99
|
+
/**
|
|
100
|
+
* Logs a failure once: the same exception passes through every use case and
|
|
101
|
+
* command up the call, each wrapping it. `warn` for a declared exception,
|
|
102
|
+
* `error` for an unexpected one, with its trace.
|
|
103
|
+
*/
|
|
104
|
+
export declare function logFailure(logger: ILogger | undefined, event: string, fields: LogFields, error: unknown): void;
|
|
105
|
+
/** Writes one line; a logger that throws never breaks the call it logs. */
|
|
106
|
+
export declare function writeLog(logger: ILogger | undefined, level: LogLevel, event: string, fields: LogFields): void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ILogger } from "../logger/logger.js";
|
|
1
2
|
import type { IRepositoryProvider } from "../repository/types/repository.interface.js";
|
|
2
3
|
/**
|
|
3
4
|
* What a call carries to its repositories, internal: the providers that
|
|
@@ -11,6 +12,8 @@ export interface ExecutionScope {
|
|
|
11
12
|
* loads, by environment: a use case that declares it gets these.
|
|
12
13
|
*/
|
|
13
14
|
readonly environments?: ReadonlyMap<object, Readonly<Record<string, unknown>>>;
|
|
15
|
+
/** The logger of the application running the call, given by its command. */
|
|
16
|
+
readonly logger?: ILogger;
|
|
14
17
|
}
|
|
15
18
|
/**
|
|
16
19
|
* Key of the constructor options (and of the repository view) that carries
|
|
@@ -2,6 +2,7 @@ import type { AnyBlueprint, BlueprintInput, BlueprintValue, IBlueprint, IBluepri
|
|
|
2
2
|
import type { EntityEvent } from "../entity/event.js";
|
|
3
3
|
import { type AnyEnvironment, type EnvironmentValue } from "../environment/environment.js";
|
|
4
4
|
import { type DeclaredExceptionClass } from "../exception/exception.js";
|
|
5
|
+
import { type ILogger, type LoggerDeclaration } from "../logger/logger.js";
|
|
5
6
|
import type { AnyRepository } from "../repository/types/repository.interface.js";
|
|
6
7
|
import { Kind } from "../symbols/kind.js";
|
|
7
8
|
import type { UseCaseStep } from "./steps/types/steps.interface.js";
|
|
@@ -26,9 +27,9 @@ export interface AnyUseCaseClass {
|
|
|
26
27
|
export type AnyExceptionClass = DeclaredExceptionClass<any>;
|
|
27
28
|
/**
|
|
28
29
|
* What a use case can depend on: another use case, a repository made by
|
|
29
|
-
* `repositoryOf`,
|
|
30
|
+
* `repositoryOf`, an environment made by `environmentOf`, or `Logger`.
|
|
30
31
|
*/
|
|
31
|
-
export type UseCaseDependency = AnyUseCaseClass | AnyRepository | AnyEnvironment;
|
|
32
|
+
export type UseCaseDependency = AnyUseCaseClass | AnyRepository | AnyEnvironment | LoggerDeclaration;
|
|
32
33
|
export type UseCaseCollection = Readonly<Record<string, UseCaseDependency>>;
|
|
33
34
|
type Declaration = {
|
|
34
35
|
readonly blueprint: AnyBlueprint;
|
|
@@ -55,9 +56,9 @@ export type UseCaseOptions<Context extends IBlueprintCollection | undefined = un
|
|
|
55
56
|
type OptionsArgs<Context extends IBlueprintCollection | undefined> = Context extends IBlueprintCollection ? [options: UseCaseOptions<Context>] : [];
|
|
56
57
|
/**
|
|
57
58
|
* What a use case gets for a dependency: a function for a use case, the
|
|
58
|
-
* repository itself,
|
|
59
|
+
* repository itself, the variables of an environment, or an `ILogger`.
|
|
59
60
|
*/
|
|
60
|
-
export type DependencyOf<Dependency> = Dependency extends AnyUseCaseClass ? (input: UseCaseInput<Dependency>) => Promise<UseCaseResponse<Dependency>> : Dependency extends AnyEnvironment ? EnvironmentValue<Dependency> : Dependency;
|
|
61
|
+
export type DependencyOf<Dependency> = Dependency extends AnyUseCaseClass ? (input: UseCaseInput<Dependency>) => Promise<UseCaseResponse<Dependency>> : Dependency extends AnyEnvironment ? EnvironmentValue<Dependency> : Dependency extends LoggerDeclaration ? ILogger : Dependency;
|
|
61
62
|
export type DependencyFunctions<Dependencies extends UseCaseCollection> = {
|
|
62
63
|
readonly [Key in keyof Dependencies]: DependencyOf<Dependencies[Key]>;
|
|
63
64
|
};
|