@dbcube/core 5.1.15 → 5.2.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/dist/index.d.mts CHANGED
@@ -2,9 +2,92 @@ import { EventEmitter } from 'events';
2
2
 
3
3
  export interface ResponseEngine {
4
4
  status: number;
5
- message: String;
5
+ message: string;
6
6
  data: any;
7
7
  }
8
+ /**
9
+ * Connection parameters for one database.
10
+ */
11
+ export interface DatabaseConnectionConfig {
12
+ /** Host name or IP (not used by SQLite) */
13
+ HOST?: string;
14
+ /** Database user (not used by SQLite) */
15
+ USER?: string;
16
+ /** Database password (not used by SQLite) */
17
+ PASSWORD?: string;
18
+ /** Database name (SQLite: file name without extension) */
19
+ DATABASE: string;
20
+ /** Port (not used by SQLite) */
21
+ PORT?: number | string;
22
+ }
23
+ /**
24
+ * Connection-pool tuning. Every field is optional — engine defaults apply
25
+ * when omitted (maxConnections 5 — 10 for SQLite —, minConnections 2,
26
+ * acquireTimeoutMs 3000, idleTimeoutMs 3600000).
27
+ */
28
+ export interface DatabasePoolConfig {
29
+ /** Max simultaneous connections held by the engine pool */
30
+ maxConnections?: number;
31
+ /** Connections kept warm even when idle */
32
+ minConnections?: number;
33
+ /** How long to wait for a free connection before failing (ms) */
34
+ acquireTimeoutMs?: number;
35
+ /** Close connections idle longer than this (ms) */
36
+ idleTimeoutMs?: number;
37
+ }
38
+ /**
39
+ * Daemon-mode tuning.
40
+ */
41
+ export interface DatabaseDaemonConfig {
42
+ /** Set to false to disable the persistent TCP daemon (one-shot mode).
43
+ * Transactions require the daemon. Equivalent to DBCUBE_DAEMON=0. */
44
+ enabled?: boolean;
45
+ /** Per-request timeout against the daemon (ms, default 30000) */
46
+ requestTimeoutMs?: number;
47
+ }
48
+ export type DatabaseType = "mysql" | "postgres" | "postgresql" | "sqlite" | "mongodb";
49
+ /**
50
+ * One database entry in dbcube.config.js.
51
+ */
52
+ export interface DatabaseDefinition {
53
+ type: DatabaseType;
54
+ config: DatabaseConnectionConfig;
55
+ pool?: DatabasePoolConfig;
56
+ daemon?: DatabaseDaemonConfig;
57
+ }
58
+ /**
59
+ * Shape accepted by config.set().
60
+ */
61
+ export interface ConfigData {
62
+ databases?: Record<string, DatabaseDefinition>;
63
+ [key: string]: unknown;
64
+ }
65
+ /**
66
+ * Clase para manejar la configuración del ORM
67
+ */
68
+ export declare class Config {
69
+ private data;
70
+ private databases;
71
+ /**
72
+ * Establece la configuración
73
+ * @param configData - Datos de configuración
74
+ */
75
+ set(configData: ConfigData): void;
76
+ /**
77
+ * Obtiene un valor de configuración
78
+ * @param key - Clave de configuración
79
+ */
80
+ get<T = unknown>(key: string): T;
81
+ /**
82
+ * Obtiene la configuración de una base de datos específica
83
+ * @param dbName - Nombre de la base de datos
84
+ */
85
+ getDatabase(dbName: string): DatabaseDefinition | null;
86
+ /**
87
+ * Obtiene todas las bases de datos configuradas
88
+ */
89
+ getAllDatabases(): Record<string, DatabaseDefinition>;
90
+ }
8
91
  export declare class Engine {
9
92
  private name;
10
93
  private config;
@@ -33,9 +116,7 @@ export declare class Engine {
33
116
  commitTransaction(txId: string): Promise<void>;
34
117
  rollbackTransaction(txId: string): Promise<void>;
35
118
  setArguments(): any[];
36
- setConfig(name: string): {
37
- [x: string]: any;
38
- } | null;
119
+ setConfig(name: string): DatabaseDefinition | null;
39
120
  getConfig(): any;
40
121
  run(binary: string, args: [
41
122
  ]): Promise<ResponseEngine>;
@@ -54,11 +135,26 @@ export declare class QueryEngine {
54
135
  private isPortAvailable;
55
136
  initializeBinary(): Promise<void>;
56
137
  setArguments(): any[];
57
- setConfig(name: string): {
58
- [x: string]: any;
59
- } | null;
138
+ /** El daemon puede desactivarse por config (daemon.enabled=false) o por env (DBCUBE_DAEMON=0). */
139
+ private daemonEnabled;
140
+ setConfig(name: string): DatabaseDefinition | null;
60
141
  getConfig(): any;
61
142
  run(binary: string, args: string[]): Promise<ResponseEngine>;
143
+ private argsToCommand;
144
+ /**
145
+ * Executes a DML plan over the persistent TCP server.
146
+ * Pass txId to run it inside an active transaction.
147
+ */
148
+ executeDml(dml: object, txId?: string): Promise<ResponseEngine>;
149
+ /**
150
+ * Executes raw SQL (or a MongoDB command document) with bound parameters
151
+ * over the persistent TCP server.
152
+ */
153
+ rawQuery(query: string, params?: any[], txId?: string): Promise<ResponseEngine>;
154
+ /** Starts a server-side transaction and returns its id. */
155
+ beginTransaction(): Promise<string>;
156
+ commitTransaction(txId: string): Promise<void>;
157
+ rollbackTransaction(txId: string): Promise<void>;
62
158
  private executeWithTcpServer;
63
159
  private waitForServerReady;
64
160
  private isServerResponding;
@@ -184,43 +280,6 @@ declare class SQLite {
184
280
  convertToParameterizedQuery(sql: string): ParametrizedQueryResult;
185
281
  }
186
282
  export declare const DbConfig: SQLite;
187
- type DatabaseConfig$1 = Record<string, any>;
188
- /**
189
- * Tipo para la configuración general del ORM
190
- */
191
- export interface ConfigData {
192
- [key: string]: any;
193
- databases?: Record<string, DatabaseConfig$1>;
194
- }
195
- /**
196
- * Clase para manejar la configuración del ORM
197
- */
198
- export declare class Config {
199
- private data;
200
- private databases;
201
- /**
202
- * Establece la configuración
203
- * @param configData - Datos de configuración
204
- */
205
- set(configData: ConfigData): void;
206
- /**
207
- * Obtiene un valor de configuración
208
- * @param key - Clave de configuración
209
- * @returns Valor de configuración
210
- */
211
- get<T = any>(key: string): T;
212
- /**
213
- * Obtiene la configuración de una base de datos específica
214
- * @param dbName - Nombre de la base de datos
215
- * @returns Configuración de la base de datos o null
216
- */
217
- getDatabase(dbName: string): DatabaseConfig$1 | null;
218
- /**
219
- * Obtiene todas las bases de datos configuradas
220
- * @returns Todas las configuraciones de bases de datos
221
- */
222
- getAllDatabases(): Record<string, DatabaseConfig$1>;
223
- }
224
283
  export interface DaemonResponse {
225
284
  status: number;
226
285
  message: string;
@@ -247,6 +306,13 @@ export declare class DaemonClient {
247
306
  static get(name: string, binaryPath: string, engineArgs: string[]): DaemonClient;
248
307
  static isEnabled(): boolean;
249
308
  private portfilePath;
309
+ private lockfilePath;
310
+ /**
311
+ * Exclusive-create lock so two processes never spawn two daemons for the
312
+ * same database at once. Stale locks (crashed starter) expire after 15s.
313
+ */
314
+ private acquireSpawnLock;
315
+ private releaseSpawnLock;
250
316
  /**
251
317
  * Ensures a usable daemon connection. Returns false when the daemon
252
318
  * can't be used (old binary, startup failure) so callers fall back
@@ -264,7 +330,7 @@ export declare class DaemonClient {
264
330
  * Sends a request to the daemon. Responses arrive in FIFO order on the
265
331
  * single socket, so pending requests resolve in send order.
266
332
  */
267
- send(payload: Record<string, any>): Promise<DaemonResponse>;
333
+ send(payload: Record<string, any>, timeoutMs?: number): Promise<DaemonResponse>;
268
334
  execute(dml: object, txId?: string): Promise<DaemonResponse>;
269
335
  raw(query: string, params?: any[], txId?: string): Promise<DaemonResponse>;
270
336
  begin(): Promise<string>;
@@ -405,7 +471,7 @@ export interface ComputedFieldConfig {
405
471
  created_at: string;
406
472
  updated_at: string;
407
473
  }
408
- export type DatabaseType = "mysql" | "sqlite" | "postgres" | "mongodb";
474
+ type DatabaseType$1 = "mysql" | "sqlite" | "postgres" | "mongodb";
409
475
  export declare class ComputedFieldProcessor {
410
476
  static getComputedFields(name: string): Promise<any[]>;
411
477
  /**
@@ -430,7 +496,7 @@ export declare class ComputedFieldProcessor {
430
496
  static computedFields<T extends DataObject>(data: T[], computedConfigs: ComputedFieldConfig[]): T[];
431
497
  }
432
498
  export declare class TableProcessor {
433
- static generateAlterQueries(nowQuery: string, dbType: DatabaseType, tableName: string, database_ref: string): Promise<string[]>;
499
+ static generateAlterQueries(nowQuery: string, dbType: DatabaseType$1, tableName: string, database_ref: string): Promise<string[]>;
434
500
  static saveQuery(table_ref: string, database_ref: string, struct: string): Promise<void>;
435
501
  }
436
502
  export declare class TriggerProcessor {
package/dist/index.d.ts CHANGED
@@ -2,9 +2,92 @@ import { EventEmitter } from 'events';
2
2
 
3
3
  export interface ResponseEngine {
4
4
  status: number;
5
- message: String;
5
+ message: string;
6
6
  data: any;
7
7
  }
8
+ /**
9
+ * Connection parameters for one database.
10
+ */
11
+ export interface DatabaseConnectionConfig {
12
+ /** Host name or IP (not used by SQLite) */
13
+ HOST?: string;
14
+ /** Database user (not used by SQLite) */
15
+ USER?: string;
16
+ /** Database password (not used by SQLite) */
17
+ PASSWORD?: string;
18
+ /** Database name (SQLite: file name without extension) */
19
+ DATABASE: string;
20
+ /** Port (not used by SQLite) */
21
+ PORT?: number | string;
22
+ }
23
+ /**
24
+ * Connection-pool tuning. Every field is optional — engine defaults apply
25
+ * when omitted (maxConnections 5 — 10 for SQLite —, minConnections 2,
26
+ * acquireTimeoutMs 3000, idleTimeoutMs 3600000).
27
+ */
28
+ export interface DatabasePoolConfig {
29
+ /** Max simultaneous connections held by the engine pool */
30
+ maxConnections?: number;
31
+ /** Connections kept warm even when idle */
32
+ minConnections?: number;
33
+ /** How long to wait for a free connection before failing (ms) */
34
+ acquireTimeoutMs?: number;
35
+ /** Close connections idle longer than this (ms) */
36
+ idleTimeoutMs?: number;
37
+ }
38
+ /**
39
+ * Daemon-mode tuning.
40
+ */
41
+ export interface DatabaseDaemonConfig {
42
+ /** Set to false to disable the persistent TCP daemon (one-shot mode).
43
+ * Transactions require the daemon. Equivalent to DBCUBE_DAEMON=0. */
44
+ enabled?: boolean;
45
+ /** Per-request timeout against the daemon (ms, default 30000) */
46
+ requestTimeoutMs?: number;
47
+ }
48
+ export type DatabaseType = "mysql" | "postgres" | "postgresql" | "sqlite" | "mongodb";
49
+ /**
50
+ * One database entry in dbcube.config.js.
51
+ */
52
+ export interface DatabaseDefinition {
53
+ type: DatabaseType;
54
+ config: DatabaseConnectionConfig;
55
+ pool?: DatabasePoolConfig;
56
+ daemon?: DatabaseDaemonConfig;
57
+ }
58
+ /**
59
+ * Shape accepted by config.set().
60
+ */
61
+ export interface ConfigData {
62
+ databases?: Record<string, DatabaseDefinition>;
63
+ [key: string]: unknown;
64
+ }
65
+ /**
66
+ * Clase para manejar la configuración del ORM
67
+ */
68
+ export declare class Config {
69
+ private data;
70
+ private databases;
71
+ /**
72
+ * Establece la configuración
73
+ * @param configData - Datos de configuración
74
+ */
75
+ set(configData: ConfigData): void;
76
+ /**
77
+ * Obtiene un valor de configuración
78
+ * @param key - Clave de configuración
79
+ */
80
+ get<T = unknown>(key: string): T;
81
+ /**
82
+ * Obtiene la configuración de una base de datos específica
83
+ * @param dbName - Nombre de la base de datos
84
+ */
85
+ getDatabase(dbName: string): DatabaseDefinition | null;
86
+ /**
87
+ * Obtiene todas las bases de datos configuradas
88
+ */
89
+ getAllDatabases(): Record<string, DatabaseDefinition>;
90
+ }
8
91
  export declare class Engine {
9
92
  private name;
10
93
  private config;
@@ -33,9 +116,7 @@ export declare class Engine {
33
116
  commitTransaction(txId: string): Promise<void>;
34
117
  rollbackTransaction(txId: string): Promise<void>;
35
118
  setArguments(): any[];
36
- setConfig(name: string): {
37
- [x: string]: any;
38
- } | null;
119
+ setConfig(name: string): DatabaseDefinition | null;
39
120
  getConfig(): any;
40
121
  run(binary: string, args: [
41
122
  ]): Promise<ResponseEngine>;
@@ -54,11 +135,26 @@ export declare class QueryEngine {
54
135
  private isPortAvailable;
55
136
  initializeBinary(): Promise<void>;
56
137
  setArguments(): any[];
57
- setConfig(name: string): {
58
- [x: string]: any;
59
- } | null;
138
+ /** El daemon puede desactivarse por config (daemon.enabled=false) o por env (DBCUBE_DAEMON=0). */
139
+ private daemonEnabled;
140
+ setConfig(name: string): DatabaseDefinition | null;
60
141
  getConfig(): any;
61
142
  run(binary: string, args: string[]): Promise<ResponseEngine>;
143
+ private argsToCommand;
144
+ /**
145
+ * Executes a DML plan over the persistent TCP server.
146
+ * Pass txId to run it inside an active transaction.
147
+ */
148
+ executeDml(dml: object, txId?: string): Promise<ResponseEngine>;
149
+ /**
150
+ * Executes raw SQL (or a MongoDB command document) with bound parameters
151
+ * over the persistent TCP server.
152
+ */
153
+ rawQuery(query: string, params?: any[], txId?: string): Promise<ResponseEngine>;
154
+ /** Starts a server-side transaction and returns its id. */
155
+ beginTransaction(): Promise<string>;
156
+ commitTransaction(txId: string): Promise<void>;
157
+ rollbackTransaction(txId: string): Promise<void>;
62
158
  private executeWithTcpServer;
63
159
  private waitForServerReady;
64
160
  private isServerResponding;
@@ -184,43 +280,6 @@ declare class SQLite {
184
280
  convertToParameterizedQuery(sql: string): ParametrizedQueryResult;
185
281
  }
186
282
  export declare const DbConfig: SQLite;
187
- type DatabaseConfig$1 = Record<string, any>;
188
- /**
189
- * Tipo para la configuración general del ORM
190
- */
191
- export interface ConfigData {
192
- [key: string]: any;
193
- databases?: Record<string, DatabaseConfig$1>;
194
- }
195
- /**
196
- * Clase para manejar la configuración del ORM
197
- */
198
- export declare class Config {
199
- private data;
200
- private databases;
201
- /**
202
- * Establece la configuración
203
- * @param configData - Datos de configuración
204
- */
205
- set(configData: ConfigData): void;
206
- /**
207
- * Obtiene un valor de configuración
208
- * @param key - Clave de configuración
209
- * @returns Valor de configuración
210
- */
211
- get<T = any>(key: string): T;
212
- /**
213
- * Obtiene la configuración de una base de datos específica
214
- * @param dbName - Nombre de la base de datos
215
- * @returns Configuración de la base de datos o null
216
- */
217
- getDatabase(dbName: string): DatabaseConfig$1 | null;
218
- /**
219
- * Obtiene todas las bases de datos configuradas
220
- * @returns Todas las configuraciones de bases de datos
221
- */
222
- getAllDatabases(): Record<string, DatabaseConfig$1>;
223
- }
224
283
  export interface DaemonResponse {
225
284
  status: number;
226
285
  message: string;
@@ -247,6 +306,13 @@ export declare class DaemonClient {
247
306
  static get(name: string, binaryPath: string, engineArgs: string[]): DaemonClient;
248
307
  static isEnabled(): boolean;
249
308
  private portfilePath;
309
+ private lockfilePath;
310
+ /**
311
+ * Exclusive-create lock so two processes never spawn two daemons for the
312
+ * same database at once. Stale locks (crashed starter) expire after 15s.
313
+ */
314
+ private acquireSpawnLock;
315
+ private releaseSpawnLock;
250
316
  /**
251
317
  * Ensures a usable daemon connection. Returns false when the daemon
252
318
  * can't be used (old binary, startup failure) so callers fall back
@@ -264,7 +330,7 @@ export declare class DaemonClient {
264
330
  * Sends a request to the daemon. Responses arrive in FIFO order on the
265
331
  * single socket, so pending requests resolve in send order.
266
332
  */
267
- send(payload: Record<string, any>): Promise<DaemonResponse>;
333
+ send(payload: Record<string, any>, timeoutMs?: number): Promise<DaemonResponse>;
268
334
  execute(dml: object, txId?: string): Promise<DaemonResponse>;
269
335
  raw(query: string, params?: any[], txId?: string): Promise<DaemonResponse>;
270
336
  begin(): Promise<string>;
@@ -405,7 +471,7 @@ export interface ComputedFieldConfig {
405
471
  created_at: string;
406
472
  updated_at: string;
407
473
  }
408
- export type DatabaseType = "mysql" | "sqlite" | "postgres" | "mongodb";
474
+ type DatabaseType$1 = "mysql" | "sqlite" | "postgres" | "mongodb";
409
475
  export declare class ComputedFieldProcessor {
410
476
  static getComputedFields(name: string): Promise<any[]>;
411
477
  /**
@@ -430,7 +496,7 @@ export declare class ComputedFieldProcessor {
430
496
  static computedFields<T extends DataObject>(data: T[], computedConfigs: ComputedFieldConfig[]): T[];
431
497
  }
432
498
  export declare class TableProcessor {
433
- static generateAlterQueries(nowQuery: string, dbType: DatabaseType, tableName: string, database_ref: string): Promise<string[]>;
499
+ static generateAlterQueries(nowQuery: string, dbType: DatabaseType$1, tableName: string, database_ref: string): Promise<string[]>;
434
500
  static saveQuery(table_ref: string, database_ref: string, struct: string): Promise<void>;
435
501
  }
436
502
  export declare class TriggerProcessor {