API reference › @evolu/common › local‑first/Owner › parseOwnerIdFromOwnerWebSocketTransportUrl

function parseOwnerIdFromOwnerWebSocketTransportUrl(
  url: string,
): (string & Brand<"Id"> & Brand<"OwnerId">) | null;

Defined in: packages/common/src/local-first/Owner.ts:733

Extracts OwnerId from the URL of an OwnerWebSocketTransport or the request target of its handshake.

Returns the ownerId query parameter if the query has exactly one and it is a valid OwnerId, and null otherwise. Other query parameters are ignored.

Example

import {
  assertEqual,
  parseOwnerIdFromOwnerWebSocketTransportUrl,
  testAppOwner,
} from "@evolu/common";

assertEqual(
  parseOwnerIdFromOwnerWebSocketTransportUrl(
    `/sync?ownerId=${testAppOwner.id}`,
  ),
  testAppOwner.id,
);
assertEqual(
  parseOwnerIdFromOwnerWebSocketTransportUrl("/sync?ownerId=invalid"),
  null,
);