@oliasoft-open-source/node-json-migrator 2.3.7 → 2.3.8-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/plan/cached-planned-version.js +7 -2
- package/dist/plan/plan.js +17 -12
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.setCachedPlannedVersion = exports.setCachedMigratorFunctions = exports.getCachedPlannedVersion = exports.getCachedMigratorFunctions = void 0;
|
|
6
|
+
exports.setCachedPlannedVersion = exports.setCachedMigratorFunctions = exports.getCachedPlannedVersion = exports.getCachedMigratorFunctions = exports.cacheHasAllMigrationFunctions = void 0;
|
|
7
7
|
let cachedPlannedVersion = null;
|
|
8
8
|
let cachedMigratorFunctions = [];
|
|
9
9
|
const getCachedPlannedVersion = () => cachedPlannedVersion;
|
|
@@ -17,4 +17,9 @@ exports.getCachedMigratorFunctions = getCachedMigratorFunctions;
|
|
|
17
17
|
const setCachedMigratorFunctions = scripts => {
|
|
18
18
|
cachedMigratorFunctions = scripts;
|
|
19
19
|
};
|
|
20
|
-
exports.setCachedMigratorFunctions = setCachedMigratorFunctions;
|
|
20
|
+
exports.setCachedMigratorFunctions = setCachedMigratorFunctions;
|
|
21
|
+
const cacheHasAllMigrationFunctions = ({
|
|
22
|
+
sortedMigrationEntries,
|
|
23
|
+
cachedMigrationEntries
|
|
24
|
+
}) => sortedMigrationEntries.every(migration => cachedMigrationEntries.some(cached => cached.fileHash === migration.fileHash && typeof cached.migrator === 'function'));
|
|
25
|
+
exports.cacheHasAllMigrationFunctions = cacheHasAllMigrationFunctions;
|
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.loadMigrationFunctions = exports.getPlannedMigrations = exports.getNextSequenceString = exports.generatePlanEntries = exports.formatJSON = void 0;
|
|
6
|
+
exports.writePlan = exports.sortPlanEntries = exports.readPlan = exports.parsePlan = exports.loadMigrationFunctionsFromStrings = exports.loadMigrationFunctions = exports.getPlannedMigrations = exports.getNextSequenceString = exports.generatePlanEntries = exports.formatJSON = void 0;
|
|
7
7
|
var _path = _interopRequireDefault(require("path"));
|
|
8
8
|
var _lodash = require("lodash");
|
|
9
9
|
var _fs = require("fs");
|
|
@@ -131,26 +131,31 @@ const generatePlanEntries = sortedMigrationEntries => sortedMigrationEntries.map
|
|
|
131
131
|
sequence: m.sequence
|
|
132
132
|
}));
|
|
133
133
|
exports.generatePlanEntries = generatePlanEntries;
|
|
134
|
+
const loadMigrationFunctionsFromStrings = async (sortedMigrationEntries, importModule) => Promise.all(sortedMigrationEntries.map(async m => {
|
|
135
|
+
const {
|
|
136
|
+
script
|
|
137
|
+
} = m;
|
|
138
|
+
const migrator = script && importModule ? (await (0, _moduleFromString.importFromString)(script))?.default : null;
|
|
139
|
+
return {
|
|
140
|
+
fileHash: m.fileHash,
|
|
141
|
+
migrator
|
|
142
|
+
};
|
|
143
|
+
}));
|
|
144
|
+
exports.loadMigrationFunctionsFromStrings = loadMigrationFunctionsFromStrings;
|
|
134
145
|
const loadMigrationFunctions = async (sortedMigrationEntries, nextVersion, importModule = true) => {
|
|
135
146
|
const cachedPlannedVersion = (0, _cachedPlannedVersion.getCachedPlannedVersion)();
|
|
136
147
|
const cachedMigratorFunctions = (0, _cachedPlannedVersion.getCachedMigratorFunctions)();
|
|
137
|
-
const cacheValid = cachedPlannedVersion === nextVersion &&
|
|
148
|
+
const cacheValid = cachedPlannedVersion === nextVersion && (0, _cachedPlannedVersion.cacheHasAllMigrationFunctions)({
|
|
149
|
+
sortedMigrationEntries,
|
|
150
|
+
cachedMigrationEntries: cachedMigratorFunctions
|
|
151
|
+
});
|
|
138
152
|
/*
|
|
139
153
|
OW-15584 the module-from-string package seems to have a memory leak bug
|
|
140
154
|
where calling importFromString multiple times consumes memory that
|
|
141
155
|
doesn't get released or garbage collected. We cache the imported strings
|
|
142
156
|
as a workaround (until plan.json version changes)
|
|
143
157
|
*/
|
|
144
|
-
const migrationFunctions = cacheValid ? cachedMigratorFunctions : await
|
|
145
|
-
const {
|
|
146
|
-
script
|
|
147
|
-
} = m;
|
|
148
|
-
const migrator = script && importModule ? (await (0, _moduleFromString.importFromString)(script))?.default : null;
|
|
149
|
-
return {
|
|
150
|
-
fileHash: m.fileHash,
|
|
151
|
-
migrator
|
|
152
|
-
};
|
|
153
|
-
}));
|
|
158
|
+
const migrationFunctions = cacheValid ? cachedMigratorFunctions : await loadMigrationFunctionsFromStrings(sortedMigrationEntries, importModule);
|
|
154
159
|
if (!cacheValid) {
|
|
155
160
|
(0, _cachedPlannedVersion.setCachedMigratorFunctions)(migrationFunctions);
|
|
156
161
|
(0, _cachedPlannedVersion.setCachedPlannedVersion)(nextVersion);
|
package/package.json
CHANGED