ueberdb2 4.0.11 → 4.0.15
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/.eslintignore +2 -0
- package/.eslintrc.cjs +44 -5
- package/databases/{cassandra_db.js → cassandra_db.ts} +45 -30
- package/databases/{couch_db.js → couch_db.ts} +78 -31
- package/databases/{dirty_db.js → dirty_db.ts} +19 -14
- package/databases/{dirty_git_db.js → dirty_git_db.ts} +19 -15
- package/databases/{elasticsearch_db.js → elasticsearch_db.ts} +30 -21
- package/databases/{memory_db.js → memory_db.ts} +8 -8
- package/databases/mock_db.ts +43 -0
- package/databases/{mongodb_db.js → mongodb_db.ts} +22 -16
- package/databases/{mssql_db.js → mssql_db.ts} +29 -21
- package/databases/{mysql_db.js → mysql_db.ts} +20 -15
- package/databases/{postgres_db.js → postgres_db.ts} +37 -22
- package/databases/{postgrespool_db.js → postgrespool_db.ts} +3 -3
- package/databases/redis_db.ts +129 -0
- package/databases/{rethink_db.js → rethink_db.ts} +35 -19
- package/databases/{sqlite_db.js → sqlite_db.ts} +37 -36
- package/docker-compose.yml +44 -0
- package/{index.js → index.ts} +76 -25
- package/lib/AbstractDatabase.ts +79 -0
- package/lib/{CacheAndBufferLayer.js → CacheAndBufferLayer.ts} +17 -16
- package/lib/{logging.js → logging.ts} +10 -6
- package/package.json +17 -3
- package/test/lib/{databases.js → databases.ts} +8 -5
- package/test/test.ts +328 -0
- package/test/test_bulk.ts +69 -0
- package/test/{test_elasticsearch.js → test_elasticsearch.ts} +48 -53
- package/test/{test_findKeys.js → test_findKeys.ts} +15 -17
- package/test/{test_flush.js → test_flush.ts} +16 -22
- package/test/test_getSub.ts +28 -0
- package/test/test_lru.ts +151 -0
- package/test/test_memory.ts +32 -0
- package/test/{test_metrics.js → test_metrics.ts} +73 -68
- package/test/{test_mysql.js → test_mysql.ts} +16 -22
- package/test/test_postgres.ts +16 -0
- package/test/{test_setSub.js → test_setSub.ts} +8 -12
- package/test/test_tojson.ts +34 -0
- package/databases/mock_db.js +0 -42
- package/databases/redis_db.js +0 -96
- package/lib/AbstractDatabase.js +0 -37
- package/test/test.js +0 -328
- package/test/test_bulk.js +0 -69
- package/test/test_getSub.js +0 -31
- package/test/test_lru.js +0 -145
- package/test/test_memory.js +0 -31
- package/test/test_postgres.js +0 -16
- package/test/test_tojson.js +0 -37
package/.eslintignore
ADDED
package/.eslintrc.cjs
CHANGED
|
@@ -4,22 +4,61 @@
|
|
|
4
4
|
require('eslint-config-etherpad/patch/modern-module-resolution');
|
|
5
5
|
|
|
6
6
|
module.exports = {
|
|
7
|
+
parserOptions: {
|
|
8
|
+
project: ['./tsconfig.json'],
|
|
9
|
+
},
|
|
10
|
+
|
|
7
11
|
root: true,
|
|
8
12
|
extends: 'etherpad/node',
|
|
13
|
+
|
|
14
|
+
rules: {
|
|
15
|
+
'mocha/no-exports': 'off',
|
|
16
|
+
'@typescript-eslint/no-unsafe-call': 'off',
|
|
17
|
+
'max-len': 'off',
|
|
18
|
+
'@typescript-eslint/restrict-template-expressions': 'off',
|
|
19
|
+
'@typescript-eslint/no-unsafe-member-access': 'off',
|
|
20
|
+
'n/no-missing-import': 'off',
|
|
21
|
+
'strict': 'off',
|
|
22
|
+
'@typescript-eslint/no-unsafe-return': 'off',
|
|
23
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
24
|
+
'@typescript-eslint/no-unsafe-argument': 'off',
|
|
25
|
+
'@typescript-eslint/no-unsafe-assignment': 'off',
|
|
26
|
+
'prefer-arrow/prefer-arrow-functions': 'off',
|
|
27
|
+
'@typescript-eslint/await-thenable': 'off',
|
|
28
|
+
'@typescript-eslint/brace-style': 'off',
|
|
29
|
+
'@typescript-eslint/comma-spacing': 'off',
|
|
30
|
+
'@typescript-eslint/consistent-type-assertions': 'off',
|
|
31
|
+
'@typescript-eslint/consistent-type-definitions': 'off',
|
|
32
|
+
'@typescript-eslint/default-param-last': 'off',
|
|
33
|
+
'@typescript-eslint/dot-notation': 'off',
|
|
34
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
35
|
+
'@typescript-eslint/explicit-member-accessibility': 'off',
|
|
36
|
+
'func-call-spacing': 'off',
|
|
37
|
+
'@typescript-eslint/no-floating-promises': 'off',
|
|
38
|
+
'camelcase': 'off',
|
|
39
|
+
'n/no-unpublished-import': 'off',
|
|
40
|
+
'n/no-unpublished-require': 'off',
|
|
41
|
+
'no-unused-vars': 'off',
|
|
42
|
+
'@typescript-eslint/no-unused-vars': 'off',
|
|
43
|
+
'@typescript-eslint/ban-ts-comment': 'off',
|
|
44
|
+
'@typescript-eslint/restrict-plus-operands': 'off',
|
|
45
|
+
},
|
|
9
46
|
overrides: [
|
|
10
47
|
{
|
|
11
48
|
files: [
|
|
12
|
-
'
|
|
49
|
+
'lib/**/*',
|
|
50
|
+
'databases/**/*',
|
|
51
|
+
'tests/**/*',
|
|
13
52
|
],
|
|
14
53
|
extends: 'etherpad/tests/backend',
|
|
15
54
|
overrides: [
|
|
16
55
|
{
|
|
17
56
|
files: [
|
|
18
|
-
'
|
|
57
|
+
'lib/**/*',
|
|
58
|
+
'databases/**/*',
|
|
59
|
+
'tests/**/*',
|
|
19
60
|
],
|
|
20
|
-
|
|
21
|
-
'mocha/no-exports': 'off',
|
|
22
|
-
},
|
|
61
|
+
|
|
23
62
|
},
|
|
24
63
|
],
|
|
25
64
|
},
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
1
|
/**
|
|
3
2
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
3
|
* you may not use this file except in compliance with the License.
|
|
@@ -13,10 +12,24 @@
|
|
|
13
12
|
* limitations under the License.
|
|
14
13
|
*/
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
import AbstractDatabase, {Settings} from '../lib/AbstractDatabase';
|
|
16
|
+
import cassandra, {ArrayOrObject, Client, types, ValueCallback} from 'cassandra-driver';
|
|
17
|
+
import ResultSet = types.ResultSet;
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
|
|
20
|
+
type Result = {
|
|
21
|
+
rows: any[];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type BulkObject = {
|
|
25
|
+
type: string
|
|
26
|
+
key:string
|
|
27
|
+
value?: string
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const Database = class Cassandra_db extends AbstractDatabase {
|
|
31
|
+
private client: Client | undefined;
|
|
32
|
+
private pool: any;
|
|
20
33
|
/**
|
|
21
34
|
* @param {Object} settings The required settings object to initiate the Cassandra database
|
|
22
35
|
* @param {String[]} settings.clientOptions See
|
|
@@ -28,7 +41,7 @@ exports.Database = class extends AbstractDatabase {
|
|
|
28
41
|
* the Cassandra driver. See https://github.com/datastax/nodejs-driver#logging for more
|
|
29
42
|
* information
|
|
30
43
|
*/
|
|
31
|
-
constructor(settings) {
|
|
44
|
+
constructor(settings:Settings) {
|
|
32
45
|
super();
|
|
33
46
|
if (!settings.clientOptions) {
|
|
34
47
|
throw new Error('The Cassandra client options should be defined');
|
|
@@ -36,8 +49,7 @@ exports.Database = class extends AbstractDatabase {
|
|
|
36
49
|
if (!settings.columnFamily) {
|
|
37
50
|
throw new Error('The Cassandra column family should be defined');
|
|
38
51
|
}
|
|
39
|
-
|
|
40
|
-
this.settings = {};
|
|
52
|
+
this.settings = {database: settings.database};
|
|
41
53
|
this.settings.clientOptions = settings.clientOptions;
|
|
42
54
|
this.settings.columnFamily = settings.columnFamily;
|
|
43
55
|
this.settings.logger = settings.logger;
|
|
@@ -50,7 +62,7 @@ exports.Database = class extends AbstractDatabase {
|
|
|
50
62
|
* @param {Function} callback Standard callback method.
|
|
51
63
|
* @param {Error} callback.err An error object (if any.)
|
|
52
64
|
*/
|
|
53
|
-
init(callback) {
|
|
65
|
+
init(callback: (arg: any)=>{}) {
|
|
54
66
|
// Create a client
|
|
55
67
|
this.client = new cassandra.Client(this.settings.clientOptions);
|
|
56
68
|
|
|
@@ -83,7 +95,7 @@ exports.Database = class extends AbstractDatabase {
|
|
|
83
95
|
const cql =
|
|
84
96
|
`CREATE COLUMNFAMILY "${this.settings.columnFamily}" ` +
|
|
85
97
|
'(key text PRIMARY KEY, data text)';
|
|
86
|
-
this.client.execute(cql, callback);
|
|
98
|
+
this.client && this.client.execute(cql, callback);
|
|
87
99
|
}
|
|
88
100
|
});
|
|
89
101
|
}
|
|
@@ -96,9 +108,9 @@ exports.Database = class extends AbstractDatabase {
|
|
|
96
108
|
* @param {Error} callback.err An error object, if any
|
|
97
109
|
* @param {String} callback.value The value for the given key (if any)
|
|
98
110
|
*/
|
|
99
|
-
get(key, callback) {
|
|
111
|
+
get(key:string, callback: (err:Error | null, data?:any)=>{}) {
|
|
100
112
|
const cql = `SELECT data FROM "${this.settings.columnFamily}" WHERE key = ?`;
|
|
101
|
-
this.client.execute(cql, [key], (err, result) => {
|
|
113
|
+
this.client && this.client.execute(cql, [key], (err, result) => {
|
|
102
114
|
if (err) {
|
|
103
115
|
return callback(err);
|
|
104
116
|
}
|
|
@@ -122,12 +134,12 @@ exports.Database = class extends AbstractDatabase {
|
|
|
122
134
|
* @param {Error} callback.err An error object, if any
|
|
123
135
|
* @param {String[]} callback.keys An array of keys that match the specified filters
|
|
124
136
|
*/
|
|
125
|
-
findKeys(key, notKey, callback) {
|
|
137
|
+
findKeys(key:string, notKey:string, callback: Function) {
|
|
126
138
|
let cql = null;
|
|
127
139
|
if (!notKey) {
|
|
128
140
|
// Get all the keys
|
|
129
141
|
cql = `SELECT key FROM "${this.settings.columnFamily}"`;
|
|
130
|
-
this.client.execute(cql, (err, result) => {
|
|
142
|
+
this.client && this.client.execute(cql, (err: Error, result:Result) => {
|
|
131
143
|
if (err) {
|
|
132
144
|
return callback(err);
|
|
133
145
|
}
|
|
@@ -135,7 +147,7 @@ exports.Database = class extends AbstractDatabase {
|
|
|
135
147
|
// Construct a regular expression based on the given key
|
|
136
148
|
const regex = new RegExp(`^${key.replace(/\*/g, '.*')}$`);
|
|
137
149
|
|
|
138
|
-
const keys = [];
|
|
150
|
+
const keys:string[] = [];
|
|
139
151
|
result.rows.forEach((row) => {
|
|
140
152
|
if (regex.test(row.key)) {
|
|
141
153
|
keys.push(row.key);
|
|
@@ -151,18 +163,20 @@ exports.Database = class extends AbstractDatabase {
|
|
|
151
163
|
// Get the 'text' bit out of the key and get all those keys from a special column.
|
|
152
164
|
// We can retrieve them from this column as we're duplicating them on .set/.remove
|
|
153
165
|
cql = `SELECT * from "${this.settings.columnFamily}" WHERE key = ?`;
|
|
154
|
-
this.client
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
166
|
+
this.client &&
|
|
167
|
+
this.client
|
|
168
|
+
.execute(cql, [`ueberdb:keys:${matches[1]}`], (err, result) => {
|
|
169
|
+
if (err) {
|
|
170
|
+
return callback(err);
|
|
171
|
+
}
|
|
158
172
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
173
|
+
if (!result.rows || result.rows.length === 0) {
|
|
174
|
+
return callback(null, []);
|
|
175
|
+
}
|
|
162
176
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
177
|
+
const keys = result.rows.map((row) => row.data);
|
|
178
|
+
return callback(null, keys);
|
|
179
|
+
});
|
|
166
180
|
} else {
|
|
167
181
|
const msg =
|
|
168
182
|
'Cassandra db only supports key patterns like pad:* when notKey is set to *:*:*';
|
|
@@ -181,7 +195,7 @@ exports.Database = class extends AbstractDatabase {
|
|
|
181
195
|
* @param {Function} callback Standard callback method
|
|
182
196
|
* @param {Error} callback.err An error object, if any
|
|
183
197
|
*/
|
|
184
|
-
set(key, value, callback) {
|
|
198
|
+
set(key: string, value:string, callback:()=>{}) {
|
|
185
199
|
this.doBulk([{type: 'set', key, value}], callback);
|
|
186
200
|
}
|
|
187
201
|
|
|
@@ -192,10 +206,11 @@ exports.Database = class extends AbstractDatabase {
|
|
|
192
206
|
* @param {Function} callback Standard callback method
|
|
193
207
|
* @param {Error} callback.err An error object, if any
|
|
194
208
|
*/
|
|
195
|
-
remove(key, callback) {
|
|
209
|
+
remove(key:string, callback: ValueCallback<ResultSet>) {
|
|
196
210
|
this.doBulk([{type: 'remove', key}], callback);
|
|
197
211
|
}
|
|
198
212
|
|
|
213
|
+
|
|
199
214
|
/**
|
|
200
215
|
* Performs multiple operations in one action
|
|
201
216
|
*
|
|
@@ -203,8 +218,8 @@ exports.Database = class extends AbstractDatabase {
|
|
|
203
218
|
* @param {Function} callback Standard callback method
|
|
204
219
|
* @param {Error} callback.err An error object, if any
|
|
205
220
|
*/
|
|
206
|
-
doBulk(bulk, callback) {
|
|
207
|
-
const queries = [];
|
|
221
|
+
doBulk(bulk:BulkObject[], callback:ValueCallback<ResultSet>) {
|
|
222
|
+
const queries:Array<string | {query: string, params?: ArrayOrObject}> = [];
|
|
208
223
|
bulk.forEach((operation) => {
|
|
209
224
|
// We support finding keys of the form `test:*`. If anything matches, we will try and save
|
|
210
225
|
// this
|
|
@@ -235,7 +250,7 @@ exports.Database = class extends AbstractDatabase {
|
|
|
235
250
|
}
|
|
236
251
|
}
|
|
237
252
|
});
|
|
238
|
-
this.client.batch(queries, {prepare: true}, callback);
|
|
253
|
+
this.client && this.client.batch(queries, {prepare: true}, callback);
|
|
239
254
|
}
|
|
240
255
|
|
|
241
256
|
/**
|
|
@@ -244,7 +259,7 @@ exports.Database = class extends AbstractDatabase {
|
|
|
244
259
|
* @param {Function} callback Standard callback method
|
|
245
260
|
* @param {Error} callback.err Error object in case something goes wrong
|
|
246
261
|
*/
|
|
247
|
-
close(callback) {
|
|
262
|
+
close(callback: ()=>{}) {
|
|
248
263
|
this.pool.shutdown(callback);
|
|
249
264
|
}
|
|
250
265
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
1
|
/**
|
|
3
2
|
* 2012 Max 'Azul' Wiehle
|
|
4
3
|
*
|
|
@@ -15,12 +14,25 @@
|
|
|
15
14
|
* limitations under the License.
|
|
16
15
|
*/
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
import AbstractDatabase, {Settings} from '../lib/AbstractDatabase';
|
|
18
|
+
import http, {Agent} from 'http';
|
|
19
|
+
import nano from 'nano';
|
|
20
|
+
import {BulkObject} from './cassandra_db';
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
type CouchDBSettings = {
|
|
23
|
+
url: string,
|
|
24
|
+
requestDefaults: {
|
|
25
|
+
auth?: {
|
|
26
|
+
username: string,
|
|
27
|
+
password: string,
|
|
28
|
+
},
|
|
29
|
+
agent: Agent
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export const Database = class Couch_db extends AbstractDatabase {
|
|
33
|
+
private agent: Agent | null;
|
|
34
|
+
private db: nano.DocumentScope<string> | null;
|
|
35
|
+
constructor(settings: Settings) {
|
|
24
36
|
super();
|
|
25
37
|
this.agent = null;
|
|
26
38
|
this.db = null;
|
|
@@ -40,38 +52,59 @@ exports.Database = class extends AbstractDatabase {
|
|
|
40
52
|
keepAlive: true,
|
|
41
53
|
maxSockets: this.settings.maxListeners || 1,
|
|
42
54
|
});
|
|
43
|
-
|
|
55
|
+
|
|
56
|
+
const coudhDBSettings: CouchDBSettings = {
|
|
44
57
|
url: `http://${this.settings.host}:${this.settings.port}`,
|
|
45
58
|
requestDefaults: {
|
|
46
|
-
|
|
47
|
-
username: this.settings.user,
|
|
48
|
-
password: this.settings.password,
|
|
49
|
-
},
|
|
50
|
-
httpAgent: this.agent,
|
|
59
|
+
agent: this.agent,
|
|
51
60
|
},
|
|
52
|
-
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
if (this.settings.user && this.settings.password) {
|
|
64
|
+
coudhDBSettings.requestDefaults.auth = {
|
|
65
|
+
username: this.settings.user,
|
|
66
|
+
password: this.settings.password,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
const client = nano(coudhDBSettings);
|
|
53
72
|
try {
|
|
54
|
-
|
|
55
|
-
|
|
73
|
+
if (this.settings.database != null) {
|
|
74
|
+
await client.db.get(this.settings.database);
|
|
75
|
+
}
|
|
76
|
+
} catch (err: any) {
|
|
56
77
|
if (err.statusCode !== 404) throw err;
|
|
57
|
-
|
|
78
|
+
if (this.settings.database != null) {
|
|
79
|
+
await client.db.create(this.settings.database);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (this.settings.database != null) {
|
|
83
|
+
this.db = client.use(this.settings.database);
|
|
58
84
|
}
|
|
59
|
-
this.db = client.use(this.settings.database);
|
|
60
85
|
}
|
|
61
86
|
|
|
62
|
-
async get(key) {
|
|
87
|
+
async get(key:string): Promise<null | string> {
|
|
63
88
|
let doc;
|
|
64
89
|
try {
|
|
65
|
-
|
|
66
|
-
|
|
90
|
+
if (this.db) {
|
|
91
|
+
doc = await this.db.get(key);
|
|
92
|
+
}
|
|
93
|
+
} catch (err:any) {
|
|
67
94
|
if (err.statusCode === 404) return null;
|
|
68
95
|
throw err;
|
|
69
96
|
}
|
|
70
|
-
|
|
97
|
+
if (doc && 'value' in doc) {
|
|
98
|
+
return doc.value as string;
|
|
99
|
+
}
|
|
100
|
+
return '';
|
|
71
101
|
}
|
|
72
102
|
|
|
73
|
-
async findKeys(key, notKey) {
|
|
103
|
+
async findKeys(key:string, notKey:string) {
|
|
74
104
|
const pfxLen = key.indexOf('*');
|
|
105
|
+
if (!this.db) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
75
108
|
const pfx = pfxLen < 0 ? key : key.slice(0, pfxLen);
|
|
76
109
|
const results = await this.db.find({
|
|
77
110
|
selector: {
|
|
@@ -87,15 +120,21 @@ exports.Database = class extends AbstractDatabase {
|
|
|
87
120
|
return results.docs.map((doc) => doc._id);
|
|
88
121
|
}
|
|
89
122
|
|
|
90
|
-
async set(key, value) {
|
|
123
|
+
async set(key:string, value:string) {
|
|
91
124
|
let doc;
|
|
125
|
+
|
|
126
|
+
if (!this.db) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
92
130
|
try {
|
|
93
131
|
doc = await this.db.get(key);
|
|
94
|
-
} catch (err) {
|
|
132
|
+
} catch (err:any) {
|
|
95
133
|
if (err.statusCode !== 404) throw err;
|
|
96
134
|
}
|
|
97
135
|
await this.db.insert({
|
|
98
136
|
_id: key,
|
|
137
|
+
// @ts-ignore
|
|
99
138
|
value,
|
|
100
139
|
...doc == null ? {} : {
|
|
101
140
|
_rev: doc._rev,
|
|
@@ -103,11 +142,14 @@ exports.Database = class extends AbstractDatabase {
|
|
|
103
142
|
});
|
|
104
143
|
}
|
|
105
144
|
|
|
106
|
-
async remove(key) {
|
|
145
|
+
async remove(key:string) {
|
|
107
146
|
let header;
|
|
147
|
+
if (!this.db) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
108
150
|
try {
|
|
109
151
|
header = await this.db.head(key);
|
|
110
|
-
} catch (err) {
|
|
152
|
+
} catch (err:any) {
|
|
111
153
|
if (err.statusCode === 404) return;
|
|
112
154
|
throw err;
|
|
113
155
|
}
|
|
@@ -116,22 +158,27 @@ exports.Database = class extends AbstractDatabase {
|
|
|
116
158
|
await this.db.destroy(key, etag);
|
|
117
159
|
}
|
|
118
160
|
|
|
119
|
-
async doBulk(bulk) {
|
|
161
|
+
async doBulk(bulk:BulkObject[]) {
|
|
162
|
+
if (!this.db) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
120
165
|
const keys = bulk.map((op) => op.key);
|
|
121
|
-
const revs = {};
|
|
166
|
+
const revs:{[key:string]:any} = {};
|
|
167
|
+
// @ts-ignore
|
|
122
168
|
for (const {key, value} of (await this.db.fetchRevs({keys})).rows) {
|
|
123
169
|
// couchDB will return error instead of value if key does not exist
|
|
124
170
|
if (value != null) revs[key] = value.rev;
|
|
125
171
|
}
|
|
126
172
|
const setters = [];
|
|
127
173
|
for (const item of bulk) {
|
|
128
|
-
const set = {_id: item.key
|
|
174
|
+
const set = {_id: item.key, _rev: undefined,
|
|
175
|
+
_deleted: false, value: ''};
|
|
129
176
|
if (revs[item.key] != null) set._rev = revs[item.key];
|
|
130
|
-
if (item.type === 'set') set.value = item.value;
|
|
177
|
+
if (item.type === 'set') set.value = item.value as string;
|
|
131
178
|
if (item.type === 'remove') set._deleted = true;
|
|
132
179
|
setters.push(set);
|
|
133
180
|
}
|
|
134
|
-
await this.db.bulk({docs: setters});
|
|
181
|
+
await this.db && await this.db.bulk({docs: setters});
|
|
135
182
|
}
|
|
136
183
|
|
|
137
184
|
async close() {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
1
|
/**
|
|
3
2
|
* 2011 Peter 'Pita' Martischka
|
|
4
3
|
*
|
|
@@ -22,15 +21,21 @@
|
|
|
22
21
|
*
|
|
23
22
|
*/
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
import AbstractDatabase, {Settings} from '../lib/AbstractDatabase';
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
import Dirty from 'dirty';
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
type DirtyDBCallback = (p?:any, keys?: string[])=>{};
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
export const Database = class extends AbstractDatabase {
|
|
32
|
+
private db: any;
|
|
33
|
+
constructor(settings:Settings) {
|
|
30
34
|
super();
|
|
31
35
|
this.db = null;
|
|
32
36
|
|
|
33
37
|
if (!settings || !settings.filename) {
|
|
38
|
+
// @ts-ignore
|
|
34
39
|
settings = {filename: null};
|
|
35
40
|
}
|
|
36
41
|
|
|
@@ -42,21 +47,21 @@ exports.Database = class extends AbstractDatabase {
|
|
|
42
47
|
this.settings.json = false;
|
|
43
48
|
}
|
|
44
49
|
|
|
45
|
-
init(callback) {
|
|
50
|
+
init(callback: ()=>{}) {
|
|
46
51
|
this.db = new Dirty(this.settings.filename);
|
|
47
|
-
this.db.on('load', (err) => {
|
|
52
|
+
this.db.on('load', (err:string) => {
|
|
48
53
|
callback();
|
|
49
54
|
});
|
|
50
55
|
}
|
|
51
56
|
|
|
52
|
-
get(key, callback) {
|
|
57
|
+
get(key:string, callback:DirtyDBCallback) {
|
|
53
58
|
callback(null, this.db.get(key));
|
|
54
59
|
}
|
|
55
60
|
|
|
56
|
-
findKeys(key, notKey, callback) {
|
|
57
|
-
const keys = [];
|
|
61
|
+
findKeys(key:string, notKey:string, callback:DirtyDBCallback) {
|
|
62
|
+
const keys:string[] = [];
|
|
58
63
|
const regex = this.createFindRegex(key, notKey);
|
|
59
|
-
this.db.forEach((key, val) => {
|
|
64
|
+
this.db.forEach((key:string, val:string) => {
|
|
60
65
|
if (key.search(regex) !== -1) {
|
|
61
66
|
keys.push(key);
|
|
62
67
|
}
|
|
@@ -64,15 +69,15 @@ exports.Database = class extends AbstractDatabase {
|
|
|
64
69
|
callback(null, keys);
|
|
65
70
|
}
|
|
66
71
|
|
|
67
|
-
set(key, value, callback) {
|
|
72
|
+
set(key:string, value:string, callback:DirtyDBCallback) {
|
|
68
73
|
this.db.set(key, value, callback);
|
|
69
74
|
}
|
|
70
75
|
|
|
71
|
-
remove(key, callback) {
|
|
76
|
+
remove(key:string, callback:DirtyDBCallback) {
|
|
72
77
|
this.db.rm(key, callback);
|
|
73
78
|
}
|
|
74
79
|
|
|
75
|
-
close(callback) {
|
|
80
|
+
close(callback:DirtyDBCallback) {
|
|
76
81
|
this.db.close();
|
|
77
82
|
this.db = null;
|
|
78
83
|
if (callback) callback();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import AbstractDatabase, {Settings} from '../lib/AbstractDatabase';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* 2011 Peter 'Pita' Martischka
|
|
4
5
|
*
|
|
@@ -15,16 +16,19 @@
|
|
|
15
16
|
* limitations under the License.
|
|
16
17
|
*/
|
|
17
18
|
|
|
18
|
-
const AbstractDatabase = require('../lib/AbstractDatabase');
|
|
19
|
-
const Dirty = require('dirty');
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
import {Dirty} from 'dirty';
|
|
22
|
+
|
|
23
|
+
export const Database = class extends AbstractDatabase {
|
|
24
|
+
private db: any;
|
|
25
|
+
constructor(settings: Settings) {
|
|
23
26
|
super();
|
|
27
|
+
// @ts-ignore
|
|
24
28
|
this.db = null;
|
|
25
29
|
|
|
26
30
|
if (!settings || !settings.filename) {
|
|
27
|
-
settings = {
|
|
31
|
+
settings = {};
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
this.settings = settings;
|
|
@@ -35,21 +39,21 @@ exports.Database = class extends AbstractDatabase {
|
|
|
35
39
|
this.settings.json = false;
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
init(callback) {
|
|
42
|
+
init(callback: ()=>void) {
|
|
39
43
|
this.db = new Dirty(this.settings.filename);
|
|
40
|
-
this.db.on('load', (err) => {
|
|
44
|
+
this.db.on('load', (err: Error) => {
|
|
41
45
|
callback();
|
|
42
46
|
});
|
|
43
47
|
}
|
|
44
48
|
|
|
45
|
-
get(key, callback) {
|
|
49
|
+
get(key:string, callback: (err: string | any, value: string)=>void) {
|
|
46
50
|
callback(null, this.db.get(key));
|
|
47
51
|
}
|
|
48
52
|
|
|
49
|
-
findKeys(key, notKey, callback) {
|
|
50
|
-
const keys = [];
|
|
53
|
+
findKeys(key:string, notKey:string, callback:(v:any, keys:string[])=>{}) {
|
|
54
|
+
const keys:string[] = [];
|
|
51
55
|
const regex = this.createFindRegex(key, notKey);
|
|
52
|
-
this.db.forEach((key, val) => {
|
|
56
|
+
this.db.forEach((key:string, val:string) => {
|
|
53
57
|
if (key.search(regex) !== -1) {
|
|
54
58
|
keys.push(key);
|
|
55
59
|
}
|
|
@@ -57,7 +61,7 @@ exports.Database = class extends AbstractDatabase {
|
|
|
57
61
|
callback(null, keys);
|
|
58
62
|
}
|
|
59
63
|
|
|
60
|
-
set(key, value, callback) {
|
|
64
|
+
set(key:string, value: string, callback: ()=>{}) {
|
|
61
65
|
this.db.set(key, value, callback);
|
|
62
66
|
const databasePath = require('path').dirname(this.settings.filename);
|
|
63
67
|
require('simple-git')(databasePath)
|
|
@@ -67,11 +71,11 @@ exports.Database = class extends AbstractDatabase {
|
|
|
67
71
|
.push(['-u', 'origin', 'master'], () => console.debug('Stored git commit'));
|
|
68
72
|
}
|
|
69
73
|
|
|
70
|
-
remove(key, callback) {
|
|
74
|
+
remove(key:string, callback:()=> {}) {
|
|
71
75
|
this.db.rm(key, callback);
|
|
72
76
|
}
|
|
73
77
|
|
|
74
|
-
close(callback) {
|
|
78
|
+
close(callback: ()=>void) {
|
|
75
79
|
this.db.close();
|
|
76
80
|
if (callback) callback();
|
|
77
81
|
}
|