Skip to content

Commit 36f1449

Browse files
jbl428username1103imdudu1
committed
feat: add observable decorator
Co-authored-by: username1103 <[email protected]> Co-authored-by: imdudu1 <[email protected]>
1 parent ad5a4d3 commit 36f1449

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

lib/decorators/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export const REQUEST_FORM_METADATA = Symbol('REQUEST_FORM_METADATA');
77
export const REQUEST_HEADER_METADATA = Symbol('REQUEST_HEADER_METADATA');
88
export const RESPONSE_BODY_METADATA = Symbol('RESPONSE_BODY_METADATA');
99
export const CIRCUIT_BREAKER_METADATA = Symbol('CIRCUIT_BREAKER_METADATA');
10+
export const OBSERVABLE_METADATA = Symbol('OBSERVABLE_METADATA');

lib/decorators/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ export * from './request-header.decorator';
88
export * from './request-param.decorator';
99
export * from './response-body.decorator';
1010
export * from './circuit-breaker.decorator';
11+
export * from './observable-response.decorator';
1112
export * from './constants';
1213
export * from './utils';
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Observable } from 'rxjs';
2+
import { describe, expect, test } from 'vitest';
3+
import { OBSERVABLE_METADATA } from './constants';
4+
import { ObservableResponse } from './observable-response.decorator';
5+
6+
describe('ObservableResponse', () => {
7+
test('should set observable response metadata', () => {
8+
// given
9+
class TestService {
10+
@ObservableResponse()
11+
request(): Observable<string> {
12+
throw new Error();
13+
}
14+
}
15+
16+
// when
17+
const result: boolean = Reflect.hasMetadata(
18+
OBSERVABLE_METADATA,
19+
TestService.prototype,
20+
'request',
21+
);
22+
23+
// then
24+
expect(result).toBe(true);
25+
});
26+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { OBSERVABLE_METADATA } from './constants';
2+
3+
export function ObservableResponse(): MethodDecorator {
4+
return (target, propertyKey) => {
5+
Reflect.defineMetadata(OBSERVABLE_METADATA, true, target, propertyKey);
6+
};
7+
}

0 commit comments

Comments
 (0)