New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: client perma cache #127
Conversation
1df1fb3
to
a9ec835
Compare
packages/client/docs/perma-cache.md
Outdated
> Put multiple URLs into nftstorage.link perma-cache | ||
|
||
```ts | ||
put(urls: string[]): PromiseResult<PermaCacheEntry>[]> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put(urls: string[]): PromiseResult<PermaCacheEntry>[]> | |
put(urls: string[]): Promise<PromiseResult<PermaCacheEntry>[]> |
...although I'd be cautious exposing PromiseResult
...You could make it a bit more erganomic by returning a custom type:
put(urls: string[]): Promise<CacheResult[]>
Where CacheResult
is:
interface CacheSuccess {
url: string
size: number
insertedAt: string
}
interface CacheFailure {
url: string
error: string
}
type CacheResult = CacheSuccess | CacheFailure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think this is a good call 👍🏼
packages/client/docs/perma-cache.md
Outdated
> Delete multiple URLs into nftstorage.link perma-cache | ||
|
||
```ts | ||
delete(urls: string[]): PromiseResult<PermaCacheDeletedEntry>[]> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete(urls: string[]): PromiseResult<PermaCacheDeletedEntry>[]> | |
delete(urls: string[]): Promise<PromiseResult<PermaCacheDeletedEntry>[]> |
packages/client/docs/perma-cache.md
Outdated
// value: { | ||
// url: 'https://bafkreidyeivj7adnnac6ljvzj2e3rd5xdw3revw4da7mx2ckrstapoupoq.ipfs.nftstorage.link', | ||
// success: true | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here:
delete(urls: string[]): Promise<CacheDeleteResult>
When is success
false? It should be an error
message no?
interface CacheDeleteSuccess {
url: string
}
interface CacheDeleteFailure {
url: string
error: string
}
type CacheDeleteResult = CacheDeleteSuccess | CacheDeleteFailure
packages/client/docs/perma-cache.md
Outdated
> Get perma-cache account status | ||
|
||
```ts | ||
status(): omise<PermaCacheStatus> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since put
, delete
and list
are top level I would have assumed status
was relating to a cached item - i.e. for getting the cache status of a given URL, not getting account related information.
status(): omise<PermaCacheStatus> | |
accountInfo(): Promise<AccountInfo> |
The endpoint should maybe be /account
instead also?
Deploying with Cloudflare Pages
|
8d1e2e6
to
13a8e8f
Compare
Co-authored-by: Alan Shaw <alan.shaw@protocol.ai>
6c6cf57
to
958c78d
Compare
BREAKING CHANGE: GET /perma-cache/status renamed to /perma-cache/account
958c78d
to
5cf0c1e
Compare
@alanshaw renamed API route as you suggest, we are still in private beta. Thinking if we should keep /perma-cache/status for now as deprecated, or just get it out right away. What do you think? |
It's the same response right? I'd maybe just stick a redirect in for now... |
packages/client/src/perma-cache.js
Outdated
// @ts-ignore p-settle will always handle error internally | ||
return cacheResults.map((cacheResult) => cacheResult.value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I'd do the error handling in this map
, then you lose a level of indentation above and I think don't need the @ts-ignore
:
// @ts-ignore p-settle will always handle error internally | |
return cacheResults.map((cacheResult) => cacheResult.value) | |
return cacheResults.map((r, i) => { | |
return r.reason ? { url: urls[i], error: r.reason.message } : r.value | |
}) |
packages/client/src/perma-cache.js
Outdated
return { | ||
...res, | ||
url, // decoded | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
url
should be in the response no?
return { | |
...res, | |
url, // decoded | |
} | |
return res |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, the issue was in the mock 🤦🏼
Co-authored-by: Alan Shaw <alan.shaw@protocol.ai>
b2ee5c6
to
b134d81
Compare
packages/client/src/perma-cache.js
Outdated
endpoint | ||
) | ||
} else { | ||
// @ts-ignore typescript complains about URL type cannot be undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bah, maybe just while(true)
, move entry yielding above this conditional and break
if !link
?
This PR adds perma-cache client to client package. There are potential improvements on the pipeline (like converting given URLs to nftstorage.link if they are IPFS urls), but keeping scope smaller for initial implementation.
It includes:
Closes #92
BREAKING CHANGE: GET /perma-cache/status renamed to /perma-cache/account