Stone.js API
    Preparing search index...
    • The imperative counterpart of a policy class: a plain function.

      It receives the same dependencies a class would get through its constructor.

      Parameters

      • authorize: (dependencies: any) => (event: IncomingEvent) => boolean | Promise<boolean>

        Decides whether the caller may proceed.

      Returns (dependencies: any) => IPolicy

      A factory producing a policy.

      export const updatePostPolicy = definePolicy(({ posts }) => async (event) => {
      const post = await posts.find(event.get('id'))
      return post.authorId === event.getMetadataValue('auth')?.sub
      })