Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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;
dynamo.add(Name, Age, Person);
class CreatePerson {
@signature()
person(name: Name, age: Age): Person {
return { name, age, kind: '$person' };
}
}
const createPerson = dynamo.function(CreatePerson);
import { Static, Union, Literal, match } from 'runtypes';
// Define the runtype
const Day = Union(
Literal('Sunday'),
Literal('Monday'),
Literal('Tuesday'),
Literal('Wednesday'),
Literal('Thursday'),
Literal('Friday'),
Literal('Saturday'),
);
// Extract the static type
type Day = Static; // = 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday'
// Extract enumerated literal values
const days: Day[] = Day.alternatives.map(lit => lit.value);
for (const day of days) {
console.log(`Good morning, it's ${day}!`);
}
});
type Planet = Static<
typeof Planet
>; /* = {
type: 'planet';
location: Vector;
mass: NonNegative;
population: NonNegative;
habitable: Boolean;
}*/
const Rank = Union(
Literal('captain'),
Literal('first mate'),
Literal('officer'),
Literal('ensign'),
);
type Rank = Static; // = 'captain' | 'first mate' | 'officer' | 'ensign'
const CrewMember = Record({
name: String,
age: NonNegative,
rank: Rank,
home: Planet,
});
type CrewMember = Static<
typeof CrewMember
>; /* = {
name: string;
age: NonNegative;
rank: Rank;
home: Planet;
import { Literal, Record, Static, String, Undefined, Union } from 'runtypes';
const NodeEnv = Union(
Literal('prod'),
Literal('production'),
Literal('dev'),
Literal('development'),
Literal('test'),
);
const LogLevel = Union(
Literal('INFO'),
Literal('FATAL'),
Literal('DEBUG'),
Literal('ERROR'),
Literal('WARN'),
Literal('FINE'),
Literal('OFF'),
);
export const EnvRunType = Record({
DATABASE_URL: String,
JWT_SECRET: String,
SESSION_SECRET: String,
REDIS_URL: String,
GOOGLE_CLIENT: String,
GOOGLE_SECRET: String,
GOOGLE_CALLBACK_URL: String,
GLOBAL_PREFIX: String,
RATE_LIMIT: String,
import { Socket } from 'net'
import { ChildProcessWithoutNullStreams } from 'child_process'
import { Logger } from './Logger'
export const Env = Union(
Literal('production'),
Literal('development'),
Literal('test')
)
export type Env = Static
export const StatusType = Union(
Literal('playing'),
Literal('stopped'),
Literal('paused'),
Literal('volumeChange'),
Literal('info'),
Literal('unknown')
)
export type StatusType = Static
export const PlaybackAction = Union(
Literal('play'),
Literal('pause'),
Literal('stop'),
Literal('prev'),
Literal('next'),
Literal('rand')
)
import { Literal, Record, Static, String, Undefined, Union } from 'runtypes';
const NodeEnv = Union(
Literal('prod'),
Literal('production'),
Literal('dev'),
Literal('development'),
Literal('test'),
);
const LogLevel = Union(
Literal('INFO'),
Literal('FATAL'),
Literal('DEBUG'),
Literal('ERROR'),
Literal('WARN'),
Literal('FINE'),
Literal('OFF'),
);
export const EnvRunType = Record({
DATABASE_URL: String,
JWT_SECRET: String,
SESSION_SECRET: String,
import { Literal, Record, Static, String, Undefined, Union } from 'runtypes';
const NodeEnv = Union(
Literal('prod'),
Literal('production'),
Literal('dev'),
Literal('development'),
Literal('test'),
);
const LogLevel = Union(
Literal('INFO'),
Literal('FATAL'),
Literal('DEBUG'),
Literal('ERROR'),
Literal('WARN'),
Literal('FINE'),
Literal('OFF'),
);
export const EnvRunType = Record({
DATABASE_URL: String,
JWT_SECRET: String,
SESSION_SECRET: String,
REDIS_URL: String,
GOOGLE_CLIENT: String,
GOOGLE_SECRET: String,
GOOGLE_CALLBACK_URL: String,
export const StatusType = Union(
Literal('playing'),
Literal('stopped'),
Literal('paused'),
Literal('volumeChange'),
Literal('info'),
Literal('unknown')
)
export type StatusType = Static
export const PlaybackAction = Union(
Literal('play'),
Literal('pause'),
Literal('stop'),
Literal('prev'),
Literal('next'),
Literal('rand')
)
export type PlaybackAction = Static
export const playbackActions: readonly PlaybackAction[] = [
'play',
'pause',
'stop',
'prev',
'next',
'rand'
]
export const VolumeAction = Union(
Literal('vol mute'),
mass: Number,
})
const Planet = Record({
type: Literal('planet'),
location: Vector,
mass: Number,
population: Number,
habitable: Boolean,
})
const Rank = Union(
Literal('captain'),
Literal('first mate'),
Literal('officer'),
Literal('ensign'),
)
const CrewMember = Record({
name: String,
age: Number,
rank: Rank,
home: Planet,
})
const Ship = Record({
type: Literal('ship'),
location: Vector,
mass: Number,
name: String,
crew: Array(CrewMember),
})