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

@discue/mongodb-resource-client

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@discue/mongodb-resource-client - npm Package Compare versions

Comparing version 0.38.1 to 0.39.0

12

lib/simple-resource-storage.d.ts

@@ -121,2 +121,14 @@ export = exports;

/**
* Returns the count of all children of a certain type/collection.
*
* Currently only supports trees with three levels.
*
* @name countAllChildren
* @param {String|Array.<String>} resourceIds resource ids that will added to the resource path i.e. /users/${id}/documents/${id}
* @param {String|Array.<String>} childPath the path of the children to query e.g. /api_clients/queues/messages
* @param {GetChildrenOptions} [options]
* @returns {Promise.<number>}
*/
countAllChildren(resourceIds: string | Array<string>, childPath: string | Array<string>, { withMetadata, projection, match }?: GetChildrenOptions): Promise<number>;
/**
* Returns all resources that pass the given aggregation stages.

@@ -123,0 +135,0 @@ *

39

lib/simple-resource-storage.js

@@ -267,3 +267,2 @@ 'use strict'

const result = await toArrayAndClose(cursor)
if (result.length === 0) {

@@ -281,2 +280,40 @@ return {}

/**
* Returns the count of all children of a certain type/collection.
*
* Currently only supports trees with three levels.
*
* @name countAllChildren
* @param {String|Array.<String>} resourceIds resource ids that will added to the resource path i.e. /users/${id}/documents/${id}
* @param {String|Array.<String>} childPath the path of the children to query e.g. /api_clients/queues/messages
* @param {GetChildrenOptions} [options]
* @returns {Promise.<number>}
*/
async countAllChildren(resourceIds, childPath, { withMetadata = false, projection, match } = {}) {
return this._withActiveSpan('count-all-simple-resource-children', resourceIds, async () => {
if (childPath.startsWith('/')) {
childPath = childPath.substring(1)
}
const [parent, child] = childPath.split('/')
if (!parent || !child) {
throw new Error(`childPath with value ${childPath} does not match expected value "parent/child"`)
}
const lookupPipeline = getSingleLookupPipeline({ rootId: this._toStringIfArray(resourceIds), childCollectionName: parent })
const childResourcesPipeline = joinAndQueryChildResourcesPipeline({ parentCollectionName: parent, childCollectionName: child, options: { withMetadata, projection, match } })
lookupPipeline.push(...childResourcesPipeline)
lookupPipeline.push(PROJECT({ count: { $size: '$children' } }))
const collection = await this._getCollection()
const cursor = collection.aggregate(lookupPipeline)
const result = await toArrayAndClose(cursor)
if (result.length === 0) {
return 0
}
return result.at(0).count
})
}
/**
* Returns all resources that pass the given aggregation stages.

@@ -283,0 +320,0 @@ *

2

package.json

@@ -5,3 +5,3 @@ {

"license": "MIT",
"version": "0.38.1",
"version": "0.39.0",
"description": "Simple wrapper around mongodb client allowing easier managing of resources",

@@ -8,0 +8,0 @@ "main": "lib/index",

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