objection 3.9.1 → 4.0.0-rc.2

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.
Files changed (250) hide show
  1. package/lib/dbErrors/LICENSE +21 -0
  2. package/lib/dbErrors/errorCodes/mssql.js +19 -0
  3. package/lib/dbErrors/errorCodes/mysql.js +805 -0
  4. package/lib/dbErrors/errorCodes/postgres.js +241 -0
  5. package/lib/dbErrors/errors/CheckViolationError.js +10 -0
  6. package/lib/dbErrors/errors/ConstraintViolationError.js +3 -0
  7. package/lib/dbErrors/errors/DBError.js +9 -0
  8. package/lib/dbErrors/errors/DataError.js +3 -0
  9. package/lib/dbErrors/errors/ForeignKeyViolationError.js +11 -0
  10. package/lib/dbErrors/errors/NotNullViolationError.js +12 -0
  11. package/lib/dbErrors/errors/UniqueViolationError.js +12 -0
  12. package/lib/dbErrors/index.js +59 -0
  13. package/lib/dbErrors/parsers/mssql/DBError/CheckViolationError/parser.js +28 -0
  14. package/lib/dbErrors/parsers/mssql/DBError/DataError/parser.js +25 -0
  15. package/lib/dbErrors/parsers/mssql/DBError/ForeignKeyViolationError/parser.js +39 -0
  16. package/lib/dbErrors/parsers/mssql/DBError/NotNullViolationError/parser.js +30 -0
  17. package/lib/dbErrors/parsers/mssql/DBError/UniqueViolationError/parser.js +53 -0
  18. package/lib/dbErrors/parsers/mssql/DBError/parser.js +51 -0
  19. package/lib/dbErrors/parsers/mssql/DBError/util.js +16 -0
  20. package/lib/dbErrors/parsers/mysql/DBError/ConstraintViolationError/ForeignKeyViolationError/parser.js +43 -0
  21. package/lib/dbErrors/parsers/mysql/DBError/ConstraintViolationError/NotNullViolationError/parser.js +29 -0
  22. package/lib/dbErrors/parsers/mysql/DBError/ConstraintViolationError/UniqueViolationError/parser.js +27 -0
  23. package/lib/dbErrors/parsers/mysql/DBError/ConstraintViolationError/parser.js +23 -0
  24. package/lib/dbErrors/parsers/mysql/DBError/DataError/parser.js +24 -0
  25. package/lib/dbErrors/parsers/mysql/DBError/parser.js +28 -0
  26. package/lib/dbErrors/parsers/postgres/DBError/ConstraintViolationError/CheckViolationError/parser.js +18 -0
  27. package/lib/dbErrors/parsers/postgres/DBError/ConstraintViolationError/ForeignKeyViolationError/parser.js +18 -0
  28. package/lib/dbErrors/parsers/postgres/DBError/ConstraintViolationError/NotNullViolationError/parser.js +18 -0
  29. package/lib/dbErrors/parsers/postgres/DBError/ConstraintViolationError/UniqueViolationError/parser.js +40 -0
  30. package/lib/dbErrors/parsers/postgres/DBError/ConstraintViolationError/parser.js +25 -0
  31. package/lib/dbErrors/parsers/postgres/DBError/DataError/parser.js +16 -0
  32. package/lib/dbErrors/parsers/postgres/DBError/parser.js +27 -0
  33. package/lib/dbErrors/parsers/sqlite/DBError/ConstraintViolationError/CheckViolationError/parser.js +20 -0
  34. package/lib/dbErrors/parsers/sqlite/DBError/ConstraintViolationError/ForeignKeyViolationError/parser.js +20 -0
  35. package/lib/dbErrors/parsers/sqlite/DBError/ConstraintViolationError/NotNullViolationError/parser.js +27 -0
  36. package/lib/dbErrors/parsers/sqlite/DBError/ConstraintViolationError/UniqueViolationError/parser.js +28 -0
  37. package/lib/dbErrors/parsers/sqlite/DBError/ConstraintViolationError/parser.js +24 -0
  38. package/lib/dbErrors/parsers/sqlite/DBError/parser.js +23 -0
  39. package/lib/dbErrors/utils/sqlState.js +3 -0
  40. package/lib/initialize.js +1 -7
  41. package/lib/model/AjvValidator.js +51 -117
  42. package/lib/model/Model.js +84 -59
  43. package/lib/model/ModifierNotFoundError.js +1 -7
  44. package/lib/model/NotFoundError.js +1 -7
  45. package/lib/model/RelationDoesNotExistError.js +1 -7
  46. package/lib/model/ValidationError.js +3 -10
  47. package/lib/model/Validator.js +1 -7
  48. package/lib/model/getModel.js +7 -6
  49. package/lib/model/inheritModel.js +1 -7
  50. package/lib/model/modelBindKnex.js +4 -10
  51. package/lib/model/modelClone.js +5 -11
  52. package/lib/model/modelColPropMap.js +3 -10
  53. package/lib/model/modelId.js +3 -10
  54. package/lib/model/modelJsonAttributes.js +35 -16
  55. package/lib/model/modelParseRelations.js +2 -8
  56. package/lib/model/modelQueryProps.js +11 -23
  57. package/lib/model/modelSet.js +89 -41
  58. package/lib/model/modelTableMetadata.js +4 -11
  59. package/lib/model/modelToJson.js +6 -13
  60. package/lib/model/modelUtils.js +14 -13
  61. package/lib/model/modelValidate.js +3 -9
  62. package/lib/model/modelValues.js +5 -14
  63. package/lib/model/modelVisitor.js +1 -7
  64. package/lib/objection.js +33 -71
  65. package/lib/queryBuilder/FunctionBuilder.js +4 -11
  66. package/lib/queryBuilder/InternalOptions.js +4 -9
  67. package/lib/queryBuilder/JoinBuilder.js +5 -8
  68. package/lib/queryBuilder/QueryBuilder.js +126 -95
  69. package/lib/queryBuilder/QueryBuilderBase.js +41 -123
  70. package/lib/queryBuilder/QueryBuilderContext.js +2 -8
  71. package/lib/queryBuilder/QueryBuilderContextBase.js +2 -8
  72. package/lib/queryBuilder/QueryBuilderOperationSupport.js +7 -21
  73. package/lib/queryBuilder/QueryBuilderUserContext.js +1 -7
  74. package/lib/queryBuilder/RawBuilder.js +5 -13
  75. package/lib/queryBuilder/ReferenceBuilder.js +20 -48
  76. package/lib/queryBuilder/RelationExpression.js +18 -16
  77. package/lib/queryBuilder/StaticHookArguments.js +74 -16
  78. package/lib/queryBuilder/ValueBuilder.js +11 -13
  79. package/lib/queryBuilder/getJoinBuilder.js +10 -0
  80. package/lib/queryBuilder/graph/GraphLoader.js +314 -0
  81. package/lib/queryBuilder/graph/GraphNode.js +241 -0
  82. package/lib/queryBuilder/graph/GraphOptions.js +55 -248
  83. package/lib/queryBuilder/graph/GraphPlan.js +431 -0
  84. package/lib/queryBuilder/graph/GraphSchedule.js +513 -0
  85. package/lib/queryBuilder/graph/GraphUpsert.js +519 -412
  86. package/lib/queryBuilder/graph/GraphWriter.js +508 -0
  87. package/lib/queryBuilder/graph/graphKeys.js +929 -0
  88. package/lib/queryBuilder/join/JoinResultColumn.js +1 -7
  89. package/lib/queryBuilder/join/JoinResultParser.js +6 -11
  90. package/lib/queryBuilder/join/RelationJoiner.js +66 -84
  91. package/lib/queryBuilder/join/TableNode.js +2 -8
  92. package/lib/queryBuilder/join/TableTree.js +3 -9
  93. package/lib/queryBuilder/join/utils.js +5 -15
  94. package/lib/queryBuilder/jsonDialects/JsonDialect.js +51 -0
  95. package/lib/queryBuilder/jsonDialects/MySqlJsonDialect.js +81 -0
  96. package/lib/queryBuilder/jsonDialects/PostgresJsonDialect.js +45 -0
  97. package/lib/queryBuilder/jsonDialects/SqliteJsonDialect.js +67 -0
  98. package/lib/queryBuilder/jsonDialects/index.js +44 -0
  99. package/lib/queryBuilder/operations/DelegateOperation.js +2 -8
  100. package/lib/queryBuilder/operations/DeleteOperation.js +10 -39
  101. package/lib/queryBuilder/operations/FindByIdOperation.js +7 -12
  102. package/lib/queryBuilder/operations/FindByIdsOperation.js +4 -8
  103. package/lib/queryBuilder/operations/FindOperation.js +14 -34
  104. package/lib/queryBuilder/operations/FirstOperation.js +6 -10
  105. package/lib/queryBuilder/operations/FromOperation.js +3 -9
  106. package/lib/queryBuilder/operations/InsertAndFetchOperation.js +13 -12
  107. package/lib/queryBuilder/operations/InsertGraphAndFetchOperation.js +4 -10
  108. package/lib/queryBuilder/operations/InsertGraphOperation.js +7 -18
  109. package/lib/queryBuilder/operations/InsertOperation.js +118 -45
  110. package/lib/queryBuilder/operations/InstanceDeleteOperation.js +5 -12
  111. package/lib/queryBuilder/operations/InstanceFindOperation.js +4 -11
  112. package/lib/queryBuilder/operations/InstanceInsertOperation.js +2 -8
  113. package/lib/queryBuilder/operations/InstanceUpdateOperation.js +7 -14
  114. package/lib/queryBuilder/operations/JoinRelatedOperation.js +5 -11
  115. package/lib/queryBuilder/operations/KnexOperation.js +2 -8
  116. package/lib/queryBuilder/operations/LimitPerParentOperation.js +7 -69
  117. package/lib/queryBuilder/operations/MergeOperation.js +5 -11
  118. package/lib/queryBuilder/operations/NoneOperation.js +2 -8
  119. package/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js +20 -49
  120. package/lib/queryBuilder/operations/OnBuildKnexOperation.js +2 -8
  121. package/lib/queryBuilder/operations/OnBuildOperation.js +2 -8
  122. package/lib/queryBuilder/operations/OnErrorOperation.js +2 -8
  123. package/lib/queryBuilder/operations/QueryBuilderOperation.js +1 -7
  124. package/lib/queryBuilder/operations/RangeOperation.js +11 -26
  125. package/lib/queryBuilder/operations/RelateOperation.js +2 -8
  126. package/lib/queryBuilder/operations/ReturningOperation.js +3 -9
  127. package/lib/queryBuilder/operations/RunAfterOperation.js +2 -12
  128. package/lib/queryBuilder/operations/RunBeforeOperation.js +2 -8
  129. package/lib/queryBuilder/operations/UnrelateOperation.js +2 -8
  130. package/lib/queryBuilder/operations/UpdateAndFetchOperation.js +14 -17
  131. package/lib/queryBuilder/operations/UpdateOperation.js +32 -132
  132. package/lib/queryBuilder/operations/UpsertGraphAndFetchOperation.js +8 -11
  133. package/lib/queryBuilder/operations/UpsertGraphOperation.js +6 -12
  134. package/lib/queryBuilder/operations/WhereCompositeOperation.js +3 -9
  135. package/lib/queryBuilder/operations/WhereGroupOperation.js +2 -8
  136. package/lib/queryBuilder/operations/eager/EagerOperation.js +3 -9
  137. package/lib/queryBuilder/operations/eager/JoinEagerOperation.js +72 -10
  138. package/lib/queryBuilder/operations/eager/NaiveEagerOperation.js +2 -8
  139. package/lib/queryBuilder/operations/eager/WhereInEagerOperation.js +23 -44
  140. package/lib/queryBuilder/operations/fieldExpressions.js +122 -0
  141. package/lib/queryBuilder/operations/jsonApi/WhereJsonHasOperation.js +20 -0
  142. package/lib/queryBuilder/operations/jsonApi/WhereJsonOperation.js +44 -0
  143. package/lib/queryBuilder/operations/jsonApi/WhereJsonTypeOperation.js +14 -0
  144. package/lib/queryBuilder/operations/select/SelectOperation.js +11 -21
  145. package/lib/queryBuilder/operations/select/Selection.js +19 -17
  146. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeMsSqlOperation.js +4 -10
  147. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeOperation.js +4 -10
  148. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeSqliteOperation.js +4 -10
  149. package/lib/queryBuilder/operations/windowOrder.js +56 -0
  150. package/lib/queryBuilder/parsers/jsonFieldExpressionParser.js +3 -7
  151. package/lib/queryBuilder/parsers/relationExpressionParser.js +42 -43
  152. package/lib/queryBuilder/parsers/relationExpressionParser.pegjs +39 -36
  153. package/lib/queryBuilder/transformations/CompositeQueryTransformation.js +2 -8
  154. package/lib/queryBuilder/transformations/QueryTransformation.js +1 -7
  155. package/lib/queryBuilder/transformations/WrapMysqlModifySubqueryTransformation.js +3 -9
  156. package/lib/queryBuilder/transformations/index.js +3 -11
  157. package/lib/queryBuilder/whereGroups.js +9 -24
  158. package/lib/queryBuilder/withoutOrder.js +4 -11
  159. package/lib/relations/Relation.js +47 -28
  160. package/lib/relations/RelationDeleteOperation.js +4 -14
  161. package/lib/relations/RelationFindOperation.js +119 -90
  162. package/lib/relations/RelationInsertOperation.js +2 -8
  163. package/lib/relations/RelationOwner.js +5 -11
  164. package/lib/relations/RelationProperty.js +4 -10
  165. package/lib/relations/RelationUpdateOperation.js +4 -14
  166. package/lib/relations/RelationWriteResultOperation.js +15 -0
  167. package/lib/relations/belongsToMany/BelongsToManyDeleteOperation.js +23 -0
  168. package/lib/relations/belongsToMany/BelongsToManyFindOperation.js +35 -0
  169. package/lib/relations/belongsToMany/BelongsToManyInsertOperation.js +28 -0
  170. package/lib/relations/belongsToMany/BelongsToManyRelateOperation.js +16 -0
  171. package/lib/relations/belongsToMany/BelongsToManyRelation.js +276 -0
  172. package/lib/relations/belongsToMany/BelongsToManyUnrelateOperation.js +11 -0
  173. package/lib/relations/belongsToOne/BelongsToOneDeleteOperation.js +2 -8
  174. package/lib/relations/belongsToOne/BelongsToOneInsertOperation.js +6 -11
  175. package/lib/relations/belongsToOne/BelongsToOneRelateOperation.js +3 -9
  176. package/lib/relations/belongsToOne/BelongsToOneRelation.js +8 -19
  177. package/lib/relations/belongsToOne/BelongsToOneUnrelateOperation.js +53 -27
  178. package/lib/relations/hasMany/HasManyInsertOperation.js +5 -10
  179. package/lib/relations/hasMany/HasManyRelateOperation.js +5 -11
  180. package/lib/relations/hasMany/HasManyRelation.js +9 -11
  181. package/lib/relations/hasMany/HasManyUnrelateOperation.js +3 -9
  182. package/lib/relations/hasOne/HasOneRelation.js +2 -8
  183. package/lib/relations/hasOneThrough/HasOneThroughRelation.js +2 -8
  184. package/lib/relations/manyToMany/ManyToManyModifyMixin.js +10 -15
  185. package/lib/relations/manyToMany/ManyToManyMySqlModifyMixin.js +2 -8
  186. package/lib/relations/manyToMany/ManyToManyRelation.js +82 -50
  187. package/lib/relations/manyToMany/ManyToManySqliteModifyMixin.js +2 -8
  188. package/lib/relations/manyToMany/delete/ManyToManyDeleteOperation.js +5 -9
  189. package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +2 -8
  190. package/lib/relations/manyToMany/delete/ManyToManyDeleteSqliteOperation.js +3 -9
  191. package/lib/relations/manyToMany/find/ManyToManyFindOperation.js +20 -59
  192. package/lib/relations/manyToMany/insert/ManyToManyInsertOperation.js +6 -11
  193. package/lib/relations/manyToMany/relate/ManyToManyRelateOperation.js +4 -10
  194. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateMySqlOperation.js +3 -9
  195. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperation.js +5 -9
  196. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperationBase.js +3 -9
  197. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateSqliteOperation.js +3 -9
  198. package/lib/relations/manyToMany/update/ManyToManyUpdateMySqlOperation.js +3 -9
  199. package/lib/relations/manyToMany/update/ManyToManyUpdateOperation.js +5 -9
  200. package/lib/relations/manyToMany/update/ManyToManyUpdateOperationBase.js +64 -72
  201. package/lib/relations/manyToMany/update/ManyToManyUpdateSqliteOperation.js +3 -9
  202. package/lib/transaction.js +3 -9
  203. package/lib/utils/assert.js +3 -11
  204. package/lib/utils/buildUtils.js +2 -8
  205. package/lib/utils/classUtils.js +1 -7
  206. package/lib/utils/createModifier.js +2 -8
  207. package/lib/utils/identifierMapping.js +23 -27
  208. package/lib/utils/internalPropUtils.js +1 -7
  209. package/lib/utils/knexUtils.js +84 -40
  210. package/lib/utils/mixin.js +3 -10
  211. package/lib/utils/normalizeIds.js +2 -8
  212. package/lib/utils/objectUtils.js +41 -60
  213. package/lib/utils/parseFieldExpression.js +16 -16
  214. package/lib/utils/promiseUtils/after.js +2 -8
  215. package/lib/utils/promiseUtils/afterReturn.js +2 -8
  216. package/lib/utils/promiseUtils/index.js +7 -16
  217. package/lib/utils/promiseUtils/isPromise.js +2 -8
  218. package/lib/utils/promiseUtils/map.js +2 -8
  219. package/lib/utils/promiseUtils/mapAfterAllReturn.js +2 -8
  220. package/lib/utils/promiseUtils/try.js +2 -8
  221. package/lib/utils/resolveModel.js +10 -17
  222. package/lib/utils/tmpColumnUtils.js +2 -9
  223. package/lib/utils/warnings.js +2 -14
  224. package/package.json +25 -17
  225. package/typings/objection/index.d.ts +3217 -2179
  226. package/lib/.eslintrc.json +0 -8
  227. package/lib/model/graph/ModelGraph.js +0 -80
  228. package/lib/model/graph/ModelGraphBuilder.js +0 -241
  229. package/lib/model/graph/ModelGraphEdge.js +0 -52
  230. package/lib/model/graph/ModelGraphNode.js +0 -238
  231. package/lib/queryBuilder/graph/GraphAction.js +0 -69
  232. package/lib/queryBuilder/graph/GraphData.js +0 -53
  233. package/lib/queryBuilder/graph/GraphFetcher.js +0 -197
  234. package/lib/queryBuilder/graph/GraphNodeDbExistence.js +0 -184
  235. package/lib/queryBuilder/graph/GraphOperation.js +0 -27
  236. package/lib/queryBuilder/graph/delete/GraphDelete.js +0 -73
  237. package/lib/queryBuilder/graph/delete/GraphDeleteAction.js +0 -88
  238. package/lib/queryBuilder/graph/insert/DeferredRelationGraphInsertAction.js +0 -58
  239. package/lib/queryBuilder/graph/insert/GraphInsert.js +0 -296
  240. package/lib/queryBuilder/graph/insert/GraphInsertAction.js +0 -233
  241. package/lib/queryBuilder/graph/insert/JoinRowGraphInsertAction.js +0 -92
  242. package/lib/queryBuilder/graph/patch/GraphPatch.js +0 -20
  243. package/lib/queryBuilder/graph/patch/GraphPatchAction.js +0 -289
  244. package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsert.js +0 -31
  245. package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsertAction.js +0 -126
  246. package/lib/queryBuilder/operations/jsonApi/WhereJsonHasPostgresOperation.js +0 -30
  247. package/lib/queryBuilder/operations/jsonApi/WhereJsonNotObjectPostgresOperation.js +0 -37
  248. package/lib/queryBuilder/operations/jsonApi/WhereJsonPostgresOperation.js +0 -62
  249. package/lib/queryBuilder/operations/jsonApi/postgresJsonApi.js +0 -192
  250. package/lib/utils/wrapDbError.js +0 -64
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ import { flatten } from './objectUtils.js';
2
2
 
3
- const { flatten } = require('./objectUtils');
4
-
5
- function mixin() {
3
+ export function mixin() {
6
4
  const args = flatten(arguments);
7
5
  const mixins = args.slice(1);
8
6
 
@@ -11,15 +9,10 @@ function mixin() {
11
9
  }, args[0]);
12
10
  }
13
11
 
14
- function compose() {
12
+ export function compose() {
15
13
  const mixins = flatten(arguments);
16
14
 
17
15
  return function (Class) {
18
16
  return mixin(Class, mixins);
19
17
  };
20
18
  }
21
-
22
- module.exports = {
23
- compose,
24
- mixin,
25
- };
@@ -1,9 +1,7 @@
1
- 'use strict';
2
-
3
- const { isObject } = require('../utils/objectUtils');
1
+ import { isObject } from '../utils/objectUtils.js';
4
2
 
5
3
  // ids is of type RelationProperty.
6
- function normalizeIds(ids, prop, opt) {
4
+ export function normalizeIds(ids, prop, opt) {
7
5
  opt = opt || {};
8
6
 
9
7
  let isComposite = prop.size > 1;
@@ -138,7 +136,3 @@ function normalizedToArray(ret, prop) {
138
136
 
139
137
  return arr;
140
138
  }
141
-
142
- module.exports = {
143
- normalizeIds,
144
- };
@@ -1,8 +1,6 @@
1
- 'use strict';
2
-
3
1
  const SMALL_ARRAY_SIZE = 10;
4
2
 
5
- function isEmpty(item) {
3
+ export function isEmpty(item) {
6
4
  if (Array.isArray(item) || Buffer.isBuffer(item)) {
7
5
  return item.length === 0;
8
6
  } else if (isObject(item)) {
@@ -12,17 +10,17 @@ function isEmpty(item) {
12
10
  }
13
11
  }
14
12
 
15
- function isObject(value) {
13
+ export function isObject(value) {
16
14
  return value !== null && typeof value === 'object';
17
15
  }
18
16
 
19
- function hasOwn(obj, prop) {
17
+ export function hasOwn(obj, prop) {
20
18
  return Object.prototype.hasOwnProperty.call(obj, prop);
21
19
  }
22
20
 
23
21
  // Quick and dirty check if an object is a plain object and not
24
22
  // for example an instance of some class.
25
- function isPlainObject(value) {
23
+ export function isPlainObject(value) {
26
24
  return (
27
25
  isObject(value) &&
28
26
  (!value.constructor || value.constructor === Object) &&
@@ -30,31 +28,31 @@ function isPlainObject(value) {
30
28
  );
31
29
  }
32
30
 
33
- function isFunction(value) {
31
+ export function isFunction(value) {
34
32
  return typeof value === 'function';
35
33
  }
36
34
 
37
- function isRegExp(value) {
35
+ export function isRegExp(value) {
38
36
  return value instanceof RegExp;
39
37
  }
40
38
 
41
- function isString(value) {
39
+ export function isString(value) {
42
40
  return typeof value === 'string';
43
41
  }
44
42
 
45
- function isNumber(value) {
43
+ export function isNumber(value) {
46
44
  return typeof value === 'number';
47
45
  }
48
46
 
49
- function asArray(value) {
50
- return Array.isArray(value) ? value : [value];
47
+ export function asArray(value) {
48
+ return Array.isArray(value) ? value : value !== undefined ? [value] : [];
51
49
  }
52
50
 
53
- function asSingle(value) {
51
+ export function asSingle(value) {
54
52
  return Array.isArray(value) ? value[0] : value;
55
53
  }
56
54
 
57
- function uniqBy(items, keyGetter = null) {
55
+ export function uniqBy(items, keyGetter = null) {
58
56
  const map = new Map();
59
57
 
60
58
  for (let i = 0, l = items.length; i < l; ++i) {
@@ -67,7 +65,7 @@ function uniqBy(items, keyGetter = null) {
67
65
  return Array.from(map.values());
68
66
  }
69
67
 
70
- function groupBy(items, keyGetter = null) {
68
+ export function groupBy(items, keyGetter = null) {
71
69
  const groups = new Map();
72
70
 
73
71
  for (const item of items) {
@@ -85,7 +83,7 @@ function groupBy(items, keyGetter = null) {
85
83
  return groups;
86
84
  }
87
85
 
88
- function omit(obj, keysToOmit) {
86
+ export function omit(obj, keysToOmit) {
89
87
  keysToOmit = asArray(keysToOmit);
90
88
 
91
89
  const keys = Object.keys(obj);
@@ -102,7 +100,7 @@ function omit(obj, keysToOmit) {
102
100
  return out;
103
101
  }
104
102
 
105
- function difference(arr1, arr2) {
103
+ export function difference(arr1, arr2) {
106
104
  const arr2Set = new Set(arr2);
107
105
  const diff = [];
108
106
 
@@ -117,7 +115,7 @@ function difference(arr1, arr2) {
117
115
  return diff;
118
116
  }
119
117
 
120
- function union(arr1, arr2) {
118
+ export function union(arr1, arr2) {
121
119
  if (arr1.length < SMALL_ARRAY_SIZE && arr2.length < SMALL_ARRAY_SIZE) {
122
120
  return unionSmall(arr1, arr2);
123
121
  } else {
@@ -157,15 +155,15 @@ function unionGeneric(arr1, arr2) {
157
155
  return Array.from(all);
158
156
  }
159
157
 
160
- function last(arr) {
158
+ export function last(arr) {
161
159
  return arr[arr.length - 1];
162
160
  }
163
161
 
164
- function upperFirst(str) {
162
+ export function upperFirst(str) {
165
163
  return str[0].toUpperCase() + str.substring(1);
166
164
  }
167
165
 
168
- function values(obj) {
166
+ export function values(obj) {
169
167
  if (isObject(obj)) {
170
168
  const keys = Object.keys(obj);
171
169
  const values = new Array(keys.length);
@@ -180,7 +178,7 @@ function values(obj) {
180
178
  }
181
179
  }
182
180
 
183
- function once(func) {
181
+ export function once(func) {
184
182
  let called = false;
185
183
  let value = undefined;
186
184
 
@@ -194,7 +192,7 @@ function once(func) {
194
192
  };
195
193
  }
196
194
 
197
- function flatten(arrays) {
195
+ export function flatten(arrays) {
198
196
  const out = [];
199
197
 
200
198
  for (let i = 0, l = arrays.length; i < l; ++i) {
@@ -212,7 +210,7 @@ function flatten(arrays) {
212
210
  return out;
213
211
  }
214
212
 
215
- function get(obj, path) {
213
+ export function get(obj, path) {
216
214
  for (let i = 0, l = path.length; i < l; ++i) {
217
215
  const key = path[i];
218
216
 
@@ -226,7 +224,7 @@ function get(obj, path) {
226
224
  return obj;
227
225
  }
228
226
 
229
- function set(obj, path, value) {
227
+ export function set(obj, path, value) {
230
228
  const inputObj = obj;
231
229
 
232
230
  for (let i = 0, l = path.length - 1; i < l; ++i) {
@@ -264,7 +262,7 @@ function set(obj, path, value) {
264
262
  return inputObj;
265
263
  }
266
264
 
267
- function zipObject(keys, values) {
265
+ export function zipObject(keys, values) {
268
266
  const out = {};
269
267
 
270
268
  for (let i = 0, l = keys.length; i < l; ++i) {
@@ -278,7 +276,7 @@ function zipObject(keys, values) {
278
276
  return out;
279
277
  }
280
278
 
281
- function chunk(arr, chunkSize) {
279
+ export function chunk(arr, chunkSize) {
282
280
  const out = [];
283
281
 
284
282
  for (let i = 0, l = arr.length; i < l; ++i) {
@@ -294,7 +292,20 @@ function chunk(arr, chunkSize) {
294
292
  return out;
295
293
  }
296
294
 
297
- function jsonEquals(val1, val2) {
295
+ // Compare like the database would, but only use loose equality for non-JSON
296
+ // values, so that for example `1` and `'1'` are equal, but `false` and `[]`
297
+ // are not (#1874).
298
+ export function nonStrictEquals(value1, value2) {
299
+ return (
300
+ (!isJsonValue(value1) && !isJsonValue(value2) && value1 == value2) || jsonEquals(value1, value2)
301
+ );
302
+ }
303
+
304
+ function isJsonValue(value) {
305
+ return Array.isArray(value) || isPlainObject(value);
306
+ }
307
+
308
+ export function jsonEquals(val1, val2) {
298
309
  return jsonEqualsBase(val1, val2, compareStrict);
299
310
  }
300
311
 
@@ -380,7 +391,7 @@ function isSafeKey(key) {
380
391
  return isNumber(key) || (isString(key) && key !== '__proto__');
381
392
  }
382
393
 
383
- function mergeMaps(map1, map2) {
394
+ export function mergeMaps(map1, map2) {
384
395
  const map = new Map(map1);
385
396
 
386
397
  if (map2) {
@@ -429,7 +440,7 @@ function getRawTag(value) {
429
440
  // sets, buffers, typed arrays and array buffers are copied, circular
430
441
  // references are kept. Anything else, like functions, errors and built-ins
431
442
  // with internal state like `URL`, is kept as it is.
432
- function cloneDeep(value, clones = new Map()) {
443
+ export function cloneDeep(value, clones = new Map()) {
433
444
  if (!isObject(value)) {
434
445
  return value;
435
446
  } else if (clones.has(value)) {
@@ -500,33 +511,3 @@ function cloneDeep(value, clones = new Map()) {
500
511
  clones.set(value, copy);
501
512
  return copy;
502
513
  }
503
-
504
- module.exports = {
505
- isEmpty,
506
- isString,
507
- isRegExp,
508
- isObject,
509
- hasOwn,
510
- isNumber,
511
- isFunction,
512
- jsonEquals,
513
- isPlainObject,
514
- difference,
515
- upperFirst,
516
- zipObject,
517
- mergeMaps,
518
- cloneDeep,
519
- asSingle,
520
- asArray,
521
- flatten,
522
- groupBy,
523
- uniqBy,
524
- values,
525
- union,
526
- chunk,
527
- omit,
528
- once,
529
- last,
530
- get,
531
- set,
532
- };
@@ -1,10 +1,8 @@
1
- 'use strict';
2
-
3
- const jsonFieldExpressionParser = require('../queryBuilder/parsers/jsonFieldExpressionParser');
4
- const { isObject, hasOwn } = require('./objectUtils');
1
+ import * as jsonFieldExpressionParser from '../queryBuilder/parsers/jsonFieldExpressionParser.js';
2
+ import { isObject, hasOwn } from './objectUtils.js';
5
3
  const cache = new Map();
6
4
 
7
- function parseFieldExpression(expr) {
5
+ export function parseFieldExpression(expr) {
8
6
  let parsedExpr = cache.get(expr);
9
7
 
10
8
  if (parsedExpr !== undefined) {
@@ -50,13 +48,13 @@ function freezeParsedExpr(parsedExpr) {
50
48
  // Keys with a ':' in the data of patches and updates are field expressions like
51
49
  // `'meta:a.b'` that write into json columns, unless they are `declared`: the
52
50
  // `properties` of the schema, or an object with their column names as keys.
53
- function isFieldExpressionKey(key, declared) {
51
+ export function isFieldExpressionKey(key, declared) {
54
52
  return key.includes(':') && !(isObject(declared) && hasOwn(declared, key));
55
53
  }
56
54
 
57
55
  // Returns the json column of a field expression key like `'meta:a'`, or `null`
58
56
  // if the key isn't a field expression or doesn't parse as one.
59
- function getFieldExpressionColumn(key, declared) {
57
+ export function getFieldExpressionColumn(key, declared) {
60
58
  if (isFieldExpressionKey(key, declared)) {
61
59
  try {
62
60
  return parseFieldExpression(key).column;
@@ -72,7 +70,7 @@ function getFieldExpressionColumn(key, declared) {
72
70
  // literal, e.g. `{a,"",b}`. Keys that would otherwise be misread (empty keys,
73
71
  // keys with whitespace, delimiters, quotes or backslashes and `NULL`) are
74
72
  // double-quoted, with quotes and backslashes escaped.
75
- function toPostgresJsonPath(access) {
73
+ export function toPostgresJsonPath(access) {
76
74
  const keys = access.map(({ ref }) => {
77
75
  const key = String(ref);
78
76
  return key === '' || /[{}",\\\s]/.test(key) || key.toUpperCase() === 'NULL'
@@ -91,7 +89,7 @@ function toPostgresJsonPath(access) {
91
89
  // so they can't escape the closing quote either. But knex's Postgres dialect
92
90
  // drops all backslashes in front of an escaped `?`, so if the path contains any,
93
91
  // an escape string literal is used in which backslashes are written as `\134`.
94
- function toPostgresJsonPathLiteral(access) {
92
+ export function toPostgresJsonPathLiteral(access) {
95
93
  const path = toPostgresJsonPath(access).replace(/'/g, "''");
96
94
 
97
95
  if (path.includes('\\?')) {
@@ -101,10 +99,12 @@ function toPostgresJsonPathLiteral(access) {
101
99
  }
102
100
  }
103
101
 
104
- module.exports = {
105
- parseFieldExpression,
106
- isFieldExpressionKey,
107
- getFieldExpressionColumn,
108
- toPostgresJsonPath,
109
- toPostgresJsonPathLiteral,
110
- };
102
+ // Formats the json path of a parsed field expression as a SQL/JSON path like
103
+ // `$."a"[0]`, as MySQL and SQLite use it. Keys are always quoted, so that they
104
+ // can't be misread.
105
+ export function toJsonPath(access) {
106
+ const path = access.map(({ type, ref }) =>
107
+ type === 'array' ? `[${ref}]` : `.${JSON.stringify(String(ref))}`,
108
+ );
109
+ return `$${path.join('')}`;
110
+ }
@@ -1,17 +1,11 @@
1
- 'use strict';
2
-
3
- const { isPromise } = require('./isPromise');
1
+ import { isPromise } from './isPromise.js';
4
2
 
5
3
  // Call `func` after `obj` has been resolved. Call `func` synchronously if
6
4
  // `obj` is not a promise for performance reasons.
7
- function after(obj, func) {
5
+ export function after(obj, func) {
8
6
  if (isPromise(obj)) {
9
7
  return obj.then(func);
10
8
  } else {
11
9
  return func(obj);
12
10
  }
13
11
  }
14
-
15
- module.exports = {
16
- after,
17
- };
@@ -1,17 +1,11 @@
1
- 'use strict';
2
-
3
- const { isPromise } = require('./isPromise');
1
+ import { isPromise } from './isPromise.js';
4
2
 
5
3
  // Return `returnValue` after `obj` has been resolved. Return `returnValue`
6
4
  // synchronously if `obj` is not a promise for performance reasons.
7
- function afterReturn(obj, returnValue) {
5
+ export function afterReturn(obj, returnValue) {
8
6
  if (isPromise(obj)) {
9
7
  return obj.then(() => returnValue);
10
8
  } else {
11
9
  return returnValue;
12
10
  }
13
11
  }
14
-
15
- module.exports = {
16
- afterReturn,
17
- };
@@ -1,17 +1,8 @@
1
- 'use strict';
1
+ import { isPromise } from './isPromise.js';
2
+ import { after } from './after.js';
3
+ import { afterReturn } from './afterReturn.js';
4
+ import { mapAfterAllReturn } from './mapAfterAllReturn.js';
5
+ import { promiseMap } from './map.js';
6
+ import { promiseTry } from './try.js';
2
7
 
3
- const { isPromise } = require('./isPromise');
4
- const { after } = require('./after');
5
- const { afterReturn } = require('./afterReturn');
6
- const { mapAfterAllReturn } = require('./mapAfterAllReturn');
7
- const { promiseMap } = require('./map');
8
- const { promiseTry } = require('./try');
9
-
10
- module.exports = {
11
- isPromise,
12
- after,
13
- afterReturn,
14
- mapAfterAllReturn,
15
- map: promiseMap,
16
- try: promiseTry,
17
- };
8
+ export { isPromise, after, afterReturn, mapAfterAllReturn, promiseMap as map, promiseTry as try };
@@ -1,11 +1,5 @@
1
- 'use strict';
1
+ import { isObject, isFunction } from '../objectUtils.js';
2
2
 
3
- const { isObject, isFunction } = require('../objectUtils');
4
-
5
- function isPromise(obj) {
3
+ export function isPromise(obj) {
6
4
  return isObject(obj) && isFunction(obj.then);
7
5
  }
8
-
9
- module.exports = {
10
- isPromise,
11
- };
@@ -1,9 +1,7 @@
1
- 'use strict';
2
-
3
- const { isPromise } = require('./isPromise');
1
+ import { isPromise } from './isPromise.js';
4
2
 
5
3
  // Works like Bluebird.map.
6
- function promiseMap(items, mapper, opt) {
4
+ export function promiseMap(items, mapper, opt) {
7
5
  switch (items.length) {
8
6
  case 0:
9
7
  return mapZero();
@@ -121,7 +119,3 @@ function rejectWhenFinished(ctx) {
121
119
  ctx.reject(ctx.error);
122
120
  }
123
121
  }
124
-
125
- module.exports = {
126
- promiseMap,
127
- };
@@ -1,11 +1,9 @@
1
- 'use strict';
2
-
3
- const { isPromise } = require('./isPromise');
1
+ import { isPromise } from './isPromise.js';
4
2
 
5
3
  // Map `arr` with `mapper` and after that return `returnValue`. If none of
6
4
  // the mapped values is a promise, return synchronously for performance
7
5
  // reasons.
8
- function mapAfterAllReturn(arr, mapper, returnValue) {
6
+ export function mapAfterAllReturn(arr, mapper, returnValue) {
9
7
  const results = new Array(arr.length);
10
8
  let containsPromise = false;
11
9
 
@@ -23,7 +21,3 @@ function mapAfterAllReturn(arr, mapper, returnValue) {
23
21
  return returnValue;
24
22
  }
25
23
  }
26
-
27
- module.exports = {
28
- mapAfterAllReturn,
29
- };
@@ -1,9 +1,7 @@
1
- 'use strict';
2
-
3
- const { isPromise } = require('./isPromise');
1
+ import { isPromise } from './isPromise.js';
4
2
 
5
3
  // Works like Bluebird.try.
6
- function promiseTry(callback) {
4
+ export function promiseTry(callback) {
7
5
  try {
8
6
  const maybePromise = callback();
9
7
 
@@ -16,7 +14,3 @@ function promiseTry(callback) {
16
14
  return Promise.reject(err);
17
15
  }
18
16
  }
19
-
20
- module.exports = {
21
- promiseTry,
22
- };
@@ -1,11 +1,14 @@
1
- 'use strict';
1
+ import path from 'node:path';
2
+ import { createRequire } from 'node:module';
3
+ import { isString, isFunction } from '../utils/objectUtils.js';
2
4
 
3
- const path = require('path');
4
- const { isString, isFunction } = require('../utils/objectUtils');
5
+ // Model files given as paths are loaded synchronously with `require()`, which
6
+ // on Node >= 20.19 loads both CommonJS and ES modules (without top-level await).
7
+ const require = createRequire(import.meta.url);
5
8
 
6
9
  class ResolveError extends Error {}
7
10
 
8
- function resolveModel(modelRef, modelPaths, errorPrefix) {
11
+ export function resolveModel(modelRef, modelPaths, errorPrefix) {
9
12
  try {
10
13
  if (isString(modelRef)) {
11
14
  if (isAbsolutePath(modelRef)) {
@@ -20,7 +23,7 @@ function resolveModel(modelRef, modelPaths, errorPrefix) {
20
23
 
21
24
  if (!isModelClass(modelRef)) {
22
25
  throw new ResolveError(
23
- `is not a subclass of Model or a file path to a module that exports one. You may be dealing with a require loop. See the documentation section about require loops.`,
26
+ `is not a subclass of Model or a file path to a module that exports one. You may be dealing with circular imports (a require loop). See the documentation section about circular imports.`,
24
27
  );
25
28
  }
26
29
 
@@ -56,19 +59,13 @@ function requireUsingModelPaths(modelRef, modelPaths) {
56
59
  }
57
60
 
58
61
  function requireModel(modelPath) {
59
- /**
60
- * Wrap path string in template literal to prevent
61
- * warnings about Objection.JS being an expression
62
- * in webpack builds.
63
- * @link https://github.com/webpack/webpack/issues/196
64
- */
65
- let mod = require(`${path.resolve(modelPath)}`);
62
+ let mod = require(path.resolve(modelPath));
66
63
  let modelClass = null;
67
64
 
68
65
  if (isModelClass(mod)) {
69
66
  modelClass = mod;
70
67
  } else if (isModelClass(mod.default)) {
71
- // Babel 6 style of exposing default export.
68
+ // ES module or Babel style default export.
72
69
  modelClass = mod.default;
73
70
  } else {
74
71
  Object.keys(mod).forEach((exportName) => {
@@ -100,7 +97,3 @@ function isAbsolutePath(pth) {
100
97
  function isModelClass(maybeModel) {
101
98
  return isFunction(maybeModel) && maybeModel.isObjectionModelClass;
102
99
  }
103
-
104
- module.exports = {
105
- resolveModel,
106
- };
@@ -1,16 +1,9 @@
1
- 'use strict';
2
-
3
1
  const OWNER_JOIN_COLUMN_ALIAS_PREFIX = 'objectiontmpjoin';
4
2
 
5
- function getTempColumn(index) {
3
+ export function getTempColumn(index) {
6
4
  return `${OWNER_JOIN_COLUMN_ALIAS_PREFIX}${index}`;
7
5
  }
8
6
 
9
- function isTempColumn(col) {
7
+ export function isTempColumn(col) {
10
8
  return col.startsWith(OWNER_JOIN_COLUMN_ALIAS_PREFIX);
11
9
  }
12
-
13
- module.exports = {
14
- getTempColumn,
15
- isTempColumn,
16
- };
@@ -1,26 +1,14 @@
1
- 'use strict';
2
-
3
1
  const LOGGED_WARNINGS = new Set();
4
2
 
5
3
  // Log each warning only once.
6
- function warnOnce(message) {
4
+ export function warnOnce(message) {
7
5
  if (!LOGGED_WARNINGS.has(message)) {
8
6
  LOGGED_WARNINGS.add(message);
9
7
  console.warn(`[objection] ${message}`);
10
8
  }
11
9
  }
12
10
 
13
- function deprecate(message) {
14
- warnOnce(message);
15
- }
16
-
17
11
  // Only meant for tests that need to see a warning again.
18
- function resetWarnings() {
12
+ export function resetWarnings() {
19
13
  LOGGED_WARNINGS.clear();
20
14
  }
21
-
22
- module.exports = {
23
- warnOnce,
24
- deprecate,
25
- resetWarnings,
26
- };