@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,614 @@
|
|
|
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
|
+
/**
|
|
50
|
+
* Core TypeScript type definitions for the KnishIO SDK
|
|
51
|
+
* Provides type safety for post-blockchain DLT operations
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
// =============================================================================
|
|
55
|
+
// IMPORTS FOR CONST ASSERTIONS
|
|
56
|
+
// =============================================================================
|
|
57
|
+
|
|
58
|
+
import type {
|
|
59
|
+
AtomIsotope,
|
|
60
|
+
KnishIOErrorType,
|
|
61
|
+
HexChar,
|
|
62
|
+
Base17Char,
|
|
63
|
+
HexPattern,
|
|
64
|
+
Base17Pattern,
|
|
65
|
+
WalletAddressPattern,
|
|
66
|
+
BundleHashPattern,
|
|
67
|
+
PositionPattern,
|
|
68
|
+
TokenSlugPattern,
|
|
69
|
+
ErrorMessageTemplate,
|
|
70
|
+
ValidationErrorTemplate,
|
|
71
|
+
OperationErrorTemplate,
|
|
72
|
+
QueryType,
|
|
73
|
+
MutationType,
|
|
74
|
+
SubscriptionType,
|
|
75
|
+
BalanceQueryType,
|
|
76
|
+
NodeEnvironment
|
|
77
|
+
} from '../constants'
|
|
78
|
+
|
|
79
|
+
import { ISOTOPE_LOOKUP } from '../constants'
|
|
80
|
+
|
|
81
|
+
// =============================================================================
|
|
82
|
+
// BRANDED TYPES WITH TEMPLATE LITERAL PATTERNS (2025 TYPESCRIPT)
|
|
83
|
+
// =============================================================================
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Enhanced branded types with template literal validation
|
|
87
|
+
* Provides both runtime and compile-time type safety
|
|
88
|
+
*/
|
|
89
|
+
export type WalletAddress = WalletAddressPattern & { readonly __brand: 'WalletAddress' }
|
|
90
|
+
export type BundleHash = BundleHashPattern & { readonly __brand: 'BundleHash' }
|
|
91
|
+
export type Position = PositionPattern & { readonly __brand: 'Position' }
|
|
92
|
+
export type MolecularHash = Base17Pattern & { readonly __brand: 'MolecularHash' }
|
|
93
|
+
export type TokenSlug = TokenSlugPattern & { readonly __brand: 'TokenSlug' }
|
|
94
|
+
export type MetaType = string & { readonly __brand: 'MetaType' }
|
|
95
|
+
export type MetaId = string & { readonly __brand: 'MetaId' }
|
|
96
|
+
export type BatchId = string & { readonly __brand: 'BatchId' }
|
|
97
|
+
export type CellSlug = string & { readonly __brand: 'CellSlug' }
|
|
98
|
+
|
|
99
|
+
// =============================================================================
|
|
100
|
+
// ENHANCED TEMPLATE LITERAL TYPES (2025 TYPESCRIPT)
|
|
101
|
+
// =============================================================================
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Advanced template literal types for validation
|
|
105
|
+
* Leverages const assertions and pattern matching
|
|
106
|
+
*/
|
|
107
|
+
export type HexString = HexPattern & { readonly __hex: true }
|
|
108
|
+
export type Base17Hash = Base17Pattern & { readonly __base17: true }
|
|
109
|
+
|
|
110
|
+
// Re-export from constants for convenience
|
|
111
|
+
export type { HexChar, Base17Char } from '../constants'
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Specific length-validated hex types using template literals
|
|
115
|
+
*/
|
|
116
|
+
export type Hex64 = `${HexChar}${string}` & { length: 64 }
|
|
117
|
+
export type Hex32 = `${HexChar}${string}` & { length: 32 }
|
|
118
|
+
export type Hex16 = `${HexChar}${string}` & { length: 16 }
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* URL and URI template patterns
|
|
122
|
+
*/
|
|
123
|
+
export type HttpUrl = `http://${string}`
|
|
124
|
+
export type HttpsUrl = `https://${string}`
|
|
125
|
+
export type WebSocketUrl = `ws://${string}` | `wss://${string}`
|
|
126
|
+
export type GraphQLEndpoint = `${HttpUrl | HttpsUrl}/graphql`
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Version template patterns
|
|
130
|
+
*/
|
|
131
|
+
export type SemanticVersion = `${number}.${number}.${number}`
|
|
132
|
+
export type SdkVersion = `v${SemanticVersion}`
|
|
133
|
+
|
|
134
|
+
// =============================================================================
|
|
135
|
+
// ATOM ISOTOPE TYPES WITH CONST ASSERTIONS (2025 TYPESCRIPT)
|
|
136
|
+
// =============================================================================
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Re-export isotope types from constants with const assertions
|
|
140
|
+
* Provides immutable type definitions at compile-time
|
|
141
|
+
*/
|
|
142
|
+
export type { AtomIsotope } from '../constants'
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Enhanced isotope descriptions with const assertion
|
|
146
|
+
* Uses satisfies operator for type checking
|
|
147
|
+
*/
|
|
148
|
+
export type IsotopeDescriptions = {
|
|
149
|
+
readonly [K in AtomIsotope]: `${string} - ${string}`
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Template literal types for isotope-specific validation
|
|
154
|
+
*/
|
|
155
|
+
export type IsotopeCode<T extends AtomIsotope> = T
|
|
156
|
+
export type IsotopeDescription<T extends AtomIsotope> = T extends keyof IsotopeDescriptions
|
|
157
|
+
? IsotopeDescriptions[T]
|
|
158
|
+
: never
|
|
159
|
+
|
|
160
|
+
// =============================================================================
|
|
161
|
+
// META DATA TYPES
|
|
162
|
+
// =============================================================================
|
|
163
|
+
|
|
164
|
+
export interface MetaData {
|
|
165
|
+
[key: string]: string | number | boolean | null | MetaData | MetaData[]
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export interface AtomMetaData extends MetaData {
|
|
169
|
+
readonly key: string
|
|
170
|
+
readonly value: string | number | boolean | null
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// =============================================================================
|
|
174
|
+
// CORE INTERFACE TYPES
|
|
175
|
+
// =============================================================================
|
|
176
|
+
|
|
177
|
+
export interface AtomParams {
|
|
178
|
+
position?: string | null
|
|
179
|
+
walletAddress?: WalletAddress | null
|
|
180
|
+
isotope?: AtomIsotope
|
|
181
|
+
token?: TokenSlug | string
|
|
182
|
+
value?: string | number | null
|
|
183
|
+
batchId?: BatchId | string | null
|
|
184
|
+
metaType?: MetaType | string | null
|
|
185
|
+
metaId?: MetaId | string | null
|
|
186
|
+
meta?: AtomMetaData[] | null
|
|
187
|
+
otsFragment?: string | null
|
|
188
|
+
index?: number | null
|
|
189
|
+
createdAt?: string | null
|
|
190
|
+
version?: number | null
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export interface WalletParams {
|
|
194
|
+
secret?: string | null
|
|
195
|
+
bundle?: BundleHash | string | null
|
|
196
|
+
token?: TokenSlug | string
|
|
197
|
+
address?: WalletAddress | string | null
|
|
198
|
+
position?: Position | string | null
|
|
199
|
+
batchId?: BatchId | string | null
|
|
200
|
+
characters?: string | null
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export interface MoleculeParams {
|
|
204
|
+
secret?: string | null
|
|
205
|
+
bundle?: BundleHash | string | null
|
|
206
|
+
sourceWallet?: WalletParams | null
|
|
207
|
+
remainderWallet?: WalletParams | null
|
|
208
|
+
cellSlug?: CellSlug | string | null
|
|
209
|
+
version?: number
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// =============================================================================
|
|
213
|
+
// CLIENT CONFIGURATION TYPES
|
|
214
|
+
// =============================================================================
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Enhanced client configuration with const assertions and template literals
|
|
218
|
+
*/
|
|
219
|
+
export interface KnishIOClientConfig {
|
|
220
|
+
readonly uri?: HttpUrl | HttpsUrl | readonly (HttpUrl | HttpsUrl)[]
|
|
221
|
+
readonly cellSlug?: CellSlug | string | null
|
|
222
|
+
readonly client?: unknown | null
|
|
223
|
+
readonly socket?: unknown | null
|
|
224
|
+
readonly serverSdkVersion?: 3 | 4 | 5 // Specific supported versions
|
|
225
|
+
readonly logging?: boolean
|
|
226
|
+
readonly timeout?: number
|
|
227
|
+
readonly retryAttempts?: number
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Configuration with satisfies operator for type safety
|
|
232
|
+
*/
|
|
233
|
+
export type ValidatedClientConfig = KnishIOClientConfig & {
|
|
234
|
+
readonly uri: NonNullable<KnishIOClientConfig['uri']>
|
|
235
|
+
readonly serverSdkVersion: NonNullable<KnishIOClientConfig['serverSdkVersion']>
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// =============================================================================
|
|
239
|
+
// AUTHENTICATION TYPES
|
|
240
|
+
// =============================================================================
|
|
241
|
+
|
|
242
|
+
export interface AuthTokenParams {
|
|
243
|
+
token: string
|
|
244
|
+
expiresAt: number
|
|
245
|
+
encrypt: boolean
|
|
246
|
+
pubkey: string
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export interface AuthParams {
|
|
250
|
+
cellSlug?: CellSlug | string | null
|
|
251
|
+
encrypt?: boolean
|
|
252
|
+
callback?: (response: unknown) => void
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export interface GuestAuthParams {
|
|
256
|
+
cellSlug?: CellSlug | string | null
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// =============================================================================
|
|
260
|
+
// TOKEN OPERATION TYPES
|
|
261
|
+
// =============================================================================
|
|
262
|
+
|
|
263
|
+
export interface TransferParams {
|
|
264
|
+
recipient: WalletAddress | string
|
|
265
|
+
amount: number | string
|
|
266
|
+
token?: TokenSlug | string
|
|
267
|
+
callbackUrl?: string | null
|
|
268
|
+
metaType?: MetaType | string | null
|
|
269
|
+
metaId?: MetaId | string | null
|
|
270
|
+
meta?: MetaData | null
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface CreateTokenParams {
|
|
274
|
+
token: TokenSlug | string
|
|
275
|
+
amount: number | string
|
|
276
|
+
metaType?: MetaType | string | null
|
|
277
|
+
metaId?: MetaId | string | null
|
|
278
|
+
meta?: MetaData | null
|
|
279
|
+
fungible?: boolean
|
|
280
|
+
splittable?: number
|
|
281
|
+
supplyToken?: TokenSlug | string | null
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export interface RequestTokensParams {
|
|
285
|
+
amount: number | string
|
|
286
|
+
token?: TokenSlug | string
|
|
287
|
+
metaType?: MetaType | string | null
|
|
288
|
+
metaId?: MetaId | string | null
|
|
289
|
+
meta?: MetaData | null
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// =============================================================================
|
|
293
|
+
// QUERY PARAMETER TYPES
|
|
294
|
+
// =============================================================================
|
|
295
|
+
|
|
296
|
+
export interface BalanceQueryParams {
|
|
297
|
+
address?: WalletAddress | string | null
|
|
298
|
+
bundleHash?: BundleHash | string | null
|
|
299
|
+
token?: TokenSlug | string | null
|
|
300
|
+
type?: 'token' | 'user' | null
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export interface MetaQueryParams {
|
|
304
|
+
metaType: MetaType | string
|
|
305
|
+
metaId?: MetaId | string | null
|
|
306
|
+
key?: string | null
|
|
307
|
+
value?: string | null
|
|
308
|
+
latest?: boolean | null
|
|
309
|
+
filter?: string | null
|
|
310
|
+
queryArgs?: Record<string, unknown> | null
|
|
311
|
+
count?: number | null
|
|
312
|
+
countBy?: string | null
|
|
313
|
+
cellSlug?: CellSlug | string | null
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export interface WalletQueryParams {
|
|
317
|
+
bundleHash?: BundleHash | string | null
|
|
318
|
+
tokenSlug?: TokenSlug | string | null
|
|
319
|
+
unspent?: boolean | null
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// =============================================================================
|
|
323
|
+
// RESPONSE BASE TYPES
|
|
324
|
+
// =============================================================================
|
|
325
|
+
|
|
326
|
+
export interface BaseResponse<T = unknown> {
|
|
327
|
+
success(): boolean
|
|
328
|
+
reason(): string | null
|
|
329
|
+
data(): T | null
|
|
330
|
+
payload(): Record<string, unknown> | null
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export interface ValidationResult {
|
|
334
|
+
valid: boolean
|
|
335
|
+
error?: string | null
|
|
336
|
+
expected?: string
|
|
337
|
+
actual?: unknown
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// =============================================================================
|
|
341
|
+
// CRYPTOGRAPHIC TYPES
|
|
342
|
+
// =============================================================================
|
|
343
|
+
|
|
344
|
+
export interface CryptoOptions {
|
|
345
|
+
seed?: string | null
|
|
346
|
+
length?: number
|
|
347
|
+
outputLength?: number
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export interface KeyPairResult {
|
|
351
|
+
privateKey: string
|
|
352
|
+
publicKey: string
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export interface SignatureResult {
|
|
356
|
+
signature: string
|
|
357
|
+
otsFragments?: string[]
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// =============================================================================
|
|
361
|
+
// GRAPHQL OPERATION TYPES
|
|
362
|
+
// =============================================================================
|
|
363
|
+
|
|
364
|
+
export interface GraphQLRequest {
|
|
365
|
+
query: string
|
|
366
|
+
variables?: Record<string, unknown>
|
|
367
|
+
operationName?: string | null
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export interface GraphQLResponse<T = unknown> {
|
|
371
|
+
data?: T | null
|
|
372
|
+
errors?: Array<{
|
|
373
|
+
message: string
|
|
374
|
+
locations?: Array<{ line: number; column: number }>
|
|
375
|
+
path?: Array<string | number>
|
|
376
|
+
extensions?: Record<string, unknown>
|
|
377
|
+
}> | null
|
|
378
|
+
extensions?: Record<string, unknown>
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// =============================================================================
|
|
382
|
+
// SUBSCRIPTION TYPES
|
|
383
|
+
// =============================================================================
|
|
384
|
+
|
|
385
|
+
export interface SubscriptionOptions {
|
|
386
|
+
operationName?: string
|
|
387
|
+
query?: string
|
|
388
|
+
variables?: Record<string, unknown>
|
|
389
|
+
callback?: (data: unknown) => void
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// =============================================================================
|
|
393
|
+
// ADVANCED UTILITY TYPES (2025 TYPESCRIPT)
|
|
394
|
+
// =============================================================================
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Enhanced utility types with const assertions
|
|
398
|
+
*/
|
|
399
|
+
export type DeepPartial<T> = {
|
|
400
|
+
readonly [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P]
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
export type RequiredBy<T, K extends keyof T> = T & Required<Pick<T, K>>
|
|
404
|
+
export type OptionalBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Const assertion utility type
|
|
408
|
+
*/
|
|
409
|
+
export type AsConst<T> = T extends readonly unknown[]
|
|
410
|
+
? readonly [...T]
|
|
411
|
+
: T extends Record<string, unknown>
|
|
412
|
+
? { readonly [K in keyof T]: AsConst<T[K]> }
|
|
413
|
+
: T
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Template literal utility for creating branded types
|
|
417
|
+
*/
|
|
418
|
+
export type Branded<T, B extends string> = T & { readonly __brand: B }
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Conditional types for isotope-specific atoms with const assertions
|
|
422
|
+
*/
|
|
423
|
+
export type AtomWithIsotope<I extends AtomIsotope> = AtomParams & {
|
|
424
|
+
readonly isotope: I
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Enhanced atom types with template literal validation
|
|
429
|
+
*/
|
|
430
|
+
export type ValueAtom = AtomWithIsotope<'V'> & {
|
|
431
|
+
readonly value: number | string
|
|
432
|
+
} & { readonly __atomType: 'ValueAtom' }
|
|
433
|
+
|
|
434
|
+
export type MetaAtom = AtomWithIsotope<'M'> & {
|
|
435
|
+
readonly metaType: MetaType | string
|
|
436
|
+
readonly metaId: MetaId | string
|
|
437
|
+
readonly meta: readonly AtomMetaData[]
|
|
438
|
+
} & { readonly __atomType: 'MetaAtom' }
|
|
439
|
+
|
|
440
|
+
export type ContinueAtom = AtomWithIsotope<'C'> & {
|
|
441
|
+
readonly __atomType: 'ContinueAtom'
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Union type for all atom variants
|
|
446
|
+
*/
|
|
447
|
+
export type AnyAtom = ValueAtom | MetaAtom | ContinueAtom
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Template literal type for operation names
|
|
451
|
+
*/
|
|
452
|
+
export type OperationName<T extends string> = `${Lowercase<T>}Operation`
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Exhaustive check utility with template literals
|
|
456
|
+
*/
|
|
457
|
+
export type Exhaustive<T> = T extends never ? never : `Unhandled case: ${T & string}`
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Template literal type for creating API method names
|
|
461
|
+
*/
|
|
462
|
+
export type ApiMethodName<T extends string> = `${Lowercase<T>}${Capitalize<string>}`
|
|
463
|
+
|
|
464
|
+
// =============================================================================
|
|
465
|
+
// ERROR TYPES
|
|
466
|
+
// =============================================================================
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Enhanced ErrorContext with conditional properties (2025 TypeScript)
|
|
470
|
+
* Supports flexible error context while maintaining type safety
|
|
471
|
+
*/
|
|
472
|
+
export interface ErrorContext {
|
|
473
|
+
readonly operation?: string
|
|
474
|
+
readonly parameters?: Record<string, unknown>
|
|
475
|
+
readonly timestamp?: number
|
|
476
|
+
readonly stack?: string
|
|
477
|
+
// Exception-specific context properties
|
|
478
|
+
readonly reason?: string
|
|
479
|
+
readonly expiresAt?: number
|
|
480
|
+
readonly credentialType?: string
|
|
481
|
+
readonly field?: string
|
|
482
|
+
readonly value?: unknown
|
|
483
|
+
readonly expected?: string
|
|
484
|
+
readonly actual?: unknown
|
|
485
|
+
readonly code?: string
|
|
486
|
+
readonly severity?: 'low' | 'medium' | 'high'
|
|
487
|
+
readonly recoverable?: boolean
|
|
488
|
+
readonly retryable?: boolean
|
|
489
|
+
// Allow additional properties with proper typing
|
|
490
|
+
readonly [key: string]: unknown
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Re-export error types from constants with const assertions
|
|
495
|
+
* Provides immutable error type definitions
|
|
496
|
+
*/
|
|
497
|
+
export type { KnishIOErrorType } from '../constants'
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Template literal types for error messages
|
|
501
|
+
*/
|
|
502
|
+
export type ErrorMessage<T extends KnishIOErrorType> = ErrorMessageTemplate<T>
|
|
503
|
+
export type ValidationError<T extends string> = ValidationErrorTemplate<T>
|
|
504
|
+
export type OperationError<T extends string> = OperationErrorTemplate<T>
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* Enhanced error context with template literals
|
|
508
|
+
*/
|
|
509
|
+
export type ErrorContextKey = `error_${string}` | `validation_${string}` | `operation_${string}`
|
|
510
|
+
|
|
511
|
+
// =============================================================================
|
|
512
|
+
// MODULE DECLARATION AUGMENTATIONS
|
|
513
|
+
// =============================================================================
|
|
514
|
+
|
|
515
|
+
declare global {
|
|
516
|
+
interface String {
|
|
517
|
+
toCamelCase(): string
|
|
518
|
+
toSnakeCase(): string
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// =============================================================================
|
|
523
|
+
// TYPE GUARDS
|
|
524
|
+
// =============================================================================
|
|
525
|
+
|
|
526
|
+
export function isHexString(value: string): value is HexString {
|
|
527
|
+
return /^[0-9a-fA-F]+$/.test(value)
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
export function isWalletAddress(value: string): value is WalletAddress {
|
|
531
|
+
return isHexString(value) && value.length === 64
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
export function isBundleHash(value: string): value is BundleHash {
|
|
535
|
+
return isHexString(value) && value.length === 64
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
export function isPosition(value: string): value is Position {
|
|
539
|
+
return isHexString(value) && value.length === 64
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
export function isMolecularHash(value: string): value is MolecularHash {
|
|
543
|
+
return /^[0-9a-g]+$/.test(value.toLowerCase()) // Base17 format
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Enhanced type guards using const assertions from constants
|
|
548
|
+
*/
|
|
549
|
+
export function isAtomIsotope(value: string): value is AtomIsotope {
|
|
550
|
+
return value in ISOTOPE_LOOKUP
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Type guard for GraphQL operations using template literals
|
|
555
|
+
*/
|
|
556
|
+
export function isGraphQLOperation(value: string): value is 'query' | 'mutation' | 'subscription' {
|
|
557
|
+
return ['query', 'mutation', 'subscription'].includes(value)
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Type guard for environment using const assertions
|
|
562
|
+
*/
|
|
563
|
+
export function isNodeEnvironment(value: string): value is NodeEnvironment {
|
|
564
|
+
return (['development', 'production', 'test'] as const).includes(value as NodeEnvironment)
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// =============================================================================
|
|
568
|
+
// FACTORY FUNCTIONS FOR BRANDED TYPES
|
|
569
|
+
// =============================================================================
|
|
570
|
+
|
|
571
|
+
export function createWalletAddress(value: string): WalletAddress {
|
|
572
|
+
if (!isWalletAddress(value)) {
|
|
573
|
+
throw new Error(`Invalid wallet address: ${value}`)
|
|
574
|
+
}
|
|
575
|
+
return value as WalletAddress
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
export function createBundleHash(value: string): BundleHash {
|
|
579
|
+
if (!isBundleHash(value)) {
|
|
580
|
+
throw new Error(`Invalid bundle hash: ${value}`)
|
|
581
|
+
}
|
|
582
|
+
return value as BundleHash
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
export function createPosition(value: string): Position {
|
|
586
|
+
if (!isPosition(value)) {
|
|
587
|
+
throw new Error(`Invalid position: ${value}`)
|
|
588
|
+
}
|
|
589
|
+
return value as Position
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
export function createTokenSlug(value: string): TokenSlug {
|
|
593
|
+
if (!value || value.length === 0) {
|
|
594
|
+
throw new Error('Token slug cannot be empty')
|
|
595
|
+
}
|
|
596
|
+
return value.toUpperCase() as TokenSlug
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
export function createMolecularHash(value: string): MolecularHash {
|
|
600
|
+
if (!isMolecularHash(value)) {
|
|
601
|
+
throw new Error(`Invalid molecular hash: ${value}`)
|
|
602
|
+
}
|
|
603
|
+
return value as MolecularHash
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// =============================================================================
|
|
607
|
+
// EXPORTS
|
|
608
|
+
// =============================================================================
|
|
609
|
+
|
|
610
|
+
export * from './client'
|
|
611
|
+
export * from './crypto'
|
|
612
|
+
export * from './graphql'
|
|
613
|
+
|
|
614
|
+
// All types are already exported via the export * statements above
|