*Add dist

This commit is contained in:
Derrick Hammer 2022-08-05 09:35:28 -04:00
parent 0ecd526fa0
commit bd27bf47f1
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 74 additions and 0 deletions

7
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
import type { DataFn } from "libskynet";
export declare function refreshGatewayList(): Promise<any>;
export declare function fetchIpfs(hash: string, path: string | undefined, headers: {} | undefined, receiveUpdate: DataFn): Promise<any>;
export declare function statIpfs(hash: string, path?: string, headers?: {}): Promise<any>;
export declare function fetchIpns(hash: string, path: string | undefined, headers: {} | undefined, receiveUpdate: DataFn): Promise<any>;
export declare function statIpns(hash: string, path?: string, headers?: {}): Promise<any>;
//# sourceMappingURL=index.d.ts.map

1
dist/index.d.ts.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAsBxC,wBAAsB,kBAAkB,iBAQvC;AAED,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,EACZ,IAAI,oBAAK,EACT,OAAO,gBAAK,EACZ,aAAa,EAAE,MAAM,gBAMtB;AAED,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,SAAK,EAAE,OAAO,KAAK,gBAKnE;AAED,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,EACZ,IAAI,oBAAK,EACT,OAAO,gBAAK,EACZ,aAAa,EAAE,MAAM,gBAMtB;AAED,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,SAAK,EAAE,OAAO,KAAK,gBAKnE"}

66
dist/index.js vendored Normal file
View File

@ -0,0 +1,66 @@
import { ipnsPath, ipfsPath } from "is-ipfs";
const IPFS_MODULE = "AQDr2iGYEiMKIdb14w7dxwxFYBo3LaYc0mAuRKXsF2w9OQ";
let callModule, connectModule;
async function loadLibs() {
if (callModule && connectModule) {
return;
}
if (typeof window !== "undefined" && window?.document) {
const pkg = await import("libkernel");
callModule = pkg.callModule;
connectModule = pkg.connectModule;
}
else {
const pkg = await import("libkmodule");
callModule = pkg.callModule;
connectModule = pkg.connectModule;
}
}
export async function refreshGatewayList() {
const [resp, err] = await doCall("refreshGatewayList");
if (err) {
throw new Error(err);
}
return resp;
}
export async function fetchIpfs(hash, path = "", headers = {}, receiveUpdate) {
if (!ipfsPath(`/ipfs/{${hash}`)) {
throw new Error("Invalid hash");
}
return doFetch("fetchIpfs", { hash, path, headers }, receiveUpdate);
}
export async function statIpfs(hash, path = "", headers = {}) {
if (!ipfsPath(`/ipfs/{${hash}`)) {
throw new Error("Invalid hash");
}
return doFetch("statIpfs", { hash, path, headers });
}
export async function fetchIpns(hash, path = "", headers = {}, receiveUpdate) {
if (!ipnsPath(`/ipns/{${hash}`)) {
throw new Error("Invalid hash");
}
return doFetch("fetchIpns", { hash, path, headers }, receiveUpdate);
}
export async function statIpns(hash, path = "", headers = {}) {
if (!ipnsPath(`/ipns/{${hash}`)) {
throw new Error("Invalid hash");
}
return doFetch("statIpns", { hash, path, headers });
}
async function doFetch(method, data, receiveUpdate) {
let [resp, err] = await doCall(method, data, receiveUpdate);
if (typeof err?.then === "function") {
[resp, err] = await err;
}
if (err) {
throw new Error(err);
}
return resp;
}
async function doCall(method, data, receiveUpdate) {
await loadLibs();
if (receiveUpdate) {
return connectModule(IPFS_MODULE, method, data, receiveUpdate);
}
return callModule(IPFS_MODULE, method, data);
}