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

tiva

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiva - npm Package Compare versions

Comparing version 0.1.4 to 0.2.0

bld/library/@utils.d.ts

1

bld/library/@typescript/index.d.ts
export * from './server-host';
export * from './logger';
export * from './utils';

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

tslib_1.__exportStar(require("./logger"), exports);
tslib_1.__exportStar(require("./utils"), exports);
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import { ValidatorOptions, GeneralValidatorTypeOptions } from './validator';
import { GeneralValidatorTypeOptions, ValidatorOptions } from './validator';
export declare type Request = InitializeRequest | DiagnoseRequest;

@@ -3,0 +3,0 @@ export interface InitializeRequest {

/// <reference types="node" />
import { EventEmitter } from 'events';
import { ValidatorOptions, GeneralValidatorTypeOptions } from './validator';
import { ExtendableError } from 'extendable-error';
import { GeneralValidatorTypeOptions, ValidatorOptions } from './validator';
export interface TivaOptions extends ValidatorOptions {

@@ -16,1 +17,5 @@ }

}
export declare class ValidateError extends ExtendableError {
readonly diagnostics: string[];
constructor(diagnostics: string[]);
}

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

const worker_threads_1 = require("worker_threads");
const extendable_error_1 = require("extendable-error");
class Tiva extends events_1.EventEmitter {

@@ -38,3 +39,3 @@ constructor(options = {}) {

if (messages) {
throw new Error(messages.join('\n'));
throw new ValidateError(messages);
}

@@ -82,2 +83,9 @@ }

exports.Tiva = Tiva;
class ValidateError extends extendable_error_1.ExtendableError {
constructor(diagnostics) {
super('Type validation failed');
this.diagnostics = diagnostics;
}
}
exports.ValidateError = ValidateError;
//# sourceMappingURL=tiva.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const validator_1 = require("validator");
const tslib_1 = require("tslib");
const validator_1 = tslib_1.__importDefault(require("validator"));
exports.builtInExtensions = {

@@ -22,3 +23,3 @@ pattern(value, pattern) {

}
if (!validator_1.isUUID(value, version)) {
if (!validator_1.default.isUUID(value, version)) {
return `Value ${JSON.stringify(value)} is not a valid UUID${version && version !== 'all' ? ` (v${version})` : ''}`;

@@ -25,0 +26,0 @@ }

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

const _typescript_1 = require("../@typescript");
const _utils_1 = require("../@utils");
const _built_in_extensions_1 = require("./@built-in-extensions");

@@ -51,3 +52,3 @@ class Validator {

`import {${type.match(/^[^.]+/)[0]}} from ${JSON.stringify(moduleSpecifier)};`,
`export const __tiva: ${type} = ${JSON.stringify(value)};`,
`export const __tiva: ${type} = ${JSON.stringify(value, undefined, 2)};`,
]

@@ -62,3 +63,3 @@ .filter((part) => !!part)

.getSemanticDiagnostics(scriptInfo.fileName)
.map(message => _typescript_1.getDeepestMessageText(message.messageText));
.map(diagnostic => _utils_1.formatDiagnostic(diagnostic));
if (reasons.length) {

@@ -106,13 +107,19 @@ return reasons;

if (tagExtensionPairs.length) {
let extensionReasons = this.extensionReasons;
let sourceFileName = node.getSourceFile().fileName;
let values = this.findValuesByDefinition(node);
for (let value of values) {
let valueInfos = this.findValuesByDefinition(node);
for (let { node: valueNode, value } of valueInfos) {
let rawReasons = [];
for (let [{ name, comment }, extension] of tagExtensionPairs) {
let tagUniqueId = `${sourceFileName}:${node.getStart()}:${name}`;
let reason = extension(value, comment, this.context, tagUniqueId);
if (typeof reason === 'string') {
extensionReasons.push(reason);
let rawReason = extension(value, comment, this.context, tagUniqueId);
if (typeof rawReason === 'string') {
rawReasons.push(rawReason);
}
}
if (rawReasons.length) {
this.extensionReasons.push([
_utils_1.getValuePathMessage(valueNode),
_utils_1.indent(rawReasons.join('\n'), ' '),
].join('\n'));
}
}

@@ -188,3 +195,8 @@ }

.filter((assignment) => !!assignment)
.map(assignment => JSON.parse(assignment.initializer.getText()));
.map(({ initializer }) => {
return {
node: initializer,
value: JSON.parse(initializer.getText()),
};
});
}

@@ -191,0 +203,0 @@ }

{
"name": "tiva",
"version": "0.1.4",
"version": "0.2.0",
"description": "Expensive plain object type validator leverages TypeScript language service.",

@@ -11,7 +11,6 @@ "license": "MIT",

"scripts": {
"build": "tsc --build",
"lint-prettier": "prettier --with-node-modules --check \"**/*.{ts,tsx,js,jsx,json,yml,md}\"",
"lint-ts": "eslint \"src/**/*.ts\"",
"lint": "yarn lint-prettier && yarn lint-ts",
"test": "rimraf bld && yarn build && yarn lint && yarn jest",
"build": "rimraf bld && tsc --build",
"lint-prettier": "prettier --check .",
"lint": "eslint .",
"test": "yarn lint-prettier && yarn build && yarn lint && jest",
"report-coverage": "cat coverage/lcov.info | coveralls"

@@ -27,23 +26,24 @@ },

"devDependencies": {
"@magicspace/configs": "^0.2.2",
"@magicspace/eslint-plugin": "^0.1.4",
"@types/jest": "^24.0.23",
"@types/node": "^12.12.3",
"@types/validator": "^10.11.3",
"coveralls": "^3.0.7",
"eslint": "^6.6.0",
"jest": "^24.9.0",
"prettier": "^1.19.0",
"ts-jest": "^24.1.0",
"@mufan/code": "^0.2.5",
"@mufan/eslint-plugin": "^0.1.32",
"@types/jest": "^26.0.10",
"@types/node": "^14.0.27",
"@types/validator": "^13.1.0",
"coveralls": "^3.1.0",
"eslint": "^7.7.0",
"jest": "^26.4.0",
"prettier": "^2.0.5",
"ts-jest": "^26.2.0",
"typescript": "^3.8.3"
},
"peerDependencies": {
"typescript": ">=3.8.0"
"typescript": ">=3.9.7"
},
"dependencies": {
"tslang": "^0.1.18",
"tslib": "^1.10.0",
"extendable-error": "^0.1.7",
"tslang": "^0.1.22",
"tslib": "^2.0.1",
"tsutils": "^3.17.1",
"validator": "^12.0.0"
"validator": "^13.1.1"
}
}
export * from './server-host';
export * from './logger';
export * from './utils';
/* istanbul ignore file */
import {sys, server, FileWatcher} from 'typescript/lib/tsserverlibrary';
import {FileWatcher, server, sys} from 'typescript/lib/tsserverlibrary';

@@ -5,0 +5,0 @@ const NOOP_FILE_WATCHER: FileWatcher = {

@@ -1,2 +0,2 @@

import {ValidatorOptions, GeneralValidatorTypeOptions} from './validator';
import {GeneralValidatorTypeOptions, ValidatorOptions} from './validator';

@@ -3,0 +3,0 @@ export type Request = InitializeRequest | DiagnoseRequest;

import {parentPort} from 'worker_threads';
import {
Request,
DiagnoseResponse,
ErrorResponse,
InitializeResponse,
Request,
} from './@worker-messages';

@@ -9,0 +9,0 @@ import {Validator} from './validator';

@@ -5,5 +5,7 @@ import {EventEmitter} from 'events';

import {InitializeRequest, Response, DiagnoseRequest} from './@worker-messages';
import {ValidatorOptions, GeneralValidatorTypeOptions} from './validator';
import {ExtendableError} from 'extendable-error';
import {DiagnoseRequest, InitializeRequest, Response} from './@worker-messages';
import {GeneralValidatorTypeOptions, ValidatorOptions} from './validator';
export interface TivaOptions extends ValidatorOptions {}

@@ -56,3 +58,3 @@

if (messages) {
throw new Error(messages.join('\n'));
throw new ValidateError(messages);
}

@@ -113,1 +115,7 @@ }

}
export class ValidateError extends ExtendableError {
constructor(readonly diagnostics: string[]) {
super('Type validation failed');
}
}

@@ -1,2 +0,2 @@

import {isUUID} from 'validator';
import Validator from 'validator';

@@ -34,3 +34,3 @@ import {ValidatorExtensions} from './validator';

if (!isUUID(value, version)) {
if (!Validator.isUUID(value, version)) {
return `Value ${JSON.stringify(value)} is not a valid UUID${

@@ -37,0 +37,0 @@ version && version !== 'all' ? ` (v${version})` : ''

import * as Path from 'path';
import {getTokenAtPosition, getJsDoc} from 'tsutils';
import {Dict} from 'tslang';
import {getJsDoc, getTokenAtPosition} from 'tsutils';
import {
Expression,
LanguageService,
Node,
Program,
PropertyAssignment,
ScriptKind,
SourceFile,
VariableStatement,
isArrayTypeNode,

@@ -20,13 +28,7 @@ isClassDeclaration,

isUnionTypeNode,
LanguageService,
Node,
Program,
PropertyAssignment,
ScriptKind,
server,
SourceFile,
VariableStatement,
} from 'typescript/lib/tsserverlibrary';
import {logger, serverHost, getDeepestMessageText} from '../@typescript';
import {logger, serverHost} from '../@typescript';
import {formatDiagnostic, getValuePathMessage, indent} from '../@utils';

@@ -150,3 +152,3 @@ import {builtInExtensions} from './@built-in-extensions';

)};`,
`export const __tiva: ${type} = ${JSON.stringify(value)};`,
`export const __tiva: ${type} = ${JSON.stringify(value, undefined, 2)};`,
]

@@ -170,3 +172,3 @@ .filter((part): part is string => !!part)

.getSemanticDiagnostics(scriptInfo.fileName)
.map(message => getDeepestMessageText(message.messageText));
.map(diagnostic => formatDiagnostic(diagnostic));

@@ -244,17 +246,31 @@ if (reasons.length) {

if (tagExtensionPairs.length) {
let extensionReasons = this.extensionReasons;
let sourceFileName = node.getSourceFile().fileName;
let values = this.findValuesByDefinition(node);
let valueInfos = this.findValuesByDefinition(node);
for (let value of values) {
for (let {node: valueNode, value} of valueInfos) {
let rawReasons: string[] = [];
for (let [{name, comment}, extension] of tagExtensionPairs) {
let tagUniqueId = `${sourceFileName}:${node.getStart()}:${name}`;
let reason = extension(value, comment, this.context, tagUniqueId);
let rawReason = extension(
value,
comment,
this.context,
tagUniqueId,
);
if (typeof reason === 'string') {
extensionReasons.push(reason);
if (typeof rawReason === 'string') {
rawReasons.push(rawReason);
}
}
if (rawReasons.length) {
this.extensionReasons.push(
[
getValuePathMessage(valueNode),
indent(rawReasons.join('\n'), ' '),
].join('\n'),
);
}
}

@@ -324,3 +340,3 @@ }

node: ts.PropertySignature | ts.PropertyDeclaration,
): unknown[] {
): FoundValueInfo[] {
let references =

@@ -350,4 +366,14 @@ this.languageService.getImplementationAtPosition(

.filter((assignment): assignment is PropertyAssignment => !!assignment)
.map(assignment => JSON.parse(assignment.initializer.getText()));
.map(({initializer}) => {
return {
node: initializer,
value: JSON.parse(initializer.getText()),
};
});
}
}
interface FoundValueInfo {
node: Expression;
value: unknown;
}

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

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