composed-di 0.2.8-ts4 → 0.2.9
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/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -21
- package/dist/index.js.map +1 -1
- package/dist/serviceFactory.d.ts +35 -35
- package/dist/serviceFactory.d.ts.map +1 -1
- package/dist/serviceFactory.js +53 -53
- package/dist/serviceFactory.js.map +1 -1
- package/dist/serviceKey.d.ts +6 -6
- package/dist/serviceKey.d.ts.map +1 -1
- package/dist/serviceKey.js +12 -12
- package/dist/serviceKey.js.map +1 -1
- package/dist/serviceModule.d.ts +33 -33
- package/dist/serviceModule.d.ts.map +1 -1
- package/dist/serviceModule.js +103 -103
- package/dist/serviceModule.js.map +1 -1
- package/dist/{ServiceScope.d.ts → serviceScope.d.ts} +6 -6
- package/dist/serviceScope.d.ts.map +1 -0
- package/dist/{ServiceScope.js → serviceScope.js} +11 -11
- package/dist/serviceScope.js.map +1 -0
- package/dist/utils.d.ts +33 -33
- package/dist/utils.js +114 -115
- package/dist/utils.js.map +1 -1
- package/package.json +3 -2
- package/src/index.ts +5 -5
- package/src/{ServiceFactory.ts → serviceFactory.ts} +83 -83
- package/src/{ServiceModule.ts → serviceModule.ts} +123 -123
- package/src/{ServiceScope.ts → serviceScope.ts} +7 -7
- package/src/utils.ts +2 -2
- package/dist/ServiceScope.d.ts.map +0 -1
- package/dist/ServiceScope.js.map +0 -1
- /package/src/{ServiceKey.ts → serviceKey.ts} +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ServiceScope = void 0;
|
|
4
|
-
class ServiceScope {
|
|
5
|
-
constructor(name) {
|
|
6
|
-
this.name = name;
|
|
7
|
-
this.symbol = Symbol(name);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
exports.ServiceScope = ServiceScope;
|
|
11
|
-
//# sourceMappingURL=
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServiceScope = void 0;
|
|
4
|
+
class ServiceScope {
|
|
5
|
+
constructor(name) {
|
|
6
|
+
this.name = name;
|
|
7
|
+
this.symbol = Symbol(name);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.ServiceScope = ServiceScope;
|
|
11
|
+
//# sourceMappingURL=serviceScope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serviceScope.js","sourceRoot":"","sources":["../src/serviceScope.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAY;IAGvB,YAAqB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;CACF;AAND,oCAMC"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { ServiceModule } from './
|
|
2
|
-
export interface DotGraphOptions {
|
|
3
|
-
/** Graph direction: 'TB' (top-bottom), 'LR' (left-right), 'BT' (bottom-top), 'RL' (right-left) */
|
|
4
|
-
direction?: 'TB' | 'LR' | 'BT' | 'RL';
|
|
5
|
-
/** Title for the graph */
|
|
6
|
-
title?: string;
|
|
7
|
-
/** Show nodes with no dependencies in a different color */
|
|
8
|
-
highlightLeaves?: boolean;
|
|
9
|
-
/** Show nodes with no dependents in a different color */
|
|
10
|
-
highlightRoots?: boolean;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Generates a DOT notation graph from a ServiceModule.
|
|
14
|
-
* The output can be visualized using Graphviz tools or online viewers like:
|
|
15
|
-
* - https://dreampuf.github.io/GraphvizOnline/
|
|
16
|
-
* - https://edotor.net/
|
|
17
|
-
*
|
|
18
|
-
* Arrows point from dependencies to dependents (from what is needed to what needs it).
|
|
19
|
-
*
|
|
20
|
-
* @param {ServiceModule} module - The ServiceModule to convert to DOT notation
|
|
21
|
-
* @param {DotGraphOptions} options - Optional configuration for the graph appearance
|
|
22
|
-
* @returns {string} A string containing the DOT notation graph
|
|
23
|
-
*/
|
|
24
|
-
export declare function createDotGraph(module: ServiceModule, { direction, title, highlightLeaves, highlightRoots }?: DotGraphOptions): string;
|
|
25
|
-
/**
|
|
26
|
-
* Prints a DOT representation of a service module graph to the console.
|
|
27
|
-
* The output can be used to visualize the graph using online graph visualization tools.
|
|
28
|
-
*
|
|
29
|
-
* @param {ServiceModule} module - The service module representing the graph to be converted into DOT format.
|
|
30
|
-
* @param {DotGraphOptions} [options] - Optional configurations to customize the output of the DOT graph.
|
|
31
|
-
* @return {void} - This function does not return a value.
|
|
32
|
-
*/
|
|
33
|
-
export declare function printDotGraph(module: ServiceModule, options?: DotGraphOptions): void;
|
|
1
|
+
import { ServiceModule } from './serviceModule';
|
|
2
|
+
export interface DotGraphOptions {
|
|
3
|
+
/** Graph direction: 'TB' (top-bottom), 'LR' (left-right), 'BT' (bottom-top), 'RL' (right-left) */
|
|
4
|
+
direction?: 'TB' | 'LR' | 'BT' | 'RL';
|
|
5
|
+
/** Title for the graph */
|
|
6
|
+
title?: string;
|
|
7
|
+
/** Show nodes with no dependencies in a different color */
|
|
8
|
+
highlightLeaves?: boolean;
|
|
9
|
+
/** Show nodes with no dependents in a different color */
|
|
10
|
+
highlightRoots?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Generates a DOT notation graph from a ServiceModule.
|
|
14
|
+
* The output can be visualized using Graphviz tools or online viewers like:
|
|
15
|
+
* - https://dreampuf.github.io/GraphvizOnline/
|
|
16
|
+
* - https://edotor.net/
|
|
17
|
+
*
|
|
18
|
+
* Arrows point from dependencies to dependents (from what is needed to what needs it).
|
|
19
|
+
*
|
|
20
|
+
* @param {ServiceModule} module - The ServiceModule to convert to DOT notation
|
|
21
|
+
* @param {DotGraphOptions} options - Optional configuration for the graph appearance
|
|
22
|
+
* @returns {string} A string containing the DOT notation graph
|
|
23
|
+
*/
|
|
24
|
+
export declare function createDotGraph(module: ServiceModule, { direction, title, highlightLeaves, highlightRoots }?: DotGraphOptions): string;
|
|
25
|
+
/**
|
|
26
|
+
* Prints a DOT representation of a service module graph to the console.
|
|
27
|
+
* The output can be used to visualize the graph using online graph visualization tools.
|
|
28
|
+
*
|
|
29
|
+
* @param {ServiceModule} module - The service module representing the graph to be converted into DOT format.
|
|
30
|
+
* @param {DotGraphOptions} [options] - Optional configurations to customize the output of the DOT graph.
|
|
31
|
+
* @return {void} - This function does not return a value.
|
|
32
|
+
*/
|
|
33
|
+
export declare function printDotGraph(module: ServiceModule, options?: DotGraphOptions): void;
|
|
34
34
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.js
CHANGED
|
@@ -1,116 +1,115 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
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
|
-
|
|
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
|
-
}
|
|
115
|
-
exports.printDotGraph = printDotGraph;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDotGraph = createDotGraph;
|
|
4
|
+
exports.printDotGraph = printDotGraph;
|
|
5
|
+
/**
|
|
6
|
+
* Escapes special characters in strings for DOT notation
|
|
7
|
+
*/
|
|
8
|
+
function escapeDotString(str) {
|
|
9
|
+
return str.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n');
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Generates a DOT notation graph from a ServiceModule.
|
|
13
|
+
* The output can be visualized using Graphviz tools or online viewers like:
|
|
14
|
+
* - https://dreampuf.github.io/GraphvizOnline/
|
|
15
|
+
* - https://edotor.net/
|
|
16
|
+
*
|
|
17
|
+
* Arrows point from dependencies to dependents (from what is needed to what needs it).
|
|
18
|
+
*
|
|
19
|
+
* @param {ServiceModule} module - The ServiceModule to convert to DOT notation
|
|
20
|
+
* @param {DotGraphOptions} options - Optional configuration for the graph appearance
|
|
21
|
+
* @returns {string} A string containing the DOT notation graph
|
|
22
|
+
*/
|
|
23
|
+
function createDotGraph(module, { direction, title, highlightLeaves, highlightRoots } = {
|
|
24
|
+
direction: 'TB',
|
|
25
|
+
title: 'Service Dependency Graph',
|
|
26
|
+
highlightLeaves: true,
|
|
27
|
+
highlightRoots: true,
|
|
28
|
+
}) {
|
|
29
|
+
const factories = module.factories;
|
|
30
|
+
const lines = [];
|
|
31
|
+
// Start the digraph
|
|
32
|
+
lines.push('digraph ServiceDependencies {');
|
|
33
|
+
lines.push(` label="${title}";`);
|
|
34
|
+
lines.push(' labelloc="t";');
|
|
35
|
+
lines.push(' fontsize=16;');
|
|
36
|
+
lines.push(` rankdir=${direction};`);
|
|
37
|
+
lines.push('');
|
|
38
|
+
// Default node styling
|
|
39
|
+
lines.push(' node [');
|
|
40
|
+
lines.push(' shape=box,');
|
|
41
|
+
lines.push(' style="rounded,filled",');
|
|
42
|
+
lines.push(' fillcolor="#e1f5ff",');
|
|
43
|
+
lines.push(' color="#0288d1",');
|
|
44
|
+
lines.push(' fontname="Arial",');
|
|
45
|
+
lines.push(' fontsize=12');
|
|
46
|
+
lines.push(' ];');
|
|
47
|
+
lines.push('');
|
|
48
|
+
// Default edge styling
|
|
49
|
+
lines.push(' edge [');
|
|
50
|
+
lines.push(' color="#666666",');
|
|
51
|
+
lines.push(' arrowsize=0.8');
|
|
52
|
+
lines.push(' ];');
|
|
53
|
+
lines.push('');
|
|
54
|
+
// Build dependency maps to identify leaves and roots
|
|
55
|
+
const hasDependencies = new Set();
|
|
56
|
+
const hasDependents = new Set();
|
|
57
|
+
factories.forEach((factory) => {
|
|
58
|
+
const serviceName = factory.provides.name;
|
|
59
|
+
if (factory.dependsOn.length > 0) {
|
|
60
|
+
hasDependencies.add(serviceName);
|
|
61
|
+
}
|
|
62
|
+
factory.dependsOn.forEach((dependency) => {
|
|
63
|
+
hasDependents.add(dependency.name);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
// Define nodes with special styling for leaves and roots
|
|
67
|
+
const nodeIds = new Map();
|
|
68
|
+
let nodeCounter = 0;
|
|
69
|
+
factories.forEach((factory) => {
|
|
70
|
+
const serviceName = factory.provides.name;
|
|
71
|
+
const nodeId = `node${nodeCounter++}`;
|
|
72
|
+
nodeIds.set(serviceName, nodeId);
|
|
73
|
+
const isLeaf = !hasDependencies.has(serviceName);
|
|
74
|
+
const isRoot = !hasDependents.has(serviceName);
|
|
75
|
+
let nodeStyle = '';
|
|
76
|
+
if (highlightLeaves && isLeaf) {
|
|
77
|
+
nodeStyle = ' [fillcolor="#c8e6c9", color="#388e3c"]';
|
|
78
|
+
}
|
|
79
|
+
else if (highlightRoots && isRoot) {
|
|
80
|
+
nodeStyle = ' [fillcolor="#ffccbc", color="#d84315"]';
|
|
81
|
+
}
|
|
82
|
+
lines.push(` ${nodeId} [label="${escapeDotString(serviceName)}"]${nodeStyle};`);
|
|
83
|
+
});
|
|
84
|
+
lines.push('');
|
|
85
|
+
// Define edges (dependencies)
|
|
86
|
+
factories.forEach((factory) => {
|
|
87
|
+
const serviceName = factory.provides.name;
|
|
88
|
+
const serviceNodeId = nodeIds.get(serviceName);
|
|
89
|
+
factory.dependsOn.forEach((dependency) => {
|
|
90
|
+
const depName = dependency.name;
|
|
91
|
+
const depNodeId = nodeIds.get(depName);
|
|
92
|
+
if (depNodeId) {
|
|
93
|
+
// Arrow points from dependent to dependency (what needs it -> what provides it)
|
|
94
|
+
lines.push(` ${serviceNodeId} -> ${depNodeId};`);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
// Close the digraph
|
|
99
|
+
lines.push('}');
|
|
100
|
+
return lines.join('\n');
|
|
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
|
+
}
|
|
116
115
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AAiCA,wCAqGC;AAUD,sCAOC;AAzID;;GAEG;AACH,SAAS,eAAe,CAAC,GAAW;IAClC,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAA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AC,kDAAkD,CAAC,CAAC;IAChE,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;AAC5D,CAAC"}
|
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.9",
|
|
5
5
|
"author": "Juan Herrera juanhr454@gmail.com",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -29,12 +29,13 @@
|
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "tsc --build",
|
|
32
|
+
"clean": "tsc --build --clean",
|
|
32
33
|
"prepublishOnly": "npm run build"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@tsconfig/recommended": "^1.0.10",
|
|
36
37
|
"@types/node": "24.0.10",
|
|
37
38
|
"prettier": "^3.3.1",
|
|
38
|
-
"typescript": "
|
|
39
|
+
"typescript": "^5.2.2"
|
|
39
40
|
}
|
|
40
41
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './utils'
|
|
1
|
+
export * from './serviceKey';
|
|
2
|
+
export * from './serviceModule';
|
|
3
|
+
export * from './serviceFactory';
|
|
4
|
+
export * from './serviceScope';
|
|
5
|
+
export * from './utils';
|
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
import { ServiceKey } from './
|
|
2
|
-
import { ServiceScope } from './
|
|
3
|
-
|
|
4
|
-
// Helper types to extract the type from ServiceKey
|
|
5
|
-
type ServiceType<T> = T extends ServiceKey<infer U> ? U : never;
|
|
6
|
-
|
|
7
|
-
// Helper types to convert an array/tuple of ServiceKey to tuple of their types
|
|
8
|
-
type DependencyTypes<T extends readonly ServiceKey<unknown>[]> = {
|
|
9
|
-
[K in keyof T]: ServiceType<T[K]>;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export abstract class ServiceFactory<
|
|
13
|
-
T,
|
|
14
|
-
D extends readonly ServiceKey<unknown>[] = [],
|
|
15
|
-
> {
|
|
16
|
-
abstract provides: ServiceKey<T>;
|
|
17
|
-
abstract dependsOn: D;
|
|
18
|
-
abstract scope?: ServiceScope;
|
|
19
|
-
abstract initialize: (...dependencies: DependencyTypes<D>) => T | Promise<T>;
|
|
20
|
-
abstract dispose?: () => void;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Creates a singleton service factory that ensures a single instance of the provided service is initialized
|
|
24
|
-
* and used throughout the scope lifecycle.
|
|
25
|
-
*/
|
|
26
|
-
static singleton<
|
|
27
|
-
T,
|
|
28
|
-
D extends readonly ServiceKey<unknown>[] = [],
|
|
29
|
-
>({
|
|
30
|
-
scope,
|
|
31
|
-
provides,
|
|
32
|
-
dependsOn = [] as unknown as D,
|
|
33
|
-
initialize,
|
|
34
|
-
dispose = () => {},
|
|
35
|
-
}: {
|
|
36
|
-
scope?: ServiceScope;
|
|
37
|
-
provides: ServiceKey<T>;
|
|
38
|
-
dependsOn?: D;
|
|
39
|
-
initialize: (...dependencies: DependencyTypes<D>) => T | Promise<T>;
|
|
40
|
-
dispose?: (instance: T) => void;
|
|
41
|
-
}): ServiceFactory<T, D> {
|
|
42
|
-
let instance: T | undefined;
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
scope,
|
|
46
|
-
provides,
|
|
47
|
-
dependsOn,
|
|
48
|
-
async initialize(...dependencies: DependencyTypes<D>): Promise<T> {
|
|
49
|
-
if (instance === undefined) {
|
|
50
|
-
instance = await initialize(...dependencies);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return instance;
|
|
54
|
-
},
|
|
55
|
-
dispose(): void {
|
|
56
|
-
if (instance !== undefined) {
|
|
57
|
-
dispose(instance);
|
|
58
|
-
instance = undefined;
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Creates a one-shot service factory that initializes a new instance of the provided service
|
|
66
|
-
* every time it is requested.
|
|
67
|
-
*/
|
|
68
|
-
static oneShot<T, D extends readonly ServiceKey<unknown>[] = []>({
|
|
69
|
-
provides,
|
|
70
|
-
dependsOn,
|
|
71
|
-
initialize,
|
|
72
|
-
}: {
|
|
73
|
-
provides: ServiceKey<T>;
|
|
74
|
-
dependsOn: D;
|
|
75
|
-
initialize: (...dependencies: DependencyTypes<D>) => T | Promise<T>;
|
|
76
|
-
}): ServiceFactory<T, D> {
|
|
77
|
-
return {
|
|
78
|
-
provides,
|
|
79
|
-
dependsOn,
|
|
80
|
-
initialize,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
}
|
|
1
|
+
import { ServiceKey } from './serviceKey';
|
|
2
|
+
import { ServiceScope } from './serviceScope';
|
|
3
|
+
|
|
4
|
+
// Helper types to extract the type from ServiceKey
|
|
5
|
+
type ServiceType<T> = T extends ServiceKey<infer U> ? U : never;
|
|
6
|
+
|
|
7
|
+
// Helper types to convert an array/tuple of ServiceKey to tuple of their types
|
|
8
|
+
type DependencyTypes<T extends readonly ServiceKey<unknown>[]> = {
|
|
9
|
+
[K in keyof T]: ServiceType<T[K]>;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export abstract class ServiceFactory<
|
|
13
|
+
const T,
|
|
14
|
+
const D extends readonly ServiceKey<unknown>[] = [],
|
|
15
|
+
> {
|
|
16
|
+
abstract provides: ServiceKey<T>;
|
|
17
|
+
abstract dependsOn: D;
|
|
18
|
+
abstract scope?: ServiceScope;
|
|
19
|
+
abstract initialize: (...dependencies: DependencyTypes<D>) => T | Promise<T>;
|
|
20
|
+
abstract dispose?: () => void;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Creates a singleton service factory that ensures a single instance of the provided service is initialized
|
|
24
|
+
* and used throughout the scope lifecycle.
|
|
25
|
+
*/
|
|
26
|
+
static singleton<
|
|
27
|
+
const T,
|
|
28
|
+
const D extends readonly ServiceKey<unknown>[] = [],
|
|
29
|
+
>({
|
|
30
|
+
scope,
|
|
31
|
+
provides,
|
|
32
|
+
dependsOn = [] as unknown as D,
|
|
33
|
+
initialize,
|
|
34
|
+
dispose = () => {},
|
|
35
|
+
}: {
|
|
36
|
+
scope?: ServiceScope;
|
|
37
|
+
provides: ServiceKey<T>;
|
|
38
|
+
dependsOn?: D;
|
|
39
|
+
initialize: (...dependencies: DependencyTypes<D>) => T | Promise<T>;
|
|
40
|
+
dispose?: (instance: T) => void;
|
|
41
|
+
}): ServiceFactory<T, D> {
|
|
42
|
+
let instance: T | undefined;
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
scope,
|
|
46
|
+
provides,
|
|
47
|
+
dependsOn,
|
|
48
|
+
async initialize(...dependencies: DependencyTypes<D>): Promise<T> {
|
|
49
|
+
if (instance === undefined) {
|
|
50
|
+
instance = await initialize(...dependencies);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return instance;
|
|
54
|
+
},
|
|
55
|
+
dispose(): void {
|
|
56
|
+
if (instance !== undefined) {
|
|
57
|
+
dispose(instance);
|
|
58
|
+
instance = undefined;
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Creates a one-shot service factory that initializes a new instance of the provided service
|
|
66
|
+
* every time it is requested.
|
|
67
|
+
*/
|
|
68
|
+
static oneShot<const T, const D extends readonly ServiceKey<unknown>[] = []>({
|
|
69
|
+
provides,
|
|
70
|
+
dependsOn,
|
|
71
|
+
initialize,
|
|
72
|
+
}: {
|
|
73
|
+
provides: ServiceKey<T>;
|
|
74
|
+
dependsOn: D;
|
|
75
|
+
initialize: (...dependencies: DependencyTypes<D>) => T | Promise<T>;
|
|
76
|
+
}): ServiceFactory<T, D> {
|
|
77
|
+
return {
|
|
78
|
+
provides,
|
|
79
|
+
dependsOn,
|
|
80
|
+
initialize,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|