feathers-casl
Version:
Add access control with CASL to your feathers application.
19 lines (16 loc) • 475 B
text/typescript
import type { HookContext } from '@feathersjs/feathers'
export const getModelName = (
modelName: string | ((context: HookContext) => string) | undefined,
context: HookContext,
): string => {
if (modelName === undefined) {
return context.path
}
if (typeof modelName === 'string') {
return modelName
}
if (typeof modelName === 'function') {
return modelName(context)
}
throw new Error("feathers-casl: 'modelName' is not a string or function")
}