@cheetah.js/orm 0.1.83 → 0.1.86

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,6 +1,6 @@
1
1
  import { BaseEntity } from '../domain/base-entity';
2
2
  import { SqlBuilder } from '../SqlBuilder';
3
- import { FilterQuery, ValueOrInstance } from '../driver/driver.interface';
3
+ import { FilterQuery, FindOptions, ValueOrInstance } from '../driver/driver.interface';
4
4
  /**
5
5
  * Generic Repository class for database operations.
6
6
  * Provides type-safe methods for CRUD operations.
@@ -45,30 +45,30 @@ export declare abstract class Repository<T extends BaseEntity> {
45
45
  * });
46
46
  * ```
47
47
  */
48
- find(options: RepositoryFindOptions<T>): Promise<T[]>;
48
+ find<Hint extends string = never>(options: RepositoryFindOptions<T, Hint>): Promise<T[]>;
49
49
  /**
50
50
  * Finds a single entity matching the given criteria.
51
51
  * Returns undefined if not found.
52
52
  */
53
- findOne(options: RepositoryFindOneOptions<T>): Promise<T | undefined>;
53
+ findOne<Hint extends string = never>(options: RepositoryFindOneOptions<T, Hint>): Promise<T | undefined>;
54
54
  /**
55
55
  * Finds a single entity matching the given criteria.
56
56
  * Throws an error if not found.
57
57
  */
58
- findOneOrFail(options: RepositoryFindOneOptions<T>): Promise<T>;
58
+ findOneOrFail<Hint extends string = never>(options: RepositoryFindOneOptions<T, Hint>): Promise<T>;
59
59
  /**
60
60
  * Finds all entities with optional filtering.
61
61
  */
62
- findAll(options?: Omit<RepositoryFindOptions<T>, 'where'>): Promise<T[]>;
62
+ findAll<Hint extends string = never>(options?: Omit<RepositoryFindOptions<T>, 'where'>): Promise<T[]>;
63
63
  /**
64
64
  * Finds an entity by its primary key.
65
65
  */
66
- findById(id: number | string): Promise<T | undefined>;
66
+ findById<Hint extends string = never>(id: number | string, options?: Omit<RepositoryFindOneOptions<T, Hint>, 'where'>): Promise<T | undefined>;
67
67
  /**
68
68
  * Finds an entity by its primary key.
69
69
  * Throws an error if not found.
70
70
  */
71
- findByIdOrFail(id: number | string): Promise<T>;
71
+ findByIdOrFail<Hint extends string = never>(id: number | string, options?: Omit<RepositoryFindOneOptions<T, Hint>, 'where'>): Promise<T>;
72
72
  /**
73
73
  * Creates a new entity.
74
74
  */
@@ -109,25 +109,13 @@ export declare abstract class Repository<T extends BaseEntity> {
109
109
  */
110
110
  exists(where: FilterQuery<T>): Promise<boolean>;
111
111
  }
112
- /**
113
- * Order options for repository queries.
114
- */
115
- export type RepositoryOrderOptions<T> = {
116
- [K in keyof T]?: 'ASC' | 'DESC';
117
- };
118
112
  /**
119
113
  * Find options for repository queries.
120
114
  */
121
- export interface RepositoryFindOptions<T> {
115
+ export type RepositoryFindOptions<T, Hint extends string = never> = FindOptions<T, Hint> & {
122
116
  where?: FilterQuery<T>;
123
- order?: RepositoryOrderOptions<T>;
124
- limit?: number;
125
- offset?: number;
126
- fields?: readonly (keyof T)[];
127
- load?: readonly string[];
128
- loadStrategy?: 'select' | 'joined';
129
- }
117
+ };
130
118
  /**
131
119
  * Find one options for repository queries.
132
120
  */
133
- export type RepositoryFindOneOptions<T> = Omit<RepositoryFindOptions<T>, 'limit' | 'offset'>;
121
+ export type RepositoryFindOneOptions<T, Hint extends string = never> = Omit<RepositoryFindOptions<T, Hint>, 'limit' | 'offset'>;
@@ -45,9 +45,9 @@ class Repository {
45
45
  * ```
46
46
  */
47
47
  async find(options) {
48
- const { where, order, limit, offset, fields, load, loadStrategy } = options;
48
+ const { where, orderBy, limit, offset, fields, load, loadStrategy } = options;
49
49
  return this.entityClass.find(where || {}, {
50
- orderBy: order,
50
+ orderBy: orderBy,
51
51
  limit,
52
52
  offset,
53
53
  fields: fields,
@@ -60,9 +60,9 @@ class Repository {
60
60
  * Returns undefined if not found.
61
61
  */
62
62
  async findOne(options) {
63
- const { where, order, fields, load, loadStrategy } = options;
63
+ const { where, orderBy, fields, load, loadStrategy } = options;
64
64
  return this.entityClass.findOne(where || {}, {
65
- orderBy: order,
65
+ orderBy: orderBy,
66
66
  fields: fields,
67
67
  load: load,
68
68
  loadStrategy,
@@ -73,9 +73,9 @@ class Repository {
73
73
  * Throws an error if not found.
74
74
  */
75
75
  async findOneOrFail(options) {
76
- const { where, order, fields, load, loadStrategy } = options;
76
+ const { where, orderBy, fields, load, loadStrategy } = options;
77
77
  return this.entityClass.findOneOrFail(where || {}, {
78
- orderBy: order,
78
+ orderBy: orderBy,
79
79
  fields: fields,
80
80
  load: load,
81
81
  loadStrategy,
@@ -85,9 +85,9 @@ class Repository {
85
85
  * Finds all entities with optional filtering.
86
86
  */
87
87
  async findAll(options) {
88
- const { order, limit, offset, fields, load, loadStrategy } = options || {};
88
+ const { orderBy, limit, offset, fields, load, loadStrategy } = options || {};
89
89
  return this.entityClass.findAll({
90
- orderBy: order,
90
+ orderBy: orderBy,
91
91
  limit,
92
92
  offset,
93
93
  fields: fields,
@@ -98,15 +98,15 @@ class Repository {
98
98
  /**
99
99
  * Finds an entity by its primary key.
100
100
  */
101
- async findById(id) {
102
- return this.findOne({ where: { id } });
101
+ async findById(id, options) {
102
+ return this.findOne({ where: { id }, ...options });
103
103
  }
104
104
  /**
105
105
  * Finds an entity by its primary key.
106
106
  * Throws an error if not found.
107
107
  */
108
- async findByIdOrFail(id) {
109
- return this.findOneOrFail({ where: { id } });
108
+ async findByIdOrFail(id, options) {
109
+ return this.findOneOrFail({ where: { id }, ...options });
110
110
  }
111
111
  /**
112
112
  * Creates a new entity.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cheetah.js/orm",
3
- "version": "0.1.83",
3
+ "version": "0.1.86",
4
4
  "description": "A simple ORM for Cheetah.js",
5
5
  "type": "commonjs",
6
6
  "main": "dist/index.js",
@@ -55,5 +55,5 @@
55
55
  "bun",
56
56
  "value-object"
57
57
  ],
58
- "gitHead": "68ad3f3b572a4a833cc56bb78db496c600a1d06d"
58
+ "gitHead": "892dcc7a37c62b283b9bebb810bd2a0ab560e20e"
59
59
  }