wacom 21.1.25 → 21.2.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.
- package/README.md +106 -151
- package/fesm2022/wacom.mjs +295 -317
- package/fesm2022/wacom.mjs.map +1 -1
- package/package.json +34 -89
- package/types/wacom.d.ts +198 -220
package/README.md
CHANGED
|
@@ -713,224 +713,179 @@ httpService.unlock();
|
|
|
713
713
|
|
|
714
714
|
## [Store Service](#store-service)
|
|
715
715
|
|
|
716
|
-
|
|
716
|
+
`StoreService` provides a unified, async-first API for working with storage (localStorage by default or a custom provider via config).
|
|
717
|
+
It supports raw values, safe JSON handling, key prefixing, and optional lifecycle hooks.
|
|
717
718
|
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
#### `_prefix: string`
|
|
721
|
-
|
|
722
|
-
The prefix for storage keys.
|
|
719
|
+
---
|
|
723
720
|
|
|
724
|
-
###
|
|
721
|
+
### Key features
|
|
725
722
|
|
|
726
|
-
|
|
723
|
+
- async/await everywhere (no separate `*Async` methods)
|
|
724
|
+
- optional side-effects via `options`
|
|
725
|
+
- automatic JSON corruption handling
|
|
726
|
+
- configurable storage backend
|
|
727
|
+
- prefix support for namespacing
|
|
727
728
|
|
|
728
|
-
|
|
729
|
-
**Parameters**:
|
|
729
|
+
---
|
|
730
730
|
|
|
731
|
-
|
|
731
|
+
### Prefixing keys
|
|
732
732
|
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
```Typescript
|
|
736
|
-
storeService.setPrefix('app_');
|
|
733
|
+
```ts
|
|
734
|
+
storeService.setPrefix("app_");
|
|
737
735
|
```
|
|
738
736
|
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
Sets a value in storage.
|
|
737
|
+
All keys will be stored as `app_<key>` (plus global config prefix if defined).
|
|
742
738
|
|
|
743
|
-
|
|
739
|
+
---
|
|
744
740
|
|
|
745
|
-
|
|
746
|
-
- `value` (string): The value to store.
|
|
747
|
-
- `callback` (function): The callback to execute on success.
|
|
748
|
-
- `errCallback` (function): The callback to execute on error.
|
|
741
|
+
### set
|
|
749
742
|
|
|
750
|
-
|
|
743
|
+
Stores a raw string value.
|
|
751
744
|
|
|
752
|
-
```
|
|
753
|
-
storeService.set(
|
|
745
|
+
```ts
|
|
746
|
+
await storeService.set("token", "abc123");
|
|
754
747
|
```
|
|
755
748
|
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
Sets a value in storage asynchronously.
|
|
759
|
-
|
|
760
|
-
**Parameters**:
|
|
761
|
-
|
|
762
|
-
- `key` (string): The storage key.
|
|
763
|
-
- `value` (string): The value to store.
|
|
764
|
-
|
|
765
|
-
**Returns**:
|
|
766
|
-
|
|
767
|
-
- `Promise<boolean>`: A promise that resolves to a boolean indicating success.
|
|
768
|
-
|
|
769
|
-
**Example**:
|
|
749
|
+
With hooks:
|
|
770
750
|
|
|
771
|
-
```
|
|
772
|
-
await storeService.
|
|
751
|
+
```ts
|
|
752
|
+
await storeService.set("token", "abc123", {
|
|
753
|
+
onSuccess: () => console.log("saved"),
|
|
754
|
+
onError: console.error,
|
|
755
|
+
});
|
|
773
756
|
```
|
|
774
757
|
|
|
775
|
-
|
|
758
|
+
**Returns:** `Promise<boolean>`
|
|
776
759
|
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
**Parameters**:
|
|
760
|
+
---
|
|
780
761
|
|
|
781
|
-
|
|
782
|
-
- `callback` (function): The callback to execute with the retrieved value.
|
|
783
|
-
- `errCallback` (function): The callback to execute on error.
|
|
762
|
+
### get
|
|
784
763
|
|
|
785
|
-
|
|
764
|
+
Retrieves a raw string value.
|
|
786
765
|
|
|
787
|
-
```
|
|
788
|
-
|
|
766
|
+
```ts
|
|
767
|
+
const token = await storeService.get("token");
|
|
789
768
|
```
|
|
790
769
|
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
Gets a value from storage asynchronously.
|
|
794
|
-
|
|
795
|
-
**Parameters**:
|
|
796
|
-
|
|
797
|
-
- `key` (string): The storage key.
|
|
798
|
-
|
|
799
|
-
**Returns**:
|
|
800
|
-
|
|
801
|
-
- `Promise<string | null>`: A promise that resolves to the retrieved value or `null` if the key is missing.
|
|
802
|
-
|
|
803
|
-
**Example**:
|
|
770
|
+
With hooks:
|
|
804
771
|
|
|
805
|
-
```
|
|
806
|
-
const
|
|
772
|
+
```ts
|
|
773
|
+
const token = await storeService.get("token", {
|
|
774
|
+
onSuccess: (v) => console.log(v),
|
|
775
|
+
onError: console.error,
|
|
776
|
+
});
|
|
807
777
|
```
|
|
808
778
|
|
|
809
|
-
|
|
779
|
+
**Returns:** `Promise<string | null>`
|
|
810
780
|
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
**Parameters**:
|
|
781
|
+
---
|
|
814
782
|
|
|
815
|
-
|
|
816
|
-
- `value` (any): The value to store.
|
|
817
|
-
- `callback` (function): The callback to execute on success.
|
|
818
|
-
- `errCallback` (function): The callback to execute on error.
|
|
783
|
+
### setJson
|
|
819
784
|
|
|
820
|
-
|
|
785
|
+
Stores a JSON-serializable value.
|
|
821
786
|
|
|
822
|
-
```
|
|
823
|
-
storeService.setJson(
|
|
787
|
+
```ts
|
|
788
|
+
await storeService.setJson("profile", { name: "Den", role: "dev" });
|
|
824
789
|
```
|
|
825
790
|
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
Sets a JSON value in storage asynchronously.
|
|
829
|
-
|
|
830
|
-
**Parameters**:
|
|
831
|
-
|
|
832
|
-
- `key` (string): The storage key.
|
|
833
|
-
- `value` (any): The value to store.
|
|
791
|
+
With hooks:
|
|
834
792
|
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
```Typescript
|
|
842
|
-
await storeService.setJsonAsync('key', { data: 'value' });
|
|
793
|
+
```ts
|
|
794
|
+
await storeService.setJson("profile", user, {
|
|
795
|
+
onSuccess: () => console.log("saved"),
|
|
796
|
+
onError: console.error,
|
|
797
|
+
});
|
|
843
798
|
```
|
|
844
799
|
|
|
845
|
-
|
|
800
|
+
**Returns:** `Promise<boolean>`
|
|
846
801
|
|
|
847
|
-
|
|
802
|
+
---
|
|
848
803
|
|
|
849
|
-
|
|
804
|
+
### getJson
|
|
850
805
|
|
|
851
|
-
|
|
852
|
-
- `callback` (function): The callback to execute with the retrieved value.
|
|
853
|
-
- `errCallback` (function): The callback to execute on error.
|
|
806
|
+
Retrieves a JSON value safely.
|
|
854
807
|
|
|
855
|
-
|
|
808
|
+
- empty or missing → `null` (or `defaultValue`)
|
|
809
|
+
- corrupted JSON → auto-cleared (by default)
|
|
856
810
|
|
|
857
|
-
```
|
|
858
|
-
|
|
811
|
+
```ts
|
|
812
|
+
const profile = await storeService.getJson<User>("profile");
|
|
859
813
|
```
|
|
860
814
|
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
Gets a JSON value from storage asynchronously.
|
|
815
|
+
With defaults and error handling:
|
|
864
816
|
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
- `Promise<T | null>`: A promise that resolves to the retrieved value.
|
|
872
|
-
|
|
873
|
-
**Example**:
|
|
874
|
-
|
|
875
|
-
```Typescript
|
|
876
|
-
const value = await storeService.getJsonAsync('key');
|
|
817
|
+
```ts
|
|
818
|
+
const profile = await storeService.getJson<User>("profile", {
|
|
819
|
+
defaultValue: {},
|
|
820
|
+
onError: console.warn,
|
|
821
|
+
});
|
|
877
822
|
```
|
|
878
823
|
|
|
879
|
-
|
|
824
|
+
Disable auto-clean:
|
|
880
825
|
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
826
|
+
```ts
|
|
827
|
+
await storeService.getJson("profile", {
|
|
828
|
+
clearOnError: false,
|
|
829
|
+
});
|
|
830
|
+
```
|
|
884
831
|
|
|
885
|
-
|
|
886
|
-
- `callback` (function): The callback to execute on success.
|
|
887
|
-
- `errCallback` (function): The callback to execute on error.
|
|
832
|
+
**Returns:** `Promise<T | null>`
|
|
888
833
|
|
|
889
|
-
|
|
834
|
+
---
|
|
890
835
|
|
|
891
|
-
|
|
836
|
+
### remove
|
|
892
837
|
|
|
893
|
-
|
|
838
|
+
Removes a single key.
|
|
894
839
|
|
|
895
|
-
```
|
|
896
|
-
await storeService.remove(
|
|
840
|
+
```ts
|
|
841
|
+
await storeService.remove("token");
|
|
897
842
|
```
|
|
898
843
|
|
|
899
|
-
|
|
844
|
+
With hooks:
|
|
900
845
|
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
846
|
+
```ts
|
|
847
|
+
await storeService.remove("token", {
|
|
848
|
+
onSuccess: () => console.log("removed"),
|
|
849
|
+
onError: console.error,
|
|
850
|
+
});
|
|
851
|
+
```
|
|
904
852
|
|
|
905
|
-
|
|
906
|
-
- `errCallback` (function): The callback to execute on error.
|
|
853
|
+
**Returns:** `Promise<boolean>`
|
|
907
854
|
|
|
908
|
-
|
|
855
|
+
---
|
|
909
856
|
|
|
910
|
-
|
|
857
|
+
### clear
|
|
911
858
|
|
|
912
|
-
|
|
859
|
+
Clears all stored values.
|
|
913
860
|
|
|
914
|
-
```
|
|
915
|
-
await storeService.clear(
|
|
861
|
+
```ts
|
|
862
|
+
await storeService.clear();
|
|
916
863
|
```
|
|
917
864
|
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
Applies the configured prefix to a storage key.
|
|
865
|
+
With hooks:
|
|
921
866
|
|
|
922
|
-
|
|
867
|
+
```ts
|
|
868
|
+
await storeService.clear({
|
|
869
|
+
onSuccess: () => console.log("cleared"),
|
|
870
|
+
onError: console.error,
|
|
871
|
+
});
|
|
872
|
+
```
|
|
923
873
|
|
|
924
|
-
|
|
874
|
+
**Returns:** `Promise<boolean>`
|
|
925
875
|
|
|
926
|
-
|
|
876
|
+
---
|
|
927
877
|
|
|
928
|
-
|
|
878
|
+
### Options object
|
|
929
879
|
|
|
930
|
-
|
|
880
|
+
All methods accept an optional `options` parameter:
|
|
931
881
|
|
|
932
|
-
```
|
|
933
|
-
|
|
882
|
+
```ts
|
|
883
|
+
interface StoreOptions<T = unknown> {
|
|
884
|
+
onSuccess?: (value?: T | null) => void;
|
|
885
|
+
onError?: (err: unknown) => void;
|
|
886
|
+
defaultValue?: T; // getJson only
|
|
887
|
+
clearOnError?: boolean; // getJson only (default: true)
|
|
888
|
+
}
|
|
934
889
|
```
|
|
935
890
|
|
|
936
891
|
## [Meta Service](#meta-service)
|