@discue/mongodb-resource-client
Advanced tools
Comparing version 0.35.0 to 0.36.0
@@ -34,6 +34,9 @@ export = exports; | ||
*/ | ||
protected _withActiveSpan(spanName: any, resourceIds: any, callback: any): Promise<any>; | ||
protected _runWithActiveSpan(spanName: any, resourceIds: any, callback: any): Promise<any>; | ||
/** | ||
* @typedef {import('mongodb').ClientSession} ClientSession | ||
*/ | ||
/** | ||
* @callback WithSessionCallback | ||
* @param {import('mongodb').ClientSession} | ||
* @param {ClientSession} clientSession | ||
*/ | ||
@@ -44,3 +47,3 @@ /** | ||
*/ | ||
protected _withTransaction(callback: (: import('mongodb').ClientSession) => any): Promise<any>; | ||
protected _withTransaction(callback: (clientSession: import("mongodb").ClientSession) => any): Promise<any>; | ||
/** | ||
@@ -47,0 +50,0 @@ * @protected |
@@ -84,3 +84,3 @@ 'use strict' | ||
async _getDb(givenClient) { | ||
return this._withActiveSpan('get-db-instance', null, async () => { | ||
return this._runWithActiveSpan('get-db-instance', null, async () => { | ||
const client = givenClient ?? await this._getConnectedClient() | ||
@@ -98,3 +98,3 @@ return client.db(this._databaseName) | ||
async _getCollection(collectionName, givenClient) { | ||
return this._withActiveSpan('get-db-collection', null, async () => { | ||
return this._runWithActiveSpan('get-db-collection', null, async () => { | ||
if (collectionName && typeof collectionName !== 'string') { | ||
@@ -112,3 +112,3 @@ givenClient = collectionName | ||
*/ | ||
async _withActiveSpan(spanName, resourceIds, callback) { | ||
async _runWithActiveSpan(spanName, resourceIds, callback) { | ||
return withActiveSpan(`${name}#${spanName}`, { 'peer.service': 'resource-client', resourceIds, resourceName: this._collectionName, databaseName: this._databaseName }, callback) | ||
@@ -118,4 +118,8 @@ } | ||
/** | ||
* @typedef {import('mongodb').ClientSession} ClientSession | ||
*/ | ||
/** | ||
* @callback WithSessionCallback | ||
* @param {import('mongodb').ClientSession} | ||
* @param {ClientSession} clientSession | ||
*/ | ||
@@ -122,0 +126,0 @@ |
@@ -11,3 +11,3 @@ export = exports; | ||
_usageEventPrefix: any; | ||
_resourceStorage: any; | ||
_resourceStorage: ResourceStorage; | ||
/** | ||
@@ -44,2 +44,3 @@ * Activate listening for storage events to monitor changes of target storage resource to | ||
} | ||
import ResourceStorage = require("./simple-resource-storage.js"); | ||
type ConstructorOptions = any; |
@@ -1,3 +0,3 @@ | ||
export const SimpleResourceStorage: any; | ||
export const SimpleTimeseriesStorage: any; | ||
export const SimpleResourceStorage: typeof import("./simple-resource-storage.js"); | ||
export const SimpleTimeseriesStorage: typeof import("./simple-timeseries-storage.js"); | ||
export const OneToFewRefStorage: typeof import("./one-to-few-ref-storage.js"); | ||
@@ -4,0 +4,0 @@ export const OneToFewResourceStorage: typeof import("./one-to-few-resource-storage.js"); |
@@ -8,3 +8,3 @@ export = exports; | ||
constructor({ client, databaseName, connectTimeout }?: ConstructorOptions); | ||
_resourceStorage: any; | ||
_resourceStorage: ResourceStorage; | ||
/** | ||
@@ -82,2 +82,3 @@ * Creates an entry in the `locks` collection. The context param is a unique identifier. If context already | ||
} | ||
import ResourceStorage = require("./simple-resource-storage.js"); | ||
type ConstructorOptions = { | ||
@@ -84,0 +85,0 @@ /** |
export = exports; | ||
declare class exports { | ||
declare class exports extends Base { | ||
/** | ||
@@ -10,14 +10,2 @@ * @public | ||
/** | ||
* Returns true if a resource with given ids exists. | ||
* | ||
* @method exists | ||
* @param {String|Array.<String>} resourceIds | ||
* @returns {boolean} | ||
*/ | ||
exists(resourceIds: string | Array<string>): boolean; | ||
/** | ||
* @private | ||
*/ | ||
private _withActiveSpan; | ||
/** | ||
* Returns all references. | ||
@@ -62,2 +50,3 @@ * | ||
} | ||
import Base = require("./simple-resource-storage.js"); | ||
type ConstructorOptions = { | ||
@@ -64,0 +53,0 @@ /** |
export = exports; | ||
declare class exports { | ||
declare class exports extends Base { | ||
/** | ||
@@ -9,4 +9,2 @@ * @public | ||
/** @private */ private _resourceName; | ||
/** @private */ private _emitUsageEvent; | ||
get usageEventPrefix(): string; | ||
/** | ||
@@ -22,6 +20,2 @@ * Returns a resource by ids. | ||
/** | ||
* @private | ||
*/ | ||
private _withActiveSpan; | ||
/** | ||
* Returns all resources. | ||
@@ -68,2 +62,3 @@ * | ||
} | ||
import Base = require("./simple-resource-storage.js"); | ||
import { Timestamp } from "mongodb"; | ||
@@ -70,0 +65,0 @@ type ConstructorOptions = { |
export = exports; | ||
declare class exports { | ||
declare class exports extends Base { | ||
/** | ||
@@ -16,18 +16,4 @@ * @public | ||
/** @private */ private _resourceLevel; | ||
/** @private */ private _emitUsageEventEnabled; | ||
/** @private */ private _childEmitUsageEvent; | ||
get usageEventPrefix(): string; | ||
/** | ||
* Returns true if a resource with given ids exists. | ||
* | ||
* @name exists | ||
* @param {String|Array.<String>} resourceIds | ||
* @returns {boolean} | ||
*/ | ||
exists(resourceIds: string | Array<string>): boolean; | ||
/** | ||
* @private | ||
*/ | ||
private _withActiveSpan; | ||
/** | ||
* Returns a resource by ids. | ||
@@ -79,3 +65,3 @@ * | ||
_getResourceWithLookup(resourceIds: string | Array<string>, options?: GetOptions): any; | ||
_getParentCollection(): Promise<any>; | ||
_getParentCollection(): Promise<import("mongodb").Collection<import("bson").Document>>; | ||
/** | ||
@@ -117,10 +103,2 @@ * | ||
/** | ||
* Deletes a resource by ids | ||
* | ||
* @name delete | ||
* @param {String|Array.<String>} resourceIds resource ids that will added to the resource path i.e. /users/${id}/documents/${id} | ||
* @returns | ||
*/ | ||
delete(resourceIds: string | Array<string>): Promise<any>; | ||
/** | ||
* Closes all clients. | ||
@@ -135,2 +113,3 @@ * | ||
} | ||
import Base = require("./simple-resource-storage.js"); | ||
type ConstructorOptions = { | ||
@@ -137,0 +116,0 @@ /** |
@@ -1,2 +0,1 @@ | ||
/// <reference types="node" /> | ||
export = exports; | ||
@@ -24,2 +23,6 @@ declare class exports extends Base { | ||
/** | ||
* @private | ||
*/ | ||
private _withActiveSpan; | ||
/** | ||
* @callback WithSessionCallback | ||
@@ -198,2 +201,42 @@ * @param {import('mongodb').ClientSession} | ||
} | ||
declare namespace exports { | ||
export { ConstructorOptions, GetOptions, WithMongoClient, Collection, MongoClient }; | ||
} | ||
import Base = require("./base-storage.js"); | ||
type ConstructorOptions = { | ||
/** | ||
* configured mongo client to use. Can be null if url is set | ||
*/ | ||
client: MongoClient; | ||
/** | ||
* name of the mongodb database | ||
*/ | ||
databaseName?: string; | ||
/** | ||
* name of the mongodb collection used to store the resources | ||
*/ | ||
collectionName: string; | ||
/** | ||
* indexes to be created on instantiation. Use format {key:1} for single indexes and {key1: 1, key:2} for compound indexes. See https://www.mongodb.com/docs/manual/reference/command/createIndexes/#command-fields | ||
*/ | ||
indexes?: Array<any>; | ||
/** | ||
* if provided, will trigger events base on resource creation, updates and deletion | ||
*/ | ||
eventEmitter: import('node:events').EventEmitter; | ||
}; | ||
type GetOptions = { | ||
/** | ||
* true if also meta data should be returned | ||
*/ | ||
withMetadata: boolean; | ||
/** | ||
* MongoDB projection object e.g. { id: 0, name: 0 } | ||
*/ | ||
projection: any; | ||
}; | ||
type WithMongoClient = { | ||
client: import('mongodb').MongoClient; | ||
}; | ||
type Collection = import('mongodb').Collection; | ||
type MongoClient = import('mongodb').MongoClient; |
@@ -1,2 +0,1 @@ | ||
/// <reference types="node" /> | ||
export = exports; | ||
@@ -16,2 +15,6 @@ declare class exports extends BaseStorage { | ||
/** | ||
* @private | ||
*/ | ||
private _withActiveSpan; | ||
/** | ||
* Returns all resources that pass the given aggregation stages. | ||
@@ -35,2 +38,39 @@ * | ||
} | ||
declare namespace exports { | ||
export { ConstructorOptions, GetOptions, Collection, MongoClient }; | ||
} | ||
import BaseStorage = require("./base-storage.js"); | ||
type ConstructorOptions = { | ||
/** | ||
* configured mongo client to use. Can be null if url is set | ||
*/ | ||
client: MongoClient; | ||
/** | ||
* name of the mongodb database | ||
*/ | ||
databaseName?: string; | ||
/** | ||
* name of the mongodb collection used to store the resources | ||
*/ | ||
collectionName: string; | ||
/** | ||
* indexes to be created on instantiation. Use format {key:1} for single indexes and {key1: 1, key:2} for compound indexes. See https://www.mongodb.com/docs/manual/reference/command/createIndexes/#command-fields | ||
*/ | ||
indexes?: Array<any>; | ||
/** | ||
* if provided, will trigger events base on resource creation, updates and deletion | ||
*/ | ||
eventEmitter: import('node:events').EventEmitter; | ||
}; | ||
type GetOptions = { | ||
/** | ||
* true if also meta data should be returned | ||
*/ | ||
withMetadata: boolean; | ||
/** | ||
* MongoDB projection object e.g. { id: 0, name: 0 } | ||
*/ | ||
projection: any; | ||
}; | ||
type Collection = import('mongodb').Collection; | ||
type MongoClient = import('mongodb').MongoClient; |
@@ -82,3 +82,3 @@ 'use strict' | ||
super._getDb().then((db) => { | ||
db.createCollection(collectionName, { timeseries: { timeField, metaField, granularity } }) | ||
db.createCollection(collectionName, { timeseries: { timeField, metaField, granularity } }).catch(() => { }) | ||
}) | ||
@@ -85,0 +85,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "0.35.0", | ||
"version": "0.36.0", | ||
"description": "Simple wrapper around mongodb client allowing easier managing of resources", | ||
@@ -8,0 +8,0 @@ "main": "lib/index", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
137432
3492