@cheetah.js/orm 0.1.46 → 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.
@@ -1,29 +1,32 @@
1
- import { EntityStorage } from './domain/entities';
2
- import { Orm } from './orm';
3
- import { ValueProcessor } from './utils/value-processor';
4
- import { SqlConditionBuilder } from './query/sql-condition-builder';
5
- import { ModelTransformer } from './query/model-transformer';
6
- import { SqlColumnManager } from './query/sql-column-manager';
7
- import { SqlJoinManager } from './query/sql-join-manager';
8
- export class SqlBuilder {
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);
@@ -202,9 +205,14 @@ export class SqlBuilder {
202
205
  }
203
206
  mapObjectKey(obj, key, parentKey) {
204
207
  const fullKey = parentKey ? `${parentKey}.${key}` : key;
205
- return this.isNestedObject(obj[key])
206
- ? this.objectToStringMap(obj[key], fullKey)
207
- : [`${this.columnManager.discoverAlias(fullKey, true)} ${obj[key]}`];
208
+ if (this.isNestedObject(obj[key])) {
209
+ return this.objectToStringMap(obj[key], fullKey);
210
+ }
211
+ if (parentKey) {
212
+ return [`${this.columnManager.discoverAlias(fullKey, true)} ${obj[key]}`];
213
+ }
214
+ const columnName = value_processor_1.ValueProcessor.getColumnName(key, this.entity);
215
+ return [`${this.columnManager.discoverAlias(columnName, true)} ${obj[key]}`];
208
216
  }
209
217
  isNestedObject(value) {
210
218
  return typeof value === 'object' && value !== null;
@@ -325,3 +333,4 @@ export class SqlBuilder {
325
333
  }
326
334
  }
327
335
  }
336
+ exports.SqlBuilder = SqlBuilder;
@@ -1,7 +1,11 @@
1
- import { ValueObject } from "./value-object";
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
- export class Email extends ValueObject {
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;
@@ -1,6 +1,10 @@
1
- import { ValueObject } from './value-object';
2
- export class Uuid extends ValueObject {
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
- import { HttpException } from "@cheetah.js/core";
2
- export class ValueObject {
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
- export const ENTITIES = 'cheetah:entities';
2
- export const PROPERTIES = 'cheetah:properties';
3
- export const PROPERTIES_METADATA = 'cheetah:properties:metadata';
4
- export const PROPERTIES_RELATIONS = 'cheetah:properties:relations';
5
- export const EVENTS_METADATA = 'cheetah:events:metadata';
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
- import { ENTITIES } from '../constants';
2
- import { Metadata } from '@cheetah.js/core';
3
- export function Entity(options) {
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
- import { Property } from './property.decorator';
2
- export function Enum(options) {
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
- import { EVENTS_METADATA } from '../constants';
2
- export function BeforeCreate() {
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
- export function AfterCreate() {
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
- export function BeforeUpdate() {
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
- export function AfterUpdate() {
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
- import { Metadata } from "@cheetah.js/core";
2
- export function Index(options) {
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
- import { PROPERTIES_RELATIONS } from '../constants';
2
- import { Metadata } from '@cheetah.js/core';
3
- import { toSnakeCase } from '../utils';
4
- export function OneToMany(entity, fkKey) {
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
- export function ManyToOne(entity) {
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
- import { Property } from './property.decorator';
2
- export function PrimaryKey(options) {
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
- import { PROPERTIES, PROPERTIES_METADATA } from "../constants";
2
- import { extendsFrom, getDefaultLength, toSnakeCase } from "../utils";
3
- import { Metadata } from "@cheetah.js/core";
4
- import { Index } from "./index.decorator";
5
- import { ValueObject } from "..";
6
- export function Property(options) {
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
- import { SqlBuilder } from '../SqlBuilder';
2
- import { EntityStorage } from './entities';
3
- export class BaseEntity {
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
- export class ArrayCollection {
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
- export class Collection extends ArrayCollection {
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;
@@ -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
- import { Metadata, Service } from "@cheetah.js/core";
12
- import { getDefaultLength, toSnakeCase } from "../utils";
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 = EntityStorage_1 = __decorate([
152
- Service(),
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 };
@@ -1,6 +1,10 @@
1
- export class Reference {
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
- import { SQL } from 'bun';
2
- export class BunDriverBase {
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
- import { BunDriverBase } from './bun-driver.base';
2
- export class BunMysqlDriver extends BunDriverBase {
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
- import { BunDriverBase } from './bun-driver.base';
2
- export class BunPgDriver extends BunDriverBase {
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
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/entry.js CHANGED
@@ -1,5 +1,8 @@
1
- import { Cheetah } from '@cheetah.js/core';
2
- import { Orm } from './orm';
3
- import { OrmService } from './orm.service';
4
- import { EntityStorage } from './domain/entities';
5
- export const CheetahOrm = new Cheetah({ exports: [Orm, OrmService, EntityStorage] });
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.d.ts CHANGED
@@ -18,3 +18,4 @@ export * from './entry';
18
18
  export * from './common/value-object';
19
19
  export * from './common/email.vo';
20
20
  export * from './common/uuid';
21
+ export * from './repository/Repository';