typed-inject
Advanced tools
Comparing version 3.0.1 to 4.0.0
@@ -0,1 +1,19 @@ | ||
# [4.0.0](https://github.com/nicojs/typed-inject/compare/v3.0.1...v4.0.0) (2023-05-05) | ||
### Features | ||
* **esm:** migrate to native esm ([#53](https://github.com/nicojs/typed-inject/issues/53)) ([b8efb26](https://github.com/nicojs/typed-inject/commit/b8efb26029bd5b683a5ac194ebfcbe8f0823db6b)) | ||
* **Node version:** set minimal node version to v16 ([#62](https://github.com/nicojs/typed-inject/issues/62)) ([585c99e](https://github.com/nicojs/typed-inject/commit/585c99e106e58ceae11ed4ccd493a07fc26662e5)) | ||
* **node:** drop support for node 10 and 12 ([#54](https://github.com/nicojs/typed-inject/issues/54)) ([c9f63bb](https://github.com/nicojs/typed-inject/commit/c9f63bb811783e343a8536c58e25d2f4f30dcb53)) | ||
### BREAKING CHANGES | ||
* **Node version:** Node 14 is no longer officially supported (although it might still work). | ||
* **node:** Node v10 and v12 are no longer supported. | ||
* **esm:** typed-inject is now a pure ESM. Please [read this](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) | ||
## [3.0.1](https://github.com/nicojs/typed-inject/compare/v3.0.0...v3.0.1) (2021-10-11) | ||
@@ -2,0 +20,0 @@ |
@@ -1,7 +0,7 @@ | ||
import { InjectionToken, InjectorToken, TargetToken } from './InjectionToken'; | ||
import { Injector } from './Injector'; | ||
export declare type CorrespondingType<TContext, T extends InjectionToken<TContext>> = T extends InjectorToken ? Injector<TContext> : T extends TargetToken ? Function | undefined : T extends keyof TContext ? TContext[T] : never; | ||
export declare type CorrespondingTypes<TContext, TS extends readonly InjectionToken<TContext>[]> = { | ||
import { InjectionToken, InjectorToken, TargetToken } from './InjectionToken.js'; | ||
import { Injector } from './Injector.js'; | ||
export type CorrespondingType<TContext, T extends InjectionToken<TContext>> = T extends InjectorToken ? Injector<TContext> : T extends TargetToken ? Function | undefined : T extends keyof TContext ? TContext[T] : never; | ||
export type CorrespondingTypes<TContext, TS extends readonly InjectionToken<TContext>[]> = { | ||
[K in keyof TS]: TS[K] extends InjectionToken<TContext> ? CorrespondingType<TContext, TS[K]> : never; | ||
}; | ||
//# sourceMappingURL=CorrespondingType.d.ts.map |
@@ -1,3 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; | ||
//# sourceMappingURL=CorrespondingType.js.map |
@@ -1,3 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; | ||
//# sourceMappingURL=Disposable.js.map |
@@ -1,4 +0,4 @@ | ||
import { CorrespondingTypes } from './CorrespondingType'; | ||
import { InjectionToken } from './InjectionToken'; | ||
export declare type InjectableClass<TContext, R, Tokens extends readonly InjectionToken<TContext>[]> = ClassWithInjections<TContext, R, Tokens> | ClassWithoutInjections<R>; | ||
import { CorrespondingTypes } from './CorrespondingType.js'; | ||
import { InjectionToken } from './InjectionToken.js'; | ||
export type InjectableClass<TContext, R, Tokens extends readonly InjectionToken<TContext>[]> = ClassWithInjections<TContext, R, Tokens> | ClassWithoutInjections<R>; | ||
export interface ClassWithInjections<TContext, R, Tokens extends readonly InjectionToken<TContext>[]> { | ||
@@ -8,4 +8,4 @@ new (...args: CorrespondingTypes<TContext, Tokens>): R; | ||
} | ||
export declare type ClassWithoutInjections<R> = new () => R; | ||
export declare type InjectableFunction<TContext, R, Tokens extends readonly InjectionToken<TContext>[]> = InjectableFunctionWithInject<TContext, R, Tokens> | InjectableFunctionWithoutInject<R>; | ||
export type ClassWithoutInjections<R> = new () => R; | ||
export type InjectableFunction<TContext, R, Tokens extends readonly InjectionToken<TContext>[]> = InjectableFunctionWithInject<TContext, R, Tokens> | InjectableFunctionWithoutInject<R>; | ||
export interface InjectableFunctionWithInject<TContext, R, Tokens extends readonly InjectionToken<TContext>[]> { | ||
@@ -15,4 +15,4 @@ (...args: CorrespondingTypes<TContext, Tokens>): R; | ||
} | ||
export declare type InjectableFunctionWithoutInject<R> = () => R; | ||
export declare type Injectable<TContext, R, Tokens extends readonly InjectionToken<TContext>[]> = InjectableClass<TContext, R, Tokens> | InjectableFunction<TContext, R, Tokens>; | ||
export type InjectableFunctionWithoutInject<R> = () => R; | ||
export type Injectable<TContext, R, Tokens extends readonly InjectionToken<TContext>[]> = InjectableClass<TContext, R, Tokens> | InjectableFunction<TContext, R, Tokens>; | ||
//# sourceMappingURL=Injectable.d.ts.map |
@@ -1,3 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; | ||
//# sourceMappingURL=Injectable.js.map |
@@ -1,2 +0,2 @@ | ||
export declare type InjectionTarget = Function | symbol | number | string | undefined; | ||
export type InjectionTarget = Function | symbol | number | string | undefined; | ||
//# sourceMappingURL=InjectionTarget.d.ts.map |
@@ -1,3 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; | ||
//# sourceMappingURL=InjectionTarget.js.map |
@@ -1,6 +0,6 @@ | ||
export declare type InjectorToken = '$injector'; | ||
export declare type TargetToken = '$target'; | ||
export type InjectorToken = '$injector'; | ||
export type TargetToken = '$target'; | ||
export declare const INJECTOR_TOKEN: InjectorToken; | ||
export declare const TARGET_TOKEN: TargetToken; | ||
export declare type InjectionToken<TContext> = InjectorToken | TargetToken | keyof TContext; | ||
export type InjectionToken<TContext> = InjectorToken | TargetToken | keyof TContext; | ||
//# sourceMappingURL=InjectionToken.d.ts.map |
@@ -1,6 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TARGET_TOKEN = exports.INJECTOR_TOKEN = void 0; | ||
exports.INJECTOR_TOKEN = '$injector'; | ||
exports.TARGET_TOKEN = '$target'; | ||
export const INJECTOR_TOKEN = '$injector'; | ||
export const TARGET_TOKEN = '$target'; | ||
//# sourceMappingURL=InjectionToken.js.map |
@@ -1,5 +0,5 @@ | ||
import { InjectableClass, InjectableFunction } from './Injectable'; | ||
import { InjectionToken } from './InjectionToken'; | ||
import { Scope } from './Scope'; | ||
import { TChildContext } from './TChildContext'; | ||
import { InjectableClass, InjectableFunction } from './Injectable.js'; | ||
import { InjectionToken } from './InjectionToken.js'; | ||
import { Scope } from './Scope.js'; | ||
import { TChildContext } from './TChildContext.js'; | ||
export interface Injector<TContext = {}> { | ||
@@ -6,0 +6,0 @@ injectClass<R, Tokens extends readonly InjectionToken<TContext>[]>(Class: InjectableClass<TContext, R, Tokens>): R; |
@@ -1,3 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; | ||
//# sourceMappingURL=Injector.js.map |
@@ -1,9 +0,6 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Scope = void 0; | ||
var Scope; | ||
export var Scope; | ||
(function (Scope) { | ||
Scope["Transient"] = "transient"; | ||
Scope["Singleton"] = "singleton"; | ||
})(Scope = exports.Scope || (exports.Scope = {})); | ||
})(Scope || (Scope = {})); | ||
//# sourceMappingURL=Scope.js.map |
@@ -1,2 +0,2 @@ | ||
export declare type TChildContext<TParentContext, TProvided, CurrentToken extends string> = { | ||
export type TChildContext<TParentContext, TProvided, CurrentToken extends string> = { | ||
[K in keyof (TParentContext & { | ||
@@ -3,0 +3,0 @@ [K in CurrentToken]: TProvided; |
@@ -1,3 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; | ||
//# sourceMappingURL=TChildContext.js.map |
@@ -1,2 +0,2 @@ | ||
import { InjectionTarget } from './api/InjectionTarget'; | ||
import type { InjectionTarget } from './api/InjectionTarget.js'; | ||
export declare abstract class TypedInjectError extends Error { | ||
@@ -3,0 +3,0 @@ } |
@@ -1,4 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.InjectionError = exports.InjectorDisposedError = exports.TypedInjectError = void 0; | ||
/* | ||
@@ -17,5 +14,4 @@ | ||
*/ | ||
class TypedInjectError extends Error { | ||
export class TypedInjectError extends Error { | ||
} | ||
exports.TypedInjectError = TypedInjectError; | ||
function describeInjectAction(target) { | ||
@@ -42,3 +38,3 @@ if (typeof target === 'function') { | ||
} | ||
class InjectorDisposedError extends TypedInjectError { | ||
export class InjectorDisposedError extends TypedInjectError { | ||
constructor(target) { | ||
@@ -48,4 +44,3 @@ super(`Injector is already disposed. Please don't use it anymore. Tried to ${describeInjectAction(target)} ${name(target)}.`); | ||
} | ||
exports.InjectorDisposedError = InjectorDisposedError; | ||
class InjectionError extends TypedInjectError { | ||
export class InjectionError extends TypedInjectError { | ||
constructor(path, cause) { | ||
@@ -65,3 +60,2 @@ super(`Could not ${describeInjectAction(path[0])} ${path.map(name).join(' -> ')}. Cause: ${cause.message}`); | ||
} | ||
exports.InjectionError = InjectionError; | ||
//# sourceMappingURL=errors.js.map |
@@ -1,12 +0,12 @@ | ||
export * from './api/Injectable'; | ||
export * from './api/CorrespondingType'; | ||
export * from './api/InjectionToken'; | ||
export * from './api/InjectionTarget'; | ||
export * from './api/Injector'; | ||
export * from './api/Scope'; | ||
export * from './api/TChildContext'; | ||
export * from './InjectorImpl'; | ||
export * from './errors'; | ||
export * from './tokens'; | ||
export * from './api/Disposable'; | ||
export * from './api/Injectable.js'; | ||
export * from './api/CorrespondingType.js'; | ||
export * from './api/InjectionToken.js'; | ||
export * from './api/InjectionTarget.js'; | ||
export * from './api/Injector.js'; | ||
export * from './api/Scope.js'; | ||
export * from './api/TChildContext.js'; | ||
export * from './InjectorImpl.js'; | ||
export * from './errors.js'; | ||
export * from './tokens.js'; | ||
export * from './api/Disposable.js'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,24 +0,12 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./api/Injectable"), exports); | ||
__exportStar(require("./api/CorrespondingType"), exports); | ||
__exportStar(require("./api/InjectionToken"), exports); | ||
__exportStar(require("./api/InjectionTarget"), exports); | ||
__exportStar(require("./api/Injector"), exports); | ||
__exportStar(require("./api/Scope"), exports); | ||
__exportStar(require("./api/TChildContext"), exports); | ||
__exportStar(require("./InjectorImpl"), exports); | ||
__exportStar(require("./errors"), exports); | ||
__exportStar(require("./tokens"), exports); | ||
__exportStar(require("./api/Disposable"), exports); | ||
export * from './api/Injectable.js'; | ||
export * from './api/CorrespondingType.js'; | ||
export * from './api/InjectionToken.js'; | ||
export * from './api/InjectionTarget.js'; | ||
export * from './api/Injector.js'; | ||
export * from './api/Scope.js'; | ||
export * from './api/TChildContext.js'; | ||
export * from './InjectorImpl.js'; | ||
export * from './errors.js'; | ||
export * from './tokens.js'; | ||
export * from './api/Disposable.js'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,3 +0,3 @@ | ||
import { Injector } from './api/Injector'; | ||
import type { Injector } from './api/Injector.js'; | ||
export declare function createInjector(): Injector<{}>; | ||
//# sourceMappingURL=InjectorImpl.d.ts.map |
@@ -1,12 +0,10 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createInjector = void 0; | ||
/* eslint-disable @typescript-eslint/no-unsafe-argument */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-return */ | ||
const Scope_1 = require("./api/Scope"); | ||
const InjectionToken_1 = require("./api/InjectionToken"); | ||
const errors_1 = require("./errors"); | ||
const utils_1 = require("./utils"); | ||
const DEFAULT_SCOPE = Scope_1.Scope.Singleton; | ||
import { INJECTOR_TOKEN, TARGET_TOKEN } from './api/InjectionToken.js'; | ||
import { Scope } from './api/Scope.js'; | ||
import { InjectionError, InjectorDisposedError } from './errors.js'; | ||
import { isDisposable } from './utils.js'; | ||
const DEFAULT_SCOPE = Scope.Singleton; | ||
/* | ||
@@ -45,3 +43,3 @@ | ||
catch (error) { | ||
throw errors_1.InjectionError.create(Class, error); | ||
throw InjectionError.create(Class, error); | ||
} | ||
@@ -56,3 +54,3 @@ } | ||
catch (error) { | ||
throw errors_1.InjectionError.create(fn, error); | ||
throw InjectionError.create(fn, error); | ||
} | ||
@@ -64,5 +62,5 @@ } | ||
switch (key) { | ||
case InjectionToken_1.TARGET_TOKEN: | ||
case TARGET_TOKEN: | ||
return target; | ||
case InjectionToken_1.INJECTOR_TOKEN: | ||
case INJECTOR_TOKEN: | ||
return this; | ||
@@ -98,3 +96,3 @@ default: | ||
if (this.isDisposed) { | ||
throw new errors_1.InjectorDisposedError(injectableOrToken); | ||
throw new InjectorDisposedError(injectableOrToken); | ||
} | ||
@@ -153,3 +151,3 @@ } | ||
catch (error) { | ||
throw errors_1.InjectionError.create(token, error); | ||
throw InjectionError.create(token, error); | ||
} | ||
@@ -163,3 +161,3 @@ } | ||
addToCacheIfNeeded(value) { | ||
if (this.scope === Scope_1.Scope.Singleton) { | ||
if (this.scope === Scope.Singleton) { | ||
this.cached = { value }; | ||
@@ -169,3 +167,3 @@ } | ||
registerProvidedValue(value) { | ||
if ((0, utils_1.isDisposable)(value)) { | ||
if (isDisposable(value)) { | ||
this.disposables.add(value); | ||
@@ -178,3 +176,3 @@ } | ||
constructor(parent, token, value) { | ||
super(parent, token, Scope_1.Scope.Transient); | ||
super(parent, token, Scope.Transient); | ||
this.value = value; | ||
@@ -204,6 +202,5 @@ } | ||
} | ||
function createInjector() { | ||
export function createInjector() { | ||
return new RootInjector(); | ||
} | ||
exports.createInjector = createInjector; | ||
//# sourceMappingURL=InjectorImpl.js.map |
@@ -1,4 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.tokens = void 0; | ||
/** | ||
@@ -13,6 +10,5 @@ * Helper method to create string literal tuple type. | ||
*/ | ||
function tokens(...tokens) { | ||
export function tokens(...tokens) { | ||
return tokens; | ||
} | ||
exports.tokens = tokens; | ||
//# sourceMappingURL=tokens.js.map |
@@ -1,3 +0,3 @@ | ||
import { Disposable } from './api/Disposable'; | ||
import { Disposable } from './api/Disposable.js'; | ||
export declare function isDisposable(maybeDisposable: unknown): maybeDisposable is Disposable; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -1,9 +0,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isDisposable = void 0; | ||
function isDisposable(maybeDisposable) { | ||
export function isDisposable(maybeDisposable) { | ||
const asDisposable = maybeDisposable; | ||
return asDisposable && asDisposable.dispose && typeof asDisposable.dispose === 'function'; | ||
} | ||
exports.isDisposable = isDisposable; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "typed-inject", | ||
"version": "3.0.1", | ||
"version": "4.0.0", | ||
"description": "Type safe dependency injection framework for TypeScript", | ||
"main": "dist/src/index.js", | ||
"type": "module", | ||
"scripts": { | ||
"all": "npm run clean && npm run lint && npm run build && npm run test && npm run stryker", | ||
"all": "npm run clean && npm run build && npm run lint && npm run test && npm run stryker", | ||
"start": "tsc -b -w", | ||
"clean": "rimraf dist", | ||
"lint": "eslint . --ext .js,.ts --ignore-path .gitignore --ignore-pattern testResources/**/*.ts --ignore-pattern stryker.conf.js --ignore-pattern .eslintrc.js", | ||
"lint": "eslint . --ext .js,.ts --ignore-path .gitignore --ignore-pattern testResources/**/*.ts --ignore-pattern stryker.conf.js", | ||
"build": "tsc -b", | ||
"test": "nyc --exclude-after-remap=false \"--exclude=dist/test/**/*.js\" --check-coverage --reporter=html --report-dir=reports/coverage --lines 100 --functions 100 --branches 100 npm run mocha", | ||
"mocha": "mocha \"dist/test/helpers/**/*.js\" \"dist/test/unit/**/*.js\" && mocha --timeout 20000 \"dist/test/helpers/**/*.js\" \"dist/test/integration/**/*.js\"", | ||
"test": "c8 --exclude-after-remap=false \"--exclude=dist/test/**/*.js\" --check-coverage --reporter=html --report-dir=reports/coverage --lines 100 --functions 100 --branches 100 npm run test:all", | ||
"test:all": "npm run test:unit && npm run test:integration", | ||
"test:unit": "mocha -r source-map-support/register \"dist/test/helpers/**/*.js\" \"dist/test/unit/**/*.js\"", | ||
"test:integration": "mocha -r source-map-support/register --timeout 20000 \"dist/test/helpers/**/*.js\" \"dist/test/integration/**/*.js\"", | ||
"stryker": "stryker run", | ||
@@ -28,3 +31,3 @@ "preversion": "npm run all", | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=16" | ||
}, | ||
@@ -49,26 +52,26 @@ "keywords": [ | ||
"devDependencies": { | ||
"@stryker-mutator/core": "^5.4.1", | ||
"@stryker-mutator/mocha-runner": "^5.4.1", | ||
"@stryker-mutator/typescript-checker": "^5.4.1", | ||
"@types/chai": "^4.2.22", | ||
"@types/mocha": "^9.0.0", | ||
"@types/node": "^16.10.3", | ||
"@types/sinon": "^10.0.4", | ||
"@types/sinon-chai": "^3.2.5", | ||
"@typescript-eslint/eslint-plugin": "^4.33.0", | ||
"@typescript-eslint/parser": "^4.33.0", | ||
"chai": "^4.3.4", | ||
"conventional-changelog-cli": "^2.1.1", | ||
"eslint": "^7.32.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"mocha": "^9.1.2", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.4.1", | ||
"rimraf": "^3.0.2", | ||
"sinon": "^11.1.2", | ||
"@stryker-mutator/core": "^6.4.2", | ||
"@stryker-mutator/mocha-runner": "^6.4.2", | ||
"@stryker-mutator/typescript-checker": "^6.4.2", | ||
"@types/chai": "^4.3.5", | ||
"@types/mocha": "^10.0.1", | ||
"@types/node": "^20.1.0", | ||
"@types/sinon": "^10.0.14", | ||
"@types/sinon-chai": "^3.2.9", | ||
"@typescript-eslint/eslint-plugin": "^5.59.2", | ||
"@typescript-eslint/parser": "^5.59.2", | ||
"c8": "^7.13.0", | ||
"chai": "^4.3.7", | ||
"conventional-changelog-cli": "^2.2.2", | ||
"eslint": "^8.40.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"mocha": "^10.2.0", | ||
"prettier": "^2.8.8", | ||
"rimraf": "^5.0.0", | ||
"sinon": "^15.0.4", | ||
"sinon-chai": "^3.7.0", | ||
"source-map-support": "^0.5.20", | ||
"typescript": "4.4.3" | ||
"source-map-support": "^0.5.21", | ||
"typescript": "~5.0.4" | ||
} | ||
} |
@@ -49,3 +49,3 @@ [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fnicojs%2Ftyped-inject%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/nicojs/typed-inject/master) | ||
_Note: due to a [bug since TypeScript 3.8](https://github.com/microsoft/TypeScript/issues/37400) there is a small chance that the compiler [doesn't catch all errors](https://github.com/nicojs/typed-inject/issues/20) (as well as you might experience some performance issues)._ | ||
_Note: due to a [bug in TypeScript >3.8 <4.5](https://github.com/microsoft/TypeScript/issues/37400) there is a small chance that the compiler [doesn't catch all errors](https://github.com/nicojs/typed-inject/issues/20) (as well as you might experience some performance issues)._ | ||
@@ -153,3 +153,3 @@ _Note: projects must enable [`--strictFunctionTypes`](https://www.typescriptlang.org/tsconfig#strictFunctionTypes) (or `--strict`) in their Typescript config or some type errors may not be caught._ | ||
The `Injector` interface is responsible for injecting classes or functions. You start off with an empty injector after calling `createInjector`. It can't provide any dependencies directly (expect for [magic tokens](#-magic-tokens)). | ||
The `Injector` interface is responsible for injecting classes or functions. You start off with an empty injector after calling `createInjector`. It can't provide any dependencies directly (except for [magic tokens](#-magic-tokens)). | ||
@@ -236,3 +236,4 @@ To do anything useful with your injector, you'll need to create child injectors. This what you do with the `provideXXX` methods. | ||
} | ||
loggerFactory.inject('target'); | ||
loggerFactory.inject = ['target'] as const; | ||
class Foo { | ||
@@ -457,3 +458,14 @@ constructor(public log: Logger) { | ||
This method creates a new instance of class `injectable` and returns it. | ||
This method creates a new instance of class `injectable` by populating its constructor arguments from the injector and returns it. | ||
Basically it is a shortcut for resolving values from the injector and creating a new instance with those values: | ||
```ts | ||
const logger = appInjector.resolve('logger'); | ||
const httpClient = appInjector.resolve('httpClient'); | ||
const service = new MyService(httpClient, logger); | ||
``` | ||
Any instance created with `injectClass` will not be disposed when `dispose` is called. It is the caller's responsiblity to dispose it. | ||
When there are any problems in the dependency graph, it gives a compiler error. | ||
@@ -471,3 +483,12 @@ | ||
This methods injects the function with requested tokens and returns the return value of the function. | ||
This method injects the function with requested tokens from the injector, invokes it and returns the result. | ||
It is a shortcut for calling the provided function with the values from the injector. | ||
```ts | ||
const logger = appInjector.resolve('logger'); | ||
const httpClient = appInjector.resolve('httpClient'); | ||
const request = doRequest(httpClient, logger); | ||
``` | ||
When there are any problems in the dependency graph, it gives a compiler error. | ||
@@ -474,0 +495,0 @@ |
@@ -1,3 +0,3 @@ | ||
import { InjectionToken, InjectorToken, TargetToken } from './InjectionToken'; | ||
import { Injector } from './Injector'; | ||
import { InjectionToken, InjectorToken, TargetToken } from './InjectionToken.js'; | ||
import { Injector } from './Injector.js'; | ||
@@ -4,0 +4,0 @@ export type CorrespondingType<TContext, T extends InjectionToken<TContext>> = T extends InjectorToken |
@@ -1,3 +0,3 @@ | ||
import { CorrespondingTypes } from './CorrespondingType'; | ||
import { InjectionToken } from './InjectionToken'; | ||
import { CorrespondingTypes } from './CorrespondingType.js'; | ||
import { InjectionToken } from './InjectionToken.js'; | ||
@@ -4,0 +4,0 @@ export type InjectableClass<TContext, R, Tokens extends readonly InjectionToken<TContext>[]> = |
@@ -1,5 +0,5 @@ | ||
import { InjectableClass, InjectableFunction } from './Injectable'; | ||
import { InjectionToken } from './InjectionToken'; | ||
import { Scope } from './Scope'; | ||
import { TChildContext } from './TChildContext'; | ||
import { InjectableClass, InjectableFunction } from './Injectable.js'; | ||
import { InjectionToken } from './InjectionToken.js'; | ||
import { Scope } from './Scope.js'; | ||
import { TChildContext } from './TChildContext.js'; | ||
@@ -6,0 +6,0 @@ export interface Injector<TContext = {}> { |
@@ -1,2 +0,2 @@ | ||
import { InjectionTarget } from './api/InjectionTarget'; | ||
import type { InjectionTarget } from './api/InjectionTarget.js'; | ||
@@ -3,0 +3,0 @@ /* |
@@ -1,11 +0,11 @@ | ||
export * from './api/Injectable'; | ||
export * from './api/CorrespondingType'; | ||
export * from './api/InjectionToken'; | ||
export * from './api/InjectionTarget'; | ||
export * from './api/Injector'; | ||
export * from './api/Scope'; | ||
export * from './api/TChildContext'; | ||
export * from './InjectorImpl'; | ||
export * from './errors'; | ||
export * from './tokens'; | ||
export * from './api/Disposable'; | ||
export * from './api/Injectable.js'; | ||
export * from './api/CorrespondingType.js'; | ||
export * from './api/InjectionToken.js'; | ||
export * from './api/InjectionTarget.js'; | ||
export * from './api/Injector.js'; | ||
export * from './api/Scope.js'; | ||
export * from './api/TChildContext.js'; | ||
export * from './InjectorImpl.js'; | ||
export * from './errors.js'; | ||
export * from './tokens.js'; | ||
export * from './api/Disposable.js'; |
@@ -0,13 +1,14 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-argument */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-return */ | ||
import { Scope } from './api/Scope'; | ||
import { InjectionToken, INJECTOR_TOKEN, TARGET_TOKEN } from './api/InjectionToken'; | ||
import { InjectableClass, InjectableFunction, Injectable } from './api/Injectable'; | ||
import { Injector } from './api/Injector'; | ||
import { InjectionError, InjectorDisposedError } from './errors'; | ||
import { Disposable } from './api/Disposable'; | ||
import { isDisposable } from './utils'; | ||
import { TChildContext } from './api/TChildContext'; | ||
import { InjectionTarget } from './api/InjectionTarget'; | ||
import { type InjectionToken, INJECTOR_TOKEN, TARGET_TOKEN } from './api/InjectionToken.js'; | ||
import type { InjectableClass, InjectableFunction, Injectable } from './api/Injectable.js'; | ||
import type { Injector } from './api/Injector.js'; | ||
import type { Disposable } from './api/Disposable.js'; | ||
import type { TChildContext } from './api/TChildContext.js'; | ||
import type { InjectionTarget } from './api/InjectionTarget.js'; | ||
import { Scope } from './api/Scope.js'; | ||
import { InjectionError, InjectorDisposedError } from './errors.js'; | ||
import { isDisposable } from './utils.js'; | ||
@@ -14,0 +15,0 @@ const DEFAULT_SCOPE = Scope.Singleton; |
@@ -1,2 +0,2 @@ | ||
import { Disposable } from './api/Disposable'; | ||
import { Disposable } from './api/Disposable.js'; | ||
@@ -3,0 +3,0 @@ export function isDisposable(maybeDisposable: unknown): maybeDisposable is Disposable { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92631
646
Yes
760