1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | exports.createProxyWithInterceptors = exports.InterceptionHandler = exports.ProxySource = void 0;
|
8 | const context_1 = require("./context");
|
9 | const interceptor_1 = require("./interceptor");
|
10 | const resolution_session_1 = require("./resolution-session");
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | class ProxySource {
|
16 | constructor(value) {
|
17 | this.value = value;
|
18 | this.type = 'proxy';
|
19 | }
|
20 | toString() {
|
21 | return this.value.getBindingPath();
|
22 | }
|
23 | }
|
24 | exports.ProxySource = ProxySource;
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | class InterceptionHandler {
|
31 | constructor(context = new context_1.Context(), session, source) {
|
32 | this.context = context;
|
33 | this.session = session;
|
34 | this.source = source;
|
35 | }
|
36 | get(target, propertyName, receiver) {
|
37 |
|
38 | const targetObj = target;
|
39 | if (typeof propertyName !== 'string')
|
40 | return targetObj[propertyName];
|
41 | const propertyOrMethod = targetObj[propertyName];
|
42 | if (typeof propertyOrMethod === 'function') {
|
43 | return (...args) => {
|
44 | var _a;
|
45 | return (0, interceptor_1.invokeMethodWithInterceptors)(this.context, target, propertyName, args, {
|
46 | source: (_a = this.source) !== null && _a !== void 0 ? _a : (this.session && new ProxySource(this.session)),
|
47 | });
|
48 | };
|
49 | }
|
50 | else {
|
51 | return propertyOrMethod;
|
52 | }
|
53 | }
|
54 | }
|
55 | exports.InterceptionHandler = InterceptionHandler;
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | function createProxyWithInterceptors(target, context, session, source) {
|
64 | return new Proxy(target, new InterceptionHandler(context, resolution_session_1.ResolutionSession.fork(session), source));
|
65 | }
|
66 | exports.createProxyWithInterceptors = createProxyWithInterceptors;
|
67 |
|
\ | No newline at end of file |