-
Notifications
You must be signed in to change notification settings - Fork 37
/
index.ts
87 lines (82 loc) · 2.11 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import {
Advised,
Metadata,
MethodMetadata,
beforeMethod,
afterMethod,
beforeGetter,
afterSetter,
afterGetter,
beforeStaticMethod
} from '../lib';
class CacheAspect {
@beforeMethod({
classNamePattern: /^(\w+Mapper|Http)$/,
methodNamePattern: /^get/
})
@beforeStaticMethod({
classNamePattern: /^(\w+Mapper|Http)$/,
methodNamePattern: /^get/
})
before(meta: Metadata) {
console.log(
`Inside CacheAspect.before for ${meta.className}.${meta.method.name} with args ${meta.method.args.join(', ')}`
);
}
@afterMethod({
classNamePattern: /^(\w+Mapper|Http)$/,
methodNamePattern: /^get/
})
@afterGetter({
classNamePattern: /^(\w+Mapper|Http)$/,
propertyNamePattern: /^get/
})
after(meta: Metadata) {
console.log(
`Inside CacheAspect.after for ${meta.className}.${meta.method.name} with args ${meta.method.args.join(', ')}`
);
}
}
// class LoggerAspect {
// @after({ classNamePattern: /.*/, methodNamePattern: /^get/})
// before(meta: Metadata) {
// console.log(`Inside LoggerAspect.before for ${meta.className}.${meta.method.name} with args ${meta.method.args.join(', ')}`);
// }
// @after({ classNamePattern: /.*/, methodNamePattern: /^get/})
// after(meta: Metadata) {
// console.log(`Inside LoggerAspect.after for ${meta.className}.${meta.method.name} with args ${meta.method.args.join(', ')}`);
// }
// }
@Advised()
class Http {
get(url: string) {
console.log(`Called Http.get with url = ${url}`);
}
post(url: string, data: any) {
console.log(`Called Http.post with url = ${url}`);
}
}
@Advised()
class UserMapper {
constructor(private http: Http) {}
get(id: number) {
console.log(`Called UserMapper.get with id = ${id}`);
this.http.get('http://foo.bar');
return 'result';
}
foo() {
console.log('bar');
}
get getfield() {
this.foo();
return 42;
}
static getUserMapper() {
console.log('Inside getUserMapper');
return 42;
}
}
let mapper = new UserMapper(new Http());
// console.log(mapper.get(42));
console.log(mapper.getfield);
// console.log(UserMapper.getUserMapper())