Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constraint['name'] = name ? `${name} ${constraint['tag']}` : constraint['tag'];
guard()(constraint, 'guard');
return constraint as any;
}
const dynamo = new Dynamo();
const nameConstraint = StringType.withConstraint(x => {
return x.length > 0;
});
// tslint:disable-next-line:variable-name
const Name = convertConstraint(nameConstraint);
type Name = InstanceType;
const ageConstraint = NumberType.withConstraint(n => {
return Number.isInteger(n) && n >= 0;
});
// tslint:disable-next-line:variable-name
const Age = convertConstraint(ageConstraint);
type Age = InstanceType;
const personRecord = Record({
name: nameConstraint,
age: ageConstraint,
kind: Literal('$person')
});
// tslint:disable-next-line:variable-name
const Person = convertConstraint(personRecord);
type Person = Static;
import {
Boolean,
Number,
String,
Literal,
Array,
Tuple,
Record,
Dictionary,
Union,
Static,
match,
} from 'runtypes';
const NonNegative = Number.withConstraint(n => n >= 0);
type NonNegative = Static; // = number
const Vector = Tuple(Number, Number, Number);
type Vector = Static; // = [number, number, number]
const Asteroid = Record({
type: Literal('asteroid'),
location: Vector,
mass: NonNegative,
});
type Asteroid = Static<
typeof Asteroid
>; /* = {
type: 'asteroid';
location: Vector;
mass: NonNegative;