composed-di 0.2.6 → 0.2.8-ts4
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 +1 -1
- package/dist/ServiceScope.d.ts +5 -5
- package/dist/ServiceScope.js +10 -10
- package/dist/index.d.ts +5 -5
- package/dist/index.js +21 -21
- package/dist/plugin/index.d.ts +66 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +397 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/serviceFactory.d.ts +34 -34
- package/dist/serviceFactory.d.ts.map +1 -1
- package/dist/serviceFactory.js +52 -52
- package/dist/serviceFactory.js.map +1 -1
- package/dist/serviceKey.d.ts +5 -5
- package/dist/serviceKey.js +11 -11
- package/dist/serviceModule.d.ts +32 -32
- package/dist/serviceModule.d.ts.map +1 -1
- package/dist/serviceModule.js +102 -102
- package/dist/serviceModule.js.map +1 -1
- package/dist/utils.d.ts +33 -33
- package/dist/utils.js +115 -114
- package/dist/utils.js.map +1 -1
- package/package.json +5 -4
- package/src/ServiceFactory.ts +5 -5
- package/src/ServiceModule.ts +2 -2
package/dist/utils.js
CHANGED
|
@@ -1,115 +1,116 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createDotGraph =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* - https://
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @param {
|
|
20
|
-
* @
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
lines.push(
|
|
33
|
-
lines.push(
|
|
34
|
-
lines.push('
|
|
35
|
-
lines.push(
|
|
36
|
-
lines.push(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
lines.push('
|
|
40
|
-
lines.push('
|
|
41
|
-
lines.push('
|
|
42
|
-
lines.push('
|
|
43
|
-
lines.push('
|
|
44
|
-
lines.push('
|
|
45
|
-
lines.push('
|
|
46
|
-
lines.push('
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
lines.push('
|
|
50
|
-
lines.push('
|
|
51
|
-
lines.push('
|
|
52
|
-
lines.push('
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
lines.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Prints a DOT representation of a service module graph to the console.
|
|
104
|
-
* The output can be used to visualize the graph using online graph visualization tools.
|
|
105
|
-
*
|
|
106
|
-
* @param {ServiceModule} module - The service module representing the graph to be converted into DOT format.
|
|
107
|
-
* @param {DotGraphOptions} [options] - Optional configurations to customize the output of the DOT graph.
|
|
108
|
-
* @return {void} - This function does not return a value.
|
|
109
|
-
*/
|
|
110
|
-
function printDotGraph(module, options) {
|
|
111
|
-
console.log(createDotGraph(module, options));
|
|
112
|
-
console.log('\n\nCopy the DOT output above and paste it into:');
|
|
113
|
-
console.log('https://dreampuf.github.io/GraphvizOnline/');
|
|
114
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printDotGraph = exports.createDotGraph = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Escapes special characters in strings for DOT notation
|
|
6
|
+
*/
|
|
7
|
+
function escapeDotString(str) {
|
|
8
|
+
return str.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n');
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Generates a DOT notation graph from a ServiceModule.
|
|
12
|
+
* The output can be visualized using Graphviz tools or online viewers like:
|
|
13
|
+
* - https://dreampuf.github.io/GraphvizOnline/
|
|
14
|
+
* - https://edotor.net/
|
|
15
|
+
*
|
|
16
|
+
* Arrows point from dependencies to dependents (from what is needed to what needs it).
|
|
17
|
+
*
|
|
18
|
+
* @param {ServiceModule} module - The ServiceModule to convert to DOT notation
|
|
19
|
+
* @param {DotGraphOptions} options - Optional configuration for the graph appearance
|
|
20
|
+
* @returns {string} A string containing the DOT notation graph
|
|
21
|
+
*/
|
|
22
|
+
function createDotGraph(module, { direction, title, highlightLeaves, highlightRoots } = {
|
|
23
|
+
direction: 'TB',
|
|
24
|
+
title: 'Service Dependency Graph',
|
|
25
|
+
highlightLeaves: true,
|
|
26
|
+
highlightRoots: true,
|
|
27
|
+
}) {
|
|
28
|
+
const factories = module.factories;
|
|
29
|
+
const lines = [];
|
|
30
|
+
// Start the digraph
|
|
31
|
+
lines.push('digraph ServiceDependencies {');
|
|
32
|
+
lines.push(` label="${title}";`);
|
|
33
|
+
lines.push(' labelloc="t";');
|
|
34
|
+
lines.push(' fontsize=16;');
|
|
35
|
+
lines.push(` rankdir=${direction};`);
|
|
36
|
+
lines.push('');
|
|
37
|
+
// Default node styling
|
|
38
|
+
lines.push(' node [');
|
|
39
|
+
lines.push(' shape=box,');
|
|
40
|
+
lines.push(' style="rounded,filled",');
|
|
41
|
+
lines.push(' fillcolor="#e1f5ff",');
|
|
42
|
+
lines.push(' color="#0288d1",');
|
|
43
|
+
lines.push(' fontname="Arial",');
|
|
44
|
+
lines.push(' fontsize=12');
|
|
45
|
+
lines.push(' ];');
|
|
46
|
+
lines.push('');
|
|
47
|
+
// Default edge styling
|
|
48
|
+
lines.push(' edge [');
|
|
49
|
+
lines.push(' color="#666666",');
|
|
50
|
+
lines.push(' arrowsize=0.8');
|
|
51
|
+
lines.push(' ];');
|
|
52
|
+
lines.push('');
|
|
53
|
+
// Build dependency maps to identify leaves and roots
|
|
54
|
+
const hasDependencies = new Set();
|
|
55
|
+
const hasDependents = new Set();
|
|
56
|
+
factories.forEach((factory) => {
|
|
57
|
+
const serviceName = factory.provides.name;
|
|
58
|
+
if (factory.dependsOn.length > 0) {
|
|
59
|
+
hasDependencies.add(serviceName);
|
|
60
|
+
}
|
|
61
|
+
factory.dependsOn.forEach((dependency) => {
|
|
62
|
+
hasDependents.add(dependency.name);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
// Define nodes with special styling for leaves and roots
|
|
66
|
+
const nodeIds = new Map();
|
|
67
|
+
let nodeCounter = 0;
|
|
68
|
+
factories.forEach((factory) => {
|
|
69
|
+
const serviceName = factory.provides.name;
|
|
70
|
+
const nodeId = `node${nodeCounter++}`;
|
|
71
|
+
nodeIds.set(serviceName, nodeId);
|
|
72
|
+
const isLeaf = !hasDependencies.has(serviceName);
|
|
73
|
+
const isRoot = !hasDependents.has(serviceName);
|
|
74
|
+
let nodeStyle = '';
|
|
75
|
+
if (highlightLeaves && isLeaf) {
|
|
76
|
+
nodeStyle = ' [fillcolor="#c8e6c9", color="#388e3c"]';
|
|
77
|
+
}
|
|
78
|
+
else if (highlightRoots && isRoot) {
|
|
79
|
+
nodeStyle = ' [fillcolor="#ffccbc", color="#d84315"]';
|
|
80
|
+
}
|
|
81
|
+
lines.push(` ${nodeId} [label="${escapeDotString(serviceName)}"]${nodeStyle};`);
|
|
82
|
+
});
|
|
83
|
+
lines.push('');
|
|
84
|
+
// Define edges (dependencies)
|
|
85
|
+
factories.forEach((factory) => {
|
|
86
|
+
const serviceName = factory.provides.name;
|
|
87
|
+
const serviceNodeId = nodeIds.get(serviceName);
|
|
88
|
+
factory.dependsOn.forEach((dependency) => {
|
|
89
|
+
const depName = dependency.name;
|
|
90
|
+
const depNodeId = nodeIds.get(depName);
|
|
91
|
+
if (depNodeId) {
|
|
92
|
+
// Arrow points from dependent to dependency (what needs it -> what provides it)
|
|
93
|
+
lines.push(` ${serviceNodeId} -> ${depNodeId};`);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
// Close the digraph
|
|
98
|
+
lines.push('}');
|
|
99
|
+
return lines.join('\n');
|
|
100
|
+
}
|
|
101
|
+
exports.createDotGraph = createDotGraph;
|
|
102
|
+
/**
|
|
103
|
+
* Prints a DOT representation of a service module graph to the console.
|
|
104
|
+
* The output can be used to visualize the graph using online graph visualization tools.
|
|
105
|
+
*
|
|
106
|
+
* @param {ServiceModule} module - The service module representing the graph to be converted into DOT format.
|
|
107
|
+
* @param {DotGraphOptions} [options] - Optional configurations to customize the output of the DOT graph.
|
|
108
|
+
* @return {void} - This function does not return a value.
|
|
109
|
+
*/
|
|
110
|
+
function printDotGraph(module, options) {
|
|
111
|
+
console.log(createDotGraph(module, options));
|
|
112
|
+
console.log('\n\nCopy the DOT output above and paste it into:');
|
|
113
|
+
console.log('https://dreampuf.github.io/GraphvizOnline/');
|
|
114
|
+
}
|
|
115
|
+
exports.printDotGraph = printDotGraph;
|
|
115
116
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;
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qGC;AAED;;;;;;;GAOG;AACH,SAAgB,aAAa,CAC3B,MAAqB,EACrB,OAAyB;IAEzB,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC7C,OAAO,CAAC,GAAG,CAAC,kDAAkD,CAAC,CAAC;IAChE,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;AAC5D,CAAC;AAPD,sCAOC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "composed-di",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.8-ts4",
|
|
5
5
|
"author": "Juan Herrera juanhr454@gmail.com",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
|
-
"require": "./dist/index.js"
|
|
12
|
+
"require": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
13
14
|
}
|
|
14
15
|
},
|
|
15
16
|
"files": [
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
"license": "MIT",
|
|
25
26
|
"repository": {
|
|
26
27
|
"type": "git",
|
|
27
|
-
"url": "https://github.com/imherrera/composed-di"
|
|
28
|
+
"url": "git+https://github.com/imherrera/composed-di.git"
|
|
28
29
|
},
|
|
29
30
|
"scripts": {
|
|
30
31
|
"build": "tsc --build",
|
|
@@ -34,6 +35,6 @@
|
|
|
34
35
|
"@tsconfig/recommended": "^1.0.10",
|
|
35
36
|
"@types/node": "24.0.10",
|
|
36
37
|
"prettier": "^3.3.1",
|
|
37
|
-
"typescript": "
|
|
38
|
+
"typescript": "4.9.3"
|
|
38
39
|
}
|
|
39
40
|
}
|
package/src/ServiceFactory.ts
CHANGED
|
@@ -10,8 +10,8 @@ type DependencyTypes<T extends readonly ServiceKey<unknown>[]> = {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export abstract class ServiceFactory<
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
T,
|
|
14
|
+
D extends readonly ServiceKey<unknown>[] = [],
|
|
15
15
|
> {
|
|
16
16
|
abstract provides: ServiceKey<T>;
|
|
17
17
|
abstract dependsOn: D;
|
|
@@ -24,8 +24,8 @@ export abstract class ServiceFactory<
|
|
|
24
24
|
* and used throughout the scope lifecycle.
|
|
25
25
|
*/
|
|
26
26
|
static singleton<
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
T,
|
|
28
|
+
D extends readonly ServiceKey<unknown>[] = [],
|
|
29
29
|
>({
|
|
30
30
|
scope,
|
|
31
31
|
provides,
|
|
@@ -65,7 +65,7 @@ export abstract class ServiceFactory<
|
|
|
65
65
|
* Creates a one-shot service factory that initializes a new instance of the provided service
|
|
66
66
|
* every time it is requested.
|
|
67
67
|
*/
|
|
68
|
-
static oneShot<
|
|
68
|
+
static oneShot<T, D extends readonly ServiceKey<unknown>[] = []>({
|
|
69
69
|
provides,
|
|
70
70
|
dependsOn,
|
|
71
71
|
initialize,
|
package/src/ServiceModule.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { ServiceKey } from './ServiceKey';
|
|
|
2
2
|
import { ServiceFactory } from './ServiceFactory';
|
|
3
3
|
import { ServiceScope } from './ServiceScope';
|
|
4
4
|
|
|
5
|
-
type GenericFactory = ServiceFactory<
|
|
6
|
-
type GenericKey = ServiceKey<
|
|
5
|
+
type GenericFactory = ServiceFactory<any, readonly ServiceKey<any>[]>;
|
|
6
|
+
type GenericKey = ServiceKey<any>;
|
|
7
7
|
|
|
8
8
|
export class ServiceModule {
|
|
9
9
|
private constructor(readonly factories: GenericFactory[]) {
|