Class: ResourceMapResolver

ResourceMapResolver()

A multi-strategy resource map (RM) look-up tool. Searches for the RM associated with a given PID and allows finding RMs when data packages have not yet been indexed. Tries the following strategies in the order listed: queries index, checks client-side storage, walks the system metadata, and finally guesses the RM PID based on a naming convention. When a match is found, the class stores the Obj-RM PID pair in the client-side storage for future use. When a match is found from a source other than index, the RM is verified to ensure it links to the pid. The history of the resolution attempts is stored in an event log.

Constructor

new ResourceMapResolver()

Since:
  • 2.34.0
Source:

Methods

addToStorage(pid, rm) → {Promise.<(string|null)>}

Adds a resource map PID to the local storage for the given PID.
Parameters:
Name Type Description
pid string The PID of the document to add the RM for
rm string The resource map PID to add
Source:
Returns:
- The PID of the resource map added to storage, or null if the addition failed
Type
Promise.<(string|null)>

checkStorage(pid) → {Promise.<(string|null)>}

Checks local storage / index DB for a resource map PID associated with the given PID. Uses localForage to access the local storage.
Parameters:
Name Type Description
pid string The PID of the document to check
Source:
Returns:
- PID of RM if found, null otherwise
Type
Promise.<(string|null)>

clearStorage() → {Promise.<void>}

Clears the saved resource map : pid pairs from the local storage.
Source:
Returns:
- A promise that resolves when the storage is cleared
Type
Promise.<void>

fetchResourceMap(rm, timeoutopt) → {Promise.<{model: PackageModel, status: number}>}

Fetches the resource map model for the given resource map PID.
Parameters:
Name Type Attributes Description
rm string The PID of the resource map to fetch
timeout number <optional>
The maximum time to wait for the fetch
Source:
Returns:
- A promise that resolves to an object containing the fetched resource map model and the HTTP status code.
Type
Promise.<{model: PackageModel, status: number}>

getLog(pid) → {object}

Get the log of events for a given PID. If no log exists, a new one is created.
Parameters:
Name Type Description
pid string The PID of the object to get the log for
Source:
Returns:
- The event log for the PID, which includes an array of events with timestamps, messages, and metadata.
Type
object

getPidForSid(sid) → {Promise.<(string|null)>}

Gets the PID for a given series ID (SID) using sys metadata. Ensures that the most recent PID is returned, even if indexing is not complete.
Parameters:
Name Type Description
sid string The series ID to get the PID for
Source:
Returns:
- The PID associated with the series ID, or null if not found
Type
Promise.<(string|null)>

guessPid(pid) → {Promise.<(string|null)>}

Guesses the resource map PID based on the PID. The guessed PID is constructed by appending the PID to a predefined prefix.
Parameters:
Name Type Description
pid string The PID of the document to guess the RM PID for
Source:
Returns:
- The guessed resource map PID if it exists and is linked to the PID, null otherwise
Type
Promise.<(string|null)>

log(pid, rm, status, metaopt, levelopt) → {object}

Logs an event for the resolution process.
Parameters:
Name Type Attributes Default Description
pid string The PID of the object being resolved
rm string The resource map PID if found, null otherwise
status string The human-readable status of the resolution
meta object <optional>
Additional metadata to include in the event
level string <optional>
info The log level for the event
Source:
Returns:
- The event log for the resolution process
Type
object

logToAnalytics(pid, eventNameopt)

Logs all events for a given PID to the analytics service.
Parameters:
Name Type Attributes Default Description
pid string The PID of the object to log events for
eventName string <optional>
resource_map_resolution The name to use for the event in analytics.
Source:

mutliRMCheck(pid, rms) → {Promise.<object>}

When 2 or more resource maps are found in the index for a PID, then this method is called to check if they are all versions of each other and if one is not yet obsoleted.
Parameters:
Name Type Description
pid string The PID to check for multiple resource maps
rms Array.<string> An array of resource map PIDs to check
Since:
  • 2.34.1
Source:
Returns:
- An object containing the PID, the resolved resource map PID if found, and metadata about the search.
Type
Promise.<object>

resolve(pid) → {ResolveResult}

The main method to resolve the resource map PID for a given PID. It will try multiple strategies in order to find the resource map associated with the PID.
Parameters:
Name Type Description
pid string The PID of the document to resolve
Source:
Returns:
- The result of the resolution process
Type
ResolveResult

resolveFromSeriesId(sid) → {Promise.<ResolveResult>}

Resolves the resource map PID from a series ID (SID). It first retrieves the system metadata for the series ID to get the most up-to-date PID, then starts the resolution process with the new PID. Called from `resolve` when the index search returns a series ID.
Parameters:
Name Type Description
sid string The series ID to resolve
Source:
Returns:
- The result of the resolution process
Type
Promise.<ResolveResult>

searchIndex(pid) → {Promise.<(object|null)>}

Searches the index for a resource map associated with the given PID. Returns an object containing the PID and metadata about the search.
Parameters:
Name Type Description
pid string The PID to search for in the index
Source:
Returns:
- An object containing the PID and metadata if a resource map is found, null otherwise
Type
Promise.<(object|null)>

status(pid, status, rmopt, metaopt) → {ResolveResult}

Records the status of the resolution process for a given PID and triggers Backbone events for the status update.
Parameters:
Name Type Attributes Description
pid string The PID of the object being resolved
status string The human-readable status of the resolution
rm string <optional>
The resource map PID if found, null otherwise
meta object <optional>
Additional metadata to include in the status
Source:
Returns:
- An object with the result of the resolution
Type
ResolveResult

trackMissingResourceMap(pid)

Send any events logged for a PID to the analytics service.
Parameters:
Name Type Description
pid string The PID of the object to send logs for
Source:

verify(rm, pid) → {Promise.<boolean>}

Verifies that the given resource map PID exists and contains the pid as a member.
Parameters:
Name Type Description
rm string The PID of the resource map to verify
pid string The PID of the document to check
Source:
Returns:
- True if the RM is valid and contains the PID, false otherwise
Type
Promise.<boolean>

walkSysmeta(pid) → {Promise.<{rm: (string|null), meta: object}>}

Walks the system metadata to find the resource map PID associated with the given PID. It starts from the given PID and walks backward through the version history to find an old resource map PID. Then, starting at the found RM pid, walks forward to find the current RM.
Parameters:
Name Type Description
pid string The PID of the document to walk sysmeta for
Source:
Returns:
- An object containing the resource map PID if found, and metadata about the walk
Type
Promise.<{rm: (string|null), meta: object}>

checkLogForMultipleRMs(log) → {boolean}

Checks the event log to see if multiple resource maps were found during the index search.
Parameters:
Name Type Description
log object The event log to check
Source:
Returns:
- True if multiple resource maps were found, false otherwise
Type
boolean

checkLogForUnauth(log) → {boolean}

Checks the event log for unauthorized access events.
Parameters:
Name Type Description
log object The event log to check
Source:
Returns:
- True if there are unauthorized access events, false otherwise
Type
boolean

containsPid(rmModel, pid) → {boolean}

Checks if the resource map model contains the given PID as a member.
Parameters:
Name Type Description
rmModel PackageModel The resource map model to check
pid string The PID to check for in the resource map
Source:
Returns:
- True if the PID is found in the resource map, false otherwise
Type
boolean

ResourceMapResolver(options)

new ResourceMapResolver(options)

Parameters:
Name Type Description
options object Options for the resolver
Properties
Name Type Attributes Description
id string <optional>
The ID to use for the resolver.
metaServiceUrl string <optional>
The base URL for service to get System Metadata
storage object <optional>
An instance of localForage to use for storage. If not provided, a new instance will be created with the name "ResourceMapResolver".
eventLog object <optional>
An instance of EventLog to use for tracing the resolution process. If not provided, a new instance will be created.
maxSteps number <optional>
The maximum number of steps to walk back in the system metadata to find a resource map PID.
maxFetchTime number <optional>
The maximum time to wait for fetching the resource map PID from the system metadata. Defaults to 45s.
consoleLevel "info" | "warning" | "error" <optional>
The level at which to log messages to the console. Defaults to "warning". Set to false to disable console logging.
Source:

Methods

addToStorage(pid, rm) → {Promise.<(string|null)>}

Adds a resource map PID to the local storage for the given PID.
Parameters:
Name Type Description
pid string The PID of the document to add the RM for
rm string The resource map PID to add
Source:
Returns:
- The PID of the resource map added to storage, or null if the addition failed
Type
Promise.<(string|null)>

checkStorage(pid) → {Promise.<(string|null)>}

Checks local storage / index DB for a resource map PID associated with the given PID. Uses localForage to access the local storage.
Parameters:
Name Type Description
pid string The PID of the document to check
Source:
Returns:
- PID of RM if found, null otherwise
Type
Promise.<(string|null)>

clearStorage() → {Promise.<void>}

Clears the saved resource map : pid pairs from the local storage.
Source:
Returns:
- A promise that resolves when the storage is cleared
Type
Promise.<void>

fetchResourceMap(rm, timeoutopt) → {Promise.<{model: PackageModel, status: number}>}

Fetches the resource map model for the given resource map PID.
Parameters:
Name Type Attributes Description
rm string The PID of the resource map to fetch
timeout number <optional>
The maximum time to wait for the fetch
Source:
Returns:
- A promise that resolves to an object containing the fetched resource map model and the HTTP status code.
Type
Promise.<{model: PackageModel, status: number}>

getLog(pid) → {object}

Get the log of events for a given PID. If no log exists, a new one is created.
Parameters:
Name Type Description
pid string The PID of the object to get the log for
Source:
Returns:
- The event log for the PID, which includes an array of events with timestamps, messages, and metadata.
Type
object

getPidForSid(sid) → {Promise.<(string|null)>}

Gets the PID for a given series ID (SID) using sys metadata. Ensures that the most recent PID is returned, even if indexing is not complete.
Parameters:
Name Type Description
sid string The series ID to get the PID for
Source:
Returns:
- The PID associated with the series ID, or null if not found
Type
Promise.<(string|null)>

guessPid(pid) → {Promise.<(string|null)>}

Guesses the resource map PID based on the PID. The guessed PID is constructed by appending the PID to a predefined prefix.
Parameters:
Name Type Description
pid string The PID of the document to guess the RM PID for
Source:
Returns:
- The guessed resource map PID if it exists and is linked to the PID, null otherwise
Type
Promise.<(string|null)>

log(pid, rm, status, metaopt, levelopt) → {object}

Logs an event for the resolution process.
Parameters:
Name Type Attributes Default Description
pid string The PID of the object being resolved
rm string The resource map PID if found, null otherwise
status string The human-readable status of the resolution
meta object <optional>
Additional metadata to include in the event
level string <optional>
info The log level for the event
Source:
Returns:
- The event log for the resolution process
Type
object

logToAnalytics(pid, eventNameopt)

Logs all events for a given PID to the analytics service.
Parameters:
Name Type Attributes Default Description
pid string The PID of the object to log events for
eventName string <optional>
resource_map_resolution The name to use for the event in analytics.
Source:

mutliRMCheck(pid, rms) → {Promise.<object>}

When 2 or more resource maps are found in the index for a PID, then this method is called to check if they are all versions of each other and if one is not yet obsoleted.
Parameters:
Name Type Description
pid string The PID to check for multiple resource maps
rms Array.<string> An array of resource map PIDs to check
Since:
  • 2.34.1
Source:
Returns:
- An object containing the PID, the resolved resource map PID if found, and metadata about the search.
Type
Promise.<object>

resolve(pid) → {ResolveResult}

The main method to resolve the resource map PID for a given PID. It will try multiple strategies in order to find the resource map associated with the PID.
Parameters:
Name Type Description
pid string The PID of the document to resolve
Source:
Returns:
- The result of the resolution process
Type
ResolveResult

resolveFromSeriesId(sid) → {Promise.<ResolveResult>}

Resolves the resource map PID from a series ID (SID). It first retrieves the system metadata for the series ID to get the most up-to-date PID, then starts the resolution process with the new PID. Called from `resolve` when the index search returns a series ID.
Parameters:
Name Type Description
sid string The series ID to resolve
Source:
Returns:
- The result of the resolution process
Type
Promise.<ResolveResult>

searchIndex(pid) → {Promise.<(object|null)>}

Searches the index for a resource map associated with the given PID. Returns an object containing the PID and metadata about the search.
Parameters:
Name Type Description
pid string The PID to search for in the index
Source:
Returns:
- An object containing the PID and metadata if a resource map is found, null otherwise
Type
Promise.<(object|null)>

status(pid, status, rmopt, metaopt) → {ResolveResult}

Records the status of the resolution process for a given PID and triggers Backbone events for the status update.
Parameters:
Name Type Attributes Description
pid string The PID of the object being resolved
status string The human-readable status of the resolution
rm string <optional>
The resource map PID if found, null otherwise
meta object <optional>
Additional metadata to include in the status
Source:
Returns:
- An object with the result of the resolution
Type
ResolveResult

trackMissingResourceMap(pid)

Send any events logged for a PID to the analytics service.
Parameters:
Name Type Description
pid string The PID of the object to send logs for
Source:

verify(rm, pid) → {Promise.<boolean>}

Verifies that the given resource map PID exists and contains the pid as a member.
Parameters:
Name Type Description
rm string The PID of the resource map to verify
pid string The PID of the document to check
Source:
Returns:
- True if the RM is valid and contains the PID, false otherwise
Type
Promise.<boolean>

walkSysmeta(pid) → {Promise.<{rm: (string|null), meta: object}>}

Walks the system metadata to find the resource map PID associated with the given PID. It starts from the given PID and walks backward through the version history to find an old resource map PID. Then, starting at the found RM pid, walks forward to find the current RM.
Parameters:
Name Type Description
pid string The PID of the document to walk sysmeta for
Source:
Returns:
- An object containing the resource map PID if found, and metadata about the walk
Type
Promise.<{rm: (string|null), meta: object}>

checkLogForMultipleRMs(log) → {boolean}

Checks the event log to see if multiple resource maps were found during the index search.
Parameters:
Name Type Description
log object The event log to check
Source:
Returns:
- True if multiple resource maps were found, false otherwise
Type
boolean

checkLogForUnauth(log) → {boolean}

Checks the event log for unauthorized access events.
Parameters:
Name Type Description
log object The event log to check
Source:
Returns:
- True if there are unauthorized access events, false otherwise
Type
boolean

containsPid(rmModel, pid) → {boolean}

Checks if the resource map model contains the given PID as a member.
Parameters:
Name Type Description
rmModel PackageModel The resource map model to check
pid string The PID to check for in the resource map
Source:
Returns:
- True if the PID is found in the resource map, false otherwise
Type
boolean