From 24e2f1c8dd769c839f89f73a73534f6a6fbffa8c Mon Sep 17 00:00:00 2001 From: BluJ Date: Mon, 3 Apr 2023 10:19:04 -0600 Subject: [PATCH] chore: Update docs and get the test working --- lib/config/builder/config.ts | 482 ++----------------------------- lib/config/builder/index.test.ts | 1 - lib/config/builder/list.ts | 27 +- lib/config/builder/value.ts | 23 +- lib/config/builder/variants.ts | 70 +++-- scripts/oldSpecToBuilder.ts | 56 +--- 6 files changed, 107 insertions(+), 552 deletions(-) diff --git a/lib/config/builder/config.ts b/lib/config/builder/config.ts index ae39494..30f266e 100644 --- a/lib/config/builder/config.ts +++ b/lib/config/builder/config.ts @@ -31,455 +31,31 @@ import { Value } from "./value"; that works with bitcoin, like c-lightning. ```ts - export const enable = Value.boolean({ - "name": "Enable", - "default": true, - "description": "Allow remote RPC requests.", - "warning": null, - }); - export const username = Value.string({ - "name": "Username", - "default": "bitcoin", - "description": "The username for connecting to Bitcoin over RPC.", - "warning": null, - "nullable": false, - "masked": true, - "placeholder": null, - "pattern": "^[a-zA-Z0-9_]+$", - "pattern-description": "Must be alphanumeric (can contain underscore).", - "textarea": null, - }); - export const password = Value.string({ - "name": "RPC Password", - "default": { - "charset": "a-z,2-7", - "len": 20, - }, - "description": "The password for connecting to Bitcoin over RPC.", - "warning": null, - "nullable": false, - "masked": true, - "placeholder": null, - "pattern": '^[^\\n"]*$', - "pattern-description": "Must not contain newline or quote characters.", - "textarea": null, - }); - export const authorizationList = List.string({ - "name": "Authorization", - "range": "[0,*)", - "spec": { - "masked": null, - "placeholder": null, - "pattern": "^[a-zA-Z0-9_-]+:([0-9a-fA-F]{2})+\\$([0-9a-fA-F]{2})+$", - "pattern-description": - 'Each item must be of the form ":$".', - "textarea": false, - }, - "default": [], - "description": - "Username and hashed password for JSON-RPC connections. RPC clients connect using the usual http basic authentication.", - "warning": null, - }); - export const auth = Value.list(authorizationList); - export const serialversion = Value.select({ - "name": "Serialization Version", - "description": - "Return raw transaction or block hex with Segwit or non-SegWit serialization.", - "warning": null, - "default": "segwit", - "values": [ - "non-segwit", - "segwit", - ], - "value-names": {}, - }); - export const servertimeout = Value.number({ - "name": "Rpc Server Timeout", - "default": 30, - "description": - "Number of seconds after which an uncompleted RPC call will time out.", - "warning": null, - "nullable": false, - "range": "[5,300]", - "integral": true, - "units": "seconds", - "placeholder": null, - }); - export const threads = Value.number({ - "name": "Threads", - "default": 16, - "description": - "Set the number of threads for handling RPC calls. You may wish to increase this if you are making lots of calls via an integration.", - "warning": null, - "nullable": false, - "range": "[1,64]", - "integral": true, - "units": null, - "placeholder": null, - }); - export const workqueue = Value.number({ - "name": "Work Queue", - "default": 128, - "description": - "Set the depth of the work queue to service RPC calls. Determines how long the backlog of RPC requests can get before it just rejects new ones.", - "warning": null, - "nullable": false, - "range": "[8,256]", - "integral": true, - "units": "requests", - "placeholder": null, - }); - export const advancedSpec = Config.of({ - "auth": auth, - "serialversion": serialversion, - "servertimeout": servertimeout, - "threads": threads, - "workqueue": workqueue, - }); - export const advanced = Value.object({ - name: "Advanced", - description: "Advanced RPC Settings", - warning: null, - default: null, - "display-as": null, - "unique-by": null, - spec: advancedSpec, - "value-names": {}, - }); - export const rpcSettingsSpec = Config.of({ - "enable": enable, - "username": username, - "password": password, - "advanced": advanced, - }); - export const rpc = Value.object({ - name: "RPC Settings", - description: "RPC configuration options.", - warning: null, - default: null, - "display-as": null, - "unique-by": null, - spec: rpcSettingsSpec, - "value-names": {}, - }); - export const zmqEnabled = Value.boolean({ - "name": "ZeroMQ Enabled", - "default": true, - "description": "Enable the ZeroMQ interface", - "warning": null, - }); - export const txindex = Value.boolean({ - "name": "Transaction Index", - "default": true, - "description": "Enable the Transaction Index (txindex)", - "warning": null, - }); - export const enable1 = Value.boolean({ - "name": "Enable Wallet", - "default": true, - "description": "Load the wallet and enable wallet RPC calls.", - "warning": null, - }); - export const avoidpartialspends = Value.boolean({ - "name": "Avoid Partial Spends", - "default": true, - "description": - "Group outputs by address, selecting all or none, instead of selecting on a per-output basis. This improves privacy at the expense of higher transaction fees.", - "warning": null, - }); - export const discardfee = Value.number({ - "name": "Discard Change Tolerance", - "default": 0.0001, - "description": - "The fee rate (in BTC/kB) that indicates your tolerance for discarding change by adding it to the fee.", - "warning": null, - "nullable": false, - "range": "[0,.01]", - "integral": false, - "units": "BTC/kB", - "placeholder": null, - }); - export const walletSpec = Config.of({ - "enable": enable1, - "avoidpartialspends": avoidpartialspends, - "discardfee": discardfee, - }); - export const wallet = Value.object({ - name: "Wallet", - description: "Wallet Settings", - warning: null, - default: null, - "display-as": null, - "unique-by": null, - spec: walletSpec, - "value-names": {}, - }); - export const mempoolfullrbf = Value.boolean({ - "name": "Enable Full RBF", - "default": false, - "description": - "Policy for your node to use for relaying and mining unconfirmed transactions. For details, see https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes/release-notes-24.0.md#notice-of-new-option-for-transaction-replacement-policies", - "warning": null, - }); - export const persistmempool = Value.boolean({ - "name": "Persist Mempool", - "default": true, - "description": "Save the mempool on shutdown and load on restart.", - "warning": null, - }); - export const maxmempool = Value.number({ - "name": "Max Mempool Size", - "default": 300, - "description": "Keep the transaction memory pool below megabytes.", - "warning": null, - "nullable": false, - "range": "[1,*)", - "integral": true, - "units": "MiB", - "placeholder": null, - }); - export const mempoolexpiry = Value.number({ - "name": "Mempool Expiration", - "default": 336, - "description": - "Do not keep transactions in the mempool longer than hours.", - "warning": null, - "nullable": false, - "range": "[1,*)", - "integral": true, - "units": "Hr", - "placeholder": null, - }); - export const mempoolSpec = Config.of({ - "mempoolfullrbf": mempoolfullrbf, - "persistmempool": persistmempool, - "maxmempool": maxmempool, - "mempoolexpiry": mempoolexpiry, - }); - export const mempool = Value.object({ - name: "Mempool", - description: "Mempool Settings", - warning: null, - default: null, - "display-as": null, - "unique-by": null, - spec: mempoolSpec, - "value-names": {}, - }); - export const listen = Value.boolean({ - "name": "Make Public", - "default": true, - "description": "Allow other nodes to find your server on the network.", - "warning": null, - }); - export const onlyconnect = Value.boolean({ - "name": "Disable Peer Discovery", - "default": false, - "description": "Only connect to specified peers.", - "warning": null, - }); - export const onlyonion = Value.boolean({ - "name": "Disable Clearnet", - "default": false, - "description": "Only connect to peers over Tor.", - "warning": null, - }); export const hostname = Value.string({ - "name": "Hostname", - "default": null, - "description": "Domain or IP address of bitcoin peer", - "warning": null, - "nullable": false, - "masked": null, - "placeholder": null, - "pattern": - "(^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$)|((^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$)|(^[a-z2-7]{16}\\.onion$)|(^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$))", - "pattern-description": - "Must be either a domain name, or an IPv4 or IPv6 address. Do not include protocol scheme (eg 'http://') or port.", - "textarea": null, - }); - export const port = Value.number({ - "name": "Port", - "default": null, - "description": "Port that peer is listening on for inbound p2p connections", - "warning": null, - "nullable": true, - "range": "[0,65535]", - "integral": true, - "units": null, - "placeholder": null, - }); - export const addNodesSpec = Config.of({ "hostname": hostname, "port": port }); - export const addNodesList = List.obj({ - name: "Add Nodes", - range: "[0,*)", - spec: { - spec: addNodesSpec, - "display-as": null, - "unique-by": null, - }, - default: [], - description: "Add addresses of nodes to connect to.", - warning: null, - }); - export const addnode = Value.list(addNodesList); - export const peersSpec = Config.of({ - "listen": listen, - "onlyconnect": onlyconnect, - "onlyonion": onlyonion, - "addnode": addnode, - }); - export const peers = Value.object({ - name: "Peers", - description: "Peer Connection Settings", - warning: null, - default: null, - "display-as": null, - "unique-by": null, - spec: peersSpec, - "value-names": {}, - }); - export const dbcache = Value.number({ - "name": "Database Cache", - "default": null, - "description": - "How much RAM to allocate for caching the TXO set. Higher values improve syncing performance, but increase your chance of using up all your system's memory or corrupting your database in the event of an ungraceful shutdown. Set this high but comfortably below your system's total RAM during IBD, then turn down to 450 (or leave blank) once the sync completes.", - "warning": - "WARNING: Increasing this value results in a higher chance of ungraceful shutdowns, which can leave your node unusable if it happens during the initial block download. Use this setting with caution. Be sure to set this back to the default (450 or leave blank) once your node is synced. DO NOT press the STOP button if your dbcache is large. Instead, set this number back to the default, hit save, and wait for bitcoind to restart on its own.", - "nullable": true, - "range": "(0,*)", - "integral": true, - "units": "MiB", - "placeholder": null, - }); - export const disabled = Config.of({}); - export const size = Value.number({ - "name": "Max Chain Size", - "default": 550, - "description": "Limit of blockchain size on disk.", - "warning": "Increasing this value will require re-syncing your node.", - "nullable": false, - "range": "[550,1000000)", - "integral": true, - "units": "MiB", - "placeholder": null, - }); - export const automatic = Config.of({ "size": size }); - export const size1 = Value.number({ - "name": "Failsafe Chain Size", - "default": 65536, - "description": "Prune blockchain if size expands beyond this.", - "warning": null, - "nullable": false, - "range": "[550,1000000)", - "integral": true, - "units": "MiB", - "placeholder": null, - }); - export const manual = Config.of({ "size": size1 }); - export const pruningSettingsVariants = Variants.of({ - "disabled": disabled, - "automatic": automatic, - "manual": manual, - }); - export const pruning = Value.union({ - name: "Pruning Settings", - 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", - default: "disabled", - variants: pruningSettingsVariants, - tag: { - "id": "mode", - "name": "Pruning Mode", - "description": - '- Disabled: Disable pruning\n- Automatic: Limit blockchain size on disk to a certain number of megabytes\n- Manual: Prune blockchain with the "pruneblockchain" RPC\n', - "warning": null, - "variant-names": { - "disabled": "Disabled", - "automatic": "Automatic", - "manual": "Manual", - }, - }, - "display-as": null, - "unique-by": null, - "variant-names": null, - }); - export const blockfilterindex = Value.boolean({ - "name": "Compute Compact Block Filters (BIP158)", - "default": true, - "description": - "Generate Compact Block Filters during initial sync (IBD) to enable 'getblockfilter' RPC. This is useful if dependent services need block filters to efficiently scan for addresses/transactions etc.", - "warning": null, - }); - export const peerblockfilters = Value.boolean({ - "name": "Serve Compact Block Filters to Peers (BIP157)", - "default": false, - "description": - "Serve Compact Block Filters as a peer service to other nodes on the network. This is useful if you wish to connect an SPV client to your node to make it efficient to scan transactions without having to download all block data. 'Compute Compact Block Filters (BIP158)' is required.", - "warning": null, - }); - export const blockFiltersSpec = Config.of({ - "blockfilterindex": blockfilterindex, - "peerblockfilters": peerblockfilters, - }); - export const blockfilters = Value.object({ - name: "Block Filters", - description: "Settings for storing and serving compact block filters", - warning: null, - default: null, - "display-as": null, - "unique-by": null, - spec: blockFiltersSpec, - "value-names": {}, - }); - export const peerbloomfilters = Value.boolean({ - "name": "Serve Bloom Filters to Peers", - "default": false, - "description": - "Peers have the option of setting filters on each connection they make after the version handshake has completed. Bloom filters are for clients implementing SPV (Simplified Payment Verification) that want to check that block headers connect together correctly, without needing to verify the full blockchain. The client must trust that the transactions in the chain are in fact valid. It is highly recommended AGAINST using for anything except Bisq integration.", - "warning": - "This is ONLY for use with Bisq integration, please use Block Filters for all other applications.", - }); - export const bloomFiltersBip37Spec = Config.of({ - "peerbloomfilters": peerbloomfilters, - }); - export const bloomfilters = Value.object({ - name: "Bloom Filters (BIP37)", - description: "Setting for serving Bloom Filters", - warning: null, - default: null, - "display-as": null, - "unique-by": null, - spec: bloomFiltersBip37Spec, - "value-names": {}, - }); - export const advancedSpec1 = Config.of({ - "mempool": mempool, - "peers": peers, - "dbcache": dbcache, - "pruning": pruning, - "blockfilters": blockfilters, - "bloomfilters": bloomfilters, - }); - export const advanced1 = Value.object({ - name: "Advanced", - description: "Advanced Settings", - warning: null, - default: null, - "display-as": null, - "unique-by": null, - spec: advancedSpec1, - "value-names": {}, - }); - export const config = Config.of({ - "rpc": rpc, - "zmq-enabled": zmqEnabled, - "txindex": txindex, - "wallet": wallet, - "advanced": advanced1, - }); + name: "Hostname", + default: null, + description: "Domain or IP address of bitcoin peer", + warning: null, + required: true, + masked: false, + placeholder: null, + pattern: + "(^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$)|((^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$)|(^[a-z2-7]{16}\\.onion$)|(^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$))", + patternDescription: + "Must be either a domain name, or an IPv4 or IPv6 address. Do not include protocol scheme (eg 'http://') or port.", +}); +export const port = Value.number({ + name: "Port", + default: null, + description: "Port that peer is listening on for inbound p2p connections", + warning: null, + required: false, + range: "[0,65535]", + integral: true, + units: null, + placeholder: null, +}); +export const addNodesSpec = Config.of({ hostname: hostname, port: port }); ``` */ @@ -487,16 +63,10 @@ export class Config extends IBuilder { static empty() { return new Config({}); } - static withValue( - key: K, - value: Value - ) { + static withValue(key: K, value: Value) { return Config.empty().withValue(key, value); } - static addValue( - key: K, - value: Value - ) { + static addValue(key: K, value: Value) { return Config.empty().withValue(key, value); } diff --git a/lib/config/builder/index.test.ts b/lib/config/builder/index.test.ts index a3a8df3..bebc368 100644 --- a/lib/config/builder/index.test.ts +++ b/lib/config/builder/index.test.ts @@ -12,7 +12,6 @@ describe("test", () => { describe("builder tests", () => { test("String", () => { - console.log("BLUJ->"); const bitcoinPropertiesBuilt: { "peer-tor-address": { name: string; diff --git a/lib/config/builder/list.ts b/lib/config/builder/list.ts index e93f539..901d67d 100644 --- a/lib/config/builder/list.ts +++ b/lib/config/builder/list.ts @@ -1,14 +1,20 @@ import { BuilderExtract, IBuilder } from "./builder"; import { Config } from "./config"; -import { - InputSpec, - ListValueSpecNumber, - ListValueSpecString, - UniqueBy, - ValueSpecList, -} from "../config-types"; +import { InputSpec, ListValueSpecNumber, ListValueSpecString, UniqueBy, ValueSpecList } from "../config-types"; import { guardAll } from "../../util"; - +/** + * Used as a subtype of Value.list +```ts +export const authorizationList = List.string({ + "name": "Authorization", + "range": "[0,*)", + "default": [], + "description": "Username and hashed password for JSON-RPC connections. RPC clients connect using the usual http basic authentication.", + "warning": null +}, {"masked":false,"placeholder":null,"pattern":"^[a-zA-Z0-9_-]+:([0-9a-fA-F]{2})+\\$([0-9a-fA-F]{2})+$","patternDescription":"Each item must be of the form \":$\"."}); +export const auth = Value.list(authorizationList); +``` +*/ export class List extends IBuilder { static string( a: { @@ -31,7 +37,7 @@ export class List extends IBuilder { } ) { const spec = { - type: 'string' as const, + type: "string" as const, placeholder: null, pattern: null, patternDescription: null, @@ -65,6 +71,8 @@ export class List extends IBuilder { range?: string; units?: string | null; placeholder?: string | null; + /** Default = 'numeric */ + inputmode?: "numeric" | "decimal"; } ) { const spec = { @@ -72,6 +80,7 @@ export class List extends IBuilder { placeholder: null, range: "(*,*)", units: null, + inputmode: "numeric" as const, ...aSpec, }; return new List({ diff --git a/lib/config/builder/value.ts b/lib/config/builder/value.ts index 37351c6..0b08dc0 100644 --- a/lib/config/builder/value.ts +++ b/lib/config/builder/value.ts @@ -21,18 +21,17 @@ import { DefaultString } from "../config-types"; * Keep an eye out for another config builder types as params. * Note, usually this is going to be used in a `Config` {@link Config} builder. ```ts - Value.string({ - name: "Name of This Value", - description: "Going to be what the description is in the FE, hover over", - warning: "What the warning is going to be on warning situations", - default: null, - nullable: false, - masked: null, // If there is a masked, then the value is going to be masked in the FE, like a password - placeholder: null, // If there is a placeholder, then the value is going to be masked in the FE, like a password - pattern: null, // A regex pattern to validate the value - patternDescription: null, - textarea: null - }) +const username = Value.string({ + name: "Username", + default: "bitcoin", + description: "The username for connecting to Bitcoin over RPC.", + warning: null, + required: true, + masked: true, + placeholder: null, + pattern: "^[a-zA-Z0-9_]+$", + patternDescription: "Must be alphanumeric (can contain underscore).", +}); ``` */ export class Value extends IBuilder { diff --git a/lib/config/builder/variants.ts b/lib/config/builder/variants.ts index 9be91ef..8efe5eb 100644 --- a/lib/config/builder/variants.ts +++ b/lib/config/builder/variants.ts @@ -7,35 +7,48 @@ import { Config } from "."; * to indicate the type of select variants that are available. The key for the record passed in will be the * key to the tag.id in the Value.select ```ts - export const pruningSettingsVariants = Variants.of({ - "disabled": disabled, - "automatic": automatic, - "manual": manual, - }); - export const pruning = Value.union({ + +export const disabled = Config.of({}); +export const size = Value.number({ + name: "Max Chain Size", + default: 550, + description: "Limit of blockchain size on disk.", + warning: "Increasing this value will require re-syncing your node.", + required: true, + range: "[550,1000000)", + integral: true, + units: "MiB", + placeholder: null, +}); +export const automatic = Config.of({ size: size }); +export const size1 = Value.number({ + name: "Failsafe Chain Size", + default: 65536, + description: "Prune blockchain if size expands beyond this.", + warning: null, + required: true, + range: "[550,1000000)", + integral: true, + units: "MiB", + placeholder: null, +}); +export const manual = Config.of({ size: size1 }); +export const pruningSettingsVariants = Variants.of({ + disabled: { name: "Disabled", spec: disabled }, + automatic: { name: "Automatic", spec: automatic }, + manual: { name: "Manual", spec: manual }, +}); +export const pruning = Value.union( + { name: "Pruning Settings", 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", + '- Disabled: Disable pruning\n- Automatic: Limit blockchain size on disk to a certain number of megabytes\n- Manual: Prune blockchain with the "pruneblockchain" RPC\n', + warning: null, + required: true, default: "disabled", - variants: pruningSettingsVariants, - tag: { - "id": "mode", - "name": "Pruning Mode", - "description": - '- Disabled: Disable pruning\n- Automatic: Limit blockchain size on disk to a certain number of megabytes\n- Manual: Prune blockchain with the "pruneblockchain" RPC\n', - "warning": null, - "variantNames": { - "disabled": "Disabled", - "automatic": "Automatic", - "manual": "Manual", - }, - }, - "displayAs": null, - "uniqueBy": null, - "variantNames": null, - }); + }, + pruningSettingsVariants +); ``` */ export class Variants< @@ -67,10 +80,7 @@ export class Variants< static empty() { return Variants.of({}); } - static withVariant( - key: K, - value: Config - ) { + static withVariant(key: K, value: Config) { return Variants.empty().withVariant(key, value); } diff --git a/scripts/oldSpecToBuilder.ts b/scripts/oldSpecToBuilder.ts index 34d6eba..f84a251 100644 --- a/scripts/oldSpecToBuilder.ts +++ b/scripts/oldSpecToBuilder.ts @@ -8,15 +8,10 @@ export async function writeConvertedFile( inputData: Promise | any, options: Parameters[1] ) { - await fs.writeFile(file, await makeFileContent(inputData, options), (err) => - console.error(err) - ); + await fs.writeFile(file, await makeFileContent(inputData, options), (err) => console.error(err)); } -export default async function makeFileContent( - inputData: Promise | any, - { startSdk = "start-sdk" } = {} -) { +export default async function makeFileContent(inputData: Promise | any, { startSdk = "start-sdk" } = {}) { const outputLines: string[] = []; outputLines.push(` import {Config, Value, List, Variants} from '${startSdk}/config/builder'; @@ -25,13 +20,8 @@ export default async function makeFileContent( const namedConsts = new Set(["Config", "Value", "List"]); const configName = newConst("InputSpec", convertInputSpec(data)); - const configMatcherName = newConst( - "matchInputSpec", - `${configName}.validator()` - ); - outputLines.push( - `export type InputSpec = typeof ${configMatcherName}._TYPE;` - ); + const configMatcherName = newConst("matchInputSpec", `${configName}.validator()`); + outputLines.push(`export type InputSpec = typeof ${configMatcherName}._TYPE;`); return outputLines.join("\n"); @@ -111,10 +101,7 @@ export default async function makeFileContent( )})`; } case "enum": { - const allValueNames = new Set([ - ...(value?.["values"] || []), - ...Object.keys(value?.["value-names"] || {}), - ]); + const allValueNames = new Set([...(value?.["values"] || []), ...Object.keys(value?.["value-names"] || {})]); const values = Object.fromEntries( Array.from(allValueNames) .filter(string.test) @@ -134,10 +121,7 @@ export default async function makeFileContent( )} as const)`; } case "object": { - const specName = newConst( - value.name + "_spec", - convertInputSpec(value.spec) - ); + const specName = newConst(value.name + "_spec", convertInputSpec(value.spec)); return `Value.object({ name: ${JSON.stringify(value.name || null)}, description: ${JSON.stringify(value.description || null)}, @@ -174,9 +158,7 @@ export default async function makeFileContent( function convertList(value: any) { switch (value.subtype) { case "string": { - return `List.${ - value?.spec?.textarea === true ? "textarea" : "string" - }(${JSON.stringify( + return `List.${value?.spec?.textarea === true ? "textarea" : "string"}(${JSON.stringify( { name: value.name || null, range: value.range || null, @@ -235,10 +217,7 @@ export default async function makeFileContent( )})`; } case "object": { - const specName = newConst( - value.name + "_spec", - convertInputSpec(value.spec.spec) - ); + const specName = newConst(value.name + "_spec", convertInputSpec(value.spec.spec)); return `List.obj({ name: ${JSON.stringify(value.name || null)}, range: ${JSON.stringify(value.range || null)}, @@ -254,19 +233,14 @@ export default async function makeFileContent( case "union": { const variants = newConst( value.name + "_variants", - convertVariants( - value.spec.variants, - value.spec["variant-names"] || {} - ) + 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 - )}, + description: ${JSON.stringify(value?.spec?.tag?.description || null)}, warning: ${JSON.stringify(value?.spec?.tag?.warning || null)}, required: ${JSON.stringify(!(value?.spec?.tag?.nullable || false))}, default: ${JSON.stringify(value?.spec?.default || null)}, @@ -281,7 +255,6 @@ export default async function makeFileContent( }) ` ); - // @TODO BluJ return `List.obj({ name:${JSON.stringify(value.name || null)}, range:${JSON.stringify(value.range || null)}, @@ -298,16 +271,11 @@ export default async function makeFileContent( throw new Error(`Unknown subtype "${value.subtype}"`); } - function convertVariants( - variants: Record, - variantNames: Record - ): string { + function convertVariants(variants: Record, variantNames: Record): string { let answer = "Variants.of({"; for (const [key, value] of Object.entries(variants)) { const variantSpec = newConst(key, convertInputSpec(value)); - answer += `"${key}": {name: "${ - variantNames[key] || key - }", spec: ${variantSpec}},`; + answer += `"${key}": {name: "${variantNames[key] || key}", spec: ${variantSpec}},`; } return `${answer}})`; }