@naturalcycles/db-lib 8.11.0 → 8.13.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/adapter/cachedb/cache.db.d.ts +3 -3
  3. package/dist/adapter/cachedb/cache.db.js +4 -4
  4. package/dist/adapter/file/file.db.d.ts +2 -2
  5. package/dist/adapter/file/file.db.js +20 -18
  6. package/dist/adapter/file/inMemory.persistence.plugin.js +1 -1
  7. package/dist/adapter/file/localFile.persistence.plugin.js +9 -9
  8. package/dist/adapter/inmemory/inMemory.db.d.ts +3 -4
  9. package/dist/adapter/inmemory/inMemory.db.js +25 -23
  10. package/dist/adapter/inmemory/queryInMemory.js +1 -1
  11. package/dist/base.common.db.d.ts +3 -3
  12. package/dist/base.common.db.js +10 -4
  13. package/dist/common.db.d.ts +3 -3
  14. package/dist/commondao/common.dao.d.ts +7 -7
  15. package/dist/commondao/common.dao.js +56 -48
  16. package/dist/commondao/common.dao.model.d.ts +20 -27
  17. package/dist/db.model.js +2 -2
  18. package/dist/getDB.js +3 -3
  19. package/dist/index.d.ts +2 -4
  20. package/dist/index.js +1 -5
  21. package/dist/kv/commonKeyValueDao.js +4 -4
  22. package/dist/model.util.js +2 -2
  23. package/dist/pipeline/dbPipelineBackup.d.ts +0 -1
  24. package/dist/pipeline/dbPipelineBackup.js +14 -25
  25. package/dist/pipeline/dbPipelineCopy.js +11 -11
  26. package/dist/pipeline/dbPipelineRestore.js +20 -20
  27. package/dist/query/dbQuery.js +2 -2
  28. package/dist/testing/daoTest.js +23 -23
  29. package/dist/testing/dbTest.js +17 -17
  30. package/dist/testing/keyValueDBTest.js +18 -14
  31. package/dist/testing/keyValueDaoTest.js +18 -14
  32. package/dist/testing/test.model.d.ts +4 -2
  33. package/dist/testing/test.model.js +39 -8
  34. package/dist/testing/timeSeriesTest.util.js +1 -1
  35. package/dist/transaction/dbTransaction.util.js +2 -2
  36. package/dist/validation/index.js +9 -9
  37. package/package.json +1 -1
  38. package/readme.md +5 -4
  39. package/src/adapter/cachedb/cache.db.ts +9 -5
  40. package/src/adapter/file/file.db.ts +7 -4
  41. package/src/adapter/inmemory/inMemory.db.ts +20 -7
  42. package/src/base.common.db.ts +10 -4
  43. package/src/common.db.ts +3 -3
  44. package/src/commondao/common.dao.model.ts +24 -29
  45. package/src/commondao/common.dao.ts +35 -24
  46. package/src/index.ts +0 -7
  47. package/src/pipeline/dbPipelineBackup.ts +2 -15
  48. package/src/pipeline/dbPipelineRestore.ts +1 -1
  49. package/src/testing/dbTest.ts +1 -1
  50. package/src/testing/keyValueDBTest.ts +10 -6
  51. package/src/testing/keyValueDaoTest.ts +10 -6
  52. package/src/testing/test.model.ts +38 -4
  53. package/dist/schema/common.schema.d.ts +0 -38
  54. package/dist/schema/common.schema.js +0 -18
  55. package/dist/schema/commonSchemaGenerator.d.ts +0 -35
  56. package/dist/schema/commonSchemaGenerator.js +0 -151
  57. package/src/schema/common.schema.ts +0 -49
  58. package/src/schema/commonSchemaGenerator.ts +0 -200
@@ -15,14 +15,14 @@ const dbQuery_1 = require("../query/dbQuery");
15
15
  async function dbPipelineCopy(opt) {
16
16
  const { batchSize = 100, dbInput, dbOutput, concurrency = 16, limit = 0, sinceUpdated, mapperPerTable = {}, saveOptionsPerTable = {}, transformMapOptions, errorMode = js_lib_1.ErrorMode.SUPPRESS, } = opt;
17
17
  let { tables } = opt;
18
- const sinceUpdatedStr = sinceUpdated ? ' since ' + colors_1.grey(time_lib_1.dayjs.unix(sinceUpdated).toPretty()) : '';
19
- console.log(`>> ${colors_1.dimWhite('dbPipelineCopy')} started...${sinceUpdatedStr}`);
18
+ const sinceUpdatedStr = sinceUpdated ? ' since ' + (0, colors_1.grey)(time_lib_1.dayjs.unix(sinceUpdated).toPretty()) : '';
19
+ console.log(`>> ${(0, colors_1.dimWhite)('dbPipelineCopy')} started...${sinceUpdatedStr}`);
20
20
  if (!tables) {
21
21
  tables = await dbInput.getTables();
22
22
  }
23
- console.log(`${colors_1.yellow(tables.length)} ${colors_1.boldWhite('table(s)')}:\n` + tables.join('\n'));
23
+ console.log(`${(0, colors_1.yellow)(tables.length)} ${(0, colors_1.boldWhite)('table(s)')}:\n` + tables.join('\n'));
24
24
  const statsPerTable = {};
25
- await js_lib_1.pMap(tables, async (table) => {
25
+ await (0, js_lib_1.pMap)(tables, async (table) => {
26
26
  let q = dbQuery_1.DBQuery.create(table).limit(limit);
27
27
  if (sinceUpdated) {
28
28
  q = q.filter('updated', '>=', sinceUpdated);
@@ -32,22 +32,22 @@ async function dbPipelineCopy(opt) {
32
32
  const stream = dbInput.streamQuery(q);
33
33
  const started = Date.now();
34
34
  let rows = 0;
35
- await nodejs_lib_1._pipeline([
35
+ await (0, nodejs_lib_1._pipeline)([
36
36
  stream,
37
- nodejs_lib_1.transformLogProgress({
37
+ (0, nodejs_lib_1.transformLogProgress)({
38
38
  logEvery: 1000,
39
39
  ...opt,
40
40
  metric: table,
41
41
  }),
42
- nodejs_lib_1.transformMap(mapper, {
42
+ (0, nodejs_lib_1.transformMap)(mapper, {
43
43
  errorMode,
44
44
  flattenArrayOutput: true,
45
45
  ...transformMapOptions,
46
46
  metric: table,
47
47
  }),
48
- nodejs_lib_1.transformTap(() => rows++),
49
- nodejs_lib_1.transformBuffer({ batchSize }),
50
- nodejs_lib_1.writableForEach(async (dbms) => {
48
+ (0, nodejs_lib_1.transformTap)(() => rows++),
49
+ (0, nodejs_lib_1.transformBuffer)({ batchSize }),
50
+ (0, nodejs_lib_1.writableForEach)(async (dbms) => {
51
51
  await dbOutput.saveBatch(table, dbms, saveOptions);
52
52
  }),
53
53
  ]);
@@ -56,7 +56,7 @@ async function dbPipelineCopy(opt) {
56
56
  rows,
57
57
  sizeBytes: 0, // n/a
58
58
  });
59
- console.log(`>> ${colors_1.grey(table)}\n` + stats.toPretty());
59
+ console.log(`>> ${(0, colors_1.grey)(table)}\n` + stats.toPretty());
60
60
  statsPerTable[table] = stats;
61
61
  }, { concurrency, errorMode });
62
62
  const statsTotal = nodejs_lib_1.NDJsonStats.createCombined(Object.values(statsPerTable));
@@ -18,8 +18,8 @@ async function dbPipelineRestore(opt) {
18
18
  const { db, concurrency = 16, batchSize = 100, limit, sinceUpdated, inputDirPath, mapperPerTable = {}, saveOptionsPerTable = {}, transformMapOptions, errorMode = js_lib_1.ErrorMode.SUPPRESS, recreateTables = false, } = opt;
19
19
  const strict = errorMode !== js_lib_1.ErrorMode.SUPPRESS;
20
20
  const onlyTables = opt.tables && new Set(opt.tables);
21
- const sinceUpdatedStr = sinceUpdated ? ' since ' + colors_1.grey(time_lib_1.dayjs.unix(sinceUpdated).toPretty()) : '';
22
- console.log(`>> ${colors_1.dimWhite('dbPipelineRestore')} started in ${colors_1.grey(inputDirPath)}...${sinceUpdatedStr}`);
21
+ const sinceUpdatedStr = sinceUpdated ? ' since ' + (0, colors_1.grey)(time_lib_1.dayjs.unix(sinceUpdated).toPretty()) : '';
22
+ console.log(`>> ${(0, colors_1.dimWhite)('dbPipelineRestore')} started in ${(0, colors_1.grey)(inputDirPath)}...${sinceUpdatedStr}`);
23
23
  fs.ensureDirSync(inputDirPath);
24
24
  const tablesToGzip = new Set();
25
25
  const sizeByTable = {};
@@ -45,51 +45,51 @@ async function dbPipelineRestore(opt) {
45
45
  tablesToGzip.add(table);
46
46
  sizeByTable[table] = fs.statSync(`${inputDirPath}/${f}`).size;
47
47
  });
48
- const sizeStrByTable = js_lib_1._mapValues(sizeByTable, (_k, b) => js_lib_1._hb(b));
49
- console.log(`${colors_1.yellow(tables.length)} ${colors_1.boldWhite('table(s)')}:\n`, sizeStrByTable);
48
+ const sizeStrByTable = (0, js_lib_1._mapValues)(sizeByTable, (_k, b) => (0, js_lib_1._hb)(b));
49
+ console.log(`${(0, colors_1.yellow)(tables.length)} ${(0, colors_1.boldWhite)('table(s)')}:\n`, sizeStrByTable);
50
50
  // const schemaByTable: Record<string, CommonSchema> = {}
51
51
  if (recreateTables) {
52
- await js_lib_1.pMap(tables, async (table) => {
52
+ await (0, js_lib_1.pMap)(tables, async (table) => {
53
53
  const schemaFilePath = `${inputDirPath}/${table}.schema.json`;
54
54
  if (!fs.existsSync(schemaFilePath)) {
55
55
  console.warn(`${schemaFilePath} does not exist!`);
56
56
  return;
57
57
  }
58
58
  const schema = await fs.readJson(schemaFilePath);
59
- await db.createTable(schema, { dropIfExists: true });
59
+ await db.createTable(table, schema, { dropIfExists: true });
60
60
  });
61
61
  }
62
- await js_lib_1.pMap(tables, async (table) => {
62
+ await (0, js_lib_1.pMap)(tables, async (table) => {
63
63
  const gzip = tablesToGzip.has(table);
64
64
  const filePath = `${inputDirPath}/${table}.ndjson` + (gzip ? '.gz' : '');
65
65
  const saveOptions = saveOptionsPerTable[table] || {};
66
66
  const started = Date.now();
67
67
  let rows = 0;
68
68
  const sizeBytes = sizeByTable[table];
69
- console.log(`<< ${colors_1.grey(filePath)} ${colors_1.dimWhite(js_lib_1._hb(sizeBytes))} started...`);
70
- await nodejs_lib_1._pipeline([
69
+ console.log(`<< ${(0, colors_1.grey)(filePath)} ${(0, colors_1.dimWhite)((0, js_lib_1._hb)(sizeBytes))} started...`);
70
+ await (0, nodejs_lib_1._pipeline)([
71
71
  fs.createReadStream(filePath),
72
- ...(gzip ? [zlib_1.createUnzip()] : []),
73
- nodejs_lib_1.transformSplit(),
74
- nodejs_lib_1.transformJsonParse({ strict }),
75
- nodejs_lib_1.transformTap(() => rows++),
76
- nodejs_lib_1.transformLogProgress({
72
+ ...(gzip ? [(0, zlib_1.createUnzip)()] : []),
73
+ (0, nodejs_lib_1.transformSplit)(),
74
+ (0, nodejs_lib_1.transformJsonParse)({ strict }),
75
+ (0, nodejs_lib_1.transformTap)(() => rows++),
76
+ (0, nodejs_lib_1.transformLogProgress)({
77
77
  logEvery: 1000,
78
78
  ...opt,
79
79
  metric: table,
80
80
  }),
81
- nodejs_lib_1.transformLimit(limit),
81
+ (0, nodejs_lib_1.transformLimit)(limit),
82
82
  ...(sinceUpdated
83
- ? [nodejs_lib_1.transformFilterSync(r => r.updated >= sinceUpdated)]
83
+ ? [(0, nodejs_lib_1.transformFilterSync)(r => r.updated >= sinceUpdated)]
84
84
  : []),
85
- nodejs_lib_1.transformMap(mapperPerTable[table] || js_lib_1._passthroughMapper, {
85
+ (0, nodejs_lib_1.transformMap)(mapperPerTable[table] || js_lib_1._passthroughMapper, {
86
86
  errorMode,
87
87
  flattenArrayOutput: true,
88
88
  ...transformMapOptions,
89
89
  metric: table,
90
90
  }),
91
- nodejs_lib_1.transformBuffer({ batchSize }),
92
- nodejs_lib_1.writableForEach(async (dbms) => {
91
+ (0, nodejs_lib_1.transformBuffer)({ batchSize }),
92
+ (0, nodejs_lib_1.writableForEach)(async (dbms) => {
93
93
  await db.saveBatch(table, dbms, saveOptions);
94
94
  }),
95
95
  ]);
@@ -98,7 +98,7 @@ async function dbPipelineRestore(opt) {
98
98
  rows,
99
99
  sizeBytes,
100
100
  });
101
- console.log(`<< ${colors_1.grey(filePath)}\n` + stats.toPretty());
101
+ console.log(`<< ${(0, colors_1.grey)(filePath)}\n` + stats.toPretty());
102
102
  statsPerTable[table] = stats;
103
103
  }, { concurrency, errorMode });
104
104
  const statsTotal = nodejs_lib_1.NDJsonStats.createCombined(Object.values(statsPerTable));
@@ -116,10 +116,10 @@ class DBQuery {
116
116
  tokens.push(`limit ${this._limitValue}`);
117
117
  }
118
118
  if (this._startCursor) {
119
- tokens.push(`startCursor ${js_lib_1._truncate(this._startCursor, 8)}`);
119
+ tokens.push(`startCursor ${(0, js_lib_1._truncate)(this._startCursor, 8)}`);
120
120
  }
121
121
  if (this._endCursor) {
122
- tokens.push(`endCursor ${js_lib_1._truncate(this._endCursor, 8)}`);
122
+ tokens.push(`endCursor ${(0, js_lib_1._truncate)(this._endCursor, 8)}`);
123
123
  }
124
124
  return tokens;
125
125
  }
@@ -28,8 +28,8 @@ function runCommonDaoTest(db, features = {}, quirks = {}) {
28
28
  // allowBooleansAsUndefined,
29
29
  // } = quirks
30
30
  const eventualConsistencyDelay = !strongConsistency && quirks.eventualConsistencyDelay;
31
- const items = test_model_1.createTestItemsBM(3);
32
- const itemsClone = js_lib_1._deepCopy(items);
31
+ const items = (0, test_model_1.createTestItemsBM)(3);
32
+ const itemsClone = (0, js_lib_1._deepCopy)(items);
33
33
  // deepFreeze(items) // mutation of id/created/updated is allowed now! (even expected)
34
34
  const item1 = items[0];
35
35
  const expectedItems = items.map(i => ({
@@ -42,7 +42,7 @@ function runCommonDaoTest(db, features = {}, quirks = {}) {
42
42
  // CREATE TABLE, DROP
43
43
  if (createTable) {
44
44
  test('createTable, dropIfExists=true', async () => {
45
- await dao.createTable(_1.getTestItemSchema(), { dropIfExists: true });
45
+ await dao.createTable((0, _1.getTestItemSchema)(), { dropIfExists: true });
46
46
  });
47
47
  }
48
48
  if (querying) {
@@ -54,7 +54,7 @@ function runCommonDaoTest(db, features = {}, quirks = {}) {
54
54
  // QUERY empty
55
55
  test('runQuery(all), runQueryCount should return empty', async () => {
56
56
  if (eventualConsistencyDelay)
57
- await js_lib_1.pDelay(eventualConsistencyDelay);
57
+ await (0, js_lib_1.pDelay)(eventualConsistencyDelay);
58
58
  expect(await dao.query().runQuery()).toEqual([]);
59
59
  expect(await dao.query().runQueryCount()).toEqual(0);
60
60
  });
@@ -78,40 +78,40 @@ function runCommonDaoTest(db, features = {}, quirks = {}) {
78
78
  // no unnecessary mutation
79
79
  const { updated: _, ...clone } = itemsClone[0];
80
80
  expect(items[0]).toMatchObject(clone);
81
- dbTest_1.expectMatch(expectedItems, itemsSaved, quirks);
81
+ (0, dbTest_1.expectMatch)(expectedItems, itemsSaved, quirks);
82
82
  });
83
83
  // GET not empty
84
84
  test('getByIds all items', async () => {
85
85
  const rows = await dao.getByIds(items.map(i => i.id).concat('abcd'));
86
- dbTest_1.expectMatch(expectedItems, rows, quirks);
86
+ (0, dbTest_1.expectMatch)(expectedItems, rows, quirks);
87
87
  });
88
88
  // QUERY
89
89
  if (querying) {
90
90
  test('runQuery(all) should return all items', async () => {
91
91
  if (eventualConsistencyDelay)
92
- await js_lib_1.pDelay(eventualConsistencyDelay);
92
+ await (0, js_lib_1.pDelay)(eventualConsistencyDelay);
93
93
  let rows = await dao.query().runQuery();
94
- rows = js_lib_1._sortBy(rows, r => r.id);
95
- dbTest_1.expectMatch(expectedItems, rows, quirks);
94
+ rows = (0, js_lib_1._sortBy)(rows, r => r.id);
95
+ (0, dbTest_1.expectMatch)(expectedItems, rows, quirks);
96
96
  });
97
97
  if (dbQueryFilter) {
98
98
  test('query even=true', async () => {
99
99
  let rows = await dao.query().filter('even', '==', true).runQuery();
100
- rows = js_lib_1._sortBy(rows, r => r.id);
101
- dbTest_1.expectMatch(expectedItems.filter(i => i.even), rows, quirks);
100
+ rows = (0, js_lib_1._sortBy)(rows, r => r.id);
101
+ (0, dbTest_1.expectMatch)(expectedItems.filter(i => i.even), rows, quirks);
102
102
  });
103
103
  }
104
104
  if (dbQueryOrder) {
105
105
  test('query order by k1 desc', async () => {
106
106
  const rows = await dao.query().order('k1', true).runQuery();
107
- dbTest_1.expectMatch([...expectedItems].reverse(), rows, quirks);
107
+ (0, dbTest_1.expectMatch)([...expectedItems].reverse(), rows, quirks);
108
108
  });
109
109
  }
110
110
  if (dbQuerySelectFields) {
111
111
  test('projection query with only ids', async () => {
112
112
  let rows = await dao.query().select(['id']).runQuery();
113
- rows = js_lib_1._sortBy(rows, r => r.id);
114
- dbTest_1.expectMatch(expectedItems.map(item => js_lib_1._pick(item, ['id'])), rows, quirks);
113
+ rows = (0, js_lib_1._sortBy)(rows, r => r.id);
114
+ (0, dbTest_1.expectMatch)(expectedItems.map(item => (0, js_lib_1._pick)(item, ['id'])), rows, quirks);
115
115
  });
116
116
  }
117
117
  test('runQueryCount should return 3', async () => {
@@ -123,24 +123,24 @@ function runCommonDaoTest(db, features = {}, quirks = {}) {
123
123
  test('streamQueryForEach all', async () => {
124
124
  let rows = [];
125
125
  await dao.query().streamQueryForEach(bm => void rows.push(bm));
126
- rows = js_lib_1._sortBy(rows, r => r.id);
127
- dbTest_1.expectMatch(expectedItems, rows, quirks);
126
+ rows = (0, js_lib_1._sortBy)(rows, r => r.id);
127
+ (0, dbTest_1.expectMatch)(expectedItems, rows, quirks);
128
128
  });
129
129
  test('streamQuery all', async () => {
130
- let rows = await nodejs_lib_1.readableToArray(dao.query().streamQuery());
131
- rows = js_lib_1._sortBy(rows, r => r.id);
132
- dbTest_1.expectMatch(expectedItems, rows, quirks);
130
+ let rows = await (0, nodejs_lib_1.readableToArray)(dao.query().streamQuery());
131
+ rows = (0, js_lib_1._sortBy)(rows, r => r.id);
132
+ (0, dbTest_1.expectMatch)(expectedItems, rows, quirks);
133
133
  });
134
134
  test('streamQueryIdsForEach all', async () => {
135
135
  let ids = [];
136
136
  await dao.query().streamQueryIdsForEach(id => void ids.push(id));
137
137
  ids = ids.sort();
138
- dbTest_1.expectMatch(expectedItems.map(i => i.id), ids, quirks);
138
+ (0, dbTest_1.expectMatch)(expectedItems.map(i => i.id), ids, quirks);
139
139
  });
140
140
  test('streamQueryIds all', async () => {
141
- let ids = await nodejs_lib_1.readableToArray(dao.query().streamQueryIds());
141
+ let ids = await (0, nodejs_lib_1.readableToArray)(dao.query().streamQueryIds());
142
142
  ids = ids.sort();
143
- dbTest_1.expectMatch(expectedItems.map(i => i.id), ids, quirks);
143
+ (0, dbTest_1.expectMatch)(expectedItems.map(i => i.id), ids, quirks);
144
144
  });
145
145
  }
146
146
  // DELETE BY
@@ -149,7 +149,7 @@ function runCommonDaoTest(db, features = {}, quirks = {}) {
149
149
  const deleted = await dao.query().filter('even', '==', false).deleteByQuery();
150
150
  expect(deleted).toBe(items.filter(item => !item.even).length);
151
151
  if (eventualConsistencyDelay)
152
- await js_lib_1.pDelay(eventualConsistencyDelay);
152
+ await (0, js_lib_1.pDelay)(eventualConsistencyDelay);
153
153
  expect(await dao.query().runQueryCount()).toBe(1);
154
154
  });
155
155
  test('cleanup', async () => {
@@ -18,8 +18,8 @@ function runCommonDBTest(db, features = {}, quirks = {}) {
18
18
  // allowBooleansAsUndefined,
19
19
  // } = quirks
20
20
  const eventualConsistencyDelay = !strongConsistency && quirks.eventualConsistencyDelay;
21
- const items = test_model_1.createTestItemsDBM(3);
22
- test_util_1.deepFreeze(items);
21
+ const items = (0, test_model_1.createTestItemsDBM)(3);
22
+ (0, test_util_1.deepFreeze)(items);
23
23
  const item1 = items[0];
24
24
  const queryAll = () => dbQuery_1.DBQuery.create(test_model_1.TEST_TABLE);
25
25
  test('ping', async () => {
@@ -28,7 +28,7 @@ function runCommonDBTest(db, features = {}, quirks = {}) {
28
28
  // CREATE TABLE, DROP
29
29
  if (createTable) {
30
30
  test('createTable, dropIfExists=true', async () => {
31
- await db.createTable(test_model_1.getTestItemSchema(), { dropIfExists: true });
31
+ await db.createTable(test_model_1.TEST_TABLE, (0, test_model_1.getTestItemSchema)(), { dropIfExists: true });
32
32
  });
33
33
  }
34
34
  if (querying) {
@@ -40,7 +40,7 @@ function runCommonDBTest(db, features = {}, quirks = {}) {
40
40
  // QUERY empty
41
41
  test('runQuery(all), runQueryCount should return empty', async () => {
42
42
  if (eventualConsistencyDelay)
43
- await js_lib_1.pDelay(eventualConsistencyDelay);
43
+ await (0, js_lib_1.pDelay)(eventualConsistencyDelay);
44
44
  expect((await db.runQuery(queryAll())).rows).toEqual([]);
45
45
  expect(await db.runQueryCount(queryAll())).toEqual(0);
46
46
  });
@@ -70,9 +70,9 @@ function runCommonDBTest(db, features = {}, quirks = {}) {
70
70
  if (querying) {
71
71
  test('runQuery(all) should return all items', async () => {
72
72
  if (eventualConsistencyDelay)
73
- await js_lib_1.pDelay(eventualConsistencyDelay);
73
+ await (0, js_lib_1.pDelay)(eventualConsistencyDelay);
74
74
  let { rows } = await db.runQuery(queryAll());
75
- rows = js_lib_1._sortBy(rows, r => r.id); // because query doesn't specify order here
75
+ rows = (0, js_lib_1._sortBy)(rows, r => r.id); // because query doesn't specify order here
76
76
  expectMatch(items, rows, quirks);
77
77
  });
78
78
  if (dbQueryFilter) {
@@ -80,7 +80,7 @@ function runCommonDBTest(db, features = {}, quirks = {}) {
80
80
  const q = new dbQuery_1.DBQuery(test_model_1.TEST_TABLE).filter('even', '==', true);
81
81
  let { rows } = await db.runQuery(q);
82
82
  if (!dbQueryOrder)
83
- rows = js_lib_1._sortBy(rows, r => r.id);
83
+ rows = (0, js_lib_1._sortBy)(rows, r => r.id);
84
84
  expectMatch(items.filter(i => i.even), rows, quirks);
85
85
  });
86
86
  }
@@ -95,14 +95,14 @@ function runCommonDBTest(db, features = {}, quirks = {}) {
95
95
  test('projection query with only ids', async () => {
96
96
  const q = new dbQuery_1.DBQuery(test_model_1.TEST_TABLE).select(['id']);
97
97
  let { rows } = await db.runQuery(q);
98
- rows = js_lib_1._sortBy(rows, r => r.id); // cause order is not specified
99
- expectMatch(items.map(item => js_lib_1._pick(item, ['id'])), rows, quirks);
98
+ rows = (0, js_lib_1._sortBy)(rows, r => r.id); // cause order is not specified
99
+ expectMatch(items.map(item => (0, js_lib_1._pick)(item, ['id'])), rows, quirks);
100
100
  });
101
101
  test('projection query without ids', async () => {
102
102
  const q = new dbQuery_1.DBQuery(test_model_1.TEST_TABLE).select(['k1']);
103
103
  let { rows } = await db.runQuery(q);
104
- rows = js_lib_1._sortBy(rows, r => r.k1); // cause order is not specified
105
- expectMatch(items.map(item => js_lib_1._pick(item, ['k1'])), rows, quirks);
104
+ rows = (0, js_lib_1._sortBy)(rows, r => r.k1); // cause order is not specified
105
+ expectMatch(items.map(item => (0, js_lib_1._pick)(item, ['k1'])), rows, quirks);
106
106
  });
107
107
  test('projection query empty fields (edge case)', async () => {
108
108
  const q = new dbQuery_1.DBQuery(test_model_1.TEST_TABLE).select([]);
@@ -117,8 +117,8 @@ function runCommonDBTest(db, features = {}, quirks = {}) {
117
117
  // STREAM
118
118
  if (streaming) {
119
119
  test('streamQuery all', async () => {
120
- let rows = await nodejs_lib_1.readableToArray(db.streamQuery(queryAll()));
121
- rows = js_lib_1._sortBy(rows, r => r.id); // cause order is not specified in DBQuery
120
+ let rows = await (0, nodejs_lib_1.readableToArray)(db.streamQuery(queryAll()));
121
+ rows = (0, js_lib_1._sortBy)(rows, r => r.id); // cause order is not specified in DBQuery
122
122
  expectMatch(items, rows, quirks);
123
123
  });
124
124
  }
@@ -127,7 +127,7 @@ function runCommonDBTest(db, features = {}, quirks = {}) {
127
127
  const tables = await db.getTables();
128
128
  console.log({ tables });
129
129
  if (tableSchemas) {
130
- await js_lib_1.pMap(tables, async (table) => {
130
+ await (0, js_lib_1.pMap)(tables, async (table) => {
131
131
  const schema = await db.getTableSchema(table);
132
132
  console.log(schema);
133
133
  expect(schema).toBeDefined();
@@ -141,7 +141,7 @@ function runCommonDBTest(db, features = {}, quirks = {}) {
141
141
  const deleted = await db.deleteByQuery(q);
142
142
  expect(deleted).toBe(items.filter(item => !item.even).length);
143
143
  if (eventualConsistencyDelay)
144
- await js_lib_1.pDelay(eventualConsistencyDelay);
144
+ await (0, js_lib_1.pDelay)(eventualConsistencyDelay);
145
145
  expect(await db.runQueryCount(queryAll())).toBe(1);
146
146
  });
147
147
  }
@@ -151,7 +151,7 @@ function runCommonDBTest(db, features = {}, quirks = {}) {
151
151
  const s = 'helloWorld 1';
152
152
  const b1 = Buffer.from(s);
153
153
  const item = {
154
- ...test_model_1.createTestItemDBM(1),
154
+ ...(0, test_model_1.createTestItemDBM)(1),
155
155
  b1,
156
156
  };
157
157
  await db.saveBatch(test_model_1.TEST_TABLE, [item]);
@@ -183,7 +183,7 @@ function expectMatch(expected, actual, quirks) {
183
183
  // const actualSorted = sortObjectDeep(actual)
184
184
  if (quirks.allowBooleansAsUndefined) {
185
185
  expected = expected.map(r => {
186
- return typeof r !== 'object' ? r : js_lib_1._filterObject(r, (_k, v) => v !== false);
186
+ return typeof r !== 'object' ? r : (0, js_lib_1._filterObject)(r, (_k, v) => v !== false);
187
187
  });
188
188
  }
189
189
  if (quirks.allowExtraPropertiesInResponse) {
@@ -4,7 +4,7 @@ exports.runCommonKeyValueDBTest = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
5
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
6
6
  const test_model_1 = require("./test.model");
7
- const testIds = js_lib_1._range(1, 4).map(n => `id${n}`);
7
+ const testIds = (0, js_lib_1._range)(1, 4).map(n => `id${n}`);
8
8
  const testEntries = testIds.map(id => [id, Buffer.from(`${id}value`)]);
9
9
  function runCommonKeyValueDBTest(db) {
10
10
  test('ping', async () => {
@@ -23,38 +23,42 @@ function runCommonKeyValueDBTest(db) {
23
23
  test('saveBatch, then getByIds', async () => {
24
24
  await db.saveBatch(test_model_1.TEST_TABLE, testEntries);
25
25
  const entries = await db.getByIds(test_model_1.TEST_TABLE, testIds);
26
- js_lib_1._sortBy(entries, e => e[0], true);
26
+ (0, js_lib_1._sortBy)(entries, e => e[0], true);
27
27
  expect(entries).toEqual(testEntries);
28
28
  });
29
29
  test('streamIds', async () => {
30
- const ids = await nodejs_lib_1.readableToArray(db.streamIds(test_model_1.TEST_TABLE));
30
+ const ids = await (0, nodejs_lib_1.readableToArray)(db.streamIds(test_model_1.TEST_TABLE));
31
31
  ids.sort();
32
32
  expect(ids).toEqual(testIds);
33
33
  });
34
34
  test('streamIds limited', async () => {
35
- const idsLimited = await nodejs_lib_1.readableToArray(db.streamIds(test_model_1.TEST_TABLE, 2));
36
- idsLimited.sort();
37
- expect(idsLimited).toEqual(testIds.slice(0, 2));
35
+ const idsLimited = await (0, nodejs_lib_1.readableToArray)(db.streamIds(test_model_1.TEST_TABLE, 2));
36
+ // Order is non-deterministic, so, cannot compare values
37
+ // idsLimited.sort()
38
+ // expect(idsLimited).toEqual(testIds.slice(0, 2))
39
+ expect(idsLimited.length).toBe(2);
38
40
  });
39
41
  test('streamValues', async () => {
40
- const values = await nodejs_lib_1.readableToArray(db.streamValues(test_model_1.TEST_TABLE));
42
+ const values = await (0, nodejs_lib_1.readableToArray)(db.streamValues(test_model_1.TEST_TABLE));
41
43
  values.sort();
42
44
  expect(values).toEqual(testEntries.map(e => e[1]));
43
45
  });
44
46
  test('streamValues limited', async () => {
45
- const valuesLimited = await nodejs_lib_1.readableToArray(db.streamValues(test_model_1.TEST_TABLE, 2));
46
- valuesLimited.sort();
47
- expect(valuesLimited).toEqual(testEntries.map(e => e[1]).slice(0, 2));
47
+ const valuesLimited = await (0, nodejs_lib_1.readableToArray)(db.streamValues(test_model_1.TEST_TABLE, 2));
48
+ // valuesLimited.sort()
49
+ // expect(valuesLimited).toEqual(testEntries.map(e => e[1]).slice(0, 2))
50
+ expect(valuesLimited.length).toBe(2);
48
51
  });
49
52
  test('streamEntries', async () => {
50
- const entries = await nodejs_lib_1.readableToArray(db.streamEntries(test_model_1.TEST_TABLE));
53
+ const entries = await (0, nodejs_lib_1.readableToArray)(db.streamEntries(test_model_1.TEST_TABLE));
51
54
  entries.sort();
52
55
  expect(entries).toEqual(testEntries);
53
56
  });
54
57
  test('streamEntries limited', async () => {
55
- const entriesLimited = await nodejs_lib_1.readableToArray(db.streamEntries(test_model_1.TEST_TABLE, 2));
56
- entriesLimited.sort();
57
- expect(entriesLimited).toEqual(testEntries.slice(0, 2));
58
+ const entriesLimited = await (0, nodejs_lib_1.readableToArray)(db.streamEntries(test_model_1.TEST_TABLE, 2));
59
+ // entriesLimited.sort()
60
+ // expect(entriesLimited).toEqual(testEntries.slice(0, 2))
61
+ expect(entriesLimited.length).toBe(2);
58
62
  });
59
63
  test('deleteByIds should clear', async () => {
60
64
  await db.deleteByIds(test_model_1.TEST_TABLE, testIds);
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runCommonKeyValueDaoTest = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
5
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
6
- const testIds = js_lib_1._range(1, 4).map(n => `id${n}`);
6
+ const testIds = (0, js_lib_1._range)(1, 4).map(n => `id${n}`);
7
7
  const testEntries = testIds.map(id => [id, Buffer.from(`${id}value`)]);
8
8
  function runCommonKeyValueDaoTest(dao) {
9
9
  test('ping', async () => {
@@ -22,38 +22,42 @@ function runCommonKeyValueDaoTest(dao) {
22
22
  test('saveBatch, then getByIds', async () => {
23
23
  await dao.saveBatch(testEntries);
24
24
  const entries = await dao.getByIds(testIds);
25
- js_lib_1._sortBy(entries, e => e[0], true);
25
+ (0, js_lib_1._sortBy)(entries, e => e[0], true);
26
26
  expect(entries).toEqual(testEntries);
27
27
  });
28
28
  test('streamIds', async () => {
29
- const ids = await nodejs_lib_1.readableToArray(dao.streamIds());
29
+ const ids = await (0, nodejs_lib_1.readableToArray)(dao.streamIds());
30
30
  ids.sort();
31
31
  expect(ids).toEqual(testIds);
32
32
  });
33
33
  test('streamIds limited', async () => {
34
- const idsLimited = await nodejs_lib_1.readableToArray(dao.streamIds(2));
35
- idsLimited.sort();
36
- expect(idsLimited).toEqual(testIds.slice(0, 2));
34
+ const idsLimited = await (0, nodejs_lib_1.readableToArray)(dao.streamIds(2));
35
+ // Order is non-deterministic, so, cannot compare values
36
+ // idsLimited.sort()
37
+ // expect(idsLimited).toEqual(testIds.slice(0, 2))
38
+ expect(idsLimited.length).toBe(2);
37
39
  });
38
40
  test('streamValues', async () => {
39
- const values = await nodejs_lib_1.readableToArray(dao.streamValues());
41
+ const values = await (0, nodejs_lib_1.readableToArray)(dao.streamValues());
40
42
  values.sort();
41
43
  expect(values).toEqual(testEntries.map(e => e[1]));
42
44
  });
43
45
  test('streamValues limited', async () => {
44
- const valuesLimited = await nodejs_lib_1.readableToArray(dao.streamValues(2));
45
- valuesLimited.sort();
46
- expect(valuesLimited).toEqual(testEntries.map(e => e[1]).slice(0, 2));
46
+ const valuesLimited = await (0, nodejs_lib_1.readableToArray)(dao.streamValues(2));
47
+ // valuesLimited.sort()
48
+ // expect(valuesLimited).toEqual(testEntries.map(e => e[1]).slice(0, 2))
49
+ expect(valuesLimited.length).toBe(2);
47
50
  });
48
51
  test('streamEntries', async () => {
49
- const entries = await nodejs_lib_1.readableToArray(dao.streamEntries());
52
+ const entries = await (0, nodejs_lib_1.readableToArray)(dao.streamEntries());
50
53
  entries.sort();
51
54
  expect(entries).toEqual(testEntries);
52
55
  });
53
56
  test('streamEntries limited', async () => {
54
- const entriesLimited = await nodejs_lib_1.readableToArray(dao.streamEntries(2));
55
- entriesLimited.sort();
56
- expect(entriesLimited).toEqual(testEntries.slice(0, 2));
57
+ const entriesLimited = await (0, nodejs_lib_1.readableToArray)(dao.streamEntries(2));
58
+ // entriesLimited.sort()
59
+ // expect(entriesLimited).toEqual(testEntries.slice(0, 2))
60
+ expect(entriesLimited.length).toBe(2);
57
61
  });
58
62
  test('deleteByIds should clear', async () => {
59
63
  await dao.deleteByIds(testIds);
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { CommonSchema } from '..';
2
+ import { JsonSchemaObject } from '@naturalcycles/js-lib';
3
3
  import { BaseDBEntity, Saved } from '../db.model';
4
4
  export declare const TEST_TABLE = "TEST_TABLE";
5
5
  export interface TestItemBM extends BaseDBEntity {
@@ -18,8 +18,10 @@ export interface TestItemTM {
18
18
  export declare const testItemBMSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<TestItemBM, TestItemBM>;
19
19
  export declare const testItemDBMSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<TestItemDBM, TestItemDBM>;
20
20
  export declare const testItemTMSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<TestItemTM, TestItemTM>;
21
+ export declare const testItemBMJsonSchema: import("@naturalcycles/js-lib/dist/json-schema/jsonSchemaBuilder").JsonSchemaObjectBuilder<TestItemBM & Partial<import("@naturalcycles/js-lib").SavedDBEntity>>;
22
+ export declare const testItemDBMJsonSchema: import("@naturalcycles/js-lib/dist/json-schema/jsonSchemaBuilder").JsonSchemaObjectBuilder<TestItemDBM>;
21
23
  export declare function createTestItemDBM(num?: number): TestItemDBM;
22
24
  export declare function createTestItemBM(num?: number): Saved<TestItemBM>;
23
25
  export declare function createTestItemsDBM(count?: number): TestItemDBM[];
24
26
  export declare function createTestItemsBM(count?: number): Saved<TestItemBM>[];
25
- export declare function getTestItemSchema(): CommonSchema<TestItemDBM>;
27
+ export declare function getTestItemSchema(): JsonSchemaObject<TestItemDBM>;
@@ -1,30 +1,49 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTestItemSchema = exports.createTestItemsBM = exports.createTestItemsDBM = exports.createTestItemBM = exports.createTestItemDBM = exports.testItemTMSchema = exports.testItemDBMSchema = exports.testItemBMSchema = exports.TEST_TABLE = void 0;
3
+ exports.getTestItemSchema = exports.createTestItemsBM = exports.createTestItemsDBM = exports.createTestItemBM = exports.createTestItemDBM = exports.testItemDBMJsonSchema = exports.testItemBMJsonSchema = exports.testItemTMSchema = exports.testItemDBMSchema = exports.testItemBMSchema = exports.TEST_TABLE = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
5
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
6
- const __1 = require("..");
7
6
  const db_model_1 = require("../db.model");
8
7
  const MOCK_TS_2018_06_21 = 1529539200;
9
8
  exports.TEST_TABLE = 'TEST_TABLE';
10
- exports.testItemBMSchema = nodejs_lib_1.objectSchema({
9
+ exports.testItemBMSchema = (0, nodejs_lib_1.objectSchema)({
11
10
  k1: nodejs_lib_1.stringSchema,
12
11
  k2: nodejs_lib_1.stringSchema.optional(),
13
12
  k3: nodejs_lib_1.numberSchema.optional(),
14
13
  even: nodejs_lib_1.booleanSchema.optional(),
15
14
  b1: nodejs_lib_1.binarySchema.optional(),
16
15
  }).concat(db_model_1.baseDBEntitySchema);
17
- exports.testItemDBMSchema = nodejs_lib_1.objectSchema({
16
+ exports.testItemDBMSchema = (0, nodejs_lib_1.objectSchema)({
18
17
  k1: nodejs_lib_1.stringSchema,
19
18
  k2: nodejs_lib_1.stringSchema.optional(),
20
19
  k3: nodejs_lib_1.numberSchema.optional(),
21
20
  even: nodejs_lib_1.booleanSchema.optional(),
22
21
  b1: nodejs_lib_1.binarySchema.optional(),
23
22
  }).concat(db_model_1.savedDBEntitySchema);
24
- exports.testItemTMSchema = nodejs_lib_1.objectSchema({
23
+ exports.testItemTMSchema = (0, nodejs_lib_1.objectSchema)({
25
24
  k1: nodejs_lib_1.stringSchema,
26
25
  even: nodejs_lib_1.booleanSchema.optional(),
27
26
  });
27
+ exports.testItemBMJsonSchema = js_lib_1.jsonSchema
28
+ .rootObject({
29
+ k1: js_lib_1.jsonSchema.string(),
30
+ k2: js_lib_1.jsonSchema.string().optional(),
31
+ k3: js_lib_1.jsonSchema.number().optional(),
32
+ even: js_lib_1.jsonSchema.boolean().optional(),
33
+ b1: js_lib_1.jsonSchema.buffer().optional(),
34
+ })
35
+ .baseDBEntity();
36
+ exports.testItemDBMJsonSchema = js_lib_1.jsonSchema.rootObject({
37
+ // todo: figure out how to not copy-paste these 3 fields
38
+ id: js_lib_1.jsonSchema.string(),
39
+ created: js_lib_1.jsonSchema.unixTimestamp(),
40
+ updated: js_lib_1.jsonSchema.unixTimestamp(),
41
+ k1: js_lib_1.jsonSchema.string(),
42
+ k2: js_lib_1.jsonSchema.string().optional(),
43
+ k3: js_lib_1.jsonSchema.number().optional(),
44
+ even: js_lib_1.jsonSchema.boolean().optional(),
45
+ b1: js_lib_1.jsonSchema.buffer().optional(),
46
+ });
28
47
  function createTestItemDBM(num = 1) {
29
48
  return {
30
49
  id: `id${num}`,
@@ -42,14 +61,26 @@ function createTestItemBM(num = 1) {
42
61
  }
43
62
  exports.createTestItemBM = createTestItemBM;
44
63
  function createTestItemsDBM(count = 1) {
45
- return js_lib_1._range(1, count + 1).map(num => createTestItemDBM(num));
64
+ return (0, js_lib_1._range)(1, count + 1).map(num => createTestItemDBM(num));
46
65
  }
47
66
  exports.createTestItemsDBM = createTestItemsDBM;
48
67
  function createTestItemsBM(count = 1) {
49
- return js_lib_1._range(1, count + 1).map(num => createTestItemBM(num));
68
+ return (0, js_lib_1._range)(1, count + 1).map(num => createTestItemBM(num));
50
69
  }
51
70
  exports.createTestItemsBM = createTestItemsBM;
71
+ const testItemJsonSchema = js_lib_1.jsonSchema
72
+ .object({
73
+ id: js_lib_1.jsonSchema.string(),
74
+ k1: js_lib_1.jsonSchema.string(),
75
+ k2: js_lib_1.jsonSchema.string(),
76
+ k3: js_lib_1.jsonSchema.number(),
77
+ even: js_lib_1.jsonSchema.boolean(),
78
+ created: js_lib_1.jsonSchema.unixTimestamp(),
79
+ updated: js_lib_1.jsonSchema.unixTimestamp(),
80
+ })
81
+ .build();
52
82
  function getTestItemSchema() {
53
- return __1.CommonSchemaGenerator.generateFromRows({ table: exports.TEST_TABLE }, createTestItemsDBM());
83
+ // return CommonSchemaGenerator.generateFromRows({ table: TEST_TABLE }, createTestItemsDBM())
84
+ return testItemJsonSchema;
54
85
  }
55
86
  exports.getTestItemSchema = getTestItemSchema;
@@ -4,6 +4,6 @@ exports.createTestTimeSeries = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
5
  function createTestTimeSeries(count = 10) {
6
6
  const ts = Date.now();
7
- return js_lib_1._range(1, count + 1).map(i => [ts - i * 60000, js_lib_1._randomInt(10, 20)]);
7
+ return (0, js_lib_1._range)(1, count + 1).map(i => [ts - i * 60000, (0, js_lib_1._randomInt)(10, 20)]);
8
8
  }
9
9
  exports.createTestTimeSeries = createTestTimeSeries;