@noego/ioc 0.0.4 → 0.0.6

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 (115) hide show
  1. package/dist/cjs/framework/decorators/Component.d.ts +10 -0
  2. package/dist/cjs/framework/decorators/Component.js +25 -0
  3. package/dist/cjs/framework/decorators/Component.js.map +1 -0
  4. package/dist/cjs/framework/decorators/Inject.d.ts +7 -0
  5. package/dist/cjs/framework/decorators/Inject.js +22 -0
  6. package/dist/cjs/framework/decorators/Inject.js.map +1 -0
  7. package/dist/cjs/framework/decorators/index.d.ts +3 -0
  8. package/dist/cjs/framework/decorators/index.js +24 -0
  9. package/dist/cjs/framework/decorators/index.js.map +1 -0
  10. package/dist/cjs/framework/decorators/metadataKeys.d.ts +3 -0
  11. package/dist/cjs/framework/decorators/metadataKeys.js +8 -0
  12. package/dist/cjs/framework/decorators/metadataKeys.js.map +1 -0
  13. package/dist/cjs/framework/errors/ContainerErrors.d.ts +33 -0
  14. package/dist/cjs/framework/errors/ContainerErrors.js +52 -0
  15. package/dist/cjs/framework/errors/ContainerErrors.js.map +1 -0
  16. package/dist/cjs/framework/implementation/Container.d.ts +31 -0
  17. package/dist/cjs/framework/implementation/Container.js +448 -0
  18. package/dist/cjs/framework/implementation/Container.js.map +1 -0
  19. package/dist/cjs/framework/implementation/Container.test.d.ts +1 -0
  20. package/dist/cjs/framework/implementation/Container.test.js +184 -0
  21. package/dist/cjs/framework/implementation/Container.test.js.map +1 -0
  22. package/dist/cjs/framework/implementation/ContainerAsync.test.d.ts +1 -0
  23. package/dist/cjs/framework/implementation/ContainerAsync.test.js +178 -0
  24. package/dist/cjs/framework/implementation/ContainerAsync.test.js.map +1 -0
  25. package/dist/cjs/framework/implementation/ContainerBasic.test.d.ts +1 -0
  26. package/dist/cjs/framework/implementation/ContainerBasic.test.js +101 -0
  27. package/dist/cjs/framework/implementation/ContainerBasic.test.js.map +1 -0
  28. package/dist/cjs/framework/implementation/ContainerDecorators.test.d.ts +1 -0
  29. package/dist/cjs/framework/implementation/ContainerDecorators.test.js +517 -0
  30. package/dist/cjs/framework/implementation/ContainerDecorators.test.js.map +1 -0
  31. package/dist/cjs/framework/implementation/ContainerExtension.test.d.ts +1 -0
  32. package/dist/cjs/framework/implementation/ContainerExtension.test.js +169 -0
  33. package/dist/cjs/framework/implementation/ContainerExtension.test.js.map +1 -0
  34. package/dist/cjs/framework/implementation/ContainerLifetimes.test.d.ts +1 -0
  35. package/dist/cjs/framework/implementation/ContainerLifetimes.test.js +154 -0
  36. package/dist/cjs/framework/implementation/ContainerLifetimes.test.js.map +1 -0
  37. package/dist/cjs/framework/implementation/DecoratorSupport.d.ts +31 -0
  38. package/dist/cjs/framework/implementation/DecoratorSupport.js +96 -0
  39. package/dist/cjs/framework/implementation/DecoratorSupport.js.map +1 -0
  40. package/dist/cjs/framework/implementation/LoadAs.d.ts +5 -0
  41. package/dist/cjs/framework/implementation/LoadAs.js +10 -0
  42. package/dist/cjs/framework/implementation/LoadAs.js.map +1 -0
  43. package/dist/cjs/framework/implementation/Parameter.d.ts +33 -0
  44. package/dist/cjs/framework/implementation/Parameter.js +87 -0
  45. package/dist/cjs/framework/implementation/Parameter.js.map +1 -0
  46. package/dist/cjs/framework/implementation/Parameter.test.d.ts +1 -0
  47. package/dist/cjs/framework/implementation/Parameter.test.js +19 -0
  48. package/dist/cjs/framework/implementation/Parameter.test.js.map +1 -0
  49. package/dist/cjs/framework/implementation/SimpleDecoratorTest.test.d.ts +1 -0
  50. package/dist/cjs/framework/implementation/SimpleDecoratorTest.test.js +78 -0
  51. package/dist/cjs/framework/implementation/SimpleDecoratorTest.test.js.map +1 -0
  52. package/dist/cjs/framework/implementation/SingletonTest.test.d.ts +1 -0
  53. package/dist/cjs/framework/implementation/SingletonTest.test.js +85 -0
  54. package/dist/cjs/framework/implementation/SingletonTest.test.js.map +1 -0
  55. package/dist/cjs/framework/interface/Container.d.ts +22 -0
  56. package/dist/cjs/framework/interface/Container.js +3 -0
  57. package/dist/cjs/framework/interface/Container.js.map +1 -0
  58. package/dist/esm/framework/decorators/Component.d.ts +10 -0
  59. package/dist/esm/framework/decorators/Component.js +21 -0
  60. package/dist/esm/framework/decorators/Component.js.map +1 -0
  61. package/dist/esm/framework/decorators/Inject.d.ts +7 -0
  62. package/dist/esm/framework/decorators/Inject.js +19 -0
  63. package/dist/esm/framework/decorators/Inject.js.map +1 -0
  64. package/dist/esm/framework/decorators/index.d.ts +3 -0
  65. package/dist/esm/framework/decorators/index.js +5 -0
  66. package/dist/esm/framework/decorators/index.js.map +1 -0
  67. package/dist/esm/framework/decorators/metadataKeys.d.ts +3 -0
  68. package/dist/esm/framework/decorators/metadataKeys.js +5 -0
  69. package/dist/esm/framework/decorators/metadataKeys.js.map +1 -0
  70. package/dist/esm/framework/errors/ContainerErrors.d.ts +33 -0
  71. package/dist/esm/framework/errors/ContainerErrors.js +44 -0
  72. package/dist/esm/framework/errors/ContainerErrors.js.map +1 -0
  73. package/dist/esm/framework/implementation/Container.d.ts +31 -0
  74. package/dist/esm/framework/implementation/Container.js +432 -0
  75. package/dist/esm/framework/implementation/Container.js.map +1 -0
  76. package/dist/esm/framework/implementation/Container.test.d.ts +1 -0
  77. package/dist/esm/framework/implementation/Container.test.js +173 -0
  78. package/dist/esm/framework/implementation/Container.test.js.map +1 -0
  79. package/dist/esm/framework/implementation/ContainerAsync.test.d.ts +1 -0
  80. package/dist/esm/framework/implementation/ContainerAsync.test.js +151 -0
  81. package/dist/esm/framework/implementation/ContainerAsync.test.js.map +1 -0
  82. package/dist/esm/framework/implementation/ContainerBasic.test.d.ts +1 -0
  83. package/dist/esm/framework/implementation/ContainerBasic.test.js +90 -0
  84. package/dist/esm/framework/implementation/ContainerBasic.test.js.map +1 -0
  85. package/dist/esm/framework/implementation/ContainerDecorators.test.d.ts +1 -0
  86. package/dist/esm/framework/implementation/ContainerDecorators.test.js +498 -0
  87. package/dist/esm/framework/implementation/ContainerDecorators.test.js.map +1 -0
  88. package/dist/esm/framework/implementation/ContainerExtension.test.d.ts +1 -0
  89. package/dist/esm/framework/implementation/ContainerExtension.test.js +158 -0
  90. package/dist/esm/framework/implementation/ContainerExtension.test.js.map +1 -0
  91. package/dist/esm/framework/implementation/ContainerLifetimes.test.d.ts +1 -0
  92. package/dist/esm/framework/implementation/ContainerLifetimes.test.js +143 -0
  93. package/dist/esm/framework/implementation/ContainerLifetimes.test.js.map +1 -0
  94. package/dist/esm/framework/implementation/DecoratorSupport.d.ts +31 -0
  95. package/dist/esm/framework/implementation/DecoratorSupport.js +87 -0
  96. package/dist/esm/framework/implementation/DecoratorSupport.js.map +1 -0
  97. package/dist/esm/framework/implementation/LoadAs.d.ts +5 -0
  98. package/dist/esm/framework/implementation/LoadAs.js +7 -0
  99. package/dist/esm/framework/implementation/LoadAs.js.map +1 -0
  100. package/dist/esm/framework/implementation/Parameter.d.ts +33 -0
  101. package/dist/esm/framework/implementation/Parameter.js +49 -0
  102. package/dist/esm/framework/implementation/Parameter.js.map +1 -0
  103. package/dist/esm/framework/implementation/Parameter.test.d.ts +1 -0
  104. package/dist/esm/framework/implementation/Parameter.test.js +17 -0
  105. package/dist/esm/framework/implementation/Parameter.test.js.map +1 -0
  106. package/dist/esm/framework/implementation/SimpleDecoratorTest.test.d.ts +1 -0
  107. package/dist/esm/framework/implementation/SimpleDecoratorTest.test.js +67 -0
  108. package/dist/esm/framework/implementation/SimpleDecoratorTest.test.js.map +1 -0
  109. package/dist/esm/framework/implementation/SingletonTest.test.d.ts +1 -0
  110. package/dist/esm/framework/implementation/SingletonTest.test.js +74 -0
  111. package/dist/esm/framework/implementation/SingletonTest.test.js.map +1 -0
  112. package/dist/esm/framework/interface/Container.d.ts +22 -0
  113. package/dist/esm/framework/interface/Container.js +2 -0
  114. package/dist/esm/framework/interface/Container.js.map +1 -0
  115. package/package.json +12 -2
@@ -0,0 +1,151 @@
1
+ import { describe } from "node:test";
2
+ import { createContainer } from "./Container";
3
+ import { LoadAs } from "./LoadAs";
4
+ describe('Container Async Support', () => {
5
+ describe('Async Class Dependencies', () => {
6
+ it('should resolve class dependencies that return promises', async () => {
7
+ const container = createContainer();
8
+ class AsyncDep {
9
+ constructor() {
10
+ this.value = '';
11
+ }
12
+ async initialize() {
13
+ // Simulate async initialization
14
+ return new Promise(resolve => {
15
+ setTimeout(() => {
16
+ this.value = 'initialized';
17
+ resolve();
18
+ }, 10);
19
+ });
20
+ }
21
+ }
22
+ class AsyncService {
23
+ constructor(dep) {
24
+ this.dep = dep;
25
+ }
26
+ async getValue() {
27
+ await this.dep.initialize();
28
+ return this.dep.value;
29
+ }
30
+ }
31
+ container.registerClass(AsyncDep);
32
+ container.registerClass(AsyncService, { param: [AsyncDep] });
33
+ const service = await container.instance(AsyncService);
34
+ const value = await service.getValue();
35
+ expect(value).toBe('initialized');
36
+ });
37
+ });
38
+ describe('Resolving Async Functions', () => {
39
+ it('should resolve functions that return promises', async () => {
40
+ const container = createContainer();
41
+ const asyncFunction = async () => {
42
+ // Simulate async operation
43
+ return new Promise(resolve => {
44
+ setTimeout(() => {
45
+ resolve('async result');
46
+ }, 10);
47
+ });
48
+ };
49
+ container.registerFunction('asyncFunc', asyncFunction);
50
+ const result = await container.get('asyncFunc');
51
+ expect(await result).toBe('async result');
52
+ });
53
+ });
54
+ describe('Chain of Async Dependencies', () => {
55
+ it('should resolve a chain of async dependencies', async () => {
56
+ const container = createContainer();
57
+ // Setup a chain of async dependencies
58
+ class Level3 {
59
+ async getValue() {
60
+ return new Promise(resolve => {
61
+ setTimeout(() => {
62
+ resolve('level3');
63
+ }, 10);
64
+ });
65
+ }
66
+ }
67
+ class Level2 {
68
+ constructor(level3) {
69
+ this.level3 = level3;
70
+ }
71
+ async getValue() {
72
+ const l3Value = await this.level3.getValue();
73
+ return `level2-${l3Value}`;
74
+ }
75
+ }
76
+ class Level1 {
77
+ constructor(level2) {
78
+ this.level2 = level2;
79
+ }
80
+ async getValue() {
81
+ const l2Value = await this.level2.getValue();
82
+ return `level1-${l2Value}`;
83
+ }
84
+ }
85
+ container.registerClass(Level3);
86
+ container.registerClass(Level2, { param: [Level3] });
87
+ container.registerClass(Level1, { param: [Level2] });
88
+ const level1 = await container.instance(Level1);
89
+ const value = await level1.getValue();
90
+ expect(value).toBe('level1-level2-level3');
91
+ });
92
+ });
93
+ describe('Error Handling in Async Dependencies', () => {
94
+ it('should handle errors in async dependencies', async () => {
95
+ const container = createContainer();
96
+ class FailingDep {
97
+ async initialize() {
98
+ throw new Error('Async dependency failed');
99
+ }
100
+ }
101
+ class AsyncService {
102
+ constructor(dep) {
103
+ this.dep = dep;
104
+ }
105
+ async getValue() {
106
+ await this.dep.initialize();
107
+ return 'success';
108
+ }
109
+ }
110
+ container.registerClass(FailingDep);
111
+ container.registerClass(AsyncService, { param: [FailingDep] });
112
+ const service = await container.instance(AsyncService);
113
+ await expect(service.getValue()).rejects.toThrow('Async dependency failed');
114
+ });
115
+ });
116
+ describe('Promise Handling in Singleton Registration', () => {
117
+ it('should handle promises correctly when registering singletons', async () => {
118
+ const container = createContainer();
119
+ class AsyncSingleton {
120
+ constructor() {
121
+ this.initialized = false;
122
+ // We'll initialize this after construction
123
+ }
124
+ async initialize() {
125
+ // Simulate async initialization
126
+ return new Promise(resolve => {
127
+ setTimeout(() => {
128
+ this.initialized = true;
129
+ resolve();
130
+ }, 10);
131
+ });
132
+ }
133
+ }
134
+ // Register as singleton
135
+ container.registerClass(AsyncSingleton, { loadAs: LoadAs.Singleton });
136
+ // Get the instance multiple times concurrently
137
+ const [instance1Promise, instance2Promise] = await Promise.all([
138
+ container.instance(AsyncSingleton),
139
+ container.instance(AsyncSingleton)
140
+ ]);
141
+ const instance1 = await instance1Promise;
142
+ const instance2 = await instance2Promise;
143
+ // Initialize the singleton
144
+ await instance1.initialize();
145
+ // Both references should point to the same instance
146
+ expect(instance1).toBe(instance2);
147
+ expect(instance2.initialized).toBe(true);
148
+ });
149
+ });
150
+ });
151
+ //# sourceMappingURL=ContainerAsync.test.js.map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gB,EAAE,gBAAgB,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;gBAC3D,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC;gBAClC,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC;aACrC,CAAC,CAAC;YAEH,MAAM,SAAS,GAAG,MAAM,gBAAgB,CAAC;YACzC,MAAM,SAAS,GAAG,MAAM,gBAAgB,CAAC;YAEzC,2BAA2B;YAC3B,MAAM,SAAS,CAAC,UAAU,EAAE,CAAC;YAE7B,oDAAoD;YACpD,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAClC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,90 @@
1
+ import { describe } from "node:test";
2
+ import { createContainer } from "./Container";
3
+ import { Parameter } from "./Parameter";
4
+ describe('Container Creation and Basic Behavior', () => {
5
+ // Test creating a container with createContainer()
6
+ describe('createContainer', () => {
7
+ it('should create a container that implements both IContainerClient and IContainerSetup', () => {
8
+ const container = createContainer();
9
+ expect(container).toBeDefined();
10
+ // Verify it implements IContainerClient
11
+ expect(typeof container.instance).toBe('function');
12
+ expect(typeof container.get).toBe('function');
13
+ expect(typeof container.extend).toBe('function');
14
+ // Verify it implements IContainerSetup
15
+ expect(typeof container.registerClass).toBe('function');
16
+ expect(typeof container.registerFunction).toBe('function');
17
+ });
18
+ it('should create a container that has empty storage maps', async () => {
19
+ const container = createContainer();
20
+ // Check that internal maps are initialized and empty
21
+ expect(container._functionDefinition.size).toBe(0);
22
+ expect(container._classDefinition.size).toBe(0);
23
+ expect(container._functionStorageSingleton.size).toBe(0);
24
+ expect(container._functionStorageScoped.size).toBe(0);
25
+ expect(container._classStorageSingleton.size).toBe(0);
26
+ expect(container._classStorageScoped.size).toBe(0);
27
+ });
28
+ });
29
+ // Test resolving a non-registered class
30
+ describe('Resolving Non-Registered Classes', () => {
31
+ it('should throw an appropriate error when resolving a non-registered class', async () => {
32
+ const container = createContainer();
33
+ class NonRegistered {
34
+ }
35
+ // Attempt to resolve a class that wasn't registered
36
+ let error;
37
+ try {
38
+ await container.instance(NonRegistered);
39
+ }
40
+ catch (e) {
41
+ error = e;
42
+ }
43
+ expect(error).toBeDefined();
44
+ });
45
+ });
46
+ // Test resolving with missing parameter values
47
+ describe('Missing Parameter Values', () => {
48
+ it('should throw an appropriate error when resolving with missing parameter values', async () => {
49
+ const container = createContainer();
50
+ class User {
51
+ constructor(id) {
52
+ this.id = id;
53
+ }
54
+ }
55
+ const USER_ID = Parameter.create();
56
+ container.registerClass(User, { param: [USER_ID] });
57
+ // Attempt to resolve without providing the required parameter
58
+ let error;
59
+ try {
60
+ await container.instance(User);
61
+ }
62
+ catch (e) {
63
+ error = e;
64
+ }
65
+ expect(error).toBeDefined();
66
+ });
67
+ });
68
+ // Test resolving with extra parameter values
69
+ describe('Extra Parameter Values', () => {
70
+ it('should ignore extra parameter values', async () => {
71
+ const container = createContainer();
72
+ class User {
73
+ constructor(id) {
74
+ this.id = id;
75
+ }
76
+ }
77
+ const USER_ID = Parameter.create();
78
+ const EXTRA_PARAM = Parameter.create();
79
+ container.registerClass(User, { param: [USER_ID] });
80
+ // Provide an extra parameter that isn't used
81
+ const user = await container.instance(User, [
82
+ USER_ID.value(1),
83
+ EXTRA_PARAM.value('extra')
84
+ ]);
85
+ expect(user).toBeInstanceOf(User);
86
+ expect(user.id).toBe(1);
87
+ });
88
+ });
89
+ });
90
+ //# sourceMappingURL=ContainerBasic.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContainerBasic.test.js","sourceRoot":"","sources":["../../../../framework/implementation/ContainerBasic.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EAAa,eAAe,EAAE,MAAM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