-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: adding api server support for read methods #33
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
23b063d
feat: adding api server support for read methods
jaswinder6991 fe43995
feat(wip): added more args to get and introduced keys method
jaswinder6991 0ad88b5
chore: merging with beta, few things might break
jaswinder6991 8c50022
chore: fixed merge issues
jaswinder6991 6322052
feat: added index() function and docs for all api server changes
jaswinder6991 c565651
docs: fix docs build
jaswinder6991 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
import TOCInline from '@theme/TOCInline'; | ||
|
||
# Fetching Indexed Data | ||
|
||
## Overview | ||
|
||
The `index` function in the Social SDK allows you to retrieve indexed values based on specified criteria from the Social API server. This function is crucial for efficient lookups of social interactions or custom indexed data, supporting various filtering, ordering, and pagination options. | ||
|
||
:::note | ||
|
||
The `index` function is only available through the API server and does not have an RPC version. | ||
|
||
::: | ||
|
||
## Function Signature | ||
|
||
```typescript | ||
public async index({ | ||
action, | ||
key, | ||
accountId, | ||
order, | ||
limit, | ||
from, | ||
}: IIndexOptions): Promise<Record<string, unknown>> | ||
``` | ||
|
||
### Parameters | ||
|
||
- `action`: The index_type from the standard (e.g., 'like' in the path 'index/like'). | ||
- `key`: Can be either a string or an object: | ||
- If string: The inner indexed value from the standard. | ||
- If object: Can include properties like type, path, and blockHeight. | ||
- `accountId` (optional): A string or array of account IDs to filter values. | ||
- `order` (optional): The order of results. Either 'asc' or 'desc'. Default is 'asc'. | ||
- `limit` (optional): The number of values to return. Default is 100. | ||
- `from` (optional): The starting point for fetching results. Defaults to 0 or Max depending on order. | ||
|
||
### Return Value | ||
|
||
A promise that resolves to an array of matched indexed values, ordered by blockHeight. | ||
|
||
## Usage Examples | ||
|
||
### Basic Usage | ||
|
||
<Tabs | ||
defaultValue="javascript-via-package-manager" | ||
values={[ | ||
{ label: 'JavaScript (via package manager)', value: 'javascript-via-package-manager' }, | ||
{ label: 'JavaScript (via CDN)', value: 'javascript-via-cdn' }, | ||
{ label: 'TypeScript', value: 'typescript' }, | ||
]}> | ||
<TabItem value="javascript-via-package-manager"> | ||
|
||
```js | ||
const { Social } = require('@builddao/near-social-js'); | ||
|
||
const social = new Social(); | ||
const result = await social.index({ | ||
action: 'like', | ||
key: 'post-123', | ||
}); | ||
|
||
console.log(result); | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="javascript-via-cdn"> | ||
|
||
```js | ||
var social = new NEARSocialSDK(); | ||
|
||
social.index({ | ||
action: 'like', | ||
key: 'post-123', | ||
}).then((result) => { | ||
console.log(result); | ||
}); | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="typescript"> | ||
|
||
```typescript | ||
import { Social } from '@builddao/near-social-js'; | ||
|
||
const social = new Social(); | ||
const result = await social.index({ | ||
action: 'like', | ||
key: 'post-123', | ||
}); | ||
|
||
console.log(result); | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
### Advanced Usage | ||
|
||
You can use additional options to customize the behavior of the `index` function: | ||
|
||
```typescript | ||
const result = await social.index({ | ||
action: 'follow', | ||
key: 'alice.near', | ||
accountId: ['bob.near', 'charlie.near'], | ||
order: 'desc', | ||
limit: '50', | ||
from: 100, | ||
}); | ||
``` | ||
|
||
This example retrieves the last 50 'follow' actions for 'alice.near', starting from the 100th most recent entry, and only includes actions by 'bob.near' and 'charlie.near'. | ||
|
||
## Use Cases | ||
|
||
The `index` function is particularly useful for: | ||
|
||
1. Fetching all 'like' actions for a specific post: | ||
```typescript | ||
const likes = await social.index({ | ||
action: 'like', | ||
key: { | ||
type: 'social', | ||
path: 'efiz.near/post/main', | ||
blockHeight: 124692995,//blockHeight of the post | ||
}, | ||
}); | ||
``` | ||
|
||
2. Retrieving recent 'follow' actions for a user: | ||
```typescript | ||
const result = await social.index({ | ||
action: 'graph', | ||
key: 'follow', | ||
order: 'desc', | ||
accountId: 'alice.near', | ||
limit: '10', | ||
}); | ||
``` | ||
|
||
3. Querying custom indexed data based on application-specific schemas: | ||
```typescript | ||
const customData = await social.index({ | ||
action: 'custom-action', | ||
key: 'app-specific-key', | ||
}); | ||
``` | ||
|
||
By leveraging the `index` function, you can build efficient and scalable features in your NEAR Social applications, such as activity feeds, trending content algorithms, or custom data aggregations. | ||
|
||
:::tip | ||
|
||
Combine the `index` function with `get` and `keys` for comprehensive data retrieval strategies in your application. | ||
|
||
::: |
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,6 +1,7 @@ | ||
# Advanced | ||
|
||
* [Reading Data](advanced/reading-data) | ||
* [Fetching Indexed Data](advanced/fetching-indexed-data) | ||
* [Storing Data](advanced/storing-data) | ||
* [Granting Write Permission](advanced/granting-write-permission) | ||
* [Storage Deposit/Withdrawal](advanced/storage-deposit-withdraw) |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the error with the build is because you need to import the components: