@uns-kit/core 2.0.40 → 2.0.42
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/README.md +38 -15
- package/dist/base-path.js.map +1 -1
- package/dist/config/project.config.extension.js.map +1 -1
- package/dist/config-file.js.map +1 -1
- package/dist/graphql/schema.js.map +1 -1
- 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/logger.js.map +1 -1
- package/dist/tools/auth/auth-client.js.map +1 -1
- package/dist/tools/auth/index.js.map +1 -1
- package/dist/tools/auth/secure-store.js.map +1 -1
- package/dist/tools/base-path.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/file-utils.js.map +1 -1
- package/dist/tools/generate-config-schema.js.map +1 -1
- package/dist/tools/generate-uns-dictionary.d.ts +23 -23
- package/dist/tools/generate-uns-dictionary.js +147 -147
- package/dist/tools/generate-uns-dictionary.js.map +1 -1
- package/dist/tools/generate-uns-measurements.d.ts +21 -21
- package/dist/tools/generate-uns-measurements.js +119 -119
- package/dist/tools/generate-uns-measurements.js.map +1 -1
- package/dist/tools/generate-uns-reference.d.ts +2 -2
- package/dist/tools/generate-uns-reference.js +76 -76
- package/dist/tools/generate-uns-reference.js.map +1 -1
- package/dist/tools/pull-request.js.map +1 -1
- package/dist/tools/refresh-uns.js.map +1 -1
- package/dist/tools/schema.js.map +1 -1
- package/dist/tools/sync-uns-schema.d.ts +2 -2
- package/dist/tools/sync-uns-schema.js +472 -472
- package/dist/tools/sync-uns-schema.js.map +1 -1
- package/dist/uns/handover-manager-event-emitter.js.map +1 -1
- package/dist/uns/handover-manager.js.map +1 -1
- package/dist/uns/process-config.js.map +1 -1
- 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/status-monitor.js.map +1 -1
- package/dist/uns/uns-asset.d.ts +1 -1
- package/dist/uns/uns-asset.js +1 -1
- package/dist/uns/uns-asset.js.map +1 -1
- package/dist/uns/uns-attributes.d.ts +6 -6
- package/dist/uns/uns-attributes.js +9 -9
- package/dist/uns/uns-attributes.js.map +1 -1
- package/dist/uns/uns-dictionary-registry.d.ts +4 -4
- package/dist/uns/uns-dictionary-registry.js +20 -20
- package/dist/uns/uns-dictionary-registry.js.map +1 -1
- package/dist/uns/uns-dictionary.generated.d.ts +663 -663
- package/dist/uns/uns-dictionary.generated.js +745 -745
- package/dist/uns/uns-dictionary.generated.js.map +1 -1
- package/dist/uns/uns-event-emitter.js.map +1 -1
- package/dist/uns/uns-interfaces.d.ts +365 -365
- package/dist/uns/uns-interfaces.js.map +1 -1
- package/dist/uns/uns-measurements.generated.d.ts +362 -362
- package/dist/uns/uns-measurements.generated.js +359 -359
- package/dist/uns/uns-measurements.generated.js.map +1 -1
- package/dist/uns/uns-measurements.js.map +1 -1
- package/dist/uns/uns-object.d.ts +20 -20
- package/dist/uns/uns-object.js +9 -9
- package/dist/uns/uns-object.js.map +1 -1
- package/dist/uns/uns-packet.js +263 -263
- package/dist/uns/uns-packet.js.map +1 -1
- package/dist/uns/uns-path.d.ts +2 -2
- package/dist/uns/uns-path.js +10 -10
- package/dist/uns/uns-path.js.map +1 -1
- 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/uns-proxy.js.map +1 -1
- package/dist/uns/uns-tags.js.map +1 -1
- package/dist/uns/uns-topic-matcher.js.map +1 -1
- package/dist/uns/uns-topics.js.map +1 -1
- package/dist/uns-config/config-schema.js.map +1 -1
- package/dist/uns-config/host-placeholders.js.map +1 -1
- package/dist/uns-config/schema-tolls.js.map +1 -1
- package/dist/uns-config/schema-tools.js.map +1 -1
- package/dist/uns-config/secret-placeholders.js.map +1 -1
- package/dist/uns-config/secret-resolver.js.map +1 -1
- package/dist/uns-config/uns-core-schema.d.ts +3276 -3276
- package/dist/uns-config/uns-core-schema.js.map +1 -1
- package/dist/uns-grpc/uns-gateway-cli.js.map +1 -1
- package/dist/uns-grpc/uns-gateway-server.js.map +1 -1
- package/dist/uns-mqtt/mqtt-interfaces.js.map +1 -1
- package/dist/uns-mqtt/mqtt-proxy.js.map +1 -1
- 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/mqtt-worker-init.js.map +1 -1
- package/dist/uns-mqtt/mqtt-worker.js.map +1 -1
- package/dist/uns-mqtt/throttled-queue.js.map +1 -1
- package/dist/uns-mqtt/uns-mqtt-proxy.js +477 -477
- package/dist/uns-mqtt/uns-mqtt-proxy.js.map +1 -1
- package/dist/uns-mqtt/ws-proxy.js.map +1 -1
- package/package.json +1 -1
package/dist/tools/file-utils.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
export async function readTextFileIfExists(filePath) {
|
|
4
|
-
const absolutePath = path.resolve(process.cwd(), filePath);
|
|
5
|
-
try {
|
|
6
|
-
return await readFile(absolutePath, "utf8");
|
|
7
|
-
}
|
|
8
|
-
catch (error) {
|
|
9
|
-
if (error.code === "ENOENT") {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
throw error;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export async function writeTextFileIfChanged(filePath, content) {
|
|
16
|
-
const absolutePath = path.resolve(process.cwd(), filePath);
|
|
17
|
-
const current = await readTextFileIfExists(absolutePath);
|
|
18
|
-
if (current === content) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
await mkdir(path.dirname(absolutePath), { recursive: true });
|
|
22
|
-
await writeFile(absolutePath, content, "utf8");
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
1
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
export async function readTextFileIfExists(filePath) {
|
|
4
|
+
const absolutePath = path.resolve(process.cwd(), filePath);
|
|
5
|
+
try {
|
|
6
|
+
return await readFile(absolutePath, "utf8");
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
if (error.code === "ENOENT") {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export async function writeTextFileIfChanged(filePath, content) {
|
|
16
|
+
const absolutePath = path.resolve(process.cwd(), filePath);
|
|
17
|
+
const current = await readTextFileIfExists(absolutePath);
|
|
18
|
+
if (current === content) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
await mkdir(path.dirname(absolutePath), { recursive: true });
|
|
22
|
+
await writeFile(absolutePath, content, "utf8");
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
25
|
//# sourceMappingURL=file-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-utils.js","sourceRoot":"","sources":["../../src/tools/file-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,QAAgB;IACzD,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;IAE3D,IAAI,CAAC;QACH,OAAO,MAAM,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACvD,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,QAAgB,EAAE,OAAe;IAC5E,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC3D,MAAM,OAAO,GAAG,MAAM,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAEzD,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;QACxB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7D,MAAM,SAAS,CAAC,YAAY,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC/C,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\n\nexport async function readTextFileIfExists(filePath: string): Promise<string | undefined> {\n const absolutePath = path.resolve(process.cwd(), filePath);\n\n try {\n return await readFile(absolutePath, \"utf8\");\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\n return undefined;\n }\n throw error;\n }\n}\n\nexport async function writeTextFileIfChanged(filePath: string, content: string): Promise<boolean> {\n const absolutePath = path.resolve(process.cwd(), filePath);\n const current = await readTextFileIfExists(absolutePath);\n\n if (current === content) {\n return false;\n }\n\n await mkdir(path.dirname(absolutePath), { recursive: true });\n await writeFile(absolutePath, content, \"utf8\");\n return true;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"file-utils.js","sourceRoot":"","sources":["../../src/tools/file-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,QAAgB;IACzD,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;IAE3D,IAAI,CAAC;QACH,OAAO,MAAM,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACvD,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,QAAgB,EAAE,OAAe;IAC5E,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC3D,MAAM,OAAO,GAAG,MAAM,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAEzD,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;QACxB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7D,MAAM,SAAS,CAAC,YAAY,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC/C,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { mkdir, readFile, writeFile } from \"node:fs/promises\";\r\nimport path from \"node:path\";\r\n\r\nexport async function readTextFileIfExists(filePath: string): Promise<string | undefined> {\r\n const absolutePath = path.resolve(process.cwd(), filePath);\r\n\r\n try {\r\n return await readFile(absolutePath, \"utf8\");\r\n } catch (error) {\r\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\r\n return undefined;\r\n }\r\n throw error;\r\n }\r\n}\r\n\r\nexport async function writeTextFileIfChanged(filePath: string, content: string): Promise<boolean> {\r\n const absolutePath = path.resolve(process.cwd(), filePath);\r\n const current = await readTextFileIfExists(absolutePath);\r\n\r\n if (current === content) {\r\n return false;\r\n }\r\n\r\n await mkdir(path.dirname(absolutePath), { recursive: true });\r\n await writeFile(absolutePath, content, \"utf8\");\r\n return true;\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-config-schema.js","sourceRoot":"","sources":["../../src/tools/generate-config-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAG5D,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAEpE,SAAS,KAAK,CAAC,QAAgB,EAAE,IAAY;IAC3C,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AACnC,CAAC;AAED,IAAI,aAAa,GAAG,KAAK,CAAC;AAE1B,KAAK,U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AAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AAEtC,IAAI,aAAa,GAAG,IAAI,CAAC;AACzB,IAAI,CAAC;IACH,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;IAChE,IAAI,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;QAC7D,IAAI,GAAG,EAAE,IAAI,KAAK,eAAe,EAAE,CAAC;YAClC,aAAa,GAAG,KAAK,CAAC;QACxB,CAAC;IACH,CAAC;AACH,CAAC;AAAC,MAAM,CAAC;IACP,aAAa,GAAG,IAAI,CAAC;AACvB,CAAC;AAED,MAAM,iBAAiB,GAAG,aAAa;IACrC,CAAC,CAAC,oRAAoR;IACtR,CAAC,CAAC,IAAI,CAAC;AAET,MAAM,SAAS,GAAG,iFAAiF,aAAa,6DAA6D,iBAAiB,EAAE,CAAC;AAEjM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,4BAA4B,CAAC,EAAE,SAAS,CAAC,CAAC;AAE7D,OAAO,CAAC,GAAG,CAAC,mEAAmE,CAAC,CAAC","sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { zodToJsonSchema } from \"zod-to-json-schema\";\nimport { zodToTs, printNode, withGetType } from \"zod-to-ts\";\nimport { z } from \"zod\";\n\nimport { hostValueSchema } from \"../uns-config/host-placeholders.js\";\nimport { secretValueSchema } from \"../uns-config/secret-placeholders.js\";\nimport { composeConfigSchema } from \"../uns-config/schema-tools.js\";\n\nfunction write(filePath: string, data: string) {\n fs.mkdirSync(path.dirname(filePath), { recursive: true });\n fs.writeFileSync(filePath, data);\n}\n\nlet tsLoaderReady = false;\n\nasync function ensureTsLoader(): Promise<void> {\n if (tsLoaderReady) {\n return;\n }\n tsLoaderReady = true;\n try {\n await import(\"tsx/esm\");\n } catch (error) {\n throw new Error(\n \"Unable to load TypeScript project.config.extension. Install 'tsx' (e.g. pnpm add -D tsx) or provide a compiled JavaScript file.\",\n );\n }\n}\n\nasync function loadProjectExtrasSchema(): Promise<z.AnyZodObject> {\n const base = path.resolve(process.cwd(), \"src/config/project.config.extension\");\n const extensions = [\"\", \".ts\", \".mts\", \".tsx\", \".js\", \".mjs\", \".cjs\"];\n\n for (const ext of extensions) {\n const candidate = ext ? `${base}${ext}` : base;\n if (!fs.existsSync(candidate)) {\n continue;\n }\n\n const lowerExt = path.extname(candidate).toLowerCase();\n try {\n if (lowerExt === \".ts\" || lowerExt === \".mts\" || lowerExt === \".tsx\") {\n await ensureTsLoader();\n }\n\n const module = await import(pathToFileURL(candidate).href);\n if (module?.projectExtrasSchema) {\n return module.projectExtrasSchema as z.AnyZodObject;\n }\n\n throw new Error(`Module '${candidate}' does not export projectExtrasSchema.`);\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n throw new Error(`Failed to load project config extension at '${candidate}': ${reason}`);\n }\n }\n\n const coreModule = await import(\"../config/project.config.extension.js\");\n return coreModule.projectExtrasSchema as z.AnyZodObject;\n}\n\n// Keep placeholder-backed values as plain strings in the generated TypeScript typings so\n// consuming code reflects the resolved shapes while the JSON schema still exposes full unions.\nconst renderAsString = (typescript: any) =>\n typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.StringKeyword);\n\nfor (const schema of [hostValueSchema, secretValueSchema]) {\n withGetType(schema, renderAsString);\n}\n\nconst { unsCoreSchema } = await import(\"../uns-config/uns-core-schema.js\");\nconst projectExtrasSchema = await loadProjectExtrasSchema();\nconst baseSchema = composeConfigSchema(unsCoreSchema, projectExtrasSchema).strict();\n\n// 1) JSON Schema for VS Code $schema\nconst jsonSchema = zodToJsonSchema(baseSchema, \"AppConfig\");\nwrite(path.resolve(\"config.schema.json\"), JSON.stringify(jsonSchema, null, 2));\n\n// 2) TypeScript `export type AppConfig = {...}`\nconst { node } = zodToTs(baseSchema, \"AppConfig\");\nconst interfaceBody = printNode(node);\n\nlet shouldAugment = true;\ntry {\n const pkgJsonPath = path.resolve(process.cwd(), \"package.json\");\n if (fs.existsSync(pkgJsonPath)) {\n const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, \"utf8\"));\n if (pkg?.name === \"@uns-kit/core\") {\n shouldAugment = false;\n }\n }\n} catch {\n shouldAugment = true;\n}\n\nconst augmentationBlock = shouldAugment\n ? `\\n\\ntype GeneratedProjectAppConfig = ProjectAppConfig;\\ntype GeneratedAppConfig = AppConfig;\\n\\ndeclare module \"@uns-kit/core/config/app-config.js\" {\\n interface ProjectAppConfig extends GeneratedProjectAppConfig {}\\n interface AppConfig extends GeneratedAppConfig {}\\n}\\n`\n : \"\\n\";\n\nconst tsContent = `/* Auto-generated. Do not edit by hand. */\\nexport interface ProjectAppConfig ${interfaceBody}\\n\\nexport interface AppConfig extends ProjectAppConfig {}${augmentationBlock}`;\n\nwrite(path.resolve(\"./src/config/app-config.ts\"), tsContent);\n\nconsole.log(\"Generated config.schema.json and updated src/config/app-config.ts\");\n"]}
|
|
1
|
+
{"version":3,"file":"generate-config-schema.js","sourceRoot":"","sources":["../../src/tools/generate-config-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAG5D,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;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GAAG,eAAe,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AAC5D,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAE/E,gDAAgD;AAChD,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AAClD,MAAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AAEtC,IAAI,aAAa,GAAG,IAAI,CAAC;AACzB,IAAI,CAAC;IACH,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;IAChE,IAAI,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;QAC7D,IAAI,GAAG,EAAE,IAAI,KAAK,eAAe,EAAE,CAAC;YAClC,aAAa,GAAG,KAAK,CAAC;QACxB,CAAC;IACH,CAAC;AACH,CAAC;AAAC,MAAM,CAAC;IACP,aAAa,GAAG,IAAI,CAAC;AACvB,CAAC;AAED,MAAM,iBAAiB,GAAG,aAAa;IACrC,CAAC,CAAC,oRAAoR;IACtR,CAAC,CAAC,IAAI,CAAC;AAET,MAAM,SAAS,GAAG,iFAAiF,aAAa,6DAA6D,iBAAiB,EAAE,CAAC;AAEjM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,4BAA4B,CAAC,EAAE,SAAS,CAAC,CAAC;AAE7D,OAAO,CAAC,GAAG,CAAC,mEAAmE,CAAC,CAAC","sourcesContent":["import fs from \"node:fs\";\r\nimport path from \"node:path\";\r\nimport { pathToFileURL } from \"node:url\";\r\nimport { zodToJsonSchema } from \"zod-to-json-schema\";\r\nimport { zodToTs, printNode, withGetType } from \"zod-to-ts\";\r\nimport { z } from \"zod\";\r\n\r\nimport { hostValueSchema } from \"../uns-config/host-placeholders.js\";\r\nimport { secretValueSchema } from \"../uns-config/secret-placeholders.js\";\r\nimport { composeConfigSchema } from \"../uns-config/schema-tools.js\";\r\n\r\nfunction write(filePath: string, data: string) {\r\n fs.mkdirSync(path.dirname(filePath), { recursive: true });\r\n fs.writeFileSync(filePath, data);\r\n}\r\n\r\nlet tsLoaderReady = false;\r\n\r\nasync function ensureTsLoader(): Promise<void> {\r\n if (tsLoaderReady) {\r\n return;\r\n }\r\n tsLoaderReady = true;\r\n try {\r\n await import(\"tsx/esm\");\r\n } catch (error) {\r\n throw new Error(\r\n \"Unable to load TypeScript project.config.extension. Install 'tsx' (e.g. pnpm add -D tsx) or provide a compiled JavaScript file.\",\r\n );\r\n }\r\n}\r\n\r\nasync function loadProjectExtrasSchema(): Promise<z.AnyZodObject> {\r\n const base = path.resolve(process.cwd(), \"src/config/project.config.extension\");\r\n const extensions = [\"\", \".ts\", \".mts\", \".tsx\", \".js\", \".mjs\", \".cjs\"];\r\n\r\n for (const ext of extensions) {\r\n const candidate = ext ? `${base}${ext}` : base;\r\n if (!fs.existsSync(candidate)) {\r\n continue;\r\n }\r\n\r\n const lowerExt = path.extname(candidate).toLowerCase();\r\n try {\r\n if (lowerExt === \".ts\" || lowerExt === \".mts\" || lowerExt === \".tsx\") {\r\n await ensureTsLoader();\r\n }\r\n\r\n const module = await import(pathToFileURL(candidate).href);\r\n if (module?.projectExtrasSchema) {\r\n return module.projectExtrasSchema as z.AnyZodObject;\r\n }\r\n\r\n throw new Error(`Module '${candidate}' does not export projectExtrasSchema.`);\r\n } catch (error) {\r\n const reason = error instanceof Error ? error.message : String(error);\r\n throw new Error(`Failed to load project config extension at '${candidate}': ${reason}`);\r\n }\r\n }\r\n\r\n const coreModule = await import(\"../config/project.config.extension.js\");\r\n return coreModule.projectExtrasSchema as z.AnyZodObject;\r\n}\r\n\r\n// Keep placeholder-backed values as plain strings in the generated TypeScript typings so\r\n// consuming code reflects the resolved shapes while the JSON schema still exposes full unions.\r\nconst renderAsString = (typescript: any) =>\r\n typescript.factory.createKeywordTypeNode(typescript.SyntaxKind.StringKeyword);\r\n\r\nfor (const schema of [hostValueSchema, secretValueSchema]) {\r\n withGetType(schema, renderAsString);\r\n}\r\n\r\nconst { unsCoreSchema } = await import(\"../uns-config/uns-core-schema.js\");\r\nconst projectExtrasSchema = await loadProjectExtrasSchema();\r\nconst baseSchema = composeConfigSchema(unsCoreSchema, projectExtrasSchema).strict();\r\n\r\n// 1) JSON Schema for VS Code $schema\r\nconst jsonSchema = zodToJsonSchema(baseSchema, \"AppConfig\");\r\nwrite(path.resolve(\"config.schema.json\"), JSON.stringify(jsonSchema, null, 2));\r\n\r\n// 2) TypeScript `export type AppConfig = {...}`\r\nconst { node } = zodToTs(baseSchema, \"AppConfig\");\r\nconst interfaceBody = printNode(node);\r\n\r\nlet shouldAugment = true;\r\ntry {\r\n const pkgJsonPath = path.resolve(process.cwd(), \"package.json\");\r\n if (fs.existsSync(pkgJsonPath)) {\r\n const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, \"utf8\"));\r\n if (pkg?.name === \"@uns-kit/core\") {\r\n shouldAugment = false;\r\n }\r\n }\r\n} catch {\r\n shouldAugment = true;\r\n}\r\n\r\nconst augmentationBlock = shouldAugment\r\n ? `\\n\\ntype GeneratedProjectAppConfig = ProjectAppConfig;\\ntype GeneratedAppConfig = AppConfig;\\n\\ndeclare module \"@uns-kit/core/config/app-config.js\" {\\n interface ProjectAppConfig extends GeneratedProjectAppConfig {}\\n interface AppConfig extends GeneratedAppConfig {}\\n}\\n`\r\n : \"\\n\";\r\n\r\nconst tsContent = `/* Auto-generated. Do not edit by hand. */\\nexport interface ProjectAppConfig ${interfaceBody}\\n\\nexport interface AppConfig extends ProjectAppConfig {}${augmentationBlock}`;\r\n\r\nwrite(path.resolve(\"./src/config/app-config.ts\"), tsContent);\r\n\r\nconsole.log(\"Generated config.schema.json and updated src/config/app-config.ts\");\r\n"]}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
type DictionaryEntry = {
|
|
3
|
-
description?: string | null;
|
|
4
|
-
descriptions?: Record<string, string | null | undefined>;
|
|
5
|
-
[key: string]: unknown;
|
|
6
|
-
};
|
|
7
|
-
type ObjectTypeEntry = DictionaryEntry & {
|
|
8
|
-
attributes?: string[] | null;
|
|
9
|
-
};
|
|
10
|
-
type UnsDictionary = {
|
|
11
|
-
schemaVersion?: unknown;
|
|
12
|
-
objectTypes?: Record<string, ObjectTypeEntry>;
|
|
13
|
-
attributes?: Record<string, DictionaryEntry>;
|
|
14
|
-
[key: string]: unknown;
|
|
15
|
-
};
|
|
16
|
-
type CliArgs = {
|
|
17
|
-
input: string;
|
|
18
|
-
output: string;
|
|
19
|
-
lang: string;
|
|
20
|
-
};
|
|
21
|
-
export declare function generateUnsDictionary(args: Partial<CliArgs>): Promise<void>;
|
|
22
|
-
export declare function renderDictionaryTs(dictionary: UnsDictionary, lang: string): string;
|
|
23
|
-
export {};
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
type DictionaryEntry = {
|
|
3
|
+
description?: string | null;
|
|
4
|
+
descriptions?: Record<string, string | null | undefined>;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
};
|
|
7
|
+
type ObjectTypeEntry = DictionaryEntry & {
|
|
8
|
+
attributes?: string[] | null;
|
|
9
|
+
};
|
|
10
|
+
type UnsDictionary = {
|
|
11
|
+
schemaVersion?: unknown;
|
|
12
|
+
objectTypes?: Record<string, ObjectTypeEntry>;
|
|
13
|
+
attributes?: Record<string, DictionaryEntry>;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
};
|
|
16
|
+
type CliArgs = {
|
|
17
|
+
input: string;
|
|
18
|
+
output: string;
|
|
19
|
+
lang: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function generateUnsDictionary(args: Partial<CliArgs>): Promise<void>;
|
|
22
|
+
export declare function renderDictionaryTs(dictionary: UnsDictionary, lang: string): string;
|
|
23
|
+
export {};
|
|
24
24
|
//# sourceMappingURL=generate-uns-dictionary.d.ts.map
|
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Generate a TypeScript dictionary of object types and attributes (with descriptions)
|
|
4
|
-
* from a JSON file. The output is meant for IntelliSense and metadata enrichment
|
|
5
|
-
* (e.g., emitting descriptions alongside topics). No GraphQL calls are performed.
|
|
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 { readFile } from "node:fs/promises";
|
|
20
|
-
import path from "node:path";
|
|
21
|
-
import { pathToFileURL } from "node:url";
|
|
22
|
-
import { writeTextFileIfChanged } from "./file-utils.js";
|
|
23
|
-
const DEFAULT_INPUT = "uns-dictionary.json";
|
|
24
|
-
const DEFAULT_OUTPUT = path.resolve(process.cwd(), "src/uns/uns-dictionary.generated.ts");
|
|
25
|
-
async function main() {
|
|
26
|
-
const args = parseArgs(process.argv.slice(2));
|
|
27
|
-
await generateUnsDictionary(args);
|
|
28
|
-
}
|
|
29
|
-
function parseArgs(argv) {
|
|
30
|
-
let input = DEFAULT_INPUT;
|
|
31
|
-
let output = DEFAULT_OUTPUT;
|
|
32
|
-
let lang = "sl";
|
|
33
|
-
for (let i = 0; i < argv.length; i++) {
|
|
34
|
-
const arg = argv[i];
|
|
35
|
-
if (arg === "--input" && argv[i + 1]) {
|
|
36
|
-
input = argv[++i];
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
if (arg === "--output" && argv[i + 1]) {
|
|
40
|
-
output = argv[++i];
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
if (arg === "--lang" && argv[i + 1]) {
|
|
44
|
-
lang = argv[++i];
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
if (arg === "--help" || arg === "-h") {
|
|
48
|
-
printHelp();
|
|
49
|
-
process.exit(0);
|
|
50
|
-
}
|
|
51
|
-
throw new Error(`Unknown argument: ${arg}`);
|
|
52
|
-
}
|
|
53
|
-
return { input, output, lang };
|
|
54
|
-
}
|
|
55
|
-
function printHelp() {
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Generate a TypeScript dictionary of object types and attributes (with descriptions)
|
|
4
|
+
* from a JSON file. The output is meant for IntelliSense and metadata enrichment
|
|
5
|
+
* (e.g., emitting descriptions alongside topics). No GraphQL calls are performed.
|
|
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 { readFile } from "node:fs/promises";
|
|
20
|
+
import path from "node:path";
|
|
21
|
+
import { pathToFileURL } from "node:url";
|
|
22
|
+
import { writeTextFileIfChanged } from "./file-utils.js";
|
|
23
|
+
const DEFAULT_INPUT = "uns-dictionary.json";
|
|
24
|
+
const DEFAULT_OUTPUT = path.resolve(process.cwd(), "src/uns/uns-dictionary.generated.ts");
|
|
25
|
+
async function main() {
|
|
26
|
+
const args = parseArgs(process.argv.slice(2));
|
|
27
|
+
await generateUnsDictionary(args);
|
|
28
|
+
}
|
|
29
|
+
function parseArgs(argv) {
|
|
30
|
+
let input = DEFAULT_INPUT;
|
|
31
|
+
let output = DEFAULT_OUTPUT;
|
|
32
|
+
let lang = "sl";
|
|
33
|
+
for (let i = 0; i < argv.length; i++) {
|
|
34
|
+
const arg = argv[i];
|
|
35
|
+
if (arg === "--input" && argv[i + 1]) {
|
|
36
|
+
input = argv[++i];
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (arg === "--output" && argv[i + 1]) {
|
|
40
|
+
output = argv[++i];
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (arg === "--lang" && argv[i + 1]) {
|
|
44
|
+
lang = argv[++i];
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (arg === "--help" || arg === "-h") {
|
|
48
|
+
printHelp();
|
|
49
|
+
process.exit(0);
|
|
50
|
+
}
|
|
51
|
+
throw new Error(`Unknown argument: ${arg}`);
|
|
52
|
+
}
|
|
53
|
+
return { input, output, lang };
|
|
54
|
+
}
|
|
55
|
+
function printHelp() {
|
|
56
56
|
console.log(`Usage: tsx packages/uns-core/src/tools/generate-uns-dictionary.ts [options]
|
|
57
57
|
|
|
58
58
|
Options:
|
|
@@ -60,96 +60,96 @@ Options:
|
|
|
60
60
|
--output <file> Path to generated TS file (default: src/uns/uns-dictionary.generated.ts)
|
|
61
61
|
--lang <code> Preferred description language code (default: "sl")
|
|
62
62
|
--help, -h Show this help
|
|
63
|
-
`);
|
|
64
|
-
}
|
|
65
|
-
async function readDictionaryFromJson(filePath) {
|
|
66
|
-
const absolute = path.resolve(process.cwd(), filePath);
|
|
67
|
-
const raw = await readFile(absolute, "utf8");
|
|
68
|
-
return JSON.parse(raw);
|
|
69
|
-
}
|
|
70
|
-
export async function generateUnsDictionary(args) {
|
|
71
|
-
const effective = {
|
|
72
|
-
input: args.input ?? DEFAULT_INPUT,
|
|
73
|
-
output: args.output ?? DEFAULT_OUTPUT,
|
|
74
|
-
lang: args.lang ?? "sl",
|
|
75
|
-
};
|
|
76
|
-
const dictionary = await readDictionaryFromJson(effective.input);
|
|
77
|
-
const changed = await writeDictionaryTs(dictionary, effective.output, effective.lang);
|
|
78
|
-
console.log(`Generated dictionary -> ${effective.output}${changed ? "" : " (unchanged)"}`);
|
|
79
|
-
}
|
|
80
|
-
const resolveDescription = (entry, lang) => {
|
|
81
|
-
if (!entry)
|
|
82
|
-
return undefined;
|
|
83
|
-
const byLang = entry.descriptions?.[lang];
|
|
84
|
-
if (byLang && byLang.length > 0)
|
|
85
|
-
return byLang;
|
|
86
|
-
if (entry.description && entry.description.length > 0)
|
|
87
|
-
return entry.description;
|
|
88
|
-
return undefined;
|
|
89
|
-
};
|
|
90
|
-
function renderDoc(description, indent) {
|
|
91
|
-
if (!description)
|
|
92
|
-
return "";
|
|
93
|
-
const normalized = description
|
|
94
|
-
.replaceAll("*/", "*\\/")
|
|
95
|
-
.split(/\r?\n/)
|
|
96
|
-
.map((line) => `${indent} * ${line}`)
|
|
97
|
-
.join("\n");
|
|
98
|
-
return `${indent}/**\n${normalized}\n${indent} */\n`;
|
|
99
|
-
}
|
|
100
|
-
export function renderDictionaryTs(dictionary, lang) {
|
|
101
|
-
const objectTypeEntries = Object.entries(dictionary.objectTypes ?? {}).sort(([left], [right]) => left.localeCompare(right));
|
|
102
|
-
const attributeEntries = Object.entries(dictionary.attributes ?? {}).sort(([left], [right]) => left.localeCompare(right));
|
|
103
|
-
const attributesByType = {};
|
|
104
|
-
for (const [name, entry] of objectTypeEntries) {
|
|
105
|
-
if (Array.isArray(entry.attributes) && entry.attributes.length > 0) {
|
|
106
|
-
attributesByType[name] = entry.attributes.filter((attribute) => typeof attribute === "string" && attribute.length > 0);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
const renderRecord = (entries) => entries
|
|
110
|
-
.map(([name, entry]) => {
|
|
111
|
-
const desc = resolveDescription(entry, lang);
|
|
112
|
-
const doc = renderDoc(desc, " ");
|
|
113
|
-
return `${doc} "${name}": "${name}",`;
|
|
114
|
-
})
|
|
115
|
-
.join("\n");
|
|
116
|
-
const renderDescriptions = (entries) => entries
|
|
117
|
-
.map(([name, value]) => ` "${name}": ${JSON.stringify(resolveDescription(value, lang) ?? "")},`)
|
|
118
|
-
.join("\n");
|
|
119
|
-
const objectTypeConst = `export const GeneratedObjectTypes = {\n${renderRecord(objectTypeEntries)}\n} as const;`;
|
|
120
|
-
const objectTypeDescConst = `export const GeneratedObjectTypeDescriptions: Record<keyof typeof GeneratedObjectTypes, string> = {\n${renderDescriptions(objectTypeEntries)}\n};`;
|
|
121
|
-
const attributeConst = `export const GeneratedAttributes = {\n${renderRecord(attributeEntries)}\n} as const;`;
|
|
122
|
-
const attributeDescConst = `export const GeneratedAttributeDescriptions: Record<keyof typeof GeneratedAttributes, string> = {\n${renderDescriptions(attributeEntries)}\n};`;
|
|
123
|
-
const renderAttributesByType = () => {
|
|
124
|
-
const blocks = [];
|
|
125
|
-
for (const [objectType, attrs] of Object.entries(attributesByType)) {
|
|
126
|
-
if (!attrs.length)
|
|
127
|
-
continue;
|
|
128
|
-
const lines = attrs
|
|
129
|
-
.map((attr) => {
|
|
130
|
-
const desc = resolveDescription(dictionary.attributes?.[attr], lang);
|
|
131
|
-
const doc = renderDoc(desc, " ");
|
|
132
|
-
return `${doc} "${attr}": "${attr}",`;
|
|
133
|
-
})
|
|
134
|
-
.join("\n");
|
|
135
|
-
blocks.push(` "${objectType}": {\n${lines}\n },`);
|
|
136
|
-
}
|
|
137
|
-
return blocks.join("\n");
|
|
138
|
-
};
|
|
139
|
-
const attributesByTypeConst = `const GeneratedAttributesByTypeBase = {\n${renderAttributesByType()}\n} as const;\n\nexport const GeneratedAttributesByType = GeneratedAttributesByTypeBase;`;
|
|
140
|
-
return `/* 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\n${attributesByTypeConst}\n\nexport type GeneratedAttributeName = keyof typeof GeneratedAttributes;\n\nexport type GeneratedAttributesFor<T extends keyof typeof GeneratedAttributesByType> = keyof typeof GeneratedAttributesByType[T];\n\nexport function getGeneratedAttributeDescription(name: string): string | undefined {\n return (GeneratedAttributeDescriptions as Record<string, string | undefined>)[name];\n}\n`;
|
|
141
|
-
}
|
|
142
|
-
async function writeDictionaryTs(dictionary, filePath, lang) {
|
|
143
|
-
const content = renderDictionaryTs(dictionary, lang);
|
|
144
|
-
return writeTextFileIfChanged(filePath, content);
|
|
145
|
-
}
|
|
146
|
-
const isDirectExecution = process.argv[1]
|
|
147
|
-
? import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href
|
|
148
|
-
: false;
|
|
149
|
-
if (isDirectExecution) {
|
|
150
|
-
main().catch((error) => {
|
|
151
|
-
console.error("Failed to generate UNS dictionary:", error);
|
|
152
|
-
process.exitCode = 1;
|
|
153
|
-
});
|
|
154
|
-
}
|
|
63
|
+
`);
|
|
64
|
+
}
|
|
65
|
+
async function readDictionaryFromJson(filePath) {
|
|
66
|
+
const absolute = path.resolve(process.cwd(), filePath);
|
|
67
|
+
const raw = await readFile(absolute, "utf8");
|
|
68
|
+
return JSON.parse(raw);
|
|
69
|
+
}
|
|
70
|
+
export async function generateUnsDictionary(args) {
|
|
71
|
+
const effective = {
|
|
72
|
+
input: args.input ?? DEFAULT_INPUT,
|
|
73
|
+
output: args.output ?? DEFAULT_OUTPUT,
|
|
74
|
+
lang: args.lang ?? "sl",
|
|
75
|
+
};
|
|
76
|
+
const dictionary = await readDictionaryFromJson(effective.input);
|
|
77
|
+
const changed = await writeDictionaryTs(dictionary, effective.output, effective.lang);
|
|
78
|
+
console.log(`Generated dictionary -> ${effective.output}${changed ? "" : " (unchanged)"}`);
|
|
79
|
+
}
|
|
80
|
+
const resolveDescription = (entry, lang) => {
|
|
81
|
+
if (!entry)
|
|
82
|
+
return undefined;
|
|
83
|
+
const byLang = entry.descriptions?.[lang];
|
|
84
|
+
if (byLang && byLang.length > 0)
|
|
85
|
+
return byLang;
|
|
86
|
+
if (entry.description && entry.description.length > 0)
|
|
87
|
+
return entry.description;
|
|
88
|
+
return undefined;
|
|
89
|
+
};
|
|
90
|
+
function renderDoc(description, indent) {
|
|
91
|
+
if (!description)
|
|
92
|
+
return "";
|
|
93
|
+
const normalized = description
|
|
94
|
+
.replaceAll("*/", "*\\/")
|
|
95
|
+
.split(/\r?\n/)
|
|
96
|
+
.map((line) => `${indent} * ${line}`)
|
|
97
|
+
.join("\n");
|
|
98
|
+
return `${indent}/**\n${normalized}\n${indent} */\n`;
|
|
99
|
+
}
|
|
100
|
+
export function renderDictionaryTs(dictionary, lang) {
|
|
101
|
+
const objectTypeEntries = Object.entries(dictionary.objectTypes ?? {}).sort(([left], [right]) => left.localeCompare(right));
|
|
102
|
+
const attributeEntries = Object.entries(dictionary.attributes ?? {}).sort(([left], [right]) => left.localeCompare(right));
|
|
103
|
+
const attributesByType = {};
|
|
104
|
+
for (const [name, entry] of objectTypeEntries) {
|
|
105
|
+
if (Array.isArray(entry.attributes) && entry.attributes.length > 0) {
|
|
106
|
+
attributesByType[name] = entry.attributes.filter((attribute) => typeof attribute === "string" && attribute.length > 0);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const renderRecord = (entries) => entries
|
|
110
|
+
.map(([name, entry]) => {
|
|
111
|
+
const desc = resolveDescription(entry, lang);
|
|
112
|
+
const doc = renderDoc(desc, " ");
|
|
113
|
+
return `${doc} "${name}": "${name}",`;
|
|
114
|
+
})
|
|
115
|
+
.join("\n");
|
|
116
|
+
const renderDescriptions = (entries) => entries
|
|
117
|
+
.map(([name, value]) => ` "${name}": ${JSON.stringify(resolveDescription(value, lang) ?? "")},`)
|
|
118
|
+
.join("\n");
|
|
119
|
+
const objectTypeConst = `export const GeneratedObjectTypes = {\n${renderRecord(objectTypeEntries)}\n} as const;`;
|
|
120
|
+
const objectTypeDescConst = `export const GeneratedObjectTypeDescriptions: Record<keyof typeof GeneratedObjectTypes, string> = {\n${renderDescriptions(objectTypeEntries)}\n};`;
|
|
121
|
+
const attributeConst = `export const GeneratedAttributes = {\n${renderRecord(attributeEntries)}\n} as const;`;
|
|
122
|
+
const attributeDescConst = `export const GeneratedAttributeDescriptions: Record<keyof typeof GeneratedAttributes, string> = {\n${renderDescriptions(attributeEntries)}\n};`;
|
|
123
|
+
const renderAttributesByType = () => {
|
|
124
|
+
const blocks = [];
|
|
125
|
+
for (const [objectType, attrs] of Object.entries(attributesByType)) {
|
|
126
|
+
if (!attrs.length)
|
|
127
|
+
continue;
|
|
128
|
+
const lines = attrs
|
|
129
|
+
.map((attr) => {
|
|
130
|
+
const desc = resolveDescription(dictionary.attributes?.[attr], lang);
|
|
131
|
+
const doc = renderDoc(desc, " ");
|
|
132
|
+
return `${doc} "${attr}": "${attr}",`;
|
|
133
|
+
})
|
|
134
|
+
.join("\n");
|
|
135
|
+
blocks.push(` "${objectType}": {\n${lines}\n },`);
|
|
136
|
+
}
|
|
137
|
+
return blocks.join("\n");
|
|
138
|
+
};
|
|
139
|
+
const attributesByTypeConst = `const GeneratedAttributesByTypeBase = {\n${renderAttributesByType()}\n} as const;\n\nexport const GeneratedAttributesByType = GeneratedAttributesByTypeBase;`;
|
|
140
|
+
return `/* 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\n${attributesByTypeConst}\n\nexport type GeneratedAttributeName = keyof typeof GeneratedAttributes;\n\nexport type GeneratedAttributesFor<T extends keyof typeof GeneratedAttributesByType> = keyof typeof GeneratedAttributesByType[T];\n\nexport function getGeneratedAttributeDescription(name: string): string | undefined {\n return (GeneratedAttributeDescriptions as Record<string, string | undefined>)[name];\n}\n`;
|
|
141
|
+
}
|
|
142
|
+
async function writeDictionaryTs(dictionary, filePath, lang) {
|
|
143
|
+
const content = renderDictionaryTs(dictionary, lang);
|
|
144
|
+
return writeTextFileIfChanged(filePath, content);
|
|
145
|
+
}
|
|
146
|
+
const isDirectExecution = process.argv[1]
|
|
147
|
+
? import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href
|
|
148
|
+
: false;
|
|
149
|
+
if (isDirectExecution) {
|
|
150
|
+
main().catch((error) => {
|
|
151
|
+
console.error("Failed to generate UNS dictionary:", error);
|
|
152
|
+
process.exitCode = 1;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
155
|
//# sourceMappingURL=generate-uns-dictionary.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-uns-dictionary.js","sourceRoot":"","sources":["../../src/tools/generate-uns-dictionary.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAuBzD,MAAM,aAAa,GAAG,qBAAqB,CAAC;AAC5C,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,qCAAqC,CAAC,CAAC;AAE1F,KAAK,UAAU,IAAI;IACjB,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,MAAM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EAAE,CAAC;IACtB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACrB,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;QAC3D,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["#!/usr/bin/env node\n/**\n * Generate a TypeScript dictionary of object types and attributes (with descriptions)\n * from a JSON file. The output is meant for IntelliSense and metadata enrichment\n * (e.g., emitting descriptions alongside topics). No GraphQL calls are performed.\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 { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { writeTextFileIfChanged } from \"./file-utils.js\";\n\ntype DictionaryEntry = {\n description?: string | null;\n descriptions?: Record<string, string | null | undefined>;\n [key: string]: unknown;\n};\ntype ObjectTypeEntry = DictionaryEntry & {\n attributes?: string[] | null;\n};\ntype UnsDictionary = {\n schemaVersion?: unknown;\n objectTypes?: Record<string, ObjectTypeEntry>;\n attributes?: Record<string, DictionaryEntry>;\n [key: string]: unknown;\n};\n\ntype CliArgs = {\n input: string;\n output: string;\n lang: string;\n};\n\nconst DEFAULT_INPUT = \"uns-dictionary.json\";\nconst DEFAULT_OUTPUT = path.resolve(process.cwd(), \"src/uns/uns-dictionary.generated.ts\");\n\nasync function main(): Promise<void> {\n const args = parseArgs(process.argv.slice(2));\n await generateUnsDictionary(args);\n}\n\nfunction parseArgs(argv: string[]): CliArgs {\n let input = DEFAULT_INPUT;\n let output = DEFAULT_OUTPUT;\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 === \"--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, 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 --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\nexport async function generateUnsDictionary(args: Partial<CliArgs>): Promise<void> {\n const effective: CliArgs = {\n input: args.input ?? DEFAULT_INPUT,\n output: args.output ?? DEFAULT_OUTPUT,\n lang: args.lang ?? \"sl\",\n };\n\n const dictionary = await readDictionaryFromJson(effective.input);\n const changed = await writeDictionaryTs(dictionary, effective.output, effective.lang);\n console.log(`Generated dictionary -> ${effective.output}${changed ? \"\" : \" (unchanged)\"}`);\n}\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 renderDoc(description: string | undefined, indent: string): string {\n if (!description) return \"\";\n const normalized = description\n .replaceAll(\"*/\", \"*\\\\/\")\n .split(/\\r?\\n/)\n .map((line) => `${indent} * ${line}`)\n .join(\"\\n\");\n return `${indent}/**\\n${normalized}\\n${indent} */\\n`;\n}\n\nexport function renderDictionaryTs(dictionary: UnsDictionary, lang: string): string {\n const objectTypeEntries = Object.entries(dictionary.objectTypes ?? {}).sort(([left], [right]) => left.localeCompare(right));\n const attributeEntries = Object.entries(dictionary.attributes ?? {}).sort(([left], [right]) => left.localeCompare(right));\n const attributesByType: Record<string, string[]> = {};\n for (const [name, entry] of objectTypeEntries) {\n if (Array.isArray(entry.attributes) && entry.attributes.length > 0) {\n attributesByType[name] = entry.attributes.filter(\n (attribute): attribute is string => typeof attribute === \"string\" && attribute.length > 0,\n );\n }\n }\n\n const renderRecord = (entries: [string, DictionaryEntry][]) =>\n entries\n .map(([name, entry]) => {\n const desc = resolveDescription(entry, lang);\n const doc = renderDoc(desc, \" \");\n return `${doc} \"${name}\": \"${name}\",`;\n })\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 renderAttributesByType = () => {\n const blocks: string[] = [];\n for (const [objectType, attrs] of Object.entries(attributesByType)) {\n if (!attrs.length) continue;\n const lines = attrs\n .map((attr) => {\n const desc = resolveDescription(dictionary.attributes?.[attr], lang);\n const doc = renderDoc(desc, \" \");\n return `${doc} \"${attr}\": \"${attr}\",`;\n })\n .join(\"\\n\");\n blocks.push(` \"${objectType}\": {\\n${lines}\\n },`);\n }\n return blocks.join(\"\\n\");\n };\n\n const attributesByTypeConst = `const GeneratedAttributesByTypeBase = {\\n${renderAttributesByType()}\\n} as const;\\n\\nexport const GeneratedAttributesByType = GeneratedAttributesByTypeBase;`;\n\n return `/* 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\\n${attributesByTypeConst}\\n\\nexport type GeneratedAttributeName = keyof typeof GeneratedAttributes;\\n\\nexport type GeneratedAttributesFor<T extends keyof typeof GeneratedAttributesByType> = keyof typeof GeneratedAttributesByType[T];\\n\\nexport function getGeneratedAttributeDescription(name: string): string | undefined {\\n return (GeneratedAttributeDescriptions as Record<string, string | undefined>)[name];\\n}\\n`;\n}\n\nasync function writeDictionaryTs(dictionary: UnsDictionary, filePath: string, lang: string): Promise<boolean> {\n const content = renderDictionaryTs(dictionary, lang);\n return writeTextFileIfChanged(filePath, content);\n}\n\nconst isDirectExecution = process.argv[1]\n ? import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href\n : false;\n\nif (isDirectExecution) {\n main().catch((error) => {\n console.error(\"Failed to generate UNS dictionary:\", error);\n process.exitCode = 1;\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"generate-uns-dictionary.js","sourceRoot":"","sources":["../../src/tools/generate-uns-dictionary.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAuBzD,MAAM,aAAa,GAAG,q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iB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACvC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;IACvE,CAAC,CAAC,KAAK,CAAC;AAEV,IAAI,iBAAiB,EAAE,CAAC;IACtB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACrB,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;QAC3D,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["#!/usr/bin/env node\r\n/**\r\n * Generate a TypeScript dictionary of object types and attributes (with descriptions)\r\n * from a JSON file. The output is meant for IntelliSense and metadata enrichment\r\n * (e.g., emitting descriptions alongside topics). No GraphQL calls are performed.\r\n *\r\n * JSON shape (example):\r\n * {\r\n * \"objectTypes\": {\r\n * \"energy-resource\": { \"description\": \"Energy carriers (electricity/steam/gas)\" },\r\n * \"custom-type\": { \"description\": \"Tenant-specific thing\" }\r\n * },\r\n * \"attributes\": {\r\n * \"cumulative-active-energy-delivered\": { \"description\": \"kWh total\" },\r\n * \"status\": { \"description\": \"Generic status\" }\r\n * }\r\n * }\r\n */\r\nimport { readFile } from \"node:fs/promises\";\r\nimport path from \"node:path\";\r\nimport { pathToFileURL } from \"node:url\";\r\nimport { writeTextFileIfChanged } from \"./file-utils.js\";\r\n\r\ntype DictionaryEntry = {\r\n description?: string | null;\r\n descriptions?: Record<string, string | null | undefined>;\r\n [key: string]: unknown;\r\n};\r\ntype ObjectTypeEntry = DictionaryEntry & {\r\n attributes?: string[] | null;\r\n};\r\ntype UnsDictionary = {\r\n schemaVersion?: unknown;\r\n objectTypes?: Record<string, ObjectTypeEntry>;\r\n attributes?: Record<string, DictionaryEntry>;\r\n [key: string]: unknown;\r\n};\r\n\r\ntype CliArgs = {\r\n input: string;\r\n output: string;\r\n lang: string;\r\n};\r\n\r\nconst DEFAULT_INPUT = \"uns-dictionary.json\";\r\nconst DEFAULT_OUTPUT = path.resolve(process.cwd(), \"src/uns/uns-dictionary.generated.ts\");\r\n\r\nasync function main(): Promise<void> {\r\n const args = parseArgs(process.argv.slice(2));\r\n await generateUnsDictionary(args);\r\n}\r\n\r\nfunction parseArgs(argv: string[]): CliArgs {\r\n let input = DEFAULT_INPUT;\r\n let output = DEFAULT_OUTPUT;\r\n let lang = \"sl\";\r\n\r\n for (let i = 0; i < argv.length; i++) {\r\n const arg = argv[i];\r\n if (arg === \"--input\" && argv[i + 1]) {\r\n input = argv[++i];\r\n continue;\r\n }\r\n if (arg === \"--output\" && argv[i + 1]) {\r\n output = argv[++i];\r\n continue;\r\n }\r\n if (arg === \"--lang\" && argv[i + 1]) {\r\n lang = argv[++i];\r\n continue;\r\n }\r\n if (arg === \"--help\" || arg === \"-h\") {\r\n printHelp();\r\n process.exit(0);\r\n }\r\n throw new Error(`Unknown argument: ${arg}`);\r\n }\r\n\r\n return { input, output, lang };\r\n}\r\n\r\nfunction printHelp(): void {\r\n console.log(`Usage: tsx packages/uns-core/src/tools/generate-uns-dictionary.ts [options]\r\n\r\nOptions:\r\n --input <file> Path to uns-dictionary.json (default: ${DEFAULT_INPUT})\r\n --output <file> Path to generated TS file (default: src/uns/uns-dictionary.generated.ts)\r\n --lang <code> Preferred description language code (default: \"sl\")\r\n --help, -h Show this help\r\n`);\r\n}\r\n\r\nasync function readDictionaryFromJson(filePath: string): Promise<UnsDictionary> {\r\n const absolute = path.resolve(process.cwd(), filePath);\r\n const raw = await readFile(absolute, \"utf8\");\r\n return JSON.parse(raw) as UnsDictionary;\r\n}\r\n\r\nexport async function generateUnsDictionary(args: Partial<CliArgs>): Promise<void> {\r\n const effective: CliArgs = {\r\n input: args.input ?? DEFAULT_INPUT,\r\n output: args.output ?? DEFAULT_OUTPUT,\r\n lang: args.lang ?? \"sl\",\r\n };\r\n\r\n const dictionary = await readDictionaryFromJson(effective.input);\r\n const changed = await writeDictionaryTs(dictionary, effective.output, effective.lang);\r\n console.log(`Generated dictionary -> ${effective.output}${changed ? \"\" : \" (unchanged)\"}`);\r\n}\r\n\r\nconst resolveDescription = (entry: DictionaryEntry | undefined, lang: string): string | undefined => {\r\n if (!entry) return undefined;\r\n const byLang = entry.descriptions?.[lang];\r\n if (byLang && byLang.length > 0) return byLang;\r\n if (entry.description && entry.description.length > 0) return entry.description;\r\n return undefined;\r\n};\r\n\r\nfunction renderDoc(description: string | undefined, indent: string): string {\r\n if (!description) return \"\";\r\n const normalized = description\r\n .replaceAll(\"*/\", \"*\\\\/\")\r\n .split(/\\r?\\n/)\r\n .map((line) => `${indent} * ${line}`)\r\n .join(\"\\n\");\r\n return `${indent}/**\\n${normalized}\\n${indent} */\\n`;\r\n}\r\n\r\nexport function renderDictionaryTs(dictionary: UnsDictionary, lang: string): string {\r\n const objectTypeEntries = Object.entries(dictionary.objectTypes ?? {}).sort(([left], [right]) => left.localeCompare(right));\r\n const attributeEntries = Object.entries(dictionary.attributes ?? {}).sort(([left], [right]) => left.localeCompare(right));\r\n const attributesByType: Record<string, string[]> = {};\r\n for (const [name, entry] of objectTypeEntries) {\r\n if (Array.isArray(entry.attributes) && entry.attributes.length > 0) {\r\n attributesByType[name] = entry.attributes.filter(\r\n (attribute): attribute is string => typeof attribute === \"string\" && attribute.length > 0,\r\n );\r\n }\r\n }\r\n\r\n const renderRecord = (entries: [string, DictionaryEntry][]) =>\r\n entries\r\n .map(([name, entry]) => {\r\n const desc = resolveDescription(entry, lang);\r\n const doc = renderDoc(desc, \" \");\r\n return `${doc} \"${name}\": \"${name}\",`;\r\n })\r\n .join(\"\\n\");\r\n\r\n const renderDescriptions = (entries: [string, DictionaryEntry][]) =>\r\n entries\r\n .map(([name, value]) => ` \"${name}\": ${JSON.stringify(resolveDescription(value, lang) ?? \"\")},`)\r\n .join(\"\\n\");\r\n\r\n const objectTypeConst = `export const GeneratedObjectTypes = {\\n${renderRecord(objectTypeEntries)}\\n} as const;`;\r\n const objectTypeDescConst = `export const GeneratedObjectTypeDescriptions: Record<keyof typeof GeneratedObjectTypes, string> = {\\n${renderDescriptions(objectTypeEntries)}\\n};`;\r\n\r\n const attributeConst = `export const GeneratedAttributes = {\\n${renderRecord(attributeEntries)}\\n} as const;`;\r\n const attributeDescConst = `export const GeneratedAttributeDescriptions: Record<keyof typeof GeneratedAttributes, string> = {\\n${renderDescriptions(attributeEntries)}\\n};`;\r\n\r\n const renderAttributesByType = () => {\r\n const blocks: string[] = [];\r\n for (const [objectType, attrs] of Object.entries(attributesByType)) {\r\n if (!attrs.length) continue;\r\n const lines = attrs\r\n .map((attr) => {\r\n const desc = resolveDescription(dictionary.attributes?.[attr], lang);\r\n const doc = renderDoc(desc, \" \");\r\n return `${doc} \"${attr}\": \"${attr}\",`;\r\n })\r\n .join(\"\\n\");\r\n blocks.push(` \"${objectType}\": {\\n${lines}\\n },`);\r\n }\r\n return blocks.join(\"\\n\");\r\n };\r\n\r\n const attributesByTypeConst = `const GeneratedAttributesByTypeBase = {\\n${renderAttributesByType()}\\n} as const;\\n\\nexport const GeneratedAttributesByType = GeneratedAttributesByTypeBase;`;\r\n\r\n return `/* 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\\n${attributesByTypeConst}\\n\\nexport type GeneratedAttributeName = keyof typeof GeneratedAttributes;\\n\\nexport type GeneratedAttributesFor<T extends keyof typeof GeneratedAttributesByType> = keyof typeof GeneratedAttributesByType[T];\\n\\nexport function getGeneratedAttributeDescription(name: string): string | undefined {\\n return (GeneratedAttributeDescriptions as Record<string, string | undefined>)[name];\\n}\\n`;\r\n}\r\n\r\nasync function writeDictionaryTs(dictionary: UnsDictionary, filePath: string, lang: string): Promise<boolean> {\r\n const content = renderDictionaryTs(dictionary, lang);\r\n return writeTextFileIfChanged(filePath, content);\r\n}\r\n\r\nconst isDirectExecution = process.argv[1]\r\n ? import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href\r\n : false;\r\n\r\nif (isDirectExecution) {\r\n main().catch((error) => {\r\n console.error(\"Failed to generate UNS dictionary:\", error);\r\n process.exitCode = 1;\r\n });\r\n}\r\n"]}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
type Entry = {
|
|
3
|
-
value: string;
|
|
4
|
-
description?: string | null;
|
|
5
|
-
descriptions?: Record<string, string | null | undefined>;
|
|
6
|
-
[key: string]: unknown;
|
|
7
|
-
};
|
|
8
|
-
type MeasurementsJson = {
|
|
9
|
-
schemaVersion?: unknown;
|
|
10
|
-
physical?: Record<string, Entry>;
|
|
11
|
-
dataSize?: Record<string, Entry>;
|
|
12
|
-
counter?: Record<string, Entry>;
|
|
13
|
-
[category: string]: unknown;
|
|
14
|
-
};
|
|
15
|
-
export declare function renderMeasurementsTs(json: MeasurementsJson, lang: string): string;
|
|
16
|
-
export declare function generateUnsMeasurements(args: Partial<{
|
|
17
|
-
input: string;
|
|
18
|
-
output: string;
|
|
19
|
-
lang: string;
|
|
20
|
-
}>): Promise<void>;
|
|
21
|
-
export {};
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
type Entry = {
|
|
3
|
+
value: string;
|
|
4
|
+
description?: string | null;
|
|
5
|
+
descriptions?: Record<string, string | null | undefined>;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
};
|
|
8
|
+
type MeasurementsJson = {
|
|
9
|
+
schemaVersion?: unknown;
|
|
10
|
+
physical?: Record<string, Entry>;
|
|
11
|
+
dataSize?: Record<string, Entry>;
|
|
12
|
+
counter?: Record<string, Entry>;
|
|
13
|
+
[category: string]: unknown;
|
|
14
|
+
};
|
|
15
|
+
export declare function renderMeasurementsTs(json: MeasurementsJson, lang: string): string;
|
|
16
|
+
export declare function generateUnsMeasurements(args: Partial<{
|
|
17
|
+
input: string;
|
|
18
|
+
output: string;
|
|
19
|
+
lang: string;
|
|
20
|
+
}>): Promise<void>;
|
|
21
|
+
export {};
|
|
22
22
|
//# sourceMappingURL=generate-uns-measurements.d.ts.map
|