emr-types
Version:
Comprehensive TypeScript Types Library for Electronic Medical Record (EMR) Applications - Domain-Driven Design with Zod Validation
119 lines • 2.53 kB
JavaScript
/**
* Tenant ID Value Object
*
* Type-safe tenant identifier with validation
*/
import { IdFactory, IdValidator } from '../../shared/value-objects/Id';
/**
* Tenant ID Factory
*/
export const TenantIdFactory = {
/**
* Create a new tenant ID
*/
create() {
return IdFactory.create();
},
/**
* Create tenant ID from string
*/
fromString(value) {
const id = IdFactory.fromString(value);
if (!IdValidator.isValid(id)) {
throw new Error('Invalid tenant ID format');
}
return id;
},
/**
* Create tenant ID from UUID
*/
fromUuid(uuid) {
const id = IdFactory.createUuid(uuid);
return id;
},
/**
* Create tenant ID from ULID
*/
fromUlid(ulid) {
const id = IdFactory.createUlid(ulid);
return id;
},
/**
* Create custom tenant ID
*/
createCustom(value, format) {
const id = IdFactory.createCustom(value, format);
return id;
}
};
/**
* Tenant ID Validator
*/
export const TenantIdValidator = {
/**
* Check if value is a valid tenant ID
*/
isValid(value) {
return IdValidator.isValid(value) && typeof value === 'object' && '__brand' in value;
},
/**
* Validate tenant ID format
*/
validateFormat(value) {
return IdValidator.validateFormat(value);
},
/**
* Check if tenant ID is empty
*/
isEmpty(tenantId) {
return IdValidator.isEmpty(tenantId);
},
/**
* Compare two tenant IDs
*/
areEqual(tenantId1, tenantId2) {
return IdValidator.areEqual(tenantId1, tenantId2);
}
};
/**
* Tenant ID Utilities
*/
export const TenantIdUtils = {
/**
* Convert tenant ID to string
*/
toString(tenantId) {
return tenantId.value;
},
/**
* Get tenant ID type
*/
getType(tenantId) {
return tenantId.type;
},
/**
* Check if tenant ID is UUID
*/
isUuid(tenantId) {
return tenantId.type === 'uuid';
},
/**
* Check if tenant ID is ULID
*/
isUlid(tenantId) {
return tenantId.type === 'ulid';
},
/**
* Check if tenant ID is custom
*/
isCustom(tenantId) {
return tenantId.type === 'custom';
},
/**
* Check if tenant ID is auto-increment
*/
isAutoIncrement(tenantId) {
return tenantId.type === 'auto-increment';
}
};
//# sourceMappingURL=TenantId.js.map