backendless 6.3.15 → 6.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/backendless.d.ts +332 -0
- package/dist/backendless.js +1964 -184
- package/dist/backendless.js.map +1 -1
- package/dist/backendless.min.js +2 -2
- package/es/hive/constants.js +14 -0
- package/es/hive/index.js +81 -0
- package/es/hive/stores/base-store.js +249 -0
- package/es/hive/stores/index.js +70 -0
- package/es/hive/stores/key-value.js +153 -0
- package/es/hive/stores/list.js +210 -0
- package/es/hive/stores/map.js +222 -0
- package/es/hive/stores/set.js +180 -0
- package/es/hive/stores/sorted-set.js +477 -0
- package/es/index.js +8 -0
- package/es/urls.js +16 -2
- package/es/utils.js +3 -0
- package/lib/hive/constants.js +14 -0
- package/lib/hive/index.js +81 -0
- package/lib/hive/stores/base-store.js +249 -0
- package/lib/hive/stores/index.js +70 -0
- package/lib/hive/stores/key-value.js +153 -0
- package/lib/hive/stores/list.js +210 -0
- package/lib/hive/stores/map.js +222 -0
- package/lib/hive/stores/set.js +180 -0
- package/lib/hive/stores/sorted-set.js +477 -0
- package/lib/index.js +8 -0
- package/lib/urls.js +16 -2
- package/lib/utils.js +3 -0
- package/package.json +2 -2
- package/src/hive/constants.js +7 -0
- package/src/hive/index.js +60 -0
- package/src/hive/stores/base-store.js +173 -0
- package/src/hive/stores/index.js +5 -0
- package/src/hive/stores/key-value.js +108 -0
- package/src/hive/stores/list.js +165 -0
- package/src/hive/stores/map.js +180 -0
- package/src/hive/stores/set.js +136 -0
- package/src/hive/stores/sorted-set.js +407 -0
- package/src/index.js +5 -0
- package/src/urls.js +11 -1
- package/src/utils.js +4 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import Utils from '../../utils'
|
|
2
|
+
|
|
3
|
+
export class HiveStore {
|
|
4
|
+
|
|
5
|
+
static STATIC_METHODS = ['keys', 'delete', 'exists', 'touch']
|
|
6
|
+
|
|
7
|
+
static registerType(hive) {
|
|
8
|
+
const context = { ...this, app: hive.app, hiveName: hive.hiveName }
|
|
9
|
+
const factory = storeKey => new this(context, storeKey)
|
|
10
|
+
|
|
11
|
+
this.STATIC_METHODS.forEach(methodName => {
|
|
12
|
+
factory[methodName] = (...args) => this[methodName].apply(context, args)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
return factory
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
constructor(context, storeKey) {
|
|
19
|
+
this.TYPE = this.constructor.TYPE
|
|
20
|
+
|
|
21
|
+
if (!storeKey || typeof storeKey !== 'string') {
|
|
22
|
+
throw new Error('Store key must be a string.')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
this.app = context.app
|
|
26
|
+
this.hiveName = context.hiveName
|
|
27
|
+
|
|
28
|
+
this.storeKey = storeKey
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static keys(options) {
|
|
32
|
+
if (options !== undefined) {
|
|
33
|
+
if (!Utils.isObject(options)) {
|
|
34
|
+
throw new Error('Options must be an object.')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const { cursor, pageSize, filterPattern } = options
|
|
38
|
+
|
|
39
|
+
if (cursor !== undefined && (typeof cursor !== 'number' || isNaN(cursor))) {
|
|
40
|
+
throw new Error('Cursor must be a number.')
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (pageSize !== undefined && (typeof pageSize !== 'number' || isNaN(pageSize))) {
|
|
44
|
+
throw new Error('Page size must be a number.')
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (filterPattern !== undefined && (typeof filterPattern !== 'string' || !filterPattern)) {
|
|
48
|
+
throw new Error('Filter pattern must be a string.')
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return this.app.request
|
|
53
|
+
.get({
|
|
54
|
+
url : `${this.app.urls.hiveStore(this.hiveName, this.TYPE)}/keys`,
|
|
55
|
+
query: options
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static delete(keys) {
|
|
60
|
+
if (!Array.isArray(keys)) {
|
|
61
|
+
throw new Error('Keys must be provided and must be a list of strings.')
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return this.app.request
|
|
65
|
+
.delete({
|
|
66
|
+
url : this.app.urls.hiveStore(this.hiveName, this.TYPE),
|
|
67
|
+
data: keys
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static exists(keys) {
|
|
72
|
+
if (!Array.isArray(keys)) {
|
|
73
|
+
throw new Error('Keys must be provided and must be a list of strings.')
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return this.app.request
|
|
77
|
+
.post({
|
|
78
|
+
url : `${this.app.urls.hiveStore(this.hiveName, this.TYPE)}/action/exists`,
|
|
79
|
+
data: keys
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static touch(keys) {
|
|
84
|
+
if (!Array.isArray(keys)) {
|
|
85
|
+
throw new Error('Keys must be provided and must be a list of strings.')
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return this.app.request
|
|
89
|
+
.put({
|
|
90
|
+
url : `${this.app.urls.hiveStore(this.hiveName, this.TYPE)}/action/touch`,
|
|
91
|
+
data: keys
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
getBaseURL() {
|
|
96
|
+
return `${this.app.urls.hiveStore(this.hiveName, this.TYPE)}/${this.storeKey}`
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
delete() {
|
|
100
|
+
return this.constructor.delete.call({ ...this, ...this.constructor }, [this.storeKey])
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async exists() {
|
|
104
|
+
const result = await this.constructor.exists.call({ ...this, ...this.constructor }, [this.storeKey])
|
|
105
|
+
|
|
106
|
+
return !!result
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
rename(newKey, overwrite) {
|
|
110
|
+
if (!newKey || typeof newKey !== 'string') {
|
|
111
|
+
throw new Error('New key name must be provided and must be a string.')
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (overwrite !== undefined && typeof overwrite !== 'boolean') {
|
|
115
|
+
throw new Error('Overwrite must be a boolean.')
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return this.app.request
|
|
119
|
+
.put({
|
|
120
|
+
url : `${this.getBaseURL()}/rename`,
|
|
121
|
+
query: { newKey, overwrite }
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
getExpiration() {
|
|
126
|
+
return this.app.request
|
|
127
|
+
.get({
|
|
128
|
+
url: `${this.getBaseURL()}/get-expiration-ttl`,
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
clearExpiration() {
|
|
133
|
+
return this.app.request
|
|
134
|
+
.put({
|
|
135
|
+
url: `${this.getBaseURL()}/clear-expiration`,
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
expireAfter(ttl) {
|
|
140
|
+
if (isNaN(ttl) || typeof ttl !== 'number') {
|
|
141
|
+
throw new Error('TTL must be a number.')
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return this.app.request
|
|
145
|
+
.put({
|
|
146
|
+
url : `${this.getBaseURL()}/expire`,
|
|
147
|
+
query: { ttl }
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
expireAt(unixTime) {
|
|
152
|
+
if (isNaN(unixTime) || typeof unixTime !== 'number') {
|
|
153
|
+
throw new Error('Expiration time must be a number.')
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return this.app.request
|
|
157
|
+
.put({
|
|
158
|
+
url : `${this.getBaseURL()}/expire-at`,
|
|
159
|
+
query: { unixTime }
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
touch() {
|
|
164
|
+
return this.constructor.touch.call({ ...this, ...this.constructor }, [this.storeKey])
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
secondsSinceLastOperation() {
|
|
168
|
+
return this.app.request
|
|
169
|
+
.get({
|
|
170
|
+
url: `${this.getBaseURL()}/seconds-since-last-operation`,
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { HiveTypes } from '../constants'
|
|
2
|
+
import { HiveStore } from './base-store'
|
|
3
|
+
import Utils from '../../utils'
|
|
4
|
+
|
|
5
|
+
export class KeyValueStore extends HiveStore {
|
|
6
|
+
|
|
7
|
+
static TYPE = HiveTypes.KEY_VALUE
|
|
8
|
+
|
|
9
|
+
static STATIC_METHODS = [...HiveStore.STATIC_METHODS, 'get', 'set']
|
|
10
|
+
|
|
11
|
+
static get(keys) {
|
|
12
|
+
if (!Array.isArray(keys)) {
|
|
13
|
+
throw new Error('Keys must be provided and must be a list of strings.')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return this.app.request
|
|
17
|
+
.post({
|
|
18
|
+
url : this.app.urls.hiveStore(this.hiveName, this.TYPE),
|
|
19
|
+
data: keys
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static set(key, value, options) {
|
|
24
|
+
if (Utils.isObject(key)) {
|
|
25
|
+
if (!Object.keys(key).length) {
|
|
26
|
+
throw new Error('Provided object must have at least 1 key.')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return this.app.request
|
|
30
|
+
.put({
|
|
31
|
+
url : this.app.urls.hiveStore(this.hiveName, this.TYPE),
|
|
32
|
+
data: key
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!key || typeof key !== 'string') {
|
|
37
|
+
throw new Error('Key must be provided and must be a string.')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (options !== undefined) {
|
|
41
|
+
if (!Utils.isObject(options)) {
|
|
42
|
+
throw new Error('Options must be an object.')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const { ttl, expireAt, condition } = options
|
|
46
|
+
|
|
47
|
+
if (ttl !== undefined && (isNaN(ttl) || typeof ttl !== 'number')) {
|
|
48
|
+
throw new Error('TTL in seconds must be a number.')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (expireAt !== undefined && (isNaN(expireAt) || typeof expireAt !== 'number')) {
|
|
52
|
+
throw new Error('ExpireAt timestamp must be a number.')
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (condition !== undefined && !['IfExists', 'IfNotExists', 'Always'].includes(condition)) {
|
|
56
|
+
throw new Error('Condition must be one of this values: [IfExists, IfNotExists, Always].')
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return this.app.request
|
|
61
|
+
.put({
|
|
62
|
+
url : `${this.app.urls.hiveStore(this.hiveName, this.TYPE)}/${key}`,
|
|
63
|
+
data: {
|
|
64
|
+
value,
|
|
65
|
+
...options
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get() {
|
|
71
|
+
return this.app.request
|
|
72
|
+
.get({
|
|
73
|
+
url: this.getBaseURL(),
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
set(value, options) {
|
|
78
|
+
return this.constructor.set.apply({ ...this, ...this.constructor }, [this.storeKey, value, options])
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
increment(value) {
|
|
82
|
+
if (isNaN(value) || typeof value !== 'number') {
|
|
83
|
+
throw new Error('Value must be provided and must be a number.')
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return this.app.request
|
|
87
|
+
.put({
|
|
88
|
+
url : `${this.getBaseURL()}/increment`,
|
|
89
|
+
query: {
|
|
90
|
+
value
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
decrement(value) {
|
|
96
|
+
if (isNaN(value) || typeof value !== 'number') {
|
|
97
|
+
throw new Error('Value must be provided and must be a number.')
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return this.app.request
|
|
101
|
+
.put({
|
|
102
|
+
url : `${this.getBaseURL()}/decrement`,
|
|
103
|
+
query: {
|
|
104
|
+
value
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { HiveTypes } from '../constants'
|
|
2
|
+
import { HiveStore } from './base-store'
|
|
3
|
+
import Utils from '../../utils'
|
|
4
|
+
|
|
5
|
+
export class ListStore extends HiveStore {
|
|
6
|
+
|
|
7
|
+
static TYPE = HiveTypes.LIST
|
|
8
|
+
|
|
9
|
+
get(from, to) {
|
|
10
|
+
if (to !== undefined) {
|
|
11
|
+
if (isNaN(to) || typeof to !== 'number') {
|
|
12
|
+
throw new Error('Index To must be a number.')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (isNaN(from) || typeof from !== 'number') {
|
|
16
|
+
throw new Error('Index From must be a number.')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return this.app.request
|
|
20
|
+
.get({
|
|
21
|
+
url : this.getBaseURL(),
|
|
22
|
+
query: { from, to }
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (from !== undefined) {
|
|
27
|
+
if (isNaN(from) || typeof from !== 'number') {
|
|
28
|
+
throw new Error('Index must be a number.')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return this.app.request
|
|
32
|
+
.get({
|
|
33
|
+
url: `${this.getBaseURL()}/${from}`,
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return this.app.request
|
|
38
|
+
.get({
|
|
39
|
+
url: this.getBaseURL(),
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
set(value, index) {
|
|
44
|
+
if (Array.isArray(value)) {
|
|
45
|
+
return this.app.request
|
|
46
|
+
.put({
|
|
47
|
+
url : this.getBaseURL(),
|
|
48
|
+
data: value
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (isNaN(index) || typeof index !== 'number') {
|
|
53
|
+
throw new Error('Index must be a number.')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return this.app.request
|
|
57
|
+
.put({
|
|
58
|
+
url : `${this.getBaseURL()}/${index}`,
|
|
59
|
+
data: {
|
|
60
|
+
value
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
length() {
|
|
66
|
+
return this.app.request
|
|
67
|
+
.get({
|
|
68
|
+
url: `${this.getBaseURL()}/length`,
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
insertBefore(valueToInsert, anchorValue) {
|
|
73
|
+
return this.insert(valueToInsert, anchorValue, true)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
insertAfter(valueToInsert, anchorValue) {
|
|
77
|
+
return this.insert(valueToInsert, anchorValue, false)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
insert(valueToInsert, anchorValue, before) {
|
|
81
|
+
if (!valueToInsert || typeof valueToInsert !== 'string') {
|
|
82
|
+
throw new Error('ValueToInsert must be provided and must be a string.')
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!anchorValue || typeof anchorValue !== 'string') {
|
|
86
|
+
throw new Error('AnchorValue must be provided and must be a string.')
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return this.app.request
|
|
90
|
+
.put({
|
|
91
|
+
url : `${this.getBaseURL()}/insert-${before ? 'before' : 'after'}`,
|
|
92
|
+
data: {
|
|
93
|
+
valueToInsert,
|
|
94
|
+
anchorValue,
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
deleteValue(value, count) {
|
|
100
|
+
if (!value || typeof value !== 'string') {
|
|
101
|
+
throw new Error('Value must be provided and must be a string.')
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (count !== undefined && (isNaN(count) || typeof count !== 'number')) {
|
|
105
|
+
throw new Error('Count must be a number.')
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return this.app.request
|
|
109
|
+
.put({
|
|
110
|
+
url : `${this.getBaseURL()}/delete-value`,
|
|
111
|
+
data: {
|
|
112
|
+
value,
|
|
113
|
+
count
|
|
114
|
+
},
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
addFirst(value) {
|
|
119
|
+
if (!value || !(typeof value === 'string' || Array.isArray(value))) {
|
|
120
|
+
throw new Error('Value(s) must be provided and must be a string or list of strings.')
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return this.app.request
|
|
124
|
+
.put({
|
|
125
|
+
url : `${this.getBaseURL()}/add-first`,
|
|
126
|
+
data: Utils.castArray(value)
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
addLast(value) {
|
|
131
|
+
if (!value || !(typeof value === 'string' || Array.isArray(value))) {
|
|
132
|
+
throw new Error('Value(s) must be provided and must be a string or list of strings.')
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return this.app.request
|
|
136
|
+
.put({
|
|
137
|
+
url : `${this.getBaseURL()}/add-last`,
|
|
138
|
+
data: Utils.castArray(value)
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
deleteFirst(count) {
|
|
143
|
+
if (count !== undefined && (isNaN(count) || typeof count !== 'number')) {
|
|
144
|
+
throw new Error('Count must be a number.')
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return this.app.request
|
|
148
|
+
.put({
|
|
149
|
+
url : `${this.getBaseURL()}/get-first-and-delete`,
|
|
150
|
+
query: { count },
|
|
151
|
+
})
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
deleteLast(count) {
|
|
155
|
+
if (count !== undefined && (isNaN(count) || typeof count !== 'number')) {
|
|
156
|
+
throw new Error('Count must be a number.')
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return this.app.request
|
|
160
|
+
.put({
|
|
161
|
+
url : `${this.getBaseURL()}/get-last-and-delete`,
|
|
162
|
+
query: { count },
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { HiveTypes } from '../constants'
|
|
2
|
+
import { HiveStore } from './base-store'
|
|
3
|
+
import Utils from '../../utils'
|
|
4
|
+
|
|
5
|
+
export class MapStore extends HiveStore {
|
|
6
|
+
|
|
7
|
+
static TYPE = HiveTypes.MAP
|
|
8
|
+
|
|
9
|
+
get(keys) {
|
|
10
|
+
if (keys !== undefined && !(typeof keys === 'string' || Array.isArray(keys))) {
|
|
11
|
+
throw new Error('Key(s) must be a string or list of strings.')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return this.app.request
|
|
15
|
+
.post({
|
|
16
|
+
url : this.getBaseURL(),
|
|
17
|
+
data: Utils.castArray(keys)
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getValue(key) {
|
|
22
|
+
if (!key || typeof key !== 'string') {
|
|
23
|
+
throw new Error('Key must be provided and must be a string.')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return this.app.request
|
|
27
|
+
.get({
|
|
28
|
+
url: `${this.getBaseURL()}/get/${key}`,
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
keyExists(key) {
|
|
33
|
+
if (!key || typeof key !== 'string') {
|
|
34
|
+
throw new Error('Key must be provided and must be a string.')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return this.app.request
|
|
38
|
+
.get({
|
|
39
|
+
url: `${this.getBaseURL()}/exists/${key}`,
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
length() {
|
|
44
|
+
return this.app.request
|
|
45
|
+
.get({
|
|
46
|
+
url: `${this.getBaseURL()}/length`,
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
keys() {
|
|
51
|
+
return this.app.request
|
|
52
|
+
.get({
|
|
53
|
+
url: `${this.getBaseURL()}/keys`,
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
values() {
|
|
58
|
+
return this.app.request
|
|
59
|
+
.get({
|
|
60
|
+
url: `${this.getBaseURL()}/values`,
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
set(key, value) {
|
|
65
|
+
if (!key) {
|
|
66
|
+
throw new Error('First argument must be provided and must be a string or an object.')
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (Utils.isObject(key)) {
|
|
70
|
+
if (!Object.keys(key).length) {
|
|
71
|
+
throw new Error('Provided object must have at least 1 key.')
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return this.app.request
|
|
75
|
+
.put({
|
|
76
|
+
url : this.getBaseURL(),
|
|
77
|
+
data: key,
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (typeof key !== 'string') {
|
|
82
|
+
throw new Error('Key must be a string.')
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!value || typeof value !== 'string') {
|
|
86
|
+
throw new Error('Value must be provided and must be a string.')
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return this.app.request
|
|
90
|
+
.put({
|
|
91
|
+
url : `${this.getBaseURL()}/set/${key}`,
|
|
92
|
+
data: {
|
|
93
|
+
value,
|
|
94
|
+
},
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
setWithOverwrite(key, value, overwrite) {
|
|
99
|
+
if (!key || typeof key !== 'string') {
|
|
100
|
+
throw new Error('Key must be provided and must be a string.')
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!value || typeof value !== 'string') {
|
|
104
|
+
throw new Error('Value must be provided and must be a string.')
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (overwrite !== undefined && typeof overwrite !== 'boolean') {
|
|
108
|
+
throw new Error('Overwrite must be a boolean.')
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return this.app.request
|
|
112
|
+
.put({
|
|
113
|
+
url : `${this.getBaseURL()}/set-with-overwrite/${key}`,
|
|
114
|
+
data: {
|
|
115
|
+
value,
|
|
116
|
+
overwrite
|
|
117
|
+
},
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
add(data) {
|
|
122
|
+
if (!Utils.isObject(data)) {
|
|
123
|
+
throw new Error('Payload must be an object.')
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (!Object.keys(data).length) {
|
|
127
|
+
throw new Error('Provided object must have at least 1 key.')
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return this.app.request
|
|
131
|
+
.put({
|
|
132
|
+
url: `${this.getBaseURL()}/add`,
|
|
133
|
+
data,
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
increment(key, count) {
|
|
138
|
+
if (!key || typeof key !== 'string') {
|
|
139
|
+
throw new Error('Key must be provided and must be a string.')
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (count !== undefined && (isNaN(count) || typeof count !== 'number')) {
|
|
143
|
+
throw new Error('Count must be a number.')
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return this.app.request
|
|
147
|
+
.put({
|
|
148
|
+
url : `${this.getBaseURL()}/increment/${key}`,
|
|
149
|
+
query: { count }
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
decrement(key, count) {
|
|
154
|
+
if (!key || typeof key !== 'string') {
|
|
155
|
+
throw new Error('Key must be provided and must be a string.')
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (count !== undefined && (isNaN(count) || typeof count !== 'number')) {
|
|
159
|
+
throw new Error('Count must be a number.')
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return this.app.request
|
|
163
|
+
.put({
|
|
164
|
+
url : `${this.getBaseURL()}/decrement/${key}`,
|
|
165
|
+
query: { count }
|
|
166
|
+
})
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
deleteKeys(keys) {
|
|
170
|
+
if (!keys || !(typeof keys === 'string' || Array.isArray(keys))) {
|
|
171
|
+
throw new Error('Key(s) must be provided and must be a string or list of strings.')
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return this.app.request
|
|
175
|
+
.delete({
|
|
176
|
+
url : `${this.getBaseURL()}/by-obj-keys`,
|
|
177
|
+
data: Utils.castArray(keys)
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
}
|