import type { Unsubscribe, Persistor } from '@segment/sovran-react-native'; import type { SegmentAPIConsentSettings, EdgeFunctionSettings } from '..'; import type { Context, DeepPartial, DestinationFilters, IntegrationSettings, RoutingRule, SegmentAPIIntegrations, SegmentEvent, UserInfoState, } from '../types'; export interface getStateFunc { (): T; (safe: true): Promise; } /** * Implements a value that can be subscribed for changes */ export interface Watchable { /** * Get current value */ get: getStateFunc; /** * Register a callback to be called when the value changes * @returns a function to unsubscribe */ onChange: (callback: (value: T) => void) => Unsubscribe; } /** * Implements a value that can be set */ export interface Settable { set: (value: T | ((state: T) => T)) => T | Promise; } /** * Implements a queue object */ export interface Queue { add: (value: T) => Promise; remove: (value: T) => Promise; } /** * Implements a map of key value pairs */ export interface Dictionary { add: (key: K, value: T) => Promise; } export interface ReadinessStore { hasRestoredContext: boolean; hasRestoredSettings: boolean; hasRestoredUserInfo: boolean; hasRestoredFilters: boolean; hasRestoredPendingEvents: boolean; hasRestoredEnabled: boolean; hasRestoredRunning: boolean; } /** * Interface for interacting with the storage layer of the client data */ export interface Storage { readonly isReady: Watchable; readonly context: Watchable | undefined> & Settable>; readonly settings: Watchable & Settable & Dictionary; readonly consentSettings: Watchable & Settable; readonly edgeFunctionSettings: Watchable & Settable; readonly filters: Watchable & Settable & Dictionary; readonly userInfo: Watchable & Settable; readonly deepLinkData: Watchable; readonly pendingEvents: Watchable & Settable & Queue; readonly enabled: Watchable & Settable; readonly running: Watchable & Settable; } export type DeepLinkData = { referring_application: string; url: string; }; export type StorageConfig = { storeId: string; storePersistor?: Persistor; storePersistorSaveDelay?: number; };