@@ -50,21 +50,18 @@ const propsThatCanBeFunction = [
50
50
] ;
51
51
52
52
class SimpleSchema {
53
- constructor ( schema = { } , {
54
- check,
55
- clean : cleanOptions ,
56
- defaultLabel,
57
- humanizeAutoLabels = true ,
58
- requiredByDefault = true ,
59
- tracker,
60
- } = { } ) {
53
+ constructor ( schema = { } , options = { } ) {
61
54
// Stash the options object
62
55
this . _constructorOptions = {
63
- check,
64
- defaultLabel,
65
- humanizeAutoLabels,
66
- requiredByDefault,
67
- tracker,
56
+ ...SimpleSchema . _constructorOptionDefaults ,
57
+ ...options ,
58
+ } ;
59
+ delete this . _constructorOptions . clean ; // stored separately below
60
+
61
+ // Schema-level defaults for cleaning
62
+ this . _cleanOptions = {
63
+ ...SimpleSchema . _constructorOptionDefaults . clean ,
64
+ ...( options . clean || { } ) ,
68
65
} ;
69
66
70
67
// Custom validators for this instance
@@ -74,18 +71,6 @@ class SimpleSchema {
74
71
// Named validation contexts
75
72
this . _validationContexts = { } ;
76
73
77
- // Schema-level defaults for cleaning
78
- this . _cleanOptions = {
79
- filter : true ,
80
- autoConvert : true ,
81
- removeEmptyStrings : true ,
82
- trimStrings : true ,
83
- getAutoValues : true ,
84
- removeNullsFromArrays : false ,
85
- extendAutoValueContext : { } ,
86
- ...cleanOptions ,
87
- } ;
88
-
89
74
// Clone, expanding shorthand, and store the schema object in this._schema
90
75
this . _schema = { } ;
91
76
this . _depsLabels = { } ;
@@ -872,6 +857,37 @@ class SimpleSchema {
872
857
SimpleSchema . _docValidators . push ( func ) ;
873
858
}
874
859
860
+ // Global constructor options
861
+ static _constructorOptionDefaults = {
862
+ clean : {
863
+ autoConvert : true ,
864
+ extendAutoValueContext : { } ,
865
+ filter : true ,
866
+ getAutoValues : true ,
867
+ removeEmptyStrings : true ,
868
+ removeNullsFromArrays : false ,
869
+ trimStrings : true ,
870
+ } ,
871
+ humanizeAutoLabels : true ,
872
+ requiredByDefault : true ,
873
+ } ;
874
+
875
+ /**
876
+ * @summary Get/set default values for SimpleSchema constructor options
877
+ */
878
+ static constructorOptionDefaults ( options ) {
879
+ if ( ! options ) return SimpleSchema . _constructorOptionDefaults ;
880
+
881
+ SimpleSchema . _constructorOptionDefaults = {
882
+ ...SimpleSchema . _constructorOptionDefaults ,
883
+ ...options ,
884
+ clean : {
885
+ ...SimpleSchema . _constructorOptionDefaults . clean ,
886
+ ...( options . clean || { } ) ,
887
+ } ,
888
+ } ;
889
+ }
890
+
875
891
static ErrorTypes = {
876
892
REQUIRED : 'required' ,
877
893
MIN_STRING : 'minString' ,
0 commit comments