Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 4d54a7c

Browse files
committed
chore: update remote pinning api implementation
1 parent 86f8c4c commit 4d54a7c

File tree

12 files changed

+522
-67
lines changed

12 files changed

+522
-67
lines changed
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "dist"
5+
},
6+
"include": [
7+
"src",
8+
"type",
9+
"package.json",
10+
]
11+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Common options across all cancellable requests.
3+
*/
4+
export interface AbortOptions {
5+
/**
6+
* Can be provided to a function that starts a long running task, which will
7+
* be aborted when signal is triggered.
8+
*/
9+
signal?: AbortSignal
10+
/**
11+
* Can be provided to a function that starts a long running task, which will
12+
* be aborted after provided timeout (in ms).
13+
*/
14+
timeout?: number
15+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
import * as Basic from './basic'
3+
import * as PinRemote from './pin/remote'
4+
5+
export { Basic, PinRemote }
6+
7+
// class Foo implements PinRemote.API {
8+
9+
// }
10+
// // export { Basic, PinRemote }
11+
12+
// declare namespace Lib {
13+
// import { AbortOptions } from '/basic'
14+
// import { API } from './pin/remote'
15+
// }
16+
17+
// export { Lib }
18+
19+
// // export { Lib }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import CID from 'cids'
2+
import Multiaddr from 'multiaddr'
3+
import { API as Service } from './remote/service'
4+
import { AbortOptions } from '../basic'
5+
6+
export interface API {
7+
/**
8+
* API for configuring remote pinning services.
9+
*/
10+
service: Service
11+
12+
/**
13+
* Stores an IPFS object(s) from a given path to a remote pinning service.
14+
*/
15+
add(cid:CID, options:AddOptions & AbortOptions):Promise<Pin>
16+
17+
/**
18+
* Returns a list of matching pins on the remote pinning service.
19+
*/
20+
ls(query: Query & AbortOptions): AsyncIterable<Pin>
21+
22+
/**
23+
* Removes a single pin object matching query allowing it to be garbage
24+
* collected (if needed). Will error if multiple pins mtach provided
25+
* query. To remove all matches use `rmAll` instead.
26+
*/
27+
rm(query: Query & AbortOptions): Promise<void>
28+
29+
/**
30+
* Removes all pin object that match given query allowing them to be garbage
31+
* collected if needed.
32+
*/
33+
rmAll(query: Query & AbortOptions): Promise<void>
34+
}
35+
36+
export interface AddOptions extends RemoteServiceOptions {
37+
/**
38+
* Optional name for pinned data; can be used for lookups later (max 255
39+
* characters)
40+
*/
41+
name?: string
42+
43+
/**
44+
* Optional list of multiaddrs known to provide the data (max 20).
45+
*/
46+
origins?: Multiaddr[]
47+
48+
/**
49+
* If true, will add to the queue on the remote service and return
50+
* RequestID immediately. If false or amitted will wait until pinned on the
51+
* remote service.
52+
*/
53+
background?: boolean
54+
}
55+
56+
/**
57+
* Reperesents query for matching pin objects.
58+
*/
59+
export interface Query extends RemoteServiceOptions {
60+
/**
61+
* If provided, will only include pin objects that have a CID from the given
62+
* set.
63+
*/
64+
cid?: CID[]
65+
/**
66+
* If passed, will only include pin objects with names that have this name
67+
* (case-sensitive, exact match).
68+
*/
69+
name?: string
70+
71+
/**
72+
* Customize the text matching strategy applied when name filter is present.
73+
* Uses "exact" if omitted.
74+
*/
75+
match?: TextMatchingStrategy
76+
77+
/**
78+
* Return pin objects for pins that have one of the specified status values.
79+
* If omitted treated as ["pinned"]
80+
*/
81+
status?: Status[]
82+
}
83+
84+
export interface RemoteServiceOptions {
85+
/**
86+
* Name of the remote pinning service to use.
87+
*/
88+
service: string
89+
}
90+
91+
export interface Pin {
92+
status: Status
93+
cid: CID
94+
name?: string
95+
}
96+
97+
export type TextMatchingStrategy =
98+
| 'exact'
99+
| 'iexact'
100+
| 'partial'
101+
| 'ipartial'
102+
export type Status =
103+
| 'queued'
104+
| 'pinning'
105+
| 'pinned'
106+
| 'failed'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { AbortOptions } from '../../basic'
2+
3+
export interface API {
4+
/**
5+
* Registers remote pinning service with a given name. Errors if service
6+
* with the given name is already registered.
7+
*/
8+
add(name: string, credentials:Credentials & AbortOptions): Promise<void>
9+
10+
/**
11+
* Unregisteres remote pinning service with a given name. If service with such
12+
* name isn't registerede this is a noop.
13+
*/
14+
rm(name: string, options?:AbortOptions):Promise<void>
15+
16+
/**
17+
* List registered remote pinning services.
18+
*/
19+
ls(options:ListOptions & AbortOptions):Promise<RemotePinService[]>
20+
}
21+
22+
export interface Credentials {
23+
/**
24+
* Service URL
25+
*/
26+
url: URL
27+
/**
28+
* Service key
29+
*/
30+
key: string
31+
}
32+
33+
export interface RemotePinService {
34+
/**
35+
* Service name
36+
*/
37+
service: string
38+
/**
39+
* Service URL
40+
*/
41+
url: URL
42+
/**
43+
* Pin count on the remote service. It is fetched from the remote service and
44+
* is done only if `pinCount` option is used. Furthermore it may not be
45+
* present if service was unreachable.
46+
*/
47+
stat?: Stat
48+
}
49+
50+
export interface ListOptions {
51+
/**
52+
* If `true` will try to fetch and include current pin count on the remote
53+
* service.
54+
*/
55+
stat?: boolean
56+
}
57+
58+
export type Stat = ValidStat | InvalidStat
59+
60+
type ValidStat = {
61+
status: 'valid'
62+
pinCount: PinCount
63+
}
64+
65+
type InvalidStat = {
66+
status: 'invalid'
67+
pinCount?: void
68+
}
69+
export type PinCount = {
70+
queued: number,
71+
pinning: number,
72+
pinned: number,
73+
failed: number
74+
}
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
'use strict'
22

3+
const Remote = require('./remote')
4+
35
module.exports = config => ({
46
add: require('./add')(config),
57
addAll: require('./add-all')(config),
68
ls: require('./ls')(config),
79
rm: require('./rm')(config),
810
rmAll: require('./rm-all')(config),
9-
remote: require('./remote')(config)
11+
remote: new Remote(config)
1012
})

packages/ipfs-http-client/src/pin/remote/add.js

-20
This file was deleted.

0 commit comments

Comments
 (0)