io-ts-fuzzer
Advanced tools
Comparing version 3.0.5 to 4.0.0
@@ -13,24 +13,24 @@ import * as t from 'io-ts'; | ||
}>; | ||
export declare function unknownFuzzer(codec?: t.Decoder<unknown, unknown>): Fuzzer<unknown, t.UnknownType>; | ||
export declare function fuzzLiteral(b: t.LiteralType<string | number | boolean>): ConcreteFuzzer<unknown>; | ||
export declare function fuzzUnion(b: t.UnionType<t.Mixed[]>): ConcreteFuzzer<unknown>; | ||
export declare function unknownFuzzer(codec?: t.Decoder<unknown, unknown>): Fuzzer<unknown, unknown, t.UnknownType>; | ||
export declare function fuzzLiteral(b: t.LiteralType<string | number | boolean>): ConcreteFuzzer<string | number | boolean, unknown>; | ||
export declare function fuzzUnion(b: t.UnionType<t.Mixed[]>): ConcreteFuzzer<unknown, unknown>; | ||
export declare function fuzzKeyof(b: t.KeyofType<{ | ||
[key: string]: unknown; | ||
}>): ConcreteFuzzer<unknown>; | ||
export declare function fuzzTuple(b: t.TupleType<t.Mixed[]>): ConcreteFuzzer<unknown[]>; | ||
export declare function fuzzExact(b: t.ExactC<t.HasProps>): ConcreteFuzzer<unknown>; | ||
export declare function fuzzReadonly(b: t.ReadonlyType<t.Any>): ConcreteFuzzer<unknown>; | ||
export declare function fuzzRecursive(b: t.RecursiveType<t.Mixed>): ConcreteFuzzer<unknown>; | ||
}>): ConcreteFuzzer<unknown, unknown>; | ||
export declare function fuzzTuple(b: t.TupleType<t.Mixed[]>): ConcreteFuzzer<unknown[], unknown>; | ||
export declare function fuzzExact(b: t.ExactC<t.HasProps>): ConcreteFuzzer<unknown, unknown>; | ||
export declare function fuzzReadonly(b: t.ReadonlyType<t.Any>): ConcreteFuzzer<unknown, unknown>; | ||
export declare function fuzzRecursive(b: t.RecursiveType<t.Mixed>): ConcreteFuzzer<unknown, unknown>; | ||
export declare const defaultMaxArrayLength = 5; | ||
export declare function arrayFuzzer(maxLength?: number): Fuzzer<unknown[], t.ArrayType<t.Mixed, any, any, unknown>>; | ||
export declare function readonlyArrayFuzzer(maxLength?: number): Fuzzer<unknown[], t.ReadonlyArrayType<t.Mixed, any, any, unknown>>; | ||
export declare function anyArrayFuzzer(maxLength?: number): Fuzzer<unknown[], t.AnyArrayType>; | ||
export declare function arrayFuzzer(maxLength?: number): Fuzzer<unknown[], unknown, t.ArrayType<t.Mixed, any, any, unknown>>; | ||
export declare function readonlyArrayFuzzer(maxLength?: number): Fuzzer<unknown[], unknown, t.ReadonlyArrayType<t.Mixed, any, any, unknown>>; | ||
export declare function anyArrayFuzzer(maxLength?: number): Fuzzer<unknown[], unknown, t.AnyArrayType>; | ||
export declare const defaultExtraProps: { | ||
___0000_extra_: t.NumberC; | ||
}; | ||
export declare const fuzzPartialWithExtraCodec: (extra: t.Props) => (b: t.PartialType<t.Props, any, any, unknown>) => ConcreteFuzzer<unknown>; | ||
export declare function partialFuzzer(extra?: t.Props): Fuzzer<unknown, t.PartialType<t.Props, any, any, unknown>>; | ||
export declare const fuzzInterfaceWithExtraCodec: (extra: t.Props) => (b: t.InterfaceType<t.Props, any, any, unknown>) => ConcreteFuzzer<unknown>; | ||
export declare function interfaceFuzzer(extra?: t.Props): Fuzzer<unknown, t.InterfaceType<t.Props, any, any, unknown>>; | ||
export declare function fuzzIntersection(b: t.IntersectionType<t.Any[]>): ConcreteFuzzer<unknown>; | ||
export declare const coreFuzzers: ReadonlyArray<Fuzzer>; | ||
export declare const fuzzPartialWithExtraCodec: (extra: t.Props) => (b: t.PartialType<t.Props, any, any, unknown>) => ConcreteFuzzer<unknown, unknown>; | ||
export declare function partialFuzzer(extra?: t.Props): Fuzzer<unknown, unknown, t.PartialType<t.Props, any, any, unknown>>; | ||
export declare const fuzzInterfaceWithExtraCodec: (extra: t.Props) => (b: t.InterfaceType<t.Props, any, any, unknown>) => ConcreteFuzzer<unknown, unknown>; | ||
export declare function interfaceFuzzer(extra?: t.Props): Fuzzer<unknown, unknown, t.InterfaceType<t.Props, any, any, unknown>>; | ||
export declare function fuzzIntersection(b: t.IntersectionType<t.Any[]>): ConcreteFuzzer<unknown, unknown>; | ||
export declare const coreFuzzers: ReadonlyArray<Fuzzer<unknown, unknown, any>>; |
@@ -296,2 +296,3 @@ "use strict"; | ||
exports.fuzzIntersection = fuzzIntersection; | ||
// tslint:disable-next-line:no-any | ||
exports.coreFuzzers = [ | ||
@@ -298,0 +299,0 @@ concrete(fuzzNumber, 'NumberType'), |
import { FuzzContext } from '../fuzzer'; | ||
import * as t from 'io-ts'; | ||
export declare function fuzzDate(_: FuzzContext, n: number): Date; | ||
export declare const fuzzers: import("../fuzzer").Fuzzer<Date, import("io-ts").Decoder<unknown, Date>>[]; | ||
export declare function fuzzUUID(_: FuzzContext, n: number): string; | ||
export declare function fuzzRegExp(i: string): RegExp; | ||
export declare const fuzzers: (import("../fuzzer").Fuzzer<unknown, Date, t.Decoder<Date, unknown>> | import("../fuzzer").Fuzzer<unknown, string, t.Decoder<string, unknown>> | import("../fuzzer").Fuzzer<unknown, number, t.Decoder<number, unknown>> | import("../fuzzer").Fuzzer<unknown, RegExp, t.Decoder<RegExp, unknown>>)[]; |
@@ -5,2 +5,31 @@ "use strict"; | ||
const rng_1 = require("../rng"); | ||
const t = require("io-ts"); | ||
const Either_1 = require("fp-ts/lib/Either"); | ||
const date_1 = require("io-ts-types/lib/date"); | ||
const DateFromISOString_1 = require("io-ts-types/lib/DateFromISOString"); | ||
const DateFromNumber_1 = require("io-ts-types/lib/DateFromNumber"); | ||
const DateFromUnixTime_1 = require("io-ts-types/lib/DateFromUnixTime"); | ||
const BooleanFromString_1 = require("io-ts-types/lib/BooleanFromString"); | ||
const IntFromString_1 = require("io-ts-types/lib/IntFromString"); | ||
const NumberFromString_1 = require("io-ts-types/lib/NumberFromString"); | ||
function decode(t, v) { | ||
const d = t.decode(v); | ||
// istanbul ignore else | ||
if (Either_1.isRight(d)) { | ||
return d.right; | ||
} | ||
else { | ||
throw new Error('IOTSF0003: cannot decode piped fuzzer output'); | ||
} | ||
} | ||
function pipeFuzzer(t, e) { | ||
return { | ||
type: 'fuzzer', | ||
mightRecurse: false, | ||
children: [t], | ||
func: (ctx, n, h0) => { | ||
return e(decode(t, h0.encode([rng_1.rngi(n), ctx]))); | ||
}, | ||
}; | ||
} | ||
function fuzzDate(_, n) { | ||
@@ -10,3 +39,37 @@ return new Date(rng_1.rngi(n) / 1000.0); | ||
exports.fuzzDate = fuzzDate; | ||
exports.fuzzers = [fuzzer_1.concreteFuzzerByName(fuzzDate, 'Date')]; | ||
function fuzzUUID(_, n) { | ||
const r = rng_1.rng(n); | ||
const ret = []; | ||
for (const i of new Array(32).keys()) { | ||
switch (i) { | ||
case 8: | ||
case 12: | ||
case 16: | ||
case 20: | ||
ret.push('-'); | ||
break; | ||
default: | ||
// nothing | ||
} | ||
ret.push((Math.abs(r.int32()) % 16).toString(16)); | ||
} | ||
return ret.join(''); | ||
} | ||
exports.fuzzUUID = fuzzUUID; | ||
function fuzzRegExp(i) { | ||
return new RegExp(i); | ||
} | ||
exports.fuzzRegExp = fuzzRegExp; | ||
exports.fuzzers = [ | ||
fuzzer_1.concreteFuzzerByName(fuzzDate, 'Date'), | ||
fuzzer_1.fuzzerByName(pipeFuzzer(t.boolean, BooleanFromString_1.BooleanFromString.encode), 'BooleanFromString'), | ||
fuzzer_1.fuzzerByName(pipeFuzzer(date_1.date, DateFromISOString_1.DateFromISOString.encode), 'DateFromISOString'), | ||
fuzzer_1.fuzzerByName(pipeFuzzer(date_1.date, DateFromNumber_1.DateFromNumber.encode), 'DateFromNumber'), | ||
fuzzer_1.fuzzerByName(pipeFuzzer(date_1.date, x => Math.floor(DateFromUnixTime_1.DateFromUnixTime.encode(x))), 'DateFromUnixTime'), | ||
fuzzer_1.fuzzerByName(pipeFuzzer(t.Int, IntFromString_1.IntFromString.encode), 'IntFromString'), | ||
fuzzer_1.fuzzerByName(pipeFuzzer(t.string, x => `n${x}`), 'NonEmptyString'), | ||
fuzzer_1.fuzzerByName(pipeFuzzer(t.number, NumberFromString_1.NumberFromString.encode), 'NumberFromString'), | ||
fuzzer_1.concreteFuzzerByName(fuzzUUID, 'UUID'), | ||
fuzzer_1.fuzzerByName(pipeFuzzer(t.string, fuzzRegExp), 'RegExp'), | ||
]; | ||
//# sourceMappingURL=io-ts-types.js.map |
@@ -13,21 +13,22 @@ import * as t from 'io-ts'; | ||
} | ||
export interface Fuzzer<T = unknown, C extends t.Decoder<unknown, T> = t.Decoder<unknown, T>> { | ||
export interface Fuzzer<T = unknown, U = unknown, C extends t.Decoder<U, T> = t.Decoder<U, T>> { | ||
readonly id: string; | ||
readonly idType: 'name' | 'tag'; | ||
readonly impl: FuzzerGenerator<T, C> | ImmediateConcreteFuzzer<T>; | ||
readonly impl: FuzzerGenerator<T, U, C> | ImmediateConcreteFuzzer<T, U>; | ||
} | ||
export interface FuzzerGenerator<T, C extends t.Decoder<unknown, T>> { | ||
export interface FuzzerGenerator<T, U, C extends t.Decoder<U, T>> { | ||
readonly type: 'generator'; | ||
readonly func: fuzzGenerator<T, C>; | ||
readonly func: fuzzGenerator<T, U, C>; | ||
} | ||
export interface ImmediateConcreteFuzzer<T> extends ConcreteFuzzer<T> { | ||
export interface ImmediateConcreteFuzzer<T, U> extends ConcreteFuzzer<T, U> { | ||
readonly type: 'fuzzer'; | ||
} | ||
export interface ConcreteFuzzer<T> { | ||
readonly children?: Array<t.Decoder<unknown, unknown>>; | ||
export interface ConcreteFuzzer<T, U> { | ||
readonly children?: Array<t.Decoder<any, unknown>>; | ||
readonly mightRecurse?: boolean; | ||
readonly func: (ctx: FuzzContext, n: number, ...h: Array<FuzzerUnit<unknown>>) => T; | ||
readonly func: (ctx: FuzzContext, n: number, ...h: Array<FuzzerUnit<unknown>>) => U; | ||
} | ||
export declare function concreteFuzzerByName<T, C extends t.Decoder<unknown, T>>(func: ConcreteFuzzer<T>['func'], name: C['name']): Fuzzer<T, C>; | ||
export declare type fuzzGenerator<T, C extends t.Decoder<unknown, T>> = (b: C) => ConcreteFuzzer<T>; | ||
export declare function fuzzerByName<T, U, C extends t.Decoder<U, T>>(impl: Fuzzer<T, U, C>['impl'], name: C['name']): Fuzzer<T, U, C>; | ||
export declare function concreteFuzzerByName<T, U, C extends t.Decoder<U, T>>(func: ConcreteFuzzer<T, U>['func'], name: C['name']): Fuzzer<T, U, C>; | ||
export declare type fuzzGenerator<T, U, C extends t.Decoder<U, T>> = (b: C) => ConcreteFuzzer<T, U>; | ||
export declare type ContextOpts = Partial<typeof defaultContextOpt>; | ||
@@ -45,7 +46,7 @@ declare const defaultContextOpt: { | ||
} | ||
export interface FuzzerUnit<T> extends ExampleGenerator<T> { | ||
export interface FuzzerUnit<U> extends ExampleGenerator<U> { | ||
readonly mightRecurse: boolean; | ||
} | ||
export declare function exampleGenerator<T>(r: Registry, d: t.Decoder<unknown, T>): ExampleGenerator<T>; | ||
export declare function exampleOf<T>(d: t.Decoder<unknown, T>, r: Registry, a: number, maxRecursionHint?: number): T; | ||
export declare function exampleGenerator<T, U>(r: Registry, d: t.Decoder<U, T>): ExampleGenerator<U>; | ||
export declare function exampleOf<T, U>(d: t.Decoder<U, T>, r: Registry, a: number, maxRecursionHint?: number): U; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function concreteFuzzerByName(func, name) { | ||
function fuzzerByName(impl, name) { | ||
return { | ||
impl: { | ||
type: 'fuzzer', | ||
func, | ||
mightRecurse: false, | ||
}, | ||
impl, | ||
id: name, | ||
@@ -14,2 +10,10 @@ idType: 'name', | ||
} | ||
exports.fuzzerByName = fuzzerByName; | ||
function concreteFuzzerByName(func, name) { | ||
return fuzzerByName({ | ||
type: 'fuzzer', | ||
func, | ||
mightRecurse: false, | ||
}, name); | ||
} | ||
exports.concreteFuzzerByName = concreteFuzzerByName; | ||
@@ -16,0 +20,0 @@ const defaultContextOpt = { |
import { Fuzzer, ExampleGenerator } from './fuzzer'; | ||
import * as t from 'io-ts'; | ||
export interface Registry { | ||
register<T, U extends t.Decoder<unknown, T>>(v0: Fuzzer<T, U>): Registry; | ||
register<T, U, C extends t.Decoder<U, T>>(v0: Fuzzer<T, U, C>): Registry; | ||
register(...vv: Fuzzer[]): Registry; | ||
exampleGenerator<T>(d: t.Decoder<unknown, T>): ExampleGenerator<T>; | ||
getFuzzer<T>(a: t.Decoder<unknown, T>): Fuzzer<T> | null; | ||
exampleGenerator<T, U>(d: t.Decoder<U, T>): ExampleGenerator<U>; | ||
getFuzzer<T, U>(a: t.Decoder<U, T>): Fuzzer<T, U> | null; | ||
} | ||
@@ -9,0 +9,0 @@ export interface FluentRegistry extends Registry { |
@@ -0,1 +1,28 @@ | ||
# [4.0.0](https://github.com/holvonix-open/io-ts-fuzzer/compare/v3.0.5...v4.0.0) (2019-08-09) | ||
### 🌟🚀 Features | ||
* support io-ts-types ([#18](https://github.com/holvonix-open/io-ts-fuzzer/issues/18)) ([5489f03](https://github.com/holvonix-open/io-ts-fuzzer/commit/5489f03)) | ||
### 📖 Documentation | ||
* fix README link typo ([4b9b5a2](https://github.com/holvonix-open/io-ts-fuzzer/commit/4b9b5a2)) | ||
### 🧦 Miscellaneous | ||
* **deps:** bump seedrandom from 3.0.1 to 3.0.3 ([#16](https://github.com/holvonix-open/io-ts-fuzzer/issues/16)) ([91e2346](https://github.com/holvonix-open/io-ts-fuzzer/commit/91e2346)) | ||
* **deps-dev:** bump @types/chai from 4.1.7 to 4.2.0 ([#15](https://github.com/holvonix-open/io-ts-fuzzer/issues/15)) ([593a4dc](https://github.com/holvonix-open/io-ts-fuzzer/commit/593a4dc)) | ||
* **deps-dev:** bump @types/node from 12.7.0 to 12.7.1 ([9be1c28](https://github.com/holvonix-open/io-ts-fuzzer/commit/9be1c28)) | ||
* **deps-dev:** bump fp-ts from 2.0.4 to 2.0.5 ([#17](https://github.com/holvonix-open/io-ts-fuzzer/issues/17)) ([6d16718](https://github.com/holvonix-open/io-ts-fuzzer/commit/6d16718)) | ||
* **deps-dev:** bump husky from 3.0.2 to 3.0.3 ([#14](https://github.com/holvonix-open/io-ts-fuzzer/issues/14)) ([83b11a5](https://github.com/holvonix-open/io-ts-fuzzer/commit/83b11a5)) | ||
* make prod deps updates chores by default ([1d16fd1](https://github.com/holvonix-open/io-ts-fuzzer/commit/1d16fd1)) | ||
### ⚠️ BREAKING CHANGES | ||
* Fuzzers now have an input and decoded type. Fuzzer generate as output the *input* of the t.Type, not the decoded or output types. | ||
## [3.0.5](https://github.com/holvonix-open/io-ts-fuzzer/compare/v3.0.4...v3.0.5) (2019-08-08) | ||
@@ -2,0 +29,0 @@ |
{ | ||
"name": "io-ts-fuzzer", | ||
"version": "3.0.5", | ||
"version": "4.0.0", | ||
"description": "Fuzzing for io-ts codecs and types", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -68,8 +68,24 @@ # io-ts-fuzzer - Fuzzing for io-ts codecs and types | ||
If you `yarn add monocle-ts io-ts-types` and register the `io-ts-types` extra | ||
fuzzers via `r.register(...await loadIoTsTypesFuzzers())`, the following | ||
additional types will be supported: | ||
If you `yarn add monocle-ts io-ts-types` and register the | ||
[`io-ts-types`](https://github.com/gcanti/io-ts-types) extra fuzzers via | ||
`r.register(...await loadIoTsTypesFuzzers())`, the following additional types | ||
will be supported: | ||
- `date` | ||
- `BooleanFromString` | ||
- `DateFromISOString` | ||
- `DateFromNumber` | ||
- `DateFromUnixTime` | ||
- `IntFromString` | ||
- `NonEmptyString` | ||
- `NumberFromString` | ||
- `UUID` | ||
- `regexp` | ||
The following `io-ts-types` are composed of core types and you do not need to | ||
`loadIoTsTypesFuzzers` to fuzz them: | ||
- `either` | ||
- `option` | ||
## How To | ||
@@ -80,5 +96,5 @@ | ||
Given a `d = t.Decoder<I,A>` (aka a `t.Type`), `fuzz.exampleGenerator` will | ||
build a `t.Encoder<[number,FuzzContext],A>` that will give example instances of | ||
`A`. The example instances should all pass on `d.decode`, which should return an | ||
identical example. No exceptions should be thrown. | ||
build a `t.Encoder<[number,FuzzContext],I>` that will give example instances of | ||
`I`. The example instances should all pass on `d.decode` (which should return an | ||
identical example in the case of basic types). No exceptions should be thrown. | ||
@@ -85,0 +101,0 @@ ### Configure Core Fuzzers |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
61317
759
0
159