testing local-first datastores
1export interface Metadata {
2 id: string;
3 key: string;
4 value: string | number | boolean;
5 category: string;
6 timestamp: number;
7}
8
9const CATEGORIES = [
10 'analytics', 'user', 'system', 'config', 'cache', 'session',
11 'event', 'metric', 'log', 'audit', 'preference', 'state'
12];
13
14const KEY_PREFIXES = [
15 'page_view', 'click', 'session', 'user_action', 'api_call',
16 'error', 'warning', 'info', 'debug', 'performance', 'conversion'
17];
18
19function randomCategory(): string {
20 return CATEGORIES[Math.floor(Math.random() * CATEGORIES.length)];
21}
22
23function randomKey(index: number): string {
24 const prefix = KEY_PREFIXES[Math.floor(Math.random() * KEY_PREFIXES.length)];
25 return `${prefix}_${index % 1000}`;
26}
27
28function randomValue(): string | number | boolean {
29 const type = Math.floor(Math.random() * 3);
30 switch (type) {
31 case 0:
32 return Math.floor(Math.random() * 10000);
33 case 1:
34 return Math.random() > 0.5;
35 default:
36 return `value_${Math.floor(Math.random() * 1000)}`;
37 }
38}
39
40export function generateMetadata(count: number): Metadata[] {
41 const metadata: Metadata[] = [];
42 const baseTime = Date.now();
43
44 for (let i = 0; i < count; i++) {
45 const id = String(i).padStart(6, '0');
46
47 metadata.push({
48 id: `meta-${id}`,
49 key: randomKey(i),
50 value: randomValue(),
51 category: randomCategory(),
52 timestamp: baseTime - (count - i) * 100
53 });
54 }
55
56 return metadata;
57}