Type alias BlobMergeCallback

BlobMergeCallback: ((args: BlobMergeCallbackParams) => Promise<BlobMergeCallbackResult>)

Type declaration

    • (args: BlobMergeCallbackParams): Promise<BlobMergeCallbackResult>
    • Provides a custom merge strategy when the default one is not sufficient.

      Example

      Prefer their changes without reading the content of the blob and just returning their object id.

      const obBlobMerge: BlobMergeCallback = async ({ theirBlob, ourBlob }) => {
      if (ourBlob && theirBlob) {
      return { oid: await theirBlob.oid(), mode: await theirBlob.mode() }
      }

      throw new MergeNotSupportedError()
      }

      Example

      Prefer their changes with returning their text.

      const obBlobMerge: BlobMergeCallback = async ({ theirBlob, ourBlob }) => {
      if (ourBlob && theirBlob) {
      const ourContent = await ourBlob.content()
      const theirContent = await theirBlob.content()

      const decoder = new TextDecoder()
      const ourText = decoder.decode(ourContent)
      const theirText = decoder.decode(theirContent)

      return { mergedText: theirText, mode: await theirBlob.mode() }
      }

      throw new MergeNotSupportedError()
      }

      Please note that those examples are very basic implementations. The actual one could be much more complicated and could include following the logic:

      • Detect if the blob has binary or text content:
      • Decide what to do if there is no base blob.
      • Decide what to do if one of the blobs were deleted.

      Throws

      MergeNotSupportedError when merge is not clean.

      Parameters

      Returns Promise<BlobMergeCallbackResult>

Generated using TypeDoc