@wishknish/knishio-client-ts 0.7.0 → 0.7.2

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.
Files changed (47) hide show
  1. package/dist/index.cjs +235 -194
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +1833 -0
  4. package/dist/index.d.ts +1833 -0
  5. package/dist/index.iife.js +238 -181
  6. package/dist/index.iife.js.map +1 -1
  7. package/dist/index.js +235 -194
  8. package/dist/index.js.map +1 -1
  9. package/package.json +13 -10
  10. package/src/KnishIOClient.ts +183 -231
  11. package/src/core/Atom.ts +1 -1
  12. package/src/core/Molecule.ts +0 -1
  13. package/src/core/Wallet.ts +71 -8
  14. package/src/libraries/CheckMolecule.ts +3 -3
  15. package/src/libraries/GraphQLClient.ts +61 -23
  16. package/src/libraries/array.ts +2 -2
  17. package/src/libraries/crypto.ts +28 -25
  18. package/src/libraries/strings.ts +3 -3
  19. package/src/mutation/MutationProposeMolecule.ts +2 -1
  20. package/src/query/Query.ts +2 -1
  21. package/src/query/QueryAtom.ts +4 -3
  22. package/src/query/QueryBalance.ts +2 -1
  23. package/src/query/QueryBatch.ts +4 -3
  24. package/src/query/QueryContinuId.ts +4 -3
  25. package/src/query/QueryMetaType.ts +4 -3
  26. package/src/query/QueryMetaTypeViaAtom.ts +4 -3
  27. package/src/query/QueryWalletBundle.ts +2 -1
  28. package/src/query/QueryWalletList.ts +4 -3
  29. package/src/response/EnhancedResponse.ts +19 -24
  30. package/src/response/Response.ts +3 -3
  31. package/src/response/ResponseAtom.ts +1 -1
  32. package/src/response/ResponseAuthorizationGuest.ts +1 -1
  33. package/src/response/ResponseBalance.ts +1 -1
  34. package/src/response/ResponseContinuId.ts +1 -1
  35. package/src/response/ResponseMetaType.ts +1 -1
  36. package/src/response/ResponseMetaTypeViaAtom.ts +1 -1
  37. package/src/response/ResponsePolicy.ts +1 -1
  38. package/src/response/ResponseProposeMolecule.ts +4 -5
  39. package/src/response/ResponseQueryActiveSession.ts +1 -1
  40. package/src/response/ResponseQueryUserActivity.ts +1 -1
  41. package/src/response/ResponseRequestAuthorizationGuest.ts +1 -1
  42. package/src/response/ResponseTransferTokens.ts +1 -1
  43. package/src/response/ResponseWalletBundle.ts +1 -1
  44. package/src/response/ResponseWalletList.ts +1 -1
  45. package/src/types/graphql.ts +8 -0
  46. package/src/types/index.ts +2 -7
  47. package/src/types/response.ts +12 -7
package/src/core/Atom.ts CHANGED
@@ -54,7 +54,7 @@ License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
54
54
  * while ensuring perfect compatibility with other SDK implementations.
55
55
  */
56
56
 
57
- import { shake256, convertToBase17 } from '@/libraries/crypto'
57
+ import { convertToBase17 } from '@/libraries/crypto'
58
58
  import JsSHA from 'jssha'
59
59
  import { PROTOCOL_CONFIG } from '@/constants'
60
60
  import { handleIsotope, isWalletAddress, isPosition } from '@/types/guards'
@@ -52,7 +52,6 @@ import Wallet from './Wallet'
52
52
  import CheckMolecule from '@/libraries/CheckMolecule'
53
53
  import { chunkSubstr, hexToBase64 } from '@/libraries/strings'
54
54
  import { generateBundleHash, generateOTSSignature } from '@/libraries/crypto'
55
- import { deepCloning } from '@/libraries/array'
56
55
  import {
57
56
  AtomsMissingException,
58
57
  BalanceInsufficientException,
@@ -48,7 +48,7 @@ License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
48
48
 
49
49
  import JsSHA from 'jssha'
50
50
  import { randomString, chunkSubstr } from '@/libraries/strings'
51
- import { generateBundleHash, generateSecret, shake256 } from '@/libraries/crypto'
51
+ import { generateBundleHash, generateSecret, shake256, generateBatchId } from '@/libraries/crypto'
52
52
  import WalletCredentialException from '@/exception/WalletCredentialException'
53
53
  import { isWalletAddress, isBundleHash, isPosition } from '@/types'
54
54
  // Post-quantum cryptography for ML-KEM768 key encapsulation
@@ -73,6 +73,13 @@ export default class Wallet {
73
73
  public tradeRates: Record<string, any>
74
74
  public molecules: Record<string, any>
75
75
 
76
+ // Token metadata (populated from query responses)
77
+ public tokenName?: string
78
+ public tokenAmount?: string
79
+ public tokenSupply?: string
80
+ public tokenFungibility?: string
81
+ public createdAt?: string
82
+
76
83
  constructor({
77
84
  secret = null,
78
85
  bundle = null,
@@ -291,6 +298,62 @@ export default class Wallet {
291
298
  })
292
299
  }
293
300
 
301
+ /**
302
+ * Sets up a batch ID - either using the sender's, or a new one
303
+ * Matches JavaScript SDK Wallet.initBatchId exactly
304
+ */
305
+ initBatchId({
306
+ sourceWallet,
307
+ isRemainder = false
308
+ }: {
309
+ sourceWallet: Wallet
310
+ isRemainder?: boolean
311
+ }): void {
312
+ if (sourceWallet.batchId) {
313
+ this.batchId = isRemainder ? sourceWallet.batchId : generateBatchId({})
314
+ }
315
+ }
316
+
317
+ /**
318
+ * Split token units between wallets
319
+ * Matches JavaScript SDK Wallet.splitUnits exactly
320
+ *
321
+ * @param units - Array of token unit IDs to transfer
322
+ * @param remainderWallet - Wallet to receive units not being transferred
323
+ * @param recipientWallet - Wallet to receive the transferred units (optional)
324
+ */
325
+ splitUnits(
326
+ units: string[],
327
+ remainderWallet: Wallet,
328
+ recipientWallet: Wallet | null = null
329
+ ): void {
330
+ // No units supplied, nothing to split
331
+ if (units.length === 0) {
332
+ return
333
+ }
334
+
335
+ // Init recipient & remainder token units
336
+ const recipientTokenUnits: any[] = []
337
+ const remainderTokenUnits: any[] = []
338
+
339
+ this.tokenUnits.forEach(tokenUnit => {
340
+ if (units.includes(tokenUnit.id)) {
341
+ recipientTokenUnits.push(tokenUnit)
342
+ } else {
343
+ remainderTokenUnits.push(tokenUnit)
344
+ }
345
+ })
346
+
347
+ // Reset token units to the sending value
348
+ this.tokenUnits = recipientTokenUnits
349
+
350
+ // Set token units to recipient & remainder
351
+ if (recipientWallet !== null) {
352
+ recipientWallet.tokenUnits = recipientTokenUnits
353
+ }
354
+ remainderWallet.tokenUnits = remainderTokenUnits
355
+ }
356
+
294
357
  /**
295
358
  * Get token units data
296
359
  * Stub for compatibility
@@ -319,9 +382,9 @@ export default class Wallet {
319
382
  * Initializes the ML-KEM key pair (matches JavaScript SDK exactly)
320
383
  */
321
384
  initializeMLKEM(): void {
322
- // Generate a 64-byte (512-bit) seed from the Knish.IO private key
323
- // Use deterministic approach: generateSecret(key, 128) → 128 hex chars = 64 bytes
324
- const seedHex = generateSecret(this.key!, 128) // 128 hex chars = 64 bytes
385
+ // Generate a 64-byte (512-bit) seed from the Knish.IO private key
386
+ // Use deterministic approach: generateSecret(key, 64) → matches JS SDK exactly
387
+ const seedHex = generateSecret(this.key!, 64) // Matches JS SDK for cross-platform compatibility
325
388
 
326
389
  // Convert the hex string to a Uint8Array
327
390
  const seed = new Uint8Array(64)
@@ -408,7 +471,7 @@ export default class Wallet {
408
471
  // Import shared secret as CryptoKey
409
472
  const key = await crypto.subtle.importKey(
410
473
  'raw',
411
- sharedSecret,
474
+ sharedSecret as BufferSource,
412
475
  { name: 'AES-GCM' },
413
476
  false,
414
477
  ['encrypt']
@@ -418,7 +481,7 @@ export default class Wallet {
418
481
  const encryptedContent = await crypto.subtle.encrypt(
419
482
  { name: 'AES-GCM', iv },
420
483
  key,
421
- message
484
+ message as BufferSource
422
485
  )
423
486
 
424
487
  // Combine IV and encrypted content
@@ -440,7 +503,7 @@ export default class Wallet {
440
503
  // Import shared secret as CryptoKey
441
504
  const key = await crypto.subtle.importKey(
442
505
  'raw',
443
- sharedSecret,
506
+ sharedSecret as BufferSource,
444
507
  { name: 'AES-GCM' },
445
508
  false,
446
509
  ['decrypt']
@@ -450,7 +513,7 @@ export default class Wallet {
450
513
  const decryptedContent = await crypto.subtle.decrypt(
451
514
  { name: 'AES-GCM', iv },
452
515
  key,
453
- ciphertext
516
+ ciphertext as BufferSource
454
517
  )
455
518
 
456
519
  return new Uint8Array(decryptedContent)
@@ -248,10 +248,10 @@ export default class CheckMolecule {
248
248
  const metas = Meta.aggregateMeta(atom.meta)
249
249
 
250
250
  for (const key of policyArray) {
251
- let policy = metas[key]
251
+ const policyRaw = metas[key]
252
252
 
253
- if (policy) {
254
- policy = JSON.parse(policy as string) as Record<string, any>
253
+ if (policyRaw) {
254
+ const policy = JSON.parse(policyRaw as string) as Record<string, any>
255
255
 
256
256
  for (const [policyName, policyValue] of Object.entries(policy)) {
257
257
  if (!policyArray.includes(policyName)) {
@@ -55,7 +55,12 @@ import {
55
55
  } from '@urql/core'
56
56
  import { createClient as createWSClient } from 'graphql-ws'
57
57
  import { pipe, subscribe } from 'wonka'
58
- import type { GraphQLClient as IGraphQLClient } from '@/types'
58
+ import type {
59
+ GraphQLClient as IGraphQLClient,
60
+ GraphQLRequest,
61
+ GraphQLResponse,
62
+ GraphQLVariables
63
+ } from '@/types'
59
64
  import type Wallet from '@/core/Wallet'
60
65
 
61
66
  /**
@@ -89,8 +94,7 @@ export default class GraphQLClient implements IGraphQLClient {
89
94
 
90
95
  private createUrqlClient({
91
96
  serverUri,
92
- socket,
93
- encrypt
97
+ socket
94
98
  }: {
95
99
  serverUri: string
96
100
  socket?: { socketUri: string | null } | null
@@ -111,7 +115,7 @@ export default class GraphQLClient implements IGraphQLClient {
111
115
  subscriptionExchange({
112
116
  forwardSubscription: (operation) => ({
113
117
  subscribe: (sink) => {
114
- const disposable = wsClient.subscribe(operation, sink)
118
+ const disposable = wsClient.subscribe(operation as any, sink as any)
115
119
  return { unsubscribe: disposable }
116
120
  }
117
121
  })
@@ -153,29 +157,63 @@ export default class GraphQLClient implements IGraphQLClient {
153
157
  })
154
158
  }
155
159
 
156
- async query<TResult = unknown, TVariables = Record<string, any>>(
157
- request: { query: string; variables?: TVariables },
160
+ async query<TResult = unknown, TVariables = GraphQLVariables>(
161
+ request: GraphQLRequest,
158
162
  variables?: TVariables
159
- ): Promise<any> {
160
- const finalVariables = variables || request.variables || {}
163
+ ): Promise<GraphQLResponse<TResult>> {
164
+ const finalVariables = (variables || request.variables || {}) as Record<string, any>
161
165
  const result = await this.$__client.query(request.query, finalVariables).toPromise()
162
- return this.formatResponse(result)
166
+ return this.formatResponse<TResult>(result)
163
167
  }
164
168
 
165
- async mutate<TResult = unknown, TVariables = Record<string, any>>(
166
- request: { mutation: string; variables?: TVariables },
169
+ async mutation<TResult = unknown, TVariables = GraphQLVariables>(
170
+ request: GraphQLRequest,
167
171
  variables?: TVariables
168
- ): Promise<any> {
169
- const finalVariables = variables || request.variables || {}
170
- const result = await this.$__client.mutation(request.mutation, finalVariables).toPromise()
171
- return this.formatResponse(result)
172
+ ): Promise<GraphQLResponse<TResult>> {
173
+ const finalVariables = (variables || request.variables || {}) as Record<string, any>
174
+ // Support both query and mutation properties for backward compatibility
175
+ const mutationString = (request as any).mutation || request.query
176
+ const result = await this.$__client.mutation(mutationString, finalVariables).toPromise()
177
+ return this.formatResponse<TResult>(result)
172
178
  }
173
179
 
174
- async mutation<TResult = unknown, TVariables = Record<string, any>>(
175
- request: { mutation: string; variables?: TVariables },
180
+ // Alias for mutation() to match JS SDK interface
181
+ async mutate<TResult = unknown, TVariables = GraphQLVariables>(
182
+ request: GraphQLRequest,
176
183
  variables?: TVariables
177
- ): Promise<any> {
178
- return this.mutate(request, variables)
184
+ ): Promise<GraphQLResponse<TResult>> {
185
+ return this.mutation<TResult, TVariables>(request, variables)
186
+ }
187
+
188
+ async *subscription<TResult = unknown, TVariables = GraphQLVariables>(
189
+ request: GraphQLRequest,
190
+ variables?: TVariables
191
+ ): AsyncIterableIterator<GraphQLResponse<TResult>> {
192
+ const finalVariables = (variables || request.variables || {}) as Record<string, any>
193
+
194
+ // Create subscription stream
195
+ const subscription = this.$__client.subscription(request.query, finalVariables)
196
+
197
+ // Convert wonka stream to async iterator
198
+ const results: GraphQLResponse<TResult>[] = []
199
+ const { unsubscribe } = pipe(
200
+ subscription,
201
+ subscribe((result) => {
202
+ results.push(this.formatResponse<TResult>(result))
203
+ })
204
+ )
205
+
206
+ try {
207
+ while (true) {
208
+ if (results.length > 0) {
209
+ yield results.shift()!
210
+ }
211
+ // Small delay to prevent busy waiting
212
+ await new Promise(resolve => setTimeout(resolve, 10))
213
+ }
214
+ } finally {
215
+ unsubscribe()
216
+ }
179
217
  }
180
218
 
181
219
  subscribe(
@@ -203,12 +241,12 @@ export default class GraphQLClient implements IGraphQLClient {
203
241
  }
204
242
  }
205
243
 
206
- private formatResponse(result: any): any {
207
- // Match old Apollo response format
244
+ private formatResponse<T>(result: any): GraphQLResponse<T> {
245
+ // Match JS SDK (UrqlClientWrapper) response format exactly
208
246
  return {
209
247
  data: result.data,
210
248
  errors: result.error ? [result.error] : undefined
211
- }
249
+ } as GraphQLResponse<T>
212
250
  }
213
251
 
214
252
  unsubscribe(operationName: string): void {
@@ -220,7 +258,7 @@ export default class GraphQLClient implements IGraphQLClient {
220
258
  }
221
259
 
222
260
  unsubscribeAll(): void {
223
- this.$__subscriptionManager.forEach((subscription, operationName) => {
261
+ this.$__subscriptionManager.forEach((_subscription, operationName) => {
224
262
  this.unsubscribe(operationName)
225
263
  })
226
264
  }
@@ -72,7 +72,7 @@ export function diff<T>(...arrays: T[][]): T[] {
72
72
  return [].concat(...arrays.map((arr, i) => {
73
73
  const others = arrays.slice(0)
74
74
  others.splice(i, 1)
75
- const unique = [...new Set([].concat(...others as any))]
75
+ const unique: T[] = [...new Set([].concat(...others as any))] as T[]
76
76
  return arr.filter(item => !unique.includes(item))
77
77
  }) as any)
78
78
  }
@@ -83,7 +83,7 @@ export function diff<T>(...arrays: T[][]): T[] {
83
83
  */
84
84
  export function intersect<T>(...arrays: T[][]): T[] {
85
85
  if (arrays.length === 0) return []
86
- if (arrays.length === 1) return arrays[0]
86
+ if (arrays.length === 1) return arrays[0]!
87
87
 
88
88
  return arrays.reduce((first, second) =>
89
89
  first.filter(item => second.includes(item))
@@ -110,9 +110,11 @@ export function shake256(input: string, outputLength: number): string {
110
110
  */
111
111
  export function shake256Enhanced(options: SHAKE256Options): string {
112
112
  const { input, outputLength, encoding = 'hex' } = options
113
-
114
- const sponge = new JsSHA('SHAKE256', typeof input === 'string' ? 'TEXT' : 'UINT8ARRAY')
115
- sponge.update(input)
113
+
114
+ // Always treat input as string for SHAKE256
115
+ const inputStr = typeof input === 'string' ? input : Array.from(input).map(b => String.fromCharCode(b)).join('')
116
+ const sponge = new JsSHA('SHAKE256', 'TEXT')
117
+ sponge.update(inputStr)
116
118
 
117
119
  // outputLength is in BITS consistently across all encodings
118
120
  switch (encoding) {
@@ -136,7 +138,7 @@ export function shake256Enhanced(options: SHAKE256Options): string {
136
138
  * If seed provided: uses SHAKE256 to generate deterministic secret
137
139
  * If no seed: uses cryptographically secure random string
138
140
  */
139
- export function generateSecret(seed: string | null = null, length = CRYPTO_CONSTANTS.SECRET_LENGTH): string {
141
+ export function generateSecret(seed: string | null = null, length: number = CRYPTO_CONSTANTS.SECRET_LENGTH): string {
140
142
  if (seed) {
141
143
  // Deterministic generation using SHAKE256 - MUST match JS SDK
142
144
  const sponge = new JsSHA('SHAKE256', 'TEXT')
@@ -221,10 +223,10 @@ export function generatePosition(): Position {
221
223
  * Enhanced position generation with options
222
224
  */
223
225
  export function generatePositionEnhanced(options: PositionGenerationOptions = {}): Position {
224
- const {
226
+ const {
225
227
  entropy = null,
226
- algorithm = 'SHAKE256',
227
- length = CRYPTO_CONSTANTS.POSITION_LENGTH
228
+ algorithm: _algorithm = 'SHAKE256',
229
+ length = CRYPTO_CONSTANTS.POSITION_LENGTH
228
230
  } = options
229
231
 
230
232
  if (entropy) {
@@ -499,21 +501,21 @@ export function charsetBaseConvert(
499
501
  fromCharset: string,
500
502
  toCharset: string
501
503
  ): string {
502
- if (input === '') return toCharset[0]
503
-
504
+ if (input === '') return toCharset[0]!
505
+
504
506
  // Convert input from source base to decimal using BigInt for precision
505
507
  let decimal = 0n
506
508
  for (let i = 0; i < input.length; i++) {
507
- const char = input[i]
509
+ const char = input[i]!
508
510
  const value = BigInt(fromCharset.indexOf(char))
509
511
  if (value === -1n) {
510
512
  throw new Error(`Invalid character '${char}' for source base ${fromBase}`)
511
513
  }
512
514
  decimal = decimal * BigInt(fromBase) + value
513
515
  }
514
-
516
+
515
517
  // Convert decimal to target base
516
- if (decimal === 0n) return toCharset[0]
518
+ if (decimal === 0n) return toCharset[0]!
517
519
 
518
520
  let result = ''
519
521
  while (decimal > 0n) {
@@ -557,9 +559,9 @@ export function enumerateMolecularHash(hash: string): number[] {
557
559
  const hashList = hash.toLowerCase().split('')
558
560
 
559
561
  for (let index = 0; index < hashList.length; index++) {
560
- const symbol = hashList[index]
562
+ const symbol = hashList[index]!
561
563
  if (typeof mapped[symbol] !== 'undefined') {
562
- target[index] = mapped[symbol]
564
+ target[index] = mapped[symbol]!
563
565
  } else {
564
566
  throw new Error(`Invalid character '${symbol}' in molecular hash`)
565
567
  }
@@ -581,19 +583,20 @@ export function normalizeMolecularHash(mappedHashArray: number[]): number[] {
581
583
 
582
584
  while (total !== 0) {
583
585
  for (let index = 0; index < normalized.length; index++) {
584
- const condition = totalCondition
585
- ? normalized[index] < 8
586
- : normalized[index] > -8
587
-
586
+ const value = normalized[index]!
587
+ const condition = totalCondition
588
+ ? value < 8
589
+ : value > -8
590
+
588
591
  if (condition) {
589
592
  if (totalCondition) {
590
- normalized[index]++
593
+ normalized[index] = value + 1
591
594
  total++
592
595
  } else {
593
- normalized[index]--
596
+ normalized[index] = value - 1
594
597
  total--
595
598
  }
596
-
599
+
597
600
  if (total === 0) break
598
601
  }
599
602
  }
@@ -634,8 +637,8 @@ export function generateOTSSignature(privateKey: string, molecularHash: string):
634
637
  // Step 3: Generate signature fragments
635
638
  let signatureFragments = ''
636
639
  for (let index = 0; index < keyChunks.length; index++) {
637
- let workingChunk = keyChunks[index]
638
-
640
+ let workingChunk = keyChunks[index]!
641
+
639
642
  // Hash (8 - normalized[index]) times for signature generation
640
643
  const iterations = 8 - (normalized[index] || 0)
641
644
  for (let j = 0; j < iterations; j++) {
@@ -689,8 +692,8 @@ export function verifyOTSSignature(
689
692
  // Step 4: Process each chunk for verification
690
693
  let keyFragments = ''
691
694
  for (let index = 0; index < otsChunks.length; index++) {
692
- let workingChunk = otsChunks[index]
693
-
695
+ let workingChunk = otsChunks[index]!
696
+
694
697
  // Hash (8 + normalized[index]) times for verification
695
698
  const iterations = 8 + (normalized[index] || 0)
696
699
  for (let j = 0; j < iterations; j++) {
@@ -88,9 +88,9 @@ export function randomString(
88
88
  if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
89
89
  const randomValues = new Uint8Array(length)
90
90
  crypto.getRandomValues(randomValues)
91
-
91
+
92
92
  for (let i = 0; i < length; i++) {
93
- result += alphabet.charAt(randomValues[i] % alphabet.length)
93
+ result += alphabet.charAt(randomValues[i]! % alphabet.length)
94
94
  }
95
95
  } else {
96
96
  // Fallback to Math.random (less secure but compatible)
@@ -310,7 +310,7 @@ export function toCamelCase(str: string): string {
310
310
 
311
311
  return str
312
312
  .toLowerCase()
313
- .replace(/[^a-zA-Z0-9]+(.)/g, (match, chr) => chr.toUpperCase())
313
+ .replace(/[^a-zA-Z0-9]+(.)/g, (_match, chr) => chr.toUpperCase())
314
314
  }
315
315
 
316
316
  /**
@@ -48,6 +48,7 @@ License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
48
48
 
49
49
  import Mutation from './Mutation'
50
50
  import ResponseProposeMolecule from '../response/ResponseProposeMolecule'
51
+ import { gql } from '@urql/core'
51
52
  import type GraphQLClient from '../libraries/GraphQLClient'
52
53
  import type KnishIOClient from '../KnishIOClient'
53
54
  import type Molecule from '../core/Molecule'
@@ -68,7 +69,7 @@ export default abstract class MutationProposeMolecule extends Mutation {
68
69
 
69
70
  this.$__molecule = molecule
70
71
  this.$__remainderWallet = null
71
- this.$__query = `
72
+ this.$__query = gql`
72
73
  mutation($molecule: MoleculeInput!) {
73
74
  ProposeMolecule(molecule: $molecule) {
74
75
  molecularHash,
@@ -49,6 +49,7 @@ License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
49
49
  import { CodeException } from '@/exception'
50
50
  import type Response from '@/response/Response'
51
51
  import type { GraphQLClient } from '@/types'
52
+ import type { TypedDocumentNode } from '@urql/core'
52
53
 
53
54
  /**
54
55
  * Base Query class for constructing GraphQL queries
@@ -57,7 +58,7 @@ export default class Query {
57
58
  protected client: GraphQLClient
58
59
  protected knishIOClient: any // Will be KnishIOClient type
59
60
  protected $__variables: Record<string, any> | null = null
60
- protected $__query: string | null = null
61
+ protected $__query: string | TypedDocumentNode<any, any> | null = null
61
62
  protected $__response: Response | null = null
62
63
  protected $__request: any = null
63
64
 
@@ -48,7 +48,8 @@ License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
48
48
 
49
49
  import Query from './Query'
50
50
  import ResponseAtom from '../response/ResponseAtom'
51
- import type { UrqlClientWrapper } from '../client/GraphQLClient'
51
+ import { gql } from '@urql/core'
52
+ import type { GraphQLClient } from '../types/graphql'
52
53
  import type KnishIOClient from '../KnishIOClient'
53
54
 
54
55
  /**
@@ -60,10 +61,10 @@ export default class QueryAtom extends Query {
60
61
  * Create new QueryAtom instance
61
62
  * Matches JavaScript SDK constructor signature exactly
62
63
  */
63
- constructor(graphQLClient: UrqlClientWrapper, knishIOClient: KnishIOClient) {
64
+ constructor(graphQLClient: GraphQLClient, knishIOClient: KnishIOClient) {
64
65
  super(graphQLClient, knishIOClient)
65
66
 
66
- this.$__query = `query(
67
+ this.$__query = gql`query(
67
68
  $molecularHashes: [String!],
68
69
  $bundleHashes: [String!],
69
70
  $positions:[String!],
@@ -48,6 +48,7 @@ License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
48
48
 
49
49
  import Query from './Query'
50
50
  import ResponseBalance from '../response/ResponseBalance'
51
+ import { gql } from '@urql/core'
51
52
  import type GraphQLClient from '../libraries/GraphQLClient'
52
53
  import type KnishIOClient from '../KnishIOClient'
53
54
 
@@ -62,7 +63,7 @@ export default class QueryBalance extends Query {
62
63
  constructor(graphQLClient: GraphQLClient, knishIOClient: KnishIOClient) {
63
64
  super(graphQLClient, knishIOClient)
64
65
 
65
- this.$__query = `
66
+ this.$__query = gql`
66
67
  query($address: String, $bundleHash: String, $type: String, $token: String, $position: String) {
67
68
  Balance(address: $address, bundleHash: $bundleHash, type: $type, token: $token, position: $position) {
68
69
  address,
@@ -48,7 +48,8 @@ License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
48
48
 
49
49
  import Query from './Query'
50
50
  import Response from '../response/Response'
51
- import type { UrqlClientWrapper } from '../client/GraphQLClient'
51
+ import { gql } from '@urql/core'
52
+ import type { GraphQLClient } from '../types/graphql'
52
53
  import type KnishIOClient from '../KnishIOClient'
53
54
 
54
55
  /**
@@ -60,10 +61,10 @@ export default class QueryBatch extends Query {
60
61
  * Create new QueryBatch instance
61
62
  * Matches JavaScript SDK constructor signature exactly
62
63
  */
63
- constructor(graphQLClient: UrqlClientWrapper, knishIOClient: KnishIOClient) {
64
+ constructor(graphQLClient: GraphQLClient, knishIOClient: KnishIOClient) {
64
65
  super(graphQLClient, knishIOClient)
65
66
 
66
- this.$__query = `query( $batchId: String ) {
67
+ this.$__query = gql`query( $batchId: String ) {
67
68
  Batch( batchId: $batchId ) {
68
69
  ${QueryBatch.getFields()},
69
70
  children {
@@ -48,7 +48,8 @@ License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
48
48
 
49
49
  import Query from './Query'
50
50
  import ResponseContinuId from '../response/ResponseContinuId'
51
- import type { UrqlClientWrapper } from '../client/GraphQLClient'
51
+ import { gql } from '@urql/core'
52
+ import type { GraphQLClient } from '../types/graphql'
52
53
  import type KnishIOClient from '../KnishIOClient'
53
54
 
54
55
  /**
@@ -60,10 +61,10 @@ export default class QueryContinuId extends Query {
60
61
  * Create new QueryContinuId instance
61
62
  * Matches JavaScript SDK constructor signature exactly
62
63
  */
63
- constructor(graphQLClient: UrqlClientWrapper, knishIOClient: KnishIOClient) {
64
+ constructor(graphQLClient: GraphQLClient, knishIOClient: KnishIOClient) {
64
65
  super(graphQLClient, knishIOClient)
65
66
 
66
- this.$__query = `query ($bundle: String!) {
67
+ this.$__query = gql`query ($bundle: String!) {
67
68
  ContinuId(bundle: $bundle) {
68
69
  address,
69
70
  bundleHash,
@@ -48,7 +48,8 @@ License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
48
48
 
49
49
  import Query from './Query'
50
50
  import ResponseMetaType from '../response/ResponseMetaType'
51
- import type { UrqlClientWrapper } from '../client/GraphQLClient'
51
+ import { gql } from '@urql/core'
52
+ import type { GraphQLClient } from '../types/graphql'
52
53
  import type KnishIOClient from '../KnishIOClient'
53
54
 
54
55
  /**
@@ -60,10 +61,10 @@ export default class QueryMetaType extends Query {
60
61
  * Create new QueryMetaType instance
61
62
  * Matches JavaScript SDK constructor signature exactly
62
63
  */
63
- constructor(graphQLClient: UrqlClientWrapper, knishIOClient: KnishIOClient) {
64
+ constructor(graphQLClient: GraphQLClient, knishIOClient: KnishIOClient) {
64
65
  super(graphQLClient, knishIOClient)
65
66
 
66
- this.$__query = `query( $metaType: String, $metaTypes: [ String! ], $metaId: String, $metaIds: [ String! ], $key: String, $keys: [ String! ], $value: String, $values: [ String! ], $count: String, $latest: Boolean, $filter: [ MetaFilter! ], $queryArgs: QueryArgs, $countBy: String, $cellSlug: String ) {
67
+ this.$__query = gql`query( $metaType: String, $metaTypes: [ String! ], $metaId: String, $metaIds: [ String! ], $key: String, $keys: [ String! ], $value: String, $values: [ String! ], $count: String, $latest: Boolean, $filter: [ MetaFilter! ], $queryArgs: QueryArgs, $countBy: String, $cellSlug: String ) {
67
68
  MetaType( metaType: $metaType, metaTypes: $metaTypes, metaId: $metaId, metaIds: $metaIds, key: $key, keys: $keys, value: $value, values: $values, count: $count, filter: $filter, queryArgs: $queryArgs, countBy: $countBy, cellSlug: $cellSlug ) {
68
69
  metaType,
69
70
  instanceCount {
@@ -48,7 +48,8 @@ License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
48
48
 
49
49
  import Query from './Query'
50
50
  import ResponseMetaTypeViaAtom from '../response/ResponseMetaTypeViaAtom'
51
- import type { UrqlClientWrapper } from '../client/GraphQLClient'
51
+ import { gql } from '@urql/core'
52
+ import type { GraphQLClient } from '../types/graphql'
52
53
  import type KnishIOClient from '../KnishIOClient'
53
54
 
54
55
  /**
@@ -60,10 +61,10 @@ export default class QueryMetaTypeViaAtom extends Query {
60
61
  * Create new QueryMetaTypeViaAtom instance
61
62
  * Matches JavaScript SDK constructor signature exactly
62
63
  */
63
- constructor(graphQLClient: UrqlClientWrapper, knishIOClient: KnishIOClient) {
64
+ constructor(graphQLClient: GraphQLClient, knishIOClient: KnishIOClient) {
64
65
  super(graphQLClient, knishIOClient)
65
66
 
66
- this.$__query = `query ($metaTypes: [String!], $metaIds: [String!], $values: [String!], $keys: [String!], $latest: Boolean, $filter: [MetaFilter!], $queryArgs: QueryArgs, $countBy: String, $atomValues: [String!], $cellSlugs: [String!] ) {
67
+ this.$__query = gql`query ($metaTypes: [String!], $metaIds: [String!], $values: [String!], $keys: [String!], $latest: Boolean, $filter: [MetaFilter!], $queryArgs: QueryArgs, $countBy: String, $atomValues: [String!], $cellSlugs: [String!] ) {
67
68
  MetaTypeViaAtom(
68
69
  metaTypes: $metaTypes
69
70
  metaIds: $metaIds
@@ -48,6 +48,7 @@ License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
48
48
 
49
49
  import Query from './Query'
50
50
  import ResponseWalletBundle from '../response/ResponseWalletBundle'
51
+ import { gql } from '@urql/core'
51
52
  import type GraphQLClient from '../libraries/GraphQLClient'
52
53
  import type KnishIOClient from '../KnishIOClient'
53
54
 
@@ -62,7 +63,7 @@ export default class QueryWalletBundle extends Query {
62
63
  constructor(graphQLClient: GraphQLClient, knishIOClient: KnishIOClient) {
63
64
  super(graphQLClient, knishIOClient)
64
65
 
65
- this.$__query = `
66
+ this.$__query = gql`
66
67
  query($bundleHashes: [String!]) {
67
68
  WalletBundle(bundleHashes: $bundleHashes) {
68
69
  bundleHash,