Stone.js API
    Preparing search index...
    • Declare a class as a policy.

      Three statements in one, which is why nothing has to be wired by hand:

      1. It is a service. The container builds it, as a singleton, so its constructor is auto-wired like any other class: a repository, a client, a translator, whatever it destructures is resolved for it. That is what lets a policy depend on the application instead of on constants.
      2. It is reachable by name. The alias is bound as policy:<name>, prefixed on purpose: an application is free to bind its own service under a plain word, and a declaration named after a domain concept must not compete for that name.
      3. It activates the module. The blueprint comes with the decorator, so declaring this is the whole setup, and a route naming it resolves to this class.

      Type Parameters

      • T extends ClassType = ClassType

      Parameters

      • Optionalalias: string

        The name a route refers to it by. Defaults to the class name.

      Returns ClassDecorator

      A class decorator.

      @Policy('post')
      export class PostPolicy {
      constructor (private readonly teams: TeamRepository) {}
      update (user: User, post: Post): boolean { return post.authorId === user.id }
      }