Represents an interface to a y-sweet document management endpoint.

Constructors

Properties

client: HttpClient

Wraps a fetch request with authorization and error handling.

Methods

  • Creates a new document on the y-sweet server given an optional docId. If a document with given ID already exists, this is a no-op.

    Parameters

    • Optional docId: string

      The ID of the document to be created. If not provided, a random ID will be generated.

    Returns Promise<DocCreationResult>

    A DocCreationResult object containing the ID of the created document.

  • Get a client token for the given document.

    If you are using authorization, this is expected to be called from your server after a user has authenticated. The returned token should then be passed to the client.

    Parameters

    • docId: string | DocCreationResult

      The ID of the document to get a token for.

    • Optional authDocRequest: AuthDocRequest

      An optional AuthDocRequest providing options for the token request.

    Returns Promise<ClientToken>

    A ClientToken object containing the URL and token needed to connect to the document.

  • Returns an entire document, represented as a Yjs update byte string.

    Parameters

    • docId: string

      The ID of the document to get.

    Returns Promise<Uint8Array>

    The document as a Yjs update byte string

  • A convenience wrapper around DocumentManager.createDoc and DocumentManager.getClientToken for getting a client token for a document. If a docId is provided, ensures that a document exists with that ID or that one is created. If no docId is provided, a new document is created with a random ID.

    Parameters

    • Optional docId: string

      The ID of the document to get or create. If not provided, a new document with a random ID will be created.

    • Optional authDocRequest: AuthDocRequest

      An optional AuthDocRequest providing options for the token request.

    Returns Promise<ClientToken>

    A ClientToken object containing the URL and token needed to connect to the document.

  • Updates a document with the given Yjs update byte string.

    Parameters

    • docId: string

      The ID of the document to update.

    • update: Uint8Array

      The Yjs update byte string to apply to the document.

    Returns Promise<void>