Skip to content

Commit

Permalink
simplify generator class name
Browse files Browse the repository at this point in the history
  • Loading branch information
veigaribo committed May 26, 2021
1 parent 223e82f commit b3df5e4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/classes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cache } from './cache'
import { ConstructorValuesGenerator } from './generators'
import { Generator } from './generators'
import { Constructor, MaybeError } from './utils'
import {
all,
Expand Down Expand Up @@ -64,7 +64,7 @@ export class Class {
*/
validate<T extends Constructor>(
Constructor: T,
values: ConstructorValuesGenerator<T>,
values: Generator<T>,
options: ValidationOptions = {},
): ValidationResult {
// check cache
Expand Down
8 changes: 3 additions & 5 deletions src/generators.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { arrayWithLength, Constructor } from './utils'

export interface ConstructorValuesGenerator<T extends Constructor> {
export interface Generator<T extends Constructor> {
get(i: number): InstanceType<T>
}

Expand All @@ -15,8 +15,7 @@ export function defaultRandom(): number {
return Math.random()
}

export class Continuous<T extends Constructor>
implements ConstructorValuesGenerator<T> {
export class Continuous<T extends Constructor> implements Generator<T> {
public readonly random: RandomFunction

/**
Expand Down Expand Up @@ -50,8 +49,7 @@ export class Continuous<T extends Constructor>
}
}

export class Discrete<T extends Constructor>
implements ConstructorValuesGenerator<T> {
export class Discrete<T extends Constructor> implements Generator<T> {
public readonly random: RandomFunction

/**
Expand Down
4 changes: 2 additions & 2 deletions src/instances.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Class } from './classes'
import { ConstructorValuesGenerator } from './generators'
import { Generator } from './generators'
import { Constructor, MaybeError } from './utils'
import { ValidationOptions } from './validators'

Expand Down Expand Up @@ -28,7 +28,7 @@ import { ValidationOptions } from './validators'
export function instance<T extends Constructor>(
Constructor: T,
clazz: Class,
values: ConstructorValuesGenerator<T>,
values: Generator<T>,
options: ValidationOptions = {},
) {
const result = clazz.validate(Constructor, values, options)
Expand Down
10 changes: 5 additions & 5 deletions src/validators.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConstructorValuesGenerator } from './generators'
import { Generator } from './generators'
import { arrayWithLength, Constructor, MaybeError } from './utils'

export interface ValidationOptions {
Expand All @@ -10,7 +10,7 @@ export type ValidationResult = MaybeError
export interface InstanceValidator<T extends Constructor> {
check(
Instance: T,
values: ConstructorValuesGenerator<T>,
values: Generator<T>,
options?: ValidationOptions,
): ValidationResult
}
Expand All @@ -26,7 +26,7 @@ export class Obeys<T extends Constructor> implements InstanceValidator<T> {

check(
Instance: T,
values: ConstructorValuesGenerator<T>,
values: Generator<T>,
options: ValidationOptions = {},
): ValidationResult {
const { sampleSize = 15 } = options
Expand Down Expand Up @@ -77,7 +77,7 @@ export class All<T extends Constructor> implements InstanceValidator<T> {

check(
Instance: T,
values: ConstructorValuesGenerator<T>,
values: Generator<T>,
options: ValidationOptions = {},
): ValidationResult {
const result = MaybeError.foldConjoin(
Expand All @@ -95,7 +95,7 @@ export class Any<T extends Constructor> implements InstanceValidator<T> {

check(
Instance: T,
values: ConstructorValuesGenerator<T>,
values: Generator<T>,
options: ValidationOptions = {},
): ValidationResult {
const result = MaybeError.foldDisjoin(
Expand Down

0 comments on commit b3df5e4

Please sign in to comment.