-
Notifications
You must be signed in to change notification settings - Fork 180
/
revokeRoles.ts
27 lines (21 loc) · 1002 Bytes
/
revokeRoles.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
import type { MigrationOptions } from '../../types';
import { toArray } from '../../utils';
import type { CascadeOption, Name } from '../generalTypes';
import type { OnlyAdminOption } from './shared';
export type RevokeRolesOptions = OnlyAdminOption & CascadeOption;
export type RevokeRoles = (
roles: Name | Name[],
rolesFrom: Name | Name[],
revokeOptions?: RevokeRolesOptions
) => string;
export function revokeRoles(mOptions: MigrationOptions): RevokeRoles {
const _revokeRoles: RevokeRoles = (roles, rolesFrom, options = {}) => {
const { onlyAdminOption = false, cascade = false } = options;
const rolesStr = toArray(roles).map(mOptions.literal).join(', ');
const rolesToStr = toArray(rolesFrom).map(mOptions.literal).join(', ');
const onlyAdminOptionStr = onlyAdminOption ? ' ADMIN OPTION FOR' : '';
const cascadeStr = cascade ? ' CASCADE' : '';
return `REVOKE${onlyAdminOptionStr} ${rolesStr} FROM ${rolesToStr}${cascadeStr};`;
};
return _revokeRoles;
}