@just-in/core
Version:
A TypeScript-first framework for building adaptive digital health interventions.
69 lines • 3.34 kB
TypeScript
import { logLevels } from './logger/logger-manager';
import type { TaskRegistration, DecisionRuleRegistration, RecordResultFunction } from './handlers/handler.type';
import type { Logger } from './logger/logger.interface';
import type { JUser, NewUserRecord } from './user-manager/user.type';
/**
* JustInLiteWrapper provides a minimal, serverless-oriented interface for 3rd-party apps:
* - configure logger & result writers
* - register tasks, decision rules, and event handlers
* - keep users in-memory for the current warm instance
* - run registered events immediately (no DB/queue)
*/
export declare class JustInLiteWrapper {
protected static instance: JustInLiteWrapper | null;
/** In-memory idempotency (per warm instance only). */
private processedKeys;
private eventHandlerManager;
/** In-memory users for this warm instance (keyed by uniqueIdentifier). */
private users;
protected constructor();
/** Returns the singleton Lite instance. */
static getInstance(): JustInLiteWrapper;
/**
* Reset the singleton (useful for tests).
* Includes a 1-tick drain to let any late recorder promises settle.
*/
killInstance(): Promise<void>;
/**
* Static teardown helper for tests/tools.
* If an instance exists, delegate to it; otherwise do a best-effort drain+clear.
* Safe to call multiple times.
*/
static killInstance(): Promise<void>;
/**
* Loads users for the current invocation (serverless-safe).
* Accepts either `JUser[]` or `NewUserRecord[]`.
* Replaces the in-memory set each call (atomic), requires `uniqueIdentifier`,
* and throws on duplicates. Returns the normalized `JUser[]`.
*/
loadUsers(users: JUser[] | NewUserRecord[]): Promise<JUser[]>;
/** Register a Task. */
registerTask(task: TaskRegistration): void;
/** Register a Decision Rule. */
registerDecisionRule(decisionRule: DecisionRuleRegistration): void;
/**
* Registers a new event type with ordered handler names.
* Also caches the definition locally for introspection.
* @param eventType - The type of the event.
* @param handlers - Ordered task/decision-rule names for the event.
*/
registerEventHandlers(eventType: string, handlers: string[]): Promise<void>;
/** Unregister handlers for an event type. */
unregisterEventHandlers(eventType: string): void;
/**
* Publish (execute) a registered event for the **currently loaded** users.
* Signature matches full JustIn; `idempotencyKey` is optional (in-memory only).
*
* @param eventType Registered event type.
* @param generatedTimestamp Event timestamp.
* @param eventDetails Optional event details payload.
* @param idempotencyKey Optional in-memory dedupe key (skips if seen).
*/
publishEvent(eventType: string, generatedTimestamp: Date, eventDetails?: object, idempotencyKey?: string): Promise<void>;
configureLogger(logger: Logger): void;
configureTaskResultWriter(taskWriter: RecordResultFunction): void;
configureDecisionRuleResultWriter(decisionRuleWriter: RecordResultFunction): void;
setLoggingLevels(levels: Partial<typeof logLevels>): void;
}
export declare const JustInLite: () => JustInLiteWrapper;
//# sourceMappingURL=JustInLite.d.ts.map