@data-fair/lib-node 2.0.3 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/mongo.d.ts +3 -2
  2. package/mongo.js +7 -3
  3. package/package.json +1 -1
package/mongo.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import type { IndexSpecification, CreateIndexesOptions, MongoClientOptions } from 'mongodb';
1
+ import type { IndexSpecification, CreateIndexesOptions, MongoClientOptions, IndexDirection } from 'mongodb';
2
2
  import { MongoClient } from 'mongodb';
3
- export type IndexDefinitions = Record<string, Record<string, IndexSpecification | [IndexSpecification, CreateIndexesOptions]>>;
3
+ type IndexDirections = Record<string, IndexDirection>;
4
+ export type IndexDefinitions = Record<string, Record<string, null | IndexDirections | [IndexDirections, CreateIndexesOptions]>>;
4
5
  export declare class Mongo {
5
6
  private _client;
6
7
  get client(): MongoClient;
package/mongo.js CHANGED
@@ -45,12 +45,16 @@ export class Mongo {
45
45
  for (const collectionName in indexDefinitions) {
46
46
  for (const indexName in indexDefinitions[collectionName]) {
47
47
  let key, options
48
- if (Array.isArray(indexDefinitions[collectionName][indexName])) {
49
- [key, options] = indexDefinitions[collectionName][indexName]
48
+ const indexDefinition = indexDefinitions[collectionName][indexName]
49
+ if (indexDefinition === null) {
50
+ await this.db.collection(collectionName).dropIndex(indexName)
51
+ continue
52
+ } else if (Array.isArray(indexDefinition)) {
53
+ [key, options] = indexDefinition
50
54
  if (options.name && options.name !== indexName) { throw new Error(`inconsistent index name ${indexName} or ${options.name}`) }
51
55
  options.name = indexName
52
56
  } else {
53
- key = indexDefinitions[collectionName][indexName]
57
+ key = indexDefinition
54
58
  options = { name: indexName }
55
59
  }
56
60
  await this.ensureIndex(collectionName, key, options)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-fair/lib-node",
3
- "version": "2.0.3",
3
+ "version": "2.1.0",
4
4
  "description": "Small nodejs related utility functions for the data-fair stack.",
5
5
  "main": "index.js",
6
6
  "files": [