From bd27bf47f1ac4e9f528637e1d5bd6f2afcbdd467 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 5 Aug 2022 09:35:28 -0400 Subject: [PATCH] *Add dist --- dist/index.d.ts | 7 +++++ dist/index.d.ts.map | 1 + dist/index.js | 66 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 dist/index.d.ts create mode 100644 dist/index.d.ts.map create mode 100644 dist/index.js diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..71f478c --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,7 @@ +import type { DataFn } from "libskynet"; +export declare function refreshGatewayList(): Promise; +export declare function fetchIpfs(hash: string, path: string | undefined, headers: {} | undefined, receiveUpdate: DataFn): Promise; +export declare function statIpfs(hash: string, path?: string, headers?: {}): Promise; +export declare function fetchIpns(hash: string, path: string | undefined, headers: {} | undefined, receiveUpdate: DataFn): Promise; +export declare function statIpns(hash: string, path?: string, headers?: {}): Promise; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/index.d.ts.map b/dist/index.d.ts.map new file mode 100644 index 0000000..dd09653 --- /dev/null +++ b/dist/index.d.ts.map @@ -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"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..b380fcc --- /dev/null +++ b/dist/index.js @@ -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); +}