Comparing version 0.0.2 to 0.1.0
import * as t from 'io-ts'; | ||
export declare type TypeOf<RT extends t.Any> = RT['_A']; | ||
export { BaseFactory } from './types/Base'; | ||
export { start, BaseFactory } from './types/Base'; | ||
export { any, AnyFactory } from './types/Any'; | ||
@@ -5,0 +5,0 @@ export { boolean, BooleanFactory } from './types/Boolean'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Base_1 = require("./types/Base"); | ||
exports.start = Base_1.start; | ||
exports.BaseFactory = Base_1.BaseFactory; | ||
@@ -5,0 +6,0 @@ var Any_1 = require("./types/Any"); |
@@ -13,2 +13,2 @@ import * as t from 'io-ts'; | ||
} | ||
export declare function any(): AnyFactoryType<t.Type<any, any, t.mixed>>; | ||
export declare const any: (() => AnyFactoryType<t.Type<any, any, t.mixed>>) & t.AnyType; |
@@ -5,2 +5,3 @@ "use strict"; | ||
const factory_1 = require("../utilties/factory"); | ||
const mimic_1 = require("../utilties/mimic"); | ||
const Base_1 = require("./Base"); | ||
@@ -20,3 +21,4 @@ class AnyFactory extends factory_1.Factory { | ||
exports.AnyFactory = AnyFactory; | ||
function any() { | ||
// tslint:disable-next-line:variable-name | ||
exports.any = mimic_1.mimic(function any() { | ||
const type = new t.AnyType(); | ||
@@ -26,4 +28,3 @@ return factory_1.metadata(AnyFactory.decorate(type), { | ||
}); | ||
} | ||
exports.any = any; | ||
}, new t.AnyType()); | ||
//# sourceMappingURL=Any.js.map |
@@ -29,3 +29,3 @@ "use strict"; | ||
parent: this, | ||
option: { name: `<=${limit} items`, length: limit } | ||
option: { name: `<=${limit} items`, max: limit } | ||
}); | ||
@@ -41,3 +41,3 @@ } | ||
parent: this, | ||
option: { name: `>=${limit} items`, length: limit } | ||
option: { name: `>=${limit} items`, min: limit } | ||
}); | ||
@@ -44,0 +44,0 @@ } |
@@ -7,2 +7,4 @@ import * as t from 'io-ts'; | ||
defaultResolver?: () => T; | ||
rescue?: T; | ||
rescueResolver?: () => T; | ||
nullAsUndefined?: boolean; | ||
@@ -26,2 +28,12 @@ } | ||
/** | ||
* Make it never fails with rescue value | ||
* @param value rescue value | ||
*/ | ||
rescue(value: this['_A']): BaseFactoryType<t.Type<this["_A"], this["_O"], this["_I"]>>; | ||
/** | ||
* Make it never fails with rescue resolver | ||
* @param value rescue value resolver | ||
*/ | ||
rescueResolver(resolver: () => this['_A']): BaseFactoryType<t.Type<this["_A"], this["_O"], this["_I"]>>; | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
@@ -63,1 +75,2 @@ */ | ||
} | ||
export declare function start<T extends t.Any = t.Any>(type: T, name?: string): BaseFactoryType<t.Type<T["_A"], T["_O"], T["_I"]>>; |
@@ -7,2 +7,3 @@ "use strict"; | ||
const factory_1 = require("../utilties/factory"); | ||
const rescue_1 = require("../utilties/rescue"); | ||
class BaseFactory extends factory_1.Factory { | ||
@@ -42,2 +43,24 @@ static decorate(t) { | ||
/** | ||
* Make it never fails with rescue value | ||
* @param value rescue value | ||
*/ | ||
rescue(value) { | ||
const type = rescue_1.withRescue(this, value); | ||
return factory_1.metadata(BaseFactory.decorate(type), { | ||
parent: this, | ||
option: { name: `with rescue`, rescue: value } | ||
}); | ||
} | ||
/** | ||
* Make it never fails with rescue resolver | ||
* @param value rescue value resolver | ||
*/ | ||
rescueResolver(resolver) { | ||
const type = rescue_1.withRescueResolver(this, resolver); | ||
return factory_1.metadata(BaseFactory.decorate(type), { | ||
parent: this, | ||
option: { name: `with rescue`, rescueResolver: resolver } | ||
}); | ||
} | ||
/** | ||
* Return the base io-ts type without Loi decorators. | ||
@@ -81,2 +104,10 @@ */ | ||
exports.BaseFactory = BaseFactory; | ||
function start(type, name = type[factory_1.loiTag] || type.name) { | ||
const clonedType = Object.create(type); | ||
return factory_1.metadata(BaseFactory.decorate(clonedType), { | ||
parent: type, | ||
tag: name | ||
}); | ||
} | ||
exports.start = start; | ||
//# sourceMappingURL=Base.js.map |
@@ -19,2 +19,2 @@ import * as t from 'io-ts'; | ||
} | ||
export declare function boolean(): BooleanFactoryType<t.Type<boolean, boolean, t.mixed>>; | ||
export declare const boolean: (() => BooleanFactoryType<t.Type<boolean, boolean, t.mixed>>) & t.BooleanType; |
@@ -7,2 +7,3 @@ "use strict"; | ||
const factory_1 = require("../utilties/factory"); | ||
const mimic_1 = require("../utilties/mimic"); | ||
const Base_1 = require("./Base"); | ||
@@ -61,3 +62,4 @@ const trueValues = ["true", "t", "yes", "y", "on", "1"]; | ||
exports.BooleanFactory = BooleanFactory; | ||
function boolean() { | ||
// tslint:disable-next-line:variable-name | ||
exports.boolean = mimic_1.mimic(function boolean() { | ||
const type = new t.BooleanType(); | ||
@@ -67,4 +69,3 @@ return factory_1.metadata(BooleanFactory.decorate(type), { | ||
}); | ||
} | ||
exports.boolean = boolean; | ||
}, new t.BooleanType()); | ||
//# sourceMappingURL=Boolean.js.map |
@@ -17,12 +17,12 @@ import * as t from 'io-ts'; | ||
static decorate<T extends t.Any>(t: T): NumberFactoryType<T>; | ||
max(limit: number): NumberFactoryType<t.Type<T["_A"], T["_O"], T["_I"]>>; | ||
min(limit: number): NumberFactoryType<t.Type<T["_A"], T["_O"], T["_I"]>>; | ||
greater(limit: number): NumberFactoryType<t.Type<T["_A"], T["_O"], T["_I"]>>; | ||
less(limit: number): NumberFactoryType<t.Type<T["_A"], T["_O"], T["_I"]>>; | ||
negative(): NumberFactoryType<t.Type<T["_A"], T["_O"], T["_I"]>>; | ||
positive(): NumberFactoryType<t.Type<T["_A"], T["_O"], T["_I"]>>; | ||
integer(): NumberFactoryType<t.Type<T["_A"], T["_O"], T["_I"]>>; | ||
finite(): NumberFactoryType<t.Type<T["_A"], T["_O"], T["_I"]>>; | ||
max(limit: number): NumberFactoryType<t.Type<this["_A"], this["_O"], this["_I"]>>; | ||
min(limit: number): NumberFactoryType<t.Type<this["_A"], this["_O"], this["_I"]>>; | ||
greater(limit: number): NumberFactoryType<t.Type<this["_A"], this["_O"], this["_I"]>>; | ||
less(limit: number): NumberFactoryType<t.Type<this["_A"], this["_O"], this["_I"]>>; | ||
negative(): NumberFactoryType<t.Type<this["_A"], this["_O"], this["_I"]>>; | ||
positive(): NumberFactoryType<t.Type<this["_A"], this["_O"], this["_I"]>>; | ||
integer(): NumberFactoryType<t.Type<this["_A"], this["_O"], this["_I"]>>; | ||
finite(): NumberFactoryType<t.Type<this["_A"], this["_O"], this["_I"]>>; | ||
parseFloat(): NumberFactoryType<t.Type<this["_A"], this["_O"], this["_I"]>>; | ||
} | ||
export declare function number(): NumberFactoryType<t.Type<number, number, t.mixed>>; | ||
export declare const number: (() => NumberFactoryType<t.Type<number, number, t.mixed>>) & t.NumberType; |
@@ -7,2 +7,3 @@ "use strict"; | ||
const factory_1 = require("../utilties/factory"); | ||
const mimic_1 = require("../utilties/mimic"); | ||
const Base_1 = require("./Base"); | ||
@@ -78,3 +79,4 @@ class NumberFactory extends factory_1.Factory { | ||
exports.NumberFactory = NumberFactory; | ||
function number() { | ||
// tslint:disable-next-line:variable-name | ||
exports.number = mimic_1.mimic(function number() { | ||
const type = new t.NumberType(); | ||
@@ -84,4 +86,3 @@ return factory_1.metadata(NumberFactory.decorate(type), { | ||
}); | ||
} | ||
exports.number = number; | ||
}, new t.NumberType()); | ||
//# sourceMappingURL=Number.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const t = require("io-ts"); | ||
// https://github.com/teamdigitale/digital-citizenship-functions/blob/5fb8b4eb42203646bd9483ce4f850e7a69b1fe21/lib/utils/default.ts | ||
// https://github.com/teamdigitale/italia-ts-commons/blob/1688059556e3b3532a73032ab923933f0403fcc5/src/types.ts#L158 | ||
/** | ||
@@ -6,0 +6,0 @@ * Sets properties default values when calling t.validate() method on models |
{ | ||
"name": "loi", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"files": [ | ||
@@ -5,0 +5,0 @@ "lib" |
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
79444
44
1084