Skip to content

Commit

Permalink
Remove queryClient from UseReqOpts
Browse files Browse the repository at this point in the history
  • Loading branch information
akiomik committed Jun 13, 2023
1 parent 957b181 commit 98177ac
Show file tree
Hide file tree
Showing 18 changed files with 29 additions and 47 deletions.
3 changes: 1 addition & 2 deletions src/lib/components/Article.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
import type { QueryKey } from '@tanstack/svelte-query';
import { useQueryClient } from '@tanstack/svelte-query';
import type { Nostr } from 'rx-nostr';
import type { ReqStatus, RxReqBase } from '$lib/stores/index.js';
Expand All @@ -17,7 +16,7 @@
export let req: RxReqBase | undefined = undefined;
// TODO: Check if $app.rxNostr is defined
$: result = useArticle($app.rxNostr, useQueryClient(), queryKey, pubkey, identifier, req);
$: result = useArticle($app.rxNostr, queryKey, pubkey, identifier, req);
$: data = result.data;
$: status = result.status;
$: error = result.error;
Expand Down
3 changes: 1 addition & 2 deletions src/lib/components/Contacts.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
import type { QueryKey } from '@tanstack/svelte-query';
import { useQueryClient } from '@tanstack/svelte-query';
import type { Nostr } from 'rx-nostr';
import type { ReqStatus, RxReqBase } from '$lib/stores/index.js';
Expand All @@ -16,7 +15,7 @@
export let req: RxReqBase | undefined = undefined;
// TODO: Check if $app.rxNostr is defined
$: result = useContacts($app.rxNostr, useQueryClient(), queryKey, pubkey, req);
$: result = useContacts($app.rxNostr, queryKey, pubkey, req);
$: data = result.data;
$: status = result.status;
$: error = result.error;
Expand Down
3 changes: 1 addition & 2 deletions src/lib/components/Metadata.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
import type { QueryKey } from '@tanstack/svelte-query';
import { useQueryClient } from '@tanstack/svelte-query';
import type { Nostr } from 'rx-nostr';
import type { ReqStatus, RxReqBase } from '$lib/stores/index.js';
Expand All @@ -16,7 +15,7 @@
export let req: RxReqBase | undefined = undefined;
// TODO: Check if $app.rxNostr is defined
$: result = useMetadata($app.rxNostr, useQueryClient(), queryKey, pubkey, req);
$: result = useMetadata($app.rxNostr, queryKey, pubkey, req);
$: data = result.data;
$: status = result.status;
$: error = result.error;
Expand Down
3 changes: 1 addition & 2 deletions src/lib/components/Text.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
import type { QueryKey } from '@tanstack/svelte-query';
import { useQueryClient } from '@tanstack/svelte-query';
import type { Nostr } from 'rx-nostr';
import type { ReqStatus, RxReqBase } from '$lib/stores/index.js';
Expand All @@ -16,7 +15,7 @@
export let req: RxReqBase | undefined = undefined;
// TODO: Check if $app.rxNostr is defined
$: result = useText($app.rxNostr, useQueryClient(), queryKey, id, req);
$: result = useText($app.rxNostr, queryKey, id, req);
$: data = result.data;
$: status = result.status;
$: error = result.error;
Expand Down
3 changes: 1 addition & 2 deletions src/lib/components/UniqueEventList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
import type { QueryKey } from '@tanstack/svelte-query';
import { useQueryClient } from '@tanstack/svelte-query';
import type { Nostr } from 'rx-nostr';
import type { ReqStatus, RxReqBase } from '$lib/stores/index.js';
Expand All @@ -16,7 +15,7 @@
export let req: RxReqBase | undefined = undefined;
// TODO: Check if $app.rxNostr is defined
$: result = useUniqueEventList($app.rxNostr, useQueryClient(), queryKey, filters, req);
$: result = useUniqueEventList($app.rxNostr, queryKey, filters, req);
$: data = result.data;
$: status = result.status;
$: error = result.error;
Expand Down
3 changes: 1 addition & 2 deletions src/lib/components/UserReactionList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
import type { QueryKey } from '@tanstack/svelte-query';
import { useQueryClient } from '@tanstack/svelte-query';
import type { Nostr } from 'rx-nostr';
import type { ReqStatus, RxReqBase } from '$lib/stores/index.js';
Expand All @@ -17,7 +16,7 @@
export let limit = 100;
// TODO: Check if $app.rxNostr is defined
$: result = useUserReactionList($app.rxNostr, useQueryClient(), queryKey, pubkey, limit, req);
$: result = useUserReactionList($app.rxNostr, queryKey, pubkey, limit, req);
$: data = result.data;
$: status = result.status;
$: error = result.error;
Expand Down
3 changes: 1 addition & 2 deletions src/lib/stores/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @copyright 2023 Akiomi Kamakura
*/

import type { QueryClient, QueryKey } from '@tanstack/svelte-query';
import type { QueryKey } from '@tanstack/svelte-query';
import type { EventPacket, Nostr, Relay, RxNostr, RxReq, RxReqController } from 'rx-nostr';
import type { OperatorFunction } from 'rxjs';
import type { Readable } from 'svelte/store';
Expand All @@ -25,7 +25,6 @@ export interface UseConnectionsOpts {

export interface UseReqOpts<A> {
rxNostr: RxNostr;
queryClient: QueryClient;
queryKey: QueryKey;
filters: Nostr.Filter[];
operator: OperatorFunction<EventPacket, A>;
Expand Down
5 changes: 2 additions & 3 deletions src/lib/stores/useArticle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @copyright 2023 Akiomi Kamakura
*/

import type { QueryClient, QueryKey } from '@tanstack/svelte-query';
import type { QueryKey } from '@tanstack/svelte-query';
import type { EventPacket, RxNostr } from 'rx-nostr';
import { latest, Nostr, verify } from 'rx-nostr';
import { pipe } from 'rxjs';
Expand All @@ -14,7 +14,6 @@ import { useReq } from './useReq.js';

export function useArticle(
rxNostr: RxNostr,
queryClient: QueryClient,
queryKey: QueryKey,
pubkey: string,
identifier: string,
Expand All @@ -24,5 +23,5 @@ export function useArticle(
{ kinds: [Nostr.Kind.Article], authors: [pubkey], '#d': [identifier], limit: 1 }
];
const operator = pipe(filterNaddr(Nostr.Kind.Article, pubkey, identifier), verify(), latest());
return useReq({ rxNostr, queryClient, queryKey, filters, operator, req });
return useReq({ rxNostr, queryKey, filters, operator, req });
}
5 changes: 2 additions & 3 deletions src/lib/stores/useArticleList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @copyright 2023 Akiomi Kamakura
*/

import type { QueryClient, QueryKey } from '@tanstack/svelte-query';
import type { QueryKey } from '@tanstack/svelte-query';
import type { EventPacket, RxNostr } from 'rx-nostr';
import { filterKind, Nostr, verify } from 'rx-nostr';
import { pipe } from 'rxjs';
Expand All @@ -14,7 +14,6 @@ import { useReq } from './useReq.js';

export function useUserArticleList(
rxNostr: RxNostr,
queryClient: QueryClient,
queryKey: QueryKey,
pubkey: string,
limit: number,
Expand All @@ -28,5 +27,5 @@ export function useUserArticleList(
latestEachNaddr(),
scanArray()
);
return useReq({ rxNostr, queryClient, queryKey, filters, operator, req, initData: [] });
return useReq({ rxNostr, queryKey, filters, operator, req, initData: [] });
}
5 changes: 2 additions & 3 deletions src/lib/stores/useContacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @copyright 2023 Akiomi Kamakura
*/

import type { QueryClient, QueryKey } from '@tanstack/svelte-query';
import type { QueryKey } from '@tanstack/svelte-query';
import type { EventPacket, RxNostr } from 'rx-nostr';
import { filterKind, latest, Nostr, verify } from 'rx-nostr';
import { pipe } from 'rxjs';
Expand All @@ -14,13 +14,12 @@ import { useReq } from './useReq.js';

export function useContacts(
rxNostr: RxNostr,
queryClient: QueryClient,
queryKey: QueryKey,
pubkey: string,
req?: RxReqBase | undefined
): ReqResult<EventPacket> {
// TODO: Add npub support
const filters = [{ kinds: [Nostr.Kind.Contacts], authors: [pubkey], limit: 1 }];
const operator = pipe(filterKind(Nostr.Kind.Contacts), filterPubkey(pubkey), verify(), latest());
return useReq({ rxNostr, queryClient, queryKey, filters, operator, req });
return useReq({ rxNostr, queryKey, filters, operator, req });
}
5 changes: 2 additions & 3 deletions src/lib/stores/useLatestEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @copyright 2023 Akiomi Kamakura
*/

import type { QueryClient, QueryKey } from '@tanstack/svelte-query';
import type { QueryKey } from '@tanstack/svelte-query';
import type { EventPacket, RxNostr } from 'rx-nostr';
import { latest, Nostr, verify } from 'rx-nostr';
import { pipe } from 'rxjs';
Expand All @@ -13,11 +13,10 @@ import { useReq } from './useReq.js';

export function useLatestEvent(
rxNostr: RxNostr,
queryClient: QueryClient,
queryKey: QueryKey,
filters: Nostr.Filter[],
req?: RxReqBase | undefined
): ReqResult<EventPacket> {
const operator = pipe(verify(), latest());
return useReq({ rxNostr, queryClient, queryKey, filters, operator, req });
return useReq({ rxNostr, queryKey, filters, operator, req });
}
5 changes: 2 additions & 3 deletions src/lib/stores/useMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @copyright 2023 Akiomi Kamakura
*/

import type { QueryClient, QueryKey } from '@tanstack/svelte-query';
import type { QueryKey } from '@tanstack/svelte-query';
import type { EventPacket, RxNostr } from 'rx-nostr';
import { filterKind, latest, Nostr, verify } from 'rx-nostr';
import { pipe } from 'rxjs';
Expand All @@ -14,13 +14,12 @@ import { useReq } from './useReq.js';

export function useMetadata(
rxNostr: RxNostr,
queryClient: QueryClient,
queryKey: QueryKey,
pubkey: string,
req?: RxReqBase | undefined
): ReqResult<EventPacket> {
// TODO: Add npub support
const filters = [{ kinds: [Nostr.Kind.Metadata], authors: [pubkey], limit: 1 }];
const operator = pipe(filterKind(Nostr.Kind.Metadata), filterPubkey(pubkey), verify(), latest());
return useReq({ rxNostr, queryClient, queryKey, filters, operator, req });
return useReq({ rxNostr, queryKey, filters, operator, req });
}
5 changes: 2 additions & 3 deletions src/lib/stores/useMetadataList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @copyright 2023 Akiomi Kamakura
*/

import type { QueryClient, QueryKey } from '@tanstack/svelte-query';
import type { QueryKey } from '@tanstack/svelte-query';
import type { EventPacket, RxNostr } from 'rx-nostr';
import { Nostr, verify } from 'rx-nostr';
import { pipe } from 'rxjs';
Expand All @@ -14,13 +14,12 @@ import { useReq } from './useReq.js';

export function useMetadataList(
rxNostr: RxNostr,
queryClient: QueryClient,
queryKey: QueryKey,
pubkeys: string[],
req?: RxReqBase | undefined
): ReqResult<EventPacket[]> {
// TODO: Add npub support
const filters = [{ kinds: [Nostr.Kind.Metadata], authors: pubkeys, limit: pubkeys.length }];
const operator = pipe(filterMetadataList(pubkeys), verify(), latestEachPubkey(), scanArray());
return useReq({ rxNostr, queryClient, queryKey, filters, operator, req, initData: [] });
return useReq({ rxNostr, queryKey, filters, operator, req, initData: [] });
}
5 changes: 2 additions & 3 deletions src/lib/stores/useText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @copyright 2023 Akiomi Kamakura
*/

import type { QueryClient, QueryKey } from '@tanstack/svelte-query';
import type { QueryKey } from '@tanstack/svelte-query';
import type { EventPacket, RxNostr } from 'rx-nostr';
import { filterKind, Nostr, uniq, verify } from 'rx-nostr';
import { pipe } from 'rxjs';
Expand All @@ -14,13 +14,12 @@ import { useReq } from './useReq.js';

export function useText(
rxNostr: RxNostr,
queryClient: QueryClient,
queryKey: QueryKey,
id: string,
req?: RxReqBase | undefined
): ReqResult<EventPacket> {
// TODO: Add note1 support
const filters = [{ kinds: [Nostr.Kind.Text], ids: [id], limit: 1 }];
const operator = pipe(filterKind(Nostr.Kind.Text), filterId(id), uniq(), verify());
return useReq({ rxNostr, queryClient, queryKey, filters, operator, req });
return useReq({ rxNostr, queryKey, filters, operator, req });
}
5 changes: 2 additions & 3 deletions src/lib/stores/useTextList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @copyright 2023 Akiomi Kamakura
*/

import type { QueryClient, QueryKey } from '@tanstack/svelte-query';
import type { QueryKey } from '@tanstack/svelte-query';
import type { EventPacket, RxNostr } from 'rx-nostr';
import { Nostr, uniq, verify } from 'rx-nostr';
import { pipe } from 'rxjs';
Expand All @@ -14,13 +14,12 @@ import { useReq } from './useReq.js';

export function useTextList(
rxNostr: RxNostr,
queryClient: QueryClient,
queryKey: QueryKey,
ids: string[],
req?: RxReqBase | undefined
): ReqResult<EventPacket[]> {
// TODO: Add note1 support
const filters = [{ kinds: [Nostr.Kind.Text], ids }];
const operator = pipe(filterTextList(ids), uniq(), verify(), scanArray());
return useReq({ rxNostr, queryClient, queryKey, filters, operator, req, initData: [] });
return useReq({ rxNostr, queryKey, filters, operator, req, initData: [] });
}
5 changes: 2 additions & 3 deletions src/lib/stores/useUniqueEventList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @copyright 2023 Akiomi Kamakura
*/

import type { QueryClient, QueryKey } from '@tanstack/svelte-query';
import type { QueryKey } from '@tanstack/svelte-query';
import type { EventPacket, RxNostr } from 'rx-nostr';
import { Nostr, uniq, verify } from 'rx-nostr';
import { pipe } from 'rxjs';
Expand All @@ -14,11 +14,10 @@ import { useReq } from './useReq.js';

export function useUniqueEventList(
rxNostr: RxNostr,
queryClient: QueryClient,
queryKey: QueryKey,
filters: Nostr.Filter[],
req?: RxReqBase | undefined
): ReqResult<EventPacket[]> {
const operator = pipe(uniq(), verify(), scanArray());
return useReq({ rxNostr, queryClient, queryKey, filters, operator, req });
return useReq({ rxNostr, queryKey, filters, operator, req });
}
5 changes: 2 additions & 3 deletions src/lib/stores/useUserReactionList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @copyright 2023 Akiomi Kamakura
*/

import type { QueryClient, QueryKey } from '@tanstack/svelte-query';
import type { QueryKey } from '@tanstack/svelte-query';
import type { EventPacket, RxNostr } from 'rx-nostr';
import { filterKind, Nostr, verify } from 'rx-nostr';
import { pipe } from 'rxjs';
Expand All @@ -14,7 +14,6 @@ import { useReq } from './useReq.js';

export function useUserReactionList(
rxNostr: RxNostr,
queryClient: QueryClient,
queryKey: QueryKey,
pubkey: string,
limit: number,
Expand All @@ -28,5 +27,5 @@ export function useUserReactionList(
latestEachNaddr(),
scanArray()
);
return useReq({ rxNostr, queryClient, queryKey, filters, operator, req, initData: [] });
return useReq({ rxNostr, queryKey, filters, operator, req, initData: [] });
}
5 changes: 2 additions & 3 deletions src/lib/stores/useUserTextList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @copyright 2023 Akiomi Kamakura
*/

import type { QueryClient, QueryKey } from '@tanstack/svelte-query';
import type { QueryKey } from '@tanstack/svelte-query';
import type { EventPacket, RxNostr } from 'rx-nostr';
import { filterKind, Nostr, uniq, verify } from 'rx-nostr';
import { pipe } from 'rxjs';
Expand All @@ -14,7 +14,6 @@ import { useReq } from './useReq.js';

export function useUserTextList(
rxNostr: RxNostr,
queryClient: QueryClient,
queryKey: QueryKey,
pubkey: string,
limit: number,
Expand All @@ -29,5 +28,5 @@ export function useUserTextList(
verify(),
scanArray()
);
return useReq({ rxNostr, queryClient, queryKey, filters, operator, req, initData: [] });
return useReq({ rxNostr, queryKey, filters, operator, req, initData: [] });
}

0 comments on commit 98177ac

Please sign in to comment.