@abejarano/ts-mongodb-criteria 1.7.0 → 1.8.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/README.md +25 -5
- package/dist/cjs/bin/cli.js +38 -0
- package/dist/esm/bin/cli.js +36 -0
- package/dist/types/bin/cli.d.ts +2 -0
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -227,15 +227,35 @@ const results = await repository.list(activeAdultUsers)
|
|
|
227
227
|
|
|
228
228
|
## 🗄️ Migrations
|
|
229
229
|
|
|
230
|
-
This repo includes a `migrate-mongo
|
|
231
|
-
|
|
232
|
-
|
|
230
|
+
This repo includes a CLI wrapper for `migrate-mongo`.
|
|
231
|
+
To use it in your application:
|
|
232
|
+
|
|
233
|
+
1. Initialize the configuration:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
bun ts-mongo init
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
2. Edit `migrate-mongo-config.js` with your database details.
|
|
240
|
+
|
|
241
|
+
3. Run migrations using the `ts-mongo` command:
|
|
233
242
|
|
|
234
243
|
```bash
|
|
235
|
-
|
|
236
|
-
bun
|
|
244
|
+
# Create a new migration
|
|
245
|
+
bun ts-mongo migrate:create add-users-index
|
|
246
|
+
|
|
247
|
+
# Run migrations up
|
|
248
|
+
bun ts-mongo migrate:up
|
|
249
|
+
|
|
250
|
+
# Undo last migration
|
|
251
|
+
bun ts-mongo migrate:down
|
|
252
|
+
|
|
253
|
+
# Check status
|
|
254
|
+
bun ts-mongo migrate:status
|
|
237
255
|
```
|
|
238
256
|
|
|
257
|
+
Note: You can also use `npx`, `bunx` or `yarn run`.
|
|
258
|
+
|
|
239
259
|
See the full CLI guide here: `docs/mongo-migrations.md`.
|
|
240
260
|
|
|
241
261
|
## 📖 Documentation
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const args = process.argv.slice(2);
|
|
6
|
+
const command = args[0];
|
|
7
|
+
const otherArgs = args.slice(1).join(" ");
|
|
8
|
+
if (!command) {
|
|
9
|
+
console.error("Please provide a command: migrate:create, migrate:up, migrate:down, migrate:status");
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
// Map short commands to full migrate-mongo commands if desired,
|
|
13
|
+
// or just pass them through if they match.
|
|
14
|
+
// The user asked for `bun run migrate:create`, so we want to support `ts-mongo migrate:create`
|
|
15
|
+
// essentially proxying.
|
|
16
|
+
// Actually, migrate-mongo CLI expects: `migrate-mongo <command> [options]`
|
|
17
|
+
// commands: init, up, down, status, create
|
|
18
|
+
// If user maps `ts-mongo migrate:create <name>`, we should map it to `migrate-mongo create <name>`
|
|
19
|
+
const validCommands = ["init", "create", "up", "down", "status"];
|
|
20
|
+
// Handle "migrate:create" style input from the user request
|
|
21
|
+
const normalizedCommand = command.replace("migrate:", "");
|
|
22
|
+
if (!validCommands.includes(normalizedCommand)) {
|
|
23
|
+
console.error(`Unknown command: ${command}.`);
|
|
24
|
+
console.error(`Available commands: ${validCommands.map(c => `migrate:${c}`).join(", ")}`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
// Execute migrate-mongo from the dependency
|
|
29
|
+
// Using `bunx` or `npx` might be safer to find the binary, or resolve it directly.
|
|
30
|
+
// Since it is a dependency, it should be in node_modules/.bin/migrate-mongo
|
|
31
|
+
const binPath = "./node_modules/.bin/migrate-mongo";
|
|
32
|
+
const finalCommand = `${binPath} ${normalizedCommand} ${otherArgs}`;
|
|
33
|
+
console.log(`Running: ${finalCommand}`);
|
|
34
|
+
(0, child_process_1.execSync)(finalCommand, { stdio: "inherit" });
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { execSync } from "child_process";
|
|
3
|
+
const args = process.argv.slice(2);
|
|
4
|
+
const command = args[0];
|
|
5
|
+
const otherArgs = args.slice(1).join(" ");
|
|
6
|
+
if (!command) {
|
|
7
|
+
console.error("Please provide a command: migrate:create, migrate:up, migrate:down, migrate:status");
|
|
8
|
+
process.exit(1);
|
|
9
|
+
}
|
|
10
|
+
// Map short commands to full migrate-mongo commands if desired,
|
|
11
|
+
// or just pass them through if they match.
|
|
12
|
+
// The user asked for `bun run migrate:create`, so we want to support `ts-mongo migrate:create`
|
|
13
|
+
// essentially proxying.
|
|
14
|
+
// Actually, migrate-mongo CLI expects: `migrate-mongo <command> [options]`
|
|
15
|
+
// commands: init, up, down, status, create
|
|
16
|
+
// If user maps `ts-mongo migrate:create <name>`, we should map it to `migrate-mongo create <name>`
|
|
17
|
+
const validCommands = ["init", "create", "up", "down", "status"];
|
|
18
|
+
// Handle "migrate:create" style input from the user request
|
|
19
|
+
const normalizedCommand = command.replace("migrate:", "");
|
|
20
|
+
if (!validCommands.includes(normalizedCommand)) {
|
|
21
|
+
console.error(`Unknown command: ${command}.`);
|
|
22
|
+
console.error(`Available commands: ${validCommands.map(c => `migrate:${c}`).join(", ")}`);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
// Execute migrate-mongo from the dependency
|
|
27
|
+
// Using `bunx` or `npx` might be safer to find the binary, or resolve it directly.
|
|
28
|
+
// Since it is a dependency, it should be in node_modules/.bin/migrate-mongo
|
|
29
|
+
const binPath = "./node_modules/.bin/migrate-mongo";
|
|
30
|
+
const finalCommand = `${binPath} ${normalizedCommand} ${otherArgs}`;
|
|
31
|
+
console.log(`Running: ${finalCommand}`);
|
|
32
|
+
execSync(finalCommand, { stdio: "inherit" });
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abejarano/ts-mongodb-criteria",
|
|
3
3
|
"author": "angel bejarano / angel.bejarano@jaspesoft.com",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.8.0",
|
|
5
5
|
"description": "Patrón Criteria para consultas MongoDB en TypeScript",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
7
7
|
"module": "dist/esm/index.js",
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
},
|
|
15
15
|
"./package.json": "./package.json"
|
|
16
16
|
},
|
|
17
|
+
"bin": {
|
|
18
|
+
"ts-mongo": "./dist/cjs/bin/cli.js"
|
|
19
|
+
},
|
|
17
20
|
"files": [
|
|
18
21
|
"dist"
|
|
19
22
|
],
|
|
@@ -48,6 +51,9 @@
|
|
|
48
51
|
"typescript"
|
|
49
52
|
],
|
|
50
53
|
"license": "MIT",
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"migrate-mongo": "14.0.7"
|
|
56
|
+
},
|
|
51
57
|
"devDependencies": {
|
|
52
58
|
"@semantic-release/changelog": "^6.0.3",
|
|
53
59
|
"@semantic-release/git": "^10.0.1",
|
|
@@ -55,7 +61,6 @@
|
|
|
55
61
|
"@types/mongodb": "^4.0.7",
|
|
56
62
|
"@types/node": "^24.5.2",
|
|
57
63
|
"jest": "^29.7.0",
|
|
58
|
-
"migrate-mongo": "14.0.7",
|
|
59
64
|
"mongodb": "^7.0.0",
|
|
60
65
|
"prettier": "^3.7.4",
|
|
61
66
|
"rimraf": "^6.1.2",
|