UUID utilities
UUID utilities provide a robust solution for generating UUIDs within your application, offering both immediate and remote generation methods, with an optional logging feature for development and debugging purposes.
Key Features
- UUID Generation: Uses the
uuidv4
library to generate UUIDs, ensuring uniqueness and compliance with the UUID v4 standard. - Logging Capability: Offers an optional parameter to log generated UUIDs, aiding in debugging and tracking ID generation.
- Configurable Service: While the current implementation directly uses
uuidv4
, future enhancements may include customizable configurations for UUID generation.
Use cases
This module is designed for:
- Generating a Universally Unique Identifier
Interfaces and services
UUIDConfig
Interface: Intended for future use to customize UUID generation through configuration options.UUID
Interface: Defines the contract for UUID generation services, including methods for creating IDs and remote IDs, with optional logging.UUIDService
Class: Implements theUUID
interface, providing default behavior for UUID generation and logging.
Examples
Generating a UUID
import { UUID } from '@genesislcap/foundation-utils';
import { GenesisElement } from '@genesislcap/web-core';
export class MyExampleComponent extends GenesisElement {
@UUID uuid: UUID;
async generateUUID(): string {
return this.uuid.createId(true); // Generates and logs a UUID
}
}
Generating a remote UUID
This method is designed for scenarios where UUID generation might involve server-side logic or validation, though the current implementation is client-side.
import { UUID } from '@genesislcap/foundation-utils';
import { GenesisElement } from '@genesislcap/web-core';
export class MyExampleComponent extends GenesisElement {
@UUID uuid: UUID;
async generateRemoteUUID(): string {
const remoteUUID = await this.uuid.createRemoteId(true); // Generates and logs a remote UUID
return remoteUUID;
}
}
Key points
- Consider UUID Uniqueness Requirements: Ensure the UUID generation strategy meets your application's requirements for uniqueness and randomness.
- Plan for Configuration Enhancements: While the
UUIDConfig
interface is a placeholder, anticipate future needs for configurable UUID generation to accommodate different scenarios or integration with back-end services.