@teqfw/di 1.3.0 → 2.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +173 -259
  3. package/dist/esm.js +1 -1
  4. package/dist/umd.js +1 -1
  5. package/package.json +16 -10
  6. package/src/AGENTS.md +177 -0
  7. package/src/Config/NamespaceRegistry.mjs +210 -0
  8. package/src/Container/Instantiate/ExportSelector.mjs +39 -0
  9. package/src/Container/Instantiate/Instantiator.mjs +143 -0
  10. package/src/Container/Lifecycle/Registry.mjs +81 -0
  11. package/src/Container/Resolve/GraphResolver.mjs +119 -0
  12. package/src/Container/Resolver.mjs +175 -0
  13. package/src/Container/Wrapper/Executor.mjs +71 -0
  14. package/src/Container.mjs +380 -0
  15. package/src/Def/Parser.mjs +146 -0
  16. package/src/Dto/DepId.mjs +131 -0
  17. package/src/Dto/Resolver/Config/Namespace.mjs +48 -0
  18. package/src/Dto/Resolver/Config.mjs +58 -0
  19. package/src/Enum/Composition.mjs +11 -0
  20. package/src/Enum/Life.mjs +11 -0
  21. package/src/Enum/Platform.mjs +12 -0
  22. package/src/Internal/Logger.mjs +54 -0
  23. package/types.d.ts +53 -26
  24. package/src/Api/Container/Config.js +0 -73
  25. package/src/Api/Container/Parser/Chunk.js +0 -27
  26. package/src/Api/Container/Parser.js +0 -34
  27. package/src/Api/Container/PostProcessor/Chunk.js +0 -17
  28. package/src/Api/Container/PostProcessor.js +0 -29
  29. package/src/Api/Container/PreProcessor/Chunk.js +0 -19
  30. package/src/Api/Container/PreProcessor.js +0 -27
  31. package/src/Api/Container/Resolver.js +0 -18
  32. package/src/Api/Container.js +0 -19
  33. package/src/Container/A/Composer/A/SpecParser.js +0 -86
  34. package/src/Container/A/Composer.js +0 -69
  35. package/src/Container/A/Parser/Chunk/Def.js +0 -69
  36. package/src/Container/A/Parser/Chunk/V02X.js +0 -66
  37. package/src/Container/Config.js +0 -93
  38. package/src/Container/Parser.js +0 -48
  39. package/src/Container/PostProcessor.js +0 -32
  40. package/src/Container/PreProcessor.js +0 -34
  41. package/src/Container/Resolver.js +0 -80
  42. package/src/Container.js +0 -187
  43. package/src/Defs.js +0 -22
  44. package/src/DepId.js +0 -52
  45. package/src/Pre/Replace.js +0 -80
  46. package/teqfw.json +0 -8
package/src/Defs.js DELETED
@@ -1,22 +0,0 @@
1
- /**
2
- * Hardcoded constants and useful utilities for the package.
3
- * @namespace TeqFw_Di_Defs
4
- */
5
- export default {
6
- CA: 'A', // composition: as-is
7
- CF: 'F', // composition: factory
8
- LI: 'I', // lifestyle: instance
9
- LS: 'S', // lifestyle: singleton
10
-
11
- /**
12
- * Return 'true' if function is a class definition.
13
- * See: https://stackoverflow.com/a/29094018/4073821
14
- *
15
- * @param {function} fn
16
- * @returns {boolean}
17
- */
18
- isClass(fn) {
19
- const proto = Object.getOwnPropertyDescriptor(fn, 'prototype');
20
- return proto && !proto.writable;
21
- },
22
- };
package/src/DepId.js DELETED
@@ -1,52 +0,0 @@
1
- /**
2
- * DTO representing a dependency identifier in the container.
3
- * @namespace TeqFw_Di_DepId
4
- */
5
- export default class TeqFw_Di_DepId {
6
- /**
7
- * The name of an export from the module.
8
- * Example: 'default', 'logger', 'DbClient'.
9
- * @type {string}
10
- */
11
- exportName;
12
- /**
13
- * Defines how the export should be used:
14
- * - 'F' (Factory): The export is a factory function, call it to get an instance.
15
- * - 'A' (As-Is): The export is returned as-is, without calling.
16
- * Example: 'F', 'A'.
17
- * @type {string}
18
- */
19
- composition;
20
- /**
21
- * Defines if the dependency is a Node.js module.
22
- * @type {boolean}
23
- */
24
- isNodeModule;
25
- /**
26
- * Defines the lifecycle of the resolved dependency:
27
- * - 'S' (Singleton): A single instance is created and reused.
28
- * - 'I' (Instance): A new instance is created on each request.
29
- * Example: 'S', 'I'.
30
- * @type {string}
31
- */
32
- life;
33
- /**
34
- * ES6 module identifier, which can be transformed into a file path.
35
- * This value is processed by the Resolver to determine the module's location.
36
- * Example: 'TeqFw_Core_Shared_Api_Logger'.
37
- * @type {string}
38
- */
39
- moduleName;
40
- /**
41
- * The original identifier string provided to the container.
42
- * This is the unprocessed dependency key.
43
- * Example: 'TeqFw_Core_Shared_Api_Logger$$'.
44
- * @type {string}
45
- */
46
- origin;
47
- /**
48
- * List of wrappers to decorate the result.
49
- * @type {string[]}
50
- */
51
- wrappers = [];
52
- }
@@ -1,80 +0,0 @@
1
- /**
2
- * Pre-processor chunk that replaces module addresses during dependency resolution.
3
- *
4
- * This chunk allows dynamically overriding the module namespace used to resolve source code
5
- * for a given dependency ID. Only the `moduleName` field of the `depId` is modified.
6
- * All other metadata (such as lifestyle, export type, etc.) remains unchanged.
7
- *
8
- * This mechanism enables redirecting from one module implementation to another
9
- * without changing aliases or component registration.
10
- *
11
- * Example:
12
- * Replace module path 'Fl32_Cms_Back_Api_Adapter' with 'App_Cms_Adapter_Custom',
13
- * while keeping the lifestyle and export configuration intact.
14
- *
15
- * @implements {TeqFw_Di_Api_Container_PreProcessor_Chunk}
16
- */
17
- export default class TeqFw_Di_Pre_Replace {
18
-
19
- constructor() {
20
- // VARS
21
-
22
- /**
23
- * Mapping of source module namespaces to their replacements.
24
- * Keys and values are strings without export/lifestyle suffixes.
25
- *
26
- * Example:
27
- * {
28
- * 'Fl32_Cms_Back_Api_Adapter': 'App_Cms_Adapter_Custom'
29
- * }
30
- *
31
- * This means: when resolving a module with `moduleName === 'Fl32_Cms_Back_Api_Adapter'`,
32
- * use source code from `'App_Cms_Adapter_Custom'` instead.
33
- *
34
- * @type {Object<string, string>}
35
- */
36
- const map = {};
37
-
38
- // INSTANCE METHODS
39
-
40
- /**
41
- * Register a single module address replacement.
42
- *
43
- * @param {string} orig - Original module namespace (e.g. 'X_Y_Z')
44
- * @param {string} alter - Replacement module namespace (e.g. 'A_B_C')
45
- */
46
- this.add = function (orig, alter) {
47
- map[orig] = alter;
48
- };
49
-
50
- /* eslint-disable no-unused-vars */
51
- /**
52
- * Replace the `moduleName` of the dependency ID if a mapping exists.
53
- *
54
- * This function does not alter any other part of the `depId` (e.g. lifestyle, export kind).
55
- *
56
- * @param {TeqFw_Di_DepId} depId - Dependency ID after previous transformations.
57
- * @param {TeqFw_Di_DepId} originalId - Original dependency ID before any processing.
58
- * @param {string[]} stack - Stack of parent dependency IDs (for trace/debug).
59
- * @returns {TeqFw_Di_DepId} - Transformed `depId` with updated `moduleName` if replaced.
60
- */
61
- this.modify = function (depId, originalId, stack) {
62
- let module = depId.moduleName;
63
- const seen = new Set();
64
-
65
- while (map[module] && !seen.has(module)) {
66
- seen.add(module);
67
- module = map[module];
68
- }
69
-
70
- if (module !== depId.moduleName) {
71
- return {
72
- ...depId,
73
- moduleName: module,
74
- };
75
- }
76
-
77
- return depId;
78
- };
79
- }
80
- }
package/teqfw.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "@teqfw/di": {
3
- "autoload": {
4
- "ns": "TeqFw_Di_",
5
- "path": "./src"
6
- }
7
- }
8
- }