import { CollectionInstance } from './Collection.js'; import { DocInstance } from './Doc.js'; import { GlobalConfig, ModuleConfig } from './types/config.js'; /** Any of the possible collection paths used so far */ export type CollectionName = string; /** * This is the global Magnetar instance that is returned when instantiating with Magnetar() */ export type MagnetarInstance = { globalConfig: Required; /** * @see {@link CollectionFn} */ collection: CollectionFn; /** * @see {@link DocFn} */ doc: DocFn; /** * Clear all data of the entire Magnetar instance * * You can exclude any collection when clearing data * @example * ```ts * magnetar.clearAllData({ exclude: ['users'] }) * ``` */ clearAllData: ( /** * You can exclude any collection when clearing data * @example * ```ts * magnetar.clearAllData({ exclude: ['users'] }) * ``` */ options?: { exclude?: CollectionName[]; }) => Promise; /** * Close all streams of the entire Magnetar instance * * You can exclude any collection when closing streams * @example * ```ts * magnetar.closeAllStreams({ exclude: ['users'] }) * ``` */ closeAllStreams: ( /** * You can exclude any collection when closing streams * @example * ```ts * magnetar.closeAllStreams({ exclude: ['users'] }) * ``` */ options?: { exclude?: CollectionName[]; }) => Promise; }; /** * The write lock promise that is resolved x seconds after the final write action has resolved */ export type WriteLock = { /** To be resolved after the countdown after the last write action finishes */ promise: null | Promise; /** Resolves the `WriteLock['promise']` */ resolve: () => any; /** To be started after every write action & To be reset when a new write action occurs */ countdown: null | ReturnType; }; /** * This is the `collection()` method type. * @see {@link CollectionInstance} */ export type CollectionFn = (idOrPath: string, moduleConfig?: ModuleConfig) => CollectionInstance; /** * This is the `doc()` method type. * @see {@link DocInstance} */ export type DocFn = (idOrPath: string, moduleConfig?: ModuleConfig) => DocInstance;