How to use the lib0/error.js.unexpectedCase function in lib0

To help you get started, we’ve selected a few lib0 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yjs / yjs / src / utils / RelativePosition.js View on Github external
export const writeRelativePosition = (encoder, rpos) => {
  const { type, tname, item } = rpos
  if (item !== null) {
    encoding.writeVarUint(encoder, 0)
    writeID(encoder, item)
  } else if (tname !== null) {
    // case 2: found position at the end of the list and type is stored in y.share
    encoding.writeUint8(encoder, 1)
    encoding.writeVarString(encoder, tname)
  } else if (type !== null) {
    // case 3: found position at the end of the list and type is attached to an item
    encoding.writeUint8(encoder, 2)
    writeID(encoder, type)
  } else {
    throw error.unexpectedCase()
  }
  return encoder
}
github yjs / yjs / src / structs / Item.js View on Github external
  () => { throw error.unexpectedCase() }, // GC is not ItemContent
  readContentDeleted,
github yjs / yjs / src / utils / StructStore.js View on Github external
while (left <= right) {
    const midindex = math.floor((left + right) / 2)
    const mid = structs[midindex]
    const midclock = mid.id.clock
    if (midclock <= clock) {
      if (clock < midclock + mid.length) {
        return midindex
      }
      left = midindex + 1
    } else {
      right = midindex - 1
    }
  }
  // Always check state before looking for a struct in StructStore
  // Therefore the case of not finding a struct is unexpected
  throw error.unexpectedCase()
}
github yjs / yjs / src / utils / ID.js View on Github external
export const findRootTypeKey = type => {
  // @ts-ignore _y must be defined, otherwise unexpected case
  for (let [key, value] of type.doc.share) {
    if (value === type) {
      return key
    }
  }
  throw error.unexpectedCase()
}
github yjs / yjs / src / structs / Item.js View on Github external
parent = /** @type {ContentType} */ (parentItem.content).type
      }
    } else if (this.parentYKey !== null) {
      parent = transaction.doc.get(this.parentYKey)
    } else if (left !== null) {
      if (left.constructor !== GC) {
        parent = left.parent
        parentSub = left.parentSub
      }
    } else if (right !== null) {
      if (right.constructor !== GC) {
        parent = right.parent
        parentSub = right.parentSub
      }
    } else {
      throw error.unexpectedCase()
    }

    return parent === null
      ? new GC(this.id, this.length)
      : new Item(
        this.id,
        left,
        this.left,
        right,
        this.right,
        parent,
        parentSub,
        this.content
      )
  }
}
github yjs / yjs / src / structs / Item.js View on Github external
gc (store, parentGCd) {
    if (!this.deleted) {
      throw error.unexpectedCase()
    }
    this.content.gc(store)
    if (parentGCd) {
      replaceStruct(store, this, new GC(this.id, this.length))
    } else {
      this.content = new ContentDeleted(this.length)
    }
  }
github yjs / yjs / src / utils / relativePosition.js View on Github external
if (type._length === apos.offset) {
    return createRelativePosition(type, null)
  } else {
    let offset = apos.offset
    let n = type._start
    while (n !== null) {
      if (!n.deleted && n.countable) {
        if (n.length > offset) {
          return createRelativePosition(type, ID.createID(n.id.client, n.id.clock + offset))
        }
        offset -= n.length
      }
      n = n.right
    }
  }
  throw error.unexpectedCase()
}