util.d.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import LRU from 'lru-cache';
  2. export declare type Listener = (...as: any[]) => void;
  3. export declare type INodeStyleCallBack<Success> = (err: Error | null, result?: Success) => void;
  4. export interface ResultBase {
  5. /**
  6. * Returns all keys in the cache.
  7. */
  8. keys: () => string[];
  9. /**
  10. * Clear the cache.
  11. */
  12. reset: () => void;
  13. /**
  14. * Delete an item given the parameters.
  15. */
  16. del: <T1, T2, T3, T4, T5, T6>(a1?: T1, a2?: T2, a3?: T3, a4?: T4, a5?: T5, a6?: T6) => void;
  17. on(event: 'hit', handler: Listener): void;
  18. on(event: 'miss', handler: Listener): void;
  19. on(event: 'queue', handler: Listener): void;
  20. }
  21. export interface IHashingFunction0 {
  22. (): string;
  23. }
  24. export interface IHashingFunction1<T1> {
  25. (a1: T1): string;
  26. }
  27. export interface IHashingFunction2<T1, T2> {
  28. (a1: T1, a2: T2): string;
  29. }
  30. export interface IHashingFunction3<T1, T2, T3> {
  31. (a1: T1, a2: T2, a3: T3): string;
  32. }
  33. export interface IHashingFunction4<T1, T2, T3, T4> {
  34. (a1: T1, a2: T2, a3: T3, a4: T4): string;
  35. }
  36. export interface IHashingFunction5<T1, T2, T3, T4, T5> {
  37. (a1: T1, a2: T2, a3: T3, a4: T4, a5: T5): string;
  38. }
  39. export interface IHashingFunction6<T1, T2, T3, T4, T5, T6> {
  40. (a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6): string;
  41. }
  42. export interface IHashingFunctionPlus {
  43. (...rest: any[]): string;
  44. }
  45. export interface IBypassFunction0 {
  46. (): boolean;
  47. }
  48. export interface IBypassFunction1<T1> {
  49. (a1: T1): boolean;
  50. }
  51. export interface IBypassFunction2<T1, T2> {
  52. (a1: T1, a2: T2): boolean;
  53. }
  54. export interface IBypassFunction3<T1, T2, T3> {
  55. (a1: T1, a2: T2, a3: T3): boolean;
  56. }
  57. export interface IBypassFunction4<T1, T2, T3, T4> {
  58. (a1: T1, a2: T2, a3: T3, a4: T4): boolean;
  59. }
  60. export interface IBypassFunction5<T1, T2, T3, T4, T5> {
  61. (a1: T1, a2: T2, a3: T3, a4: T4, a5: T5): boolean;
  62. }
  63. export interface IBypassFunction6<T1, T2, T3, T4, T5, T6> {
  64. (a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6): boolean;
  65. }
  66. export interface IBypassFunctionPlus {
  67. (...rest: any[]): boolean;
  68. }
  69. export interface IMaxAgeFunction0<TResult> {
  70. (res: TResult): number;
  71. }
  72. export interface IMaxAgeFunction1<T1, TResult> {
  73. (a1: T1, res: TResult): number;
  74. }
  75. export interface IMaxAgeFunction2<T1, T2, TResult> {
  76. (a1: T1, a2: T2, res: TResult): number;
  77. }
  78. export interface IMaxAgeFunction3<T1, T2, T3, TResult> {
  79. (a1: T1, a2: T2, a3: T3, res: TResult): number;
  80. }
  81. export interface IMaxAgeFunction4<T1, T2, T3, T4, TResult> {
  82. (a1: T1, a2: T2, a3: T3, a4: T4, res: TResult): number;
  83. }
  84. export interface IMaxAgeFunction5<T1, T2, T3, T4, T5, TResult> {
  85. (a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, res: TResult): number;
  86. }
  87. export interface IMaxAgeFunction6<T1, T2, T3, T4, T5, T6, TResult> {
  88. (a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6, res: TResult): number;
  89. }
  90. export interface IMaxAgeFunctionPlus {
  91. (...rest: any[]): number;
  92. }
  93. export interface IParamsBase0<TResult> extends IParamsBaseCommons {
  94. hash: IHashingFunction0;
  95. bypass?: IBypassFunction0;
  96. itemMaxAge?: IMaxAgeFunction0<TResult>;
  97. }
  98. export interface IParamsBase1<T1, TResult> extends IParamsBaseCommons {
  99. hash: IHashingFunction1<T1>;
  100. bypass?: IBypassFunction1<T1>;
  101. itemMaxAge?: IMaxAgeFunction1<T1, TResult>;
  102. }
  103. export interface IParamsBase2<T1, T2, TResult> extends IParamsBaseCommons {
  104. hash: IHashingFunction2<T1, T2>;
  105. bypass?: IBypassFunction2<T1, T2>;
  106. itemMaxAge?: IMaxAgeFunction2<T1, T2, TResult>;
  107. }
  108. export interface IParamsBase3<T1, T2, T3, TResult> extends IParamsBaseCommons {
  109. hash: IHashingFunction3<T1, T2, T3>;
  110. bypass?: IBypassFunction3<T1, T2, T3>;
  111. itemMaxAge?: IMaxAgeFunction3<T1, T2, T3, TResult>;
  112. }
  113. export interface IParamsBase4<T1, T2, T3, T4, TResult> extends IParamsBaseCommons {
  114. hash: IHashingFunction4<T1, T2, T3, T4>;
  115. bypass?: IBypassFunction4<T1, T2, T3, T4>;
  116. itemMaxAge?: IMaxAgeFunction4<T1, T2, T3, T4, TResult>;
  117. }
  118. export interface IParamsBase5<T1, T2, T3, T4, T5, TResult> extends IParamsBaseCommons {
  119. hash: IHashingFunction5<T1, T2, T3, T4, T5>;
  120. bypass?: IBypassFunction5<T1, T2, T3, T4, T5>;
  121. itemMaxAge?: IMaxAgeFunction5<T1, T2, T3, T4, T5, TResult>;
  122. }
  123. export interface IParamsBase6<T1, T2, T3, T4, T5, T6, TResult> extends IParamsBaseCommons {
  124. /**
  125. * A function to generate the key of the cache.
  126. */
  127. hash: IHashingFunction6<T1, T2, T3, T4, T5, T6>;
  128. /**
  129. * Return true if the result should not be retrieved from the cache.
  130. */
  131. bypass?: IBypassFunction6<T1, T2, T3, T4, T5, T6>;
  132. /**
  133. * An optional function to indicate the maxAge of an specific item.
  134. */
  135. itemMaxAge?: IMaxAgeFunction6<T1, T2, T3, T4, T5, T6, TResult>;
  136. }
  137. export interface IParamsBasePlus extends IParamsBaseCommons {
  138. hash: IHashingFunctionPlus;
  139. bypass?: IBypassFunctionPlus;
  140. itemMaxAge?: IMaxAgeFunctionPlus;
  141. }
  142. interface IParamsBaseCommons extends LRU.Options<string, any> {
  143. /**
  144. * Indicates if the resource should be freezed.
  145. */
  146. freeze?: boolean;
  147. /**
  148. * Indicates if the resource should be cloned before is returned.
  149. */
  150. clone?: boolean;
  151. /**
  152. * Disable the cache and executes the load logic directly.
  153. */
  154. disable?: boolean;
  155. /**
  156. * Do not queue requests if initial call is more than `queueMaxAge` milliseconds old.
  157. * Instead, invoke `load` again and create a new queue.
  158. * Defaults to 1000ms.
  159. */
  160. queueMaxAge?: number;
  161. }
  162. export {};