managarten/packages/shared-links/src/resolvers.ts
Till JS 2222ce25e5 feat: add @manacore/shared-links for cross-app record linking
New shared package enabling bidirectional links between records across
apps (e.g. todo→calendar, task→file). Each link creates a forward+reverse
pair sharing a pairId for efficient queries from both sides. Stored in
dedicated IndexedDB (manacore-links), synced via mana-sync.

Includes: types, store, mutations, reactive queries, cached display data
resolvers, ManaLinkBadge and ManaLinkList UI components.

Integrates into Todo app as first consumer — link store initialized in
layout, ManaLinkList rendered in TaskEditModal.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 01:02:42 +02:00

34 lines
976 B
TypeScript

/**
* ManaLink — Display Data Resolvers
*
* Helpers to build cached display data from app metadata.
*/
import { getManaApp } from '@manacore/shared-branding';
import type { AppIconId } from '@manacore/shared-branding';
import type { LinkCachedData } from './types.js';
/**
* Build LinkCachedData from app branding + a title.
* Called by the app creating the link to populate offline-friendly display data.
*/
export function buildCachedData(appId: string, title: string, subtitle?: string): LinkCachedData {
const app = getManaApp(appId as AppIconId);
return {
title,
subtitle,
icon: app?.icon,
color: app?.color,
appName: app?.name,
fetchedAt: new Date().toISOString(),
};
}
/**
* Check if cached data is stale (older than threshold).
* Default: 24 hours.
*/
export function isCacheStale(cached: LinkCachedData, maxAgeMs = 24 * 60 * 60 * 1000): boolean {
const age = Date.now() - new Date(cached.fetchedAt).getTime();
return age > maxAgeMs;
}