From 83f70f5cb78a8446f7f3bded774bae540cf29618 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Mon, 17 Mar 2025 21:26:41 +0100 Subject: [PATCH] feat: expose editId --- .changeset/dry-files-clap.md | 5 +++++ README.md | 2 +- src/ipfs.ts | 21 ++++++++++++++++----- 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 .changeset/dry-files-clap.md diff --git a/.changeset/dry-files-clap.md b/.changeset/dry-files-clap.md new file mode 100644 index 0000000..caf883a --- /dev/null +++ b/.changeset/dry-files-clap.md @@ -0,0 +1,5 @@ +--- +"@graphprotocol/grc-20": minor +--- + +return object with cid and editId from Ipfs.publishEdit diff --git a/README.md b/README.md index 1b95872..43bc70a 100644 --- a/README.md +++ b/README.md @@ -235,7 +235,7 @@ We've abstracted the IPFS publishing and binary encoding into a single API. ```ts import { Ipfs } from '@graphprotocol/grc-20'; -const cid = await Ipfs.publishEdit({ +const { cid } = await Ipfs.publishEdit({ name: 'Edit name', ops: ops, author: '0x000000000000000000000000000000000000', diff --git a/src/ipfs.ts b/src/ipfs.ts index 536c2f5..d071649 100644 --- a/src/ipfs.ts +++ b/src/ipfs.ts @@ -9,7 +9,8 @@ import { Micro } from 'effect'; import { gzipSync } from 'fflate'; import { imageSize } from 'image-size'; -import { EditProposal } from '../proto.js'; +import { Edit, EditProposal } from '../proto.js'; +import { Id } from './id.js'; import type { Op } from './types.js'; class IpfsUploadError extends Error { @@ -22,6 +23,13 @@ type PublishEditProposalParams = { author: string; }; +type PublishEditResult = { + // IPFS CID representing the edit prefixed with `ipfs://` + cid: string; + // The ID of the edit + editId: Id; +}; + /** * Generates correct protobuf encoding for an Edit and uploads it to IPFS. * @@ -29,7 +37,7 @@ type PublishEditProposalParams = { * ```ts * import { IPFS } from '@graphprotocol/grc-20'; * - * const cid = await IPFS.publishEdit({ + * const { cid, editId } = await IPFS.publishEdit({ * name: 'Edit name', * ops: ops, * author: '0x000000000000000000000000000000000000', @@ -37,9 +45,9 @@ type PublishEditProposalParams = { * ``` * * @param args arguments for publishing an edit to IPFS {@link PublishEditProposalParams} - * @returns IPFS CID representing the edit prefixed with `ipfs://` + * @returns - {@link PublishEditResult} */ -export async function publishEdit(args: PublishEditProposalParams): Promise { +export async function publishEdit(args: PublishEditProposalParams): Promise { const { name, ops, author } = args; const edit = EditProposal.encode({ name, ops, author }); @@ -48,7 +56,10 @@ export async function publishEdit(args: PublishEditProposalParams): Promise