outlet-orm 6.5.0 → 7.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/bin/init.js +122 -0
- package/bin/mcp.js +78 -0
- package/bin/migrate.js +25 -0
- package/docs/skills/outlet-orm/ADVANCED.md +575 -0
- package/docs/skills/outlet-orm/AI.md +220 -0
- package/docs/skills/outlet-orm/API.md +522 -0
- package/docs/skills/outlet-orm/BACKUP.md +150 -0
- package/docs/skills/outlet-orm/MIGRATIONS.md +605 -0
- package/docs/skills/outlet-orm/MODELS.md +427 -0
- package/docs/skills/outlet-orm/QUERIES.md +345 -0
- package/docs/skills/outlet-orm/RELATIONS.md +555 -0
- package/docs/skills/outlet-orm/SECURITY.md +386 -0
- package/docs/skills/outlet-orm/SEEDS.md +98 -0
- package/docs/skills/outlet-orm/SKILL.md +205 -0
- package/docs/skills/outlet-orm/TYPESCRIPT.md +480 -0
- package/package.json +7 -3
- package/src/AI/AISafetyGuardrails.js +146 -0
- package/src/AI/MCPServer.js +685 -0
- package/src/AI/PromptGenerator.js +318 -0
- package/src/index.js +11 -1
- package/types/index.d.ts +106 -0
package/bin/init.js
CHANGED
|
@@ -16,7 +16,129 @@ const rl = readline.createInterface({
|
|
|
16
16
|
|
|
17
17
|
const question = (query) => new Promise((resolve) => rl.question(query, resolve));
|
|
18
18
|
|
|
19
|
+
// ─── Parse CLI flags ─────────────────────────────────────────────
|
|
20
|
+
|
|
21
|
+
function parseInitFlags(argv) {
|
|
22
|
+
const flags = {};
|
|
23
|
+
for (let i = 0; i < argv.length; i++) {
|
|
24
|
+
const arg = argv[i];
|
|
25
|
+
if (arg === '--prompt' || arg === '-P') {
|
|
26
|
+
flags.prompt = argv[++i];
|
|
27
|
+
} else if (arg === '--driver' || arg === '-d') {
|
|
28
|
+
flags.driver = argv[++i];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return flags;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ─── Prompt-based init (v7.0.0) ─────────────────────────────────
|
|
35
|
+
|
|
36
|
+
async function initFromPrompt(promptText, driverName) {
|
|
37
|
+
const PromptGenerator = require('../src/AI/PromptGenerator');
|
|
38
|
+
|
|
39
|
+
console.log('\n🤖 Outlet ORM — Prompt-based Initialization\n');
|
|
40
|
+
console.log(` Prompt: "${promptText}"`);
|
|
41
|
+
|
|
42
|
+
const blueprint = PromptGenerator.parse(promptText);
|
|
43
|
+
console.log(` Domain detected: ${blueprint.domain} (score: ${blueprint.score})`);
|
|
44
|
+
console.log(` Tables: ${Object.keys(blueprint.tables).join(', ')}\n`);
|
|
45
|
+
|
|
46
|
+
// Determine the driver
|
|
47
|
+
const driver = driverName || 'sqlite';
|
|
48
|
+
const driverConfig = {
|
|
49
|
+
mysql: { package: 'mysql2', port: 3306 },
|
|
50
|
+
postgres: { package: 'pg', port: 5432 },
|
|
51
|
+
sqlite: { package: 'sqlite3', port: null }
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
if (!driverConfig[driver]) {
|
|
55
|
+
console.error(`❌ Unknown driver: ${driver}. Use mysql, postgres, or sqlite.`);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const cwd = process.cwd();
|
|
60
|
+
|
|
61
|
+
// Create directory structure
|
|
62
|
+
const directories = ['database/migrations', 'database/seeds', 'models', 'config'];
|
|
63
|
+
for (const dir of directories) {
|
|
64
|
+
const dirPath = path.join(cwd, dir);
|
|
65
|
+
if (!fs.existsSync(dirPath)) {
|
|
66
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
67
|
+
console.log(` 📁 ${dir}/`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Generate database config
|
|
72
|
+
let config;
|
|
73
|
+
if (driver === 'sqlite') {
|
|
74
|
+
config = { driver: 'sqlite', database: './database.sqlite' };
|
|
75
|
+
} else {
|
|
76
|
+
config = {
|
|
77
|
+
driver,
|
|
78
|
+
host: 'localhost',
|
|
79
|
+
port: driverConfig[driver].port,
|
|
80
|
+
database: 'my_app',
|
|
81
|
+
user: 'root',
|
|
82
|
+
password: ''
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const configContent = `const { DatabaseConnection } = require('outlet-orm');\n\nconst db = new DatabaseConnection(${JSON.stringify(config, null, 2)});\n\nmodule.exports = db;\n`;
|
|
87
|
+
const configPath = path.join(cwd, 'database', 'config.js');
|
|
88
|
+
if (!fs.existsSync(configPath)) {
|
|
89
|
+
fs.writeFileSync(configPath, configContent);
|
|
90
|
+
console.log(' ✅ database/config.js');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Generate .env
|
|
94
|
+
const envPath = path.join(cwd, '.env');
|
|
95
|
+
if (!fs.existsSync(envPath)) {
|
|
96
|
+
const envLines = [`DB_DRIVER=${config.driver}`];
|
|
97
|
+
if (driver !== 'sqlite') {
|
|
98
|
+
envLines.push(`DB_HOST=${config.host}`, `DB_PORT=${config.port}`, `DB_USER=${config.user}`, `DB_PASSWORD=${config.password}`, `DB_DATABASE=${config.database}`);
|
|
99
|
+
} else {
|
|
100
|
+
envLines.push(`DB_FILE=${config.database}`);
|
|
101
|
+
}
|
|
102
|
+
fs.writeFileSync(envPath, envLines.join('\n') + '\n');
|
|
103
|
+
console.log(' ✅ .env');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Generate models
|
|
107
|
+
console.log('\n📊 Generating models...');
|
|
108
|
+
const modelFiles = PromptGenerator.generateModels(blueprint, path.join(cwd, 'models'));
|
|
109
|
+
for (const f of modelFiles) {
|
|
110
|
+
console.log(` ✅ ${path.relative(cwd, f)}`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Generate migrations
|
|
114
|
+
console.log('\n📦 Generating migrations...');
|
|
115
|
+
const migrationFiles = PromptGenerator.generateMigrations(blueprint, path.join(cwd, 'database', 'migrations'));
|
|
116
|
+
for (const f of migrationFiles) {
|
|
117
|
+
console.log(` ✅ ${path.relative(cwd, f)}`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Generate seeder
|
|
121
|
+
console.log('\n🌱 Generating seeder...');
|
|
122
|
+
const seederFile = PromptGenerator.generateSeeder(blueprint, path.join(cwd, 'database', 'seeds'));
|
|
123
|
+
console.log(` ✅ ${path.relative(cwd, seederFile)}`);
|
|
124
|
+
|
|
125
|
+
console.log('\n✨ Project generated from prompt!\n');
|
|
126
|
+
console.log('Next steps:');
|
|
127
|
+
console.log(' 1. Review generated models in models/');
|
|
128
|
+
console.log(' 2. Review migrations in database/migrations/');
|
|
129
|
+
console.log(' 3. Run migrations: outlet-migrate migrate');
|
|
130
|
+
console.log(` 4. Install driver: npm install ${driverConfig[driver].package}`);
|
|
131
|
+
}
|
|
132
|
+
|
|
19
133
|
async function init() {
|
|
134
|
+
// Check for --prompt flag
|
|
135
|
+
const flags = parseInitFlags(process.argv.slice(2));
|
|
136
|
+
if (flags.prompt) {
|
|
137
|
+
await initFromPrompt(flags.prompt, flags.driver);
|
|
138
|
+
rl.close();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
20
142
|
console.log('\n🚀 Bienvenue dans l\'assistant de configuration Outlet ORM!\n');
|
|
21
143
|
|
|
22
144
|
try {
|
package/bin/mcp.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* outlet-mcp — MCP Server CLI entry point
|
|
5
|
+
* Starts the Outlet ORM MCP server on stdio for AI agent integration.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* npx outlet-mcp # Start the MCP server
|
|
9
|
+
* npx outlet-mcp --project /path # Start with custom project directory
|
|
10
|
+
* npx outlet-mcp --no-safety # Disable AI safety guardrails
|
|
11
|
+
*
|
|
12
|
+
* @since 7.0.0
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const MCPServer = require('../src/AI/MCPServer');
|
|
16
|
+
|
|
17
|
+
// ─── Parse CLI flags ─────────────────────────────────────────────
|
|
18
|
+
|
|
19
|
+
const args = process.argv.slice(2);
|
|
20
|
+
const options = {};
|
|
21
|
+
|
|
22
|
+
for (let i = 0; i < args.length; i++) {
|
|
23
|
+
const arg = args[i];
|
|
24
|
+
if (arg === '--project' || arg === '-p') {
|
|
25
|
+
options.projectDir = args[++i];
|
|
26
|
+
} else if (arg === '--no-safety') {
|
|
27
|
+
options.safetyGuardrails = false;
|
|
28
|
+
} else if (arg === '--help' || arg === '-h') {
|
|
29
|
+
console.error(`
|
|
30
|
+
outlet-mcp — Outlet ORM MCP Server
|
|
31
|
+
|
|
32
|
+
Usage:
|
|
33
|
+
outlet-mcp [options]
|
|
34
|
+
|
|
35
|
+
Options:
|
|
36
|
+
--project, -p <path> Project root directory (default: cwd)
|
|
37
|
+
--no-safety Disable AI safety guardrails
|
|
38
|
+
--help, -h Show this help message
|
|
39
|
+
|
|
40
|
+
The server communicates over stdio using the Model Context Protocol (MCP).
|
|
41
|
+
It exposes tools for migrations, schema introspection, queries, seeds, and backups.
|
|
42
|
+
|
|
43
|
+
Documentation: https://github.com/omgbwa-yasse/outlet-orm/blob/main/docs/MCP.md
|
|
44
|
+
`);
|
|
45
|
+
process.exit(0);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// ─── Start ───────────────────────────────────────────────────────
|
|
50
|
+
|
|
51
|
+
const server = new MCPServer(options);
|
|
52
|
+
|
|
53
|
+
server.on('started', () => {
|
|
54
|
+
process.stderr.write('[outlet-mcp] MCP server started on stdio\n');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
server.on('initialized', () => {
|
|
58
|
+
process.stderr.write('[outlet-mcp] Client connected and initialized\n');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
server.on('close', async () => {
|
|
62
|
+
process.stderr.write('[outlet-mcp] Shutting down...\n');
|
|
63
|
+
await server.close();
|
|
64
|
+
process.exit(0);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Graceful shutdown
|
|
68
|
+
process.on('SIGINT', async () => {
|
|
69
|
+
await server.close();
|
|
70
|
+
process.exit(0);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
process.on('SIGTERM', async () => {
|
|
74
|
+
await server.close();
|
|
75
|
+
process.exit(0);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
server.start();
|
package/bin/migrate.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
const readline = require('readline');
|
|
9
9
|
const fs = require('fs').promises;
|
|
10
10
|
const path = require('path');
|
|
11
|
+
const AISafetyGuardrails = require('../src/AI/AISafetyGuardrails');
|
|
11
12
|
|
|
12
13
|
const rl = readline.createInterface({
|
|
13
14
|
input: process.stdin,
|
|
@@ -367,6 +368,14 @@ async function runNonInteractive(cmd, flags) {
|
|
|
367
368
|
}
|
|
368
369
|
|
|
369
370
|
case 'reset': {
|
|
371
|
+
// AI Safety Guardrails check (v7.0.0)
|
|
372
|
+
if (AISafetyGuardrails.isDestructiveCommand('reset')) {
|
|
373
|
+
const check = AISafetyGuardrails.validateDestructiveAction('reset', flags);
|
|
374
|
+
if (!check.allowed) {
|
|
375
|
+
console.error(check.message);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
370
379
|
if (flags.yes || flags.force) {
|
|
371
380
|
await manager.reset();
|
|
372
381
|
} else {
|
|
@@ -376,6 +385,14 @@ async function runNonInteractive(cmd, flags) {
|
|
|
376
385
|
}
|
|
377
386
|
|
|
378
387
|
case 'refresh': {
|
|
388
|
+
// AI Safety Guardrails check (v7.0.0)
|
|
389
|
+
if (AISafetyGuardrails.isDestructiveCommand('fresh')) {
|
|
390
|
+
const check = AISafetyGuardrails.validateDestructiveAction('refresh', flags);
|
|
391
|
+
if (!check.allowed) {
|
|
392
|
+
console.error(check.message);
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
379
396
|
if (flags.yes || flags.force) {
|
|
380
397
|
await manager.refresh();
|
|
381
398
|
} else {
|
|
@@ -385,6 +402,14 @@ async function runNonInteractive(cmd, flags) {
|
|
|
385
402
|
}
|
|
386
403
|
|
|
387
404
|
case 'fresh': {
|
|
405
|
+
// AI Safety Guardrails check (v7.0.0)
|
|
406
|
+
if (AISafetyGuardrails.isDestructiveCommand('fresh')) {
|
|
407
|
+
const check = AISafetyGuardrails.validateDestructiveAction('fresh', flags);
|
|
408
|
+
if (!check.allowed) {
|
|
409
|
+
console.error(check.message);
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
388
413
|
if (flags.yes || flags.force) {
|
|
389
414
|
await manager.fresh();
|
|
390
415
|
} else {
|