@cheetah.js/orm 0.1.62 → 0.1.63

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.
@@ -237,22 +237,43 @@ let OrmService = class OrmService {
237
237
  });
238
238
  }
239
239
  async onInit(customConfig = {}) {
240
- const configFile = globby.sync('cheetah.config.ts', { absolute: true });
241
- if (configFile.length === 0) {
242
- console.log('No config file found!');
243
- return;
240
+ const hasCustomConfig = Object.keys(customConfig).length > 0;
241
+ let config = null;
242
+ let setConfig;
243
+ if (!hasCustomConfig) {
244
+ const configFile = globby.sync('cheetah.config.ts', { absolute: true });
245
+ if (configFile.length === 0) {
246
+ console.log('No config file found!');
247
+ return;
248
+ }
249
+ config = await Promise.resolve(`${configFile[0]}`).then(s => __importStar(require(s)));
250
+ setConfig = config.default;
251
+ }
252
+ else {
253
+ setConfig = customConfig;
244
254
  }
245
- const config = await Promise.resolve(`${configFile[0]}`).then(s => __importStar(require(s)));
246
- const setConfig = Object.keys(customConfig).length > 0 ? customConfig : config.default;
247
255
  this.orm.setConnection(setConfig);
248
256
  await this.orm.connect();
249
- if (typeof config.default.entities === 'string') {
257
+ if (config && typeof config.default.entities === 'string') {
250
258
  const files = globby.sync([config.default.entities, '!node_modules'], { gitignore: true, absolute: true });
251
259
  for (const file of files) {
252
260
  await Promise.resolve(`${file}`).then(s => __importStar(require(s)));
253
261
  }
254
262
  }
255
- const entities = core_1.Metadata.get(constants_1.ENTITIES, Reflect);
263
+ let entities = core_1.Metadata.get(constants_1.ENTITIES, Reflect);
264
+ if (!entities) {
265
+ const entityPaths = this.getSourceFilePaths();
266
+ const entityFiles = globby.sync(entityPaths.filter(path => path.includes('.entity.') || path.includes('entities/')));
267
+ for (const file of entityFiles) {
268
+ try {
269
+ await Promise.resolve(`${file}`).then(s => __importStar(require(s)));
270
+ }
271
+ catch (error) {
272
+ console.warn(`Failed to import entity file ${file}:`, error);
273
+ }
274
+ }
275
+ entities = core_1.Metadata.get(constants_1.ENTITIES, Reflect);
276
+ }
256
277
  if (!entities) {
257
278
  console.log('No entities found!');
258
279
  return;
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
37
  };
@@ -43,6 +76,12 @@ function selectLogger(options) {
43
76
  }
44
77
  async function initializeOrm(orm, options) {
45
78
  const storage = new entities_1.EntityStorage();
79
+ if (options.entityFile) {
80
+ const entityFiles = await (0, globby_1.default)(options.entityFile, { absolute: true });
81
+ for (const file of entityFiles) {
82
+ await Promise.resolve(`${file}`).then(s => __importStar(require(s)));
83
+ }
84
+ }
46
85
  const service = new orm_service_1.OrmService(orm, storage, options.entityFile);
47
86
  const connection = resolveConnection(options.connection);
48
87
  await service.onInit(connection);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cheetah.js/orm",
3
- "version": "0.1.62",
3
+ "version": "0.1.63",
4
4
  "description": "A simple ORM for Cheetah.js",
5
5
  "type": "commonjs",
6
6
  "main": "dist/index.js",
@@ -55,5 +55,5 @@
55
55
  "bun",
56
56
  "value-object"
57
57
  ],
58
- "gitHead": "d3d5471df38cbb87399a11df1e59945085ab2288"
58
+ "gitHead": "b81c351dba661381729aa4aa04985276596f4ac9"
59
59
  }