class_docstr: Define the ``PATCH-DOC`` message for sending Document patch events
  between remote documents.
  
  The ``content`` fragment of for this message is has the form:
  
  .. code-block:: python
  
      {
          'events'     : <protocol document events>
          'references' : <model references>
      }
docstr: Create a ``PATCH-DOC`` message
  
  Args:
      events (list) :
          A list of patch events to apply to a document
  
  Any additional keyword arguments will be put into the message
  ``metadata`` fragment as-is.
docstr_tok: ["Create","a","``","PATCH-DOC","``","message","Args",":","events","(","list",")",":","A","list","of","patch","events","to","apply","to","a","document","Any","additional","keyword","arguments","will","be","put","into","the","message","``","metadata","``","fragment","as-is","."]
code: def create(
      cls, events: list[DocumentPatchedEvent], **metadata: Any
  ) -> patch_doc:
      """Create a ``PATCH-DOC`` message
  
      Args:
          events (list) :
              A list of patch events to apply to a document
  
      Any additional keyword arguments will be put into the message
      ``metadata`` fragment as-is.
  
      """
      header = cls.create_header()
  
      if not events:
          raise ValueError(
              "PATCH-DOC message requires at least one event"
          )
  
      docs = {event.document for event in events}
      if len(docs) != 1:
          raise ValueError(
              "PATCH-DOC message configured with events for more than one document"
          )
  
      [doc] = docs
      serializer = Serializer(references=doc.models.synced_references)
      patch_json = PatchJson(events=serializer.encode(events))
      doc.models.flush_synced(
          lambda model: not serializer.has_ref(model)
      )
  
      msg = cls(header, metadata, patch_json)
  
      for buffer in serializer.buffers:
          msg.add_buffer(buffer)
  
      return msg
  
file_path: bokeh/src/bokeh/protocol/messages/patch_doc.py
imports: from __future__ import annotations
  import logging
  from typing import TYPE_CHECKING, Any
  from ...core.serialization import Serializer
  from ...document.callbacks import invoke_with_curdoc
  from ...document.json import PatchJson
  from ..message import Message
label_desc: Use image node_id 1 for calling the patch_doc obj's underlying member method code with example usage: obj.create(cls, events) and returns: msg