1
1
import type { CommandReply } from '../../commands/generic-transformers' ;
2
2
import type { CommandPolicies } from './policies-constants' ;
3
3
import { REQUEST_POLICIES_WITH_DEFAULTS , RESPONSE_POLICIES_WITH_DEFAULTS } from './policies-constants' ;
4
- import type { PolicyResolver } from './types' ;
4
+ import type { PolicyResolver , ModulePolicyRecords } from './types' ;
5
5
import { StaticPolicyResolver } from './static-policy-resolver' ;
6
- import type { ModulePolicyRecords } from './static-policies-data' ;
7
6
8
7
/**
9
8
* Function type that returns command information from Redis
@@ -28,7 +27,7 @@ export class DynamicPolicyResolverFactory {
28
27
static async create (
29
28
commandFetcher : CommandFetcher ,
30
29
fallbackResolver ?: PolicyResolver
31
- ) : Promise < StaticPolicyResolver > {
30
+ ) : Promise < PolicyResolver > {
32
31
const commands = await commandFetcher ( ) ;
33
32
const policies : ModulePolicyRecords = { } ;
34
33
@@ -98,10 +97,28 @@ export class DynamicPolicyResolverFactory {
98
97
const defaultResponse = isKeyless
99
98
? RESPONSE_POLICIES_WITH_DEFAULTS . DEFAULT_KEYLESS
100
99
: RESPONSE_POLICIES_WITH_DEFAULTS . DEFAULT_KEYED ;
100
+
101
+ let subcommands : Record < string , CommandPolicies > | undefined ;
102
+ if ( command . subcommands . length > 0 ) {
103
+ subcommands = { } ;
104
+ for ( const subcommand of command . subcommands ) {
105
+
106
+ // Subcommands are in format "parentCommand|subcommand"
107
+ const parts = subcommand . name . split ( "\|" )
108
+ if ( parts . length !== 2 ) {
109
+ throw new Error ( `Invalid subcommand name: ${ subcommand . name } ` ) ;
110
+ }
111
+ const subcommandName = parts [ 1 ] ;
112
+
113
+ subcommands [ subcommandName ] = DynamicPolicyResolverFactory . #buildCommandPolicies( subcommand ) ;
114
+ }
115
+ }
101
116
102
117
return {
103
118
request : command . policies . request ?? defaultRequest ,
104
- response : command . policies . response ?? defaultResponse
119
+ response : command . policies . response ?? defaultResponse ,
120
+ isKeyless,
121
+ subcommands
105
122
} ;
106
123
}
107
124
}
0 commit comments