mirror of
https://github.com/standardnotes/server
synced 2026-07-14 00:01:54 -04:00
* feat: extract cache entry model to domain-core * fix(auth): rename cache table to be auth specific
33 lines
1012 B
TypeScript
33 lines
1012 B
TypeScript
import { CacheEntry, MapperInterface, UniqueEntityId } from '@standardnotes/domain-core'
|
|
|
|
import { TypeORMCacheEntry } from '../Infra/TypeORM/TypeORMCacheEntry'
|
|
|
|
export class CacheEntryPersistenceMapper implements MapperInterface<CacheEntry, TypeORMCacheEntry> {
|
|
toDomain(projection: TypeORMCacheEntry): CacheEntry {
|
|
const cacheEntryOrError = CacheEntry.create(
|
|
{
|
|
key: projection.key,
|
|
value: projection.value,
|
|
expiresAt: projection.expiresAt,
|
|
},
|
|
new UniqueEntityId(projection.uuid),
|
|
)
|
|
if (cacheEntryOrError.isFailed()) {
|
|
throw new Error(`CacheEntryPersistenceMapper.toDomain: ${cacheEntryOrError.getError()}`)
|
|
}
|
|
|
|
return cacheEntryOrError.getValue()
|
|
}
|
|
|
|
toProjection(domain: CacheEntry): TypeORMCacheEntry {
|
|
const typeorm = new TypeORMCacheEntry()
|
|
|
|
typeorm.uuid = domain.id.toString()
|
|
typeorm.key = domain.props.key
|
|
typeorm.value = domain.props.value
|
|
typeorm.expiresAt = domain.props.expiresAt
|
|
|
|
return typeorm
|
|
}
|
|
}
|