@mikro-orm/core 7.0.0-dev.112 → 7.0.0-dev.113

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.
@@ -154,21 +154,21 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
154
154
  * - POJO/entity instance
155
155
  *
156
156
  * ```ts
157
- * const currentCursor = await em.findByCursor(User, {}, {
157
+ * const currentCursor = await em.findByCursor(User, {
158
158
  * first: 10,
159
159
  * after: previousCursor, // cursor instance
160
160
  * orderBy: { id: 'desc' },
161
161
  * });
162
162
  *
163
163
  * // to fetch next page
164
- * const nextCursor = await em.findByCursor(User, {}, {
164
+ * const nextCursor = await em.findByCursor(User, {
165
165
  * first: 10,
166
166
  * after: currentCursor.endCursor, // opaque string
167
167
  * orderBy: { id: 'desc' },
168
168
  * });
169
169
  *
170
170
  * // to fetch next page
171
- * const nextCursor2 = await em.findByCursor(User, {}, {
171
+ * const nextCursor2 = await em.findByCursor(User, {
172
172
  * first: 10,
173
173
  * after: { id: lastSeenId }, // entity-like POJO
174
174
  * orderBy: { id: 'desc' },
@@ -196,7 +196,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
196
196
  * }
197
197
  * ```
198
198
  */
199
- findByCursor<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never, IncludeCount extends boolean = true>(entityName: EntityName<Entity>, where: FilterQuery<NoInfer<Entity>>, options: FindByCursorOptions<Entity, Hint, Fields, Excludes, IncludeCount>): Promise<Cursor<Entity, Hint, Fields, Excludes, IncludeCount>>;
199
+ findByCursor<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never, IncludeCount extends boolean = true>(entityName: EntityName<Entity>, options: FindByCursorOptions<Entity, Hint, Fields, Excludes, IncludeCount>): Promise<Cursor<Entity, Hint, Fields, Excludes, IncludeCount>>;
200
200
  /**
201
201
  * Refreshes the persistent state of an entity from the database, overriding any local changes that have not yet been
202
202
  * persisted. Returns the same entity instance (same object reference), but re-hydrated. If the entity is no longer
package/EntityManager.js CHANGED
@@ -489,21 +489,21 @@ export class EntityManager {
489
489
  * - POJO/entity instance
490
490
  *
491
491
  * ```ts
492
- * const currentCursor = await em.findByCursor(User, {}, {
492
+ * const currentCursor = await em.findByCursor(User, {
493
493
  * first: 10,
494
494
  * after: previousCursor, // cursor instance
495
495
  * orderBy: { id: 'desc' },
496
496
  * });
497
497
  *
498
498
  * // to fetch next page
499
- * const nextCursor = await em.findByCursor(User, {}, {
499
+ * const nextCursor = await em.findByCursor(User, {
500
500
  * first: 10,
501
501
  * after: currentCursor.endCursor, // opaque string
502
502
  * orderBy: { id: 'desc' },
503
503
  * });
504
504
  *
505
505
  * // to fetch next page
506
- * const nextCursor2 = await em.findByCursor(User, {}, {
506
+ * const nextCursor2 = await em.findByCursor(User, {
507
507
  * first: 10,
508
508
  * after: { id: lastSeenId }, // entity-like POJO
509
509
  * orderBy: { id: 'desc' },
@@ -531,16 +531,17 @@ export class EntityManager {
531
531
  * }
532
532
  * ```
533
533
  */
534
- async findByCursor(entityName, where, options) {
534
+ async findByCursor(entityName, options) {
535
535
  const em = this.getContext(false);
536
536
  entityName = Utils.className(entityName);
537
537
  options.overfetch ??= true;
538
+ options.where ??= {};
538
539
  if (Utils.isEmpty(options.orderBy)) {
539
540
  throw new Error('Explicit `orderBy` option required');
540
541
  }
541
542
  const [entities, count] = options.includeCount !== false
542
- ? await em.findAndCount(entityName, where, options)
543
- : [await em.find(entityName, where, options)];
543
+ ? await em.findAndCount(entityName, options.where, options)
544
+ : [await em.find(entityName, options.where, options)];
544
545
  return new Cursor(entities, count, options, this.metadata.get(entityName));
545
546
  }
546
547
  /**
@@ -166,7 +166,7 @@ export interface FindOptions<Entity, Hint extends string = never, Fields extends
166
166
  /** @internal used to apply filters to the auto-joined relations */
167
167
  em?: EntityManager;
168
168
  }
169
- export interface FindByCursorOptions<T extends object, P extends string = never, F extends string = '*', E extends string = never, I extends boolean = true> extends Omit<FindOptions<T, P, F, E>, 'limit' | 'offset'> {
169
+ export interface FindByCursorOptions<T extends object, P extends string = never, F extends string = '*', E extends string = never, I extends boolean = true> extends Omit<FindAllOptions<T, P, F, E>, 'limit' | 'offset'> {
170
170
  includeCount?: I;
171
171
  }
172
172
  export interface FindOneOptions<T, P extends string = never, F extends string = '*', E extends string = never> extends Omit<FindOptions<T, P, F, E>, 'limit' | 'lockMode'> {
@@ -80,7 +80,7 @@ export declare class EntityRepository<Entity extends object> {
80
80
  /**
81
81
  * @inheritDoc EntityManager.findByCursor
82
82
  */
83
- findByCursor<Hint extends string = never, Fields extends string = '*', Excludes extends string = never, IncludeCount extends boolean = true>(where: FilterQuery<Entity>, options: FindByCursorOptions<Entity, Hint, Fields, Excludes, IncludeCount>): Promise<Cursor<Entity, Hint, Fields, Excludes, IncludeCount>>;
83
+ findByCursor<Hint extends string = never, Fields extends string = '*', Excludes extends string = never, IncludeCount extends boolean = true>(options: FindByCursorOptions<Entity, Hint, Fields, Excludes, IncludeCount>): Promise<Cursor<Entity, Hint, Fields, Excludes, IncludeCount>>;
84
84
  /**
85
85
  * Finds all entities of given type. You can pass additional options via the `options` parameter.
86
86
  */
@@ -90,8 +90,8 @@ export class EntityRepository {
90
90
  /**
91
91
  * @inheritDoc EntityManager.findByCursor
92
92
  */
93
- async findByCursor(where, options) {
94
- return this.getEntityManager().findByCursor(this.entityName, where, options);
93
+ async findByCursor(options) {
94
+ return this.getEntityManager().findByCursor(this.entityName, options);
95
95
  }
96
96
  /**
97
97
  * Finds all entities of given type. You can pass additional options via the `options` parameter.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
3
  "type": "module",
4
- "version": "7.0.0-dev.112",
4
+ "version": "7.0.0-dev.113",
5
5
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
6
6
  "exports": {
7
7
  "./package.json": "./package.json",
package/utils/Utils.js CHANGED
@@ -123,7 +123,7 @@ export function parseJsonSafe(value) {
123
123
  }
124
124
  export class Utils {
125
125
  static PK_SEPARATOR = '~~~';
126
- static #ORM_VERSION = '7.0.0-dev.112';
126
+ static #ORM_VERSION = '7.0.0-dev.113';
127
127
  /**
128
128
  * Checks if the argument is instance of `Object`. Returns false for arrays.
129
129
  */