mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-05-12 13:29:42 +00:00
* Add createNode(preset, mode, overrides, additions) nim api * Set p2pTcp/discv5Udp/websocket ports to 0 (auto-bind) in new createNode() * Soft-deprecate --cluster-id=N triggering the associated preset selection * Rewrite applyNetworkConf to apply user-set fields over preset fields * Generate WakuNodeConfOverlay (all Option fields) from WakuNodeConf * New parser for configJson handles new messaging shape and full conf shape * Change all confbuilder defaults from literal values to DefaultXXX consts * Change int/bool WakuNodeConf fields to Option to get user intent w/o sentinels * Make Option CLI default-value help mention defaults now owned by confbuilder * Misc refactors, fixes * Add tests
41 lines
1.6 KiB
Nim
41 lines
1.6 KiB
Nim
{.push raises: [].}
|
|
|
|
import std/options
|
|
import results
|
|
import ./cli_args
|
|
import ./optionalize
|
|
|
|
const WakuNodeConfOverlayExcludes* = ["cmd", "execute"]
|
|
## Variant-safety: `cmd` is the CLI subcommand discriminator (not dispatched
|
|
## on by the library) and `execute` lives in its inactive branch. Excluded
|
|
## from the overlay AND used as the JSON parser's hard-reject list.
|
|
|
|
# Generates the WakuNodeConfOverlay type from the WakuNodeConf type.
|
|
# The generated type converts fields from type T to Option[T] if T != Option.
|
|
# Skips fields that are in WakuNodeConfOverlayExcludes.
|
|
optionalizeType(WakuNodeConfOverlay, WakuNodeConf, WakuNodeConfOverlayExcludes)
|
|
|
|
proc init*(T: type WakuNodeConfOverlay): WakuNodeConfOverlay =
|
|
## Default config overlay where every field is `none`.
|
|
return WakuNodeConfOverlay()
|
|
|
|
proc applyAsOverride*(conf: var WakuNodeConf, overlay: WakuNodeConfOverlay) =
|
|
## For all fields, overlay.some() overrides field of same name in conf.
|
|
for confName, confValue in fieldPairs(conf):
|
|
for ovName, ovValue in fieldPairs(overlay):
|
|
when confName == ovName:
|
|
if ovValue.isSome():
|
|
when typeof(confValue) is Option:
|
|
confValue = ovValue
|
|
else:
|
|
confValue = ovValue.get()
|
|
|
|
proc applyAsAddition*(conf: var WakuNodeConf, overlay: WakuNodeConfOverlay) =
|
|
## For all seq fields, overlay.some() concats to field of same name in conf.
|
|
for confName, confValue in fieldPairs(conf):
|
|
for ovName, ovValue in fieldPairs(overlay):
|
|
when confName == ovName:
|
|
when typeof(confValue) is seq:
|
|
if ovValue.isSome() and ovValue.get().len > 0:
|
|
confValue = confValue & ovValue.get()
|