File tree Expand file tree Collapse file tree 3 files changed +17
-14
lines changed
src/components/authorization/policy Expand file tree Collapse file tree 3 files changed +17
-14
lines changed Original file line number Diff line number Diff line change @@ -3,4 +3,4 @@ export * from './missing-context.exception';
3
3
export * from './aggregate.condition' ;
4
4
export * from './calculated.condition' ;
5
5
export * from './eql.util' ;
6
- export * from './optimizer.interface' ;
6
+ export { Optimizer } from './optimizer.interface' ;
Original file line number Diff line number Diff line change 1
- import {
2
- applyDecorators ,
3
- Injectable ,
4
- SetMetadata ,
5
- type Type ,
6
- } from '@nestjs/common' ;
1
+ import { Injectable , type Type } from '@nestjs/common' ;
2
+ import { createMetadataDecorator } from '@seedcompany/nest' ;
7
3
import { type Condition } from './condition.interface' ;
8
4
5
+ export const OptimizerWatermark = createMetadataDecorator ( {
6
+ types : [ 'class' ] ,
7
+ additionalDecorators : [ Injectable ( ) ] ,
8
+ } ) ;
9
+
9
10
export abstract class Optimizer {
10
- static register = ( ) => ( cls : Type < Optimizer > ) =>
11
- applyDecorators ( Injectable ( ) , SetMetadata ( Optimizer , true ) ) ( cls ) ;
11
+ static register = ( ) => ( cls : Type < Optimizer > ) => OptimizerWatermark ( ) ( cls ) ;
12
12
13
13
abstract optimize ( condition : Condition ) : Condition ;
14
14
}
Original file line number Diff line number Diff line change 1
- import { DiscoveryService } from '@golevelup/nestjs-discovery' ;
2
1
import { Injectable , type OnModuleInit } from '@nestjs/common' ;
2
+ import { MetadataDiscovery } from '~/core/discovery' ;
3
3
import {
4
4
AggregateConditions ,
5
5
AndConditions ,
6
6
type Condition ,
7
- Optimizer ,
7
+ type Optimizer ,
8
8
OrConditions ,
9
9
} from '../conditions' ;
10
+ import { OptimizerWatermark } from '../conditions/optimizer.interface' ;
10
11
11
12
@Injectable ( )
12
13
export class ConditionOptimizer implements OnModuleInit {
13
14
private optimizers : Optimizer [ ] ;
14
15
15
- constructor ( private readonly discovery : DiscoveryService ) { }
16
+ constructor ( private readonly discovery : MetadataDiscovery ) { }
16
17
17
18
async onModuleInit ( ) {
18
- const found = await this . discovery . providersWithMetaAtKey ( Optimizer as any ) ;
19
- this . optimizers = found . map ( ( p ) => p . discoveredClass . instance as Optimizer ) ;
19
+ this . optimizers = this . discovery
20
+ . discover ( OptimizerWatermark )
21
+ . classes < Optimizer > ( )
22
+ . map ( ( discovery ) => discovery . instance ) ;
20
23
}
21
24
22
25
optimize ( condition : Condition ) {
You can’t perform that action at this time.
0 commit comments