assemblerjs 1.0.0 → 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.
- package/README.md +29 -53
- package/dist/index.d.ts +430 -9
- package/dist/index.js +24 -12
- package/dist/index.mjs +16 -12
- package/dist/index11.js +82 -20
- package/dist/index11.mjs +78 -20
- package/dist/index12.js +17 -8
- package/dist/index12.mjs +16 -8
- package/dist/index13.js +148 -73
- package/dist/index13.mjs +148 -73
- package/dist/index14.js +4 -17
- package/dist/index14.mjs +4 -17
- package/dist/index15.js +21 -16
- package/dist/index15.mjs +21 -16
- package/dist/index16.js +10 -16
- package/dist/index16.mjs +10 -16
- package/dist/index17.js +88 -16
- package/dist/index17.mjs +88 -16
- package/dist/index18.js +11 -20
- package/dist/index18.mjs +11 -19
- package/dist/index19.js +11 -20
- package/dist/index19.mjs +11 -19
- package/dist/index2.js +3 -3
- package/dist/index2.mjs +3 -3
- package/dist/index20.js +11 -20
- package/dist/index20.mjs +11 -20
- package/dist/index21.js +14 -25
- package/dist/index21.mjs +14 -21
- package/dist/index22.js +24 -46
- package/dist/index22.mjs +23 -45
- package/dist/index23.js +25 -63
- package/dist/index23.mjs +24 -63
- package/dist/index24.js +24 -30
- package/dist/index24.mjs +24 -30
- package/dist/index25.js +24 -62
- package/dist/index25.mjs +20 -62
- package/dist/index26.js +46 -30
- package/dist/index26.mjs +45 -30
- package/dist/index27.js +2 -34
- package/dist/index27.mjs +2 -32
- package/dist/index28.js +17 -41
- package/dist/index28.mjs +15 -40
- package/dist/index29.js +64 -15
- package/dist/index29.mjs +64 -13
- package/dist/index3.js +2 -2
- package/dist/index3.mjs +2 -2
- package/dist/index30.js +32 -14
- package/dist/index30.mjs +32 -12
- package/dist/index31.js +57 -86
- package/dist/index31.mjs +57 -84
- package/dist/index32.js +28 -19
- package/dist/index32.mjs +28 -19
- package/dist/index33.js +28 -25
- package/dist/index33.mjs +28 -24
- package/dist/index34.js +17 -8
- package/dist/index34.mjs +14 -8
- package/dist/index35.js +23 -49
- package/dist/index35.mjs +23 -49
- package/dist/index36.js +37 -108
- package/dist/index36.mjs +36 -108
- package/dist/index37.js +98 -10
- package/dist/index37.mjs +96 -10
- package/dist/index38.js +95 -20
- package/dist/index38.mjs +95 -20
- package/dist/index39.js +23 -44
- package/dist/index39.mjs +23 -43
- package/dist/index4.js +5 -5
- package/dist/index4.mjs +5 -5
- package/dist/index40.js +34 -0
- package/dist/index40.mjs +29 -0
- package/dist/index41.js +14 -0
- package/dist/index41.mjs +10 -0
- package/dist/index42.js +54 -0
- package/dist/index42.mjs +50 -0
- package/dist/index43.js +177 -0
- package/dist/index43.mjs +173 -0
- package/dist/index44.js +947 -0
- package/dist/index44.mjs +943 -0
- package/dist/index45.js +7 -0
- package/dist/index45.mjs +3 -0
- package/dist/index46.js +7 -0
- package/dist/index46.mjs +3 -0
- package/dist/index47.js +19 -0
- package/dist/index47.mjs +15 -0
- package/dist/index48.js +33 -0
- package/dist/index48.mjs +29 -0
- package/dist/index49.js +67 -0
- package/dist/index49.mjs +62 -0
- package/package.json +2 -2
package/dist/index43.mjs
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { isClass, clearInstance } from '@assemblerjs/core';
|
|
2
|
+
import { ReflectValue } from './index28.mjs';
|
|
3
|
+
import { defineCustomMetadata } from './index34.mjs';
|
|
4
|
+
import { InjectableBuilder } from './index48.mjs';
|
|
5
|
+
import { resolveDependencies } from './index49.mjs';
|
|
6
|
+
import { unregisterEvents } from './index36.mjs';
|
|
7
|
+
import { HookManager } from './index31.mjs';
|
|
8
|
+
import { isAssemblage } from './index3.mjs';
|
|
9
|
+
import { getDefinition } from './index37.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;
|
|
71
|
+
}
|
|
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
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export { Injectable };
|