@naturalcycles/db-lib 10.41.0 → 10.41.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.
|
@@ -569,7 +569,7 @@ export class CommonDao {
|
|
|
569
569
|
* Mutates `dbm`.
|
|
570
570
|
*/
|
|
571
571
|
async compress(dbm) {
|
|
572
|
-
if (!this.cfg.compress)
|
|
572
|
+
if (!this.cfg.compress?.keys.length)
|
|
573
573
|
return; // No compression requested
|
|
574
574
|
const { keys } = this.cfg.compress;
|
|
575
575
|
const properties = _pick(dbm, keys);
|
|
@@ -584,6 +584,8 @@ export class CommonDao {
|
|
|
584
584
|
*/
|
|
585
585
|
async decompress(dbm) {
|
|
586
586
|
_typeCast(dbm);
|
|
587
|
+
if (!this.cfg.compress)
|
|
588
|
+
return; // Auto-compression not turned on
|
|
587
589
|
if (!Buffer.isBuffer(dbm.data))
|
|
588
590
|
return; // No compressed data
|
|
589
591
|
// try-catch to avoid a `data` with Buffer which is not compressed, but legit data
|
|
@@ -171,11 +171,14 @@ export interface CommonDaoCfg<BM extends BaseDBEntity, DBM extends BaseDBEntity
|
|
|
171
171
|
* When specified, the listed properties will be compressed under a `data` property in the DBM.
|
|
172
172
|
* If DBM already has a `data` property and you don't add it to the list, an error will be thrown.
|
|
173
173
|
*
|
|
174
|
+
* When specified with an empty `keys` list, then compression will be skipped, but all previously compressed data
|
|
175
|
+
* will be decompressed, so the Dao can still work.
|
|
176
|
+
*
|
|
174
177
|
* Compression happens after the `beforeBMToDBM` hook and before the DBM is saved to the database.
|
|
175
178
|
* Decompression happens after the DBM is loaded from the database and before the `beforeDBMToBM` hook.
|
|
176
179
|
*/
|
|
177
180
|
compress?: {
|
|
178
|
-
keys:
|
|
181
|
+
keys: (keyof DBM)[];
|
|
179
182
|
};
|
|
180
183
|
}
|
|
181
184
|
/**
|
package/package.json
CHANGED
|
@@ -210,11 +210,14 @@ export interface CommonDaoCfg<
|
|
|
210
210
|
* When specified, the listed properties will be compressed under a `data` property in the DBM.
|
|
211
211
|
* If DBM already has a `data` property and you don't add it to the list, an error will be thrown.
|
|
212
212
|
*
|
|
213
|
+
* When specified with an empty `keys` list, then compression will be skipped, but all previously compressed data
|
|
214
|
+
* will be decompressed, so the Dao can still work.
|
|
215
|
+
*
|
|
213
216
|
* Compression happens after the `beforeBMToDBM` hook and before the DBM is saved to the database.
|
|
214
217
|
* Decompression happens after the DBM is loaded from the database and before the `beforeDBMToBM` hook.
|
|
215
218
|
*/
|
|
216
219
|
compress?: {
|
|
217
|
-
keys:
|
|
220
|
+
keys: (keyof DBM)[]
|
|
218
221
|
}
|
|
219
222
|
}
|
|
220
223
|
|
|
@@ -758,7 +758,7 @@ export class CommonDao<
|
|
|
758
758
|
* Mutates `dbm`.
|
|
759
759
|
*/
|
|
760
760
|
async compress(dbm: DBM): Promise<void> {
|
|
761
|
-
if (!this.cfg.compress) return // No compression requested
|
|
761
|
+
if (!this.cfg.compress?.keys.length) return // No compression requested
|
|
762
762
|
|
|
763
763
|
const { keys } = this.cfg.compress
|
|
764
764
|
const properties = _pick(dbm, keys)
|
|
@@ -777,6 +777,7 @@ export class CommonDao<
|
|
|
777
777
|
*/
|
|
778
778
|
async decompress(dbm: DBM): Promise<void> {
|
|
779
779
|
_typeCast<Compressed<DBM>>(dbm)
|
|
780
|
+
if (!this.cfg.compress) return // Auto-compression not turned on
|
|
780
781
|
if (!Buffer.isBuffer(dbm.data)) return // No compressed data
|
|
781
782
|
|
|
782
783
|
// try-catch to avoid a `data` with Buffer which is not compressed, but legit data
|