node-dependency-injection 4.0.0-alpha.0 → 4.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/.eslintrc +16 -0
- package/.github/workflows/build.yml +24 -0
- package/.github/workflows/publish.yml +35 -0
- package/.mocharc.yaml +0 -1
- package/CHANGELOG-3.md +6 -1
- package/CONTRIBUTING.md +2 -2
- package/README.md +337 -112
- package/UPGRADE-3.0.md +4 -1
- package/UPGRADE-4.0.md +50 -0
- package/assets/logo.png +0 -0
- package/bin/Services/File/XmlAdapter.js +53 -0
- package/bin/ndi-container:service.js +5 -0
- package/bin/ndi-container:validate.js +116 -0
- package/bin/ndi.js +1 -0
- package/dist/bin/Services/File/BaseAdapter.js +1 -50
- package/dist/bin/Services/File/FileManager.js +1 -55
- package/dist/bin/Services/File/JsAdapter.js +1 -62
- package/dist/bin/Services/File/JsonAdapter.js +1 -60
- package/dist/bin/Services/File/XmlAdapter.js +1 -0
- package/dist/bin/Services/File/YamlAdapter.js +1 -67
- package/dist/bin/ndi-config:check.js +1 -55
- package/dist/bin/ndi-config:create.js +1 -40
- package/dist/bin/ndi-container:service.js +1 -131
- package/dist/bin/ndi-container:validate.js +2 -0
- package/dist/bin/ndi.js +1 -9
- package/dist/lib/Autowire.js +1 -281
- package/dist/lib/AutowireIdentifier.js +1 -0
- package/dist/lib/Compiler.js +1 -101
- package/dist/lib/CompilerPass/AutowireOverridePass.js +1 -0
- package/dist/lib/CompilerPass/DecoratePass.js +1 -118
- package/dist/lib/CompilerPass/OptimizePass.js +1 -60
- package/dist/lib/CompilerPass/RemovePass.js +1 -57
- package/dist/lib/CompilerPass/index.js +1 -131
- package/dist/lib/Condition.js +1 -0
- package/dist/lib/ContainerBuilder.js +1 -463
- package/dist/lib/ContainerValidator.js +1 -0
- package/dist/lib/Definition.js +1 -371
- package/dist/lib/Dump/Dumper.js +1 -0
- package/dist/lib/Dump/JsDumper.js +1 -0
- package/dist/lib/Dump/JsonDumper.js +1 -0
- package/dist/lib/Dump/XmlDumper.js +1 -0
- package/dist/lib/Dump/YamlDumper.js +1 -0
- package/dist/lib/Exception/AbstractServiceException.js +1 -47
- package/dist/lib/Exception/AttributesMapException.js +1 -44
- package/dist/lib/Exception/CannotAutowireOverrideSearch.js +1 -0
- package/dist/lib/Exception/ConfigurationFileNotFoundException.js +1 -47
- package/dist/lib/Exception/ContainerDefaultDirMustBeSet.js +1 -0
- package/dist/lib/Exception/ContainerValidationError.js +1 -0
- package/dist/lib/Exception/DefinitionNotFoundException.js +1 -47
- package/dist/lib/Exception/FrozenContainerException.js +1 -44
- package/dist/lib/Exception/KeyedGroupNoDefaultException.js +1 -0
- package/dist/lib/Exception/KeyedGroupNotFoundException.js +1 -0
- package/dist/lib/Exception/KeyedServiceNotFoundException.js +1 -0
- package/dist/lib/Exception/LoadMethodNotFoundException.js +1 -47
- package/dist/lib/Exception/LoggerWarnMethodNotFoundException.js +1 -44
- package/dist/lib/Exception/MethodCallEmptyException.js +1 -44
- package/dist/lib/Exception/MethodCallNotFoundException.js +1 -47
- package/dist/lib/Exception/NotAbstractServiceException.js +1 -47
- package/dist/lib/Exception/PrivateServiceException.js +1 -47
- package/dist/lib/Exception/ProcessMethodNotFoundException.js +1 -47
- package/dist/lib/Exception/RootDirectoryMustBeAbsolute.js +1 -0
- package/dist/lib/Exception/RootDirectoryNotFound.js +1 -0
- package/dist/lib/Exception/ServiceCircularReferenceException.js +1 -44
- package/dist/lib/Exception/ServiceFileNotAbsolute.js +1 -0
- package/dist/lib/Exception/ServiceFileNotFoundException.js +1 -47
- package/dist/lib/Exception/ServiceFileNotLoadedException.js +1 -47
- package/dist/lib/Exception/ServiceFileNotValidExtension.js +1 -0
- package/dist/lib/Exception/ServiceNotFoundException.js +1 -48
- package/dist/lib/Exception/UnableToGetInstanceFromId.js +1 -0
- package/dist/lib/Exception/WrongCompilerPassTypeException.js +1 -47
- package/dist/lib/Exception/WrongDefinitionException.js +1 -44
- package/dist/lib/InstanceManager.js +1 -363
- package/dist/lib/KeyedGroupReference.js +1 -0
- package/dist/lib/KeyedReference.js +1 -0
- package/dist/lib/Loader/Argument.js +1 -0
- package/dist/lib/Loader/FileLoader.js +1 -417
- package/dist/lib/Loader/JsFileLoader.js +1 -68
- package/dist/lib/Loader/JsonFileLoader.js +1 -40
- package/dist/lib/Loader/XmlFileLoader.js +1 -0
- package/dist/lib/Loader/YamlFileLoader.js +1 -88
- package/dist/lib/LoggerHelper.js +1 -0
- package/dist/lib/PackageReference.js +1 -37
- package/dist/lib/ParameterReference.js +1 -0
- package/dist/lib/PassConfig.js +1 -78
- package/dist/lib/Reference.js +1 -49
- package/dist/lib/ServiceFile.js +1 -0
- package/dist/lib/TagReference.js +1 -37
- package/dist/lib/ValidationResult.js +1 -0
- package/dist/lib/index.js +1 -79
- package/dist/lib/schema/services.xsd +163 -0
- package/dist/lib/types/index.d.ts +173 -11
- package/dist/lib/types/tests.ts +36 -2
- package/package.json +25 -11
- package/tsconfig.json +8 -1
- package/.travis.yml +0 -14
|
@@ -1,10 +1,36 @@
|
|
|
1
1
|
// Only for typings exports
|
|
2
2
|
|
|
3
|
+
export type AutowireIdStrategy = 'legacy' | 'readable';
|
|
4
|
+
|
|
3
5
|
export type PassConfigHook = 'beforeOptimization' | 'optimize' | 'beforeRemoving' | 'remove' | 'afterRemoving';
|
|
4
6
|
|
|
5
7
|
export type Parameter = string | boolean | object | any[];
|
|
6
8
|
|
|
7
|
-
export type Argument = TagReference | Reference | PackageReference | any;
|
|
9
|
+
export type Argument = TagReference | Reference | KeyedReference | KeyedGroupReference | PackageReference | ParameterReference | any;
|
|
10
|
+
|
|
11
|
+
export type ValidationSeverity = 'ERROR' | 'WARN' | 'INFO';
|
|
12
|
+
|
|
13
|
+
export type ValidationIssueType =
|
|
14
|
+
| 'missing_dependency'
|
|
15
|
+
| 'circular_dependency'
|
|
16
|
+
| 'unresolved_parameter'
|
|
17
|
+
| 'unused_nullable_fallback'
|
|
18
|
+
| 'deprecated_service_in_use'
|
|
19
|
+
| 'orphan_tagged_service'
|
|
20
|
+
| 'keyed_group_no_default';
|
|
21
|
+
|
|
22
|
+
export interface ValidationIssue {
|
|
23
|
+
severity: ValidationSeverity;
|
|
24
|
+
type: ValidationIssueType;
|
|
25
|
+
service: string;
|
|
26
|
+
detail: string;
|
|
27
|
+
message: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface CompileOptions {
|
|
31
|
+
validate?: boolean;
|
|
32
|
+
throwOnError?: boolean;
|
|
33
|
+
}
|
|
8
34
|
|
|
9
35
|
export interface Extension {
|
|
10
36
|
load: Function;
|
|
@@ -12,10 +38,14 @@ export interface Extension {
|
|
|
12
38
|
|
|
13
39
|
export interface Logger {
|
|
14
40
|
warn(message?: any, ...optionalParams: any[]): void;
|
|
41
|
+
info?(message?: any, ...optionalParams: any[]): void;
|
|
42
|
+
debug?(message?: any, ...optionalParams: any[]): void;
|
|
15
43
|
}
|
|
16
44
|
|
|
45
|
+
export type Verbosity = 'silent' | 'warn' | 'info' | 'debug';
|
|
46
|
+
|
|
17
47
|
export interface CompilerPass {
|
|
18
|
-
process(container: ContainerBuilder): void
|
|
48
|
+
process(container: ContainerBuilder): Promise<void>;
|
|
19
49
|
}
|
|
20
50
|
|
|
21
51
|
export interface Factory {
|
|
@@ -36,14 +66,18 @@ export interface Tag {
|
|
|
36
66
|
export class InstanceManager {
|
|
37
67
|
constructor(containerBuilder: ContainerBuilder, definitions: Map<string, Definition>, alias: Map<string, string>);
|
|
38
68
|
|
|
39
|
-
getInstance(id:
|
|
69
|
+
getInstance(id: any, bypassPublic?: boolean): any;
|
|
40
70
|
|
|
41
71
|
getInstanceFromDefinition(definition: Definition): any;
|
|
72
|
+
|
|
73
|
+
searchDefinitionsToOverrideArgs(): Map<string, Definition>;
|
|
74
|
+
|
|
75
|
+
searchNotOverrideDefinitionsByObject(Object: any): Map<string, Definition>;
|
|
42
76
|
}
|
|
43
77
|
|
|
44
78
|
// Package exports
|
|
45
79
|
export class ContainerBuilder {
|
|
46
|
-
|
|
80
|
+
defaultDir: string;
|
|
47
81
|
readonly containerReferenceAsService: boolean;
|
|
48
82
|
readonly definitions: Map<string, Definition>;
|
|
49
83
|
readonly instanceManager: InstanceManager;
|
|
@@ -51,25 +85,35 @@ export class ContainerBuilder {
|
|
|
51
85
|
readonly services: Map<string, any>;
|
|
52
86
|
frozen: boolean;
|
|
53
87
|
logger: Logger;
|
|
88
|
+
verbosity: Verbosity;
|
|
89
|
+
autowire: Autowire | null;
|
|
54
90
|
|
|
55
91
|
constructor(containerReferenceAsService?: boolean, defaultDir?: string | null);
|
|
56
92
|
|
|
57
93
|
addCompilerPass(compilerPass: any, type?: PassConfigHook, priority?: number): void;
|
|
58
94
|
|
|
59
|
-
compile():
|
|
95
|
+
compile(): Promise<undefined>;
|
|
96
|
+
compile(options: CompileOptions & { validate: true }): Promise<ValidationResult>;
|
|
97
|
+
compile(options?: CompileOptions): Promise<ValidationResult | undefined>;
|
|
60
98
|
|
|
61
|
-
findDefinition(key: string): Definition
|
|
99
|
+
findDefinition(key: string): Promise<Definition>;
|
|
62
100
|
|
|
63
|
-
findTaggedServiceIds(name: string):
|
|
101
|
+
findTaggedServiceIds(name: string): Iterable<{id: string, definition: Definition}>;
|
|
64
102
|
|
|
65
|
-
get<T = any>(id: string): T;
|
|
103
|
+
get<T = any>(id: string|any): T;
|
|
66
104
|
|
|
67
105
|
getDefinition(key: string): Definition;
|
|
68
106
|
|
|
69
107
|
getParameter<T extends Parameter>(key: string): T;
|
|
70
108
|
|
|
109
|
+
getKeyed<T = any>(group: string, key?: string | null): T;
|
|
110
|
+
|
|
111
|
+
getKeyedGroup<T = any>(group: string): Map<string, T>;
|
|
112
|
+
|
|
71
113
|
has(key: string): boolean;
|
|
72
114
|
|
|
115
|
+
hasAlias(alias: string): boolean;
|
|
116
|
+
|
|
73
117
|
hasDefinition(key: string): boolean;
|
|
74
118
|
|
|
75
119
|
hasParameter(key: string): boolean;
|
|
@@ -78,6 +122,8 @@ export class ContainerBuilder {
|
|
|
78
122
|
|
|
79
123
|
register(id: string, object?: any, args?: Argument[]): Definition;
|
|
80
124
|
|
|
125
|
+
registerKeyed(group: string, key: string, object?: any, args?: Argument[]): Definition;
|
|
126
|
+
|
|
81
127
|
registerExtension(extension: Extension): void;
|
|
82
128
|
|
|
83
129
|
remove(id: string): void;
|
|
@@ -98,6 +144,7 @@ export class Definition {
|
|
|
98
144
|
Object: any
|
|
99
145
|
args: Argument[];
|
|
100
146
|
appendArgs: Argument[];
|
|
147
|
+
overrideArgs: Argument[];
|
|
101
148
|
public: boolean;
|
|
102
149
|
deprecated: string;
|
|
103
150
|
lazy: boolean;
|
|
@@ -107,14 +154,20 @@ export class Definition {
|
|
|
107
154
|
shared: boolean;
|
|
108
155
|
abstract: boolean;
|
|
109
156
|
parent: string;
|
|
157
|
+
keyedGroup: string | null;
|
|
158
|
+
keyedKey: string | null;
|
|
159
|
+
keyedDefault: boolean;
|
|
110
160
|
readonly factory: Factory | null;
|
|
111
161
|
readonly calls: Call[];
|
|
112
162
|
readonly tags: Tag[];
|
|
113
163
|
readonly properties: Map<string, any>;
|
|
164
|
+
readonly condition: Condition | null;
|
|
165
|
+
readonly whenMissingId: string | null;
|
|
166
|
+
readonly whenServiceExistsId: string | null;
|
|
114
167
|
|
|
115
|
-
constructor(object?: any, args?: Argument[]);
|
|
168
|
+
constructor(object?: any, args?: Argument[], overrideArgs?: Argument[]);
|
|
116
169
|
|
|
117
|
-
addArgument(argument: Argument): Definition;
|
|
170
|
+
addArgument(argument: Argument, append?: boolean): Definition;
|
|
118
171
|
|
|
119
172
|
addMethodCall(method: string, args: any[]): Definition;
|
|
120
173
|
|
|
@@ -124,8 +177,16 @@ export class Definition {
|
|
|
124
177
|
|
|
125
178
|
isPublic(bypassPublic?: boolean): boolean;
|
|
126
179
|
|
|
180
|
+
setDefault(value: boolean): Definition;
|
|
181
|
+
|
|
127
182
|
setFactory(Object: Reference | Object, method: string): void;
|
|
128
183
|
|
|
184
|
+
setCondition(condition: Condition): Definition;
|
|
185
|
+
|
|
186
|
+
whenMissing(id: string): Definition;
|
|
187
|
+
|
|
188
|
+
whenServiceExists(id: string): Definition;
|
|
189
|
+
|
|
129
190
|
}
|
|
130
191
|
|
|
131
192
|
export class PackageReference {
|
|
@@ -147,6 +208,19 @@ export class TagReference {
|
|
|
147
208
|
constructor(name: string);
|
|
148
209
|
}
|
|
149
210
|
|
|
211
|
+
export class KeyedReference {
|
|
212
|
+
readonly group: string;
|
|
213
|
+
readonly key: string;
|
|
214
|
+
|
|
215
|
+
constructor(group: string, key: string);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export class KeyedGroupReference {
|
|
219
|
+
readonly group: string;
|
|
220
|
+
|
|
221
|
+
constructor(group: string);
|
|
222
|
+
}
|
|
223
|
+
|
|
150
224
|
export class PassConfig {
|
|
151
225
|
static readonly TYPE_BEFORE_OPTIMIZATION: PassConfigHook;
|
|
152
226
|
static readonly TYPE_OPTIMIZE: PassConfigHook;
|
|
@@ -160,7 +234,7 @@ export class PassConfig {
|
|
|
160
234
|
export class FileLoader {
|
|
161
235
|
constructor(container: ContainerBuilder);
|
|
162
236
|
|
|
163
|
-
load(file: string | null): void
|
|
237
|
+
load(file: string | null): Promise<void>;
|
|
164
238
|
}
|
|
165
239
|
|
|
166
240
|
export class YamlFileLoader extends FileLoader {
|
|
@@ -171,3 +245,91 @@ export class JsFileLoader extends FileLoader {
|
|
|
171
245
|
|
|
172
246
|
export class JsonFileLoader extends JsFileLoader {
|
|
173
247
|
}
|
|
248
|
+
|
|
249
|
+
export class XmlFileLoader extends FileLoader {
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export class Autowire {
|
|
253
|
+
constructor (container: ContainerBuilder, tsConfigFullPath?: string);
|
|
254
|
+
|
|
255
|
+
get container (): ContainerBuilder;
|
|
256
|
+
|
|
257
|
+
process (): Promise<void>;
|
|
258
|
+
|
|
259
|
+
addExclude(excludedPath: string): void;
|
|
260
|
+
|
|
261
|
+
set serviceFile(serviceFile: ServiceFile);
|
|
262
|
+
|
|
263
|
+
get serviceFile(): ServiceFile;
|
|
264
|
+
|
|
265
|
+
get idStrategy(): AutowireIdStrategy;
|
|
266
|
+
|
|
267
|
+
makeIdReadable(): void;
|
|
268
|
+
|
|
269
|
+
makeIdLegacy(): void;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export class ServiceFile {
|
|
273
|
+
constructor (servicesDumpPath: string, absolutePath?: boolean);
|
|
274
|
+
|
|
275
|
+
generateFromContainer(container: ContainerBuilder): Promise<void>;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export class ParameterReference {
|
|
279
|
+
readonly key: string;
|
|
280
|
+
|
|
281
|
+
constructor(key: string);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export class ValidationResult {
|
|
285
|
+
readonly errors: ValidationIssue[];
|
|
286
|
+
readonly warnings: ValidationIssue[];
|
|
287
|
+
readonly info: ValidationIssue[];
|
|
288
|
+
readonly isValid: boolean;
|
|
289
|
+
serviceCount: number;
|
|
290
|
+
|
|
291
|
+
addError(type: ValidationIssueType, service: string, detail: string, message: string): void;
|
|
292
|
+
addWarning(type: ValidationIssueType, service: string, detail: string, message: string): void;
|
|
293
|
+
addInfo(type: ValidationIssueType, service: string, detail: string, message: string): void;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export class ContainerValidationError extends Error {
|
|
297
|
+
readonly result: ValidationResult;
|
|
298
|
+
|
|
299
|
+
constructor(result: ValidationResult);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export class ContainerValidator {
|
|
303
|
+
constructor(container: ContainerBuilder);
|
|
304
|
+
|
|
305
|
+
validate(): ValidationResult;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export class Condition {
|
|
309
|
+
readonly type: string;
|
|
310
|
+
readonly options: object;
|
|
311
|
+
|
|
312
|
+
constructor(type: string, options?: object);
|
|
313
|
+
|
|
314
|
+
isPhaseOne(): boolean;
|
|
315
|
+
|
|
316
|
+
isPhaseTwo(): boolean;
|
|
317
|
+
|
|
318
|
+
evaluate(): boolean;
|
|
319
|
+
|
|
320
|
+
evaluatePhaseTwo(remainingIds: Set<string>): boolean;
|
|
321
|
+
|
|
322
|
+
static envExists(varName: string): Condition;
|
|
323
|
+
|
|
324
|
+
static envEquals(varName: string, value: string): Condition;
|
|
325
|
+
|
|
326
|
+
static custom(fn: () => boolean): Condition;
|
|
327
|
+
|
|
328
|
+
static all(...conditions: Condition[]): Condition;
|
|
329
|
+
|
|
330
|
+
static any(...conditions: Condition[]): Condition;
|
|
331
|
+
|
|
332
|
+
static missing(id: string): Condition;
|
|
333
|
+
|
|
334
|
+
static serviceExists(id: string): Condition;
|
|
335
|
+
}
|
package/dist/lib/types/tests.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Autowire,
|
|
2
3
|
Call,
|
|
3
4
|
CompilerPass,
|
|
4
5
|
ContainerBuilder,
|
|
@@ -9,7 +10,9 @@ import {
|
|
|
9
10
|
PackageReference,
|
|
10
11
|
PassConfig,
|
|
11
12
|
Reference,
|
|
13
|
+
ServiceFile,
|
|
12
14
|
Tag,
|
|
15
|
+
XmlFileLoader,
|
|
13
16
|
YamlFileLoader
|
|
14
17
|
} from './index'
|
|
15
18
|
|
|
@@ -53,7 +56,7 @@ class SomeManager {
|
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
class CustomPass implements CompilerPass {
|
|
56
|
-
process(container: ContainerBuilder) {
|
|
59
|
+
async process(container: ContainerBuilder) {
|
|
57
60
|
// ... do something during the compilation
|
|
58
61
|
}
|
|
59
62
|
}
|
|
@@ -70,6 +73,13 @@ function assertIsDefinition(value: Definition): void {
|
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
75
|
|
|
76
|
+
async function assertIsPromisedDefinition(value: Promise<Definition>): Promise<void> {
|
|
77
|
+
const definition = await value
|
|
78
|
+
if (!(definition instanceof Definition)) {
|
|
79
|
+
throw TypeError()
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
73
83
|
function assertType<T>(value: T): void {
|
|
74
84
|
}
|
|
75
85
|
|
|
@@ -115,13 +125,20 @@ container.logger = new NullLogger()
|
|
|
115
125
|
// Other methods
|
|
116
126
|
assertIsBoolean(container.has('some'))
|
|
117
127
|
assertIsBoolean(container.hasDefinition('some'))
|
|
128
|
+
assertIsBoolean(container.hasAlias('some'))
|
|
118
129
|
assertIsBoolean(container.removeDefinition('some'))
|
|
119
130
|
assertIsDefinition(container.getDefinition('some'))
|
|
120
|
-
|
|
131
|
+
assertIsPromisedDefinition(container.findDefinition('some'))
|
|
121
132
|
assertIsBoolean(container.hasParameter('mailer.transport'))
|
|
122
133
|
container.findTaggedServiceIds('tag')
|
|
123
134
|
container.setAlias('mailer', 'service.mailer')
|
|
124
135
|
container.setParameter('mailer.transport', 'sendmail')
|
|
136
|
+
// defaultDir setter
|
|
137
|
+
container.defaultDir = '/'
|
|
138
|
+
// autowire getter/setter
|
|
139
|
+
const autowire = new Autowire(container)
|
|
140
|
+
container.autowire = autowire
|
|
141
|
+
assertType<Autowire | null>(container.autowire)
|
|
125
142
|
// Compile
|
|
126
143
|
container.addCompilerPass(new CustomPass())
|
|
127
144
|
container.addCompilerPass(new CustomPass(), PassConfig.TYPE_AFTER_REMOVING)
|
|
@@ -141,10 +158,15 @@ container = new ContainerBuilder()
|
|
|
141
158
|
loader = new JsFileLoader(container)
|
|
142
159
|
loader.load('/path/to/file.js')
|
|
143
160
|
|
|
161
|
+
container = new ContainerBuilder()
|
|
162
|
+
loader = new XmlFileLoader(container)
|
|
163
|
+
loader.load('/path/to/file.xml')
|
|
164
|
+
|
|
144
165
|
// * Definition *
|
|
145
166
|
// Constructor
|
|
146
167
|
new Definition()
|
|
147
168
|
new Definition(null, ['some_argument'])
|
|
169
|
+
new Definition(Mailer, ['sendmail'], [new Reference('other')])
|
|
148
170
|
const mailerDefinition = new Definition(Mailer, ['sendmail'])
|
|
149
171
|
|
|
150
172
|
// Properties
|
|
@@ -160,6 +182,8 @@ mailerDefinition.parent = 'base_mailer'
|
|
|
160
182
|
mailerDefinition.Object = {}
|
|
161
183
|
mailerDefinition.args = [3.14, 'sendmail', new PackageReference('fs')]
|
|
162
184
|
mailerDefinition.appendArgs = ['sendmail']
|
|
185
|
+
mailerDefinition.overrideArgs = [new Reference('mailer')]
|
|
186
|
+
assertType<any[]>(mailerDefinition.overrideArgs)
|
|
163
187
|
// Readonly properties
|
|
164
188
|
const mailerFactory = mailerDefinition.factory
|
|
165
189
|
if (mailerFactory != null) {
|
|
@@ -175,6 +199,8 @@ mailerDefinition.addTag('tag_name')
|
|
|
175
199
|
const tagAttributes = new Map()
|
|
176
200
|
tagAttributes.set('event', 'prePersist')
|
|
177
201
|
mailerDefinition.addTag('listener', tagAttributes)
|
|
202
|
+
mailerDefinition.addArgument('arg')
|
|
203
|
+
mailerDefinition.addArgument('arg', true)
|
|
178
204
|
new Definition(SomeManager).setFactory(SomeManager, 'getFactory')
|
|
179
205
|
|
|
180
206
|
// Setter injection
|
|
@@ -185,3 +211,11 @@ container.setDefinition('mailer_manage', mailerManagerDefinition)
|
|
|
185
211
|
// Property injection
|
|
186
212
|
const definition = new Definition(NewsletterManager)
|
|
187
213
|
definition.addProperty('mailer', new Reference('mailer'))
|
|
214
|
+
|
|
215
|
+
// * ServiceFile *
|
|
216
|
+
new ServiceFile('/path/to/services.yaml')
|
|
217
|
+
new ServiceFile('/path/to/services.yaml', true)
|
|
218
|
+
|
|
219
|
+
// * Autowire *
|
|
220
|
+
const autowireWithTsConfig = new Autowire(container, '/path/to/tsconfig.json')
|
|
221
|
+
assertType<ContainerBuilder>(autowireWithTsConfig.container)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-dependency-injection",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "The NodeDependencyInjection component allows you to standardize and centralize the way objects are constructed in your application.",
|
|
5
5
|
"main": "dist/lib/index.js",
|
|
6
6
|
"directories": {
|
|
@@ -11,17 +11,16 @@
|
|
|
11
11
|
"ndi": "dist/bin/ndi.js"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
|
-
"test": "cross-env NODE_ENV=test mocha
|
|
15
|
-
"test:coverage": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text mocha",
|
|
14
|
+
"test": "cross-env NODE_ENV=test ts-mocha --paths",
|
|
15
|
+
"test:coverage": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text ts-mocha --paths",
|
|
16
16
|
"test:standard": "standard",
|
|
17
17
|
"test:standard:fix": "standard --fix",
|
|
18
|
-
"build:lib": "rm -rf dist/lib/* && babel lib -d dist/lib -D",
|
|
19
|
-
"build:bin": "rm -rf dist/bin/* && babel bin -d dist/bin -D",
|
|
18
|
+
"build:lib": "rm -rf dist/lib/* && babel lib -d dist/lib -D --compact --no-comments",
|
|
19
|
+
"build:bin": "rm -rf dist/bin/* && babel bin -d dist/bin -D --compact --no-comments",
|
|
20
20
|
"build": "npm run build:lib && npm run build:bin",
|
|
21
21
|
"report:coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
|
|
22
22
|
"preversion": "npm run test:standard && npm test",
|
|
23
|
-
"
|
|
24
|
-
"postversion": "git push && git push --tags && npm publish"
|
|
23
|
+
"postversion": "git push && git push --tags"
|
|
25
24
|
},
|
|
26
25
|
"standard": {
|
|
27
26
|
"ignore": [
|
|
@@ -49,32 +48,47 @@
|
|
|
49
48
|
"url": "https://github.com/zazoomauro/node-dependency-injection/issues"
|
|
50
49
|
},
|
|
51
50
|
"homepage": "https://github.com/zazoomauro/node-dependency-injection#readme",
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=15.0.0"
|
|
53
|
+
},
|
|
52
54
|
"dependencies": {
|
|
53
|
-
"@babel/
|
|
54
|
-
"@typescript-eslint/
|
|
55
|
+
"@babel/runtime": "^7.26.10",
|
|
56
|
+
"@typescript-eslint/typescript-estree": "^5.23.0",
|
|
55
57
|
"chalk": "^4.1.0",
|
|
56
58
|
"commander": "^8.3.0",
|
|
57
59
|
"console.table": "^0.10.0",
|
|
58
|
-
"
|
|
60
|
+
"fast-xml-parser": "^5.7.3",
|
|
61
|
+
"js-yaml": "^4.1.1",
|
|
62
|
+
"json5": "^2.2.2",
|
|
59
63
|
"validate-npm-package-name": "^3.0.0"
|
|
60
64
|
},
|
|
61
65
|
"devDependencies": {
|
|
62
66
|
"@babel/cli": "^7.17.10",
|
|
63
67
|
"@babel/core": "^7.17.10",
|
|
68
|
+
"@babel/plugin-transform-runtime": "^7.25.4",
|
|
64
69
|
"@babel/preset-env": "^7.17.10",
|
|
65
70
|
"@babel/register": "^7.17.7",
|
|
66
71
|
"@types/chai": "^4.3.1",
|
|
72
|
+
"@types/expect": "^24.3.0",
|
|
67
73
|
"@types/mocha": "^9.1.1",
|
|
68
74
|
"babel-plugin-istanbul": "^6.1.1",
|
|
69
75
|
"chai": "^4.3.6",
|
|
76
|
+
"chai-as-promised": "^7.1.1",
|
|
77
|
+
"chai-iterator": "^3.0.2",
|
|
70
78
|
"codecov": "^4.0.0-0",
|
|
71
79
|
"cross-env": "^7.0.3",
|
|
80
|
+
"eslint": "^8.57.1",
|
|
81
|
+
"eslint-config-standard": "^17.0.0",
|
|
82
|
+
"eslint-plugin-n": "^15.2.0",
|
|
83
|
+
"eslint-plugin-sonarjs": "^0.13.0",
|
|
72
84
|
"istanbul": "^0.4.5",
|
|
73
85
|
"mocha": "^9.2.2",
|
|
74
86
|
"nyc": "^15.1.0",
|
|
75
87
|
"sinon": "^11.1.2",
|
|
76
88
|
"standard": "^16.0.4",
|
|
89
|
+
"ts-mocha": "^10.0.0",
|
|
77
90
|
"ts-node": "^10.7.0",
|
|
91
|
+
"tsconfig-paths": "^4.0.0",
|
|
78
92
|
"typescript": "^4.6.4"
|
|
79
93
|
},
|
|
80
94
|
"babel": {
|
|
@@ -82,7 +96,7 @@
|
|
|
82
96
|
"@babel/preset-env"
|
|
83
97
|
],
|
|
84
98
|
"plugins": [
|
|
85
|
-
"@babel/
|
|
99
|
+
"@babel/transform-runtime"
|
|
86
100
|
],
|
|
87
101
|
"env": {
|
|
88
102
|
"test": {
|
package/tsconfig.json
CHANGED