Skip to content

Move subscription shape typing from useTaiiNet to useSubscription#2

Open
Copilot wants to merge 9 commits into
masterfrom
copilot/convert-library-to-typescript-module
Open

Move subscription shape typing from useTaiiNet to useSubscription#2
Copilot wants to merge 9 commits into
masterfrom
copilot/convert-library-to-typescript-module

Conversation

Copilot AI commented May 26, 2026

Copy link
Copy Markdown

useTaiiNet previously carried a global subscription type map, which constrained consumers to one shape map per hook instance. This change moves shape typing to useSubscription, so each subscription call can declare its own typed shape map.

  • API typing shift

    • Removed the generic type parameter from useTaiiNet / UseTaiiNetResult.
    • Updated UseSubscriptionHook so typed mapping is declared per invocation (useSubscription<...>()), while preserving the untyped fallback overload.
  • Consumer-facing usage update

    • Updated React usage to type subscriptions at call sites instead of hook creation time.
    • This supports multiple differently shaped subscriptions from the same useTaiiNet() result.
  • Docs and contract alignment

    • Updated README examples to reflect the new API surface.
    • Updated hook test typing to match the new call pattern.
type FeedSubscriptions = {
  tweet: { type: "tweet"; body: string };
};

const { useSubscription } = useTaiiNet();
const { data, sendData } = useSubscription<FeedSubscriptions>({ type: "tweet" }, { backlog: true });

Copilot AI changed the title Convert TaiiNet into a typed TypeScript package with core test coverage Remove legacy JS sources and introduce React-first useTaiiNet API May 29, 2026
Copilot finished work on behalf of Taiiwo May 29, 2026 08:43
Copilot AI requested a review from Taiiwo May 29, 2026 08:43
Copilot AI changed the title Remove legacy JS sources and introduce React-first useTaiiNet API Add GitHub Actions test workflow for push/PR events May 29, 2026
Copilot finished work on behalf of Taiiwo May 29, 2026 09:17
@Taiiwo Taiiwo marked this pull request as ready for review May 29, 2026 09:42
Copilot AI review requested due to automatic review settings May 29, 2026 09:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds GitHub Actions test automation, but the reviewed diff also includes a TypeScript/ESM package rewrite with React hook support, tests, and updated documentation.

Changes:

  • Adds Node-based package metadata, TypeScript config, lockfile, and CI test workflow.
  • Replaces legacy root JavaScript modules with typed src/ implementations.
  • Adds Vitest coverage for core query, event, subscription, TaiiNet, and React hook behavior.

Reviewed changes

Copilot reviewed 23 out of 26 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
.github/workflows/tests.yml Adds CI workflow running npm ci and npm test.
.gitignore Ignores Node/TypeScript build artifacts.
README.md Updates usage docs for TypeScript package and React hook API.
package.json Defines package exports, scripts, dependencies, and metadata.
package-lock.json Locks npm dependency graph.
tsconfig.json Adds TypeScript compiler configuration.
src/BacklogSubscription.ts Adds typed backlog subscription implementation.
src/EventBase.ts Adds typed event emitter base.
src/Subscription.ts Adds typed subscription implementation.
src/Swarm.ts Adds typed peer swarm implementation.
src/TaiiNet.ts Adds typed TaiiNet client implementation.
src/index.ts Adds public package exports.
src/query.ts Adds query matching helpers.
src/types.ts Adds shared TypeScript interfaces.
src/useTaiiNet.ts Adds React hook wrapper for TaiiNet.
tests/EventBase.test.ts Adds EventBase tests.
tests/Subscription.test.ts Adds Subscription and BacklogSubscription tests.
tests/TaiiNet.test.ts Adds TaiiNet client tests.
tests/helpers.ts Adds test doubles for signaller/swarm/channel behavior.
tests/query.test.ts Adds query helper tests.
tests/useTaiiNet.test.tsx Adds React hook tests.
BacklogSubscription.js Removes legacy JavaScript implementation.
EventBase.js Removes legacy JavaScript implementation.
Subscription.js Removes legacy JavaScript implementation.
Swarm.js Removes legacy JavaScript implementation.
TaiiNet.js Removes legacy JavaScript implementation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +34 to +39
if (data.type === "backlog") {
if (!this.messages.includes(serializedMessage)) {
this.messages.push(serializedMessage);
}
this.trigger("data", data.data, event);
return;
Comment on lines +49 to +51
for (const message of this.messages) {
this.swarm.send_direct(requestingPeer, JSON.parse(message) as QueryRecord, "backlog");
}
Comment thread src/useTaiiNet.ts
Comment on lines +41 to +42
if (!clientRef.current) {
clientRef.current = createClient ? createClient(taiiNetOptions) : new TaiiNet(taiiNetOptions);
Copilot AI changed the title Add GitHub Actions test workflow for push/PR events Refactor React API to provider-initialized, typed stateful subscriptions May 29, 2026
Copilot finished work on behalf of Taiiwo May 29, 2026 10:01
Copilot AI changed the title Refactor React API to provider-initialized, typed stateful subscriptions Move subscription shape typing from useTaiiNet to useSubscription May 30, 2026
Copilot finished work on behalf of Taiiwo May 30, 2026 00:23
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.

3 participants