@naturalcycles/db-lib 9.27.0 → 10.0.0

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.
@@ -20,7 +20,10 @@ function queryInMemory(q, rows = []) {
20
20
  // .filter
21
21
  // eslint-disable-next-line unicorn/no-array-reduce
22
22
  rows = q._filters.reduce((rows, filter) => {
23
- return rows.filter(row => FILTER_FNS[filter.op](row[filter.name], filter.val));
23
+ return rows.filter(row => {
24
+ const value = (0, js_lib_1._get)(row, filter.name);
25
+ return FILTER_FNS[filter.op](value, filter.val);
26
+ });
24
27
  }, rows);
25
28
  // .select(fieldNames)
26
29
  if (q._selectedFieldNames) {
@@ -4,6 +4,7 @@ exports.runCommonDaoTest = runCommonDaoTest;
4
4
  const node_stream_1 = require("node:stream");
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
7
+ const vitest_1 = require("vitest");
7
8
  const __1 = require("..");
8
9
  const common_dao_1 = require("../commondao/common.dao");
9
10
  const dbTest_1 = require("./dbTest");
@@ -23,52 +24,52 @@ function runCommonDaoTest(db, quirks = {}) {
23
24
  const item1 = items[0];
24
25
  const expectedItems = items.map(i => ({
25
26
  ...i,
26
- updated: expect.any(Number),
27
+ updated: vitest_1.expect.any(Number),
27
28
  }));
28
- test('ping', async () => {
29
+ (0, vitest_1.test)('ping', async () => {
29
30
  await dao.ping();
30
31
  });
31
32
  // CREATE TABLE, DROP
32
33
  if (support.createTable) {
33
- test('createTable, dropIfExists=true', async () => {
34
+ (0, vitest_1.test)('createTable, dropIfExists=true', async () => {
34
35
  await dao.createTable(test_model_1.testItemBMJsonSchema, { dropIfExists: true });
35
36
  });
36
37
  }
37
38
  if (support.queries) {
38
39
  // DELETE ALL initially
39
- test('deleteByIds test items', async () => {
40
+ (0, vitest_1.test)('deleteByIds test items', async () => {
40
41
  const rows = await dao.query().select(['id']).runQuery();
41
42
  await db.deleteByQuery(__1.DBQuery.create(test_model_1.TEST_TABLE).filter('id', 'in', rows.map(r => r.id)));
42
43
  });
43
44
  // QUERY empty
44
- test('runQuery(all), runQueryCount should return empty', async () => {
45
- expect(await dao.query().runQuery()).toEqual([]);
46
- expect(await dao.query().runQueryCount()).toBe(0);
45
+ (0, vitest_1.test)('runQuery(all), runQueryCount should return empty', async () => {
46
+ (0, vitest_1.expect)(await dao.query().runQuery()).toEqual([]);
47
+ (0, vitest_1.expect)(await dao.query().runQueryCount()).toBe(0);
47
48
  });
48
49
  }
49
50
  // GET empty
50
- test('getByIds(item1.id) should return empty', async () => {
51
+ (0, vitest_1.test)('getByIds(item1.id) should return empty', async () => {
51
52
  const [item1Loaded] = await dao.getByIds([item1.id]);
52
- expect(item1Loaded).toBeUndefined();
53
- expect(await dao.getById(item1.id)).toBeNull();
53
+ (0, vitest_1.expect)(item1Loaded).toBeUndefined();
54
+ (0, vitest_1.expect)(await dao.getById(item1.id)).toBeNull();
54
55
  });
55
- test('getByIds([]) should return []', async () => {
56
- expect(await dao.getByIds([])).toEqual([]);
56
+ (0, vitest_1.test)('getByIds([]) should return []', async () => {
57
+ (0, vitest_1.expect)(await dao.getByIds([])).toEqual([]);
57
58
  });
58
- test('getByIds(...) should return empty', async () => {
59
- expect(await dao.getByIds(['abc', 'abcd'])).toEqual([]);
59
+ (0, vitest_1.test)('getByIds(...) should return empty', async () => {
60
+ (0, vitest_1.expect)(await dao.getByIds(['abc', 'abcd'])).toEqual([]);
60
61
  });
61
62
  // TimeMachine
62
63
  if (support.timeMachine) {
63
- test('getByIds(...) 10 minutes ago should return []', async () => {
64
- expect(await dao.getByIds([item1.id, 'abc'], {
64
+ (0, vitest_1.test)('getByIds(...) 10 minutes ago should return []', async () => {
65
+ (0, vitest_1.expect)(await dao.getByIds([item1.id, 'abc'], {
65
66
  readAt: js_lib_1.localTime.now().minus(10, 'minute').unix,
66
67
  })).toEqual([]);
67
68
  });
68
69
  }
69
70
  // SAVE
70
71
  if (support.nullValues) {
71
- test('should allow to save and load null values', async () => {
72
+ (0, vitest_1.test)('should allow to save and load null values', async () => {
72
73
  const item3 = {
73
74
  ...(0, test_model_1.createTestItemBM)(3),
74
75
  k2: null,
@@ -77,12 +78,12 @@ function runCommonDaoTest(db, quirks = {}) {
77
78
  await dao.save(item3);
78
79
  const item3Loaded = await dao.requireById(item3.id);
79
80
  (0, dbTest_1.expectMatch)([item3], [item3Loaded], quirks);
80
- expect(item3Loaded.k2).toBeNull();
81
- expect(Object.keys(item3)).toContain('k2');
82
- expect(item3.k2).toBeNull();
81
+ (0, vitest_1.expect)(item3Loaded.k2).toBeNull();
82
+ (0, vitest_1.expect)(Object.keys(item3)).toContain('k2');
83
+ (0, vitest_1.expect)(item3.k2).toBeNull();
83
84
  });
84
85
  }
85
- test('undefined values should not be saved/loaded', async () => {
86
+ (0, vitest_1.test)('undefined values should not be saved/loaded', async () => {
86
87
  const item3 = {
87
88
  ...(0, test_model_1.createTestItemBM)(3),
88
89
  k2: undefined,
@@ -94,21 +95,21 @@ function runCommonDaoTest(db, quirks = {}) {
94
95
  expected.updated = item3.updated; // as it's mutated
95
96
  const item3Loaded = await dao.requireById(item3.id);
96
97
  (0, dbTest_1.expectMatch)([expected], [item3Loaded], quirks);
97
- expect(item3Loaded.k2).toBeUndefined();
98
- expect(Object.keys(item3Loaded)).not.toContain('k2');
99
- expect(Object.keys(item3)).toContain('k2');
100
- expect(item3.k2).toBeUndefined();
98
+ (0, vitest_1.expect)(item3Loaded.k2).toBeUndefined();
99
+ (0, vitest_1.expect)(Object.keys(item3Loaded)).not.toContain('k2');
100
+ (0, vitest_1.expect)(Object.keys(item3)).toContain('k2');
101
+ (0, vitest_1.expect)(item3.k2).toBeUndefined();
101
102
  });
102
- test('saveBatch test items', async () => {
103
+ (0, vitest_1.test)('saveBatch test items', async () => {
103
104
  const itemsSaved = await dao.saveBatch(items);
104
- expect(itemsSaved[0]).toBe(items[0]); // expect "same object" returned
105
+ (0, vitest_1.expect)(itemsSaved[0]).toBe(items[0]); // expect "same object" returned
105
106
  // no unnecessary mutation
106
107
  const { updated: _, ...clone } = itemsClone[0];
107
- expect(items[0]).toMatchObject(clone);
108
+ (0, vitest_1.expect)(items[0]).toMatchObject(clone);
108
109
  (0, dbTest_1.expectMatch)(expectedItems, itemsSaved, quirks);
109
110
  });
110
111
  if (support.increment) {
111
- test('increment', async () => {
112
+ (0, vitest_1.test)('increment', async () => {
112
113
  await dao.incrementBatch('k3', { id1: 1, id2: 2 });
113
114
  let rows = await dao.query().runQuery();
114
115
  rows = (0, js_lib_1._sortBy)(rows, r => r.id);
@@ -134,66 +135,74 @@ function runCommonDaoTest(db, quirks = {}) {
134
135
  });
135
136
  }
136
137
  // GET not empty
137
- test('getByIds all items', async () => {
138
+ (0, vitest_1.test)('getByIds all items', async () => {
138
139
  const rows = await dao.getByIds(items.map(i => i.id).concat('abcd'));
139
140
  (0, dbTest_1.expectMatch)(expectedItems, (0, js_lib_1._sortBy)(rows, r => r.id), quirks);
140
141
  });
141
142
  // QUERY
142
143
  if (support.queries) {
143
- test('runQuery(all) should return all items', async () => {
144
+ (0, vitest_1.test)('runQuery(all) should return all items', async () => {
144
145
  let rows = await dao.query().runQuery();
145
146
  rows = (0, js_lib_1._sortBy)(rows, r => r.id);
146
147
  (0, dbTest_1.expectMatch)(expectedItems, rows, quirks);
147
148
  });
148
149
  if (support.dbQueryFilter) {
149
- test('query even=true', async () => {
150
+ (0, vitest_1.test)('query even=true', async () => {
150
151
  let rows = await dao.query().filter('even', '==', true).runQuery();
151
152
  rows = (0, js_lib_1._sortBy)(rows, r => r.id);
152
153
  (0, dbTest_1.expectMatch)(expectedItems.filter(i => i.even), rows, quirks);
153
154
  });
155
+ (0, vitest_1.test)('query nested property', async () => {
156
+ let rows = await dao
157
+ .query()
158
+ .filter('nested.foo', '==', 1)
159
+ .runQuery();
160
+ rows = (0, js_lib_1._sortBy)(rows, r => r.id);
161
+ (0, dbTest_1.expectMatch)(expectedItems.filter(i => i.nested?.foo === 1), rows, quirks);
162
+ });
154
163
  }
155
164
  if (support.dbQueryOrder) {
156
- test('query order by k1 desc', async () => {
165
+ (0, vitest_1.test)('query order by k1 desc', async () => {
157
166
  const rows = await dao.query().order('k1', true).runQuery();
158
167
  (0, dbTest_1.expectMatch)([...expectedItems].reverse(), rows, quirks);
159
168
  });
160
169
  }
161
170
  if (support.dbQuerySelectFields) {
162
- test('projection query with only ids', async () => {
171
+ (0, vitest_1.test)('projection query with only ids', async () => {
163
172
  let rows = await dao.query().select(['id']).runQuery();
164
173
  rows = (0, js_lib_1._sortBy)(rows, r => r.id);
165
174
  (0, dbTest_1.expectMatch)(expectedItems.map(item => (0, js_lib_1._pick)(item, ['id'])), rows, quirks);
166
175
  });
167
176
  }
168
- test('runQueryCount should return 3', async () => {
169
- expect(await dao.query().runQueryCount()).toBe(3);
177
+ (0, vitest_1.test)('runQueryCount should return 3', async () => {
178
+ (0, vitest_1.expect)(await dao.query().runQueryCount()).toBe(3);
170
179
  });
171
180
  }
172
181
  // STREAM
173
182
  if (support.streaming) {
174
- test('streamQueryForEach all', async () => {
183
+ (0, vitest_1.test)('streamQueryForEach all', async () => {
175
184
  let rows = [];
176
185
  await dao.query().streamQueryForEach(bm => void rows.push(bm));
177
186
  rows = (0, js_lib_1._sortBy)(rows, r => r.id);
178
187
  (0, dbTest_1.expectMatch)(expectedItems, rows, quirks);
179
188
  });
180
- test('streamQuery all', async () => {
189
+ (0, vitest_1.test)('streamQuery all', async () => {
181
190
  let rows = await dao.query().streamQuery().toArray();
182
191
  rows = (0, js_lib_1._sortBy)(rows, r => r.id);
183
192
  (0, dbTest_1.expectMatch)(expectedItems, rows, quirks);
184
193
  });
185
- test('streamQueryIdsForEach all', async () => {
194
+ (0, vitest_1.test)('streamQueryIdsForEach all', async () => {
186
195
  let ids = [];
187
196
  await dao.query().streamQueryIdsForEach(id => void ids.push(id));
188
197
  ids = ids.sort();
189
198
  (0, dbTest_1.expectMatch)(expectedItems.map(i => i.id), ids, quirks);
190
199
  });
191
- test('streamQueryIds all', async () => {
200
+ (0, vitest_1.test)('streamQueryIds all', async () => {
192
201
  let ids = await dao.query().streamQueryIds().toArray();
193
202
  ids = ids.sort();
194
203
  (0, dbTest_1.expectMatch)(expectedItems.map(i => i.id), ids, quirks);
195
204
  });
196
- test('streamSaveTransform', async () => {
205
+ (0, vitest_1.test)('streamSaveTransform', async () => {
197
206
  const items2 = (0, test_model_1.createTestItemsBM)(2).map(i => ({ ...i, id: i.id + '_str' }));
198
207
  const ids = items2.map(i => i.id);
199
208
  await (0, nodejs_lib_1._pipeline)([node_stream_1.Readable.from(items2), ...dao.streamSaveTransform()]);
@@ -205,18 +214,18 @@ function runCommonDaoTest(db, quirks = {}) {
205
214
  }
206
215
  // DELETE BY
207
216
  if (support.queries) {
208
- test('deleteByQuery even=false', async () => {
217
+ (0, vitest_1.test)('deleteByQuery even=false', async () => {
209
218
  const deleted = await dao.query().filter('even', '==', false).deleteByQuery();
210
- expect(deleted).toBe(items.filter(item => !item.even).length);
211
- expect(await dao.query().runQueryCount()).toBe(1);
219
+ (0, vitest_1.expect)(deleted).toBe(items.filter(item => !item.even).length);
220
+ (0, vitest_1.expect)(await dao.query().runQueryCount()).toBe(1);
212
221
  });
213
- test('cleanup', async () => {
222
+ (0, vitest_1.test)('cleanup', async () => {
214
223
  // CLEAN UP
215
224
  await dao.query().deleteByQuery();
216
225
  });
217
226
  }
218
227
  if (support.transactions) {
219
- test('transaction happy path', async () => {
228
+ (0, vitest_1.test)('transaction happy path', async () => {
220
229
  // cleanup
221
230
  await dao.query().deleteByQuery();
222
231
  // Test that id, created, updated are created
@@ -226,10 +235,10 @@ function runCommonDaoTest(db, quirks = {}) {
226
235
  await tx.save(dao, row);
227
236
  });
228
237
  const loaded = await dao.query().runQuery();
229
- expect(loaded.length).toBe(1);
230
- expect(loaded[0].id).toBeDefined();
231
- expect(loaded[0].created).toBeGreaterThanOrEqual(now);
232
- expect(loaded[0].updated).toBe(loaded[0].created);
238
+ (0, vitest_1.expect)(loaded.length).toBe(1);
239
+ (0, vitest_1.expect)(loaded[0].id).toBeDefined();
240
+ (0, vitest_1.expect)(loaded[0].created).toBeGreaterThanOrEqual(now);
241
+ (0, vitest_1.expect)(loaded[0].updated).toBe(loaded[0].created);
233
242
  await dao.runInTransaction(async (tx) => {
234
243
  await tx.deleteById(dao, loaded[0].id);
235
244
  });
@@ -246,8 +255,8 @@ function runCommonDaoTest(db, quirks = {}) {
246
255
  const expected = [items[0], { ...items[2], k1: 'k1_mod' }];
247
256
  (0, dbTest_1.expectMatch)(expected, rows, quirks);
248
257
  });
249
- test('transaction rollback', async () => {
250
- await expect(dao.runInTransaction(async (tx) => {
258
+ (0, vitest_1.test)('transaction rollback', async () => {
259
+ await (0, vitest_1.expect)(dao.runInTransaction(async (tx) => {
251
260
  await tx.deleteById(dao, items[2].id);
252
261
  await tx.save(dao, { ...items[0], k1: 5 }); // it should fail here
253
262
  })).rejects.toThrow();
@@ -256,7 +265,7 @@ function runCommonDaoTest(db, quirks = {}) {
256
265
  (0, dbTest_1.expectMatch)(expected, rows, quirks);
257
266
  });
258
267
  if (support.queries) {
259
- test('transaction cleanup', async () => {
268
+ (0, vitest_1.test)('transaction cleanup', async () => {
260
269
  await dao.query().deleteByQuery();
261
270
  });
262
271
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runCommonDBTest = runCommonDBTest;
4
4
  exports.expectMatch = expectMatch;
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
+ const vitest_1 = require("vitest");
6
7
  const common_db_1 = require("../common.db");
7
8
  const dbQuery_1 = require("../query/dbQuery");
8
9
  const test_model_1 = require("./test.model");
@@ -12,50 +13,50 @@ function runCommonDBTest(db, quirks = {}) {
12
13
  (0, js_lib_1._deepFreeze)(items);
13
14
  const item1 = items[0];
14
15
  const queryAll = () => dbQuery_1.DBQuery.create(test_model_1.TEST_TABLE);
15
- test('ping', async () => {
16
+ (0, vitest_1.test)('ping', async () => {
16
17
  await db.ping();
17
18
  });
18
19
  // CREATE TABLE, DROP
19
20
  if (support.createTable) {
20
- test('createTable, dropIfExists=true', async () => {
21
+ (0, vitest_1.test)('createTable, dropIfExists=true', async () => {
21
22
  await db.createTable(test_model_1.TEST_TABLE, test_model_1.testItemBMJsonSchema, { dropIfExists: true });
22
23
  });
23
24
  }
24
25
  if (support.queries) {
25
26
  // DELETE ALL initially
26
- test('deleteByIds test items', async () => {
27
+ (0, vitest_1.test)('deleteByIds test items', async () => {
27
28
  const { rows } = await db.runQuery(queryAll().select(['id']));
28
29
  await db.deleteByQuery(queryAll().filterIn('id', rows.map(i => i.id)));
29
30
  });
30
31
  // QUERY empty
31
- test('runQuery(all), runQueryCount should return empty', async () => {
32
- expect((await db.runQuery(queryAll())).rows).toEqual([]);
33
- expect(await db.runQueryCount(queryAll())).toBe(0);
32
+ (0, vitest_1.test)('runQuery(all), runQueryCount should return empty', async () => {
33
+ (0, vitest_1.expect)((await db.runQuery(queryAll())).rows).toEqual([]);
34
+ (0, vitest_1.expect)(await db.runQueryCount(queryAll())).toBe(0);
34
35
  });
35
36
  }
36
37
  // GET empty
37
- test('getByIds(item1.id) should return empty', async () => {
38
+ (0, vitest_1.test)('getByIds(item1.id) should return empty', async () => {
38
39
  const [item1Loaded] = await db.getByIds(test_model_1.TEST_TABLE, [item1.id]);
39
40
  // console.log(a)
40
- expect(item1Loaded).toBeUndefined();
41
+ (0, vitest_1.expect)(item1Loaded).toBeUndefined();
41
42
  });
42
- test('getByIds([]) should return []', async () => {
43
- expect(await db.getByIds(test_model_1.TEST_TABLE, [])).toEqual([]);
43
+ (0, vitest_1.test)('getByIds([]) should return []', async () => {
44
+ (0, vitest_1.expect)(await db.getByIds(test_model_1.TEST_TABLE, [])).toEqual([]);
44
45
  });
45
- test('getByIds(...) should return empty', async () => {
46
- expect(await db.getByIds(test_model_1.TEST_TABLE, ['abc', 'abcd'])).toEqual([]);
46
+ (0, vitest_1.test)('getByIds(...) should return empty', async () => {
47
+ (0, vitest_1.expect)(await db.getByIds(test_model_1.TEST_TABLE, ['abc', 'abcd'])).toEqual([]);
47
48
  });
48
49
  // TimeMachine
49
50
  if (support.timeMachine) {
50
- test('getByIds(...) 10 minutes ago should return []', async () => {
51
- expect(await db.getByIds(test_model_1.TEST_TABLE, [item1.id, 'abc'], {
51
+ (0, vitest_1.test)('getByIds(...) 10 minutes ago should return []', async () => {
52
+ (0, vitest_1.expect)(await db.getByIds(test_model_1.TEST_TABLE, [item1.id, 'abc'], {
52
53
  readAt: js_lib_1.localTime.now().minus(10, 'minute').unix,
53
54
  })).toEqual([]);
54
55
  });
55
56
  }
56
57
  // SAVE
57
58
  if (support.nullValues) {
58
- test('should allow to save and load null values', async () => {
59
+ (0, vitest_1.test)('should allow to save and load null values', async () => {
59
60
  const item3 = {
60
61
  ...(0, test_model_1.createTestItemDBM)(3),
61
62
  k2: null,
@@ -64,11 +65,11 @@ function runCommonDBTest(db, quirks = {}) {
64
65
  await db.saveBatch(test_model_1.TEST_TABLE, [item3]);
65
66
  const item3Loaded = (await db.getByIds(test_model_1.TEST_TABLE, [item3.id]))[0];
66
67
  expectMatch([item3], [item3Loaded], quirks);
67
- expect(item3Loaded.k2).toBeNull();
68
+ (0, vitest_1.expect)(item3Loaded.k2).toBeNull();
68
69
  });
69
70
  }
70
71
  if (db.dbType === common_db_1.CommonDBType.document) {
71
- test('undefined values should not be saved/loaded', async () => {
72
+ (0, vitest_1.test)('undefined values should not be saved/loaded', async () => {
72
73
  const item3 = {
73
74
  ...(0, test_model_1.createTestItemDBM)(3),
74
75
  k2: undefined,
@@ -79,45 +80,45 @@ function runCommonDBTest(db, quirks = {}) {
79
80
  await db.saveBatch(test_model_1.TEST_TABLE, [item3]);
80
81
  const item3Loaded = (await db.getByIds(test_model_1.TEST_TABLE, [item3.id]))[0];
81
82
  expectMatch([expected], [item3Loaded], quirks);
82
- expect(item3Loaded.k2).toBeUndefined();
83
- expect(Object.keys(item3Loaded)).not.toContain('k2');
83
+ (0, vitest_1.expect)(item3Loaded.k2).toBeUndefined();
84
+ (0, vitest_1.expect)(Object.keys(item3Loaded)).not.toContain('k2');
84
85
  });
85
86
  }
86
87
  if (support.updateSaveMethod) {
87
- test('saveBatch UPDATE method should throw', async () => {
88
- await expect(db.saveBatch(test_model_1.TEST_TABLE, items, { saveMethod: 'update' })).rejects.toThrow();
88
+ (0, vitest_1.test)('saveBatch UPDATE method should throw', async () => {
89
+ await (0, vitest_1.expect)(db.saveBatch(test_model_1.TEST_TABLE, items, { saveMethod: 'update' })).rejects.toThrow();
89
90
  });
90
91
  }
91
- test('saveBatch test items', async () => {
92
+ (0, vitest_1.test)('saveBatch test items', async () => {
92
93
  await db.saveBatch(test_model_1.TEST_TABLE, items);
93
94
  });
94
- test('saveBatch should throw on null id', async () => {
95
- await expect(db.saveBatch(test_model_1.TEST_TABLE, [{ ...item1, id: null }])).rejects.toThrow();
95
+ (0, vitest_1.test)('saveBatch should throw on null id', async () => {
96
+ await (0, vitest_1.expect)(db.saveBatch(test_model_1.TEST_TABLE, [{ ...item1, id: null }])).rejects.toThrow();
96
97
  });
97
98
  if (support.insertSaveMethod) {
98
- test('saveBatch INSERT method should throw', async () => {
99
- await expect(db.saveBatch(test_model_1.TEST_TABLE, items, { saveMethod: 'insert' })).rejects.toThrow();
99
+ (0, vitest_1.test)('saveBatch INSERT method should throw', async () => {
100
+ await (0, vitest_1.expect)(db.saveBatch(test_model_1.TEST_TABLE, items, { saveMethod: 'insert' })).rejects.toThrow();
100
101
  });
101
102
  }
102
103
  if (support.updateSaveMethod) {
103
- test('saveBatch UPDATE method should pass', async () => {
104
+ (0, vitest_1.test)('saveBatch UPDATE method should pass', async () => {
104
105
  await db.saveBatch(test_model_1.TEST_TABLE, items, { saveMethod: 'update' });
105
106
  });
106
107
  }
107
108
  // GET not empty
108
- test('getByIds all items', async () => {
109
+ (0, vitest_1.test)('getByIds all items', async () => {
109
110
  const rows = await db.getByIds(test_model_1.TEST_TABLE, items.map(i => i.id).concat('abcd'));
110
111
  expectMatch(items, (0, js_lib_1._sortBy)(rows, r => r.id), quirks);
111
112
  });
112
113
  // QUERY
113
114
  if (support.queries) {
114
- test('runQuery(all) should return all items', async () => {
115
+ (0, vitest_1.test)('runQuery(all) should return all items', async () => {
115
116
  let { rows } = await db.runQuery(queryAll());
116
117
  rows = (0, js_lib_1._sortBy)(rows, r => r.id); // because query doesn't specify order here
117
118
  expectMatch(items, rows, quirks);
118
119
  });
119
120
  if (support.dbQueryFilter) {
120
- test('query even=true', async () => {
121
+ (0, vitest_1.test)('query even=true', async () => {
121
122
  const q = new dbQuery_1.DBQuery(test_model_1.TEST_TABLE).filter('even', '==', true);
122
123
  let { rows } = await db.runQuery(q);
123
124
  if (!support.dbQueryOrder)
@@ -126,67 +127,67 @@ function runCommonDBTest(db, quirks = {}) {
126
127
  });
127
128
  }
128
129
  if (support.dbQueryOrder) {
129
- test('query order by k1 desc', async () => {
130
+ (0, vitest_1.test)('query order by k1 desc', async () => {
130
131
  const q = new dbQuery_1.DBQuery(test_model_1.TEST_TABLE).order('k1', true);
131
132
  const { rows } = await db.runQuery(q);
132
133
  expectMatch([...items].reverse(), rows, quirks);
133
134
  });
134
135
  }
135
136
  if (support.dbQuerySelectFields) {
136
- test('projection query with only ids', async () => {
137
+ (0, vitest_1.test)('projection query with only ids', async () => {
137
138
  const q = new dbQuery_1.DBQuery(test_model_1.TEST_TABLE).select(['id']);
138
139
  let { rows } = await db.runQuery(q);
139
140
  rows = (0, js_lib_1._sortBy)(rows, r => r.id); // cause order is not specified
140
141
  expectMatch(items.map(item => (0, js_lib_1._pick)(item, ['id'])), rows, quirks);
141
142
  });
142
- test('projection query without ids', async () => {
143
+ (0, vitest_1.test)('projection query without ids', async () => {
143
144
  const q = new dbQuery_1.DBQuery(test_model_1.TEST_TABLE).select(['k1']);
144
145
  let { rows } = await db.runQuery(q);
145
146
  rows = (0, js_lib_1._sortBy)(rows, r => r.k1); // cause order is not specified
146
147
  expectMatch(items.map(item => (0, js_lib_1._pick)(item, ['k1'])), rows, quirks);
147
148
  });
148
- test('projection query empty fields (edge case)', async () => {
149
+ (0, vitest_1.test)('projection query empty fields (edge case)', async () => {
149
150
  const q = new dbQuery_1.DBQuery(test_model_1.TEST_TABLE).select([]);
150
151
  const { rows } = await db.runQuery(q);
151
152
  expectMatch(items.map(() => ({})), rows, quirks);
152
153
  });
153
154
  }
154
- test('runQueryCount should return 3', async () => {
155
- expect(await db.runQueryCount(new dbQuery_1.DBQuery(test_model_1.TEST_TABLE))).toBe(3);
155
+ (0, vitest_1.test)('runQueryCount should return 3', async () => {
156
+ (0, vitest_1.expect)(await db.runQueryCount(new dbQuery_1.DBQuery(test_model_1.TEST_TABLE))).toBe(3);
156
157
  });
157
158
  }
158
159
  // STREAM
159
160
  if (support.streaming) {
160
- test('streamQuery all', async () => {
161
+ (0, vitest_1.test)('streamQuery all', async () => {
161
162
  let rows = await db.streamQuery(queryAll()).toArray();
162
163
  rows = (0, js_lib_1._sortBy)(rows, r => r.id); // cause order is not specified in DBQuery
163
164
  expectMatch(items, rows, quirks);
164
165
  });
165
166
  }
166
167
  // getTables
167
- test('getTables, getTableSchema (if supported)', async () => {
168
+ (0, vitest_1.test)('getTables, getTableSchema (if supported)', async () => {
168
169
  const tables = await db.getTables();
169
170
  // console.log({ tables })
170
171
  if (support.tableSchemas) {
171
172
  await (0, js_lib_1.pMap)(tables, async (table) => {
172
173
  const schema = await db.getTableSchema(table);
173
174
  // console.log(schema)
174
- expect(schema.$id).toBe(`${table}.schema.json`);
175
+ (0, vitest_1.expect)(schema.$id).toBe(`${table}.schema.json`);
175
176
  });
176
177
  }
177
178
  });
178
179
  // DELETE BY
179
180
  if (support.queries && support.dbQueryFilter) {
180
- test('deleteByQuery even=false', async () => {
181
+ (0, vitest_1.test)('deleteByQuery even=false', async () => {
181
182
  const q = new dbQuery_1.DBQuery(test_model_1.TEST_TABLE).filter('even', '==', false);
182
183
  const deleted = await db.deleteByQuery(q);
183
- expect(deleted).toBe(items.filter(item => !item.even).length);
184
- expect(await db.runQueryCount(queryAll())).toBe(1);
184
+ (0, vitest_1.expect)(deleted).toBe(items.filter(item => !item.even).length);
185
+ (0, vitest_1.expect)(await db.runQueryCount(queryAll())).toBe(1);
185
186
  });
186
187
  }
187
188
  // BUFFER
188
189
  if (support.bufferValues) {
189
- test('buffer values', async () => {
190
+ (0, vitest_1.test)('buffer values', async () => {
190
191
  const s = 'helloWorld 1';
191
192
  const b1 = Buffer.from(s);
192
193
  const item = {
@@ -204,12 +205,12 @@ function runCommonDBTest(db, quirks = {}) {
204
205
  // b1,
205
206
  // b1Loaded,
206
207
  // })
207
- expect(b1Loaded).toEqual(b1);
208
- expect(b1Loaded.toString()).toBe(s);
208
+ (0, vitest_1.expect)(b1Loaded).toEqual(b1);
209
+ (0, vitest_1.expect)(b1Loaded.toString()).toBe(s);
209
210
  });
210
211
  }
211
212
  if (support.transactions) {
212
- test('transaction happy path', async () => {
213
+ (0, vitest_1.test)('transaction happy path', async () => {
213
214
  // cleanup
214
215
  await db.deleteByQuery(queryAll());
215
216
  // saveBatch [item1, 2, 3]
@@ -225,7 +226,7 @@ function runCommonDBTest(db, quirks = {}) {
225
226
  const expected = [items[0], { ...items[2], k1: 'k1_mod' }];
226
227
  expectMatch(expected, rows, quirks);
227
228
  });
228
- test('transaction rollback', async () => {
229
+ (0, vitest_1.test)('transaction rollback', async () => {
229
230
  let err;
230
231
  try {
231
232
  await db.runInTransaction(async (tx) => {
@@ -237,14 +238,14 @@ function runCommonDBTest(db, quirks = {}) {
237
238
  catch (err_) {
238
239
  err = err_;
239
240
  }
240
- expect(err).toBeDefined();
241
+ (0, vitest_1.expect)(err).toBeDefined();
241
242
  const { rows } = await db.runQuery(queryAll());
242
243
  const expected = [items[0], { ...items[2], k1: 'k1_mod' }];
243
244
  expectMatch(expected, rows, quirks);
244
245
  });
245
246
  }
246
247
  if (support.patchByQuery) {
247
- test('patchByQuery', async () => {
248
+ (0, vitest_1.test)('patchByQuery', async () => {
248
249
  // cleanup, reset initial data
249
250
  await db.deleteByQuery(queryAll());
250
251
  await db.saveBatch(test_model_1.TEST_TABLE, items);
@@ -264,7 +265,7 @@ function runCommonDBTest(db, quirks = {}) {
264
265
  });
265
266
  }
266
267
  if (support.increment) {
267
- test('incrementBatch', async () => {
268
+ (0, vitest_1.test)('incrementBatch', async () => {
268
269
  // cleanup, reset initial data
269
270
  await db.deleteByQuery(queryAll());
270
271
  await db.saveBatch(test_model_1.TEST_TABLE, items);
@@ -283,7 +284,7 @@ function runCommonDBTest(db, quirks = {}) {
283
284
  });
284
285
  }
285
286
  if (support.queries) {
286
- test('cleanup', async () => {
287
+ (0, vitest_1.test)('cleanup', async () => {
287
288
  // CLEAN UP
288
289
  await db.deleteByQuery(queryAll());
289
290
  });
@@ -298,9 +299,9 @@ function expectMatch(expected, actual, quirks) {
298
299
  });
299
300
  }
300
301
  if (quirks.allowExtraPropertiesInResponse) {
301
- expect(actual).toMatchObject(expected);
302
+ (0, vitest_1.expect)(actual).toMatchObject(expected);
302
303
  }
303
304
  else {
304
- expect(actual).toEqual(expected);
305
+ (0, vitest_1.expect)(actual).toEqual(expected);
305
306
  }
306
307
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runCommonKeyValueDBTest = runCommonKeyValueDBTest;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
+ const vitest_1 = require("vitest");
5
6
  const test_model_1 = require("./test.model");
6
7
  const testIds = (0, js_lib_1._range)(1, 4).map(n => `id${n}`);
7
8
  const testEntries = testIds.map(id => [
@@ -9,7 +10,7 @@ const testEntries = testIds.map(id => [
9
10
  Buffer.from(`${id}value`),
10
11
  ]);
11
12
  function runCommonKeyValueDBTest(db) {
12
- beforeAll(async () => {
13
+ (0, vitest_1.beforeAll)(async () => {
13
14
  // Tests in this suite are not isolated,
14
15
  // and failing tests can leave the DB in an unexpected state for other tests,
15
16
  // including the following test run.
@@ -17,98 +18,98 @@ function runCommonKeyValueDBTest(db) {
17
18
  const ids = await db.streamIds(test_model_1.TEST_TABLE).toArray();
18
19
  await db.deleteByIds(test_model_1.TEST_TABLE, ids);
19
20
  });
20
- afterAll(async () => {
21
+ (0, vitest_1.afterAll)(async () => {
21
22
  const ids = await db.streamIds(test_model_1.TEST_TABLE).toArray();
22
23
  await db.deleteByIds(test_model_1.TEST_TABLE, ids);
23
24
  });
24
25
  const { support } = db;
25
- test('ping', async () => {
26
+ (0, vitest_1.test)('ping', async () => {
26
27
  await db.ping();
27
28
  });
28
- test('createTable', async () => {
29
+ (0, vitest_1.test)('createTable', async () => {
29
30
  await db.createTable(test_model_1.TEST_TABLE, { dropIfExists: true });
30
31
  });
31
- test('deleteByIds non existing', async () => {
32
+ (0, vitest_1.test)('deleteByIds non existing', async () => {
32
33
  await db.deleteByIds(test_model_1.TEST_TABLE, testIds);
33
34
  });
34
- test('getByIds should return empty', async () => {
35
+ (0, vitest_1.test)('getByIds should return empty', async () => {
35
36
  const results = await db.getByIds(test_model_1.TEST_TABLE, testIds);
36
- expect(results).toEqual([]);
37
+ (0, vitest_1.expect)(results).toEqual([]);
37
38
  });
38
- test('count should be 0', async () => {
39
- expect(await db.count(test_model_1.TEST_TABLE)).toBe(0);
39
+ (0, vitest_1.test)('count should be 0', async () => {
40
+ (0, vitest_1.expect)(await db.count(test_model_1.TEST_TABLE)).toBe(0);
40
41
  });
41
- test('saveBatch, then getByIds', async () => {
42
+ (0, vitest_1.test)('saveBatch, then getByIds', async () => {
42
43
  await db.saveBatch(test_model_1.TEST_TABLE, testEntries);
43
44
  const entries = await db.getByIds(test_model_1.TEST_TABLE, testIds);
44
45
  (0, js_lib_1._sortBy)(entries, e => e[0], true);
45
- expect(entries).toEqual(testEntries);
46
+ (0, vitest_1.expect)(entries).toEqual(testEntries);
46
47
  });
47
48
  if (support.count) {
48
- test('count should be 3', async () => {
49
- expect(await db.count(test_model_1.TEST_TABLE)).toBe(3);
49
+ (0, vitest_1.test)('count should be 3', async () => {
50
+ (0, vitest_1.expect)(await db.count(test_model_1.TEST_TABLE)).toBe(3);
50
51
  });
51
52
  }
52
- test('streamIds', async () => {
53
+ (0, vitest_1.test)('streamIds', async () => {
53
54
  const ids = await db.streamIds(test_model_1.TEST_TABLE).toArray();
54
55
  ids.sort();
55
- expect(ids).toEqual(testIds);
56
+ (0, vitest_1.expect)(ids).toEqual(testIds);
56
57
  });
57
- test('streamIds limited', async () => {
58
+ (0, vitest_1.test)('streamIds limited', async () => {
58
59
  const idsLimited = await db.streamIds(test_model_1.TEST_TABLE, 2).toArray();
59
60
  // Order is non-deterministic, so, cannot compare values
60
61
  // idsLimited.sort()
61
62
  // expect(idsLimited).toEqual(testIds.slice(0, 2))
62
- expect(idsLimited.length).toBe(2);
63
+ (0, vitest_1.expect)(idsLimited.length).toBe(2);
63
64
  });
64
- test('streamValues', async () => {
65
+ (0, vitest_1.test)('streamValues', async () => {
65
66
  const values = await db.streamValues(test_model_1.TEST_TABLE).toArray();
66
67
  values.sort();
67
- expect(values).toEqual(testEntries.map(e => e[1]));
68
+ (0, vitest_1.expect)(values).toEqual(testEntries.map(e => e[1]));
68
69
  });
69
- test('streamValues limited', async () => {
70
+ (0, vitest_1.test)('streamValues limited', async () => {
70
71
  const valuesLimited = await db.streamValues(test_model_1.TEST_TABLE, 2).toArray();
71
72
  // valuesLimited.sort()
72
73
  // expect(valuesLimited).toEqual(testEntries.map(e => e[1]).slice(0, 2))
73
- expect(valuesLimited.length).toBe(2);
74
+ (0, vitest_1.expect)(valuesLimited.length).toBe(2);
74
75
  });
75
- test('streamEntries', async () => {
76
+ (0, vitest_1.test)('streamEntries', async () => {
76
77
  const entries = await db.streamEntries(test_model_1.TEST_TABLE).toArray();
77
78
  entries.sort();
78
- expect(entries).toEqual(testEntries);
79
+ (0, vitest_1.expect)(entries).toEqual(testEntries);
79
80
  });
80
- test('streamEntries limited', async () => {
81
+ (0, vitest_1.test)('streamEntries limited', async () => {
81
82
  const entriesLimited = await db.streamEntries(test_model_1.TEST_TABLE, 2).toArray();
82
83
  // entriesLimited.sort()
83
84
  // expect(entriesLimited).toEqual(testEntries.slice(0, 2))
84
- expect(entriesLimited.length).toBe(2);
85
+ (0, vitest_1.expect)(entriesLimited.length).toBe(2);
85
86
  });
86
- test('deleteByIds should clear', async () => {
87
+ (0, vitest_1.test)('deleteByIds should clear', async () => {
87
88
  await db.deleteByIds(test_model_1.TEST_TABLE, testIds);
88
89
  const results = await db.getByIds(test_model_1.TEST_TABLE, testIds);
89
- expect(results).toEqual([]);
90
+ (0, vitest_1.expect)(results).toEqual([]);
90
91
  });
91
92
  if (support.increment) {
92
93
  const id = 'nonExistingField';
93
94
  const id2 = 'nonExistingField2';
94
- test('increment on a non-existing field should set the value to 1', async () => {
95
+ (0, vitest_1.test)('increment on a non-existing field should set the value to 1', async () => {
95
96
  const result = await db.incrementBatch(test_model_1.TEST_TABLE, [[id, 1]]);
96
- expect(result).toEqual([[id, 1]]);
97
+ (0, vitest_1.expect)(result).toEqual([[id, 1]]);
97
98
  });
98
- test('increment on a existing field should increase the value by one', async () => {
99
+ (0, vitest_1.test)('increment on a existing field should increase the value by one', async () => {
99
100
  const result = await db.incrementBatch(test_model_1.TEST_TABLE, [[id, 1]]);
100
- expect(result).toEqual([[id, 2]]);
101
+ (0, vitest_1.expect)(result).toEqual([[id, 2]]);
101
102
  });
102
- test('increment should increase the value by the specified amount', async () => {
103
+ (0, vitest_1.test)('increment should increase the value by the specified amount', async () => {
103
104
  const result = await db.incrementBatch(test_model_1.TEST_TABLE, [[id, 2]]);
104
- expect(result).toEqual([[id, 4]]);
105
+ (0, vitest_1.expect)(result).toEqual([[id, 4]]);
105
106
  });
106
- test('increment 2 ids at the same time', async () => {
107
+ (0, vitest_1.test)('increment 2 ids at the same time', async () => {
107
108
  const result = await db.incrementBatch(test_model_1.TEST_TABLE, [
108
109
  [id, 1],
109
110
  [id2, 2],
110
111
  ]);
111
- expect(Object.fromEntries(result)).toEqual({
112
+ (0, vitest_1.expect)(Object.fromEntries(result)).toEqual({
112
113
  [id]: 5,
113
114
  [id2]: 2,
114
115
  });
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runCommonKeyValueDaoTest = runCommonKeyValueDaoTest;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
+ const vitest_1 = require("vitest");
5
6
  const commonKeyValueDao_1 = require("../kv/commonKeyValueDao");
6
7
  const test_model_1 = require("./test.model");
7
8
  const testItems = (0, test_model_1.createTestItemsBM)(4);
@@ -14,7 +15,7 @@ function runCommonKeyValueDaoTest(db) {
14
15
  // todo: make this test support "deflatedJson" transformer
15
16
  });
16
17
  const { support } = db;
17
- beforeAll(async () => {
18
+ (0, vitest_1.beforeAll)(async () => {
18
19
  // Tests in this suite are not isolated,
19
20
  // and failing tests can leave the DB in an unexpected state for other tests,
20
21
  // including the following test run.
@@ -22,92 +23,92 @@ function runCommonKeyValueDaoTest(db) {
22
23
  const ids = await dao.streamIds().toArray();
23
24
  await dao.deleteByIds(ids);
24
25
  });
25
- afterAll(async () => {
26
+ (0, vitest_1.afterAll)(async () => {
26
27
  const ids = await dao.streamIds().toArray();
27
28
  await dao.deleteByIds(ids);
28
29
  });
29
- test('ping', async () => {
30
+ (0, vitest_1.test)('ping', async () => {
30
31
  await dao.ping();
31
32
  });
32
- test('createTable', async () => {
33
+ (0, vitest_1.test)('createTable', async () => {
33
34
  await dao.createTable({ dropIfExists: true });
34
35
  });
35
- test('deleteByIds non existing', async () => {
36
+ (0, vitest_1.test)('deleteByIds non existing', async () => {
36
37
  await dao.deleteByIds(testIds);
37
38
  });
38
- test('getByIds should return empty', async () => {
39
+ (0, vitest_1.test)('getByIds should return empty', async () => {
39
40
  const results = await dao.getByIds(testIds);
40
- expect(results).toEqual([]);
41
+ (0, vitest_1.expect)(results).toEqual([]);
41
42
  });
42
- test('saveBatch, then getByIds', async () => {
43
+ (0, vitest_1.test)('saveBatch, then getByIds', async () => {
43
44
  await dao.saveBatch(testEntries);
44
45
  const entries = await dao.getByIds(testIds);
45
46
  // console.log(typeof entries[0]![1], entries[0]![1])
46
47
  (0, js_lib_1._sortBy)(entries, e => e[0], true);
47
- expect(entries).toEqual(testEntries); // Jest doesn't allow to compare Buffers directly
48
+ (0, vitest_1.expect)(entries).toEqual(testEntries); // Jest doesn't allow to compare Buffers directly
48
49
  // expect(entries.map(e => e[0])).toEqual(testEntries.map(e => e[0]))
49
50
  // expect(entries.map(e => e[1].toString())).toEqual(testEntries.map(e => e[1].toString()))
50
51
  });
51
- test('streamIds', async () => {
52
+ (0, vitest_1.test)('streamIds', async () => {
52
53
  const ids = await dao.streamIds().toArray();
53
54
  ids.sort();
54
- expect(ids).toEqual(testIds);
55
+ (0, vitest_1.expect)(ids).toEqual(testIds);
55
56
  });
56
- test('streamIds limited', async () => {
57
+ (0, vitest_1.test)('streamIds limited', async () => {
57
58
  const idsLimited = await dao.streamIds(2).toArray();
58
59
  // Order is non-deterministic, so, cannot compare values
59
60
  // idsLimited.sort()
60
61
  // expect(idsLimited).toEqual(testIds.slice(0, 2))
61
- expect(idsLimited.length).toBe(2);
62
+ (0, vitest_1.expect)(idsLimited.length).toBe(2);
62
63
  });
63
- test('streamValues', async () => {
64
+ (0, vitest_1.test)('streamValues', async () => {
64
65
  const values = await dao.streamValues().toArray();
65
66
  values.sort();
66
- expect(values).toEqual(testEntries.map(e => e[1]));
67
+ (0, vitest_1.expect)(values).toEqual(testEntries.map(e => e[1]));
67
68
  });
68
- test('streamValues limited', async () => {
69
+ (0, vitest_1.test)('streamValues limited', async () => {
69
70
  const valuesLimited = await dao.streamValues(2).toArray();
70
71
  // valuesLimited.sort()
71
72
  // expect(valuesLimited).toEqual(testEntries.map(e => e[1]).slice(0, 2))
72
- expect(valuesLimited.length).toBe(2);
73
+ (0, vitest_1.expect)(valuesLimited.length).toBe(2);
73
74
  });
74
- test('streamEntries', async () => {
75
+ (0, vitest_1.test)('streamEntries', async () => {
75
76
  const entries = await dao.streamEntries().toArray();
76
77
  entries.sort();
77
- expect(entries).toEqual(testEntries);
78
+ (0, vitest_1.expect)(entries).toEqual(testEntries);
78
79
  });
79
- test('streamEntries limited', async () => {
80
+ (0, vitest_1.test)('streamEntries limited', async () => {
80
81
  const entriesLimited = await dao.streamEntries(2).toArray();
81
82
  // entriesLimited.sort()
82
83
  // expect(entriesLimited).toEqual(testEntries.slice(0, 2))
83
- expect(entriesLimited.length).toBe(2);
84
+ (0, vitest_1.expect)(entriesLimited.length).toBe(2);
84
85
  });
85
- test('deleteByIds should clear', async () => {
86
+ (0, vitest_1.test)('deleteByIds should clear', async () => {
86
87
  await dao.deleteByIds(testIds);
87
88
  const results = await dao.getByIds(testIds);
88
- expect(results).toEqual([]);
89
+ (0, vitest_1.expect)(results).toEqual([]);
89
90
  });
90
91
  if (support.increment) {
91
92
  const id = 'nonExistingField';
92
93
  const id2 = 'nonExistingField2';
93
- test('increment on a non-existing field should set the value to 1', async () => {
94
+ (0, vitest_1.test)('increment on a non-existing field should set the value to 1', async () => {
94
95
  const result = await dao.increment(id);
95
- expect(result).toBe(1);
96
+ (0, vitest_1.expect)(result).toBe(1);
96
97
  });
97
- test('increment on a existing field should increase the value by one', async () => {
98
+ (0, vitest_1.test)('increment on a existing field should increase the value by one', async () => {
98
99
  const result = await dao.increment(id);
99
- expect(result).toBe(2);
100
+ (0, vitest_1.expect)(result).toBe(2);
100
101
  });
101
- test('increment should increase the value by the specified amount', async () => {
102
+ (0, vitest_1.test)('increment should increase the value by the specified amount', async () => {
102
103
  const result = await dao.increment(id, 2);
103
- expect(result).toBe(4);
104
+ (0, vitest_1.expect)(result).toBe(4);
104
105
  });
105
- test('increment 2 ids at the same time', async () => {
106
+ (0, vitest_1.test)('increment 2 ids at the same time', async () => {
106
107
  const result = await dao.incrementBatch([
107
108
  [id, 1],
108
109
  [id2, 2],
109
110
  ]);
110
- expect(Object.fromEntries(result)).toEqual({
111
+ (0, vitest_1.expect)(Object.fromEntries(result)).toEqual({
111
112
  [id]: 5,
112
113
  [id2]: 2,
113
114
  });
@@ -6,6 +6,9 @@ export interface TestItemBM extends BaseDBEntity {
6
6
  k3?: number;
7
7
  even?: boolean;
8
8
  b1?: Buffer;
9
+ nested?: {
10
+ foo: number;
11
+ };
9
12
  }
10
13
  export interface TestItemDBM extends TestItemBM {
11
14
  }
@@ -15,6 +15,9 @@ exports.testItemBMSchema = (0, nodejs_lib_1.objectSchema)({
15
15
  k3: nodejs_lib_1.numberSchema.optional(),
16
16
  even: nodejs_lib_1.booleanSchema.optional(),
17
17
  b1: nodejs_lib_1.binarySchema.optional(),
18
+ nested: (0, nodejs_lib_1.objectSchema)({
19
+ foo: nodejs_lib_1.numberSchema,
20
+ }).optional(),
18
21
  }).concat(nodejs_lib_1.baseDBEntitySchema);
19
22
  exports.testItemTMSchema = (0, nodejs_lib_1.objectSchema)({
20
23
  k1: nodejs_lib_1.stringSchema,
@@ -41,6 +44,7 @@ function createTestItemDBM(num = 1) {
41
44
  k2: `v${num * 2}`,
42
45
  k3: num,
43
46
  even: num % 2 === 0,
47
+ nested: { foo: num },
44
48
  created: MOCK_TS_2018_06_21,
45
49
  updated: MOCK_TS_2018_06_21,
46
50
  };
package/package.json CHANGED
@@ -14,9 +14,10 @@
14
14
  },
15
15
  "devDependencies": {
16
16
  "@naturalcycles/bench-lib": "^3",
17
- "@naturalcycles/dev-lib": "^15",
17
+ "@naturalcycles/dev-lib": "^16",
18
18
  "@types/node": "^22",
19
- "jest": "^29"
19
+ "@vitest/coverage-v8": "^3",
20
+ "vitest": "^3"
20
21
  },
21
22
  "files": [
22
23
  "dist",
@@ -43,9 +44,9 @@
43
44
  "url": "https://github.com/NaturalCycles/db-lib"
44
45
  },
45
46
  "engines": {
46
- "node": ">=22.10.0"
47
+ "node": ">=22.12.0"
47
48
  },
48
- "version": "9.27.0",
49
+ "version": "10.0.0",
49
50
  "description": "Lowest Common Denominator API to supported Databases",
50
51
  "keywords": [
51
52
  "db",
@@ -1,4 +1,4 @@
1
- import { _pick, ObjectWithId } from '@naturalcycles/js-lib'
1
+ import { _get, _pick, ObjectWithId } from '@naturalcycles/js-lib'
2
2
  import { DBQuery, DBQueryFilterOperator } from '../../query/dbQuery'
3
3
 
4
4
  type FilterFn = (v: any, val: any) => boolean
@@ -22,7 +22,10 @@ export function queryInMemory<ROW extends ObjectWithId>(q: DBQuery<ROW>, rows: R
22
22
  // .filter
23
23
  // eslint-disable-next-line unicorn/no-array-reduce
24
24
  rows = q._filters.reduce((rows, filter) => {
25
- return rows.filter(row => FILTER_FNS[filter.op](row[filter.name], filter.val))
25
+ return rows.filter(row => {
26
+ const value = _get(row, filter.name as string)
27
+ return FILTER_FNS[filter.op](value, filter.val)
28
+ })
26
29
  }, rows)
27
30
 
28
31
  // .select(fieldNames)
@@ -1,6 +1,7 @@
1
1
  import { Readable } from 'node:stream'
2
2
  import { _deepCopy, _omit, _pick, _sortBy, localTime } from '@naturalcycles/js-lib'
3
3
  import { _pipeline } from '@naturalcycles/nodejs-lib'
4
+ import { expect, test } from 'vitest'
4
5
  import { CommonDaoLogLevel, DBQuery } from '..'
5
6
  import { CommonDB } from '../common.db'
6
7
  import { CommonDao } from '../commondao/common.dao'
@@ -196,6 +197,19 @@ export function runCommonDaoTest(db: CommonDB, quirks: CommonDBImplementationQui
196
197
  quirks,
197
198
  )
198
199
  })
200
+
201
+ test('query nested property', async () => {
202
+ let rows = await dao
203
+ .query()
204
+ .filter('nested.foo' as any, '==', 1)
205
+ .runQuery()
206
+ rows = _sortBy(rows, r => r.id)
207
+ expectMatch(
208
+ expectedItems.filter(i => i.nested?.foo === 1),
209
+ rows,
210
+ quirks,
211
+ )
212
+ })
199
213
  }
200
214
 
201
215
  if (support.dbQueryOrder) {
@@ -1,4 +1,5 @@
1
1
  import { _deepFreeze, _filterObject, _pick, _sortBy, localTime, pMap } from '@naturalcycles/js-lib'
2
+ import { expect, test } from 'vitest'
2
3
  import { CommonDB, CommonDBType } from '../common.db'
3
4
  import { DBQuery } from '../query/dbQuery'
4
5
  import {
@@ -1,4 +1,5 @@
1
1
  import { _range, _sortBy, KeyValueTuple } from '@naturalcycles/js-lib'
2
+ import { afterAll, beforeAll, expect, test } from 'vitest'
2
3
  import { CommonKeyValueDB } from '../kv/commonKeyValueDB'
3
4
  import { TEST_TABLE } from './test.model'
4
5
 
@@ -1,4 +1,5 @@
1
1
  import { _sortBy } from '@naturalcycles/js-lib'
2
+ import { afterAll, beforeAll, expect, test } from 'vitest'
2
3
  import { CommonKeyValueDao } from '../kv/commonKeyValueDao'
3
4
  import { CommonKeyValueDB, KeyValueDBTuple } from '../kv/commonKeyValueDB'
4
5
  import { createTestItemsBM, TEST_TABLE } from './test.model'
@@ -24,6 +24,9 @@ export interface TestItemBM extends BaseDBEntity {
24
24
  k3?: number
25
25
  even?: boolean
26
26
  b1?: Buffer
27
+ nested?: {
28
+ foo: number
29
+ }
27
30
  }
28
31
 
29
32
  export interface TestItemDBM extends TestItemBM {}
@@ -39,6 +42,9 @@ export const testItemBMSchema = objectSchema<TestItemBM>({
39
42
  k3: numberSchema.optional(),
40
43
  even: booleanSchema.optional(),
41
44
  b1: binarySchema.optional(),
45
+ nested: objectSchema({
46
+ foo: numberSchema,
47
+ }).optional(),
42
48
  }).concat(baseDBEntitySchema as any)
43
49
 
44
50
  export const testItemTMSchema = objectSchema<TestItemTM>({
@@ -68,6 +74,7 @@ export function createTestItemDBM(num = 1): TestItemDBM {
68
74
  k2: `v${num * 2}`,
69
75
  k3: num,
70
76
  even: num % 2 === 0,
77
+ nested: { foo: num },
71
78
  created: MOCK_TS_2018_06_21,
72
79
  updated: MOCK_TS_2018_06_21,
73
80
  }