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,175 +1,173 @@
1
- "use strict";
2
- /**
3
- * 2012 Max 'Azul' Wiehle
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 http_1 = __importDefault(require("http"));
24
- const nano_1 = __importDefault(require("nano"));
25
- const Database = class Couch_db extends AbstractDatabase_1.default {
26
- agent;
27
- db;
28
- constructor(settings) {
29
- super();
30
- this.agent = null;
31
- this.db = null;
32
- this.settings = settings;
33
- // force some settings
34
- // used by CacheAndBufferLayer.js
35
- this.settings.cache = 1000;
36
- this.settings.writeInterval = 100;
37
- this.settings.json = false;
38
- }
39
- get isAsync() { return true; }
40
- async init() {
41
- this.agent = new http_1.default.Agent({
42
- keepAlive: true,
43
- maxSockets: this.settings.maxListeners || 1,
44
- });
45
- const coudhDBSettings = {
46
- url: `http://${this.settings.host}:${this.settings.port}`,
47
- requestDefaults: {
48
- agent: this.agent,
49
- },
50
- };
51
- if (this.settings.user && this.settings.password) {
52
- coudhDBSettings.requestDefaults.auth = {
53
- username: this.settings.user,
54
- password: this.settings.password,
55
- };
56
- }
57
- const client = (0, nano_1.default)(coudhDBSettings);
58
- try {
59
- await client.db.get(this.settings.database);
60
- }
61
- catch (err) {
62
- if (err.statusCode !== 404)
63
- throw err;
64
- await client.db.create(this.settings.database);
65
- }
66
- this.db = client.use(this.settings.database);
67
- }
68
- async get(key) {
69
- let doc;
70
- try {
71
- if (this.db) {
72
- doc = await this.db.get(key);
73
- }
74
- }
75
- catch (err) {
76
- if (err.statusCode === 404)
77
- return null;
78
- throw err;
79
- }
80
- if (doc && 'value' in doc) {
81
- return doc.value;
82
- }
83
- return '';
84
- }
85
- async findKeys(key, notKey) {
86
- const pfxLen = key.indexOf('*');
87
- if (!this.db) {
88
- return;
89
- }
90
- const pfx = pfxLen < 0 ? key : key.slice(0, pfxLen);
91
- const results = await this.db.find({
92
- selector: {
93
- _id: pfxLen < 0 ? pfx : {
94
- $gte: pfx,
95
- // https://docs.couchdb.org/en/3.2.2/ddocs/views/collation.html#string-ranges
96
- $lte: `${pfx}\ufff0`,
97
- $regex: this.createFindRegex(key, notKey).source,
98
- },
99
- },
100
- fields: ['_id'],
101
- });
102
- return results.docs.map((doc) => doc._id);
103
- }
104
- async set(key, value) {
105
- let doc;
106
- if (!this.db) {
107
- return;
108
- }
109
- try {
110
- doc = await this.db.get(key);
111
- }
112
- catch (err) {
113
- if (err.statusCode !== 404)
114
- throw err;
115
- }
116
- await this.db.insert({
117
- _id: key,
118
- // @ts-ignore
119
- value,
120
- ...doc == null ? {} : {
121
- _rev: doc._rev,
122
- },
123
- });
124
- }
125
- async remove(key) {
126
- let header;
127
- if (!this.db) {
128
- return;
129
- }
130
- try {
131
- header = await this.db.head(key);
132
- }
133
- catch (err) {
134
- if (err.statusCode === 404)
135
- return;
136
- throw err;
137
- }
138
- // etag has additional quotation marks, remove them
139
- const etag = JSON.parse(header.etag);
140
- await this.db.destroy(key, etag);
141
- }
142
- async doBulk(bulk) {
143
- if (!this.db) {
144
- return;
145
- }
146
- const keys = bulk.map((op) => op.key);
147
- const revs = {};
148
- // @ts-ignore
149
- for (const { key, value } of (await this.db.fetchRevs({ keys })).rows) {
150
- // couchDB will return error instead of value if key does not exist
151
- if (value != null)
152
- revs[key] = value.rev;
153
- }
154
- const setters = [];
155
- for (const item of bulk) {
156
- const set = { _id: item.key, _rev: undefined,
157
- _deleted: false, value: '' };
158
- if (revs[item.key] != null)
159
- set._rev = revs[item.key];
160
- if (item.type === 'set')
161
- set.value = item.value;
162
- if (item.type === 'remove')
163
- set._deleted = true;
164
- setters.push(set);
165
- }
166
- await this.db.bulk({ docs: setters });
167
- }
168
- async close() {
169
- this.db = null;
170
- if (this.agent)
171
- this.agent.destroy();
172
- this.agent = null;
173
- }
1
+ 'use strict';
2
+
3
+ var AbstractDatabase = require('../lib/AbstractDatabase.js');
4
+ var http = require('http');
5
+ var nano = require('nano');
6
+
7
+ /**
8
+ * 2012 Max 'Azul' Wiehle
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 Couch_db extends AbstractDatabase {
23
+ agent;
24
+ db;
25
+ constructor(settings) {
26
+ super();
27
+ this.agent = null;
28
+ this.db = null;
29
+ this.settings = settings;
30
+ // force some settings
31
+ // used by CacheAndBufferLayer.js
32
+ this.settings.cache = 1000;
33
+ this.settings.writeInterval = 100;
34
+ this.settings.json = false;
35
+ }
36
+ get isAsync() { return true; }
37
+ async init() {
38
+ this.agent = new http.Agent({
39
+ keepAlive: true,
40
+ maxSockets: this.settings.maxListeners || 1,
41
+ });
42
+ const coudhDBSettings = {
43
+ url: `http://${this.settings.host}:${this.settings.port}`,
44
+ requestDefaults: {
45
+ agent: this.agent,
46
+ },
47
+ };
48
+ if (this.settings.user && this.settings.password) {
49
+ coudhDBSettings.requestDefaults.auth = {
50
+ username: this.settings.user,
51
+ password: this.settings.password,
52
+ };
53
+ }
54
+ const client = nano(coudhDBSettings);
55
+ try {
56
+ await client.db.get(this.settings.database);
57
+ }
58
+ catch (err) {
59
+ if (err.statusCode !== 404)
60
+ throw err;
61
+ await client.db.create(this.settings.database);
62
+ }
63
+ this.db = client.use(this.settings.database);
64
+ }
65
+ async get(key) {
66
+ let doc;
67
+ try {
68
+ if (this.db) {
69
+ doc = await this.db.get(key);
70
+ }
71
+ }
72
+ catch (err) {
73
+ if (err.statusCode === 404)
74
+ return null;
75
+ throw err;
76
+ }
77
+ if (doc && 'value' in doc) {
78
+ return doc.value;
79
+ }
80
+ return '';
81
+ }
82
+ async findKeys(key, notKey) {
83
+ const pfxLen = key.indexOf('*');
84
+ if (!this.db) {
85
+ return;
86
+ }
87
+ const pfx = pfxLen < 0 ? key : key.slice(0, pfxLen);
88
+ const results = await this.db.find({
89
+ selector: {
90
+ _id: pfxLen < 0 ? pfx : {
91
+ $gte: pfx,
92
+ // https://docs.couchdb.org/en/3.2.2/ddocs/views/collation.html#string-ranges
93
+ $lte: `${pfx}\ufff0`,
94
+ $regex: this.createFindRegex(key, notKey).source,
95
+ },
96
+ },
97
+ fields: ['_id'],
98
+ });
99
+ return results.docs.map((doc) => doc._id);
100
+ }
101
+ async set(key, value) {
102
+ let doc;
103
+ if (!this.db) {
104
+ return;
105
+ }
106
+ try {
107
+ doc = await this.db.get(key);
108
+ }
109
+ catch (err) {
110
+ if (err.statusCode !== 404)
111
+ throw err;
112
+ }
113
+ await this.db.insert({
114
+ _id: key,
115
+ // @ts-ignore
116
+ value,
117
+ ...doc == null ? {} : {
118
+ _rev: doc._rev,
119
+ },
120
+ });
121
+ }
122
+ async remove(key) {
123
+ let header;
124
+ if (!this.db) {
125
+ return;
126
+ }
127
+ try {
128
+ header = await this.db.head(key);
129
+ }
130
+ catch (err) {
131
+ if (err.statusCode === 404)
132
+ return;
133
+ throw err;
134
+ }
135
+ // etag has additional quotation marks, remove them
136
+ const etag = JSON.parse(header.etag);
137
+ await this.db.destroy(key, etag);
138
+ }
139
+ async doBulk(bulk) {
140
+ if (!this.db) {
141
+ return;
142
+ }
143
+ const keys = bulk.map((op) => op.key);
144
+ const revs = {};
145
+ // @ts-ignore
146
+ for (const { key, value } of (await this.db.fetchRevs({ keys })).rows) {
147
+ // couchDB will return error instead of value if key does not exist
148
+ if (value != null)
149
+ revs[key] = value.rev;
150
+ }
151
+ const setters = [];
152
+ for (const item of bulk) {
153
+ const set = { _id: item.key, _rev: undefined,
154
+ _deleted: false, value: '' };
155
+ if (revs[item.key] != null)
156
+ set._rev = revs[item.key];
157
+ if (item.type === 'set')
158
+ set.value = item.value;
159
+ if (item.type === 'remove')
160
+ set._deleted = true;
161
+ setters.push(set);
162
+ }
163
+ await this.db.bulk({ docs: setters });
164
+ }
165
+ async close() {
166
+ this.db = null;
167
+ if (this.agent)
168
+ this.agent.destroy();
169
+ this.agent = null;
170
+ }
174
171
  };
172
+
175
173
  exports.Database = Database;
@@ -1,78 +1,75 @@
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
- /*
23
- *
24
- * Fair warning that length may not provide the correct value upon load.
25
- * See https://github.com/ether/etherpad-lite/pull/3984
26
- *
27
- */
28
- const AbstractDatabase_1 = __importDefault(require("../lib/AbstractDatabase"));
29
- // @ts-ignore
30
- const dirty_1 = __importDefault(require("dirty"));
31
- const Database = class extends AbstractDatabase_1.default {
32
- db;
33
- constructor(settings) {
34
- super();
35
- this.db = null;
36
- if (!settings || !settings.filename) {
37
- // @ts-ignore
38
- settings = { filename: null };
39
- }
40
- this.settings = settings;
41
- // set default settings
42
- this.settings.cache = 0;
43
- this.settings.writeInterval = 0;
44
- this.settings.json = false;
45
- }
46
- init(callback) {
47
- this.db = new dirty_1.default(this.settings.filename);
48
- this.db.on('load', (err) => {
49
- callback();
50
- });
51
- }
52
- get(key, callback) {
53
- callback(null, this.db.get(key));
54
- }
55
- findKeys(key, notKey, callback) {
56
- const keys = [];
57
- const regex = this.createFindRegex(key, notKey);
58
- this.db.forEach((key, val) => {
59
- if (key.search(regex) !== -1) {
60
- keys.push(key);
61
- }
62
- });
63
- callback(null, keys);
64
- }
65
- set(key, value, callback) {
66
- this.db.set(key, value, callback);
67
- }
68
- remove(key, callback) {
69
- this.db.rm(key, callback);
70
- }
71
- close(callback) {
72
- this.db.close();
73
- this.db = null;
74
- if (callback)
75
- callback();
76
- }
1
+ 'use strict';
2
+
3
+ var AbstractDatabase = require('../lib/AbstractDatabase.js');
4
+ var Dirty = require('dirty');
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
+ /*
22
+ *
23
+ * Fair warning that length may not provide the correct value upon load.
24
+ * See https://github.com/ether/etherpad-lite/pull/3984
25
+ *
26
+ */
27
+ const Database = class extends AbstractDatabase {
28
+ db;
29
+ constructor(settings) {
30
+ super();
31
+ this.db = null;
32
+ if (!settings || !settings.filename) {
33
+ // @ts-ignore
34
+ settings = { filename: null };
35
+ }
36
+ this.settings = settings;
37
+ // set default settings
38
+ this.settings.cache = 0;
39
+ this.settings.writeInterval = 0;
40
+ this.settings.json = false;
41
+ }
42
+ init(callback) {
43
+ this.db = new Dirty(this.settings.filename);
44
+ this.db.on('load', (err) => {
45
+ callback();
46
+ });
47
+ }
48
+ get(key, callback) {
49
+ callback(null, this.db.get(key));
50
+ }
51
+ findKeys(key, notKey, callback) {
52
+ const keys = [];
53
+ const regex = this.createFindRegex(key, notKey);
54
+ this.db.forEach((key, val) => {
55
+ if (key.search(regex) !== -1) {
56
+ keys.push(key);
57
+ }
58
+ });
59
+ callback(null, keys);
60
+ }
61
+ set(key, value, callback) {
62
+ this.db.set(key, value, callback);
63
+ }
64
+ remove(key, callback) {
65
+ this.db.rm(key, callback);
66
+ }
67
+ close(callback) {
68
+ this.db.close();
69
+ this.db = null;
70
+ if (callback)
71
+ callback();
72
+ }
77
73
  };
74
+
78
75
  exports.Database = Database;
@@ -1,77 +1,59 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Database = void 0;
7
- const AbstractDatabase_1 = __importDefault(require("../lib/AbstractDatabase"));
8
- /**
9
- * 2011 Peter 'Pita' Martischka
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS-IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License.
22
- */
23
- // @ts-ignore
24
- const dirty_1 = require("dirty");
25
- const Database = class extends AbstractDatabase_1.default {
26
- db;
27
- constructor(settings) {
28
- super();
29
- // @ts-ignore
30
- this.db = null;
31
- if (!settings || !settings.filename) {
32
- settings = {};
33
- }
34
- this.settings = settings;
35
- // set default settings
36
- this.settings.cache = 0;
37
- this.settings.writeInterval = 0;
38
- this.settings.json = false;
39
- }
40
- init(callback) {
41
- this.db = new dirty_1.Dirty(this.settings.filename);
42
- this.db.on('load', (err) => {
43
- callback();
44
- });
45
- }
46
- get(key, callback) {
47
- callback(null, this.db.get(key));
48
- }
49
- findKeys(key, notKey, callback) {
50
- const keys = [];
51
- const regex = this.createFindRegex(key, notKey);
52
- this.db.forEach((key, val) => {
53
- if (key.search(regex) !== -1) {
54
- keys.push(key);
55
- }
56
- });
57
- callback(null, keys);
58
- }
59
- set(key, value, callback) {
60
- this.db.set(key, value, callback);
61
- const databasePath = require('path').dirname(this.settings.filename);
62
- require('simple-git')(databasePath)
63
- .silent(true)
64
- .add('./*.db')
65
- .commit('Automated commit...')
66
- .push(['-u', 'origin', 'master'], () => console.debug('Stored git commit'));
67
- }
68
- remove(key, callback) {
69
- this.db.rm(key, callback);
70
- }
71
- close(callback) {
72
- this.db.close();
73
- if (callback)
74
- callback();
75
- }
1
+ 'use strict';
2
+
3
+ var AbstractDatabase = require('../lib/AbstractDatabase.js');
4
+ var Dirty = require('dirty');
5
+
6
+ const Database = class extends AbstractDatabase {
7
+ db;
8
+ constructor(settings) {
9
+ super();
10
+ // @ts-ignore
11
+ this.db = null;
12
+ if (!settings || !settings.filename) {
13
+ settings = {};
14
+ }
15
+ this.settings = settings;
16
+ // set default settings
17
+ this.settings.cache = 0;
18
+ this.settings.writeInterval = 0;
19
+ this.settings.json = false;
20
+ }
21
+ init(callback) {
22
+ this.db = new Dirty.Dirty(this.settings.filename);
23
+ this.db.on('load', (err) => {
24
+ callback();
25
+ });
26
+ }
27
+ get(key, callback) {
28
+ callback(null, this.db.get(key));
29
+ }
30
+ findKeys(key, notKey, callback) {
31
+ const keys = [];
32
+ const regex = this.createFindRegex(key, notKey);
33
+ this.db.forEach((key, val) => {
34
+ if (key.search(regex) !== -1) {
35
+ keys.push(key);
36
+ }
37
+ });
38
+ callback(null, keys);
39
+ }
40
+ set(key, value, callback) {
41
+ this.db.set(key, value, callback);
42
+ const databasePath = require('path').dirname(this.settings.filename);
43
+ require('simple-git')(databasePath)
44
+ .silent(true)
45
+ .add('./*.db')
46
+ .commit('Automated commit...')
47
+ .push(['-u', 'origin', 'master'], () => console.debug('Stored git commit'));
48
+ }
49
+ remove(key, callback) {
50
+ this.db.rm(key, callback);
51
+ }
52
+ close(callback) {
53
+ this.db.close();
54
+ if (callback)
55
+ callback();
56
+ }
76
57
  };
58
+
77
59
  exports.Database = Database;