IF Commons GitHub

logical/as-of

Written to: 6 requirements: 6 proved, 0 partly, 0 failing, 0 with no test recorded. 0010-grc-as-of FR-001, 0010-grc-as-of FR-002, 0010-grc-as-of FR-003, 0010-grc-as-of FR-004, 0010-grc-as-of FR-005, 0010-grc-as-of FR-006

The as-of view (0010-grc-as-of): the state of every control at an instant, computed only from the results, exceptions, risks and ledger entries recorded up to that instant. Events after the instant are ignored and expirations are evaluated at the instant, so the same events give the same view in any order and whatever came later. Pure: the instant is a parameter.

import { asOf } from "./as-of.ts";
// const view = asOf({ frameworks, crosswalks: [], checks, results, exceptions: [], risks: [], ledger: [] }, "2026-03-01T00:00:00Z");
// view.kind === "ok" && view.value.controls.map((c) => c.status);

Source: commons/grc/src/logical/as-of.ts

4 of 14 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

logical.AsOfInputtypeno test imports it
type AsOfInput = {
  readonly frameworks: readonly Framework[];
  readonly crosswalks: readonly Crosswalk[];
  readonly checks: readonly Check[];
  readonly policies?: readonly Policy[];
  readonly results: readonly Outcome[];
  readonly exceptions: readonly Exception[];
  readonly risks: readonly Risk[];
  readonly ledger: readonly LedgerEntry[];
};

Everything recorded: what the as-of view is computed from.

logical.ControlFreshnesstypeno test imports it
type ControlFreshness = FreshnessState | "unobserved";

How fresh the evidence of a control is, unobserved where nothing was observed.

logical.ControlStatetypeno test imports it
type ControlState = { readonly control: string; readonly status: Status; readonly coverage: CoverageState; reado… (610 characters)
type ControlState = {
  readonly control: string;
  readonly status: Status;
  readonly coverage: CoverageState;
  readonly freshness: ControlFreshness;
  /** The instant of the newest observation that shows the control. */
  readonly newestAt: string | undefined;
  /** The ids of the exceptions in force that excuse the control, its checks or a policy that names it. */
  readonly exceptions: readonly string[];
  /** The highest level of the risks that name the control. */
  readonly risk: Level | undefined;
  /** The ids of those risks whose review has come. */
  readonly risksDue: readonly string[];
};

The state of a control at an instant.

logical.AsOfViewtypeno test imports it
type AsOfView = {
  readonly at: string;
  readonly controls: readonly ControlState[];
  /** The ledger up to the instant. */
  readonly ledger: { readonly length: number; readonly head: string };
  readonly rollup: Rollup;
};

The view at an instant.

logical.asOffunctionno test imports it
function asOf(input: AsOfInput, at: string): Result<AsOfView, string>

The view at at from what was recorded up to it: results observed, risks and entries created and exceptions granted at or before it; an exception is in force until its expiry. An at that is not an instant is an error.

// const view = asOf(input, "2026-03-01T00:00:00Z"); // events after the instant are ignored
logical.currentViewfunctionno test imports it
function currentView(input: AsOfInput, now: string): Result<AsOfView, string>

The current view at now: the same computation with nothing filtered out by the instant.

// currentView(input, "2026-03-01T00:00:00Z"); // nothing filtered by the instant
logical.latestInstantfunctionno test imports it
function latestInstant(input: AsOfInput): string | undefined

The latest instant any event of the input has (an observation, a grant, the creation of a risk or an entry); undefined where there is none.

// latestInstant(input); // the instant after which the as-of view no longer changes
AsOfInputtype
type AsOfInput = {
  readonly frameworks: readonly Framework[];
  readonly crosswalks: readonly Crosswalk[];
  readonly checks: readonly Check[];
  readonly policies?: readonly Policy[];
  readonly results: readonly Outcome[];
  readonly exceptions: readonly Exception[];
  readonly risks: readonly Risk[];
  readonly ledger: readonly LedgerEntry[];
};

Everything recorded: what the as-of view is computed from.

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

ControlFreshnesstypeno test imports it
type ControlFreshness = FreshnessState | "unobserved";

How fresh the evidence of a control is, unobserved where nothing was observed.

ControlStatetypeno test imports it
type ControlState = { readonly control: string; readonly status: Status; readonly coverage: CoverageState; reado… (610 characters)
type ControlState = {
  readonly control: string;
  readonly status: Status;
  readonly coverage: CoverageState;
  readonly freshness: ControlFreshness;
  /** The instant of the newest observation that shows the control. */
  readonly newestAt: string | undefined;
  /** The ids of the exceptions in force that excuse the control, its checks or a policy that names it. */
  readonly exceptions: readonly string[];
  /** The highest level of the risks that name the control. */
  readonly risk: Level | undefined;
  /** The ids of those risks whose review has come. */
  readonly risksDue: readonly string[];
};

The state of a control at an instant.

AsOfViewtypeno test imports it
type AsOfView = {
  readonly at: string;
  readonly controls: readonly ControlState[];
  /** The ledger up to the instant. */
  readonly ledger: { readonly length: number; readonly head: string };
  readonly rollup: Rollup;
};

The view at an instant.

asOffunction
function asOf(input: AsOfInput, at: string): Result<AsOfView, string>

The view at at from what was recorded up to it: results observed, risks and entries created and exceptions granted at or before it; an exception is in force until its expiry. An at that is not an instant is an error.

// const view = asOf(input, "2026-03-01T00:00:00Z"); // events after the instant are ignored

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

currentViewfunction
function currentView(input: AsOfInput, now: string): Result<AsOfView, string>

The current view at now: the same computation with nothing filtered out by the instant.

// currentView(input, "2026-03-01T00:00:00Z"); // nothing filtered by the instant

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

latestInstantfunction
function latestInstant(input: AsOfInput): string | undefined

The latest instant any event of the input has (an observation, a grant, the creation of a risk or an entry); undefined where there is none.

// latestInstant(input); // the instant after which the as-of view no longer changes

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.