@camstack/system 1.2.415 → 1.2.417
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/addon-runner.js +9969 -27
- package/dist/addon-runner.mjs +9930 -9
- package/dist/addon-utils.js +19 -20
- package/dist/addon-utils.mjs +1 -2
- package/dist/auth/auth-audit-log.d.ts +1 -1
- package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
- package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
- package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
- package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
- package/dist/builtins/alerts/alerts.addon.js +1 -1
- package/dist/builtins/alerts/alerts.addon.mjs +1 -1
- package/dist/builtins/autotrack/index.js +1 -1
- package/dist/builtins/autotrack/index.mjs +1 -1
- package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
- package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
- package/dist/builtins/calendars/calendars.addon.js +1 -1
- package/dist/builtins/calendars/calendars.addon.mjs +1 -1
- package/dist/builtins/camera-grid/index.js +1 -1
- package/dist/builtins/camera-grid/index.mjs +1 -1
- package/dist/builtins/composer/composer.addon.js +2 -2
- package/dist/builtins/composer/composer.addon.mjs +2 -2
- package/dist/builtins/console-logging/index.js +1 -1
- package/dist/builtins/console-logging/index.mjs +1 -1
- package/dist/builtins/core-blocks/core-blocks.addon.js +2 -2
- package/dist/builtins/core-blocks/core-blocks.addon.mjs +2 -2
- package/dist/builtins/device-manager/device-manager.addon.js +2 -2
- package/dist/builtins/device-manager/device-manager.addon.mjs +2 -2
- package/dist/builtins/hub-forwarder/index.js +1 -1
- package/dist/builtins/hub-forwarder/index.mjs +1 -1
- package/dist/builtins/keychain/index.js +3 -3
- package/dist/builtins/keychain/index.mjs +3 -3
- package/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
- package/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
- package/dist/builtins/local-auth/local-auth.addon.js +12 -9
- package/dist/builtins/local-auth/local-auth.addon.mjs +7 -4
- package/dist/builtins/local-network/hub-mdns-ciao.d.ts +7 -0
- package/dist/builtins/local-network/hub-mdns.d.ts +58 -0
- package/dist/builtins/local-network/local-network.addon.d.ts +11 -0
- package/dist/builtins/local-network/local-network.addon.js +194 -3
- package/dist/builtins/local-network/local-network.addon.mjs +195 -3
- package/dist/builtins/loki-logging/index.js +1 -1
- package/dist/builtins/loki-logging/index.mjs +1 -1
- package/dist/builtins/native-metrics/native-metrics.addon.js +102 -10
- package/dist/builtins/native-metrics/native-metrics.addon.mjs +92 -4
- package/dist/builtins/platform-probe/index.js +1 -1
- package/dist/builtins/platform-probe/index.mjs +1 -1
- package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
- package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
- package/dist/builtins/snapshot/index.js +1 -1
- package/dist/builtins/snapshot/index.mjs +1 -1
- package/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
- package/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
- package/dist/builtins/sqlite-storage/sqlite-settings.addon.js +0 -0
- package/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +0 -0
- package/dist/builtins/storage-orchestrator/index.mjs +1 -1
- package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +84 -5
- package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +80 -5
- package/dist/builtins/system-config/system-config.addon.js +80 -785
- package/dist/builtins/system-config/system-config.addon.mjs +52 -757
- package/dist/builtins/winston-logging/index.js +1 -1
- package/dist/builtins/winston-logging/index.mjs +1 -1
- package/dist/{composition-sources-YlkCjf-1.js → composition-sources-ChAX2Kdo.js} +1 -1
- package/dist/{composition-sources-CXxkMoXq.mjs → composition-sources-CndJVssc.mjs} +1 -1
- package/dist/{constants-BT-fudVK.mjs → constants-BzxwnfDc.mjs} +1 -1
- package/dist/{constants-DChnQrhM.js → constants-VXvZkGgw.js} +1 -1
- package/dist/{event-loop-stall-monitor-LZvGqiHI.js → custom-action-registry-Bb28ibZV.js} +63 -1
- package/dist/{event-loop-stall-monitor-BEfMVUxz.mjs → custom-action-registry-DHv0kYcT.mjs} +58 -2
- package/dist/{dist-CvarXqQt.js → dist-BMOD9OyH.js} +32 -111
- package/dist/{dist-dEsHYY8m.mjs → dist-H_RapIeM.mjs} +21 -100
- package/dist/index.js +22786 -10067
- package/dist/index.mjs +22602 -9883
- package/dist/{jwt-signing-key-CfiteETM.js → jwt-signing-key-BiKHENST.js} +1 -1
- package/dist/{jwt-signing-key-SFIxaH2x.mjs → jwt-signing-key-xQxqpwMC.mjs} +1 -1
- package/dist/kernel/moleculer/broker-factory.d.ts +2 -4
- package/dist/kernel/transport/local-child-registry.d.ts +1 -1
- package/dist/lib-B_R6sPC3.mjs +7106 -0
- package/dist/lib-DOJ5yyWA.js +7110 -0
- package/dist/logging/log-redactor.d.ts +1 -1
- package/dist/{ms-DlIWNkkk.mjs → ms-CgH2OFlD.mjs} +2 -42
- package/dist/{ms-t68_FaqE.js → ms-LB3giGoU.js} +1 -48
- package/dist/{resource-monitor-B2WZ8_q9.mjs → resource-monitor-Di9daRwI.mjs} +1 -1
- package/dist/{resource-monitor-BgWGRxN5.js → resource-monitor-mio9dSCT.js} +5 -5
- package/dist/{restore-archive-CAw_3iNq.js → restore-archive-BobsETEp.js} +1 -1
- package/dist/{restore-archive-Bww1Fl04.mjs → restore-archive-CCAQicV-.mjs} +1 -1
- package/dist/{retired-settings-keys-YLflwTPH.js → retired-settings-keys-BMq2u4Wv.js} +1 -1
- package/dist/{retired-settings-keys-ChQ3qH-V.mjs → retired-settings-keys-CwL4zHLg.mjs} +1 -1
- package/dist/safe-buffer-B1OjL1I9.mjs +42 -0
- package/dist/safe-buffer-D3aoa-7X.js +46 -0
- package/dist/src-CnAqG6EF.js +714 -0
- package/dist/src-hG4grMU4.mjs +709 -0
- package/dist/{tls-BWpwU-d5.js → tls-C0TRPfqc.js} +1 -1
- package/dist/{tls-C2NT-Orr.mjs → tls-D-2dPY-5.mjs} +1 -1
- package/dist/{x509.es-Xf3K_brW.mjs → x509.es-CAjSsrkk.mjs} +643 -2
- package/dist/{x509.es-BhTzcFhZ.js → x509.es-Dzl0BbmG.js} +653 -0
- package/package.json +3 -2
- package/dist/child-cap-dispatch-DFBrdGH2.js +0 -13986
- package/dist/child-cap-dispatch-SF8oiwgo.mjs +0 -12916
- package/dist/custom-action-registry-B4Cf4O_X.mjs +0 -57
- package/dist/custom-action-registry-acBY3mHA.js +0 -62
- package/dist/hub-cap-forward-CDiN1p98.mjs +0 -78
- package/dist/hub-cap-forward-W8oEm4ME.js +0 -101
- package/dist/proc-stat-CbC55Kqi.mjs +0 -92
- package/dist/proc-stat-DL-WUOhl.js +0 -127
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { describeCustomActions } from "@camstack/types/addon";
|
|
2
|
-
//#region src/kernel/custom-action-registry.ts
|
|
3
|
-
/**
|
|
4
|
-
* CustomActionRegistry — per-process registry of addon custom actions.
|
|
5
|
-
*
|
|
6
|
-
* Populated at boot from each addon's `AddonInitResult.customActions` +
|
|
7
|
-
* `handleCustomAction` handler. Rejects actions declared with scope other
|
|
8
|
-
* than 'system' (today only 'system' is runtime-supported; the descriptor
|
|
9
|
-
* allows future scopes for forward compat).
|
|
10
|
-
*/
|
|
11
|
-
var CustomActionRegistry = class {
|
|
12
|
-
byAddon = /* @__PURE__ */ new Map();
|
|
13
|
-
registerAddon(addonId, catalog, handler) {
|
|
14
|
-
const actions = /* @__PURE__ */ new Map();
|
|
15
|
-
for (const [name, spec] of Object.entries(catalog)) {
|
|
16
|
-
const scope = spec.scope ?? { kind: "system" };
|
|
17
|
-
if (scope.kind !== "system") throw new Error(`custom action '${addonId}.${name}' declared scope '${scope.kind}' — not yet implemented`);
|
|
18
|
-
actions.set(name, {
|
|
19
|
-
spec,
|
|
20
|
-
handler: (input, caller) => handler(name, input, caller)
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
this.byAddon.set(addonId, actions);
|
|
24
|
-
}
|
|
25
|
-
unregisterAddon(addonId) {
|
|
26
|
-
this.byAddon.delete(addonId);
|
|
27
|
-
}
|
|
28
|
-
resolve(addonId, action) {
|
|
29
|
-
return this.byAddon.get(addonId)?.get(action) ?? null;
|
|
30
|
-
}
|
|
31
|
-
listActions(addonId) {
|
|
32
|
-
return [...this.byAddon.get(addonId)?.keys() ?? []];
|
|
33
|
-
}
|
|
34
|
-
listAddons() {
|
|
35
|
-
return [...this.byAddon.keys()];
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Every registered catalog with its schemas stripped, keyed by addon id —
|
|
39
|
-
* what a runner puts in its register frame so the hub learns the catalogs
|
|
40
|
-
* from the process that owns them (D444). `hostedAddonIds` are the addons
|
|
41
|
-
* this runner hosts: each is present in the result, with an EMPTY catalog
|
|
42
|
-
* when it registered none, so the parent can say "declares no actions" per
|
|
43
|
-
* addon instead of guessing from an absent key.
|
|
44
|
-
*/
|
|
45
|
-
describeAll(hostedAddonIds) {
|
|
46
|
-
const out = {};
|
|
47
|
-
for (const addonId of hostedAddonIds) out[addonId] = {};
|
|
48
|
-
for (const [addonId, actions] of this.byAddon) {
|
|
49
|
-
const catalog = {};
|
|
50
|
-
for (const [name, entry] of actions) catalog[name] = entry.spec;
|
|
51
|
-
out[addonId] = describeCustomActions(catalog);
|
|
52
|
-
}
|
|
53
|
-
return out;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
//#endregion
|
|
57
|
-
export { CustomActionRegistry as t };
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
let _camstack_types_addon = require("@camstack/types/addon");
|
|
2
|
-
//#region src/kernel/custom-action-registry.ts
|
|
3
|
-
/**
|
|
4
|
-
* CustomActionRegistry — per-process registry of addon custom actions.
|
|
5
|
-
*
|
|
6
|
-
* Populated at boot from each addon's `AddonInitResult.customActions` +
|
|
7
|
-
* `handleCustomAction` handler. Rejects actions declared with scope other
|
|
8
|
-
* than 'system' (today only 'system' is runtime-supported; the descriptor
|
|
9
|
-
* allows future scopes for forward compat).
|
|
10
|
-
*/
|
|
11
|
-
var CustomActionRegistry = class {
|
|
12
|
-
byAddon = /* @__PURE__ */ new Map();
|
|
13
|
-
registerAddon(addonId, catalog, handler) {
|
|
14
|
-
const actions = /* @__PURE__ */ new Map();
|
|
15
|
-
for (const [name, spec] of Object.entries(catalog)) {
|
|
16
|
-
const scope = spec.scope ?? { kind: "system" };
|
|
17
|
-
if (scope.kind !== "system") throw new Error(`custom action '${addonId}.${name}' declared scope '${scope.kind}' — not yet implemented`);
|
|
18
|
-
actions.set(name, {
|
|
19
|
-
spec,
|
|
20
|
-
handler: (input, caller) => handler(name, input, caller)
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
this.byAddon.set(addonId, actions);
|
|
24
|
-
}
|
|
25
|
-
unregisterAddon(addonId) {
|
|
26
|
-
this.byAddon.delete(addonId);
|
|
27
|
-
}
|
|
28
|
-
resolve(addonId, action) {
|
|
29
|
-
return this.byAddon.get(addonId)?.get(action) ?? null;
|
|
30
|
-
}
|
|
31
|
-
listActions(addonId) {
|
|
32
|
-
return [...this.byAddon.get(addonId)?.keys() ?? []];
|
|
33
|
-
}
|
|
34
|
-
listAddons() {
|
|
35
|
-
return [...this.byAddon.keys()];
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Every registered catalog with its schemas stripped, keyed by addon id —
|
|
39
|
-
* what a runner puts in its register frame so the hub learns the catalogs
|
|
40
|
-
* from the process that owns them (D444). `hostedAddonIds` are the addons
|
|
41
|
-
* this runner hosts: each is present in the result, with an EMPTY catalog
|
|
42
|
-
* when it registered none, so the parent can say "declares no actions" per
|
|
43
|
-
* addon instead of guessing from an absent key.
|
|
44
|
-
*/
|
|
45
|
-
describeAll(hostedAddonIds) {
|
|
46
|
-
const out = {};
|
|
47
|
-
for (const addonId of hostedAddonIds) out[addonId] = {};
|
|
48
|
-
for (const [addonId, actions] of this.byAddon) {
|
|
49
|
-
const catalog = {};
|
|
50
|
-
for (const [name, entry] of actions) catalog[name] = entry.spec;
|
|
51
|
-
out[addonId] = (0, _camstack_types_addon.describeCustomActions)(catalog);
|
|
52
|
-
}
|
|
53
|
-
return out;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
//#endregion
|
|
57
|
-
Object.defineProperty(exports, "CustomActionRegistry", {
|
|
58
|
-
enumerable: true,
|
|
59
|
-
get: function() {
|
|
60
|
-
return CustomActionRegistry;
|
|
61
|
-
}
|
|
62
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
//#region src/kernel/transport/hub-cap-forward.ts
|
|
2
|
-
/** The Moleculer service name the hub registers for agent→hub cap forwarding. */
|
|
3
|
-
var HUB_CAP_FWD_SERVICE = "$hub-cap-fwd";
|
|
4
|
-
/** The Moleculer action (service.action) for hub cap forwarding. */
|
|
5
|
-
var HUB_CAP_FWD_ACTION = `${HUB_CAP_FWD_SERVICE}.forward`;
|
|
6
|
-
/**
|
|
7
|
-
* Drop a `caller` the forwarded args carry. `caller` is the USER identity the
|
|
8
|
-
* hub's tRPC router injects for `caller: 'required'` methods
|
|
9
|
-
* (`cap-router-builder.ts`), and providers trust it — `keychainAdmin.reveal`
|
|
10
|
-
* reads `input.caller.userId`. A call that arrives over the mesh has no user
|
|
11
|
-
* session behind it, so whatever `caller` it carries is forged (D802). The
|
|
12
|
-
* args' `callerAddonId` is overwritten or stripped further down by
|
|
13
|
-
* `stampCallerAddonId`; `caller` had no such guard.
|
|
14
|
-
*/
|
|
15
|
-
function stripForwardedCaller(args) {
|
|
16
|
-
if (args === null || typeof args !== "object" || Array.isArray(args)) return args;
|
|
17
|
-
if (!Object.prototype.hasOwnProperty.call(args, "caller")) return args;
|
|
18
|
-
const rest = {};
|
|
19
|
-
for (const [key, value] of Object.entries(args)) if (key !== "caller") rest[key] = value;
|
|
20
|
-
return rest;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Narrow Moleculer's loosely-typed `ctx.params` to {@link HubCapForwardParams}
|
|
24
|
-
* without unsafe casts — mirrors `agent-cap-dispatch-service.ts:narrowParams`.
|
|
25
|
-
*/
|
|
26
|
-
function narrowParams(raw) {
|
|
27
|
-
if (raw === null || typeof raw !== "object") throw new Error("$hub-cap-fwd.forward: invalid params — capName and method are required strings");
|
|
28
|
-
const capName = Reflect.get(raw, "capName");
|
|
29
|
-
const method = Reflect.get(raw, "method");
|
|
30
|
-
if (typeof capName !== "string" || typeof method !== "string") throw new Error("$hub-cap-fwd.forward: invalid params — capName and method are required strings");
|
|
31
|
-
const deviceId = Reflect.get(raw, "deviceId");
|
|
32
|
-
const nodeId = Reflect.get(raw, "nodeId");
|
|
33
|
-
const native = Reflect.get(raw, "native");
|
|
34
|
-
const callerAddonId = Reflect.get(raw, "callerAddonId");
|
|
35
|
-
return {
|
|
36
|
-
capName,
|
|
37
|
-
method,
|
|
38
|
-
args: stripForwardedCaller(Reflect.get(raw, "args")),
|
|
39
|
-
deviceId: typeof deviceId === "number" ? deviceId : void 0,
|
|
40
|
-
nodeId: typeof nodeId === "string" && nodeId.length > 0 ? nodeId : void 0,
|
|
41
|
-
native: native === true ? true : void 0,
|
|
42
|
-
callerAddonId: typeof callerAddonId === "string" && callerAddonId.length > 0 ? callerAddonId : void 0
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Build the `$hub-cap-fwd` Moleculer `ServiceSchema`. The hub registers this on
|
|
47
|
-
* its broker (only the hub registers it → an agent's `broker.call` for
|
|
48
|
-
* `$hub-cap-fwd.forward` discovers it on the hub with no explicit nodeID pin).
|
|
49
|
-
*
|
|
50
|
-
* @param onUnownedCall The hub's cap routing handler (from
|
|
51
|
-
* `createParentUnownedCallHandler`). Reused verbatim so
|
|
52
|
-
* forwarded calls route exactly like a hub-local child's.
|
|
53
|
-
*/
|
|
54
|
-
function createHubCapForwardService(onUnownedCall, options = {}) {
|
|
55
|
-
return {
|
|
56
|
-
name: HUB_CAP_FWD_SERVICE,
|
|
57
|
-
actions: { forward: { handler: async (ctx) => {
|
|
58
|
-
const { capName, method, args, deviceId, nodeId, native, callerAddonId } = narrowParams(ctx.params);
|
|
59
|
-
const sender = typeof ctx.nodeID === "string" ? ctx.nodeID : null;
|
|
60
|
-
let caller = callerAddonId;
|
|
61
|
-
if (caller !== void 0 && options.isCallerOnNode !== void 0 && (sender === null || !options.isCallerOnNode(sender, caller))) {
|
|
62
|
-
options.onRejectedCaller?.(sender ?? "(unknown node)", caller);
|
|
63
|
-
caller = void 0;
|
|
64
|
-
}
|
|
65
|
-
return onUnownedCall({
|
|
66
|
-
capName,
|
|
67
|
-
method,
|
|
68
|
-
args,
|
|
69
|
-
...deviceId !== void 0 ? { deviceId } : {},
|
|
70
|
-
...nodeId !== void 0 ? { nodeId } : {},
|
|
71
|
-
...native === true ? { native: true } : {},
|
|
72
|
-
...caller !== void 0 ? { callerAddonId: caller } : {}
|
|
73
|
-
});
|
|
74
|
-
} } }
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
//#endregion
|
|
78
|
-
export { stripForwardedCaller as i, HUB_CAP_FWD_SERVICE as n, createHubCapForwardService as r, HUB_CAP_FWD_ACTION as t };
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
//#region src/kernel/transport/hub-cap-forward.ts
|
|
2
|
-
/** The Moleculer service name the hub registers for agent→hub cap forwarding. */
|
|
3
|
-
var HUB_CAP_FWD_SERVICE = "$hub-cap-fwd";
|
|
4
|
-
/** The Moleculer action (service.action) for hub cap forwarding. */
|
|
5
|
-
var HUB_CAP_FWD_ACTION = `${HUB_CAP_FWD_SERVICE}.forward`;
|
|
6
|
-
/**
|
|
7
|
-
* Drop a `caller` the forwarded args carry. `caller` is the USER identity the
|
|
8
|
-
* hub's tRPC router injects for `caller: 'required'` methods
|
|
9
|
-
* (`cap-router-builder.ts`), and providers trust it — `keychainAdmin.reveal`
|
|
10
|
-
* reads `input.caller.userId`. A call that arrives over the mesh has no user
|
|
11
|
-
* session behind it, so whatever `caller` it carries is forged (D802). The
|
|
12
|
-
* args' `callerAddonId` is overwritten or stripped further down by
|
|
13
|
-
* `stampCallerAddonId`; `caller` had no such guard.
|
|
14
|
-
*/
|
|
15
|
-
function stripForwardedCaller(args) {
|
|
16
|
-
if (args === null || typeof args !== "object" || Array.isArray(args)) return args;
|
|
17
|
-
if (!Object.prototype.hasOwnProperty.call(args, "caller")) return args;
|
|
18
|
-
const rest = {};
|
|
19
|
-
for (const [key, value] of Object.entries(args)) if (key !== "caller") rest[key] = value;
|
|
20
|
-
return rest;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Narrow Moleculer's loosely-typed `ctx.params` to {@link HubCapForwardParams}
|
|
24
|
-
* without unsafe casts — mirrors `agent-cap-dispatch-service.ts:narrowParams`.
|
|
25
|
-
*/
|
|
26
|
-
function narrowParams(raw) {
|
|
27
|
-
if (raw === null || typeof raw !== "object") throw new Error("$hub-cap-fwd.forward: invalid params — capName and method are required strings");
|
|
28
|
-
const capName = Reflect.get(raw, "capName");
|
|
29
|
-
const method = Reflect.get(raw, "method");
|
|
30
|
-
if (typeof capName !== "string" || typeof method !== "string") throw new Error("$hub-cap-fwd.forward: invalid params — capName and method are required strings");
|
|
31
|
-
const deviceId = Reflect.get(raw, "deviceId");
|
|
32
|
-
const nodeId = Reflect.get(raw, "nodeId");
|
|
33
|
-
const native = Reflect.get(raw, "native");
|
|
34
|
-
const callerAddonId = Reflect.get(raw, "callerAddonId");
|
|
35
|
-
return {
|
|
36
|
-
capName,
|
|
37
|
-
method,
|
|
38
|
-
args: stripForwardedCaller(Reflect.get(raw, "args")),
|
|
39
|
-
deviceId: typeof deviceId === "number" ? deviceId : void 0,
|
|
40
|
-
nodeId: typeof nodeId === "string" && nodeId.length > 0 ? nodeId : void 0,
|
|
41
|
-
native: native === true ? true : void 0,
|
|
42
|
-
callerAddonId: typeof callerAddonId === "string" && callerAddonId.length > 0 ? callerAddonId : void 0
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Build the `$hub-cap-fwd` Moleculer `ServiceSchema`. The hub registers this on
|
|
47
|
-
* its broker (only the hub registers it → an agent's `broker.call` for
|
|
48
|
-
* `$hub-cap-fwd.forward` discovers it on the hub with no explicit nodeID pin).
|
|
49
|
-
*
|
|
50
|
-
* @param onUnownedCall The hub's cap routing handler (from
|
|
51
|
-
* `createParentUnownedCallHandler`). Reused verbatim so
|
|
52
|
-
* forwarded calls route exactly like a hub-local child's.
|
|
53
|
-
*/
|
|
54
|
-
function createHubCapForwardService(onUnownedCall, options = {}) {
|
|
55
|
-
return {
|
|
56
|
-
name: HUB_CAP_FWD_SERVICE,
|
|
57
|
-
actions: { forward: { handler: async (ctx) => {
|
|
58
|
-
const { capName, method, args, deviceId, nodeId, native, callerAddonId } = narrowParams(ctx.params);
|
|
59
|
-
const sender = typeof ctx.nodeID === "string" ? ctx.nodeID : null;
|
|
60
|
-
let caller = callerAddonId;
|
|
61
|
-
if (caller !== void 0 && options.isCallerOnNode !== void 0 && (sender === null || !options.isCallerOnNode(sender, caller))) {
|
|
62
|
-
options.onRejectedCaller?.(sender ?? "(unknown node)", caller);
|
|
63
|
-
caller = void 0;
|
|
64
|
-
}
|
|
65
|
-
return onUnownedCall({
|
|
66
|
-
capName,
|
|
67
|
-
method,
|
|
68
|
-
args,
|
|
69
|
-
...deviceId !== void 0 ? { deviceId } : {},
|
|
70
|
-
...nodeId !== void 0 ? { nodeId } : {},
|
|
71
|
-
...native === true ? { native: true } : {},
|
|
72
|
-
...caller !== void 0 ? { callerAddonId: caller } : {}
|
|
73
|
-
});
|
|
74
|
-
} } }
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
//#endregion
|
|
78
|
-
Object.defineProperty(exports, "HUB_CAP_FWD_ACTION", {
|
|
79
|
-
enumerable: true,
|
|
80
|
-
get: function() {
|
|
81
|
-
return HUB_CAP_FWD_ACTION;
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
Object.defineProperty(exports, "HUB_CAP_FWD_SERVICE", {
|
|
85
|
-
enumerable: true,
|
|
86
|
-
get: function() {
|
|
87
|
-
return HUB_CAP_FWD_SERVICE;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
Object.defineProperty(exports, "createHubCapForwardService", {
|
|
91
|
-
enumerable: true,
|
|
92
|
-
get: function() {
|
|
93
|
-
return createHubCapForwardService;
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
Object.defineProperty(exports, "stripForwardedCaller", {
|
|
97
|
-
enumerable: true,
|
|
98
|
-
get: function() {
|
|
99
|
-
return stripForwardedCaller;
|
|
100
|
-
}
|
|
101
|
-
});
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { readFile, readdir } from "node:fs/promises";
|
|
2
|
-
/**
|
|
3
|
-
* Parse one `/proc/<pid>/stat` line. `null` for a line that does not parse —
|
|
4
|
-
* a process that exited between the readdir and the read leaves a truncated
|
|
5
|
-
* or empty file, and that is normal, not an error.
|
|
6
|
-
*/
|
|
7
|
-
function parseProcStat(line) {
|
|
8
|
-
const close = line.lastIndexOf(")");
|
|
9
|
-
const open = line.indexOf("(");
|
|
10
|
-
if (close < 0 || open < 0 || close < open) return null;
|
|
11
|
-
const pid = Number(line.slice(0, open).trim());
|
|
12
|
-
const comm = line.slice(open + 1, close);
|
|
13
|
-
const rest = line.slice(close + 1).trim().split(/\s+/);
|
|
14
|
-
const state = rest[0];
|
|
15
|
-
const ppid = Number(rest[1]);
|
|
16
|
-
const pgid = Number(rest[2]);
|
|
17
|
-
const utime = Number(rest[11]);
|
|
18
|
-
const stime = Number(rest[12]);
|
|
19
|
-
const startTicks = Number(rest[19]);
|
|
20
|
-
const rssPages = Number(rest[21]);
|
|
21
|
-
if (state === void 0 || state === "") return null;
|
|
22
|
-
if (![
|
|
23
|
-
pid,
|
|
24
|
-
ppid,
|
|
25
|
-
pgid,
|
|
26
|
-
utime,
|
|
27
|
-
stime,
|
|
28
|
-
startTicks,
|
|
29
|
-
rssPages
|
|
30
|
-
].every(Number.isFinite)) return null;
|
|
31
|
-
return {
|
|
32
|
-
pid,
|
|
33
|
-
comm,
|
|
34
|
-
state,
|
|
35
|
-
ppid,
|
|
36
|
-
pgid,
|
|
37
|
-
ticks: utime + stime,
|
|
38
|
-
startTicks,
|
|
39
|
-
rssPages
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function statusKb(status, key) {
|
|
43
|
-
const match = status.match(new RegExp(`^${key}:\\s+(\\d+)`, "m"));
|
|
44
|
-
return match ? parseInt(match[1], 10) * 1024 : void 0;
|
|
45
|
-
}
|
|
46
|
-
/** Read `VmRSS` / `RssAnon` / `RssFile` (kB in the file) out of `/proc/<pid>/status`. */
|
|
47
|
-
function parseProcStatusRss(status) {
|
|
48
|
-
return {
|
|
49
|
-
rssBytes: statusKb(status, "VmRSS"),
|
|
50
|
-
privateBytes: statusKb(status, "RssAnon"),
|
|
51
|
-
sharedBytes: statusKb(status, "RssFile")
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
/** Seconds the process has been alive — `ps etime`, whole seconds. */
|
|
55
|
-
function elapsedSecSince(input) {
|
|
56
|
-
return Math.max(0, Math.floor(input.uptimeSec - input.startTicks / 100));
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* `ps pcpu`: CPU time over elapsed time, as a percentage with one decimal.
|
|
60
|
-
*
|
|
61
|
-
* This is deliberately the LIFETIME average `ps` prints, not an instantaneous
|
|
62
|
-
* rate: the columns fed from it have always shown that quantity, and the
|
|
63
|
-
* instantaneous split is a different number with a different owner
|
|
64
|
-
* (`cpuMainPercent` / `cpuGcPercent` from `thread-cpu-sampler.ts`). A process
|
|
65
|
-
* with no elapsed window yet reports 0, never a division by zero.
|
|
66
|
-
*/
|
|
67
|
-
function lifetimeCpuPercent(input) {
|
|
68
|
-
const elapsedSec = input.uptimeSec - input.startTicks / 100;
|
|
69
|
-
if (!(elapsedSec > 0)) return 0;
|
|
70
|
-
const cpuSec = input.ticks / 100;
|
|
71
|
-
return Math.round(cpuSec / elapsedSec * 1e3) / 10;
|
|
72
|
-
}
|
|
73
|
-
var PID_RE = /^\d+$/;
|
|
74
|
-
var nodeProcReader = {
|
|
75
|
-
listPids: async () => (await readdir("/proc")).filter((entry) => PID_RE.test(entry)).map((entry) => Number(entry)),
|
|
76
|
-
readStat: (pid) => readFile(`/proc/${pid}/stat`, "latin1"),
|
|
77
|
-
readStatus: (pid) => readFile(`/proc/${pid}/status`, "latin1"),
|
|
78
|
-
readCmdline: (pid) => readFile(`/proc/${pid}/cmdline`, "latin1"),
|
|
79
|
-
readUptimeSec: async () => {
|
|
80
|
-
const [first] = (await readFile("/proc/uptime", "latin1")).trim().split(/\s+/);
|
|
81
|
-
const seconds = Number(first);
|
|
82
|
-
if (!Number.isFinite(seconds)) throw new Error(`/proc/uptime unreadable: ${String(first)}`);
|
|
83
|
-
return seconds;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
/** `ps command=`: argv joined by spaces, or `[comm]` when there is no argv. */
|
|
87
|
-
function commandFromCmdline(cmdline, comm) {
|
|
88
|
-
const joined = cmdline.split("\0").filter((part) => part.length > 0).join(" ");
|
|
89
|
-
return joined.length > 0 ? joined : `[${comm}]`;
|
|
90
|
-
}
|
|
91
|
-
//#endregion
|
|
92
|
-
export { parseProcStat as a, nodeProcReader as i, elapsedSecSince as n, parseProcStatusRss as o, lifetimeCpuPercent as r, commandFromCmdline as t };
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
let node_fs_promises = require("node:fs/promises");
|
|
2
|
-
/**
|
|
3
|
-
* Parse one `/proc/<pid>/stat` line. `null` for a line that does not parse —
|
|
4
|
-
* a process that exited between the readdir and the read leaves a truncated
|
|
5
|
-
* or empty file, and that is normal, not an error.
|
|
6
|
-
*/
|
|
7
|
-
function parseProcStat(line) {
|
|
8
|
-
const close = line.lastIndexOf(")");
|
|
9
|
-
const open = line.indexOf("(");
|
|
10
|
-
if (close < 0 || open < 0 || close < open) return null;
|
|
11
|
-
const pid = Number(line.slice(0, open).trim());
|
|
12
|
-
const comm = line.slice(open + 1, close);
|
|
13
|
-
const rest = line.slice(close + 1).trim().split(/\s+/);
|
|
14
|
-
const state = rest[0];
|
|
15
|
-
const ppid = Number(rest[1]);
|
|
16
|
-
const pgid = Number(rest[2]);
|
|
17
|
-
const utime = Number(rest[11]);
|
|
18
|
-
const stime = Number(rest[12]);
|
|
19
|
-
const startTicks = Number(rest[19]);
|
|
20
|
-
const rssPages = Number(rest[21]);
|
|
21
|
-
if (state === void 0 || state === "") return null;
|
|
22
|
-
if (![
|
|
23
|
-
pid,
|
|
24
|
-
ppid,
|
|
25
|
-
pgid,
|
|
26
|
-
utime,
|
|
27
|
-
stime,
|
|
28
|
-
startTicks,
|
|
29
|
-
rssPages
|
|
30
|
-
].every(Number.isFinite)) return null;
|
|
31
|
-
return {
|
|
32
|
-
pid,
|
|
33
|
-
comm,
|
|
34
|
-
state,
|
|
35
|
-
ppid,
|
|
36
|
-
pgid,
|
|
37
|
-
ticks: utime + stime,
|
|
38
|
-
startTicks,
|
|
39
|
-
rssPages
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function statusKb(status, key) {
|
|
43
|
-
const match = status.match(new RegExp(`^${key}:\\s+(\\d+)`, "m"));
|
|
44
|
-
return match ? parseInt(match[1], 10) * 1024 : void 0;
|
|
45
|
-
}
|
|
46
|
-
/** Read `VmRSS` / `RssAnon` / `RssFile` (kB in the file) out of `/proc/<pid>/status`. */
|
|
47
|
-
function parseProcStatusRss(status) {
|
|
48
|
-
return {
|
|
49
|
-
rssBytes: statusKb(status, "VmRSS"),
|
|
50
|
-
privateBytes: statusKb(status, "RssAnon"),
|
|
51
|
-
sharedBytes: statusKb(status, "RssFile")
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
/** Seconds the process has been alive — `ps etime`, whole seconds. */
|
|
55
|
-
function elapsedSecSince(input) {
|
|
56
|
-
return Math.max(0, Math.floor(input.uptimeSec - input.startTicks / 100));
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* `ps pcpu`: CPU time over elapsed time, as a percentage with one decimal.
|
|
60
|
-
*
|
|
61
|
-
* This is deliberately the LIFETIME average `ps` prints, not an instantaneous
|
|
62
|
-
* rate: the columns fed from it have always shown that quantity, and the
|
|
63
|
-
* instantaneous split is a different number with a different owner
|
|
64
|
-
* (`cpuMainPercent` / `cpuGcPercent` from `thread-cpu-sampler.ts`). A process
|
|
65
|
-
* with no elapsed window yet reports 0, never a division by zero.
|
|
66
|
-
*/
|
|
67
|
-
function lifetimeCpuPercent(input) {
|
|
68
|
-
const elapsedSec = input.uptimeSec - input.startTicks / 100;
|
|
69
|
-
if (!(elapsedSec > 0)) return 0;
|
|
70
|
-
const cpuSec = input.ticks / 100;
|
|
71
|
-
return Math.round(cpuSec / elapsedSec * 1e3) / 10;
|
|
72
|
-
}
|
|
73
|
-
var PID_RE = /^\d+$/;
|
|
74
|
-
var nodeProcReader = {
|
|
75
|
-
listPids: async () => (await (0, node_fs_promises.readdir)("/proc")).filter((entry) => PID_RE.test(entry)).map((entry) => Number(entry)),
|
|
76
|
-
readStat: (pid) => (0, node_fs_promises.readFile)(`/proc/${pid}/stat`, "latin1"),
|
|
77
|
-
readStatus: (pid) => (0, node_fs_promises.readFile)(`/proc/${pid}/status`, "latin1"),
|
|
78
|
-
readCmdline: (pid) => (0, node_fs_promises.readFile)(`/proc/${pid}/cmdline`, "latin1"),
|
|
79
|
-
readUptimeSec: async () => {
|
|
80
|
-
const [first] = (await (0, node_fs_promises.readFile)("/proc/uptime", "latin1")).trim().split(/\s+/);
|
|
81
|
-
const seconds = Number(first);
|
|
82
|
-
if (!Number.isFinite(seconds)) throw new Error(`/proc/uptime unreadable: ${String(first)}`);
|
|
83
|
-
return seconds;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
/** `ps command=`: argv joined by spaces, or `[comm]` when there is no argv. */
|
|
87
|
-
function commandFromCmdline(cmdline, comm) {
|
|
88
|
-
const joined = cmdline.split("\0").filter((part) => part.length > 0).join(" ");
|
|
89
|
-
return joined.length > 0 ? joined : `[${comm}]`;
|
|
90
|
-
}
|
|
91
|
-
//#endregion
|
|
92
|
-
Object.defineProperty(exports, "commandFromCmdline", {
|
|
93
|
-
enumerable: true,
|
|
94
|
-
get: function() {
|
|
95
|
-
return commandFromCmdline;
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
Object.defineProperty(exports, "elapsedSecSince", {
|
|
99
|
-
enumerable: true,
|
|
100
|
-
get: function() {
|
|
101
|
-
return elapsedSecSince;
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
Object.defineProperty(exports, "lifetimeCpuPercent", {
|
|
105
|
-
enumerable: true,
|
|
106
|
-
get: function() {
|
|
107
|
-
return lifetimeCpuPercent;
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
Object.defineProperty(exports, "nodeProcReader", {
|
|
111
|
-
enumerable: true,
|
|
112
|
-
get: function() {
|
|
113
|
-
return nodeProcReader;
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
Object.defineProperty(exports, "parseProcStat", {
|
|
117
|
-
enumerable: true,
|
|
118
|
-
get: function() {
|
|
119
|
-
return parseProcStat;
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
Object.defineProperty(exports, "parseProcStatusRss", {
|
|
123
|
-
enumerable: true,
|
|
124
|
-
get: function() {
|
|
125
|
-
return parseProcStatusRss;
|
|
126
|
-
}
|
|
127
|
-
});
|