Skip to content

Commit

Permalink
Merge branch 'next' into T-23291/js-action-implement-group-queries
Browse files Browse the repository at this point in the history
  • Loading branch information
juangm authored Dec 16, 2024
2 parents 88259cc + c650381 commit fe78e5b
Show file tree
Hide file tree
Showing 19 changed files with 628 additions and 54 deletions.
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
}
},
"devDependencies": {
"@lens-network/sdk": "0.0.0-canary-20241203140504",
"@lens-network/sdk": "canary",
"tsup": "^8.3.5",
"typescript": "^5.6.3",
"viem": "^2.21.53"
Expand Down
27 changes: 25 additions & 2 deletions packages/client/src/actions/admins.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import type {
AddAdminsRequest,
AddAdminsResult,
Admin,
AdminsForRequest,
RemoveAdminsRequest,
RemoveAdminsResult,
} from '@lens-protocol/graphql';
import { AddAdminsMutation, RemoveAdminsMutation } from '@lens-protocol/graphql';
import { AddAdminsMutation, AdminsForQuery, RemoveAdminsMutation } from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

import type { SessionClient } from '../clients';
import type { Paginated } from '@lens-protocol/graphql';
import type { AnyClient, SessionClient } from '../clients';
import type { UnauthenticatedError, UnexpectedError } from '../errors';

/**
Expand Down Expand Up @@ -51,3 +54,23 @@ export function removeAdmins(
): ResultAsync<RemoveAdminsResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(RemoveAdminsMutation, { request });
}

/**
* Fetch admins for.
*
* ```ts
* const result = await fetchAdminsFor(anyClient, {
* address: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'),
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of admins or empty if it does not exist.
*/
export function fetchAdminsFor(
client: AnyClient,
request: AdminsForRequest,
): ResultAsync<Paginated<Admin> | null, UnexpectedError> {
return client.query(AdminsForQuery, { request });
}
57 changes: 54 additions & 3 deletions packages/client/src/actions/feed.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import type { CreateFeedRequest, CreateFeedResult } from '@lens-protocol/graphql';
import { CreateFeedMutation } from '@lens-protocol/graphql';
import type {
CreateFeedRequest,
CreateFeedResult,
Feed,
FeedRequest,
FeedsRequest,
Paginated,
} from '@lens-protocol/graphql';
import { CreateFeedMutation, FeedQuery, FeedsQuery } from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

import type { SessionClient } from '../clients';
import type { AnyClient, SessionClient } from '../clients';
import type { UnauthenticatedError, UnexpectedError } from '../errors';

/**
Expand All @@ -22,3 +29,47 @@ export function createFeed(
): ResultAsync<CreateFeedResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(CreateFeedMutation, { request });
}

/**
* Fetch a Feed.
*
* ```ts
* const result = await fetchFeed(anyClient, {
* feed: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'),
* });
* ```
*
* @param client - Any Lens client.
* @param request - The Feed query request.
* @returns The Feed or `null` if it does not exist.
*/
export function fetchFeed(
client: AnyClient,
request: FeedRequest,
): ResultAsync<Feed | null, UnexpectedError> {
return client.query(FeedQuery, { request });
}

/**
* Fetch Feeds.
*
* ```ts
* const result = await fetchFeeds(anyClient, {
* filter: {
* managedBy: {
* address: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')
* }
* },
* });
* ```
*
* @param client - Any Lens client.
* @param request - The Feeds query request.
* @returns The list of Feeds or empty list if none exist.
*/
export function fetchFeeds(
client: AnyClient,
request: FeedsRequest,
): ResultAsync<Paginated<Feed> | null, UnexpectedError> {
return client.query(FeedsQuery, { request });
}
57 changes: 54 additions & 3 deletions packages/client/src/actions/graph.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import type { CreateGraphRequest, CreateGraphResult } from '@lens-protocol/graphql';
import { CreateGraphMutation } from '@lens-protocol/graphql';
import type {
CreateGraphRequest,
CreateGraphResult,
Graph,
GraphRequest,
GraphsRequest,
Paginated,
} from '@lens-protocol/graphql';
import { CreateGraphMutation, GraphQuery, GraphsQuery } from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

import type { SessionClient } from '../clients';
import type { AnyClient, SessionClient } from '../clients';
import type { UnauthenticatedError, UnexpectedError } from '../errors';

/**
Expand All @@ -22,3 +29,47 @@ export function createGraph(
): ResultAsync<CreateGraphResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(CreateGraphMutation, { request });
}

/**
* Fetch a Graph.
*
* ```ts
* const result = await fetchGraph(anyClient, {
* graph: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'),
* });
* ```
*
* @param client - Any Lens client.
* @param request - The Graph query request.
* @returns The Graph or `null` if it does not exist.
*/
export function fetchGraph(
client: AnyClient,
request: GraphRequest,
): ResultAsync<Graph | null, UnexpectedError> {
return client.query(GraphQuery, { request });
}

/**
* Fetch Graphs.
*
* ```ts
* const result = await fetchGraphs(anyClient, {
* filter: {
* managedBy: {
* address: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')
* }
* },
* });
* ```
*
* @param client - Any Lens client.
* @param request - The Graphs query request.
* @returns The list of Graphs or empty list if none exist.
*/
export function fetchGraphs(
client: AnyClient,
request: GraphsRequest,
): ResultAsync<Paginated<Graph> | null, UnexpectedError> {
return client.query(GraphsQuery, { request });
}
56 changes: 54 additions & 2 deletions packages/client/src/actions/namespace.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import type {
CreateUsernameNamespaceRequest,
CreateUsernameNamespaceResult,
NamespacesRequest,
Paginated,
UsernameNamespace,
UsernameNamespaceRequest,
} from '@lens-protocol/graphql';
import {
CreateUsernameNamespaceMutation,
NamespacesQuery,
UsernameNamespaceQuery,
} from '@lens-protocol/graphql';
import { CreateUsernameNamespaceMutation } from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

import type { SessionClient } from '../clients';
import type { AnyClient, SessionClient } from '../clients';
import type { UnauthenticatedError, UnexpectedError } from '../errors';

/**
Expand All @@ -28,3 +36,47 @@ export function createUsernameNamespace(
): ResultAsync<CreateUsernameNamespaceResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(CreateUsernameNamespaceMutation, { request });
}

/**
* Fetch a UsernameNamespace.
*
* ```ts
* const result = await fetchUsernameNamespace(anyClient, {
* namespace: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'),
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The UsernameNamespace or `null` if it does not exist.
*/
export function fetchUsernameNamespace(
client: AnyClient,
request: UsernameNamespaceRequest,
): ResultAsync<UsernameNamespace | null, UnexpectedError> {
return client.query(UsernameNamespaceQuery, { request });
}

/**
* Fetch Namespaces.
*
* ```ts
* const result = await fetchNamespaces(anyClient, {
* filter: {
* managedBy: {
* address: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')
* }
* },
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of Namespaces or empty list if none exist.
*/
export function fetchNamespaces(
client: AnyClient,
request: NamespacesRequest,
): ResultAsync<Paginated<UsernameNamespace> | null, UnexpectedError> {
return client.query(NamespacesQuery, { request });
}
117 changes: 117 additions & 0 deletions packages/client/src/actions/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,25 @@ import type {
import {
PostActionsQuery,
PostBookmarksQuery,
PostEditsQuery,
PostQuery,
PostReactionStatusQuery,
PostReactionsQuery,
PostReferencesQuery,
PostTagsQuery,
WhoActedOnPostQuery,
WhoReferencedPostQuery,
} from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

import type { PostTagsRequest } from '@lens-protocol/graphql';
import type { PostReactionStatusRequest } from '@lens-protocol/graphql';
import type { PostReactionStatus } from '@lens-protocol/graphql';
import type { WhoReferencedPostRequest } from '@lens-protocol/graphql';
import type { Account } from '@lens-protocol/graphql';
import type { WhoActedOnPostQueryRequest } from '@lens-protocol/graphql';
import type { PostEditsRequest } from '@lens-protocol/graphql';
import type { PostEdit } from '@lens-protocol/graphql';
import type { AnyClient, SessionClient } from '../clients';
import type { UnauthenticatedError, UnexpectedError } from '../errors';

Expand Down Expand Up @@ -120,3 +133,107 @@ export function fetchPostReferences(
): ResultAsync<Paginated<AnyPost>, UnexpectedError | UnauthenticatedError> {
return client.query(PostReferencesQuery, { request });
}

/**
* Fetch post tags.
*
* ```ts
* const result = await fetchPostTags(anyClient, {
* forFeeds: [evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')],
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of post tags.
*/
export function fetchPostTags(
client: AnyClient,
request: PostTagsRequest,
): ResultAsync<Paginated<string>, UnexpectedError> {
return client.query(PostTagsQuery, { request });
}

/**
* Fetch post reaction status.
*
* ```ts
* const result = await fetchPostReactionStatus(anyClient, {
* pairs: [{
* account: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')],
* post: postId('42'),
* }],
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of post reaction status.
*/
export function fetchPostReactionStatus(
client: AnyClient,
request: PostReactionStatusRequest,
): ResultAsync<PostReactionStatus[], UnexpectedError> {
return client.query(PostReactionStatusQuery, { request });
}

/**
* Fetch who referenced post.
*
* ```ts
* const result = await fetchWhoReferencedPost(anyClient, {
* referenceTypes: [PostReferenceType.CommentOn]
* post: postId('42'),
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of accounts who referenced the post.
*/
export function fetchWhoReferencedPost(
client: AnyClient,
request: WhoReferencedPostRequest,
): ResultAsync<Paginated<Account>, UnexpectedError> {
return client.query(WhoReferencedPostQuery, { request });
}

/**
* Fetch who acted on post.
*
* ```ts
* const result = await fetchWhoActedOnPost(anyClient, {
* post: postId('42'),
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of accounts who acted on the post.
*/
export function fetchWhoActedOnPost(
client: AnyClient,
request: WhoActedOnPostQueryRequest,
): ResultAsync<Paginated<Account>, UnexpectedError> {
return client.query(WhoActedOnPostQuery, { request });
}

/**
* Fetch post edits.
*
* ```ts
* const result = await fetchPostEdits(anyClient, {
* post: postId('42'),
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of edits for the post.
*/
export function fetchPostEdits(
client: AnyClient,
request: PostEditsRequest,
): ResultAsync<Paginated<PostEdit>, UnexpectedError> {
return client.query(PostEditsQuery, { request });
}
Loading

0 comments on commit fe78e5b

Please sign in to comment.