@mmstack/di 19.3.0 → 20.5.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/fesm2022/mmstack-di.mjs +3 -3
- package/index.d.ts +73 -2
- package/package.json +2 -2
- package/lib/injectable.d.ts +0 -61
- package/lib/root-injectable.d.ts +0 -19
package/fesm2022/mmstack-di.mjs
CHANGED
|
@@ -57,10 +57,10 @@ class RootInjectables {
|
|
|
57
57
|
get(key) {
|
|
58
58
|
return this.registry[key];
|
|
59
59
|
}
|
|
60
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
61
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
60
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.17", ngImport: i0, type: RootInjectables, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
61
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.17", ngImport: i0, type: RootInjectables, providedIn: 'root' });
|
|
62
62
|
}
|
|
63
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
63
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.17", ngImport: i0, type: RootInjectables, decorators: [{
|
|
64
64
|
type: Injectable,
|
|
65
65
|
args: [{
|
|
66
66
|
providedIn: 'root',
|
package/index.d.ts
CHANGED
|
@@ -1,2 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { InjectOptions, Provider, Type, AbstractType, InjectionToken, Injector } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
type ServiceType<T> = T extends Type<infer U> ? U : T extends AbstractType<infer U> ? U : T extends InjectionToken<infer U> ? U : never;
|
|
4
|
+
type MapDeps<T extends readonly any[]> = {
|
|
5
|
+
[K in keyof T]: ServiceType<T[K]>;
|
|
6
|
+
};
|
|
7
|
+
type ProviderFn<T> = {
|
|
8
|
+
(value: T): Provider;
|
|
9
|
+
<const TDeps extends any[]>(fn: (...deps: MapDeps<TDeps>) => T, deps: TDeps): Provider;
|
|
10
|
+
};
|
|
11
|
+
type InjectFns<T> = [
|
|
12
|
+
(opt?: Omit<InjectOptions, 'optional'>) => T,
|
|
13
|
+
ProviderFn<T>
|
|
14
|
+
];
|
|
15
|
+
type FallbackInjectableOptions<T> = {
|
|
16
|
+
/** Default value returned when the injectable is not provided */
|
|
17
|
+
fallback: T;
|
|
18
|
+
};
|
|
19
|
+
type LazyFallbackInjectableOptions<T> = {
|
|
20
|
+
/** Function that returns a default value when the injectable is not provided. Useful for expensive defaults. */
|
|
21
|
+
lazyFallback: () => T;
|
|
22
|
+
};
|
|
23
|
+
type ErrorMessageInjectableOptions = {
|
|
24
|
+
/** Error message thrown when the injectable is not provided */
|
|
25
|
+
errorMessage: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Creates a typed InjectionToken with inject and provide helper functions.
|
|
29
|
+
*
|
|
30
|
+
* @param token - Unique token identifier
|
|
31
|
+
* @param opt - Optional configuration for fallback value or error message
|
|
32
|
+
* @returns A tuple of [injectFn, provideFn] for type-safe dependency injection
|
|
33
|
+
*/
|
|
34
|
+
declare function injectable<T>(token: string): InjectFns<T | null>;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a typed InjectionToken with inject and provide helper functions.
|
|
37
|
+
* Returns a fallback value when the injectable is not provided.
|
|
38
|
+
*
|
|
39
|
+
* @param token - Unique token identifier
|
|
40
|
+
* @param opt - Configuration with fallback value
|
|
41
|
+
* @returns A tuple of [injectFn, provideFn] for type-safe dependency injection
|
|
42
|
+
*/
|
|
43
|
+
declare function injectable<T>(token: string, opt: FallbackInjectableOptions<T>): InjectFns<T>;
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* Creates a typed InjectionToken with inject and provide helper functions.
|
|
47
|
+
* Returns a lazily evaluated fallback value when the injectable is not provided.
|
|
48
|
+
*
|
|
49
|
+
* @param token
|
|
50
|
+
* @param opt
|
|
51
|
+
*/
|
|
52
|
+
declare function injectable<T>(token: string, opt: LazyFallbackInjectableOptions<T>): InjectFns<T>;
|
|
53
|
+
/**
|
|
54
|
+
* Creates a typed InjectionToken with inject and provide helper functions.
|
|
55
|
+
* Throws an error with a custom message when the injectable is not provided.
|
|
56
|
+
*
|
|
57
|
+
* @param token - Unique token identifier
|
|
58
|
+
* @param opt - Configuration with error message
|
|
59
|
+
* @returns A tuple of [injectFn, provideFn] for type-safe dependency injection
|
|
60
|
+
*/
|
|
61
|
+
declare function injectable<T>(token: string, opt: ErrorMessageInjectableOptions): InjectFns<T>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Creates a lazily-initialized root-level injectable that maintains a singleton instance.
|
|
65
|
+
* The factory function runs in the root injection context on first access.
|
|
66
|
+
* This should only be used for pure singletons, if you need scoped instances use regular @Injectable services.
|
|
67
|
+
*
|
|
68
|
+
* @param register - Factory function that creates the injectable instance using the root injector
|
|
69
|
+
* @returns An inject function that returns the singleton instance
|
|
70
|
+
*/
|
|
71
|
+
declare function rootInjectable<T>(register: (injector: Injector) => T): () => T;
|
|
72
|
+
|
|
73
|
+
export { injectable, rootInjectable };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mmstack/di",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "20.5.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"angular",
|
|
6
6
|
"dependency injection",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"homepage": "https://github.com/mihajm/mmstack/blob/master/packages/di",
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"@angular/core": ">=
|
|
19
|
+
"@angular/core": ">=20 <21"
|
|
20
20
|
},
|
|
21
21
|
"sideEffects": false,
|
|
22
22
|
"module": "fesm2022/mmstack-di.mjs",
|
package/lib/injectable.d.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { InjectionToken, type AbstractType, type InjectOptions, type Provider, type Type } from '@angular/core';
|
|
2
|
-
type ServiceType<T> = T extends Type<infer U> ? U : T extends AbstractType<infer U> ? U : T extends InjectionToken<infer U> ? U : never;
|
|
3
|
-
type MapDeps<T extends readonly any[]> = {
|
|
4
|
-
[K in keyof T]: ServiceType<T[K]>;
|
|
5
|
-
};
|
|
6
|
-
type ProviderFn<T> = {
|
|
7
|
-
(value: T): Provider;
|
|
8
|
-
<const TDeps extends any[]>(fn: (...deps: MapDeps<TDeps>) => T, deps: TDeps): Provider;
|
|
9
|
-
};
|
|
10
|
-
type InjectFns<T> = [
|
|
11
|
-
(opt?: Omit<InjectOptions, 'optional'>) => T,
|
|
12
|
-
ProviderFn<T>
|
|
13
|
-
];
|
|
14
|
-
type FallbackInjectableOptions<T> = {
|
|
15
|
-
/** Default value returned when the injectable is not provided */
|
|
16
|
-
fallback: T;
|
|
17
|
-
};
|
|
18
|
-
type LazyFallbackInjectableOptions<T> = {
|
|
19
|
-
/** Function that returns a default value when the injectable is not provided. Useful for expensive defaults. */
|
|
20
|
-
lazyFallback: () => T;
|
|
21
|
-
};
|
|
22
|
-
type ErrorMessageInjectableOptions = {
|
|
23
|
-
/** Error message thrown when the injectable is not provided */
|
|
24
|
-
errorMessage: string;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Creates a typed InjectionToken with inject and provide helper functions.
|
|
28
|
-
*
|
|
29
|
-
* @param token - Unique token identifier
|
|
30
|
-
* @param opt - Optional configuration for fallback value or error message
|
|
31
|
-
* @returns A tuple of [injectFn, provideFn] for type-safe dependency injection
|
|
32
|
-
*/
|
|
33
|
-
export declare function injectable<T>(token: string): InjectFns<T | null>;
|
|
34
|
-
/**
|
|
35
|
-
* Creates a typed InjectionToken with inject and provide helper functions.
|
|
36
|
-
* Returns a fallback value when the injectable is not provided.
|
|
37
|
-
*
|
|
38
|
-
* @param token - Unique token identifier
|
|
39
|
-
* @param opt - Configuration with fallback value
|
|
40
|
-
* @returns A tuple of [injectFn, provideFn] for type-safe dependency injection
|
|
41
|
-
*/
|
|
42
|
-
export declare function injectable<T>(token: string, opt: FallbackInjectableOptions<T>): InjectFns<T>;
|
|
43
|
-
/**
|
|
44
|
-
*
|
|
45
|
-
* Creates a typed InjectionToken with inject and provide helper functions.
|
|
46
|
-
* Returns a lazily evaluated fallback value when the injectable is not provided.
|
|
47
|
-
*
|
|
48
|
-
* @param token
|
|
49
|
-
* @param opt
|
|
50
|
-
*/
|
|
51
|
-
export declare function injectable<T>(token: string, opt: LazyFallbackInjectableOptions<T>): InjectFns<T>;
|
|
52
|
-
/**
|
|
53
|
-
* Creates a typed InjectionToken with inject and provide helper functions.
|
|
54
|
-
* Throws an error with a custom message when the injectable is not provided.
|
|
55
|
-
*
|
|
56
|
-
* @param token - Unique token identifier
|
|
57
|
-
* @param opt - Configuration with error message
|
|
58
|
-
* @returns A tuple of [injectFn, provideFn] for type-safe dependency injection
|
|
59
|
-
*/
|
|
60
|
-
export declare function injectable<T>(token: string, opt: ErrorMessageInjectableOptions): InjectFns<T>;
|
|
61
|
-
export {};
|
package/lib/root-injectable.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Injector } from '@angular/core';
|
|
2
|
-
import * as i0 from "@angular/core";
|
|
3
|
-
export declare class RootInjectables {
|
|
4
|
-
private readonly injector;
|
|
5
|
-
private readonly registry;
|
|
6
|
-
register<T>(register: (injector: Injector) => T): string;
|
|
7
|
-
get<T>(key: string): T;
|
|
8
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<RootInjectables, never>;
|
|
9
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<RootInjectables>;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Creates a lazily-initialized root-level injectable that maintains a singleton instance.
|
|
13
|
-
* The factory function runs in the root injection context on first access.
|
|
14
|
-
* This should only be used for pure singletons, if you need scoped instances use regular @Injectable services.
|
|
15
|
-
*
|
|
16
|
-
* @param register - Factory function that creates the injectable instance using the root injector
|
|
17
|
-
* @returns An inject function that returns the singleton instance
|
|
18
|
-
*/
|
|
19
|
-
export declare function rootInjectable<T>(register: (injector: Injector) => T): () => T;
|