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.31.0 to 0.32.0

2

lib/aggregations.js

@@ -0,1 +1,3 @@

'use strict'
/**

@@ -2,0 +4,0 @@ * Returns a $match aggregation stage

@@ -0,1 +1,3 @@

'use strict'
/**

@@ -2,0 +4,0 @@ *

2

lib/history.d.ts

@@ -7,3 +7,3 @@ export = exports;

*/
constructor({ url, client, databaseName, collectionName, connectTimeout, usageEventPrefix, eventEmitter }?: any);
constructor({ client, databaseName, collectionName, connectTimeout, usageEventPrefix, eventEmitter }?: any);
_eventEmitter: any;

@@ -10,0 +10,0 @@ _collectionName: any;

@@ -0,1 +1,3 @@

'use strict'
const { createTracer } = require('@discue/open-telemetry-tracing')

@@ -17,8 +19,6 @@ const ResourceStorage = require('./simple-resource-storage.js')

* @description Options for class constructor
* @property {String} [url=null] url to mongo instance. Can be null if client is set
* @property {MongoClient} [client=null] configured mongo client to use. Can be null if url is set
* @property {MongoClient} client configured mongo client to use. Can be null if url is set
* @property {string} [databaseName=null] name of the mongodb database
* @property {string} collectionName name of the mongodb collection used to store the resources
* @property {string} usageEventPrefix the usageEventPrefix of the target storage module
* @property {number} [connectTimeout=10_000] the connect timeout of the mongo db client if client was not passed
* @property {import('node:events').EventEmitter} eventEmitter if provided, will trigger events base on resource creation, updates and deletion

@@ -61,3 +61,3 @@ *

*/
constructor({ url, client, databaseName, collectionName, connectTimeout = 10_000, usageEventPrefix, eventEmitter } = {}) {
constructor({ client, databaseName, collectionName, connectTimeout = 10_000, usageEventPrefix, eventEmitter } = {}) {

@@ -68,3 +68,3 @@ this._eventEmitter = eventEmitter

this._resourceStorage = new ResourceStorage({ url, client, databaseName, collectionName: this._collectionName, connectTimeout })
this._resourceStorage = new ResourceStorage({ client, databaseName, collectionName: this._collectionName, connectTimeout })
}

@@ -71,0 +71,0 @@

@@ -0,1 +1,3 @@

'use strict'
const { createTracer } = require('@discue/open-telemetry-tracing')

@@ -2,0 +4,0 @@ const SpanStatusCode = require('@discue/open-telemetry-tracing/status-codes')

@@ -0,1 +1,3 @@

'use strict'
const { PROJECT, EQUALS, LOOKUP, REDUCE, CONCAT_ARRAYS, TO_OBJECT, LET, APPEND_OBJECTS, JOIN_STRINGS, EQUALS_ALL } = require('./aggregations.js')

@@ -2,0 +4,0 @@

@@ -52,10 +52,6 @@ export = exports;

/**
* url to mongo instance. Can be null if client is set
* =null configured mongo client to use. Can be null if url is set
*/
url?: string;
client: MongoClient;
/**
* configured mongo client to use. Can be null if url is set
*/
client?: MongoClient;
/**
* name of the mongodb database

@@ -62,0 +58,0 @@ */

@@ -0,1 +1,3 @@

'use strict'
const { createTracer } = require('@discue/open-telemetry-tracing')

@@ -17,4 +19,3 @@ const { EQUALS_ANY_OF, EQUALS } = require('./aggregations.js')

* @typedef ConstructorOptions
* @property {String} [url=null] url to mongo instance. Can be null if client is set
* @property {MongoClient} [client=null] configured mongo client to use. Can be null if url is set
* @property {MongoClient} client configured mongo client to use. Can be null if url is set
* @property {string} [databaseName=null] name of the mongodb database

@@ -25,5 +26,11 @@ * @property {string} collectionName name of the mongodb collection used to store the resources

* @example
* const { MongoClient } = require('mongodb')
* const { OneToFewRefstorage } = require('@discue/mongodb-resource-client')
* const onetoFewRefStorage = new OneToFewRefStorage({
* url: 'mongodb://127.0.0.1:27017',
*
* const client = new MongoClient(url, {
* serverApi: { version: '1', strict: true, deprecationErrors: true }, // https://www.mongodb.com/docs/manual/reference/stable-api/
* })
*
* const oneToFewRefStorage = new OneToFewRefStorage({
* client,
* collectionName: 'api_clients',

@@ -30,0 +37,0 @@ * resourceName: 'queues'

@@ -64,9 +64,5 @@ export = exports;

/**
* url to mongo instance. Can be null if client is set
*/
url?: string;
/**
* configured mongo client to use. Can be null if url is set
*/
client?: MongoClient;
client: MongoClient;
/**

@@ -73,0 +69,0 @@ * name of the mongodb database

@@ -0,1 +1,3 @@

'use strict'
const { PROJECT, EQUALS, LIMIT } = require('./aggregations.js')

@@ -19,4 +21,3 @@ const eventTrigger = require('./usage-event-trigger.js')

* @typedef ConstructorOptions
* @property {String} [url=null] url to mongo instance. Can be null if client is set
* @property {MongoClient} [client=null] configured mongo client to use. Can be null if url is set
* @property {MongoClient} client configured mongo client to use. Can be null if url is set
* @property {string} [databaseName=null] name of the mongodb database

@@ -28,5 +29,11 @@ * @property {string} collectionName name of the mongodb collection used to store the resources

* @example
* const { MongoClient } = require('mongodb')
* const { OneToFewResourceStorage } = require('@discue/mongodb-resource-client')
*
* const client = new MongoClient(url, {
* serverApi: { version: '1', strict: true, deprecationErrors: true }, // https://www.mongodb.com/docs/manual/reference/stable-api/
* })
*
* const oneToFewResourceStorage = new OneToFewResourceStorage({
* url: 'mongodb://127.0.0.1:27017',
* client,
* collectionName: 'api_clients',

@@ -33,0 +40,0 @@ * resourceName: 'queues'

@@ -0,1 +1,3 @@

'use strict'
const Base = require('./simple-resource-storage.js')

@@ -22,4 +24,3 @@ const OneToFewStorage = require('./one-to-few-ref-storage.js')

* @typedef ConstructorOptions
* @property {String} [url=null] url to mongo instance. Can be null if client is set
* @property {MongoClient} [client=null] configured mongo client to use. Can be null if url is set
* @property {MongoClient} client configured mongo client to use. Can be null if url is set
* @property {string} [databaseName=null] name of the mongodb database

@@ -34,5 +35,11 @@ * @property {string} collectionName name of the mongodb collection used to store the resources

* @example
* const { MongoClient } = require('mongodb')
* const { OneToManyResourceStorage } = require('@discue/mongodb-resource-client')
*
* const client = new MongoClient(url, {
* serverApi: { version: '1', strict: true, deprecationErrors: true }, // https://www.mongodb.com/docs/manual/reference/stable-api/
* })
*
* const oneToManyResourceStorage = new OneToManyResourceStorage({
* url: 'mongodb://127.0.0.1:27017',
* client,
* collectionName: 'api_clients',

@@ -39,0 +46,0 @@ * resourceName: 'listeners'

@@ -0,3 +1,3 @@

'use strict'
/**

@@ -4,0 +4,0 @@ *

@@ -8,5 +8,4 @@ export = exports;

*/
constructor({ url, client, databaseName, collectionName, connectTimeout, eventEmitter }?: ConstructorOptions);
_mongoDbClient: MongoClient;
/** @private */ private _url;
constructor({ client, databaseName, collectionName, eventEmitter }?: ConstructorOptions);
_mongoDbClient: import("mongodb").MongoClient;
/** @private */ private _databaseName;

@@ -249,3 +248,2 @@ /** @private */ private _useSharedClient;

}
import { MongoClient } from "mongodb";
type ConstructorOptions = {

@@ -269,6 +267,2 @@ /**

/**
* the connect timeout of the mongo db client if client was not passed
*/
connectTimeout?: number;
/**
* if provided, will trigger events base on resource creation, updates and deletion

@@ -275,0 +269,0 @@ */

@@ -1,2 +0,4 @@

const { MongoClient, Timestamp } = require('mongodb')
'use strict'
const { Timestamp } = require('mongodb')
const { EQUALS, LIMIT, PROJECT } = require('./aggregations.js')

@@ -24,9 +26,14 @@ const eventTrigger = require('./usage-event-trigger.js')

* @property {string} collectionName name of the mongodb collection used to store the resources
* @property {number} [connectTimeout=10_000] the connect timeout of the mongo db client if client was not passed
* @property {import('node:events').EventEmitter} eventEmitter if provided, will trigger events base on resource creation, updates and deletion
*
* @example
* const { MongoClient } = require('mongodb')
* const { SimpleResourceStorage } = require('@discue/mongodb-resource-client')
*
* const client = new MongoClient(url, {
* serverApi: { version: '1', strict: true, deprecationErrors: true }, // https://www.mongodb.com/docs/manual/reference/stable-api/
* })
*
* const storage = new SimpleResourceStorage({
* url: 'mongodb://127.0.0.1:27017',
* client,
* collectionName: 'api_clients',

@@ -71,18 +78,9 @@ * })

*/
constructor({ url, client, databaseName, collectionName, connectTimeout = 10_000, eventEmitter } = {}) {
constructor({ client, databaseName, collectionName, eventEmitter } = {}) {
if (client) {
this._mongoDbClient = client
} else if (url) {
this._mongoDbClient = new MongoClient(url, {
connectTimeoutMS: connectTimeout,
})
// if no client was provided, we need to take care of closing it
process.on('SIGTERM', () => {
this._mongoDbClient.close()
})
} else {
throw new Error('Configuration Error. Either `url` or `client` needs to be set.')
throw new Error('Configuration Error. `client` needs to be set.')
}
/** @private */ this._url = url
/** @private */ this._databaseName = process.env.DSQ_MONGODB_RESOURCE_CLIENT_DB_NAME || databaseName

@@ -89,0 +87,0 @@ /** @private */ this._useSharedClient = process.env.DSQ_MONGODB_USE_SHARED_DB_CLIENT === 'false' ? false : true

@@ -0,3 +1,5 @@

'use strict'
const { Timestamp } = require('mongodb')
module.exports.Timestamp = Timestamp

@@ -0,1 +1,3 @@

'use strict'
/**

@@ -2,0 +4,0 @@ *

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

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

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

@@ -55,2 +55,3 @@

```javascript
const { MongoClient } = require('mongodb')
const { EventEmiter } = require('events')

@@ -63,4 +64,8 @@ const { OneToFewResourceStorage, ResourceStorageHistory } = require('@discue/mongodb-resource-client')

const client = new MongoClient(url, {
serverApi: { version: '1', strict: true, deprecationErrors: true }, // https://www.mongodb.com/docs/manual/reference/stable-api/
})
const oneToFewResourceStorage = new OneToFewResourceStorage({
url,
client,
collectionName,

@@ -71,3 +76,3 @@ eventEmitter

const history = new ResourceStorageHistory({
url,
client,
collectionName,

@@ -74,0 +79,0 @@ usageEventPrefix: oneToFewResourceStorage.usageEventPrefix

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