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:
@@ -18,7 +18,7 @@
|
|||||||
// " 10.0.0.1"; a phone's keyboard puts a space after a word). A name and an
|
// " 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.
|
// 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 =
|
export type FieldRule =
|
||||||
| 'name'
|
| 'name'
|
||||||
@@ -34,7 +34,9 @@ export type FieldRule =
|
|||||||
/** A firewall rule's mask: empty, or ones then zeros (EingabenUeberpruefung.isValidSubnetmask). */
|
/** A firewall rule's mask: empty, or ones then zeros (EingabenUeberpruefung.isValidSubnetmask). */
|
||||||
| 'firewallMask'
|
| 'firewallMask'
|
||||||
/** A firewall rule's port: empty for all ports, or musterPort. */
|
/** 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. */
|
/** 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 };
|
export type CheckedField = { readonly value: string } | { readonly invalid: true };
|
||||||
@@ -97,6 +99,10 @@ export function checkField(rule: FieldRule, text: string): CheckedField {
|
|||||||
}
|
}
|
||||||
case 'portOrEmpty':
|
case 'portOrEmpty':
|
||||||
return text.trim() === '' ? { value: '' } : checkField('port', text);
|
return text.trim() === '' ? { value: '' } : checkField('port', text);
|
||||||
|
case 'modemCode': {
|
||||||
|
const code = modemCodeOf(text);
|
||||||
|
return code === undefined ? INVALID : { value: code };
|
||||||
|
}
|
||||||
case 'macAddress':
|
case 'macAddress':
|
||||||
// Upper case, as the model keeps MAC addresses (Java keeps them as typed and compares ignoring case).
|
// 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;
|
return MAC_ADDRESS_PATTERN.test(text.trim()) ? { value: text.trim().toUpperCase() } : INVALID;
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ import {
|
|||||||
firewallConfiguration,
|
firewallConfiguration,
|
||||||
firewallRule,
|
firewallRule,
|
||||||
forwardsIPv4ByDefault,
|
forwardsIPv4ByDefault,
|
||||||
modemCodeOf,
|
|
||||||
type FirewallAction,
|
type FirewallAction,
|
||||||
type FirewallProtocol,
|
type FirewallProtocol,
|
||||||
type DhcpStaticAssignment,
|
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. */
|
/** 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 {
|
export function setModemCode(doc: Y.Doc, id: Id, text: string, origin: unknown): CheckedField {
|
||||||
const node = nodes(doc).get(id);
|
return setChecked(doc, id, checkField('modemCode', text), (node, code) => modemSetting(node).set('relay', toY({ role: 'join', code })), origin);
|
||||||
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 };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const portsOf = (node: Y.Map<unknown>) => node.get('ports') as Y.Array<Y.Map<unknown>>;
|
const portsOf = (node: Y.Map<unknown>) => node.get('ports') as Y.Array<Y.Map<unknown>>;
|
||||||
|
|||||||
Reference in New Issue
Block a user