Skip to content

Commit

Permalink
Merge Storage Function Options (#148)
Browse files Browse the repository at this point in the history
* merge default and parameter options

* added changeset

* Updates ssx-test-app

---------

Co-authored-by: Juliano Cezar Chagas Tavares <[email protected]>
  • Loading branch information
skgbafa and Juliano1612 authored Jul 24, 2023
1 parent 44038f1 commit ad0311d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
5 changes: 5 additions & 0 deletions .changeset/small-hounds-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@spruceid/ssx': patch
---

Updates the way the default options are included in the KeplerStorage module
8 changes: 1 addition & 7 deletions examples/ssx-test-app/src/pages/StorageModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@ function StorageModule({ ssx }: IStorageModule) {
useEffect(() => {
const getContentList = async () => {
const { data } = await ssx.storage.list({ removePrefix: true });
setContentList(
data.map((d: string) => {
const contentArr = d.split('/');
contentArr.shift(); // remove the prefix
return contentArr.join('/');
})
);
setContentList(data);
};
getContentList();
}, [ssx]);
Expand Down
44 changes: 22 additions & 22 deletions packages/ssx-sdk/src/modules/Storage/KeplerStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,36 +152,35 @@ export class KeplerStorage implements IStorage, IKepler {

public async get(
key: string,
options: IStorageGetOptions = {
prefix: this.prefix,
}
options: IStorageGetOptions = {}
): Promise<Response> {
const { prefix, request } = options;
const defaultOptions = {
prefix: this.prefix,
};
const { prefix, request } = { ...defaultOptions, ...options };
return this.orbit.get(`${prefix}/${key}`, request);
}

public async put(
key: string,
value: any,
options: IStoragePutOptions = {
prefix: this.prefix,
}
options: IStoragePutOptions = {}
): Promise<Response> {
const { prefix, request } = options;
return this.orbit.put(`${prefix}/${key}`, value, request);
const defaultOptions = {
prefix: this.prefix,
};
const { prefix, request } = { ...defaultOptions, ...options };
return this.orbit.put(`${prefix || this.prefix}/${key}`, value, request);
}

public async list(
options: IStorageListOptions = {
removePrefix: false,
}
options: IStorageListOptions = {}
): Promise<Response> {
const {
prefix = this.prefix,
path,
request,
removePrefix = false,
} = options;
const defaultOptions = {
prefix: this.prefix,
removePrefix: false,
};
const { prefix, path, request, removePrefix } = { ...defaultOptions, ...options };
const p = path ? `${prefix}/${path}` : `${prefix}/`;
const response = await this.orbit.list(prefix, request);
// remove prefix from keys
Expand All @@ -192,11 +191,12 @@ export class KeplerStorage implements IStorage, IKepler {

public async delete(
key: string,
options: IStorageDeleteOptions = {
prefix: this.prefix,
}
options: IStorageDeleteOptions = {}
): Promise<Response> {
const { prefix, request } = options;
const defaultOptions = {
prefix: this.prefix,
};
const { prefix, request } = { ...defaultOptions, ...options };
return this.orbit.delete(`${prefix}/${key}`, request);
}

Expand Down

0 comments on commit ad0311d

Please sign in to comment.