Skip to content

cozy-pouch-link / PouchLink

Class: PouchLink

Link to be passed to a CozyClient instance to support CouchDB. It instantiates PouchDB collections for each doctype that it supports and knows how to respond to queries and mutations.

Hierarchy

  • default

    PouchLink

Constructors

constructor

new PouchLink(opts)

constructor - Initializes a new PouchLink

Parameters

Name Type
opts PouchLinkOptions

Overrides

CozyLink.constructor

Defined in

CozyPouchLink.js:94

Properties

client

client: any

Defined in

CozyPouchLink.js:169


doctypes

doctypes: string[]

Defined in

CozyPouchLink.js:112


doctypesReplicationOptions

doctypesReplicationOptions: Record<string, any>

Defined in

CozyPouchLink.js:113


indexes

indexes: Object

Defined in

CozyPouchLink.js:114


initialSync

initialSync: boolean

Defined in

CozyPouchLink.js:118


options

options: { replicationInterval: number } & PouchLinkOptions

Defined in

CozyPouchLink.js:106


performanceApi

performanceApi: any

Defined in

CozyPouchLink.js:134


periodicSync

periodicSync: boolean

Defined in

CozyPouchLink.js:119


pouches

pouches: any

Defined in

CozyPouchLink.js:242


replicationStatus

replicationStatus: Record<string, ReplicationStatus>

Defined in

CozyPouchLink.js:122


storage

storage: PouchLocalStorage

Defined in

CozyPouchLink.js:115

Methods

addReferencesTo

addReferencesTo(mutation): Promise<void>

Parameters

Name Type
mutation any

Returns

Promise<void>

Defined in

CozyPouchLink.js:845


createDocument

createDocument(mutation): Promise<any>

Parameters

Name Type
mutation any

Returns

Promise<any>

Defined in

CozyPouchLink.js:806


createIndex

createIndex(fields, indexOption?): Promise<PouchDbIndex>

Create the PouchDB index if not existing

Parameters

Name Type Description
fields any[] Fields to index
indexOption Object Options for the index
indexOption.doctype string -
indexOption.indexName string -
indexOption.partialFilter any -

Returns

Promise<PouchDbIndex>

Defined in

CozyPouchLink.js:611


dbMethod

dbMethod(method, mutation): Promise<any>

Parameters

Name Type
method any
mutation any

Returns

Promise<any>

Defined in

CozyPouchLink.js:849


deleteDocument

deleteDocument(mutation): Promise<any>

Parameters

Name Type
mutation any

Returns

Promise<any>

Defined in

CozyPouchLink.js:834


executeMutation

executeMutation(mutation, options, result, forward): Promise<any>

Parameters

Name Type
mutation any
options any
result any
forward any

Returns

Promise<any>

Defined in

CozyPouchLink.js:768


executeQuery

executeQuery(__namedParameters): Promise<{ data: any = res.cozyPouchData; meta: undefined ; next: undefined ; skip: undefined = offset } | { data: any ; meta: { count: any = docs.length } ; next: boolean ; skip: any = offset }>

Parameters

Name Type
__namedParameters Object

Returns

Promise<{ data: any = res.cozyPouchData; meta: undefined ; next: undefined ; skip: undefined = offset } | { data: any ; meta: { count: any = docs.length } ; next: boolean ; skip: any = offset }>

Defined in

CozyPouchLink.js:688


findExistingIndex

findExistingIndex(doctype, options, indexName): PouchDbIndex

Retrieve the PouchDB index if exist, undefined otherwise

Parameters

Name Type Description
doctype string The query’s doctype
options MangoQueryOptions The find options
indexName string The index name

Returns

PouchDbIndex

Defined in

CozyPouchLink.js:635


getChanges

getChanges(doctype, options): Promise<PouchDBChangesResults>

Get PouchDB changes See https://pouchdb.com/api.html#changes

Parameters

Name Type Description
doctype string The PouchDB database’s doctype
options any The changes options. See https://pouchdb.com/api.html#changes

Returns

Promise<PouchDBChangesResults>

The changes

Defined in

CozyPouchLink.js:481


getDbInfo

getDbInfo(doctype): Promise<PouchDBInfo>

Get PouchDB database info See https://pouchdb.com/api.html#database_information

Parameters

Name Type Description
doctype string The PouchDB database’s doctype

Returns

Promise<PouchDBInfo>

The db info

Defined in

CozyPouchLink.js:496


getPouch

getPouch(doctype): any

Parameters

Name Type
doctype any

Returns

any

Defined in

CozyPouchLink.js:402


getReplicationURL

getReplicationURL(doctype): string

Parameters

Name Type
doctype any

Returns

string

Defined in

CozyPouchLink.js:149


getSyncInfo

getSyncInfo(doctype): any

Parameters

Name Type
doctype any

Returns

any

Defined in

CozyPouchLink.js:398


handleDoctypeSyncEnd

handleDoctypeSyncEnd(doctype): void

Parameters

Name Type
doctype any

Returns

void

Defined in

CozyPouchLink.js:300


handleDoctypeSyncStart

handleDoctypeSyncStart(doctype): void

Parameters

Name Type
doctype any

Returns

void

Defined in

CozyPouchLink.js:295


handleOnSync

handleOnSync(doctypeUpdates): void

Receives PouchDB updates (documents grouped by doctype). Normalizes the data (.id -> ._id, .rev -> _rev). Passes the data to the client and to the onSync handler.

Emits an event (pouchlink:sync:end) when the sync (all doctypes) is done

Parameters

Name Type
doctypeUpdates any

Returns

void

Defined in

CozyPouchLink.js:281


hasIndex

hasIndex(name): boolean

Parameters

Name Type
name any

Returns

boolean

Defined in

CozyPouchLink.js:597


migrateAdapter

migrateAdapter(params): Promise<void>

Migrate the current adapter

property {string} [fromAdapter] - The current adapter type, e.g. ‘idb’

property {string} [toAdapter] - The new adapter type, e.g. ‘indexeddb’

property {string} [url] - The Cozy URL

property {Array} [plugins] - The PouchDB plugins

Parameters

Name Type Description
params MigrationParams Migration params

Returns

Promise<void>

Defined in

CozyPouchLink.js:183


needsToWaitWarmup

needsToWaitWarmup(doctype): Promise<boolean>

Check if there is warmup queries for this doctype and return if those queries are already warmed up or not

Parameters

Name Type Description
doctype string Doctype to check

Returns

Promise<boolean>

the need to wait for the warmup

Defined in

CozyPouchLink.js:583


onLogin

onLogin(): Promise<void>

Returns

Promise<void>

Defined in

CozyPouchLink.js:202


onSyncError

onSyncError(error): Promise<void>

Parameters

Name Type
error any

Returns

Promise<void>

Defined in

CozyPouchLink.js:378


persistCozyData

persistCozyData(data, forward?): Promise<void>

Parameters

Name Type Default value
data any undefined
forward (operation: any, result: any) => void doNothing

Returns

Promise<void>

Overrides

CozyLink.persistCozyData

Defined in

CozyPouchLink.js:531


registerClient

registerClient(client): Promise<void>

Parameters

Name Type
client any

Returns

Promise<void>

Defined in

CozyPouchLink.js:168


request

request(operation, options, result?, forward?): Promise<any>

Parameters

Name Type Default value
operation any undefined
options any undefined
result any null
forward (operation: any, result: any) => void doNothing

Returns

Promise<any>

Overrides

CozyLink.request

Defined in

CozyPouchLink.js:421


reset

reset(): Promise<void>

Returns

Promise<void>

Overrides

CozyLink.reset

Defined in

CozyPouchLink.js:265


sanitizeJsonApi

sanitizeJsonApi(data): Omit<Pick<any, string | number | symbol>, "attributes" | "meta">

Parameters

Name Type
data any

Returns

Omit<Pick<any, string | number | symbol>, "attributes" | "meta">

Defined in

CozyPouchLink.js:504


startReplication

startReplication(options?): void

User of the link can call this to start ongoing replications. Typically, it can be used when the application regains focus.

Emits pouchlink:sync:start event when the replication begins

Parameters

Name Type Description
options Object The options
options.waitForReplications boolean -

Returns

void

Defined in

CozyPouchLink.js:334


startReplicationWithDebounce

startReplicationWithDebounce(options?): void

Debounced version of startReplication() method

Debounce delay can be configured through constructor’s syncDebounceDelayInMs option

Parameters

Name Type Description
options Object The options
options.waitForReplications boolean -

Returns

void

Defined in

CozyPouchLink.js:351


stopReplication

stopReplication(): void

User of the link can call this to stop ongoing replications. Typically, it can be used when the applications loses focus.

Emits pouchlink:sync:stop event

Returns

void

Defined in

CozyPouchLink.js:370


supportsOperation

supportsOperation(operation): boolean

Parameters

Name Type
operation any

Returns

boolean

Defined in

CozyPouchLink.js:406


syncImmediately

syncImmediately(): Promise<void>

Returns

Promise<void>

Defined in

CozyPouchLink.js:879


updateDocument

updateDocument(mutation): Promise<any>

Parameters

Name Type
mutation any

Returns

Promise<any>

Defined in

CozyPouchLink.js:811


updateDocuments

updateDocuments(mutation): Promise<any[]>

Parameters

Name Type
mutation any

Returns

Promise<any[]>

Defined in

CozyPouchLink.js:816


getPouchAdapterName

Static getPouchAdapterName(localStorage): Promise<string>

Return the PouchDB adapter name. Should be IndexedDB for newest adapters.

Parameters

Name Type Description
localStorage LocalStorage Methods to access local storage

Returns

Promise<string>

The adapter name

Defined in

CozyPouchLink.js:144