@openrewrite/types
Advanced tools
+7
-0
@@ -5,2 +5,9 @@ # Changelog | ||
| ### [0.0.14](https://github.com/openrewrite/typescript-types/compare/v0.0.13...v0.0.14) (2021-09-14) | ||
| ### Features | ||
| * provide default export ([9bb1e56](https://github.com/openrewrite/typescript-types/commit/9bb1e56578750c8c4b72138ccb3e7d4d849d14e5)) | ||
| ### [0.0.13](https://github.com/openrewrite/typescript-types/compare/v0.0.12...v0.0.13) (2021-09-14) | ||
@@ -7,0 +14,0 @@ |
+2
-0
| /// <reference path="./lib/java.d.ts" /> | ||
| export * from './lib/openrewrite'; | ||
| import * as OpenRewrite from './lib/openrewrite'; | ||
| export default OpenRewrite; |
+1
-1
@@ -1,2 +0,2 @@ | ||
| declare var Delegate: any; | ||
| // declare var Delegate: any; | ||
@@ -3,0 +3,0 @@ /** |
+224
-225
| export type Maybe<T> = T | null; | ||
| export namespace OpenRewrite { | ||
| export declare const Delegate: OpenRewrite.TreeVisitor<any, unknown>; | ||
| export class Cursor { | ||
| private parent: Maybe<Cursor>; | ||
| private value: Object; | ||
| private messages: Map<string, Object>; | ||
| constructor(parent: Maybe<Cursor>, value: Object) { | ||
| this.parent = parent; | ||
| this.value = value; | ||
| } | ||
| export declare const Delegate: TreeVisitor<any, unknown>; | ||
| export class Cursor { | ||
| private parent: Maybe<Cursor>; | ||
| private value: Object; | ||
| private messages: Map<string, Object>; | ||
| public getRoot(): Cursor { | ||
| let cursor: Cursor = this; | ||
| while (cursor.parent !== null) { | ||
| cursor = cursor.parent; | ||
| } | ||
| return cursor; | ||
| } | ||
| constructor(parent: Maybe<Cursor>, value: Object) { | ||
| this.parent = parent; | ||
| this.value = value; | ||
| } | ||
| public getParent(levels: number = 1): Maybe<Cursor> { | ||
| let cursor: Cursor = this; | ||
| for (let i = 0; i < levels && cursor != null; i++) { | ||
| cursor = cursor.parent; | ||
| } | ||
| return cursor; | ||
| public getRoot(): Cursor { | ||
| let cursor: Cursor = this; | ||
| while (cursor.parent !== null) { | ||
| cursor = cursor.parent; | ||
| } | ||
| return cursor; | ||
| } | ||
| public getValue<T>(): T { | ||
| return this.value as T; | ||
| public getParent(levels: number = 1): Maybe<Cursor> { | ||
| let cursor: Cursor = this; | ||
| for (let i = 0; i < levels && cursor != null; i++) { | ||
| cursor = cursor.parent; | ||
| } | ||
| return cursor; | ||
| } | ||
| public fork(): Cursor { | ||
| return new Cursor(parent == null ? null : this.parent.fork(), this.value); | ||
| } | ||
| public getValue<T>(): T { | ||
| return this.value as T; | ||
| } | ||
| public static isScopeInCursorPath(scope: Tree, cursor: Cursor): boolean { | ||
| if (!scope || !cursor || !isTree(scope) || !isTree(cursor.value)) { | ||
| return false; | ||
| } | ||
| return scope.getId() === cursor.value.getId() ? true : Cursor.isScopeInCursorPath(scope, cursor.getParent()); | ||
| } | ||
| public fork(): Cursor { | ||
| return new Cursor(parent == null ? null : this.parent.fork(), this.value); | ||
| } | ||
| public isScopeInPath(scope: Tree): boolean { | ||
| return Cursor.isScopeInCursorPath(scope, this); | ||
| public static isScopeInCursorPath(scope: Tree, cursor: Cursor): boolean { | ||
| if (!scope || !cursor || !isTree(scope) || !isTree(cursor.value)) { | ||
| return false; | ||
| } | ||
| return scope.getId() === cursor.value.getId() ? true : Cursor.isScopeInCursorPath(scope, cursor.getParent()); | ||
| } | ||
| export function isTree(tree: any): tree is Tree { | ||
| return tree.getId && tree.print; | ||
| public isScopeInPath(scope: Tree): boolean { | ||
| return Cursor.isScopeInCursorPath(scope, this); | ||
| } | ||
| } | ||
| export interface Tree { | ||
| /** | ||
| * An id that can be used to identify a particular AST element, even after | ||
| * transformations have taken place on it | ||
| */ | ||
| getId(): unknown; | ||
| export function isTree(tree: any): tree is Tree { | ||
| return tree.getId && tree.print; | ||
| } | ||
| print(): string; | ||
| printTrimmed(): string; | ||
| isAcceptable?<P>(v: TreeVisitor<any, P>, p: P): boolean; | ||
| isScope?(tree: Maybe<Tree>): boolean; | ||
| } | ||
| export interface Tree { | ||
| /** | ||
| * An id that can be used to identify a particular AST element, even after | ||
| * transformations have taken place on it | ||
| */ | ||
| getId(): unknown; | ||
| export class TreeVisitor<T extends Tree, P> { | ||
| private static IS_DEBUGGING: boolean = false; | ||
| private cursor: Cursor; | ||
| private afterVisit: TreeVisitor<T, P>[] = []; | ||
| private visitCount: number; | ||
| print(): string; | ||
| printTrimmed(): string; | ||
| isAcceptable?<P>(v: TreeVisitor<any, P>, p: P): boolean; | ||
| isScope?(tree: Maybe<Tree>): boolean; | ||
| } | ||
| protected setCursor(cursor: Maybe<Cursor>): void { | ||
| this.cursor = cursor; | ||
| } | ||
| export class TreeVisitor<T extends Tree, P> { | ||
| private static IS_DEBUGGING: boolean = false; | ||
| private cursor: Cursor; | ||
| private afterVisit: TreeVisitor<T, P>[] = []; | ||
| private visitCount: number; | ||
| protected doAfterVisit(visitor: TreeVisitor<T, P> | Recipe): void { | ||
| if (isRecipe(visitor)) { | ||
| this.afterVisit.push(visitor.getVisitor() as unknown as TreeVisitor<T, P>); | ||
| } else { | ||
| this.afterVisit.push(visitor); | ||
| } | ||
| } | ||
| protected setCursor(cursor: Maybe<Cursor>): void { | ||
| this.cursor = cursor; | ||
| } | ||
| protected getAfterVisit(): TreeVisitor<T, P>[] { | ||
| return []; | ||
| protected doAfterVisit(visitor: TreeVisitor<T, P> | Recipe): void { | ||
| if (isRecipe(visitor)) { | ||
| this.afterVisit.push(visitor.getVisitor() as unknown as TreeVisitor<T, P>); | ||
| } else { | ||
| this.afterVisit.push(visitor); | ||
| } | ||
| } | ||
| public getLanguage(): Maybe<string> { | ||
| return null; | ||
| } | ||
| protected getAfterVisit(): TreeVisitor<T, P>[] { | ||
| return []; | ||
| } | ||
| public getCursor(): Cursor { | ||
| if (this.cursor == null) { | ||
| throw new Error('Cursoring is not enabled for this visitor.'); | ||
| } | ||
| return this.cursor; | ||
| } | ||
| public getLanguage(): Maybe<string> { | ||
| return null; | ||
| } | ||
| public preVisit(tree: T, p: P): Maybe<T> { | ||
| return tree; | ||
| public getCursor(): Cursor { | ||
| if (this.cursor == null) { | ||
| throw new Error('Cursoring is not enabled for this visitor.'); | ||
| } | ||
| public postVisit(tree: T, p: P): Maybe<T> { | ||
| return tree; | ||
| } | ||
| public visit(tree: Maybe<T>, p: P, parent?: Cursor): Maybe<T> { | ||
| return tree; | ||
| } | ||
| return this.cursor; | ||
| } | ||
| export interface ExecutionContext { | ||
| putMessage(key: string, value: object): void; | ||
| getMessage(key: string): unknown | null; | ||
| public preVisit(tree: T, p: P): Maybe<T> { | ||
| return tree; | ||
| } | ||
| export interface RecipeDescriptor { | ||
| readonly name: string; | ||
| readonly displayName: string; | ||
| readonly description: string; | ||
| readonly tags: string[]; | ||
| readonly options: RecipeOptions[]; | ||
| readonly languages: string[]; | ||
| readonly recipeList: RecipeListEntry[]; | ||
| public postVisit(tree: T, p: P): Maybe<T> { | ||
| return tree; | ||
| } | ||
| export type RecipeListEntry = OpenRewrite.Recipe; | ||
| export interface RecipeListDescriptor<T = any> { | ||
| readonly name: string; | ||
| readonly options: { [key in keyof T]: T[key] }; | ||
| public visit(tree: Maybe<T>, p: P, parent?: Cursor): Maybe<T> { | ||
| return tree; | ||
| } | ||
| } | ||
| export function isRecipe(recipe: any): recipe is Recipe { | ||
| return Boolean(recipe.getVisitor); | ||
| } | ||
| export interface ExecutionContext { | ||
| putMessage(key: string, value: object): void; | ||
| getMessage(key: string): unknown | null; | ||
| } | ||
| export class Recipe<Options = any> { | ||
| public recipeList: RecipeListEntry[] = []; | ||
| public options: RecipeOptions[] = []; | ||
| export interface RecipeDescriptor { | ||
| readonly name: string; | ||
| readonly displayName: string; | ||
| readonly description: string; | ||
| readonly tags: string[]; | ||
| readonly options: RecipeOptions[]; | ||
| readonly languages: string[]; | ||
| readonly recipeList: RecipeListEntry[]; | ||
| } | ||
| constructor(options?: Options) {} | ||
| export type RecipeListEntry = Recipe; | ||
| public getName(): string { | ||
| return ''; | ||
| } | ||
| export interface RecipeListDescriptor<T = any> { | ||
| readonly name: string; | ||
| readonly options: { [key in keyof T]: T[key] }; | ||
| } | ||
| public getDisplayName(): string { | ||
| return ''; | ||
| } | ||
| export function isRecipe(recipe: any): recipe is Recipe { | ||
| return Boolean(recipe.getVisitor); | ||
| } | ||
| public getDescription(): string { | ||
| return ''; | ||
| } | ||
| export class Recipe<Options = any> { | ||
| public recipeList: RecipeListEntry[] = []; | ||
| public options: RecipeOptions[] = []; | ||
| public getTags(): string[] { | ||
| return []; | ||
| } | ||
| constructor(options?: Options) {} | ||
| public getLanguages(): string[] { | ||
| return []; | ||
| } | ||
| public getName(): string { | ||
| return ''; | ||
| } | ||
| public getRecipeList(): RecipeListEntry[] { | ||
| return this.recipeList; | ||
| } | ||
| public getDisplayName(): string { | ||
| return ''; | ||
| } | ||
| public doNext<T>(recipe: RecipeListEntry): Recipe { | ||
| this.recipeList.push(recipe); | ||
| return this; | ||
| } | ||
| public getDescription(): string { | ||
| return ''; | ||
| } | ||
| public static getOptions(recipe: Recipe): RecipeOptions[] { | ||
| return recipe.options; | ||
| } | ||
| public getTags(): string[] { | ||
| return []; | ||
| } | ||
| public getDescriptor(): RecipeDescriptor { | ||
| return { | ||
| name: this.getName(), | ||
| displayName: this.getDisplayName(), | ||
| description: this.getDescription(), | ||
| tags: this.getTags(), | ||
| options: this.options, | ||
| languages: this.getLanguages(), | ||
| recipeList: this.getRecipeList() | ||
| }; | ||
| } | ||
| public getLanguages(): string[] { | ||
| return []; | ||
| } | ||
| protected getSingleSourceApplicableTest(): Maybe<TreeVisitor<Tree, ExecutionContext>> { | ||
| return null; | ||
| } | ||
| public getRecipeList(): RecipeListEntry[] { | ||
| return this.recipeList; | ||
| } | ||
| public getVisitor(): Maybe<TreeVisitor<Tree, ExecutionContext>> { | ||
| return null; | ||
| } | ||
| public doNext<T>(recipe: RecipeListEntry): Recipe { | ||
| this.recipeList.push(recipe); | ||
| return this; | ||
| } | ||
| export interface RecipeOptions { | ||
| displayName: string; | ||
| description: string; | ||
| example?: Maybe<string>; | ||
| valid?: Maybe<string>; | ||
| required: boolean; | ||
| public static getOptions(recipe: Recipe): RecipeOptions[] { | ||
| return recipe.options; | ||
| } | ||
| export interface Space { | ||
| EMPTY: Space; | ||
| getIndent(): string; | ||
| getLastWhitespace(): string; | ||
| getWhitespaceIndent(whitespace: string | null): string; | ||
| getComments(): Comment[]; | ||
| getWhiteSpace(): string; | ||
| hasComment(comment: string): boolean; | ||
| withComments(comments: Comment[]): Space; | ||
| withWhitespace(whitespace: string): Space; | ||
| isEmpty(): boolean; | ||
| toString(): string; | ||
| public getDescriptor(): RecipeDescriptor { | ||
| return { | ||
| name: this.getName(), | ||
| displayName: this.getDisplayName(), | ||
| description: this.getDescription(), | ||
| tags: this.getTags(), | ||
| options: this.options, | ||
| languages: this.getLanguages(), | ||
| recipeList: this.getRecipeList() | ||
| }; | ||
| } | ||
| export interface Marker extends Tree { | ||
| isAcceptable(): false; | ||
| print(): ''; | ||
| protected getSingleSourceApplicableTest(): Maybe<TreeVisitor<Tree, ExecutionContext>> { | ||
| return null; | ||
| } | ||
| export class Markers implements Tree { | ||
| private id: string; | ||
| private markers: Marker[] = []; | ||
| public getVisitor(): Maybe<TreeVisitor<Tree, ExecutionContext>> { | ||
| return null; | ||
| } | ||
| } | ||
| public static build(markers): Markers { | ||
| return markers; | ||
| } | ||
| export interface RecipeOptions { | ||
| displayName: string; | ||
| description: string; | ||
| example?: Maybe<string>; | ||
| valid?: Maybe<string>; | ||
| required: boolean; | ||
| } | ||
| constructor(id, markers: Marker[]) { | ||
| this.id = id; | ||
| this.markers = markers; | ||
| } | ||
| export interface Space { | ||
| EMPTY: Space; | ||
| getIndent(): string; | ||
| getLastWhitespace(): string; | ||
| getWhitespaceIndent(whitespace: string | null): string; | ||
| getComments(): Comment[]; | ||
| getWhiteSpace(): string; | ||
| hasComment(comment: string): boolean; | ||
| withComments(comments: Comment[]): Space; | ||
| withWhitespace(whitespace: string): Space; | ||
| isEmpty(): boolean; | ||
| toString(): string; | ||
| } | ||
| /** | ||
| * An id that can be used to identify a particular AST element, even after | ||
| * transformations have taken place on it | ||
| */ | ||
| public getId(): string { | ||
| return this.id; | ||
| } | ||
| export interface Marker extends Tree { | ||
| isAcceptable(): false; | ||
| print(): ''; | ||
| } | ||
| public print(): string { | ||
| return ''; | ||
| } | ||
| export class Markers implements Tree { | ||
| private id: string; | ||
| private markers: Marker[] = []; | ||
| public printTrimmed(): string { | ||
| return ''; | ||
| } | ||
| public static build(markers): Markers { | ||
| return markers; | ||
| } | ||
| public isAcceptable<P>(v: TreeVisitor<any, P>, p: P): boolean { | ||
| return false; | ||
| } | ||
| constructor(id, markers: Marker[]) { | ||
| this.id = id; | ||
| this.markers = markers; | ||
| } | ||
| public entries(): Marker[] { | ||
| return this.markers; | ||
| } | ||
| /** | ||
| * An id that can be used to identify a particular AST element, even after | ||
| * transformations have taken place on it | ||
| */ | ||
| public getId(): string { | ||
| return this.id; | ||
| } | ||
| public add(marker: Marker): void { | ||
| this.markers.push(marker); | ||
| } | ||
| public print(): string { | ||
| return ''; | ||
| } | ||
| public findAll(markerType: any): Marker[] { | ||
| return this.markers.filter((marker) => marker instanceof markerType); | ||
| } | ||
| public printTrimmed(): string { | ||
| return ''; | ||
| } | ||
| public findFirst(markerType: any): Maybe<Marker> { | ||
| return this.markers.find((marker) => marker instanceof markerType); | ||
| } | ||
| public isAcceptable<P>(v: TreeVisitor<any, P>, p: P): boolean { | ||
| return false; | ||
| } | ||
| export type Json = Tree & { | ||
| getPrefix(): Space; | ||
| withPrefix<T extends Json>(prefix: Space): T; | ||
| withMarkers<T extends Json>(markers: Markers): T; | ||
| }; | ||
| public entries(): Marker[] { | ||
| return this.markers; | ||
| } | ||
| export interface JsonChangeValue { | ||
| oldKeyPath: string; | ||
| value: string | boolean | number; | ||
| fileMatcher?: string; | ||
| public add(marker: Marker): void { | ||
| this.markers.push(marker); | ||
| } | ||
| export interface JsonChangeKey { | ||
| oldKeyPath: string; | ||
| newKey: string; | ||
| fileMatcher?: string; | ||
| public findAll(markerType: any): Marker[] { | ||
| return this.markers.filter((marker) => marker instanceof markerType); | ||
| } | ||
| public findFirst(markerType: any): Maybe<Marker> { | ||
| return this.markers.find((marker) => marker instanceof markerType); | ||
| } | ||
| } | ||
| export type Json = Tree & { | ||
| getPrefix(): Space; | ||
| withPrefix<T extends Json>(prefix: Space): T; | ||
| withMarkers<T extends Json>(markers: Markers): T; | ||
| }; | ||
| export interface JsonChangeValue { | ||
| oldKeyPath: string; | ||
| value: string | boolean | number; | ||
| fileMatcher?: string; | ||
| } | ||
| export interface JsonChangeKey { | ||
| oldKeyPath: string; | ||
| newKey: string; | ||
| fileMatcher?: string; | ||
| } | ||
| /** | ||
@@ -309,5 +308,5 @@ * Java namespace here can be used for defining any custom members on recipes | ||
| export function requireRecipe(recipe: string): JavaClass<OpenRewrite.Recipe>; | ||
| export function requireRecipe(recipe: string): JavaClass<OpenRewrite.Recipe> { | ||
| return Java.type<OpenRewrite.Recipe>(recipe); | ||
| export function requireRecipe(recipe: string): JavaClass<Recipe>; | ||
| export function requireRecipe(recipe: string): JavaClass<Recipe> { | ||
| return Java.type<Recipe>(recipe); | ||
| } |
+1
-1
| { | ||
| "name": "@openrewrite/types", | ||
| "version": "0.0.13", | ||
| "version": "0.0.14", | ||
| "description": "Various Typescript types to aid in OpenRewrite recipe development", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
61320
-0.38%