11import type { CommandReply } from '../../commands/generic-transformers' ;
22import type { CommandPolicies } from './policies-constants' ;
33import { REQUEST_POLICIES_WITH_DEFAULTS , RESPONSE_POLICIES_WITH_DEFAULTS } from './policies-constants' ;
4- import type { PolicyResolver } from './types' ;
4+ import type { PolicyResolver , ModulePolicyRecords } from './types' ;
55import { StaticPolicyResolver } from './static-policy-resolver' ;
6- import type { ModulePolicyRecords } from './static-policies-data' ;
76
87/**
98 * Function type that returns command information from Redis
@@ -28,7 +27,7 @@ export class DynamicPolicyResolverFactory {
2827 static async create (
2928 commandFetcher : CommandFetcher ,
3029 fallbackResolver ?: PolicyResolver
31- ) : Promise < StaticPolicyResolver > {
30+ ) : Promise < PolicyResolver > {
3231 const commands = await commandFetcher ( ) ;
3332 const policies : ModulePolicyRecords = { } ;
3433
@@ -98,10 +97,28 @@ export class DynamicPolicyResolverFactory {
9897 const defaultResponse = isKeyless
9998 ? RESPONSE_POLICIES_WITH_DEFAULTS . DEFAULT_KEYLESS
10099 : 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+ }
101116
102117 return {
103118 request : command . policies . request ?? defaultRequest ,
104- response : command . policies . response ?? defaultResponse
119+ response : command . policies . response ?? defaultResponse ,
120+ isKeyless,
121+ subcommands
105122 } ;
106123 }
107124}
0 commit comments