@uns-kit/core 0.0.1

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 (111) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -0
  3. package/dist/app-config.d.ts +177 -0
  4. package/dist/app-config.js +1 -0
  5. package/dist/base-path.d.ts +1 -0
  6. package/dist/base-path.js +5 -0
  7. package/dist/config/project.config.extension.d.ts +3 -0
  8. package/dist/config/project.config.extension.js +3 -0
  9. package/dist/config-file.d.ts +12 -0
  10. package/dist/config-file.js +44 -0
  11. package/dist/examples/data-example.d.ts +1 -0
  12. package/dist/examples/data-example.js +44 -0
  13. package/dist/examples/load-test-data.d.ts +1 -0
  14. package/dist/examples/load-test-data.js +72 -0
  15. package/dist/examples/table-example.d.ts +4 -0
  16. package/dist/examples/table-example.js +52 -0
  17. package/dist/examples/uns-gateway.d.ts +1 -0
  18. package/dist/examples/uns-gateway.js +5 -0
  19. package/dist/graphql/schema.d.ts +377 -0
  20. package/dist/graphql/schema.js +13 -0
  21. package/dist/index.d.ts +5 -0
  22. package/dist/index.js +4 -0
  23. package/dist/logger.d.ts +2 -0
  24. package/dist/logger.js +18 -0
  25. package/dist/tools/auth/auth-client.d.ts +23 -0
  26. package/dist/tools/auth/auth-client.js +172 -0
  27. package/dist/tools/auth/index.d.ts +1 -0
  28. package/dist/tools/auth/index.js +1 -0
  29. package/dist/tools/auth/secure-store.d.ts +17 -0
  30. package/dist/tools/auth/secure-store.js +110 -0
  31. package/dist/tools/base-path.d.ts +1 -0
  32. package/dist/tools/base-path.js +5 -0
  33. package/dist/tools/generate-config-schema.d.ts +1 -0
  34. package/dist/tools/generate-config-schema.js +23 -0
  35. package/dist/tools/initialize.d.ts +1 -0
  36. package/dist/tools/initialize.js +103 -0
  37. package/dist/tools/make.d.ts +1 -0
  38. package/dist/tools/make.js +27 -0
  39. package/dist/tools/pull-request.d.ts +1 -0
  40. package/dist/tools/pull-request.js +157 -0
  41. package/dist/tools/refresh-uns.d.ts +1 -0
  42. package/dist/tools/refresh-uns.js +109 -0
  43. package/dist/tools/schema.d.ts +208 -0
  44. package/dist/tools/schema.js +1 -0
  45. package/dist/tools/update-rtt.d.ts +1 -0
  46. package/dist/tools/update-rtt.js +169 -0
  47. package/dist/tools/update-tools.d.ts +1 -0
  48. package/dist/tools/update-tools.js +72 -0
  49. package/dist/uns/handover-manager-event-emitter.d.ts +6 -0
  50. package/dist/uns/handover-manager-event-emitter.js +19 -0
  51. package/dist/uns/handover-manager.d.ts +34 -0
  52. package/dist/uns/handover-manager.js +227 -0
  53. package/dist/uns/process-config.d.ts +10 -0
  54. package/dist/uns/process-config.js +12 -0
  55. package/dist/uns/process-name-service.d.ts +7 -0
  56. package/dist/uns/process-name-service.js +28 -0
  57. package/dist/uns/status-monitor.d.ts +35 -0
  58. package/dist/uns/status-monitor.js +82 -0
  59. package/dist/uns/uns-event-emitter.d.ts +6 -0
  60. package/dist/uns/uns-event-emitter.js +19 -0
  61. package/dist/uns/uns-interfaces.d.ts +156 -0
  62. package/dist/uns/uns-interfaces.js +5 -0
  63. package/dist/uns/uns-measurements.d.ts +95 -0
  64. package/dist/uns/uns-measurements.js +146 -0
  65. package/dist/uns/uns-packet.d.ts +28 -0
  66. package/dist/uns/uns-packet.js +223 -0
  67. package/dist/uns/uns-proxy-process.d.ts +56 -0
  68. package/dist/uns/uns-proxy-process.js +179 -0
  69. package/dist/uns/uns-proxy.d.ts +31 -0
  70. package/dist/uns/uns-proxy.js +120 -0
  71. package/dist/uns/uns-tags.d.ts +1 -0
  72. package/dist/uns/uns-tags.js +1 -0
  73. package/dist/uns/uns-topic-matcher.d.ts +9 -0
  74. package/dist/uns/uns-topic-matcher.js +34 -0
  75. package/dist/uns/uns-topics.d.ts +1 -0
  76. package/dist/uns/uns-topics.js +1 -0
  77. package/dist/uns-config/config-schema.d.ts +7 -0
  78. package/dist/uns-config/config-schema.js +5 -0
  79. package/dist/uns-config/host-placeholders.d.ts +139 -0
  80. package/dist/uns-config/host-placeholders.js +70 -0
  81. package/dist/uns-config/schema-tolls.d.ts +2 -0
  82. package/dist/uns-config/schema-tolls.js +4 -0
  83. package/dist/uns-config/schema-tools.d.ts +2 -0
  84. package/dist/uns-config/schema-tools.js +18 -0
  85. package/dist/uns-config/secret-placeholders.d.ts +128 -0
  86. package/dist/uns-config/secret-placeholders.js +64 -0
  87. package/dist/uns-config/secret-resolver.d.ts +77 -0
  88. package/dist/uns-config/secret-resolver.js +285 -0
  89. package/dist/uns-config/uns-core-schema.d.ts +705 -0
  90. package/dist/uns-config/uns-core-schema.js +25 -0
  91. package/dist/uns-grpc/uns-gateway-cli.d.ts +2 -0
  92. package/dist/uns-grpc/uns-gateway-cli.js +32 -0
  93. package/dist/uns-grpc/uns-gateway-server.d.ts +47 -0
  94. package/dist/uns-grpc/uns-gateway-server.js +424 -0
  95. package/dist/uns-mqtt/mqtt-interfaces.d.ts +22 -0
  96. package/dist/uns-mqtt/mqtt-interfaces.js +1 -0
  97. package/dist/uns-mqtt/mqtt-proxy.d.ts +34 -0
  98. package/dist/uns-mqtt/mqtt-proxy.js +245 -0
  99. package/dist/uns-mqtt/mqtt-topic-builder.d.ts +51 -0
  100. package/dist/uns-mqtt/mqtt-topic-builder.js +70 -0
  101. package/dist/uns-mqtt/mqtt-worker-init.d.ts +1 -0
  102. package/dist/uns-mqtt/mqtt-worker-init.js +5 -0
  103. package/dist/uns-mqtt/mqtt-worker.d.ts +20 -0
  104. package/dist/uns-mqtt/mqtt-worker.js +120 -0
  105. package/dist/uns-mqtt/throttled-queue.d.ts +166 -0
  106. package/dist/uns-mqtt/throttled-queue.js +388 -0
  107. package/dist/uns-mqtt/uns-mqtt-proxy.d.ts +107 -0
  108. package/dist/uns-mqtt/uns-mqtt-proxy.js +349 -0
  109. package/dist/uns-mqtt/ws-proxy.d.ts +38 -0
  110. package/dist/uns-mqtt/ws-proxy.js +86 -0
  111. package/package.json +48 -0
@@ -0,0 +1,208 @@
1
+ export type Maybe<T> = T | null;
2
+ export type InputMaybe<T> = Maybe<T>;
3
+ export type Exact<T extends {
4
+ [key: string]: unknown;
5
+ }> = {
6
+ [K in keyof T]: T[K];
7
+ };
8
+ export type MakeOptional<T, K extends keyof T> = Omit<T, K> & {
9
+ [SubKey in K]?: Maybe<T[SubKey]>;
10
+ };
11
+ export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & {
12
+ [SubKey in K]: Maybe<T[SubKey]>;
13
+ };
14
+ export type MakeEmpty<T extends {
15
+ [key: string]: unknown;
16
+ }, K extends keyof T> = {
17
+ [_ in K]?: never;
18
+ };
19
+ export type Incremental<T> = T | {
20
+ [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never;
21
+ };
22
+ /** All built-in and custom scalars, mapped to their actual values */
23
+ export type Scalars = {
24
+ ID: {
25
+ input: string;
26
+ output: string;
27
+ };
28
+ String: {
29
+ input: string;
30
+ output: string;
31
+ };
32
+ Boolean: {
33
+ input: boolean;
34
+ output: boolean;
35
+ };
36
+ Int: {
37
+ input: number;
38
+ output: number;
39
+ };
40
+ Float: {
41
+ input: number;
42
+ output: number;
43
+ };
44
+ Date: {
45
+ input: any;
46
+ output: any;
47
+ };
48
+ };
49
+ export type ActivateMqttTranslation = {
50
+ enabled?: InputMaybe<Scalars['Boolean']['input']>;
51
+ sourceTag?: InputMaybe<Scalars['String']['input']>;
52
+ };
53
+ /** MQTT Translator object. */
54
+ export type AddMqttTranslation = {
55
+ description?: InputMaybe<Scalars['String']['input']>;
56
+ sourceTag?: InputMaybe<Scalars['String']['input']>;
57
+ sourceTopic?: InputMaybe<Scalars['String']['input']>;
58
+ targetTag?: InputMaybe<Scalars['String']['input']>;
59
+ targetTopic?: InputMaybe<Scalars['String']['input']>;
60
+ uom?: InputMaybe<Scalars['String']['input']>;
61
+ };
62
+ export type AddMqttTranslatorTopic = {
63
+ sourceTopic?: InputMaybe<Scalars['String']['input']>;
64
+ };
65
+ export type DeleteMqttTranslation = {
66
+ sourceTag?: InputMaybe<Scalars['String']['input']>;
67
+ };
68
+ export type DeleteMqttTranslatorTopic = {
69
+ sourceTopic?: InputMaybe<Scalars['String']['input']>;
70
+ };
71
+ export type InitMqttTranslation = {
72
+ sourceTag?: InputMaybe<Scalars['String']['input']>;
73
+ sourceTopic?: InputMaybe<Scalars['String']['input']>;
74
+ };
75
+ export type InsertUnsNode = {
76
+ parent?: InputMaybe<Scalars['Int']['input']>;
77
+ unsNode?: InputMaybe<Scalars['String']['input']>;
78
+ };
79
+ export type ModifyMqttTranslation = {
80
+ description?: InputMaybe<Scalars['String']['input']>;
81
+ enabled?: InputMaybe<Scalars['Boolean']['input']>;
82
+ sourceTag?: InputMaybe<Scalars['String']['input']>;
83
+ targetTag?: InputMaybe<Scalars['String']['input']>;
84
+ targetTopic?: InputMaybe<Scalars['String']['input']>;
85
+ uom?: InputMaybe<Scalars['String']['input']>;
86
+ };
87
+ /** MQTT Translator object. */
88
+ export type MqttTranslation = {
89
+ __typename?: 'MqttTranslation';
90
+ description?: Maybe<Scalars['String']['output']>;
91
+ enabled?: Maybe<Scalars['Boolean']['output']>;
92
+ sourceTag?: Maybe<Scalars['String']['output']>;
93
+ sourceTopic?: Maybe<Scalars['String']['output']>;
94
+ targetTag?: Maybe<Scalars['String']['output']>;
95
+ targetTopic?: Maybe<Scalars['String']['output']>;
96
+ uom?: Maybe<Scalars['String']['output']>;
97
+ };
98
+ export type MqttTranslatorTopic = {
99
+ __typename?: 'MqttTranslatorTopic';
100
+ sourceTopic?: Maybe<Scalars['String']['output']>;
101
+ };
102
+ export type Mutation = {
103
+ __typename?: 'Mutation';
104
+ ActivateMqttTranslation?: Maybe<Scalars['Boolean']['output']>;
105
+ AddMqttTranslation?: Maybe<Scalars['Boolean']['output']>;
106
+ /** Add MQTT topic to be translated. */
107
+ AddMqttTranslatorTopic?: Maybe<Scalars['Boolean']['output']>;
108
+ AddUnsNode?: Maybe<Scalars['Boolean']['output']>;
109
+ /** Add MQTT translation. */
110
+ DeleteMqttTranslation?: Maybe<Scalars['Boolean']['output']>;
111
+ DeleteMqttTranslatorTopic?: Maybe<Scalars['Boolean']['output']>;
112
+ DeleteRttNode?: Maybe<Scalars['Boolean']['output']>;
113
+ DeleteUnsNode?: Maybe<Scalars['Boolean']['output']>;
114
+ DeployRttNode?: Maybe<Scalars['Boolean']['output']>;
115
+ /** Populate MQTT Translator table with sourceTag and sourceTopic. */
116
+ InitMqttTranslation?: Maybe<Scalars['Boolean']['output']>;
117
+ /** Update MQTT Translator table with defined targetTopic. */
118
+ ModifyMqttTranslation?: Maybe<Scalars['Boolean']['output']>;
119
+ ModifyUnsNode?: Maybe<Scalars['Boolean']['output']>;
120
+ StartRttNode?: Maybe<Scalars['Boolean']['output']>;
121
+ StopRttNode?: Maybe<Scalars['Boolean']['output']>;
122
+ };
123
+ export type MutationActivateMqttTranslationArgs = {
124
+ entry?: InputMaybe<ActivateMqttTranslation>;
125
+ };
126
+ export type MutationAddMqttTranslationArgs = {
127
+ entry?: InputMaybe<AddMqttTranslation>;
128
+ };
129
+ export type MutationAddMqttTranslatorTopicArgs = {
130
+ entry?: InputMaybe<AddMqttTranslatorTopic>;
131
+ };
132
+ export type MutationAddUnsNodeArgs = {
133
+ node?: InputMaybe<InsertUnsNode>;
134
+ };
135
+ export type MutationDeleteMqttTranslationArgs = {
136
+ entry?: InputMaybe<DeleteMqttTranslation>;
137
+ };
138
+ export type MutationDeleteMqttTranslatorTopicArgs = {
139
+ entry?: InputMaybe<DeleteMqttTranslatorTopic>;
140
+ };
141
+ export type MutationDeleteRttNodeArgs = {
142
+ rttNode?: InputMaybe<Scalars['String']['input']>;
143
+ };
144
+ export type MutationDeleteUnsNodeArgs = {
145
+ id?: InputMaybe<Scalars['Int']['input']>;
146
+ };
147
+ export type MutationDeployRttNodeArgs = {
148
+ rttNode?: InputMaybe<Scalars['String']['input']>;
149
+ tag?: InputMaybe<Scalars['String']['input']>;
150
+ };
151
+ export type MutationInitMqttTranslationArgs = {
152
+ entry?: InputMaybe<InitMqttTranslation>;
153
+ };
154
+ export type MutationModifyMqttTranslationArgs = {
155
+ entry?: InputMaybe<ModifyMqttTranslation>;
156
+ };
157
+ export type MutationModifyUnsNodeArgs = {
158
+ id?: InputMaybe<Scalars['Int']['input']>;
159
+ node?: InputMaybe<UpdateUnsNode>;
160
+ };
161
+ export type MutationStartRttNodeArgs = {
162
+ rttNode?: InputMaybe<Scalars['String']['input']>;
163
+ };
164
+ export type MutationStopRttNodeArgs = {
165
+ rttNode?: InputMaybe<Scalars['String']['input']>;
166
+ };
167
+ /** name: uns-datahub */
168
+ export type Query = {
169
+ __typename?: 'Query';
170
+ /** Get MQTT Translator translations. */
171
+ GetMqttTranslations?: Maybe<Array<Maybe<MqttTranslation>>>;
172
+ GetMqttTranslatorTopics?: Maybe<Array<Maybe<MqttTranslatorTopic>>>;
173
+ GetRttNodes?: Maybe<Array<Maybe<RttNode>>>;
174
+ GetTreeStructure?: Maybe<Array<Maybe<TreeStructure>>>;
175
+ };
176
+ export type RttNode = {
177
+ __typename?: 'RttNode';
178
+ author?: Maybe<Scalars['String']['output']>;
179
+ deployedVersions?: Maybe<Array<Maybe<Scalars['String']['output']>>>;
180
+ description?: Maybe<Scalars['String']['output']>;
181
+ lastLog?: Maybe<Scalars['String']['output']>;
182
+ latestDeployedVersion?: Maybe<Scalars['String']['output']>;
183
+ memory?: Maybe<Scalars['Int']['output']>;
184
+ pid?: Maybe<Scalars['Int']['output']>;
185
+ restarts?: Maybe<Scalars['Int']['output']>;
186
+ rttNode?: Maybe<Scalars['String']['output']>;
187
+ runningVersion?: Maybe<Scalars['String']['output']>;
188
+ status?: Maybe<Scalars['String']['output']>;
189
+ uptime?: Maybe<Scalars['Int']['output']>;
190
+ version?: Maybe<Scalars['String']['output']>;
191
+ };
192
+ export type TreeStructure = {
193
+ __typename?: 'TreeStructure';
194
+ children?: Maybe<Array<Maybe<TreeStructure>>>;
195
+ id?: Maybe<Scalars['Int']['output']>;
196
+ parent?: Maybe<Scalars['Int']['output']>;
197
+ unsNode?: Maybe<Scalars['String']['output']>;
198
+ };
199
+ export type UnsNode = {
200
+ __typename?: 'UnsNode';
201
+ id?: Maybe<Scalars['Int']['output']>;
202
+ parent?: Maybe<Scalars['Int']['output']>;
203
+ unsNode?: Maybe<Scalars['String']['output']>;
204
+ };
205
+ export type UpdateUnsNode = {
206
+ parent?: InputMaybe<Scalars['Int']['input']>;
207
+ unsNode?: InputMaybe<Scalars['String']['input']>;
208
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,169 @@
1
+ import { basePath } from "./base-path.js";
2
+ import readline from "node:readline";
3
+ import * as path from "path";
4
+ import chalk from "chalk";
5
+ import { readFile } from "fs/promises";
6
+ import fs from "fs-extra";
7
+ import * as prettier from "prettier";
8
+ const rl = readline.createInterface({
9
+ input: process.stdin,
10
+ output: process.stdout,
11
+ });
12
+ const packageJsonPath = path.join(basePath, "package.json");
13
+ const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
14
+ // Flags
15
+ const argv = new Set(process.argv.slice(2));
16
+ const DRY_RUN = argv.has("--dry-run") || process.env.DRY_RUN === "1";
17
+ function logAction(action) {
18
+ if (DRY_RUN)
19
+ console.log(`[dry-run] ${action}`);
20
+ else
21
+ console.log(action);
22
+ }
23
+ function writeJson(file, obj) {
24
+ return prettier.format(JSON.stringify(obj), { parser: "json" }).then((s) => {
25
+ if (DRY_RUN) {
26
+ console.log(`[dry-run] write ${file} (${s.length} bytes)`);
27
+ }
28
+ else {
29
+ fs.writeFileSync(file, s, "utf8");
30
+ }
31
+ });
32
+ }
33
+ function copyDir(src, dest, options) {
34
+ if (DRY_RUN) {
35
+ console.log(`[dry-run] copy ${src} -> ${dest}`);
36
+ return;
37
+ }
38
+ fs.copySync(src, dest, { overwrite: true, ...options });
39
+ }
40
+ function removePath(p, opts) {
41
+ if (DRY_RUN) {
42
+ console.log(`[dry-run] rm ${p}`);
43
+ return;
44
+ }
45
+ fs.rmSync(p, { force: true, recursive: true, ...opts });
46
+ }
47
+ try {
48
+ await main();
49
+ rl.close();
50
+ }
51
+ catch (error) {
52
+ console.log(chalk.red.bold(`\n${error}`));
53
+ rl.close();
54
+ }
55
+ async function main() {
56
+ const tmpRtt = path.join(basePath, "/tmp-rtt");
57
+ try {
58
+ logAction(`Overwrite examples`);
59
+ copyDir(path.join(tmpRtt, "/src/examples"), path.join(basePath, "/src/examples"));
60
+ logAction(`Overwrite uns`);
61
+ copyDir(path.join(tmpRtt, "/src/uns"), path.join(basePath, "/src/uns"));
62
+ logAction(`Overwrite uns-config`);
63
+ copyDir(path.join(tmpRtt, "/src/uns-config"), path.join(basePath, "/src/uns-config"));
64
+ // Python: copy template but preserve local project area(s) and environments
65
+ // Preserved by default: python/rtt, python/venv, python/.venv, python/__pycache__
66
+ const pythonSrc = path.join(tmpRtt, "/python");
67
+ const pythonDst = path.join(basePath, "/python");
68
+ logAction(`Overwrite python (preserve local, rtt, venv/.venv, __pycache__)`);
69
+ copyDir(pythonSrc, pythonDst, {
70
+ filter: (src) => {
71
+ // Only filter relative to template python root
72
+ const rel = path.relative(pythonSrc, src);
73
+ if (!rel || rel === "")
74
+ return true;
75
+ const top = rel.split(path.sep)[0];
76
+ const preserved = new Set(["local", "rtt", "venv", ".venv", "__pycache__"]);
77
+ return !preserved.has(top);
78
+ },
79
+ });
80
+ logAction(`Overwrite uns-grpc`);
81
+ copyDir(path.join(tmpRtt, "/src/uns-grpc"), path.join(basePath, "/packages/uns-core/src/uns-grpc"));
82
+ logAction(`Overwrite uns-cron`);
83
+ copyDir(path.join(tmpRtt, "/src/uns-cron"), path.join(basePath, "/packages/uns-cron/src"));
84
+ logAction(`Overwrite uns-api`);
85
+ copyDir(path.join(tmpRtt, "/src/uns-api"), path.join(basePath, "/packages/uns-api/src"));
86
+ logAction(`Overwrite uns-mqtt`);
87
+ copyDir(path.join(tmpRtt, "/src/uns-mqtt"), path.join(basePath, "/packages/uns-core/src/uns-mqtt"));
88
+ logAction(`Overwrite uns-temporal`);
89
+ copyDir(path.join(tmpRtt, "/src/uns-temporal"), path.join(basePath, "/packages/uns-temporal/src"));
90
+ logAction(`Overwrite eslint.config.mjs`);
91
+ copyDir(path.join(tmpRtt, "/eslint.config.mjs"), path.join(basePath, "/eslint.config.mjs"));
92
+ logAction(`Overwrite schema.ts`);
93
+ copyDir(path.join(tmpRtt, "/src/graphql/schema.ts"), path.join(basePath, "/src/graphql/schema.ts"));
94
+ logAction(`Overwrite config-template.json`);
95
+ copyDir(path.join(tmpRtt, "/config-template.json"), path.join(basePath, "/config-template.json"));
96
+ logAction(`Overwrite vite.config.js`);
97
+ copyDir(path.join(tmpRtt, "/vite.config.js"), path.join(basePath, "/vite.config.js"));
98
+ logAction(`Overwrite codegen.ts`);
99
+ copyDir(path.join(tmpRtt, "/codegen.ts"), path.join(basePath, "/codegen.ts"));
100
+ logAction(`Overwrite logger.ts`);
101
+ copyDir(path.join(tmpRtt, "/src/logger.ts"), path.join(basePath, "/src/logger.ts"));
102
+ }
103
+ catch (error) {
104
+ console.error(chalk.red.bold(`exec error: ${error}`));
105
+ return;
106
+ }
107
+ try {
108
+ logAction(`Merge package.json scripts (template overrides existing keys, preserves extras)`);
109
+ const tmpPackageJson = JSON.parse(await readFile(path.join(tmpRtt, 'package.json'), "utf8"));
110
+ const currentScripts = packageJson.scripts || {};
111
+ const templateScripts = tmpPackageJson.scripts || {};
112
+ packageJson.scripts = { ...currentScripts, ...templateScripts };
113
+ await writeJson('package.json', packageJson);
114
+ }
115
+ catch (error) {
116
+ console.error(chalk.red.bold(`exec error: ${error}`));
117
+ return;
118
+ }
119
+ try {
120
+ console.log(chalk.red(`Update devDependencies: overwrite versions for existing, add missing; preserve extras.`));
121
+ const tmpPackageJson = JSON.parse(await readFile(path.join(tmpRtt, 'package.json'), "utf8"));
122
+ packageJson.devDependencies = packageJson.devDependencies || {};
123
+ for (const [dep, version] of Object.entries(tmpPackageJson.devDependencies || {})) {
124
+ packageJson.devDependencies[dep] = version;
125
+ }
126
+ await writeJson('package.json', packageJson);
127
+ }
128
+ catch (error) {
129
+ console.error(chalk.red.bold(`exec error: ${error}`));
130
+ return;
131
+ }
132
+ try {
133
+ console.log(chalk.red(`Update dependencies: keep existing versions; add missing from template.`));
134
+ const tmpPackageJson = JSON.parse(await readFile(path.join(tmpRtt, 'package.json'), "utf8"));
135
+ packageJson.dependencies = packageJson.dependencies || {};
136
+ for (const [dep, version] of Object.entries(tmpPackageJson.dependencies || {})) {
137
+ if (!(dep in packageJson.dependencies)) {
138
+ packageJson.dependencies[dep] = version;
139
+ }
140
+ }
141
+ await writeJson('package.json', packageJson);
142
+ }
143
+ catch (error) {
144
+ console.error(chalk.red.bold(`exec error: ${error}`));
145
+ return;
146
+ }
147
+ try {
148
+ logAction(`Remove obsolete directories and files`);
149
+ removePath(path.join(basePath, "/src/mqtt-rtt"));
150
+ removePath(path.join(basePath, "/src/uns-rtt"));
151
+ removePath(path.join(basePath, "/.eslintignore"));
152
+ removePath(path.join(basePath, "/.eslintrc.json"));
153
+ removePath(path.join(basePath, "/src/update-rtt.ts"));
154
+ removePath(path.join(basePath, "/src/demo"));
155
+ }
156
+ catch (error) {
157
+ console.error(chalk.red.bold(`exec error: ${error}`));
158
+ return;
159
+ }
160
+ try {
161
+ logAction(`Remove tmp-rtt`);
162
+ removePath(tmpRtt);
163
+ }
164
+ catch (error) {
165
+ console.error(chalk.red.bold(`exec error: ${error}`));
166
+ return;
167
+ }
168
+ console.log(chalk.green.bold("\nRun npm run build to rebuild the project, and remove obsolete directories and files."));
169
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,72 @@
1
+ import { CleanOptions, simpleGit } from "simple-git";
2
+ import { basePath } from "./base-path.js";
3
+ import readline from "node:readline";
4
+ import * as path from "path";
5
+ import chalk from "chalk";
6
+ import fs from "fs-extra";
7
+ import { execSync } from "child_process";
8
+ const rl = readline.createInterface({
9
+ input: process.stdin,
10
+ output: process.stdout,
11
+ });
12
+ const git = simpleGit("./").clean(CleanOptions.FORCE);
13
+ try {
14
+ await main();
15
+ rl.close();
16
+ }
17
+ catch (error) {
18
+ console.log(chalk.red.bold(`\n${error}`));
19
+ rl.close();
20
+ }
21
+ async function main() {
22
+ const tmpRtt = path.join(basePath, "/tmp-rtt");
23
+ try {
24
+ console.log(`Pull template-ts-nodejs into tmp-rtt`);
25
+ await git.clone("git@ssh.dev.azure.com:v3/sijit/industry40/template-uns-rtt", tmpRtt);
26
+ }
27
+ catch (error) {
28
+ console.error(chalk.red.bold(`exec error: ${error}`));
29
+ return;
30
+ }
31
+ try {
32
+ console.log(`Overwrite tools`);
33
+ fs.copySync(path.join(tmpRtt, "/src/tools"), path.join(basePath, "/src/tools"), { overwrite: true });
34
+ }
35
+ catch (error) {
36
+ console.error(chalk.red.bold(`exec error: ${error}`));
37
+ return;
38
+ }
39
+ // Update library version JSON at repo root from template
40
+ try {
41
+ const srcJson = path.join(tmpRtt, 'uns-library.json');
42
+ const dstJson = path.join(basePath, 'uns-library.json');
43
+ if (fs.existsSync(srcJson)) {
44
+ fs.copyFileSync(srcJson, dstJson);
45
+ const ver = JSON.parse(fs.readFileSync(srcJson, 'utf8')).version;
46
+ console.log(`Updated uns-library.json -> ${ver}`);
47
+ }
48
+ else {
49
+ // Fallback for older templates: synthesize from package.json
50
+ const tmpPackageJsonPath = path.join(tmpRtt, 'package.json');
51
+ const tmpPackageJson = JSON.parse(fs.readFileSync(tmpPackageJsonPath, 'utf8'));
52
+ const payload = JSON.stringify({ name: tmpPackageJson.name, version: tmpPackageJson.version }, null, 2);
53
+ fs.writeFileSync(dstJson, payload + "\n", 'utf8');
54
+ console.log(`Updated uns-library.json -> ${tmpPackageJson.version}`);
55
+ }
56
+ }
57
+ catch (error) {
58
+ console.error(chalk.red.bold(`exec error: ${error}`));
59
+ return;
60
+ }
61
+ try {
62
+ console.log(`Running update-rtt from tools`);
63
+ // Propagate any CLI args to update-rtt (e.g., --dry-run)
64
+ const args = process.argv.slice(2).join(" ");
65
+ // Run the TypeScript tool directly to avoid relying on a successful build
66
+ execSync(`tsx ./src/tools/update-rtt.ts ${args}`.trim(), { stdio: 'inherit' });
67
+ }
68
+ catch (error) {
69
+ console.error(chalk.red.bold(`exec error: ${error}`));
70
+ return;
71
+ }
72
+ }
@@ -0,0 +1,6 @@
1
+ export declare class HandoverManagerEventEmitter<Events extends Record<string, any>> {
2
+ private listeners;
3
+ on<K extends keyof Events>(eventName: K, listener: (event: Events[K]) => void): void;
4
+ off<K extends keyof Events>(eventName: K, listener: (event: Events[K]) => void): void;
5
+ emit<K extends keyof Events>(eventName: K, event: Events[K]): void;
6
+ }
@@ -0,0 +1,19 @@
1
+ export class HandoverManagerEventEmitter {
2
+ listeners = {};
3
+ on(eventName, listener) {
4
+ if (!this.listeners[eventName]) {
5
+ this.listeners[eventName] = [];
6
+ }
7
+ this.listeners[eventName].push(listener);
8
+ }
9
+ off(eventName, listener) {
10
+ if (!this.listeners[eventName])
11
+ return;
12
+ this.listeners[eventName] = this.listeners[eventName].filter((l) => l !== listener);
13
+ }
14
+ emit(eventName, event) {
15
+ if (!this.listeners[eventName])
16
+ return;
17
+ this.listeners[eventName].forEach((listener) => listener(event));
18
+ }
19
+ }
@@ -0,0 +1,34 @@
1
+ import { UnsEvents } from "./uns-interfaces.js";
2
+ import { HandoverManagerEventEmitter } from "./handover-manager-event-emitter.js";
3
+ import { HandoverManagerEvents } from "../uns-mqtt/mqtt-interfaces.js";
4
+ import MqttProxy from "../uns-mqtt/mqtt-proxy.js";
5
+ import UnsMqttProxy from "../uns-mqtt/uns-mqtt-proxy.js";
6
+ /**
7
+ * HandoverManager is responsible for all handover-related logic,
8
+ * including handling incoming MQTT messages, issuing handover requests,
9
+ * and processing handover responses.
10
+ */
11
+ export declare class HandoverManager {
12
+ event: HandoverManagerEventEmitter<HandoverManagerEvents>;
13
+ private processName;
14
+ private mqttProxy;
15
+ private unsMqttProxies;
16
+ private requestingHandover;
17
+ private handoverInProgress;
18
+ private topicBuilder;
19
+ private activeTimeout;
20
+ private active;
21
+ handoverRequestEnabled: boolean;
22
+ handoverEnabled: boolean;
23
+ forceStartEnabled: boolean;
24
+ constructor(processName: string, mqttProxy: MqttProxy, unsMqttProxies: UnsMqttProxy[], handoverRequestEnabled: boolean, handoverEnabled: boolean, forceStartEnabled: boolean);
25
+ /**
26
+ * Main entry point for handling incoming MQTT messages.
27
+ * It checks the topic and delegates to the corresponding handler.
28
+ */
29
+ handleMqttMessage(event: UnsEvents["input"]): Promise<void>;
30
+ /**
31
+ * Handles handovers.
32
+ */
33
+ private handleHandover;
34
+ }