Skip to content

Commit

Permalink
use preferred type unpacking pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Nov 15, 2023
1 parent 277a986 commit 5a7637b
Showing 1 changed file with 39 additions and 36 deletions.
75 changes: 39 additions & 36 deletions packages/core/src/types/config/access-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,46 @@ export type ListFilterAccessControl<
args: BaseAccessArgs<ListTypeInfo> & { operation: Operation }
) => MaybePromise<boolean | ListTypeInfo['inputs']['where']>

export type CreateListItemAccessControl<ListTypeInfo extends BaseListTypeInfo> = (
args: BaseAccessArgs<ListTypeInfo> & {
operation: 'create'

/**
* The input passed in from the GraphQL API
*/
inputData: ListTypeInfo['inputs']['create']
}
) => MaybePromise<boolean>

export type UpdateListItemAccessControl<ListTypeInfo extends BaseListTypeInfo> = (
export type ListItemAccessControl<
Operation extends ItemOperation,
ListTypeInfo extends BaseListTypeInfo
> = (
args: BaseAccessArgs<ListTypeInfo> & {
operation: 'update'
create: {
operation: 'create'

/**
* The item being updated
*/
item: ListTypeInfo['item']
/**
* The input passed in from the GraphQL API
*/
inputData: ListTypeInfo['inputs']['create']
}
update: {
operation: 'update'

/**
* The input passed in from the GraphQL API
*/
inputData: ListTypeInfo['inputs']['update']

/**
* The item being updated
*/
item: ListTypeInfo['item']
}
delete: {
operation: 'delete'

/**
* The input passed in from the GraphQL API
*/
inputData: ListTypeInfo['inputs']['update']
}
/**
* The item being deleted
*/
item: ListTypeInfo['item']
}
}[Operation]
) => MaybePromise<boolean>

export type DeleteListItemAccessControl<ListTypeInfo extends BaseListTypeInfo> = (
args: BaseAccessArgs<ListTypeInfo> & {
operation: 'delete'

/**
* The item being deleted
*/
item: ListTypeInfo['item']
}
) => MaybePromise<boolean>
export type CreateListItemAccessControl<ListTypeInfo extends BaseListTypeInfo> = ListItemAccessControl<'create', ListTypeInfo>
export type UpdateListItemAccessControl<ListTypeInfo extends BaseListTypeInfo> = ListItemAccessControl<'update', ListTypeInfo>
export type DeleteListItemAccessControl<ListTypeInfo extends BaseListTypeInfo> = ListItemAccessControl<'delete', ListTypeInfo>

type ListAccessControlFunction<ListTypeInfo extends BaseListTypeInfo> = (
args: BaseAccessArgs<ListTypeInfo> & { operation: AccessOperation }
Expand Down Expand Up @@ -91,10 +94,10 @@ type ListAccessControlObject<ListTypeInfo extends BaseListTypeInfo> = {
// These rules are applied to each item being operated on individually. They return `true` or `false`,
// and if false, an access denied error will be returned for the individual operation.
item?: {
// read?: not supported
create?: CreateListItemAccessControl<ListTypeInfo>
update?: UpdateListItemAccessControl<ListTypeInfo>
delete?: DeleteListItemAccessControl<ListTypeInfo>
// read?: not supported // TODO: why not
create?: ListItemAccessControl<'create', ListTypeInfo>
update?: ListItemAccessControl<'update', ListTypeInfo>
delete?: ListItemAccessControl<'delete', ListTypeInfo>
}
}

Expand Down

0 comments on commit 5a7637b

Please sign in to comment.