Skip to content

Commit

Permalink
chore: fix tsdoc comments for @example
Browse files Browse the repository at this point in the history
Embedded typescript code in comments cannot be rendered correctly inside
markdown tables. Add @example to extract example code snippets.
  • Loading branch information
raymondfeng committed May 8, 2019
1 parent c878080 commit b8d005c
Show file tree
Hide file tree
Showing 27 changed files with 110 additions and 36 deletions.
2 changes: 2 additions & 0 deletions examples/log-extension/src/mixins/log.mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {LogComponent} from '../component';
* Also provides .logLevel() to bind application wide logLevel.
* Functions with a log level set to logLevel or higher sill log data
*
* @example
* ```ts
* class MyApplication extends LogMixin(Application) {}
* ```
Expand All @@ -34,6 +35,7 @@ export function LogMixin<T extends Constructor<any>>(superClass: T) {
*
* @param level The log level to set for @log decorator
*
* @example
* ```ts
* app.logLevel(LOG_LEVEL.INFO);
* ```
Expand Down
5 changes: 5 additions & 0 deletions packages/authentication/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export namespace AuthenticationBindings {
* Key used to bind an authentication strategy to the context for the
* authentication function to use.
*
* @example
* ```ts
* server
* .bind(AuthenticationBindings.STRATEGY)
Expand All @@ -29,6 +30,7 @@ export namespace AuthenticationBindings {
/**
* Key used to inject the authentication function into the sequence.
*
* @example
* ```ts
* class MySequence implements SequenceHandler {
* constructor(
Expand Down Expand Up @@ -64,6 +66,7 @@ export namespace AuthenticationBindings {
* Key used to inject authentication metadata, which is used to determine
* whether a request requires authentication or not.
*
* @example
* ```ts
* class MyPassportStrategyProvider implements Provider<Strategy | undefined> {
* constructor(
Expand All @@ -86,6 +89,8 @@ export namespace AuthenticationBindings {
/**
* Key used to inject the user instance retrieved by the
* authentication function
*
* @example
* ```ts
* class MyController {
* constructor(
Expand Down
1 change: 1 addition & 0 deletions packages/authentication/src/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export interface UserService<U, C> {
* Verify the identity of a user, construct a corresponding user profile using
* the user information and return the user profile.
*
* @example
* A pseudo code for basic authentication:
* ```ts
* verifyCredentials(credentials: C): Promise<U> {
Expand Down
2 changes: 2 additions & 0 deletions packages/boot/src/mixins/boot.mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export function BootMixin<T extends Constructor<any>>(superClass: T) {
*
* @param booterCls Booter classes to bind to the Application
*
* @example
* ```ts
* app.booters(MyBooter, MyOtherBooter)
* ```
Expand All @@ -94,6 +95,7 @@ export function BootMixin<T extends Constructor<any>>(superClass: T) {
*
* @param component The component to add.
*
* @example
* ```ts
*
* export class ProductComponent {
Expand Down
1 change: 1 addition & 0 deletions packages/context/src/binding-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {BindingAddress} from './binding-key';
* A function that filters bindings. It returns `true` to select a given
* binding.
*
* @remarks
* TODO(semver-major): We might change this type in the future to either remove
* the `<ValueType>` or make it as type guard by asserting the matched binding
* to be typed with `<ValueType>`.
Expand Down
4 changes: 3 additions & 1 deletion packages/context/src/binding-inspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ export function bindingTemplateFor<T = unknown>(
}

/**
* Mapping artifact types to binding key namespaces (prefixes). For example:
* Mapping artifact types to binding key namespaces (prefixes).
*
* @example
* ```ts
* {
* repository: 'repositories'
Expand Down
2 changes: 1 addition & 1 deletion packages/context/src/binding-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class BindingKey<ValueType> {
/**
* Create a new key for a binding bound to a value of type `ValueType`.
*
* **Example**
* @example
*
* ```ts
* BindingKey.create<string>('application.name');
Expand Down
5 changes: 3 additions & 2 deletions packages/context/src/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,10 @@ export class Binding<T = BoundValue> {
* - the bound value
* - a promise of the bound value
*
* Consumers wishing to consume sync values directly should use `isPromise`
* Consumers wishing to consume sync values directly should use `isPromiseLike`
* to check the type of the returned value to decide how to handle it.
*
* @example
* ```
* const result = binding.getValue(ctx);
* if (isPromiseLike(result)) {
Expand Down Expand Up @@ -540,7 +541,7 @@ export class Binding<T = BoundValue> {
* Apply one or more template functions to set up the binding with scope,
* tags, and other attributes as a group.
*
* For example,
* @example
* ```ts
* const serverTemplate = (binding: Binding) =>
* binding.inScope(BindingScope.SINGLETON).tag('server');
Expand Down
11 changes: 8 additions & 3 deletions packages/context/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ export class Context extends EventEmitter {
private notificationQueue: AsyncIterableIterator<Notification> | undefined;

/**
* Create a new context. For example,
* Create a new context.
*
* @example
* ```ts
* // Create a new root context, let the framework to create a unique name
* const rootCtx = new Context();
Expand Down Expand Up @@ -354,12 +356,15 @@ export class Context extends EventEmitter {
}

/**
* Unbind a binding from the context. No parent contexts will be checked. If
* you need to unbind a binding owned by a parent context, use the code below:
* Unbind a binding from the context. No parent contexts will be checked.
*
* @remarks
* If you need to unbind a binding owned by a parent context, use the code below:
* ```ts
* const ownerCtx = ctx.getOwnerContext(key);
* return ownerCtx != null && ownerCtx.unbind(key);
* ```
*
* @param key Binding key
* @returns true if the binding key is found and removed from this context
*/
Expand Down
8 changes: 5 additions & 3 deletions packages/context/src/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export interface Injection<ValueType = BoundValue> {
* A decorator to annotate method arguments for automatic injection
* by LoopBack IoC container.
*
* @example
* Usage - Typescript:
*
* ```ts
Expand Down Expand Up @@ -206,7 +207,7 @@ export namespace Getter {
* The function injected by `@inject.setter(bindingKey)`. It sets the underlying
* binding to a constant value using `binding.to(value)`.
*
* For example:
* @example
*
* ```ts
* setterFn('my-value');
Expand Down Expand Up @@ -282,7 +283,7 @@ export namespace inject {
* `metadata.bindingCreation` option. See `BindingCreationPolicy` for more
* details.
*
* For example:
* @example
*
* ```ts
* class MyAuthAction {
Expand Down Expand Up @@ -311,7 +312,7 @@ export namespace inject {
/**
* Inject an array of values by a tag pattern string or regexp
*
* For example,
* @example
* ```ts
* class AuthenticationManager {
* constructor(
Expand All @@ -336,6 +337,7 @@ export namespace inject {
/**
* Inject matching bound values by the filter function
*
* @example
* ```ts
* class MyControllerWithView {
* @inject.view(filterByTag('foo'))
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class Application extends Context implements LifeCycleObserver {
* further modify the binding, e.g. lock the value to prevent further
* modifications.
*
* @example
* ```ts
* class MyController {
* }
Expand All @@ -74,6 +75,7 @@ export class Application extends Context implements LifeCycleObserver {
* Each server constructor added in this way must provide a unique prefix
* to prevent binding overlap.
*
* @example
* ```ts
* app.server(RestServer);
* // This server constructor will be bound under "servers.RestServer".
Expand Down Expand Up @@ -107,6 +109,7 @@ export class Application extends Context implements LifeCycleObserver {
* Each server added in this way will automatically be named based on the
* class constructor name with the "servers." prefix.
*
* @remarks
* If you wish to control the binding keys for particular server instances,
* use the app.server function instead.
* ```ts
Expand Down Expand Up @@ -181,6 +184,7 @@ export class Application extends Context implements LifeCycleObserver {
* @param componentCtor The component class to add.
* @param {string=} name Optional component name, default to the class name
*
* @example
* ```ts
*
* export class ProductComponent {
Expand Down
9 changes: 6 additions & 3 deletions packages/core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export interface Component {

/**
* A map of providers to be bound to the application context
* * For example:
*
* @example
* ```ts
* {
* 'authentication.strategies.ldap': LdapStrategyProvider
Expand All @@ -52,7 +53,7 @@ export interface Component {
/**
* A map of classes to be bound to the application context.
*
* For example:
* @example
* ```ts
* {
* 'rest.body-parsers.xml': XmlBodyParser
Expand All @@ -71,7 +72,9 @@ export interface Component {
lifeCycleObservers?: Constructor<LifeCycleObserver>[];

/**
* An array of bindings to be aded to the application context. For example,
* An array of bindings to be aded to the application context.
*
* @example
* ```ts
* const bindingX = Binding.bind('x').to('Value X');
* this.bindings = [bindingX]
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/extension-point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import {CoreTags} from './keys';

/**
* Decorate a class as a named extension point. If the decoration is not
* present, the name of the class will be used. For example:
* present, the name of the class will be used.
*
* @example
* ```ts
* import {extensionPoint} from '@loopback/core';
*
Expand All @@ -39,8 +40,9 @@ export function extensionPoint(name: string, ...specs: BindingSpec[]) {
}

/**
* Shortcut to inject extensions for the given extension point. For example:
* Shortcut to inject extensions for the given extension point.
*
* @example
* ```ts
* import {Getter} from '@loopback/context';
* import {extensionPoint, extensions} from '@loopback/core';
Expand Down
7 changes: 5 additions & 2 deletions packages/metadata/src/decorator-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,11 @@ export class ParameterDecoratorFactory<T> extends DecoratorFactory<
}

/**
* Factory for method level parameter decorator. For example, the following
* code uses `@param` to declare two parameters for `greet()`.
* Factory for method level parameter decorator.
*
* @example
* For example, the following code uses `@param` to declare two parameters for
* `greet()`.
* ```ts
* class MyController {
* @param('name') // Parameter 0
Expand Down
4 changes: 3 additions & 1 deletion packages/openapi-v3/src/decorators/parameter.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ const builtinTypes = {
* takes an argument of `ParameterObject` to define how to map the parameter
* to OpenAPI specification.
*
* `@param(paramSpec)` must be applied to parameters. For example,
* `@param(paramSpec)` must be applied to parameters.
*
* @example
* ```ts
* class MyController {
* @get('/')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const REQUEST_BODY_INDEX = 'x-parameter-index';
* A typical OpenAPI requestBody spec contains property
* `description`, `required`, and `content`:
*
* @example
* ```ts
* requestBodySpec: {
* description: 'a user',
Expand Down
6 changes: 4 additions & 2 deletions packages/repository/src/common-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ export interface Class<T> {
}

/**
* Interface for constructor functions without `new` operator, for example,
* ```
* Interface for constructor functions without `new` operator.
*
* @example
* ```ts
* function Foo(x) {
* if (!(this instanceof Foo)) { return new Foo(x); }
* this.x = x;
Expand Down
2 changes: 2 additions & 0 deletions packages/repository/src/decorators/repository.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export class RepositoryMetadata {
/**
* Decorator for repository injections on properties or method arguments
*
* @example
* ```ts
* class CustomerController {
* @repository(CustomerRepository) public custRepo: CustomerRepository;
Expand All @@ -106,6 +107,7 @@ export function repository(
* Decorator for DefaultCrudRepository generation and injection on properties
* or method arguments based on the given model and dataSource (or their names)
*
* @example
* ```ts
* class CustomerController {
* @repository('Customer', 'mySqlDataSource')
Expand Down
8 changes: 7 additions & 1 deletion packages/repository/src/mixins/repository.mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const debug = debugFactory('loopback:repository:mixin');
* function to register a repository automatically. Also overrides
* component function to allow it to register repositories automatically.
*
* @example
* ```ts
*
* class MyApplication extends RepositoryMixin(Application) {}
* ```
*
Expand All @@ -40,6 +40,7 @@ export function RepositoryMixin<T extends Class<any>>(superClass: T) {
*
* @param repoClass The repository to add.
*
* @example
* ```ts
*
* class NoteRepo {
Expand Down Expand Up @@ -93,6 +94,7 @@ export function RepositoryMixin<T extends Class<any>>(superClass: T) {
* @param dataSource The dataSource to add.
* @param name The binding name of the datasource; defaults to dataSource.name
*
* @example
* ```ts
*
* const ds: juggler.DataSource = new juggler.DataSource({
Expand Down Expand Up @@ -138,6 +140,7 @@ export function RepositoryMixin<T extends Class<any>>(superClass: T) {
*
* @param component The component to add.
*
* @example
* ```ts
*
* export class ProductComponent {
Expand Down Expand Up @@ -257,6 +260,7 @@ export class RepositoryMixinDoc {
*
* @param repo The repository to add.
*
* @example
* ```ts
*
* class NoteRepo {
Expand Down Expand Up @@ -300,6 +304,7 @@ export class RepositoryMixinDoc {
* @param dataSource The dataSource to add.
* @param name The binding name of the datasource; defaults to dataSource.name
*
* @example
* ```ts
*
* const ds: juggler.DataSource = new juggler.DataSource({
Expand Down Expand Up @@ -328,6 +333,7 @@ export class RepositoryMixinDoc {
*
* @param component The component to add.
*
* @example
* ```ts
*
* export class ProductComponent {
Expand Down
Loading

0 comments on commit b8d005c

Please sign in to comment.