@modulify/validator 0.0.1
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/CHANGELOG.md +16 -0
- package/README.md +177 -0
- package/dist/index.cjs +326 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +317 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +60 -0
- package/types/index.d.ts +130 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
+
|
|
5
|
+
### 0.0.1 (2024-02-05)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* Added constraint Each to apply constraints to array entries ([eb0f44f](https://github.com/modulify/validator/commit/eb0f44f722cfbae7493e23b71ef92ddcc3655228))
|
|
11
|
+
* Added exported by src/index.ts members to types/index.d.ts ([cce525b](https://github.com/modulify/validator/commit/cce525bc8c893e4c3c3b6eec6ddcaa7d901aa948))
|
|
12
|
+
* Added Length / OneOf constraint to exported by src/index.ts members ([c152199](https://github.com/modulify/validator/commit/c152199bc470a3b3746b8f2f376063457b86728a))
|
|
13
|
+
* Added meta to ConstraintViolation ([11b9bf0](https://github.com/modulify/validator/commit/11b9bf0df520d7b427b3a6eb19dc8f3ada12cbd8))
|
|
14
|
+
* Added meta to OneOf violation ([8dd59fc](https://github.com/modulify/validator/commit/8dd59fc2663df1e791ad95449ba774374b6e0bf8))
|
|
15
|
+
* Added possibility to override initial valitators set ([0192f44](https://github.com/modulify/validator/commit/0192f44e4e9e487cbc1230cd588ea62d926e7143))
|
|
16
|
+
* Asynchronous validation ([1505f41](https://github.com/modulify/validator/commit/1505f417bd869ba762f6a91d1d30a360d2505ad4))
|
package/README.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# `@modulify/validator`
|
|
2
|
+
|
|
3
|
+
[](https://codecov.io/gh/modulify/validator)
|
|
4
|
+
[](https://github.com/modulify/validator/actions)
|
|
5
|
+
[](https://www.npmjs.com/package/@modulify/validator)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
This library provides a declarative validation util.
|
|
9
|
+
|
|
10
|
+
The util does not provide any text messages in the constraints produced and gives only metadata that can
|
|
11
|
+
be used to create a custom view for them.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
No installation yet
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import {
|
|
21
|
+
Collection,
|
|
22
|
+
Exists,
|
|
23
|
+
Length,
|
|
24
|
+
createValidator,
|
|
25
|
+
} from '@modulify/validator'
|
|
26
|
+
|
|
27
|
+
const validator = createValidator()
|
|
28
|
+
|
|
29
|
+
const violations = validator.validate({
|
|
30
|
+
form: {
|
|
31
|
+
nickname: '',
|
|
32
|
+
password: '',
|
|
33
|
+
},
|
|
34
|
+
}, new Collection({
|
|
35
|
+
form: [
|
|
36
|
+
new Exists(),
|
|
37
|
+
new Collection({
|
|
38
|
+
nickname: new Length({ min: 4 }),
|
|
39
|
+
password: new Length({ min: 6 }),
|
|
40
|
+
}),
|
|
41
|
+
],
|
|
42
|
+
}), /* do not set or set to true for async validation */ false) /* [{
|
|
43
|
+
by: '@modulify/validator/Length',
|
|
44
|
+
value: '',
|
|
45
|
+
path: ['form', 'nickname'],
|
|
46
|
+
reason: 'min',
|
|
47
|
+
meta: 4,
|
|
48
|
+
}, {
|
|
49
|
+
by: '@modulify/validator/Length',
|
|
50
|
+
value: '',
|
|
51
|
+
path: ['form', 'password'],
|
|
52
|
+
reason: 'min',
|
|
53
|
+
meta: 6,
|
|
54
|
+
}] */
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Constraints
|
|
58
|
+
|
|
59
|
+
Constraints provide information of how the value should be validated.
|
|
60
|
+
|
|
61
|
+
Available from the box:
|
|
62
|
+
|
|
63
|
+
* `Collection` – used for validating objects' structure;
|
|
64
|
+
* `Each` – used for validating arrays' elements; applies specified constraints to each element of an array;
|
|
65
|
+
* `Exists` – used for checking if a value is defined; useful for finding missing keys;
|
|
66
|
+
* `Length` – used for checking arrays' and string's length, available settings (all optional) are:
|
|
67
|
+
* `exact` – `number`, array or string should have exactly specified count of elements or characters;
|
|
68
|
+
* `max` – `number`, maximum elements in array or maximum characters in string;
|
|
69
|
+
* `min` – `number`, minimum elements in array or minimum characters in string;
|
|
70
|
+
* `OneOf` – used for restricting which values can be used.
|
|
71
|
+
|
|
72
|
+
There is no any basic constraint class to extend, but they should follow signature
|
|
73
|
+
described in `types/index.d.ts` – `Constraint`.
|
|
74
|
+
|
|
75
|
+
### Validators
|
|
76
|
+
|
|
77
|
+
Validators provide validation logic that relies on information provided by constraints.
|
|
78
|
+
|
|
79
|
+
There is no any basic validator class to extend, but they should follow signature
|
|
80
|
+
described in `types/index.d.ts` – `ConstraintValidator`.
|
|
81
|
+
|
|
82
|
+
### Provider
|
|
83
|
+
|
|
84
|
+
Provider is used to bind constraints with their validators, provides a validator for a constraint.
|
|
85
|
+
|
|
86
|
+
All providers should follow signature described in `types/index.d.ts` – `Provider`.
|
|
87
|
+
|
|
88
|
+
This feature is responsible for extending validation capabilities. Custom provider can be passed into
|
|
89
|
+
`createValidator` function or `override` method of `Validator` instance.
|
|
90
|
+
|
|
91
|
+
There is a built-in provider – `ProviderChain`. It allows to "chain" providers – if
|
|
92
|
+
suitable validator was not found in currently used provider, it will try to find it in previous provider that was
|
|
93
|
+
overridden by `override` method.
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import type {
|
|
97
|
+
Constraint,
|
|
98
|
+
ConstraintValidator,
|
|
99
|
+
ConstraintViolation,
|
|
100
|
+
Key,
|
|
101
|
+
Provider,
|
|
102
|
+
} from '@modulify/validator'
|
|
103
|
+
|
|
104
|
+
import {
|
|
105
|
+
ProviderChain,
|
|
106
|
+
createValidator,
|
|
107
|
+
} from '@modulify/validator'
|
|
108
|
+
|
|
109
|
+
class Email implements Constraint {
|
|
110
|
+
public readonly name = '@app/validator/Email'
|
|
111
|
+
|
|
112
|
+
toViolation (value: unknown, path: Key[]): ConstraintViolation {
|
|
113
|
+
return {
|
|
114
|
+
by: this.name,
|
|
115
|
+
value,
|
|
116
|
+
path,
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
class EmailValidator implements ConstraintValidator {
|
|
122
|
+
private readonly _constraint: Email
|
|
123
|
+
|
|
124
|
+
constructor (constraint: Email) {
|
|
125
|
+
this._constraint = constraint
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
validate (value: unknown, path?: Key[]): ConstraintViolation | null {
|
|
129
|
+
if (!(typeof value === 'string') || !/\S+@\S+\.\S+/.test(value)) {
|
|
130
|
+
return this._constraint.toViolation(value, path)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return null
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
then
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
const provider = new ProviderChain(new class implements Provider {
|
|
142
|
+
get (constraint: Constraint) {
|
|
143
|
+
return constraint instanceof Email ? new EmailValidator(constraint) : null
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
override (provider: Provider): Provider {
|
|
147
|
+
return new ProviderChain(provider, this)
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
or
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
const provider = new class implements Provider {
|
|
156
|
+
get (constraint: Constraint) {
|
|
157
|
+
return constraint instanceof Email ? new EmailValidator(constraint) : null
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
override (provider: Provider): Provider {
|
|
161
|
+
return new ProviderChain(provider, this)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
and then
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
const validator = createValidator(provider)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
or
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
const validator = createValidator()
|
|
176
|
+
const overridden = validator.override(provider) // it creates new validator instance, so validator !== overridden
|
|
177
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/******************************************************************************
|
|
4
|
+
Copyright (c) Microsoft Corporation.
|
|
5
|
+
|
|
6
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
+
purpose with or without fee is hereby granted.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
***************************************************************************** */
|
|
17
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
21
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
22
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
23
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
24
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
25
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
26
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
31
|
+
var e = new Error(message);
|
|
32
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
class Collection {
|
|
36
|
+
constructor(constraints) {
|
|
37
|
+
this.name = '@modulify/validator/Collection';
|
|
38
|
+
this.constraints = constraints;
|
|
39
|
+
}
|
|
40
|
+
reduce(reducer, initial) {
|
|
41
|
+
return Object.keys(this.constraints).reduce((accumulator, key) => {
|
|
42
|
+
return reducer(accumulator, this.constraints[key], key);
|
|
43
|
+
}, initial);
|
|
44
|
+
}
|
|
45
|
+
toViolation(value, path, reason) {
|
|
46
|
+
return {
|
|
47
|
+
by: this.name,
|
|
48
|
+
value,
|
|
49
|
+
path,
|
|
50
|
+
reason,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const arraify = (value) => Array.isArray(value)
|
|
56
|
+
? [...value]
|
|
57
|
+
: [value];
|
|
58
|
+
const flatten = (recursive) => {
|
|
59
|
+
const flattened = [];
|
|
60
|
+
recursive.forEach(element => {
|
|
61
|
+
flattened.push(...(Array.isArray(element)
|
|
62
|
+
? flatten(element)
|
|
63
|
+
: [element]));
|
|
64
|
+
});
|
|
65
|
+
return flattened;
|
|
66
|
+
};
|
|
67
|
+
const constructorOf = (value) => {
|
|
68
|
+
return Object.getPrototypeOf(value).constructor;
|
|
69
|
+
};
|
|
70
|
+
const isRecord = (value) => {
|
|
71
|
+
return constructorOf(value) === Object && Object.keys(Object.getPrototypeOf(value)).length === 0;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
class Each {
|
|
75
|
+
constructor(constraints) {
|
|
76
|
+
this.name = '@modulify/validator/Each';
|
|
77
|
+
this.constraints = arraify(constraints);
|
|
78
|
+
}
|
|
79
|
+
toViolation(value, path, reason) {
|
|
80
|
+
return {
|
|
81
|
+
by: this.name,
|
|
82
|
+
value,
|
|
83
|
+
path,
|
|
84
|
+
reason,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
class Exists {
|
|
90
|
+
constructor() {
|
|
91
|
+
this.name = '@modulify/validator/Exists';
|
|
92
|
+
}
|
|
93
|
+
toViolation(value, path) {
|
|
94
|
+
return {
|
|
95
|
+
by: this.name,
|
|
96
|
+
value,
|
|
97
|
+
path,
|
|
98
|
+
reason: 'undefined',
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
class Length {
|
|
104
|
+
constructor(options) {
|
|
105
|
+
var _a, _b, _c;
|
|
106
|
+
this.name = '@modulify/validator/Length';
|
|
107
|
+
this.exact = (_a = options.exact) !== null && _a !== void 0 ? _a : null;
|
|
108
|
+
this.max = (_b = options.max) !== null && _b !== void 0 ? _b : null;
|
|
109
|
+
this.min = (_c = options.min) !== null && _c !== void 0 ? _c : null;
|
|
110
|
+
}
|
|
111
|
+
toViolation(value, path, reason) {
|
|
112
|
+
return {
|
|
113
|
+
by: this.name,
|
|
114
|
+
value,
|
|
115
|
+
path,
|
|
116
|
+
reason,
|
|
117
|
+
meta: {
|
|
118
|
+
exact: this.exact,
|
|
119
|
+
max: this.max,
|
|
120
|
+
min: this.min,
|
|
121
|
+
}[reason],
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
class OneOf {
|
|
127
|
+
constructor(values, equalTo = (a, b) => a === b) {
|
|
128
|
+
this.name = '@modulify/validator/OneOf';
|
|
129
|
+
this.values = Array.isArray(values) ? values : Object.values(values);
|
|
130
|
+
this.equalTo = equalTo;
|
|
131
|
+
}
|
|
132
|
+
toViolation(value, path) {
|
|
133
|
+
return {
|
|
134
|
+
by: this.name,
|
|
135
|
+
value,
|
|
136
|
+
path,
|
|
137
|
+
meta: this.values,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
class LengthValidator {
|
|
143
|
+
constructor(constraint) {
|
|
144
|
+
this.constraint = constraint;
|
|
145
|
+
}
|
|
146
|
+
validate(value, path = []) {
|
|
147
|
+
const constraint = this.constraint;
|
|
148
|
+
const { exact, max, min } = constraint;
|
|
149
|
+
if (!(typeof value === 'string' || Array.isArray(value))) {
|
|
150
|
+
return constraint.toViolation(value, path, 'unsupported');
|
|
151
|
+
}
|
|
152
|
+
if (exact !== null && exact !== value.length) {
|
|
153
|
+
return constraint.toViolation(value, path, 'exact');
|
|
154
|
+
}
|
|
155
|
+
if (max !== null && value.length > max) {
|
|
156
|
+
return constraint.toViolation(value, path, 'max');
|
|
157
|
+
}
|
|
158
|
+
if (min !== null && value.length < min) {
|
|
159
|
+
return constraint.toViolation(value, path, 'min');
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
class OneOfValidator {
|
|
166
|
+
constructor(constraint) {
|
|
167
|
+
this.constraint = constraint;
|
|
168
|
+
}
|
|
169
|
+
validate(value, path = []) {
|
|
170
|
+
const equalTo = this.constraint.equalTo;
|
|
171
|
+
if (!this.constraint.values.some(allowed => equalTo(allowed, value))) {
|
|
172
|
+
return this.constraint.toViolation(value, path);
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
class ProviderChain {
|
|
179
|
+
constructor(current = null, previous = null) {
|
|
180
|
+
this._current = current;
|
|
181
|
+
this._previous = previous;
|
|
182
|
+
}
|
|
183
|
+
get(constraint) {
|
|
184
|
+
var _a, _b, _c, _d;
|
|
185
|
+
switch (true) {
|
|
186
|
+
case constraint instanceof Length:
|
|
187
|
+
return new LengthValidator(constraint);
|
|
188
|
+
case constraint instanceof OneOf:
|
|
189
|
+
return new OneOfValidator(constraint);
|
|
190
|
+
default:
|
|
191
|
+
return (_d = (_b = (_a = this._current) === null || _a === void 0 ? void 0 : _a.get(constraint)) !== null && _b !== void 0 ? _b : (_c = this._previous) === null || _c === void 0 ? void 0 : _c.get(constraint)) !== null && _d !== void 0 ? _d : null;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
override(provider) {
|
|
195
|
+
return new ProviderChain(provider, this);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const validateAsynchronously = (provider, value, constraints, path = []) => __awaiter(void 0, void 0, void 0, function* () {
|
|
200
|
+
const validations = [];
|
|
201
|
+
for (const c of arraify(constraints)) {
|
|
202
|
+
if (c instanceof Collection) {
|
|
203
|
+
if (isRecord(value)) {
|
|
204
|
+
validations.push(...c.reduce((validations, constraints, key) => {
|
|
205
|
+
return [...validations, validateAsynchronously(provider, value[key], constraints, [...path, key])];
|
|
206
|
+
}, []));
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
validations.push(Promise.resolve([c.toViolation(value, path, 'unsupported')]));
|
|
210
|
+
}
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (c instanceof Each) {
|
|
214
|
+
if (Array.isArray(value)) {
|
|
215
|
+
value.forEach((value, index) => {
|
|
216
|
+
validations.push(validateAsynchronously(provider, value, c.constraints, [...path, index]));
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
validations.push(validateAsynchronously(provider, value, c.constraints, [...path]));
|
|
221
|
+
}
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
if (c instanceof Exists) {
|
|
225
|
+
if (typeof value === 'undefined') {
|
|
226
|
+
validations.push(Promise.resolve([c.toViolation(value, [...path])]));
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
const validator = provider.get(c);
|
|
232
|
+
if (!validator) {
|
|
233
|
+
throw new Error('No validator for constraint ' + c.name);
|
|
234
|
+
}
|
|
235
|
+
const v = validator.validate(value, [...path]);
|
|
236
|
+
if (v) {
|
|
237
|
+
if (v instanceof Promise) {
|
|
238
|
+
validations.push(v.then(v => v ? [v] : []));
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
validations.push(Promise.resolve([v]));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const results = yield Promise.allSettled(validations);
|
|
246
|
+
const violations = [];
|
|
247
|
+
results.forEach(result => {
|
|
248
|
+
if (result.status === 'fulfilled') {
|
|
249
|
+
violations.push(...result.value);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
return violations;
|
|
253
|
+
});
|
|
254
|
+
const validateSynchronously = (provider, value, constraints, path = []) => {
|
|
255
|
+
const violations = [];
|
|
256
|
+
for (const c of arraify(constraints)) {
|
|
257
|
+
if (c instanceof Collection) {
|
|
258
|
+
if (isRecord(value)) {
|
|
259
|
+
violations.push(c.reduce((violations, constraints, key) => {
|
|
260
|
+
return [...violations, ...validateSynchronously(provider, value[key], constraints, [...path, key])];
|
|
261
|
+
}, []));
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
violations.push(c.toViolation(value, path, 'unsupported'));
|
|
265
|
+
}
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
if (c instanceof Each) {
|
|
269
|
+
if (Array.isArray(value)) {
|
|
270
|
+
value.forEach((value, index) => {
|
|
271
|
+
violations.push(...validateSynchronously(provider, value, c.constraints, [...path, index]));
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
violations.push(...validateSynchronously(provider, value, c.constraints, [...path]));
|
|
276
|
+
}
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
if (c instanceof Exists) {
|
|
280
|
+
if (typeof value === 'undefined') {
|
|
281
|
+
violations.push(c.toViolation(value, [...path]));
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
const validator = provider.get(c);
|
|
287
|
+
if (!validator) {
|
|
288
|
+
throw new Error('No validator for constraint ' + c.name);
|
|
289
|
+
}
|
|
290
|
+
const v = validator.validate(value, [...path]);
|
|
291
|
+
if (v) {
|
|
292
|
+
if (v instanceof Promise) {
|
|
293
|
+
throw new Error('Found asynchronous validator for constraint ' + c.name);
|
|
294
|
+
}
|
|
295
|
+
violations.push(v);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return flatten(violations);
|
|
299
|
+
};
|
|
300
|
+
const validate = (provider, value, constraints, path = [], asynchronously = true) => {
|
|
301
|
+
return asynchronously
|
|
302
|
+
? validateAsynchronously(provider, value, constraints, path)
|
|
303
|
+
: validateSynchronously(provider, value, constraints, path);
|
|
304
|
+
};
|
|
305
|
+
class V {
|
|
306
|
+
constructor(provider = null) {
|
|
307
|
+
this._provider = provider !== null && provider !== void 0 ? provider : new ProviderChain();
|
|
308
|
+
}
|
|
309
|
+
override(provider) {
|
|
310
|
+
return new V(this._provider.override(provider));
|
|
311
|
+
}
|
|
312
|
+
validate(value, constraints, asynchronously = true) {
|
|
313
|
+
return validate(this._provider, value, constraints, [], asynchronously);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
const createValidator = (provider = null) => new V(provider);
|
|
317
|
+
|
|
318
|
+
exports.Collection = Collection;
|
|
319
|
+
exports.Each = Each;
|
|
320
|
+
exports.Exists = Exists;
|
|
321
|
+
exports.Length = Length;
|
|
322
|
+
exports.OneOf = OneOf;
|
|
323
|
+
exports.ProviderChain = ProviderChain;
|
|
324
|
+
exports.createValidator = createValidator;
|
|
325
|
+
exports.validate = validate;
|
|
326
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../node_modules/tslib/tslib.es6.js","../src/constraints/Collection.ts","../src/utils.ts","../src/constraints/Each.ts","../src/constraints/Exists.ts","../src/constraints/Length.ts","../src/constraints/OneOf.ts","../src/validators/LengthValidator.ts","../src/validators/OneOfValidator.ts","../src/provider.ts","../src/index.ts"],"sourcesContent":["/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise, SuppressedError, Symbol */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\r\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\r\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\r\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\r\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\r\n var _, done = false;\r\n for (var i = decorators.length - 1; i >= 0; i--) {\r\n var context = {};\r\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\r\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\r\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\r\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\r\n if (kind === \"accessor\") {\r\n if (result === void 0) continue;\r\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\r\n if (_ = accept(result.get)) descriptor.get = _;\r\n if (_ = accept(result.set)) descriptor.set = _;\r\n if (_ = accept(result.init)) initializers.unshift(_);\r\n }\r\n else if (_ = accept(result)) {\r\n if (kind === \"field\") initializers.unshift(_);\r\n else descriptor[key] = _;\r\n }\r\n }\r\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\r\n done = true;\r\n};\r\n\r\nexport function __runInitializers(thisArg, initializers, value) {\r\n var useValue = arguments.length > 2;\r\n for (var i = 0; i < initializers.length; i++) {\r\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\r\n }\r\n return useValue ? value : void 0;\r\n};\r\n\r\nexport function __propKey(x) {\r\n return typeof x === \"symbol\" ? x : \"\".concat(x);\r\n};\r\n\r\nexport function __setFunctionName(f, name, prefix) {\r\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\r\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\r\n};\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n var desc = Object.getOwnPropertyDescriptor(m, k);\r\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\r\n desc = { enumerable: true, get: function() { return m[k]; } };\r\n }\r\n Object.defineProperty(o, k2, desc);\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n\r\nexport function __classPrivateFieldIn(state, receiver) {\r\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\r\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\r\n}\r\n\r\nexport function __addDisposableResource(env, value, async) {\r\n if (value !== null && value !== void 0) {\r\n if (typeof value !== \"object\" && typeof value !== \"function\") throw new TypeError(\"Object expected.\");\r\n var dispose;\r\n if (async) {\r\n if (!Symbol.asyncDispose) throw new TypeError(\"Symbol.asyncDispose is not defined.\");\r\n dispose = value[Symbol.asyncDispose];\r\n }\r\n if (dispose === void 0) {\r\n if (!Symbol.dispose) throw new TypeError(\"Symbol.dispose is not defined.\");\r\n dispose = value[Symbol.dispose];\r\n }\r\n if (typeof dispose !== \"function\") throw new TypeError(\"Object not disposable.\");\r\n env.stack.push({ value: value, dispose: dispose, async: async });\r\n }\r\n else if (async) {\r\n env.stack.push({ async: true });\r\n }\r\n return value;\r\n}\r\n\r\nvar _SuppressedError = typeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\r\n var e = new Error(message);\r\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\r\n};\r\n\r\nexport function __disposeResources(env) {\r\n function fail(e) {\r\n env.error = env.hasError ? new _SuppressedError(e, env.error, \"An error was suppressed during disposal.\") : e;\r\n env.hasError = true;\r\n }\r\n function next() {\r\n while (env.stack.length) {\r\n var rec = env.stack.pop();\r\n try {\r\n var result = rec.dispose && rec.dispose.call(rec.value);\r\n if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });\r\n }\r\n catch (e) {\r\n fail(e);\r\n }\r\n }\r\n if (env.hasError) throw env.error;\r\n }\r\n return next();\r\n}\r\n\r\nexport default {\r\n __extends: __extends,\r\n __assign: __assign,\r\n __rest: __rest,\r\n __decorate: __decorate,\r\n __param: __param,\r\n __metadata: __metadata,\r\n __awaiter: __awaiter,\r\n __generator: __generator,\r\n __createBinding: __createBinding,\r\n __exportStar: __exportStar,\r\n __values: __values,\r\n __read: __read,\r\n __spread: __spread,\r\n __spreadArrays: __spreadArrays,\r\n __spreadArray: __spreadArray,\r\n __await: __await,\r\n __asyncGenerator: __asyncGenerator,\r\n __asyncDelegator: __asyncDelegator,\r\n __asyncValues: __asyncValues,\r\n __makeTemplateObject: __makeTemplateObject,\r\n __importStar: __importStar,\r\n __importDefault: __importDefault,\r\n __classPrivateFieldGet: __classPrivateFieldGet,\r\n __classPrivateFieldSet: __classPrivateFieldSet,\r\n __classPrivateFieldIn: __classPrivateFieldIn,\r\n __addDisposableResource: __addDisposableResource,\r\n __disposeResources: __disposeResources,\r\n};\r\n",null,null,null,null,null,null,null,null,null,null],"names":[],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAkGA;AACO,SAAS,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,SAAS,EAAE;AAC7D,IAAI,SAAS,KAAK,CAAC,KAAK,EAAE,EAAE,OAAO,KAAK,YAAY,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,CAAC,UAAU,OAAO,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;AAChH,IAAI,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,EAAE,UAAU,OAAO,EAAE,MAAM,EAAE;AAC/D,QAAQ,SAAS,SAAS,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;AACnG,QAAQ,SAAS,QAAQ,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,C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
|
+
/******************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
19
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
20
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
21
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
22
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
23
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
24
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
29
|
+
var e = new Error(message);
|
|
30
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
class Collection {
|
|
34
|
+
constructor(constraints) {
|
|
35
|
+
this.name = '@modulify/validator/Collection';
|
|
36
|
+
this.constraints = constraints;
|
|
37
|
+
}
|
|
38
|
+
reduce(reducer, initial) {
|
|
39
|
+
return Object.keys(this.constraints).reduce((accumulator, key) => {
|
|
40
|
+
return reducer(accumulator, this.constraints[key], key);
|
|
41
|
+
}, initial);
|
|
42
|
+
}
|
|
43
|
+
toViolation(value, path, reason) {
|
|
44
|
+
return {
|
|
45
|
+
by: this.name,
|
|
46
|
+
value,
|
|
47
|
+
path,
|
|
48
|
+
reason,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const arraify = (value) => Array.isArray(value)
|
|
54
|
+
? [...value]
|
|
55
|
+
: [value];
|
|
56
|
+
const flatten = (recursive) => {
|
|
57
|
+
const flattened = [];
|
|
58
|
+
recursive.forEach(element => {
|
|
59
|
+
flattened.push(...(Array.isArray(element)
|
|
60
|
+
? flatten(element)
|
|
61
|
+
: [element]));
|
|
62
|
+
});
|
|
63
|
+
return flattened;
|
|
64
|
+
};
|
|
65
|
+
const constructorOf = (value) => {
|
|
66
|
+
return Object.getPrototypeOf(value).constructor;
|
|
67
|
+
};
|
|
68
|
+
const isRecord = (value) => {
|
|
69
|
+
return constructorOf(value) === Object && Object.keys(Object.getPrototypeOf(value)).length === 0;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
class Each {
|
|
73
|
+
constructor(constraints) {
|
|
74
|
+
this.name = '@modulify/validator/Each';
|
|
75
|
+
this.constraints = arraify(constraints);
|
|
76
|
+
}
|
|
77
|
+
toViolation(value, path, reason) {
|
|
78
|
+
return {
|
|
79
|
+
by: this.name,
|
|
80
|
+
value,
|
|
81
|
+
path,
|
|
82
|
+
reason,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
class Exists {
|
|
88
|
+
constructor() {
|
|
89
|
+
this.name = '@modulify/validator/Exists';
|
|
90
|
+
}
|
|
91
|
+
toViolation(value, path) {
|
|
92
|
+
return {
|
|
93
|
+
by: this.name,
|
|
94
|
+
value,
|
|
95
|
+
path,
|
|
96
|
+
reason: 'undefined',
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
class Length {
|
|
102
|
+
constructor(options) {
|
|
103
|
+
var _a, _b, _c;
|
|
104
|
+
this.name = '@modulify/validator/Length';
|
|
105
|
+
this.exact = (_a = options.exact) !== null && _a !== void 0 ? _a : null;
|
|
106
|
+
this.max = (_b = options.max) !== null && _b !== void 0 ? _b : null;
|
|
107
|
+
this.min = (_c = options.min) !== null && _c !== void 0 ? _c : null;
|
|
108
|
+
}
|
|
109
|
+
toViolation(value, path, reason) {
|
|
110
|
+
return {
|
|
111
|
+
by: this.name,
|
|
112
|
+
value,
|
|
113
|
+
path,
|
|
114
|
+
reason,
|
|
115
|
+
meta: {
|
|
116
|
+
exact: this.exact,
|
|
117
|
+
max: this.max,
|
|
118
|
+
min: this.min,
|
|
119
|
+
}[reason],
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
class OneOf {
|
|
125
|
+
constructor(values, equalTo = (a, b) => a === b) {
|
|
126
|
+
this.name = '@modulify/validator/OneOf';
|
|
127
|
+
this.values = Array.isArray(values) ? values : Object.values(values);
|
|
128
|
+
this.equalTo = equalTo;
|
|
129
|
+
}
|
|
130
|
+
toViolation(value, path) {
|
|
131
|
+
return {
|
|
132
|
+
by: this.name,
|
|
133
|
+
value,
|
|
134
|
+
path,
|
|
135
|
+
meta: this.values,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
class LengthValidator {
|
|
141
|
+
constructor(constraint) {
|
|
142
|
+
this.constraint = constraint;
|
|
143
|
+
}
|
|
144
|
+
validate(value, path = []) {
|
|
145
|
+
const constraint = this.constraint;
|
|
146
|
+
const { exact, max, min } = constraint;
|
|
147
|
+
if (!(typeof value === 'string' || Array.isArray(value))) {
|
|
148
|
+
return constraint.toViolation(value, path, 'unsupported');
|
|
149
|
+
}
|
|
150
|
+
if (exact !== null && exact !== value.length) {
|
|
151
|
+
return constraint.toViolation(value, path, 'exact');
|
|
152
|
+
}
|
|
153
|
+
if (max !== null && value.length > max) {
|
|
154
|
+
return constraint.toViolation(value, path, 'max');
|
|
155
|
+
}
|
|
156
|
+
if (min !== null && value.length < min) {
|
|
157
|
+
return constraint.toViolation(value, path, 'min');
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
class OneOfValidator {
|
|
164
|
+
constructor(constraint) {
|
|
165
|
+
this.constraint = constraint;
|
|
166
|
+
}
|
|
167
|
+
validate(value, path = []) {
|
|
168
|
+
const equalTo = this.constraint.equalTo;
|
|
169
|
+
if (!this.constraint.values.some(allowed => equalTo(allowed, value))) {
|
|
170
|
+
return this.constraint.toViolation(value, path);
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
class ProviderChain {
|
|
177
|
+
constructor(current = null, previous = null) {
|
|
178
|
+
this._current = current;
|
|
179
|
+
this._previous = previous;
|
|
180
|
+
}
|
|
181
|
+
get(constraint) {
|
|
182
|
+
var _a, _b, _c, _d;
|
|
183
|
+
switch (true) {
|
|
184
|
+
case constraint instanceof Length:
|
|
185
|
+
return new LengthValidator(constraint);
|
|
186
|
+
case constraint instanceof OneOf:
|
|
187
|
+
return new OneOfValidator(constraint);
|
|
188
|
+
default:
|
|
189
|
+
return (_d = (_b = (_a = this._current) === null || _a === void 0 ? void 0 : _a.get(constraint)) !== null && _b !== void 0 ? _b : (_c = this._previous) === null || _c === void 0 ? void 0 : _c.get(constraint)) !== null && _d !== void 0 ? _d : null;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
override(provider) {
|
|
193
|
+
return new ProviderChain(provider, this);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const validateAsynchronously = (provider, value, constraints, path = []) => __awaiter(void 0, void 0, void 0, function* () {
|
|
198
|
+
const validations = [];
|
|
199
|
+
for (const c of arraify(constraints)) {
|
|
200
|
+
if (c instanceof Collection) {
|
|
201
|
+
if (isRecord(value)) {
|
|
202
|
+
validations.push(...c.reduce((validations, constraints, key) => {
|
|
203
|
+
return [...validations, validateAsynchronously(provider, value[key], constraints, [...path, key])];
|
|
204
|
+
}, []));
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
validations.push(Promise.resolve([c.toViolation(value, path, 'unsupported')]));
|
|
208
|
+
}
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if (c instanceof Each) {
|
|
212
|
+
if (Array.isArray(value)) {
|
|
213
|
+
value.forEach((value, index) => {
|
|
214
|
+
validations.push(validateAsynchronously(provider, value, c.constraints, [...path, index]));
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
validations.push(validateAsynchronously(provider, value, c.constraints, [...path]));
|
|
219
|
+
}
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
if (c instanceof Exists) {
|
|
223
|
+
if (typeof value === 'undefined') {
|
|
224
|
+
validations.push(Promise.resolve([c.toViolation(value, [...path])]));
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
const validator = provider.get(c);
|
|
230
|
+
if (!validator) {
|
|
231
|
+
throw new Error('No validator for constraint ' + c.name);
|
|
232
|
+
}
|
|
233
|
+
const v = validator.validate(value, [...path]);
|
|
234
|
+
if (v) {
|
|
235
|
+
if (v instanceof Promise) {
|
|
236
|
+
validations.push(v.then(v => v ? [v] : []));
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
validations.push(Promise.resolve([v]));
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const results = yield Promise.allSettled(validations);
|
|
244
|
+
const violations = [];
|
|
245
|
+
results.forEach(result => {
|
|
246
|
+
if (result.status === 'fulfilled') {
|
|
247
|
+
violations.push(...result.value);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
return violations;
|
|
251
|
+
});
|
|
252
|
+
const validateSynchronously = (provider, value, constraints, path = []) => {
|
|
253
|
+
const violations = [];
|
|
254
|
+
for (const c of arraify(constraints)) {
|
|
255
|
+
if (c instanceof Collection) {
|
|
256
|
+
if (isRecord(value)) {
|
|
257
|
+
violations.push(c.reduce((violations, constraints, key) => {
|
|
258
|
+
return [...violations, ...validateSynchronously(provider, value[key], constraints, [...path, key])];
|
|
259
|
+
}, []));
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
violations.push(c.toViolation(value, path, 'unsupported'));
|
|
263
|
+
}
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (c instanceof Each) {
|
|
267
|
+
if (Array.isArray(value)) {
|
|
268
|
+
value.forEach((value, index) => {
|
|
269
|
+
violations.push(...validateSynchronously(provider, value, c.constraints, [...path, index]));
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
violations.push(...validateSynchronously(provider, value, c.constraints, [...path]));
|
|
274
|
+
}
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
if (c instanceof Exists) {
|
|
278
|
+
if (typeof value === 'undefined') {
|
|
279
|
+
violations.push(c.toViolation(value, [...path]));
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
const validator = provider.get(c);
|
|
285
|
+
if (!validator) {
|
|
286
|
+
throw new Error('No validator for constraint ' + c.name);
|
|
287
|
+
}
|
|
288
|
+
const v = validator.validate(value, [...path]);
|
|
289
|
+
if (v) {
|
|
290
|
+
if (v instanceof Promise) {
|
|
291
|
+
throw new Error('Found asynchronous validator for constraint ' + c.name);
|
|
292
|
+
}
|
|
293
|
+
violations.push(v);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return flatten(violations);
|
|
297
|
+
};
|
|
298
|
+
const validate = (provider, value, constraints, path = [], asynchronously = true) => {
|
|
299
|
+
return asynchronously
|
|
300
|
+
? validateAsynchronously(provider, value, constraints, path)
|
|
301
|
+
: validateSynchronously(provider, value, constraints, path);
|
|
302
|
+
};
|
|
303
|
+
class V {
|
|
304
|
+
constructor(provider = null) {
|
|
305
|
+
this._provider = provider !== null && provider !== void 0 ? provider : new ProviderChain();
|
|
306
|
+
}
|
|
307
|
+
override(provider) {
|
|
308
|
+
return new V(this._provider.override(provider));
|
|
309
|
+
}
|
|
310
|
+
validate(value, constraints, asynchronously = true) {
|
|
311
|
+
return validate(this._provider, value, constraints, [], asynchronously);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
const createValidator = (provider = null) => new V(provider);
|
|
315
|
+
|
|
316
|
+
export { Collection, Each, Exists, Length, OneOf, ProviderChain, createValidator, validate };
|
|
317
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../node_modules/tslib/tslib.es6.js","../src/constraints/Collection.ts","../src/utils.ts","../src/constraints/Each.ts","../src/constraints/Exists.ts","../src/constraints/Length.ts","../src/constraints/OneOf.ts","../src/validators/LengthValidator.ts","../src/validators/OneOfValidator.ts","../src/provider.ts","../src/index.ts"],"sourcesContent":["/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise, SuppressedError, Symbol */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\r\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\r\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\r\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\r\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\r\n var _, done = false;\r\n for (var i = decorators.length - 1; i >= 0; i--) {\r\n var context = {};\r\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\r\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\r\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\r\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\r\n if (kind === \"accessor\") {\r\n if (result === void 0) continue;\r\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\r\n if (_ = accept(result.get)) descriptor.get = _;\r\n if (_ = accept(result.set)) descriptor.set = _;\r\n if (_ = accept(result.init)) initializers.unshift(_);\r\n }\r\n else if (_ = accept(result)) {\r\n if (kind === \"field\") initializers.unshift(_);\r\n else descriptor[key] = _;\r\n }\r\n }\r\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\r\n done = true;\r\n};\r\n\r\nexport function __runInitializers(thisArg, initializers, value) {\r\n var useValue = arguments.length > 2;\r\n for (var i = 0; i < initializers.length; i++) {\r\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\r\n }\r\n return useValue ? value : void 0;\r\n};\r\n\r\nexport function __propKey(x) {\r\n return typeof x === \"symbol\" ? x : \"\".concat(x);\r\n};\r\n\r\nexport function __setFunctionName(f, name, prefix) {\r\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\r\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\r\n};\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n var desc = Object.getOwnPropertyDescriptor(m, k);\r\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\r\n desc = { enumerable: true, get: function() { return m[k]; } };\r\n }\r\n Object.defineProperty(o, k2, desc);\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n\r\nexport function __classPrivateFieldIn(state, receiver) {\r\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\r\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\r\n}\r\n\r\nexport function __addDisposableResource(env, value, async) {\r\n if (value !== null && value !== void 0) {\r\n if (typeof value !== \"object\" && typeof value !== \"function\") throw new TypeError(\"Object expected.\");\r\n var dispose;\r\n if (async) {\r\n if (!Symbol.asyncDispose) throw new TypeError(\"Symbol.asyncDispose is not defined.\");\r\n dispose = value[Symbol.asyncDispose];\r\n }\r\n if (dispose === void 0) {\r\n if (!Symbol.dispose) throw new TypeError(\"Symbol.dispose is not defined.\");\r\n dispose = value[Symbol.dispose];\r\n }\r\n if (typeof dispose !== \"function\") throw new TypeError(\"Object not disposable.\");\r\n env.stack.push({ value: value, dispose: dispose, async: async });\r\n }\r\n else if (async) {\r\n env.stack.push({ async: true });\r\n }\r\n return value;\r\n}\r\n\r\nvar _SuppressedError = typeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\r\n var e = new Error(message);\r\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\r\n};\r\n\r\nexport function __disposeResources(env) {\r\n function fail(e) {\r\n env.error = env.hasError ? new _SuppressedError(e, env.error, \"An error was suppressed during disposal.\") : e;\r\n env.hasError = true;\r\n }\r\n function next() {\r\n while (env.stack.length) {\r\n var rec = env.stack.pop();\r\n try {\r\n var result = rec.dispose && rec.dispose.call(rec.value);\r\n if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });\r\n }\r\n catch (e) {\r\n fail(e);\r\n }\r\n }\r\n if (env.hasError) throw env.error;\r\n }\r\n return next();\r\n}\r\n\r\nexport default {\r\n __extends: __extends,\r\n __assign: __assign,\r\n __rest: __rest,\r\n __decorate: __decorate,\r\n __param: __param,\r\n __metadata: __metadata,\r\n __awaiter: __awaiter,\r\n __generator: __generator,\r\n __createBinding: __createBinding,\r\n __exportStar: __exportStar,\r\n __values: __values,\r\n __read: __read,\r\n __spread: __spread,\r\n __spreadArrays: __spreadArrays,\r\n __spreadArray: __spreadArray,\r\n __await: __await,\r\n __asyncGenerator: __asyncGenerator,\r\n __asyncDelegator: __asyncDelegator,\r\n __asyncValues: __asyncValues,\r\n __makeTemplateObject: __makeTemplateObject,\r\n __importStar: __importStar,\r\n __importDefault: __importDefault,\r\n __classPrivateFieldGet: __classPrivateFieldGet,\r\n __classPrivateFieldSet: __classPrivateFieldSet,\r\n __classPrivateFieldIn: __classPrivateFieldIn,\r\n __addDisposableResource: __addDisposableResource,\r\n __disposeResources: __disposeResources,\r\n};\r\n",null,null,null,null,null,null,null,null,null,null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAkGA;AACO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,CAAwD,CAAA;AACtH,EAAC;AAED,MAAM,CAAC,CAAA;AAGL,IAAA,WAAA,CAAa,WAA4B,IAAI,EAAA;AAC3C,QAAA,IAAI,CAAC,SAAS,GAAG,QAAQ,KAAR,IAAA,IAAA,QAAQ,KAAR,KAAA,CAAA,GAAA,QAAQ,GAAI,IAAI,aAAa,EAAE,CAAA;KACjD;AAED,IAAA,QAAQ,CAAE,QAAkB,EAAA;AAC1B,QAAA,OAAO,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAA;KAChD;AAED,IAAA,QAAQ,CACN,KAAY,EACZ,WAAoD,EACpD,iBAAiC,IAAsB,EAAA;AAEvD,QAAA,OAAO,QAAQ,CACb,IAAI,CAAC,SAAS,EACd,KAAK,EACL,WAAW,EACX,EAAE,EACF,cAAc,CACf,CAAA;KACF;AACF,CAAA;AAED,MAAM,eAAe,GAAG,CACtB,QAAA,GAA4B,IAAI,KAClB,IAAI,CAAC,CAAC,QAAQ;;;;","x_google_ignoreList":[0]}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@modulify/validator",
|
|
3
|
+
"description": "Declarative validation util for JavaScript",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"version": "0.0.1",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.mjs",
|
|
8
|
+
"types": "types/index.d.ts",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "rollup --config rollup.config.ts --configPlugin typescript",
|
|
11
|
+
"lint": "eslint --ext .js,.mjs,.ts src tests types",
|
|
12
|
+
"prepare": "husky",
|
|
13
|
+
"release": "standard-version",
|
|
14
|
+
"release:minor": "standard-version --release-as minor",
|
|
15
|
+
"release:patch": "standard-version --release-as patch",
|
|
16
|
+
"release:major": "standard-version --release-as major",
|
|
17
|
+
"test": "jest --config jest.config.ts",
|
|
18
|
+
"test:coverage": "jest --config jest.config.ts --coverage --coverageReporters=lcov"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@commitlint/cli": "^17.7.1",
|
|
22
|
+
"@commitlint/config-conventional": "^17.7.0",
|
|
23
|
+
"@jest/types": "^29.6.3",
|
|
24
|
+
"@rollup/plugin-alias": "^5.1.0",
|
|
25
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
26
|
+
"@types/node": "^18.15 || ^20.11",
|
|
27
|
+
"@typescript-eslint/eslint-plugin": "^6.19.1",
|
|
28
|
+
"@typescript-eslint/parser": "^6.19.1",
|
|
29
|
+
"eslint": "^8.56.0",
|
|
30
|
+
"husky": "^9.0.10",
|
|
31
|
+
"jest": "^29.7.0",
|
|
32
|
+
"rollup": "^4.9.6",
|
|
33
|
+
"rollup-plugin-delete": "^2.0.0",
|
|
34
|
+
"standard-version": "^9.5.0",
|
|
35
|
+
"ts-jest": "^29.1.2",
|
|
36
|
+
"ts-node": "^10.9.2",
|
|
37
|
+
"tslib": "^2.6.2",
|
|
38
|
+
"typescript": "^5.3.3"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"validate",
|
|
45
|
+
"validator"
|
|
46
|
+
],
|
|
47
|
+
"contributors": [
|
|
48
|
+
"Zaitsev Kirill <zaytsev.cmath10@gmail.com>"
|
|
49
|
+
],
|
|
50
|
+
"homepage": "https://github.com/modulify/validator",
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "https://github.com/modulify/validator.git"
|
|
54
|
+
},
|
|
55
|
+
"husky": {
|
|
56
|
+
"hooks": {
|
|
57
|
+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export type Key = number | string | symbol
|
|
2
|
+
export type Recursive<T> = T | Recursive<T>[]
|
|
3
|
+
|
|
4
|
+
export interface ConstraintViolation<Value = unknown, Meta = unknown> {
|
|
5
|
+
by: string | symbol;
|
|
6
|
+
value: Value;
|
|
7
|
+
/** Path to a property, if a constraint is used as part of a `Collection` for checking some object's structure */
|
|
8
|
+
path?: Key[];
|
|
9
|
+
reason?: string | symbol;
|
|
10
|
+
meta?: Meta;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface Constraint<Value = unknown> {
|
|
14
|
+
name: string;
|
|
15
|
+
toViolation (value: Value, path: Key[], reason?: string): ConstraintViolation<Value>
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type ConstraintCollection<T> = {
|
|
19
|
+
[P in keyof T]: Constraint<T[P]> | Constraint<T[P]>[]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Works only with a specific constraint
|
|
24
|
+
*/
|
|
25
|
+
export interface ConstraintValidator<Value = unknown> {
|
|
26
|
+
validate (value: Value, path?: Key[]): ConstraintViolation<Value> | null | Promise<ConstraintViolation<Value> | null>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Used by Validator|FunctionalValidator to determine, how a specific constraint should be validated.
|
|
31
|
+
*/
|
|
32
|
+
export interface Provider {
|
|
33
|
+
get (constraint: Constraint): ConstraintValidator | null;
|
|
34
|
+
override (provider: Provider): Provider;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type MaybePromise<
|
|
38
|
+
Value,
|
|
39
|
+
Asynchronously extends boolean = true
|
|
40
|
+
> = Asynchronously extends true ? Promise<Value> : Value
|
|
41
|
+
|
|
42
|
+
export type FunctionalValidator = <Value, Asynchronously extends boolean = true>(
|
|
43
|
+
provider: Provider,
|
|
44
|
+
value: Value,
|
|
45
|
+
constraints: Constraint<Value> | Constraint<Value>[],
|
|
46
|
+
path?: Key[],
|
|
47
|
+
asynchronously?: Asynchronously
|
|
48
|
+
) => MaybePromise<ConstraintViolation[], Asynchronously>
|
|
49
|
+
|
|
50
|
+
export interface Validator {
|
|
51
|
+
override (provider: Provider): Validator;
|
|
52
|
+
|
|
53
|
+
validate<Value, Asynchronously extends boolean = true>(
|
|
54
|
+
value: Value,
|
|
55
|
+
constraints: Constraint<Value> | Constraint<Value>[],
|
|
56
|
+
asynchronously?: Asynchronously
|
|
57
|
+
): MaybePromise<ConstraintViolation[], Asynchronously>
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export declare class Collection<T = Record<string, unknown>> implements Constraint<T> {
|
|
61
|
+
public readonly name = '@modulify/validator/Collection'
|
|
62
|
+
public readonly constraints: ConstraintCollection<T>
|
|
63
|
+
|
|
64
|
+
constructor (constraints: ConstraintCollection<T>);
|
|
65
|
+
|
|
66
|
+
toViolation (value: T, path: Key[], reason: string): ConstraintViolation<T>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* If the value should be defined. Interrupts validation of a value, if it produces a violation
|
|
71
|
+
*/
|
|
72
|
+
export declare class Exists implements Constraint {
|
|
73
|
+
public readonly name = '@modulify/validator/Exists'
|
|
74
|
+
|
|
75
|
+
toViolation (value: unknown, path: Key[]): ConstraintViolation;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export declare class Length<Value = unknown> implements Constraint<Value> {
|
|
79
|
+
public readonly name = '@modulify/validator/Length'
|
|
80
|
+
|
|
81
|
+
public readonly exact: number | null
|
|
82
|
+
public readonly max: number | null
|
|
83
|
+
public readonly min: number | null
|
|
84
|
+
|
|
85
|
+
constructor (options: {
|
|
86
|
+
exact?: number
|
|
87
|
+
max?: number
|
|
88
|
+
min?: number
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
toViolation (
|
|
92
|
+
value: Value,
|
|
93
|
+
path: Key[],
|
|
94
|
+
reason: 'exact' | 'max' | 'min' | 'unsupported'
|
|
95
|
+
): ConstraintViolation<Value, number>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
type EqualPredicate<Expected> = (a: Expected, b: unknown) => boolean
|
|
99
|
+
|
|
100
|
+
export declare class OneOf<Expected = unknown, Actual = unknown> implements Constraint<Actual> {
|
|
101
|
+
public readonly name = '@modulify/validator/OneOf'
|
|
102
|
+
public readonly values: Expected[]
|
|
103
|
+
public readonly equalTo: EqualPredicate<Expected>
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @param values Array of allowed values
|
|
107
|
+
* @param equalTo Defaults to strict comparison via `===`
|
|
108
|
+
*/
|
|
109
|
+
constructor (
|
|
110
|
+
values: Expected[] | Record<string, Expected>,
|
|
111
|
+
equalTo?: EqualPredicate<Expected>
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
toViolation (value: Actual, path: Key[]): ConstraintViolation<Actual>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export declare class ProviderChain implements Provider {
|
|
118
|
+
constructor (
|
|
119
|
+
current?: Provider | null,
|
|
120
|
+
previous?: Provider | null
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
get (constraint: Constraint): ConstraintValidator | null;
|
|
124
|
+
|
|
125
|
+
override (provider: Provider): Provider;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export declare const createValidator: (provider?: Provider | null) => Validator;
|
|
129
|
+
|
|
130
|
+
export declare const validate: FunctionalValidator;
|