npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rbxts/flamework-gateways-mod

v0.2.4

Published

A class-based Flamework networking mod

Downloads

39

Readme

✨ Featuring

🌉 Gateways - Handle remote events and functions with classes

🛡️ Guards - Block certain requests before they are processed

📞 Pipes - Transform and validate parameters passed to requests

🌻 Motivation

This is mainly a personal project to handle remotes with classes and decorators.

🔌 Installation

npm install @flamework/core@modding
npm install -D rbxts-transformer-flamework@modding
npm install @rbxts/flamework-gateways-mod

📚 Examples

🗂️ Client-server connection

connectServer and connectClient should be called before igniting Flamework.

Do note that guards & pipes will not be applied to external listeners like .on, .wait, etc.!

type ServerGateway = OneGateway & AnotherGateway;

const server = connectServer<ServerGateway, ClientGateway>();

server.emit("clientEvent", players, ...args);
server.broadcast("clientEvent", ...args);
type ClientGateway = OneGateway & AnotherGateway;

const client = connectClient<ServerGateway, ClientGateway>();

client.emit("serverEvent", ...args);
client.request("serverInvoke", ...args);

🌉 Gateway

Gateways should be added to Flamework.addPaths()

@Gateway({
  guards: [new AdminGuard(["littensy"])],
})
class AdminGateway {
  constructor(private readonly adminService: AdminService) {}

  @OnEvent()
  @UseGuards(CommandDebounceGuard)
  @UsePipes([], CommandPipe)
  async processCommand(player: Player, message: string | Array<string>) {
    this.adminService.runCommand(player, message as Array<string>);
  }

  @OnInvoke()
  async getCommands() {
    return this.adminService.getCommands();
  }
}

🛡️ Guard

Creatable guards

class AdminGuard implements CanActivate {
  constructor(private readonly admins: Array<string>) {}

  canActivate(context: ExecutionContext) {
    return this.admins.includes(context.getPlayer().Name);
  }
}

Singleton guards should be added to Flamework.addPaths()

@Guard()
class CommandDebounceGuard implements CanActivate {
  constructor(private readonly roduxService: RoduxService) {}

  canActivate(context: ExecutionContext) {
    const state = this.roduxService.getState();
    return time() >= state.commandDebounce;
  }
}

📞 Pipe

Creatable pipe

class CommandPipe implements PipeTransform {
  transform(value: unknown) {
    assert(typeIs(value, "string"), "(CommandPipe) Value must be a string");
    return value.split(" ");
  }
}

Singleton pipes should be added to Flamework.addPaths()

⚠️ Limitations

❌ Client-side RemoteFunctions are not supported

  • It is difficult to safely determine whether a client remote is a function or an event from the server.

❌ Some type limitations

  • Pipe transformation input/output is not type checked, use Input | Output in the parameter type to keep track (see examples).