@contember/schema-utils 1.1.0-alpha.5 → 1.1.0-alpha.8
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/dist/src/acl/AllowAllPermissionFactory.d.ts.map +1 -1
- package/dist/src/acl/AllowAllPermissionFactory.js.map +1 -1
- package/dist/src/acl/index.js +5 -1
- package/dist/src/acl/index.js.map +1 -1
- package/dist/src/dataUtils.d.ts +2 -2
- package/dist/src/dataUtils.d.ts.map +1 -1
- package/dist/src/dataUtils.js +1 -1
- package/dist/src/dataUtils.js.map +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +25 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/model/NamingHelper.d.ts +1 -1
- package/dist/src/model/NamingHelper.d.ts.map +1 -1
- package/dist/src/model/NamingHelper.js.map +1 -1
- package/dist/src/model/index.js +5 -1
- package/dist/src/model/index.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/src/type-schema/acl.d.ts +10 -0
- package/dist/src/type-schema/acl.d.ts.map +1 -0
- package/dist/src/type-schema/acl.js +90 -0
- package/dist/src/type-schema/acl.js.map +1 -0
- package/dist/src/type-schema/index.d.ts +4 -0
- package/dist/src/type-schema/index.d.ts.map +1 -0
- package/dist/src/type-schema/index.js +20 -0
- package/dist/src/type-schema/index.js.map +1 -0
- package/dist/src/type-schema/model.d.ts +30 -0
- package/dist/src/type-schema/model.d.ts.map +1 -0
- package/dist/src/type-schema/model.js +148 -0
- package/dist/src/type-schema/model.js.map +1 -0
- package/dist/src/type-schema/validation.d.ts +15 -0
- package/dist/src/type-schema/validation.d.ts.map +1 -0
- package/dist/src/type-schema/validation.js +95 -0
- package/dist/src/type-schema/validation.js.map +1 -0
- package/dist/src/utils/index.js +5 -1
- package/dist/src/utils/index.js.map +1 -1
- package/dist/src/validation/AclValidator.d.ts +1 -2
- package/dist/src/validation/AclValidator.d.ts.map +1 -1
- package/dist/src/validation/AclValidator.js +22 -197
- package/dist/src/validation/AclValidator.js.map +1 -1
- package/dist/src/validation/ModelValidator.d.ts +1 -1
- package/dist/src/validation/ModelValidator.d.ts.map +1 -1
- package/dist/src/validation/ModelValidator.js +48 -219
- package/dist/src/validation/ModelValidator.js.map +1 -1
- package/dist/src/validation/SchemaValidator.d.ts.map +1 -1
- package/dist/src/validation/SchemaValidator.js +5 -19
- package/dist/src/validation/SchemaValidator.js.map +1 -1
- package/dist/src/validation/ValidationValidator.d.ts +1 -3
- package/dist/src/validation/ValidationValidator.d.ts.map +1 -1
- package/dist/src/validation/ValidationValidator.js +28 -201
- package/dist/src/validation/ValidationValidator.js.map +1 -1
- package/dist/src/validation/index.d.ts +2 -0
- package/dist/src/validation/index.d.ts.map +1 -1
- package/dist/src/validation/index.js +7 -1
- package/dist/src/validation/index.js.map +1 -1
- package/package.json +3 -2
- package/src/acl/AllowAllPermissionFactory.ts +2 -2
- package/src/dataUtils.ts +3 -3
- package/src/index.ts +8 -0
- package/src/model/NamingHelper.ts +1 -1
- package/src/tsconfig.json +3 -0
- package/src/type-schema/acl.ts +105 -0
- package/src/type-schema/index.ts +3 -0
- package/src/type-schema/model.ts +173 -0
- package/src/type-schema/validation.ts +100 -0
- package/src/validation/AclValidator.ts +42 -239
- package/src/validation/ModelValidator.ts +63 -263
- package/src/validation/SchemaValidator.ts +6 -21
- package/src/validation/ValidationValidator.ts +41 -222
- package/src/validation/index.ts +2 -0
- package/dist/src/validation/utils.d.ts +0 -18
- package/dist/src/validation/utils.d.ts.map +0 -1
- package/dist/src/validation/utils.js +0 -36
- package/dist/src/validation/utils.js.map +0 -1
- package/src/validation/utils.ts +0 -45
|
@@ -1,84 +1,57 @@
|
|
|
1
1
|
import { Model, Validation } from '@contember/schema'
|
|
2
2
|
import { ErrorBuilder, ValidationError } from './errors'
|
|
3
|
-
import { everyIs, hasArrayProperty, hasStringProperty, isArray, isObject } from './utils'
|
|
4
3
|
import { acceptFieldVisitor } from '../model'
|
|
5
4
|
|
|
6
5
|
export class ValidationValidator {
|
|
7
6
|
constructor(private readonly model: Model.Schema) {}
|
|
8
7
|
|
|
9
|
-
public validate(schema:
|
|
8
|
+
public validate(schema: Validation.Schema): ValidationError[] {
|
|
10
9
|
const errorBuilder = new ErrorBuilder([], ['validation'])
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
errorBuilder.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const entity = this.model.entities[entityName]
|
|
19
|
-
const entityErrorBuilder = errorBuilder.for(entityName)
|
|
20
|
-
if (!entity) {
|
|
21
|
-
entityErrorBuilder.add('Entity not found')
|
|
22
|
-
} else {
|
|
23
|
-
validSchema[entityName] = this.validateEntityRules(entityErrorBuilder, schema[entityName], entity)
|
|
24
|
-
}
|
|
10
|
+
for (const entityName in schema) {
|
|
11
|
+
const entity = this.model.entities[entityName]
|
|
12
|
+
const entityErrorBuilder = errorBuilder.for(entityName)
|
|
13
|
+
if (!entity) {
|
|
14
|
+
entityErrorBuilder.add('Entity not found')
|
|
15
|
+
} else {
|
|
16
|
+
this.validateEntityRules(entityErrorBuilder, schema[entityName], entity)
|
|
25
17
|
}
|
|
26
18
|
}
|
|
27
|
-
return
|
|
19
|
+
return errorBuilder.errors
|
|
28
20
|
}
|
|
29
21
|
|
|
30
22
|
private validateEntityRules(
|
|
31
23
|
errorBuilder: ErrorBuilder,
|
|
32
|
-
entitySchema:
|
|
24
|
+
entitySchema: Validation.EntityRules,
|
|
33
25
|
entity: Model.Entity,
|
|
34
|
-
):
|
|
35
|
-
if (!isObject(entitySchema)) {
|
|
36
|
-
errorBuilder.add('Must be an object')
|
|
37
|
-
return {}
|
|
38
|
-
}
|
|
39
|
-
const validRules: Validation.EntityRules = {}
|
|
26
|
+
): void {
|
|
40
27
|
for (const fieldName in entitySchema) {
|
|
41
28
|
const field = entity.fields[fieldName]
|
|
42
29
|
const fieldErrorBuilder = errorBuilder.for(fieldName)
|
|
43
30
|
if (!field) {
|
|
44
31
|
fieldErrorBuilder.add('Field not found')
|
|
45
32
|
} else {
|
|
46
|
-
|
|
33
|
+
this.validateFieldRules(fieldErrorBuilder, entitySchema[fieldName], entity, field)
|
|
47
34
|
}
|
|
48
35
|
}
|
|
49
|
-
return validRules
|
|
50
36
|
}
|
|
51
37
|
|
|
52
38
|
private validateFieldRules(
|
|
53
39
|
errorBuilder: ErrorBuilder,
|
|
54
|
-
fieldSchema:
|
|
40
|
+
fieldSchema: readonly Validation.ValidationRule[],
|
|
55
41
|
entity: Model.Entity,
|
|
56
42
|
field: Model.AnyField,
|
|
57
|
-
):
|
|
58
|
-
if (!isArray(fieldSchema)) {
|
|
59
|
-
errorBuilder.add('Must be an array')
|
|
60
|
-
return []
|
|
61
|
-
}
|
|
62
|
-
const validRules = []
|
|
43
|
+
): void {
|
|
63
44
|
for (const i in fieldSchema) {
|
|
64
|
-
|
|
65
|
-
if (rule !== undefined) {
|
|
66
|
-
validRules.push(rule)
|
|
67
|
-
}
|
|
45
|
+
this.validateFieldRule(errorBuilder.for(i), fieldSchema[i], entity, field)
|
|
68
46
|
}
|
|
69
|
-
return validRules
|
|
70
47
|
}
|
|
71
48
|
|
|
72
49
|
private validateFieldRule(
|
|
73
50
|
errorBuilder: ErrorBuilder,
|
|
74
|
-
rule:
|
|
51
|
+
rule: Validation.ValidationRule,
|
|
75
52
|
entity: Model.Entity,
|
|
76
53
|
field: Model.AnyField,
|
|
77
|
-
):
|
|
78
|
-
if (!isObject(rule)) {
|
|
79
|
-
errorBuilder.add('Must be an object')
|
|
80
|
-
return undefined
|
|
81
|
-
}
|
|
54
|
+
): void {
|
|
82
55
|
const errorMessage = acceptFieldVisitor(this.model, entity, field, {
|
|
83
56
|
visitColumn: () => null,
|
|
84
57
|
visitHasOne: () => null,
|
|
@@ -87,173 +60,65 @@ export class ValidationValidator {
|
|
|
87
60
|
},
|
|
88
61
|
})
|
|
89
62
|
if (errorMessage) {
|
|
90
|
-
errorBuilder.add(errorMessage)
|
|
91
|
-
return undefined
|
|
92
|
-
}
|
|
93
|
-
const validMessage = this.validateFieldRuleMessage(errorBuilder.for('message'), rule.message)
|
|
94
|
-
if (!validMessage) {
|
|
95
|
-
return undefined
|
|
63
|
+
return errorBuilder.add(errorMessage)
|
|
96
64
|
}
|
|
97
|
-
|
|
98
|
-
const validValidator = this.validateValidator(errorBuilder.for('validator'), rule.validator, entity, field)
|
|
99
|
-
if (!validValidator) {
|
|
100
|
-
return undefined
|
|
101
|
-
}
|
|
102
|
-
return { message: validMessage, validator: validValidator }
|
|
65
|
+
this.validateValidator(errorBuilder.for('validator'), rule.validator, entity, field)
|
|
103
66
|
}
|
|
104
67
|
|
|
105
|
-
private validateFieldRuleMessage(errorBuilder: ErrorBuilder, message: unknown): Validation.Message | undefined {
|
|
106
|
-
if (!isObject(message)) {
|
|
107
|
-
errorBuilder.add('Must be an object')
|
|
108
|
-
return undefined
|
|
109
|
-
}
|
|
110
|
-
if (!hasStringProperty(message, 'text')) {
|
|
111
|
-
errorBuilder.for('text').add('Must be a string')
|
|
112
|
-
return undefined
|
|
113
|
-
}
|
|
114
|
-
let validMessage: Validation.Message = { text: message.text }
|
|
115
|
-
if (message.parameters) {
|
|
116
|
-
if (!hasArrayProperty(message, 'parameters')) {
|
|
117
|
-
errorBuilder.for('parameters').add('Must be an array')
|
|
118
|
-
return undefined
|
|
119
|
-
}
|
|
120
|
-
validMessage.parameters = message.parameters as string[]
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return validMessage
|
|
124
|
-
}
|
|
125
68
|
|
|
126
69
|
private validateValidator(
|
|
127
70
|
errorBuilder: ErrorBuilder,
|
|
128
|
-
validator:
|
|
71
|
+
validator: Validation.Validator,
|
|
129
72
|
entity: Model.Entity,
|
|
130
73
|
field: Model.AnyField,
|
|
131
|
-
):
|
|
132
|
-
if (!isObject(validator)) {
|
|
133
|
-
errorBuilder.add('Must be an object')
|
|
134
|
-
return undefined
|
|
135
|
-
}
|
|
74
|
+
): void {
|
|
136
75
|
const validatorCast = validator as Validation.Validator
|
|
137
76
|
switch (validatorCast.operation) {
|
|
138
77
|
case 'and':
|
|
139
|
-
const andArgs = validatorCast.args
|
|
140
|
-
.map((it, index) => this.validateValidatorArgument(errorBuilder.for(String(index)), it, entity, field))
|
|
141
|
-
.filter((it): it is Validation.ValidatorArgument => it !== undefined)
|
|
142
|
-
return { operation: 'and' as const, args: andArgs }
|
|
143
78
|
case 'or':
|
|
144
|
-
|
|
145
|
-
.
|
|
146
|
-
.filter((it): it is Validation.ValidatorArgument => it !== undefined)
|
|
147
|
-
return { operation: 'or' as const, args: orArgs }
|
|
79
|
+
return validatorCast.args
|
|
80
|
+
.forEach((it, index) => this.validateValidatorArgument(errorBuilder.for(String(index)), it, entity, field))
|
|
148
81
|
case 'conditional':
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return undefined
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return { operation: 'conditional', args: [argA, argB] }
|
|
82
|
+
this.validateValidatorArgument(errorBuilder.for('condition'), validatorCast.args[0], entity, field)
|
|
83
|
+
this.validateValidatorArgument(errorBuilder.for('rule'), validatorCast.args[1], entity, field)
|
|
84
|
+
return
|
|
156
85
|
case 'pattern':
|
|
157
|
-
const patternLiteral = this.validateLiteralArgument(errorBuilder, validatorCast.args[0])
|
|
158
|
-
if (!patternLiteral) {
|
|
159
|
-
return undefined
|
|
160
|
-
}
|
|
161
|
-
if (
|
|
162
|
-
!isArray(patternLiteral.value) ||
|
|
163
|
-
patternLiteral.value.length !== 2 ||
|
|
164
|
-
typeof patternLiteral.value[0] !== 'string' ||
|
|
165
|
-
typeof patternLiteral.value[1] !== 'string'
|
|
166
|
-
) {
|
|
167
|
-
errorBuilder.add('Invalid pattern value')
|
|
168
|
-
return undefined
|
|
169
|
-
}
|
|
170
|
-
return { operation: 'pattern', args: [patternLiteral as Validation.LiteralArgument<[string, string]>] }
|
|
171
86
|
case 'lengthRange':
|
|
172
|
-
const lengthArgA = this.validateLiteralArgument(errorBuilder.for('min'), validatorCast.args[0])
|
|
173
|
-
const lengthArgB = this.validateLiteralArgument(errorBuilder.for('max'), validatorCast.args[1])
|
|
174
|
-
if (lengthArgA === undefined || lengthArgB === undefined) {
|
|
175
|
-
return undefined
|
|
176
|
-
}
|
|
177
|
-
return {
|
|
178
|
-
operation: 'lengthRange',
|
|
179
|
-
args: [lengthArgA as Validation.LiteralArgument<number>, lengthArgB as Validation.LiteralArgument<number>],
|
|
180
|
-
}
|
|
181
87
|
case 'range':
|
|
182
|
-
const rangeArgA = this.validateLiteralArgument(errorBuilder.for('min'), validatorCast.args[0])
|
|
183
|
-
const rangeArgB = this.validateLiteralArgument(errorBuilder.for('max'), validatorCast.args[1])
|
|
184
|
-
if (rangeArgA === undefined || rangeArgB === undefined) {
|
|
185
|
-
return undefined
|
|
186
|
-
}
|
|
187
|
-
return {
|
|
188
|
-
operation: 'range',
|
|
189
|
-
args: [rangeArgA as Validation.LiteralArgument<number>, rangeArgB as Validation.LiteralArgument<number>],
|
|
190
|
-
}
|
|
191
88
|
case 'equals':
|
|
192
|
-
const eqArg = this.validateLiteralArgument(errorBuilder, validatorCast.args[0])
|
|
193
|
-
if (eqArg === undefined) {
|
|
194
|
-
return undefined
|
|
195
|
-
}
|
|
196
|
-
return {
|
|
197
|
-
operation: 'equals',
|
|
198
|
-
args: [eqArg],
|
|
199
|
-
}
|
|
200
|
-
case 'not':
|
|
201
|
-
const notArg = this.validateValidatorArgument(errorBuilder, validatorCast.args[0], entity, field)
|
|
202
|
-
if (notArg === undefined) {
|
|
203
|
-
return undefined
|
|
204
|
-
}
|
|
205
|
-
return { operation: 'not', args: [notArg] }
|
|
206
89
|
case 'empty':
|
|
207
|
-
return { operation: 'empty', args: [] }
|
|
208
90
|
case 'defined':
|
|
209
|
-
return
|
|
91
|
+
return
|
|
92
|
+
case 'not':
|
|
93
|
+
return this.validateValidatorArgument(errorBuilder, validatorCast.args[0], entity, field)
|
|
210
94
|
case 'inContext':
|
|
211
95
|
const pathArgResult = this.validatePathArgument(errorBuilder.for('path'), validatorCast.args[0], entity)
|
|
212
96
|
if (pathArgResult === undefined) {
|
|
213
97
|
return undefined
|
|
214
98
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const inValidatorArg = this.validateValidatorArgument(
|
|
99
|
+
return this.validateValidatorArgument(
|
|
218
100
|
errorBuilder.for('validator'),
|
|
219
101
|
validatorCast.args[1],
|
|
220
102
|
entity,
|
|
221
|
-
|
|
103
|
+
pathArgResult,
|
|
222
104
|
)
|
|
223
|
-
if (inValidatorArg === undefined) {
|
|
224
|
-
return undefined
|
|
225
|
-
}
|
|
226
|
-
return { operation: 'inContext', args: [pathArg, inValidatorArg] }
|
|
227
105
|
case 'every':
|
|
228
|
-
const everyArg = this.validateValidatorArgument(errorBuilder, validatorCast.args[0], entity, field)
|
|
229
|
-
if (everyArg === undefined) {
|
|
230
|
-
return undefined
|
|
231
|
-
}
|
|
232
|
-
return { operation: 'every', args: [everyArg] }
|
|
233
106
|
case 'any':
|
|
234
|
-
|
|
235
|
-
if (anyArg === undefined) {
|
|
236
|
-
return undefined
|
|
237
|
-
}
|
|
238
|
-
return { operation: 'any', args: [anyArg] }
|
|
107
|
+
return this.validateValidatorArgument(errorBuilder, validatorCast.args[0], entity, field)
|
|
239
108
|
case 'filter':
|
|
240
|
-
|
|
109
|
+
this.validateValidatorArgument(
|
|
241
110
|
errorBuilder.for('filter'),
|
|
242
111
|
validatorCast.args[0],
|
|
243
112
|
entity,
|
|
244
113
|
field,
|
|
245
114
|
)
|
|
246
|
-
|
|
115
|
+
this.validateValidatorArgument(
|
|
247
116
|
errorBuilder.for('validator'),
|
|
248
117
|
validatorCast.args[1],
|
|
249
118
|
entity,
|
|
250
119
|
field,
|
|
251
120
|
)
|
|
252
|
-
|
|
253
|
-
return undefined
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
return { operation: 'filter', args: [filterArgA, filterArgB] }
|
|
121
|
+
return
|
|
257
122
|
default:
|
|
258
123
|
((_: never) => {
|
|
259
124
|
errorBuilder.for('operation', `Operation ${(validatorCast as any).operation} is not an valid option`)
|
|
@@ -263,65 +128,19 @@ export class ValidationValidator {
|
|
|
263
128
|
|
|
264
129
|
private validateValidatorArgument(
|
|
265
130
|
errorBuilder: ErrorBuilder,
|
|
266
|
-
argument:
|
|
131
|
+
argument: Validation.ValidatorArgument,
|
|
267
132
|
entity: Model.Entity,
|
|
268
133
|
field: Model.AnyField,
|
|
269
|
-
):
|
|
270
|
-
|
|
271
|
-
errorBuilder.add('Must be an object')
|
|
272
|
-
return undefined
|
|
273
|
-
}
|
|
274
|
-
if (!hasStringProperty(argument, 'type') || argument.type !== Validation.ArgumentType.validator) {
|
|
275
|
-
errorBuilder.for('type').add(`Invalid value ${argument.type}`)
|
|
276
|
-
return undefined
|
|
277
|
-
}
|
|
278
|
-
const validator = this.validateValidator(errorBuilder.for('validator'), argument.validator, entity, field)
|
|
279
|
-
if (!validator) {
|
|
280
|
-
return undefined
|
|
281
|
-
}
|
|
282
|
-
return { validator, type: argument.type }
|
|
134
|
+
): void {
|
|
135
|
+
this.validateValidator(errorBuilder.for('validator'), argument.validator, entity, field)
|
|
283
136
|
}
|
|
284
137
|
|
|
285
|
-
private validateLiteralArgument(
|
|
286
|
-
errorBuilder: ErrorBuilder,
|
|
287
|
-
argument: unknown,
|
|
288
|
-
): Validation.LiteralArgument<unknown> | undefined {
|
|
289
|
-
if (!isObject(argument)) {
|
|
290
|
-
errorBuilder.add('Must be an object')
|
|
291
|
-
return undefined
|
|
292
|
-
}
|
|
293
|
-
if (!hasStringProperty(argument, 'type') || argument.type !== Validation.ArgumentType.literal) {
|
|
294
|
-
errorBuilder.for('type').add(`Invalid value ${argument.type}`)
|
|
295
|
-
return undefined
|
|
296
|
-
}
|
|
297
|
-
if (!('value' in argument)) {
|
|
298
|
-
errorBuilder.for('value').add('Undefined literal value')
|
|
299
|
-
return undefined
|
|
300
|
-
}
|
|
301
|
-
return { type: argument.type, value: argument.value }
|
|
302
|
-
}
|
|
303
138
|
|
|
304
139
|
private validatePathArgument(
|
|
305
140
|
errorBuilder: ErrorBuilder,
|
|
306
|
-
argument:
|
|
141
|
+
argument: Validation.PathArgument,
|
|
307
142
|
entity: Model.Entity,
|
|
308
|
-
):
|
|
309
|
-
if (!isObject(argument)) {
|
|
310
|
-
errorBuilder.add('Must be an object')
|
|
311
|
-
return undefined
|
|
312
|
-
}
|
|
313
|
-
if (!hasStringProperty(argument, 'type') || argument.type !== Validation.ArgumentType.path) {
|
|
314
|
-
errorBuilder.for('type').add(`Invalid value ${argument.type}`)
|
|
315
|
-
return undefined
|
|
316
|
-
}
|
|
317
|
-
if (!hasArrayProperty(argument, 'path')) {
|
|
318
|
-
errorBuilder.add('Undefined path')
|
|
319
|
-
return undefined
|
|
320
|
-
}
|
|
321
|
-
if (!everyIs(argument.path, (it): it is string => typeof it === 'string')) {
|
|
322
|
-
errorBuilder.add('Invalid path')
|
|
323
|
-
return undefined
|
|
324
|
-
}
|
|
143
|
+
): Model.AnyField | undefined {
|
|
325
144
|
const isRelation = acceptFieldVisitor(this.model, entity, argument.path[0], {
|
|
326
145
|
visitColumn: () => false,
|
|
327
146
|
visitRelation: () => true,
|
|
@@ -330,6 +149,6 @@ export class ValidationValidator {
|
|
|
330
149
|
errorBuilder.add('Rules depending on relations are currently not supported.')
|
|
331
150
|
return undefined
|
|
332
151
|
}
|
|
333
|
-
return
|
|
152
|
+
return entity.fields[argument.path[0]]
|
|
334
153
|
}
|
|
335
154
|
}
|
package/src/validation/index.ts
CHANGED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export declare type UnknownObject = Record<string, unknown>;
|
|
2
|
-
export declare function isObject(input: unknown): input is UnknownObject;
|
|
3
|
-
export declare function isArray(input: unknown): input is unknown[];
|
|
4
|
-
export declare function hasStringProperty<Input extends UnknownObject, Property extends string>(input: Input, property: Property): input is Input & {
|
|
5
|
-
[key in Property]: string;
|
|
6
|
-
};
|
|
7
|
-
export declare function hasNumberProperty<Input extends UnknownObject, Property extends string>(input: Input, property: Property): input is Input & {
|
|
8
|
-
[key in Property]: number;
|
|
9
|
-
};
|
|
10
|
-
export declare function hasObjectProperty<Input extends UnknownObject, Property extends string>(input: Input, property: Property): input is Input & {
|
|
11
|
-
[key in Property]: UnknownObject;
|
|
12
|
-
};
|
|
13
|
-
export declare function hasArrayProperty<Input extends UnknownObject, Property extends string>(input: Input, property: Property): input is Input & {
|
|
14
|
-
[key in Property]: unknown[];
|
|
15
|
-
};
|
|
16
|
-
export declare function everyIs<Type>(input: unknown[], predicate: (it: unknown) => it is Type): input is Type[];
|
|
17
|
-
export declare function checkExtraProperties(object: UnknownObject, allowedKeys: string[]): string[];
|
|
18
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/validation/utils.ts"],"names":[],"mappings":"AAAA,oBAAY,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEnD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAE/D;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO,EAAE,CAE1D;AAED,wBAAgB,iBAAiB,CAAC,KAAK,SAAS,aAAa,EAAE,QAAQ,SAAS,MAAM,EACrF,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,GAChB,KAAK,IAAI,KAAK,GAAG;KAAG,GAAG,IAAI,QAAQ,GAAG,MAAM;CAAE,CAEhD;AAED,wBAAgB,iBAAiB,CAAC,KAAK,SAAS,aAAa,EAAE,QAAQ,SAAS,MAAM,EACrF,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,GAChB,KAAK,IAAI,KAAK,GAAG;KAAG,GAAG,IAAI,QAAQ,GAAG,MAAM;CAAE,CAEhD;AAED,wBAAgB,iBAAiB,CAAC,KAAK,SAAS,aAAa,EAAE,QAAQ,SAAS,MAAM,EACrF,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,GAChB,KAAK,IAAI,KAAK,GAAG;KAAG,GAAG,IAAI,QAAQ,GAAG,aAAa;CAAE,CAEvD;AAED,wBAAgB,gBAAgB,CAAC,KAAK,SAAS,aAAa,EAAE,QAAQ,SAAS,MAAM,EACpF,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,GAChB,KAAK,IAAI,KAAK,GAAG;KAAG,GAAG,IAAI,QAAQ,GAAG,OAAO,EAAE;CAAE,CAEnD;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE,OAAO,KAAK,EAAE,IAAI,IAAI,GAAG,KAAK,IAAI,IAAI,EAAE,CAEvG;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAE3F"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkExtraProperties = exports.everyIs = exports.hasArrayProperty = exports.hasObjectProperty = exports.hasNumberProperty = exports.hasStringProperty = exports.isArray = exports.isObject = void 0;
|
|
4
|
-
function isObject(input) {
|
|
5
|
-
return typeof input === 'object' && input !== null;
|
|
6
|
-
}
|
|
7
|
-
exports.isObject = isObject;
|
|
8
|
-
function isArray(input) {
|
|
9
|
-
return Array.isArray(input);
|
|
10
|
-
}
|
|
11
|
-
exports.isArray = isArray;
|
|
12
|
-
function hasStringProperty(input, property) {
|
|
13
|
-
return typeof input[property] === 'string';
|
|
14
|
-
}
|
|
15
|
-
exports.hasStringProperty = hasStringProperty;
|
|
16
|
-
function hasNumberProperty(input, property) {
|
|
17
|
-
return typeof input[property] === 'number';
|
|
18
|
-
}
|
|
19
|
-
exports.hasNumberProperty = hasNumberProperty;
|
|
20
|
-
function hasObjectProperty(input, property) {
|
|
21
|
-
return isObject(input[property]);
|
|
22
|
-
}
|
|
23
|
-
exports.hasObjectProperty = hasObjectProperty;
|
|
24
|
-
function hasArrayProperty(input, property) {
|
|
25
|
-
return isArray(input[property]);
|
|
26
|
-
}
|
|
27
|
-
exports.hasArrayProperty = hasArrayProperty;
|
|
28
|
-
function everyIs(input, predicate) {
|
|
29
|
-
return input.every(it => predicate(it));
|
|
30
|
-
}
|
|
31
|
-
exports.everyIs = everyIs;
|
|
32
|
-
function checkExtraProperties(object, allowedKeys) {
|
|
33
|
-
return Object.keys(object).filter(it => !allowedKeys.includes(it));
|
|
34
|
-
}
|
|
35
|
-
exports.checkExtraProperties = checkExtraProperties;
|
|
36
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/validation/utils.ts"],"names":[],"mappings":";;;AAEA,SAAgB,QAAQ,CAAC,KAAc;IACtC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAA;AACnD,CAAC;AAFD,4BAEC;AAED,SAAgB,OAAO,CAAC,KAAc;IACrC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC5B,CAAC;AAFD,0BAEC;AAED,SAAgB,iBAAiB,CAChC,KAAY,EACZ,QAAkB;IAElB,OAAO,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,QAAQ,CAAA;AAC3C,CAAC;AALD,8CAKC;AAED,SAAgB,iBAAiB,CAChC,KAAY,EACZ,QAAkB;IAElB,OAAO,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,QAAQ,CAAA;AAC3C,CAAC;AALD,8CAKC;AAED,SAAgB,iBAAiB,CAChC,KAAY,EACZ,QAAkB;IAElB,OAAO,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAA;AACjC,CAAC;AALD,8CAKC;AAED,SAAgB,gBAAgB,CAC/B,KAAY,EACZ,QAAkB;IAElB,OAAO,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAA;AAChC,CAAC;AALD,4CAKC;AAED,SAAgB,OAAO,CAAO,KAAgB,EAAE,SAAsC;IACrF,OAAO,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAA;AACxC,CAAC;AAFD,0BAEC;AAED,SAAgB,oBAAoB,CAAC,MAAqB,EAAE,WAAqB;IAChF,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAA;AACnE,CAAC;AAFD,oDAEC"}
|
package/src/validation/utils.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export type UnknownObject = Record<string, unknown>
|
|
2
|
-
|
|
3
|
-
export function isObject(input: unknown): input is UnknownObject {
|
|
4
|
-
return typeof input === 'object' && input !== null
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function isArray(input: unknown): input is unknown[] {
|
|
8
|
-
return Array.isArray(input)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function hasStringProperty<Input extends UnknownObject, Property extends string>(
|
|
12
|
-
input: Input,
|
|
13
|
-
property: Property,
|
|
14
|
-
): input is Input & { [key in Property]: string } {
|
|
15
|
-
return typeof input[property] === 'string'
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function hasNumberProperty<Input extends UnknownObject, Property extends string>(
|
|
19
|
-
input: Input,
|
|
20
|
-
property: Property,
|
|
21
|
-
): input is Input & { [key in Property]: number } {
|
|
22
|
-
return typeof input[property] === 'number'
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function hasObjectProperty<Input extends UnknownObject, Property extends string>(
|
|
26
|
-
input: Input,
|
|
27
|
-
property: Property,
|
|
28
|
-
): input is Input & { [key in Property]: UnknownObject } {
|
|
29
|
-
return isObject(input[property])
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function hasArrayProperty<Input extends UnknownObject, Property extends string>(
|
|
33
|
-
input: Input,
|
|
34
|
-
property: Property,
|
|
35
|
-
): input is Input & { [key in Property]: unknown[] } {
|
|
36
|
-
return isArray(input[property])
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function everyIs<Type>(input: unknown[], predicate: (it: unknown) => it is Type): input is Type[] {
|
|
40
|
-
return input.every(it => predicate(it))
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function checkExtraProperties(object: UnknownObject, allowedKeys: string[]): string[] {
|
|
44
|
-
return Object.keys(object).filter(it => !allowedKeys.includes(it))
|
|
45
|
-
}
|