@cheetah.js/orm 0.1.47 → 0.1.48
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/SqlBuilder.js +24 -20
- package/dist/common/email.vo.js +6 -2
- package/dist/common/uuid.js +6 -2
- package/dist/common/value-object.js +13 -9
- package/dist/constants.js +8 -5
- package/dist/decorators/entity.decorator.js +8 -5
- package/dist/decorators/enum.decorator.js +6 -3
- package/dist/decorators/event-hook.decorator.js +19 -13
- package/dist/decorators/index.decorator.js +7 -4
- package/dist/decorators/one-many.decorator.js +17 -13
- package/dist/decorators/primary-key.decorator.js +6 -3
- package/dist/decorators/property.decorator.js +21 -18
- package/dist/domain/base-entity.js +10 -6
- package/dist/domain/collection.js +7 -2
- package/dist/domain/entities.js +11 -8
- package/dist/domain/reference.js +5 -1
- package/dist/driver/bun-driver.base.js +7 -3
- package/dist/driver/bun-mysql.driver.js +6 -2
- package/dist/driver/bun-pg.driver.js +6 -2
- package/dist/driver/driver.interface.js +2 -1
- package/dist/entry.js +8 -5
- package/dist/index.js +39 -21
- package/dist/orm.js +10 -7
- package/dist/orm.service.js +58 -22
- package/dist/query/model-transformer.js +8 -4
- package/dist/query/sql-column-manager.js +5 -1
- package/dist/query/sql-condition-builder.js +8 -4
- package/dist/query/sql-join-manager.js +5 -1
- package/dist/repository/Repository.js +5 -1
- package/dist/utils/value-processor.js +12 -8
- package/dist/utils.js +8 -3
- package/package.json +8 -9
package/dist/SqlBuilder.js
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SqlBuilder = void 0;
|
|
4
|
+
const entities_1 = require("./domain/entities");
|
|
5
|
+
const orm_1 = require("./orm");
|
|
6
|
+
const value_processor_1 = require("./utils/value-processor");
|
|
7
|
+
const sql_condition_builder_1 = require("./query/sql-condition-builder");
|
|
8
|
+
const model_transformer_1 = require("./query/model-transformer");
|
|
9
|
+
const sql_column_manager_1 = require("./query/sql-column-manager");
|
|
10
|
+
const sql_join_manager_1 = require("./query/sql-join-manager");
|
|
11
|
+
class SqlBuilder {
|
|
9
12
|
constructor(model) {
|
|
10
13
|
this.statements = {};
|
|
11
14
|
this.aliases = new Set();
|
|
12
15
|
this.updatedColumns = [];
|
|
13
16
|
this.originalColumns = [];
|
|
14
|
-
const orm = Orm.getInstance();
|
|
17
|
+
const orm = orm_1.Orm.getInstance();
|
|
15
18
|
this.driver = orm.driverInstance;
|
|
16
19
|
this.logger = orm.logger;
|
|
17
|
-
this.entityStorage = EntityStorage.getInstance();
|
|
20
|
+
this.entityStorage = entities_1.EntityStorage.getInstance();
|
|
18
21
|
this.getEntity(model);
|
|
19
22
|
this.statements.hooks = this.entity.hooks;
|
|
20
|
-
this.modelTransformer = new ModelTransformer(this.entityStorage);
|
|
21
|
-
this.columnManager = new SqlColumnManager(this.entityStorage, this.statements, this.entity);
|
|
23
|
+
this.modelTransformer = new model_transformer_1.ModelTransformer(this.entityStorage);
|
|
24
|
+
this.columnManager = new sql_column_manager_1.SqlColumnManager(this.entityStorage, this.statements, this.entity);
|
|
22
25
|
const applyJoinWrapper = (relationship, value, alias) => {
|
|
23
26
|
return this.joinManager.applyJoin(relationship, value, alias);
|
|
24
27
|
};
|
|
25
|
-
this.conditionBuilder = new SqlConditionBuilder(this.entityStorage, applyJoinWrapper, this.statements);
|
|
26
|
-
this.joinManager = new SqlJoinManager(this.entityStorage, this.statements, this.entity, this.model, this.driver, this.logger, this.conditionBuilder, this.columnManager, this.modelTransformer, () => this.originalColumns, this.getAlias.bind(this));
|
|
28
|
+
this.conditionBuilder = new sql_condition_builder_1.SqlConditionBuilder(this.entityStorage, applyJoinWrapper, this.statements);
|
|
29
|
+
this.joinManager = new sql_join_manager_1.SqlJoinManager(this.entityStorage, this.statements, this.entity, this.model, this.driver, this.logger, this.conditionBuilder, this.columnManager, this.modelTransformer, () => this.originalColumns, this.getAlias.bind(this));
|
|
27
30
|
}
|
|
28
31
|
select(columns) {
|
|
29
32
|
const tableName = this.entity.tableName || this.model.name.toLowerCase();
|
|
@@ -45,9 +48,9 @@ export class SqlBuilder {
|
|
|
45
48
|
}
|
|
46
49
|
insert(values) {
|
|
47
50
|
const { tableName, schema } = this.getTableName();
|
|
48
|
-
const processedValues = ValueProcessor.processForInsert(values, this.entity);
|
|
51
|
+
const processedValues = value_processor_1.ValueProcessor.processForInsert(values, this.entity);
|
|
49
52
|
this.statements.statement = 'insert';
|
|
50
|
-
this.statements.instance = ValueProcessor.createInstance(processedValues, this.model, 'insert');
|
|
53
|
+
this.statements.instance = value_processor_1.ValueProcessor.createInstance(processedValues, this.model, 'insert');
|
|
51
54
|
this.statements.alias = this.getAlias(tableName);
|
|
52
55
|
this.statements.table = `"${schema}"."${tableName}"`;
|
|
53
56
|
this.statements.values = this.withUpdatedValues(this.withDefaultValues(processedValues, this.entity), this.entity);
|
|
@@ -56,12 +59,12 @@ export class SqlBuilder {
|
|
|
56
59
|
}
|
|
57
60
|
update(values) {
|
|
58
61
|
const { tableName, schema } = this.getTableName();
|
|
59
|
-
const processedValues = ValueProcessor.processForUpdate(values, this.entity);
|
|
62
|
+
const processedValues = value_processor_1.ValueProcessor.processForUpdate(values, this.entity);
|
|
60
63
|
this.statements.statement = 'update';
|
|
61
64
|
this.statements.alias = this.getAlias(tableName);
|
|
62
65
|
this.statements.table = `${schema}.${tableName}`;
|
|
63
66
|
this.statements.values = this.withUpdatedValues(processedValues, this.entity);
|
|
64
|
-
this.statements.instance = ValueProcessor.createInstance(processedValues, this.model, 'update');
|
|
67
|
+
this.statements.instance = value_processor_1.ValueProcessor.createInstance(processedValues, this.model, 'update');
|
|
65
68
|
return this;
|
|
66
69
|
}
|
|
67
70
|
where(where) {
|
|
@@ -74,7 +77,7 @@ export class SqlBuilder {
|
|
|
74
77
|
newWhere[key] = where[key];
|
|
75
78
|
continue;
|
|
76
79
|
}
|
|
77
|
-
newWhere[ValueProcessor.getColumnName(key, this.entity)] = where[key];
|
|
80
|
+
newWhere[value_processor_1.ValueProcessor.getColumnName(key, this.entity)] = where[key];
|
|
78
81
|
}
|
|
79
82
|
where = newWhere;
|
|
80
83
|
this.statements.where = this.conditionBuilder.build(where, this.statements.alias, this.model);
|
|
@@ -208,7 +211,7 @@ export class SqlBuilder {
|
|
|
208
211
|
if (parentKey) {
|
|
209
212
|
return [`${this.columnManager.discoverAlias(fullKey, true)} ${obj[key]}`];
|
|
210
213
|
}
|
|
211
|
-
const columnName = ValueProcessor.getColumnName(key, this.entity);
|
|
214
|
+
const columnName = value_processor_1.ValueProcessor.getColumnName(key, this.entity);
|
|
212
215
|
return [`${this.columnManager.discoverAlias(columnName, true)} ${obj[key]}`];
|
|
213
216
|
}
|
|
214
217
|
isNestedObject(value) {
|
|
@@ -330,3 +333,4 @@ export class SqlBuilder {
|
|
|
330
333
|
}
|
|
331
334
|
}
|
|
332
335
|
}
|
|
336
|
+
exports.SqlBuilder = SqlBuilder;
|
package/dist/common/email.vo.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Email = void 0;
|
|
4
|
+
const value_object_1 = require("./value-object");
|
|
2
5
|
const REGEX = /^[a-z0-9.]+@[a-z0-9]+\.[a-z]+(\.[a-z]+)?$/i;
|
|
3
|
-
|
|
6
|
+
class Email extends value_object_1.ValueObject {
|
|
4
7
|
validate(value) {
|
|
5
8
|
return REGEX.test(value);
|
|
6
9
|
}
|
|
7
10
|
}
|
|
11
|
+
exports.Email = Email;
|
package/dist/common/uuid.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Uuid = void 0;
|
|
4
|
+
const value_object_1 = require("./value-object");
|
|
5
|
+
class Uuid extends value_object_1.ValueObject {
|
|
3
6
|
validate(value) {
|
|
4
7
|
return /^[a-f\d]{8}(-[a-f\d]{4}){4}[a-f\d]{8}$/i.test(value);
|
|
5
8
|
}
|
|
6
9
|
}
|
|
10
|
+
exports.Uuid = Uuid;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValueObject = void 0;
|
|
4
|
+
const core_1 = require("@cheetah.js/core");
|
|
5
|
+
class ValueObject {
|
|
3
6
|
constructor(value, skipValidation = false) {
|
|
4
7
|
if (!skipValidation && (!this.validate(value) || !this.validateDatabase(value))) {
|
|
5
|
-
throw new HttpException(`Invalid value for ${this.constructor.name}`, 400);
|
|
8
|
+
throw new core_1.HttpException(`Invalid value for ${this.constructor.name}`, 400);
|
|
6
9
|
}
|
|
7
10
|
this.setValue(value);
|
|
8
11
|
}
|
|
@@ -64,32 +67,33 @@ export class ValueObject {
|
|
|
64
67
|
validateDatabase(value) {
|
|
65
68
|
if (typeof value === "string") {
|
|
66
69
|
if (this.max !== undefined && value.length > this.max) {
|
|
67
|
-
throw new HttpException(`Value exceeds maximum length of ${this.max}`, 400);
|
|
70
|
+
throw new core_1.HttpException(`Value exceeds maximum length of ${this.max}`, 400);
|
|
68
71
|
}
|
|
69
72
|
if (this.min !== undefined && value.length < this.min) {
|
|
70
|
-
throw new HttpException(`Value is less than minimum length of ${this.min}`, 400);
|
|
73
|
+
throw new core_1.HttpException(`Value is less than minimum length of ${this.min}`, 400);
|
|
71
74
|
}
|
|
72
75
|
}
|
|
73
76
|
else if (typeof value === "number") {
|
|
74
77
|
if (this.max !== undefined && value > this.max) {
|
|
75
|
-
throw new HttpException(`Value exceeds maximum value of ${this.max}`, 400);
|
|
78
|
+
throw new core_1.HttpException(`Value exceeds maximum value of ${this.max}`, 400);
|
|
76
79
|
}
|
|
77
80
|
if (this.min !== undefined && value < this.min) {
|
|
78
|
-
throw new HttpException(`Value is less than minimum value of ${this.min}`, 400);
|
|
81
|
+
throw new core_1.HttpException(`Value is less than minimum value of ${this.min}`, 400);
|
|
79
82
|
}
|
|
80
83
|
if (this.precision !== undefined) {
|
|
81
84
|
const totalDigits = value.toString().replace(".", "").length;
|
|
82
85
|
if (totalDigits > this.precision) {
|
|
83
|
-
throw new HttpException(`Value exceeds precision of ${this.precision}`, 400);
|
|
86
|
+
throw new core_1.HttpException(`Value exceeds precision of ${this.precision}`, 400);
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
if (this.scale !== undefined) {
|
|
87
90
|
const decimalDigits = (value.toString().split(".")[1] || "").length;
|
|
88
91
|
if (decimalDigits > this.scale) {
|
|
89
|
-
throw new HttpException(`Value exceeds scale of ${this.scale}`, 400);
|
|
92
|
+
throw new core_1.HttpException(`Value exceeds scale of ${this.scale}`, 400);
|
|
90
93
|
}
|
|
91
94
|
}
|
|
92
95
|
}
|
|
93
96
|
return true;
|
|
94
97
|
}
|
|
95
98
|
}
|
|
99
|
+
exports.ValueObject = ValueObject;
|
package/dist/constants.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EVENTS_METADATA = exports.PROPERTIES_RELATIONS = exports.PROPERTIES_METADATA = exports.PROPERTIES = exports.ENTITIES = void 0;
|
|
4
|
+
exports.ENTITIES = 'cheetah:entities';
|
|
5
|
+
exports.PROPERTIES = 'cheetah:properties';
|
|
6
|
+
exports.PROPERTIES_METADATA = 'cheetah:properties:metadata';
|
|
7
|
+
exports.PROPERTIES_RELATIONS = 'cheetah:properties:relations';
|
|
8
|
+
exports.EVENTS_METADATA = 'cheetah:events:metadata';
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Entity = Entity;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const core_1 = require("@cheetah.js/core");
|
|
6
|
+
function Entity(options) {
|
|
4
7
|
return (target) => {
|
|
5
|
-
const entities = Metadata.get(ENTITIES, Reflect) || [];
|
|
8
|
+
const entities = core_1.Metadata.get(constants_1.ENTITIES, Reflect) || [];
|
|
6
9
|
entities.push({ target, options });
|
|
7
|
-
Metadata.set(ENTITIES, entities, Reflect);
|
|
10
|
+
core_1.Metadata.set(constants_1.ENTITIES, entities, Reflect);
|
|
8
11
|
};
|
|
9
12
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Enum = Enum;
|
|
4
|
+
const property_decorator_1 = require("./property.decorator");
|
|
5
|
+
function Enum(options) {
|
|
3
6
|
const isEnum = true;
|
|
4
7
|
//@ts-ignore
|
|
5
8
|
let enumItems = typeof options === 'function' ? options() : (typeof options.items === 'function' ? options.items() : options.items);
|
|
6
9
|
if (typeof enumItems === 'object') {
|
|
7
10
|
enumItems = Object.keys(enumItems).map(key => enumItems[key]);
|
|
8
11
|
}
|
|
9
|
-
return Property({ ...options, isEnum, enumItems, dbType: 'enum' });
|
|
12
|
+
return (0, property_decorator_1.Property)({ ...options, isEnum, enumItems, dbType: 'enum' });
|
|
10
13
|
}
|
|
@@ -1,25 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BeforeCreate = BeforeCreate;
|
|
4
|
+
exports.AfterCreate = AfterCreate;
|
|
5
|
+
exports.BeforeUpdate = BeforeUpdate;
|
|
6
|
+
exports.AfterUpdate = AfterUpdate;
|
|
7
|
+
const constants_1 = require("../constants");
|
|
8
|
+
function BeforeCreate() {
|
|
3
9
|
return function (target, propertyName) {
|
|
4
|
-
const metadata = Reflect.getMetadata(EVENTS_METADATA, target.constructor) || [];
|
|
5
|
-
Reflect.defineMetadata(EVENTS_METADATA, [...metadata, { type: 'beforeCreate', propertyName }], target.constructor);
|
|
10
|
+
const metadata = Reflect.getMetadata(constants_1.EVENTS_METADATA, target.constructor) || [];
|
|
11
|
+
Reflect.defineMetadata(constants_1.EVENTS_METADATA, [...metadata, { type: 'beforeCreate', propertyName }], target.constructor);
|
|
6
12
|
};
|
|
7
13
|
}
|
|
8
|
-
|
|
14
|
+
function AfterCreate() {
|
|
9
15
|
return function (target, propertyName) {
|
|
10
|
-
const metadata = Reflect.getMetadata(EVENTS_METADATA, target.constructor) || [];
|
|
11
|
-
Reflect.defineMetadata(EVENTS_METADATA, [...metadata, { type: 'afterCreate', propertyName }], target.constructor);
|
|
16
|
+
const metadata = Reflect.getMetadata(constants_1.EVENTS_METADATA, target.constructor) || [];
|
|
17
|
+
Reflect.defineMetadata(constants_1.EVENTS_METADATA, [...metadata, { type: 'afterCreate', propertyName }], target.constructor);
|
|
12
18
|
};
|
|
13
19
|
}
|
|
14
|
-
|
|
20
|
+
function BeforeUpdate() {
|
|
15
21
|
return function (target, propertyName) {
|
|
16
|
-
const metadata = Reflect.getMetadata(EVENTS_METADATA, target.constructor) || [];
|
|
17
|
-
Reflect.defineMetadata(EVENTS_METADATA, [...metadata, { type: 'beforeUpdate', propertyName }], target.constructor);
|
|
22
|
+
const metadata = Reflect.getMetadata(constants_1.EVENTS_METADATA, target.constructor) || [];
|
|
23
|
+
Reflect.defineMetadata(constants_1.EVENTS_METADATA, [...metadata, { type: 'beforeUpdate', propertyName }], target.constructor);
|
|
18
24
|
};
|
|
19
25
|
}
|
|
20
|
-
|
|
26
|
+
function AfterUpdate() {
|
|
21
27
|
return function (target, propertyName) {
|
|
22
|
-
const metadata = Reflect.getMetadata(EVENTS_METADATA, target.constructor) || [];
|
|
23
|
-
Reflect.defineMetadata(EVENTS_METADATA, [...metadata, { type: 'afterUpdate', propertyName }], target.constructor);
|
|
28
|
+
const metadata = Reflect.getMetadata(constants_1.EVENTS_METADATA, target.constructor) || [];
|
|
29
|
+
Reflect.defineMetadata(constants_1.EVENTS_METADATA, [...metadata, { type: 'afterUpdate', propertyName }], target.constructor);
|
|
24
30
|
};
|
|
25
31
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Index = Index;
|
|
4
|
+
const core_1 = require("@cheetah.js/core");
|
|
5
|
+
function Index(options) {
|
|
3
6
|
return (target, propertyKey) => {
|
|
4
|
-
const indexes = Metadata.get('indexes', target.constructor) || [];
|
|
7
|
+
const indexes = core_1.Metadata.get('indexes', target.constructor) || [];
|
|
5
8
|
let index;
|
|
6
9
|
if (options && options.properties) {
|
|
7
10
|
const properties = options.properties;
|
|
@@ -11,6 +14,6 @@ export function Index(options) {
|
|
|
11
14
|
index = { name: `${propertyKey}_index`, properties: [propertyKey] };
|
|
12
15
|
}
|
|
13
16
|
indexes.push(index);
|
|
14
|
-
Metadata.set('indexes', indexes, target.constructor);
|
|
17
|
+
core_1.Metadata.set('indexes', indexes, target.constructor);
|
|
15
18
|
};
|
|
16
19
|
}
|
|
@@ -1,23 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OneToMany = OneToMany;
|
|
4
|
+
exports.ManyToOne = ManyToOne;
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const core_1 = require("@cheetah.js/core");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
function OneToMany(entity, fkKey) {
|
|
5
9
|
return (target, propertyKey) => {
|
|
6
|
-
const existing = Metadata.get(PROPERTIES_RELATIONS, target.constructor) || [];
|
|
7
|
-
const options = { relation: 'one-to-many', propertyKey, isRelation: true, entity, fkKey, type: Metadata.getType(target, propertyKey), originalEntity: target.constructor };
|
|
8
|
-
options['columnName'] = `${toSnakeCase(propertyKey)}_id`;
|
|
10
|
+
const existing = core_1.Metadata.get(constants_1.PROPERTIES_RELATIONS, target.constructor) || [];
|
|
11
|
+
const options = { relation: 'one-to-many', propertyKey, isRelation: true, entity, fkKey, type: core_1.Metadata.getType(target, propertyKey), originalEntity: target.constructor };
|
|
12
|
+
options['columnName'] = `${(0, utils_1.toSnakeCase)(propertyKey)}_id`;
|
|
9
13
|
// @ts-ignore
|
|
10
14
|
existing.push(options);
|
|
11
|
-
Metadata.set(PROPERTIES_RELATIONS, existing, target.constructor);
|
|
15
|
+
core_1.Metadata.set(constants_1.PROPERTIES_RELATIONS, existing, target.constructor);
|
|
12
16
|
};
|
|
13
17
|
}
|
|
14
|
-
|
|
18
|
+
function ManyToOne(entity) {
|
|
15
19
|
return (target, propertyKey) => {
|
|
16
|
-
const existing = Metadata.get(PROPERTIES_RELATIONS, target.constructor) || [];
|
|
17
|
-
const options = { relation: 'many-to-one', propertyKey, isRelation: true, entity, type: Metadata.getType(target, propertyKey), originalEntity: target.constructor };
|
|
18
|
-
options['columnName'] = `${toSnakeCase(propertyKey)}_id`;
|
|
20
|
+
const existing = core_1.Metadata.get(constants_1.PROPERTIES_RELATIONS, target.constructor) || [];
|
|
21
|
+
const options = { relation: 'many-to-one', propertyKey, isRelation: true, entity, type: core_1.Metadata.getType(target, propertyKey), originalEntity: target.constructor };
|
|
22
|
+
options['columnName'] = `${(0, utils_1.toSnakeCase)(propertyKey)}_id`;
|
|
19
23
|
// @ts-ignore
|
|
20
24
|
existing.push(options);
|
|
21
|
-
Metadata.set(PROPERTIES_RELATIONS, existing, target.constructor);
|
|
25
|
+
core_1.Metadata.set(constants_1.PROPERTIES_RELATIONS, existing, target.constructor);
|
|
22
26
|
};
|
|
23
27
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PrimaryKey = PrimaryKey;
|
|
4
|
+
const property_decorator_1 = require("./property.decorator");
|
|
5
|
+
function PrimaryKey(options) {
|
|
3
6
|
const isPrimary = true;
|
|
4
|
-
return Property({ ...options, isPrimary });
|
|
7
|
+
return (0, property_decorator_1.Property)({ ...options, isPrimary });
|
|
5
8
|
}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Property = Property;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const core_1 = require("@cheetah.js/core");
|
|
7
|
+
const index_decorator_1 = require("./index.decorator");
|
|
8
|
+
const __1 = require("..");
|
|
9
|
+
function Property(options) {
|
|
7
10
|
return (target, propertyKey) => {
|
|
8
|
-
const properties = Metadata.get(PROPERTIES, target.constructor) || [];
|
|
9
|
-
const type = Metadata.getType(target, propertyKey);
|
|
10
|
-
const length = (options && options.length) || getDefaultLength(type.name);
|
|
11
|
+
const properties = core_1.Metadata.get(constants_1.PROPERTIES, target.constructor) || [];
|
|
12
|
+
const type = core_1.Metadata.getType(target, propertyKey);
|
|
13
|
+
const length = (options && options.length) || (0, utils_1.getDefaultLength)(type.name);
|
|
11
14
|
options = { length, ...options };
|
|
12
|
-
options["columnName"] = options?.columnName || toSnakeCase(propertyKey);
|
|
13
|
-
if (extendsFrom(ValueObject, type.prototype)) {
|
|
15
|
+
options["columnName"] = options?.columnName || (0, utils_1.toSnakeCase)(propertyKey);
|
|
16
|
+
if ((0, utils_1.extendsFrom)(__1.ValueObject, type.prototype)) {
|
|
14
17
|
let instance = new type(null, true).getDatabaseValues();
|
|
15
18
|
options["length"] = instance.max;
|
|
16
19
|
options["precision"] = instance.precision;
|
|
@@ -18,20 +21,20 @@ export function Property(options) {
|
|
|
18
21
|
instance = null; // Garbage collector
|
|
19
22
|
}
|
|
20
23
|
properties.push({ propertyKey, options });
|
|
21
|
-
Metadata.set(PROPERTIES, properties, target.constructor);
|
|
24
|
+
core_1.Metadata.set(constants_1.PROPERTIES, properties, target.constructor);
|
|
22
25
|
if (options.isPrimary) {
|
|
23
|
-
const indexes = Metadata.get("indexes", target.constructor) || [];
|
|
26
|
+
const indexes = core_1.Metadata.get("indexes", target.constructor) || [];
|
|
24
27
|
indexes.push({ name: `[TABLE]_pkey`, properties: [propertyKey] });
|
|
25
|
-
Metadata.set("indexes", indexes, target.constructor);
|
|
28
|
+
core_1.Metadata.set("indexes", indexes, target.constructor);
|
|
26
29
|
}
|
|
27
30
|
if (options.index) {
|
|
28
|
-
Index({ properties: [propertyKey] })(target, propertyKey);
|
|
31
|
+
(0, index_decorator_1.Index)({ properties: [propertyKey] })(target, propertyKey);
|
|
29
32
|
}
|
|
30
33
|
properties.forEach((property) => {
|
|
31
|
-
const types = Metadata.get(PROPERTIES_METADATA, target.constructor) || {};
|
|
32
|
-
const type = Metadata.getType(target, property.propertyKey);
|
|
34
|
+
const types = core_1.Metadata.get(constants_1.PROPERTIES_METADATA, target.constructor) || {};
|
|
35
|
+
const type = core_1.Metadata.getType(target, property.propertyKey);
|
|
33
36
|
types[property.propertyKey] = { type, options: property.options };
|
|
34
|
-
Metadata.set(PROPERTIES_METADATA, types, target.constructor);
|
|
37
|
+
core_1.Metadata.set(constants_1.PROPERTIES_METADATA, types, target.constructor);
|
|
35
38
|
});
|
|
36
39
|
};
|
|
37
40
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseEntity = void 0;
|
|
4
|
+
const SqlBuilder_1 = require("../SqlBuilder");
|
|
5
|
+
const entities_1 = require("./entities");
|
|
6
|
+
class BaseEntity {
|
|
4
7
|
constructor() {
|
|
5
8
|
this._oldValues = {};
|
|
6
9
|
this._changedValues = {};
|
|
@@ -28,14 +31,14 @@ export class BaseEntity {
|
|
|
28
31
|
* Gets current entity's Repository.
|
|
29
32
|
*/
|
|
30
33
|
static createQueryBuilder() {
|
|
31
|
-
return new SqlBuilder(this);
|
|
34
|
+
return new SqlBuilder_1.SqlBuilder(this);
|
|
32
35
|
}
|
|
33
36
|
/**
|
|
34
37
|
* Gets current entity's Repository.
|
|
35
38
|
*/
|
|
36
39
|
createQueryBuilder() {
|
|
37
40
|
// @ts-ignore
|
|
38
|
-
return new SqlBuilder(this.constructor);
|
|
41
|
+
return new SqlBuilder_1.SqlBuilder(this.constructor);
|
|
39
42
|
}
|
|
40
43
|
static async find(where, options) {
|
|
41
44
|
return this.createQueryBuilder()
|
|
@@ -110,7 +113,7 @@ export class BaseEntity {
|
|
|
110
113
|
}
|
|
111
114
|
toJSON() {
|
|
112
115
|
let data = {};
|
|
113
|
-
let storage = EntityStorage.getInstance();
|
|
116
|
+
let storage = entities_1.EntityStorage.getInstance();
|
|
114
117
|
let entity = storage.get(this.constructor);
|
|
115
118
|
let allProperties = new Map(Object.entries(entity.properties).map(([key, value]) => [key, value]));
|
|
116
119
|
for (const key in this) {
|
|
@@ -129,3 +132,4 @@ export class BaseEntity {
|
|
|
129
132
|
return data;
|
|
130
133
|
}
|
|
131
134
|
}
|
|
135
|
+
exports.BaseEntity = BaseEntity;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Collection = exports.ArrayCollection = void 0;
|
|
4
|
+
class ArrayCollection {
|
|
2
5
|
getItems() {
|
|
3
6
|
return [];
|
|
4
7
|
}
|
|
5
8
|
}
|
|
6
|
-
|
|
9
|
+
exports.ArrayCollection = ArrayCollection;
|
|
10
|
+
class Collection extends ArrayCollection {
|
|
7
11
|
constructor(owner, items, initialized = true) {
|
|
8
12
|
super();
|
|
9
13
|
}
|
|
10
14
|
}
|
|
15
|
+
exports.Collection = Collection;
|
package/dist/domain/entities.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,16 +9,18 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
10
|
};
|
|
10
11
|
var EntityStorage_1;
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.EntityStorage = void 0;
|
|
14
|
+
const core_1 = require("@cheetah.js/core");
|
|
15
|
+
const utils_1 = require("../utils");
|
|
13
16
|
let EntityStorage = EntityStorage_1 = class EntityStorage {
|
|
14
17
|
constructor() {
|
|
15
18
|
this.entities = new Map();
|
|
16
19
|
EntityStorage_1.instance = this;
|
|
17
20
|
}
|
|
18
21
|
add(entity, properties, relations, hooks) {
|
|
19
|
-
const entityName = entity.options?.tableName || toSnakeCase(entity.target.name);
|
|
20
|
-
const indexes = Metadata.get("indexes", entity.target) || [];
|
|
22
|
+
const entityName = entity.options?.tableName || (0, utils_1.toSnakeCase)(entity.target.name);
|
|
23
|
+
const indexes = core_1.Metadata.get("indexes", entity.target) || [];
|
|
21
24
|
this.entities.set(entity.target, {
|
|
22
25
|
properties: properties,
|
|
23
26
|
hideProperties: Object.entries(properties)
|
|
@@ -79,7 +82,7 @@ let EntityStorage = EntityStorage_1 = class EntityStorage {
|
|
|
79
82
|
type,
|
|
80
83
|
nullable: relation.nullable,
|
|
81
84
|
unique: relation.unique,
|
|
82
|
-
length: relation.length || getDefaultLength(type),
|
|
85
|
+
length: relation.length || (0, utils_1.getDefaultLength)(type),
|
|
83
86
|
default: relation.default,
|
|
84
87
|
autoIncrement: relation.autoIncrement,
|
|
85
88
|
primary: relation.isPrimary,
|
|
@@ -148,8 +151,8 @@ let EntityStorage = EntityStorage_1 = class EntityStorage {
|
|
|
148
151
|
return match ? match.groups.propriedade : "";
|
|
149
152
|
}
|
|
150
153
|
};
|
|
151
|
-
EntityStorage =
|
|
152
|
-
|
|
154
|
+
exports.EntityStorage = EntityStorage;
|
|
155
|
+
exports.EntityStorage = EntityStorage = EntityStorage_1 = __decorate([
|
|
156
|
+
(0, core_1.Service)(),
|
|
153
157
|
__metadata("design:paramtypes", [])
|
|
154
158
|
], EntityStorage);
|
|
155
|
-
export { EntityStorage };
|
package/dist/domain/reference.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Reference = void 0;
|
|
4
|
+
class Reference {
|
|
2
5
|
constructor(entity) {
|
|
3
6
|
this.entity = entity;
|
|
4
7
|
console.log('Reference constructor');
|
|
5
8
|
}
|
|
6
9
|
}
|
|
10
|
+
exports.Reference = Reference;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BunDriverBase = void 0;
|
|
4
|
+
const bun_1 = require("bun");
|
|
5
|
+
class BunDriverBase {
|
|
3
6
|
constructor(options) {
|
|
4
7
|
this.connectionString = this.buildConnectionString(options);
|
|
5
8
|
}
|
|
@@ -15,7 +18,7 @@ export class BunDriverBase {
|
|
|
15
18
|
if (this.sql) {
|
|
16
19
|
return;
|
|
17
20
|
}
|
|
18
|
-
this.sql = new SQL(this.connectionString);
|
|
21
|
+
this.sql = new bun_1.SQL(this.connectionString);
|
|
19
22
|
await this.validateConnection();
|
|
20
23
|
}
|
|
21
24
|
async validateConnection() {
|
|
@@ -216,3 +219,4 @@ export class BunDriverBase {
|
|
|
216
219
|
};
|
|
217
220
|
}
|
|
218
221
|
}
|
|
222
|
+
exports.BunDriverBase = BunDriverBase;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BunMysqlDriver = void 0;
|
|
4
|
+
const bun_driver_base_1 = require("./bun-driver.base");
|
|
5
|
+
class BunMysqlDriver extends bun_driver_base_1.BunDriverBase {
|
|
3
6
|
constructor(options) {
|
|
4
7
|
super(options);
|
|
5
8
|
this.dbType = 'mysql';
|
|
@@ -231,3 +234,4 @@ export class BunMysqlDriver extends BunDriverBase {
|
|
|
231
234
|
});
|
|
232
235
|
}
|
|
233
236
|
}
|
|
237
|
+
exports.BunMysqlDriver = BunMysqlDriver;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BunPgDriver = void 0;
|
|
4
|
+
const bun_driver_base_1 = require("./bun-driver.base");
|
|
5
|
+
class BunPgDriver extends bun_driver_base_1.BunDriverBase {
|
|
3
6
|
constructor(options) {
|
|
4
7
|
super(options);
|
|
5
8
|
this.dbType = 'postgres';
|
|
@@ -240,3 +243,4 @@ export class BunPgDriver extends BunDriverBase {
|
|
|
240
243
|
});
|
|
241
244
|
}
|
|
242
245
|
}
|
|
246
|
+
exports.BunPgDriver = BunPgDriver;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/entry.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CheetahOrm = void 0;
|
|
4
|
+
const core_1 = require("@cheetah.js/core");
|
|
5
|
+
const orm_1 = require("./orm");
|
|
6
|
+
const orm_service_1 = require("./orm.service");
|
|
7
|
+
const entities_1 = require("./domain/entities");
|
|
8
|
+
exports.CheetahOrm = new core_1.Cheetah({ exports: [orm_1.Orm, orm_service_1.OrmService, entities_1.EntityStorage] });
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.EntityStorage = void 0;
|
|
18
|
+
__exportStar(require("./decorators/entity.decorator"), exports);
|
|
19
|
+
__exportStar(require("./decorators/property.decorator"), exports);
|
|
20
|
+
__exportStar(require("./decorators/primary-key.decorator"), exports);
|
|
21
|
+
__exportStar(require("./decorators/one-many.decorator"), exports);
|
|
22
|
+
__exportStar(require("./decorators/index.decorator"), exports);
|
|
23
|
+
__exportStar(require("./decorators/event-hook.decorator"), exports);
|
|
24
|
+
__exportStar(require("./decorators/enum.decorator"), exports);
|
|
25
|
+
__exportStar(require("./orm"), exports);
|
|
26
|
+
__exportStar(require("./orm.service"), exports);
|
|
27
|
+
__exportStar(require("./domain/base-entity"), exports);
|
|
28
|
+
var entities_1 = require("./domain/entities");
|
|
29
|
+
Object.defineProperty(exports, "EntityStorage", { enumerable: true, get: function () { return entities_1.EntityStorage; } });
|
|
30
|
+
__exportStar(require("./driver/bun-pg.driver"), exports);
|
|
31
|
+
__exportStar(require("./driver/bun-mysql.driver"), exports);
|
|
32
|
+
__exportStar(require("./driver/bun-driver.base"), exports);
|
|
33
|
+
__exportStar(require("./utils"), exports);
|
|
34
|
+
__exportStar(require("./driver/driver.interface"), exports);
|
|
35
|
+
__exportStar(require("./entry"), exports);
|
|
36
|
+
__exportStar(require("./common/value-object"), exports);
|
|
37
|
+
__exportStar(require("./common/email.vo"), exports);
|
|
38
|
+
__exportStar(require("./common/uuid"), exports);
|
|
39
|
+
__exportStar(require("./repository/Repository"), exports);
|
package/dist/orm.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,8 +9,10 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
10
|
};
|
|
10
11
|
var Orm_1;
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.Orm = void 0;
|
|
14
|
+
const core_1 = require("@cheetah.js/core");
|
|
15
|
+
const SqlBuilder_1 = require("./SqlBuilder");
|
|
13
16
|
let Orm = Orm_1 = class Orm {
|
|
14
17
|
constructor(logger) {
|
|
15
18
|
this.logger = logger;
|
|
@@ -24,7 +27,7 @@ let Orm = Orm_1 = class Orm {
|
|
|
24
27
|
this.driverInstance = new this.connection.driver(connection);
|
|
25
28
|
}
|
|
26
29
|
createQueryBuilder(model) {
|
|
27
|
-
return new SqlBuilder(model);
|
|
30
|
+
return new SqlBuilder_1.SqlBuilder(model);
|
|
28
31
|
}
|
|
29
32
|
connect() {
|
|
30
33
|
return this.driverInstance.connect();
|
|
@@ -33,8 +36,8 @@ let Orm = Orm_1 = class Orm {
|
|
|
33
36
|
return this.driverInstance.disconnect();
|
|
34
37
|
}
|
|
35
38
|
};
|
|
36
|
-
Orm =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
exports.Orm = Orm;
|
|
40
|
+
exports.Orm = Orm = Orm_1 = __decorate([
|
|
41
|
+
(0, core_1.Service)(),
|
|
42
|
+
__metadata("design:paramtypes", [core_1.LoggerService])
|
|
39
43
|
], Orm);
|
|
40
|
-
export { Orm };
|
package/dist/orm.service.js
CHANGED
|
@@ -1,25 +1,61 @@
|
|
|
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
|
+
});
|
|
1
18
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
19
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
20
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
21
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
22
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
23
|
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
7
41
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
42
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
43
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.OrmService = void 0;
|
|
46
|
+
const core_1 = require("@cheetah.js/core");
|
|
47
|
+
const entities_1 = require("./domain/entities");
|
|
48
|
+
const constants_1 = require("./constants");
|
|
49
|
+
const ts_morph_1 = require("ts-morph");
|
|
50
|
+
const orm_1 = require("./orm");
|
|
51
|
+
const globby = __importStar(require("globby"));
|
|
16
52
|
let OrmService = class OrmService {
|
|
17
53
|
constructor(orm, storage, entityFile) {
|
|
18
54
|
this.orm = orm;
|
|
19
55
|
this.storage = storage;
|
|
20
56
|
this.allEntities = new Map();
|
|
21
57
|
console.log('Preparing entities...');
|
|
22
|
-
const files = new Project({ skipLoadingLibFiles: true }).addSourceFilesAtPaths(entityFile ?? this.getSourceFilePaths());
|
|
58
|
+
const files = new ts_morph_1.Project({ skipLoadingLibFiles: true }).addSourceFilesAtPaths(entityFile ?? this.getSourceFilePaths());
|
|
23
59
|
files.forEach(file => {
|
|
24
60
|
file.getClasses().forEach(classDeclaration => {
|
|
25
61
|
if (classDeclaration.getDecorator('Entity')) {
|
|
@@ -41,14 +77,14 @@ let OrmService = class OrmService {
|
|
|
41
77
|
if (initializer) {
|
|
42
78
|
const initializerKind = initializer.getKind();
|
|
43
79
|
switch (initializerKind) {
|
|
44
|
-
case SyntaxKind.StringLiteral:
|
|
80
|
+
case ts_morph_1.SyntaxKind.StringLiteral:
|
|
45
81
|
defaults[propertyName] = initializer.getText();
|
|
46
82
|
break;
|
|
47
|
-
case SyntaxKind.NumericLiteral:
|
|
83
|
+
case ts_morph_1.SyntaxKind.NumericLiteral:
|
|
48
84
|
defaults[propertyName] = parseFloat(initializer.getText());
|
|
49
85
|
break;
|
|
50
|
-
case SyntaxKind.NewExpression:
|
|
51
|
-
case SyntaxKind.CallExpression:
|
|
86
|
+
case ts_morph_1.SyntaxKind.NewExpression:
|
|
87
|
+
case ts_morph_1.SyntaxKind.CallExpression:
|
|
52
88
|
break;
|
|
53
89
|
default:
|
|
54
90
|
defaults[propertyName] = () => initializer.getText();
|
|
@@ -67,26 +103,26 @@ let OrmService = class OrmService {
|
|
|
67
103
|
console.log('No config file found!');
|
|
68
104
|
return;
|
|
69
105
|
}
|
|
70
|
-
const config = await
|
|
106
|
+
const config = await Promise.resolve(`${configFile[0]}`).then(s => __importStar(require(s)));
|
|
71
107
|
const setConfig = Object.keys(customConfig).length > 0 ? customConfig : config.default;
|
|
72
108
|
this.orm.setConnection(setConfig);
|
|
73
109
|
await this.orm.connect();
|
|
74
110
|
if (typeof config.default.entities === 'string') {
|
|
75
111
|
const files = globby.sync([config.default.entities, '!node_modules'], { gitignore: true, absolute: true });
|
|
76
112
|
for (const file of files) {
|
|
77
|
-
await
|
|
113
|
+
await Promise.resolve(`${file}`).then(s => __importStar(require(s)));
|
|
78
114
|
}
|
|
79
115
|
}
|
|
80
|
-
const entities = Metadata.get(ENTITIES, Reflect);
|
|
116
|
+
const entities = core_1.Metadata.get(constants_1.ENTITIES, Reflect);
|
|
81
117
|
if (!entities) {
|
|
82
118
|
console.log('No entities found!');
|
|
83
119
|
return;
|
|
84
120
|
}
|
|
85
121
|
for (const entity of entities) {
|
|
86
122
|
const nullableDefaultEntity = this.allEntities.get(entity.target.name);
|
|
87
|
-
const properties = Metadata.get(PROPERTIES_METADATA, entity.target);
|
|
88
|
-
const relationship = Metadata.get(PROPERTIES_RELATIONS, entity.target);
|
|
89
|
-
const hooks = Metadata.get(EVENTS_METADATA, entity.target);
|
|
123
|
+
const properties = core_1.Metadata.get(constants_1.PROPERTIES_METADATA, entity.target);
|
|
124
|
+
const relationship = core_1.Metadata.get(constants_1.PROPERTIES_RELATIONS, entity.target);
|
|
125
|
+
const hooks = core_1.Metadata.get(constants_1.EVENTS_METADATA, entity.target);
|
|
90
126
|
for (const property in properties) {
|
|
91
127
|
if (nullableDefaultEntity?.nullables.includes(property)) {
|
|
92
128
|
properties[property].options.nullable = true;
|
|
@@ -115,14 +151,14 @@ let OrmService = class OrmService {
|
|
|
115
151
|
return getAllFiles(projectRoot);
|
|
116
152
|
}
|
|
117
153
|
};
|
|
154
|
+
exports.OrmService = OrmService;
|
|
118
155
|
__decorate([
|
|
119
|
-
OnApplicationInit(),
|
|
156
|
+
(0, core_1.OnApplicationInit)(),
|
|
120
157
|
__metadata("design:type", Function),
|
|
121
158
|
__metadata("design:paramtypes", [Object]),
|
|
122
159
|
__metadata("design:returntype", Promise)
|
|
123
160
|
], OrmService.prototype, "onInit", null);
|
|
124
|
-
OrmService = __decorate([
|
|
125
|
-
Service(),
|
|
126
|
-
__metadata("design:paramtypes", [Orm, EntityStorage, String])
|
|
161
|
+
exports.OrmService = OrmService = __decorate([
|
|
162
|
+
(0, core_1.Service)(),
|
|
163
|
+
__metadata("design:paramtypes", [orm_1.Orm, entities_1.EntityStorage, String])
|
|
127
164
|
], OrmService);
|
|
128
|
-
export { OrmService };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModelTransformer = void 0;
|
|
4
|
+
const value_object_1 = require("../common/value-object");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
class ModelTransformer {
|
|
4
7
|
constructor(entityStorage) {
|
|
5
8
|
this.entityStorage = entityStorage;
|
|
6
9
|
}
|
|
@@ -79,7 +82,7 @@ export class ModelTransformer {
|
|
|
79
82
|
return { key: entry[0], property: entry[1] };
|
|
80
83
|
}
|
|
81
84
|
isValueObjectType(type) {
|
|
82
|
-
return extendsFrom(ValueObject, type?.prototype);
|
|
85
|
+
return (0, utils_1.extendsFrom)(value_object_1.ValueObject, type?.prototype);
|
|
83
86
|
}
|
|
84
87
|
linkJoinedEntities(statement, instanceMap, optionsMap) {
|
|
85
88
|
if (!statement.join) {
|
|
@@ -116,3 +119,4 @@ export class ModelTransformer {
|
|
|
116
119
|
return existingArray ? [...existingArray, newItem] : [newItem];
|
|
117
120
|
}
|
|
118
121
|
}
|
|
122
|
+
exports.ModelTransformer = ModelTransformer;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SqlColumnManager = void 0;
|
|
4
|
+
class SqlColumnManager {
|
|
2
5
|
constructor(entityStorage, statements, entity) {
|
|
3
6
|
this.entityStorage = entityStorage;
|
|
4
7
|
this.statements = statements;
|
|
@@ -122,3 +125,4 @@ export class SqlColumnManager {
|
|
|
122
125
|
return `${alias}."${columnName}" as ${alias}_${columnName}`;
|
|
123
126
|
}
|
|
124
127
|
}
|
|
128
|
+
exports.SqlColumnManager = SqlColumnManager;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SqlConditionBuilder = void 0;
|
|
4
|
+
const value_object_1 = require("../common/value-object");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
class SqlConditionBuilder {
|
|
4
7
|
constructor(entityStorage, applyJoinCallback, statements) {
|
|
5
8
|
this.entityStorage = entityStorage;
|
|
6
9
|
this.applyJoinCallback = applyJoinCallback;
|
|
@@ -128,7 +131,7 @@ export class SqlConditionBuilder {
|
|
|
128
131
|
return `(${conditions.join(` ${operator} `)})`;
|
|
129
132
|
}
|
|
130
133
|
extractValueFromValueObject(value) {
|
|
131
|
-
if (extendsFrom(ValueObject, value?.constructor?.prototype)) {
|
|
134
|
+
if ((0, utils_1.extendsFrom)(value_object_1.ValueObject, value?.constructor?.prototype)) {
|
|
132
135
|
return value.getValue();
|
|
133
136
|
}
|
|
134
137
|
return value;
|
|
@@ -158,3 +161,4 @@ export class SqlConditionBuilder {
|
|
|
158
161
|
}
|
|
159
162
|
}
|
|
160
163
|
}
|
|
164
|
+
exports.SqlConditionBuilder = SqlConditionBuilder;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SqlJoinManager = void 0;
|
|
4
|
+
class SqlJoinManager {
|
|
2
5
|
constructor(entityStorage, statements, entity, model, driver, logger, conditionBuilder, columnManager, modelTransformer, getOriginalColumnsCallback, getAliasCallback) {
|
|
3
6
|
this.entityStorage = entityStorage;
|
|
4
7
|
this.statements = statements;
|
|
@@ -222,3 +225,4 @@ export class SqlJoinManager {
|
|
|
222
225
|
return (typeof value === 'string') ? `'${value}'` : value;
|
|
223
226
|
}
|
|
224
227
|
}
|
|
228
|
+
exports.SqlJoinManager = SqlJoinManager;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Repository = void 0;
|
|
1
4
|
/**
|
|
2
5
|
* Generic Repository class for database operations.
|
|
3
6
|
* Provides type-safe methods for CRUD operations.
|
|
@@ -19,7 +22,7 @@
|
|
|
19
22
|
* }
|
|
20
23
|
* ```
|
|
21
24
|
*/
|
|
22
|
-
|
|
25
|
+
class Repository {
|
|
23
26
|
constructor(entityClass) {
|
|
24
27
|
this.entityClass = entityClass;
|
|
25
28
|
}
|
|
@@ -148,3 +151,4 @@ export class Repository {
|
|
|
148
151
|
return count > 0;
|
|
149
152
|
}
|
|
150
153
|
}
|
|
154
|
+
exports.Repository = Repository;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValueProcessor = void 0;
|
|
4
|
+
const value_object_1 = require("../common/value-object");
|
|
5
|
+
const base_entity_1 = require("../domain/base-entity");
|
|
6
|
+
const entities_1 = require("../domain/entities");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
class ValueProcessor {
|
|
6
9
|
static processForInsert(values, options) {
|
|
7
10
|
const newValue = {};
|
|
8
11
|
for (const value in values) {
|
|
@@ -47,7 +50,7 @@ export class ValueProcessor {
|
|
|
47
50
|
return property.options.columnName || propertyKey;
|
|
48
51
|
}
|
|
49
52
|
static createInstance(values, entity, moment = undefined) {
|
|
50
|
-
const entityStorage = EntityStorage.getInstance();
|
|
53
|
+
const entityStorage = entities_1.EntityStorage.getInstance();
|
|
51
54
|
const entityOptions = entityStorage.get(entity);
|
|
52
55
|
const instance = new entity();
|
|
53
56
|
if (!entityOptions) {
|
|
@@ -76,9 +79,10 @@ export class ValueProcessor {
|
|
|
76
79
|
return instance;
|
|
77
80
|
}
|
|
78
81
|
static isValueObject(value) {
|
|
79
|
-
return extendsFrom(ValueObject, value?.constructor?.prototype);
|
|
82
|
+
return (0, utils_1.extendsFrom)(value_object_1.ValueObject, value?.constructor?.prototype);
|
|
80
83
|
}
|
|
81
84
|
static isBaseEntity(value) {
|
|
82
|
-
return value instanceof BaseEntity;
|
|
85
|
+
return value instanceof base_entity_1.BaseEntity;
|
|
83
86
|
}
|
|
84
87
|
}
|
|
88
|
+
exports.ValueProcessor = ValueProcessor;
|
package/dist/utils.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefaultLength = getDefaultLength;
|
|
4
|
+
exports.toSnakeCase = toSnakeCase;
|
|
5
|
+
exports.extendsFrom = extendsFrom;
|
|
6
|
+
function getDefaultLength(type) {
|
|
2
7
|
return null;
|
|
3
8
|
}
|
|
4
|
-
|
|
9
|
+
function toSnakeCase(propertyKey1) {
|
|
5
10
|
propertyKey1 = propertyKey1[0].toLowerCase() + propertyKey1.slice(1);
|
|
6
11
|
return propertyKey1.replace(/([A-Z])/g, '_$1').toLowerCase();
|
|
7
12
|
}
|
|
8
|
-
|
|
13
|
+
function extendsFrom(baseClass, instance) {
|
|
9
14
|
if (!instance)
|
|
10
15
|
return false;
|
|
11
16
|
let proto = Object.getPrototypeOf(instance);
|
package/package.json
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cheetah.js/orm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.48",
|
|
4
4
|
"description": "A simple ORM for Cheetah.js",
|
|
5
|
+
"type": "commonjs",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
"./package.json": "./package.json",
|
|
10
10
|
".": {
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
"default": "./dist/index.js"
|
|
14
|
-
},
|
|
15
|
-
"require": "./dist/index.js"
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
16
13
|
}
|
|
17
14
|
},
|
|
18
15
|
"scripts": {
|
|
19
|
-
"compile": "rm -rf ./dist tsconfig.tsbuildinfo && tsc --build --force
|
|
16
|
+
"compile": "rm -rf ./dist tsconfig.tsbuildinfo && tsc --build --force",
|
|
17
|
+
"build": "tsc --build --force",
|
|
18
|
+
"prepublishOnly": "bun run build"
|
|
20
19
|
},
|
|
21
20
|
"dependencies": {
|
|
22
21
|
"commander": "^11.1.0",
|
|
@@ -51,5 +50,5 @@
|
|
|
51
50
|
"bun",
|
|
52
51
|
"value-object"
|
|
53
52
|
],
|
|
54
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "b5e1a37c74002278ec28cff0cab8f58d66cbf0b9"
|
|
55
54
|
}
|