@oliasoft-open-source/node-json-migrator 2.3.4 → 2.3.5-beta-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/dist/hash/hash.js CHANGED
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.hash = void 0;
7
- var crypto = _interopRequireWildcard(require("crypto"));
8
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
9
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
7
+ var _crypto = require("crypto");
10
8
  /**
11
9
  * Generate SHA256 hash from a string
12
10
  *
@@ -14,5 +12,5 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
14
12
  * @returns {String} SHA256 hash
15
13
  */
16
14
 
17
- const hash = string => crypto.createHash('sha256').update(string).digest('hex');
15
+ const hash = string => (0, _crypto.createHash)('sha256').update(string).digest('hex');
18
16
  exports.hash = hash;
@@ -51,9 +51,8 @@ const migrate = async ({
51
51
  } = await (0, _pending.getPendingMigrators)({
52
52
  config
53
53
  });
54
- const nextPayload = (0, _pipe.pipe)(pendingMigrators, payload);
55
54
  return {
56
- nextPayload,
55
+ nextPayload: pendingMigrators.length ? (0, _pipe.pipe)(pendingMigrators, payload) : payload,
57
56
  nextVersion
58
57
  };
59
58
  };
@@ -67,7 +67,7 @@ const getPendingMigrators = async ({
67
67
  });
68
68
  return {
69
69
  pendingMigrators,
70
- nextVersion
70
+ nextVersion: plannedMigrations.length < executedMigrations.length ? version : nextVersion
71
71
  };
72
72
  };
73
73
  exports.getPendingMigrators = getPendingMigrators;
package/dist/plan/plan.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.writePlan = exports.sortPlanEntries = exports.readPlan = exports.parsePlan = exports.getPlannedMigrations = exports.getNextSequenceString = exports.generatePlanEntries = void 0;
6
+ exports.writePlan = exports.sortPlanEntries = exports.readPlan = exports.parsePlan = exports.getPlannedMigrations = exports.getNextSequenceString = exports.generatePlanEntries = exports.formatJSON = void 0;
7
7
  var _path = _interopRequireDefault(require("path"));
8
8
  var _fs = require("fs");
9
9
  var _moduleFromString = require("module-from-string");
@@ -13,7 +13,16 @@ var _validator = require("./validator");
13
13
  var _database = require("../database/database");
14
14
  var _cachedPlannedVersion = require("./cached-planned-version");
15
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ /**
17
+ * Format JSON with 2-space indentation
18
+ *
19
+ * @param {String} json
20
+ * @returns {String} formatted json
21
+ */
22
+ const formatJSON = json => JSON.stringify(JSON.parse(json), null, 2);
23
+
16
24
  //https://stackoverflow.com/a/31102605/942635
25
+ exports.formatJSON = formatJSON;
17
26
  const sortEntry = entry => Object.keys(entry).sort().reduce((obj, key) => {
18
27
  obj[key] = entry[key];
19
28
  return obj;
@@ -60,9 +69,9 @@ const readPlan = async directory => {
60
69
  plan = await _fs.promises.readFile(`${directory}/plan.json`, {
61
70
  encoding: 'utf8'
62
71
  });
63
- return plan;
72
+ return formatJSON(plan);
64
73
  } catch {
65
- return '[]';
74
+ throw new Error('Invalid JSON for migrator plan.js (unable to parse file)');
66
75
  }
67
76
  };
68
77
 
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getPlannedVersion = void 0;
7
- var _fs = require("fs");
8
7
  var _hash = require("../hash/hash");
9
8
  var _plan = require("./plan");
10
9
  var _cachedPlannedVersion = require("./cached-planned-version");
@@ -14,9 +13,7 @@ const getPlannedVersion = async ({
14
13
  const {
15
14
  directory
16
15
  } = config;
17
- const currentPlan = await _fs.promises.readFile(`${directory}/plan.json`, {
18
- encoding: 'utf8'
19
- });
16
+ const currentPlan = await (0, _plan.readPlan)(directory);
20
17
  const plannedVersion = (0, _hash.hash)(currentPlan);
21
18
  const cachedPlannedVersion = (0, _cachedPlannedVersion.getCachedPlannedVersion)();
22
19
  return cachedPlannedVersion === plannedVersion ? cachedPlannedVersion : (await (0, _plan.getPlannedMigrations)({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/node-json-migrator",
3
- "version": "2.3.4",
3
+ "version": "2.3.5-beta-1",
4
4
  "description": "A library for JSON migrations",
5
5
  "homepage": "https://oliasoft-open-source.gitlab.io/node-postgresql-migrator",
6
6
  "bugs": {