@grest-ts/locator 0.0.5
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/LICENSE +21 -0
- package/README.md +209 -0
- package/dist/src/GGLocator.d.ts +12 -0
- package/dist/src/GGLocator.d.ts.map +1 -0
- package/dist/src/GGLocator.js +35 -0
- package/dist/src/GGLocator.js.map +1 -0
- package/dist/src/GGLocatorKey.d.ts +10 -0
- package/dist/src/GGLocatorKey.d.ts.map +1 -0
- package/dist/src/GGLocatorKey.js +23 -0
- package/dist/src/GGLocatorKey.js.map +1 -0
- package/dist/src/GGLocatorScope.d.ts +79 -0
- package/dist/src/GGLocatorScope.d.ts.map +1 -0
- package/dist/src/GGLocatorScope.js +160 -0
- package/dist/src/GGLocatorScope.js.map +1 -0
- package/dist/src/GGLocatorScopeDebug.d.ts +32 -0
- package/dist/src/GGLocatorScopeDebug.d.ts.map +1 -0
- package/dist/src/GGLocatorScopeDebug.js +116 -0
- package/dist/src/GGLocatorScopeDebug.js.map +1 -0
- package/dist/src/GGLocatorStorage.d.ts +5 -0
- package/dist/src/GGLocatorStorage.d.ts.map +1 -0
- package/dist/src/GGLocatorStorage.js +7 -0
- package/dist/src/GGLocatorStorage.js.map +1 -0
- package/dist/src/GG_ENV.d.ts +2 -0
- package/dist/src/GG_ENV.d.ts.map +1 -0
- package/dist/src/GG_ENV.js +2 -0
- package/dist/src/GG_ENV.js.map +1 -0
- package/dist/src/index-browser.d.ts +5 -0
- package/dist/src/index-browser.d.ts.map +1 -0
- package/dist/src/index-browser.js +4 -0
- package/dist/src/index-browser.js.map +1 -0
- package/dist/src/index-node.d.ts +5 -0
- package/dist/src/index-node.d.ts.map +1 -0
- package/dist/src/index-node.js +7 -0
- package/dist/src/index-node.js.map +1 -0
- package/dist/src/tsconfig.json +17 -0
- package/dist/tsconfig.publish.tsbuildinfo +1 -0
- package/package.json +55 -0
- package/src/GGLocator.ts +46 -0
- package/src/GGLocatorKey.ts +30 -0
- package/src/GGLocatorScope.ts +206 -0
- package/src/GGLocatorScopeDebug.ts +153 -0
- package/src/GGLocatorStorage.ts +9 -0
- package/src/GG_ENV.ts +0 -0
- package/src/index-browser.ts +4 -0
- package/src/index-node.ts +8 -0
- package/src/tsconfig.json +17 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Grest Games OÜ
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# Locator Package (@grest-ts/locator)
|
|
2
|
+
|
|
3
|
+
Service locator pattern implementation using AsyncLocalStorage for managing dependency injection in async contexts. Provides type-safe access to services throughout the request lifecycle without
|
|
4
|
+
explicit passing.
|
|
5
|
+
|
|
6
|
+
## When do you need it?
|
|
7
|
+
|
|
8
|
+
- **Framework level**: The framework uses GGLocator internally to provide access to services like logging, config, databases, etc.
|
|
9
|
+
- **Your services**: You can use it to avoid passing service dependencies through deep call stacks. Register once, access anywhere.
|
|
10
|
+
|
|
11
|
+
Note: GGLocator is for **services** (long-lived dependencies). For request-scoped data (requestId, auth, etc.), use `GGContext` instead.
|
|
12
|
+
|
|
13
|
+
## Basic Usage
|
|
14
|
+
|
|
15
|
+
### Defining a Service Key
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import {GGLocatorKey} from "@grest-ts/locator"
|
|
19
|
+
|
|
20
|
+
interface UserService {
|
|
21
|
+
getUser(id: string): Promise<User>
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const UserServiceKey = new GGLocatorKey<UserService>("UserService")
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Case study: Dependency injection (DI) in Services
|
|
28
|
+
|
|
29
|
+
Explicit, manually passing dependencies. This is what you probably would do for smaller services
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
class OrderService {
|
|
33
|
+
|
|
34
|
+
private readonly userService: UserService
|
|
35
|
+
private readonly paymentService: PaymentService
|
|
36
|
+
|
|
37
|
+
constructor(userService: UserService, paymentService: PaymentService) {
|
|
38
|
+
this.userService = userService
|
|
39
|
+
this.paymentService = paymentService
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async createOrder(userId: string, items: Item[]) {
|
|
43
|
+
const user = await this.userService.getUser(userId)
|
|
44
|
+
return this.paymentService.charge(user, items)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Using dependency injection via GGLocator keys. Use this when things start getting bigger and you really see value in this.
|
|
50
|
+
|
|
51
|
+
Pros: Less setup
|
|
52
|
+
|
|
53
|
+
Cons: Less visibility for dependencies.
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
class OrderService {
|
|
57
|
+
|
|
58
|
+
private readonly userService = UserServiceKey.get()
|
|
59
|
+
private readonly paymentService = PaymentServiceKey.get()
|
|
60
|
+
|
|
61
|
+
async createOrder(userId: string, items: Item[]) {
|
|
62
|
+
const user = await this.userService.getUser(userId)
|
|
63
|
+
return this.paymentService.charge(user, items)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
What NOT to do:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
class OrderService {
|
|
72
|
+
|
|
73
|
+
async createOrder(userId: string, items: Item[]) {
|
|
74
|
+
// VERY BAD: Keeps the dependency "hidden" and causes issues for your project in the future.
|
|
75
|
+
const user = await UserServiceKey.get().getUser(userId)
|
|
76
|
+
return PaymentServiceKey.get().charge(user, items)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
But when is direct access fine?
|
|
82
|
+
|
|
83
|
+
You can always define that some "service" is generic and accessible everywhere. This is for you to decide where you draw the line.
|
|
84
|
+
Passing Logging, metrics, tracing etc around everywhere can become very tedious, so it is easier to just use inline.
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
class OrderService {
|
|
88
|
+
|
|
89
|
+
async createOrder(userId: string, items: Item[]) {
|
|
90
|
+
// Important - all these next examples are still async context scoped.
|
|
91
|
+
GGLog.info(this, "Some log message") // Library itself provides quick access is usually a hint it is meant to be used like this.
|
|
92
|
+
MyMetrics.orders.increment("orders.created") // Metrics are usually defined globally and accessible everywhere.
|
|
93
|
+
const isEnabled = MyConfig.something.somewhere.get() // Config is usually defined globally and accessible everywhere.
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Registering and Accessing Services
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import {GGLocatorScope} from "@grest-ts/locator"
|
|
102
|
+
|
|
103
|
+
// You usually don't need to create the scope, but for the completeness of this example, we create it here.
|
|
104
|
+
new GGLocatorScope("something").run(async () => {
|
|
105
|
+
|
|
106
|
+
// Set the service
|
|
107
|
+
UserServiceKey.set(new UserServiceImpl())
|
|
108
|
+
|
|
109
|
+
// Set the service
|
|
110
|
+
UserServiceKey.overwrite(new UserServiceImpl())
|
|
111
|
+
|
|
112
|
+
// Access service anywhere in the call stack
|
|
113
|
+
const userService = UserServiceKey.get() // Throws if service is not set.
|
|
114
|
+
const user = await userService.getUser("123")
|
|
115
|
+
|
|
116
|
+
// Optionally get the service
|
|
117
|
+
const userServiceOpt = UserServiceKey.tryGet()
|
|
118
|
+
if (userServiceOpt) {
|
|
119
|
+
const user = await userServiceOpt.getUser("123")
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
})
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Using GGLocator Static Helpers
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import {GGLocator} from "@grest-ts/locator"
|
|
129
|
+
|
|
130
|
+
// Check if scope exists
|
|
131
|
+
if (GGLocator.hasScope()) {
|
|
132
|
+
const scope = GGLocator.getScope()
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Safe access (returns undefined if no scope)
|
|
136
|
+
const scope = GGLocator.tryGetScope()
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Debugging
|
|
140
|
+
|
|
141
|
+
To see what services are registered in the current scope:
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
const debugData = GGLocator.getScope().getScopeDebugFull();
|
|
145
|
+
console.log(debugData.toString()) // Nicer for console log for a quick peek.
|
|
146
|
+
console.log(debugData.toJSON()) // JSON format.
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
This prints the full scope tree with all registered services and their registration stacks - useful for understanding what's available in your current context.
|
|
150
|
+
|
|
151
|
+
## Scope Branching
|
|
152
|
+
|
|
153
|
+
Create child scopes that inherit parent services:
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
const rootScope = new GGLocatorScope("root")
|
|
157
|
+
rootScope.set(ConfigKey, config)
|
|
158
|
+
|
|
159
|
+
// Child scope inherits parent services
|
|
160
|
+
const requestScope = rootScope.branch("request")
|
|
161
|
+
requestScope.set(RequestContextKey, requestContext)
|
|
162
|
+
|
|
163
|
+
requestScope.run(() => {
|
|
164
|
+
ConfigKey.get() // Works - inherited from parent
|
|
165
|
+
RequestContextKey.get() // Works - set in this scope
|
|
166
|
+
})
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## GGLocatorKey Methods
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
const ServiceKey = new GGLocatorKey<MyService>("MyService")
|
|
173
|
+
|
|
174
|
+
// Get service (throws if not found)
|
|
175
|
+
const service = ServiceKey.get()
|
|
176
|
+
|
|
177
|
+
// Try get service (returns undefined if not found)
|
|
178
|
+
const service = ServiceKey.tryGet()
|
|
179
|
+
|
|
180
|
+
// Check if service exists
|
|
181
|
+
if (ServiceKey.has()) { ...
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Set service (throws if already set)
|
|
185
|
+
ServiceKey.set(new MyService())
|
|
186
|
+
|
|
187
|
+
// Overwrite service (allows replacing)
|
|
188
|
+
ServiceKey.overwrite(new MyService())
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Async Context Helpers
|
|
192
|
+
|
|
193
|
+
Wrap callbacks to preserve scope across async boundaries:
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
// Wrap function to run within current scope
|
|
197
|
+
const wrappedFn = GGLocator.wrapWithRun(myCallback)
|
|
198
|
+
|
|
199
|
+
// Schedule with scope preservation
|
|
200
|
+
GGLocator.setTimeout(() => {
|
|
201
|
+
// Scope is preserved here
|
|
202
|
+
ServiceKey.get()
|
|
203
|
+
}, 1000)
|
|
204
|
+
|
|
205
|
+
GGLocator.setInterval(() => { ...
|
|
206
|
+
}, 5000)
|
|
207
|
+
GGLocator.setImmediate(() => { ...
|
|
208
|
+
})
|
|
209
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { GGLocatorScope } from "./GGLocatorScope";
|
|
2
|
+
export declare class GGLocator {
|
|
3
|
+
static hasScope(): boolean;
|
|
4
|
+
static getScope(): GGLocatorScope;
|
|
5
|
+
static tryGetScope(): GGLocatorScope | undefined;
|
|
6
|
+
static wrapWithRun<T extends (...args: any[]) => any>(fn: T): T;
|
|
7
|
+
static wrapWithEnter<T extends (...args: any[]) => any>(fn: T): T;
|
|
8
|
+
static setImmediate<R>(fn: () => R): NodeJS.Immediate;
|
|
9
|
+
static setTimeout<R>(fn: () => R, timeout: number): NodeJS.Timeout;
|
|
10
|
+
static setInterval<R>(fn: () => R, timeout: number): NodeJS.Timeout;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=GGLocator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GGLocator.d.ts","sourceRoot":"","sources":["../../src/GGLocator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAGhD,qBAAa,SAAS;WAEJ,QAAQ,IAAI,OAAO;WAInB,QAAQ,IAAI,cAAc;WAQ1B,WAAW,IAAI,cAAc,GAAG,SAAS;WAQzC,WAAW,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC;WAIxD,aAAa,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC;WAI1D,YAAY,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,SAAS;WAI9C,UAAU,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,OAAO;WAI3D,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,OAAO;CAI7E"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { GG_ASYNC_STORAGE } from "./GGLocatorStorage.js";
|
|
2
|
+
export class GGLocator {
|
|
3
|
+
static hasScope() {
|
|
4
|
+
return GG_ASYNC_STORAGE.getStore() !== undefined;
|
|
5
|
+
}
|
|
6
|
+
static getScope() {
|
|
7
|
+
const level = GG_ASYNC_STORAGE.getStore();
|
|
8
|
+
if (!level) {
|
|
9
|
+
throw new Error(`No GGLocatorScope found! Make sure you have entered GGLocatorScope context.`);
|
|
10
|
+
}
|
|
11
|
+
return level;
|
|
12
|
+
}
|
|
13
|
+
static tryGetScope() {
|
|
14
|
+
return GG_ASYNC_STORAGE.getStore();
|
|
15
|
+
}
|
|
16
|
+
// ----------------------------------------------------
|
|
17
|
+
// Helper functions to make life easier :)
|
|
18
|
+
// ----------------------------------------------------
|
|
19
|
+
static wrapWithRun(fn) {
|
|
20
|
+
return this.getScope().wrapWithRun(fn);
|
|
21
|
+
}
|
|
22
|
+
static wrapWithEnter(fn) {
|
|
23
|
+
return this.getScope().wrapWithEnter(fn);
|
|
24
|
+
}
|
|
25
|
+
static setImmediate(fn) {
|
|
26
|
+
return this.getScope().setImmediate(fn);
|
|
27
|
+
}
|
|
28
|
+
static setTimeout(fn, timeout) {
|
|
29
|
+
return this.getScope().setTimeout(fn, timeout);
|
|
30
|
+
}
|
|
31
|
+
static setInterval(fn, timeout) {
|
|
32
|
+
return this.getScope().setInterval(fn, timeout);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=GGLocator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GGLocator.js","sourceRoot":"","sources":["../../src/GGLocator.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,EAAC,MAAM,o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src/GGLocatorKey.ts"],"names":[],"mappings":"AAEA,qBAAa,YAAY,CAAC,CAAC;IAEvB,SAAgB,IAAI,EAAE,MAAM,CAAA;gBAET,IAAI,EAAE,MAAM;IAIxB,GAAG,IAAI,CAAC;IAIR,MAAM,IAAI,CAAC,GAAG,SAAS;IAIvB,GAAG,IAAI,OAAO;IAId,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAInB,SAAS,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;CAGnC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { GGLocator } from "./GGLocator.js";
|
|
2
|
+
export class GGLocatorKey {
|
|
3
|
+
name;
|
|
4
|
+
constructor(name) {
|
|
5
|
+
this.name = name;
|
|
6
|
+
}
|
|
7
|
+
get() {
|
|
8
|
+
return GGLocator.getScope().get(this);
|
|
9
|
+
}
|
|
10
|
+
tryGet() {
|
|
11
|
+
return GGLocator.tryGetScope()?.tryGet(this);
|
|
12
|
+
}
|
|
13
|
+
has() {
|
|
14
|
+
return !!GGLocator.tryGetScope()?.has(this);
|
|
15
|
+
}
|
|
16
|
+
set(value) {
|
|
17
|
+
GGLocator.getScope().set(this, value);
|
|
18
|
+
}
|
|
19
|
+
overwrite(value) {
|
|
20
|
+
GGLocator.getScope().overwrite(this, value);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=GGLocatorKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GGLocatorKey.js","sourceRoot":"","sources":["../../src/GGLocatorKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAEtC,MAAM,OAAO,YAAY;IAEL,IAAI,CAAQ;IAE5B,YAAmB,IAAY;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IACpB,CAAC;IAEM,GAAG;QACN,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAEM,MAAM;QACT,OAAO,SAAS,CAAC,WAAW,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACjD,CAAC;IAEM,GAAG;QACN,OAAO,CAAC,CAAC,SAAS,CAAC,WAAW,EAAE,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IAEM,GAAG,CAAC,KAAQ;QACf,SAAS,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC1C,CAAC;IAEM,SAAS,CAAC,KAAQ;QACrB,SAAS,CAAC,QAAQ,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAChD,CAAC;CACJ"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { GGLocatorKey } from "./GGLocatorKey";
|
|
2
|
+
import { GGLocatorScopeDebug, GGLocatorScopeDebugList } from "./GGLocatorScopeDebug";
|
|
3
|
+
type ConstructorOf<T> = new (...args: any[]) => T;
|
|
4
|
+
/**
|
|
5
|
+
* service-locator pattern for async context cases.
|
|
6
|
+
*/
|
|
7
|
+
export declare class GGLocatorScope {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly serviceName?: string;
|
|
10
|
+
private readonly parent;
|
|
11
|
+
private readonly values;
|
|
12
|
+
private readonly registrationStacks;
|
|
13
|
+
private readonly creationStack;
|
|
14
|
+
constructor(name: string, parent?: GGLocatorScope, serviceName?: string);
|
|
15
|
+
private _get;
|
|
16
|
+
get<T>(token: GGLocatorKey<T>): T;
|
|
17
|
+
tryGet<T>(token: GGLocatorKey<T>): T | undefined;
|
|
18
|
+
getByTokenName<T>(name: string, type: ConstructorOf<T>): T;
|
|
19
|
+
set<T>(token: GGLocatorKey<T>, value: T): void;
|
|
20
|
+
overwrite<T>(token: GGLocatorKey<T>, value: T): void;
|
|
21
|
+
has<T>(token: GGLocatorKey<T>): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Returns all registered key names in this scope.
|
|
24
|
+
* Used by testkit to report available services to test runner.
|
|
25
|
+
*/
|
|
26
|
+
getKeys(): string[];
|
|
27
|
+
private _lifecycleHandler?;
|
|
28
|
+
setLifecycleOwner(handler: (service: GGLocatorLifecycleCallbacks) => void | undefined): void;
|
|
29
|
+
setWithLifecycle<T>(token: GGLocatorKey<T>, value: T, lifecycle: GGLocatorLifecycleCallbacks): void;
|
|
30
|
+
setImmediate<R>(fn: () => R): NodeJS.Immediate;
|
|
31
|
+
setTimeout<R>(fn: () => R, timeout: number): NodeJS.Timeout;
|
|
32
|
+
setInterval<R>(fn: () => R, timeout: number): NodeJS.Timeout;
|
|
33
|
+
/**
|
|
34
|
+
* Wraps a function with a async context run() call. Safe for most cases.
|
|
35
|
+
* Consider wrapWithEnter in case you want same context for that function forever.
|
|
36
|
+
*/
|
|
37
|
+
wrapWithRun<T extends (...args: any[]) => any>(fn: T): T;
|
|
38
|
+
/**
|
|
39
|
+
* Wraps function to ensure this scope is active before each call.
|
|
40
|
+
* Unlike wrapWithRun, doesn't create a new async boundary - just ensures scope is entered.
|
|
41
|
+
* More performant for high-frequency event handlers where scope doesn't change.
|
|
42
|
+
*/
|
|
43
|
+
wrapWithEnter<T extends (...args: any[]) => any>(fn: T): T;
|
|
44
|
+
getScopeDebug(): GGLocatorScopeDebug;
|
|
45
|
+
getScopeDebugFull(list?: GGLocatorScopeDebugList): GGLocatorScopeDebugList;
|
|
46
|
+
branch(name: string, serviceName?: string): GGLocatorScope;
|
|
47
|
+
run<R>(fn: () => R): R;
|
|
48
|
+
enter(): this;
|
|
49
|
+
ensureEntered(): void;
|
|
50
|
+
reset(): void;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Service initialization order - determines the sequence in which services start and stop.
|
|
54
|
+
* Services with lower values start first and stop last (reverse order for teardown).
|
|
55
|
+
*
|
|
56
|
+
* Example startup order: CONFIG → DATABASE → HTTP → INTL → BUSINESS → PERIODIC_JOBS → SERVICE_DISCOVERY
|
|
57
|
+
*/
|
|
58
|
+
export declare enum GGLocatorServiceType {
|
|
59
|
+
CONFIG = 0,
|
|
60
|
+
DATABASE = 10,
|
|
61
|
+
HTTP = 20,
|
|
62
|
+
INTL = 25,
|
|
63
|
+
BUSINESS = 30,
|
|
64
|
+
PERIODIC_JOBS = 40,
|
|
65
|
+
SERVICE_DISCOVERY = 999
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Service lifecycle callbacks registered with GGServiceRegistry.
|
|
69
|
+
*
|
|
70
|
+
* Services register these during construction (in GGRuntime.compose) to participate
|
|
71
|
+
* in the runtime lifecycle - startup, teardown, and per-request context hooks.
|
|
72
|
+
*/
|
|
73
|
+
export interface GGLocatorLifecycleCallbacks {
|
|
74
|
+
type: GGLocatorServiceType;
|
|
75
|
+
start: () => any | Promise<any>;
|
|
76
|
+
teardown?: () => any | Promise<any>;
|
|
77
|
+
}
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=GGLocatorScope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GGLocatorScope.d.ts","sourceRoot":"","sources":["../../src/GGLocatorScope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EAAC,mBAAmB,EAAE,uBAAuB,EAAC,MAAM,uBAAuB,CAAC;AAEnF,KAAK,aAAa,CAAC,CAAC,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAElD;;GAEG;AACH,qBAAa,cAAc;IAEvB,SAAgB,IAAI,EAAE,MAAM,CAAA;IAC5B,SAAgB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4B;IACnD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IACzC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAuB;IAC1D,OAAO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EAAE,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,OAAO;IAInE;;;OAGG;IACI,WAAW,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC;IAQ/D;;;;OAIG;IACI,aAAa,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC;IAO1D,aAAa,IAAI,mBAAmB;IAQpC,iBAAiB,CAAC,IAAI,GAAE,uBAAuD,GAAG,uBAAuB;IAUzG,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,cAAc;IAI1D,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAItB,KAAK;IAKL,aAAa,IAAI,IAAI;IAOrB,KAAK,IAAI,IAAI;CAOvB;AAED;;;;;GAKG;AACH,oBAAY,oBAAoB;IAC5B,MAAM,IAAI;IACV,QAAQ,KAAK;IACb,IAAI,KAAK;IACT,IAAI,KAAK;IACT,QAAQ,KAAK;IACb,aAAa,KAAK;IAClB,iBAAiB,MAAM;CAC1B;AAED;;;;;GAKG;AACH,MAAM,WAAW,2BAA2B;IACxC,IAAI,EAAE,oBAAoB,CAAA;IAC1B,KAAK,EAAE,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;IAC/B,QAAQ,CAAC,EAAE,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;CACtC"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { GG_ASYNC_STORAGE } from "./GGLocatorStorage.js";
|
|
2
|
+
import { GGLocatorScopeDebug, GGLocatorScopeDebugList } from "./GGLocatorScopeDebug.js";
|
|
3
|
+
/**
|
|
4
|
+
* service-locator pattern for async context cases.
|
|
5
|
+
*/
|
|
6
|
+
export class GGLocatorScope {
|
|
7
|
+
name;
|
|
8
|
+
serviceName;
|
|
9
|
+
parent;
|
|
10
|
+
values;
|
|
11
|
+
registrationStacks;
|
|
12
|
+
creationStack;
|
|
13
|
+
constructor(name, parent, serviceName) {
|
|
14
|
+
this.name = name;
|
|
15
|
+
this.serviceName = serviceName ?? this.serviceName ?? "Unknown";
|
|
16
|
+
this.parent = parent;
|
|
17
|
+
this.values = new Map(this.parent?.values ?? []);
|
|
18
|
+
this.registrationStacks = new Map(this.parent?.registrationStacks ?? []);
|
|
19
|
+
this.creationStack = new Error().stack?.split("\n").splice(2) ?? [];
|
|
20
|
+
}
|
|
21
|
+
_get(name) {
|
|
22
|
+
const value = this.values.get(name);
|
|
23
|
+
if (value === undefined) {
|
|
24
|
+
throw new Error(`Service "${name}" not found in async context!\n` +
|
|
25
|
+
`Scope tree: ${this.getScopeDebug().toString()}`);
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
get(token) {
|
|
30
|
+
return this._get(token.name);
|
|
31
|
+
}
|
|
32
|
+
tryGet(token) {
|
|
33
|
+
return this.values.get(token.name);
|
|
34
|
+
}
|
|
35
|
+
getByTokenName(name, type) {
|
|
36
|
+
const value = this._get(name);
|
|
37
|
+
if (!(value instanceof type)) {
|
|
38
|
+
throw new Error("Service is not extending expected type! Expected '" + type?.name + "', but got '" + value?.constructor?.name + "' instead.");
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
set(token, value) {
|
|
43
|
+
if (this.values.has(token.name)) {
|
|
44
|
+
throw new Error(`Scope already has service "${token.name}"!`);
|
|
45
|
+
}
|
|
46
|
+
this.overwrite(token, value);
|
|
47
|
+
}
|
|
48
|
+
overwrite(token, value) {
|
|
49
|
+
this.values.set(token.name, value);
|
|
50
|
+
this.registrationStacks.set(token.name, new Error().stack.split("\n").splice(2));
|
|
51
|
+
}
|
|
52
|
+
has(token) {
|
|
53
|
+
return this.values.has(token.name);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Returns all registered key names in this scope.
|
|
57
|
+
* Used by testkit to report available services to test runner.
|
|
58
|
+
*/
|
|
59
|
+
getKeys() {
|
|
60
|
+
return Array.from(this.values.keys());
|
|
61
|
+
}
|
|
62
|
+
// -----------
|
|
63
|
+
_lifecycleHandler;
|
|
64
|
+
setLifecycleOwner(handler) {
|
|
65
|
+
this._lifecycleHandler = handler;
|
|
66
|
+
}
|
|
67
|
+
setWithLifecycle(token, value, lifecycle) {
|
|
68
|
+
if (!this._lifecycleHandler) {
|
|
69
|
+
throw new Error("No lifecycle handler - are you registering outside compose phase?");
|
|
70
|
+
}
|
|
71
|
+
this.set(token, value);
|
|
72
|
+
this._lifecycleHandler(lifecycle);
|
|
73
|
+
}
|
|
74
|
+
// -----------
|
|
75
|
+
setImmediate(fn) {
|
|
76
|
+
return setImmediate(() => this.run(fn));
|
|
77
|
+
}
|
|
78
|
+
setTimeout(fn, timeout) {
|
|
79
|
+
return setTimeout(() => this.run(fn), timeout);
|
|
80
|
+
}
|
|
81
|
+
setInterval(fn, timeout) {
|
|
82
|
+
return setInterval(() => this.run(fn), timeout);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Wraps a function with a async context run() call. Safe for most cases.
|
|
86
|
+
* Consider wrapWithEnter in case you want same context for that function forever.
|
|
87
|
+
*/
|
|
88
|
+
wrapWithRun(fn) {
|
|
89
|
+
return ((...args) => {
|
|
90
|
+
return this.run(() => {
|
|
91
|
+
return fn(...args);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Wraps function to ensure this scope is active before each call.
|
|
97
|
+
* Unlike wrapWithRun, doesn't create a new async boundary - just ensures scope is entered.
|
|
98
|
+
* More performant for high-frequency event handlers where scope doesn't change.
|
|
99
|
+
*/
|
|
100
|
+
wrapWithEnter(fn) {
|
|
101
|
+
return ((...args) => {
|
|
102
|
+
this.ensureEntered();
|
|
103
|
+
return fn(...args);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
getScopeDebug() {
|
|
107
|
+
const debug = new GGLocatorScopeDebug(this.name, this.creationStack);
|
|
108
|
+
this.values.forEach((value, name) => {
|
|
109
|
+
debug.add(name, value, this.registrationStacks.get(name));
|
|
110
|
+
});
|
|
111
|
+
return debug;
|
|
112
|
+
}
|
|
113
|
+
getScopeDebugFull(list = new GGLocatorScopeDebugList()) {
|
|
114
|
+
if (this.parent) {
|
|
115
|
+
this.parent.getScopeDebugFull(list);
|
|
116
|
+
}
|
|
117
|
+
list.add(this.getScopeDebug());
|
|
118
|
+
return list;
|
|
119
|
+
}
|
|
120
|
+
// -----------
|
|
121
|
+
branch(name, serviceName) {
|
|
122
|
+
return new GGLocatorScope(name, this, serviceName);
|
|
123
|
+
}
|
|
124
|
+
run(fn) {
|
|
125
|
+
return GG_ASYNC_STORAGE.run(this, fn);
|
|
126
|
+
}
|
|
127
|
+
enter() {
|
|
128
|
+
GG_ASYNC_STORAGE.enterWith(this);
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
ensureEntered() {
|
|
132
|
+
const store = GG_ASYNC_STORAGE.getStore();
|
|
133
|
+
if (store !== this) {
|
|
134
|
+
GG_ASYNC_STORAGE.enterWith(this);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
reset() {
|
|
138
|
+
this.values.clear();
|
|
139
|
+
this.parent.values.forEach((value, name) => this.values.set(name, value));
|
|
140
|
+
this.registrationStacks.clear();
|
|
141
|
+
this.parent.registrationStacks.forEach((value, name) => this.registrationStacks.set(name, value));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Service initialization order - determines the sequence in which services start and stop.
|
|
146
|
+
* Services with lower values start first and stop last (reverse order for teardown).
|
|
147
|
+
*
|
|
148
|
+
* Example startup order: CONFIG → DATABASE → HTTP → INTL → BUSINESS → PERIODIC_JOBS → SERVICE_DISCOVERY
|
|
149
|
+
*/
|
|
150
|
+
export var GGLocatorServiceType;
|
|
151
|
+
(function (GGLocatorServiceType) {
|
|
152
|
+
GGLocatorServiceType[GGLocatorServiceType["CONFIG"] = 0] = "CONFIG";
|
|
153
|
+
GGLocatorServiceType[GGLocatorServiceType["DATABASE"] = 10] = "DATABASE";
|
|
154
|
+
GGLocatorServiceType[GGLocatorServiceType["HTTP"] = 20] = "HTTP";
|
|
155
|
+
GGLocatorServiceType[GGLocatorServiceType["INTL"] = 25] = "INTL";
|
|
156
|
+
GGLocatorServiceType[GGLocatorServiceType["BUSINESS"] = 30] = "BUSINESS";
|
|
157
|
+
GGLocatorServiceType[GGLocatorServiceType["PERIODIC_JOBS"] = 40] = "PERIODIC_JOBS";
|
|
158
|
+
GGLocatorServiceType[GGLocatorServiceType["SERVICE_DISCOVERY"] = 999] = "SERVICE_DISCOVERY";
|
|
159
|
+
})(GGLocatorServiceType || (GGLocatorServiceType = {}));
|
|
160
|
+
//# sourceMappingURL=GGLocatorScope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GGLocatorScope.js","sourceRoot":"","sources":["../../src/GGLocatorScope.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,mBAAmB,EAAE,uBAAuB,EAAC,MAAM,uBAAuB,CAAC;AAInF;;GAEG;AACH,MAAM,OAAO,cAAc;IAEP,IAAI,CAAQ;IACZ,WAAW,CAAS;IACnB,MAAM,CAA4B;IAClC,MAAM,CAAkB;IACxB,kBAAkB,CAAuB;IACzC,aAAa,CAAU;IAExC,YAAY,IAAY,EAAE,MAAuB,EAAE,WAAoB;QACnE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,WAAW,GAAG,WAAW,IAAI,IAAI,CAAC,WAAW,IAAI,SAAS,CAAC;QAChE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QAC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CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAA;IACrG,CAAC;CAEJ;AAED;;;;;GAKG;AACH,MAAM,CAAN,IAAY,oBAQX;AARD,WAAY,oBAAoB;IAC5B,mEAAU,CAAA;IACV,wEAAa,CAAA;IACb,gEAAS,CAAA;IACT,gEAAS,CAAA;IACT,wEAAa,CAAA;IACb,kFAAkB,CAAA;IAClB,2FAAuB,CAAA;AAC3B,CAAC,EARW,oBAAoB,KAApB,oBAAoB,QAQ/B"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface GGLocatorDebugService {
|
|
2
|
+
key: string;
|
|
3
|
+
className: string | undefined;
|
|
4
|
+
stack: string[];
|
|
5
|
+
composeLine: string | undefined;
|
|
6
|
+
}
|
|
7
|
+
export interface GGLocatorRawServiceData {
|
|
8
|
+
key: string;
|
|
9
|
+
value: any;
|
|
10
|
+
rawStack: string[];
|
|
11
|
+
}
|
|
12
|
+
export declare class GGLocatorScopeDebugList {
|
|
13
|
+
readonly scopes: GGLocatorScopeDebug[];
|
|
14
|
+
add(tree: GGLocatorScopeDebug): void;
|
|
15
|
+
toString(color?: boolean): string;
|
|
16
|
+
toJSON(): object;
|
|
17
|
+
}
|
|
18
|
+
export declare class GGLocatorScopeDebug {
|
|
19
|
+
readonly scopeName: string;
|
|
20
|
+
readonly creationStack: string[];
|
|
21
|
+
readonly services: GGLocatorDebugService[];
|
|
22
|
+
constructor(scopeName: string, rawCreationStack: string[]);
|
|
23
|
+
private processCreationStack;
|
|
24
|
+
add(key: string, value: any, rawStack: string[] | undefined): void;
|
|
25
|
+
private processService;
|
|
26
|
+
private normalizeStackLine;
|
|
27
|
+
private findComposeLine;
|
|
28
|
+
private normalizePathToFileUrl;
|
|
29
|
+
toString(color?: boolean): string;
|
|
30
|
+
toJSON(): object;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=GGLocatorScopeDebug.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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