Roblox.js - Open Cloud made easy

Roblox.js

Open Cloud made easy

About

Roblox.js is a modern open-source NPM package that brings the official Roblox Open Cloud and few others things to JavaScript world with little learning curve. Roblox.js is designed to be as close as possible to native Luau APIs in terms of design, and therefore, making it very easy to transition to.

Installation

NPM

npm i @daw588/roblox.js

Yarn

yarn add @daw588/roblox.js

Getting Started

import { Universe, DataStore } from "@daw588/roblox.js";

const universe = new Universe(0000000000, "specify-api-key");
const coinsStore = new DataStore(universe, "Coins");

await coinsStore.SetAsync("1234", 5);
const [data] = await coinsStore.GetAsync("1234");

console.log(data); // Output: 5

Learn more about this NPM package by visiting our Wiki page.

License

MIT

Closing

If you have any feedback that you want to give me, feel free to do so. You can suggest features and report any bugs here or in the GitHub repository. Please also keep in mind that this is my first ever open-source project and therefore, I am not really familiar with NPM, GitHub, Git and other technologies, which were used to make this project possible.

50 Likes

Thanks for sharing this! It will be good to see more Open Cloud APIs and modules like this get even more useful.

4 Likes

v0.0.4 - New features & Restructure


External

  • Renamed Game to Universe as game object refers to a place and not to the universe.
    • Changed order of parameters from new Game(apiKey, universeId) to new Universe(id, apiKey).
  • Added Place class that utilizes the Place Management API.
    • Added <Place>.SaveAs() method.
    • Added <Place>.PublishAs() method.
  • Added more methods to DataStore class.
    • Added <DataStore>.ListVersionsAsync() method.
    • Added <DataStore>.GetVersionAsync() method.
  • Fixed bunch of mistakes in the documentation and expended it accordingly to include the changes to the methods.
    • Moved the documentation to GitHub’s Wiki tab.

Internal

  • Added strong-typed Typescript definitions for Roblox Open Cloud API for better autocomplete and maintenance.
  • Improved <Place>.SetAsync() method by removing switch case data formatting to just one simple JSON.stringify() call.
  • Revamped the Page class to support all different kinds of data structures.
  • Fixed couple minor bugs.

For more in-depth changes to the NPM package, visit the history page located in the GitHub repository.

2 Likes

v0.0.5 - New features


External

  • Added one more method to Universe class.
    • Added <Universe>.ListDataStoresAsync() method.
  • Updated the documentation to be up-to-date with the latest version of the NPM package.
    • Corrected few mistakes and typos.

Internal

  • Added Jest framework for unit-testing purposes.

For more in-depth changes to the NPM package, visit the history page located in the GitHub repository.

2 Likes

I’m not the best with import things on javascript, and I’m pretty sure you can’t import and require on the same file…

I was wondering, can we require this by chance? I’d love to use this to make my cloud infraction system rather than using a queue system with express that has 4 ban handling servers that use message service to contact the others to send kick requests etc!

1 Like

Nope, it’s not possible and I am not planning to support require() as it’s thing of a past. You can add such support yourself if you really can’t switch to ES6. If you have anything else to give feedback on, please let me know.

2 Likes

I used async to import it instead, I was about to use it then I got a weird error saying 403, not allowed.
I assume it’s a problem on my end, anyways, I’ll certainly use this in my upcoming roleplay game for a discord bot that checks inventories, stats, etc!

3 Likes

So in that way, we must create our bot in TypeScript language.

I don’t think people like to remake their Discord bot originaly created in JavaScript into TypeScript.

1 Like

Import and export syntax is not exclusive to TypeScript. The module syntax came in JavaScript (ES6) which was released in 2015. So, no. People do not need to rewrite their JavaScript code into TypeScript code, as it’s not necessary.

The NPM package is indeed written in TypeScript, however it’s transpiled to JavaScript since TypeScript cannot be executed and it only exists for type checking capabilities and for additional syntax features that are not available in JavaScript without cluttering my codebase with code that would somewhat emulate such features (eg. enum).

If you still don’t understand on what I am talking about then I would suggest you to look up and read more about what JavaScript and TypeScript is, and the difference between them so that you have better understanding on this topic.

3 Likes

v0.0.6 - Bug Fixes & Improvements


External

  • Support for Roblox inf object has been added to <DataStore>.GetAsync() method, which now returns it as an Infinity object. Previously getting data from a key that contained inf in it’s value would result in JSON parsing error, as mentioned by @Happywalker on GitHub.
  • HTTPS errors are no longer parsed as strings and instead, they are returned as one object, which contains <HttpsError>.status and <HttpsError>.statusText properties that can be easily accessed by the developer, as requested by @Happywalker on GitHub.

Internal

  • Added pre-processing function for inf object, which runs right before JSON.parse().
  • Replaced throw and Error() with Promise.reject() that returns both status code and text in a single object.

For more in-depth changes to the NPM package, visit the history page located in the GitHub repository.

2 Likes

just so you know, there’s already a package called Roblox.js.

It was the precursor to noblox.js. Just so you know

1 Like

I don’t think that it should be a problem since it has different purpose and it was discontinued a while ago.

2 Likes

v0.1.6 - Implemented the MessagingService API


External

Internal

  • Corrected code formatting and made eslint ignore the test folder.
  • Switched to semantic versioning.

For more in-depth changes to the NPM package, visit the history page located in the GitHub repository.

Improved Syntax Proposal

Currently to interact with the library you would write this:

import { Universe, DataStore } from "@daw588/roblox.js";

const universe = new Universe(0000000000, "specify-api-key");
const coinsStore = new DataStore(universe, "Coins");

await coinsStore.SetAsync("1234", 5);
const [data] = await coinsStore.GetAsync("1234");

console.log(data); // Output: 5

Universe.PublishMessageAsync("Announcement", "Hello World!");

However, this could be improved to be more close to the syntax that Roblox is using:

import { Universe } from "@daw588/roblox.js";

const MyGame = new Universe(0000000000, "specify-api-key");

const DataStoreService = MyGame.GetService("DataStoreService");
const MessagingService = MyGame.GetService("MessagingService");

const CoinStore = DataStoreService.GetDataStore("Coins");

await CoinStore.SetAsync("1234", 5);
const [data] = await CoinStore.GetAsync("1234");

console.log(data); // Output: 5

MessagingService.PublishAsync("Announcement", "Hello World!");
What should I do?
  • Stick with the current syntax
  • Implement the proposed syntax

0 voters

mmm i really regret pinging you now lol

overall yes i do think that this is a better syntax though

Indeed, especially considering that this library is suppose to be as close as possible to the Luau version of the API.

And why is that? :grin:

How would I make this work with my JS code?

Could you elaborate more? Because I do not know on what you mean by “will this work”.

My bot uses JavaScript, but your code is TypeScript. How can I get your TS to work with my JS

As I explained already, TypeScript transpiles to JavaScript, the NPM package doesn’t contain any TypeScript, only the transpiled JavaScript.

Just install the NPM package and use it.