alp-migrations 9.0.0 → 10.0.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/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [10.0.0](https://github.com/christophehurpeau/alp/compare/alp-migrations@9.0.0...alp-migrations@10.0.0) (2025-08-02)
7
+
8
+ ### ⚠ BREAKING CHANGES
9
+
10
+ * update dependencies and drop node 20
11
+ * update dev dependencies, replace parse-json-object-as-map with native JSON.parse, update koa
12
+ * update liwi-mongo
13
+ * update router-segments
14
+
15
+ ### Features
16
+
17
+ * update dependencies and drop node 20 ([fc5b322](https://github.com/christophehurpeau/alp/commit/fc5b322e076e9a3c7c4a235d16734b89fd85e211))
18
+ * update dev dependencies, replace parse-json-object-as-map with native JSON.parse, update koa ([5ae7723](https://github.com/christophehurpeau/alp/commit/5ae77238cafc573fe72c5eb63b103802b8b2e537))
19
+ * update liwi-mongo ([55e04ba](https://github.com/christophehurpeau/alp/commit/55e04baac1ccc46b83880dd03076b0ab0d705ae2))
20
+ * update router-segments ([07ff52b](https://github.com/christophehurpeau/alp/commit/07ff52b3f851204256509056d0a4b25e1f630e5b))
21
+
22
+ Version bump for dependency: alp-node
23
+
24
+
6
25
  ## [9.0.0](https://github.com/christophehurpeau/alp/compare/alp-migrations@8.2.1...alp-migrations@9.0.0) (2024-01-06)
7
26
 
8
27
 
package/README.md CHANGED
@@ -1,16 +1,16 @@
1
- <h3 align="center">
1
+ <h1 align="center">
2
2
  alp-migrations
3
- </h3>
3
+ </h1>
4
4
 
5
5
  <p align="center">
6
6
  migrations scripts in alp
7
7
  </p>
8
8
 
9
9
  <p align="center">
10
- <a href="https://npmjs.org/package/alp-migrations"><img src="https://img.shields.io/npm/v/alp-migrations.svg?style=flat-square"></a>
11
- <a href="https://npmjs.org/package/alp-migrations"><img src="https://img.shields.io/npm/dw/alp-migrations.svg?style=flat-square"></a>
12
- <a href="https://npmjs.org/package/alp-migrations"><img src="https://img.shields.io/node/v/alp-migrations.svg?style=flat-square"></a>
13
- <a href="https://npmjs.org/package/alp-migrations"><img src="https://img.shields.io/npm/types/alp-migrations.svg?style=flat-square"></a>
10
+ <a href="https://npmjs.org/package/alp-migrations"><img src="https://img.shields.io/npm/v/alp-migrations.svg?style=flat-square" alt="npm version"></a>
11
+ <a href="https://npmjs.org/package/alp-migrations"><img src="https://img.shields.io/npm/dw/alp-migrations.svg?style=flat-square" alt="npm downloads"></a>
12
+ <a href="https://npmjs.org/package/alp-migrations"><img src="https://img.shields.io/node/v/alp-migrations.svg?style=flat-square" alt="node version"></a>
13
+ <a href="https://npmjs.org/package/alp-migrations"><img src="https://img.shields.io/npm/types/alp-migrations.svg?style=flat-square" alt="types"></a>
14
14
  </p>
15
15
 
16
16
  ## Install
@@ -26,7 +26,7 @@ http://alpjs.github.io/alp-migrations/docs
26
26
  ## Usage
27
27
 
28
28
  ```js
29
- import alpMigrations from 'alp-migrations';
29
+ import alpMigrations from "alp-migrations";
30
30
 
31
31
  console.log(alpMigrations);
32
32
  ```
@@ -1,4 +1,4 @@
1
- import type { MongoStore, MongoInsertType, MongoBaseModel } from 'liwi-mongo';
1
+ import type { MongoBaseModel, MongoInsertType, MongoStore } from "liwi-mongo";
2
2
  export interface Migration extends MongoBaseModel {
3
3
  version: string;
4
4
  fileName: string;
@@ -1 +1 @@
1
- {"version":3,"file":"Manager.d.ts","sourceRoot":"","sources":["../../src/Manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE9E,MAAM,WAAW,SAAU,SAAQ,cAAc;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;gBAEjB,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC;IAIxC,eAAe,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAI9C,gBAAgB,CAAC,SAAS,EAAE,eAAe,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC;CAG5E"}
1
+ {"version":3,"file":"Manager.d.ts","sourceRoot":"","sources":["../../src/Manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE9E,MAAM,WAAW,SAAU,SAAQ,cAAc;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;gBAEjB,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC;IAIxC,eAAe,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAI9C,gBAAgB,CAAC,SAAS,EAAE,eAAe,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC;CAG5E"}
@@ -1,10 +1,10 @@
1
- import type AlpNodeApp from 'alp-node';
2
- import type MigrationsManager from './Manager';
3
- export { default as MigrationsManager } from './Manager';
1
+ import type AlpNodeApp from "alp-node";
2
+ import type MigrationsManager from "./Manager";
3
+ export { default as MigrationsManager } from "./Manager";
4
4
  export interface Options {
5
5
  app: AlpNodeApp;
6
6
  migrationsManager: MigrationsManager;
7
- config?: AlpNodeApp['config'];
7
+ config?: AlpNodeApp["config"];
8
8
  dirname?: string;
9
9
  }
10
10
  export default function migrate({ app, migrationsManager, config, dirname, }: Options): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,UAAU,CAAC;AAGvC,OAAO,KAAK,iBAAiB,MAAM,WAAW,CAAC;AAM/C,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEzD,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,UAAU,CAAC;IAChB,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,MAAM,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAA8B,OAAO,CAAC,EACpC,GAAG,EACH,iBAAiB,EACjB,MAAmB,EACnB,OAAqC,GACtC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAgEzB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,UAAU,CAAC;AAGvC,OAAO,KAAK,iBAAiB,MAAM,WAAW,CAAC;AAM/C,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEzD,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,UAAU,CAAC;IAChB,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,MAAM,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAA8B,OAAO,CAAC,EACpC,GAAG,EACH,iBAAiB,EACjB,MAAmB,EACnB,OAAqC,GACtC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAiEzB"}
@@ -1,5 +1,4 @@
1
- /// <reference types="node" />
2
- import type { Stats } from 'node:fs';
1
+ import type { Stats } from "node:fs";
3
2
  export interface CallbackParam {
4
3
  filename: string;
5
4
  basedir: string;
@@ -1 +1 @@
1
- {"version":3,"file":"readRecursiveDirectory.d.ts","sourceRoot":"","sources":["../../src/readRecursiveDirectory.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGrC,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,KAAK,CAAC;CACb;AAED,wBAA8B,sBAAsB,CAClD,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GACvD,OAAO,CAAC,IAAI,CAAC,CAoBf"}
1
+ {"version":3,"file":"readRecursiveDirectory.d.ts","sourceRoot":"","sources":["../../src/readRecursiveDirectory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGrC,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,KAAK,CAAC;CACb;AAED,wBAA8B,sBAAsB,CAClD,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GACvD,OAAO,CAAC,IAAI,CAAC,CAoBf"}
@@ -7,7 +7,7 @@ async function readRecursiveDirectory(directory, callback) {
7
7
  await Promise.all(files.map(async file => {
8
8
  const path = `${directory}/${file}`;
9
9
  const stat$1 = await stat(path);
10
- if (stat$1?.isDirectory()) {
10
+ if (stat$1.isDirectory()) {
11
11
  await readRecursiveDirectory(path, callback);
12
12
  return;
13
13
  }
@@ -36,7 +36,7 @@ class MigrationsManager {
36
36
 
37
37
  /* eslint-disable unicorn/no-process-exit */
38
38
 
39
- const logger = new Logger('alp:migrations');
39
+ const logger = new Logger("alp:migrations");
40
40
  async function migrate({
41
41
  app,
42
42
  migrationsManager,
@@ -44,25 +44,25 @@ async function migrate({
44
44
  dirname = `${app.dirname}/migrations`
45
45
  }) {
46
46
  const unhandledRejectionHandler = reason => {
47
- logger.error('unhandledRejection', {
47
+ logger.error("unhandledRejection", {
48
48
  err: reason
49
49
  });
50
50
  process.exit(1);
51
51
  };
52
- process.on('unhandledRejection', unhandledRejectionHandler);
52
+ process.on("unhandledRejection", unhandledRejectionHandler);
53
53
  const packageVersion = config.packageConfig.version;
54
54
  const currentVersion = await migrationsManager.findLastVersion();
55
55
  let migrations = [];
56
- logger.info('migrate', {
56
+ logger.info("migrate", {
57
57
  packageVersion,
58
58
  currentVersion
59
59
  });
60
60
  await readRecursiveDirectory(dirname, res => {
61
61
  const fileName = res.path.slice(dirname.length + 1);
62
- if (!fileName.endsWith('.js')) {
62
+ if (!fileName.endsWith(".js")) {
63
63
  return;
64
64
  }
65
- const versionExecResult = /([\d.]+)(_.*|\.js)$/.exec(fileName);
65
+ const versionExecResult = /([\d.]+)(?:_.*|\.js)$/.exec(fileName);
66
66
  if (!versionExecResult?.[1]) {
67
67
  return;
68
68
  }
@@ -95,8 +95,8 @@ async function migrate({
95
95
  logger.error(error);
96
96
  process.exit(1);
97
97
  }
98
- process.removeListener('unhandledRejection', unhandledRejectionHandler);
98
+ process.removeListener("unhandledRejection", unhandledRejectionHandler);
99
99
  }
100
100
 
101
101
  export { MigrationsManager, migrate as default };
102
- //# sourceMappingURL=index-node18.mjs.map
102
+ //# sourceMappingURL=index-node20.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-node20.mjs","sources":["../src/readRecursiveDirectory.ts","../src/Manager.ts","../src/index.ts"],"sourcesContent":["import type { Stats } from \"node:fs\";\nimport { stat as fsStat, readdir } from \"node:fs/promises\";\n\nexport interface CallbackParam {\n filename: string;\n basedir: string;\n path: string;\n stat: Stats;\n}\n\nexport default async function readRecursiveDirectory(\n directory: string,\n callback: (param: CallbackParam) => Promise<void> | void,\n): Promise<void> {\n const files = await readdir(directory);\n\n await Promise.all(\n files.map(async (file): Promise<void> => {\n const path = `${directory}/${file}`;\n const stat = await fsStat(path);\n\n if (stat.isDirectory()) {\n await readRecursiveDirectory(path, callback);\n return;\n }\n await callback({\n filename: file,\n basedir: directory,\n path,\n stat,\n });\n }),\n );\n}\n","import type { MongoBaseModel, MongoInsertType, MongoStore } from \"liwi-mongo\";\n\nexport interface Migration extends MongoBaseModel {\n version: string;\n fileName: string;\n}\n\nexport default class MigrationsManager {\n store: MongoStore<Migration>;\n\n constructor(store: MongoStore<Migration>) {\n this.store = store;\n }\n\n findLastVersion(): Promise<string | undefined> {\n return this.store.findOne({}, { created: -1 }).then((row) => row?.version);\n }\n\n addMigrationDone(migration: MongoInsertType<Migration>): Promise<Migration> {\n return this.store.insertOne(migration);\n }\n}\n","/* eslint-disable unicorn/no-process-exit */\nimport type AlpNodeApp from \"alp-node\";\nimport { Logger } from \"nightingale-logger\";\nimport semver from \"semver\";\nimport type MigrationsManager from \"./Manager\";\nimport type { CallbackParam } from \"./readRecursiveDirectory\";\nimport readRecursiveDirectory from \"./readRecursiveDirectory\";\n\nconst logger = new Logger(\"alp:migrations\");\n\nexport { default as MigrationsManager } from \"./Manager\";\n\nexport interface Options {\n app: AlpNodeApp;\n migrationsManager: MigrationsManager;\n config?: AlpNodeApp[\"config\"];\n dirname?: string;\n}\n\nexport default async function migrate({\n app,\n migrationsManager,\n config = app.config,\n dirname = `${app.dirname}/migrations`,\n}: Options): Promise<void> {\n const unhandledRejectionHandler = (reason: unknown): void => {\n logger.error(\"unhandledRejection\", { err: reason });\n\n process.exit(1);\n };\n process.on(\"unhandledRejection\", unhandledRejectionHandler);\n\n const packageVersion = config.packageConfig.version as string;\n const currentVersion = await migrationsManager.findLastVersion();\n\n let migrations: { version: string; fileName: string }[] = [];\n\n logger.info(\"migrate\", { packageVersion, currentVersion });\n\n await readRecursiveDirectory(dirname, (res: CallbackParam) => {\n const fileName = res.path.slice(dirname.length + 1);\n\n if (!fileName.endsWith(\".js\")) {\n return;\n }\n\n const versionExecResult = /([\\d.]+)(?:_.*|\\.js)$/.exec(fileName);\n\n if (!versionExecResult?.[1]) {\n return;\n }\n\n const version: string = versionExecResult[1];\n\n if (currentVersion && semver.lte(version, currentVersion)) return;\n\n migrations.push({ version, fileName });\n });\n\n migrations = migrations.sort((a, b) =>\n semver.gt(a.version, b.version) ? 1 : -1,\n );\n\n try {\n for (const migration of migrations) {\n logger.info(`Migration to ${migration.fileName}`);\n try {\n const migrateFn: unknown = await import(\n `${dirname}/${migration.fileName}`\n );\n await (migrateFn as () => Promise<void>)();\n } catch (error) {\n logger.error(`Migration to ${migration.version} Failed !`);\n throw error;\n }\n\n logger.success(`Migration to ${migration.fileName} done !`);\n\n // only add to db if migration version <= package version\n if (semver.lte(migration.version, packageVersion)) {\n await migrationsManager.addMigrationDone(migration);\n }\n }\n } catch (error: any) {\n logger.error(error as Error);\n process.exit(1);\n }\n\n process.removeListener(\"unhandledRejection\", unhandledRejectionHandler);\n}\n"],"names":["readRecursiveDirectory","directory","callback","files","readdir","Promise","all","map","file","path","stat","fsStat","isDirectory","filename","basedir","MigrationsManager","constructor","store","findLastVersion","findOne","created","then","row","version","addMigrationDone","migration","insertOne","logger","Logger","migrate","app","migrationsManager","config","dirname","unhandledRejectionHandler","reason","error","err","process","exit","on","packageVersion","packageConfig","currentVersion","migrations","info","res","fileName","slice","length","endsWith","versionExecResult","exec","semver","lte","push","sort","a","b","gt","migrateFn","success","removeListener"],"mappings":";;;;AAUe,eAAeA,sBAAsBA,CAClDC,SAAiB,EACjBC,QAAwD,EACzC;AACf,EAAA,MAAMC,KAAK,GAAG,MAAMC,OAAO,CAACH,SAAS,CAAC;EAEtC,MAAMI,OAAO,CAACC,GAAG,CACfH,KAAK,CAACI,GAAG,CAAC,MAAOC,IAAI,IAAoB;AACvC,IAAA,MAAMC,IAAI,GAAG,CAAA,EAAGR,SAAS,CAAA,CAAA,EAAIO,IAAI,CAAA,CAAE;AACnC,IAAA,MAAME,MAAI,GAAG,MAAMC,IAAM,CAACF,IAA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BpB,SAAS,CAACsB,QAAQ,EAAE,CAAC;MACjD,IAAI;AACF,QAAA,MAAMa,SAAkB,GAAG,MAAM,OAC/B,CAAA,EAAG3B,OAAO,CAAA,CAAA,EAAIR,SAAS,CAACsB,QAAQ,CAAA,CAClC,CAAC;QACD,MAAOa,SAAS,EAA0B;OAC3C,CAAC,OAAOxB,KAAK,EAAE;QACdT,MAAM,CAACS,KAAK,CAAC,CAAA,aAAA,EAAgBX,SAAS,CAACF,OAAO,WAAW,CAAC;AAC1D,QAAA,MAAMa,KAAK;AACb;MAEAT,MAAM,CAACkC,OAAO,CAAC,CAAA,aAAA,EAAgBpC,SAAS,CAACsB,QAAQ,SAAS,CAAC;;AAE3D;MACA,IAAIM,MAAM,CAACC,GAAG,CAAC7B,SAAS,CAACF,OAAO,EAAEkB,cAAc,CAAC,EAAE;AACjD,QAAA,MAAMV,iBAAiB,CAACP,gBAAgB,CAACC,SAAS,CAAC;AACrD;AACF;GACD,CAAC,OAAOW,KAAU,EAAE;AACnBT,IAAAA,MAAM,CAACS,KAAK,CAACA,KAAc,CAAC;AAC5BE,IAAAA,OAAO,CAACC,IAAI,CAAC,CAAC,CAAC;AACjB;AAEAD,EAAAA,OAAO,CAACwB,cAAc,CAAC,oBAAoB,EAAE5B,yBAAyB,CAAC;AACzE;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alp-migrations",
3
- "version": "9.0.0",
3
+ "version": "10.0.0",
4
4
  "description": "migrations scripts in alp",
5
5
  "keywords": [],
6
6
  "author": "Christophe Hurpeau <christophe@hurpeau.com> (https://christophe.hurpeau.com)",
@@ -13,17 +13,17 @@
13
13
  "homepage": "https://github.com/christophehurpeau/alp",
14
14
  "type": "module",
15
15
  "engines": {
16
- "node": ">=18.12.0"
16
+ "node": ">=20.11.0"
17
17
  },
18
18
  "sideEffects": false,
19
- "main": "./dist/index-node18.mjs",
19
+ "main": "./dist/index-node20.mjs",
20
20
  "types": "./dist/definitions/index.d.ts",
21
21
  "exports": {
22
22
  "./package.json": "./package.json",
23
23
  ".": {
24
24
  "types": "./dist/definitions/index.d.ts",
25
25
  "node": {
26
- "import": "./dist/index-node18.mjs"
26
+ "import": "./dist/index-node20.mjs"
27
27
  }
28
28
  }
29
29
  },
@@ -37,37 +37,38 @@
37
37
  "clean": "yarn clean:build",
38
38
  "clean:build": "pob-babel-clean-out dist",
39
39
  "lint": "yarn run lint:eslint",
40
- "lint:eslint": "yarn ../.. run eslint --report-unused-disable-directives --resolve-plugins-relative-to . --quiet packages/alp-migrations",
40
+ "lint:eslint": "yarn ../.. run eslint --quiet packages/alp-migrations",
41
41
  "watch": "yarn clean:build && rollup --config rollup.config.mjs --watch"
42
42
  },
43
43
  "pob": {
44
- "babelEnvs": [
44
+ "bundler": "rollup-babel",
45
+ "entries": [
46
+ "index"
47
+ ],
48
+ "envs": [
45
49
  {
46
50
  "target": "node",
47
- "version": "18"
51
+ "version": "20"
48
52
  }
49
- ],
50
- "entries": [
51
- "index"
52
53
  ]
53
54
  },
54
55
  "prettier": "@pob/root/prettier-config",
55
56
  "peerDependencies": {
56
- "liwi-mongo": "^11.0.0",
57
- "router-segments": "^9.1.0"
57
+ "liwi-mongo": "^12.0.0",
58
+ "router-segments": "^11.0.0"
58
59
  },
59
60
  "dependencies": {
60
- "alp-node": "7.0.0",
61
+ "alp-node": "8.0.0",
61
62
  "nightingale-logger": "^15.0.0",
62
63
  "semver": "^7.3.5"
63
64
  },
64
65
  "devDependencies": {
65
- "@babel/core": "7.23.7",
66
- "@types/node": "20.10.6",
67
- "@types/semver": "7.5.6",
68
- "liwi-mongo": "11.0.0",
69
- "pob-babel": "38.0.2",
70
- "router-segments": "9.1.0",
71
- "typescript": "5.3.3"
66
+ "@babel/core": "7.28.0",
67
+ "@types/node": "20.19.9",
68
+ "@types/semver": "7.7.0",
69
+ "liwi-mongo": "12.0.0",
70
+ "pob-babel": "43.7.0",
71
+ "router-segments": "11.0.0",
72
+ "typescript": "5.8.3"
72
73
  }
73
74
  }
package/src/Manager.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { MongoStore, MongoInsertType, MongoBaseModel } from 'liwi-mongo';
1
+ import type { MongoBaseModel, MongoInsertType, MongoStore } from "liwi-mongo";
2
2
 
3
3
  export interface Migration extends MongoBaseModel {
4
4
  version: string;
package/src/index.ts CHANGED
@@ -1,19 +1,19 @@
1
1
  /* eslint-disable unicorn/no-process-exit */
2
- import type AlpNodeApp from 'alp-node';
3
- import { Logger } from 'nightingale-logger';
4
- import semver from 'semver';
5
- import type MigrationsManager from './Manager';
6
- import type { CallbackParam } from './readRecursiveDirectory';
7
- import readRecursiveDirectory from './readRecursiveDirectory';
2
+ import type AlpNodeApp from "alp-node";
3
+ import { Logger } from "nightingale-logger";
4
+ import semver from "semver";
5
+ import type MigrationsManager from "./Manager";
6
+ import type { CallbackParam } from "./readRecursiveDirectory";
7
+ import readRecursiveDirectory from "./readRecursiveDirectory";
8
8
 
9
- const logger = new Logger('alp:migrations');
9
+ const logger = new Logger("alp:migrations");
10
10
 
11
- export { default as MigrationsManager } from './Manager';
11
+ export { default as MigrationsManager } from "./Manager";
12
12
 
13
13
  export interface Options {
14
14
  app: AlpNodeApp;
15
15
  migrationsManager: MigrationsManager;
16
- config?: AlpNodeApp['config'];
16
+ config?: AlpNodeApp["config"];
17
17
  dirname?: string;
18
18
  }
19
19
 
@@ -24,26 +24,27 @@ export default async function migrate({
24
24
  dirname = `${app.dirname}/migrations`,
25
25
  }: Options): Promise<void> {
26
26
  const unhandledRejectionHandler = (reason: unknown): void => {
27
- logger.error('unhandledRejection', { err: reason });
27
+ logger.error("unhandledRejection", { err: reason });
28
+
28
29
  process.exit(1);
29
30
  };
30
- process.on('unhandledRejection', unhandledRejectionHandler);
31
+ process.on("unhandledRejection", unhandledRejectionHandler);
31
32
 
32
33
  const packageVersion = config.packageConfig.version as string;
33
34
  const currentVersion = await migrationsManager.findLastVersion();
34
35
 
35
36
  let migrations: { version: string; fileName: string }[] = [];
36
37
 
37
- logger.info('migrate', { packageVersion, currentVersion });
38
+ logger.info("migrate", { packageVersion, currentVersion });
38
39
 
39
40
  await readRecursiveDirectory(dirname, (res: CallbackParam) => {
40
41
  const fileName = res.path.slice(dirname.length + 1);
41
42
 
42
- if (!fileName.endsWith('.js')) {
43
+ if (!fileName.endsWith(".js")) {
43
44
  return;
44
45
  }
45
46
 
46
- const versionExecResult = /([\d.]+)(_.*|\.js)$/.exec(fileName);
47
+ const versionExecResult = /([\d.]+)(?:_.*|\.js)$/.exec(fileName);
47
48
 
48
49
  if (!versionExecResult?.[1]) {
49
50
  return;
@@ -85,5 +86,5 @@ export default async function migrate({
85
86
  process.exit(1);
86
87
  }
87
88
 
88
- process.removeListener('unhandledRejection', unhandledRejectionHandler);
89
+ process.removeListener("unhandledRejection", unhandledRejectionHandler);
89
90
  }
@@ -1,5 +1,5 @@
1
- import type { Stats } from 'node:fs';
2
- import { readdir, stat as fsStat } from 'node:fs/promises';
1
+ import type { Stats } from "node:fs";
2
+ import { stat as fsStat, readdir } from "node:fs/promises";
3
3
 
4
4
  export interface CallbackParam {
5
5
  filename: string;
@@ -19,7 +19,7 @@ export default async function readRecursiveDirectory(
19
19
  const path = `${directory}/${file}`;
20
20
  const stat = await fsStat(path);
21
21
 
22
- if (stat?.isDirectory()) {
22
+ if (stat.isDirectory()) {
23
23
  await readRecursiveDirectory(path, callback);
24
24
  return;
25
25
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-node18.mjs","sources":["../src/readRecursiveDirectory.ts","../src/Manager.ts","../src/index.ts"],"sourcesContent":["import type { Stats } from 'node:fs';\nimport { readdir, stat as fsStat } from 'node:fs/promises';\n\nexport interface CallbackParam {\n filename: string;\n basedir: string;\n path: string;\n stat: Stats;\n}\n\nexport default async function readRecursiveDirectory(\n directory: string,\n callback: (param: CallbackParam) => Promise<void> | void,\n): Promise<void> {\n const files = await readdir(directory);\n\n await Promise.all(\n files.map(async (file): Promise<void> => {\n const path = `${directory}/${file}`;\n const stat = await fsStat(path);\n\n if (stat?.isDirectory()) {\n await readRecursiveDirectory(path, callback);\n return;\n }\n await callback({\n filename: file,\n basedir: directory,\n path,\n stat,\n });\n }),\n );\n}\n","import type { MongoStore, MongoInsertType, MongoBaseModel } from 'liwi-mongo';\n\nexport interface Migration extends MongoBaseModel {\n version: string;\n fileName: string;\n}\n\nexport default class MigrationsManager {\n store: MongoStore<Migration>;\n\n constructor(store: MongoStore<Migration>) {\n this.store = store;\n }\n\n findLastVersion(): Promise<string | undefined> {\n return this.store.findOne({}, { created: -1 }).then((row) => row?.version);\n }\n\n addMigrationDone(migration: MongoInsertType<Migration>): Promise<Migration> {\n return this.store.insertOne(migration);\n }\n}\n","/* eslint-disable unicorn/no-process-exit */\nimport type AlpNodeApp from 'alp-node';\nimport { Logger } from 'nightingale-logger';\nimport semver from 'semver';\nimport type MigrationsManager from './Manager';\nimport type { CallbackParam } from './readRecursiveDirectory';\nimport readRecursiveDirectory from './readRecursiveDirectory';\n\nconst logger = new Logger('alp:migrations');\n\nexport { default as MigrationsManager } from './Manager';\n\nexport interface Options {\n app: AlpNodeApp;\n migrationsManager: MigrationsManager;\n config?: AlpNodeApp['config'];\n dirname?: string;\n}\n\nexport default async function migrate({\n app,\n migrationsManager,\n config = app.config,\n dirname = `${app.dirname}/migrations`,\n}: Options): Promise<void> {\n const unhandledRejectionHandler = (reason: unknown): void => {\n logger.error('unhandledRejection', { err: reason });\n process.exit(1);\n };\n process.on('unhandledRejection', unhandledRejectionHandler);\n\n const packageVersion = config.packageConfig.version as string;\n const currentVersion = await migrationsManager.findLastVersion();\n\n let migrations: { version: string; fileName: string }[] = [];\n\n logger.info('migrate', { packageVersion, currentVersion });\n\n await readRecursiveDirectory(dirname, (res: CallbackParam) => {\n const fileName = res.path.slice(dirname.length + 1);\n\n if (!fileName.endsWith('.js')) {\n return;\n }\n\n const versionExecResult = /([\\d.]+)(_.*|\\.js)$/.exec(fileName);\n\n if (!versionExecResult?.[1]) {\n return;\n }\n\n const version: string = versionExecResult[1];\n\n if (currentVersion && semver.lte(version, currentVersion)) return;\n\n migrations.push({ version, fileName });\n });\n\n migrations = migrations.sort((a, b) =>\n semver.gt(a.version, b.version) ? 1 : -1,\n );\n\n try {\n for (const migration of migrations) {\n logger.info(`Migration to ${migration.fileName}`);\n try {\n const migrateFn: unknown = await import(\n `${dirname}/${migration.fileName}`\n );\n await (migrateFn as () => Promise<void>)();\n } catch (error) {\n logger.error(`Migration to ${migration.version} Failed !`);\n throw error;\n }\n\n logger.success(`Migration to ${migration.fileName} done !`);\n\n // only add to db if migration version <= package version\n if (semver.lte(migration.version, packageVersion)) {\n await migrationsManager.addMigrationDone(migration);\n }\n }\n } catch (error: any) {\n logger.error(error as Error);\n process.exit(1);\n }\n\n process.removeListener('unhandledRejection', unhandledRejectionHandler);\n}\n"],"names":["readRecursiveDirectory","directory","callback","files","readdir","Promise","all","map","file","path","stat","fsStat","isDirectory","filename","basedir","MigrationsManager","constructor","store","findLastVersion","findOne","created","then","row","version","addMigrationDone","migration","insertOne","logger","Logger","migrate","app","migrationsManager","config","dirname","unhandledRejectionHandler","reason","error","err","process","exit","on","packageVersion","packageConfig","currentVersion","migrations","info","res","fileName","slice","length","endsWith","versionExecResult","exec","semver","lte","push","sort","a","b","gt","migrateFn","success","removeListener"],"mappings":";;;;AAUe,eAAeA,sBAAsBA,CAClDC,SAAiB,EACjBC,QAAwD,EACzC;AACf,EAAA,MAAMC,KAAK,GAAG,MAAMC,OAAO,CAACH,SAAS,CAAC,CAAA;EAEtC,MAAMI,OAAO,CAACC,GAAG,CACfH,KAAK,CAACI,GAAG,CAAC,MAAOC,IAAI,IAAoB;AACvC,IAAA,MAAMC,IAAI,GAAI,CAAA,EAAER,SAAU,CAAA,CAAA,EAAGO,IAAK,CAAC,CAAA,CAAA;AACnC,IAAA,MAAME,MAAI,GAAG,MAAMC,IAAM,CAACF,IAAI,CAAC,CAAA;AAE/B,IAAA,IAAIC,MAAI,EAAEE,WAAW,E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OAAO,EAAEmC,CAAC,CAACnC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CACzC,CAAC,CAAA;EAED,IAAI;AACF,IAAA,KAAK,MAAME,SAAS,IAAImB,UAAU,EAAE;MAClCjB,MAAM,CAACkB,IAAI,CAAE,CAAA,aAAA,EAAepB,SAAS,CAACsB,QAAS,EAAC,CAAC,CAAA;MACjD,IAAI;AACF,QAAA,MAAMa,SAAkB,GAAG,MAAM,OAC9B,CAAA,EAAE3B,OAAQ,CAAA,CAAA,EAAGR,SAAS,CAACsB,QAAS,CAAA,CACnC,CAAC,CAAA;QACD,MAAOa,SAAS,EAA0B,CAAA;OAC3C,CAAC,OAAOxB,KAAK,EAAE;QACdT,MAAM,CAACS,KAAK,CAAE,CAAA,aAAA,EAAeX,SAAS,CAACF,OAAQ,WAAU,CAAC,CAAA;AAC1D,QAAA,MAAMa,KAAK,CAAA;AACb,OAAA;MAEAT,MAAM,CAACkC,OAAO,CAAE,CAAA,aAAA,EAAepC,SAAS,CAACsB,QAAS,SAAQ,CAAC,CAAA;;AAE3D;MACA,IAAIM,MAAM,CAACC,GAAG,CAAC7B,SAAS,CAACF,OAAO,EAAEkB,cAAc,CAAC,EAAE;AACjD,QAAA,MAAMV,iBAAiB,CAACP,gBAAgB,CAACC,SAAS,CAAC,CAAA;AACrD,OAAA;AACF,KAAA;GACD,CAAC,OAAOW,KAAU,EAAE;AACnBT,IAAAA,MAAM,CAACS,KAAK,CAACA,KAAc,CAAC,CAAA;AAC5BE,IAAAA,OAAO,CAACC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,GAAA;AAEAD,EAAAA,OAAO,CAACwB,cAAc,CAAC,oBAAoB,EAAE5B,yBAAyB,CAAC,CAAA;AACzE;;;;"}
@@ -1,31 +0,0 @@
1
- {
2
- "root": true,
3
- "parser": "@typescript-eslint/parser",
4
- "parserOptions": {
5
- "EXPERIMENTAL_useProjectService": true,
6
- "project": "packages/alp-migrations/tsconfig.json"
7
- },
8
- "plugins": ["@typescript-eslint"],
9
- "extends": [
10
- "@pob/eslint-config-typescript",
11
- "@pob/eslint-config-typescript/node"
12
- ],
13
- "ignorePatterns": ["*.d.ts"],
14
- "overrides": [
15
- {
16
- "files": ["**/*.test.ts", "__tests__/**/*.ts"],
17
- "extends": ["@pob/eslint-config-typescript/test"],
18
- "env": {
19
- "jest": true
20
- },
21
- "rules": {
22
- "import/no-extraneous-dependencies": [
23
- "error",
24
- {
25
- "devDependencies": true
26
- }
27
- ]
28
- }
29
- }
30
- ]
31
- }