@teqfw/di 0.10.0 → 0.11.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 +7 -4
- package/RELEASE.md +6 -0
- package/bin/release/clean.sh +1 -0
- package/package.json +1 -1
- package/src/Back/Api/Dto/Plugin/Desc.mjs +18 -6
- package/src/Shared/Api/IProxy.mjs +11 -0
- package/src/Shared/Api/Dto/Plugin/Desc/Replace.mjs +0 -50
- package/src/Shared/Api/Enum/Area.mjs +0 -10
- package/src/Shared/Api/IFactory.mjs +0 -11
package/README.md
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
"_DI_" means both "_Dynamic Import_" and "_Dependency Injection_" here. This package allows defining logical namespaces
|
|
4
4
|
in your projects, dynamically importing ES6-modules from these namespaces, creating new objects from imported
|
|
5
5
|
functions/classes and resolving dependencies in constructors. It uses pure ECMAScript 2015+ (ES6+) and works both for
|
|
6
|
-
modern browsers & nodejs apps. You can share the same code between your frontend (browser) and your backend (nodejs)
|
|
6
|
+
modern browsers & nodejs apps. You can share the same code between your frontend (browser) and your backend (nodejs)
|
|
7
|
+
without TypeScript and preprocessors. Code in the browser's debugger will be the same as in your editor. Finally, you
|
|
8
|
+
even can use interfaces in you projects and replace it with implementations.
|
|
7
9
|
|
|
8
|
-
The '_proxy object_' for `constructor` specification is inspired by [awilix](https://github.com/jeffijoe/awilix).
|
|
9
|
-
|
|
10
|
+
The '_proxy object_' for `constructor` specification is inspired by [awilix](https://github.com/jeffijoe/awilix). Thanks
|
|
11
|
+
guys.
|
|
10
12
|
|
|
11
13
|
## Installation
|
|
12
14
|
|
|
@@ -36,7 +38,8 @@ import ScanData from '../Api/Dto/Scanned.mjs';
|
|
|
36
38
|
import {existsSync, readdirSync, readFileSync, statSync} from 'fs';
|
|
37
39
|
```
|
|
38
40
|
|
|
39
|
-
but DI container cannot process these imports. Function or class should have this interface to be compatible with DI
|
|
41
|
+
but DI container cannot process these imports. Function or class should have this interface to be compatible with DI
|
|
42
|
+
container:
|
|
40
43
|
|
|
41
44
|
```ecmascript 6
|
|
42
45
|
export default function ObjectFactory(spec) {/* ... */}
|
package/RELEASE.md
CHANGED
package/bin/release/clean.sh
CHANGED
package/package.json
CHANGED
|
@@ -9,7 +9,12 @@ const NS = 'TeqFw_Di_Back_Api_Dto_Plugin_Desc';
|
|
|
9
9
|
export default class TeqFw_Di_Back_Api_Dto_Plugin_Desc {
|
|
10
10
|
/** @type {TeqFw_Di_Shared_Api_Dto_Plugin_Desc_Autoload} */
|
|
11
11
|
autoload;
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Replacements for IDs:
|
|
14
|
+
* - {'Interface_Name': 'Impl_Name'}: replace es6-module 'Interface_Name' with 'Impl_Name' on injection;
|
|
15
|
+
* - {'front': {'Interface_Name': 'Impl_Name'}}: do the same for 'front' area only (should be implemented outside this plugin)
|
|
16
|
+
* @type {Object<string, string>|Object<string, Object<string, string>>}
|
|
17
|
+
*/
|
|
13
18
|
replace;
|
|
14
19
|
}
|
|
15
20
|
|
|
@@ -25,11 +30,9 @@ export class Factory {
|
|
|
25
30
|
constructor(spec) {
|
|
26
31
|
/** @type {TeqFw_Di_Shared_Api_Dto_Plugin_Desc_Autoload.Factory} */
|
|
27
32
|
const fAutoload = spec['TeqFw_Di_Shared_Api_Dto_Plugin_Desc_Autoload#Factory$'];
|
|
28
|
-
/** @type {TeqFw_Di_Shared_Api_Dto_Plugin_Desc_Replace.Factory} */
|
|
29
|
-
const fReplace = spec['TeqFw_Di_Shared_Api_Dto_Plugin_Desc_Replace#Factory$'];
|
|
30
33
|
|
|
31
34
|
/**
|
|
32
|
-
* @param {
|
|
35
|
+
* @param {*} data
|
|
33
36
|
* @return {TeqFw_Di_Back_Api_Dto_Plugin_Desc}
|
|
34
37
|
*/
|
|
35
38
|
this.create = function (data = null) {
|
|
@@ -38,8 +41,17 @@ export class Factory {
|
|
|
38
41
|
function parseReplace(data) {
|
|
39
42
|
const res = {};
|
|
40
43
|
if (typeof data === 'object')
|
|
41
|
-
for (const ns of Object.keys(data))
|
|
42
|
-
|
|
44
|
+
for (const ns of Object.keys(data)) {
|
|
45
|
+
const node = data[ns];
|
|
46
|
+
if (typeof node === 'string') {
|
|
47
|
+
res[ns] = data[ns]; // {"interface": "impl"}
|
|
48
|
+
} else if (typeof node === 'object') {
|
|
49
|
+
res[ns] = {}; // {"interface": {"area": "impl"}}
|
|
50
|
+
for (const area of Object.keys(node))
|
|
51
|
+
if (typeof node[area] === 'string')
|
|
52
|
+
res[ns][area] = node[area];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
43
55
|
return res;
|
|
44
56
|
}
|
|
45
57
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for proxy factory to create objects using 'Vnd_Plugin_Single@' & 'Vnd_Plugin_Obj@@' dependency ID.
|
|
3
|
+
* @interface
|
|
4
|
+
*/
|
|
5
|
+
export default class TeqFw_Di_Shared_Api_IProxy {
|
|
6
|
+
/**
|
|
7
|
+
* Get target object asynchronously.
|
|
8
|
+
* @return {Promise<*>}
|
|
9
|
+
*/
|
|
10
|
+
get create() { }
|
|
11
|
+
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DTO to represent plugin descriptor (teqfw.json) structure
|
|
3
|
-
* that is related to 'di/replace' node:
|
|
4
|
-
*/
|
|
5
|
-
// MODULE'S IMPORT
|
|
6
|
-
import AREA from '../../../Enum/Area.mjs';
|
|
7
|
-
// MODULE'S VARS
|
|
8
|
-
const NS = 'TeqFw_Di_Shared_Api_Dto_Plugin_Desc_Replace';
|
|
9
|
-
|
|
10
|
-
// MODULE'S CLASSES
|
|
11
|
-
export default class TeqFw_Di_Shared_Api_Dto_Plugin_Desc_Replace {
|
|
12
|
-
/**
|
|
13
|
-
* App area to use replacement ('back', 'front', 'shared').
|
|
14
|
-
* @type {string}
|
|
15
|
-
*/
|
|
16
|
-
area;
|
|
17
|
-
/**
|
|
18
|
-
* Logical name for ES6 module with replacement code (Vnd_Plug_Implementation).
|
|
19
|
-
* @type {string}
|
|
20
|
-
*/
|
|
21
|
-
ns;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// attributes names to use as aliases in queries to object props
|
|
25
|
-
TeqFw_Di_Shared_Api_Dto_Plugin_Desc_Replace.AREA = 'area';
|
|
26
|
-
TeqFw_Di_Shared_Api_Dto_Plugin_Desc_Replace.NS = 'ns';
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Factory to create new DTO instances.
|
|
30
|
-
* @memberOf TeqFw_Di_Shared_Api_Dto_Plugin_Desc_Replace
|
|
31
|
-
*/
|
|
32
|
-
export class Factory {
|
|
33
|
-
constructor() {
|
|
34
|
-
/**
|
|
35
|
-
* @param {TeqFw_Di_Shared_Api_Dto_Plugin_Desc_Replace|null} data
|
|
36
|
-
* @return {TeqFw_Di_Shared_Api_Dto_Plugin_Desc_Replace}
|
|
37
|
-
*/
|
|
38
|
-
this.create = function (data = null) {
|
|
39
|
-
const res = new TeqFw_Di_Shared_Api_Dto_Plugin_Desc_Replace();
|
|
40
|
-
res.ns = data?.ns;
|
|
41
|
-
res.area = ((data?.area === AREA.BACK) || (data?.area === AREA.FRONT))
|
|
42
|
-
? data.area : AREA.SHARED;
|
|
43
|
-
return res;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// freeze DTO class to deny attributes changes and pin namespace
|
|
49
|
-
Object.freeze(TeqFw_Di_Shared_Api_Dto_Plugin_Desc_Replace);
|
|
50
|
-
Object.defineProperty(Factory, 'name', {value: `${NS}.${Factory.constructor.name}`});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enumeration for application areas.
|
|
3
|
-
*/
|
|
4
|
-
const TeqFw_Di_Shared_Api_Enum_Area = {
|
|
5
|
-
BACK: 'back', // nodejs compatible 'import' is allowed
|
|
6
|
-
FRONT: 'front', // browser compatible 'import' is allowed
|
|
7
|
-
SHARED: 'shared', // relative 'import' only is allowed
|
|
8
|
-
}
|
|
9
|
-
Object.freeze(TeqFw_Di_Shared_Api_Enum_Area);
|
|
10
|
-
export default TeqFw_Di_Shared_Api_Enum_Area;
|