biketrack-app/node_modules/@ethersphere/bee-js/dist/mjs/modules/pinning.js

106 lines
2.3 KiB
JavaScript

var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P ? value : new P(function (resolve) {
resolve(value);
});
}
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { http } from "../utils/http.js";
const PINNING_ENDPOINT = 'pins';
/**
* Pin data with given reference
*
* @param ky Ky instance for given Bee class instance
* @param reference Bee data reference
*/
export function pin(ky, reference) {
return __awaiter(this, void 0, void 0, function* () {
yield http(ky, {
method: 'post',
responseType: 'json',
path: `${PINNING_ENDPOINT}/${reference}`
});
});
}
/**
* Unpin data with given reference
*
* @param ky Ky instance for given Bee class instance
* @param reference Bee data reference
*/
export function unpin(ky, reference) {
return __awaiter(this, void 0, void 0, function* () {
yield http(ky, {
method: 'delete',
responseType: 'json',
path: `${PINNING_ENDPOINT}/${reference}`
});
});
}
/**
* Get pin status for specific address.
*
* @param ky Ky instance
* @param reference
* @throws Error if given address is not pinned
*/
export function getPin(ky, reference) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield http(ky, {
method: 'get',
responseType: 'json',
path: `${PINNING_ENDPOINT}/${reference}`
});
return response.data;
});
}
/**
* Get list of all pins
*
* @param ky Ky instance
*/
export function getAllPins(ky) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield http(ky, {
method: 'get',
responseType: 'json',
path: `${PINNING_ENDPOINT}`
});
const result = response.data.references;
if (result === null) {
return [];
}
return result;
});
}