Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

586 B
Raw Blame
import { expect } from 'vitest';

/** The key a point was sent with, if any. */
const sentKey = (point: object): unknown => ('key' in point ? point.key : undefined);

/**
 * CW-03: the points of a save as the server keeps them. Every point carries a
 * station key: the one it was sent with, or a fresh one in the shape of
 * `stationKeySchema` where it came without.
 */
export function keyed<T extends object>(points: readonly T[]): Array<T & { key: unknown }> {
  return points.map((point) => ({ ...point, key: sentKey(point) ?? expect.stringMatching(/^[A-Za-z0-9_-]{6,64}$/) }));
}