| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * This software contains information and intellectual property that is |
| b69ab31 | | | 3 | * confidential and proprietary to Facebook, Inc. and its affiliates. |
| b69ab31 | | | 4 | * |
| b69ab31 | | | 5 | * @generated |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | /* |
| b69ab31 | | | 9 | * This file is synced between fbcode/eden/fs/facebook/prototypes/node-edenfs-notifications-client/index.d.ts. |
| b69ab31 | | | 10 | * The authoritative copy is the one in eden/fs/. |
| b69ab31 | | | 11 | * Use `yarn sync-edenfs-notifications` to perform the sync. |
| b69ab31 | | | 12 | * |
| b69ab31 | | | 13 | * This file is intended to be self contained so it may be copied/referenced from other extensions, |
| b69ab31 | | | 14 | * which is why it should not import anything and why it reimplements many types. |
| b69ab31 | | | 15 | */ |
| b69ab31 | | | 16 | |
| b69ab31 | | | 17 | /** |
| b69ab31 | | | 18 | * TypeScript type definitions for EdenFS Notifications Client |
| b69ab31 | | | 19 | * JavaScript interface for EdenFS CLI notify endpoint |
| b69ab31 | | | 20 | */ |
| b69ab31 | | | 21 | |
| b69ab31 | | | 22 | import {EventEmitter} from 'events'; |
| b69ab31 | | | 23 | |
| b69ab31 | | | 24 | /** |
| b69ab31 | | | 25 | * Options for initializing EdenFSNotificationsClient |
| b69ab31 | | | 26 | */ |
| b69ab31 | | | 27 | export interface EdenFSClientOptions { |
| b69ab31 | | | 28 | /** Path to the mount point */ |
| b69ab31 | | | 29 | mountPoint?: string; |
| b69ab31 | | | 30 | /** Timeout in milliseconds for commands (default: 30000) */ |
| b69ab31 | | | 31 | timeout?: number; |
| b69ab31 | | | 32 | /** Path to the eden binary (default: 'eden') */ |
| b69ab31 | | | 33 | edenBinaryPath?: string; |
| b69ab31 | | | 34 | } |
| b69ab31 | | | 35 | |
| b69ab31 | | | 36 | /** |
| b69ab31 | | | 37 | * Journal position information |
| b69ab31 | | | 38 | */ |
| b69ab31 | | | 39 | export interface JournalPosition { |
| b69ab31 | | | 40 | journalPosition: string; |
| b69ab31 | | | 41 | } |
| b69ab31 | | | 42 | |
| b69ab31 | | | 43 | /** |
| b69ab31 | | | 44 | * Options for getStatus command |
| b69ab31 | | | 45 | */ |
| b69ab31 | | | 46 | export interface GetStatusOptions { |
| b69ab31 | | | 47 | /** Use case identifier for the command */ |
| b69ab31 | | | 48 | useCase?: string; |
| b69ab31 | | | 49 | } |
| b69ab31 | | | 50 | |
| b69ab31 | | | 51 | /** |
| b69ab31 | | | 52 | * Options for waitReady command |
| b69ab31 | | | 53 | */ |
| b69ab31 | | | 54 | export interface WaitReadyOptions { |
| b69ab31 | | | 55 | /** Use case identifier for the command */ |
| b69ab31 | | | 56 | useCase?: string; |
| b69ab31 | | | 57 | /** Timeout in milliseconds for the command (overrides constructor value) */ |
| b69ab31 | | | 58 | timeout?: number; |
| b69ab31 | | | 59 | } |
| b69ab31 | | | 60 | |
| b69ab31 | | | 61 | /** |
| b69ab31 | | | 62 | * Options for getPosition command |
| b69ab31 | | | 63 | */ |
| b69ab31 | | | 64 | export interface GetPositionOptions { |
| b69ab31 | | | 65 | /** Use case identifier for the command */ |
| b69ab31 | | | 66 | useCase?: string; |
| b69ab31 | | | 67 | /** Mount point path (overrides constructor value) */ |
| b69ab31 | | | 68 | mountPoint?: string; |
| b69ab31 | | | 69 | } |
| b69ab31 | | | 70 | |
| b69ab31 | | | 71 | /** |
| b69ab31 | | | 72 | * Options for getChangesSince command |
| b69ab31 | | | 73 | */ |
| b69ab31 | | | 74 | export interface GetChangesSinceOptions { |
| b69ab31 | | | 75 | /** Journal position to start from */ |
| b69ab31 | | | 76 | position?: string | JournalPosition; |
| b69ab31 | | | 77 | /** Use case identifier */ |
| b69ab31 | | | 78 | useCase?: string; |
| b69ab31 | | | 79 | /** Mount point path (overrides constructor value) */ |
| b69ab31 | | | 80 | mountPoint?: string; |
| b69ab31 | | | 81 | /** Relative root to scope results */ |
| b69ab31 | | | 82 | relativeRoot?: string; |
| b69ab31 | | | 83 | /** Include VCS roots in output */ |
| b69ab31 | | | 84 | includeVcsRoots?: boolean; |
| b69ab31 | | | 85 | /** Included roots in output */ |
| b69ab31 | | | 86 | includedRoots?: string[]; |
| b69ab31 | | | 87 | /** Excluded roots in output */ |
| b69ab31 | | | 88 | excludedRoots?: string[]; |
| b69ab31 | | | 89 | /** Included file suffixes in output */ |
| b69ab31 | | | 90 | includedSuffixes?: string[]; |
| b69ab31 | | | 91 | /** Excluded file suffixes in output */ |
| b69ab31 | | | 92 | excludedSuffixes?: string[]; |
| b69ab31 | | | 93 | /** Return JSON format (default: true) */ |
| b69ab31 | | | 94 | json?: boolean; |
| b69ab31 | | | 95 | /** States to wait for deassertion */ |
| b69ab31 | | | 96 | deferredStates?: string[]; |
| b69ab31 | | | 97 | } |
| b69ab31 | | | 98 | |
| b69ab31 | | | 99 | /** |
| b69ab31 | | | 100 | * Options for subscription |
| b69ab31 | | | 101 | */ |
| b69ab31 | | | 102 | export interface SubscriptionOptions { |
| b69ab31 | | | 103 | /** Journal position to start from */ |
| b69ab31 | | | 104 | position?: string; |
| b69ab31 | | | 105 | /** Use case identifier */ |
| b69ab31 | | | 106 | useCase?: string; |
| b69ab31 | | | 107 | /** Mount point path */ |
| b69ab31 | | | 108 | mountPoint?: string; |
| b69ab31 | | | 109 | /** Throttle in milliseconds between events (default: 0) */ |
| b69ab31 | | | 110 | throttle?: number; |
| b69ab31 | | | 111 | /** Relative root to scope results */ |
| b69ab31 | | | 112 | relativeRoot?: string; |
| b69ab31 | | | 113 | /** Include VCS roots in output */ |
| b69ab31 | | | 114 | includeVcsRoots?: boolean; |
| b69ab31 | | | 115 | /** Included roots in output */ |
| b69ab31 | | | 116 | includedRoots?: string[]; |
| b69ab31 | | | 117 | /** Excluded roots in output */ |
| b69ab31 | | | 118 | excludedRoots?: string[]; |
| b69ab31 | | | 119 | /** Included file suffixes in output */ |
| b69ab31 | | | 120 | includedSuffixes?: string[]; |
| b69ab31 | | | 121 | /** Excluded file suffixes in output */ |
| b69ab31 | | | 122 | excludedSuffixes?: string[]; |
| b69ab31 | | | 123 | /** States to wait for deassertion */ |
| b69ab31 | | | 124 | deferredStates?: string[]; |
| b69ab31 | | | 125 | /** Path to eden binary */ |
| b69ab31 | | | 126 | edenBinaryPath?: string; |
| b69ab31 | | | 127 | } |
| b69ab31 | | | 128 | |
| b69ab31 | | | 129 | /** |
| b69ab31 | | | 130 | * Options for enterState command |
| b69ab31 | | | 131 | */ |
| b69ab31 | | | 132 | export interface EnterStateOptions { |
| b69ab31 | | | 133 | /** Duration in seconds to maintain state */ |
| b69ab31 | | | 134 | duration?: number; |
| b69ab31 | | | 135 | /** Use case identifier */ |
| b69ab31 | | | 136 | useCase?: string; |
| b69ab31 | | | 137 | /** Mount point path (overrides constructor value) */ |
| b69ab31 | | | 138 | mountPoint?: string; |
| b69ab31 | | | 139 | } |
| b69ab31 | | | 140 | |
| b69ab31 | | | 141 | /** |
| b69ab31 | | | 142 | * Small change types |
| b69ab31 | | | 143 | */ |
| b69ab31 | | | 144 | export interface AddedChange { |
| b69ab31 | | | 145 | path: number[]; |
| b69ab31 | | | 146 | file_type: string; |
| b69ab31 | | | 147 | } |
| b69ab31 | | | 148 | |
| b69ab31 | | | 149 | export interface ModifiedChange { |
| b69ab31 | | | 150 | path: number[]; |
| b69ab31 | | | 151 | file_type: string; |
| b69ab31 | | | 152 | } |
| b69ab31 | | | 153 | |
| b69ab31 | | | 154 | export interface RemovedChange { |
| b69ab31 | | | 155 | path: number[]; |
| b69ab31 | | | 156 | file_type: string; |
| b69ab31 | | | 157 | } |
| b69ab31 | | | 158 | |
| b69ab31 | | | 159 | export interface RenamedChange { |
| b69ab31 | | | 160 | from: number[]; |
| b69ab31 | | | 161 | to: number[]; |
| b69ab31 | | | 162 | file_type: string; |
| b69ab31 | | | 163 | } |
| b69ab31 | | | 164 | |
| b69ab31 | | | 165 | export interface ReplacedChange { |
| b69ab31 | | | 166 | from: number[]; |
| b69ab31 | | | 167 | to: number[]; |
| b69ab31 | | | 168 | file_type: string; |
| b69ab31 | | | 169 | } |
| b69ab31 | | | 170 | |
| b69ab31 | | | 171 | export interface SmallChange { |
| b69ab31 | | | 172 | Added?: AddedChange; |
| b69ab31 | | | 173 | Modified?: ModifiedChange; |
| b69ab31 | | | 174 | Removed?: RemovedChange; |
| b69ab31 | | | 175 | Renamed?: RenamedChange; |
| b69ab31 | | | 176 | Replaced?: ReplacedChange; |
| b69ab31 | | | 177 | } |
| b69ab31 | | | 178 | |
| b69ab31 | | | 179 | /** |
| b69ab31 | | | 180 | * Large change types |
| b69ab31 | | | 181 | */ |
| b69ab31 | | | 182 | export interface DirectoryRenamedChange { |
| b69ab31 | | | 183 | from: number[]; |
| b69ab31 | | | 184 | to: number[]; |
| b69ab31 | | | 185 | } |
| b69ab31 | | | 186 | |
| b69ab31 | | | 187 | export interface CommitTransitionChange { |
| b69ab31 | | | 188 | from: number[]; |
| b69ab31 | | | 189 | to: number[]; |
| b69ab31 | | | 190 | } |
| b69ab31 | | | 191 | |
| b69ab31 | | | 192 | export interface LostChanges { |
| b69ab31 | | | 193 | reason: string; |
| b69ab31 | | | 194 | } |
| b69ab31 | | | 195 | |
| b69ab31 | | | 196 | export interface LargeChange { |
| b69ab31 | | | 197 | DirectoryRenamed?: DirectoryRenamedChange; |
| b69ab31 | | | 198 | CommitTransition?: CommitTransitionChange; |
| b69ab31 | | | 199 | LostChanges?: LostChanges; |
| b69ab31 | | | 200 | } |
| b69ab31 | | | 201 | |
| b69ab31 | | | 202 | /** |
| b69ab31 | | | 203 | * State change types |
| b69ab31 | | | 204 | */ |
| b69ab31 | | | 205 | export interface StateEnteredChange { |
| b69ab31 | | | 206 | state: string; |
| b69ab31 | | | 207 | } |
| b69ab31 | | | 208 | |
| b69ab31 | | | 209 | export interface StateLeftChange { |
| b69ab31 | | | 210 | state: string; |
| b69ab31 | | | 211 | } |
| b69ab31 | | | 212 | |
| b69ab31 | | | 213 | export interface StateChange { |
| b69ab31 | | | 214 | StateEntered?: StateEnteredChange; |
| b69ab31 | | | 215 | StateLeft?: StateLeftChange; |
| b69ab31 | | | 216 | } |
| b69ab31 | | | 217 | |
| b69ab31 | | | 218 | /** |
| b69ab31 | | | 219 | * File system change event |
| b69ab31 | | | 220 | */ |
| b69ab31 | | | 221 | export interface Change { |
| b69ab31 | | | 222 | SmallChange?: SmallChange; |
| b69ab31 | | | 223 | LargeChange?: LargeChange; |
| b69ab31 | | | 224 | StateChange?: StateChange; |
| b69ab31 | | | 225 | } |
| b69ab31 | | | 226 | |
| b69ab31 | | | 227 | /** |
| b69ab31 | | | 228 | * Response from getChangesSince |
| b69ab31 | | | 229 | */ |
| b69ab31 | | | 230 | export interface ChangesSinceResponse { |
| b69ab31 | | | 231 | /** List of changes */ |
| b69ab31 | | | 232 | changes: Change[]; |
| b69ab31 | | | 233 | /** New journal position after changes */ |
| b69ab31 | | | 234 | to_position?: string; |
| b69ab31 | | | 235 | } |
| b69ab31 | | | 236 | |
| b69ab31 | | | 237 | /** |
| b69ab31 | | | 238 | * Event emitted by subscription |
| b69ab31 | | | 239 | */ |
| b69ab31 | | | 240 | export interface SubscriptionEvent extends ChangesSinceResponse { |
| b69ab31 | | | 241 | /** Position a state change occurred at */ |
| b69ab31 | | | 242 | position?: string; |
| b69ab31 | | | 243 | /** Event type for state changes */ |
| b69ab31 | | | 244 | event_type?: 'Entered' | 'Left'; |
| b69ab31 | | | 245 | /** State name for state change events */ |
| b69ab31 | | | 246 | state?: string; |
| b69ab31 | | | 247 | } |
| b69ab31 | | | 248 | |
| b69ab31 | | | 249 | /** |
| b69ab31 | | | 250 | * Callback for subscription events |
| b69ab31 | | | 251 | */ |
| b69ab31 | | | 252 | export type SubscriptionCallback = (error: Error | null, result: SubscriptionEvent | null) => void; |
| b69ab31 | | | 253 | |
| b69ab31 | | | 254 | /** |
| b69ab31 | | | 255 | * Custom error class for EdenFS errors |
| b69ab31 | | | 256 | */ |
| b69ab31 | | | 257 | export class EdenFSError extends Error { |
| b69ab31 | | | 258 | edenFSResponse: any; |
| b69ab31 | | | 259 | } |
| b69ab31 | | | 260 | |
| b69ab31 | | | 261 | /** |
| b69ab31 | | | 262 | * EdenFS Notifications Client |
| b69ab31 | | | 263 | * Provides methods to interact with EdenFS notifications via the EdenFS CLI |
| b69ab31 | | | 264 | */ |
| b69ab31 | | | 265 | export class EdenFSNotificationsClient extends EventEmitter { |
| b69ab31 | | | 266 | mountPoint: string | null; |
| b69ab31 | | | 267 | timeout: number; |
| b69ab31 | | | 268 | edenBinaryPath: string; |
| b69ab31 | | | 269 | readonly DEFAULT_EDENFS_RECONNECT_DELAY_MS: number; |
| b69ab31 | | | 270 | readonly MAXIMUM_EDENFS_RECONNECT_DELAY_MS: number; |
| b69ab31 | | | 271 | |
| b69ab31 | | | 272 | constructor(options?: EdenFSClientOptions); |
| b69ab31 | | | 273 | |
| b69ab31 | | | 274 | /** |
| b69ab31 | | | 275 | * Get the current EdenFS status |
| b69ab31 | | | 276 | */ |
| b69ab31 | | | 277 | getStatus(options?: GetStatusOptions): Promise<string>; |
| b69ab31 | | | 278 | |
| b69ab31 | | | 279 | /** |
| b69ab31 | | | 280 | * Wait until EdenFS is ready, using getStatus |
| b69ab31 | | | 281 | * @returns Promise that resolves to true if healthy, false if timeout |
| b69ab31 | | | 282 | */ |
| b69ab31 | | | 283 | waitReady(options?: WaitReadyOptions): Promise<boolean>; |
| b69ab31 | | | 284 | |
| b69ab31 | | | 285 | /** |
| b69ab31 | | | 286 | * Get the current EdenFS journal position |
| b69ab31 | | | 287 | */ |
| b69ab31 | | | 288 | getPosition(options?: GetPositionOptions): Promise<string>; |
| b69ab31 | | | 289 | |
| b69ab31 | | | 290 | /** |
| b69ab31 | | | 291 | * Get changes since a specific journal position |
| b69ab31 | | | 292 | */ |
| b69ab31 | | | 293 | getChangesSince(options?: GetChangesSinceOptions): Promise<ChangesSinceResponse>; |
| b69ab31 | | | 294 | |
| b69ab31 | | | 295 | /** |
| b69ab31 | | | 296 | * Subscribe to filesystem changes |
| b69ab31 | | | 297 | */ |
| b69ab31 | | | 298 | subscribe(options?: SubscriptionOptions, callback?: SubscriptionCallback): EdenFSSubscription; |
| b69ab31 | | | 299 | |
| b69ab31 | | | 300 | /** |
| b69ab31 | | | 301 | * Enter a specific state |
| b69ab31 | | | 302 | */ |
| b69ab31 | | | 303 | enterState(state: string, options?: EnterStateOptions): Promise<void>; |
| b69ab31 | | | 304 | } |
| b69ab31 | | | 305 | |
| b69ab31 | | | 306 | /** |
| b69ab31 | | | 307 | * EdenFS Subscription |
| b69ab31 | | | 308 | * Handles real-time filesystem change notifications |
| b69ab31 | | | 309 | */ |
| b69ab31 | | | 310 | export class EdenFSSubscription extends EventEmitter { |
| b69ab31 | | | 311 | client: EdenFSNotificationsClient; |
| b69ab31 | | | 312 | options: SubscriptionOptions; |
| b69ab31 | | | 313 | process: any; |
| b69ab31 | | | 314 | edenBinaryPath: string; |
| b69ab31 | | | 315 | errData: string; |
| b69ab31 | | | 316 | killTimeout: NodeJS.Timeout | null; |
| b69ab31 | | | 317 | |
| b69ab31 | | | 318 | constructor(client: EdenFSNotificationsClient, options?: SubscriptionOptions); |
| b69ab31 | | | 319 | |
| b69ab31 | | | 320 | /** |
| b69ab31 | | | 321 | * Start the subscription |
| b69ab31 | | | 322 | */ |
| b69ab31 | | | 323 | start(): Promise<void>; |
| b69ab31 | | | 324 | |
| b69ab31 | | | 325 | /** |
| b69ab31 | | | 326 | * Stop the subscription |
| b69ab31 | | | 327 | */ |
| b69ab31 | | | 328 | stop(): void; |
| b69ab31 | | | 329 | |
| b69ab31 | | | 330 | // EventEmitter events |
| b69ab31 | | | 331 | on(event: 'change', listener: (event: SubscriptionEvent) => void): this; |
| b69ab31 | | | 332 | on(event: 'error', listener: (error: Error) => void): this; |
| b69ab31 | | | 333 | on(event: 'close', listener: () => void): this; |
| b69ab31 | | | 334 | |
| b69ab31 | | | 335 | once(event: 'change', listener: (event: SubscriptionEvent) => void): this; |
| b69ab31 | | | 336 | once(event: 'error', listener: (error: Error) => void): this; |
| b69ab31 | | | 337 | once(event: 'close', listener: () => void): this; |
| b69ab31 | | | 338 | |
| b69ab31 | | | 339 | emit(event: 'change', data: SubscriptionEvent): boolean; |
| b69ab31 | | | 340 | emit(event: 'error', error: Error): boolean; |
| b69ab31 | | | 341 | emit(event: 'close'): boolean; |
| b69ab31 | | | 342 | } |
| b69ab31 | | | 343 | |
| b69ab31 | | | 344 | /** |
| b69ab31 | | | 345 | * Utility functions for working with EdenFS notify data |
| b69ab31 | | | 346 | */ |
| b69ab31 | | | 347 | export class EdenFSUtils { |
| b69ab31 | | | 348 | /** |
| b69ab31 | | | 349 | * Convert byte array path to string |
| b69ab31 | | | 350 | */ |
| b69ab31 | | | 351 | static bytesToPath(pathBytes: number[]): string; |
| b69ab31 | | | 352 | |
| b69ab31 | | | 353 | /** |
| b69ab31 | | | 354 | * Convert byte array to hex string |
| b69ab31 | | | 355 | */ |
| b69ab31 | | | 356 | static bytesToHex(bytes: number[]): string; |
| b69ab31 | | | 357 | |
| b69ab31 | | | 358 | /** |
| b69ab31 | | | 359 | * Extract file type from change |
| b69ab31 | | | 360 | */ |
| b69ab31 | | | 361 | static extractFileType(smallChange: SmallChange): string; |
| b69ab31 | | | 362 | |
| b69ab31 | | | 363 | /** |
| b69ab31 | | | 364 | * Extract file path(s) from single change |
| b69ab31 | | | 365 | */ |
| b69ab31 | | | 366 | static extractPath(changes: SmallChange): string[]; |
| b69ab31 | | | 367 | |
| b69ab31 | | | 368 | /** |
| b69ab31 | | | 369 | * Extract file paths from changes |
| b69ab31 | | | 370 | */ |
| b69ab31 | | | 371 | static extractPaths(changes: Change[]): string[]; |
| b69ab31 | | | 372 | |
| b69ab31 | | | 373 | /** |
| b69ab31 | | | 374 | * Get change type from a change object |
| b69ab31 | | | 375 | */ |
| b69ab31 | | | 376 | static getChangeType( |
| b69ab31 | | | 377 | change: Change, |
| b69ab31 | | | 378 | ): |
| b69ab31 | | | 379 | | 'added' |
| b69ab31 | | | 380 | | 'modified' |
| b69ab31 | | | 381 | | 'removed' |
| b69ab31 | | | 382 | | 'renamed' |
| b69ab31 | | | 383 | | 'replaced' |
| b69ab31 | | | 384 | | 'directory renamed' |
| b69ab31 | | | 385 | | 'commit transition' |
| b69ab31 | | | 386 | | 'lost changes' |
| b69ab31 | | | 387 | | 'state entered' |
| b69ab31 | | | 388 | | 'state left' |
| b69ab31 | | | 389 | | 'unknown'; |
| b69ab31 | | | 390 | } |
| b69ab31 | | | 391 | |
| b69ab31 | | | 392 | declare const exports: { |
| b69ab31 | | | 393 | EdenFSNotificationsClient: typeof EdenFSNotificationsClient; |
| b69ab31 | | | 394 | EdenFSSubscription: typeof EdenFSSubscription; |
| b69ab31 | | | 395 | EdenFSUtils: typeof EdenFSUtils; |
| b69ab31 | | | 396 | }; |
| b69ab31 | | | 397 | |
| b69ab31 | | | 398 | export default exports; |
| b69ab31 | | | 399 | |
| b69ab31 | | | 400 | export type Options = { |
| b69ab31 | | | 401 | mountPoint?: string; |
| b69ab31 | | | 402 | timeout?: number; |
| b69ab31 | | | 403 | edenBinaryPath?: string; |
| b69ab31 | | | 404 | }; |
| b69ab31 | | | 405 | |
| b69ab31 | | | 406 | export type CommandCallback = (error?: Error, result?: Response) => void; |