@mikro-orm/core 6.4.2-dev.8 → 6.4.2-dev.9

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.
@@ -47,7 +47,7 @@ export declare abstract class DatabaseDriver<C extends Connection> implements ID
47
47
  orderBy: OrderDefinition<T>[];
48
48
  where: FilterQuery<T>;
49
49
  };
50
- protected createCursorCondition<T extends object>(definition: (readonly [keyof T & string, QueryOrder])[], offsets: Dictionary[], inverse: boolean): FilterQuery<T>;
50
+ protected createCursorCondition<T extends object>(definition: (readonly [keyof T & string, QueryOrder])[], offsets: Dictionary[], inverse: boolean, meta: EntityMetadata<T>): FilterQuery<T>;
51
51
  /** @internal */
52
52
  mapDataToFieldNames(data: Dictionary, stringifyJsonArrays: boolean, properties?: Record<string, EntityProperty>, convertCustomTypes?: boolean, object?: boolean): Dictionary;
53
53
  protected inlineEmbeddables<T extends object>(meta: EntityMetadata<T>, data: T, where?: boolean): void;
@@ -125,7 +125,7 @@ class DatabaseDriver {
125
125
  /* istanbul ignore next */
126
126
  const offsets = def ? utils_1.Cursor.decode(def) : [];
127
127
  if (definition.length === offsets.length) {
128
- return this.createCursorCondition(definition, offsets, inverse);
128
+ return this.createCursorCondition(definition, offsets, inverse, meta);
129
129
  }
130
130
  /* istanbul ignore next */
131
131
  return {};
@@ -157,11 +157,17 @@ class DatabaseDriver {
157
157
  };
158
158
  }
159
159
  /* istanbul ignore next */
160
- createCursorCondition(definition, offsets, inverse) {
160
+ createCursorCondition(definition, offsets, inverse, meta) {
161
161
  const createCondition = (prop, direction, offset, eq = false) => {
162
+ if (offset === null) {
163
+ throw errors_1.CursorError.missingValue(meta.className, prop);
164
+ }
162
165
  if (utils_1.Utils.isPlainObject(direction)) {
163
166
  const value = utils_1.Utils.keys(direction).reduce((o, key) => {
164
- Object.assign(o, createCondition(key, direction[key], offset[prop][key], eq));
167
+ if (utils_1.Utils.isEmpty(offset[key])) {
168
+ throw errors_1.CursorError.missingValue(meta.className, `${prop}.${key}`);
169
+ }
170
+ Object.assign(o, createCondition(key, direction[key], offset[key], eq));
165
171
  return o;
166
172
  }, {});
167
173
  return ({ [prop]: value });
@@ -180,7 +186,7 @@ class DatabaseDriver {
180
186
  ...createCondition(prop, direction, offset, true),
181
187
  $or: [
182
188
  createCondition(prop, direction, offset),
183
- this.createCursorCondition(otherOrders, otherOffsets, inverse),
189
+ this.createCursorCondition(otherOrders, otherOffsets, inverse, meta),
184
190
  ],
185
191
  };
186
192
  }
package/errors.d.ts CHANGED
@@ -28,6 +28,7 @@ export declare class ValidationError<T extends AnyEntity = AnyEntity> extends Er
28
28
  }
29
29
  export declare class CursorError<T extends AnyEntity = AnyEntity> extends ValidationError<T> {
30
30
  static entityNotPopulated(entity: AnyEntity, prop: string): ValidationError;
31
+ static missingValue(entityName: string, prop: string): ValidationError;
31
32
  }
32
33
  export declare class OptimisticLockError<T extends AnyEntity = AnyEntity> extends ValidationError<T> {
33
34
  static notVersioned(meta: EntityMetadata): OptimisticLockError;
package/errors.js CHANGED
@@ -107,6 +107,9 @@ class CursorError extends ValidationError {
107
107
  static entityNotPopulated(entity, prop) {
108
108
  return new CursorError(`Cannot create cursor, value for '${entity.constructor.name}.${prop}' is missing.`);
109
109
  }
110
+ static missingValue(entityName, prop) {
111
+ return new CursorError(`Invalid cursor condition, value for '${entityName}.${prop}' is missing.`);
112
+ }
110
113
  }
111
114
  exports.CursorError = CursorError;
112
115
  class OptimisticLockError extends ValidationError {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.4.2-dev.8",
3
+ "version": "6.4.2-dev.9",
4
4
  "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.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -64,7 +64,7 @@
64
64
  "esprima": "4.0.1",
65
65
  "fs-extra": "11.2.0",
66
66
  "globby": "11.1.0",
67
- "mikro-orm": "6.4.2-dev.8",
67
+ "mikro-orm": "6.4.2-dev.9",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
package/utils/Cursor.js CHANGED
@@ -98,11 +98,10 @@ class Cursor {
98
98
  from(entity) {
99
99
  const processEntity = (entity, prop, direction, object = false) => {
100
100
  if (Utils_1.Utils.isPlainObject(direction)) {
101
- const value = Utils_1.Utils.keys(direction).reduce((o, key) => {
101
+ return Utils_1.Utils.keys(direction).reduce((o, key) => {
102
102
  Object.assign(o, processEntity(Reference_1.Reference.unwrapReference(entity[prop]), key, direction[key], true));
103
103
  return o;
104
104
  }, {});
105
- return ({ [prop]: value });
106
105
  }
107
106
  if (entity[prop] == null) {
108
107
  throw errors_1.CursorError.entityNotPopulated(entity, prop);