Skip to content

feat: add IPNS publish strategy completion events - #1103

Open
nikhilkumar1612 wants to merge 2 commits into
ipfs:mainfrom
nikhilkumar1612:main
Open

feat: add IPNS publish strategy completion events#1103
nikhilkumar1612 wants to merge 2 commits into
ipfs:mainfrom
nikhilkumar1612:main

Conversation

@nikhilkumar1612

Copy link
Copy Markdown

Title

feat: add IPNS publish strategy completion events

Description

Fixes #959.

Adds a publish progress event that fires after each IPNS publishing strategy has completed. This lets callers distinguish between local persistence, Helia routing publication, and any custom routing strategies finishing.

This also addresses the behavior requested in #945 by moving the ipns:routing:datastore:put progress event so it is emitted after the datastore batch commit completes. Callers can now wait for the local IPNS record to be persisted without needing to wait for slower network publishing such as DHT publication.

Changes include:

  • add ipns:publish:strategy:success
  • include the completed strategy name, routing key, and IPNS record in the event detail
  • emit strategy completion after each router put(...) resolves
  • emit a local strategy completion event for offline publishing
  • emit ipns:routing:datastore:put after local datastore commit
  • add tests for online strategy completion, offline local-only completion, and datastore post-commit timing

Notes & open questions

The new strategy completion event uses a single event type, ipns:publish:strategy:success, with the completed strategy identified in evt.detail.strategy.

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

@nikhilkumar1612
nikhilkumar1612 requested a review from a team as a code owner August 10, 2026 15:32

@tabcat tabcat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikhilkumar1612 apologies for the wait. main change i think should be included is replacing #publishStrategySuccess with a function outside of the class called withStrategyProgressEvents that is used to call any router we need to. it wraps the call with start, success, and error events for ipns:publish:strategy namespace. see comments for more detail. otherwise looks pretty good thanks 🙏

Comment thread packages/ipns/src/ipns/publisher.ts Outdated
}))
}

#strategyName (router: IPNSRouting): string {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a pure function and doesnt need to exist on the class. can be moved to the bottom on this file as its own function.

Comment thread packages/ipns/src/index.ts Outdated
/**
* The routing key the IPNS record was published under.
*/
routingKey: Uint8Array

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be better off to include the keyName and publicKey fields here instead of routingKey.

Comment thread packages/ipns/src/local-store.ts Outdated
batch.put(ipnsMetadataKey(routingKey), IPNSPublishMetadata.encode(options.metadata))
}
await batch.commit(options)
options.onProgress?.(new CustomProgressEvent('ipns:routing:datastore:put'))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we are adding the start/success/failure events for each router call we can remove the changes to this file.

Comment thread packages/ipns/src/index.ts Outdated

export type PublishProgressEvents =
ProgressEvent<'ipns:publish:start'> |
ProgressEvent<'ipns:publish:strategy:success', IPNSPublishStrategyResult> |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets add ipns:publish:strategy:{start|success|failure} events.

Comment thread packages/ipns/src/ipns/publisher.ts Outdated
}
})

this.#publishStrategySuccess('LocalStoreRouting()', routingKey, record, options)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed after we call localStore strategy with the withProgressEvents caller.

Comment thread packages/ipns/src/ipns/publisher.ts Outdated
}
}

#publishStrategySuccess (strategy: string, routingKey: Uint8Array, record: IPNSEntry, options: PublishOptions): void {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets move this out of the class, name it withStrategyProgressEvents and have it call onProgress with start|success|error events.

shape can be something like:

withStrategyProgressEvents (detail: IPNSPublishStrategyDetail, options: ProgressOptions, fn: () => unknown): Promise<void>

Comment thread packages/ipns/src/ipns/publisher.ts Outdated
}
})

this.#publishStrategySuccess(this.#strategyName(r), routingKey, record, options)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed after adding withProgressEvents caller.

Comment thread packages/ipns/src/ipns/publisher.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map these to a withProgressEvents call.

Comment thread packages/ipns/src/ipns/publisher.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call this with withProgressEvents.

Comment thread packages/ipns/src/index.ts Outdated
publicKey: PublicKey
}

export interface IPNSPublishStrategyResult {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to IPNSPublishStrategyDetail

@nikhilkumar1612

Copy link
Copy Markdown
Author

@nikhilkumar1612 apologies for the wait. main change i think should be included is replacing #publishStrategySuccess with a function outside of the class called withStrategyProgressEvents that is used to call any router we need to. it wraps the call with start, success, and error events for ipns:publish:strategy namespace. see comments for more detail. otherwise looks pretty good thanks 🙏

Thanks for the review, I have made the necessary changes. @tabcat

@nikhilkumar1612
nikhilkumar1612 requested a review from tabcat August 31, 2026 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

progress events on completion for each ipns publishing strategy

2 participants