@strictly/define 0.0.9 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.out/transformers/copies/copy_to.js +1 -4
- package/.out/tsconfig.tsbuildinfo +1 -1
- package/.out/tsup.config.js +2 -9
- package/.out/types/builders.js +27 -84
- package/.out/validation/validators/defined_validator.js +6 -2
- package/.out/validation/validators/minimum_string_length_validator.js +6 -2
- package/.out/validation/validators/optional_validator_proxy.js +13 -8
- package/.out/validation/validators/regexp_validator.js +42 -14
- package/.turbo/turbo-build.log +7 -7
- package/.turbo/turbo-check-types.log +1 -1
- package/.turbo/turbo-release$colon$exports.log +1 -1
- package/dist/index.cjs +83 -94
- package/dist/index.js +86 -94
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
+
|
|
1
22
|
// transformers/copies/copy_to.ts
|
|
2
23
|
import {
|
|
3
24
|
map,
|
|
@@ -115,14 +136,13 @@ function copyUnion(typeDef, value, copier) {
|
|
|
115
136
|
} = typeDef;
|
|
116
137
|
if (discriminator != null) {
|
|
117
138
|
const discriminatorValue = value[discriminator];
|
|
118
|
-
const discriminatingUnion = {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
),
|
|
139
|
+
const discriminatingUnion = __spreadProps(__spreadValues({}, internalCopyTo(
|
|
140
|
+
unions[discriminatorValue],
|
|
141
|
+
value,
|
|
142
|
+
copier
|
|
143
|
+
)), {
|
|
124
144
|
[discriminator]: discriminatorValue
|
|
125
|
-
};
|
|
145
|
+
});
|
|
126
146
|
return copier(discriminatingUnion, typeDef);
|
|
127
147
|
}
|
|
128
148
|
const allTypeDefs = Object.values(unions);
|
|
@@ -762,35 +782,32 @@ var TypeDefBuilder = class _TypeDefBuilder {
|
|
|
762
782
|
enforce(rule) {
|
|
763
783
|
return new _TypeDefBuilder(
|
|
764
784
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
765
|
-
{
|
|
766
|
-
...this.definition,
|
|
767
|
-
...isAnnotatedValidator(rule) ? mergeAnnotations(rule.annotations(null, null), this.definition) : {},
|
|
785
|
+
__spreadProps(__spreadValues(__spreadValues({}, this.definition), isAnnotatedValidator(rule) ? mergeAnnotations(rule.annotations(null, null), this.definition) : {}), {
|
|
768
786
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
769
787
|
rule: (value) => {
|
|
770
|
-
|
|
788
|
+
var _a;
|
|
789
|
+
return (_a = this.definition.rule(value)) != null ? _a : validate(rule, value, null, null);
|
|
771
790
|
}
|
|
772
791
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
773
|
-
}
|
|
792
|
+
})
|
|
774
793
|
);
|
|
775
794
|
}
|
|
776
795
|
required() {
|
|
777
796
|
return new _TypeDefBuilder(
|
|
778
797
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
779
|
-
{
|
|
780
|
-
...this.definition,
|
|
798
|
+
__spreadProps(__spreadValues({}, this.definition), {
|
|
781
799
|
required: true
|
|
782
800
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
783
|
-
}
|
|
801
|
+
})
|
|
784
802
|
);
|
|
785
803
|
}
|
|
786
804
|
readonly() {
|
|
787
805
|
return new _TypeDefBuilder(
|
|
788
806
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
789
|
-
{
|
|
790
|
-
...this.definition,
|
|
807
|
+
__spreadProps(__spreadValues({}, this.definition), {
|
|
791
808
|
readonly: true
|
|
792
809
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
793
|
-
}
|
|
810
|
+
})
|
|
794
811
|
);
|
|
795
812
|
}
|
|
796
813
|
// should only be used in tests requiring Types, client code should be happy with validating types
|
|
@@ -807,13 +824,11 @@ var TypeDefBuilder = class _TypeDefBuilder {
|
|
|
807
824
|
};
|
|
808
825
|
var ListTypeDefBuilder = class _ListTypeDefBuilder extends TypeDefBuilder {
|
|
809
826
|
readonlyElements() {
|
|
810
|
-
return new _ListTypeDefBuilder({
|
|
811
|
-
|
|
812
|
-
elements: {
|
|
813
|
-
...this.definition.elements,
|
|
827
|
+
return new _ListTypeDefBuilder(__spreadProps(__spreadValues({}, this.definition), {
|
|
828
|
+
elements: __spreadProps(__spreadValues({}, this.definition.elements), {
|
|
814
829
|
readonly: true
|
|
815
|
-
}
|
|
816
|
-
});
|
|
830
|
+
})
|
|
831
|
+
}));
|
|
817
832
|
}
|
|
818
833
|
};
|
|
819
834
|
var RecordTypeDefBuilder = class _RecordTypeDefBuilder extends TypeDefBuilder {
|
|
@@ -821,75 +836,54 @@ var RecordTypeDefBuilder = class _RecordTypeDefBuilder extends TypeDefBuilder {
|
|
|
821
836
|
return this;
|
|
822
837
|
}
|
|
823
838
|
readonlyKeys() {
|
|
824
|
-
return new _RecordTypeDefBuilder({
|
|
825
|
-
|
|
826
|
-
valueTypeDef: {
|
|
827
|
-
...this.definition.valueTypeDef,
|
|
839
|
+
return new _RecordTypeDefBuilder(__spreadProps(__spreadValues({}, this.definition), {
|
|
840
|
+
valueTypeDef: __spreadProps(__spreadValues({}, this.definition.valueTypeDef), {
|
|
828
841
|
readonly: true
|
|
829
|
-
}
|
|
830
|
-
});
|
|
842
|
+
})
|
|
843
|
+
}));
|
|
831
844
|
}
|
|
832
845
|
};
|
|
833
846
|
var ObjectTypeDefBuilder = class _ObjectTypeDefBuilder extends TypeDefBuilder {
|
|
834
847
|
field(name, { definition }, rule) {
|
|
835
|
-
return new _ObjectTypeDefBuilder({
|
|
836
|
-
...this.definition,
|
|
848
|
+
return new _ObjectTypeDefBuilder(__spreadProps(__spreadValues({}, this.definition), {
|
|
837
849
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
838
|
-
fields: {
|
|
839
|
-
|
|
840
|
-
[name]: {
|
|
841
|
-
...definition,
|
|
850
|
+
fields: __spreadProps(__spreadValues({}, this.definition.fields), {
|
|
851
|
+
[name]: __spreadProps(__spreadValues({}, definition), {
|
|
842
852
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
843
853
|
rule: function(v) {
|
|
844
|
-
return definition.rule(v) || rule
|
|
854
|
+
return definition.rule(v) || (rule == null ? void 0 : rule(v));
|
|
845
855
|
}
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
});
|
|
856
|
+
})
|
|
857
|
+
})
|
|
858
|
+
}));
|
|
849
859
|
}
|
|
850
860
|
readonlyField(name, { definition }) {
|
|
851
861
|
const newFields = {
|
|
852
|
-
[name]: {
|
|
853
|
-
...definition,
|
|
862
|
+
[name]: __spreadProps(__spreadValues({}, definition), {
|
|
854
863
|
readonly: true
|
|
855
|
-
}
|
|
864
|
+
})
|
|
856
865
|
};
|
|
857
|
-
return new _ObjectTypeDefBuilder({
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
...this.definition.fields,
|
|
861
|
-
...newFields
|
|
862
|
-
}
|
|
863
|
-
});
|
|
866
|
+
return new _ObjectTypeDefBuilder(__spreadProps(__spreadValues({}, this.definition), {
|
|
867
|
+
fields: __spreadValues(__spreadValues({}, this.definition.fields), newFields)
|
|
868
|
+
}));
|
|
864
869
|
}
|
|
865
870
|
optionalField(name, { definition }) {
|
|
866
871
|
const newFields = {
|
|
867
|
-
[name]: {
|
|
868
|
-
...definition
|
|
869
|
-
}
|
|
872
|
+
[name]: __spreadValues({}, definition)
|
|
870
873
|
};
|
|
871
|
-
return new _ObjectTypeDefBuilder({
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
...this.definition.fields,
|
|
875
|
-
...newFields
|
|
876
|
-
}
|
|
877
|
-
});
|
|
874
|
+
return new _ObjectTypeDefBuilder(__spreadProps(__spreadValues({}, this.definition), {
|
|
875
|
+
fields: __spreadValues(__spreadValues({}, this.definition.fields), newFields)
|
|
876
|
+
}));
|
|
878
877
|
}
|
|
879
878
|
readonlyOptionalField(name, { definition }) {
|
|
880
879
|
const newFields = {
|
|
881
|
-
[name]: {
|
|
882
|
-
...definition,
|
|
880
|
+
[name]: __spreadProps(__spreadValues({}, definition), {
|
|
883
881
|
readonly: true
|
|
884
|
-
}
|
|
882
|
+
})
|
|
885
883
|
};
|
|
886
|
-
return new _ObjectTypeDefBuilder({
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
...this.definition.fields,
|
|
890
|
-
...newFields
|
|
891
|
-
}
|
|
892
|
-
});
|
|
884
|
+
return new _ObjectTypeDefBuilder(__spreadProps(__spreadValues({}, this.definition), {
|
|
885
|
+
fields: __spreadValues(__spreadValues({}, this.definition.fields), newFields)
|
|
886
|
+
}));
|
|
893
887
|
}
|
|
894
888
|
};
|
|
895
889
|
var UnionTypeDefBuilder = class _UnionTypeDefBuilder extends TypeDefBuilder {
|
|
@@ -900,14 +894,12 @@ var UnionTypeDefBuilder = class _UnionTypeDefBuilder extends TypeDefBuilder {
|
|
|
900
894
|
unions
|
|
901
895
|
} = this.definition;
|
|
902
896
|
return new _UnionTypeDefBuilder(
|
|
903
|
-
{
|
|
904
|
-
...this.definition,
|
|
897
|
+
__spreadProps(__spreadValues({}, this.definition), {
|
|
905
898
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
906
|
-
unions: {
|
|
907
|
-
...unions,
|
|
899
|
+
unions: __spreadProps(__spreadValues({}, unions), {
|
|
908
900
|
[k]: typeDef
|
|
909
|
-
}
|
|
910
|
-
}
|
|
901
|
+
})
|
|
902
|
+
})
|
|
911
903
|
);
|
|
912
904
|
}
|
|
913
905
|
};
|
|
@@ -973,7 +965,7 @@ function union(discriminator) {
|
|
|
973
965
|
{
|
|
974
966
|
type: 5 /* Union */,
|
|
975
967
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
976
|
-
discriminator: discriminator
|
|
968
|
+
discriminator: discriminator != null ? discriminator : null,
|
|
977
969
|
unions: {},
|
|
978
970
|
rule: emptyRule,
|
|
979
971
|
readonly: false,
|
|
@@ -1044,38 +1036,26 @@ var OptionalValidatorProxy = class _OptionalValidatorProxy {
|
|
|
1044
1036
|
return null;
|
|
1045
1037
|
}
|
|
1046
1038
|
annotations(valuePath, context) {
|
|
1047
|
-
return {
|
|
1048
|
-
...this.proxied.annotations(valuePath, context),
|
|
1039
|
+
return __spreadProps(__spreadValues({}, this.proxied.annotations(valuePath, context)), {
|
|
1049
1040
|
required: false
|
|
1050
|
-
};
|
|
1041
|
+
});
|
|
1051
1042
|
}
|
|
1052
1043
|
};
|
|
1053
1044
|
|
|
1054
1045
|
// validation/validators/regexp_validator.ts
|
|
1055
1046
|
var RegexpValidationErrorType = "regexp";
|
|
1056
|
-
var
|
|
1047
|
+
var _RegexpValidator = class _RegexpValidator {
|
|
1057
1048
|
constructor(regexp, intent, {
|
|
1058
1049
|
negate = false,
|
|
1059
1050
|
required = false
|
|
1060
1051
|
} = {}) {
|
|
1061
1052
|
this.regexp = regexp;
|
|
1062
1053
|
this.intent = intent;
|
|
1054
|
+
__publicField(this, "negate");
|
|
1055
|
+
__publicField(this, "required");
|
|
1063
1056
|
this.negate = negate;
|
|
1064
1057
|
this.required = required;
|
|
1065
1058
|
}
|
|
1066
|
-
/**
|
|
1067
|
-
* Extremely permissive email validator
|
|
1068
|
-
*/
|
|
1069
|
-
static email = new _RegexpValidator(/^[^\s@]+@[^\s@]+\.[^\s@]+$/, "email");
|
|
1070
|
-
/**
|
|
1071
|
-
* Extremely permissive phone number validator
|
|
1072
|
-
*/
|
|
1073
|
-
static phone = new _RegexpValidator(
|
|
1074
|
-
/^(\+\d{1,4}[\s]*)?(((\([\d\s-]{1,6}\))|\d)[\s-]*){3,14}(\d|(\(\d+\)))$/,
|
|
1075
|
-
"phone"
|
|
1076
|
-
);
|
|
1077
|
-
negate;
|
|
1078
|
-
required;
|
|
1079
1059
|
validate(value) {
|
|
1080
1060
|
const passes = this.regexp.test(value);
|
|
1081
1061
|
if (!passes && !this.negate || passes && this.negate) {
|
|
@@ -1093,6 +1073,18 @@ var RegexpValidator = class _RegexpValidator {
|
|
|
1093
1073
|
};
|
|
1094
1074
|
}
|
|
1095
1075
|
};
|
|
1076
|
+
/**
|
|
1077
|
+
* Extremely permissive email validator
|
|
1078
|
+
*/
|
|
1079
|
+
__publicField(_RegexpValidator, "email", new _RegexpValidator(/^[^\s@]+@[^\s@]+\.[^\s@]+$/, "email"));
|
|
1080
|
+
/**
|
|
1081
|
+
* Extremely permissive phone number validator
|
|
1082
|
+
*/
|
|
1083
|
+
__publicField(_RegexpValidator, "phone", new _RegexpValidator(
|
|
1084
|
+
/^(\+\d{1,4}[\s]*)?(((\([\d\s-]{1,6}\))|\d)[\s-]*){3,14}(\d|(\(\d+\)))$/,
|
|
1085
|
+
"phone"
|
|
1086
|
+
));
|
|
1087
|
+
var RegexpValidator = _RegexpValidator;
|
|
1096
1088
|
export {
|
|
1097
1089
|
DefinedValidator,
|
|
1098
1090
|
MinimumStringLengthValidationErrorType,
|