@rolster/invertly 1.0.8 → 1.1.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 (39) hide show
  1. package/dist/cjs/index.js +69 -81
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/es/index.js +69 -81
  4. package/dist/es/index.js.map +1 -1
  5. package/dist/esm/decorators/inject.decorator.d.ts +3 -3
  6. package/dist/esm/decorators/inject.decorator.js +10 -11
  7. package/dist/esm/decorators/inject.decorator.js.map +1 -1
  8. package/dist/esm/decorators/injectable.decorator.d.ts +5 -5
  9. package/dist/esm/decorators/injectable.decorator.js +7 -9
  10. package/dist/esm/decorators/injectable.decorator.js.map +1 -1
  11. package/dist/esm/factories/container.factory.d.ts +4 -4
  12. package/dist/esm/factories/container.factory.js +13 -13
  13. package/dist/esm/factories/container.factory.js.map +1 -1
  14. package/dist/esm/factories/index.d.ts +8 -23
  15. package/dist/esm/factories/index.js +25 -34
  16. package/dist/esm/factories/index.js.map +1 -1
  17. package/dist/esm/index.d.ts +2 -2
  18. package/dist/esm/index.js +1 -1
  19. package/dist/esm/index.js.map +1 -1
  20. package/dist/esm/stores/context.store.d.ts +2 -2
  21. package/dist/esm/stores/context.store.js +2 -2
  22. package/dist/esm/stores/context.store.js.map +1 -1
  23. package/dist/esm/stores/inject.store.d.ts +3 -3
  24. package/dist/esm/stores/inject.store.js +5 -5
  25. package/dist/esm/stores/inject.store.js.map +1 -1
  26. package/dist/esm/stores/injectable.store.d.ts +4 -4
  27. package/dist/esm/stores/injectable.store.js +3 -3
  28. package/dist/esm/stores/injectable.store.js.map +1 -1
  29. package/dist/esm/stores/locator.store.d.ts +5 -5
  30. package/dist/esm/stores/locator.store.js +3 -3
  31. package/dist/esm/stores/locator.store.js.map +1 -1
  32. package/dist/esm/stores/scope.store.d.ts +2 -2
  33. package/dist/esm/stores/scope.store.js +1 -1
  34. package/dist/esm/stores/scope.store.js.map +1 -1
  35. package/dist/esm/types/context.type.d.ts +2 -2
  36. package/dist/esm/types/inject.type.d.ts +2 -2
  37. package/dist/esm/types/injectable.type.d.ts +3 -3
  38. package/dist/esm/types/locator.type.d.ts +1 -1
  39. package/package.json +2 -2
package/dist/cjs/index.js CHANGED
@@ -5,8 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  require('reflect-metadata');
6
6
 
7
7
  class Context extends Map {
8
- fetch(key) {
9
- return this.has(key) ? this.get(key) : undefined;
8
+ request(key) {
9
+ return this.get(key);
10
10
  }
11
11
  }
12
12
 
@@ -14,12 +14,12 @@ class InjectStore {
14
14
  constructor() {
15
15
  this.collection = new Map();
16
16
  }
17
- push(config) {
18
- const { parent, index } = config;
19
- const injects = this.fetch(parent);
20
- injects[index] = config;
17
+ push(options) {
18
+ const { parent, index } = options;
19
+ const injects = this.request(parent);
20
+ injects[index] = options;
21
21
  }
22
- fetch(token) {
22
+ request(token) {
23
23
  const current = this.collection.get(token);
24
24
  if (current) {
25
25
  return current;
@@ -34,10 +34,10 @@ class InjectableStore {
34
34
  constructor() {
35
35
  this.collection = new Map();
36
36
  }
37
- push(config) {
38
- this.collection.set(config.token, config);
37
+ push(options) {
38
+ this.collection.set(options.token, options);
39
39
  }
40
- fetch(token) {
40
+ request(token) {
41
41
  return this.collection.get(token);
42
42
  }
43
43
  }
@@ -60,7 +60,7 @@ class LocatorStore {
60
60
  this.collection.set(reference, { token, useClass: token });
61
61
  }
62
62
  }
63
- fetch(token) {
63
+ request(token) {
64
64
  return this.collection.get(token);
65
65
  }
66
66
  }
@@ -71,8 +71,8 @@ function saveInLocator(dependencies) {
71
71
  function pushInLocator(reference, token) {
72
72
  locatorStore.push(reference, token);
73
73
  }
74
- function fetchInLocator(token) {
75
- return locatorStore.fetch(token);
74
+ function requestInLocator(token) {
75
+ return locatorStore.request(token);
76
76
  }
77
77
 
78
78
  class ScopeStore {
@@ -82,7 +82,7 @@ class ScopeStore {
82
82
  push(token, value) {
83
83
  this.collection.set(token, value);
84
84
  }
85
- fetch(token) {
85
+ request(token) {
86
86
  return this.collection.get(token);
87
87
  }
88
88
  }
@@ -101,7 +101,7 @@ class Dependency {
101
101
  this.scope = new ScopeStore();
102
102
  }
103
103
  build(injectable) {
104
- const config = this.warehouse.injectables.fetch(injectable);
104
+ const config = this.warehouse.injectables.request(injectable);
105
105
  if (!config) {
106
106
  throw Error(`Class ${injectable.toString()} is not found in the collection`);
107
107
  }
@@ -120,7 +120,7 @@ class Dependency {
120
120
  return Reflect.getMetadata('design:paramtypes', reference);
121
121
  }
122
122
  createFromScope({ token, scope }) {
123
- const instance = scope.fetch(token);
123
+ const instance = scope.request(token);
124
124
  if (instance) {
125
125
  return instance;
126
126
  }
@@ -145,7 +145,7 @@ class Dependency {
145
145
  }
146
146
  createFromDecorator(inject) {
147
147
  const { token, scopeable, singleton } = inject;
148
- const locator = fetchInLocator(token);
148
+ const locator = requestInLocator(token);
149
149
  if (locator) {
150
150
  const { useClass: token } = locator;
151
151
  return this.createInstance({ token, scopeable, singleton });
@@ -154,13 +154,13 @@ class Dependency {
154
154
  }
155
155
  createReflectArgs({ tokens, token }) {
156
156
  const { warehouse, context } = this;
157
- const injects = warehouse.injects.fetch(token);
157
+ const injects = warehouse.injects.request(token);
158
158
  return tokens.map((token, index) => {
159
159
  const inject = injects[index];
160
160
  if (inject) {
161
161
  return this.createFromDecorator(inject);
162
162
  }
163
- const locator = fetchInLocator(token);
163
+ const locator = requestInLocator(token);
164
164
  if (locator) {
165
165
  const { useClass: token, scopeable, singleton } = locator;
166
166
  return this.createInstance({ token, scopeable, singleton });
@@ -172,7 +172,7 @@ class Dependency {
172
172
  });
173
173
  }
174
174
  createTokenArgs(token) {
175
- const injects = this.warehouse.injects.fetch(token);
175
+ const injects = this.warehouse.injects.request(token);
176
176
  return injects.reduce((objects, { index, scopeable, singleton, token }) => {
177
177
  objects[index] = this.createInstance({ token, scopeable, singleton });
178
178
  return objects;
@@ -183,89 +183,77 @@ class Container {
183
183
  constructor() {
184
184
  this.warehouse = new Warehouse();
185
185
  }
186
- registerInjectable(config) {
187
- this.warehouse.injectables.push(config);
186
+ registerInjectable(options) {
187
+ this.warehouse.injectables.push(options);
188
188
  }
189
- registerInject(config) {
190
- this.warehouse.injects.push(config);
189
+ registerInject(options) {
190
+ this.warehouse.injects.push(options);
191
191
  }
192
- createInjectable(config) {
193
- const { token, context } = config;
192
+ createInjectable(options) {
193
+ const { token, context } = options;
194
194
  const { warehouse } = this;
195
195
  const dependency = new Dependency({ warehouse, context });
196
196
  return dependency.build(token);
197
197
  }
198
198
  }
199
199
 
200
- const rootContainer = new Container();
201
- const createFromInvertly = (options) => {
202
- const { config, container } = options;
203
- return (container || rootContainer).createInjectable(config);
204
- };
205
- const invertly = (token, { container } = {}) => {
206
- return createFromInvertly({ config: { token }, container });
207
- };
208
- const registerInjectable = (options) => {
209
- const { config, container } = options;
210
- (container || rootContainer).registerInjectable(config);
211
- };
212
- const registerInject = (options) => {
213
- const { config, container } = options;
214
- (container || rootContainer).registerInject(config);
215
- };
216
- const registerDependency = (token, options) => {
200
+ const invertlyContainer = new Container();
201
+ function createFromInvertly(options, container) {
202
+ return (container || invertlyContainer).createInjectable(options);
203
+ }
204
+ function invertly(token, container) {
205
+ return createFromInvertly({ token }, container);
206
+ }
207
+ function registerInjectable(options, container) {
208
+ (container || invertlyContainer).registerInjectable(options);
209
+ }
210
+ function registerInject(options, container) {
211
+ (container || invertlyContainer).registerInject(options);
212
+ }
213
+ function registerDependency(token, options) {
217
214
  const { container, injects, scopeable, singleton } = options;
218
215
  registerInjectable({
219
- config: {
220
- token,
221
- scopeable: scopeable || false,
222
- singleton: singleton || false
223
- },
224
- container
225
- });
216
+ token,
217
+ scopeable: scopeable || false,
218
+ singleton: singleton || false
219
+ }, container);
226
220
  injects?.forEach((inject, indexParent) => {
227
221
  const { index, scopeable: childrenScopeable, singleton: childrenSingleton, token: childrenToken } = inject;
228
222
  registerInject({
229
- config: {
230
- index: index || indexParent,
231
- parent: token,
232
- scopeable: childrenScopeable || scopeable || false,
233
- singleton: childrenSingleton || singleton || false,
234
- token: childrenToken
235
- },
236
- container
237
- });
223
+ index: index || indexParent,
224
+ parent: token,
225
+ scopeable: childrenScopeable || scopeable || false,
226
+ singleton: childrenSingleton || singleton || false,
227
+ token: childrenToken
228
+ }, container);
238
229
  });
239
- };
230
+ }
240
231
 
241
- const createInject = ({ scopeable, singleton, token }) => {
232
+ function createInject(inject) {
233
+ const { scopeable, singleton, token } = inject;
242
234
  return (parent, _, index) => {
243
- registerInject({
244
- config: { index, parent, scopeable, singleton, token }
245
- });
235
+ registerInject({ index, parent, scopeable, singleton, token });
246
236
  };
247
- };
248
- const Singleton = (token) => {
237
+ }
238
+ function Singleton(token) {
249
239
  return createInject({ token, scopeable: false, singleton: true });
250
- };
251
- const Scope = (token) => {
240
+ }
241
+ function Scope(token) {
252
242
  return createInject({ token, scopeable: true, singleton: false });
253
- };
254
- const Factory = (token) => {
243
+ }
244
+ function Factory(token) {
255
245
  return createInject({ token, scopeable: false, singleton: false });
256
- };
246
+ }
257
247
 
258
- const DEFAULT_CONFIG = {
259
- scopeable: false,
260
- singleton: false
261
- };
262
- const Injectable = (config) => {
263
- const finalConfig = { ...DEFAULT_CONFIG, ...config };
264
- const { scopeable, singleton } = finalConfig;
248
+ function Injectable(options) {
265
249
  return (token) => {
266
- registerInjectable({ config: { scopeable, singleton, token } });
250
+ registerInjectable({
251
+ scopeable: !!options?.scopeable,
252
+ singleton: !!options?.singleton,
253
+ token
254
+ });
267
255
  };
268
- };
256
+ }
269
257
 
270
258
  exports.Container = Container;
271
259
  exports.Context = Context;
@@ -274,11 +262,11 @@ exports.Injectable = Injectable;
274
262
  exports.Scope = Scope;
275
263
  exports.Singleton = Singleton;
276
264
  exports["default"] = createFromInvertly;
277
- exports.fetchInLocator = fetchInLocator;
278
265
  exports.invertly = invertly;
279
266
  exports.pushInLocator = pushInLocator;
280
267
  exports.registerDependency = registerDependency;
281
268
  exports.registerInject = registerInject;
282
269
  exports.registerInjectable = registerInjectable;
270
+ exports.requestInLocator = requestInLocator;
283
271
  exports.saveInLocator = saveInLocator;
284
272
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../esm/stores/context.store.js","../esm/stores/inject.store.js","../esm/stores/injectable.store.js","../esm/stores/locator.store.js","../esm/stores/scope.store.js","../esm/factories/container.factory.js","../esm/factories/index.js","../esm/decorators/inject.decorator.js","../esm/decorators/injectable.decorator.js"],"sourcesContent":["export class Context extends Map {\r\n fetch(key) {\r\n return this.has(key) ? this.get(key) : undefined;\r\n }\r\n}\r\n//# sourceMappingURL=context.store.js.map","export class InjectStore {\r\n constructor() {\r\n this.collection = new Map();\r\n }\r\n push(config) {\r\n const { parent, index } = config;\r\n const injects = this.fetch(parent);\r\n injects[index] = config;\r\n }\r\n fetch(token) {\r\n const current = this.collection.get(token);\r\n if (current) {\r\n return current;\r\n }\r\n const injects = [];\r\n this.collection.set(token, injects);\r\n return injects;\r\n }\r\n}\r\n//# sourceMappingURL=inject.store.js.map","export class InjectableStore {\r\n constructor() {\r\n this.collection = new Map();\r\n }\r\n push(config) {\r\n this.collection.set(config.token, config);\r\n }\r\n fetch(token) {\r\n return this.collection.get(token);\r\n }\r\n}\r\n//# sourceMappingURL=injectable.store.js.map","class LocatorStore {\r\n constructor() {\r\n this.collection = new Map();\r\n }\r\n save(dependencies) {\r\n dependencies.forEach((config) => {\r\n this.collection.set(config.token, config);\r\n });\r\n }\r\n push(reference, token) {\r\n if (typeof reference !== 'string' && typeof reference !== 'symbol') {\r\n const { token, useClass } = reference;\r\n this.collection.set(token, { token, useClass });\r\n }\r\n else if (token) {\r\n this.collection.set(reference, { token, useClass: token });\r\n }\r\n }\r\n fetch(token) {\r\n return this.collection.get(token);\r\n }\r\n}\r\nconst locatorStore = new LocatorStore();\r\nexport function saveInLocator(dependencies) {\r\n locatorStore.save(dependencies);\r\n}\r\nexport function pushInLocator(reference, token) {\r\n locatorStore.push(reference, token);\r\n}\r\nexport function fetchInLocator(token) {\r\n return locatorStore.fetch(token);\r\n}\r\n//# sourceMappingURL=locator.store.js.map","export class ScopeStore {\r\n constructor() {\r\n this.collection = new Map();\r\n }\r\n push(token, value) {\r\n this.collection.set(token, value);\r\n }\r\n fetch(token) {\r\n return this.collection.get(token);\r\n }\r\n}\r\n//# sourceMappingURL=scope.store.js.map","import 'reflect-metadata';\r\nimport { Context, InjectStore, InjectableStore, ScopeStore, fetchInLocator } from '../stores';\r\nclass Warehouse {\r\n constructor() {\r\n this.scope = new ScopeStore();\r\n this.injectables = new InjectableStore();\r\n this.injects = new InjectStore();\r\n }\r\n}\r\nclass Dependency {\r\n constructor({ warehouse, context }) {\r\n this.warehouse = warehouse;\r\n this.context = context;\r\n this.scope = new ScopeStore();\r\n }\r\n build(injectable) {\r\n const config = this.warehouse.injectables.fetch(injectable);\r\n if (!config) {\r\n throw Error(`Class ${injectable.toString()} is not found in the collection`);\r\n }\r\n const { scopeable, singleton, token } = config;\r\n return this.createInstance({ token, scopeable, singleton });\r\n }\r\n createObject(token) {\r\n const Constructor = token;\r\n const tokens = this.reflectTokens(Constructor);\r\n const params = tokens\r\n ? this.createReflectArgs({ token, tokens })\r\n : this.createTokenArgs(token);\r\n return new Constructor(...params);\r\n }\r\n reflectTokens(reference) {\r\n return Reflect.getMetadata('design:paramtypes', reference);\r\n }\r\n createFromScope({ token, scope }) {\r\n const instance = scope.fetch(token);\r\n if (instance) {\r\n return instance;\r\n }\r\n const object = this.createObject(token);\r\n scope.push(token, object);\r\n return object;\r\n }\r\n createFromContainer(token) {\r\n const { warehouse: { scope } } = this;\r\n return this.createFromScope({ token, scope });\r\n }\r\n createInstance(props) {\r\n const { token, scopeable, singleton } = props;\r\n const { scope } = this;\r\n if (singleton) {\r\n return this.createFromContainer(token);\r\n }\r\n if (scopeable) {\r\n return this.createFromScope({ token, scope });\r\n }\r\n return this.createObject(token);\r\n }\r\n createFromDecorator(inject) {\r\n const { token, scopeable, singleton } = inject;\r\n const locator = fetchInLocator(token);\r\n if (locator) {\r\n const { useClass: token } = locator;\r\n return this.createInstance({ token, scopeable, singleton });\r\n }\r\n return this.createInstance({ token, scopeable, singleton });\r\n }\r\n createReflectArgs({ tokens, token }) {\r\n const { warehouse, context } = this;\r\n const injects = warehouse.injects.fetch(token);\r\n return tokens.map((token, index) => {\r\n const inject = injects[index];\r\n if (inject) {\r\n return this.createFromDecorator(inject);\r\n }\r\n const locator = fetchInLocator(token);\r\n if (locator) {\r\n const { useClass: token, scopeable, singleton } = locator;\r\n return this.createInstance({ token, scopeable, singleton });\r\n }\r\n if (token === Context) {\r\n return context;\r\n }\r\n return this.createObject(token);\r\n });\r\n }\r\n createTokenArgs(token) {\r\n const injects = this.warehouse.injects.fetch(token);\r\n return injects.reduce((objects, { index, scopeable, singleton, token }) => {\r\n objects[index] = this.createInstance({ token, scopeable, singleton });\r\n return objects;\r\n }, []);\r\n }\r\n}\r\nexport class Container {\r\n constructor() {\r\n this.warehouse = new Warehouse();\r\n }\r\n registerInjectable(config) {\r\n this.warehouse.injectables.push(config);\r\n }\r\n registerInject(config) {\r\n this.warehouse.injects.push(config);\r\n }\r\n createInjectable(config) {\r\n const { token, context } = config;\r\n const { warehouse } = this;\r\n const dependency = new Dependency({ warehouse, context });\r\n return dependency.build(token);\r\n }\r\n}\r\n//# sourceMappingURL=container.factory.js.map","import { Container } from './container.factory';\r\nconst rootContainer = new Container();\r\nconst createFromInvertly = (options) => {\r\n const { config, container } = options;\r\n return (container || rootContainer).createInjectable(config);\r\n};\r\nexport const invertly = (token, { container } = {}) => {\r\n return createFromInvertly({ config: { token }, container });\r\n};\r\nexport const registerInjectable = (options) => {\r\n const { config, container } = options;\r\n (container || rootContainer).registerInjectable(config);\r\n};\r\nexport const registerInject = (options) => {\r\n const { config, container } = options;\r\n (container || rootContainer).registerInject(config);\r\n};\r\nexport const registerDependency = (token, options) => {\r\n const { container, injects, scopeable, singleton } = options;\r\n registerInjectable({\r\n config: {\r\n token,\r\n scopeable: scopeable || false,\r\n singleton: singleton || false\r\n },\r\n container\r\n });\r\n injects?.forEach((inject, indexParent) => {\r\n const { index, scopeable: childrenScopeable, singleton: childrenSingleton, token: childrenToken } = inject;\r\n registerInject({\r\n config: {\r\n index: index || indexParent,\r\n parent: token,\r\n scopeable: childrenScopeable || scopeable || false,\r\n singleton: childrenSingleton || singleton || false,\r\n token: childrenToken\r\n },\r\n container\r\n });\r\n });\r\n};\r\nexport { Container } from './container.factory';\r\nexport default createFromInvertly;\r\n//# sourceMappingURL=index.js.map","import { registerInject } from '../factories';\r\nconst createInject = ({ scopeable, singleton, token }) => {\r\n return (parent, _, index) => {\r\n registerInject({\r\n config: { index, parent, scopeable, singleton, token }\r\n });\r\n };\r\n};\r\nexport const Singleton = (token) => {\r\n return createInject({ token, scopeable: false, singleton: true });\r\n};\r\nexport const Scope = (token) => {\r\n return createInject({ token, scopeable: true, singleton: false });\r\n};\r\nexport const Factory = (token) => {\r\n return createInject({ token, scopeable: false, singleton: false });\r\n};\r\n//# sourceMappingURL=inject.decorator.js.map","import { registerInjectable } from '../factories';\r\nconst DEFAULT_CONFIG = {\r\n scopeable: false,\r\n singleton: false\r\n};\r\nexport const Injectable = (config) => {\r\n const finalConfig = { ...DEFAULT_CONFIG, ...config };\r\n const { scopeable, singleton } = finalConfig;\r\n return (token) => {\r\n registerInjectable({ config: { scopeable, singleton, token } });\r\n };\r\n};\r\n//# sourceMappingURL=injectable.decorator.js.map"],"names":[],"mappings":";;;;;;AAAO,MAAM,OAAO,SAAS,GAAG,CAAC;AACjC,IAAI,KAAK,CAAC,GAAG,EAAE;AACf,QAAQ,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;AACzD,KAAK;AACL;;ACJO,MAAM,WAAW,CAAC;AACzB,IAAI,WAAW,GAAG;AAClB,QAAQ,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EA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AC;AACvB,YAAY,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE;AAClE,SAAS,CAAC,CAAC;AACX,KAAK,CAAC;AACN,CAAC,CAAC;AACU,MAAC,SAAS,GAAG,CAAC,KAAK,KAAK;AACpC,IAAI,OAAO,YAAY,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AACtE,EAAE;AACU,MAAC,KAAK,GAAG,CAAC,KAAK,KAAK;AAChC,IAAI,OAAO,YAAY,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;AACtE,EAAE;AACU,MAAC,OAAO,GAAG,CAAC,KAAK,KAAK;AAClC,IAAI,OAAO,YAAY,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;AACvE;;ACfA,MAAM,cAAc,GAAG;AACvB,IAAI,SAAS,EAAE,KAAK;AACpB,IAAI,SAAS,EAAE,KAAK;AACpB,CAAC,CAAC;AACU,MAAC,UAAU,GAAG,CAAC,MAAM,KAAK;AACtC,IAAI,MAAM,WAAW,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,CAAC;AACzD,IAAI,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,WAAW,CAAC;AACjD,IAAI,OAAO,CAAC,KAAK,KAAK;AACtB,QAAQ,kBAAkB,CAAC,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;AACxE,KAAK,CAAC;AACN;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../esm/stores/context.store.js","../esm/stores/inject.store.js","../esm/stores/injectable.store.js","../esm/stores/locator.store.js","../esm/stores/scope.store.js","../esm/factories/container.factory.js","../esm/factories/index.js","../esm/decorators/inject.decorator.js","../esm/decorators/injectable.decorator.js"],"sourcesContent":["export class Context extends Map {\r\n request(key) {\r\n return this.get(key);\r\n }\r\n}\r\n//# sourceMappingURL=context.store.js.map","export class InjectStore {\r\n constructor() {\r\n this.collection = new Map();\r\n }\r\n push(options) {\r\n const { parent, index } = options;\r\n const injects = this.request(parent);\r\n injects[index] = options;\r\n }\r\n request(token) {\r\n const current = this.collection.get(token);\r\n if (current) {\r\n return current;\r\n }\r\n const injects = [];\r\n this.collection.set(token, injects);\r\n return injects;\r\n }\r\n}\r\n//# sourceMappingURL=inject.store.js.map","export class InjectableStore {\r\n constructor() {\r\n this.collection = new Map();\r\n }\r\n push(options) {\r\n this.collection.set(options.token, options);\r\n }\r\n request(token) {\r\n return this.collection.get(token);\r\n }\r\n}\r\n//# sourceMappingURL=injectable.store.js.map","class LocatorStore {\r\n constructor() {\r\n this.collection = new Map();\r\n }\r\n save(dependencies) {\r\n dependencies.forEach((config) => {\r\n this.collection.set(config.token, config);\r\n });\r\n }\r\n push(reference, token) {\r\n if (typeof reference !== 'string' && typeof reference !== 'symbol') {\r\n const { token, useClass } = reference;\r\n this.collection.set(token, { token, useClass });\r\n }\r\n else if (token) {\r\n this.collection.set(reference, { token, useClass: token });\r\n }\r\n }\r\n request(token) {\r\n return this.collection.get(token);\r\n }\r\n}\r\nconst locatorStore = new LocatorStore();\r\nexport function saveInLocator(dependencies) {\r\n locatorStore.save(dependencies);\r\n}\r\nexport function pushInLocator(reference, token) {\r\n locatorStore.push(reference, token);\r\n}\r\nexport function requestInLocator(token) {\r\n return locatorStore.request(token);\r\n}\r\n//# sourceMappingURL=locator.store.js.map","export class ScopeStore {\r\n constructor() {\r\n this.collection = new Map();\r\n }\r\n push(token, value) {\r\n this.collection.set(token, value);\r\n }\r\n request(token) {\r\n return this.collection.get(token);\r\n }\r\n}\r\n//# sourceMappingURL=scope.store.js.map","import 'reflect-metadata';\r\nimport { Context, InjectStore, InjectableStore, ScopeStore, requestInLocator } from '../stores';\r\nclass Warehouse {\r\n constructor() {\r\n this.scope = new ScopeStore();\r\n this.injectables = new InjectableStore();\r\n this.injects = new InjectStore();\r\n }\r\n}\r\nclass Dependency {\r\n constructor({ warehouse, context }) {\r\n this.warehouse = warehouse;\r\n this.context = context;\r\n this.scope = new ScopeStore();\r\n }\r\n build(injectable) {\r\n const config = this.warehouse.injectables.request(injectable);\r\n if (!config) {\r\n throw Error(`Class ${injectable.toString()} is not found in the collection`);\r\n }\r\n const { scopeable, singleton, token } = config;\r\n return this.createInstance({ token, scopeable, singleton });\r\n }\r\n createObject(token) {\r\n const Constructor = token;\r\n const tokens = this.reflectTokens(Constructor);\r\n const params = tokens\r\n ? this.createReflectArgs({ token, tokens })\r\n : this.createTokenArgs(token);\r\n return new Constructor(...params);\r\n }\r\n reflectTokens(reference) {\r\n return Reflect.getMetadata('design:paramtypes', reference);\r\n }\r\n createFromScope({ token, scope }) {\r\n const instance = scope.request(token);\r\n if (instance) {\r\n return instance;\r\n }\r\n const object = this.createObject(token);\r\n scope.push(token, object);\r\n return object;\r\n }\r\n createFromContainer(token) {\r\n const { warehouse: { scope } } = this;\r\n return this.createFromScope({ token, scope });\r\n }\r\n createInstance(props) {\r\n const { token, scopeable, singleton } = props;\r\n const { scope } = this;\r\n if (singleton) {\r\n return this.createFromContainer(token);\r\n }\r\n if (scopeable) {\r\n return this.createFromScope({ token, scope });\r\n }\r\n return this.createObject(token);\r\n }\r\n createFromDecorator(inject) {\r\n const { token, scopeable, singleton } = inject;\r\n const locator = requestInLocator(token);\r\n if (locator) {\r\n const { useClass: token } = locator;\r\n return this.createInstance({ token, scopeable, singleton });\r\n }\r\n return this.createInstance({ token, scopeable, singleton });\r\n }\r\n createReflectArgs({ tokens, token }) {\r\n const { warehouse, context } = this;\r\n const injects = warehouse.injects.request(token);\r\n return tokens.map((token, index) => {\r\n const inject = injects[index];\r\n if (inject) {\r\n return this.createFromDecorator(inject);\r\n }\r\n const locator = requestInLocator(token);\r\n if (locator) {\r\n const { useClass: token, scopeable, singleton } = locator;\r\n return this.createInstance({ token, scopeable, singleton });\r\n }\r\n if (token === Context) {\r\n return context;\r\n }\r\n return this.createObject(token);\r\n });\r\n }\r\n createTokenArgs(token) {\r\n const injects = this.warehouse.injects.request(token);\r\n return injects.reduce((objects, { index, scopeable, singleton, token }) => {\r\n objects[index] = this.createInstance({ token, scopeable, singleton });\r\n return objects;\r\n }, []);\r\n }\r\n}\r\nexport class Container {\r\n constructor() {\r\n this.warehouse = new Warehouse();\r\n }\r\n registerInjectable(options) {\r\n this.warehouse.injectables.push(options);\r\n }\r\n registerInject(options) {\r\n this.warehouse.injects.push(options);\r\n }\r\n createInjectable(options) {\r\n const { token, context } = options;\r\n const { warehouse } = this;\r\n const dependency = new Dependency({ warehouse, context });\r\n return dependency.build(token);\r\n }\r\n}\r\n//# sourceMappingURL=container.factory.js.map","import { Container } from './container.factory';\r\nconst invertlyContainer = new Container();\r\nfunction createFromInvertly(options, container) {\r\n return (container || invertlyContainer).createInjectable(options);\r\n}\r\nexport function invertly(token, container) {\r\n return createFromInvertly({ token }, container);\r\n}\r\nexport function registerInjectable(options, container) {\r\n (container || invertlyContainer).registerInjectable(options);\r\n}\r\nexport function registerInject(options, container) {\r\n (container || invertlyContainer).registerInject(options);\r\n}\r\nexport function registerDependency(token, options) {\r\n const { container, injects, scopeable, singleton } = options;\r\n registerInjectable({\r\n token,\r\n scopeable: scopeable || false,\r\n singleton: singleton || false\r\n }, container);\r\n injects?.forEach((inject, indexParent) => {\r\n const { index, scopeable: childrenScopeable, singleton: childrenSingleton, token: childrenToken } = inject;\r\n registerInject({\r\n index: index || indexParent,\r\n parent: token,\r\n scopeable: childrenScopeable || scopeable || false,\r\n singleton: childrenSingleton || singleton || false,\r\n token: childrenToken\r\n }, container);\r\n });\r\n}\r\nexport { Container } from './container.factory';\r\nexport default createFromInvertly;\r\n//# sourceMappingURL=index.js.map","import { registerInject } from '../factories';\r\nfunction createInject(inject) {\r\n const { scopeable, singleton, token } = inject;\r\n return (parent, _, index) => {\r\n registerInject({ index, parent, scopeable, singleton, token });\r\n };\r\n}\r\nexport function Singleton(token) {\r\n return createInject({ token, scopeable: false, singleton: true });\r\n}\r\nexport function Scope(token) {\r\n return createInject({ token, scopeable: true, singleton: false });\r\n}\r\nexport function Factory(token) {\r\n return createInject({ token, scopeable: false, singleton: false });\r\n}\r\n//# sourceMappingURL=inject.decorator.js.map","import { registerInjectable } from '../factories';\r\nexport function Injectable(options) {\r\n return (token) => {\r\n registerInjectable({\r\n scopeable: !!options?.scopeable,\r\n singleton: !!options?.singleton,\r\n token\r\n });\r\n };\r\n}\r\n//# sourceMappingURL=injectable.decorator.js.map"],"names":[],"mappings":";;;;;;AAAO,MAAM,OAAO,SAAS,GAAG,CAAC;AACjC,IAAI,OAAO,CAAC,GAAG,EAAE;AACjB,QAAQ,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC7B,KAAK;AACL;;ACJO,MAAM,WAAW,CAAC;AACzB,IAAI,WAAW,GAAG;AAClB,QAAQ,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,CAAC;AACpC,KAAK;AACL,IAAI,IAAI,CAAC,OAAO,EAAE;AAClB,QAAQ,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;AAC1C,QAAQ,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7C,QAAQ,OAAO,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC;AACjC,KAAK;AACL,IAAI,OAAO,CAAC,KAAK,EAAE;AACnB,QAAQ,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACnD,QAAQ,IAAI,OAAO,EAAE;AACrB,YAAY,OAAO,OAAO,CAAC;AAC3B,SAAS;AACT,QAAQ,MAAM,OAAO,GAAG,EAAE,CAAC;AAC3B,QAAQ,I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AACjB,SAAS,CAAC,CAAC;AACX,KAAK,CAAC;AACN;;;;;;;;;;;;;;;;;"}
package/dist/es/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import 'reflect-metadata';
2
2
 
3
3
  class Context extends Map {
4
- fetch(key) {
5
- return this.has(key) ? this.get(key) : undefined;
4
+ request(key) {
5
+ return this.get(key);
6
6
  }
7
7
  }
8
8
 
@@ -10,12 +10,12 @@ class InjectStore {
10
10
  constructor() {
11
11
  this.collection = new Map();
12
12
  }
13
- push(config) {
14
- const { parent, index } = config;
15
- const injects = this.fetch(parent);
16
- injects[index] = config;
13
+ push(options) {
14
+ const { parent, index } = options;
15
+ const injects = this.request(parent);
16
+ injects[index] = options;
17
17
  }
18
- fetch(token) {
18
+ request(token) {
19
19
  const current = this.collection.get(token);
20
20
  if (current) {
21
21
  return current;
@@ -30,10 +30,10 @@ class InjectableStore {
30
30
  constructor() {
31
31
  this.collection = new Map();
32
32
  }
33
- push(config) {
34
- this.collection.set(config.token, config);
33
+ push(options) {
34
+ this.collection.set(options.token, options);
35
35
  }
36
- fetch(token) {
36
+ request(token) {
37
37
  return this.collection.get(token);
38
38
  }
39
39
  }
@@ -56,7 +56,7 @@ class LocatorStore {
56
56
  this.collection.set(reference, { token, useClass: token });
57
57
  }
58
58
  }
59
- fetch(token) {
59
+ request(token) {
60
60
  return this.collection.get(token);
61
61
  }
62
62
  }
@@ -67,8 +67,8 @@ function saveInLocator(dependencies) {
67
67
  function pushInLocator(reference, token) {
68
68
  locatorStore.push(reference, token);
69
69
  }
70
- function fetchInLocator(token) {
71
- return locatorStore.fetch(token);
70
+ function requestInLocator(token) {
71
+ return locatorStore.request(token);
72
72
  }
73
73
 
74
74
  class ScopeStore {
@@ -78,7 +78,7 @@ class ScopeStore {
78
78
  push(token, value) {
79
79
  this.collection.set(token, value);
80
80
  }
81
- fetch(token) {
81
+ request(token) {
82
82
  return this.collection.get(token);
83
83
  }
84
84
  }
@@ -97,7 +97,7 @@ class Dependency {
97
97
  this.scope = new ScopeStore();
98
98
  }
99
99
  build(injectable) {
100
- const config = this.warehouse.injectables.fetch(injectable);
100
+ const config = this.warehouse.injectables.request(injectable);
101
101
  if (!config) {
102
102
  throw Error(`Class ${injectable.toString()} is not found in the collection`);
103
103
  }
@@ -116,7 +116,7 @@ class Dependency {
116
116
  return Reflect.getMetadata('design:paramtypes', reference);
117
117
  }
118
118
  createFromScope({ token, scope }) {
119
- const instance = scope.fetch(token);
119
+ const instance = scope.request(token);
120
120
  if (instance) {
121
121
  return instance;
122
122
  }
@@ -141,7 +141,7 @@ class Dependency {
141
141
  }
142
142
  createFromDecorator(inject) {
143
143
  const { token, scopeable, singleton } = inject;
144
- const locator = fetchInLocator(token);
144
+ const locator = requestInLocator(token);
145
145
  if (locator) {
146
146
  const { useClass: token } = locator;
147
147
  return this.createInstance({ token, scopeable, singleton });
@@ -150,13 +150,13 @@ class Dependency {
150
150
  }
151
151
  createReflectArgs({ tokens, token }) {
152
152
  const { warehouse, context } = this;
153
- const injects = warehouse.injects.fetch(token);
153
+ const injects = warehouse.injects.request(token);
154
154
  return tokens.map((token, index) => {
155
155
  const inject = injects[index];
156
156
  if (inject) {
157
157
  return this.createFromDecorator(inject);
158
158
  }
159
- const locator = fetchInLocator(token);
159
+ const locator = requestInLocator(token);
160
160
  if (locator) {
161
161
  const { useClass: token, scopeable, singleton } = locator;
162
162
  return this.createInstance({ token, scopeable, singleton });
@@ -168,7 +168,7 @@ class Dependency {
168
168
  });
169
169
  }
170
170
  createTokenArgs(token) {
171
- const injects = this.warehouse.injects.fetch(token);
171
+ const injects = this.warehouse.injects.request(token);
172
172
  return injects.reduce((objects, { index, scopeable, singleton, token }) => {
173
173
  objects[index] = this.createInstance({ token, scopeable, singleton });
174
174
  return objects;
@@ -179,89 +179,77 @@ class Container {
179
179
  constructor() {
180
180
  this.warehouse = new Warehouse();
181
181
  }
182
- registerInjectable(config) {
183
- this.warehouse.injectables.push(config);
182
+ registerInjectable(options) {
183
+ this.warehouse.injectables.push(options);
184
184
  }
185
- registerInject(config) {
186
- this.warehouse.injects.push(config);
185
+ registerInject(options) {
186
+ this.warehouse.injects.push(options);
187
187
  }
188
- createInjectable(config) {
189
- const { token, context } = config;
188
+ createInjectable(options) {
189
+ const { token, context } = options;
190
190
  const { warehouse } = this;
191
191
  const dependency = new Dependency({ warehouse, context });
192
192
  return dependency.build(token);
193
193
  }
194
194
  }
195
195
 
196
- const rootContainer = new Container();
197
- const createFromInvertly = (options) => {
198
- const { config, container } = options;
199
- return (container || rootContainer).createInjectable(config);
200
- };
201
- const invertly = (token, { container } = {}) => {
202
- return createFromInvertly({ config: { token }, container });
203
- };
204
- const registerInjectable = (options) => {
205
- const { config, container } = options;
206
- (container || rootContainer).registerInjectable(config);
207
- };
208
- const registerInject = (options) => {
209
- const { config, container } = options;
210
- (container || rootContainer).registerInject(config);
211
- };
212
- const registerDependency = (token, options) => {
196
+ const invertlyContainer = new Container();
197
+ function createFromInvertly(options, container) {
198
+ return (container || invertlyContainer).createInjectable(options);
199
+ }
200
+ function invertly(token, container) {
201
+ return createFromInvertly({ token }, container);
202
+ }
203
+ function registerInjectable(options, container) {
204
+ (container || invertlyContainer).registerInjectable(options);
205
+ }
206
+ function registerInject(options, container) {
207
+ (container || invertlyContainer).registerInject(options);
208
+ }
209
+ function registerDependency(token, options) {
213
210
  const { container, injects, scopeable, singleton } = options;
214
211
  registerInjectable({
215
- config: {
216
- token,
217
- scopeable: scopeable || false,
218
- singleton: singleton || false
219
- },
220
- container
221
- });
212
+ token,
213
+ scopeable: scopeable || false,
214
+ singleton: singleton || false
215
+ }, container);
222
216
  injects?.forEach((inject, indexParent) => {
223
217
  const { index, scopeable: childrenScopeable, singleton: childrenSingleton, token: childrenToken } = inject;
224
218
  registerInject({
225
- config: {
226
- index: index || indexParent,
227
- parent: token,
228
- scopeable: childrenScopeable || scopeable || false,
229
- singleton: childrenSingleton || singleton || false,
230
- token: childrenToken
231
- },
232
- container
233
- });
219
+ index: index || indexParent,
220
+ parent: token,
221
+ scopeable: childrenScopeable || scopeable || false,
222
+ singleton: childrenSingleton || singleton || false,
223
+ token: childrenToken
224
+ }, container);
234
225
  });
235
- };
226
+ }
236
227
 
237
- const createInject = ({ scopeable, singleton, token }) => {
228
+ function createInject(inject) {
229
+ const { scopeable, singleton, token } = inject;
238
230
  return (parent, _, index) => {
239
- registerInject({
240
- config: { index, parent, scopeable, singleton, token }
241
- });
231
+ registerInject({ index, parent, scopeable, singleton, token });
242
232
  };
243
- };
244
- const Singleton = (token) => {
233
+ }
234
+ function Singleton(token) {
245
235
  return createInject({ token, scopeable: false, singleton: true });
246
- };
247
- const Scope = (token) => {
236
+ }
237
+ function Scope(token) {
248
238
  return createInject({ token, scopeable: true, singleton: false });
249
- };
250
- const Factory = (token) => {
239
+ }
240
+ function Factory(token) {
251
241
  return createInject({ token, scopeable: false, singleton: false });
252
- };
242
+ }
253
243
 
254
- const DEFAULT_CONFIG = {
255
- scopeable: false,
256
- singleton: false
257
- };
258
- const Injectable = (config) => {
259
- const finalConfig = { ...DEFAULT_CONFIG, ...config };
260
- const { scopeable, singleton } = finalConfig;
244
+ function Injectable(options) {
261
245
  return (token) => {
262
- registerInjectable({ config: { scopeable, singleton, token } });
246
+ registerInjectable({
247
+ scopeable: !!options?.scopeable,
248
+ singleton: !!options?.singleton,
249
+ token
250
+ });
263
251
  };
264
- };
252
+ }
265
253
 
266
- export { Container, Context, Factory, Injectable, Scope, Singleton, createFromInvertly as default, fetchInLocator, invertly, pushInLocator, registerDependency, registerInject, registerInjectable, saveInLocator };
254
+ export { Container, Context, Factory, Injectable, Scope, Singleton, createFromInvertly as default, invertly, pushInLocator, registerDependency, registerInject, registerInjectable, requestInLocator, saveInLocator };
267
255
  //# sourceMappingURL=index.js.map