-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add JSDOC comments and fix grammatical errors
- Loading branch information
1 parent
3d68af2
commit 753ac17
Showing
5 changed files
with
155 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,48 @@ | ||
import type { Serializer, StorageType } from "./storage"; | ||
|
||
/** | ||
* Options interface with optional properties for customizing the store behavior. | ||
* | ||
* @template StoreType - The type of the store. | ||
* @template SerializerType - The type of the serializer. | ||
*/ | ||
export interface Options<StoreType, SerializerType> { | ||
/** Optional serializer for custom serialization logic. */ | ||
serializer?: Serializer<SerializerType>; | ||
/** If true, synchronizes the store across multiple tabs. */ | ||
syncTabs?: boolean; | ||
/** Callback function to handle errors. */ | ||
onError?: (e: unknown) => void; | ||
/** Callback function to handle write errors. */ | ||
onWriteError?: (e: unknown) => void; | ||
/** Callback function to handle parse errors. */ | ||
onParseError?: (newValue: string | null, e: unknown) => void; | ||
/** Function to process values before reading from the store. */ | ||
beforeRead?: (val: SerializerType) => StoreType; | ||
/** Function to process values before writing to the store. */ | ||
beforeWrite?: (val: StoreType) => SerializerType; | ||
} | ||
|
||
/** | ||
* Options interface with required storage property. | ||
* | ||
* @template StoreType - The type of the store. | ||
* @template SerializerType - The type of the serializer. | ||
*/ | ||
export interface OptionsWithRequiredStorage<StoreType, SerializerType> | ||
extends Options<StoreType, SerializerType> { | ||
/** Required storage type. */ | ||
storage: StorageType; | ||
} | ||
|
||
/** | ||
* Deprecated options interface with optional storage property. | ||
* | ||
* @template StoreType - The type of the store. | ||
* @template SerializerType - The type of the serializer. | ||
*/ | ||
export interface DeprecatedOptions<StoreType, SerializerType> | ||
extends Options<StoreType, SerializerType> { | ||
/** Optional storage type. */ | ||
storage?: StorageType; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,28 @@ | ||
/** | ||
* Defines the storage types that were available before the introduction of IndexedDB support. | ||
* This type is associated with the deprecated `persisted()` function. | ||
*/ | ||
export type StorageType = "local" | "session"; | ||
|
||
/** | ||
* Interface representing a serializer. | ||
* | ||
* @template T - The type of the object to be serialized/deserialized. | ||
*/ | ||
export interface Serializer<T> { | ||
/** | ||
* Parses a string and returns an object of type T. | ||
* | ||
* @param text - The string to parse. | ||
* @returns The parsed object. | ||
*/ | ||
parse(text: string): T; | ||
|
||
/** | ||
* Converts an object of type T to a string. | ||
* | ||
* @param object - The object to stringify. | ||
* @returns The stringified object. | ||
*/ | ||
stringify(object: T): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,76 @@ | ||
import { type Writable } from "svelte/store"; | ||
|
||
/** | ||
* Type representing an updater function. | ||
* | ||
* @template T - The type of the value to be updated. | ||
*/ | ||
export type Updater<T> = (value: T) => T; | ||
|
||
/** | ||
* Interface representing the different types of stores. | ||
*/ | ||
export interface Stores { | ||
/** Local storage dictionary. */ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
local: StoreDict<any>; | ||
/** Session storage dictionary. */ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
session: StoreDict<any>; | ||
/** IndexedDB storage dictionary. */ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
indexedDB: StoreDict<any>; | ||
} | ||
|
||
/** | ||
* Type representing a dictionary of persisted stores. | ||
* | ||
* @template T - The type of the value in the store. | ||
*/ | ||
export type StoreDict<T> = { | ||
[key: string]: Persisted<T> | AsyncPersisted<T>; | ||
}; | ||
|
||
/** | ||
* Interface representing an asynchronous persisted store. | ||
* | ||
* @template T - The type of the value in the store. | ||
*/ | ||
export interface AsyncPersisted<T> extends Writable<T> { | ||
/** | ||
* Asynchronously sets the value of the store. | ||
* | ||
* @param value - The new value. | ||
*/ | ||
set: (this: void, value: T) => Promise<void>; | ||
/** Asynchronously resets the store to its initial value. */ | ||
reset: () => Promise<void>; | ||
/** | ||
* Asynchronously updates the value of the store using a callback function. | ||
* | ||
* @param callback - The updater function. | ||
*/ | ||
update: (callback: Updater<T>) => Promise<void>; | ||
} | ||
|
||
/** | ||
* Interface representing a persisted store. | ||
* | ||
* @template T - The type of the value in the store. | ||
*/ | ||
export interface Persisted<T> extends Writable<T> { | ||
/** | ||
* Sets the value of the store. | ||
* | ||
* @param value - The new value. | ||
*/ | ||
set: (this: void, value: T) => void; | ||
/** Resets the store to its initial value. */ | ||
reset: () => void; | ||
/** | ||
* Updates the value of the store using a callback function. | ||
* | ||
* @param callback - The updater function. | ||
*/ | ||
update: (callback: Updater<T>) => void; | ||
} | ||
|
||
export interface Stores { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
local: StoreDict<any>; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
session: StoreDict<any>; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
indexedDB: StoreDict<any>; | ||
} |