Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typedconverter

Package Overview
Dependencies
Maintainers
1
Versions
193
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typedconverter - npm Package Compare versions

Comparing version 1.0.0-beta.3 to 1.0.0-beta.4

lib/decorators.d.ts

6

lib/index.d.ts

@@ -0,4 +1,5 @@

import { Opt, val } from "./decorators";
import { VisitorExtension, VisitorInvocation } from "./invocation";
import { Class } from "./types";
import { optional, OptionalValidator, partial, PartialValidator, requiredValidationVisitor, validate, Validator, ValidatorDecorator } from "./validation";
import { optional, OptionalValidator, partial, PartialValidator, requiredValidationVisitor, Validator, validatorVisitor, ValidatorDecorator } from "./validation";
import { Result, ResultMessages } from "./visitor";

@@ -34,2 +35,3 @@ interface Option {

export default function createConverter(option: Option): (value: any) => Result;
export { convert, Option, VisitorExtension, VisitorInvocation, Result, ResultMessages, validate, optional, partial, requiredValidationVisitor, Validator, ValidatorDecorator, OptionalValidator, PartialValidator };
declare function validate(value: any, opt: Option): Result;
export { convert, Option, VisitorExtension, VisitorInvocation, Result, ResultMessages, optional, partial, requiredValidationVisitor, validatorVisitor, Validator, OptionalValidator, PartialValidator, val, Opt, validate, ValidatorDecorator };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const decorators_1 = require("./decorators");
exports.val = decorators_1.val;
const transformer_1 = require("./transformer");

@@ -10,3 +12,3 @@ const validation_1 = require("./validation");

exports.requiredValidationVisitor = validation_1.requiredValidationVisitor;
exports.validate = validation_1.validate;
exports.validatorVisitor = validation_1.validatorVisitor;
const visitor_1 = require("./visitor");

@@ -31,1 +33,9 @@ exports.Result = visitor_1.Result;

exports.default = createConverter;
function validate(value, opt) {
const visitors = [validation_1.requiredValidationVisitor, validation_1.validatorVisitor];
for (const visitor of (opt.visitors || [])) {
visitors.push(visitor);
}
return convert(value, { type: opt.type, decorators: opt.decorators, path: opt.path, visitors });
}
exports.validate = validate;

@@ -11,3 +11,3 @@ import { VisitorInvocation } from './invocation';

}
declare function validate(validator: Validator | string | symbol): (target: any, name: string, index?: any) => void;
declare function createValidation(validator: Validator | string | symbol): (target: any, name: string, index?: any) => void;
declare function optional(): (target: any, name: string, index?: any) => void;

@@ -20,2 +20,3 @@ declare function partial(type: Class): (...args: any[]) => void;

declare function requiredValidationVisitor(i: VisitorInvocation): Result;
export { validate, optional, partial, requiredValidationVisitor, Validator, ValidatorDecorator, OptionalValidator, PartialValidator };
declare function validatorVisitor(i: VisitorInvocation): Result;
export { createValidation, optional, partial, requiredValidationVisitor, validatorVisitor, Validator, ValidatorDecorator, OptionalValidator, PartialValidator };

@@ -6,2 +6,3 @@ "use strict";

const visitor_1 = require("./visitor");
const converter_1 = require("./converter");
const OptionalValidator = Symbol("tc:optional");

@@ -11,12 +12,12 @@ exports.OptionalValidator = OptionalValidator;

exports.PartialValidator = PartialValidator;
function validate(validator) {
function createValidation(validator) {
return tinspector_1.decorateProperty({ type: "tc:validator", validator });
}
exports.validate = validate;
exports.createValidation = createValidation;
function optional() {
return validate(OptionalValidator);
return createValidation(OptionalValidator);
}
exports.optional = optional;
function partial(type) {
return tinspector_1.mergeDecorator(tinspector_1.default.type(type, "Partial"), validate(PartialValidator));
return tinspector_1.mergeDecorator(tinspector_1.default.type(type, "Partial"), createValidation(PartialValidator));
}

@@ -39,1 +40,24 @@ exports.partial = partial;

exports.requiredValidationVisitor = requiredValidationVisitor;
function getValidators(i) {
return i.decorators
.filter((x) => x.validator !== OptionalValidator
&& x.validator !== PartialValidator && x.type === "tc:validator");
}
function validatorVisitor(i) {
const validators = getValidators(i);
if (validators.length > 0) {
const result = i.proceed();
const messages = [];
for (const validator of validators) {
if (typeof validator.validator === "function") {
const msg = validator.validator(converter_1.safeToString(i.value));
if (msg)
messages.push(msg);
}
}
return messages.length > 0 ? visitor_1.Result.error(i.path, messages) : result;
}
else
return i.proceed();
}
exports.validatorVisitor = validatorVisitor;
{
"name": "typedconverter",
"version": "1.0.0-beta.3",
"version": "1.0.0-beta.4",
"description": "Convert object into classes match with TypeScript type annotation",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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