@fjell/core
Version:
Core Item and Key Framework for Fjell
55 lines (54 loc) • 4.13 kB
TypeScript
import { ComKey, ItemTypeArray, LocKeyArray, PriKey } from '@fjell/types';
import { BaseEvent } from './events';
import { Subscription } from './subscription';
/**
* Core subscription matching logic.
* Determines whether an event should be delivered to a specific subscription.
*/
export declare function doesEventMatchSubscription<S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(event: BaseEvent<S, L1, L2, L3, L4, L5>, subscription: Subscription<S, L1, L2, L3, L4, L5>): boolean;
/**
* Check if event scopes match subscription scope requirements.
*
* @param eventScopes - Scopes from the event (e.g., ["firestore"])
* @param subscriptionScopes - Optional scopes required by subscription
* @returns true if scopes are compatible
*/
export declare function doesScopeMatch(eventScopes: string[], subscriptionScopes?: string[]): boolean;
/**
* Check if event type matches subscription event type requirements.
*
* @param eventType - Type from the event (e.g., "create", "update")
* @param subscriptionEventTypes - Optional event types required by subscription
* @returns true if event type is compatible
*/
export declare function doesEventTypeMatch(eventType: string, subscriptionEventTypes?: string[]): boolean;
/**
* Check if two keys are exactly equal.
* Used for item-based subscriptions that want events for a specific key.
*/
export declare function doesKeyMatch<S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(eventKey: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>, subscriptionKey: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>): boolean;
/**
* Check if an event key matches a location-based subscription.
* This is more complex as it needs to determine if the event key is "within" the subscription location.
*/
export declare function doesKeyMatchLocation<S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(eventKey: PriKey<S> | ComKey<S, L1, L2, L3, L4, L5>, subscriptionKta: ItemTypeArray<S, L1, L2, L3, L4, L5>, subscriptionLocation: LocKeyArray<L1, L2, L3, L4, L5>): boolean;
/**
* Check if an event's location keys match a subscription's location requirements.
* This implements the hierarchical location matching logic.
*/
export declare function doesLocationMatch<L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(eventLocation: LocKeyArray<L1, L2, L3, L4, L5>, subscriptionLocation: LocKeyArray<L1, L2, L3, L4, L5>, _subscriptionKta: ItemTypeArray<string, L1, L2, L3, L4, L5>): boolean;
/**
* Find all subscriptions that match a given event.
* Used by EventSubscriber implementations to determine which subscriptions should receive an event.
*/
export declare function findMatchingSubscriptions<S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(event: BaseEvent<S, L1, L2, L3, L4, L5>, subscriptions: Subscription<S, L1, L2, L3, L4, L5>[]): Subscription<S, L1, L2, L3, L4, L5>[];
/**
* Utility function to extract the location from a ComKey for comparison purposes.
* Returns the location key values as strings for easier comparison.
*/
export declare function extractLocationValues<L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(location: LocKeyArray<L1, L2, L3, L4, L5>): string[];
/**
* Utility function to compare two location arrays by their values.
* Useful for debugging and testing location matching logic.
*/
export declare function compareLocationValues<L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(location1: LocKeyArray<L1, L2, L3, L4, L5>, location2: LocKeyArray<L1, L2, L3, L4, L5>): boolean;