Connection to a remote Couch Database.
object loading / updating / deleting
custom requests
synchronization
event binding
sets name (think: namespace) and some other options
in order to differentiate whether an object from remote should trigger a 'new' or an 'update' event, we store a hash of known objects
name
the name of the Remote is the name of the CouchDB database and is also used to prefix triggered events
sync
if set to true, updates will be continuously pulled
and pushed. Alternatively, sync can be set to
pull: true or push: true.
prefix
prefix for docs in a CouchDB database, e.g. all docs in public user stores are prefixed by '$public/'
wrapper for hoodie.request, with some store specific defaults and a prefixed path
send a GET request to the named view
sends a POST request to the specified updated_function
find one object
find all objects, can be filetered by a type
make sure that only objects starting with
startkey will be returned
save a new object. If it existed before, all properties will be overwritten
remove one object
remove all objects, can be filtered by type
determine between a known and a new object
determine between a known and a new object
start syncing. this.bootstrap() will automatically start
pulling when this.connected remains true.
stop syncing changes from remote store
returns the sequence number from wich to start to find changes in pull
sets the sequence number from wich to start to find changes in pull
inital pull of data of the remote start. By default, we pull all changes since the beginning, but this behavior might be adjusted, e.g for a filtered bootstrap.
a.k.a. make a GET request to CouchDB's _changes feed.
We currently make long poll requests, that we manually abort
and restart each 25 seconds.
Push objects to remote store using the _bulk_docs API.
push objects, then pull updates.
namespaced alias for hoodie.on
namespaced alias for hoodie.trigger
valid CouchDB doc attributes starting with an underscore
parse object for remote storage. All properties starting with an
underscore do not get synchronized despite the special properties
_id, _rev and _deleted (see above)
Also id gets replaced with _id which consists of type & id
prepare CouchDB id
normalize objects coming from remote
renames _id attribute to id and removes the type from the id,
e.g. type/123 -> 123
handle id and type
turn doc/123 into type = doc & id = 123 NOTE: we don't use a simple id.split(/\//) here, as in some cases IDs might contain "/", too
extends passed object with a _rev property
local changes are not meant to be replicated outside of the
users database, therefore the -local suffix.
Depending on whether remote is connected, return a longpoll URL or not
request gets restarted automaticcally when aborted (see @_handlePullError)
request gets restarted automaticcally when aborted (see @_handlePullError)
when there is a change, trigger event, then check for another change
Session is invalid. User is still login, but needs to reauthenticate before sync can be continued
the 404 comes, when the requested DB has been removed or does not exist yet.
BUT: it might also happen that the background workers did not create a pending database yet. Therefore, we try it again in 3 seconds
TODO: review / rethink that.
Please server, don't give us these. At least not persistently
usually a 0, which stands for timeout or server not reachable.
manual abort after 25sec. restart pulling changes directly when connected
oops. This might be caused by an unreachable server. Or the server canceled it for what ever reason, e.g. heroku kills the request after ~30s. we'll try again after a 3s timeout
Remote