@cheetah.js/orm 0.1.135 → 0.1.136
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.
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { EntityName } from '../driver/driver.interface';
|
|
2
|
+
import { PropertyOptions } from './property.decorator';
|
|
2
3
|
export declare function OneToMany<T>(entity: () => EntityName<T>, fkKey: (string & keyof T) | ((e: T) => any)): PropertyDecorator;
|
|
3
|
-
|
|
4
|
+
type ManyToOneOptions = Partial<PropertyOptions>;
|
|
5
|
+
export declare function ManyToOne<T>(entityOrOptions?: (() => EntityName<T>) | ManyToOneOptions, maybeOptions?: ManyToOneOptions): PropertyDecorator;
|
|
6
|
+
export {};
|
|
@@ -5,6 +5,7 @@ exports.ManyToOne = ManyToOne;
|
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
6
|
const core_1 = require("@cheetah.js/core");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
|
+
const index_decorator_1 = require("./index.decorator");
|
|
8
9
|
function OneToMany(entity, fkKey) {
|
|
9
10
|
return (target, propertyKey) => {
|
|
10
11
|
const existing = core_1.Metadata.get(constants_1.PROPERTIES_RELATIONS, target.constructor) || [];
|
|
@@ -15,14 +16,27 @@ function OneToMany(entity, fkKey) {
|
|
|
15
16
|
core_1.Metadata.set(constants_1.PROPERTIES_RELATIONS, existing, target.constructor);
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
|
-
function ManyToOne(
|
|
19
|
+
function ManyToOne(entityOrOptions, maybeOptions) {
|
|
19
20
|
return (target, propertyKey) => {
|
|
20
21
|
const existing = core_1.Metadata.get(constants_1.PROPERTIES_RELATIONS, target.constructor) || [];
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
options
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const hasEntity = typeof entityOrOptions === 'function';
|
|
23
|
+
const entity = hasEntity ? entityOrOptions : undefined;
|
|
24
|
+
const options = (!hasEntity ? entityOrOptions : maybeOptions) || {};
|
|
25
|
+
const columnName = options.columnName || `${(0, utils_1.toSnakeCase)(propertyKey)}_id`;
|
|
26
|
+
const relationOptions = {
|
|
27
|
+
relation: 'many-to-one',
|
|
28
|
+
propertyKey,
|
|
29
|
+
isRelation: true,
|
|
30
|
+
entity: entity || '__AUTO_DETECT__',
|
|
31
|
+
type: core_1.Metadata.getType(target, propertyKey),
|
|
32
|
+
originalEntity: target.constructor,
|
|
33
|
+
columnName,
|
|
34
|
+
...options,
|
|
35
|
+
};
|
|
36
|
+
if (options.index) {
|
|
37
|
+
(0, index_decorator_1.Index)({ properties: [propertyKey] })(target, propertyKey);
|
|
38
|
+
}
|
|
39
|
+
existing.push(relationOptions);
|
|
26
40
|
core_1.Metadata.set(constants_1.PROPERTIES_RELATIONS, existing, target.constructor);
|
|
27
41
|
};
|
|
28
42
|
}
|
package/dist/orm.service.js
CHANGED
|
@@ -41,6 +41,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
41
41
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
42
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
43
|
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
44
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
48
|
exports.OrmService = void 0;
|
|
46
49
|
const core_1 = require("@cheetah.js/core");
|
|
@@ -49,6 +52,7 @@ const constants_1 = require("./constants");
|
|
|
49
52
|
const ts_morph_1 = require("ts-morph");
|
|
50
53
|
const orm_1 = require("./orm");
|
|
51
54
|
const globby = __importStar(require("globby"));
|
|
55
|
+
const path_1 = __importDefault(require("path"));
|
|
52
56
|
let OrmService = class OrmService {
|
|
53
57
|
constructor(orm, storage, entityFile) {
|
|
54
58
|
this.orm = orm;
|
|
@@ -315,19 +319,17 @@ let OrmService = class OrmService {
|
|
|
315
319
|
}
|
|
316
320
|
}
|
|
317
321
|
getSourceFilePaths() {
|
|
318
|
-
const projectRoot = process.cwd();
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
// Filtra os arquivos pelo padrão de nomenclatura
|
|
330
|
-
return getAllFiles(projectRoot);
|
|
322
|
+
const projectRoot = process.cwd();
|
|
323
|
+
const patterns = ['**/*.ts', '**/*.js', '!**/node_modules/**'];
|
|
324
|
+
try {
|
|
325
|
+
return globby
|
|
326
|
+
.sync(patterns, { cwd: projectRoot, gitignore: true, absolute: false })
|
|
327
|
+
.map((filePath) => path_1.default.resolve(projectRoot, filePath));
|
|
328
|
+
}
|
|
329
|
+
catch (error) {
|
|
330
|
+
console.error('Erro ao obter arquivos:', error);
|
|
331
|
+
return [];
|
|
332
|
+
}
|
|
331
333
|
}
|
|
332
334
|
};
|
|
333
335
|
exports.OrmService = OrmService;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cheetah.js/orm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.136",
|
|
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": "
|
|
58
|
+
"gitHead": "2109d17dd39ca357d6a0b48bf0b7bb08270fe8b6"
|
|
59
59
|
}
|