@rsdk/actx 6.0.0-next.29 → 6.0.0-next.30
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/context-carrier.d.ts +9 -0
- package/dist/context-carrier.js +3 -0
- package/dist/context-carrier.js.map +1 -0
- package/dist/context.enricher.d.ts +14 -0
- package/dist/context.enricher.js +9 -0
- package/dist/context.enricher.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/ingress.context.d.ts +27 -0
- package/dist/ingress.context.js +62 -0
- package/dist/ingress.context.js.map +1 -0
- package/package.json +2 -2
- package/src/context-carrier.ts +9 -0
- package/src/context.enricher.ts +16 -0
- package/src/index.ts +5 -0
- package/src/ingress.context.ts +50 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Источник пар ключ→значение (заголовки/метадата точки входа), из которого
|
|
3
|
+
* `ContextEnricher` обогащает async-контекст. Транспортно-нейтрален: его
|
|
4
|
+
* структурно реализует `GenericHeaders` из транспортов
|
|
5
|
+
* и т.п.
|
|
6
|
+
*/
|
|
7
|
+
export interface ContextCarrier {
|
|
8
|
+
get(key: string): string | undefined;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-carrier.js","sourceRoot":"","sources":["../src/context-carrier.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ContextCarrier } from './context-carrier';
|
|
2
|
+
/**
|
|
3
|
+
* Обогатитель контекста: кладёт данные из `carrier` в УЖЕ открытый
|
|
4
|
+
* async-контекст. Программный аналог интерсептора-обогатителя из пайплайна
|
|
5
|
+
* (например, `TracingInterceptor`), но переиспользуемый на любом входе.
|
|
6
|
+
*/
|
|
7
|
+
export interface ContextEnricher {
|
|
8
|
+
enrich(carrier: ContextCarrier): void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* DI-токен со списком всех `ContextEnricher`. Собирается из встроенных
|
|
12
|
+
* (трейсинг) и плагинных обогатителей.
|
|
13
|
+
*/
|
|
14
|
+
export declare const CONTEXT_ENRICHERS: unique symbol;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CONTEXT_ENRICHERS = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* DI-токен со списком всех `ContextEnricher`. Собирается из встроенных
|
|
6
|
+
* (трейсинг) и плагинных обогатителей.
|
|
7
|
+
*/
|
|
8
|
+
exports.CONTEXT_ENRICHERS = Symbol('CONTEXT_ENRICHERS');
|
|
9
|
+
//# sourceMappingURL=context.enricher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.enricher.js","sourceRoot":"","sources":["../src/context.enricher.ts"],"names":[],"mappings":";;;AAWA;;;GAGG;AACU,QAAA,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
export { AsyncContextModule } from './async-context.module';
|
|
2
2
|
export { createAsyncContextProvider, AsyncContextProvider, } from './async-context.provider';
|
|
3
|
+
export { IngressContext } from './ingress.context';
|
|
4
|
+
export { CONTEXT_ENRICHERS } from './context.enricher';
|
|
5
|
+
export type { ContextEnricher } from './context.enricher';
|
|
6
|
+
export type { ContextCarrier } from './context-carrier';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createAsyncContextProvider = exports.AsyncContextModule = void 0;
|
|
3
|
+
exports.CONTEXT_ENRICHERS = exports.IngressContext = exports.createAsyncContextProvider = exports.AsyncContextModule = void 0;
|
|
4
4
|
var async_context_module_1 = require("./async-context.module");
|
|
5
5
|
Object.defineProperty(exports, "AsyncContextModule", { enumerable: true, get: function () { return async_context_module_1.AsyncContextModule; } });
|
|
6
6
|
var async_context_provider_1 = require("./async-context.provider");
|
|
7
7
|
Object.defineProperty(exports, "createAsyncContextProvider", { enumerable: true, get: function () { return async_context_provider_1.createAsyncContextProvider; } });
|
|
8
|
+
var ingress_context_1 = require("./ingress.context");
|
|
9
|
+
Object.defineProperty(exports, "IngressContext", { enumerable: true, get: function () { return ingress_context_1.IngressContext; } });
|
|
10
|
+
var context_enricher_1 = require("./context.enricher");
|
|
11
|
+
Object.defineProperty(exports, "CONTEXT_ENRICHERS", { enumerable: true, get: function () { return context_enricher_1.CONTEXT_ENRICHERS; } });
|
|
8
12
|
//# 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,+DAA4D;AAAnD,0HAAA,kBAAkB,OAAA;AAE3B,mEAGkC;AAFhC,oIAAA,0BAA0B,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+DAA4D;AAAnD,0HAAA,kBAAkB,OAAA;AAE3B,mEAGkC;AAFhC,oIAAA,0BAA0B,OAAA;AAI5B,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AACvB,uDAAuD;AAA9C,qHAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ContextEnricher } from './context.enricher';
|
|
2
|
+
import type { ContextCarrier } from './context-carrier';
|
|
3
|
+
/**
|
|
4
|
+
* Транспортно-нейтральная точка входа: открывает свежий async-контекст,
|
|
5
|
+
* обогащает его данными из `carrier` всеми зарегистрированными
|
|
6
|
+
* `ContextEnricher` и выполняет `fn` внутри этого контекста.
|
|
7
|
+
*
|
|
8
|
+
* Программный двойник цепочки `AsyncContextInterceptor` (открыть scope) +
|
|
9
|
+
* интерсепторы-обогатители (`TracingInterceptor` и т.п.) для входов без
|
|
10
|
+
* NestJS-пайплайна: pull-консьюмеры (NATS).
|
|
11
|
+
* Открывает контекст тем же `AsyncContextStorage.run`, что и интерсептор.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ingress.run(new NatsHeaders(msg.headers), () => handle(msg));
|
|
15
|
+
*/
|
|
16
|
+
export declare class IngressContext {
|
|
17
|
+
private readonly enrichers;
|
|
18
|
+
constructor(enrichers: ContextEnricher[]);
|
|
19
|
+
run<T>(carrier: ContextCarrier, fn: () => T): T;
|
|
20
|
+
/**
|
|
21
|
+
* Фиксирует текущий async-контекст и возвращает раннер, исполняющий `fn`
|
|
22
|
+
* в этом зафиксированном контексте. Для отложенного кода (ленивый генератор),
|
|
23
|
+
* который должен помнить контекст точки создания/подписки. Если контекста
|
|
24
|
+
* нет — раннер просто выполняет `fn` как есть.
|
|
25
|
+
*/
|
|
26
|
+
capture(): <T>(fn: () => T) => T;
|
|
27
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.IngressContext = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const async_context_storage_1 = require("./async-context.storage");
|
|
18
|
+
const context_enricher_1 = require("./context.enricher");
|
|
19
|
+
/**
|
|
20
|
+
* Транспортно-нейтральная точка входа: открывает свежий async-контекст,
|
|
21
|
+
* обогащает его данными из `carrier` всеми зарегистрированными
|
|
22
|
+
* `ContextEnricher` и выполняет `fn` внутри этого контекста.
|
|
23
|
+
*
|
|
24
|
+
* Программный двойник цепочки `AsyncContextInterceptor` (открыть scope) +
|
|
25
|
+
* интерсепторы-обогатители (`TracingInterceptor` и т.п.) для входов без
|
|
26
|
+
* NestJS-пайплайна: pull-консьюмеры (NATS).
|
|
27
|
+
* Открывает контекст тем же `AsyncContextStorage.run`, что и интерсептор.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ingress.run(new NatsHeaders(msg.headers), () => handle(msg));
|
|
31
|
+
*/
|
|
32
|
+
let IngressContext = class IngressContext {
|
|
33
|
+
enrichers;
|
|
34
|
+
constructor(enrichers) {
|
|
35
|
+
this.enrichers = enrichers;
|
|
36
|
+
}
|
|
37
|
+
run(carrier, fn) {
|
|
38
|
+
return async_context_storage_1.AsyncContextStorage.run(new Map(), () => {
|
|
39
|
+
for (const enricher of this.enrichers) {
|
|
40
|
+
enricher.enrich(carrier);
|
|
41
|
+
}
|
|
42
|
+
return fn();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Фиксирует текущий async-контекст и возвращает раннер, исполняющий `fn`
|
|
47
|
+
* в этом зафиксированном контексте. Для отложенного кода (ленивый генератор),
|
|
48
|
+
* который должен помнить контекст точки создания/подписки. Если контекста
|
|
49
|
+
* нет — раннер просто выполняет `fn` как есть.
|
|
50
|
+
*/
|
|
51
|
+
capture() {
|
|
52
|
+
const store = async_context_storage_1.AsyncContextStorage.getStore();
|
|
53
|
+
return (fn) => store ? async_context_storage_1.AsyncContextStorage.run(store, fn) : fn();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
exports.IngressContext = IngressContext;
|
|
57
|
+
exports.IngressContext = IngressContext = __decorate([
|
|
58
|
+
(0, common_1.Injectable)(),
|
|
59
|
+
__param(0, (0, common_1.Inject)(context_enricher_1.CONTEXT_ENRICHERS)),
|
|
60
|
+
__metadata("design:paramtypes", [Array])
|
|
61
|
+
], IngressContext);
|
|
62
|
+
//# sourceMappingURL=ingress.context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingress.context.js","sourceRoot":"","sources":["../src/ingress.context.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AAEpD,mEAA8D;AAE9D,yDAAuD;AAGvD;;;;;;;;;;;;GAYG;AAEI,IAAM,cAAc,GAApB,MAAM,cAAc;IAGN;IAFnB,YAEmB,SAA4B;QAA5B,cAAS,GAAT,SAAS,CAAmB;IAC5C,CAAC;IAEJ,GAAG,CAAI,OAAuB,EAAE,EAAW;QACzC,OAAO,2CAAmB,CAAC,GAAG,CAAC,IAAI,GAAG,EAAY,EAAE,GAAG,EAAE;YACvD,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;gBACtC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC3B,CAAC;YAED,OAAO,EAAE,EAAE,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,OAAO;QACL,MAAM,KAAK,GAAG,2CAAmB,CAAC,QAAQ,EAAE,CAAC;QAE7C,OAAO,CAAI,EAAW,EAAK,EAAE,CAC3B,KAAK,CAAC,CAAC,CAAC,2CAAmB,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IACtD,CAAC;CACF,CAAA;AA5BY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,eAAM,EAAC,oCAAiB,CAAC,CAAA;;GAFjB,cAAc,CA4B1B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/actx",
|
|
3
|
-
"version": "6.0.0-next.
|
|
3
|
+
"version": "6.0.0-next.30",
|
|
4
4
|
"description": "Library for AsyncLocalStorage",
|
|
5
5
|
"license": "Apache License 2.0",
|
|
6
6
|
"publishConfig": {
|
|
@@ -15,5 +15,5 @@
|
|
|
15
15
|
"@nestjs/core": "<=10.4.8",
|
|
16
16
|
"rxjs": "^7.8.1"
|
|
17
17
|
},
|
|
18
|
-
"gitHead": "
|
|
18
|
+
"gitHead": "b3508ef34ae639383ce55056f597f2783303bd9f"
|
|
19
19
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Источник пар ключ→значение (заголовки/метадата точки входа), из которого
|
|
3
|
+
* `ContextEnricher` обогащает async-контекст. Транспортно-нейтрален: его
|
|
4
|
+
* структурно реализует `GenericHeaders` из транспортов
|
|
5
|
+
* и т.п.
|
|
6
|
+
*/
|
|
7
|
+
export interface ContextCarrier {
|
|
8
|
+
get(key: string): string | undefined;
|
|
9
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ContextCarrier } from './context-carrier';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Обогатитель контекста: кладёт данные из `carrier` в УЖЕ открытый
|
|
5
|
+
* async-контекст. Программный аналог интерсептора-обогатителя из пайплайна
|
|
6
|
+
* (например, `TracingInterceptor`), но переиспользуемый на любом входе.
|
|
7
|
+
*/
|
|
8
|
+
export interface ContextEnricher {
|
|
9
|
+
enrich(carrier: ContextCarrier): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* DI-токен со списком всех `ContextEnricher`. Собирается из встроенных
|
|
14
|
+
* (трейсинг) и плагинных обогатителей.
|
|
15
|
+
*/
|
|
16
|
+
export const CONTEXT_ENRICHERS = Symbol('CONTEXT_ENRICHERS');
|
package/src/index.ts
CHANGED
|
@@ -4,3 +4,8 @@ export {
|
|
|
4
4
|
createAsyncContextProvider,
|
|
5
5
|
AsyncContextProvider,
|
|
6
6
|
} from './async-context.provider';
|
|
7
|
+
|
|
8
|
+
export { IngressContext } from './ingress.context';
|
|
9
|
+
export { CONTEXT_ENRICHERS } from './context.enricher';
|
|
10
|
+
export type { ContextEnricher } from './context.enricher';
|
|
11
|
+
export type { ContextCarrier } from './context-carrier';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Inject, Injectable } from '@nestjs/common';
|
|
2
|
+
|
|
3
|
+
import { AsyncContextStorage } from './async-context.storage';
|
|
4
|
+
import type { ContextEnricher } from './context.enricher';
|
|
5
|
+
import { CONTEXT_ENRICHERS } from './context.enricher';
|
|
6
|
+
import type { ContextCarrier } from './context-carrier';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Транспортно-нейтральная точка входа: открывает свежий async-контекст,
|
|
10
|
+
* обогащает его данными из `carrier` всеми зарегистрированными
|
|
11
|
+
* `ContextEnricher` и выполняет `fn` внутри этого контекста.
|
|
12
|
+
*
|
|
13
|
+
* Программный двойник цепочки `AsyncContextInterceptor` (открыть scope) +
|
|
14
|
+
* интерсепторы-обогатители (`TracingInterceptor` и т.п.) для входов без
|
|
15
|
+
* NestJS-пайплайна: pull-консьюмеры (NATS).
|
|
16
|
+
* Открывает контекст тем же `AsyncContextStorage.run`, что и интерсептор.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ingress.run(new NatsHeaders(msg.headers), () => handle(msg));
|
|
20
|
+
*/
|
|
21
|
+
@Injectable()
|
|
22
|
+
export class IngressContext {
|
|
23
|
+
constructor(
|
|
24
|
+
@Inject(CONTEXT_ENRICHERS)
|
|
25
|
+
private readonly enrichers: ContextEnricher[],
|
|
26
|
+
) {}
|
|
27
|
+
|
|
28
|
+
run<T>(carrier: ContextCarrier, fn: () => T): T {
|
|
29
|
+
return AsyncContextStorage.run(new Map<any, any>(), () => {
|
|
30
|
+
for (const enricher of this.enrichers) {
|
|
31
|
+
enricher.enrich(carrier);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return fn();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Фиксирует текущий async-контекст и возвращает раннер, исполняющий `fn`
|
|
40
|
+
* в этом зафиксированном контексте. Для отложенного кода (ленивый генератор),
|
|
41
|
+
* который должен помнить контекст точки создания/подписки. Если контекста
|
|
42
|
+
* нет — раннер просто выполняет `fn` как есть.
|
|
43
|
+
*/
|
|
44
|
+
capture(): <T>(fn: () => T) => T {
|
|
45
|
+
const store = AsyncContextStorage.getStore();
|
|
46
|
+
|
|
47
|
+
return <T>(fn: () => T): T =>
|
|
48
|
+
store ? AsyncContextStorage.run(store, fn) : fn();
|
|
49
|
+
}
|
|
50
|
+
}
|