react-epson-epos-sdk
Version:
React library for managing Epson printers with ePOS SDK support.
38 lines (37 loc) • 2 kB
TypeScript
import type { Dispatch, RefObject, SetStateAction } from "react";
import { Printer } from "../../components/Printer";
import type { PrinterConfig } from "../printer.types";
import { createPrintForId } from "./createPrintForId";
import type { PrinterRuntimeState, UnprintedQueueEntry } from "./internalTypes";
import { ConnectionStatus, PrintResult } from "../PrinterProvider.enum";
export type PrintFn = (opts?: {
retryOnError?: boolean;
}) => Promise<{
printResult: PrintResult;
}>;
export type PrinterRegistry = {
printersRef: RefObject<PrinterConfig[]>;
printersKey: string;
printerIdSet: ReadonlySet<string>;
instanceEpoch: number;
instancesRef: RefObject<Map<string, Printer>>;
/** Source of truth for per-id status. Read via `getStatusForId`; mutate via `setStatusForId`. */
statusByIdRef: RefObject<Map<string, PrinterRuntimeState>>;
/** Bumps on every real status change. Used as a re-run trigger by internal effects; NOT exposed to consumers. */
statusVersion: number;
subscribeToStatus: (id: string, callback: () => void) => () => void;
getStatusForId: (id: string) => ConnectionStatus;
unprintedById: Record<string, UnprintedQueueEntry[]>;
setStatusForId: (id: string, status: ConnectionStatus) => void;
printForId: ReturnType<typeof createPrintForId>;
/** Returns a stable per-id `print` wrapper. Same reference across renders for the same id. */
getPrintForId: (id: string) => PrintFn;
setUnprintedById: Dispatch<SetStateAction<Record<string, UnprintedQueueEntry[]>>>;
};
/**
* Holds printer instances, the per-id status store, retry queues, and `printForId`.
* Status lives in a ref-backed pub/sub store so heartbeat ticks don't re-render
* consumers of unrelated ids. `printersKey` only changes when the effective
* printer list/config changes (not when the array reference alone changes).
*/
export declare function usePrinterRegistry(printers: PrinterConfig[], testMode?: boolean): PrinterRegistry;