New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

typescript-parser

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript-parser - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

34

DeclarationIndex.d.ts
import { DeclarationInfo } from './declarations/DeclarationInfo';
import { TypescriptParser } from './TypescriptParser';
/**
* IndexDelta type, is calculated by the declaration index to give an overview, what has changed in the index.
* Returns a list of deleted declarations, newly added declarations (with the corresponding infos) and
* which declarations have been updated (with all declarations under that name).
*/
export declare type IndexDelta = {
added: {
[declaration: string]: DeclarationInfo[];
};
updated: {
[declaration: string]: DeclarationInfo[];
};
deleted: string[];
};
/**
* Interface for file changes. Contains lists of file uri's to the specific action.

@@ -71,2 +85,17 @@ *

/**
* Calculates the differences between two indices. Calculates removed, added and updated declarations.
* The updated declarations are calculated and all declarations that the new index contains are inserted in the list.
*
* @static
* @param {{ [declaration: string]: DeclarationInfo[] }} oldIndex
* @param {{ [declaration: string]: DeclarationInfo[] }} newIndex
* @returns {IndexDelta}
* @memberof DeclarationIndex
*/
static calculateIndexDelta(oldIndex: {
[declaration: string]: DeclarationInfo[];
}, newIndex: {
[declaration: string]: DeclarationInfo[];
}): IndexDelta;
/**
* Resets the whole index. Does delete everything. Period.

@@ -90,9 +119,10 @@ * Is useful for unit testing or similar things.

* Is called when file events happen. Does reindex for the changed files and creates a new index.
* Returns the differences for the new index.
*
* @param {FileEvent[]} changes
* @returns {Promise<void>}
* @returns {Promise<IndexDelta>}
*
* @memberof DeclarationIndex
*/
reindexForChanges(changes: FileChanges): Promise<void>;
reindexForChanges(changes: FileChanges): Promise<IndexDelta>;
/**

@@ -99,0 +129,0 @@ * Returns a list of files that export a certain resource (declaration).

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const lodash_1 = require("lodash");
const path_1 = require("path");

@@ -85,2 +86,31 @@ const DeclarationInfo_1 = require("./declarations/DeclarationInfo");

/**
* Calculates the differences between two indices. Calculates removed, added and updated declarations.
* The updated declarations are calculated and all declarations that the new index contains are inserted in the list.
*
* @static
* @param {{ [declaration: string]: DeclarationInfo[] }} oldIndex
* @param {{ [declaration: string]: DeclarationInfo[] }} newIndex
* @returns {IndexDelta}
* @memberof DeclarationIndex
*/
static calculateIndexDelta(oldIndex, newIndex) {
const oldKeys = Object.keys(oldIndex);
const newKeys = Object.keys(newIndex);
return {
added: lodash_1.difference(newKeys, oldKeys).reduce((obj, currentKey) => {
obj[currentKey] = newIndex[currentKey];
return obj;
}, {}),
updated: lodash_1.intersection(oldKeys, newKeys).reduce((obj, currentKey) => {
const old = oldIndex[currentKey];
const neu = newIndex[currentKey];
if (lodash_1.differenceWith(neu, old, lodash_1.isEqual).length > 0 || lodash_1.differenceWith(old, neu, lodash_1.isEqual).length > 0) {
obj[currentKey] = neu;
}
return obj;
}, {}),
deleted: lodash_1.difference(oldKeys, newKeys),
};
}
/**
* Resets the whole index. Does delete everything. Period.

@@ -125,5 +155,6 @@ * Is useful for unit testing or similar things.

* Is called when file events happen. Does reindex for the changed files and creates a new index.
* Returns the differences for the new index.
*
* @param {FileEvent[]} changes
* @returns {Promise<void>}
* @returns {Promise<IndexDelta>}
*

@@ -171,7 +202,5 @@ * @memberof DeclarationIndex

}
const old = this._index || {};
this._index = yield this.createIndex(this.parsedResources);
// return {
// deleted: removeResources,
// updated: await this.createIndex(resources),
// };
return DeclarationIndex.calculateIndexDelta(old, this._index);
});

@@ -178,0 +207,0 @@ }

13

package.json
{
"name": "typescript-parser",
"version": "1.0.1",
"version": "1.1.0",
"description": "Parser for typescript (and javascript) files, that compiles those files and generates a human understandable AST.",

@@ -33,7 +33,14 @@ "main": "index.js",

"homepage": "https://github.com/TypeScript-Heroes/node-typescript-parser#readme",
"release": {
"generateNotes": "github-post-release"
},
"devDependencies": {
"@types/jest": "^20.0.1",
"@types/mock-fs": "^3.6.30",
"@types/node": "^8.0.1",
"del-cli": "^1.0.0",
"github-post-release": "^1.7.1",
"jest": "^20.0.4",
"mock-fs": "^4.4.1",
"semantic-release": "^6.3.6",
"ts-jest": "^20.0.6",

@@ -43,7 +50,7 @@ "tslint": "^5.4.3",

"tsutils": "^2.4.0",
"typedoc": "^0.7.1",
"semantic-release": "^6.3.6"
"typedoc": "^0.7.1"
},
"dependencies": {
"coveralls": "^2.13.1",
"lodash": "^4.17.4",
"tslib": "^1.7.1",

@@ -50,0 +57,0 @@ "typescript": "^2.4.1"

@@ -10,2 +10,3 @@ # node typescript parser

[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![Greenkeeper badge](https://badges.greenkeeper.io/TypeScript-Heroes/node-typescript-parser.svg)](https://greenkeeper.io/)

@@ -12,0 +13,0 @@ ## How to use

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

import { difference, differenceWith, intersection, isEqual } from 'lodash';
import { join, normalize, relative, resolve } from 'path';

@@ -37,6 +38,12 @@

// export type DeltaIndex = {
// deleted: string[];
// updated: { [declaration: string]: DeclarationInfo[] };
// };
/**
* IndexDelta type, is calculated by the declaration index to give an overview, what has changed in the index.
* Returns a list of deleted declarations, newly added declarations (with the corresponding infos) and
* which declarations have been updated (with all declarations under that name).
*/
export type IndexDelta = {
added: { [declaration: string]: DeclarationInfo[] };
updated: { [declaration: string]: DeclarationInfo[] };
deleted: string[];
};

@@ -124,2 +131,44 @@ /**

/**
* Calculates the differences between two indices. Calculates removed, added and updated declarations.
* The updated declarations are calculated and all declarations that the new index contains are inserted in the list.
*
* @static
* @param {{ [declaration: string]: DeclarationInfo[] }} oldIndex
* @param {{ [declaration: string]: DeclarationInfo[] }} newIndex
* @returns {IndexDelta}
* @memberof DeclarationIndex
*/
public static calculateIndexDelta(
oldIndex: { [declaration: string]: DeclarationInfo[] },
newIndex: { [declaration: string]: DeclarationInfo[] },
): IndexDelta {
const oldKeys = Object.keys(oldIndex);
const newKeys = Object.keys(newIndex);
return {
added: difference(newKeys, oldKeys).reduce(
(obj, currentKey) => {
obj[currentKey] = newIndex[currentKey];
return obj;
},
{} as { [declaration: string]: DeclarationInfo[] },
),
updated: intersection(oldKeys, newKeys).reduce(
(obj, currentKey) => {
const old = oldIndex[currentKey];
const neu = newIndex[currentKey];
if (differenceWith(neu, old, isEqual).length > 0 || differenceWith(old, neu, isEqual).length > 0) {
obj[currentKey] = neu;
}
return obj;
},
{} as { [declaration: string]: DeclarationInfo[] },
),
deleted: difference(oldKeys, newKeys),
};
}
/**
* Resets the whole index. Does delete everything. Period.

@@ -164,9 +213,10 @@ * Is useful for unit testing or similar things.

* Is called when file events happen. Does reindex for the changed files and creates a new index.
* Returns the differences for the new index.
*
* @param {FileEvent[]} changes
* @returns {Promise<void>}
* @returns {Promise<IndexDelta>}
*
* @memberof DeclarationIndex
*/
public async reindexForChanges(changes: FileChanges): Promise<void> {
public async reindexForChanges(changes: FileChanges): Promise<IndexDelta> {
const rebuildResources: string[] = [];

@@ -218,7 +268,6 @@ const removeResources: string[] = [];

}
const old = this._index || {};
this._index = await this.createIndex(this.parsedResources);
// return {
// deleted: removeResources,
// updated: await this.createIndex(resources),
// };
return DeclarationIndex.calculateIndexDelta(old, this._index);
}

@@ -225,0 +274,0 @@

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