-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(lib): merge agents.ts and profiles.ts into streams.ts
- Loading branch information
Showing
6 changed files
with
23 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
// Echo bot | ||
import { Relay } from "../../../client.ts"; | ||
import { DefaultAgent } from "../../../lib/agents.ts"; | ||
import { Transformer } from "../../../lib/streams.ts"; | ||
import { EventPublisher } from "../../../lib/events.ts"; | ||
import { TextNoteComposer } from "../../../lib/notes.ts"; | ||
import { env } from "../../../lib/env.ts"; | ||
|
||
const relay = new Relay("wss://nostr-dev.wellorder.net"); | ||
|
||
relay.subscribe({ kinds: [1], "#p": [env.PUBLIC_KEY] }) | ||
.pipeThrough(new DefaultAgent((ev) => ({ content: ev.content }))) | ||
.pipeThrough(new TextNoteComposer()) | ||
.pipeThrough(new Transformer((ev) => ({ kind: 1, content: ev.content }))) | ||
.pipeTo(new EventPublisher(relay, env.PRIVATE_KEY)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ export { mergeReadableStreams as merge } from "https://deno.land/[email protected]/str | |
/** | ||
* TransformStream which filters out duplicate values from a stream. | ||
*/ | ||
export class Distinctor<R extends unknown, T extends unknown> | ||
export class Distinctor<R = unknown, T = unknown> | ||
extends TransformStream<R, R> { | ||
#seen: Set<T>; | ||
|
||
|
@@ -21,3 +21,17 @@ export class Distinctor<R extends unknown, T extends unknown> | |
this.#seen = new Set<T>(); | ||
} | ||
} | ||
|
||
export class Transformer<R = unknown, W = unknown> | ||
extends TransformStream<R, W> { | ||
constructor(fn: (chunk: R) => W) { | ||
super({ | ||
transform(event, controller) { | ||
const result = fn(event); | ||
if (result) { | ||
controller.enqueue(result); | ||
} | ||
}, | ||
}); | ||
} | ||
} |