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

@syntest/analysis

Package Overview
Dependencies
Maintainers
4
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@syntest/analysis - npm Package Compare versions

Comparing version 0.3.0-beta.0 to 0.3.0-beta.1

dist/lib/Events.d.ts

2

dist/index.d.ts

@@ -6,5 +6,5 @@ export * from "./lib/factories/AbstractSyntaxTreeFactory";

export * from "./lib/factories/TargetFactory";
export * from "./lib/util/Events";
export * from "./lib/Events";
export * from "./lib/RootContext";
export * from "./lib/Target";
//# sourceMappingURL=index.d.ts.map

@@ -39,5 +39,5 @@ "use strict";

__exportStar(require("./lib/factories/TargetFactory"), exports);
__exportStar(require("./lib/util/Events"), exports);
__exportStar(require("./lib/Events"), exports);
__exportStar(require("./lib/RootContext"), exports);
__exportStar(require("./lib/Target"), exports);
//# sourceMappingURL=index.js.map

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

import { Result } from "@syntest/diagnostics";
export interface AbstractSyntaxTreeFactory<S> {
convert(filePath: string, source: string): S;
convert(filePath: string, source: string): Result<S>;
}
//# sourceMappingURL=AbstractSyntaxTreeFactory.d.ts.map
import { ControlFlowProgram } from "@syntest/cfg";
import { Result } from "@syntest/diagnostics";
export interface ControlFlowGraphFactory<S> {
convert(filePath: string, AST: S): ControlFlowProgram;
convert(filePath: string, AST: S): Result<ControlFlowProgram>;
}
//# sourceMappingURL=ControlFlowGraphFactory.d.ts.map

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

import { Result } from "@syntest/diagnostics";
export interface DependencyFactory<S> {
extract(filePath: string, AST: S): string[];
extract(filePath: string, AST: S): Result<string[]>;
}
//# sourceMappingURL=DependencyFactory.d.ts.map

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

import { Result } from "@syntest/diagnostics";
export declare class SourceFactory {
produce(filePath: string): string;
produce(filePath: string): Result<string>;
}
//# sourceMappingURL=SourceFactory.d.ts.map

@@ -23,3 +23,3 @@ "use strict";

const path = require("node:path");
const diagnostics_1 = require("../util/diagnostics");
const diagnostics_1 = require("@syntest/diagnostics");
class SourceFactory {

@@ -29,11 +29,17 @@ produce(filePath) {

if (!parsed.base) {
throw new Error((0, diagnostics_1.fileIsNotAFile)(filePath));
return (0, diagnostics_1.failure)(new diagnostics_1.IOError("The given path is not a file", {
context: { path: filePath },
}));
}
if (!parsed.ext) {
throw new Error((0, diagnostics_1.fileDoesNotHaveExtension)(filePath));
return (0, diagnostics_1.failure)(new diagnostics_1.IOError("The given file does not have an extension", {
context: { path: filePath },
}));
}
if (!(0, node_fs_1.existsSync)(filePath)) {
throw new Error((0, diagnostics_1.fileDoesNotExist)(filePath));
return (0, diagnostics_1.failure)(new diagnostics_1.IOError("The given file does not exist", {
context: { path: filePath },
}));
}
return (0, node_fs_1.readFileSync)(filePath, "utf8");
return (0, diagnostics_1.success)((0, node_fs_1.readFileSync)(filePath, "utf8"));
}

@@ -40,0 +46,0 @@ }

@@ -0,5 +1,6 @@

import { Result } from "@syntest/diagnostics";
import { Target } from "../Target";
export interface TargetFactory<S> {
extract(filePath: string, AST: S): Target;
extract(filePath: string, AST: S): Result<Target>;
}
//# sourceMappingURL=TargetFactory.d.ts.map
import { ControlFlowProgram } from "@syntest/cfg";
import { Result } from "@syntest/diagnostics";
import { AbstractSyntaxTreeFactory } from "./factories/AbstractSyntaxTreeFactory";

@@ -21,3 +22,3 @@ import { ControlFlowGraphFactory } from "./factories/ControlFlowGraphFactory";

constructor(rootPath: string, sourceFactory: SourceFactory, abstractSyntaxTreeFactory: AbstractSyntaxTreeFactory<S>, controlFlowGraphFactory: ControlFlowGraphFactory<S>, targetFactory: TargetFactory<S>, dependencyFactory: DependencyFactory<S>);
protected resolvePath(filePath: string): string;
protected resolvePath(filePath: string): Result<string>;
protected verifyTargetPath(filePath: string): boolean;

@@ -28,3 +29,3 @@ /**

*/
getSource(filePath: string): string;
getSource(filePath: string): Result<string>;
/**

@@ -34,3 +35,3 @@ * Loads the abstract syntax tree from the given filePath

*/
getAbstractSyntaxTree(filePath: string): S;
getAbstractSyntaxTree(filePath: string): Result<S>;
/**

@@ -40,3 +41,3 @@ * Loads the control flow program from the given filePath

*/
getControlFlowProgram(filePath: string): ControlFlowProgram;
getControlFlowProgram(filePath: string): Result<ControlFlowProgram>;
/**

@@ -47,3 +48,3 @@ * Loads the target context from the given filePath

*/
getTarget(filePath: string): Target;
getTarget(filePath: string): Result<Target>;
/**

@@ -53,3 +54,3 @@ * gets all sub-targets from the given filePath

*/
getSubTargets(filePath: string): SubTarget[];
getSubTargets(filePath: string): Result<SubTarget[]>;
/**

@@ -59,4 +60,4 @@ * Loads all dependencies from the given filePath

*/
getDependencies(filePath: string): string[];
getDependencies(filePath: string): Result<string[]>;
}
//# sourceMappingURL=RootContext.d.ts.map

@@ -22,3 +22,3 @@ "use strict";

const path = require("node:path");
const diagnostics_1 = require("./util/diagnostics");
const diagnostics_1 = require("@syntest/diagnostics");
class RootContext {

@@ -41,5 +41,7 @@ constructor(rootPath, sourceFactory, abstractSyntaxTreeFactory, controlFlowGraphFactory, targetFactory, dependencyFactory) {

if (!this.verifyTargetPath(absolutePath)) {
throw new Error((0, diagnostics_1.pathNotInRootPath)(this._rootPath, absolutePath));
return (0, diagnostics_1.failure)(new diagnostics_1.IOError("The given filepath is not in the given root path", {
context: { rootPath: this._rootPath, filePath: filePath },
}));
}
return absolutePath;
return (0, diagnostics_1.success)(absolutePath);
}

@@ -54,10 +56,16 @@ verifyTargetPath(filePath) {

getSource(filePath) {
const absolutePath = this.resolvePath(filePath);
const result = this.resolvePath(filePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
const absolutePath = (0, diagnostics_1.unwrap)(result);
// this takes up too much memory we should do some kind of garbage collection if we want to save it all
if (!this._sources.has(absolutePath)) {
process.emit("sourceResolvingStart", this, absolutePath);
this._sources.set(absolutePath, this.sourceFactory.produce(absolutePath));
const result = this.sourceFactory.produce(absolutePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
this._sources.set(absolutePath, (0, diagnostics_1.unwrap)(result));
process.emit("sourceResolvingComplete", this, absolutePath, this._sources.get(absolutePath));
}
return this._sources.get(absolutePath);
return (0, diagnostics_1.success)(this._sources.get(absolutePath));
}

@@ -69,10 +77,19 @@ /**

getAbstractSyntaxTree(filePath) {
const absolutePath = this.resolvePath(filePath);
const result = this.resolvePath(filePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
const absolutePath = (0, diagnostics_1.unwrap)(result);
// this takes up too much memory we should do some kind of garbage collection if we want to save it all
if (!this._abstractSyntaxTrees.has(absolutePath)) {
process.emit("abstractSyntaxTreeResolvingStart", this, absolutePath);
this._abstractSyntaxTrees.set(absolutePath, this.abstractSyntaxTreeFactory.convert(absolutePath, this.getSource(absolutePath)));
const result = this.getSource(absolutePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
const astResult = this.abstractSyntaxTreeFactory.convert(absolutePath, (0, diagnostics_1.unwrap)(result));
if ((0, diagnostics_1.isFailure)(astResult))
return astResult;
this._abstractSyntaxTrees.set(absolutePath, (0, diagnostics_1.unwrap)(astResult));
process.emit("abstractSyntaxTreeResolvingComplete", this, absolutePath, this._abstractSyntaxTrees.get(absolutePath));
}
return this._abstractSyntaxTrees.get(absolutePath);
return (0, diagnostics_1.success)(this._abstractSyntaxTrees.get(absolutePath));
}

@@ -84,9 +101,18 @@ /**

getControlFlowProgram(filePath) {
const absolutePath = this.resolvePath(filePath);
const result = this.resolvePath(filePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
const absolutePath = (0, diagnostics_1.unwrap)(result);
if (!this._controlFlowProgramMap.has(absolutePath)) {
process.emit("controlFlowGraphResolvingStart", this, absolutePath);
this._controlFlowProgramMap.set(absolutePath, this.controlFlowGraphFactory.convert(absolutePath, this.getAbstractSyntaxTree(absolutePath)));
const result = this.getAbstractSyntaxTree(absolutePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
const cfgResult = this.controlFlowGraphFactory.convert(absolutePath, (0, diagnostics_1.unwrap)(result));
if ((0, diagnostics_1.isFailure)(cfgResult))
return cfgResult;
this._controlFlowProgramMap.set(absolutePath, (0, diagnostics_1.unwrap)(cfgResult));
process.emit("controlFlowGraphResolvingComplete", this, absolutePath, this._controlFlowProgramMap.get(absolutePath));
}
return this._controlFlowProgramMap.get(absolutePath);
return (0, diagnostics_1.success)(this._controlFlowProgramMap.get(absolutePath));
}

@@ -99,9 +125,18 @@ /**

getTarget(filePath) {
const absolutePath = this.resolvePath(filePath);
const result = this.resolvePath(filePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
const absolutePath = (0, diagnostics_1.unwrap)(result);
if (!this._targetMap.has(absolutePath)) {
process.emit("targetExtractionStart", this, absolutePath);
this._targetMap.set(absolutePath, this.targetFactory.extract(absolutePath, this.getAbstractSyntaxTree(absolutePath)));
const result = this.getAbstractSyntaxTree(absolutePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
const targetResult = this.targetFactory.extract(absolutePath, (0, diagnostics_1.unwrap)(result));
if ((0, diagnostics_1.isFailure)(targetResult))
return targetResult;
this._targetMap.set(absolutePath, (0, diagnostics_1.unwrap)(targetResult));
process.emit("targetExtractionComplete", this, absolutePath, this._targetMap.get(absolutePath));
}
return this._targetMap.get(absolutePath);
return (0, diagnostics_1.success)(this._targetMap.get(absolutePath));
}

@@ -113,3 +148,6 @@ /**

getSubTargets(filePath) {
return this.getTarget(filePath).subTargets;
const result = this.getTarget(filePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
return (0, diagnostics_1.success)((0, diagnostics_1.unwrap)(result).subTargets);
}

@@ -121,9 +159,18 @@ /**

getDependencies(filePath) {
const absolutePath = this.resolvePath(filePath);
const result = this.resolvePath(filePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
const absolutePath = (0, diagnostics_1.unwrap)(result);
if (!this._dependenciesMap.has(absolutePath)) {
process.emit("dependencyResolvingStart", this, absolutePath);
this._dependenciesMap.set(absolutePath, this.dependencyFactory.extract(absolutePath, this.getAbstractSyntaxTree(absolutePath)));
const result = this.getAbstractSyntaxTree(absolutePath);
if ((0, diagnostics_1.isFailure)(result))
return result;
const dependencyResult = this.dependencyFactory.extract(absolutePath, (0, diagnostics_1.unwrap)(result));
if ((0, diagnostics_1.isFailure)(dependencyResult))
return dependencyResult;
this._dependenciesMap.set(absolutePath, (0, diagnostics_1.unwrap)(dependencyResult));
process.emit("dependencyResolvingComplete", this, absolutePath, this._dependenciesMap.get(absolutePath));
}
return this._dependenciesMap.get(absolutePath);
return (0, diagnostics_1.success)(this._dependenciesMap.get(absolutePath));
}

@@ -130,0 +177,0 @@ }

{
"name": "@syntest/analysis",
"version": "0.3.0-beta.0",
"version": "0.3.0-beta.1",
"description": "SynTest library for analyzing code",

@@ -51,4 +51,5 @@ "keywords": [

"dependencies": {
"@syntest/cfg": "^0.4.1-beta.3",
"@syntest/logging": "^0.2.0-beta.1",
"@syntest/cfg": "^0.5.0-beta.0",
"@syntest/diagnostics": "^0.1.0-beta.0",
"@syntest/logging": "^0.2.0-beta.2",
"lodash.clonedeep": "^4.5.0"

@@ -65,3 +66,3 @@ },

},
"gitHead": "20ce3f59489341e9e9ba8f3a441b516a5d625d9a"
"gitHead": "3f6b9612c030ffc79d5e79c5c1c126ca816a87a6"
}

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

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