@naturalcycles/db-lib 10.46.0 → 10.47.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.
@@ -645,10 +645,10 @@ export class CommonDao {
645
645
  async compress(dbm) {
646
646
  if (!this.cfg.compress?.keys.length)
647
647
  return; // No compression requested
648
- const { keys } = this.cfg.compress;
648
+ const { keys, level = 1 } = this.cfg.compress;
649
649
  const properties = _pick(dbm, keys);
650
650
  const bufferString = JSON.stringify(properties);
651
- const __compressed = await zstdCompress(bufferString);
651
+ const __compressed = await zstdCompress(bufferString, level);
652
652
  _omitWithUndefined(dbm, _objectKeys(properties), { mutate: true });
653
653
  Object.assign(dbm, { __compressed });
654
654
  }
@@ -659,14 +659,11 @@ export class CommonDao {
659
659
  _typeCast(dbm);
660
660
  if (!Buffer.isBuffer(dbm.__compressed))
661
661
  return; // No compressed data
662
- try {
663
- // todo: stop supporting Inflate when we are sure that we have migrated everything to zstd
664
- const bufferString = await decompressZstdOrInflateToString(dbm.__compressed);
665
- const properties = JSON.parse(bufferString);
666
- dbm.__compressed = undefined;
667
- Object.assign(dbm, properties);
668
- }
669
- catch { }
662
+ // todo: stop supporting Inflate when we are sure that we have migrated everything to zstd
663
+ const bufferString = await decompressZstdOrInflateToString(dbm.__compressed);
664
+ const properties = JSON.parse(bufferString);
665
+ dbm.__compressed = undefined;
666
+ Object.assign(dbm, properties);
670
667
  }
671
668
  anyToDBM(dbm, _opt = {}) {
672
669
  if (!dbm)
@@ -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,13 +1,13 @@
1
1
  {
2
2
  "name": "@naturalcycles/db-lib",
3
3
  "type": "module",
4
- "version": "10.46.0",
4
+ "version": "10.47.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@naturalcycles/nodejs-lib": "^15"
8
8
  },
9
9
  "devDependencies": {
10
- "@typescript/native-preview": "7.0.0-dev.20260201.1",
10
+ "@typescript/native-preview": "7.0.0-dev.20260301.1",
11
11
  "@naturalcycles/dev-lib": "18.4.2"
12
12
  },
13
13
  "files": [
@@ -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
 
@@ -841,10 +841,10 @@ export class CommonDao<
841
841
  private async compress(dbm: DBM): Promise<void> {
842
842
  if (!this.cfg.compress?.keys.length) return // No compression requested
843
843
 
844
- const { keys } = this.cfg.compress
844
+ const { keys, level = 1 } = this.cfg.compress
845
845
  const properties = _pick(dbm, keys)
846
846
  const bufferString = JSON.stringify(properties)
847
- const __compressed = await zstdCompress(bufferString)
847
+ const __compressed = await zstdCompress(bufferString, level)
848
848
  _omitWithUndefined(dbm as any, _objectKeys(properties), { mutate: true })
849
849
  Object.assign(dbm, { __compressed })
850
850
  }
@@ -856,13 +856,11 @@ export class CommonDao<
856
856
  _typeCast<Compressed<DBM>>(dbm)
857
857
  if (!Buffer.isBuffer(dbm.__compressed)) return // No compressed data
858
858
 
859
- try {
860
- // todo: stop supporting Inflate when we are sure that we have migrated everything to zstd
861
- const bufferString = await decompressZstdOrInflateToString(dbm.__compressed)
862
- const properties = JSON.parse(bufferString)
863
- dbm.__compressed = undefined
864
- Object.assign(dbm, properties)
865
- } catch {}
859
+ // todo: stop supporting Inflate when we are sure that we have migrated everything to zstd
860
+ const bufferString = await decompressZstdOrInflateToString(dbm.__compressed)
861
+ const properties = JSON.parse(bufferString)
862
+ dbm.__compressed = undefined
863
+ Object.assign(dbm, properties)
866
864
  }
867
865
 
868
866
  anyToDBM(dbm: undefined, opt?: CommonDaoOptions): null