-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44f8b1d
commit a87db59
Showing
8 changed files
with
135 additions
and
157 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
import { exceptionHandler } from '@apillon/sdk'; | ||
|
||
export function enumValues(enumType: any): string[] { | ||
return Object.values(enumType) | ||
.filter((value) => typeof value === 'number') | ||
.map((value) => value.toString()); | ||
} | ||
|
||
export async function withErrorHandler(handler: () => Promise<any>) { | ||
try { | ||
await handler(); | ||
} catch (err) { | ||
exceptionHandler(err); | ||
} | ||
} |
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
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,68 +1,59 @@ | ||
import { Storage, exceptionHandler } from '@apillon/sdk'; | ||
import { Storage } from '@apillon/sdk'; | ||
import { GlobalOptions } from '../../lib/types'; | ||
import { paginate } from '../../lib/options'; | ||
import { withErrorHandler } from '../../lib/utils'; | ||
|
||
export async function listIpnsNames(optsWithGlobals: GlobalOptions) { | ||
await withErrorHandler(async (storage: Storage) => { | ||
const data = await storage | ||
await withErrorHandler(async () => { | ||
const data = await new Storage(optsWithGlobals) | ||
.bucket(optsWithGlobals.bucketUuid) | ||
.listIpnsNames(paginate(optsWithGlobals)); | ||
data.items = data.items.map((w) => w.serialize()); | ||
console.log(data); | ||
}, optsWithGlobals); | ||
}); | ||
} | ||
|
||
export async function createIpns(optsWithGlobals: GlobalOptions) { | ||
await withErrorHandler(async (storage: Storage) => { | ||
const ipns = await storage.bucket(optsWithGlobals.bucketUuid).createIpns({ | ||
name: optsWithGlobals.name, | ||
description: optsWithGlobals.description, | ||
cid: optsWithGlobals.cid, | ||
}); | ||
await withErrorHandler(async () => { | ||
const ipns = await new Storage(optsWithGlobals) | ||
.bucket(optsWithGlobals.bucketUuid) | ||
.createIpns({ | ||
name: optsWithGlobals.name, | ||
description: optsWithGlobals.description, | ||
cid: optsWithGlobals.cid, | ||
}); | ||
console.log('IPNS record created successfully'); | ||
console.log(ipns.serialize()); | ||
}, optsWithGlobals); | ||
}); | ||
} | ||
|
||
export async function getIpns(optsWithGlobals: GlobalOptions) { | ||
await withErrorHandler(async (storage: Storage) => { | ||
const ipns = await storage | ||
await withErrorHandler(async () => { | ||
const ipns = await new Storage(optsWithGlobals) | ||
.bucket(optsWithGlobals.bucketUuid) | ||
.ipns(optsWithGlobals.ipnsUuid) | ||
.get(); | ||
console.log(ipns.serialize()); | ||
}, optsWithGlobals); | ||
}); | ||
} | ||
|
||
export async function publishIpns(optsWithGlobals: GlobalOptions) { | ||
await withErrorHandler(async (storage: Storage) => { | ||
const ipns = await storage | ||
await withErrorHandler(async () => { | ||
const ipns = await new Storage(optsWithGlobals) | ||
.bucket(optsWithGlobals.bucketUuid) | ||
.ipns(optsWithGlobals.ipnsUuid) | ||
.publish(optsWithGlobals.cid); | ||
console.log('IPNS published successfully'); | ||
console.log(ipns.serialize()); | ||
}, optsWithGlobals); | ||
}); | ||
} | ||
|
||
export async function deleteIpns(optsWithGlobals: GlobalOptions) { | ||
await withErrorHandler(async (storage: Storage) => { | ||
await storage | ||
await withErrorHandler(async () => { | ||
await new Storage(optsWithGlobals) | ||
.bucket(optsWithGlobals.bucketUuid) | ||
.ipns(optsWithGlobals.ipnsUuid) | ||
.delete(); | ||
console.log('IPNS record deleted successfully'); | ||
}, optsWithGlobals); | ||
} | ||
|
||
async function withErrorHandler( | ||
handler: (module: Storage) => Promise<any>, | ||
optsWithGlobals: GlobalOptions, | ||
) { | ||
try { | ||
const module = new Storage(optsWithGlobals); | ||
await handler(module); | ||
} catch (err) { | ||
exceptionHandler(err); | ||
} | ||
}); | ||
} |
Oops, something went wrong.