ExplorableSiteMap class

A site that exposes its keys so it can be traversed

JSON Keys protocol support #

If you use ExplorableSiteMap to wrap a site that supports the JSON Keys protocol, the ExplorableSiteMap instance will be able to programmatically return the keys at a given route. See that protocol for more details.

For example, you can use the ori CLI to display the keys of a given site route using the custom explore: protocol, which returns an ExplorableSiteMap.

$ ori keys explore://weborigami.org/samples/greetings/
- Alice
- Bob
- Carol

You can also use ori to display the complete contents of all pages at a given route:

$ ori explore://weborigami.org/samples/greetings/
Alice: Hello, Alice.
Bob: Hello, Bob.
Carol: Hello, Carol.

Above, the custom explore: protocol retrieves the route’s keys defined in the .keys.json, then makes separate requests for each of those pages.

API #

A SiteMap that implements the JSON Keys protocol. This enables a keys() method that can return the keys of a site route even though such a mechanism is not built into the HTTP protocol.

new ExplorableSiteMap(href)

  • href: string

static async groupBy(iterable, keyFn)

  • iterable: any
  • keyFn: (element: any, index: any) => Promise

Returns: Promise

Groups items from an async iterable into an AsyncMap according to the keys returned by the given function.

*keys()

Returns: unknown

Returns the keys of the site route. For this to work, the route must have a .keys.json file that contains a JSON array of string keys.

async get(key)

  • key: any

Returns: Promise

Returns the value associated with the key, or undefined if there is none.

async clear()

Returns: any

Remove all key/value entries from the map.

This method invokes the keys() and delete() methods.

async delete(key)

  • key: any

Returns: Promise

Removes the entry for the given key, return true if an entry was removed and false if there was no entry for the key.

*entries()

Returns: AsyncIterableIterator<[any, any]>

Returns a new AsyncIterator object that contains a two-member array of [key, value] for each element in the map in insertion order.

This method invokes the keys() and get() methods.

async forEach(callback, [thisArg])

  • callback: (value: any, key: any, thisArg: any) => Promise
  • thisArg: any

Returns: any

Calls callback once for each key/value pair in the map, in insertion order.

This method invokes the entries() method.

async has(key)

  • key: any

Returns: unknown

Returns true if the given key appears in the set returned by keys().

It doesn’t matter whether the value returned by get() is defined or not.

If the requested key has a trailing slash but has no associated value, but the alternate form with a slash does appear, this returns true.

parent

Type: AsyncMap

The parent of this node in a tree.

readOnly

Type: boolean

True if the object is read-only. This will be true if get() has been overridden but set() and delete() have not.

async set(key, value)

  • key: any
  • value: any

Returns: Promise

Sets the value for the given key.

size

Type: Promise

Returns the number of keys in the map.

The size property invokes an overridden keys() to ensure proper behavior in subclasses. Because a subclass may not enforce a direct correspondence between keys() and get(), the size may not reflect the number of values that can be retrieved.

*values()

Returns: AsyncIterableIterator

Returns a new AsyncIterator object that contains the values for each element in the map in insertion order.