Sni
@Js
const class Sni : Obj
Sni models a Subject Navigation Identifier formatted as:
/provider/tail?params#frag
Parse from string formatted as "/provider/tail?params#frag"
Fragment identifier for location within the subject
Home root "/"
Query parameters parsed as key-value map
Provider is the first path segment identifying the subject provider
Spilled values keyed by spill key "a", "b", "c"..
Tail as list of path segments after the provider
Decode the full view state from a Dict produced by encode
Default is same as home
Encode the full view state -- string plus spilled values -- to a Dict for history state, server requests, and favorites
Equality based on string and spills
Equality ignoring fragment
Construct Sni from a Ref identity (reverse of id)
Create "/db?sel=id1,id2,..." sni from multiple refs
Get a single param value by name, or null if not present
Hash code based on string
Get Ref identity for this Sni
Parse fragment as start location, or null if no fragment
Parse fragment as end location for a range, or null if no range
Last named part in path of tail or provider
/files/lib/doc.xeto/Specs.md => "Specs.md"
Return Sni with fragment stripped
Append a name to the tail path, dropping any params
Append a trailing slash, dropping any params
/dev/a/b?view=xxx plusSlash => /dev/a/b/
Selection ids parsed from the "sel" param, or null if not present
Return new Sni with the given param set
Return new Sni with given fragment, or remove if null
Return new Sni with given params
Return new Sni with the "sel" param set to the given selection ids, or removed if null
Return new Sni with given tail
Set view name
Tail as the full string after the provider
To item
Full string representation
Convert to a URI
Get the "view" parameter
static Sni decode(Dict d)
Decode the full view state from a Dict produced by encode.
static Sni defVal()
Default is same as home
Dict encode()
Encode the full view state -- string plus spilled values -- to a Dict for
history state, server requests, and favorites. The sni tag holds the
string (with "$key" placeholders); the spills tag holds the spilled
values when present. Reverse with decode.
virtual Bool equals(Obj? that)
Equality based on string and spills. Spill keys must match exactly.
For string-only comparison use a.toStr == b.toStr.
Bool equalsIgnoreFrag(Sni that)
Equality ignoring fragment
const Str? : frag
Fragment identifier for location within the subject. Null if no fragment.
/files/lib.xeto#L10 => "L10"
/files/lib.xeto#L10,5-L20,3 => "L10,5-L20,3"
static Sni fromId(Ref id, Bool norm := true)
Construct Sni from a Ref identity (reverse of id). If norm is true, relativize the ref via UiSpace if available.
static Sni fromIds(Ref[] ids, Bool norm := true)
Create "/db?sel=id1,id2,..." sni from multiple refs.
If norm is true, relativize ids via UiSpace if available.
More than 8 ids will spill to the $a key (e.g. "?sel=$a").
static new fromStr(Str s, Bool checked := true)
Parse from string formatted as "/provider/tail?params#frag"
@Operator
Str? get(Str name)
Get a single param value by name, or null if not present.
virtual Int hash()
Hash code based on string
const static Sni : home
Home root "/"
Ref id()
Get Ref identity for this Sni. For /db/{id} where id is a valid bare Ref, returns Ref(id). For all others returns sni:{provider}:{tail-encoded}. Params and fragment are never part of identity.
FileLoc? loc()
Parse fragment as start location, or null if no fragment. Returns FileLoc with line and optional column.
#L10 => FileLoc("", 10)
#L10,5 => FileLoc("", 10, 5)
#L10,5-L20,3 => FileLoc("", 10, 5)
FileLoc? locEnd()
Parse fragment as end location for a range, or null if no range. Returns FileLoc with line and optional column.
#L10 => null
#L10-L20 => FileLoc("", 20)
#L10,5-L20,3 => FileLoc("", 20, 3)
Str name()
Last named part in path of tail or provider
/files/lib/doc.xeto/Specs.md => "Specs.md"
Sni noFrag()
Return Sni with fragment stripped. Returns this if no fragment.
const Str:Str : params
Query parameters parsed as key-value map. Returns empty map if no params.
Sni plusName(Str name)
Append a name to the tail path, dropping any params.
/dev/a/b?view=xxx plusName("c.txt") => /dev/a/b/c.txt
Sni plusSlash()
Append a trailing slash, dropping any params
/dev/a/b?view=xxx plusSlash => /dev/a/b/
const Str : provider
Provider is the first path segment identifying the subject provider. Empty string only for root "/".
/db/ph::Equip/abc-123 => "db"
/files/lib/doc.xeto/Specs.md => "file"
Ref[]? sel()
Selection ids parsed from the "sel" param, or null if not present. A selection is a view of its base collection, never identity - see id. Returns null if the param was spilled and the spill values are not available (string-only reparse). See setSel.
Sni set(Str name, Str? val)
Return new Sni with the given param set. If val is null, the param is removed. Returns this if unchanged.
Sni setFrag(Str? frag)
Return new Sni with given fragment, or remove if null.
Sni setParams([Str:Str]? params)
Return new Sni with given params.
Sni setSel(Ref[]? ids)
Return new Sni with the "sel" param set to the given selection ids, or removed if null. More than 8 ids spill to a "$key" placeholder carried by the spills Dict. See sel.
Sni setTail(Str[] tail)
Return new Sni with given tail.
Sni setView(Str viewName)
Set view name
const Dict : spills
Spilled values keyed by spill key "a", "b", "c"... These are the typed
values (e.g. Ref[]) referenced by "$key" placeholders in the string
(so "$a" maps to spills->a). Keys are valid tag names. Empty Dict if
no values spilled. See encode.
const Str[] : tail
Tail as list of path segments after the provider. Returns empty list if no tail.
/db/ph::Equip/abc-123 => ["ph::Equip", "abc-123"]
/files/lib/doc.xeto/Specs.md => ["lib", "doc.xeto", "Specs.md"]
Str tailStr()
Tail as the full string after the provider. Returns empty string if no tail.
/db/ph::Equip/abc-123 => "ph::Equip/abc-123"
/files/lib/doc.xeto/Specs.md => "lib/doc.xeto/Specs.md"
Item toItem(Obj? text := null, Icon? icon := null, Dict? meta := null)
To item
virtual Str toStr()
Full string representation. This is the URL form which carries spill
placeholders such as "$0" but not the spilled values themselves. Use
encode/decode to round-trip the full state including spills.
Uri toUri()
Convert to a URI
Str? view()
Get the "view" parameter