link-cli 3.5.2

A CLI tool and reusable library for links manipulation backed by a LiNo-notation doublet storage engine.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
//! The links interface (`ILinks` in C#, [`doublets::Links`] in Rust) as LiNo
//! documents, so a store behind a [`LinksServer`](super::LinksServer) is used
//! exactly like a local one through [`RemoteLinks`](super::RemoteLinks).
//!
//! Every request is one top-level link named after the operation and holding
//! exactly one value. The substitution query language ignores that shape (a
//! query needs a restriction *and* a substitution), so an operation never
//! collides with a query sent to the same server.
//!
//! | Request                          | Reply                                  |
//! |----------------------------------|----------------------------------------|
//! | `(count: (index source target))` | `(count: N)`                           |
//! | `(each: (index source target))`  | one `(index: source target)` per match |
//! | `(create: (source target))`      | `() ((index: source target))`          |
//! | `(update: (index source target))`| `((index: s t)) ((index: source target))` per changed link |
//! | `(delete: index)`                | `((index: source target)) ()` per removed link |
//! | `(get-name: link)`               | `(name: 'text')`, or nothing           |
//! | `(set-name: (link 'text'))`      | `(link: N)`                            |
//! | `(get-by-name: 'text')`          | `(link: N)`, or nothing                |
//! | `(remove-name: link)`            | nothing                                |
//! | `(subscribe: (index source target))` | `(subscription: N)`; later pushes of `(notify: N)` and its changes |
//! | `(unsubscribe: N)`               | nothing                                |
//!
//! A restriction holds up to three parts, matched like the raw links
//! interface matches a query: none matches every link, `(index)` one link,
//! `(index value)` links of that index whose source or target is `value`,
//! and `(index source target)` matches part by part. `*` matches anything.
//! Every reference in a reply is a number; failures are `(error: 'message')`.
//!
//! The changes of a `create`, `update` or `delete` are the net change of every
//! link it touched, the way `clink --changes` reports a query: a cascading
//! delete is one `((index: source target)) ()` per removed link, without the
//! intermediate steps by which the store behind the server got there, which
//! differ between the C# and the Rust stores.
//!
//! A subscription belongs to the connection that made it: once a connection
//! sent `(subscribe: restriction)`, the server pushes it every later change
//! another connection makes to a matching link, as `(notify: N)` followed by
//! the `(before) (after)` lines of the change. A side that does not match is
//! left empty, so a link that leaves the subscription arrives as a deletion.

use super::error::{ProtocolError, ProtocolResult};
use crate::changes_simplifier::simplify_generic_changes;
use crate::link::{GenericLink, Link};
use crate::named_type_links::NamedTypeLinks;
use crate::query_address::QueryAddress;
use links_notation::binary::{format_document, format_link, LinoDocument};
use links_notation::LiNo;

/// The wire spelling of "any value" in a restriction.
pub const ANY: &str = "*";

/// One part of a restriction: `None` matches any value.
pub type Part<T = u32> = Option<T>;

/// One call of the links interface.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum GenericLinksOperation<T> {
    /// Number of links matching the restriction.
    Count(Vec<Part<T>>),
    /// Every link matching the restriction, ordered by index.
    Each(Vec<Part<T>>),
    /// Creates a link.
    Create { source: T, target: T },
    /// Points an existing link at a new source and target; an update that
    /// would duplicate an existing link merges into it instead.
    Update { index: T, source: T, target: T },
    /// Deletes a link, and every link that still refers to it.
    Delete(T),
    /// The name of a link.
    GetName(T),
    /// Names a link.
    SetName(T, String),
    /// The link with a name.
    GetByName(String),
    /// Removes the name of a link.
    RemoveName(T),
    /// Asks a [`LinksServer`](super::LinksServer) to push the changes other
    /// connections make to the links matching the restriction; the reply is
    /// `(subscription: N)` and every later push a [`notification_document`].
    ///
    /// A subscription belongs to the connection that made it: only the server
    /// can run it, so [`execute`](Self::execute) on a store fails.
    Subscribe(Vec<Part<T>>),
    /// Stops a subscription of this connection; the reply is empty, even for
    /// an unknown number.
    Unsubscribe(T),
}

/// A change a [`LinksServer`](super::LinksServer) pushed to a subscriber: the
/// subscription it fits and its changes, a missing side being [`Link::null`].
///
/// Each side is the link as the subscription sees it: a side that does not fit
/// the restriction (or that the subscriber may not read) is the null link, so a
/// link that leaves the subscription arrives as a deletion and one that comes
/// into it as a creation.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LinksNotification {
    /// The number the `subscribe` reply gave.
    pub subscription: u32,
    /// The `(before, after)` changes.
    pub changes: Vec<Change>,
}

/// A `(before, after)` change; a missing side is [`GenericLink::null`].
pub type Change<T = u32> = (GenericLink<T>, GenericLink<T>);

/// The existing u32 links operation facade.
pub type LinksOperation = GenericLinksOperation<u32>;

impl<T: QueryAddress> GenericLinksOperation<T> {
    /// The request document for this operation.
    pub fn to_document(&self) -> LinoDocument {
        let (name, argument) = match self {
            Self::Count(restriction) => ("count", restriction_lino(restriction)),
            Self::Each(restriction) => ("each", restriction_lino(restriction)),
            Self::Create { source, target } => ("create", numbers_lino(&[*source, *target])),
            Self::Update {
                index,
                source,
                target,
            } => ("update", numbers_lino(&[*index, *source, *target])),
            Self::Delete(index) => ("delete", number(*index)),
            Self::GetName(index) => ("get-name", number(*index)),
            Self::SetName(index, name) => (
                "set-name",
                group(vec![number(*index), LiNo::Ref(name.clone())]),
            ),
            Self::GetByName(name) => ("get-by-name", LiNo::Ref(name.clone())),
            Self::RemoveName(index) => ("remove-name", number(*index)),
            Self::Subscribe(restriction) => ("subscribe", restriction_lino(restriction)),
            Self::Unsubscribe(subscription) => ("unsubscribe", number(*subscription)),
        };
        vec![named(name, vec![argument])]
    }

    /// Recognises an operation request; `Ok(None)` for any other document,
    /// such as a substitution query.
    pub fn from_document(document: &[LiNo<String>]) -> ProtocolResult<Option<Self>> {
        let [LiNo::Link {
            id: Some(name),
            values,
        }] = document
        else {
            return Ok(None);
        };
        let [argument] = values.as_slice() else {
            return Ok(None);
        };
        let operation = match name.as_str() {
            "count" => Self::Count(parse_restriction(argument)?),
            "each" => Self::Each(parse_restriction(argument)?),
            "create" => {
                let [source, target] = parse_numbers_for::<T, 2>(argument)?;
                Self::Create { source, target }
            }
            "update" => {
                let [index, source, target] = parse_numbers_for::<T, 3>(argument)?;
                Self::Update {
                    index,
                    source,
                    target,
                }
            }
            "delete" => Self::Delete(parse_number(argument)?),
            "get-name" => Self::GetName(parse_number(argument)?),
            "set-name" => match parts(argument) {
                [index, LiNo::Ref(name)] => Self::SetName(parse_number(index)?, name.clone()),
                _ => return Err(malformed_argument("set-name", argument)),
            },
            "get-by-name" => match argument {
                LiNo::Ref(name) => Self::GetByName(name.clone()),
                _ => return Err(malformed_argument("get-by-name", argument)),
            },
            "remove-name" => Self::RemoveName(parse_number(argument)?),
            "subscribe" => Self::Subscribe(parse_restriction(argument)?),
            "unsubscribe" => Self::Unsubscribe(parse_number(argument)?),
            _ => return Ok(None),
        };
        Ok(Some(operation))
    }

    /// Runs the operation against `storage` and returns the reply document.
    pub fn execute<S: NamedTypeLinks<T> + ?Sized>(
        &self,
        storage: &mut S,
    ) -> anyhow::Result<LinoDocument> {
        if let Some(limits) = storage.query_limits() {
            match self {
                Self::Count(parts) | Self::Each(parts) | Self::Subscribe(parts) => {
                    anyhow::ensure!(parts.len() <= 3, "expected at most three restriction parts")
                }
                Self::SetName(_, name) | Self::GetByName(name) => anyhow::ensure!(
                    name.len() <= limits.max_bytes,
                    "protocol byte limit exceeded"
                ),
                _ => {}
            }
            let addresses: Vec<T> = match self {
                Self::Count(parts) | Self::Each(parts) | Self::Subscribe(parts) => {
                    parts.iter().flatten().copied().collect()
                }
                Self::Create { source, target } => vec![*source, *target],
                Self::Update {
                    index,
                    source,
                    target,
                } => vec![*index, *source, *target],
                Self::Delete(index)
                | Self::GetName(index)
                | Self::SetName(index, _)
                | Self::RemoveName(index)
                | Self::Unsubscribe(index) => vec![*index],
                Self::GetByName(_) => Vec::new(),
            };
            anyhow::ensure!(
                addresses.iter().all(|value| value
                    .to_u128()
                    .is_some_and(|value| value <= limits.max_address)),
                "protocol address out of range"
            );
        }
        Ok(match self {
            Self::Count(restriction) => {
                let count = matching(storage, restriction).len();
                vec![named("count", vec![LiNo::Ref(count.to_string())])]
            }
            Self::Each(restriction) => {
                let links = matching(storage, restriction);
                if let Some(limits) = storage.query_limits() {
                    anyhow::ensure!(
                        links.len() <= limits.max_results,
                        "protocol result limit exceeded"
                    );
                }
                links.iter().map(link_lino).collect()
            }
            Self::Create { source, target } => {
                // `create` makes exactly `(index: source target)`.
                let created =
                    GenericLink::new(storage.try_create(*source, *target)?, *source, *target);
                storage.save()?;
                changes_document_for(&[(GenericLink::null(), created)])
            }
            Self::Update {
                index,
                source,
                target,
            } => {
                let mut changes = Vec::new();
                storage.update_observed(*index, *source, *target, &mut |before, after| {
                    changes.push((before, after))
                })?;
                storage.save()?;
                changes_document_for(&simplify_generic_changes(changes))
            }
            Self::Delete(index) => {
                let mut changes = Vec::new();
                storage
                    .delete_observed(*index, &mut |before, after| changes.push((before, after)))?;
                storage.save()?;
                changes_document_for(&simplify_generic_changes(changes))
            }
            Self::GetName(index) => match storage.get_name(*index)? {
                Some(name) => vec![named("name", vec![LiNo::Ref(name)])],
                None => Vec::new(),
            },
            Self::SetName(index, name) => {
                let link = storage.set_name(*index, name)?;
                storage.save()?;
                link_reply(Some(link))
            }
            Self::GetByName(name) => link_reply(storage.get_by_name(name)?),
            Self::RemoveName(index) => {
                storage.remove_name(*index)?;
                storage.save()?;
                Vec::new()
            }
            Self::Subscribe(_) | Self::Unsubscribe(_) => {
                anyhow::bail!("subscriptions belong to a connection to a links server")
            }
        })
    }
}

/// Whether `link` matches `restriction`, with the shapes of the raw links
/// interface: see the [module documentation](self).
pub fn matches<T: QueryAddress>(link: &GenericLink<T>, restriction: &[Part<T>]) -> bool {
    let is = |part: Part<T>, value: T| part.is_none_or(|part| part == value);
    match *restriction {
        [] => true,
        [index] => is(index, link.index),
        [index, value] => {
            is(index, link.index) && (is(value, link.source) || is(value, link.target))
        }
        [index, source, target] => {
            is(index, link.index) && is(source, link.source) && is(target, link.target)
        }
        _ => false,
    }
}

fn matching<T: QueryAddress, S: NamedTypeLinks<T> + ?Sized>(
    storage: &mut S,
    restriction: &[Part<T>],
) -> Vec<GenericLink<T>> {
    let mut links = match restriction.first() {
        Some(Some(index)) => storage.get_link(*index).into_iter().collect(),
        _ => storage.all_links(),
    };
    links.retain(|link| matches(link, restriction));
    links.sort_by_key(|link| link.index);
    links
}

/// The `count` of a `(count: N)` reply.
pub fn parse_count(document: &[LiNo<String>]) -> ProtocolResult<u32> {
    match document {
        [LiNo::Link {
            id: Some(id),
            values,
        }] if id == "count" => match values.as_slice() {
            [count] => parse_number(count),
            _ => Err(malformed_reply("count", document)),
        },
        _ => Err(malformed_reply("count", document)),
    }
}

/// The number of a `(subscription: N)` reply.
pub fn parse_subscription(document: &[LiNo<String>]) -> ProtocolResult<u32> {
    match document {
        [LiNo::Link {
            id: Some(id),
            values,
        }] if id == "subscription" => match values.as_slice() {
            [subscription] => parse_number(subscription),
            _ => Err(malformed_reply("subscription", document)),
        },
        _ => Err(malformed_reply("subscription", document)),
    }
}

/// The reply to a [`LinksOperation::Subscribe`]: `(subscription: N)`.
pub fn subscription_document(subscription: u32) -> LinoDocument {
    vec![named("subscription", vec![number(subscription)])]
}

/// Whether `document` is a push rather than a reply: its first link is
/// `(notify: N)`.
///
/// No reply starts that way: the replies to operations name their first link
/// after the operation's result or leave it unnamed, and the links a server
/// lists are `(index: source target)`, with two values.
pub fn is_notification(document: &[LiNo<String>]) -> bool {
    notification_number(document).is_some()
}

pub(super) fn notification_number(document: &[LiNo<String>]) -> Option<u32> {
    match document.first()? {
        LiNo::Link {
            id: Some(id),
            values,
        } if id == "notify" => match values.as_slice() {
            [LiNo::Ref(text)] if text.bytes().all(|byte| byte.is_ascii_digit()) => {
                text.parse().ok()
            }
            _ => None,
        },
        _ => None,
    }
}

/// A push: `(notify: N)` followed by one `(before) (after)` line per change,
/// with plain numbers.
pub fn notification_document(subscription: u32, changes: &[Change]) -> LinoDocument {
    let mut document = vec![named("notify", vec![number(subscription)])];
    document.extend(changes_document(changes));
    document
}

/// The subscription and the changes of a [`notification_document`].
pub fn parse_notification(document: &[LiNo<String>]) -> ProtocolResult<LinksNotification> {
    let subscription =
        notification_number(document).ok_or_else(|| malformed_reply("notify", document))?;
    Ok(LinksNotification {
        subscription,
        changes: parse_changes(&document[1..])?,
    })
}

/// The links of an `each` reply.
pub fn parse_links_for<T: QueryAddress>(
    document: &[LiNo<String>],
) -> ProtocolResult<Vec<GenericLink<T>>> {
    document.iter().map(parse_link).collect()
}

/// The `(before) (after)` pairs of a `create`, `update` or `delete` reply.
pub fn parse_changes_for<T: QueryAddress>(
    document: &[LiNo<String>],
) -> ProtocolResult<Vec<Change<T>>> {
    document
        .iter()
        .map(|change| match parts(change) {
            [before, after] => Ok((parse_change_side(before)?, parse_change_side(after)?)),
            _ => Err(malformed_reply("change", document)),
        })
        .collect()
}

/// The name of a `get-name` reply.
pub fn parse_name(document: &[LiNo<String>]) -> ProtocolResult<Option<String>> {
    match document {
        [] => Ok(None),
        [LiNo::Link {
            id: Some(id),
            values,
        }] if id == "name" => match values.as_slice() {
            [LiNo::Ref(name)] => Ok(Some(name.clone())),
            _ => Err(malformed_reply("name", document)),
        },
        _ => Err(malformed_reply("name", document)),
    }
}

/// The link of a `set-name` or `get-by-name` reply.
pub fn parse_link_reply_for<T: QueryAddress>(
    document: &[LiNo<String>],
) -> ProtocolResult<Option<T>> {
    match document {
        [] => Ok(None),
        [LiNo::Link {
            id: Some(id),
            values,
        }] if id == "link" => match values.as_slice() {
            [link] => parse_number(link).map(Some),
            _ => Err(malformed_reply("link", document)),
        },
        _ => Err(malformed_reply("link", document)),
    }
}

/// A reply listing `changes`, one `(before) (after)` line each.
pub fn changes_document_for<T: QueryAddress>(changes: &[Change<T>]) -> LinoDocument {
    changes
        .iter()
        .map(|(before, after)| group(vec![change_side(before), change_side(after)]))
        .collect()
}

/// `(index: source target)` with plain numbers.
pub fn link_lino<T: QueryAddress>(link: &GenericLink<T>) -> LiNo<String> {
    named(
        &link.index.to_string(),
        vec![number(link.source), number(link.target)],
    )
}

fn link_reply<T: QueryAddress>(link: Option<T>) -> LinoDocument {
    link.map(|link| vec![named("link", vec![number(link)])])
        .unwrap_or_default()
}

fn change_side<T: QueryAddress>(link: &GenericLink<T>) -> LiNo<String> {
    if link.is_null() {
        group(Vec::new())
    } else {
        group(vec![link_lino(link)])
    }
}

fn parse_change_side<T: QueryAddress>(side: &LiNo<String>) -> ProtocolResult<GenericLink<T>> {
    match side {
        LiNo::Link { id: None, values } if values.is_empty() => Ok(GenericLink::null()),
        LiNo::Link { id: None, values } if values.len() == 1 => parse_link(&values[0]),
        // `((index: source target))` loses its wrapper when the side is the
        // single named link itself.
        link @ LiNo::Link { id: Some(_), .. } => parse_link(link),
        _ => Err(ProtocolError::malformed(format!(
            "expected a change side, found {}",
            format_link(side)
        ))),
    }
}

fn parse_link<T: QueryAddress>(link: &LiNo<String>) -> ProtocolResult<GenericLink<T>> {
    match link {
        LiNo::Link {
            id: Some(index),
            values,
        } => match values.as_slice() {
            [source, target] => Ok(GenericLink::new(
                parse_text_number(index)?,
                parse_number(source)?,
                parse_number(target)?,
            )),
            _ => Err(ProtocolError::malformed(format!(
                "expected (index: source target), found {}",
                format_link(link)
            ))),
        },
        _ => Err(ProtocolError::malformed(format!(
            "expected (index: source target), found {}",
            format_link(link)
        ))),
    }
}

pub(super) fn restriction_lino<T: QueryAddress>(restriction: &[Part<T>]) -> LiNo<String> {
    group(
        restriction
            .iter()
            .map(|part| part.map_or_else(|| LiNo::Ref(ANY.to_string()), number))
            .collect(),
    )
}

pub(super) fn parse_restriction<T: QueryAddress>(
    argument: &LiNo<String>,
) -> ProtocolResult<Vec<Part<T>>> {
    parse_restriction_of(argument, 3)
}

pub(super) fn parse_restriction_of<T: QueryAddress>(
    argument: &LiNo<String>,
    longest: usize,
) -> ProtocolResult<Vec<Part<T>>> {
    let parts = parts(argument);
    if parts.len() > longest {
        return Err(malformed_argument("restriction", argument));
    }
    parts
        .iter()
        .map(|part| match part {
            LiNo::Ref(text) if text == ANY => Ok(None),
            part => parse_number(part).map(Some),
        })
        .collect()
}

pub(super) fn numbers_lino<T: QueryAddress>(numbers: &[T]) -> LiNo<String> {
    group(numbers.iter().copied().map(number).collect())
}

fn parse_numbers_for<T: QueryAddress, const N: usize>(
    argument: &LiNo<String>,
) -> ProtocolResult<[T; N]> {
    let numbers = parts(argument)
        .iter()
        .map(parse_number)
        .collect::<ProtocolResult<Vec<_>>>()?;
    numbers
        .try_into()
        .map_err(|_| malformed_argument(&format!("{N} numbers"), argument))
}

/// The values of an unnamed group; a lone reference is a group of one, since
/// the canonical document model unwraps `(x)` to `x`.
pub(super) fn parts(argument: &LiNo<String>) -> &[LiNo<String>] {
    match argument {
        LiNo::Link { id: None, values } => values,
        reference => std::slice::from_ref(reference),
    }
}

pub(super) fn parse_number<T: QueryAddress>(value: &LiNo<String>) -> ProtocolResult<T> {
    match value {
        LiNo::Ref(text) => parse_text_number(text),
        _ => Err(ProtocolError::malformed(format!(
            "expected a number, found {}",
            format_link(value)
        ))),
    }
}

pub(super) fn parse_text_number<T: QueryAddress>(text: &str) -> ProtocolResult<T> {
    text.parse()
        .map_err(|_| ProtocolError::malformed(format!("expected a number, found '{text}'")))
}

pub(super) fn number<T: QueryAddress>(value: T) -> LiNo<String> {
    LiNo::Ref(value.to_string())
}

pub(super) fn named(id: &str, values: Vec<LiNo<String>>) -> LiNo<String> {
    LiNo::Link {
        id: Some(id.to_string()),
        values,
    }
}

pub(super) fn group(values: Vec<LiNo<String>>) -> LiNo<String> {
    LiNo::Link { id: None, values }
}

pub(super) fn malformed_argument(expected: &str, argument: &LiNo<String>) -> ProtocolError {
    ProtocolError::malformed(format!(
        "expected {expected}, found {}",
        format_link(argument)
    ))
}

pub(super) fn malformed_reply(expected: &str, document: &[LiNo<String>]) -> ProtocolError {
    ProtocolError::malformed(format!(
        "expected a {expected} reply, found {}",
        format_document(document)
    ))
}

/// The links of an `each` reply using the existing u32 facade.
pub fn parse_links(document: &[LiNo<String>]) -> ProtocolResult<Vec<Link>> {
    parse_links_for(document)
}

/// The changes of a mutation reply using the existing u32 facade.
pub fn parse_changes(document: &[LiNo<String>]) -> ProtocolResult<Vec<Change>> {
    parse_changes_for(document)
}

/// A named-link reply using the existing u32 facade.
pub fn parse_link_reply(document: &[LiNo<String>]) -> ProtocolResult<Option<u32>> {
    parse_link_reply_for(document)
}

/// A change document using the existing u32 facade.
pub fn changes_document(changes: &[Change]) -> LinoDocument {
    changes_document_for(changes)
}

pub(super) fn parse_numbers<const N: usize>(argument: &LiNo<String>) -> ProtocolResult<[u32; N]> {
    parse_numbers_for::<u32, N>(argument)
}