var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  return value;
};

// src/server.ts
var Server = class {
  constructor(party) {
    this.party = party;
    __publicField(this, "clockHead", /* @__PURE__ */ new Map());
  }
  async onStart() {
    return this.party.storage.get("main").then((head) => {
      if (head) {
        this.clockHead = head;
      }
    });
  }
  async onConnect(conn) {
    for (const value of this.clockHead.values()) {
      conn.send(value);
    }
  }
  onMessage(message, sender) {
    const { data, cid, parents } = JSON.parse(message);
    for (const p of parents) {
      this.clockHead.delete(p);
    }
    this.clockHead.set(cid, data);
    this.party.broadcast(data, [sender.id]);
    void this.party.storage.put("main", this.clockHead);
  }
};
export {
  Server as default
};
//# sourceMappingURL=server.esm.js.map
