Comparing version 0.8.0 to 0.9.1
@@ -9,4 +9,4 @@ import * as t from 'io-ts'; | ||
readonly _tag: 'LoiDecoratorConvert'; | ||
readonly [loiTagTypeDecorator]: boolean; | ||
readonly [loiTagTypeDecorator] = true; | ||
constructor(type: RT, convert?: (val: X) => t.TypeOf<RT>, guard?: (val: X) => boolean, name?: string); | ||
} |
@@ -12,3 +12,3 @@ import * as t from 'io-ts'; | ||
readonly _tag: 'LoiDecoratorDefault'; | ||
readonly [loiTagTypeDecorator]: boolean; | ||
readonly [loiTagTypeDecorator] = true; | ||
constructor(type: RT, defaultValue: RT['_A'], name?: string); | ||
@@ -25,4 +25,4 @@ } | ||
readonly _tag: 'LoiDecoratorDefaultResolver'; | ||
readonly [loiTagTypeDecorator]: boolean; | ||
readonly [loiTagTypeDecorator] = true; | ||
constructor(type: RT, defaultValueResolver: () => RT['_A'], name?: string); | ||
} |
@@ -7,4 +7,4 @@ import * as t from 'io-ts'; | ||
readonly _tag: 'LoiDecoratorNullAsUndefined'; | ||
readonly [loiTagTypeDecorator]: boolean; | ||
readonly [loiTagTypeDecorator] = true; | ||
constructor(type: RT, name?: string); | ||
} |
@@ -8,3 +8,3 @@ import * as t from 'io-ts'; | ||
readonly _tag: 'LoiDecoratorRescue'; | ||
readonly [loiTagTypeDecorator]: boolean; | ||
readonly [loiTagTypeDecorator] = true; | ||
constructor(type: RT, rescueValue: RT['_A'], name?: string); | ||
@@ -17,4 +17,4 @@ } | ||
readonly _tag: 'LoiDecoratorRescueResolver'; | ||
readonly [loiTagTypeDecorator]: boolean; | ||
readonly [loiTagTypeDecorator] = true; | ||
constructor(type: RT, rescueValueResolver: () => RT['_A'], name?: string); | ||
} |
import * as t from 'io-ts'; | ||
import { loiTagTypeDecorator } from '../utilties/tag'; | ||
export declare class LoiDecoratorUndefinedable<RT extends t.Any> extends t.Type<RT['_A'] | undefined, RT['_O'] | undefined, RT['_I']> { | ||
export declare class LoiDecoratorUndefinedable<RT extends t.Any, CVS extends (string | number | boolean | null | undefined)[] = []> extends t.Type<RT['_A'] | undefined, RT['_O'] | undefined, RT['_I']> { | ||
readonly type: RT; | ||
readonly castValues: CVS; | ||
static readonly _tag: 'LoiDecoratorUndefinedable'; | ||
readonly _tag: 'LoiDecoratorUndefinedable'; | ||
readonly [loiTagTypeDecorator]: boolean; | ||
readonly [loiTagTypeDecorator] = true; | ||
constructor(type: RT, castValues?: CVS, name?: string); | ||
} | ||
export declare class LoiDecoratorNotUndefinedable<RT extends t.Any> extends t.Type<Exclude<RT['_A'], undefined>, Exclude<RT['_O'], undefined>, RT['_I']> { | ||
readonly type: RT; | ||
static readonly _tag: 'LoiDecoratorNotUndefinedable'; | ||
readonly _tag: 'LoiDecoratorNotUndefinedable'; | ||
readonly [loiTagTypeDecorator] = true; | ||
constructor(type: RT, name?: string); | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var _a; | ||
var _a, _b; | ||
const t = require("io-ts"); | ||
const tag_1 = require("../utilties/tag"); | ||
class LoiDecoratorUndefinedable extends t.Type { | ||
constructor(type, name = type.name) { | ||
super(name, (v) => (v === undefined) ? true : type.is(v), (v, c) => (v === undefined) ? t.success(undefined) : type.validate(v, c), (v) => type.encode(v)); | ||
constructor(type, castValues = [], name = type.name) { | ||
super(name, (v) => (v === undefined || castValues.indexOf(v) >= 0) ? true : type.is(v), (v, c) => (v === undefined || castValues.indexOf(v) >= 0) ? t.success(undefined) : type.validate(v, c), (v) => type.encode(v)); | ||
this.type = type; | ||
this.castValues = castValues; | ||
this._tag = 'LoiDecoratorUndefinedable'; | ||
@@ -17,2 +18,33 @@ this[_a] = true; | ||
exports.LoiDecoratorUndefinedable = LoiDecoratorUndefinedable; | ||
class LoiDecoratorNotUndefinedable extends t.Type { | ||
constructor(type, name = type.name) { | ||
super(name, (v) => { | ||
if (v === undefined) | ||
return false; | ||
if (!type.is(v)) | ||
return false; | ||
const result = type.decode(v); | ||
if (result.isLeft()) | ||
return false; | ||
if (result.value === undefined) | ||
return false; | ||
return true; | ||
}, (v, c) => { | ||
if (v === undefined) | ||
return t.failure(undefined, c); | ||
const result = type.validate(v, c); | ||
if (result.isLeft()) | ||
return result; | ||
if (result.value === undefined) | ||
return t.failure(undefined, c); | ||
return result; | ||
}, (v) => type.encode(v)); | ||
this.type = type; | ||
this._tag = 'LoiDecoratorNotUndefinedable'; | ||
this[_b] = true; | ||
} | ||
} | ||
_b = tag_1.loiTagTypeDecorator; | ||
LoiDecoratorNotUndefinedable._tag = 'LoiDecoratorNotUndefinedable'; | ||
exports.LoiDecoratorNotUndefinedable = LoiDecoratorNotUndefinedable; | ||
//# sourceMappingURL=undefinedable.js.map |
@@ -10,2 +10,3 @@ import * as t from 'io-ts'; | ||
path: string; | ||
kind: string; | ||
message?: string; | ||
@@ -12,0 +13,0 @@ } |
@@ -11,2 +11,3 @@ "use strict"; | ||
path: path_1.getRealContextPath(context), | ||
kind: context[context.length - 1].type.name, | ||
message: `Invalid value \`${stringify_1.stringify(v)}' supplied to ${path_1.getRealContextPath(context)}: ${context[context.length - 1].type.name}.` | ||
@@ -13,0 +14,0 @@ }; |
@@ -11,2 +11,3 @@ "use strict"; | ||
for (const key in nodes) { | ||
/* istanbul ignore else */ | ||
if (Object.prototype.hasOwnProperty.call(nodes, key)) { | ||
@@ -13,0 +14,0 @@ const node = nodes[key]; |
@@ -17,6 +17,8 @@ import * as t from 'io-ts'; | ||
export { taggedUnion } from './types/TaggedUnion'; | ||
export { literal, never, null, undefined } from 'io-ts'; | ||
export { literal, never, null, undefined } from './types/Literal'; | ||
export { LoiDecoratorConvert } from './decorators/convert'; | ||
export { LoiDecoratorDefault, LoiDecoratorDefaultResolver } from './decorators/default'; | ||
export { LoiDecoratorNullAsUndefined } from './decorators/nullAsUndefined'; | ||
export { LoiDecoratorUndefinedable } from './decorators/undefinedable'; | ||
export { LoiDecoratorNullable } from './decorators/nullable'; | ||
export { validate, validateOrReturn, validateOrThrow } from './helpers/validate'; | ||
@@ -23,0 +25,0 @@ export { LoiValidationError, LoiValidationErrorItem, LoiValidationResult, createError } from './helpers/error'; |
@@ -36,7 +36,7 @@ "use strict"; | ||
exports.taggedUnion = TaggedUnion_1.taggedUnion; | ||
var io_ts_1 = require("io-ts"); | ||
exports.literal = io_ts_1.literal; | ||
exports.never = io_ts_1.never; | ||
exports.null = io_ts_1.null; | ||
exports.undefined = io_ts_1.undefined; | ||
var Literal_1 = require("./types/Literal"); | ||
exports.literal = Literal_1.literal; | ||
exports.never = Literal_1.never; | ||
exports.null = Literal_1.null; | ||
exports.undefined = Literal_1.undefined; | ||
var convert_1 = require("./decorators/convert"); | ||
@@ -49,2 +49,6 @@ exports.LoiDecoratorConvert = convert_1.LoiDecoratorConvert; | ||
exports.LoiDecoratorNullAsUndefined = nullAsUndefined_1.LoiDecoratorNullAsUndefined; | ||
var undefinedable_1 = require("./decorators/undefinedable"); | ||
exports.LoiDecoratorUndefinedable = undefinedable_1.LoiDecoratorUndefinedable; | ||
var nullable_1 = require("./decorators/nullable"); | ||
exports.LoiDecoratorNullable = nullable_1.LoiDecoratorNullable; | ||
var validate_1 = require("./helpers/validate"); | ||
@@ -51,0 +55,0 @@ exports.validate = validate_1.validate; |
@@ -7,2 +7,6 @@ import * as t from 'io-ts'; | ||
nullAsUndefined(): LoiFactoryTypeBase<t.Type<this["_A"] | undefined, this["_O"] | undefined, this["_I"]>>; | ||
nullable<CVS extends (string | number | boolean | null | undefined)[]>(allow?: true, ...castValues: CVS): LoiFactoryTypeBase<t.Type<this["_A"] | null, this["_O"] | null, this["_I"]>>; | ||
nullable(allow: false): LoiFactoryTypeBase<t.Type<Exclude<this["_A"], null>, Exclude<this["_O"], null>, this["_I"]>>; | ||
undefinedable<CVS extends (string | number | boolean | null | undefined)[]>(allow?: true, ...castValues: CVS): LoiFactoryTypeBase<t.Type<this["_A"] | undefined, this["_O"] | undefined, this["_I"]>>; | ||
undefinedable(allow: false): LoiFactoryTypeBase<t.Type<Exclude<this["_A"], undefined>, Exclude<this["_O"], undefined>, this["_I"]>>; | ||
/** | ||
@@ -35,15 +39,15 @@ * Sets properties default values when calling t.validate() method on models | ||
*/ | ||
finish(): t.Type<T['_A'], T['_O'], T['_I']>; | ||
finish(): t.Type<T["_A"], T["_O"], T["_I"]>; | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
end(): t.Type<T['_A'], T['_O'], T['_I']>; | ||
end(): t.Type<T["_A"], T["_O"], T["_I"]>; | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
simple(): t.Type<T['_A'], T['_O'], T['_I']>; | ||
simple(): t.Type<T["_A"], T["_O"], T["_I"]>; | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
clean(): t.Type<T['_A'], T['_O'], T['_I']>; | ||
clean(): t.Type<T["_A"], T["_O"], T["_I"]>; | ||
allow<T1 extends t.Any>(t1: T1): LoiFactoryTypeBaseUnion<t.Type<this['_A'], this['_O'], this['_I']> | t.Type<T1['_A'], T1['_O'], T1['_I']>>; | ||
@@ -50,0 +54,0 @@ allow<T1 extends t.Any, T2 extends t.Any>(t1: T1, t2: T2): LoiFactoryTypeBaseUnion<t.Type<this['_A'], this['_O'], this['_I']> | t.Type<T1['_A'], T1['_O'], T1['_I']> | t.Type<T2['_A'], T2['_O'], T2['_I']>>; |
@@ -5,4 +5,6 @@ "use strict"; | ||
const default_1 = require("../decorators/default"); | ||
const nullable_1 = require("../decorators/nullable"); | ||
const nullAsUndefined_1 = require("../decorators/nullAsUndefined"); | ||
const rescue_1 = require("../decorators/rescue"); | ||
const undefinedable_1 = require("../decorators/undefinedable"); | ||
const factory_1 = require("../utilties/factory"); | ||
@@ -21,2 +23,38 @@ class LoiFactoryBase extends factory_1.LoiFactory { | ||
} | ||
nullable(_allow = true, ...castValues) { | ||
if (_allow) { | ||
const type = new nullable_1.LoiDecoratorNullable(this, castValues); | ||
return factory_1.metadata(LoiFactoryBase.decorate(type), { | ||
parent: this, | ||
option: { name: `nullable`, nullable: true }, | ||
optionFilter: (i) => i.nullable !== true && i.nullable !== false | ||
}); | ||
} | ||
else { | ||
const type = new nullable_1.LoiDecoratorNotNullable(this); | ||
return factory_1.metadata(LoiFactoryBase.decorate(type), { | ||
parent: this, | ||
option: { name: `not nullable`, nullable: false }, | ||
optionFilter: (i) => i.nullable !== true && i.nullable !== false | ||
}); | ||
} | ||
} | ||
undefinedable(_allow = true, ...castValues) { | ||
if (_allow) { | ||
const type = new undefinedable_1.LoiDecoratorUndefinedable(this, castValues); | ||
return factory_1.metadata(LoiFactoryBase.decorate(type), { | ||
parent: this, | ||
option: { name: `undefinedable`, undefinedable: true }, | ||
optionFilter: (i) => i.undefinedable !== true && i.undefinedable !== false | ||
}); | ||
} | ||
else { | ||
const type = new undefinedable_1.LoiDecoratorNotUndefinedable(this); | ||
return factory_1.metadata(LoiFactoryBase.decorate(type), { | ||
parent: this, | ||
option: { name: `not undefinedable`, undefinedable: false }, | ||
optionFilter: (i) => i.undefinedable !== true && i.undefinedable !== false | ||
}); | ||
} | ||
} | ||
/** | ||
@@ -75,23 +113,15 @@ * Sets properties default values when calling t.validate() method on models | ||
*/ | ||
finish() { | ||
return this; | ||
} | ||
finish() { return this.asBaseType(); } | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
end() { | ||
return this; | ||
} | ||
end() { return this.asBaseType(); } | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
simple() { | ||
return this; | ||
} | ||
simple() { return this.asBaseType(); } | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
clean() { | ||
return this; | ||
} | ||
clean() { return this.asBaseType(); } | ||
allow(...ts) { | ||
@@ -98,0 +128,0 @@ const type = t.union([this, ...ts]); |
import * as t from 'io-ts'; | ||
import { LoiFactory } from '../utilties/factory'; | ||
import { LoiFactoryBase } from './Base'; | ||
export declare type TypeOfPartialUndefinedableProps<P extends t.AnyProps> = { | ||
export declare type TypeOfPartialProps<P extends t.AnyProps> = { | ||
[K in keyof P]?: t.TypeOf<P[K]> | undefined; | ||
}; | ||
export declare type OutputOfPartialUndefinedableProps<P extends t.AnyProps> = { | ||
export declare type OutputOfPartialProps<P extends t.AnyProps> = { | ||
[K in keyof P]?: t.OutputOf<P[K]> | undefined; | ||
}; | ||
export declare class LoiTypeObject<R extends t.Props, O extends t.Props> extends t.Type<t.TypeOfProps<R> & TypeOfPartialUndefinedableProps<O>, t.OutputOfProps<R> & OutputOfPartialUndefinedableProps<O>> { | ||
export declare class LoiTypeObject<R extends t.Props, O extends t.Props> extends t.Type<t.TypeOfProps<R> & TypeOfPartialProps<O>, t.OutputOfProps<R> & OutputOfPartialProps<O>> { | ||
readonly props: R; | ||
@@ -25,3 +25,3 @@ readonly optionalProps: O; | ||
*/ | ||
export declare class LoiTypeObjectStrict<R extends t.Props, O extends t.Props> extends t.Type<t.TypeOfProps<R> & TypeOfPartialUndefinedableProps<O>, t.OutputOfProps<R> & OutputOfPartialUndefinedableProps<O>> { | ||
export declare class LoiTypeObjectStrict<R extends t.Props, O extends t.Props> extends t.Type<t.TypeOfProps<R> & TypeOfPartialProps<O>, t.OutputOfProps<R> & OutputOfPartialProps<O>> { | ||
readonly props: R; | ||
@@ -33,3 +33,3 @@ readonly optionalProps: O; | ||
} | ||
export declare class LoiTypeObjectViolet<R extends t.Props, O extends t.Props> extends t.Type<t.TypeOfProps<R> & TypeOfPartialUndefinedableProps<O>, t.OutputOfProps<R> & OutputOfPartialUndefinedableProps<O>> { | ||
export declare class LoiTypeObjectViolet<R extends t.Props, O extends t.Props> extends t.Type<t.TypeOfProps<R> & TypeOfPartialProps<O>, t.OutputOfProps<R> & OutputOfPartialProps<O>> { | ||
readonly props: R; | ||
@@ -44,2 +44,4 @@ readonly optionalProps: O; | ||
export declare class LoiFactoryObject<R extends t.Props, O extends t.Props, T extends t.Any> extends LoiFactory<T> { | ||
props: R; | ||
optionalProps: O; | ||
type<F>(constructor: { | ||
@@ -51,6 +53,71 @@ new (...args: any[]): F; | ||
}): LoiFactoryTypeObject<R, O, t.Type<this["_A"] & F, this["_O"] & F, this["_I"]>>; | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
asBaseType(): t.Type<T['_A'], T['_O'], T['_I']> & { | ||
props: R; | ||
optionalProps: O; | ||
}; | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
finish(): t.Type<T["_A"], T["_O"], T["_I"]> & { | ||
props: R; | ||
optionalProps: O; | ||
}; | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
end(): t.Type<T["_A"], T["_O"], T["_I"]> & { | ||
props: R; | ||
optionalProps: O; | ||
}; | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
simple(): t.Type<T["_A"], T["_O"], T["_I"]> & { | ||
props: R; | ||
optionalProps: O; | ||
}; | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
clean(): t.Type<T["_A"], T["_O"], T["_I"]> & { | ||
props: R; | ||
optionalProps: O; | ||
}; | ||
} | ||
export declare class LoiFactoryObjectInitial<R extends t.Props, O extends t.Props, T extends t.Any> extends LoiFactory<T> { | ||
props: R; | ||
optionalProps: O; | ||
strict(): LoiFactoryTypeObject<R, O, t.Type<T["_A"], T["_O"], T["_I"]>>; | ||
violet(): LoiFactoryTypeObject<R, O, t.Type<T["_A"], T["_O"], T["_I"]>>; | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
finish(): t.Type<T['_A'], T['_O'], T['_I']> & { | ||
props: R; | ||
optionalProps: O; | ||
}; | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
end(): t.Type<T['_A'], T['_O'], T['_I']> & { | ||
props: R; | ||
optionalProps: O; | ||
}; | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
simple(): t.Type<T['_A'], T['_O'], T['_I']> & { | ||
props: R; | ||
optionalProps: O; | ||
}; | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
clean(): t.Type<T['_A'], T['_O'], T['_I']> & { | ||
props: R; | ||
optionalProps: O; | ||
}; | ||
} | ||
@@ -57,0 +124,0 @@ export declare function object(name?: string): LoiFactoryTypeObjectInitial<{}, {}, t.Type<{}, {}, t.mixed>>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const t = require("io-ts"); | ||
const undefinedable_1 = require("../decorators/undefinedable"); | ||
const factory_1 = require("../utilties/factory"); | ||
@@ -17,10 +16,5 @@ const lodash_1 = require("../utilties/lodash"); | ||
exports.getNameFromProps = getNameFromProps; | ||
/** @internal */ | ||
function undefinedablePartial(props, name) { | ||
return t.partial(lodash_1.objectMapValues(props, (i) => new undefinedable_1.LoiDecoratorUndefinedable(i)), name); | ||
} | ||
exports.undefinedablePartial = undefinedablePartial; | ||
class LoiTypeObject extends t.Type { | ||
constructor(props, optionalProps, name = getNameFromProps(props, optionalProps)) { | ||
super(name, (loose = t.intersection([t.interface(props), undefinedablePartial(optionalProps)])).is, loose.validate, loose.encode); | ||
super(name, (loose = t.intersection([t.interface(props), t.partial(optionalProps)])).is, loose.validate, loose.encode); | ||
this.props = props; | ||
@@ -53,3 +47,3 @@ this.optionalProps = optionalProps; | ||
return errors.length ? t.failures(errors) : t.success(o); | ||
}), (loose = t.intersection([t.interface(props), undefinedablePartial(optionalProps)])).encode); | ||
}), (loose = t.intersection([t.interface(props), t.partial(optionalProps)])).encode); | ||
this.props = props; | ||
@@ -80,3 +74,3 @@ this.optionalProps = optionalProps; | ||
return t.success(newObject); | ||
}), (loose = t.intersection([t.interface(props), undefinedablePartial(optionalProps)])).encode); | ||
}), (loose = t.intersection([t.interface(props), t.partial(optionalProps)])).encode); | ||
this.props = props; | ||
@@ -94,6 +88,2 @@ this.optionalProps = optionalProps; | ||
exports.LoiTypeObjectViolet = LoiTypeObjectViolet; | ||
/** @internal */ | ||
exports.loiObjectRequired = Symbol('loiObjectRequired'); | ||
/** @internal */ | ||
exports.loiObjectOptional = Symbol('loiObjectOptional'); | ||
class LoiFactoryObject extends factory_1.LoiFactory { | ||
@@ -118,2 +108,24 @@ /** @internal */ | ||
} | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
asBaseType() { | ||
return this; | ||
} | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
finish() { return this.asBaseType(); } | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
end() { return this.asBaseType(); } | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
simple() { return this.asBaseType(); } | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
clean() { return this.asBaseType(); } | ||
} | ||
@@ -127,3 +139,3 @@ exports.LoiFactoryObject = LoiFactoryObject; | ||
strict() { | ||
const type = new LoiTypeObjectStrict(this[exports.loiObjectRequired], this[exports.loiObjectOptional], this.name); | ||
const type = new LoiTypeObjectStrict(this.props, this.optionalProps, this.name); | ||
return factory_1.metadata(LoiFactoryObject.decorate(type), { | ||
@@ -135,3 +147,3 @@ parent: this, | ||
violet() { | ||
const type = new LoiTypeObjectViolet(this[exports.loiObjectRequired], this[exports.loiObjectOptional], this.name); | ||
const type = new LoiTypeObjectViolet(this.props, this.optionalProps, this.name); | ||
return factory_1.metadata(LoiFactoryObject.decorate(type), { | ||
@@ -142,2 +154,26 @@ parent: this, | ||
} | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
finish() { | ||
return this; | ||
} | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
end() { | ||
return this; | ||
} | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
simple() { | ||
return this; | ||
} | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
*/ | ||
clean() { | ||
return this; | ||
} | ||
} | ||
@@ -185,4 +221,4 @@ exports.LoiFactoryObjectInitial = LoiFactoryObjectInitial; | ||
}); | ||
decorated[exports.loiObjectRequired] = required; | ||
decorated[exports.loiObjectOptional] = optional; | ||
decorated.props = required; | ||
decorated.optionalProps = optional; | ||
return decorated; | ||
@@ -189,0 +225,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { mixed, Type, UnionType } from 'io-ts'; | ||
import { Mixed, mixed, Type, UnionType } from 'io-ts'; | ||
export declare type Tagged<Tag extends string, A = any, O = A> = Type<A, O> & { | ||
@@ -7,4 +7,4 @@ _A: { | ||
}; | ||
export declare const isTagged: <Tag extends string>(tag: Tag) => (type: Type<any, any, mixed>) => type is Tagged<Tag, any, any>; | ||
export declare const isTagged: <Tag extends string>(tag: Tag) => (type: Mixed) => type is Tagged<Tag, any, any>; | ||
export declare const getTagValue: <Tag extends string>(tag: Tag) => (type: Tagged<Tag, any, any>) => string | number | boolean; | ||
export declare const taggedUnion: <Tag extends string, RTS extends Tagged<Tag, any, any>[]>(tag: Tag, types: RTS, name?: string) => UnionType<RTS, RTS["_A"]["_A"], RTS["_A"]["_O"], mixed>; |
@@ -14,4 +14,4 @@ "use strict"; | ||
// @ts-ignore | ||
/* istanbul ignore next */ const pitfall = undefined; | ||
/* istanbul ignore next */ super(pitfall, pitfall, pitfall, pitfall); | ||
/* istanbul ignore next */ const pitfall = undefined; /* istanbul ignore next */ | ||
super(pitfall, pitfall, pitfall, pitfall); | ||
} | ||
@@ -64,4 +64,8 @@ } | ||
function metadata(t, params) { | ||
let previousOptions = (params && params.parent && params.parent[exports.loiOption] || []); | ||
if (params && params.optionFilter) { | ||
previousOptions = Array.prototype.filter.call(previousOptions, params.optionFilter); | ||
} | ||
const tag = (params && params.tag) || (t && t[exports.loiTag]) || (params && params.parent && params.parent[exports.loiTag]) || (t && t.name) || "unknown"; | ||
const options = [...(params && params.parent && params.parent[exports.loiOption] || []), ...(params && params.option ? [params && params.option] : [])]; | ||
const options = [...previousOptions, ...(params && params.option ? [params && params.option] : [])]; | ||
t.name = `${tag}${options.length ? `(${options.map((i) => i.name || JSON.stringify(i)).join(", ")})` : ""}`; | ||
@@ -68,0 +72,0 @@ t[exports.loiTag] = tag; |
{ | ||
"name": "loi", | ||
"version": "0.8.0", | ||
"version": "0.9.1", | ||
"files": [ | ||
@@ -22,3 +22,3 @@ "lib" | ||
"tslint": "^5.11.0", | ||
"typescript": "^3.0.1" | ||
"typescript": "^3.2.1" | ||
}, | ||
@@ -36,4 +36,4 @@ "scripts": { | ||
"dependencies": { | ||
"io-ts": "^1.3.0" | ||
"io-ts": ">=1.3.0, <=1.3.3" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
168712
89
2289
+ Addedio-ts@1.3.3(transitive)
- Removedio-ts@1.10.4(transitive)
Updatedio-ts@>=1.3.0, <=1.3.3