@e22m4u/js-repository 0.8.4 → 0.8.6
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 +37 -49
- package/dist/cjs/index.cjs +762 -353
- package/eslint.config.js +1 -0
- package/package.json +14 -14
- package/src/adapter/adapter-loader.js +9 -4
- package/src/adapter/adapter-registry.js +3 -1
- package/src/adapter/builtin/memory-adapter.js +29 -13
- package/src/adapter/decorator/data-sanitizing-decorator.js +2 -1
- package/src/adapter/decorator/default-values-decorator.js +2 -1
- package/src/adapter/decorator/fields-filtering-decorator.js +14 -7
- package/src/adapter/decorator/inclusion-decorator.js +14 -7
- package/src/adapter/decorator/property-uniqueness-decorator.js +2 -1
- package/src/adapter/decorator/required-property-decorator.js +2 -1
- package/src/definition/datasource/datasource-definition-validator.js +6 -3
- package/src/definition/definition-registry.js +8 -4
- package/src/definition/model/model-data-sanitizer.js +4 -2
- package/src/definition/model/model-definition-utils.js +74 -35
- package/src/definition/model/model-definition-utils.spec.js +2 -6
- package/src/definition/model/model-definition-validator.js +10 -5
- package/src/definition/model/properties/primary-keys-definition-validator.js +4 -2
- package/src/definition/model/properties/properties-definition-validator.js +36 -18
- package/src/definition/model/properties/property-uniqueness-validator.js +30 -18
- package/src/definition/model/properties/property-uniqueness-validator.spec.js +734 -74
- package/src/definition/model/properties/required-property-validator.js +7 -12
- package/src/definition/model/properties/required-property-validator.spec.js +7 -46
- package/src/definition/model/relations/relations-definition-validator.js +70 -33
- package/src/filter/fields-clause-tool.js +31 -12
- package/src/filter/include-clause-tool.js +38 -15
- package/src/filter/operator-clause-tool.js +55 -23
- package/src/filter/order-clause-tool.js +36 -13
- package/src/filter/slice-clause-tool.js +16 -7
- package/src/filter/where-clause-tool.js +24 -10
- package/src/relations/belongs-to-resolver.js +44 -20
- package/src/relations/has-many-resolver.js +52 -25
- package/src/relations/has-one-resolver.js +58 -27
- package/src/relations/references-many-resolver.js +24 -11
- package/src/repository/repository-registry.js +3 -1
- package/src/repository/repository.js +2 -1
- package/src/utils/capitalize.js +3 -1
- package/src/utils/clone-deep.js +6 -2
- package/src/utils/exclude-object-keys.js +2 -1
- package/src/utils/get-value-by-path.js +6 -2
- package/src/utils/is-deep-equal.js +21 -7
- package/src/utils/is-promise.js +6 -2
- package/src/utils/model-name-to-model-key.js +2 -1
- package/src/utils/select-object-keys.js +9 -4
- package/src/utils/singularize.js +3 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -40,8 +40,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
40
40
|
|
|
41
41
|
// src/utils/is-promise.js
|
|
42
42
|
function isPromise(value) {
|
|
43
|
-
if (!value)
|
|
44
|
-
|
|
43
|
+
if (!value) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (typeof value !== "object") {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
45
49
|
return typeof value.then === "function";
|
|
46
50
|
}
|
|
47
51
|
var init_is_promise = __esm({
|
|
@@ -53,7 +57,9 @@ var init_is_promise = __esm({
|
|
|
53
57
|
|
|
54
58
|
// src/utils/capitalize.js
|
|
55
59
|
function capitalize(string) {
|
|
56
|
-
if (!string || typeof string !== "string")
|
|
60
|
+
if (!string || typeof string !== "string") {
|
|
61
|
+
return string;
|
|
62
|
+
}
|
|
57
63
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
58
64
|
}
|
|
59
65
|
var init_capitalize = __esm({
|
|
@@ -65,11 +71,15 @@ var init_capitalize = __esm({
|
|
|
65
71
|
|
|
66
72
|
// src/utils/clone-deep.js
|
|
67
73
|
function cloneDeep(value) {
|
|
68
|
-
if (!value)
|
|
74
|
+
if (!value) {
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
69
77
|
const types = [Number, String, Boolean];
|
|
70
78
|
let result;
|
|
71
79
|
types.forEach((type) => {
|
|
72
|
-
if (value instanceof type)
|
|
80
|
+
if (value instanceof type) {
|
|
81
|
+
result = type(value);
|
|
82
|
+
}
|
|
73
83
|
});
|
|
74
84
|
if (result === void 0) {
|
|
75
85
|
if (Array.isArray(value)) {
|
|
@@ -109,7 +119,9 @@ var init_clone_deep = __esm({
|
|
|
109
119
|
|
|
110
120
|
// src/utils/singularize.js
|
|
111
121
|
function singularize(noun) {
|
|
112
|
-
if (!noun || typeof noun !== "string")
|
|
122
|
+
if (!noun || typeof noun !== "string") {
|
|
123
|
+
return noun;
|
|
124
|
+
}
|
|
113
125
|
const endings = {
|
|
114
126
|
ves: "fe",
|
|
115
127
|
ies: "y",
|
|
@@ -135,17 +147,27 @@ var init_singularize = __esm({
|
|
|
135
147
|
function isDeepEqual(firstValue, secondValue) {
|
|
136
148
|
const cached = /* @__PURE__ */ new WeakMap();
|
|
137
149
|
const compare = /* @__PURE__ */ __name((a, b) => {
|
|
138
|
-
if (a === null || b === null)
|
|
139
|
-
|
|
150
|
+
if (a === null || b === null) {
|
|
151
|
+
return a === b;
|
|
152
|
+
}
|
|
153
|
+
if (typeof a !== "object" || typeof b !== "object") {
|
|
154
|
+
return a === b;
|
|
155
|
+
}
|
|
140
156
|
const dataTypeA = Array.isArray(a) ? "array" : "object";
|
|
141
157
|
const dataTypeB = Array.isArray(b) ? "array" : "object";
|
|
142
|
-
if (dataTypeA !== dataTypeB)
|
|
158
|
+
if (dataTypeA !== dataTypeB) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
143
161
|
const keysA = Object.keys(a);
|
|
144
162
|
const keysB = Object.keys(b);
|
|
145
|
-
if (keysA.length !== keysB.length)
|
|
163
|
+
if (keysA.length !== keysB.length) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
146
166
|
const symbolsA = Object.getOwnPropertySymbols(a);
|
|
147
167
|
const symbolsB = Object.getOwnPropertySymbols(b);
|
|
148
|
-
if (symbolsA.length !== symbolsB.length)
|
|
168
|
+
if (symbolsA.length !== symbolsB.length) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
149
171
|
let setForA = cached.get(a);
|
|
150
172
|
if (setForA == null) {
|
|
151
173
|
setForA = /* @__PURE__ */ new Set();
|
|
@@ -164,10 +186,14 @@ function isDeepEqual(firstValue, secondValue) {
|
|
|
164
186
|
setForB.add(a);
|
|
165
187
|
const propertyNamesA = [...keysA, ...symbolsA];
|
|
166
188
|
for (const propertyNameA of propertyNamesA) {
|
|
167
|
-
if (!Object.prototype.hasOwnProperty.call(b, propertyNameA))
|
|
189
|
+
if (!Object.prototype.hasOwnProperty.call(b, propertyNameA)) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
168
192
|
const propertyValueA = a[propertyNameA];
|
|
169
193
|
const propertyValueB = b[propertyNameA];
|
|
170
|
-
if (!compare(propertyValueA, propertyValueB))
|
|
194
|
+
if (!compare(propertyValueA, propertyValueB)) {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
171
197
|
}
|
|
172
198
|
return true;
|
|
173
199
|
}, "compare");
|
|
@@ -316,8 +342,12 @@ var init_string_to_regexp = __esm({
|
|
|
316
342
|
|
|
317
343
|
// src/utils/get-value-by-path.js
|
|
318
344
|
function getValueByPath(obj, path, orElse = void 0) {
|
|
319
|
-
if (!obj || typeof obj !== "object")
|
|
320
|
-
|
|
345
|
+
if (!obj || typeof obj !== "object") {
|
|
346
|
+
return orElse;
|
|
347
|
+
}
|
|
348
|
+
if (!path || typeof path !== "string") {
|
|
349
|
+
return orElse;
|
|
350
|
+
}
|
|
321
351
|
const keys = path.split(".");
|
|
322
352
|
let value = obj;
|
|
323
353
|
for (const key of keys) {
|
|
@@ -339,27 +369,32 @@ var init_get_value_by_path = __esm({
|
|
|
339
369
|
|
|
340
370
|
// src/utils/select-object-keys.js
|
|
341
371
|
function selectObjectKeys(obj, keys) {
|
|
342
|
-
if (!obj || typeof obj !== "object" || Array.isArray(obj))
|
|
372
|
+
if (!obj || typeof obj !== "object" || Array.isArray(obj)) {
|
|
343
373
|
throw new InvalidArgumentError(
|
|
344
374
|
"The first argument of selectObjectKeys should be an Object, but %v was given.",
|
|
345
375
|
obj
|
|
346
376
|
);
|
|
347
|
-
|
|
377
|
+
}
|
|
378
|
+
if (!Array.isArray(keys)) {
|
|
348
379
|
throw new InvalidArgumentError(
|
|
349
380
|
"The second argument of selectObjectKeys should be an Array of String, but %v was given.",
|
|
350
381
|
keys
|
|
351
382
|
);
|
|
383
|
+
}
|
|
352
384
|
keys.forEach((key) => {
|
|
353
|
-
if (typeof key !== "string")
|
|
385
|
+
if (typeof key !== "string") {
|
|
354
386
|
throw new InvalidArgumentError(
|
|
355
387
|
"The second argument of selectObjectKeys should be an Array of String, but %v was given.",
|
|
356
388
|
key
|
|
357
389
|
);
|
|
390
|
+
}
|
|
358
391
|
});
|
|
359
392
|
const result = {};
|
|
360
393
|
const allKeys = Object.keys(obj);
|
|
361
394
|
allKeys.forEach((key) => {
|
|
362
|
-
if (keys.includes(key))
|
|
395
|
+
if (keys.includes(key)) {
|
|
396
|
+
result[key] = obj[key];
|
|
397
|
+
}
|
|
363
398
|
});
|
|
364
399
|
return result;
|
|
365
400
|
}
|
|
@@ -373,11 +408,12 @@ var init_select_object_keys = __esm({
|
|
|
373
408
|
|
|
374
409
|
// src/utils/exclude-object-keys.js
|
|
375
410
|
function excludeObjectKeys(obj, keys) {
|
|
376
|
-
if (typeof obj !== "object" || !obj || Array.isArray(obj))
|
|
411
|
+
if (typeof obj !== "object" || !obj || Array.isArray(obj)) {
|
|
377
412
|
throw new InvalidArgumentError(
|
|
378
413
|
"Cannot exclude keys from a non-Object value, %v was given.",
|
|
379
414
|
obj
|
|
380
415
|
);
|
|
416
|
+
}
|
|
381
417
|
const result = { ...obj };
|
|
382
418
|
keys = Array.isArray(keys) ? keys : [keys];
|
|
383
419
|
keys.forEach((key) => delete result[key]);
|
|
@@ -393,11 +429,12 @@ var init_exclude_object_keys = __esm({
|
|
|
393
429
|
|
|
394
430
|
// src/utils/model-name-to-model-key.js
|
|
395
431
|
function modelNameToModelKey(modelName) {
|
|
396
|
-
if (!modelName || typeof modelName !== "string" || /\s/.test(modelName))
|
|
432
|
+
if (!modelName || typeof modelName !== "string" || /\s/.test(modelName)) {
|
|
397
433
|
throw new InvalidArgumentError(
|
|
398
434
|
"The model name should be a non-empty String without spaces, but %v was given.",
|
|
399
435
|
modelName
|
|
400
436
|
);
|
|
437
|
+
}
|
|
401
438
|
return modelName.toLowerCase().replace(/[-_]/g, "");
|
|
402
439
|
}
|
|
403
440
|
var init_model_name_to_model_key = __esm({
|
|
@@ -444,21 +481,24 @@ var init_slice_clause_tool = __esm({
|
|
|
444
481
|
* @returns {object[]}
|
|
445
482
|
*/
|
|
446
483
|
slice(entities, skip = void 0, limit = void 0) {
|
|
447
|
-
if (!Array.isArray(entities))
|
|
484
|
+
if (!Array.isArray(entities)) {
|
|
448
485
|
throw new InvalidArgumentError(
|
|
449
486
|
"The first argument of SliceClauseTool.slice should be an Array, but %v was given.",
|
|
450
487
|
entities
|
|
451
488
|
);
|
|
452
|
-
|
|
489
|
+
}
|
|
490
|
+
if (skip != null && typeof skip !== "number") {
|
|
453
491
|
throw new InvalidArgumentError(
|
|
454
492
|
'The provided option "skip" should be a Number, but %v was given.',
|
|
455
493
|
skip
|
|
456
494
|
);
|
|
457
|
-
|
|
495
|
+
}
|
|
496
|
+
if (limit != null && typeof limit !== "number") {
|
|
458
497
|
throw new InvalidArgumentError(
|
|
459
498
|
'The provided option "limit" should be a Number, but %v was given.',
|
|
460
499
|
limit
|
|
461
500
|
);
|
|
501
|
+
}
|
|
462
502
|
skip = skip || 0;
|
|
463
503
|
limit = limit || entities.length;
|
|
464
504
|
return entities.slice(skip, skip + limit);
|
|
@@ -469,12 +509,15 @@ var init_slice_clause_tool = __esm({
|
|
|
469
509
|
* @param {number|undefined} skip
|
|
470
510
|
*/
|
|
471
511
|
static validateSkipClause(skip) {
|
|
472
|
-
if (skip == null)
|
|
473
|
-
|
|
512
|
+
if (skip == null) {
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
if (typeof skip !== "number") {
|
|
474
516
|
throw new InvalidArgumentError(
|
|
475
517
|
'The provided option "skip" should be a Number, but %v was given.',
|
|
476
518
|
skip
|
|
477
519
|
);
|
|
520
|
+
}
|
|
478
521
|
}
|
|
479
522
|
/**
|
|
480
523
|
* Validate limit clause.
|
|
@@ -482,12 +525,15 @@ var init_slice_clause_tool = __esm({
|
|
|
482
525
|
* @param {number|undefined} limit
|
|
483
526
|
*/
|
|
484
527
|
static validateLimitClause(limit) {
|
|
485
|
-
if (limit == null)
|
|
486
|
-
|
|
528
|
+
if (limit == null) {
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
if (typeof limit !== "number") {
|
|
487
532
|
throw new InvalidArgumentError(
|
|
488
533
|
'The provided option "limit" should be a Number, but %v was given.',
|
|
489
534
|
limit
|
|
490
535
|
);
|
|
536
|
+
}
|
|
491
537
|
}
|
|
492
538
|
};
|
|
493
539
|
__name(_SliceClauseTool, "SliceClauseTool");
|
|
@@ -526,21 +572,30 @@ var init_order_clause_tool = __esm({
|
|
|
526
572
|
* @param {string|string[]|undefined} clause
|
|
527
573
|
*/
|
|
528
574
|
sort(entities, clause) {
|
|
529
|
-
if (clause == null)
|
|
530
|
-
|
|
531
|
-
|
|
575
|
+
if (clause == null) {
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
if (Array.isArray(clause) === false) {
|
|
579
|
+
clause = [clause];
|
|
580
|
+
}
|
|
581
|
+
if (!clause.length) {
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
532
584
|
const mapping = [];
|
|
533
585
|
clause.forEach((key, index) => {
|
|
534
|
-
if (!key || typeof key !== "string")
|
|
586
|
+
if (!key || typeof key !== "string") {
|
|
535
587
|
throw new InvalidArgumentError(
|
|
536
588
|
'The provided option "order" should be a non-empty String or an Array of non-empty String, but %v was given.',
|
|
537
589
|
key
|
|
538
590
|
);
|
|
591
|
+
}
|
|
539
592
|
let reverse = 1;
|
|
540
593
|
const matches = key.match(/\s+(A|DE)SC$/i);
|
|
541
594
|
if (matches) {
|
|
542
595
|
key = key.replace(/\s+(A|DE)SC/i, "");
|
|
543
|
-
if (matches[1].toLowerCase() === "de")
|
|
596
|
+
if (matches[1].toLowerCase() === "de") {
|
|
597
|
+
reverse = -1;
|
|
598
|
+
}
|
|
544
599
|
}
|
|
545
600
|
mapping[index] = { key, reverse };
|
|
546
601
|
});
|
|
@@ -552,15 +607,22 @@ var init_order_clause_tool = __esm({
|
|
|
552
607
|
* @param {string|string[]|undefined} clause
|
|
553
608
|
*/
|
|
554
609
|
static validateOrderClause(clause) {
|
|
555
|
-
if (clause == null)
|
|
556
|
-
|
|
557
|
-
|
|
610
|
+
if (clause == null) {
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
if (Array.isArray(clause) === false) {
|
|
614
|
+
clause = [clause];
|
|
615
|
+
}
|
|
616
|
+
if (!clause.length) {
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
558
619
|
clause.forEach((field) => {
|
|
559
|
-
if (!field || typeof field !== "string")
|
|
620
|
+
if (!field || typeof field !== "string") {
|
|
560
621
|
throw new InvalidArgumentError(
|
|
561
622
|
'The provided option "order" should be a non-empty String or an Array of non-empty String, but %v was given.',
|
|
562
623
|
field
|
|
563
624
|
);
|
|
625
|
+
}
|
|
564
626
|
});
|
|
565
627
|
}
|
|
566
628
|
/**
|
|
@@ -570,15 +632,22 @@ var init_order_clause_tool = __esm({
|
|
|
570
632
|
* @returns {string[]|undefined}
|
|
571
633
|
*/
|
|
572
634
|
static normalizeOrderClause(clause) {
|
|
573
|
-
if (clause == null)
|
|
574
|
-
|
|
575
|
-
|
|
635
|
+
if (clause == null) {
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
if (Array.isArray(clause) === false) {
|
|
639
|
+
clause = [clause];
|
|
640
|
+
}
|
|
641
|
+
if (!clause.length) {
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
576
644
|
clause.forEach((field) => {
|
|
577
|
-
if (!field || typeof field !== "string")
|
|
645
|
+
if (!field || typeof field !== "string") {
|
|
578
646
|
throw new InvalidArgumentError(
|
|
579
647
|
'The provided option "order" should be a non-empty String or an Array of non-empty String, but %v was given.',
|
|
580
648
|
field
|
|
581
649
|
);
|
|
650
|
+
}
|
|
582
651
|
});
|
|
583
652
|
return clause;
|
|
584
653
|
}
|
|
@@ -629,8 +698,12 @@ var init_operator_clause_tool = __esm({
|
|
|
629
698
|
}
|
|
630
699
|
}
|
|
631
700
|
if (type1 === "string" && type2 === "string") {
|
|
632
|
-
if (val1 > val2)
|
|
633
|
-
|
|
701
|
+
if (val1 > val2) {
|
|
702
|
+
return 1;
|
|
703
|
+
}
|
|
704
|
+
if (val1 < val2) {
|
|
705
|
+
return -1;
|
|
706
|
+
}
|
|
634
707
|
return 0;
|
|
635
708
|
}
|
|
636
709
|
return NaN;
|
|
@@ -643,11 +716,12 @@ var init_operator_clause_tool = __esm({
|
|
|
643
716
|
* @returns {boolean|undefined}
|
|
644
717
|
*/
|
|
645
718
|
testAll(clause, value) {
|
|
646
|
-
if (!clause || typeof clause !== "object" || Array.isArray(clause))
|
|
719
|
+
if (!clause || typeof clause !== "object" || Array.isArray(clause)) {
|
|
647
720
|
throw new InvalidArgumentError(
|
|
648
721
|
"The first argument of OperatorUtils.testAll should be an Object, but %v was given.",
|
|
649
722
|
clause
|
|
650
723
|
);
|
|
724
|
+
}
|
|
651
725
|
const operatorMap = {
|
|
652
726
|
eq: this.testEqNeq,
|
|
653
727
|
neq: this.testEqNeq,
|
|
@@ -702,13 +776,18 @@ var init_operator_clause_tool = __esm({
|
|
|
702
776
|
* @returns {boolean|undefined}
|
|
703
777
|
*/
|
|
704
778
|
testEqNeq(clause, value) {
|
|
705
|
-
if (!clause || typeof clause !== "object")
|
|
779
|
+
if (!clause || typeof clause !== "object") {
|
|
706
780
|
throw new InvalidArgumentError(
|
|
707
781
|
"The first argument of OperatorUtils.testEqNeq should be an Object, but %v was given.",
|
|
708
782
|
clause
|
|
709
783
|
);
|
|
710
|
-
|
|
711
|
-
if ("
|
|
784
|
+
}
|
|
785
|
+
if ("eq" in clause) {
|
|
786
|
+
return this.compare(clause.eq, value, true) === 0;
|
|
787
|
+
}
|
|
788
|
+
if ("neq" in clause) {
|
|
789
|
+
return this.compare(clause.neq, value, true) !== 0;
|
|
790
|
+
}
|
|
712
791
|
}
|
|
713
792
|
/**
|
|
714
793
|
* Test lt/gt/lte/gte operator.
|
|
@@ -746,15 +825,24 @@ var init_operator_clause_tool = __esm({
|
|
|
746
825
|
* @returns {boolean|undefined}
|
|
747
826
|
*/
|
|
748
827
|
testGtLt(clause, value) {
|
|
749
|
-
if (!clause || typeof clause !== "object")
|
|
828
|
+
if (!clause || typeof clause !== "object") {
|
|
750
829
|
throw new InvalidArgumentError(
|
|
751
830
|
"The first argument of OperatorUtils.testGtLt should be an Object, but %v was given.",
|
|
752
831
|
clause
|
|
753
832
|
);
|
|
754
|
-
|
|
755
|
-
if ("
|
|
756
|
-
|
|
757
|
-
|
|
833
|
+
}
|
|
834
|
+
if ("gt" in clause) {
|
|
835
|
+
return this.compare(value, clause.gt) > 0;
|
|
836
|
+
}
|
|
837
|
+
if ("gte" in clause) {
|
|
838
|
+
return this.compare(value, clause.gte) >= 0;
|
|
839
|
+
}
|
|
840
|
+
if ("lt" in clause) {
|
|
841
|
+
return this.compare(value, clause.lt) < 0;
|
|
842
|
+
}
|
|
843
|
+
if ("lte" in clause) {
|
|
844
|
+
return this.compare(value, clause.lte) <= 0;
|
|
845
|
+
}
|
|
758
846
|
}
|
|
759
847
|
/**
|
|
760
848
|
* Test inc operator.
|
|
@@ -771,11 +859,12 @@ var init_operator_clause_tool = __esm({
|
|
|
771
859
|
* @returns {boolean|undefined}
|
|
772
860
|
*/
|
|
773
861
|
testInq(clause, value) {
|
|
774
|
-
if (!clause || typeof clause !== "object")
|
|
862
|
+
if (!clause || typeof clause !== "object") {
|
|
775
863
|
throw new InvalidArgumentError(
|
|
776
864
|
"The first argument of OperatorUtils.testInq should be an Object, but %v was given.",
|
|
777
865
|
clause
|
|
778
866
|
);
|
|
867
|
+
}
|
|
779
868
|
if ("inq" in clause && clause.inq !== void 0) {
|
|
780
869
|
if (!clause.inq || !Array.isArray(clause.inq)) {
|
|
781
870
|
throw new InvalidOperatorValueError(
|
|
@@ -807,11 +896,12 @@ var init_operator_clause_tool = __esm({
|
|
|
807
896
|
* @returns {boolean|undefined}
|
|
808
897
|
*/
|
|
809
898
|
testNin(clause, value) {
|
|
810
|
-
if (!clause || typeof clause !== "object")
|
|
899
|
+
if (!clause || typeof clause !== "object") {
|
|
811
900
|
throw new InvalidArgumentError(
|
|
812
901
|
"The first argument of OperatorUtils.testNin should be an Object, but %v was given.",
|
|
813
902
|
clause
|
|
814
903
|
);
|
|
904
|
+
}
|
|
815
905
|
if ("nin" in clause && clause.nin !== void 0) {
|
|
816
906
|
if (!clause.nin || !Array.isArray(clause.nin)) {
|
|
817
907
|
throw new InvalidOperatorValueError(
|
|
@@ -840,11 +930,12 @@ var init_operator_clause_tool = __esm({
|
|
|
840
930
|
* @returns {boolean|undefined}
|
|
841
931
|
*/
|
|
842
932
|
testBetween(clause, value) {
|
|
843
|
-
if (!clause || typeof clause !== "object")
|
|
933
|
+
if (!clause || typeof clause !== "object") {
|
|
844
934
|
throw new InvalidArgumentError(
|
|
845
935
|
"The first argument of OperatorUtils.testBetween should be an Object, but %v was given.",
|
|
846
936
|
clause
|
|
847
937
|
);
|
|
938
|
+
}
|
|
848
939
|
if ("between" in clause && clause.between !== void 0) {
|
|
849
940
|
if (!Array.isArray(clause.between) || clause.between.length !== 2) {
|
|
850
941
|
throw new InvalidOperatorValueError(
|
|
@@ -871,11 +962,12 @@ var init_operator_clause_tool = __esm({
|
|
|
871
962
|
* @returns {boolean|undefined}
|
|
872
963
|
*/
|
|
873
964
|
testExists(clause, value) {
|
|
874
|
-
if (!clause || typeof clause !== "object")
|
|
965
|
+
if (!clause || typeof clause !== "object") {
|
|
875
966
|
throw new InvalidArgumentError(
|
|
876
967
|
"The first argument of OperatorUtils.testExists should be an Object, but %v was given.",
|
|
877
968
|
clause
|
|
878
969
|
);
|
|
970
|
+
}
|
|
879
971
|
if ("exists" in clause && clause.exists !== void 0) {
|
|
880
972
|
if (typeof clause.exists !== "boolean") {
|
|
881
973
|
throw new InvalidOperatorValueError(
|
|
@@ -902,14 +994,16 @@ var init_operator_clause_tool = __esm({
|
|
|
902
994
|
* @returns {boolean|undefined}
|
|
903
995
|
*/
|
|
904
996
|
testLike(clause, value) {
|
|
905
|
-
if (!clause || typeof clause !== "object" || Array.isArray(clause))
|
|
997
|
+
if (!clause || typeof clause !== "object" || Array.isArray(clause)) {
|
|
906
998
|
throw new InvalidArgumentError(
|
|
907
999
|
"The first argument of OperatorUtils.testLike should be an Object, but %v was given.",
|
|
908
1000
|
clause
|
|
909
1001
|
);
|
|
1002
|
+
}
|
|
910
1003
|
if ("like" in clause && clause.like !== void 0) {
|
|
911
|
-
if (typeof clause.like !== "string")
|
|
1004
|
+
if (typeof clause.like !== "string") {
|
|
912
1005
|
throw new InvalidOperatorValueError("like", "a String", clause.like);
|
|
1006
|
+
}
|
|
913
1007
|
return likeToRegexp(clause.like).test(value);
|
|
914
1008
|
}
|
|
915
1009
|
}
|
|
@@ -928,11 +1022,12 @@ var init_operator_clause_tool = __esm({
|
|
|
928
1022
|
* @returns {boolean|undefined}
|
|
929
1023
|
*/
|
|
930
1024
|
testNlike(clause, value) {
|
|
931
|
-
if (!clause || typeof clause !== "object" || Array.isArray(clause))
|
|
1025
|
+
if (!clause || typeof clause !== "object" || Array.isArray(clause)) {
|
|
932
1026
|
throw new InvalidArgumentError(
|
|
933
1027
|
"The first argument of OperatorUtils.testNlike should be an Object, but %v was given.",
|
|
934
1028
|
clause
|
|
935
1029
|
);
|
|
1030
|
+
}
|
|
936
1031
|
if ("nlike" in clause && clause.nlike !== void 0) {
|
|
937
1032
|
if (typeof clause.nlike !== "string") {
|
|
938
1033
|
throw new InvalidOperatorValueError("nlike", "a String", clause.nlike);
|
|
@@ -955,11 +1050,12 @@ var init_operator_clause_tool = __esm({
|
|
|
955
1050
|
* @returns {boolean|undefined}
|
|
956
1051
|
*/
|
|
957
1052
|
testIlike(clause, value) {
|
|
958
|
-
if (!clause || typeof clause !== "object" || Array.isArray(clause))
|
|
1053
|
+
if (!clause || typeof clause !== "object" || Array.isArray(clause)) {
|
|
959
1054
|
throw new InvalidArgumentError(
|
|
960
1055
|
"The first argument of OperatorUtils.testIlike should be an Object, but %v was given.",
|
|
961
1056
|
clause
|
|
962
1057
|
);
|
|
1058
|
+
}
|
|
963
1059
|
if ("ilike" in clause && clause.ilike !== void 0) {
|
|
964
1060
|
if (typeof clause.ilike !== "string") {
|
|
965
1061
|
throw new InvalidOperatorValueError("ilike", "a String", clause.ilike);
|
|
@@ -982,11 +1078,12 @@ var init_operator_clause_tool = __esm({
|
|
|
982
1078
|
* @returns {boolean|undefined}
|
|
983
1079
|
*/
|
|
984
1080
|
testNilike(clause, value) {
|
|
985
|
-
if (!clause || typeof clause !== "object" || Array.isArray(clause))
|
|
1081
|
+
if (!clause || typeof clause !== "object" || Array.isArray(clause)) {
|
|
986
1082
|
throw new InvalidArgumentError(
|
|
987
1083
|
"The first argument of OperatorUtils.testNilike should be an Object, but %v was given.",
|
|
988
1084
|
clause
|
|
989
1085
|
);
|
|
1086
|
+
}
|
|
990
1087
|
if ("nilike" in clause && clause.nilike !== void 0) {
|
|
991
1088
|
if (typeof clause.nilike !== "string") {
|
|
992
1089
|
throw new InvalidOperatorValueError(
|
|
@@ -1021,11 +1118,12 @@ var init_operator_clause_tool = __esm({
|
|
|
1021
1118
|
* @returns {boolean|undefined}
|
|
1022
1119
|
*/
|
|
1023
1120
|
testRegexp(clause, value) {
|
|
1024
|
-
if (!clause || typeof clause !== "object")
|
|
1121
|
+
if (!clause || typeof clause !== "object") {
|
|
1025
1122
|
throw new InvalidArgumentError(
|
|
1026
1123
|
"The first argument of OperatorUtils.testRegexp should be an Object, but %v was given.",
|
|
1027
1124
|
clause
|
|
1028
1125
|
);
|
|
1126
|
+
}
|
|
1029
1127
|
if ("regexp" in clause && clause.regexp !== void 0) {
|
|
1030
1128
|
if (typeof clause.regexp !== "string" && !(clause.regexp instanceof RegExp)) {
|
|
1031
1129
|
throw new InvalidOperatorValueError(
|
|
@@ -1035,12 +1133,15 @@ var init_operator_clause_tool = __esm({
|
|
|
1035
1133
|
);
|
|
1036
1134
|
}
|
|
1037
1135
|
const flags = clause.flags || void 0;
|
|
1038
|
-
if (flags && typeof flags !== "string")
|
|
1136
|
+
if (flags && typeof flags !== "string") {
|
|
1039
1137
|
throw new InvalidArgumentError(
|
|
1040
1138
|
"RegExp flags should be a String, but %v was given.",
|
|
1041
1139
|
clause.flags
|
|
1042
1140
|
);
|
|
1043
|
-
|
|
1141
|
+
}
|
|
1142
|
+
if (!value || typeof value !== "string") {
|
|
1143
|
+
return false;
|
|
1144
|
+
}
|
|
1044
1145
|
const regExp = stringToRegexp(clause.regexp, flags);
|
|
1045
1146
|
return !!value.match(regExp);
|
|
1046
1147
|
}
|
|
@@ -1091,12 +1192,15 @@ var init_where_clause_tool = __esm({
|
|
|
1091
1192
|
* @returns {object[]}
|
|
1092
1193
|
*/
|
|
1093
1194
|
filter(entities, where = void 0) {
|
|
1094
|
-
if (!Array.isArray(entities))
|
|
1195
|
+
if (!Array.isArray(entities)) {
|
|
1095
1196
|
throw new InvalidArgumentError(
|
|
1096
1197
|
"The first argument of WhereClauseTool.filter should be an Array of Object, but %v was given.",
|
|
1097
1198
|
entities
|
|
1098
1199
|
);
|
|
1099
|
-
|
|
1200
|
+
}
|
|
1201
|
+
if (where == null) {
|
|
1202
|
+
return entities;
|
|
1203
|
+
}
|
|
1100
1204
|
return entities.filter(this._createFilter(where));
|
|
1101
1205
|
}
|
|
1102
1206
|
/**
|
|
@@ -1106,31 +1210,37 @@ var init_where_clause_tool = __esm({
|
|
|
1106
1210
|
* @returns {Function}
|
|
1107
1211
|
*/
|
|
1108
1212
|
_createFilter(whereClause) {
|
|
1109
|
-
if (typeof whereClause !== "object" || Array.isArray(whereClause))
|
|
1213
|
+
if (typeof whereClause !== "object" || Array.isArray(whereClause)) {
|
|
1110
1214
|
throw new InvalidArgumentError(
|
|
1111
1215
|
'The provided option "where" should be an Object, but %v was given.',
|
|
1112
1216
|
whereClause
|
|
1113
1217
|
);
|
|
1218
|
+
}
|
|
1114
1219
|
const keys = Object.keys(whereClause);
|
|
1115
1220
|
return (data) => {
|
|
1116
|
-
if (typeof data !== "object")
|
|
1221
|
+
if (typeof data !== "object") {
|
|
1117
1222
|
throw new InvalidArgumentError(
|
|
1118
1223
|
"The first argument of WhereClauseTool.filter should be an Array of Object, but %v was given.",
|
|
1119
1224
|
data
|
|
1120
1225
|
);
|
|
1226
|
+
}
|
|
1121
1227
|
return keys.every((key) => {
|
|
1122
1228
|
if (key === "and" && key in whereClause) {
|
|
1123
1229
|
const andClause = whereClause[key];
|
|
1124
|
-
if (Array.isArray(andClause))
|
|
1230
|
+
if (Array.isArray(andClause)) {
|
|
1125
1231
|
return andClause.every((clause) => this._createFilter(clause)(data));
|
|
1232
|
+
}
|
|
1126
1233
|
} else if (key === "or" && key in whereClause) {
|
|
1127
1234
|
const orClause = whereClause[key];
|
|
1128
|
-
if (Array.isArray(orClause))
|
|
1235
|
+
if (Array.isArray(orClause)) {
|
|
1129
1236
|
return orClause.some((clause) => this._createFilter(clause)(data));
|
|
1237
|
+
}
|
|
1130
1238
|
}
|
|
1131
1239
|
const value = getValueByPath(data, key);
|
|
1132
1240
|
const matcher = whereClause[key];
|
|
1133
|
-
if (this._test(matcher, value))
|
|
1241
|
+
if (this._test(matcher, value)) {
|
|
1242
|
+
return true;
|
|
1243
|
+
}
|
|
1134
1244
|
});
|
|
1135
1245
|
};
|
|
1136
1246
|
}
|
|
@@ -1174,7 +1284,9 @@ var init_where_clause_tool = __esm({
|
|
|
1174
1284
|
}
|
|
1175
1285
|
if (Array.isArray(value)) {
|
|
1176
1286
|
const isElementMatched = value.some((el) => isDeepEqual(el, example));
|
|
1177
|
-
if (isElementMatched)
|
|
1287
|
+
if (isElementMatched) {
|
|
1288
|
+
return true;
|
|
1289
|
+
}
|
|
1178
1290
|
}
|
|
1179
1291
|
return isDeepEqual(example, value);
|
|
1180
1292
|
}
|
|
@@ -1184,12 +1296,15 @@ var init_where_clause_tool = __esm({
|
|
|
1184
1296
|
* @param {WhereClause|undefined} clause
|
|
1185
1297
|
*/
|
|
1186
1298
|
static validateWhereClause(clause) {
|
|
1187
|
-
if (clause == null || typeof clause === "function")
|
|
1188
|
-
|
|
1299
|
+
if (clause == null || typeof clause === "function") {
|
|
1300
|
+
return;
|
|
1301
|
+
}
|
|
1302
|
+
if (typeof clause !== "object" || Array.isArray(clause)) {
|
|
1189
1303
|
throw new InvalidArgumentError(
|
|
1190
1304
|
'The provided option "where" should be an Object, but %v was given.',
|
|
1191
1305
|
clause
|
|
1192
1306
|
);
|
|
1307
|
+
}
|
|
1193
1308
|
}
|
|
1194
1309
|
};
|
|
1195
1310
|
__name(_WhereClauseTool, "WhereClauseTool");
|
|
@@ -1234,17 +1349,19 @@ var init_relations_definition_validator = __esm({
|
|
|
1234
1349
|
* @param {object} relDefs
|
|
1235
1350
|
*/
|
|
1236
1351
|
validate(modelName, relDefs) {
|
|
1237
|
-
if (!modelName || typeof modelName !== "string")
|
|
1352
|
+
if (!modelName || typeof modelName !== "string") {
|
|
1238
1353
|
throw new InvalidArgumentError(
|
|
1239
1354
|
"The first argument of RelationsDefinitionValidator.validate should be a non-empty String, but %v was given.",
|
|
1240
1355
|
modelName
|
|
1241
1356
|
);
|
|
1242
|
-
|
|
1357
|
+
}
|
|
1358
|
+
if (!relDefs || typeof relDefs !== "object" || Array.isArray(relDefs)) {
|
|
1243
1359
|
throw new InvalidArgumentError(
|
|
1244
1360
|
'The provided option "relations" of the model %v should be an Object, but %v was given.',
|
|
1245
1361
|
modelName,
|
|
1246
1362
|
relDefs
|
|
1247
1363
|
);
|
|
1364
|
+
}
|
|
1248
1365
|
const relNames = Object.keys(relDefs);
|
|
1249
1366
|
relNames.forEach((relName) => {
|
|
1250
1367
|
const relDef = relDefs[relName];
|
|
@@ -1259,25 +1376,28 @@ var init_relations_definition_validator = __esm({
|
|
|
1259
1376
|
* @param {object} relDef
|
|
1260
1377
|
*/
|
|
1261
1378
|
_validateRelation(modelName, relName, relDef) {
|
|
1262
|
-
if (!modelName || typeof modelName !== "string")
|
|
1379
|
+
if (!modelName || typeof modelName !== "string") {
|
|
1263
1380
|
throw new InvalidArgumentError(
|
|
1264
1381
|
"The first argument of RelationsDefinitionValidator._validateRelation should be a non-empty String, but %v was given.",
|
|
1265
1382
|
modelName
|
|
1266
1383
|
);
|
|
1267
|
-
|
|
1384
|
+
}
|
|
1385
|
+
if (!relName || typeof relName !== "string") {
|
|
1268
1386
|
throw new InvalidArgumentError(
|
|
1269
1387
|
"The relation name of the model %v should be a non-empty String, but %v was given.",
|
|
1270
1388
|
modelName,
|
|
1271
1389
|
relName
|
|
1272
1390
|
);
|
|
1273
|
-
|
|
1391
|
+
}
|
|
1392
|
+
if (!relDef || typeof relDef !== "object" || Array.isArray(relDef)) {
|
|
1274
1393
|
throw new InvalidArgumentError(
|
|
1275
1394
|
"The relation %v of the model %v should be an Object, but %v was given.",
|
|
1276
1395
|
relName,
|
|
1277
1396
|
modelName,
|
|
1278
1397
|
relDef
|
|
1279
1398
|
);
|
|
1280
|
-
|
|
1399
|
+
}
|
|
1400
|
+
if (!relDef.type || !Object.values(RelationType).includes(relDef.type)) {
|
|
1281
1401
|
throw new InvalidArgumentError(
|
|
1282
1402
|
'The relation %v of the model %v requires the option "type" to have one of relation types: %l, but %v was given.',
|
|
1283
1403
|
relName,
|
|
@@ -1285,6 +1405,7 @@ var init_relations_definition_validator = __esm({
|
|
|
1285
1405
|
Object.values(RelationType),
|
|
1286
1406
|
relDef.type
|
|
1287
1407
|
);
|
|
1408
|
+
}
|
|
1288
1409
|
this._validateBelongsTo(modelName, relName, relDef);
|
|
1289
1410
|
this._validateHasOne(modelName, relName, relDef);
|
|
1290
1411
|
this._validateHasMany(modelName, relName, relDef);
|
|
@@ -1318,50 +1439,58 @@ var init_relations_definition_validator = __esm({
|
|
|
1318
1439
|
* @private
|
|
1319
1440
|
*/
|
|
1320
1441
|
_validateBelongsTo(modelName, relName, relDef) {
|
|
1321
|
-
if (relDef.type !== RelationType.BELONGS_TO)
|
|
1442
|
+
if (relDef.type !== RelationType.BELONGS_TO) {
|
|
1443
|
+
return;
|
|
1444
|
+
}
|
|
1322
1445
|
if (relDef.polymorphic) {
|
|
1323
|
-
if (typeof relDef.polymorphic !== "boolean")
|
|
1446
|
+
if (typeof relDef.polymorphic !== "boolean") {
|
|
1324
1447
|
throw new InvalidArgumentError(
|
|
1325
1448
|
'The relation %v of the model %v has the type "belongsTo", so it expects the option "polymorphic" to be a Boolean, but %v was given.',
|
|
1326
1449
|
relName,
|
|
1327
1450
|
modelName,
|
|
1328
1451
|
relDef.polymorphic
|
|
1329
1452
|
);
|
|
1330
|
-
|
|
1453
|
+
}
|
|
1454
|
+
if (relDef.foreignKey && typeof relDef.foreignKey !== "string") {
|
|
1331
1455
|
throw new InvalidArgumentError(
|
|
1332
1456
|
'The relation %v of the model %v is a polymorphic "belongsTo" relation, so it expects the provided option "foreignKey" to be a String, but %v was given.',
|
|
1333
1457
|
relName,
|
|
1334
1458
|
modelName,
|
|
1335
1459
|
relDef.foreignKey
|
|
1336
1460
|
);
|
|
1337
|
-
|
|
1461
|
+
}
|
|
1462
|
+
if (relDef.discriminator && typeof relDef.discriminator !== "string") {
|
|
1338
1463
|
throw new InvalidArgumentError(
|
|
1339
1464
|
'The relation %v of the model %v is a polymorphic "belongsTo" relation, so it expects the provided option "discriminator" to be a String, but %v was given.',
|
|
1340
1465
|
relName,
|
|
1341
1466
|
modelName,
|
|
1342
1467
|
relDef.discriminator
|
|
1343
1468
|
);
|
|
1469
|
+
}
|
|
1344
1470
|
} else {
|
|
1345
|
-
if (!relDef.model || typeof relDef.model !== "string")
|
|
1471
|
+
if (!relDef.model || typeof relDef.model !== "string") {
|
|
1346
1472
|
throw new InvalidArgumentError(
|
|
1347
1473
|
'The relation %v of the model %v has the type "belongsTo", so it requires the option "model" to be a non-empty String, but %v was given.',
|
|
1348
1474
|
relName,
|
|
1349
1475
|
modelName,
|
|
1350
1476
|
relDef.model
|
|
1351
1477
|
);
|
|
1352
|
-
|
|
1478
|
+
}
|
|
1479
|
+
if (relDef.foreignKey && typeof relDef.foreignKey !== "string") {
|
|
1353
1480
|
throw new InvalidArgumentError(
|
|
1354
1481
|
'The relation %v of the model %v has the type "belongsTo", so it expects the provided option "foreignKey" to be a String, but %v was given.',
|
|
1355
1482
|
relName,
|
|
1356
1483
|
modelName,
|
|
1357
1484
|
relDef.foreignKey
|
|
1358
1485
|
);
|
|
1359
|
-
|
|
1486
|
+
}
|
|
1487
|
+
if (relDef.discriminator) {
|
|
1360
1488
|
throw new InvalidArgumentError(
|
|
1361
1489
|
'The relation %v of the model %v is a non-polymorphic "belongsTo" relation, so it should not have the option "discriminator" to be provided.',
|
|
1362
1490
|
relName,
|
|
1363
1491
|
modelName
|
|
1364
1492
|
);
|
|
1493
|
+
}
|
|
1365
1494
|
}
|
|
1366
1495
|
}
|
|
1367
1496
|
/**
|
|
@@ -1402,43 +1531,50 @@ var init_relations_definition_validator = __esm({
|
|
|
1402
1531
|
* @private
|
|
1403
1532
|
*/
|
|
1404
1533
|
_validateHasOne(modelName, relName, relDef) {
|
|
1405
|
-
if (relDef.type !== RelationType.HAS_ONE)
|
|
1406
|
-
|
|
1534
|
+
if (relDef.type !== RelationType.HAS_ONE) {
|
|
1535
|
+
return;
|
|
1536
|
+
}
|
|
1537
|
+
if (!relDef.model || typeof relDef.model !== "string") {
|
|
1407
1538
|
throw new InvalidArgumentError(
|
|
1408
1539
|
'The relation %v of the model %v has the type "hasOne", so it requires the option "model" to be a non-empty String, but %v was given.',
|
|
1409
1540
|
relName,
|
|
1410
1541
|
modelName,
|
|
1411
1542
|
relDef.model
|
|
1412
1543
|
);
|
|
1544
|
+
}
|
|
1413
1545
|
if (relDef.polymorphic) {
|
|
1414
1546
|
if (typeof relDef.polymorphic === "string") {
|
|
1415
|
-
if (relDef.foreignKey)
|
|
1547
|
+
if (relDef.foreignKey) {
|
|
1416
1548
|
throw new InvalidArgumentError(
|
|
1417
1549
|
'The relation %v of the model %v has the option "polymorphic" with a String value, so it should not have the option "foreignKey" to be provided.',
|
|
1418
1550
|
relName,
|
|
1419
1551
|
modelName
|
|
1420
1552
|
);
|
|
1421
|
-
|
|
1553
|
+
}
|
|
1554
|
+
if (relDef.discriminator) {
|
|
1422
1555
|
throw new InvalidArgumentError(
|
|
1423
1556
|
'The relation %v of the model %v has the option "polymorphic" with a String value, so it should not have the option "discriminator" to be provided.',
|
|
1424
1557
|
relName,
|
|
1425
1558
|
modelName
|
|
1426
1559
|
);
|
|
1560
|
+
}
|
|
1427
1561
|
} else if (typeof relDef.polymorphic === "boolean") {
|
|
1428
|
-
if (!relDef.foreignKey || typeof relDef.foreignKey !== "string")
|
|
1562
|
+
if (!relDef.foreignKey || typeof relDef.foreignKey !== "string") {
|
|
1429
1563
|
throw new InvalidArgumentError(
|
|
1430
1564
|
'The relation %v of the model %v has the option "polymorphic" with "true" value, so it requires the option "foreignKey" to be a non-empty String, but %v was given.',
|
|
1431
1565
|
relName,
|
|
1432
1566
|
modelName,
|
|
1433
1567
|
relDef.foreignKey
|
|
1434
1568
|
);
|
|
1435
|
-
|
|
1569
|
+
}
|
|
1570
|
+
if (!relDef.discriminator || typeof relDef.discriminator !== "string") {
|
|
1436
1571
|
throw new InvalidArgumentError(
|
|
1437
1572
|
'The relation %v of the model %v has the option "polymorphic" with "true" value, so it requires the option "discriminator" to be a non-empty String, but %v was given.',
|
|
1438
1573
|
relName,
|
|
1439
1574
|
modelName,
|
|
1440
1575
|
relDef.discriminator
|
|
1441
1576
|
);
|
|
1577
|
+
}
|
|
1442
1578
|
} else {
|
|
1443
1579
|
throw new InvalidArgumentError(
|
|
1444
1580
|
'The relation %v of the model %v has the type "hasOne", so it expects the provided option "polymorphic" to be a String or a Boolean, but %v was given.',
|
|
@@ -1448,19 +1584,21 @@ var init_relations_definition_validator = __esm({
|
|
|
1448
1584
|
);
|
|
1449
1585
|
}
|
|
1450
1586
|
} else {
|
|
1451
|
-
if (!relDef.foreignKey || typeof relDef.foreignKey !== "string")
|
|
1587
|
+
if (!relDef.foreignKey || typeof relDef.foreignKey !== "string") {
|
|
1452
1588
|
throw new InvalidArgumentError(
|
|
1453
1589
|
'The relation %v of the model %v has the type "hasOne", so it requires the option "foreignKey" to be a non-empty String, but %v was given.',
|
|
1454
1590
|
relName,
|
|
1455
1591
|
modelName,
|
|
1456
1592
|
relDef.foreignKey
|
|
1457
1593
|
);
|
|
1458
|
-
|
|
1594
|
+
}
|
|
1595
|
+
if (relDef.discriminator) {
|
|
1459
1596
|
throw new InvalidArgumentError(
|
|
1460
1597
|
'The relation %v of the model %v is a non-polymorphic "hasOne" relation, so it should not have the option "discriminator" to be provided.',
|
|
1461
1598
|
relName,
|
|
1462
1599
|
modelName
|
|
1463
1600
|
);
|
|
1601
|
+
}
|
|
1464
1602
|
}
|
|
1465
1603
|
}
|
|
1466
1604
|
/**
|
|
@@ -1501,43 +1639,50 @@ var init_relations_definition_validator = __esm({
|
|
|
1501
1639
|
* @private
|
|
1502
1640
|
*/
|
|
1503
1641
|
_validateHasMany(modelName, relName, relDef) {
|
|
1504
|
-
if (relDef.type !== RelationType.HAS_MANY)
|
|
1505
|
-
|
|
1642
|
+
if (relDef.type !== RelationType.HAS_MANY) {
|
|
1643
|
+
return;
|
|
1644
|
+
}
|
|
1645
|
+
if (!relDef.model || typeof relDef.model !== "string") {
|
|
1506
1646
|
throw new InvalidArgumentError(
|
|
1507
1647
|
'The relation %v of the model %v has the type "hasMany", so it requires the option "model" to be a non-empty String, but %v was given.',
|
|
1508
1648
|
relName,
|
|
1509
1649
|
modelName,
|
|
1510
1650
|
relDef.model
|
|
1511
1651
|
);
|
|
1652
|
+
}
|
|
1512
1653
|
if (relDef.polymorphic) {
|
|
1513
1654
|
if (typeof relDef.polymorphic === "string") {
|
|
1514
|
-
if (relDef.foreignKey)
|
|
1655
|
+
if (relDef.foreignKey) {
|
|
1515
1656
|
throw new InvalidArgumentError(
|
|
1516
1657
|
'The relation %v of the model %v has the option "polymorphic" with a String value, so it should not have the option "foreignKey" to be provided.',
|
|
1517
1658
|
relName,
|
|
1518
1659
|
modelName
|
|
1519
1660
|
);
|
|
1520
|
-
|
|
1661
|
+
}
|
|
1662
|
+
if (relDef.discriminator) {
|
|
1521
1663
|
throw new InvalidArgumentError(
|
|
1522
1664
|
'The relation %v of the model %v has the option "polymorphic" with a String value, so it should not have the option "discriminator" to be provided.',
|
|
1523
1665
|
relName,
|
|
1524
1666
|
modelName
|
|
1525
1667
|
);
|
|
1668
|
+
}
|
|
1526
1669
|
} else if (typeof relDef.polymorphic === "boolean") {
|
|
1527
|
-
if (!relDef.foreignKey || typeof relDef.foreignKey !== "string")
|
|
1670
|
+
if (!relDef.foreignKey || typeof relDef.foreignKey !== "string") {
|
|
1528
1671
|
throw new InvalidArgumentError(
|
|
1529
1672
|
'The relation %v of the model %v has the option "polymorphic" with "true" value, so it requires the option "foreignKey" to be a non-empty String, but %v was given.',
|
|
1530
1673
|
relName,
|
|
1531
1674
|
modelName,
|
|
1532
1675
|
relDef.foreignKey
|
|
1533
1676
|
);
|
|
1534
|
-
|
|
1677
|
+
}
|
|
1678
|
+
if (!relDef.discriminator || typeof relDef.discriminator !== "string") {
|
|
1535
1679
|
throw new InvalidArgumentError(
|
|
1536
1680
|
'The relation %v of the model %v has the option "polymorphic" with "true" value, so it requires the option "discriminator" to be a non-empty String, but %v was given.',
|
|
1537
1681
|
relName,
|
|
1538
1682
|
modelName,
|
|
1539
1683
|
relDef.discriminator
|
|
1540
1684
|
);
|
|
1685
|
+
}
|
|
1541
1686
|
} else {
|
|
1542
1687
|
throw new InvalidArgumentError(
|
|
1543
1688
|
'The relation %v of the model %v has the type "hasMany", so it expects the provided option "polymorphic" to be a String or a Boolean, but %v was given.',
|
|
@@ -1547,19 +1692,21 @@ var init_relations_definition_validator = __esm({
|
|
|
1547
1692
|
);
|
|
1548
1693
|
}
|
|
1549
1694
|
} else {
|
|
1550
|
-
if (!relDef.foreignKey || typeof relDef.foreignKey !== "string")
|
|
1695
|
+
if (!relDef.foreignKey || typeof relDef.foreignKey !== "string") {
|
|
1551
1696
|
throw new InvalidArgumentError(
|
|
1552
1697
|
'The relation %v of the model %v has the type "hasMany", so it requires the option "foreignKey" to be a non-empty String, but %v was given.',
|
|
1553
1698
|
relName,
|
|
1554
1699
|
modelName,
|
|
1555
1700
|
relDef.foreignKey
|
|
1556
1701
|
);
|
|
1557
|
-
|
|
1702
|
+
}
|
|
1703
|
+
if (relDef.discriminator) {
|
|
1558
1704
|
throw new InvalidArgumentError(
|
|
1559
1705
|
'The relation %v of the model %v is a non-polymorphic "hasMany" relation, so it should not have the option "discriminator" to be provided.',
|
|
1560
1706
|
relName,
|
|
1561
1707
|
modelName
|
|
1562
1708
|
);
|
|
1709
|
+
}
|
|
1563
1710
|
}
|
|
1564
1711
|
}
|
|
1565
1712
|
/**
|
|
@@ -1580,27 +1727,32 @@ var init_relations_definition_validator = __esm({
|
|
|
1580
1727
|
* @private
|
|
1581
1728
|
*/
|
|
1582
1729
|
_validateReferencesMany(modelName, relName, relDef) {
|
|
1583
|
-
if (relDef.type !== RelationType.REFERENCES_MANY)
|
|
1584
|
-
|
|
1730
|
+
if (relDef.type !== RelationType.REFERENCES_MANY) {
|
|
1731
|
+
return;
|
|
1732
|
+
}
|
|
1733
|
+
if (!relDef.model || typeof relDef.model !== "string") {
|
|
1585
1734
|
throw new InvalidArgumentError(
|
|
1586
1735
|
'The relation %v of the model %v has the type "referencesMany", so it requires the option "model" to be a non-empty String, but %v was given.',
|
|
1587
1736
|
relName,
|
|
1588
1737
|
modelName,
|
|
1589
1738
|
relDef.model
|
|
1590
1739
|
);
|
|
1591
|
-
|
|
1740
|
+
}
|
|
1741
|
+
if (relDef.foreignKey && typeof relDef.foreignKey !== "string") {
|
|
1592
1742
|
throw new InvalidArgumentError(
|
|
1593
1743
|
'The relation %v of the model %v has the type "referencesMany", so it expects the provided option "foreignKey" to be a String, but %v was given.',
|
|
1594
1744
|
relName,
|
|
1595
1745
|
modelName,
|
|
1596
1746
|
relDef.foreignKey
|
|
1597
1747
|
);
|
|
1598
|
-
|
|
1748
|
+
}
|
|
1749
|
+
if (relDef.discriminator) {
|
|
1599
1750
|
throw new InvalidArgumentError(
|
|
1600
1751
|
'The relation %v of the model %v has the type "referencesMany", so it should not have the option "discriminator" to be provided.',
|
|
1601
1752
|
relName,
|
|
1602
1753
|
modelName
|
|
1603
1754
|
);
|
|
1755
|
+
}
|
|
1604
1756
|
}
|
|
1605
1757
|
};
|
|
1606
1758
|
__name(_RelationsDefinitionValidator, "RelationsDefinitionValidator");
|
|
@@ -1685,11 +1837,12 @@ var init_definition_registry = __esm({
|
|
|
1685
1837
|
addDatasource(datasourceDef) {
|
|
1686
1838
|
this.getService(DatasourceDefinitionValidator).validate(datasourceDef);
|
|
1687
1839
|
const name = datasourceDef.name;
|
|
1688
|
-
if (name in this._datasources)
|
|
1840
|
+
if (name in this._datasources) {
|
|
1689
1841
|
throw new InvalidArgumentError(
|
|
1690
1842
|
"The datasource %v is already defined.",
|
|
1691
1843
|
name
|
|
1692
1844
|
);
|
|
1845
|
+
}
|
|
1693
1846
|
this._datasources[name] = datasourceDef;
|
|
1694
1847
|
}
|
|
1695
1848
|
/**
|
|
@@ -1709,8 +1862,9 @@ var init_definition_registry = __esm({
|
|
|
1709
1862
|
*/
|
|
1710
1863
|
getDatasource(name) {
|
|
1711
1864
|
const datasourceDef = this._datasources[name];
|
|
1712
|
-
if (!datasourceDef)
|
|
1865
|
+
if (!datasourceDef) {
|
|
1713
1866
|
throw new InvalidArgumentError("The datasource %v is not defined.", name);
|
|
1867
|
+
}
|
|
1714
1868
|
return datasourceDef;
|
|
1715
1869
|
}
|
|
1716
1870
|
/**
|
|
@@ -1721,11 +1875,12 @@ var init_definition_registry = __esm({
|
|
|
1721
1875
|
addModel(modelDef) {
|
|
1722
1876
|
this.getService(ModelDefinitionValidator).validate(modelDef);
|
|
1723
1877
|
const modelKey = modelNameToModelKey(modelDef.name);
|
|
1724
|
-
if (modelKey in this._models)
|
|
1878
|
+
if (modelKey in this._models) {
|
|
1725
1879
|
throw new InvalidArgumentError(
|
|
1726
1880
|
"The model %v is already defined.",
|
|
1727
1881
|
modelDef.name
|
|
1728
1882
|
);
|
|
1883
|
+
}
|
|
1729
1884
|
this._models[modelKey] = modelDef;
|
|
1730
1885
|
}
|
|
1731
1886
|
/**
|
|
@@ -1747,8 +1902,9 @@ var init_definition_registry = __esm({
|
|
|
1747
1902
|
getModel(name) {
|
|
1748
1903
|
const modelKey = modelNameToModelKey(name);
|
|
1749
1904
|
const modelDef = this._models[modelKey];
|
|
1750
|
-
if (!modelDef)
|
|
1905
|
+
if (!modelDef) {
|
|
1751
1906
|
throw new InvalidArgumentError("The model %v is not defined.", name);
|
|
1907
|
+
}
|
|
1752
1908
|
return modelDef;
|
|
1753
1909
|
}
|
|
1754
1910
|
};
|
|
@@ -1758,13 +1914,12 @@ var init_definition_registry = __esm({
|
|
|
1758
1914
|
});
|
|
1759
1915
|
|
|
1760
1916
|
// src/definition/model/model-definition-utils.js
|
|
1761
|
-
var import_js_service7,
|
|
1917
|
+
var import_js_service7, DEFAULT_PRIMARY_KEY_PROPERTY_NAME, _ModelDefinitionUtils, ModelDefinitionUtils;
|
|
1762
1918
|
var init_model_definition_utils = __esm({
|
|
1763
1919
|
"src/definition/model/model-definition-utils.js"() {
|
|
1764
1920
|
"use strict";
|
|
1765
1921
|
import_js_service7 = require("@e22m4u/js-service");
|
|
1766
1922
|
init_properties();
|
|
1767
|
-
import_js_empty_values = require("@e22m4u/js-empty-values");
|
|
1768
1923
|
init_errors();
|
|
1769
1924
|
init_definition_registry();
|
|
1770
1925
|
init_utils();
|
|
@@ -1786,12 +1941,13 @@ var init_model_definition_utils = __esm({
|
|
|
1786
1941
|
const isDefaultPrimaryKeyAlreadyInUse = Object.keys(propDefs).includes(
|
|
1787
1942
|
DEFAULT_PRIMARY_KEY_PROPERTY_NAME
|
|
1788
1943
|
);
|
|
1789
|
-
if (isDefaultPrimaryKeyAlreadyInUse)
|
|
1944
|
+
if (isDefaultPrimaryKeyAlreadyInUse) {
|
|
1790
1945
|
throw new InvalidArgumentError(
|
|
1791
1946
|
'The property name %v of the model %v is defined as a regular property. In this case, a primary key should be defined explicitly. Do use the option "primaryKey" to specify the primary key.',
|
|
1792
1947
|
DEFAULT_PRIMARY_KEY_PROPERTY_NAME,
|
|
1793
1948
|
modelName
|
|
1794
1949
|
);
|
|
1950
|
+
}
|
|
1795
1951
|
return DEFAULT_PRIMARY_KEY_PROPERTY_NAME;
|
|
1796
1952
|
}
|
|
1797
1953
|
return propNames[0];
|
|
@@ -1808,9 +1964,13 @@ var init_model_definition_utils = __esm({
|
|
|
1808
1964
|
try {
|
|
1809
1965
|
pkColName = this.getColumnNameByPropertyName(modelName, pkPropName);
|
|
1810
1966
|
} catch (error) {
|
|
1811
|
-
if (!(error instanceof InvalidArgumentError))
|
|
1967
|
+
if (!(error instanceof InvalidArgumentError)) {
|
|
1968
|
+
throw error;
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
if (pkColName === void 0) {
|
|
1972
|
+
return pkPropName;
|
|
1812
1973
|
}
|
|
1813
|
-
if (pkColName === void 0) return pkPropName;
|
|
1814
1974
|
return pkColName;
|
|
1815
1975
|
}
|
|
1816
1976
|
/**
|
|
@@ -1835,14 +1995,16 @@ var init_model_definition_utils = __esm({
|
|
|
1835
1995
|
var _a;
|
|
1836
1996
|
const propDefs = this.getPropertiesDefinitionInBaseModelHierarchy(modelName);
|
|
1837
1997
|
const propDef = propDefs[propertyName];
|
|
1838
|
-
if (!propDef)
|
|
1998
|
+
if (!propDef) {
|
|
1839
1999
|
throw new InvalidArgumentError(
|
|
1840
2000
|
"The model %v does not have the property %v.",
|
|
1841
2001
|
modelName,
|
|
1842
2002
|
propertyName
|
|
1843
2003
|
);
|
|
1844
|
-
|
|
2004
|
+
}
|
|
2005
|
+
if (propDef && typeof propDef === "object") {
|
|
1845
2006
|
return (_a = propDef.columnName) != null ? _a : propertyName;
|
|
2007
|
+
}
|
|
1846
2008
|
return propertyName;
|
|
1847
2009
|
}
|
|
1848
2010
|
/**
|
|
@@ -1855,17 +2017,19 @@ var init_model_definition_utils = __esm({
|
|
|
1855
2017
|
getDefaultPropertyValue(modelName, propertyName) {
|
|
1856
2018
|
const propDefs = this.getPropertiesDefinitionInBaseModelHierarchy(modelName);
|
|
1857
2019
|
const propDef = propDefs[propertyName];
|
|
1858
|
-
if (!propDef)
|
|
2020
|
+
if (!propDef) {
|
|
1859
2021
|
throw new InvalidArgumentError(
|
|
1860
2022
|
"The model %v does not have the property %v.",
|
|
1861
2023
|
modelName,
|
|
1862
2024
|
propertyName
|
|
1863
2025
|
);
|
|
1864
|
-
|
|
2026
|
+
}
|
|
2027
|
+
if (propDef && typeof propDef === "object") {
|
|
1865
2028
|
return propDef.default instanceof Function ? propDef.default() : propDef.default;
|
|
2029
|
+
}
|
|
1866
2030
|
}
|
|
1867
2031
|
/**
|
|
1868
|
-
* Set default values
|
|
2032
|
+
* Set default values to empty properties.
|
|
1869
2033
|
*
|
|
1870
2034
|
* @param {string} modelName
|
|
1871
2035
|
* @param {object} modelData
|
|
@@ -1876,13 +2040,12 @@ var init_model_definition_utils = __esm({
|
|
|
1876
2040
|
const propDefs = this.getPropertiesDefinitionInBaseModelHierarchy(modelName);
|
|
1877
2041
|
const propNames = onlyProvidedProperties ? Object.keys(modelData) : Object.keys(propDefs);
|
|
1878
2042
|
const extendedData = cloneDeep(modelData);
|
|
1879
|
-
const blankValuesService = this.getService(import_js_empty_values.BlankValuesService);
|
|
1880
2043
|
propNames.forEach((propName) => {
|
|
1881
2044
|
const propDef = propDefs[propName];
|
|
1882
2045
|
const propValue = extendedData[propName];
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
2046
|
+
if (propValue != null) {
|
|
2047
|
+
return;
|
|
2048
|
+
}
|
|
1886
2049
|
if (propDef && typeof propDef === "object" && propDef.default !== void 0) {
|
|
1887
2050
|
extendedData[propName] = this.getDefaultPropertyValue(
|
|
1888
2051
|
modelName,
|
|
@@ -1904,7 +2067,9 @@ var init_model_definition_utils = __esm({
|
|
|
1904
2067
|
const propNames = Object.keys(propDefs);
|
|
1905
2068
|
const convertedData = cloneDeep(modelData);
|
|
1906
2069
|
propNames.forEach((propName) => {
|
|
1907
|
-
if (!(propName in convertedData))
|
|
2070
|
+
if (!(propName in convertedData)) {
|
|
2071
|
+
return;
|
|
2072
|
+
}
|
|
1908
2073
|
const colName = this.getColumnNameByPropertyName(modelName, propName);
|
|
1909
2074
|
let propValue = convertedData[propName];
|
|
1910
2075
|
const propDef = propDefs[propName];
|
|
@@ -1937,7 +2102,9 @@ var init_model_definition_utils = __esm({
|
|
|
1937
2102
|
const convertedData = cloneDeep(tableData);
|
|
1938
2103
|
propNames.forEach((propName) => {
|
|
1939
2104
|
const colName = this.getColumnNameByPropertyName(modelName, propName);
|
|
1940
|
-
if (!(colName in convertedData))
|
|
2105
|
+
if (!(colName in convertedData)) {
|
|
2106
|
+
return;
|
|
2107
|
+
}
|
|
1941
2108
|
let colValue = convertedData[colName];
|
|
1942
2109
|
const propDef = propDefs[propName];
|
|
1943
2110
|
if (colValue !== null && typeof colValue === "object" && !Array.isArray(colValue) && propDef !== null && typeof propDef === "object" && propDef.type === DataType.OBJECT && propDef.model) {
|
|
@@ -1968,14 +2135,18 @@ var init_model_definition_utils = __esm({
|
|
|
1968
2135
|
const propDef = propDefs[propertyName];
|
|
1969
2136
|
if (!propDef) {
|
|
1970
2137
|
const pkPropName = this.getPrimaryKeyAsPropertyName(modelName);
|
|
1971
|
-
if (pkPropName === propertyName)
|
|
2138
|
+
if (pkPropName === propertyName) {
|
|
2139
|
+
return DataType.ANY;
|
|
2140
|
+
}
|
|
1972
2141
|
throw new InvalidArgumentError(
|
|
1973
2142
|
"The model %v does not have the property %v.",
|
|
1974
2143
|
modelName,
|
|
1975
2144
|
propertyName
|
|
1976
2145
|
);
|
|
1977
2146
|
}
|
|
1978
|
-
if (typeof propDef === "string")
|
|
2147
|
+
if (typeof propDef === "string") {
|
|
2148
|
+
return propDef;
|
|
2149
|
+
}
|
|
1979
2150
|
return propDef.type;
|
|
1980
2151
|
}
|
|
1981
2152
|
/**
|
|
@@ -1991,14 +2162,17 @@ var init_model_definition_utils = __esm({
|
|
|
1991
2162
|
propDef
|
|
1992
2163
|
);
|
|
1993
2164
|
}
|
|
1994
|
-
if (typeof propDef === "string")
|
|
2165
|
+
if (typeof propDef === "string") {
|
|
2166
|
+
return propDef;
|
|
2167
|
+
}
|
|
1995
2168
|
const dataType = propDef.type;
|
|
1996
|
-
if (!Object.values(DataType).includes(dataType))
|
|
2169
|
+
if (!Object.values(DataType).includes(dataType)) {
|
|
1997
2170
|
throw new InvalidArgumentError(
|
|
1998
2171
|
'The given Object to the ModelDefinitionUtils.getDataTypeFromPropertyDefinition should have the "type" property with one of values: %l, but %v was given.',
|
|
1999
2172
|
Object.values(DataType),
|
|
2000
2173
|
propDef.type
|
|
2001
2174
|
);
|
|
2175
|
+
}
|
|
2002
2176
|
return dataType;
|
|
2003
2177
|
}
|
|
2004
2178
|
/**
|
|
@@ -2029,7 +2203,9 @@ var init_model_definition_utils = __esm({
|
|
|
2029
2203
|
const propDefs = (_a = modelDef.properties) != null ? _a : {};
|
|
2030
2204
|
return Object.keys(propDefs).reduce((result, propName) => {
|
|
2031
2205
|
const propDef = propDefs[propName];
|
|
2032
|
-
if (typeof propDef === "object" && propDef.primaryKey)
|
|
2206
|
+
if (typeof propDef === "object" && propDef.primaryKey) {
|
|
2207
|
+
return result;
|
|
2208
|
+
}
|
|
2033
2209
|
return { ...result, [propName]: propDef };
|
|
2034
2210
|
}, {});
|
|
2035
2211
|
}
|
|
@@ -2043,19 +2219,23 @@ var init_model_definition_utils = __esm({
|
|
|
2043
2219
|
let pkPropDefs = {};
|
|
2044
2220
|
let regularPropDefs = {};
|
|
2045
2221
|
const recursion = /* @__PURE__ */ __name((currModelName, prevModelName = void 0) => {
|
|
2046
|
-
if (currModelName === prevModelName)
|
|
2222
|
+
if (currModelName === prevModelName) {
|
|
2047
2223
|
throw new InvalidArgumentError(
|
|
2048
2224
|
"The model %v has a circular inheritance.",
|
|
2049
2225
|
currModelName
|
|
2050
2226
|
);
|
|
2051
|
-
|
|
2227
|
+
}
|
|
2228
|
+
if (Object.keys(pkPropDefs).length === 0) {
|
|
2052
2229
|
pkPropDefs = this.getOwnPropertiesDefinitionOfPrimaryKeys(currModelName);
|
|
2230
|
+
}
|
|
2053
2231
|
regularPropDefs = {
|
|
2054
2232
|
...this.getOwnPropertiesDefinitionWithoutPrimaryKeys(currModelName),
|
|
2055
2233
|
...regularPropDefs
|
|
2056
2234
|
};
|
|
2057
2235
|
const modelDef = this.getService(DefinitionRegistry).getModel(currModelName);
|
|
2058
|
-
if (modelDef.base)
|
|
2236
|
+
if (modelDef.base) {
|
|
2237
|
+
recursion(modelDef.base, currModelName);
|
|
2238
|
+
}
|
|
2059
2239
|
}, "recursion");
|
|
2060
2240
|
recursion(modelName);
|
|
2061
2241
|
return { ...pkPropDefs, ...regularPropDefs };
|
|
@@ -2081,15 +2261,18 @@ var init_model_definition_utils = __esm({
|
|
|
2081
2261
|
let result = {};
|
|
2082
2262
|
const recursion = /* @__PURE__ */ __name((currModelName, prevModelName = void 0) => {
|
|
2083
2263
|
var _a;
|
|
2084
|
-
if (currModelName === prevModelName)
|
|
2264
|
+
if (currModelName === prevModelName) {
|
|
2085
2265
|
throw new InvalidArgumentError(
|
|
2086
2266
|
"The model %v has a circular inheritance.",
|
|
2087
2267
|
currModelName
|
|
2088
2268
|
);
|
|
2269
|
+
}
|
|
2089
2270
|
const modelDef = this.getService(DefinitionRegistry).getModel(currModelName);
|
|
2090
2271
|
const ownRelDefs = (_a = modelDef.relations) != null ? _a : {};
|
|
2091
2272
|
result = { ...ownRelDefs, ...result };
|
|
2092
|
-
if (modelDef.base)
|
|
2273
|
+
if (modelDef.base) {
|
|
2274
|
+
recursion(modelDef.base, currModelName);
|
|
2275
|
+
}
|
|
2093
2276
|
}, "recursion");
|
|
2094
2277
|
recursion(modelName);
|
|
2095
2278
|
return result;
|
|
@@ -2111,12 +2294,13 @@ var init_model_definition_utils = __esm({
|
|
|
2111
2294
|
break;
|
|
2112
2295
|
}
|
|
2113
2296
|
}
|
|
2114
|
-
if (!foundDef)
|
|
2297
|
+
if (!foundDef) {
|
|
2115
2298
|
throw new InvalidArgumentError(
|
|
2116
2299
|
"The model %v does not have relation name %v.",
|
|
2117
2300
|
modelName,
|
|
2118
2301
|
relationName
|
|
2119
2302
|
);
|
|
2303
|
+
}
|
|
2120
2304
|
return foundDef;
|
|
2121
2305
|
}
|
|
2122
2306
|
/**
|
|
@@ -2127,11 +2311,12 @@ var init_model_definition_utils = __esm({
|
|
|
2127
2311
|
* @returns {object}
|
|
2128
2312
|
*/
|
|
2129
2313
|
excludeObjectKeysByRelationNames(modelName, modelData) {
|
|
2130
|
-
if (!modelData || typeof modelData !== "object" || Array.isArray(modelData))
|
|
2314
|
+
if (!modelData || typeof modelData !== "object" || Array.isArray(modelData)) {
|
|
2131
2315
|
throw new InvalidArgumentError(
|
|
2132
2316
|
"The second argument of ModelDefinitionUtils.excludeObjectKeysByRelationNames should be an Object, but %v was given.",
|
|
2133
2317
|
modelData
|
|
2134
2318
|
);
|
|
2319
|
+
}
|
|
2135
2320
|
const relDefs = this.getRelationsDefinitionInBaseModelHierarchy(modelName);
|
|
2136
2321
|
const relNames = Object.keys(relDefs);
|
|
2137
2322
|
return excludeObjectKeys(modelData, relNames);
|
|
@@ -2144,23 +2329,30 @@ var init_model_definition_utils = __esm({
|
|
|
2144
2329
|
* @returns {string|undefined}
|
|
2145
2330
|
*/
|
|
2146
2331
|
getModelNameOfPropertyValueIfDefined(modelName, propertyName) {
|
|
2147
|
-
if (!modelName || typeof modelName !== "string")
|
|
2332
|
+
if (!modelName || typeof modelName !== "string") {
|
|
2148
2333
|
throw new InvalidArgumentError(
|
|
2149
2334
|
'Parameter "modelName" of ModelDefinitionUtils.getModelNameOfPropertyValueIfDefined requires a non-empty String, but %v was given.',
|
|
2150
2335
|
modelName
|
|
2151
2336
|
);
|
|
2152
|
-
|
|
2337
|
+
}
|
|
2338
|
+
if (!propertyName || typeof propertyName !== "string") {
|
|
2153
2339
|
throw new InvalidArgumentError(
|
|
2154
2340
|
'Parameter "propertyName" of ModelDefinitionUtils.getModelNameOfPropertyValueIfDefined requires a non-empty String, but %v was given.',
|
|
2155
2341
|
propertyName
|
|
2156
2342
|
);
|
|
2343
|
+
}
|
|
2157
2344
|
const propDefs = this.getPropertiesDefinitionInBaseModelHierarchy(modelName);
|
|
2158
2345
|
const propDef = propDefs[propertyName];
|
|
2159
|
-
if (!propDef)
|
|
2346
|
+
if (!propDef) {
|
|
2347
|
+
return void 0;
|
|
2348
|
+
}
|
|
2160
2349
|
if (propDef && typeof propDef === "object") {
|
|
2161
|
-
if (propDef.type === DataType.OBJECT)
|
|
2162
|
-
|
|
2350
|
+
if (propDef.type === DataType.OBJECT) {
|
|
2351
|
+
return propDef.model || void 0;
|
|
2352
|
+
}
|
|
2353
|
+
if (propDef.type === DataType.ARRAY) {
|
|
2163
2354
|
return propDef.itemModel || void 0;
|
|
2355
|
+
}
|
|
2164
2356
|
}
|
|
2165
2357
|
return void 0;
|
|
2166
2358
|
}
|
|
@@ -2171,13 +2363,12 @@ var init_model_definition_utils = __esm({
|
|
|
2171
2363
|
});
|
|
2172
2364
|
|
|
2173
2365
|
// src/definition/model/properties/required-property-validator.js
|
|
2174
|
-
var import_js_service8,
|
|
2366
|
+
var import_js_service8, _RequiredPropertyValidator, RequiredPropertyValidator;
|
|
2175
2367
|
var init_required_property_validator = __esm({
|
|
2176
2368
|
"src/definition/model/properties/required-property-validator.js"() {
|
|
2177
2369
|
"use strict";
|
|
2178
2370
|
init_data_type();
|
|
2179
2371
|
import_js_service8 = require("@e22m4u/js-service");
|
|
2180
|
-
import_js_empty_values2 = require("@e22m4u/js-empty-values");
|
|
2181
2372
|
init_errors();
|
|
2182
2373
|
init_model_definition_utils();
|
|
2183
2374
|
_RequiredPropertyValidator = class _RequiredPropertyValidator extends import_js_service8.Service {
|
|
@@ -2212,23 +2403,19 @@ var init_required_property_validator = __esm({
|
|
|
2212
2403
|
ModelDefinitionUtils
|
|
2213
2404
|
).getPropertiesDefinitionInBaseModelHierarchy(modelName);
|
|
2214
2405
|
const propNames = Object.keys(isPartial ? modelData : propDefs);
|
|
2215
|
-
const blankValuesService = this.getService(import_js_empty_values2.BlankValuesService);
|
|
2216
2406
|
for (const propName of propNames) {
|
|
2217
2407
|
const propDef = propDefs[propName];
|
|
2218
2408
|
if (!propDef || typeof propDef !== "object") {
|
|
2219
2409
|
continue;
|
|
2220
2410
|
}
|
|
2221
2411
|
const propValue = modelData[propName];
|
|
2222
|
-
if (propDef.required) {
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
propValue
|
|
2230
|
-
);
|
|
2231
|
-
}
|
|
2412
|
+
if (propDef.required && propValue == null) {
|
|
2413
|
+
throw new InvalidArgumentError(
|
|
2414
|
+
"Property %v of the model %v is required, but %v was given.",
|
|
2415
|
+
propName,
|
|
2416
|
+
modelName,
|
|
2417
|
+
propValue
|
|
2418
|
+
);
|
|
2232
2419
|
}
|
|
2233
2420
|
if (propDef.type === DataType.OBJECT && propDef.model && propValue !== null && typeof propValue === "object" && !Array.isArray(propValue)) {
|
|
2234
2421
|
this.validate(propDef.model, propValue);
|
|
@@ -2248,14 +2435,12 @@ var init_required_property_validator = __esm({
|
|
|
2248
2435
|
});
|
|
2249
2436
|
|
|
2250
2437
|
// src/definition/model/properties/property-uniqueness-validator.js
|
|
2251
|
-
var import_js_service9,
|
|
2438
|
+
var import_js_service9, _PropertyUniquenessValidator, PropertyUniquenessValidator;
|
|
2252
2439
|
var init_property_uniqueness_validator = __esm({
|
|
2253
2440
|
"src/definition/model/properties/property-uniqueness-validator.js"() {
|
|
2254
2441
|
"use strict";
|
|
2255
|
-
init_data_type();
|
|
2256
2442
|
import_js_service9 = require("@e22m4u/js-service");
|
|
2257
2443
|
init_utils();
|
|
2258
|
-
import_js_empty_values3 = require("@e22m4u/js-empty-values");
|
|
2259
2444
|
init_property_uniqueness();
|
|
2260
2445
|
init_errors();
|
|
2261
2446
|
init_model_definition_utils();
|
|
@@ -2271,27 +2456,31 @@ var init_property_uniqueness_validator = __esm({
|
|
|
2271
2456
|
* @returns {Promise<undefined>}
|
|
2272
2457
|
*/
|
|
2273
2458
|
async validate(countMethod, methodName, modelName, modelData, modelId = void 0) {
|
|
2274
|
-
if (typeof countMethod !== "function")
|
|
2459
|
+
if (typeof countMethod !== "function") {
|
|
2275
2460
|
throw new InvalidArgumentError(
|
|
2276
2461
|
'The parameter "countMethod" of the PropertyUniquenessValidator must be a Function, but %v was given.',
|
|
2277
2462
|
countMethod
|
|
2278
2463
|
);
|
|
2279
|
-
|
|
2464
|
+
}
|
|
2465
|
+
if (!methodName || typeof methodName !== "string") {
|
|
2280
2466
|
throw new InvalidArgumentError(
|
|
2281
2467
|
'The parameter "methodName" of the PropertyUniquenessValidator must be a non-empty String, but %v was given.',
|
|
2282
2468
|
methodName
|
|
2283
2469
|
);
|
|
2284
|
-
|
|
2470
|
+
}
|
|
2471
|
+
if (!modelName || typeof modelName !== "string") {
|
|
2285
2472
|
throw new InvalidArgumentError(
|
|
2286
2473
|
'The parameter "modelName" of the PropertyUniquenessValidator must be a non-empty String, but %v was given.',
|
|
2287
2474
|
modelName
|
|
2288
2475
|
);
|
|
2289
|
-
|
|
2476
|
+
}
|
|
2477
|
+
if (!isPlainObject(modelData)) {
|
|
2290
2478
|
throw new InvalidArgumentError(
|
|
2291
2479
|
"The data of the model %v should be an Object, but %v was given.",
|
|
2292
2480
|
modelName,
|
|
2293
2481
|
modelData
|
|
2294
2482
|
);
|
|
2483
|
+
}
|
|
2295
2484
|
const propDefs = this.getService(
|
|
2296
2485
|
ModelDefinitionUtils
|
|
2297
2486
|
).getPropertiesDefinitionInBaseModelHierarchy(modelName);
|
|
@@ -2307,27 +2496,28 @@ var init_property_uniqueness_validator = __esm({
|
|
|
2307
2496
|
propValue
|
|
2308
2497
|
), "createError");
|
|
2309
2498
|
let willBeReplaced = void 0;
|
|
2310
|
-
const blankValuesService = this.getService(import_js_empty_values3.BlankValuesService);
|
|
2311
2499
|
for (const propName of propNames) {
|
|
2312
2500
|
const propDef = propDefs[propName];
|
|
2313
2501
|
if (!propDef || typeof propDef === "string" || !propDef.unique || propDef.unique === PropertyUniqueness.NON_UNIQUE) {
|
|
2314
2502
|
continue;
|
|
2315
2503
|
}
|
|
2316
2504
|
const propValue = modelData[propName];
|
|
2317
|
-
if (propDef.unique === PropertyUniqueness.SPARSE) {
|
|
2318
|
-
|
|
2319
|
-
const isBlank = blankValuesService.isBlankOf(propType, propValue);
|
|
2320
|
-
if (isBlank) continue;
|
|
2505
|
+
if (propDef.unique === PropertyUniqueness.SPARSE && !propValue) {
|
|
2506
|
+
continue;
|
|
2321
2507
|
}
|
|
2322
2508
|
if (methodName === "create") {
|
|
2323
2509
|
const count = await countMethod({ [propName]: propValue });
|
|
2324
|
-
if (count > 0)
|
|
2510
|
+
if (count > 0) {
|
|
2511
|
+
throw createError(propName, propValue);
|
|
2512
|
+
}
|
|
2325
2513
|
} else if (methodName === "replaceById") {
|
|
2326
2514
|
const count = await countMethod({
|
|
2327
2515
|
[idProp]: { neq: modelId },
|
|
2328
2516
|
[propName]: propValue
|
|
2329
2517
|
});
|
|
2330
|
-
if (count > 0)
|
|
2518
|
+
if (count > 0) {
|
|
2519
|
+
throw createError(propName, propValue);
|
|
2520
|
+
}
|
|
2331
2521
|
} else if (methodName === "replaceOrCreate") {
|
|
2332
2522
|
const idFromData = modelData[idProp];
|
|
2333
2523
|
if (willBeReplaced == null && idFromData != null) {
|
|
@@ -2339,20 +2529,28 @@ var init_property_uniqueness_validator = __esm({
|
|
|
2339
2529
|
[idProp]: { neq: idFromData },
|
|
2340
2530
|
[propName]: propValue
|
|
2341
2531
|
});
|
|
2342
|
-
if (count > 0)
|
|
2532
|
+
if (count > 0) {
|
|
2533
|
+
throw createError(propName, propValue);
|
|
2534
|
+
}
|
|
2343
2535
|
} else {
|
|
2344
2536
|
const count = await countMethod({ [propName]: propValue });
|
|
2345
|
-
if (count > 0)
|
|
2537
|
+
if (count > 0) {
|
|
2538
|
+
throw createError(propName, propValue);
|
|
2539
|
+
}
|
|
2346
2540
|
}
|
|
2347
2541
|
} else if (methodName === "patch") {
|
|
2348
2542
|
const count = await countMethod({ [propName]: propValue });
|
|
2349
|
-
if (count > 0)
|
|
2543
|
+
if (count > 0) {
|
|
2544
|
+
throw createError(propName, propValue);
|
|
2545
|
+
}
|
|
2350
2546
|
} else if (methodName === "patchById") {
|
|
2351
2547
|
const count = await countMethod({
|
|
2352
2548
|
[idProp]: { neq: modelId },
|
|
2353
2549
|
[propName]: propValue
|
|
2354
2550
|
});
|
|
2355
|
-
if (count > 0)
|
|
2551
|
+
if (count > 0) {
|
|
2552
|
+
throw createError(propName, propValue);
|
|
2553
|
+
}
|
|
2356
2554
|
} else {
|
|
2357
2555
|
throw new InvalidArgumentError(
|
|
2358
2556
|
"The PropertyUniquenessValidator does not support the adapter method %v.",
|
|
@@ -2389,20 +2587,22 @@ var init_primary_keys_definition_validator = __esm({
|
|
|
2389
2587
|
});
|
|
2390
2588
|
if (propNames.length < 1) {
|
|
2391
2589
|
const isDefaultPrimaryKeyAlreadyInUse = Object.keys(propDefs).includes(DEFAULT_PRIMARY_KEY_PROPERTY_NAME);
|
|
2392
|
-
if (isDefaultPrimaryKeyAlreadyInUse)
|
|
2590
|
+
if (isDefaultPrimaryKeyAlreadyInUse) {
|
|
2393
2591
|
throw new InvalidArgumentError(
|
|
2394
2592
|
'The property name %v of the model %v is defined as a regular property. In this case, a primary key should be defined explicitly. Do use the option "primaryKey" to specify the primary key.',
|
|
2395
2593
|
DEFAULT_PRIMARY_KEY_PROPERTY_NAME,
|
|
2396
2594
|
modelName
|
|
2397
2595
|
);
|
|
2596
|
+
}
|
|
2398
2597
|
return;
|
|
2399
2598
|
}
|
|
2400
|
-
if (propNames.length > 1)
|
|
2599
|
+
if (propNames.length > 1) {
|
|
2401
2600
|
throw new InvalidArgumentError(
|
|
2402
2601
|
"The model definition %v should not have multiple primary keys, but %v keys given.",
|
|
2403
2602
|
modelName,
|
|
2404
2603
|
propNames.length
|
|
2405
2604
|
);
|
|
2605
|
+
}
|
|
2406
2606
|
const pkPropName = propNames[0];
|
|
2407
2607
|
const pkPropDef = propDefs[pkPropName];
|
|
2408
2608
|
if (pkPropDef && typeof pkPropDef === "object" && pkPropDef.default !== void 0) {
|
|
@@ -2438,11 +2638,12 @@ var init_properties_definition_validator = __esm({
|
|
|
2438
2638
|
* @param {object} propDefs
|
|
2439
2639
|
*/
|
|
2440
2640
|
validate(modelName, propDefs) {
|
|
2441
|
-
if (!modelName || typeof modelName !== "string")
|
|
2641
|
+
if (!modelName || typeof modelName !== "string") {
|
|
2442
2642
|
throw new InvalidArgumentError(
|
|
2443
2643
|
"The first argument of PropertiesDefinitionValidator.validate should be a non-empty String, but %v was given.",
|
|
2444
2644
|
modelName
|
|
2445
2645
|
);
|
|
2646
|
+
}
|
|
2446
2647
|
if (!propDefs || typeof propDefs !== "object" || Array.isArray(propDefs)) {
|
|
2447
2648
|
throw new InvalidArgumentError(
|
|
2448
2649
|
'The provided option "properties" of the model %v should be an Object, but %v was given.',
|
|
@@ -2468,26 +2669,29 @@ var init_properties_definition_validator = __esm({
|
|
|
2468
2669
|
* @param {object} propDef
|
|
2469
2670
|
*/
|
|
2470
2671
|
_validateProperty(modelName, propName, propDef) {
|
|
2471
|
-
if (!modelName || typeof modelName !== "string")
|
|
2672
|
+
if (!modelName || typeof modelName !== "string") {
|
|
2472
2673
|
throw new InvalidArgumentError(
|
|
2473
2674
|
"The first argument of PropertiesDefinitionValidator._validateProperty should be a non-empty String, but %v was given.",
|
|
2474
2675
|
modelName
|
|
2475
2676
|
);
|
|
2476
|
-
|
|
2677
|
+
}
|
|
2678
|
+
if (!propName || typeof propName !== "string") {
|
|
2477
2679
|
throw new InvalidArgumentError(
|
|
2478
2680
|
"The property name of the model %v should be a non-empty String, but %v was given.",
|
|
2479
2681
|
modelName,
|
|
2480
2682
|
propName
|
|
2481
2683
|
);
|
|
2482
|
-
|
|
2684
|
+
}
|
|
2685
|
+
if (!propDef) {
|
|
2483
2686
|
throw new InvalidArgumentError(
|
|
2484
2687
|
"The property %v of the model %v should have a property definition, but %v was given.",
|
|
2485
2688
|
propName,
|
|
2486
2689
|
modelName,
|
|
2487
2690
|
propDef
|
|
2488
2691
|
);
|
|
2692
|
+
}
|
|
2489
2693
|
if (typeof propDef === "string") {
|
|
2490
|
-
if (!Object.values(DataType).includes(propDef))
|
|
2694
|
+
if (!Object.values(DataType).includes(propDef)) {
|
|
2491
2695
|
throw new InvalidArgumentError(
|
|
2492
2696
|
"In case of a short property definition, the property %v of the model %v should have one of data types: %l, but %v was given.",
|
|
2493
2697
|
propName,
|
|
@@ -2495,6 +2699,7 @@ var init_properties_definition_validator = __esm({
|
|
|
2495
2699
|
Object.values(DataType),
|
|
2496
2700
|
propDef
|
|
2497
2701
|
);
|
|
2702
|
+
}
|
|
2498
2703
|
return;
|
|
2499
2704
|
}
|
|
2500
2705
|
if (!propDef || typeof propDef !== "object" || Array.isArray(propDef)) {
|
|
@@ -2505,7 +2710,7 @@ var init_properties_definition_validator = __esm({
|
|
|
2505
2710
|
propDef
|
|
2506
2711
|
);
|
|
2507
2712
|
}
|
|
2508
|
-
if (!propDef.type || !Object.values(DataType).includes(propDef.type))
|
|
2713
|
+
if (!propDef.type || !Object.values(DataType).includes(propDef.type)) {
|
|
2509
2714
|
throw new InvalidArgumentError(
|
|
2510
2715
|
'The property %v of the model %v requires the option "type" to have one of data types: %l, but %v was given.',
|
|
2511
2716
|
propName,
|
|
@@ -2513,6 +2718,7 @@ var init_properties_definition_validator = __esm({
|
|
|
2513
2718
|
Object.values(DataType),
|
|
2514
2719
|
propDef.type
|
|
2515
2720
|
);
|
|
2721
|
+
}
|
|
2516
2722
|
if (propDef.itemType && !Object.values(DataType).includes(propDef.itemType)) {
|
|
2517
2723
|
throw new InvalidArgumentError(
|
|
2518
2724
|
'The provided option "itemType" of the property %v in the model %v should have one of data types: %l, but %v was given.',
|
|
@@ -2530,73 +2736,83 @@ var init_properties_definition_validator = __esm({
|
|
|
2530
2736
|
propDef.itemModel
|
|
2531
2737
|
);
|
|
2532
2738
|
}
|
|
2533
|
-
if (propDef.model && typeof propDef.model !== "string")
|
|
2739
|
+
if (propDef.model && typeof propDef.model !== "string") {
|
|
2534
2740
|
throw new InvalidArgumentError(
|
|
2535
2741
|
'The provided option "model" of the property %v in the model %v should be a String, but %v was given.',
|
|
2536
2742
|
propName,
|
|
2537
2743
|
modelName,
|
|
2538
2744
|
propDef.model
|
|
2539
2745
|
);
|
|
2540
|
-
|
|
2746
|
+
}
|
|
2747
|
+
if (propDef.primaryKey && typeof propDef.primaryKey !== "boolean") {
|
|
2541
2748
|
throw new InvalidArgumentError(
|
|
2542
2749
|
'The provided option "primaryKey" of the property %v in the model %v should be a Boolean, but %v was given.',
|
|
2543
2750
|
propName,
|
|
2544
2751
|
modelName,
|
|
2545
2752
|
propDef.primaryKey
|
|
2546
2753
|
);
|
|
2547
|
-
|
|
2754
|
+
}
|
|
2755
|
+
if (propDef.columnName && typeof propDef.columnName !== "string") {
|
|
2548
2756
|
throw new InvalidArgumentError(
|
|
2549
2757
|
'The provided option "columnName" of the property %v in the model %v should be a String, but %v was given.',
|
|
2550
2758
|
propName,
|
|
2551
2759
|
modelName,
|
|
2552
2760
|
propDef.columnName
|
|
2553
2761
|
);
|
|
2554
|
-
|
|
2762
|
+
}
|
|
2763
|
+
if (propDef.columnType && typeof propDef.columnType !== "string") {
|
|
2555
2764
|
throw new InvalidArgumentError(
|
|
2556
2765
|
'The provided option "columnType" of the property %v in the model %v should be a String, but %v was given.',
|
|
2557
2766
|
propName,
|
|
2558
2767
|
modelName,
|
|
2559
2768
|
propDef.columnType
|
|
2560
2769
|
);
|
|
2561
|
-
|
|
2770
|
+
}
|
|
2771
|
+
if (propDef.required && typeof propDef.required !== "boolean") {
|
|
2562
2772
|
throw new InvalidArgumentError(
|
|
2563
2773
|
'The provided option "required" of the property %v in the model %v should be a Boolean, but %v was given.',
|
|
2564
2774
|
propName,
|
|
2565
2775
|
modelName,
|
|
2566
2776
|
propDef.required
|
|
2567
2777
|
);
|
|
2568
|
-
|
|
2778
|
+
}
|
|
2779
|
+
if (propDef.required && propDef.default !== void 0) {
|
|
2569
2780
|
throw new InvalidArgumentError(
|
|
2570
2781
|
'The property %v of the model %v is a required property, so it should not have the option "default" to be provided.',
|
|
2571
2782
|
propName,
|
|
2572
2783
|
modelName
|
|
2573
2784
|
);
|
|
2574
|
-
|
|
2785
|
+
}
|
|
2786
|
+
if (propDef.primaryKey && propDef.required) {
|
|
2575
2787
|
throw new InvalidArgumentError(
|
|
2576
2788
|
'The property %v of the model %v is a primary key, so it should not have the option "required" to be provided.',
|
|
2577
2789
|
propName,
|
|
2578
2790
|
modelName
|
|
2579
2791
|
);
|
|
2580
|
-
|
|
2792
|
+
}
|
|
2793
|
+
if (propDef.primaryKey && propDef.default !== void 0) {
|
|
2581
2794
|
throw new InvalidArgumentError(
|
|
2582
2795
|
'The property %v of the model %v is a primary key, so it should not have the option "default" to be provided.',
|
|
2583
2796
|
propName,
|
|
2584
2797
|
modelName
|
|
2585
2798
|
);
|
|
2586
|
-
|
|
2799
|
+
}
|
|
2800
|
+
if (propDef.itemType && propDef.type !== DataType.ARRAY) {
|
|
2587
2801
|
throw new InvalidArgumentError(
|
|
2588
2802
|
'The property %v of the model %v has a non-array type, so it should not have the option "itemType" to be provided.',
|
|
2589
2803
|
propName,
|
|
2590
2804
|
modelName,
|
|
2591
2805
|
propDef.type
|
|
2592
2806
|
);
|
|
2593
|
-
|
|
2807
|
+
}
|
|
2808
|
+
if (propDef.itemModel && propDef.type !== DataType.ARRAY) {
|
|
2594
2809
|
throw new InvalidArgumentError(
|
|
2595
2810
|
'The option "itemModel" is not supported for %s property type, so the property %v of the model %v should not have the option "itemModel" to be provided.',
|
|
2596
2811
|
capitalize(propDef.type),
|
|
2597
2812
|
propName,
|
|
2598
2813
|
modelName
|
|
2599
2814
|
);
|
|
2815
|
+
}
|
|
2600
2816
|
if (propDef.itemModel && propDef.itemType !== DataType.OBJECT) {
|
|
2601
2817
|
if (propDef.itemType) {
|
|
2602
2818
|
throw new InvalidArgumentError(
|
|
@@ -2613,13 +2829,14 @@ var init_properties_definition_validator = __esm({
|
|
|
2613
2829
|
);
|
|
2614
2830
|
}
|
|
2615
2831
|
}
|
|
2616
|
-
if (propDef.model && propDef.type !== DataType.OBJECT)
|
|
2832
|
+
if (propDef.model && propDef.type !== DataType.OBJECT) {
|
|
2617
2833
|
throw new InvalidArgumentError(
|
|
2618
2834
|
'The option "model" is not supported for %s property type, so the property %v of the model %v should not have the option "model" to be provided.',
|
|
2619
2835
|
capitalize(propDef.type),
|
|
2620
2836
|
propName,
|
|
2621
2837
|
modelName
|
|
2622
2838
|
);
|
|
2839
|
+
}
|
|
2623
2840
|
if (propDef.unique) {
|
|
2624
2841
|
if (typeof propDef.unique !== "boolean" && !Object.values(PropertyUniqueness).includes(propDef.unique)) {
|
|
2625
2842
|
throw new InvalidArgumentError(
|
|
@@ -2631,12 +2848,13 @@ var init_properties_definition_validator = __esm({
|
|
|
2631
2848
|
);
|
|
2632
2849
|
}
|
|
2633
2850
|
}
|
|
2634
|
-
if (propDef.unique && propDef.primaryKey)
|
|
2851
|
+
if (propDef.unique && propDef.primaryKey) {
|
|
2635
2852
|
throw new InvalidArgumentError(
|
|
2636
2853
|
'The property %v of the model %v is a primary key, so it should not have the option "unique" to be provided.',
|
|
2637
2854
|
propName,
|
|
2638
2855
|
modelName
|
|
2639
2856
|
);
|
|
2857
|
+
}
|
|
2640
2858
|
}
|
|
2641
2859
|
};
|
|
2642
2860
|
__name(_PropertiesDefinitionValidator, "PropertiesDefinitionValidator");
|
|
@@ -2682,16 +2900,18 @@ var init_model_data_sanitizer = __esm({
|
|
|
2682
2900
|
* @returns {object}
|
|
2683
2901
|
*/
|
|
2684
2902
|
sanitize(modelName, modelData) {
|
|
2685
|
-
if (!modelName || typeof modelName !== "string")
|
|
2903
|
+
if (!modelName || typeof modelName !== "string") {
|
|
2686
2904
|
throw new InvalidArgumentError(
|
|
2687
2905
|
"The first argument of ModelDataSanitizer.sanitize should be a string, but %v was given.",
|
|
2688
2906
|
modelName
|
|
2689
2907
|
);
|
|
2690
|
-
|
|
2908
|
+
}
|
|
2909
|
+
if (!modelData || typeof modelData !== "object") {
|
|
2691
2910
|
throw new InvalidArgumentError(
|
|
2692
2911
|
"The second argument of ModelDataSanitizer.sanitize should be an Object, but %v was given.",
|
|
2693
2912
|
modelData
|
|
2694
2913
|
);
|
|
2914
|
+
}
|
|
2695
2915
|
return this.getService(
|
|
2696
2916
|
ModelDefinitionUtils
|
|
2697
2917
|
).excludeObjectKeysByRelationNames(modelName, modelData);
|
|
@@ -2718,34 +2938,39 @@ var init_model_definition_validator = __esm({
|
|
|
2718
2938
|
* @param {object} modelDef
|
|
2719
2939
|
*/
|
|
2720
2940
|
validate(modelDef) {
|
|
2721
|
-
if (!modelDef || typeof modelDef !== "object" || Array.isArray(modelDef))
|
|
2941
|
+
if (!modelDef || typeof modelDef !== "object" || Array.isArray(modelDef)) {
|
|
2722
2942
|
throw new InvalidArgumentError(
|
|
2723
2943
|
"The model definition should be an Object, but %v was given.",
|
|
2724
2944
|
modelDef
|
|
2725
2945
|
);
|
|
2726
|
-
|
|
2946
|
+
}
|
|
2947
|
+
if (!modelDef.name || typeof modelDef.name !== "string") {
|
|
2727
2948
|
throw new InvalidArgumentError(
|
|
2728
2949
|
'The model definition requires the option "name" as a non-empty String, but %v was given.',
|
|
2729
2950
|
modelDef.name
|
|
2730
2951
|
);
|
|
2731
|
-
|
|
2952
|
+
}
|
|
2953
|
+
if (modelDef.datasource && typeof modelDef.datasource !== "string") {
|
|
2732
2954
|
throw new InvalidArgumentError(
|
|
2733
2955
|
'The provided option "datasource" of the model %v should be a String, but %v was given.',
|
|
2734
2956
|
modelDef.name,
|
|
2735
2957
|
modelDef.datasource
|
|
2736
2958
|
);
|
|
2737
|
-
|
|
2959
|
+
}
|
|
2960
|
+
if (modelDef.base && typeof modelDef.base !== "string") {
|
|
2738
2961
|
throw new InvalidArgumentError(
|
|
2739
2962
|
'The provided option "base" of the model %v should be a String, but %v was given.',
|
|
2740
2963
|
modelDef.name,
|
|
2741
2964
|
modelDef.base
|
|
2742
2965
|
);
|
|
2743
|
-
|
|
2966
|
+
}
|
|
2967
|
+
if (modelDef.tableName && typeof modelDef.tableName !== "string") {
|
|
2744
2968
|
throw new InvalidArgumentError(
|
|
2745
2969
|
'The provided option "tableName" of the model %v should be a String, but %v was given.',
|
|
2746
2970
|
modelDef.name,
|
|
2747
2971
|
modelDef.tableName
|
|
2748
2972
|
);
|
|
2973
|
+
}
|
|
2749
2974
|
if (modelDef.properties) {
|
|
2750
2975
|
if (typeof modelDef.properties !== "object" || Array.isArray(modelDef.properties)) {
|
|
2751
2976
|
throw new InvalidArgumentError(
|
|
@@ -2806,22 +3031,25 @@ var init_datasource_definition_validator = __esm({
|
|
|
2806
3031
|
* @param {object} datasourceDef
|
|
2807
3032
|
*/
|
|
2808
3033
|
validate(datasourceDef) {
|
|
2809
|
-
if (!datasourceDef || typeof datasourceDef !== "object")
|
|
3034
|
+
if (!datasourceDef || typeof datasourceDef !== "object") {
|
|
2810
3035
|
throw new InvalidArgumentError(
|
|
2811
3036
|
"The datasource definition should be an Object, but %v was given.",
|
|
2812
3037
|
datasourceDef
|
|
2813
3038
|
);
|
|
2814
|
-
|
|
3039
|
+
}
|
|
3040
|
+
if (!datasourceDef.name || typeof datasourceDef.name !== "string") {
|
|
2815
3041
|
throw new InvalidArgumentError(
|
|
2816
3042
|
'The datasource definition requires the option "name" as a non-empty String, but %v was given.',
|
|
2817
3043
|
datasourceDef.name
|
|
2818
3044
|
);
|
|
2819
|
-
|
|
3045
|
+
}
|
|
3046
|
+
if (!datasourceDef.adapter || typeof datasourceDef.adapter !== "string") {
|
|
2820
3047
|
throw new InvalidArgumentError(
|
|
2821
3048
|
'The datasource %v requires the option "adapter" as a non-empty String, but %v was given.',
|
|
2822
3049
|
datasourceDef.name,
|
|
2823
3050
|
datasourceDef.adapter
|
|
2824
3051
|
);
|
|
3052
|
+
}
|
|
2825
3053
|
}
|
|
2826
3054
|
};
|
|
2827
3055
|
__name(_DatasourceDefinitionValidator, "DatasourceDefinitionValidator");
|
|
@@ -2869,31 +3097,40 @@ var init_fields_clause_tool = __esm({
|
|
|
2869
3097
|
const isArray = Array.isArray(input);
|
|
2870
3098
|
let entities = isArray ? input : [input];
|
|
2871
3099
|
entities.forEach((entity) => {
|
|
2872
|
-
if (!entity || typeof entity !== "object" || Array.isArray(entity))
|
|
3100
|
+
if (!entity || typeof entity !== "object" || Array.isArray(entity)) {
|
|
2873
3101
|
throw new InvalidArgumentError(
|
|
2874
3102
|
"The first argument of FieldsClauseTool.filter should be an Object or an Array of Object, but %v was given.",
|
|
2875
3103
|
entity
|
|
2876
3104
|
);
|
|
3105
|
+
}
|
|
2877
3106
|
});
|
|
2878
|
-
if (!modelName || typeof modelName !== "string")
|
|
3107
|
+
if (!modelName || typeof modelName !== "string") {
|
|
2879
3108
|
throw new InvalidArgumentError(
|
|
2880
3109
|
"The second argument of FieldsClauseTool.filter should be a non-empty String, but %v was given.",
|
|
2881
3110
|
modelName
|
|
2882
3111
|
);
|
|
2883
|
-
|
|
3112
|
+
}
|
|
3113
|
+
if (clause == null) {
|
|
3114
|
+
return input;
|
|
3115
|
+
}
|
|
2884
3116
|
const fields = Array.isArray(clause) ? clause.slice() : [clause];
|
|
2885
|
-
if (!fields.length)
|
|
3117
|
+
if (!fields.length) {
|
|
3118
|
+
return input;
|
|
3119
|
+
}
|
|
2886
3120
|
fields.forEach((field) => {
|
|
2887
|
-
if (!field || typeof field !== "string")
|
|
3121
|
+
if (!field || typeof field !== "string") {
|
|
2888
3122
|
throw new InvalidArgumentError(
|
|
2889
3123
|
'The provided option "fields" should be a non-empty String or an Array of non-empty String, but %v was given.',
|
|
2890
3124
|
field
|
|
2891
3125
|
);
|
|
3126
|
+
}
|
|
2892
3127
|
});
|
|
2893
3128
|
const pkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
|
|
2894
3129
|
modelName
|
|
2895
3130
|
);
|
|
2896
|
-
if (fields.indexOf(pkPropName) === -1)
|
|
3131
|
+
if (fields.indexOf(pkPropName) === -1) {
|
|
3132
|
+
fields.push(pkPropName);
|
|
3133
|
+
}
|
|
2897
3134
|
entities = entities.map((entity) => selectObjectKeys(entity, fields));
|
|
2898
3135
|
return isArray ? entities : entities[0];
|
|
2899
3136
|
}
|
|
@@ -2903,15 +3140,20 @@ var init_fields_clause_tool = __esm({
|
|
|
2903
3140
|
* @param {string|string[]|undefined} clause
|
|
2904
3141
|
*/
|
|
2905
3142
|
static validateFieldsClause(clause) {
|
|
2906
|
-
if (clause == null)
|
|
3143
|
+
if (clause == null) {
|
|
3144
|
+
return;
|
|
3145
|
+
}
|
|
2907
3146
|
const fields = Array.isArray(clause) ? clause : [clause];
|
|
2908
|
-
if (!fields.length)
|
|
3147
|
+
if (!fields.length) {
|
|
3148
|
+
return;
|
|
3149
|
+
}
|
|
2909
3150
|
fields.forEach((field) => {
|
|
2910
|
-
if (!field || typeof field !== "string")
|
|
3151
|
+
if (!field || typeof field !== "string") {
|
|
2911
3152
|
throw new InvalidArgumentError(
|
|
2912
3153
|
'The provided option "fields" should be a non-empty String or an Array of non-empty String, but %v was given.',
|
|
2913
3154
|
field
|
|
2914
3155
|
);
|
|
3156
|
+
}
|
|
2915
3157
|
});
|
|
2916
3158
|
}
|
|
2917
3159
|
/**
|
|
@@ -2921,15 +3163,20 @@ var init_fields_clause_tool = __esm({
|
|
|
2921
3163
|
* @returns {string[]|undefined}
|
|
2922
3164
|
*/
|
|
2923
3165
|
static normalizeFieldsClause(clause) {
|
|
2924
|
-
if (clause == null)
|
|
3166
|
+
if (clause == null) {
|
|
3167
|
+
return;
|
|
3168
|
+
}
|
|
2925
3169
|
const fields = Array.isArray(clause) ? clause : [clause];
|
|
2926
|
-
if (!fields.length)
|
|
3170
|
+
if (!fields.length) {
|
|
3171
|
+
return;
|
|
3172
|
+
}
|
|
2927
3173
|
fields.forEach((field) => {
|
|
2928
|
-
if (!field || typeof field !== "string")
|
|
3174
|
+
if (!field || typeof field !== "string") {
|
|
2929
3175
|
throw new InvalidArgumentError(
|
|
2930
3176
|
'The provided option "fields" should be a non-empty String or an Array of non-empty String, but %v was given.',
|
|
2931
3177
|
field
|
|
2932
3178
|
);
|
|
3179
|
+
}
|
|
2933
3180
|
});
|
|
2934
3181
|
return fields;
|
|
2935
3182
|
}
|
|
@@ -2955,18 +3202,20 @@ var init_inclusion_decorator = __esm({
|
|
|
2955
3202
|
* @param {Adapter} adapter
|
|
2956
3203
|
*/
|
|
2957
3204
|
decorate(adapter) {
|
|
2958
|
-
if (!adapter || !(adapter instanceof Adapter))
|
|
3205
|
+
if (!adapter || !(adapter instanceof Adapter)) {
|
|
2959
3206
|
throw new InvalidArgumentError(
|
|
2960
3207
|
"The first argument of InclusionDecorator.decorate should be an Adapter instance, but %v was given.",
|
|
2961
3208
|
adapter
|
|
2962
3209
|
);
|
|
3210
|
+
}
|
|
2963
3211
|
const tool = adapter.getService(IncludeClauseTool);
|
|
2964
3212
|
const includeTo = /* @__PURE__ */ __name((...args) => tool.includeTo(...args), "includeTo");
|
|
2965
3213
|
const create = adapter.create;
|
|
2966
3214
|
adapter.create = async function(modelName, modelData, filter) {
|
|
2967
3215
|
const retvalData = await create.call(this, modelName, modelData, filter);
|
|
2968
|
-
if (filter && typeof filter === "object" && filter.include)
|
|
3216
|
+
if (filter && typeof filter === "object" && filter.include) {
|
|
2969
3217
|
await includeTo([retvalData], modelName, filter.include);
|
|
3218
|
+
}
|
|
2970
3219
|
return retvalData;
|
|
2971
3220
|
};
|
|
2972
3221
|
const replaceById = adapter.replaceById;
|
|
@@ -2978,8 +3227,9 @@ var init_inclusion_decorator = __esm({
|
|
|
2978
3227
|
modelData,
|
|
2979
3228
|
filter
|
|
2980
3229
|
);
|
|
2981
|
-
if (filter && typeof filter === "object" && filter.include)
|
|
3230
|
+
if (filter && typeof filter === "object" && filter.include) {
|
|
2982
3231
|
await includeTo([retvalData], modelName, filter.include);
|
|
3232
|
+
}
|
|
2983
3233
|
return retvalData;
|
|
2984
3234
|
};
|
|
2985
3235
|
const replaceOrCreate = adapter.replaceOrCreate;
|
|
@@ -2990,8 +3240,9 @@ var init_inclusion_decorator = __esm({
|
|
|
2990
3240
|
modelData,
|
|
2991
3241
|
filter
|
|
2992
3242
|
);
|
|
2993
|
-
if (filter && typeof filter === "object" && filter.include)
|
|
3243
|
+
if (filter && typeof filter === "object" && filter.include) {
|
|
2994
3244
|
await includeTo([retvalData], modelName, filter.include);
|
|
3245
|
+
}
|
|
2995
3246
|
return retvalData;
|
|
2996
3247
|
};
|
|
2997
3248
|
const patchById = adapter.patchById;
|
|
@@ -3003,22 +3254,25 @@ var init_inclusion_decorator = __esm({
|
|
|
3003
3254
|
modelData,
|
|
3004
3255
|
filter
|
|
3005
3256
|
);
|
|
3006
|
-
if (filter && typeof filter === "object" && filter.include)
|
|
3257
|
+
if (filter && typeof filter === "object" && filter.include) {
|
|
3007
3258
|
await includeTo([retvalData], modelName, filter.include);
|
|
3259
|
+
}
|
|
3008
3260
|
return retvalData;
|
|
3009
3261
|
};
|
|
3010
3262
|
const find = adapter.find;
|
|
3011
3263
|
adapter.find = async function(modelName, filter) {
|
|
3012
3264
|
const modelItems = await find.call(this, modelName, filter);
|
|
3013
|
-
if (filter && typeof filter === "object" && filter.include)
|
|
3265
|
+
if (filter && typeof filter === "object" && filter.include) {
|
|
3014
3266
|
await includeTo(modelItems, modelName, filter.include);
|
|
3267
|
+
}
|
|
3015
3268
|
return modelItems;
|
|
3016
3269
|
};
|
|
3017
3270
|
const findById = adapter.findById;
|
|
3018
3271
|
adapter.findById = async function(modelName, id, filter) {
|
|
3019
3272
|
const retvalData = await findById.call(this, modelName, id, filter);
|
|
3020
|
-
if (filter && typeof filter === "object" && filter.include)
|
|
3273
|
+
if (filter && typeof filter === "object" && filter.include) {
|
|
3021
3274
|
await includeTo([retvalData], modelName, filter.include);
|
|
3275
|
+
}
|
|
3022
3276
|
return retvalData;
|
|
3023
3277
|
};
|
|
3024
3278
|
}
|
|
@@ -3044,11 +3298,12 @@ var init_default_values_decorator = __esm({
|
|
|
3044
3298
|
* @param {Adapter} adapter
|
|
3045
3299
|
*/
|
|
3046
3300
|
decorate(adapter) {
|
|
3047
|
-
if (!adapter || !(adapter instanceof Adapter))
|
|
3301
|
+
if (!adapter || !(adapter instanceof Adapter)) {
|
|
3048
3302
|
throw new InvalidArgumentError(
|
|
3049
3303
|
"The first argument of DefaultValuesDecorator.decorate should be an Adapter instance, but %v was given.",
|
|
3050
3304
|
adapter
|
|
3051
3305
|
);
|
|
3306
|
+
}
|
|
3052
3307
|
const utils = adapter.getService(ModelDefinitionUtils);
|
|
3053
3308
|
const setDefaults = /* @__PURE__ */ __name((...args) => utils.setDefaultValuesToEmptyProperties(...args), "setDefaults");
|
|
3054
3309
|
const create = adapter.create;
|
|
@@ -3109,11 +3364,12 @@ var init_data_sanitizing_decorator = __esm({
|
|
|
3109
3364
|
* @param {Adapter} adapter
|
|
3110
3365
|
*/
|
|
3111
3366
|
decorate(adapter) {
|
|
3112
|
-
if (!adapter || !(adapter instanceof Adapter))
|
|
3367
|
+
if (!adapter || !(adapter instanceof Adapter)) {
|
|
3113
3368
|
throw new InvalidArgumentError(
|
|
3114
3369
|
"The first argument of DataSanitizingDecorator.decorate should be an Adapter instance, but %v was given.",
|
|
3115
3370
|
adapter
|
|
3116
3371
|
);
|
|
3372
|
+
}
|
|
3117
3373
|
const sanitizer = adapter.getService(ModelDataSanitizer);
|
|
3118
3374
|
const sanitize = /* @__PURE__ */ __name((...args) => sanitizer.sanitize(...args), "sanitize");
|
|
3119
3375
|
const create = adapter.create;
|
|
@@ -3164,18 +3420,20 @@ var init_fields_filtering_decorator = __esm({
|
|
|
3164
3420
|
* @param {Adapter} adapter
|
|
3165
3421
|
*/
|
|
3166
3422
|
decorate(adapter) {
|
|
3167
|
-
if (!adapter || !(adapter instanceof Adapter))
|
|
3423
|
+
if (!adapter || !(adapter instanceof Adapter)) {
|
|
3168
3424
|
throw new InvalidArgumentError(
|
|
3169
3425
|
"The first argument of FieldsFilteringDecorator.decorate should be an Adapter instance, but %v was given.",
|
|
3170
3426
|
adapter
|
|
3171
3427
|
);
|
|
3428
|
+
}
|
|
3172
3429
|
const tool = adapter.getService(FieldsClauseTool);
|
|
3173
3430
|
const selectFields = /* @__PURE__ */ __name((...args) => tool.filter(...args), "selectFields");
|
|
3174
3431
|
const create = adapter.create;
|
|
3175
3432
|
adapter.create = async function(modelName, modelData, filter) {
|
|
3176
3433
|
let result = await create.call(this, modelName, modelData, filter);
|
|
3177
|
-
if (filter && typeof filter === "object" && filter.fields)
|
|
3434
|
+
if (filter && typeof filter === "object" && filter.fields) {
|
|
3178
3435
|
result = selectFields(result, modelName, filter.fields);
|
|
3436
|
+
}
|
|
3179
3437
|
return result;
|
|
3180
3438
|
};
|
|
3181
3439
|
const replaceById = adapter.replaceById;
|
|
@@ -3187,8 +3445,9 @@ var init_fields_filtering_decorator = __esm({
|
|
|
3187
3445
|
modelData,
|
|
3188
3446
|
filter
|
|
3189
3447
|
);
|
|
3190
|
-
if (filter && typeof filter === "object" && filter.fields)
|
|
3448
|
+
if (filter && typeof filter === "object" && filter.fields) {
|
|
3191
3449
|
result = selectFields(result, modelName, filter.fields);
|
|
3450
|
+
}
|
|
3192
3451
|
return result;
|
|
3193
3452
|
};
|
|
3194
3453
|
const replaceOrCreate = adapter.replaceOrCreate;
|
|
@@ -3199,29 +3458,33 @@ var init_fields_filtering_decorator = __esm({
|
|
|
3199
3458
|
modelData,
|
|
3200
3459
|
filter
|
|
3201
3460
|
);
|
|
3202
|
-
if (filter && typeof filter === "object" && filter.fields)
|
|
3461
|
+
if (filter && typeof filter === "object" && filter.fields) {
|
|
3203
3462
|
result = selectFields(result, modelName, filter.fields);
|
|
3463
|
+
}
|
|
3204
3464
|
return result;
|
|
3205
3465
|
};
|
|
3206
3466
|
const patchById = adapter.patchById;
|
|
3207
3467
|
adapter.patchById = async function(modelName, id, modelData, filter) {
|
|
3208
3468
|
let result = await patchById.call(this, modelName, id, modelData, filter);
|
|
3209
|
-
if (filter && typeof filter === "object" && filter.fields)
|
|
3469
|
+
if (filter && typeof filter === "object" && filter.fields) {
|
|
3210
3470
|
result = selectFields(result, modelName, filter.fields);
|
|
3471
|
+
}
|
|
3211
3472
|
return result;
|
|
3212
3473
|
};
|
|
3213
3474
|
const find = adapter.find;
|
|
3214
3475
|
adapter.find = async function(modelName, filter) {
|
|
3215
3476
|
let result = await find.call(this, modelName, filter);
|
|
3216
|
-
if (filter && typeof filter === "object" && filter.fields)
|
|
3477
|
+
if (filter && typeof filter === "object" && filter.fields) {
|
|
3217
3478
|
result = selectFields(result, modelName, filter.fields);
|
|
3479
|
+
}
|
|
3218
3480
|
return result;
|
|
3219
3481
|
};
|
|
3220
3482
|
const findById = adapter.findById;
|
|
3221
3483
|
adapter.findById = async function(modelName, id, filter) {
|
|
3222
3484
|
let result = await findById.call(this, modelName, id, filter);
|
|
3223
|
-
if (filter && typeof filter === "object" && filter.fields)
|
|
3485
|
+
if (filter && typeof filter === "object" && filter.fields) {
|
|
3224
3486
|
result = selectFields(result, modelName, filter.fields);
|
|
3487
|
+
}
|
|
3225
3488
|
return result;
|
|
3226
3489
|
};
|
|
3227
3490
|
}
|
|
@@ -3247,11 +3510,12 @@ var init_required_property_decorator = __esm({
|
|
|
3247
3510
|
* @param {Adapter} adapter
|
|
3248
3511
|
*/
|
|
3249
3512
|
decorate(adapter) {
|
|
3250
|
-
if (!adapter || !(adapter instanceof Adapter))
|
|
3513
|
+
if (!adapter || !(adapter instanceof Adapter)) {
|
|
3251
3514
|
throw new InvalidArgumentError(
|
|
3252
3515
|
"The first argument of RequiredPropertyDecorator.decorate should be an Adapter instance, but %v was given.",
|
|
3253
3516
|
adapter
|
|
3254
3517
|
);
|
|
3518
|
+
}
|
|
3255
3519
|
const validator = this.getService(RequiredPropertyValidator);
|
|
3256
3520
|
const create = adapter.create;
|
|
3257
3521
|
adapter.create = async function(modelName, modelData, filter) {
|
|
@@ -3301,11 +3565,12 @@ var init_property_uniqueness_decorator = __esm({
|
|
|
3301
3565
|
* @param {Adapter} adapter
|
|
3302
3566
|
*/
|
|
3303
3567
|
decorate(adapter) {
|
|
3304
|
-
if (!adapter || !(adapter instanceof Adapter))
|
|
3568
|
+
if (!adapter || !(adapter instanceof Adapter)) {
|
|
3305
3569
|
throw new InvalidArgumentError(
|
|
3306
3570
|
"The first argument of PropertyUniquenessDecorator.decorate should be an Adapter instance, but %v was given.",
|
|
3307
3571
|
adapter
|
|
3308
3572
|
);
|
|
3573
|
+
}
|
|
3309
3574
|
const validator = this.getService(PropertyUniquenessValidator);
|
|
3310
3575
|
const create = adapter.create;
|
|
3311
3576
|
adapter.create = async function(modelName, modelData, filter) {
|
|
@@ -3615,7 +3880,9 @@ var init_memory_adapter = __esm({
|
|
|
3615
3880
|
_getTableOrCreate(modelName) {
|
|
3616
3881
|
const tableName = this.getService(ModelDefinitionUtils).getTableNameByModelName(modelName);
|
|
3617
3882
|
let table = this._tables.get(tableName);
|
|
3618
|
-
if (table)
|
|
3883
|
+
if (table) {
|
|
3884
|
+
return table;
|
|
3885
|
+
}
|
|
3619
3886
|
table = /* @__PURE__ */ new Map();
|
|
3620
3887
|
this._tables.set(tableName, table);
|
|
3621
3888
|
return table;
|
|
@@ -3687,13 +3954,14 @@ var init_memory_adapter = __esm({
|
|
|
3687
3954
|
this._updateLastIdValueIfNeeded(modelName, idValue);
|
|
3688
3955
|
}
|
|
3689
3956
|
const table = this._getTableOrCreate(modelName);
|
|
3690
|
-
if (table.has(idValue))
|
|
3957
|
+
if (table.has(idValue)) {
|
|
3691
3958
|
throw new InvalidArgumentError(
|
|
3692
3959
|
"The value %v of the primary key %v already exists in the model %v.",
|
|
3693
3960
|
idValue,
|
|
3694
3961
|
pkPropName,
|
|
3695
3962
|
modelName
|
|
3696
3963
|
);
|
|
3964
|
+
}
|
|
3697
3965
|
modelData = cloneDeep(modelData);
|
|
3698
3966
|
modelData[pkPropName] = idValue;
|
|
3699
3967
|
const tableData = this.getService(
|
|
@@ -3720,13 +3988,14 @@ var init_memory_adapter = __esm({
|
|
|
3720
3988
|
const pkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
|
|
3721
3989
|
modelName
|
|
3722
3990
|
);
|
|
3723
|
-
if (!isExists)
|
|
3991
|
+
if (!isExists) {
|
|
3724
3992
|
throw new InvalidArgumentError(
|
|
3725
3993
|
"The value %v of the primary key %v does not exist in the model %v.",
|
|
3726
3994
|
id,
|
|
3727
3995
|
pkPropName,
|
|
3728
3996
|
modelName
|
|
3729
3997
|
);
|
|
3998
|
+
}
|
|
3730
3999
|
modelData = cloneDeep(modelData);
|
|
3731
4000
|
modelData[pkPropName] = id;
|
|
3732
4001
|
const tableData = this.getService(
|
|
@@ -3778,15 +4047,18 @@ var init_memory_adapter = __esm({
|
|
|
3778
4047
|
async patch(modelName, modelData, where = void 0) {
|
|
3779
4048
|
const table = this._getTableOrCreate(modelName);
|
|
3780
4049
|
const tableItems = Array.from(table.values());
|
|
3781
|
-
if (!tableItems.length)
|
|
4050
|
+
if (!tableItems.length) {
|
|
4051
|
+
return 0;
|
|
4052
|
+
}
|
|
3782
4053
|
let modelItems = tableItems.map(
|
|
3783
4054
|
(tableItem) => this.getService(ModelDefinitionUtils).convertColumnNamesToPropertyNames(
|
|
3784
4055
|
modelName,
|
|
3785
4056
|
tableItem
|
|
3786
4057
|
)
|
|
3787
4058
|
);
|
|
3788
|
-
if (where && typeof where === "object")
|
|
4059
|
+
if (where && typeof where === "object") {
|
|
3789
4060
|
modelItems = this.getService(WhereClauseTool).filter(modelItems, where);
|
|
4061
|
+
}
|
|
3790
4062
|
const size = modelItems.length;
|
|
3791
4063
|
const pkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
|
|
3792
4064
|
modelName
|
|
@@ -3819,13 +4091,14 @@ var init_memory_adapter = __esm({
|
|
|
3819
4091
|
const pkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
|
|
3820
4092
|
modelName
|
|
3821
4093
|
);
|
|
3822
|
-
if (existingTableData == null)
|
|
4094
|
+
if (existingTableData == null) {
|
|
3823
4095
|
throw new InvalidArgumentError(
|
|
3824
4096
|
"The value %v of the primary key %v does not exist in the model %v.",
|
|
3825
4097
|
id,
|
|
3826
4098
|
pkPropName,
|
|
3827
4099
|
modelName
|
|
3828
4100
|
);
|
|
4101
|
+
}
|
|
3829
4102
|
modelData = cloneDeep(modelData);
|
|
3830
4103
|
delete modelData[pkPropName];
|
|
3831
4104
|
const existingModelData = this.getService(
|
|
@@ -3857,19 +4130,22 @@ var init_memory_adapter = __esm({
|
|
|
3857
4130
|
)
|
|
3858
4131
|
);
|
|
3859
4132
|
if (filter && typeof filter === "object") {
|
|
3860
|
-
if (filter.where)
|
|
4133
|
+
if (filter.where) {
|
|
3861
4134
|
modelItems = this.getService(WhereClauseTool).filter(
|
|
3862
4135
|
modelItems,
|
|
3863
4136
|
filter.where
|
|
3864
4137
|
);
|
|
3865
|
-
|
|
4138
|
+
}
|
|
4139
|
+
if (filter.skip || filter.limit) {
|
|
3866
4140
|
modelItems = this.getService(SliceClauseTool).slice(
|
|
3867
4141
|
modelItems,
|
|
3868
4142
|
filter.skip,
|
|
3869
4143
|
filter.limit
|
|
3870
4144
|
);
|
|
3871
|
-
|
|
4145
|
+
}
|
|
4146
|
+
if (filter.order) {
|
|
3872
4147
|
this.getService(OrderClauseTool).sort(modelItems, filter.order);
|
|
4148
|
+
}
|
|
3873
4149
|
}
|
|
3874
4150
|
return modelItems;
|
|
3875
4151
|
}
|
|
@@ -3888,13 +4164,14 @@ var init_memory_adapter = __esm({
|
|
|
3888
4164
|
const pkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
|
|
3889
4165
|
modelName
|
|
3890
4166
|
);
|
|
3891
|
-
if (!tableData)
|
|
4167
|
+
if (!tableData) {
|
|
3892
4168
|
throw new InvalidArgumentError(
|
|
3893
4169
|
"The value %v of the primary key %v does not exist in the model %v.",
|
|
3894
4170
|
id,
|
|
3895
4171
|
pkPropName,
|
|
3896
4172
|
modelName
|
|
3897
4173
|
);
|
|
4174
|
+
}
|
|
3898
4175
|
return this.getService(
|
|
3899
4176
|
ModelDefinitionUtils
|
|
3900
4177
|
).convertColumnNamesToPropertyNames(modelName, tableData);
|
|
@@ -3909,15 +4186,18 @@ var init_memory_adapter = __esm({
|
|
|
3909
4186
|
async delete(modelName, where = void 0) {
|
|
3910
4187
|
const table = this._getTableOrCreate(modelName);
|
|
3911
4188
|
const tableItems = Array.from(table.values());
|
|
3912
|
-
if (!tableItems.length)
|
|
4189
|
+
if (!tableItems.length) {
|
|
4190
|
+
return 0;
|
|
4191
|
+
}
|
|
3913
4192
|
let modelItems = tableItems.map(
|
|
3914
4193
|
(tableItem) => this.getService(ModelDefinitionUtils).convertColumnNamesToPropertyNames(
|
|
3915
4194
|
modelName,
|
|
3916
4195
|
tableItem
|
|
3917
4196
|
)
|
|
3918
4197
|
);
|
|
3919
|
-
if (where && typeof where === "object")
|
|
4198
|
+
if (where && typeof where === "object") {
|
|
3920
4199
|
modelItems = this.getService(WhereClauseTool).filter(modelItems, where);
|
|
4200
|
+
}
|
|
3921
4201
|
const size = modelItems.length;
|
|
3922
4202
|
const idPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
|
|
3923
4203
|
modelName
|
|
@@ -3968,8 +4248,9 @@ var init_memory_adapter = __esm({
|
|
|
3968
4248
|
tableItem
|
|
3969
4249
|
)
|
|
3970
4250
|
);
|
|
3971
|
-
if (where && typeof where === "object")
|
|
4251
|
+
if (where && typeof where === "object") {
|
|
3972
4252
|
modelItems = this.getService(WhereClauseTool).filter(modelItems, where);
|
|
4253
|
+
}
|
|
3973
4254
|
return modelItems.length;
|
|
3974
4255
|
}
|
|
3975
4256
|
};
|
|
@@ -3991,7 +4272,9 @@ var init_ = __esm({
|
|
|
3991
4272
|
// src/adapter/adapter-loader.js
|
|
3992
4273
|
function findAdapterCtorInModule(module2) {
|
|
3993
4274
|
let adapterCtor;
|
|
3994
|
-
if (!module2 || typeof module2 !== "object" || Array.isArray(module2))
|
|
4275
|
+
if (!module2 || typeof module2 !== "object" || Array.isArray(module2)) {
|
|
4276
|
+
return;
|
|
4277
|
+
}
|
|
3995
4278
|
for (const ctor of Object.values(module2)) {
|
|
3996
4279
|
if (typeof ctor === "function" && Array.isArray(ctor.kinds) && Adapter.kinds.includes(ADAPTER_CLASS_NAME)) {
|
|
3997
4280
|
adapterCtor = ctor;
|
|
@@ -4017,28 +4300,31 @@ var init_adapter_loader = __esm({
|
|
|
4017
4300
|
* @returns {Promise<Adapter>}
|
|
4018
4301
|
*/
|
|
4019
4302
|
async loadByName(adapterName, settings = void 0) {
|
|
4020
|
-
if (!adapterName || typeof adapterName !== "string")
|
|
4303
|
+
if (!adapterName || typeof adapterName !== "string") {
|
|
4021
4304
|
throw new InvalidArgumentError(
|
|
4022
4305
|
"The adapter name should be a non-empty String, but %v was given.",
|
|
4023
4306
|
adapterName
|
|
4024
4307
|
);
|
|
4308
|
+
}
|
|
4025
4309
|
let adapterCtor;
|
|
4026
4310
|
try {
|
|
4027
4311
|
const module2 = await globImport_builtin_adapter_js(`./builtin/${adapterName}-adapter.js`);
|
|
4028
4312
|
adapterCtor = findAdapterCtorInModule(module2);
|
|
4029
4313
|
} catch {
|
|
4030
4314
|
}
|
|
4031
|
-
if (!adapterCtor)
|
|
4315
|
+
if (!adapterCtor) {
|
|
4032
4316
|
try {
|
|
4033
4317
|
const module2 = await Promise.resolve().then(() => __toESM(require(`@e22m4u/js-repository-${adapterName}-adapter`)));
|
|
4034
4318
|
adapterCtor = findAdapterCtorInModule(module2);
|
|
4035
4319
|
} catch {
|
|
4036
4320
|
}
|
|
4037
|
-
|
|
4321
|
+
}
|
|
4322
|
+
if (!adapterCtor) {
|
|
4038
4323
|
throw new InvalidArgumentError(
|
|
4039
4324
|
"The adapter %v is not found.",
|
|
4040
4325
|
adapterName
|
|
4041
4326
|
);
|
|
4327
|
+
}
|
|
4042
4328
|
return new adapterCtor(this.container, settings);
|
|
4043
4329
|
}
|
|
4044
4330
|
};
|
|
@@ -4072,7 +4358,9 @@ var init_adapter_registry = __esm({
|
|
|
4072
4358
|
*/
|
|
4073
4359
|
async getAdapter(datasourceName) {
|
|
4074
4360
|
let adapter = this._adapters[datasourceName];
|
|
4075
|
-
if (adapter)
|
|
4361
|
+
if (adapter) {
|
|
4362
|
+
return adapter;
|
|
4363
|
+
}
|
|
4076
4364
|
const datasource = this.getService(DefinitionRegistry).getDatasource(datasourceName);
|
|
4077
4365
|
const adapterName = datasource.adapter;
|
|
4078
4366
|
adapter = await this.getService(AdapterLoader).loadByName(
|
|
@@ -4148,11 +4436,12 @@ var init_repository = __esm({
|
|
|
4148
4436
|
this._modelName = modelName;
|
|
4149
4437
|
const modelDef = this.getService(DefinitionRegistry).getModel(modelName);
|
|
4150
4438
|
const datasourceName = modelDef.datasource;
|
|
4151
|
-
if (!datasourceName)
|
|
4439
|
+
if (!datasourceName) {
|
|
4152
4440
|
throw new InvalidArgumentError(
|
|
4153
4441
|
"The model %v does not have a specified datasource.",
|
|
4154
4442
|
modelName
|
|
4155
4443
|
);
|
|
4444
|
+
}
|
|
4156
4445
|
this._datasourceName = datasourceName;
|
|
4157
4446
|
}
|
|
4158
4447
|
/**
|
|
@@ -4346,7 +4635,9 @@ var init_repository_registry = __esm({
|
|
|
4346
4635
|
getRepository(modelName) {
|
|
4347
4636
|
const modelKey = modelNameToModelKey(modelName);
|
|
4348
4637
|
let repository = this._repositories[modelKey];
|
|
4349
|
-
if (repository)
|
|
4638
|
+
if (repository) {
|
|
4639
|
+
return repository;
|
|
4640
|
+
}
|
|
4350
4641
|
repository = new this._repositoryCtor(this.container, modelName);
|
|
4351
4642
|
this._repositories[modelKey] = repository;
|
|
4352
4643
|
return repository;
|
|
@@ -4389,48 +4680,57 @@ var init_has_one_resolver = __esm({
|
|
|
4389
4680
|
* @returns {Promise<void>}
|
|
4390
4681
|
*/
|
|
4391
4682
|
async includeTo(entities, sourceName, targetName, relationName, foreignKey, scope = void 0) {
|
|
4392
|
-
if (!entities || !Array.isArray(entities))
|
|
4683
|
+
if (!entities || !Array.isArray(entities)) {
|
|
4393
4684
|
throw new InvalidArgumentError(
|
|
4394
4685
|
'The parameter "entities" of HasOneResolver.includeTo requires an Array of Object, but %v was given.',
|
|
4395
4686
|
entities
|
|
4396
4687
|
);
|
|
4397
|
-
|
|
4688
|
+
}
|
|
4689
|
+
if (!sourceName || typeof sourceName !== "string") {
|
|
4398
4690
|
throw new InvalidArgumentError(
|
|
4399
4691
|
'The parameter "sourceName" of HasOneResolver.includeTo requires a non-empty String, but %v was given.',
|
|
4400
4692
|
sourceName
|
|
4401
4693
|
);
|
|
4402
|
-
|
|
4694
|
+
}
|
|
4695
|
+
if (!targetName || typeof targetName !== "string") {
|
|
4403
4696
|
throw new InvalidArgumentError(
|
|
4404
4697
|
'The parameter "targetName" of HasOneResolver.includeTo requires a non-empty String, but %v was given.',
|
|
4405
4698
|
targetName
|
|
4406
4699
|
);
|
|
4407
|
-
|
|
4700
|
+
}
|
|
4701
|
+
if (!relationName || typeof relationName !== "string") {
|
|
4408
4702
|
throw new InvalidArgumentError(
|
|
4409
4703
|
'The parameter "relationName" of HasOneResolver.includeTo requires a non-empty String, but %v was given.',
|
|
4410
4704
|
relationName
|
|
4411
4705
|
);
|
|
4412
|
-
|
|
4706
|
+
}
|
|
4707
|
+
if (!foreignKey || typeof foreignKey !== "string") {
|
|
4413
4708
|
throw new InvalidArgumentError(
|
|
4414
4709
|
'The parameter "foreignKey" of HasOneResolver.includeTo requires a non-empty String, but %v was given.',
|
|
4415
4710
|
foreignKey
|
|
4416
4711
|
);
|
|
4417
|
-
|
|
4712
|
+
}
|
|
4713
|
+
if (scope && (typeof scope !== "object" || Array.isArray(scope))) {
|
|
4418
4714
|
throw new InvalidArgumentError(
|
|
4419
4715
|
'The provided parameter "scope" of HasOneResolver.includeTo should be an Object, but %v was given.',
|
|
4420
4716
|
scope
|
|
4421
4717
|
);
|
|
4718
|
+
}
|
|
4422
4719
|
const sourcePkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
|
|
4423
4720
|
sourceName
|
|
4424
4721
|
);
|
|
4425
4722
|
const sourceIds = [];
|
|
4426
4723
|
entities.forEach((entity) => {
|
|
4427
|
-
if (!entity || typeof entity !== "object" || Array.isArray(entity))
|
|
4724
|
+
if (!entity || typeof entity !== "object" || Array.isArray(entity)) {
|
|
4428
4725
|
throw new InvalidArgumentError(
|
|
4429
4726
|
'The parameter "entities" of HasOneResolver.includeTo requires an Array of Object, but %v was given.',
|
|
4430
4727
|
entity
|
|
4431
4728
|
);
|
|
4729
|
+
}
|
|
4432
4730
|
const sourceId = entity[sourcePkPropName];
|
|
4433
|
-
if (sourceIds.includes(sourceId))
|
|
4731
|
+
if (sourceIds.includes(sourceId)) {
|
|
4732
|
+
return;
|
|
4733
|
+
}
|
|
4434
4734
|
sourceIds.push(sourceId);
|
|
4435
4735
|
});
|
|
4436
4736
|
const promises = [];
|
|
@@ -4445,7 +4745,9 @@ var init_has_one_resolver = __esm({
|
|
|
4445
4745
|
filter.limit = 1;
|
|
4446
4746
|
promises.push(
|
|
4447
4747
|
targetRepository.find(filter).then((result) => {
|
|
4448
|
-
if (result.length)
|
|
4748
|
+
if (result.length) {
|
|
4749
|
+
targetBySourceId.set(sourceId, result[0]);
|
|
4750
|
+
}
|
|
4449
4751
|
})
|
|
4450
4752
|
);
|
|
4451
4753
|
});
|
|
@@ -4468,53 +4770,63 @@ var init_has_one_resolver = __esm({
|
|
|
4468
4770
|
* @returns {Promise<void>}
|
|
4469
4771
|
*/
|
|
4470
4772
|
async includePolymorphicTo(entities, sourceName, targetName, relationName, foreignKey, discriminator, scope = void 0) {
|
|
4471
|
-
if (!entities || !Array.isArray(entities))
|
|
4773
|
+
if (!entities || !Array.isArray(entities)) {
|
|
4472
4774
|
throw new InvalidArgumentError(
|
|
4473
4775
|
'The parameter "entities" of HasOneResolver.includePolymorphicTo requires an Array of Object, but %v was given.',
|
|
4474
4776
|
entities
|
|
4475
4777
|
);
|
|
4476
|
-
|
|
4778
|
+
}
|
|
4779
|
+
if (!sourceName || typeof sourceName !== "string") {
|
|
4477
4780
|
throw new InvalidArgumentError(
|
|
4478
4781
|
'The parameter "sourceName" of HasOneResolver.includePolymorphicTo requires a non-empty String, but %v was given.',
|
|
4479
4782
|
sourceName
|
|
4480
4783
|
);
|
|
4481
|
-
|
|
4784
|
+
}
|
|
4785
|
+
if (!targetName || typeof targetName !== "string") {
|
|
4482
4786
|
throw new InvalidArgumentError(
|
|
4483
4787
|
'The parameter "targetName" of HasOneResolver.includePolymorphicTo requires a non-empty String, but %v was given.',
|
|
4484
4788
|
targetName
|
|
4485
4789
|
);
|
|
4486
|
-
|
|
4790
|
+
}
|
|
4791
|
+
if (!relationName || typeof relationName !== "string") {
|
|
4487
4792
|
throw new InvalidArgumentError(
|
|
4488
4793
|
'The parameter "relationName" of HasOneResolver.includePolymorphicTo requires a non-empty String, but %v was given.',
|
|
4489
4794
|
relationName
|
|
4490
4795
|
);
|
|
4491
|
-
|
|
4796
|
+
}
|
|
4797
|
+
if (!foreignKey || typeof foreignKey !== "string") {
|
|
4492
4798
|
throw new InvalidArgumentError(
|
|
4493
4799
|
'The parameter "foreignKey" of HasOneResolver.includePolymorphicTo requires a non-empty String, but %v was given.',
|
|
4494
4800
|
foreignKey
|
|
4495
4801
|
);
|
|
4496
|
-
|
|
4802
|
+
}
|
|
4803
|
+
if (!discriminator || typeof discriminator !== "string") {
|
|
4497
4804
|
throw new InvalidArgumentError(
|
|
4498
4805
|
'The parameter "discriminator" of HasOneResolver.includePolymorphicTo requires a non-empty String, but %v was given.',
|
|
4499
4806
|
discriminator
|
|
4500
4807
|
);
|
|
4501
|
-
|
|
4808
|
+
}
|
|
4809
|
+
if (scope && (typeof scope !== "object" || Array.isArray(scope))) {
|
|
4502
4810
|
throw new InvalidArgumentError(
|
|
4503
4811
|
'The provided parameter "scope" of HasOneResolver.includePolymorphicTo should be an Object, but %v was given.',
|
|
4504
4812
|
scope
|
|
4505
4813
|
);
|
|
4814
|
+
}
|
|
4506
4815
|
const sourcePkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
|
|
4507
4816
|
sourceName
|
|
4508
4817
|
);
|
|
4509
4818
|
const sourceIds = [];
|
|
4510
4819
|
entities.forEach((entity) => {
|
|
4511
|
-
if (!entity || typeof entity !== "object" || Array.isArray(entity))
|
|
4820
|
+
if (!entity || typeof entity !== "object" || Array.isArray(entity)) {
|
|
4512
4821
|
throw new InvalidArgumentError(
|
|
4513
4822
|
'The parameter "entities" of HasOneResolver.includePolymorphicTo requires an Array of Object, but %v was given.',
|
|
4514
4823
|
entity
|
|
4515
4824
|
);
|
|
4825
|
+
}
|
|
4516
4826
|
const sourceId = entity[sourcePkPropName];
|
|
4517
|
-
if (sourceIds.includes(sourceId))
|
|
4827
|
+
if (sourceIds.includes(sourceId)) {
|
|
4828
|
+
return;
|
|
4829
|
+
}
|
|
4518
4830
|
sourceIds.push(sourceId);
|
|
4519
4831
|
});
|
|
4520
4832
|
const promises = [];
|
|
@@ -4532,7 +4844,9 @@ var init_has_one_resolver = __esm({
|
|
|
4532
4844
|
filter.limit = 1;
|
|
4533
4845
|
promises.push(
|
|
4534
4846
|
targetRepository.find(filter).then((result) => {
|
|
4535
|
-
if (result.length)
|
|
4847
|
+
if (result.length) {
|
|
4848
|
+
targetBySourceId.set(sourceId, result[0]);
|
|
4849
|
+
}
|
|
4536
4850
|
})
|
|
4537
4851
|
);
|
|
4538
4852
|
});
|
|
@@ -4554,40 +4868,46 @@ var init_has_one_resolver = __esm({
|
|
|
4554
4868
|
* @returns {Promise<void>}
|
|
4555
4869
|
*/
|
|
4556
4870
|
async includePolymorphicByRelationName(entities, sourceName, targetName, relationName, targetRelationName, scope = void 0) {
|
|
4557
|
-
if (!entities || !Array.isArray(entities))
|
|
4871
|
+
if (!entities || !Array.isArray(entities)) {
|
|
4558
4872
|
throw new InvalidArgumentError(
|
|
4559
4873
|
'The parameter "entities" of HasOneResolver.includePolymorphicByRelationName requires an Array of Object, but %v was given.',
|
|
4560
4874
|
entities
|
|
4561
4875
|
);
|
|
4562
|
-
|
|
4876
|
+
}
|
|
4877
|
+
if (!sourceName || typeof sourceName !== "string") {
|
|
4563
4878
|
throw new InvalidArgumentError(
|
|
4564
4879
|
'The parameter "sourceName" of HasOneResolver.includePolymorphicByRelationName requires a non-empty String, but %v was given.',
|
|
4565
4880
|
sourceName
|
|
4566
4881
|
);
|
|
4567
|
-
|
|
4882
|
+
}
|
|
4883
|
+
if (!targetName || typeof targetName !== "string") {
|
|
4568
4884
|
throw new InvalidArgumentError(
|
|
4569
4885
|
'The parameter "targetName" of HasOneResolver.includePolymorphicByRelationName requires a non-empty String, but %v was given.',
|
|
4570
4886
|
targetName
|
|
4571
4887
|
);
|
|
4572
|
-
|
|
4888
|
+
}
|
|
4889
|
+
if (!relationName || typeof relationName !== "string") {
|
|
4573
4890
|
throw new InvalidArgumentError(
|
|
4574
4891
|
'The parameter "relationName" of HasOneResolver.includePolymorphicByRelationName requires a non-empty String, but %v was given.',
|
|
4575
4892
|
relationName
|
|
4576
4893
|
);
|
|
4577
|
-
|
|
4894
|
+
}
|
|
4895
|
+
if (!targetRelationName || typeof targetRelationName !== "string") {
|
|
4578
4896
|
throw new InvalidArgumentError(
|
|
4579
4897
|
'The parameter "targetRelationName" of HasOneResolver.includePolymorphicByRelationName requires a non-empty String, but %v was given.',
|
|
4580
4898
|
targetRelationName
|
|
4581
4899
|
);
|
|
4582
|
-
|
|
4900
|
+
}
|
|
4901
|
+
if (scope && (typeof scope !== "object" || Array.isArray(scope))) {
|
|
4583
4902
|
throw new InvalidArgumentError(
|
|
4584
4903
|
'The provided parameter "scope" of HasOneResolver.includePolymorphicByRelationName should be an Object, but %v was given.',
|
|
4585
4904
|
scope
|
|
4586
4905
|
);
|
|
4906
|
+
}
|
|
4587
4907
|
const targetRelationDef = this.getService(
|
|
4588
4908
|
ModelDefinitionUtils
|
|
4589
4909
|
).getRelationDefinitionByName(targetName, targetRelationName);
|
|
4590
|
-
if (targetRelationDef.type !== RelationType.BELONGS_TO)
|
|
4910
|
+
if (targetRelationDef.type !== RelationType.BELONGS_TO) {
|
|
4591
4911
|
throw new InvalidArgumentError(
|
|
4592
4912
|
'The relation %v of the model %v is a polymorphic "hasOne" relation, so it requires the target relation %v to be a polymorphic "belongsTo", but %v type was given.',
|
|
4593
4913
|
relationName,
|
|
@@ -4595,13 +4915,15 @@ var init_has_one_resolver = __esm({
|
|
|
4595
4915
|
targetRelationName,
|
|
4596
4916
|
targetRelationDef.type
|
|
4597
4917
|
);
|
|
4598
|
-
|
|
4918
|
+
}
|
|
4919
|
+
if (!targetRelationDef.polymorphic) {
|
|
4599
4920
|
throw new InvalidArgumentError(
|
|
4600
4921
|
'The relation %v of the model %v is a polymorphic "hasOne" relation, so it requires the target relation %v to be a polymorphic too.',
|
|
4601
4922
|
relationName,
|
|
4602
4923
|
sourceName,
|
|
4603
4924
|
targetRelationName
|
|
4604
4925
|
);
|
|
4926
|
+
}
|
|
4605
4927
|
const foreignKey = targetRelationDef.foreignKey || `${targetRelationName}Id`;
|
|
4606
4928
|
const discriminator = targetRelationDef.discriminator || `${targetRelationName}Type`;
|
|
4607
4929
|
return this.includePolymorphicTo(
|
|
@@ -4643,48 +4965,57 @@ var init_has_many_resolver = __esm({
|
|
|
4643
4965
|
* @returns {Promise<void>}
|
|
4644
4966
|
*/
|
|
4645
4967
|
async includeTo(entities, sourceName, targetName, relationName, foreignKey, scope = void 0) {
|
|
4646
|
-
if (!entities || !Array.isArray(entities))
|
|
4968
|
+
if (!entities || !Array.isArray(entities)) {
|
|
4647
4969
|
throw new InvalidArgumentError(
|
|
4648
4970
|
'The parameter "entities" of HasManyResolver.includeTo requires an Array of Object, but %v was given.',
|
|
4649
4971
|
entities
|
|
4650
4972
|
);
|
|
4651
|
-
|
|
4973
|
+
}
|
|
4974
|
+
if (!sourceName || typeof sourceName !== "string") {
|
|
4652
4975
|
throw new InvalidArgumentError(
|
|
4653
4976
|
'The parameter "sourceName" of HasManyResolver.includeTo requires a non-empty String, but %v was given.',
|
|
4654
4977
|
sourceName
|
|
4655
4978
|
);
|
|
4656
|
-
|
|
4979
|
+
}
|
|
4980
|
+
if (!targetName || typeof targetName !== "string") {
|
|
4657
4981
|
throw new InvalidArgumentError(
|
|
4658
4982
|
'The parameter "targetName" of HasManyResolver.includeTo requires a non-empty String, but %v was given.',
|
|
4659
4983
|
targetName
|
|
4660
4984
|
);
|
|
4661
|
-
|
|
4985
|
+
}
|
|
4986
|
+
if (!relationName || typeof relationName !== "string") {
|
|
4662
4987
|
throw new InvalidArgumentError(
|
|
4663
4988
|
'The parameter "relationName" of HasManyResolver.includeTo requires a non-empty String, but %v was given.',
|
|
4664
4989
|
relationName
|
|
4665
4990
|
);
|
|
4666
|
-
|
|
4991
|
+
}
|
|
4992
|
+
if (!foreignKey || typeof foreignKey !== "string") {
|
|
4667
4993
|
throw new InvalidArgumentError(
|
|
4668
4994
|
'The parameter "foreignKey" of HasManyResolver.includeTo requires a non-empty String, but %v was given.',
|
|
4669
4995
|
foreignKey
|
|
4670
4996
|
);
|
|
4671
|
-
|
|
4997
|
+
}
|
|
4998
|
+
if (scope && (typeof scope !== "object" || Array.isArray(scope))) {
|
|
4672
4999
|
throw new InvalidArgumentError(
|
|
4673
5000
|
'The provided parameter "scope" of HasManyResolver.includeTo should be an Object, but %v was given.',
|
|
4674
5001
|
scope
|
|
4675
5002
|
);
|
|
5003
|
+
}
|
|
4676
5004
|
const sourcePkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
|
|
4677
5005
|
sourceName
|
|
4678
5006
|
);
|
|
4679
5007
|
const sourceIds = [];
|
|
4680
5008
|
entities.forEach((entity) => {
|
|
4681
|
-
if (!entity || typeof entity !== "object" || Array.isArray(entity))
|
|
5009
|
+
if (!entity || typeof entity !== "object" || Array.isArray(entity)) {
|
|
4682
5010
|
throw new InvalidArgumentError(
|
|
4683
5011
|
'The parameter "entities" of HasManyResolver.includeTo requires an Array of Object, but %v was given.',
|
|
4684
5012
|
entity
|
|
4685
5013
|
);
|
|
5014
|
+
}
|
|
4686
5015
|
const sourceId = entity[sourcePkPropName];
|
|
4687
|
-
if (sourceIds.includes(sourceId))
|
|
5016
|
+
if (sourceIds.includes(sourceId)) {
|
|
5017
|
+
return;
|
|
5018
|
+
}
|
|
4688
5019
|
sourceIds.push(sourceId);
|
|
4689
5020
|
});
|
|
4690
5021
|
const promises = [];
|
|
@@ -4727,53 +5058,63 @@ var init_has_many_resolver = __esm({
|
|
|
4727
5058
|
* @returns {Promise<void>}
|
|
4728
5059
|
*/
|
|
4729
5060
|
async includePolymorphicTo(entities, sourceName, targetName, relationName, foreignKey, discriminator, scope = void 0) {
|
|
4730
|
-
if (!entities || !Array.isArray(entities))
|
|
5061
|
+
if (!entities || !Array.isArray(entities)) {
|
|
4731
5062
|
throw new InvalidArgumentError(
|
|
4732
5063
|
'The parameter "entities" of HasManyResolver.includePolymorphicTo requires an Array of Object, but %v was given.',
|
|
4733
5064
|
entities
|
|
4734
5065
|
);
|
|
4735
|
-
|
|
5066
|
+
}
|
|
5067
|
+
if (!sourceName || typeof sourceName !== "string") {
|
|
4736
5068
|
throw new InvalidArgumentError(
|
|
4737
5069
|
'The parameter "sourceName" of HasManyResolver.includePolymorphicTo requires a non-empty String, but %v was given.',
|
|
4738
5070
|
sourceName
|
|
4739
5071
|
);
|
|
4740
|
-
|
|
5072
|
+
}
|
|
5073
|
+
if (!targetName || typeof targetName !== "string") {
|
|
4741
5074
|
throw new InvalidArgumentError(
|
|
4742
5075
|
'The parameter "targetName" of HasManyResolver.includePolymorphicTo requires a non-empty String, but %v was given.',
|
|
4743
5076
|
targetName
|
|
4744
5077
|
);
|
|
4745
|
-
|
|
5078
|
+
}
|
|
5079
|
+
if (!relationName || typeof relationName !== "string") {
|
|
4746
5080
|
throw new InvalidArgumentError(
|
|
4747
5081
|
'The parameter "relationName" of HasManyResolver.includePolymorphicTo requires a non-empty String, but %v was given.',
|
|
4748
5082
|
relationName
|
|
4749
5083
|
);
|
|
4750
|
-
|
|
5084
|
+
}
|
|
5085
|
+
if (!foreignKey || typeof foreignKey !== "string") {
|
|
4751
5086
|
throw new InvalidArgumentError(
|
|
4752
5087
|
'The parameter "foreignKey" of HasManyResolver.includePolymorphicTo requires a non-empty String, but %v was given.',
|
|
4753
5088
|
foreignKey
|
|
4754
5089
|
);
|
|
4755
|
-
|
|
5090
|
+
}
|
|
5091
|
+
if (!discriminator || typeof discriminator !== "string") {
|
|
4756
5092
|
throw new InvalidArgumentError(
|
|
4757
5093
|
'The parameter "discriminator" of HasManyResolver.includePolymorphicTo requires a non-empty String, but %v was given.',
|
|
4758
5094
|
discriminator
|
|
4759
5095
|
);
|
|
4760
|
-
|
|
5096
|
+
}
|
|
5097
|
+
if (scope && (typeof scope !== "object" || Array.isArray(scope))) {
|
|
4761
5098
|
throw new InvalidArgumentError(
|
|
4762
5099
|
'The provided parameter "scope" of HasManyResolver.includePolymorphicTo should be an Object, but %v was given.',
|
|
4763
5100
|
scope
|
|
4764
5101
|
);
|
|
5102
|
+
}
|
|
4765
5103
|
const sourcePkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
|
|
4766
5104
|
sourceName
|
|
4767
5105
|
);
|
|
4768
5106
|
const sourceIds = [];
|
|
4769
5107
|
entities.forEach((entity) => {
|
|
4770
|
-
if (!entity || typeof entity !== "object" || Array.isArray(entity))
|
|
5108
|
+
if (!entity || typeof entity !== "object" || Array.isArray(entity)) {
|
|
4771
5109
|
throw new InvalidArgumentError(
|
|
4772
5110
|
'The parameter "entities" of HasManyResolver.includePolymorphicTo requires an Array of Object, but %v was given.',
|
|
4773
5111
|
entity
|
|
4774
5112
|
);
|
|
5113
|
+
}
|
|
4775
5114
|
const sourceId = entity[sourcePkPropName];
|
|
4776
|
-
if (sourceIds.includes(sourceId))
|
|
5115
|
+
if (sourceIds.includes(sourceId)) {
|
|
5116
|
+
return;
|
|
5117
|
+
}
|
|
4777
5118
|
sourceIds.push(sourceId);
|
|
4778
5119
|
});
|
|
4779
5120
|
const promises = [];
|
|
@@ -4818,40 +5159,46 @@ var init_has_many_resolver = __esm({
|
|
|
4818
5159
|
* @returns {Promise<void>}
|
|
4819
5160
|
*/
|
|
4820
5161
|
async includePolymorphicByRelationName(entities, sourceName, targetName, relationName, targetRelationName, scope = void 0) {
|
|
4821
|
-
if (!entities || !Array.isArray(entities))
|
|
5162
|
+
if (!entities || !Array.isArray(entities)) {
|
|
4822
5163
|
throw new InvalidArgumentError(
|
|
4823
5164
|
'The parameter "entities" of HasManyResolver.includePolymorphicByRelationName requires an Array of Object, but %v was given.',
|
|
4824
5165
|
entities
|
|
4825
5166
|
);
|
|
4826
|
-
|
|
5167
|
+
}
|
|
5168
|
+
if (!sourceName || typeof sourceName !== "string") {
|
|
4827
5169
|
throw new InvalidArgumentError(
|
|
4828
5170
|
'The parameter "sourceName" of HasManyResolver.includePolymorphicByRelationName requires a non-empty String, but %v was given.',
|
|
4829
5171
|
sourceName
|
|
4830
5172
|
);
|
|
4831
|
-
|
|
5173
|
+
}
|
|
5174
|
+
if (!targetName || typeof targetName !== "string") {
|
|
4832
5175
|
throw new InvalidArgumentError(
|
|
4833
5176
|
'The parameter "targetName" of HasManyResolver.includePolymorphicByRelationName requires a non-empty String, but %v was given.',
|
|
4834
5177
|
targetName
|
|
4835
5178
|
);
|
|
4836
|
-
|
|
5179
|
+
}
|
|
5180
|
+
if (!relationName || typeof relationName !== "string") {
|
|
4837
5181
|
throw new InvalidArgumentError(
|
|
4838
5182
|
'The parameter "relationName" of HasManyResolver.includePolymorphicByRelationName requires a non-empty String, but %v was given.',
|
|
4839
5183
|
relationName
|
|
4840
5184
|
);
|
|
4841
|
-
|
|
5185
|
+
}
|
|
5186
|
+
if (!targetRelationName || typeof targetRelationName !== "string") {
|
|
4842
5187
|
throw new InvalidArgumentError(
|
|
4843
5188
|
'The parameter "targetRelationName" of HasManyResolver.includePolymorphicByRelationName requires a non-empty String, but %v was given.',
|
|
4844
5189
|
targetRelationName
|
|
4845
5190
|
);
|
|
4846
|
-
|
|
5191
|
+
}
|
|
5192
|
+
if (scope && (typeof scope !== "object" || Array.isArray(scope))) {
|
|
4847
5193
|
throw new InvalidArgumentError(
|
|
4848
5194
|
'The provided parameter "scope" of HasManyResolver.includePolymorphicByRelationName should be an Object, but %v was given.',
|
|
4849
5195
|
scope
|
|
4850
5196
|
);
|
|
5197
|
+
}
|
|
4851
5198
|
const targetRelationDef = this.getService(
|
|
4852
5199
|
ModelDefinitionUtils
|
|
4853
5200
|
).getRelationDefinitionByName(targetName, targetRelationName);
|
|
4854
|
-
if (targetRelationDef.type !== RelationType.BELONGS_TO)
|
|
5201
|
+
if (targetRelationDef.type !== RelationType.BELONGS_TO) {
|
|
4855
5202
|
throw new InvalidArgumentError(
|
|
4856
5203
|
'The relation %v of the model %v is a polymorphic "hasMany" relation, so it requires the target relation %v to be a polymorphic "belongsTo", but %v type was given.',
|
|
4857
5204
|
relationName,
|
|
@@ -4859,13 +5206,15 @@ var init_has_many_resolver = __esm({
|
|
|
4859
5206
|
targetRelationName,
|
|
4860
5207
|
targetRelationDef.type
|
|
4861
5208
|
);
|
|
4862
|
-
|
|
5209
|
+
}
|
|
5210
|
+
if (!targetRelationDef.polymorphic) {
|
|
4863
5211
|
throw new InvalidArgumentError(
|
|
4864
5212
|
'The relation %v of the model %v is a polymorphic "hasMany" relation, so it requires the target relation %v to be a polymorphic too.',
|
|
4865
5213
|
relationName,
|
|
4866
5214
|
sourceName,
|
|
4867
5215
|
targetRelationName
|
|
4868
5216
|
);
|
|
5217
|
+
}
|
|
4869
5218
|
const foreignKey = targetRelationDef.foreignKey || `${targetRelationName}Id`;
|
|
4870
5219
|
const discriminator = targetRelationDef.discriminator || `${targetRelationName}Type`;
|
|
4871
5220
|
return this.includePolymorphicTo(
|
|
@@ -4907,43 +5256,52 @@ var init_belongs_to_resolver = __esm({
|
|
|
4907
5256
|
* @returns {Promise<void>}
|
|
4908
5257
|
*/
|
|
4909
5258
|
async includeTo(entities, sourceName, targetName, relationName, foreignKey = void 0, scope = void 0) {
|
|
4910
|
-
if (!entities || !Array.isArray(entities))
|
|
5259
|
+
if (!entities || !Array.isArray(entities)) {
|
|
4911
5260
|
throw new InvalidArgumentError(
|
|
4912
5261
|
'The parameter "entities" of BelongsToResolver.includeTo requires an Array of Object, but %v was given.',
|
|
4913
5262
|
entities
|
|
4914
5263
|
);
|
|
4915
|
-
|
|
5264
|
+
}
|
|
5265
|
+
if (!sourceName || typeof sourceName !== "string") {
|
|
4916
5266
|
throw new InvalidArgumentError(
|
|
4917
5267
|
'The parameter "sourceName" of BelongsToResolver.includeTo requires a non-empty String, but %v was given.',
|
|
4918
5268
|
sourceName
|
|
4919
5269
|
);
|
|
4920
|
-
|
|
5270
|
+
}
|
|
5271
|
+
if (!targetName || typeof targetName !== "string") {
|
|
4921
5272
|
throw new InvalidArgumentError(
|
|
4922
5273
|
'The parameter "targetName" of BelongsToResolver.includeTo requires a non-empty String, but %v was given.',
|
|
4923
5274
|
targetName
|
|
4924
5275
|
);
|
|
4925
|
-
|
|
5276
|
+
}
|
|
5277
|
+
if (!relationName || typeof relationName !== "string") {
|
|
4926
5278
|
throw new InvalidArgumentError(
|
|
4927
5279
|
'The parameter "relationName" of BelongsToResolver.includeTo requires a non-empty String, but %v was given.',
|
|
4928
5280
|
relationName
|
|
4929
5281
|
);
|
|
4930
|
-
|
|
5282
|
+
}
|
|
5283
|
+
if (foreignKey && typeof foreignKey !== "string") {
|
|
4931
5284
|
throw new InvalidArgumentError(
|
|
4932
5285
|
'The provided parameter "foreignKey" of BelongsToResolver.includeTo should be a String, but %v was given.',
|
|
4933
5286
|
foreignKey
|
|
4934
5287
|
);
|
|
4935
|
-
|
|
5288
|
+
}
|
|
5289
|
+
if (scope && (typeof scope !== "object" || Array.isArray(scope))) {
|
|
4936
5290
|
throw new InvalidArgumentError(
|
|
4937
5291
|
'The provided parameter "scope" of BelongsToResolver.includeTo should be an Object, but %v was given.',
|
|
4938
5292
|
scope
|
|
4939
5293
|
);
|
|
4940
|
-
|
|
5294
|
+
}
|
|
5295
|
+
if (foreignKey == null) {
|
|
5296
|
+
foreignKey = `${relationName}Id`;
|
|
5297
|
+
}
|
|
4941
5298
|
const targetIds = entities.reduce((acc, entity) => {
|
|
4942
|
-
if (!entity || typeof entity !== "object" || Array.isArray(entity))
|
|
5299
|
+
if (!entity || typeof entity !== "object" || Array.isArray(entity)) {
|
|
4943
5300
|
throw new InvalidArgumentError(
|
|
4944
5301
|
'The parameter "entities" of BelongsToResolver.includeTo requires an Array of Object, but %v was given.',
|
|
4945
5302
|
entity
|
|
4946
5303
|
);
|
|
5304
|
+
}
|
|
4947
5305
|
const targetId = entity[foreignKey];
|
|
4948
5306
|
return targetId != null ? [...acc, targetId] : acc;
|
|
4949
5307
|
}, []);
|
|
@@ -4964,7 +5322,9 @@ var init_belongs_to_resolver = __esm({
|
|
|
4964
5322
|
const target = targets.find(
|
|
4965
5323
|
(e) => e[targetPkPropName] === entity[foreignKey]
|
|
4966
5324
|
);
|
|
4967
|
-
if (target)
|
|
5325
|
+
if (target) {
|
|
5326
|
+
entity[relationName] = target;
|
|
5327
|
+
}
|
|
4968
5328
|
});
|
|
4969
5329
|
}
|
|
4970
5330
|
/**
|
|
@@ -4979,36 +5339,42 @@ var init_belongs_to_resolver = __esm({
|
|
|
4979
5339
|
* @returns {Promise<void>}
|
|
4980
5340
|
*/
|
|
4981
5341
|
async includePolymorphicTo(entities, sourceName, relationName, foreignKey = void 0, discriminator = void 0, scope = void 0) {
|
|
4982
|
-
if (!entities || !Array.isArray(entities))
|
|
5342
|
+
if (!entities || !Array.isArray(entities)) {
|
|
4983
5343
|
throw new InvalidArgumentError(
|
|
4984
5344
|
'The parameter "entities" of BelongsToResolver.includePolymorphicTo requires an Array of Object, but %v was given.',
|
|
4985
5345
|
entities
|
|
4986
5346
|
);
|
|
4987
|
-
|
|
5347
|
+
}
|
|
5348
|
+
if (!sourceName || typeof sourceName !== "string") {
|
|
4988
5349
|
throw new InvalidArgumentError(
|
|
4989
5350
|
'The parameter "sourceName" of BelongsToResolver.includePolymorphicTo requires a non-empty String, but %v was given.',
|
|
4990
5351
|
sourceName
|
|
4991
5352
|
);
|
|
4992
|
-
|
|
5353
|
+
}
|
|
5354
|
+
if (!relationName || typeof relationName !== "string") {
|
|
4993
5355
|
throw new InvalidArgumentError(
|
|
4994
5356
|
'The parameter "relationName" of BelongsToResolver.includePolymorphicTo requires a non-empty String, but %v was given.',
|
|
4995
5357
|
relationName
|
|
4996
5358
|
);
|
|
4997
|
-
|
|
5359
|
+
}
|
|
5360
|
+
if (foreignKey && typeof foreignKey !== "string") {
|
|
4998
5361
|
throw new InvalidArgumentError(
|
|
4999
5362
|
'The provided parameter "foreignKey" of BelongsToResolver.includePolymorphicTo should be a String, but %v was given.',
|
|
5000
5363
|
foreignKey
|
|
5001
5364
|
);
|
|
5002
|
-
|
|
5365
|
+
}
|
|
5366
|
+
if (discriminator && typeof discriminator !== "string") {
|
|
5003
5367
|
throw new InvalidArgumentError(
|
|
5004
5368
|
'The provided parameter "discriminator" of BelongsToResolver.includePolymorphicTo should be a String, but %v was given.',
|
|
5005
5369
|
discriminator
|
|
5006
5370
|
);
|
|
5007
|
-
|
|
5371
|
+
}
|
|
5372
|
+
if (scope && (typeof scope !== "object" || Array.isArray(scope))) {
|
|
5008
5373
|
throw new InvalidArgumentError(
|
|
5009
5374
|
'The provided parameter "scope" of BelongsToResolver.includePolymorphicTo should be an Object, but %v was given.',
|
|
5010
5375
|
scope
|
|
5011
5376
|
);
|
|
5377
|
+
}
|
|
5012
5378
|
if (foreignKey == null) {
|
|
5013
5379
|
const singularRelationName = singularize(relationName);
|
|
5014
5380
|
foreignKey = `${singularRelationName}Id`;
|
|
@@ -5019,18 +5385,23 @@ var init_belongs_to_resolver = __esm({
|
|
|
5019
5385
|
}
|
|
5020
5386
|
const targetIdsByTargetName = {};
|
|
5021
5387
|
entities.forEach((entity) => {
|
|
5022
|
-
if (!entity || typeof entity !== "object" || Array.isArray(entity))
|
|
5388
|
+
if (!entity || typeof entity !== "object" || Array.isArray(entity)) {
|
|
5023
5389
|
throw new InvalidArgumentError(
|
|
5024
5390
|
'The parameter "entities" of BelongsToResolver.includePolymorphicTo requires an Array of Object, but %v was given.',
|
|
5025
5391
|
entity
|
|
5026
5392
|
);
|
|
5393
|
+
}
|
|
5027
5394
|
const targetId = entity[foreignKey];
|
|
5028
5395
|
const targetName = entity[discriminator];
|
|
5029
|
-
if (targetId == null || targetName == null)
|
|
5030
|
-
|
|
5396
|
+
if (targetId == null || targetName == null) {
|
|
5397
|
+
return;
|
|
5398
|
+
}
|
|
5399
|
+
if (targetIdsByTargetName[targetName] == null) {
|
|
5031
5400
|
targetIdsByTargetName[targetName] = [];
|
|
5032
|
-
|
|
5401
|
+
}
|
|
5402
|
+
if (!targetIdsByTargetName[targetName].includes(targetId)) {
|
|
5033
5403
|
targetIdsByTargetName[targetName].push(targetId);
|
|
5404
|
+
}
|
|
5034
5405
|
});
|
|
5035
5406
|
const promises = [];
|
|
5036
5407
|
const targetNames = Object.keys(targetIdsByTargetName);
|
|
@@ -5082,7 +5453,9 @@ var init_belongs_to_resolver = __esm({
|
|
|
5082
5453
|
targetName
|
|
5083
5454
|
);
|
|
5084
5455
|
const target = targetEntities.find((e) => e[targetPkPropName] === targetId);
|
|
5085
|
-
if (target)
|
|
5456
|
+
if (target) {
|
|
5457
|
+
entity[relationName] = target;
|
|
5458
|
+
}
|
|
5086
5459
|
});
|
|
5087
5460
|
}
|
|
5088
5461
|
};
|
|
@@ -5114,52 +5487,62 @@ var init_references_many_resolver = __esm({
|
|
|
5114
5487
|
* @returns {Promise<void>}
|
|
5115
5488
|
*/
|
|
5116
5489
|
async includeTo(entities, sourceName, targetName, relationName, foreignKey = void 0, scope = void 0) {
|
|
5117
|
-
if (!entities || !Array.isArray(entities))
|
|
5490
|
+
if (!entities || !Array.isArray(entities)) {
|
|
5118
5491
|
throw new InvalidArgumentError(
|
|
5119
5492
|
'The parameter "entities" of ReferencesManyResolver.includeTo requires an Array of Object, but %v was given.',
|
|
5120
5493
|
entities
|
|
5121
5494
|
);
|
|
5122
|
-
|
|
5495
|
+
}
|
|
5496
|
+
if (!sourceName || typeof sourceName !== "string") {
|
|
5123
5497
|
throw new InvalidArgumentError(
|
|
5124
5498
|
'The parameter "sourceName" of ReferencesManyResolver.includeTo requires a non-empty String, but %v was given.',
|
|
5125
5499
|
sourceName
|
|
5126
5500
|
);
|
|
5127
|
-
|
|
5501
|
+
}
|
|
5502
|
+
if (!targetName || typeof targetName !== "string") {
|
|
5128
5503
|
throw new InvalidArgumentError(
|
|
5129
5504
|
'The parameter "targetName" of ReferencesManyResolver.includeTo requires a non-empty String, but %v was given.',
|
|
5130
5505
|
targetName
|
|
5131
5506
|
);
|
|
5132
|
-
|
|
5507
|
+
}
|
|
5508
|
+
if (!relationName || typeof relationName !== "string") {
|
|
5133
5509
|
throw new InvalidArgumentError(
|
|
5134
5510
|
'The parameter "relationName" of ReferencesManyResolver.includeTo requires a non-empty String, but %v was given.',
|
|
5135
5511
|
relationName
|
|
5136
5512
|
);
|
|
5137
|
-
|
|
5513
|
+
}
|
|
5514
|
+
if (foreignKey && typeof foreignKey !== "string") {
|
|
5138
5515
|
throw new InvalidArgumentError(
|
|
5139
5516
|
'The provided parameter "foreignKey" of ReferencesManyResolver.includeTo should be a String, but %v was given.',
|
|
5140
5517
|
foreignKey
|
|
5141
5518
|
);
|
|
5142
|
-
|
|
5519
|
+
}
|
|
5520
|
+
if (scope && (typeof scope !== "object" || Array.isArray(scope))) {
|
|
5143
5521
|
throw new InvalidArgumentError(
|
|
5144
5522
|
'The provided parameter "scope" of ReferencesManyResolver.includeTo should be an Object, but %v was given.',
|
|
5145
5523
|
scope
|
|
5146
5524
|
);
|
|
5525
|
+
}
|
|
5147
5526
|
if (foreignKey == null) {
|
|
5148
5527
|
const singularRelationName = singularize(relationName);
|
|
5149
5528
|
foreignKey = `${singularRelationName}Ids`;
|
|
5150
5529
|
}
|
|
5151
5530
|
const targetIds = entities.reduce((acc, entity) => {
|
|
5152
|
-
if (!entity || typeof entity !== "object" || Array.isArray(entity))
|
|
5531
|
+
if (!entity || typeof entity !== "object" || Array.isArray(entity)) {
|
|
5153
5532
|
throw new InvalidArgumentError(
|
|
5154
5533
|
'The parameter "entities" of ReferencesManyResolver.includeTo requires an Array of Object, but %v was given.',
|
|
5155
5534
|
entity
|
|
5156
5535
|
);
|
|
5536
|
+
}
|
|
5157
5537
|
const ids = entity[foreignKey];
|
|
5158
|
-
if (Array.isArray(ids))
|
|
5538
|
+
if (Array.isArray(ids)) {
|
|
5159
5539
|
ids.forEach((id) => {
|
|
5160
|
-
if (id == null || acc.includes(id))
|
|
5540
|
+
if (id == null || acc.includes(id)) {
|
|
5541
|
+
return;
|
|
5542
|
+
}
|
|
5161
5543
|
acc.push(id);
|
|
5162
5544
|
});
|
|
5545
|
+
}
|
|
5163
5546
|
return acc;
|
|
5164
5547
|
}, []);
|
|
5165
5548
|
const targetRepository = this.getService(RepositoryRegistry).getRepository(targetName);
|
|
@@ -5178,11 +5561,14 @@ var init_references_many_resolver = __esm({
|
|
|
5178
5561
|
entities.forEach((entity) => {
|
|
5179
5562
|
const ids = entity[foreignKey];
|
|
5180
5563
|
entity[relationName] = [];
|
|
5181
|
-
if (Array.isArray(ids))
|
|
5564
|
+
if (Array.isArray(ids)) {
|
|
5182
5565
|
targets.forEach((target) => {
|
|
5183
5566
|
const targetId = target[targetPkPropName];
|
|
5184
|
-
if (ids.includes(targetId))
|
|
5567
|
+
if (ids.includes(targetId)) {
|
|
5568
|
+
entity[relationName].push(target);
|
|
5569
|
+
}
|
|
5185
5570
|
});
|
|
5571
|
+
}
|
|
5186
5572
|
});
|
|
5187
5573
|
}
|
|
5188
5574
|
};
|
|
@@ -5371,30 +5757,37 @@ var init_include_clause_tool = __esm({
|
|
|
5371
5757
|
relNames.push(el);
|
|
5372
5758
|
} else if (typeof el === "object") {
|
|
5373
5759
|
Object.keys(el).forEach((key) => {
|
|
5374
|
-
if (Object.prototype.hasOwnProperty.call(el, key))
|
|
5760
|
+
if (Object.prototype.hasOwnProperty.call(el, key)) {
|
|
5375
5761
|
relNames.push(key);
|
|
5762
|
+
}
|
|
5376
5763
|
});
|
|
5377
5764
|
}
|
|
5378
5765
|
});
|
|
5379
5766
|
const duplicateNames = relNames.filter(
|
|
5380
5767
|
(name, i) => relNames.indexOf(name) !== i
|
|
5381
5768
|
);
|
|
5382
|
-
if (duplicateNames.length)
|
|
5769
|
+
if (duplicateNames.length) {
|
|
5383
5770
|
throw new InvalidArgumentError(
|
|
5384
5771
|
'The provided option "include" has duplicates of %v.',
|
|
5385
5772
|
duplicateNames[0]
|
|
5386
5773
|
);
|
|
5774
|
+
}
|
|
5387
5775
|
} else if (typeof clause === "object") {
|
|
5388
5776
|
if ("relation" in clause) {
|
|
5389
|
-
if (!clause.relation || typeof clause.relation !== "string")
|
|
5777
|
+
if (!clause.relation || typeof clause.relation !== "string") {
|
|
5390
5778
|
throw new InvalidArgumentError(
|
|
5391
5779
|
'The provided option "relation" should be a non-empty String, but %v was given.',
|
|
5392
5780
|
clause.relation
|
|
5393
5781
|
);
|
|
5394
|
-
|
|
5782
|
+
}
|
|
5783
|
+
if ("scope" in clause && clause) {
|
|
5784
|
+
this.validateScopeClause(clause.scope);
|
|
5785
|
+
}
|
|
5395
5786
|
} else {
|
|
5396
5787
|
Object.keys(clause).forEach((key) => {
|
|
5397
|
-
if (!Object.prototype.hasOwnProperty.call(clause, key))
|
|
5788
|
+
if (!Object.prototype.hasOwnProperty.call(clause, key)) {
|
|
5789
|
+
return;
|
|
5790
|
+
}
|
|
5398
5791
|
this.validateIncludeClause(key);
|
|
5399
5792
|
this.validateIncludeClause(clause[key]);
|
|
5400
5793
|
});
|
|
@@ -5412,12 +5805,15 @@ var init_include_clause_tool = __esm({
|
|
|
5412
5805
|
* @param {object|undefined} clause
|
|
5413
5806
|
*/
|
|
5414
5807
|
static validateScopeClause(clause) {
|
|
5415
|
-
if (clause == null)
|
|
5416
|
-
|
|
5808
|
+
if (clause == null) {
|
|
5809
|
+
return;
|
|
5810
|
+
}
|
|
5811
|
+
if (typeof clause !== "object" || Array.isArray(clause)) {
|
|
5417
5812
|
throw new InvalidArgumentError(
|
|
5418
5813
|
'The provided option "scope" should be an Object, but %v was given.',
|
|
5419
5814
|
clause
|
|
5420
5815
|
);
|
|
5816
|
+
}
|
|
5421
5817
|
if (clause.where != null) {
|
|
5422
5818
|
WhereClauseTool.validateWhereClause(clause.where);
|
|
5423
5819
|
}
|
|
@@ -5458,29 +5854,37 @@ var init_include_clause_tool = __esm({
|
|
|
5458
5854
|
const duplicateNames = relNames.filter(
|
|
5459
5855
|
(name, i) => relNames.indexOf(name) !== i
|
|
5460
5856
|
);
|
|
5461
|
-
if (duplicateNames.length)
|
|
5857
|
+
if (duplicateNames.length) {
|
|
5462
5858
|
throw new InvalidArgumentError(
|
|
5463
5859
|
'The provided option "include" has duplicates of %v.',
|
|
5464
5860
|
duplicateNames[0]
|
|
5465
5861
|
);
|
|
5862
|
+
}
|
|
5466
5863
|
} else if (typeof clause === "object") {
|
|
5467
5864
|
if ("relation" in clause) {
|
|
5468
|
-
if (!clause.relation || typeof clause.relation !== "string")
|
|
5865
|
+
if (!clause.relation || typeof clause.relation !== "string") {
|
|
5469
5866
|
throw new InvalidArgumentError(
|
|
5470
5867
|
'The provided option "relation" should be a non-empty String, but %v was given.',
|
|
5471
5868
|
clause.relation
|
|
5472
5869
|
);
|
|
5870
|
+
}
|
|
5473
5871
|
const normalized = { relation: clause.relation };
|
|
5474
5872
|
const scope = this.normalizeScopeClause(clause.scope);
|
|
5475
|
-
if (scope)
|
|
5873
|
+
if (scope) {
|
|
5874
|
+
normalized.scope = scope;
|
|
5875
|
+
}
|
|
5476
5876
|
result.push(normalized);
|
|
5477
5877
|
} else {
|
|
5478
5878
|
Object.keys(clause).forEach((key) => {
|
|
5479
|
-
if (!Object.prototype.hasOwnProperty.call(clause, key))
|
|
5879
|
+
if (!Object.prototype.hasOwnProperty.call(clause, key)) {
|
|
5880
|
+
return;
|
|
5881
|
+
}
|
|
5480
5882
|
this.validateIncludeClause(key);
|
|
5481
5883
|
const normalized = { relation: key };
|
|
5482
5884
|
const include = this.normalizeIncludeClause(clause[key]);
|
|
5483
|
-
if (include.length)
|
|
5885
|
+
if (include.length) {
|
|
5886
|
+
normalized.scope = { include };
|
|
5887
|
+
}
|
|
5484
5888
|
result.push(normalized);
|
|
5485
5889
|
});
|
|
5486
5890
|
}
|
|
@@ -5499,12 +5903,15 @@ var init_include_clause_tool = __esm({
|
|
|
5499
5903
|
* @returns {object|undefined}
|
|
5500
5904
|
*/
|
|
5501
5905
|
static normalizeScopeClause(clause) {
|
|
5502
|
-
if (clause == null)
|
|
5503
|
-
|
|
5906
|
+
if (clause == null) {
|
|
5907
|
+
return;
|
|
5908
|
+
}
|
|
5909
|
+
if (typeof clause !== "object" || Array.isArray(clause)) {
|
|
5504
5910
|
throw new InvalidArgumentError(
|
|
5505
5911
|
'The provided option "scope" should be an Object, but %v was given.',
|
|
5506
5912
|
clause
|
|
5507
5913
|
);
|
|
5914
|
+
}
|
|
5508
5915
|
const result = {};
|
|
5509
5916
|
if (clause.where != null) {
|
|
5510
5917
|
WhereClauseTool.validateWhereClause(clause.where);
|
|
@@ -5529,7 +5936,9 @@ var init_include_clause_tool = __esm({
|
|
|
5529
5936
|
if (clause.include != null) {
|
|
5530
5937
|
result.include = this.normalizeIncludeClause(clause.include);
|
|
5531
5938
|
}
|
|
5532
|
-
if (Object.keys(result).length)
|
|
5939
|
+
if (Object.keys(result).length) {
|
|
5940
|
+
return result;
|
|
5941
|
+
}
|
|
5533
5942
|
return void 0;
|
|
5534
5943
|
}
|
|
5535
5944
|
};
|