@beignet/core 0.0.1 → 0.0.2
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/CHANGELOG.md +11 -0
- package/README.md +149 -4
- package/dist/application/index.d.ts +93 -9
- package/dist/application/index.d.ts.map +1 -1
- package/dist/application/index.js +11 -11
- package/dist/application/index.js.map +1 -1
- package/dist/client/client.d.ts +73 -12
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +37 -12
- package/dist/client/client.js.map +1 -1
- package/dist/client/index.d.ts +12 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +6 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.d.ts +69 -8
- package/dist/client/types.d.ts.map +1 -1
- package/dist/config/index.d.ts +84 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +36 -0
- package/dist/config/index.js.map +1 -1
- package/dist/contracts/contract-builder.d.ts +49 -22
- package/dist/contracts/contract-builder.d.ts.map +1 -1
- package/dist/contracts/contract-builder.js +48 -21
- package/dist/contracts/contract-builder.js.map +1 -1
- package/dist/contracts/contract-group.d.ts +35 -19
- package/dist/contracts/contract-group.d.ts.map +1 -1
- package/dist/contracts/contract-group.js +35 -19
- package/dist/contracts/contract-group.js.map +1 -1
- package/dist/contracts/contract-like.d.ts +4 -4
- package/dist/contracts/contract-like.d.ts.map +1 -1
- package/dist/contracts/contract-like.js +2 -1
- package/dist/contracts/contract-like.js.map +1 -1
- package/dist/contracts/index.d.ts +28 -0
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/index.js +12 -0
- package/dist/contracts/index.js.map +1 -1
- package/dist/contracts/openapi-meta.d.ts +8 -8
- package/dist/contracts/openapi-meta.d.ts.map +1 -1
- package/dist/contracts/path-template.d.ts +27 -0
- package/dist/contracts/path-template.d.ts.map +1 -1
- package/dist/contracts/path-template.js +6 -0
- package/dist/contracts/path-template.js.map +1 -1
- package/dist/contracts/types.d.ts +104 -10
- package/dist/contracts/types.d.ts.map +1 -1
- package/dist/contracts/types.js +15 -0
- package/dist/contracts/types.js.map +1 -1
- package/dist/contracts/utils.d.ts +6 -0
- package/dist/contracts/utils.d.ts.map +1 -1
- package/dist/contracts/utils.js +6 -0
- package/dist/contracts/utils.js.map +1 -1
- package/dist/domain/entity.d.ts +22 -11
- package/dist/domain/entity.d.ts.map +1 -1
- package/dist/domain/entity.js +5 -1
- package/dist/domain/entity.js.map +1 -1
- package/dist/domain/events.d.ts +5 -2
- package/dist/domain/events.d.ts.map +1 -1
- package/dist/domain/events.js +4 -1
- package/dist/domain/events.js.map +1 -1
- package/dist/domain/value-object.d.ts +19 -9
- package/dist/domain/value-object.d.ts.map +1 -1
- package/dist/domain/value-object.js +5 -1
- package/dist/domain/value-object.js.map +1 -1
- package/dist/errors/catalog.d.ts +40 -16
- package/dist/errors/catalog.d.ts.map +1 -1
- package/dist/errors/catalog.js +18 -7
- package/dist/errors/catalog.js.map +1 -1
- package/dist/errors/response.d.ts +16 -4
- package/dist/errors/response.d.ts.map +1 -1
- package/dist/errors/response.js +3 -3
- package/dist/errors/response.js.map +1 -1
- package/dist/errors/validation.d.ts +10 -1
- package/dist/errors/validation.d.ts.map +1 -1
- package/dist/errors/validation.js +3 -0
- package/dist/errors/validation.js.map +1 -1
- package/dist/events/index.d.ts +133 -0
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +30 -0
- package/dist/events/index.js.map +1 -1
- package/dist/idempotency/index.d.ts +355 -0
- package/dist/idempotency/index.d.ts.map +1 -0
- package/dist/idempotency/index.js +360 -0
- package/dist/idempotency/index.js.map +1 -0
- package/dist/jobs/index.d.ts +110 -0
- package/dist/jobs/index.d.ts.map +1 -1
- package/dist/jobs/index.js +22 -0
- package/dist/jobs/index.js.map +1 -1
- package/dist/mail/index.d.ts +149 -0
- package/dist/mail/index.d.ts.map +1 -1
- package/dist/mail/index.js +30 -0
- package/dist/mail/index.js.map +1 -1
- package/dist/notifications/index.d.ts +369 -0
- package/dist/notifications/index.d.ts.map +1 -0
- package/dist/notifications/index.js +310 -0
- package/dist/notifications/index.js.map +1 -0
- package/dist/openapi/index.d.ts +132 -16
- package/dist/openapi/index.d.ts.map +1 -1
- package/dist/openapi/index.js +1 -1
- package/dist/openapi/index.js.map +1 -1
- package/dist/outbox/index.d.ts +469 -0
- package/dist/outbox/index.d.ts.map +1 -0
- package/dist/outbox/index.js +482 -0
- package/dist/outbox/index.js.map +1 -0
- package/dist/pagination/index.d.ts +166 -0
- package/dist/pagination/index.d.ts.map +1 -0
- package/dist/pagination/index.js +96 -0
- package/dist/pagination/index.js.map +1 -0
- package/dist/ports/audit.d.ts +271 -0
- package/dist/ports/audit.d.ts.map +1 -1
- package/dist/ports/audit.js +128 -0
- package/dist/ports/audit.js.map +1 -1
- package/dist/ports/auth.d.ts +70 -0
- package/dist/ports/auth.d.ts.map +1 -1
- package/dist/ports/auth.js +30 -0
- package/dist/ports/auth.js.map +1 -1
- package/dist/ports/cache.d.ts +41 -0
- package/dist/ports/cache.d.ts.map +1 -1
- package/dist/ports/cache.js +10 -0
- package/dist/ports/cache.js.map +1 -1
- package/dist/ports/clock.d.ts +38 -0
- package/dist/ports/clock.d.ts.map +1 -1
- package/dist/ports/clock.js +20 -0
- package/dist/ports/clock.js.map +1 -1
- package/dist/ports/id-generator.d.ts +37 -0
- package/dist/ports/id-generator.d.ts.map +1 -1
- package/dist/ports/id-generator.js +22 -0
- package/dist/ports/id-generator.js.map +1 -1
- package/dist/ports/index.d.ts +83 -0
- package/dist/ports/index.d.ts.map +1 -1
- package/dist/ports/index.js +41 -5
- package/dist/ports/index.js.map +1 -1
- package/dist/ports/logger.d.ts +56 -0
- package/dist/ports/logger.d.ts.map +1 -1
- package/dist/ports/logger.js +17 -0
- package/dist/ports/logger.js.map +1 -1
- package/dist/ports/policy.d.ts +132 -0
- package/dist/ports/policy.d.ts.map +1 -1
- package/dist/ports/policy.js +45 -0
- package/dist/ports/policy.js.map +1 -1
- package/dist/ports/rate-limit.d.ts +25 -0
- package/dist/ports/rate-limit.d.ts.map +1 -1
- package/dist/ports/rate-limit.js +10 -0
- package/dist/ports/rate-limit.js.map +1 -1
- package/dist/ports/redaction.d.ts +101 -0
- package/dist/ports/redaction.d.ts.map +1 -1
- package/dist/ports/redaction.js +59 -0
- package/dist/ports/redaction.js.map +1 -1
- package/dist/ports/storage.d.ts +100 -0
- package/dist/ports/storage.d.ts.map +1 -1
- package/dist/ports/storage.js +10 -0
- package/dist/ports/storage.js.map +1 -1
- package/dist/ports/testing.d.ts +47 -0
- package/dist/ports/testing.d.ts.map +1 -1
- package/dist/ports/testing.js +23 -0
- package/dist/ports/testing.js.map +1 -1
- package/dist/ports/unit-of-work.d.ts +60 -3
- package/dist/ports/unit-of-work.d.ts.map +1 -1
- package/dist/ports/unit-of-work.js +11 -2
- package/dist/ports/unit-of-work.js.map +1 -1
- package/dist/providers/instrumentation.d.ts +204 -0
- package/dist/providers/instrumentation.d.ts.map +1 -1
- package/dist/providers/instrumentation.js +14 -0
- package/dist/providers/instrumentation.js.map +1 -1
- package/dist/providers/provider.d.ts +14 -1
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/provider.js.map +1 -1
- package/dist/schedules/index.d.ts +246 -0
- package/dist/schedules/index.d.ts.map +1 -1
- package/dist/schedules/index.js +27 -0
- package/dist/schedules/index.js.map +1 -1
- package/dist/server/health.d.ts +14 -5
- package/dist/server/health.d.ts.map +1 -1
- package/dist/server/health.js +5 -2
- package/dist/server/health.js.map +1 -1
- package/dist/server/hooks/auth.d.ts +57 -0
- package/dist/server/hooks/auth.d.ts.map +1 -1
- package/dist/server/hooks/auth.js.map +1 -1
- package/dist/server/hooks/cors.d.ts +27 -0
- package/dist/server/hooks/cors.d.ts.map +1 -1
- package/dist/server/hooks/cors.js +12 -0
- package/dist/server/hooks/cors.js.map +1 -1
- package/dist/server/hooks/errors.d.ts +15 -6
- package/dist/server/hooks/errors.d.ts.map +1 -1
- package/dist/server/hooks/errors.js.map +1 -1
- package/dist/server/hooks/index.d.ts +3 -0
- package/dist/server/hooks/index.d.ts.map +1 -1
- package/dist/server/hooks/index.js +3 -0
- package/dist/server/hooks/index.js.map +1 -1
- package/dist/server/hooks/logging.d.ts +36 -0
- package/dist/server/hooks/logging.d.ts.map +1 -1
- package/dist/server/hooks/logging.js +6 -0
- package/dist/server/hooks/logging.js.map +1 -1
- package/dist/server/hooks/rate-limit.d.ts +33 -0
- package/dist/server/hooks/rate-limit.d.ts.map +1 -1
- package/dist/server/hooks/rate-limit.js +11 -0
- package/dist/server/hooks/rate-limit.js.map +1 -1
- package/dist/server/http.d.ts +170 -0
- package/dist/server/http.d.ts.map +1 -1
- package/dist/server/index.d.ts +18 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +6 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/openapi.d.ts +5 -3
- package/dist/server/openapi.d.ts.map +1 -1
- package/dist/server/openapi.js +4 -2
- package/dist/server/openapi.js.map +1 -1
- package/dist/server/providers/loadProviderConfig.d.ts +9 -0
- package/dist/server/providers/loadProviderConfig.d.ts.map +1 -1
- package/dist/server/providers/loadProviderConfig.js +9 -0
- package/dist/server/providers/loadProviderConfig.js.map +1 -1
- package/dist/server/server.d.ts +107 -8
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +27 -7
- package/dist/server/server.js.map +1 -1
- package/dist/testing/index.d.ts +167 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +119 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +21 -1
- package/src/application/index.ts +85 -22
- package/src/client/client.ts +73 -12
- package/src/client/index.ts +12 -0
- package/src/client/types.ts +70 -9
- package/src/config/index.ts +86 -0
- package/src/contracts/contract-builder.ts +49 -22
- package/src/contracts/contract-group.ts +35 -19
- package/src/contracts/contract-like.ts +4 -4
- package/src/contracts/index.ts +28 -1
- package/src/contracts/openapi-meta.ts +8 -8
- package/src/contracts/path-template.ts +27 -0
- package/src/contracts/types.ts +111 -10
- package/src/contracts/utils.ts +6 -0
- package/src/domain/entity.ts +22 -11
- package/src/domain/events.ts +5 -2
- package/src/domain/value-object.ts +19 -9
- package/src/errors/catalog.ts +40 -16
- package/src/errors/response.ts +16 -4
- package/src/errors/validation.ts +10 -1
- package/src/events/index.ts +134 -0
- package/src/idempotency/index.ts +767 -0
- package/src/jobs/index.ts +111 -0
- package/src/mail/index.ts +149 -0
- package/src/notifications/index.ts +771 -0
- package/src/openapi/index.ts +133 -16
- package/src/outbox/index.ts +1024 -0
- package/src/pagination/index.ts +278 -0
- package/src/ports/audit.ts +271 -0
- package/src/ports/auth.ts +70 -0
- package/src/ports/cache.ts +41 -0
- package/src/ports/clock.ts +38 -0
- package/src/ports/id-generator.ts +37 -0
- package/src/ports/index.ts +106 -11
- package/src/ports/logger.ts +56 -0
- package/src/ports/policy.ts +133 -0
- package/src/ports/rate-limit.ts +25 -0
- package/src/ports/redaction.ts +101 -0
- package/src/ports/storage.ts +100 -0
- package/src/ports/testing.ts +47 -0
- package/src/ports/unit-of-work.ts +60 -3
- package/src/providers/instrumentation.ts +204 -0
- package/src/providers/provider.ts +14 -1
- package/src/schedules/index.ts +247 -0
- package/src/server/health.ts +14 -5
- package/src/server/hooks/auth.ts +58 -0
- package/src/server/hooks/cors.ts +27 -0
- package/src/server/hooks/errors.ts +15 -6
- package/src/server/hooks/index.ts +3 -0
- package/src/server/hooks/logging.ts +36 -0
- package/src/server/hooks/rate-limit.ts +33 -0
- package/src/server/http.ts +170 -1
- package/src/server/index.ts +18 -1
- package/src/server/openapi.ts +5 -3
- package/src/server/providers/loadProviderConfig.ts +9 -0
- package/src/server/server.ts +107 -9
- package/src/testing/index.ts +337 -0
package/src/ports/testing.ts
CHANGED
|
@@ -55,6 +55,9 @@ export function createRecordingEventBus(): {
|
|
|
55
55
|
return { bus, events };
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Expected outcome for one policy matrix case.
|
|
60
|
+
*/
|
|
58
61
|
export type PolicyMatrixExpectation = "allow" | "deny";
|
|
59
62
|
|
|
60
63
|
type PolicyMatrixSubject<TResolver> =
|
|
@@ -62,6 +65,9 @@ type PolicyMatrixSubject<TResolver> =
|
|
|
62
65
|
? { subject: Subject }
|
|
63
66
|
: { subject?: never };
|
|
64
67
|
|
|
68
|
+
/**
|
|
69
|
+
* One typed authorization matrix case for a policy ability.
|
|
70
|
+
*/
|
|
65
71
|
export type PolicyMatrixCase<
|
|
66
72
|
TContext,
|
|
67
73
|
TPolicies extends readonly PolicyDefinition[] = readonly PolicyDefinition[],
|
|
@@ -76,6 +82,9 @@ export type PolicyMatrixCase<
|
|
|
76
82
|
} & PolicyMatrixSubject<PolicyMapFromDefinitions<TPolicies>[TAbility]>;
|
|
77
83
|
}[keyof PolicyMapFromDefinitions<TPolicies> & string];
|
|
78
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Untyped policy matrix case used internally for failure reporting.
|
|
87
|
+
*/
|
|
79
88
|
export type UntypedPolicyMatrixCase<TContext> = {
|
|
80
89
|
name: string;
|
|
81
90
|
ctx: TContext;
|
|
@@ -86,6 +95,9 @@ export type UntypedPolicyMatrixCase<TContext> = {
|
|
|
86
95
|
code?: string;
|
|
87
96
|
};
|
|
88
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Result for one evaluated policy matrix case.
|
|
100
|
+
*/
|
|
89
101
|
export type PolicyMatrixResult<
|
|
90
102
|
TContext,
|
|
91
103
|
TPolicies extends readonly PolicyDefinition[] = readonly PolicyDefinition[],
|
|
@@ -96,19 +108,40 @@ export type PolicyMatrixResult<
|
|
|
96
108
|
message?: string;
|
|
97
109
|
};
|
|
98
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Test helper for evaluating authorization policies.
|
|
113
|
+
*/
|
|
99
114
|
export type PolicyTester<
|
|
100
115
|
TContext,
|
|
101
116
|
TPolicies extends readonly PolicyDefinition[],
|
|
102
117
|
> = {
|
|
118
|
+
/**
|
|
119
|
+
* Gate created from the same policies, useful for direct assertions.
|
|
120
|
+
*/
|
|
103
121
|
gate: GatePort<TContext, TPolicies>;
|
|
122
|
+
/**
|
|
123
|
+
* Evaluate cases and return structured pass/fail results.
|
|
124
|
+
*/
|
|
104
125
|
evaluateMatrix(
|
|
105
126
|
cases: readonly PolicyMatrixCase<TContext, TPolicies>[],
|
|
106
127
|
): Promise<PolicyMatrixResult<TContext, TPolicies>[]>;
|
|
128
|
+
/**
|
|
129
|
+
* Evaluate cases and throw a combined assertion error when any fail.
|
|
130
|
+
*/
|
|
107
131
|
assertMatrix(
|
|
108
132
|
cases: readonly PolicyMatrixCase<TContext, TPolicies>[],
|
|
109
133
|
): Promise<void>;
|
|
110
134
|
};
|
|
111
135
|
|
|
136
|
+
/**
|
|
137
|
+
* Create a policy tester from the same options used by `createGate(...)`.
|
|
138
|
+
*
|
|
139
|
+
* Use this for table-driven authorization tests that document who can perform
|
|
140
|
+
* each ability against which subject.
|
|
141
|
+
*
|
|
142
|
+
* @param options - Policy definitions and optional denial mapper.
|
|
143
|
+
* @returns A policy tester with a gate plus matrix helpers.
|
|
144
|
+
*/
|
|
112
145
|
export function createPolicyTester<
|
|
113
146
|
const TPolicies extends readonly PolicyDefinition[],
|
|
114
147
|
>(
|
|
@@ -126,6 +159,13 @@ export function createPolicyTester<
|
|
|
126
159
|
};
|
|
127
160
|
}
|
|
128
161
|
|
|
162
|
+
/**
|
|
163
|
+
* Evaluate a table of policy cases without throwing.
|
|
164
|
+
*
|
|
165
|
+
* @param gate - Gate under test.
|
|
166
|
+
* @param cases - Matrix cases to evaluate.
|
|
167
|
+
* @returns Structured result for each case.
|
|
168
|
+
*/
|
|
129
169
|
export async function evaluatePolicyMatrix<
|
|
130
170
|
TContext,
|
|
131
171
|
TPolicies extends readonly PolicyDefinition[],
|
|
@@ -152,6 +192,13 @@ export async function evaluatePolicyMatrix<
|
|
|
152
192
|
return results;
|
|
153
193
|
}
|
|
154
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Assert that all policy matrix cases pass.
|
|
197
|
+
*
|
|
198
|
+
* @param gate - Gate under test.
|
|
199
|
+
* @param cases - Matrix cases to evaluate.
|
|
200
|
+
* @throws Combined error listing every failed case.
|
|
201
|
+
*/
|
|
155
202
|
export async function assertPolicyMatrix<
|
|
156
203
|
TContext,
|
|
157
204
|
TPolicies extends readonly PolicyDefinition[],
|
|
@@ -3,6 +3,12 @@ import type { DomainEventDef, EventBusPort, InferEventPayload } from "./events";
|
|
|
3
3
|
|
|
4
4
|
type MaybePromise<T> = T | Promise<T>;
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Work function executed inside a Unit of Work.
|
|
8
|
+
*
|
|
9
|
+
* `tx` contains transaction-scoped app ports, usually repositories plus
|
|
10
|
+
* side-effect recorders such as `events`, `jobs`, or `audit`.
|
|
11
|
+
*/
|
|
6
12
|
export type UnitOfWorkCallback<TxPorts, Result> = (
|
|
7
13
|
tx: TxPorts,
|
|
8
14
|
) => MaybePromise<Result>;
|
|
@@ -15,11 +21,19 @@ export type UnitOfWorkCallback<TxPorts, Result> = (
|
|
|
15
21
|
* `createNoopUnitOfWork`.
|
|
16
22
|
*/
|
|
17
23
|
export interface UnitOfWorkPort<TxPorts> {
|
|
24
|
+
/**
|
|
25
|
+
* Run application work with transaction-scoped ports.
|
|
26
|
+
*
|
|
27
|
+
* Durable implementations should commit only if this callback resolves.
|
|
28
|
+
*/
|
|
18
29
|
transaction<Result>(
|
|
19
30
|
work: UnitOfWorkCallback<TxPorts, Result>,
|
|
20
31
|
): Promise<Result>;
|
|
21
32
|
}
|
|
22
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Hooks for `createNoopUnitOfWork(...)`.
|
|
36
|
+
*/
|
|
23
37
|
export interface NoopUnitOfWorkOptions<TxPorts> {
|
|
24
38
|
/**
|
|
25
39
|
* Runs after the callback completes successfully.
|
|
@@ -37,22 +51,56 @@ export interface NoopUnitOfWorkOptions<TxPorts> {
|
|
|
37
51
|
afterRollback?: (error: unknown, tx: TxPorts) => MaybePromise<void>;
|
|
38
52
|
}
|
|
39
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Domain event captured by a buffered event recorder.
|
|
56
|
+
*/
|
|
40
57
|
export interface RecordedDomainEvent {
|
|
58
|
+
/**
|
|
59
|
+
* Event definition used to validate the payload before publishing.
|
|
60
|
+
*/
|
|
41
61
|
event: DomainEventDef;
|
|
62
|
+
/**
|
|
63
|
+
* Stable event name.
|
|
64
|
+
*/
|
|
42
65
|
eventName: string;
|
|
66
|
+
/**
|
|
67
|
+
* Unparsed payload recorded during the transaction.
|
|
68
|
+
*/
|
|
43
69
|
payload: unknown;
|
|
44
70
|
}
|
|
45
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Transaction-scoped port used to record domain events.
|
|
74
|
+
*
|
|
75
|
+
* Use cases record events here during the Unit of Work. The adapter decides
|
|
76
|
+
* whether to publish after commit, enqueue through an outbox, or buffer for a
|
|
77
|
+
* test assertion.
|
|
78
|
+
*/
|
|
46
79
|
export interface DomainEventRecorderPort {
|
|
80
|
+
/**
|
|
81
|
+
* Record a domain event payload.
|
|
82
|
+
*/
|
|
47
83
|
record<E extends DomainEventDef>(
|
|
48
84
|
event: E,
|
|
49
85
|
payload: InferEventPayload<E>,
|
|
50
|
-
): void;
|
|
86
|
+
): Promise<void> | void;
|
|
51
87
|
}
|
|
52
88
|
|
|
89
|
+
/**
|
|
90
|
+
* In-memory event recorder that can be inspected, cleared, or flushed.
|
|
91
|
+
*/
|
|
53
92
|
export interface BufferedDomainEventRecorder extends DomainEventRecorderPort {
|
|
93
|
+
/**
|
|
94
|
+
* Return recorded events without clearing them.
|
|
95
|
+
*/
|
|
54
96
|
entries(): readonly RecordedDomainEvent[];
|
|
97
|
+
/**
|
|
98
|
+
* Remove all recorded events.
|
|
99
|
+
*/
|
|
55
100
|
clear(): void;
|
|
101
|
+
/**
|
|
102
|
+
* Validate and publish all recorded events to an event bus in FIFO order.
|
|
103
|
+
*/
|
|
56
104
|
flush(eventBus: EventBusPort): Promise<void>;
|
|
57
105
|
}
|
|
58
106
|
|
|
@@ -62,6 +110,11 @@ export interface BufferedDomainEventRecorder extends DomainEventRecorderPort {
|
|
|
62
110
|
*
|
|
63
111
|
* This helper does not create database transactions. It gives applications the
|
|
64
112
|
* same UOW shape everywhere and runs commit/rollback hooks around the callback.
|
|
113
|
+
*
|
|
114
|
+
* @param txPortsOrFactory - Transaction-scoped ports or a factory that creates
|
|
115
|
+
* them per transaction call.
|
|
116
|
+
* @param options - Optional commit and rollback hooks.
|
|
117
|
+
* @returns A Unit of Work port with no durable transaction semantics.
|
|
65
118
|
*/
|
|
66
119
|
export function createNoopUnitOfWork<TxPorts>(
|
|
67
120
|
txPortsOrFactory: TxPorts | (() => TxPorts),
|
|
@@ -99,8 +152,12 @@ export function createNoopUnitOfWork<TxPorts>(
|
|
|
99
152
|
}
|
|
100
153
|
|
|
101
154
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
155
|
+
* Create a recorder that buffers domain events until the caller flushes them.
|
|
156
|
+
*
|
|
157
|
+
* Unit of Work adapters commonly flush this recorder from an `afterCommit`
|
|
158
|
+
* hook so events are not published when the work rolls back.
|
|
159
|
+
*
|
|
160
|
+
* @returns A buffered domain event recorder for tests or Unit of Work adapters.
|
|
104
161
|
*/
|
|
105
162
|
export function createDomainEventRecorder(): BufferedDomainEventRecorder {
|
|
106
163
|
const records: RecordedDomainEvent[] = [];
|
|
@@ -1,86 +1,230 @@
|
|
|
1
1
|
import { type Redactor, redactValue } from "../ports/redaction";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Logical provider watcher name used to toggle groups of instrumentation
|
|
5
|
+
* events.
|
|
6
|
+
*/
|
|
3
7
|
export type ProviderInstrumentationWatcherName = string;
|
|
4
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Common metadata attached to every provider instrumentation event.
|
|
11
|
+
*/
|
|
5
12
|
export interface BaseProviderInstrumentationEvent {
|
|
13
|
+
/**
|
|
14
|
+
* Optional event identifier supplied by the caller.
|
|
15
|
+
*/
|
|
6
16
|
id?: string;
|
|
17
|
+
/**
|
|
18
|
+
* ISO timestamp supplied by the caller. Devtools can also assign a timestamp
|
|
19
|
+
* when one is omitted.
|
|
20
|
+
*/
|
|
7
21
|
timestamp?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Request correlation ID for events emitted during request handling.
|
|
24
|
+
*/
|
|
8
25
|
requestId?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Trace identifier for distributed tracing integrations.
|
|
28
|
+
*/
|
|
9
29
|
traceId?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Span identifier for the current operation.
|
|
32
|
+
*/
|
|
10
33
|
spanId?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Parent span identifier for nested operations.
|
|
36
|
+
*/
|
|
11
37
|
parentSpanId?: string;
|
|
38
|
+
/**
|
|
39
|
+
* W3C traceparent header value, when available.
|
|
40
|
+
*/
|
|
12
41
|
traceparent?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Watcher category used by devtools and instrumentation sinks.
|
|
44
|
+
*/
|
|
13
45
|
watcher?: ProviderInstrumentationWatcherName;
|
|
46
|
+
/**
|
|
47
|
+
* Provider-specific structured details. Values are redacted before being
|
|
48
|
+
* recorded by `createProviderInstrumentation(...)`.
|
|
49
|
+
*/
|
|
14
50
|
details?: unknown;
|
|
15
51
|
}
|
|
16
52
|
|
|
53
|
+
/**
|
|
54
|
+
* HTTP request instrumentation emitted by server adapters.
|
|
55
|
+
*/
|
|
17
56
|
export interface RequestProviderInstrumentationEvent
|
|
18
57
|
extends BaseProviderInstrumentationEvent {
|
|
19
58
|
type: "request";
|
|
59
|
+
/**
|
|
60
|
+
* HTTP method.
|
|
61
|
+
*/
|
|
20
62
|
method: string;
|
|
63
|
+
/**
|
|
64
|
+
* Request path.
|
|
65
|
+
*/
|
|
21
66
|
path: string;
|
|
67
|
+
/**
|
|
68
|
+
* Matched contract name, when known.
|
|
69
|
+
*/
|
|
22
70
|
contractName?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Response status code.
|
|
73
|
+
*/
|
|
23
74
|
status?: number;
|
|
75
|
+
/**
|
|
76
|
+
* Request duration in milliseconds.
|
|
77
|
+
*/
|
|
24
78
|
durationMs?: number;
|
|
79
|
+
/**
|
|
80
|
+
* Human-readable summary for devtools lists.
|
|
81
|
+
*/
|
|
25
82
|
summary?: string;
|
|
26
83
|
}
|
|
27
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Error instrumentation emitted by framework hooks, use cases, or providers.
|
|
87
|
+
*/
|
|
28
88
|
export interface ErrorProviderInstrumentationEvent
|
|
29
89
|
extends BaseProviderInstrumentationEvent {
|
|
30
90
|
type: "error";
|
|
91
|
+
/**
|
|
92
|
+
* Error message.
|
|
93
|
+
*/
|
|
31
94
|
message: string;
|
|
95
|
+
/**
|
|
96
|
+
* Error stack trace, when available.
|
|
97
|
+
*/
|
|
32
98
|
stack?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Contract associated with the error.
|
|
101
|
+
*/
|
|
33
102
|
contractName?: string;
|
|
103
|
+
/**
|
|
104
|
+
* Use case associated with the error.
|
|
105
|
+
*/
|
|
34
106
|
useCaseName?: string;
|
|
35
107
|
}
|
|
36
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Use-case lifecycle instrumentation.
|
|
111
|
+
*/
|
|
37
112
|
export interface UseCaseProviderInstrumentationEvent
|
|
38
113
|
extends BaseProviderInstrumentationEvent {
|
|
39
114
|
type: "usecase";
|
|
115
|
+
/**
|
|
116
|
+
* Use-case name.
|
|
117
|
+
*/
|
|
40
118
|
name: string;
|
|
119
|
+
/**
|
|
120
|
+
* Optional classification used by devtools.
|
|
121
|
+
*/
|
|
41
122
|
kind?: "command" | "query";
|
|
123
|
+
/**
|
|
124
|
+
* Lifecycle phase.
|
|
125
|
+
*/
|
|
42
126
|
phase: "start" | "end" | "error";
|
|
127
|
+
/**
|
|
128
|
+
* Duration in milliseconds for completed phases.
|
|
129
|
+
*/
|
|
43
130
|
durationMs?: number;
|
|
131
|
+
/**
|
|
132
|
+
* Error summary for failed phases.
|
|
133
|
+
*/
|
|
44
134
|
error?: string;
|
|
45
135
|
}
|
|
46
136
|
|
|
137
|
+
/**
|
|
138
|
+
* Event bus instrumentation.
|
|
139
|
+
*/
|
|
47
140
|
export interface EventBusProviderInstrumentationEvent
|
|
48
141
|
extends BaseProviderInstrumentationEvent {
|
|
49
142
|
type: "eventBus";
|
|
143
|
+
/**
|
|
144
|
+
* Domain or integration event name.
|
|
145
|
+
*/
|
|
50
146
|
eventName: string;
|
|
51
147
|
}
|
|
52
148
|
|
|
149
|
+
/**
|
|
150
|
+
* Background job instrumentation.
|
|
151
|
+
*/
|
|
53
152
|
export interface JobProviderInstrumentationEvent
|
|
54
153
|
extends BaseProviderInstrumentationEvent {
|
|
55
154
|
type: "job";
|
|
155
|
+
/**
|
|
156
|
+
* Job name.
|
|
157
|
+
*/
|
|
56
158
|
jobName: string;
|
|
159
|
+
/**
|
|
160
|
+
* Job lifecycle status.
|
|
161
|
+
*/
|
|
57
162
|
status: "scheduled" | "started" | "completed" | "failed";
|
|
58
163
|
}
|
|
59
164
|
|
|
165
|
+
/**
|
|
166
|
+
* Scheduled task instrumentation.
|
|
167
|
+
*/
|
|
60
168
|
export interface ScheduleProviderInstrumentationEvent
|
|
61
169
|
extends BaseProviderInstrumentationEvent {
|
|
62
170
|
type: "schedule";
|
|
171
|
+
/**
|
|
172
|
+
* Schedule name.
|
|
173
|
+
*/
|
|
63
174
|
scheduleName: string;
|
|
175
|
+
/**
|
|
176
|
+
* Schedule run lifecycle status.
|
|
177
|
+
*/
|
|
64
178
|
status: "started" | "completed" | "failed";
|
|
179
|
+
/**
|
|
180
|
+
* Cron expression for the schedule, when known.
|
|
181
|
+
*/
|
|
65
182
|
cron?: string;
|
|
183
|
+
/**
|
|
184
|
+
* Time zone used by the schedule, when known.
|
|
185
|
+
*/
|
|
66
186
|
timezone?: string;
|
|
67
187
|
}
|
|
68
188
|
|
|
189
|
+
/**
|
|
190
|
+
* Provider lifecycle instrumentation emitted during setup, start, and stop.
|
|
191
|
+
*/
|
|
69
192
|
export interface ProviderLifecycleInstrumentationEvent
|
|
70
193
|
extends BaseProviderInstrumentationEvent {
|
|
71
194
|
type: "provider";
|
|
195
|
+
/**
|
|
196
|
+
* Provider name.
|
|
197
|
+
*/
|
|
72
198
|
providerName: string;
|
|
199
|
+
/**
|
|
200
|
+
* Lifecycle action.
|
|
201
|
+
*/
|
|
73
202
|
action: "setup" | "start" | "stop";
|
|
74
203
|
}
|
|
75
204
|
|
|
205
|
+
/**
|
|
206
|
+
* Custom provider instrumentation event for provider-owned operations.
|
|
207
|
+
*/
|
|
76
208
|
export interface CustomProviderInstrumentationEvent
|
|
77
209
|
extends BaseProviderInstrumentationEvent {
|
|
78
210
|
type: "custom";
|
|
211
|
+
/**
|
|
212
|
+
* Stable event name.
|
|
213
|
+
*/
|
|
79
214
|
name: string;
|
|
215
|
+
/**
|
|
216
|
+
* Short display label for devtools.
|
|
217
|
+
*/
|
|
80
218
|
label?: string;
|
|
219
|
+
/**
|
|
220
|
+
* Human-readable summary for devtools lists.
|
|
221
|
+
*/
|
|
81
222
|
summary?: string;
|
|
82
223
|
}
|
|
83
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Union of instrumentation events that provider sinks can receive.
|
|
227
|
+
*/
|
|
84
228
|
export type ProviderInstrumentationEvent =
|
|
85
229
|
| RequestProviderInstrumentationEvent
|
|
86
230
|
| ErrorProviderInstrumentationEvent
|
|
@@ -91,36 +235,82 @@ export type ProviderInstrumentationEvent =
|
|
|
91
235
|
| ProviderLifecycleInstrumentationEvent
|
|
92
236
|
| CustomProviderInstrumentationEvent;
|
|
93
237
|
|
|
238
|
+
/**
|
|
239
|
+
* Input accepted by provider instrumentation recorders.
|
|
240
|
+
*/
|
|
94
241
|
export type ProviderInstrumentationEventInput = ProviderInstrumentationEvent;
|
|
95
242
|
|
|
243
|
+
/**
|
|
244
|
+
* Custom instrumentation input. `type: "custom"` is added by the helper.
|
|
245
|
+
*/
|
|
96
246
|
export type ProviderCustomInstrumentationEventInput = Omit<
|
|
97
247
|
CustomProviderInstrumentationEvent,
|
|
98
248
|
"type"
|
|
99
249
|
>;
|
|
100
250
|
|
|
251
|
+
/**
|
|
252
|
+
* Sink for provider instrumentation events.
|
|
253
|
+
*/
|
|
101
254
|
export interface ProviderInstrumentationPort<
|
|
102
255
|
EventInput extends
|
|
103
256
|
ProviderInstrumentationEventInput = ProviderInstrumentationEventInput,
|
|
104
257
|
WatcherName extends string = ProviderInstrumentationWatcherName,
|
|
105
258
|
RecordResult = unknown,
|
|
106
259
|
> {
|
|
260
|
+
/**
|
|
261
|
+
* Record an instrumentation event.
|
|
262
|
+
*/
|
|
107
263
|
record(event: EventInput): RecordResult;
|
|
264
|
+
/**
|
|
265
|
+
* Return whether a watcher is enabled. Missing methods are treated as
|
|
266
|
+
* enabled so simple sinks only need to implement `record`.
|
|
267
|
+
*/
|
|
108
268
|
isWatcherEnabled?(name: WatcherName): boolean;
|
|
109
269
|
}
|
|
110
270
|
|
|
271
|
+
/**
|
|
272
|
+
* Options for creating a provider instrumentation helper.
|
|
273
|
+
*/
|
|
111
274
|
export interface ProviderInstrumentationOptions {
|
|
275
|
+
/**
|
|
276
|
+
* Provider name to attach to custom event details.
|
|
277
|
+
*/
|
|
112
278
|
providerName: string;
|
|
279
|
+
/**
|
|
280
|
+
* Default watcher name for events emitted by the helper.
|
|
281
|
+
*/
|
|
113
282
|
watcher?: ProviderInstrumentationWatcherName;
|
|
283
|
+
/**
|
|
284
|
+
* Optional redactor applied after Beignet's default redaction pass.
|
|
285
|
+
*/
|
|
114
286
|
redact?: Redactor<ProviderInstrumentationEventInput>;
|
|
115
287
|
}
|
|
116
288
|
|
|
289
|
+
/**
|
|
290
|
+
* Convenience wrapper used by providers to emit safe, watcher-aware events.
|
|
291
|
+
*/
|
|
117
292
|
export interface ProviderInstrumentation {
|
|
293
|
+
/**
|
|
294
|
+
* Resolved instrumentation port, when one is available.
|
|
295
|
+
*/
|
|
118
296
|
port: ProviderInstrumentationPort | undefined;
|
|
297
|
+
/**
|
|
298
|
+
* Return whether the given watcher is enabled.
|
|
299
|
+
*/
|
|
119
300
|
isEnabled(watcher?: ProviderInstrumentationWatcherName): boolean;
|
|
301
|
+
/**
|
|
302
|
+
* Record a fully formed provider instrumentation event.
|
|
303
|
+
*/
|
|
120
304
|
record(event: ProviderInstrumentationEventInput): unknown;
|
|
305
|
+
/**
|
|
306
|
+
* Record a provider-owned custom event.
|
|
307
|
+
*/
|
|
121
308
|
custom(event: ProviderCustomInstrumentationEventInput): unknown;
|
|
122
309
|
}
|
|
123
310
|
|
|
311
|
+
/**
|
|
312
|
+
* Values accepted by `createProviderInstrumentation(...)`.
|
|
313
|
+
*/
|
|
124
314
|
export type ProviderInstrumentationTarget =
|
|
125
315
|
| ProviderInstrumentationPort
|
|
126
316
|
| ProviderInstrumentation
|
|
@@ -134,6 +324,9 @@ function isObject(value: unknown): value is Record<string, unknown> {
|
|
|
134
324
|
return typeof value === "object" && value !== null;
|
|
135
325
|
}
|
|
136
326
|
|
|
327
|
+
/**
|
|
328
|
+
* Return whether a value is a provider instrumentation helper.
|
|
329
|
+
*/
|
|
137
330
|
export function isProviderInstrumentation(
|
|
138
331
|
value: unknown,
|
|
139
332
|
): value is ProviderInstrumentation {
|
|
@@ -145,6 +338,9 @@ export function isProviderInstrumentation(
|
|
|
145
338
|
);
|
|
146
339
|
}
|
|
147
340
|
|
|
341
|
+
/**
|
|
342
|
+
* Return whether a value is a provider instrumentation port.
|
|
343
|
+
*/
|
|
148
344
|
export function isProviderInstrumentationPort(
|
|
149
345
|
value: unknown,
|
|
150
346
|
): value is ProviderInstrumentationPort {
|
|
@@ -159,6 +355,10 @@ function resolveProviderInstrumentationValue(
|
|
|
159
355
|
return undefined;
|
|
160
356
|
}
|
|
161
357
|
|
|
358
|
+
/**
|
|
359
|
+
* Resolve an instrumentation port from a direct port, helper, or context-like
|
|
360
|
+
* object.
|
|
361
|
+
*/
|
|
162
362
|
export function resolveProviderInstrumentationPort(
|
|
163
363
|
target: ProviderInstrumentationTarget,
|
|
164
364
|
): ProviderInstrumentationPort | undefined {
|
|
@@ -187,6 +387,10 @@ function withProviderDetails(providerName: string, details: unknown): unknown {
|
|
|
187
387
|
return { providerName, value: details };
|
|
188
388
|
}
|
|
189
389
|
|
|
390
|
+
/**
|
|
391
|
+
* Create a provider instrumentation helper that handles watcher checks,
|
|
392
|
+
* default watcher assignment, redaction, and sink failures.
|
|
393
|
+
*/
|
|
190
394
|
export function createProviderInstrumentation(
|
|
191
395
|
target: ProviderInstrumentationTarget,
|
|
192
396
|
options: ProviderInstrumentationOptions,
|
|
@@ -38,12 +38,24 @@ export interface ProviderConfigDef<CfgSchema extends StandardSchemaV1> {
|
|
|
38
38
|
envPrefix?: string;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Value or promise of that value.
|
|
43
|
+
*/
|
|
41
44
|
export type MaybePromise<T> = T | Promise<T>;
|
|
42
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Context passed to provider lifecycle hooks.
|
|
48
|
+
*/
|
|
43
49
|
export type ProviderLifecycleContext = {
|
|
50
|
+
/**
|
|
51
|
+
* Final app ports after provider setup.
|
|
52
|
+
*/
|
|
44
53
|
ports: Readonly<ProviderPorts>;
|
|
45
54
|
};
|
|
46
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Result returned from provider setup.
|
|
58
|
+
*/
|
|
47
59
|
export type ProviderSetupResult<ProvidedPorts extends ProviderPorts> = {
|
|
48
60
|
/**
|
|
49
61
|
* Ports contributed by this provider.
|
|
@@ -113,7 +125,8 @@ export interface ServiceProvider<
|
|
|
113
125
|
|
|
114
126
|
/**
|
|
115
127
|
* Setup phase: create the ports this provider contributes.
|
|
116
|
-
* Called during
|
|
128
|
+
* Called during server initialization before provider `start` hooks and
|
|
129
|
+
* before the server handles requests.
|
|
117
130
|
*
|
|
118
131
|
* @param ctx.ports - Ports contributed by previous providers
|
|
119
132
|
* @param ctx.config - Validated config (if config was defined), or undefined
|