-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add getAtomicAsset and getCollection functions
- Loading branch information
Showing
27 changed files
with
2,417 additions
and
323 deletions.
There are no files selected for viewing
File renamed without changes.
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,57 @@ | ||
--- | ||
title: Get Atomic Asset | ||
description: Returns details regarding the Atomic Asset including the evaluated state. | ||
--- | ||
|
||
## Usage | ||
|
||
```ts | ||
const res = await toolkit.assets.getAtomicAsset(id); | ||
``` | ||
|
||
## Input Parameters | ||
|
||
- **id: `string`**: The Atomic Asset ID. | ||
|
||
<Note> | ||
The Function will throw an error if Transaction Id does not has necessary | ||
Atomic Asset Tags | ||
</Note> | ||
|
||
## Return Value | ||
|
||
The return value is a Promise that resolves to the `object`. It has the following properties: | ||
|
||
- **id: `string`**: The transaction ID of the Atomic Asset contract. | ||
- **owner**: The Owner of the Transaction, it has the following tow feilds: | ||
- **id: `string`**: The Address of the owner. | ||
- **key: `string`**: The key of the owner. | ||
- **tags: Tag[]**: The Tags of the Atomic Asset. | ||
- **state: `Record<string,any>`**: The current evaluated state for the Atomic Asset. | ||
|
||
## Example | ||
|
||
```ts | ||
const id = 'HbsnADOnipgjAlVWwH-cClIozntMm6ePuER6HZp8Qf8'; | ||
|
||
const res = await toolkit.assets.getAtomicAsset(id); | ||
``` | ||
|
||
**Response:** | ||
|
||
```json | ||
{ | ||
"id": "HbsnADOnipgjAlVWwH-cClIozntMm6ePuER6HZp8Qf8", | ||
"owner": { | ||
"address": "9WQ7xH2LOuqfAccjGquck8eaKARg1vMhRJaOo3LJL14", | ||
"key": "..." | ||
}, | ||
"tags": [...], | ||
"state": { | ||
"name": "Envoy_ Avatar", | ||
"ticker": "ENVOY", | ||
"balances": { "9WQ7xH2LOuqfAccjGquck8eaKARg1vMhRJaOo3LJL14": 1 }, | ||
"claimable": [] | ||
} | ||
} | ||
``` |
File renamed without changes.
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,68 @@ | ||
--- | ||
title: Get Collection | ||
description: Returns details regarding the collection. | ||
--- | ||
|
||
## Usage | ||
|
||
```ts | ||
const res = await toolkit.collection.getCollection(id); | ||
``` | ||
|
||
## Input Parameters | ||
|
||
- **id: `string`**: The Collection to retrieve. | ||
|
||
<Note> | ||
The Function will throw an error if Id does not has necessary Tags as per | ||
the [Collection | ||
Protocol](https://specs.arweave.dev/#/view/4zqtz8-U4LNKjFU4gZ28oKkV6bTlfzJiguqjbMl9R4Q) | ||
</Note> | ||
|
||
## Return Value | ||
|
||
The return value is a Promise that resolves to the `object`. It has the following properties: | ||
|
||
- **id: `string`**: The transaction ID of the Collection | ||
- **owner**: The Owner of the Transaction, it has the following tow feilds: | ||
- **id: `string`**: The Address of the owner. | ||
- **key: `string`**: The key of the owner. | ||
- **tags: Tag[]**: The Tags of the Atomic Asset. | ||
- **state: `CollectionData`**: The Collection Data, it has the following fields: | ||
- **type: `string`**: Collection | ||
- **items: `string[]`**: The Items of the Collection. | ||
|
||
## Example | ||
|
||
```ts | ||
const id = 'naUSbwwYgZo1Zo8wD1jsWNTulydnccOTnx6eOyzy5AM'; | ||
|
||
const res = await toolkit.collection.getCollection(id); | ||
``` | ||
|
||
**Response:** | ||
|
||
```json | ||
{ | ||
"id": "naUSbwwYgZo1Zo8wD1jsWNTulydnccOTnx6eOyzy5AM", | ||
"owner": { | ||
"address": "lI9-NG4x2OLcoH-mC-I1FDTH103Up_yjuiRcNQG77Kg", | ||
"key": "..." | ||
}, | ||
"tags": [...], | ||
"data": { | ||
"type": "Collection", | ||
"items": [ | ||
"sGzVbVABiWT6fnU7qruryjilYeufjKabNBoy1wS1LlA", | ||
"du9bVSXdLobW7Qq5dxjHK7jC3o9BXLXaY_b-Amj6dBc", | ||
"sp-4lXQpoSN2eC-cozHciZkjxV_kzaXfgsHtiNH_8hs", | ||
"cwjwZv0wV8b-6G9MvOxxYlN_6Vv69_K--g4HIKMsXd8", | ||
"qJT8sHT5B0AMKt87zogCGVyPS-GTxlhxVibNNCbOfj4", | ||
"JHj7KEfjADfwSasspI8f5yCvfZL1YhRvSkP8FOWLVaM", | ||
"_99PpbdCgDtj3FjVn4YOAxDleARCBEMZK0JPulwz1Wk", | ||
"h2wXK7uqdSx9H2-bISdNNTGmLiStA8_TASFuAQP3FCk", | ||
"1y_mTr00n7btOw4YkNV8rXhjs9rZNpzhVXwa14FqfJc" | ||
] | ||
} | ||
} | ||
``` |
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
File renamed without changes
Binary file not shown.
File renamed without changes
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,19 @@ | ||
import { CodegenConfig } from '@graphql-codegen/cli'; | ||
import { maskTypename } from '@urql/core'; | ||
|
||
const config: CodegenConfig = { | ||
schema: 'https://arweave.net/graphql', | ||
documents: ['src/**/*.ts'], | ||
generates: { | ||
'./generated/': { | ||
preset: 'client-preset', | ||
config: { | ||
strictScalars: true, | ||
maskTypename: true, | ||
useTypeImports: true, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default config; |
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,66 @@ | ||
import type { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; | ||
import type { FragmentDefinitionNode } from 'graphql'; | ||
import type { Incremental } from './graphql'; | ||
|
||
|
||
export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> = TDocumentType extends DocumentTypeDecoration< | ||
infer TType, | ||
any | ||
> | ||
? [TType] extends [{ ' $fragmentName'?: infer TKey }] | ||
? TKey extends string | ||
? { ' $fragmentRefs'?: { [key in TKey]: TType } } | ||
: never | ||
: never | ||
: never; | ||
|
||
// return non-nullable if `fragmentType` is non-nullable | ||
export function useFragment<TType>( | ||
_documentNode: DocumentTypeDecoration<TType, any>, | ||
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | ||
): TType; | ||
// return nullable if `fragmentType` is nullable | ||
export function useFragment<TType>( | ||
_documentNode: DocumentTypeDecoration<TType, any>, | ||
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined | ||
): TType | null | undefined; | ||
// return array of non-nullable if `fragmentType` is array of non-nullable | ||
export function useFragment<TType>( | ||
_documentNode: DocumentTypeDecoration<TType, any>, | ||
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | ||
): ReadonlyArray<TType>; | ||
// return array of nullable if `fragmentType` is array of nullable | ||
export function useFragment<TType>( | ||
_documentNode: DocumentTypeDecoration<TType, any>, | ||
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined | ||
): ReadonlyArray<TType> | null | undefined; | ||
export function useFragment<TType>( | ||
_documentNode: DocumentTypeDecoration<TType, any>, | ||
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined | ||
): TType | ReadonlyArray<TType> | null | undefined { | ||
return fragmentType as any; | ||
} | ||
|
||
|
||
export function makeFragmentData< | ||
F extends DocumentTypeDecoration<any, any>, | ||
FT extends ResultOf<F> | ||
>(data: FT, _fragment: F): FragmentType<F> { | ||
return data as FragmentType<F>; | ||
} | ||
export function isFragmentReady<TQuery, TFrag>( | ||
queryNode: DocumentTypeDecoration<TQuery, any>, | ||
fragmentNode: TypedDocumentNode<TFrag>, | ||
data: FragmentType<TypedDocumentNode<Incremental<TFrag>, any>> | null | undefined | ||
): data is FragmentType<typeof fragmentNode> { | ||
const deferredFields = (queryNode as { __meta__?: { deferredFields: Record<string, (keyof TFrag)[]> } }).__meta__ | ||
?.deferredFields; | ||
|
||
if (!deferredFields) return true; | ||
|
||
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined; | ||
const fragName = fragDef?.name?.value; | ||
|
||
const fields = (fragName && deferredFields[fragName]) || []; | ||
return fields.length > 0 && fields.every(field => data && field in data); | ||
} |
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,47 @@ | ||
/* eslint-disable */ | ||
import * as types from './graphql'; | ||
import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; | ||
|
||
/** | ||
* Map of all GraphQL operations in the project. | ||
* | ||
* This map has several performance disadvantages: | ||
* 1. It is not tree-shakeable, so it will include all operations in the project. | ||
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle. | ||
* 3. It does not support dead code elimination, so it will add unused operations. | ||
* | ||
* Therefore it is highly recommended to use the babel or swc plugin for production. | ||
*/ | ||
const documents = { | ||
"\n query GetAtomicAsset($transactionId: ID!) {\n transaction(id: $transactionId) {\n id\n owner {\n address\n key\n }\n tags {\n name\n value\n }\n }\n }\n": types.GetAtomicAssetDocument, | ||
"\n query GetCollection($collectionId: ID!) {\n transaction(id: $collectionId) {\n id\n owner {\n address\n key\n }\n tags {\n name\n value\n }\n }\n }\n": types.GetCollectionDocument, | ||
}; | ||
|
||
/** | ||
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. | ||
* | ||
* | ||
* @example | ||
* ```ts | ||
* const query = graphql(`query GetUser($id: ID!) { user(id: $id) { name } }`); | ||
* ``` | ||
* | ||
* The query argument is unknown! | ||
* Please regenerate the types. | ||
*/ | ||
export function graphql(source: string): unknown; | ||
|
||
/** | ||
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. | ||
*/ | ||
export function graphql(source: "\n query GetAtomicAsset($transactionId: ID!) {\n transaction(id: $transactionId) {\n id\n owner {\n address\n key\n }\n tags {\n name\n value\n }\n }\n }\n"): (typeof documents)["\n query GetAtomicAsset($transactionId: ID!) {\n transaction(id: $transactionId) {\n id\n owner {\n address\n key\n }\n tags {\n name\n value\n }\n }\n }\n"]; | ||
/** | ||
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. | ||
*/ | ||
export function graphql(source: "\n query GetCollection($collectionId: ID!) {\n transaction(id: $collectionId) {\n id\n owner {\n address\n key\n }\n tags {\n name\n value\n }\n }\n }\n"): (typeof documents)["\n query GetCollection($collectionId: ID!) {\n transaction(id: $collectionId) {\n id\n owner {\n address\n key\n }\n tags {\n name\n value\n }\n }\n }\n"]; | ||
|
||
export function graphql(source: string) { | ||
return (documents as any)[source] ?? {}; | ||
} | ||
|
||
export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode< infer TType, any> ? TType : never; |
Oops, something went wrong.