@dbcube/core 0.0.1
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/.npmignore +52 -0
- package/CONTRIBUTING.md +9 -0
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/dist/index.cjs +1427 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +346 -0
- package/dist/index.d.ts +346 -0
- package/dist/index.js +1389 -0
- package/dist/index.js.map +1 -0
- package/dist/install.cjs +309 -0
- package/dist/install.cjs.map +1 -0
- package/dist/install.d.mts +2 -0
- package/dist/install.d.ts +2 -0
- package/dist/install.js +285 -0
- package/dist/install.js.map +1 -0
- package/package.json +74 -0
- package/tsup.config.ts +14 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import * as sqlite3 from 'sqlite3';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
|
|
4
|
+
interface ResponseEngine {
|
|
5
|
+
status: number;
|
|
6
|
+
message: String;
|
|
7
|
+
data: any;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare class Engine {
|
|
11
|
+
private name;
|
|
12
|
+
private config;
|
|
13
|
+
private arguments;
|
|
14
|
+
private binary;
|
|
15
|
+
private timeout;
|
|
16
|
+
constructor(name: string, timeout?: number);
|
|
17
|
+
setArguments(): any[];
|
|
18
|
+
setConfig(name: string): {
|
|
19
|
+
[x: string]: any;
|
|
20
|
+
} | null;
|
|
21
|
+
getConfig(): any;
|
|
22
|
+
run(binary: string, args: []): Promise<ResponseEngine>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface SystemInfo {
|
|
26
|
+
platform: string;
|
|
27
|
+
arch: string;
|
|
28
|
+
release: string;
|
|
29
|
+
type: string;
|
|
30
|
+
endianness: string;
|
|
31
|
+
cpus: number;
|
|
32
|
+
}
|
|
33
|
+
declare class Arquitecture {
|
|
34
|
+
private systemInfo;
|
|
35
|
+
constructor();
|
|
36
|
+
/**
|
|
37
|
+
* Detecta información completa del sistema
|
|
38
|
+
*/
|
|
39
|
+
private detectSystemInfo;
|
|
40
|
+
/**
|
|
41
|
+
* Obtiene la plataforma normalizada
|
|
42
|
+
*/
|
|
43
|
+
getPlatform(): string;
|
|
44
|
+
/**
|
|
45
|
+
* Obtiene la arquitectura normalizada
|
|
46
|
+
*/
|
|
47
|
+
getArchitecture(): string;
|
|
48
|
+
/**
|
|
49
|
+
* Genera el nombre del binario basado en la arquitectura
|
|
50
|
+
*/
|
|
51
|
+
getBinaryName(baseName: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* Obtiene información completa del sistema
|
|
54
|
+
*/
|
|
55
|
+
getSystemInfo(): SystemInfo;
|
|
56
|
+
/**
|
|
57
|
+
* Obtiene el triple de destino (target triple) para Rust
|
|
58
|
+
*/
|
|
59
|
+
getRustTargetTriple(): string;
|
|
60
|
+
/**
|
|
61
|
+
* Muestra información detallada del sistema
|
|
62
|
+
*/
|
|
63
|
+
printSystemInfo(): void;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface BinaryType {
|
|
67
|
+
query_engine: string;
|
|
68
|
+
schema_engine: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
declare class Binary {
|
|
72
|
+
static get(): BinaryType;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
interface DatabaseConfig$1 {
|
|
76
|
+
name?: string;
|
|
77
|
+
HOST?: string;
|
|
78
|
+
USER?: string;
|
|
79
|
+
PASSWORD?: string;
|
|
80
|
+
DATABASE?: string;
|
|
81
|
+
PORT?: number;
|
|
82
|
+
}
|
|
83
|
+
interface QueryResult {
|
|
84
|
+
status: 'success' | 'error';
|
|
85
|
+
message: string;
|
|
86
|
+
data: any | null;
|
|
87
|
+
}
|
|
88
|
+
interface ParametrizedQueryResult {
|
|
89
|
+
query: string;
|
|
90
|
+
parameters: any[];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Main class to handle SQLite database connections and queries.
|
|
94
|
+
* Implements the Singleton pattern to ensure a single instance of the connection.
|
|
95
|
+
*/
|
|
96
|
+
declare class SQLite {
|
|
97
|
+
private db;
|
|
98
|
+
private database?;
|
|
99
|
+
constructor(config: DatabaseConfig$1);
|
|
100
|
+
ifExist(): Boolean;
|
|
101
|
+
connect(): Promise<sqlite3.Database>;
|
|
102
|
+
disconnect(): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Executes a SQL query on the currently set database.
|
|
105
|
+
*
|
|
106
|
+
* @param {string} sqlQuery - The SQL query to execute.
|
|
107
|
+
* @returns {Promise<QueryResult>} - Returns a JSON object with the status, message, and data (if any).
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* const result = await db.query('SELECT * FROM users;');
|
|
111
|
+
* console.log(result);
|
|
112
|
+
* // { status: 'success', message: 'Query executed successfully', data: [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }] }
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* const result = await db.query('INVALID SQL QUERY;');
|
|
116
|
+
* console.log(result);
|
|
117
|
+
* // { status: 'error', message: 'SQL syntax error', data: null }
|
|
118
|
+
*/
|
|
119
|
+
query(sqlQuery: string): Promise<QueryResult>;
|
|
120
|
+
/**
|
|
121
|
+
* Executes a SQL query with parameters on the currently set database.
|
|
122
|
+
*
|
|
123
|
+
* @param {string} sqlQuery - The SQL query to execute with placeholders (?).
|
|
124
|
+
* @param {any[]} params - Array of parameters to bind to the query placeholders.
|
|
125
|
+
* @returns {Promise<QueryResult>} - Returns a JSON object with the status, message, and data (if any).
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* const result = await db.queryWithParameters('INSERT INTO users (name, email) VALUES (?, ?)', ['John', 'john@example.com']);
|
|
129
|
+
* console.log(result);
|
|
130
|
+
* // { status: 'success', message: 'Query executed successfully', data: { changes: 1, lastID: 3 } }
|
|
131
|
+
*/
|
|
132
|
+
queryWithParameters(sqlQuery: string, params?: any[]): Promise<QueryResult>;
|
|
133
|
+
convertToParameterizedQuery(sql: string): ParametrizedQueryResult;
|
|
134
|
+
}
|
|
135
|
+
declare const DbConfig: SQLite;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Tipo para la configuración de una base de datos
|
|
139
|
+
*/
|
|
140
|
+
type DatabaseConfig = Record<string, any>;
|
|
141
|
+
/**
|
|
142
|
+
* Tipo para la configuración general del ORM
|
|
143
|
+
*/
|
|
144
|
+
interface ConfigData {
|
|
145
|
+
[key: string]: any;
|
|
146
|
+
databases?: Record<string, DatabaseConfig>;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Clase para manejar la configuración del ORM
|
|
150
|
+
*/
|
|
151
|
+
declare class Config {
|
|
152
|
+
private data;
|
|
153
|
+
private databases;
|
|
154
|
+
/**
|
|
155
|
+
* Establece la configuración
|
|
156
|
+
* @param configData - Datos de configuración
|
|
157
|
+
*/
|
|
158
|
+
set(configData: ConfigData): void;
|
|
159
|
+
/**
|
|
160
|
+
* Obtiene un valor de configuración
|
|
161
|
+
* @param key - Clave de configuración
|
|
162
|
+
* @returns Valor de configuración
|
|
163
|
+
*/
|
|
164
|
+
get<T = any>(key: string): T;
|
|
165
|
+
/**
|
|
166
|
+
* Obtiene la configuración de una base de datos específica
|
|
167
|
+
* @param dbName - Nombre de la base de datos
|
|
168
|
+
* @returns Configuración de la base de datos o null
|
|
169
|
+
*/
|
|
170
|
+
getDatabase(dbName: string): DatabaseConfig | null;
|
|
171
|
+
/**
|
|
172
|
+
* Obtiene todas las bases de datos configuradas
|
|
173
|
+
* @returns Todas las configuraciones de bases de datos
|
|
174
|
+
*/
|
|
175
|
+
getAllDatabases(): Record<string, DatabaseConfig>;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
interface InterceptOptions {
|
|
179
|
+
interceptLog?: boolean;
|
|
180
|
+
interceptError?: boolean;
|
|
181
|
+
interceptWarn?: boolean;
|
|
182
|
+
keepOriginal?: boolean;
|
|
183
|
+
useBuffer?: boolean;
|
|
184
|
+
}
|
|
185
|
+
interface ReadOptions {
|
|
186
|
+
lines?: number | null;
|
|
187
|
+
fromEnd?: boolean;
|
|
188
|
+
asArray?: boolean;
|
|
189
|
+
}
|
|
190
|
+
interface WatchOptions {
|
|
191
|
+
persistent?: boolean;
|
|
192
|
+
interval?: number;
|
|
193
|
+
fromEnd?: boolean;
|
|
194
|
+
}
|
|
195
|
+
interface WatchController {
|
|
196
|
+
id: string;
|
|
197
|
+
stop: () => void;
|
|
198
|
+
isWatching: () => boolean;
|
|
199
|
+
}
|
|
200
|
+
interface InterceptController {
|
|
201
|
+
restore: () => void;
|
|
202
|
+
commit: () => Promise<boolean>;
|
|
203
|
+
discard: () => number;
|
|
204
|
+
hasBuffer: () => boolean;
|
|
205
|
+
getBufferSize: () => number;
|
|
206
|
+
}
|
|
207
|
+
interface DeleteResult {
|
|
208
|
+
filePath: string;
|
|
209
|
+
deleted: boolean;
|
|
210
|
+
error: string | null;
|
|
211
|
+
}
|
|
212
|
+
type LogLevel = 'INFO' | 'ERROR' | 'WARN' | 'DEBUG';
|
|
213
|
+
declare class FileLogger extends EventEmitter {
|
|
214
|
+
private static watchers;
|
|
215
|
+
private static buffers;
|
|
216
|
+
/**
|
|
217
|
+
* Escribe un log en el archivo especificado
|
|
218
|
+
* @param filePath - Ruta del archivo de log
|
|
219
|
+
* @param message - Mensaje a escribir
|
|
220
|
+
* @param level - Nivel del log (INFO, ERROR, WARN, DEBUG)
|
|
221
|
+
* @param append - Si debe agregar al final del archivo (default: true)
|
|
222
|
+
*/
|
|
223
|
+
static write(filePath: string, message: string, level?: LogLevel, append?: boolean): Promise<boolean>;
|
|
224
|
+
/**
|
|
225
|
+
* Inicia un buffer temporal para un archivo de log
|
|
226
|
+
* @param filePath - Ruta del archivo de log
|
|
227
|
+
*/
|
|
228
|
+
static startBuffer(filePath: string): void;
|
|
229
|
+
/**
|
|
230
|
+
* Confirma y escribe todos los logs del buffer al archivo
|
|
231
|
+
* @param filePath - Ruta del archivo de log
|
|
232
|
+
*/
|
|
233
|
+
static commitBuffer(filePath: string): Promise<boolean>;
|
|
234
|
+
/**
|
|
235
|
+
* Descarta todos los logs del buffer sin escribirlos
|
|
236
|
+
* @param filePath - Ruta del archivo de log
|
|
237
|
+
*/
|
|
238
|
+
static discardBuffer(filePath: string): number;
|
|
239
|
+
/**
|
|
240
|
+
* Verifica si existe un buffer activo para un archivo
|
|
241
|
+
* @param filePath - Ruta del archivo de log
|
|
242
|
+
*/
|
|
243
|
+
static hasBuffer(filePath: string): boolean;
|
|
244
|
+
/**
|
|
245
|
+
* Obtiene el número de logs en el buffer
|
|
246
|
+
* @param filePath - Ruta del archivo de log
|
|
247
|
+
*/
|
|
248
|
+
static getBufferSize(filePath: string): number;
|
|
249
|
+
/**
|
|
250
|
+
* Intercepta console.log y console.error para escribir a archivo
|
|
251
|
+
* @param filePath - Ruta del archivo de log
|
|
252
|
+
* @param options - Opciones de interceptación
|
|
253
|
+
*/
|
|
254
|
+
static interceptConsole(filePath: string, options?: InterceptOptions): InterceptController;
|
|
255
|
+
/**
|
|
256
|
+
* Lee el contenido completo del archivo de log
|
|
257
|
+
* @param filePath - Ruta del archivo de log
|
|
258
|
+
* @param options - Opciones de lectura
|
|
259
|
+
* @returns Contenido del archivo
|
|
260
|
+
*/
|
|
261
|
+
static read(filePath: string, options?: ReadOptions): Promise<string | string[]>;
|
|
262
|
+
/**
|
|
263
|
+
* Observa un archivo de log en tiempo real
|
|
264
|
+
* @param filePath - Ruta del archivo de log
|
|
265
|
+
* @param callback - Función callback para nuevas líneas
|
|
266
|
+
* @param options - Opciones del watcher
|
|
267
|
+
* @returns Objeto con métodos para controlar el watcher
|
|
268
|
+
*/
|
|
269
|
+
static watch(filePath: string, callback: (line: string, filePath: string) => void, options?: WatchOptions): WatchController;
|
|
270
|
+
/**
|
|
271
|
+
* Detiene todos los watchers activos
|
|
272
|
+
*/
|
|
273
|
+
static stopAllWatchers(): void;
|
|
274
|
+
/**
|
|
275
|
+
* Métodos de conveniencia para diferentes niveles de log
|
|
276
|
+
*/
|
|
277
|
+
static info(filePath: string, message: string): Promise<boolean>;
|
|
278
|
+
static error(filePath: string, message: string): Promise<boolean>;
|
|
279
|
+
static warn(filePath: string, message: string): Promise<boolean>;
|
|
280
|
+
static debug(filePath: string, message: string): Promise<boolean>;
|
|
281
|
+
/**
|
|
282
|
+
* Limpia logs antiguos
|
|
283
|
+
* @param filePath - Ruta del archivo de log
|
|
284
|
+
* @param maxLines - Máximo número de líneas a mantener
|
|
285
|
+
*/
|
|
286
|
+
static cleanup(filePath: string, maxLines?: number): Promise<number>;
|
|
287
|
+
/**
|
|
288
|
+
* Elimina un archivo de log
|
|
289
|
+
* @param filePath - Ruta del archivo de log a eliminar
|
|
290
|
+
*/
|
|
291
|
+
static deleteLogFile(filePath: string): Promise<boolean>;
|
|
292
|
+
/**
|
|
293
|
+
* Elimina múltiples archivos de log
|
|
294
|
+
* @param filePaths - Array de rutas de archivos de log a eliminar
|
|
295
|
+
*/
|
|
296
|
+
static deleteLogFiles(filePaths: string[]): Promise<DeleteResult[]>;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
interface DataObject {
|
|
300
|
+
[key: string]: any;
|
|
301
|
+
}
|
|
302
|
+
interface ComputedFieldConfig {
|
|
303
|
+
id: number;
|
|
304
|
+
table_ref: string;
|
|
305
|
+
column: string;
|
|
306
|
+
type: 'string' | 'number' | 'boolean' | 'date' | 'object';
|
|
307
|
+
instruction: string;
|
|
308
|
+
database_ref: string;
|
|
309
|
+
created_at: string;
|
|
310
|
+
updated_at: string;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
type DatabaseType = 'mysql' | 'sqlite' | 'postgres' | 'mongodb';
|
|
314
|
+
|
|
315
|
+
declare class ComputedFieldProcessor {
|
|
316
|
+
static getComputedFields(name: string): Promise<any[]>;
|
|
317
|
+
/**
|
|
318
|
+
* Processes computed field instruction and returns the computed value
|
|
319
|
+
* @param instruction - The @compute instruction
|
|
320
|
+
* @param rowData - The row data containing column values
|
|
321
|
+
* @returns The computed value or null if there's an error
|
|
322
|
+
*/
|
|
323
|
+
static processInstruction(instruction: string, rowData: Record<string, any>): any;
|
|
324
|
+
/**
|
|
325
|
+
* Extracts column dependencies from a computed field instruction
|
|
326
|
+
* @param instruction - The @compute instruction
|
|
327
|
+
* @returns Array of column names that this computed field depends on
|
|
328
|
+
*/
|
|
329
|
+
static extractDependencies(instruction: string): string[];
|
|
330
|
+
/**
|
|
331
|
+
* Adds computed fields to an array of data objects based on configuration array
|
|
332
|
+
* @param data - Array of data objects
|
|
333
|
+
* @param computedConfigs - Array of computed field configurations
|
|
334
|
+
* @returns Array with the new computed fields added
|
|
335
|
+
*/
|
|
336
|
+
static computedFields<T extends DataObject>(data: T[], computedConfigs: ComputedFieldConfig[]): T[];
|
|
337
|
+
}
|
|
338
|
+
declare class TableProcessor {
|
|
339
|
+
static generateAlterQueries(nowQuery: string, dbType: DatabaseType, tableName: string, database_ref: string): Promise<string[]>;
|
|
340
|
+
static saveQuery(table_ref: string, database_ref: string, struct: string): Promise<void>;
|
|
341
|
+
}
|
|
342
|
+
declare class TriggerProcessor {
|
|
343
|
+
static getTriggers(name: string): Promise<any[]>;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export { Arquitecture, Binary, ComputedFieldProcessor, Config, DbConfig, Engine, FileLogger, type InterceptController, TableProcessor, TriggerProcessor };
|