managarten/packages/shared-links/src/store.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

40 lines
1,004 B
TypeScript

/**
* ManaLink — Local-First Store
*
* Creates a shared IndexedDB database ('manacore-links') that all apps
* can read from. Links are synced to the server via mana-sync.
*/
import { createLocalStore } from '@manacore/local-store';
import type { LocalManaLink } from './types.js';
const SYNC_SERVER_URL =
(typeof window !== 'undefined' &&
(window as unknown as { __PUBLIC_SYNC_SERVER_URL__?: string }).__PUBLIC_SYNC_SERVER_URL__) ||
(typeof import.meta !== 'undefined' && import.meta.env?.PUBLIC_SYNC_SERVER_URL) ||
'http://localhost:3050';
export const linkLocalStore = createLocalStore({
appId: 'links',
collections: [
{
name: 'links',
indexes: [
'pairId',
'direction',
'sourceApp',
'sourceId',
'targetApp',
'targetId',
'linkType',
'[sourceApp+sourceId]',
'[sourceApp+sourceCollection+sourceId]',
],
},
],
sync: {
serverUrl: SYNC_SERVER_URL,
},
});
export const linkCollection = linkLocalStore.collection<LocalManaLink>('links');