~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/pds.js

An atproto PDS in JavaScript, for Cloudflare Workers and Node

0
0
main
33 lines · 831 B Raw History
// @pdsjs/spaces/path - record path and set hash element formatting.

/**
 * @param {string} collection
 * @param {string} rkey
 * @returns {string}
 */
export function formatRecordPath(collection, rkey) {
  return `${collection}/${rkey}`;
}

/**
 * @param {string} path
 * @returns {{collection: string, rkey: string}}
 */
export function parseRecordPath(path) {
  const parts = path.split('/');
  if (parts.length !== 2 || !parts[0] || !parts[1]) {
    throw new Error(`invalid record path: ${path}`);
  }
  return { collection: parts[0], rkey: parts[1] };
}

/**
 * The element a record contributes to a repo's set hash.
 * @param {string} collection
 * @param {string} rkey
 * @param {string} cid
 * @returns {string}
 */
export function formatSetHashElement(collection, rkey, cid) {
  return `${collection}/${rkey}/${cid}`;
}