Skip to content

@casl/[email protected]

Pre-release
Pre-release
Compare
Choose a tag to compare
@stalniy stalniy released this 10 Aug 11:45
· 635 commits to master since this release

5.0.0 (2020-08-10)

Bug Fixes

  • ability: removes sift specific types from casl (9f18b31)

Code Refactoring

  • ability: removes deprecated types and fields (bf5ef73), closes #355
  • package: replaces siftjs with @ucast/mongo2js (41e53aa), closes #350

Features

  • ability: stores ast property in Rule if conditionsMatcher has ast (53e5e28), closes #350

BREAKING CHANGES

  • package: replaces siftjs with @ucast/mongo2js. This changed MongoQuery type and buildMongoQueryMatcher function parameters. Influences users who implemented custom sift operators:

    • MongoQuery accepted a generic type of AdditionalOperators, now it accepts an object interface and custom operators
    • MongoQueryOperators is renamed to MongoQueryFieldOperators and now accepts Value generic parameter
    • buildMongoQuery now accepts 3 optional parameters: custom parsing instruction, custom operator interpreters and options for JavaScript interpreters
    • Ability does not compare objects anymore, so if you rely on value to equal specific object, then you need to either change your conditions or implement custom equal function

    Before

    import { MongoQuery, MongoQueryOperators, buildMongoQueryMatcher } from '@casl/ability';
    import { $nor } from 'sift';
    
    type CustomMongoQuery = MongoQuery<{
      $customOperator: Function
    }>;
    type $eq = MongoQueryOperators['$eq'];
    
    const matcher = buildMongoQueryMatcher({ $nor })

    After

    import { MongoQuery, MongoQueryFieldOperators, buildMongoQueryMatcher } from '@casl/
    ability';
    import { $nor, nor } from '@ucast/mongo2js'
    
    type CustomMongoQuery<T> = MongoQuery<T, {
      toplevel: {
        // can be used only on document level
        $customOperator: Function
      },
      field: {
        // can be used only on field level
        $my: boolean
      }
    }>
    type $eq = MongoQueryFieldOperators['$eq']; // accepts optional `Value` generic parameter
    
    const matcher = buildMongoQueryMatcher({ $nor }, { nor });
          ```
  • ability: removes deprecated options and types:

  • AbilityOptions['subjectName'] has been removed, use detectSubjectType instead

  • LegacyClaimRawRule and LegacySubjectRawRule are both removed, so you are no longer allowed to use actions in rule definition, use action property instead

  • Ability throws an error if you specify a rule with property field to be an empty array

  • Ability no longer warns about using only inverted rules. This may be done by intention, so now it's left up to developer to decide whether it's fine or not