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

@faast/ts-common

Package Overview
Dependencies
Maintainers
3
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@faast/ts-common - npm Package Compare versions

Comparing version 0.5.2 to 0.5.3

25

dist/lib/utils/validation.js
import { UnionType, IntersectionType } from 'io-ts';
import { stringify } from './string';
function isCodec(actual, expected) {
return actual instanceof expected || actual._tag === expected.name;
}
function getContextPath(context) {

@@ -9,3 +12,3 @@ return context

const previousType = context[i - 1].type;
return !(previousType instanceof UnionType || previousType instanceof IntersectionType);
return !(isCodec(previousType, UnionType) || isCodec(previousType, IntersectionType));
})

@@ -15,4 +18,22 @@ .map(({ key, type }) => (key ? key : type.name))

}
function stringifyNested(types, delim) {
return types.map((type) => type.name).join(delim);
}
function getContextTypeName(context) {
if (context.length <= 0) {
return '';
}
if (context.length > 1) {
const parent = context[context.length - 2].type;
if (isCodec(parent, UnionType)) {
return stringifyNested(parent.types, ' | ');
}
else if (isCodec(parent, IntersectionType)) {
return stringifyNested(parent.types, ' & ');
}
}
return context[context.length - 1].type.name;
}
export function getMessage(e) {
const expectedType = e.context.length > 0 ? e.context[e.context.length - 1].type.name : '';
const expectedType = getContextTypeName(e.context);
const contextPath = getContextPath(e.context);

@@ -19,0 +40,0 @@ const expectedMessage = expectedType !== contextPath ? `${expectedType} for ${contextPath}` : expectedType;

2

package.json
{
"name": "@faast/ts-common",
"version": "0.5.2",
"version": "0.5.3",
"description": "Common typescript types and utils used by faast",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -5,2 +5,9 @@ import { Context, ValidationError, UnionType, IntersectionType, Type } from 'io-ts'

function isCodec<T extends { new (...args: any[]): Type<any> }>(
actual: object,
expected: T,
): actual is InstanceType<T> {
return actual instanceof expected || (actual as any)._tag === expected.name
}
function getContextPath(context: Context): string {

@@ -10,4 +17,4 @@ return context

if (i === 0) return true
const previousType = context[i - 1].type
return !(previousType instanceof UnionType || previousType instanceof IntersectionType)
const previousType = context[i - 1].type as any
return !(isCodec(previousType, UnionType) || isCodec(previousType, IntersectionType))
})

@@ -18,4 +25,23 @@ .map(({ key, type }) => (key ? key : type.name))

function stringifyNested(types: any[], delim: string): string {
return types.map((type: Type<any>) => type.name).join(delim)
}
function getContextTypeName(context: Context): string {
if (context.length <= 0) {
return ''
}
if (context.length > 1) {
const parent = context[context.length - 2].type
if (isCodec(parent, UnionType)) {
return stringifyNested(parent.types, ' | ')
} else if (isCodec(parent, IntersectionType)) {
return stringifyNested(parent.types, ' & ')
}
}
return context[context.length - 1].type.name
}
export function getMessage(e: ValidationError): string {
const expectedType = e.context.length > 0 ? e.context[e.context.length - 1].type.name : ''
const expectedType = getContextTypeName(e.context)
const contextPath = getContextPath(e.context)

@@ -22,0 +48,0 @@ const expectedMessage = expectedType !== contextPath ? `${expectedType} for ${contextPath}` : expectedType

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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