@startupjs/server-aggregate
Advanced tools
Comparing version 0.56.0-alpha.0 to 0.56.0-alpha.53
{ | ||
"name": "@startupjs/server-aggregate", | ||
"version": "0.56.0-alpha.0", | ||
"version": "0.56.0-alpha.53", | ||
"description": "Module for describing aggregations on the server", | ||
@@ -13,3 +13,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "076772b216a09281ed38b32866b576024562f099" | ||
"gitHead": "b262ddbd0ca367a0bd1669d3d39c2adae3739aba" | ||
} |
@@ -12,3 +12,3 @@ import ShareDBAccessError from './error.js' | ||
export default (backend, customCheck) => { | ||
export default (backend, { customCheck } = {}) => { | ||
backend.addAggregate = (collection, queryName, queryFunction) => { | ||
@@ -24,3 +24,9 @@ QUERIES[collection + '.' + queryName] = queryFunction | ||
if (query.$aggregate) throw new ShareDBAccessError(ERR_ACCESS_ONLY_SERVER_AGGREATE, `access denied - only server-queries for $aggregate are allowed, collection: '${collection}', query: '${query}'`) | ||
if (query.$aggregate) { | ||
throw new ShareDBAccessError(ERR_ACCESS_ONLY_SERVER_AGGREATE, ` | ||
access denied - only server-queries for $aggregate are allowed | ||
collection: '${collection}', | ||
query: \n${JSON.stringify(query, null, 2)} | ||
`) | ||
} | ||
if (!queryName && !queryParams) return | ||
@@ -50,2 +56,14 @@ | ||
if (Array.isArray(serverQuery)) serverQuery = { $aggregate: serverQuery } | ||
if (typeof serverQuery !== 'object') { | ||
throw new ShareDBAccessError(ERR_ACCESS_IN_SERVER_QUERY, ` | ||
access denied for server aggregation | ||
{ | ||
collection: '${collection}', | ||
$aggregationName: '${queryName}' | ||
} | ||
`) | ||
} | ||
if (customCheck) { | ||
@@ -58,3 +76,3 @@ const customPermissionMessage = await customCheck(shareRequest) | ||
shareRequest.query = { $aggregate: serverQuery } | ||
shareRequest.query = serverQuery | ||
} | ||
@@ -61,0 +79,0 @@ |
5013
92