@orion-js/schema 4.0.0-next.2 → 4.0.0-next.3
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/LICENSE +21 -0
- package/dist/index.cjs +60 -127
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +60 -129
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
1
|
// src/ValidationError.ts
|
|
5
2
|
import isPlainObject from "lodash/isPlainObject";
|
|
6
|
-
var getPrintableError =
|
|
3
|
+
var getPrintableError = (validationErrors) => {
|
|
7
4
|
const printableErrors = Object.keys(validationErrors).map((key) => {
|
|
8
5
|
return `${key}: ${validationErrors[key]}`;
|
|
9
6
|
}).join(", ");
|
|
10
7
|
const message = `Validation Error: {${printableErrors}}`;
|
|
11
8
|
return message;
|
|
12
|
-
}
|
|
13
|
-
var
|
|
9
|
+
};
|
|
10
|
+
var ValidationError = class _ValidationError extends Error {
|
|
14
11
|
code;
|
|
15
12
|
isValidationError;
|
|
16
13
|
isOrionError;
|
|
@@ -27,24 +24,22 @@ var _ValidationError = class _ValidationError extends Error {
|
|
|
27
24
|
this.validationErrors = validationErrors;
|
|
28
25
|
this.getInfo;
|
|
29
26
|
}
|
|
30
|
-
getInfo =
|
|
27
|
+
getInfo = () => {
|
|
31
28
|
return {
|
|
32
29
|
error: "validationError",
|
|
33
30
|
message: "Validation Error",
|
|
34
31
|
validationErrors: this.validationErrors
|
|
35
32
|
};
|
|
36
|
-
}
|
|
37
|
-
prependKey =
|
|
33
|
+
};
|
|
34
|
+
prependKey = (prepend) => {
|
|
38
35
|
const newErrors = {};
|
|
39
36
|
const keys = Object.keys(this.validationErrors);
|
|
40
37
|
for (const key of keys) {
|
|
41
38
|
newErrors[`${prepend}.${key}`] = this.validationErrors[key];
|
|
42
39
|
}
|
|
43
40
|
return new _ValidationError(newErrors);
|
|
44
|
-
}
|
|
41
|
+
};
|
|
45
42
|
};
|
|
46
|
-
__name(_ValidationError, "ValidationError");
|
|
47
|
-
var ValidationError = _ValidationError;
|
|
48
43
|
|
|
49
44
|
// src/getValidationErrors/convertTypedModel.ts
|
|
50
45
|
function isClass(obj) {
|
|
@@ -55,8 +50,7 @@ function isClass(obj) {
|
|
|
55
50
|
const isPrototypeCtorClass = obj.prototype.constructor && obj.prototype.constructor.toString && obj.prototype.constructor.toString().substring(0, 5) === "class";
|
|
56
51
|
return isCtorClass || isPrototypeCtorClass;
|
|
57
52
|
}
|
|
58
|
-
|
|
59
|
-
var convertOnParam = /* @__PURE__ */ __name((info, paramName) => {
|
|
53
|
+
var convertOnParam = (info, paramName) => {
|
|
60
54
|
if (!info[paramName]) return;
|
|
61
55
|
const type = info[paramName].type;
|
|
62
56
|
if (!type) return;
|
|
@@ -64,20 +58,20 @@ var convertOnParam = /* @__PURE__ */ __name((info, paramName) => {
|
|
|
64
58
|
if (!isClass(type)) return;
|
|
65
59
|
if (!type.getModel || !type.__schemaId) return;
|
|
66
60
|
info[paramName].type = type.getModel().getCleanSchema();
|
|
67
|
-
}
|
|
68
|
-
var convertTypedModel =
|
|
61
|
+
};
|
|
62
|
+
var convertTypedModel = (info) => {
|
|
69
63
|
convertOnParam(info, "schema");
|
|
70
64
|
convertOnParam(info, "currentSchema");
|
|
71
|
-
}
|
|
65
|
+
};
|
|
72
66
|
|
|
73
67
|
// src/getSchemaFromTypedModel.ts
|
|
74
|
-
var getSchemaFromTypedModel =
|
|
68
|
+
var getSchemaFromTypedModel = (schema) => {
|
|
75
69
|
const item = schema;
|
|
76
70
|
if (typeof item !== "function") return item;
|
|
77
71
|
if (!isClass(item)) return item;
|
|
78
72
|
if (!item.getModel || !item.__schemaId) return item;
|
|
79
73
|
return item.getModel().getCleanSchema();
|
|
80
|
-
}
|
|
74
|
+
};
|
|
81
75
|
|
|
82
76
|
// src/getValidationErrors/getError/index.ts
|
|
83
77
|
import isNil2 from "lodash/isNil";
|
|
@@ -90,13 +84,13 @@ import isString5 from "lodash/isString";
|
|
|
90
84
|
// src/fieldType.ts
|
|
91
85
|
function fieldType(opts) {
|
|
92
86
|
const { name, validate: validate2, clean: clean3, ...otherFields } = opts;
|
|
93
|
-
const overwrittenValidate =
|
|
87
|
+
const overwrittenValidate = (value, info = {}) => {
|
|
94
88
|
if (!info.currentSchema) {
|
|
95
89
|
info.currentSchema = {};
|
|
96
90
|
}
|
|
97
91
|
return validate2(value, info);
|
|
98
|
-
}
|
|
99
|
-
const overwrittenClean =
|
|
92
|
+
};
|
|
93
|
+
const overwrittenClean = (value, info = {}) => {
|
|
100
94
|
if (!info.options) {
|
|
101
95
|
info.options = {};
|
|
102
96
|
}
|
|
@@ -104,7 +98,7 @@ function fieldType(opts) {
|
|
|
104
98
|
return clean3(value, info);
|
|
105
99
|
}
|
|
106
100
|
return value;
|
|
107
|
-
}
|
|
101
|
+
};
|
|
108
102
|
return {
|
|
109
103
|
...otherFields,
|
|
110
104
|
name,
|
|
@@ -113,7 +107,6 @@ function fieldType(opts) {
|
|
|
113
107
|
_isFieldType: true
|
|
114
108
|
};
|
|
115
109
|
}
|
|
116
|
-
__name(fieldType, "fieldType");
|
|
117
110
|
|
|
118
111
|
// src/fieldTypes/array.ts
|
|
119
112
|
import isArray from "lodash/isArray";
|
|
@@ -149,9 +142,7 @@ var array_default = fieldType({
|
|
|
149
142
|
clean(value, { options }) {
|
|
150
143
|
if (options.autoConvert) {
|
|
151
144
|
if (!isArray(value)) {
|
|
152
|
-
value = [
|
|
153
|
-
value
|
|
154
|
-
];
|
|
145
|
+
value = [value];
|
|
155
146
|
}
|
|
156
147
|
}
|
|
157
148
|
return value;
|
|
@@ -413,19 +404,11 @@ function getFieldValidator_default(type) {
|
|
|
413
404
|
}
|
|
414
405
|
return type;
|
|
415
406
|
}
|
|
416
|
-
__name(getFieldValidator_default, "default");
|
|
417
407
|
|
|
418
408
|
// src/getValidationErrors/getError/index.ts
|
|
419
409
|
async function getValidationErrors(params) {
|
|
420
410
|
const { schema, doc, currentDoc, value, currentSchema, keys, options = {}, args = [] } = params;
|
|
421
|
-
const info = {
|
|
422
|
-
schema,
|
|
423
|
-
doc,
|
|
424
|
-
currentDoc,
|
|
425
|
-
keys,
|
|
426
|
-
currentSchema,
|
|
427
|
-
options
|
|
428
|
-
};
|
|
411
|
+
const info = { schema, doc, currentDoc, keys, currentSchema, options };
|
|
429
412
|
if (isNil2(value)) {
|
|
430
413
|
if (!currentSchema.optional && !options.omitRequired) {
|
|
431
414
|
return Errors_default.REQUIRED;
|
|
@@ -454,7 +437,6 @@ async function getValidationErrors(params) {
|
|
|
454
437
|
}
|
|
455
438
|
return null;
|
|
456
439
|
}
|
|
457
|
-
__name(getValidationErrors, "getValidationErrors");
|
|
458
440
|
|
|
459
441
|
// src/getValidationErrors/doValidation.ts
|
|
460
442
|
import isPlainObject5 from "lodash/isPlainObject";
|
|
@@ -465,17 +447,7 @@ import difference2 from "lodash/difference";
|
|
|
465
447
|
async function doValidation(params) {
|
|
466
448
|
convertTypedModel(params);
|
|
467
449
|
const { schema, doc, currentDoc, value, currentSchema, keys = [], addError, options, args } = params;
|
|
468
|
-
const info = {
|
|
469
|
-
schema,
|
|
470
|
-
doc,
|
|
471
|
-
currentDoc,
|
|
472
|
-
value,
|
|
473
|
-
currentSchema,
|
|
474
|
-
keys,
|
|
475
|
-
options,
|
|
476
|
-
args,
|
|
477
|
-
addError
|
|
478
|
-
};
|
|
450
|
+
const info = { schema, doc, currentDoc, value, currentSchema, keys, options, args, addError };
|
|
479
451
|
const error = await getValidationErrors(info);
|
|
480
452
|
if (error) {
|
|
481
453
|
addError(keys, error);
|
|
@@ -525,15 +497,12 @@ async function doValidation(params) {
|
|
|
525
497
|
...info,
|
|
526
498
|
currentDoc: value,
|
|
527
499
|
value: itemValue,
|
|
528
|
-
currentSchema: {
|
|
529
|
-
type: itemSchema
|
|
530
|
-
},
|
|
500
|
+
currentSchema: { type: itemSchema },
|
|
531
501
|
keys: keyItemKeys
|
|
532
502
|
});
|
|
533
503
|
}
|
|
534
504
|
}
|
|
535
505
|
}
|
|
536
|
-
__name(doValidation, "doValidation");
|
|
537
506
|
|
|
538
507
|
// src/getValidationErrors/getValidationErrorsObject.ts
|
|
539
508
|
import Dot from "dot-object";
|
|
@@ -546,7 +515,6 @@ function getValidationErrorsObject(validationErrors) {
|
|
|
546
515
|
}
|
|
547
516
|
return dot.dot(errors);
|
|
548
517
|
}
|
|
549
|
-
__name(getValidationErrorsObject, "getValidationErrorsObject");
|
|
550
518
|
|
|
551
519
|
// src/getValidationErrors/index.ts
|
|
552
520
|
var defaultOptions = {
|
|
@@ -554,32 +522,26 @@ var defaultOptions = {
|
|
|
554
522
|
};
|
|
555
523
|
async function getValidationErrors2(schema, doc, passedOptions = {}, ...args) {
|
|
556
524
|
schema = getSchemaFromTypedModel(schema);
|
|
557
|
-
const options = {
|
|
558
|
-
...defaultOptions,
|
|
559
|
-
...passedOptions
|
|
560
|
-
};
|
|
525
|
+
const options = { ...defaultOptions, ...passedOptions };
|
|
561
526
|
const errors = [];
|
|
562
|
-
const addError =
|
|
527
|
+
const addError = function(keys, code) {
|
|
563
528
|
errors.push({
|
|
564
529
|
key: keys.join("."),
|
|
565
530
|
code
|
|
566
531
|
});
|
|
567
|
-
}
|
|
532
|
+
};
|
|
568
533
|
await doValidation({
|
|
569
534
|
schema,
|
|
570
535
|
doc,
|
|
571
536
|
currentDoc: doc,
|
|
572
537
|
value: doc,
|
|
573
|
-
currentSchema: {
|
|
574
|
-
type: schema
|
|
575
|
-
},
|
|
538
|
+
currentSchema: { type: schema },
|
|
576
539
|
addError,
|
|
577
540
|
options,
|
|
578
541
|
args
|
|
579
542
|
});
|
|
580
543
|
return getValidationErrorsObject(errors);
|
|
581
544
|
}
|
|
582
|
-
__name(getValidationErrors2, "getValidationErrors");
|
|
583
545
|
|
|
584
546
|
// src/validate.ts
|
|
585
547
|
async function validate(schema, doc, passedOptions = {}, ...args) {
|
|
@@ -588,14 +550,12 @@ async function validate(schema, doc, passedOptions = {}, ...args) {
|
|
|
588
550
|
throw new ValidationError(validationErrors);
|
|
589
551
|
}
|
|
590
552
|
}
|
|
591
|
-
__name(validate, "validate");
|
|
592
553
|
|
|
593
554
|
// src/isValid.ts
|
|
594
555
|
async function isValid(schema, doc, passedOptions = {}, ...args) {
|
|
595
556
|
const validationErrors = await getValidationErrors2(schema, doc, passedOptions, ...args);
|
|
596
557
|
return !validationErrors;
|
|
597
558
|
}
|
|
598
|
-
__name(isValid, "isValid");
|
|
599
559
|
|
|
600
560
|
// src/getValidationErrors/getError/getFieldType.ts
|
|
601
561
|
function getFieldType(type) {
|
|
@@ -603,7 +563,6 @@ function getFieldType(type) {
|
|
|
603
563
|
const validator = validatorKey === "custom" ? type : fieldTypes_default[validatorKey];
|
|
604
564
|
return validator;
|
|
605
565
|
}
|
|
606
|
-
__name(getFieldType, "getFieldType");
|
|
607
566
|
|
|
608
567
|
// src/clean/recursiveClean.ts
|
|
609
568
|
import isUndefined from "lodash/isUndefined";
|
|
@@ -621,7 +580,6 @@ function getObjectNode(schema, value) {
|
|
|
621
580
|
}
|
|
622
581
|
return null;
|
|
623
582
|
}
|
|
624
|
-
__name(getObjectNode, "getObjectNode");
|
|
625
583
|
|
|
626
584
|
// src/clean/cleanType.ts
|
|
627
585
|
async function cleanType(type, fieldSchema, value, info, ...args) {
|
|
@@ -663,11 +621,14 @@ async function cleanType(type, fieldSchema, value, info, ...args) {
|
|
|
663
621
|
}
|
|
664
622
|
return value;
|
|
665
623
|
}
|
|
666
|
-
__name(cleanType, "cleanType");
|
|
667
624
|
|
|
668
625
|
// src/clean/recursiveClean.ts
|
|
669
626
|
import isNil5 from "lodash/isNil";
|
|
670
|
-
var cleanObjectFields =
|
|
627
|
+
var cleanObjectFields = async function({
|
|
628
|
+
schema,
|
|
629
|
+
value,
|
|
630
|
+
...other
|
|
631
|
+
}) {
|
|
671
632
|
const keys = Object.keys(schema.type).filter((key) => !key.startsWith("__"));
|
|
672
633
|
const newDoc = {};
|
|
673
634
|
for (const key of keys) {
|
|
@@ -687,8 +648,12 @@ var cleanObjectFields = /* @__PURE__ */ __name(async function({ schema, value, .
|
|
|
687
648
|
}
|
|
688
649
|
}
|
|
689
650
|
return newDoc;
|
|
690
|
-
}
|
|
691
|
-
var cleanArrayItems =
|
|
651
|
+
};
|
|
652
|
+
var cleanArrayItems = async function({
|
|
653
|
+
schema,
|
|
654
|
+
value,
|
|
655
|
+
...other
|
|
656
|
+
}) {
|
|
692
657
|
const schemaType = schema.type[0];
|
|
693
658
|
const promises = value.map(async (item, index) => {
|
|
694
659
|
const newValue = await clean({
|
|
@@ -703,7 +668,7 @@ var cleanArrayItems = /* @__PURE__ */ __name(async function({ schema, value, ...
|
|
|
703
668
|
});
|
|
704
669
|
const result = await Promise.all(promises);
|
|
705
670
|
return result.filter((value2) => !isUndefined(value2));
|
|
706
|
-
}
|
|
671
|
+
};
|
|
707
672
|
function getArrayNode(schema, value) {
|
|
708
673
|
if (isArray5(schema.type) && !isNil5(value)) {
|
|
709
674
|
const result = schema;
|
|
@@ -711,13 +676,10 @@ function getArrayNode(schema, value) {
|
|
|
711
676
|
}
|
|
712
677
|
return null;
|
|
713
678
|
}
|
|
714
|
-
|
|
715
|
-
var clean = /* @__PURE__ */ __name(async function(info) {
|
|
679
|
+
var clean = async function(info) {
|
|
716
680
|
convertTypedModel(info);
|
|
717
681
|
let { schema, args = [], value } = info;
|
|
718
|
-
const currSchema = schema.type === void 0 ? {
|
|
719
|
-
type: schema
|
|
720
|
-
} : schema;
|
|
682
|
+
const currSchema = schema.type === void 0 ? { type: schema } : schema;
|
|
721
683
|
const objectSchema = getObjectNode(currSchema, value);
|
|
722
684
|
if (objectSchema) {
|
|
723
685
|
const newDoc = await cleanObjectFields({
|
|
@@ -732,9 +694,7 @@ var clean = /* @__PURE__ */ __name(async function(info) {
|
|
|
732
694
|
if (arraySchema) {
|
|
733
695
|
let updatedValue = value;
|
|
734
696
|
if (!isArray5(value) && !Array.isArray(value)) {
|
|
735
|
-
updatedValue = [
|
|
736
|
-
value
|
|
737
|
-
];
|
|
697
|
+
updatedValue = [value];
|
|
738
698
|
}
|
|
739
699
|
const newDoc = await cleanArrayItems({
|
|
740
700
|
...info,
|
|
@@ -746,7 +706,7 @@ var clean = /* @__PURE__ */ __name(async function(info) {
|
|
|
746
706
|
}
|
|
747
707
|
const result = await cleanType(currSchema.type, currSchema, value, info, ...args);
|
|
748
708
|
return result;
|
|
749
|
-
}
|
|
709
|
+
};
|
|
750
710
|
var recursiveClean_default = clean;
|
|
751
711
|
|
|
752
712
|
// src/clean/index.ts
|
|
@@ -759,14 +719,9 @@ var defaultOptions2 = {
|
|
|
759
719
|
async function clean2(schema, doc, opts = {}, ...args) {
|
|
760
720
|
if (!doc) return doc;
|
|
761
721
|
schema = getSchemaFromTypedModel(schema);
|
|
762
|
-
const options = {
|
|
763
|
-
...defaultOptions2,
|
|
764
|
-
...opts
|
|
765
|
-
};
|
|
722
|
+
const options = { ...defaultOptions2, ...opts };
|
|
766
723
|
const params = {
|
|
767
|
-
schema: {
|
|
768
|
-
type: schema
|
|
769
|
-
},
|
|
724
|
+
schema: { type: schema },
|
|
770
725
|
value: doc,
|
|
771
726
|
doc: options.forceDoc || doc,
|
|
772
727
|
currentDoc: doc,
|
|
@@ -776,42 +731,32 @@ async function clean2(schema, doc, opts = {}, ...args) {
|
|
|
776
731
|
const cleanedResult = await recursiveClean_default(params);
|
|
777
732
|
return cleanedResult;
|
|
778
733
|
}
|
|
779
|
-
__name(clean2, "clean");
|
|
780
734
|
|
|
781
735
|
// src/validateKey/dotGetSchema.ts
|
|
782
736
|
import isPlainObject7 from "lodash/isPlainObject";
|
|
783
737
|
import isNil6 from "lodash/isNil";
|
|
784
|
-
var dotGet =
|
|
738
|
+
var dotGet = function dotGet2(object, path) {
|
|
785
739
|
if (path === "") return object;
|
|
786
740
|
const pathParts = path.split(".");
|
|
787
741
|
const first = pathParts.shift();
|
|
788
742
|
const remainingPath = pathParts.join(".");
|
|
789
743
|
const levelObject = object.type;
|
|
790
744
|
if (first === "$" || /^[0-9]+$/.test(first)) {
|
|
791
|
-
return dotGet2({
|
|
792
|
-
type: levelObject[0]
|
|
793
|
-
}, remainingPath);
|
|
745
|
+
return dotGet2({ type: levelObject[0] }, remainingPath);
|
|
794
746
|
} else if (isPlainObject7(levelObject[first])) {
|
|
795
747
|
return dotGet2(levelObject[first], remainingPath);
|
|
796
748
|
}
|
|
797
749
|
if (levelObject === "blackbox") {
|
|
798
|
-
return {
|
|
799
|
-
type: "blackbox",
|
|
800
|
-
optional: true,
|
|
801
|
-
isBlackboxChild: true
|
|
802
|
-
};
|
|
750
|
+
return { type: "blackbox", optional: true, isBlackboxChild: true };
|
|
803
751
|
}
|
|
804
752
|
return null;
|
|
805
|
-
}
|
|
753
|
+
};
|
|
806
754
|
function dotGetSchema_default(schema, path) {
|
|
807
755
|
if (isNil6(schema)) {
|
|
808
756
|
throw new Error("You need to pass a schema");
|
|
809
757
|
}
|
|
810
|
-
return dotGet({
|
|
811
|
-
type: schema
|
|
812
|
-
}, path);
|
|
758
|
+
return dotGet({ type: schema }, path);
|
|
813
759
|
}
|
|
814
|
-
__name(dotGetSchema_default, "default");
|
|
815
760
|
|
|
816
761
|
// src/dotGetSchema.ts
|
|
817
762
|
var dotGetSchema_default2 = dotGetSchema_default;
|
|
@@ -821,10 +766,7 @@ var defaultOptions3 = {
|
|
|
821
766
|
filter: true
|
|
822
767
|
};
|
|
823
768
|
async function cleanKey_default(schema, key, value, passedOptions = {}, ...args) {
|
|
824
|
-
const options = {
|
|
825
|
-
...defaultOptions3,
|
|
826
|
-
...passedOptions
|
|
827
|
-
};
|
|
769
|
+
const options = { ...defaultOptions3, ...passedOptions };
|
|
828
770
|
const keySchema = dotGetSchema_default2(schema, key);
|
|
829
771
|
if (!keySchema) {
|
|
830
772
|
if (options.filter) {
|
|
@@ -833,24 +775,16 @@ async function cleanKey_default(schema, key, value, passedOptions = {}, ...args)
|
|
|
833
775
|
return value;
|
|
834
776
|
}
|
|
835
777
|
}
|
|
836
|
-
const result = await clean2({
|
|
837
|
-
clean: keySchema
|
|
838
|
-
}, {
|
|
839
|
-
clean: value
|
|
840
|
-
}, options, ...args);
|
|
778
|
+
const result = await clean2({ clean: keySchema }, { clean: value }, options, ...args);
|
|
841
779
|
return result.clean;
|
|
842
780
|
}
|
|
843
|
-
__name(cleanKey_default, "default");
|
|
844
781
|
|
|
845
782
|
// src/validateKey/index.ts
|
|
846
783
|
var defaultOptions4 = {
|
|
847
784
|
filter: false
|
|
848
785
|
};
|
|
849
786
|
async function validateKey_default(schema, key, value, passedOptions = {}, ...args) {
|
|
850
|
-
const options = {
|
|
851
|
-
...defaultOptions4,
|
|
852
|
-
...passedOptions
|
|
853
|
-
};
|
|
787
|
+
const options = { ...defaultOptions4, ...passedOptions };
|
|
854
788
|
const keySchema = dotGetSchema_default(schema, key);
|
|
855
789
|
if (!keySchema) {
|
|
856
790
|
if (options.filter) {
|
|
@@ -862,15 +796,15 @@ async function validateKey_default(schema, key, value, passedOptions = {}, ...ar
|
|
|
862
796
|
if (keySchema.isBlackboxChild) {
|
|
863
797
|
return null;
|
|
864
798
|
}
|
|
865
|
-
const result = await getValidationErrors2(
|
|
866
|
-
validate: keySchema
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
799
|
+
const result = await getValidationErrors2(
|
|
800
|
+
{ validate: keySchema },
|
|
801
|
+
{ validate: value },
|
|
802
|
+
options,
|
|
803
|
+
...args
|
|
804
|
+
);
|
|
870
805
|
if (!result) return null;
|
|
871
806
|
return result.validate;
|
|
872
807
|
}
|
|
873
|
-
__name(validateKey_default, "default");
|
|
874
808
|
|
|
875
809
|
// src/fieldTypes/enum.ts
|
|
876
810
|
import isString6 from "lodash/isString";
|
|
@@ -884,19 +818,17 @@ function createEnum(name, values) {
|
|
|
884
818
|
enumName: name,
|
|
885
819
|
enumValues: values
|
|
886
820
|
},
|
|
887
|
-
toGraphQLType:
|
|
821
|
+
toGraphQLType: (GraphQL) => {
|
|
888
822
|
global.GraphQLEnums = global.GraphQLEnums || {};
|
|
889
823
|
global.GraphQLEnums[name] = global.GraphQLEnums[name] || new GraphQL.GraphQLEnumType({
|
|
890
824
|
name,
|
|
891
825
|
values: values.reduce((result, value) => {
|
|
892
|
-
result[value] = {
|
|
893
|
-
value
|
|
894
|
-
};
|
|
826
|
+
result[value] = { value };
|
|
895
827
|
return result;
|
|
896
828
|
}, {})
|
|
897
829
|
});
|
|
898
830
|
return global.GraphQLEnums[name];
|
|
899
|
-
},
|
|
831
|
+
},
|
|
900
832
|
validate(value, { currentSchema }) {
|
|
901
833
|
if (!isString6(value)) return Errors_default.NOT_A_STRING;
|
|
902
834
|
if (!includes2(values, value)) {
|
|
@@ -921,7 +853,6 @@ function createEnum(name, values) {
|
|
|
921
853
|
})
|
|
922
854
|
};
|
|
923
855
|
}
|
|
924
|
-
__name(createEnum, "createEnum");
|
|
925
856
|
export {
|
|
926
857
|
ValidationError,
|
|
927
858
|
clean2 as clean,
|