static-injector 2.1.0 → 2.2.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/import/commonjs/index.js +403 -211
- package/import/{es2015 → es2022}/di/create_injector.js +5 -3
- package/import/{es2015 → es2022}/di/forward_ref.js +32 -5
- package/import/{es2015 → es2022}/di/injection_token.js +20 -11
- package/import/{es2015 → es2022}/di/injector.js +15 -16
- package/import/{es2015 → es2022}/di/injector_compatibility.js +27 -13
- package/import/{es2015 → es2022}/di/injector_token.js +3 -3
- package/import/{es2015 → es2022}/di/interface/defs.js +22 -27
- package/import/{es2015 → es2022}/di/interface/injector.js +1 -1
- package/import/{es2015 → es2022}/di/interface/provider.js +3 -1
- package/import/{es2015 → es2022}/di/null_injector.js +3 -3
- package/import/es2022/di/provider_collection.js +104 -0
- package/import/{es2015 → es2022}/di/r3_injector.js +71 -37
- package/import/es2022/error_details_base_url.js +19 -0
- package/import/es2022/errors.js +44 -0
- package/import/es2022/interface/type.js +21 -0
- package/import/{es2015 → es2022}/render3/definition_factory.js +2 -3
- package/import/{es2015 → es2022}/render3/error_code.js +1 -0
- package/import/{es2015 → es2022}/render3/errors_di.js +2 -3
- package/import/es2022/render3/fields.js +22 -0
- package/import/{es2015 → es2022}/render3/instructions/di.js +0 -7
- package/import/{es2015 → es2022}/render3/util/stringify_utils.js +5 -5
- package/import/{es2015 → es2022}/util/array_utils.js +0 -7
- package/import/es2022/util/decorators.js +53 -0
- package/import/{es2015 → es2022}/util/empty.js +4 -0
- package/import/{es2015 → es2022}/util/stringify.js +5 -5
- package/import/{fesm2015 → fesm2022}/index.js +399 -209
- package/import/typings/di/create_injector.d.ts +3 -5
- package/import/typings/di/forward_ref.d.ts +30 -3
- package/import/typings/di/inject_switch.d.ts +1 -1
- package/import/typings/di/injectable.d.ts +4 -3
- package/import/typings/di/injection_token.d.ts +21 -6
- package/import/typings/di/injector.d.ts +19 -3
- package/import/typings/di/injector_compatibility.d.ts +12 -5
- package/import/typings/di/injector_token.d.ts +2 -2
- package/import/typings/di/interface/defs.d.ts +17 -9
- package/import/typings/di/interface/injector.d.ts +2 -2
- package/import/typings/di/interface/provider.d.ts +64 -4
- package/import/typings/di/metadata.d.ts +4 -4
- package/import/typings/di/null_injector.d.ts +1 -1
- package/import/typings/di/provider_collection.d.ts +53 -11
- package/import/typings/di/provider_token.d.ts +2 -2
- package/import/typings/di/r3_injector.d.ts +11 -14
- package/import/typings/di/scope.d.ts +1 -1
- package/import/typings/error_details_base_url.d.ts +19 -0
- package/import/typings/errors.d.ts +114 -0
- package/import/typings/interface/type.d.ts +45 -0
- package/import/typings/render3/errors_di.d.ts +7 -0
- package/import/typings/render3/fields.d.ts +9 -0
- package/import/typings/render3/instructions/di.d.ts +0 -7
- package/import/typings/util/array_utils.d.ts +15 -7
- package/import/typings/util/decorators.d.ts +3 -1
- package/import/typings/util/empty.d.ts +1 -0
- package/package.json +7 -7
- package/readme.md +4 -1
- package/transform/compiler/src/injectable_compiler_2.d.ts +0 -1
- package/transform/compiler/src/injectable_compiler_2.js +31 -16
- package/transform/compiler/src/output/output_ast.d.ts +53 -10
- package/transform/compiler/src/output/output_ast.js +211 -12
- package/transform/compiler/src/parse_util.js +10 -0
- package/transform/compiler/src/render3/partial/api.js +1 -1
- package/transform/compiler/src/render3/r3_factory.d.ts +0 -8
- package/transform/compiler/src/render3/r3_factory.js +5 -4
- package/transform/compiler/src/render3/r3_identifiers.js +37 -37
- package/transform/compiler/src/render3/view/util.js +1 -3
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.js +2 -4
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/factory.js +1 -0
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.d.ts +1 -1
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +5 -9
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +2 -1
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +12 -8
- package/transform/compiler-cli/src/ngtsc/diagnostics/error.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +8 -4
- package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.js +1 -1
- package/transform/compiler-cli/src/ngtsc/imports/src/default.js +1 -2
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +24 -173
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +2 -51
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +5 -3
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +5 -10
- package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +5 -23
- package/transform/compiler-cli/src/ngtsc/transform/src/api.js +0 -21
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +1 -2
- package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +7 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/context.js +1 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +4 -2
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +1 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +10 -4
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +2 -1
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +20 -16
- package/transform/injectable-transform.d.ts +2 -2
- package/transform/injectable-transform.js +32 -6
- package/import/es2015/di/provider_collection.js +0 -49
- package/import/es2015/interface/type.js +0 -8
- package/import/es2015/render3/fields.js +0 -11
- package/import/es2015/util/decorators.js +0 -30
- /package/import/{es2015 → es2022}/di/initializer_token.js +0 -0
- /package/import/{es2015 → es2022}/di/inject_switch.js +0 -0
- /package/import/{es2015 → es2022}/di/injectable.js +0 -0
- /package/import/{es2015 → es2022}/di/injector_marker.js +0 -0
- /package/import/{es2015 → es2022}/di/internal_tokens.js +0 -0
- /package/import/{es2015 → es2022}/di/metadata.js +0 -0
- /package/import/{es2015 → es2022}/di/provider_token.js +0 -0
- /package/import/{es2015 → es2022}/di/scope.js +0 -0
- /package/import/{es2015 → es2022}/index.js +0 -0
- /package/import/{es2015 → es2022}/interface/lifecycle_hooks.js +0 -0
- /package/import/{es2015 → es2022}/render3/di.js +0 -0
- /package/import/{es2015 → es2022}/util/closure.js +0 -0
- /package/import/{es2015 → es2022}/util/property.js +0 -0
|
@@ -8,13 +8,10 @@
|
|
|
8
8
|
import { Injector } from './injector';
|
|
9
9
|
import { InjectorType } from './interface/defs';
|
|
10
10
|
import { InjectFlags, InjectOptions } from './interface/injector';
|
|
11
|
-
import {
|
|
11
|
+
import { EnvironmentProviders, Provider } from './interface/provider';
|
|
12
|
+
import { SingleProvider } from './provider_collection';
|
|
12
13
|
import { ProviderToken } from './provider_token';
|
|
13
14
|
import { InjectorScope } from './scope';
|
|
14
|
-
/**
|
|
15
|
-
* Internal type for a single provider in a deep provider array.
|
|
16
|
-
*/
|
|
17
|
-
type SingleProvider = TypeProvider | ValueProvider | ClassProvider | ConstructorProvider | ExistingProvider | FactoryProvider | StaticClassProvider;
|
|
18
15
|
export declare function getNullInjector(): Injector;
|
|
19
16
|
/**
|
|
20
17
|
* An `Injector` that's part of the environment injector hierarchy, which exists outside of the
|
|
@@ -56,19 +53,20 @@ export declare abstract class EnvironmentInjector implements Injector {
|
|
|
56
53
|
/**
|
|
57
54
|
* Runs the given function in the context of this `EnvironmentInjector`.
|
|
58
55
|
*
|
|
59
|
-
* Within the function's stack frame, `inject` can be used to inject
|
|
60
|
-
* injector. Note that `inject` is only usable synchronously, and cannot be
|
|
61
|
-
* asynchronous callbacks or after any `await` points.
|
|
56
|
+
* Within the function's stack frame, [`inject`](api/core/inject) can be used to inject
|
|
57
|
+
* dependencies from this injector. Note that `inject` is only usable synchronously, and cannot be
|
|
58
|
+
* used in any asynchronous callbacks or after any `await` points.
|
|
62
59
|
*
|
|
63
60
|
* @param fn the closure to be run in the context of this injector
|
|
64
61
|
* @returns the return value of the function, if any
|
|
62
|
+
* @deprecated use the standalone function `runInInjectionContext` instead
|
|
65
63
|
*/
|
|
66
64
|
abstract runInContext<ReturnT>(fn: () => ReturnT): ReturnT;
|
|
67
65
|
abstract destroy(): void;
|
|
68
66
|
/**
|
|
69
67
|
* @internal
|
|
70
68
|
*/
|
|
71
|
-
abstract onDestroy(callback: () => void): void;
|
|
69
|
+
abstract onDestroy(callback: () => void): () => void;
|
|
72
70
|
}
|
|
73
71
|
export declare class R3Injector extends EnvironmentInjector {
|
|
74
72
|
readonly parent: Injector;
|
|
@@ -91,7 +89,7 @@ export declare class R3Injector extends EnvironmentInjector {
|
|
|
91
89
|
get destroyed(): boolean;
|
|
92
90
|
private _destroyed;
|
|
93
91
|
private injectorDefTypes;
|
|
94
|
-
constructor(providers: Array<Provider>, parent: Injector, source: string | null, scopes: Set<InjectorScope>);
|
|
92
|
+
constructor(providers: Array<Provider | EnvironmentProviders>, parent: Injector, source: string | null, scopes: Set<InjectorScope>);
|
|
95
93
|
/**
|
|
96
94
|
* Destroy the injector and release references to every instance or provider associated with it.
|
|
97
95
|
*
|
|
@@ -99,19 +97,20 @@ export declare class R3Injector extends EnvironmentInjector {
|
|
|
99
97
|
* hook was found.
|
|
100
98
|
*/
|
|
101
99
|
destroy(): void;
|
|
102
|
-
onDestroy(callback: () => void): void;
|
|
100
|
+
onDestroy(callback: () => void): () => void;
|
|
103
101
|
runInContext<ReturnT>(fn: () => ReturnT): ReturnT;
|
|
104
102
|
get<T>(token: ProviderToken<T>, notFoundValue?: any, flags?: InjectFlags | InjectOptions): T;
|
|
105
103
|
/** @internal */
|
|
106
104
|
resolveInjectorInitializers(): void;
|
|
107
105
|
toString(): string;
|
|
108
|
-
|
|
106
|
+
assertNotDestroyed(): void;
|
|
109
107
|
/**
|
|
110
108
|
* Process a `SingleProvider` and add it.
|
|
111
109
|
*/
|
|
112
110
|
private processProvider;
|
|
113
111
|
private hydrate;
|
|
114
112
|
private injectableDefInScope;
|
|
113
|
+
private removeOnDestroy;
|
|
115
114
|
}
|
|
116
115
|
/**
|
|
117
116
|
* Converts a `SingleProvider` into a factory function.
|
|
@@ -119,5 +118,3 @@ export declare class R3Injector extends EnvironmentInjector {
|
|
|
119
118
|
* @param provider provider to convert to factory
|
|
120
119
|
*/
|
|
121
120
|
export declare function providerToFactory(provider: SingleProvider, ngModuleType?: InjectorType<any>, providers?: any[]): () => any;
|
|
122
|
-
export declare function isTypeProvider(value: SingleProvider): value is TypeProvider;
|
|
123
|
-
export {};
|
|
@@ -12,4 +12,4 @@ export type InjectorScope = 'root' | 'platform' | 'environment';
|
|
|
12
12
|
* as a root scoped injector when processing requests for unknown tokens which may indicate
|
|
13
13
|
* they are provided in the root scope.
|
|
14
14
|
*/
|
|
15
|
-
export declare const INJECTOR_SCOPE: InjectionToken<InjectorScope>;
|
|
15
|
+
export declare const INJECTOR_SCOPE: InjectionToken<InjectorScope | null>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Base URL for the error details page.
|
|
10
|
+
*
|
|
11
|
+
* Keep this constant in sync across:
|
|
12
|
+
* - packages/compiler-cli/src/ngtsc/diagnostics/src/error_details_base_url.ts
|
|
13
|
+
* - packages/core/src/error_details_base_url.ts
|
|
14
|
+
*/
|
|
15
|
+
export declare const ERROR_DETAILS_PAGE_BASE_URL = "https://angular.io/errors";
|
|
16
|
+
/**
|
|
17
|
+
* URL for the XSS security documentation.
|
|
18
|
+
*/
|
|
19
|
+
export declare const XSS_SECURITY_URL = "https://g.co/ng/security#xss";
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The list of error codes used in runtime code of the `core` package.
|
|
10
|
+
* Reserved error code range: 100-999.
|
|
11
|
+
*
|
|
12
|
+
* Note: the minus sign denotes the fact that a particular code has a detailed guide on
|
|
13
|
+
* angular.io. This extra annotation is needed to avoid introducing a separate set to store
|
|
14
|
+
* error codes which have guides, which might leak into runtime code.
|
|
15
|
+
*
|
|
16
|
+
* Full list of available error guides can be found at https://angular.io/errors.
|
|
17
|
+
*
|
|
18
|
+
* Error code ranges per package:
|
|
19
|
+
* - core (this package): 100-999
|
|
20
|
+
* - forms: 1000-1999
|
|
21
|
+
* - common: 2000-2999
|
|
22
|
+
* - animations: 3000-3999
|
|
23
|
+
* - router: 4000-4999
|
|
24
|
+
* - platform-browser: 5000-5500
|
|
25
|
+
*/
|
|
26
|
+
export declare const enum RuntimeErrorCode {
|
|
27
|
+
EXPRESSION_CHANGED_AFTER_CHECKED = -100,
|
|
28
|
+
RECURSIVE_APPLICATION_REF_TICK = 101,
|
|
29
|
+
RECURSIVE_APPLICATION_RENDER = 102,
|
|
30
|
+
CYCLIC_DI_DEPENDENCY = -200,
|
|
31
|
+
PROVIDER_NOT_FOUND = -201,
|
|
32
|
+
INVALID_FACTORY_DEPENDENCY = 202,
|
|
33
|
+
MISSING_INJECTION_CONTEXT = -203,
|
|
34
|
+
INVALID_INJECTION_TOKEN = 204,
|
|
35
|
+
INJECTOR_ALREADY_DESTROYED = 205,
|
|
36
|
+
PROVIDER_IN_WRONG_CONTEXT = 207,
|
|
37
|
+
MISSING_INJECTION_TOKEN = 208,
|
|
38
|
+
INVALID_MULTI_PROVIDER = -209,
|
|
39
|
+
MISSING_DOCUMENT = 210,
|
|
40
|
+
MULTIPLE_COMPONENTS_MATCH = -300,
|
|
41
|
+
EXPORT_NOT_FOUND = -301,
|
|
42
|
+
PIPE_NOT_FOUND = -302,
|
|
43
|
+
UNKNOWN_BINDING = 303,
|
|
44
|
+
UNKNOWN_ELEMENT = 304,
|
|
45
|
+
TEMPLATE_STRUCTURE_ERROR = 305,
|
|
46
|
+
INVALID_EVENT_BINDING = 306,
|
|
47
|
+
HOST_DIRECTIVE_UNRESOLVABLE = 307,
|
|
48
|
+
HOST_DIRECTIVE_NOT_STANDALONE = 308,
|
|
49
|
+
DUPLICATE_DIRECTITVE = 309,
|
|
50
|
+
HOST_DIRECTIVE_COMPONENT = 310,
|
|
51
|
+
HOST_DIRECTIVE_UNDEFINED_BINDING = 311,
|
|
52
|
+
HOST_DIRECTIVE_CONFLICTING_ALIAS = 312,
|
|
53
|
+
MULTIPLE_MATCHING_PIPES = 313,
|
|
54
|
+
MULTIPLE_PLATFORMS = 400,
|
|
55
|
+
PLATFORM_NOT_FOUND = 401,
|
|
56
|
+
MISSING_REQUIRED_INJECTABLE_IN_BOOTSTRAP = 402,
|
|
57
|
+
BOOTSTRAP_COMPONENTS_NOT_FOUND = -403,
|
|
58
|
+
PLATFORM_ALREADY_DESTROYED = 404,
|
|
59
|
+
ASYNC_INITIALIZERS_STILL_RUNNING = 405,
|
|
60
|
+
APPLICATION_REF_ALREADY_DESTROYED = 406,
|
|
61
|
+
RENDERER_NOT_FOUND = 407,
|
|
62
|
+
HYDRATION_NODE_MISMATCH = -500,
|
|
63
|
+
HYDRATION_MISSING_SIBLINGS = -501,
|
|
64
|
+
HYDRATION_MISSING_NODE = -502,
|
|
65
|
+
UNSUPPORTED_PROJECTION_DOM_NODES = -503,
|
|
66
|
+
INVALID_SKIP_HYDRATION_HOST = -504,
|
|
67
|
+
MISSING_HYDRATION_ANNOTATIONS = -505,
|
|
68
|
+
HYDRATION_STABLE_TIMEDOUT = -506,
|
|
69
|
+
MISSING_SSR_CONTENT_INTEGRITY_MARKER = -507,
|
|
70
|
+
SIGNAL_WRITE_FROM_ILLEGAL_CONTEXT = 600,
|
|
71
|
+
REQUIRE_SYNC_WITHOUT_SYNC_EMIT = 601,
|
|
72
|
+
INVALID_I18N_STRUCTURE = 700,
|
|
73
|
+
MISSING_LOCALE_DATA = 701,
|
|
74
|
+
IMPORT_PROVIDERS_FROM_STANDALONE = 800,
|
|
75
|
+
INVALID_DIFFER_INPUT = 900,
|
|
76
|
+
NO_SUPPORTING_DIFFER_FACTORY = 901,
|
|
77
|
+
VIEW_ALREADY_ATTACHED = 902,
|
|
78
|
+
INVALID_INHERITANCE = 903,
|
|
79
|
+
UNSAFE_VALUE_IN_RESOURCE_URL = 904,
|
|
80
|
+
UNSAFE_VALUE_IN_SCRIPT = 905,
|
|
81
|
+
MISSING_GENERATED_DEF = 906,
|
|
82
|
+
TYPE_IS_NOT_STANDALONE = 907,
|
|
83
|
+
MISSING_ZONEJS = 908,
|
|
84
|
+
UNEXPECTED_ZONE_STATE = 909,
|
|
85
|
+
UNSAFE_IFRAME_ATTRS = -910,
|
|
86
|
+
VIEW_ALREADY_DESTROYED = 911,
|
|
87
|
+
COMPONENT_ID_COLLISION = -912,
|
|
88
|
+
RUNTIME_DEPS_INVALID_IMPORTED_TYPE = 1000
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Class that represents a runtime error.
|
|
92
|
+
* Formats and outputs the error message in a consistent way.
|
|
93
|
+
*
|
|
94
|
+
* Example:
|
|
95
|
+
* ```
|
|
96
|
+
* throw new RuntimeError(
|
|
97
|
+
* RuntimeErrorCode.INJECTOR_ALREADY_DESTROYED,
|
|
98
|
+
* ngDevMode && 'Injector has already been destroyed.');
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* Note: the `message` argument contains a descriptive error message as a string in development
|
|
102
|
+
* mode (when the `ngDevMode` is defined). In production mode (after tree-shaking pass), the
|
|
103
|
+
* `message` argument becomes `false`, thus we account for it in the typings and the runtime
|
|
104
|
+
* logic.
|
|
105
|
+
*/
|
|
106
|
+
export declare class RuntimeError<T extends number = RuntimeErrorCode> extends Error {
|
|
107
|
+
code: T;
|
|
108
|
+
constructor(code: T, message: null | false | string);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Called to format a runtime error.
|
|
112
|
+
* See additional info on the `message` argument type in the `RuntimeError` class description.
|
|
113
|
+
*/
|
|
114
|
+
export declare function formatRuntimeError<T extends number = RuntimeErrorCode>(code: T, message: null | false | string): string;
|
|
@@ -5,6 +5,18 @@
|
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
|
+
/**
|
|
9
|
+
* @description
|
|
10
|
+
*
|
|
11
|
+
* Represents a type that a Component or other object is instances of.
|
|
12
|
+
*
|
|
13
|
+
* An example of a `Type` is `MyCustomComponent` class, which in JavaScript is represented by
|
|
14
|
+
* the `MyCustomComponent` constructor function.
|
|
15
|
+
*
|
|
16
|
+
* @publicApi
|
|
17
|
+
*/
|
|
18
|
+
export declare const Type: FunctionConstructor;
|
|
19
|
+
export declare function isType(v: any): v is Type<any>;
|
|
8
20
|
/**
|
|
9
21
|
* @description
|
|
10
22
|
*
|
|
@@ -19,3 +31,36 @@ export interface AbstractType<T> extends Function {
|
|
|
19
31
|
export interface Type<T> extends Function {
|
|
20
32
|
new (...args: any[]): T;
|
|
21
33
|
}
|
|
34
|
+
export type Mutable<T extends {
|
|
35
|
+
[x: string]: any;
|
|
36
|
+
}, K extends string> = {
|
|
37
|
+
[P in K]: T[P];
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Returns a writable type version of type.
|
|
41
|
+
*
|
|
42
|
+
* USAGE:
|
|
43
|
+
* Given:
|
|
44
|
+
* ```
|
|
45
|
+
* interface Person {readonly name: string}
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* We would like to get a read/write version of `Person`.
|
|
49
|
+
* ```
|
|
50
|
+
* const WritablePerson = Writable<Person>;
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* The result is that you can do:
|
|
54
|
+
*
|
|
55
|
+
* ```
|
|
56
|
+
* const readonlyPerson: Person = {name: 'Marry'};
|
|
57
|
+
* readonlyPerson.name = 'John'; // TypeError
|
|
58
|
+
* (readonlyPerson as WritablePerson).name = 'John'; // OK
|
|
59
|
+
*
|
|
60
|
+
* // Error: Correctly detects that `Person` did not have `age` property.
|
|
61
|
+
* (readonlyPerson as WritablePerson).age = 30;
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export type Writable<T> = {
|
|
65
|
+
-readonly [K in keyof T]: T[K];
|
|
66
|
+
};
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
1
8
|
/** Throws an error when a token is not found in DI. */
|
|
2
9
|
export declare function throwProviderNotFoundError(token: any, injectorName?: string): never;
|
|
@@ -6,3 +6,12 @@
|
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
8
|
export declare const NG_FACTORY_DEF: string;
|
|
9
|
+
/**
|
|
10
|
+
* The `NG_ENV_ID` field on a DI token indicates special processing in the `EnvironmentInjector`:
|
|
11
|
+
* getting such tokens from the `EnvironmentInjector` will bypass the standard DI resolution
|
|
12
|
+
* strategy and instead will return implementation produced by the `NG_ENV_ID` factory function.
|
|
13
|
+
*
|
|
14
|
+
* This particular retrieval of DI tokens is mostly done to eliminate circular dependencies and
|
|
15
|
+
* improve tree-shaking.
|
|
16
|
+
*/
|
|
17
|
+
export declare const NG_ENV_ID: string;
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google LLC All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
|
7
|
-
*/
|
|
8
1
|
/**
|
|
9
2
|
* Throws an error indicating that a factory function could not be generated by the compiler for a
|
|
10
3
|
* particular class.
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google LLC All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
|
7
|
-
*/
|
|
8
1
|
export declare function deepForEach<T>(input: (T | any[])[], fn: (value: T) => void): void;
|
|
9
2
|
export declare function newArray<T = any>(size: number): T[];
|
|
10
3
|
export declare function newArray<T>(size: number, value: T): T[];
|
|
4
|
+
/**
|
|
5
|
+
* `KeyValueArray` is an array where even positions contain keys and odd positions contain values.
|
|
6
|
+
*
|
|
7
|
+
* `KeyValueArray` provides a very efficient way of iterating over its contents. For small
|
|
8
|
+
* sets (~10) the cost of binary searching an `KeyValueArray` has about the same performance
|
|
9
|
+
* characteristics that of a `Map` with significantly better memory footprint.
|
|
10
|
+
*
|
|
11
|
+
* If used as a `Map` the keys are stored in alphabetical order so that they can be binary searched
|
|
12
|
+
* for retrieval.
|
|
13
|
+
*
|
|
14
|
+
* See: `keyValueArraySet`, `keyValueArrayGet`, `keyValueArrayIndexOf`, `keyValueArrayDelete`.
|
|
15
|
+
*/
|
|
16
|
+
export interface KeyValueArray<VALUE> extends Array<VALUE | string> {
|
|
17
|
+
__brand__: 'array-map';
|
|
18
|
+
}
|
|
@@ -23,5 +23,7 @@ export interface TypeDecorator {
|
|
|
23
23
|
*/
|
|
24
24
|
<T extends Type<any>>(type: T): T;
|
|
25
25
|
(target: Object, propertyKey?: string | symbol, parameterIndex?: number): void;
|
|
26
|
+
(target: unknown, context: unknown): void;
|
|
26
27
|
}
|
|
27
|
-
export declare
|
|
28
|
+
export declare const PARAMETERS = "__parameters__";
|
|
29
|
+
export declare function makeParamDecorator(name: string, props?: (...args: any[]) => any, parentClass?: any): any;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "static-injector",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Angular的静态注入器独立使用版本",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
7
7
|
"injector",
|
|
8
8
|
"typescript",
|
|
9
|
-
"typescript
|
|
9
|
+
"typescript 5.1.6",
|
|
10
10
|
"injectable",
|
|
11
11
|
"static-inject"
|
|
12
12
|
],
|
|
@@ -19,17 +19,17 @@
|
|
|
19
19
|
},
|
|
20
20
|
"homepage": "https://github.com/wszgrcy/static-injector#readme",
|
|
21
21
|
"main": "import/commonjs/index.js",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"module": "import/
|
|
22
|
+
"es2022": "import/fesm2022/index.js",
|
|
23
|
+
"fesm2022": "import/fesm2022/index.js",
|
|
24
|
+
"esm2022": "import/esm2022/index.js",
|
|
25
|
+
"module": "import/fesm2022/index.js",
|
|
26
26
|
"typings": "import/typings/index.d.ts",
|
|
27
27
|
"private": false,
|
|
28
28
|
"scripts": {},
|
|
29
29
|
"author": "wszgrcy",
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"typescript": "
|
|
32
|
+
"typescript": "~5.1.6"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {},
|
|
35
35
|
"sideEffects": false
|
package/readme.md
CHANGED
|
@@ -11,7 +11,6 @@ import { MaybeForwardRefExpression, R3CompiledExpression, R3Reference } from './
|
|
|
11
11
|
export interface R3InjectableMetadata {
|
|
12
12
|
name: string;
|
|
13
13
|
type: R3Reference;
|
|
14
|
-
internalType: o.Expression;
|
|
15
14
|
typeArgumentCount: number;
|
|
16
15
|
providedIn: MaybeForwardRefExpression;
|
|
17
16
|
useClass?: MaybeForwardRefExpression;
|
|
@@ -41,7 +41,6 @@ function compileInjectable(meta, resolveForwardRefs) {
|
|
|
41
41
|
const factoryMeta = {
|
|
42
42
|
name: meta.name,
|
|
43
43
|
type: meta.type,
|
|
44
|
-
internalType: meta.internalType,
|
|
45
44
|
typeArgumentCount: meta.typeArgumentCount,
|
|
46
45
|
deps: [],
|
|
47
46
|
target: r3_factory_1.FactoryTarget.Injectable,
|
|
@@ -53,14 +52,19 @@ function compileInjectable(meta, resolveForwardRefs) {
|
|
|
53
52
|
//
|
|
54
53
|
// A special case exists for useClass: Type where Type is the injectable type itself and no
|
|
55
54
|
// deps are specified, in which case 'useClass' is effectively ignored.
|
|
56
|
-
const useClassOnSelf = meta.useClass.expression.isEquivalent(meta.
|
|
55
|
+
const useClassOnSelf = meta.useClass.expression.isEquivalent(meta.type.value);
|
|
57
56
|
let deps = undefined;
|
|
58
57
|
if (meta.deps !== undefined) {
|
|
59
58
|
deps = meta.deps;
|
|
60
59
|
}
|
|
61
60
|
if (deps !== undefined) {
|
|
62
61
|
// factory: () => new meta.useClass(...deps)
|
|
63
|
-
result = (0, r3_factory_1.compileFactoryFunction)(
|
|
62
|
+
result = (0, r3_factory_1.compileFactoryFunction)({
|
|
63
|
+
...factoryMeta,
|
|
64
|
+
delegate: meta.useClass.expression,
|
|
65
|
+
delegateDeps: deps,
|
|
66
|
+
delegateType: r3_factory_1.R3FactoryDelegateType.Class,
|
|
67
|
+
});
|
|
64
68
|
}
|
|
65
69
|
else if (useClassOnSelf) {
|
|
66
70
|
result = (0, r3_factory_1.compileFactoryFunction)(factoryMeta);
|
|
@@ -74,7 +78,12 @@ function compileInjectable(meta, resolveForwardRefs) {
|
|
|
74
78
|
}
|
|
75
79
|
else if (meta.useFactory !== undefined) {
|
|
76
80
|
if (meta.deps !== undefined) {
|
|
77
|
-
result = (0, r3_factory_1.compileFactoryFunction)(
|
|
81
|
+
result = (0, r3_factory_1.compileFactoryFunction)({
|
|
82
|
+
...factoryMeta,
|
|
83
|
+
delegate: meta.useFactory,
|
|
84
|
+
delegateDeps: meta.deps || [],
|
|
85
|
+
delegateType: r3_factory_1.R3FactoryDelegateType.Function,
|
|
86
|
+
});
|
|
78
87
|
}
|
|
79
88
|
else {
|
|
80
89
|
result = {
|
|
@@ -87,21 +96,27 @@ function compileInjectable(meta, resolveForwardRefs) {
|
|
|
87
96
|
// Note: it's safe to use `meta.useValue` instead of the `USE_VALUE in meta` check used for
|
|
88
97
|
// client code because meta.useValue is an Expression which will be defined even if the actual
|
|
89
98
|
// value is undefined.
|
|
90
|
-
result = (0, r3_factory_1.compileFactoryFunction)(
|
|
99
|
+
result = (0, r3_factory_1.compileFactoryFunction)({
|
|
100
|
+
...factoryMeta,
|
|
101
|
+
expression: meta.useValue.expression,
|
|
102
|
+
});
|
|
91
103
|
}
|
|
92
104
|
else if (meta.useExisting !== undefined) {
|
|
93
105
|
// useExisting is an `inject` call on the existing token.
|
|
94
|
-
result = (0, r3_factory_1.compileFactoryFunction)(
|
|
106
|
+
result = (0, r3_factory_1.compileFactoryFunction)({
|
|
107
|
+
...factoryMeta,
|
|
108
|
+
expression: o
|
|
95
109
|
.importExpr(r3_identifiers_1.Identifiers.inject)
|
|
96
|
-
.callFn([meta.useExisting.expression])
|
|
110
|
+
.callFn([meta.useExisting.expression]),
|
|
111
|
+
});
|
|
97
112
|
}
|
|
98
113
|
else {
|
|
99
114
|
result = {
|
|
100
115
|
statements: [],
|
|
101
|
-
expression: delegateToFactory(meta.type.value, meta.
|
|
116
|
+
expression: delegateToFactory(meta.type.value, meta.type.value, resolveForwardRefs),
|
|
102
117
|
};
|
|
103
118
|
}
|
|
104
|
-
const token = meta.
|
|
119
|
+
const token = meta.type.value;
|
|
105
120
|
const injectableProps = new util_2.DefinitionMap();
|
|
106
121
|
injectableProps.set('token', token);
|
|
107
122
|
injectableProps.set('factory', result.expression);
|
|
@@ -125,30 +140,30 @@ function createInjectableType(meta) {
|
|
|
125
140
|
]));
|
|
126
141
|
}
|
|
127
142
|
exports.createInjectableType = createInjectableType;
|
|
128
|
-
function delegateToFactory(type,
|
|
129
|
-
if (type.node ===
|
|
143
|
+
function delegateToFactory(type, useType, unwrapForwardRefs) {
|
|
144
|
+
if (type.node === useType.node) {
|
|
130
145
|
// The types are the same, so we can simply delegate directly to the type's factory.
|
|
131
146
|
// ```
|
|
132
147
|
// factory: type.ɵfac
|
|
133
148
|
// ```
|
|
134
|
-
return
|
|
149
|
+
return useType.prop('ɵfac');
|
|
135
150
|
}
|
|
136
151
|
if (!unwrapForwardRefs) {
|
|
137
152
|
// The type is not wrapped in a `forwardRef()`, so we create a simple factory function that
|
|
138
153
|
// accepts a sub-type as an argument.
|
|
139
154
|
// ```
|
|
140
|
-
// factory: function(t) { return
|
|
155
|
+
// factory: function(t) { return useType.ɵfac(t); }
|
|
141
156
|
// ```
|
|
142
|
-
return createFactoryFunction(
|
|
157
|
+
return createFactoryFunction(useType);
|
|
143
158
|
}
|
|
144
|
-
// The
|
|
159
|
+
// The useType is actually wrapped in a `forwardRef()` so we need to resolve that before
|
|
145
160
|
// calling its factory.
|
|
146
161
|
// ```
|
|
147
162
|
// factory: function(t) { return core.resolveForwardRef(type).ɵfac(t); }
|
|
148
163
|
// ```
|
|
149
164
|
const unwrappedType = o
|
|
150
165
|
.importExpr(r3_identifiers_1.Identifiers.resolveForwardRef)
|
|
151
|
-
.callFn([
|
|
166
|
+
.callFn([useType]);
|
|
152
167
|
return createFactoryFunction(unwrappedType);
|
|
153
168
|
}
|
|
154
169
|
function createFactoryFunction(type) {
|