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/index36.js
CHANGED
|
@@ -2,116 +2,45 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const constants = require('./index29.js');
|
|
7
|
-
const reflection = require('./index30.js');
|
|
8
|
-
const injectableBuilder = require('./index38.js');
|
|
9
|
-
const dependencies = require('./index39.js');
|
|
10
|
-
const helpers = require('./index28.js');
|
|
11
|
-
const hookManager = require('./index25.js');
|
|
12
|
-
const schema = require('./index31.js');
|
|
13
|
-
const helpers$1 = require('./index3.js');
|
|
5
|
+
const eventManager = require('./index6.js');
|
|
14
6
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
get singleton() {
|
|
49
|
-
return this.singletonInstance;
|
|
50
|
-
}
|
|
51
|
-
get injections() {
|
|
52
|
-
if (this.cachedInjections === undefined) {
|
|
53
|
-
this.cachedInjections = this.definition.inject || [];
|
|
54
|
-
}
|
|
55
|
-
return this.cachedInjections;
|
|
56
|
-
}
|
|
57
|
-
get objects() {
|
|
58
|
-
if (this.cachedObjects === undefined) {
|
|
59
|
-
this.cachedObjects = this.definition.use || [];
|
|
60
|
-
}
|
|
61
|
-
return this.cachedObjects;
|
|
62
|
-
}
|
|
63
|
-
get tags() {
|
|
64
|
-
if (this.cachedTags === undefined) {
|
|
65
|
-
this.cachedTags = this.definition.tags || [];
|
|
66
|
-
}
|
|
67
|
-
return Array.isArray(this.cachedTags) ? this.cachedTags : [
|
|
68
|
-
this.cachedTags
|
|
69
|
-
];
|
|
70
|
-
}
|
|
71
|
-
get globals() {
|
|
72
|
-
if (this.cachedGlobals === undefined) {
|
|
73
|
-
this.cachedGlobals = this.definition.global;
|
|
74
|
-
}
|
|
75
|
-
return this.cachedGlobals;
|
|
76
|
-
}
|
|
77
|
-
get events() {
|
|
78
|
-
if (this.cachedEvents === undefined) {
|
|
79
|
-
this.cachedEvents = this.definition.events || [];
|
|
80
|
-
}
|
|
81
|
-
return this.cachedEvents;
|
|
82
|
-
}
|
|
83
|
-
constructor(e, n, o){
|
|
84
|
-
this.privateContext = n;
|
|
85
|
-
this.publicContext = o;
|
|
86
|
-
this.dependenciesIds = [];
|
|
87
|
-
this.identifier = e.identifier;
|
|
88
|
-
this.concrete = e.concrete;
|
|
89
|
-
this.configuration = e.configuration;
|
|
90
|
-
if (process.env.NODE_ENV !== 'production' && !helpers$1.isAssemblage(this.concrete)) {
|
|
91
|
-
throw new Error(`Class '${this.concrete.name}' is not an Assemblage.`);
|
|
92
|
-
}
|
|
93
|
-
this.builder = new injectableBuilder.InjectableBuilder(this);
|
|
94
|
-
reflection.defineCustomMetadata(constants.ReflectValue.AssemblageContext, this.publicContext, this.concrete);
|
|
95
|
-
for (const e of this.injections){
|
|
96
|
-
this.privateContext.register(e);
|
|
97
|
-
}
|
|
98
|
-
for (const e of this.objects){
|
|
99
|
-
if (typeof e[0] === 'string' || typeof e[0] === 'symbol') {
|
|
100
|
-
this.privateContext.use(e[0], e[1]);
|
|
101
|
-
} else {
|
|
102
|
-
this.privateContext.register(e, true);
|
|
7
|
+
const registerEvents = (t, n)=>{
|
|
8
|
+
const o = t.concrete.prototype instanceof eventManager.EventManager;
|
|
9
|
+
if (o) {
|
|
10
|
+
const e = n;
|
|
11
|
+
const o = e.channels;
|
|
12
|
+
for (const n of t.events){
|
|
13
|
+
if (!o.has(n)) e.addChannels(n);
|
|
14
|
+
if (!t.privateContext.events.has(n)) t.privateContext.addChannels(n);
|
|
15
|
+
}
|
|
16
|
+
for (const e of t.events){
|
|
17
|
+
n.on(e, (...n)=>{
|
|
18
|
+
t.privateContext.emit(e, ...n);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
for (const e of t.events){
|
|
23
|
+
if (!t.privateContext.events.has(e)) t.privateContext.addChannels(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const unregisterEvents = (t, n)=>{
|
|
28
|
+
const o = t.concrete.prototype instanceof eventManager.EventManager;
|
|
29
|
+
if (o) {
|
|
30
|
+
const e = n;
|
|
31
|
+
for (const n of t.events){
|
|
32
|
+
e.off(n);
|
|
33
|
+
}
|
|
34
|
+
e.removeChannels(...t.events);
|
|
35
|
+
t.privateContext.removeChannels(...t.events);
|
|
36
|
+
} else {
|
|
37
|
+
for (const e of t.events){
|
|
38
|
+
if (t.privateContext.events.has(e)) {
|
|
39
|
+
t.privateContext.removeChannels(e);
|
|
103
40
|
}
|
|
104
41
|
}
|
|
105
|
-
this.dependenciesIds = dependencies.resolveDependencies(this.concrete);
|
|
106
|
-
if (this.globals) {
|
|
107
|
-
for(const e in this.globals){
|
|
108
|
-
this.privateContext.addGlobal(e, this.globals[e]);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (e.instance) {
|
|
112
|
-
this.singletonInstance = e.instance;
|
|
113
|
-
}
|
|
114
42
|
}
|
|
115
|
-
}
|
|
43
|
+
};
|
|
116
44
|
|
|
117
|
-
exports.
|
|
45
|
+
exports.registerEvents = registerEvents;
|
|
46
|
+
exports.unregisterEvents = unregisterEvents;
|
package/dist/index36.mjs
CHANGED
|
@@ -1,113 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ReflectValue } from './index29.mjs';
|
|
3
|
-
import { defineCustomMetadata } from './index30.mjs';
|
|
4
|
-
import { InjectableBuilder } from './index38.mjs';
|
|
5
|
-
import { resolveDependencies } from './index39.mjs';
|
|
6
|
-
import { unregisterEvents } from './index28.mjs';
|
|
7
|
-
import { HookManager } from './index25.mjs';
|
|
8
|
-
import { getDefinition } from './index31.mjs';
|
|
9
|
-
import { isAssemblage } from './index3.mjs';
|
|
1
|
+
import { EventManager } from './index6.mjs';
|
|
10
2
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
get singleton() {
|
|
45
|
-
return this.singletonInstance;
|
|
46
|
-
}
|
|
47
|
-
get injections() {
|
|
48
|
-
if (this.cachedInjections === undefined) {
|
|
49
|
-
this.cachedInjections = this.definition.inject || [];
|
|
50
|
-
}
|
|
51
|
-
return this.cachedInjections;
|
|
52
|
-
}
|
|
53
|
-
get objects() {
|
|
54
|
-
if (this.cachedObjects === undefined) {
|
|
55
|
-
this.cachedObjects = this.definition.use || [];
|
|
56
|
-
}
|
|
57
|
-
return this.cachedObjects;
|
|
58
|
-
}
|
|
59
|
-
get tags() {
|
|
60
|
-
if (this.cachedTags === undefined) {
|
|
61
|
-
this.cachedTags = this.definition.tags || [];
|
|
62
|
-
}
|
|
63
|
-
return Array.isArray(this.cachedTags) ? this.cachedTags : [
|
|
64
|
-
this.cachedTags
|
|
65
|
-
];
|
|
66
|
-
}
|
|
67
|
-
get globals() {
|
|
68
|
-
if (this.cachedGlobals === undefined) {
|
|
69
|
-
this.cachedGlobals = this.definition.global;
|
|
70
|
-
}
|
|
71
|
-
return this.cachedGlobals;
|
|
72
|
-
}
|
|
73
|
-
get events() {
|
|
74
|
-
if (this.cachedEvents === undefined) {
|
|
75
|
-
this.cachedEvents = this.definition.events || [];
|
|
76
|
-
}
|
|
77
|
-
return this.cachedEvents;
|
|
78
|
-
}
|
|
79
|
-
constructor(e, n, o){
|
|
80
|
-
this.privateContext = n;
|
|
81
|
-
this.publicContext = o;
|
|
82
|
-
this.dependenciesIds = [];
|
|
83
|
-
this.identifier = e.identifier;
|
|
84
|
-
this.concrete = e.concrete;
|
|
85
|
-
this.configuration = e.configuration;
|
|
86
|
-
if (process.env.NODE_ENV !== 'production' && !isAssemblage(this.concrete)) {
|
|
87
|
-
throw new Error(`Class '${this.concrete.name}' is not an Assemblage.`);
|
|
88
|
-
}
|
|
89
|
-
this.builder = new InjectableBuilder(this);
|
|
90
|
-
defineCustomMetadata(ReflectValue.AssemblageContext, this.publicContext, this.concrete);
|
|
91
|
-
for (const e of this.injections){
|
|
92
|
-
this.privateContext.register(e);
|
|
93
|
-
}
|
|
94
|
-
for (const e of this.objects){
|
|
95
|
-
if (typeof e[0] === 'string' || typeof e[0] === 'symbol') {
|
|
96
|
-
this.privateContext.use(e[0], e[1]);
|
|
97
|
-
} else {
|
|
98
|
-
this.privateContext.register(e, true);
|
|
3
|
+
const registerEvents = (t, n)=>{
|
|
4
|
+
const o = t.concrete.prototype instanceof EventManager;
|
|
5
|
+
if (o) {
|
|
6
|
+
const e = n;
|
|
7
|
+
const o = e.channels;
|
|
8
|
+
for (const n of t.events){
|
|
9
|
+
if (!o.has(n)) e.addChannels(n);
|
|
10
|
+
if (!t.privateContext.events.has(n)) t.privateContext.addChannels(n);
|
|
11
|
+
}
|
|
12
|
+
for (const e of t.events){
|
|
13
|
+
n.on(e, (...n)=>{
|
|
14
|
+
t.privateContext.emit(e, ...n);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
for (const e of t.events){
|
|
19
|
+
if (!t.privateContext.events.has(e)) t.privateContext.addChannels(e);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const unregisterEvents = (t, n)=>{
|
|
24
|
+
const o = t.concrete.prototype instanceof EventManager;
|
|
25
|
+
if (o) {
|
|
26
|
+
const e = n;
|
|
27
|
+
for (const n of t.events){
|
|
28
|
+
e.off(n);
|
|
29
|
+
}
|
|
30
|
+
e.removeChannels(...t.events);
|
|
31
|
+
t.privateContext.removeChannels(...t.events);
|
|
32
|
+
} else {
|
|
33
|
+
for (const e of t.events){
|
|
34
|
+
if (t.privateContext.events.has(e)) {
|
|
35
|
+
t.privateContext.removeChannels(e);
|
|
99
36
|
}
|
|
100
37
|
}
|
|
101
|
-
this.dependenciesIds = resolveDependencies(this.concrete);
|
|
102
|
-
if (this.globals) {
|
|
103
|
-
for(const e in this.globals){
|
|
104
|
-
this.privateContext.addGlobal(e, this.globals[e]);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (e.instance) {
|
|
108
|
-
this.singletonInstance = e.instance;
|
|
109
|
-
}
|
|
110
38
|
}
|
|
111
|
-
}
|
|
39
|
+
};
|
|
112
40
|
|
|
113
|
-
export {
|
|
41
|
+
export { registerEvents, unregisterEvents };
|
package/dist/index37.js
CHANGED
|
@@ -2,18 +2,106 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const constants = require('./index28.js');
|
|
6
|
+
const reflection = require('./index34.js');
|
|
7
|
+
const helpers = require('./index3.js');
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
const n = {
|
|
10
|
+
singleton: {
|
|
11
|
+
test: (r)=>typeof r === 'boolean' || typeof r === 'undefined',
|
|
12
|
+
throw: ()=>{
|
|
13
|
+
throw new Error(`'singleton' property must be of type 'boolean' or 'undefined'.`);
|
|
14
|
+
},
|
|
15
|
+
transform: (r)=>{
|
|
16
|
+
return typeof r === 'undefined' ? true : r ? true : false;
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
events: {
|
|
20
|
+
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>typeof r === 'string'),
|
|
21
|
+
throw: ()=>{
|
|
22
|
+
throw new Error(`'events' property must be an array of strings or 'undefined'.`);
|
|
23
|
+
},
|
|
24
|
+
transform: (r)=>r
|
|
25
|
+
},
|
|
26
|
+
inject: {
|
|
27
|
+
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>Array.isArray(r) && r.length >= 1 && r.length <= 3),
|
|
28
|
+
throw: ()=>{
|
|
29
|
+
throw new Error(`'inject' property must be an array of tuples of length 1, 2 or 3.`);
|
|
30
|
+
},
|
|
31
|
+
transform: (r)=>r
|
|
32
|
+
},
|
|
33
|
+
use: {
|
|
34
|
+
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>Array.isArray(r) && r.length == 2),
|
|
35
|
+
throw: ()=>{
|
|
36
|
+
throw new Error(`'use' property must be an array of tuples of length 2.`);
|
|
37
|
+
},
|
|
38
|
+
transform: (r)=>r
|
|
39
|
+
},
|
|
40
|
+
engage: {
|
|
41
|
+
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>Array.isArray(r) && r.length >= 1 && r.length <= 3),
|
|
42
|
+
throw: ()=>{
|
|
43
|
+
throw new Error(`'engage' property must be an array of tuples of length 1, 2 or 3.`);
|
|
44
|
+
},
|
|
45
|
+
transform: (r)=>r
|
|
46
|
+
},
|
|
47
|
+
tags: {
|
|
48
|
+
test: (r)=>typeof r === 'undefined' || typeof r === 'string' || Array.isArray(r) && r.every((r)=>typeof r === 'string'),
|
|
49
|
+
throw: ()=>{
|
|
50
|
+
throw new Error(`'tags' property must be a string or an array of strings.`);
|
|
51
|
+
},
|
|
52
|
+
transform: (r)=>typeof r === 'string' ? [
|
|
53
|
+
r
|
|
54
|
+
] : r
|
|
55
|
+
},
|
|
56
|
+
metadata: {
|
|
57
|
+
test: (r)=>(typeof r === 'object' || typeof r === 'undefined') && !Array.isArray(r),
|
|
58
|
+
throw: ()=>{
|
|
59
|
+
throw new Error(`'metadata' property must be of type 'object' or 'undefined'.`);
|
|
60
|
+
},
|
|
61
|
+
transform: (r)=>r
|
|
62
|
+
},
|
|
63
|
+
global: {
|
|
64
|
+
test: (r)=>(typeof r === 'object' || typeof r === 'undefined') && !Array.isArray(r),
|
|
65
|
+
throw: ()=>{
|
|
66
|
+
throw new Error(`'global' property must be of type 'object' or 'undefined'.`);
|
|
67
|
+
},
|
|
68
|
+
transform: (r)=>r
|
|
10
69
|
}
|
|
11
|
-
|
|
12
|
-
|
|
70
|
+
};
|
|
71
|
+
const validateDefinition = (r)=>{
|
|
72
|
+
const e = {
|
|
73
|
+
...r
|
|
74
|
+
};
|
|
75
|
+
for(const r in e){
|
|
76
|
+
if (!Object.keys(n).includes(r)) {
|
|
77
|
+
throw new Error(`Property '${r}' is not a valid assemblage definition property.`);
|
|
78
|
+
}
|
|
13
79
|
}
|
|
14
|
-
|
|
15
|
-
|
|
80
|
+
for(const r in n){
|
|
81
|
+
const t = n[r].test;
|
|
82
|
+
const o = n[r].throw;
|
|
83
|
+
const s = n[r].transform;
|
|
84
|
+
if (!t(e[r])) {
|
|
85
|
+
o();
|
|
86
|
+
}
|
|
87
|
+
e[r] = s(e[r]);
|
|
16
88
|
}
|
|
17
|
-
|
|
89
|
+
return e;
|
|
90
|
+
};
|
|
91
|
+
const getDefinition = (e)=>{
|
|
92
|
+
if (!helpers.isAssemblage(e)) {
|
|
93
|
+
throw new Error(`Class '${e.name}' is not an assemblage or transversal.`);
|
|
94
|
+
}
|
|
95
|
+
return reflection.getOwnCustomMetadata(constants.ReflectValue.AssemblageDefinition, e);
|
|
96
|
+
};
|
|
97
|
+
const setDefinitionValue = (t, o, n)=>{
|
|
98
|
+
const s = getDefinition(n);
|
|
99
|
+
s[t] = o;
|
|
100
|
+
const a = validateDefinition(s);
|
|
101
|
+
reflection.defineCustomMetadata(constants.ReflectValue.AssemblageDefinition, a, n);
|
|
102
|
+
return a;
|
|
103
|
+
};
|
|
18
104
|
|
|
19
|
-
exports.
|
|
105
|
+
exports.getDefinition = getDefinition;
|
|
106
|
+
exports.setDefinitionValue = setDefinitionValue;
|
|
107
|
+
exports.validateDefinition = validateDefinition;
|
package/dist/index37.mjs
CHANGED
|
@@ -1,15 +1,101 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReflectValue } from './index28.mjs';
|
|
2
|
+
import { getOwnCustomMetadata, defineCustomMetadata } from './index34.mjs';
|
|
3
|
+
import { isAssemblage } from './index3.mjs';
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
const n = {
|
|
6
|
+
singleton: {
|
|
7
|
+
test: (r)=>typeof r === 'boolean' || typeof r === 'undefined',
|
|
8
|
+
throw: ()=>{
|
|
9
|
+
throw new Error(`'singleton' property must be of type 'boolean' or 'undefined'.`);
|
|
10
|
+
},
|
|
11
|
+
transform: (r)=>{
|
|
12
|
+
return typeof r === 'undefined' ? true : r ? true : false;
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
events: {
|
|
16
|
+
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>typeof r === 'string'),
|
|
17
|
+
throw: ()=>{
|
|
18
|
+
throw new Error(`'events' property must be an array of strings or 'undefined'.`);
|
|
19
|
+
},
|
|
20
|
+
transform: (r)=>r
|
|
21
|
+
},
|
|
22
|
+
inject: {
|
|
23
|
+
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>Array.isArray(r) && r.length >= 1 && r.length <= 3),
|
|
24
|
+
throw: ()=>{
|
|
25
|
+
throw new Error(`'inject' property must be an array of tuples of length 1, 2 or 3.`);
|
|
26
|
+
},
|
|
27
|
+
transform: (r)=>r
|
|
28
|
+
},
|
|
29
|
+
use: {
|
|
30
|
+
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>Array.isArray(r) && r.length == 2),
|
|
31
|
+
throw: ()=>{
|
|
32
|
+
throw new Error(`'use' property must be an array of tuples of length 2.`);
|
|
33
|
+
},
|
|
34
|
+
transform: (r)=>r
|
|
35
|
+
},
|
|
36
|
+
engage: {
|
|
37
|
+
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>Array.isArray(r) && r.length >= 1 && r.length <= 3),
|
|
38
|
+
throw: ()=>{
|
|
39
|
+
throw new Error(`'engage' property must be an array of tuples of length 1, 2 or 3.`);
|
|
40
|
+
},
|
|
41
|
+
transform: (r)=>r
|
|
42
|
+
},
|
|
43
|
+
tags: {
|
|
44
|
+
test: (r)=>typeof r === 'undefined' || typeof r === 'string' || Array.isArray(r) && r.every((r)=>typeof r === 'string'),
|
|
45
|
+
throw: ()=>{
|
|
46
|
+
throw new Error(`'tags' property must be a string or an array of strings.`);
|
|
47
|
+
},
|
|
48
|
+
transform: (r)=>typeof r === 'string' ? [
|
|
49
|
+
r
|
|
50
|
+
] : r
|
|
51
|
+
},
|
|
52
|
+
metadata: {
|
|
53
|
+
test: (r)=>(typeof r === 'object' || typeof r === 'undefined') && !Array.isArray(r),
|
|
54
|
+
throw: ()=>{
|
|
55
|
+
throw new Error(`'metadata' property must be of type 'object' or 'undefined'.`);
|
|
56
|
+
},
|
|
57
|
+
transform: (r)=>r
|
|
58
|
+
},
|
|
59
|
+
global: {
|
|
60
|
+
test: (r)=>(typeof r === 'object' || typeof r === 'undefined') && !Array.isArray(r),
|
|
61
|
+
throw: ()=>{
|
|
62
|
+
throw new Error(`'global' property must be of type 'object' or 'undefined'.`);
|
|
63
|
+
},
|
|
64
|
+
transform: (r)=>r
|
|
6
65
|
}
|
|
7
|
-
|
|
8
|
-
|
|
66
|
+
};
|
|
67
|
+
const validateDefinition = (r)=>{
|
|
68
|
+
const e = {
|
|
69
|
+
...r
|
|
70
|
+
};
|
|
71
|
+
for(const r in e){
|
|
72
|
+
if (!Object.keys(n).includes(r)) {
|
|
73
|
+
throw new Error(`Property '${r}' is not a valid assemblage definition property.`);
|
|
74
|
+
}
|
|
9
75
|
}
|
|
10
|
-
|
|
11
|
-
|
|
76
|
+
for(const r in n){
|
|
77
|
+
const t = n[r].test;
|
|
78
|
+
const o = n[r].throw;
|
|
79
|
+
const s = n[r].transform;
|
|
80
|
+
if (!t(e[r])) {
|
|
81
|
+
o();
|
|
82
|
+
}
|
|
83
|
+
e[r] = s(e[r]);
|
|
12
84
|
}
|
|
13
|
-
|
|
85
|
+
return e;
|
|
86
|
+
};
|
|
87
|
+
const getDefinition = (e)=>{
|
|
88
|
+
if (!isAssemblage(e)) {
|
|
89
|
+
throw new Error(`Class '${e.name}' is not an assemblage or transversal.`);
|
|
90
|
+
}
|
|
91
|
+
return getOwnCustomMetadata(ReflectValue.AssemblageDefinition, e);
|
|
92
|
+
};
|
|
93
|
+
const setDefinitionValue = (t, o, n)=>{
|
|
94
|
+
const s = getDefinition(n);
|
|
95
|
+
s[t] = o;
|
|
96
|
+
const a = validateDefinition(s);
|
|
97
|
+
defineCustomMetadata(ReflectValue.AssemblageDefinition, a, n);
|
|
98
|
+
return a;
|
|
99
|
+
};
|
|
14
100
|
|
|
15
|
-
export {
|
|
101
|
+
export { getDefinition, setDefinitionValue, validateDefinition };
|
package/dist/index38.js
CHANGED
|
@@ -2,30 +2,105 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const transversalManager = require('./index13.js');
|
|
6
|
+
const affect = require('./index12.js');
|
|
7
7
|
|
|
8
|
-
class
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
class TransversalWeaver {
|
|
9
|
+
static weave(n, r, o) {
|
|
10
|
+
const c = transversalManager.TransversalManager.getInstance(o);
|
|
11
|
+
const s = c.getAspectsForTarget(r);
|
|
12
|
+
const a = Object.getPrototypeOf(n);
|
|
13
|
+
const i = Object.getOwnPropertyNames(a).some((t)=>{
|
|
14
|
+
if (t === 'constructor' || typeof a[t] !== 'function') return false;
|
|
15
|
+
const n = affect.getAffectedMethods(a, t);
|
|
16
|
+
return n.length > 0;
|
|
17
|
+
});
|
|
18
|
+
if (s.length === 0 && !i) {
|
|
19
|
+
return n;
|
|
20
|
+
}
|
|
21
|
+
return new Proxy(n, {
|
|
22
|
+
get (t, e, n) {
|
|
23
|
+
const r = Reflect.get(t, e, n);
|
|
24
|
+
if (typeof r !== 'function') {
|
|
25
|
+
return r;
|
|
26
|
+
}
|
|
27
|
+
return function(...n) {
|
|
28
|
+
const o = String(e);
|
|
29
|
+
const a = {
|
|
30
|
+
target: t,
|
|
31
|
+
methodName: o,
|
|
32
|
+
args: n
|
|
33
|
+
};
|
|
34
|
+
const i = c.getAdvicesForJoinPoint(a, s, t, e);
|
|
35
|
+
return TransversalWeaver.executeAdviceChain(i, r, t, n, a);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
});
|
|
15
39
|
}
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
40
|
+
static executeAdviceChain(t, e, n, r, o) {
|
|
41
|
+
const c = t.filter((t)=>t.type === 'before');
|
|
42
|
+
const s = t.filter((t)=>t.type === 'around');
|
|
43
|
+
const a = t.filter((t)=>t.type === 'after');
|
|
44
|
+
try {
|
|
45
|
+
for (const t of c){
|
|
46
|
+
const e = {
|
|
47
|
+
...o,
|
|
48
|
+
config: t.config
|
|
49
|
+
};
|
|
50
|
+
t.method.call(t.transversalInstance, e);
|
|
51
|
+
}
|
|
52
|
+
let t;
|
|
53
|
+
if (s.length > 0) {
|
|
54
|
+
t = this.buildAroundChain(s, e, n, r, o);
|
|
55
|
+
} else {
|
|
56
|
+
t = e.apply(n, r);
|
|
57
|
+
}
|
|
58
|
+
if (t instanceof Promise) {
|
|
59
|
+
return t.then((t)=>{
|
|
60
|
+
for (const e of a){
|
|
61
|
+
const n = {
|
|
62
|
+
...o,
|
|
63
|
+
result: t
|
|
64
|
+
};
|
|
65
|
+
e.method.call(e.transversalInstance, n);
|
|
66
|
+
}
|
|
67
|
+
return t;
|
|
68
|
+
}).catch((t)=>{
|
|
69
|
+
o.error = t;
|
|
70
|
+
throw t;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
for (const e of a){
|
|
74
|
+
const n = {
|
|
75
|
+
...o,
|
|
76
|
+
result: t,
|
|
77
|
+
config: e.config
|
|
78
|
+
};
|
|
79
|
+
e.method.call(e.transversalInstance, n);
|
|
80
|
+
}
|
|
81
|
+
return t;
|
|
82
|
+
} catch (t) {
|
|
83
|
+
o.error = t;
|
|
84
|
+
throw t;
|
|
23
85
|
}
|
|
24
|
-
return t;
|
|
25
86
|
}
|
|
26
|
-
|
|
27
|
-
|
|
87
|
+
static buildAroundChain(t, e, n, r, o) {
|
|
88
|
+
let c = 0;
|
|
89
|
+
const s = ()=>{
|
|
90
|
+
if (c < t.length) {
|
|
91
|
+
const e = t[c++];
|
|
92
|
+
const n = {
|
|
93
|
+
...o,
|
|
94
|
+
proceed: s,
|
|
95
|
+
config: e.config
|
|
96
|
+
};
|
|
97
|
+
return e.method.call(e.transversalInstance, n);
|
|
98
|
+
} else {
|
|
99
|
+
return e.apply(n, r);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
return s();
|
|
28
103
|
}
|
|
29
104
|
}
|
|
30
105
|
|
|
31
|
-
exports.
|
|
106
|
+
exports.TransversalWeaver = TransversalWeaver;
|