CustomStatWatcher.d.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /// <reference types="node" />
  2. /// <reference types="node" />
  3. /// <reference types="node" />
  4. /// <reference types="node" />
  5. import { EventEmitter } from 'events';
  6. import { BigIntStats, Stats } from 'fs';
  7. import { StatWatcher, WatchFileCallback, WatchFileOptions, FakeFS } from '../../FakeFS';
  8. import { Path } from '../../path';
  9. export declare enum Event {
  10. Change = "change",
  11. Stop = "stop"
  12. }
  13. export declare enum Status {
  14. Ready = "ready",
  15. Running = "running",
  16. Stopped = "stopped"
  17. }
  18. export declare function assertStatus<T extends Status>(current: Status, expected: T): asserts current is T;
  19. export type ListenerOptions = Omit<Required<WatchFileOptions>, 'bigint'>;
  20. export type CustomStatWatcherOptions = {
  21. bigint?: boolean;
  22. };
  23. export declare class CustomStatWatcher<P extends Path> extends EventEmitter implements StatWatcher {
  24. readonly fakeFs: FakeFS<P>;
  25. readonly path: P;
  26. readonly bigint: boolean;
  27. private status;
  28. private changeListeners;
  29. private lastStats;
  30. private startTimeout;
  31. static create<P extends Path>(fakeFs: FakeFS<P>, path: P, opts?: CustomStatWatcherOptions): CustomStatWatcher<P>;
  32. private constructor();
  33. start(): void;
  34. stop(): void;
  35. stat(): Stats | BigIntStats;
  36. /**
  37. * Creates an interval whose callback compares the current stats with the previous stats and notifies all listeners in case of changes.
  38. *
  39. * @param opts.persistent Decides whether the interval should be immediately unref-ed.
  40. */
  41. makeInterval(opts: ListenerOptions): NodeJS.Timeout;
  42. /**
  43. * Registers a listener and assigns it an interval.
  44. */
  45. registerChangeListener(listener: WatchFileCallback, opts: ListenerOptions): void;
  46. /**
  47. * Unregisters the listener and clears the assigned interval.
  48. */
  49. unregisterChangeListener(listener: WatchFileCallback): void;
  50. /**
  51. * Unregisters all listeners and clears all assigned intervals.
  52. */
  53. unregisterAllChangeListeners(): void;
  54. hasChangeListeners(): boolean;
  55. /**
  56. * Refs all stored intervals.
  57. */
  58. ref(): this;
  59. /**
  60. * Unrefs all stored intervals.
  61. */
  62. unref(): this;
  63. }