diff --git a/lib/test/makeOutput.ts b/lib/test/makeOutput.ts index 61beeb6..a3cb439 100644 --- a/lib/test/makeOutput.ts +++ b/lib/test/makeOutput.ts @@ -3,6 +3,41 @@ import { writeConvertedFile } from "../../scripts/oldSpecToBuilder"; writeConvertedFile( "./lib/test/output.ts", { + testListUnion: { + type: "list", + subtype: "union", + name: "Lightning Nodes", + description: "List of Lightning Network node instances to manage", + range: "[1,*)", + default: ["lnd"], + spec: { + type: "string", + "display-as": "{{name}}", + "unique-by": "name", + name: "Node Implementation", + tag: { + id: "type", + name: "Type", + description: "- LND: Lightning Network Daemon from Lightning Labs\n- CLN: Core Lightning from Blockstream\n", + "variant-names": { + lnd: "Lightning Network Daemon (LND)", + "c-lightning": "Core Lightning (CLN)", + }, + }, + default: "lnd", + variants: { + lnd: { + name: { + type: "string", + name: "Node Name", + description: "Name of this node in the list", + default: "Embassy LND", + nullable: false, + }, + }, + }, + }, + }, rpc: { type: "object", name: "RPC Settings", @@ -22,8 +57,7 @@ writeConvertedFile( default: "bitcoin", masked: true, pattern: "^[a-zA-Z0-9_]+$", - "pattern-description": - "Must be alphanumeric (can contain underscore).", + "pattern-description": "Must be alphanumeric (can contain underscore).", }, password: { type: "string", @@ -35,8 +69,7 @@ writeConvertedFile( len: 20, }, pattern: '^[^\\n"]*$', - "pattern-description": - "Must not contain newline or quote characters.", + "pattern-description": "Must not contain newline or quote characters.", copyable: true, masked: true, }, @@ -53,18 +86,15 @@ writeConvertedFile( subtype: "string", default: [], spec: { - pattern: - "^[a-zA-Z0-9_-]+:([0-9a-fA-F]{2})+\\$([0-9a-fA-F]{2})+$", - "pattern-description": - 'Each item must be of the form ":$".', + pattern: "^[a-zA-Z0-9_-]+:([0-9a-fA-F]{2})+\\$([0-9a-fA-F]{2})+$", + "pattern-description": 'Each item must be of the form ":$".', masked: false, }, range: "[0,*)", }, serialversion: { name: "Serialization Version", - description: - "Return raw transaction or block hex with Segwit or non-SegWit serialization.", + description: "Return raw transaction or block hex with Segwit or non-SegWit serialization.", type: "enum", values: ["non-segwit", "segwit"], "value-names": {}, @@ -72,8 +102,7 @@ writeConvertedFile( }, servertimeout: { name: "Rpc Server Timeout", - description: - "Number of seconds after which an uncompleted RPC call will time out.", + description: "Number of seconds after which an uncompleted RPC call will time out.", type: "number", nullable: false, range: "[5,300]", @@ -176,8 +205,7 @@ writeConvertedFile( type: "number", nullable: false, name: "Max Mempool Size", - description: - "Keep the transaction memory pool below megabytes.", + description: "Keep the transaction memory pool below megabytes.", range: "[1,*)", integral: true, units: "MiB", @@ -187,8 +215,7 @@ writeConvertedFile( type: "number", nullable: false, name: "Mempool Expiration", - description: - "Do not keep transactions in the mempool longer than hours.", + description: "Do not keep transactions in the mempool longer than hours.", range: "[1,*)", integral: true, units: "Hr", @@ -204,8 +231,7 @@ writeConvertedFile( listen: { type: "boolean", name: "Make Public", - description: - "Allow other nodes to find your server on the network.", + description: "Allow other nodes to find your server on the network.", default: true, }, onlyconnect: { @@ -245,8 +271,7 @@ writeConvertedFile( type: "number", nullable: true, name: "Port", - description: - "Port that peer is listening on for inbound p2p connections", + description: "Port that peer is listening on for inbound p2p connections", range: "[0,65535]", integral: true, }, @@ -270,8 +295,7 @@ writeConvertedFile( pruning: { type: "union", name: "Pruning Settings", - description: - "Blockchain Pruning Options\nReduce the blockchain size on disk\n", + description: "Blockchain Pruning Options\nReduce the blockchain size on disk\n", warning: "If you set pruning to Manual and your disk is smaller than the total size of the blockchain, you MUST have something running that prunes these blocks or you may overfill your disk!\nDisabling pruning will convert your node into a full archival node. This requires a resync of the entire blockchain, a process that may take several days. Make sure you have enough free disk space or you may fill up your disk.\n", tag: { @@ -293,8 +317,7 @@ writeConvertedFile( nullable: false, name: "Max Chain Size", description: "Limit of blockchain size on disk.", - warning: - "Increasing this value will require re-syncing your node.", + warning: "Increasing this value will require re-syncing your node.", default: 550, range: "[550,1000000)", integral: true, diff --git a/lib/test/output.test.ts b/lib/test/output.test.ts index 7874b5a..bbfcf2b 100644 --- a/lib/test/output.test.ts +++ b/lib/test/output.test.ts @@ -1,4 +1,4 @@ -import { unionSelectKey } from "../config/config-types"; +import { UnionSelectKey, unionSelectKey } from "../config/config-types"; import { InputSpec, matchInputSpec, threads } from "./output"; type IfEquals = (() => G extends T ? 1 : 2) extends () => G extends U ? 1 : 2 @@ -46,10 +46,20 @@ testOutput()(null); testOutput()(null); testOutput()(null); testOutput()(null); +testOutput()(null); +testOutput()(null); + +// @ts-expect-error Expect that the string is the one above +testOutput()(null); /// Here we test the output of the matchInputSpec function describe("Inputs", () => { const validInput: InputSpec = { + testListUnion: [ + { + [unionSelectKey]: { [unionSelectKey]: "lnd", name: "string" }, + }, + ], rpc: { enable: true, username: "test", diff --git a/scripts/oldSpecToBuilder.ts b/scripts/oldSpecToBuilder.ts index 360c059..9d5cfab 100644 --- a/scripts/oldSpecToBuilder.ts +++ b/scripts/oldSpecToBuilder.ts @@ -228,25 +228,37 @@ export default async function makeFileContent(inputData: Promise | any, { s value.name + "_variants", convertVariants(value.spec.variants, value.spec["variant-names"] || {}) ); + const unionValueName = newConst( + value.name + "_union", + ` + Value.union({ + name: ${JSON.stringify(value?.spec?.tag?.name || null)}, + description: ${JSON.stringify(value?.spec?.tag?.description || null)}, + warning: ${JSON.stringify(value?.spec?.tag?.warning || null)}, + variants: ${variants}, + nullable: ${JSON.stringify(value?.spec?.tag?.nullable || false)}, + default: ${JSON.stringify(value?.spec?.default || null)}, + }) + ` + ); + const listConfig = newConst( + value.name + "_list_config", + ` + Config.of({ + ${unionSelectKey}: ${unionValueName} + }) + ` + ); // @TODO BluJ return `List.obj({ name:${JSON.stringify(value.name || null)}, range:${JSON.stringify(value.range || null)}, spec: { - spec: { - ${unionSelectKey}: { - type: "union", - name: ${JSON.stringify(value?.spec?.tag?.name || null)}, - description: ${JSON.stringify(value?.spec?.tag?.description || null)}, - warning: ${JSON.stringify(value?.spec?.tag?.warning || null)}, - variants: ${variants}, - nullable: false, - } - } + spec: ${listConfig}, displayAs: ${JSON.stringify(value?.spec?.["display-as"] || null)}, uniqueBy: ${JSON.stringify(value?.spec?.["unique-by"] || null)}, }, - default: ${JSON.stringify(value.default || null)}, + default: [], description: ${JSON.stringify(value.description || null)}, warning: ${JSON.stringify(value.warning || null)}, })`;