@noego/proper 0.2.2 → 0.3.0
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/bin/cli.js +70 -45
- package/bin/cli.js.map +1 -1
- package/bin/cli.mjs +79 -47
- package/bin/cli.mjs.map +1 -1
- package/bin/index.d.mts +5 -0
- package/bin/index.d.ts +5 -0
- package/bin/index.js +70 -45
- package/bin/index.js.map +1 -1
- package/bin/index.mjs +70 -45
- package/bin/index.mjs.map +1 -1
- package/package.json +1 -1
- package/readme.md +8 -1
package/bin/cli.mjs
CHANGED
|
@@ -327,6 +327,79 @@ ${originalError.message}` : message, patchFile, patchKey);
|
|
|
327
327
|
}
|
|
328
328
|
});
|
|
329
329
|
|
|
330
|
+
// framework/MigrationManifest.ts
|
|
331
|
+
import fs from "fs";
|
|
332
|
+
import path from "path";
|
|
333
|
+
function isMigrationFile(fileName) {
|
|
334
|
+
return MIGRATION_FILE_REGEX.test(fileName);
|
|
335
|
+
}
|
|
336
|
+
function canonicalMigrationKey(value) {
|
|
337
|
+
return value.replace(MIGRATION_FILE_REGEX, "").toLowerCase();
|
|
338
|
+
}
|
|
339
|
+
function mintMigrationStamp(now = Date.now()) {
|
|
340
|
+
return now % 10 === 0 ? now + 1 : now;
|
|
341
|
+
}
|
|
342
|
+
function isHandStampedKey(key) {
|
|
343
|
+
const stamp = key.split("_")[0];
|
|
344
|
+
return /^\d+$/.test(stamp) && /000$/.test(stamp);
|
|
345
|
+
}
|
|
346
|
+
function resolveMigrationFile(directory, baseName, direction, dialect) {
|
|
347
|
+
const dialectExt = dialect === "sql" ? "mysql" : dialect;
|
|
348
|
+
const dialectFile = path.join(directory, `${baseName}.${dialectExt}.${direction}.sql`);
|
|
349
|
+
if (fs.existsSync(dialectFile)) return dialectFile;
|
|
350
|
+
const genericFile = path.join(directory, `${baseName}.${direction}.sql`);
|
|
351
|
+
if (fs.existsSync(genericFile)) return genericFile;
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
function loadMigrationManifest(directory, dialect) {
|
|
355
|
+
const manifest = /* @__PURE__ */ new Map();
|
|
356
|
+
if (!fs.existsSync(directory)) return manifest;
|
|
357
|
+
const files = fs.readdirSync(directory, { withFileTypes: true }).filter((f) => f.isFile()).map((f) => f.name).filter(isMigrationFile);
|
|
358
|
+
const uniqueKeys = /* @__PURE__ */ new Set();
|
|
359
|
+
files.forEach((file) => uniqueKeys.add(canonicalMigrationKey(file)));
|
|
360
|
+
uniqueKeys.forEach((key) => {
|
|
361
|
+
manifest.set(key, {
|
|
362
|
+
key,
|
|
363
|
+
upFile: resolveMigrationFile(directory, key, "up", dialect),
|
|
364
|
+
downFile: resolveMigrationFile(directory, key, "down", dialect)
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
return manifest;
|
|
368
|
+
}
|
|
369
|
+
var MIGRATION_FILE_REGEX;
|
|
370
|
+
var init_MigrationManifest = __esm({
|
|
371
|
+
"framework/MigrationManifest.ts"() {
|
|
372
|
+
MIGRATION_FILE_REGEX = /(?:\.(mysql|sqlite|pg))?\.(up|down)\.(sql|js)$/i;
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
// framework/MigrationConfig.ts
|
|
377
|
+
function validateLegacyMigrationKeys(value) {
|
|
378
|
+
if (value === void 0) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
if (!Array.isArray(value) || value.some((key) => !isExactCanonicalMigrationKey(key))) {
|
|
382
|
+
throw new ConfigurationError(
|
|
383
|
+
"legacy_migration_keys must be an array of nonempty exact canonical migration keys; filenames, paths, wildcards, and nonstrings are not allowed"
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
function isExactCanonicalMigrationKey(value) {
|
|
388
|
+
if (typeof value !== "string" || value.length === 0 || value !== value.trim()) {
|
|
389
|
+
return false;
|
|
390
|
+
}
|
|
391
|
+
if (value.includes("/") || value.includes("\\") || ["*", "?", "[", "]", "{", "}"].some((token) => value.includes(token))) {
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
return !isMigrationFile(value) && canonicalMigrationKey(value) === value;
|
|
395
|
+
}
|
|
396
|
+
var init_MigrationConfig = __esm({
|
|
397
|
+
"framework/MigrationConfig.ts"() {
|
|
398
|
+
init_errors();
|
|
399
|
+
init_MigrationManifest();
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
|
|
330
403
|
// framework/MigrationNode.ts
|
|
331
404
|
var MigrationNode, SqlMigrationNode;
|
|
332
405
|
var init_MigrationNode = __esm({
|
|
@@ -470,52 +543,6 @@ var init_SqlMigrationBuilder = __esm({
|
|
|
470
543
|
}
|
|
471
544
|
});
|
|
472
545
|
|
|
473
|
-
// framework/MigrationManifest.ts
|
|
474
|
-
import fs from "fs";
|
|
475
|
-
import path from "path";
|
|
476
|
-
function isMigrationFile(fileName) {
|
|
477
|
-
return MIGRATION_FILE_REGEX.test(fileName);
|
|
478
|
-
}
|
|
479
|
-
function canonicalMigrationKey(value) {
|
|
480
|
-
return value.replace(MIGRATION_FILE_REGEX, "").toLowerCase();
|
|
481
|
-
}
|
|
482
|
-
function mintMigrationStamp(now = Date.now()) {
|
|
483
|
-
return now % 10 === 0 ? now + 1 : now;
|
|
484
|
-
}
|
|
485
|
-
function isHandStampedKey(key) {
|
|
486
|
-
const stamp = key.split("_")[0];
|
|
487
|
-
return /^\d+$/.test(stamp) && /000$/.test(stamp);
|
|
488
|
-
}
|
|
489
|
-
function resolveMigrationFile(directory, baseName, direction, dialect) {
|
|
490
|
-
const dialectExt = dialect === "sql" ? "mysql" : dialect;
|
|
491
|
-
const dialectFile = path.join(directory, `${baseName}.${dialectExt}.${direction}.sql`);
|
|
492
|
-
if (fs.existsSync(dialectFile)) return dialectFile;
|
|
493
|
-
const genericFile = path.join(directory, `${baseName}.${direction}.sql`);
|
|
494
|
-
if (fs.existsSync(genericFile)) return genericFile;
|
|
495
|
-
return null;
|
|
496
|
-
}
|
|
497
|
-
function loadMigrationManifest(directory, dialect) {
|
|
498
|
-
const manifest = /* @__PURE__ */ new Map();
|
|
499
|
-
if (!fs.existsSync(directory)) return manifest;
|
|
500
|
-
const files = fs.readdirSync(directory, { withFileTypes: true }).filter((f) => f.isFile()).map((f) => f.name).filter(isMigrationFile);
|
|
501
|
-
const uniqueKeys = /* @__PURE__ */ new Set();
|
|
502
|
-
files.forEach((file) => uniqueKeys.add(canonicalMigrationKey(file)));
|
|
503
|
-
uniqueKeys.forEach((key) => {
|
|
504
|
-
manifest.set(key, {
|
|
505
|
-
key,
|
|
506
|
-
upFile: resolveMigrationFile(directory, key, "up", dialect),
|
|
507
|
-
downFile: resolveMigrationFile(directory, key, "down", dialect)
|
|
508
|
-
});
|
|
509
|
-
});
|
|
510
|
-
return manifest;
|
|
511
|
-
}
|
|
512
|
-
var MIGRATION_FILE_REGEX;
|
|
513
|
-
var init_MigrationManifest = __esm({
|
|
514
|
-
"framework/MigrationManifest.ts"() {
|
|
515
|
-
MIGRATION_FILE_REGEX = /(?:\.(mysql|sqlite|pg))?\.(up|down)\.(sql|js)$/i;
|
|
516
|
-
}
|
|
517
|
-
});
|
|
518
|
-
|
|
519
546
|
// framework/MigrationDirectoryReader.ts
|
|
520
547
|
import fs2 from "fs";
|
|
521
548
|
var MigrationDirectoryReader;
|
|
@@ -1798,6 +1825,7 @@ function makeRunner(database, conn) {
|
|
|
1798
1825
|
var MigrationRunnerFactory, MySQLMigrationRunner, FileMigrationConfigReader, MigrationCreator;
|
|
1799
1826
|
var init_MigrationRunner = __esm({
|
|
1800
1827
|
"framework/MigrationRunner.ts"() {
|
|
1828
|
+
init_MigrationConfig();
|
|
1801
1829
|
init_MigrationDirectoryReader();
|
|
1802
1830
|
init_MigrationSetup();
|
|
1803
1831
|
init_MigrationFilter();
|
|
@@ -1954,6 +1982,7 @@ var init_MigrationRunner = __esm({
|
|
|
1954
1982
|
*/
|
|
1955
1983
|
this.preflightPromise = null;
|
|
1956
1984
|
this.lastPatchResults = [];
|
|
1985
|
+
validateLegacyMigrationKeys(config.legacy_migration_keys);
|
|
1957
1986
|
}
|
|
1958
1987
|
setup() {
|
|
1959
1988
|
return __async(this, null, function* () {
|
|
@@ -2059,11 +2088,13 @@ var init_MigrationRunner = __esm({
|
|
|
2059
2088
|
}
|
|
2060
2089
|
migrate(migrationNodes, forward) {
|
|
2061
2090
|
return __async(this, null, function* () {
|
|
2091
|
+
var _a;
|
|
2062
2092
|
yield this.setup();
|
|
2063
2093
|
if (forward) {
|
|
2094
|
+
const legacyMigrationKeys = new Set((_a = this.config.legacy_migration_keys) != null ? _a : []);
|
|
2064
2095
|
for (const node of migrationNodes) {
|
|
2065
2096
|
const key = node.get_key();
|
|
2066
|
-
if (isHandStampedKey(key) && !(yield node.status()).completed) {
|
|
2097
|
+
if (isHandStampedKey(key) && !legacyMigrationKeys.has(key) && !(yield node.status()).completed) {
|
|
2067
2098
|
throw new MigrationStampError(key);
|
|
2068
2099
|
}
|
|
2069
2100
|
}
|
|
@@ -2163,6 +2194,7 @@ var init_MigrationRunner = __esm({
|
|
|
2163
2194
|
try {
|
|
2164
2195
|
const fileContent = fs6.readFileSync(this.configFile);
|
|
2165
2196
|
const config = JSON.parse(fileContent.toString());
|
|
2197
|
+
validateLegacyMigrationKeys(config.legacy_migration_keys);
|
|
2166
2198
|
if (!config.migration_folder) {
|
|
2167
2199
|
throw ConfigurationError.missingRequiredProperty("migration_folder");
|
|
2168
2200
|
}
|