Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
container.register('DS', function (Promise, container, sqlAdapter, messageService) {
var JSData = require('js-data');
JSData.DSUtils.Promise = Promise;
var store = new JSData.DS({
cacheResponse: false,
bypassCache: true,
// Important: If your relationships stop working, you might
// have deleted this.
linkRelations: false,
// Because
upsert: false,
// Don't really need this stuff on the server, so let's improve
// performance and disable these features
notify: false,
keepChangeHistory: false,
resetHistoryOnInject: false,
var _ = require('underscore');
var JSData = require('js-data');
var DSHttpAdapter = require('js-data-http');
JSData.DSUtils.Promise = require('bluebird');
var store = new JSData.DS();
store.registerAdapter('http', new DSHttpAdapter({
basePath: 'http://services.odata.org/V4/Northwind/Northwind.svc/',
deserialize: function (definition, response) {
return response.data.value;
},
queryTransform: function (definition, params) {
var query = {};
_.has(params, 'offset') && (query.$skip = params.offset);
_.has(params, 'limit') && (query.$top = params.limit);
_.has(params, 'orderBy') && (query.$orderby = params.orderBy.map(function (item) {
return item[0] + ' ' + item[1].toLowerCase();
}).join(','));
import _ from 'underscore';
import JSData from 'js-data';
import DSHttpAdapter from 'js-data-http';
JSData.DSUtils.Promise = require('bluebird');
let store = new JSData.DS();
store.registerAdapter('http', new DSHttpAdapter({
basePath: 'https://services.odata.org/V4/Northwind/Northwind.svc/',
deserialize: (definition, response) => {
return response.data.value;
},
queryTransform: (definition, params) => {
let query = {};
_.has(params, 'offset') && (query.$skip = params.offset);
_.has(params, 'limit') && (query.$top = params.limit);
_.has(params, 'orderBy') && (query.$orderby = params.orderBy.map((item) => {
return item[0] + ' ' + item[1].toLowerCase();
}).join(','));
findAll(definition, params, options) {
let totalCount = 0;
options.afterFindAll = (resource, data) => {
totalCount = data['@odata.count'];
return data.value;
};
options.afterInject = (resource, instances) => {
Object.defineProperty(instances, 'totalCount', { value: totalCount });
};
return super.findAll(definition, params, options);
}
}
JSData.DSUtils.Promise = require('bluebird');
var store = new JSData.DS();
store.registerAdapter('odata', new ODataAdapter({
basePath: 'http://services.odata.org/V4/Northwind/Northwind.svc/',
}), { default: true });
module.exports = store.defineResource({
name: 'Customers',
idAttribute: 'CustomerID',
});