Improved jsdoc for permission migration utils

- this helps with readability and editor autocomplete
This commit is contained in:
Daniel Lockyer 2022-10-18 14:38:58 +07:00
parent 3858f255b9
commit 18c52f2a2a
No known key found for this signature in database

View File

@ -10,6 +10,10 @@ const messages = {
permissionRoleActionError: 'Cannot {action} permission({permission}) with role({role}) - {resource} does not exist'
};
/**
* @param {import('knex').Knex} connection
* @param {PermissionConfig} config
*/
async function addPermissionHelper(connection, config) {
const existingPermission = await connection('permissions').where({
name: config.name,
@ -38,6 +42,10 @@ async function addPermissionHelper(connection, config) {
});
}
/**
* @param {import('knex').Knex} connection
* @param {PermissionConfig} config
*/
async function removePermissionHelper(connection, config) {
const existingPermission = await connection('permissions').where({
name: config.name,
@ -61,10 +69,7 @@ async function removePermissionHelper(connection, config) {
/**
* Creates a migration which will add a permission to the database
*
* @param {Object} config
* @param {string} config.name - The name of the permission
* @param {string} config.action - The action_type of the permission
* @param {string} config.object - The object_type of the permission
* @param {PermissionConfig} config
*
* @returns {Migration}
*/
@ -82,10 +87,7 @@ function addPermission(config) {
/**
* Creates a migration which will remove a permission from the database
*
* @param {Object} config
* @param {string} config.name - The name of the permission
* @param {string} config.action - The action_type of the permission
* @param {string} config.object - The object_type of the permission
* @param {PermissionConfig} config
*
* @returns {Migration}
*/
@ -100,6 +102,10 @@ function removePermission(config) {
);
}
/**
* @param {import('knex').Knex} connection
* @param {PermissionRoleConfig} config
*/
async function addPermissionToRoleHelper(connection, config) {
const permission = await connection('permissions').where({
name: config.permission
@ -149,6 +155,10 @@ async function addPermissionToRoleHelper(connection, config) {
});
}
/**
* @param {import('knex').Knex} connection
* @param {PermissionRoleConfig} config
*/
async function removePermissionFromRoleHelper(connection, config) {
const permission = await connection('permissions').where({
name: config.permission
@ -188,9 +198,7 @@ async function removePermissionFromRoleHelper(connection, config) {
/**
* Creates a migration which will link a permission to a role in the database
*
* @param {Object} config
* @param {string} config.permission - The name of the permission
* @param {string} config.role - The name of the role
* @param {PermissionRoleConfig} config
*
* @returns {Migration}
*/
@ -208,9 +216,7 @@ function addPermissionToRole(config) {
/**
* Creates a migration which will remove the permission from roles
*
* @param {Object} config
* @param {string} config.permission - The name of the permission
* @param {string} config.role - The name of the role
* @param {PermissionRoleConfig} config
*
* @returns {Migration}
*/
@ -228,11 +234,7 @@ function removePermissionFromRole(config) {
/**
* Creates a migration which will add a permission to the database, and then link it to roles
*
* @param {Object} config
* @param {string} config.name - The name of the permission
* @param {string} config.action - The action_type of the permission
* @param {string} config.object - The object_type of the permission
*
* @param {PermissionConfig} config
* @param {string[]} roles - A list of role names
*
* @returns {Migration}
@ -247,11 +249,7 @@ function addPermissionWithRoles(config, roles) {
/**
* Creates a migration which will remove permissions from roles, and then remove the permission
*
* @param {Object} config
* @param {string} config.name - The name of the permission
* @param {string} config.action - The action_type of the permission
* @param {string} config.object - The object_type of the permission
*
* @param {PermissionConfig} config
* @param {string[]} roles - A list of role names
*
* @returns {Migration}
@ -270,6 +268,19 @@ module.exports = {
createRemovePermissionMigration
};
/**
* @typedef {Object} PermissionConfig
* @prop {string} config.name - The name of the permission
* @prop {string} config.action - The action_type of the permission
* @prop {string} config.object - The object_type of the permission
*/
/**
* @typedef {Object} PermissionRoleConfig
* @prop {string} config.permission - The name of the permission
* @prop {string} config.role - The role to assign the Permission to
*/
/**
* @typedef {Object} TransactionalMigrationFunctionOptions
*