-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStorage.js
92 lines (83 loc) · 2.06 KB
/
Storage.js
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
/**
* The main interface to the data.
* Usage:
* var storage = new Storage();
* storage.setImplementation(...);
* storage.addEntry(...);
*
* @constructor
*/
function Storage() {
var impl;
/**
* Sets the backed implementation for this class. Any call to {@link Storage}
* methods will be redirected to the provided implementation.
*/
this.setImplementation = function(implementation) {
impl = implementation;
}
/**
* @return {int} the number of entries
*/
this.getEntryCount = function() {
return impl.getEntryCount();
}
/**
* @return {Tags}
*/
this.getTagManager = function() {
return impl.getTagManager();
}
/**
* Adds a new entry.
* @param {string} content
* @param {array} tags - array of strings
* @return {object}
*/
this.addEntry = function(content, tags) {
return impl.addEntry(content, tags);
}
/**
* Updates an existing entry.
* @param entry {object}
* @throw error if the entry is not valid.
*/
this.updateEntry = function(entry) {
return impl.updateEntry(entry);
}
/**
* Searches the entries by the given tagName, and retrieves {@code count}
* results from the {@code offset}.
* @param tagName {string}
* @param offset {int} the start index
* @param count {int} the maximum number of items to retrieve
* @return
* { searchType: string,
* searchValue: string,
* hasMore: boolean,
* offset: int,
* count: int,
* entries: Array.<{content: string,
* tags: Array.<string>,
* updatedDate: number}
* }
*/
this.findEntriesByTag = function(tagName, offset, count) {
var entries = impl.findEntriesByTagImpl(tagName, offset, count + 1);
var result = {
searchType: 'tag',
searchValue: tagName,
offset: offset,
count: count,
hasMore: (entries.length > count),
entries: entries,
};
if (result.hasMore) {
entries.pop();
}
return result;
};
}
if (typeof DriveApp == "undefined") {
module.exports = Storage;
}