@abedmurrar/objection 4.0.0-beta.5 → 4.0.0-beta.7

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 (61) hide show
  1. package/lib/initialize.js +4 -5
  2. package/lib/model/AjvValidator.js +24 -21
  3. package/lib/model/Model.js +116 -114
  4. package/lib/model/ModifierNotFoundError.js +4 -4
  5. package/lib/model/NotFoundError.js +4 -4
  6. package/lib/model/RelationDoesNotExistError.js +4 -4
  7. package/lib/model/ValidationError.js +8 -8
  8. package/lib/model/Validator.js +7 -6
  9. package/lib/model/getModel.js +4 -4
  10. package/lib/model/graph/ModelGraph.js +9 -7
  11. package/lib/model/graph/ModelGraphBuilder.js +24 -24
  12. package/lib/model/graph/ModelGraphEdge.js +4 -4
  13. package/lib/model/graph/ModelGraphNode.js +17 -11
  14. package/lib/model/inheritModel.js +3 -4
  15. package/lib/model/modelBindKnex.js +12 -13
  16. package/lib/model/modelClone.js +15 -16
  17. package/lib/model/modelColPropMap.js +7 -8
  18. package/lib/model/modelConcurrency.js +6 -7
  19. package/lib/model/modelId.js +4 -5
  20. package/lib/model/modelJsonAttributes.js +10 -11
  21. package/lib/model/modelParseRelations.js +5 -6
  22. package/lib/model/modelQueryProps.js +12 -13
  23. package/lib/model/modelSet.js +17 -18
  24. package/lib/model/modelTableMetadata.js +9 -10
  25. package/lib/model/modelToJson.js +13 -14
  26. package/lib/model/modelUtils.js +7 -7
  27. package/lib/model/modelValidate.js +5 -6
  28. package/lib/model/modelValues.js +10 -10
  29. package/lib/model/modelVisitor.js +3 -4
  30. package/lib/queryBuilder/InternalOptions.js +4 -4
  31. package/lib/queryBuilder/QueryBuilder.js +161 -135
  32. package/lib/queryBuilder/QueryBuilderBase.js +203 -203
  33. package/lib/queryBuilder/QueryBuilderContext.js +6 -6
  34. package/lib/queryBuilder/QueryBuilderContextBase.js +12 -8
  35. package/lib/queryBuilder/QueryBuilderOperationSupport.js +30 -25
  36. package/lib/queryBuilder/QueryBuilderUserContext.js +4 -4
  37. package/lib/queryBuilder/StaticHookArguments.js +11 -11
  38. package/lib/queryBuilder/graph/GraphAction.js +7 -7
  39. package/lib/queryBuilder/graph/GraphData.js +4 -4
  40. package/lib/queryBuilder/graph/GraphFetcher.js +18 -17
  41. package/lib/queryBuilder/graph/GraphNodeDbExistence.js +45 -12
  42. package/lib/queryBuilder/graph/GraphOperation.js +4 -4
  43. package/lib/queryBuilder/graph/GraphOptions.js +5 -5
  44. package/lib/queryBuilder/graph/GraphUpsert.js +36 -36
  45. package/lib/queryBuilder/graph/delete/GraphDelete.js +8 -8
  46. package/lib/queryBuilder/graph/delete/GraphDeleteAction.js +46 -11
  47. package/lib/queryBuilder/graph/insert/GraphInsert.js +12 -12
  48. package/lib/queryBuilder/graph/insert/GraphInsertAction.js +59 -21
  49. package/lib/queryBuilder/graph/insert/JoinRowGraphInsertAction.js +49 -11
  50. package/lib/queryBuilder/graph/patch/GraphPatch.js +8 -8
  51. package/lib/queryBuilder/graph/patch/GraphPatchAction.js +52 -19
  52. package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsert.js +8 -8
  53. package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsertAction.js +54 -18
  54. package/lib/queryBuilder/operations/types.js +2 -2
  55. package/lib/queryBuilder/transformations/CompositeQueryTransformation.js +6 -6
  56. package/lib/queryBuilder/transformations/QueryTransformation.js +4 -4
  57. package/lib/queryBuilder/transformations/WrapMysqlModifySubqueryTransformation.js +11 -8
  58. package/lib/queryBuilder/transformations/index.js +8 -8
  59. package/lib/queryBuilder/whereScopes.js +15 -21
  60. package/lib/transaction.js +44 -12
  61. package/package.json +1 -1
@@ -1,8 +1,11 @@
1
- 'use strict';
2
- const { defineNonEnumerableProperty } = require('./modelUtils');
3
- const { isPromise } = require('../utils/promiseUtils');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchTableMetadata = fetchTableMetadata;
4
+ exports.tableMetadata = tableMetadata;
5
+ const modelUtils_1 = require("./modelUtils");
6
+ const promiseUtils_1 = require("../utils/promiseUtils");
4
7
  const TABLE_METADATA = '$$tableMetadata';
5
- function fetchTableMetadata(modelClass, { parentBuilder = null, knex = null, force = false, table = null } = {}) {
8
+ function fetchTableMetadata(modelClass, { parentBuilder = null, knex = null, force = false, table = null, } = {}) {
6
9
  // The table isn't necessarily same as `modelClass.getTableName()` for example if
7
10
  // a view is queried instead.
8
11
  if (!table) {
@@ -22,7 +25,7 @@ function fetchTableMetadata(modelClass, { parentBuilder = null, knex = null, for
22
25
  // Memoize metadata but only for modelClass. The hasOwnProperty check
23
26
  // will fail for subclasses and the value gets recreated.
24
27
  if (!Object.hasOwn(modelClass, TABLE_METADATA)) {
25
- defineNonEnumerableProperty(modelClass, TABLE_METADATA, new Map());
28
+ (0, modelUtils_1.defineNonEnumerableProperty)(modelClass, TABLE_METADATA, new Map());
26
29
  }
27
30
  // The cache needs to be checked in addition to calling tableMetadata
28
31
  // because the cache may contain a temporary promise in which case
@@ -54,7 +57,7 @@ function fetchTableMetadata(modelClass, { parentBuilder = null, knex = null, for
54
57
  function tableMetadata(modelClass, { table } = {}) {
55
58
  if (Object.hasOwn(modelClass, TABLE_METADATA)) {
56
59
  const metadata = modelClass[TABLE_METADATA].get(table || modelClass.getTableName());
57
- if (isPromise(metadata)) {
60
+ if ((0, promiseUtils_1.isPromise)(metadata)) {
58
61
  return null;
59
62
  }
60
63
  else {
@@ -65,7 +68,3 @@ function tableMetadata(modelClass, { table } = {}) {
65
68
  return null;
66
69
  }
67
70
  }
68
- module.exports = {
69
- fetchTableMetadata,
70
- tableMetadata,
71
- };
@@ -1,7 +1,10 @@
1
- 'use strict';
2
- const { isInternalProp } = require('../utils/internalPropUtils');
3
- const { mergeQueryProps } = require('./modelQueryProps');
4
- const { isObject, cloneDeep, isFunction } = require('../utils/objectUtils');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toJson = toJson;
4
+ exports.toDatabaseJson = toDatabaseJson;
5
+ const internalPropUtils_1 = require("../utils/internalPropUtils");
6
+ const modelQueryProps_1 = require("./modelQueryProps");
7
+ const objectUtils_1 = require("../utils/objectUtils");
5
8
  const EMPTY_ARRAY = [];
6
9
  function toJson(model, optIn) {
7
10
  const modelClass = model.constructor;
@@ -29,7 +32,7 @@ function toDatabaseJson(model, builder) {
29
32
  };
30
33
  let json = toDatabaseJsonImpl(model, opt);
31
34
  json = model.$formatDatabaseJson(json);
32
- return mergeQueryProps(model, json, opt.omitFromJson, builder);
35
+ return (0, modelQueryProps_1.mergeQueryProps)(model, json, opt.omitFromJson, builder);
33
36
  }
34
37
  function getVirtuals(opt) {
35
38
  if (!opt) {
@@ -91,10 +94,10 @@ function assignJsonValue(json, key, value, opt) {
91
94
  const type = typeof value;
92
95
  if (type !== 'function' &&
93
96
  type !== 'undefined' &&
94
- !isInternalProp(key) &&
97
+ !(0, internalPropUtils_1.isInternalProp)(key) &&
95
98
  !shouldOmit(opt, key) &&
96
99
  shouldPick(opt, key)) {
97
- if (isObject(value)) {
100
+ if ((0, objectUtils_1.isObject)(value)) {
98
101
  json[key] = toJsonObject(value, opt);
99
102
  }
100
103
  else {
@@ -113,7 +116,7 @@ function assignVirtualAttributes(json, model, vAttr, opt) {
113
116
  for (let i = 0, l = vAttr.length; i < l; ++i) {
114
117
  const key = vAttr[i];
115
118
  let value = model[key];
116
- if (isFunction(value)) {
119
+ if ((0, objectUtils_1.isFunction)(value)) {
117
120
  value = value.call(model);
118
121
  }
119
122
  assignJsonValue(json, key, value, opt);
@@ -132,7 +135,7 @@ function toJsonObject(value, opt) {
132
135
  return value;
133
136
  }
134
137
  else if (opt.cloneObjects) {
135
- return cloneDeep(value);
138
+ return (0, objectUtils_1.cloneDeep)(value);
136
139
  }
137
140
  else {
138
141
  return value;
@@ -142,7 +145,7 @@ function toJsonArray(value, opt) {
142
145
  const ret = new Array(value.length);
143
146
  for (let i = 0, l = ret.length; i < l; ++i) {
144
147
  const item = value[i];
145
- if (isObject(item)) {
148
+ if ((0, objectUtils_1.isObject)(item)) {
146
149
  ret[i] = toJsonObject(item, opt);
147
150
  }
148
151
  else {
@@ -151,7 +154,3 @@ function toJsonArray(value, opt) {
151
154
  }
152
155
  return ret;
153
156
  }
154
- module.exports = {
155
- toJson,
156
- toDatabaseJson,
157
- };
@@ -1,5 +1,10 @@
1
- 'use strict';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.staticHiddenProps = exports.hiddenProps = void 0;
4
+ exports.defineNonEnumerableProperty = defineNonEnumerableProperty;
5
+ exports.keyByProps = keyByProps;
2
6
  const hiddenProps = ['$$queryProps'];
7
+ exports.hiddenProps = hiddenProps;
3
8
  const staticHiddenProps = [
4
9
  '$$knex',
5
10
  '$$validator',
@@ -16,6 +21,7 @@ const staticHiddenProps = [
16
21
  '$$idRelationProperty',
17
22
  '$$virtualAttributes',
18
23
  ];
24
+ exports.staticHiddenProps = staticHiddenProps;
19
25
  function defineNonEnumerableProperty(obj, prop, value) {
20
26
  Object.defineProperty(obj, prop, {
21
27
  enumerable: false,
@@ -32,9 +38,3 @@ function keyByProps(models, props) {
32
38
  }
33
39
  return map;
34
40
  }
35
- module.exports = {
36
- hiddenProps,
37
- staticHiddenProps,
38
- defineNonEnumerableProperty,
39
- keyByProps,
40
- };
@@ -1,5 +1,7 @@
1
- 'use strict';
2
- const { clone } = require('./modelClone');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validate = validate;
4
+ const modelClone_1 = require("./modelClone");
3
5
  function validate(model, json, options = {}) {
4
6
  json = json || model;
5
7
  const inputJson = json;
@@ -12,7 +14,7 @@ function validate(model, json, options = {}) {
12
14
  // TODO 1: This should use `json.$toJson()` since we always validate the input representation!
13
15
  // TODO 2: This should also keep the relations in the object because some validators may
14
16
  // depend on the relations.
15
- json = clone(json, true, true);
17
+ json = (0, modelClone_1.clone)(json, true, true);
16
18
  // We can mutate `json` now that we took a copy of it.
17
19
  options = Object.assign({}, options, { mutable: true });
18
20
  }
@@ -35,6 +37,3 @@ function validate(model, json, options = {}) {
35
37
  return json;
36
38
  }
37
39
  }
38
- module.exports = {
39
- validate,
40
- };
@@ -1,8 +1,15 @@
1
- 'use strict';
2
- const { isObject } = require('../utils/objectUtils');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PROP_KEY_PREFIX = void 0;
4
+ exports.propToStr = propToStr;
5
+ exports.values = values;
6
+ exports.hasProps = hasProps;
7
+ exports.propKey = propKey;
8
+ const objectUtils_1 = require("../utils/objectUtils");
3
9
  // Property keys needs to be prefixed with a non-numeric character so that
4
10
  // they are not considered indexes when used as object keys.
5
11
  const PROP_KEY_PREFIX = 'k_';
12
+ exports.PROP_KEY_PREFIX = PROP_KEY_PREFIX;
6
13
  function values(model, args) {
7
14
  switch (args.length) {
8
15
  case 1:
@@ -94,7 +101,7 @@ function propToStr(value) {
94
101
  else if (Buffer.isBuffer(value)) {
95
102
  return value.toString('hex');
96
103
  }
97
- else if (isObject(value)) {
104
+ else if ((0, objectUtils_1.isObject)(value)) {
98
105
  return JSON.stringify(value);
99
106
  }
100
107
  else {
@@ -104,10 +111,3 @@ function propToStr(value) {
104
111
  function isNullOrUndefined(val) {
105
112
  return val === null || val === undefined;
106
113
  }
107
- module.exports = {
108
- PROP_KEY_PREFIX,
109
- propToStr,
110
- values,
111
- hasProps,
112
- propKey,
113
- };
@@ -1,4 +1,6 @@
1
- 'use strict';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.visitModels = visitModels;
2
4
  function visitModels(models, modelClass, visitor) {
3
5
  doVisit(models, modelClass, null, null, visitor);
4
6
  }
@@ -29,6 +31,3 @@ function visitOne(model, modelClass, parent, rel, visitor) {
29
31
  }
30
32
  }
31
33
  }
32
- module.exports = {
33
- visitModels,
34
- };
@@ -1,4 +1,6 @@
1
- 'use strict';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InternalOptions = void 0;
2
4
  class InternalOptions {
3
5
  constructor() {
4
6
  this.skipUndefined = false;
@@ -19,6 +21,4 @@ class InternalOptions {
19
21
  return copy;
20
22
  }
21
23
  }
22
- module.exports = {
23
- InternalOptions,
24
- };
24
+ exports.InternalOptions = InternalOptions;