Skip to content

Commit ac05926

Browse files
author
Kaushik Shetty
committed
chore: add return types and jsdoc to store methods
1 parent a93d899 commit ac05926

File tree

3 files changed

+32
-31
lines changed

3 files changed

+32
-31
lines changed

src/stack/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class Stack {
1616

1717
_connection: any
1818
_data: StackDetail
19-
ContentType: any // TODO: change it
20-
Asset: any // TODO: change it
19+
ContentType: any
20+
Asset: any
2121
private _currentBranch: BranchDetail | null = null;
2222

2323

src/store.ts

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,43 +12,46 @@ class Store {
1212
constructor(connection: typeof postRobot) {
1313
this._connection = connection;
1414
}
15+
1516
/**
16-
* Gets the value of key
17-
* @param {string} key Key of the stored data
18-
* @example extension.store.get('key').then((value) => console.log(value)) // will log value for the given key
19-
* @return {external:Promise}
17+
* Retrieves the stored data value associated with the given key.
18+
* @param {string} key - The key of the stored data.
19+
* @example
20+
* extension.store.get('key').then((value) => console.log(value)); // Logs the value for the given key
21+
* @returns {Promise<any>} A Promise that resolves to the value associated with the key.
2022
*/
21-
get(key: string) {
23+
get(key: string): Promise<any> {
2224
if (!key || typeof key !== "string") {
2325
throw new Error("Kindly provide valid parameters");
2426
}
2527
return this._connection
2628
.sendToParent("store", { action: "get", key })
27-
.then((event: { data: GenericObjectType }) => Promise.resolve(event.data))
29+
.then((event: { data: GenericObjectType }) =>
30+
Promise.resolve(event.data)
31+
)
2832
.catch(onError);
2933
}
3034

3135
/**
32-
* Gets an object with all the stored key-value pairs.
33-
* @example extension.store.getAll().then((obj) => obj)
34-
* @return {external:Promise}
36+
* Retrieves an object with all the stored key-value pairs.
37+
* @example await extension.store.getAll(); // Returns a Promise containing the stored data.
38+
* @return {Promise<GenericObjectType>} A Promise that resolves with the stored key-value pairs as an object.
3539
*/
36-
getAll() {
40+
getAll(): Promise<GenericObjectType> {
3741
return this._connection
3842
.sendToParent("store", { action: "getAll" })
3943
.then(({ data = {} }) => Promise.resolve(data))
4044
.catch(onError);
4145
}
4246

4347
/**
44-
* Sets the value of a key
45-
* @param {string} key Key of the stored data.
46-
* @param {*} value Data to be stored.
47-
* @example extension.store.set('key', 'value').then((success) => console.log(success)) // will log ‘true’ when value is set
48-
* @return {external:Promise}
48+
* Sets the value of a key.
49+
* @param {string} key The key for the stored data.
50+
* @param {*} value The data to be stored.
51+
* @example await extension.store.set('key', 'value'); // Returns a Promise that resolves with the success status.
52+
* @return {Promise<boolean>} A Promise that resolves with the success status (true when the value was set successfully).
4953
*/
50-
51-
set(key: string, value: string) {
54+
set(key: string, value: any): Promise<boolean> {
5255
if (!key || !value || typeof key !== "string") {
5356
throw new Error("Kindly provide valid parameters");
5457
}
@@ -59,13 +62,12 @@ class Store {
5962
}
6063

6164
/**
62-
* Removes the value of a key
63-
* @param {string} key Key of the data to be removed from the store
64-
* @example extension.store.remove('key').then((success) => console.log(success)) // will log ‘true’ when value is removed
65-
* @return {external:Promise}
65+
* Removes the value associated with a key from the store.
66+
* @param {string} key The key whose value needs to be removed.
67+
* @example await extension.store.remove('key'); // Returns a Promise that resolves with the success status.
68+
* @return {Promise<boolean>} A Promise that resolves with the success status (true when the value was removed successfully).
6669
*/
67-
68-
remove(key: string) {
70+
remove(key: string): Promise<boolean> {
6971
if (!key || typeof key !== "string") {
7072
throw new Error("Kindly provide valid parameters");
7173
}
@@ -76,12 +78,11 @@ class Store {
7678
}
7779

7880
/**
79-
* Clears all the stored data of an extension
80-
* @example extension.store.clear().then((success) => console.log(success)) // will log ‘true’ when values are cleared
81-
* @return {external:Promise}
81+
* Clears all the stored data of an extension.
82+
* @example await extension.store.clear(); // Returns a Promise that resolves with the success status.
83+
* @returns {Promise<boolean>} A Promise that resolves with the success status (true when all values are cleared successfully).
8284
*/
83-
84-
clear() {
85+
clear(): Promise<boolean> {
8586
return this._connection
8687
.sendToParent("store", { action: "clear" })
8788
.then(() => Promise.resolve(true))

src/types/stack.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export declare interface StackDetail {
2222
live_preview?: Partial<{
2323
enabled: boolean;
2424
"default-env": string;
25-
"default-url": string; // TODO: correct it
25+
"default-url": string;
2626
}>;
2727
language_fallback?: boolean;
2828
};

0 commit comments

Comments
 (0)