@abedmurrar/objection 4.0.0-beta.1 → 4.0.0-beta.11
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/objection.js +4 -26
- package/lib/queryBuilder/FunctionBuilder.js +35 -31
- package/lib/queryBuilder/InternalOptions.js +4 -4
- package/lib/queryBuilder/JoinBuilder.js +46 -45
- package/lib/queryBuilder/QueryBuilder.js +161 -135
- package/lib/queryBuilder/QueryBuilderBase.js +203 -203
- package/lib/queryBuilder/QueryBuilderContext.js +6 -6
- package/lib/queryBuilder/QueryBuilderContextBase.js +12 -8
- package/lib/queryBuilder/QueryBuilderOperationSupport.js +30 -25
- package/lib/queryBuilder/QueryBuilderUserContext.js +4 -4
- package/lib/queryBuilder/RawBuilder.js +15 -13
- package/lib/queryBuilder/ReferenceBuilder.js +25 -23
- package/lib/queryBuilder/RelationExpression.js +29 -20
- package/lib/queryBuilder/StaticHookArguments.js +11 -11
- package/lib/queryBuilder/ValueBuilder.js +20 -19
- package/lib/queryBuilder/expressions.js +8 -18
- package/lib/queryBuilder/functions/mysql.js +18 -42
- package/lib/queryBuilder/graph/GraphAction.js +7 -7
- package/lib/queryBuilder/graph/GraphData.js +4 -4
- package/lib/queryBuilder/graph/GraphFetcher.js +18 -17
- package/lib/queryBuilder/graph/GraphNodeDbExistence.js +45 -12
- package/lib/queryBuilder/graph/GraphOperation.js +4 -4
- package/lib/queryBuilder/graph/GraphOptions.js +5 -5
- package/lib/queryBuilder/graph/GraphUpsert.js +36 -36
- package/lib/queryBuilder/graph/delete/GraphDelete.js +8 -8
- package/lib/queryBuilder/graph/delete/GraphDeleteAction.js +46 -11
- package/lib/queryBuilder/graph/insert/GraphInsert.js +12 -12
- package/lib/queryBuilder/graph/insert/GraphInsertAction.js +59 -21
- package/lib/queryBuilder/graph/insert/JoinRowGraphInsertAction.js +49 -11
- package/lib/queryBuilder/graph/patch/GraphPatch.js +8 -8
- package/lib/queryBuilder/graph/patch/GraphPatchAction.js +52 -19
- package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsert.js +8 -8
- package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsertAction.js +54 -18
- package/lib/queryBuilder/join/JoinResultColumn.js +6 -4
- package/lib/queryBuilder/join/JoinResultParser.js +10 -8
- package/lib/queryBuilder/join/RelationJoiner.js +40 -35
- package/lib/queryBuilder/join/TableNode.js +7 -5
- package/lib/queryBuilder/join/TableTree.js +13 -9
- package/lib/queryBuilder/join/utils.js +8 -8
- package/lib/queryBuilder/operations/DelegateOperation.js +6 -6
- package/lib/queryBuilder/operations/DeleteOperation.js +11 -11
- package/lib/queryBuilder/operations/FindByIdOperation.js +8 -8
- package/lib/queryBuilder/operations/FindByIdsOperation.js +6 -6
- package/lib/queryBuilder/operations/FindOperation.js +23 -23
- package/lib/queryBuilder/operations/FirstOperation.js +6 -6
- package/lib/queryBuilder/operations/FromOperation.js +13 -13
- package/lib/queryBuilder/operations/InsertAndFetchOperation.js +12 -12
- package/lib/queryBuilder/operations/InsertGraphAndFetchOperation.js +10 -10
- package/lib/queryBuilder/operations/InsertGraphOperation.js +11 -11
- package/lib/queryBuilder/operations/InsertOperation.js +23 -22
- package/lib/queryBuilder/operations/InstanceDeleteOperation.js +12 -12
- package/lib/queryBuilder/operations/InstanceFindOperation.js +10 -10
- package/lib/queryBuilder/operations/InstanceInsertOperation.js +6 -6
- package/lib/queryBuilder/operations/InstanceUpdateOperation.js +14 -14
- package/lib/queryBuilder/operations/JoinRelatedOperation.js +13 -13
- package/lib/queryBuilder/operations/KnexOperation.js +6 -6
- package/lib/queryBuilder/operations/MergeOperation.js +11 -11
- package/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js +26 -22
- package/lib/queryBuilder/operations/OnBuildKnexOperation.js +6 -6
- package/lib/queryBuilder/operations/OnBuildOperation.js +6 -6
- package/lib/queryBuilder/operations/OnErrorOperation.js +6 -6
- package/lib/queryBuilder/operations/QueryBuilderOperation.js +6 -4
- package/lib/queryBuilder/operations/RangeOperation.js +7 -6
- package/lib/queryBuilder/operations/RelateOperation.js +6 -6
- package/lib/queryBuilder/operations/ReturningOperation.js +8 -8
- package/lib/queryBuilder/operations/RunAfterOperation.js +6 -6
- package/lib/queryBuilder/operations/RunBeforeOperation.js +6 -6
- package/lib/queryBuilder/operations/UnrelateOperation.js +6 -6
- package/lib/queryBuilder/operations/UpdateAndFetchOperation.js +12 -12
- package/lib/queryBuilder/operations/UpdateOperation.js +24 -24
- package/lib/queryBuilder/operations/UpsertGraphAndFetchOperation.js +10 -10
- package/lib/queryBuilder/operations/UpsertGraphOperation.js +10 -10
- package/lib/queryBuilder/operations/WhereCompositeOperation.js +8 -8
- package/lib/queryBuilder/operations/WhereInOperation.js +11 -9
- package/lib/queryBuilder/operations/eager/EagerOperation.js +11 -9
- package/lib/queryBuilder/operations/eager/JoinEagerOperation.js +10 -12
- package/lib/queryBuilder/operations/eager/NaiveEagerOperation.js +6 -6
- package/lib/queryBuilder/operations/eager/WhereInEagerOperation.js +64 -28
- package/lib/queryBuilder/operations/jsonApi/WhereJsonHasOperation.js +45 -12
- package/lib/queryBuilder/operations/jsonApi/WhereJsonNotObjectOperation.js +45 -12
- package/lib/queryBuilder/operations/jsonApi/WhereJsonOperation.js +45 -12
- package/lib/queryBuilder/operations/jsonApi/WhereJsonOverlapsOperation.js +46 -13
- package/lib/queryBuilder/operations/jsonApi/mysqlJsonApi.js +22 -27
- package/lib/queryBuilder/operations/jsonApi/postgresJsonApi.js +51 -17
- package/lib/queryBuilder/operations/select/SelectOperation.js +12 -12
- package/lib/queryBuilder/operations/select/Selection.js +23 -19
- package/lib/queryBuilder/operations/types.js +8 -0
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeMsSqlOperation.js +13 -12
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeOperation.js +11 -11
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeSqliteOperation.js +10 -10
- package/lib/queryBuilder/transformations/CompositeQueryTransformation.js +6 -6
- package/lib/queryBuilder/transformations/QueryTransformation.js +4 -4
- package/lib/queryBuilder/transformations/WrapMysqlModifySubqueryTransformation.js +11 -8
- package/lib/queryBuilder/transformations/index.js +8 -8
- package/lib/queryBuilder/whereScopes.js +15 -21
- package/lib/relations/RelationDeleteOperation.js +0 -2
- package/lib/relations/RelationFindOperation.js +0 -1
- package/lib/relations/RelationUpdateOperation.js +0 -1
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +0 -1
- package/lib/transaction.js +44 -12
- package/lib/utils/objectUtils.js +6 -1
- package/lib/utils/parseFieldExpression.js +4 -35
- package/lib/utils/promiseUtils/index.js +19 -9
- package/package.json +1 -1
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValueBuilder = void 0;
|
|
4
|
+
exports.val = val;
|
|
5
|
+
const objectUtils_1 = require("../utils/objectUtils");
|
|
6
|
+
const buildUtils_1 = require("../utils/buildUtils");
|
|
7
|
+
const knexUtils_1 = require("../utils/knexUtils");
|
|
8
|
+
const mysqlJsonPath_1 = require("../utils/mysqlJsonPath");
|
|
9
|
+
const expressions_1 = require("./expressions");
|
|
7
10
|
class ValueBuilder {
|
|
8
11
|
constructor(value) {
|
|
9
12
|
this._value = value;
|
|
10
13
|
this._cast = null;
|
|
11
14
|
// Cast objects and arrays to json by default.
|
|
12
|
-
this._toJson = isObject(value);
|
|
15
|
+
this._toJson = (0, objectUtils_1.isObject)(value);
|
|
13
16
|
this._toArray = false;
|
|
14
17
|
this._alias = null;
|
|
15
18
|
}
|
|
@@ -67,29 +70,30 @@ class ValueBuilder {
|
|
|
67
70
|
sql = '?';
|
|
68
71
|
}
|
|
69
72
|
else if (this._toArray) {
|
|
70
|
-
const values = asArray(this._value);
|
|
71
|
-
bindings.push(...values.map((it) => buildArg(it, builder)));
|
|
73
|
+
const values = (0, objectUtils_1.asArray)(this._value);
|
|
74
|
+
bindings.push(...values.map((it) => (0, buildUtils_1.buildArg)(it, builder)));
|
|
72
75
|
sql = `ARRAY[${values.map(() => '?').join(', ')}]`;
|
|
73
76
|
}
|
|
74
77
|
else {
|
|
78
|
+
// A value of the user, which knex binds as it is.
|
|
75
79
|
bindings.push(this._value);
|
|
76
80
|
sql = '?';
|
|
77
81
|
}
|
|
78
82
|
const knex = builder.unsafeKnex();
|
|
79
|
-
const mysql = isMySql(knex);
|
|
83
|
+
const mysql = (0, knexUtils_1.isMySql)(knex);
|
|
80
84
|
if (this._toJson && !this._cast && mysql) {
|
|
81
85
|
// MySQL compares strings and JSON values as strings, so `{}` is never
|
|
82
86
|
// equal to a JSON column without the cast. Postgres casts it implicitly.
|
|
83
|
-
sql = toJsonSql(sql, knex);
|
|
87
|
+
sql = (0, mysqlJsonPath_1.toJsonSql)(sql, knex);
|
|
84
88
|
}
|
|
85
89
|
else if (this._cast && mysql) {
|
|
86
|
-
const type = toMySqlCastType(this._cast);
|
|
90
|
+
const type = (0, mysqlJsonPath_1.toMySqlCastType)(this._cast);
|
|
87
91
|
// MySQL can't cast to a boolean.
|
|
88
|
-
if (isBooleanType(this._cast)) {
|
|
92
|
+
if ((0, mysqlJsonPath_1.isBooleanType)(this._cast)) {
|
|
89
93
|
sql = `(${sql} <> 0)`;
|
|
90
94
|
}
|
|
91
95
|
else if (type === 'JSON') {
|
|
92
|
-
sql = toJsonSql(sql, knex);
|
|
96
|
+
sql = (0, mysqlJsonPath_1.toJsonSql)(sql, knex);
|
|
93
97
|
}
|
|
94
98
|
else {
|
|
95
99
|
sql = `CAST(${sql} AS ${type})`;
|
|
@@ -105,11 +109,8 @@ class ValueBuilder {
|
|
|
105
109
|
return [sql, bindings];
|
|
106
110
|
}
|
|
107
111
|
}
|
|
108
|
-
|
|
112
|
+
exports.ValueBuilder = ValueBuilder;
|
|
113
|
+
(0, expressions_1.addExpressionMethods)(ValueBuilder.prototype);
|
|
109
114
|
function val(val) {
|
|
110
115
|
return new ValueBuilder(val);
|
|
111
116
|
}
|
|
112
|
-
module.exports = {
|
|
113
|
-
ValueBuilder,
|
|
114
|
-
val,
|
|
115
|
-
};
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// Person.ref('age').gte(18).as('isAdult')
|
|
7
|
-
// Pet.ref('order').plus(1)
|
|
8
|
-
// Person.ref('firstName').isNotBlank().or(Person.ref('lastName').isNotBlank())
|
|
9
|
-
//
|
|
10
|
-
// Every method returns a new `FunctionBuilder`. The sql is wrapped in parentheses,
|
|
11
|
-
// so expressions can be nested without thinking about operator precedence. The
|
|
12
|
-
// arguments are bindings like the arguments of `fn()`: strings are values and
|
|
13
|
-
// columns are passed with `ref()` or `Model.ref()`.
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addExpressionMethods = addExpressionMethods;
|
|
4
|
+
exports.expression = expression;
|
|
5
|
+
const objectUtils_1 = require("../utils/objectUtils");
|
|
14
6
|
const COMPARISONS = {
|
|
15
7
|
eq: '=',
|
|
16
8
|
ne: '<>',
|
|
@@ -98,7 +90,9 @@ function createLogic(first, rest, operator) {
|
|
|
98
90
|
return expression(`(${conditions.map(() => '?').join(` ${operator} `)})`, conditions);
|
|
99
91
|
}
|
|
100
92
|
function isSubquery(value) {
|
|
101
|
-
return (isObject(value) &&
|
|
93
|
+
return ((0, objectUtils_1.isObject)(value) &&
|
|
94
|
+
(value.isObjectionQueryBuilderBase ||
|
|
95
|
+
typeof value.toSQL === 'function'));
|
|
102
96
|
}
|
|
103
97
|
function expression(sql, args) {
|
|
104
98
|
// Required here because `FunctionBuilder` itself gets these methods.
|
|
@@ -115,7 +109,3 @@ function addExpressionMethods(prototype) {
|
|
|
115
109
|
});
|
|
116
110
|
}
|
|
117
111
|
}
|
|
118
|
-
module.exports = {
|
|
119
|
-
addExpressionMethods,
|
|
120
|
-
expression,
|
|
121
|
-
};
|
|
@@ -1,35 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
// name the name of the helper: `fn.dateFormat()`
|
|
8
|
-
// sql the name of the SQL function: `DATE_FORMAT`
|
|
9
|
-
// params the parameters, as TypeScript
|
|
10
|
-
// result the type of the result, as TypeScript
|
|
11
|
-
// options `json`: the arguments that are JSON documents. Objects and arrays
|
|
12
|
-
// passed to them are cast to JSON. An array of indexes,
|
|
13
|
-
// 'all', or 'even' (0, 2, 4, ...) / 'odd' (1, 3, 5, ...).
|
|
14
|
-
// `portable`: the function works the same on postgres, so it
|
|
15
|
-
// isn't limited to MySQL.
|
|
16
|
-
// `build`: a function that builds the sql for functions with
|
|
17
|
-
// keywords in their syntax, like `TIMESTAMPDIFF(DAY, ?, ?)`.
|
|
18
|
-
// `aggregate`: the function is an aggregate that `filter()` works
|
|
19
|
-
// with. `true` when every argument is aggregated, or a
|
|
20
|
-
// function that returns how many of the first arguments are.
|
|
21
|
-
// `window`: the function is a window function, which needs `over()`.
|
|
22
|
-
//
|
|
23
|
-
// The arguments are bindings, so strings are values. Columns are passed with
|
|
24
|
-
// `ref()` or `Model.ref()`.
|
|
25
|
-
//
|
|
26
|
-
// The typings in `typings/objection/index.d.ts` are generated from this list
|
|
27
|
-
// with `node scripts/generate-fn-typings.js`.
|
|
28
|
-
//
|
|
29
|
-
// Not included: spatial functions, operators, `CASE`, `JSON_TABLE()`, internal functions and functions
|
|
30
|
-
// that are deprecated (`JSON_MERGE()`, `FOUND_ROWS()`, `VALUES()`,
|
|
31
|
-
// `MASTER_POS_WAIT()`) or that need a component (`VALIDATE_PASSWORD_STRENGTH()`).
|
|
32
|
-
// `fn('NAME', ...args)` calls any function.
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TIMESTAMP_UNITS = exports.INTERVAL_UNITS = exports.MARIADB_UNSUPPORTED = exports.FUNCTIONS = void 0;
|
|
4
|
+
exports.buildOrderBy = buildOrderBy;
|
|
5
|
+
const ReferenceBuilder_1 = require("../ReferenceBuilder");
|
|
33
6
|
const STR = 'string | null';
|
|
34
7
|
const NUM = 'number | null';
|
|
35
8
|
const DEC = 'FnNumeric | null';
|
|
@@ -66,7 +39,9 @@ const INTERVAL_UNITS = [
|
|
|
66
39
|
'DAY_HOUR',
|
|
67
40
|
'YEAR_MONTH',
|
|
68
41
|
];
|
|
42
|
+
exports.INTERVAL_UNITS = INTERVAL_UNITS;
|
|
69
43
|
const TIMESTAMP_UNITS = INTERVAL_UNITS.slice(0, 9);
|
|
44
|
+
exports.TIMESTAMP_UNITS = TIMESTAMP_UNITS;
|
|
70
45
|
const CAST_TYPE = /^((BINARY|CHAR|NCHAR)(\(\d+\))?( CHARACTER SET \w+)?|DATE|(DATETIME|TIME)(\(\d\))?|DECIMAL(\(\d+(, ?\d+)?\))?|DOUBLE|FLOAT(\(\d+\))?|JSON|REAL|(SIGNED|UNSIGNED)( INTEGER)?|YEAR)$/i;
|
|
71
46
|
const CHARSET = /^\w+$/;
|
|
72
47
|
const MATCH_MODES = {
|
|
@@ -540,6 +515,7 @@ const FUNCTIONS = [
|
|
|
540
515
|
{ json: [0, 1], build: buildMemberOf },
|
|
541
516
|
],
|
|
542
517
|
];
|
|
518
|
+
exports.FUNCTIONS = FUNCTIONS;
|
|
543
519
|
// Builders for the functions with keywords in their syntax. They return
|
|
544
520
|
// `[sql, args]`. Keywords are checked against lists, since they can't be bindings.
|
|
545
521
|
function buildDateAdd(name, sql, [date, amount, unit]) {
|
|
@@ -592,6 +568,7 @@ function buildTrim(name, sql, [str, options = {}]) {
|
|
|
592
568
|
}
|
|
593
569
|
}
|
|
594
570
|
function buildChar(name, sql, [codes, options = {}]) {
|
|
571
|
+
// `codes`, `columns` and `exprs` below are arrays after the first line.
|
|
595
572
|
codes = Array.isArray(codes) ? codes : [codes];
|
|
596
573
|
const placeholders = codes.map(() => '?').join(', ');
|
|
597
574
|
if (options.using === undefined) {
|
|
@@ -612,7 +589,10 @@ function buildMatch(name, sql, [columns, search, options = {}]) {
|
|
|
612
589
|
}
|
|
613
590
|
mode = ` ${mode}`;
|
|
614
591
|
}
|
|
615
|
-
return [
|
|
592
|
+
return [
|
|
593
|
+
`MATCH(${columns.map(() => '?').join(', ')}) AGAINST(?${mode})`,
|
|
594
|
+
[...columns, search],
|
|
595
|
+
];
|
|
616
596
|
}
|
|
617
597
|
function buildCountDistinct(name, sql, exprs) {
|
|
618
598
|
return [`COUNT(DISTINCT ${exprs.map(() => '?').join(', ')})`, exprs];
|
|
@@ -653,7 +633,7 @@ function buildOrderBy(name, orderBy) {
|
|
|
653
633
|
return [sql, args];
|
|
654
634
|
}
|
|
655
635
|
function toColumn(column) {
|
|
656
|
-
return typeof column === 'string' ? ref(column) : column;
|
|
636
|
+
return typeof column === 'string' ? (0, ReferenceBuilder_1.ref)(column) : column;
|
|
657
637
|
}
|
|
658
638
|
function buildNtile(name, sql, [buckets]) {
|
|
659
639
|
return [`NTILE(${integer(name, 'buckets', buckets, 1)})`, []];
|
|
@@ -751,12 +731,8 @@ const MARIADB_UNSUPPORTED = {
|
|
|
751
731
|
regexpInstr: MAX_ARGS(2),
|
|
752
732
|
regexpSubstr: MAX_ARGS(2),
|
|
753
733
|
regexpReplace: MAX_ARGS(3),
|
|
754
|
-
jsonValue: (args) => args[2] && args[2].returning !== undefined
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
FUNCTIONS,
|
|
758
|
-
MARIADB_UNSUPPORTED,
|
|
759
|
-
buildOrderBy,
|
|
760
|
-
INTERVAL_UNITS,
|
|
761
|
-
TIMESTAMP_UNITS,
|
|
734
|
+
jsonValue: (args) => args[2] && args[2].returning !== undefined
|
|
735
|
+
? "can't use the returning option on MariaDB"
|
|
736
|
+
: null,
|
|
762
737
|
};
|
|
738
|
+
exports.MARIADB_UNSUPPORTED = MARIADB_UNSUPPORTED;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphAction = void 0;
|
|
4
|
+
const knexUtils_1 = require("../../utils/knexUtils");
|
|
3
5
|
const POSTGRES_MAX_INSERT_BATCH_SIZE = 100;
|
|
4
6
|
const MAX_CONCURRENCY = 100;
|
|
5
7
|
class GraphAction {
|
|
@@ -9,7 +11,7 @@ class GraphAction {
|
|
|
9
11
|
static get ReturningAllSelector() {
|
|
10
12
|
return (op) => {
|
|
11
13
|
// Only select `returning('*')` operation.
|
|
12
|
-
return op.name === 'returning' && op.args.includes('*');
|
|
14
|
+
return (op.name === 'returning' && op.args.includes('*'));
|
|
13
15
|
};
|
|
14
16
|
}
|
|
15
17
|
static getConcurrency(builder, nodes) {
|
|
@@ -33,7 +35,7 @@ class GraphAction {
|
|
|
33
35
|
return GraphAction.getConcurrency(builder, nodes);
|
|
34
36
|
}
|
|
35
37
|
_getBatchSize(builder) {
|
|
36
|
-
return isPostgres(builder.unsafeKnex()) ? POSTGRES_MAX_INSERT_BATCH_SIZE : 1;
|
|
38
|
+
return (0, knexUtils_1.isPostgres)(builder.unsafeKnex()) ? POSTGRES_MAX_INSERT_BATCH_SIZE : 1;
|
|
37
39
|
}
|
|
38
40
|
_resolveReferences(node) {
|
|
39
41
|
if (node.isReference) {
|
|
@@ -49,6 +51,4 @@ class GraphAction {
|
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
|
-
|
|
53
|
-
GraphAction,
|
|
54
|
-
};
|
|
54
|
+
exports.GraphAction = GraphAction;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphData = void 0;
|
|
2
4
|
class GraphData {
|
|
3
5
|
constructor({ graph, currentGraph, graphOptions, nodeDbExistence }) {
|
|
4
6
|
this.graph = graph;
|
|
@@ -7,6 +9,4 @@ class GraphData {
|
|
|
7
9
|
this.nodeDbExistence = nodeDbExistence;
|
|
8
10
|
}
|
|
9
11
|
}
|
|
10
|
-
|
|
11
|
-
GraphData,
|
|
12
|
-
};
|
|
12
|
+
exports.GraphData = GraphData;
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphFetcher = void 0;
|
|
4
|
+
const objectUtils_1 = require("../../utils/objectUtils");
|
|
5
|
+
const ModelGraph_1 = require("../../model/graph/ModelGraph");
|
|
6
|
+
const GraphOptions_1 = require("./GraphOptions");
|
|
7
|
+
const RelationExpression_1 = require("../RelationExpression");
|
|
6
8
|
class GraphFetcher {
|
|
7
9
|
/**
|
|
8
10
|
* Given a graph and options, fetches the current state of that graph
|
|
9
11
|
* from the database and returns it as a ModelGraph instance.
|
|
10
12
|
*/
|
|
11
|
-
static async fetchCurrentGraph({ builder, graph, graphOptions }) {
|
|
13
|
+
static async fetchCurrentGraph({ builder, graph, graphOptions, }) {
|
|
12
14
|
const { rootObjects } = graph;
|
|
13
15
|
const rootIds = getRootIds(rootObjects);
|
|
14
16
|
const modelClass = builder.modelClass();
|
|
15
17
|
if (rootIds.length === 0) {
|
|
16
|
-
return Promise.resolve(ModelGraph.create(modelClass, []));
|
|
18
|
+
return Promise.resolve(ModelGraph_1.ModelGraph.create(modelClass, []));
|
|
17
19
|
}
|
|
18
|
-
const eagerExpr = RelationExpression.fromModelGraph(rootObjects);
|
|
20
|
+
const eagerExpr = RelationExpression_1.RelationExpression.fromModelGraph(rootObjects);
|
|
19
21
|
const models = await modelClass
|
|
20
22
|
.query()
|
|
21
23
|
.childQueryOf(builder, childQueryOptions())
|
|
@@ -24,11 +26,12 @@ class GraphFetcher {
|
|
|
24
26
|
.findByIds(rootIds)
|
|
25
27
|
.withGraphFetched(eagerExpr)
|
|
26
28
|
.internalOptions(fetchQueryInternalOptions());
|
|
27
|
-
return ModelGraph.create(modelClass, models);
|
|
29
|
+
return ModelGraph_1.ModelGraph.create(modelClass, models);
|
|
28
30
|
}
|
|
29
31
|
}
|
|
32
|
+
exports.GraphFetcher = GraphFetcher;
|
|
30
33
|
function getRootIds(rootObjects) {
|
|
31
|
-
return asArray(rootObjects)
|
|
34
|
+
return (0, objectUtils_1.asArray)(rootObjects)
|
|
32
35
|
.filter((it) => it.$hasId())
|
|
33
36
|
.map((root) => root.$id());
|
|
34
37
|
}
|
|
@@ -57,7 +60,7 @@ function buildFetchQuerySelects(graph, graphOptions, eagerExpr) {
|
|
|
57
60
|
};
|
|
58
61
|
}
|
|
59
62
|
function groupNodesByRelationPath(graph, eagerExpr) {
|
|
60
|
-
const nodesByRelationPath = groupBy(graph.nodes, (node) => node.relationPathKey);
|
|
63
|
+
const nodesByRelationPath = (0, objectUtils_1.groupBy)(graph.nodes, (node) => node.relationPathKey);
|
|
61
64
|
// Not all relation paths have nodes. Relations with nulls or empty arrays
|
|
62
65
|
// don't have nodes, but will still need to be fetched. Add these to the
|
|
63
66
|
// map as empty arrays.
|
|
@@ -69,10 +72,10 @@ function groupNodesByRelationPath(graph, eagerExpr) {
|
|
|
69
72
|
return nodesByRelationPath;
|
|
70
73
|
}
|
|
71
74
|
function createFetchSelectModifier(nodes, graphOptions) {
|
|
72
|
-
if (graphOptions.isFetchStrategy(FetchStrategy.OnlyIdentifiers)) {
|
|
75
|
+
if (graphOptions.isFetchStrategy(GraphOptions_1.FetchStrategy.OnlyIdentifiers)) {
|
|
73
76
|
return createIdentifierSelector();
|
|
74
77
|
}
|
|
75
|
-
else if (graphOptions.isFetchStrategy(FetchStrategy.OnlyNeeded)) {
|
|
78
|
+
else if (graphOptions.isFetchStrategy(GraphOptions_1.FetchStrategy.OnlyNeeded)) {
|
|
76
79
|
return createInputColumnSelector(nodes);
|
|
77
80
|
}
|
|
78
81
|
else {
|
|
@@ -101,7 +104,7 @@ function createInputColumnSelector(nodes) {
|
|
|
101
104
|
}
|
|
102
105
|
}
|
|
103
106
|
const selectArr = Array.from(selects.values());
|
|
104
|
-
const idColumns = asArray(builder.fullIdColumn());
|
|
107
|
+
const idColumns = (0, objectUtils_1.asArray)(builder.fullIdColumn());
|
|
105
108
|
for (const idColumn of idColumns) {
|
|
106
109
|
if (!selectArr.includes(idColumn)) {
|
|
107
110
|
// Always select the identifers.
|
|
@@ -142,6 +145,7 @@ function fetchQueryInternalOptions() {
|
|
|
142
145
|
keepImplicitJoinProps: true,
|
|
143
146
|
};
|
|
144
147
|
}
|
|
148
|
+
// `eagerExprNode` is a relation expression node: `$childNames` and a property per child.
|
|
145
149
|
function forEachPath(eagerExprNode, cb, path = []) {
|
|
146
150
|
for (const relation of eagerExprNode.$childNames) {
|
|
147
151
|
path.push(relation);
|
|
@@ -150,6 +154,3 @@ function forEachPath(eagerExprNode, cb, path = []) {
|
|
|
150
154
|
path.pop();
|
|
151
155
|
}
|
|
152
156
|
}
|
|
153
|
-
module.exports = {
|
|
154
|
-
GraphFetcher,
|
|
155
|
-
};
|
|
@@ -1,7 +1,42 @@
|
|
|
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.GraphNodeDbExistence = void 0;
|
|
37
|
+
const GraphData_1 = require("./GraphData");
|
|
38
|
+
const GraphAction_1 = require("./GraphAction");
|
|
39
|
+
const promiseUtils = __importStar(require("../../utils/promiseUtils"));
|
|
5
40
|
/**
|
|
6
41
|
* This weird little class is responsible for checking (and maintaining information)
|
|
7
42
|
* whether certain nodes exist in the database.
|
|
@@ -19,12 +54,12 @@ class GraphNodeDbExistence {
|
|
|
19
54
|
* creates an instance of GraphNodeDbExistence that can be used to
|
|
20
55
|
* synchronously check if a node exist in the database.
|
|
21
56
|
*/
|
|
22
|
-
static async create({ builder, graph, graphOptions, currentGraph }) {
|
|
57
|
+
static async create({ builder, graph, graphOptions, currentGraph, }) {
|
|
23
58
|
if (graphOptions.isInsertOnly()) {
|
|
24
59
|
// With insertGraph, we never want to do anything but inserts.
|
|
25
60
|
return GraphNodeDbExistence.createEveryNodeExistsExistence();
|
|
26
61
|
}
|
|
27
|
-
const graphData = new GraphData({
|
|
62
|
+
const graphData = new GraphData_1.GraphData({
|
|
28
63
|
graph,
|
|
29
64
|
graphOptions,
|
|
30
65
|
currentGraph,
|
|
@@ -54,6 +89,7 @@ class GraphNodeDbExistence {
|
|
|
54
89
|
return !idMap.has(node.obj.$idKey());
|
|
55
90
|
}
|
|
56
91
|
}
|
|
92
|
+
exports.GraphNodeDbExistence = GraphNodeDbExistence;
|
|
57
93
|
function createMayNotExistMap(graphData) {
|
|
58
94
|
const { graph, currentGraph, graphOptions } = graphData;
|
|
59
95
|
const mayNotExist = new Map();
|
|
@@ -94,11 +130,11 @@ function hasNodeById(currentGraph, nodeToFind) {
|
|
|
94
130
|
idProps.every((idProp) => node.obj[idProp] === nodeToFind.obj[idProp]));
|
|
95
131
|
});
|
|
96
132
|
}
|
|
97
|
-
async function createDontExistMap({ builder, mayNotExist, mayNotExistNodes }) {
|
|
133
|
+
async function createDontExistMap({ builder, mayNotExist, mayNotExistNodes, }) {
|
|
98
134
|
const dontExist = cloneExistenceMap(mayNotExist);
|
|
99
135
|
const existenceCheckQueries = createExistenceCheckQueries({ builder, mayNotExist });
|
|
100
136
|
const results = await promiseUtils.map(existenceCheckQueries, (builder) => builder.execute(), {
|
|
101
|
-
concurrency: GraphAction.getConcurrency(builder, mayNotExistNodes),
|
|
137
|
+
concurrency: GraphAction_1.GraphAction.getConcurrency(builder, mayNotExistNodes),
|
|
102
138
|
});
|
|
103
139
|
// Remove all items from the mayNotExist map that we have just proven to exist
|
|
104
140
|
// by executing the existenceCheckQueries.
|
|
@@ -113,7 +149,7 @@ async function createDontExistMap({ builder, mayNotExist, mayNotExistNodes }) {
|
|
|
113
149
|
// Now only items that don't exist in the db are left in this map.
|
|
114
150
|
return dontExist;
|
|
115
151
|
}
|
|
116
|
-
function createExistenceCheckQueries({ builder, mayNotExist }) {
|
|
152
|
+
function createExistenceCheckQueries({ builder, mayNotExist, }) {
|
|
117
153
|
const builders = [];
|
|
118
154
|
for (const [modelClass, idMap] of mayNotExist.entries()) {
|
|
119
155
|
const ids = Array.from(idMap.values());
|
|
@@ -141,6 +177,3 @@ function cloneExistenceMap(exixtenseMap) {
|
|
|
141
177
|
}
|
|
142
178
|
return clone;
|
|
143
179
|
}
|
|
144
|
-
module.exports = {
|
|
145
|
-
GraphNodeDbExistence,
|
|
146
|
-
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphOperation = void 0;
|
|
2
4
|
class GraphOperation {
|
|
3
5
|
constructor(graphData) {
|
|
4
6
|
this.graphData = graphData;
|
|
@@ -16,6 +18,4 @@ class GraphOperation {
|
|
|
16
18
|
return [];
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
|
-
|
|
20
|
-
GraphOperation,
|
|
21
|
-
};
|
|
21
|
+
exports.GraphOperation = GraphOperation;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FetchStrategy = exports.GraphOptions = void 0;
|
|
2
4
|
const NO_RELATE = 'noRelate';
|
|
3
5
|
const NO_UNRELATE = 'noUnrelate';
|
|
4
6
|
const NO_INSERT = 'noInsert';
|
|
@@ -15,6 +17,7 @@ const FetchStrategy = {
|
|
|
15
17
|
Everything: 'Everything',
|
|
16
18
|
OnlyNeeded: 'OnlyNeeded',
|
|
17
19
|
};
|
|
20
|
+
exports.FetchStrategy = FetchStrategy;
|
|
18
21
|
class GraphOptions {
|
|
19
22
|
constructor(options) {
|
|
20
23
|
if (options instanceof GraphOptions) {
|
|
@@ -147,6 +150,7 @@ class GraphOptions {
|
|
|
147
150
|
}
|
|
148
151
|
}
|
|
149
152
|
}
|
|
153
|
+
exports.GraphOptions = GraphOptions;
|
|
150
154
|
function getCurrentNode(node, graphData) {
|
|
151
155
|
if (!graphData || !node) {
|
|
152
156
|
return null;
|
|
@@ -159,7 +163,3 @@ function getNode(currentNode, graph) {
|
|
|
159
163
|
}
|
|
160
164
|
return graph.nodeForNode(currentNode);
|
|
161
165
|
}
|
|
162
|
-
module.exports = {
|
|
163
|
-
GraphOptions,
|
|
164
|
-
FetchStrategy,
|
|
165
|
-
};
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphUpsert = void 0;
|
|
4
|
+
const ModelGraph_1 = require("../../model/graph/ModelGraph");
|
|
5
|
+
const ModelGraphEdge_1 = require("../../model/graph/ModelGraphEdge");
|
|
6
|
+
const ModelGraphBuilder_1 = require("../../model/graph/ModelGraphBuilder");
|
|
7
|
+
const GraphFetcher_1 = require("../graph/GraphFetcher");
|
|
8
|
+
const GraphInsert_1 = require("./insert/GraphInsert");
|
|
9
|
+
const GraphPatch_1 = require("./patch/GraphPatch");
|
|
10
|
+
const GraphDelete_1 = require("./delete/GraphDelete");
|
|
11
|
+
const GraphRecursiveUpsert_1 = require("./recursiveUpsert/GraphRecursiveUpsert");
|
|
12
|
+
const GraphOptions_1 = require("./GraphOptions");
|
|
13
|
+
const ValidationError_1 = require("../../model/ValidationError");
|
|
14
|
+
const RelationExpression_1 = require("../RelationExpression");
|
|
15
|
+
const GraphNodeDbExistence_1 = require("./GraphNodeDbExistence");
|
|
16
|
+
const GraphData_1 = require("./GraphData");
|
|
17
|
+
const objectUtils_1 = require("../../utils/objectUtils");
|
|
16
18
|
class GraphUpsert {
|
|
17
|
-
constructor({ rootModelClass, objects, upsertOptions }) {
|
|
19
|
+
constructor({ rootModelClass, objects, upsertOptions, }) {
|
|
18
20
|
checkCanBeConvertedToModels(rootModelClass, objects);
|
|
19
21
|
this.objects = rootModelClass.ensureModelArray(objects, GraphUpsert.modelOptions);
|
|
20
22
|
this.isArray = Array.isArray(objects);
|
|
@@ -25,8 +27,8 @@ class GraphUpsert {
|
|
|
25
27
|
}
|
|
26
28
|
run(builder) {
|
|
27
29
|
const modelClass = builder.modelClass();
|
|
28
|
-
const graphOptions = new GraphOptions(this.upsertOpt);
|
|
29
|
-
const graph = ModelGraph.create(modelClass, this.objects);
|
|
30
|
+
const graphOptions = new GraphOptions_1.GraphOptions(this.upsertOpt);
|
|
31
|
+
const graph = ModelGraph_1.ModelGraph.create(modelClass, this.objects);
|
|
30
32
|
assignDbRefsAsRelateProps(graph);
|
|
31
33
|
return createGraphData(builder, graphOptions, graph)
|
|
32
34
|
.then(checkForErrors(builder))
|
|
@@ -35,10 +37,11 @@ class GraphUpsert {
|
|
|
35
37
|
.then(returnResult(this.objects, this.isArray));
|
|
36
38
|
}
|
|
37
39
|
}
|
|
40
|
+
exports.GraphUpsert = GraphUpsert;
|
|
38
41
|
function checkCanBeConvertedToModels(modelClass, objects) {
|
|
39
|
-
asArray(objects).forEach((obj) => {
|
|
40
|
-
if (!isObject(obj)) {
|
|
41
|
-
throw createNotModelError(modelClass, obj);
|
|
42
|
+
(0, objectUtils_1.asArray)(objects).forEach((obj) => {
|
|
43
|
+
if (!(0, objectUtils_1.isObject)(obj)) {
|
|
44
|
+
throw (0, ModelGraphBuilder_1.createNotModelError)(modelClass, obj);
|
|
42
45
|
}
|
|
43
46
|
});
|
|
44
47
|
}
|
|
@@ -47,25 +50,25 @@ function assignDbRefsAsRelateProps(graph) {
|
|
|
47
50
|
if (!node.parentEdge || !node.parentEdge.relation || !node.isDbReference) {
|
|
48
51
|
continue;
|
|
49
52
|
}
|
|
50
|
-
node.parentEdge.relation.setRelateProp(node.obj, asArray(node.dbReference));
|
|
53
|
+
node.parentEdge.relation.setRelateProp(node.obj, (0, objectUtils_1.asArray)(node.dbReference));
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
async function createGraphData(builder, graphOptions, graph) {
|
|
54
57
|
const currentGraph = await fetchCurrentGraph(builder, graphOptions, graph);
|
|
55
|
-
const nodeDbExistence = await GraphNodeDbExistence.create({
|
|
58
|
+
const nodeDbExistence = await GraphNodeDbExistence_1.GraphNodeDbExistence.create({
|
|
56
59
|
builder,
|
|
57
60
|
graph,
|
|
58
61
|
graphOptions,
|
|
59
62
|
currentGraph,
|
|
60
63
|
});
|
|
61
|
-
return new GraphData({ graph, currentGraph, graphOptions, nodeDbExistence });
|
|
64
|
+
return new GraphData_1.GraphData({ graph, currentGraph, graphOptions, nodeDbExistence });
|
|
62
65
|
}
|
|
63
66
|
function fetchCurrentGraph(builder, graphOptions, graph) {
|
|
64
67
|
if (graphOptions.isInsertOnly()) {
|
|
65
|
-
return Promise.resolve(ModelGraph.createEmpty());
|
|
68
|
+
return Promise.resolve(ModelGraph_1.ModelGraph.createEmpty());
|
|
66
69
|
}
|
|
67
70
|
else {
|
|
68
|
-
return GraphFetcher.fetchCurrentGraph({ builder, graph, graphOptions });
|
|
71
|
+
return GraphFetcher_1.GraphFetcher.fetchCurrentGraph({ builder, graph, graphOptions });
|
|
69
72
|
}
|
|
70
73
|
}
|
|
71
74
|
// Remove branches from the graph that require no operations. For example
|
|
@@ -110,7 +113,7 @@ function pruneDeletedBranches(graphData) {
|
|
|
110
113
|
}
|
|
111
114
|
function findRoots(nodes) {
|
|
112
115
|
const nodeSet = new Set(nodes);
|
|
113
|
-
return uniqBy(nodes.filter((node) => {
|
|
116
|
+
return (0, objectUtils_1.uniqBy)(nodes.filter((node) => {
|
|
114
117
|
let parentNode = node.parentNode;
|
|
115
118
|
while (parentNode) {
|
|
116
119
|
if (nodeSet.has(parentNode)) {
|
|
@@ -178,10 +181,10 @@ function checkForUnallowedRelationErrors(graphData, builder) {
|
|
|
178
181
|
const allowedExpression = builder.allowedGraphExpression();
|
|
179
182
|
if (allowedExpression) {
|
|
180
183
|
const rootsObjs = graph.nodes.filter((node) => !node.parentEdge).map((node) => node.obj);
|
|
181
|
-
const expression = RelationExpression.fromModelGraph(rootsObjs);
|
|
184
|
+
const expression = RelationExpression_1.RelationExpression.fromModelGraph(rootsObjs);
|
|
182
185
|
if (!allowedExpression.isSubExpression(expression)) {
|
|
183
186
|
throw builder.modelClass().createValidationError({
|
|
184
|
-
type: ValidationErrorType.UnallowedRelation,
|
|
187
|
+
type: ValidationError_1.ValidationErrorType.UnallowedRelation,
|
|
185
188
|
message: 'trying to upsert an unallowed relation',
|
|
186
189
|
});
|
|
187
190
|
}
|
|
@@ -192,9 +195,9 @@ function checkForUnallowedReferenceErrors(graphData, builder) {
|
|
|
192
195
|
if (graphOptions.allowRefs()) {
|
|
193
196
|
return;
|
|
194
197
|
}
|
|
195
|
-
if (graph.edges.some((edge) => edge.type === ModelGraphEdge.Type.Reference)) {
|
|
198
|
+
if (graph.edges.some((edge) => edge.type === ModelGraphEdge_1.ModelGraphEdge.Type.Reference)) {
|
|
196
199
|
throw builder.modelClass().createValidationError({
|
|
197
|
-
type: ValidationErrorType.InvalidGraph,
|
|
200
|
+
type: ValidationError_1.ValidationErrorType.InvalidGraph,
|
|
198
201
|
message: '#ref references are not allowed in a graph by default. see the allowRefs insert/upsert graph option',
|
|
199
202
|
});
|
|
200
203
|
}
|
|
@@ -211,8 +214,8 @@ function checkForHasManyRelateErrors(graphData) {
|
|
|
211
214
|
function executeOperations(builder) {
|
|
212
215
|
return (graphData) => {
|
|
213
216
|
const operations = graphData.graphOptions.isInsertOnly()
|
|
214
|
-
? [GraphInsert]
|
|
215
|
-
: [GraphDelete, GraphInsert, GraphPatch, GraphRecursiveUpsert];
|
|
217
|
+
? [GraphInsert_1.GraphInsert]
|
|
218
|
+
: [GraphDelete_1.GraphDelete, GraphInsert_1.GraphInsert, GraphPatch_1.GraphPatch, GraphRecursiveUpsert_1.GraphRecursiveUpsert];
|
|
216
219
|
return operations.reduce((promise, Operation) => {
|
|
217
220
|
const operation = new Operation(graphData);
|
|
218
221
|
const actions = operation.createActions();
|
|
@@ -226,6 +229,3 @@ function executeActions(builder, actions) {
|
|
|
226
229
|
function returnResult(objects, isArray) {
|
|
227
230
|
return () => (isArray ? objects : objects[0]);
|
|
228
231
|
}
|
|
229
|
-
module.exports = {
|
|
230
|
-
GraphUpsert,
|
|
231
|
-
};
|