dbcube 1.1.10 → 1.1.12
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/package.json +4 -4
- package/src/index.ts +4 -0
- package/{dist/index.d.ts → src/lib/Dbcube.ts} +146 -112
- package/src/lib/FileUtils.ts +79 -0
- package/tsconfig.json +16 -0
- package/tsup.config.ts +14 -0
- package/.npmignore +0 -53
- package/dist/index.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbcube",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.12",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -54,15 +54,15 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@dbcube/core": "^1.0.
|
|
58
|
-
"@dbcube/query-builder": "^1.0.
|
|
57
|
+
"@dbcube/core": "^1.0.9",
|
|
58
|
+
"@dbcube/query-builder": "^1.0.8"
|
|
59
59
|
},
|
|
60
60
|
"repository": {
|
|
61
61
|
"type": "git",
|
|
62
62
|
"url": "git+https://github.com/Dbcube/query-builder"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@types/node": "^24.3.
|
|
65
|
+
"@types/node": "^24.3.1",
|
|
66
66
|
"alwait": "^1.0.0",
|
|
67
67
|
"chalk": "^5.6.0",
|
|
68
68
|
"dotenv": "^17.2.2",
|
package/src/index.ts
ADDED
|
@@ -1,112 +1,146 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
*
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* @
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
1
|
+
import { Config } from '@dbcube/core';
|
|
2
|
+
import { Database } from '@dbcube/query-builder';
|
|
3
|
+
import FileUtils from './FileUtils';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* DBCube ORM - Main class for database management
|
|
8
|
+
*
|
|
9
|
+
* A lightweight, flexible ORM that supports multiple database engines including
|
|
10
|
+
* MySQL, PostgreSQL, SQLite, and MongoDB with a fluent query builder interface.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { Dbcube } from 'dbcube';
|
|
15
|
+
*
|
|
16
|
+
* const dbcube = new Dbcube();
|
|
17
|
+
* await dbcube.init();
|
|
18
|
+
*
|
|
19
|
+
* // Get a database connection
|
|
20
|
+
* const db = dbcube.database('myDatabase');
|
|
21
|
+
*
|
|
22
|
+
* // Use query builder
|
|
23
|
+
* const users = await db.table('users').select().where('active', true).get();
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @class
|
|
27
|
+
* @author Albert Araya
|
|
28
|
+
* @license MIT
|
|
29
|
+
*/
|
|
30
|
+
export class Dbcube {
|
|
31
|
+
private static instance: Dbcube;
|
|
32
|
+
private configPath!: string;
|
|
33
|
+
private config: any;
|
|
34
|
+
private databases!: Record<string, any>;
|
|
35
|
+
private initialized!: boolean;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new Dbcube instance (Singleton pattern)
|
|
39
|
+
*
|
|
40
|
+
* @constructor
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const dbcube = new Dbcube();
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
constructor() {
|
|
47
|
+
if (Dbcube.instance) {
|
|
48
|
+
return Dbcube.instance;
|
|
49
|
+
}
|
|
50
|
+
this.configPath = path.join(process.cwd(), 'dbcube.config.js');
|
|
51
|
+
this.config = new Config();
|
|
52
|
+
this.databases = {};
|
|
53
|
+
this.initialized = false;
|
|
54
|
+
|
|
55
|
+
Dbcube.instance = this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Loads configuration from dbcube.config.js file
|
|
60
|
+
*
|
|
61
|
+
* @private
|
|
62
|
+
* @returns {Promise<void>}
|
|
63
|
+
* @throws {Error} If config file doesn't exist
|
|
64
|
+
*/
|
|
65
|
+
async loadConfig() {
|
|
66
|
+
const exists = await FileUtils.fileExists(this.configPath);
|
|
67
|
+
exists ?? console.log('❌ Dont exists config file, please create a dbcube.config.js file');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Initializes the Dbcube ORM with database configurations
|
|
72
|
+
*
|
|
73
|
+
* @param {Object} configCreate - Optional configuration for creating new database
|
|
74
|
+
* @param {string} [configCreate.databaseName] - Name of the database to create
|
|
75
|
+
* @param {string} [configCreate.motor] - Database engine (mysql, postgres, sqlite, mongodb)
|
|
76
|
+
* @param {any} [configCreate.configAnswers] - Additional configuration answers
|
|
77
|
+
* @returns {Promise<void>}
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* // Initialize with existing config
|
|
82
|
+
* await dbcube.init();
|
|
83
|
+
*
|
|
84
|
+
* // Initialize with new database creation
|
|
85
|
+
* await dbcube.init({
|
|
86
|
+
* databaseName: 'myapp',
|
|
87
|
+
* motor: 'mysql'
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
async init(configCreate: { databaseName?: string; motor?: string; configAnswers?: any } = {}) {
|
|
92
|
+
if (this.initialized) return;
|
|
93
|
+
await this.loadConfig();
|
|
94
|
+
const config = require(this.configPath);
|
|
95
|
+
|
|
96
|
+
config(this.config);
|
|
97
|
+
const databases = Object.keys(this.config.getAllDatabases());
|
|
98
|
+
|
|
99
|
+
for (const database of databases) {
|
|
100
|
+
this.databases[database] = new Database(database);
|
|
101
|
+
}
|
|
102
|
+
if(configCreate.databaseName){
|
|
103
|
+
this.databases[configCreate.databaseName] = new Database(configCreate.databaseName);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Gets a database connection instance for query building
|
|
109
|
+
*
|
|
110
|
+
* @param {string} databaseName - Name of the database configuration
|
|
111
|
+
* @returns {Database} Database instance with query builder capabilities
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* // Get database connection
|
|
116
|
+
* const db = dbcube.database('myapp');
|
|
117
|
+
*
|
|
118
|
+
* // Use query builder methods
|
|
119
|
+
* const users = await db.table('users')
|
|
120
|
+
* .select(['id', 'name', 'email'])
|
|
121
|
+
* .where('status', 'active')
|
|
122
|
+
* .orderBy('created_at', 'desc')
|
|
123
|
+
* .limit(10)
|
|
124
|
+
* .get();
|
|
125
|
+
*
|
|
126
|
+
* // Insert data
|
|
127
|
+
* await db.table('users').insert({
|
|
128
|
+
* name: 'John Doe',
|
|
129
|
+
* email: 'john@example.com'
|
|
130
|
+
* });
|
|
131
|
+
*
|
|
132
|
+
* // Update data
|
|
133
|
+
* await db.table('users')
|
|
134
|
+
* .where('id', 1)
|
|
135
|
+
* .update({ status: 'inactive' });
|
|
136
|
+
*
|
|
137
|
+
* // Delete data
|
|
138
|
+
* await db.table('users').where('id', 1).delete();
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
database(databaseName: string){
|
|
142
|
+
return this.databases[databaseName];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export default Dbcube;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
4
|
+
export class FileUtils {
|
|
5
|
+
/**
|
|
6
|
+
* Verifica si un archivo existe (asincrónico).
|
|
7
|
+
* @param filePath - Ruta del archivo.
|
|
8
|
+
* @returns Promise que resuelve true si el archivo existe, false si no.
|
|
9
|
+
*/
|
|
10
|
+
static async fileExists(filePath: string): Promise<boolean> {
|
|
11
|
+
return new Promise<boolean>((resolve) => {
|
|
12
|
+
fs.access(path.resolve(filePath), fs.constants.F_OK, (err) => {
|
|
13
|
+
resolve(!err);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Verifica si un archivo existe (sincrónico).
|
|
20
|
+
* @param filePath - Ruta del archivo.
|
|
21
|
+
* @returns True si el archivo existe, false si no.
|
|
22
|
+
*/
|
|
23
|
+
static fileExistsSync(filePath: string): boolean {
|
|
24
|
+
try {
|
|
25
|
+
fs.accessSync(path.resolve(filePath), fs.constants.F_OK);
|
|
26
|
+
return true;
|
|
27
|
+
} catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Extrae el nombre de la base de datos de un string con formato @database().
|
|
34
|
+
* @param input - String de entrada que contiene la referencia a la base de datos.
|
|
35
|
+
* @returns El nombre de la base de datos o null si no se encuentra.
|
|
36
|
+
*/
|
|
37
|
+
static extractDatabaseName(input: string): string | null {
|
|
38
|
+
const match = input.match(/@database\(["']?([\w-]+)["']?\)/);
|
|
39
|
+
return match ? match[1] : null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Lee recursivamente archivos que terminan en un sufijo dado y los ordena numéricamente.
|
|
44
|
+
* @param dir - Directorio base (relativo o absoluto).
|
|
45
|
+
* @param suffix - Sufijo de archivo (como 'table.cube').
|
|
46
|
+
* @returns Rutas absolutas de los archivos encontrados y ordenados.
|
|
47
|
+
*/
|
|
48
|
+
static getCubeFilesRecursively(dir: string, suffix: string): string[] {
|
|
49
|
+
const baseDir = path.resolve(dir); // ✅ Asegura que sea absoluto
|
|
50
|
+
const cubeFiles: string[] = [];
|
|
51
|
+
|
|
52
|
+
function recurse(currentDir: string): void {
|
|
53
|
+
const entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
|
54
|
+
|
|
55
|
+
for (const entry of entries) {
|
|
56
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
57
|
+
|
|
58
|
+
if (entry.isDirectory()) {
|
|
59
|
+
recurse(fullPath);
|
|
60
|
+
} else if (entry.isFile() && (entry.name.endsWith(suffix) || entry.name.includes(suffix))) {
|
|
61
|
+
cubeFiles.push(fullPath); // Ya es absoluta
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
recurse(baseDir);
|
|
67
|
+
|
|
68
|
+
// Ordenar por número si los archivos comienzan con un número
|
|
69
|
+
cubeFiles.sort((a: string, b: string) => {
|
|
70
|
+
const aNum = parseInt(path.basename(a));
|
|
71
|
+
const bNum = parseInt(path.basename(b));
|
|
72
|
+
return (isNaN(aNum) ? 0 : aNum) - (isNaN(bNum) ? 0 : bNum);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return cubeFiles;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export default FileUtils;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"declaration": true, // Generar archivos .d.ts
|
|
6
|
+
"declarationDir": "./dist",
|
|
7
|
+
"outDir": "./dist", // Directorio de salida
|
|
8
|
+
"moduleResolution": "node",
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"strict": true,
|
|
12
|
+
"allowSyntheticDefaultImports": true
|
|
13
|
+
},
|
|
14
|
+
"include": ["src/**/*", "checkEnv.js"], // Incluye los archivos TypeScript
|
|
15
|
+
"exclude": ["node_modules", "dist"]
|
|
16
|
+
}
|
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineConfig } from 'tsup';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
entry: ['src/index.ts'], // Punto de entrada
|
|
5
|
+
format: ['cjs', 'esm'], // Genera CommonJS y ES Modules
|
|
6
|
+
dts: true, // Genera archivos de tipos
|
|
7
|
+
clean: true, // Limpia el directorio de salida
|
|
8
|
+
outDir: 'dist', // Directorio de salida
|
|
9
|
+
splitting: false, // Desactiva la división de código
|
|
10
|
+
sourcemap: true, // Genera sourcemaps
|
|
11
|
+
outExtension: ({ format }) => ({ // Forzar extensiones personalizadas
|
|
12
|
+
js: format === 'cjs' ? '.cjs' : '.js',
|
|
13
|
+
}),
|
|
14
|
+
});
|
package/.npmignore
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# Directories
|
|
2
|
-
examples
|
|
3
|
-
|
|
4
|
-
# Ignorar dependencias y configuraciones de desarrollo
|
|
5
|
-
node_modules/
|
|
6
|
-
npm-debug.log*
|
|
7
|
-
yarn-debug.log*
|
|
8
|
-
yarn-error.log*
|
|
9
|
-
|
|
10
|
-
# Ignorar carpetas y archivos irrelevantes
|
|
11
|
-
.vscode/
|
|
12
|
-
.lh
|
|
13
|
-
.idea/
|
|
14
|
-
.DS_Store
|
|
15
|
-
Thumbs.db
|
|
16
|
-
*.log
|
|
17
|
-
|
|
18
|
-
# Ignorar configuraciones del proyecto
|
|
19
|
-
.env
|
|
20
|
-
.env.*.local
|
|
21
|
-
package-lock.json
|
|
22
|
-
|
|
23
|
-
# Ignorar archivos del sistema
|
|
24
|
-
*.swp
|
|
25
|
-
*.swo
|
|
26
|
-
*.tmp
|
|
27
|
-
*.temp
|
|
28
|
-
|
|
29
|
-
# Ignorar carpetas de trabajo
|
|
30
|
-
temp/
|
|
31
|
-
logs/
|
|
32
|
-
debug/
|
|
33
|
-
|
|
34
|
-
# Ignorar archivos de compilación
|
|
35
|
-
src/
|
|
36
|
-
tsconfig.json
|
|
37
|
-
tsconfig.tsbuildinfo
|
|
38
|
-
|
|
39
|
-
# Ignorar pruebas y configuraciones
|
|
40
|
-
tests/
|
|
41
|
-
__tests__/
|
|
42
|
-
__mocks__/
|
|
43
|
-
coverage/
|
|
44
|
-
jest.config.js
|
|
45
|
-
|
|
46
|
-
# Ignorar documentación o ejemplos no necesarios
|
|
47
|
-
docs/
|
|
48
|
-
examples/
|
|
49
|
-
|
|
50
|
-
# Asegurarse de incluir solo lo esencial
|
|
51
|
-
!.npmignore
|
|
52
|
-
tsconfig.json
|
|
53
|
-
tsup.config.ts
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/Dbcube.ts","../src/lib/FileUtils.ts"],"sourcesContent":["import { Config } from '@dbcube/core';\r\nimport { Database } from '@dbcube/query-builder';\r\nimport FileUtils from './FileUtils';\r\nimport path from 'path';\r\n\r\n/**\r\n * DBCube ORM - Main class for database management\r\n * \r\n * A lightweight, flexible ORM that supports multiple database engines including \r\n * MySQL, PostgreSQL, SQLite, and MongoDB with a fluent query builder interface.\r\n * \r\n * @example\r\n * ```typescript\r\n * import { Dbcube } from 'dbcube';\r\n * \r\n * const dbcube = new Dbcube();\r\n * await dbcube.init();\r\n * \r\n * // Get a database connection\r\n * const db = dbcube.database('myDatabase');\r\n * \r\n * // Use query builder\r\n * const users = await db.table('users').select().where('active', true).get();\r\n * ```\r\n * \r\n * @class\r\n * @author Albert Araya\r\n * @license MIT\r\n */\r\nexport class Dbcube {\r\n private static instance: Dbcube;\r\n private configPath!: string;\r\n private config: any;\r\n private databases!: Record<string, any>;\r\n private initialized!: boolean;\r\n\r\n /**\r\n * Creates a new Dbcube instance (Singleton pattern)\r\n * \r\n * @constructor\r\n * @example\r\n * ```typescript\r\n * const dbcube = new Dbcube();\r\n * ```\r\n */\r\n constructor() {\r\n if (Dbcube.instance) {\r\n return Dbcube.instance;\r\n }\r\n this.configPath = path.join(process.cwd(), 'dbcube.config.js');\r\n this.config = new Config();\r\n this.databases = {};\r\n this.initialized = false;\r\n\r\n Dbcube.instance = this;\r\n }\r\n\r\n /**\r\n * Loads configuration from dbcube.config.js file\r\n * \r\n * @private\r\n * @returns {Promise<void>}\r\n * @throws {Error} If config file doesn't exist\r\n */\r\n async loadConfig() {\r\n const exists = await FileUtils.fileExists(this.configPath);\r\n exists ?? console.log('❌ Dont exists config file, please create a dbcube.config.js file');\r\n }\r\n\r\n /**\r\n * Initializes the Dbcube ORM with database configurations\r\n * \r\n * @param {Object} configCreate - Optional configuration for creating new database\r\n * @param {string} [configCreate.databaseName] - Name of the database to create\r\n * @param {string} [configCreate.motor] - Database engine (mysql, postgres, sqlite, mongodb)\r\n * @param {any} [configCreate.configAnswers] - Additional configuration answers\r\n * @returns {Promise<void>}\r\n * \r\n * @example\r\n * ```typescript\r\n * // Initialize with existing config\r\n * await dbcube.init();\r\n * \r\n * // Initialize with new database creation\r\n * await dbcube.init({\r\n * databaseName: 'myapp',\r\n * motor: 'mysql'\r\n * });\r\n * ```\r\n */\r\n async init(configCreate: { databaseName?: string; motor?: string; configAnswers?: any } = {}) {\r\n if (this.initialized) return;\r\n await this.loadConfig();\r\n const config = require(this.configPath);\r\n \r\n config(this.config);\r\n const databases = Object.keys(this.config.getAllDatabases());\r\n \r\n for (const database of databases) {\r\n this.databases[database] = new Database(database);\r\n }\r\n if(configCreate.databaseName){\r\n this.databases[configCreate.databaseName] = new Database(configCreate.databaseName);\r\n }\r\n }\r\n\r\n /**\r\n * Gets a database connection instance for query building\r\n * \r\n * @param {string} databaseName - Name of the database configuration\r\n * @returns {Database} Database instance with query builder capabilities\r\n * \r\n * @example\r\n * ```typescript\r\n * // Get database connection\r\n * const db = dbcube.database('myapp');\r\n * \r\n * // Use query builder methods\r\n * const users = await db.table('users')\r\n * .select(['id', 'name', 'email'])\r\n * .where('status', 'active')\r\n * .orderBy('created_at', 'desc')\r\n * .limit(10)\r\n * .get();\r\n * \r\n * // Insert data\r\n * await db.table('users').insert({\r\n * name: 'John Doe',\r\n * email: 'john@example.com'\r\n * });\r\n * \r\n * // Update data\r\n * await db.table('users')\r\n * .where('id', 1)\r\n * .update({ status: 'inactive' });\r\n * \r\n * // Delete data\r\n * await db.table('users').where('id', 1).delete();\r\n * ```\r\n */\r\n database(databaseName: string){\r\n return this.databases[databaseName];\r\n }\r\n}\r\n\r\nexport default Dbcube;","import * as fs from 'fs';\r\nimport * as path from 'path';\r\n\r\nexport class FileUtils {\r\n /**\r\n * Verifica si un archivo existe (asincrónico).\r\n * @param filePath - Ruta del archivo.\r\n * @returns Promise que resuelve true si el archivo existe, false si no.\r\n */\r\n static async fileExists(filePath: string): Promise<boolean> {\r\n return new Promise<boolean>((resolve) => {\r\n fs.access(path.resolve(filePath), fs.constants.F_OK, (err) => {\r\n resolve(!err);\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Verifica si un archivo existe (sincrónico).\r\n * @param filePath - Ruta del archivo.\r\n * @returns True si el archivo existe, false si no.\r\n */\r\n static fileExistsSync(filePath: string): boolean {\r\n try {\r\n fs.accessSync(path.resolve(filePath), fs.constants.F_OK);\r\n return true;\r\n } catch {\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * Extrae el nombre de la base de datos de un string con formato @database().\r\n * @param input - String de entrada que contiene la referencia a la base de datos.\r\n * @returns El nombre de la base de datos o null si no se encuentra.\r\n */\r\n static extractDatabaseName(input: string): string | null {\r\n const match = input.match(/@database\\([\"']?([\\w-]+)[\"']?\\)/);\r\n return match ? match[1] : null;\r\n }\r\n\r\n /**\r\n * Lee recursivamente archivos que terminan en un sufijo dado y los ordena numéricamente.\r\n * @param dir - Directorio base (relativo o absoluto).\r\n * @param suffix - Sufijo de archivo (como 'table.cube').\r\n * @returns Rutas absolutas de los archivos encontrados y ordenados.\r\n */\r\n static getCubeFilesRecursively(dir: string, suffix: string): string[] {\r\n const baseDir = path.resolve(dir); // ✅ Asegura que sea absoluto\r\n const cubeFiles: string[] = [];\r\n\r\n function recurse(currentDir: string): void {\r\n const entries = fs.readdirSync(currentDir, { withFileTypes: true });\r\n \r\n for (const entry of entries) {\r\n const fullPath = path.join(currentDir, entry.name);\r\n \r\n if (entry.isDirectory()) {\r\n recurse(fullPath);\r\n } else if (entry.isFile() && (entry.name.endsWith(suffix) || entry.name.includes(suffix))) {\r\n cubeFiles.push(fullPath); // Ya es absoluta\r\n }\r\n }\r\n }\r\n\r\n recurse(baseDir);\r\n\r\n // Ordenar por número si los archivos comienzan con un número\r\n cubeFiles.sort((a: string, b: string) => {\r\n const aNum = parseInt(path.basename(a));\r\n const bNum = parseInt(path.basename(b));\r\n return (isNaN(aNum) ? 0 : aNum) - (isNaN(bNum) ? 0 : bNum);\r\n });\r\n\r\n return cubeFiles;\r\n }\r\n}\r\n\r\nexport default FileUtils;"],"mappings":";;;;;;;;AAAA,SAAS,cAAc;AACvB,SAAS,gBAAgB;;;ACDzB,YAAY,QAAQ;AACpB,YAAY,UAAU;AAEf,IAAM,YAAN,MAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMrB,aAAa,WAAW,UAAoC;AAC1D,WAAO,IAAI,QAAiB,CAACA,aAAY;AACvC,MAAG,UAAY,aAAQ,QAAQ,GAAM,aAAU,MAAM,CAAC,QAAQ;AAC5D,QAAAA,SAAQ,CAAC,GAAG;AAAA,MACd,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAO,eAAe,UAA2B;AAC/C,QAAI;AACF,MAAG,cAAgB,aAAQ,QAAQ,GAAM,aAAU,IAAI;AACvD,aAAO;AAAA,IACT,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAO,oBAAoB,OAA8B;AACvD,UAAM,QAAQ,MAAM,MAAM,iCAAiC;AAC3D,WAAO,QAAQ,MAAM,CAAC,IAAI;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,wBAAwB,K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