-
Notifications
You must be signed in to change notification settings - Fork 459
Expand file tree
/
Copy pathindex.ts
More file actions
107 lines (91 loc) · 3.4 KB
/
index.ts
File metadata and controls
107 lines (91 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
var async = require('async');
var ShareDBError = require('../error');
var ERROR_CODE = ShareDBError.CODES;
function DB(options) {
// pollDebounce is the minimum time in ms between query polls
this.pollDebounce = options && options.pollDebounce;
}
module.exports = DB;
// When false, Backend will handle projections instead of DB
DB.prototype.projectsSnapshots = false;
DB.prototype.disableSubscribe = false;
DB.prototype.close = function(callback) {
if (callback) callback();
};
DB.prototype.commit = function(collection, id, op, snapshot, options, callback) {
callback(new ShareDBError(ERROR_CODE.ERR_DATABASE_METHOD_NOT_IMPLEMENTED, 'commit DB method unimplemented'));
};
DB.prototype.getSnapshot = function(collection, id, fields, options, callback) {
callback(new ShareDBError(ERROR_CODE.ERR_DATABASE_METHOD_NOT_IMPLEMENTED, 'getSnapshot DB method unimplemented'));
};
DB.prototype.getSnapshotBulk = function(collection, ids, fields, options, callback) {
var results = Object.create(null);
var db = this;
async.each(ids, function(id, eachCb) {
db.getSnapshot(collection, id, fields, options, function(err, snapshot) {
if (err) return eachCb(err);
results[id] = snapshot;
eachCb();
});
}, function(err) {
if (err) return callback(err);
callback(null, results);
});
};
DB.prototype.getOps = function(collection, id, from, to, options, callback) {
callback(new ShareDBError(ERROR_CODE.ERR_DATABASE_METHOD_NOT_IMPLEMENTED, 'getOps DB method unimplemented'));
};
DB.prototype.getOpsToSnapshot = function(collection, id, from, snapshot, options, callback) {
var to = snapshot.v;
this.getOps(collection, id, from, to, options, callback);
};
DB.prototype.getOpsBulk = function(collection, fromMap, toMap, options, callback) {
var results = Object.create(null);
var db = this;
async.forEachOf(fromMap, function(from, id, eachCb) {
var to = toMap && toMap[id];
db.getOps(collection, id, from, to, options, function(err, ops) {
if (err) return eachCb(err);
results[id] = ops;
eachCb();
});
}, function(err) {
if (err) return callback(err);
callback(null, results);
});
};
DB.prototype.getCommittedOpVersion = function(collection, id, snapshot, op, options, callback) {
this.getOpsToSnapshot(collection, id, 0, snapshot, options, function(err, ops) {
if (err) return callback(err);
for (var i = ops.length; i--;) {
var item = ops[i];
if (op.src === item.src && op.seq === item.seq) {
return callback(null, item.v);
}
}
callback();
});
};
DB.prototype.query = function(collection, query, fields, options, callback) {
callback(new ShareDBError(ERROR_CODE.ERR_DATABASE_METHOD_NOT_IMPLEMENTED, 'query DB method unimplemented'));
};
DB.prototype.queryPoll = function(collection, query, options, callback) {
var fields = Object.create(null);
this.query(collection, query, fields, options, function(err, snapshots, extra) {
if (err) return callback(err);
var ids = [];
for (var i = 0; i < snapshots.length; i++) {
ids.push(snapshots[i].id);
}
callback(null, ids, extra);
});
};
DB.prototype.queryPollDoc = function(collection, id, query, options, callback) {
callback(new ShareDBError(ERROR_CODE.ERR_DATABASE_METHOD_NOT_IMPLEMENTED, 'queryPollDoc DB method unimplemented'));
};
DB.prototype.canPollDoc = function() {
return false;
};
DB.prototype.skipPoll = function() {
return false;
};