@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/.out/tsup.config.js
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import { defineConfig, } from 'tsup';
|
|
2
|
-
export default defineConfig((options) => ({
|
|
3
|
-
entry: ['index.ts'],
|
|
4
|
-
tsconfig: './tsconfig.build.json',
|
|
5
|
-
clean: false,
|
|
6
|
-
dts: true,
|
|
7
|
-
format: [
|
|
2
|
+
export default defineConfig((options) => (Object.assign({ entry: ['index.ts'], tsconfig: './tsconfig.build.json', clean: false, dts: true, format: [
|
|
8
3
|
'cjs',
|
|
9
4
|
'esm',
|
|
10
|
-
],
|
|
11
|
-
...options,
|
|
12
|
-
}));
|
|
5
|
+
] }, options)));
|
package/.out/types/builders.js
CHANGED
|
@@ -5,40 +5,33 @@ function emptyRule() {
|
|
|
5
5
|
return null;
|
|
6
6
|
}
|
|
7
7
|
class TypeDefBuilder {
|
|
8
|
-
definition;
|
|
9
8
|
constructor(definition) {
|
|
10
|
-
this
|
|
9
|
+
Object.defineProperty(this, "definition", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: definition
|
|
14
|
+
});
|
|
11
15
|
}
|
|
12
16
|
enforce(rule) {
|
|
13
17
|
return new TypeDefBuilder(
|
|
14
18
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
15
|
-
{
|
|
16
|
-
...this.definition,
|
|
17
|
-
...(isAnnotatedValidator(rule) ? mergeAnnotations(rule.annotations(null, null), this.definition) : {}),
|
|
19
|
+
Object.assign(Object.assign(Object.assign({}, this.definition), (isAnnotatedValidator(rule) ? mergeAnnotations(rule.annotations(null, null), this.definition) : {})), {
|
|
18
20
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
21
|
rule: (value) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
});
|
|
22
|
+
var _a;
|
|
23
|
+
return (_a = this.definition.rule(value)) !== null && _a !== void 0 ? _a : validate(rule, value, null, null);
|
|
24
|
+
} }));
|
|
24
25
|
}
|
|
25
26
|
required() {
|
|
26
27
|
return new TypeDefBuilder(
|
|
27
28
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
28
|
-
{
|
|
29
|
-
...this.definition,
|
|
30
|
-
required: true,
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
-
});
|
|
29
|
+
Object.assign(Object.assign({}, this.definition), { required: true }));
|
|
33
30
|
}
|
|
34
31
|
readonly() {
|
|
35
32
|
return new TypeDefBuilder(
|
|
36
33
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
37
|
-
{
|
|
38
|
-
...this.definition,
|
|
39
|
-
readonly: true,
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
-
});
|
|
34
|
+
Object.assign(Object.assign({}, this.definition), { readonly: true }));
|
|
42
35
|
}
|
|
43
36
|
// should only be used in tests requiring Types, client code should be happy with validating types
|
|
44
37
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
@@ -55,13 +48,7 @@ class TypeDefBuilder {
|
|
|
55
48
|
}
|
|
56
49
|
class ListTypeDefBuilder extends TypeDefBuilder {
|
|
57
50
|
readonlyElements() {
|
|
58
|
-
return new ListTypeDefBuilder({
|
|
59
|
-
...this.definition,
|
|
60
|
-
elements: {
|
|
61
|
-
...this.definition.elements,
|
|
62
|
-
readonly: true,
|
|
63
|
-
},
|
|
64
|
-
});
|
|
51
|
+
return new ListTypeDefBuilder(Object.assign(Object.assign({}, this.definition), { elements: Object.assign(Object.assign({}, this.definition.elements), { readonly: true }) }));
|
|
65
52
|
}
|
|
66
53
|
}
|
|
67
54
|
class RecordTypeDefBuilder extends TypeDefBuilder {
|
|
@@ -69,92 +56,48 @@ class RecordTypeDefBuilder extends TypeDefBuilder {
|
|
|
69
56
|
return this;
|
|
70
57
|
}
|
|
71
58
|
readonlyKeys() {
|
|
72
|
-
return new RecordTypeDefBuilder({
|
|
73
|
-
...this.definition,
|
|
74
|
-
valueTypeDef: {
|
|
75
|
-
...this.definition.valueTypeDef,
|
|
76
|
-
readonly: true,
|
|
77
|
-
},
|
|
78
|
-
});
|
|
59
|
+
return new RecordTypeDefBuilder(Object.assign(Object.assign({}, this.definition), { valueTypeDef: Object.assign(Object.assign({}, this.definition.valueTypeDef), { readonly: true }) }));
|
|
79
60
|
}
|
|
80
61
|
}
|
|
81
62
|
class ObjectTypeDefBuilder extends TypeDefBuilder {
|
|
82
63
|
field(name, { definition }, rule) {
|
|
83
64
|
// have to explicitly supply types as TS will infinitely recurse trying to infer them!
|
|
84
|
-
return new ObjectTypeDefBuilder({
|
|
85
|
-
...this.definition,
|
|
65
|
+
return new ObjectTypeDefBuilder(Object.assign(Object.assign({}, this.definition), {
|
|
86
66
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
87
|
-
fields: {
|
|
88
|
-
...this.definition.fields,
|
|
89
|
-
[name]: {
|
|
90
|
-
...definition,
|
|
67
|
+
fields: Object.assign(Object.assign({}, this.definition.fields), { [name]: Object.assign(Object.assign({}, definition), {
|
|
91
68
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
92
69
|
rule: function (v) {
|
|
93
|
-
return definition.rule(v) || rule
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
});
|
|
70
|
+
return definition.rule(v) || (rule === null || rule === void 0 ? void 0 : rule(v));
|
|
71
|
+
} }) }) }));
|
|
98
72
|
}
|
|
99
73
|
readonlyField(name, { definition }) {
|
|
100
74
|
const newFields = {
|
|
101
|
-
[name]: {
|
|
102
|
-
...definition,
|
|
103
|
-
readonly: true,
|
|
104
|
-
},
|
|
75
|
+
[name]: Object.assign(Object.assign({}, definition), { readonly: true }),
|
|
105
76
|
};
|
|
106
77
|
// have to explicitly supply types as TS will infinitely recurse trying to infer them!
|
|
107
|
-
return new ObjectTypeDefBuilder({
|
|
108
|
-
...this.definition,
|
|
109
|
-
fields: {
|
|
110
|
-
...this.definition.fields,
|
|
111
|
-
...newFields,
|
|
112
|
-
},
|
|
113
|
-
});
|
|
78
|
+
return new ObjectTypeDefBuilder(Object.assign(Object.assign({}, this.definition), { fields: Object.assign(Object.assign({}, this.definition.fields), newFields) }));
|
|
114
79
|
}
|
|
115
80
|
optionalField(name, { definition }) {
|
|
116
81
|
const newFields = {
|
|
117
|
-
[name]: {
|
|
118
|
-
...definition,
|
|
119
|
-
},
|
|
82
|
+
[name]: Object.assign({}, definition),
|
|
120
83
|
};
|
|
121
84
|
// have to explicitly supply types as TS will infinitely recurse trying to infer them!
|
|
122
|
-
return new ObjectTypeDefBuilder({
|
|
123
|
-
...this.definition,
|
|
124
|
-
fields: {
|
|
125
|
-
...this.definition.fields,
|
|
126
|
-
...newFields,
|
|
127
|
-
},
|
|
128
|
-
});
|
|
85
|
+
return new ObjectTypeDefBuilder(Object.assign(Object.assign({}, this.definition), { fields: Object.assign(Object.assign({}, this.definition.fields), newFields) }));
|
|
129
86
|
}
|
|
130
87
|
readonlyOptionalField(name, { definition }) {
|
|
131
88
|
const newFields = {
|
|
132
|
-
[name]: {
|
|
133
|
-
...definition,
|
|
134
|
-
readonly: true,
|
|
135
|
-
},
|
|
89
|
+
[name]: Object.assign(Object.assign({}, definition), { readonly: true }),
|
|
136
90
|
};
|
|
137
91
|
// have to explicitly supply types as TS will infinitely recurse trying to infer them!
|
|
138
|
-
return new ObjectTypeDefBuilder({
|
|
139
|
-
...this.definition,
|
|
140
|
-
fields: {
|
|
141
|
-
...this.definition.fields,
|
|
142
|
-
...newFields,
|
|
143
|
-
},
|
|
144
|
-
});
|
|
92
|
+
return new ObjectTypeDefBuilder(Object.assign(Object.assign({}, this.definition), { fields: Object.assign(Object.assign({}, this.definition.fields), newFields) }));
|
|
145
93
|
}
|
|
146
94
|
}
|
|
147
95
|
class UnionTypeDefBuilder extends TypeDefBuilder {
|
|
148
96
|
or(k, { definition: typeDef, }) {
|
|
149
97
|
const { unions, } = this.definition;
|
|
150
|
-
return new UnionTypeDefBuilder({
|
|
151
|
-
...this.definition,
|
|
98
|
+
return new UnionTypeDefBuilder(Object.assign(Object.assign({}, this.definition), {
|
|
152
99
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
153
|
-
unions: {
|
|
154
|
-
...unions,
|
|
155
|
-
[k]: typeDef,
|
|
156
|
-
},
|
|
157
|
-
});
|
|
100
|
+
unions: Object.assign(Object.assign({}, unions), { [k]: typeDef }) }));
|
|
158
101
|
}
|
|
159
102
|
}
|
|
160
103
|
export function literal(value) {
|
|
@@ -219,7 +162,7 @@ export function union(discriminator) {
|
|
|
219
162
|
return new UnionTypeDefBuilder({
|
|
220
163
|
type: TypeDefType.Union,
|
|
221
164
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
222
|
-
discriminator: (discriminator
|
|
165
|
+
discriminator: (discriminator !== null && discriminator !== void 0 ? discriminator : null),
|
|
223
166
|
unions: {},
|
|
224
167
|
rule: emptyRule,
|
|
225
168
|
readonly: false,
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
export const MinimumStringLengthValidationErrorType = 'minimum_string_length';
|
|
2
2
|
export class MinimumStringLengthValidator {
|
|
3
|
-
minimumLength;
|
|
4
3
|
constructor(minimumLength) {
|
|
5
|
-
this
|
|
4
|
+
Object.defineProperty(this, "minimumLength", {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true,
|
|
8
|
+
value: minimumLength
|
|
9
|
+
});
|
|
6
10
|
}
|
|
7
11
|
validate(value) {
|
|
8
12
|
if (value.length < this.minimumLength) {
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export class OptionalValidatorProxy {
|
|
2
|
-
proxied;
|
|
3
|
-
isRequired;
|
|
4
2
|
static createNullable(proxied) {
|
|
5
3
|
return new OptionalValidatorProxy(proxied, (v) => v != null);
|
|
6
4
|
}
|
|
@@ -8,8 +6,18 @@ export class OptionalValidatorProxy {
|
|
|
8
6
|
return new OptionalValidatorProxy(proxied, (v) => v != null && v !== '');
|
|
9
7
|
}
|
|
10
8
|
constructor(proxied, isRequired) {
|
|
11
|
-
this
|
|
12
|
-
|
|
9
|
+
Object.defineProperty(this, "proxied", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: proxied
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(this, "isRequired", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: isRequired
|
|
20
|
+
});
|
|
13
21
|
}
|
|
14
22
|
validate(v, valuePath, context) {
|
|
15
23
|
if (this.isRequired(v)) {
|
|
@@ -18,9 +26,6 @@ export class OptionalValidatorProxy {
|
|
|
18
26
|
return null;
|
|
19
27
|
}
|
|
20
28
|
annotations(valuePath, context) {
|
|
21
|
-
return {
|
|
22
|
-
...this.proxied.annotations(valuePath, context),
|
|
23
|
-
required: false,
|
|
24
|
-
};
|
|
29
|
+
return Object.assign(Object.assign({}, this.proxied.annotations(valuePath, context)), { required: false });
|
|
25
30
|
}
|
|
26
31
|
}
|
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
export const RegexpValidationErrorType = 'regexp';
|
|
2
2
|
export class RegexpValidator {
|
|
3
|
-
regexp;
|
|
4
|
-
intent;
|
|
5
|
-
/**
|
|
6
|
-
* Extremely permissive email validator
|
|
7
|
-
*/
|
|
8
|
-
static email = new RegexpValidator(/^[^\s@]+@[^\s@]+\.[^\s@]+$/, 'email');
|
|
9
|
-
/**
|
|
10
|
-
* Extremely permissive phone number validator
|
|
11
|
-
*/
|
|
12
|
-
static phone = new RegexpValidator(/^(\+\d{1,4}[\s]*)?(((\([\d\s-]{1,6}\))|\d)[\s-]*){3,14}(\d|(\(\d+\)))$/, 'phone');
|
|
13
|
-
negate;
|
|
14
|
-
required;
|
|
15
3
|
constructor(regexp, intent, { negate = false, required = false, } = {}) {
|
|
16
|
-
this
|
|
17
|
-
|
|
4
|
+
Object.defineProperty(this, "regexp", {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true,
|
|
8
|
+
value: regexp
|
|
9
|
+
});
|
|
10
|
+
Object.defineProperty(this, "intent", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value: intent
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(this, "negate", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
value: void 0
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(this, "required", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: void 0
|
|
27
|
+
});
|
|
18
28
|
this.negate = negate;
|
|
19
29
|
this.required = required;
|
|
20
30
|
}
|
|
@@ -35,3 +45,21 @@ export class RegexpValidator {
|
|
|
35
45
|
};
|
|
36
46
|
}
|
|
37
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Extremely permissive email validator
|
|
50
|
+
*/
|
|
51
|
+
Object.defineProperty(RegexpValidator, "email", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
writable: true,
|
|
55
|
+
value: new RegexpValidator(/^[^\s@]+@[^\s@]+\.[^\s@]+$/, 'email')
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* Extremely permissive phone number validator
|
|
59
|
+
*/
|
|
60
|
+
Object.defineProperty(RegexpValidator, "phone", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
configurable: true,
|
|
63
|
+
writable: true,
|
|
64
|
+
value: new RegexpValidator(/^(\+\d{1,4}[\s]*)?(((\([\d\s-]{1,6}\))|\d)[\s-]*){3,14}(\d|(\(\d+\)))$/, 'phone')
|
|
65
|
+
});
|
package/.turbo/turbo-build.log
CHANGED
|
@@ -4,15 +4,15 @@ $ tsup
|
|
|
4
4
|
[34mCLI[39m Using tsconfig: tsconfig.build.json
|
|
5
5
|
[34mCLI[39m tsup v8.3.5
|
|
6
6
|
[34mCLI[39m Using tsup config: /home/runner/work/strictly/strictly/packages/define/tsup.config.ts
|
|
7
|
-
[34mCLI[39m Target:
|
|
7
|
+
[34mCLI[39m Target: es6
|
|
8
8
|
[34mCJS[39m Build start
|
|
9
9
|
[34mESM[39m Build start
|
|
10
|
-
[32mCJS[39m [1mdist/index.cjs [22m[
|
|
11
|
-
[32mCJS[39m ⚡️ Build success in
|
|
12
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
13
|
-
[32mESM[39m ⚡️ Build success in
|
|
10
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m30.58 KB[39m
|
|
11
|
+
[32mCJS[39m ⚡️ Build success in 76ms
|
|
12
|
+
[32mESM[39m [1mdist/index.js [22m[32m28.28 KB[39m
|
|
13
|
+
[32mESM[39m ⚡️ Build success in 75ms
|
|
14
14
|
[34mDTS[39m Build start
|
|
15
|
-
[32mDTS[39m ⚡️ Build success in
|
|
15
|
+
[32mDTS[39m ⚡️ Build success in 5294ms
|
|
16
16
|
[32mDTS[39m [1mdist/index.d.cts [22m[32m40.10 KB[39m
|
|
17
17
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m40.10 KB[39m
|
|
18
|
-
Done in 6.
|
|
18
|
+
Done in 6.13s.
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
6
23
|
var __export = (target, all) => {
|
|
7
24
|
for (var name in all)
|
|
8
25
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -16,6 +33,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
33
|
return to;
|
|
17
34
|
};
|
|
18
35
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
19
37
|
|
|
20
38
|
// index.ts
|
|
21
39
|
var index_exports = {};
|
|
@@ -169,14 +187,13 @@ function copyUnion(typeDef, value, copier) {
|
|
|
169
187
|
} = typeDef;
|
|
170
188
|
if (discriminator != null) {
|
|
171
189
|
const discriminatorValue = value[discriminator];
|
|
172
|
-
const discriminatingUnion = {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
),
|
|
190
|
+
const discriminatingUnion = __spreadProps(__spreadValues({}, internalCopyTo(
|
|
191
|
+
unions[discriminatorValue],
|
|
192
|
+
value,
|
|
193
|
+
copier
|
|
194
|
+
)), {
|
|
178
195
|
[discriminator]: discriminatorValue
|
|
179
|
-
};
|
|
196
|
+
});
|
|
180
197
|
return copier(discriminatingUnion, typeDef);
|
|
181
198
|
}
|
|
182
199
|
const allTypeDefs = Object.values(unions);
|
|
@@ -794,35 +811,32 @@ var TypeDefBuilder = class _TypeDefBuilder {
|
|
|
794
811
|
enforce(rule) {
|
|
795
812
|
return new _TypeDefBuilder(
|
|
796
813
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
797
|
-
{
|
|
798
|
-
...this.definition,
|
|
799
|
-
...isAnnotatedValidator(rule) ? mergeAnnotations(rule.annotations(null, null), this.definition) : {},
|
|
814
|
+
__spreadProps(__spreadValues(__spreadValues({}, this.definition), isAnnotatedValidator(rule) ? mergeAnnotations(rule.annotations(null, null), this.definition) : {}), {
|
|
800
815
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
801
816
|
rule: (value) => {
|
|
802
|
-
|
|
817
|
+
var _a;
|
|
818
|
+
return (_a = this.definition.rule(value)) != null ? _a : validate(rule, value, null, null);
|
|
803
819
|
}
|
|
804
820
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
805
|
-
}
|
|
821
|
+
})
|
|
806
822
|
);
|
|
807
823
|
}
|
|
808
824
|
required() {
|
|
809
825
|
return new _TypeDefBuilder(
|
|
810
826
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
811
|
-
{
|
|
812
|
-
...this.definition,
|
|
827
|
+
__spreadProps(__spreadValues({}, this.definition), {
|
|
813
828
|
required: true
|
|
814
829
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
815
|
-
}
|
|
830
|
+
})
|
|
816
831
|
);
|
|
817
832
|
}
|
|
818
833
|
readonly() {
|
|
819
834
|
return new _TypeDefBuilder(
|
|
820
835
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
821
|
-
{
|
|
822
|
-
...this.definition,
|
|
836
|
+
__spreadProps(__spreadValues({}, this.definition), {
|
|
823
837
|
readonly: true
|
|
824
838
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
825
|
-
}
|
|
839
|
+
})
|
|
826
840
|
);
|
|
827
841
|
}
|
|
828
842
|
// should only be used in tests requiring Types, client code should be happy with validating types
|
|
@@ -839,13 +853,11 @@ var TypeDefBuilder = class _TypeDefBuilder {
|
|
|
839
853
|
};
|
|
840
854
|
var ListTypeDefBuilder = class _ListTypeDefBuilder extends TypeDefBuilder {
|
|
841
855
|
readonlyElements() {
|
|
842
|
-
return new _ListTypeDefBuilder({
|
|
843
|
-
|
|
844
|
-
elements: {
|
|
845
|
-
...this.definition.elements,
|
|
856
|
+
return new _ListTypeDefBuilder(__spreadProps(__spreadValues({}, this.definition), {
|
|
857
|
+
elements: __spreadProps(__spreadValues({}, this.definition.elements), {
|
|
846
858
|
readonly: true
|
|
847
|
-
}
|
|
848
|
-
});
|
|
859
|
+
})
|
|
860
|
+
}));
|
|
849
861
|
}
|
|
850
862
|
};
|
|
851
863
|
var RecordTypeDefBuilder = class _RecordTypeDefBuilder extends TypeDefBuilder {
|
|
@@ -853,75 +865,54 @@ var RecordTypeDefBuilder = class _RecordTypeDefBuilder extends TypeDefBuilder {
|
|
|
853
865
|
return this;
|
|
854
866
|
}
|
|
855
867
|
readonlyKeys() {
|
|
856
|
-
return new _RecordTypeDefBuilder({
|
|
857
|
-
|
|
858
|
-
valueTypeDef: {
|
|
859
|
-
...this.definition.valueTypeDef,
|
|
868
|
+
return new _RecordTypeDefBuilder(__spreadProps(__spreadValues({}, this.definition), {
|
|
869
|
+
valueTypeDef: __spreadProps(__spreadValues({}, this.definition.valueTypeDef), {
|
|
860
870
|
readonly: true
|
|
861
|
-
}
|
|
862
|
-
});
|
|
871
|
+
})
|
|
872
|
+
}));
|
|
863
873
|
}
|
|
864
874
|
};
|
|
865
875
|
var ObjectTypeDefBuilder = class _ObjectTypeDefBuilder extends TypeDefBuilder {
|
|
866
876
|
field(name, { definition }, rule) {
|
|
867
|
-
return new _ObjectTypeDefBuilder({
|
|
868
|
-
...this.definition,
|
|
877
|
+
return new _ObjectTypeDefBuilder(__spreadProps(__spreadValues({}, this.definition), {
|
|
869
878
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
870
|
-
fields: {
|
|
871
|
-
|
|
872
|
-
[name]: {
|
|
873
|
-
...definition,
|
|
879
|
+
fields: __spreadProps(__spreadValues({}, this.definition.fields), {
|
|
880
|
+
[name]: __spreadProps(__spreadValues({}, definition), {
|
|
874
881
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
875
882
|
rule: function(v) {
|
|
876
|
-
return definition.rule(v) || rule
|
|
883
|
+
return definition.rule(v) || (rule == null ? void 0 : rule(v));
|
|
877
884
|
}
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
});
|
|
885
|
+
})
|
|
886
|
+
})
|
|
887
|
+
}));
|
|
881
888
|
}
|
|
882
889
|
readonlyField(name, { definition }) {
|
|
883
890
|
const newFields = {
|
|
884
|
-
[name]: {
|
|
885
|
-
...definition,
|
|
891
|
+
[name]: __spreadProps(__spreadValues({}, definition), {
|
|
886
892
|
readonly: true
|
|
887
|
-
}
|
|
893
|
+
})
|
|
888
894
|
};
|
|
889
|
-
return new _ObjectTypeDefBuilder({
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
...this.definition.fields,
|
|
893
|
-
...newFields
|
|
894
|
-
}
|
|
895
|
-
});
|
|
895
|
+
return new _ObjectTypeDefBuilder(__spreadProps(__spreadValues({}, this.definition), {
|
|
896
|
+
fields: __spreadValues(__spreadValues({}, this.definition.fields), newFields)
|
|
897
|
+
}));
|
|
896
898
|
}
|
|
897
899
|
optionalField(name, { definition }) {
|
|
898
900
|
const newFields = {
|
|
899
|
-
[name]: {
|
|
900
|
-
...definition
|
|
901
|
-
}
|
|
901
|
+
[name]: __spreadValues({}, definition)
|
|
902
902
|
};
|
|
903
|
-
return new _ObjectTypeDefBuilder({
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
...this.definition.fields,
|
|
907
|
-
...newFields
|
|
908
|
-
}
|
|
909
|
-
});
|
|
903
|
+
return new _ObjectTypeDefBuilder(__spreadProps(__spreadValues({}, this.definition), {
|
|
904
|
+
fields: __spreadValues(__spreadValues({}, this.definition.fields), newFields)
|
|
905
|
+
}));
|
|
910
906
|
}
|
|
911
907
|
readonlyOptionalField(name, { definition }) {
|
|
912
908
|
const newFields = {
|
|
913
|
-
[name]: {
|
|
914
|
-
...definition,
|
|
909
|
+
[name]: __spreadProps(__spreadValues({}, definition), {
|
|
915
910
|
readonly: true
|
|
916
|
-
}
|
|
911
|
+
})
|
|
917
912
|
};
|
|
918
|
-
return new _ObjectTypeDefBuilder({
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
...this.definition.fields,
|
|
922
|
-
...newFields
|
|
923
|
-
}
|
|
924
|
-
});
|
|
913
|
+
return new _ObjectTypeDefBuilder(__spreadProps(__spreadValues({}, this.definition), {
|
|
914
|
+
fields: __spreadValues(__spreadValues({}, this.definition.fields), newFields)
|
|
915
|
+
}));
|
|
925
916
|
}
|
|
926
917
|
};
|
|
927
918
|
var UnionTypeDefBuilder = class _UnionTypeDefBuilder extends TypeDefBuilder {
|
|
@@ -932,14 +923,12 @@ var UnionTypeDefBuilder = class _UnionTypeDefBuilder extends TypeDefBuilder {
|
|
|
932
923
|
unions
|
|
933
924
|
} = this.definition;
|
|
934
925
|
return new _UnionTypeDefBuilder(
|
|
935
|
-
{
|
|
936
|
-
...this.definition,
|
|
926
|
+
__spreadProps(__spreadValues({}, this.definition), {
|
|
937
927
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
938
|
-
unions: {
|
|
939
|
-
...unions,
|
|
928
|
+
unions: __spreadProps(__spreadValues({}, unions), {
|
|
940
929
|
[k]: typeDef
|
|
941
|
-
}
|
|
942
|
-
}
|
|
930
|
+
})
|
|
931
|
+
})
|
|
943
932
|
);
|
|
944
933
|
}
|
|
945
934
|
};
|
|
@@ -1005,7 +994,7 @@ function union(discriminator) {
|
|
|
1005
994
|
{
|
|
1006
995
|
type: 5 /* Union */,
|
|
1007
996
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1008
|
-
discriminator: discriminator
|
|
997
|
+
discriminator: discriminator != null ? discriminator : null,
|
|
1009
998
|
unions: {},
|
|
1010
999
|
rule: emptyRule,
|
|
1011
1000
|
readonly: false,
|
|
@@ -1076,38 +1065,26 @@ var OptionalValidatorProxy = class _OptionalValidatorProxy {
|
|
|
1076
1065
|
return null;
|
|
1077
1066
|
}
|
|
1078
1067
|
annotations(valuePath, context) {
|
|
1079
|
-
return {
|
|
1080
|
-
...this.proxied.annotations(valuePath, context),
|
|
1068
|
+
return __spreadProps(__spreadValues({}, this.proxied.annotations(valuePath, context)), {
|
|
1081
1069
|
required: false
|
|
1082
|
-
};
|
|
1070
|
+
});
|
|
1083
1071
|
}
|
|
1084
1072
|
};
|
|
1085
1073
|
|
|
1086
1074
|
// validation/validators/regexp_validator.ts
|
|
1087
1075
|
var RegexpValidationErrorType = "regexp";
|
|
1088
|
-
var
|
|
1076
|
+
var _RegexpValidator = class _RegexpValidator {
|
|
1089
1077
|
constructor(regexp, intent, {
|
|
1090
1078
|
negate = false,
|
|
1091
1079
|
required = false
|
|
1092
1080
|
} = {}) {
|
|
1093
1081
|
this.regexp = regexp;
|
|
1094
1082
|
this.intent = intent;
|
|
1083
|
+
__publicField(this, "negate");
|
|
1084
|
+
__publicField(this, "required");
|
|
1095
1085
|
this.negate = negate;
|
|
1096
1086
|
this.required = required;
|
|
1097
1087
|
}
|
|
1098
|
-
/**
|
|
1099
|
-
* Extremely permissive email validator
|
|
1100
|
-
*/
|
|
1101
|
-
static email = new _RegexpValidator(/^[^\s@]+@[^\s@]+\.[^\s@]+$/, "email");
|
|
1102
|
-
/**
|
|
1103
|
-
* Extremely permissive phone number validator
|
|
1104
|
-
*/
|
|
1105
|
-
static phone = new _RegexpValidator(
|
|
1106
|
-
/^(\+\d{1,4}[\s]*)?(((\([\d\s-]{1,6}\))|\d)[\s-]*){3,14}(\d|(\(\d+\)))$/,
|
|
1107
|
-
"phone"
|
|
1108
|
-
);
|
|
1109
|
-
negate;
|
|
1110
|
-
required;
|
|
1111
1088
|
validate(value) {
|
|
1112
1089
|
const passes = this.regexp.test(value);
|
|
1113
1090
|
if (!passes && !this.negate || passes && this.negate) {
|
|
@@ -1125,6 +1102,18 @@ var RegexpValidator = class _RegexpValidator {
|
|
|
1125
1102
|
};
|
|
1126
1103
|
}
|
|
1127
1104
|
};
|
|
1105
|
+
/**
|
|
1106
|
+
* Extremely permissive email validator
|
|
1107
|
+
*/
|
|
1108
|
+
__publicField(_RegexpValidator, "email", new _RegexpValidator(/^[^\s@]+@[^\s@]+\.[^\s@]+$/, "email"));
|
|
1109
|
+
/**
|
|
1110
|
+
* Extremely permissive phone number validator
|
|
1111
|
+
*/
|
|
1112
|
+
__publicField(_RegexpValidator, "phone", new _RegexpValidator(
|
|
1113
|
+
/^(\+\d{1,4}[\s]*)?(((\([\d\s-]{1,6}\))|\d)[\s-]*){3,14}(\d|(\(\d+\)))$/,
|
|
1114
|
+
"phone"
|
|
1115
|
+
));
|
|
1116
|
+
var RegexpValidator = _RegexpValidator;
|
|
1128
1117
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1129
1118
|
0 && (module.exports = {
|
|
1130
1119
|
DefinedValidator,
|