Skip to content

Proposal: Add a type-bound policy factory to reduce generic repetition #3

@pedroddomingues

Description

@pedroddomingues

Hi! Thanks for the great work on Gatehouse-TS.

While integrating the library, one DX issue stood out: the need to repeatedly specify
<User, Resource, Action, Context> every time we create policies or instantiate PermissionChecker.

Example today:

const policy = buildAbacPolicy<User, Resource, Action, Context>({ ... });

In larger projects this becomes boilerplate, increases visual noise, and can lead to inconsistent generics across files.

Suggested solution: a policy factory

Introduce something like:

const {
  buildAbacPolicy,
  buildRebacPolicy,
  buildAndPolicy,
  buildOrPolicy,
  PermissionChecker,
} = createPolicyFactory<User, Resource, Action, Context>();

So policy code becomes:

const policy = buildAbacPolicy({ ... });

Benefits:

  • Removes repeated generics
  • Preserves full type safety
  • No breaking changes
  • Works well even with multiple authorization domains

Would you be open to this improvement?
If yes, I can open a PR implementing the factory.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions