Skip to content

Commit

Permalink
fix(angular): adding type definitions for accessibleFields (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
bagofjuice authored and stalniy committed Oct 10, 2018
1 parent 2b24aee commit a00c02b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/casl-mongoose/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,24 @@ interface PermittedFieldsOptions {
only?: string | string[],
except?: string | string[]
}
interface AccessibleFieldsOptions {
only?: string | string[],
except?: string | string[]
}

export function permittedFieldsPlugin(schema: PermittedFieldsSchema, options?: PermittedFieldsOptions): void
export function accessibleFieldsPlugin(schema: AccessibleFieldsSchema, options?: AccessibleFieldsOptions): void

export interface PermittedFieldsSchema extends mongoose.Schema {
plugin(
plugin: typeof permittedFieldsPlugin,
options?: PermittedFieldsOptions): this
}
export interface AccessibleFieldsSchema extends mongoose.Schema {
plugin(
plugin: typeof accessibleFieldsPlugin,
options?: AccessibleFieldsOptions): this
}

export function accessibleRecordsPlugin(schema: mongoose.Schema): void

Expand All @@ -25,7 +35,7 @@ export interface AccessibleSchema extends mongoose.Schema {
declare module "mongoose" {
export function model<T extends Document>(
name: string,
schema?: PermittedFieldsSchema | AccessibleSchema,
schema?: PermittedFieldsSchema | AccessibleFieldsSchema | AccessibleSchema,
collection?: string,
skipInit?: boolean): Model<T>

Expand All @@ -36,9 +46,11 @@ declare module "mongoose" {
interface Model<T extends Document> {
accessibleBy(ability: Ability, action?: string): Query<T>
permittedFieldsBy(ability: Ability, action?: string): string[]
accessibleFieldsBy(ability: Ability, action?: string): string[]
}

interface Document {
permittedFieldsBy(ability: Ability, action?: string): string[]
accessibleFieldsBy(ability: Ability, action?: string): string[]
}
}

0 comments on commit a00c02b

Please sign in to comment.