source-graph-stream-client
    Preparing search index...

    source-graph-stream-client

    SourceGraph Search Streaming Client

    A streaming client for SourceGraph search results.

    Implements a client for streaming search results from a SourceGraph instance, provide an async generators for the search results, and support for authentication via access tokens or OAuth tokens.

    See the Sourcegraph Stream API for more details.

    Battle-tested in production environments.

    auto-release

    Install the package:

    npm i source-graph-stream-client
    

    Create a client with your SourceGraph instance URL and access token:

    import {SourceGraphClient} from "source-graph-stream-client";

    const client = new SourceGraphClient({
    url: "https://example.sourcegraph.com/.api/search/stream",
    accessToken: "your-access-token",
    });

    The minimal required options are url and either accessToken or oauthToken.

    Option Type Description Default
    url string The SourceGraph instance search stream endpoint. required
    accessToken string The access token for authentication. Can not use with oauthToken undefined
    oauthToken string The OAuth token for authentication. Can not use with accessToken undefined
    throwOnError boolean Whether to throw an error for fail to parse a message or just skip it. false
    init RequestInit Additional fetch options to use when making requests. undefined

    See the options definition for more details


    Stream search results using for-await-of:

    for await (const result of client.search("your search query")) {
    console.log(result);
    }
    for await (const result of client.search("query", {displayLimit: 10})) {
    console.log(result);
    }

    See the SearchOptions type for all available search options.

    The client exports the following search result types:

    • ContentSearchResult - represents a result from a file content.
    • RepoSearchResult - represents a result from a repository name/path.
    • PathSearchResult - represents a result from a file/directory path.

    See the types definitions for more details.

    You can also stream all SourceGraph events (not just search results) using the raw method:

    for await (const event of client.raw("your search query")) {
    console.log(event);
    }

    See the SourceGraph Event-Types for more details.