import PouchDB from 'pouchdb-browser'
import PouchDBFindPlugin from 'pouchdb-find'
import PouchDBUpsertPlugin from 'pouchdb-upsert'

export default PouchDB.plugin(PouchDBFindPlugin).plugin(PouchDBUpsertPlugin)

// Type guard to check if the error is of type `Error` and has a `name` property
export function isNotFoundError(error: unknown): error is { name: string } {
  return (
    typeof error === 'object' &&
    error !== null &&
    'name' in error &&
    (error as { name: string }).name === 'not_found'
  )
}
