@uns-kit/core 1.0.5 → 1.0.9

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 (42) hide show
  1. package/README.md +18 -0
  2. package/dist/tools/generate-uns-dictionary.d.ts +3 -0
  3. package/dist/tools/generate-uns-dictionary.d.ts.map +1 -0
  4. package/dist/tools/generate-uns-dictionary.js +270 -0
  5. package/dist/tools/generate-uns-dictionary.js.map +1 -0
  6. package/dist/tools/initialize.js.map +1 -1
  7. package/dist/tools/update-tools.js.map +1 -1
  8. package/dist/uns/uns-attributes.d.ts +6 -143
  9. package/dist/uns/uns-attributes.d.ts.map +1 -1
  10. package/dist/uns/uns-attributes.js +7 -180
  11. package/dist/uns/uns-attributes.js.map +1 -1
  12. package/dist/uns/uns-dictionary.generated.d.ts +83 -0
  13. package/dist/uns/uns-dictionary.generated.d.ts.map +1 -0
  14. package/dist/uns/uns-dictionary.generated.js +160 -0
  15. package/dist/uns/uns-dictionary.generated.js.map +1 -0
  16. package/dist/uns/uns-interfaces.d.ts +10 -3
  17. package/dist/uns/uns-interfaces.d.ts.map +1 -1
  18. package/dist/uns/uns-interfaces.js.map +1 -1
  19. package/dist/uns/uns-object.d.ts +14 -38
  20. package/dist/uns/uns-object.d.ts.map +1 -1
  21. package/dist/uns/uns-object.js +4 -61
  22. package/dist/uns/uns-object.js.map +1 -1
  23. package/dist/uns/uns-proxy.d.ts +3 -1
  24. package/dist/uns/uns-proxy.d.ts.map +1 -1
  25. package/dist/uns/uns-proxy.js +10 -5
  26. package/dist/uns/uns-proxy.js.map +1 -1
  27. package/dist/uns-grpc/uns-gateway-server.js +1 -1
  28. package/dist/uns-grpc/uns-gateway-server.js.map +1 -1
  29. package/dist/uns-mqtt/uns-mqtt-proxy.d.ts.map +1 -1
  30. package/dist/uns-mqtt/uns-mqtt-proxy.js +5 -2
  31. package/dist/uns-mqtt/uns-mqtt-proxy.js.map +1 -1
  32. package/package.json +1 -1
  33. package/dist/app-config.d.ts.map +0 -1
  34. package/dist/app-config.js.map +0 -1
  35. package/dist/tools/initialize.d.ts +0 -2
  36. package/dist/tools/initialize.js +0 -104
  37. package/dist/tools/make.d.ts +0 -2
  38. package/dist/tools/make.js +0 -28
  39. package/dist/tools/update-rtt.d.ts +0 -2
  40. package/dist/tools/update-rtt.js +0 -170
  41. package/dist/tools/update-tools.d.ts +0 -2
  42. package/dist/tools/update-tools.js +0 -73
package/README.md CHANGED
@@ -40,6 +40,24 @@ pnpm run refresh-uns
40
40
 
41
41
  When configured via `uns-kit configure-codegen`, this script lives in your project `package.json` and writes into `src/uns/`.
42
42
 
43
+ ### Generate UNS dictionary (object types & attributes with descriptions)
44
+
45
+ Use `packages/uns-core/src/tools/generate-uns-dictionary.ts` to turn a JSON dictionary into a TypeScript helper (with optional GraphQL overlay). Defaults:
46
+
47
+ ```bash
48
+ pnpm tsx packages/uns-core/src/tools/generate-uns-dictionary.ts \
49
+ --input uns-dictionary.json \ # base JSON (optional; skipped if missing)
50
+ --output src/uns/uns-dictionary.generated.ts \
51
+ --from-graphql \ # optional: fetch overlay from GraphQL
52
+ --lang sl \ # pick language code from descriptions
53
+ --priority overlay \ # overlay wins when it has a description
54
+ --write-merged-json --json-out uns-dictionary.merged.json # optional: persist merged view
55
+ ```
56
+
57
+ - Reads base JSON if present; overlays GraphQL results on top (additive, per-key override).
58
+ - Logs any additions/overrides; JSON stays untouched unless `--write-merged-json` is passed.
59
+ - The generated TS file exports constants, description maps, and helper getters for IntelliSense and metadata emission.
60
+
43
61
  ### Infisical secret resolution in development
44
62
 
45
63
  - The resolver looks for `SecretResolverOptions.infisical.fetchSecret`, then `INFISICAL_TOKEN`/`INFISICAL_PERSONAL_TOKEN`, then `/run/secrets/infisical_token` (or `/var/lib/uns/secrets/infisical_token`).
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=generate-uns-dictionary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-uns-dictionary.d.ts","sourceRoot":"","sources":["../../src/tools/generate-uns-dictionary.ts"],"names":[],"mappings":""}
@@ -0,0 +1,270 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Generate a TypeScript dictionary of object types and attributes (with descriptions)
4
+ * from a JSON file or by fetching from GraphQL. The output is meant for IntelliSense
5
+ * and metadata enrichment (e.g., emitting descriptions alongside topics).
6
+ *
7
+ * JSON shape (example):
8
+ * {
9
+ * "objectTypes": {
10
+ * "energy-resource": { "description": "Energy carriers (electricity/steam/gas)" },
11
+ * "custom-type": { "description": "Tenant-specific thing" }
12
+ * },
13
+ * "attributes": {
14
+ * "cumulative-active-energy-delivered": { "description": "kWh total" },
15
+ * "status": { "description": "Generic status" }
16
+ * }
17
+ * }
18
+ */
19
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
20
+ import path from "node:path";
21
+ import { GraphQLClient, ClientError, gql } from "graphql-request";
22
+ import { ConfigFile } from "../config-file.js";
23
+ import { AuthClient } from "./auth/index.js";
24
+ const DEFAULT_INPUT = "uns-dictionary.json";
25
+ const DEFAULT_OUTPUT = path.resolve(process.cwd(), "src/uns/uns-dictionary.generated.ts");
26
+ const DEFAULT_JSON_OUT = path.resolve(process.cwd(), DEFAULT_INPUT);
27
+ async function main() {
28
+ const args = parseArgs(process.argv.slice(2));
29
+ const baseDictionary = await readDictionaryIfExists(args.input);
30
+ const overlayDictionary = args.fromGraphql
31
+ ? await fetchDictionaryFromGraphql(args.queryFile)
32
+ : {};
33
+ const { merged, differences } = mergeDictionaries(baseDictionary, overlayDictionary, args.priority, args.lang);
34
+ if (differences.length) {
35
+ console.log("Overlay changes applied:");
36
+ for (const diff of differences) {
37
+ console.log(` [${diff.section}] ${diff.key}: "${diff.from ?? ""}" -> "${diff.to ?? ""}"`);
38
+ }
39
+ }
40
+ else {
41
+ console.log("No overlay changes applied.");
42
+ }
43
+ // Persist the merged JSON only when explicitly requested.
44
+ if (args.writeMergedJson) {
45
+ await writeJson(merged, args.jsonOut);
46
+ }
47
+ await writeDictionaryTs(merged, args.output, args.lang);
48
+ console.log(`Generated dictionary -> ${args.output}`);
49
+ }
50
+ function parseArgs(argv) {
51
+ let input = DEFAULT_INPUT;
52
+ let output = DEFAULT_OUTPUT;
53
+ let jsonOut = DEFAULT_JSON_OUT;
54
+ let fromGraphql = false;
55
+ let queryFile;
56
+ let writeMergedJson = false;
57
+ let priority = "overlay";
58
+ let lang = "sl";
59
+ for (let i = 0; i < argv.length; i++) {
60
+ const arg = argv[i];
61
+ if (arg === "--input" && argv[i + 1]) {
62
+ input = argv[++i];
63
+ continue;
64
+ }
65
+ if (arg === "--output" && argv[i + 1]) {
66
+ output = argv[++i];
67
+ continue;
68
+ }
69
+ if (arg === "--json-out" && argv[i + 1]) {
70
+ jsonOut = argv[++i];
71
+ continue;
72
+ }
73
+ if (arg === "--write-merged-json") {
74
+ writeMergedJson = true;
75
+ continue;
76
+ }
77
+ if (arg === "--from-graphql") {
78
+ fromGraphql = true;
79
+ continue;
80
+ }
81
+ if (arg === "--query-file" && argv[i + 1]) {
82
+ queryFile = argv[++i];
83
+ continue;
84
+ }
85
+ if (arg === "--priority" && argv[i + 1]) {
86
+ const val = argv[++i];
87
+ if (val !== "overlay" && val !== "base") {
88
+ throw new Error(`Invalid priority "${val}". Use "overlay" or "base".`);
89
+ }
90
+ priority = val;
91
+ continue;
92
+ }
93
+ if (arg === "--lang" && argv[i + 1]) {
94
+ lang = argv[++i];
95
+ continue;
96
+ }
97
+ if (arg === "--help" || arg === "-h") {
98
+ printHelp();
99
+ process.exit(0);
100
+ }
101
+ throw new Error(`Unknown argument: ${arg}`);
102
+ }
103
+ return { input, output, jsonOut, fromGraphql, queryFile, writeMergedJson, priority, lang };
104
+ }
105
+ function printHelp() {
106
+ console.log(`Usage: tsx packages/uns-core/src/tools/generate-uns-dictionary.ts [options]
107
+
108
+ Options:
109
+ --input <file> Path to uns-dictionary.json (default: ${DEFAULT_INPUT})
110
+ --output <file> Path to generated TS file (default: src/uns/uns-dictionary.generated.ts)
111
+ --json-out <file> Where to write merged JSON (default: ${DEFAULT_JSON_OUT})
112
+ --write-merged-json Persist the merged JSON (otherwise JSON is left untouched)
113
+ --from-graphql Fetch dictionary from GraphQL instead of reading local JSON
114
+ --query-file <file> Optional .graphql/.gql file to override the default query
115
+ --priority <p> Merge priority: "overlay" (default) or "base" (keep base descriptions)
116
+ --lang <code> Preferred description language code (default: "sl")
117
+ --help, -h Show this help
118
+ `);
119
+ }
120
+ async function readDictionaryFromJson(filePath) {
121
+ const absolute = path.resolve(process.cwd(), filePath);
122
+ const raw = await readFile(absolute, "utf8");
123
+ return JSON.parse(raw);
124
+ }
125
+ async function readDictionaryIfExists(filePath) {
126
+ try {
127
+ return await readDictionaryFromJson(filePath);
128
+ }
129
+ catch (error) {
130
+ if (error?.code === "ENOENT") {
131
+ return {};
132
+ }
133
+ throw error;
134
+ }
135
+ }
136
+ async function fetchDictionaryFromGraphql(queryFile) {
137
+ const config = await ConfigFile.loadConfig();
138
+ const auth = await AuthClient.create();
139
+ let accessToken = await auth.getAccessToken();
140
+ const client = new GraphQLClient(config.uns.graphql, {
141
+ headers: { Authorization: `Bearer ${accessToken}` },
142
+ });
143
+ const querySource = queryFile
144
+ ? await readFile(path.resolve(process.cwd(), queryFile), "utf8")
145
+ : DEFAULT_DICTIONARY_QUERY;
146
+ const document = gql `${querySource}`;
147
+ async function requestWithAuth(documentToRun) {
148
+ try {
149
+ return await client.request(documentToRun);
150
+ }
151
+ catch (err) {
152
+ const isAuthErr = err instanceof ClientError && (err.response.status === 401 || err.response.status === 403);
153
+ if (isAuthErr) {
154
+ accessToken = await auth.getAccessToken();
155
+ client.setHeader("Authorization", `Bearer ${accessToken}`);
156
+ return await client.request(documentToRun);
157
+ }
158
+ throw err;
159
+ }
160
+ }
161
+ const data = await requestWithAuth(document);
162
+ const objectTypeArray = data?.GetObjectTypes ??
163
+ data?.objectTypes ??
164
+ data?.unsDictionary?.objectTypes ??
165
+ [];
166
+ const attributeArray = data?.GetAttributes ??
167
+ data?.attributes ??
168
+ data?.unsDictionary?.attributes ??
169
+ [];
170
+ const objectTypes = {};
171
+ for (const item of objectTypeArray) {
172
+ if (item?.name) {
173
+ objectTypes[item.name] = { description: item.description ?? undefined };
174
+ }
175
+ }
176
+ const attributes = {};
177
+ for (const item of attributeArray) {
178
+ if (item?.name) {
179
+ attributes[item.name] = { description: item.description ?? undefined };
180
+ }
181
+ }
182
+ return { objectTypes, attributes };
183
+ }
184
+ async function writeJson(dictionary, filePath) {
185
+ const absolute = path.resolve(process.cwd(), filePath);
186
+ await mkdir(path.dirname(absolute), { recursive: true });
187
+ await writeFile(absolute, JSON.stringify(dictionary, null, 2) + "\n", "utf8");
188
+ console.log(`Wrote dictionary JSON -> ${absolute}`);
189
+ }
190
+ const resolveDescription = (entry, lang) => {
191
+ if (!entry)
192
+ return undefined;
193
+ const byLang = entry.descriptions?.[lang];
194
+ if (byLang && byLang.length > 0)
195
+ return byLang;
196
+ if (entry.description && entry.description.length > 0)
197
+ return entry.description;
198
+ return undefined;
199
+ };
200
+ function mergeDictionaries(base, overlay, priority, lang) {
201
+ const differences = [];
202
+ const mergeSection = (baseSection = {}, overlaySection = {}, section) => {
203
+ const result = { ...baseSection };
204
+ for (const [key, value] of Object.entries(overlaySection)) {
205
+ const baseEntry = result[key];
206
+ const mergedEntry = {
207
+ ...(baseEntry ?? {}),
208
+ descriptions: { ...(baseEntry?.descriptions ?? {}), ...(value.descriptions ?? {}) },
209
+ };
210
+ if (value.description !== undefined) {
211
+ mergedEntry.description = value.description ?? undefined;
212
+ }
213
+ if (!baseEntry) {
214
+ result[key] = mergedEntry;
215
+ const toDesc = resolveDescription(mergedEntry, lang) ?? "";
216
+ differences.push({ section, key, from: undefined, to: toDesc });
217
+ continue;
218
+ }
219
+ const baseDesc = resolveDescription(baseEntry, lang);
220
+ const overlayDesc = resolveDescription(value, lang);
221
+ const shouldOverride = priority === "overlay" && overlayDesc && overlayDesc.length > 0;
222
+ if (shouldOverride && overlayDesc !== baseDesc) {
223
+ differences.push({ section, key, from: baseDesc ?? "", to: overlayDesc });
224
+ // mergedEntry already contains overlay descriptions; resolved value will pick it up.
225
+ }
226
+ result[key] = mergedEntry;
227
+ }
228
+ return result;
229
+ };
230
+ const merged = {
231
+ objectTypes: mergeSection(base.objectTypes, overlay.objectTypes, "objectTypes"),
232
+ attributes: mergeSection(base.attributes, overlay.attributes, "attributes"),
233
+ };
234
+ return { merged, differences };
235
+ }
236
+ async function writeDictionaryTs(dictionary, filePath, lang) {
237
+ const objectTypeEntries = Object.entries(dictionary.objectTypes ?? {});
238
+ const attributeEntries = Object.entries(dictionary.attributes ?? {});
239
+ const renderRecord = (entries) => entries
240
+ .map(([name]) => ` "${name}": "${name}",`)
241
+ .join("\n");
242
+ const renderDescriptions = (entries) => entries
243
+ .map(([name, value]) => ` "${name}": ${JSON.stringify(resolveDescription(value, lang) ?? "")},`)
244
+ .join("\n");
245
+ const objectTypeConst = `export const GeneratedObjectTypes = {\n${renderRecord(objectTypeEntries)}\n} as const;`;
246
+ const objectTypeDescConst = `export const GeneratedObjectTypeDescriptions: Record<keyof typeof GeneratedObjectTypes, string> = {\n${renderDescriptions(objectTypeEntries)}\n};`;
247
+ const attributeConst = `export const GeneratedAttributes = {\n${renderRecord(attributeEntries)}\n} as const;`;
248
+ const attributeDescConst = `export const GeneratedAttributeDescriptions: Record<keyof typeof GeneratedAttributes, string> = {\n${renderDescriptions(attributeEntries)}\n};`;
249
+ const content = `/* Auto-generated by generate-uns-dictionary.ts. Do not edit by hand. */\n${objectTypeConst}\n\n${objectTypeDescConst}\n\nexport type GeneratedObjectTypeName = keyof typeof GeneratedObjectTypes;\n\nexport function getGeneratedObjectTypeDescription(name: string): string | undefined {\n return (GeneratedObjectTypeDescriptions as Record<string, string | undefined>)[name];\n}\n\n${attributeConst}\n\n${attributeDescConst}\n\nexport type GeneratedAttributeName = keyof typeof GeneratedAttributes;\n\nexport function getGeneratedAttributeDescription(name: string): string | undefined {\n return (GeneratedAttributeDescriptions as Record<string, string | undefined>)[name];\n}\n`;
250
+ const absolute = path.resolve(process.cwd(), filePath);
251
+ await mkdir(path.dirname(absolute), { recursive: true });
252
+ await writeFile(absolute, content, "utf8");
253
+ }
254
+ const DEFAULT_DICTIONARY_QUERY = /* GraphQL */ `
255
+ query GetUnsDictionary {
256
+ GetObjectTypes {
257
+ name
258
+ description
259
+ }
260
+ GetAttributes {
261
+ name
262
+ description
263
+ }
264
+ }
265
+ `;
266
+ main().catch((error) => {
267
+ console.error("Failed to generate UNS dictionary:", error);
268
+ process.exitCode = 1;
269
+ });
270
+ //# sourceMappingURL=generate-uns-dictionary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-uns-dictionary.js","sourceRoot":"","sources":["../../src/tools/generate-uns-dictionary.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAsB7C,MAAM,aAAa,GAAG,qBAAqB,CAAC;AAC5C,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,qCAAqC,CAAC,CAAC;AAC1F,MAAM,gBAAgB,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,CAAC,CAAC;AAEpE,KAAK,UAAU,IAAI;IACjB,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAE9C,MAAM,cAAc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M,OAAO,GAAG,6EAA6E,eAAe,OAAO,mBAAmB,wQAAwQ,cAAc,OAAO,kBAAkB,iQAAiQ,CAAC;IAEvrB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;IACvD,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,MAAM,SAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,wBAAwB,GAAG,aAAa,CAAC;;;;;;;;;;;CAW9C,CAAC;AAEF,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;IAC3D,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n/**\n * Generate a TypeScript dictionary of object types and attributes (with descriptions)\n * from a JSON file or by fetching from GraphQL. The output is meant for IntelliSense\n * and metadata enrichment (e.g., emitting descriptions alongside topics).\n *\n * JSON shape (example):\n * {\n * \"objectTypes\": {\n * \"energy-resource\": { \"description\": \"Energy carriers (electricity/steam/gas)\" },\n * \"custom-type\": { \"description\": \"Tenant-specific thing\" }\n * },\n * \"attributes\": {\n * \"cumulative-active-energy-delivered\": { \"description\": \"kWh total\" },\n * \"status\": { \"description\": \"Generic status\" }\n * }\n * }\n */\nimport { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { GraphQLClient, ClientError, gql } from \"graphql-request\";\nimport { ConfigFile } from \"../config-file.js\";\nimport { AuthClient } from \"./auth/index.js\";\n\ntype DictionaryEntry = {\n description?: string | null;\n descriptions?: Record<string, string | null | undefined>;\n};\ntype UnsDictionary = {\n objectTypes?: Record<string, DictionaryEntry>;\n attributes?: Record<string, DictionaryEntry>;\n};\n\ntype CliArgs = {\n input: string;\n output: string;\n jsonOut: string;\n fromGraphql: boolean;\n queryFile?: string;\n writeMergedJson: boolean;\n priority: \"overlay\" | \"base\";\n lang: string;\n};\n\nconst DEFAULT_INPUT = \"uns-dictionary.json\";\nconst DEFAULT_OUTPUT = path.resolve(process.cwd(), \"src/uns/uns-dictionary.generated.ts\");\nconst DEFAULT_JSON_OUT = path.resolve(process.cwd(), DEFAULT_INPUT);\n\nasync function main(): Promise<void> {\n const args = parseArgs(process.argv.slice(2));\n\n const baseDictionary = await readDictionaryIfExists(args.input);\n const overlayDictionary = args.fromGraphql\n ? await fetchDictionaryFromGraphql(args.queryFile)\n : {};\n\n const { merged, differences } = mergeDictionaries(baseDictionary, overlayDictionary, args.priority, args.lang);\n\n if (differences.length) {\n console.log(\"Overlay changes applied:\");\n for (const diff of differences) {\n console.log(` [${diff.section}] ${diff.key}: \"${diff.from ?? \"\"}\" -> \"${diff.to ?? \"\"}\"`);\n }\n } else {\n console.log(\"No overlay changes applied.\");\n }\n\n // Persist the merged JSON only when explicitly requested.\n if (args.writeMergedJson) {\n await writeJson(merged, args.jsonOut);\n }\n\n await writeDictionaryTs(merged, args.output, args.lang);\n console.log(`Generated dictionary -> ${args.output}`);\n}\n\nfunction parseArgs(argv: string[]): CliArgs {\n let input = DEFAULT_INPUT;\n let output = DEFAULT_OUTPUT;\n let jsonOut = DEFAULT_JSON_OUT;\n let fromGraphql = false;\n let queryFile: string | undefined;\n let writeMergedJson = false;\n let priority: \"overlay\" | \"base\" = \"overlay\";\n let lang = \"sl\";\n\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n if (arg === \"--input\" && argv[i + 1]) {\n input = argv[++i];\n continue;\n }\n if (arg === \"--output\" && argv[i + 1]) {\n output = argv[++i];\n continue;\n }\n if (arg === \"--json-out\" && argv[i + 1]) {\n jsonOut = argv[++i];\n continue;\n }\n if (arg === \"--write-merged-json\") {\n writeMergedJson = true;\n continue;\n }\n if (arg === \"--from-graphql\") {\n fromGraphql = true;\n continue;\n }\n if (arg === \"--query-file\" && argv[i + 1]) {\n queryFile = argv[++i];\n continue;\n }\n if (arg === \"--priority\" && argv[i + 1]) {\n const val = argv[++i];\n if (val !== \"overlay\" && val !== \"base\") {\n throw new Error(`Invalid priority \"${val}\". Use \"overlay\" or \"base\".`);\n }\n priority = val;\n continue;\n }\n if (arg === \"--lang\" && argv[i + 1]) {\n lang = argv[++i];\n continue;\n }\n if (arg === \"--help\" || arg === \"-h\") {\n printHelp();\n process.exit(0);\n }\n throw new Error(`Unknown argument: ${arg}`);\n }\n\n return { input, output, jsonOut, fromGraphql, queryFile, writeMergedJson, priority, lang };\n}\n\nfunction printHelp(): void {\n console.log(`Usage: tsx packages/uns-core/src/tools/generate-uns-dictionary.ts [options]\n\nOptions:\n --input <file> Path to uns-dictionary.json (default: ${DEFAULT_INPUT})\n --output <file> Path to generated TS file (default: src/uns/uns-dictionary.generated.ts)\n --json-out <file> Where to write merged JSON (default: ${DEFAULT_JSON_OUT})\n --write-merged-json Persist the merged JSON (otherwise JSON is left untouched)\n --from-graphql Fetch dictionary from GraphQL instead of reading local JSON\n --query-file <file> Optional .graphql/.gql file to override the default query\n --priority <p> Merge priority: \"overlay\" (default) or \"base\" (keep base descriptions)\n --lang <code> Preferred description language code (default: \"sl\")\n --help, -h Show this help\n`);\n}\n\nasync function readDictionaryFromJson(filePath: string): Promise<UnsDictionary> {\n const absolute = path.resolve(process.cwd(), filePath);\n const raw = await readFile(absolute, \"utf8\");\n return JSON.parse(raw) as UnsDictionary;\n}\n\nasync function readDictionaryIfExists(filePath: string): Promise<UnsDictionary> {\n try {\n return await readDictionaryFromJson(filePath);\n } catch (error: any) {\n if (error?.code === \"ENOENT\") {\n return {};\n }\n throw error;\n }\n}\n\nasync function fetchDictionaryFromGraphql(queryFile?: string): Promise<UnsDictionary> {\n const config = await ConfigFile.loadConfig();\n const auth = await AuthClient.create();\n let accessToken = await auth.getAccessToken();\n\n const client = new GraphQLClient(config.uns.graphql, {\n headers: { Authorization: `Bearer ${accessToken}` },\n });\n\n const querySource = queryFile\n ? await readFile(path.resolve(process.cwd(), queryFile), \"utf8\")\n : DEFAULT_DICTIONARY_QUERY;\n\n const document = gql`${querySource}`;\n\n async function requestWithAuth<T>(documentToRun: any): Promise<T> {\n try {\n return await client.request<T>(documentToRun);\n } catch (err: any) {\n const isAuthErr = err instanceof ClientError && (err.response.status === 401 || err.response.status === 403);\n if (isAuthErr) {\n accessToken = await auth.getAccessToken();\n client.setHeader(\"Authorization\", `Bearer ${accessToken}`);\n return await client.request<T>(documentToRun);\n }\n throw err;\n }\n }\n\n const data: any = await requestWithAuth(document);\n\n const objectTypeArray =\n data?.GetObjectTypes ??\n data?.objectTypes ??\n data?.unsDictionary?.objectTypes ??\n [];\n\n const attributeArray =\n data?.GetAttributes ??\n data?.attributes ??\n data?.unsDictionary?.attributes ??\n [];\n\n const objectTypes: Record<string, DictionaryEntry> = {};\n for (const item of objectTypeArray) {\n if (item?.name) {\n objectTypes[item.name] = { description: item.description ?? undefined };\n }\n }\n\n const attributes: Record<string, DictionaryEntry> = {};\n for (const item of attributeArray) {\n if (item?.name) {\n attributes[item.name] = { description: item.description ?? undefined };\n }\n }\n\n return { objectTypes, attributes };\n}\n\nasync function writeJson(dictionary: UnsDictionary, filePath: string): Promise<void> {\n const absolute = path.resolve(process.cwd(), filePath);\n await mkdir(path.dirname(absolute), { recursive: true });\n await writeFile(absolute, JSON.stringify(dictionary, null, 2) + \"\\n\", \"utf8\");\n console.log(`Wrote dictionary JSON -> ${absolute}`);\n}\n\ntype Diff = { section: \"objectTypes\" | \"attributes\"; key: string; from?: string; to?: string };\n\nconst resolveDescription = (entry: DictionaryEntry | undefined, lang: string): string | undefined => {\n if (!entry) return undefined;\n const byLang = entry.descriptions?.[lang];\n if (byLang && byLang.length > 0) return byLang;\n if (entry.description && entry.description.length > 0) return entry.description;\n return undefined;\n};\n\nfunction mergeDictionaries(base: UnsDictionary, overlay: UnsDictionary, priority: \"overlay\" | \"base\", lang: string): { merged: UnsDictionary; differences: Diff[] } {\n const differences: Diff[] = [];\n\n const mergeSection = (\n baseSection: Record<string, DictionaryEntry> = {},\n overlaySection: Record<string, DictionaryEntry> = {},\n section: Diff[\"section\"],\n ) => {\n const result: Record<string, DictionaryEntry> = { ...baseSection };\n for (const [key, value] of Object.entries(overlaySection)) {\n const baseEntry = result[key];\n const mergedEntry: DictionaryEntry = {\n ...(baseEntry ?? {}),\n descriptions: { ...(baseEntry?.descriptions ?? {}), ...(value.descriptions ?? {}) },\n };\n\n if (value.description !== undefined) {\n mergedEntry.description = value.description ?? undefined;\n }\n\n if (!baseEntry) {\n result[key] = mergedEntry;\n const toDesc = resolveDescription(mergedEntry, lang) ?? \"\";\n differences.push({ section, key, from: undefined, to: toDesc });\n continue;\n }\n\n const baseDesc = resolveDescription(baseEntry, lang);\n const overlayDesc = resolveDescription(value, lang);\n const shouldOverride = priority === \"overlay\" && overlayDesc && overlayDesc.length > 0;\n\n if (shouldOverride && overlayDesc !== baseDesc) {\n differences.push({ section, key, from: baseDesc ?? \"\", to: overlayDesc });\n // mergedEntry already contains overlay descriptions; resolved value will pick it up.\n }\n\n result[key] = mergedEntry;\n }\n return result;\n };\n\n const merged = {\n objectTypes: mergeSection(base.objectTypes, overlay.objectTypes, \"objectTypes\"),\n attributes: mergeSection(base.attributes, overlay.attributes, \"attributes\"),\n };\n\n return { merged, differences };\n}\n\nasync function writeDictionaryTs(dictionary: UnsDictionary, filePath: string, lang: string): Promise<void> {\n const objectTypeEntries = Object.entries(dictionary.objectTypes ?? {});\n const attributeEntries = Object.entries(dictionary.attributes ?? {});\n\n const renderRecord = (entries: [string, DictionaryEntry][]) =>\n entries\n .map(([name]) => ` \"${name}\": \"${name}\",`)\n .join(\"\\n\");\n\n const renderDescriptions = (entries: [string, DictionaryEntry][]) =>\n entries\n .map(([name, value]) => ` \"${name}\": ${JSON.stringify(resolveDescription(value, lang) ?? \"\")},`)\n .join(\"\\n\");\n\n const objectTypeConst = `export const GeneratedObjectTypes = {\\n${renderRecord(objectTypeEntries)}\\n} as const;`;\n const objectTypeDescConst = `export const GeneratedObjectTypeDescriptions: Record<keyof typeof GeneratedObjectTypes, string> = {\\n${renderDescriptions(objectTypeEntries)}\\n};`;\n\n const attributeConst = `export const GeneratedAttributes = {\\n${renderRecord(attributeEntries)}\\n} as const;`;\n const attributeDescConst = `export const GeneratedAttributeDescriptions: Record<keyof typeof GeneratedAttributes, string> = {\\n${renderDescriptions(attributeEntries)}\\n};`;\n\n const content = `/* Auto-generated by generate-uns-dictionary.ts. Do not edit by hand. */\\n${objectTypeConst}\\n\\n${objectTypeDescConst}\\n\\nexport type GeneratedObjectTypeName = keyof typeof GeneratedObjectTypes;\\n\\nexport function getGeneratedObjectTypeDescription(name: string): string | undefined {\\n return (GeneratedObjectTypeDescriptions as Record<string, string | undefined>)[name];\\n}\\n\\n${attributeConst}\\n\\n${attributeDescConst}\\n\\nexport type GeneratedAttributeName = keyof typeof GeneratedAttributes;\\n\\nexport function getGeneratedAttributeDescription(name: string): string | undefined {\\n return (GeneratedAttributeDescriptions as Record<string, string | undefined>)[name];\\n}\\n`;\n\n const absolute = path.resolve(process.cwd(), filePath);\n await mkdir(path.dirname(absolute), { recursive: true });\n await writeFile(absolute, content, \"utf8\");\n}\n\nconst DEFAULT_DICTIONARY_QUERY = /* GraphQL */ `\n query GetUnsDictionary {\n GetObjectTypes {\n name\n description\n }\n GetAttributes {\n name\n description\n }\n }\n`;\n\nmain().catch((error) => {\n console.error(\"Failed to generate UNS dictionary:\", error);\n process.exitCode = 1;\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../src/tools/initialize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAG/C,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,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AI,CAAC,QAAQ,EAAC,aAAa,CAAC,CAAC,CAAC;YAC/F,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;QAC3C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC;QAC9C,CAAC;QAED,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,KAAK,CAAC,IAAI,CACd,kCAAkC,QAAQ,8CAA8C,OAAO,GAAG,CACnG,CACF,CAAC;IACJ,CAAC;AACH,CAAC;AAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,mBAAmB,QAAQ,IAAI,CAAC,CAAC,CAAC;AAE/D,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;AACrC,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;IACjC,EAAE,CAAC,KAAK,EAAE,CAAC;IACX,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;IACzD,KAAK,GAAG,MAAM,CAAC;IACf,GAAG,EAAE,CAAC;AACR,CAAC;KAAM,CAAC;IACN,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;IACrD,EAAE,CAAC,QAAQ,CACT,oGAAoG,EACpG,CAAC,QAAQ,EAAE,EAAE;QACX,EAAE,CAAC,KAAK,EAAE,CAAC;QACX,KAAK,GAAG,QAAQ,CAAC;QACjB,GAAG,EAAE,CAAC;IACR,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import * as azdev from \"azure-devops-node-api\";\nimport * as ga from \"azure-devops-node-api/GitApi\";\nimport { GitRepository } from \"azure-devops-node-api/interfaces/TfvcInterfaces\";\nimport chalk from \"chalk\";\nimport { readFile } from \"fs/promises\";\nimport readline from \"node:readline\";\nimport * as path from \"path\";\nimport { CleanOptions, SimpleGit, simpleGit } from \"simple-git\";\nimport fs from \"fs-extra\";\nimport { basePath } from \"./base-path.js\";\n\n\nconst git: SimpleGit = simpleGit(\"./\").clean(CleanOptions.FORCE);\n\nexport const packageJsonPath = path.join(basePath, \"package.json\");\nconst orgUrl = \"https://sijit@dev.azure.com/sijit\";\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet token: string = \"\";\nconst packageJson = JSON.parse(await readFile(packageJsonPath, \"utf8\"));\nconst repoName: string = packageJson.name;\n\nasync function run() {\n let repos: GitRepository[];\n let gitApi: ga.IGitApi;\n const project = \"industry40\";\n try {\n const authHandler = azdev.getPersonalAccessTokenHandler(token);\n const connection = new azdev.WebApi(orgUrl, authHandler);\n gitApi = await connection.getGitApi();\n repos = await gitApi.getRepositories(project); \n } catch (error) {\n console.error(\"Your AZURE_PAT environment variable has probably expired.\");\n console.log(\"Please update your AZURE_PAT environment with a new one on.\");\n console.log(\"You can create a new one at[https://dev.azure.com/sijit/_usersSettings/tokens]\");\n }\n\n if (repos.filter((x) => x.name == repoName).length > 0) {\n console.log(\n chalk.red.bold(\n `Error: Repository ${repoName} in project ${project} already exists.`,\n ),\n );\n } else {\n process.stdout.write(`Create ${repoName} in project ${project}`);\n try {\n await gitApi.createRepository({ name: repoName }, project);\n console.log(chalk.green.bold(` ... OK`));\n } catch (error) {\n console.error(chalk.red.bold(`\\n${error}`));\n }\n\n process.stdout.write(`Initialize local git repository on branch master`);\n try {\n await git.init();\n await git.checkoutLocalBranch(\"master\");\n await git.add(\".\");\n await git.commit(\"Initial commit\");\n console.log(chalk.green.bold(` ... OK`));\n } catch (error) {\n console.error(chalk.red.bold(`\\n${error}`));\n }\n\n process.stdout.write(`Add remote origin.`);\n try {\n await git.remote([\n \"add\",\n \"origin\",\n `git@ssh.dev.azure.com:v3/sijit/industry40/${repoName}`,\n ]);\n console.log(chalk.green.bold(` ... OK`));\n } catch (error) {\n console.error(chalk.red.bold(`\\n${error}`));\n }\n\n process.stdout.write(`Push master to remote`);\n try {\n await git.push(\"origin\", \"master\");\n console.log(chalk.green.bold(` ... OK`));\n } catch (error) {\n console.error(chalk.red.bold(`\\n${error}`));\n }\n\n process.stdout.write(`Create default config.json from config-template.json`);\n try {\n fs.copyFileSync(path.join(basePath,'config-template.json'), path.join(basePath,'config.json'));\n console.log(chalk.green.bold(` ... OK`));\n } catch (error) {\n console.error(chalk.red.bold(`\\n${error}`));\n }\n\n console.log(\n chalk.green.bold(\n `\\nNow you can add pipeline for ${repoName} in Azure DevOps pipelines for the project ${project}.`,\n ),\n );\n }\n}\n\nconsole.log(chalk.green.bold(`Create new RTT: ${repoName}\\n`));\n\nconst envPat = process.env.AZURE_PAT;\nif (envPat && envPat.length > 10) {\n rl.close();\n console.log(\"Using PAT from your AZURE_PAT environment\");\n token = envPat;\n run();\n} else {\n console.log(\"Could not find AZURE_PAT environment.\");\n rl.question(\n `Please enter your PAT, you can create one at [https://dev.azure.com/sijit/_usersSettings/tokens]: `,\n (newToken) => {\n rl.close();\n token = newToken;\n run();\n },\n ); \n}\n"]}
1
+ {"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../src/tools/initialize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAG/C,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAa,SAAS,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C,MAAM,GAAG,GAAc,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,C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K,CAAC,IAAI,CACd,kCAAkC,QAAQ,8CAA8C,OAAO,GAAG,CACnG,CACF,CAAC;IACJ,CAAC;AACH,CAAC;AAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,mBAAmB,QAAQ,IAAI,CAAC,CAAC,CAAC;AAE/D,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;AACrC,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;IACjC,EAAE,CAAC,KAAK,EAAE,CAAC;IACX,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;IACzD,KAAK,GAAG,MAAM,CAAC;IACf,GAAG,EAAE,CAAC;AACR,CAAC;KAAM,CAAC;IACN,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;IACrD,EAAE,CAAC,QAAQ,CACT,0GAA0G,EAC1G,CAAC,QAAQ,EAAE,EAAE;QACX,EAAE,CAAC,KAAK,EAAE,CAAC;QACX,KAAK,GAAG,QAAQ,CAAC;QACjB,GAAG,EAAE,CAAC;IACR,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import * as azdev from \"azure-devops-node-api\";\nimport * as ga from \"azure-devops-node-api/GitApi\";\nimport { GitRepository } from \"azure-devops-node-api/interfaces/TfvcInterfaces\";\nimport chalk from \"chalk\";\nimport { readFile } from \"fs/promises\";\nimport readline from \"node:readline\";\nimport * as path from \"path\";\nimport { CleanOptions, SimpleGit, simpleGit } from \"simple-git\";\nimport fs from \"fs-extra\";\nimport { basePath } from \"./base-path.js\";\n\n\nconst git: SimpleGit = simpleGit(\"./\").clean(CleanOptions.FORCE);\n\nexport const packageJsonPath = path.join(basePath, \"package.json\");\nconst orgUrl = \"https://example-org@dev.azure.com/example-org\";\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet token: string = \"\";\nconst packageJson = JSON.parse(await readFile(packageJsonPath, \"utf8\"));\nconst repoName: string = packageJson.name;\n\nasync function run() {\n let repos: GitRepository[];\n let gitApi: ga.IGitApi;\n const project = \"example-project\";\n try {\n const authHandler = azdev.getPersonalAccessTokenHandler(token);\n const connection = new azdev.WebApi(orgUrl, authHandler);\n gitApi = await connection.getGitApi();\n repos = await gitApi.getRepositories(project); \n } catch (error) {\n console.error(\"Your AZURE_PAT environment variable has probably expired.\");\n console.log(\"Please update your AZURE_PAT environment with a new one on.\");\n console.log(\"You can create a new one at[https://dev.azure.com/example-org/_usersSettings/tokens]\");\n }\n\n if (repos.filter((x) => x.name == repoName).length > 0) {\n console.log(\n chalk.red.bold(\n `Error: Repository ${repoName} in project ${project} already exists.`,\n ),\n );\n } else {\n process.stdout.write(`Create ${repoName} in project ${project}`);\n try {\n await gitApi.createRepository({ name: repoName }, project);\n console.log(chalk.green.bold(` ... OK`));\n } catch (error) {\n console.error(chalk.red.bold(`\\n${error}`));\n }\n\n process.stdout.write(`Initialize local git repository on branch master`);\n try {\n await git.init();\n await git.checkoutLocalBranch(\"master\");\n await git.add(\".\");\n await git.commit(\"Initial commit\");\n console.log(chalk.green.bold(` ... OK`));\n } catch (error) {\n console.error(chalk.red.bold(`\\n${error}`));\n }\n\n process.stdout.write(`Add remote origin.`);\n try {\n await git.remote([\n \"add\",\n \"origin\",\n `git@ssh.dev.azure.com:v3/example-org/example-project/${repoName}`,\n ]);\n console.log(chalk.green.bold(` ... OK`));\n } catch (error) {\n console.error(chalk.red.bold(`\\n${error}`));\n }\n\n process.stdout.write(`Push master to remote`);\n try {\n await git.push(\"origin\", \"master\");\n console.log(chalk.green.bold(` ... OK`));\n } catch (error) {\n console.error(chalk.red.bold(`\\n${error}`));\n }\n\n process.stdout.write(`Create default config.json from config-template.json`);\n try {\n fs.copyFileSync(path.join(basePath,'config-template.json'), path.join(basePath,'config.json'));\n console.log(chalk.green.bold(` ... OK`));\n } catch (error) {\n console.error(chalk.red.bold(`\\n${error}`));\n }\n\n console.log(\n chalk.green.bold(\n `\\nNow you can add pipeline for ${repoName} in Azure DevOps pipelines for the project ${project}.`,\n ),\n );\n }\n}\n\nconsole.log(chalk.green.bold(`Create new RTT: ${repoName}\\n`));\n\nconst envPat = process.env.AZURE_PAT;\nif (envPat && envPat.length > 10) {\n rl.close();\n console.log(\"Using PAT from your AZURE_PAT environment\");\n token = envPat;\n run();\n} else {\n console.log(\"Could not find AZURE_PAT environment.\");\n rl.question(\n `Please enter your PAT, you can create one at [https://dev.azure.com/example-org/_usersSettings/tokens]: `,\n (newToken) => {\n rl.close();\n token = newToken;\n run();\n },\n ); \n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"update-tools.js","sourceRoot":"","sources":["../../src/tools/update-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAa,SAAS,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,MAAM,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC;IAClC,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,MAAM,EAAE,OAAO,CAAC,MAAM;CACvB,CAAC,CAAC;AAEH,MAAM,GAAG,GAAc,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AAEjE,IAAI,CAAC;IACH,MAAM,IAAI,EAAE,CAAC;IACb,EAAE,CAAC,KAAK,EAAE,CAAC;AACb,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IACf,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC,CAA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,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,KAAK,EAAE,CAAC,CAAC,CAAC;QACtD,OAAO;IACT,CAAC;AACH,CAAC","sourcesContent":["import { CleanOptions, SimpleGit, simpleGit } from \"simple-git\";\nimport { basePath } from \"./base-path.js\";\nimport readline from \"node:readline\";\nimport * as path from \"path\";\nimport chalk from \"chalk\";\nimport fs from \"fs-extra\";\nimport { execSync } from \"child_process\";\n\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst git: SimpleGit = simpleGit(\"./\").clean(CleanOptions.FORCE);\n\ntry {\n await main();\n rl.close();\n} catch (error) {\n console.log(chalk.red.bold(`\\n${error}`));\n rl.close();\n}\n\nasync function main() {\n const tmpRtt = path.join(basePath, \"/tmp-rtt\");\n try {\n console.log(`Pull template-ts-nodejs into tmp-rtt`);\n await git.clone(\"git@ssh.dev.azure.com:v3/sijit/industry40/template-uns-rtt\", tmpRtt);\n } catch (error) {\n console.error(chalk.red.bold(`exec error: ${error}`)); \n return;\n }\n\n try {\n console.log(`Overwrite tools`);\n fs.copySync(path.join(tmpRtt, \"/src/tools\"), path.join(basePath, \"/src/tools\"), {overwrite: true});\n } catch (error) {\n console.error(chalk.red.bold(`exec error: ${error}`)); \n return;\n }\n\n // Update library version JSON at repo root from template\n try {\n const srcJson = path.join(tmpRtt, 'uns-library.json');\n const dstJson = path.join(basePath, 'uns-library.json');\n if (fs.existsSync(srcJson)) {\n fs.copyFileSync(srcJson, dstJson);\n const ver = JSON.parse(fs.readFileSync(srcJson, 'utf8')).version;\n console.log(`Updated uns-library.json -> ${ver}`);\n } else {\n // Fallback for older templates: synthesize from package.json\n const tmpPackageJsonPath = path.join(tmpRtt, 'package.json');\n const tmpPackageJson = JSON.parse(fs.readFileSync(tmpPackageJsonPath, 'utf8'));\n const payload = JSON.stringify({ name: tmpPackageJson.name, version: tmpPackageJson.version }, null, 2);\n fs.writeFileSync(dstJson, payload + \"\\n\", 'utf8');\n console.log(`Updated uns-library.json -> ${tmpPackageJson.version}`);\n }\n } catch (error) {\n console.error(chalk.red.bold(`exec error: ${error}`));\n return;\n }\n\n try {\n console.log(`Running update-rtt from tools`);\n // Propagate any CLI args to update-rtt (e.g., --dry-run)\n const args = process.argv.slice(2).join(\" \");\n // Run the TypeScript tool directly to avoid relying on a successful build\n execSync(`tsx ./src/tools/update-rtt.ts ${args}`.trim(), { stdio: 'inherit' });\n } catch (error) {\n console.error(chalk.red.bold(`exec error: ${error}`)); \n return; \n }\n}\n"]}
1
+ {"version":3,"file":"update-tools.js","sourceRoot":"","sources":["../../src/tools/update-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAa,SAAS,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,MAAM,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC;IAClC,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,MAAM,EAAE,OAAO,CAAC,MAAM;CACvB,CAAC,CAAC;AAEH,MAAM,GAAG,GAAc,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AAEjE,IAAI,CAAC;IACH,MAAM,IAAI,EAAE,CAAC;IACb,EAAE,CAAC,KAAK,EAAE,CAAC;AACb,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IACf,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC;IAC1C,EAAE,CAAC,KAAK,E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C,GAAG,CAAC,IAAI,CAAC,eAAe,KAAK,EAAE,CAAC,CAAC,CAAC;QACtD,OAAO;IACT,CAAC;AACH,CAAC","sourcesContent":["import { CleanOptions, SimpleGit, simpleGit } from \"simple-git\";\nimport { basePath } from \"./base-path.js\";\nimport readline from \"node:readline\";\nimport * as path from \"path\";\nimport chalk from \"chalk\";\nimport fs from \"fs-extra\";\nimport { execSync } from \"child_process\";\n\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst git: SimpleGit = simpleGit(\"./\").clean(CleanOptions.FORCE);\n\ntry {\n await main();\n rl.close();\n} catch (error) {\n console.log(chalk.red.bold(`\\n${error}`));\n rl.close();\n}\n\nasync function main() {\n const tmpRtt = path.join(basePath, \"/tmp-rtt\");\n try {\n console.log(`Pull template-ts-nodejs into tmp-rtt`);\n await git.clone(\"git@ssh.dev.azure.com:v3/example-org/example-project/template-uns-rtt\", tmpRtt);\n } catch (error) {\n console.error(chalk.red.bold(`exec error: ${error}`)); \n return;\n }\n\n try {\n console.log(`Overwrite tools`);\n fs.copySync(path.join(tmpRtt, \"/src/tools\"), path.join(basePath, \"/src/tools\"), {overwrite: true});\n } catch (error) {\n console.error(chalk.red.bold(`exec error: ${error}`)); \n return;\n }\n\n // Update library version JSON at repo root from template\n try {\n const srcJson = path.join(tmpRtt, 'uns-library.json');\n const dstJson = path.join(basePath, 'uns-library.json');\n if (fs.existsSync(srcJson)) {\n fs.copyFileSync(srcJson, dstJson);\n const ver = JSON.parse(fs.readFileSync(srcJson, 'utf8')).version;\n console.log(`Updated uns-library.json -> ${ver}`);\n } else {\n // Fallback for older templates: synthesize from package.json\n const tmpPackageJsonPath = path.join(tmpRtt, 'package.json');\n const tmpPackageJson = JSON.parse(fs.readFileSync(tmpPackageJsonPath, 'utf8'));\n const payload = JSON.stringify({ name: tmpPackageJson.name, version: tmpPackageJson.version }, null, 2);\n fs.writeFileSync(dstJson, payload + \"\\n\", 'utf8');\n console.log(`Updated uns-library.json -> ${tmpPackageJson.version}`);\n }\n } catch (error) {\n console.error(chalk.red.bold(`exec error: ${error}`));\n return;\n }\n\n try {\n console.log(`Running update-rtt from tools`);\n // Propagate any CLI args to update-rtt (e.g., --dry-run)\n const args = process.argv.slice(2).join(\" \");\n // Run the TypeScript tool directly to avoid relying on a successful build\n execSync(`tsx ./src/tools/update-rtt.ts ${args}`.trim(), { stdio: 'inherit' });\n } catch (error) {\n console.error(chalk.red.bold(`exec error: ${error}`)); \n return; \n }\n}\n"]}
@@ -1,144 +1,7 @@
1
- export declare const knownUnsAttributes: readonly ["measured-temperature", "measured-vibration", "measured-pressure", "measured-flow", "temperature", "status", "operating-hours", "fault-code", "speed", "energy-consumption", "power", "voltage", "current", "energy", "lot", "lot-id", "batch-number", "material-type", "quantity", "location", "presence", "task-id", "assigned-task", "role", "start-time", "end-time", "duration", "output-quantity", "product-code", "revision", "specification", "target-parameters", "material-composition", "version-history", "inspection-result", "deviation", "pass-fail", "surface-defect", "hardness", "tensile-strength", "work-order-id", "task-list", "planned-start", "planned-end", "assigned-to", "instruction-url", "pressure", "flow", "consumption", "alarm", "availability", "utilization", "downtime", "maintenance-status", "frequency", "cost", "total-flow", "conductivity", "ph", "level", "consumption-rate", "refill-required", "last-refill"];
2
- export type KnownUnsAttributeName = typeof knownUnsAttributes[number];
3
- export type UnsAttribute = KnownUnsAttributeName | (string & {});
4
- export declare const EquipmentAttributes: {
5
- readonly Status: "status";
6
- readonly MeasuredTemperature: "measured-temperature";
7
- readonly MeasuredVibration: "measured-vibration";
8
- readonly MeasuredPressure: "measured-pressure";
9
- readonly MeasuredFlow: "measured-flow";
10
- readonly OperatingHours: "operating-hours";
11
- readonly FaultCode: "fault-code";
12
- readonly Speed: "speed";
13
- readonly EnergyConsumption: "energy-consumption";
14
- readonly Power: "power";
15
- readonly Voltage: "voltage";
16
- readonly Current: "current";
17
- readonly Energy: "energy";
18
- };
19
- export type EquipmentAttributeName = typeof EquipmentAttributes[keyof typeof EquipmentAttributes];
20
- export declare const MaterialAttributes: {
21
- readonly Lot: "lot";
22
- readonly LotId: "lot-id";
23
- readonly BatchNumber: "batch-number";
24
- readonly MaterialType: "material-type";
25
- readonly Quantity: "quantity";
26
- readonly Location: "location";
27
- readonly Status: "status";
28
- };
29
- export type MaterialAttributeName = typeof MaterialAttributes[keyof typeof MaterialAttributes];
30
- export declare const PersonnelAttributes: {
31
- readonly Presence: "presence";
32
- readonly TaskId: "task-id";
33
- readonly AssignedTask: "assigned-task";
34
- readonly Role: "role";
35
- readonly Status: "status";
36
- };
37
- export type PersonnelAttributeName = typeof PersonnelAttributes[keyof typeof PersonnelAttributes];
38
- export declare const ProcessSegmentAttributes: {
39
- readonly StartTime: "start-time";
40
- readonly EndTime: "end-time";
41
- readonly Duration: "duration";
42
- readonly Status: "status";
43
- readonly OutputQuantity: "output-quantity";
44
- };
45
- export type ProcessSegmentAttributeName = typeof ProcessSegmentAttributes[keyof typeof ProcessSegmentAttributes];
46
- export declare const ProductDefinitionAttributes: {
47
- readonly ProductCode: "product-code";
48
- readonly Revision: "revision";
49
- readonly Specification: "specification";
50
- readonly TargetParameters: "target-parameters";
51
- readonly MaterialComposition: "material-composition";
52
- readonly VersionHistory: "version-history";
53
- };
54
- export type ProductDefinitionAttributeName = typeof ProductDefinitionAttributes[keyof typeof ProductDefinitionAttributes];
55
- export declare const ProductQualityAttributes: {
56
- readonly InspectionResult: "inspection-result";
57
- readonly Deviation: "deviation";
58
- readonly PassFail: "pass-fail";
59
- readonly SurfaceDefect: "surface-defect";
60
- readonly Hardness: "hardness";
61
- readonly TensileStrength: "tensile-strength";
62
- };
63
- export type ProductQualityAttributeName = typeof ProductQualityAttributes[keyof typeof ProductQualityAttributes];
64
- export declare const WorkDefinitionAttributes: {
65
- readonly WorkOrderId: "work-order-id";
66
- readonly TaskList: "task-list";
67
- readonly PlannedStart: "planned-start";
68
- readonly PlannedEnd: "planned-end";
69
- readonly AssignedTo: "assigned-to";
70
- readonly InstructionUrl: "instruction-url";
71
- };
72
- export type WorkDefinitionAttributeName = typeof WorkDefinitionAttributes[keyof typeof WorkDefinitionAttributes];
73
- export declare const ResourceStatusAttributes: {
74
- readonly Availability: "availability";
75
- readonly Utilization: "utilization";
76
- readonly Downtime: "downtime";
77
- readonly Status: "status";
78
- readonly MaintenanceStatus: "maintenance-status";
79
- };
80
- export type ResourceStatusAttributeName = typeof ResourceStatusAttributes[keyof typeof ResourceStatusAttributes];
81
- export declare const EnergyResourceAttributes: {
82
- readonly Power: "power";
83
- readonly Energy: "energy";
84
- readonly Voltage: "voltage";
85
- readonly Current: "current";
86
- readonly Frequency: "frequency";
87
- readonly Cost: "cost";
88
- };
89
- export type EnergyResourceAttributeName = typeof EnergyResourceAttributes[keyof typeof EnergyResourceAttributes];
90
- export declare const UtilityResourceAttributes: {
91
- readonly Pressure: "pressure";
92
- readonly Flow: "flow";
93
- readonly Consumption: "consumption";
94
- readonly Status: "status";
95
- readonly Alarm: "alarm";
96
- };
97
- export type UtilityResourceAttributeName = typeof UtilityResourceAttributes[keyof typeof UtilityResourceAttributes];
98
- export declare const FluidResourceAttributes: {
99
- readonly Flow: "flow";
100
- readonly Pressure: "pressure";
101
- readonly Temperature: "temperature";
102
- readonly TotalFlow: "total-flow";
103
- readonly Conductivity: "conductivity";
104
- readonly PH: "ph";
105
- };
106
- export type FluidResourceAttributeName = typeof FluidResourceAttributes[keyof typeof FluidResourceAttributes];
107
- export declare const ConsumableResourceAttributes: {
108
- readonly Level: "level";
109
- readonly ConsumptionRate: "consumption-rate";
110
- readonly RefillRequired: "refill-required";
111
- readonly LastRefill: "last-refill";
112
- readonly Status: "status";
113
- };
114
- export type ConsumableResourceAttributeName = typeof ConsumableResourceAttributes[keyof typeof ConsumableResourceAttributes];
115
- export declare const LineAttributes: {
116
- readonly Status: "status";
117
- };
118
- export type LineAttributeName = typeof LineAttributes[keyof typeof LineAttributes];
119
- export declare const AreaAttributes: {
120
- readonly Status: "status";
121
- };
122
- export type AreaAttributeName = typeof AreaAttributes[keyof typeof AreaAttributes];
123
- export declare const SiteAttributes: {
124
- readonly Status: "status";
125
- };
126
- export type SiteAttributeName = typeof SiteAttributes[keyof typeof SiteAttributes];
127
- export declare const EnterpriseAttributes: {
128
- readonly Status: "status";
129
- };
130
- export type EnterpriseAttributeName = typeof EnterpriseAttributes[keyof typeof EnterpriseAttributes];
131
- export declare const AssetAttributes: {
132
- readonly Status: "status";
133
- };
134
- export type AssetAttributeName = typeof AssetAttributes[keyof typeof AssetAttributes];
135
- export declare const SensorAttributes: {
136
- readonly Status: "status";
137
- readonly MeasuredTemperature: "measured-temperature";
138
- readonly MeasuredVibration: "measured-vibration";
139
- readonly MeasuredPressure: "measured-pressure";
140
- readonly MeasuredFlow: "measured-flow";
141
- readonly Temperature: "temperature";
142
- };
143
- export type SensorAttributeName = typeof SensorAttributes[keyof typeof SensorAttributes];
1
+ import { GeneratedAttributes } from "./uns-dictionary.generated.js";
2
+ export declare const knownUnsAttributes: ("status" | "temperature" | "vibration" | "operating-hours" | "fault-code" | "speed" | "energy-consumption" | "lot-id" | "batch-number" | "material-type" | "quantity" | "location" | "presence" | "task-id" | "role" | "authorization-level" | "start-time" | "end-time" | "duration" | "output-quantity" | "operator-id" | "product-code" | "revision" | "specification" | "target-parameters" | "material-composition" | "version-history" | "inspection-result" | "deviation" | "pass-fail" | "surface-defect" | "hardness" | "tensile-strength" | "work-order-id" | "task-list" | "planned-start" | "planned-end" | "assigned-to" | "instruction-url" | "availability" | "utilization" | "downtime" | "maintenance-status" | "power" | "energy" | "voltage" | "current" | "frequency" | "cost" | "pressure" | "flow" | "consumption" | "alarm" | "total-flow" | "conductivity" | "ph" | "level" | "consumption-rate" | "refill-required" | "last-refill")[];
3
+ export type KnownUnsAttributeName = typeof GeneratedAttributes[keyof typeof GeneratedAttributes];
4
+ export type UnsAttribute = "" | KnownUnsAttributeName | (string & {});
5
+ export declare const AttributeDescriptions: Record<"status" | "temperature" | "vibration" | "operating-hours" | "fault-code" | "speed" | "energy-consumption" | "lot-id" | "batch-number" | "material-type" | "quantity" | "location" | "presence" | "task-id" | "role" | "authorization-level" | "start-time" | "end-time" | "duration" | "output-quantity" | "operator-id" | "product-code" | "revision" | "specification" | "target-parameters" | "material-composition" | "version-history" | "inspection-result" | "deviation" | "pass-fail" | "surface-defect" | "hardness" | "tensile-strength" | "work-order-id" | "task-list" | "planned-start" | "planned-end" | "assigned-to" | "instruction-url" | "availability" | "utilization" | "downtime" | "maintenance-status" | "power" | "energy" | "voltage" | "current" | "frequency" | "cost" | "pressure" | "flow" | "consumption" | "alarm" | "total-flow" | "conductivity" | "ph" | "level" | "consumption-rate" | "refill-required" | "last-refill", string>;
6
+ export declare function getAttributeDescription(name: string): string | undefined;
144
7
  //# sourceMappingURL=uns-attributes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"uns-attributes.d.ts","sourceRoot":"","sources":["../../src/uns/uns-attributes.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,kBAAkB,u6BAgErB,CAAC;AAEX,MAAM,MAAM,qBAAqB,GAAG,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC;AAGtE,MAAM,MAAM,YAAY,GAAG,qBAAqB,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAGjE,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;CActB,CAAC;AACX,MAAM,MAAM,sBAAsB,GAAG,OAAO,mBAAmB,CAAC,MAAM,OAAO,mBAAmB,CAAC,CAAC;AAElG,eAAO,MAAM,kBAAkB;;;;;;;;CAQrB,CAAC;AACX,MAAM,MAAM,qBAAqB,GAAG,OAAO,kBAAkB,CAAC,MAAM,OAAO,kBAAkB,CAAC,CAAC;AAE/F,eAAO,MAAM,mBAAmB;;;;;;CAMtB,CAAC;AACX,MAAM,MAAM,sBAAsB,GAAG,OAAO,mBAAmB,CAAC,MAAM,OAAO,mBAAmB,CAAC,CAAC;AAElG,eAAO,MAAM,wBAAwB;;;;;;CAM3B,CAAC;AACX,MAAM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