@uns-kit/core 1.0.24 → 1.0.26

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 (40) hide show
  1. package/README.md +2 -0
  2. package/dist/config/app-config.d.ts +97 -28
  3. package/dist/config/app-config.d.ts.map +1 -1
  4. package/dist/config/app-config.js.map +1 -1
  5. package/dist/tools/generate-config-schema.js +17 -1
  6. package/dist/tools/generate-config-schema.js.map +1 -1
  7. package/dist/uns/handover-manager.d.ts +5 -1
  8. package/dist/uns/handover-manager.d.ts.map +1 -1
  9. package/dist/uns/handover-manager.js +49 -19
  10. package/dist/uns/handover-manager.js.map +1 -1
  11. package/dist/uns/status-monitor.d.ts +6 -1
  12. package/dist/uns/status-monitor.d.ts.map +1 -1
  13. package/dist/uns/status-monitor.js +15 -2
  14. package/dist/uns/status-monitor.js.map +1 -1
  15. package/dist/uns/uns-interfaces.d.ts +36 -0
  16. package/dist/uns/uns-interfaces.d.ts.map +1 -1
  17. package/dist/uns/uns-interfaces.js.map +1 -1
  18. package/dist/uns/uns-proxy-process.d.ts +1 -0
  19. package/dist/uns/uns-proxy-process.d.ts.map +1 -1
  20. package/dist/uns/uns-proxy-process.js +28 -3
  21. package/dist/uns/uns-proxy-process.js.map +1 -1
  22. package/dist/uns-config/uns-core-schema.d.ts +1801 -88
  23. package/dist/uns-config/uns-core-schema.d.ts.map +1 -1
  24. package/dist/uns-config/uns-core-schema.js +38 -2
  25. package/dist/uns-config/uns-core-schema.js.map +1 -1
  26. package/dist/uns-grpc/uns-gateway-server.d.ts +2 -0
  27. package/dist/uns-grpc/uns-gateway-server.d.ts.map +1 -1
  28. package/dist/uns-grpc/uns-gateway-server.js +88 -10
  29. package/dist/uns-grpc/uns-gateway-server.js.map +1 -1
  30. package/dist/uns-mqtt/mqtt-interfaces.d.ts +33 -1
  31. package/dist/uns-mqtt/mqtt-interfaces.d.ts.map +1 -1
  32. package/dist/uns-mqtt/mqtt-interfaces.js.map +1 -1
  33. package/dist/uns-mqtt/mqtt-proxy.d.ts +3 -0
  34. package/dist/uns-mqtt/mqtt-proxy.d.ts.map +1 -1
  35. package/dist/uns-mqtt/mqtt-proxy.js +86 -4
  36. package/dist/uns-mqtt/mqtt-proxy.js.map +1 -1
  37. package/dist/uns-mqtt/uns-mqtt-proxy.d.ts.map +1 -1
  38. package/dist/uns-mqtt/uns-mqtt-proxy.js +31 -9
  39. package/dist/uns-mqtt/uns-mqtt-proxy.js.map +1 -1
  40. package/package.json +1 -1
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Core utilities and runtime building blocks for building Unified Namespace (UNS) realtime transformers. The package bundles the process lifecycle manager, MQTT integrations, gRPC gateway helpers, configuration tooling, and shared type definitions that power the UNS ecosystem.
4
4
 
5
+ Note: Apps built with uns-kit are intended to be managed by the **UNS Datahub controller**.
6
+
5
7
  ## uns-kit in context
6
8
 
7
9
  uns-kit is a batteries-included toolkit for Unified Namespace applications. It standardizes MQTT wiring, auth, config schemas, and scaffolding so teams can focus on domain logic instead of boilerplate. This package is the foundation; the full toolkit includes:
@@ -5,31 +5,7 @@ export interface ProjectAppConfig {
5
5
  /** Email used when authenticating to graphql endpoint of the UNS instance. */
6
6
  email: string;
7
7
  /** Password or secret value paired with the UNS email. */
8
- password: string | ({
9
- /** Load the secret from an environment variable. */
10
- provider: "env";
11
- /** Name of the environment variable to read. */
12
- key: string;
13
- /** Allow the variable to be absent without throwing during resolution. */
14
- optional?: boolean | undefined;
15
- /** Fallback value when optional is true and the variable is missing. */
16
- default?: string | undefined;
17
- } | {
18
- /** Load the secret from Infisical. */
19
- provider: "infisical";
20
- /** Secret folder path in Infisical, e.g. '/app/database'. */
21
- path: string;
22
- /** Secret key/name inside the given path. */
23
- key: string;
24
- /** Allow the secret to be absent without throwing during resolution. */
25
- optional?: boolean | undefined;
26
- /** Infisical environment override (defaults to current mode if omitted). */
27
- environment?: string | undefined;
28
- /** Optional Infisical project identifier when not using the default. */
29
- projectId?: string | undefined;
30
- /** Fallback value when the secret is missing and optional resolution is allowed. */
31
- default?: string | undefined;
32
- });
8
+ password: string;
33
9
  instanceMode?: "wait" | "force" | "handover";
34
10
  processName?: string | undefined;
35
11
  handover?: boolean;
@@ -38,22 +14,115 @@ export interface ProjectAppConfig {
38
14
  env?: "dev" | "staging" | "test" | "prod";
39
15
  };
40
16
  input?: {
41
- host: string;
17
+ host?: string | undefined;
18
+ hosts?: string[] | undefined;
19
+ servers?: {
20
+ host: string;
21
+ port?: number | undefined;
22
+ protocol?: ("mqtt" | "mqtts" | "ws" | "wss" | "tcp" | "ssl") | undefined;
23
+ }[] | undefined;
24
+ port?: number | undefined;
25
+ protocol?: ("mqtt" | "mqtts" | "ws" | "wss" | "tcp" | "ssl") | undefined;
42
26
  username?: string | undefined;
43
27
  password?: string | undefined;
44
28
  clientId?: string | undefined;
29
+ clean?: boolean | undefined;
30
+ keepalive?: number | undefined;
31
+ connectTimeout?: number | undefined;
32
+ reconnectPeriod?: number | undefined;
33
+ reconnectOnConnackError?: boolean | undefined;
34
+ resubscribe?: boolean | undefined;
35
+ queueQoSZero?: boolean | undefined;
36
+ rejectUnauthorized?: boolean | undefined;
37
+ properties?: {
38
+ sessionExpiryInterval?: number | undefined;
39
+ receiveMaximum?: number | undefined;
40
+ maximumPacketSize?: number | undefined;
41
+ topicAliasMaximum?: number | undefined;
42
+ requestResponseInformation?: boolean | undefined;
43
+ requestProblemInformation?: boolean | undefined;
44
+ userProperties?: {
45
+ [x: string]: string;
46
+ } | undefined;
47
+ } | undefined;
48
+ ca?: string | undefined;
49
+ cert?: string | undefined;
50
+ key?: string | undefined;
51
+ servername?: string | undefined;
45
52
  } | undefined;
46
53
  output?: {
47
- host: string;
54
+ host?: string | undefined;
55
+ hosts?: string[] | undefined;
56
+ servers?: {
57
+ host: string;
58
+ port?: number | undefined;
59
+ protocol?: ("mqtt" | "mqtts" | "ws" | "wss" | "tcp" | "ssl") | undefined;
60
+ }[] | undefined;
61
+ port?: number | undefined;
62
+ protocol?: ("mqtt" | "mqtts" | "ws" | "wss" | "tcp" | "ssl") | undefined;
48
63
  username?: string | undefined;
49
64
  password?: string | undefined;
50
65
  clientId?: string | undefined;
66
+ clean?: boolean | undefined;
67
+ keepalive?: number | undefined;
68
+ connectTimeout?: number | undefined;
69
+ reconnectPeriod?: number | undefined;
70
+ reconnectOnConnackError?: boolean | undefined;
71
+ resubscribe?: boolean | undefined;
72
+ queueQoSZero?: boolean | undefined;
73
+ rejectUnauthorized?: boolean | undefined;
74
+ properties?: {
75
+ sessionExpiryInterval?: number | undefined;
76
+ receiveMaximum?: number | undefined;
77
+ maximumPacketSize?: number | undefined;
78
+ topicAliasMaximum?: number | undefined;
79
+ requestResponseInformation?: boolean | undefined;
80
+ requestProblemInformation?: boolean | undefined;
81
+ userProperties?: {
82
+ [x: string]: string;
83
+ } | undefined;
84
+ } | undefined;
85
+ ca?: string | undefined;
86
+ cert?: string | undefined;
87
+ key?: string | undefined;
88
+ servername?: string | undefined;
51
89
  } | undefined;
52
90
  infra: {
53
- host: string;
91
+ host?: string | undefined;
92
+ hosts?: string[] | undefined;
93
+ servers?: {
94
+ host: string;
95
+ port?: number | undefined;
96
+ protocol?: ("mqtt" | "mqtts" | "ws" | "wss" | "tcp" | "ssl") | undefined;
97
+ }[] | undefined;
98
+ port?: number | undefined;
99
+ protocol?: ("mqtt" | "mqtts" | "ws" | "wss" | "tcp" | "ssl") | undefined;
54
100
  username?: string | undefined;
55
101
  password?: string | undefined;
56
102
  clientId?: string | undefined;
103
+ clean?: boolean | undefined;
104
+ keepalive?: number | undefined;
105
+ connectTimeout?: number | undefined;
106
+ reconnectPeriod?: number | undefined;
107
+ reconnectOnConnackError?: boolean | undefined;
108
+ resubscribe?: boolean | undefined;
109
+ queueQoSZero?: boolean | undefined;
110
+ rejectUnauthorized?: boolean | undefined;
111
+ properties?: {
112
+ sessionExpiryInterval?: number | undefined;
113
+ receiveMaximum?: number | undefined;
114
+ maximumPacketSize?: number | undefined;
115
+ topicAliasMaximum?: number | undefined;
116
+ requestResponseInformation?: boolean | undefined;
117
+ requestProblemInformation?: boolean | undefined;
118
+ userProperties?: {
119
+ [x: string]: string;
120
+ } | undefined;
121
+ } | undefined;
122
+ ca?: string | undefined;
123
+ cert?: string | undefined;
124
+ key?: string | undefined;
125
+ servername?: string | undefined;
57
126
  };
58
127
  devops?: {
59
128
  provider?: "azure-devops";
@@ -1 +1 @@
1
- {"version":3,"file":"app-config.d.ts","sourceRoot":"","sources":["../../src/config/app-config.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,gBAAgB;IAC7B,GAAG,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,8EAA8E;QAC9E,KAAK,EAAE,MAAM,CAAC;QACd,0DAA0D;QAC1D,QAAQ,EAAE,MAAM,GAAG,CAAC;YAChB,oDAAoD;YACpD,QAAQ,EAAE,KAAK,CAAC;YAChB,gDAAgD;YAChD,GAAG,EAAE,MAAM,CAAC;YACZ,0EAA0E;YAC1E,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;YAC/B,wEAAwE;YACxE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;SAChC,GAAG;YACA,sCAAsC;YACtC,QAAQ,EAAE,WAAW,CAAC;YACtB,6DAA6D;YAC7D,IAAI,EAAE,MAAM,CAAC;YACb,6CAA6C;YAC7C,GAAG,EAAE,MAAM,CAAC;YACZ,wEAAwE;YACxE,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;YAC/B,4EAA4E;YAC5E,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;YACjC,wEAAwE;YACxE,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;YAC/B,oFAAoF;YACpF,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;SAChC,CAAC,CAAC;QACH,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,UA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QACrC,uBAAuB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;QAC9C,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;QAClC,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;QACnC,kBAAkB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;QACzC,UAAU,CAAC,EAAE;YACT,qBAAqB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;YAC3C,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;YACpC,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;YACvC,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;YACvC,0BAA0B,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;YACjD,yBAAyB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;YAChD,cAAc,CAAC,EAAE;gBACb,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;aACvB,GAAG,SAAS,CAAC;SACjB,GAAG,SAAS,CAAC;QACd,EAAE,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QACxB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC1B,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QACzB,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KACnC,CAAC;IACF,MAAM,CAAC,EAAE;QACL,QAAQ,CAAC,EAAE,cAAc,CAAC;QAC1B,YAAY,EAAE,MAAM,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KAChC,GAAG,SAAS,CAAC;CACjB;AAED,MAAM,WAAW,SAAU,SAAQ,gBAAgB;CAAG"}
@@ -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 /** Email used when authenticating to graphql endpoint of the UNS instance. */\n email: string;\n /** Password or secret value paired with the UNS email. */\n password: string | ({\n /** Load the secret from an environment variable. */\n provider: \"env\";\n /** Name of the environment variable to read. */\n key: string;\n /** Allow the variable to be absent without throwing during resolution. */\n optional?: boolean | undefined;\n /** Fallback value when optional is true and the variable is missing. */\n default?: string | undefined;\n } | {\n /** Load the secret from Infisical. */\n provider: \"infisical\";\n /** Secret folder path in Infisical, e.g. '/app/database'. */\n path: string;\n /** Secret key/name inside the given path. */\n key: string;\n /** Allow the secret to be absent without throwing during resolution. */\n optional?: boolean | undefined;\n /** Infisical environment override (defaults to current mode if omitted). */\n environment?: string | undefined;\n /** Optional Infisical project identifier when not using the default. */\n projectId?: string | undefined;\n /** Fallback value when the secret is missing and optional resolution is allowed. */\n default?: string | undefined;\n });\n instanceMode?: \"wait\" | \"force\" | \"handover\";\n processName?: string | undefined;\n handover?: boolean;\n jwksWellKnownUrl?: string | undefined;\n kidWellKnownUrl?: string | undefined;\n env?: \"dev\" | \"staging\" | \"test\" | \"prod\";\n };\n input?: {\n host: string;\n username?: string | undefined;\n password?: string | undefined;\n clientId?: string | undefined;\n } | undefined;\n output?: {\n host: string;\n username?: string | undefined;\n password?: string | undefined;\n clientId?: string | undefined;\n } | undefined;\n infra: {\n host: string;\n username?: string | undefined;\n password?: string | undefined;\n clientId?: 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 {}"]}
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 /** Email used when authenticating to graphql endpoint of the UNS instance. */\n email: string;\n /** Password or secret value paired with the UNS email. */\n password: string;\n instanceMode?: \"wait\" | \"force\" | \"handover\";\n processName?: string | undefined;\n handover?: boolean;\n jwksWellKnownUrl?: string | undefined;\n kidWellKnownUrl?: string | undefined;\n env?: \"dev\" | \"staging\" | \"test\" | \"prod\";\n };\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 } | 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"]}
@@ -65,7 +65,23 @@ write(path.resolve("config.schema.json"), JSON.stringify(jsonSchema, null, 2));
65
65
  // 2) TypeScript `export type AppConfig = {...}`
66
66
  const { node } = zodToTs(baseSchema, "AppConfig");
67
67
  const interfaceBody = printNode(node);
68
- const tsContent = `/* Auto-generated. Do not edit by hand. */\nexport interface ProjectAppConfig ${interfaceBody}\n\nexport interface AppConfig extends ProjectAppConfig {}\n\ntype GeneratedProjectAppConfig = ProjectAppConfig;\ntype GeneratedAppConfig = AppConfig;\n\ndeclare module "@uns-kit/core/config/app-config.js" {\n interface ProjectAppConfig extends GeneratedProjectAppConfig {}\n interface AppConfig extends GeneratedAppConfig {}\n}\n`;
68
+ let shouldAugment = true;
69
+ try {
70
+ const pkgJsonPath = path.resolve(process.cwd(), "package.json");
71
+ if (fs.existsSync(pkgJsonPath)) {
72
+ const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
73
+ if (pkg?.name === "@uns-kit/core") {
74
+ shouldAugment = false;
75
+ }
76
+ }
77
+ }
78
+ catch {
79
+ shouldAugment = true;
80
+ }
81
+ const augmentationBlock = shouldAugment
82
+ ? `\n\ntype GeneratedProjectAppConfig = ProjectAppConfig;\ntype GeneratedAppConfig = AppConfig;\n\ndeclare module "@uns-kit/core/config/app-config.js" {\n interface ProjectAppConfig extends GeneratedProjectAppConfig {}\n interface AppConfig extends GeneratedAppConfig {}\n}\n`
83
+ : "\n";
84
+ const tsContent = `/* Auto-generated. Do not edit by hand. */\nexport interface ProjectAppConfig ${interfaceBody}\n\nexport interface AppConfig extends ProjectAppConfig {}${augmentationBlock}`;
69
85
  write(path.resolve("./src/config/app-config.ts"), tsContent);
70
86
  console.log("Generated config.schema.json and updated src/config/app-config.ts");
71
87
  //# sourceMappingURL=generate-config-schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate-config-schema.js","sourceRoot":"","sources":["../../src/tools/generate-config-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,SAAS,EA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,CAAC,CAAC;AAC3E,MAAM,mBAAmB,GAAG,MAAM,uBAAuB,EAAE,CAAC;AAC5D,MAAM,UAAU,GAAG,mBAAmB,CAAC,aAAa,EAAE,mBAAmB,CAAC,CAAC,MAAM,EAAE,CAAC;AAEpF,qCAAqC;AACrC,MAAM,UAAU,GAAG,eAAe,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AAC5D,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAE/E,gDAAgD;AAChD,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AAClD,MAAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AAEtC,MAAM,SAAS,GAAG,iFAAiF,aAAa,8UAA8U,CAAC;AAE/b,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,4BAA4B,CAAC,EAAE,SAAS,CAAC,CAAC;AAE7D,OAAO,CAAC,GAAG,CAAC,mEAAmE,CAAC,CAAC","sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { zodToJsonSchema } from \"zod-to-json-schema\";\nimport { zodToTs, printNode, withGetType } from \"zod-to-ts\";\nimport { z } from \"zod\";\n\nimport { hostValueSchema } from \"../uns-config/host-placeholders.js\";\nimport { secretValueSchema } from \"../uns-config/secret-placeholders.js\";\nimport { composeConfigSchema } from \"../uns-config/schema-tools.js\";\n\nfunction write(filePath: string, data: string) {\n fs.mkdirSync(path.dirname(filePath), { recursive: true });\n fs.writeFileSync(filePath, data);\n}\n\nlet tsLoaderReady = false;\n\nasync function ensureTsLoader(): Promise<void> {\n if (tsLoaderReady) {\n return;\n }\n tsLoaderReady = true;\n try {\n await import(\"tsx/esm\");\n } catch (error) {\n throw new Error(\n \"Unable to load TypeScript project.config.extension. Install 'tsx' (e.g. pnpm add -D tsx) or provide a compiled JavaScript file.\",\n );\n }\n}\n\nasync function loadProjectExtrasSchema(): Promise<z.AnyZodObject> {\n const base = path.resolve(process.cwd(), \"src/config/project.config.extension\");\n const extensions = [\"\", \".ts\", \".mts\", \".tsx\", \".js\", \".mjs\", \".cjs\"];\n\n for (const ext of extensions) {\n const candidate = ext ? `${base}${ext}` : base;\n if (!fs.existsSync(candidate)) {\n continue;\n }\n\n const lowerExt = path.extname(candidate).toLowerCase();\n try {\n if (lowerExt === \".ts\" || lowerExt === \".mts\" || lowerExt === \".tsx\") {\n await ensureTsLoader();\n }\n\n const module = await import(pathToFileURL(candidate).href);\n if (module?.projectExtrasSchema) {\n return module.projectExtrasSchema as z.AnyZodObject;\n }\n\n throw new Error(`Module '${candidate}' does not export projectExtrasSchema.`);\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n throw new Error(`Failed to load project config extension at '${candidate}': ${reason}`);\n }\n }\n\n const coreModule = await import(\"../config/project.config.extension.js\");\n return coreModule.projectExtrasSchema as z.AnyZodObject;\n}\n\n// Keep placeholder-backed values as plain strings in the generated TypeScript typings so\n// consuming code reflects the resolved shapes while the JSON schema still exposes full unions.\nconst renderAsString = (typescript: any) =>\n typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.StringKeyword);\n\nfor (const schema of [hostValueSchema, secretValueSchema]) {\n withGetType(schema, renderAsString);\n}\n\nconst { unsCoreSchema } = await import(\"../uns-config/uns-core-schema.js\");\nconst projectExtrasSchema = await loadProjectExtrasSchema();\nconst baseSchema = composeConfigSchema(unsCoreSchema, projectExtrasSchema).strict();\n\n// 1) JSON Schema for VS Code $schema\nconst jsonSchema = zodToJsonSchema(baseSchema, \"AppConfig\");\nwrite(path.resolve(\"config.schema.json\"), JSON.stringify(jsonSchema, null, 2));\n\n// 2) TypeScript `export type AppConfig = {...}`\nconst { node } = zodToTs(baseSchema, \"AppConfig\");\nconst interfaceBody = printNode(node);\n\nconst tsContent = `/* Auto-generated. Do not edit by hand. */\\nexport interface ProjectAppConfig ${interfaceBody}\\n\\nexport interface AppConfig extends ProjectAppConfig {}\\n\\ntype GeneratedProjectAppConfig = ProjectAppConfig;\\ntype GeneratedAppConfig = AppConfig;\\n\\ndeclare module \"@uns-kit/core/config/app-config.js\" {\\n interface ProjectAppConfig extends GeneratedProjectAppConfig {}\\n interface AppConfig extends GeneratedAppConfig {}\\n}\\n`;\n\nwrite(path.resolve(\"./src/config/app-config.ts\"), tsContent);\n\nconsole.log(\"Generated config.schema.json and updated src/config/app-config.ts\");\n"]}
1
+ {"version":3,"file":"generate-config-schema.js","sourceRoot":"","sources":["../../src/tools/generate-config-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAG5D,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAEpE,SAAS,KAAK,CAAC,QAAgB,EAAE,IAAY;IAC3C,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AACnC,CAAC;AAED,IAAI,aAAa,GAAG,KAAK,CAAC;AAE1B,KAAK,UAAU,cAAc;IAC3B,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO;IACT,CAAC;IACD,aAAa,GAAG,IAAI,CAAC;IACrB,IAAI,CAA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AM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;IAChE,IAAI,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;QAC7D,IAAI,GAAG,EAAE,IAAI,KAAK,eAAe,EAAE,CAAC;YAClC,aAAa,GAAG,KAAK,CAAC;QACxB,CAAC;IACH,CAAC;AACH,CAAC;AAAC,MAAM,CAAC;IACP,aAAa,GAAG,IAAI,CAAC;AACvB,CAAC;AAED,MAAM,iBAAiB,GAAG,aAAa;IACrC,CAAC,CAAC,oRAAoR;IACtR,CAAC,CAAC,IAAI,CAAC;AAET,MAAM,SAAS,GAAG,iFAAiF,aAAa,6DAA6D,iBAAiB,EAAE,CAAC;AAEjM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,4BAA4B,CAAC,EAAE,SAAS,CAAC,CAAC;AAE7D,OAAO,CAAC,GAAG,CAAC,mEAAmE,CAAC,CAAC","sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { zodToJsonSchema } from \"zod-to-json-schema\";\nimport { zodToTs, printNode, withGetType } from \"zod-to-ts\";\nimport { z } from \"zod\";\n\nimport { hostValueSchema } from \"../uns-config/host-placeholders.js\";\nimport { secretValueSchema } from \"../uns-config/secret-placeholders.js\";\nimport { composeConfigSchema } from \"../uns-config/schema-tools.js\";\n\nfunction write(filePath: string, data: string) {\n fs.mkdirSync(path.dirname(filePath), { recursive: true });\n fs.writeFileSync(filePath, data);\n}\n\nlet tsLoaderReady = false;\n\nasync function ensureTsLoader(): Promise<void> {\n if (tsLoaderReady) {\n return;\n }\n tsLoaderReady = true;\n try {\n await import(\"tsx/esm\");\n } catch (error) {\n throw new Error(\n \"Unable to load TypeScript project.config.extension. Install 'tsx' (e.g. pnpm add -D tsx) or provide a compiled JavaScript file.\",\n );\n }\n}\n\nasync function loadProjectExtrasSchema(): Promise<z.AnyZodObject> {\n const base = path.resolve(process.cwd(), \"src/config/project.config.extension\");\n const extensions = [\"\", \".ts\", \".mts\", \".tsx\", \".js\", \".mjs\", \".cjs\"];\n\n for (const ext of extensions) {\n const candidate = ext ? `${base}${ext}` : base;\n if (!fs.existsSync(candidate)) {\n continue;\n }\n\n const lowerExt = path.extname(candidate).toLowerCase();\n try {\n if (lowerExt === \".ts\" || lowerExt === \".mts\" || lowerExt === \".tsx\") {\n await ensureTsLoader();\n }\n\n const module = await import(pathToFileURL(candidate).href);\n if (module?.projectExtrasSchema) {\n return module.projectExtrasSchema as z.AnyZodObject;\n }\n\n throw new Error(`Module '${candidate}' does not export projectExtrasSchema.`);\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n throw new Error(`Failed to load project config extension at '${candidate}': ${reason}`);\n }\n }\n\n const coreModule = await import(\"../config/project.config.extension.js\");\n return coreModule.projectExtrasSchema as z.AnyZodObject;\n}\n\n// Keep placeholder-backed values as plain strings in the generated TypeScript typings so\n// consuming code reflects the resolved shapes while the JSON schema still exposes full unions.\nconst renderAsString = (typescript: any) =>\n typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.StringKeyword);\n\nfor (const schema of [hostValueSchema, secretValueSchema]) {\n withGetType(schema, renderAsString);\n}\n\nconst { unsCoreSchema } = await import(\"../uns-config/uns-core-schema.js\");\nconst projectExtrasSchema = await loadProjectExtrasSchema();\nconst baseSchema = composeConfigSchema(unsCoreSchema, projectExtrasSchema).strict();\n\n// 1) JSON Schema for VS Code $schema\nconst jsonSchema = zodToJsonSchema(baseSchema, \"AppConfig\");\nwrite(path.resolve(\"config.schema.json\"), JSON.stringify(jsonSchema, null, 2));\n\n// 2) TypeScript `export type AppConfig = {...}`\nconst { node } = zodToTs(baseSchema, \"AppConfig\");\nconst interfaceBody = printNode(node);\n\nlet shouldAugment = true;\ntry {\n const pkgJsonPath = path.resolve(process.cwd(), \"package.json\");\n if (fs.existsSync(pkgJsonPath)) {\n const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, \"utf8\"));\n if (pkg?.name === \"@uns-kit/core\") {\n shouldAugment = false;\n }\n }\n} catch {\n shouldAugment = true;\n}\n\nconst augmentationBlock = shouldAugment\n ? `\\n\\ntype GeneratedProjectAppConfig = ProjectAppConfig;\\ntype GeneratedAppConfig = AppConfig;\\n\\ndeclare module \"@uns-kit/core/config/app-config.js\" {\\n interface ProjectAppConfig extends GeneratedProjectAppConfig {}\\n interface AppConfig extends GeneratedAppConfig {}\\n}\\n`\n : \"\\n\";\n\nconst tsContent = `/* Auto-generated. Do not edit by hand. */\\nexport interface ProjectAppConfig ${interfaceBody}\\n\\nexport interface AppConfig extends ProjectAppConfig {}${augmentationBlock}`;\n\nwrite(path.resolve(\"./src/config/app-config.ts\"), tsContent);\n\nconsole.log(\"Generated config.schema.json and updated src/config/app-config.ts\");\n"]}
@@ -11,6 +11,7 @@ import UnsMqttProxy from "../uns-mqtt/uns-mqtt-proxy.js";
11
11
  export declare class HandoverManager {
12
12
  event: HandoverManagerEventEmitter<HandoverManagerEvents>;
13
13
  private processName;
14
+ private processId;
14
15
  private mqttProxy;
15
16
  private unsMqttProxies;
16
17
  private requestingHandover;
@@ -21,7 +22,10 @@ export declare class HandoverManager {
21
22
  handoverRequestEnabled: boolean;
22
23
  handoverEnabled: boolean;
23
24
  forceStartEnabled: boolean;
24
- constructor(processName: string, mqttProxy: MqttProxy, unsMqttProxies: UnsMqttProxy[], handoverRequestEnabled: boolean, handoverEnabled: boolean, forceStartEnabled: boolean);
25
+ constructor(processName: string, processId: string, mqttProxy: MqttProxy, unsMqttProxies: UnsMqttProxy[], handoverRequestEnabled: boolean, handoverEnabled: boolean, forceStartEnabled: boolean);
26
+ private getUserProperties;
27
+ private getSourceProcessId;
28
+ private parseActiveValue;
25
29
  /**
26
30
  * Main entry point for handling incoming MQTT messages.
27
31
  * It checks the topic and delegates to the corresponding handler.
@@ -1 +1 @@
1
- {"version":3,"file":"handover-manager.d.ts","sourceRoot":"","sources":["../../src/uns/handover-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,SAAS,MAAM,2BAA2B,CAAC;AAGlD,OAAO,YAAY,MAAM,+BAA+B,CAAC;AAEzD;;;;GAIG;AACH,qBAAa,eAAe;IACnB,KAAK,EAAE,2BAA2B,CAAC,qBAAqB,CAAC,CAA4D;IAC5H,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,kBAAkB,CAAkB;IAC5C,OAAO,CAAC,kBAAkB,CAAkB;IAC5C,OAAO,CAAC,YAAY,CAAmB;IACvC,OAAO,CAAC,aAAa,CAA6B;IAClD,OAAO,CAAC,MAAM,CAAkB;IACzB,sBAAsB,EAAE,OAAO,CAAS;IACxC,eAAe,EAAE,OAAO,CAAQ;IAChC,iBAAiB,EAAE,OAAO,CAAS;gBAE9B,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,EAAE,EAAE,sBAAsB,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,iBAAiB,EAAE,OAAO;IA0B5K;;;OAGG;IACU,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAoExE;;OAEG;YACW,cAAc;CAyI7B"}
1
+ {"version":3,"file":"handover-manager.d.ts","sourceRoot":"","sources":["../../src/uns/handover-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,SAAS,MAAM,2BAA2B,CAAC;AAGlD,OAAO,YAAY,MAAM,+BAA+B,CAAC;AAEzD;;;;GAIG;AACH,qBAAa,eAAe;IACnB,KAAK,EAAE,2BAA2B,CAAC,qBAAqB,CAAC,CAA4D;IAC5H,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,kBAAkB,CAAkB;IAC5C,OAAO,CAAC,kBAAkB,CAAkB;IAC5C,OAAO,CAAC,YAAY,CAAmB;IACvC,OAAO,CAAC,aAAa,CAA6B;IAClD,OAAO,CAAC,MAAM,CAAkB;IACzB,sBAAsB,EAAE,OAAO,CAAS;IACxC,eAAe,EAAE,OAAO,CAAQ;IAChC,iBAAiB,EAAE,OAAO,CAAS;gBAE9B,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,EAAE,EAAE,sBAAsB,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,iBAAiB,EAAE,OAAO;IA2B/L,OAAO,CAAC,iBAAiB;IAOzB,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,gBAAgB;IAgBxB;;;OAGG;IACU,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IA6ExE;;OAEG;YACW,cAAc;CAmI7B"}
@@ -10,6 +10,7 @@ import { ACTIVE_TIMEOUT, PACKAGE_INFO } from "./process-config.js";
10
10
  export class HandoverManager {
11
11
  event = new HandoverManagerEventEmitter();
12
12
  processName;
13
+ processId;
13
14
  mqttProxy;
14
15
  unsMqttProxies;
15
16
  requestingHandover = false;
@@ -20,8 +21,9 @@ export class HandoverManager {
20
21
  handoverRequestEnabled = false;
21
22
  handoverEnabled = true;
22
23
  forceStartEnabled = false;
23
- constructor(processName, mqttProxy, unsMqttProxies, handoverRequestEnabled, handoverEnabled, forceStartEnabled) {
24
+ constructor(processName, processId, mqttProxy, unsMqttProxies, handoverRequestEnabled, handoverEnabled, forceStartEnabled) {
24
25
  this.processName = processName;
26
+ this.processId = processId;
25
27
  this.mqttProxy = mqttProxy;
26
28
  this.unsMqttProxies = unsMqttProxies;
27
29
  this.handoverRequestEnabled = handoverRequestEnabled;
@@ -43,19 +45,54 @@ export class HandoverManager {
43
45
  });
44
46
  }, ACTIVE_TIMEOUT);
45
47
  }
48
+ getUserProperties() {
49
+ return {
50
+ processName: this.processName,
51
+ processId: this.processId,
52
+ };
53
+ }
54
+ getSourceProcessId(event) {
55
+ return event.packet?.properties?.userProperties?.processId;
56
+ }
57
+ parseActiveValue(message) {
58
+ try {
59
+ const parsed = JSON.parse(message);
60
+ const value = parsed?.message?.data?.value ?? parsed?.data?.value;
61
+ if (value === 1 || value === "1" || value === true || value === "true") {
62
+ return true;
63
+ }
64
+ if (value === 0 || value === "0" || value === false || value === "false") {
65
+ return false;
66
+ }
67
+ return null;
68
+ }
69
+ catch {
70
+ return null;
71
+ }
72
+ }
46
73
  /**
47
74
  * Main entry point for handling incoming MQTT messages.
48
75
  * It checks the topic and delegates to the corresponding handler.
49
76
  */
50
77
  async handleMqttMessage(event) {
51
78
  try {
79
+ const activeTopic = this.topicBuilder.getActiveTopic();
52
80
  // Check if the packet is active messages from other processes and this process is not active.
53
- if (this.requestingHandover === false &&
54
- this.topicBuilder.getActiveTopic() !== event.topic &&
81
+ if (event.topic === activeTopic &&
82
+ this.requestingHandover === false &&
55
83
  this.active === false &&
56
84
  this.handoverInProgress === false) {
57
- logger.info(`${this.processName} - Another process is active on ${event.topic}.`);
58
- if (this.handoverRequestEnabled) {
85
+ const sourceProcessId = this.getSourceProcessId(event);
86
+ if (sourceProcessId === this.processId) {
87
+ return;
88
+ }
89
+ const activeValue = this.parseActiveValue(event.message.toString());
90
+ if (activeValue !== true) {
91
+ return;
92
+ }
93
+ const sourceInfo = sourceProcessId ? ` (processId=${sourceProcessId})` : "";
94
+ logger.info(`${this.processName} - Another process is active${sourceInfo} on ${event.topic}.`);
95
+ if (this.handoverRequestEnabled && this.handoverEnabled) {
59
96
  // Requester process
60
97
  // Publish a handover request message after 10 seconds to the handover topic.
61
98
  clearTimeout(this.activeTimeout); // Clear the active timeout if it exists - prevent this process from becoming active after a timeout.
@@ -71,9 +108,7 @@ export class HandoverManager {
71
108
  retain: false,
72
109
  properties: {
73
110
  responseTopic: this.topicBuilder.getHandoverTopic(),
74
- userProperties: {
75
- processName: this.processName,
76
- },
111
+ userProperties: this.getUserProperties(),
77
112
  },
78
113
  });
79
114
  }, 10000);
@@ -95,13 +130,14 @@ export class HandoverManager {
95
130
  }
96
131
  else {
97
132
  logger.info(`${this.processName} - Waiting for the other process on topic ${event.topic} to become passive.`);
98
- this.activeTimeout.refresh();
133
+ this.activeTimeout?.refresh();
99
134
  }
100
135
  }
101
136
  }
102
137
  // Check if the packet is an handover message, sent to a handover topic.
103
138
  if (event.topic === this.topicBuilder.getHandoverTopic() && this.handoverEnabled) {
104
- if (event.packet?.properties?.userProperties?.processName && event.packet.properties.userProperties.processName !== this.processName) {
139
+ const sourceProcessId = this.getSourceProcessId(event);
140
+ if (sourceProcessId !== this.processId) {
105
141
  await this.handleHandover(event);
106
142
  }
107
143
  }
@@ -142,9 +178,7 @@ export class HandoverManager {
142
178
  retain: false,
143
179
  properties: {
144
180
  responseTopic: this.topicBuilder.getHandoverTopic(),
145
- userProperties: {
146
- processName: this.processName,
147
- },
181
+ userProperties: this.getUserProperties(),
148
182
  },
149
183
  });
150
184
  }
@@ -160,9 +194,7 @@ export class HandoverManager {
160
194
  retain: false,
161
195
  properties: {
162
196
  responseTopic: this.topicBuilder.getHandoverTopic(),
163
- userProperties: {
164
- processName: this.processName,
165
- },
197
+ userProperties: this.getUserProperties(),
166
198
  },
167
199
  });
168
200
  logger.info(`${this.processName} - Handover fin message sent.`);
@@ -205,9 +237,7 @@ export class HandoverManager {
205
237
  retain: false,
206
238
  properties: {
207
239
  responseTopic: this.topicBuilder.getHandoverTopic(),
208
- userProperties: {
209
- processName: this.processName,
210
- },
240
+ userProperties: this.getUserProperties(),
211
241
  },
212
242
  });
213
243
  logger.info(`${this.processName} - Handover ack message sent.`);
@@ -1 +1 @@
1
- {"version":3,"file":"handover-manager.js","sourceRoot":"","sources":["../../src/uns/handover-manager.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAGlF,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnE;;;;GAIG;AACH,MAAM,OAAO,eAAe;IACnB,KAAK,GAAuD,IAAI,2BAA2B,EAAyB,CAAC;IACpH,WAAW,CAAS;IACpB,SAAS,CAAY;IACrB,cAAc,CAAiB;IAC/B,kBAAkB,GAAY,KAAK,CAAC;IACpC,kBAAkB,GAAY,KAAK,CAAC;IACpC,YAAY,CAAmB;IAC/B,aAAa,CAA6B;IAC1C,MAAM,GAAY,KAAK,CAAC;IACzB,sBAAsB,GAAY,KAAK,CAAC;IACxC,eAAe,GAAY,IAAI,CAAC;IAChC,iBAAiB,GAAY,KAAK,CAAC;IAE1C,YAAY,WAAmB,EAAE,SAAoB,EAAE,cAA8B,EAAE,sBAA+B,EAAE,eAAwB,EAAE,iBAA0B;QAC1K,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,sBAAsB,GAA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port logger from \"../logger.js\";\nimport { HandoverManagerEventEmitter } from \"./handover-manager-event-emitter.js\";\nimport { HandoverManagerEvents } from \"../uns-mqtt/mqtt-interfaces.js\";\nimport MqttProxy from \"../uns-mqtt/mqtt-proxy.js\";\nimport { MqttTopicBuilder } from \"../uns-mqtt/mqtt-topic-builder.js\";\nimport { ACTIVE_TIMEOUT, PACKAGE_INFO } from \"./process-config.js\";\nimport UnsMqttProxy from \"../uns-mqtt/uns-mqtt-proxy.js\";\n\n/**\n * HandoverManager is responsible for all handover-related logic,\n * including handling incoming MQTT messages, issuing handover requests,\n * and processing handover responses.\n */\nexport class HandoverManager {\n public event: HandoverManagerEventEmitter<HandoverManagerEvents> = new HandoverManagerEventEmitter<HandoverManagerEvents>();\n private processName: string;\n private mqttProxy: MqttProxy;\n private unsMqttProxies: UnsMqttProxy[];\n private requestingHandover: boolean = false;\n private handoverInProgress: boolean = false;\n private topicBuilder: MqttTopicBuilder;\n private activeTimeout: NodeJS.Timeout | undefined;\n private active: boolean = false;\n public handoverRequestEnabled: boolean = false;\n public handoverEnabled: boolean = true;\n public forceStartEnabled: boolean = false;\n\n constructor(processName: string, mqttProxy: MqttProxy, unsMqttProxies: UnsMqttProxy[], handoverRequestEnabled: boolean, handoverEnabled: boolean, forceStartEnabled: boolean) {\n this.processName = processName;\n this.mqttProxy = mqttProxy;\n this.unsMqttProxies = unsMqttProxies;\n this.handoverRequestEnabled = handoverRequestEnabled;\n this.handoverEnabled = handoverEnabled;\n this.forceStartEnabled = forceStartEnabled;\n\n // Instantiate the topic builder.\n const packageName = PACKAGE_INFO.name;\n const version = PACKAGE_INFO.version;\n this.topicBuilder = new MqttTopicBuilder(`uns-infra/${MqttTopicBuilder.sanitizeTopicPart(packageName)}/${MqttTopicBuilder.sanitizeTopicPart(version)}/${MqttTopicBuilder.sanitizeTopicPart(this.processName)}/`);\n\n // Set status as active after a timeout if no other active process are detected.\n this.activeTimeout = setTimeout(() => {\n logger.info(`${this.processName} - No active message received within timeout. Assuming no other process is running.`);\n this.active = true;\n this.event.emit(\"handoverManager\", { active: this.active });\n // Activate all UNS proxy instance publishers and subscribers.\n this.unsMqttProxies.forEach((unsProxy) => {\n unsProxy.setPublisherActive();\n unsProxy.setSubscriberActive();\n });\n }, ACTIVE_TIMEOUT);\n }\n\n /**\n * Main entry point for handling incoming MQTT messages.\n * It checks the topic and delegates to the corresponding handler.\n */\n public async handleMqttMessage(event: UnsEvents[\"input\"]): Promise<void> {\n try {\n // Check if the packet is active messages from other processes and this process is not active.\n if (\n this.requestingHandover === false &&\n this.topicBuilder.getActiveTopic() !== event.topic &&\n this.active === false &&\n this.handoverInProgress === false\n ) {\n logger.info(`${this.processName} - Another process is active on ${event.topic}.`);\n\n if (this.handoverRequestEnabled) {\n // Requester process\n // Publish a handover request message after 10 seconds to the handover topic.\n clearTimeout(this.activeTimeout); // Clear the active timeout if it exists - prevent this process from becoming active after a timeout.\n this.activeTimeout = undefined;\n this.event.emit(\"handoverManager\", { active: this.active });\n this.requestingHandover = true;\n logger.info(`${this.processName} - Requesting handover in 10 seconds.`);\n setTimeout(async () => {\n const eventHandoverTopic = new MqttTopicBuilder(MqttTopicBuilder.extractBaseTopic(event.topic)).getHandoverTopic();\n logger.info(`${this.processName} - Requesting handover ${eventHandoverTopic}.`);\n this.handoverInProgress = true;\n await this.mqttProxy.publish(eventHandoverTopic, JSON.stringify({ type: \"handover_request\" }), {\n retain: false,\n properties: {\n responseTopic: this.topicBuilder.getHandoverTopic(),\n userProperties: {\n processName: this.processName,\n },\n },\n });\n }, 10000);\n } else {\n if (this.forceStartEnabled) {\n // Force start the process even if another process is active.\n logger.info(`${this.processName} - Force starting the process.`);\n logger.warn(`${this.processName} - Warning: Source and destination being the same may lead to duplicate messages.`);\n clearTimeout(this.activeTimeout); // Clear the active timeout if it exists - prevent this process from becoming active after a timeout.\n this.activeTimeout = undefined;\n this.active = true;\n this.event.emit(\"handoverManager\", { active: this.active });\n // Activate all UNS proxy instance publishers and subscribers.\n this.unsMqttProxies.forEach((unsProxy) => {\n unsProxy.setPublisherActive();\n unsProxy.setSubscriberActive();\n }\n );\n }\n else {\n logger.info(`${this.processName} - Waiting for the other process on topic ${event.topic} to become passive.`);\n this.activeTimeout.refresh();\n }\n }\n }\n\n // Check if the packet is an handover message, sent to a handover topic.\n if (event.topic === this.topicBuilder.getHandoverTopic() && this.handoverEnabled) {\n if (event.packet?.properties?.userProperties?.processName && event.packet.properties.userProperties.processName !== this.processName) {\n await this.handleHandover(event);\n }\n }\n } catch (error) {\n logger.error(`${this.processName} - Error processing MQTT message: ${error.message}`);\n return;\n }\n }\n\n /**\n * Handles handovers.\n */\n private async handleHandover(event: UnsEvents[\"input\"]): Promise<void> {\n try {\n const response = JSON.parse(event.message.toString());\n // Responder process\n // Check if the message is a handover request and publish MULTIPLE handover_subscriber messages\n if (response.type === \"handover_request\") {\n logger.info(\n `${this.processName} - Received handover request from ${event.packet?.properties?.userProperties?.processName}. Accepting handover.`,\n );\n\n // Set all UNS proxy instance subscribers to passive and drain the queue.\n const mqttWorkerData: UnsEvents[\"mqttWorker\"][] = [];\n for (let i = 0; i < this.unsMqttProxies.length; i++) {\n const unsProxy = this.unsMqttProxies[i];\n const workerData = await unsProxy.setSubscriberPassiveAndDrainQueue();\n mqttWorkerData.push(workerData);\n }\n logger.info(`${this.processName} - Handover request accepted. Sending handover_subscriber messages.`);\n\n // Publish handover_subscriber messages for each instance that has processed some data.\n for (let i = 0; i < mqttWorkerData.length; i++) {\n const workerData = mqttWorkerData[i];\n if (workerData.batchSize > 0) {\n await this.mqttProxy.publish(\n event.packet.properties?.responseTopic ?? \"\",\n JSON.stringify({\n type: \"handover_subscriber\",\n batchSize: workerData.batchSize,\n referenceHash: workerData.referenceHash,\n instanceName: workerData.instanceName,\n }),\n {\n retain: false,\n properties: {\n responseTopic: this.topicBuilder.getHandoverTopic(),\n userProperties: {\n processName: this.processName,\n },\n },\n },\n );\n }\n }\n logger.info(`${this.processName} - Handover subscriber messages sent.`);\n\n // Publish a single handover acknowledgment only when all\n // handover_subscriber messages have been sent\n this.active = false;\n this.event.emit(\"handoverManager\", { active: this.active });\n await this.mqttProxy.publish(\n event.packet.properties?.responseTopic ?? \"\",\n JSON.stringify({\n type: \"handover_fin\",\n }),\n {\n retain: false,\n properties: {\n responseTopic: this.topicBuilder.getHandoverTopic(),\n userProperties: {\n processName: this.processName,\n },\n },\n },\n );\n logger.info(`${this.processName} - Handover fin message sent.`);\n\n this.handoverInProgress = false;\n this.requestingHandover = false;\n\n this.unsMqttProxies.forEach((unsProxy: UnsMqttProxy) => {\n unsProxy.stop();\n });\n }\n\n // Requestor process\n // Check if the message is one of the handover_subscriber message in response to handover_request\n // and publish a handover_ack message\n if (response.type === \"handover_subscriber\") {\n // Find correct unsProxy instance for handover_subscriber and set it active\n this.unsMqttProxies.forEach((unsProxy: UnsMqttProxy) => {\n if (unsProxy.instanceName === response.instanceName) {\n unsProxy.setSubscriberActive(response.batchSize, response.referenceHash);\n }\n });\n }\n\n // Requestor process\n // Check if the message is a handover_fin at the end of handover_subscriber messages\n if (response.type === \"handover_fin\") {\n logger.info(`${this.processName} - Received handover fin from ${event.packet?.properties?.userProperties?.processName}.`);\n\n // Maybe we should count the number of requests that were allrady made TODO\n // this.handoverInProgress = false;\n // this.requestingHandover = false;\n\n this.active = true;\n this.event.emit(\"handoverManager\", { active: this.active });\n logger.info(`${this.processName} - Handover completed.`);\n // Activate all UNS proxy instance publishers and subscribers.\n this.unsMqttProxies.forEach((unsProxy) => {\n unsProxy.setPublisherActive();\n unsProxy.setSubscriberActive();\n });\n\n // Maybe we should reply with handover_ack.\n await this.mqttProxy.publish(\n event.packet.properties?.responseTopic ?? \"\",\n JSON.stringify({\n type: \"handover_ack\",\n }),\n {\n retain: false,\n properties: {\n responseTopic: this.topicBuilder.getHandoverTopic(),\n userProperties: {\n processName: this.processName,\n },\n },\n },\n );\n logger.info(`${this.processName} - Handover ack message sent.`);\n }\n\n // Responder process\n // Check if the message is a handover_ack at the end of handover_fin messages\n if (response.type === \"handover_ack\") {\n logger.info(`${this.processName} - Received handover ack from ${event.packet?.properties?.userProperties?.processName}.`);\n this.handoverInProgress = false;\n this.requestingHandover = false;\n\n logger.info(`${this.processName} - Handover completed. Exiting process.`);\n process.exit(0);\n }\n } catch (error) {\n logger.error(`${this.processName} - Error processing handover response: ${error.message}`);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"handover-manager.js","sourceRoot":"","sources":["../../src/uns/handover-manager.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAGlF,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnE;;;;GAIG;AACH,MAAM,OAAO,eAAe;IACnB,KAAK,GAAuD,IAAI,2BAA2B,EAAyB,CAAC;IACpH,WAAW,CAAS;IACpB,SAAS,CAAS;IAClB,SAAS,CAAY;IACrB,cAAc,CAAiB;IAC/B,kBAAkB,GAAY,KAAK,CAAC;IACpC,kBAAkB,GAAY,KAAK,CAAC;IACpC,YAAY,CAAmB;IAC/B,aAAa,CAA6B;IAC1C,MAAM,GAAY,KAAK,CAAC;IACzB,sBAAsB,GAAY,KAAK,CAAC;IACxC,eAAe,GAAY,IAAI,CAAC;IAChC,iBAAiB,GAAY,KAAK,CAAC;IAE1C,YAAY,WAAmB,EAAE,SAAiB,EAAE,SAAoB,EAAE,cAA8B,EAAE,sBAA+B,EAAE,eAAwB,EAAE,iBAA0B;QAC7L,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,sBAAsB,GAAG,sBAAsB,CAAC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\";\nimport { HandoverManagerEventEmitter } from \"./handover-manager-event-emitter.js\";\nimport { HandoverManagerEvents } from \"../uns-mqtt/mqtt-interfaces.js\";\nimport MqttProxy from \"../uns-mqtt/mqtt-proxy.js\";\nimport { MqttTopicBuilder } from \"../uns-mqtt/mqtt-topic-builder.js\";\nimport { ACTIVE_TIMEOUT, PACKAGE_INFO } from \"./process-config.js\";\nimport UnsMqttProxy from \"../uns-mqtt/uns-mqtt-proxy.js\";\n\n/**\n * HandoverManager is responsible for all handover-related logic,\n * including handling incoming MQTT messages, issuing handover requests,\n * and processing handover responses.\n */\nexport class HandoverManager {\n public event: HandoverManagerEventEmitter<HandoverManagerEvents> = new HandoverManagerEventEmitter<HandoverManagerEvents>();\n private processName: string;\n private processId: string;\n private mqttProxy: MqttProxy;\n private unsMqttProxies: UnsMqttProxy[];\n private requestingHandover: boolean = false;\n private handoverInProgress: boolean = false;\n private topicBuilder: MqttTopicBuilder;\n private activeTimeout: NodeJS.Timeout | undefined;\n private active: boolean = false;\n public handoverRequestEnabled: boolean = false;\n public handoverEnabled: boolean = true;\n public forceStartEnabled: boolean = false;\n\n constructor(processName: string, processId: string, mqttProxy: MqttProxy, unsMqttProxies: UnsMqttProxy[], handoverRequestEnabled: boolean, handoverEnabled: boolean, forceStartEnabled: boolean) {\n this.processName = processName;\n this.processId = processId;\n this.mqttProxy = mqttProxy;\n this.unsMqttProxies = unsMqttProxies;\n this.handoverRequestEnabled = handoverRequestEnabled;\n this.handoverEnabled = handoverEnabled;\n this.forceStartEnabled = forceStartEnabled;\n\n // Instantiate the topic builder.\n const packageName = PACKAGE_INFO.name;\n const version = PACKAGE_INFO.version;\n this.topicBuilder = new MqttTopicBuilder(`uns-infra/${MqttTopicBuilder.sanitizeTopicPart(packageName)}/${MqttTopicBuilder.sanitizeTopicPart(version)}/${MqttTopicBuilder.sanitizeTopicPart(this.processName)}/`);\n\n // Set status as active after a timeout if no other active process are detected.\n this.activeTimeout = setTimeout(() => {\n logger.info(`${this.processName} - No active message received within timeout. Assuming no other process is running.`);\n this.active = true;\n this.event.emit(\"handoverManager\", { active: this.active });\n // Activate all UNS proxy instance publishers and subscribers.\n this.unsMqttProxies.forEach((unsProxy) => {\n unsProxy.setPublisherActive();\n unsProxy.setSubscriberActive();\n });\n }, ACTIVE_TIMEOUT);\n }\n\n private getUserProperties(): Record<string, string> {\n return {\n processName: this.processName,\n processId: this.processId,\n };\n }\n\n private getSourceProcessId(event: UnsEvents[\"input\"]): string | undefined {\n return event.packet?.properties?.userProperties?.processId;\n }\n\n private parseActiveValue(message: string): boolean | null {\n try {\n const parsed = JSON.parse(message);\n const value = parsed?.message?.data?.value ?? parsed?.data?.value;\n if (value === 1 || value === \"1\" || value === true || value === \"true\") {\n return true;\n }\n if (value === 0 || value === \"0\" || value === false || value === \"false\") {\n return false;\n }\n return null;\n } catch {\n return null;\n }\n }\n\n /**\n * Main entry point for handling incoming MQTT messages.\n * It checks the topic and delegates to the corresponding handler.\n */\n public async handleMqttMessage(event: UnsEvents[\"input\"]): Promise<void> {\n try {\n const activeTopic = this.topicBuilder.getActiveTopic();\n // Check if the packet is active messages from other processes and this process is not active.\n if (\n event.topic === activeTopic &&\n this.requestingHandover === false &&\n this.active === false &&\n this.handoverInProgress === false\n ) {\n const sourceProcessId = this.getSourceProcessId(event);\n if (sourceProcessId === this.processId) {\n return;\n }\n const activeValue = this.parseActiveValue(event.message.toString());\n if (activeValue !== true) {\n return;\n }\n const sourceInfo = sourceProcessId ? ` (processId=${sourceProcessId})` : \"\";\n logger.info(`${this.processName} - Another process is active${sourceInfo} on ${event.topic}.`);\n\n if (this.handoverRequestEnabled && this.handoverEnabled) {\n // Requester process\n // Publish a handover request message after 10 seconds to the handover topic.\n clearTimeout(this.activeTimeout); // Clear the active timeout if it exists - prevent this process from becoming active after a timeout.\n this.activeTimeout = undefined;\n this.event.emit(\"handoverManager\", { active: this.active });\n this.requestingHandover = true;\n logger.info(`${this.processName} - Requesting handover in 10 seconds.`);\n setTimeout(async () => {\n const eventHandoverTopic = new MqttTopicBuilder(MqttTopicBuilder.extractBaseTopic(event.topic)).getHandoverTopic();\n logger.info(`${this.processName} - Requesting handover ${eventHandoverTopic}.`);\n this.handoverInProgress = true;\n await this.mqttProxy.publish(eventHandoverTopic, JSON.stringify({ type: \"handover_request\" }), {\n retain: false,\n properties: {\n responseTopic: this.topicBuilder.getHandoverTopic(),\n userProperties: this.getUserProperties(),\n },\n });\n }, 10000);\n } else {\n if (this.forceStartEnabled) {\n // Force start the process even if another process is active.\n logger.info(`${this.processName} - Force starting the process.`);\n logger.warn(`${this.processName} - Warning: Source and destination being the same may lead to duplicate messages.`);\n clearTimeout(this.activeTimeout); // Clear the active timeout if it exists - prevent this process from becoming active after a timeout.\n this.activeTimeout = undefined;\n this.active = true;\n this.event.emit(\"handoverManager\", { active: this.active });\n // Activate all UNS proxy instance publishers and subscribers.\n this.unsMqttProxies.forEach((unsProxy) => {\n unsProxy.setPublisherActive();\n unsProxy.setSubscriberActive();\n }\n );\n }\n else {\n logger.info(`${this.processName} - Waiting for the other process on topic ${event.topic} to become passive.`);\n this.activeTimeout?.refresh();\n }\n }\n }\n\n // Check if the packet is an handover message, sent to a handover topic.\n if (event.topic === this.topicBuilder.getHandoverTopic() && this.handoverEnabled) {\n const sourceProcessId = this.getSourceProcessId(event);\n if (sourceProcessId !== this.processId) {\n await this.handleHandover(event);\n }\n }\n } catch (error) {\n logger.error(`${this.processName} - Error processing MQTT message: ${error.message}`);\n return;\n }\n }\n\n /**\n * Handles handovers.\n */\n private async handleHandover(event: UnsEvents[\"input\"]): Promise<void> {\n try {\n const response = JSON.parse(event.message.toString());\n // Responder process\n // Check if the message is a handover request and publish MULTIPLE handover_subscriber messages\n if (response.type === \"handover_request\") {\n logger.info(\n `${this.processName} - Received handover request from ${event.packet?.properties?.userProperties?.processName}. Accepting handover.`,\n );\n\n // Set all UNS proxy instance subscribers to passive and drain the queue.\n const mqttWorkerData: UnsEvents[\"mqttWorker\"][] = [];\n for (let i = 0; i < this.unsMqttProxies.length; i++) {\n const unsProxy = this.unsMqttProxies[i];\n const workerData = await unsProxy.setSubscriberPassiveAndDrainQueue();\n mqttWorkerData.push(workerData);\n }\n logger.info(`${this.processName} - Handover request accepted. Sending handover_subscriber messages.`);\n\n // Publish handover_subscriber messages for each instance that has processed some data.\n for (let i = 0; i < mqttWorkerData.length; i++) {\n const workerData = mqttWorkerData[i];\n if (workerData.batchSize > 0) {\n await this.mqttProxy.publish(\n event.packet.properties?.responseTopic ?? \"\",\n JSON.stringify({\n type: \"handover_subscriber\",\n batchSize: workerData.batchSize,\n referenceHash: workerData.referenceHash,\n instanceName: workerData.instanceName,\n }),\n {\n retain: false,\n properties: {\n responseTopic: this.topicBuilder.getHandoverTopic(),\n userProperties: this.getUserProperties(),\n },\n },\n );\n }\n }\n logger.info(`${this.processName} - Handover subscriber messages sent.`);\n\n // Publish a single handover acknowledgment only when all\n // handover_subscriber messages have been sent\n this.active = false;\n this.event.emit(\"handoverManager\", { active: this.active });\n await this.mqttProxy.publish(\n event.packet.properties?.responseTopic ?? \"\",\n JSON.stringify({\n type: \"handover_fin\",\n }),\n {\n retain: false,\n properties: {\n responseTopic: this.topicBuilder.getHandoverTopic(),\n userProperties: this.getUserProperties(),\n },\n },\n );\n logger.info(`${this.processName} - Handover fin message sent.`);\n\n this.handoverInProgress = false;\n this.requestingHandover = false;\n\n this.unsMqttProxies.forEach((unsProxy: UnsMqttProxy) => {\n unsProxy.stop();\n });\n }\n\n // Requestor process\n // Check if the message is one of the handover_subscriber message in response to handover_request\n // and publish a handover_ack message\n if (response.type === \"handover_subscriber\") {\n // Find correct unsProxy instance for handover_subscriber and set it active\n this.unsMqttProxies.forEach((unsProxy: UnsMqttProxy) => {\n if (unsProxy.instanceName === response.instanceName) {\n unsProxy.setSubscriberActive(response.batchSize, response.referenceHash);\n }\n });\n }\n\n // Requestor process\n // Check if the message is a handover_fin at the end of handover_subscriber messages\n if (response.type === \"handover_fin\") {\n logger.info(`${this.processName} - Received handover fin from ${event.packet?.properties?.userProperties?.processName}.`);\n\n // Maybe we should count the number of requests that were allrady made TODO\n // this.handoverInProgress = false;\n // this.requestingHandover = false;\n\n this.active = true;\n this.event.emit(\"handoverManager\", { active: this.active });\n logger.info(`${this.processName} - Handover completed.`);\n // Activate all UNS proxy instance publishers and subscribers.\n this.unsMqttProxies.forEach((unsProxy) => {\n unsProxy.setPublisherActive();\n unsProxy.setSubscriberActive();\n });\n\n // Maybe we should reply with handover_ack.\n await this.mqttProxy.publish(\n event.packet.properties?.responseTopic ?? \"\",\n JSON.stringify({\n type: \"handover_ack\",\n }),\n {\n retain: false,\n properties: {\n responseTopic: this.topicBuilder.getHandoverTopic(),\n userProperties: this.getUserProperties(),\n },\n },\n );\n logger.info(`${this.processName} - Handover ack message sent.`);\n }\n\n // Responder process\n // Check if the message is a handover_ack at the end of handover_fin messages\n if (response.type === \"handover_ack\") {\n logger.info(`${this.processName} - Received handover ack from ${event.packet?.properties?.userProperties?.processName}.`);\n this.handoverInProgress = false;\n this.requestingHandover = false;\n\n logger.info(`${this.processName} - Handover completed. Exiting process.`);\n process.exit(0);\n }\n } catch (error) {\n logger.error(`${this.processName} - Error processing handover response: ${error.message}`);\n }\n }\n}\n"]}
@@ -5,6 +5,7 @@ export declare class StatusMonitor {
5
5
  private activeSupplier;
6
6
  private memoryIntervalMs;
7
7
  private statusIntervalMs;
8
+ private processIdentity?;
8
9
  private memoryInterval?;
9
10
  private statusInterval?;
10
11
  /**
@@ -13,8 +14,12 @@ export declare class StatusMonitor {
13
14
  * @param activeSupplier A function returning the current active state (boolean).
14
15
  * @param memoryIntervalMs Interval in milliseconds for publishing memory status.
15
16
  * @param statusIntervalMs Interval in milliseconds for publishing active status.
17
+ * @param processIdentity Optional identity to attach to active status messages.
16
18
  */
17
- constructor(mqttProxy: MqttProxy, processStatusTopic: string, activeSupplier: () => boolean, memoryIntervalMs: number, statusIntervalMs: number);
19
+ constructor(mqttProxy: MqttProxy, processStatusTopic: string, activeSupplier: () => boolean, memoryIntervalMs: number, statusIntervalMs: number, processIdentity?: {
20
+ processName: string;
21
+ processId: string;
22
+ });
18
23
  /**
19
24
  * Starts the periodic memory and status updates.
20
25
  */
@@ -1 +1 @@
1
- {"version":3,"file":"status-monitor.d.ts","sourceRoot":"","sources":["../../src/uns/status-monitor.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,SAAS,MAAM,2BAA2B,CAAC;AAEvD,qBAAa,aAAa;IAYtB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,kBAAkB;IAC1B,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,gBAAgB;IACxB,OAAO,CAAC,gBAAgB;IAf1B,OAAO,CAAC,cAAc,CAAC,CAAiB;IACxC,OAAO,CAAC,cAAc,CAAC,CAAiB;IAExC;;;;;;OAMG;gBAEO,SAAS,EAAE,SAAS,EACpB,kBAAkB,EAAE,MAAM,EAC1B,cAAc,EAAE,MAAM,OAAO,EAC7B,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,EAAE,MAAM;IAGlC;;OAEG;IACI,KAAK,IAAI,IAAI;IAKpB;;OAEG;IACI,IAAI,IAAI,IAAI;IAWnB;;;OAGG;YACW,oBAAoB;IAuBlC;;OAEG;YACW,oBAAoB;CAgBnC"}
1
+ {"version":3,"file":"status-monitor.d.ts","sourceRoot":"","sources":["../../src/uns/status-monitor.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,SAAS,MAAM,2BAA2B,CAAC;AAEvD,qBAAa,aAAa;IAatB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,kBAAkB;IAC1B,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,gBAAgB;IACxB,OAAO,CAAC,gBAAgB;IACxB,OAAO,CAAC,eAAe,CAAC;IAjB1B,OAAO,CAAC,cAAc,CAAC,CAAiB;IACxC,OAAO,CAAC,cAAc,CAAC,CAAiB;IAExC;;;;;;;OAOG;gBAEO,SAAS,EAAE,SAAS,EACpB,kBAAkB,EAAE,MAAM,EAC1B,cAAc,EAAE,MAAM,OAAO,EAC7B,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,EAAE,MAAM,EACxB,eAAe,CAAC,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE;IAGtE;;OAEG;IACI,KAAK,IAAI,IAAI;IAKpB;;OAEG;IACI,IAAI,IAAI,IAAI;IAWnB;;;OAGG;YACW,oBAAoB;IAuBlC;;OAEG;YACW,oBAAoB;CA0BnC"}
@@ -8,6 +8,7 @@ export class StatusMonitor {
8
8
  activeSupplier;
9
9
  memoryIntervalMs;
10
10
  statusIntervalMs;
11
+ processIdentity;
11
12
  memoryInterval;
12
13
  statusInterval;
13
14
  /**
@@ -16,13 +17,15 @@ export class StatusMonitor {
16
17
  * @param activeSupplier A function returning the current active state (boolean).
17
18
  * @param memoryIntervalMs Interval in milliseconds for publishing memory status.
18
19
  * @param statusIntervalMs Interval in milliseconds for publishing active status.
20
+ * @param processIdentity Optional identity to attach to active status messages.
19
21
  */
20
- constructor(mqttProxy, processStatusTopic, activeSupplier, memoryIntervalMs, statusIntervalMs) {
22
+ constructor(mqttProxy, processStatusTopic, activeSupplier, memoryIntervalMs, statusIntervalMs, processIdentity) {
21
23
  this.mqttProxy = mqttProxy;
22
24
  this.processStatusTopic = processStatusTopic;
23
25
  this.activeSupplier = activeSupplier;
24
26
  this.memoryIntervalMs = memoryIntervalMs;
25
27
  this.statusIntervalMs = statusIntervalMs;
28
+ this.processIdentity = processIdentity;
26
29
  }
27
30
  /**
28
31
  * Starts the periodic memory and status updates.
@@ -73,7 +76,17 @@ export class StatusMonitor {
73
76
  data: { time, value: Number(this.activeSupplier()) },
74
77
  };
75
78
  const packet = await UnsPacket.unsPacketFromUnsMessage(activeMessage);
76
- this.mqttProxy.publish(`${this.processStatusTopic}active`, JSON.stringify(packet), { retain: false, });
79
+ this.mqttProxy.publish(`${this.processStatusTopic}active`, JSON.stringify(packet), {
80
+ retain: false,
81
+ properties: this.processIdentity
82
+ ? {
83
+ userProperties: {
84
+ processName: this.processIdentity.processName,
85
+ processId: this.processIdentity.processId,
86
+ },
87
+ }
88
+ : undefined,
89
+ });
77
90
  }
78
91
  catch (error) {
79
92
  logger.error(`StatusMonitor - Error publishing status updates: ${error.message}`);