ts-ioc-container 70.1.0 → 71.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/cjm/provider/Provider.js +1 -1
- package/cjm/utils/array.js +1 -1
- package/esm/provider/Provider.js +1 -1
- package/esm/utils/array.js +1 -1
- package/package.json +1 -1
- package/typings/provider/IProvider.d.ts +1 -1
- package/typings/token/InjectionToken.d.ts +1 -1
- package/typings/token/toToken.d.ts +1 -1
- package/typings/utils/array.d.ts +1 -1
package/README.md
CHANGED
|
@@ -1795,7 +1795,7 @@ Constructor parameters that should pick up positional args from `ProviderOptions
|
|
|
1795
1795
|
|
|
1796
1796
|
`argsFn(predicate)` is the general form: it iterates the runtime `args` array and returns the **first argument matching** `predicate(value, index)` — think `args.find(predicate)`. `arg(index)` is just a shortcut for matching by position: `arg(0)` is `argsFn((value, index) => index === 0)`. `args` is `(scope, options) => options.args`, i.e. it returns the runtime args array as-is. Every `InjectFn` receives `(scope, options)`, where `options.args` is the runtime args array.
|
|
1797
1797
|
|
|
1798
|
-
`findOrFail(predicate)` is the strict
|
|
1798
|
+
`findOrFail(predicate)` is the strict counterpart for `singleton()` cache keys — `singleton(findOrFail(isUserId))` keys a per-argument singleton, for example. It receives the full runtime `args` array, returns the first argument matching `predicate(value)`, and throws `ArgumentNotFoundError` when none does, instead of silently handing out `undefined`.
|
|
1799
1799
|
|
|
1800
1800
|
### Runtime args flow through tokens
|
|
1801
1801
|
|
|
@@ -2024,7 +2024,7 @@ describe('IProvider', function () {
|
|
|
2024
2024
|
|
|
2025
2025
|
@register(
|
|
2026
2026
|
bindTo(EntityManagerToken),
|
|
2027
|
-
singleton((repository) => (repository as IRepository).name), // Cache unique instance per repository type
|
|
2027
|
+
singleton(([repository]) => (repository as IRepository).name), // Cache unique instance per repository type
|
|
2028
2028
|
)
|
|
2029
2029
|
class EntityManager {
|
|
2030
2030
|
constructor(@inject(arg(0)) public repository: IRepository) {}
|
package/cjm/provider/Provider.js
CHANGED
|
@@ -32,7 +32,7 @@ class Provider {
|
|
|
32
32
|
if (!this.getKey) {
|
|
33
33
|
return this.resolveDep(scope, options);
|
|
34
34
|
}
|
|
35
|
-
const key = (0, basic_1.toString)(this.getKey(
|
|
35
|
+
const key = (0, basic_1.toString)(this.getKey(options.args ?? []));
|
|
36
36
|
if (!this.cache.has(key)) {
|
|
37
37
|
this.cache.set(key, this.resolveDep(scope, options));
|
|
38
38
|
}
|
package/cjm/utils/array.js
CHANGED
|
@@ -8,7 +8,7 @@ exports.Filter = {
|
|
|
8
8
|
return (v) => !excludeSet.has(v);
|
|
9
9
|
},
|
|
10
10
|
};
|
|
11
|
-
const findOrFail = (predicate) => (
|
|
11
|
+
const findOrFail = (predicate) => (args = []) => {
|
|
12
12
|
const index = args.findIndex((arg) => predicate(arg));
|
|
13
13
|
if (index === -1) {
|
|
14
14
|
throw new ArgumentNotFoundError_1.ArgumentNotFoundError();
|
package/esm/provider/Provider.js
CHANGED
|
@@ -29,7 +29,7 @@ export class Provider {
|
|
|
29
29
|
if (!this.getKey) {
|
|
30
30
|
return this.resolveDep(scope, options);
|
|
31
31
|
}
|
|
32
|
-
const key = toString(this.getKey(
|
|
32
|
+
const key = toString(this.getKey(options.args ?? []));
|
|
33
33
|
if (!this.cache.has(key)) {
|
|
34
34
|
this.cache.set(key, this.resolveDep(scope, options));
|
|
35
35
|
}
|
package/esm/utils/array.js
CHANGED
|
@@ -5,7 +5,7 @@ export const Filter = {
|
|
|
5
5
|
return (v) => !excludeSet.has(v);
|
|
6
6
|
},
|
|
7
7
|
};
|
|
8
|
-
export const findOrFail = (predicate) => (
|
|
8
|
+
export const findOrFail = (predicate) => (args = []) => {
|
|
9
9
|
const index = args.findIndex((arg) => predicate(arg));
|
|
10
10
|
if (index === -1) {
|
|
11
11
|
throw new ArgumentNotFoundError();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-ioc-container",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "71.0.0",
|
|
4
4
|
"description": "Fast, lightweight TypeScript dependency injection container with a clean API, scoped lifecycles, decorators, tokens, hooks, lazy injection, customizable providers, and no global container objects.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -13,7 +13,7 @@ export type ScopeAccessOptions = {
|
|
|
13
13
|
};
|
|
14
14
|
export type ScopeAccessRule = (options: ScopeAccessOptions, prev: boolean) => boolean;
|
|
15
15
|
export type ArgsFn = (l: IContainer, options?: InjectOptions) => unknown[];
|
|
16
|
-
export type GetCacheKey = (
|
|
16
|
+
export type GetCacheKey = (args: unknown[]) => string | Serializable;
|
|
17
17
|
export type DecorateFn<Instance = any> = (dep: Instance, scope: IContainer) => Instance;
|
|
18
18
|
export type ProviderHook = (dependency: unknown, scope: IContainer) => void;
|
|
19
19
|
export interface IProvider<T = any> {
|
|
@@ -12,4 +12,4 @@ export declare abstract class InjectionToken<T = any> {
|
|
|
12
12
|
hasTag(tag: Tag): boolean;
|
|
13
13
|
protected getTags(): Tag[];
|
|
14
14
|
}
|
|
15
|
-
export declare function isInjectionToken(target: unknown): target is InjectionToken
|
|
15
|
+
export declare function isInjectionToken<T = any>(target: unknown): target is InjectionToken<T>;
|
|
@@ -5,5 +5,5 @@ import { type constructor } from '../utils/basic.js';
|
|
|
5
5
|
import { type MapFn } from '../utils/fp.js';
|
|
6
6
|
export type Injectable<T = any> = InjectFn<T> | InjectionToken<T> | DependencyKey | constructor<T>;
|
|
7
7
|
export declare const toToken: <T = any>(token: Injectable<T>) => InjectionToken<T>;
|
|
8
|
-
export declare const argToToken: (v:
|
|
8
|
+
export declare const argToToken: <T = unknown>(v: T) => InjectionToken<T>;
|
|
9
9
|
export declare const toMappedToken: <T = any, R = T>(token: Injectable<T>, mappers: MapFn<any, any>[]) => InjectionToken<R>;
|
package/typings/utils/array.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export type Predicate<T> = (value: T) => boolean;
|
|
|
2
2
|
export declare const Filter: {
|
|
3
3
|
exclude: <T>(arr: Set<T> | T[]) => (v: T) => boolean;
|
|
4
4
|
};
|
|
5
|
-
export declare const findOrFail: <T>(predicate: Predicate<T>) => (
|
|
5
|
+
export declare const findOrFail: <T>(predicate: Predicate<T>) => (args?: unknown[]) => T;
|