Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
tinspector
Advanced tools
TypeScript type inspector
tinspector is a type inspector used to extract metadata from JavaScript (TypeScript generated) Function, Class, Module
import reflect from "tinspector"
class MyAwesomeClass {
constructor(id:number, name:string){}
myAwesomeMethod(stringPar:string){}
}
const metadata = reflect(MyAwesomeClass)
/*
metadata:
{
kind: "Class",
name: "MyAwesomeClass",
...
ctor: {
kind: "Contructor",
...
parameters: [{
kind: "Parameter",
name: "id",
...
},{
kind: "Parameter",
name: "name",
...
}]
},
methods: [{
kind: "Function",
name: "myAwesomeMethod",
...
parameters: [{
kind: "Parameter",
name: "stringPar",
...
}]
}]
}
*/
TypeScript provided design type information by using decorator. To get a proper type information on function parameter and its return type you can use noop decorator (decorator that does nothing).
import reflect, { decorate } from "tinspector"
@decorate({})
class MyAwesomeClass {
constructor(id:number, name:string){}
@decorate({})
myAwesomeMethod(stringPar:string): number { return 1 }
}
const metadata = reflect(MyAwesomeClass)
/*
metadata:
{
kind: "Class",
name: "MyAwesomeClass",
...
ctor: {
kind: "Contructor",
...
parameters:[{
kind: "Parameter",
name: "id",
type: Number, <--- type information
...
},{
kind: "Parameter",
name: "name",
type: String, <--- type information
...
}]
},
methods: [{
kind: "Function",
name: "myAwesomeMethod",
returnType: Number, <--- type information
...
parameters: [{
kind: "Parameter",
name: "stringPar",
type: String, <--- type information
...
}]
}]
}
*/
Use predefined decorator decorate
, decorateClass
, decorateMethod
, decorateProperty
, decorateParameter
to add
decorator information that understand by reflect
import reflect, { decorateMethod } from "tinspector"
class MyAwesomeClass {
@decorateMethod({ type: "Cache", cache: '60s' })
myAwesomeMethod(stringPar:string){}
}
const metadata = reflect(MyAwesomeClass)
/*
metadata:
{
kind: "Class",
name: "MyAwesomeClass",
...
methods: [{
kind: "Function",
name: "myAwesomeMethod",
decorators: [{
type: "Cache",
cache: '60s'
}]
...
}]
}
*/
TypeScript parameter properties information erased after transpile, so you need to tell tinspector
that you have parameter properties by decorate class using @reflect.parameterProperties()
import reflect from "tinspector"
@reflect.parameterProperties()
class MyAwesomeClass {
constructor(public id:number, public name:string){}
}
const metadata = reflect(MyAwesomeClass)
/*
metadata:
{
kind: "Class",
name: "MyAwesomeClass",
...
ctor: {
kind: "Contructor",
...
parameters:[{
kind: "Parameter",
name: "id",
type: Number,
...
},{
kind: "Parameter",
name: "name",
type: String,
...
}]
},
properties: [{
kind: "Parameter",
name: "id",
type: Number,
...
},{
kind: "Parameter",
name: "name",
type: String,
...
}]
}
*/
@reflect.parameterProperties()
assume that all of the class parameter is parameter property, to exclude parameter from transformed into property use@reflect.ignore()
@reflect.parameterProperties()
class MyAwesomeClass {
constructor(public id:number, public name:string, @reflect.ignore() nonProperty:string){}
}
tinspector will traverse through base classes property to get proper meta data.
class BaseClass {
@decorate({})
myAwesomeMethod(stringPar:string): number { return 1 }
}
class MyAwesomeClass extends BaseClass{
@decorate({})
myOtherMethod(stringPar:string): number { return 1 }
}
const metadata = reflect(MyAwesomeClass)
/*
metadata:
{
kind: "Class",
name: "MyAwesomeClass",
...
methods: [{
kind: "Method",
name: "myAwesomeMethod",
...
},{
kind: "Method",
name: "myOtherMethod",
...
}]
}
*/
All Predefined decorators receives two type of argument, an object or a callback to hook function on decorator creation.
decorateParameter(callback: ((target: Class, name: string, index: number) => object))
decorateMethod(callback: ((target: Class, name: string) => object))
decorateProperty(callback: ((target: Class, name: string, index?: any) => object))
decorateClass(callback: ((target: Class) => object))
Using callback you can get more information about applied object.
tinpector uses regex to extract parameter name on constructor, function and methods. Some ES6 parameter feature still not supported.
Decorator is not inherited by design due to TypeScript behavior that use decorator to provide type information, which in some case will force duplication. Except on inherited method/properties that is not overridden in the child class. Example
FAQs
TypeScript type inspector
The npm package tinspector receives a total of 218 weekly downloads. As such, tinspector popularity was classified as not popular.
We found that tinspector demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.