Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@startupjs/server-aggregate

Package Overview
Dependencies
Maintainers
9
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

  • 0.35.0
  • npm
  • Socket score

Version published
Weekly downloads
124
increased by158.33%
Maintainers
9
Weekly downloads
 
Created
Source

@startupjs/server-aggregate

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

install

yarn add @startupjs/server-aggregate

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

FAQs

Package last updated on 13 May 2021

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