@codefresh-io/service-base 4.0.7 → 5.0.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/codefresh.yaml CHANGED
@@ -8,13 +8,13 @@ steps:
8
8
 
9
9
  install_dependencies:
10
10
  title: 'Installing testing dependencies'
11
- image: node:14.0.0
11
+ image: node:${{NODE_VERSION}}
12
12
  commands:
13
13
  - yarn install --frozen-lockfile
14
14
 
15
15
  eslint:
16
16
  title: 'Running linting logic'
17
- image: node:12.13.0
17
+ image: node:${{NODE_VERSION}}
18
18
  commands:
19
19
  - yarn eslint
20
20
 
@@ -2,15 +2,15 @@ const { splitUriBySlash, getDbNameFromUri } = require('../helper');
2
2
  const { MongoMemoryServer } = require('mongodb-memory-server');
3
3
  const mongoClient = require('../mongo');
4
4
 
5
-
5
+ /**
6
+ * @type {MongoMemoryServer}
7
+ */
6
8
  let mongod;
7
9
  async function clientSetupByUriAndDbName() {
8
- const uri = await mongod.getUri();
9
- const port = await mongod.getPort();
10
+ const uri = mongod.getUri();
11
+ const { port, dbPath, dbName } = mongod.instanceInfo;
10
12
  console.log(`using port ${port}`);
11
- const dbPath = await mongod.getDbPath();
12
13
  console.log(`dbPath ${dbPath}`);
13
- const dbName = await mongod.getDbName();
14
14
  console.log(`dbName ${dbName}`);
15
15
 
16
16
  await mongoClient.init({ mongo: { uri, dbName } });
@@ -19,7 +19,7 @@ async function clientSetupByUriAndDbName() {
19
19
 
20
20
  describe('mongo init compatibility code', () => {
21
21
  beforeEach(async () => {
22
- mongod = new MongoMemoryServer();
22
+ mongod = await MongoMemoryServer.create();
23
23
  });
24
24
  afterEach(async () => {
25
25
  await mongoClient.stop();
@@ -46,8 +46,8 @@ describe('mongo init compatibility code', () => {
46
46
  });
47
47
 
48
48
  it('smokeTest2.2.33 and 3.6 extracted dbname', async () => {
49
- const uri = await mongod.getUri();
50
- const dbName = await mongod.getDbName();
49
+ const uri = mongod.getUri();
50
+ const { dbName } = mongod.instanceInfo;
51
51
  expect(dbName)
52
52
  .toEqual(getDbNameFromUri(uri));
53
53
  await mongoClient.init({ mongo: { uri } });
@@ -61,7 +61,7 @@ describe('mongo init compatibility code', () => {
61
61
  });
62
62
 
63
63
  it('db.db old use driver 2.x style API of uri no dbname param', async () => {
64
- const uri = await mongod.getUri();
64
+ const uri = mongod.getUri();
65
65
  await mongoClient.init({ mongo: { uri } });
66
66
  const pipelineManagerDB = mongoClient.client.db(process.env.PIPELINE_MANAGER_DB || 'pipeline-manager');
67
67
  const stepCollection = pipelineManagerDB.collection('steps');
@@ -71,8 +71,8 @@ describe('mongo init compatibility code', () => {
71
71
  });
72
72
 
73
73
  it('client.db 3.x the new style using client', async () => {
74
- const uri = await mongod.getUri();
75
- const dbName = await mongod.getDbName();
74
+ const uri = mongod.getUri();
75
+ const { dbName } = mongod.instanceInfo;
76
76
  expect(dbName).toEqual(getDbNameFromUri(uri));
77
77
  await mongoClient.init({ mongo: { uri } });
78
78
  const pipelineManagerDB = await mongoClient.client.db(process.env.PIPELINE_MANAGER_DB || 'pipeline-manager');
@@ -85,8 +85,8 @@ describe('mongo init compatibility code', () => {
85
85
  });
86
86
 
87
87
  it('additional uses', async () => {
88
- const uri = await mongod.getUri();
89
- const dbName = await mongod.getDbName();
88
+ const uri = mongod.getUri();
89
+ const { dbName } = mongod.instanceInfo;
90
90
  expect(dbName).toEqual(getDbNameFromUri(uri));
91
91
  await mongoClient.init({ mongo: { uri } });
92
92
  // eslint-disable-next-line prefer-destructuring
@@ -94,11 +94,11 @@ describe('mongo init compatibility code', () => {
94
94
  expect(ObjectId).toBeTruthy();
95
95
 
96
96
  const collection = mongoClient.collection('charts');
97
- await collection.ensureIndex({ account: 1, repository: 1, name: 1, version: 1 }, {
97
+ await collection.createIndex({ account: 1, repository: 1, name: 1, version: 1 }, {
98
98
  unique: true,
99
99
  background: true,
100
100
  });
101
- await collection.ensureIndex({ created: 1 }, { expireAfterSeconds: 60 });
101
+ await collection.createIndex({ created: 1 }, { expireAfterSeconds: 60 });
102
102
  const generateObjectId = () => new mongoClient.ObjectId().toString();
103
103
  const objectId = generateObjectId();
104
104
  expect(objectId).toBeTruthy();
@@ -47,7 +47,7 @@ function getOrCreateSafe(safeId) {
47
47
  _id: safeId,
48
48
  key: (new Buffer(uuid.v4())).toString('base64'), // eslint-disable-line
49
49
  };
50
- return collection.save(newSafe)
50
+ return collection.insertOne(newSafe)
51
51
  .then(() => new Safe(newSafe))
52
52
  .catch((err) => {
53
53
  throw new Error(`Error occurred while creating safe: ${safeId}. Caused by: ${err.toString()}`);
package/infra/mongo.js CHANGED
@@ -1,6 +1,3 @@
1
-
2
-
3
- const Promise = require('bluebird');
4
1
  const { MongoClient, ObjectId } = require('mongodb');
5
2
  const { getDbNameFromUri } = require('./helper');
6
3
 
@@ -12,31 +9,26 @@ class Mongo {
12
9
 
13
10
  /**
14
11
  * starts the connection to mongo
15
- * @returns {*}
12
+ * @returns {Promise<void>}
16
13
  */
17
- init(config) {
18
- const clientSettings = {
19
- promiseLibrary: Promise,
20
- ...config.mongo.options,
21
- };
14
+ async init(config) {
15
+ const clientSettings = { ...config.mongo.options };
22
16
 
23
17
  const logger = require('cf-logs').Logger('codefresh:infra:mongo'); // eslint-disable-line
24
18
  this.logger = logger;
25
19
 
26
20
  const { uri } = config.mongo;
27
21
  const dbName = config.mongo.dbName || getDbNameFromUri(uri);
28
- return MongoClient.connect(uri, clientSettings)
29
- .then(async (client) => {
30
- this.client = client;
31
- this.db = await client.db(dbName);
32
- logger.info('Mongo driver connected');
33
- });
22
+ const client = await MongoClient.connect(uri, clientSettings);
23
+ this.client = client;
24
+ this.db = client.db(dbName);
25
+ logger.info('Mongo driver connected');
34
26
  }
35
27
 
36
28
 
37
29
  /**
38
30
  * stops the connection to mongo
39
- * @returns {*}
31
+ * @returns {Promise<void>}
40
32
  */
41
33
  stop() {
42
34
  if (!this.db) {
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "@codefresh-io/service-base",
3
- "version": "4.0.7",
3
+ "version": "5.0.1",
4
4
  "main": "index.js",
5
5
  "description": "",
6
6
  "bin": {
7
7
  "cf-openapi": "./node_modules/cf-openapi/bin/cf-openapi"
8
8
  },
9
+ "engines": {
10
+ "node": ">=12.22.12"
11
+ },
9
12
  "scripts": {
10
13
  "test": "(find . -not -path './node_modules/*' -path '*/*.spec.js' | grep -v '__tests__' | NODE_ENV=test xargs mocha) && jest",
11
14
  "start": "node index.js",
@@ -49,7 +52,7 @@
49
52
  "js-yaml": "^3.13.1",
50
53
  "lodash": "4.17.21",
51
54
  "method-override": "^3.0.0",
52
- "mongodb": "~3.3.0",
55
+ "mongodb": "^4.17.2",
53
56
  "morgan": "^1.9.1",
54
57
  "node-uuid": "^1.4.8",
55
58
  "proxyquire": "^1.8.0",
@@ -59,14 +62,14 @@
59
62
  "request-promise": "4.2.6"
60
63
  },
61
64
  "devDependencies": {
62
- "@shelf/jest-mongodb": "^1.2.2",
65
+ "@shelf/jest-mongodb": "^4.2.0",
63
66
  "eslint": "^4.18.2",
64
67
  "eslint-config-airbnb-base": "^12.1.0",
65
68
  "eslint-plugin-import": "^2.9.0",
66
- "eslint-plugin-jest": "^21.12.3",
69
+ "eslint-plugin-jest": "^27.6.3",
67
70
  "eslint-plugin-mocha": "^4.12.1",
68
- "jest": "^26.4.0",
71
+ "jest": "^29.7.0",
69
72
  "mocha": "^8.2.1",
70
- "mongodb-memory-server": "^6.6.3"
73
+ "mongodb-memory-server": "^9.1.6"
71
74
  }
72
75
  }