ilana-orm 1.0.8 → 1.0.9
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/orm/CustomCasts.mjs +7 -0
- package/orm/MigrationRunner.js +23 -15
- package/package.json +7 -2
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// CustomCasts.mjs - ES Module wrapper
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const CustomCasts = require('./CustomCasts.js');
|
|
6
|
+
|
|
7
|
+
export const { MoneyCast, EncryptedCast, JsonCast, ArrayCast, DateCast } = CustomCasts;
|
package/orm/MigrationRunner.js
CHANGED
|
@@ -7,19 +7,27 @@ let config = {};
|
|
|
7
7
|
|
|
8
8
|
// Auto-load configuration on first import
|
|
9
9
|
(async function autoLoadConfig() {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const configPathJs = path.join(process.cwd(), 'ilana.config.js');
|
|
11
|
+
const configPathMjs = path.join(process.cwd(), 'ilana.config.mjs');
|
|
12
|
+
|
|
13
|
+
// Try .mjs first (ES modules)
|
|
14
|
+
if (fs.existsSync(configPathMjs)) {
|
|
15
|
+
try {
|
|
16
|
+
const configModule = await import(configPathMjs);
|
|
17
|
+
config = configModule.default || configModule;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error('Error loading ilana.config.mjs:', error.message);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// Try .js (CommonJS)
|
|
23
|
+
else if (fs.existsSync(configPathJs)) {
|
|
24
|
+
delete require.cache[configPathJs];
|
|
13
25
|
try {
|
|
14
|
-
config = require(
|
|
26
|
+
config = require(configPathJs) || {};
|
|
15
27
|
} catch (error) {
|
|
16
28
|
if (error.code === 'ERR_REQUIRE_ESM') {
|
|
17
|
-
|
|
18
|
-
const configModule = await import(configPath);
|
|
29
|
+
const configModule = await import(configPathJs);
|
|
19
30
|
config = configModule.default || configModule;
|
|
20
|
-
if (typeof config.configure === 'function') {
|
|
21
|
-
config.configure(config);
|
|
22
|
-
}
|
|
23
31
|
} else {
|
|
24
32
|
throw error;
|
|
25
33
|
}
|
|
@@ -347,7 +355,7 @@ class MigrationRunner {
|
|
|
347
355
|
|
|
348
356
|
if (isCreate || name.includes('create_')) {
|
|
349
357
|
return isTS ?
|
|
350
|
-
`import SchemaBuilder from 'ilana-orm
|
|
358
|
+
`import type { SchemaBuilder } from 'ilana-orm';
|
|
351
359
|
|
|
352
360
|
export default class ${className} {
|
|
353
361
|
// connection = 'mysql'; // Uncomment to use specific connection
|
|
@@ -364,7 +372,7 @@ export default class ${className} {
|
|
|
364
372
|
}
|
|
365
373
|
}
|
|
366
374
|
` :
|
|
367
|
-
`const SchemaBuilder = require('ilana-orm
|
|
375
|
+
`const { SchemaBuilder } = require('ilana-orm');
|
|
368
376
|
|
|
369
377
|
class ${className} {
|
|
370
378
|
// connection = 'mysql'; // Uncomment to use specific connection
|
|
@@ -385,7 +393,7 @@ module.exports = ${className};
|
|
|
385
393
|
`;
|
|
386
394
|
} else if (tableName) {
|
|
387
395
|
return isTS ?
|
|
388
|
-
`import SchemaBuilder from 'ilana-orm
|
|
396
|
+
`import type { SchemaBuilder } from 'ilana-orm';
|
|
389
397
|
|
|
390
398
|
export default class ${className} {
|
|
391
399
|
// connection = 'mysql'; // Uncomment to use specific connection
|
|
@@ -405,7 +413,7 @@ export default class ${className} {
|
|
|
405
413
|
}
|
|
406
414
|
}
|
|
407
415
|
` :
|
|
408
|
-
`const SchemaBuilder = require('ilana-orm
|
|
416
|
+
`const { SchemaBuilder } = require('ilana-orm');
|
|
409
417
|
|
|
410
418
|
class ${className} {
|
|
411
419
|
// connection = 'mysql'; // Uncomment to use specific connection
|
|
@@ -430,7 +438,7 @@ module.exports = ${className};
|
|
|
430
438
|
}
|
|
431
439
|
|
|
432
440
|
return isTS ?
|
|
433
|
-
`import SchemaBuilder from 'ilana-orm
|
|
441
|
+
`import type { SchemaBuilder } from 'ilana-orm';
|
|
434
442
|
|
|
435
443
|
export default class ${className} {
|
|
436
444
|
// connection = 'mysql'; // Uncomment to use specific connection
|
|
@@ -444,7 +452,7 @@ export default class ${className} {
|
|
|
444
452
|
}
|
|
445
453
|
}
|
|
446
454
|
` :
|
|
447
|
-
`const SchemaBuilder = require('ilana-orm
|
|
455
|
+
`const { SchemaBuilder } = require('ilana-orm');
|
|
448
456
|
|
|
449
457
|
class ${className} {
|
|
450
458
|
// connection = 'mysql'; // Uncomment to use specific connection
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ilana-orm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "A fully-featured, Eloquent-style ORM for Node.js with TypeScript support",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -25,6 +25,11 @@
|
|
|
25
25
|
"require": "./orm/Collection.js",
|
|
26
26
|
"types": "./orm/Collection.d.ts"
|
|
27
27
|
},
|
|
28
|
+
"./orm/CustomCasts": {
|
|
29
|
+
"import": "./orm/CustomCasts.mjs",
|
|
30
|
+
"require": "./orm/CustomCasts.js",
|
|
31
|
+
"types": "./orm/CustomCasts.d.ts"
|
|
32
|
+
},
|
|
28
33
|
"./database/connection": {
|
|
29
34
|
"import": "./database/connection.mjs",
|
|
30
35
|
"require": "./database/connection.js",
|
|
@@ -105,4 +110,4 @@
|
|
|
105
110
|
"engines": {
|
|
106
111
|
"node": ">=16.0.0"
|
|
107
112
|
}
|
|
108
|
-
}
|
|
113
|
+
}
|