feat: replace flat context with tuple-keyed store (#50)

Context keys are now tuples instead of strings, inspired by
React Query's query keys. This prevents context collisions
when multiple instances of the same source type are registered.

Sources write to structured keys like
["aris.google-calendar", "nextEvent", { account: "work" }]
and consumers can query by prefix via context.find().

Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
2026-03-01 22:52:41 +00:00
committed by GitHub
parent 8ca8a0d1d2
commit 96e22e227c
29 changed files with 544 additions and 227 deletions

View File

@@ -1,5 +1,4 @@
import type { Context } from "@aris/core"
import { Context } from "@aris/core"
import { LocationKey, type Location } from "@aris/source-location"
import { describe, expect, test } from "bun:test"
@@ -81,9 +80,9 @@ class FixtureTflApi implements ITflApi {
}
function createContext(location?: Location): Context {
const ctx: Context = { time: new Date("2026-01-15T12:00:00Z") }
const ctx = new Context(new Date("2026-01-15T12:00:00Z"))
if (location) {
ctx[LocationKey] = location
ctx.set([[LocationKey, location]])
}
return ctx
}

View File

@@ -1,6 +1,6 @@
import type { ActionDefinition, Context, FeedItemSignals, FeedSource } from "@aris/core"
import type { ActionDefinition, ContextEntry, FeedItemSignals, FeedSource } from "@aris/core"
import { TimeRelevance, UnknownActionError, contextValue } from "@aris/core"
import { Context, TimeRelevance, UnknownActionError } from "@aris/core"
import { LocationKey } from "@aris/source-location"
import { type } from "arktype"
@@ -112,7 +112,7 @@ export class TflSource implements FeedSource<TflAlertFeedItem> {
}
}
async fetchContext(): Promise<null> {
async fetchContext(): Promise<readonly ContextEntry[] | null> {
return null
}
@@ -129,7 +129,7 @@ export class TflSource implements FeedSource<TflAlertFeedItem> {
this.client.fetchStations(),
])
const location = contextValue(context, LocationKey)
const location = context.get(LocationKey)
const items: TflAlertFeedItem[] = statuses.map((status) => {
const closestStationDistance = location