@composed-di/core 0.5.1-alpha → 0.5.3-alpha
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/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/redactingEventListener.d.ts +119 -0
- package/dist/redactingEventListener.d.ts.map +1 -0
- package/dist/redactingEventListener.js +169 -0
- package/dist/redactingEventListener.js.map +1 -0
- package/dist/serviceModule.d.ts +2 -2
- package/dist/serviceModule.d.ts.map +1 -1
- package/dist/serviceModule.js.map +1 -1
- package/dist/serviceModuleListener.d.ts +133 -0
- package/dist/serviceModuleListener.d.ts.map +1 -0
- package/dist/serviceModuleListener.js +3 -0
- package/dist/serviceModuleListener.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +2 -1
- package/src/redactingEventListener.ts +256 -0
- package/src/serviceModule.ts +5 -5
- package/src/{serviceEventListener.ts → serviceModuleListener.ts} +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ export * from './serviceModule';
|
|
|
3
3
|
export * from './serviceFactory';
|
|
4
4
|
export * from './serviceScope';
|
|
5
5
|
export * from './serviceSelector';
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './serviceModuleListener';
|
|
7
|
+
export * from './redactingEventListener';
|
|
7
8
|
export * from './errors';
|
|
8
9
|
export * from './utils';
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -19,7 +19,8 @@ __exportStar(require("./serviceModule"), exports);
|
|
|
19
19
|
__exportStar(require("./serviceFactory"), exports);
|
|
20
20
|
__exportStar(require("./serviceScope"), exports);
|
|
21
21
|
__exportStar(require("./serviceSelector"), exports);
|
|
22
|
-
__exportStar(require("./
|
|
22
|
+
__exportStar(require("./serviceModuleListener"), exports);
|
|
23
|
+
__exportStar(require("./redactingEventListener"), exports);
|
|
23
24
|
__exportStar(require("./errors"), exports);
|
|
24
25
|
__exportStar(require("./utils"), exports);
|
|
25
26
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,kDAAgC;AAChC,mDAAiC;AACjC,iDAA+B;AAC/B,oDAAkC;AAClC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,kDAAgC;AAChC,mDAAiC;AACjC,iDAA+B;AAC/B,oDAAkC;AAClC,0DAAwC;AACxC,2DAAyC;AACzC,2CAAyB;AACzB,0CAAwB"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { DisposeContext, EventSpan, InitializeContext, MethodCallContext, ServiceModuleListener } from './serviceModuleListener';
|
|
2
|
+
import type { ServiceKey } from './serviceKey';
|
|
3
|
+
/**
|
|
4
|
+
* The placeholder that replaces a redacted value when no custom
|
|
5
|
+
* transform is given for it.
|
|
6
|
+
*/
|
|
7
|
+
export declare const REDACTED_VALUE = "[REDACTED]";
|
|
8
|
+
/**
|
|
9
|
+
* Custom masking for one included property, narrowed to the exact
|
|
10
|
+
* method named when {@link RedactionRuleBuilder.redact} is called.
|
|
11
|
+
* Omitting a side fully blanks it with {@link REDACTED_VALUE}; providing
|
|
12
|
+
* one lets you report a partial mask instead (e.g. the last 4 digits of
|
|
13
|
+
* a card number) — both always return a `string`, the masked
|
|
14
|
+
* representation to report in place of the real value.
|
|
15
|
+
*/
|
|
16
|
+
export type Mask<T, K extends Extract<keyof T, string>> = T[K] extends (...args: infer A) => infer R ? {
|
|
17
|
+
maskArgs?: (...args: A) => string;
|
|
18
|
+
maskResult?: (result: R) => string;
|
|
19
|
+
} : never;
|
|
20
|
+
/**
|
|
21
|
+
* Marks a service — or specific properties of it — as sensitive, so the
|
|
22
|
+
* values flowing through its events are redacted. Returned by
|
|
23
|
+
* {@link RedactionRuleBuilder.build}, which is the only way to construct
|
|
24
|
+
* one — the `redactAll`/per-property merge logic lives entirely inside
|
|
25
|
+
* `maskArgs`/`maskResult`, so callers never need to know how a rule
|
|
26
|
+
* reached its decision, only what to do with it.
|
|
27
|
+
*/
|
|
28
|
+
export interface RedactionRule<T> {
|
|
29
|
+
readonly key: ServiceKey<T>;
|
|
30
|
+
/**
|
|
31
|
+
* The args to report for a call to `functionName`: unchanged if not
|
|
32
|
+
* redacted, otherwise blanked or run through a custom `maskArgs`.
|
|
33
|
+
*/
|
|
34
|
+
maskArgs(functionName: string, args: readonly unknown[]): readonly unknown[];
|
|
35
|
+
/**
|
|
36
|
+
* The value to report for a success outcome: unchanged if not
|
|
37
|
+
* redacted, otherwise blanked or run through a custom `maskResult`.
|
|
38
|
+
* Omit `functionName` to ask about the initialize result (the service
|
|
39
|
+
* instance itself), which only the rule's `redactAll` default touches.
|
|
40
|
+
*/
|
|
41
|
+
maskResult(functionName: string | undefined, result: unknown): unknown;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Fluent, single-key rule builder returned by {@link redactionRule}.
|
|
45
|
+
* `redactAll`, `redact`, and `exclude` all merge into the same rule —
|
|
46
|
+
* call them in any combination, in any order; the more specific
|
|
47
|
+
* per-property calls (`redact`/`exclude`) always win over the blanket
|
|
48
|
+
* `redactAll` default for the properties they name.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const rules = [
|
|
53
|
+
* redactionRule(SecretClientKey)
|
|
54
|
+
* .redactAll()
|
|
55
|
+
* .build(), // whole service is sensitive
|
|
56
|
+
* redactionRule(BillingKey)
|
|
57
|
+
* .redactAll()
|
|
58
|
+
* .redact('chargeCard', { maskResult: (card) => `card ending in ${card.number.slice(-4)}` })
|
|
59
|
+
* .exclude('ping') // redact everything except this, with one custom mask
|
|
60
|
+
* .build(),
|
|
61
|
+
* redactionRule(VaultKey)
|
|
62
|
+
* .redact('getSecret')
|
|
63
|
+
* .build(), // only this call, nothing else
|
|
64
|
+
* ];
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare class RedactionRuleBuilder<T> {
|
|
68
|
+
private readonly key;
|
|
69
|
+
private redactAllFlag;
|
|
70
|
+
private readonly overrides;
|
|
71
|
+
constructor(key: ServiceKey<T>);
|
|
72
|
+
/** Redacts every property, plus the initialize result, by default. */
|
|
73
|
+
redactAll(): this;
|
|
74
|
+
/**
|
|
75
|
+
* Marks one property (method) as redacted, with optional custom
|
|
76
|
+
* masking. Call repeatedly for several properties. Overrides
|
|
77
|
+
* `redactAll`/`exclude` for this specific property.
|
|
78
|
+
*/
|
|
79
|
+
redact<K extends Extract<keyof T, string>>(name: K, mask?: Mask<T, K>): this;
|
|
80
|
+
/**
|
|
81
|
+
* Marks one or more properties as explicitly NOT redacted, overriding
|
|
82
|
+
* `redactAll` for just these.
|
|
83
|
+
*/
|
|
84
|
+
exclude(...names: Extract<keyof T, string>[]): this;
|
|
85
|
+
build(): RedactionRule<any>;
|
|
86
|
+
}
|
|
87
|
+
export declare function redactionRule<T>(key: ServiceKey<T>): RedactionRuleBuilder<T>;
|
|
88
|
+
/**
|
|
89
|
+
* A ServiceEventListener decorator that redacts sensitive values before
|
|
90
|
+
* they reach the wrapped listener. Works with any implementation via
|
|
91
|
+
* delegation: arguments in MethodCallContext and success values in
|
|
92
|
+
* EventOutcome are replaced (wholesale, or via a custom transform)
|
|
93
|
+
* before the delegate ever sees them — whatever it captures or exports
|
|
94
|
+
* is already scrubbed.
|
|
95
|
+
*
|
|
96
|
+
* Failure outcomes are passed through unchanged so error reporting keeps
|
|
97
|
+
* working; keep secrets out of error messages at the throwing site.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* const listener = new RedactingEventListener(
|
|
102
|
+
* new OTELEventListener({ captureArguments: true, captureResults: true }),
|
|
103
|
+
* [
|
|
104
|
+
* redactionRule(SecretClientKey).redactAll().build(), // whole service is sensitive
|
|
105
|
+
* redactionRule(VaultKey).redact('getSecret').build(), // only this call
|
|
106
|
+
* redactionRule(HealthKey).redactAll().exclude('ping').build(), // everything but this call
|
|
107
|
+
* ],
|
|
108
|
+
* );
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export declare class RedactingEventListener implements ServiceModuleListener {
|
|
112
|
+
private readonly delegate;
|
|
113
|
+
private readonly rules;
|
|
114
|
+
constructor(delegate: ServiceModuleListener, rules: readonly RedactionRule<any>[]);
|
|
115
|
+
onInitialize(context: InitializeContext): EventSpan | void;
|
|
116
|
+
onDispose(context: DisposeContext): EventSpan | void;
|
|
117
|
+
onMethodCall(context: MethodCallContext): EventSpan | void;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=redactingEventListener.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redactingEventListener.d.ts","sourceRoot":"","sources":["../src/redactingEventList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;OAIG;IACH,MAAM,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI;IAK5E;;;OAGG;IACH,OAAO,CAAC,GAAG,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,GAAG,IAAI;IAOnD,KAAK,IAAI,aAAa,CAAC,GAAG,CAAC;CAwC5B;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAE5E;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,sBAAuB,YAAW,qBAAqB;IAEhE,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK;gBADL,QAAQ,EAAE,qBAAqB,EAC/B,KAAK,EAAE,SAAS,aAAa,CAAC,GAAG,CAAC,EAAE;IAGvD,YAAY,CAAC,OAAO,EAAE,iBAAiB,GAAG,SAAS,GAAG,IAAI;IAK1D,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS,GAAG,IAAI;IAKpD,YAAY,CAAC,OAAO,EAAE,iBAAiB,GAAG,SAAS,GAAG,IAAI;CAY3D"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RedactingEventListener = exports.RedactionRuleBuilder = exports.REDACTED_VALUE = void 0;
|
|
4
|
+
exports.redactionRule = redactionRule;
|
|
5
|
+
/**
|
|
6
|
+
* The placeholder that replaces a redacted value when no custom
|
|
7
|
+
* transform is given for it.
|
|
8
|
+
*/
|
|
9
|
+
exports.REDACTED_VALUE = '[REDACTED]';
|
|
10
|
+
/**
|
|
11
|
+
* Fluent, single-key rule builder returned by {@link redactionRule}.
|
|
12
|
+
* `redactAll`, `redact`, and `exclude` all merge into the same rule —
|
|
13
|
+
* call them in any combination, in any order; the more specific
|
|
14
|
+
* per-property calls (`redact`/`exclude`) always win over the blanket
|
|
15
|
+
* `redactAll` default for the properties they name.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const rules = [
|
|
20
|
+
* redactionRule(SecretClientKey)
|
|
21
|
+
* .redactAll()
|
|
22
|
+
* .build(), // whole service is sensitive
|
|
23
|
+
* redactionRule(BillingKey)
|
|
24
|
+
* .redactAll()
|
|
25
|
+
* .redact('chargeCard', { maskResult: (card) => `card ending in ${card.number.slice(-4)}` })
|
|
26
|
+
* .exclude('ping') // redact everything except this, with one custom mask
|
|
27
|
+
* .build(),
|
|
28
|
+
* redactionRule(VaultKey)
|
|
29
|
+
* .redact('getSecret')
|
|
30
|
+
* .build(), // only this call, nothing else
|
|
31
|
+
* ];
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
class RedactionRuleBuilder {
|
|
35
|
+
constructor(key) {
|
|
36
|
+
this.key = key;
|
|
37
|
+
this.redactAllFlag = false;
|
|
38
|
+
this.overrides = {};
|
|
39
|
+
}
|
|
40
|
+
/** Redacts every property, plus the initialize result, by default. */
|
|
41
|
+
redactAll() {
|
|
42
|
+
this.redactAllFlag = true;
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Marks one property (method) as redacted, with optional custom
|
|
47
|
+
* masking. Call repeatedly for several properties. Overrides
|
|
48
|
+
* `redactAll`/`exclude` for this specific property.
|
|
49
|
+
*/
|
|
50
|
+
redact(name, mask) {
|
|
51
|
+
this.overrides[name] = Object.assign({ redacted: true }, mask);
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Marks one or more properties as explicitly NOT redacted, overriding
|
|
56
|
+
* `redactAll` for just these.
|
|
57
|
+
*/
|
|
58
|
+
exclude(...names) {
|
|
59
|
+
for (const name of names) {
|
|
60
|
+
this.overrides[name] = { redacted: false };
|
|
61
|
+
}
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
build() {
|
|
65
|
+
if (!this.redactAllFlag && Object.keys(this.overrides).length === 0) {
|
|
66
|
+
throw new Error(`redactionRule(${this.key.name}) has no effect: call .redactAll() and/or .redact(...) ` +
|
|
67
|
+
'before .build(), otherwise this rule never redacts anything.');
|
|
68
|
+
}
|
|
69
|
+
const redactAllFlag = this.redactAllFlag;
|
|
70
|
+
const overrides = this.overrides;
|
|
71
|
+
return {
|
|
72
|
+
key: this.key,
|
|
73
|
+
maskArgs(functionName, args) {
|
|
74
|
+
const override = overrides[functionName];
|
|
75
|
+
const redacted = override ? override.redacted : redactAllFlag;
|
|
76
|
+
if (!redacted) {
|
|
77
|
+
return args;
|
|
78
|
+
}
|
|
79
|
+
return (override === null || override === void 0 ? void 0 : override.maskArgs)
|
|
80
|
+
? // A custom mask reports one string for the whole call,
|
|
81
|
+
// rather than a value per argument.
|
|
82
|
+
[override.maskArgs(...args)]
|
|
83
|
+
: // Replace each argument rather than the whole array, so the
|
|
84
|
+
// delegate still sees the call's arity.
|
|
85
|
+
args.map(() => exports.REDACTED_VALUE);
|
|
86
|
+
},
|
|
87
|
+
maskResult(functionName, result) {
|
|
88
|
+
const override = functionName === undefined ? undefined : overrides[functionName];
|
|
89
|
+
const redacted = override ? override.redacted : redactAllFlag;
|
|
90
|
+
if (!redacted) {
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
return (override === null || override === void 0 ? void 0 : override.maskResult)
|
|
94
|
+
? override.maskResult(result)
|
|
95
|
+
: exports.REDACTED_VALUE;
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.RedactionRuleBuilder = RedactionRuleBuilder;
|
|
101
|
+
function redactionRule(key) {
|
|
102
|
+
return new RedactionRuleBuilder(key);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* A ServiceEventListener decorator that redacts sensitive values before
|
|
106
|
+
* they reach the wrapped listener. Works with any implementation via
|
|
107
|
+
* delegation: arguments in MethodCallContext and success values in
|
|
108
|
+
* EventOutcome are replaced (wholesale, or via a custom transform)
|
|
109
|
+
* before the delegate ever sees them — whatever it captures or exports
|
|
110
|
+
* is already scrubbed.
|
|
111
|
+
*
|
|
112
|
+
* Failure outcomes are passed through unchanged so error reporting keeps
|
|
113
|
+
* working; keep secrets out of error messages at the throwing site.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const listener = new RedactingEventListener(
|
|
118
|
+
* new OTELEventListener({ captureArguments: true, captureResults: true }),
|
|
119
|
+
* [
|
|
120
|
+
* redactionRule(SecretClientKey).redactAll().build(), // whole service is sensitive
|
|
121
|
+
* redactionRule(VaultKey).redact('getSecret').build(), // only this call
|
|
122
|
+
* redactionRule(HealthKey).redactAll().exclude('ping').build(), // everything but this call
|
|
123
|
+
* ],
|
|
124
|
+
* );
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
class RedactingEventListener {
|
|
128
|
+
constructor(delegate, rules) {
|
|
129
|
+
this.delegate = delegate;
|
|
130
|
+
this.rules = rules;
|
|
131
|
+
}
|
|
132
|
+
onInitialize(context) {
|
|
133
|
+
var _a, _b;
|
|
134
|
+
const rule = this.rules.find((r) => r.key === context.key);
|
|
135
|
+
return redactSpan((_b = (_a = this.delegate).onInitialize) === null || _b === void 0 ? void 0 : _b.call(_a, context), rule);
|
|
136
|
+
}
|
|
137
|
+
onDispose(context) {
|
|
138
|
+
var _a, _b;
|
|
139
|
+
// Dispose carries no arguments and no result value; nothing to redact.
|
|
140
|
+
return (_b = (_a = this.delegate).onDispose) === null || _b === void 0 ? void 0 : _b.call(_a, context);
|
|
141
|
+
}
|
|
142
|
+
onMethodCall(context) {
|
|
143
|
+
var _a, _b;
|
|
144
|
+
const rule = this.rules.find((r) => r.key === context.key);
|
|
145
|
+
const span = (_b = (_a = this.delegate).onMethodCall) === null || _b === void 0 ? void 0 : _b.call(_a, rule
|
|
146
|
+
? Object.assign(Object.assign({}, context), { args: rule.maskArgs(context.functionName, context.args) }) : context);
|
|
147
|
+
return redactSpan(span, rule, context.functionName);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.RedactingEventListener = RedactingEventListener;
|
|
151
|
+
/**
|
|
152
|
+
* Wraps the delegate's EventSpan so success values are redacted before
|
|
153
|
+
* `end` sees them, by delegating to the rule's `maskResult`. `run` (and
|
|
154
|
+
* any future fields) pass through untouched. `functionName` is omitted
|
|
155
|
+
* for the initialize result (the instance itself).
|
|
156
|
+
*/
|
|
157
|
+
function redactSpan(span, rule, functionName) {
|
|
158
|
+
if (!rule || !(span === null || span === void 0 ? void 0 : span.end)) {
|
|
159
|
+
return span;
|
|
160
|
+
}
|
|
161
|
+
const end = span.end.bind(span);
|
|
162
|
+
return Object.assign(Object.assign({}, span), { end: (outcome) => end(outcome.type === 'success'
|
|
163
|
+
? {
|
|
164
|
+
type: 'success',
|
|
165
|
+
value: rule.maskResult(functionName, outcome.value),
|
|
166
|
+
}
|
|
167
|
+
: outcome) });
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=redactingEventListener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redactingEventListener.js","sourceRoot":"","sources":["../src/redactingEventListener.ts"],"names":[],"mappings":";;;AA2KA,sCAEC;AAnKD;;;GAGG;AACU,QAAA,cAAc,GAAG,YAAY,CAAC;AA0D3C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAa,oBAAoB;IAI/B,YAA6B,GAAkB;QAAlB,QAAG,GAAH,GAAG,CAAe;QAHvC,kBAAa,GAAG,KAAK,CAAC;QACb,cAAS,GAAqC,EAAE,CAAC;IAEhB,CAAC;IAEnD,sEAAsE;IACtE,SAAS;QACP,IAAI,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CAAC;aACpD;YACH,CAAC,CAAC,OAAO,CACZ,IACH;AACJ,CAAC"}
|
package/dist/serviceModule.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ServiceKey } from './serviceKey';
|
|
2
2
|
import { ServiceFactory } from './serviceFactory';
|
|
3
3
|
import { ServiceScope } from './serviceScope';
|
|
4
|
-
import type {
|
|
4
|
+
import type { ServiceModuleListener } from './serviceModuleListener';
|
|
5
5
|
type GenericFactory = ServiceFactory<unknown, readonly ServiceKey<any>[]>;
|
|
6
6
|
/**
|
|
7
7
|
* ServiceModule is a container for service factories and manages dependency resolution.
|
|
@@ -65,7 +65,7 @@ export declare class ServiceModule {
|
|
|
65
65
|
* @return A new ServiceModule containing the deduplicated factories.
|
|
66
66
|
* @throws {ServiceModuleInitError} If circular or missing dependencies are detected during module creation.
|
|
67
67
|
*/
|
|
68
|
-
static from(entries: (ServiceModule | GenericFactory)[], listener?:
|
|
68
|
+
static from(entries: (ServiceModule | GenericFactory)[], listener?: ServiceModuleListener): ServiceModule;
|
|
69
69
|
}
|
|
70
70
|
export {};
|
|
71
71
|
//# sourceMappingURL=serviceModule.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serviceModule.d.ts","sourceRoot":"","sources":["../src/serviceModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAsB,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,KAAK,EAEV,
|
|
1
|
+
{"version":3,"file":"serviceModule.d.ts","sourceRoot":"","sources":["../src/serviceModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAsB,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB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AC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { ServiceKey } from './serviceKey';
|
|
2
|
+
/**
|
|
3
|
+
* A handle representing a single in-flight operation (initialization,
|
|
4
|
+
* disposal, or method call), returned by a ServiceEventListener when the
|
|
5
|
+
* operation starts.
|
|
6
|
+
*
|
|
7
|
+
* `end` is invoked exactly once when the operation finishes, so
|
|
8
|
+
* implementations can close over per-call state (a start time, a span
|
|
9
|
+
* handle, a correlation id) without any bookkeeping to pair concurrent
|
|
10
|
+
* start/finish events.
|
|
11
|
+
*/
|
|
12
|
+
export interface EventSpan {
|
|
13
|
+
/**
|
|
14
|
+
* Optional wrapper around the operation itself. When present, the module
|
|
15
|
+
* invokes the operation as `run(() => operation())`, so the listener can
|
|
16
|
+
* establish ambient state that the operation body and its async
|
|
17
|
+
* continuations inherit — this is what lets spans of nested service
|
|
18
|
+
* calls form a parent-child hierarchy.
|
|
19
|
+
*
|
|
20
|
+
* Implementations must invoke `fn` exactly once, synchronously, and
|
|
21
|
+
* return its result unchanged (for async operations, the promise itself).
|
|
22
|
+
* `end` is still delivered separately when the operation finishes.
|
|
23
|
+
*
|
|
24
|
+
* @param fn - A thunk that performs the operation.
|
|
25
|
+
* @return The value returned by `fn`.
|
|
26
|
+
*/
|
|
27
|
+
run?<T>(fn: () => T): T;
|
|
28
|
+
/**
|
|
29
|
+
* Invoked exactly once when the operation finishes, whether it succeeded
|
|
30
|
+
* or failed. For methods that return a promise, this fires when the
|
|
31
|
+
* promise settles, not when the method returns. On failure, the error is
|
|
32
|
+
* rethrown to the caller after this is invoked.
|
|
33
|
+
*
|
|
34
|
+
* Whether to retain or log the outcome is the implementation's choice;
|
|
35
|
+
* values are passed by reference, so implementations must not mutate them.
|
|
36
|
+
*
|
|
37
|
+
* @param outcome - How the operation finished, and its value or error.
|
|
38
|
+
* @return void
|
|
39
|
+
*/
|
|
40
|
+
end?(outcome: EventOutcome): void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* How an operation finished, delivered to EventSpan.end: `success` carries
|
|
44
|
+
* the value produced by the operation (the return or resolved value for
|
|
45
|
+
* method calls, the service instance for initialize, undefined for
|
|
46
|
+
* dispose); `failure` carries the error that was thrown or rejected.
|
|
47
|
+
*/
|
|
48
|
+
export type EventOutcome = {
|
|
49
|
+
type: 'success';
|
|
50
|
+
value: unknown;
|
|
51
|
+
} | {
|
|
52
|
+
type: 'failure';
|
|
53
|
+
error: unknown;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Context of a service initialization, delivered to onInitialize.
|
|
57
|
+
* Future fields are added here rather than as extra parameters.
|
|
58
|
+
*/
|
|
59
|
+
export interface InitializeContext {
|
|
60
|
+
/**
|
|
61
|
+
* The unique identifier of the service that is being initialized.
|
|
62
|
+
*/
|
|
63
|
+
key: ServiceKey<unknown>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Context of a service disposal, delivered to onDispose.
|
|
67
|
+
* Future fields are added here rather than as extra parameters.
|
|
68
|
+
*/
|
|
69
|
+
export interface DisposeContext {
|
|
70
|
+
/**
|
|
71
|
+
* The unique identifier of the service that is being disposed.
|
|
72
|
+
*/
|
|
73
|
+
key: ServiceKey<unknown>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Context of a method invocation, delivered to onMethodCall.
|
|
77
|
+
* Future fields are added here rather than as extra parameters.
|
|
78
|
+
*/
|
|
79
|
+
export interface MethodCallContext {
|
|
80
|
+
/**
|
|
81
|
+
* The unique identifier of the service the method belongs to.
|
|
82
|
+
*/
|
|
83
|
+
key: ServiceKey<unknown>;
|
|
84
|
+
/**
|
|
85
|
+
* The name of the class implementing the service (the instance's
|
|
86
|
+
* constructor name), which may differ from `key.name`. Undefined for
|
|
87
|
+
* services that are not instances of a named class, such as plain
|
|
88
|
+
* object literals.
|
|
89
|
+
*/
|
|
90
|
+
className?: string;
|
|
91
|
+
/**
|
|
92
|
+
* The name of the method that is being called.
|
|
93
|
+
*/
|
|
94
|
+
functionName: string;
|
|
95
|
+
/**
|
|
96
|
+
* The arguments the method was invoked with, passed by reference;
|
|
97
|
+
* implementations must not mutate them.
|
|
98
|
+
*/
|
|
99
|
+
args: readonly unknown[];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Interface for listening to service events. Implement this interface to
|
|
103
|
+
* observe lifecycle events and method calls of services in a module.
|
|
104
|
+
*
|
|
105
|
+
* Each method is invoked when the corresponding operation starts and may
|
|
106
|
+
* return an EventSpan that is notified when that operation finishes.
|
|
107
|
+
* Returning nothing opts out of completion tracking for that call.
|
|
108
|
+
*/
|
|
109
|
+
export interface ServiceModuleListener {
|
|
110
|
+
/**
|
|
111
|
+
* Invoked at the start of the initialization process for a specific service.
|
|
112
|
+
*
|
|
113
|
+
* @param context - Context of the initialization, including the service key.
|
|
114
|
+
* @return An EventSpan notified when initialization finishes, or void.
|
|
115
|
+
*/
|
|
116
|
+
onInitialize?(context: InitializeContext): EventSpan | void;
|
|
117
|
+
/**
|
|
118
|
+
* Invoked when the disposal process for a service starts.
|
|
119
|
+
*
|
|
120
|
+
* @param context - Context of the disposal, including the service key.
|
|
121
|
+
* @return An EventSpan notified when disposal finishes, or void.
|
|
122
|
+
*/
|
|
123
|
+
onDispose?(context: DisposeContext): EventSpan | void;
|
|
124
|
+
/**
|
|
125
|
+
* Invoked when a method call starts on a service instance.
|
|
126
|
+
*
|
|
127
|
+
* @param context - Context of the invocation, including the service key,
|
|
128
|
+
* the method name, and its arguments.
|
|
129
|
+
* @return An EventSpan notified when the call finishes, or void.
|
|
130
|
+
*/
|
|
131
|
+
onMethodCall?(context: MethodCallContext): EventSpan | void;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=serviceModuleListener.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serviceModuleListener.d.ts","sourceRoot":"","sources":["../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Y,CAAC,CAAC,OAAO,EAAE,iBAAiB,GAAG,SAAS,GAAG,IAAI,CAAC;CAC7D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serviceModuleListener.js","sourceRoot":"","sources":["../src/serviceModuleListener.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from './serviceModule';
|
|
|
3
3
|
export * from './serviceFactory';
|
|
4
4
|
export * from './serviceScope';
|
|
5
5
|
export * from './serviceSelector';
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './serviceModuleListener';
|
|
7
|
+
export * from './redactingEventListener';
|
|
7
8
|
export * from './errors';
|
|
8
9
|
export * from './utils';
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DisposeContext,
|
|
3
|
+
EventOutcome,
|
|
4
|
+
EventSpan,
|
|
5
|
+
InitializeContext,
|
|
6
|
+
MethodCallContext,
|
|
7
|
+
ServiceModuleListener,
|
|
8
|
+
} from './serviceModuleListener';
|
|
9
|
+
import type { ServiceKey } from './serviceKey';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The placeholder that replaces a redacted value when no custom
|
|
13
|
+
* transform is given for it.
|
|
14
|
+
*/
|
|
15
|
+
export const REDACTED_VALUE = '[REDACTED]';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Custom masking for one included property, narrowed to the exact
|
|
19
|
+
* method named when {@link RedactionRuleBuilder.redact} is called.
|
|
20
|
+
* Omitting a side fully blanks it with {@link REDACTED_VALUE}; providing
|
|
21
|
+
* one lets you report a partial mask instead (e.g. the last 4 digits of
|
|
22
|
+
* a card number) — both always return a `string`, the masked
|
|
23
|
+
* representation to report in place of the real value.
|
|
24
|
+
*/
|
|
25
|
+
export type Mask<T, K extends Extract<keyof T, string>> = T[K] extends (
|
|
26
|
+
...args: infer A
|
|
27
|
+
) => infer R
|
|
28
|
+
? {
|
|
29
|
+
maskArgs?: (...args: A) => string;
|
|
30
|
+
maskResult?: (result: R) => string;
|
|
31
|
+
}
|
|
32
|
+
: never;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Per-property override, layered on top of a rule's `redactAll` default.
|
|
36
|
+
* `redacted: true` (from {@link RedactionRuleBuilder.redact}) redacts
|
|
37
|
+
* that property, optionally with a custom mask; `redacted: false` (from
|
|
38
|
+
* {@link RedactionRuleBuilder.exclude}) forces it to be left untouched
|
|
39
|
+
* regardless of `redactAll`.
|
|
40
|
+
*/
|
|
41
|
+
interface PropertyOverride {
|
|
42
|
+
redacted: boolean;
|
|
43
|
+
maskArgs?: (...args: any[]) => string;
|
|
44
|
+
maskResult?: (result: any) => string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Marks a service — or specific properties of it — as sensitive, so the
|
|
49
|
+
* values flowing through its events are redacted. Returned by
|
|
50
|
+
* {@link RedactionRuleBuilder.build}, which is the only way to construct
|
|
51
|
+
* one — the `redactAll`/per-property merge logic lives entirely inside
|
|
52
|
+
* `maskArgs`/`maskResult`, so callers never need to know how a rule
|
|
53
|
+
* reached its decision, only what to do with it.
|
|
54
|
+
*/
|
|
55
|
+
export interface RedactionRule<T> {
|
|
56
|
+
readonly key: ServiceKey<T>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The args to report for a call to `functionName`: unchanged if not
|
|
60
|
+
* redacted, otherwise blanked or run through a custom `maskArgs`.
|
|
61
|
+
*/
|
|
62
|
+
maskArgs(functionName: string, args: readonly unknown[]): readonly unknown[];
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The value to report for a success outcome: unchanged if not
|
|
66
|
+
* redacted, otherwise blanked or run through a custom `maskResult`.
|
|
67
|
+
* Omit `functionName` to ask about the initialize result (the service
|
|
68
|
+
* instance itself), which only the rule's `redactAll` default touches.
|
|
69
|
+
*/
|
|
70
|
+
maskResult(functionName: string | undefined, result: unknown): unknown;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Fluent, single-key rule builder returned by {@link redactionRule}.
|
|
75
|
+
* `redactAll`, `redact`, and `exclude` all merge into the same rule —
|
|
76
|
+
* call them in any combination, in any order; the more specific
|
|
77
|
+
* per-property calls (`redact`/`exclude`) always win over the blanket
|
|
78
|
+
* `redactAll` default for the properties they name.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* const rules = [
|
|
83
|
+
* redactionRule(SecretClientKey)
|
|
84
|
+
* .redactAll()
|
|
85
|
+
* .build(), // whole service is sensitive
|
|
86
|
+
* redactionRule(BillingKey)
|
|
87
|
+
* .redactAll()
|
|
88
|
+
* .redact('chargeCard', { maskResult: (card) => `card ending in ${card.number.slice(-4)}` })
|
|
89
|
+
* .exclude('ping') // redact everything except this, with one custom mask
|
|
90
|
+
* .build(),
|
|
91
|
+
* redactionRule(VaultKey)
|
|
92
|
+
* .redact('getSecret')
|
|
93
|
+
* .build(), // only this call, nothing else
|
|
94
|
+
* ];
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export class RedactionRuleBuilder<T> {
|
|
98
|
+
private redactAllFlag = false;
|
|
99
|
+
private readonly overrides: Record<string, PropertyOverride> = {};
|
|
100
|
+
|
|
101
|
+
constructor(private readonly key: ServiceKey<T>) {}
|
|
102
|
+
|
|
103
|
+
/** Redacts every property, plus the initialize result, by default. */
|
|
104
|
+
redactAll(): this {
|
|
105
|
+
this.redactAllFlag = true;
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Marks one property (method) as redacted, with optional custom
|
|
111
|
+
* masking. Call repeatedly for several properties. Overrides
|
|
112
|
+
* `redactAll`/`exclude` for this specific property.
|
|
113
|
+
*/
|
|
114
|
+
redact<K extends Extract<keyof T, string>>(name: K, mask?: Mask<T, K>): this {
|
|
115
|
+
this.overrides[name] = { redacted: true, ...mask };
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Marks one or more properties as explicitly NOT redacted, overriding
|
|
121
|
+
* `redactAll` for just these.
|
|
122
|
+
*/
|
|
123
|
+
exclude(...names: Extract<keyof T, string>[]): this {
|
|
124
|
+
for (const name of names) {
|
|
125
|
+
this.overrides[name] = { redacted: false };
|
|
126
|
+
}
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
build(): RedactionRule<any> {
|
|
131
|
+
if (!this.redactAllFlag && Object.keys(this.overrides).length === 0) {
|
|
132
|
+
throw new Error(
|
|
133
|
+
`redactionRule(${this.key.name}) has no effect: call .redactAll() and/or .redact(...) ` +
|
|
134
|
+
'before .build(), otherwise this rule never redacts anything.',
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const redactAllFlag = this.redactAllFlag;
|
|
139
|
+
const overrides = this.overrides;
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
key: this.key,
|
|
143
|
+
maskArgs(functionName, args) {
|
|
144
|
+
const override = overrides[functionName];
|
|
145
|
+
const redacted = override ? override.redacted : redactAllFlag;
|
|
146
|
+
if (!redacted) {
|
|
147
|
+
return args;
|
|
148
|
+
}
|
|
149
|
+
return override?.maskArgs
|
|
150
|
+
? // A custom mask reports one string for the whole call,
|
|
151
|
+
// rather than a value per argument.
|
|
152
|
+
[override.maskArgs(...args)]
|
|
153
|
+
: // Replace each argument rather than the whole array, so the
|
|
154
|
+
// delegate still sees the call's arity.
|
|
155
|
+
args.map(() => REDACTED_VALUE);
|
|
156
|
+
},
|
|
157
|
+
maskResult(functionName, result) {
|
|
158
|
+
const override =
|
|
159
|
+
functionName === undefined ? undefined : overrides[functionName];
|
|
160
|
+
const redacted = override ? override.redacted : redactAllFlag;
|
|
161
|
+
if (!redacted) {
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
return override?.maskResult
|
|
165
|
+
? override.maskResult(result)
|
|
166
|
+
: REDACTED_VALUE;
|
|
167
|
+
},
|
|
168
|
+
} as RedactionRule<any>;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function redactionRule<T>(key: ServiceKey<T>): RedactionRuleBuilder<T> {
|
|
173
|
+
return new RedactionRuleBuilder(key);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* A ServiceEventListener decorator that redacts sensitive values before
|
|
178
|
+
* they reach the wrapped listener. Works with any implementation via
|
|
179
|
+
* delegation: arguments in MethodCallContext and success values in
|
|
180
|
+
* EventOutcome are replaced (wholesale, or via a custom transform)
|
|
181
|
+
* before the delegate ever sees them — whatever it captures or exports
|
|
182
|
+
* is already scrubbed.
|
|
183
|
+
*
|
|
184
|
+
* Failure outcomes are passed through unchanged so error reporting keeps
|
|
185
|
+
* working; keep secrets out of error messages at the throwing site.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```ts
|
|
189
|
+
* const listener = new RedactingEventListener(
|
|
190
|
+
* new OTELEventListener({ captureArguments: true, captureResults: true }),
|
|
191
|
+
* [
|
|
192
|
+
* redactionRule(SecretClientKey).redactAll().build(), // whole service is sensitive
|
|
193
|
+
* redactionRule(VaultKey).redact('getSecret').build(), // only this call
|
|
194
|
+
* redactionRule(HealthKey).redactAll().exclude('ping').build(), // everything but this call
|
|
195
|
+
* ],
|
|
196
|
+
* );
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
export class RedactingEventListener implements ServiceModuleListener {
|
|
200
|
+
constructor(
|
|
201
|
+
private readonly delegate: ServiceModuleListener,
|
|
202
|
+
private readonly rules: readonly RedactionRule<any>[],
|
|
203
|
+
) {}
|
|
204
|
+
|
|
205
|
+
onInitialize(context: InitializeContext): EventSpan | void {
|
|
206
|
+
const rule = this.rules.find((r) => r.key === context.key);
|
|
207
|
+
return redactSpan(this.delegate.onInitialize?.(context), rule);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
onDispose(context: DisposeContext): EventSpan | void {
|
|
211
|
+
// Dispose carries no arguments and no result value; nothing to redact.
|
|
212
|
+
return this.delegate.onDispose?.(context);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
onMethodCall(context: MethodCallContext): EventSpan | void {
|
|
216
|
+
const rule = this.rules.find((r) => r.key === context.key);
|
|
217
|
+
const span = this.delegate.onMethodCall?.(
|
|
218
|
+
rule
|
|
219
|
+
? {
|
|
220
|
+
...context,
|
|
221
|
+
args: rule.maskArgs(context.functionName, context.args),
|
|
222
|
+
}
|
|
223
|
+
: context,
|
|
224
|
+
);
|
|
225
|
+
return redactSpan(span, rule, context.functionName);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Wraps the delegate's EventSpan so success values are redacted before
|
|
231
|
+
* `end` sees them, by delegating to the rule's `maskResult`. `run` (and
|
|
232
|
+
* any future fields) pass through untouched. `functionName` is omitted
|
|
233
|
+
* for the initialize result (the instance itself).
|
|
234
|
+
*/
|
|
235
|
+
function redactSpan(
|
|
236
|
+
span: EventSpan | void,
|
|
237
|
+
rule: RedactionRule<any> | undefined,
|
|
238
|
+
functionName?: string,
|
|
239
|
+
): EventSpan | void {
|
|
240
|
+
if (!rule || !span?.end) {
|
|
241
|
+
return span;
|
|
242
|
+
}
|
|
243
|
+
const end = span.end.bind(span);
|
|
244
|
+
return {
|
|
245
|
+
...span,
|
|
246
|
+
end: (outcome: EventOutcome) =>
|
|
247
|
+
end(
|
|
248
|
+
outcome.type === 'success'
|
|
249
|
+
? {
|
|
250
|
+
type: 'success',
|
|
251
|
+
value: rule.maskResult(functionName, outcome.value),
|
|
252
|
+
}
|
|
253
|
+
: outcome,
|
|
254
|
+
),
|
|
255
|
+
};
|
|
256
|
+
}
|
package/src/serviceModule.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { ServiceSelector } from './serviceSelector';
|
|
|
5
5
|
import { ServiceFactoryNotFoundError, ServiceModuleInitError } from './errors';
|
|
6
6
|
import type {
|
|
7
7
|
EventSpan,
|
|
8
|
-
|
|
9
|
-
} from './
|
|
8
|
+
ServiceModuleListener,
|
|
9
|
+
} from './serviceModuleListener';
|
|
10
10
|
|
|
11
11
|
type GenericFactory = ServiceFactory<unknown, readonly ServiceKey<any>[]>;
|
|
12
12
|
type GenericKey = ServiceKey<any>;
|
|
@@ -123,7 +123,7 @@ export class ServiceModule {
|
|
|
123
123
|
*/
|
|
124
124
|
static from(
|
|
125
125
|
entries: (ServiceModule | GenericFactory)[],
|
|
126
|
-
listener?:
|
|
126
|
+
listener?: ServiceModuleListener,
|
|
127
127
|
): ServiceModule {
|
|
128
128
|
// Flatten entries and keep only the last factory for each ServiceKey
|
|
129
129
|
const flattened = entries.flatMap((e) =>
|
|
@@ -277,7 +277,7 @@ function isSuitable<T, D extends readonly ServiceKey<any>[]>(
|
|
|
277
277
|
* @return A new service factory that provides the same dependencies but includes event notification logic.
|
|
278
278
|
*/
|
|
279
279
|
function makeObservable<T, D extends readonly ServiceKey<any>[]>(
|
|
280
|
-
listener:
|
|
280
|
+
listener: ServiceModuleListener,
|
|
281
281
|
delegate: ServiceFactory<any, D>,
|
|
282
282
|
): ServiceFactory<T, D> {
|
|
283
283
|
const key = delegate.provides;
|
|
@@ -330,7 +330,7 @@ function makeObservable<T, D extends readonly ServiceKey<any>[]>(
|
|
|
330
330
|
*/
|
|
331
331
|
function observeMethodCalls(
|
|
332
332
|
thing: any,
|
|
333
|
-
listener:
|
|
333
|
+
listener: ServiceModuleListener,
|
|
334
334
|
key: ServiceKey<unknown>,
|
|
335
335
|
): any {
|
|
336
336
|
if (typeof thing !== 'object' || thing === null) {
|
|
@@ -111,7 +111,7 @@ export interface MethodCallContext {
|
|
|
111
111
|
* return an EventSpan that is notified when that operation finishes.
|
|
112
112
|
* Returning nothing opts out of completion tracking for that call.
|
|
113
113
|
*/
|
|
114
|
-
export interface
|
|
114
|
+
export interface ServiceModuleListener {
|
|
115
115
|
/**
|
|
116
116
|
* Invoked at the start of the initialization process for a specific service.
|
|
117
117
|
*
|