How to use the js-data.utils 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-examples / server / src / index.js View on Github external
'use strict'

require('source-map-support').install()
const Promise = require('bluebird')
const JSData = require('js-data')
const express = require('express')
const nconf = require('nconf')

// 1. Pull config from the commandline arguments
// 2. Pull config from environment variables
// 3. Pull config from a config file
nconf.argv().env().file({ file: `${__dirname}/../config.json` })

// Make JSData use bluebird internally
JSData.utils.Promise = Promise

const utils = require('./utils')
const middleware = require('./middleware')
const store = require('./store').store
const app = express()

const PAGE_SIZE = 5

// Application middleware
app.use(require('body-parser').json())
app.use(require('express-session')({ secret: 'keyboard cat' }))
app.use(middleware.passport.initialize())
app.use(middleware.passport.session())
app.use(express.static(`${__dirname}/../../client/public`))
app.use(middleware.queryRewrite)
github js-data / js-data-sql / dist / js-data-sql.js View on Github external
* @example Using {@link SqlAdapter.extend}.
 * const instanceProps = {...};
 * const classProps = {...};
 *
 * const MySqlAdapter = SqlAdapter.extend(instanceProps, classProps);
 * const adapter = new MySqlAdapter();
 *
 * @method SqlAdapter.extend
 * @static
 * @param {Object} [instanceProps] Properties that will be added to the
 * prototype of the subclass.
 * @param {Object} [classProps] Properties that will be added as static
 * properties to the subclass itself.
 * @return {Constructor} Subclass of `SqlAdapter`.
 */
SqlAdapter.extend = jsData.utils.extend;

/*
function processRelationField (resourceConfig, query, field, criteria, options, joinedTables) {
  let fieldParts = field.split('.')
  let localResourceConfig = resourceConfig
  let relationPath = []
  let relationName = null;

  while (fieldParts.length >= 2) {
    relationName = fieldParts.shift()
    let [relation] = localResourceConfig.relationList.filter(r => r.relation === relationName || r.localField === relationName)

    if (relation) {
      let relationResourceConfig = resourceConfig.getResource(relation.relation)
      relationPath.push(relation.relation)
github GoogleCloudPlatform / js-data-cloud-datastore / dist / js-data-cloud-datastore.js View on Github external
* @example Using {@link CloudDatastoreAdapter.extend}.
 * var instanceProps = {...}
 * var classProps = {...}
 *
 * var MyCloudDatastoreAdapter = CloudDatastoreAdapter.extend(instanceProps, classProps)
 * var adapter = new MyCloudDatastoreAdapter()
 *
 * @method CloudDatastoreAdapter.extend
 * @static
 * @param {Object} [instanceProps] Properties that will be added to the
 * prototype of the subclass.
 * @param {Object} [classProps] Properties that will be added as static
 * properties to the subclass itself.
 * @return {Constructor} Subclass of `CloudDatastoreAdapter`.
 */
CloudDatastoreAdapter.extend = jsData.utils.extend;

jsData.utils.addHiddenPropsToTarget(CloudDatastoreAdapter.prototype, {
  /**
   * Apply the specified selection query to the provided Datastore query.
   *
   * @method CloudDatastoreAdapter#filterQuery
   * @param {Object} mapper The mapper.
   * @param {Object} [query] Selection query.
   * @param {Object} [query.where] Filtering criteria.
   * @param {string|Array} [query.orderBy] Sorting criteria.
   * @param {string|Array} [query.sort] Same as `query.sort`.
   * @param {number} [query.limit] Limit results.
   * @param {number} [query.skip] Offset results.
   * @param {number} [query.offset] Same as `query.skip`.
   * @param {Object} [opts] Configuration options.
   * @param {Object} [opts.operators] Override the default predicate functions
github js-data / js-data-rethinkdb / dist / js-data-rethinkdb.js View on Github external
* @example Using {@link RethinkDBAdapter.extend}.
 * var instanceProps = {...}
 * var classProps = {...}
 *
 * var MyRethinkDBAdapter = RethinkDBAdapter.extend(instanceProps, classProps)
 * var adapter = new MyRethinkDBAdapter()
 *
 * @name RethinkDBAdapter.extend
 * @method
 * @param {Object} [instanceProps] Properties that will be added to the
 * prototype of the Subclass.
 * @param {Object} [classProps] Properties that will be added as static
 * properties to the Subclass itself.
 * @return {Constructor} Subclass of `RethinkDBAdapter`.
 */
RethinkDBAdapter.extend = jsData.utils.extend;

jsData.utils.addHiddenPropsToTarget(RethinkDBAdapter.prototype, {
  _handleErrors: function _handleErrors(cursor) {
    if (cursor && cursor.errors > 0) {
      if (cursor.first_error) {
        throw new Error(cursor.first_error);
      }
      throw new Error('Unknown RethinkDB Error');
    }
  },
  _count: function _count(mapper, query, opts) {
    var self = this;
    opts || (opts = {});
    query || (query = {});

    return self.filterSequence(self.selectTable(mapper, opts), query).count().run(self.getOpt('runOpts', opts)).then(function (count) {
github js-data / js-data-mongodb / dist / js-data-mongodb.js View on Github external
function MongoDBAdapter(opts) {
  var self = this;
  jsData.utils.classCallCheck(self, MongoDBAdapter);
  opts || (opts = {});
  if (jsData.utils.isString(opts)) {
    opts = { uri: opts };
  }
  jsData.utils.fillIn(opts, DEFAULTS);
  jsDataAdapter.Adapter.call(self, opts);

  /**
   * Default options to pass to collection#count.
   *
   * @name MongoDBAdapter#countOpts
   * @type {Object}
   * @default {}
   */
  self.countOpts || (self.countOpts = {});
  jsData.utils.fillIn(self.countOpts, COUNT_OPTS_DEFAULTS);

  /**
   * Default options to pass to collection#find.
   *
   * @name MongoDBAdapter#findOpts
github js-data / js-data-mongodb / dist / js-data-mongodb.js View on Github external
* @example Using {@link MongoDBAdapter.extend}.
 * var instanceProps = {...}
 * var classProps = {...}
 *
 * var MyMongoDBAdapter = MongoDBAdapter.extend(instanceProps, classProps)
 * var adapter = new MyMongoDBAdapter()
 *
 * @method MongoDBAdapter.extend
 * @static
 * @param {Object} [instanceProps] Properties that will be added to the
 * prototype of the subclass.
 * @param {Object} [classProps] Properties that will be added as static
 * properties to the subclass itself.
 * @return {Object} Subclass of `MongoDBAdapter`.
 */
MongoDBAdapter.extend = jsData.utils.extend;

jsData.utils.addHiddenPropsToTarget(MongoDBAdapter.prototype, {
  /**
   * Translate ObjectIDs to strings.
   *
   * @method MongoDBAdapter#_translateId
   * @return {*}
   */

  _translateId: function _translateId(r, opts) {
    opts || (opts = {});
    if (this.getOpt('translateId', opts)) {
      if (jsData.utils.isArray(r)) {
        r.forEach(function (_r) {
          var __id = _r._id ? _r._id.toString() : _r._id;
          _r._id = typeof __id === 'string' ? __id : _r._id;
github js-data / js-data-express / dist / js-data-express.js View on Github external
function makeHandler(method, component) {
  var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

  config[method] || (config[method] = {});
  var userRequestHandler = jsData.utils.isFunction(config[method].request) ? config[method].request : handlerNoop;
  var defaultRequestHandler = makeRequestHandler(method, component, config);
  var defaultResponseHandler = makeResponseHandler(method, component, config);

  return function (req, res, next) {
    userRequestHandler(req, res, function (err) {
      if (err) {
        return next(err);
      }
      defaultRequestHandler(req, res, function (err) {
        if (err) {
          return next(err);
        }
        if (jsData.utils.isFunction(config[method].response)) {
          config[method].response(req, res, next);
        } else {
          defaultResponseHandler(req, res, next);
github js-data / js-data-express / dist / js-data-express.js View on Github external
defaultRequestHandler(req, res, function (err) {
        if (err) {
          return next(err);
        }
        if (jsData.utils.isFunction(config[method].response)) {
          config[method].response(req, res, next);
        } else {
          defaultResponseHandler(req, res, next);
        }
      });
    });
github js-data / js-data-rethinkdb / dist / js-data-rethinkdb.js View on Github external
selectDb: function selectDb(opts) {
    return this.r.db(jsData.utils.isUndefined(opts.db) ? this.db : opts.db);
  },
  selectTable: function selectTable(mapper, opts) {
github GoogleCloudPlatform / js-data-cloud-datastore / mocha.start.js View on Github external
return super.updateAll(...args).then((result) => {
      return new JSData.utils.Promise((resolve) => {
        setTimeout(() => resolve(result), 500);
      });
    });
  }