@teqfw/di 1.3.0 → 2.0.1
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/CHANGELOG.md +14 -0
- package/README.md +173 -259
- package/dist/esm.js +1 -1
- package/dist/umd.js +1 -1
- package/package.json +19 -13
- package/src/AGENTS.md +177 -0
- package/src/Config/NamespaceRegistry.mjs +210 -0
- package/src/Container/Instantiate/ExportSelector.mjs +39 -0
- package/src/Container/Instantiate/Instantiator.mjs +143 -0
- package/src/Container/Lifecycle/Registry.mjs +81 -0
- package/src/Container/Resolve/GraphResolver.mjs +119 -0
- package/src/Container/Resolver.mjs +175 -0
- package/src/Container/Wrapper/Executor.mjs +71 -0
- package/src/Container.mjs +380 -0
- package/src/Def/Parser.mjs +146 -0
- package/src/Dto/DepId.mjs +131 -0
- package/src/Dto/Resolver/Config/Namespace.mjs +48 -0
- package/src/Dto/Resolver/Config.mjs +58 -0
- package/src/Enum/Composition.mjs +11 -0
- package/src/Enum/Life.mjs +11 -0
- package/src/Enum/Platform.mjs +12 -0
- package/src/Internal/Logger.mjs +54 -0
- package/types.d.ts +24 -32
- package/src/Api/Container/Config.js +0 -73
- package/src/Api/Container/Parser/Chunk.js +0 -27
- package/src/Api/Container/Parser.js +0 -34
- package/src/Api/Container/PostProcessor/Chunk.js +0 -17
- package/src/Api/Container/PostProcessor.js +0 -29
- package/src/Api/Container/PreProcessor/Chunk.js +0 -19
- package/src/Api/Container/PreProcessor.js +0 -27
- package/src/Api/Container/Resolver.js +0 -18
- package/src/Api/Container.js +0 -19
- package/src/Container/A/Composer/A/SpecParser.js +0 -86
- package/src/Container/A/Composer.js +0 -69
- package/src/Container/A/Parser/Chunk/Def.js +0 -69
- package/src/Container/A/Parser/Chunk/V02X.js +0 -66
- package/src/Container/Config.js +0 -93
- package/src/Container/Parser.js +0 -48
- package/src/Container/PostProcessor.js +0 -32
- package/src/Container/PreProcessor.js +0 -34
- package/src/Container/Resolver.js +0 -80
- package/src/Container.js +0 -187
- package/src/Defs.js +0 -22
- package/src/DepId.js +0 -52
- package/src/Pre/Replace.js +0 -80
- package/teqfw.json +0 -8
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* DTO and factory for resolver namespace rule records.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Runtime DTO for one namespace resolution rule.
|
|
9
|
+
*/
|
|
10
|
+
export class DTO {
|
|
11
|
+
/** @type {string|undefined} Namespace prefix in depId module name. */
|
|
12
|
+
prefix;
|
|
13
|
+
/** @type {string|undefined} Import target base for matched namespace. */
|
|
14
|
+
target;
|
|
15
|
+
/** @type {string|undefined} Default extension appended to matched module path. */
|
|
16
|
+
defaultExt;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Factory for resolver namespace DTO with optional immutability.
|
|
21
|
+
*/
|
|
22
|
+
export default class Factory {
|
|
23
|
+
/**
|
|
24
|
+
* Creates normalized resolver namespace DTO.
|
|
25
|
+
*
|
|
26
|
+
* @param {Partial<TeqFw_Di_Dto_Resolver_Config_Namespace$DTO$>|Record<string, unknown>} [input] Source values.
|
|
27
|
+
* @param {{immutable?: boolean}|Record<string, unknown>} [options] Factory options.
|
|
28
|
+
* @returns {TeqFw_Di_Dto_Resolver_Config_Namespace$DTO$}
|
|
29
|
+
*/
|
|
30
|
+
create(input, options) {
|
|
31
|
+
/** @type {Partial<TeqFw_Di_Dto_Resolver_Config_Namespace$DTO$>|Record<string, unknown>} */
|
|
32
|
+
const source = (input && (typeof input === 'object')) ? input : {};
|
|
33
|
+
/** @type {{immutable?: boolean}|Record<string, unknown>} */
|
|
34
|
+
const mode = (options && (typeof options === 'object')) ? options : {};
|
|
35
|
+
|
|
36
|
+
/** @type {TeqFw_Di_Dto_Resolver_Config_Namespace$DTO$} */
|
|
37
|
+
const dto = new DTO();
|
|
38
|
+
dto.prefix = (typeof source.prefix === 'string') ? source.prefix : undefined;
|
|
39
|
+
dto.target = (typeof source.target === 'string') ? source.target : undefined;
|
|
40
|
+
dto.defaultExt = (typeof source.defaultExt === 'string') ? source.defaultExt : undefined;
|
|
41
|
+
|
|
42
|
+
if (mode.immutable === true) {
|
|
43
|
+
Object.freeze(dto);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return dto;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import TeqFw_Di_Dto_Resolver_Config_Namespace from './Config/Namespace.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* DTO and factory for resolver configuration records.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Runtime DTO for resolver configuration.
|
|
11
|
+
*/
|
|
12
|
+
export class DTO {
|
|
13
|
+
/** @type {TeqFw_Di_Dto_Resolver_Config_Namespace$DTO$[]} Namespace resolution rules. */
|
|
14
|
+
namespaces;
|
|
15
|
+
/** @type {string|undefined} Optional node_modules root prefix for npm modules. */
|
|
16
|
+
nodeModulesRoot;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Factory for resolver configuration DTO with optional immutability.
|
|
21
|
+
*/
|
|
22
|
+
export default class Factory {
|
|
23
|
+
/**
|
|
24
|
+
* Creates factory instance.
|
|
25
|
+
*/
|
|
26
|
+
constructor() {
|
|
27
|
+
/** @type {TeqFw_Di_Dto_Resolver_Config_Namespace} Factory for namespace DTO records. */
|
|
28
|
+
const nsFactory = new TeqFw_Di_Dto_Resolver_Config_Namespace();
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Creates normalized resolver configuration DTO.
|
|
32
|
+
*
|
|
33
|
+
* @param {Partial<TeqFw_Di_Dto_Resolver_Config$DTO>|Record<string, unknown>} [input] Source values.
|
|
34
|
+
* @param {{immutable?: boolean}|Record<string, unknown>} [options] Factory options.
|
|
35
|
+
* @returns {TeqFw_Di_Dto_Resolver_Config$DTO}
|
|
36
|
+
*/
|
|
37
|
+
this.create = function (input, options) {
|
|
38
|
+
/** @type {Partial<TeqFw_Di_Dto_Resolver_Config$DTO>|Record<string, unknown>} */
|
|
39
|
+
const source = (input && (typeof input === 'object')) ? input : {};
|
|
40
|
+
/** @type {{immutable?: boolean}|Record<string, unknown>} */
|
|
41
|
+
const mode = (options && (typeof options === 'object')) ? options : {};
|
|
42
|
+
|
|
43
|
+
/** @type {TeqFw_Di_Dto_Resolver_Config$DTO} */
|
|
44
|
+
const dto = new DTO();
|
|
45
|
+
/** @type {unknown[]} */
|
|
46
|
+
const items = Array.isArray(source.namespaces) ? source.namespaces : [];
|
|
47
|
+
dto.namespaces = items.map((item) => nsFactory.create(item, mode));
|
|
48
|
+
dto.nodeModulesRoot = (typeof source.nodeModulesRoot === 'string') ? source.nodeModulesRoot : undefined;
|
|
49
|
+
|
|
50
|
+
if (mode.immutable === true) {
|
|
51
|
+
Object.freeze(dto.namespaces);
|
|
52
|
+
Object.freeze(dto);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return dto;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Internal synchronous console logger.
|
|
5
|
+
*
|
|
6
|
+
* This module is internal infrastructure and must not be exposed as a public API.
|
|
7
|
+
*/
|
|
8
|
+
export default class TeqFw_Di_Internal_Logger {
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} scope
|
|
11
|
+
*/
|
|
12
|
+
constructor(scope = 'teqfw/di') {
|
|
13
|
+
/** @type {string} */
|
|
14
|
+
const prefix = `[${scope}]`;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {string} message
|
|
18
|
+
* @returns {void}
|
|
19
|
+
*/
|
|
20
|
+
this.log = function (message) {
|
|
21
|
+
console.debug(`${prefix} ${message}`);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {string} message
|
|
26
|
+
* @param {unknown} [error]
|
|
27
|
+
* @returns {void}
|
|
28
|
+
*/
|
|
29
|
+
this.error = function (message, error) {
|
|
30
|
+
console.error(`${prefix} ${message}`);
|
|
31
|
+
if (error instanceof Error) {
|
|
32
|
+
console.error(error.stack ?? error.message);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (error !== undefined) {
|
|
36
|
+
console.error(error);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* No-op logger for disabled logging mode.
|
|
44
|
+
*/
|
|
45
|
+
export const TeqFw_Di_Internal_Logger_Noop = Object.freeze({
|
|
46
|
+
/**
|
|
47
|
+
* @returns {void}
|
|
48
|
+
*/
|
|
49
|
+
log() {},
|
|
50
|
+
/**
|
|
51
|
+
* @returns {void}
|
|
52
|
+
*/
|
|
53
|
+
error() {},
|
|
54
|
+
});
|
package/types.d.ts
CHANGED
|
@@ -1,34 +1,26 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
|
|
3
1
|
declare global {
|
|
4
|
-
type
|
|
5
|
-
type
|
|
6
|
-
type
|
|
7
|
-
type
|
|
8
|
-
type
|
|
9
|
-
type
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
type
|
|
13
|
-
type
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
type
|
|
17
|
-
type
|
|
18
|
-
type
|
|
19
|
-
type
|
|
20
|
-
type
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
type
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
type TeqFw_Di_Container_Config = InstanceType<typeof import('./src/Container/Config.js').default>;
|
|
27
|
-
type TeqFw_Di_Container_Parser = InstanceType<typeof import('./src/Container/Parser.js').default>;
|
|
28
|
-
type TeqFw_Di_Container_PostProcessor = InstanceType<typeof import('./src/Container/PostProcessor.js').default>;
|
|
29
|
-
type TeqFw_Di_Container_PreProcessor = InstanceType<typeof import('./src/Container/PreProcessor.js').default>;
|
|
30
|
-
type TeqFw_Di_Container_Resolver = InstanceType<typeof import('./src/Container/Resolver.js').default>;
|
|
31
|
-
type TeqFw_Di_Defs = typeof import('./src/Defs.js').default;
|
|
32
|
-
type TeqFw_Di_DepId = InstanceType<typeof import('./src/DepId.js').default>;
|
|
33
|
-
type TeqFw_Di_Pre_Replace = InstanceType<typeof import('./src/Pre/Replace.js').default>;
|
|
2
|
+
type TeqFw_Di_Config_NamespaceRegistry = import("./src/Config/NamespaceRegistry.mjs").default;
|
|
3
|
+
type TeqFw_Di_Container = import("./src/Container.mjs").default;
|
|
4
|
+
type TeqFw_Di_Container_Instantiate_ExportSelector = import("./src/Container/Instantiate/ExportSelector.mjs").default;
|
|
5
|
+
type TeqFw_Di_Container_Instantiate_Instantiator = import("./src/Container/Instantiate/Instantiator.mjs").default;
|
|
6
|
+
type TeqFw_Di_Container_Lifecycle_Registry = import("./src/Container/Lifecycle/Registry.mjs").default;
|
|
7
|
+
type TeqFw_Di_Container_Resolve_GraphResolver = import("./src/Container/Resolve/GraphResolver.mjs").default;
|
|
8
|
+
type TeqFw_Di_Container_Wrapper_Executor = import("./src/Container/Wrapper/Executor.mjs").default;
|
|
9
|
+
type TeqFw_Di_Def_Parser = import("./src/Def/Parser.mjs").default;
|
|
10
|
+
type TeqFw_Di_DepId = import("./src/Dto/DepId.mjs").default;
|
|
11
|
+
type TeqFw_Di_DepId$DTO = import("./src/Dto/DepId.mjs").DTO;
|
|
12
|
+
type TeqFw_Di_Dto_DepId = import("./src/Dto/DepId.mjs").default;
|
|
13
|
+
type TeqFw_Di_Dto_DepId$DTO = import("./src/Dto/DepId.mjs").DTO;
|
|
14
|
+
type TeqFw_Di_Dto_Resolver_Config = import("./src/Dto/Resolver/Config.mjs").default;
|
|
15
|
+
type TeqFw_Di_Dto_Resolver_Config$DTO = import("./src/Dto/Resolver/Config.mjs").DTO;
|
|
16
|
+
type TeqFw_Di_Dto_Resolver_Config_Namespace = import("./src/Dto/Resolver/Config/Namespace.mjs").default;
|
|
17
|
+
type TeqFw_Di_Dto_Resolver_Config_Namespace$DTO = import("./src/Dto/Resolver/Config/Namespace.mjs").DTO;
|
|
18
|
+
type TeqFw_Di_Dto_Resolver_Config_Namespace$DTO$ = import("./src/Dto/Resolver/Config/Namespace.mjs").DTO;
|
|
19
|
+
type TeqFw_Di_Enum_Composition = typeof import("./src/Enum/Composition.mjs").default;
|
|
20
|
+
type TeqFw_Di_Enum_Life = typeof import("./src/Enum/Life.mjs").default;
|
|
21
|
+
type TeqFw_Di_Enum_Platform = typeof import("./src/Enum/Platform.mjs").default;
|
|
22
|
+
type TeqFw_Di_Internal_Logger = import("./src/Internal/Logger.mjs").default;
|
|
23
|
+
type TeqFw_Di_Resolver = import("./src/Container/Resolver.mjs").default;
|
|
34
24
|
}
|
|
25
|
+
|
|
26
|
+
export {};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Public configuration API of the DI container.
|
|
3
|
-
*
|
|
4
|
-
* This is not executable code, it is just for documentation purposes (similar to .h files in the C/C++ language).
|
|
5
|
-
* @interface
|
|
6
|
-
*/
|
|
7
|
-
export default class TeqFw_Di_Api_Container_Config {
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Returns the parser configurator.
|
|
11
|
-
*
|
|
12
|
-
* @returns {TeqFw_Di_Api_Container_Parser}
|
|
13
|
-
*/
|
|
14
|
-
parser() {
|
|
15
|
-
throw new Error('TeqFw_Di_Api_Container_Config#parser is abstract.');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Returns the pre-processor configurator.
|
|
20
|
-
*
|
|
21
|
-
* @returns {TeqFw_Di_Api_Container_PreProcessor}
|
|
22
|
-
*/
|
|
23
|
-
preProcessor() {
|
|
24
|
-
throw new Error('TeqFw_Di_Api_Container_Config#preProcessor is abstract.');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Returns the post-processor configurator.
|
|
29
|
-
*
|
|
30
|
-
* @returns {TeqFw_Di_Api_Container_PostProcessor}
|
|
31
|
-
*/
|
|
32
|
-
postProcessor() {
|
|
33
|
-
throw new Error('TeqFw_Di_Api_Container_Config#postProcessor is abstract.');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Returns the resolver configurator.
|
|
38
|
-
*
|
|
39
|
-
* @returns {TeqFw_Di_Api_Container_Resolver}
|
|
40
|
-
*/
|
|
41
|
-
resolver() {
|
|
42
|
-
throw new Error('TeqFw_Di_Api_Container_Config#resolver is abstract.');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Enables test mode.
|
|
47
|
-
*
|
|
48
|
-
* @returns {void}
|
|
49
|
-
*/
|
|
50
|
-
enableTestMode() {
|
|
51
|
-
throw new Error('TeqFw_Di_Api_Container_Config#enableTestMode is abstract.');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Registers a singleton or a Node.js module replacement in test mode.
|
|
56
|
-
*
|
|
57
|
-
* @param {string} depId
|
|
58
|
-
* @param {object} obj
|
|
59
|
-
* @returns {void}
|
|
60
|
-
*/
|
|
61
|
-
register(depId, obj) {
|
|
62
|
-
throw new Error('TeqFw_Di_Api_Container_Config#register is abstract.');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Finalizes configuration and returns a runtime container instance.
|
|
67
|
-
*
|
|
68
|
-
* @returns {TeqFw_Di_Api_Container}
|
|
69
|
-
*/
|
|
70
|
-
finalize() {
|
|
71
|
-
throw new Error('TeqFw_Di_Api_Container_Config#finalize is abstract.');
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interface for one chunk of the runtime dependency ID parser.
|
|
3
|
-
*
|
|
4
|
-
* This is not executable code, it is just for documentation purposes (similar to .h files in the C/C++ language).
|
|
5
|
-
* @interface
|
|
6
|
-
*/
|
|
7
|
-
export default class TeqFw_Di_Api_Container_Parser_Chunk {
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Returns 'true' if this chunk can parse the given dependency ID.
|
|
11
|
-
*
|
|
12
|
-
* @param {string} depId
|
|
13
|
-
* @returns {boolean}
|
|
14
|
-
*/
|
|
15
|
-
canParse(depId) {
|
|
16
|
-
throw new Error('TeqFw_Di_Api_Container_Parser_Chunk#canParse is abstract.');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Parses a string ID for a runtime dependency and returns structured data (DTO).
|
|
21
|
-
* @param {string} depId
|
|
22
|
-
* @returns {TeqFw_Di_DepId}
|
|
23
|
-
*/
|
|
24
|
-
parse(depId) {
|
|
25
|
-
throw new Error('TeqFw_Di_Api_Container_Parser_Chunk#parse is abstract.');
|
|
26
|
-
}
|
|
27
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interface for the parser of the runtime dependency ID.
|
|
3
|
-
*
|
|
4
|
-
* This is not executable code, it is just for documentation purposes (similar to .h files in the C/C++ language).
|
|
5
|
-
* @interface
|
|
6
|
-
*/
|
|
7
|
-
export default class TeqFw_Di_Api_Container_Parser {
|
|
8
|
-
/**
|
|
9
|
-
* Adds the given chunk to the parser.
|
|
10
|
-
*
|
|
11
|
-
* @param {TeqFw_Di_Api_Container_Parser_Chunk} chunk
|
|
12
|
-
*/
|
|
13
|
-
addChunk(chunk) {
|
|
14
|
-
throw new Error('TeqFw_Di_Api_Container_Parser#addChunk is abstract.');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Parse given dependency ID and return structured data as DTO.
|
|
19
|
-
* @param {string} depId
|
|
20
|
-
* @returns {TeqFw_Di_DepId}
|
|
21
|
-
*/
|
|
22
|
-
parse(depId) {
|
|
23
|
-
throw new Error('TeqFw_Di_Api_Container_Parser#parse is abstract.');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Sets the default chunk of the parser.
|
|
28
|
-
*
|
|
29
|
-
* @param {TeqFw_Di_Api_Container_Parser_Chunk} chunk
|
|
30
|
-
*/
|
|
31
|
-
setDefaultChunk(chunk) {
|
|
32
|
-
throw new Error('TeqFw_Di_Api_Container_Parser#setDefaultChunk is abstract.');
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interface for one chunk of the post-processor that modifies result.
|
|
3
|
-
*
|
|
4
|
-
* This is not executable code, it is just for documentation purposes (similar to .h files in the C/C++ language).
|
|
5
|
-
* @interface
|
|
6
|
-
*/
|
|
7
|
-
export default class TeqFw_Di_Api_Container_PostProcessor_Chunk {
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Modify result before returning to the caller.
|
|
11
|
-
* @param {*} obj - created object
|
|
12
|
-
* @param {TeqFw_Di_DepId} originalId - original `depId` DTO
|
|
13
|
-
* @param {string[]} stack - stack of parents depIds
|
|
14
|
-
* @returns {*} modified object
|
|
15
|
-
*/
|
|
16
|
-
modify(obj, originalId, stack) {}
|
|
17
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interface for the post-processor of the result object.
|
|
3
|
-
*
|
|
4
|
-
* This is not executable code, it is just for documentation purposes (similar to .h files in the C/C++ language).
|
|
5
|
-
* @interface
|
|
6
|
-
*/
|
|
7
|
-
export default class TeqFw_Di_Api_Container_PostProcessor {
|
|
8
|
-
/**
|
|
9
|
-
* Adds the given chunk to the parser.
|
|
10
|
-
*
|
|
11
|
-
* @param {TeqFw_Di_Api_Container_PostProcessor_Chunk} chunk
|
|
12
|
-
*/
|
|
13
|
-
addChunk(chunk) {
|
|
14
|
-
throw new Error('TeqFw_Di_Api_Container_PostProcessor#addChunk is abstract.');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Modifies the result of the object composition.
|
|
19
|
-
*
|
|
20
|
-
* @param {*} obj - The result object to be modified.
|
|
21
|
-
* @param {TeqFw_Di_DepId} depId - The original depID DTO.
|
|
22
|
-
* @param {string[]} stack - The stack of parent IDs.
|
|
23
|
-
* @returns {Promise<*>}
|
|
24
|
-
*/
|
|
25
|
-
modify(obj, depId, stack) {
|
|
26
|
-
throw new Error('TeqFw_Di_Api_Container_PostProcessor#modify is abstract.');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interface for one chunk of the pre-processor that modify initial `depId`.
|
|
3
|
-
*
|
|
4
|
-
* This is not executable code, it is just for documentation purposes (similar to .h files in the C/C++ language).
|
|
5
|
-
* @interface
|
|
6
|
-
*/
|
|
7
|
-
export default class TeqFw_Di_Api_Container_PreProcessor_Chunk {
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Modify runtime dependency ID before creating any object.
|
|
11
|
-
* @param {TeqFw_Di_DepId} depId - `depId` DTO after all previous pre-processing steps
|
|
12
|
-
* @param {TeqFw_Di_DepId} originalId - original `depId` DTO
|
|
13
|
-
* @param {string[]} stack - stack of parents depIds
|
|
14
|
-
* @returns {TeqFw_Di_DepId}
|
|
15
|
-
*/
|
|
16
|
-
modify(depId, originalId, stack) {
|
|
17
|
-
throw new Error('TeqFw_Di_Api_Container_PreProcessor_Chunk#modify is abstract.');
|
|
18
|
-
}
|
|
19
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interface for the pre-processor of the runtime dependency ID.
|
|
3
|
-
*
|
|
4
|
-
* This is not executable code, it is just for documentation purposes (similar to .h files in the C/C++ language).
|
|
5
|
-
* @interface
|
|
6
|
-
*/
|
|
7
|
-
export default class TeqFw_Di_Api_Container_PreProcessor {
|
|
8
|
-
/**
|
|
9
|
-
* Adds the given chunk to the parser.
|
|
10
|
-
*
|
|
11
|
-
* @param {TeqFw_Di_Api_Container_PreProcessor_Chunk} chunk
|
|
12
|
-
*/
|
|
13
|
-
addChunk(chunk) {
|
|
14
|
-
throw new Error('TeqFw_Di_Api_Container_PreProcessor#addChunk is abstract.');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Modify parsed depID and return it.
|
|
19
|
-
* @param {TeqFw_Di_DepId} depId - The depID as DTO.
|
|
20
|
-
* @param {string[]} stack - The stack of parent IDs.
|
|
21
|
-
* @returns {TeqFw_Di_DepId} -
|
|
22
|
-
*/
|
|
23
|
-
modify(depId, stack) {
|
|
24
|
-
throw new Error('TeqFw_Di_Api_Container_PreProcessor#modify is abstract.');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interface for the resolver to map a module name of the dependency ID into the path to the sources.
|
|
3
|
-
*
|
|
4
|
-
* This is not executable code, it is just for documentation purposes (similar to .h files in the C/C++ language).
|
|
5
|
-
* @interface
|
|
6
|
-
*/
|
|
7
|
-
export default class TeqFw_Di_Api_Container_Resolver {
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Convert the module name to the path of the source files .
|
|
11
|
-
* @param {string} moduleName 'Vendor_Package_Module'
|
|
12
|
-
* @returns {string} '/home/user/app/node_modules/@vendor/package/src/Module.js'
|
|
13
|
-
*/
|
|
14
|
-
resolve(moduleName) {
|
|
15
|
-
throw new Error('TeqFw_Di_Api_Container_Resolver#resolve is abstract.');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
}
|
package/src/Api/Container.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Public runtime API of the DI container.
|
|
3
|
-
*
|
|
4
|
-
* This is not executable code, it is just for documentation purposes (similar to .h files in the C/C++ language).
|
|
5
|
-
* @interface
|
|
6
|
-
*/
|
|
7
|
-
export default class TeqFw_Di_Api_Container {
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Resolves a dependency by its identifier and returns the result.
|
|
11
|
-
*
|
|
12
|
-
* @param {string} depId
|
|
13
|
-
* @param {string[]} [stack]
|
|
14
|
-
* @returns {Promise<*>}
|
|
15
|
-
*/
|
|
16
|
-
get(depId, stack) {
|
|
17
|
-
throw new Error('TeqFw_Di_Api_Container#get is abstract.');
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This function analyses specification of dependencies extracted from the text definition of the function itself.
|
|
3
|
-
*
|
|
4
|
-
* This is a local module and is used only inside the `TeqFw_Di_Container_A_Composer` space.
|
|
5
|
-
*
|
|
6
|
-
* @namespace TeqFw_Di_Container_A_Composer_A_SpecParser
|
|
7
|
-
*/
|
|
8
|
-
import Defs from '../../../../Defs.js';
|
|
9
|
-
|
|
10
|
-
// VARS
|
|
11
|
-
const FUNC = /(function)*\s*\w*\s*\(\s*\{([^}]*)}/s;
|
|
12
|
-
const CLASS = /constructor\s*\(\s*\{([^}]*)}/s;
|
|
13
|
-
|
|
14
|
-
// FUNCS
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Internal function to analyze extracted parameters.
|
|
18
|
-
*
|
|
19
|
-
* @param {string} params
|
|
20
|
-
* @returns {string[]}
|
|
21
|
-
* @private
|
|
22
|
-
*/
|
|
23
|
-
function _analyze(params) {
|
|
24
|
-
const res = [];
|
|
25
|
-
// create wrapper for arguments and collect dependencies using Proxy
|
|
26
|
-
try {
|
|
27
|
-
const fn = new Function(`{${params}}`, 'return');
|
|
28
|
-
const spec = new Proxy({}, {
|
|
29
|
-
get: (target, prop) => res.push(prop),
|
|
30
|
-
});
|
|
31
|
-
// run wrapper and return dependencies
|
|
32
|
-
fn(spec);
|
|
33
|
-
} catch (e) {
|
|
34
|
-
const msg = `Cannot analyze the deps specification:${params}\n`
|
|
35
|
-
+ '\nPlease, be sure that spec does not contain extra \')\' in a comments.'
|
|
36
|
-
+ `\n\nError: ${e}`;
|
|
37
|
-
throw new Error(msg);
|
|
38
|
-
}
|
|
39
|
-
return res;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @param {Function|Object} exp
|
|
44
|
-
* @returns {string[]}
|
|
45
|
-
*/
|
|
46
|
-
function _analyzeClass(exp) {
|
|
47
|
-
const res = [];
|
|
48
|
-
// extract arguments from constructor
|
|
49
|
-
const def = exp.toString();
|
|
50
|
-
const parts = CLASS.exec(def);
|
|
51
|
-
if (parts) {
|
|
52
|
-
res.push(..._analyze(parts[1]));
|
|
53
|
-
} // else: constructor does not have arguments
|
|
54
|
-
return res;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @param {Function|Object} exp
|
|
59
|
-
* @returns {string[]}
|
|
60
|
-
*/
|
|
61
|
-
function _analyzeFunc(exp) {
|
|
62
|
-
const res = [];
|
|
63
|
-
// extract arguments from factory function
|
|
64
|
-
const def = exp.toString();
|
|
65
|
-
const parts = FUNC.exec(def);
|
|
66
|
-
if (parts) {
|
|
67
|
-
res.push(..._analyze(parts[2]));
|
|
68
|
-
} // else: constructor does not have arguments
|
|
69
|
-
return res;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// MAIN
|
|
73
|
-
/**
|
|
74
|
-
* @param {Function|Object} exp
|
|
75
|
-
* @returns {string[]}
|
|
76
|
-
*/
|
|
77
|
-
export default function (exp) {
|
|
78
|
-
if (typeof exp === 'function') {
|
|
79
|
-
if (Defs.isClass(exp)) {
|
|
80
|
-
return _analyzeClass(exp);
|
|
81
|
-
} else {
|
|
82
|
-
return _analyzeFunc(exp);
|
|
83
|
-
}
|
|
84
|
-
} else
|
|
85
|
-
return [];
|
|
86
|
-
}
|