@uns-kit/core 3.0.32 → 3.0.33

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.
Files changed (35) hide show
  1. package/MIGRATIONS.md +16 -0
  2. package/dist/config/app-config.d.ts +1 -0
  3. package/dist/config/app-config.d.ts.map +1 -1
  4. package/dist/config/app-config.js.map +1 -1
  5. package/dist/runtime/mqtt-drain.d.ts +29 -0
  6. package/dist/runtime/mqtt-drain.d.ts.map +1 -0
  7. package/dist/runtime/mqtt-drain.js +70 -0
  8. package/dist/runtime/mqtt-drain.js.map +1 -0
  9. package/dist/runtime/mqtt-output-state-contract.d.ts.map +1 -1
  10. package/dist/runtime/mqtt-output-state-contract.js +2 -0
  11. package/dist/runtime/mqtt-output-state-contract.js.map +1 -1
  12. package/dist/uns/uns-proxy-process.d.ts +8 -4
  13. package/dist/uns/uns-proxy-process.d.ts.map +1 -1
  14. package/dist/uns/uns-proxy-process.js +41 -5
  15. package/dist/uns/uns-proxy-process.js.map +1 -1
  16. package/dist/uns-config/config-schema.d.ts +1 -0
  17. package/dist/uns-config/config-schema.d.ts.map +1 -1
  18. package/dist/uns-config/uns-core-schema.d.ts +2 -0
  19. package/dist/uns-config/uns-core-schema.d.ts.map +1 -1
  20. package/dist/uns-mqtt/disabled-publish-queue.d.ts +6 -0
  21. package/dist/uns-mqtt/disabled-publish-queue.d.ts.map +1 -0
  22. package/dist/uns-mqtt/disabled-publish-queue.js +64 -0
  23. package/dist/uns-mqtt/disabled-publish-queue.js.map +1 -0
  24. package/dist/uns-mqtt/publish-queue-contract.d.ts +2 -0
  25. package/dist/uns-mqtt/publish-queue-contract.d.ts.map +1 -1
  26. package/dist/uns-mqtt/publish-queue-contract.js +4 -0
  27. package/dist/uns-mqtt/publish-queue-contract.js.map +1 -1
  28. package/dist/uns-mqtt/publish-queue.d.ts.map +1 -1
  29. package/dist/uns-mqtt/publish-queue.js +2 -0
  30. package/dist/uns-mqtt/publish-queue.js.map +1 -1
  31. package/dist/uns-mqtt/uns-mqtt-proxy.d.ts +3 -0
  32. package/dist/uns-mqtt/uns-mqtt-proxy.d.ts.map +1 -1
  33. package/dist/uns-mqtt/uns-mqtt-proxy.js +17 -1
  34. package/dist/uns-mqtt/uns-mqtt-proxy.js.map +1 -1
  35. package/package.json +1 -1
package/MIGRATIONS.md CHANGED
@@ -9,6 +9,22 @@ Agents must inspect the application's existing ownership and shutdown flow
9
9
  before editing it. The examples below describe the intended behavior, not a
10
10
  mechanical search-and-replace operation.
11
11
 
12
+ ## 3.0.33 - Explicit queue disablement and generic clean MQTT migration
13
+
14
+ When crossing `<3.0.33` to `>=3.0.33`, existing applications require no change.
15
+ An existing `publishQueue` remains enabled unless explicitly configured otherwise.
16
+ Use `enabled: false` only for an initial RAM-only deployment or a verified empty
17
+ old queue: pending state, another identity or a live owner blocks disabling.
18
+
19
+ Applications opting into ordinary clean MQTT migration declare `unsDatahub.mqttDrain`
20
+ protocol1 and call `UnsProxyProcess.enableMigrationDrain()` after preparation.
21
+ Provide `handoverShutdown` hooks that stop background admission and await all
22
+ accepted application work; report publication failures instead of silently losing
23
+ them. Hosts must wait for the bound SDK drain receipt and clean original exit;
24
+ PM2 online/stopped alone is insufficient. Unknown results block the successor.
25
+ Keep standalone shutdown functional. This does not retire paired input journals
26
+ or imply automatic queue transfer. See [the capability and example](https://github.com/uns-openhub/uns-kit/blob/master/docs/mqtt-migration-drain.md).
27
+
12
28
  ## 3.0.32 - Reviewed process-group MQTT output enablement
13
29
 
14
30
  When crossing `<3.0.32` to `>=3.0.32`, ordinary services, input journals and
@@ -114,6 +114,7 @@ export interface ProjectAppConfig {
114
114
  servername?: string | undefined;
115
115
  /** Opt-in MQTT output persistence; does not persist input subscriptions. */
116
116
  publishQueue?: {
117
+ enabled?: boolean;
117
118
  mode: "buffered" | "durable";
118
119
  storage?: "local" | "runtime";
119
120
  directory: string;
@@ -1 +1 @@
1
- {"version":3,"file":"app-config.d.ts","sourceRoot":"","sources":["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AAG"}
@@ -1 +1 @@
1
- {"version":3,"file":"app-config.js","sourceRoot":"","sources":["../../src/config/app-config.ts"],"names":[],"mappings":"","sourcesContent":["/* Auto-generated. Do not edit by hand. */\nexport interface ProjectAppConfig {\n uns: {\n graphql: string;\n rest: string;\n /** Bearer token used for service-to-service access to the UNS instance. */\n token?: string | undefined;\n /** Email used when authenticating to graphql endpoint of the UNS instance. */\n email?: string | undefined;\n /** Password or secret value paired with the UNS email. */\n password?: string | undefined;\n instanceMode?: \"wait\" | \"force\" | \"handover\";\n /** Process name used in MQTT topics and logs. */\n processName: string;\n handover?: boolean;\n /** Opt-in controller-correlated MQTT handover protocol. */\n handoverProtocol?: \"correlated-v1\" | undefined;\n /** Optional PM2/controller supervisor guard settings for this RTT instance. */\n supervisor?: {\n /** Enable controller/PM2 supervisor handling for this RTT instance. */\n enabled?: boolean;\n /** Let PM2 restart the process when it exits unexpectedly. */\n restartOnExit?: boolean;\n /** Optional PM2 memory restart limit in megabytes. */\n maxMemoryMb?: number | undefined;\n /** Let the controller auto-start this instance when required system-service runtime signals are absent. */\n restartOnUnhealthy?: boolean;\n /** How long runtime signals must stay unhealthy before the controller supervisor can act. */\n unhealthyAfterMs?: number;\n /** Minimum time between controller supervisor restart attempts for this instance. */\n restartCooldownMs?: number;\n } | undefined;\n jwksWellKnownUrl?: string | undefined;\n kidWellKnownUrl?: string | undefined;\n env?: \"dev\" | \"staging\" | \"test\" | \"prod\";\n };\n logging?: {\n adapter?: string;\n host: string;\n port?: number;\n level?: \"error\" | \"warn\" | \"info\" | \"http\" | \"verbose\" | \"debug\" | \"silly\";\n } | undefined;\n input?: {\n host?: string | undefined;\n hosts?: string[] | undefined;\n servers?: {\n host: string;\n port?: number | undefined;\n protocol?: (\"mqtt\" | \"mqtts\" | \"ws\" | \"wss\" | \"tcp\" | \"ssl\") | undefined;\n }[] | undefined;\n port?: number | undefined;\n protocol?: (\"mqtt\" | \"mqtts\" | \"ws\" | \"wss\" | \"tcp\" | \"ssl\") | undefined;\n username?: string | undefined;\n password?: string | undefined;\n clientId?: string | undefined;\n clean?: boolean | undefined;\n keepalive?: number | undefined;\n connectTimeout?: number | undefined;\n reconnectPeriod?: number | undefined;\n reconnectOnConnackError?: boolean | undefined;\n resubscribe?: boolean | undefined;\n queueQoSZero?: boolean | undefined;\n rejectUnauthorized?: boolean | undefined;\n properties?: {\n sessionExpiryInterval?: number | undefined;\n receiveMaximum?: number | undefined;\n maximumPacketSize?: number | undefined;\n topicAliasMaximum?: number | undefined;\n requestResponseInformation?: boolean | undefined;\n requestProblemInformation?: boolean | undefined;\n userProperties?: {\n [x: string]: string;\n } | undefined;\n } | undefined;\n ca?: string | undefined;\n cert?: string | undefined;\n key?: string | undefined;\n servername?: string | undefined;\n } | undefined;\n output?: {\n host?: string | undefined;\n hosts?: string[] | undefined;\n servers?: {\n host: string;\n port?: number | undefined;\n protocol?: (\"mqtt\" | \"mqtts\" | \"ws\" | \"wss\" | \"tcp\" | \"ssl\") | undefined;\n }[] | undefined;\n port?: number | undefined;\n protocol?: (\"mqtt\" | \"mqtts\" | \"ws\" | \"wss\" | \"tcp\" | \"ssl\") | undefined;\n username?: string | undefined;\n password?: string | undefined;\n clientId?: string | undefined;\n clean?: boolean | undefined;\n keepalive?: number | undefined;\n connectTimeout?: number | undefined;\n reconnectPeriod?: number | undefined;\n reconnectOnConnackError?: boolean | undefined;\n resubscribe?: boolean | undefined;\n queueQoSZero?: boolean | undefined;\n rejectUnauthorized?: boolean | undefined;\n properties?: {\n sessionExpiryInterval?: number | undefined;\n receiveMaximum?: number | undefined;\n maximumPacketSize?: number | undefined;\n topicAliasMaximum?: number | undefined;\n requestResponseInformation?: boolean | undefined;\n requestProblemInformation?: boolean | undefined;\n userProperties?: {\n [x: string]: string;\n } | undefined;\n } | undefined;\n ca?: string | undefined;\n cert?: string | undefined;\n key?: string | undefined;\n servername?: string | undefined;\n /** Opt-in MQTT output persistence; does not persist input subscriptions. */\n publishQueue?: {\n mode: \"buffered\" | \"durable\";\n storage?: \"local\" | \"runtime\";\n directory: string;\n maxRecords?: number;\n maxBytes?: number;\n memoryRecords?: number;\n memoryBytes?: number;\n maxMessageBytes?: number;\n maxDiskBytes?: number;\n minFreeBytes?: number;\n retryIntervalMs?: number;\n publishTimeoutMs?: number;\n } | undefined;\n } | undefined;\n infra: {\n host?: string | undefined;\n hosts?: string[] | undefined;\n servers?: {\n host: string;\n port?: number | undefined;\n protocol?: (\"mqtt\" | \"mqtts\" | \"ws\" | \"wss\" | \"tcp\" | \"ssl\") | undefined;\n }[] | undefined;\n port?: number | undefined;\n protocol?: (\"mqtt\" | \"mqtts\" | \"ws\" | \"wss\" | \"tcp\" | \"ssl\") | undefined;\n username?: string | undefined;\n password?: string | undefined;\n clientId?: string | undefined;\n clean?: boolean | undefined;\n keepalive?: number | undefined;\n connectTimeout?: number | undefined;\n reconnectPeriod?: number | undefined;\n reconnectOnConnackError?: boolean | undefined;\n resubscribe?: boolean | undefined;\n queueQoSZero?: boolean | undefined;\n rejectUnauthorized?: boolean | undefined;\n properties?: {\n sessionExpiryInterval?: number | undefined;\n receiveMaximum?: number | undefined;\n maximumPacketSize?: number | undefined;\n topicAliasMaximum?: number | undefined;\n requestResponseInformation?: boolean | undefined;\n requestProblemInformation?: boolean | undefined;\n userProperties?: {\n [x: string]: string;\n } | undefined;\n } | undefined;\n ca?: string | undefined;\n cert?: string | undefined;\n key?: string | undefined;\n servername?: string | undefined;\n };\n devops?: {\n provider?: \"azure-devops\";\n organization: string;\n project?: string | undefined;\n } | undefined;\n}\n\nexport interface AppConfig extends ProjectAppConfig {}\n"]}
1
+ {"version":3,"file":"app-config.js","sourceRoot":"","sources":["../../src/config/app-config.ts"],"names":[],"mappings":"","sourcesContent":["/* Auto-generated. Do not edit by hand. */\nexport interface ProjectAppConfig {\n uns: {\n graphql: string;\n rest: string;\n /** Bearer token used for service-to-service access to the UNS instance. */\n token?: string | undefined;\n /** Email used when authenticating to graphql endpoint of the UNS instance. */\n email?: string | undefined;\n /** Password or secret value paired with the UNS email. */\n password?: string | undefined;\n instanceMode?: \"wait\" | \"force\" | \"handover\";\n /** Process name used in MQTT topics and logs. */\n processName: string;\n handover?: boolean;\n /** Opt-in controller-correlated MQTT handover protocol. */\n handoverProtocol?: \"correlated-v1\" | undefined;\n /** Optional PM2/controller supervisor guard settings for this RTT instance. */\n supervisor?: {\n /** Enable controller/PM2 supervisor handling for this RTT instance. */\n enabled?: boolean;\n /** Let PM2 restart the process when it exits unexpectedly. */\n restartOnExit?: boolean;\n /** Optional PM2 memory restart limit in megabytes. */\n maxMemoryMb?: number | undefined;\n /** Let the controller auto-start this instance when required system-service runtime signals are absent. */\n restartOnUnhealthy?: boolean;\n /** How long runtime signals must stay unhealthy before the controller supervisor can act. */\n unhealthyAfterMs?: number;\n /** Minimum time between controller supervisor restart attempts for this instance. */\n restartCooldownMs?: number;\n } | undefined;\n jwksWellKnownUrl?: string | undefined;\n kidWellKnownUrl?: string | undefined;\n env?: \"dev\" | \"staging\" | \"test\" | \"prod\";\n };\n logging?: {\n adapter?: string;\n host: string;\n port?: number;\n level?: \"error\" | \"warn\" | \"info\" | \"http\" | \"verbose\" | \"debug\" | \"silly\";\n } | undefined;\n input?: {\n host?: string | undefined;\n hosts?: string[] | undefined;\n servers?: {\n host: string;\n port?: number | undefined;\n protocol?: (\"mqtt\" | \"mqtts\" | \"ws\" | \"wss\" | \"tcp\" | \"ssl\") | undefined;\n }[] | undefined;\n port?: number | undefined;\n protocol?: (\"mqtt\" | \"mqtts\" | \"ws\" | \"wss\" | \"tcp\" | \"ssl\") | undefined;\n username?: string | undefined;\n password?: string | undefined;\n clientId?: string | undefined;\n clean?: boolean | undefined;\n keepalive?: number | undefined;\n connectTimeout?: number | undefined;\n reconnectPeriod?: number | undefined;\n reconnectOnConnackError?: boolean | undefined;\n resubscribe?: boolean | undefined;\n queueQoSZero?: boolean | undefined;\n rejectUnauthorized?: boolean | undefined;\n properties?: {\n sessionExpiryInterval?: number | undefined;\n receiveMaximum?: number | undefined;\n maximumPacketSize?: number | undefined;\n topicAliasMaximum?: number | undefined;\n requestResponseInformation?: boolean | undefined;\n requestProblemInformation?: boolean | undefined;\n userProperties?: {\n [x: string]: string;\n } | undefined;\n } | undefined;\n ca?: string | undefined;\n cert?: string | undefined;\n key?: string | undefined;\n servername?: string | undefined;\n } | undefined;\n output?: {\n host?: string | undefined;\n hosts?: string[] | undefined;\n servers?: {\n host: string;\n port?: number | undefined;\n protocol?: (\"mqtt\" | \"mqtts\" | \"ws\" | \"wss\" | \"tcp\" | \"ssl\") | undefined;\n }[] | undefined;\n port?: number | undefined;\n protocol?: (\"mqtt\" | \"mqtts\" | \"ws\" | \"wss\" | \"tcp\" | \"ssl\") | undefined;\n username?: string | undefined;\n password?: string | undefined;\n clientId?: string | undefined;\n clean?: boolean | undefined;\n keepalive?: number | undefined;\n connectTimeout?: number | undefined;\n reconnectPeriod?: number | undefined;\n reconnectOnConnackError?: boolean | undefined;\n resubscribe?: boolean | undefined;\n queueQoSZero?: boolean | undefined;\n rejectUnauthorized?: boolean | undefined;\n properties?: {\n sessionExpiryInterval?: number | undefined;\n receiveMaximum?: number | undefined;\n maximumPacketSize?: number | undefined;\n topicAliasMaximum?: number | undefined;\n requestResponseInformation?: boolean | undefined;\n requestProblemInformation?: boolean | undefined;\n userProperties?: {\n [x: string]: string;\n } | undefined;\n } | undefined;\n ca?: string | undefined;\n cert?: string | undefined;\n key?: string | undefined;\n servername?: string | undefined;\n /** Opt-in MQTT output persistence; does not persist input subscriptions. */\n publishQueue?: {\n enabled?: boolean;\n mode: \"buffered\" | \"durable\";\n storage?: \"local\" | \"runtime\";\n directory: string;\n maxRecords?: number;\n maxBytes?: number;\n memoryRecords?: number;\n memoryBytes?: number;\n maxMessageBytes?: number;\n maxDiskBytes?: number;\n minFreeBytes?: number;\n retryIntervalMs?: number;\n publishTimeoutMs?: number;\n } | undefined;\n } | undefined;\n infra: {\n host?: string | undefined;\n hosts?: string[] | undefined;\n servers?: {\n host: string;\n port?: number | undefined;\n protocol?: (\"mqtt\" | \"mqtts\" | \"ws\" | \"wss\" | \"tcp\" | \"ssl\") | undefined;\n }[] | undefined;\n port?: number | undefined;\n protocol?: (\"mqtt\" | \"mqtts\" | \"ws\" | \"wss\" | \"tcp\" | \"ssl\") | undefined;\n username?: string | undefined;\n password?: string | undefined;\n clientId?: string | undefined;\n clean?: boolean | undefined;\n keepalive?: number | undefined;\n connectTimeout?: number | undefined;\n reconnectPeriod?: number | undefined;\n reconnectOnConnackError?: boolean | undefined;\n resubscribe?: boolean | undefined;\n queueQoSZero?: boolean | undefined;\n rejectUnauthorized?: boolean | undefined;\n properties?: {\n sessionExpiryInterval?: number | undefined;\n receiveMaximum?: number | undefined;\n maximumPacketSize?: number | undefined;\n topicAliasMaximum?: number | undefined;\n requestResponseInformation?: boolean | undefined;\n requestProblemInformation?: boolean | undefined;\n userProperties?: {\n [x: string]: string;\n } | undefined;\n } | undefined;\n ca?: string | undefined;\n cert?: string | undefined;\n key?: string | undefined;\n servername?: string | undefined;\n };\n devops?: {\n provider?: \"azure-devops\";\n organization: string;\n project?: string | undefined;\n } | undefined;\n}\n\nexport interface AppConfig extends ProjectAppConfig {}\n"]}
@@ -0,0 +1,29 @@
1
+ import { z } from "zod";
2
+ import type { MqttPublishQueueStatus } from "../uns-mqtt/publish-queue-contract.js";
3
+ /** Generic process-local handshake. The host supplies identity and durable receipts. */
4
+ export declare const MQTT_DRAIN_HANDLER: unique symbol;
5
+ export declare const MQTT_DRAIN_READY_EVENT = "uns-kit:mqtt-drain-ready";
6
+ export declare const mqttDrainReceiptSchema: z.ZodObject<{
7
+ protocol: z.ZodLiteral<1>;
8
+ state: z.ZodLiteral<"drained">;
9
+ pendingRecords: z.ZodLiteral<0>;
10
+ outputs: z.ZodNumber;
11
+ }, z.core.$strict>;
12
+ export type MqttDrainReceipt = z.infer<typeof mqttDrainReceiptSchema>;
13
+ export declare const mqttDrainCapabilitySchema: z.ZodObject<{
14
+ protocolVersion: z.ZodLiteral<1>;
15
+ }, z.core.$strict>;
16
+ export declare function readMqttDrainCapability(packageRoot: string): 1 | undefined;
17
+ export interface MqttDrainOutput {
18
+ flush(timeoutMs: number): Promise<void>;
19
+ sealPublishes(): void;
20
+ getPublishQueueStatus(): MqttPublishQueueStatus | undefined;
21
+ }
22
+ /** Quiesce before flushing. A timeout is a blocked attempt, never a clean exit. */
23
+ export declare function drainMqttForMigration(options: {
24
+ quiesce(): Promise<void>;
25
+ finishAccepted(): Promise<void>;
26
+ outputs: readonly MqttDrainOutput[];
27
+ timeoutMs?: number;
28
+ }): Promise<MqttDrainReceipt>;
29
+ //# sourceMappingURL=mqtt-drain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mqtt-drain.d.ts","sourceRoot":"","sources":["../../src/runtime/mqtt-drain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAEpF,wFAAwF;AACxF,eAAO,MAAM,kBAAkB,eAAsC,CAAC;AACtE,eAAO,MAAM,sBAAsB,6BAA6B,CAAC;AACjE,eAAO,MAAM,sBAAsB;;;;;kBAKjC,CAAC;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AACtE,eAAO,MAAM,yBAAyB;;kBAAoD,CAAC;AAC3F,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAa1E;AACD,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,aAAa,IAAI,IAAI,CAAC;IACtB,qBAAqB,IAAI,sBAAsB,GAAG,SAAS,CAAC;CAC7D;AAED,mFAAmF;AACnF,wBAAsB,qBAAqB,CAAC,OAAO,EAAE;IACnD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,OAAO,EAAE,SAAS,eAAe,EAAE,CAAC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA8B5B"}
@@ -0,0 +1,70 @@
1
+ import { z } from "zod";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ /** Generic process-local handshake. The host supplies identity and durable receipts. */
5
+ export const MQTT_DRAIN_HANDLER = Symbol.for("uns-kit.mqtt-drain.v1");
6
+ export const MQTT_DRAIN_READY_EVENT = "uns-kit:mqtt-drain-ready";
7
+ export const mqttDrainReceiptSchema = z.strictObject({
8
+ protocol: z.literal(1),
9
+ state: z.literal("drained"),
10
+ pendingRecords: z.literal(0),
11
+ outputs: z.number().int().min(0).max(64),
12
+ });
13
+ export const mqttDrainCapabilitySchema = z.strictObject({ protocolVersion: z.literal(1) });
14
+ export function readMqttDrainCapability(packageRoot) {
15
+ const file = path.join(packageRoot, "package.json");
16
+ let stat;
17
+ try {
18
+ stat = fs.lstatSync(file);
19
+ }
20
+ catch (error) {
21
+ if (error.code === "ENOENT")
22
+ return undefined;
23
+ throw error;
24
+ }
25
+ if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 1048576)
26
+ throw Error("Unsafe installed MQTT drain descriptor");
27
+ const value = JSON.parse(fs.readFileSync(file, "utf8"))?.unsDatahub?.mqttDrain;
28
+ if (value === undefined)
29
+ return undefined;
30
+ mqttDrainCapabilitySchema.parse(value);
31
+ return 1;
32
+ }
33
+ /** Quiesce before flushing. A timeout is a blocked attempt, never a clean exit. */
34
+ export async function drainMqttForMigration(options) {
35
+ const timeoutMs = options.timeoutMs ?? 30_000;
36
+ if (!Number.isInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 300_000 || options.outputs.length > 64)
37
+ throw Error("Invalid bounded MQTT migration drain");
38
+ let timer;
39
+ const deadline = Date.now() + timeoutMs;
40
+ let expired = false;
41
+ const work = (async () => {
42
+ await options.quiesce();
43
+ await options.finishAccepted();
44
+ const remaining = deadline - Date.now();
45
+ if (remaining <= 0)
46
+ throw Error("MQTT migration drain timed out; retain the original owner");
47
+ await Promise.all(options.outputs.map(output => output.flush(remaining)));
48
+ for (const output of options.outputs) {
49
+ const status = output.getPublishQueueStatus();
50
+ if (status && (status.pendingRecords !== 0 || status.memoryRecords !== 0 || status.diskRecords !== 0 || status.inFlight || status.state === "blocked"))
51
+ throw Error("MQTT output is not confirmed empty; migration remains blocked");
52
+ }
53
+ if (expired || Date.now() > deadline)
54
+ throw Error("MQTT migration drain expired; outcome must be reconciled");
55
+ // No await between the final checks and admission fences.
56
+ for (const output of options.outputs)
57
+ output.sealPublishes();
58
+ return mqttDrainReceiptSchema.parse({ protocol: 1, state: "drained", pendingRecords: 0, outputs: options.outputs.length });
59
+ })();
60
+ try {
61
+ return await Promise.race([work, new Promise((_, reject) => {
62
+ timer = setTimeout(() => { expired = true; reject(Error("MQTT migration drain timed out; pending work retained")); }, timeoutMs);
63
+ })]);
64
+ }
65
+ finally {
66
+ if (timer)
67
+ clearTimeout(timer);
68
+ }
69
+ }
70
+ //# sourceMappingURL=mqtt-drain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mqtt-drain.js","sourceRoot":"","sources":["../../src/runtime/mqtt-drain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,wFAAwF;AACxF,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AACtE,MAAM,CAAC,MAAM,sBAAsB,GAAG,0BAA0B,CAAC;AACjE,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,YAAY,CAAC;IACnD,QAAQ,EAAE,CAAC,CA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IAAI,OAAO,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ;YAAE,MAAM,KAAK,CAAC,0DAA0D,CAAC,CAAC;QAC9G,0DAA0D;QAC1D,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,OAAO;YAAE,MAAM,CAAC,aAAa,EAAE,CAAC;QAC7D,OAAO,sBAAsB,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC7H,CAAC,CAAC,EAAE,CAAC;IACL,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;gBAChE,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,GAAG,OAAO,GAAG,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,uDAAuD,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;YACnI,CAAC,CAAC,CAAC,CAAC,CAAC;IACP,CAAC;YAAS,CAAC;QACT,IAAI,KAAK;YAAE,YAAY,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;AACH,CAAC","sourcesContent":["import { z } from \"zod\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { MqttPublishQueueStatus } from \"../uns-mqtt/publish-queue-contract.js\";\n\n/** Generic process-local handshake. The host supplies identity and durable receipts. */\nexport const MQTT_DRAIN_HANDLER = Symbol.for(\"uns-kit.mqtt-drain.v1\");\nexport const MQTT_DRAIN_READY_EVENT = \"uns-kit:mqtt-drain-ready\";\nexport const mqttDrainReceiptSchema = z.strictObject({\n protocol: z.literal(1),\n state: z.literal(\"drained\"),\n pendingRecords: z.literal(0),\n outputs: z.number().int().min(0).max(64),\n});\nexport type MqttDrainReceipt = z.infer<typeof mqttDrainReceiptSchema>;\nexport const mqttDrainCapabilitySchema = z.strictObject({ protocolVersion: z.literal(1) });\nexport function readMqttDrainCapability(packageRoot: string): 1 | undefined {\n const file = path.join(packageRoot, \"package.json\");\n let stat: fs.Stats;\n try { stat = fs.lstatSync(file); }\n catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") return undefined;\n throw error;\n }\n if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 1048576) throw Error(\"Unsafe installed MQTT drain descriptor\");\n const value = JSON.parse(fs.readFileSync(file, \"utf8\"))?.unsDatahub?.mqttDrain;\n if (value === undefined) return undefined;\n mqttDrainCapabilitySchema.parse(value);\n return 1;\n}\nexport interface MqttDrainOutput {\n flush(timeoutMs: number): Promise<void>;\n sealPublishes(): void;\n getPublishQueueStatus(): MqttPublishQueueStatus | undefined;\n}\n\n/** Quiesce before flushing. A timeout is a blocked attempt, never a clean exit. */\nexport async function drainMqttForMigration(options: {\n quiesce(): Promise<void>;\n finishAccepted(): Promise<void>;\n outputs: readonly MqttDrainOutput[];\n timeoutMs?: number;\n}): Promise<MqttDrainReceipt> {\n const timeoutMs = options.timeoutMs ?? 30_000;\n if (!Number.isInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 300_000 || options.outputs.length > 64)\n throw Error(\"Invalid bounded MQTT migration drain\");\n let timer: ReturnType<typeof setTimeout> | undefined;\n const deadline = Date.now() + timeoutMs;\n let expired = false;\n const work = (async () => {\n await options.quiesce();\n await options.finishAccepted();\n const remaining = deadline - Date.now();\n if (remaining <= 0) throw Error(\"MQTT migration drain timed out; retain the original owner\");\n await Promise.all(options.outputs.map(output => output.flush(remaining)));\n for (const output of options.outputs) {\n const status = output.getPublishQueueStatus();\n if (status && (status.pendingRecords !== 0 || status.memoryRecords !== 0 || status.diskRecords !== 0 || status.inFlight || status.state === \"blocked\"))\n throw Error(\"MQTT output is not confirmed empty; migration remains blocked\");\n }\n if (expired || Date.now() > deadline) throw Error(\"MQTT migration drain expired; outcome must be reconciled\");\n // No await between the final checks and admission fences.\n for (const output of options.outputs) output.sealPublishes();\n return mqttDrainReceiptSchema.parse({ protocol: 1, state: \"drained\", pendingRecords: 0, outputs: options.outputs.length });\n })();\n try {\n return await Promise.race([work, new Promise<never>((_, reject) => {\n timer = setTimeout(() => { expired = true; reject(Error(\"MQTT migration drain timed out; pending work retained\")); }, timeoutMs);\n })]);\n } finally {\n if (timer) clearTimeout(timer);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"mqtt-output-state-contract.d.ts","sourceRoot":"","sources":["../../src/runtime/mqtt-output-state-contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,eAAO,MAAM,qBAAqB;;;;;;;EAA2B,CAAC;AAC9D,eAAO,MAAM,2BAA2B;;;;;;;;;;;kBAcqD,CAAC;AAE9F,qFAAqF;AACrF,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAOvI"}
1
+ {"version":3,"file":"mqtt-output-state-contract.d.ts","sourceRoot":"","sources":["../../src/runtime/mqtt-output-state-contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,eAAO,MAAM,qBAAqB;;;;;;;EAA2B,CAAC;AAC9D,eAAO,MAAM,2BAA2B;;;;;;;;;;;kBAcqD,CAAC;AAE9F,qFAAqF;AACrF,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAQvI"}
@@ -25,6 +25,8 @@ export function managedMqttOutputBinding(config, root) {
25
25
  if (value?.output?.publishQueue === undefined)
26
26
  return undefined;
27
27
  const queue = mqttPublishQueueSchema.parse(value.output.publishQueue);
28
+ if (queue.enabled === false)
29
+ return undefined;
28
30
  if (queue.storage !== "runtime" || !root)
29
31
  throw Error("Controller-managed MQTT output requires storage=runtime and a reviewed persistent Runtime mount");
30
32
  return { directory: queue.directory, relative: outputStateRelative(root, queue.directory) };
@@ -1 +1 @@
1
- {"version":3,"file":"mqtt-output-state-contract.js","sourceRoot":"","sources":["../../src/runtime/mqtt-output-state-contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,KAAK,MAAM,mCAAmC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAEtE,MAAM,CAAC,MAAM,qBAAqB,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;AAC9D,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC;KACzC,YAAY,CAAC;IACZ,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3B,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACpC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC;IAC9C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,qBAAqB,CAAC,aAAa,CAAC;IACxE,OAAO,EAAE,CAAC;SACP,MAAM,EAAE;SACR,GAAG,EAAE;SACL,GAAG,CAAC,CAAC,CAAC;SACN,GAAG,CAAC,qBAAqB,CAAC,aAAa,GAAG,qBAAqB,CAAC,sBAAsB,CAAC;IAC1F,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,qBAAqB,CAAC,mBAAmB,CAAC;IACjF,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC;CAC3C,CAAC;KACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;AAE9F,qFAAqF;AACrF,MAAM,UAAU,wBAAwB,CAAC,MAAe,EAAE,IAAwB;IAChF,MAAM,KAAK,GAAG,MAAiD,CAAC;IAChE,IAAI,KAAK,EAAE,MAAM,EAAE,YAAY,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAChE,MAAM,KAAK,GAAG,sBAAsB,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IACtE,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS,IAAI,CAAC,IAAI;QACtC,MAAM,KAAK,CAAC,iGAAiG,CAAC,CAAC;IACjH,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,QAAQ,EAAE,mBAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;AAC9F,CAAC","sourcesContent":["import { z } from \"zod\";\n\nimport { mqttPublishQueueSchema } from \"../uns-mqtt/publish-queue-contract.js\";\nimport fixed from \"./mqtt-output-state-contract.json\" with { type: \"json\" };\nimport { outputStateLimits } from \"./mqtt-output-state-program.mjs\";\nimport { outputStateRelative } from \"./mqtt-output-state-program.mjs\";\n\nexport const mqttOutputStateLimits = outputStateLimits(fixed);\nexport const mqttOutputStateBackupSchema = z\n .strictObject({\n schemaVersion: z.literal(1),\n state: z.enum([\"included\", \"empty\"]),\n rootSha256: z.string().regex(/^[a-f0-9]{64}$/),\n queues: z.number().int().min(0).max(mqttOutputStateLimits.maximumQueues),\n records: z\n .number()\n .int()\n .min(0)\n .max(mqttOutputStateLimits.maximumQueues * mqttOutputStateLimits.maximumRecordsPerQueue),\n bytes: z.number().int().positive().max(mqttOutputStateLimits.maximumCapsuleBytes),\n sha256: z.string().regex(/^[a-f0-9]{64}$/),\n })\n .refine((v) => (v.state === \"included\" ? v.queues > 0 : v.queues === 0 && v.records === 0));\n\n/** Controller inspection of standard SDK configuration, without application code. */\nexport function managedMqttOutputBinding(config: unknown, root: string | undefined): { directory: string; relative: string } | undefined {\n const value = config as { output?: { publishQueue?: unknown } };\n if (value?.output?.publishQueue === undefined) return undefined;\n const queue = mqttPublishQueueSchema.parse(value.output.publishQueue);\n if (queue.storage !== \"runtime\" || !root)\n throw Error(\"Controller-managed MQTT output requires storage=runtime and a reviewed persistent Runtime mount\");\n return { directory: queue.directory, relative: outputStateRelative(root, queue.directory) };\n}\n"]}
1
+ {"version":3,"file":"mqtt-output-state-contract.js","sourceRoot":"","sources":["../../src/runtime/mqtt-output-state-contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,KAAK,MAAM,mCAAmC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAEtE,MAAM,CAAC,MAAM,qBAAqB,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;AAC9D,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC;KACzC,YAAY,CAA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tE,IAAI,KAAK,CAAC,OAAO,KAAK,KAAK;QAAE,OAAO,SAAS,CAAC;IAC9C,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS,IAAI,CAAC,IAAI;QACtC,MAAM,KAAK,CAAC,iGAAiG,CAAC,CAAC;IACjH,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,QAAQ,EAAE,mBAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;AAC9F,CAAC","sourcesContent":["import { z } from \"zod\";\n\nimport { mqttPublishQueueSchema } from \"../uns-mqtt/publish-queue-contract.js\";\nimport fixed from \"./mqtt-output-state-contract.json\" with { type: \"json\" };\nimport { outputStateLimits } from \"./mqtt-output-state-program.mjs\";\nimport { outputStateRelative } from \"./mqtt-output-state-program.mjs\";\n\nexport const mqttOutputStateLimits = outputStateLimits(fixed);\nexport const mqttOutputStateBackupSchema = z\n .strictObject({\n schemaVersion: z.literal(1),\n state: z.enum([\"included\", \"empty\"]),\n rootSha256: z.string().regex(/^[a-f0-9]{64}$/),\n queues: z.number().int().min(0).max(mqttOutputStateLimits.maximumQueues),\n records: z\n .number()\n .int()\n .min(0)\n .max(mqttOutputStateLimits.maximumQueues * mqttOutputStateLimits.maximumRecordsPerQueue),\n bytes: z.number().int().positive().max(mqttOutputStateLimits.maximumCapsuleBytes),\n sha256: z.string().regex(/^[a-f0-9]{64}$/),\n })\n .refine((v) => (v.state === \"included\" ? v.queues > 0 : v.queues === 0 && v.records === 0));\n\n/** Controller inspection of standard SDK configuration, without application code. */\nexport function managedMqttOutputBinding(config: unknown, root: string | undefined): { directory: string; relative: string } | undefined {\n const value = config as { output?: { publishQueue?: unknown } };\n if (value?.output?.publishQueue === undefined) return undefined;\n const queue = mqttPublishQueueSchema.parse(value.output.publishQueue);\n if (queue.enabled === false) return undefined;\n if (queue.storage !== \"runtime\" || !root)\n throw Error(\"Controller-managed MQTT output requires storage=runtime and a reviewed persistent Runtime mount\");\n return { directory: queue.directory, relative: outputStateRelative(root, queue.directory) };\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { type MqttDrainReceipt } from "../runtime/mqtt-drain.js";
1
2
  import UnsMqttProxy from "../uns-mqtt/uns-mqtt-proxy.js";
2
3
  import type { UnsMqttProxyStopOptions } from "../uns-mqtt/uns-mqtt-proxy.js";
3
4
  import { type UnsServiceMetadata, type UnsServiceMetadataInput } from "./service-metadata.js";
@@ -31,6 +32,8 @@ declare class UnsProxyProcess {
31
32
  private statusMonitor;
32
33
  private serviceMetadataTopic;
33
34
  private shutdownPromise;
35
+ private migrationDrainPromise;
36
+ private migrationDrainHandler?;
34
37
  static pluginApiVersion: number;
35
38
  private static registered;
36
39
  private static registeredMethodNames;
@@ -58,10 +61,11 @@ declare class UnsProxyProcess {
58
61
  * with live process status to decide whether a service is currently healthy.
59
62
  */
60
63
  publishServiceMetadata(metadata: UnsServiceMetadataInput): Promise<UnsServiceMetadata>;
61
- /**
62
- * Shuts down the process by clearing intervals, timeouts, and removing
63
- * MQTT event listeners, and stopping the StatusMonitor.
64
- */
64
+ /** Call after application input handlers and shutdown hooks are prepared. */
65
+ enableMigrationDrain(): void;
66
+ /** Works without a Controller too; success means confirmed empty output and closed owners. */
67
+ drainForMigration(timeoutMs?: number): Promise<MqttDrainReceipt>;
68
+ /** Stop process timers, status publication and all owned MQTT proxies. */
65
69
  shutdown(options?: UnsMqttProxyStopOptions): Promise<void>;
66
70
  private performShutdown;
67
71
  }
@@ -1 +1 @@
1
- {"version":3,"file":"uns-proxy-process.d.ts","sourceRoot":"","sources":["../../src/uns/uns-proxy-process.ts"],"names":[],"mappings":"AAMA,OAAO,YAAY,MAAM,+BAA+B,CAAC;AACzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAK7E,OAAO,EAAE,KAAK,kBAAkB,EAAE,KAAK,uBAAuB,EAA2B,MAAM,uBAAuB,CAAC;AAEvH,OAAO,EAAe,cAAc,EAAE,qBAAq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AkB,CAC7B,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,OAAO,EACjB,aAAa,CAAC,EAAE,cAAc,GAC7B,OAAO,CAAC,YAAY,CAAC;IAwCX,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC;IAMtD;;;;;;OAMG;IACU,sBAAsB,CAAC,QAAQ,EAAE,uBAAuB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAWnG,6EAA6E;IACtE,oBAAoB,IAAI,IAAI;IASnC,8FAA8F;IACvF,iBAAiB,CAAC,SAAS,SAA6C,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAkB3G,0EAA0E;IACnE,QAAQ,CAAC,OAAO,GAAE,uBAA4B,GAAG,OAAO,CAAC,IAAI,CAAC;YASvD,eAAe;CAqD9B;AAED,UAAU,eAAe;CAAG;AAE5B,eAAe,eAAe,CAAC;AAC/B,YAAY,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { MQTT_DRAIN_HANDLER, MQTT_DRAIN_READY_EVENT, drainMqttForMigration } from "../runtime/mqtt-drain.js";
1
2
  import { randomBytes } from "crypto";
2
3
  import logger from "../logger.js";
3
4
  import MqttProxy from "../uns-mqtt/mqtt-proxy.js";
@@ -24,6 +25,8 @@ class UnsProxyProcess {
24
25
  statusMonitor;
25
26
  serviceMetadataTopic;
26
27
  shutdownPromise = null;
28
+ migrationDrainPromise = null;
29
+ migrationDrainHandler;
27
30
  // Plugin
28
31
  static pluginApiVersion = 1;
29
32
  static registered = new Set();
@@ -149,7 +152,7 @@ class UnsProxyProcess {
149
152
  * Creates a new UNS proxy instance and stores it for future management.
150
153
  */
151
154
  async createUnsMqttProxy(mqttHost, instanceName, instanceMode, handover, unsParameters) {
152
- if (unsParameters?.publishQueue && handover) {
155
+ if (unsParameters?.publishQueue && unsParameters.publishQueue.enabled !== false && handover) {
153
156
  throw new Error("Persistent MQTT output requires handover=false and one owner; legacy RAM handover does not transfer an outbox");
154
157
  }
155
158
  // Wait until the MQTT connection is established before proceeding.
@@ -200,10 +203,37 @@ class UnsProxyProcess {
200
203
  await this.processMqttProxy.publish(this.serviceMetadataTopic, JSON.stringify(resolved), { retain: true });
201
204
  return resolved;
202
205
  }
203
- /**
204
- * Shuts down the process by clearing intervals, timeouts, and removing
205
- * MQTT event listeners, and stopping the StatusMonitor.
206
- */
206
+ /** Call after application input handlers and shutdown hooks are prepared. */
207
+ enableMigrationDrain() {
208
+ const registry = globalThis;
209
+ if (this.migrationDrainHandler)
210
+ return;
211
+ if (registry[MQTT_DRAIN_HANDLER])
212
+ throw Error("One migration drain owner is allowed per process");
213
+ this.migrationDrainHandler = () => this.drainForMigration();
214
+ registry[MQTT_DRAIN_HANDLER] = this.migrationDrainHandler;
215
+ process.emit(MQTT_DRAIN_READY_EVENT, { protocol: 1 });
216
+ }
217
+ /** Works without a Controller too; success means confirmed empty output and closed owners. */
218
+ drainForMigration(timeoutMs = this.handoverShutdown?.timeoutMs ?? 30_000) {
219
+ if (this.migrationDrainPromise)
220
+ return this.migrationDrainPromise;
221
+ this.migrationDrainPromise = (async () => {
222
+ const receipt = await drainMqttForMigration({
223
+ quiesce: async () => {
224
+ this.handoverShutdown?.onRelease?.();
225
+ await Promise.all(this.unsMqttProxies.map(proxy => proxy.setSubscriberPassiveAndDrainQueue()));
226
+ },
227
+ finishAccepted: async () => { await this.handoverShutdown?.drain(); },
228
+ outputs: this.unsMqttProxies,
229
+ timeoutMs,
230
+ });
231
+ await this.shutdown({ drain: true, timeoutMs });
232
+ return receipt;
233
+ })().catch(error => { this.migrationDrainPromise = null; throw error; });
234
+ return this.migrationDrainPromise;
235
+ }
236
+ /** Stop process timers, status publication and all owned MQTT proxies. */
207
237
  shutdown(options = {}) {
208
238
  if (this.shutdownPromise) {
209
239
  return this.shutdownPromise;
@@ -254,6 +284,12 @@ class UnsProxyProcess {
254
284
  if (shutdownErrors.length > 0) {
255
285
  throw new AggregateError(shutdownErrors, `${this.processName} - Shutdown completed with errors.`);
256
286
  }
287
+ if (this.migrationDrainHandler) {
288
+ const registry = globalThis;
289
+ if (registry[MQTT_DRAIN_HANDLER] === this.migrationDrainHandler)
290
+ delete registry[MQTT_DRAIN_HANDLER];
291
+ process.channel?.unref();
292
+ }
257
293
  logger.info(`${this.processName} - Shutdown complete.`);
258
294
  }
259
295
  }
@@ -1 +1 @@
1
- {"version":3,"file":"uns-proxy-process.js","sourceRoot":"","sources":["../../src/uns/uns-proxy-process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,MAAM,MAAM,cAAc,CAAC;AAElC,OAAO,SAAS,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,YAAY,MAAM,+BAA+B,CAAC;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAA8B,MAAM,wBAAwB,CAAC;AAC9F,mDAAmD;AACnD,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAyD,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AACvH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAqB5C,MAAM,eAAe;IACX,MAAM,GAAY,KAAK,CAAC;IACxB,kBAAkB,CAAS;IAC3B,WAAW,CAAS;IACpB,SAAS,CAAS;IAClB,UAAU,CAAqB;IAC/B,gBAAgB,CAAoC;IACpD,cAAc,CAAiB;IAC/B,aAAa,CAAY;IACzB,gBAAgB,CAAY;IAC5B,eAAe,CAAkB;IACjC,aAAa,CAAgB;IAC7B,oBAAoB,CAAS;IAC7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AAC,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;gBACjG,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,WAAW,qCAAqC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;gBACvF,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;QAED,IAAI,CAAC;YACH,IAAI,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBACrD,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC;YACrC,CAAC;QACH,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,MAAM,MAAM,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7D,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,WAAW,iCAAiC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;YACnF,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC9B,CAAC;QAED,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,cAAc,CAAC,cAAc,EAAE,GAAG,IAAI,CAAC,WAAW,oCAAoC,CAAC,CAAC;QACpG,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,uBAAuB,CAAC,CAAC;IAC1D,CAAC;;AAKH,eAAe,eAAe,CAAC;AAE/B,OAAO,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import { randomBytes } from \"crypto\";\n\nimport logger from \"../logger.js\";\nimport { IMqttParameters } from \"../uns-mqtt/mqtt-interfaces.js\";\nimport MqttProxy from \"../uns-mqtt/mqtt-proxy.js\";\nimport { MqttTopicBuilder } from \"../uns-mqtt/mqtt-topic-builder.js\";\nimport UnsMqttProxy from \"../uns-mqtt/uns-mqtt-proxy.js\";\nimport type { UnsMqttProxyStopOptions } from \"../uns-mqtt/uns-mqtt-proxy.js\";\nimport { HandoverManager } from \"./handover-manager.js\";\nimport { validateHandoverShutdown, type HandoverShutdownHooks } from \"./handover-shutdown.js\";\n// Import configuration and initialization modules.\nimport { MQTT_UPDATE_INTERVAL, PACKAGE_INFO } from \"./process-config.js\";\nimport { type UnsServiceMetadata, type UnsServiceMetadataInput, buildUnsServiceMetadata } from \"./service-metadata.js\";\nimport { StatusMonitor } from \"./status-monitor.js\";\nimport { IUnsMessage, IUnsParameters, IUnsProcessParameters, UnsEvents } from \"./uns-interfaces.js\";\nimport { UnsPacket } from \"./uns-packet.js\";\n\n/**\n * UnsProxyProcess is responsible for managing the process lifecycle,\n * configuring MQTT (subscriptions and publishing for status updates), and\n * handling UNS proxy instances.\n *\n * It leverages HandoverManager for handover events and StatusMonitor for health reporting.\n */\nexport type UnsProxyProcessPluginMethod = (this: UnsProxyProcess, ...args: unknown[]) => unknown;\n\nexport type UnsProxyProcessPluginMethods = Record<string, UnsProxyProcessPluginMethod>;\n\nexport interface UnsProxyProcessPluginApi {\n version: number;\n define(methods: UnsProxyProcessPluginMethods): void;\n UnsProxyProcess: typeof UnsProxyProcess;\n}\n\nexport type UnsProxyProcessPlugin = (api: UnsProxyProcessPluginApi) => void;\n\nclass UnsProxyProcess {\n private active: boolean = false;\n private processStatusTopic: string;\n private processName: string;\n private processId: string;\n private handoverId: string | undefined;\n private handoverShutdown: HandoverShutdownHooks | undefined;\n private unsMqttProxies: UnsMqttProxy[];\n private unsApiProxies: unknown[];\n private processMqttProxy: MqttProxy;\n private handoverManager: HandoverManager;\n private statusMonitor: StatusMonitor;\n private serviceMetadataTopic: string;\n private shutdownPromise: Promise<void> | null = null;\n\n // Plugin\n static pluginApiVersion = 1;\n private static registered = new Set<UnsProxyProcessPlugin>();\n private static registeredMethodNames = new Set<string>();\n private static applied = false;\n\n static use(plugin: UnsProxyProcessPlugin) {\n if (this.registered.has(plugin)) return this;\n this.registered.add(plugin);\n if (this.applied) this.applyPlugin(plugin);\n return this;\n }\n\n private static applyPlugin(plugin: UnsProxyProcessPlugin) {\n const define: UnsProxyProcessPluginApi[\"define\"] = (methods) => {\n for (const [name, fn] of Object.entries(methods)) {\n if (typeof fn !== \"function\") {\n throw new TypeError(`UnsProxyProcess plugin attempted to register non-function member \\\"${name}\\\".`);\n }\n if (this.registeredMethodNames.has(name) || Reflect.has(this.prototype, name)) {\n throw new Error(`UnsProxyProcess plugin attempted to overwrite existing member \\\"${name}\\\".`);\n }\n Object.defineProperty(this.prototype, name, {\n value: fn,\n writable: true,\n configurable: true,\n enumerable: false,\n });\n this.registeredMethodNames.add(name);\n }\n };\n\n plugin({\n define,\n version: this.pluginApiVersion,\n UnsProxyProcess: this,\n });\n }\n\n private static applyAll() {\n if (this.applied) return;\n this.applied = true;\n for (const p of this.registered) this.applyPlugin(p);\n }\n\n // References for cleanup.\n private mqttInputHandler: (event: any) => void;\n\n constructor(mqttHost: string, unsProxyProcessParameters: IUnsProcessParameters) {\n (this.constructor as typeof UnsProxyProcess).applyAll(); // Activate all the plugins\n\n this.unsMqttProxies = [];\n this.unsApiProxies = [];\n if (!unsProxyProcessParameters?.processName) {\n throw new Error(\"UnsProxyProcess requires a processName in configuration.\");\n }\n validateHandoverShutdown(unsProxyProcessParameters.handoverShutdown);\n this.handoverShutdown = unsProxyProcessParameters.handoverShutdown\n ? { ...unsProxyProcessParameters.handoverShutdown } : undefined;\n this.processName = unsProxyProcessParameters.processName;\n this.processId = randomBytes(16).toString(\"hex\");\n this.handoverId = unsProxyProcessParameters.handoverId ?? process.env[\"UNS_HANDOVER_ID\"];\n const { name: packageName, version } = PACKAGE_INFO;\n\n // Instantiate the topic builder.\n const topicBuilder = new MqttTopicBuilder(\n `uns-infra/${MqttTopicBuilder.sanitizeTopicPart(packageName)}/${MqttTopicBuilder.sanitizeTopicPart(version)}/${MqttTopicBuilder.sanitizeTopicPart(this.processName)}/`,\n );\n\n // Generate topics.\n const processStatusTopic = topicBuilder.getProcessStatusTopic();\n const handoverTopic = topicBuilder.getHandoverTopic();\n const wildcardActiveTopic = topicBuilder.getWildcardActiveTopic();\n const serviceMetadataTopic = topicBuilder.getServiceMetadataTopic();\n\n this.processStatusTopic = processStatusTopic;\n this.serviceMetadataTopic = serviceMetadataTopic;\n\n // Configure MQTT topics for subscription.\n const mqttSubToTopics = unsProxyProcessParameters?.mqttSubToTopics ?? [wildcardActiveTopic, handoverTopic];\n const mqttParameters: IMqttParameters = {\n mqttSubToTopics,\n username: unsProxyProcessParameters?.username ?? \"\",\n password: unsProxyProcessParameters?.password ?? \"\",\n mqttSSL: unsProxyProcessParameters?.mqttSSL ?? false,\n statusTopic: this.processStatusTopic,\n clientId: unsProxyProcessParameters?.clientId ?? `${this.processName}-${this.processId}`,\n hosts: unsProxyProcessParameters?.hosts,\n servers: unsProxyProcessParameters?.servers,\n port: unsProxyProcessParameters?.port,\n protocol: unsProxyProcessParameters?.protocol,\n keepalive: unsProxyProcessParameters?.keepalive,\n clean: unsProxyProcessParameters?.clean,\n connectTimeout: unsProxyProcessParameters?.connectTimeout,\n reconnectPeriod: unsProxyProcessParameters?.reconnectPeriod,\n reconnectOnConnackError: unsProxyProcessParameters?.reconnectOnConnackError,\n resubscribe: unsProxyProcessParameters?.resubscribe,\n queueQoSZero: unsProxyProcessParameters?.queueQoSZero,\n rejectUnauthorized: unsProxyProcessParameters?.rejectUnauthorized ?? false,\n properties: unsProxyProcessParameters?.properties,\n ca: unsProxyProcessParameters?.ca,\n cert: unsProxyProcessParameters?.cert,\n key: unsProxyProcessParameters?.key,\n servername: unsProxyProcessParameters?.servername,\n };\n\n // Initialize MQTT proxy and start connection.\n this.processMqttProxy = new MqttProxy(mqttHost, this.processName, mqttParameters);\n this.processMqttProxy.start();\n\n // Instantiate and start the StatusMonitor for memory and status updates.\n this.statusMonitor = new StatusMonitor(\n this.processMqttProxy,\n this.processStatusTopic,\n () => this.active,\n MQTT_UPDATE_INTERVAL,\n MQTT_UPDATE_INTERVAL,\n { processName: this.processName, processId: this.processId },\n );\n this.statusMonitor.start();\n }\n\n /**\n * Initializes the HandoverManager instance and sets up event listeners for handover and MQTT input events.\n * Determines handover and force start modes based on process arguments.\n */\n private initHandoverManager(instanceMode: string, handover: boolean, handoverId?: string) {\n const handoverRequestEnabled = instanceMode == \"handover\" ? true : false;\n const forceStartEnabled = instanceMode == \"force\" ? true : false;\n\n this.handoverManager = new HandoverManager(\n this.processName,\n this.processId,\n this.processMqttProxy,\n this.unsMqttProxies,\n handoverRequestEnabled,\n handover ?? true,\n forceStartEnabled,\n handoverId,\n this.handoverShutdown,\n );\n\n // Listen for handover events.\n this.handoverManager.event.on(\"handoverManager\", (event) => {\n this.active = event.active;\n });\n\n // Delegate MQTT events to the HandoverManager.\n this.mqttInputHandler = async (event: UnsEvents[\"input\"]) => {\n await this.handoverManager.handleMqttMessage(event);\n };\n this.processMqttProxy.event.on(\"input\", this.mqttInputHandler);\n }\n\n /**\n * Creates a new UNS proxy instance and stores it for future management.\n */\n public async createUnsMqttProxy(\n mqttHost: string,\n instanceName: string,\n instanceMode: string,\n handover: boolean,\n unsParameters?: IUnsParameters,\n ): Promise<UnsMqttProxy> {\n if (unsParameters?.publishQueue && handover) {\n throw new Error(\"Persistent MQTT output requires handover=false and one owner; legacy RAM handover does not transfer an outbox\");\n }\n // Wait until the MQTT connection is established before proceeding.\n await this.waitForProcessConnection();\n\n // Currently handover manager can handle only mqtt events\n if (!this.handoverManager) {\n this.initHandoverManager(\n instanceMode,\n handover,\n this.handoverId,\n );\n }\n\n const resolvedUnsParameters: IUnsParameters = {\n ...(unsParameters ?? {}),\n clientId: unsParameters?.clientId ?? `${this.processName}-${instanceName}-${this.processId}`,\n };\n const unsMqttProxy = new UnsMqttProxy(mqttHost, this.processName, instanceName, resolvedUnsParameters);\n\n // Listen for UNS proxy producing topics and publish them via MQTT.\n unsMqttProxy.event.on(\"unsProxyProducedTopics\", (event) => {\n this.processMqttProxy.publish(event.statusTopic, JSON.stringify(event.producedTopics));\n });\n\n // Listen for UNS proxy status events and publish them via MQTT.\n unsMqttProxy.event.on(\"mqttProxyStatus\", (event) => {\n const time = UnsPacket.formatToISO8601(new Date());\n const unsMessage: IUnsMessage = { data: { time, value: event.value, uom: event.uom } };\n UnsPacket.unsPacketFromUnsMessage(unsMessage).then((packet) => {\n this.processMqttProxy.publish(event.statusTopic, JSON.stringify(packet));\n });\n });\n\n this.unsMqttProxies.push(unsMqttProxy);\n return unsMqttProxy;\n }\n\n public async waitForProcessConnection(): Promise<void> {\n while (!this.processMqttProxy?.isConnected) {\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n }\n\n /**\n * Publishes retained product/system service metadata for controller discovery.\n *\n * The payload is intentionally separate from the volatile active/alive status\n * topics. Controllers can combine this retained identity/capability metadata\n * with live process status to decide whether a service is currently healthy.\n */\n public async publishServiceMetadata(metadata: UnsServiceMetadataInput): Promise<UnsServiceMetadata> {\n await this.waitForProcessConnection();\n const resolved = buildUnsServiceMetadata({\n processName: this.processName,\n processId: this.processId,\n metadata,\n });\n await this.processMqttProxy.publish(this.serviceMetadataTopic, JSON.stringify(resolved), { retain: true });\n return resolved;\n }\n\n /**\n * Shuts down the process by clearing intervals, timeouts, and removing\n * MQTT event listeners, and stopping the StatusMonitor.\n */\n public shutdown(options: UnsMqttProxyStopOptions = {}): Promise<void> {\n if (this.shutdownPromise) {\n return this.shutdownPromise;\n }\n\n this.shutdownPromise = this.performShutdown(options);\n return this.shutdownPromise;\n }\n\n private async performShutdown(options: UnsMqttProxyStopOptions): Promise<void> {\n logger.info(`${this.processName} - Shutting down UnsProxyProcess...`);\n const shutdownErrors: Error[] = [];\n\n try {\n this.statusMonitor.stop();\n await this.statusMonitor.publishInactiveStatus();\n } catch (e: any) {\n const reason = e instanceof Error ? e : new Error(String(e));\n logger.error(`${this.processName} - Error stopping StatusMonitor or publishing passive state: ${reason.message}`);\n shutdownErrors.push(reason);\n }\n\n if (this.mqttInputHandler) {\n try {\n this.processMqttProxy.event.off(\"input\", this.mqttInputHandler);\n } catch (e: any) {\n const reason = e instanceof Error ? e : new Error(String(e));\n logger.error(`${this.processName} - Error removing MQTT input handler: ${reason.message}`);\n shutdownErrors.push(reason);\n }\n }\n\n const proxyStopResults = await Promise.allSettled(this.unsMqttProxies.map((proxy) => proxy.stop(options)));\n for (const result of proxyStopResults) {\n if (result.status === \"rejected\") {\n const reason = result.reason instanceof Error ? result.reason : new Error(String(result.reason));\n logger.error(`${this.processName} - Error stopping UNS MQTT proxy: ${reason.message}`);\n shutdownErrors.push(reason);\n }\n }\n\n try {\n if (typeof this.processMqttProxy.stop === \"function\") {\n await this.processMqttProxy.stop();\n }\n } catch (e: any) {\n const reason = e instanceof Error ? e : new Error(String(e));\n logger.error(`${this.processName} - Error stopping MQTT proxy: ${reason.message}`);\n shutdownErrors.push(reason);\n }\n\n if (shutdownErrors.length > 0) {\n throw new AggregateError(shutdownErrors, `${this.processName} - Shutdown completed with errors.`);\n }\n\n logger.info(`${this.processName} - Shutdown complete.`);\n }\n}\n\ninterface UnsProxyProcess {}\n\nexport default UnsProxyProcess;\nexport type { UnsServiceMetadata, UnsServiceMetadataInput };\nexport { UnsProxyProcess };\n"]}
1
+ {"version":3,"file":"uns-proxy-process.js","sourceRoot":"","sources":["../../src/uns/uns-proxy-process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,qBAAqB,EAAyB,MAAM,0BAA0B,CAAC;AACpI,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,MAAM,MAAM,cAAc,CAAC;AAElC,OAAO,SAAS,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,YAAY,MAAM,+BAA+B,CAAC;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,C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;gBACrD,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC;YACrC,CAAC;QACH,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,MAAM,MAAM,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7D,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,WAAW,iCAAiC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;YACnF,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC9B,CAAC;QAED,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,cAAc,CAAC,cAAc,EAAE,GAAG,IAAI,CAAC,WAAW,oCAAoC,CAAC,CAAC;QACpG,CAAC;QAED,IAAI,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC/B,MAAM,QAAQ,GAAG,UAAgD,CAAC;YAClE,IAAI,QAAQ,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC,qBAAqB;gBAAE,OAAO,QAAQ,CAAC,kBAAkB,CAAC,CAAC;YACrG,OAAO,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;QAC3B,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,uBAAuB,CAAC,CAAC;IAC1D,CAAC;;AAKH,eAAe,eAAe,CAAC;AAE/B,OAAO,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import { MQTT_DRAIN_HANDLER, MQTT_DRAIN_READY_EVENT, drainMqttForMigration, type MqttDrainReceipt } from \"../runtime/mqtt-drain.js\";\nimport { randomBytes } from \"crypto\";\n\nimport logger from \"../logger.js\";\nimport { IMqttParameters } from \"../uns-mqtt/mqtt-interfaces.js\";\nimport MqttProxy from \"../uns-mqtt/mqtt-proxy.js\";\nimport { MqttTopicBuilder } from \"../uns-mqtt/mqtt-topic-builder.js\";\nimport UnsMqttProxy from \"../uns-mqtt/uns-mqtt-proxy.js\";\nimport type { UnsMqttProxyStopOptions } from \"../uns-mqtt/uns-mqtt-proxy.js\";\nimport { HandoverManager } from \"./handover-manager.js\";\nimport { validateHandoverShutdown, type HandoverShutdownHooks } from \"./handover-shutdown.js\";\n// Import configuration and initialization modules.\nimport { MQTT_UPDATE_INTERVAL, PACKAGE_INFO } from \"./process-config.js\";\nimport { type UnsServiceMetadata, type UnsServiceMetadataInput, buildUnsServiceMetadata } from \"./service-metadata.js\";\nimport { StatusMonitor } from \"./status-monitor.js\";\nimport { IUnsMessage, IUnsParameters, IUnsProcessParameters, UnsEvents } from \"./uns-interfaces.js\";\nimport { UnsPacket } from \"./uns-packet.js\";\n\n/**\n * UnsProxyProcess is responsible for managing the process lifecycle,\n * configuring MQTT (subscriptions and publishing for status updates), and\n * handling UNS proxy instances.\n *\n * It leverages HandoverManager for handover events and StatusMonitor for health reporting.\n */\nexport type UnsProxyProcessPluginMethod = (this: UnsProxyProcess, ...args: unknown[]) => unknown;\n\nexport type UnsProxyProcessPluginMethods = Record<string, UnsProxyProcessPluginMethod>;\n\nexport interface UnsProxyProcessPluginApi {\n version: number;\n define(methods: UnsProxyProcessPluginMethods): void;\n UnsProxyProcess: typeof UnsProxyProcess;\n}\n\nexport type UnsProxyProcessPlugin = (api: UnsProxyProcessPluginApi) => void;\n\nclass UnsProxyProcess {\n private active: boolean = false;\n private processStatusTopic: string;\n private processName: string;\n private processId: string;\n private handoverId: string | undefined;\n private handoverShutdown: HandoverShutdownHooks | undefined;\n private unsMqttProxies: UnsMqttProxy[];\n private unsApiProxies: unknown[];\n private processMqttProxy: MqttProxy;\n private handoverManager: HandoverManager;\n private statusMonitor: StatusMonitor;\n private serviceMetadataTopic: string;\n private shutdownPromise: Promise<void> | null = null;\n private migrationDrainPromise: Promise<MqttDrainReceipt> | null = null;\n private migrationDrainHandler?: () => Promise<MqttDrainReceipt>;\n\n // Plugin\n static pluginApiVersion = 1;\n private static registered = new Set<UnsProxyProcessPlugin>();\n private static registeredMethodNames = new Set<string>();\n private static applied = false;\n\n static use(plugin: UnsProxyProcessPlugin) {\n if (this.registered.has(plugin)) return this;\n this.registered.add(plugin);\n if (this.applied) this.applyPlugin(plugin);\n return this;\n }\n\n private static applyPlugin(plugin: UnsProxyProcessPlugin) {\n const define: UnsProxyProcessPluginApi[\"define\"] = (methods) => {\n for (const [name, fn] of Object.entries(methods)) {\n if (typeof fn !== \"function\") {\n throw new TypeError(`UnsProxyProcess plugin attempted to register non-function member \\\"${name}\\\".`);\n }\n if (this.registeredMethodNames.has(name) || Reflect.has(this.prototype, name)) {\n throw new Error(`UnsProxyProcess plugin attempted to overwrite existing member \\\"${name}\\\".`);\n }\n Object.defineProperty(this.prototype, name, {\n value: fn,\n writable: true,\n configurable: true,\n enumerable: false,\n });\n this.registeredMethodNames.add(name);\n }\n };\n\n plugin({\n define,\n version: this.pluginApiVersion,\n UnsProxyProcess: this,\n });\n }\n\n private static applyAll() {\n if (this.applied) return;\n this.applied = true;\n for (const p of this.registered) this.applyPlugin(p);\n }\n\n // References for cleanup.\n private mqttInputHandler: (event: any) => void;\n\n constructor(mqttHost: string, unsProxyProcessParameters: IUnsProcessParameters) {\n (this.constructor as typeof UnsProxyProcess).applyAll(); // Activate all the plugins\n\n this.unsMqttProxies = [];\n this.unsApiProxies = [];\n if (!unsProxyProcessParameters?.processName) {\n throw new Error(\"UnsProxyProcess requires a processName in configuration.\");\n }\n validateHandoverShutdown(unsProxyProcessParameters.handoverShutdown);\n this.handoverShutdown = unsProxyProcessParameters.handoverShutdown\n ? { ...unsProxyProcessParameters.handoverShutdown } : undefined;\n this.processName = unsProxyProcessParameters.processName;\n this.processId = randomBytes(16).toString(\"hex\");\n this.handoverId = unsProxyProcessParameters.handoverId ?? process.env[\"UNS_HANDOVER_ID\"];\n const { name: packageName, version } = PACKAGE_INFO;\n\n // Instantiate the topic builder.\n const topicBuilder = new MqttTopicBuilder(\n `uns-infra/${MqttTopicBuilder.sanitizeTopicPart(packageName)}/${MqttTopicBuilder.sanitizeTopicPart(version)}/${MqttTopicBuilder.sanitizeTopicPart(this.processName)}/`,\n );\n\n // Generate topics.\n const processStatusTopic = topicBuilder.getProcessStatusTopic();\n const handoverTopic = topicBuilder.getHandoverTopic();\n const wildcardActiveTopic = topicBuilder.getWildcardActiveTopic();\n const serviceMetadataTopic = topicBuilder.getServiceMetadataTopic();\n\n this.processStatusTopic = processStatusTopic;\n this.serviceMetadataTopic = serviceMetadataTopic;\n\n // Configure MQTT topics for subscription.\n const mqttSubToTopics = unsProxyProcessParameters?.mqttSubToTopics ?? [wildcardActiveTopic, handoverTopic];\n const mqttParameters: IMqttParameters = {\n mqttSubToTopics,\n username: unsProxyProcessParameters?.username ?? \"\",\n password: unsProxyProcessParameters?.password ?? \"\",\n mqttSSL: unsProxyProcessParameters?.mqttSSL ?? false,\n statusTopic: this.processStatusTopic,\n clientId: unsProxyProcessParameters?.clientId ?? `${this.processName}-${this.processId}`,\n hosts: unsProxyProcessParameters?.hosts,\n servers: unsProxyProcessParameters?.servers,\n port: unsProxyProcessParameters?.port,\n protocol: unsProxyProcessParameters?.protocol,\n keepalive: unsProxyProcessParameters?.keepalive,\n clean: unsProxyProcessParameters?.clean,\n connectTimeout: unsProxyProcessParameters?.connectTimeout,\n reconnectPeriod: unsProxyProcessParameters?.reconnectPeriod,\n reconnectOnConnackError: unsProxyProcessParameters?.reconnectOnConnackError,\n resubscribe: unsProxyProcessParameters?.resubscribe,\n queueQoSZero: unsProxyProcessParameters?.queueQoSZero,\n rejectUnauthorized: unsProxyProcessParameters?.rejectUnauthorized ?? false,\n properties: unsProxyProcessParameters?.properties,\n ca: unsProxyProcessParameters?.ca,\n cert: unsProxyProcessParameters?.cert,\n key: unsProxyProcessParameters?.key,\n servername: unsProxyProcessParameters?.servername,\n };\n\n // Initialize MQTT proxy and start connection.\n this.processMqttProxy = new MqttProxy(mqttHost, this.processName, mqttParameters);\n this.processMqttProxy.start();\n\n // Instantiate and start the StatusMonitor for memory and status updates.\n this.statusMonitor = new StatusMonitor(\n this.processMqttProxy,\n this.processStatusTopic,\n () => this.active,\n MQTT_UPDATE_INTERVAL,\n MQTT_UPDATE_INTERVAL,\n { processName: this.processName, processId: this.processId },\n );\n this.statusMonitor.start();\n }\n\n /**\n * Initializes the HandoverManager instance and sets up event listeners for handover and MQTT input events.\n * Determines handover and force start modes based on process arguments.\n */\n private initHandoverManager(instanceMode: string, handover: boolean, handoverId?: string) {\n const handoverRequestEnabled = instanceMode == \"handover\" ? true : false;\n const forceStartEnabled = instanceMode == \"force\" ? true : false;\n\n this.handoverManager = new HandoverManager(\n this.processName,\n this.processId,\n this.processMqttProxy,\n this.unsMqttProxies,\n handoverRequestEnabled,\n handover ?? true,\n forceStartEnabled,\n handoverId,\n this.handoverShutdown,\n );\n\n // Listen for handover events.\n this.handoverManager.event.on(\"handoverManager\", (event) => {\n this.active = event.active;\n });\n\n // Delegate MQTT events to the HandoverManager.\n this.mqttInputHandler = async (event: UnsEvents[\"input\"]) => {\n await this.handoverManager.handleMqttMessage(event);\n };\n this.processMqttProxy.event.on(\"input\", this.mqttInputHandler);\n }\n\n /**\n * Creates a new UNS proxy instance and stores it for future management.\n */\n public async createUnsMqttProxy(\n mqttHost: string,\n instanceName: string,\n instanceMode: string,\n handover: boolean,\n unsParameters?: IUnsParameters,\n ): Promise<UnsMqttProxy> {\n if (unsParameters?.publishQueue && unsParameters.publishQueue.enabled !== false && handover) {\n throw new Error(\"Persistent MQTT output requires handover=false and one owner; legacy RAM handover does not transfer an outbox\");\n }\n // Wait until the MQTT connection is established before proceeding.\n await this.waitForProcessConnection();\n\n // Currently handover manager can handle only mqtt events\n if (!this.handoverManager) {\n this.initHandoverManager(\n instanceMode,\n handover,\n this.handoverId,\n );\n }\n\n const resolvedUnsParameters: IUnsParameters = {\n ...(unsParameters ?? {}),\n clientId: unsParameters?.clientId ?? `${this.processName}-${instanceName}-${this.processId}`,\n };\n const unsMqttProxy = new UnsMqttProxy(mqttHost, this.processName, instanceName, resolvedUnsParameters);\n\n // Listen for UNS proxy producing topics and publish them via MQTT.\n unsMqttProxy.event.on(\"unsProxyProducedTopics\", (event) => {\n this.processMqttProxy.publish(event.statusTopic, JSON.stringify(event.producedTopics));\n });\n\n // Listen for UNS proxy status events and publish them via MQTT.\n unsMqttProxy.event.on(\"mqttProxyStatus\", (event) => {\n const time = UnsPacket.formatToISO8601(new Date());\n const unsMessage: IUnsMessage = { data: { time, value: event.value, uom: event.uom } };\n UnsPacket.unsPacketFromUnsMessage(unsMessage).then((packet) => {\n this.processMqttProxy.publish(event.statusTopic, JSON.stringify(packet));\n });\n });\n\n this.unsMqttProxies.push(unsMqttProxy);\n return unsMqttProxy;\n }\n\n public async waitForProcessConnection(): Promise<void> {\n while (!this.processMqttProxy?.isConnected) {\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n }\n\n /**\n * Publishes retained product/system service metadata for controller discovery.\n *\n * The payload is intentionally separate from the volatile active/alive status\n * topics. Controllers can combine this retained identity/capability metadata\n * with live process status to decide whether a service is currently healthy.\n */\n public async publishServiceMetadata(metadata: UnsServiceMetadataInput): Promise<UnsServiceMetadata> {\n await this.waitForProcessConnection();\n const resolved = buildUnsServiceMetadata({\n processName: this.processName,\n processId: this.processId,\n metadata,\n });\n await this.processMqttProxy.publish(this.serviceMetadataTopic, JSON.stringify(resolved), { retain: true });\n return resolved;\n }\n\n /** Call after application input handlers and shutdown hooks are prepared. */\n public enableMigrationDrain(): void {\n const registry = globalThis as unknown as Record<symbol, unknown>;\n if (this.migrationDrainHandler) return;\n if (registry[MQTT_DRAIN_HANDLER]) throw Error(\"One migration drain owner is allowed per process\");\n this.migrationDrainHandler = () => this.drainForMigration();\n registry[MQTT_DRAIN_HANDLER] = this.migrationDrainHandler;\n (process as unknown as { emit(event: string, value: unknown): boolean }).emit(MQTT_DRAIN_READY_EVENT, { protocol: 1 });\n }\n\n /** Works without a Controller too; success means confirmed empty output and closed owners. */\n public drainForMigration(timeoutMs = this.handoverShutdown?.timeoutMs ?? 30_000): Promise<MqttDrainReceipt> {\n if (this.migrationDrainPromise) return this.migrationDrainPromise;\n this.migrationDrainPromise = (async () => {\n const receipt = await drainMqttForMigration({\n quiesce: async () => {\n this.handoverShutdown?.onRelease?.();\n await Promise.all(this.unsMqttProxies.map(proxy => proxy.setSubscriberPassiveAndDrainQueue()));\n },\n finishAccepted: async () => { await this.handoverShutdown?.drain(); },\n outputs: this.unsMqttProxies,\n timeoutMs,\n });\n await this.shutdown({ drain: true, timeoutMs });\n return receipt;\n })().catch(error => { this.migrationDrainPromise = null; throw error; });\n return this.migrationDrainPromise;\n }\n\n /** Stop process timers, status publication and all owned MQTT proxies. */\n public shutdown(options: UnsMqttProxyStopOptions = {}): Promise<void> {\n if (this.shutdownPromise) {\n return this.shutdownPromise;\n }\n\n this.shutdownPromise = this.performShutdown(options);\n return this.shutdownPromise;\n }\n\n private async performShutdown(options: UnsMqttProxyStopOptions): Promise<void> {\n logger.info(`${this.processName} - Shutting down UnsProxyProcess...`);\n const shutdownErrors: Error[] = [];\n\n try {\n this.statusMonitor.stop();\n await this.statusMonitor.publishInactiveStatus();\n } catch (e: any) {\n const reason = e instanceof Error ? e : new Error(String(e));\n logger.error(`${this.processName} - Error stopping StatusMonitor or publishing passive state: ${reason.message}`);\n shutdownErrors.push(reason);\n }\n\n if (this.mqttInputHandler) {\n try {\n this.processMqttProxy.event.off(\"input\", this.mqttInputHandler);\n } catch (e: any) {\n const reason = e instanceof Error ? e : new Error(String(e));\n logger.error(`${this.processName} - Error removing MQTT input handler: ${reason.message}`);\n shutdownErrors.push(reason);\n }\n }\n\n const proxyStopResults = await Promise.allSettled(this.unsMqttProxies.map((proxy) => proxy.stop(options)));\n for (const result of proxyStopResults) {\n if (result.status === \"rejected\") {\n const reason = result.reason instanceof Error ? result.reason : new Error(String(result.reason));\n logger.error(`${this.processName} - Error stopping UNS MQTT proxy: ${reason.message}`);\n shutdownErrors.push(reason);\n }\n }\n\n try {\n if (typeof this.processMqttProxy.stop === \"function\") {\n await this.processMqttProxy.stop();\n }\n } catch (e: any) {\n const reason = e instanceof Error ? e : new Error(String(e));\n logger.error(`${this.processName} - Error stopping MQTT proxy: ${reason.message}`);\n shutdownErrors.push(reason);\n }\n\n if (shutdownErrors.length > 0) {\n throw new AggregateError(shutdownErrors, `${this.processName} - Shutdown completed with errors.`);\n }\n\n if (this.migrationDrainHandler) {\n const registry = globalThis as unknown as Record<symbol, unknown>;\n if (registry[MQTT_DRAIN_HANDLER] === this.migrationDrainHandler) delete registry[MQTT_DRAIN_HANDLER];\n process.channel?.unref();\n }\n logger.info(`${this.processName} - Shutdown complete.`);\n }\n}\n\ninterface UnsProxyProcess {}\n\nexport default UnsProxyProcess;\nexport type { UnsServiceMetadata, UnsServiceMetadataInput };\nexport { UnsProxyProcess };\n"]}
@@ -293,6 +293,7 @@ export declare const baseSchema: z.ZodObject<{
293
293
  key: z.ZodOptional<z.ZodString>;
294
294
  servername: z.ZodOptional<z.ZodString>;
295
295
  publishQueue: z.ZodOptional<z.ZodObject<{
296
+ enabled: z.ZodDefault<z.ZodBoolean>;
296
297
  mode: z.ZodEnum<{
297
298
  buffered: "buffered";
298
299
  durable: "durable";
@@ -1 +1 @@
1
- {"version":3,"file":"config-schema.d.ts","sourceRoot":"","sources":["../../src/uns-config/config-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8CAAmE,CAAC;AAG3F,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC"}
1
+ {"version":3,"file":"config-schema.d.ts","sourceRoot":"","sources":["../../src/uns-config/config-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8CAAmE,CAAC;AAG3F,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC"}
@@ -208,6 +208,7 @@ export declare const mqttOutputChannelSchema: z.ZodObject<{
208
208
  key: z.ZodOptional<z.ZodString>;
209
209
  servername: z.ZodOptional<z.ZodString>;
210
210
  publishQueue: z.ZodOptional<z.ZodObject<{
211
+ enabled: z.ZodDefault<z.ZodBoolean>;
211
212
  mode: z.ZodEnum<{
212
213
  buffered: "buffered";
213
214
  durable: "durable";
@@ -522,6 +523,7 @@ export declare const unsCoreSchema: z.ZodObject<{
522
523
  key: z.ZodOptional<z.ZodString>;
523
524
  servername: z.ZodOptional<z.ZodString>;
524
525
  publishQueue: z.ZodOptional<z.ZodObject<{
526
+ enabled: z.ZodDefault<z.ZodBoolean>;
525
527
  mode: z.ZodEnum<{
526
528
  buffered: "buffered";
527
529
  durable: "durable";
@@ -1 +1 @@
1
- {"version":3,"file":"uns-core-schema.d.ts","sourceRoot":"","sources":["../../src/uns-config/uns-core-schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA2DxB,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAgC3B,CAAC;AAEJ,wFAAwF;AACxF,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAEzB,CAAC;AAEZ,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA0Cf,CAAC;AAEZ,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { MqttPublishQueueOptions } from "./publish-queue-contract.js";
2
+ /** Disabling persistence is not permission to hide retained output or a live owner. */
3
+ export declare function assertDisabledPublishQueueEmpty(config: MqttPublishQueueOptions, identity: string): void;
4
+ /** Host preflight may prove emptiness; the launching SDK still verifies its exact identity. */
5
+ export declare function assertRetainedPublishQueueEmpty(config: MqttPublishQueueOptions, identity?: string): void;
6
+ //# sourceMappingURL=disabled-publish-queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disabled-publish-queue.d.ts","sourceRoot":"","sources":["../../src/uns-mqtt/disabled-publish-queue.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E,uFAAuF;AACvF,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAGvG;AAED,+FAA+F;AAC/F,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,uBAAuB,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAmCxG"}