@naturalcycles/db-lib 10.46.1 → 10.47.1

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.
@@ -178,7 +178,10 @@ export class CommonDao {
178
178
  q.table = opt.table || q.table;
179
179
  let pipeline = this.cfg.db.streamQuery(q, opt);
180
180
  if (this.cfg.compress?.keys.length) {
181
- pipeline = pipeline.map(async row => await this.storageRowToDBM(row));
181
+ pipeline = pipeline.map(async row => await this.storageRowToDBM(row), {
182
+ // lowered, to reduce the total buffer size a bit for uncompressed objects
183
+ highWaterMark: 16,
184
+ });
182
185
  }
183
186
  const isPartialQuery = !!q._selectedFieldNames;
184
187
  if (isPartialQuery)
@@ -192,7 +195,10 @@ export class CommonDao {
192
195
  q.table = opt.table || q.table;
193
196
  let pipeline = this.cfg.db.streamQuery(q, opt);
194
197
  if (this.cfg.compress?.keys.length) {
195
- pipeline = pipeline.map(async row => await this.storageRowToDBM(row));
198
+ pipeline = pipeline.map(async row => await this.storageRowToDBM(row), {
199
+ // lowered, to reduce the total buffer size a bit for uncompressed objects
200
+ highWaterMark: 16,
201
+ });
196
202
  }
197
203
  const isPartialQuery = !!q._selectedFieldNames;
198
204
  if (isPartialQuery)
@@ -645,10 +651,10 @@ export class CommonDao {
645
651
  async compress(dbm) {
646
652
  if (!this.cfg.compress?.keys.length)
647
653
  return; // No compression requested
648
- const { keys } = this.cfg.compress;
654
+ const { keys, level = 1 } = this.cfg.compress;
649
655
  const properties = _pick(dbm, keys);
650
656
  const bufferString = JSON.stringify(properties);
651
- const __compressed = await zstdCompress(bufferString);
657
+ const __compressed = await zstdCompress(bufferString, level);
652
658
  _omitWithUndefined(dbm, _objectKeys(properties), { mutate: true });
653
659
  Object.assign(dbm, { __compressed });
654
660
  }
@@ -1,7 +1,7 @@
1
1
  import type { ValidationFunction } from '@naturalcycles/js-lib';
2
2
  import type { AppError, ErrorMode } from '@naturalcycles/js-lib/error';
3
3
  import type { CommonLogger } from '@naturalcycles/js-lib/log';
4
- import type { BaseDBEntity, UnixTimestamp } from '@naturalcycles/js-lib/types';
4
+ import type { BaseDBEntity, Integer, UnixTimestamp } from '@naturalcycles/js-lib/types';
5
5
  import type { TransformLogProgressOptions } from '@naturalcycles/nodejs-lib/stream';
6
6
  import type { CommonDB } from '../commondb/common.db.js';
7
7
  import type { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions } from '../db.model.js';
@@ -180,6 +180,11 @@ export interface CommonDaoCfg<BM extends BaseDBEntity, DBM extends BaseDBEntity
180
180
  */
181
181
  compress?: {
182
182
  keys: (keyof DBM)[];
183
+ /**
184
+ * zstd compression level.
185
+ * Undefined will default to level 1 (not the 3, which is the zstd default)
186
+ */
187
+ level?: Integer;
183
188
  };
184
189
  }
185
190
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/db-lib",
3
3
  "type": "module",
4
- "version": "10.46.1",
4
+ "version": "10.47.1",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@naturalcycles/nodejs-lib": "^15"
@@ -1,7 +1,7 @@
1
1
  import type { ValidationFunction } from '@naturalcycles/js-lib'
2
2
  import type { AppError, ErrorMode } from '@naturalcycles/js-lib/error'
3
3
  import type { CommonLogger } from '@naturalcycles/js-lib/log'
4
- import type { BaseDBEntity, UnixTimestamp } from '@naturalcycles/js-lib/types'
4
+ import type { BaseDBEntity, Integer, UnixTimestamp } from '@naturalcycles/js-lib/types'
5
5
  import type { TransformLogProgressOptions } from '@naturalcycles/nodejs-lib/stream'
6
6
  import type { CommonDB } from '../commondb/common.db.js'
7
7
  import type { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions } from '../db.model.js'
@@ -219,6 +219,11 @@ export interface CommonDaoCfg<
219
219
  */
220
220
  compress?: {
221
221
  keys: (keyof DBM)[]
222
+ /**
223
+ * zstd compression level.
224
+ * Undefined will default to level 1 (not the 3, which is the zstd default)
225
+ */
226
+ level?: Integer
222
227
  }
223
228
  }
224
229
 
@@ -254,7 +254,10 @@ export class CommonDao<
254
254
  let pipeline = this.cfg.db.streamQuery<DBM>(q, opt)
255
255
 
256
256
  if (this.cfg.compress?.keys.length) {
257
- pipeline = pipeline.map(async row => await this.storageRowToDBM(row))
257
+ pipeline = pipeline.map(async row => await this.storageRowToDBM(row), {
258
+ // lowered, to reduce the total buffer size a bit for uncompressed objects
259
+ highWaterMark: 16,
260
+ })
258
261
  }
259
262
 
260
263
  const isPartialQuery = !!q._selectedFieldNames
@@ -272,7 +275,10 @@ export class CommonDao<
272
275
  let pipeline = this.cfg.db.streamQuery<DBM>(q, opt)
273
276
 
274
277
  if (this.cfg.compress?.keys.length) {
275
- pipeline = pipeline.map(async row => await this.storageRowToDBM(row))
278
+ pipeline = pipeline.map(async row => await this.storageRowToDBM(row), {
279
+ // lowered, to reduce the total buffer size a bit for uncompressed objects
280
+ highWaterMark: 16,
281
+ })
276
282
  }
277
283
 
278
284
  const isPartialQuery = !!q._selectedFieldNames
@@ -841,10 +847,10 @@ export class CommonDao<
841
847
  private async compress(dbm: DBM): Promise<void> {
842
848
  if (!this.cfg.compress?.keys.length) return // No compression requested
843
849
 
844
- const { keys } = this.cfg.compress
850
+ const { keys, level = 1 } = this.cfg.compress
845
851
  const properties = _pick(dbm, keys)
846
852
  const bufferString = JSON.stringify(properties)
847
- const __compressed = await zstdCompress(bufferString)
853
+ const __compressed = await zstdCompress(bufferString, level)
848
854
  _omitWithUndefined(dbm as any, _objectKeys(properties), { mutate: true })
849
855
  Object.assign(dbm, { __compressed })
850
856
  }