@pristine-ts/networking 2.0.2 → 2.0.3
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/lib/cjs/contexts/contexts.js +18 -0
- package/dist/lib/cjs/contexts/contexts.js.map +1 -0
- package/dist/lib/cjs/contexts/request-context.js +24 -0
- package/dist/lib/cjs/contexts/request-context.js.map +1 -0
- package/dist/lib/cjs/handlers/request.event-handler.js +0 -2
- package/dist/lib/cjs/handlers/request.event-handler.js.map +1 -1
- package/dist/lib/cjs/interceptors/request-body-converter.interceptor.js +3 -3
- package/dist/lib/cjs/interceptors/request-body-converter.interceptor.js.map +1 -1
- package/dist/lib/cjs/managers/managers.js +18 -0
- package/dist/lib/cjs/managers/managers.js.map +1 -0
- package/dist/lib/cjs/managers/request-context.manager.js +98 -0
- package/dist/lib/cjs/managers/request-context.manager.js.map +1 -0
- package/dist/lib/cjs/networking.module.js +2 -0
- package/dist/lib/cjs/networking.module.js.map +1 -1
- package/dist/lib/cjs/router.js +154 -155
- package/dist/lib/cjs/router.js.map +1 -1
- package/dist/lib/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/lib/esm/contexts/contexts.js +2 -0
- package/dist/lib/esm/contexts/contexts.js.map +1 -0
- package/dist/lib/esm/contexts/request-context.js +20 -0
- package/dist/lib/esm/contexts/request-context.js.map +1 -0
- package/dist/lib/esm/handlers/request.event-handler.js +0 -2
- package/dist/lib/esm/handlers/request.event-handler.js.map +1 -1
- package/dist/lib/esm/interceptors/request-body-converter.interceptor.js +3 -3
- package/dist/lib/esm/interceptors/request-body-converter.interceptor.js.map +1 -1
- package/dist/lib/esm/managers/managers.js +2 -0
- package/dist/lib/esm/managers/managers.js.map +1 -0
- package/dist/lib/esm/managers/request-context.manager.js +95 -0
- package/dist/lib/esm/managers/request-context.manager.js.map +1 -0
- package/dist/lib/esm/networking.module.js +2 -0
- package/dist/lib/esm/networking.module.js.map +1 -1
- package/dist/lib/esm/router.js +154 -155
- package/dist/lib/esm/router.js.map +1 -1
- package/dist/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/types/contexts/contexts.d.ts +1 -0
- package/dist/types/contexts/request-context.d.ts +24 -0
- package/dist/types/managers/managers.d.ts +1 -0
- package/dist/types/managers/request-context.manager.d.ts +43 -0
- package/dist/types/networking.module.d.ts +2 -0
- package/dist/types/router.d.ts +3 -1
- package/package.json +7 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contexts.js","sourceRoot":"","sources":["../../../../src/contexts/contexts.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-HTTP-request state, scoped to the lifetime of one routed request. Layered
|
|
3
|
+
* **inside** the framework's `EventContext` (which holds `eventId`/`traceId`/`container`):
|
|
4
|
+
* a controller method running inside an HTTP request can read both the EventContext
|
|
5
|
+
* primitives and these networking-specific slots.
|
|
6
|
+
*
|
|
7
|
+
* Owned by `@pristine-ts/networking`. Apps that don't import the networking module
|
|
8
|
+
* never see this type — `Request`, `MethodRouterNode`, and `IdentityInterface` are
|
|
9
|
+
* concerns of HTTP-shaped flows, not of the framework as a whole.
|
|
10
|
+
*
|
|
11
|
+
* Populated incrementally as the router progresses through the request lifecycle:
|
|
12
|
+
* - `request` is set the moment the context is installed (route matching has
|
|
13
|
+
* succeeded by then; a 404 short-circuits before installation).
|
|
14
|
+
* - `methodNode` is set immediately after request (always together).
|
|
15
|
+
* - `identity` fills in once the authentication pipeline runs. Until then,
|
|
16
|
+
* downstream code that reads `identity` from the context sees `undefined`.
|
|
17
|
+
*/
|
|
18
|
+
export class RequestContext {
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=request-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-context.js","sourceRoot":"","sources":["../../../../src/contexts/request-context.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,cAAc;CAI1B"}
|
|
@@ -58,7 +58,6 @@ let RequestEventHandler = class RequestEventHandler {
|
|
|
58
58
|
extra: {
|
|
59
59
|
event,
|
|
60
60
|
},
|
|
61
|
-
eventId: event.id,
|
|
62
61
|
breadcrumb: `${NetworkingModuleKeyname}:request.event-handler:handle`,
|
|
63
62
|
});
|
|
64
63
|
const start = performance.now();
|
|
@@ -71,7 +70,6 @@ let RequestEventHandler = class RequestEventHandler {
|
|
|
71
70
|
responseBody: response.body,
|
|
72
71
|
responseHeaders: response.headers,
|
|
73
72
|
},
|
|
74
|
-
eventId: event.id,
|
|
75
73
|
extra: {
|
|
76
74
|
event,
|
|
77
75
|
response,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.event-handler.js","sourceRoot":"","sources":["../../../../src/handlers/request.event-handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAA+B,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAsB,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAEjE,OAAO,EAAC,YAAY,EAAE,OAAO,EAAY,wBAAwB,EAAE,GAAG,EAAC,MAAM,qBAAqB,CAAC;AAEnG,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAC;AAM9D,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAG9B,YAAuC,MAAwC,EACpC,UAAgD,EAC5C,cAAwD,EACnC,mBAAyD,EAC3E,0BAAuE;QAJjE,WAAM,GAAN,MAAM,CAAiB;QACnB,eAAU,GAAV,UAAU,CAAqB;QAC3B,mBAAc,GAAd,cAAc,CAAyB;QAClB,wBAAmB,GAAnB,mBAAmB,CAAqB;QAC1D,+BAA0B,GAA1B,0BAA0B,CAA4B;QANzH,aAAQ,GAAW,KAAK,CAAC,CAAC,wHAAwH;IAQlJ,CAAC;IAED,QAAQ,CAAI,KAAe;QACzB,OAAO,KAAK,CAAC,OAAO,YAAY,OAAO,CAAC;IAC1C,CAAC;IAEK,MAAM,CAAC,KAAqB;;YAChC,8CAA8C;YAC9C,yCAAyC;YACzC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;YACnB,gBAAgB;YAChB,qEAAqE;YACrE,EAAE;YACF,0BAA0B;YAC1B,0BAA0B;YAC1B,EAAE;YACF,4CAA4C;YAC5C,yDAAyD;YAGzD,iDAAiD;YACjD,qEAAqE;YAErE,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,qBAAqB,KAAK,CAAC,OAAO,CAAC,UAAU,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE;gBAC1F,UAAU,EAAE;oBACV,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI;oBACxB,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO;iBAC/B;gBACD,KAAK,EAAE;oBACL,KAAK;iBACN;gBACD,
|
|
1
|
+
{"version":3,"file":"request.event-handler.js","sourceRoot":"","sources":["../../../../src/handlers/request.event-handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAA+B,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAsB,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAEjE,OAAO,EAAC,YAAY,EAAE,OAAO,EAAY,wBAAwB,EAAE,GAAG,EAAC,MAAM,qBAAqB,CAAC;AAEnG,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAC;AAM9D,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAG9B,YAAuC,MAAwC,EACpC,UAAgD,EAC5C,cAAwD,EACnC,mBAAyD,EAC3E,0BAAuE;QAJjE,WAAM,GAAN,MAAM,CAAiB;QACnB,eAAU,GAAV,UAAU,CAAqB;QAC3B,mBAAc,GAAd,cAAc,CAAyB;QAClB,wBAAmB,GAAnB,mBAAmB,CAAq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ACpJ,UAAU,EAAE;oBACV,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI;oBAC/B,cAAc,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO;oBACrC,YAAY,EAAE,QAAQ,CAAC,IAAI;oBAC3B,eAAe,EAAE,QAAQ,CAAC,OAAO;iBAClC;gBACD,KAAK,EAAE;oBACL,KAAK;oBACL,QAAQ;iBACT;gBACD,WAAW,EAAE;oBACX,iBAAiB,EAAE,IAAI;iBACxB;aACF,CAAC,CAAA;YAEF,gBAAgB;YAChB,kFAAkF;YAElF,OAAO,IAAI,aAAa,CAAoB,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC/D,CAAC;KAAA;CAEF,CAAA;AAvEY,mBAAmB;IAH/B,YAAY,CAAC,uBAAuB,CAAC;IACrC,GAAG,CAAC,wBAAwB,CAAC,YAAY,CAAC;IAC1C,UAAU,EAAE;IAIE,WAAA,MAAM,CAAC,iBAAiB,CAAC,CAAA;IACzB,WAAA,MAAM,CAAC,qBAAqB,CAAC,CAAA;IAC7B,WAAA,MAAM,CAAC,yBAAyB,CAAC,CAAA;IACjC,WAAA,MAAM,CAAC,wBAAwB,CAAC,qBAAqB,CAAC,CAAA;IACtD,WAAA,MAAM,CAAC,4BAA4B,CAAC,CAAA;;GAPtC,mBAAmB,CAuE/B"}
|
|
@@ -62,7 +62,7 @@ let RequestBodyConverterInterceptor = class RequestBodyConverterInterceptor {
|
|
|
62
62
|
case "object":
|
|
63
63
|
if (request.body.constructor === Date) {
|
|
64
64
|
const errorMessage = "RequestBodyConverterInterceptor: This request has the Content-Type header 'application/json' but the body is a Date object which is invalid JSON.";
|
|
65
|
-
this.logHandler.error(errorMessage
|
|
65
|
+
this.logHandler.error(errorMessage);
|
|
66
66
|
throw new InvalidBodyHttpError(errorMessage);
|
|
67
67
|
}
|
|
68
68
|
return request;
|
|
@@ -74,13 +74,13 @@ let RequestBodyConverterInterceptor = class RequestBodyConverterInterceptor {
|
|
|
74
74
|
}
|
|
75
75
|
catch (e) {
|
|
76
76
|
const errorMessage = "RequestBodyConverterInterceptor: This request has the Content-Type header 'application/json', and the body is of type string, but the body contains invalid JSON.";
|
|
77
|
-
this.logHandler.error(errorMessage
|
|
77
|
+
this.logHandler.error(errorMessage);
|
|
78
78
|
throw new InvalidBodyHttpError(errorMessage);
|
|
79
79
|
}
|
|
80
80
|
break;
|
|
81
81
|
default:
|
|
82
82
|
const errorMessage = "RequestBodyConverterInterceptor: This request has the Content-Type header 'application/json' but the body contains invalid JSON.";
|
|
83
|
-
this.logHandler.error(errorMessage
|
|
83
|
+
this.logHandler.error(errorMessage);
|
|
84
84
|
throw new InvalidBodyHttpError(errorMessage);
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-body-converter.interceptor.js","sourceRoot":"","sources":["../../../../src/interceptors/request-body-converter.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAC,2BAA2B,EAAC,MAAM,kCAAkC,CAAC;AAE7E,OAAO,EAAC,YAAY,EAAE,YAAY,EAAW,wBAAwB,EAAE,GAAG,EAAC,MAAM,qBAAqB,CAAC;AACvG,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAC;AAErE,OAAO,EAAC,oBAAoB,EAAC,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAC,8BAA8B,EAAC,MAAM,4CAA4C,CAAC;AAE1F;;;GAGG;AAII,IAAM,+BAA+B,GAArC,MAAM,+BAA+B;IAI1C;;;;;OAKG;IACH,YAAoF,QAAkC,EAC3E,UAAgD;QADU,aAAQ,GAAR,QAAQ,CAAS;QAC1D,eAAU,GAAV,UAAU,CAAqB;QAT3F,aAAQ,GAAG,8BAA8B,CAAC,aAAa,CAAC;IAUxD,CAAC;IAED;;;OAGG;IACG,gBAAgB,CAAC,OAAgB;;YACrC,IAAI,IAAI,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC;gBAC5B,OAAO,OAAO,CAAC;YACjB,CAAC;YAED,IAAI,OAAO,CAAC,SAAS,CAAC,cAAc,CAAC,KAAK,KAAK,EAAE,CAAC;gBAChD,OAAO,OAAO,CAAC;YACjB,CAAC;YAED,MAAM,WAAW,GAAW,OAAO,CAAC,SAAS,CAAC,cAAc,CAAW,CAAC;YAExE,QAAQ,WAAW,CAAC,WAAW,EAAE,EAAE,CAAC;gBAClC,KAAK,kBAAkB;oBAGrB,QAAQ,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;wBAC5B,KAAK,WAAW;4BACd,OAAO,OAAO,CAAC;wBACjB,KAAK,QAAQ;4BACX,IAAI,OAAO,CAAC,IAAI,CAAC,WAAW,KAAK,IAAI,EAAE,CAAC;gCACtC,MAAM,YAAY,GAAG,mJAAmJ,CAAC;gCACzK,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"request-body-converter.interceptor.js","sourceRoot":"","sources":["../../../../src/interceptors/request-body-converter.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAC,2BAA2B,EAAC,MAAM,kCAAkC,CAAC;AAE7E,OAAO,EAAC,YAAY,EAAE,YAAY,EAAW,wBAAwB,EAAE,GAAG,EAAC,MAAM,qBAAqB,CAAC;AACvG,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAC;AAErE,OAAO,EAAC,oBAAoB,EAAC,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAC,8BAA8B,EAAC,MAAM,4CAA4C,CAAC;AAE1F;;;GAGG;AAII,IAAM,+BAA+B,GAArC,MAAM,+BAA+B;IAI1C;;;;;OAKG;IACH,YAAoF,QAAkC,EAC3E,UAAgD;QADU,aAAQ,GAAR,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,CAAC;4BAC/C,CAAC;4BACD,MAAM;wBAER;4BACE,MAAM,YAAY,GAAG,kIAAkI,CAAC;4BACxJ,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;4BAEpC,MAAM,IAAI,oBAAoB,CAAC,YAAY,CAAC,CAAC;oBACjD,CAAC;YAGL,CAAC;YAED,OAAO,OAAO,CAAC;QACjB,CAAC;KAAA;CAEF,CAAA;AAvEY,+BAA+B;IAH3C,GAAG,CAAC,wBAAwB,CAAC,kBAAkB,CAAC;IAChD,YAAY,CAAC,uBAAuB,CAAC;IACrC,UAAU,EAAE;IAWE,WAAA,YAAY,CAAC,2BAA2B,CAAC,4BAA4B,CAAC,CAAA;IACtE,WAAA,MAAM,CAAC,qBAAqB,CAAC,CAAA;;GAX/B,+BAA+B,CAuE3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"managers.js","sourceRoot":"","sources":["../../../../src/managers/managers.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var RequestContextManager_1;
|
|
8
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
9
|
+
import { injectable } from "tsyringe";
|
|
10
|
+
import { EventContextManager } from "@pristine-ts/common";
|
|
11
|
+
/**
|
|
12
|
+
* Owns the `AsyncLocalStorage` instance that propagates the active `RequestContext`
|
|
13
|
+
* across `await` boundaries for HTTP-routed code.
|
|
14
|
+
*
|
|
15
|
+
* Nested inside the framework's `EventContext`: when the router installs a
|
|
16
|
+
* `RequestContext`, the surrounding `EventContext` (`eventId`/`traceId`/`container`)
|
|
17
|
+
* is still active, so application code inside a controller method can read both.
|
|
18
|
+
*
|
|
19
|
+
* Same shape as `EventContextManager` — `run` + read accessors + static convenience
|
|
20
|
+
* mirrors + `bind` for the background-work escape hatch.
|
|
21
|
+
*
|
|
22
|
+
* Application code outside the networking module never sees this manager. Code inside
|
|
23
|
+
* the networking module uses it to look up the active request without threading it
|
|
24
|
+
* through every method parameter.
|
|
25
|
+
*/
|
|
26
|
+
let RequestContextManager = RequestContextManager_1 = class RequestContextManager {
|
|
27
|
+
run(ctx, fn) {
|
|
28
|
+
return RequestContextManager_1.als.run(ctx, fn);
|
|
29
|
+
}
|
|
30
|
+
current() {
|
|
31
|
+
return RequestContextManager_1.als.getStore();
|
|
32
|
+
}
|
|
33
|
+
request() {
|
|
34
|
+
var _a;
|
|
35
|
+
return (_a = this.current()) === null || _a === void 0 ? void 0 : _a.request;
|
|
36
|
+
}
|
|
37
|
+
methodNode() {
|
|
38
|
+
var _a;
|
|
39
|
+
return (_a = this.current()) === null || _a === void 0 ? void 0 : _a.methodNode;
|
|
40
|
+
}
|
|
41
|
+
identity() {
|
|
42
|
+
var _a;
|
|
43
|
+
return (_a = this.current()) === null || _a === void 0 ? void 0 : _a.identity;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Convenience alias for `EventContextManager.eventId()`. The framework's correlation
|
|
47
|
+
* id (`eventId`) is the same value HTTP people often call "request id" — exposing it
|
|
48
|
+
* here as `requestId()` makes it discoverable next to `request()` / `identity()`
|
|
49
|
+
* without duplicating storage. There is no `RequestContext.requestId` field — the
|
|
50
|
+
* canonical slot lives on `EventContext` and we delegate at lookup time, so the two
|
|
51
|
+
* values can never drift.
|
|
52
|
+
*/
|
|
53
|
+
requestId() {
|
|
54
|
+
return EventContextManager.eventId();
|
|
55
|
+
}
|
|
56
|
+
bind(fn) {
|
|
57
|
+
const ctx = this.current();
|
|
58
|
+
if (ctx === undefined)
|
|
59
|
+
return fn;
|
|
60
|
+
const als = RequestContextManager_1.als;
|
|
61
|
+
return ((...args) => als.run(ctx, () => fn(...args)));
|
|
62
|
+
}
|
|
63
|
+
// ── Static convenience mirrors. ────────────────────────────────────────────────
|
|
64
|
+
static current() {
|
|
65
|
+
return RequestContextManager_1.als.getStore();
|
|
66
|
+
}
|
|
67
|
+
static request() {
|
|
68
|
+
var _a;
|
|
69
|
+
return (_a = RequestContextManager_1.current()) === null || _a === void 0 ? void 0 : _a.request;
|
|
70
|
+
}
|
|
71
|
+
static methodNode() {
|
|
72
|
+
var _a;
|
|
73
|
+
return (_a = RequestContextManager_1.current()) === null || _a === void 0 ? void 0 : _a.methodNode;
|
|
74
|
+
}
|
|
75
|
+
static identity() {
|
|
76
|
+
var _a;
|
|
77
|
+
return (_a = RequestContextManager_1.current()) === null || _a === void 0 ? void 0 : _a.identity;
|
|
78
|
+
}
|
|
79
|
+
static requestId() {
|
|
80
|
+
return EventContextManager.eventId();
|
|
81
|
+
}
|
|
82
|
+
static bind(fn) {
|
|
83
|
+
const ctx = RequestContextManager_1.current();
|
|
84
|
+
if (ctx === undefined)
|
|
85
|
+
return fn;
|
|
86
|
+
const als = RequestContextManager_1.als;
|
|
87
|
+
return ((...args) => als.run(ctx, () => fn(...args)));
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
RequestContextManager.als = new AsyncLocalStorage();
|
|
91
|
+
RequestContextManager = RequestContextManager_1 = __decorate([
|
|
92
|
+
injectable()
|
|
93
|
+
], RequestContextManager);
|
|
94
|
+
export { RequestContextManager };
|
|
95
|
+
//# sourceMappingURL=request-context.manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-context.manager.js","sourceRoot":"","sources":["../../../../src/managers/request-context.manager.ts"],"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,EAAE,CAAC;IAC9C,CAAC;IAED,MAAM,CAAC,OAAO;;QACZ,OAAO,MAAA,uBAAqB,CAAC,OAAO,EAAE,0CAAE,OAAO,CAAC;IAClD,CAAC;IAED,MAAM,CAAC,UAAU;;QACf,OAAO,MAAA,uBAAqB,CAAC,OAAO,EAAE,0CAAE,UAAU,CAAC;IACrD,CAAC;IAED,MAAM,CAAC,QAAQ;;QACb,OAAO,MAAA,uBAAqB,CAAC,OAAO,EAAE,0CAAE,QAAQ,CAAC;IACnD,CAAC;IAED,MAAM,CAAC,SAAS;QACd,OAAO,mBAAmB,CAAC,OAAO,EAAE,CAAC;IACvC,CAAC;IAED,MAAM,CAAC,IAAI,CAAoC,EAAK;QAClD,MAAM,GAAG,GAAG,uBAAqB,CAAC,OAAO,EAAE,CAAC;QAC5C,IAAI,GAAG,KAAK,SAAS;YAAE,OAAO,EAAE,CAAC;QACjC,MAAM,GAAG,GAAG,uBAAqB,CAAC,GAAG,CAAC;QACtC,OAAO,CAAC,CAAC,GAAG,IAAW,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAM,CAAC;IACpE,CAAC;;AAtEuB,yBAAG,GAAG,IAAI,iBAAiB,EAAkB,AAA1C,CAA2C;AAD3D,qBAAqB;IADjC,UAAU,EAAE;GACA,qBAAqB,CAwEjC"}
|
|
@@ -5,12 +5,14 @@ import { BooleanResolver, EnvironmentVariableResolver } from "@pristine-ts/confi
|
|
|
5
5
|
import { LoggingModule } from "@pristine-ts/logging";
|
|
6
6
|
import { DataMappingModule } from "@pristine-ts/data-mapping";
|
|
7
7
|
export * from "./cache/cache";
|
|
8
|
+
export * from "./contexts/contexts";
|
|
8
9
|
export * from "./decorators/decorators";
|
|
9
10
|
export * from "./enums/enums";
|
|
10
11
|
export * from "./errors/errors";
|
|
11
12
|
export * from "./handlers/handlers";
|
|
12
13
|
export * from "./interceptors/interceptors";
|
|
13
14
|
export * from "./interfaces/interfaces";
|
|
15
|
+
export * from "./managers/managers";
|
|
14
16
|
export * from "./mappers/mappers";
|
|
15
17
|
export * from "./models/models";
|
|
16
18
|
export * from "./nodes/nodes";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"networking.module.js","sourceRoot":"","sources":["../../../src/networking.module.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,uBAAuB,EAAC,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAC,cAAc,EAAC,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAC,eAAe,EAAC,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAC,eAAe,EAAE,2BAA2B,EAAC,MAAM,4BAA4B,CAAC;AACxF,OAAO,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAC,iBAAiB,EAAC,MAAM,2BAA2B,CAAC;AAE5D,cAAc,eAAe,CAAC;AAC9B,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAE9B,cAAc,UAAU,CAAC;AAEzB,cAAc,iCAAiC,CAAC;AAChD,MAAM,CAAC,MAAM,gBAAgB,GAAoB;IAC/C,OAAO,EAAE,uBAAuB;IAChC,aAAa,EAAE;QACb,aAAa;QACb,cAAc;QACd,eAAe;QACf,iBAAiB;KAClB;IACD,wBAAwB,EAAE;QACxB;;WAEG;QACH;YACE,aAAa,EAAE,uBAAuB,GAAG,gCAAgC;YACzE,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,IAAI;YAClB,gBAAgB,EAAE;gBAChB,IAAI,eAAe,CAAC,IAAI,2BAA2B,CAAC,sDAAsD,CAAC,CAAC;aAC7G;SACF;QAED;;WAEG;QACH;YACE,aAAa,EAAE,uBAAuB,GAAG,4CAA4C;YACrF,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,IAAI;YAClB,gBAAgB,EAAE;gBAChB,IAAI,eAAe,CAAC,IAAI,2BAA2B,CAAC,oEAAoE,CAAC,CAAC;aAC3H;SACF;QAED;;WAEG;QACH;YACE,aAAa,EAAE,uBAAuB,GAAG,mCAAmC;YAC5E,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,kBAAkB;YAChC,gBAAgB,EAAE;gBAChB,IAAI,2BAA2B,CAAC,0DAA0D,CAAC;aAC5F;SACF;QAED;;WAEG;QACH;YACE,aAAa,EAAE,uBAAuB,GAAG,uBAAuB;YAChE,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,KAAK;YACnB,gBAAgB,EAAE;gBAChB,IAAI,eAAe,CAAC,IAAI,2BAA2B,CAAC,4CAA4C,CAAC,CAAC;aACnG;SACF;QAED;;WAEG;QACH;YACE,aAAa,EAAE,uBAAuB,GAAG,qCAAqC;YAC9E,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,IAAI;YAClB,gBAAgB,EAAE;gBAChB,IAAI,eAAe,CAAC,IAAI,2BAA2B,CAAC,wDAAwD,CAAC,CAAC;aAC/G;SACF;KACF;CACF,CAAA"}
|
|
1
|
+
{"version":3,"file":"networking.module.js","sourceRoot":"","sources":["../../../src/networking.module.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,uBAAuB,EAAC,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAC,cAAc,EAAC,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAC,eAAe,EAAC,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAC,eAAe,EAAE,2BAA2B,EAAC,MAAM,4BAA4B,CAAC;AACxF,OAAO,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AACnD,OAA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