
import { createRequire } from 'module'; 
const require = createRequire(import.meta.url);
        

// src/server.ts
var Server = class {
  constructor(party) {
    this.party = party;
  }
  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
