Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate eventKind constants #328

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import "websocket-polyfill";
### Basics

```ts
import { eventKind, NostrFetcher } from "nostr-fetch";
import { NostrFetcher } from "nostr-fetch";

const nHoursAgo = (hrs: number): number =>
Math.floor((Date.now() - hrs * 60 * 60 * 1000) / 1000);
Expand All @@ -50,7 +50,7 @@ const relayUrls = [/* relay URLs */];
const postIter = fetcher.allEventsIterator(
relayUrls,
/* filter (kinds, authors, ids, tags) */
{ kinds: [ eventKind.text ] },
{ kinds: [ 1 ] },
/* time range filter (since, until) */
{ since: nHoursAgo(24) },
/* fetch options (optional) */
Expand All @@ -64,7 +64,7 @@ for await (const ev of postIter) {
const allPosts = await fetcher.fetchAllEvents(
relayUrls,
/* filter */
{ kinds: [ eventKind.text ] },
{ kinds: [ 1 ] },
/* time range filter */
{ since: nHoursAgo(24) },
/* fetch options (optional) */
Expand All @@ -75,7 +75,7 @@ const allPosts = await fetcher.fetchAllEvents(
### Various Fetch Methods

```ts
import { eventKind, NostrFetcher } from "nostr-fetch";
import { NostrFetcher } from "nostr-fetch";

const fetcher = NostrFetcher.init();
const relayUrls = [/* relay URLs */];
Expand All @@ -88,7 +88,7 @@ const relayUrls = [/* relay URLs */];
const latestPosts: NostrEvent[] = await fetcher.fetchLatestEvents(
relayUrls,
/* filter */
{ kinds: [ eventKind.text ] },
{ kinds: [ 1 ] },
/* number of events to fetch */
100,
);
Expand All @@ -100,7 +100,7 @@ const latestPosts: NostrEvent[] = await fetcher.fetchLatestEvents(
const lastMetadata: NostrEvent | undefined = await fetcher.fetchLastEvent(
relayUrls,
/* filter */
{ kinds: [ eventKind.metadata ], authors: [ "deadbeef..." ] },
{ kinds: [ 0 ], authors: [ "deadbeef..." ] },
);

// fetches latest 10 text posts from each author in `authors`
Expand All @@ -113,7 +113,7 @@ const postsPerAuthor = fetcher.fetchLatestEventsPerAuthor(
relayUrls,
},
/* filter */
{ kinds: [ eventKind.text ] },
{ kinds: [ 1 ] },
/* number of events to fetch for each author */
10,
);
Expand All @@ -134,7 +134,7 @@ const metadataPerAuthor = fetcher.fetchLastEventPerAuthor(
relayUrls,
}
/* filter */
{ kinds: [ eventKind.metadata ] },
{ kinds: [ 0 ] },
);
for await (const { author, event } of metadataPerAuthor ) {
console.log(`${author}: ${event?.content ?? "not found"}`);
Expand All @@ -152,7 +152,7 @@ npm install @nostr-fetch/adapter-nostr-tools

Then, wrap your relay pool instance with the adapter and pass it to the initializer `NostrFetcher.withCustomPool()`.
```ts
import { eventKind, NostrFetcher } from "nostr-fetch";
import { NostrFetcher } from "nostr-fetch";
import { simplePoolAdapter } from "@nostr-fetch/adapter-nostr-tools";
import { SimplePool } from "nostr-tools";

Expand All @@ -177,7 +177,7 @@ const fetcher = NostrFetcher.withCustomPool(simplePoolAdapter(pool));
### Cancelling by AbortController

```ts
import { eventKind, NostrFecher } from "nostr-fetch"
import { NostrFecher } from "nostr-fetch"

const fetcher = NostrFetcher.init();
const relayUrls = [/* relay URLs */];
Expand Down
4 changes: 2 additions & 2 deletions packages/examples/src/abort.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { eventKind, NostrFetcher } from "nostr-fetch";
import { NostrFetcher } from "nostr-fetch";
import "websocket-polyfill";

import { defaultRelays, nHoursAgo } from "./utils";
Expand All @@ -10,7 +10,7 @@ const main = async () => {
const evIter = fetcher.allEventsIterator(
defaultRelays,
{
kinds: [eventKind.text],
kinds: [1],
},
{
since: nHoursAgo(24),
Expand Down
4 changes: 2 additions & 2 deletions packages/examples/src/allEventsIter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NostrFetcher, eventKind } from "nostr-fetch";
import { NostrFetcher } from "nostr-fetch";
import "websocket-polyfill";

import { defaultRelays, nHoursAgo } from "./utils";
Expand All @@ -11,7 +11,7 @@ const main = async () => {
const eventsIter = fetcher.allEventsIterator(
defaultRelays,
{
kinds: [eventKind.text],
kinds: [1],
},
{
since: nHoursAgo(1),
Expand Down
4 changes: 2 additions & 2 deletions packages/examples/src/backpressure.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { setTimeout as delay } from "node:timers/promises";
import { NostrFetcher, eventKind } from "nostr-fetch";
import { NostrFetcher } from "nostr-fetch";
import "websocket-polyfill";

import { defaultRelays, nHoursAgo } from "./utils";
Expand All @@ -12,7 +12,7 @@ const main = async () => {
const eventsIter = fetcher.allEventsIterator(
defaultRelays,
{
kinds: [eventKind.text],
kinds: [1],
},
{
since: nHoursAgo(3),
Expand Down
4 changes: 2 additions & 2 deletions packages/examples/src/fetchAll.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { eventKind, NostrFetcher } from "nostr-fetch";
import { NostrFetcher } from "nostr-fetch";
import "websocket-polyfill";

import { defaultRelays, nHoursAgo } from "./utils";
Expand All @@ -10,7 +10,7 @@ const main = async () => {
const events = await fetcher.fetchAllEvents(
defaultRelays,
{
kinds: [eventKind.text],
kinds: [1],
},
{
since: nHoursAgo(1),
Expand Down
4 changes: 2 additions & 2 deletions packages/examples/src/fetchLast.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { eventKind, NostrFetcher } from "nostr-fetch";
import { NostrFetcher } from "nostr-fetch";
import "websocket-polyfill";

import { defaultRelays } from "./utils";
Expand All @@ -8,7 +8,7 @@ const main = async () => {

// fetch the last metadata event (kind 0) and contact list event (kind 3) published by the pubkey from the relays
const [lastMetadata, lastContacts] = await Promise.all(
[eventKind.metadata, eventKind.contacts].map((kind) =>
[0, 3].map((kind) =>
fetcher.fetchLastEvent(defaultRelays, {
kinds: [kind],
authors: ["d1d1747115d16751a97c239f46ec1703292c3b7e9988b9ebdd4ec4705b15ed44"],
Expand Down
6 changes: 3 additions & 3 deletions packages/examples/src/fetchLastPerAuthor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { eventKind, NostrFetcher } from "nostr-fetch";
import { NostrFetcher } from "nostr-fetch";
import "websocket-polyfill";

import { defaultRelays } from "./utils";
Expand All @@ -17,7 +17,7 @@ const main = async () => {

// get pubkeys of followees from the latest kind 3 event
const lastFollowEvent = await fetcher.fetchLastEvent(defaultRelays, {
kinds: [eventKind.contacts],
kinds: [3],
authors: [pubkey],
});
if (lastFollowEvent === undefined) {
Expand All @@ -32,7 +32,7 @@ const main = async () => {
const profilePerAuthor = fetcher.fetchLastEventPerAuthor(
{ authors: followees, relayUrls: defaultRelays },
{
kinds: [eventKind.metadata],
kinds: [0],
},
);

Expand Down
4 changes: 2 additions & 2 deletions packages/examples/src/fetchLatest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { eventKind, NostrFetcher } from "nostr-fetch";
import { NostrFetcher } from "nostr-fetch";
import "websocket-polyfill";

import { defaultRelays } from "./utils";
Expand All @@ -10,7 +10,7 @@ const main = async () => {
const latestPosts = await fetcher.fetchLatestEvents(
defaultRelays,
{
kinds: [eventKind.text],
kinds: [1],
},
100,
// { skipVerification: true }
Expand Down
4 changes: 2 additions & 2 deletions packages/examples/src/fetchLatestAsOf.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { eventKind, NostrFetcher } from "nostr-fetch";
import { NostrFetcher } from "nostr-fetch";
import "websocket-polyfill";

import { defaultRelays } from "./utils";
Expand All @@ -10,7 +10,7 @@ const main = async () => {
const latestPosts = await fetcher.fetchLatestEvents(
defaultRelays,
{
kinds: [eventKind.text],
kinds: [1],
},
100,
{ asOf: Math.floor(new Date("2023-08-31T12:00:00Z").getTime() / 1000) },
Expand Down
6 changes: 3 additions & 3 deletions packages/examples/src/fetchLatestPerAuthor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { eventKind, NostrFetcher } from "nostr-fetch";
import { NostrFetcher } from "nostr-fetch";
import "websocket-polyfill";

import { defaultRelays } from "./utils";
Expand All @@ -14,7 +14,7 @@ const main = async () => {

// get pubkeys of followees from the latest kind 3 event
const lastFollowEvent = await fetcher.fetchLastEvent(defaultRelays, {
kinds: [eventKind.contacts],
kinds: [3],
authors: [pubkey],
});
if (lastFollowEvent === undefined) {
Expand All @@ -28,7 +28,7 @@ const main = async () => {
// get latest 10 posts for each followee
const latestPostsPerFollowee = fetcher.fetchLatestEventsPerAuthor(
{ authors: followees, relayUrls: defaultRelays },
{ kinds: [eventKind.text] },
{ kinds: [1] },
10,
);

Expand Down
4 changes: 2 additions & 2 deletions packages/examples/src/interop/ndk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import NDK from "@nostr-dev-kit/ndk";
import { ndkAdapter } from "@nostr-fetch/adapter-ndk";
import { NostrFetcher, eventKind, normalizeRelayUrlSet } from "nostr-fetch";
import { NostrFetcher, normalizeRelayUrlSet } from "nostr-fetch";
import { defaultRelays, nHoursAgo } from "../utils";

import "websocket-polyfill";
Expand All @@ -21,7 +21,7 @@ const main = async () => {
const eventsIter = fetcher.allEventsIterator(
defaultRelays,
{
kinds: [eventKind.text],
kinds: [1],
},
{
since: nHoursAgo(1),
Expand Down
4 changes: 2 additions & 2 deletions packages/examples/src/interop/relayPoolTs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { relayPoolAdapter } from "@nostr-fetch/adapter-nostr-relaypool";
import { NostrFetcher, eventKind } from "nostr-fetch";
import { NostrFetcher } from "nostr-fetch";
import { RelayPool } from "nostr-relaypool";

import { defaultRelays, nHoursAgo } from "../utils";
Expand All @@ -13,7 +13,7 @@ const main = async () => {
const eventsIter = fetcher.allEventsIterator(
defaultRelays,
{
kinds: [eventKind.text],
kinds: [1],
},
{
since: nHoursAgo(1),
Expand Down
4 changes: 2 additions & 2 deletions packages/examples/src/interop/rxNostr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { rxNostrAdapter } from "@nostr-fetch/adapter-rx-nostr";
import { NostrFetcher, eventKind } from "nostr-fetch";
import { NostrFetcher } from "nostr-fetch";
import { createRxNostr } from "rx-nostr";
import "websocket-polyfill";

Expand All @@ -14,7 +14,7 @@ const main = async () => {
const eventsIter = fetcher.allEventsIterator(
defaultRelays,
{
kinds: [eventKind.text],
kinds: [1],
},
{
since: nHoursAgo(1),
Expand Down
4 changes: 2 additions & 2 deletions packages/examples/src/interop/simplePool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { simplePoolAdapter } from "@nostr-fetch/adapter-nostr-tools";
import { eventKind, NostrFetcher } from "nostr-fetch";
import { NostrFetcher } from "nostr-fetch";
import { SimplePool } from "nostr-tools";
import "websocket-polyfill";

Expand All @@ -14,7 +14,7 @@ const main = async () => {
const eventsIter = fetcher.allEventsIterator(
defaultRelays,
{
kinds: [eventKind.text],
kinds: [1],
},
{
since: nHoursAgo(1),
Expand Down
4 changes: 2 additions & 2 deletions packages/examples/src/interop/simplePoolV2.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { simplePoolAdapter } from "@nostr-fetch/adapter-nostr-tools-v2";
import { eventKind, NostrFetcher } from "nostr-fetch";
import { NostrFetcher } from "nostr-fetch";
import { SimplePool, useWebSocketImplementation } from "nostr-tools-v2";
import ws from "ws";

Expand All @@ -15,7 +15,7 @@ const main = async () => {
const eventsIter = fetcher.allEventsIterator(
defaultRelays,
{
kinds: [eventKind.text],
kinds: [1],
},
{
since: nHoursAgo(1),
Expand Down
8 changes: 4 additions & 4 deletions packages/examples/src/outboxModel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { setTimeout } from "node:timers/promises";
import { type NostrEvent, NostrFetcher, eventKind } from "nostr-fetch";
import { type NostrEvent, NostrFetcher } from "nostr-fetch";
import "websocket-polyfill";

import { defaultRelays, getWriteRelaysFromEvent } from "./utils";
Expand All @@ -15,7 +15,7 @@ const fetcher = NostrFetcher.init({});
// fetch pubkeys of followees from the latest kind 3 event
const fetchFollowees = async (pubkey: string): Promise<string[]> => {
const ev = await fetcher.fetchLastEvent(defaultRelays, {
kinds: [eventKind.contacts],
kinds: [3],
authors: [pubkey],
});
if (ev === undefined) {
Expand All @@ -29,7 +29,7 @@ const fetchWriteRelaysPerAuthors = async (authors: string[]): Promise<Map<string
const iter = fetcher.fetchLastEventPerAuthor(
{ authors, relayUrls: defaultRelays },
{
kinds: [eventKind.contacts, eventKind.relayList],
kinds: [3, 10002],
},
);
const res = new Map<string, string[]>();
Expand All @@ -56,7 +56,7 @@ const main = async () => {
const lastPostsPerFollowee = fetcher.fetchLastEventPerAuthor(
writeRelaysPerFollowees,
{
kinds: [eventKind.text],
kinds: [1],
},
{ statsListener: (stats) => console.error(stats) },
);
Expand Down
4 changes: 2 additions & 2 deletions packages/examples/src/search.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NostrFetcher, eventKind } from "nostr-fetch";
import { NostrFetcher } from "nostr-fetch";
import "websocket-polyfill";

import { nHoursAgo } from "./utils";
Expand All @@ -18,7 +18,7 @@ const main = async () => {
const eventsIter = fetcher.allEventsIterator(
searchRelays,
{
kinds: [eventKind.text],
kinds: [1],
search: searchQuery,
},
{
Expand Down
4 changes: 2 additions & 2 deletions packages/examples/src/seenOn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { eventKind, NostrFetcher } from "nostr-fetch";
import { NostrFetcher } from "nostr-fetch";
import "websocket-polyfill";

import { defaultRelays } from "./utils";
Expand All @@ -10,7 +10,7 @@ const main = async () => {
const latestPosts = await fetcher.fetchLatestEvents(
defaultRelays,
{
kinds: [eventKind.text],
kinds: [1],
},
100,
{ withSeenOn: false },
Expand Down
Loading