@teqfw/di 1.2.0 → 1.3.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/README.md CHANGED
@@ -3,30 +3,18 @@
3
3
  ![npms.io](https://img.shields.io/npm/dm/@teqfw/di)
4
4
  ![jsdelivr](https://img.shields.io/jsdelivr/npm/hm/@teqfw/di)
5
5
 
6
- > [!IMPORTANT] > **Breaking Changes in v1.0.0**
6
+ > [!WARNING]
7
+ > This branch contains the **legacy v1 line** of `@teqfw/di`.
8
+ > The code here is **manually authored** and is kept for compatibility with existing integrations and previously delivered solutions.
7
9
  >
8
- > The library has been stable for a long time and is now promoted to its first major version. To improve security, the Object Container can no longer access itself, so all configuration must occur in the Composition Root. This restriction ensures that third-party plugins cannot override or modify the container's internal functionality. Legacy versions are maintained in the `forerunner` branch, and packages like `@teqfw/core` should depend on `@teqfw/di` versions below `1.0.0`.
9
-
10
- `@teqfw/di` is a lightweight dependency injection container for standard JavaScript, enabling late binding of code
11
- objects with minimal manual configuration. It integrates smoothly in both browser and Node.js environments, supporting
12
- flexibility, modularity, and easier testing for your applications.
13
-
14
- Unlike typical object containers, `@teqfw/di` requires no manual registration of objects, instead mapping dependency IDs
15
- directly to their source paths for greater simplicity. However, for advanced use cases—such as unit testing—it is
16
- possible to explicitly register singleton objects using the `register(depId, obj)` method (available only in test mode).
17
- This allows controlled substitution of dependencies without altering the main codebase.
18
-
19
- **This library is specifically optimized for ES6 modules, ensuring top performance and compatibility. It does not
20
- support CommonJS, AMD, UMD, or other module formats.**
21
-
22
- To increase robustness, all instances created by the container are automatically **frozen** using `Object.freeze()`.
23
- This guarantees immutability of the returned objects, helping prevent accidental modifications and ensuring predictable
24
- behavior at runtime.
10
+ > Active development has moved to the main branch:
11
+ > **https://github.com/teqfw/di/tree/main**
12
+ >
13
+ > The new container generation is built through an AI-agent workflow and follows a different architecture and dependency model.
14
+ > **Backward compatibility with this v1 line is not guaranteed.**
25
15
 
26
- While this library is primarily designed for JavaScript, it is also fully compatible with TypeScript. Developers can use
27
- TypeScript to compose dependency identifiers in the same way as in JavaScript. It is important to ensure that TypeScript
28
- transpiles the source code to ES6 modules for proper functionality. With this setup, TypeScript users can effectively
29
- leverage the benefits of this library without any additional configuration.
16
+ `@teqfw/di` v1 is a lightweight dependency injection container for standard JavaScript, enabling late binding of code
17
+ objects with minimal manual configuration. It integrates in both browser and Node.js environments for modularity and testing.
30
18
 
31
19
  ---
32
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teqfw/di",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Dependency Injection container for ES6 modules that works in both browser and Node.js apps.",
5
5
  "keywords": [
6
6
  "dependency injection",
@@ -23,9 +23,6 @@
23
23
  "files": [
24
24
  "dist/",
25
25
  "src/",
26
- "CHANGELOG.md",
27
- "LICENSE",
28
- "README.md",
29
26
  "teqfw.json",
30
27
  "types.d.ts"
31
28
  ],
@@ -48,15 +45,16 @@
48
45
  },
49
46
  "scripts": {
50
47
  "rollup": "rollup -c",
51
- "eslint": "eslint './src/**/*.js'",
52
- "test": "node --test"
48
+ "eslint": "npx eslint './src/**/*.js'",
49
+ "test:unit": "node --test"
53
50
  },
54
51
  "devDependencies": {
55
52
  "@eslint/js": "^9.33.0",
56
53
  "@rollup/plugin-node-resolve": "^16.0.1",
57
54
  "@rollup/plugin-terser": "^0.4.4",
58
55
  "eslint": "^9.33.0",
59
- "rollup": "^4.47.1"
56
+ "rollup": "^4.47.1",
57
+ "typescript": "^5.9.3"
60
58
  },
61
59
  "engines": {
62
60
  "node": ">=20"
@@ -0,0 +1,73 @@
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
+ }
@@ -12,12 +12,16 @@ export default class TeqFw_Di_Api_Container_Parser_Chunk {
12
12
  * @param {string} depId
13
13
  * @returns {boolean}
14
14
  */
15
- canParse(depId) {};
15
+ canParse(depId) {
16
+ throw new Error('TeqFw_Di_Api_Container_Parser_Chunk#canParse is abstract.');
17
+ }
16
18
 
17
19
  /**
18
20
  * Parses a string ID for a runtime dependency and returns structured data (DTO).
19
21
  * @param {string} depId
20
22
  * @returns {TeqFw_Di_DepId}
21
23
  */
22
- parse(depId) {}
23
- };
24
+ parse(depId) {
25
+ throw new Error('TeqFw_Di_Api_Container_Parser_Chunk#parse is abstract.');
26
+ }
27
+ };
@@ -10,19 +10,25 @@ export default class TeqFw_Di_Api_Container_Parser {
10
10
  *
11
11
  * @param {TeqFw_Di_Api_Container_Parser_Chunk} chunk
12
12
  */
13
- addChunk(chunk) {}
13
+ addChunk(chunk) {
14
+ throw new Error('TeqFw_Di_Api_Container_Parser#addChunk is abstract.');
15
+ }
14
16
 
15
17
  /**
16
18
  * Parse given dependency ID and return structured data as DTO.
17
19
  * @param {string} depId
18
20
  * @returns {TeqFw_Di_DepId}
19
21
  */
20
- parse(depId) {}
22
+ parse(depId) {
23
+ throw new Error('TeqFw_Di_Api_Container_Parser#parse is abstract.');
24
+ }
21
25
 
22
26
  /**
23
27
  * Sets the default chunk of the parser.
24
28
  *
25
29
  * @param {TeqFw_Di_Api_Container_Parser_Chunk} chunk
26
30
  */
27
- setDefaultChunk(chunk) {}
28
- }
31
+ setDefaultChunk(chunk) {
32
+ throw new Error('TeqFw_Di_Api_Container_Parser#setDefaultChunk is abstract.');
33
+ }
34
+ }
@@ -10,16 +10,20 @@ export default class TeqFw_Di_Api_Container_PostProcessor {
10
10
  *
11
11
  * @param {TeqFw_Di_Api_Container_PostProcessor_Chunk} chunk
12
12
  */
13
- addChunk(chunk) {}
13
+ addChunk(chunk) {
14
+ throw new Error('TeqFw_Di_Api_Container_PostProcessor#addChunk is abstract.');
15
+ }
14
16
 
15
17
  /**
16
18
  * Modifies the result of the object composition.
17
19
  *
18
20
  * @param {*} obj - The result object to be modified.
19
21
  * @param {TeqFw_Di_DepId} depId - The original depID DTO.
20
- * @param {string[]} - The stack of parent IDs.
22
+ * @param {string[]} stack - The stack of parent IDs.
21
23
  * @returns {Promise<*>}
22
24
  */
23
- modify(obj, depId, stack) {}
25
+ modify(obj, depId, stack) {
26
+ throw new Error('TeqFw_Di_Api_Container_PostProcessor#modify is abstract.');
27
+ }
24
28
 
25
- }
29
+ }
@@ -13,5 +13,7 @@ export default class TeqFw_Di_Api_Container_PreProcessor_Chunk {
13
13
  * @param {string[]} stack - stack of parents depIds
14
14
  * @returns {TeqFw_Di_DepId}
15
15
  */
16
- modify(depId, originalId, stack) {}
17
- };
16
+ modify(depId, originalId, stack) {
17
+ throw new Error('TeqFw_Di_Api_Container_PreProcessor_Chunk#modify is abstract.');
18
+ }
19
+ };
@@ -10,7 +10,9 @@ export default class TeqFw_Di_Api_Container_PreProcessor {
10
10
  *
11
11
  * @param {TeqFw_Di_Api_Container_PreProcessor_Chunk} chunk
12
12
  */
13
- addChunk(chunk) {}
13
+ addChunk(chunk) {
14
+ throw new Error('TeqFw_Di_Api_Container_PreProcessor#addChunk is abstract.');
15
+ }
14
16
 
15
17
  /**
16
18
  * Modify parsed depID and return it.
@@ -18,6 +20,8 @@ export default class TeqFw_Di_Api_Container_PreProcessor {
18
20
  * @param {string[]} stack - The stack of parent IDs.
19
21
  * @returns {TeqFw_Di_DepId} -
20
22
  */
21
- modify(depId, stack) {}
23
+ modify(depId, stack) {
24
+ throw new Error('TeqFw_Di_Api_Container_PreProcessor#modify is abstract.');
25
+ }
22
26
 
23
- }
27
+ }
@@ -11,6 +11,8 @@ export default class TeqFw_Di_Api_Container_Resolver {
11
11
  * @param {string} moduleName 'Vendor_Package_Module'
12
12
  * @returns {string} '/home/user/app/node_modules/@vendor/package/src/Module.js'
13
13
  */
14
- resolve(moduleName) {}
14
+ resolve(moduleName) {
15
+ throw new Error('TeqFw_Di_Api_Container_Resolver#resolve is abstract.');
16
+ }
15
17
 
16
- }
18
+ }
@@ -0,0 +1,19 @@
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
+ }
@@ -0,0 +1,93 @@
1
+ import Container from '../Container.js';
2
+
3
+ /**
4
+ * Runtime configuration facade for the DI container.
5
+ *
6
+ * @implements {TeqFw_Di_Api_Container_Config}
7
+ */
8
+ export default class TeqFw_Di_Container_Config {
9
+ constructor() {
10
+ // VARS
11
+ const _container = new Container();
12
+ let _finalized = false;
13
+
14
+ // FUNCS
15
+ function assertNotFinalized() {
16
+ if (_finalized) throw new Error('Container configuration is finalized.');
17
+ }
18
+
19
+ // INSTANCE METHODS
20
+
21
+ /**
22
+ * Returns the parser configurator.
23
+ *
24
+ * @returns {TeqFw_Di_Api_Container_Parser}
25
+ */
26
+ this.parser = function () {
27
+ assertNotFinalized();
28
+ return _container.getParser();
29
+ };
30
+
31
+ /**
32
+ * Returns the pre-processor configurator.
33
+ *
34
+ * @returns {TeqFw_Di_Api_Container_PreProcessor}
35
+ */
36
+ this.preProcessor = function () {
37
+ assertNotFinalized();
38
+ return _container.getPreProcessor();
39
+ };
40
+
41
+ /**
42
+ * Returns the post-processor configurator.
43
+ *
44
+ * @returns {TeqFw_Di_Api_Container_PostProcessor}
45
+ */
46
+ this.postProcessor = function () {
47
+ assertNotFinalized();
48
+ return _container.getPostProcessor();
49
+ };
50
+
51
+ /**
52
+ * Returns the resolver configurator.
53
+ *
54
+ * @returns {TeqFw_Di_Api_Container_Resolver}
55
+ */
56
+ this.resolver = function () {
57
+ assertNotFinalized();
58
+ return _container.getResolver();
59
+ };
60
+
61
+ /**
62
+ * Enables test mode.
63
+ *
64
+ * @returns {void}
65
+ */
66
+ this.enableTestMode = function () {
67
+ assertNotFinalized();
68
+ _container.enableTestMode();
69
+ };
70
+
71
+ /**
72
+ * Registers a singleton or a Node.js module replacement in test mode.
73
+ *
74
+ * @param {string} depId
75
+ * @param {object} obj
76
+ * @returns {void}
77
+ */
78
+ this.register = function (depId, obj) {
79
+ assertNotFinalized();
80
+ _container.register(depId, obj);
81
+ };
82
+
83
+ /**
84
+ * Finalizes configuration and returns a runtime container instance.
85
+ *
86
+ * @returns {TeqFw_Di_Api_Container}
87
+ */
88
+ this.finalize = function () {
89
+ _finalized = true;
90
+ return _container;
91
+ };
92
+ }
93
+ }
@@ -21,7 +21,7 @@ const NSS = '_';
21
21
 
22
22
  // MAIN
23
23
  /**
24
- * @implements TeqFw_Di_Api_Container_Resolver
24
+ * @implements {TeqFw_Di_Api_Container_Resolver}
25
25
  */
26
26
  export default class TeqFw_Di_Container_Resolver {
27
27
 
package/types.d.ts CHANGED
@@ -1,24 +1,34 @@
1
- type TeqFw_Di_Container_A_Composer = InstanceType<typeof import("./src/Container/A/Composer.js").default>;
2
- type TeqFw_Di_Container_A_Composer_A_SpecParser = import("./src/Container/A/Composer/A/SpecParser.js").default;
3
- type TeqFw_Di_Container_A_Parser_Chunk_Def = InstanceType<typeof import("./src/Container/A/Parser/Chunk/Def.js").default>;
4
- type TeqFw_Di_Container_A_Parser_Chunk_V02X = InstanceType<typeof import("./src/Container/A/Parser/Chunk/V02X.js").default>;
5
- type TeqFw_Di_Container_Parser = InstanceType<typeof import("./src/Container/Parser.js").default>;
6
- type TeqFw_Di_Container_PostProcessor = InstanceType<typeof import("./src/Container/PostProcessor.js").default>;
7
- type TeqFw_Di_Container_PreProcessor = InstanceType<typeof import("./src/Container/PreProcessor.js").default>;
8
- type TeqFw_Di_Container_Resolver = InstanceType<typeof import("./src/Container/Resolver.js").default>;
1
+ export {};
9
2
 
10
3
  declare global {
11
- type TeqFw_Di_Api_Container_Parser = InstanceType<typeof import("./src/Api/Container/Parser.js").default>;
12
- type TeqFw_Di_Api_Container_Parser_Chunk = InstanceType<typeof import("./src/Api/Container/Parser/Chunk.js").default>;
13
- type TeqFw_Di_Api_Container_PostProcessor = InstanceType<typeof import("./src/Api/Container/PostProcessor.js").default>;
14
- type TeqFw_Di_Api_Container_PostProcessor_Chunk = InstanceType<typeof import("./src/Api/Container/PostProcessor/Chunk.js").default>;
15
- type TeqFw_Di_Api_Container_PreProcessor = InstanceType<typeof import("./src/Api/Container/PreProcessor.js").default>;
16
- type TeqFw_Di_Api_Container_PreProcessor_Chunk = InstanceType<typeof import("./src/Api/Container/PreProcessor/Chunk.js").default>;
17
- type TeqFw_Di_Api_Container_Resolver = InstanceType<typeof import("./src/Api/Container/Resolver.js").default>;
18
- type TeqFw_Di_Container = InstanceType<typeof import("./src/Container.js").default>;
19
- type TeqFw_Di_Defs = import("./src/Defs.js").default;
20
- type TeqFw_Di_DepId = InstanceType<typeof import("./src/DepId.js").default>;
21
- type TeqFw_Di_Pre_Replace = InstanceType<typeof import("./src/Pre/Replace.js").default>;
4
+ type TeqFw_Di_Api_Container = InstanceType<typeof import('./src/Api/Container.js').default>;
5
+ type TeqFw_Di_Api_Container_Config = InstanceType<typeof import('./src/Api/Container/Config.js').default>;
6
+ type TeqFw_Di_Api_Container_Parser = InstanceType<typeof import('./src/Api/Container/Parser.js').default>;
7
+ type TeqFw_Di_Api_Container_Parser_Chunk = InstanceType<typeof import('./src/Api/Container/Parser/Chunk.js').default>;
8
+ type TeqFw_Di_Api_Container_PostProcessor = InstanceType<typeof import('./src/Api/Container/PostProcessor.js').default>;
9
+ type TeqFw_Di_Api_Container_PostProcessor_Chunk = InstanceType<
10
+ typeof import('./src/Api/Container/PostProcessor/Chunk.js').default
11
+ >;
12
+ type TeqFw_Di_Api_Container_PreProcessor = InstanceType<typeof import('./src/Api/Container/PreProcessor.js').default>;
13
+ type TeqFw_Di_Api_Container_PreProcessor_Chunk = InstanceType<
14
+ typeof import('./src/Api/Container/PreProcessor/Chunk.js').default
15
+ >;
16
+ type TeqFw_Di_Api_Container_Resolver = InstanceType<typeof import('./src/Api/Container/Resolver.js').default>;
17
+ type TeqFw_Di_Container = InstanceType<typeof import('./src/Container.js').default>;
18
+ type TeqFw_Di_Container_A_Composer = InstanceType<typeof import('./src/Container/A/Composer.js').default>;
19
+ type TeqFw_Di_Container_A_Composer_A_SpecParser = typeof import('./src/Container/A/Composer/A/SpecParser.js').default;
20
+ type TeqFw_Di_Container_A_Parser_Chunk_Def = InstanceType<
21
+ typeof import('./src/Container/A/Parser/Chunk/Def.js').default
22
+ >;
23
+ type TeqFw_Di_Container_A_Parser_Chunk_V02X = InstanceType<
24
+ typeof import('./src/Container/A/Parser/Chunk/V02X.js').default
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>;
22
34
  }
23
-
24
- export {};
package/CHANGELOG.md DELETED
@@ -1,45 +0,0 @@
1
- # Changelog
2
-
3
- ## 1.2.0
4
-
5
- - Documented the dependency declaration model in the README and product overview.
6
- - Refined the type map rules to clarify tsserver scope and public vs internal type visibility.
7
- - Updated `types.d.ts` mappings to use `InstanceType` for class defaults and split internal aliases from globals.
8
-
9
- ## 1.1.3
10
-
11
- - Added global type declarations to `types.d.ts` to match the type map architecture rules.
12
-
13
- ## 1.1.2
14
-
15
- - Moved architecture diagrams into `ctx/img/` and updated the context map accordingly.
16
- - Clarified type map rules to require global namespace declarations for IDE type resolution.
17
-
18
- ## 1.1.1
19
-
20
- - Added missing published files (`CHANGELOG.md`, `teqfw.json`, `types.d.ts`) and declared `types.d.ts` in `package.json`.
21
-
22
- ## 1.1.0
23
-
24
- - Added ADSM cognitive context documentation and reporting structure under `ctx/`.
25
- - Added type map documentation and a `types.d.ts` namespace-to-source mapping for IDE support.
26
- - Updated `.npmignore` to ignore `output.md` artifacts.
27
-
28
- ## 1.0.2
29
-
30
- - Added ability to import the Replace preprocessor chunk via package subpath (`./pre/replace`).
31
- - Updated `.npmignore` to exclude development artifacts (`ctx/`, logs, test files) and ensure clean npm package contents.
32
- - Improved ignore patterns to prevent accidental publication of internal files.
33
-
34
- ## 1.0.1
35
-
36
- - Prepare npm package for publication.
37
- - Add distribution build outputs to package files and specify entry points.
38
-
39
- ## 1.0.0
40
-
41
- - Started changelog for version 1.0.0.
42
- - Added AGENTS.md with English-only guidelines and link to PHILOSOPHY.md.
43
- - Switched tests from Mocha to Node's built-in runner.
44
- - Updated package scripts and removed Mocha dependency.
45
- - Documented breaking changes for v1.0.0: the container can no longer access itself, configuration must occur in the Composition Root, and legacy versions live in the `forerunner` branch.