@asaidimu/utils-database 3.1.4 → 3.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.mts CHANGED
@@ -738,7 +738,8 @@ declare class IndexedDBStore<T extends Record<string, any>> implements Store<T>
738
738
  */
739
739
  declare const createIndexedDbStore: <T extends Record<string, any>>(config: StoreConfig) => Store<T>;
740
740
 
741
- declare function DatabaseConnection(config: Omit<DatabaseConfig, "keyPath">, createStore: <T extends Record<string, any>>(config: StoreConfig, indexes: IndexDefinition[]) => Store<T>): Promise<Database>;
741
+ type StoreFactory = <T extends Record<string, any>>(config: StoreConfig, indexes: IndexDefinition[]) => Store<T>;
742
+ declare function DatabaseConnection(config: Omit<DatabaseConfig, "keyPath">, createStore: StoreFactory): Promise<Database>;
742
743
 
743
744
  interface MutexOptions {
744
745
  /**
@@ -816,16 +817,18 @@ interface EventBus<TEventMap extends Record<string, any>> {
816
817
  * Subscribes to a specific event by name.
817
818
  * @param eventName - The name of the event to subscribe to.
818
819
  * @param callback - The function to call when the event is emitted.
820
+ * @param options - Extra options to determine the behaviour of the
821
+ * subscription
819
822
  * @returns A function to unsubscribe from the event.
820
823
  */
821
- subscribe: <TEventName extends keyof TEventMap>(eventName: TEventName, callback: (payload: TEventMap[TEventName]) => void) => () => void;
824
+ subscribe: <TEventName extends keyof TEventMap>(eventName: TEventName, callback: (payload: TEventMap[TEventName]) => void, options?: SubscribeOptions) => () => void;
822
825
  /**
823
826
  * Subscribes to an event and automatically unsubscribes after it fires once.
824
827
  * @param eventName - The name of the event to subscribe to.
825
828
  * @param callback - The function to call when the event is emitted.
826
829
  * @returns A function to cancel the one-shot subscription before it fires.
827
830
  */
828
- once: <TEventName extends keyof TEventMap>(eventName: TEventName, callback: (payload: TEventMap[TEventName]) => void) => () => void;
831
+ once: <TEventName extends keyof TEventMap>(eventName: TEventName, callback: (payload: TEventMap[TEventName]) => void, options?: SubscribeOptions) => () => void;
829
832
  /**
830
833
  * Emits an event with a payload to all subscribed listeners.
831
834
  * @param event - An object containing the event name and payload.
@@ -859,6 +862,14 @@ interface EventMetrics {
859
862
  /** Average duration of event dispatch in milliseconds. */
860
863
  averageEmitDuration: number;
861
864
  }
865
+ interface SubscribeOptions {
866
+ /**
867
+ * Debounce delay in milliseconds. When multiple events arrive in quick
868
+ * succession, the callback runs only after the quiet period ends, using the
869
+ * latest payload. Default = no debouncing.
870
+ */
871
+ debounce?: number;
872
+ }
862
873
 
863
874
  interface MiddlewareContext {
864
875
  collection?: string;
@@ -967,4 +978,4 @@ declare class DatabaseError extends Error {
967
978
  constructor(type: DatabaseErrorType, message: string, schema?: SchemaDefinition, cause?: unknown, issues?: any);
968
979
  }
969
980
 
970
- export { type BufferedOperation, type Collection, type CollectionEvent, type CollectionEventType, type CollectionMigrationOptions, ConnectionManager, type CursorCallback, type CursorCallbackResult, type CursorPaginationOptions, DEFAULT_KEYPATH, type Database, type DatabaseConfig, DatabaseConnection, DatabaseError, DatabaseErrorType, type DatabaseEvent, type DatabaseEventType, type Document, type DocumentEvent, type DocumentEventType, type DocumentMetadata, IndexedDBStore, type Store, type StoreConfig, type StoreKeyRange, type TelemetryEvent, type TelemetryEventType, createDocument, createEphemeralStore, createIndexedDbStore, openCollection };
981
+ export { type BufferedOperation, type Collection, type CollectionEvent, type CollectionEventType, type CollectionMigrationOptions, ConnectionManager, type CursorCallback, type CursorCallbackResult, type CursorPaginationOptions, DEFAULT_KEYPATH, type Database, type DatabaseConfig, DatabaseConnection, DatabaseError, DatabaseErrorType, type DatabaseEvent, type DatabaseEventType, type Document, type DocumentEvent, type DocumentEventType, type DocumentMetadata, IndexedDBStore, type Store, type StoreConfig, type StoreFactory, type StoreKeyRange, type TelemetryEvent, type TelemetryEventType, createDocument, createEphemeralStore, createIndexedDbStore, openCollection };
package/index.d.ts CHANGED
@@ -738,7 +738,8 @@ declare class IndexedDBStore<T extends Record<string, any>> implements Store<T>
738
738
  */
739
739
  declare const createIndexedDbStore: <T extends Record<string, any>>(config: StoreConfig) => Store<T>;
740
740
 
741
- declare function DatabaseConnection(config: Omit<DatabaseConfig, "keyPath">, createStore: <T extends Record<string, any>>(config: StoreConfig, indexes: IndexDefinition[]) => Store<T>): Promise<Database>;
741
+ type StoreFactory = <T extends Record<string, any>>(config: StoreConfig, indexes: IndexDefinition[]) => Store<T>;
742
+ declare function DatabaseConnection(config: Omit<DatabaseConfig, "keyPath">, createStore: StoreFactory): Promise<Database>;
742
743
 
743
744
  interface MutexOptions {
744
745
  /**
@@ -816,16 +817,18 @@ interface EventBus<TEventMap extends Record<string, any>> {
816
817
  * Subscribes to a specific event by name.
817
818
  * @param eventName - The name of the event to subscribe to.
818
819
  * @param callback - The function to call when the event is emitted.
820
+ * @param options - Extra options to determine the behaviour of the
821
+ * subscription
819
822
  * @returns A function to unsubscribe from the event.
820
823
  */
821
- subscribe: <TEventName extends keyof TEventMap>(eventName: TEventName, callback: (payload: TEventMap[TEventName]) => void) => () => void;
824
+ subscribe: <TEventName extends keyof TEventMap>(eventName: TEventName, callback: (payload: TEventMap[TEventName]) => void, options?: SubscribeOptions) => () => void;
822
825
  /**
823
826
  * Subscribes to an event and automatically unsubscribes after it fires once.
824
827
  * @param eventName - The name of the event to subscribe to.
825
828
  * @param callback - The function to call when the event is emitted.
826
829
  * @returns A function to cancel the one-shot subscription before it fires.
827
830
  */
828
- once: <TEventName extends keyof TEventMap>(eventName: TEventName, callback: (payload: TEventMap[TEventName]) => void) => () => void;
831
+ once: <TEventName extends keyof TEventMap>(eventName: TEventName, callback: (payload: TEventMap[TEventName]) => void, options?: SubscribeOptions) => () => void;
829
832
  /**
830
833
  * Emits an event with a payload to all subscribed listeners.
831
834
  * @param event - An object containing the event name and payload.
@@ -859,6 +862,14 @@ interface EventMetrics {
859
862
  /** Average duration of event dispatch in milliseconds. */
860
863
  averageEmitDuration: number;
861
864
  }
865
+ interface SubscribeOptions {
866
+ /**
867
+ * Debounce delay in milliseconds. When multiple events arrive in quick
868
+ * succession, the callback runs only after the quiet period ends, using the
869
+ * latest payload. Default = no debouncing.
870
+ */
871
+ debounce?: number;
872
+ }
862
873
 
863
874
  interface MiddlewareContext {
864
875
  collection?: string;
@@ -967,4 +978,4 @@ declare class DatabaseError extends Error {
967
978
  constructor(type: DatabaseErrorType, message: string, schema?: SchemaDefinition, cause?: unknown, issues?: any);
968
979
  }
969
980
 
970
- export { type BufferedOperation, type Collection, type CollectionEvent, type CollectionEventType, type CollectionMigrationOptions, ConnectionManager, type CursorCallback, type CursorCallbackResult, type CursorPaginationOptions, DEFAULT_KEYPATH, type Database, type DatabaseConfig, DatabaseConnection, DatabaseError, DatabaseErrorType, type DatabaseEvent, type DatabaseEventType, type Document, type DocumentEvent, type DocumentEventType, type DocumentMetadata, IndexedDBStore, type Store, type StoreConfig, type StoreKeyRange, type TelemetryEvent, type TelemetryEventType, createDocument, createEphemeralStore, createIndexedDbStore, openCollection };
981
+ export { type BufferedOperation, type Collection, type CollectionEvent, type CollectionEventType, type CollectionMigrationOptions, ConnectionManager, type CursorCallback, type CursorCallbackResult, type CursorPaginationOptions, DEFAULT_KEYPATH, type Database, type DatabaseConfig, DatabaseConnection, DatabaseError, DatabaseErrorType, type DatabaseEvent, type DatabaseEventType, type Document, type DocumentEvent, type DocumentEventType, type DocumentMetadata, IndexedDBStore, type Store, type StoreConfig, type StoreFactory, type StoreKeyRange, type TelemetryEvent, type TelemetryEventType, createDocument, createEphemeralStore, createIndexedDbStore, openCollection };