mirror of
https://github.com/vale981/grapher
synced 2025-03-05 17:41:41 -05:00
Merge pull request #158 from Herteby/deprecate_createNamedQuery
deprecated createNamedQuery and moved functionality to createQuery
This commit is contained in:
commit
33fbf72440
8 changed files with 61 additions and 50 deletions
6
lib/namedQuery/_createNamedQuery.js
Normal file
6
lib/namedQuery/_createNamedQuery.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
import createQuery from '../query/createQuery.js'
|
||||
|
||||
export default (...args) => {
|
||||
console.warn('createNamedQuery is deprecated. Functionality has been moved over to createQuery');
|
||||
return createQuery(...args);
|
||||
}
|
8
lib/namedQuery/_extension.js
Normal file
8
lib/namedQuery/_extension.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
import createQuery from '../query/createQuery.js';
|
||||
|
||||
_.extend(Mongo.Collection.prototype, {
|
||||
createNamedQuery(...args) {
|
||||
console.warn('createNamedQuery is deprecated. Functionality has been moved over to createQuery');
|
||||
return this.createQuery(...args);
|
||||
}
|
||||
});
|
|
@ -1,27 +0,0 @@
|
|||
import NamedQuery from './namedQuery.js';
|
||||
import NamedQueryStore from './store';
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param data
|
||||
* @param args
|
||||
*
|
||||
* @returns NamedQuery
|
||||
*/
|
||||
export default (name, data, ...args) => {
|
||||
if (_.keys(data).length > 1) {
|
||||
throw new Meteor.Error('invalid-query', 'When using createNamedQuery you should only have one main root point, meaning your object should have a single key, representing the collection name.')
|
||||
}
|
||||
|
||||
const entryPointName = _.first(_.keys(data));
|
||||
const collection = Mongo.Collection.get(entryPointName);
|
||||
if (!collection) {
|
||||
throw new Meteor.Error('invalid-name', `We could not find any collection with the name "${entryPointName}". Make sure it is imported prior to using this`)
|
||||
}
|
||||
|
||||
const query = new NamedQuery(name, collection, data[entryPointName], ...args);
|
||||
|
||||
NamedQueryStore.add(name, query);
|
||||
|
||||
return query;
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
import NamedQuery from './namedQuery.js';
|
||||
import NamedQueryStore from './store';
|
||||
|
||||
_.extend(Mongo.Collection.prototype, {
|
||||
createNamedQuery(name, body, params = {}) {
|
||||
const query = new NamedQuery(name, this, body, params);
|
||||
|
||||
NamedQueryStore.add(name, query);
|
||||
|
||||
return query;
|
||||
}
|
||||
});
|
|
@ -1,24 +1,46 @@
|
|||
import Query from './query.js';
|
||||
import NamedQuery from '../namedQuery/namedQuery.js';
|
||||
import NamedQueryStore from '../namedQuery/store.js';
|
||||
|
||||
export default (data, ...args) => {
|
||||
if (_.keys(data).length > 1) {
|
||||
export default (...args) => {
|
||||
let name;
|
||||
let body;
|
||||
let rest;
|
||||
if (typeof args[0] == 'string') { //NamedQuery
|
||||
name = args[0];
|
||||
body = args[1];
|
||||
rest = args.slice(2)
|
||||
} else { //Query
|
||||
body = args[0];
|
||||
rest = args.slice(1)
|
||||
}
|
||||
|
||||
if (_.keys(body).length > 1) {
|
||||
throw new Meteor.Error('invalid-query', 'When using createQuery you should only have one main root point that represents the collection name.')
|
||||
}
|
||||
|
||||
const entryPointName = _.first(_.keys(data));
|
||||
const entryPointName = _.first(_.keys(body));
|
||||
|
||||
const collection = Mongo.Collection.get(entryPointName);
|
||||
|
||||
if (!collection) {
|
||||
if (name) { //is a NamedQuery
|
||||
throw new Meteor.Error('invalid-name', `We could not find any collection with the name "${entryPointName}". Make sure it is imported prior to using this`)
|
||||
}
|
||||
const namedQuery = NamedQueryStore.get(entryPointName);
|
||||
|
||||
if (!namedQuery) {
|
||||
throw new Meteor.Error('entry-point-not-found', `We could not find any collection or named query with the name "${entryPointName}". Make sure you have them loaded in the environment you are executing *createQuery*`)
|
||||
} else {
|
||||
return namedQuery.clone(data[entryPointName], ...args);
|
||||
return namedQuery.clone(body[entryPointName], ...rest);
|
||||
}
|
||||
}
|
||||
|
||||
return new Query(collection, data[entryPointName], ...args);
|
||||
if (name) {
|
||||
const query = new NamedQuery(name, collection, body[entryPointName], ...rest);
|
||||
NamedQueryStore.add(name, query);
|
||||
|
||||
return query;
|
||||
} else {
|
||||
return new Query(collection, body[entryPointName], ...rest);
|
||||
}
|
||||
}
|
|
@ -1,7 +1,21 @@
|
|||
import Query from './query.js';
|
||||
|
||||
_.extend(Mongo.Collection.prototype, {
|
||||
createQuery(body, params = {}) {
|
||||
createQuery(...args) {
|
||||
if (args[0] == 'string') { //NamedQuery
|
||||
const name = args[0];
|
||||
const body = args[1];
|
||||
const params = args[2];
|
||||
|
||||
const query = new NamedQuery(name, this, body, params);
|
||||
NamedQueryStore.add(name, query);
|
||||
|
||||
return query;
|
||||
} else { //Query
|
||||
const body = args[0];
|
||||
const params = args[1];
|
||||
|
||||
return new Query(this, body, params);
|
||||
}
|
||||
}
|
||||
});
|
|
@ -1,7 +1,7 @@
|
|||
import './lib/links/extension.js';
|
||||
import './lib/query/extension.js';
|
||||
import './lib/query/reducers/extension.js';
|
||||
import './lib/namedQuery/extension.js';
|
||||
import './lib/namedQuery/_extension.js'; //deprecated
|
||||
|
||||
export {
|
||||
default as createQuery
|
||||
|
@ -9,7 +9,7 @@ export {
|
|||
|
||||
export {
|
||||
default as createNamedQuery
|
||||
} from './lib/namedQuery/createNamedQuery.js';
|
||||
} from './lib/namedQuery/_createNamedQuery.js'; //deprecated
|
||||
|
||||
export {
|
||||
default as prepareForProcess
|
||||
|
|
|
@ -3,7 +3,7 @@ import './lib/links/extension.js';
|
|||
import './lib/query/extension.js';
|
||||
import './lib/query/reducers/extension.js';
|
||||
import './lib/namedQuery/expose/extension.js';
|
||||
import './lib/namedQuery/extension.js';
|
||||
import './lib/namedQuery/_extension.js'; //deprecated
|
||||
|
||||
export {
|
||||
default as createQuery
|
||||
|
@ -11,7 +11,7 @@ export {
|
|||
|
||||
export {
|
||||
default as createNamedQuery
|
||||
} from './lib/namedQuery/createNamedQuery.js';
|
||||
} from './lib/namedQuery/_createNamedQuery.js'; //deprecated
|
||||
|
||||
export {
|
||||
default as Exposure
|
||||
|
|
Loading…
Add table
Reference in a new issue