@data-fair/lib-node 2.0.3 → 2.1.1
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.
- package/mongo.d.ts +3 -2
- package/mongo.js +7 -3
- package/package.json +1 -1
- package/upgrade-scripts.js +5 -2
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
|
-
|
|
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
|
-
|
|
49
|
-
|
|
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 =
|
|
57
|
+
key = indexDefinition
|
|
54
58
|
options = { name: indexName }
|
|
55
59
|
}
|
|
56
60
|
await this.ensureIndex(collectionName, key, options)
|
package/package.json
CHANGED
package/upgrade-scripts.js
CHANGED
|
@@ -14,8 +14,11 @@ export default async function (db, locks, basePath = './') {
|
|
|
14
14
|
// containers for the scripts that are running in only 1 (while loop on "acquire" ?) and a healthcheck
|
|
15
15
|
// are not considered "up" and the previous versions keep running in the mean time
|
|
16
16
|
} else {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
try {
|
|
18
|
+
await runScripts(db, basePath)
|
|
19
|
+
} finally {
|
|
20
|
+
await locks.release('upgrade')
|
|
21
|
+
}
|
|
19
22
|
}
|
|
20
23
|
}
|
|
21
24
|
async function runScripts (db, basePath) {
|