@@ -279,7 +279,7 @@ type ClassHelp = {
279
279
} ;
280
280
281
281
export const toIgnore = [ 'constructor' , 'help' ] ;
282
- export function shellApiClassGeneric ( constructor : Function , hasHelp : boolean ) : void {
282
+ function shellApiClassGeneric ( constructor : Function , hasHelp : boolean ) : void {
283
283
const className = constructor . name ;
284
284
const classHelpKeyPrefix = `shell-api.classes.${ className } .help` ;
285
285
const classHelp : ClassHelp = {
@@ -405,10 +405,16 @@ export function shellApiClassGeneric(constructor: Function, hasHelp: boolean): v
405
405
}
406
406
}
407
407
408
+ /**
409
+ * Marks a class as being a Shell API class including help information.
410
+ */
408
411
export function shellApiClassDefault ( constructor : Function ) : void {
409
412
shellApiClassGeneric ( constructor , true ) ;
410
413
}
411
414
415
+ /**
416
+ * Marks a class as being a Shell API class without help information
417
+ */
412
418
export function shellApiClassNoHelp ( constructor : Function ) : void {
413
419
shellApiClassGeneric ( constructor , false ) ;
414
420
}
@@ -424,6 +430,19 @@ function markImplicitlyAwaited<T extends(...args: any) => Promise<any>>(orig: T)
424
430
}
425
431
426
432
export { signatures } ;
433
+ /**
434
+ * Marks the decorated method as being supported for the given range of server versions.
435
+ * Server versions are given as `[min, max]` where both boundaries are **inclusive**.
436
+ * If the version of the server the user is connected to is not inside the range, the method
437
+ * will not be included in autocompletion.
438
+ *
439
+ * When a method is deprecated after a specific server version, the `versionArray` should include
440
+ * this version as the `max` value.
441
+ *
442
+ * See also `ServerVersions.earliest` and `ServerVersions.latest`.
443
+ *
444
+ * @param versionArray An array of supported server versions
445
+ */
427
446
export function serverVersions ( versionArray : [ string , string ] ) : Function {
428
447
return function (
429
448
_target : any ,
@@ -433,6 +452,15 @@ export function serverVersions(versionArray: [ string, string ]): Function {
433
452
descriptor . value . serverVersions = versionArray ;
434
453
} ;
435
454
}
455
+
456
+ /**
457
+ * Marks the decorated method as being supported for the given range of API versions.
458
+ * API versions are given as `[version]` or `[min, max]`.
459
+ * If the API version the user specified during connection is not inside the range, the method
460
+ * will not be included in autocompletion.
461
+ *
462
+ * @param versionArray An array of supported API versions
463
+ */
436
464
export function apiVersions ( versionArray : [ ] | [ number ] | [ number , number ] ) : Function {
437
465
return function (
438
466
_target : any ,
@@ -447,9 +475,27 @@ export function apiVersions(versionArray: [] | [ number ] | [ number, number ]):
447
475
descriptor . value . apiVersions = versionArray ;
448
476
} ;
449
477
}
478
+
479
+ /**
480
+ * Marks the decorated class/method as deprecated.
481
+ * A deprecated method will not be included in autocompletion.
482
+ *
483
+ * Calling a deprecated method will automatically emit a telemetry event but
484
+ * will **not** print an automatic deprecation warning (see `printDeprecationWarning`).
485
+ *
486
+ * **Important:** To exclude the method from autocompletion use `@serverVersions`.
487
+ */
450
488
export function deprecated ( _target : any , _propertyKey : string , descriptor : PropertyDescriptor ) : void {
451
489
descriptor . value . deprecated = true ;
452
490
}
491
+
492
+ /**
493
+ * Marks the decorated method as only being available for the given topologies.
494
+ * The method will not be included in autocomplete if the user is connected to a cluster
495
+ * of a topology type that is not present in `topologiesArray`.
496
+ *
497
+ * @param topologiesArray The topologies for which the method is available
498
+ */
453
499
export function topologies ( topologiesArray : Topologies [ ] ) : Function {
454
500
return function (
455
501
_target : any ,
@@ -459,7 +505,15 @@ export function topologies(topologiesArray: Topologies[]): Function {
459
505
descriptor . value . topologies = topologiesArray ;
460
506
} ;
461
507
}
508
+
462
509
export const nonAsyncFunctionsReturningPromises : string [ ] = [ ] ; // For testing.
510
+ /**
511
+ * Marks the decorated method as having a synthetic promise return value that needs to be implicitly
512
+ * awaited by the async rewriter.
513
+ *
514
+ * Note: a test will verify that the `nonAsyncFunctionsReturningPromises` is empty, i.e. **every**
515
+ * method that is decorated with `@returnsPromise` must be an `async` method.
516
+ */
463
517
export function returnsPromise ( _target : any , _propertyKey : string , descriptor : PropertyDescriptor ) : void {
464
518
const originalFunction = descriptor . value ;
465
519
originalFunction . returnsPromise = true ;
@@ -482,11 +536,24 @@ export function returnsPromise(_target: any, _propertyKey: string, descriptor: P
482
536
nonAsyncFunctionsReturningPromises . push ( originalFunction . name ) ;
483
537
}
484
538
}
485
- // This is use to mark functions that are executable in the shell in a POSIX-shell-like
486
- // fashion, e.g. `show foo` which is translated into a call to `show('foo')`.
539
+
540
+ /**
541
+ * Marks the deocrated method as executable in the shell in a POSIX-shell-like
542
+ * fashion, e.g. `show foo` which is translated into a call to `show('foo')`.
543
+ */
487
544
export function directShellCommand ( _target : any , _propertyKey : string , descriptor : PropertyDescriptor ) : void {
488
545
descriptor . value . isDirectShellCommand = true ;
489
546
}
547
+
548
+ /**
549
+ * Marks the decorated method to provide a specific `completer` function to be
550
+ * called for autocomplete.
551
+ *
552
+ * This can be used to provide autocompletion for POSIX-shell-like commands,
553
+ * e.g. `show ...`.
554
+ *
555
+ * @param completer The completer to use for autocomplete
556
+ */
490
557
export function shellCommandCompleter ( completer : ShellCommandCompleter ) : Function {
491
558
return function (
492
559
_target : any ,
@@ -496,7 +563,15 @@ export function shellCommandCompleter(completer: ShellCommandCompleter): Functio
496
563
descriptor . value . shellCommandCompleter = completer ;
497
564
} ;
498
565
}
499
- export function returnType ( type : string | TypeSignature ) : Function {
566
+
567
+ /**
568
+ * Marks the decorated method as returning a (resolved) value of the given Shell API type.
569
+ * The type is given as string being the classname of the Shell API class.
570
+ * Specify `'this'` in order to return a value of the methods surrounding class type.
571
+ *
572
+ * @param type The Shell API return type of the method
573
+ */
574
+ export function returnType ( type : string ) : Function {
500
575
return function (
501
576
_target : any ,
502
577
_propertyKey : string ,
@@ -505,12 +580,21 @@ export function returnType(type: string | TypeSignature): Function {
505
580
descriptor . value . returnType = type ;
506
581
} ;
507
582
}
508
- export function classReturnsPromise ( constructor : Function ) : void {
509
- constructor . prototype . returnsPromise = true ;
510
- }
583
+
584
+ /**
585
+ * Marks the constructor of the decorated class as being deprecated.
586
+ *
587
+ * Calling the constructor will automatically emit a telemetry event but
588
+ * will **not** print an automatic deprecation warning (see `printDeprecationWarning`).
589
+ */
511
590
export function classDeprecated ( constructor : Function ) : void {
512
591
constructor . prototype . deprecated = true ;
513
592
}
593
+
594
+ /**
595
+ * Marks the decorated method as only being supported on the given platforms.
596
+ * @param platformsArray The platforms the method is supported on
597
+ */
514
598
export function platforms ( platformsArray : any [ ] ) : Function {
515
599
return function (
516
600
_target : any ,
@@ -520,11 +604,21 @@ export function platforms(platformsArray: any[]): Function {
520
604
descriptor . value . platforms = platformsArray ;
521
605
} ;
522
606
}
607
+
608
+ /**
609
+ * Marks the constructor of the decorated class as only being supported on the given platforms.
610
+ * @param platformsArray The platforms the method is supported on
611
+ */
523
612
export function classPlatforms ( platformsArray : any [ ] ) : Function {
524
613
return function ( constructor : Function ) : void {
525
614
constructor . prototype . platforms = platformsArray ;
526
615
} ;
527
616
}
617
+
618
+ /**
619
+ * Marks the decorated class that for all methods in the class additional
620
+ * source information of the call will be added to the calls returned result.
621
+ */
528
622
export function addSourceToResults ( constructor : Function ) : void {
529
623
( constructor as any ) [ addSourceToResultsSymbol ] = true ;
530
624
}
0 commit comments