SongGuess
    Preparing search index...

    Handles API requests to the /api/{endpoint} endpoints.

    Hierarchy

    • Server<Env>
      • SongGuessAPI
    Index
    __DURABLE_OBJECT_BRAND: never
    axiosClient: AxiosInstance | null = null

    Client used for communication with Apple Music API.

    env: Env
    inFlightRequests: Map<string, Promise<InFlightEntry>> = ...

    Internal registry tracking active, ongoing fetch operations within this DO instance.

    soundCloud: SoundCloudAPI = ...

    Client used for communication with SoundCloud API.

    options: { hibernate?: boolean }
    • get name(): string

      The name for this server.

      Resolves from this.ctx.id.name — the native DO id name, populated whenever the stub was created via idFromName() or getByName(). This is available inside every entry point (including the constructor, alarms, and hibernating websocket handlers).

      For alarm handlers firing on stale on-disk alarm records from older workerd versions that didn't persist name into the alarm record, the name is recovered from a storage fallback record.

      Throws if neither source is available — typically this means the DO was addressed via idFromString() or newUniqueId(), which is not supported by PartyServer.

      Returns string

    • Internal

      — Do not use directly. This is an escape hatch for frameworks (like Agents) that receive calls via native DO RPC, bypassing the standard fetch/alarm/webSocket entry points where initialization normally happens. Calling this from application code is unsupported and may break without notice.

      Returns Promise<void>

    • Internal

      Parameters

      • name: string
      • props: Record<string, unknown> | undefined
      • request: Request

      Returns Promise<Response>

      Retained for backward compatibility with older callers. routePartykitRequest no longer uses this method; it sends props via the x-partykit-props header on the underlying fetch() request.

    • Returns Promise<void>

    • Send a message to all connected clients, except connection ids listed in without

      Parameters

      • msg: string | ArrayBuffer | ArrayBufferView<ArrayBufferLike>
      • Optionalwithout: string[]

      Returns void

    • Caches a fetch response asynchronously while streaming the body content directly to the client. Also prevents redundant fetches during concurrent requests

      Parameters

      • url: URL

        The target URL key for the Cache API storage.

      • fetchFunction: () => Promise<Response>

        An asynchronous supplier returning the underlying network Response.

      Returns Promise<Response>

      A Promise resolving to a Response object suitable for immediate streaming.

    • Parameters

      Returns void | Promise<void>

    • Creates a new SongGuessServer Durable Object by generating a unique ID and then returning the room data.

      Returns Promise<Response>

      A Promise that resolves with a standard Response object.

      • Status 201 (Created) with the room ID as the body on success.
      • Status 409 (Conflict) if no free room ID could be generated.
      • Status 500 (Internal Server Error) on room validation failure.
    • Handle incoming requests to the server.

      Parameters

      Returns Promise<Response>

    • Generates a unique 6-character room ID that does not currently exist.

      Returns Promise<string | null>

      A Promise that resolves with the unique 6-character room ID, or null if a unique ID couldn't be found after 100 attempts.

    • Get a connection by connection id

      Type Parameters

      • TState = unknown

      Parameters

      • id: string

      Returns Connection<TState> | undefined

    • Get all connections. Optionally, you can provide a tag to filter returned connections. Use Server#getConnectionTags to tag the connection on connect.

      Type Parameters

      • TState = unknown

      Parameters

      • Optionaltag: string

      Returns Iterable<Connection<TState>>

    • You can tag a connection to filter them in Server#getConnections. Each connection supports up to 9 tags, each tag max length is 256 characters.

      Parameters

      • connection: Connection
      • context: ConnectionContext

      Returns string[] | Promise<string[]>

    • Fetches playlist information from an Apple Music URL.

      Parameters

      • url: string

        The Apple Music URL of the playlist.

      Returns Promise<
          {
              cover: string
              | null;
              hrefURL: string;
              name: string;
              songs: {
                  artist: string;
                  audioURL: string;
                  cover: string | null;
                  hrefURL: string;
                  name: string;
              }[];
              subtitle?: string;
          },
      >

      A Promise resolving to the Playlist information.

    • Returns void | Promise<void>

    • Called when a connection is closed.

      Parameters

      • connection: Connection
      • code: number
      • reason: string
      • wasClean: boolean

      Returns void | Promise<void>

    • Called when a new connection is made to the server.

      Parameters

      • connection: Connection
      • ctx: ConnectionContext

      Returns void | Promise<void>

    • Called when an error occurs on a connection.

      Parameters

      • connection: Connection
      • error: unknown

      Returns void | Promise<void>

    • Called when an exception occurs.

      Parameters

      • error: unknown

        The error that occurred.

      Returns void | Promise<void>

    • Called when a message is received from a connection.

      Parameters

      • connection: Connection
      • message: WSMessage

      Returns void | Promise<void>

    • Called when the server is started for the first time.

      Parameters

      • Optionalprops: Record<string, unknown>

      Returns void | Promise<void>

    • Parameters

      • query: string

      Returns Promise<
          {
              artist: string;
              audioURL: string;
              cover: string
              | null;
              hrefURL: string;
              name: string;
          }[],
      >

    • Establish this server's name and trigger onStart().

      Use cases:

      1. Framework-level bootstrap of DOs where ctx.id.name is undefined — e.g. DOs addressed via idFromString() / newUniqueId(). setName() stashes the name in memory and persists it under __ps_name so cold-wake invocations recover it via #ensureInitialized()'s legacy fallback.
      2. Delivering initial props to onStart() via the optional second argument.

      For DOs addressed via idFromName() / getByName(), calling setName() is redundant — this.name is available automatically from ctx.id.name. The normal initialization path also persists a fallback record so old-compat alarm handlers can recover the name. Throws if name does not match ctx.id.name.

      Not appropriate for facets. Cloudflare Agents and any other framework using ctx.facets.get(...) should pass an explicit id in FacetStartupOptions so the facet has its own ctx.id.name:

      const stub = ctx.facets.get(facetKey, () => ({
      class: ChildClass,
      id: ctx.exports.SomeBoundDOClass.idFromName(facetName),
      }));

      Without an explicit id, the facet inherits the parent DO's ctx.id (including ctx.id.name), and setName() will throw the ctx.id.name-mismatch error because the facet's intended name differs from the parent's. See https://developers.cloudflare.com/dynamic-workers/usage/durable-object-facets/ for the FacetStartupOptions.id semantics.

      Parameters

      • name: string
      • Optionalprops: Record<string, unknown>

      Returns Promise<void>

      for callers that address DOs via idFromName() / getByName(). Still the supported API for framework-level bootstrap of header/newUniqueId-addressed DOs and for delivering initial props to onStart().

    • Fetches a song from Apple Music API using its ISRC.

      Parameters

      • isrc: string

        the ISRC to look for.

      Returns Promise<Response>

      A promise that resolves to a JSON song object or null if not found.

    • Execute SQL queries against the Server's database

      Type Parameters

      • T = Record<string, string | number | boolean | null>

        Type of the returned rows

      Parameters

      • strings: TemplateStringsArray

        SQL query template strings

      • ...values: (string | number | boolean | null)[]

        Values to be inserted into the query

      Returns T[]

      Array of query results

    • Parameters

      • ws: WebSocket
      • code: number
      • reason: string
      • wasClean: boolean

      Returns Promise<void>

    • Parameters

      Returns Promise<void>

    • Parameters

      Returns Promise<void>