@wishknish/knishio-client-ts 0.7.2 → 0.7.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wishknish/knishio-client-ts",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "productName": "Knish.IO TypeScript SDK Client",
5
5
  "description": "TypeScript implementation of the Knish.IO SDK to consume Knish.IO GraphQL APIs with enhanced type safety.",
6
6
  "license": "GPL-3.0-or-later",
@@ -20,11 +20,11 @@
20
20
  "main": "./dist/index.cjs",
21
21
  "module": "./dist/index.js",
22
22
  "types": "./dist/index.d.ts",
23
- "browser": "./dist/index.iife.js",
23
+ "browser": "./dist/index.js",
24
24
  "exports": {
25
25
  ".": {
26
26
  "types": "./dist/index.d.ts",
27
- "browser": "./dist/index.iife.js",
27
+ "browser": "./dist/index.js",
28
28
  "import": {
29
29
  "types": "./dist/index.d.ts",
30
30
  "default": "./dist/index.js"
@@ -121,7 +121,8 @@ import type {
121
121
  CellSlug,
122
122
  MetaType,
123
123
  MetaId,
124
- BatchId
124
+ BatchId,
125
+ MetaFilter
125
126
  } from '@/types'
126
127
 
127
128
  /**
@@ -849,7 +850,7 @@ export default class KnishIOClient {
849
850
  queryArgs = null,
850
851
  count = null,
851
852
  countBy = null,
852
- throughAtom = null,
853
+ throughAtom = true,
853
854
  values = null,
854
855
  keys = null,
855
856
  atomValues = null
@@ -860,7 +861,7 @@ export default class KnishIOClient {
860
861
  value?: string | null
861
862
  latest?: boolean | null
862
863
  fields?: string[] | null
863
- filter?: string | null
864
+ filter?: MetaFilter[] | null
864
865
  queryArgs?: Record<string, any> | null
865
866
  count?: number | null
866
867
  countBy?: string | null
@@ -872,47 +873,38 @@ export default class KnishIOClient {
872
873
  this.log('info', `KnishIOClient::queryMeta() - Querying metaType: ${metaType}, metaId: ${metaId}...`)
873
874
 
874
875
  let query: Query
876
+ let variables: Record<string, any>
875
877
 
876
- if (throughAtom === true) {
878
+ if (throughAtom) {
877
879
  query = this.createQuery(QueryMetaTypeViaAtom)
880
+ variables = QueryMetaTypeViaAtom.createVariables({
881
+ metaType,
882
+ metaId,
883
+ key,
884
+ value,
885
+ latest,
886
+ filter,
887
+ queryArgs,
888
+ countBy,
889
+ values,
890
+ keys,
891
+ atomValues,
892
+ cellSlug: this.getCellSlug()
893
+ })
878
894
  } else {
879
895
  query = this.createQuery(QueryMetaType)
880
- }
881
-
882
- const variables: Record<string, any> = {
883
- metaType: metaType.toUpperCase(),
884
- metaId
885
- }
886
-
887
- if (filter !== null) {
888
- variables.filter = filter
889
- }
890
- if (latest !== null) {
891
- variables.latest = latest
892
- }
893
- if (key !== null) {
894
- variables.key = key
895
- }
896
- if (value !== null) {
897
- variables.value = value
898
- }
899
- if (queryArgs !== null) {
900
- variables.queryArgs = queryArgs
901
- }
902
- if (count !== null) {
903
- variables.count = count
904
- }
905
- if (countBy !== null) {
906
- variables.countBy = countBy
907
- }
908
- if (values !== null) {
909
- variables.values = values
910
- }
911
- if (keys !== null) {
912
- variables.keys = keys
913
- }
914
- if (atomValues !== null) {
915
- variables.atomValues = atomValues
896
+ variables = QueryMetaType.createVariables({
897
+ metaType,
898
+ metaId,
899
+ key,
900
+ value,
901
+ latest,
902
+ filter,
903
+ queryArgs,
904
+ count,
905
+ countBy,
906
+ cellSlug: this.getCellSlug()
907
+ })
916
908
  }
917
909
 
918
910
  return this.executeQuery(query, variables) as Promise<Response>
@@ -1008,42 +1000,43 @@ export default class KnishIOClient {
1008
1000
  metaId?: string | null
1009
1001
  indexes?: number[] | null
1010
1002
  index?: number | null
1011
- filter?: string | null
1003
+ filter?: MetaFilter[] | null
1012
1004
  latest?: boolean | null
1013
1005
  queryArgs?: Record<string, any> | null
1014
1006
  } = {}): Promise<Response> {
1007
+ this.log('info', 'KnishIOClient::queryAtom() - Querying atom instances')
1008
+
1015
1009
  const query = this.createQuery(QueryAtom)
1016
1010
 
1017
- const variables: Record<string, any> = {}
1018
-
1019
- // Add all non-null parameters to variables
1020
- if (molecularHashes !== null) variables.molecularHashes = molecularHashes
1021
- if (molecularHash !== null) variables.molecularHash = molecularHash
1022
- if (bundleHashes !== null) variables.bundleHashes = bundleHashes
1023
- if (bundleHash !== null) variables.bundleHash = bundleHash
1024
- if (positions !== null) variables.positions = positions
1025
- if (position !== null) variables.position = position
1026
- if (walletAddresses !== null) variables.walletAddresses = walletAddresses
1027
- if (walletAddress !== null) variables.walletAddress = walletAddress
1028
- if (isotopes !== null) variables.isotopes = isotopes
1029
- if (isotope !== null) variables.isotope = isotope
1030
- if (tokenSlugs !== null) variables.tokenSlugs = tokenSlugs
1031
- if (tokenSlug !== null) variables.tokenSlug = tokenSlug
1032
- if (cellSlugs !== null) variables.cellSlugs = cellSlugs
1033
- if (cellSlug !== null) variables.cellSlug = cellSlug
1034
- if (batchIds !== null) variables.batchIds = batchIds
1035
- if (batchId !== null) variables.batchId = batchId
1036
- if (values !== null) variables.values = values
1037
- if (value !== null) variables.value = value
1038
- if (metaTypes !== null) variables.metaTypes = metaTypes
1039
- if (metaType !== null) variables.metaType = metaType
1040
- if (metaIds !== null) variables.metaIds = metaIds
1041
- if (metaId !== null) variables.metaId = metaId
1042
- if (indexes !== null) variables.indexes = indexes
1043
- if (index !== null) variables.index = index
1044
- if (filter !== null) variables.filter = filter
1045
- if (latest !== null) variables.latest = latest
1046
- if (queryArgs !== null) variables.queryArgs = queryArgs
1011
+ const variables = QueryAtom.createVariables({
1012
+ molecularHashes,
1013
+ molecularHash,
1014
+ bundleHashes,
1015
+ bundleHash,
1016
+ positions,
1017
+ position,
1018
+ walletAddresses,
1019
+ walletAddress,
1020
+ isotopes,
1021
+ isotope,
1022
+ tokenSlugs,
1023
+ tokenSlug,
1024
+ cellSlugs,
1025
+ cellSlug,
1026
+ batchIds,
1027
+ batchId,
1028
+ values,
1029
+ value,
1030
+ metaTypes,
1031
+ metaType,
1032
+ metaIds,
1033
+ metaId,
1034
+ indexes,
1035
+ index,
1036
+ filter,
1037
+ latest,
1038
+ queryArgs
1039
+ })
1047
1040
 
1048
1041
  return this.executeQuery(query, variables) as Promise<Response>
1049
1042
  }
package/src/index.ts CHANGED
@@ -479,16 +479,7 @@ export const DevUtils = process.env.NODE_ENV === 'development' ? {
479
479
  // COMPATIBILITY WITH JAVASCRIPT SDK
480
480
  // =============================================================================
481
481
 
482
- /**
483
- * Legacy export names for compatibility with JavaScript SDK
484
- * These maintain the exact same naming convention
485
- */
486
- export {
487
- // Core exports (matching JS SDK exactly)
488
- shake256 as default, // The JS SDK doesn't export a default, but this maintains compatibility
489
- }
490
-
491
- // Maintain exact export structure as JS SDK index.js
482
+ // Maintain exact export structure as JS SDK index.js (named exports only)
492
483
  export const KnishIO = {
493
484
  shake256,
494
485
  generateSecret,
@@ -58,8 +58,7 @@ import { pipe, subscribe } from 'wonka'
58
58
  import type {
59
59
  GraphQLClient as IGraphQLClient,
60
60
  GraphQLRequest,
61
- GraphQLResponse,
62
- GraphQLVariables
61
+ GraphQLResponse
63
62
  } from '@/types'
64
63
  import type Wallet from '@/core/Wallet'
65
64
 
@@ -157,42 +156,38 @@ export default class GraphQLClient implements IGraphQLClient {
157
156
  })
158
157
  }
159
158
 
160
- async query<TResult = unknown, TVariables = GraphQLVariables>(
161
- request: GraphQLRequest,
162
- variables?: TVariables
159
+ async query<TResult = unknown>(
160
+ request: GraphQLRequest
163
161
  ): Promise<GraphQLResponse<TResult>> {
164
- const finalVariables = (variables || request.variables || {}) as Record<string, any>
165
- const result = await this.$__client.query(request.query, finalVariables).toPromise()
162
+ const { query, variables } = request
163
+ const result = await this.$__client.query(query, variables || {}).toPromise()
166
164
  return this.formatResponse<TResult>(result)
167
165
  }
168
166
 
169
- async mutation<TResult = unknown, TVariables = GraphQLVariables>(
170
- request: GraphQLRequest,
171
- variables?: TVariables
167
+ async mutation<TResult = unknown>(
168
+ request: GraphQLRequest
172
169
  ): Promise<GraphQLResponse<TResult>> {
173
- const finalVariables = (variables || request.variables || {}) as Record<string, any>
170
+ const { query, variables } = request
174
171
  // 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()
172
+ const mutationString = (request as any).mutation || query
173
+ const result = await this.$__client.mutation(mutationString, variables || {}).toPromise()
177
174
  return this.formatResponse<TResult>(result)
178
175
  }
179
176
 
180
177
  // Alias for mutation() to match JS SDK interface
181
- async mutate<TResult = unknown, TVariables = GraphQLVariables>(
182
- request: GraphQLRequest,
183
- variables?: TVariables
178
+ async mutate<TResult = unknown>(
179
+ request: GraphQLRequest
184
180
  ): Promise<GraphQLResponse<TResult>> {
185
- return this.mutation<TResult, TVariables>(request, variables)
181
+ return this.mutation<TResult>(request)
186
182
  }
187
183
 
188
- async *subscription<TResult = unknown, TVariables = GraphQLVariables>(
189
- request: GraphQLRequest,
190
- variables?: TVariables
184
+ async *subscription<TResult = unknown>(
185
+ request: GraphQLRequest
191
186
  ): AsyncIterableIterator<GraphQLResponse<TResult>> {
192
- const finalVariables = (variables || request.variables || {}) as Record<string, any>
187
+ const { query, variables } = request
193
188
 
194
189
  // Create subscription stream
195
- const subscription = this.$__client.subscription(request.query, finalVariables)
190
+ const subscription = this.$__client.subscription(query, variables || {})
196
191
 
197
192
  // Convert wonka stream to async iterator
198
193
  const results: GraphQLResponse<TResult>[] = []
@@ -151,12 +151,12 @@ export default class Query {
151
151
  /**
152
152
  * Executes the Query and returns a Response
153
153
  */
154
- async execute({
155
- variables = {},
156
- context = {}
157
- }: {
158
- variables?: Record<string, any>
159
- context?: Record<string, any>
154
+ async execute({
155
+ variables = null,
156
+ context = {}
157
+ }: {
158
+ variables?: Record<string, any> | null
159
+ context?: Record<string, any>
160
160
  } = {}): Promise<Response | null> {
161
161
  this.$__request = this.createQuery({ variables })
162
162
 
@@ -156,33 +156,33 @@ export default class QueryAtom extends Query {
156
156
  latest,
157
157
  queryArgs
158
158
  }: {
159
- molecularHashes?: string[]
160
- molecularHash?: string
161
- bundleHashes?: string[]
162
- bundleHash?: string
163
- positions?: string[]
164
- position?: string
165
- walletAddresses?: string[]
166
- walletAddress?: string
167
- isotopes?: string[]
168
- isotope?: string
169
- tokenSlugs?: string[]
170
- tokenSlug?: string
171
- cellSlugs?: string[]
172
- cellSlug?: string
173
- batchIds?: string[]
174
- batchId?: string
175
- values?: string[]
176
- value?: string | number
177
- metaTypes?: string[]
178
- metaType?: string
179
- metaIds?: string[]
180
- metaId?: string
181
- indexes?: number[]
182
- index?: number
183
- filter?: object[]
184
- latest?: boolean
185
- queryArgs?: object
159
+ molecularHashes?: string[] | null
160
+ molecularHash?: string | null
161
+ bundleHashes?: string[] | null
162
+ bundleHash?: string | null
163
+ positions?: string[] | null
164
+ position?: string | null
165
+ walletAddresses?: string[] | null
166
+ walletAddress?: string | null
167
+ isotopes?: string[] | null
168
+ isotope?: string | null
169
+ tokenSlugs?: string[] | null
170
+ tokenSlug?: string | null
171
+ cellSlugs?: string[] | null
172
+ cellSlug?: string | null
173
+ batchIds?: string[] | null
174
+ batchId?: string | null
175
+ values?: string[] | null
176
+ value?: string | number | null
177
+ metaTypes?: string[] | null
178
+ metaType?: string | null
179
+ metaIds?: string[] | null
180
+ metaId?: string | null
181
+ indexes?: number[] | null
182
+ index?: number | null
183
+ filter?: object[] | null
184
+ latest?: boolean | null
185
+ queryArgs?: object | null
186
186
  }): Record<string, any> {
187
187
  if (molecularHash) {
188
188
  molecularHashes = molecularHashes || []
@@ -114,7 +114,7 @@ export default class QueryMetaType extends Query {
114
114
  latest?: boolean | null
115
115
  filter?: any | null
116
116
  queryArgs?: any | null
117
- count?: string | null
117
+ count?: string | number | null
118
118
  countBy?: string | null
119
119
  cellSlug?: string | null
120
120
  } = {}): Record<string, any> {
@@ -95,6 +95,17 @@ export default class Response implements UniversalResponse<any> {
95
95
  throw new InvalidResponseException()
96
96
  }
97
97
 
98
+ // Check for GraphQL errors array
99
+ if (this.$__response.errors && Array.isArray(this.$__response.errors) && this.$__response.errors.length > 0) {
100
+ const errorMessage = this.$__response.errors[0].message || 'Unknown GraphQL error'
101
+
102
+ if (errorMessage.includes('Unauthenticated')) {
103
+ throw new UnauthenticatedException('Unauthenticated request')
104
+ }
105
+
106
+ throw new InvalidResponseException(`GraphQL Error: ${errorMessage}`)
107
+ }
108
+
98
109
  this.init()
99
110
  }
100
111
 
@@ -113,9 +124,14 @@ export default class Response implements UniversalResponse<any> {
113
124
  return this.response()
114
125
  }
115
126
 
127
+ // Check if response has data field
128
+ if (!this.response().data) {
129
+ throw new InvalidResponseException('Response has no data field')
130
+ }
131
+
116
132
  // Check key & return custom data from the response
117
133
  if (!Dot.has(this.response(), this.dataKey)) {
118
- throw new InvalidResponseException()
134
+ throw new InvalidResponseException(`Missing expected field: ${this.dataKey}`)
119
135
  }
120
136
 
121
137
  return Dot.get(this.response(), this.dataKey)
@@ -248,6 +248,17 @@ export const RequestTokensParamsSchema = z.object({
248
248
  meta: z.union([MetaDataSchema, z.null()]).optional()
249
249
  }).strict()
250
250
 
251
+ // =============================================================================
252
+ // FILTER SCHEMAS
253
+ // =============================================================================
254
+
255
+ export const MetaFilterSchema = z.object({
256
+ key: z.string(),
257
+ value: z.string(),
258
+ comparison: z.string().optional(),
259
+ criterion: z.string().optional()
260
+ }).strict()
261
+
251
262
  // =============================================================================
252
263
  // QUERY PARAMETER SCHEMAS
253
264
  // =============================================================================
@@ -265,7 +276,7 @@ export const MetaQueryParamsSchema = z.object({
265
276
  key: z.union([z.string(), z.null()]).optional(),
266
277
  value: z.union([z.string(), z.null()]).optional(),
267
278
  latest: z.union([z.boolean(), z.null()]).optional(),
268
- filter: z.union([z.string(), z.null()]).optional(),
279
+ filter: z.union([z.array(MetaFilterSchema), z.null()]).optional(),
269
280
  queryArgs: z.union([z.record(z.unknown()), z.null()]).optional(),
270
281
  count: z.union([z.number().int().min(1), z.null()]).optional(),
271
282
  countBy: z.union([z.string(), z.null()]).optional(),
@@ -58,7 +58,8 @@ import type {
58
58
  MetaId,
59
59
  CellSlug,
60
60
  MetaData,
61
- BaseResponse
61
+ BaseResponse,
62
+ MetaFilter
62
63
  } from './index'
63
64
 
64
65
  // =============================================================================
@@ -237,7 +238,7 @@ export interface MetaQueryOptions {
237
238
  key?: string | null
238
239
  value?: string | null
239
240
  latest?: boolean | null
240
- filter?: string | null
241
+ filter?: MetaFilter[] | null
241
242
  queryArgs?: Record<string, unknown> | null
242
243
  count?: number | null
243
244
  countBy?: string | null
@@ -59,7 +59,8 @@ import type {
59
59
  MetaId,
60
60
  CellSlug,
61
61
  AtomIsotope,
62
- MetaData
62
+ MetaData,
63
+ MetaFilter
63
64
  } from './index'
64
65
 
65
66
  // =============================================================================
@@ -173,7 +174,7 @@ export interface QueryMetaTypeVariables {
173
174
  key?: string | null
174
175
  value?: string | null
175
176
  latest?: boolean | null
176
- filter?: string | null
177
+ filter?: MetaFilter[] | null
177
178
  queryArgs?: Record<string, unknown> | null
178
179
  count?: number | null
179
180
  countBy?: string | null
@@ -284,6 +284,21 @@ export interface RequestTokensParams {
284
284
  meta?: MetaData | null
285
285
  }
286
286
 
287
+ // =============================================================================
288
+ // FILTER TYPES
289
+ // =============================================================================
290
+
291
+ /**
292
+ * MetaFilter interface for filtering meta queries
293
+ * Matches the GraphQL MetaFilter input type from the server
294
+ */
295
+ export interface MetaFilter {
296
+ key: string
297
+ value: string
298
+ comparison?: string // '=', '<', '>', '<=', '>=', '!='
299
+ criterion?: string
300
+ }
301
+
287
302
  // =============================================================================
288
303
  // QUERY PARAMETER TYPES
289
304
  // =============================================================================
@@ -301,7 +316,7 @@ export interface MetaQueryParams {
301
316
  key?: string | null
302
317
  value?: string | null
303
318
  latest?: boolean | null
304
- filter?: string | null
319
+ filter?: MetaFilter[] | null
305
320
  queryArgs?: Record<string, unknown> | null
306
321
  count?: number | null
307
322
  countBy?: string | null