ueberdb2 4.0.11 → 4.0.17

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 (81) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.cjs +44 -5
  3. package/.github/workflows/npmpublish.yml +3 -3
  4. package/databases/{cassandra_db.js → cassandra_db.ts} +45 -30
  5. package/databases/{couch_db.js → couch_db.ts} +78 -31
  6. package/databases/{dirty_db.js → dirty_db.ts} +19 -14
  7. package/databases/{dirty_git_db.js → dirty_git_db.ts} +19 -15
  8. package/databases/{elasticsearch_db.js → elasticsearch_db.ts} +30 -21
  9. package/databases/{memory_db.js → memory_db.ts} +8 -8
  10. package/databases/mock_db.ts +43 -0
  11. package/databases/{mongodb_db.js → mongodb_db.ts} +22 -16
  12. package/databases/{mssql_db.js → mssql_db.ts} +29 -21
  13. package/databases/{mysql_db.js → mysql_db.ts} +20 -15
  14. package/databases/{postgres_db.js → postgres_db.ts} +37 -22
  15. package/databases/{postgrespool_db.js → postgrespool_db.ts} +3 -3
  16. package/databases/redis_db.ts +129 -0
  17. package/databases/{rethink_db.js → rethink_db.ts} +35 -19
  18. package/databases/{sqlite_db.js → sqlite_db.ts} +37 -36
  19. package/dist/databases/cassandra_db.js +237 -0
  20. package/dist/databases/couch_db.js +181 -0
  21. package/dist/databases/dirty_db.js +78 -0
  22. package/dist/databases/dirty_git_db.js +77 -0
  23. package/dist/databases/elasticsearch_db.js +251 -0
  24. package/dist/databases/memory_db.js +39 -0
  25. package/dist/databases/mock_db.js +40 -0
  26. package/dist/databases/mongodb_db.js +127 -0
  27. package/dist/databases/mssql_db.js +187 -0
  28. package/dist/databases/mysql_db.js +170 -0
  29. package/dist/databases/postgres_db.js +192 -0
  30. package/dist/databases/postgrespool_db.js +12 -0
  31. package/dist/databases/redis_db.js +105 -0
  32. package/dist/databases/rethink_db.js +123 -0
  33. package/dist/databases/sqlite_db.js +140 -0
  34. package/dist/index.js +215 -0
  35. package/dist/lib/AbstractDatabase.js +38 -0
  36. package/dist/lib/CacheAndBufferLayer.js +657 -0
  37. package/dist/lib/logging.js +34 -0
  38. package/dist/test/lib/databases.js +72 -0
  39. package/dist/test/test.js +373 -0
  40. package/dist/test/test_bulk.js +74 -0
  41. package/dist/test/test_elasticsearch.js +157 -0
  42. package/dist/test/test_findKeys.js +69 -0
  43. package/dist/test/test_flush.js +83 -0
  44. package/dist/test/test_getSub.js +57 -0
  45. package/dist/test/test_lru.js +155 -0
  46. package/dist/test/test_memory.js +59 -0
  47. package/dist/test/test_metrics.js +772 -0
  48. package/dist/test/test_mysql.js +91 -0
  49. package/dist/test/test_postgres.js +40 -0
  50. package/dist/test/test_setSub.js +48 -0
  51. package/dist/test/test_tojson.js +62 -0
  52. package/docker-compose.yml +44 -0
  53. package/{index.js → index.ts} +76 -25
  54. package/lib/AbstractDatabase.ts +79 -0
  55. package/lib/{CacheAndBufferLayer.js → CacheAndBufferLayer.ts} +17 -16
  56. package/lib/{logging.js → logging.ts} +10 -6
  57. package/package.json +18 -3
  58. package/test/lib/{databases.js → databases.ts} +8 -5
  59. package/test/test.ts +328 -0
  60. package/test/test_bulk.ts +69 -0
  61. package/test/{test_elasticsearch.js → test_elasticsearch.ts} +48 -53
  62. package/test/{test_findKeys.js → test_findKeys.ts} +15 -17
  63. package/test/{test_flush.js → test_flush.ts} +16 -22
  64. package/test/test_getSub.ts +28 -0
  65. package/test/test_lru.ts +151 -0
  66. package/test/test_memory.ts +32 -0
  67. package/test/{test_metrics.js → test_metrics.ts} +73 -68
  68. package/test/{test_mysql.js → test_mysql.ts} +16 -22
  69. package/test/test_postgres.ts +16 -0
  70. package/test/{test_setSub.js → test_setSub.ts} +8 -12
  71. package/test/test_tojson.ts +34 -0
  72. package/databases/mock_db.js +0 -42
  73. package/databases/redis_db.js +0 -96
  74. package/lib/AbstractDatabase.js +0 -37
  75. package/test/test.js +0 -328
  76. package/test/test_bulk.js +0 -69
  77. package/test/test_getSub.js +0 -31
  78. package/test/test_lru.js +0 -145
  79. package/test/test_memory.js +0 -31
  80. package/test/test_postgres.js +0 -16
  81. package/test/test_tojson.js +0 -37
@@ -1,26 +1,24 @@
1
+ import assert$0 from 'assert';
2
+ import logging from '../lib/logging';
3
+ import * as ueberdb from '../index';
1
4
  'use strict';
2
-
3
- const assert = require('assert').strict;
4
- const logging = require('../lib/logging');
5
- const ueberdb = require('../index');
6
-
5
+ const assert = assert$0.strict;
7
6
  const logger = new logging.ConsoleLogger();
8
-
9
- describe(__filename, function () {
10
- let db = null;
11
- let mock = null;
7
+ describe(__filename, () => {
8
+ let db: any = null;
9
+ let mock: any = null;
12
10
  const createDb = async (wrapperSettings = {}) => {
13
11
  const settings = {};
14
12
  db = new ueberdb.Database('mock', settings, {json: false, ...wrapperSettings}, logger);
13
+ // @ts-expect-error TS(2339): Property 'mock' does not exist on type '{}'.
15
14
  mock = settings.mock;
16
- mock.once('init', (cb) => cb());
15
+ mock.once('init', (cb: any) => cb());
17
16
  await db.init();
18
17
  };
19
-
20
- afterEach(async function () {
18
+ afterEach(async () => {
21
19
  if (mock != null) {
22
20
  mock.removeAllListeners();
23
- mock.once('close', (cb) => cb());
21
+ mock.once('close', (cb: any) => cb());
24
22
  mock = null;
25
23
  }
26
24
  if (db != null) {
@@ -28,13 +26,13 @@ describe(__filename, function () {
28
26
  db = null;
29
27
  }
30
28
  });
31
-
32
- it('cached entries are flushed before calling findKeys', async function () {
29
+ it('cached entries are flushed before calling findKeys', async () => {
33
30
  // Trigger a test timeout if flush() completes before the write operation is buffered.
34
31
  await createDb({writeInterval: 1e9});
35
32
  let called = false;
36
- mock.on('set', (k, v, cb) => { called = true; cb(null); });
37
- mock.on('findKeys', (k, nk, cb) => { assert(called); cb(null, []); });
33
+ mock.on('set', (k: any, v: any, cb: any) => { called = true; cb(null); });
34
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
35
+ mock.on('findKeys', (k: any, nk: any, cb: any) => { assert(called); cb(null, []); });
38
36
  await Promise.all([
39
37
  db.set('key', 'value'),
40
38
  db.findKeys('key', null),
@@ -1,25 +1,22 @@
1
+ import logging from '../lib/logging';
2
+ import * as ueberdb from '../index';
1
3
  'use strict';
2
-
3
- const logging = require('../lib/logging');
4
- const ueberdb = require('../index');
5
-
6
4
  const logger = new logging.ConsoleLogger();
7
-
8
- describe(__filename, function () {
9
- let db = null;
10
- let mock = null;
5
+ describe(__filename, () => {
6
+ let db: any = null;
7
+ let mock: any = null;
11
8
  const createDb = async (wrapperSettings = {}) => {
12
9
  const settings = {};
13
10
  db = new ueberdb.Database('mock', settings, {json: false, ...wrapperSettings}, logger);
11
+ // @ts-expect-error TS(2339): Property 'mock' does not exist on type '{}'.
14
12
  mock = settings.mock;
15
- mock.once('init', (cb) => cb());
13
+ mock.once('init', (cb: any) => cb());
16
14
  await db.init();
17
15
  };
18
-
19
- afterEach(async function () {
16
+ afterEach(async () => {
20
17
  if (mock != null) {
21
18
  mock.removeAllListeners();
22
- mock.once('close', (cb) => cb());
19
+ mock.once('close', (cb: any) => cb());
23
20
  mock = null;
24
21
  }
25
22
  if (db != null) {
@@ -27,32 +24,29 @@ describe(__filename, function () {
27
24
  db = null;
28
25
  }
29
26
  });
30
-
31
- it('flush() immediately after set() sees the write operation', async function () {
27
+ it('flush() immediately after set() sees the write operation', async () => {
32
28
  // Trigger a test timeout if flush() completes before the write operation is buffered.
33
29
  await createDb({writeInterval: 1e9});
34
- mock.on('set', (k, v, cb) => cb());
30
+ mock.on('set', (k: any, v: any, cb: any) => cb());
35
31
  await Promise.all([
36
32
  db.set('key', 'value'),
37
33
  db.flush(),
38
34
  ]);
39
35
  });
40
-
41
- it('flush() immediately after setSub() sees the write operation', async function () {
36
+ it('flush() immediately after setSub() sees the write operation', async () => {
42
37
  // Trigger a test timeout if flush() completes before the write operation is buffered.
43
38
  await createDb({writeInterval: 1e9});
44
- mock.on('get', (k, cb) => cb(null, {sub: 'oldvalue'}));
45
- mock.on('set', (k, v, cb) => cb(null));
39
+ mock.on('get', (k: any, cb: any) => cb(null, {sub: 'oldvalue'}));
40
+ mock.on('set', (k: any, v: any, cb: any) => cb(null));
46
41
  await Promise.all([
47
42
  db.setSub('key', ['sub'], 'newvalue'),
48
43
  db.flush(),
49
44
  ]);
50
45
  });
51
-
52
- it('flush() immediately after remove() sees the write operation', async function () {
46
+ it('flush() immediately after remove() sees the write operation', async () => {
53
47
  // Trigger a test timeout if flush() completes before the write operation is buffered.
54
48
  await createDb({writeInterval: 1e9});
55
- mock.on('remove', (k, cb) => cb(null));
49
+ mock.on('remove', (k: any, cb: any) => cb(null));
56
50
  await Promise.all([
57
51
  db.remove('key'),
58
52
  db.flush(),
@@ -0,0 +1,28 @@
1
+ import assert$0 from 'assert';
2
+ import * as ueberdb from '../index';
3
+ 'use strict';
4
+ const assert = assert$0.strict;
5
+ describe(__filename, () => {
6
+ let db: any;
7
+ beforeEach(async () => {
8
+ db = new ueberdb.Database('memory', {}, {});
9
+ await db.init();
10
+ await db.set('k', {s: 'v'});
11
+ });
12
+ afterEach(async () => {
13
+ if (db != null) await db.close();
14
+ db = null;
15
+ });
16
+ it('getSub stops at non-objects', async () => {
17
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
18
+ assert((await db.getSub('k', ['s', 'length'])) == null);
19
+ });
20
+ it('getSub ignores non-own properties', async () => {
21
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
22
+ assert((await db.getSub('k', ['toString'])) == null);
23
+ });
24
+ it('getSub ignores __proto__', async () => {
25
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
26
+ assert((await db.getSub('k', ['__proto__'])) == null);
27
+ });
28
+ });
@@ -0,0 +1,151 @@
1
+ // @ts-expect-error TS(2306): File '/mnt/c/Users/samue/WebstormProjects/ueberDB/... Remove this comment to see the full error message
2
+ import {exportedForTesting} from '../lib/CacheAndBufferLayer';
3
+ import assert$0 from 'assert';
4
+ 'use strict';
5
+ const LRU = {exportedForTesting}.exportedForTesting.LRU;
6
+ const assert = assert$0.strict;
7
+ describe(__filename, () => {
8
+ describe('capacity = 0', () => {
9
+ it('constructor does not throw', async () => {
10
+ new LRU(0);
11
+ });
12
+ describe('behavior when empty', () => {
13
+ it('get() returns nullish', async () => {
14
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
15
+ assert((new LRU(0)).get('k') == null);
16
+ });
17
+ it('empty iteration', async () => {
18
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
19
+ assert.equal([...(new LRU(0))].length, 0);
20
+ });
21
+ it('evictOld() does not throw', async () => {
22
+ (new LRU(0)).evictOld();
23
+ });
24
+ });
25
+ describe('single entry with evictable = false', () => {
26
+ let evictable: any, lru: any, key: any, val: any;
27
+ beforeEach(async () => {
28
+ evictable = false;
29
+ lru = new LRU(0, () => evictable);
30
+ key = 'k';
31
+ val = 'v';
32
+ lru.set(key, val);
33
+ });
34
+ it('get() works', async () => {
35
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
36
+ assert.equal(lru.get(key), val);
37
+ });
38
+ it('iterate works', async () => {
39
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
40
+ assert.deepEqual([...lru], [[key, val]]);
41
+ });
42
+ it('re-set() works', async () => {
43
+ const val2 = 'v2';
44
+ lru.set(key, val2);
45
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
46
+ assert.equal(lru.get(key), val2);
47
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
48
+ assert.deepEqual([...lru], [[key, val2]]);
49
+ });
50
+ it('evictOld() does not evict', async () => {
51
+ lru.evictOld();
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, val]]);
54
+ });
55
+ it('evictOld() evicts after setting evictable = true', async () => {
56
+ evictable = true;
57
+ lru.evictOld();
58
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
59
+ assert.deepEqual([...lru], []);
60
+ });
61
+ });
62
+ describe('set immediately evicts if evictable', () => {
63
+ it('explicitly evictable', async () => {
64
+ const lru = new LRU(0, () => true);
65
+ lru.set('k', 'v');
66
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
67
+ assert(lru.get('k') == null);
68
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
69
+ assert.deepEqual([...lru], []);
70
+ });
71
+
72
+ it('is evictable by default', async () => {
73
+ const lru = new LRU(0);
74
+ lru.set('k', 'v');
75
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
76
+ assert(lru.get('k') == null);
77
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
78
+ assert.deepEqual([...lru], []);
79
+ });
80
+ });
81
+ });
82
+ describe('capacity = 2', () => {
83
+ let evictable: any, lru: any;
84
+ beforeEach(async () => {
85
+ evictable = () => false;
86
+ lru = new LRU(2, (k: any, v: any) => evictable(k, v));
87
+ });
88
+ it('iterates oldest first', async () => {
89
+ lru.set(0, '0');
90
+ lru.set(1, '1');
91
+ let i = 0;
92
+ for (const [k, v] of lru) {
93
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
94
+ assert.equal(k, i);
95
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
96
+ assert.equal(v, `${i}`);
97
+ i++;
98
+ }
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(i, 2);
101
+ });
102
+ it('get(k) updates recently used', async () => {
103
+ lru.set(0, '0');
104
+ lru.set(1, '1');
105
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
106
+ assert.equal(lru.get(0), '0');
107
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
108
+ assert.deepEqual([...lru], [[1, '1'], [0, '0']]);
109
+ });
110
+ it('get(k, false) does not update recently used', async () => {
111
+ lru.set(0, '0');
112
+ lru.set(1, '1');
113
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
114
+ assert.equal(lru.get(0, false), '0');
115
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
116
+ assert.deepEqual([...lru], [[0, '0'], [1, '1']]);
117
+ });
118
+ it('re-set() updates recently used', async () => {
119
+ lru.set(0, '0');
120
+ lru.set(1, '1');
121
+ lru.set(0, '00');
122
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
123
+ assert.deepEqual([...lru], [[1, '1'], [0, '00']]);
124
+ });
125
+ it('evictOld() only evicts evictable entries', async () => {
126
+ evictable = () => false;
127
+ lru.set(0, '0');
128
+ lru.set(1, '1');
129
+ lru.set(2, '2');
130
+ lru.set(3, '3');
131
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
132
+ assert.deepEqual([...lru], [[0, '0'], [1, '1'], [2, '2'], [3, '3']]);
133
+ evictable = (k: any) => k >= 2;
134
+ lru.evictOld();
135
+ // The newer entries should be evicted because the older are dirty/writingInProgress.
136
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
137
+ assert.deepEqual([...lru], [[0, '0'], [1, '1']]);
138
+ });
139
+ it('evictOld() does nothing if at or below capacity', async () => {
140
+ evictable = () => true;
141
+ lru.set(0, '0');
142
+ lru.evictOld();
143
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
144
+ assert.deepEqual([...lru], [[0, '0']]);
145
+ lru.set(1, '1');
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'], [1, '1']]);
149
+ });
150
+ });
151
+ });
@@ -0,0 +1,32 @@
1
+ import assert$0 from 'assert';
2
+ import * as memory from '../databases/memory_db';
3
+ 'use strict';
4
+ const assert = assert$0.strict;
5
+
6
+ describe(__filename, () => {
7
+ describe('data option', () => {
8
+ it('uses existing records from data option', async () => {
9
+ const db = new memory.Database({data: new Map([['foo', 'bar']])});
10
+ await db.init();
11
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
12
+ assert.equal(await db.get('foo'), 'bar');
13
+ });
14
+ it('updates existing map', async () => {
15
+ const data = new Map();
16
+ const db = new memory.Database({data});
17
+ await db.init();
18
+ await db.set('foo', 'bar');
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.equal(data.get('foo'), 'bar');
21
+ });
22
+ it('does not clear map on close', async () => {
23
+ const data = new Map();
24
+ const db = new memory.Database({data});
25
+ await db.init();
26
+ await db.set('foo', 'bar');
27
+ await db.close();
28
+ // @ts-expect-error TS(2775): Assertions require every name in the call target t... Remove this comment to see the full error message
29
+ assert.equal(data.get('foo'), 'bar');
30
+ });
31
+ });
32
+ });