refactor: front end code to unified design

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-06-28 12:21:09 -04:00
parent 08c1de9723
commit 80a8dac2fd
21 changed files with 1087 additions and 1151 deletions
+32 -16
View File
@@ -7,7 +7,8 @@ import { defineStore } from 'pinia'
import { serviceService } from '../services'
import { ServiceObject } from '../models/service'
import type {
SourceSelector,
CollectionIdentifier,
ServiceIdentifier,
ServiceInterface,
} from '../types'
@@ -55,20 +56,30 @@ export const useServicesStore = defineStore('chronoServicesStore', () => {
* @returns Service object or null
*/
function service(provider: string, identifier: string | number, retrieve: boolean = false): ServiceObject | null {
const key = identifierKey(provider, identifier)
if (retrieve === true && !_services.value[key]) {
console.debug(`[Chrono Manager][Store] - Force fetching service "${key}"`)
fetch(provider, identifier)
return serviceByIdentifier(identifierKey(provider, identifier), retrieve)
}
/**
* Get a service from store by its unique identifier, with optional retrieval
*/
function serviceByIdentifier(identifier: ServiceIdentifier, retrieve: boolean = false): ServiceObject | null {
if (retrieve === true && !_services.value[identifier]) {
console.debug(`[Chrono Manager][Store] - Force fetching service "${identifier}"`)
const separatorIndex = identifier.indexOf(':')
const provider = identifier.slice(0, separatorIndex)
const serviceIdentifier = identifier.slice(separatorIndex + 1)
void fetch(provider, serviceIdentifier)
}
return _services.value[key] || null
return _services.value[identifier] ?? null
}
/**
* Unique key for a service
*/
function identifierKey(provider: string, identifier: string | number | null): string {
return `${provider}:${identifier ?? ''}`
function identifierKey(provider: string, identifier: string | number | null): ServiceIdentifier {
return `${provider}:${identifier ?? ''}` as ServiceIdentifier
}
// Actions
@@ -80,10 +91,10 @@ export const useServicesStore = defineStore('chronoServicesStore', () => {
*
* @returns Promise with service object list keyed by provider and service identifier
*/
async function list(sources?: SourceSelector): Promise<Record<string, ServiceObject>> {
async function list(targets?: ServiceIdentifier[] | CollectionIdentifier[]): Promise<Record<string, ServiceObject>> {
transceiving.value = true
try {
const response = await serviceService.list({ sources })
const response = await serviceService.list({ targets })
// Flatten nested structure: provider-id: { service-id: object } -> "provider-id:service-id": object
const services: Record<string, ServiceObject> = {}
@@ -141,12 +152,12 @@ export const useServicesStore = defineStore('chronoServicesStore', () => {
*
* @returns Promise with service availability status
*/
async function extant(sources: SourceSelector) {
async function extant(targets: ServiceIdentifier[]) {
transceiving.value = true
try {
const response = await serviceService.extant({ sources })
const response = await serviceService.extant({ targets })
console.debug('[Chrono Manager][Store] - Successfully checked', sources ? Object.keys(sources).length : 0, 'services')
console.debug('[Chrono Manager][Store] - Successfully checked', targets?.length ?? 0, 'services')
return response
} catch (error: any) {
console.error('[Chrono Manager][Store] - Failed to check services:', error)
@@ -192,10 +203,14 @@ export const useServicesStore = defineStore('chronoServicesStore', () => {
*
* @returns Promise with updated service object
*/
async function update(provider: string, identifier: string | number, data: Partial<ServiceInterface>): Promise<ServiceObject> {
async function update(provider: string, identifier: string | number, delta: boolean, data: ServiceObject | Partial<ServiceInterface>): Promise<ServiceObject> {
transceiving.value = true
try {
const service = await serviceService.update({ provider, identifier, data })
const payload: Partial<ServiceInterface> = data instanceof ServiceObject
? (delta ? data.toJson(true) : data.toJson())
: data
const service = await serviceService.update({ provider, identifier, delta, data: payload })
// Merge updated service into state
const key = identifierKey(service.provider, service.identifier)
@@ -249,6 +264,7 @@ export const useServicesStore = defineStore('chronoServicesStore', () => {
// Actions
service,
serviceByIdentifier,
list,
fetch,
extant,