UNPKG

@colyseus/redis-driver

Version:

<div align="center"> <a href="https://github.com/colyseus/colyseus"> <img src="media/logo.svg?raw=true" width="60%" height="300" /> </a> <br> <br> <a href="https://npmjs.com/package/colyseus"> <img src="https://img.shields.io/npm/dm/coly

102 lines (101 loc) 3.03 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var RoomData_exports = {}; __export(RoomData_exports, { RoomData: () => RoomData }); module.exports = __toCommonJS(RoomData_exports); var import_core = require("@colyseus/core"); class RoomData { constructor(initialValues, client) { this.clients = 0; this.locked = false; this.private = false; this.maxClients = Infinity; this.unlisted = false; this.#removed = false; this.#client = client; this.createdAt = initialValues && initialValues.createdAt ? new Date(initialValues.createdAt) : /* @__PURE__ */ new Date(); for (const field in initialValues) { if (initialValues.hasOwnProperty(field)) { this[field] = initialValues[field]; } } } #client; #removed; toJSON() { return { clients: this.clients, createdAt: this.createdAt, maxClients: this.maxClients, metadata: this.metadata, name: this.name, publicAddress: this.publicAddress, processId: this.processId, roomId: this.roomId }; } async save() { if (this.#removed) { return; } if (this.roomId) { const toJSON = this.toJSON; this.toJSON = void 0; const roomcache = JSON.stringify(this); this.toJSON = toJSON; await this.hset("roomcaches", this.roomId, roomcache); } else { import_core.logger.warn("RedisDriver: can't .save() without a `roomId`"); } } updateOne(operations) { if (operations.$set) { for (const field in operations.$set) { if (operations.$set.hasOwnProperty(field)) { this[field] = operations.$set[field]; } } } if (operations.$inc) { for (const field in operations.$inc) { if (operations.$inc.hasOwnProperty(field)) { this[field] += operations.$inc[field]; } } } return this.save(); } remove() { if (this.roomId) { this.#removed = true; return this.hdel("roomcaches", this.roomId); } } async hset(key, field, value) { return await this.#client.hset(key, field, value); } async hdel(key, field) { return await this.#client.hdel(key, field); } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { RoomData });