UNPKG

@dappnode/dappnodesdk

Version:

dappnodesdk is a tool to make the creation of new dappnode packages as simple as possible. It helps to initialize and publish in ethereum blockchain

64 lines 2.51 kB
import { prettyPinataPinName } from "../utils/format.js"; import { groupPinsByBranch } from "./utils.js"; // This file has all logic for the pin strategy of DAppNode packages // In development, builds will be uploaded on each push on a PR // only the latest commit of each branch will stay pinned. // // When PR is merged (and the branch is deleted) all pins associated to // that branch will be unpinned export function getPinMetadata(manifest, gitHead) { const upstreamVersion = Array.isArray(manifest.upstreamVersion) ? manifest.upstreamVersion.join(", ") : manifest.upstreamVersion; return { name: prettyPinataPinName(manifest, gitHead), keyvalues: { dnpName: manifest.name, version: manifest.version, upstreamVersion: upstreamVersion, commit: gitHead ? gitHead.commit : undefined, branch: gitHead ? gitHead.branch : undefined } }; } /** * Fetch pins with same branch, assuming pins are upload with `DnpPinMetadata` metadata. * Can be used to clean all pins from a deleted branch with */ export async function fetchPinsWithBranch(pinata, manifest, gitHead) { const pinsWithSameBranch = await pinata.pinList({ keyvalues: { dnpName: { value: manifest.name, op: "eq" }, branch: { value: gitHead.branch, op: "eq" } } }); return pinsWithSameBranch.map(pin => { var _a; return ({ commit: (_a = pin.metadata.keyvalues) === null || _a === void 0 ? void 0 : _a.commit, ipfsHash: pin.ipfs_pin_hash }); }); } /** * Fetch pins with same branch, assuming pins are upload with `DnpPinMetadata` metadata. * Can be used to clean all pins from a deleted branch with */ export async function fetchPinsGroupedByBranch(pinata, manifest) { const pins = await pinata.pinList({ keyvalues: { dnpName: { value: manifest.name, op: "eq" } } }); return groupPinsByBranch(pins); } /** * Fetch pins with same branch, assuming pins are upload with `DnpPinMetadata` metadata. * Returns only pins associated with a commit that is previous * to current commit from `gitHead`, according to `git --is-ancestor`. */ export async function fetchPinsWithBranchToDelete(pinata, manifest, gitHead) { const pins = await fetchPinsWithBranch(pinata, manifest, gitHead); return pins.filter(pin => pin.commit && pin.commit !== gitHead.commit); } //# sourceMappingURL=index.js.map