/* * ExplorableGraph is a JavaScript project, but we use TypeScript as an internal * tool to confirm our code is type safe. */ /** * Core ExplorableGraph interface */ interface Explorable { [Symbol.asyncIterator](): AsyncIterableIterator; get(key: any): Promise; isKeyExplorable?(key: any): Promise; set?(key: any, value: any): Promise; set?(variant: GraphVariant): Promise; traverse?(...keys: any[]): Promise; } /* * A class constructor is an object with a `new` method that returns an * instance of the indicated type. */ type Constructor = new (...args: any[]) => T; /* * A mixin is a function that takes an existing class and returns a new class. * * The use of a generic type `T` here is a way of indicating that the members of * the supplied base class automatically pass through to the result. That * ensures the use of the mixin doesn't accidentally hide members of the class * passed to the mixin. */ type Mixin = ( Base: Constructor ) => Constructor; type PlainObject = { [key: string]: any; }; interface HasFunction { toFunction(): Function; } type Invocable = Explorable | Function | HasFunction; type GraphVariant = Explorable | PlainObject | string | Function | any[];