Skip to content

Commit 0a36a0e

Browse files
authored
Refactor endpoint types and align Atomic Assets client (#10)
- consolidate endpoint response type exports and related model fixes - align Atomic Assets client options and response structs with upstream API behavior - add collection schema response support, schema asset count handling, and related nullability fixes - update package metadata, TypeScript/tooling dependencies, and lockfile
1 parent 10490bd commit 0a36a0e

8 files changed

Lines changed: 770 additions & 573 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@wharfkit/atomicassets",
33
"description": "AtomicAsset library for Wharf",
4-
"version": "1.2.3",
4+
"version": "1.2.4",
55
"homepage": "https://github.com/wharfkit/atomicassets",
66
"main": "lib/atomicassets.js",
77
"module": "lib/atomicassets.m.js",
@@ -62,4 +62,4 @@
6262
"typedoc": "^0.23.14",
6363
"typescript": "^4.4"
6464
}
65-
}
65+
}

src/endpoints/assets/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ export class SchemaCount extends Struct {
5050
@Struct.field(UInt64) declare assets: UInt64
5151
}
5252

53+
@Struct.type('collection_schema')
54+
export class CollectionSchema extends Struct {
55+
@Struct.field(Name) declare schema_name: Name
56+
}
57+
5358
@Struct.type('template_count')
5459
export class TemplateCount extends Struct {
5560
@Struct.field(Int32) declare template_id: Int32
@@ -82,6 +87,11 @@ export class GetCollectionStatsResponse extends ResponseStruct {
8287
@Struct.field(CollectionStats) declare data: CollectionStats
8388
}
8489

90+
@Struct.type('get_collection_schemas_resp')
91+
export class GetCollectionSchemasResponse extends ResponseStruct {
92+
@Struct.field(CollectionSchema, {array: true}) declare data: CollectionSchema[]
93+
}
94+
8595
@Struct.type('get_schemas_resp')
8696
export class GetSchemasResponse extends ResponseStruct {
8797
@Struct.field(SchemaObject, {array: true}) declare data: SchemaObject[]

src/endpoints/assets/v1.ts

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export interface GetAssetsOptions {
2525
collection_whitelist?: NameType[]
2626
only_duplicate_templates?: boolean
2727
has_backed_tokens?: boolean
28+
has_template_buyoffer?: boolean
29+
template_mint?: UInt32Type
30+
min_template_mint?: UInt32Type
31+
max_template_mint?: UInt32Type
2832
authorized_account?: NameType
2933
template_whitelist?: Int32Type[]
3034
template_blacklist?: Int32Type[]
@@ -45,12 +49,13 @@ export interface GetAssetsOptions {
4549
export interface GetCollectionsOptions {
4650
author?: NameType[]
4751
match?: string
52+
search?: string
4853
authorized_account?: NameType
4954
notify_account?: NameType
5055
collection_blacklist?: NameType[]
5156
collection_whitelist?: NameType[]
5257
collection_name?: NameType[]
53-
ids?: UInt64Type[]
58+
ids?: NameType[]
5459
lower_bound?: string
5560
upper_bound?: string
5661
before?: number
@@ -68,7 +73,7 @@ export interface GetSchemasOptions {
6873
match?: string
6974
collection_blacklist?: NameType[]
7075
collection_whitelist?: NameType[]
71-
ids?: UInt64Type[]
76+
ids?: NameType[]
7277
lower_bound?: string
7378
upper_bound?: string
7479
before?: number
@@ -91,6 +96,7 @@ export interface GetTemplatesOptions {
9196
is_transferable?: boolean
9297
authorized_account?: NameType
9398
match?: string
99+
search?: string
94100
collection_blacklist?: NameType[]
95101
collection_whitelist?: NameType[]
96102
template_id?: Int32Type[]
@@ -127,8 +133,8 @@ export interface GetOffersOptions {
127133
collection_whitelist?: NameType[]
128134
hide_contracts?: boolean
129135
hide_empty_offers?: boolean
130-
offer_id?: UInt64Type
131-
ids?: UInt64Type
136+
offer_id?: UInt64Type[]
137+
ids?: UInt64Type[]
132138
lower_bound?: string
133139
upper_bound?: string
134140
before?: number
@@ -174,12 +180,28 @@ export interface GetAccountsOptions {
174180
collection_blacklist?: NameType[]
175181
collection_whitelist?: NameType[]
176182
owner?: NameType[]
177-
ids?: UInt64Type[]
183+
ids?: NameType[]
184+
lower_bound?: string
185+
upper_bound?: string
186+
page?: number
187+
limit?: number
188+
}
189+
190+
export interface GetBurnsOptions {
191+
match_owner?: string
192+
collection_name?: NameType[]
193+
schema_name?: NameType[]
194+
template_id?: Int32Type[]
195+
burned?: boolean
196+
hide_offers?: boolean
197+
collection_blacklist?: NameType[]
198+
collection_whitelist?: NameType[]
199+
burned_by_account?: NameType[]
200+
ids?: NameType[]
178201
lower_bound?: string
179202
upper_bound?: string
180203
page?: number
181204
limit?: number
182-
order?: 'asc' | 'desc'
183205
}
184206

185207
export class AssetsV1APIClient {
@@ -286,6 +308,14 @@ export class AssetsV1APIClient {
286308
})
287309
}
288310

311+
async get_collection_schemas(collection_name: NameType) {
312+
return this.client.call({
313+
path: `/atomicassets/v1/collections/${collection_name}/schemas`,
314+
method: 'GET',
315+
responseType: Assets.GetCollectionSchemasResponse,
316+
})
317+
}
318+
289319
async get_collection_logs(
290320
collection_name: NameType,
291321
options?: {
@@ -404,9 +434,19 @@ export class AssetsV1APIClient {
404434
})
405435
}
406436

407-
async get_template_stats(collection_name: NameType, template_id: Int32Type) {
437+
async get_template_stats(template_id: Int32Type): Promise<any>
438+
async get_template_stats(collection_name: NameType, template_id: Int32Type): Promise<any>
439+
async get_template_stats(
440+
collection_name_or_template_id: NameType | Int32Type,
441+
template_id?: Int32Type
442+
) {
443+
const path =
444+
typeof template_id === 'undefined'
445+
? `/atomicassets/v1/templates/${collection_name_or_template_id}/stats`
446+
: `/atomicassets/v1/templates/${collection_name_or_template_id}/${template_id}/stats`
447+
408448
return this.client.call({
409-
path: `/atomicassets/v1/templates/${collection_name}/${template_id}/stats`,
449+
path,
410450
method: 'GET',
411451
responseType: Assets.GetTemplateStatsResponse,
412452
})
@@ -562,22 +602,7 @@ export class AssetsV1APIClient {
562602
})
563603
}
564604

565-
async get_burns(options?: {
566-
match_owner?: string
567-
collection_name?: NameType[]
568-
schema_name?: NameType[]
569-
template_id?: Int32Type[]
570-
burned?: boolean
571-
collection_blacklist?: NameType[]
572-
collection_whitelist?: NameType[]
573-
burned_by_account?: NameType[]
574-
ids?: UInt64Type[]
575-
lower_bound?: string
576-
upper_bound?: string
577-
page?: number
578-
limit?: number
579-
order?: 'asc' | 'desc'
580-
}) {
605+
async get_burns(options?: GetBurnsOptions) {
581606
const bodyParams = buildBodyParams(options)
582607

583608
return this.client.call({

src/endpoints/types.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export class CollectionObject extends Struct {
131131
@Struct.type('schema_object')
132132
export class SchemaObject extends Struct {
133133
@Struct.field(Name) declare schema_name: Name
134+
@Struct.field(UInt64, {optional: true}) declare assets: UInt64
134135
@Struct.field(AtomicAssetsContract.Types.FORMAT, {array: true})
135136
declare format: AtomicAssetsContract.Types.FORMAT[]
136137
@Struct.field(Name, {optional: true}) declare contract: Name
@@ -505,8 +506,8 @@ export class BurnedBySchema extends Struct {
505506

506507
@Struct.type('collection_stats')
507508
export class CollectionStats extends Struct {
508-
@Struct.field(UInt64) declare assets: UInt64
509-
@Struct.field(UInt64) declare burned: UInt64
509+
@Struct.field(UInt64, {optional: true}) declare assets: UInt64
510+
@Struct.field(UInt64, {optional: true}) declare burned: UInt64
510511
@Struct.field(UInt64) declare templates: UInt64
511512
@Struct.field(UInt64) declare schemas: UInt64
512513
@Struct.field(BurnedByTemplate, {array: true})
@@ -528,8 +529,8 @@ export class TemplateStats extends Struct {
528529

529530
@Struct.type('schema_stats')
530531
export class SchemaStats extends Struct {
531-
@Struct.field(UInt64) declare assets: UInt64
532-
@Struct.field(UInt64) declare burned: UInt64
532+
@Struct.field(UInt64, {optional: true}) declare assets: UInt64
533+
@Struct.field(UInt64, {optional: true}) declare burned: UInt64
533534
@Struct.field(UInt64) declare templates: UInt64
534535
}
535536

src/endpoints/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function buildBodyParams(
2222
export function fixPostArguments(params) {
2323
// https://github.com/pinknetworkx/eosio-contract-api/issues/131
2424
const options = {...params}
25-
for (const key of ['page', 'limit', 'before', 'after'])
25+
for (const key of ['page', 'limit', 'before', 'after', 'burned'])
2626
if (key in options) {
2727
options[key] = String(options[key])
2828
}

src/objects/schema.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {Action, NameType} from '@wharfkit/antelope'
2-
import {Name} from '@wharfkit/antelope'
2+
import {Name, UInt64} from '@wharfkit/antelope'
33
import type {SchemaObject} from '../types'
44
import {Collection} from './collection'
55
import type * as AtomicAssetsContract from '../contracts/atomicassets'
@@ -25,6 +25,10 @@ export class Schema {
2525
return Name.from(this.data.schema_name)
2626
}
2727

28+
get assets() {
29+
return UInt64.from(this.data.assets)
30+
}
31+
2832
get format() {
2933
return this.data.format
3034
}

test/schema.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ suite('Schema', function () {
4343
assert.isTrue(testSchema.schemaName.equals(schemaName))
4444
})
4545

46+
test('assets', function () {
47+
assert.isTrue(testSchema.assets.toNumber() > 0)
48+
})
49+
4650
test('collection', function () {
4751
assert.isTrue(testSchema.collection.collectionName.equals(collectionName))
4852
})

0 commit comments

Comments
 (0)