@wishknish/knishio-client-ts 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/README.md +425 -0
- package/dist/index.cjs +9961 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.iife.js +32241 -0
- package/dist/index.iife.js.map +1 -0
- package/dist/index.js +9853 -0
- package/dist/index.js.map +1 -0
- package/package.json +113 -0
- package/src/AuthToken.ts +214 -0
- package/src/KnishIOClient.ts +2020 -0
- package/src/constants.ts +398 -0
- package/src/core/Atom.ts +646 -0
- package/src/core/AtomMeta.ts +278 -0
- package/src/core/Meta.ts +428 -0
- package/src/core/Molecule.ts +825 -0
- package/src/core/PolicyMeta.ts +130 -0
- package/src/core/TokenUnit.ts +148 -0
- package/src/core/Wallet.ts +467 -0
- package/src/exception/AtomIndexException.ts +97 -0
- package/src/exception/AtomsMissingException.ts +109 -0
- package/src/exception/AuthorizationRejectedException.ts +63 -0
- package/src/exception/BalanceInsufficientException.ts +58 -0
- package/src/exception/BaseException.ts +275 -0
- package/src/exception/BatchIdException.ts +58 -0
- package/src/exception/CodeException.ts +119 -0
- package/src/exception/DecryptionKeyException.ts +65 -0
- package/src/exception/InvalidResponseException.ts +112 -0
- package/src/exception/MetaMissingException.ts +58 -0
- package/src/exception/MolecularHashMismatchException.ts +115 -0
- package/src/exception/MolecularHashMissingException.ts +58 -0
- package/src/exception/NegativeAmountException.ts +58 -0
- package/src/exception/PolicyInvalidException.ts +58 -0
- package/src/exception/SignatureMalformedException.ts +58 -0
- package/src/exception/SignatureMismatchException.ts +98 -0
- package/src/exception/StackableUnitAmountException.ts +65 -0
- package/src/exception/StackableUnitDecimalsException.ts +65 -0
- package/src/exception/TransferBalanceException.ts +98 -0
- package/src/exception/TransferMalformedException.ts +58 -0
- package/src/exception/TransferMismatchedException.ts +58 -0
- package/src/exception/TransferRemainderException.ts +58 -0
- package/src/exception/TransferToSelfException.ts +58 -0
- package/src/exception/TransferUnbalancedException.ts +58 -0
- package/src/exception/UnauthenticatedException.ts +147 -0
- package/src/exception/WalletCredentialException.ts +108 -0
- package/src/exception/WalletShadowException.ts +65 -0
- package/src/exception/WrongTokenTypeException.ts +58 -0
- package/src/exception/index.ts +272 -0
- package/src/index.ts +512 -0
- package/src/instance/rules/Callback.ts +257 -0
- package/src/instance/rules/Condition.ts +96 -0
- package/src/instance/rules/Meta.ts +163 -0
- package/src/instance/rules/Rule.ts +29 -0
- package/src/instance/rules/exception/RuleArgumentException.ts +65 -0
- package/src/libraries/CheckMolecule.ts +581 -0
- package/src/libraries/Decimal.ts +94 -0
- package/src/libraries/Dot.ts +202 -0
- package/src/libraries/GraphQLClient.ts +276 -0
- package/src/libraries/Hex.ts +155 -0
- package/src/libraries/UrqlClientWrapper.ts +336 -0
- package/src/libraries/array.ts +91 -0
- package/src/libraries/crypto.ts +816 -0
- package/src/libraries/strings.ts +458 -0
- package/src/mutation/Mutation.ts +103 -0
- package/src/mutation/MutationActiveSession.ts +108 -0
- package/src/mutation/MutationClaimShadowWallet.ts +91 -0
- package/src/mutation/MutationCreateIdentifier.ts +86 -0
- package/src/mutation/MutationCreateMeta.ts +92 -0
- package/src/mutation/MutationCreateRule.ts +90 -0
- package/src/mutation/MutationCreateToken.ts +92 -0
- package/src/mutation/MutationCreateWallet.ts +78 -0
- package/src/mutation/MutationDepositBufferToken.ts +72 -0
- package/src/mutation/MutationLinkIdentifier.ts +87 -0
- package/src/mutation/MutationProposeMolecule.ts +147 -0
- package/src/mutation/MutationRequestAuthorization.ts +77 -0
- package/src/mutation/MutationRequestAuthorizationGuest.ts +85 -0
- package/src/mutation/MutationRequestTokens.ts +98 -0
- package/src/mutation/MutationTransferTokens.ts +87 -0
- package/src/mutation/MutationWithdrawBufferToken.ts +73 -0
- package/src/query/Query.ts +187 -0
- package/src/query/QueryActiveSession.ts +89 -0
- package/src/query/QueryAtom.ts +275 -0
- package/src/query/QueryBalance.ts +102 -0
- package/src/query/QueryBatch.ts +145 -0
- package/src/query/QueryBatchHistory.ts +86 -0
- package/src/query/QueryContinuId.ts +91 -0
- package/src/query/QueryMetaType.ts +177 -0
- package/src/query/QueryMetaTypeViaAtom.ts +199 -0
- package/src/query/QueryPolicy.ts +91 -0
- package/src/query/QueryToken.ts +90 -0
- package/src/query/QueryUserActivity.ts +153 -0
- package/src/query/QueryWalletBundle.ts +92 -0
- package/src/query/QueryWalletList.ts +106 -0
- package/src/response/EnhancedResponse.ts +345 -0
- package/src/response/Response.ts +254 -0
- package/src/response/ResponseActiveSession.ts +72 -0
- package/src/response/ResponseAtom.ts +132 -0
- package/src/response/ResponseAuthorizationGuest.ts +119 -0
- package/src/response/ResponseBalance.ts +153 -0
- package/src/response/ResponseClaimShadowWallet.ts +56 -0
- package/src/response/ResponseContinuId.ts +101 -0
- package/src/response/ResponseCreateIdentifier.ts +56 -0
- package/src/response/ResponseCreateMeta.ts +58 -0
- package/src/response/ResponseCreateRule.ts +56 -0
- package/src/response/ResponseCreateToken.ts +58 -0
- package/src/response/ResponseCreateWallet.ts +58 -0
- package/src/response/ResponseLinkIdentifier.ts +87 -0
- package/src/response/ResponseMetaBatch.ts +72 -0
- package/src/response/ResponseMetaType.ts +108 -0
- package/src/response/ResponseMetaTypeViaAtom.ts +108 -0
- package/src/response/ResponsePolicy.ts +90 -0
- package/src/response/ResponseProposeMolecule.ts +155 -0
- package/src/response/ResponseQueryActiveSession.ts +105 -0
- package/src/response/ResponseQueryUserActivity.ts +89 -0
- package/src/response/ResponseRequestAuthorization.ts +100 -0
- package/src/response/ResponseRequestAuthorizationGuest.ts +133 -0
- package/src/response/ResponseRequestTokens.ts +58 -0
- package/src/response/ResponseTransferTokens.ts +72 -0
- package/src/response/ResponseWalletBundle.ts +95 -0
- package/src/response/ResponseWalletList.ts +165 -0
- package/src/schemas/index.ts +457 -0
- package/src/subscribe/ActiveSessionSubscribe.ts +72 -0
- package/src/subscribe/ActiveWalletSubscribe.ts +99 -0
- package/src/subscribe/CreateMoleculeSubscribe.ts +106 -0
- package/src/subscribe/Subscribe.ts +182 -0
- package/src/subscribe/WalletStatusSubscribe.ts +70 -0
- package/src/subscribe/index.ts +59 -0
- package/src/types/assertions.ts +722 -0
- package/src/types/client.ts +567 -0
- package/src/types/crypto.ts +541 -0
- package/src/types/graphql.ts +630 -0
- package/src/types/guards.ts +659 -0
- package/src/types/index.ts +614 -0
- package/src/types/response.ts +133 -0
- package/src/types/template-literals.ts +382 -0
- package/src/validation/UNIVERSAL_CONFIGURATION_INTERFACES.ts +580 -0
- package/src/validation/ValidationService.ts +607 -0
- package/src/validation/schemas.ts +447 -0
- package/src/versions/HashAtom.ts +170 -0
- package/src/versions/Version4.ts +120 -0
- package/src/versions/index.ts +80 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/*
|
|
2
|
+
(
|
|
3
|
+
(/(
|
|
4
|
+
(//(
|
|
5
|
+
(///(
|
|
6
|
+
(/////(
|
|
7
|
+
(//////( )
|
|
8
|
+
(////////( (/)
|
|
9
|
+
(////////( (///)
|
|
10
|
+
(//////////( (////)
|
|
11
|
+
(//////////( (//////)
|
|
12
|
+
(////////////( (///////)
|
|
13
|
+
(/////////////( (/////////)
|
|
14
|
+
(//////////////( (///////////)
|
|
15
|
+
(///////////////( (/////////////)
|
|
16
|
+
(////////////////( (//////////////)
|
|
17
|
+
((((((((((((((((((( (((((((((((((((
|
|
18
|
+
((((((((((((((((((( ((((((((((((((
|
|
19
|
+
((((((((((((((((((( ((((((((((((((
|
|
20
|
+
(((((((((((((((((((( (((((((((((((
|
|
21
|
+
(((((((((((((((((((( ((((((((((((
|
|
22
|
+
((((((((((((((((((( ((((((((((((
|
|
23
|
+
((((((((((((((((((( ((((((((((
|
|
24
|
+
((((((((((((((((((/ (((((((((
|
|
25
|
+
(((((((((((((((((( ((((((((
|
|
26
|
+
((((((((((((((((( (((((((
|
|
27
|
+
(((((((((((((((((( (((((
|
|
28
|
+
################# ##
|
|
29
|
+
################ #
|
|
30
|
+
################# ##
|
|
31
|
+
%################ ###
|
|
32
|
+
###############( ####
|
|
33
|
+
############### ####
|
|
34
|
+
############### ######
|
|
35
|
+
%#############( (#######
|
|
36
|
+
%############# #########
|
|
37
|
+
############( ##########
|
|
38
|
+
########### #############
|
|
39
|
+
######### ##############
|
|
40
|
+
%######
|
|
41
|
+
|
|
42
|
+
Powered by Knish.IO: Connecting a Decentralized World
|
|
43
|
+
|
|
44
|
+
Please visit https://github.com/WishKnish/KnishIO-Client-TS for information.
|
|
45
|
+
|
|
46
|
+
License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
import { CodeException } from '@/exception'
|
|
50
|
+
import type Response from '@/response/Response'
|
|
51
|
+
import type { GraphQLClient } from '@/types'
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Base Query class for constructing GraphQL queries
|
|
55
|
+
*/
|
|
56
|
+
export default class Query {
|
|
57
|
+
protected client: GraphQLClient
|
|
58
|
+
protected knishIOClient: any // Will be KnishIOClient type
|
|
59
|
+
protected $__variables: Record<string, any> | null = null
|
|
60
|
+
protected $__query: string | null = null
|
|
61
|
+
protected $__response: Response | null = null
|
|
62
|
+
protected $__request: any = null
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Create new Query instance
|
|
66
|
+
*/
|
|
67
|
+
constructor(graphQLClient: GraphQLClient, knishIOClient: any) {
|
|
68
|
+
this.client = graphQLClient
|
|
69
|
+
this.knishIOClient = knishIOClient
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Return a response object
|
|
74
|
+
* Used at KnishIOClient::createMolecule => sets the source wallet from the remainder one stored in response object
|
|
75
|
+
*/
|
|
76
|
+
response(): Response | null {
|
|
77
|
+
return this.$__response
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Builds a Response based on JSON input
|
|
82
|
+
*/
|
|
83
|
+
async createResponseRaw(response: any): Promise<Response> {
|
|
84
|
+
return this.createResponse(response)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Returns a Response object
|
|
89
|
+
*/
|
|
90
|
+
createResponse(json: any): Response {
|
|
91
|
+
// Import here to avoid circular dependency
|
|
92
|
+
const Response = require('@/response/Response').default
|
|
93
|
+
return new Response({
|
|
94
|
+
query: this,
|
|
95
|
+
json
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Compiles variables for the query
|
|
101
|
+
* Can be overridden by subclasses to add specific variables
|
|
102
|
+
*/
|
|
103
|
+
compiledVariables(variables: Record<string, any> | null = null): Record<string, any> {
|
|
104
|
+
return variables || {}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Gets the current variables
|
|
109
|
+
*/
|
|
110
|
+
variables(): Record<string, any> | null {
|
|
111
|
+
return this.$__variables
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Gets the node URI
|
|
116
|
+
*/
|
|
117
|
+
uri(): string {
|
|
118
|
+
return this.client.getUri()
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Creates a new Request for the given parameters
|
|
123
|
+
*/
|
|
124
|
+
createQuery({ variables = null }: { variables?: Record<string, any> | null }): any {
|
|
125
|
+
this.$__variables = this.compiledVariables(variables)
|
|
126
|
+
|
|
127
|
+
// Uri is a required parameter
|
|
128
|
+
const uri = this.uri()
|
|
129
|
+
if (!uri) {
|
|
130
|
+
throw new CodeException('Query::createQuery() - Node URI was not initialized for this client instance!')
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (this.$__query === null) {
|
|
134
|
+
throw new CodeException('Query::createQuery() - GraphQL query was not initialized!')
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
query: this.$__query,
|
|
139
|
+
variables: this.variables()
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Creates the query context
|
|
145
|
+
*/
|
|
146
|
+
createQueryContext(): Record<string, any> {
|
|
147
|
+
return {}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Executes the Query and returns a Response
|
|
152
|
+
*/
|
|
153
|
+
async execute({
|
|
154
|
+
variables = {},
|
|
155
|
+
context = {}
|
|
156
|
+
}: {
|
|
157
|
+
variables?: Record<string, any>
|
|
158
|
+
context?: Record<string, any>
|
|
159
|
+
} = {}): Promise<Response | null> {
|
|
160
|
+
this.$__request = this.createQuery({ variables })
|
|
161
|
+
|
|
162
|
+
const mergedContext = {
|
|
163
|
+
...context,
|
|
164
|
+
...this.createQueryContext()
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
const queryParams = {
|
|
169
|
+
...this.$__request,
|
|
170
|
+
context: mergedContext
|
|
171
|
+
}
|
|
172
|
+
const response = await this.client.query(queryParams)
|
|
173
|
+
this.$__response = await this.createResponseRaw(response)
|
|
174
|
+
return this.$__response
|
|
175
|
+
} catch (error) {
|
|
176
|
+
if ((error as any).name === 'AbortError') {
|
|
177
|
+
this.knishIOClient.log('warn', 'Query was cancelled')
|
|
178
|
+
const Response = require('@/response/Response').default
|
|
179
|
+
return new Response({
|
|
180
|
+
query: this,
|
|
181
|
+
json: { data: null, errors: [{ message: 'Query was cancelled' }] }
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
throw error
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/*
|
|
2
|
+
(
|
|
3
|
+
(/(
|
|
4
|
+
(//(
|
|
5
|
+
(///(
|
|
6
|
+
(/////(
|
|
7
|
+
(//////( )
|
|
8
|
+
(////////( (/)
|
|
9
|
+
(////////( (///)
|
|
10
|
+
(//////////( (////)
|
|
11
|
+
(//////////( (//////)
|
|
12
|
+
(////////////( (///////)
|
|
13
|
+
(/////////////( (/////////)
|
|
14
|
+
(//////////////( (///////////)
|
|
15
|
+
(///////////////( (/////////////)
|
|
16
|
+
(////////////////( (//////////////)
|
|
17
|
+
((((((((((((((((((( (((((((((((((((
|
|
18
|
+
((((((((((((((((((( ((((((((((((((
|
|
19
|
+
((((((((((((((((((( ((((((((((((((
|
|
20
|
+
(((((((((((((((((((( (((((((((((((
|
|
21
|
+
(((((((((((((((((((( ((((((((((((
|
|
22
|
+
((((((((((((((((((( ((((((((((((
|
|
23
|
+
((((((((((((((((((( ((((((((((
|
|
24
|
+
((((((((((((((((((/ (((((((((
|
|
25
|
+
(((((((((((((((((( ((((((((
|
|
26
|
+
((((((((((((((((( (((((((
|
|
27
|
+
(((((((((((((((((( (((((
|
|
28
|
+
################# ##
|
|
29
|
+
################ #
|
|
30
|
+
################# ##
|
|
31
|
+
%################ ###
|
|
32
|
+
###############( ####
|
|
33
|
+
############### ####
|
|
34
|
+
############### ######
|
|
35
|
+
%#############( (#######
|
|
36
|
+
%############# #########
|
|
37
|
+
############( ##########
|
|
38
|
+
########### #############
|
|
39
|
+
######### ##############
|
|
40
|
+
%######
|
|
41
|
+
|
|
42
|
+
Powered by Knish.IO: Connecting a Decentralized World
|
|
43
|
+
|
|
44
|
+
Please visit https://github.com/WishKnish/KnishIO-Client-TS for information.
|
|
45
|
+
|
|
46
|
+
License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
import Query from './Query'
|
|
50
|
+
import ResponseQueryActiveSession from '@/response/ResponseQueryActiveSession'
|
|
51
|
+
import { gql } from '@urql/core'
|
|
52
|
+
import type { GraphQLClient as IGraphQLClient } from '@/types'
|
|
53
|
+
import type KnishIOClient from '@/KnishIOClient'
|
|
54
|
+
import type { BundleHash, MetaType, MetaId } from '@/types'
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Query for retrieving a list of active User Sessions
|
|
58
|
+
*/
|
|
59
|
+
export default class QueryActiveSession extends Query {
|
|
60
|
+
/**
|
|
61
|
+
* Constructor
|
|
62
|
+
*/
|
|
63
|
+
constructor(graphQLClient: IGraphQLClient, knishIOClient: KnishIOClient) {
|
|
64
|
+
super(graphQLClient, knishIOClient)
|
|
65
|
+
|
|
66
|
+
this.$__query = gql`
|
|
67
|
+
query ActiveUserQuery($bundleHash: String, $metaType: String, $metaId: String) {
|
|
68
|
+
ActiveUser(bundleHash: $bundleHash, metaType: $metaType, metaId: $metaId) {
|
|
69
|
+
bundleHash
|
|
70
|
+
metaType
|
|
71
|
+
metaId
|
|
72
|
+
jsonData
|
|
73
|
+
createdAt
|
|
74
|
+
updatedAt
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
`
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Creates a Response object
|
|
82
|
+
*/
|
|
83
|
+
override createResponse(json: Record<string, any>): ResponseQueryActiveSession {
|
|
84
|
+
return new ResponseQueryActiveSession({
|
|
85
|
+
query: this,
|
|
86
|
+
json
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/*
|
|
2
|
+
(
|
|
3
|
+
(/(
|
|
4
|
+
(//(
|
|
5
|
+
(///(
|
|
6
|
+
(/////(
|
|
7
|
+
(//////( )
|
|
8
|
+
(////////( (/)
|
|
9
|
+
(////////( (///)
|
|
10
|
+
(//////////( (////)
|
|
11
|
+
(//////////( (//////)
|
|
12
|
+
(////////////( (///////)
|
|
13
|
+
(/////////////( (/////////)
|
|
14
|
+
(//////////////( (///////////)
|
|
15
|
+
(///////////////( (/////////////)
|
|
16
|
+
(////////////////( (//////////////)
|
|
17
|
+
((((((((((((((((((( (((((((((((((((
|
|
18
|
+
((((((((((((((((((( ((((((((((((((
|
|
19
|
+
((((((((((((((((((( ((((((((((((((
|
|
20
|
+
(((((((((((((((((((( (((((((((((((
|
|
21
|
+
(((((((((((((((((((( ((((((((((((
|
|
22
|
+
((((((((((((((((((( ((((((((((((
|
|
23
|
+
((((((((((((((((((( ((((((((((
|
|
24
|
+
((((((((((((((((((/ (((((((((
|
|
25
|
+
(((((((((((((((((( ((((((((
|
|
26
|
+
((((((((((((((((( (((((((
|
|
27
|
+
(((((((((((((((((( (((((
|
|
28
|
+
################# ##
|
|
29
|
+
################ #
|
|
30
|
+
################# ##
|
|
31
|
+
%################ ###
|
|
32
|
+
###############( ####
|
|
33
|
+
############### ####
|
|
34
|
+
############### ######
|
|
35
|
+
%#############( (#######
|
|
36
|
+
%############# #########
|
|
37
|
+
############( ##########
|
|
38
|
+
########### #############
|
|
39
|
+
######### ##############
|
|
40
|
+
%######
|
|
41
|
+
|
|
42
|
+
Powered by Knish.IO: Connecting a Decentralized World
|
|
43
|
+
|
|
44
|
+
Please visit https://github.com/WishKnish/KnishIO-Client-TS for information.
|
|
45
|
+
|
|
46
|
+
License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
import Query from './Query'
|
|
50
|
+
import ResponseAtom from '../response/ResponseAtom'
|
|
51
|
+
import type { UrqlClientWrapper } from '../client/GraphQLClient'
|
|
52
|
+
import type KnishIOClient from '../KnishIOClient'
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* QueryAtom class - Query for getting Knish.IO Atoms
|
|
56
|
+
* Matches JavaScript SDK QueryAtom implementation exactly
|
|
57
|
+
*/
|
|
58
|
+
export default class QueryAtom extends Query {
|
|
59
|
+
/**
|
|
60
|
+
* Create new QueryAtom instance
|
|
61
|
+
* Matches JavaScript SDK constructor signature exactly
|
|
62
|
+
*/
|
|
63
|
+
constructor(graphQLClient: UrqlClientWrapper, knishIOClient: KnishIOClient) {
|
|
64
|
+
super(graphQLClient, knishIOClient)
|
|
65
|
+
|
|
66
|
+
this.$__query = `query(
|
|
67
|
+
$molecularHashes: [String!],
|
|
68
|
+
$bundleHashes: [String!],
|
|
69
|
+
$positions:[String!],
|
|
70
|
+
$walletAddresses: [String!],
|
|
71
|
+
$isotopes: [String!],
|
|
72
|
+
$tokenSlugs: [String!],
|
|
73
|
+
$cellSlugs: [String!],
|
|
74
|
+
$batchIds: [String!],
|
|
75
|
+
$values: [String!],
|
|
76
|
+
$metaTypes: [String!],
|
|
77
|
+
$metaIds: [String!],
|
|
78
|
+
$indexes: [String!],
|
|
79
|
+
$filter: [ MetaFilter! ],
|
|
80
|
+
$latest: Boolean,
|
|
81
|
+
$queryArgs: QueryArgs,
|
|
82
|
+
) {
|
|
83
|
+
Atom(
|
|
84
|
+
molecularHashes: $molecularHashes,
|
|
85
|
+
bundleHashes: $bundleHashes,
|
|
86
|
+
positions: $positions,
|
|
87
|
+
walletAddresses: $walletAddresses,
|
|
88
|
+
isotopes: $isotopes,
|
|
89
|
+
tokenSlugs: $tokenSlugs,
|
|
90
|
+
cellSlugs: $cellSlugs,
|
|
91
|
+
batchIds: $batchIds,
|
|
92
|
+
values: $values,
|
|
93
|
+
metaTypes: $metaTypes,
|
|
94
|
+
metaIds: $metaIds,
|
|
95
|
+
indexes: $indexes,
|
|
96
|
+
filter: $filter,
|
|
97
|
+
latest: $latest,
|
|
98
|
+
queryArgs: $queryArgs,
|
|
99
|
+
) {
|
|
100
|
+
instances {
|
|
101
|
+
position,
|
|
102
|
+
walletAddress,
|
|
103
|
+
tokenSlug,
|
|
104
|
+
isotope,
|
|
105
|
+
index,
|
|
106
|
+
molecularHash,
|
|
107
|
+
metaId,
|
|
108
|
+
metaType,
|
|
109
|
+
metasJson,
|
|
110
|
+
batchId,
|
|
111
|
+
value,
|
|
112
|
+
bundleHashes,
|
|
113
|
+
cellSlugs,
|
|
114
|
+
createdAt,
|
|
115
|
+
otsFragment
|
|
116
|
+
},
|
|
117
|
+
paginatorInfo {
|
|
118
|
+
currentPage,
|
|
119
|
+
total
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}`
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Queries Knish.IO Atoms
|
|
127
|
+
* Matches JavaScript SDK createVariables method exactly
|
|
128
|
+
*/
|
|
129
|
+
static createVariables({
|
|
130
|
+
molecularHashes,
|
|
131
|
+
molecularHash,
|
|
132
|
+
bundleHashes,
|
|
133
|
+
bundleHash,
|
|
134
|
+
positions,
|
|
135
|
+
position,
|
|
136
|
+
walletAddresses,
|
|
137
|
+
walletAddress,
|
|
138
|
+
isotopes,
|
|
139
|
+
isotope,
|
|
140
|
+
tokenSlugs,
|
|
141
|
+
tokenSlug,
|
|
142
|
+
cellSlugs,
|
|
143
|
+
cellSlug,
|
|
144
|
+
batchIds,
|
|
145
|
+
batchId,
|
|
146
|
+
values,
|
|
147
|
+
value,
|
|
148
|
+
metaTypes,
|
|
149
|
+
metaType,
|
|
150
|
+
metaIds,
|
|
151
|
+
metaId,
|
|
152
|
+
indexes,
|
|
153
|
+
index,
|
|
154
|
+
filter,
|
|
155
|
+
latest,
|
|
156
|
+
queryArgs
|
|
157
|
+
}: {
|
|
158
|
+
molecularHashes?: string[]
|
|
159
|
+
molecularHash?: string
|
|
160
|
+
bundleHashes?: string[]
|
|
161
|
+
bundleHash?: string
|
|
162
|
+
positions?: string[]
|
|
163
|
+
position?: string
|
|
164
|
+
walletAddresses?: string[]
|
|
165
|
+
walletAddress?: string
|
|
166
|
+
isotopes?: string[]
|
|
167
|
+
isotope?: string
|
|
168
|
+
tokenSlugs?: string[]
|
|
169
|
+
tokenSlug?: string
|
|
170
|
+
cellSlugs?: string[]
|
|
171
|
+
cellSlug?: string
|
|
172
|
+
batchIds?: string[]
|
|
173
|
+
batchId?: string
|
|
174
|
+
values?: string[]
|
|
175
|
+
value?: string | number
|
|
176
|
+
metaTypes?: string[]
|
|
177
|
+
metaType?: string
|
|
178
|
+
metaIds?: string[]
|
|
179
|
+
metaId?: string
|
|
180
|
+
indexes?: number[]
|
|
181
|
+
index?: number
|
|
182
|
+
filter?: object[]
|
|
183
|
+
latest?: boolean
|
|
184
|
+
queryArgs?: object
|
|
185
|
+
}): Record<string, any> {
|
|
186
|
+
if (molecularHash) {
|
|
187
|
+
molecularHashes = molecularHashes || []
|
|
188
|
+
molecularHashes.push(molecularHash)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (bundleHash) {
|
|
192
|
+
bundleHashes = bundleHashes || []
|
|
193
|
+
bundleHashes.push(bundleHash)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (position) {
|
|
197
|
+
positions = positions || []
|
|
198
|
+
positions.push(position)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (walletAddress) {
|
|
202
|
+
walletAddresses = walletAddresses || []
|
|
203
|
+
walletAddresses.push(walletAddress)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (isotope) {
|
|
207
|
+
isotopes = isotopes || []
|
|
208
|
+
isotopes.push(isotope)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (tokenSlug) {
|
|
212
|
+
tokenSlugs = tokenSlugs || []
|
|
213
|
+
tokenSlugs.push(tokenSlug)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (cellSlug) {
|
|
217
|
+
cellSlugs = cellSlugs || []
|
|
218
|
+
cellSlugs.push(cellSlug)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (batchId) {
|
|
222
|
+
batchIds = batchIds || []
|
|
223
|
+
batchIds.push(batchId)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (value) {
|
|
227
|
+
values = values || []
|
|
228
|
+
values.push(String(value))
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (metaType) {
|
|
232
|
+
metaTypes = metaTypes || []
|
|
233
|
+
metaTypes.push(metaType)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (metaId) {
|
|
237
|
+
metaIds = metaIds || []
|
|
238
|
+
metaIds.push(metaId)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (index) {
|
|
242
|
+
indexes = indexes || []
|
|
243
|
+
indexes.push(index)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return {
|
|
247
|
+
molecularHashes,
|
|
248
|
+
bundleHashes,
|
|
249
|
+
positions,
|
|
250
|
+
walletAddresses,
|
|
251
|
+
isotopes,
|
|
252
|
+
tokenSlugs,
|
|
253
|
+
cellSlugs,
|
|
254
|
+
batchIds,
|
|
255
|
+
values,
|
|
256
|
+
metaTypes,
|
|
257
|
+
metaIds,
|
|
258
|
+
indexes,
|
|
259
|
+
filter,
|
|
260
|
+
latest,
|
|
261
|
+
queryArgs
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Returns a Response object
|
|
267
|
+
* Matches JavaScript SDK createResponse method exactly
|
|
268
|
+
*/
|
|
269
|
+
override createResponse(json: any): ResponseAtom {
|
|
270
|
+
return new ResponseAtom({
|
|
271
|
+
query: this,
|
|
272
|
+
json
|
|
273
|
+
})
|
|
274
|
+
}
|
|
275
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/*
|
|
2
|
+
(
|
|
3
|
+
(/(
|
|
4
|
+
(//(
|
|
5
|
+
(///(
|
|
6
|
+
(/////(
|
|
7
|
+
(//////( )
|
|
8
|
+
(////////( (/)
|
|
9
|
+
(////////( (///)
|
|
10
|
+
(//////////( (////)
|
|
11
|
+
(//////////( (//////)
|
|
12
|
+
(////////////( (///////)
|
|
13
|
+
(/////////////( (/////////)
|
|
14
|
+
(//////////////( (///////////)
|
|
15
|
+
(///////////////( (/////////////)
|
|
16
|
+
(////////////////( (//////////////)
|
|
17
|
+
((((((((((((((((((( (((((((((((((((
|
|
18
|
+
((((((((((((((((((( ((((((((((((((
|
|
19
|
+
((((((((((((((((((( ((((((((((((((
|
|
20
|
+
(((((((((((((((((((( (((((((((((((
|
|
21
|
+
(((((((((((((((((((( ((((((((((((
|
|
22
|
+
((((((((((((((((((( ((((((((((((
|
|
23
|
+
((((((((((((((((((( ((((((((((
|
|
24
|
+
((((((((((((((((((/ (((((((((
|
|
25
|
+
(((((((((((((((((( ((((((((
|
|
26
|
+
((((((((((((((((( (((((((
|
|
27
|
+
(((((((((((((((((( (((((
|
|
28
|
+
################# ##
|
|
29
|
+
################ #
|
|
30
|
+
################# ##
|
|
31
|
+
%################ ###
|
|
32
|
+
###############( ####
|
|
33
|
+
############### ####
|
|
34
|
+
############### ######
|
|
35
|
+
%#############( (#######
|
|
36
|
+
%############# #########
|
|
37
|
+
############( ##########
|
|
38
|
+
########### #############
|
|
39
|
+
######### ##############
|
|
40
|
+
%######
|
|
41
|
+
|
|
42
|
+
Powered by Knish.IO: Connecting a Decentralized World
|
|
43
|
+
|
|
44
|
+
Please visit https://github.com/WishKnish/KnishIO-Client-TS for information.
|
|
45
|
+
|
|
46
|
+
License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
import Query from './Query'
|
|
50
|
+
import ResponseBalance from '../response/ResponseBalance'
|
|
51
|
+
import type GraphQLClient from '../libraries/GraphQLClient'
|
|
52
|
+
import type KnishIOClient from '../KnishIOClient'
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Query for getting the balance of a given wallet or token slug
|
|
56
|
+
* Matches JavaScript SDK QueryBalance implementation exactly
|
|
57
|
+
*/
|
|
58
|
+
export default class QueryBalance extends Query {
|
|
59
|
+
/**
|
|
60
|
+
* Create QueryBalance instance
|
|
61
|
+
*/
|
|
62
|
+
constructor(graphQLClient: GraphQLClient, knishIOClient: KnishIOClient) {
|
|
63
|
+
super(graphQLClient, knishIOClient)
|
|
64
|
+
|
|
65
|
+
this.$__query = `
|
|
66
|
+
query($address: String, $bundleHash: String, $type: String, $token: String, $position: String) {
|
|
67
|
+
Balance(address: $address, bundleHash: $bundleHash, type: $type, token: $token, position: $position) {
|
|
68
|
+
address,
|
|
69
|
+
bundleHash,
|
|
70
|
+
type,
|
|
71
|
+
tokenSlug,
|
|
72
|
+
batchId,
|
|
73
|
+
position,
|
|
74
|
+
amount,
|
|
75
|
+
characters,
|
|
76
|
+
pubkey,
|
|
77
|
+
createdAt,
|
|
78
|
+
tokenUnits {
|
|
79
|
+
id,
|
|
80
|
+
name,
|
|
81
|
+
metas
|
|
82
|
+
},
|
|
83
|
+
tradeRates {
|
|
84
|
+
tokenSlug,
|
|
85
|
+
amount
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
`
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Create ResponseBalance instance from JSON data
|
|
94
|
+
* Matches JavaScript SDK createResponse method signature exactly
|
|
95
|
+
*/
|
|
96
|
+
override createResponse(json: Record<string, unknown>): ResponseBalance {
|
|
97
|
+
return new ResponseBalance({
|
|
98
|
+
query: this,
|
|
99
|
+
json
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
}
|