-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: wallet support for frontend apps and API server methods (#43)
* feat(wip): removed signer from viewMethods by dropping NAJ account.ViewFunction (#35) * feat(wip): removed signer from viewMethods by dropping accounts.ViewFunction * chore: fixed docs and removed comments * chore: fixed linting issues * fix: removed the use of Buffer as it won't work in browser environments * fix: put try/catch for btoa * chore(release): 1.1.0-beta.1 # [1.1.0-beta.1](v1.0.1...v1.1.0-beta.1) (2024-07-24) ### Features * **wip:** removed signer from viewMethods by dropping NAJ account.ViewFunction ([#35](#35)) ([a57edc4](a57edc4)) * feat: remove near-api-js account object dependency from change functions (#38) * refactor: remove dependency on near-api-js account and connection objects from change functions * test: update tests to use new network initialization * chore: squash * docs: amend docs to use new initailaization * docs: update docs to use the new signer object and fix broken links * build(lint): fix linting errors * chore: squash * refactor: convert signer to account because signer is icky * chore(release): 1.1.0-beta.2 # [1.1.0-beta.2](v1.1.0-beta.1...v1.1.0-beta.2) (2024-07-25) ### Features * remove near-api-js account object dependency from change functions ([#38](#38)) ([134e463](134e463)) * fix: required deposit fix when available storage is higher than needed (#40) * fix: required deposit fix when available storage is higher than needed * chore: fixed lint error * chore(release): 1.1.0-beta.3 # [1.1.0-beta.3](v1.1.0-beta.2...v1.1.0-beta.3) (2024-07-30) ### Bug Fixes * required deposit fix when available storage is higher than needed ([#40](#40)) ([99f9e8d](99f9e8d)) * feat: adding api server support for read methods (#33) * feat: adding api server support for read methods * feat(wip): added more args to get and introduced keys method * chore: fixed merge issues * feat: added index() function and docs for all api server changes * docs: fix docs build * chore(release): 1.1.0-beta.4 # [1.1.0-beta.4](v1.1.0-beta.3...v1.1.0-beta.4) (2024-08-01) ### Features * adding api server support for read methods ([#33](#33)) ([dc53b30](dc53b30)) * feat: aded transformActions utility and exposed all utils (#42) feat: added transformActions utility and exposed all utils * chore(release): 1.1.0-beta.5 # [1.1.0-beta.5](v1.1.0-beta.4...v1.1.0-beta.5) (2024-08-05) ### Features * aded transformActions utility and exposed all utils ([#42](#42)) ([bfc9072](bfc9072)) --------- Co-authored-by: nearbuilder <[email protected]> Co-authored-by: Kieran O'Neill <[email protected]>
- Loading branch information
1 parent
b8bb3cb
commit 83bb3a6
Showing
76 changed files
with
1,955 additions
and
556 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
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
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) |
Oops, something went wrong.