@startupjs/server-aggregate v0.55.8
@startupjs/server-aggregate
Racer server aggregate plugin. It allows only server-defined aggregate queries.
install
yarn add @startupjs/server-aggregate
requirements
racer: 0.9.15
usage
In our client code:
require('@startupjs/server-aggregate/client')
On the server:
const serverAggregate = require('@startupjs/server-aggregate')
serverAggregate(backend, customCheck)
Here:
- `backend` - your backend
- `customCheck` - your personal check function. It should return an error message if there is an error. **IMPORTANT** The message must be of type `string`.
// function addAggregate accept
// 'collection' - collection name
// 'queryName' - name of query
// 'cb' - function that accepts 'params' and 'shareRequest'
// and returns a query-object or error-string
backend.addAggregate('items', 'main', async (params, shareRequest) => {
// ...
// access control or whatever
// ...
return [
{$match: {type: 'wooden'}}
]
})
Using queries (on the client):
// function aggregateQuery accepts 3 arguments:
// 'collection' - collection name (should match one from addServerQuery)
// 'queryName' - name of query (should match one from addServerQuery)
// 'params' - object with query-params
const query = model.aggregateQuery('items', 'main', {
type: 'global'
})
model.subscribe(query, function(){
// ...
})
Alternative approach (using regular model.query)
const query = model.query('items', {
$aggregationName: 'main',
$params: {
type: 'global'
}
})
model.subscribe(query, function(){
// ...
})
MIT License
Copyright (c) 2018 by Artur Zayats
2 months ago
4 months ago
5 months ago
5 months ago
7 months ago
6 months ago
9 months ago
6 months ago
7 months ago
7 months ago
12 months ago
12 months ago
12 months ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago