Socket
Socket
Sign inDemoInstall

@startupjs/server-aggregate

Package Overview
Dependencies
Maintainers
6
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@startupjs/server-aggregate

Module for describing aggregations on the server


Version published
Weekly downloads
132
increased by312.5%
Maintainers
6
Weekly downloads
 
Created
Source

@startupjs/server-aggregate

Racer server aggregate plugin. It allows only server-defined aggregate queries.

Install

yarn add @startupjs/server-aggregate

Setup

In the client code:

require('@startupjs/server-aggregate/client')

On the server:

const serverAggregate = require('@startupjs/server-aggregate')
serverAggregate(backend, customCheck)

where:

  • backend: your ShareDB backend instance
  • customCheck (optional): your personal check function. It should return an error message if there is an error. IMPORTANT The message must be of type string.

How to add aggregation

On the server side to add aggregation use backend.addAggregate(collection, queryName, cb), where:

  • collection: collection name
  • queryName: query name (alias)
  • cb(params, shareRequest): async function that returns a query object or throw an error
backend.addAggregate('items', 'main', async (params, shareRequest) => {
  // ...
  // access control or whatever
  // ...

  return [
    {$match: {type: 'wooden'}}
  ]
})

Usage

model.query('items', {
  $aggregationName: 'main',
  $params: {
    type: 'global'
  }
})

When you setup the client side as described in the Setup section you can use the aggregateQuery(collection, queryName, params) function which is syntactic sugar over the model.query, where:

model.aggregateQuery('items', 'main', { type: 'global' })

MIT License

Copyright (c) 2018 by Artur Zayats

FAQs

Package last updated on 16 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc