@camstack/server 1.1.22 → 1.1.23
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.
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.createNodeCapAuthority = createNodeCapAuthority;
|
|
18
18
|
exports.createInProcessProviderLookup = createInProcessProviderLookup;
|
|
19
|
+
exports.createHubResidentProviderLookup = createHubResidentProviderLookup;
|
|
19
20
|
/**
|
|
20
21
|
* Build a NodeCapAuthority backed by a HubNodeRegistry.
|
|
21
22
|
*
|
|
@@ -107,16 +108,42 @@ function createInProcessProviderLookup(capabilityService) {
|
|
|
107
108
|
capabilityService.getSingleton(capName);
|
|
108
109
|
if (provider === null || provider === undefined)
|
|
109
110
|
return null;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
111
|
+
return buildProviderRef(capName, provider);
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* NODE-ACCURATE variant of {@link createInProcessProviderLookup}: resolves a
|
|
116
|
+
* provider ONLY when one is physically resident on the hub node
|
|
117
|
+
* (`getSingletonForNode(cap, 'hub')`) — no fallback to the cluster-elected
|
|
118
|
+
* ACTIVE singleton.
|
|
119
|
+
*
|
|
120
|
+
* Rationale: `getSingleton(cap)` returns the elected provider OBJECT, which
|
|
121
|
+
* for a remote election is a Moleculer-proxy registered in the hub registry.
|
|
122
|
+
* That fallback is correct for UNPINNED singleton dispatch (election
|
|
123
|
+
* adherence) but must never satisfy an explicit `nodePin('hub')` — the
|
|
124
|
+
* "hub-in-process" route would silently execute on another node (the shm
|
|
125
|
+
* frame-plane cross-node decoder-session storm: a `decoder` call pinned to
|
|
126
|
+
* the hub landed on a remote agent whenever the hub's decoder runner was
|
|
127
|
+
* circuit-broken). Wired into `CapRouteResolver.hubResidentProviders`.
|
|
128
|
+
*/
|
|
129
|
+
function createHubResidentProviderLookup(capabilityService) {
|
|
130
|
+
return (capName) => {
|
|
131
|
+
const provider = capabilityService.getSingletonForNode?.(capName, 'hub');
|
|
132
|
+
if (provider === null || provider === undefined)
|
|
133
|
+
return null;
|
|
134
|
+
return buildProviderRef(capName, provider);
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/** Shared cast-free InProcessProviderRef builder over a provider object. */
|
|
138
|
+
function buildProviderRef(capName, provider) {
|
|
139
|
+
return {
|
|
140
|
+
invoke: (method, args) => {
|
|
141
|
+
const fn = provider[method];
|
|
142
|
+
if (typeof fn !== 'function') {
|
|
143
|
+
return Promise.reject(new Error(`method "${method}" not found on cap "${capName}"`));
|
|
144
|
+
}
|
|
145
|
+
const result = fn.call(provider, args);
|
|
146
|
+
return Promise.resolve(result);
|
|
147
|
+
},
|
|
121
148
|
};
|
|
122
149
|
}
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MoleculerService = void 0;
|
|
4
4
|
exports.buildChildUdsManifest = buildChildUdsManifest;
|
|
5
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
6
|
const system_1 = require("@camstack/system");
|
|
7
|
+
const types_1 = require("@camstack/types");
|
|
6
8
|
const cap_router_runtime_js_1 = require("../../api/trpc/cap-router-runtime.js");
|
|
7
9
|
const cap_call_fn_js_1 = require("./cap-call-fn.js");
|
|
8
10
|
const cap_route_authority_js_1 = require("./cap-route-authority.js");
|
|
9
|
-
const types_1 = require("@camstack/types");
|
|
10
|
-
const node_crypto_1 = require("node:crypto");
|
|
11
11
|
class MoleculerService {
|
|
12
12
|
eventBus;
|
|
13
13
|
config;
|
|
@@ -411,6 +411,12 @@ class MoleculerService {
|
|
|
411
411
|
null,
|
|
412
412
|
}),
|
|
413
413
|
inProcessProviders: (0, cap_route_authority_js_1.createInProcessProviderLookup)(this.capabilityService),
|
|
414
|
+
// Node-accurate lookup for EXPLICITLY hub-pinned calls: unlike the
|
|
415
|
+
// lookup above (which falls back to the cluster-elected ACTIVE
|
|
416
|
+
// singleton — possibly a remote proxy), this resolves only providers
|
|
417
|
+
// physically resident on the hub, so a `nodePin('hub')` fails precisely
|
|
418
|
+
// instead of silently executing on another node.
|
|
419
|
+
hubResidentProviders: (0, cap_route_authority_js_1.createHubResidentProviderLookup)(this.capabilityService),
|
|
414
420
|
// Per-cap-method RPC timeout override (e.g. model-convert.convert, which
|
|
415
421
|
// runs for minutes) — read from the cap definition's declared timeoutMs.
|
|
416
422
|
capTimeoutMs: (capName, method) => this.capabilityService.getRegistry()?.getDefinition(capName)?.methods?.[method]?.timeoutMs,
|