SKILL.md--- name: uuid description: 'UUID generation skill - Universally Unique Identifiers v4 and v7 for entity IDs. For ng-events construction site progress tracking system.' --- # UUID - Universally Unique Identifiers Trigger patterns: "UUID", "unique ID", "identifier", "v4", "v7", "uuidv4", "uuidv7" ## Overview UUID library for generating RFC9562-compliant unique identifiers in JavaScript/TypeScript applications. **Package**: uuid@13.0.0 **Standard**: RFC9562 (formerly RFC4122) ## Core Functions ### 1. v4() - Random UUID (Most Common) Generates a version 4 UUID using cryptographically secure random values. ```typescript import { v4 as uuidv4 } from 'uuid'; // Generate random UUID const taskId = uuidv4(); // '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d' // Use in entity creation interface Task { id: string; title: string; createdAt: Date; } function createTask(title: string): Task { return { id: uuidv4(), title, createdAt: new Date() }; } ``` **When to use**: - Entity IDs (tasks, users, blueprints) - Session IDs - Request tracking IDs - File upload IDs - Any unique identifier needs ### 2. v7() - Timestamp-based UUID (Sortable) Generates a version 7 UUID with Unix epoch timestamp for natural chronological sorting. ```typescript import { v7 as uuidv7 } from 'uuid'; // Generate timestamp-based UUID const orderId = uuidv7(); // '019a26ab-9a66-71a9-a89e-63c35fce4a5a' // Multiple UUIDs are naturally sortable const ids = Array.from({ length: 5 }, () => uuidv7()); // All IDs will be in chronological order // Use for database primary keys interface Order { id: string; // v7 UUID - sortable by creation time customerId: string; createdAt: Date; } ``` **When to use**: - Database primary keys requiring chronological sorting - Event IDs in time-series data - Log entry IDs - Audit trail records - Any scenario where temporal ordering matters **Advantages**: - Natural sort order by creation time - Better database index performance - Reduced fragmentation in B-tree indexes - Compatible with UUID v4 in storage/APIs ## Real-World Examples ### Task Repository with UUID ```typescript import { Injectable, inject } from '@angular/core'; import { Firestore, collection, doc, setDoc, getDoc } from '@angular/fire/firestore'; import { v4 as uuidv4 } from 'uuid'; export interface Task { id: string; blueprintId: string; title: string; description: string; status: 'pending' | 'in-progress' | 'completed'; createdAt: Date; updatedAt: Date; } @Injectable({ providedIn: 'root' }) export class TaskRepository { private firestore = inject(Firestore); private tasksCollection = collection(this.firestore, 'tasks'); /** * Create task with UUID v4 */ async create(task: Omit<Task, 'id' | 'createdAt' | 'updatedAt'>): Promise<Task> { const id = uuidv4(); // Generate unique ID const now = new Date(); const newTask: Task = { ...task, id, createdAt: now, updatedAt: now }; const docRef = doc(this.tasksCollectio