ueberdb2 4.1.10 → 4.1.11

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.
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ var logging = require('./logging.js');
4
+
5
+ const nullLogger = logging.normalizeLogger(null);
6
+ // Format: All characters match themselves except * matches any zero or more characters. No
7
+ // backslash escaping is supported, so it is impossible to create a pattern that matches only the
8
+ // '*' character.
9
+ const simpleGlobToRegExp = (s) => s.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
10
+ class AbstractDatabase {
11
+ logger;
12
+ // @ts-ignore
13
+ settings;
14
+ constructor() {
15
+ if (new.target === module.exports) {
16
+ throw new TypeError('cannot instantiate Abstract Database directly');
17
+ }
18
+ for (const fn of ['init', 'close', 'get', 'findKeys', 'remove', 'set']) {
19
+ // @ts-ignore
20
+ if (typeof this[fn] !== 'function')
21
+ throw new TypeError(`method ${fn} not defined`);
22
+ }
23
+ this.logger = nullLogger;
24
+ }
25
+ /**
26
+ * For findKey regex. Used by document dbs like mongodb or dirty.
27
+ */
28
+ createFindRegex(key, notKey) {
29
+ let regex = `^(?=${simpleGlobToRegExp(key)}$)`;
30
+ if (notKey != null)
31
+ regex += `(?!${simpleGlobToRegExp(notKey)}$)`;
32
+ return new RegExp(regex);
33
+ }
34
+ doBulk(operations, cb) {
35
+ throw new Error('the doBulk method must be implemented if write caching is enabled');
36
+ }
37
+ get isAsync() { return false; }
38
+ }
39
+
40
+ module.exports = AbstractDatabase;