X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=src%2Fdb%2Fschema-version-helper.js;h=4582a872a1ff5def85ed100f38573a636ede9280;hb=f0bf29c75b0fd405ff92fa76f058e61162b87e43;hp=65a1e39f2c3cb64ceea5483f9dabf5606b35d736;hpb=4b7809255e4d2f07171963aacbe7488e93931da1;p=squeep-indie-auther diff --git a/src/db/schema-version-helper.js b/src/db/schema-version-helper.js index 65a1e39..4582a87 100644 --- a/src/db/schema-version-helper.js +++ b/src/db/schema-version-helper.js @@ -10,17 +10,17 @@ const path = require('path'); */ /** - * @typedef {Object} SchemaVersionObject - * @property {Number} major - * @property {Number} minor - * @property {Number} patch + * @typedef {object} SchemaVersionObject + * @property {number} major major + * @property {number} minor minor + * @property {number} patch patch */ /** * Split a dotted version string into parts. - * @param {String} v - * @returns {SchemaVersionObject} + * @param {string} v version string + * @returns {SchemaVersionObject} version object */ function schemaVersionStringToObject(v) { const [ major, minor, patch ] = v.split('.', 3).map((x) => parseInt(x, 10)); @@ -30,8 +30,9 @@ function schemaVersionStringToObject(v) { /** * Render a version object numerically. - * @param {SchemaVersionObject} v - * @returns {Number} + * Assumes no part will be greater than 1000. + * @param {SchemaVersionObject} v version object + * @returns {number} number */ function schemaVersionObjectToNumber(v) { const vScale = 1000; @@ -41,8 +42,8 @@ function schemaVersionObjectToNumber(v) { /** * Convert dotted version string into number. - * @param {String} v - * @returns {Number} + * @param {string} v version string + * @returns {number} number */ function schemaVersionStringToNumber(v) { return schemaVersionObjectToNumber(schemaVersionStringToObject(v)); @@ -51,9 +52,9 @@ function schemaVersionStringToNumber(v) { /** * Version string comparison, for sorting. - * @param {String} a - * @param {String} b - * @returns {Number} + * @param {string} a version string + * @param {string} b version string + * @returns {number} cmp */ function schemaVersionStringCmp(a, b) { return schemaVersionStringToNumber(a) - schemaVersionStringToNumber(b); @@ -62,9 +63,10 @@ function schemaVersionStringCmp(a, b) { /** * Check if an entry in a directory is a directory containing a migration file. - * @param {String} schemaDir - * @param {String} name - * @returns {Boolean} + * @param {string} schemaDir schema dir + * @param {string} name name + * @param {string} migrationFile migration file + * @returns {boolean} is */ function isSchemaMigrationDirectory(schemaDir, name, migrationFile = 'apply.sql') { // eslint-disable-next-line security/detect-non-literal-fs-filename @@ -75,7 +77,7 @@ function isSchemaMigrationDirectory(schemaDir, name, migrationFile = 'apply.sql' // eslint-disable-next-line security/detect-non-literal-fs-filename applyStat = fs.statSync(path.join(schemaDir, name, migrationFile)); return applyStat.isFile(); - } catch (e) { + } catch (e) { // eslint-disable-line no-unused-vars return false; } } @@ -86,8 +88,8 @@ function isSchemaMigrationDirectory(schemaDir, name, migrationFile = 'apply.sql' /** * Return an array of schema migration directory names within engineDir, * sorted in increasing order. - * @param {String} engineDir - * @returns {String[]} + * @param {string} engineDir path to implementation + * @returns {string[]} versions */ function allSchemaVersions(engineDir) { const schemaDir = path.join(engineDir, 'sql', 'schema'); @@ -101,12 +103,12 @@ function allSchemaVersions(engineDir) { /** * Return an array of schema migration directory names within engineDir, * which are within supported range, and are greater than the current - * @param {String} engineDir - * @param {SchemaVersionObject} current - * @param {Object} supported - * @param {SchemaVersionObject} supported.min - * @param {SchemaVersionObject} supported.max - * @returns {String[]} + * @param {string} engineDir path to implementation + * @param {SchemaVersionObject} current version + * @param {object} supported range of supported versions + * @param {SchemaVersionObject} supported.min minimum version + * @param {SchemaVersionObject} supported.max maximum version + * @returns {string[]} applicable versions */ function unappliedSchemaVersions(engineDir, current, supported) { const min = schemaVersionObjectToNumber(supported.min); @@ -128,4 +130,4 @@ module.exports = { isSchemaMigrationDirectory, allSchemaVersions, unappliedSchemaVersions, -}; \ No newline at end of file +};