feat(doc): the field rule for a modem's code, which the sheet's commit left behind

87c09c6 uses rule "modemCode" and setModemCode through it; both lived in
these two files, which that commit did not take.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-11 18:35:03 +00:00
co-authored by Claude Opus 5.5
parent 87c09c6c9d
commit b4e0046a09
2 changed files with 9 additions and 8 deletions
+8 -2
View File
@@ -18,7 +18,7 @@
// " 10.0.0.1"; a phone's keyboard puts a space after a word). A name and an
// SSID are taken as typed, spaces included, as Java takes them.
import { DIRECTLY_CONNECTED_SOURCE_MARKER, IP_ADDRESS_PATTERN, javaIpCheck, parseIPv4 } from '@mdg-filius/core';
import { DIRECTLY_CONNECTED_SOURCE_MARKER, IP_ADDRESS_PATTERN, javaIpCheck, modemCodeOf, parseIPv4 } from '@mdg-filius/core';
export type FieldRule =
| 'name'
@@ -34,7 +34,9 @@ export type FieldRule =
/** A firewall rule's mask: empty, or ones then zeros (EingabenUeberpruefung.isValidSubnetmask). */
| 'firewallMask'
/** A firewall rule's port: empty for all ports, or musterPort. */
| 'portOrEmpty';
| 'portOrEmpty'
/** The code of another project's modem (modemCodeOf: six characters, spaces, dashes and small letters allowed). */
| 'modemCode';
/** What a field's text comes to: the value the device takes, or that it takes none. */
export type CheckedField = { readonly value: string } | { readonly invalid: true };
@@ -97,6 +99,10 @@ export function checkField(rule: FieldRule, text: string): CheckedField {
}
case 'portOrEmpty':
return text.trim() === '' ? { value: '' } : checkField('port', text);
case 'modemCode': {
const code = modemCodeOf(text);
return code === undefined ? INVALID : { value: code };
}
case 'macAddress':
// Upper case, as the model keeps MAC addresses (Java keeps them as typed and compares ignoring case).
return MAC_ADDRESS_PATTERN.test(text.trim()) ? { value: text.trim().toUpperCase() } : INVALID;
+1 -6
View File
@@ -41,7 +41,6 @@ import {
firewallConfiguration,
firewallRule,
forwardsIPv4ByDefault,
modemCodeOf,
type FirewallAction,
type FirewallProtocol,
type DhcpStaticAssignment,
@@ -251,11 +250,7 @@ export function setModemConnection(doc: Y.Doc, id: Id, connection: ModemConnecti
/** The code of the modem a joining modem connects to, as typed (spaces, dashes, small letters allowed); refused when it is no code. */
export function setModemCode(doc: Y.Doc, id: Id, text: string, origin: unknown): CheckedField {
const node = nodes(doc).get(id);
const code = modemCodeOf(text);
if (node === undefined || code === undefined) return { invalid: true };
doc.transact(() => modemSetting(node).set('relay', toY({ role: 'join', code })), origin);
return { value: code };
return setChecked(doc, id, checkField('modemCode', text), (node, code) => modemSetting(node).set('relay', toY({ role: 'join', code })), origin);
}
const portsOf = (node: Y.Map<unknown>) => node.get('ports') as Y.Array<Y.Map<unknown>>;