@abedmurrar/objection 4.0.0-beta.6 → 4.0.0-beta.8
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.
- package/README.md +1 -1
- package/lib/initialize.js +4 -5
- package/lib/model/AjvValidator.js +24 -21
- package/lib/model/Model.js +116 -114
- package/lib/model/ModifierNotFoundError.js +4 -4
- package/lib/model/NotFoundError.js +4 -4
- package/lib/model/RelationDoesNotExistError.js +4 -4
- package/lib/model/ValidationError.js +8 -8
- package/lib/model/Validator.js +7 -6
- package/lib/model/getModel.js +4 -4
- package/lib/model/graph/ModelGraph.js +9 -7
- package/lib/model/graph/ModelGraphBuilder.js +24 -24
- package/lib/model/graph/ModelGraphEdge.js +4 -4
- package/lib/model/graph/ModelGraphNode.js +17 -11
- package/lib/model/inheritModel.js +3 -4
- package/lib/model/modelBindKnex.js +12 -13
- package/lib/model/modelClone.js +15 -16
- package/lib/model/modelColPropMap.js +7 -8
- package/lib/model/modelConcurrency.js +6 -7
- package/lib/model/modelId.js +4 -5
- package/lib/model/modelJsonAttributes.js +10 -11
- package/lib/model/modelParseRelations.js +5 -6
- package/lib/model/modelQueryProps.js +12 -13
- package/lib/model/modelSet.js +17 -18
- package/lib/model/modelTableMetadata.js +9 -10
- package/lib/model/modelToJson.js +13 -14
- package/lib/model/modelUtils.js +7 -7
- package/lib/model/modelValidate.js +5 -6
- package/lib/model/modelValues.js +10 -10
- package/lib/model/modelVisitor.js +3 -4
- package/lib/transaction.js +44 -12
- package/package.json +1 -1
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
};
|
package/lib/model/modelToJson.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
};
|
package/lib/model/modelUtils.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
2
|
-
|
|
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
|
-
};
|
package/lib/model/modelValues.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
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
|
-
};
|
package/lib/transaction.js
CHANGED
|
@@ -1,13 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.transaction = transaction;
|
|
37
|
+
const promiseUtils = __importStar(require("./utils/promiseUtils"));
|
|
38
|
+
const objectUtils_1 = require("./utils/objectUtils");
|
|
39
|
+
function transaction(...transactionArgs) {
|
|
5
40
|
// There must be at least one model class and the callback.
|
|
6
|
-
if (
|
|
41
|
+
if (transactionArgs.length < 2) {
|
|
7
42
|
return Promise.reject(new Error('objection.transaction: provide at least one Model class to bind to the transaction or a knex instance'));
|
|
8
43
|
}
|
|
9
|
-
let args = Array.from(
|
|
10
|
-
if (!isModelClass(args[0]) && isFunction(args[0].transaction)) {
|
|
44
|
+
let args = Array.from(transactionArgs);
|
|
45
|
+
if (!isModelClass(args[0]) && (0, objectUtils_1.isFunction)(args[0].transaction)) {
|
|
11
46
|
const knex = args[0];
|
|
12
47
|
args = args.slice(1);
|
|
13
48
|
return knex.transaction.apply(knex, args);
|
|
@@ -45,7 +80,7 @@ transaction.start = function (modelClassOrKnex) {
|
|
|
45
80
|
if (isModelClass(modelClassOrKnex)) {
|
|
46
81
|
knex = modelClassOrKnex.knex();
|
|
47
82
|
}
|
|
48
|
-
if (!knex || !isFunction(knex.transaction)) {
|
|
83
|
+
if (!knex || !(0, objectUtils_1.isFunction)(knex.transaction)) {
|
|
49
84
|
return Promise.reject(new Error('objection.transaction.start: first argument must be a model class or a knex instance'));
|
|
50
85
|
}
|
|
51
86
|
return new Promise((resolve, reject) => {
|
|
@@ -59,8 +94,5 @@ transaction.start = function (modelClassOrKnex) {
|
|
|
59
94
|
});
|
|
60
95
|
};
|
|
61
96
|
function isModelClass(maybeModel) {
|
|
62
|
-
return isFunction(maybeModel) && maybeModel.isObjectionModelClass;
|
|
97
|
+
return (0, objectUtils_1.isFunction)(maybeModel) && maybeModel.isObjectionModelClass;
|
|
63
98
|
}
|
|
64
|
-
module.exports = {
|
|
65
|
-
transaction,
|
|
66
|
-
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abedmurrar/objection",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.8",
|
|
4
4
|
"description": "An SQL-friendly ORM for Node.js. A fork of objection.js with strict TypeScript types and MySQL support.",
|
|
5
5
|
"main": "lib/objection.js",
|
|
6
6
|
"type": "commonjs",
|