anote-server-libs 0.2.13 → 0.3.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.
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseModelRepository = void 0;
4
+ const crypto = require("crypto");
4
5
  const fs = require("fs");
5
- const node_forge_1 = require("node-forge");
6
6
  const ApiCall_1 = require("../ApiCall");
7
7
  const Migration_1 = require("../Migration");
8
8
  class BaseModelRepository {
@@ -23,7 +23,7 @@ class BaseModelRepository {
23
23
  this.Migration = new Migration_1.MigrationRepository(db, dbMssql, logger);
24
24
  this.ApiCall = new ApiCall_1.ApiCallRepository(db, dbMssql, logger);
25
25
  }
26
- migrate(migrationsPath, callback) {
26
+ migrate(migrationsPath, callback, onlyAboveOrEquals = 0) {
27
27
  (this.db ? this.db.query('CREATE TABLE IF NOT EXISTS migration (' +
28
28
  'id integer PRIMARY KEY,' +
29
29
  'hash text NOT NULL,' +
@@ -51,19 +51,19 @@ class BaseModelRepository {
51
51
  return {
52
52
  id: file,
53
53
  content: content,
54
- hash: node_forge_1.md.sha256.create().update(content).digest().toHex()
54
+ hash: crypto.createHash('sha256').update(content).digest('hex')
55
55
  };
56
56
  });
57
57
  if (migrationsAvailable.length === 0
58
58
  || migrationsAvailable.length
59
59
  !== migrationsAvailable[migrationsAvailable.length - 1].id)
60
60
  process.exit(5);
61
- let highestCommon = 0;
61
+ let highestCommon = onlyAboveOrEquals;
62
62
  while (highestCommon < migrations.length && highestCommon < migrationsAvailable.length
63
63
  && migrations[highestCommon].hash === migrationsAvailable[highestCommon].hash)
64
64
  highestCommon++;
65
65
  this.applyDownUntil(migrations, migrations.length, highestCommon).then(() => {
66
- this.applyUpUntil(migrationsAvailable, highestCommon, migrationsAvailable.length).then(callback, process.exit);
66
+ this.applyUpUntil(migrationsAvailable, Math.min(highestCommon, migrations.length), migrationsAvailable.length).then(callback, process.exit);
67
67
  }, process.exit);
68
68
  });
69
69
  }, () => process.exit(3));
@@ -25,7 +25,7 @@ export class BaseModelRepository {
25
25
  this.ApiCall = new ApiCallRepository(db, dbMssql, logger);
26
26
  }
27
27
 
28
- migrate(migrationsPath: string, callback: (() => void)) {
28
+ migrate(migrationsPath: string, callback: (() => void), onlyAboveOrEquals = 0) {
29
29
  (this.db ? this.db.query('CREATE TABLE IF NOT EXISTS migration (' +
30
30
  'id integer PRIMARY KEY,' +
31
31
  'hash text NOT NULL,' +
@@ -59,12 +59,12 @@ export class BaseModelRepository {
59
59
  if(migrationsAvailable.length === 0
60
60
  || migrationsAvailable.length
61
61
  !== migrationsAvailable[migrationsAvailable.length - 1].id) process.exit(5); // Did not use OK files
62
- let highestCommon = 0;
62
+ let highestCommon = onlyAboveOrEquals;
63
63
  while(highestCommon < migrations.length && highestCommon < migrationsAvailable.length
64
64
  && migrations[highestCommon].hash === migrationsAvailable[highestCommon].hash)
65
65
  highestCommon++;
66
66
  this.applyDownUntil(migrations, migrations.length, highestCommon).then(() => {
67
- this.applyUpUntil(migrationsAvailable, highestCommon, migrationsAvailable.length).then(callback, process.exit);
67
+ this.applyUpUntil(migrationsAvailable, Math.min(highestCommon, migrations.length), migrationsAvailable.length).then(callback, process.exit);
68
68
  }, process.exit);
69
69
  });
70
70
  }, () => process.exit(3));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anote-server-libs",
3
- "version": "0.2.13",
3
+ "version": "0.3.1",
4
4
  "description": "Helpers for express-TS servers",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",