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
package/dist/index.js CHANGED
@@ -1,215 +1,197 @@
1
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
- /**
8
- * 2011 Peter 'Pita' Martischka
9
- * 2020 John McLear
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 CacheAndBufferLayer_1 = __importDefault(require("./lib/CacheAndBufferLayer"));
25
- const logging_1 = require("./lib/logging");
26
- const util_1 = require("util");
27
- const cbDb = {
28
- init: () => { },
29
- flush: () => { },
30
- get: () => { },
31
- remove: () => { },
32
- findKeys: () => { },
33
- close: () => { },
34
- getSub: () => { },
35
- setSub: () => { },
36
- };
37
- const fns = ['close', 'findKeys', 'flush', 'get', 'getSub', 'init', 'remove', 'set', 'setSub'];
38
- for (const fn of fns) { // @ts-ignore
39
- cbDb[fn] = (0, util_1.callbackify)(CacheAndBufferLayer_1.default.Database.prototype[fn]);
40
- }
41
- const makeDoneCallback = (callback, deprecated) => (err) => {
42
- if (callback)
43
- callback(err);
44
- if (deprecated)
45
- deprecated(err);
46
- if (err != null && callback == null && deprecated == null)
47
- throw err;
48
- };
49
- const Database = class {
50
- type;
51
- dbModule;
52
- dbSettings;
53
- wrapperSettings;
54
- logger;
55
- db;
56
- metrics;
57
- /**
58
- * @param type The type of the database
59
- * @param dbSettings The settings for that specific database type
60
- * @param wrapperSettings
61
- * @param logger Optional logger object. If no logger object is provided no logging will occur.
62
- * The logger object is expected to be a log4js logger object or `console`. A logger object
63
- * from another logging library should also work, but performance may be reduced if the logger
64
- * object does not have is${Level}Enabled() methods (isDebugEnabled(), etc.).
65
- */
66
- constructor(type, dbSettings, wrapperSettings, logger = null) {
67
- if (!type) {
68
- type = 'sqlite';
69
- dbSettings = null;
70
- wrapperSettings = null;
71
- }
72
- // saves all settings and require the db module
73
- this.type = type;
74
- this.dbModule = require(`./databases/${type}_db`);
75
- this.dbSettings = dbSettings;
76
- this.wrapperSettings = wrapperSettings;
77
- this.logger = (0, logging_1.normalizeLogger)(logger);
78
- const db = new this.dbModule.Database(this.dbSettings);
79
- db.logger = this.logger;
80
- this.db = new CacheAndBufferLayer_1.default.Database(db, this.wrapperSettings, this.logger);
81
- // Expose the cache wrapper's metrics to the user. See lib/CacheAndBufferLayer.js for details.
82
- //
83
- // WARNING: This feature is EXPERIMENTAL -- do not assume it will continue to exist in its
84
- // current form in a future version.
85
- this.metrics = this.db.metrics;
86
- }
87
- /**
88
- * @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
89
- */
90
- init(callback = null) {
91
- if (callback != null) {
92
- return cbDb.init.call(this.db);
93
- }
94
- return this.db.init();
95
- }
96
- /**
97
- * Wrapper functions
98
- */
99
- /**
100
- * Deprecated synonym of flush().
101
- *
102
- * @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
103
- */
104
- doShutdown(callback = null) {
105
- return this.flush(callback);
106
- }
107
- /**
108
- * Writes any unsaved changes to the underlying database.
109
- *
110
- * @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
111
- */
112
- flush(callback = null) {
113
- if (!cbDb || !cbDb.flush === undefined)
114
- return null;
115
- if (callback != null) { // @ts-ignore
116
- return cbDb.flush.call(this.db, callback);
117
- }
118
- return this.db.flush();
119
- }
120
- /**
121
- * @param key
122
- * @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
123
- */
124
- get(key, callback = null) {
125
- if (callback != null) { // @ts-ignore
126
- return cbDb.get.call(this.db, key, callback);
127
- }
128
- return this.db.get(key);
129
- }
130
- /**
131
- * @param key
132
- * @param notKey
133
- * @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
134
- */
135
- findKeys(key, notKey, callback = null) {
136
- if (callback != null) { // @ts-ignore
137
- return cbDb.findKeys.call(this.db, key, notKey, callback);
138
- }
139
- return this.db.findKeys(key, notKey);
140
- }
141
- /**
142
- * Removes an entry from the database if present.
143
- *
144
- * @param key
145
- * @param cb Deprecated. Node-style callback. Called when the write has been committed to the
146
- * underlying database driver. If null, a Promise is returned.
147
- * @param deprecated Deprecated callback that is called just after cb. Ignored if cb is null.
148
- */
149
- remove(key, cb = null, deprecated = null) {
150
- if (cb != null) { // @ts-ignore
151
- return cbDb.remove.call(this.db, key, makeDoneCallback(cb, deprecated));
152
- }
153
- return this.db.remove(key);
154
- }
155
- /**
156
- * Adds or changes the value of an entry.
157
- *
158
- * @param key
159
- * @param value
160
- * @param cb Deprecated. Node-style callback. Called when the write has been committed to the
161
- * underlying database driver. If null, a Promise is returned.
162
- * @param deprecated Deprecated callback that is called just after cb. Ignored if cb is null.
163
- */
164
- set(key, value, cb = null, deprecated = null) {
165
- if (cb != null) { // @ts-ignore
166
- return cbDb.get.call(this.db, key, value, makeDoneCallback(cb, deprecated));
167
- }
168
- return this.db.set(key, value);
169
- }
170
- /**
171
- * @param key
172
- * @param sub
173
- * @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
174
- */
175
- getSub(key, sub, callback = null) {
176
- if (callback != null) { // @ts-ignore
177
- return cbDb.getSub.call(this.db, key, sub, callback);
178
- }
179
- return this.db.getSub(key, sub);
180
- }
181
- /**
182
- * Adds or changes a subvalue of an entry.
183
- *
184
- * @param key
185
- * @param sub
186
- * @param value
187
- * @param cb Deprecated. Node-style callback. Called when the write has been committed to the
188
- * underlying database driver. If null, a Promise is returned.
189
- * @param deprecated Deprecated callback that is called just after cb. Ignored if cb is null.
190
- */
191
- setSub(key, sub, value, cb = null, deprecated = null) {
192
- if (cb != null) {
193
- // @ts-ignore
194
- return cbDb.setSub.call(this.db, key, sub, value, makeDoneCallback(cb, deprecated));
195
- }
196
- return this.db.setSub(key, sub, value);
197
- }
198
- /**
199
- * Flushes unwritten changes then closes the connection to the underlying database. After this
200
- * returns, any future call to a method on this object may result in an error.
201
- *
202
- * @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
203
- */
204
- close(callback = null) {
205
- if (callback != null) { // @ts-ignore
206
- return cbDb.close.call(this.db, callback);
207
- }
208
- return this.db.close();
209
- }
210
- };
211
- exports.Database = Database;
212
- /**
213
- * Deprecated synonym of Database.
214
- */
2
+
3
+ var CacheAndBufferLayer = require('./lib/CacheAndBufferLayer.js');
4
+ var logging = require('./lib/logging.js');
5
+ var util = require('util');
6
+
7
+ const cbDb = {
8
+ init: () => { },
9
+ flush: () => { },
10
+ get: () => { },
11
+ remove: () => { },
12
+ findKeys: () => { },
13
+ close: () => { },
14
+ getSub: () => { },
15
+ setSub: () => { },
16
+ };
17
+ const fns = ['close', 'findKeys', 'flush', 'get', 'getSub', 'init', 'remove', 'set', 'setSub'];
18
+ for (const fn of fns) {
19
+ // @ts-ignore
20
+ cbDb[fn] = util.callbackify(CacheAndBufferLayer.Database.prototype[fn]);
21
+ }
22
+ const makeDoneCallback = (callback, deprecated) => (err) => {
23
+ if (callback)
24
+ callback(err);
25
+ if (deprecated)
26
+ deprecated(err);
27
+ if (err != null && callback == null && deprecated == null)
28
+ throw err;
29
+ };
30
+ const Database = class {
31
+ type;
32
+ dbModule;
33
+ dbSettings;
34
+ wrapperSettings;
35
+ logger;
36
+ db;
37
+ metrics;
38
+ /**
39
+ * @param type The type of the database
40
+ * @param dbSettings The settings for that specific database type
41
+ * @param wrapperSettings
42
+ * @param logger Optional logger object. If no logger object is provided no logging will occur.
43
+ * The logger object is expected to be a log4js logger object or `console`. A logger object
44
+ * from another logging library should also work, but performance may be reduced if the logger
45
+ * object does not have is${Level}Enabled() methods (isDebugEnabled(), etc.).
46
+ */
47
+ constructor(type, dbSettings, wrapperSettings, logger = null) {
48
+ if (!type) {
49
+ type = 'sqlite';
50
+ dbSettings = null;
51
+ wrapperSettings = null;
52
+ }
53
+ // saves all settings and require the db module
54
+ this.type = type;
55
+ this.dbModule = require(`./databases/${type}_db`);
56
+ this.dbSettings = dbSettings;
57
+ this.wrapperSettings = wrapperSettings;
58
+ this.logger = logging.normalizeLogger(logger);
59
+ const db = new this.dbModule.Database(this.dbSettings);
60
+ db.logger = this.logger;
61
+ this.db = new CacheAndBufferLayer.Database(db, this.wrapperSettings, this.logger);
62
+ // Expose the cache wrapper's metrics to the user. See lib/CacheAndBufferLayer.js for details.
63
+ //
64
+ // WARNING: This feature is EXPERIMENTAL -- do not assume it will continue to exist in its
65
+ // current form in a future version.
66
+ this.metrics = this.db.metrics;
67
+ }
68
+ /**
69
+ * @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
70
+ */
71
+ init(callback = null) {
72
+ if (callback != null) {
73
+ return cbDb.init.call(this.db);
74
+ }
75
+ return this.db.init();
76
+ }
77
+ /**
78
+ * Wrapper functions
79
+ */
80
+ /**
81
+ * Deprecated synonym of flush().
82
+ *
83
+ * @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
84
+ */
85
+ doShutdown(callback = null) {
86
+ return this.flush(callback);
87
+ }
88
+ /**
89
+ * Writes any unsaved changes to the underlying database.
90
+ *
91
+ * @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
92
+ */
93
+ flush(callback = null) {
94
+ if (!cbDb || !cbDb.flush === undefined)
95
+ return null;
96
+ if (callback != null) { // @ts-ignore
97
+ return cbDb.flush.call(this.db, callback);
98
+ }
99
+ return this.db.flush();
100
+ }
101
+ /**
102
+ * @param key
103
+ * @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
104
+ */
105
+ get(key, callback = null) {
106
+ if (callback != null) { // @ts-ignore
107
+ return cbDb.get.call(this.db, key, callback);
108
+ }
109
+ return this.db.get(key);
110
+ }
111
+ /**
112
+ * @param key
113
+ * @param notKey
114
+ * @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
115
+ */
116
+ findKeys(key, notKey, callback = null) {
117
+ if (callback != null) { // @ts-ignore
118
+ return cbDb.findKeys.call(this.db, key, notKey, callback);
119
+ }
120
+ return this.db.findKeys(key, notKey);
121
+ }
122
+ /**
123
+ * Removes an entry from the database if present.
124
+ *
125
+ * @param key
126
+ * @param cb Deprecated. Node-style callback. Called when the write has been committed to the
127
+ * underlying database driver. If null, a Promise is returned.
128
+ * @param deprecated Deprecated callback that is called just after cb. Ignored if cb is null.
129
+ */
130
+ remove(key, cb = null, deprecated = null) {
131
+ if (cb != null) { // @ts-ignore
132
+ return cbDb.remove.call(this.db, key, makeDoneCallback(cb, deprecated));
133
+ }
134
+ return this.db.remove(key);
135
+ }
136
+ /**
137
+ * Adds or changes the value of an entry.
138
+ *
139
+ * @param key
140
+ * @param value
141
+ * @param cb Deprecated. Node-style callback. Called when the write has been committed to the
142
+ * underlying database driver. If null, a Promise is returned.
143
+ * @param deprecated Deprecated callback that is called just after cb. Ignored if cb is null.
144
+ */
145
+ set(key, value, cb = null, deprecated = null) {
146
+ if (cb != null) { // @ts-ignore
147
+ return cbDb.get.call(this.db, key, value, makeDoneCallback(cb, deprecated));
148
+ }
149
+ return this.db.set(key, value);
150
+ }
151
+ /**
152
+ * @param key
153
+ * @param sub
154
+ * @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
155
+ */
156
+ getSub(key, sub, callback = null) {
157
+ if (callback != null) { // @ts-ignore
158
+ return cbDb.getSub.call(this.db, key, sub, callback);
159
+ }
160
+ return this.db.getSub(key, sub);
161
+ }
162
+ /**
163
+ * Adds or changes a subvalue of an entry.
164
+ *
165
+ * @param key
166
+ * @param sub
167
+ * @param value
168
+ * @param cb Deprecated. Node-style callback. Called when the write has been committed to the
169
+ * underlying database driver. If null, a Promise is returned.
170
+ * @param deprecated Deprecated callback that is called just after cb. Ignored if cb is null.
171
+ */
172
+ setSub(key, sub, value, cb = null, deprecated = null) {
173
+ if (cb != null) {
174
+ // @ts-ignore
175
+ return cbDb.setSub.call(this.db, key, sub, value, makeDoneCallback(cb, deprecated));
176
+ }
177
+ return this.db.setSub(key, sub, value);
178
+ }
179
+ /**
180
+ * Flushes unwritten changes then closes the connection to the underlying database. After this
181
+ * returns, any future call to a method on this object may result in an error.
182
+ *
183
+ * @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
184
+ */
185
+ close(callback = null) {
186
+ if (callback != null) { // @ts-ignore
187
+ return cbDb.close.call(this.db, callback);
188
+ }
189
+ return this.db.close();
190
+ }
191
+ };
192
+ /**
193
+ * Deprecated synonym of Database.
194
+ */
215
195
  exports.database = exports.Database;
196
+
197
+ exports.Database = Database;
@@ -0,0 +1,79 @@
1
+ import {normalizeLogger} from './logging';
2
+
3
+ const nullLogger = normalizeLogger(null);
4
+
5
+ // Format: All characters match themselves except * matches any zero or more characters. No
6
+ // backslash escaping is supported, so it is impossible to create a pattern that matches only the
7
+ // '*' character.
8
+ const simpleGlobToRegExp = (s:string) => s.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
9
+
10
+ export type Settings = {
11
+ data?: any;
12
+ table?: string;
13
+ db?: string;
14
+ idleTimeoutMillis?: any;
15
+ min?: any;
16
+ max?: any;
17
+ engine?: string;
18
+ charset?: string;
19
+ server?: string | undefined;
20
+ requestTimeout?: number;
21
+ bulkLimit?: number;
22
+ queryTimeout?: number;
23
+ connectionString?: string;
24
+ parseJSON?: boolean;
25
+ dbName?: string;
26
+ collection?: string;
27
+ url?: string;
28
+ mock?: any;
29
+ base_index?: string;
30
+ migrate_to_newer_schema?: boolean;
31
+ api?: string
32
+ filename?: string;
33
+ database?: string;
34
+ password?: string;
35
+ user?: string;
36
+ port?: number | string;
37
+ host?: string;
38
+ maxListeners?: number | undefined;
39
+ json?: boolean;
40
+ cache?: number;
41
+ writeInterval?: number;
42
+ logger?: any;
43
+ columnFamily?: any;
44
+ clientOptions?: any;
45
+ };
46
+
47
+
48
+ class AbstractDatabase {
49
+ logger: any;
50
+ // @ts-ignore
51
+ settings: Settings;
52
+ constructor() {
53
+ if (new.target === module.exports) {
54
+ throw new TypeError('cannot instantiate Abstract Database directly');
55
+ }
56
+ for (const fn of ['init', 'close', 'get', 'findKeys', 'remove', 'set']) {
57
+ // @ts-ignore
58
+ if (typeof this[fn] !== 'function') throw new TypeError(`method ${fn} not defined`);
59
+ }
60
+ this.logger = nullLogger;
61
+ }
62
+
63
+ /**
64
+ * For findKey regex. Used by document dbs like mongodb or dirty.
65
+ */
66
+ createFindRegex(key:string, notKey?:string) {
67
+ let regex = `^(?=${simpleGlobToRegExp(key)}$)`;
68
+ if (notKey != null) regex += `(?!${simpleGlobToRegExp(notKey)}$)`;
69
+ return new RegExp(regex);
70
+ }
71
+
72
+ doBulk(operations:any, cb: ()=>{}) {
73
+ throw new Error('the doBulk method must be implemented if write caching is enabled');
74
+ }
75
+
76
+ get isAsync() { return false; }
77
+ }
78
+
79
+ export default AbstractDatabase;