Socket
Socket
Sign inDemoInstall

io-ts

Package Overview
Dependencies
Maintainers
1
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

io-ts - npm Package Compare versions

Comparing version 1.7.0 to 1.7.1

9

CHANGELOG.md

@@ -17,2 +17,11 @@ # Changelog

# 1.7.1
- **Deprecation**
- deprecate `any` (@gcanti)
- deprecate `object` (@gcanti)
- deprecate `Dictionary` in favour of `UnknownRecord` (@gcanti)
- deprecate `Array` in favour of `UnknownArray` (@gcanti)
- deprecate `dictionary` in favour of `record` (@gcanti)
# 1.7.0

@@ -19,0 +28,0 @@

25

lib/index.d.ts

@@ -221,3 +221,5 @@ import { Either } from 'fp-ts/lib/Either';

/**
* Use `unknown` instead
* @since 1.0.0
* @deprecated
*/

@@ -317,4 +319,7 @@ export declare const any: AnyC;

}
declare const arrayType: UnknownArrayC;
/**
* @since 1.7.1
*/
export declare const UnknownArray: UnknownArrayC;
/**
* @since 1.0.0

@@ -329,2 +334,6 @@ */

/**
* @since 1.7.1
*/
export declare const UnknownRecord: UnknownRecordC;
/**
* @since 1.5.3

@@ -335,3 +344,5 @@ */

/**
* Use `UnknownRecord` instead
* @since 1.0.0
* @deprecated
*/

@@ -352,3 +363,5 @@ export declare const Dictionary: UnknownRecordC;

/**
* Use `UnknownRecord` instead
* @since 1.0.0
* @deprecated
*/

@@ -577,5 +590,11 @@ export declare const object: ObjectC;

/**
* @since 1.7.1
*/
export declare const record: <D extends Mixed, C extends Mixed>(domain: D, codomain: C, name?: string) => RecordC<D, C>;
/**
* Use `record` instead
* @since 1.0.0
* @deprecated
*/
export declare const dictionary: <D extends Mixed, C extends Mixed>(domain: D, codomain: C, name?: string) => RecordC<D, C>;
export declare const dictionary: typeof record;
/**

@@ -839,2 +858,2 @@ * @since 1.0.0

export declare function alias<A, O, P, I>(codec: InterfaceType<P, A, O, I>): <AA extends Exact<A, AA>, OO extends Exact<O, OO> = O, PP extends Exact<P, PP> = P, II extends I = I>() => InterfaceType<PP, AA, OO, II>;
export { nullType as null, undefinedType as undefined, arrayType as Array, type as interface, voidType as void };
export { nullType as null, undefinedType as undefined, UnknownArray as Array, type as interface, voidType as void };

59

lib/index.js

@@ -214,3 +214,5 @@ "use strict";

/**
* Use `unknown` instead
* @since 1.0.0
* @deprecated
*/

@@ -313,3 +315,3 @@ exports.any = new AnyType();

function AnyArrayType() {
var _this = _super.call(this, 'Array', Array.isArray, function (u, c) { return (_this.is(u) ? exports.success(u) : exports.failure(u, c)); }, exports.identity) || this;
var _this = _super.call(this, 'UnknownArray', Array.isArray, function (u, c) { return (_this.is(u) ? exports.success(u) : exports.failure(u, c)); }, exports.identity) || this;
_this._tag = 'AnyArrayType';

@@ -321,5 +323,8 @@ return _this;

exports.AnyArrayType = AnyArrayType;
var arrayType = new AnyArrayType();
exports.Array = arrayType;
/**
* @since 1.7.1
*/
exports.UnknownArray = new AnyArrayType();
exports.Array = exports.UnknownArray;
/**
* @since 1.0.0

@@ -330,3 +335,3 @@ */

function AnyDictionaryType() {
var _this = _super.call(this, 'Dictionary', function (u) { return u !== null && typeof u === 'object'; }, function (u, c) { return (_this.is(u) ? exports.success(u) : exports.failure(u, c)); }, exports.identity) || this;
var _this = _super.call(this, 'UnknownRecord', function (u) { return u !== null && typeof u === 'object'; }, function (u, c) { return (_this.is(u) ? exports.success(u) : exports.failure(u, c)); }, exports.identity) || this;
_this._tag = 'AnyDictionaryType';

@@ -339,5 +344,11 @@ return _this;

/**
* @since 1.7.1
*/
exports.UnknownRecord = new AnyDictionaryType();
/**
* Use `UnknownRecord` instead
* @since 1.0.0
* @deprecated
*/
exports.Dictionary = new AnyDictionaryType();
exports.Dictionary = exports.UnknownRecord;
/**

@@ -349,3 +360,3 @@ * @since 1.0.0

function ObjectType() {
var _this = _super.call(this, 'object', exports.Dictionary.is, exports.Dictionary.validate, exports.identity) || this;
var _this = _super.call(this, 'object', exports.UnknownRecord.is, exports.UnknownRecord.validate, exports.identity) || this;
_this._tag = 'ObjectType';

@@ -358,3 +369,5 @@ return _this;

/**
* Use `UnknownRecord` instead
* @since 1.0.0
* @deprecated
*/

@@ -526,4 +539,4 @@ exports.object = new ObjectType();

if (name === void 0) { name = "Array<" + codec.name + ">"; }
return new ArrayType(name, function (u) { return arrayType.is(u) && u.every(codec.is); }, function (u, c) {
var arrayValidation = arrayType.validate(u, c);
return new ArrayType(name, function (u) { return exports.UnknownArray.is(u) && u.every(codec.is); }, function (u, c) {
var arrayValidation = exports.UnknownArray.validate(u, c);
if (arrayValidation.isLeft()) {

@@ -594,3 +607,3 @@ return arrayValidation;

return new InterfaceType(name, function (u) {
if (!exports.Dictionary.is(u)) {
if (!exports.UnknownRecord.is(u)) {
return false;

@@ -606,3 +619,3 @@ }

}, function (u, c) {
var dictionaryValidation = exports.Dictionary.validate(u, c);
var dictionaryValidation = exports.UnknownRecord.validate(u, c);
if (dictionaryValidation.isLeft()) {

@@ -684,3 +697,3 @@ return dictionaryValidation;

return new PartialType(name, function (u) {
if (!exports.Dictionary.is(u)) {
if (!exports.UnknownRecord.is(u)) {
return false;

@@ -696,3 +709,3 @@ }

}, function (u, c) {
var dictionaryValidation = exports.Dictionary.validate(u, c);
var dictionaryValidation = exports.UnknownRecord.validate(u, c);
if (dictionaryValidation.isLeft()) {

@@ -757,8 +770,8 @@ return dictionaryValidation;

/**
* @since 1.0.0
* @since 1.7.1
*/
exports.dictionary = function (domain, codomain, name) {
exports.record = function (domain, codomain, name) {
if (name === void 0) { name = "{ [K in " + domain.name + "]: " + codomain.name + " }"; }
return new DictionaryType(name, function (u) {
if (!exports.Dictionary.is(u)) {
if (!exports.UnknownRecord.is(u)) {
return false;

@@ -771,3 +784,3 @@ }

}, function (u, c) {
var dictionaryValidation = exports.Dictionary.validate(u, c);
var dictionaryValidation = exports.UnknownRecord.validate(u, c);
if (dictionaryValidation.isLeft()) {

@@ -824,4 +837,10 @@ return dictionaryValidation;

/**
* Use `record` instead
* @since 1.0.0
* @deprecated
*/
exports.dictionary = exports.record;
/**
* @since 1.0.0
*/
var UnionType = /** @class */ (function (_super) {

@@ -933,4 +952,4 @@ __extends(UnionType, _super);

var len = codecs.length;
return new TupleType(name, function (u) { return arrayType.is(u) && u.length === len && codecs.every(function (type, i) { return type.is(u[i]); }); }, function (u, c) {
var arrayValidation = arrayType.validate(u, c);
return new TupleType(name, function (u) { return exports.UnknownArray.is(u) && u.length === len && codecs.every(function (type, i) { return type.is(u[i]); }); }, function (u, c) {
var arrayValidation = exports.UnknownArray.validate(u, c);
if (arrayValidation.isLeft()) {

@@ -1212,3 +1231,3 @@ return arrayValidation;

return new TaggedUnionType(name, function (u) {
if (!exports.Dictionary.is(u)) {
if (!exports.UnknownRecord.is(u)) {
return false;

@@ -1220,3 +1239,3 @@ }

}, function (u, c) {
var dictionaryResult = exports.Dictionary.validate(u, c);
var dictionaryResult = exports.UnknownRecord.validate(u, c);
if (dictionaryResult.isLeft()) {

@@ -1223,0 +1242,0 @@ return dictionaryResult;

{
"name": "io-ts",
"version": "1.7.0",
"version": "1.7.1",
"description": "TypeScript compatible runtime type system for IO validation",

@@ -5,0 +5,0 @@ "files": [

@@ -19,5 +19,3 @@ [![build status](https://img.shields.io/travis/gcanti/io-ts/master.svg?style=flat-square)](https://travis-ci.org/gcanti/io-ts)

```ts
export type mixed = unknown
class Type<A, O = A, I = mixed> {
class Type<A, O, I> {
readonly _A: A

@@ -30,3 +28,3 @@ readonly _O: O

/** a custom type guard */
readonly is: (v: mixed) => v is A,
readonly is: (u: unknown) => u is A,
/** succeeds if a value of type I can be decoded to a value of type A */

@@ -52,18 +50,10 @@ readonly validate: (input: I, context: Context) => Either<Errors, A>,

// codec definition
export class StringType extends t.Type<string> {
// equivalent to Type<string, string, mixed> as per type parameter defaults
readonly _tag: 'StringType' = 'StringType'
constructor() {
super(
'string',
(m): m is string => typeof m === 'string',
(m, c) => (this.is(m) ? t.success(m) : t.failure(m, c)),
t.identity
)
}
}
const isString = (u: unknown): u is string => typeof u === 'string'
// codec instance: use this when building other codecs instances
export const string = new StringType()
const string = new t.Type<string, string, unknown>(
'string',
isString,
(u, c) => (isString(u) ? t.success(u) : t.failure(u, c)),
t.identity
)
```

@@ -130,7 +120,10 @@

}
interface Context extends ReadonlyArray<ContextEntry> {}
interface ValidationError {
readonly value: mixed
readonly value: unknown
readonly context: Context
}
interface Errors extends Array<ValidationError> {}

@@ -219,32 +212,31 @@ ```

| Type | TypeScript | codec / combinator |
| ------------------------- | --------------------------------------- | ----------------------------------------------------- |
| null | `null` | `t.null` or `t.nullType` |
| undefined | `undefined` | `t.undefined` |
| void | `void` | `t.void` or `t.voidType` |
| string | `string` | `t.string` |
| number | `number` | `t.number` |
| boolean | `boolean` | `t.boolean` |
| any | `any` | `t.any` |
| never | `never` | `t.never` |
| object | `object` | `t.object` |
| integer | ✘ | `t.Integer` |
| array of any | `Array<mixed>` | `t.Array` |
| array of type | `Array<A>` | `t.array(A)` |
| dictionary of any | `{ [key: string]: mixed }` | `t.Dictionary` |
| dictionary of type | `{ [K in A]: B }` | `t.dictionary(A, B)` |
| function | `Function` | `t.Function` |
| literal | `'s'` | `t.literal('s')` |
| partial | `Partial<{ name: string }>` | `t.partial({ name: t.string })` |
| readonly | `Readonly<T>` | `t.readonly(T)` |
| readonly array | `ReadonlyArray<number>` | `t.readonlyArray(t.number)` |
| type alias | `type A = { name: string }` | `t.type({ name: t.string })` |
| tuple | `[ A, B ]` | `t.tuple([ A, B ])` |
| union | `A \| B` | `t.union([ A, B ])` or `t.taggedUnion(tag, [ A, B ])` |
| intersection | `A & B` | `t.intersection([ A, B ])` |
| keyof | `keyof M` | `t.keyof(M)` |
| recursive types | see [Recursive types](#recursive-types) | `t.recursion(name, definition)` |
| refinement | ✘ | `t.refinement(A, predicate)` |
| exact types | ✘ | `t.exact(type)` |
| strict types (deprecated) | ✘ | `t.strict({ name: t.string })` |
| Type | TypeScript | codec / combinator |
| ----------------- | --------------------------------------- | ----------------------------------------------------- |
| null | `null` | `t.null` or `t.nullType` |
| undefined | `undefined` | `t.undefined` |
| void | `void` | `t.void` or `t.voidType` |
| string | `string` | `t.string` |
| number | `number` | `t.number` |
| boolean | `boolean` | `t.boolean` |
| unknown | `unknown` | t.unknown |
| never | `never` | `t.never` |
| object | `object` | `t.object` |
| integer | ✘ | `t.Integer` |
| array of unknown | `Array<unknown>` | `t.UnknownArray` |
| array of type | `Array<A>` | `t.array(A)` |
| record of unknown | `Record<string, unknown>` | `t.UnknownRecord` |
| record of type | `Record<K, A>` | `t.record(K, A)` |
| function | `Function` | `t.Function` |
| literal | `'s'` | `t.literal('s')` |
| partial | `Partial<{ name: string }>` | `t.partial({ name: t.string })` |
| readonly | `Readonly<T>` | `t.readonly(T)` |
| readonly array | `ReadonlyArray<number>` | `t.readonlyArray(t.number)` |
| type alias | `type A = { name: string }` | `t.type({ name: t.string })` |
| tuple | `[ A, B ]` | `t.tuple([ A, B ])` |
| union | `A \| B` | `t.union([ A, B ])` or `t.taggedUnion(tag, [ A, B ])` |
| intersection | `A & B` | `t.intersection([ A, B ])` |
| keyof | `keyof M` | `t.keyof(M)` |
| recursive types | see [Recursive types](#recursive-types) | `t.recursion(name, definition)` |
| refinement | ✘ | `t.refinement(A, predicate)` |
| exact types | ✘ | `t.exact(type)` |

@@ -256,9 +248,8 @@ # Recursive types

```ts
// helper type
interface ICategory {
interface Category {
name: string
categories: Array<ICategory>
categories: Array<Category>
}
const Category = t.recursion<ICategory>('Category', Category =>
const Category: t.RecursiveType<t.Type<Category>> = t.recursion('Category', () =>
t.type({

@@ -274,13 +265,13 @@ name: t.string,

```ts
interface IFoo {
interface Foo {
type: 'Foo'
b: IBar | undefined
b: Bar | undefined
}
interface IBar {
interface Bar {
type: 'Bar'
a: IFoo | undefined
a: Foo | undefined
}
const Foo: t.RecursiveType<t.Type<IFoo>, IFoo> = t.recursion<IFoo>('Foo', _ =>
const Foo: t.RecursiveType<t.Type<Foo>> = t.recursion('Foo', () =>
t.interface({

@@ -292,3 +283,3 @@ type: t.literal('Foo'),

const Bar: t.RecursiveType<t.Type<IBar>, IBar> = t.recursion<IBar>('Bar', _ =>
const Bar: t.RecursiveType<t.Type<Bar>> = t.recursion('Bar', () =>
t.interface({

@@ -461,2 +452,4 @@ type: t.literal('Bar'),

import * as t from 'io-ts'
// t.Mixed = t.Type<any, any, unknown>
const ResponseBody = <RT extends t.Mixed>(type: RT) =>

@@ -463,0 +456,0 @@ t.interface({

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc