From c909758502bc363a17065358105363ef5c1589b6 Mon Sep 17 00:00:00 2001 From: penpenpng Date: Wed, 15 Jan 2025 00:39:32 +0900 Subject: [PATCH] Revert "feat: replay option for RxReq" This reverts commit 74679edf044bc03099838125fa53497c90fa2b38. --- .../core/src/__test__/rx-req-replay.test.ts | 73 ------------------- packages/core/src/rx-nostr/rx-req.ts | 62 +++------------- 2 files changed, 11 insertions(+), 124 deletions(-) delete mode 100644 packages/core/src/__test__/rx-req-replay.test.ts diff --git a/packages/core/src/__test__/rx-req-replay.test.ts b/packages/core/src/__test__/rx-req-replay.test.ts deleted file mode 100644 index 8d5767e..0000000 --- a/packages/core/src/__test__/rx-req-replay.test.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { afterEach, beforeEach, expect, test } from "vitest"; -import { createMockRelay, type MockRelay } from "vitest-nostr"; - -import { - createRxBackwardReq, - createRxNostr, - noopVerifier, - RxNostr, -} from "../index.js"; -import { disposeMockRelay, stateWillBe } from "./helper.js"; - -const DEFAULT_RELAY = "ws://localhost:1234"; -let rxNostr: RxNostr; -let defaultRelay: MockRelay; - -beforeEach(async () => { - defaultRelay = createMockRelay(DEFAULT_RELAY); - - rxNostr = createRxNostr({ - verifier: noopVerifier, - skipFetchNip11: true, - skipVerify: true, - }); - await rxNostr.setDefaultRelays([DEFAULT_RELAY]); -}); - -afterEach(() => { - rxNostr.dispose(); - disposeMockRelay(defaultRelay); -}); - -test("`replay` option works well.", async () => { - const rxReq = createRxBackwardReq({ rxReqId: "sub", replay: true }); - - rxReq.emit({ limit: 1 }); - rxReq.emit({ limit: 2 }); - rxReq.emit({ limit: 3 }); - - rxNostr.use(rxReq).subscribe(); - - await defaultRelay.connected; - await expect(defaultRelay).toReceiveREQ(["sub:0", { limit: 1 }]); - await expect(defaultRelay).toReceiveREQ(["sub:1", { limit: 2 }]); - await expect(defaultRelay).toReceiveREQ(["sub:2", { limit: 3 }]); -}); - -test("`replay` option works well even if over() is called.", async () => { - const rxReq = createRxBackwardReq({ rxReqId: "sub", replay: true }); - - rxReq.emit({ limit: 1 }); - rxReq.emit({ limit: 2 }); - rxReq.emit({ limit: 3 }); - rxReq.over(); - - rxNostr.use(rxReq).subscribe(); - - await defaultRelay.connected; - await expect(defaultRelay).toReceiveREQ(["sub:0", { limit: 1 }]); - await expect(defaultRelay).toReceiveREQ(["sub:1", { limit: 2 }]); - await expect(defaultRelay).toReceiveREQ(["sub:2", { limit: 3 }]); - - await expect(stateWillBe(rxNostr, DEFAULT_RELAY, "connected")).resolves.toBe( - true, - ); - - defaultRelay.emitEOSE("sub:0"); - defaultRelay.emitEOSE("sub:1"); - defaultRelay.emitEOSE("sub:2"); - - await expect(stateWillBe(rxNostr, DEFAULT_RELAY, "dormant")).resolves.toBe( - true, - ); -}); diff --git a/packages/core/src/rx-nostr/rx-req.ts b/packages/core/src/rx-nostr/rx-req.ts index bd84593..addd13b 100644 --- a/packages/core/src/rx-nostr/rx-req.ts +++ b/packages/core/src/rx-nostr/rx-req.ts @@ -1,11 +1,5 @@ import * as Nostr from "nostr-typedef"; -import { - Observable, - of, - type OperatorFunction, - ReplaySubject, - Subject, -} from "rxjs"; +import { Observable, of, type OperatorFunction, Subject } from "rxjs"; import { LazyFilter, ReqPacket } from "../packet.js"; @@ -156,12 +150,6 @@ const createRxReq = (params: { }; }; -export interface RxBackwardReqOptions { - /** @deprecated */ - rxReqId?: string; - replay?: boolean; -} - /** * Create a RxReq instance based on the backward strategy. * It is useful if you want to retrieve past events that have already been published. @@ -174,32 +162,15 @@ export interface RxBackwardReqOptions { * For more information, see [document](https://penpenpng.github.io/rx-nostr/v1/req-strategy.html#backward-strategy). */ export function createRxBackwardReq( - // TODO (v4): remove string format options - options?: string /* for backward compatibility. */ | RxBackwardReqOptions, + rxReqId?: string, ): RxReq<"backward"> & RxReqEmittable<{ relays: string[] }> & RxReqOverable & RxReqPipeable { - if (typeof options === "string") { - const rxReqId = options; - return createRxReq({ - strategy: "backward", - rxReqId, - }); - } else { - const { rxReqId, replay } = options ?? {}; - return createRxReq({ - strategy: "backward", - rxReqId, - subject: replay ? new ReplaySubject() : undefined, - }); - } -} - -export interface RxForwardReqOptions { - /** @deprecated */ - rxReqId?: string; - replay?: boolean; + return createRxReq({ + strategy: "backward", + rxReqId, + }); } /** @@ -215,23 +186,12 @@ export interface RxForwardReqOptions { * For more information, see [document](https://penpenpng.github.io/rx-nostr/v1/req-strategy.html#forward-strategy). */ export function createRxForwardReq( - // TODO (v4): remove string format options - options?: string /* for backward compatibility. */ | RxForwardReqOptions, + rxReqId?: string, ): RxReq<"forward"> & RxReqEmittable & RxReqPipeable { - if (typeof options === "string") { - const rxReqId = options; - return createRxReq({ - strategy: "forward", - rxReqId, - }); - } else { - const { rxReqId, replay } = options ?? {}; - return createRxReq({ - strategy: "forward", - rxReqId, - subject: replay ? new ReplaySubject() : undefined, - }); - } + return createRxReq({ + strategy: "forward", + rxReqId, + }); } /**