mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 14:57:10 +00:00
forge-di: Provides its own types (#39608)
This commit is contained in:
committed by
Jesse Trinity
parent
f9be2e89f0
commit
72e896c558
@@ -1230,6 +1230,12 @@
|
||||
"sourceRepoURL": "https://github.com/acdlite/flux-standard-action",
|
||||
"asOfVersion": "1.1.0"
|
||||
},
|
||||
{
|
||||
"libraryName": "forge-di",
|
||||
"typingsPackageName": "forge-di",
|
||||
"sourceRepoURL": "https://github.com/nkohari/forge",
|
||||
"asOfVersion": "12.0.2"
|
||||
},
|
||||
{
|
||||
"libraryName": "fork-ts-checker-webpack-plugin",
|
||||
"typingsPackageName": "fork-ts-checker-webpack-plugin",
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
|
||||
import Forge = require('forge-di');
|
||||
|
||||
var forge = new Forge();
|
||||
|
||||
class Bar {}
|
||||
|
||||
class Foo {
|
||||
constructor(public bar: Bar) {
|
||||
}
|
||||
}
|
||||
|
||||
forge.bind('foo').to.type(Foo);
|
||||
forge.bind('bar').to.type(Bar);
|
||||
|
||||
var foo: Foo = forge.get<Foo>('foo');
|
||||
var barInst = foo.bar;
|
||||
|
||||
// register functions
|
||||
var createFoo = (bar: Bar) => new Foo(bar);
|
||||
forge.bind('foo').to.function(createFoo);
|
||||
|
||||
// Conditional bindings and resolution hints
|
||||
class RedFoo {}
|
||||
class BlueFoo {}
|
||||
|
||||
forge.bind('foo').to.type(RedFoo).when('red');
|
||||
forge.bind('foo').to.type(BlueFoo).when((hint) => hint === 'blue');
|
||||
|
||||
// Lifecycles
|
||||
forge.bind('foo').to.type(Foo).as.singleton();
|
||||
forge.bind('bar').to.type(Bar).as.transient();
|
||||
|
||||
// explicit arguments
|
||||
var manuallyCreatedBar = new Bar();
|
||||
forge.bind('foo').to.type(Foo).with({bar: manuallyCreatedBar});
|
||||
|
||||
var bindingArgs: Forge.IBindingArguments = {
|
||||
bar: manuallyCreatedBar
|
||||
};
|
||||
forge.bind('foo').to.type(Foo).with(bindingArgs);
|
||||
|
||||
// Ephemeral Bindings TODO
|
||||
class DependsOnFoo {
|
||||
constructor(public foo: Foo){}
|
||||
}
|
||||
var dependsOnFoo = forge.create(DependsOnFoo);
|
||||
|
||||
// Unbinding and rebinding
|
||||
forge.unbind('foo');
|
||||
forge.rebind('foo').to.type(Foo);
|
||||
Vendored
-205
@@ -1,205 +0,0 @@
|
||||
// Type definitions for forge-di v0.9.5
|
||||
// Project: https://github.com/nkohari/forge
|
||||
// Definitions by: Adam Carr <https://github.com/adamcarr>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of the forge dependency injection manager.
|
||||
*/
|
||||
declare class Forge {
|
||||
/**
|
||||
* Creates a new instance
|
||||
* @returns {Forge} a new instance.
|
||||
*/
|
||||
constructor();
|
||||
|
||||
/**
|
||||
* The bindings mapped to this forge instance.
|
||||
*/
|
||||
bindings: Forge.IBindingMap;
|
||||
|
||||
/**
|
||||
* Creates a new binding.
|
||||
* @param {string} name The binding name.
|
||||
*/
|
||||
bind(name: string): Forge.IBinding;
|
||||
/**
|
||||
* Unbinds then recreates a binding for this name.
|
||||
* @param {string} name The binding name.
|
||||
*/
|
||||
rebind(name: string): Forge.IBinding;
|
||||
/**
|
||||
* Unbinds all bindings for this name. Returns the number of bindings removed.
|
||||
* @param {string} name The binding name.
|
||||
*/
|
||||
unbind(name: string): number;
|
||||
/**
|
||||
* Get instance or instances of type registered under the provided name and optional hint.
|
||||
* @param {string} name The binding name.
|
||||
* @param {string} hint The binding hint.
|
||||
* @param {...args} args Additional args.
|
||||
*/
|
||||
get<T>(name: string, hint?: string, ...args: any[]): T;
|
||||
/**
|
||||
* Get a single instance of type registered under the provided name and optional hint.
|
||||
* @param {string} name The binding name.
|
||||
* @param {string} hint The binding hint.
|
||||
* @param {...args} args Additional args.
|
||||
*/
|
||||
getOne<T>(name: string, hint?: string, ...args: any[]): T;
|
||||
/**
|
||||
* Gets all instances of the type registered under the provided name.
|
||||
* @param {string} name The binding name.
|
||||
* @param {...args} args Additional args.
|
||||
*/
|
||||
getAll<T>(name: string, ...args: any[]): T | T[];
|
||||
/**
|
||||
* Creates an instance of the target type attempting to resolve any dependencies.
|
||||
* @param {T} target The target type.
|
||||
* @param {...args} args Additional args.
|
||||
*/
|
||||
create<T>(target: T, ...args: any[]): T;
|
||||
/**
|
||||
* Get all bindings registered under a binding name and optional hint.
|
||||
* @param {string} name The binding name.
|
||||
* @param {string} hint The binding hint.
|
||||
*/
|
||||
getMatchingBindings(name: string, hint?: string): Forge.IBinding[];
|
||||
/**
|
||||
* Returns a string that represents all bindings within this forge instance.
|
||||
*/
|
||||
inspect(): string;
|
||||
|
||||
resolve<T>(name: string, context?: Forge.IContext, hint?: string, all?: boolean, ...args: any[]): T | T[];
|
||||
resolveBindings(context: Forge.IContext, bindings: Forge.IBinding[], hint: string, args: any[], unwrap: boolean): Forge.IBinding[];
|
||||
}
|
||||
|
||||
declare namespace Forge {
|
||||
interface IContext {
|
||||
new (): IContext;
|
||||
bindings: IBinding[];
|
||||
has(binding: IBinding): boolean;
|
||||
push(binding: IBinding): void;
|
||||
pop(): IBinding;
|
||||
toString(indent: number): string;
|
||||
}
|
||||
|
||||
interface IType {
|
||||
new (...args: any[]): any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents arguments to help with resolving a binding.
|
||||
*/
|
||||
interface IBindingArguments {
|
||||
[name: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a binding between a name, type/instance/function and optional hint.
|
||||
*/
|
||||
interface IBinding {
|
||||
/** The forge that contains this binding. */
|
||||
forge: Forge;
|
||||
/** The binding name. */
|
||||
name: string;
|
||||
/** Alias mapping to this binding. */
|
||||
to: IBinding;
|
||||
/** Alias mapping to this binding. */
|
||||
as: IBinding;
|
||||
/** Whether or not this binding is currently resolving. */
|
||||
isResolving: boolean;
|
||||
/** The resolver for this binding. */
|
||||
resolver: IResolver;
|
||||
/** The lifecycle associated with this binding. Defaults to singleton. */
|
||||
lifecycle: ILifecycle;
|
||||
/** The predicate associated with this binding. Used to support hints. */
|
||||
predicate: IPredicate;
|
||||
/** The additional binding arguments to help resolve dependencies. */
|
||||
arguments: IBindingArguments;
|
||||
|
||||
/**
|
||||
* Checks whether or not this binding matches the hint by executing the predicate.
|
||||
* @param {string} hint The hint to check against.
|
||||
*/
|
||||
matches(hint: string): boolean;
|
||||
/**
|
||||
* Registers a type to a binding. This type must have a constructor.
|
||||
* @param {T} target The target type.
|
||||
*/
|
||||
type<T extends IType>(target: T): IBinding;
|
||||
/**
|
||||
* Registers a type to a binding. This must be a callable function.
|
||||
* @param {T} target The target function.
|
||||
*/
|
||||
function<T extends { (...args: any[]): any }>(target: T): IBinding;
|
||||
/**
|
||||
* Registeres an instance to a binding. This instance will always be returned.
|
||||
* @param {T} target The target instance.
|
||||
*/
|
||||
instance<T extends Object>(target: T): IBinding;
|
||||
/**
|
||||
* Configures this binding lifecycle as a singleton. This is the default lifecycle.
|
||||
*/
|
||||
singleton(): IBinding;
|
||||
/**
|
||||
* Configures this binding lifecycle as transient.
|
||||
* New instances will be created, if this is a type based binding, on each get.
|
||||
*/
|
||||
transient(): IBinding;
|
||||
/**
|
||||
* Registers a predicate for this binding.
|
||||
* @param {IPredicate} predicate The predicate.
|
||||
*/
|
||||
when(predicate: IPredicate): IBinding;
|
||||
/**
|
||||
* Registers a hint for this binding.
|
||||
* @param {string} hint The hint.
|
||||
*/
|
||||
when(hint: string): IBinding;
|
||||
/**
|
||||
* Registers additional binding arguments to help with resolving.
|
||||
* @param {IBindingArguments} args The additional binding arguments.
|
||||
*/
|
||||
with(args: IBindingArguments): IBinding;
|
||||
/**
|
||||
* Returns a string representing this binding.
|
||||
*/
|
||||
toString(): string;
|
||||
}
|
||||
|
||||
/** Represents a binding map. */
|
||||
interface IBindingMap {
|
||||
/** Gets a binding by name. */
|
||||
[name: string]: IBinding[];
|
||||
}
|
||||
|
||||
/** Represents a predicate. */
|
||||
interface IPredicate {
|
||||
/**
|
||||
* Returns whether or not the hit satisfies this predicate.
|
||||
* @param {string} hint The hint to check against.
|
||||
*/
|
||||
(hint: string): boolean;
|
||||
}
|
||||
|
||||
/** Represents a resolver. */
|
||||
interface IResolver {
|
||||
/**
|
||||
* Resolves a specific type.
|
||||
*/
|
||||
resolve<T>(): T;
|
||||
}
|
||||
|
||||
/** Represents a binding lifecycle. */
|
||||
interface ILifecycle {
|
||||
/**
|
||||
* Returns the instance from a resolver based on the configured lifecycle.
|
||||
* @param {IResolver} resolver The type resolver.
|
||||
*/
|
||||
getInstance<T>(resolver: IResolver): T;
|
||||
}
|
||||
}
|
||||
|
||||
export = Forge;
|
||||
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"forge-di-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"npm-naming": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user