Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function renderExhibits(ctx, next) {
const query = searchQuery.parse(ctx.query.query, { keywords: ['ids'] });
if (!query.ids) return;
// searchQueryParser automatically changes comma seperated lists into arrays
const ids = typeof query.ids === 'string' ? query.ids.split(',') : query.ids;
const exhibits = await getExhibitionExhibits(ctx.request, {ids});
ctx.render('components/exhibits/exhibits', {
exhibits: exhibits.results
});
ctx.body = {
html: ctx.body
};
}
parseSearchQuery(query) {
const searchQueryParams = searchQuery.parse(query, { keywords: SEARCH_KEYWORDS });
const variables = { concurrency: { group: null }, states: null, agentQueryRules: null };
if (typeof searchQueryParams === 'string') {
variables.agentQueryRules = searchQueryParams;
} else if (searchQueryParams) {
variables.agentQueryRules = searchQueryParams.text;
variables.concurrency.group = searchQueryParams['concurrency-group'];
// Ensure the states are all upper case since it's a GraphQL enum
const states = searchQueryParams['state'];
if (states) {
if (typeof states === 'string') {
variables.states = states.toUpperCase();
} else {
variables.states = states.map((state) => state.toUpperCase());
}
function parseSearchQuery(query, options) {
options = Object.assign({ throwOnInvalid: false }, options);
// Parse query into object
query = searchQueryParser.parse(query, { keywords: qualifiers });
query = typeof query === 'string' ? { text: query } : query;
query = mapKeys(query, (value, key) => camelCase(key)); // CamelCase keys
delete query.exclude; // We do not use the exclusion feature from search-query-parser
delete query.offsets; // Remove `offsets` otherwise validation will fail
// Convert & validate
const validation = Joi.validate(query, paramsSchema, { abortEarly: options.throwOnInvalid });
let params = validation.value;
if (validation.error) {
// Throw if there's an error and `options.throwOnInvalid` is enabled
if (options.throwOnInvalid && validation.error) {
throw validation.error;
}
// If `options.throwOnInvalid` is enabled, remove all failed validation props and fill it with defaults
export function parseQuery(query: string): StructuredSearchQuery {
const structuredQuery = searchQueryParser.parse(query, {
keywords: [
'types',
'type',
'ids',
'id',
'tags',
'tag',
'pageSize',
'orderings',
// content type specific
'article-series',
],
});
const arrayedStructuredQuery = Object.keys(structuredQuery).reduce(
(acc, key) => {
const value = structuredQuery[key];
ipcMain.on('db-search', (event, query) => {
const searchOptions = {
keywords: ['slug', 'branch', 'name', 'owner', 'source', 'url', 'createdAt', 'updatedAt'],
ranges: ['createdAt', 'updatedAt']
};
let parsedQuery = searchQuery.parse(query, searchOptions);
if (typeof parsedQuery === 'string') {
if (parsedQuery !== '') {
parsedQuery = { slug: parsedQuery };
} else {
parsedQuery = {};
}
}
const { offsets, exclude, ...pq } = parsedQuery; // eslint-disable-line
this.utilsDb
.get(toMongo(pq))
.then((docs) => {
event.sender.send('reset-list', docs);
});
});
}
function discardQualifiers(query) {
query = searchQueryParser.parse(query, { keywords: qualifiers });
return (typeof query === 'string' ? query : query.text || '').trim();
}
parse(query: string) {
const parsedQuery = parse(query, this.config);
if (typeof parsedQuery === 'string') {
return {
text: parsedQuery,
} as SearchParserResult;
}
return parsedQuery;
}
}
parsed () {
return sQuery.parse(this.query, this.parser)
}
},
function discardQualifiers(query) {
query = searchQueryParser.parse(query, { keywords });
return (typeof query === 'string' ? query : query.text || '').trim();
}