@uns-kit/core 2.0.40 → 2.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +170 -147
- package/dist/index.d.ts +9 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/tools/datahub/datahub-client.js.map +1 -1
- package/dist/tools/file-utils.d.ts +2 -2
- package/dist/tools/file-utils.js +24 -24
- package/dist/tools/generate-uns-dictionary.d.ts +23 -23
- package/dist/tools/generate-uns-dictionary.js +154 -154
- package/dist/tools/generate-uns-measurements.d.ts +21 -21
- package/dist/tools/generate-uns-measurements.js +126 -126
- package/dist/tools/generate-uns-reference.d.ts +2 -2
- package/dist/tools/generate-uns-reference.js +85 -85
- package/dist/tools/refresh-uns.js +50 -50
- package/dist/tools/sync-uns-schema.d.ts +2 -2
- package/dist/tools/sync-uns-schema.js +489 -489
- package/dist/uns/service-metadata.d.ts +53 -0
- package/dist/uns/service-metadata.d.ts.map +1 -0
- package/dist/uns/service-metadata.js +56 -0
- package/dist/uns/service-metadata.js.map +1 -0
- package/dist/uns/uns-asset.d.ts +1 -1
- package/dist/uns/uns-asset.js +1 -1
- package/dist/uns/uns-attributes.d.ts +6 -6
- package/dist/uns/uns-attributes.js +9 -9
- package/dist/uns/uns-dictionary-registry.d.ts +4 -4
- package/dist/uns/uns-dictionary-registry.js +20 -20
- package/dist/uns/uns-dictionary.generated.d.ts +663 -663
- package/dist/uns/uns-dictionary.generated.js +745 -745
- package/dist/uns/uns-interfaces.d.ts +365 -365
- package/dist/uns/uns-measurements.generated.d.ts +362 -362
- package/dist/uns/uns-measurements.generated.js +359 -359
- package/dist/uns/uns-object.d.ts +20 -20
- package/dist/uns/uns-object.js +9 -9
- package/dist/uns/uns-packet.js +263 -263
- package/dist/uns/uns-path.d.ts +2 -2
- package/dist/uns/uns-path.js +10 -10
- package/dist/uns/uns-proxy-process.d.ts +11 -0
- package/dist/uns/uns-proxy-process.d.ts.map +1 -1
- package/dist/uns/uns-proxy-process.js +224 -203
- package/dist/uns/uns-proxy-process.js.map +1 -1
- package/dist/uns/uns-proxy.d.ts +51 -51
- package/dist/uns/uns-proxy.js +190 -190
- package/dist/uns-config/uns-core-schema.d.ts +3276 -3276
- package/dist/uns-grpc/uns-gateway.proto +104 -104
- package/dist/uns-mqtt/mqtt-topic-builder.d.ts +6 -0
- package/dist/uns-mqtt/mqtt-topic-builder.d.ts.map +1 -1
- package/dist/uns-mqtt/mqtt-topic-builder.js +8 -0
- package/dist/uns-mqtt/mqtt-topic-builder.js.map +1 -1
- package/dist/uns-mqtt/uns-mqtt-proxy.js +477 -477
- package/package.json +1 -1
- package/dist/app-config.d.ts.map +0 -1
- package/dist/app-config.js.map +0 -1
|
@@ -1,104 +1,104 @@
|
|
|
1
|
-
syntax = "proto3";
|
|
2
|
-
|
|
3
|
-
package uns;
|
|
4
|
-
|
|
5
|
-
service UnsGateway {
|
|
6
|
-
rpc Publish (PublishRequest) returns (Ack);
|
|
7
|
-
rpc Subscribe (SubscribeRequest) returns (stream MqttMessage);
|
|
8
|
-
rpc RegisterApiGet (RegisterApiGetRequest) returns (Ack);
|
|
9
|
-
rpc UnregisterApiGet (UnregisterApiGetRequest) returns (Ack);
|
|
10
|
-
rpc ApiEventStream (stream ApiEventResponse) returns (stream ApiEvent);
|
|
11
|
-
rpc Ready (ReadyRequest) returns (Ack);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
message PublishRequest {
|
|
15
|
-
string topic = 1;
|
|
16
|
-
string attribute = 2;
|
|
17
|
-
string description = 3;
|
|
18
|
-
repeated string tags = 4;
|
|
19
|
-
bool attribute_needs_persistence = 5;
|
|
20
|
-
oneof content {
|
|
21
|
-
Data data = 6;
|
|
22
|
-
Table table = 7;
|
|
23
|
-
}
|
|
24
|
-
bool value_is_cumulative = 8; // for Data: publish as delta
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
message Data {
|
|
28
|
-
string time = 1;
|
|
29
|
-
double value_number = 2;
|
|
30
|
-
string value_string = 3;
|
|
31
|
-
string uom = 4;
|
|
32
|
-
string data_group = 5;
|
|
33
|
-
string foreign_event_key = 6;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
message TableValue {
|
|
37
|
-
string name = 1;
|
|
38
|
-
string type = 2; // QuestDB column type (e.g., int, double, geohash(5c))
|
|
39
|
-
string uom = 3; // Optional unit of measure
|
|
40
|
-
double value_number = 4;
|
|
41
|
-
string value_string = 5;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
message Table {
|
|
45
|
-
string time = 1;
|
|
46
|
-
repeated TableValue columns = 2;
|
|
47
|
-
string data_group = 3;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
message SubscribeRequest {
|
|
51
|
-
repeated string topics = 1;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
message MqttMessage {
|
|
55
|
-
string topic = 1;
|
|
56
|
-
string payload = 2; // UNS packet JSON
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
message Ack {
|
|
60
|
-
bool ok = 1;
|
|
61
|
-
string error = 2;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
message ReadyRequest {
|
|
65
|
-
int32 timeout_ms = 1; // default 15000
|
|
66
|
-
bool wait_output = 2; // wait for publisher active (output)
|
|
67
|
-
bool wait_input = 3; // wait for subscriber active (input)
|
|
68
|
-
bool wait_api = 4; // wait for API server (optional)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
message ApiQueryParam {
|
|
72
|
-
string name = 1;
|
|
73
|
-
string type = 2; // string | number | boolean
|
|
74
|
-
bool required = 3;
|
|
75
|
-
string description = 4;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
message RegisterApiGetRequest {
|
|
79
|
-
string topic = 1;
|
|
80
|
-
string attribute = 2;
|
|
81
|
-
string api_description = 3;
|
|
82
|
-
repeated string tags = 4;
|
|
83
|
-
repeated ApiQueryParam query_params = 5;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
message UnregisterApiGetRequest {
|
|
87
|
-
string topic = 1;
|
|
88
|
-
string attribute = 2;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
message ApiEvent {
|
|
92
|
-
string id = 1;
|
|
93
|
-
string method = 2; // GET only for now
|
|
94
|
-
string path = 3; // /{topic}{attribute}
|
|
95
|
-
map<string, string> query = 4;
|
|
96
|
-
string bearer = 5; // access token (optional)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
message ApiEventResponse {
|
|
100
|
-
string id = 1; // correlation
|
|
101
|
-
int32 status = 2; // HTTP status
|
|
102
|
-
string body = 3; // response body as string (JSON string if needed)
|
|
103
|
-
map<string, string> headers = 4; // optional extra headers
|
|
104
|
-
}
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
|
|
3
|
+
package uns;
|
|
4
|
+
|
|
5
|
+
service UnsGateway {
|
|
6
|
+
rpc Publish (PublishRequest) returns (Ack);
|
|
7
|
+
rpc Subscribe (SubscribeRequest) returns (stream MqttMessage);
|
|
8
|
+
rpc RegisterApiGet (RegisterApiGetRequest) returns (Ack);
|
|
9
|
+
rpc UnregisterApiGet (UnregisterApiGetRequest) returns (Ack);
|
|
10
|
+
rpc ApiEventStream (stream ApiEventResponse) returns (stream ApiEvent);
|
|
11
|
+
rpc Ready (ReadyRequest) returns (Ack);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
message PublishRequest {
|
|
15
|
+
string topic = 1;
|
|
16
|
+
string attribute = 2;
|
|
17
|
+
string description = 3;
|
|
18
|
+
repeated string tags = 4;
|
|
19
|
+
bool attribute_needs_persistence = 5;
|
|
20
|
+
oneof content {
|
|
21
|
+
Data data = 6;
|
|
22
|
+
Table table = 7;
|
|
23
|
+
}
|
|
24
|
+
bool value_is_cumulative = 8; // for Data: publish as delta
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
message Data {
|
|
28
|
+
string time = 1;
|
|
29
|
+
double value_number = 2;
|
|
30
|
+
string value_string = 3;
|
|
31
|
+
string uom = 4;
|
|
32
|
+
string data_group = 5;
|
|
33
|
+
string foreign_event_key = 6;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
message TableValue {
|
|
37
|
+
string name = 1;
|
|
38
|
+
string type = 2; // QuestDB column type (e.g., int, double, geohash(5c))
|
|
39
|
+
string uom = 3; // Optional unit of measure
|
|
40
|
+
double value_number = 4;
|
|
41
|
+
string value_string = 5;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
message Table {
|
|
45
|
+
string time = 1;
|
|
46
|
+
repeated TableValue columns = 2;
|
|
47
|
+
string data_group = 3;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
message SubscribeRequest {
|
|
51
|
+
repeated string topics = 1;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
message MqttMessage {
|
|
55
|
+
string topic = 1;
|
|
56
|
+
string payload = 2; // UNS packet JSON
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
message Ack {
|
|
60
|
+
bool ok = 1;
|
|
61
|
+
string error = 2;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
message ReadyRequest {
|
|
65
|
+
int32 timeout_ms = 1; // default 15000
|
|
66
|
+
bool wait_output = 2; // wait for publisher active (output)
|
|
67
|
+
bool wait_input = 3; // wait for subscriber active (input)
|
|
68
|
+
bool wait_api = 4; // wait for API server (optional)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
message ApiQueryParam {
|
|
72
|
+
string name = 1;
|
|
73
|
+
string type = 2; // string | number | boolean
|
|
74
|
+
bool required = 3;
|
|
75
|
+
string description = 4;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
message RegisterApiGetRequest {
|
|
79
|
+
string topic = 1;
|
|
80
|
+
string attribute = 2;
|
|
81
|
+
string api_description = 3;
|
|
82
|
+
repeated string tags = 4;
|
|
83
|
+
repeated ApiQueryParam query_params = 5;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
message UnregisterApiGetRequest {
|
|
87
|
+
string topic = 1;
|
|
88
|
+
string attribute = 2;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
message ApiEvent {
|
|
92
|
+
string id = 1;
|
|
93
|
+
string method = 2; // GET only for now
|
|
94
|
+
string path = 3; // /{topic}{attribute}
|
|
95
|
+
map<string, string> query = 4;
|
|
96
|
+
string bearer = 5; // access token (optional)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
message ApiEventResponse {
|
|
100
|
+
string id = 1; // correlation
|
|
101
|
+
int32 status = 2; // HTTP status
|
|
102
|
+
string body = 3; // response body as string (JSON string if needed)
|
|
103
|
+
map<string, string> headers = 4; // optional extra headers
|
|
104
|
+
}
|
|
@@ -38,6 +38,12 @@ export declare class MqttTopicBuilder {
|
|
|
38
38
|
* Example: "uns-infra/packageName/version/processName/handover"
|
|
39
39
|
*/
|
|
40
40
|
getHandoverTopic(): string;
|
|
41
|
+
/**
|
|
42
|
+
* Returns the retained metadata topic for product/system service discovery.
|
|
43
|
+
*
|
|
44
|
+
* Example: "uns-infra/packageName/version/processName/service-metadata"
|
|
45
|
+
*/
|
|
46
|
+
getServiceMetadataTopic(): string;
|
|
41
47
|
/**
|
|
42
48
|
* Returns a wildcard topic for active status messages from any process.
|
|
43
49
|
* Useful for subscriptions that must capture status from multiple processes.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mqtt-topic-builder.d.ts","sourceRoot":"","sources":["../../src/uns-mqtt/mqtt-topic-builder.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,qBAAa,gBAAgB;IACzB,OAAO,CAAC,kBAAkB,CAAS;IAEnC;;;;;OAKG;gBACS,kBAAkB,EAAE,MAAM;IAQtC;;;;OAIG;WACW,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IASrD;;;;OAIG;IACI,qBAAqB,IAAI,MAAM;IAItC;;;;OAIG;IACI,cAAc,IAAI,MAAM;IAI/B;;;;OAIG;IACI,gBAAgB,IAAI,MAAM;IAIjC;;;;;OAKG;IACI,sBAAsB,IAAI,MAAM;IAIvC;;;;;;;OAOG;WACW,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;CAO1D"}
|
|
1
|
+
{"version":3,"file":"mqtt-topic-builder.d.ts","sourceRoot":"","sources":["../../src/uns-mqtt/mqtt-topic-builder.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,qBAAa,gBAAgB;IACzB,OAAO,CAAC,kBAAkB,CAAS;IAEnC;;;;;OAKG;gBACS,kBAAkB,EAAE,MAAM;IAQtC;;;;OAIG;WACW,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IASrD;;;;OAIG;IACI,qBAAqB,IAAI,MAAM;IAItC;;;;OAIG;IACI,cAAc,IAAI,MAAM;IAI/B;;;;OAIG;IACI,gBAAgB,IAAI,MAAM;IAIjC;;;;OAIG;IACI,uBAAuB,IAAI,MAAM;IAIxC;;;;;OAKG;IACI,sBAAsB,IAAI,MAAM;IAIvC;;;;;;;OAOG;WACW,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;CAO1D"}
|
|
@@ -56,6 +56,14 @@ export class MqttTopicBuilder {
|
|
|
56
56
|
getHandoverTopic() {
|
|
57
57
|
return this.getProcessStatusTopic() + "handover";
|
|
58
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Returns the retained metadata topic for product/system service discovery.
|
|
61
|
+
*
|
|
62
|
+
* Example: "uns-infra/packageName/version/processName/service-metadata"
|
|
63
|
+
*/
|
|
64
|
+
getServiceMetadataTopic() {
|
|
65
|
+
return this.getProcessStatusTopic() + "service-metadata";
|
|
66
|
+
}
|
|
59
67
|
/**
|
|
60
68
|
* Returns a wildcard topic for active status messages from any process.
|
|
61
69
|
* Useful for subscriptions that must capture status from multiple processes.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mqtt-topic-builder.js","sourceRoot":"","sources":["../../src/uns-mqtt/mqtt-topic-builder.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IACjB,kBAAkB,CAAS;IAEnC;;;;;OAKG;IACH,YAAY,kBAA0B;QAEpC,IAAI,CAAC,oCAAoC,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC;YACnE,MAAM,IAAI,KAAK,CAAC,+FAA+F,CAAC,CAAC;QACnH,CAAC;QACD,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;IAC/C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,iBAAiB,CAAC,IAAY;QAC1C,MAAM,SAAS,GAAG,IAAI;aACnB,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC;aAChC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC;aACtB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QAE3B,OAAO,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC;IAC1D,CAAC;IAAA,CAAC;IAEF;;;;OAIG;IACI,qBAAqB;QAC1B,OAAO,IAAI,CAAC,kBAAkB,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACI,cAAc;QACnB,OAAO,IAAI,CAAC,qBAAqB,EAAE,GAAG,QAAQ,CAAC;IACjD,CAAC;IAED;;;;OAIG;IACI,gBAAgB;QACrB,OAAO,IAAI,CAAC,qBAAqB,EAAE,GAAG,UAAU,CAAC;IACnD,CAAC;IAED;;;;;OAKG;IACI,sBAAsB;QAC3B,OAAO,IAAI,CAAC,qBAAqB,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC;IACvF,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,gBAAgB,CAAC,SAAiB;QAC9C,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,oFAAoF,CAAC,CAAC;QACxG,CAAC;QACD,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;IAC3C,CAAC;CACF","sourcesContent":["/**\n * MqttTopicBuilder is a utility class responsible for generating MQTT topics\n * based on a standardized pattern using the package name, version, and process name.\n *\n * This centralizes all MQTT topic definitions so that changes to topic structures\n * only need to be made in one place.\n */\nexport class MqttTopicBuilder {\n private processStatusTopic: string;\n\n /**\n * Constructor for MqttTopicBuilder.\n * It validates the provided process status topic and initializes the instance.\n * @param processStatusTopic The base topic for the process status.\n * Example: \"uns-infra/packageName/version/processName/\"\n */\n constructor(processStatusTopic: string) {\n \n if (!/^uns-infra\\/[^/]+\\/[^/]+\\/[^/]+\\/$/.test(processStatusTopic)) {\n throw new Error(\"processStatusTopic must follow the pattern 'uns-infra/<packageName>/<version>/<processName>/'\");\n }\n this.processStatusTopic = processStatusTopic;\n }\n\n /**\n * Sanitize topic\n * @param name \n * @returns \n */\n public static sanitizeTopicPart(name: string): string {\n const sanitized = name\n .replace(/[^a-zA-Z0-9_-]+/g, \"-\")\n .replace(/-{2,}/g, \"-\")\n .replace(/^-+|-+$/g, \"\");\n\n return sanitized.length > 0 ? sanitized : \"uns-process\";\n }; \n \n /**\n * Returns the process status topic.\n *\n * Example: \"uns-infra/packageName/version/processName\"\n */\n public getProcessStatusTopic(): string {\n return this.processStatusTopic;\n }\n \n /**\n * Returns the topic used for publishing the active state.\n *\n * Example: \"uns-infra/packageName/version/processName/active\"\n */\n public getActiveTopic(): string {\n return this.getProcessStatusTopic() + \"active\";\n }\n \n /**\n * Returns the topic used for handover requests.\n *\n * Example: \"uns-infra/packageName/version/processName/handover\"\n */\n public getHandoverTopic(): string {\n return this.getProcessStatusTopic() + \"handover\";\n }\n \n /**\n * Returns a wildcard topic for active status messages from any process.\n * Useful for subscriptions that must capture status from multiple processes.\n *\n * Example: \"uns-infra/packageName/+/+/active\"\n */\n public getWildcardActiveTopic(): string {\n return this.getProcessStatusTopic().split('/').slice(0, 2).join('/') + '/+/+/active';\n }\n\n /**\n * Extract base topic from a full topic string.\n * This is useful for creating a topic builder from an existing topic.\n * @param fullTopic The full topic string.\n * Example: \"uns-infra/packageName/version/processName/active\"\n * @returns The base topic string.\n * Example: \"uns-infra/packageName/version/processName/\"\n */\n public static extractBaseTopic(fullTopic: string): string {\n const parts = fullTopic.split('/');\n if (parts.length < 4) {\n throw new Error(\"Invalid topic format. Expected 'uns-infra/<packageName>/<version>/<processName>/'.\");\n }\n return parts.slice(0, 4).join('/') + '/';\n }\n }\n
|
|
1
|
+
{"version":3,"file":"mqtt-topic-builder.js","sourceRoot":"","sources":["../../src/uns-mqtt/mqtt-topic-builder.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IACjB,kBAAkB,CAAS;IAEnC;;;;;OAKG;IACH,YAAY,kBAA0B;QAEpC,IAAI,CAAC,oCAAoC,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC;YACnE,MAAM,IAAI,KAAK,CAAC,+FAA+F,CAAC,CAAC;QACnH,CAAC;QACD,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;IAC/C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,iBAAiB,CAAC,IAAY;QAC1C,MAAM,SAAS,GAAG,IAAI;aACnB,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC;aAChC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC;aACtB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QAE3B,OAAO,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC;IAC1D,CAAC;IAAA,CAAC;IAEF;;;;OAIG;IACI,qBAAqB;QAC1B,OAAO,IAAI,CAAC,kBAAkB,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACI,cAAc;QACnB,OAAO,IAAI,CAAC,qBAAqB,EAAE,GAAG,QAAQ,CAAC;IACjD,CAAC;IAED;;;;OAIG;IACI,gBAAgB;QACrB,OAAO,IAAI,CAAC,qBAAqB,EAAE,GAAG,UAAU,CAAC;IACnD,CAAC;IAED;;;;OAIG;IACI,uBAAuB;QAC5B,OAAO,IAAI,CAAC,qBAAqB,EAAE,GAAG,kBAAkB,CAAC;IAC3D,CAAC;IAED;;;;;OAKG;IACI,sBAAsB;QAC3B,OAAO,IAAI,CAAC,qBAAqB,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC;IACvF,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,gBAAgB,CAAC,SAAiB;QAC9C,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,oFAAoF,CAAC,CAAC;QACxG,CAAC;QACD,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;IAC3C,CAAC;CACF","sourcesContent":["/**\n * MqttTopicBuilder is a utility class responsible for generating MQTT topics\n * based on a standardized pattern using the package name, version, and process name.\n *\n * This centralizes all MQTT topic definitions so that changes to topic structures\n * only need to be made in one place.\n */\nexport class MqttTopicBuilder {\n private processStatusTopic: string;\n\n /**\n * Constructor for MqttTopicBuilder.\n * It validates the provided process status topic and initializes the instance.\n * @param processStatusTopic The base topic for the process status.\n * Example: \"uns-infra/packageName/version/processName/\"\n */\n constructor(processStatusTopic: string) {\n \n if (!/^uns-infra\\/[^/]+\\/[^/]+\\/[^/]+\\/$/.test(processStatusTopic)) {\n throw new Error(\"processStatusTopic must follow the pattern 'uns-infra/<packageName>/<version>/<processName>/'\");\n }\n this.processStatusTopic = processStatusTopic;\n }\n\n /**\n * Sanitize topic\n * @param name \n * @returns \n */\n public static sanitizeTopicPart(name: string): string {\n const sanitized = name\n .replace(/[^a-zA-Z0-9_-]+/g, \"-\")\n .replace(/-{2,}/g, \"-\")\n .replace(/^-+|-+$/g, \"\");\n\n return sanitized.length > 0 ? sanitized : \"uns-process\";\n }; \n \n /**\n * Returns the process status topic.\n *\n * Example: \"uns-infra/packageName/version/processName\"\n */\n public getProcessStatusTopic(): string {\n return this.processStatusTopic;\n }\n \n /**\n * Returns the topic used for publishing the active state.\n *\n * Example: \"uns-infra/packageName/version/processName/active\"\n */\n public getActiveTopic(): string {\n return this.getProcessStatusTopic() + \"active\";\n }\n \n /**\n * Returns the topic used for handover requests.\n *\n * Example: \"uns-infra/packageName/version/processName/handover\"\n */\n public getHandoverTopic(): string {\n return this.getProcessStatusTopic() + \"handover\";\n }\n\n /**\n * Returns the retained metadata topic for product/system service discovery.\n *\n * Example: \"uns-infra/packageName/version/processName/service-metadata\"\n */\n public getServiceMetadataTopic(): string {\n return this.getProcessStatusTopic() + \"service-metadata\";\n }\n \n /**\n * Returns a wildcard topic for active status messages from any process.\n * Useful for subscriptions that must capture status from multiple processes.\n *\n * Example: \"uns-infra/packageName/+/+/active\"\n */\n public getWildcardActiveTopic(): string {\n return this.getProcessStatusTopic().split('/').slice(0, 2).join('/') + '/+/+/active';\n }\n\n /**\n * Extract base topic from a full topic string.\n * This is useful for creating a topic builder from an existing topic.\n * @param fullTopic The full topic string.\n * Example: \"uns-infra/packageName/version/processName/active\"\n * @returns The base topic string.\n * Example: \"uns-infra/packageName/version/processName/\"\n */\n public static extractBaseTopic(fullTopic: string): string {\n const parts = fullTopic.split('/');\n if (parts.length < 4) {\n throw new Error(\"Invalid topic format. Expected 'uns-infra/<packageName>/<version>/<processName>/'.\");\n }\n return parts.slice(0, 4).join('/') + '/';\n }\n }\n"]}
|