@vampgg/utils 1.0.0-beta.4 → 1.0.0-beta.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/dist/service-registry.d.mts +21 -0
- package/dist/service-registry.mjs +31 -0
- package/package.json +2 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TempoLogger } from "@tempojs/common";
|
|
2
|
+
import { BebopMethodAny, ServiceRegistry } from "@tempojs/server";
|
|
3
|
+
|
|
4
|
+
//#region src/service-registry.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* One router takes one registry, but a host can generate services across
|
|
7
|
+
* several packages (each with its own registry class). Method ids are
|
|
8
|
+
* service+method hashes (collision-free across services), so first-hit-wins
|
|
9
|
+
* lookup is safe. Generated `init()` is destructive (moves the
|
|
10
|
+
* decorator-registered singleton out of a static map), so it must run exactly
|
|
11
|
+
* once — the router constructor also calls `init()`.
|
|
12
|
+
*/
|
|
13
|
+
declare class CompositeServiceRegistry extends ServiceRegistry {
|
|
14
|
+
#private;
|
|
15
|
+
private readonly registries;
|
|
16
|
+
constructor(logger: TempoLogger, registries: readonly ServiceRegistry[]);
|
|
17
|
+
init(): void;
|
|
18
|
+
getMethod(methodId: number): BebopMethodAny | undefined;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { CompositeServiceRegistry };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ServiceRegistry } from "@tempojs/server";
|
|
2
|
+
//#region src/service-registry.ts
|
|
3
|
+
/**
|
|
4
|
+
* One router takes one registry, but a host can generate services across
|
|
5
|
+
* several packages (each with its own registry class). Method ids are
|
|
6
|
+
* service+method hashes (collision-free across services), so first-hit-wins
|
|
7
|
+
* lookup is safe. Generated `init()` is destructive (moves the
|
|
8
|
+
* decorator-registered singleton out of a static map), so it must run exactly
|
|
9
|
+
* once — the router constructor also calls `init()`.
|
|
10
|
+
*/
|
|
11
|
+
var CompositeServiceRegistry = class extends ServiceRegistry {
|
|
12
|
+
registries;
|
|
13
|
+
#initialized = false;
|
|
14
|
+
constructor(logger, registries) {
|
|
15
|
+
super(logger);
|
|
16
|
+
this.registries = registries;
|
|
17
|
+
}
|
|
18
|
+
init() {
|
|
19
|
+
if (this.#initialized) return;
|
|
20
|
+
this.#initialized = true;
|
|
21
|
+
for (const registry of this.registries) registry.init();
|
|
22
|
+
}
|
|
23
|
+
getMethod(methodId) {
|
|
24
|
+
for (const registry of this.registries) {
|
|
25
|
+
const method = registry.getMethod(methodId);
|
|
26
|
+
if (method) return method;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { CompositeServiceRegistry };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vampgg/utils",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.5",
|
|
4
4
|
"description": "Tempo RPC, Bebop serialization, transports, and async primitives for @vampgg.",
|
|
5
5
|
"homepage": "https://github.com/sammccord/vamp/tree/main/packages/utils#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"./extension-router": "./dist/extension-router.mjs",
|
|
30
30
|
"./pino-logger": "./dist/pino-logger.mjs",
|
|
31
31
|
"./router-core": "./dist/router-core.mjs",
|
|
32
|
+
"./service-registry": "./dist/service-registry.mjs",
|
|
32
33
|
"./worker-channel": "./dist/worker-channel.mjs",
|
|
33
34
|
"./worker-router": "./dist/worker-router.mjs",
|
|
34
35
|
"./ws-channel": "./dist/ws-channel.mjs",
|