@sv443-network/userutils 9.0.2 → 9.0.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @sv443-network/userutils
2
2
 
3
+ ## 9.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - e3f1e6a: Fixed `Debouncer` TS types as to not break backwards compat
8
+ - 5861bb4: Fixed broken ambiguity of DataStore's migration function type
9
+
3
10
  ## 9.0.2
4
11
 
5
12
  ### Patch Changes
@@ -8,7 +8,7 @@
8
8
  // ==UserLibrary==
9
9
  // @name UserUtils
10
10
  // @description Lightweight library with various utilities for userscripts - register listeners for when CSS selectors exist, intercept events, create persistent & synchronous data stores, modify the DOM more easily and much more
11
- // @version 9.0.2
11
+ // @version 9.0.3
12
12
  // @license MIT
13
13
  // @copyright Sv443 (https://github.com/Sv443)
14
14
 
@@ -3,8 +3,10 @@
3
3
  * This module contains the DataStore class, which is a general purpose, sync and async persistent JSON database - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#datastore)
4
4
  */
5
5
  import type { Prettify } from "./types.js";
6
+ /** Function that takes the data in the old format and returns the data in the new format. Also supports an asynchronous migration. */
7
+ type MigrationFunc = (oldData: any) => any | Promise<any>;
6
8
  /** Dictionary of format version numbers and the function that migrates to them from the previous whole integer */
7
- export type DataMigrationsDict = Record<number, ((oldData: unknown) => unknown | Promise<unknown>)>;
9
+ export type DataMigrationsDict = Record<number, MigrationFunc>;
8
10
  /** Options for the DataStore instance */
9
11
  export type DataStoreOptions<TData> = Prettify<{
10
12
  /**
@@ -159,3 +161,4 @@ export declare class DataStore<TData extends object = object> {
159
161
  /** Deletes a value from persistent storage - can be overwritten in a subclass if you want to use something other than the default storage methods */
160
162
  protected deleteValue(name: string): Promise<void>;
161
163
  }
164
+ export {};
@@ -18,11 +18,15 @@ import { NanoEmitter } from "./NanoEmitter.js";
18
18
  * - Calls could get stuck in the queue indefinitely if there is no downtime between calls that is greater than the `timeoutDuration`
19
19
  */
20
20
  export type DebouncerType = "immediate" | "idle";
21
- export type DebouncerFunc<TArgs> = (...args: TArgs[]) => void | unknown;
21
+ type AnyFunc = (...args: any) => any;
22
+ /** The debounced function type that is returned by the {@linkcode debounce} function */
23
+ export type DebouncedFunction<TFunc extends AnyFunc> = ((...args: Parameters<TFunc>) => ReturnType<TFunc>) & {
24
+ debouncer: Debouncer<TFunc>;
25
+ };
22
26
  /** Event map for the {@linkcode Debouncer} */
23
- export type DebouncerEventMap<TArgs> = {
27
+ export type DebouncerEventMap<TFunc extends AnyFunc> = {
24
28
  /** Emitted when the debouncer calls all registered listeners, as a pub-sub alternative */
25
- call: DebouncerFunc<TArgs>;
29
+ call: TFunc;
26
30
  /** Emitted when the timeout or edge type is changed after the instance was created */
27
31
  change: (timeout: number, type: DebouncerType) => void;
28
32
  };
@@ -35,15 +39,15 @@ export type DebouncerEventMap<TArgs> = {
35
39
  * - `call` - emitted when the debouncer calls all listeners - use this as a pub-sub alternative to the default callback-style listeners
36
40
  * - `change` - emitted when the timeout or edge type is changed after the instance was created
37
41
  */
38
- export declare class Debouncer<TArgs> extends NanoEmitter<DebouncerEventMap<TArgs>> {
42
+ export declare class Debouncer<TFunc extends AnyFunc> extends NanoEmitter<DebouncerEventMap<TFunc>> {
39
43
  protected timeout: number;
40
44
  protected type: DebouncerType;
41
45
  /** All registered listener functions and the time they were attached */
42
- protected listeners: DebouncerFunc<TArgs>[];
46
+ protected listeners: TFunc[];
43
47
  /** The currently active timeout */
44
48
  protected activeTimeout: ReturnType<typeof setTimeout> | undefined;
45
49
  /** The latest queued call */
46
- protected queuedCall: DebouncerFunc<TArgs> | undefined;
50
+ protected queuedCall: (() => void) | undefined;
47
51
  /**
48
52
  * Creates a new debouncer with the specified timeout and edge type.
49
53
  * @param timeout Timeout in milliseconds between letting through calls - defaults to 200
@@ -51,9 +55,9 @@ export declare class Debouncer<TArgs> extends NanoEmitter<DebouncerEventMap<TArg
51
55
  */
52
56
  constructor(timeout?: number, type?: DebouncerType);
53
57
  /** Adds a listener function that will be called on timeout */
54
- addListener(fn: DebouncerFunc<TArgs>): void;
58
+ addListener(fn: TFunc): void;
55
59
  /** Removes the listener with the specified function reference */
56
- removeListener(fn: DebouncerFunc<TArgs>): void;
60
+ removeListener(fn: TFunc): void;
57
61
  /** Removes all listeners */
58
62
  removeAllListeners(): void;
59
63
  /** Sets the timeout for the debouncer */
@@ -67,7 +71,7 @@ export declare class Debouncer<TArgs> extends NanoEmitter<DebouncerEventMap<TArg
67
71
  /** Returns the current edge type */
68
72
  getType(): DebouncerType;
69
73
  /** Use this to call the debouncer with the specified arguments that will be passed to all listener functions registered with {@linkcode addListener()} */
70
- call(...args: TArgs[]): void;
74
+ call(...args: Parameters<TFunc>): void;
71
75
  }
72
76
  /**
73
77
  * Creates a {@linkcode Debouncer} instance with the specified timeout and edge type and attaches the passed function as a listener.
@@ -76,6 +80,5 @@ export declare class Debouncer<TArgs> extends NanoEmitter<DebouncerEventMap<TArg
76
80
  *
77
81
  * Refer to the {@linkcode Debouncer} class definition or the [Debouncer documentation](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#debouncer) for more information.
78
82
  */
79
- export declare function debounce<TFunc extends DebouncerFunc<TArgs>, TArgs>(fn: TFunc, timeout?: number, type?: DebouncerType): DebouncerFunc<TArgs> & {
80
- debouncer: Debouncer<TArgs>;
81
- };
83
+ export declare function debounce<TFunc extends (...args: any[]) => any>(fn: TFunc, timeout?: number, type?: DebouncerType): DebouncedFunction<TFunc>;
84
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sv443-network/userutils",
3
3
  "libName": "UserUtils",
4
- "version": "9.0.2",
4
+ "version": "9.0.3",
5
5
  "description": "Lightweight library with various utilities for userscripts - register listeners for when CSS selectors exist, intercept events, create persistent & synchronous data stores, modify the DOM more easily and much more",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",