objection 3.1.4 → 3.1.5

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.
@@ -36,8 +36,10 @@ class AjvValidator extends Validator {
36
36
  self.cache = new Map();
37
37
 
38
38
  const setupAjv = (ajv) => {
39
- conf.onCreateAjv(ajv);
40
- // Only add AJV formats if they weren't added in user-space already
39
+ if (conf.onCreateAjv) {
40
+ conf.onCreateAjv(ajv);
41
+ }
42
+ // Only add Ajv formats if they weren't added in user-space already
41
43
  if (!ajv.formats['date-time']) {
42
44
  addFormats(ajv);
43
45
  }
@@ -77,7 +79,7 @@ class AjvValidator extends Validator {
77
79
  }
78
80
 
79
81
  validator.call(model, json);
80
- const error = parseValidationError(validator.errors, modelClass, options);
82
+ const error = parseValidationError(validator.errors, modelClass, options, this.ajvOptions);
81
83
 
82
84
  if (error) {
83
85
  throw error;
@@ -87,7 +89,7 @@ class AjvValidator extends Validator {
87
89
  }
88
90
 
89
91
  getValidator(modelClass, jsonSchema, isPatchObject) {
90
- // Use the AJV custom serializer if provided.
92
+ // Use the Ajv custom serializer if provided.
91
93
  const createCacheKey = this.ajvOptions.serialize || JSON.stringify;
92
94
 
93
95
  // Optimization for the common case where jsonSchema is never modified.
@@ -103,7 +105,7 @@ class AjvValidator extends Validator {
103
105
  if (!validators) {
104
106
  validators = {
105
107
  // Validator created for the schema object without `required` properties
106
- // using the AJV instance that doesn't set default values.
108
+ // using the Ajv instance that doesn't set default values.
107
109
  patchValidator: null,
108
110
 
109
111
  // Validator created for the unmodified schema.
@@ -143,7 +145,7 @@ class AjvValidator extends Validator {
143
145
  }
144
146
  }
145
147
 
146
- function parseValidationError(errors, modelClass, options) {
148
+ function parseValidationError(errors, modelClass, options, ajvOptions) {
147
149
  if (!errors) {
148
150
  return null;
149
151
  }
@@ -178,13 +180,21 @@ function parseValidationError(errors, modelClass, options) {
178
180
  // More than one error can occur for the same key in Ajv, merge them in the array:
179
181
  const array = errorHash[key] || (errorHash[key] = []);
180
182
 
181
- // Use unshift instead of push so that the last error ends up at [0],
182
- // preserving previous behavior where only the last error was stored.
183
- array.unshift({
183
+ // Prepare error object
184
+ const errorObj = {
184
185
  message: error.message,
185
186
  keyword: error.keyword,
186
187
  params: error.params,
187
- });
188
+ };
189
+
190
+ // Add data if verbose enabled
191
+ if (ajvOptions.verbose) {
192
+ errorObj.data = error.data;
193
+ }
194
+
195
+ // Use unshift instead of push so that the last error ends up at [0],
196
+ // preserving previous behavior where only the last error was stored.
197
+ array.unshift(errorObj);
188
198
 
189
199
  ++numErrors;
190
200
  }
@@ -317,9 +317,6 @@ class Model {
317
317
 
318
318
  static createValidator() {
319
319
  return new AjvValidator({
320
- onCreateAjv: (ajv) => {
321
- /* Do Nothing by default */
322
- },
323
320
  options: {
324
321
  allErrors: true,
325
322
  validateSchema: false,
@@ -12,7 +12,7 @@ const WhereSelector = /^(where|orWhere|andWhere|find\w+)/;
12
12
  const OnSelector = /^(on|orOn|andOn)/;
13
13
  const OrderBySelector = /orderBy/;
14
14
  const JoinSelector = /(join|joinRaw|joinRelated)$/i;
15
- const FromSelector = /^(from|into|table)$/;
15
+ const FromSelector = /^(from|fromRaw|into|table)$/;
16
16
 
17
17
  class QueryBuilderOperationSupport {
18
18
  constructor(...args) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "objection",
3
- "version": "3.1.4",
3
+ "version": "3.1.5",
4
4
  "description": "An SQL-friendly ORM for Node.js",
5
5
  "main": "lib/objection.js",
6
6
  "license": "MIT",
@@ -53,7 +53,7 @@
53
53
  ],
54
54
  "types": "./typings/objection/index.d.ts",
55
55
  "dependencies": {
56
- "ajv": "^8.12.0",
56
+ "ajv": "^8.17.1",
57
57
  "ajv-formats": "^2.1.1",
58
58
  "db-errors": "^0.2.3"
59
59
  },
@@ -61,20 +61,20 @@
61
61
  "knex": ">=1.0.1"
62
62
  },
63
63
  "devDependencies": {
64
- "@types/node": "^20.10.0",
64
+ "@types/node": "^22.7.0",
65
65
  "chai": "^4.3.10",
66
66
  "chai-subset": "^1.6.0",
67
67
  "eslint": "^8.54.0",
68
68
  "eslint-formatter-codeframe": "^7.32.1",
69
- "eslint-plugin-prettier": "^5.0.1",
69
+ "eslint-plugin-prettier": "^5.2.1",
70
70
  "expect.js": "^0.3.1",
71
- "knex": "^3.0.1",
72
- "mocha": "^10.2.0",
71
+ "knex": "^3.1.0",
72
+ "mocha": "^10.7.3",
73
73
  "mysql": "^2.18.1",
74
- "pg": "^8.11.3",
75
- "prettier": "3.2.5",
76
- "sqlite3": "^5.1.6",
77
- "typescript": ">=5.3.2",
74
+ "pg": "^8.13.0",
75
+ "prettier": "3.3.3",
76
+ "sqlite3": "^5.1.7",
77
+ "typescript": ">=5.6.2",
78
78
  "vuepress": "1.9.10"
79
79
  }
80
80
  }
@@ -1070,7 +1070,7 @@ declare namespace Objection {
1070
1070
  insert(insert: PartialModelObject<M>[]): ArrayQueryBuilder<this>;
1071
1071
  insert(): SingleQueryBuilder<this>;
1072
1072
 
1073
- onConflict(column?: string | string[] | true): this;
1073
+ onConflict(column?: ColumnRef | ColumnRef[] | true): this;
1074
1074
  ignore(): this;
1075
1075
  merge(merge?: PartialModelObject<M> | string[]): this;
1076
1076
 
@@ -1423,6 +1423,19 @@ declare namespace Objection {
1423
1423
  new (): T;
1424
1424
  }
1425
1425
 
1426
+ interface PrototypeType<T> extends Function {
1427
+ prototype: T;
1428
+ }
1429
+
1430
+ interface ConstructorFunctionType<T = any> extends PrototypeType<T> {
1431
+ new (...args: any[]): T;
1432
+ }
1433
+
1434
+ // for internal use on generic static this deduction, copied from https://github.com/microsoft/TypeScript/issues/5863#issuecomment-1483978415
1435
+ type ConstructorType<T = unknown, Static extends Record<string, any> = PrototypeType<T>> = (ConstructorFunctionType<T> | PrototypeType<T>) & {
1436
+ [Key in keyof Static]: Static[Key];
1437
+ };
1438
+
1426
1439
  export interface ModelConstructor<M extends Model> extends Constructor<M> {}
1427
1440
 
1428
1441
  export interface ModelClass<M extends Model> extends ModelConstructor<M> {
@@ -1473,6 +1486,9 @@ declare namespace Objection {
1473
1486
  fromJson(json: object, opt?: ModelOptions): M;
1474
1487
  fromDatabaseJson(json: object): M;
1475
1488
 
1489
+ columnNameToPropertyName(columnName: string): string;
1490
+ propertyNameToColumnName(propertyName: string): string;
1491
+
1476
1492
  createValidator(): Validator;
1477
1493
  createValidationError(args: CreateValidationErrorArgs): Error;
1478
1494
  createNotFoundError(queryContext: QueryContext, args: CreateNotFoundErrorArgs): Error;
@@ -1570,7 +1586,7 @@ declare namespace Objection {
1570
1586
  ): QueryBuilderType<M>;
1571
1587
 
1572
1588
  static relatedQuery<M extends Model, K extends keyof M>(
1573
- this: Constructor<M>,
1589
+ this: ConstructorType<M>,
1574
1590
  relationName: K,
1575
1591
  trxOrKnex?: TransactionOrKnex,
1576
1592
  ): ArrayRelatedQueryBuilder<M[K]>;
@@ -1583,6 +1599,9 @@ declare namespace Objection {
1583
1599
  static fromJson<M extends Model>(this: Constructor<M>, json: object, opt?: ModelOptions): M;
1584
1600
  static fromDatabaseJson<M extends Model>(this: Constructor<M>, json: object): M;
1585
1601
 
1602
+ static columnNameToPropertyName(columnName: string): string;
1603
+ static propertyNameToColumnName(propertyName: string): string;
1604
+
1586
1605
  static createValidator(): Validator;
1587
1606
  static createValidationError(args: CreateValidationErrorArgs): Error;
1588
1607
  static createNotFoundError(queryContext: QueryContext, args: CreateNotFoundErrorArgs): Error;
@@ -1596,7 +1615,7 @@ declare namespace Objection {
1596
1615
 
1597
1616
  static transaction<T>(callback: (trx: Transaction) => Promise<T>): Promise<T>;
1598
1617
  static transaction<T>(
1599
- trxOrKnex: TransactionOrKnex,
1618
+ trxOrKnex: TransactionOrKnex | undefined,
1600
1619
  callback: (trx: Transaction) => Promise<T>,
1601
1620
  ): Promise<T>;
1602
1621