UNPKG

@just-in/core

Version:

A TypeScript-first framework for building adaptive digital health interventions.

163 lines 7.45 kB
import { logLevels } from './logger/logger-manager'; import { TaskRegistration, DecisionRuleRegistration, RecordResultFunction } from './handlers/handler.type'; import { DBType } from './data-manager/data-manager.constants'; import { Logger } from './logger/logger.interface'; import { IntervalTimerEventGenerator } from './event/interval-timer-event-generator'; import { IntervalTimerEventGeneratorOptions } from './event/event.type'; import { NewUserRecord, JUser } from './user-manager/user.type'; /** * JustInWrapper class provides a unified interface for managing application-level configurations, * event registrations, data manager initialization, and orchestrating the event queue for processing. */ export declare class JustInWrapper { protected static instance: JustInWrapper | null; private dataManager; private eventHandlerManager; private isInitialized; private initializedAt; private intervalTimerEventGenerators; protected constructor(); /** * Retrieves the singleton instance of JustInWrapper. * @returns {JustInWrapper} The singleton instance. */ static getInstance(): JustInWrapper; /** * Deletes the singleton instance of JustInWrapper. */ static killInstance(): void; /** * Returns the initialization status of the JustInWrapper. * @returns {boolean} The initialization status. */ getInitializationStatus(): boolean; /** * Initializes the DataManager and UserManager, setting up the database connection. * This should be called before any operations that depend on the database. * @param {DBType} dbType - The type of database to initialize (default is MongoDB). * @returns {Promise<void>} */ init(dbType?: DBType): Promise<void>; /** * Shuts down data manager, user manager, and event queue. * Clears all interval timer event generators and event handlers. * This should be called when the application is shutting down. */ shutdown(): Promise<void>; /** * Starts the event queue engine, processing all queued events. * This should be called after init(). */ startEngine(): Promise<void>; /** * Stops the engine, halts event processing, and unregisters all clock events. * This can be called to stop the engine without shutting down the application. */ stopEngine(): Promise<void>; /** * Adds a list of new users to the database. * @param {NewUserRecord[]} users - The list of new users to add. * @returns {Promise<(JUser | null)[]>} The list of added users, or null if not found. */ addUsers(users: NewUserRecord[]): Promise<(JUser | null)[]>; /** * Retrieves a list of users from the database. * @returns {Promise<(JUser | null)[]>} The list of users, or null if not found. */ getAllUsers(): Promise<(JUser | null)[]>; /** * Adds a new user to the database. * @param {NewUserRecord} newUserRecord - The new user record to add. * @returns {Promise<JUser>} The added user. */ addUser(newUserRecord: NewUserRecord): Promise<JUser | null>; /** * Retrieves a user from the database by their unique identifier. * @param {string} uniqueIdentifier - The unique identifier of the user. * @returns {Promise<JUser | null>} The user, or null if not found. */ getUser(uniqueIdentifier: string): Promise<JUser | null>; /** * Retrieves a user from the database by their unique identifier. * @param {string} uniqueIdentifier - The unique identifier of the user. * @param {Record<string, any>} attributesToUpdate - The attributes to update in the user record. * @returns {Promise<JUser | null>} The user, or null if not found. */ updateUser(uniqueIdentifier: string, attributesToUpdate: Record<string, any>): Promise<JUser | null>; /** * Deletes a user from the database by their unique identifier. * @param {string} uniqueIdentifier - The unique identifier of the user. * @returns {Promise<void>} A promise that resolves when the user is deleted. */ deleteUser(uniqueIdentifier: string): Promise<void>; /** * Registers a new event type and adds it to the queue. * @param {string} eventType - The type of the event. * @param {string[]} handlers - The ordered task or decision rule names for the event. */ registerEventHandlers(eventType: string, handlers: string[]): Promise<void>; /** * Unregisters an existing event by name. * @param {string} eventType - The type of the event to unregister. */ unregisterEventHandlers(eventType: string): void; /** * Creates a new interval timer event generator. * @param {string} eventTypeName - The name of the event type. * @param {number} intervalInMs - The interval in milliseconds. * @param {IntervalTimerEventGeneratorOptions} options - The options for the event generator. */ createIntervalTimerEventGenerator(eventTypeName: string, intervalInMs: number, options?: IntervalTimerEventGeneratorOptions): void; /** * Returns the interval timer event generators. * @returns {Map<string, IntervalTimerEventGenerator>} The interval timer event generators. */ getIntervalTimerEventGenerators(): Map<string, IntervalTimerEventGenerator>; /** * Publishes an event, adding it to the processing queue. * @param {string} eventType - The type of the event. * @param {Date} generatedTimestamp - The timestamp of the event. * @param {object} eventDetails - The details of the event instance. * NOTE: publishEventDetails expects a Record, * but I don't think we want to expose this to 3PDs */ publishEvent(eventType: string, generatedTimestamp: Date, eventDetails?: object): Promise<void>; /** * Sets up the event queue listener. */ setupEventQueueListener(): void; /** * Registers a new task within the framework. * @param {TaskRegistration} task - The task to register. */ registerTask(task: TaskRegistration): void; /** * Registers a new decision rule within the framework. * @param {DecisionRuleRegistration} decisionRule - The decision rule to register. */ registerDecisionRule(decisionRule: DecisionRuleRegistration): void; /** * Configures the logger with a custom logger instance. * @param {Logger} logger - The logger implementation to use. */ configureLogger(logger: Logger): void; /** * Configures the writer for a task result with a custom function. * Will default to writing to the db * @param {RecordResultFunction} taskWriter - The function to take in the results of a task */ configureTaskResultWriter(taskWriter: RecordResultFunction): void; /** * Configures the writer for a decision rule result with a custom function. * Will default to writing to the db * @param {RecordResultFunction} decisionRuleWriter - The function to take in the results of a task */ configureDecisionRuleResultWriter(decisionRuleWriter: RecordResultFunction): void; /** * Sets the logging levels for the application. * @param levels - The logging levels to enable or disable. */ setLoggingLevels(levels: Partial<typeof logLevels>): void; } export declare const JustIn: () => JustInWrapper; //# sourceMappingURL=JustInWrapper.d.ts.map