Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Mongo.Collection.prototype.findInStore = function (store, selector = {}, options = {}) {
const typeName = this.options && this.options.typeName;
const docs = _.where(store.getState().apollo.data, {__typename: typeName})
const mingoQuery = Mingo.Query(selector);
const cursor = mingoQuery.find(docs);
const sortedDocs = cursor.sort(options.sort).all();
// console.log('// findRedux')
// console.log("typeName: ", typeName)
// console.log("selector: ", selector)
// console.log("options: ", options)
// console.log("all docs: ", docs)
// console.log("selected docs: ", cursor.all())
// console.log("sorted docs: ", cursor.sort(options.sort).all())
return {fetch: () => sortedDocs};
}
// if collection has no mutations defined, just return previous results
if (!collection.options.mutations) {
return previousResults;
}
const newMutationName = collection.options.mutations.new && collection.options.mutations.new.name;
const editMutationName = collection.options.mutations.edit && collection.options.mutations.edit.name;
const removeMutationName = collection.options.mutations.remove && collection.options.mutations.remove.name;
let newResults = previousResults;
// get mongo selector and options objects based on current terms
const result = collection.getParameters(mergedTerms, apolloClient);
const { selector, options } = result;
const mingoQuery = Mingo.Query(selector);
// function to remove a document from a results object, used by edit and remove cases below
const removeFromResults = (results, document) => {
const listWithoutDocument = results[listResolverName].filter(doc => doc._id !== document._id);
const newResults = update(results, {
[listResolverName]: { $set: listWithoutDocument }, // ex: postsList
[totalResolverName]: { $set: results[totalResolverName] - 1 } // ex: postsListTotal
});
return newResults;
}
// add document to a results object
const addToResults = (results, document) => {
return update(results, {
[listResolverName]: { $unshift: [document] },
// Stellarium Web - Copyright (c) 2018 - Noctua Software Ltd
//
// This program is licensed under the terms of the GNU AGPL v3, or
// alternatively under a commercial licence.
//
// The terms of the AGPL v3 license can be found in the main directory of this
// repository.
import Swagger from 'swagger-client'
import _ from 'lodash'
import store from 'store'
import mingo from 'mingo'
mingo.setup({key: 'id'})
var swaggerClient
var localIdCounter = 0
var generateLocalId = function () {
localIdCounter++
return 'local_' + localIdCounter
}
var equipments = [
{
id: 'none'
},
{
id: 'base',
schema: [
const makeQuery = (gqlString) => {
const filter = gql.parse(gqlString);
return new mingo.Query(filter);
};
evalScript(scr,doc,mode) {
if(!scr.active) return;
if(scr.language !== 'javascript') return;
let mq = new mingo.Query(scr.trigger);
const matched = mq.find([doc]).all();
if(matched.length <= 0) return;
console.log("found a script to trigger",scr);
console.log('evaluating script ',scr.code);
console.log('on document',doc);
const event = {
mode: mode,
document: doc,
database: this
};
try {
//the actual eval
eval(scr.code)(event);
api.queryJSON = function (obj) {
this.query = this.query || new mingo.Query(api.parse());
return this.query.test(obj);
};
export const matchSelector = (document, selector) => {
const mingoQuery = new Mingo.Query(selector);
return mingoQuery.test(document);
};
export const createFilterFunction = (filter: any): Function => {
const query = new Mingo.Query(filter);
return (doc: any) => query.test(doc);
};
public watch(selector?: Selector): Observable> {
if (!selector) {
return this.changes.asObservable();
}
const mq = new mingo.Query(selector);
return this.changes.pipe(
switchMap(change => {
const docs = change.docs.filter(doc => mq.test(doc));
if (!docs.length) {
return empty();
}
return of(Object.assign({}, change, { docs }));
})
);
}
protected filter(docs: T[], selector: Selector, options: FindOptions): T[] {
let cursor = mingo.find(docs, selector);
if (options.sort) {
cursor = cursor.sort(options.sort);
}
if (options.skip) {
cursor = cursor.skip(options.skip);
}
if (options.limit) {
cursor = cursor.limit(options.limit);
}
return cursor.all();
}