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,69 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const assert_1 = __importDefault(require("assert"));
30
- const logging_1 = __importDefault(require("../lib/logging"));
31
- const ueberdb = __importStar(require("../index"));
32
- 'use strict';
33
- const assert = assert_1.default.strict;
34
- const logger = new logging_1.default.ConsoleLogger();
35
- describe(__filename, () => {
36
- let db = null;
37
- let mock = null;
38
- const createDb = async (wrapperSettings = {}) => {
39
- const settings = {};
40
- db = new ueberdb.Database('mock', settings, { json: false, ...wrapperSettings }, logger);
41
- // @ts-expect-error TS(2339): Property 'mock' does not exist on type '{}'.
42
- mock = settings.mock;
43
- mock.once('init', (cb) => cb());
44
- await db.init();
45
- };
46
- afterEach(async () => {
47
- if (mock != null) {
48
- mock.removeAllListeners();
49
- mock.once('close', (cb) => cb());
50
- mock = null;
51
- }
52
- if (db != null) {
53
- await db.close();
54
- db = null;
55
- }
56
- });
57
- it('cached entries are flushed before calling findKeys', async () => {
58
- // Trigger a test timeout if flush() completes before the write operation is buffered.
59
- await createDb({ writeInterval: 1e9 });
60
- let called = false;
61
- mock.on('set', (k, v, cb) => { called = true; cb(null); });
62
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
63
- mock.on('findKeys', (k, nk, cb) => { assert(called); cb(null, []); });
64
- await Promise.all([
65
- db.set('key', 'value'),
66
- db.findKeys('key', null),
67
- ]);
68
- });
69
- });
@@ -1,83 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const logging_1 = __importDefault(require("../lib/logging"));
30
- const ueberdb = __importStar(require("../index"));
31
- 'use strict';
32
- const logger = new logging_1.default.ConsoleLogger();
33
- describe(__filename, () => {
34
- let db = null;
35
- let mock = null;
36
- const createDb = async (wrapperSettings = {}) => {
37
- const settings = {};
38
- db = new ueberdb.Database('mock', settings, { json: false, ...wrapperSettings }, logger);
39
- // @ts-expect-error TS(2339): Property 'mock' does not exist on type '{}'.
40
- mock = settings.mock;
41
- mock.once('init', (cb) => cb());
42
- await db.init();
43
- };
44
- afterEach(async () => {
45
- if (mock != null) {
46
- mock.removeAllListeners();
47
- mock.once('close', (cb) => cb());
48
- mock = null;
49
- }
50
- if (db != null) {
51
- await db.close();
52
- db = null;
53
- }
54
- });
55
- it('flush() immediately after set() sees the write operation', async () => {
56
- // Trigger a test timeout if flush() completes before the write operation is buffered.
57
- await createDb({ writeInterval: 1e9 });
58
- mock.on('set', (k, v, cb) => cb());
59
- await Promise.all([
60
- db.set('key', 'value'),
61
- db.flush(),
62
- ]);
63
- });
64
- it('flush() immediately after setSub() sees the write operation', async () => {
65
- // Trigger a test timeout if flush() completes before the write operation is buffered.
66
- await createDb({ writeInterval: 1e9 });
67
- mock.on('get', (k, cb) => cb(null, { sub: 'oldvalue' }));
68
- mock.on('set', (k, v, cb) => cb(null));
69
- await Promise.all([
70
- db.setSub('key', ['sub'], 'newvalue'),
71
- db.flush(),
72
- ]);
73
- });
74
- it('flush() immediately after remove() sees the write operation', async () => {
75
- // Trigger a test timeout if flush() completes before the write operation is buffered.
76
- await createDb({ writeInterval: 1e9 });
77
- mock.on('remove', (k, cb) => cb(null));
78
- await Promise.all([
79
- db.remove('key'),
80
- db.flush(),
81
- ]);
82
- });
83
- });
@@ -1,57 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const assert_1 = __importDefault(require("assert"));
30
- const ueberdb = __importStar(require("../index"));
31
- 'use strict';
32
- const assert = assert_1.default.strict;
33
- describe(__filename, () => {
34
- let db;
35
- beforeEach(async () => {
36
- db = new ueberdb.Database('memory', {}, {});
37
- await db.init();
38
- await db.set('k', { s: 'v' });
39
- });
40
- afterEach(async () => {
41
- if (db != null)
42
- await db.close();
43
- db = null;
44
- });
45
- it('getSub stops at non-objects', async () => {
46
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
47
- assert((await db.getSub('k', ['s', 'length'])) == null);
48
- });
49
- it('getSub ignores non-own properties', async () => {
50
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
51
- assert((await db.getSub('k', ['toString'])) == null);
52
- });
53
- it('getSub ignores __proto__', async () => {
54
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
55
- assert((await db.getSub('k', ['__proto__'])) == null);
56
- });
57
- });
@@ -1,155 +0,0 @@
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
- // @ts-expect-error TS(2306): File '/mnt/c/Users/samue/WebstormProjects/ueberDB/... Remove this comment to see the full error message
7
- const CacheAndBufferLayer_1 = require("../lib/CacheAndBufferLayer");
8
- const assert_1 = __importDefault(require("assert"));
9
- 'use strict';
10
- const LRU = { exportedForTesting: CacheAndBufferLayer_1.exportedForTesting }.exportedForTesting.LRU;
11
- const assert = assert_1.default.strict;
12
- describe(__filename, () => {
13
- describe('capacity = 0', () => {
14
- it('constructor does not throw', async () => {
15
- new LRU(0);
16
- });
17
- describe('behavior when empty', () => {
18
- it('get() returns nullish', async () => {
19
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
20
- assert((new LRU(0)).get('k') == null);
21
- });
22
- it('empty iteration', async () => {
23
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
24
- assert.equal([...(new LRU(0))].length, 0);
25
- });
26
- it('evictOld() does not throw', async () => {
27
- (new LRU(0)).evictOld();
28
- });
29
- });
30
- describe('single entry with evictable = false', () => {
31
- let evictable, lru, key, val;
32
- beforeEach(async () => {
33
- evictable = false;
34
- lru = new LRU(0, () => evictable);
35
- key = 'k';
36
- val = 'v';
37
- lru.set(key, val);
38
- });
39
- it('get() works', async () => {
40
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
41
- assert.equal(lru.get(key), val);
42
- });
43
- it('iterate works', async () => {
44
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
45
- assert.deepEqual([...lru], [[key, val]]);
46
- });
47
- it('re-set() works', async () => {
48
- const val2 = 'v2';
49
- lru.set(key, val2);
50
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
51
- assert.equal(lru.get(key), val2);
52
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
53
- assert.deepEqual([...lru], [[key, val2]]);
54
- });
55
- it('evictOld() does not evict', async () => {
56
- lru.evictOld();
57
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
58
- assert.deepEqual([...lru], [[key, val]]);
59
- });
60
- it('evictOld() evicts after setting evictable = true', async () => {
61
- evictable = true;
62
- lru.evictOld();
63
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
64
- assert.deepEqual([...lru], []);
65
- });
66
- });
67
- describe('set immediately evicts if evictable', () => {
68
- it('explicitly evictable', async () => {
69
- const lru = new LRU(0, () => true);
70
- lru.set('k', 'v');
71
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
72
- assert(lru.get('k') == null);
73
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
74
- assert.deepEqual([...lru], []);
75
- });
76
- it('is evictable by default', async () => {
77
- const lru = new LRU(0);
78
- lru.set('k', 'v');
79
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
80
- assert(lru.get('k') == null);
81
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
82
- assert.deepEqual([...lru], []);
83
- });
84
- });
85
- });
86
- describe('capacity = 2', () => {
87
- let evictable, lru;
88
- beforeEach(async () => {
89
- evictable = () => false;
90
- lru = new LRU(2, (k, v) => evictable(k, v));
91
- });
92
- it('iterates oldest first', async () => {
93
- lru.set(0, '0');
94
- lru.set(1, '1');
95
- let i = 0;
96
- for (const [k, v] of lru) {
97
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
98
- assert.equal(k, i);
99
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
100
- assert.equal(v, `${i}`);
101
- i++;
102
- }
103
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
104
- assert.equal(i, 2);
105
- });
106
- it('get(k) updates recently used', async () => {
107
- lru.set(0, '0');
108
- lru.set(1, '1');
109
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
110
- assert.equal(lru.get(0), '0');
111
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
112
- assert.deepEqual([...lru], [[1, '1'], [0, '0']]);
113
- });
114
- it('get(k, false) does not update recently used', async () => {
115
- lru.set(0, '0');
116
- lru.set(1, '1');
117
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
118
- assert.equal(lru.get(0, false), '0');
119
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
120
- assert.deepEqual([...lru], [[0, '0'], [1, '1']]);
121
- });
122
- it('re-set() updates recently used', async () => {
123
- lru.set(0, '0');
124
- lru.set(1, '1');
125
- lru.set(0, '00');
126
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
127
- assert.deepEqual([...lru], [[1, '1'], [0, '00']]);
128
- });
129
- it('evictOld() only evicts evictable entries', async () => {
130
- evictable = () => false;
131
- lru.set(0, '0');
132
- lru.set(1, '1');
133
- lru.set(2, '2');
134
- lru.set(3, '3');
135
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
136
- assert.deepEqual([...lru], [[0, '0'], [1, '1'], [2, '2'], [3, '3']]);
137
- evictable = (k) => k >= 2;
138
- lru.evictOld();
139
- // The newer entries should be evicted because the older are dirty/writingInProgress.
140
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
141
- assert.deepEqual([...lru], [[0, '0'], [1, '1']]);
142
- });
143
- it('evictOld() does nothing if at or below capacity', async () => {
144
- evictable = () => true;
145
- lru.set(0, '0');
146
- lru.evictOld();
147
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
148
- assert.deepEqual([...lru], [[0, '0']]);
149
- lru.set(1, '1');
150
- lru.evictOld();
151
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
152
- assert.deepEqual([...lru], [[0, '0'], [1, '1']]);
153
- });
154
- });
155
- });
@@ -1,59 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const assert_1 = __importDefault(require("assert"));
30
- const memory = __importStar(require("../databases/memory_db"));
31
- 'use strict';
32
- const assert = assert_1.default.strict;
33
- describe(__filename, () => {
34
- describe('data option', () => {
35
- it('uses existing records from data option', async () => {
36
- const db = new memory.Database({ data: new Map([['foo', 'bar']]) });
37
- await db.init();
38
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
39
- assert.equal(await db.get('foo'), 'bar');
40
- });
41
- it('updates existing map', async () => {
42
- const data = new Map();
43
- const db = new memory.Database({ data });
44
- await db.init();
45
- await db.set('foo', 'bar');
46
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
47
- assert.equal(data.get('foo'), 'bar');
48
- });
49
- it('does not clear map on close', async () => {
50
- const data = new Map();
51
- const db = new memory.Database({ data });
52
- await db.init();
53
- await db.set('foo', 'bar');
54
- await db.close();
55
- // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
56
- assert.equal(data.get('foo'), 'bar');
57
- });
58
- });
59
- });