dbcube 1.1.2 → 1.1.4

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 CHANGED
@@ -49,3 +49,5 @@ examples/
49
49
 
50
50
  # Asegurarse de incluir solo lo esencial
51
51
  !.npmignore
52
+ tsconfig.json
53
+ tsup.config.ts
package/.pnpmrc ADDED
@@ -0,0 +1 @@
1
+ enable-pre-post-scripts=true
package/dist/index.cjs CHANGED
@@ -115,6 +115,15 @@ var Dbcube = class _Dbcube {
115
115
  config;
116
116
  databases;
117
117
  initialized;
118
+ /**
119
+ * Creates a new Dbcube instance (Singleton pattern)
120
+ *
121
+ * @constructor
122
+ * @example
123
+ * ```typescript
124
+ * const dbcube = new Dbcube();
125
+ * ```
126
+ */
118
127
  constructor() {
119
128
  if (_Dbcube.instance) {
120
129
  return _Dbcube.instance;
@@ -125,10 +134,38 @@ var Dbcube = class _Dbcube {
125
134
  this.initialized = false;
126
135
  _Dbcube.instance = this;
127
136
  }
137
+ /**
138
+ * Loads configuration from dbcube.config.js file
139
+ *
140
+ * @private
141
+ * @returns {Promise<void>}
142
+ * @throws {Error} If config file doesn't exist
143
+ */
128
144
  async loadConfig() {
129
145
  const exists = await FileUtils_default.fileExists(this.configPath);
130
146
  exists ?? console.log("\u274C Dont exists config file, please create a dbcube.config.js file");
131
147
  }
148
+ /**
149
+ * Initializes the Dbcube ORM with database configurations
150
+ *
151
+ * @param {Object} configCreate - Optional configuration for creating new database
152
+ * @param {string} [configCreate.databaseName] - Name of the database to create
153
+ * @param {string} [configCreate.motor] - Database engine (mysql, postgres, sqlite, mongodb)
154
+ * @param {any} [configCreate.configAnswers] - Additional configuration answers
155
+ * @returns {Promise<void>}
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * // Initialize with existing config
160
+ * await dbcube.init();
161
+ *
162
+ * // Initialize with new database creation
163
+ * await dbcube.init({
164
+ * databaseName: 'myapp',
165
+ * motor: 'mysql'
166
+ * });
167
+ * ```
168
+ */
132
169
  async init(configCreate = {}) {
133
170
  if (this.initialized) return;
134
171
  await this.loadConfig();
@@ -142,6 +179,40 @@ var Dbcube = class _Dbcube {
142
179
  this.databases[configCreate.databaseName] = new import_query_builder.Database(configCreate.databaseName);
143
180
  }
144
181
  }
182
+ /**
183
+ * Gets a database connection instance for query building
184
+ *
185
+ * @param {string} databaseName - Name of the database configuration
186
+ * @returns {Database} Database instance with query builder capabilities
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * // Get database connection
191
+ * const db = dbcube.database('myapp');
192
+ *
193
+ * // Use query builder methods
194
+ * const users = await db.table('users')
195
+ * .select(['id', 'name', 'email'])
196
+ * .where('status', 'active')
197
+ * .orderBy('created_at', 'desc')
198
+ * .limit(10)
199
+ * .get();
200
+ *
201
+ * // Insert data
202
+ * await db.table('users').insert({
203
+ * name: 'John Doe',
204
+ * email: 'john@example.com'
205
+ * });
206
+ *
207
+ * // Update data
208
+ * await db.table('users')
209
+ * .where('id', 1)
210
+ * .update({ status: 'inactive' });
211
+ *
212
+ * // Delete data
213
+ * await db.table('users').where('id', 1).delete();
214
+ * ```
215
+ */
145
216
  database(databaseName) {
146
217
  return this.databases[databaseName];
147
218
  }
@@ -150,4 +221,28 @@ var Dbcube = class _Dbcube {
150
221
  0 && (module.exports = {
151
222
  Dbcube
152
223
  });
224
+ /**
225
+ * DBCube ORM - Main class for database management
226
+ *
227
+ * A lightweight, flexible ORM that supports multiple database engines including
228
+ * MySQL, PostgreSQL, SQLite, and MongoDB with a fluent query builder interface.
229
+ *
230
+ * @example
231
+ * ```typescript
232
+ * import { Dbcube } from 'dbcube';
233
+ *
234
+ * const dbcube = new Dbcube();
235
+ * await dbcube.init();
236
+ *
237
+ * // Get a database connection
238
+ * const db = dbcube.database('myDatabase');
239
+ *
240
+ * // Use query builder
241
+ * const users = await db.table('users').select().where('active', true).get();
242
+ * ```
243
+ *
244
+ * @class
245
+ * @author Albert Araya
246
+ * @license MIT
247
+ */
153
248
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/lib/Dbcube.ts","../src/lib/FileUtils.ts"],"sourcesContent":["import { Dbcube } from './lib/Dbcube';\r\n\r\n\r\nexport { Dbcube };","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\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 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 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 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 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)) {\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":";;;;;;;;;;;;;;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dbcube.ts","../src/lib/FileUtils.ts"],"sourcesContent":["import { Dbcube } from './lib/Dbcube';\r\n\r\n\r\nexport { Dbcube };","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)) {\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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gBAAgB,CAAC;AAE3D,eAAW,YAAY,WAAW;AAC9B,WAAK,UAAU,QAAQ,IAAI,IAAI,8BAAS,QAAQ;AAAA,IACpD;AACA,QAAG,aAAa,cAAa;AACzB,WAAK,UAAU,aAAa,YAAY,IAAI,IAAI,8BAAS,aAAa,YAAY;AAAA,IACtF;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoCA,SAAS,cAAqB;AAC1B,WAAO,KAAK,UAAU,YAAY;AAAA,EACtC;AACJ;","names":["resolve","path"]}
package/dist/index.d.mts CHANGED
@@ -1,16 +1,111 @@
1
+ /**
2
+ * DBCube ORM - Main class for database management
3
+ *
4
+ * A lightweight, flexible ORM that supports multiple database engines including
5
+ * MySQL, PostgreSQL, SQLite, and MongoDB with a fluent query builder interface.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { Dbcube } from 'dbcube';
10
+ *
11
+ * const dbcube = new Dbcube();
12
+ * await dbcube.init();
13
+ *
14
+ * // Get a database connection
15
+ * const db = dbcube.database('myDatabase');
16
+ *
17
+ * // Use query builder
18
+ * const users = await db.table('users').select().where('active', true).get();
19
+ * ```
20
+ *
21
+ * @class
22
+ * @author Albert Araya
23
+ * @license MIT
24
+ */
1
25
  declare class Dbcube {
2
26
  private static instance;
3
27
  private configPath;
4
28
  private config;
5
29
  private databases;
6
30
  private initialized;
31
+ /**
32
+ * Creates a new Dbcube instance (Singleton pattern)
33
+ *
34
+ * @constructor
35
+ * @example
36
+ * ```typescript
37
+ * const dbcube = new Dbcube();
38
+ * ```
39
+ */
7
40
  constructor();
41
+ /**
42
+ * Loads configuration from dbcube.config.js file
43
+ *
44
+ * @private
45
+ * @returns {Promise<void>}
46
+ * @throws {Error} If config file doesn't exist
47
+ */
8
48
  loadConfig(): Promise<void>;
49
+ /**
50
+ * Initializes the Dbcube ORM with database configurations
51
+ *
52
+ * @param {Object} configCreate - Optional configuration for creating new database
53
+ * @param {string} [configCreate.databaseName] - Name of the database to create
54
+ * @param {string} [configCreate.motor] - Database engine (mysql, postgres, sqlite, mongodb)
55
+ * @param {any} [configCreate.configAnswers] - Additional configuration answers
56
+ * @returns {Promise<void>}
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * // Initialize with existing config
61
+ * await dbcube.init();
62
+ *
63
+ * // Initialize with new database creation
64
+ * await dbcube.init({
65
+ * databaseName: 'myapp',
66
+ * motor: 'mysql'
67
+ * });
68
+ * ```
69
+ */
9
70
  init(configCreate?: {
10
71
  databaseName?: string;
11
72
  motor?: string;
12
73
  configAnswers?: any;
13
74
  }): Promise<void>;
75
+ /**
76
+ * Gets a database connection instance for query building
77
+ *
78
+ * @param {string} databaseName - Name of the database configuration
79
+ * @returns {Database} Database instance with query builder capabilities
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * // Get database connection
84
+ * const db = dbcube.database('myapp');
85
+ *
86
+ * // Use query builder methods
87
+ * const users = await db.table('users')
88
+ * .select(['id', 'name', 'email'])
89
+ * .where('status', 'active')
90
+ * .orderBy('created_at', 'desc')
91
+ * .limit(10)
92
+ * .get();
93
+ *
94
+ * // Insert data
95
+ * await db.table('users').insert({
96
+ * name: 'John Doe',
97
+ * email: 'john@example.com'
98
+ * });
99
+ *
100
+ * // Update data
101
+ * await db.table('users')
102
+ * .where('id', 1)
103
+ * .update({ status: 'inactive' });
104
+ *
105
+ * // Delete data
106
+ * await db.table('users').where('id', 1).delete();
107
+ * ```
108
+ */
14
109
  database(databaseName: string): any;
15
110
  }
16
111
 
package/dist/index.d.ts CHANGED
@@ -1,16 +1,111 @@
1
+ /**
2
+ * DBCube ORM - Main class for database management
3
+ *
4
+ * A lightweight, flexible ORM that supports multiple database engines including
5
+ * MySQL, PostgreSQL, SQLite, and MongoDB with a fluent query builder interface.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { Dbcube } from 'dbcube';
10
+ *
11
+ * const dbcube = new Dbcube();
12
+ * await dbcube.init();
13
+ *
14
+ * // Get a database connection
15
+ * const db = dbcube.database('myDatabase');
16
+ *
17
+ * // Use query builder
18
+ * const users = await db.table('users').select().where('active', true).get();
19
+ * ```
20
+ *
21
+ * @class
22
+ * @author Albert Araya
23
+ * @license MIT
24
+ */
1
25
  declare class Dbcube {
2
26
  private static instance;
3
27
  private configPath;
4
28
  private config;
5
29
  private databases;
6
30
  private initialized;
31
+ /**
32
+ * Creates a new Dbcube instance (Singleton pattern)
33
+ *
34
+ * @constructor
35
+ * @example
36
+ * ```typescript
37
+ * const dbcube = new Dbcube();
38
+ * ```
39
+ */
7
40
  constructor();
41
+ /**
42
+ * Loads configuration from dbcube.config.js file
43
+ *
44
+ * @private
45
+ * @returns {Promise<void>}
46
+ * @throws {Error} If config file doesn't exist
47
+ */
8
48
  loadConfig(): Promise<void>;
49
+ /**
50
+ * Initializes the Dbcube ORM with database configurations
51
+ *
52
+ * @param {Object} configCreate - Optional configuration for creating new database
53
+ * @param {string} [configCreate.databaseName] - Name of the database to create
54
+ * @param {string} [configCreate.motor] - Database engine (mysql, postgres, sqlite, mongodb)
55
+ * @param {any} [configCreate.configAnswers] - Additional configuration answers
56
+ * @returns {Promise<void>}
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * // Initialize with existing config
61
+ * await dbcube.init();
62
+ *
63
+ * // Initialize with new database creation
64
+ * await dbcube.init({
65
+ * databaseName: 'myapp',
66
+ * motor: 'mysql'
67
+ * });
68
+ * ```
69
+ */
9
70
  init(configCreate?: {
10
71
  databaseName?: string;
11
72
  motor?: string;
12
73
  configAnswers?: any;
13
74
  }): Promise<void>;
75
+ /**
76
+ * Gets a database connection instance for query building
77
+ *
78
+ * @param {string} databaseName - Name of the database configuration
79
+ * @returns {Database} Database instance with query builder capabilities
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * // Get database connection
84
+ * const db = dbcube.database('myapp');
85
+ *
86
+ * // Use query builder methods
87
+ * const users = await db.table('users')
88
+ * .select(['id', 'name', 'email'])
89
+ * .where('status', 'active')
90
+ * .orderBy('created_at', 'desc')
91
+ * .limit(10)
92
+ * .get();
93
+ *
94
+ * // Insert data
95
+ * await db.table('users').insert({
96
+ * name: 'John Doe',
97
+ * email: 'john@example.com'
98
+ * });
99
+ *
100
+ * // Update data
101
+ * await db.table('users')
102
+ * .where('id', 1)
103
+ * .update({ status: 'inactive' });
104
+ *
105
+ * // Delete data
106
+ * await db.table('users').where('id', 1).delete();
107
+ * ```
108
+ */
14
109
  database(databaseName: string): any;
15
110
  }
16
111
 
package/dist/index.js CHANGED
@@ -86,6 +86,15 @@ var Dbcube = class _Dbcube {
86
86
  config;
87
87
  databases;
88
88
  initialized;
89
+ /**
90
+ * Creates a new Dbcube instance (Singleton pattern)
91
+ *
92
+ * @constructor
93
+ * @example
94
+ * ```typescript
95
+ * const dbcube = new Dbcube();
96
+ * ```
97
+ */
89
98
  constructor() {
90
99
  if (_Dbcube.instance) {
91
100
  return _Dbcube.instance;
@@ -96,10 +105,38 @@ var Dbcube = class _Dbcube {
96
105
  this.initialized = false;
97
106
  _Dbcube.instance = this;
98
107
  }
108
+ /**
109
+ * Loads configuration from dbcube.config.js file
110
+ *
111
+ * @private
112
+ * @returns {Promise<void>}
113
+ * @throws {Error} If config file doesn't exist
114
+ */
99
115
  async loadConfig() {
100
116
  const exists = await FileUtils_default.fileExists(this.configPath);
101
117
  exists ?? console.log("\u274C Dont exists config file, please create a dbcube.config.js file");
102
118
  }
119
+ /**
120
+ * Initializes the Dbcube ORM with database configurations
121
+ *
122
+ * @param {Object} configCreate - Optional configuration for creating new database
123
+ * @param {string} [configCreate.databaseName] - Name of the database to create
124
+ * @param {string} [configCreate.motor] - Database engine (mysql, postgres, sqlite, mongodb)
125
+ * @param {any} [configCreate.configAnswers] - Additional configuration answers
126
+ * @returns {Promise<void>}
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * // Initialize with existing config
131
+ * await dbcube.init();
132
+ *
133
+ * // Initialize with new database creation
134
+ * await dbcube.init({
135
+ * databaseName: 'myapp',
136
+ * motor: 'mysql'
137
+ * });
138
+ * ```
139
+ */
103
140
  async init(configCreate = {}) {
104
141
  if (this.initialized) return;
105
142
  await this.loadConfig();
@@ -113,6 +150,40 @@ var Dbcube = class _Dbcube {
113
150
  this.databases[configCreate.databaseName] = new Database(configCreate.databaseName);
114
151
  }
115
152
  }
153
+ /**
154
+ * Gets a database connection instance for query building
155
+ *
156
+ * @param {string} databaseName - Name of the database configuration
157
+ * @returns {Database} Database instance with query builder capabilities
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * // Get database connection
162
+ * const db = dbcube.database('myapp');
163
+ *
164
+ * // Use query builder methods
165
+ * const users = await db.table('users')
166
+ * .select(['id', 'name', 'email'])
167
+ * .where('status', 'active')
168
+ * .orderBy('created_at', 'desc')
169
+ * .limit(10)
170
+ * .get();
171
+ *
172
+ * // Insert data
173
+ * await db.table('users').insert({
174
+ * name: 'John Doe',
175
+ * email: 'john@example.com'
176
+ * });
177
+ *
178
+ * // Update data
179
+ * await db.table('users')
180
+ * .where('id', 1)
181
+ * .update({ status: 'inactive' });
182
+ *
183
+ * // Delete data
184
+ * await db.table('users').where('id', 1).delete();
185
+ * ```
186
+ */
116
187
  database(databaseName) {
117
188
  return this.databases[databaseName];
118
189
  }
@@ -120,4 +191,28 @@ var Dbcube = class _Dbcube {
120
191
  export {
121
192
  Dbcube
122
193
  };
194
+ /**
195
+ * DBCube ORM - Main class for database management
196
+ *
197
+ * A lightweight, flexible ORM that supports multiple database engines including
198
+ * MySQL, PostgreSQL, SQLite, and MongoDB with a fluent query builder interface.
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * import { Dbcube } from 'dbcube';
203
+ *
204
+ * const dbcube = new Dbcube();
205
+ * await dbcube.init();
206
+ *
207
+ * // Get a database connection
208
+ * const db = dbcube.database('myDatabase');
209
+ *
210
+ * // Use query builder
211
+ * const users = await db.table('users').select().where('active', true).get();
212
+ * ```
213
+ *
214
+ * @class
215
+ * @author Albert Araya
216
+ * @license MIT
217
+ */
123
218
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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\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 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 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 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 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)) {\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) ? 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AY;AAAA,EACtC;AACJ;","names":["resolve","path","path"]}
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)) {\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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AW,YAAY,WAAW;AAC9B,WAAK,UAAU,QAAQ,IAAI,IAAI,SAAS,QAAQ;AAAA,IACpD;AACA,QAAG,aAAa,cAAa;AACzB,WAAK,UAAU,aAAa,YAAY,IAAI,IAAI,SAAS,aAAa,YAAY;AAAA,IACtF;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoCA,SAAS,cAAqB;AAC1B,WAAO,KAAK,UAAU,YAAY;AAAA,EACtC;AACJ;","names":["resolve","path","path"]}
@@ -0,0 +1,21 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*|*MINGW*|*MSYS*)
6
+ if command -v cygpath > /dev/null 2>&1; then
7
+ basedir=`cygpath -w "$basedir"`
8
+ fi
9
+ ;;
10
+ esac
11
+
12
+ if [ -z "$NODE_PATH" ]; then
13
+ export NODE_PATH="/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/@dbcube+cli@1.1.3_@types+node@24.3.0/node_modules/@dbcube/cli/src/node_modules:/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/@dbcube+cli@1.1.3_@types+node@24.3.0/node_modules/@dbcube/cli/node_modules:/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/@dbcube+cli@1.1.3_@types+node@24.3.0/node_modules/@dbcube/node_modules:/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/@dbcube+cli@1.1.3_@types+node@24.3.0/node_modules:/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/node_modules"
14
+ else
15
+ export NODE_PATH="/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/@dbcube+cli@1.1.3_@types+node@24.3.0/node_modules/@dbcube/cli/src/node_modules:/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/@dbcube+cli@1.1.3_@types+node@24.3.0/node_modules/@dbcube/cli/node_modules:/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/@dbcube+cli@1.1.3_@types+node@24.3.0/node_modules/@dbcube/node_modules:/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/@dbcube+cli@1.1.3_@types+node@24.3.0/node_modules:/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/node_modules:$NODE_PATH"
16
+ fi
17
+ if [ -x "$basedir/node" ]; then
18
+ exec "$basedir/node" "$basedir/../@dbcube/cli/src/index.js" "$@"
19
+ else
20
+ exec node "$basedir/../@dbcube/cli/src/index.js" "$@"
21
+ fi
@@ -0,0 +1,12 @@
1
+ @SETLOCAL
2
+ @IF NOT DEFINED NODE_PATH (
3
+ @SET "NODE_PATH=C:\Users\huawei\Documents\github\dbcube\orm\node_modules\.pnpm\@dbcube+cli@1.1.3_@types+node@24.3.0\node_modules\@dbcube\cli\src\node_modules;C:\Users\huawei\Documents\github\dbcube\orm\node_modules\.pnpm\@dbcube+cli@1.1.3_@types+node@24.3.0\node_modules\@dbcube\cli\node_modules;C:\Users\huawei\Documents\github\dbcube\orm\node_modules\.pnpm\@dbcube+cli@1.1.3_@types+node@24.3.0\node_modules\@dbcube\node_modules;C:\Users\huawei\Documents\github\dbcube\orm\node_modules\.pnpm\@dbcube+cli@1.1.3_@types+node@24.3.0\node_modules;C:\Users\huawei\Documents\github\dbcube\orm\node_modules\.pnpm\node_modules"
4
+ ) ELSE (
5
+ @SET "NODE_PATH=C:\Users\huawei\Documents\github\dbcube\orm\node_modules\.pnpm\@dbcube+cli@1.1.3_@types+node@24.3.0\node_modules\@dbcube\cli\src\node_modules;C:\Users\huawei\Documents\github\dbcube\orm\node_modules\.pnpm\@dbcube+cli@1.1.3_@types+node@24.3.0\node_modules\@dbcube\cli\node_modules;C:\Users\huawei\Documents\github\dbcube\orm\node_modules\.pnpm\@dbcube+cli@1.1.3_@types+node@24.3.0\node_modules\@dbcube\node_modules;C:\Users\huawei\Documents\github\dbcube\orm\node_modules\.pnpm\@dbcube+cli@1.1.3_@types+node@24.3.0\node_modules;C:\Users\huawei\Documents\github\dbcube\orm\node_modules\.pnpm\node_modules;%NODE_PATH%"
6
+ )
7
+ @IF EXIST "%~dp0\node.exe" (
8
+ "%~dp0\node.exe" "%~dp0\..\@dbcube\cli\src\index.js" %*
9
+ ) ELSE (
10
+ @SET PATHEXT=%PATHEXT:;.JS;=;%
11
+ node "%~dp0\..\@dbcube\cli\src\index.js" %*
12
+ )
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env pwsh
2
+ $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
3
+
4
+ $exe=""
5
+ $pathsep=":"
6
+ $env_node_path=$env:NODE_PATH
7
+ $new_node_path="C:\Users\huawei\Documents\github\dbcube\orm\node_modules\.pnpm\@dbcube+cli@1.1.3_@types+node@24.3.0\node_modules\@dbcube\cli\src\node_modules;C:\Users\huawei\Documents\github\dbcube\orm\node_modules\.pnpm\@dbcube+cli@1.1.3_@types+node@24.3.0\node_modules\@dbcube\cli\node_modules;C:\Users\huawei\Documents\github\dbcube\orm\node_modules\.pnpm\@dbcube+cli@1.1.3_@types+node@24.3.0\node_modules\@dbcube\node_modules;C:\Users\huawei\Documents\github\dbcube\orm\node_modules\.pnpm\@dbcube+cli@1.1.3_@types+node@24.3.0\node_modules;C:\Users\huawei\Documents\github\dbcube\orm\node_modules\.pnpm\node_modules"
8
+ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
9
+ # Fix case when both the Windows and Linux builds of Node
10
+ # are installed in the same directory
11
+ $exe=".exe"
12
+ $pathsep=";"
13
+ } else {
14
+ $new_node_path="/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/@dbcube+cli@1.1.3_@types+node@24.3.0/node_modules/@dbcube/cli/src/node_modules:/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/@dbcube+cli@1.1.3_@types+node@24.3.0/node_modules/@dbcube/cli/node_modules:/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/@dbcube+cli@1.1.3_@types+node@24.3.0/node_modules/@dbcube/node_modules:/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/@dbcube+cli@1.1.3_@types+node@24.3.0/node_modules:/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/node_modules"
15
+ }
16
+ if ([string]::IsNullOrEmpty($env_node_path)) {
17
+ $env:NODE_PATH=$new_node_path
18
+ } else {
19
+ $env:NODE_PATH="$new_node_path$pathsep$env_node_path"
20
+ }
21
+
22
+ $ret=0
23
+ if (Test-Path "$basedir/node$exe") {
24
+ # Support pipeline input
25
+ if ($MyInvocation.ExpectingInput) {
26
+ $input | & "$basedir/node$exe" "$basedir/../@dbcube/cli/src/index.js" $args
27
+ } else {
28
+ & "$basedir/node$exe" "$basedir/../@dbcube/cli/src/index.js" $args
29
+ }
30
+ $ret=$LASTEXITCODE
31
+ } else {
32
+ # Support pipeline input
33
+ if ($MyInvocation.ExpectingInput) {
34
+ $input | & "node$exe" "$basedir/../@dbcube/cli/src/index.js" $args
35
+ } else {
36
+ & "node$exe" "$basedir/../@dbcube/cli/src/index.js" $args
37
+ }
38
+ $ret=$LASTEXITCODE
39
+ }
40
+ $env:NODE_PATH=$env_node_path
41
+ exit $ret
@@ -0,0 +1,21 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*|*MINGW*|*MSYS*)
6
+ if command -v cygpath > /dev/null 2>&1; then
7
+ basedir=`cygpath -w "$basedir"`
8
+ fi
9
+ ;;
10
+ esac
11
+
12
+ if [ -z "$NODE_PATH" ]; then
13
+ export NODE_PATH="/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/esbuild@0.25.9/node_modules/esbuild/bin/node_modules:/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/esbuild@0.25.9/node_modules/esbuild/node_modules:/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/esbuild@0.25.9/node_modules:/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/node_modules"
14
+ else
15
+ export NODE_PATH="/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/esbuild@0.25.9/node_modules/esbuild/bin/node_modules:/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/esbuild@0.25.9/node_modules/esbuild/node_modules:/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/esbuild@0.25.9/node_modules:/mnt/c/Users/huawei/Documents/github/dbcube/orm/node_modules/.pnpm/node_modules:$NODE_PATH"
16
+ fi
17
+ if [ -x "$basedir/node" ]; then
18
+ exec "$basedir/node" "$basedir/../.pnpm/esbuild@0.25.9/node_modules/esbuild/bin/esbuild" "$@"
19
+ else
20
+ exec node "$basedir/../.pnpm/esbuild@0.25.9/node_modules/esbuild/bin/esbuild" "$@"
21
+ fi