starOf

tcmts.records.starOf · #q2dv7v73 · term · runs anywhere

A star record's subject, if it is one (and at its own key).

import { starKey } from "#codebase/tcmts/records";

export function starOf(
  rkey: string,
  v: unknown,
): { author: string; package: string; createdAt: string } | undefined {
  const r = v as
    | { subject?: { author?: unknown; package?: unknown }; createdAt?: unknown }
    | undefined;
  const author = r?.subject?.author;
  const pkg = r?.subject?.package;
  if (typeof author !== "string" || typeof pkg !== "string" || starKey(author, pkg) !== rkey)
    return undefined;
  return {
    author,
    package: pkg,
    createdAt: typeof r?.createdAt === "string" ? r.createdAt : new Date().toISOString(),
  };
}

uses

used by