|
34 | 34 | export class TestingHooks {
|
35 | 35 | private readonly onExistenceFilterMismatchCallbacks = new Map<
|
36 | 36 | Symbol,
|
37 |
| - (arg: unknown) => void |
| 37 | + (info: ExistenceFilterMismatchInfo) => void |
38 | 38 | >();
|
39 | 39 |
|
40 | 40 | private constructor() {}
|
@@ -65,31 +65,50 @@ export class TestingHooks {
|
65 | 65 | * The relative order in which callbacks are notified is unspecified; do not
|
66 | 66 | * rely on any particular ordering.
|
67 | 67 | *
|
68 |
| - * @param callback the callback to invoke upon existence filter mismatch. The |
69 |
| - * type of the argument to this callback is intentionally declared as |
70 |
| - * `unknown`, rather than something more specific, to discourage its use |
71 |
| - * unless you really, really know what you are doing. If you know what you are |
72 |
| - * doing then you know the type and how to interpret it. |
| 68 | + * @param callback the callback to invoke upon existence filter mismatch. |
73 | 69 | *
|
74 | 70 | * @return a function that, when called, unregisters the given callback; only
|
75 | 71 | * the first invocation of the returned function does anything; all subsequent
|
76 | 72 | * invocations do nothing.
|
77 | 73 | */
|
78 |
| - onExistenceFilterMismatch(callback: (arg: unknown) => void): () => void { |
| 74 | + onExistenceFilterMismatch( |
| 75 | + callback: (info: ExistenceFilterMismatchInfo) => void |
| 76 | + ): () => void { |
79 | 77 | const key = Symbol();
|
80 | 78 | this.onExistenceFilterMismatchCallbacks.set(key, callback);
|
81 | 79 | return () => this.onExistenceFilterMismatchCallbacks.delete(key);
|
82 | 80 | }
|
83 | 81 |
|
84 | 82 | /**
|
85 | 83 | * Invokes all currently-registered `onExistenceFilterMismatch` callbacks.
|
86 |
| - * @param arg the argument to specify to the callbacks; see the documentation |
87 |
| - * for `onExistenceFilterMismatch()` for details. |
| 84 | + * @param info the argument to specify to the callbacks. |
88 | 85 | */
|
89 |
| - notifyOnExistenceFilterMismatch(arg: unknown): void { |
90 |
| - this.onExistenceFilterMismatchCallbacks.forEach(callback => callback(arg)); |
| 86 | + notifyOnExistenceFilterMismatch(info: ExistenceFilterMismatchInfo): void { |
| 87 | + this.onExistenceFilterMismatchCallbacks.forEach(callback => callback(info)); |
91 | 88 | }
|
92 | 89 | }
|
93 | 90 |
|
| 91 | +/** |
| 92 | + * The shape of the object specified to |
| 93 | + * `TestingUtils.onExistenceFilterMismatch()` callbacks. |
| 94 | + */ |
| 95 | +export interface ExistenceFilterMismatchInfo { |
| 96 | + actualCount: number; |
| 97 | + bloomFilterApplied: boolean; |
| 98 | + change: { |
| 99 | + targetId: number; |
| 100 | + existenceFilter: { |
| 101 | + count: number; |
| 102 | + unchangedNames?: { |
| 103 | + bits?: { |
| 104 | + bitmap?: string | Uint8Array; |
| 105 | + padding?: number; |
| 106 | + }; |
| 107 | + hashCount?: number; |
| 108 | + }; |
| 109 | + }; |
| 110 | + }; |
| 111 | +} |
| 112 | + |
94 | 113 | /** The global singleton instance of `TestingHooks`. */
|
95 | 114 | let gTestingHooksSingletonInstance: TestingHooks | null = null;
|
0 commit comments