@sv443-network/coreutils 3.0.2 → 3.0.4
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.
- package/CHANGELOG.md +12 -0
- package/dist/CoreUtils.cjs +17 -17
- package/dist/CoreUtils.min.cjs +3 -3
- package/dist/CoreUtils.min.mjs +3 -3
- package/dist/CoreUtils.min.umd.js +3 -3
- package/dist/CoreUtils.mjs +17 -17
- package/dist/CoreUtils.umd.js +547 -473
- package/package.json +1 -1
package/dist/CoreUtils.mjs
CHANGED
|
@@ -496,7 +496,6 @@ var DataStore = class {
|
|
|
496
496
|
* @param opts The options for this DataStore instance
|
|
497
497
|
*/
|
|
498
498
|
constructor(opts) {
|
|
499
|
-
var _a;
|
|
500
499
|
this.id = opts.id;
|
|
501
500
|
this.formatVersion = opts.formatVersion;
|
|
502
501
|
this.defaultData = opts.defaultData;
|
|
@@ -505,16 +504,9 @@ var DataStore = class {
|
|
|
505
504
|
this.migrations = opts.migrations;
|
|
506
505
|
if (opts.migrateIds)
|
|
507
506
|
this.migrateIds = Array.isArray(opts.migrateIds) ? opts.migrateIds : [opts.migrateIds];
|
|
508
|
-
this.encodeData = opts.encodeData;
|
|
509
|
-
this.decodeData = opts.decodeData;
|
|
510
507
|
this.engine = typeof opts.engine === "function" ? opts.engine() : opts.engine;
|
|
511
508
|
this.options = opts;
|
|
512
|
-
if (
|
|
513
|
-
this.compressionFormat = opts.compressionFormat = ((_a = opts.encodeData) == null ? void 0 : _a[0]) ?? "deflate-raw";
|
|
514
|
-
if (typeof opts.compressionFormat === "string") {
|
|
515
|
-
this.encodeData = [opts.compressionFormat, async (data) => await compress(data, opts.compressionFormat, "string")];
|
|
516
|
-
this.decodeData = [opts.compressionFormat, async (data) => await compress(data, opts.compressionFormat, "string")];
|
|
517
|
-
} else if ("encodeData" in opts && "decodeData" in opts && Array.isArray(opts.encodeData) && Array.isArray(opts.decodeData)) {
|
|
509
|
+
if ("encodeData" in opts && "decodeData" in opts && Array.isArray(opts.encodeData) && Array.isArray(opts.decodeData)) {
|
|
518
510
|
this.encodeData = [opts.encodeData[0], opts.encodeData[1]];
|
|
519
511
|
this.decodeData = [opts.decodeData[0], opts.decodeData[1]];
|
|
520
512
|
this.compressionFormat = opts.encodeData[0] ?? null;
|
|
@@ -522,9 +514,17 @@ var DataStore = class {
|
|
|
522
514
|
this.encodeData = void 0;
|
|
523
515
|
this.decodeData = void 0;
|
|
524
516
|
this.compressionFormat = null;
|
|
525
|
-
} else
|
|
526
|
-
|
|
527
|
-
|
|
517
|
+
} else {
|
|
518
|
+
const fmt = typeof opts.compressionFormat === "string" ? opts.compressionFormat : "deflate-raw";
|
|
519
|
+
this.compressionFormat = fmt;
|
|
520
|
+
this.encodeData = [fmt, async (data) => await compress(data, fmt, "string")];
|
|
521
|
+
this.decodeData = [fmt, async (data) => await decompress(data, fmt, "string")];
|
|
522
|
+
}
|
|
523
|
+
this.engine.setDataStoreOptions({
|
|
524
|
+
id: this.id,
|
|
525
|
+
encodeData: this.encodeData,
|
|
526
|
+
decodeData: this.decodeData
|
|
527
|
+
});
|
|
528
528
|
}
|
|
529
529
|
//#region loadData
|
|
530
530
|
/**
|
|
@@ -549,8 +549,8 @@ var DataStore = class {
|
|
|
549
549
|
migrateFmt(`_uucfg-${this.id}`, `__ds-${this.id}-dat`, oldData);
|
|
550
550
|
if (!isNaN(oldVer))
|
|
551
551
|
migrateFmt(`_uucfgver-${this.id}`, `__ds-${this.id}-ver`, oldVer);
|
|
552
|
-
if (typeof oldEnc === "boolean")
|
|
553
|
-
migrateFmt(`_uucfgenc-${this.id}`, `__ds-${this.id}-enf`,
|
|
552
|
+
if (typeof oldEnc === "boolean" || oldEnc === "true" || oldEnc === "false" || typeof oldEnc === "number" || oldEnc === "0" || oldEnc === "1")
|
|
553
|
+
migrateFmt(`_uucfgenc-${this.id}`, `__ds-${this.id}-enf`, [0, "0", true, "true"].includes(oldEnc) ? this.compressionFormat ?? null : null);
|
|
554
554
|
else {
|
|
555
555
|
promises.push(this.engine.setValue(`__ds-${this.id}-enf`, this.compressionFormat));
|
|
556
556
|
promises.push(this.engine.deleteValue(`_uucfgenc-${this.id}`));
|
|
@@ -572,7 +572,7 @@ var DataStore = class {
|
|
|
572
572
|
}
|
|
573
573
|
const storedData = storedDataRaw ?? JSON.stringify(this.defaultData);
|
|
574
574
|
const encodingFmt = String(await this.engine.getValue(`__ds-${this.id}-enf`, null));
|
|
575
|
-
const isEncoded = encodingFmt !== "null" && encodingFmt !== "false";
|
|
575
|
+
const isEncoded = encodingFmt !== "null" && encodingFmt !== "false" && encodingFmt !== "0" && encodingFmt !== "" && encodingFmt !== null;
|
|
576
576
|
let saveData = false;
|
|
577
577
|
if (isNaN(storedFmtVer)) {
|
|
578
578
|
await this.engine.setValue(`__ds-${this.id}-ver`, storedFmtVer = this.formatVersion);
|
|
@@ -679,7 +679,7 @@ var DataStore = class {
|
|
|
679
679
|
}
|
|
680
680
|
}
|
|
681
681
|
await Promise.allSettled([
|
|
682
|
-
this.engine.setValue(`__ds-${this.id}-dat`, await this.engine.serializeData(newData)),
|
|
682
|
+
this.engine.setValue(`__ds-${this.id}-dat`, await this.engine.serializeData(newData, this.encodingEnabled())),
|
|
683
683
|
this.engine.setValue(`__ds-${this.id}-ver`, lastFmtVer),
|
|
684
684
|
this.engine.setValue(`__ds-${this.id}-enf`, this.compressionFormat)
|
|
685
685
|
]);
|
|
@@ -708,7 +708,7 @@ var DataStore = class {
|
|
|
708
708
|
return;
|
|
709
709
|
const parsed = await this.engine.deserializeData(data, isEncoded);
|
|
710
710
|
await Promise.allSettled([
|
|
711
|
-
this.engine.setValue(`__ds-${this.id}-dat`, await this.engine.serializeData(parsed)),
|
|
711
|
+
this.engine.setValue(`__ds-${this.id}-dat`, await this.engine.serializeData(parsed, this.encodingEnabled())),
|
|
712
712
|
this.engine.setValue(`__ds-${this.id}-ver`, fmtVer),
|
|
713
713
|
this.engine.setValue(`__ds-${this.id}-enf`, this.compressionFormat),
|
|
714
714
|
this.engine.deleteValue(`__ds-${id}-dat`),
|