assemblerjs 1.1.1 → 1.1.3

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 (64) hide show
  1. package/dist/index.d.ts +53 -8
  2. package/dist/index13.js +1 -1
  3. package/dist/index13.mjs +1 -1
  4. package/dist/index18.js +1 -1
  5. package/dist/index18.mjs +1 -1
  6. package/dist/index19.js +1 -1
  7. package/dist/index19.mjs +1 -1
  8. package/dist/index20.js +1 -1
  9. package/dist/index20.mjs +1 -1
  10. package/dist/index21.js +1 -1
  11. package/dist/index21.mjs +1 -1
  12. package/dist/index22.js +1 -1
  13. package/dist/index22.mjs +1 -1
  14. package/dist/index23.js +1 -1
  15. package/dist/index23.mjs +1 -1
  16. package/dist/index24.js +1 -1
  17. package/dist/index24.mjs +1 -1
  18. package/dist/index27.js +1 -1
  19. package/dist/index27.mjs +1 -1
  20. package/dist/index30.js +8 -2
  21. package/dist/index30.mjs +8 -2
  22. package/dist/index31.js +38 -20
  23. package/dist/index31.mjs +37 -20
  24. package/dist/index32.js +17 -58
  25. package/dist/index32.mjs +17 -58
  26. package/dist/index33.js +57 -20
  27. package/dist/index33.mjs +57 -20
  28. package/dist/index34.js +23 -57
  29. package/dist/index34.mjs +23 -57
  30. package/dist/index35.js +75 -27
  31. package/dist/index35.mjs +75 -27
  32. package/dist/index36.js +39 -29
  33. package/dist/index36.mjs +39 -29
  34. package/dist/index37.js +30 -39
  35. package/dist/index37.mjs +30 -38
  36. package/dist/index38.js +125 -97
  37. package/dist/index38.mjs +125 -97
  38. package/dist/index39.js +101 -24
  39. package/dist/index39.mjs +101 -24
  40. package/dist/index4.js +21 -8
  41. package/dist/index4.mjs +21 -8
  42. package/dist/index40.js +28 -48
  43. package/dist/index40.mjs +28 -48
  44. package/dist/index41.js +43 -3
  45. package/dist/index41.mjs +43 -3
  46. package/dist/index42.js +22 -28
  47. package/dist/index42.mjs +21 -27
  48. package/dist/index43.js +26 -169
  49. package/dist/index43.mjs +25 -169
  50. package/dist/index44.js +192 -940
  51. package/dist/index44.mjs +192 -940
  52. package/dist/index45.js +942 -2
  53. package/dist/index45.mjs +942 -2
  54. package/dist/index46.js +2 -2
  55. package/dist/index46.mjs +2 -2
  56. package/dist/index47.js +2 -14
  57. package/dist/index47.mjs +2 -14
  58. package/dist/index48.js +9 -23
  59. package/dist/index48.mjs +9 -23
  60. package/dist/index49.js +32 -55
  61. package/dist/index49.mjs +32 -54
  62. package/dist/index50.js +67 -0
  63. package/dist/index50.mjs +62 -0
  64. package/package.json +1 -1
package/dist/index43.mjs CHANGED
@@ -1,173 +1,29 @@
1
- import { isClass, clearInstance } from '@assemblerjs/core';
2
- import { ReflectValue } from './index28.mjs';
3
- import { defineCustomMetadata } from './index29.mjs';
4
- import { InjectableBuilder } from './index48.mjs';
5
- import { resolveDependencies } from './index49.mjs';
6
- import { unregisterEvents } from './index37.mjs';
7
- import { HookManager } from './index34.mjs';
8
- import { isAssemblage } from './index3.mjs';
9
- import { getDefinition } from './index30.mjs';
10
- import { isTransversal } from './index11.mjs';
11
- import { TransversalManager } from './index13.mjs';
12
-
13
- class Injectable {
14
- static of(e, t, s) {
15
- return new Injectable(e, t, s);
16
- }
17
- resolveTransversalToInjection(e) {
18
- if (e.length === 1) {
19
- return [
20
- e[0]
21
- ];
22
- } else if (e.length === 2) {
23
- const s = e[1];
24
- if (isClass(s)) {
25
- return [
26
- e[0],
27
- e[1]
28
- ];
29
- } else {
30
- return [
31
- e[0],
32
- e[1]
33
- ];
34
- }
35
- } else {
36
- return [
37
- e[0],
38
- e[1],
39
- e[2]
40
- ];
41
- }
42
- }
43
- dispose() {
44
- if (this.singletonInstance) {
45
- unregisterEvents(this, this.singletonInstance);
46
- HookManager.callHook(this.singletonInstance, 'onDispose', this.publicContext, this.mergedConfiguration || this.configuration);
47
- clearInstance(this.singletonInstance, this.concrete);
48
- }
49
- clearInstance(this, Injectable);
50
- }
51
- build(e) {
52
- return this.builder.build(e);
53
- }
54
- setSingletonInstance(e, t) {
55
- this.singletonInstance = e;
56
- if (t) {
57
- this.mergedConfiguration = t;
58
- }
59
- }
60
- get definition() {
61
- if (!this.cachedDefinition) {
62
- this.cachedDefinition = getDefinition(this.concrete) || {};
63
- }
64
- return this.cachedDefinition;
65
- }
66
- get isSingleton() {
67
- return this.definition.singleton ?? false;
68
- }
69
- get dependencies() {
70
- return this.dependenciesIds;
1
+ class SingletonStrategy {
2
+ resolve(t, e) {
3
+ const n = t.identifier;
4
+ if (this.cache.has(n)) {
5
+ return this.cache.get(n);
6
+ }
7
+ const o = t.build(e);
8
+ const r = e ? {
9
+ ...t.configuration,
10
+ ...e
11
+ } : t.configuration;
12
+ t.setSingletonInstance(o, r);
13
+ this.cache.set(n, o);
14
+ t.privateContext.prepareInitHook(o, t.configuration);
15
+ return o;
16
+ }
17
+ constructor(){
18
+ this.cache = new Map();
71
19
  }
72
- get singleton() {
73
- return this.singletonInstance;
74
- }
75
- get injections() {
76
- if (this.cachedInjections === undefined) {
77
- this.cachedInjections = this.definition.inject || [];
78
- }
79
- return this.cachedInjections;
80
- }
81
- get objects() {
82
- if (this.cachedObjects === undefined) {
83
- this.cachedObjects = this.definition.use || [];
84
- }
85
- return this.cachedObjects;
86
- }
87
- get transversals() {
88
- if (this.cachedTransversals === undefined) {
89
- this.cachedTransversals = this.definition.engage || [];
90
- }
91
- return this.cachedTransversals;
92
- }
93
- get tags() {
94
- if (this.cachedTags === undefined) {
95
- this.cachedTags = this.definition.tags || [];
96
- }
97
- return Array.isArray(this.cachedTags) ? this.cachedTags : [
98
- this.cachedTags
99
- ];
100
- }
101
- get globals() {
102
- if (this.cachedGlobals === undefined) {
103
- this.cachedGlobals = this.definition.global;
104
- }
105
- return this.cachedGlobals;
106
- }
107
- get events() {
108
- if (this.cachedEvents === undefined) {
109
- this.cachedEvents = this.definition.events || [];
110
- }
111
- return this.cachedEvents;
112
- }
113
- constructor(e, t, r){
114
- this.privateContext = t;
115
- this.publicContext = r;
116
- this.dependenciesIds = [];
117
- this.identifier = e.identifier;
118
- this.concrete = e.concrete;
119
- this.configuration = e.configuration;
120
- if (process.env.NODE_ENV !== 'production' && !isAssemblage(this.concrete)) {
121
- throw new Error(`Class '${this.concrete.name}' is not an Assemblage.`);
122
- }
123
- this.builder = new InjectableBuilder(this);
124
- defineCustomMetadata(ReflectValue.AssemblageContext, this.publicContext, this.concrete);
125
- for (const e of this.transversals){
126
- const t = this.resolveTransversalToInjection(e);
127
- this.privateContext.register(t);
128
- }
129
- for (const e of this.injections){
130
- const [t] = e;
131
- if (isTransversal(t)) {
132
- this.privateContext.register(e);
133
- }
134
- }
135
- for (const e of this.injections){
136
- const [t] = e;
137
- if (!isTransversal(t)) {
138
- this.privateContext.register(e);
139
- }
140
- }
141
- for (const e of this.objects){
142
- if (typeof e[0] === 'string' || typeof e[0] === 'symbol') {
143
- this.privateContext.use(e[0], e[1]);
144
- } else {
145
- this.privateContext.register(e, true);
146
- }
147
- }
148
- const a = TransversalManager.getInstance(this.publicContext);
149
- for (const e of this.transversals){
150
- a.registerTransversal(e, this.privateContext);
151
- }
152
- for (const e of this.injections){
153
- const [t] = e;
154
- if (isTransversal(t)) {
155
- const s = e.length > 1 ? e : [
156
- t
157
- ];
158
- a.registerTransversal(s, this.privateContext);
159
- }
160
- }
161
- this.dependenciesIds = resolveDependencies(this.concrete);
162
- if (this.globals) {
163
- for(const e in this.globals){
164
- this.privateContext.addGlobal(e, this.globals[e]);
165
- }
166
- }
167
- if (e.instance) {
168
- this.singletonInstance = e.instance;
169
- }
20
+ }
21
+ class TransientStrategy {
22
+ resolve(t, e) {
23
+ const n = t.build(e);
24
+ t.privateContext.prepareInitHook(n, t.configuration);
25
+ return n;
170
26
  }
171
27
  }
172
28
 
173
- export { Injectable };
29
+ export { SingletonStrategy, TransientStrategy };