@sv443-network/userutils 10.0.2 → 10.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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @sv443-network/userutils
2
2
 
3
+ ## 10.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 13159d8: Updated CoreUtils to fix underlying encoding and decoding inconsistencies.
8
+
9
+ ## 10.0.3
10
+
11
+ ### Patch Changes
12
+
13
+ - d7d3bea: Fixed decoding step when migrating DataStore data.
14
+
3
15
  ## 10.0.2
4
16
 
5
17
  ### Patch Changes
@@ -114,7 +114,7 @@ __export(lib_exports, {
114
114
  });
115
115
  module.exports = __toCommonJS(lib_exports);
116
116
 
117
- // node_modules/.pnpm/@sv443-network+coreutils@3.0.2/node_modules/@sv443-network/coreutils/dist/CoreUtils.mjs
117
+ // node_modules/.pnpm/@sv443-network+coreutils@3.0.4/node_modules/@sv443-network/coreutils/dist/CoreUtils.mjs
118
118
  function bitSetHas(bitSet, checkVal) {
119
119
  return (bitSet & checkVal) === checkVal;
120
120
  }
@@ -598,7 +598,6 @@ var DataStore = class {
598
598
  * @param opts The options for this DataStore instance
599
599
  */
600
600
  constructor(opts) {
601
- var _a;
602
601
  this.id = opts.id;
603
602
  this.formatVersion = opts.formatVersion;
604
603
  this.defaultData = opts.defaultData;
@@ -607,16 +606,9 @@ var DataStore = class {
607
606
  this.migrations = opts.migrations;
608
607
  if (opts.migrateIds)
609
608
  this.migrateIds = Array.isArray(opts.migrateIds) ? opts.migrateIds : [opts.migrateIds];
610
- this.encodeData = opts.encodeData;
611
- this.decodeData = opts.decodeData;
612
609
  this.engine = typeof opts.engine === "function" ? opts.engine() : opts.engine;
613
610
  this.options = opts;
614
- if (typeof opts.compressionFormat === "undefined")
615
- this.compressionFormat = opts.compressionFormat = ((_a = opts.encodeData) == null ? void 0 : _a[0]) ?? "deflate-raw";
616
- if (typeof opts.compressionFormat === "string") {
617
- this.encodeData = [opts.compressionFormat, async (data) => await compress(data, opts.compressionFormat, "string")];
618
- this.decodeData = [opts.compressionFormat, async (data) => await compress(data, opts.compressionFormat, "string")];
619
- } else if ("encodeData" in opts && "decodeData" in opts && Array.isArray(opts.encodeData) && Array.isArray(opts.decodeData)) {
611
+ if ("encodeData" in opts && "decodeData" in opts && Array.isArray(opts.encodeData) && Array.isArray(opts.decodeData)) {
620
612
  this.encodeData = [opts.encodeData[0], opts.encodeData[1]];
621
613
  this.decodeData = [opts.decodeData[0], opts.decodeData[1]];
622
614
  this.compressionFormat = opts.encodeData[0] ?? null;
@@ -624,9 +616,17 @@ var DataStore = class {
624
616
  this.encodeData = void 0;
625
617
  this.decodeData = void 0;
626
618
  this.compressionFormat = null;
627
- } else
628
- throw new TypeError("Either `compressionFormat` or `encodeData` and `decodeData` have to be set and valid, but not all three at a time. Please refer to the documentation for more info.");
629
- this.engine.setDataStoreOptions(opts);
619
+ } else {
620
+ const fmt = typeof opts.compressionFormat === "string" ? opts.compressionFormat : "deflate-raw";
621
+ this.compressionFormat = fmt;
622
+ this.encodeData = [fmt, async (data) => await compress(data, fmt, "string")];
623
+ this.decodeData = [fmt, async (data) => await decompress(data, fmt, "string")];
624
+ }
625
+ this.engine.setDataStoreOptions({
626
+ id: this.id,
627
+ encodeData: this.encodeData,
628
+ decodeData: this.decodeData
629
+ });
630
630
  }
631
631
  //#region loadData
632
632
  /**
@@ -651,8 +651,8 @@ var DataStore = class {
651
651
  migrateFmt(`_uucfg-${this.id}`, `__ds-${this.id}-dat`, oldData);
652
652
  if (!isNaN(oldVer))
653
653
  migrateFmt(`_uucfgver-${this.id}`, `__ds-${this.id}-ver`, oldVer);
654
- if (typeof oldEnc === "boolean")
655
- migrateFmt(`_uucfgenc-${this.id}`, `__ds-${this.id}-enf`, oldEnc === true ? this.compressionFormat ?? null : null);
654
+ if (typeof oldEnc === "boolean" || oldEnc === "true" || oldEnc === "false" || typeof oldEnc === "number" || oldEnc === "0" || oldEnc === "1")
655
+ migrateFmt(`_uucfgenc-${this.id}`, `__ds-${this.id}-enf`, [0, "0", true, "true"].includes(oldEnc) ? this.compressionFormat ?? null : null);
656
656
  else {
657
657
  promises.push(this.engine.setValue(`__ds-${this.id}-enf`, this.compressionFormat));
658
658
  promises.push(this.engine.deleteValue(`_uucfgenc-${this.id}`));
@@ -674,7 +674,7 @@ var DataStore = class {
674
674
  }
675
675
  const storedData = storedDataRaw ?? JSON.stringify(this.defaultData);
676
676
  const encodingFmt = String(await this.engine.getValue(`__ds-${this.id}-enf`, null));
677
- const isEncoded = encodingFmt !== "null" && encodingFmt !== "false";
677
+ const isEncoded = encodingFmt !== "null" && encodingFmt !== "false" && encodingFmt !== "0" && encodingFmt !== "" && encodingFmt !== null;
678
678
  let saveData = false;
679
679
  if (isNaN(storedFmtVer)) {
680
680
  await this.engine.setValue(`__ds-${this.id}-ver`, storedFmtVer = this.formatVersion);
@@ -781,7 +781,7 @@ var DataStore = class {
781
781
  }
782
782
  }
783
783
  await Promise.allSettled([
784
- this.engine.setValue(`__ds-${this.id}-dat`, await this.engine.serializeData(newData)),
784
+ this.engine.setValue(`__ds-${this.id}-dat`, await this.engine.serializeData(newData, this.encodingEnabled())),
785
785
  this.engine.setValue(`__ds-${this.id}-ver`, lastFmtVer),
786
786
  this.engine.setValue(`__ds-${this.id}-enf`, this.compressionFormat)
787
787
  ]);
@@ -810,7 +810,7 @@ var DataStore = class {
810
810
  return;
811
811
  const parsed = await this.engine.deserializeData(data, isEncoded);
812
812
  await Promise.allSettled([
813
- this.engine.setValue(`__ds-${this.id}-dat`, await this.engine.serializeData(parsed)),
813
+ this.engine.setValue(`__ds-${this.id}-dat`, await this.engine.serializeData(parsed, this.encodingEnabled())),
814
814
  this.engine.setValue(`__ds-${this.id}-ver`, fmtVer),
815
815
  this.engine.setValue(`__ds-${this.id}-enf`, this.compressionFormat),
816
816
  this.engine.deleteValue(`__ds-${id}-dat`),
@@ -1,4 +1,4 @@
1
- // node_modules/.pnpm/@sv443-network+coreutils@3.0.2/node_modules/@sv443-network/coreutils/dist/CoreUtils.mjs
1
+ // node_modules/.pnpm/@sv443-network+coreutils@3.0.4/node_modules/@sv443-network/coreutils/dist/CoreUtils.mjs
2
2
  function bitSetHas(bitSet, checkVal) {
3
3
  return (bitSet & checkVal) === checkVal;
4
4
  }
@@ -482,7 +482,6 @@ var DataStore = class {
482
482
  * @param opts The options for this DataStore instance
483
483
  */
484
484
  constructor(opts) {
485
- var _a;
486
485
  this.id = opts.id;
487
486
  this.formatVersion = opts.formatVersion;
488
487
  this.defaultData = opts.defaultData;
@@ -491,16 +490,9 @@ var DataStore = class {
491
490
  this.migrations = opts.migrations;
492
491
  if (opts.migrateIds)
493
492
  this.migrateIds = Array.isArray(opts.migrateIds) ? opts.migrateIds : [opts.migrateIds];
494
- this.encodeData = opts.encodeData;
495
- this.decodeData = opts.decodeData;
496
493
  this.engine = typeof opts.engine === "function" ? opts.engine() : opts.engine;
497
494
  this.options = opts;
498
- if (typeof opts.compressionFormat === "undefined")
499
- this.compressionFormat = opts.compressionFormat = ((_a = opts.encodeData) == null ? void 0 : _a[0]) ?? "deflate-raw";
500
- if (typeof opts.compressionFormat === "string") {
501
- this.encodeData = [opts.compressionFormat, async (data) => await compress(data, opts.compressionFormat, "string")];
502
- this.decodeData = [opts.compressionFormat, async (data) => await compress(data, opts.compressionFormat, "string")];
503
- } else if ("encodeData" in opts && "decodeData" in opts && Array.isArray(opts.encodeData) && Array.isArray(opts.decodeData)) {
495
+ if ("encodeData" in opts && "decodeData" in opts && Array.isArray(opts.encodeData) && Array.isArray(opts.decodeData)) {
504
496
  this.encodeData = [opts.encodeData[0], opts.encodeData[1]];
505
497
  this.decodeData = [opts.decodeData[0], opts.decodeData[1]];
506
498
  this.compressionFormat = opts.encodeData[0] ?? null;
@@ -508,9 +500,17 @@ var DataStore = class {
508
500
  this.encodeData = void 0;
509
501
  this.decodeData = void 0;
510
502
  this.compressionFormat = null;
511
- } else
512
- throw new TypeError("Either `compressionFormat` or `encodeData` and `decodeData` have to be set and valid, but not all three at a time. Please refer to the documentation for more info.");
513
- this.engine.setDataStoreOptions(opts);
503
+ } else {
504
+ const fmt = typeof opts.compressionFormat === "string" ? opts.compressionFormat : "deflate-raw";
505
+ this.compressionFormat = fmt;
506
+ this.encodeData = [fmt, async (data) => await compress(data, fmt, "string")];
507
+ this.decodeData = [fmt, async (data) => await decompress(data, fmt, "string")];
508
+ }
509
+ this.engine.setDataStoreOptions({
510
+ id: this.id,
511
+ encodeData: this.encodeData,
512
+ decodeData: this.decodeData
513
+ });
514
514
  }
515
515
  //#region loadData
516
516
  /**
@@ -535,8 +535,8 @@ var DataStore = class {
535
535
  migrateFmt(`_uucfg-${this.id}`, `__ds-${this.id}-dat`, oldData);
536
536
  if (!isNaN(oldVer))
537
537
  migrateFmt(`_uucfgver-${this.id}`, `__ds-${this.id}-ver`, oldVer);
538
- if (typeof oldEnc === "boolean")
539
- migrateFmt(`_uucfgenc-${this.id}`, `__ds-${this.id}-enf`, oldEnc === true ? this.compressionFormat ?? null : null);
538
+ if (typeof oldEnc === "boolean" || oldEnc === "true" || oldEnc === "false" || typeof oldEnc === "number" || oldEnc === "0" || oldEnc === "1")
539
+ migrateFmt(`_uucfgenc-${this.id}`, `__ds-${this.id}-enf`, [0, "0", true, "true"].includes(oldEnc) ? this.compressionFormat ?? null : null);
540
540
  else {
541
541
  promises.push(this.engine.setValue(`__ds-${this.id}-enf`, this.compressionFormat));
542
542
  promises.push(this.engine.deleteValue(`_uucfgenc-${this.id}`));
@@ -558,7 +558,7 @@ var DataStore = class {
558
558
  }
559
559
  const storedData = storedDataRaw ?? JSON.stringify(this.defaultData);
560
560
  const encodingFmt = String(await this.engine.getValue(`__ds-${this.id}-enf`, null));
561
- const isEncoded = encodingFmt !== "null" && encodingFmt !== "false";
561
+ const isEncoded = encodingFmt !== "null" && encodingFmt !== "false" && encodingFmt !== "0" && encodingFmt !== "" && encodingFmt !== null;
562
562
  let saveData = false;
563
563
  if (isNaN(storedFmtVer)) {
564
564
  await this.engine.setValue(`__ds-${this.id}-ver`, storedFmtVer = this.formatVersion);
@@ -665,7 +665,7 @@ var DataStore = class {
665
665
  }
666
666
  }
667
667
  await Promise.allSettled([
668
- this.engine.setValue(`__ds-${this.id}-dat`, await this.engine.serializeData(newData)),
668
+ this.engine.setValue(`__ds-${this.id}-dat`, await this.engine.serializeData(newData, this.encodingEnabled())),
669
669
  this.engine.setValue(`__ds-${this.id}-ver`, lastFmtVer),
670
670
  this.engine.setValue(`__ds-${this.id}-enf`, this.compressionFormat)
671
671
  ]);
@@ -694,7 +694,7 @@ var DataStore = class {
694
694
  return;
695
695
  const parsed = await this.engine.deserializeData(data, isEncoded);
696
696
  await Promise.allSettled([
697
- this.engine.setValue(`__ds-${this.id}-dat`, await this.engine.serializeData(parsed)),
697
+ this.engine.setValue(`__ds-${this.id}-dat`, await this.engine.serializeData(parsed, this.encodingEnabled())),
698
698
  this.engine.setValue(`__ds-${this.id}-ver`, fmtVer),
699
699
  this.engine.setValue(`__ds-${this.id}-enf`, this.compressionFormat),
700
700
  this.engine.deleteValue(`__ds-${id}-dat`),
@@ -183,7 +183,7 @@ __export(lib_exports, {
183
183
  });
184
184
  module.exports = __toCommonJS(lib_exports);
185
185
 
186
- // node_modules/.pnpm/@sv443-network+coreutils@3.0.2/node_modules/@sv443-network/coreutils/dist/CoreUtils.mjs
186
+ // node_modules/.pnpm/@sv443-network+coreutils@3.0.4/node_modules/@sv443-network/coreutils/dist/CoreUtils.mjs
187
187
  function bitSetHas(bitSet, checkVal) {
188
188
  return (bitSet & checkVal) === checkVal;
189
189
  }
@@ -681,40 +681,40 @@ var DataStore = class {
681
681
  __publicField(this, "cachedData");
682
682
  __publicField(this, "migrations");
683
683
  __publicField(this, "migrateIds", []);
684
- var _a2, _b, _c;
685
- var _a;
684
+ var _a, _b;
686
685
  this.id = opts.id;
687
686
  this.formatVersion = opts.formatVersion;
688
687
  this.defaultData = opts.defaultData;
689
- this.memoryCache = Boolean((_a2 = opts.memoryCache) != null ? _a2 : true);
688
+ this.memoryCache = Boolean((_a = opts.memoryCache) != null ? _a : true);
690
689
  this.cachedData = this.memoryCache ? opts.defaultData : {};
691
690
  this.migrations = opts.migrations;
692
691
  if (opts.migrateIds)
693
692
  this.migrateIds = Array.isArray(opts.migrateIds) ? opts.migrateIds : [opts.migrateIds];
694
- this.encodeData = opts.encodeData;
695
- this.decodeData = opts.decodeData;
696
693
  this.engine = typeof opts.engine === "function" ? opts.engine() : opts.engine;
697
694
  this.options = opts;
698
- if (typeof opts.compressionFormat === "undefined")
699
- this.compressionFormat = opts.compressionFormat = (_b = (_a = opts.encodeData) == null ? void 0 : _a[0]) != null ? _b : "deflate-raw";
700
- if (typeof opts.compressionFormat === "string") {
701
- this.encodeData = [opts.compressionFormat, (data) => __async(this, null, function* () {
702
- return yield compress(data, opts.compressionFormat, "string");
703
- })];
704
- this.decodeData = [opts.compressionFormat, (data) => __async(this, null, function* () {
705
- return yield compress(data, opts.compressionFormat, "string");
706
- })];
707
- } else if ("encodeData" in opts && "decodeData" in opts && Array.isArray(opts.encodeData) && Array.isArray(opts.decodeData)) {
695
+ if ("encodeData" in opts && "decodeData" in opts && Array.isArray(opts.encodeData) && Array.isArray(opts.decodeData)) {
708
696
  this.encodeData = [opts.encodeData[0], opts.encodeData[1]];
709
697
  this.decodeData = [opts.decodeData[0], opts.decodeData[1]];
710
- this.compressionFormat = (_c = opts.encodeData[0]) != null ? _c : null;
698
+ this.compressionFormat = (_b = opts.encodeData[0]) != null ? _b : null;
711
699
  } else if (opts.compressionFormat === null) {
712
700
  this.encodeData = void 0;
713
701
  this.decodeData = void 0;
714
702
  this.compressionFormat = null;
715
- } else
716
- throw new TypeError("Either `compressionFormat` or `encodeData` and `decodeData` have to be set and valid, but not all three at a time. Please refer to the documentation for more info.");
717
- this.engine.setDataStoreOptions(opts);
703
+ } else {
704
+ const fmt = typeof opts.compressionFormat === "string" ? opts.compressionFormat : "deflate-raw";
705
+ this.compressionFormat = fmt;
706
+ this.encodeData = [fmt, (data) => __async(this, null, function* () {
707
+ return yield compress(data, fmt, "string");
708
+ })];
709
+ this.decodeData = [fmt, (data) => __async(this, null, function* () {
710
+ return yield decompress(data, fmt, "string");
711
+ })];
712
+ }
713
+ this.engine.setDataStoreOptions({
714
+ id: this.id,
715
+ encodeData: this.encodeData,
716
+ decodeData: this.decodeData
717
+ });
718
718
  }
719
719
  //#region loadData
720
720
  /**
@@ -741,8 +741,8 @@ var DataStore = class {
741
741
  migrateFmt(`_uucfg-${this.id}`, `__ds-${this.id}-dat`, oldData);
742
742
  if (!isNaN(oldVer))
743
743
  migrateFmt(`_uucfgver-${this.id}`, `__ds-${this.id}-ver`, oldVer);
744
- if (typeof oldEnc === "boolean")
745
- migrateFmt(`_uucfgenc-${this.id}`, `__ds-${this.id}-enf`, oldEnc === true ? (_a = this.compressionFormat) != null ? _a : null : null);
744
+ if (typeof oldEnc === "boolean" || oldEnc === "true" || oldEnc === "false" || typeof oldEnc === "number" || oldEnc === "0" || oldEnc === "1")
745
+ migrateFmt(`_uucfgenc-${this.id}`, `__ds-${this.id}-enf`, [0, "0", true, "true"].includes(oldEnc) ? (_a = this.compressionFormat) != null ? _a : null : null);
746
746
  else {
747
747
  promises.push(this.engine.setValue(`__ds-${this.id}-enf`, this.compressionFormat));
748
748
  promises.push(this.engine.deleteValue(`_uucfgenc-${this.id}`));
@@ -764,7 +764,7 @@ var DataStore = class {
764
764
  }
765
765
  const storedData = storedDataRaw != null ? storedDataRaw : JSON.stringify(this.defaultData);
766
766
  const encodingFmt = String(yield this.engine.getValue(`__ds-${this.id}-enf`, null));
767
- const isEncoded = encodingFmt !== "null" && encodingFmt !== "false";
767
+ const isEncoded = encodingFmt !== "null" && encodingFmt !== "false" && encodingFmt !== "0" && encodingFmt !== "" && encodingFmt !== null;
768
768
  let saveData = false;
769
769
  if (isNaN(storedFmtVer)) {
770
770
  yield this.engine.setValue(`__ds-${this.id}-ver`, storedFmtVer = this.formatVersion);
@@ -877,7 +877,7 @@ var DataStore = class {
877
877
  }
878
878
  }
879
879
  yield Promise.allSettled([
880
- this.engine.setValue(`__ds-${this.id}-dat`, yield this.engine.serializeData(newData)),
880
+ this.engine.setValue(`__ds-${this.id}-dat`, yield this.engine.serializeData(newData, this.encodingEnabled())),
881
881
  this.engine.setValue(`__ds-${this.id}-ver`, lastFmtVer),
882
882
  this.engine.setValue(`__ds-${this.id}-enf`, this.compressionFormat)
883
883
  ]);
@@ -908,7 +908,7 @@ var DataStore = class {
908
908
  return;
909
909
  const parsed = yield this.engine.deserializeData(data, isEncoded);
910
910
  yield Promise.allSettled([
911
- this.engine.setValue(`__ds-${this.id}-dat`, yield this.engine.serializeData(parsed)),
911
+ this.engine.setValue(`__ds-${this.id}-dat`, yield this.engine.serializeData(parsed, this.encodingEnabled())),
912
912
  this.engine.setValue(`__ds-${this.id}-ver`, fmtVer),
913
913
  this.engine.setValue(`__ds-${this.id}-enf`, this.compressionFormat),
914
914
  this.engine.deleteValue(`__ds-${id}-dat`),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sv443-network/userutils",
3
3
  "libName": "UserUtils",
4
- "version": "10.0.2",
4
+ "version": "10.0.4",
5
5
  "description": "General purpose DOM/GreaseMonkey library that allows you to register listeners for when CSS selectors exist, intercept events, create persistent & synchronous data stores, modify the DOM more easily and much more",
6
6
  "main": "dist/UserUtils.mjs",
7
7
  "module": "dist/UserUtils.mjs",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "homepage": "https://github.com/Sv443-Network/UserUtils",
35
35
  "dependencies": {
36
- "@sv443-network/coreutils": "3.0.2",
36
+ "@sv443-network/coreutils": "3.0.4",
37
37
  "nanoevents": "9.1.0"
38
38
  },
39
39
  "devDependencies": {