feathers-utils

Useful hooks and utils for use with feathers services.


Keywords
feathers, feathersjs, hook, hooks, service, filters, permission, mixins, utils
License
MIT
Install
npm install feathers-utils@2.0.0

Documentation

feathers-utils

npm NPM Version GitHub Workflow Status Maintainability Code Coverage npm GitHub license

NOTE: This package was previously named feathers-utils. The ownership of the package name was transferred to feathers. The new package name is @fratzinger/feathers-utils. Starting from version 7.0.1 the package is published under the new name. Please update your dependencies accordingly.

Installation

npm i @fratzinger/feathers-utils

Usage

Hooks

  • checkMulti: throws if the request is multi data, but the services allowsMulti(method) returns false
  • createRelated: simply create related items from a hook.
  • forEach
  • onDelete: simply remove/set null related items from a hook.
  • paramsForServer
  • paramsFromClient
  • parseFields
  • removeRelated: simple remove related items from a hook. Basically cascade at feathers level.
  • runPerItem: run a function for every item. Meant for multi:true.
  • setData: map properties from context to data. Something like userId: context.params.user.id

Mixins

  • mixins/debounceMixin & mixins/DebouncedStore

Utils

  • defineHooks
  • filterQuery
  • flattenQuery
  • deflattenQuery
  • getItemsIsArray(context): returns { items: any[], isArray: boolean }
  • getPaginate
  • isMulti(context) => Boolean: returns true, if find, create/patch/remove: multi
  • isPaginated
  • markHookForSkip: add hookName to context.params.skipHooks - also see shouldSkip
  • mergeQuery: deeply merges queries
  • mergeArrays: merges arrays with intersection options
  • pushSet: if existing array: push, else set
  • setQueryKeySafely
  • setResultEmpty
  • shouldSkip: checks context.params.skipHooks for 'all' | '${hookName}' | '${type}:${hookName}' - also see markHookForSkip