All files / src/db served-databases.js

62.5% Statements 5/8
25% Branches 1/4
50% Functions 1/2
71.42% Lines 5/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                39x               39x                       39x 3x 3x    
/**
 * The databases each context serves: the identity of the content data a running host reads.
 *
 * @module src/db/served-databases.js
 * @namespace ServedDatabases
 */
 
/** The databases the partitions of each context serve, by `<host><path>`. */
const servedDatabases = new Map();
 
/**
 * Records the databases the partitions of a context serve; none when each serves its own database.
 * @param {string} contextKey - `<host><path>`.
 * @param {string} signature - `<partition>=<database>` pairs, or `''`.
 * @memberof ServedDatabases
 */
export const recordServedDatabases = (contextKey, signature) => {
  if (signature) servedDatabases.set(contextKey, signature);
  else servedDatabases.delete(contextKey);
};
 
/**
 * The content data a context reads. A rebind, a rollback included, reads data of its own; the
 * partitions' own databases never share data with a bound database.
 * @param {string} contextKey - `<host><path>`.
 * @returns {string}
 * @memberof ServedDatabases
 */
export const contentDataKey = (contextKey) => {
  const served = servedDatabases.get(contextKey);
  return served ? `served@${served}` : 'base';
};