Spreadsheet-UX op een echte relationele engine

main

Deze repository wordt als momentopname gepubliceerd: een clone bevat de volledige inhoud, maar geen commitgeschiedenis.

1.2 kB Ruw bestand
import { DEFAULT_LOCALE, type Locale } from '@wellformed/shared';
import { applyDemo, type DemoMode } from './demo.js';
import type { Db } from './driver.js';
import { loadMeta } from './meta.js';

export interface SeedResult {
  created: boolean;
}

/**
 * Give a fresh workspace something to look at.
 *
 * Idempotent by design: a workspace that already has a table is left alone.
 * That is what makes this safe to call from anywhere — the demo can only ever
 * be the *first* thing in a workspace, never something that lands on top of
 * real data.
 *
 * Purely about content. Who may open this workspace is the control plane's
 * business, and no account is created here.
 */
export function seed(
  db: Db,
  options: { quiet?: boolean; locale?: Locale; mode?: DemoMode } = {},
): SeedResult {
  const meta = loadMeta(db);
  if (meta.tableOrder.length > 0) return { created: false };

  const mode = options.mode ?? 'full';
  applyDemo(db, { locale: options.locale ?? DEFAULT_LOCALE, mode });

  if (!options.quiet) {
    console.log(
      `[wellformed] seeded workspace with the demo ${mode === 'full' ? 'workspace' : 'structure'}`,
    );
  }

  return { created: true };
}