Stack (file)

In an Akord vault, files and other assets are organized as 'stacks'. A stack represents one single file and all the subsequent revisions that may come after.

create(vaultId, file, options)

  • vaultId (string, required)

  • file (FileLike, required) - file object - web: File, node: NodeJs.File (Blob implementation; web like File)

  • options (StackCreateOptions, optional)

  • returns Promise<{ stackId, transactionId, uri }> - Promise with new stack id & corresponding transaction id

example
const { stackId } = await akord.stack.create(vaultId, "./photo.jpg");

See Next.js file upload showcase here

import(vaultId, fileTxId)

Create new stack from an existing arweave file transaction:

  • vaultId (string, required)

  • fileTxId (string, required) - arweave file transaction id reference

  • options (NodeCreateOptions, optional) - parent id, etc.

  • returns Promise<{ stackId, transactionId }> - Promise with new stack id & corresponding transaction id

example
const { stackId } = await akord.stack.import(vaultId, "kzGxbFW_oJ3PyYneRs9cPrChQ-k-8Fym5k9PCZNJ_HA");

rename(stackId, name)

  • stackId (string, required)

  • name (string, required) - new stack name

  • returns Promise<{ transactionId }> - Promise with corresponding transaction id

example
const { transactionId } = await akord.stack.rename(stackId, "new name for your stack");

uploadRevision(stackId, file)

  • stackId (string, required)

  • file (FileLike, required) - file object

  • options (FileUploadOptions, optional)

  • returns Promise<{ transactionId }> - Promise with corresponding transaction id

example
const { uri } = await akord.stack.uploadRevision(stackId, "./photo.jpg");

revoke(stackId)

  • stackId (string, required)

  • returns Promise<{ transactionId }> - Promise with corresponding transaction id

example
const { transactionId } = await akord.stack.revoke(stackId);

move(stackId, parentId)

  • stackId (string, required)

  • parentId (string, required) - new parent folder id

  • returns Promise<{ transactionId }> - Promise with corresponding transaction id

example
// create new folder
const { folderId } = await akord.folder.create(vaultId, "new folder");
// move the stack to newly created folder
const { transactionId } = await akord.stack.move(stackId, folderId);

restore(stackId)

  • stackId (string, required)

  • returns Promise<{ transactionId }> - Promise with corresponding transaction id

example
const { transactionId } = await akord.stack.restore(stackId);

delete(stackId)

  • stackId (string, required)

  • returns Promise<{ transactionId }> - Promise with corresponding transaction id

example
const { transactionId } = await akord.stack.delete(stackId);

get(stackId, options)

  • stackId (string, required)

  • options (GetOptions optional)

  • returns Promise<Stack> - Promise with the stack object

example
const stack = await akord.stack.get(stackId);

listAll(vaultId, options)

  • vaultId (string, required)

  • options (ListOptions, optional)

  • returns Promise<Array<Stack>> - Promise with all stacks within given vault

example
const stacks = await akord.stack.listAll(vaultId);

list(vaultId, options)

  • vaultId (string, required)

  • options (ListOptions, optional)

  • returns Promise<{ items, nextToken }> - Promise with paginated stacks within given vault

example
// retrieve first 100 stacks for the vault
const { items } = await akord.stack.list(vaultId);

// retrieve first 20 stacks for the vault
const { items } = await akord.stack.list(vaultId, { limit: 20 });

// iterate through all stacks
let token = null;
let stacks = [];
do {
  const { items, nextToken } = await akord.stack.list(vaultId, { nextToken: token });
  stacks = stacks.concat(items);
  token = nextToken;
} while (token);

getVersion(stackId, index)

Get file stack version by index, return the latest version by default:

  • stackId (string, required)

  • index (number, optional) - file version index

  • returns Promise<{ name: string, data: ArrayBuffer }> - Promise with file name & data buffer

example
// get the latest stack version
const { name: fileName, data: fileBuffer } = await akord.stack.getVersion(stackId);

// get the first stack version
const { name: fileName, data: fileBuffer } = await akord.stack.getVersion(stackId, 0);

getUri(stackId, type, index)

Get stack file uri by index, return the latest arweave uri by default:

  • stackId (string, required)

  • type (StorageType, optional) - storage type, default to arweave

  • index (number, optional) - file version index, default to latest

  • returns Promise<string> - Promise with stack file uri

example
// get the arweave uri for the latest file version
const arweaveUri = await akord.stack.getUri(stackId);

// get the arweave uri for the first file version
const arweaveUri = await akord.stack.getUri(stackId, 0);

Last updated