ueberdb2 4.1.8 → 4.1.10

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.
Files changed (37) hide show
  1. package/dist/databases/cassandra_db.js +233 -235
  2. package/dist/databases/couch_db.js +171 -173
  3. package/dist/databases/dirty_db.js +73 -76
  4. package/dist/databases/dirty_git_db.js +57 -75
  5. package/dist/databases/elasticsearch_db.js +241 -267
  6. package/dist/databases/memory_db.js +35 -37
  7. package/dist/databases/mock_db.js +36 -38
  8. package/dist/databases/mongodb_db.js +131 -133
  9. package/dist/databases/mssql_db.js +183 -185
  10. package/dist/databases/mysql_db.js +166 -168
  11. package/dist/databases/postgres_db.js +188 -190
  12. package/dist/databases/postgrespool_db.js +10 -10
  13. package/dist/databases/redis_db.js +118 -120
  14. package/dist/databases/rethink_db.js +119 -121
  15. package/dist/databases/sqlite_db.js +135 -137
  16. package/dist/index.js +195 -213
  17. package/lib/AbstractDatabase.ts +79 -0
  18. package/lib/CacheAndBufferLayer.ts +665 -0
  19. package/lib/logging.ts +32 -0
  20. package/package.json +16 -12
  21. package/dist/lib/AbstractDatabase.js +0 -38
  22. package/dist/lib/CacheAndBufferLayer.js +0 -657
  23. package/dist/lib/logging.js +0 -34
  24. package/dist/test/lib/databases.js +0 -74
  25. package/dist/test/test.js +0 -327
  26. package/dist/test/test_bulk.js +0 -74
  27. package/dist/test/test_elasticsearch.js +0 -157
  28. package/dist/test/test_findKeys.js +0 -69
  29. package/dist/test/test_flush.js +0 -83
  30. package/dist/test/test_getSub.js +0 -57
  31. package/dist/test/test_lru.js +0 -155
  32. package/dist/test/test_memory.js +0 -59
  33. package/dist/test/test_metrics.js +0 -772
  34. package/dist/test/test_mysql.js +0 -90
  35. package/dist/test/test_postgres.js +0 -40
  36. package/dist/test/test_setSub.js +0 -48
  37. package/dist/test/test_tojson.js +0 -62
@@ -1,122 +1,120 @@
1
- "use strict";
2
- /**
3
- * 2011 Peter 'Pita' Martischka
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS-IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.Database = void 0;
22
- const AbstractDatabase_1 = __importDefault(require("../lib/AbstractDatabase"));
23
- const redis_1 = require("redis");
24
- const Database = class RedisDB extends AbstractDatabase_1.default {
25
- _client;
26
- constructor(settings) {
27
- super();
28
- this._client = null;
29
- this.settings = settings || {};
30
- }
31
- get isAsync() { return true; }
32
- async init() {
33
- if (this.settings.url) {
34
- this._client = (0, redis_1.createClient)({ url: this.settings.url });
35
- }
36
- else if (this.settings.host) {
37
- const options = {
38
- socket: {
39
- host: this.settings.host,
40
- port: Number(this.settings.port),
41
- }
42
- };
43
- if (this.settings.password) {
44
- options.password = this.settings.password;
45
- }
46
- if (this.settings.user) {
47
- options.username = this.settings.user;
48
- }
49
- this._client = (0, redis_1.createClient)(options);
50
- }
51
- if (this._client) {
52
- await this._client.connect();
53
- await this._client.ping();
54
- }
55
- }
56
- async get(key) {
57
- if (this._client == null)
58
- return null;
59
- return await this._client.get(key);
60
- }
61
- async findKeys(key, notKey) {
62
- if (this._client == null)
63
- return null;
64
- const [type] = /^([^:*]+):\*$/.exec(key) || [];
65
- if (type != null && ['*:*:*', `${key}:*`].includes(notKey)) {
66
- // Performance optimization for a common Etherpad case.
67
- return await this._client.sMembers(`ueberDB:keys:${type}`);
68
- }
69
- let keys = await this._client.keys(key.replace(/[?[\]\\]/g, '\\$&'));
70
- if (notKey != null) {
71
- const regex = this.createFindRegex(key, notKey);
72
- keys = keys.filter((k) => regex.test(k));
73
- }
74
- return keys;
75
- }
76
- async set(key, value) {
77
- if (this._client == null)
78
- return null;
79
- const matches = /^([^:]+):([^:]+)$/.exec(key);
80
- await Promise.all([
81
- matches && this._client.sAdd(`ueberDB:keys:${matches[1]}`, matches[0]),
82
- this._client.set(key, value),
83
- ]);
84
- }
85
- async remove(key) {
86
- if (this._client == null)
87
- return null;
88
- const matches = /^([^:]+):([^:]+)$/.exec(key);
89
- await Promise.all([
90
- matches && this._client.sRem(`ueberDB:keys:${matches[1]}`, matches[0]),
91
- this._client.del(key),
92
- ]);
93
- }
94
- async doBulk(bulk) {
95
- if (this._client == null)
96
- return null;
97
- const multi = this._client.multi();
98
- for (const { key, type, value } of bulk) {
99
- const matches = /^([^:]+):([^:]+)$/.exec(key);
100
- if (type === 'set') {
101
- if (matches) {
102
- multi.sAdd(`ueberDB:keys:${matches[1]}`, matches[0]);
103
- }
104
- multi.set(key, value);
105
- }
106
- else if (type === 'remove') {
107
- if (matches) {
108
- multi.sRem(`ueberDB:keys:${matches[1]}`, matches[0]);
109
- }
110
- multi.del(key);
111
- }
112
- }
113
- await multi.exec();
114
- }
115
- async close() {
116
- if (this._client == null)
117
- return null;
118
- await this._client.quit();
119
- this._client = null;
120
- }
1
+ 'use strict';
2
+
3
+ var AbstractDatabase = require('../lib/AbstractDatabase.js');
4
+ var redis = require('redis');
5
+
6
+ /**
7
+ * 2011 Peter 'Pita' Martischka
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS-IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+ const Database = class RedisDB extends AbstractDatabase {
22
+ _client;
23
+ constructor(settings) {
24
+ super();
25
+ this._client = null;
26
+ this.settings = settings || {};
27
+ }
28
+ get isAsync() { return true; }
29
+ async init() {
30
+ if (this.settings.url) {
31
+ this._client = redis.createClient({ url: this.settings.url });
32
+ }
33
+ else if (this.settings.host) {
34
+ const options = {
35
+ socket: {
36
+ host: this.settings.host,
37
+ port: Number(this.settings.port),
38
+ }
39
+ };
40
+ if (this.settings.password) {
41
+ options.password = this.settings.password;
42
+ }
43
+ if (this.settings.user) {
44
+ options.username = this.settings.user;
45
+ }
46
+ this._client = redis.createClient(options);
47
+ }
48
+ if (this._client) {
49
+ await this._client.connect();
50
+ await this._client.ping();
51
+ }
52
+ }
53
+ async get(key) {
54
+ if (this._client == null)
55
+ return null;
56
+ return await this._client.get(key);
57
+ }
58
+ async findKeys(key, notKey) {
59
+ if (this._client == null)
60
+ return null;
61
+ const [type] = /^([^:*]+):\*$/.exec(key) || [];
62
+ if (type != null && ['*:*:*', `${key}:*`].includes(notKey)) {
63
+ // Performance optimization for a common Etherpad case.
64
+ return await this._client.sMembers(`ueberDB:keys:${type}`);
65
+ }
66
+ let keys = await this._client.keys(key.replace(/[?[\]\\]/g, '\\$&'));
67
+ if (notKey != null) {
68
+ const regex = this.createFindRegex(key, notKey);
69
+ keys = keys.filter((k) => regex.test(k));
70
+ }
71
+ return keys;
72
+ }
73
+ async set(key, value) {
74
+ if (this._client == null)
75
+ return null;
76
+ const matches = /^([^:]+):([^:]+)$/.exec(key);
77
+ await Promise.all([
78
+ matches && this._client.sAdd(`ueberDB:keys:${matches[1]}`, matches[0]),
79
+ this._client.set(key, value),
80
+ ]);
81
+ }
82
+ async remove(key) {
83
+ if (this._client == null)
84
+ return null;
85
+ const matches = /^([^:]+):([^:]+)$/.exec(key);
86
+ await Promise.all([
87
+ matches && this._client.sRem(`ueberDB:keys:${matches[1]}`, matches[0]),
88
+ this._client.del(key),
89
+ ]);
90
+ }
91
+ async doBulk(bulk) {
92
+ if (this._client == null)
93
+ return null;
94
+ const multi = this._client.multi();
95
+ for (const { key, type, value } of bulk) {
96
+ const matches = /^([^:]+):([^:]+)$/.exec(key);
97
+ if (type === 'set') {
98
+ if (matches) {
99
+ multi.sAdd(`ueberDB:keys:${matches[1]}`, matches[0]);
100
+ }
101
+ multi.set(key, value);
102
+ }
103
+ else if (type === 'remove') {
104
+ if (matches) {
105
+ multi.sRem(`ueberDB:keys:${matches[1]}`, matches[0]);
106
+ }
107
+ multi.del(key);
108
+ }
109
+ }
110
+ await multi.exec();
111
+ }
112
+ async close() {
113
+ if (this._client == null)
114
+ return null;
115
+ await this._client.quit();
116
+ this._client = null;
117
+ }
121
118
  };
119
+
122
120
  exports.Database = Database;
@@ -1,123 +1,121 @@
1
- "use strict";
2
- /**
3
- * 2016 Remi Arnaud
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS-IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.Database = void 0;
22
- const AbstractDatabase_1 = __importDefault(require("../lib/AbstractDatabase"));
23
- const rethinkdb_1 = __importDefault(require("rethinkdb"));
24
- const async_1 = __importDefault(require("async"));
25
- const Database = class extends AbstractDatabase_1.default {
26
- host;
27
- db;
28
- port;
29
- table;
30
- connection;
31
- constructor(settings) {
32
- super();
33
- if (!settings)
34
- settings = {};
35
- if (!settings.host) {
36
- settings.host = 'localhost';
37
- }
38
- if (!settings.port) {
39
- settings.port = 28015;
40
- }
41
- if (!settings.db) {
42
- settings.db = 'test';
43
- }
44
- if (!settings.table) {
45
- settings.table = 'test';
46
- }
47
- this.host = settings.host;
48
- this.db = settings.db;
49
- this.port = settings.port;
50
- this.table = settings.table;
51
- this.connection = null;
52
- }
53
- init(callback) {
54
- // @ts-ignore
55
- rethinkdb_1.default.connect(this, (err, conn) => {
56
- if (err)
57
- throw err;
58
- this.connection = conn;
59
- rethinkdb_1.default.table(this.table).run(this.connection, (err, cursor) => {
60
- if (err) {
61
- // assuming table does not exists
62
- // @ts-ignore
63
- rethinkdb_1.default.tableCreate(this.table).run(this.connection, callback);
64
- }
65
- else if (callback) {
66
- callback(null, cursor);
67
- }
68
- });
69
- });
70
- }
71
- get(key, callback) {
72
- // @ts-ignore
73
- rethinkdb_1.default.table(this.table).get(key).run(this.connection, (err, item) => {
74
- // @ts-ignore
75
- callback(err, (item ? item.content : item));
76
- });
77
- }
78
- findKeys(key, notKey, callback) {
79
- const keys = [];
80
- const regex = this.createFindRegex(key, notKey);
81
- // @ts-ignore
82
- rethinkdb_1.default.filter((item) => {
83
- if (item.id.search(regex) !== -1) {
84
- keys.push(item.id);
85
- }
86
- }).run(this.connection, callback);
87
- }
88
- set(key, value, callback) {
89
- rethinkdb_1.default.table(this.table)
90
- .insert({ id: key, content: value }, { conflict: 'replace' })
91
- .run(this.connection, callback);
92
- }
93
- doBulk(bulk, callback) {
94
- const _in = [];
95
- const _out = [];
96
- for (const i in bulk) {
97
- if (bulk[i].type === 'set') {
98
- _in.push({ id: bulk[i].key, content: bulk[i].value });
99
- }
100
- else if (bulk[i].type === 'remove') {
101
- _out.push(bulk[i].key);
102
- }
103
- }
104
- async_1.default.parallel([
105
- (cb) => {
106
- rethinkdb_1.default.table(this.table).insert(_in, { conflict: 'replace' }).run(this.connection, cb);
107
- },
108
- (cb) => {
109
- rethinkdb_1.default.table(this.table).getAll(_out).delete().run(this.connection, cb);
110
- },
111
- ], callback);
112
- }
113
- remove(key, callback) {
114
- // @ts-ignore
115
- rethinkdb_1.default.table(this.table).get(key).delete().run(this.connection, callback);
116
- }
117
- close(callback) {
118
- if (this.connection) {
119
- this.connection.close(callback);
120
- }
121
- }
1
+ 'use strict';
2
+
3
+ var AbstractDatabase = require('../lib/AbstractDatabase.js');
4
+ var r = require('rethinkdb');
5
+ var async = require('async');
6
+
7
+ /**
8
+ * 2016 Remi Arnaud
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License.
12
+ * You may obtain a copy of the License at
13
+ *
14
+ * http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS-IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+ const Database = class extends AbstractDatabase {
23
+ host;
24
+ db;
25
+ port;
26
+ table;
27
+ connection;
28
+ constructor(settings) {
29
+ super();
30
+ if (!settings)
31
+ settings = {};
32
+ if (!settings.host) {
33
+ settings.host = 'localhost';
34
+ }
35
+ if (!settings.port) {
36
+ settings.port = 28015;
37
+ }
38
+ if (!settings.db) {
39
+ settings.db = 'test';
40
+ }
41
+ if (!settings.table) {
42
+ settings.table = 'test';
43
+ }
44
+ this.host = settings.host;
45
+ this.db = settings.db;
46
+ this.port = settings.port;
47
+ this.table = settings.table;
48
+ this.connection = null;
49
+ }
50
+ init(callback) {
51
+ // @ts-ignore
52
+ r.connect(this, (err, conn) => {
53
+ if (err)
54
+ throw err;
55
+ this.connection = conn;
56
+ r.table(this.table).run(this.connection, (err, cursor) => {
57
+ if (err) {
58
+ // assuming table does not exists
59
+ // @ts-ignore
60
+ r.tableCreate(this.table).run(this.connection, callback);
61
+ }
62
+ else if (callback) {
63
+ callback(null, cursor);
64
+ }
65
+ });
66
+ });
67
+ }
68
+ get(key, callback) {
69
+ // @ts-ignore
70
+ r.table(this.table).get(key).run(this.connection, (err, item) => {
71
+ // @ts-ignore
72
+ callback(err, (item ? item.content : item));
73
+ });
74
+ }
75
+ findKeys(key, notKey, callback) {
76
+ const keys = [];
77
+ const regex = this.createFindRegex(key, notKey);
78
+ // @ts-ignore
79
+ r.filter((item) => {
80
+ if (item.id.search(regex) !== -1) {
81
+ keys.push(item.id);
82
+ }
83
+ }).run(this.connection, callback);
84
+ }
85
+ set(key, value, callback) {
86
+ r.table(this.table)
87
+ .insert({ id: key, content: value }, { conflict: 'replace' })
88
+ .run(this.connection, callback);
89
+ }
90
+ doBulk(bulk, callback) {
91
+ const _in = [];
92
+ const _out = [];
93
+ for (const i in bulk) {
94
+ if (bulk[i].type === 'set') {
95
+ _in.push({ id: bulk[i].key, content: bulk[i].value });
96
+ }
97
+ else if (bulk[i].type === 'remove') {
98
+ _out.push(bulk[i].key);
99
+ }
100
+ }
101
+ async.parallel([
102
+ (cb) => {
103
+ r.table(this.table).insert(_in, { conflict: 'replace' }).run(this.connection, cb);
104
+ },
105
+ (cb) => {
106
+ r.table(this.table).getAll(_out).delete().run(this.connection, cb);
107
+ },
108
+ ], callback);
109
+ }
110
+ remove(key, callback) {
111
+ // @ts-ignore
112
+ r.table(this.table).get(key).delete().run(this.connection, callback);
113
+ }
114
+ close(callback) {
115
+ if (this.connection) {
116
+ this.connection.close(callback);
117
+ }
118
+ }
122
119
  };
120
+
123
121
  exports.Database = Database;