Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
TodoList.prototype = Object.create(Array.prototype);
TodoList.prototype.completed = function(){
return this.filter(function(todo){
return todo.status === "complete";
});
};
TodoList.prototype.active = function(){
return this.filter(function(todo){
return todo.status !== "complete";
});
};
// A connection that gets todos data
var todoConnection = connect(["constructor","data-url"],{
url: "/todos",
list: function(listData, set){
return new TodoList(listData.data);
},
instance: function(props) {
return new Todo(props);
}
});
// Trap ajax requests to return and modify the following `todo` object.
fixture({
"GET /todos": function(request){
return {
data: [
{id: 1, name: "mow lawn", status: "assigned"},
.then(() => {
// Destroy the local entity.
this.destroy();
})
.then(null, jqXHR => {
let jsonData = {};
if (jqXHR.responseText) {
try {
jsonData = $.parseJSON(jqXHR.responseText);
} catch (e) { }
}
return Ajax.handleError(request, jsonData);
});
};
Group.connection = connect([connectParse, connectDataUrl, connectConstructor, connectMap], {
Map: Group,
List: Group.List,
url: {
resource: '/',
destroyData: function() {
// @see Group::delete() function
return Promise.resolve({});
},
getData: function(params) {
params = params || {};
params['api-version'] = 'v2';
return Ajax.request({
url: 'groups/{id}.json',
type: 'GET',
params: params
});
this.profile.assign({avatar: data.profile.avatar});
this.dispatch('updated');
Ajax._unregisterRequest(request);
return Promise.resolve(this);
}), jqXHR => {
let jsonData = {};
if (jqXHR.responseText) {
try {
jsonData = $.parseJSON(jqXHR.responseText);
} catch (e) { }
}
return Ajax.handleError(request, jsonData);
});
};
User.connection = connect([connectParse, connectDataUrl, connectConstructor, connectMap], {
Map: User,
List: User.List,
url: {
resource: '/',
createData: function(params) {
return Ajax.request({
url: 'users.json?api-version=v2',
type: 'POST',
params: params
});
},
updateData: function(params) {
// Filter the attributes that need to be send by the request.
const _params = User.filterAttributes(params);
return Ajax.request({
url: 'users/{id}.json?api-version=v2',
import connect from "can-connect";
import "can-connect/data/url/";
import "can-connect/constructor/";
import "can-connect/constructor/store/";
import "can-connect/data/localstorage-cache/";
import "can-connect/fall-through-cache/";
import fixture from "can-fixture";
import $ from "jquery";
import helpers from "can-connect/helpers/";
var cache = connect(['data-localstorage-cache'],{
name: "todos"
});
// A connection that gets todos data
var todosConnection = connect([
"fall-through-cache",
"constructor",
"constructor-store",
"data-url"],{
url: "/todos",
cacheConnection: cache
});
var todoItem = function(todo) {
var li = $("<li>");
var update = function(){
if(todo.complete) {
li.css("text-decoration","line-through");
} else {</li>
secretKey: data.yubikey_secret_key
};
}
if (data.duo_provider) {
result.providers.push('duo');
result.duo = {
hostName: data.duo_host_name,
integrationKey: data.duo_integration_key,
salt: data.duo_salt,
secretKey: data.duo_secret_key
};
}
return result;
};
MfaSettings.connection = connect([connectParse, connectDataUrl, connectConstructor, connectMap], {
Map: MfaSettings,
url: {
resource: '/',
getData: function() {
const params = {};
params['api-version'] = 'v2';
return Ajax.request({
url: 'mfa/settings.json',
type: 'GET',
params: params
}).then(settings => MfaSettings.mapFromApi(settings));
},
updateData: function(params) {
return Ajax.request({
url: 'mfa/settings.json?api-version=v2',
type: 'POST',
if (resourcesIds.length > batchSize) {
const resourcesIdsParts = chunk(resourcesIds, batchSize);
return resourcesIdsParts.reduce((promise, resourcesIdsPart) => promise.then(carry => Resource.findAllByIds(resourcesIdsPart)
.then(resources => carry.concat(resources))), Promise.resolve(new Resource.List()));
}
const findOptions = {
contain: {favorite: 1, permission: 1, tag: 1},
filter: {
'has-id': resourcesIds
}
};
return Resource.findAll(findOptions);
};
Resource.connection = connect([connectParse, connectDataUrl, connectConstructor, connectMap], {
Map: Resource,
List: Resource.List,
url: {
resource: '/',
getData: function(params) {
params = params || {};
params['api-version'] = 'v2';
return Ajax.request({
url: 'resources/{id}.json',
type: 'GET',
params: params
});
},
getListData: function(params) {
params = params || {};
params['api-version'] = 'v2';
};
/**
* Update the resource tags
* @param {string} resourceId The target resource to update the tags for
* @param {array} slugs The list tags
*/
Tag.updateResourceTags = function(resourceId, slugs) {
return Ajax.request({
url: 'tags/{resourceId}.json?api-version=v2',
type: 'POST',
params: {Tags: slugs, resourceId: resourceId}
}).then(data => Promise.resolve(new Tag.List(data)));
};
Tag.connection = connect([connectParse, connectDataUrl, connectConstructor, connectMap], {
Map: Tag,
List: Tag.List,
url: {
resource: '/',
getListData: function(params) {
params = params || {};
params['api-version'] = 'v2';
return Ajax.request({
url: 'tags.json',
type: 'GET',
params: params
});
},
destroyData: function(params) {
return Ajax.request({
url: `tags/${params.id}.json?api-version=v2`,
/**
* Select a theme
* @param {Theme} theme The target theme
*/
Theme.select = function(theme) {
return Ajax.request({
url: '/account/settings/themes.json',
type: 'POST',
params: {value: theme.name}
}).then(() => {
Config.write('accountSetting.theme', theme.name);
});
};
Theme.connection = connect([connectParse, connectDataUrl, connectConstructor, connectMap], {
Map: Theme,
List: Theme.List,
url: {
resource: '/',
getListData: function(params) {
params = params || {};
params['api-version'] = 'v2';
return Ajax.request({
url: '/account/settings/themes.json',
type: 'GET',
params: params
});
}
}
});
realtime
];
export const Session = DefineMap.extend('Session', {
_id: '*',
email: 'string',
password: 'string',
data: '*',
token: 'string'
});
Session.List = DefineList.extend({
'*': Session
});
export const sessionConnection = connect(behaviors, {
url: {
createData: data => feathers.authenticate(data),
destroyData: () => feathers.logout().then(() => {
window.localStorage.clear();
window.location.pathname = '/';
})
},
idProp: '<%= idProp %>',
Map: Session,
List: Session.List,
name: 'session'
});
export default Session;
DefineMap.setReference('EmailNotificationSettings', EmailNotificationSettings);
/**
* Check if the settings are overridden by file
* @param {object} data
* @returns boolean
*/
EmailNotificationSettings.settingsOverridenByfile = function(data) {
return data.sources_file === true && data.sources_database === true;
};
EmailNotificationSettings.fileConfigExists = function(data) {
return data.sources_file === true;
};
EmailNotificationSettings.connection = connect([connectParse, connectDataUrl, connectConstructor, connectMap], {
Map: EmailNotificationSettings,
url: {
resource: '/',
getData: function() {
const params = {};
params['api-version'] = 'v2';
return Ajax.request({
url: 'settings/emails/notifications.json',
type: 'GET',
params: params
});
},
updateData: function(params) {
return Ajax.request({
url: 'settings/emails/notifications.json?api-version=v2',
type: 'POST',