How to use the js-data.utils.isFunction function in js-data

To help you get started, we’ve selected a few js-data examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github js-data / js-data-http / src / index.js View on Github external
deserialize (mapper, response, opts) {
    opts || (opts = {})
    if (utils.isFunction(opts.deserialize)) {
      return opts.deserialize(mapper, response, opts)
    }
    if (utils.isFunction(mapper.deserialize)) {
      return mapper.deserialize(mapper, response, opts)
    }
    if (response && response.hasOwnProperty('data')) {
      return response.data
    }
    return response
  },
github js-data / js-data-http / src / index.js View on Github external
serialize (mapper, data, opts) {
    opts || (opts = {})
    if (utils.isFunction(opts.serialize)) {
      return opts.serialize(mapper, data, opts)
    }
    if (utils.isFunction(mapper.serialize)) {
      return mapper.serialize(mapper, data, opts)
    }
    return data
  },
github js-data / js-data-http / src / index.js View on Github external
queryTransform (mapper, params, opts) {
    opts || (opts = {})
    if (utils.isFunction(opts.queryTransform)) {
      return opts.queryTransform(mapper, params, opts)
    }
    if (utils.isFunction(mapper.queryTransform)) {
      return mapper.queryTransform(mapper, params, opts)
    }
    return params
  },
github js-data / js-data-express / src / index.js View on Github external
export function Router (component, config = {}) {
  if (!(component instanceof Mapper) && !(component instanceof Container)) {
    throw new Error('You must provide an instance of JSData.Container, JSData.DataStore, or JSData.Mapper!')
  }

  const router = this.router = express.Router()
  router.use(bodyParser.json())
  router.use(bodyParser.urlencoded({
    extended: true
  }))

  if (utils.isFunction(config.request)) {
    router.use(config.request)
    config.request = undefined
  }

  if (component instanceof Container) {
    utils.forOwn(component._mappers, (mapper, name) => {
      let endpoint = `/${mapper.endpoint || name}`
      if (utils.isFunction(config.getEndpoint)) {
        endpoint = config.getEndpoint(mapper)
      }
      router.use(endpoint, new Router(mapper, config).router)
    })
  } else if (component instanceof Mapper) {
    const createManyHandler = makeHandler('createMany', component, config)
    const createHandler = makeHandler('create', component, config)
    const updateManyHandler = makeHandler('updateMany', component, config)
github js-data / js-data-express / src / index.js View on Github external
defaultRequestHandler(req, res, (err) => {
        if (err) {
          return next(err)
        }
        if (utils.isFunction(config[method].response)) {
          config[method].response(req, res, next)
        } else {
          defaultResponseHandler(req, res, next)
        }
      })
    })
github js-data / js-data-express / src / index.js View on Github external
utils.forOwn(component._mappers, (mapper, name) => {
      let endpoint = `/${mapper.endpoint || name}`
      if (utils.isFunction(config.getEndpoint)) {
        endpoint = config.getEndpoint(mapper)
      }
      router.use(endpoint, new Router(mapper, config).router)
    })
  } else if (component instanceof Mapper) {
github js-data / js-data-express / src / index.js View on Github external
function makeHandler (method, component, config = {}) {
  config[method] || (config[method] = {})
  const userRequestHandler = utils.isFunction(config[method].request) ? config[method].request : handlerNoop
  const defaultRequestHandler = handlers.makeRequestHandler(method, component, config)
  const defaultResponseHandler = handlers.makeResponseHandler(method, component, config)

  return (req, res, next) => {
    userRequestHandler(req, res, (err) => {
      if (err) {
        return next(err)
      }
      defaultRequestHandler(req, res, (err) => {
        if (err) {
          return next(err)
        }
        if (utils.isFunction(config[method].response)) {
          config[method].response(req, res, next)
        } else {
          defaultResponseHandler(req, res, next)