-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
nest_land.ts
52 lines (44 loc) 路 1.44 KB
/
nest_land.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Provider, Versions } from "../provider.ts";
export interface NestLandProviderOptions {
name?: string;
}
export class NestLandProvider extends Provider {
name = "nest.land";
private readonly repositoryUrl = "https://nest.land/package/";
private readonly registryUrl = "https://x.nest.land/";
private readonly moduleName?: string;
constructor({ name }: NestLandProviderOptions = {}) {
super();
this.moduleName = name;
}
async getVersions(
name: string,
): Promise<Versions> {
const response = await fetch(`https://nest.land/api/package-client`, {
method: "post",
body: JSON.stringify({ data: { name: this.moduleName ?? name } }),
headers: { "Content-Type": "application/json" },
});
if (!response.ok) {
throw new Error(
"couldn't fetch the latest version - try again after sometime",
);
}
const { body: { latestVersion, packageUploadNames } } = await response
.json();
return {
latest: latestVersion,
versions: packageUploadNames.map(
(version: string) =>
version.replace(new RegExp(`^${this.moduleName ?? name}@`), ""),
).reverse(),
};
}
getRepositoryUrl(name: string): string {
return new URL(`${this.moduleName ?? name}/`, this.repositoryUrl).href;
}
getRegistryUrl(name: string, version: string): string {
return new URL(`${this.moduleName ?? name}@${version}/`, this.registryUrl)
.href;
}
}