@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
package/src/constants.ts
ADDED
|
@@ -0,0 +1,398 @@
|
|
|
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
|
+
* Constants with Const Assertions for KnishIO SDK
|
|
51
|
+
*
|
|
52
|
+
* Implements 2025 TypeScript patterns:
|
|
53
|
+
* - Const assertions for immutable data structures
|
|
54
|
+
* - Template literal types for enhanced validation
|
|
55
|
+
* - Type-safe constants for protocol definitions
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
// =============================================================================
|
|
59
|
+
// ATOM ISOTOPE CONSTANTS (CONST ASSERTION)
|
|
60
|
+
// =============================================================================
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Immutable array of atom isotopes with const assertion
|
|
64
|
+
* Provides compile-time type safety and runtime immutability
|
|
65
|
+
*/
|
|
66
|
+
export const ISOTOPES = ['C', 'V', 'U', 'T', 'M', 'I', 'R', 'B', 'F'] as const
|
|
67
|
+
export type AtomIsotope = typeof ISOTOPES[number]
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Isotope descriptions with const assertion for type safety
|
|
71
|
+
*/
|
|
72
|
+
export const ISOTOPE_DESCRIPTIONS = {
|
|
73
|
+
C: 'Continue - Position continuation',
|
|
74
|
+
V: 'Value - Token value transfer',
|
|
75
|
+
U: 'User - User token operations',
|
|
76
|
+
T: 'Token - Token creation/management',
|
|
77
|
+
M: 'Meta - Metadata operations',
|
|
78
|
+
I: 'Identity - Identity operations',
|
|
79
|
+
R: 'Rule - Policy operations',
|
|
80
|
+
B: 'Buffer - Buffer token operations',
|
|
81
|
+
F: 'Fuse - Token fusion operations'
|
|
82
|
+
} as const satisfies Record<AtomIsotope, string>
|
|
83
|
+
|
|
84
|
+
// =============================================================================
|
|
85
|
+
// ERROR TYPE CONSTANTS (CONST ASSERTION)
|
|
86
|
+
// =============================================================================
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Immutable error type definitions with const assertion
|
|
90
|
+
*/
|
|
91
|
+
export const ERROR_TYPES = [
|
|
92
|
+
'ATOM_INDEX_ERROR',
|
|
93
|
+
'ATOMS_MISSING_ERROR',
|
|
94
|
+
'AUTHORIZATION_REJECTED_ERROR',
|
|
95
|
+
'BALANCE_INSUFFICIENT_ERROR',
|
|
96
|
+
'BATCH_ID_ERROR',
|
|
97
|
+
'CODE_ERROR',
|
|
98
|
+
'DECRYPTION_KEY_ERROR',
|
|
99
|
+
'INVALID_RESPONSE_ERROR',
|
|
100
|
+
'META_MISSING_ERROR',
|
|
101
|
+
'MOLECULAR_HASH_MISMATCH_ERROR',
|
|
102
|
+
'MOLECULAR_HASH_MISSING_ERROR',
|
|
103
|
+
'NEGATIVE_AMOUNT_ERROR',
|
|
104
|
+
'POLICY_INVALID_ERROR',
|
|
105
|
+
'RULE_ARGUMENT_ERROR',
|
|
106
|
+
'SIGNATURE_MALFORMED_ERROR',
|
|
107
|
+
'SIGNATURE_MISMATCH_ERROR',
|
|
108
|
+
'STACKABLE_UNIT_AMOUNT_ERROR',
|
|
109
|
+
'STACKABLE_UNIT_DECIMALS_ERROR',
|
|
110
|
+
'TRANSFER_BALANCE_ERROR',
|
|
111
|
+
'TRANSFER_MALFORMED_ERROR',
|
|
112
|
+
'TRANSFER_MISMATCHED_ERROR',
|
|
113
|
+
'TRANSFER_REMAINDER_ERROR',
|
|
114
|
+
'TRANSFER_TO_SELF_ERROR',
|
|
115
|
+
'TRANSFER_UNBALANCED_ERROR',
|
|
116
|
+
'UNAUTHENTICATED_ERROR',
|
|
117
|
+
'WALLET_CREDENTIAL_ERROR',
|
|
118
|
+
'WALLET_SHADOW_ERROR',
|
|
119
|
+
'WRONG_TOKEN_TYPE_ERROR'
|
|
120
|
+
] as const
|
|
121
|
+
|
|
122
|
+
export type KnishIOErrorType = typeof ERROR_TYPES[number]
|
|
123
|
+
|
|
124
|
+
// =============================================================================
|
|
125
|
+
// CRYPTO CONSTANTS (CONST ASSERTION)
|
|
126
|
+
// =============================================================================
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Hexadecimal characters with const assertion
|
|
130
|
+
*/
|
|
131
|
+
export const HEX_CHARS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'] as const
|
|
132
|
+
export type HexChar = typeof HEX_CHARS[number]
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Base17 characters for molecular hashing (includes g for base17)
|
|
136
|
+
*/
|
|
137
|
+
export const BASE17_CHARS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g'] as const
|
|
138
|
+
export type Base17Char = typeof BASE17_CHARS[number]
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Hash length constants
|
|
142
|
+
*/
|
|
143
|
+
export const HASH_LENGTHS = {
|
|
144
|
+
WALLET_ADDRESS: 64,
|
|
145
|
+
BUNDLE_HASH: 64,
|
|
146
|
+
POSITION: 64,
|
|
147
|
+
MOLECULAR_HASH_MIN: 32,
|
|
148
|
+
MOLECULAR_HASH_MAX: 128
|
|
149
|
+
} as const
|
|
150
|
+
|
|
151
|
+
// =============================================================================
|
|
152
|
+
// PROTOCOL CONSTANTS (CONST ASSERTION)
|
|
153
|
+
// =============================================================================
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* SDK version and protocol constants
|
|
157
|
+
*/
|
|
158
|
+
export const PROTOCOL_CONFIG = {
|
|
159
|
+
DEFAULT_SDK_VERSION: 4,
|
|
160
|
+
SUPPORTED_SDK_VERSIONS: [3, 4, 5],
|
|
161
|
+
DEFAULT_TOKEN: 'USER',
|
|
162
|
+
MAX_BATCH_SIZE: 1000,
|
|
163
|
+
DEFAULT_TIMEOUT: 30000,
|
|
164
|
+
MAX_RETRY_ATTEMPTS: 3
|
|
165
|
+
} as const
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Network and endpoint constants
|
|
169
|
+
*/
|
|
170
|
+
export const NETWORK_CONFIG = {
|
|
171
|
+
DEFAULT_CELL_SLUG: 'default',
|
|
172
|
+
DEFAULT_LOGGING: false,
|
|
173
|
+
GRAPHQL_ENDPOINTS: {
|
|
174
|
+
QUERY: 'query',
|
|
175
|
+
MUTATION: 'mutation',
|
|
176
|
+
SUBSCRIPTION: 'subscription'
|
|
177
|
+
}
|
|
178
|
+
} as const
|
|
179
|
+
|
|
180
|
+
// =============================================================================
|
|
181
|
+
// TEMPLATE LITERAL TYPE PATTERNS
|
|
182
|
+
// =============================================================================
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Template literal types for validation patterns
|
|
186
|
+
*/
|
|
187
|
+
export type HexPattern = `${HexChar}${string}`
|
|
188
|
+
export type Base17Pattern = `${Base17Char}${string}`
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Specific hex patterns for different hash types
|
|
192
|
+
*/
|
|
193
|
+
export type WalletAddressPattern = `${HexChar}${HexChar}${string}` & { length: 64 }
|
|
194
|
+
export type BundleHashPattern = `${HexChar}${HexChar}${string}` & { length: 64 }
|
|
195
|
+
export type PositionPattern = `${HexChar}${HexChar}${string}` & { length: 64 }
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Token slug patterns (uppercase alphanumeric with underscores)
|
|
199
|
+
*/
|
|
200
|
+
export type TokenSlugPattern = `${Uppercase<string>}`
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Meta type patterns
|
|
204
|
+
*/
|
|
205
|
+
export type MetaTypePattern = `${string}`
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Error message templates
|
|
209
|
+
*/
|
|
210
|
+
export type ErrorMessageTemplate<T extends string> = `${T}: ${string}`
|
|
211
|
+
export type ValidationErrorTemplate<T extends string> = `Validation failed for ${T}`
|
|
212
|
+
export type OperationErrorTemplate<T extends string> = `Operation '${T}' failed`
|
|
213
|
+
|
|
214
|
+
// =============================================================================
|
|
215
|
+
// QUERY TYPE CONSTANTS (CONST ASSERTION)
|
|
216
|
+
// =============================================================================
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Query operation types
|
|
220
|
+
*/
|
|
221
|
+
export const QUERY_TYPES = [
|
|
222
|
+
'Balance',
|
|
223
|
+
'WalletBundle',
|
|
224
|
+
'WalletList',
|
|
225
|
+
'Atom',
|
|
226
|
+
'MetaType',
|
|
227
|
+
'MetaTypeViaAtom',
|
|
228
|
+
'ContinuId',
|
|
229
|
+
'Batch',
|
|
230
|
+
'ActiveSession',
|
|
231
|
+
'Policy',
|
|
232
|
+
'Token',
|
|
233
|
+
'UserActivity'
|
|
234
|
+
] as const
|
|
235
|
+
|
|
236
|
+
export type QueryType = typeof QUERY_TYPES[number]
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Mutation operation types
|
|
240
|
+
*/
|
|
241
|
+
export const MUTATION_TYPES = [
|
|
242
|
+
'TransferTokens',
|
|
243
|
+
'CreateWallet',
|
|
244
|
+
'RequestAuthorization',
|
|
245
|
+
'CreateMeta',
|
|
246
|
+
'CreateToken',
|
|
247
|
+
'RequestTokens',
|
|
248
|
+
'ActiveSession',
|
|
249
|
+
'ClaimShadowWallet',
|
|
250
|
+
'CreateIdentifier',
|
|
251
|
+
'CreateRule',
|
|
252
|
+
'RequestAuthorizationGuest',
|
|
253
|
+
'DepositBufferToken',
|
|
254
|
+
'LinkIdentifier',
|
|
255
|
+
'WithdrawBufferToken',
|
|
256
|
+
'ProposeMolecule'
|
|
257
|
+
] as const
|
|
258
|
+
|
|
259
|
+
export type MutationType = typeof MUTATION_TYPES[number]
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Subscription operation types
|
|
263
|
+
*/
|
|
264
|
+
export const SUBSCRIPTION_TYPES = [
|
|
265
|
+
'CreateMolecule',
|
|
266
|
+
'ActiveSession',
|
|
267
|
+
'ActiveWallet',
|
|
268
|
+
'WalletStatus'
|
|
269
|
+
] as const
|
|
270
|
+
|
|
271
|
+
export type SubscriptionType = typeof SUBSCRIPTION_TYPES[number]
|
|
272
|
+
|
|
273
|
+
// =============================================================================
|
|
274
|
+
// VALIDATION CONSTANTS (CONST ASSERTION)
|
|
275
|
+
// =============================================================================
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Validation rule constants
|
|
279
|
+
*/
|
|
280
|
+
export const VALIDATION_RULES = {
|
|
281
|
+
MIN_TOKEN_SLUG_LENGTH: 1,
|
|
282
|
+
MAX_TOKEN_SLUG_LENGTH: 32,
|
|
283
|
+
MIN_AMOUNT: 0,
|
|
284
|
+
MAX_AMOUNT: Number.MAX_SAFE_INTEGER,
|
|
285
|
+
MIN_META_KEY_LENGTH: 1,
|
|
286
|
+
MAX_META_KEY_LENGTH: 255,
|
|
287
|
+
TOKEN_SLUG_PATTERN: /^[A-Z0-9_]+$/,
|
|
288
|
+
HEX_PATTERN: /^[0-9a-fA-F]+$/,
|
|
289
|
+
BASE17_PATTERN: /^[0-9a-g]+$/i
|
|
290
|
+
} as const
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Environment variable keys with const assertion
|
|
294
|
+
*/
|
|
295
|
+
export const ENV_KEYS = [
|
|
296
|
+
'NODE_ENV',
|
|
297
|
+
'KNISHIO_NODE_URI',
|
|
298
|
+
'KNISHIO_CELL_SLUG',
|
|
299
|
+
'KNISHIO_LOGGING',
|
|
300
|
+
'KNISHIO_SERVER_SDK_VERSION'
|
|
301
|
+
] as const
|
|
302
|
+
|
|
303
|
+
export type EnvKey = typeof ENV_KEYS[number]
|
|
304
|
+
|
|
305
|
+
// =============================================================================
|
|
306
|
+
// TYPE HELPER CONSTANTS
|
|
307
|
+
// =============================================================================
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Balance query types
|
|
311
|
+
*/
|
|
312
|
+
export const BALANCE_QUERY_TYPES = ['token', 'user'] as const
|
|
313
|
+
export type BalanceQueryType = typeof BALANCE_QUERY_TYPES[number]
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Node environment types
|
|
317
|
+
*/
|
|
318
|
+
export const NODE_ENVIRONMENTS = ['development', 'production', 'test'] as const
|
|
319
|
+
export type NodeEnvironment = typeof NODE_ENVIRONMENTS[number]
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* GraphQL operation names
|
|
323
|
+
*/
|
|
324
|
+
export const GRAPHQL_OPERATIONS = ['query', 'mutation', 'subscription'] as const
|
|
325
|
+
export type GraphQLOperation = typeof GRAPHQL_OPERATIONS[number]
|
|
326
|
+
|
|
327
|
+
// =============================================================================
|
|
328
|
+
// UTILITY TYPE HELPERS WITH CONST ASSERTIONS
|
|
329
|
+
// =============================================================================
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Create immutable lookup objects with const assertions
|
|
333
|
+
*/
|
|
334
|
+
export function createLookup<T extends readonly string[]>(
|
|
335
|
+
values: T
|
|
336
|
+
): Record<T[number], T[number]> {
|
|
337
|
+
return values.reduce((acc, value) => {
|
|
338
|
+
(acc as any)[value] = value
|
|
339
|
+
return acc
|
|
340
|
+
}, {} as Record<T[number], T[number]>)
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Isotope lookup for O(1) access
|
|
345
|
+
*/
|
|
346
|
+
export const ISOTOPE_LOOKUP = createLookup(ISOTOPES)
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Error type lookup for O(1) access
|
|
350
|
+
*/
|
|
351
|
+
export const ERROR_TYPE_LOOKUP = createLookup(ERROR_TYPES)
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Query type lookup for O(1) access
|
|
355
|
+
*/
|
|
356
|
+
export const QUERY_TYPE_LOOKUP = createLookup(QUERY_TYPES)
|
|
357
|
+
|
|
358
|
+
// =============================================================================
|
|
359
|
+
// SATISFIES OPERATOR EXAMPLES (2025 PATTERN)
|
|
360
|
+
// =============================================================================
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Configuration with satisfies operator for type checking
|
|
364
|
+
*/
|
|
365
|
+
export const DEFAULT_CLIENT_CONFIG = {
|
|
366
|
+
uri: undefined,
|
|
367
|
+
cellSlug: NETWORK_CONFIG.DEFAULT_CELL_SLUG,
|
|
368
|
+
serverSdkVersion: PROTOCOL_CONFIG.DEFAULT_SDK_VERSION,
|
|
369
|
+
logging: NETWORK_CONFIG.DEFAULT_LOGGING
|
|
370
|
+
} as const satisfies Partial<{
|
|
371
|
+
uri: string | string[] | undefined
|
|
372
|
+
cellSlug: string | undefined
|
|
373
|
+
serverSdkVersion: number
|
|
374
|
+
logging: boolean
|
|
375
|
+
}>
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Error templates with satisfies operator
|
|
379
|
+
*/
|
|
380
|
+
export const ERROR_TEMPLATES = {
|
|
381
|
+
VALIDATION_FAILED: 'Validation failed for field',
|
|
382
|
+
OPERATION_FAILED: 'Operation failed',
|
|
383
|
+
NETWORK_ERROR: 'Network error occurred',
|
|
384
|
+
TIMEOUT_ERROR: 'Operation timed out'
|
|
385
|
+
} as const satisfies Record<string, string>
|
|
386
|
+
|
|
387
|
+
// =============================================================================
|
|
388
|
+
// EXPORTS
|
|
389
|
+
// =============================================================================
|
|
390
|
+
|
|
391
|
+
// Re-export specific constants for convenience
|
|
392
|
+
export {
|
|
393
|
+
ISOTOPES as AtomIsotopes,
|
|
394
|
+
ERROR_TYPES as ErrorTypes,
|
|
395
|
+
HEX_CHARS as HexChars,
|
|
396
|
+
PROTOCOL_CONFIG as Protocol,
|
|
397
|
+
VALIDATION_RULES as ValidationRules
|
|
398
|
+
}
|