@dws-std/registry 1.2.1 → 1.3.1
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 +10 -6
- package/dist/index.js +7 -7
- package/dist/registry.d.ts +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://github.com/Dominus-Web-Service/std/blob/main/packages/registry/logo-registry.png" alt="DWS Registry logo" width="200" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
1
5
|
# 🎯 DWS Registry
|
|
2
6
|
|
|
3
7
|
If you've ever copy-pasted a `getInstance()` pattern into yet another class, this package is for you.
|
|
@@ -42,11 +46,11 @@ Register your instances once at startup. They're available everywhere after that
|
|
|
42
46
|
import { Registry } from '@dws-std/registry';
|
|
43
47
|
|
|
44
48
|
class DatabaseConnection {
|
|
45
|
-
private
|
|
49
|
+
private isConnected: boolean = false;
|
|
46
50
|
|
|
47
51
|
public constructor() {
|
|
48
52
|
console.log('Database connection created');
|
|
49
|
-
this.
|
|
53
|
+
this.isConnected = true;
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
public query(sql: string): string[] {
|
|
@@ -56,12 +60,12 @@ class DatabaseConnection {
|
|
|
56
60
|
|
|
57
61
|
class ApiClient {
|
|
58
62
|
public constructor(
|
|
59
|
-
private readonly
|
|
60
|
-
private readonly
|
|
63
|
+
private readonly baseUrl: string,
|
|
64
|
+
private readonly apiKey: string
|
|
61
65
|
) {}
|
|
62
66
|
|
|
63
67
|
public get baseUrl(): string {
|
|
64
|
-
return this.
|
|
68
|
+
return this.baseUrl;
|
|
65
69
|
}
|
|
66
70
|
}
|
|
67
71
|
|
|
@@ -97,7 +101,7 @@ Registry.register('DatabaseConnection', new DatabaseConnection());
|
|
|
97
101
|
|
|
98
102
|
## 📚 API Reference
|
|
99
103
|
|
|
100
|
-
Full docs: [
|
|
104
|
+
Full docs: [https://dominus-web-service.github.io/std/](https://dominus-web-service.github.io/std/)
|
|
101
105
|
|
|
102
106
|
## ⚖️ License
|
|
103
107
|
|
package/dist/index.js
CHANGED
|
@@ -7,24 +7,24 @@ var REGISTRY_ERROR_KEYS = {
|
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
class Registry {
|
|
10
|
-
static
|
|
10
|
+
static registry = new Map;
|
|
11
11
|
static register(name, instance) {
|
|
12
|
-
if (this.
|
|
12
|
+
if (this.registry.has(name))
|
|
13
13
|
throw new Exception(`Instance already registered: ${name}`, {
|
|
14
14
|
key: REGISTRY_ERROR_KEYS.CLASS_INSTANCE_ALREADY_REGISTERED,
|
|
15
15
|
cause: name
|
|
16
16
|
});
|
|
17
|
-
this.
|
|
17
|
+
this.registry.set(name, instance);
|
|
18
18
|
}
|
|
19
19
|
static unregister(name) {
|
|
20
|
-
if (!this.
|
|
20
|
+
if (!this.registry.delete(name))
|
|
21
21
|
throw new Exception(`Instance not registered: ${name}`, {
|
|
22
22
|
key: REGISTRY_ERROR_KEYS.CLASS_INSTANCE_NOT_REGISTERED,
|
|
23
23
|
cause: name
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
static get(name) {
|
|
27
|
-
const instance = this.
|
|
27
|
+
const instance = this.registry.get(name);
|
|
28
28
|
if (!instance)
|
|
29
29
|
throw new Exception(`Instance not registered: ${name}`, {
|
|
30
30
|
key: REGISTRY_ERROR_KEYS.CLASS_INSTANCE_NOT_REGISTERED,
|
|
@@ -33,10 +33,10 @@ class Registry {
|
|
|
33
33
|
return instance;
|
|
34
34
|
}
|
|
35
35
|
static has(name) {
|
|
36
|
-
return this.
|
|
36
|
+
return this.registry.has(name);
|
|
37
37
|
}
|
|
38
38
|
static clear() {
|
|
39
|
-
this.
|
|
39
|
+
this.registry.clear();
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
export {
|
package/dist/registry.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dws-std/registry",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Centralized, type-safe registry for managing named instances.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -38,16 +38,16 @@
|
|
|
38
38
|
"test": "bun test --pass-with-no-tests --coverage"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@dws-std/error": "^2.
|
|
41
|
+
"@dws-std/error": "^2.3.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/bun": "^1.3.14",
|
|
45
|
-
"oxfmt": "0.
|
|
46
|
-
"oxlint": "1.
|
|
45
|
+
"oxfmt": "0.56.0",
|
|
46
|
+
"oxlint": "1.71.0",
|
|
47
47
|
"oxlint-tsgolint": "0.23.0",
|
|
48
48
|
"typescript": "^6.0.3"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@dws-std/error": "^2.
|
|
51
|
+
"@dws-std/error": "^2.3.1"
|
|
52
52
|
}
|
|
53
53
|
}
|