Socket
Socket
Sign inDemoInstall

follicle

Package Overview
Dependencies
16
Maintainers
3
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 2.0.1-0

8

build/lib/clients/client.js

@@ -85,2 +85,10 @@ "use strict";

removeIndex(collection, field) {
throw new TypeError('You must override removeIndex.');
}
listIndexes(collection) {
throw new TypeError('You must override listIndexes.');
}
static connect(url, options) {

@@ -87,0 +95,0 @@ throw new TypeError('You must override connect (static).');

@@ -18,2 +18,4 @@ "use strict";

var _util2 = _interopRequireDefault(require("util"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -306,2 +308,29 @@

/**
* Remove index
*
* @param {String} collection Collection's name
* @param {String} field Field name
* @returns {Promise}
*/
async removeIndex(collection, field) {
const db = this._mongo.collection(collection);
await _util2.default.promisify(db.removeIndex.bind(db))(field);
}
/**
* List indexes
*
* @param {String} collection Collection's name
* @returns {Promise<Array<>>}
*/
async listIndexes(collection) {
const db = this._mongo.collection(collection);
return await db.listIndexes().next(); // TODO: will fail if there are more than 1k indexes
}
/**
* Create index

@@ -308,0 +337,0 @@ *

@@ -287,2 +287,27 @@ "use strict";

/**
* Remove index
*
* @param {String} collection Collection's name
* @param {String} field Field name
* @returns {Promise}
*/
async removeIndex(collection, field) {
const db = await getCollection(collection, this._collections, this._path, this._options, this._readOnly);
await _util.default.promisify(db.removeIndex.bind(db))(field);
}
/**
* List indexes
*
* @param {String} collection Collection's name
* @returns {Promise<Array<string>>}
*/
async listIndexes(collection) {
const db = await getCollection(collection, this._collections, this._path, this._options, this._readOnly);
return Object.keys(db.indexes);
}
/**
* Create index

@@ -289,0 +314,0 @@ *

@@ -274,2 +274,27 @@ "use strict";

/**
* Remove index
*
* @param {String} collection Collection's name
* @param {String} field Field name
* @returns {Promise}
*/
async removeIndex(collection, field) {
const db = await getCollection(collection, this._collections, this._path, this._options, this._readOnly);
await _util.default.promisify(db.removeIndex.bind(db))(field);
}
/**
* List indexes
*
* @param {String} collection Collection's name
* @returns {Promise<Array<string>>}
*/
async listIndexes(collection) {
const db = await getCollection(collection, this._collections, this._path, this._options, this._readOnly);
return Object.keys(db.indexes);
}
/**
* Create index

@@ -276,0 +301,0 @@ *

@@ -370,2 +370,14 @@ "use strict";

static removeIndexes() {
return client._startTask(this._removeIndexes());
}
static async _removeIndexes() {
for (const k of await client.listIndexes(this.collectionName())) {
if (k !== '_id') await client.removeIndex(this.collectionName(), k);
}
this._indexesCreated = false;
}
static createIndexes() {

@@ -436,4 +448,6 @@ return client._startTask(this._createIndexes());

}, {});
if (data.length) await this.removeIndexes();
const migrate = (0, _util.migrateDocument)(this._getMigrations());
await Promise.all(data.map(entry => migrate(entry)).map(async entry => client.save(this.collectionName(), entry._id, entry)));
await this.createIndexes();
}

@@ -440,0 +454,0 @@ /**

2

package.json

@@ -12,3 +12,3 @@ {

],
"version": "2.0.0",
"version": "2.0.1-0",
"description": "A class-based ES6 ODM for Mongo-like databases.",

@@ -15,0 +15,0 @@ "author": {

@@ -73,2 +73,10 @@ export default class DatabaseClient {

removeIndex (collection, field) {
throw new TypeError('You must override removeIndex.')
}
listIndexes (collection) {
throw new TypeError('You must override listIndexes.')
}
static connect (url, options) {

@@ -75,0 +83,0 @@ throw new TypeError('You must override connect (static).')

@@ -6,2 +6,3 @@ import DatabaseClient from './client'

import { URL } from 'url'
import util from 'util'

@@ -253,2 +254,25 @@ export default class MongoClient extends DatabaseClient {

/**
* Remove index
*
* @param {String} collection Collection's name
* @param {String} field Field name
* @returns {Promise}
*/
async removeIndex (collection, field) {
const db = this._mongo.collection(collection)
await util.promisify(db.removeIndex.bind(db))(field)
}
/**
* List indexes
*
* @param {String} collection Collection's name
* @returns {Promise<Array<>>}
*/
async listIndexes (collection) {
const db = this._mongo.collection(collection)
return await db.listIndexes().next() // TODO: will fail if there are more than 1k indexes
}
/**
* Create index

@@ -255,0 +279,0 @@ *

@@ -242,2 +242,25 @@ import * as path from 'path'

/**
* Remove index
*
* @param {String} collection Collection's name
* @param {String} field Field name
* @returns {Promise}
*/
async removeIndex (collection, field) {
const db = await getCollection(collection, this._collections, this._path, this._options, this._readOnly)
await util.promisify(db.removeIndex.bind(db))(field)
}
/**
* List indexes
*
* @param {String} collection Collection's name
* @returns {Promise<Array<string>>}
*/
async listIndexes (collection) {
const db = await getCollection(collection, this._collections, this._path, this._options, this._readOnly)
return Object.keys(db.indexes)
}
/**
* Create index

@@ -244,0 +267,0 @@ *

@@ -228,2 +228,25 @@ import * as path from 'path'

/**
* Remove index
*
* @param {String} collection Collection's name
* @param {String} field Field name
* @returns {Promise}
*/
async removeIndex (collection, field) {
const db = await getCollection(collection, this._collections, this._path, this._options, this._readOnly)
await util.promisify(db.removeIndex.bind(db))(field)
}
/**
* List indexes
*
* @param {String} collection Collection's name
* @returns {Promise<Array<string>>}
*/
async listIndexes (collection) {
const db = await getCollection(collection, this._collections, this._path, this._options, this._readOnly)
return Object.keys(db.indexes)
}
/**
* Create index

@@ -230,0 +253,0 @@ *

@@ -333,2 +333,13 @@ import depd from 'depd'

static removeIndexes () {
return client._startTask(this._removeIndexes())
}
static async _removeIndexes () {
for (const k of await client.listIndexes(this.collectionName())) {
if (k !== '_id') await client.removeIndex(this.collectionName(), k)
}
this._indexesCreated = false
}
static createIndexes () {

@@ -391,2 +402,3 @@ return client._startTask(this._createIndexes())

const data = await client.find(this.collectionName(), { _version: { $ne: this._getDocumentVersion() } }, {})
if (data.length) await this.removeIndexes()
const migrate = migrateDocument(this._getMigrations())

@@ -397,2 +409,3 @@ await Promise.all(data

)
await this.createIndexes()
}

@@ -399,0 +412,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc