@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.
package/dist/index.js CHANGED
@@ -1,20 +1,39 @@
1
- export * from './decorators/entity.decorator';
2
- export * from './decorators/property.decorator';
3
- export * from './decorators/primary-key.decorator';
4
- export * from './decorators/one-many.decorator';
5
- export * from './decorators/index.decorator';
6
- export * from './decorators/event-hook.decorator';
7
- export * from './decorators/enum.decorator';
8
- export * from './orm';
9
- export * from './orm.service';
10
- export * from './domain/base-entity';
11
- export { EntityStorage } from './domain/entities';
12
- export * from './driver/bun-pg.driver';
13
- export * from './driver/bun-mysql.driver';
14
- export * from './driver/bun-driver.base';
15
- export * from './utils';
16
- export * from './driver/driver.interface';
17
- export * from './entry';
18
- export * from './common/value-object';
19
- export * from './common/email.vo';
20
- export * from './common/uuid';
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
- import { LoggerService, Service } from '@cheetah.js/core';
12
- import { SqlBuilder } from './SqlBuilder';
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 = Orm_1 = __decorate([
37
- Service(),
38
- __metadata("design:paramtypes", [LoggerService])
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 };
@@ -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
- import { Metadata, OnApplicationInit, Service } from '@cheetah.js/core';
11
- import { EntityStorage } from './domain/entities';
12
- import { ENTITIES, EVENTS_METADATA, PROPERTIES_METADATA, PROPERTIES_RELATIONS } from './constants';
13
- import { Project, SyntaxKind } from 'ts-morph';
14
- import { Orm } from './orm';
15
- import * as globby from 'globby';
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 import(configFile[0]);
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 import(file);
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
- import { ValueObject } from '../common/value-object';
2
- import { extendsFrom } from '../utils';
3
- export class ModelTransformer {
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
- export class SqlColumnManager {
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
- import { ValueObject } from '../common/value-object';
2
- import { extendsFrom } from '../utils';
3
- export class SqlConditionBuilder {
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
- export class SqlJoinManager {
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;
@@ -0,0 +1,125 @@
1
+ import { BaseEntity } from '../domain/base-entity';
2
+ import { SqlBuilder } from '../SqlBuilder';
3
+ import { FilterQuery, ValueOrInstance } from '../driver/driver.interface';
4
+ /**
5
+ * Generic Repository class for database operations.
6
+ * Provides type-safe methods for CRUD operations.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * @Service()
11
+ * export class LessonRepository extends Repository<Lesson> {
12
+ * constructor() {
13
+ * super(Lesson);
14
+ * }
15
+ *
16
+ * async findByCourse(courseId: number): Promise<Lesson[]> {
17
+ * return this.find({
18
+ * where: { courseId },
19
+ * order: { orderIndex: 'ASC' }
20
+ * });
21
+ * }
22
+ * }
23
+ * ```
24
+ */
25
+ export declare abstract class Repository<T extends BaseEntity> {
26
+ protected readonly entityClass: {
27
+ new (): T;
28
+ } & typeof BaseEntity;
29
+ constructor(entityClass: {
30
+ new (): T;
31
+ } & typeof BaseEntity);
32
+ /**
33
+ * Creates a new query builder for the entity.
34
+ */
35
+ protected createQueryBuilder(): SqlBuilder<T>;
36
+ /**
37
+ * Finds entities matching the given criteria.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const lessons = await repository.find({
42
+ * where: { courseId: 1, isPublished: true },
43
+ * order: { orderIndex: 'ASC' },
44
+ * limit: 10
45
+ * });
46
+ * ```
47
+ */
48
+ find(options: RepositoryFindOptions<T>): Promise<T[]>;
49
+ /**
50
+ * Finds a single entity matching the given criteria.
51
+ * Returns undefined if not found.
52
+ */
53
+ findOne(options: RepositoryFindOneOptions<T>): Promise<T | undefined>;
54
+ /**
55
+ * Finds a single entity matching the given criteria.
56
+ * Throws an error if not found.
57
+ */
58
+ findOneOrFail(options: RepositoryFindOneOptions<T>): Promise<T>;
59
+ /**
60
+ * Finds all entities with optional filtering.
61
+ */
62
+ findAll(options?: Omit<RepositoryFindOptions<T>, 'where'>): Promise<T[]>;
63
+ /**
64
+ * Finds an entity by its primary key.
65
+ */
66
+ findById(id: number | string): Promise<T | undefined>;
67
+ /**
68
+ * Finds an entity by its primary key.
69
+ * Throws an error if not found.
70
+ */
71
+ findByIdOrFail(id: number | string): Promise<T>;
72
+ /**
73
+ * Creates a new entity.
74
+ */
75
+ create(data: Partial<{
76
+ [K in keyof T]: ValueOrInstance<T[K]>;
77
+ }>): Promise<T>;
78
+ /**
79
+ * Updates entities matching the criteria.
80
+ */
81
+ update(where: FilterQuery<T>, data: Partial<{
82
+ [K in keyof T]: ValueOrInstance<T[K]>;
83
+ }>): Promise<void>;
84
+ /**
85
+ * Updates an entity by its primary key.
86
+ */
87
+ updateById(id: number | string, data: Partial<{
88
+ [K in keyof T]: ValueOrInstance<T[K]>;
89
+ }>): Promise<void>;
90
+ /**
91
+ * Finds entities for deletion (use with caution).
92
+ * To delete, call .remove() on returned entities or use SQL directly.
93
+ */
94
+ findForDeletion(where: FilterQuery<T>): Promise<T[]>;
95
+ /**
96
+ * Counts entities matching the criteria.
97
+ */
98
+ count(where?: FilterQuery<T>): Promise<number>;
99
+ /**
100
+ * Checks if any entity matches the criteria.
101
+ */
102
+ exists(where: FilterQuery<T>): Promise<boolean>;
103
+ }
104
+ /**
105
+ * Order options for repository queries.
106
+ */
107
+ export type RepositoryOrderOptions<T> = {
108
+ [K in keyof T]?: 'ASC' | 'DESC';
109
+ };
110
+ /**
111
+ * Find options for repository queries.
112
+ */
113
+ export interface RepositoryFindOptions<T> {
114
+ where?: FilterQuery<T>;
115
+ order?: RepositoryOrderOptions<T>;
116
+ limit?: number;
117
+ offset?: number;
118
+ fields?: readonly (keyof T)[];
119
+ load?: readonly string[];
120
+ loadStrategy?: 'select' | 'joined';
121
+ }
122
+ /**
123
+ * Find one options for repository queries.
124
+ */
125
+ export type RepositoryFindOneOptions<T> = Omit<RepositoryFindOptions<T>, 'limit' | 'offset'>;
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Repository = void 0;
4
+ /**
5
+ * Generic Repository class for database operations.
6
+ * Provides type-safe methods for CRUD operations.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * @Service()
11
+ * export class LessonRepository extends Repository<Lesson> {
12
+ * constructor() {
13
+ * super(Lesson);
14
+ * }
15
+ *
16
+ * async findByCourse(courseId: number): Promise<Lesson[]> {
17
+ * return this.find({
18
+ * where: { courseId },
19
+ * order: { orderIndex: 'ASC' }
20
+ * });
21
+ * }
22
+ * }
23
+ * ```
24
+ */
25
+ class Repository {
26
+ constructor(entityClass) {
27
+ this.entityClass = entityClass;
28
+ }
29
+ /**
30
+ * Creates a new query builder for the entity.
31
+ */
32
+ createQueryBuilder() {
33
+ return this.entityClass.createQueryBuilder();
34
+ }
35
+ /**
36
+ * Finds entities matching the given criteria.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const lessons = await repository.find({
41
+ * where: { courseId: 1, isPublished: true },
42
+ * order: { orderIndex: 'ASC' },
43
+ * limit: 10
44
+ * });
45
+ * ```
46
+ */
47
+ async find(options) {
48
+ const { where, order, limit, offset, fields, load, loadStrategy } = options;
49
+ return this.entityClass.find(where || {}, {
50
+ orderBy: order,
51
+ limit,
52
+ offset,
53
+ fields: fields,
54
+ load: load,
55
+ loadStrategy,
56
+ });
57
+ }
58
+ /**
59
+ * Finds a single entity matching the given criteria.
60
+ * Returns undefined if not found.
61
+ */
62
+ async findOne(options) {
63
+ const { where, order, fields, load, loadStrategy } = options;
64
+ return this.entityClass.findOne(where || {}, {
65
+ orderBy: order,
66
+ fields: fields,
67
+ load: load,
68
+ loadStrategy,
69
+ });
70
+ }
71
+ /**
72
+ * Finds a single entity matching the given criteria.
73
+ * Throws an error if not found.
74
+ */
75
+ async findOneOrFail(options) {
76
+ const { where, order, fields, load, loadStrategy } = options;
77
+ return this.entityClass.findOneOrFail(where || {}, {
78
+ orderBy: order,
79
+ fields: fields,
80
+ load: load,
81
+ loadStrategy,
82
+ });
83
+ }
84
+ /**
85
+ * Finds all entities with optional filtering.
86
+ */
87
+ async findAll(options) {
88
+ const { order, limit, offset, fields, load, loadStrategy } = options || {};
89
+ return this.entityClass.findAll({
90
+ orderBy: order,
91
+ limit,
92
+ offset,
93
+ fields: fields,
94
+ load: load,
95
+ loadStrategy,
96
+ });
97
+ }
98
+ /**
99
+ * Finds an entity by its primary key.
100
+ */
101
+ async findById(id) {
102
+ return this.findOne({ where: { id } });
103
+ }
104
+ /**
105
+ * Finds an entity by its primary key.
106
+ * Throws an error if not found.
107
+ */
108
+ async findByIdOrFail(id) {
109
+ return this.findOneOrFail({ where: { id } });
110
+ }
111
+ /**
112
+ * Creates a new entity.
113
+ */
114
+ async create(data) {
115
+ return this.entityClass.create(data);
116
+ }
117
+ /**
118
+ * Updates entities matching the criteria.
119
+ */
120
+ async update(where, data) {
121
+ await this.createQueryBuilder()
122
+ .update(data)
123
+ .where(where)
124
+ .execute();
125
+ }
126
+ /**
127
+ * Updates an entity by its primary key.
128
+ */
129
+ async updateById(id, data) {
130
+ await this.update({ id }, data);
131
+ }
132
+ /**
133
+ * Finds entities for deletion (use with caution).
134
+ * To delete, call .remove() on returned entities or use SQL directly.
135
+ */
136
+ async findForDeletion(where) {
137
+ return this.find({ where });
138
+ }
139
+ /**
140
+ * Counts entities matching the criteria.
141
+ */
142
+ async count(where) {
143
+ const results = await this.find({ where: where || {} });
144
+ return results.length;
145
+ }
146
+ /**
147
+ * Checks if any entity matches the criteria.
148
+ */
149
+ async exists(where) {
150
+ const count = await this.count(where);
151
+ return count > 0;
152
+ }
153
+ }
154
+ exports.Repository = Repository;
@@ -1,8 +1,11 @@
1
- import { ValueObject } from '../common/value-object';
2
- import { BaseEntity } from '../domain/base-entity';
3
- import { EntityStorage } from '../domain/entities';
4
- import { extendsFrom } from '../utils';
5
- export class ValueProcessor {
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
- export function getDefaultLength(type) {
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
- export function toSnakeCase(propertyKey1) {
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
- export function extendsFrom(baseClass, instance) {
13
+ function extendsFrom(baseClass, instance) {
9
14
  if (!instance)
10
15
  return false;
11
16
  let proto = Object.getPrototypeOf(instance);