Skip to content

Commit

Permalink
feat: add getAtomicAsset and getCollection functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Envoy-VC committed Dec 26, 2023
1 parent 44bd9c3 commit fa6a5fd
Show file tree
Hide file tree
Showing 27 changed files with 2,417 additions and 323 deletions.
File renamed without changes.
57 changes: 57 additions & 0 deletions apps/docs/guides/atomic-asset/get-atomic-asset.mdx
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.
68 changes: 68 additions & 0 deletions apps/docs/guides/collection/get-collection.mdx
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"
]
}
}
```
10 changes: 8 additions & 2 deletions apps/docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,18 @@
{
"group": "Atomic Asset",
"icon": "image",
"pages": ["guides/create-atomic-asset"]
"pages": [
"guides/atomic-asset/create-atomic-asset",
"guides/atomic-asset/get-atomic-asset"
]
},
{
"group": "Collection",
"icon": "layer-group",
"pages": ["guides/create-collection"]
"pages": [
"guides/collection/create-collection",
"guides/collection/get-collection"
]
}
]
},
Expand Down
Binary file removed packages/atomic-toolkit/assets/test.jpeg
Binary file not shown.
19 changes: 19 additions & 0 deletions packages/atomic-toolkit/codegen.ts
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;
66 changes: 66 additions & 0 deletions packages/atomic-toolkit/generated/fragment-masking.ts
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);
}
47 changes: 47 additions & 0 deletions packages/atomic-toolkit/generated/gql.ts
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;
Loading

0 comments on commit fa6a5fd

Please sign in to comment.