@liveblocks/server 1.1.0 → 1.1.1-pnpmtest1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -562,6 +562,11 @@ interface IStorageDriver {
562
562
  * Delete a leased session by session ID.
563
563
  */
564
564
  delete_leased_session(sessionId: string): Awaitable<void>;
565
+ /**
566
+ * Return the number of storage rows written since last call to this method,
567
+ * and reset the counter.
568
+ */
569
+ takeRowsWritten?(): number;
565
570
  }
566
571
 
567
572
  /**
@@ -1102,6 +1107,8 @@ declare class Room<RM, SM, CM extends JsonObject, C = undefined> {
1102
1107
  ticket: Ticket<SM, CM>;
1103
1108
  socket: IServerWebSocket;
1104
1109
  lastActivity: Date;
1110
+ /** Original session creation time (e.g. from persisted attachment). Required for correct session duration after hibernation. */
1111
+ createdAt?: Date;
1105
1112
  }[]): void;
1106
1113
  private sendSessionStartMessages;
1107
1114
  /**
@@ -1478,6 +1485,7 @@ declare class InMemoryDriver implements IStorageDriver {
1478
1485
  get_leased_session(sessionId: string): Promise<LeasedSession | undefined>;
1479
1486
  put_leased_session(session: LeasedSession): Promise<void>;
1480
1487
  delete_leased_session(sessionId: string): Promise<void>;
1488
+ takeRowsWritten(): number;
1481
1489
  next_actor(): number;
1482
1490
  iter_y_updates(docId: YDocId): Promise<IterableIterator<[string, Uint8Array]>>;
1483
1491
  write_y_updates(docId: YDocId, key: string, data: Uint8Array): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -562,6 +562,11 @@ interface IStorageDriver {
562
562
  * Delete a leased session by session ID.
563
563
  */
564
564
  delete_leased_session(sessionId: string): Awaitable<void>;
565
+ /**
566
+ * Return the number of storage rows written since last call to this method,
567
+ * and reset the counter.
568
+ */
569
+ takeRowsWritten?(): number;
565
570
  }
566
571
 
567
572
  /**
@@ -1102,6 +1107,8 @@ declare class Room<RM, SM, CM extends JsonObject, C = undefined> {
1102
1107
  ticket: Ticket<SM, CM>;
1103
1108
  socket: IServerWebSocket;
1104
1109
  lastActivity: Date;
1110
+ /** Original session creation time (e.g. from persisted attachment). Required for correct session duration after hibernation. */
1111
+ createdAt?: Date;
1105
1112
  }[]): void;
1106
1113
  private sendSessionStartMessages;
1107
1114
  /**
@@ -1478,6 +1485,7 @@ declare class InMemoryDriver implements IStorageDriver {
1478
1485
  get_leased_session(sessionId: string): Promise<LeasedSession | undefined>;
1479
1486
  put_leased_session(session: LeasedSession): Promise<void>;
1480
1487
  delete_leased_session(sessionId: string): Promise<void>;
1488
+ takeRowsWritten(): number;
1481
1489
  next_actor(): number;
1482
1490
  iter_y_updates(docId: YDocId): Promise<IterableIterator<[string, Uint8Array]>>;
1483
1491
  write_y_updates(docId: YDocId, key: string, data: Uint8Array): Promise<void>;
package/dist/index.js CHANGED
@@ -891,6 +891,9 @@ var InMemoryDriver = class {
891
891
  async delete_leased_session(sessionId) {
892
892
  this._leasedSessions.delete(sessionId);
893
893
  }
894
+ takeRowsWritten() {
895
+ return 0;
896
+ }
894
897
  next_actor() {
895
898
  return ++this._nextActor;
896
899
  }
@@ -1701,7 +1704,7 @@ function stripOpId(op2) {
1701
1704
  var __socket, __debug, __lastActiveAt, __hasNotifiedClientStorageUpdateError;
1702
1705
  var BrowserSession = class {
1703
1706
  /** @internal - Never create a BrowserSession instance manually. Use the room.startBrowserSession() API instead. */
1704
- constructor(ticket, socket, debug) {
1707
+ constructor(ticket, socket, debug, createdAt) {
1705
1708
  // ^^ User-defined Session Metadata
1706
1709
  // ^^ User-defined Client Metadata (sent to client in ROOM_STATE)
1707
1710
  __publicField(this, "version");
@@ -1730,7 +1733,7 @@ var BrowserSession = class {
1730
1733
  this.publicMeta = ticket.publicMeta;
1731
1734
  __privateSet(this, __socket, socket);
1732
1735
  __privateSet(this, __debug, debug);
1733
- const now = /* @__PURE__ */ new Date();
1736
+ const now = createdAt ?? /* @__PURE__ */ new Date();
1734
1737
  this.createdAt = now;
1735
1738
  __privateSet(this, __lastActiveAt, now);
1736
1739
  __privateSet(this, __hasNotifiedClientStorageUpdateError, false);
@@ -1973,8 +1976,13 @@ var Room = class {
1973
1976
  if (this.sessions.size > 0) {
1974
1977
  throw new Error("This API can only be called before any sessions exist");
1975
1978
  }
1976
- for (const { ticket, socket, lastActivity } of sessions) {
1977
- const newSession = new BrowserSession(ticket, socket, __privateGet(this, __debug2));
1979
+ for (const { ticket, socket, lastActivity, createdAt } of sessions) {
1980
+ const newSession = new BrowserSession(
1981
+ ticket,
1982
+ socket,
1983
+ __privateGet(this, __debug2),
1984
+ createdAt
1985
+ );
1978
1986
  this.sessions.set(ticket.sessionKey, newSession);
1979
1987
  newSession.markActive(lastActivity);
1980
1988
  }